diff --git a/src/compiler/glsl/gl_nir_link_uniform_blocks.c b/src/compiler/glsl/gl_nir_link_uniform_blocks.c index b27c77dc5f9..f519aae7b65 100644 --- a/src/compiler/glsl/gl_nir_link_uniform_blocks.c +++ b/src/compiler/glsl/gl_nir_link_uniform_blocks.c @@ -876,8 +876,8 @@ allocate_uniform_blocks(void *mem_ctx, struct hash_table *block_hash, struct gl_linked_shader *shader, struct gl_uniform_block **out_blks, unsigned *num_blocks, struct gl_uniform_buffer_variable **out_variables, - unsigned *num_variables, - enum block_type block_type) + unsigned *num_variables, enum block_type block_type, + bool supports_std430) { *num_variables = 0; *num_blocks = 0; @@ -903,6 +903,34 @@ allocate_uniform_blocks(void *mem_ctx, struct hash_table *block_hash, if (prog->data->spirv) { count_block(var->type, num_blocks, num_variables); } else { + /* For UBO and SSBO variables, we need explicit types */ + const glsl_type *explicit_ifc_type = + glsl_get_explicit_interface_type(var->interface_type, + supports_std430); + + var->interface_type = explicit_ifc_type; + + if (glsl_type_is_interface(glsl_without_array(var->type))) { + /* If the type contains the interface, wrap the explicit type in + * the right number of arrays. + */ + var->type = glsl_type_wrap_in_arrays(explicit_ifc_type, var->type); + } else { + /* Otherwise, this variable is one entry in the interface */ + UNUSED bool found = false; + for (unsigned i = 0; i < explicit_ifc_type->length; i++) { + const glsl_struct_field *field = + &explicit_ifc_type->fields.structure[i]; + if (strcmp(var->name, field->name) != 0) + continue; + + var->type = field->type; + found = true; + break; + } + assert(found); + } + /* Process the block. Bail if there was an error. */ struct link_uniform_block_active *b = process_block(mem_ctx, block_hash, var); @@ -1159,7 +1187,7 @@ link_linked_shader_uniform_blocks(void *mem_ctx, allocate_uniform_blocks(mem_ctx, block_hash, prog, shader, blocks, num_blocks, &variables, &num_variables, - block_type); + block_type, consts->UseSTD430AsDefaultPacking); if (!prog->data->LinkStatus) return; diff --git a/src/compiler/glsl/glsl_to_nir.cpp b/src/compiler/glsl/glsl_to_nir.cpp index fb7444f2c11..db116c60f0e 100644 --- a/src/compiler/glsl/glsl_to_nir.cpp +++ b/src/compiler/glsl/glsl_to_nir.cpp @@ -501,28 +501,16 @@ nir_visitor::visit(ir_variable *ir) var->interface_type = ir->get_interface_type(); - /* For UBO and SSBO variables, we need explicit types */ if (var->data.mode & (nir_var_mem_ubo | nir_var_mem_ssbo)) { - const glsl_type *explicit_ifc_type = - glsl_get_explicit_interface_type(ir->get_interface_type(), supports_std430); - - var->interface_type = explicit_ifc_type; - - if (glsl_type_is_interface(glsl_without_array(ir->type))) { - /* If the type contains the interface, wrap the explicit type in the - * right number of arrays. - */ - var->type = glsl_type_wrap_in_arrays(explicit_ifc_type, ir->type); - } else { - /* Otherwise, this variable is one entry in the interface */ + if (!glsl_type_is_interface(glsl_without_array(ir->type))) { + /* This variable is one entry in the interface */ UNUSED bool found = false; - for (unsigned i = 0; i < explicit_ifc_type->length; i++) { + for (unsigned i = 0; i < ir->get_interface_type()->length; i++) { const glsl_struct_field *field = - &explicit_ifc_type->fields.structure[i]; + &ir->get_interface_type()->fields.structure[i]; if (strcmp(ir->name, field->name) != 0) continue; - var->type = field->type; if (field->memory_read_only) mem_access |= ACCESS_NON_WRITEABLE; if (field->memory_write_only)