summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2014-11-19 12:53:08 -0800
committerJason Ekstrand <[email protected]>2015-01-15 07:19:02 -0800
commitb5143edaeeb6f57558f5bb6fbd7f7cc39ad7489d (patch)
tree8362d1cbab931746f1cbe2095bceae6d74f0da5a
parent8219ff1796ab18d19fe9cf3cf93f463a984e2c80 (diff)
nir: Make array deref direct vs. indirect an enum
Reviewed-by: Connor Abbott <[email protected]>
-rw-r--r--src/glsl/nir/glsl_to_nir.cpp3
-rw-r--r--src/glsl/nir/nir.c10
-rw-r--r--src/glsl/nir/nir.h7
-rw-r--r--src/glsl/nir/nir_lower_atomics.c2
-rw-r--r--src/glsl/nir/nir_lower_samplers.cpp2
-rw-r--r--src/glsl/nir/nir_lower_variables_scalar.c4
-rw-r--r--src/glsl/nir/nir_print.c9
-rw-r--r--src/glsl/nir/nir_validate.c3
8 files changed, 25 insertions, 15 deletions
diff --git a/src/glsl/nir/glsl_to_nir.cpp b/src/glsl/nir/glsl_to_nir.cpp
index 58721913f74..6b90da5481c 100644
--- a/src/glsl/nir/glsl_to_nir.cpp
+++ b/src/glsl/nir/glsl_to_nir.cpp
@@ -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);
}
diff --git a/src/glsl/nir/nir.c b/src/glsl/nir/nir.c
index f63248ec4f1..0514158bbde 100644
--- a/src/glsl/nir/nir.c
+++ b/src/glsl/nir/nir.c
@@ -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;
}
diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
index 6a872c508bd..021d4c91323 100644
--- a/src/glsl/nir/nir.h
+++ b/src/glsl/nir/nir.h
@@ -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;
diff --git a/src/glsl/nir/nir_lower_atomics.c b/src/glsl/nir/nir_lower_atomics.c
index c2387cd8109..23d5de0c0ac 100644
--- a/src/glsl/nir/nir_lower_atomics.c
+++ b/src/glsl/nir/nir_lower_atomics.c
@@ -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;
diff --git a/src/glsl/nir/nir_lower_samplers.cpp b/src/glsl/nir/nir_lower_samplers.cpp
index 347c84adc9b..be6a75525b7 100644
--- a/src/glsl/nir/nir_lower_samplers.cpp
+++ b/src/glsl/nir/nir_lower_samplers.cpp
@@ -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
diff --git a/src/glsl/nir/nir_lower_variables_scalar.c b/src/glsl/nir/nir_lower_variables_scalar.c
index 0b7263c88de..3127dbb19b4 100644
--- a/src/glsl/nir/nir_lower_variables_scalar.c
+++ b/src/glsl/nir/nir_lower_variables_scalar.c
@@ -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;
diff --git a/src/glsl/nir/nir_print.c b/src/glsl/nir/nir_print.c
index 2ae31ef9bc9..0156582c20c 100644
--- a/src/glsl/nir/nir_print.c
+++ b/src/glsl/nir/nir_print.c
@@ -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, "]");
}
diff --git a/src/glsl/nir/nir_validate.c b/src/glsl/nir/nir_validate.c
index dc5c1633698..d4a8cd588c7 100644
--- a/src/glsl/nir/nir_validate.c
+++ b/src/glsl/nir/nir_validate.c
@@ -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;