From 4d4418dbb39d4f9bae09aa8e4ea5361b7eab87be Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Thu, 12 Dec 2024 09:48:04 +0100 Subject: [PATCH] spirv: add an options to lower SpvOpTerminateInvocation to OpKill To workaround game bugs like Indiana Jones. Original workaround found by Hans-Kristian. Cc: mesa-stable Signed-off-by: Samuel Pitoiset Part-of: --- src/compiler/spirv/nir_spirv.h | 5 +++++ src/compiler/spirv/vtn_structured_cfg.c | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/compiler/spirv/nir_spirv.h b/src/compiler/spirv/nir_spirv.h index 2402013ad2c..3494a8e07cb 100644 --- a/src/compiler/spirv/nir_spirv.h +++ b/src/compiler/spirv/nir_spirv.h @@ -136,6 +136,11 @@ struct spirv_to_nir_options { /* 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; + /* 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 * but continue executing other tests. diff --git a/src/compiler/spirv/vtn_structured_cfg.c b/src/compiler/spirv/vtn_structured_cfg.c index cbd2676e46a..3224e7a99be 100644 --- a/src/compiler/spirv/vtn_structured_cfg.c +++ b/src/compiler/spirv/vtn_structured_cfg.c @@ -976,7 +976,10 @@ branch_type_for_terminator(struct vtn_builder *b, struct vtn_block *block) case SpvOpKill: return vtn_branch_type_discard; case SpvOpTerminateInvocation: - return vtn_branch_type_terminate_invocation; + if (b->options->lower_terminate_to_discard) + return vtn_branch_type_discard; + else + return vtn_branch_type_terminate_invocation; case SpvOpIgnoreIntersectionKHR: return vtn_branch_type_ignore_intersection; case SpvOpTerminateRayKHR: