nir: add info.fs.require_full_quads

This flag indicates the requirement of helper invocations
in fragment shaders, independent from any present instructions.
This fixes the lowering of OpGroupNonUniformQuad* instructions.

Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Reviewed-by: Caio Oliveira <caio.oliveira@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26026>
This commit is contained in:
Daniel Schürmann 2023-11-02 15:44:40 +01:00
parent 2db0507b5d
commit f1110576d9
4 changed files with 24 additions and 2 deletions

View file

@ -762,6 +762,10 @@ gather_intrinsic_info(nir_intrinsic_instr *instr, nir_shader *shader,
case nir_intrinsic_mbcnt_amd:
case nir_intrinsic_write_invocation_amd:
shader->info.uses_wide_subgroup_intrinsics = true;
if (shader->info.stage == MESA_SHADER_FRAGMENT &&
shader->info.fs.require_full_quads)
shader->info.fs.needs_quad_helper_invocations = true;
break;
case nir_intrinsic_end_primitive:

View file

@ -2535,6 +2535,7 @@ print_shader_info(const struct shader_info *info, FILE *fp)
print_nz_bool(fp, "uses_fbfetch_output", info->fs.uses_fbfetch_output);
print_nz_bool(fp, "color_is_dual_source", info->fs.color_is_dual_source);
print_nz_bool(fp, "require_full_quads", info->fs.require_full_quads);
print_nz_bool(fp, "needs_quad_helper_invocations", info->fs.needs_quad_helper_invocations);
print_nz_bool(fp, "uses_sample_qualifier", info->fs.uses_sample_qualifier);
print_nz_bool(fp, "uses_sample_shading", info->fs.uses_sample_shading);

View file

@ -414,11 +414,16 @@ typedef struct shader_info {
bool fbfetch_coherent:1;
bool color_is_dual_source:1;
/**
* True if this fragment shader requires full quad invocations.
*/
bool require_full_quads:1;
/**
* True if this fragment shader requires helper invocations. This
* can be caused by the use of ALU derivative ops, texture
* instructions which do implicit derivatives, and the use of quad
* subgroup operations.
* instructions which do implicit derivatives, the use of quad
* subgroup operations or if the shader requires full quads.
*/
bool needs_quad_helper_invocations:1;

View file

@ -341,6 +341,15 @@ vtn_handle_subgroup(struct vtn_builder *b, SpvOp opcode,
}
case SpvOpGroupNonUniformQuadBroadcast:
/* From the Vulkan spec 1.3.269:
*
* 9.27. Quad Group Operations:
* "Fragment shaders that statically execute quad group operations
* must launch sufficient invocations to ensure their correct operation;"
*/
if (b->shader->info.stage == MESA_SHADER_FRAGMENT)
b->shader->info.fs.require_full_quads = true;
vtn_push_ssa_value(b, w[2],
vtn_build_subgroup_instr(b, nir_intrinsic_quad_broadcast,
vtn_ssa_value(b, w[4]),
@ -348,6 +357,9 @@ vtn_handle_subgroup(struct vtn_builder *b, SpvOp opcode,
break;
case SpvOpGroupNonUniformQuadSwap: {
if (b->shader->info.stage == MESA_SHADER_FRAGMENT)
b->shader->info.fs.require_full_quads = true;
unsigned direction = vtn_constant_uint(b, w[5]);
nir_intrinsic_op op;
switch (direction) {