Rather than make yet another copy of channel(), let's move it into nir.
Signed-off-by: Rob Clark <robclark@freedesktop.org>
Reviewed-by: Jason Ekstrand <jason.ekstrand@intel.com>
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.
#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)
{
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");
* 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)
{
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));
*/
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,