summaryrefslogtreecommitdiffstats
path: root/src/compiler/nir
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2016-11-29 22:19:28 -0800
committerJason Ekstrand <[email protected]>2016-12-02 10:53:32 -0800
commit19a541f496aace95d6660ed7e216fecc8be2e49d (patch)
tree5ce74da718bdf4c831135ba290ec781b8c0b67db /src/compiler/nir
parentc45d84ad8349d0c69893458d6c58eb5f6f1609c4 (diff)
nir: Get rid of nir_constant_data
This has bothered me for about as long as NIR has been around. Why do we have two different unions for constants? No good reason other than one of them is a direct port from GLSL IR. Reviewed-by: Iago Toral Quiroga <[email protected]>
Diffstat (limited to 'src/compiler/nir')
-rw-r--r--src/compiler/nir/nir.c32
-rw-r--r--src/compiler/nir/nir.h30
-rw-r--r--src/compiler/nir/nir_clone.c2
-rw-r--r--src/compiler/nir/nir_print.c29
4 files changed, 41 insertions, 52 deletions
diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c
index cfb032c68b9..2d882f76483 100644
--- a/src/compiler/nir/nir.c
+++ b/src/compiler/nir/nir.c
@@ -806,7 +806,7 @@ nir_deref_get_const_initializer_load(nir_shader *shader, nir_deref_var *deref)
assert(constant);
const nir_deref *tail = &deref->deref;
- unsigned matrix_offset = 0;
+ unsigned matrix_col = 0;
while (tail->child) {
switch (tail->child->deref_type) {
case nir_deref_type_array: {
@@ -814,7 +814,7 @@ nir_deref_get_const_initializer_load(nir_shader *shader, nir_deref_var *deref)
assert(arr->deref_array_type == nir_deref_array_type_direct);
if (glsl_type_is_matrix(tail->type)) {
assert(arr->deref.child == NULL);
- matrix_offset = arr->base_offset;
+ matrix_col = arr->base_offset;
} else {
constant = constant->elements[arr->base_offset];
}
@@ -838,24 +838,16 @@ nir_deref_get_const_initializer_load(nir_shader *shader, nir_deref_var *deref)
nir_load_const_instr_create(shader, glsl_get_vector_elements(tail->type),
bit_size);
- matrix_offset *= load->def.num_components;
- for (unsigned i = 0; i < load->def.num_components; i++) {
- switch (glsl_get_base_type(tail->type)) {
- case GLSL_TYPE_FLOAT:
- case GLSL_TYPE_INT:
- case GLSL_TYPE_UINT:
- load->value.u32[i] = constant->value.u[matrix_offset + i];
- break;
- case GLSL_TYPE_DOUBLE:
- load->value.f64[i] = constant->value.d[matrix_offset + i];
- break;
- case GLSL_TYPE_BOOL:
- load->value.u32[i] = constant->value.b[matrix_offset + i] ?
- NIR_TRUE : NIR_FALSE;
- break;
- default:
- unreachable("Invalid immediate type");
- }
+ switch (glsl_get_base_type(tail->type)) {
+ case GLSL_TYPE_FLOAT:
+ case GLSL_TYPE_INT:
+ case GLSL_TYPE_UINT:
+ case GLSL_TYPE_DOUBLE:
+ case GLSL_TYPE_BOOL:
+ load->value = constant->values[matrix_col];
+ break;
+ default:
+ unreachable("Invalid immediate type");
}
return load;
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 3e6d168e974..9e8ed2cd47d 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -97,16 +97,15 @@ typedef enum {
nir_var_all = ~0,
} nir_variable_mode;
-/**
- * Data stored in an nir_constant
- */
-union nir_constant_data {
- unsigned u[16];
- int i[16];
- float f[16];
- bool b[16];
- double d[16];
-};
+
+typedef union {
+ float f32[4];
+ double f64[4];
+ int32_t i32[4];
+ uint32_t u32[4];
+ int64_t i64[4];
+ uint64_t u64[4];
+} nir_const_value;
typedef struct nir_constant {
/**
@@ -116,7 +115,7 @@ typedef struct nir_constant {
* by the type associated with the \c nir_variable. Constants may be
* scalars, vectors, or matrices.
*/
- union nir_constant_data value;
+ nir_const_value values[4];
/* we could get this from the var->type but makes clone *much* easier to
* not have to care about the type.
@@ -1345,15 +1344,6 @@ nir_tex_instr_src_index(nir_tex_instr *instr, nir_tex_src_type type)
void nir_tex_instr_remove_src(nir_tex_instr *tex, unsigned src_idx);
-typedef union {
- float f32[4];
- double f64[4];
- int32_t i32[4];
- uint32_t u32[4];
- int64_t i64[4];
- uint64_t u64[4];
-} nir_const_value;
-
typedef struct {
nir_instr instr;
diff --git a/src/compiler/nir/nir_clone.c b/src/compiler/nir/nir_clone.c
index 4f7bdd96969..be89426b88d 100644
--- a/src/compiler/nir/nir_clone.c
+++ b/src/compiler/nir/nir_clone.c
@@ -114,7 +114,7 @@ nir_constant_clone(const nir_constant *c, nir_variable *nvar)
{
nir_constant *nc = ralloc(nvar, nir_constant);
- nc->value = c->value;
+ memcpy(nc->values, c->values, sizeof(nc->values));
nc->num_elements = c->num_elements;
nc->elements = ralloc_array(nvar, nir_constant *, c->num_elements);
for (unsigned i = 0; i < c->num_elements; i++) {
diff --git a/src/compiler/nir/nir_print.c b/src/compiler/nir/nir_print.c
index a5b29093c5b..eb5f57f9534 100644
--- a/src/compiler/nir/nir_print.c
+++ b/src/compiler/nir/nir_print.c
@@ -295,30 +295,37 @@ static void
print_constant(nir_constant *c, const struct glsl_type *type, print_state *state)
{
FILE *fp = state->fp;
- unsigned total_elems = glsl_get_components(type);
- unsigned i;
+ const unsigned rows = glsl_get_vector_elements(type);
+ const unsigned cols = glsl_get_matrix_columns(type);
+ unsigned i, j;
switch (glsl_get_base_type(type)) {
case GLSL_TYPE_UINT:
case GLSL_TYPE_INT:
case GLSL_TYPE_BOOL:
- for (i = 0; i < total_elems; i++) {
- if (i > 0) fprintf(fp, ", ");
- fprintf(fp, "0x%08x", c->value.u[i]);
+ for (i = 0; i < cols; i++) {
+ for (j = 0; j < rows; j++) {
+ if (i + j > 0) fprintf(fp, ", ");
+ fprintf(fp, "0x%08x", c->values[i].u32[j]);
+ }
}
break;
case GLSL_TYPE_FLOAT:
- for (i = 0; i < total_elems; i++) {
- if (i > 0) fprintf(fp, ", ");
- fprintf(fp, "%f", c->value.f[i]);
+ for (i = 0; i < cols; i++) {
+ for (j = 0; j < rows; j++) {
+ if (i + j > 0) fprintf(fp, ", ");
+ fprintf(fp, "%f", c->values[i].f32[j]);
+ }
}
break;
case GLSL_TYPE_DOUBLE:
- for (i = 0; i < total_elems; i++) {
- if (i > 0) fprintf(fp, ", ");
- fprintf(fp, "%f", c->value.d[i]);
+ for (i = 0; i < cols; i++) {
+ for (j = 0; j < rows; j++) {
+ if (i + j > 0) fprintf(fp, ", ");
+ fprintf(fp, "%f", c->values[i].f64[j]);
+ }
}
break;