nir/lower_tex: Rework invalid implicit LOD lowering
authorJason Ekstrand <jason@jlekstrand.net>
Fri, 9 Jul 2021 16:34:23 +0000 (11:34 -0500)
committerMarge Bot <eric+marge@anholt.net>
Fri, 23 Jul 2021 15:53:57 +0000 (15:53 +0000)
commit74ec2b12be17a7796186b3100a5a6b208be45b23
treed2e964ae6e09cfb897d2a1da9cfa1054467099ac
parentf9442e46ff61c37358d5dc3fa49c6e4f474b4674
nir/lower_tex: Rework invalid implicit LOD lowering

Only fragment and some compute shaders support implicit derivatives.
They're totally meaningless without helper invocations and some
understanding of the dispatch pattern.  We've got code to lower
nir_texop_tex in these shader stages to use an explicit derivative of 0
but it was pretty badly broken:

 1. It only handled nir_texop_tex, not nir_texop_txb or nir_texop_lod.

 2. It didn't take min_lod into account

 3. It was conflated with adding a missing LOD parameter to opcodes
    which expect one such as nir_texop_txf.  While not really a bug,
    this does make it way harder to reason about the code.

 4. Unless you set a flag (which most drivers don't), it left the
    opcode nir_texop_tex instead of nir_texop_txl which it should have
    been.

This reworks it to go through roughly the same path as other LOD
lowering only with a constant lod of 0 instead of calling out to
nir_texop_lod.  We also get rid of the lower_tex_without_implicit_lod
flag because most drivers set it and those that don't are probably
subtly broken.  If someone really wants to get nir_texop_tex in their
vertex shaders, they can write a new patch to add the flag back in.

Fixes: e382890e25c0 "nir: set default lod to texture opcodes that..."
Fixes: d5ac5d6e836f "nir: Add option to lower tex to txl when..."
Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11775>
src/compiler/nir/nir.h
src/compiler/nir/nir_lower_tex.c
src/gallium/auxiliary/gallivm/lp_bld_nir.c
src/intel/compiler/brw_nir.c
src/panfrost/bifrost/bifrost_compile.c