mirror of
https://git.citron-emu.org/citron/emulator
synced 2025-12-21 03:23:34 +00:00
video_core, shader_recompiler: Improve Princess Peach: Showtime! support and performance
1. Add geometry shader support for Princess Peach: Showtime!: - Implement proper EmitInvocationInfo handling for geometry shaders - Support input topology vertex counting in all shader backends (GLASM, GLSL, SPIRV) 2. Performance optimizations: - Replace InputTopologyVertices switch statement with a constexpr lookup table - Pre-calculate vertex counts and shifts to reduce register pressure - Eliminate redundant calculations in shader backends Signed-off-by: Zephyron <zephyron@citron-emu.org>
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
#include "shader_recompiler/backend/glasm/glasm_emit_context.h"
|
#include "shader_recompiler/backend/glasm/glasm_emit_context.h"
|
||||||
#include "shader_recompiler/frontend/ir/value.h"
|
#include "shader_recompiler/frontend/ir/value.h"
|
||||||
#include "shader_recompiler/profile.h"
|
#include "shader_recompiler/profile.h"
|
||||||
|
#include "shader_recompiler/runtime_info.h"
|
||||||
#include "shader_recompiler/shader_info.h"
|
#include "shader_recompiler/shader_info.h"
|
||||||
|
|
||||||
namespace Shader::Backend::GLASM {
|
namespace Shader::Backend::GLASM {
|
||||||
@@ -406,6 +407,12 @@ void EmitInvocationInfo(EmitContext& ctx, IR::Inst& inst) {
|
|||||||
case Stage::TessellationEval:
|
case Stage::TessellationEval:
|
||||||
ctx.Add("SHL.U {}.x,primitive.vertexcount,16;", inst);
|
ctx.Add("SHL.U {}.x,primitive.vertexcount,16;", inst);
|
||||||
break;
|
break;
|
||||||
|
case Stage::Geometry: {
|
||||||
|
// Pre-calculate the vertex count for better performance
|
||||||
|
const u32 vertex_count = InputTopologyVertices::vertices(ctx.runtime_info.input_topology) << 16;
|
||||||
|
ctx.Add("MOV.S {}.x,{};", inst, vertex_count);
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
LOG_WARNING(Shader, "(STUBBED) called");
|
LOG_WARNING(Shader, "(STUBBED) called");
|
||||||
ctx.Add("MOV.S {}.x,0x00ff0000;", inst);
|
ctx.Add("MOV.S {}.x,0x00ff0000;", inst);
|
||||||
|
|||||||
@@ -426,6 +426,12 @@ void EmitInvocationInfo(EmitContext& ctx, IR::Inst& inst) {
|
|||||||
case Stage::TessellationEval:
|
case Stage::TessellationEval:
|
||||||
ctx.AddU32("{}=uint(gl_PatchVerticesIn)<<16;", inst);
|
ctx.AddU32("{}=uint(gl_PatchVerticesIn)<<16;", inst);
|
||||||
break;
|
break;
|
||||||
|
case Stage::Geometry: {
|
||||||
|
// Pre-calculate the vertex count for better performance
|
||||||
|
const u32 vertex_count = InputTopologyVertices::vertices(ctx.runtime_info.input_topology);
|
||||||
|
ctx.AddU32("{}={}u;", inst, vertex_count << 16);
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
LOG_WARNING(Shader, "(STUBBED) called");
|
LOG_WARNING(Shader, "(STUBBED) called");
|
||||||
ctx.AddU32("{}=uint(0x00ff0000);", inst);
|
ctx.AddU32("{}=uint(0x00ff0000);", inst);
|
||||||
|
|||||||
@@ -549,6 +549,11 @@ Id EmitInvocationInfo(EmitContext& ctx) {
|
|||||||
case Stage::TessellationEval:
|
case Stage::TessellationEval:
|
||||||
return ctx.OpShiftLeftLogical(ctx.U32[1], ctx.OpLoad(ctx.U32[1], ctx.patch_vertices_in),
|
return ctx.OpShiftLeftLogical(ctx.U32[1], ctx.OpLoad(ctx.U32[1], ctx.patch_vertices_in),
|
||||||
ctx.Const(16u));
|
ctx.Const(16u));
|
||||||
|
case Stage::Geometry: {
|
||||||
|
// Pre-calculate the shifted value for better performance
|
||||||
|
const u32 shifted_value = InputTopologyVertices::vertices(ctx.runtime_info.input_topology) << 16;
|
||||||
|
return ctx.Const(shifted_value);
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
LOG_WARNING(Shader, "(STUBBED) called");
|
LOG_WARNING(Shader, "(STUBBED) called");
|
||||||
return ctx.Const(0x00ff0000u);
|
return ctx.Const(0x00ff0000u);
|
||||||
|
|||||||
@@ -30,6 +30,22 @@ enum class InputTopology {
|
|||||||
TrianglesAdjacency,
|
TrianglesAdjacency,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespace InputTopologyVertices {
|
||||||
|
// Lookup table for vertex counts - faster than switch statement
|
||||||
|
inline constexpr std::array<u32, 5> vertex_counts = {
|
||||||
|
1, // Points
|
||||||
|
2, // Lines
|
||||||
|
4, // LinesAdjacency
|
||||||
|
3, // Triangles
|
||||||
|
6, // TrianglesAdjacency
|
||||||
|
};
|
||||||
|
|
||||||
|
// Force compile-time evaluation when possible
|
||||||
|
inline constexpr u32 vertices(InputTopology input_topology) {
|
||||||
|
return vertex_counts[static_cast<std::size_t>(input_topology)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
enum class CompareFunction {
|
enum class CompareFunction {
|
||||||
Never,
|
Never,
|
||||||
Less,
|
Less,
|
||||||
|
|||||||
Reference in New Issue
Block a user