[Mesa-dev] [PATCH 070/133] nir: Validate that the SSA def and register indices are unique
Jason Ekstrand
jason at jlekstrand.net
Mon Dec 15 22:05:20 PST 2014
---
src/glsl/nir/nir_validate.c | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/src/glsl/nir/nir_validate.c b/src/glsl/nir/nir_validate.c
index ae8deb8..727f141 100644
--- a/src/glsl/nir/nir_validate.c
+++ b/src/glsl/nir/nir_validate.c
@@ -49,6 +49,9 @@ typedef struct {
/* map of register -> validation state (struct above) */
struct hash_table *regs;
+ /* the current shader being validated */
+ nir_shader *shader;
+
/* the current instruction being validated */
nir_instr *instr;
@@ -67,6 +70,12 @@ typedef struct {
/* map of SSA value -> function implementation where it is defined */
struct hash_table *ssa_defs;
+ /* bitset of ssa definitions we have found; used to check uniqueness */
+ BITSET_WORD *ssa_defs_found;
+
+ /* bitset of registers we have currently found; used to check uniqueness */
+ BITSET_WORD *regs_found;
+
/* map of local variable -> function implementation where it is defined */
struct hash_table *var_defs;
} validate_state;
@@ -207,6 +216,10 @@ validate_reg_dest(nir_reg_dest *dest, validate_state *state)
static void
validate_ssa_def(nir_ssa_def *def, validate_state *state)
{
+ assert(def->index < state->impl->ssa_alloc);
+ assert(!BITSET_TEST(state->ssa_defs_found, def->index));
+ BITSET_SET(state->ssa_defs_found, def->index);
+
assert(def->num_components <= 4);
_mesa_hash_table_insert(state->ssa_defs, _mesa_hash_pointer(def), def,
state->impl);
@@ -620,6 +633,13 @@ prevalidate_reg_decl(nir_register *reg, bool is_global, validate_state *state)
{
assert(reg->is_global == is_global);
+ if (is_global)
+ assert(reg->index < state->shader->reg_alloc);
+ else
+ assert(reg->index < state->impl->reg_alloc);
+ assert(!BITSET_TEST(state->regs_found, reg->index));
+ BITSET_SET(state->regs_found, reg->index);
+
reg_validate_state *reg_state = ralloc(state->regs, reg_validate_state);
reg_state->uses = _mesa_set_create(reg_state, _mesa_key_pointer_equal);
reg_state->defs = _mesa_set_create(reg_state, _mesa_key_pointer_equal);
@@ -715,11 +735,21 @@ validate_function_impl(nir_function_impl *impl, validate_state *state)
validate_var_decl(var, false, state);
}
+ state->regs_found = realloc(state->regs_found,
+ BITSET_WORDS(impl->reg_alloc) *
+ sizeof(BITSET_WORD));
+ memset(state->regs_found, 0, BITSET_WORDS(impl->reg_alloc) *
+ sizeof(BITSET_WORD));
exec_list_validate(&impl->registers);
foreach_list_typed(nir_register, reg, node, &impl->registers) {
prevalidate_reg_decl(reg, false, state);
}
+ state->ssa_defs_found = realloc(state->ssa_defs_found,
+ BITSET_WORDS(impl->ssa_alloc) *
+ sizeof(BITSET_WORD));
+ memset(state->ssa_defs_found, 0, BITSET_WORDS(impl->ssa_alloc) *
+ sizeof(BITSET_WORD));
exec_list_validate(&impl->body);
foreach_list_typed(nir_cf_node, node, node, &impl->body) {
validate_cf_node(node, state);
@@ -753,6 +783,8 @@ init_validate_state(validate_state *state)
{
state->regs = _mesa_hash_table_create(NULL, _mesa_key_pointer_equal);
state->ssa_defs = _mesa_hash_table_create(NULL, _mesa_key_pointer_equal);
+ state->ssa_defs_found = NULL;
+ state->regs_found = NULL;
state->var_defs = _mesa_hash_table_create(NULL, _mesa_key_pointer_equal);
}
@@ -761,6 +793,8 @@ destroy_validate_state(validate_state *state)
{
_mesa_hash_table_destroy(state->regs, NULL);
_mesa_hash_table_destroy(state->ssa_defs, NULL);
+ free(state->ssa_defs_found);
+ free(state->regs_found);
_mesa_hash_table_destroy(state->var_defs, NULL);
}
@@ -770,6 +804,8 @@ nir_validate_shader(nir_shader *shader)
validate_state state;
init_validate_state(&state);
+ state.shader = shader;
+
struct hash_entry *entry;
hash_table_foreach(shader->uniforms, entry) {
validate_var_decl((nir_variable *) entry->data, true, &state);
@@ -793,6 +829,11 @@ nir_validate_shader(nir_shader *shader)
validate_var_decl(var, true, &state);
}
+ state.regs_found = realloc(state.regs_found,
+ BITSET_WORDS(shader->reg_alloc) *
+ sizeof(BITSET_WORD));
+ memset(state.regs_found, 0, BITSET_WORDS(shader->reg_alloc) *
+ sizeof(BITSET_WORD));
exec_list_validate(&shader->registers);
foreach_list_typed(nir_register, reg, node, &shader->registers) {
prevalidate_reg_decl(reg, true, &state);
--
2.2.0
More information about the mesa-dev
mailing list