nir: Remove old-school deref chain support
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:
@@ -64,7 +64,6 @@ nir_shader_create(void *mem_ctx,
|
||||
shader->num_outputs = 0;
|
||||
shader->num_uniforms = 0;
|
||||
shader->num_shared = 0;
|
||||
shader->lowered_derefs = 0;
|
||||
|
||||
return shader;
|
||||
}
|
||||
@@ -540,9 +539,7 @@ nir_tex_instr_create(nir_shader *shader, unsigned num_srcs)
|
||||
|
||||
instr->texture_index = 0;
|
||||
instr->texture_array_size = 0;
|
||||
instr->texture = NULL;
|
||||
instr->sampler_index = 0;
|
||||
instr->sampler = NULL;
|
||||
|
||||
return instr;
|
||||
}
|
||||
@@ -620,218 +617,6 @@ nir_ssa_undef_instr_create(nir_shader *shader,
|
||||
return instr;
|
||||
}
|
||||
|
||||
nir_deref_var *
|
||||
nir_deref_var_create(void *mem_ctx, nir_variable *var)
|
||||
{
|
||||
nir_deref_var *deref = ralloc(mem_ctx, nir_deref_var);
|
||||
deref->deref.deref_type = nir_deref_type_var;
|
||||
deref->deref.child = NULL;
|
||||
deref->deref.type = var->type;
|
||||
deref->var = var;
|
||||
return deref;
|
||||
}
|
||||
|
||||
nir_deref_array *
|
||||
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->deref_array_type = nir_deref_array_type_direct;
|
||||
src_init(&deref->indirect);
|
||||
deref->base_offset = 0;
|
||||
return deref;
|
||||
}
|
||||
|
||||
nir_deref_struct *
|
||||
nir_deref_struct_create(void *mem_ctx, unsigned field_index)
|
||||
{
|
||||
nir_deref_struct *deref = ralloc(mem_ctx, nir_deref_struct);
|
||||
deref->deref.deref_type = nir_deref_type_struct;
|
||||
deref->deref.child = NULL;
|
||||
deref->index = field_index;
|
||||
return deref;
|
||||
}
|
||||
|
||||
nir_deref_var *
|
||||
nir_deref_var_clone(const nir_deref_var *deref, void *mem_ctx)
|
||||
{
|
||||
if (deref == NULL)
|
||||
return NULL;
|
||||
|
||||
nir_deref_var *ret = nir_deref_var_create(mem_ctx, deref->var);
|
||||
ret->deref.type = deref->deref.type;
|
||||
if (deref->deref.child)
|
||||
ret->deref.child = nir_deref_clone(deref->deref.child, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static nir_deref_array *
|
||||
deref_array_clone(const nir_deref_array *deref, void *mem_ctx)
|
||||
{
|
||||
nir_deref_array *ret = nir_deref_array_create(mem_ctx);
|
||||
ret->base_offset = deref->base_offset;
|
||||
ret->deref_array_type = deref->deref_array_type;
|
||||
if (deref->deref_array_type == nir_deref_array_type_indirect) {
|
||||
nir_src_copy(&ret->indirect, &deref->indirect, mem_ctx);
|
||||
}
|
||||
ret->deref.type = deref->deref.type;
|
||||
if (deref->deref.child)
|
||||
ret->deref.child = nir_deref_clone(deref->deref.child, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static nir_deref_struct *
|
||||
deref_struct_clone(const nir_deref_struct *deref, void *mem_ctx)
|
||||
{
|
||||
nir_deref_struct *ret = nir_deref_struct_create(mem_ctx, deref->index);
|
||||
ret->deref.type = deref->deref.type;
|
||||
if (deref->deref.child)
|
||||
ret->deref.child = nir_deref_clone(deref->deref.child, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
nir_deref *
|
||||
nir_deref_clone(const nir_deref *deref, void *mem_ctx)
|
||||
{
|
||||
if (deref == NULL)
|
||||
return NULL;
|
||||
|
||||
switch (deref->deref_type) {
|
||||
case nir_deref_type_var:
|
||||
return &nir_deref_var_clone(nir_deref_as_var(deref), mem_ctx)->deref;
|
||||
case nir_deref_type_array:
|
||||
return &deref_array_clone(nir_deref_as_array(deref), mem_ctx)->deref;
|
||||
case nir_deref_type_struct:
|
||||
return &deref_struct_clone(nir_deref_as_struct(deref), mem_ctx)->deref;
|
||||
default:
|
||||
unreachable("Invalid dereference type");
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* This is the second step in the recursion. We've found the tail and made a
|
||||
* copy. Now we need to iterate over all possible leaves and call the
|
||||
* callback on each one.
|
||||
*/
|
||||
static bool
|
||||
deref_foreach_leaf_build_recur(nir_deref_var *deref, nir_deref *tail,
|
||||
nir_deref_foreach_leaf_cb cb, void *state)
|
||||
{
|
||||
unsigned length;
|
||||
union {
|
||||
nir_deref_array arr;
|
||||
nir_deref_struct str;
|
||||
} tmp;
|
||||
|
||||
assert(tail->child == NULL);
|
||||
switch (glsl_get_base_type(tail->type)) {
|
||||
case GLSL_TYPE_UINT:
|
||||
case GLSL_TYPE_UINT16:
|
||||
case GLSL_TYPE_UINT64:
|
||||
case GLSL_TYPE_INT:
|
||||
case GLSL_TYPE_INT16:
|
||||
case GLSL_TYPE_INT64:
|
||||
case GLSL_TYPE_FLOAT:
|
||||
case GLSL_TYPE_FLOAT16:
|
||||
case GLSL_TYPE_DOUBLE:
|
||||
case GLSL_TYPE_BOOL:
|
||||
if (glsl_type_is_vector_or_scalar(tail->type))
|
||||
return cb(deref, state);
|
||||
/* Fall Through */
|
||||
|
||||
case GLSL_TYPE_ARRAY:
|
||||
tmp.arr.deref.deref_type = nir_deref_type_array;
|
||||
tmp.arr.deref.type = glsl_get_array_element(tail->type);
|
||||
tmp.arr.deref_array_type = nir_deref_array_type_direct;
|
||||
tmp.arr.indirect = NIR_SRC_INIT;
|
||||
tail->child = &tmp.arr.deref;
|
||||
|
||||
length = glsl_get_length(tail->type);
|
||||
for (unsigned i = 0; i < length; i++) {
|
||||
tmp.arr.deref.child = NULL;
|
||||
tmp.arr.base_offset = i;
|
||||
if (!deref_foreach_leaf_build_recur(deref, &tmp.arr.deref, cb, state))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
case GLSL_TYPE_STRUCT:
|
||||
tmp.str.deref.deref_type = nir_deref_type_struct;
|
||||
tail->child = &tmp.str.deref;
|
||||
|
||||
length = glsl_get_length(tail->type);
|
||||
for (unsigned i = 0; i < length; i++) {
|
||||
tmp.arr.deref.child = NULL;
|
||||
tmp.str.deref.type = glsl_get_struct_field(tail->type, i);
|
||||
tmp.str.index = i;
|
||||
if (!deref_foreach_leaf_build_recur(deref, &tmp.arr.deref, cb, state))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
default:
|
||||
unreachable("Invalid type for dereference");
|
||||
}
|
||||
}
|
||||
|
||||
/* This is the first step of the foreach_leaf recursion. In this step we are
|
||||
* walking to the end of the deref chain and making a copy in the stack as we
|
||||
* go. This is because we don't want to mutate the deref chain that was
|
||||
* passed in by the caller. The downside is that this deref chain is on the
|
||||
* stack and , if the caller wants to do anything with it, they will have to
|
||||
* make their own copy because this one will go away.
|
||||
*/
|
||||
static bool
|
||||
deref_foreach_leaf_copy_recur(nir_deref_var *deref, nir_deref *tail,
|
||||
nir_deref_foreach_leaf_cb cb, void *state)
|
||||
{
|
||||
union {
|
||||
nir_deref_array arr;
|
||||
nir_deref_struct str;
|
||||
} c;
|
||||
|
||||
if (tail->child) {
|
||||
switch (tail->child->deref_type) {
|
||||
case nir_deref_type_array:
|
||||
c.arr = *nir_deref_as_array(tail->child);
|
||||
tail->child = &c.arr.deref;
|
||||
return deref_foreach_leaf_copy_recur(deref, &c.arr.deref, cb, state);
|
||||
|
||||
case nir_deref_type_struct:
|
||||
c.str = *nir_deref_as_struct(tail->child);
|
||||
tail->child = &c.str.deref;
|
||||
return deref_foreach_leaf_copy_recur(deref, &c.str.deref, cb, state);
|
||||
|
||||
case nir_deref_type_var:
|
||||
default:
|
||||
unreachable("Invalid deref type for a child");
|
||||
}
|
||||
} else {
|
||||
/* We've gotten to the end of the original deref. Time to start
|
||||
* building our own derefs.
|
||||
*/
|
||||
return deref_foreach_leaf_build_recur(deref, tail, cb, state);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function iterates over all of the possible derefs that can be created
|
||||
* with the given deref as the head. It then calls the provided callback with
|
||||
* a full deref for each one.
|
||||
*
|
||||
* The deref passed to the callback will be allocated on the stack. You will
|
||||
* need to make a copy if you want it to hang around.
|
||||
*/
|
||||
bool
|
||||
nir_deref_foreach_leaf(nir_deref_var *deref,
|
||||
nir_deref_foreach_leaf_cb cb, void *state)
|
||||
{
|
||||
nir_deref_var copy = *deref;
|
||||
return deref_foreach_leaf_copy_recur(©, ©.deref, cb, state);
|
||||
}
|
||||
|
||||
static nir_const_value
|
||||
const_value_float(double d, unsigned bit_size)
|
||||
{
|
||||
@@ -1259,31 +1044,6 @@ visit_src(nir_src *src, nir_foreach_src_cb cb, void *state)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
visit_deref_array_src(nir_deref_array *deref, nir_foreach_src_cb cb,
|
||||
void *state)
|
||||
{
|
||||
if (deref->deref_array_type == nir_deref_array_type_indirect)
|
||||
return visit_src(&deref->indirect, cb, state);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
visit_deref_src(nir_deref_var *deref, nir_foreach_src_cb cb, void *state)
|
||||
{
|
||||
nir_deref *cur = &deref->deref;
|
||||
while (cur != NULL) {
|
||||
if (cur->deref_type == nir_deref_type_array) {
|
||||
if (!visit_deref_array_src(nir_deref_as_array(cur), cb, state))
|
||||
return false;
|
||||
}
|
||||
|
||||
cur = cur->child;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
visit_alu_src(nir_alu_instr *instr, nir_foreach_src_cb cb, void *state)
|
||||
{
|
||||
@@ -1319,16 +1079,6 @@ visit_tex_src(nir_tex_instr *instr, nir_foreach_src_cb cb, void *state)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (instr->texture != NULL) {
|
||||
if (!visit_deref_src(instr->texture, cb, state))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (instr->sampler != NULL) {
|
||||
if (!visit_deref_src(instr->sampler, cb, state))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1342,13 +1092,6 @@ visit_intrinsic_src(nir_intrinsic_instr *instr, nir_foreach_src_cb cb,
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned num_vars =
|
||||
nir_intrinsic_infos[instr->intrinsic].num_variables;
|
||||
for (unsigned i = 0; i < num_vars; i++) {
|
||||
if (!visit_deref_src(instr->variables[i], cb, state))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1588,19 +1331,6 @@ nir_instr_rewrite_dest(nir_instr *instr, nir_dest *dest, nir_dest new_dest)
|
||||
src_add_all_uses(dest->reg.indirect, instr, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
nir_instr_rewrite_deref(nir_instr *instr, nir_deref_var **deref,
|
||||
nir_deref_var *new_deref)
|
||||
{
|
||||
if (*deref)
|
||||
visit_deref_src(*deref, remove_use_cb, NULL);
|
||||
|
||||
*deref = new_deref;
|
||||
|
||||
if (*deref)
|
||||
visit_deref_src(*deref, add_use_cb, instr);
|
||||
}
|
||||
|
||||
/* note: does *not* take ownership of 'name' */
|
||||
void
|
||||
nir_ssa_def_init(nir_instr *instr, nir_ssa_def *def,
|
||||
|
Reference in New Issue
Block a user