[Mesa-dev] [PATCH 11/28] nir/builder: Add a helper for grabbing multiple channels from an ssa def

Jason Ekstrand jason at jlekstrand.net
Tue May 10 23:16:31 UTC 2016


This is similar to nir_channel except that it lets you grab more than one
channel by providing a mask.
---
 src/compiler/nir/nir_builder.h     | 14 ++++++++++++++
 src/intel/vulkan/anv_meta_blit2d.c |  4 +---
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/src/compiler/nir/nir_builder.h b/src/compiler/nir/nir_builder.h
index 756188f..32d619f 100644
--- a/src/compiler/nir/nir_builder.h
+++ b/src/compiler/nir/nir_builder.h
@@ -324,6 +324,20 @@ nir_channel(nir_builder *b, nir_ssa_def *def, unsigned c)
    return nir_swizzle(b, def, swizzle, 1, false);
 }
 
+static inline nir_ssa_def *
+nir_channels(nir_builder *b, nir_ssa_def *def, unsigned mask)
+{
+   unsigned num_channels = 0, swizzle[4] = { 0, 0, 0, 0 };
+
+   for (unsigned i = 0; i < 4; i++) {
+      if ((mask & (1 << i)) == 0)
+         continue;
+      swizzle[num_channels++] = i;
+   }
+
+   return nir_swizzle(b, def, swizzle, num_channels, false);
+}
+
 /**
  * Turns a nir_src into a nir_ssa_def * so it can be passed to
  * nir_build_alu()-based builder calls.
diff --git a/src/intel/vulkan/anv_meta_blit2d.c b/src/intel/vulkan/anv_meta_blit2d.c
index 577eeae..06e1043 100644
--- a/src/intel/vulkan/anv_meta_blit2d.c
+++ b/src/intel/vulkan/anv_meta_blit2d.c
@@ -1010,9 +1010,7 @@ build_nir_w_tiled_fragment_shader(struct anv_device *device,
    discard->src[0] = nir_src_for_ssa(oob);
    nir_builder_instr_insert(&b, &discard->instr);
 
-   unsigned swiz[4] = { 0, 1, 0, 0 };
-   nir_ssa_def *tex_off =
-      nir_swizzle(&b, nir_load_var(&b, tex_off_in), swiz, 2, false);
+   nir_ssa_def *tex_off = nir_channels(&b, nir_load_var(&b, tex_off_in), 0x3);
    nir_ssa_def *tex_pos = nir_iadd(&b, nir_vec2(&b, x_W, y_W), tex_off);
    nir_ssa_def *tex_pitch = nir_channel(&b, nir_load_var(&b, tex_off_in), 2);
 
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list