mirror of
https://github.com/cemu-project/Cemu.git
synced 2024-12-01 21:44:17 +01:00
correct the object shader hash
This commit is contained in:
parent
2ee92e53e9
commit
b13ba58aad
@ -8,7 +8,6 @@
|
|||||||
#include "Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompilerInstructions.h"
|
#include "Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompilerInstructions.h"
|
||||||
#include "Cafe/HW/Latte/Core/FetchShader.h"
|
#include "Cafe/HW/Latte/Core/FetchShader.h"
|
||||||
#include "Cafe/HW/Latte/ISA/LatteInstructions.h"
|
#include "Cafe/HW/Latte/ISA/LatteInstructions.h"
|
||||||
#include "HW/Latte/Renderer/Renderer.h"
|
|
||||||
#include "util/containers/LookupTableL3.h"
|
#include "util/containers/LookupTableL3.h"
|
||||||
#include "util/helpers/fspinlock.h"
|
#include "util/helpers/fspinlock.h"
|
||||||
#include <openssl/sha.h> /* SHA1_DIGEST_LENGTH */
|
#include <openssl/sha.h> /* SHA1_DIGEST_LENGTH */
|
||||||
@ -108,14 +107,6 @@ void LatteShader_calculateFSKey(LatteFetchShader* fetchShader)
|
|||||||
key += (uint64)(attrib->offset & 3);
|
key += (uint64)(attrib->offset & 3);
|
||||||
key = std::rotl<uint64>(key, 2);
|
key = std::rotl<uint64>(key, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: also check if geometry shader is used
|
|
||||||
if (g_renderer->GetType() == RendererAPI::Metal)
|
|
||||||
{
|
|
||||||
key += (uint64)group.attributeBufferIndex;
|
|
||||||
key = std::rotl<uint64>(key, 5);
|
|
||||||
// TODO: hash the stride as well
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// todo - also hash invalid buffer groups?
|
// todo - also hash invalid buffer groups?
|
||||||
fetchShader->key = key;
|
fetchShader->key = key;
|
||||||
@ -155,6 +146,23 @@ void LatteFetchShader::CalculateFetchShaderVkHash()
|
|||||||
this->vkPipelineHashFragment = h;
|
this->vkPipelineHashFragment = h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LatteFetchShader::CalculateFetchShaderMtlObjectShaderHash(uint32* contextRegister)
|
||||||
|
{uint64 key = 0;
|
||||||
|
for (sint32 g = 0; g < bufferGroups.size(); g++)
|
||||||
|
{
|
||||||
|
LatteParsedFetchShaderBufferGroup_t& group = bufferGroups[g];
|
||||||
|
uint32 bufferIndex = group.attributeBufferIndex;
|
||||||
|
uint32 bufferBaseRegisterIndex = mmSQ_VTX_ATTRIBUTE_BLOCK_START + bufferIndex * 7;
|
||||||
|
uint32 bufferStride = (contextRegister[bufferBaseRegisterIndex + 2] >> 11) & 0xFFFF;
|
||||||
|
|
||||||
|
key += (uint64)bufferIndex;
|
||||||
|
key = std::rotl<uint64>(key, 5);
|
||||||
|
key += (uint64)bufferStride;
|
||||||
|
key = std::rotl<uint64>(key, 5);
|
||||||
|
}
|
||||||
|
mtlShaderHashObject = key;
|
||||||
|
}
|
||||||
|
|
||||||
void _fetchShaderDecompiler_parseInstruction_VTX_SEMANTIC(LatteFetchShader* parsedFetchShader, uint32* contextRegister, const LatteClauseInstruction_VTX* instr)
|
void _fetchShaderDecompiler_parseInstruction_VTX_SEMANTIC(LatteFetchShader* parsedFetchShader, uint32* contextRegister, const LatteClauseInstruction_VTX* instr)
|
||||||
{
|
{
|
||||||
uint32 semanticId = instr->getFieldSEM_SEMANTIC_ID(); // location (attribute index inside shader)
|
uint32 semanticId = instr->getFieldSEM_SEMANTIC_ID(); // location (attribute index inside shader)
|
||||||
@ -337,6 +345,7 @@ LatteFetchShader* LatteShaderRecompiler_createFetchShader(LatteFetchShader::Cach
|
|||||||
// 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);
|
LatteShader_calculateFSKey(newFetchShader);
|
||||||
newFetchShader->CalculateFetchShaderVkHash();
|
newFetchShader->CalculateFetchShaderVkHash();
|
||||||
|
newFetchShader->CalculateFetchShaderMtlObjectShaderHash(contextRegister);
|
||||||
return newFetchShader;
|
return newFetchShader;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -396,6 +405,7 @@ LatteFetchShader* LatteShaderRecompiler_createFetchShader(LatteFetchShader::Cach
|
|||||||
}
|
}
|
||||||
LatteShader_calculateFSKey(newFetchShader);
|
LatteShader_calculateFSKey(newFetchShader);
|
||||||
newFetchShader->CalculateFetchShaderVkHash();
|
newFetchShader->CalculateFetchShaderVkHash();
|
||||||
|
newFetchShader->CalculateFetchShaderMtlObjectShaderHash(contextRegister);
|
||||||
|
|
||||||
// register in cache
|
// register in cache
|
||||||
// its possible that during multi-threaded shader cache loading, two identical (same hash) fetch shaders get created simultaneously
|
// its possible that during multi-threaded shader cache loading, two identical (same hash) fetch shaders get created simultaneously
|
||||||
|
@ -46,6 +46,9 @@ struct LatteFetchShader
|
|||||||
// Vulkan
|
// Vulkan
|
||||||
uint64 vkPipelineHashFragment{}; // hash of all fetch shader state that influences the Vulkan graphics pipeline
|
uint64 vkPipelineHashFragment{}; // hash of all fetch shader state that influences the Vulkan graphics pipeline
|
||||||
|
|
||||||
|
// Metal
|
||||||
|
uint64 mtlShaderHashObject{};
|
||||||
|
|
||||||
// cache info
|
// cache info
|
||||||
CacheHash m_cacheHash{};
|
CacheHash m_cacheHash{};
|
||||||
bool m_isRegistered{}; // if true, fetch shader is referenced by cache (RegisterInCache() succeeded)
|
bool m_isRegistered{}; // if true, fetch shader is referenced by cache (RegisterInCache() succeeded)
|
||||||
@ -53,6 +56,8 @@ struct LatteFetchShader
|
|||||||
|
|
||||||
void CalculateFetchShaderVkHash();
|
void CalculateFetchShaderVkHash();
|
||||||
|
|
||||||
|
void CalculateFetchShaderMtlObjectShaderHash(uint32* contextRegister);
|
||||||
|
|
||||||
uint64 getVkPipelineHashFragment() const { return vkPipelineHashFragment; };
|
uint64 getVkPipelineHashFragment() const { return vkPipelineHashFragment; };
|
||||||
|
|
||||||
static bool isValidBufferIndex(const uint32 index) { return index < 0x10; };
|
static bool isValidBufferIndex(const uint32 index) { return index < 0x10; };
|
||||||
|
@ -498,6 +498,8 @@ void LatteSHRC_UpdateVSBaseHash(uint8* vertexShaderPtr, uint32 vertexShaderSize,
|
|||||||
uint64 vsHash2 = 0;
|
uint64 vsHash2 = 0;
|
||||||
_calculateShaderProgramHash(vsProgramCode, vertexShaderSize, &hashCacheVS, &vsHash1, &vsHash2);
|
_calculateShaderProgramHash(vsProgramCode, vertexShaderSize, &hashCacheVS, &vsHash1, &vsHash2);
|
||||||
uint64 vsHash = vsHash1 + vsHash2 + _activeFetchShader->key + _activePSImportTable.key + (usesGeometryShader ? 0x1111ULL : 0ULL);
|
uint64 vsHash = vsHash1 + vsHash2 + _activeFetchShader->key + _activePSImportTable.key + (usesGeometryShader ? 0x1111ULL : 0ULL);
|
||||||
|
if (g_renderer->GetType() == RendererAPI::Metal && usesGeometryShader)
|
||||||
|
vsHash += _activeFetchShader->mtlShaderHashObject;
|
||||||
|
|
||||||
uint32 tmp = LatteGPUState.contextNew.PA_CL_VTE_CNTL.getRawValue() ^ 0x43F;
|
uint32 tmp = LatteGPUState.contextNew.PA_CL_VTE_CNTL.getRawValue() ^ 0x43F;
|
||||||
vsHash += tmp;
|
vsHash += tmp;
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#include "Cafe/HW/Latte/Renderer/Metal/MetalCommon.h"
|
#include "Cafe/HW/Latte/Renderer/Metal/MetalCommon.h"
|
||||||
#include "Cafe/HW/Latte/Renderer/Metal/MetalPipelineCache.h"
|
#include "Cafe/HW/Latte/Renderer/Metal/MetalPipelineCache.h"
|
||||||
#include "Cafe/HW/Latte/Renderer/Metal/MetalRenderer.h"
|
#include "Cafe/HW/Latte/Renderer/Metal/MetalRenderer.h"
|
||||||
#include "Foundation/NSObject.hpp"
|
|
||||||
#include "HW/Latte/Core/LatteShader.h"
|
#include "HW/Latte/Core/LatteShader.h"
|
||||||
#include "HW/Latte/Renderer/Metal/CachedFBOMtl.h"
|
#include "HW/Latte/Renderer/Metal/CachedFBOMtl.h"
|
||||||
#include "HW/Latte/Renderer/Metal/LatteToMtl.h"
|
#include "HW/Latte/Renderer/Metal/LatteToMtl.h"
|
||||||
@ -10,7 +9,6 @@
|
|||||||
|
|
||||||
#include "HW/Latte/Core/FetchShader.h"
|
#include "HW/Latte/Core/FetchShader.h"
|
||||||
#include "HW/Latte/ISA/RegDefines.h"
|
#include "HW/Latte/ISA/RegDefines.h"
|
||||||
#include "Metal/MTLRenderPipeline.hpp"
|
|
||||||
#include "config/ActiveSettings.h"
|
#include "config/ActiveSettings.h"
|
||||||
|
|
||||||
static void rectsEmulationGS_outputSingleVertex(std::string& gsSrc, const LatteDecompilerShader* vertexShader, LatteShaderPSInputTable* psInputTable, sint32 vIdx, const LatteContextRegister& latteRegister)
|
static void rectsEmulationGS_outputSingleVertex(std::string& gsSrc, const LatteDecompilerShader* vertexShader, LatteShaderPSInputTable* psInputTable, sint32 vIdx, const LatteContextRegister& latteRegister)
|
||||||
|
Loading…
Reference in New Issue
Block a user