nir: Use a list instead of a hash_table for inputs, outputs, and uniforms

We never did a single hash table lookup in the entire NIR code base that I
found so there was no real benifit to doing it that way.  I suppose that
for linking, we'll probably want to be able to lookup by name but we can
leave building that hash table to the linker.  In the mean time this was
causing problems with GLSL IR -> NIR because GLSL IR doesn't guarantee us
unique names of uniforms, etc.  This was causing massive rendering isues in
the unreal4 Sun Temple demo.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
This commit is contained in:
Jason Ekstrand
2015-03-18 12:34:09 -07:00
parent 8f255f948b
commit 639115123e
7 changed files with 32 additions and 45 deletions

View File

@@ -352,15 +352,15 @@ nir_visitor::visit(ir_variable *ir)
break; break;
case nir_var_shader_in: case nir_var_shader_in:
_mesa_hash_table_insert(shader->inputs, var->name, var); exec_list_push_tail(&shader->inputs, &var->node);
break; break;
case nir_var_shader_out: case nir_var_shader_out:
_mesa_hash_table_insert(shader->outputs, var->name, var); exec_list_push_tail(&shader->outputs, &var->node);
break; break;
case nir_var_uniform: case nir_var_uniform:
_mesa_hash_table_insert(shader->uniforms, var->name, var); exec_list_push_tail(&shader->uniforms, &var->node);
break; break;
case nir_var_system_value: case nir_var_system_value:

View File

@@ -33,12 +33,9 @@ nir_shader_create(void *mem_ctx, const nir_shader_compiler_options *options)
{ {
nir_shader *shader = ralloc(mem_ctx, nir_shader); nir_shader *shader = ralloc(mem_ctx, nir_shader);
shader->uniforms = _mesa_hash_table_create(shader, _mesa_key_hash_string, exec_list_make_empty(&shader->uniforms);
_mesa_key_string_equal); exec_list_make_empty(&shader->inputs);
shader->inputs = _mesa_hash_table_create(shader, _mesa_key_hash_string, exec_list_make_empty(&shader->outputs);
_mesa_key_string_equal);
shader->outputs = _mesa_hash_table_create(shader, _mesa_key_hash_string,
_mesa_key_string_equal);
shader->options = options; shader->options = options;

View File

@@ -1380,13 +1380,13 @@ typedef struct nir_shader_compiler_options {
typedef struct nir_shader { typedef struct nir_shader {
/** hash table of name -> uniform nir_variable */ /** hash table of name -> uniform nir_variable */
struct hash_table *uniforms; struct exec_list uniforms;
/** hash table of name -> input nir_variable */ /** hash table of name -> input nir_variable */
struct hash_table *inputs; struct exec_list inputs;
/** hash table of name -> output nir_variable */ /** hash table of name -> output nir_variable */
struct hash_table *outputs; struct exec_list outputs;
/** Set of driver-specific options for the shader. /** Set of driver-specific options for the shader.
* *

View File

@@ -77,14 +77,11 @@ type_size(const struct glsl_type *type)
} }
static void static void
assign_var_locations(struct hash_table *ht, unsigned *size) assign_var_locations(struct exec_list *var_list, unsigned *size)
{ {
unsigned location = 0; unsigned location = 0;
struct hash_entry *entry; foreach_list_typed(nir_variable, var, node, var_list) {
hash_table_foreach(ht, entry) {
nir_variable *var = (nir_variable *) entry->data;
/* /*
* UBO's have their own address spaces, so don't count them towards the * UBO's have their own address spaces, so don't count them towards the
* number of global uniforms * number of global uniforms
@@ -102,9 +99,9 @@ assign_var_locations(struct hash_table *ht, unsigned *size)
static void static void
assign_var_locations_shader(nir_shader *shader) assign_var_locations_shader(nir_shader *shader)
{ {
assign_var_locations(shader->inputs, &shader->num_inputs); assign_var_locations(&shader->inputs, &shader->num_inputs);
assign_var_locations(shader->outputs, &shader->num_outputs); assign_var_locations(&shader->outputs, &shader->num_outputs);
assign_var_locations(shader->uniforms, &shader->num_uniforms); assign_var_locations(&shader->uniforms, &shader->num_uniforms);
} }
static bool static bool

View File

@@ -844,18 +844,16 @@ nir_print_shader(nir_shader *shader, FILE *fp)
print_var_state state; print_var_state state;
init_print_state(&state); init_print_state(&state);
struct hash_entry *entry; foreach_list_typed(nir_variable, var, node, &shader->uniforms) {
print_var_decl(var, &state, fp);
hash_table_foreach(shader->uniforms, entry) {
print_var_decl((nir_variable *) entry->data, &state, fp);
} }
hash_table_foreach(shader->inputs, entry) { foreach_list_typed(nir_variable, var, node, &shader->inputs) {
print_var_decl((nir_variable *) entry->data, &state, fp); print_var_decl(var, &state, fp);
} }
hash_table_foreach(shader->outputs, entry) { foreach_list_typed(nir_variable, var, node, &shader->outputs) {
print_var_decl((nir_variable *) entry->data, &state, fp); print_var_decl(var, &state, fp);
} }
foreach_list_typed(nir_variable, var, node, &shader->globals) { foreach_list_typed(nir_variable, var, node, &shader->globals) {

View File

@@ -931,17 +931,19 @@ nir_validate_shader(nir_shader *shader)
state.shader = shader; state.shader = shader;
struct hash_entry *entry; exec_list_validate(&shader->uniforms);
hash_table_foreach(shader->uniforms, entry) { foreach_list_typed(nir_variable, var, node, &shader->uniforms) {
validate_var_decl((nir_variable *) entry->data, true, &state); validate_var_decl(var, true, &state);
} }
hash_table_foreach(shader->inputs, entry) { exec_list_validate(&shader->inputs);
validate_var_decl((nir_variable *) entry->data, true, &state); foreach_list_typed(nir_variable, var, node, &shader->inputs) {
validate_var_decl(var, true, &state);
} }
hash_table_foreach(shader->outputs, entry) { exec_list_validate(&shader->outputs);
validate_var_decl((nir_variable *) entry->data, true, &state); foreach_list_typed(nir_variable, var, node, &shader->outputs) {
validate_var_decl(var, true, &state);
} }
exec_list_validate(&shader->globals); exec_list_validate(&shader->globals);

View File

@@ -196,9 +196,7 @@ fs_visitor::emit_nir_code()
void void
fs_visitor::nir_setup_inputs(nir_shader *shader) fs_visitor::nir_setup_inputs(nir_shader *shader)
{ {
struct hash_entry *entry; foreach_list_typed(nir_variable, var, node, &shader->inputs) {
hash_table_foreach(shader->inputs, entry) {
nir_variable *var = (nir_variable *) entry->data;
enum brw_reg_type type = brw_type_for_base_type(var->type); enum brw_reg_type type = brw_type_for_base_type(var->type);
fs_reg input = offset(nir_inputs, var->data.driver_location); fs_reg input = offset(nir_inputs, var->data.driver_location);
@@ -250,9 +248,7 @@ fs_visitor::nir_setup_outputs(nir_shader *shader)
{ {
brw_wm_prog_key *key = (brw_wm_prog_key*) this->key; brw_wm_prog_key *key = (brw_wm_prog_key*) this->key;
struct hash_entry *entry; foreach_list_typed(nir_variable, var, node, &shader->outputs) {
hash_table_foreach(shader->outputs, entry) {
nir_variable *var = (nir_variable *) entry->data;
fs_reg reg = offset(nir_outputs, var->data.driver_location); fs_reg reg = offset(nir_outputs, var->data.driver_location);
int vector_elements = int vector_elements =
@@ -304,10 +300,7 @@ fs_visitor::nir_setup_uniforms(nir_shader *shader)
if (dispatch_width != 8) if (dispatch_width != 8)
return; return;
struct hash_entry *entry; foreach_list_typed(nir_variable, var, node, &shader->uniforms) {
hash_table_foreach(shader->uniforms, entry) {
nir_variable *var = (nir_variable *) entry->data;
/* UBO's and atomics don't take up space in the uniform file */ /* UBO's and atomics don't take up space in the uniform file */
if (var->interface_type != NULL || var->type->contains_atomic()) if (var->interface_type != NULL || var->type->contains_atomic())