From f2eb31b1a2997d44b56610472ac2371412990a3d Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Tue, 4 Mar 2025 09:18:00 +0100 Subject: [PATCH] spirv: move workarounds to an inner struct in spirv_to_nir_options To be more explicit. Signed-off-by: Samuel Pitoiset Part-of: --- src/amd/vulkan/radv_shader.c | 9 ++++++--- src/compiler/spirv/nir_spirv.h | 19 +++++++++++-------- src/compiler/spirv/spirv_to_nir.c | 2 +- src/compiler/spirv/vtn_structured_cfg.c | 2 +- src/compiler/spirv/vtn_variables.c | 2 +- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/amd/vulkan/radv_shader.c b/src/amd/vulkan/radv_shader.c index 0f6f637550f..0eab9708301 100644 --- a/src/amd/vulkan/radv_shader.c +++ b/src/amd/vulkan/radv_shader.c @@ -386,9 +386,12 @@ radv_shader_spirv_to_nir(struct radv_device *device, const struct radv_shader_st .func = radv_spirv_nir_debug, .private_data = &spirv_debug_data, }, - .force_tex_non_uniform = pdev->cache_key.tex_non_uniform, - .force_ssbo_non_uniform = pdev->cache_key.ssbo_non_uniform, - .lower_terminate_to_discard = pdev->cache_key.lower_terminate_to_discard, + .workarounds = + { + .force_tex_non_uniform = pdev->cache_key.tex_non_uniform, + .force_ssbo_non_uniform = pdev->cache_key.ssbo_non_uniform, + .lower_terminate_to_discard = pdev->cache_key.lower_terminate_to_discard, + }, .emit_debug_break = !!device->trap_handler_shader, .debug_info = !!(instance->debug_flags & RADV_DEBUG_NIR_DEBUG_INFO), }; diff --git a/src/compiler/spirv/nir_spirv.h b/src/compiler/spirv/nir_spirv.h index 36111b73480..16b8a681af5 100644 --- a/src/compiler/spirv/nir_spirv.h +++ b/src/compiler/spirv/nir_spirv.h @@ -131,15 +131,17 @@ struct spirv_to_nir_options { /* Whether debug_break instructions should be emitted. */ bool emit_debug_break; - /* Force texture sampling to be non-uniform. */ - bool force_tex_non_uniform; - /* Force SSBO accesses to be non-uniform. */ - bool force_ssbo_non_uniform; + struct { + /* Force texture sampling to be non-uniform. */ + bool force_tex_non_uniform; + /* Force SSBO accesses to be non-uniform. */ + bool force_ssbo_non_uniform; - /* Whether OpTerminateInvocation should be lowered to OpKill to workaround - * game bugs. - */ - bool lower_terminate_to_discard; + /* Whether OpTerminateInvocation should be lowered to OpKill to workaround + * game bugs. + */ + bool lower_terminate_to_discard; + } workarounds; /* In Debug Builds, instead of emitting an OS break on failure, just return NULL from * spirv_to_nir(). This is useful for the unit tests that want to report a test failed @@ -149,6 +151,7 @@ struct spirv_to_nir_options { /* Shader index provided by VkPipelineShaderStageNodeCreateInfoAMDX */ uint32_t shader_index; + }; enum spirv_verify_result { diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c index b3ad9be8e2b..a91cfb1cc2b 100644 --- a/src/compiler/spirv/spirv_to_nir.c +++ b/src/compiler/spirv/spirv_to_nir.c @@ -3598,7 +3598,7 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode, if (operands & SpvImageOperandsNontemporalMask) access |= ACCESS_NON_TEMPORAL; - if (sampler && b->options->force_tex_non_uniform) + if (sampler && b->options->workarounds.force_tex_non_uniform) access |= ACCESS_NON_UNIFORM; if (sampled_val->propagated_non_uniform) diff --git a/src/compiler/spirv/vtn_structured_cfg.c b/src/compiler/spirv/vtn_structured_cfg.c index 3224e7a99be..6efc984cfc3 100644 --- a/src/compiler/spirv/vtn_structured_cfg.c +++ b/src/compiler/spirv/vtn_structured_cfg.c @@ -976,7 +976,7 @@ branch_type_for_terminator(struct vtn_builder *b, struct vtn_block *block) case SpvOpKill: return vtn_branch_type_discard; case SpvOpTerminateInvocation: - if (b->options->lower_terminate_to_discard) + if (b->options->workarounds.lower_terminate_to_discard) return vtn_branch_type_discard; else return vtn_branch_type_terminate_invocation; diff --git a/src/compiler/spirv/vtn_variables.c b/src/compiler/spirv/vtn_variables.c index f5b276bfc06..73e8fc97217 100644 --- a/src/compiler/spirv/vtn_variables.c +++ b/src/compiler/spirv/vtn_variables.c @@ -2735,7 +2735,7 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode, /* Workaround for https://gitlab.freedesktop.org/mesa/mesa/-/issues/3406 */ access |= base->access & ACCESS_NON_UNIFORM; - if (base->mode == vtn_variable_mode_ssbo && b->options->force_ssbo_non_uniform) + if (base->mode == vtn_variable_mode_ssbo && b->options->workarounds.force_ssbo_non_uniform) access |= ACCESS_NON_UNIFORM; struct vtn_pointer *ptr = vtn_pointer_dereference(b, base, chain);