[Mesa-dev] [PATCH 080/133] nir: Make array deref direct vs. indirect an enum
Jason Ekstrand
jason at jlekstrand.net
Mon Dec 15 22:11:25 PST 2014
---
src/glsl/nir/glsl_to_nir.cpp | 3 ++-
src/glsl/nir/nir.c | 10 +++++-----
src/glsl/nir/nir.h | 7 ++++++-
src/glsl/nir/nir_lower_atomics.c | 2 +-
src/glsl/nir/nir_lower_samplers.cpp | 2 +-
src/glsl/nir/nir_lower_variables_scalar.c | 4 ++--
src/glsl/nir/nir_print.c | 9 ++++++---
src/glsl/nir/nir_validate.c | 3 ++-
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 240a2c1..4004066 100644
--- a/src/glsl/nir/glsl_to_nir.cpp
+++ b/src/glsl/nir/glsl_to_nir.cpp
@@ -1773,9 +1773,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 cf238c1..15b691f 100644
--- a/src/glsl/nir/nir.c
+++ b/src/glsl/nir/nir.c
@@ -516,7 +516,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;
@@ -547,9 +547,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)
@@ -1471,7 +1471,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 8cf3a57..f4db3f8 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 c2387cd..23d5de0 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 347c84a..be6a755 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 92b716a..40aba7d 100644
--- a/src/glsl/nir/nir_lower_variables_scalar.c
+++ b/src/glsl/nir/nir_lower_variables_scalar.c
@@ -168,7 +168,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;
}
}
@@ -197,7 +197,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 dd57116..15f6ae1 100644
--- a/src/glsl/nir/nir_print.c
+++ b/src/glsl/nir/nir_print.c
@@ -266,12 +266,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 727f141..f95d1d5 100644
--- a/src/glsl/nir/nir_validate.c
+++ b/src/glsl/nir/nir_validate.c
@@ -272,7 +272,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;
--
2.2.0
More information about the mesa-dev
mailing list