From 58f843a193b99994479da48f0d65360efe8a4a8d Mon Sep 17 00:00:00 2001 From: Michael Tang Date: Thu, 29 Apr 2021 13:10:55 -0700 Subject: [PATCH] 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 Part-of: --- 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) {