nir/opt_frag_coord_to_pixel_coord: optimize trunc/floor

Foz-DB Navi21:
Totals from 207 (0.26% of 79206) affected shaders:
MaxWaves: 5924 -> 5980 (+0.95%)
Instrs: 83164 -> 83144 (-0.02%); split: -0.06%, +0.04%
CodeSize: 457296 -> 459092 (+0.39%); split: -0.00%, +0.39%
VGPRs: 5336 -> 5160 (-3.30%)
Latency: 1308811 -> 1307754 (-0.08%); split: -0.16%, +0.08%
InvThroughput: 232768 -> 222979 (-4.21%); split: -4.21%, +0.00%
VClause: 1359 -> 1370 (+0.81%); split: -0.07%, +0.88%
SClause: 3300 -> 3293 (-0.21%); split: -0.24%, +0.03%
Copies: 4992 -> 4985 (-0.14%); split: -0.56%, +0.42%
PreVGPRs: 3757 -> 3619 (-3.67%)
VALU: 58366 -> 58338 (-0.05%); split: -0.08%, +0.03%

Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31966>
This commit is contained in:
Georg Lehmann
2024-11-04 18:08:25 +01:00
committed by Marge Bot
parent 62011e564c
commit 3738c69796
@@ -50,6 +50,8 @@ opt_frag_pos(nir_builder *b, nir_intrinsic_instr *intr, UNUSED void *data)
case nir_op_f2u16:
case nir_op_f2u32:
case nir_op_f2u64:
case nir_op_ftrunc:
case nir_op_ffloor:
continue;
default:
return false;
@@ -70,7 +72,8 @@ opt_frag_pos(nir_builder *b, nir_intrinsic_instr *intr, UNUSED void *data)
nir_alu_instr *use_instr = nir_instr_as_alu(nir_src_parent_instr(use));
/* load_frag_coord is always positive, so we should never sign extend here. */
nir_alu_type dst_type = nir_type_uint | use_instr->def.bit_size;
bool needs_float = use_instr->op == nir_op_ffloor || use_instr->op == nir_op_ftrunc;
nir_alu_type dst_type = (needs_float ? nir_type_float : nir_type_uint) | use_instr->def.bit_size;
use_instr->op = nir_type_conversion_op(nir_type_uint16, dst_type, nir_rounding_mode_undef);
}