From 54c32aeba6300f5cafc2bae18020398645925969 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis-Francis=20Ratt=C3=A9-Boulianne?= Date: Tue, 9 Nov 2021 22:51:02 -0500 Subject: [PATCH] microsoft/compiler: Use SRVs for read-only images Acked-by: Enrico Galli Reviewed-by: Jesse Natalie Part-of: --- src/microsoft/compiler/nir_to_dxil.c | 30 +++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/microsoft/compiler/nir_to_dxil.c b/src/microsoft/compiler/nir_to_dxil.c index c7c7c19507d..c77f4dbb98c 100644 --- a/src/microsoft/compiler/nir_to_dxil.c +++ b/src/microsoft/compiler/nir_to_dxil.c @@ -4289,12 +4289,17 @@ emit_deref(struct ntd_context* ctx, nir_deref_instr* instr) assert(glsl_type_is_sampler(type) || glsl_type_is_image(type) || glsl_type_is_texture(type)); enum dxil_resource_class res_class; - if (glsl_type_is_image(type)) - res_class = DXIL_RESOURCE_CLASS_UAV; - else if (glsl_type_is_sampler(type)) + if (glsl_type_is_image(type)) { + if (ctx->opts->environment == DXIL_ENVIRONMENT_VULKAN && + (var->data.access & ACCESS_NON_WRITEABLE)) + res_class = DXIL_RESOURCE_CLASS_SRV; + else + res_class = DXIL_RESOURCE_CLASS_UAV; + } else if (glsl_type_is_sampler(type)) { res_class = DXIL_RESOURCE_CLASS_SAMPLER; - else + } else { res_class = DXIL_RESOURCE_CLASS_SRV; + } unsigned descriptor_set = ctx->opts->environment == DXIL_ENVIRONMENT_VULKAN ? var->data.descriptor_set : (glsl_type_is_image(type) ? 1 : 0); @@ -5171,12 +5176,19 @@ emit_module(struct ntd_context *ctx, const struct nir_to_dxil_options *opts) /* SRVs */ nir_foreach_variable_with_modes(var, ctx->shader, nir_var_uniform) { - unsigned count = glsl_type_get_texture_count(var->type); - assert(count == 0 || glsl_type_is_texture(glsl_without_array(var->type))); - if (count > 0 && !emit_srv(ctx, var, count)) + if (glsl_type_is_texture(glsl_without_array(var->type)) && + !emit_srv(ctx, var, glsl_type_get_texture_count(var->type))) return false; } + if (ctx->opts->environment == DXIL_ENVIRONMENT_VULKAN) { + nir_foreach_image_variable(var, ctx->shader) { + if ((var->data.access & ACCESS_NON_WRITEABLE) && + !emit_srv(ctx, var, glsl_type_get_image_count(var->type))) + return false; + } + } + /* Handle read-only SSBOs as SRVs */ if (ctx->opts->environment == DXIL_ENVIRONMENT_VULKAN) { nir_foreach_variable_with_modes(var, ctx->shader, nir_var_mem_ssbo) { @@ -5258,6 +5270,10 @@ emit_module(struct ntd_context *ctx, const struct nir_to_dxil_options *opts) } nir_foreach_image_variable(var, ctx->shader) { + if (ctx->opts->environment == DXIL_ENVIRONMENT_VULKAN && + var && (var->data.access & ACCESS_NON_WRITEABLE)) + continue; // already handled in SRV + if (!emit_uav_var(ctx, var, glsl_type_get_image_count(var->type))) return false; }