X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fcompiler%2Fnir%2Fnir_validate.c;h=eee737e8069cd8c9f9d90cc8a8377af94fc9ea64;hb=67c728f7a9450b04d4de1a29f1dcfb9265a7ebfd;hp=cdbe6a6dced2498923babd1b75b4b75d1e5968a0;hpb=a136884139c42a9ab96c659cbfe44149b1bbffdb;p=mesa.git diff --git a/src/compiler/nir/nir_validate.c b/src/compiler/nir/nir_validate.c index cdbe6a6dced..eee737e8069 100644 --- a/src/compiler/nir/nir_validate.c +++ b/src/compiler/nir/nir_validate.c @@ -35,7 +35,7 @@ /* Since this file is just a pile of asserts, don't bother compiling it if * we're not building a debug build. */ -#ifdef DEBUG +#ifndef NDEBUG /* * Per-register validation state. @@ -96,7 +96,9 @@ typedef struct { /* 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 */ + /* map of variable -> function implementation where it is defined or NULL + * if it is a global variable + */ struct hash_table *var_defs; /* map of instruction/var/etc to failed assert string */ @@ -294,7 +296,9 @@ validate_ssa_def(nir_ssa_def *def, validate_state *state) validate_assert(state, def->parent_instr == state->instr); - validate_assert(state, def->num_components <= 4); + validate_assert(state, (def->num_components <= 4) || + (def->num_components == 8) || + (def->num_components == 16)); list_validate(&def->uses); list_validate(&def->if_uses); @@ -397,7 +401,8 @@ validate_alu_instr(nir_alu_instr *instr, validate_state *state) } static void -validate_deref_chain(nir_deref *deref, validate_state *state) +validate_deref_chain(nir_deref *deref, nir_variable_mode mode, + validate_state *state) { validate_assert(state, deref->child == NULL || ralloc_parent(deref->child) == deref); @@ -405,6 +410,19 @@ validate_deref_chain(nir_deref *deref, validate_state *state) while (deref != NULL) { switch (deref->deref_type) { case nir_deref_type_array: + if (mode == nir_var_shared) { + /* Shared variables have a bit more relaxed rules because we need + * to be able to handle array derefs on vectors. Fortunately, + * nir_lower_io handles these just fine. + */ + validate_assert(state, glsl_type_is_array(parent->type) || + glsl_type_is_matrix(parent->type) || + glsl_type_is_vector(parent->type)); + } else { + /* Most of NIR cannot handle array derefs on vectors */ + validate_assert(state, glsl_type_is_array(parent->type) || + glsl_type_is_matrix(parent->type)); + } validate_assert(state, deref->type == glsl_get_array_element(parent->type)); if (nir_deref_as_array(deref)->deref_array_type == nir_deref_array_type_indirect) @@ -434,12 +452,10 @@ validate_deref_chain(nir_deref *deref, validate_state *state) static void validate_var_use(nir_variable *var, validate_state *state) { - if (var->data.mode == nir_var_local) { - struct hash_entry *entry = _mesa_hash_table_search(state->var_defs, var); - - validate_assert(state, entry); + struct hash_entry *entry = _mesa_hash_table_search(state->var_defs, var); + validate_assert(state, entry); + if (var->data.mode == nir_var_local) validate_assert(state, (nir_function_impl *) entry->data == state->impl); - } } static void @@ -451,7 +467,7 @@ validate_deref_var(void *parent_mem_ctx, nir_deref_var *deref, validate_state *s validate_var_use(deref->var, state); - validate_deref_chain(&deref->deref, state); + validate_deref_chain(&deref->deref, deref->var->data.mode, state); } static void @@ -467,10 +483,7 @@ validate_intrinsic_instr(nir_intrinsic_instr *instr, validate_state *state) unsigned num_srcs = nir_intrinsic_infos[instr->intrinsic].num_srcs; for (unsigned i = 0; i < num_srcs; i++) { - unsigned components_read = - nir_intrinsic_infos[instr->intrinsic].src_components[i]; - if (components_read == 0) - components_read = instr->num_components; + unsigned components_read = nir_intrinsic_src_components(instr, i); validate_assert(state, components_read > 0); @@ -483,10 +496,7 @@ validate_intrinsic_instr(nir_intrinsic_instr *instr, validate_state *state) } if (nir_intrinsic_infos[instr->intrinsic].has_dest) { - unsigned components_written = - nir_intrinsic_infos[instr->intrinsic].dest_components; - if (components_written == 0) - components_written = instr->num_components; + unsigned components_written = nir_intrinsic_dest_components(instr); validate_assert(state, components_written > 0); @@ -966,14 +976,14 @@ validate_var_decl(nir_variable *var, bool is_global, validate_state *state) validate_assert(state, is_global == nir_variable_is_global(var)); /* Must have exactly one mode set */ - validate_assert(state, util_bitcount(var->data.mode) == 1); + validate_assert(state, util_is_power_of_two_nonzero(var->data.mode)); if (var->data.compact) { /* The "compact" flag is only valid on arrays of scalars. */ assert(glsl_type_is_array(var->type)); const struct glsl_type *type = glsl_get_array_element(var->type); - if (nir_is_per_vertex_io(var, state->shader->stage)) { + if (nir_is_per_vertex_io(var, state->shader->info.stage)) { assert(glsl_type_is_array(type)); assert(glsl_type_is_scalar(glsl_get_array_element(type))); } else { @@ -986,9 +996,8 @@ validate_var_decl(nir_variable *var, bool is_global, validate_state *state) * support) */ - if (!is_global) { - _mesa_hash_table_insert(state->var_defs, var, state->impl); - } + _mesa_hash_table_insert(state->var_defs, var, + is_global ? NULL : state->impl); state->var = NULL; }