<div dir="auto"><div>It doesn't matter if the opcode supplies a lod. The only thing that matters is if the opcode computes derivatives. It seems that the only opcodes computing derivatives are tex, tex_bias, and query_lod. This only applies to fragment shaders. Other stages never compute derivatives. There is an NV extension that enables derivatives in compute shaders.</div><div dir="auto"><br></div><div dir="auto">Marek<br><br><div class="gmail_quote" dir="auto"><div dir="ltr" class="gmail_attr">On Thu, May 30, 2019, 2:47 PM Rhys Perry <<a href="mailto:pendingchaos02@gmail.com">pendingchaos02@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Seems txf can(should?) have a lod supplied. txf_ms and tg4 always use<br>
the 0th level.<br>
<br>
I'll add txf, txf_ms and tg4 to the list of nir_texop which don't ever<br>
have implicit derivatives.<br>
<br>
On Thu, 30 May 2019 at 19:43, Ilia Mirkin <<a href="mailto:imirkin@alum.mit.edu" target="_blank" rel="noreferrer">imirkin@alum.mit.edu</a>> wrote:<br>
><br>
> txf supplies an lod, but tg4's is implicitly always 0.<br>
><br>
> On Thu, May 30, 2019 at 2:26 PM Bas Nieuwenhuizen<br>
> <<a href="mailto:bas@basnieuwenhuizen.nl" target="_blank" rel="noreferrer">bas@basnieuwenhuizen.nl</a>> wrote:<br>
> ><br>
> > On Thu, May 30, 2019 at 6:50 PM Rhys Perry <<a href="mailto:pendingchaos02@gmail.com" target="_blank" rel="noreferrer">pendingchaos02@gmail.com</a>> wrote:<br>
> > ><br>
> > > Otherwise LLVM can sink them and their texture coordinate calculations<br>
> > > into divergent branches.<br>
> > ><br>
> > > Cc: <<a href="mailto:mesa-stable@lists.freedesktop.org" target="_blank" rel="noreferrer">mesa-stable@lists.freedesktop.org</a>><br>
> > > Signed-off-by: Rhys Perry <<a href="mailto:pendingchaos02@gmail.com" target="_blank" rel="noreferrer">pendingchaos02@gmail.com</a>><br>
> > > ---<br>
> > > src/amd/common/ac_nir_to_llvm.c | 29 +++++++++++++++++++++++++++++<br>
> > > 1 file changed, 29 insertions(+)<br>
> > ><br>
> > > diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c<br>
> > > index 265e3b636c4..d2dc617de36 100644<br>
> > > --- a/src/amd/common/ac_nir_to_llvm.c<br>
> > > +++ b/src/amd/common/ac_nir_to_llvm.c<br>
> > > @@ -1316,6 +1316,30 @@ static nir_deref_instr *get_tex_texture_deref(const nir_tex_instr *instr)<br>
> > > return texture_deref_instr;<br>
> > > }<br>
> > ><br>
> > > +static bool has_implicit_derivatives(const nir_tex_instr *instr)<br>
> > > +{<br>
> > > + switch (instr->op) {<br>
> > > + case nir_texop_txs:<br>
> > > + case nir_texop_query_levels:<br>
> > > + case nir_texop_texture_samples:<br>
> > > + case nir_texop_samples_identical:<br>
> > > + return false;<br>
> > > + default:<br>
> > > + break;<br>
> > > + }<br>
> > > + for (unsigned i = 0; i < instr->num_srcs; i++) {<br>
> > > + switch (instr->src[i].src_type) {<br>
> > > + case nir_tex_src_lod:<br>
> > > + case nir_tex_src_ddx:<br>
> > > + case nir_tex_src_ddy:<br>
> > > + return false;<br>
> > > + default:<br>
> > > + break;<br>
> > > + }<br>
> > > + }<br>
> > > + return true;<br>
> > > +}<br>
> ><br>
> > txf, tg4 and friends do not provide any of lod/ddx/ddy do they?<br>
> ><br>
> > > +<br>
> > > static LLVMValueRef build_tex_intrinsic(struct ac_nir_context *ctx,<br>
> > > const nir_tex_instr *instr,<br>
> > > struct ac_image_args *args)<br>
> > > @@ -1394,6 +1418,11 @@ static LLVMValueRef build_tex_intrinsic(struct ac_nir_context *ctx,<br>
> > > }<br>
> > ><br>
> > > args->attributes = AC_FUNC_ATTR_READNONE;<br>
> > > + /* Prevent texture instructions with implicit derivatives from being<br>
> > > + * sinked into branches. */<br>
> > > + if (has_implicit_derivatives(instr))<br>
> > > + args->attributes |= AC_FUNC_ATTR_CONVERGENT;<br>
> > > +<br>
> > > return ac_build_image_opcode(&ctx->ac, args);<br>
> > > }<br>
> > ><br>
> > > --<br>
> > > 2.21.0<br>
> > ><br>
> > _______________________________________________<br>
> > mesa-dev mailing list<br>
> > <a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank" rel="noreferrer">mesa-dev@lists.freedesktop.org</a><br>
> > <a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank" rel="noreferrer">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a></blockquote></div></div></div>