X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fcompiler%2Fglsl%2Flink_uniforms.cpp;h=c29fbed743590d1f05183f49e0954c10fd5635d8;hb=abc8a702d0f01852f85705a87c9d624300c1efec;hp=cd00837cca929a351932b39b0f7a9a08f7802e4e;hpb=a1da57c19c27505b9eab4792355f2f1b5c774a0a;p=mesa.git diff --git a/src/compiler/glsl/link_uniforms.cpp b/src/compiler/glsl/link_uniforms.cpp index cd00837cca9..c29fbed7435 100644 --- a/src/compiler/glsl/link_uniforms.cpp +++ b/src/compiler/glsl/link_uniforms.cpp @@ -45,7 +45,7 @@ /** * Count the backing storage requirements for a type */ -static unsigned +unsigned values_for_type(const glsl_type *type) { if (type->is_sampler()) { @@ -535,7 +535,7 @@ private: const char *str_end; while((str_start = strchr(name_copy, '[')) && (str_end = strchr(name_copy, ']'))) { - memmove(str_start, str_end + 1, 1 + strlen(str_end)); + memmove(str_start, str_end + 1, 1 + strlen(str_end + 1)); } unsigned index = 0; @@ -901,9 +901,10 @@ link_update_uniform_buffer_variables(struct gl_linked_shader *shader, var->data.mode == ir_var_shader_storage); unsigned num_blocks = var->data.mode == ir_var_uniform ? - shader->NumUniformBlocks : shader->NumShaderStorageBlocks; + shader->Program->info.num_ubos : shader->Program->info.num_ssbos; struct gl_uniform_block **blks = var->data.mode == ir_var_uniform ? - shader->UniformBlocks : shader->ShaderStorageBlocks; + shader->Program->sh.UniformBlocks : + shader->Program->sh.ShaderStorageBlocks; if (var->is_interface_instance()) { const ir_array_refcount_entry *const entry = v.get_variable_entry(var); @@ -1041,12 +1042,10 @@ find_empty_block(struct gl_shader_program *prog, static void link_setup_uniform_remap_tables(struct gl_context *ctx, - struct gl_shader_program *prog, - unsigned num_explicit_uniform_locs) + struct gl_shader_program *prog) { - unsigned total_entries = num_explicit_uniform_locs; - unsigned empty_locs = - prog->NumUniformRemapTable - num_explicit_uniform_locs; + unsigned total_entries = prog->NumExplicitUniformLocations; + unsigned empty_locs = prog->NumUniformRemapTable - total_entries; /* Reserve all the explicit locations of the active uniforms. */ for (unsigned i = 0; i < prog->data->NumUniformStorage; i++) { @@ -1205,8 +1204,7 @@ link_setup_uniform_remap_tables(struct gl_context *ctx, static void link_assign_uniform_storage(struct gl_context *ctx, struct gl_shader_program *prog, - const unsigned num_data_slots, - unsigned num_explicit_uniform_locs) + const unsigned num_data_slots) { /* On the outside chance that there were no uniforms, bail out. */ @@ -1215,11 +1213,17 @@ link_assign_uniform_storage(struct gl_context *ctx, unsigned int boolean_true = ctx->Const.UniformBooleanTrue; - prog->data->UniformStorage = rzalloc_array(prog, struct gl_uniform_storage, - prog->data->NumUniformStorage); - union gl_constant_value *data = rzalloc_array(prog->data->UniformStorage, - union gl_constant_value, - num_data_slots); + union gl_constant_value *data; + if (prog->data->UniformStorage == NULL) { + prog->data->UniformStorage = rzalloc_array(prog, + struct gl_uniform_storage, + prog->data->NumUniformStorage); + data = rzalloc_array(prog->data->UniformStorage, + union gl_constant_value, num_data_slots); + } else { + data = prog->data->UniformDataSlots; + } + #ifndef NDEBUG union gl_constant_value *data_end = &data[num_data_slots]; #endif @@ -1243,15 +1247,24 @@ link_assign_uniform_storage(struct gl_context *ctx, parcel.set_and_process(var); } - prog->_LinkedShaders[i]->active_samplers = parcel.shader_samplers_used; + prog->_LinkedShaders[i]->Program->SamplersUsed = + parcel.shader_samplers_used; prog->_LinkedShaders[i]->shadow_samplers = parcel.shader_shadow_samplers; - STATIC_ASSERT(sizeof(prog->_LinkedShaders[i]->SamplerTargets) == + STATIC_ASSERT(sizeof(prog->_LinkedShaders[i]->Program->sh.SamplerTargets) == sizeof(parcel.targets)); - memcpy(prog->_LinkedShaders[i]->SamplerTargets, parcel.targets, - sizeof(prog->_LinkedShaders[i]->SamplerTargets)); + memcpy(prog->_LinkedShaders[i]->Program->sh.SamplerTargets, + parcel.targets, + sizeof(prog->_LinkedShaders[i]->Program->sh.SamplerTargets)); } + /* If this is a fallback compile for a cache miss we already have the + * correct uniform mappings and we don't want to reinitialise uniforms so + * just return now. + */ + if (prog->data->cache_fallback) + return; + #ifndef NDEBUG for (unsigned i = 0; i < prog->data->NumUniformStorage; i++) { assert(prog->data->UniformStorage[i].storage != NULL || @@ -1263,19 +1276,24 @@ link_assign_uniform_storage(struct gl_context *ctx, assert(parcel.values == data_end); #endif - link_setup_uniform_remap_tables(ctx, prog, num_explicit_uniform_locs); + link_setup_uniform_remap_tables(ctx, prog); + + /* Set shader cache fields */ + prog->data->NumUniformDataSlots = num_data_slots; + prog->data->UniformDataSlots = data; link_set_uniform_initializers(prog, boolean_true); } void link_assign_uniform_locations(struct gl_shader_program *prog, - struct gl_context *ctx, - unsigned int num_explicit_uniform_locs) + struct gl_context *ctx) { - ralloc_free(prog->data->UniformStorage); - prog->data->UniformStorage = NULL; - prog->data->NumUniformStorage = 0; + if (!prog->data->cache_fallback) { + ralloc_free(prog->data->UniformStorage); + prog->data->UniformStorage = NULL; + prog->data->NumUniformStorage = 0; + } if (prog->UniformHash != NULL) { prog->UniformHash->clear(); @@ -1298,17 +1316,6 @@ link_assign_uniform_locations(struct gl_shader_program *prog, if (sh == NULL) continue; - /* Uniforms that lack an initializer in the shader code have an initial - * value of zero. This includes sampler uniforms. - * - * Page 24 (page 30 of the PDF) of the GLSL 1.20 spec says: - * - * "The link time initial value is either the value of the variable's - * initializer, if present, or 0 if no initializer is present. Sampler - * types cannot have initializers." - */ - memset(sh->SamplerUnits, 0, sizeof(sh->SamplerUnits)); - link_update_uniform_buffer_variables(sh, i); /* Reset various per-shader target counts. @@ -1325,14 +1332,14 @@ link_assign_uniform_locations(struct gl_shader_program *prog, uniform_size.process(var); } - sh->num_samplers = uniform_size.num_shader_samplers; - sh->NumImages = uniform_size.num_shader_images; + sh->Program->info.num_textures = uniform_size.num_shader_samplers; + sh->Program->info.num_images = uniform_size.num_shader_images; sh->num_uniform_components = uniform_size.num_shader_uniform_components; sh->num_combined_uniform_components = sh->num_uniform_components; - for (unsigned i = 0; i < sh->NumUniformBlocks; i++) { + for (unsigned i = 0; i < sh->Program->info.num_ubos; i++) { sh->num_combined_uniform_components += - sh->UniformBlocks[i]->UniformBufferSize / 4; + sh->Program->sh.UniformBlocks[i]->UniformBufferSize / 4; } } @@ -1343,6 +1350,5 @@ link_assign_uniform_locations(struct gl_shader_program *prog, hiddenUniforms->iterate(assign_hidden_uniform_slot_id, &uniform_size); delete hiddenUniforms; - link_assign_uniform_storage(ctx, prog, uniform_size.num_values, - num_explicit_uniform_locs); + link_assign_uniform_storage(ctx, prog, uniform_size.num_values); }