Mesa (master): microsoft/compiler: Maintain sorting of resource type in the context

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Apr 30 00:08:17 UTC 2021


Module: Mesa
Branch: master
Commit: 58f843a193b99994479da48f0d65360efe8a4a8d
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=58f843a193b99994479da48f0d65360efe8a4a8d

Author: Michael Tang <tangm at microsoft.com>
Date:   Thu Apr 29 13:10:55 2021 -0700

microsoft/compiler: Maintain sorting of resource type in the context

This change moves the SRVs associated with read-only SSBOs to be emitted
before any other UAV. We do this because the validator expects resources
to be emitted in a specific order, as noted by `emit_module`.

Previously, we emitted SSBOs as SRVs (read-only) or UAVs (read-write)
after other UAVs.

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

---

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

diff --git a/src/microsoft/compiler/nir_to_dxil.c b/src/microsoft/compiler/nir_to_dxil.c
index 0b4b38fc40e..a97a6b3af31 100644
--- a/src/microsoft/compiler/nir_to_dxil.c
+++ b/src/microsoft/compiler/nir_to_dxil.c
@@ -4240,25 +4240,6 @@ emit_scratch(struct ntd_context *ctx)
    return true;
 }
 
-static bool
-emit_ssbos(struct ntd_context *ctx)
-{
-   nir_foreach_variable_with_modes(var, ctx->shader, nir_var_mem_ssbo) {
-      unsigned count = 1;
-      if (glsl_type_is_array(var->type))
-         count = glsl_get_length(var->type);
-
-      bool success = (var->data.access & ACCESS_NON_WRITEABLE) ?
-         emit_srv(ctx, var, count) :
-         emit_uav(ctx, var->data.binding, var->data.descriptor_set, count, DXIL_COMP_TYPE_INVALID, DXIL_RESOURCE_KIND_RAW_BUFFER, var->name);
-
-      if (!success)
-         return false;
-   }
-
-   return true;
-}
-
 /* The validator complains if we don't have ops that reference a global variable. */
 static bool
 shader_has_shared_ops(struct nir_shader *s)
@@ -4326,6 +4307,16 @@ emit_module(struct ntd_context *ctx, const struct nir_to_dxil_options *opts)
             return false;
       }
    }
+   /* Handle read-only SSBOs as SRVs */
+   nir_foreach_variable_with_modes(var, ctx->shader, nir_var_mem_ssbo) {
+      if ((var->data.access & ACCESS_NON_WRITEABLE) != 0) {
+         unsigned count = 1;
+         if (glsl_type_is_array(var->type))
+            count = glsl_get_length(var->type);
+         if (!emit_srv(ctx, var, count))
+            return false;
+      }
+   }
 
    if (ctx->shader->info.shared_size && shader_has_shared_ops(ctx->shader)) {
       const struct dxil_type *type;
@@ -4365,8 +4356,18 @@ emit_module(struct ntd_context *ctx, const struct nir_to_dxil_options *opts)
       if (!emit_global_consts(ctx))
          return false;
    } else {
-      if (!emit_ssbos(ctx))
-         return false;
+      /* Handle read/write SSBOs as UAVs */
+      nir_foreach_variable_with_modes(var, ctx->shader, nir_var_mem_ssbo) {
+         if ((var->data.access & ACCESS_NON_WRITEABLE) == 0) {
+            unsigned count = 1;
+            if (glsl_type_is_array(var->type))
+               count = glsl_get_length(var->type);
+            if (!emit_uav(ctx, var->data.binding, var->data.descriptor_set,
+                        count, DXIL_COMP_TYPE_INVALID,
+                        DXIL_RESOURCE_KIND_RAW_BUFFER, var->name))
+               return false;
+         }
+      }
    }
 
    nir_foreach_variable_with_modes(var, ctx->shader, nir_var_uniform) {



More information about the mesa-commit mailing list