summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Natalie <jenatali@microsoft.com>2021-04-16 20:55:45 -0700
committerMarge Bot <eric+marge@anholt.net>2021-04-27 23:13:19 +0000
commit29ad039d131cf5914d8c7611ae01c65c8c3b7311 (patch)
treefa8fe693cb29ce2c22e12209ffcbafd6713b16db
parent611934c556ad0a63324a269ef63fff8e6296ebe3 (diff)
microsoft/compiler: Handle unbounded arrays
Note that it's no longer sufficient to check for >=1 sampler/image in a potential array, because unbounded arrays have 0 of them. Reviewed-by: Enrico Galli <enrico.galli@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10298>
-rw-r--r--src/microsoft/compiler/nir_to_dxil.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/microsoft/compiler/nir_to_dxil.c b/src/microsoft/compiler/nir_to_dxil.c
index 5d03df95677..0b4b38fc40e 100644
--- a/src/microsoft/compiler/nir_to_dxil.c
+++ b/src/microsoft/compiler/nir_to_dxil.c
@@ -745,7 +745,10 @@ add_resource(struct ntd_context *ctx, enum dxil_resource_type type,
resource->resource_type = type;
resource->space = layout->space;
resource->lower_bound = layout->binding;
- resource->upper_bound = layout->binding + layout->size - 1;
+ if (layout->size == 0 || (uint64_t)layout->size + layout->binding >= UINT_MAX)
+ resource->upper_bound = UINT_MAX;
+ else
+ resource->upper_bound = layout->binding + layout->size - 1;
}
static unsigned
@@ -1066,7 +1069,7 @@ emit_cbv(struct ntd_context *ctx, unsigned binding, unsigned space,
const struct dxil_type *array_type = dxil_module_get_array_type(&ctx->mod, float32, size);
const struct dxil_type *buffer_type = dxil_module_get_struct_type(&ctx->mod, name,
&array_type, 1);
- const struct dxil_type *final_type = count > 1 ? dxil_module_get_array_type(&ctx->mod, buffer_type, count) : buffer_type;
+ const struct dxil_type *final_type = count != 1 ? dxil_module_get_array_type(&ctx->mod, buffer_type, count) : buffer_type;
resource_array_layout layout = {idx, binding, count, space};
const struct dxil_mdnode *cbv_meta = emit_cbv_metadata(&ctx->mod, final_type,
name, &layout, 4 * size);
@@ -3515,8 +3518,8 @@ emit_deref(struct ntd_context* ctx, nir_deref_instr* instr)
nir_variable *var = nir_deref_instr_get_variable(instr);
assert(var);
- if (glsl_type_get_sampler_count(var->type) == 0 &&
- glsl_type_get_image_count(var->type) == 0)
+ if (!glsl_type_is_sampler(glsl_without_array(var->type)) &&
+ !glsl_type_is_image(glsl_without_array(var->type)))
return true;
const struct glsl_type *type = instr->type;
@@ -4305,8 +4308,9 @@ emit_module(struct ntd_context *ctx, const struct nir_to_dxil_options *opts)
/* Samplers */
nir_foreach_variable_with_modes(var, ctx->shader, nir_var_uniform) {
unsigned count = glsl_type_get_sampler_count(var->type);
- if (var->data.mode == nir_var_uniform && count &&
- glsl_get_sampler_result_type(glsl_without_array(var->type)) == GLSL_TYPE_VOID) {
+ const struct glsl_type *without_array = glsl_without_array(var->type);
+ if (var->data.mode == nir_var_uniform && glsl_type_is_sampler(without_array) &&
+ glsl_get_sampler_result_type(without_array) == GLSL_TYPE_VOID) {
if (!emit_sampler(ctx, var, count))
return false;
}
@@ -4315,8 +4319,9 @@ 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_sampler_count(var->type);
- if (var->data.mode == nir_var_uniform && count &&
- glsl_get_sampler_result_type(glsl_without_array(var->type)) != GLSL_TYPE_VOID) {
+ const struct glsl_type *without_array = glsl_without_array(var->type);
+ if (var->data.mode == nir_var_uniform && glsl_type_is_sampler(without_array) &&
+ glsl_get_sampler_result_type(without_array) != GLSL_TYPE_VOID) {
if (!emit_srv(ctx, var, count))
return false;
}
@@ -4365,9 +4370,8 @@ emit_module(struct ntd_context *ctx, const struct nir_to_dxil_options *opts)
}
nir_foreach_variable_with_modes(var, ctx->shader, nir_var_uniform) {
- unsigned count = glsl_type_get_image_count(var->type);
- if (var->data.mode == nir_var_uniform && count) {
- if (!emit_uav_var(ctx, var, count))
+ if (var->data.mode == nir_var_uniform && glsl_type_is_image(glsl_without_array(var->type))) {
+ if (!emit_uav_var(ctx, var, glsl_type_get_image_count(var->type)))
return false;
}
}