mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-27 06:10:13 +01:00
linker: Set block bindings based on UniformBlocks rather than UniformStorage
For blocks, gl_shader_program::UniformStorage isn't very useful. The names stored there are the names of the elements of the block, so finding blocks with an instance name is hard. There is also only one entry in ::UniformStorage for each element of a block array, and that is a deal breaker. Using ::UniformBlocks is what _mesa_GetUniformBlockIndex does. I contemplated sharing code between set_block_binding and _mesa_GetUniformBlockIndex, but building the stand-alone compiler and the unit tests make this hard. I plan to return to this effort shortly. Signed-off-by: Ian Romanick <ian.d.romanick@intel.com> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=76323 Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Cc: "10.1" <mesa-stable@lists.freedesktop.org> Cc: github@socker.lepus.uberspace.de
This commit is contained in:
parent
157391a41b
commit
cc42717b50
1 changed files with 21 additions and 11 deletions
|
|
@ -46,6 +46,18 @@ get_storage(gl_uniform_storage *storage, unsigned num_storage,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static unsigned
|
||||
get_uniform_block_index(const gl_shader_program *shProg,
|
||||
const char *uniformBlockName)
|
||||
{
|
||||
for (unsigned i = 0; i < shProg->NumUniformBlocks; i++) {
|
||||
if (!strcmp(shProg->UniformBlocks[i].Name, uniformBlockName))
|
||||
return i;
|
||||
}
|
||||
|
||||
return GL_INVALID_INDEX;
|
||||
}
|
||||
|
||||
void
|
||||
copy_constant_to_storage(union gl_constant_value *storage,
|
||||
const ir_constant *val,
|
||||
|
|
@ -123,29 +135,24 @@ set_sampler_binding(gl_shader_program *prog, const char *name, int binding)
|
|||
}
|
||||
|
||||
void
|
||||
set_block_binding(gl_shader_program *prog, const char *name, int binding)
|
||||
set_block_binding(gl_shader_program *prog, const char *block_name, int binding)
|
||||
{
|
||||
struct gl_uniform_storage *const storage =
|
||||
get_storage(prog->UniformStorage, prog->NumUserUniformStorage, name);
|
||||
const unsigned block_index = get_uniform_block_index(prog, block_name);
|
||||
|
||||
if (storage == NULL) {
|
||||
assert(storage != NULL);
|
||||
if (block_index == GL_INVALID_INDEX) {
|
||||
assert(block_index != GL_INVALID_INDEX);
|
||||
return;
|
||||
}
|
||||
|
||||
if (storage->block_index != -1) {
|
||||
/* This is a field of a UBO. val is the binding index. */
|
||||
for (int i = 0; i < MESA_SHADER_STAGES; i++) {
|
||||
int stage_index = prog->UniformBlockStageIndex[i][storage->block_index];
|
||||
int stage_index = prog->UniformBlockStageIndex[i][block_index];
|
||||
|
||||
if (stage_index != -1) {
|
||||
struct gl_shader *sh = prog->_LinkedShaders[i];
|
||||
sh->UniformBlocks[stage_index].Binding = binding;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
storage->initialized = true;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -253,7 +260,10 @@ link_set_uniform_initializers(struct gl_shader_program *prog)
|
|||
|| (type->is_array() && type->fields.array->is_sampler())) {
|
||||
linker::set_sampler_binding(prog, var->name, var->data.binding);
|
||||
} else if (var->is_in_uniform_block()) {
|
||||
linker::set_block_binding(prog, var->name, var->data.binding);
|
||||
const glsl_type *const iface_type = var->get_interface_type();
|
||||
|
||||
linker::set_block_binding(prog, iface_type->name,
|
||||
var->data.binding);
|
||||
} else {
|
||||
assert(!"Explicit binding not on a sampler or UBO.");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue