[Mesa-dev] [PATCH] nir: add nir_swizzle
Rob Clark
robdclark at gmail.com
Thu Sep 10 13:08:11 PDT 2015
From: Rob Clark <robclark at freedesktop.org>
Rather than make yet another copy of channel(), let's move it into nir.
Signed-off-by: Rob Clark <robclark at freedesktop.org>
---
src/glsl/nir/nir_builder.h | 6 ++++++
src/glsl/nir/nir_lower_tex_projector.c | 24 +++++++++---------------
src/glsl/nir/nir_normalize_cubemap_coords.c | 20 +++++++-------------
3 files changed, 22 insertions(+), 28 deletions(-)
diff --git a/src/glsl/nir/nir_builder.h b/src/glsl/nir/nir_builder.h
index ba988d7..6568493 100644
--- a/src/glsl/nir/nir_builder.h
+++ b/src/glsl/nir/nir_builder.h
@@ -216,6 +216,12 @@ nir_swizzle(nir_builder *build, nir_ssa_def *src, unsigned swiz[4],
nir_imov_alu(build, alu_src, num_components);
}
+static inline nir_ssa_def *
+nir_channel(nir_builder *b, nir_ssa_def *def, int c)
+{
+ return nir_swizzle(b, def, (unsigned[4]){c, c, c, c}, 1, 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/glsl/nir/nir_lower_tex_projector.c b/src/glsl/nir/nir_lower_tex_projector.c
index 8a482b1..7126ca7 100644
--- a/src/glsl/nir/nir_lower_tex_projector.c
+++ b/src/glsl/nir/nir_lower_tex_projector.c
@@ -30,12 +30,6 @@
#include "nir.h"
#include "nir_builder.h"
-static nir_ssa_def *
-channel(nir_builder *b, nir_ssa_def *def, int c)
-{
- return nir_swizzle(b, def, (unsigned[4]){c, c, c, c}, 1, false);
-}
-
static bool
nir_lower_tex_projector_block(nir_block *block, void *void_state)
{
@@ -79,21 +73,21 @@ nir_lower_tex_projector_block(nir_block *block, void *void_state)
switch (tex->coord_components) {
case 4:
projected = nir_vec4(b,
- channel(b, projected, 0),
- channel(b, projected, 1),
- channel(b, projected, 2),
- channel(b, unprojected, 3));
+ nir_channel(b, projected, 0),
+ nir_channel(b, projected, 1),
+ nir_channel(b, projected, 2),
+ nir_channel(b, unprojected, 3));
break;
case 3:
projected = nir_vec3(b,
- channel(b, projected, 0),
- channel(b, projected, 1),
- channel(b, unprojected, 2));
+ nir_channel(b, projected, 0),
+ nir_channel(b, projected, 1),
+ nir_channel(b, unprojected, 2));
break;
case 2:
projected = nir_vec2(b,
- channel(b, projected, 0),
- channel(b, unprojected, 1));
+ nir_channel(b, projected, 0),
+ nir_channel(b, unprojected, 1));
break;
default:
unreachable("bad texture coord count for array");
diff --git a/src/glsl/nir/nir_normalize_cubemap_coords.c b/src/glsl/nir/nir_normalize_cubemap_coords.c
index 75b647f..ca68bd7 100644
--- a/src/glsl/nir/nir_normalize_cubemap_coords.c
+++ b/src/glsl/nir/nir_normalize_cubemap_coords.c
@@ -33,12 +33,6 @@
* or 1.0. This is based on the old GLSL IR based pass by Eric.
*/
-static nir_ssa_def *
-channel(nir_builder *b, nir_ssa_def *def, int c)
-{
- return nir_swizzle(b, def, (unsigned[4]){c, c, c, c}, 1, false);
-}
-
static bool
normalize_cubemap_coords_block(nir_block *block, void *void_state)
{
@@ -63,9 +57,9 @@ normalize_cubemap_coords_block(nir_block *block, void *void_state)
assert(orig_coord->num_components >= 3);
nir_ssa_def *abs = nir_fabs(b, orig_coord);
- nir_ssa_def *norm = nir_fmax(b, channel(b, abs, 0),
- nir_fmax(b, channel(b, abs, 1),
- channel(b, abs, 2)));
+ nir_ssa_def *norm = nir_fmax(b, nir_channel(b, abs, 0),
+ nir_fmax(b, nir_channel(b, abs, 1),
+ nir_channel(b, abs, 2)));
nir_ssa_def *normalized = nir_fmul(b, orig_coord, nir_frcp(b, norm));
@@ -74,10 +68,10 @@ normalize_cubemap_coords_block(nir_block *block, void *void_state)
*/
if (tex->coord_components == 4) {
normalized = nir_vec4(b,
- channel(b, normalized, 0),
- channel(b, normalized, 1),
- channel(b, normalized, 2),
- channel(b, orig_coord, 3));
+ nir_channel(b, normalized, 0),
+ nir_channel(b, normalized, 1),
+ nir_channel(b, normalized, 2),
+ nir_channel(b, orig_coord, 3));
}
nir_instr_rewrite_src(&tex->instr,
--
2.4.3
More information about the mesa-dev
mailing list