nir: Make array deref direct vs. indirect an enum
Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
This commit is contained in:
@@ -1767,9 +1767,10 @@ nir_visitor::visit(ir_dereference_array *ir)
|
||||
|
||||
ir_constant *const_index = ir->array_index->as_constant();
|
||||
if (const_index != NULL) {
|
||||
deref->deref_array_type = nir_deref_array_type_direct;
|
||||
deref->base_offset = const_index->value.u[0];
|
||||
} else {
|
||||
deref->has_indirect = true;
|
||||
deref->deref_array_type = nir_deref_array_type_indirect;
|
||||
deref->indirect = evaluate_rvalue(ir->array_index);
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -522,7 +522,7 @@ nir_deref_array_create(void *mem_ctx)
|
||||
nir_deref_array *deref = ralloc(mem_ctx, nir_deref_array);
|
||||
deref->deref.deref_type = nir_deref_type_array;
|
||||
deref->deref.child = NULL;
|
||||
deref->has_indirect = false;
|
||||
deref->deref_array_type = nir_deref_array_type_direct;
|
||||
src_init(&deref->indirect);
|
||||
deref->base_offset = 0;
|
||||
return deref;
|
||||
@@ -553,9 +553,9 @@ copy_deref_array(void *mem_ctx, nir_deref_array *deref)
|
||||
{
|
||||
nir_deref_array *ret = nir_deref_array_create(mem_ctx);
|
||||
ret->base_offset = deref->base_offset;
|
||||
if (deref->has_indirect) {
|
||||
ret->has_indirect = true;
|
||||
ret->indirect = deref->indirect;
|
||||
ret->deref_array_type = deref->deref_array_type;
|
||||
if (deref->deref_array_type == nir_deref_array_type_indirect) {
|
||||
ret->indirect = nir_src_copy(deref->indirect, mem_ctx);
|
||||
}
|
||||
ret->deref.type = deref->deref.type;
|
||||
if (deref->deref.child)
|
||||
@@ -1477,7 +1477,7 @@ static bool
|
||||
visit_deref_array_src(nir_deref_array *deref, nir_foreach_src_cb cb,
|
||||
void *state)
|
||||
{
|
||||
if (deref->has_indirect)
|
||||
if (deref->deref_array_type == nir_deref_array_type_indirect)
|
||||
return visit_src(&deref->indirect, cb, state);
|
||||
return true;
|
||||
}
|
||||
|
||||
+6
-1
@@ -625,11 +625,16 @@ typedef struct {
|
||||
nir_variable *var;
|
||||
} nir_deref_var;
|
||||
|
||||
typedef enum {
|
||||
nir_deref_array_type_direct,
|
||||
nir_deref_array_type_indirect,
|
||||
} nir_deref_array_type;
|
||||
|
||||
typedef struct {
|
||||
nir_deref deref;
|
||||
|
||||
nir_deref_array_type deref_array_type;
|
||||
unsigned base_offset;
|
||||
bool has_indirect;
|
||||
nir_src indirect;
|
||||
} nir_deref_array;
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ lower_instr(nir_intrinsic_instr *instr, nir_function_impl *impl)
|
||||
|
||||
offset_const->value.u[0] += deref_array->base_offset;
|
||||
|
||||
if (deref_array->has_indirect) {
|
||||
if (deref_array->deref_array_type == nir_deref_array_type_indirect) {
|
||||
nir_load_const_instr *atomic_counter_size =
|
||||
nir_load_const_instr_create(mem_ctx);
|
||||
atomic_counter_size->num_components = 1;
|
||||
|
||||
@@ -51,7 +51,7 @@ get_deref_name_offset(nir_deref_var *deref_var,
|
||||
switch (deref->deref_type) {
|
||||
case nir_deref_type_array:
|
||||
deref_array = nir_deref_as_array(deref);
|
||||
if (deref_array->has_indirect) {
|
||||
if (deref_array->deref_array_type == nir_deref_array_type_indirect) {
|
||||
/* GLSL 1.10 and 1.20 allowed variable sampler array indices,
|
||||
* while GLSL 1.30 requires that the array indices be
|
||||
* constant integer expressions. We don't expect any driver
|
||||
|
||||
@@ -169,7 +169,7 @@ deref_has_indirect(nir_deref_var *deref_var)
|
||||
deref = deref->child;
|
||||
if (deref->deref_type == nir_deref_type_array) {
|
||||
nir_deref_array *deref_array = nir_deref_as_array(deref);
|
||||
if (deref_array->has_indirect)
|
||||
if (deref_array->deref_array_type == nir_deref_array_type_indirect)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -198,7 +198,7 @@ get_deref_offset(nir_deref_var *deref_var, nir_instr *instr,
|
||||
|
||||
base_offset += size * deref_array->base_offset;
|
||||
|
||||
if (deref_array->has_indirect) {
|
||||
if (deref_array->deref_array_type == nir_deref_array_type_indirect) {
|
||||
nir_src src;
|
||||
if (size == 1) {
|
||||
src = deref_array->indirect;
|
||||
|
||||
@@ -265,12 +265,15 @@ static void
|
||||
print_deref_array(nir_deref_array *deref, print_var_state *state, FILE *fp)
|
||||
{
|
||||
fprintf(fp, "[");
|
||||
if (!deref->has_indirect || deref->base_offset != 0)
|
||||
switch (deref->deref_array_type) {
|
||||
case nir_deref_array_type_direct:
|
||||
fprintf(fp, "%u", deref->base_offset);
|
||||
if (deref->has_indirect) {
|
||||
break;
|
||||
case nir_deref_array_type_indirect:
|
||||
if (deref->base_offset != 0)
|
||||
fprintf(fp, " + ");
|
||||
fprintf(fp, "%u + ", deref->base_offset);
|
||||
print_src(&deref->indirect, fp);
|
||||
break;
|
||||
}
|
||||
fprintf(fp, "]");
|
||||
}
|
||||
|
||||
@@ -267,7 +267,8 @@ validate_deref_chain(nir_deref *deref, validate_state *state)
|
||||
switch (deref->deref_type) {
|
||||
case nir_deref_type_array:
|
||||
assert(deref->type == glsl_get_array_element(parent->type));
|
||||
if (nir_deref_as_array(deref)->has_indirect)
|
||||
if (nir_deref_as_array(deref)->deref_array_type ==
|
||||
nir_deref_array_type_indirect)
|
||||
validate_src(&nir_deref_as_array(deref)->indirect, state);
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user