From 3e33ed9c9d84dc8cadf5d39ebc2c1a3a52e4f367 Mon Sep 17 00:00:00 2001 From: Andrii Simiklit Date: Tue, 5 Mar 2019 15:45:57 +0200 Subject: [PATCH] glsl: fix assigning the binding point This change is needed because of answer by Khronos Group: https://github.com/KhronosGroup/OpenGL-API/issues/46 This fix solves two problems: 1. Fixes the tests: https://patchwork.freedesktop.org/patch/286287/ 2. Fixes the root cause of a deqp issue. Signed-off-by: Andrii Simiklit --- .../glsl/link_uniform_block_active_visitor.cpp | 1 + .../glsl/link_uniform_block_active_visitor.h | 1 + src/compiler/glsl/link_uniform_blocks.cpp | 13 ++++++++----- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/compiler/glsl/link_uniform_block_active_visitor.cpp b/src/compiler/glsl/link_uniform_block_active_visitor.cpp index 368981852c0..0af3b312071 100644 --- a/src/compiler/glsl/link_uniform_block_active_visitor.cpp +++ b/src/compiler/glsl/link_uniform_block_active_visitor.cpp @@ -103,6 +103,7 @@ process_arrays(void *mem_ctx, ir_dereference_array *ir, if (*ub_array_ptr == NULL) { *ub_array_ptr = rzalloc(mem_ctx, struct uniform_block_array_elements); (*ub_array_ptr)->ir = ir; + (*ub_array_ptr)->original_dim_size = block->type->length; } struct uniform_block_array_elements *ub_array = *ub_array_ptr; diff --git a/src/compiler/glsl/link_uniform_block_active_visitor.h b/src/compiler/glsl/link_uniform_block_active_visitor.h index fbac65d5b67..a8ea3f52b6d 100644 --- a/src/compiler/glsl/link_uniform_block_active_visitor.h +++ b/src/compiler/glsl/link_uniform_block_active_visitor.h @@ -32,6 +32,7 @@ struct uniform_block_array_elements { unsigned num_array_elements; ir_dereference_array *ir; + unsigned original_dim_size; struct uniform_block_array_elements *array; }; diff --git a/src/compiler/glsl/link_uniform_blocks.cpp b/src/compiler/glsl/link_uniform_blocks.cpp index 0b890586298..1665fc3f8cb 100644 --- a/src/compiler/glsl/link_uniform_blocks.cpp +++ b/src/compiler/glsl/link_uniform_blocks.cpp @@ -244,18 +244,21 @@ process_block_array(struct uniform_block_array_elements *ub_array, char **name, for (unsigned j = 0; j < ub_array->num_array_elements; j++) { size_t new_length = name_length; + unsigned int element_idx = ub_array->array_elements[j]; /* Append the subscript to the current variable name */ - ralloc_asprintf_rewrite_tail(name, &new_length, "[%u]", - ub_array->array_elements[j]); + ralloc_asprintf_rewrite_tail(name, &new_length, "[%u]", element_idx); if (ub_array->array) { + unsigned boffset = (*binding_offset) + (element_idx * + ub_array->original_dim_size); process_block_array(ub_array->array, name, new_length, blocks, parcel, variables, b, block_index, - binding_offset, ctx, prog, first_index); + &boffset, ctx, prog, first_index); } else { + unsigned boffset = (*binding_offset) + element_idx; process_block_array_leaf(*name, blocks, parcel, variables, b, block_index, - binding_offset, *block_index - first_index, + &boffset, *block_index - first_index, ctx, prog); } } @@ -307,7 +310,6 @@ process_block_array_leaf(const char *name, (unsigned)(ptrdiff_t)(&variables[parcel->index] - blocks[i].Uniforms); *block_index = *block_index + 1; - *binding_offset = *binding_offset + 1; } /* This function resizes the array types of the block so that later we can use @@ -440,6 +442,7 @@ link_uniform_blocks(void *mem_ctx, GLSL_INTERFACE_PACKING_PACKED)) { b->type = resize_block_array(b->type, b->array); b->var->type = b->type; + b->var->data.max_array_access = b->type->length - 1; } block_size.num_active_uniforms = 0; -- 2.17.1