nir: Add a lowering pass for UYVY textures
authorJohnson Lin <johnson.lin@intel.com>
Fri, 16 Jun 2017 05:40:31 +0000 (13:40 +0800)
committerLionel Landwerlin <lionel.g.landwerlin@intel.com>
Fri, 30 Jun 2017 09:16:26 +0000 (10:16 +0100)
Similar with support for YUYV but with byte order difference in sampler

Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com>
src/compiler/nir/nir.h
src/compiler/nir/nir_lower_tex.c

index ab7ba14303b788bc0ec168b9e3cda7dec0c9ef45..1b4e47058d4d608c6305005d25105f11a81ad25d 100644 (file)
@@ -2449,6 +2449,7 @@ typedef struct nir_lower_tex_options {
    unsigned lower_y_uv_external;
    unsigned lower_y_u_v_external;
    unsigned lower_yx_xuxv_external;
+   unsigned lower_xy_uxvx_external;
 
    /**
     * To emulate certain texture wrap modes, this can be used
index 4ef81955513e6d6ac82894da7ccad0f608e3eb2e..65681decb1c0d49561536cc8098938a6fd9df0bd 100644 (file)
@@ -301,6 +301,20 @@ lower_yx_xuxv_external(nir_builder *b, nir_tex_instr *tex)
                       nir_channel(b, xuxv, 3));
 }
 
+static void
+lower_xy_uxvx_external(nir_builder *b, nir_tex_instr *tex)
+{
+  b->cursor = nir_after_instr(&tex->instr);
+
+  nir_ssa_def *y = sample_plane(b, tex, 0);
+  nir_ssa_def *uxvx = sample_plane(b, tex, 1);
+
+  convert_yuv_to_rgb(b, tex,
+                     nir_channel(b, y, 1),
+                     nir_channel(b, uxvx, 0),
+                     nir_channel(b, uxvx, 2));
+}
+
 /*
  * Emits a textureLod operation used to replace an existing
  * textureGrad instruction.
@@ -760,6 +774,10 @@ nir_lower_tex_block(nir_block *block, nir_builder *b,
          progress = true;
       }
 
+      if ((1 << tex->texture_index) & options->lower_xy_uxvx_external) {
+         lower_xy_uxvx_external(b, tex);
+         progress = true;
+      }
 
       if (sat_mask) {
          saturate_src(b, tex, sat_mask);