Skip to content
This repository was archived by the owner on Jan 7, 2023. It is now read-only.

Commit f07dea1

Browse files
asimiklitstrassek
authored andcommitted
FROMLIST: glsl: fix a binding points assignment for ssbo/ubo arrays
This is needed to be in agreement with spec requirements: KhronosGroup/OpenGL-API#46 Piers Daniell: "We discussed this in the OpenGL/ES working group meeting and agreed that eliminating unused elements from the interface block array is not desirable. There is no statement in the spec that this takes place and it would be highly implementation dependent if it happens. If the application has an "interface" in the shader they need to match up with the API it would be quite confusing to have the binding point get compacted. So the answer is no, the binding points aren't affected by unused elements in the interface block array." v2: - 'original_dim_size' field moved above to keep the struct packed better on 64-bit - added a comment for 'total_num_array_elements' field - fixed a binding point calculations for SSBOs array of arrays ( Ian Romanick <ian.d.romanick@intel.com> ) - fixed binding point calculations for non-packed SSBOs Fixes: 8cf1333 "glsl: link uniform block arrays of arrays" Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=109532 Reported-By: Ilia Mirkin <imirkin@alum.mit.edu> Tested-by: Fritz Koenig <frkoenig@google.com> Signed-off-by: Andrii Simiklit <andrii.simiklit@globallogic.com> TEST=[CTS 9.0_r8} dEQP-GLES31.functional.ssbo.layout.random.all_per_block_buffers#18 (am from https://gitlab.freedesktop.org/mesa/mesa/merge_requests/332) Signed-off-by: Kevin Strasser <kevin.strasser@intel.com>
1 parent 03c0457 commit f07dea1

3 files changed

Lines changed: 25 additions & 12 deletions

File tree

src/compiler/glsl/link_uniform_block_active_visitor.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ process_arrays(void *mem_ctx, ir_dereference_array *ir,
103103
if (*ub_array_ptr == NULL) {
104104
*ub_array_ptr = rzalloc(mem_ctx, struct uniform_block_array_elements);
105105
(*ub_array_ptr)->ir = ir;
106+
(*ub_array_ptr)->total_num_array_elements =
107+
ir->array->type->arrays_of_arrays_size();
106108
}
107109

108110
struct uniform_block_array_elements *ub_array = *ub_array_ptr;
@@ -199,6 +201,7 @@ link_uniform_block_active_visitor::visit(ir_variable *var)
199201
(*ub_array)->array_elements,
200202
unsigned,
201203
(*ub_array)->num_array_elements);
204+
(*ub_array)->total_num_array_elements = type->arrays_of_arrays_size();
202205

203206
for (unsigned i = 0; i < (*ub_array)->num_array_elements; i++) {
204207
(*ub_array)->array_elements[i] = i;

src/compiler/glsl/link_uniform_block_active_visitor.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@
3030
struct uniform_block_array_elements {
3131
unsigned *array_elements;
3232
unsigned num_array_elements;
33+
/**
34+
* Size of the array before array-trimming optimizations.
35+
*
36+
* Locations are only assigned to active array elements, but the location
37+
* values are calculated as if all elements are active. The total number
38+
* of elements in an array including the elements in arrays of arrays before
39+
* inactive elements are removed is needed to be perform that calculation.
40+
*/
41+
unsigned total_num_array_elements;
3342

3443
ir_dereference_array *ir;
3544

src/compiler/glsl/link_uniform_blocks.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ static void process_block_array_leaf(const char *name, gl_uniform_block *blocks,
222222
gl_uniform_buffer_variable *variables,
223223
const struct link_uniform_block_active *const b,
224224
unsigned *block_index,
225-
unsigned *binding_offset,
225+
unsigned binding_offset,
226226
unsigned linearized_index,
227227
struct gl_context *ctx,
228228
struct gl_shader_program *prog);
@@ -237,25 +237,28 @@ process_block_array(struct uniform_block_array_elements *ub_array, char **name,
237237
size_t name_length, gl_uniform_block *blocks,
238238
ubo_visitor *parcel, gl_uniform_buffer_variable *variables,
239239
const struct link_uniform_block_active *const b,
240-
unsigned *block_index, unsigned *binding_offset,
240+
unsigned *block_index, unsigned binding_offset,
241241
struct gl_context *ctx, struct gl_shader_program *prog,
242242
unsigned first_index)
243243
{
244244
for (unsigned j = 0; j < ub_array->num_array_elements; j++) {
245245
size_t new_length = name_length;
246246

247+
unsigned int element_idx = ub_array->array_elements[j];
247248
/* Append the subscript to the current variable name */
248-
ralloc_asprintf_rewrite_tail(name, &new_length, "[%u]",
249-
ub_array->array_elements[j]);
249+
ralloc_asprintf_rewrite_tail(name, &new_length, "[%u]", element_idx);
250250

251251
if (ub_array->array) {
252+
unsigned boffset = binding_offset + (element_idx *
253+
ub_array->array->total_num_array_elements);
252254
process_block_array(ub_array->array, name, new_length, blocks,
253255
parcel, variables, b, block_index,
254-
binding_offset, ctx, prog, first_index);
256+
boffset, ctx, prog, first_index);
255257
} else {
258+
unsigned boffset = binding_offset + element_idx;
256259
process_block_array_leaf(*name, blocks,
257260
parcel, variables, b, block_index,
258-
binding_offset, *block_index - first_index,
261+
boffset, *block_index - first_index,
259262
ctx, prog);
260263
}
261264
}
@@ -266,7 +269,7 @@ process_block_array_leaf(const char *name,
266269
gl_uniform_block *blocks,
267270
ubo_visitor *parcel, gl_uniform_buffer_variable *variables,
268271
const struct link_uniform_block_active *const b,
269-
unsigned *block_index, unsigned *binding_offset,
272+
unsigned *block_index, unsigned binding_offset,
270273
unsigned linearized_index,
271274
struct gl_context *ctx, struct gl_shader_program *prog)
272275
{
@@ -283,7 +286,7 @@ process_block_array_leaf(const char *name,
283286
* block binding and each subsequent element takes the next consecutive
284287
* uniform block binding point.
285288
*/
286-
blocks[i].Binding = (b->has_binding) ? b->binding + *binding_offset : 0;
289+
blocks[i].Binding = (b->has_binding) ? b->binding + binding_offset : 0;
287290

288291
blocks[i].UniformBufferSize = 0;
289292
blocks[i]._Packing = glsl_interface_packing(type->interface_packing);
@@ -307,7 +310,6 @@ process_block_array_leaf(const char *name,
307310
(unsigned)(ptrdiff_t)(&variables[parcel->index] - blocks[i].Uniforms);
308311

309312
*block_index = *block_index + 1;
310-
*binding_offset = *binding_offset + 1;
311313
}
312314

313315
/* This function resizes the array types of the block so that later we can use
@@ -370,20 +372,19 @@ create_buffer_blocks(void *mem_ctx, struct gl_context *ctx,
370372
if ((create_ubo_blocks && !b->is_shader_storage) ||
371373
(!create_ubo_blocks && b->is_shader_storage)) {
372374

373-
unsigned binding_offset = 0;
374375
if (b->array != NULL) {
375376
char *name = ralloc_strdup(NULL,
376377
block_type->without_array()->name);
377378
size_t name_length = strlen(name);
378379

379380
assert(b->has_instance_name);
380381
process_block_array(b->array, &name, name_length, blocks, &parcel,
381-
variables, b, &i, &binding_offset, ctx, prog,
382+
variables, b, &i, 0, ctx, prog,
382383
i);
383384
ralloc_free(name);
384385
} else {
385386
process_block_array_leaf(block_type->name, blocks, &parcel,
386-
variables, b, &i, &binding_offset,
387+
variables, b, &i, 0,
387388
0, ctx, prog);
388389
}
389390
}

0 commit comments

Comments
 (0)