From e42d2bd534481cadd344c7349e43dcb77610a0ae Mon Sep 17 00:00:00 2001 From: =?utf8?q?Timur=20Krist=C3=B3f?= Date: Thu, 30 Mar 2023 19:34:31 +0200 Subject: [PATCH] nir: Gather compile time constant task->mesh dispatch size. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Some GPUs such as AMD RDNA3 can use this information to optimize mesh shader dispatches. Signed-off-by: Timur Kristóf Reviewed-by: Marcin Ślusarz Reviewed-by: Rhys Perry Reviewed-by: Samuel Pitoiset Part-of: --- src/compiler/nir/nir_gather_info.c | 16 ++++++++++++++++ src/compiler/shader_info.h | 8 +++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/compiler/nir/nir_gather_info.c b/src/compiler/nir/nir_gather_info.c index 76c89c0..9fe6310 100644 --- a/src/compiler/nir/nir_gather_info.c +++ b/src/compiler/nir/nir_gather_info.c @@ -875,6 +875,17 @@ gather_intrinsic_info(nir_intrinsic_instr *instr, nir_shader *shader, BITFIELD64_BIT(FRAG_RESULT_STENCIL); break; + case nir_intrinsic_launch_mesh_workgroups: + case nir_intrinsic_launch_mesh_workgroups_with_payload_deref: { + for (unsigned i = 0; i < 3; ++i) { + nir_ssa_scalar dim = nir_ssa_scalar_resolved(instr->src[0].ssa, i); + if (nir_ssa_scalar_is_const(dim)) + shader->info.mesh.ts_mesh_dispatch_dimensions[i] = + nir_ssa_scalar_as_uint(dim); + } + break; + } + default: shader->info.uses_bindless |= intrinsic_is_bindless(instr); if (nir_intrinsic_writes_external_memory(instr)) @@ -1054,6 +1065,11 @@ nir_shader_gather_info(nir_shader *shader, nir_function_impl *entrypoint) if (shader->info.stage == MESA_SHADER_MESH) { shader->info.mesh.ms_cross_invocation_output_access = 0; } + if (shader->info.stage == MESA_SHADER_TASK) { + shader->info.mesh.ts_mesh_dispatch_dimensions[0] = 0; + shader->info.mesh.ts_mesh_dispatch_dimensions[1] = 0; + shader->info.mesh.ts_mesh_dispatch_dimensions[2] = 0; + } if (shader->info.stage != MESA_SHADER_FRAGMENT) shader->info.writes_memory = shader->info.has_transform_feedback_varyings; diff --git a/src/compiler/shader_info.h b/src/compiler/shader_info.h index 522a797..d3a978b 100644 --- a/src/compiler/shader_info.h +++ b/src/compiler/shader_info.h @@ -550,13 +550,19 @@ typedef struct shader_info { uint64_t tcs_cross_invocation_outputs_read; } tess; - /* Applies to MESH. */ + /* Applies to MESH and TASK. */ struct { /* Bit mask of MS outputs that are used * with an index that is NOT the local invocation index. */ uint64_t ms_cross_invocation_output_access; + /* Dimensions of task->mesh dispatch (EmitMeshTasksEXT) + * when they are known compile-time constants. + * 0 means they are not known. + */ + uint32_t ts_mesh_dispatch_dimensions[3]; + uint16_t max_vertices_out; uint16_t max_primitives_out; uint16_t primitive_type; /* GL_POINTS, GL_LINES or GL_TRIANGLES. */ -- 2.7.4