From 33676d829664474e2ebb2bdb7079e5ae39042e73 Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Fri, 3 Apr 2026 14:56:56 +0200 Subject: [PATCH] spirv: mark all resources as non-uniform by default with descriptor heap It's required by descriptor heap. There is already a NIR pass that optimizes non-uniform access, so this should be mostly safe. Signed-off-by: Samuel Pitoiset Part-of: --- src/compiler/spirv/spirv_to_nir.c | 10 +++++----- src/compiler/spirv/vtn_private.h | 13 +++++++++++++ src/compiler/spirv/vtn_variables.c | 10 +++++++++- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c index 6a19e49d35c..f47305189dd 100644 --- a/src/compiler/spirv/spirv_to_nir.c +++ b/src/compiler/spirv/spirv_to_nir.c @@ -3473,8 +3473,8 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode, "Type of Image operand of OpSampledImage"); enum gl_access_qualifier access = 0; - if (vtn_has_decoration(b, vtn_untyped_value(b, w[3]), SpvDecorationNonUniformEXT) || - vtn_has_decoration(b, vtn_untyped_value(b, w[4]), SpvDecorationNonUniformEXT)) + if (vtn_value_is_non_uniform(b, vtn_untyped_value(b, w[3])) || + vtn_value_is_non_uniform(b, vtn_untyped_value(b, w[4]))) access |= ACCESS_NON_UNIFORM; vtn_push_sampled_image(b, w[2], si, access & ACCESS_NON_UNIFORM); @@ -3483,7 +3483,7 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode, struct vtn_sampled_image si = vtn_get_sampled_image(b, w[3]); enum gl_access_qualifier access = 0; - if (vtn_has_decoration(b, vtn_untyped_value(b, w[3]), SpvDecorationNonUniformEXT)) + if (vtn_value_is_non_uniform(b, vtn_untyped_value(b, w[3]))) access |= ACCESS_NON_UNIFORM; vtn_push_image(b, w[2], si.image, access & ACCESS_NON_UNIFORM); @@ -4015,7 +4015,7 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode, * can assume it doesn't exist. */ enum gl_access_qualifier access = 0; - if (vtn_has_decoration(b, sampled_val, SpvDecorationNonUniformEXT)) + if (vtn_value_is_non_uniform(b, sampled_val)) access |= ACCESS_NON_UNIFORM; if (operands & SpvImageOperandsNontemporalMask) @@ -4473,7 +4473,7 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode, * chains to find the NonUniform decoration. It's either right there or we * can assume it doesn't exist. */ - if (vtn_has_decoration(b, res_val, SpvDecorationNonUniformEXT)) + if (vtn_value_is_non_uniform(b, res_val)) access |= ACCESS_NON_UNIFORM; nir_intrinsic_set_access(intrin, access); diff --git a/src/compiler/spirv/vtn_private.h b/src/compiler/spirv/vtn_private.h index 4adccd533fc..ff2fb401180 100644 --- a/src/compiler/spirv/vtn_private.h +++ b/src/compiler/spirv/vtn_private.h @@ -1092,4 +1092,17 @@ nir_deref_instr *vtn_create_cmat_temporary(struct vtn_builder *b, mesa_shader_stage vtn_stage_for_execution_model(SpvExecutionModel model); +static inline bool +vtn_value_is_non_uniform(struct vtn_builder *b, struct vtn_value *value) +{ + if (vtn_has_decoration(b, value, SpvDecorationNonUniformEXT)) + return true; + + if (b->enabled_capabilities.DescriptorHeapEXT && + !vtn_has_decoration(b, value, SpvDecorationUniform)) + return true; + + return false; +} + #endif /* _VTN_PRIVATE_H_ */ diff --git a/src/compiler/spirv/vtn_variables.c b/src/compiler/spirv/vtn_variables.c index 221e3af75f5..a5cbdca3251 100644 --- a/src/compiler/spirv/vtn_variables.c +++ b/src/compiler/spirv/vtn_variables.c @@ -56,6 +56,10 @@ ptr_decoration_cb(struct vtn_builder *b, struct vtn_value *val, int member, default: break; } + + if (b->enabled_capabilities.DescriptorHeapEXT && + dec->decoration != SpvDecorationUniform) + ptr->access |= ACCESS_NON_UNIFORM; } struct access_align { @@ -81,6 +85,10 @@ access_align_cb(struct vtn_builder *b, struct vtn_value *val, int member, default: break; } + + if (b->enabled_capabilities.DescriptorHeapEXT && + dec->decoration != SpvDecorationUniform) + aa->access |= ACCESS_NON_UNIFORM; } static struct vtn_pointer* @@ -2888,7 +2896,7 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode, } /* Workaround for https://gitlab.freedesktop.org/mesa/mesa/-/issues/3406 */ - if (vtn_has_decoration(b, link_val, SpvDecorationNonUniformEXT)) + if (vtn_value_is_non_uniform(b, link_val)) access |= ACCESS_NON_UNIFORM; idx++;