From 7809f76fe8a47ba80804897906a82f2157a30781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20=C5=9Alusarz?= Date: Mon, 5 Dec 2022 12:27:38 +0100 Subject: [PATCH] intel/compiler/mesh: align payload size to the size of vec4 This reduces the number of instructions in task shaders when payload size is not aligned to vec4 and payload_in_shared WA is enabled, because nir_lower_task_shader will not need to handle the unaligned size case. Reviewed-by: Caio Oliveira Part-of: --- src/intel/compiler/brw_mesh.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/intel/compiler/brw_mesh.cpp b/src/intel/compiler/brw_mesh.cpp index 3d3a36411af..4843f94f278 100644 --- a/src/intel/compiler/brw_mesh.cpp +++ b/src/intel/compiler/brw_mesh.cpp @@ -238,6 +238,37 @@ brw_nir_adjust_payload(nir_shader *shader, const struct brw_compiler *compiler) NIR_PASS(_, shader, nir_opt_constant_folding); } +static bool +brw_nir_align_launch_mesh_workgroups_instr(nir_builder *b, nir_instr *instr, void *data) +{ + if (instr->type != nir_instr_type_intrinsic) + return false; + + nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr); + + if (intrin->intrinsic != nir_intrinsic_launch_mesh_workgroups) + return false; + + /* nir_lower_task_shader uses "range" as task payload size. */ + unsigned range = nir_intrinsic_range(intrin); + /* This will avoid special case in nir_lower_task_shader dealing with + * not vec4-aligned payload when payload_in_shared workaround is enabled. + */ + nir_intrinsic_set_range(intrin, ALIGN(range, 16)); + + return true; +} + +static bool +brw_nir_align_launch_mesh_workgroups(nir_shader *nir) +{ + return nir_shader_instructions_pass(nir, + brw_nir_align_launch_mesh_workgroups_instr, + nir_metadata_block_index | + nir_metadata_dominance, + NULL); +} + const unsigned * brw_compile_task(const struct brw_compiler *compiler, void *mem_ctx, @@ -250,6 +281,8 @@ brw_compile_task(const struct brw_compiler *compiler, brw_nir_lower_tue_outputs(nir, &prog_data->map); + NIR_PASS(_, nir, brw_nir_align_launch_mesh_workgroups); + nir_lower_task_shader_options lower_ts_opt = { .payload_to_shared_for_atomics = true, .payload_to_shared_for_small_types = true,