glsl: use UniformHash to find storage location

There is no need to be looping over all the uniforms.

Reviewed-by: Eric Anholt <eric@anholt.net>
This commit is contained in:
Timothy Arceri 2016-07-27 15:20:44 +10:00
parent 82e153daff
commit 549222f5f8

View file

@ -22,6 +22,7 @@
*/ */
#include "main/core.h" #include "main/core.h"
#include "program/hash_table.h"
#include "ir.h" #include "ir.h"
#include "linker.h" #include "linker.h"
#include "ir_uniform.h" #include "ir_uniform.h"
@ -33,14 +34,13 @@
namespace linker { namespace linker {
gl_uniform_storage * gl_uniform_storage *
get_storage(gl_uniform_storage *storage, unsigned num_storage, get_storage(struct gl_shader_program *prog, const char *name)
const char *name)
{ {
for (unsigned int i = 0; i < num_storage; i++) { unsigned id;
if (strcmp(name, storage[i].name) == 0) if (prog->UniformHash->get(id, name))
return &storage[i]; return &prog->UniformStorage[id];
}
assert(!"No uniform storage found!");
return NULL; return NULL;
} }
@ -108,13 +108,10 @@ set_opaque_binding(void *mem_ctx, gl_shader_program *prog,
element_name, binding); element_name, binding);
} }
} else { } else {
struct gl_uniform_storage *const storage = struct gl_uniform_storage *const storage = get_storage(prog, name);
get_storage(prog->UniformStorage, prog->NumUniformStorage, name);
if (storage == NULL) { if (!storage)
assert(storage != NULL);
return; return;
}
const unsigned elements = MAX2(storage->array_elements, 1); const unsigned elements = MAX2(storage->array_elements, 1);
@ -207,14 +204,10 @@ set_uniform_initializer(void *mem_ctx, gl_shader_program *prog,
return; return;
} }
struct gl_uniform_storage *const storage = struct gl_uniform_storage *const storage = get_storage(prog, name);
get_storage(prog->UniformStorage,
prog->NumUniformStorage, if (!storage)
name);
if (storage == NULL) {
assert(storage != NULL);
return; return;
}
if (val->type->is_array()) { if (val->type->is_array()) {
const enum glsl_base_type base_type = const enum glsl_base_type base_type =