From 2b312a4fd7761a7a1dc7701956268745ffade34b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timur=20Krist=C3=B3f?= Date: Thu, 8 Apr 2021 15:39:39 +0200 Subject: [PATCH] aco: Extract ngg_nogs_export_prim_id to a separate function. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Timur Kristóf Reviewed-by: Rhys Perry Part-of: --- .../compiler/aco_instruction_selection.cpp | 57 +++++++++++-------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/src/amd/compiler/aco_instruction_selection.cpp b/src/amd/compiler/aco_instruction_selection.cpp index 845d56e4cf2..86fbed300ff 100644 --- a/src/amd/compiler/aco_instruction_selection.cpp +++ b/src/amd/compiler/aco_instruction_selection.cpp @@ -11294,6 +11294,37 @@ void ngg_nogs_export_primitives(isel_context *ctx) end_divergent_if(ctx, &ic); } +void ngg_nogs_export_prim_id(isel_context *ctx) +{ + if (!ctx->args->options->key.vs_common_out.export_prim_id) + return; + + Temp prim_id; + + if (ctx->stage == vertex_ngg) { + /* Wait for GS threads to store primitive ID in LDS. */ + Builder bld(ctx->program, ctx->block); + create_workgroup_barrier(bld); + + /* Calculate LDS address where the GS threads stored the primitive ID. */ + Temp thread_id_in_tg = thread_id_in_threadgroup(ctx); + Temp addr = bld.v_mul24_imm(bld.def(v1), thread_id_in_tg, 4u); + + /* Load primitive ID from LDS. */ + prim_id = load_lds(ctx, 4, bld.tmp(v1), addr, 0u, 4u); + } else if (ctx->stage == tess_eval_ngg) { + /* TES: Just use the patch ID as the primitive ID. */ + prim_id = get_arg(ctx, ctx->args->ac.tes_patch_id); + } else { + unreachable("unsupported NGG non-GS shader stage."); + } + + ctx->outputs.mask[VARYING_SLOT_PRIMITIVE_ID] |= 0x1; + ctx->outputs.temps[VARYING_SLOT_PRIMITIVE_ID * 4u] = prim_id; + + export_vs_varying(ctx, VARYING_SLOT_PRIMITIVE_ID, false, nullptr); +} + void ngg_nogs_export_vertices(isel_context *ctx) { Builder bld(ctx->program, ctx->block); @@ -11303,31 +11334,7 @@ void ngg_nogs_export_vertices(isel_context *ctx) create_vs_exports(ctx); /* Export primitive ID */ - if (ctx->args->options->key.vs_common_out.export_prim_id) { - Temp prim_id; - - if (ctx->stage == vertex_ngg) { - /* Wait for GS threads to store primitive ID in LDS. */ - create_workgroup_barrier(bld); - - /* Calculate LDS address where the GS threads stored the primitive ID. */ - Temp thread_id_in_tg = thread_id_in_threadgroup(ctx); - Temp addr = bld.v_mul24_imm(bld.def(v1), thread_id_in_tg, 4u); - - /* Load primitive ID from LDS. */ - prim_id = load_lds(ctx, 4, bld.tmp(v1), addr, 0u, 4u); - } else if (ctx->stage == tess_eval_ngg) { - /* TES: Just use the patch ID as the primitive ID. */ - prim_id = get_arg(ctx, ctx->args->ac.tes_patch_id); - } else { - unreachable("unsupported NGG non-GS shader stage."); - } - - ctx->outputs.mask[VARYING_SLOT_PRIMITIVE_ID] |= 0x1; - ctx->outputs.temps[VARYING_SLOT_PRIMITIVE_ID * 4u] = prim_id; - - export_vs_varying(ctx, VARYING_SLOT_PRIMITIVE_ID, false, nullptr); - } + ngg_nogs_export_prim_id(ctx); } void ngg_nogs_prelude(isel_context *ctx)