From: Mike Blumenkrantz Date: Mon, 22 Jun 2020 19:11:16 +0000 (-0400) Subject: zink: correctly handle ARB_arrays_of_arrays in ntv for samplers X-Git-Tag: upstream/21.0.0~4705 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7767c3dae304e68d583658cb9e9924732fe34906;p=platform%2Fupstream%2Fmesa.git zink: correctly handle ARB_arrays_of_arrays in ntv for samplers this extension allows for array nesting with no clear limitations, so we need to ensure that we use the "unrolled" array size in a couple places in order to correctly bind and access these types of arrays in shaders fixes spec@arb_separate_shader_objects@active sampler conflict and others Reviewed-by: Erik Faye-Lund Part-of: --- diff --git a/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c b/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c index 00dea03..073b8ee 100644 --- a/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c +++ b/src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c @@ -536,7 +536,11 @@ emit_sampler(struct ntv_context *ctx, struct nir_variable *var) sampled_type); if (glsl_type_is_array(var->type)) { - for (int i = 0; i < glsl_get_length(var->type); ++i) { + /* ARB_arrays_of_arrays from GLSL 1.30 allows nesting of arrays, so we just + * use the total array size if we encounter a nested array + */ + unsigned size = glsl_get_aoa_size(var->type); + for (int i = 0; i < size; ++i) { SpvId var_id = spirv_builder_emit_var(&ctx->builder, pointer_type, SpvStorageClassUniformConstant); diff --git a/src/gallium/drivers/zink/zink_compiler.c b/src/gallium/drivers/zink/zink_compiler.c index 8f0c16c..740b795 100644 --- a/src/gallium/drivers/zink/zink_compiler.c +++ b/src/gallium/drivers/zink/zink_compiler.c @@ -289,9 +289,24 @@ zink_shader_create(struct zink_screen *screen, struct nir_shader *nir, ret->num_bindings++; } else { assert(var->data.mode == nir_var_uniform); - if (glsl_type_is_array(var->type) && - glsl_type_is_sampler(glsl_get_array_element(var->type))) { - for (int i = 0; i < glsl_get_length(var->type); ++i) { + if (glsl_type_is_sampler(var->type)) { + int binding = zink_binding(nir->info.stage, + VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, + var->data.binding); + ret->bindings[ret->num_bindings].index = var->data.binding; + ret->bindings[ret->num_bindings].binding = binding; + ret->bindings[ret->num_bindings].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; + ret->num_bindings++; + } else if (glsl_type_is_array(var->type)) { + /* need to unroll possible arrays of arrays before checking type + * in order to handle ARB_arrays_of_arrays extension + */ + const struct glsl_type *type = glsl_without_array(var->type); + if (!glsl_type_is_sampler(type)) + continue; + + unsigned size = glsl_get_aoa_size(var->type); + for (int i = 0; i < size; ++i) { int binding = zink_binding(nir->info.stage, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, var->data.binding + i); @@ -300,14 +315,6 @@ zink_shader_create(struct zink_screen *screen, struct nir_shader *nir, ret->bindings[ret->num_bindings].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; ret->num_bindings++; } - } else if (glsl_type_is_sampler(var->type)) { - int binding = zink_binding(nir->info.stage, - VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, - var->data.binding); - ret->bindings[ret->num_bindings].index = var->data.binding; - ret->bindings[ret->num_bindings].binding = binding; - ret->bindings[ret->num_bindings].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; - ret->num_bindings++; } } }