From 562b86dd8fec7620c08dc595bbcb4c2138173e8e Mon Sep 17 00:00:00 2001 From: SSimco <37044560+SSimco@users.noreply.github.com> Date: Mon, 10 Mar 2025 10:13:38 +0200 Subject: [PATCH] Latte: Add dummy params in shaders --- .../LatteDecompilerEmitGLSL.cpp | 6 ++++++ .../LatteDecompilerEmitGLSLHeader.hpp | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompilerEmitGLSL.cpp b/src/Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompilerEmitGLSL.cpp index 7a6605f8..4e4b08b3 100644 --- a/src/Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompilerEmitGLSL.cpp +++ b/src/Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompilerEmitGLSL.cpp @@ -3961,6 +3961,12 @@ void LatteDecompiler_emitGLSLShader(LatteDecompilerShaderContext* shaderContext, // start of main src->add("void main()" _CRLF); src->add("{" _CRLF); + + if (shaderContext->options->usesGeometryShader == false && shaderContext->shaderType == LatteConst::ShaderType::Vertex) + { + src->add("dummyPassParamInit();" _CRLF); + } + // variable definition if (shaderContext->typeTracker.useArrayGPRs == false) { diff --git a/src/Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompilerEmitGLSLHeader.hpp b/src/Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompilerEmitGLSLHeader.hpp index 428f8647..898721bb 100644 --- a/src/Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompilerEmitGLSLHeader.hpp +++ b/src/Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompilerEmitGLSLHeader.hpp @@ -356,6 +356,8 @@ namespace LatteDecompiler void _emitVSExports(LatteDecompilerShaderContext* shaderContext) { + std::array activePassParams{}; + auto* src = shaderContext->shaderSource; LatteShaderPSInputTable* psInputTable = LatteSHRC_GetPSInputTable(); auto parameterMask = shaderContext->shader->outputParameterMask; @@ -379,6 +381,8 @@ namespace LatteDecompiler if (psInputIndex == -1) continue; // no ps input + activePassParams.at(psInputIndex) = true; + src->addFmt("layout(location = {}) ", psInputIndex); if (psInputTable->import[psInputIndex].isFlat) src->add("flat "); @@ -387,6 +391,21 @@ namespace LatteDecompiler src->add("out"); src->addFmt(" vec4 passParameterSem{};" _CRLF, psInputTable->import[psInputIndex].semanticId); } + + // TODO: fix this + for (uint32 i = 0; i < 32; i++) + { + if (!activePassParams[i]) + src->addFmt("layout(location = {0}) out vec4 dummyPassParameterSem{0};" _CRLF, i); + } + + src->add("void dummyPassParamInit() {" _CRLF); + for (uint32 i = 0; i < 32; i++) + { + if (!activePassParams[i]) + src->addFmt("dummyPassParameterSem{} = vec4(0.0, 0.0, 0.0, 0.0);" _CRLF, i); + } + src->add("}" _CRLF); } void _emitPSImports(LatteDecompilerShaderContext* shaderContext)