Mesa (main): microsoft/compiler: Add a dunmmy SV_SampleIndex when needed

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Apr 19 09:12:22 UTC 2022


Module: Mesa
Branch: main
Commit: cacc3f03e6dff8aca09bd61c9e0a7cf33f6759ec
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=cacc3f03e6dff8aca09bd61c9e0a7cf33f6759ec

Author: Boris Brezillon <boris.brezillon at collabora.com>
Date:   Thu Apr 14 07:21:26 2022 -0700

microsoft/compiler: Add a dunmmy SV_SampleIndex when needed

When per-sample shading is forced and all input variables have a flat
interpolation, DXIL validation detects a mismatch between the
SampleFrequency property and the fact that no variables are per-sample
and SV_SampleIndex is never read. When that happens, add a dummy
SV_SampleIndex.

Reviewed-by: Jesse Natalie <jenatali at microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15916>

---

 src/microsoft/compiler/nir_to_dxil.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/src/microsoft/compiler/nir_to_dxil.c b/src/microsoft/compiler/nir_to_dxil.c
index cfc849667a6..ae07e28cf5a 100644
--- a/src/microsoft/compiler/nir_to_dxil.c
+++ b/src/microsoft/compiler/nir_to_dxil.c
@@ -5608,6 +5608,28 @@ allocate_sysvalues(struct ntd_context *ctx)
    nir_foreach_variable_with_modes(var, ctx->shader, nir_var_system_value)
       driver_location++;
 
+   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;
+
+      /* "var->data.sample = true" sometimes just mean, "I want per-sample
+       * shading", which explains why we can end up with vars having flat
+       * interpolation with the per-sample bit set. If there's only such
+       * type of variables, we need to tell DXIL that we read SV_SampleIndex
+       * 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) {
+            need_sample_id = false;
+            break;
+         }
+      }
+
+      if (need_sample_id)
+         BITSET_SET(ctx->shader->info.system_values_read, SYSTEM_VALUE_SAMPLE_ID);
+   }
+
    for (unsigned i = 0; i < ARRAY_SIZE(possible_sysvalues); ++i) {
       struct sysvalue_name *info = &possible_sysvalues[i];
       if (info->only_in_shader != MESA_SHADER_NONE &&



More information about the mesa-commit mailing list