From 7e959864b20bd961188cf78f6026a70baac3a824 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Tue, 19 Nov 2024 11:04:39 -0500 Subject: [PATCH] radeonsi: enable NGG culling for non-monolithic TES and GS It doesn't enable back face culling and small line culling. Those can only be enabled for monolithic shaders. It only enables view culling and small triangle culling. Doing this has these minor advantages: 1. We can enable at least some culling immediately instead of when the first monolithic shader finishes compilation. 2. If back face culling and clip planes are disabled, we no longer compile monolithic TES and GS shader variants to get only view culling and small triangle culling. 3. shader-db will show culling code changes for TES and GS. Acked-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/gallium/drivers/radeonsi/si_shader.h | 10 +++++++++- src/gallium/drivers/radeonsi/si_state_draw.cpp | 10 +++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/gallium/drivers/radeonsi/si_shader.h b/src/gallium/drivers/radeonsi/si_shader.h index 2ab8e81750c..c0d2f437830 100644 --- a/src/gallium/drivers/radeonsi/si_shader.h +++ b/src/gallium/drivers/radeonsi/si_shader.h @@ -1152,7 +1152,15 @@ static inline bool si_shader_uses_discard(struct si_shader *shader) static inline bool si_shader_culling_enabled(struct si_shader *shader) { - return !!shader->key.ge.opt.ngg_culling; + if (shader->key.ge.opt.ngg_culling) + return true; + + unsigned output_prim = si_get_output_prim_simplified(shader->selector, &shader->key); + + /* This enables NGG culling for non-monolithic TES and GS. */ + return shader->key.ge.as_ngg && !shader->key.ge.as_es && + shader->selector->ngg_cull_vert_threshold == 0 && + (output_prim == MESA_PRIM_TRIANGLES || output_prim == MESA_PRIM_LINES); } #ifdef __cplusplus diff --git a/src/gallium/drivers/radeonsi/si_state_draw.cpp b/src/gallium/drivers/radeonsi/si_state_draw.cpp index 1e6071bdc86..6c67798a8a8 100644 --- a/src/gallium/drivers/radeonsi/si_state_draw.cpp +++ b/src/gallium/drivers/radeonsi/si_state_draw.cpp @@ -2255,12 +2255,12 @@ static void si_draw(struct pipe_context *ctx, if (util_prim_is_lines(sctx->current_rast_prim)) { /* Overwrite it to mask out face cull flags. */ - ngg_culling = rs->ngg_cull_flags_lines; - ngg_culling |= SI_NGG_CULL_VS_LINES; + ngg_culling = rs->ngg_cull_flags_lines | + (!HAS_TESS && !HAS_GS ? SI_NGG_CULL_VS_LINES : 0); } else { - ngg_culling = sctx->viewport0_y_inverted ? rs->ngg_cull_flags_tris_y_inverted : - rs->ngg_cull_flags_tris; - ngg_culling |= SI_NGG_CULL_VS_TRIANGLES; + ngg_culling = (sctx->viewport0_y_inverted ? rs->ngg_cull_flags_tris_y_inverted : + rs->ngg_cull_flags_tris) | + (!HAS_TESS && !HAS_GS ? SI_NGG_CULL_VS_TRIANGLES : 0); } if (ngg_culling != old_ngg_culling) {