From efcd5563785dbd38f05cb7a83a9cb54abfaddd68 Mon Sep 17 00:00:00 2001 From: Edoardo Canepa Date: Mon, 12 Feb 2024 15:56:32 +0100 Subject: [PATCH] When cloning a NIR shader that was missing the FRAG0/COLOR output, avoid adding again the output variable if one is already present. This was causing DXIL validation to fail due to the duplicate SV_Target output parameter --- src/gallium/drivers/d3d12/d3d12_compiler.cpp | 5 +++-- src/gallium/drivers/d3d12/d3d12_nir_passes.c | 10 ++++++++++ src/gallium/drivers/d3d12/d3d12_nir_passes.h | 3 +++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/gallium/drivers/d3d12/d3d12_compiler.cpp b/src/gallium/drivers/d3d12/d3d12_compiler.cpp index 73191ee7ee5..b31430e3f4a 100644 --- a/src/gallium/drivers/d3d12/d3d12_compiler.cpp +++ b/src/gallium/drivers/d3d12/d3d12_compiler.cpp @@ -1238,8 +1238,9 @@ select_shader_variant(struct d3d12_selection_context *sel_ctx, d3d12_shader_sele } if (key.fs.missing_dual_src_outputs) { - NIR_PASS_V(new_nir_variant, d3d12_add_missing_dual_src_target, - key.fs.missing_dual_src_outputs); + if (d3d12_is_missing_dual_src_target(new_nir_variant)) { + NIR_PASS_V(new_nir_variant, d3d12_add_missing_dual_src_target, key.fs.missing_dual_src_outputs); + } } else if (key.fs.frag_result_color_lowering) { NIR_PASS_V(new_nir_variant, nir_lower_fragcolor, key.fs.frag_result_color_lowering); diff --git a/src/gallium/drivers/d3d12/d3d12_nir_passes.c b/src/gallium/drivers/d3d12/d3d12_nir_passes.c index cb26e263818..8e320db7a22 100644 --- a/src/gallium/drivers/d3d12/d3d12_nir_passes.c +++ b/src/gallium/drivers/d3d12/d3d12_nir_passes.c @@ -577,6 +577,16 @@ d3d12_lower_state_vars(nir_shader *nir, struct d3d12_shader *shader) return progress; } +bool +d3d12_is_missing_dual_src_target(struct nir_shader *s) +{ + nir_foreach_variable_with_modes (var, s, nir_var_shader_out) { + if (var->data.location == FRAG_RESULT_DATA0) + return false; + } + return true; +} + void d3d12_add_missing_dual_src_target(struct nir_shader *s, unsigned missing_mask) diff --git a/src/gallium/drivers/d3d12/d3d12_nir_passes.h b/src/gallium/drivers/d3d12/d3d12_nir_passes.h index ee3560dac05..d9d58f54be0 100644 --- a/src/gallium/drivers/d3d12/d3d12_nir_passes.h +++ b/src/gallium/drivers/d3d12/d3d12_nir_passes.h @@ -78,6 +78,9 @@ d3d12_lower_compute_state_vars(nir_shader *nir); void d3d12_lower_uint_cast(nir_shader *nir, bool is_signed); +bool +d3d12_is_missing_dual_src_target(struct nir_shader *s); + void d3d12_add_missing_dual_src_target(struct nir_shader *s, unsigned missing_mask);