<div dir="auto"><div><br><div class="gmail_extra"><br><div class="gmail_quote">On Dec 27, 2016 7:05 AM, "Eduardo Lima Mitev" <<a href="mailto:elima@igalia.com">elima@igalia.com</a>> wrote:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="quoted-text">On 12/26/2016 06:13 PM, Jason Ekstrand wrote:<br>
> We rename it to nir_deref_clone, re-order the sources to match the other<br>
> clone functions, and expose nir_deref_var_clone. This past part, in<br>
> particular, lets us get rid of quite a few lines since we no longer have<br>
> to call nir_copy_deref and wrap it in deref_to_var.<br>
> ---<br>
><br>
<br>
</div>This patch brings a number of regressions in piglit at least, crashing<br>
tests that were passing or failing before. All of them crash because<br>
nir_deref_var_clone() gets called with a null 'deref' argument. The<br>
attached diff fixes all crashes I found, but I only tried piglit, so<br>
there could be more. Maybe the solution is just adding a check for<br>
nullness to 'deref' argument inside nir_deref_var_clone() ?<br></blockquote></div></div></div><div dir="auto"><br></div><div dir="auto">I've already done that locally</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The list of regressions are:<br>
<br>
spec/arb_shader_texture_lod/<wbr>compiler/tex_grad-texturecube-<wbr>cube-vec3.frag<br>
<br>
spec/arb_shader_texture_lod/<wbr>execution/arb_shader_texture_<wbr>lod-texgradcube<br>
<br>
spec/arb_shader_texture_lod/<wbr>execution/tex-miplevel-<wbr>selection *gradarb cube<br>
<br>
spec/arb_texture_cube_map_<wbr>array/compiler/tex_grad-01.<wbr>frag<br>
<br>
spec/ext_image_dma_buf_import/<wbr>ext_image_dma_buf_import-<wbr>sample_nv12<br>
<br>
spec/ext_image_dma_buf_import/<wbr>ext_image_dma_buf_import-<wbr>sample_yuv420<br>
<br>
spec/ext_image_dma_buf_import/<wbr>ext_image_dma_buf_import-<wbr>sample_yvu420<br>
<br>
spec/glsl-1.30/execution/tex-<wbr>miplevel-selection texturegrad cube<br>
<br>
spec/glsl-1.30/execution/tex-<wbr>miplevel-selection texturegrad cubearray<br>
<br>
spec/glsl-1.30/execution/tex-<wbr>miplevel-selection texturegrad cubeshadow<br>
<br>
<br>
An example gdb backtrace:<br>
<br>
Starting program: piglit/bin/glslparsertest<br>
generated_tests/spec/arb_<wbr>shader_texture_lod/compiler/<wbr>tex_grad-textureCube-Cube-<wbr>vec3.frag<br>
pass 1.10 GL_ARB_shader_texture_lod<br>
[Thread debugging using libthread_db enabled]<br>
Using host libthread_db library "/lib/x86_64-linux-gnu/<wbr>libthread_db.so.1".<br>
<br>
Program received signal SIGSEGV, Segmentation fault.<br>
0x00007ffff1720f09 in nir_deref_var_clone (deref=0x0, mem_ctx=0x786c40)<br>
at nir/nir.c:630<br>
630 nir_deref_var *ret = nir_deref_var_create(mem_ctx, deref->var);<br>
(gdb) bt<br>
#0 0x00007ffff1720f09 in nir_deref_var_clone (deref=0x0,<br>
mem_ctx=0x786c40) at nir/nir.c:630<br>
#1 0x00007ffff1759f95 in get_texture_size (b=0x7fffffffd7e0,<br>
tex=0x782260) at nir/nir_lower_tex.c:168<br>
#2 0x00007ffff175af05 in lower_gradient_cube_map (b=0x7fffffffd7e0,<br>
tex=0x782260) at nir/nir_lower_tex.c:363<br>
#3 0x00007ffff175c6bc in nir_lower_tex_block (block=0x781000,<br>
b=0x7fffffffd7e0, options=0x7ffff1a42ce0 <tex_options>) at<br>
nir/nir_lower_tex.c:786<br>
#4 0x00007ffff175c78b in nir_lower_tex_impl (impl=0x780f10,<br>
options=0x7ffff1a42ce0 <tex_options>) at nir/nir_lower_tex.c:811<br>
#5 0x00007ffff175c810 in nir_lower_tex (shader=0x7878e0,<br>
options=0x7ffff1a42ce0 <tex_options>) at nir/nir_lower_tex.c:826<br>
#6 0x00007ffff18c7152 in brw_preprocess_nir (compiler=0x62e760,<br>
nir=0x7878e0) at brw_nir.c:494<br>
#7 0x00007ffff17c1b6b in brw_create_nir (brw=0x7ffff7f80040,<br>
shader_prog=0x8f42d0, prog=0x780680, stage=MESA_SHADER_FRAGMENT,<br>
is_scalar=true) at brw_program.c:93<br>
#8 0x00007ffff17b927e in brw_link_shader (ctx=0x7ffff7f80040,<br>
shProg=0x8f42d0) at brw_link.cpp:245<br>
#9 0x00007ffff162a676 in _mesa_glsl_link_shader (ctx=0x7ffff7f80040,<br>
prog=0x8f42d0) at program/ir_to_mesa.cpp:3066<br>
#10 0x00007ffff14bd7bc in _mesa_link_program (ctx=0x7ffff7f80040,<br>
shProg=0x8f42d0) at main/shaderapi.c:1089<br>
#11 0x00007ffff14be87d in _mesa_LinkProgram (programObj=2) at<br>
main/shaderapi.c:1595<br>
#12 0x00007ffff7ac9c3d in stub_glLinkProgram (program=2) at<br>
tests/util/piglit-dispatch-<wbr>gen.c:33005<br>
#13 0x000000000040206f in test () at<br>
tests/glslparsertest/<wbr>glslparsertest.c:345<br>
#14 0x00000000004026ed in piglit_init (argc=5, argv=0x7fffffffdd68) at<br>
tests/glslparsertest/<wbr>glslparsertest.c:543<br>
#15 0x00007ffff7b3b0b0 in run_test (gl_fw=0x615c20, argc=5,<br>
argv=0x7fffffffdd68) at<br>
tests/util/piglit-framework-<wbr>gl/piglit_winsys_framework.c:<wbr>73<br>
#16 0x00007ffff7b1fbe4 in piglit_gl_test_run (argc=5,<br>
argv=0x7fffffffdd68, config=0x7fffffffdc20) at<br>
tests/util/piglit-framework-<wbr>gl.c:203<br>
#17 0x000000000040196e in main (argc=5, argv=0x7fffffffdd68) at<br>
tests/glslparsertest/<wbr>glslparsertest.c:90<br>
<font color="#888888"><br>
Eduardo<br>
</font><div class="elided-text"><br>
> src/compiler/glsl/glsl_to_nir.<wbr>cpp | 3 +--<br>
> src/compiler/nir/nir.c | 22 +++++++++++-----------<br>
> src/compiler/nir/nir.h | 4 ++--<br>
> src/compiler/nir/nir_builder.h | 6 +++---<br>
> src/compiler/nir/nir_inline_<wbr>functions.c | 2 +-<br>
> src/compiler/nir/nir_lower_<wbr>indirect_derefs.c | 6 ++----<br>
> src/compiler/nir/nir_lower_<wbr>tex.c | 18 ++++++------------<br>
> src/compiler/nir/nir_lower_<wbr>var_copies.c | 4 ++--<br>
> src/compiler/nir/nir_split_<wbr>var_copies.c | 17 +++++++----------<br>
> src/compiler/spirv/spirv_to_<wbr>nir.c | 22 ++++++++++------------<br>
> src/compiler/spirv/vtn_<wbr>glsl450.c | 3 +--<br>
> src/compiler/spirv/vtn_<wbr>variables.c | 3 +--<br>
> src/intel/vulkan/anv_nir_<wbr>lower_input_attachments.c | 3 +--<br>
> 13 files changed, 48 insertions(+), 65 deletions(-)<br>
><br>
> diff --git a/src/compiler/glsl/glsl_to_<wbr>nir.cpp b/src/compiler/glsl/glsl_to_<wbr>nir.cpp<br>
> index fcaca9f..8efd030 100644<br>
> --- a/src/compiler/glsl/glsl_to_<wbr>nir.cpp<br>
> +++ b/src/compiler/glsl/glsl_to_<wbr>nir.cpp<br>
> @@ -1179,8 +1179,7 @@ nir_visitor::visit(ir_<wbr>assignment *ir)<br>
> nir_intrinsic_instr_create(<wbr>this->shader, nir_intrinsic_store_var);<br>
> store->num_components = ir->lhs->type->vector_<wbr>elements;<br>
> nir_intrinsic_set_write_mask(<wbr>store, ir->write_mask);<br>
> - nir_deref *store_deref = nir_copy_deref(store, &lhs_deref->deref);<br>
> - store->variables[0] = nir_deref_as_var(store_deref);<br>
> + store->variables[0] = nir_deref_var_clone(lhs_deref, store);<br>
> store->src[0] = nir_src_for_ssa(src);<br>
><br>
> if (ir->condition) {<br>
> diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c<br>
> index 885616e..6057143 100644<br>
> --- a/src/compiler/nir/nir.c<br>
> +++ b/src/compiler/nir/nir.c<br>
> @@ -624,18 +624,18 @@ nir_deref_struct_create(void *mem_ctx, unsigned field_index)<br>
> return deref;<br>
> }<br>
><br>
> -static nir_deref_var *<br>
> -copy_deref_var(void *mem_ctx, nir_deref_var *deref)<br>
> +nir_deref_var *<br>
> +nir_deref_var_clone(const nir_deref_var *deref, void *mem_ctx)<br>
> {<br>
> nir_deref_var *ret = nir_deref_var_create(mem_ctx, deref->var);<br>
> ret->deref.type = deref->deref.type;<br>
> if (deref->deref.child)<br>
> - ret->deref.child = nir_copy_deref(ret, deref->deref.child);<br>
> + ret->deref.child = nir_deref_clone(deref->deref.<wbr>child, ret);<br>
> return ret;<br>
> }<br>
><br>
> static nir_deref_array *<br>
> -copy_deref_array(void *mem_ctx, nir_deref_array *deref)<br>
> +deref_array_clone(const nir_deref_array *deref, void *mem_ctx)<br>
> {<br>
> nir_deref_array *ret = nir_deref_array_create(mem_<wbr>ctx);<br>
> ret->base_offset = deref->base_offset;<br>
> @@ -645,33 +645,33 @@ copy_deref_array(void *mem_ctx, nir_deref_array *deref)<br>
> }<br>
> ret->deref.type = deref->deref.type;<br>
> if (deref->deref.child)<br>
> - ret->deref.child = nir_copy_deref(ret, deref->deref.child);<br>
> + ret->deref.child = nir_deref_clone(deref->deref.<wbr>child, ret);<br>
> return ret;<br>
> }<br>
><br>
> static nir_deref_struct *<br>
> -copy_deref_struct(void *mem_ctx, nir_deref_struct *deref)<br>
> +deref_struct_clone(const nir_deref_struct *deref, void *mem_ctx)<br>
> {<br>
> nir_deref_struct *ret = nir_deref_struct_create(mem_<wbr>ctx, deref->index);<br>
> ret->deref.type = deref->deref.type;<br>
> if (deref->deref.child)<br>
> - ret->deref.child = nir_copy_deref(ret, deref->deref.child);<br>
> + ret->deref.child = nir_deref_clone(deref->deref.<wbr>child, ret);<br>
> return ret;<br>
> }<br>
><br>
> nir_deref *<br>
> -nir_copy_deref(void *mem_ctx, nir_deref *deref)<br>
> +nir_deref_clone(const nir_deref *deref, void *mem_ctx)<br>
> {<br>
> if (deref == NULL)<br>
> return NULL;<br>
><br>
> switch (deref->deref_type) {<br>
> case nir_deref_type_var:<br>
> - return ©_deref_var(mem_ctx, nir_deref_as_var(deref))-><wbr>deref;<br>
> + return &nir_deref_var_clone(nir_<wbr>deref_as_var(deref), mem_ctx)->deref;<br>
> case nir_deref_type_array:<br>
> - return ©_deref_array(mem_ctx, nir_deref_as_array(deref))-><wbr>deref;<br>
> + return &deref_array_clone(nir_deref_<wbr>as_array(deref), mem_ctx)->deref;<br>
> case nir_deref_type_struct:<br>
> - return ©_deref_struct(mem_ctx, nir_deref_as_struct(deref))-><wbr>deref;<br>
> + return &deref_struct_clone(nir_deref_<wbr>as_struct(deref), mem_ctx)->deref;<br>
> default:<br>
> unreachable("Invalid dereference type");<br>
> }<br>
> diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h<br>
> index 6557631..d896679 100644<br>
> --- a/src/compiler/nir/nir.h<br>
> +++ b/src/compiler/nir/nir.h<br>
> @@ -1927,8 +1927,6 @@ nir_deref_var *nir_deref_var_create(void *mem_ctx, nir_variable *var);<br>
> nir_deref_array *nir_deref_array_create(void *mem_ctx);<br>
> nir_deref_struct *nir_deref_struct_create(void *mem_ctx, unsigned field_index);<br>
><br>
> -nir_deref *nir_copy_deref(void *mem_ctx, nir_deref *deref);<br>
> -<br>
> typedef bool (*nir_deref_foreach_leaf_cb)(<wbr>nir_deref_var *deref, void *state);<br>
> bool nir_deref_foreach_leaf(nir_<wbr>deref_var *deref,<br>
> nir_deref_foreach_leaf_cb cb, void *state);<br>
> @@ -2236,6 +2234,8 @@ nir_shader *nir_shader_clone(void *mem_ctx, const nir_shader *s);<br>
> nir_function_impl *nir_function_impl_clone(const nir_function_impl *fi);<br>
> nir_constant *nir_constant_clone(const nir_constant *c, nir_variable *var);<br>
> nir_variable *nir_variable_clone(const nir_variable *c, nir_shader *shader);<br>
> +nir_deref *nir_deref_clone(const nir_deref *deref, void *mem_ctx);<br>
> +nir_deref_var *nir_deref_var_clone(const nir_deref_var *deref, void *mem_ctx);<br>
><br>
> #ifdef DEBUG<br>
> void nir_validate_shader(nir_shader *shader);<br>
> diff --git a/src/compiler/nir/nir_<wbr>builder.h b/src/compiler/nir/nir_<wbr>builder.h<br>
> index 0ee7d1a..2ea9af1 100644<br>
> --- a/src/compiler/nir/nir_<wbr>builder.h<br>
> +++ b/src/compiler/nir/nir_<wbr>builder.h<br>
> @@ -437,7 +437,7 @@ nir_store_deref_var(nir_<wbr>builder *build, nir_deref_var *deref,<br>
> nir_intrinsic_instr_create(<wbr>build->shader, nir_intrinsic_store_var);<br>
> store->num_components = num_components;<br>
> store->const_index[0] = writemask & ((1 << num_components) - 1);<br>
> - store->variables[0] = nir_deref_as_var(nir_copy_<wbr>deref(store, &deref->deref));<br>
> + store->variables[0] = nir_deref_var_clone(deref, store);<br>
> store->src[0] = nir_src_for_ssa(value);<br>
> nir_builder_instr_insert(<wbr>build, &store->instr);<br>
> }<br>
> @@ -450,8 +450,8 @@ nir_copy_deref_var(nir_builder *build, nir_deref_var *dest, nir_deref_var *src)<br>
><br>
> nir_intrinsic_instr *copy =<br>
> nir_intrinsic_instr_create(<wbr>build->shader, nir_intrinsic_copy_var);<br>
> - copy->variables[0] = nir_deref_as_var(nir_copy_<wbr>deref(copy, &dest->deref));<br>
> - copy->variables[1] = nir_deref_as_var(nir_copy_<wbr>deref(copy, &src->deref));<br>
> + copy->variables[0] = nir_deref_var_clone(dest, copy);<br>
> + copy->variables[1] = nir_deref_var_clone(src, copy);<br>
> nir_builder_instr_insert(<wbr>build, ©->instr);<br>
> }<br>
><br>
> diff --git a/src/compiler/nir/nir_inline_<wbr>functions.c b/src/compiler/nir/nir_inline_<wbr>functions.c<br>
> index c36748d..b91e7bc 100644<br>
> --- a/src/compiler/nir/nir_inline_<wbr>functions.c<br>
> +++ b/src/compiler/nir/nir_inline_<wbr>functions.c<br>
> @@ -49,7 +49,7 @@ convert_deref_to_param_deref(<wbr>nir_instr *instr, nir_deref_var **deref,<br>
> /* Now we make a new deref by concatenating the deref in the call's<br>
> * parameter with the deref we were given.<br>
> */<br>
> - nir_deref_var *new_deref = nir_deref_as_var(nir_copy_<wbr>deref(instr, &call_deref->deref));<br>
> + nir_deref_var *new_deref = nir_deref_var_clone(call_<wbr>deref, instr);<br>
> nir_deref *new_tail = nir_deref_tail(&new_deref-><wbr>deref);<br>
> new_tail->child = (*deref)->deref.child;<br>
> ralloc_steal(new_tail, new_tail->child);<br>
> diff --git a/src/compiler/nir/nir_lower_<wbr>indirect_derefs.c b/src/compiler/nir/nir_lower_<wbr>indirect_derefs.c<br>
> index 5c97dc8e..09cc9a3 100644<br>
> --- a/src/compiler/nir/nir_lower_<wbr>indirect_derefs.c<br>
> +++ b/src/compiler/nir/nir_lower_<wbr>indirect_derefs.c<br>
> @@ -122,8 +122,7 @@ emit_load_store(nir_builder *b, nir_intrinsic_instr *orig_instr,<br>
> nir_intrinsic_instr *load =<br>
> nir_intrinsic_instr_create(b-><wbr>shader, nir_intrinsic_load_var);<br>
> load->num_components = orig_instr->num_components;<br>
> - load->variables[0] =<br>
> - nir_deref_as_var(nir_copy_<wbr>deref(load, &deref->deref));<br>
> + load->variables[0] = nir_deref_var_clone(deref, load);<br>
> unsigned bit_size = orig_instr->dest.ssa.bit_size;<br>
> nir_ssa_dest_init(&load-><wbr>instr, &load->dest,<br>
> load->num_components, bit_size, NULL);<br>
> @@ -135,8 +134,7 @@ emit_load_store(nir_builder *b, nir_intrinsic_instr *orig_instr,<br>
> nir_intrinsic_instr_create(b-><wbr>shader, nir_intrinsic_store_var);<br>
> store->num_components = orig_instr->num_components;<br>
> nir_intrinsic_set_write_mask(<wbr>store, nir_intrinsic_write_mask(orig_<wbr>instr));<br>
> - store->variables[0] =<br>
> - nir_deref_as_var(nir_copy_<wbr>deref(store, &deref->deref));<br>
> + store->variables[0] = nir_deref_var_clone(deref, store);<br>
> store->src[0] = nir_src_for_ssa(src);<br>
> nir_builder_instr_insert(b, &store->instr);<br>
> }<br>
> diff --git a/src/compiler/nir/nir_lower_<wbr>tex.c b/src/compiler/nir/nir_lower_<wbr>tex.c<br>
> index 3e3ac8c..66e2317 100644<br>
> --- a/src/compiler/nir/nir_lower_<wbr>tex.c<br>
> +++ b/src/compiler/nir/nir_lower_<wbr>tex.c<br>
> @@ -163,11 +163,9 @@ get_texture_size(nir_builder *b, nir_tex_instr *tex)<br>
> txs->is_shadow = tex->is_shadow;<br>
> txs->is_new_style_shadow = tex->is_new_style_shadow;<br>
> txs->texture_index = tex->texture_index;<br>
> - txs->texture = (nir_deref_var *)<br>
> - nir_copy_deref(txs, &tex->texture->deref);<br>
> + txs->texture = nir_deref_var_clone(tex-><wbr>texture, txs);<br>
> txs->sampler_index = tex->sampler_index;<br>
> - txs->sampler = (nir_deref_var *)<br>
> - nir_copy_deref(txs, &tex->sampler->deref);<br>
> + txs->sampler = nir_deref_var_clone(tex-><wbr>sampler, txs);<br>
> txs->dest_type = nir_type_int;<br>
><br>
> /* only single src, the lod: */<br>
> @@ -221,11 +219,9 @@ sample_plane(nir_builder *b, nir_tex_instr *tex, int plane)<br>
> plane_tex->coord_components = 2;<br>
><br>
> plane_tex->texture_index = tex->texture_index;<br>
> - plane_tex->texture = (nir_deref_var *)<br>
> - nir_copy_deref(plane_tex, &tex->texture->deref);<br>
> + plane_tex->texture = nir_deref_var_clone(tex-><wbr>texture, plane_tex);<br>
> plane_tex->sampler_index = tex->sampler_index;<br>
> - plane_tex->sampler = (nir_deref_var *)<br>
> - nir_copy_deref(plane_tex, &tex->sampler->deref);<br>
> + plane_tex->sampler = nir_deref_var_clone(tex-><wbr>sampler, plane_tex);<br>
><br>
> nir_ssa_dest_init(&plane_tex-><wbr>instr, &plane_tex->dest, 4, 32, NULL);<br>
><br>
> @@ -325,10 +321,8 @@ replace_gradient_with_lod(nir_<wbr>builder *b, nir_ssa_def *lod, nir_tex_instr *tex)<br>
> txl->is_shadow = tex->is_shadow;<br>
> txl->is_new_style_shadow = tex->is_new_style_shadow;<br>
> txl->sampler_index = tex->sampler_index;<br>
> - txl->texture = (nir_deref_var *)<br>
> - nir_copy_deref(txl, &tex->texture->deref);<br>
> - txl->sampler = (nir_deref_var *)<br>
> - nir_copy_deref(txl, &tex->sampler->deref);<br>
> + txl->texture = nir_deref_var_clone(tex-><wbr>texture, txl);<br>
> + txl->sampler = nir_deref_var_clone(tex-><wbr>sampler, txl);<br>
> txl->coord_components = tex->coord_components;<br>
><br>
> nir_ssa_dest_init(&txl->instr, &txl->dest, 4, 32, NULL);<br>
> diff --git a/src/compiler/nir/nir_lower_<wbr>var_copies.c b/src/compiler/nir/nir_lower_<wbr>var_copies.c<br>
> index b7e9989..b12d953 100644<br>
> --- a/src/compiler/nir/nir_lower_<wbr>var_copies.c<br>
> +++ b/src/compiler/nir/nir_lower_<wbr>var_copies.c<br>
> @@ -121,7 +121,7 @@ emit_copy_load_store(nir_<wbr>intrinsic_instr *copy_instr,<br>
> nir_intrinsic_instr *load =<br>
> nir_intrinsic_instr_create(<wbr>mem_ctx, nir_intrinsic_load_var);<br>
> load->num_components = num_components;<br>
> - load->variables[0] = nir_deref_as_var(nir_copy_<wbr>deref(load, &src_head->deref));<br>
> + load->variables[0] = nir_deref_var_clone(src_head, load);<br>
> nir_ssa_dest_init(&load-><wbr>instr, &load->dest, num_components, bit_size,<br>
> NULL);<br>
><br>
> @@ -131,7 +131,7 @@ emit_copy_load_store(nir_<wbr>intrinsic_instr *copy_instr,<br>
> nir_intrinsic_instr_create(<wbr>mem_ctx, nir_intrinsic_store_var);<br>
> store->num_components = num_components;<br>
> nir_intrinsic_set_write_mask(<wbr>store, (1 << num_components) - 1);<br>
> - store->variables[0] = nir_deref_as_var(nir_copy_<wbr>deref(store, &dest_head->deref));<br>
> + store->variables[0] = nir_deref_var_clone(dest_head, store);<br>
><br>
> store->src[0].is_ssa = true;<br>
> store->src[0].ssa = &load->dest.ssa;<br>
> diff --git a/src/compiler/nir/nir_split_<wbr>var_copies.c b/src/compiler/nir/nir_split_<wbr>var_copies.c<br>
> index 63a7611..cfebb0b 100644<br>
> --- a/src/compiler/nir/nir_split_<wbr>var_copies.c<br>
> +++ b/src/compiler/nir/nir_split_<wbr>var_copies.c<br>
> @@ -82,7 +82,7 @@ struct split_var_copies_state {<br>
> */<br>
> static void<br>
> split_var_copy_instr(nir_<wbr>intrinsic_instr *old_copy,<br>
> - nir_deref *dest_head, nir_deref *src_head,<br>
> + nir_deref_var *dest_head, nir_deref_var *src_head,<br>
> nir_deref *dest_tail, nir_deref *src_tail,<br>
> struct split_var_copies_state *state)<br>
> {<br>
> @@ -182,11 +182,8 @@ split_var_copy_instr(nir_<wbr>intrinsic_instr *old_copy,<br>
> * belongs to the copy instruction and b) the deref chains may<br>
> * have some of the same links due to the way we constructed them<br>
> */<br>
> - nir_deref *src = nir_copy_deref(new_copy, src_head);<br>
> - nir_deref *dest = nir_copy_deref(new_copy, dest_head);<br>
> -<br>
> - new_copy->variables[0] = nir_deref_as_var(dest);<br>
> - new_copy->variables[1] = nir_deref_as_var(src);<br>
> + new_copy->variables[0] = nir_deref_var_clone(dest_head, new_copy);<br>
> + new_copy->variables[1] = nir_deref_var_clone(src_head, new_copy);<br>
><br>
> /* Emit the copy instruction after the old instruction. We'll<br>
> * remove the old one later.<br>
> @@ -216,10 +213,10 @@ split_var_copies_block(nir_<wbr>block *block, struct split_var_copies_state *state)<br>
> if (intrinsic->intrinsic != nir_intrinsic_copy_var)<br>
> continue;<br>
><br>
> - nir_deref *dest_head = &intrinsic->variables[0]-><wbr>deref;<br>
> - nir_deref *src_head = &intrinsic->variables[1]-><wbr>deref;<br>
> - nir_deref *dest_tail = nir_deref_tail(dest_head);<br>
> - nir_deref *src_tail = nir_deref_tail(src_head);<br>
> + nir_deref_var *dest_head = intrinsic->variables[0];<br>
> + nir_deref_var *src_head = intrinsic->variables[1];<br>
> + nir_deref *dest_tail = nir_deref_tail(&dest_head-><wbr>deref);<br>
> + nir_deref *src_tail = nir_deref_tail(&src_head-><wbr>deref);<br>
><br>
> switch (glsl_get_base_type(src_tail-><wbr>type)) {<br>
> case GLSL_TYPE_ARRAY:<br>
> diff --git a/src/compiler/spirv/spirv_to_<wbr>nir.c b/src/compiler/spirv/spirv_to_<wbr>nir.c<br>
> index 57d0886..739fa71 100644<br>
> --- a/src/compiler/spirv/spirv_to_<wbr>nir.c<br>
> +++ b/src/compiler/spirv/spirv_to_<wbr>nir.c<br>
> @@ -1206,7 +1206,7 @@ vtn_handle_function_call(<wbr>struct vtn_builder *b, SpvOp opcode,<br>
> struct vtn_value *arg = vtn_untyped_value(b, arg_id);<br>
> if (arg->value_type == vtn_value_type_access_chain) {<br>
> nir_deref_var *d = vtn_access_chain_to_deref(b, arg->access_chain);<br>
> - call->params[i] = nir_deref_as_var(nir_copy_<wbr>deref(call, &d->deref));<br>
> + call->params[i] = nir_deref_var_clone(d, call);<br>
> } else {<br>
> struct vtn_ssa_value *arg_ssa = vtn_ssa_value(b, arg_id);<br>
><br>
> @@ -1542,15 +1542,15 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode,<br>
> }<br>
><br>
> nir_deref_var *sampler = vtn_access_chain_to_deref(b, sampled.sampler);<br>
> - nir_deref *texture;<br>
> + nir_deref_var *texture;<br>
> if (sampled.image) {<br>
> nir_deref_var *image = vtn_access_chain_to_deref(b, sampled.image);<br>
> - texture = &image->deref;<br>
> + texture = image;<br>
> } else {<br>
> - texture = &sampler->deref;<br>
> + texture = sampler;<br>
> }<br>
><br>
> - instr->texture = nir_deref_as_var(nir_copy_<wbr>deref(instr, texture));<br>
> + instr->texture = nir_deref_var_clone(texture, instr);<br>
><br>
> switch (instr->op) {<br>
> case nir_texop_tex:<br>
> @@ -1558,7 +1558,7 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode,<br>
> case nir_texop_txl:<br>
> case nir_texop_txd:<br>
> /* These operations require a sampler */<br>
> - instr->sampler = nir_deref_as_var(nir_copy_<wbr>deref(instr, &sampler->deref));<br>
> + instr->sampler = nir_deref_var_clone(sampler, instr);<br>
> break;<br>
> case nir_texop_txf:<br>
> case nir_texop_txf_ms:<br>
> @@ -1599,8 +1599,7 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode,<br>
> instrs[i]->is_new_style_shadow = instr->is_new_style_shadow;<br>
> instrs[i]->component = instr->component;<br>
> instrs[i]->dest_type = instr->dest_type;<br>
> - instrs[i]->texture =<br>
> - nir_deref_as_var(nir_copy_<wbr>deref(instrs[i], texture));<br>
> + instrs[i]->texture = nir_deref_var_clone(texture, instrs[i]);<br>
> instrs[i]->sampler = NULL;<br>
><br>
> memcpy(instrs[i]->src, srcs, instr->num_srcs * sizeof(*instr->src));<br>
> @@ -1807,8 +1806,7 @@ vtn_handle_image(struct vtn_builder *b, SpvOp opcode,<br>
> nir_intrinsic_instr *intrin = nir_intrinsic_instr_create(b-><wbr>shader, op);<br>
><br>
> nir_deref_var *image_deref = vtn_access_chain_to_deref(b, image.image);<br>
> - intrin->variables[0] =<br>
> - nir_deref_as_var(nir_copy_<wbr>deref(&intrin->instr, &image_deref->deref));<br>
> + intrin->variables[0] = nir_deref_var_clone(image_<wbr>deref, intrin);<br>
><br>
> /* ImageQuerySize doesn't take any extra parameters */<br>
> if (opcode != SpvOpImageQuerySize) {<br>
> @@ -1967,10 +1965,10 @@ vtn_handle_ssbo_or_shared_<wbr>atomic(struct vtn_builder *b, SpvOp opcode,<br>
><br>
> if (chain->var->mode == vtn_variable_mode_workgroup) {<br>
> struct vtn_type *type = chain->var->type;<br>
> - nir_deref *deref = &vtn_access_chain_to_deref(b, chain)->deref;<br>
> + nir_deref_var *deref = vtn_access_chain_to_deref(b, chain);<br>
> nir_intrinsic_op op = get_shared_nir_atomic_op(<wbr>opcode);<br>
> atomic = nir_intrinsic_instr_create(b-><wbr>nb.shader, op);<br>
> - atomic->variables[0] = nir_deref_as_var(nir_copy_<wbr>deref(atomic, deref));<br>
> + atomic->variables[0] = nir_deref_var_clone(deref, atomic);<br>
><br>
> switch (opcode) {<br>
> case SpvOpAtomicLoad:<br>
> diff --git a/src/compiler/spirv/vtn_<wbr>glsl450.c b/src/compiler/spirv/vtn_<wbr>glsl450.c<br>
> index fbc7ce6..a19676f 100644<br>
> --- a/src/compiler/spirv/vtn_<wbr>glsl450.c<br>
> +++ b/src/compiler/spirv/vtn_<wbr>glsl450.c<br>
> @@ -667,8 +667,7 @@ handle_glsl450_interpolation(<wbr>struct vtn_builder *b, enum GLSLstd450 opcode,<br>
> nir_intrinsic_instr *intrin = nir_intrinsic_instr_create(b-><wbr>nb.shader, op);<br>
><br>
> nir_deref_var *deref = vtn_nir_deref(b, w[5]);<br>
> - intrin->variables[0] =<br>
> - nir_deref_as_var(nir_copy_<wbr>deref(intrin, &deref->deref));<br>
> + intrin->variables[0] = nir_deref_var_clone(deref, intrin);<br>
><br>
> switch (opcode) {<br>
> case GLSLstd450InterpolateAtCentroi<wbr>d:<br>
> diff --git a/src/compiler/spirv/vtn_<wbr>variables.c b/src/compiler/spirv/vtn_<wbr>variables.c<br>
> index be64dd9..de7c8fe 100644<br>
> --- a/src/compiler/spirv/vtn_<wbr>variables.c<br>
> +++ b/src/compiler/spirv/vtn_<wbr>variables.c<br>
> @@ -186,8 +186,7 @@ _vtn_local_load_store(struct vtn_builder *b, bool load, nir_deref_var *deref,<br>
> nir_intrinsic_store_var;<br>
><br>
> nir_intrinsic_instr *intrin = nir_intrinsic_instr_create(b-><wbr>shader, op);<br>
> - intrin->variables[0] =<br>
> - nir_deref_as_var(nir_copy_<wbr>deref(intrin, &deref->deref));<br>
> + intrin->variables[0] = nir_deref_var_clone(deref, intrin);<br>
> intrin->num_components = glsl_get_vector_elements(tail-<wbr>>type);<br>
><br>
> if (load) {<br>
> diff --git a/src/intel/vulkan/anv_nir_<wbr>lower_input_attachments.c b/src/intel/vulkan/anv_nir_<wbr>lower_input_attachments.c<br>
> index e11b563..1d6f727 100644<br>
> --- a/src/intel/vulkan/anv_nir_<wbr>lower_input_attachments.c<br>
> +++ b/src/intel/vulkan/anv_nir_<wbr>lower_input_attachments.c<br>
> @@ -86,8 +86,7 @@ try_lower_input_load(nir_<wbr>function_impl *impl, nir_intrinsic_instr *load)<br>
> tex->is_array = true;<br>
> tex->is_shadow = false;<br>
><br>
> - tex->texture =<br>
> - nir_deref_as_var(nir_copy_<wbr>deref(tex, &load->variables[0]->deref));<br>
> + tex->texture = nir_deref_var_clone(load-><wbr>variables[0], tex);<br>
> tex->sampler = NULL;<br>
> tex->texture_index = 0;<br>
> tex->sampler_index = 0;<br>
><br>
<br>
</div></blockquote></div><br></div></div></div>