mirror of
https://github.com/cemu-project/Cemu.git
synced 2025-07-07 23:41:18 +12:00
implement framebuffer fetch
This commit is contained in:
parent
68aa40518d
commit
e4068856bc
6 changed files with 184 additions and 98 deletions
|
@ -504,45 +504,6 @@ void LatteSHRC_UpdateVSBaseHash(uint8* vertexShaderPtr, uint32 vertexShaderSize,
|
|||
uint64 vsHash2 = 0;
|
||||
_calculateShaderProgramHash(vsProgramCode, vertexShaderSize, &hashCacheVS, &vsHash1, &vsHash2);
|
||||
uint64 vsHash = vsHash1 + vsHash2 + _activeFetchShader->key + _activePSImportTable.key + (usesGeometryShader ? 0x1111ULL : 0ULL);
|
||||
if (g_renderer->GetType() == RendererAPI::Metal)
|
||||
{
|
||||
if (usesGeometryShader || _activeFetchShader->mtlFetchVertexManually)
|
||||
{
|
||||
for (sint32 g = 0; g < _activeFetchShader->bufferGroups.size(); g++)
|
||||
{
|
||||
LatteParsedFetchShaderBufferGroup_t& group = _activeFetchShader->bufferGroups[g];
|
||||
uint32 bufferIndex = group.attributeBufferIndex;
|
||||
uint32 bufferBaseRegisterIndex = mmSQ_VTX_ATTRIBUTE_BLOCK_START + bufferIndex * 7;
|
||||
uint32 bufferStride = (LatteGPUState.contextRegister[bufferBaseRegisterIndex + 2] >> 11) & 0xFFFF;
|
||||
|
||||
vsHash += (uint64)bufferStride;
|
||||
vsHash = std::rotl<uint64>(vsHash, 7);
|
||||
}
|
||||
}
|
||||
|
||||
if (!usesGeometryShader)
|
||||
{
|
||||
// Rasterization
|
||||
bool rasterizationEnabled = !LatteGPUState.contextNew.PA_CL_CLIP_CNTL.get_DX_RASTERIZATION_KILL();
|
||||
|
||||
// HACK
|
||||
if (!LatteGPUState.contextNew.PA_CL_VTE_CNTL.get_VPORT_X_OFFSET_ENA())
|
||||
rasterizationEnabled = true;
|
||||
|
||||
const auto& polygonControlReg = LatteGPUState.contextNew.PA_SU_SC_MODE_CNTL;
|
||||
uint32 cullFront = polygonControlReg.get_CULL_FRONT();
|
||||
uint32 cullBack = polygonControlReg.get_CULL_BACK();
|
||||
if (cullFront && cullBack)
|
||||
rasterizationEnabled = false;
|
||||
|
||||
if (rasterizationEnabled)
|
||||
vsHash += 51ULL;
|
||||
|
||||
// Vertex fetch
|
||||
if (_activeFetchShader->mtlFetchVertexManually)
|
||||
vsHash += 349ULL;
|
||||
}
|
||||
}
|
||||
|
||||
uint32 tmp = LatteGPUState.contextNew.PA_CL_VTE_CNTL.getRawValue() ^ 0x43F;
|
||||
vsHash += tmp;
|
||||
|
@ -563,6 +524,46 @@ void LatteSHRC_UpdateVSBaseHash(uint8* vertexShaderPtr, uint32 vertexShaderSize,
|
|||
if (LatteGPUState.contextNew.PA_CL_CLIP_CNTL.get_DX_CLIP_SPACE_DEF())
|
||||
vsHash += 0x1537;
|
||||
|
||||
if (g_renderer->GetType() == RendererAPI::Metal)
|
||||
{
|
||||
if (usesGeometryShader || _activeFetchShader->mtlFetchVertexManually)
|
||||
{
|
||||
for (sint32 g = 0; g < _activeFetchShader->bufferGroups.size(); g++)
|
||||
{
|
||||
LatteParsedFetchShaderBufferGroup_t& group = _activeFetchShader->bufferGroups[g];
|
||||
uint32 bufferIndex = group.attributeBufferIndex;
|
||||
uint32 bufferBaseRegisterIndex = mmSQ_VTX_ATTRIBUTE_BLOCK_START + bufferIndex * 7;
|
||||
uint32 bufferStride = (LatteGPUState.contextRegister[bufferBaseRegisterIndex + 2] >> 11) & 0xFFFF;
|
||||
|
||||
vsHash += (uint64)bufferStride;
|
||||
vsHash = std::rotl<uint64>(vsHash, 7);
|
||||
}
|
||||
}
|
||||
|
||||
if (!usesGeometryShader)
|
||||
{
|
||||
// Rasterization
|
||||
bool rasterizationEnabled = !LatteGPUState.contextNew.PA_CL_CLIP_CNTL.get_DX_RASTERIZATION_KILL();
|
||||
|
||||
// HACK
|
||||
if (!LatteGPUState.contextNew.PA_CL_VTE_CNTL.get_VPORT_X_OFFSET_ENA())
|
||||
rasterizationEnabled = true;
|
||||
|
||||
const auto& polygonControlReg = LatteGPUState.contextNew.PA_SU_SC_MODE_CNTL;
|
||||
uint32 cullFront = polygonControlReg.get_CULL_FRONT();
|
||||
uint32 cullBack = polygonControlReg.get_CULL_BACK();
|
||||
if (cullFront && cullBack)
|
||||
rasterizationEnabled = false;
|
||||
|
||||
if (rasterizationEnabled)
|
||||
vsHash += 51ULL;
|
||||
|
||||
// Vertex fetch
|
||||
if (_activeFetchShader->mtlFetchVertexManually)
|
||||
vsHash += 349ULL;
|
||||
}
|
||||
}
|
||||
|
||||
_shaderBaseHash_vs = vsHash;
|
||||
}
|
||||
|
||||
|
@ -589,19 +590,6 @@ void LatteSHRC_UpdatePSBaseHash(uint8* pixelShaderPtr, uint32 pixelShaderSize, b
|
|||
// get vertex shader
|
||||
uint64 psHash = psHash1 + psHash2 + _activePSImportTable.key + (usesGeometryShader ? hashCacheGS.prevHash1 : 0ULL);
|
||||
|
||||
#if ENABLE_METAL
|
||||
if (g_renderer->GetType() == RendererAPI::Metal)
|
||||
{
|
||||
for (uint8 i = 0; i < LATTE_NUM_COLOR_TARGET; i++)
|
||||
{
|
||||
auto format = LatteMRT::GetColorBufferFormat(i, LatteGPUState.contextNew);
|
||||
uint8 dataType = (uint8)GetMtlPixelFormatInfo(format, false).dataType;
|
||||
psHash += (uint64)dataType;
|
||||
psHash = std::rotl<uint64>(psHash, 7);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
_shaderBaseHash_ps = psHash;
|
||||
}
|
||||
|
||||
|
@ -635,6 +623,7 @@ uint64 LatteSHRC_CalcVSAuxHash(LatteDecompilerShader* vertexShader, uint32* cont
|
|||
auxHashTex += 0x333;
|
||||
}
|
||||
}
|
||||
|
||||
return auxHash + auxHashTex;
|
||||
}
|
||||
|
||||
|
@ -668,6 +657,28 @@ uint64 LatteSHRC_CalcPSAuxHash(LatteDecompilerShader* pixelShader, uint32* conte
|
|||
auxHash = (auxHash << 3) | (auxHash >> 61);
|
||||
auxHash += (uint64)dim;
|
||||
}
|
||||
|
||||
// Textures as render targets
|
||||
for (uint32 i = 0; i < pixelShader->textureUnitListCount; i++)
|
||||
{
|
||||
uint8 t = pixelShader->textureUnitList[i];
|
||||
auxHash = std::rotl<uint64>(auxHash, 11);
|
||||
auxHash += (uint64)pixelShader->textureRenderTargetIndex[t];
|
||||
}
|
||||
|
||||
#if ENABLE_METAL
|
||||
if (g_renderer->GetType() == RendererAPI::Metal)
|
||||
{
|
||||
for (uint8 i = 0; i < LATTE_NUM_COLOR_TARGET; i++)
|
||||
{
|
||||
auto format = LatteMRT::GetColorBufferFormat(i, LatteGPUState.contextNew);
|
||||
uint8 dataType = (uint8)GetMtlPixelFormatInfo(format, false).dataType;
|
||||
auxHash = std::rotl<uint64>(auxHash, 7);
|
||||
auxHash += (uint64)dataType;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return auxHash;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue