Mesa (main): nir/lower_tex: Add support for lowering YUYV formats

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri May 21 02:07:17 UTC 2021


Module: Mesa
Branch: main
Commit: 880b00dc59973ee64cf0ce5f21dc13f19ac12e70
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=880b00dc59973ee64cf0ce5f21dc13f19ac12e70

Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Fri Mar 12 23:07:09 2021 -0800

nir/lower_tex: Add support for lowering YUYV formats

v2: Rebase on bc438c91d9b ("nir/lower_tex: ignore texture_index if
tex_instr has deref src")

Reviewed-by: Emma Anholt <emma at anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9610>

---

 src/compiler/nir/nir.h           |  1 +
 src/compiler/nir/nir_lower_tex.c | 23 +++++++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 03fce223f5d..c89663575e7 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -4721,6 +4721,7 @@ typedef struct nir_lower_tex_options {
    unsigned lower_ayuv_external;
    unsigned lower_xyuv_external;
    unsigned lower_yuv_external;
+   unsigned lower_yu_yv_external;
    unsigned lower_y41x_external;
    unsigned bt709_external;
    unsigned bt2020_external;
diff --git a/src/compiler/nir/nir_lower_tex.c b/src/compiler/nir/nir_lower_tex.c
index 6f3df7d6282..e96676c2ffa 100644
--- a/src/compiler/nir/nir_lower_tex.c
+++ b/src/compiler/nir/nir_lower_tex.c
@@ -490,6 +490,24 @@ lower_yuv_external(nir_builder *b, nir_tex_instr *tex,
                      texture_index);
 }
 
+static void
+lower_yu_yv_external(nir_builder *b, nir_tex_instr *tex,
+                     const nir_lower_tex_options *options,
+                     unsigned texture_index)
+{
+  b->cursor = nir_after_instr(&tex->instr);
+
+  nir_ssa_def *yuv = sample_plane(b, tex, 0, options);
+
+  convert_yuv_to_rgb(b, tex,
+                     nir_channel(b, yuv, 1),
+                     nir_channel(b, yuv, 2),
+                     nir_channel(b, yuv, 0),
+                     nir_imm_float(b, 1.0f),
+                     options,
+                     texture_index);
+}
+
 /*
  * Converts a nir_texop_txd instruction to nir_texop_txl with the given lod
  * computed from the gradients.
@@ -1227,6 +1245,11 @@ nir_lower_tex_block(nir_block *block, nir_builder *b,
          progress = true;
       }
 
+      if ((1 << tex->texture_index) & options->lower_yu_yv_external) {
+         lower_yu_yv_external(b, tex, options, texture_index);
+         progress = true;
+      }
+
       if ((1 << tex->texture_index) & options->lower_y41x_external) {
          lower_y41x_external(b, tex, options, texture_index);
          progress = true;



More information about the mesa-commit mailing list