From 9b293c3a98896ea4b7cccfbfbec5ca4038790d6d Mon Sep 17 00:00:00 2001 From: Zephyron Date: Fri, 28 Feb 2025 17:08:27 +1000 Subject: shader_recompiler: Implement vertex count lookup for Geometry stage Add proper handling of input topologies in the Geometry stage for all three shader backends (GLASM, GLSL, SPIRV). This implementation uses a lookup table approach to determine vertex counts based on input topology type (Points, Lines, LinesAdjacency, Triangles, TrianglesAdjacency) and shifts the vertex count by 16 bits as required by the invocation info format. Additional changes: - Fixed TessellationControl and TessellationEval stages to properly break after emitting code - Added proper header include for runtime_info.h in GLASM backend - Improved code documentation with clear commenting patterns This change ensures accurate geometry shader behavior across all backends, improving compatibility with games that rely on proper vertex count reporting. Signed-off-by: Zephyron --- .../backend/spirv/emit_spirv_context_get_set.cpp | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/shader_recompiler/backend/spirv') diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp index 64f828107..f3c15cfc2 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp @@ -1,4 +1,5 @@ // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project +// SPDX-FileCopyrightText: Copyright 2025 citron Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #include @@ -553,6 +554,42 @@ Id EmitInvocationInfo(EmitContext& ctx) { // Return sample mask in upper 16 bits return ctx.OpShiftLeftLogical(ctx.U32[1], ctx.OpLoad(ctx.U32[1], ctx.sample_mask), ctx.Const(16u)); + case Stage::Geometry: { + // Return vertex count in upper 16 bits based on input topology + // Using a lookup table approach for vertex counts + const std::array vertex_counts = { + 1, // Points + 2, // Lines + 4, // LinesAdjacency + 3, // Triangles + 6 // TrianglesAdjacency + }; + + // Map the input topology to an index in our lookup table + u32 topology_index = 0; + switch (ctx.runtime_info.input_topology) { + case InputTopology::Lines: + topology_index = 1; + break; + case InputTopology::LinesAdjacency: + topology_index = 2; + break; + case InputTopology::Triangles: + topology_index = 3; + break; + case InputTopology::TrianglesAdjacency: + topology_index = 4; + break; + case InputTopology::Points: + default: + topology_index = 0; + break; + } + + // Get the vertex count from the lookup table and shift it + const u32 vertex_count = vertex_counts[topology_index]; + return ctx.OpShiftLeftLogical(ctx.U32[1], ctx.Const(vertex_count), ctx.Const(16u)); + } case Stage::Compute: // For compute shaders, return standard format since we can't access workgroup size directly return ctx.Const(0x00ff0000u); -- cgit v1.2.3