agx: Handle indirect texture/samplers
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Mon, 27 Feb 2023 02:53:16 +0000 (21:53 -0500)
committerMarge Bot <emma+marge@anholt.net>
Fri, 10 Mar 2023 14:14:42 +0000 (14:14 +0000)
Get the texture/sampler index from the texture/sampler_offset source (which
is an offset from 0 thanks to the lower_index_to_offset lowering) and feed it in
as corresponding 16-bit texture instruction sources.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21704>

src/asahi/compiler/agx_compile.c
src/asahi/compiler/agx_nir_lower_texture.c

index ea596b4..0ea574e 100644 (file)
@@ -1348,6 +1348,13 @@ agx_emit_tex(agx_builder *b, nir_tex_instr *instr)
          compare = index;
          break;
 
+      case nir_tex_src_texture_offset:
+         texture = index;
+         break;
+      case nir_tex_src_sampler_offset:
+         sampler = index;
+         break;
+
       case nir_tex_src_ddx: {
          int y_idx = nir_tex_instr_src_index(instr, nir_tex_src_ddy);
          assert(y_idx >= 0 && "we only handle gradients");
@@ -1373,10 +1380,8 @@ agx_emit_tex(agx_builder *b, nir_tex_instr *instr)
          /* handled above */
          break;
 
-      case nir_tex_src_texture_offset:
-      case nir_tex_src_sampler_offset:
       default:
-         unreachable("todo");
+         unreachable("Unexpected texture source");
       }
    }
 
index d338e50..fddec9a 100644 (file)
@@ -38,15 +38,16 @@ texture_descriptor_ptr(nir_builder *b, nir_tex_instr *tex)
    if (handle_idx >= 0)
       return tex->src[handle_idx].src.ssa;
 
-   /* For non-bindless, compute from the texture index, offset, and table */
-   unsigned base_B = tex->texture_index * AGX_TEXTURE_DESC_STRIDE;
-   nir_ssa_def *offs = nir_imm_int(b, base_B);
+   /* For non-bindless, compute from the texture index */
+   nir_ssa_def *offs;
 
    int offs_idx = nir_tex_instr_src_index(tex, nir_tex_src_texture_offset);
    if (offs_idx >= 0) {
       nir_ssa_def *offset_src = tex->src[offs_idx].src.ssa;
-      offs = nir_iadd(b, offs,
-                      nir_imul_imm(b, offset_src, AGX_TEXTURE_DESC_STRIDE));
+      offs = nir_imul_imm(b, offset_src, AGX_TEXTURE_DESC_STRIDE);
+   } else {
+      unsigned base_B = tex->texture_index * AGX_TEXTURE_DESC_STRIDE;
+      offs = nir_imm_int(b, base_B);
    }
 
    return nir_iadd(b, nir_load_texture_base_agx(b), nir_u2u64(b, offs));
@@ -322,6 +323,7 @@ agx_nir_lower_texture(nir_shader *s, bool support_lod_bias)
       .lower_txp = ~0,
       .lower_invalid_implicit_lod = true,
       .lower_tg4_offsets = true,
+      .lower_index_to_offset = true,
 
       /* XXX: Metal seems to handle just like 3D txd, so why doesn't it work?
        * TODO: Stop using this lowering
@@ -333,6 +335,8 @@ agx_nir_lower_texture(nir_shader *s, bool support_lod_bias)
       [nir_tex_src_lod] = {true, 16},
       [nir_tex_src_bias] = {true, 16},
       [nir_tex_src_ms_index] = {true, 16},
+      [nir_tex_src_texture_offset] = {true, 16},
+      [nir_tex_src_sampler_offset] = {true, 16},
    };
 
    NIR_PASS(progress, s, nir_lower_tex, &lower_tex_options);