mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-06-07 03:58:19 +02:00
nir: fsub -> fadd_imm
When doing nir_fsub(b, x, imm), we can negate the immediate value, and replace the fsub with nir_fadd_imm() and get the same result. This makes the code a bit shorter and easier to read. Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com> Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23179>
This commit is contained in:
parent
5382b4fc2e
commit
c4d2ebd285
8 changed files with 14 additions and 14 deletions
|
|
@ -48,7 +48,7 @@ radv_meta_build_resolve_srgb_conversion(nir_builder *b, nir_ssa_def *input)
|
|||
for (i = 0; i < 3; i++) {
|
||||
gtvals[i] = nir_fpow(b, nir_channel(b, input, i), nir_imm_float(b, 1.0 / 2.4));
|
||||
gtvals[i] = nir_fmul_imm(b, gtvals[i], 1.055);
|
||||
gtvals[i] = nir_fsub(b, gtvals[i], nir_imm_float(b, 0.055));
|
||||
gtvals[i] = nir_fadd_imm(b, gtvals[i], -0.055);
|
||||
}
|
||||
|
||||
nir_ssa_def *comp[4];
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ radv_nir_lower_fs_intrinsics(nir_shader *nir, const struct radv_pipeline_stage *
|
|||
nir_load_sample_positions_amd(&b, 32, intrin->src[0].ssa, num_samples);
|
||||
|
||||
/* sample_pos -= 0.5 */
|
||||
sample_pos = nir_fsub(&b, sample_pos, nir_imm_float(&b, 0.5f));
|
||||
sample_pos = nir_fadd_imm(&b, sample_pos, -0.5f);
|
||||
|
||||
res2 = nir_load_barycentric_at_offset(
|
||||
&b, 32, sample_pos, .interp_mode = nir_intrinsic_interp_mode(intrin));
|
||||
|
|
@ -131,7 +131,7 @@ radv_nir_lower_fs_intrinsics(nir_shader *nir, const struct radv_pipeline_stage *
|
|||
nir_load_sample_positions_amd(&b, 32, intrin->src[0].ssa, num_samples);
|
||||
|
||||
/* sample_pos -= 0.5 */
|
||||
sample_pos = nir_fsub(&b, sample_pos, nir_imm_float(&b, 0.5f));
|
||||
sample_pos = nir_fadd_imm(&b, sample_pos, -0.5f);
|
||||
|
||||
new_dest = nir_load_barycentric_at_offset(
|
||||
&b, 32, sample_pos, .interp_mode = nir_intrinsic_interp_mode(intrin));
|
||||
|
|
|
|||
|
|
@ -380,7 +380,7 @@ lower_floor(nir_builder *b, nir_ssa_def *src)
|
|||
return nir_bcsel(b,
|
||||
nir_ior(b, positive, nir_feq(b, src, tr)),
|
||||
tr,
|
||||
nir_fsub(b, tr, nir_imm_double(b, 1.0)));
|
||||
nir_fadd_imm(b, tr, -1.0));
|
||||
}
|
||||
|
||||
static nir_ssa_def *
|
||||
|
|
|
|||
|
|
@ -436,7 +436,7 @@ static bool lower_intrinsic(nir_builder *b, nir_instr *instr, struct lower_abi_s
|
|||
nir_ssa_def *buf = si_nir_load_internal_binding(b, args, SI_PS_CONST_SAMPLE_POSITIONS, 4);
|
||||
nir_ssa_def *sample_pos = nir_load_ubo(b, 2, 32, buf, offset, .range = ~0);
|
||||
|
||||
sample_pos = nir_fsub(b, sample_pos, nir_imm_float(b, 0.5));
|
||||
sample_pos = nir_fadd_imm(b, sample_pos, -0.5);
|
||||
|
||||
replacement = nir_load_barycentric_at_offset(b, 32, sample_pos, .interp_mode = mode);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -298,7 +298,7 @@ static nir_ssa_def *convert_linear_to_srgb(nir_builder *b, nir_ssa_def *input)
|
|||
for (unsigned i = 0; i < 3; i++) {
|
||||
gtvals[i] = nir_fpow(b, nir_channel(b, input, i), nir_imm_float(b, 1.0/2.4));
|
||||
gtvals[i] = nir_fmul_imm(b, gtvals[i], 1.055);
|
||||
gtvals[i] = nir_fsub(b, gtvals[i], nir_imm_float(b, 0.055));
|
||||
gtvals[i] = nir_fadd_imm(b, gtvals[i], -0.055);
|
||||
}
|
||||
|
||||
nir_ssa_def *comp[4];
|
||||
|
|
|
|||
|
|
@ -119,10 +119,10 @@ vc4_nir_get_vattr_channel_vpm(struct vc4_compile *c,
|
|||
if (chan->type == UTIL_FORMAT_TYPE_SIGNED) {
|
||||
temp = nir_ixor(b, vpm, nir_imm_int(b, 0x80808080));
|
||||
if (chan->normalized) {
|
||||
return nir_fsub(b, nir_fmul_imm(b,
|
||||
vc4_nir_unpack_8f(b, temp, swiz),
|
||||
2.0),
|
||||
nir_imm_float(b, 1.0));
|
||||
return nir_fadd_imm(b, nir_fmul_imm(b,
|
||||
vc4_nir_unpack_8f(b, temp, swiz),
|
||||
2.0),
|
||||
-1.0);
|
||||
} else {
|
||||
return nir_fadd_imm(b,
|
||||
nir_i2f32(b,
|
||||
|
|
|
|||
|
|
@ -375,7 +375,7 @@ clc_lower_nonnormalized_samplers(nir_shader *nir,
|
|||
// Don't scale the array index, but do clamp it
|
||||
comps[i] = nir_fround_even(&b, comps[i]);
|
||||
comps[i] = nir_fmax(&b, comps[i], nir_imm_float(&b, 0.0f));
|
||||
comps[i] = nir_fmin(&b, comps[i], nir_fsub(&b, nir_channel(&b, txs, i), nir_imm_float(&b, 1.0f)));
|
||||
comps[i] = nir_fmin(&b, comps[i], nir_fadd_imm(&b, nir_channel(&b, txs, i), -1.0f));
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ static void
|
|||
wrap_clamp_to_edge(nir_builder *b, wrap_result_t *wrap_params, nir_ssa_def *size)
|
||||
{
|
||||
/* clamp(coord, 0, size - 1) */
|
||||
wrap_params->coords = nir_fmin(b, nir_fsub(b, size, nir_imm_float(b, 1.0f)),
|
||||
wrap_params->coords = nir_fmin(b, nir_fadd_imm(b, size, -1.0f),
|
||||
nir_fmax(b, wrap_params->coords, nir_imm_float(b, 0.0f)));
|
||||
}
|
||||
|
||||
|
|
@ -157,14 +157,14 @@ wrap_mirror_repeat(nir_builder *b, wrap_result_t *wrap_params, nir_ssa_def *size
|
|||
nir_ssa_def *coord_mod2size = nir_fmod(b, wrap_params->coords, nir_fmul_imm(b, size, 2.0f));
|
||||
nir_instr_as_alu(coord_mod2size->parent_instr)->exact = true;
|
||||
nir_ssa_def *a = nir_fsub(b, coord_mod2size, size);
|
||||
wrap_params->coords = nir_fsub(b, nir_fsub(b, size, nir_imm_float(b, 1.0f)), mirror(b, a));
|
||||
wrap_params->coords = nir_fsub(b, nir_fadd_imm(b, size, -1.0f), mirror(b, a));
|
||||
}
|
||||
|
||||
static void
|
||||
wrap_mirror_clamp_to_edge(nir_builder *b, wrap_result_t *wrap_params, nir_ssa_def *size)
|
||||
{
|
||||
/* clamp(mirror(coord), 0, size - 1) */
|
||||
wrap_params->coords = nir_fmin(b, nir_fsub(b, size, nir_imm_float(b, 1.0f)),
|
||||
wrap_params->coords = nir_fmin(b, nir_fadd_imm(b, size, -1.0f),
|
||||
nir_fmax(b, mirror(b, wrap_params->coords), nir_imm_float(b, 0.0f)));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue