From 95bc42af74295f2c97eba18fa44fe9b8bcc7c58a Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Tue, 5 Nov 2024 01:08:07 -0800 Subject: [PATCH] nir: Use load_global_constant for reorderable nir_var_mem_global access The main difference between load_global and load_global_constant is that the latter can be reordered arbitrarily. If the access being lowered is already tagged as being reorderable, then we can preserve that by using the load_global_constant intrinsics instead of load_global. This gives us more flexibility. On Intel, this lets us use the load_global_constant_uniform_block_intel intrinsic for doing convergent block loads in more cases. This nets us significant reductions in spill/fills: Borderlands 3 on Lunarlake sees spills/fills reduced by 53%. Alchemist sees a 13% reduction. Improves performance of Borderlands 3 DX12 on Intel Battlemage by around 44%. Improves Hogwarts Legacy by around 14%. Reviewed-by: Alyssa Rosenzweig Reviewed-by: Lionel Landwerlin Part-of: --- src/compiler/nir/nir_lower_io.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/compiler/nir/nir_lower_io.c b/src/compiler/nir/nir_lower_io.c index 2f9f9642f1e..86cc1d9cd95 100644 --- a/src/compiler/nir/nir_lower_io.c +++ b/src/compiler/nir/nir_lower_io.c @@ -1486,7 +1486,12 @@ build_explicit_io_load(nir_builder *b, nir_intrinsic_instr *intrin, break; case nir_var_mem_global: assert(addr_format_is_global(addr_format, mode)); - op = get_load_global_op_from_addr_format(addr_format); + + if (nir_intrinsic_has_access(intrin) && + (nir_intrinsic_access(intrin) & ACCESS_CAN_REORDER)) + op = get_load_global_constant_op_from_addr_format(addr_format); + else + op = get_load_global_op_from_addr_format(addr_format); break; case nir_var_uniform: assert(addr_format_is_offset(addr_format, mode));