From 76ce7752403912642cd00905f1d7a5f8bf21d219 Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Tue, 21 Jan 2020 14:57:37 +1100 Subject: [PATCH] glsl: correctly set explicit offsets for struct members MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This correctly sets offsets set in glsl when using the nir linker. Reviewed-by: Alejandro Piñeiro Part-of: --- src/compiler/glsl/gl_nir_link_uniforms.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/compiler/glsl/gl_nir_link_uniforms.c b/src/compiler/glsl/gl_nir_link_uniforms.c index d4ab8628c59..88154cd6fcb 100644 --- a/src/compiler/glsl/gl_nir_link_uniforms.c +++ b/src/compiler/glsl/gl_nir_link_uniforms.c @@ -181,6 +181,7 @@ struct nir_link_uniforms_state { /* per-variable */ nir_variable *current_var; + const struct glsl_type *current_ifc_type; int offset; bool var_is_in_block; int top_level_array_size; @@ -637,9 +638,14 @@ nir_link_uniform(struct gl_context *ctx, * a buffer object. For variables not backed by a buffer object, * offset is -1. */ - if (state->var_is_in_block && prog->data->spirv) { - state->offset = - struct_base_offset + glsl_get_struct_field_offset(type, i); + if (state->var_is_in_block) { + if (prog->data->spirv) { + state->offset = + struct_base_offset + glsl_get_struct_field_offset(type, i); + } else if (glsl_get_struct_field_offset(type, i) != -1 && + type == state->current_ifc_type) { + state->offset = glsl_get_struct_field_offset(type, i); + } } /* Append '.field' to the current variable name. */ @@ -968,6 +974,7 @@ gl_nir_link_uniforms(struct gl_context *ctx, nir_foreach_variable(var, &nir->uniforms) { state.current_var = var; + state.current_ifc_type = NULL; state.offset = 0; state.var_is_in_block = nir_variable_is_in_block(var); state.top_level_array_size = 0; @@ -1013,6 +1020,7 @@ gl_nir_link_uniforms(struct gl_context *ctx, ((!prog->data->spirv && glsl_without_array(type) == var->interface_type) || (prog->data->spirv && type == var->interface_type))) { type = glsl_without_array(var->type); + state.current_ifc_type = type; name = ralloc_strdup(NULL, glsl_get_type_name(type)); } else { name = ralloc_strdup(NULL, var->name); -- 2.30.2