diff options
author | Karol Herbst <[email protected]> | 2018-07-13 03:33:22 +0200 |
---|---|---|
committer | Karol Herbst <[email protected]> | 2018-07-13 15:46:57 +0200 |
commit | cb65246ed2ac826285b6d6cc6e1994ff1299e531 (patch) | |
tree | 41b6f0180b5f5f41f7c96aed00e05f8917a3bdc3 /src/compiler/nir | |
parent | 0288fe8d0417730bdd5b3477130dd1dc32bdbcd3 (diff) |
nir: cleanup oversized arrays in nir_swizzle calls
There are no fixed sized array arguments in C, those are simply pointers
to unsized arrays and as the size is passed in anyway, just rely on that.
where possible calls are replaced by nir_channel and nir_channels.
Reviewed-by: Jason Ekstrand <[email protected]>
Signed-off-by: Karol Herbst <[email protected]>
Diffstat (limited to 'src/compiler/nir')
-rw-r--r-- | src/compiler/nir/nir_builder.h | 8 | ||||
-rw-r--r-- | src/compiler/nir/nir_lower_drawpixels.c | 7 | ||||
-rw-r--r-- | src/compiler/nir/nir_lower_tex.c | 11 |
3 files changed, 11 insertions, 15 deletions
diff --git a/src/compiler/nir/nir_builder.h b/src/compiler/nir/nir_builder.h index ae64e72663c..ed61771150a 100644 --- a/src/compiler/nir/nir_builder.h +++ b/src/compiler/nir/nir_builder.h @@ -430,12 +430,13 @@ nir_imov_alu(nir_builder *build, nir_alu_src src, unsigned num_components) * Construct an fmov or imov that reswizzles the source's components. */ static inline nir_ssa_def * -nir_swizzle(nir_builder *build, nir_ssa_def *src, const unsigned swiz[4], +nir_swizzle(nir_builder *build, nir_ssa_def *src, const unsigned *swiz, unsigned num_components, bool use_fmov) { + assert(num_components <= 4); nir_alu_src alu_src = { NIR_SRC_INIT }; alu_src.src = nir_src_for_ssa(src); - for (unsigned i = 0; i < num_components; i++) + for (unsigned i = 0; i < num_components && i < 4; i++) alu_src.swizzle[i] = swiz[i]; return use_fmov ? nir_fmov_alu(build, alu_src, num_components) : @@ -481,8 +482,7 @@ nir_bany(nir_builder *b, nir_ssa_def *src) static inline nir_ssa_def * nir_channel(nir_builder *b, nir_ssa_def *def, unsigned c) { - unsigned swizzle[4] = {c, c, c, c}; - return nir_swizzle(b, def, swizzle, 1, false); + return nir_swizzle(b, def, &c, 1, false); } static inline nir_ssa_def * diff --git a/src/compiler/nir/nir_lower_drawpixels.c b/src/compiler/nir/nir_lower_drawpixels.c index f7ff5c07eaf..462b9c308b2 100644 --- a/src/compiler/nir/nir_lower_drawpixels.c +++ b/src/compiler/nir/nir_lower_drawpixels.c @@ -151,9 +151,6 @@ lower_color(lower_drawpixels_state *state, nir_intrinsic_instr *intr) } if (state->options->pixel_maps) { - static const unsigned swiz_xy[4] = {0,1}; - static const unsigned swiz_zw[4] = {2,3}; - /* do four pixel map look-ups with two TEX instructions: */ nir_ssa_def *def_xy, *def_zw; @@ -166,7 +163,7 @@ lower_color(lower_drawpixels_state *state, nir_intrinsic_instr *intr) tex->texture_index = state->options->pixelmap_sampler; tex->dest_type = nir_type_float; tex->src[0].src_type = nir_tex_src_coord; - tex->src[0].src = nir_src_for_ssa(nir_swizzle(b, def, swiz_xy, 2, true)); + tex->src[0].src = nir_src_for_ssa(nir_channels(b, def, 0x3)); nir_ssa_dest_init(&tex->instr, &tex->dest, 4, 32, NULL); nir_builder_instr_insert(b, &tex->instr); @@ -180,7 +177,7 @@ lower_color(lower_drawpixels_state *state, nir_intrinsic_instr *intr) tex->sampler_index = state->options->pixelmap_sampler; tex->dest_type = nir_type_float; tex->src[0].src_type = nir_tex_src_coord; - tex->src[0].src = nir_src_for_ssa(nir_swizzle(b, def, swiz_zw, 2, true)); + tex->src[0].src = nir_src_for_ssa(nir_channels(b, def, 0xc)); nir_ssa_dest_init(&tex->instr, &tex->dest, 4, 32, NULL); nir_builder_instr_insert(b, &tex->instr); diff --git a/src/compiler/nir/nir_lower_tex.c b/src/compiler/nir/nir_lower_tex.c index 1ccd253320c..9f550542fa1 100644 --- a/src/compiler/nir/nir_lower_tex.c +++ b/src/compiler/nir/nir_lower_tex.c @@ -479,8 +479,8 @@ lower_gradient_cube_map(nir_builder *b, nir_tex_instr *tex) nir_ssa_def *cond_z = nir_fge(b, abs_p_z, nir_fmax(b, abs_p_x, abs_p_y)); nir_ssa_def *cond_y = nir_fge(b, abs_p_y, nir_fmax(b, abs_p_x, abs_p_z)); - unsigned yzx[4] = { 1, 2, 0, 0 }; - unsigned xzy[4] = { 0, 2, 1, 0 }; + unsigned yzx[3] = { 1, 2, 0 }; + unsigned xzy[3] = { 0, 2, 1 }; Q = nir_bcsel(b, cond_z, p, @@ -508,16 +508,15 @@ lower_gradient_cube_map(nir_builder *b, nir_tex_instr *tex) */ nir_ssa_def *rcp_Q_z = nir_frcp(b, nir_channel(b, Q, 2)); - unsigned xy[4] = { 0, 1, 0, 0 }; - nir_ssa_def *Q_xy = nir_swizzle(b, Q, xy, 2, false); + nir_ssa_def *Q_xy = nir_channels(b, Q, 0x3); nir_ssa_def *tmp = nir_fmul(b, Q_xy, rcp_Q_z); - nir_ssa_def *dQdx_xy = nir_swizzle(b, dQdx, xy, 2, false); + nir_ssa_def *dQdx_xy = nir_channels(b, dQdx, 0x3); nir_ssa_def *dQdx_z = nir_channel(b, dQdx, 2); nir_ssa_def *dx = nir_fmul(b, rcp_Q_z, nir_fsub(b, dQdx_xy, nir_fmul(b, tmp, dQdx_z))); - nir_ssa_def *dQdy_xy = nir_swizzle(b, dQdy, xy, 2, false); + nir_ssa_def *dQdy_xy = nir_channels(b, dQdy, 0x3); nir_ssa_def *dQdy_z = nir_channel(b, dQdy, 2); nir_ssa_def *dy = nir_fmul(b, rcp_Q_z, nir_fsub(b, dQdy_xy, nir_fmul(b, tmp, dQdy_z))); |