nir: make fclamp_pos_mali and fsat_signed_mali opcodes generic

V3D can use these too.

Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Reviewed-by: Jose Maria Casanova Crespo <jmcasanova@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31480>
This commit is contained in:
Iago Toral Quiroga 2024-10-02 09:03:01 +02:00 committed by Marge Bot
parent 023277173c
commit aac1c074cc
10 changed files with 22 additions and 22 deletions

View file

@ -96,7 +96,7 @@ store_tilebuffer(nir_builder *b, struct agx_tilebuffer_layout *tib,
}
static nir_def *
nir_fsat_signed(nir_builder *b, nir_def *x)
nir_build_fsat_signed(nir_builder *b, nir_def *x)
{
return nir_fclamp(b, x, nir_imm_floatN_t(b, -1.0, x->bit_size),
nir_imm_floatN_t(b, +1.0, x->bit_size));
@ -108,7 +108,7 @@ nir_fsat_to_format(nir_builder *b, nir_def *x, enum pipe_format format)
if (util_format_is_unorm(format))
return nir_fsat(b, x);
else if (util_format_is_snorm(format))
return nir_fsat_signed(b, x);
return nir_build_fsat_signed(b, x);
else
return x;
}

View file

@ -133,7 +133,7 @@ nir_blend_factor_value(
}
static nir_def *
nir_fsat_signed(nir_builder *b, nir_def *x)
nir_build_fsat_signed(nir_builder *b, nir_def *x)
{
return nir_fclamp(b, x, nir_imm_floatN_t(b, -1.0, x->bit_size),
nir_imm_floatN_t(b, +1.0, x->bit_size));
@ -145,7 +145,7 @@ nir_fsat_to_format(nir_builder *b, nir_def *x, enum pipe_format format)
if (util_format_is_unorm(format))
return nir_fsat(b, x);
else if (util_format_is_snorm(format))
return nir_fsat_signed(b, x);
return nir_build_fsat_signed(b, x);
else
return x;
}

View file

@ -1504,9 +1504,9 @@ unop("pack_2x16_to_unorm_2x10_v3d", tuint32, "pack_2x16_to_unorm_2x10(src0)")
# and one 10 bit unorm
unop("pack_2x16_to_unorm_10_2_v3d", tuint32, "pack_2x16_to_unorm_10_2(src0)")
# Mali-specific opcodes
unop("fsat_signed_mali", tfloat, ("fmin(fmax(src0, -1.0), 1.0)"))
unop("fclamp_pos_mali", tfloat, ("fmax(src0, 0.0)"))
# These opcodes are used used by Mali and V3D
unop("fsat_signed", tfloat, ("fmin(fmax(src0, -1.0), 1.0)"))
unop("fclamp_pos", tfloat, ("fmax(src0, 0.0)"))
opcode("b32fcsel_mdg", 0, tuint, [0, 0, 0],
[tbool32, tfloat, tfloat], False, selection, "src0 ? src1 : src2",

View file

@ -39,7 +39,7 @@ lower_ftrunc = [
# PP fuse clamp_positive. Shared with Midgard/Bifrost
ppir_algebraic_late = [
(('fmax', 'a', 0.0), ('fclamp_pos_mali', 'a')),
(('fmax', 'a', 0.0), ('fclamp_pos', 'a')),
]
def main():

View file

@ -151,7 +151,7 @@ static int nir_to_ppir_opcodes[nir_num_opcodes] = {
[nir_op_inot] = ppir_op_not,
[nir_op_ftrunc] = ppir_op_trunc,
[nir_op_fsat] = ppir_op_sat,
[nir_op_fclamp_pos_mali] = ppir_op_clamp_pos,
[nir_op_fclamp_pos] = ppir_op_clamp_pos,
};
static bool ppir_emit_alu(ppir_block *block, nir_instr *ni)

View file

@ -2643,13 +2643,13 @@ bi_emit_alu(bi_builder *b, nir_alu_instr *instr)
break;
}
case nir_op_fsat_signed_mali: {
case nir_op_fsat_signed: {
bi_instr *I = bi_fclamp_to(b, sz, dst, s0);
I->clamp = BI_CLAMP_CLAMP_M1_1;
break;
}
case nir_op_fclamp_pos_mali: {
case nir_op_fclamp_pos: {
bi_instr *I = bi_fclamp_to(b, sz, dst, s0);
I->clamp = BI_CLAMP_CLAMP_0_INF;
break;

View file

@ -52,9 +52,9 @@ algebraic_late = [
(('fmul', a, 2.0), ('fadd', a, a)),
# Fuse Mali-specific clamps
(('fmin', ('fmax', a, -1.0), 1.0), ('fsat_signed_mali', a)),
(('fmax', ('fmin', a, 1.0), -1.0), ('fsat_signed_mali', a)),
(('fmax', a, 0.0), ('fclamp_pos_mali', a)),
(('fmin', ('fmax', a, -1.0), 1.0), ('fsat_signed', a)),
(('fmax', ('fmin', a, 1.0), -1.0), ('fsat_signed', a)),
(('fmax', a, 0.0), ('fclamp_pos', a)),
(('b32csel', 'b@32', ('iadd', 'a@32', 1), a), ('iadd', a, ('b2i32', b))),

View file

@ -832,8 +832,8 @@ emit_alu(compiler_context *ctx, nir_alu_instr *instr)
ALU_CASE(fabs, fmov);
ALU_CASE(fneg, fmov);
ALU_CASE(fsat, fmov);
ALU_CASE(fsat_signed_mali, fmov);
ALU_CASE(fclamp_pos_mali, fmov);
ALU_CASE(fsat_signed, fmov);
ALU_CASE(fclamp_pos, fmov);
/* For size conversion, we use a move. Ideally though we would squash
* these ops together; maybe that has to happen after in NIR as part of
@ -934,9 +934,9 @@ emit_alu(compiler_context *ctx, nir_alu_instr *instr)
outmod = midgard_outmod_keeplo;
} else if (instr->op == nir_op_fsat) {
outmod = midgard_outmod_clamp_0_1;
} else if (instr->op == nir_op_fsat_signed_mali) {
} else if (instr->op == nir_op_fsat_signed) {
outmod = midgard_outmod_clamp_m1_1;
} else if (instr->op == nir_op_fclamp_pos_mali) {
} else if (instr->op == nir_op_fclamp_pos) {
outmod = midgard_outmod_clamp_0_inf;
}

View file

@ -51,11 +51,11 @@ algebraic_late = [
(('b32csel', a, 0, 'b@32'), ('iand', ('inot', a), b)),
# Fuse sat_signed. This should probably be shared with Bifrost
(('~fmin', ('fmax', a, -1.0), 1.0), ('fsat_signed_mali', a)),
(('~fmax', ('fmin', a, 1.0), -1.0), ('fsat_signed_mali', a)),
(('~fmin', ('fmax', a, -1.0), 1.0), ('fsat_signed', a)),
(('~fmax', ('fmin', a, 1.0), -1.0), ('fsat_signed', a)),
# Fuse clamp_positive. This should probably be shared with Utgard/bifrost
(('fmax', a, 0.0), ('fclamp_pos_mali', a)),
(('fmax', a, 0.0), ('fclamp_pos', a)),
(('ishl', 'a@16', b), ('u2u16', ('ishl', ('u2u32', a), b))),
(('ishr', 'a@16', b), ('i2i16', ('ishr', ('i2i32', a), b))),

View file

@ -202,7 +202,7 @@ static nir_def *
pan_fsat(nir_builder *b, nir_def *v, bool is_signed)
{
if (is_signed)
return nir_fsat_signed_mali(b, v);
return nir_fsat_signed(b, v);
else
return nir_fsat(b, v);
}