From cbc481f39f236967f20b5591381d873e28e79282 Mon Sep 17 00:00:00 2001 From: Jesse Natalie Date: Thu, 5 Jan 2023 10:19:29 -0800 Subject: [PATCH] microsoft/compiler: Re-work the logic for adding SV_SampleIndex to force sample-rate Only add SV_SampleIndex if there exists a sample-rate var that has either flat interpolation or centroid (and therefore can't force sample rate implicitly), unless there is also a sample-rate var that doesn't have those properties. Part-of: --- src/microsoft/compiler/nir_to_dxil.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/microsoft/compiler/nir_to_dxil.c b/src/microsoft/compiler/nir_to_dxil.c index 83a4c3ef668..6d7fe3f9c46 100644 --- a/src/microsoft/compiler/nir_to_dxil.c +++ b/src/microsoft/compiler/nir_to_dxil.c @@ -6034,7 +6034,7 @@ allocate_sysvalues(struct ntd_context *ctx) if (ctx->shader->info.stage == MESA_SHADER_FRAGMENT && ctx->shader->info.inputs_read && !BITSET_TEST(ctx->shader->info.system_values_read, SYSTEM_VALUE_SAMPLE_ID)) { - bool need_sample_id = true; + bool need_sample_id = false; /* "var->data.sample = true" sometimes just mean, "I want per-sample * shading", which explains why we can end up with vars having flat @@ -6043,10 +6043,17 @@ allocate_sysvalues(struct ntd_context *ctx) * to make DXIL validation happy. */ nir_foreach_variable_with_modes(var, ctx->shader, nir_var_shader_in) { - if (!var->data.sample || var->data.interpolation != INTERP_MODE_FLAT) { + bool var_can_be_sample_rate = !var->data.centroid && var->data.interpolation != INTERP_MODE_FLAT; + /* If there's an input that will actually force sample-rate shading, then we don't + * need SV_SampleIndex. */ + if (var->data.sample && var_can_be_sample_rate) { need_sample_id = false; break; } + /* If there's an input that wants to be sample-rate, but can't be, then we might + * need SV_SampleIndex. */ + if (var->data.sample && !var_can_be_sample_rate) + need_sample_id = true; } if (need_sample_id)