From 4b58ac1a1ee97f50a0d3c962ddfbc5987c6b2cdf Mon Sep 17 00:00:00 2001 From: Samuliak Date: Mon, 11 Nov 2024 17:21:16 +0100 Subject: [PATCH] check if verticesPerInstance uniform is used --- .../LegacyShaderDecompiler/LatteDecompilerAnalyzer.cpp | 6 ++++++ .../LatteDecompilerEmitMSLHeader.hpp | 10 +++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompilerAnalyzer.cpp b/src/Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompilerAnalyzer.cpp index b5697d42..3a45ade5 100644 --- a/src/Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompilerAnalyzer.cpp +++ b/src/Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompilerAnalyzer.cpp @@ -547,6 +547,12 @@ namespace LatteDecompiler { decompilerContext->hasUniformVarBlock = true; // uf_verticesPerInstance and uf_streamoutBufferBase* } + if (g_renderer->GetType() == RendererAPI::Metal) + { + // TODO: also check for rect primitive + if (decompilerContext->shaderType == LatteConst::ShaderType::Vertex && decompilerContext->options->usesGeometryShader) + decompilerContext->hasUniformVarBlock = true; // uf_verticesPerInstance + } } void _initUniformBindingPoints(LatteDecompilerShaderContext* decompilerContext) diff --git a/src/Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompilerEmitMSLHeader.hpp b/src/Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompilerEmitMSLHeader.hpp index 1e3091a6..0ca4422a 100644 --- a/src/Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompilerEmitMSLHeader.hpp +++ b/src/Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompilerEmitMSLHeader.hpp @@ -5,7 +5,7 @@ namespace LatteDecompiler { - static void _emitUniformVariables(LatteDecompilerShaderContext* decompilerContext) + static void _emitUniformVariables(LatteDecompilerShaderContext* decompilerContext, bool isRectVertexShader) { auto src = decompilerContext->shaderSource; @@ -85,7 +85,11 @@ namespace LatteDecompiler uniformCurrentOffset += 8; } // define verticesPerInstance + streamoutBufferBaseX - if (shader->shaderType == LatteConst::ShaderType::Vertex || shader->shaderType == LatteConst::ShaderType::Geometry) + if ((shader->shaderType == LatteConst::ShaderType::Vertex && + (decompilerContext->options->usesGeometryShader || isRectVertexShader)) || + (decompilerContext->analyzer.useSSBOForStreamout && + (shader->shaderType == LatteConst::ShaderType::Vertex && !decompilerContext->options->usesGeometryShader) || + (shader->shaderType == LatteConst::ShaderType::Geometry))) { src->add("int verticesPerInstance;" _CRLF); uniformOffsets.offset_verticesPerInstance = uniformCurrentOffset; @@ -392,7 +396,7 @@ namespace LatteDecompiler if(dump_shaders_enabled) decompilerContext->shaderSource->add("// start of shader inputs/outputs, predetermined by Cemu. Do not touch" _CRLF); // uniform variables - _emitUniformVariables(decompilerContext); + _emitUniformVariables(decompilerContext, isRectVertexShader); // uniform buffers _emitUniformBuffers(decompilerContext); // inputs and outputs