From e035c289b52a0867956d78135c1669abb9a60b2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timur=20Krist=C3=B3f?= Date: Sat, 6 Aug 2022 01:21:47 +0200 Subject: [PATCH] ac/nir/cull: Tweak phi for cull_small_primitive branch. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cull_small_primitive will now allow the caller to pass an SSA def that it will use to determine if the primitive was initially rejected. This allows ACO to remove an s_branch instruction from every NGG culling shader. Fossil DB stats on Navi 21: Totals from 60918 (45.16% of 134906) affected shaders: CodeSize: 160086644 -> 159355824 (-0.46%); split: -0.46%, +0.00% Instrs: 30477916 -> 30356092 (-0.40%); split: -0.40%, +0.00% Latency: 139587915 -> 139611487 (+0.02%); split: -0.00%, +0.02% InvThroughput: 21184261 -> 21184346 (+0.00%) Copies: 2762930 -> 2702024 (-2.20%); split: -2.20%, +0.00% Branches: 1236970 -> 1176052 (-4.92%) Signed-off-by: Timur Kristóf Reviewed-by: Marek Olšák Part-of: --- src/amd/common/ac_nir_cull.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/amd/common/ac_nir_cull.c b/src/amd/common/ac_nir_cull.c index d88dbd85944..232edee282c 100644 --- a/src/amd/common/ac_nir_cull.c +++ b/src/amd/common/ac_nir_cull.c @@ -101,17 +101,17 @@ cull_frustrum(nir_builder *b, nir_ssa_def *bbox_min[3], nir_ssa_def *bbox_max[3] } static nir_ssa_def * -cull_small_primitive(nir_builder *b, nir_ssa_def *bbox_min[3], nir_ssa_def *bbox_max[3]) +cull_small_primitive(nir_builder *b, nir_ssa_def *bbox_min[3], nir_ssa_def *bbox_max[3], + nir_ssa_def *prim_is_small_else) { nir_ssa_def *prim_is_small = NULL; - nir_ssa_def *prim_is_small_else = nir_imm_false(b); nir_if *if_cull_small_prims = nir_push_if(b, nir_load_cull_small_primitives_enabled_amd(b)); { nir_ssa_def *vp_scale[2] = { nir_load_viewport_x_scale(b), nir_load_viewport_y_scale(b), }; nir_ssa_def *vp_translate[2] = { nir_load_viewport_x_offset(b), nir_load_viewport_y_offset(b), }; nir_ssa_def *small_prim_precision = nir_load_cull_small_prim_precision_amd(b); - prim_is_small = nir_imm_false(b); + prim_is_small = prim_is_small_else; for (unsigned chan = 0; chan < 2; ++chan) { /* Convert the position to screen-space coordinates. */ @@ -155,8 +155,7 @@ ac_nir_cull_triangle(nir_builder *b, calc_bbox(b, pos, bbox_min, bbox_max); nir_ssa_def *prim_outside_view = cull_frustrum(b, bbox_min, bbox_max); - nir_ssa_def *prim_is_small = cull_small_primitive(b, bbox_min, bbox_max); - nir_ssa_def *prim_invisible = nir_ior(b, prim_outside_view, prim_is_small); + nir_ssa_def *prim_invisible = cull_small_primitive(b, bbox_min, bbox_max, prim_outside_view); accepted = nir_iand(b, nir_inot(b, prim_invisible), nir_inot(b, w_info.any_w_negative)); nir_if *if_still_accepted = nir_push_if(b, accepted);