<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Oct 11, 2017 at 9:42 AM, Eric Anholt <span dir="ltr"><<a href="mailto:eric@anholt.net" target="_blank">eric@anholt.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">Samuel Iglesias Gonsálvez <<a href="mailto:siglesias@igalia.com">siglesias@igalia.com</a>> writes:<br>
<br>
</span>> [ Unknown signature status ]<br>
<div><div class="h5">> On Tuesday, October 10, 2017 11:53:27 AM CEST Eric Anholt wrote:<br>
>> Samuel Iglesias Gonsálvez <<a href="mailto:siglesias@igalia.com">siglesias@igalia.com</a>> writes:<br>
>> > Signed-off-by: Samuel Iglesias Gonsálvez <<a href="mailto:siglesias@igalia.com">siglesias@igalia.com</a>><br>
>> > ---<br>
>> ><br>
>> > src/compiler/nir/nir_lower_<wbr>tex.c | 68<br>
>> > ++++++++++++++++++++++++++++++<wbr>++++++++++ 1 file changed, 68<br>
>> > insertions(+)<br>
>> ><br>
>> > diff --git a/src/compiler/nir/nir_lower_<wbr>tex.c<br>
>> > b/src/compiler/nir/nir_lower_<wbr>tex.c index 65681decb1c..d3380710405 100644<br>
>> > --- a/src/compiler/nir/nir_lower_<wbr>tex.c<br>
>> > +++ b/src/compiler/nir/nir_lower_<wbr>tex.c<br>
>> > @@ -717,6 +717,52 @@ linearize_srgb_result(nir_<wbr>builder *b, nir_tex_instr<br>
>> > *tex)><br>
>> > result->parent_instr);<br>
>> ><br>
>> > }<br>
>> ><br>
>> > +static void<br>
>> > +set_default_lod(nir_builder *b, nir_tex_instr *tex)<br>
>> > +{<br>
>> > + b->cursor = nir_before_instr(&tex->instr);<br>
>> > +<br>
>> > + /* We are going to emit the same texture but adding a default LOD.<br>
>> > + */<br>
>> > + int num_srcs = tex->num_srcs + 1;<br>
>> > + nir_tex_instr *new = nir_tex_instr_create(b-><wbr>shader, num_srcs);<br>
>> > +<br>
>> > + new->op = tex->op;<br>
>> > + new->sampler_dim = tex->sampler_dim;<br>
>> > + new->texture_index = tex->texture_index;<br>
>> > + new->dest_type = tex->dest_type;<br>
>> > + new->is_array = tex->is_array;<br>
>> > + new->is_shadow = tex->is_shadow;<br>
>> > + new->is_new_style_shadow = tex->is_new_style_shadow;<br>
>> > + new->sampler_index = tex->sampler_index;<br>
>> > + new->texture = nir_deref_var_clone(tex-><wbr>texture, new);<br>
>> > + new->sampler = nir_deref_var_clone(tex-><wbr>sampler, new);<br>
>> > + new->coord_components = tex->coord_components;<br>
>><br>
>> Couldn't we just make a new srcs array of num_srcs+1, memcpy the old<br>
>> srcs/types over, add our new use of the immediate 0 lod to it by<br>
>> manipulating the immediate's uses list<br>
><br>
> This is an interesting approach. I have done the following:<br>
><br>
> b->cursor = nir_before_instr(&tex->instr);<br>
><br>
> nir_tex_src *srcs = ralloc_array(tex, nir_tex_src, tex->num_srcs + 1);<br>
> memcpy(srcs, tex->src, sizeof(nir_tex_src) * tex->num_srcs);<br>
><br>
> srcs[tex->num_srcs + 1].src = nir_src_for_ssa(nir_imm_int(b, 0));<br>
> srcs[tex->num_srcs + 1].src_type = nir_tex_src_lod;<br>
> tex->num_srcs++;<br>
> ralloc_free(tex->src);<br>
> tex->src = srcs;<br>
><br>
> However, it crashes when validating ssa def. I also tried calling<br>
> nir_ssa_def_rewrite_uses() but I am not sure how to do it for this case,<br>
> probably I am missing something.<br>
><br>
> How can I manipulate the immediate's uses list for this case? Can you provide<br>
> an example?<br>
<br>
</div></div>When you nir_instr_insert() in your original code, add_defs_uses() will<br>
call add_use_cb() on this src. I was thinking that you could just<br>
open-code that bit (or maybe we want to make the body of that function<br>
public?)<br>
<br>
Oh, wait, reallocating the srcs array would break the uses entries of<br>
all the other srcs, so you'd need to remove uses from the old list and<br>
add all of the new list. It's less clear to me now whether this is a<br>
good way to go.<br></blockquote></div></div><div class="gmail_extra"><br></div><div class="gmail_extra">I think just resizing the sources array is the right thing to do. However, Lionel is 100% correct that we really need a helper for this. There are several places which have to deal with it and it's always a pain. anv_nir_apply_pipeline_layout has examples of both growing and shrinking.<br></div></div>