nir: Use deref instructions in lower_constant_initializers
Acked-by: Rob Clark <robdclark@gmail.com> Acked-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl> Acked-by: Dave Airlie <airlied@redhat.com> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
This commit is contained in:
@@ -832,69 +832,6 @@ nir_deref_foreach_leaf(nir_deref_var *deref,
|
|||||||
return deref_foreach_leaf_copy_recur(©, ©.deref, cb, state);
|
return deref_foreach_leaf_copy_recur(©, ©.deref, cb, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns a load_const instruction that represents the constant
|
|
||||||
* initializer for the given deref chain. The caller is responsible for
|
|
||||||
* ensuring that there actually is a constant initializer.
|
|
||||||
*/
|
|
||||||
nir_load_const_instr *
|
|
||||||
nir_deref_get_const_initializer_load(nir_shader *shader, nir_deref_var *deref)
|
|
||||||
{
|
|
||||||
nir_constant *constant = deref->var->constant_initializer;
|
|
||||||
assert(constant);
|
|
||||||
|
|
||||||
const nir_deref *tail = &deref->deref;
|
|
||||||
unsigned matrix_col = 0;
|
|
||||||
while (tail->child) {
|
|
||||||
switch (tail->child->deref_type) {
|
|
||||||
case nir_deref_type_array: {
|
|
||||||
nir_deref_array *arr = nir_deref_as_array(tail->child);
|
|
||||||
assert(arr->deref_array_type == nir_deref_array_type_direct);
|
|
||||||
if (glsl_type_is_matrix(tail->type)) {
|
|
||||||
assert(arr->deref.child == NULL);
|
|
||||||
matrix_col = arr->base_offset;
|
|
||||||
} else {
|
|
||||||
constant = constant->elements[arr->base_offset];
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case nir_deref_type_struct: {
|
|
||||||
constant = constant->elements[nir_deref_as_struct(tail->child)->index];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
unreachable("Invalid deref child type");
|
|
||||||
}
|
|
||||||
|
|
||||||
tail = tail->child;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned bit_size = glsl_get_bit_size(tail->type);
|
|
||||||
nir_load_const_instr *load =
|
|
||||||
nir_load_const_instr_create(shader, glsl_get_vector_elements(tail->type),
|
|
||||||
bit_size);
|
|
||||||
|
|
||||||
switch (glsl_get_base_type(tail->type)) {
|
|
||||||
case GLSL_TYPE_FLOAT:
|
|
||||||
case GLSL_TYPE_INT:
|
|
||||||
case GLSL_TYPE_UINT:
|
|
||||||
case GLSL_TYPE_FLOAT16:
|
|
||||||
case GLSL_TYPE_DOUBLE:
|
|
||||||
case GLSL_TYPE_INT16:
|
|
||||||
case GLSL_TYPE_UINT16:
|
|
||||||
case GLSL_TYPE_UINT64:
|
|
||||||
case GLSL_TYPE_INT64:
|
|
||||||
case GLSL_TYPE_BOOL:
|
|
||||||
load->value = constant->values[matrix_col];
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
unreachable("Invalid immediate type");
|
|
||||||
}
|
|
||||||
|
|
||||||
return load;
|
|
||||||
}
|
|
||||||
|
|
||||||
static nir_const_value
|
static nir_const_value
|
||||||
const_value_float(double d, unsigned bit_size)
|
const_value_float(double d, unsigned bit_size)
|
||||||
{
|
{
|
||||||
|
@@ -2248,9 +2248,6 @@ typedef bool (*nir_deref_foreach_leaf_cb)(nir_deref_var *deref, void *state);
|
|||||||
bool nir_deref_foreach_leaf(nir_deref_var *deref,
|
bool nir_deref_foreach_leaf(nir_deref_var *deref,
|
||||||
nir_deref_foreach_leaf_cb cb, void *state);
|
nir_deref_foreach_leaf_cb cb, void *state);
|
||||||
|
|
||||||
nir_load_const_instr *
|
|
||||||
nir_deref_get_const_initializer_load(nir_shader *shader, nir_deref_var *deref);
|
|
||||||
|
|
||||||
nir_const_value nir_alu_binop_identity(nir_op binop, unsigned bit_size);
|
nir_const_value nir_alu_binop_identity(nir_op binop, unsigned bit_size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -24,18 +24,44 @@
|
|||||||
#include "nir.h"
|
#include "nir.h"
|
||||||
#include "nir_builder.h"
|
#include "nir_builder.h"
|
||||||
|
|
||||||
static bool
|
static void
|
||||||
deref_apply_constant_initializer(nir_deref_var *deref, void *state)
|
build_constant_load(nir_builder *b, nir_deref_instr *deref, nir_constant *c)
|
||||||
{
|
{
|
||||||
struct nir_builder *b = state;
|
if (glsl_type_is_vector_or_scalar(deref->type)) {
|
||||||
|
nir_load_const_instr *load =
|
||||||
nir_load_const_instr *initializer =
|
nir_load_const_instr_create(b->shader,
|
||||||
nir_deref_get_const_initializer_load(b->shader, deref);
|
glsl_get_vector_elements(deref->type),
|
||||||
nir_builder_instr_insert(b, &initializer->instr);
|
glsl_get_bit_size(deref->type));
|
||||||
|
load->value = c->values[0];
|
||||||
nir_store_deref_var(b, deref, &initializer->def, 0xf);
|
nir_builder_instr_insert(b, &load->instr);
|
||||||
|
nir_store_deref(b, deref, &load->def, ~0);
|
||||||
return true;
|
} else if (glsl_type_is_matrix(deref->type)) {
|
||||||
|
unsigned cols = glsl_get_matrix_columns(deref->type);
|
||||||
|
unsigned rows = glsl_get_vector_elements(deref->type);
|
||||||
|
unsigned bit_size = glsl_get_bit_size(deref->type);
|
||||||
|
for (unsigned i = 0; i < cols; i++) {
|
||||||
|
nir_load_const_instr *load =
|
||||||
|
nir_load_const_instr_create(b->shader, rows, bit_size);
|
||||||
|
load->value = c->values[i];
|
||||||
|
nir_builder_instr_insert(b, &load->instr);
|
||||||
|
nir_store_deref(b, nir_build_deref_array(b, deref, nir_imm_int(b, i)),
|
||||||
|
&load->def, ~0);
|
||||||
|
}
|
||||||
|
} else if (glsl_type_is_struct(deref->type)) {
|
||||||
|
unsigned len = glsl_get_length(deref->type);
|
||||||
|
for (unsigned i = 0; i < len; i++) {
|
||||||
|
build_constant_load(b, nir_build_deref_struct(b, deref, i),
|
||||||
|
c->elements[i]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
assert(glsl_type_is_array(deref->type));
|
||||||
|
unsigned len = glsl_get_length(deref->type);
|
||||||
|
for (unsigned i = 0; i < len; i++) {
|
||||||
|
build_constant_load(b,
|
||||||
|
nir_build_deref_array(b, deref, nir_imm_int(b, i)),
|
||||||
|
c->elements[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
@@ -51,13 +77,8 @@ lower_const_initializer(struct nir_builder *b, struct exec_list *var_list)
|
|||||||
|
|
||||||
progress = true;
|
progress = true;
|
||||||
|
|
||||||
nir_deref_var deref;
|
build_constant_load(b, nir_build_deref_var(b, var),
|
||||||
deref.deref.deref_type = nir_deref_type_var,
|
var->constant_initializer);
|
||||||
deref.deref.child = NULL;
|
|
||||||
deref.deref.type = var->type,
|
|
||||||
deref.var = var;
|
|
||||||
|
|
||||||
nir_deref_foreach_leaf(&deref, deref_apply_constant_initializer, b);
|
|
||||||
|
|
||||||
var->constant_initializer = NULL;
|
var->constant_initializer = NULL;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user