nir_intrinsic_instr_create(this->shader, nir_intrinsic_store_var);
store->num_components = ir->lhs->type->vector_elements;
nir_intrinsic_set_write_mask(store, ir->write_mask);
- nir_deref *store_deref = nir_copy_deref(store, &lhs_deref->deref);
- store->variables[0] = nir_deref_as_var(store_deref);
+ store->variables[0] = nir_deref_var_clone(lhs_deref, store);
store->src[0] = nir_src_for_ssa(src);
if (ir->condition) {
return deref;
}
-static nir_deref_var *
-copy_deref_var(void *mem_ctx, nir_deref_var *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_copy_deref(ret, deref->deref.child);
+ ret->deref.child = nir_deref_clone(deref->deref.child, ret);
return ret;
}
static nir_deref_array *
-copy_deref_array(void *mem_ctx, nir_deref_array *deref)
+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.type = deref->deref.type;
if (deref->deref.child)
- ret->deref.child = nir_copy_deref(ret, deref->deref.child);
+ ret->deref.child = nir_deref_clone(deref->deref.child, ret);
return ret;
}
static nir_deref_struct *
-copy_deref_struct(void *mem_ctx, nir_deref_struct *deref)
+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_copy_deref(ret, deref->deref.child);
+ ret->deref.child = nir_deref_clone(deref->deref.child, ret);
return ret;
}
nir_deref *
-nir_copy_deref(void *mem_ctx, nir_deref *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 ©_deref_var(mem_ctx, nir_deref_as_var(deref))->deref;
+ return &nir_deref_var_clone(nir_deref_as_var(deref), mem_ctx)->deref;
case nir_deref_type_array:
- return ©_deref_array(mem_ctx, nir_deref_as_array(deref))->deref;
+ return &deref_array_clone(nir_deref_as_array(deref), mem_ctx)->deref;
case nir_deref_type_struct:
- return ©_deref_struct(mem_ctx, nir_deref_as_struct(deref))->deref;
+ return &deref_struct_clone(nir_deref_as_struct(deref), mem_ctx)->deref;
default:
unreachable("Invalid dereference type");
}
nir_deref_array *nir_deref_array_create(void *mem_ctx);
nir_deref_struct *nir_deref_struct_create(void *mem_ctx, unsigned field_index);
-nir_deref *nir_copy_deref(void *mem_ctx, nir_deref *deref);
-
typedef bool (*nir_deref_foreach_leaf_cb)(nir_deref_var *deref, void *state);
bool nir_deref_foreach_leaf(nir_deref_var *deref,
nir_deref_foreach_leaf_cb cb, void *state);
nir_function_impl *nir_function_impl_clone(const nir_function_impl *fi);
nir_constant *nir_constant_clone(const nir_constant *c, nir_variable *var);
nir_variable *nir_variable_clone(const nir_variable *c, nir_shader *shader);
+nir_deref *nir_deref_clone(const nir_deref *deref, void *mem_ctx);
+nir_deref_var *nir_deref_var_clone(const nir_deref_var *deref, void *mem_ctx);
#ifdef DEBUG
void nir_validate_shader(nir_shader *shader);
nir_intrinsic_instr_create(build->shader, nir_intrinsic_store_var);
store->num_components = num_components;
store->const_index[0] = writemask & ((1 << num_components) - 1);
- store->variables[0] = nir_deref_as_var(nir_copy_deref(store, &deref->deref));
+ store->variables[0] = nir_deref_var_clone(deref, store);
store->src[0] = nir_src_for_ssa(value);
nir_builder_instr_insert(build, &store->instr);
}
nir_intrinsic_instr *copy =
nir_intrinsic_instr_create(build->shader, nir_intrinsic_copy_var);
- copy->variables[0] = nir_deref_as_var(nir_copy_deref(copy, &dest->deref));
- copy->variables[1] = nir_deref_as_var(nir_copy_deref(copy, &src->deref));
+ copy->variables[0] = nir_deref_var_clone(dest, copy);
+ copy->variables[1] = nir_deref_var_clone(src, copy);
nir_builder_instr_insert(build, ©->instr);
}
/* Now we make a new deref by concatenating the deref in the call's
* parameter with the deref we were given.
*/
- nir_deref_var *new_deref = nir_deref_as_var(nir_copy_deref(instr, &call_deref->deref));
+ nir_deref_var *new_deref = nir_deref_var_clone(call_deref, instr);
nir_deref *new_tail = nir_deref_tail(&new_deref->deref);
new_tail->child = (*deref)->deref.child;
ralloc_steal(new_tail, new_tail->child);
nir_intrinsic_instr *load =
nir_intrinsic_instr_create(b->shader, nir_intrinsic_load_var);
load->num_components = orig_instr->num_components;
- load->variables[0] =
- nir_deref_as_var(nir_copy_deref(load, &deref->deref));
+ load->variables[0] = nir_deref_var_clone(deref, load);
unsigned bit_size = orig_instr->dest.ssa.bit_size;
nir_ssa_dest_init(&load->instr, &load->dest,
load->num_components, bit_size, NULL);
nir_intrinsic_instr_create(b->shader, nir_intrinsic_store_var);
store->num_components = orig_instr->num_components;
nir_intrinsic_set_write_mask(store, nir_intrinsic_write_mask(orig_instr));
- store->variables[0] =
- nir_deref_as_var(nir_copy_deref(store, &deref->deref));
+ store->variables[0] = nir_deref_var_clone(deref, store);
store->src[0] = nir_src_for_ssa(src);
nir_builder_instr_insert(b, &store->instr);
}
txs->is_shadow = tex->is_shadow;
txs->is_new_style_shadow = tex->is_new_style_shadow;
txs->texture_index = tex->texture_index;
- txs->texture = (nir_deref_var *)
- nir_copy_deref(txs, &tex->texture->deref);
+ txs->texture = nir_deref_var_clone(tex->texture, txs);
txs->sampler_index = tex->sampler_index;
- txs->sampler = (nir_deref_var *)
- nir_copy_deref(txs, &tex->sampler->deref);
+ txs->sampler = nir_deref_var_clone(tex->sampler, txs);
txs->dest_type = nir_type_int;
/* only single src, the lod: */
plane_tex->coord_components = 2;
plane_tex->texture_index = tex->texture_index;
- plane_tex->texture = (nir_deref_var *)
- nir_copy_deref(plane_tex, &tex->texture->deref);
+ plane_tex->texture = nir_deref_var_clone(tex->texture, plane_tex);
plane_tex->sampler_index = tex->sampler_index;
- plane_tex->sampler = (nir_deref_var *)
- nir_copy_deref(plane_tex, &tex->sampler->deref);
+ plane_tex->sampler = nir_deref_var_clone(tex->sampler, plane_tex);
nir_ssa_dest_init(&plane_tex->instr, &plane_tex->dest, 4, 32, NULL);
txl->is_shadow = tex->is_shadow;
txl->is_new_style_shadow = tex->is_new_style_shadow;
txl->sampler_index = tex->sampler_index;
- txl->texture = (nir_deref_var *)
- nir_copy_deref(txl, &tex->texture->deref);
- txl->sampler = (nir_deref_var *)
- nir_copy_deref(txl, &tex->sampler->deref);
+ txl->texture = nir_deref_var_clone(tex->texture, txl);
+ txl->sampler = nir_deref_var_clone(tex->sampler, txl);
txl->coord_components = tex->coord_components;
nir_ssa_dest_init(&txl->instr, &txl->dest, 4, 32, NULL);
nir_intrinsic_instr *load =
nir_intrinsic_instr_create(mem_ctx, nir_intrinsic_load_var);
load->num_components = num_components;
- load->variables[0] = nir_deref_as_var(nir_copy_deref(load, &src_head->deref));
+ load->variables[0] = nir_deref_var_clone(src_head, load);
nir_ssa_dest_init(&load->instr, &load->dest, num_components, bit_size,
NULL);
nir_intrinsic_instr_create(mem_ctx, nir_intrinsic_store_var);
store->num_components = num_components;
nir_intrinsic_set_write_mask(store, (1 << num_components) - 1);
- store->variables[0] = nir_deref_as_var(nir_copy_deref(store, &dest_head->deref));
+ store->variables[0] = nir_deref_var_clone(dest_head, store);
store->src[0].is_ssa = true;
store->src[0].ssa = &load->dest.ssa;
*/
static void
split_var_copy_instr(nir_intrinsic_instr *old_copy,
- nir_deref *dest_head, nir_deref *src_head,
+ nir_deref_var *dest_head, nir_deref_var *src_head,
nir_deref *dest_tail, nir_deref *src_tail,
struct split_var_copies_state *state)
{
* belongs to the copy instruction and b) the deref chains may
* have some of the same links due to the way we constructed them
*/
- nir_deref *src = nir_copy_deref(new_copy, src_head);
- nir_deref *dest = nir_copy_deref(new_copy, dest_head);
-
- new_copy->variables[0] = nir_deref_as_var(dest);
- new_copy->variables[1] = nir_deref_as_var(src);
+ new_copy->variables[0] = nir_deref_var_clone(dest_head, new_copy);
+ new_copy->variables[1] = nir_deref_var_clone(src_head, new_copy);
/* Emit the copy instruction after the old instruction. We'll
* remove the old one later.
if (intrinsic->intrinsic != nir_intrinsic_copy_var)
continue;
- nir_deref *dest_head = &intrinsic->variables[0]->deref;
- nir_deref *src_head = &intrinsic->variables[1]->deref;
- nir_deref *dest_tail = nir_deref_tail(dest_head);
- nir_deref *src_tail = nir_deref_tail(src_head);
+ nir_deref_var *dest_head = intrinsic->variables[0];
+ nir_deref_var *src_head = intrinsic->variables[1];
+ nir_deref *dest_tail = nir_deref_tail(&dest_head->deref);
+ nir_deref *src_tail = nir_deref_tail(&src_head->deref);
switch (glsl_get_base_type(src_tail->type)) {
case GLSL_TYPE_ARRAY:
struct vtn_value *arg = vtn_untyped_value(b, arg_id);
if (arg->value_type == vtn_value_type_access_chain) {
nir_deref_var *d = vtn_access_chain_to_deref(b, arg->access_chain);
- call->params[i] = nir_deref_as_var(nir_copy_deref(call, &d->deref));
+ call->params[i] = nir_deref_var_clone(d, call);
} else {
struct vtn_ssa_value *arg_ssa = vtn_ssa_value(b, arg_id);
}
nir_deref_var *sampler = vtn_access_chain_to_deref(b, sampled.sampler);
- nir_deref *texture;
+ nir_deref_var *texture;
if (sampled.image) {
nir_deref_var *image = vtn_access_chain_to_deref(b, sampled.image);
- texture = &image->deref;
+ texture = image;
} else {
- texture = &sampler->deref;
+ texture = sampler;
}
- instr->texture = nir_deref_as_var(nir_copy_deref(instr, texture));
+ instr->texture = nir_deref_var_clone(texture, instr);
switch (instr->op) {
case nir_texop_tex:
case nir_texop_txl:
case nir_texop_txd:
/* These operations require a sampler */
- instr->sampler = nir_deref_as_var(nir_copy_deref(instr, &sampler->deref));
+ instr->sampler = nir_deref_var_clone(sampler, instr);
break;
case nir_texop_txf:
case nir_texop_txf_ms:
instrs[i]->is_new_style_shadow = instr->is_new_style_shadow;
instrs[i]->component = instr->component;
instrs[i]->dest_type = instr->dest_type;
- instrs[i]->texture =
- nir_deref_as_var(nir_copy_deref(instrs[i], texture));
+ instrs[i]->texture = nir_deref_var_clone(texture, instrs[i]);
instrs[i]->sampler = NULL;
memcpy(instrs[i]->src, srcs, instr->num_srcs * sizeof(*instr->src));
nir_intrinsic_instr *intrin = nir_intrinsic_instr_create(b->shader, op);
nir_deref_var *image_deref = vtn_access_chain_to_deref(b, image.image);
- intrin->variables[0] =
- nir_deref_as_var(nir_copy_deref(&intrin->instr, &image_deref->deref));
+ intrin->variables[0] = nir_deref_var_clone(image_deref, intrin);
/* ImageQuerySize doesn't take any extra parameters */
if (opcode != SpvOpImageQuerySize) {
if (chain->var->mode == vtn_variable_mode_workgroup) {
struct vtn_type *type = chain->var->type;
- nir_deref *deref = &vtn_access_chain_to_deref(b, chain)->deref;
+ nir_deref_var *deref = vtn_access_chain_to_deref(b, chain);
nir_intrinsic_op op = get_shared_nir_atomic_op(opcode);
atomic = nir_intrinsic_instr_create(b->nb.shader, op);
- atomic->variables[0] = nir_deref_as_var(nir_copy_deref(atomic, deref));
+ atomic->variables[0] = nir_deref_var_clone(deref, atomic);
switch (opcode) {
case SpvOpAtomicLoad:
nir_intrinsic_instr *intrin = nir_intrinsic_instr_create(b->nb.shader, op);
nir_deref_var *deref = vtn_nir_deref(b, w[5]);
- intrin->variables[0] =
- nir_deref_as_var(nir_copy_deref(intrin, &deref->deref));
+ intrin->variables[0] = nir_deref_var_clone(deref, intrin);
switch (opcode) {
case GLSLstd450InterpolateAtCentroid:
nir_intrinsic_store_var;
nir_intrinsic_instr *intrin = nir_intrinsic_instr_create(b->shader, op);
- intrin->variables[0] =
- nir_deref_as_var(nir_copy_deref(intrin, &deref->deref));
+ intrin->variables[0] = nir_deref_var_clone(deref, intrin);
intrin->num_components = glsl_get_vector_elements(tail->type);
if (load) {
tex->is_array = true;
tex->is_shadow = false;
- tex->texture =
- nir_deref_as_var(nir_copy_deref(tex, &load->variables[0]->deref));
+ tex->texture = nir_deref_var_clone(load->variables[0], tex);
tex->sampler = NULL;
tex->texture_index = 0;
tex->sampler_index = 0;