latte: isolate Metal-specific hashes

This commit is contained in:
Samuliak 2025-05-19 20:22:45 +02:00
parent 4ec2638395
commit feba1aa7ba
No known key found for this signature in database
3 changed files with 15 additions and 12 deletions

View file

@ -75,7 +75,7 @@ uint32 LatteShaderRecompiler_getAttributeAlignment(LatteParsedFetchShaderAttribu
return 4; return 4;
} }
void LatteShader_calculateFSKey(LatteFetchShader* fetchShader, uint32* contextRegister) void LatteShader_calculateFSKey(LatteFetchShader* fetchShader)
{ {
uint64 key = 0; uint64 key = 0;
for (sint32 g = 0; g < fetchShader->bufferGroups.size(); g++) for (sint32 g = 0; g < fetchShader->bufferGroups.size(); g++)
@ -367,7 +367,7 @@ LatteFetchShader* LatteShaderRecompiler_createFetchShader(LatteFetchShader::Cach
{ {
// empty fetch shader, seen in Minecraft // empty fetch shader, seen in Minecraft
// these only make sense when vertex shader does not call FS? // these only make sense when vertex shader does not call FS?
LatteShader_calculateFSKey(newFetchShader, contextRegister); LatteShader_calculateFSKey(newFetchShader);
newFetchShader->CalculateFetchShaderVkHash(); newFetchShader->CalculateFetchShaderVkHash();
newFetchShader->CheckIfVerticesNeedManualFetchMtl(contextRegister); newFetchShader->CheckIfVerticesNeedManualFetchMtl(contextRegister);
return newFetchShader; return newFetchShader;
@ -427,7 +427,7 @@ LatteFetchShader* LatteShaderRecompiler_createFetchShader(LatteFetchShader::Cach
} }
bufferGroup.vboStride = vboOffset; bufferGroup.vboStride = vboOffset;
} }
LatteShader_calculateFSKey(newFetchShader, contextRegister); LatteShader_calculateFSKey(newFetchShader);
newFetchShader->CalculateFetchShaderVkHash(); newFetchShader->CalculateFetchShaderVkHash();
newFetchShader->CheckIfVerticesNeedManualFetchMtl(contextRegister); newFetchShader->CheckIfVerticesNeedManualFetchMtl(contextRegister);

View file

@ -650,6 +650,9 @@ uint64 LatteSHRC_CalcPSAuxHash(LatteDecompilerShader* pixelShader, uint32* conte
auxHash += (uint64)dim; auxHash += (uint64)dim;
} }
#if ENABLE_METAL
if (g_renderer->GetType() == RendererAPI::Metal)
{
// Textures as render targets // Textures as render targets
for (uint32 i = 0; i < pixelShader->textureUnitListCount; i++) for (uint32 i = 0; i < pixelShader->textureUnitListCount; i++)
{ {
@ -658,9 +661,7 @@ uint64 LatteSHRC_CalcPSAuxHash(LatteDecompilerShader* pixelShader, uint32* conte
auxHash += (uint64)pixelShader->textureRenderTargetIndex[t]; auxHash += (uint64)pixelShader->textureRenderTargetIndex[t];
} }
#if ENABLE_METAL // Color buffers
if (g_renderer->GetType() == RendererAPI::Metal)
{
for (uint8 i = 0; i < LATTE_NUM_COLOR_TARGET; i++) for (uint8 i = 0; i < LATTE_NUM_COLOR_TARGET; i++)
{ {
auto format = LatteMRT::GetColorBufferFormat(i, LatteGPUState.contextNew); auto format = LatteMRT::GetColorBufferFormat(i, LatteGPUState.contextNew);
@ -669,6 +670,7 @@ uint64 LatteSHRC_CalcPSAuxHash(LatteDecompilerShader* pixelShader, uint32* conte
auxHash += (uint64)dataType; auxHash += (uint64)dataType;
} }
// Depth buffer
bool hasDepthBuffer = LatteMRT::GetActiveDepthBufferMask(LatteGPUState.contextNew); bool hasDepthBuffer = LatteMRT::GetActiveDepthBufferMask(LatteGPUState.contextNew);
if (hasDepthBuffer) if (hasDepthBuffer)
{ {

View file

@ -403,7 +403,8 @@ void LatteDecompiler_analyzeExport(LatteDecompilerShaderContext* shaderContext,
} }
else if (cfInstruction->exportType == 0 && cfInstruction->exportArrayBase == 61) else if (cfInstruction->exportType == 0 && cfInstruction->exportArrayBase == 61)
{ {
if (LatteMRT::GetActiveDepthBufferMask(*shaderContext->contextRegistersNew)) // Only check for depth buffer mask on Metal, as its not in the PS hash on other backends
if (g_renderer->GetType() != RendererAPI::Metal || LatteMRT::GetActiveDepthBufferMask(*shaderContext->contextRegistersNew))
shader->depthMask = true; shader->depthMask = true;
} }
else else