glsl: move call to create explicit ifc layout out of glsl_to_nir

We move this later so that we can call glsl_to_nir() on glsl ir that
has not set the array size on unsized ifc members. Later patches will
move sizing of the arrays out of glsl ir and into the nir linker.

Acked-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29991>
This commit is contained in:
Timothy Arceri
2024-07-01 15:54:43 +10:00
committed by Marge Bot
parent 870be63c7e
commit 063d62f142
2 changed files with 35 additions and 19 deletions

View File

@@ -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;

View File

@@ -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)