From e6e692e19a918b30fe3a191def9c68998348c714 Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Thu, 15 Dec 2022 20:31:52 +0000 Subject: [PATCH] aco/gfx11: export mrtz in discard early exit for non-color shaders If a shader doesn't export any color targets and instead only exports mrtz, the discard early exit block should match. Fixes artifacts on Lara in Rise of the Tomb Raider benchmark and hair in The Witcher 3 (classic). https://reviews.llvm.org/D128185 Signed-off-by: Rhys Perry Reviewed-by: Bas Nieuwenhuizen Reviewed-by: Samuel Pitoiset Fixes: bc8da20dda6 ("aco: export MRT0 instead of NULL on GFX11") Part-of: (cherry picked from commit 192486b7aa5ef3b24516e16b0e219fad7032fb7c) --- .pick_status.json | 2 +- src/amd/compiler/aco_instruction_selection.cpp | 6 ++++++ src/amd/compiler/aco_ir.h | 1 + src/amd/compiler/aco_lower_to_hw_instr.cpp | 7 +++++-- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 9d0b994..a7bca82 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -2380,7 +2380,7 @@ "description": "aco/gfx11: export mrtz in discard early exit for non-color shaders", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "bc8da20dda6b078aea800767f3b7983929e8bf23" }, diff --git a/src/amd/compiler/aco_instruction_selection.cpp b/src/amd/compiler/aco_instruction_selection.cpp index 2d11efe..7472b45 100644 --- a/src/amd/compiler/aco_instruction_selection.cpp +++ b/src/amd/compiler/aco_instruction_selection.cpp @@ -11208,6 +11208,8 @@ export_mrt(isel_context* ctx, const struct aco_export_mrt* mrt) bld.exp(aco_opcode::exp, mrt->out[0], mrt->out[1], mrt->out[2], mrt->out[3], mrt->enabled_channels, mrt->target, mrt->compr); + + ctx->program->has_color_exports = true; } static bool @@ -11401,6 +11403,8 @@ create_fs_null_export(isel_context* ctx) unsigned dest = ctx->options->gfx_level >= GFX11 ? V_008DFC_SQ_EXP_MRT : V_008DFC_SQ_EXP_NULL; bld.exp(aco_opcode::exp, Operand(v1), Operand(v1), Operand(v1), Operand(v1), /* enabled_mask */ 0, dest, /* compr */ false, /* done */ true, /* vm */ true); + + ctx->program->has_color_exports = true; } static void @@ -11476,6 +11480,8 @@ create_fs_dual_src_export_gfx11(isel_context* ctx, const struct aco_export_mrt* exp->definitions[4] = bld.def(bld.lm, vcc); exp->definitions[5] = bld.def(s1, scc); ctx->block->instructions.emplace_back(std::move(exp)); + + ctx->program->has_color_exports = true; } static void diff --git a/src/amd/compiler/aco_ir.h b/src/amd/compiler/aco_ir.h index fad6272..c2b6457 100644 --- a/src/amd/compiler/aco_ir.h +++ b/src/amd/compiler/aco_ir.h @@ -2170,6 +2170,7 @@ public: Stage stage; bool needs_exact = false; /* there exists an instruction with disable_wqm = true */ bool needs_wqm = false; /* there exists a p_wqm instruction */ + bool has_color_exports = false; std::vector constant_data; Temp private_segment_buffer; diff --git a/src/amd/compiler/aco_lower_to_hw_instr.cpp b/src/amd/compiler/aco_lower_to_hw_instr.cpp index 5fb097a..f5c4c4a 100644 --- a/src/amd/compiler/aco_lower_to_hw_instr.cpp +++ b/src/amd/compiler/aco_lower_to_hw_instr.cpp @@ -2129,9 +2129,12 @@ lower_to_hw_instr(Program* program) block = &program->blocks[block_idx]; bld.reset(discard_block); + unsigned target = V_008DFC_SQ_EXP_NULL; + if (program->gfx_level >= GFX11) + target = + program->has_color_exports ? V_008DFC_SQ_EXP_MRT : V_008DFC_SQ_EXP_MRTZ; bld.exp(aco_opcode::exp, Operand(v1), Operand(v1), Operand(v1), Operand(v1), 0, - program->gfx_level >= GFX11 ? V_008DFC_SQ_EXP_MRT : V_008DFC_SQ_EXP_NULL, - false, true, true); + target, false, true, true); if (should_dealloc_vgprs) bld.sopp(aco_opcode::s_sendmsg, -1, sendmsg_dealloc_vgprs); bld.sopp(aco_opcode::s_endpgm); -- 2.7.4