nir: Add nir_lower_tex support for Broadcom's swizzled TG4 results.
authorEric Anholt <eric@anholt.net>
Thu, 27 Dec 2018 06:45:04 +0000 (22:45 -0800)
committerEric Anholt <eric@anholt.net>
Tue, 8 Jan 2019 21:03:41 +0000 (13:03 -0800)
V3D returns the texels in a different order in the resulting vec4 from
what GLSL wants, so we need to put in a swizzle.  Fixes
dEQP-GLES31.functional.texture.gather.basic.2d.rgba8.base_level.level_1

Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/broadcom/compiler/vir.c
src/compiler/nir/nir.h
src/compiler/nir/nir_lower_tex.c

index 01e18ffd07446526dde5cd9f711ceaacee14354d..4e6149d11aa319abb38d57c43181bd2423d4c1cb 100644 (file)
@@ -611,6 +611,8 @@ v3d_lower_nir(struct v3d_compile *c)
 {
         struct nir_lower_tex_options tex_options = {
                 .lower_txd = true,
+                .lower_tg4_broadcom_swizzle = true,
+
                 .lower_rect = false, /* XXX: Use this on V3D 3.x */
                 .lower_txp = ~0,
                 /* Apply swizzles to all samplers. */
index 76c09069985827dc3a2c7acf882353cf336c1fad..318ffb33cef9a9dfaac6e0ad01b537879e46b377 100644 (file)
@@ -3085,6 +3085,12 @@ typedef struct nir_lower_tex_options {
     */
    bool lower_txd_offset_clamp;
 
+   /**
+    * If true, apply a .bagr swizzle on tg4 results to handle Broadcom's
+    * mixed-up tg4 locations.
+    */
+   bool lower_tg4_broadcom_swizzle;
+
    enum nir_lower_tex_packing lower_tex_packing[32];
 } nir_lower_tex_options;
 
index 001c525e66602b4bf0e193e2505b33e025715969..a618b86b34c56eae6d5ed292622e6a79300f7c99 100644 (file)
@@ -738,6 +738,21 @@ get_zero_or_one(nir_builder *b, nir_alu_type type, uint8_t swizzle_val)
    return nir_build_imm(b, 4, 32, v);
 }
 
+static void
+swizzle_tg4_broadcom(nir_builder *b, nir_tex_instr *tex)
+{
+   assert(tex->dest.is_ssa);
+
+   b->cursor = nir_after_instr(&tex->instr);
+
+   assert(nir_tex_instr_dest_size(tex) == 4);
+   unsigned swiz[4] = { 2, 3, 1, 0 };
+   nir_ssa_def *swizzled = nir_swizzle(b, &tex->dest.ssa, swiz, 4, false);
+
+   nir_ssa_def_rewrite_uses_after(&tex->dest.ssa, nir_src_for_ssa(swizzled),
+                                  swizzled->parent_instr);
+}
+
 static void
 swizzle_result(nir_builder *b, nir_tex_instr *tex, const uint8_t swizzle[4])
 {
@@ -937,6 +952,11 @@ nir_lower_tex_block(nir_block *block, nir_builder *b,
          progress = true;
       }
 
+      if (tex->op == nir_texop_tg4 && options->lower_tg4_broadcom_swizzle) {
+         swizzle_tg4_broadcom(b, tex);
+         progress = true;
+      }
+
       if (((1 << tex->texture_index) & options->swizzle_result) &&
           !nir_tex_instr_is_query(tex) &&
           !(tex->is_shadow && tex->is_new_style_shadow)) {