X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fcompiler%2Fglsl%2Fgl_nir_link_uniforms.c;h=05b70a965077a25703ae43f3ffb4a76176078d85;hb=5d2b2b59c451915c0b11184ae47c0673fdff3146;hp=b1187c45dc14cebdf89ac92a436ef58bebe91cef;hpb=a34cc97ca3e19fb36045bf361b3a6bd865f71c7b;p=mesa.git diff --git a/src/compiler/glsl/gl_nir_link_uniforms.c b/src/compiler/glsl/gl_nir_link_uniforms.c index b1187c45dc1..05b70a96507 100644 --- a/src/compiler/glsl/gl_nir_link_uniforms.c +++ b/src/compiler/glsl/gl_nir_link_uniforms.c @@ -42,9 +42,6 @@ struct uniform_array_info { /** Set of bit-flags to note which array elements have been accessed. */ BITSET_WORD *indices; - - /** Have we rezized this array yet */ - bool resized; }; /** @@ -100,7 +97,8 @@ uniform_storage_size(const struct glsl_type *type) */ static void update_array_sizes(struct gl_shader_program *prog, nir_variable *var, - struct hash_table **referenced_uniforms) + struct hash_table **referenced_uniforms, + unsigned current_var_stage) { /* For now we only resize 1D arrays. * TODO: add support for resizing more complex array types ?? @@ -133,12 +131,9 @@ update_array_sizes(struct gl_shader_program *prog, nir_variable *var, continue; struct hash_entry *entry = - _mesa_hash_table_search(referenced_uniforms[stage], var); + _mesa_hash_table_search(referenced_uniforms[stage], var->name); if (entry) { ainfo = (struct uniform_array_info *) entry->data; - if (ainfo->resized) - return; - max_array_size = MAX2(BITSET_LAST_BIT(ainfo->indices, words), max_array_size); } @@ -166,24 +161,15 @@ update_array_sizes(struct gl_shader_program *prog, nir_variable *var, max_array_size, 0); /* Update the types of dereferences in case we changed any. */ - for (unsigned stage = 0; stage < MESA_SHADER_STAGES; stage++) { - struct gl_linked_shader *sh = prog->_LinkedShaders[stage]; - if (!sh) - continue; - - struct hash_entry *entry = - _mesa_hash_table_search(referenced_uniforms[stage], var); - if (entry) { - struct uniform_array_info *ainfo = - (struct uniform_array_info *) entry->data; - util_dynarray_foreach(ainfo->deref_list, nir_deref_instr *, deref) { - (*deref)->type = var->type; - } + struct hash_entry *entry = + _mesa_hash_table_search(referenced_uniforms[current_var_stage], var->name); + if (entry) { + struct uniform_array_info *ainfo = + (struct uniform_array_info *) entry->data; + util_dynarray_foreach(ainfo->deref_list, nir_deref_instr *, deref) { + (*deref)->type = var->type; } } - - if (ainfo) - ainfo->resized = true; } } @@ -467,7 +453,7 @@ add_var_use_deref(nir_deref_instr *deref, struct hash_table *live, struct uniform_array_info *ainfo = NULL; struct hash_entry *entry = - _mesa_hash_table_search(live, deref->var); + _mesa_hash_table_search(live, deref->var->name); if (!entry && glsl_type_is_array(deref->var->type)) { ainfo = ralloc(live, struct uniform_array_info); @@ -476,8 +462,6 @@ add_var_use_deref(nir_deref_instr *deref, struct hash_table *live, ainfo->deref_list = ralloc(live, struct util_dynarray); util_dynarray_init(ainfo->deref_list, live); - - ainfo->resized = false; } if (entry) @@ -499,7 +483,7 @@ add_var_use_deref(nir_deref_instr *deref, struct hash_table *live, } assert(deref->mode == deref->var->data.mode); - _mesa_hash_table_insert(live, deref->var, ainfo); + _mesa_hash_table_insert(live, deref->var->name, ainfo); } /* Iterate over the shader and collect infomation about uniform use */ @@ -946,11 +930,12 @@ find_and_update_named_uniform_storage(struct gl_context *ctx, update_uniforms_shader_info(prog, state, uniform, type, stage); const struct glsl_type *type_no_array = glsl_without_array(type); - struct hash_entry *entry = + struct hash_entry *entry = prog->data->spirv ? NULL : _mesa_hash_table_search(state->referenced_uniforms[stage], - state->current_var); + state->current_var->name); if (entry != NULL || - glsl_get_base_type(type_no_array) == GLSL_TYPE_SUBROUTINE) + glsl_get_base_type(type_no_array) == GLSL_TYPE_SUBROUTINE || + prog->data->spirv) uniform->active_shader_mask |= 1 << stage; if (!state->var_is_in_block) @@ -1329,11 +1314,12 @@ nir_link_uniform(struct gl_context *ctx, uniform->top_level_array_size = state->top_level_array_size; uniform->top_level_array_stride = state->top_level_array_stride; - struct hash_entry *entry = + struct hash_entry *entry = prog->data->spirv ? NULL : _mesa_hash_table_search(state->referenced_uniforms[stage], - state->current_var); + state->current_var->name); if (entry != NULL || - glsl_get_base_type(type_no_array) == GLSL_TYPE_SUBROUTINE) + glsl_get_base_type(type_no_array) == GLSL_TYPE_SUBROUTINE || + prog->data->spirv) uniform->active_shader_mask |= 1 << stage; if (location >= 0) { @@ -1508,29 +1494,30 @@ gl_nir_link_uniforms(struct gl_context *ctx, /* Iterate through all linked shaders */ struct nir_link_uniforms_state state = {0,}; - /* Gather information on uniform use */ - for (unsigned stage = 0; stage < MESA_SHADER_STAGES; stage++) { - struct gl_linked_shader *sh = prog->_LinkedShaders[stage]; - if (!sh) - continue; + if (!prog->data->spirv) { + /* Gather information on uniform use */ + for (unsigned stage = 0; stage < MESA_SHADER_STAGES; stage++) { + struct gl_linked_shader *sh = prog->_LinkedShaders[stage]; + if (!sh) + continue; - state.referenced_uniforms[stage] = - _mesa_hash_table_create(NULL, _mesa_hash_pointer, - _mesa_key_pointer_equal); + state.referenced_uniforms[stage] = + _mesa_hash_table_create(NULL, _mesa_hash_string, + _mesa_key_string_equal); - nir_shader *nir = sh->Program->nir; - add_var_use_shader(nir, state.referenced_uniforms[stage]); - } + nir_shader *nir = sh->Program->nir; + add_var_use_shader(nir, state.referenced_uniforms[stage]); + } - /* Resize uniform arrays based on the maximum array index */ - for (unsigned stage = 0; stage < MESA_SHADER_STAGES; stage++) { - struct gl_linked_shader *sh = prog->_LinkedShaders[stage]; - if (!sh) - continue; + /* Resize uniform arrays based on the maximum array index */ + for (unsigned stage = 0; stage < MESA_SHADER_STAGES; stage++) { + struct gl_linked_shader *sh = prog->_LinkedShaders[stage]; + if (!sh) + continue; - nir_shader *nir = sh->Program->nir; - nir_foreach_variable(var, &nir->uniforms) - update_array_sizes(prog, var, state.referenced_uniforms); + nir_foreach_gl_uniform_variable(var, sh->Program->nir) + update_array_sizes(prog, var, state.referenced_uniforms, stage); + } } /* Count total number of uniforms and allocate storage */ @@ -1543,7 +1530,7 @@ gl_nir_link_uniforms(struct gl_context *ctx, if (!sh) continue; - nir_foreach_variable(var, &sh->Program->nir->uniforms) { + nir_foreach_gl_uniform_variable(var, sh->Program->nir) { const struct glsl_type *type = var->type; const char *name = var->name; if (nir_variable_is_in_block(var) && @@ -1594,7 +1581,7 @@ gl_nir_link_uniforms(struct gl_context *ctx, state.shader_shadow_samplers = 0; state.params = fill_parameters ? sh->Program->Parameters : NULL; - nir_foreach_variable(var, &nir->uniforms) { + nir_foreach_gl_uniform_variable(var, nir) { state.current_var = var; state.current_ifc_type = NULL; state.offset = 0; @@ -1689,7 +1676,8 @@ gl_nir_link_uniforms(struct gl_context *ctx, buffer_block_index = i; struct hash_entry *entry = - _mesa_hash_table_search(state.referenced_uniforms[shader_type], var); + _mesa_hash_table_search(state.referenced_uniforms[shader_type], + var->name); if (entry) { struct uniform_array_info *ainfo = (struct uniform_array_info *) entry->data; @@ -1704,7 +1692,8 @@ gl_nir_link_uniforms(struct gl_context *ctx, buffer_block_index = i; struct hash_entry *entry = - _mesa_hash_table_search(state.referenced_uniforms[shader_type], var); + _mesa_hash_table_search(state.referenced_uniforms[shader_type], + var->name); if (entry) blocks[i].stageref |= 1U << shader_type; @@ -1767,7 +1756,7 @@ gl_nir_link_uniforms(struct gl_context *ctx, location = j; struct hash_entry *entry = - _mesa_hash_table_search(state.referenced_uniforms[shader_type], var); + _mesa_hash_table_search(state.referenced_uniforms[shader_type], var->name); if (entry) blocks[i].stageref |= 1U << shader_type; @@ -1824,7 +1813,10 @@ gl_nir_link_uniforms(struct gl_context *ctx, return false; } - _mesa_hash_table_destroy(state.referenced_uniforms[shader_type], NULL); + if (!prog->data->spirv) { + _mesa_hash_table_destroy(state.referenced_uniforms[shader_type], + NULL); + } if (state.num_shader_samplers > ctx->Const.Program[shader_type].MaxTextureImageUnits) {