From 2b93604da002515d35f766f76c97052782221cc5 Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Sat, 4 Feb 2023 22:35:34 +0000 Subject: [PATCH] Use hades HLE replacement for constant buffer attributes In the cases of indirect draws, we don't know the vertex offset to write into the driver info constant buffer ahead of time, and to do it at draw time on the GPU would mean marking the constant buffer as GPU dirty (slow). HLE them in the shader instead using the host draw parameters extension. --- app/src/main/cpp/skyline/gpu/shader_manager.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/app/src/main/cpp/skyline/gpu/shader_manager.cpp b/app/src/main/cpp/skyline/gpu/shader_manager.cpp index b0251025..fe6e38d2 100644 --- a/app/src/main/cpp/skyline/gpu/shader_manager.cpp +++ b/app/src/main/cpp/skyline/gpu/shader_manager.cpp @@ -213,11 +213,24 @@ namespace skyline::gpu { } [[nodiscard]] bool HasHLEMacroState() const final { - return false; + return stage == Shader::Stage::VertexB || stage == Shader::Stage::VertexA; } [[nodiscard]] std::optional GetReplaceConstBuffer(u32 bank, u32 offset) final { - return std::nullopt; + if (bank != 0 || !is_propietary_driver) + return std::nullopt; + + // Replace constant buffer offsets containing draw parameters with the appropriate shader attribute, required as e.g. in the case of indirect draws the constant buffer contents won't be entirely correct for these specific parameters + switch (offset) { + case 0x640: + return Shader::ReplaceConstant::BaseVertex; + case 0x644: + return Shader::ReplaceConstant::BaseInstance; + case 0x648: + return Shader::ReplaceConstant::DrawID; + default: + return std::nullopt; + } } void Dump(u64 hash) final {}