mirror of
https://github.com/cemu-project/Cemu.git
synced 2025-07-13 10:18:30 +12:00
Initial support for title switching + better Wii U menu compatibility (#907)
This commit is contained in:
parent
bfbeeae6f6
commit
2200cc0ddf
95 changed files with 2549 additions and 746 deletions
|
@ -100,11 +100,6 @@ PPCInterpreter_t* PPCCore_executeCallbackInternal(uint32 functionMPTR)
|
|||
return hCPU;
|
||||
}
|
||||
|
||||
void PPCCore_deleteAllThreads()
|
||||
{
|
||||
assert_dbg();
|
||||
}
|
||||
|
||||
void PPCCore_init()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -236,7 +236,6 @@ HLECALL PPCInterpreter_getHLECall(HLEIDX funcIndex);
|
|||
|
||||
// HLE scheduler
|
||||
|
||||
void PPCCore_deleteAllThreads();
|
||||
void PPCInterpreter_relinquishTimeslice();
|
||||
|
||||
void PPCCore_boostQuantum(sint32 numCycles);
|
||||
|
|
|
@ -289,11 +289,16 @@ void PPCRecompiler_recompileAtAddress(uint32 address)
|
|||
bool r = PPCRecompiler_makeRecompiledFunctionActive(address, range, func, functionEntryPoints);
|
||||
}
|
||||
|
||||
std::thread s_threadRecompiler;
|
||||
std::atomic_bool s_recompilerThreadStopSignal{false};
|
||||
|
||||
void PPCRecompiler_thread()
|
||||
{
|
||||
SetThreadName("PPCRecompiler_thread");
|
||||
while (true)
|
||||
{
|
||||
if(s_recompilerThreadStopSignal)
|
||||
return;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
// asynchronous recompilation:
|
||||
// 1) take address from queue
|
||||
|
@ -326,7 +331,12 @@ void PPCRecompiler_thread()
|
|||
|
||||
#define PPC_REC_ALLOC_BLOCK_SIZE (4*1024*1024) // 4MB
|
||||
|
||||
std::bitset<(MEMORY_CODEAREA_ADDR + MEMORY_CODEAREA_SIZE) / PPC_REC_ALLOC_BLOCK_SIZE> ppcRecompiler_reservedBlockMask;
|
||||
constexpr uint32 PPCRecompiler_GetNumAddressSpaceBlocks()
|
||||
{
|
||||
return (MEMORY_CODEAREA_ADDR + MEMORY_CODEAREA_SIZE + PPC_REC_ALLOC_BLOCK_SIZE - 1) / PPC_REC_ALLOC_BLOCK_SIZE;
|
||||
}
|
||||
|
||||
std::bitset<PPCRecompiler_GetNumAddressSpaceBlocks()> ppcRecompiler_reservedBlockMask;
|
||||
|
||||
void PPCRecompiler_reserveLookupTableBlock(uint32 offset)
|
||||
{
|
||||
|
@ -496,16 +506,9 @@ void PPCRecompiler_init()
|
|||
MemMapper::AllocateMemory(&(ppcRecompilerInstanceData->_x64XMM_xorNegateMaskBottom), sizeof(PPCRecompilerInstanceData_t) - offsetof(PPCRecompilerInstanceData_t, _x64XMM_xorNegateMaskBottom), MemMapper::PAGE_PERMISSION::P_RW, true);
|
||||
PPCRecompilerX64Gen_generateRecompilerInterfaceFunctions();
|
||||
|
||||
uint32 codeRegionEnd = RPLLoader_GetMaxCodeOffset();
|
||||
codeRegionEnd = (codeRegionEnd + PPC_REC_ALLOC_BLOCK_SIZE - 1) & ~(PPC_REC_ALLOC_BLOCK_SIZE - 1);
|
||||
|
||||
uint32 codeRegionSize = codeRegionEnd - PPC_REC_CODE_AREA_START;
|
||||
cemuLog_logDebug(LogType::Force, "Allocating recompiler tables for range 0x{:08x}-0x{:08x}", PPC_REC_CODE_AREA_START, codeRegionEnd);
|
||||
|
||||
for (uint32 i = 0; i < codeRegionSize; i += PPC_REC_ALLOC_BLOCK_SIZE)
|
||||
{
|
||||
PPCRecompiler_reserveLookupTableBlock(i);
|
||||
}
|
||||
PPCRecompiler_allocateRange(0, 0x1000); // the first entry is used for fallback to interpreter
|
||||
PPCRecompiler_allocateRange(mmuRange_TRAMPOLINE_AREA.getBase(), mmuRange_TRAMPOLINE_AREA.getSize());
|
||||
PPCRecompiler_allocateRange(mmuRange_CODECAVE.getBase(), mmuRange_CODECAVE.getSize());
|
||||
|
||||
// init x64 recompiler instance data
|
||||
ppcRecompilerInstanceData->_x64XMM_xorNegateMaskBottom[0] = 1ULL << 63ULL;
|
||||
|
@ -589,6 +592,33 @@ void PPCRecompiler_init()
|
|||
ppcRecompilerEnabled = true;
|
||||
|
||||
// launch recompilation thread
|
||||
std::thread t_recompiler(PPCRecompiler_thread);
|
||||
t_recompiler.detach();
|
||||
s_recompilerThreadStopSignal = false;
|
||||
s_threadRecompiler = std::thread(PPCRecompiler_thread);
|
||||
}
|
||||
|
||||
void PPCRecompiler_Shutdown()
|
||||
{
|
||||
// shut down recompiler thread
|
||||
s_recompilerThreadStopSignal = true;
|
||||
if(s_threadRecompiler.joinable())
|
||||
s_threadRecompiler.join();
|
||||
// clean up queues
|
||||
while(!PPCRecompilerState.targetQueue.empty())
|
||||
PPCRecompilerState.targetQueue.pop();
|
||||
PPCRecompilerState.invalidationRanges.clear();
|
||||
// clean range store
|
||||
rangeStore_ppcRanges.clear();
|
||||
// clean up memory
|
||||
uint32 numBlocks = PPCRecompiler_GetNumAddressSpaceBlocks();
|
||||
for(uint32 i=0; i<numBlocks; i++)
|
||||
{
|
||||
if(!ppcRecompiler_reservedBlockMask[i])
|
||||
continue;
|
||||
// deallocate
|
||||
uint64 offset = i * PPC_REC_ALLOC_BLOCK_SIZE;
|
||||
MemMapper::FreeMemory(&(ppcRecompilerInstanceData->ppcRecompilerFuncTable[offset/4]), (PPC_REC_ALLOC_BLOCK_SIZE/4)*sizeof(void*), true);
|
||||
MemMapper::FreeMemory(&(ppcRecompilerInstanceData->ppcRecompilerDirectJumpTable[offset/4]), (PPC_REC_ALLOC_BLOCK_SIZE/4)*sizeof(void*), true);
|
||||
// mark as unmapped
|
||||
ppcRecompiler_reservedBlockMask[i] = false;
|
||||
}
|
||||
}
|
|
@ -373,6 +373,7 @@ extern PPCRecompilerInstanceData_t* ppcRecompilerInstanceData;
|
|||
extern bool ppcRecompilerEnabled;
|
||||
|
||||
void PPCRecompiler_init();
|
||||
void PPCRecompiler_Shutdown();
|
||||
|
||||
void PPCRecompiler_allocateRange(uint32 startAddress, uint32 size);
|
||||
|
||||
|
|
|
@ -173,4 +173,5 @@ void LatteRenderTarget_updateViewport();
|
|||
// Latte emulation control
|
||||
void Latte_Start();
|
||||
void Latte_Stop();
|
||||
bool Latte_IsActive();
|
||||
bool Latte_GetStopSignal(); // returns true if stop was requested or if in stopped state
|
||||
void LatteThread_Exit();
|
|
@ -96,7 +96,7 @@ void LatteAsyncCommands_waitUntilAllProcessed()
|
|||
void LatteAsyncCommands_checkAndExecute()
|
||||
{
|
||||
// quick check if queue is empty (requires no lock)
|
||||
if (!Latte_IsActive())
|
||||
if (Latte_GetStopSignal())
|
||||
LatteThread_Exit();
|
||||
if (LatteAsyncCommandQueue.empty())
|
||||
return;
|
||||
|
|
|
@ -257,6 +257,11 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
return m_map.empty();
|
||||
}
|
||||
|
||||
const std::map<InternalRange, TNodeObject*>& getAll() const { return m_map; };
|
||||
};
|
||||
|
||||
|
@ -455,48 +460,6 @@ public:
|
|||
}
|
||||
if(m_invalidationRangeEnd <= m_invalidationRangeBegin)
|
||||
m_hasInvalidation = false;
|
||||
|
||||
//if (resRangeBegin <= m_invalidationRangeBegin)
|
||||
//{
|
||||
// // shrink/replace invalidation range from the bottom
|
||||
// uint32 uploadBegin = m_invalidationRangeBegin;//std::max(m_invalidationRangeBegin, resRangeBegin);
|
||||
// uint32 uploadEnd = std::min(resRangeEnd, m_invalidationRangeEnd);
|
||||
// cemu_assert_debug(uploadEnd >= uploadBegin);
|
||||
// if (uploadBegin != uploadEnd)
|
||||
// checkAndSyncModifications(uploadBegin, uploadEnd, true);
|
||||
// m_invalidationRangeBegin = uploadEnd;
|
||||
// cemu_assert_debug(m_invalidationRangeBegin <= m_invalidationRangeEnd);
|
||||
// if (m_invalidationRangeBegin >= m_invalidationRangeEnd)
|
||||
// m_hasInvalidation = false;
|
||||
//}
|
||||
//else if (resRangeEnd >= m_invalidationRangeEnd)
|
||||
//{
|
||||
// // shrink/replace invalidation range from the top
|
||||
// uint32 uploadBegin = std::max(m_invalidationRangeBegin, resRangeBegin);
|
||||
// uint32 uploadEnd = m_invalidationRangeEnd;// std::min(resRangeEnd, m_invalidationRangeEnd);
|
||||
// cemu_assert_debug(uploadEnd >= uploadBegin);
|
||||
// if (uploadBegin != uploadEnd)
|
||||
// checkAndSyncModifications(uploadBegin, uploadEnd, true);
|
||||
// m_invalidationRangeEnd = uploadBegin;
|
||||
// cemu_assert_debug(m_invalidationRangeBegin <= m_invalidationRangeEnd);
|
||||
// if (m_invalidationRangeBegin >= m_invalidationRangeEnd)
|
||||
// m_hasInvalidation = false;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// // since we cant cut holes into the range upload it in it's entirety
|
||||
// cemu_assert_debug(m_invalidationRangeEnd <= m_rangeEnd);
|
||||
// cemu_assert_debug(m_invalidationRangeBegin >= m_rangeBegin);
|
||||
// cemu_assert_debug(m_invalidationRangeBegin < m_invalidationRangeEnd);
|
||||
// checkAndSyncModifications(m_invalidationRangeBegin, m_invalidationRangeEnd, true);
|
||||
// m_hasInvalidation = false;
|
||||
//}
|
||||
|
||||
|
||||
|
||||
// todo - dont re-upload the whole range immediately
|
||||
// under ideal circumstances we would only upload the data range requested for the current draw call
|
||||
// but this is a hot path so we can't check
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -827,6 +790,21 @@ private:
|
|||
static std::vector<uint32> g_deallocateQueue;
|
||||
|
||||
public:
|
||||
static void UnloadAll()
|
||||
{
|
||||
size_t i = 0;
|
||||
while (i < s_allCacheNodes.size())
|
||||
{
|
||||
BufferCacheNode* node = s_allCacheNodes[i];
|
||||
node->ReleaseCacheMemoryImmediately();
|
||||
LatteBufferCache_removeSingleNodeFromTree(node);
|
||||
delete node;
|
||||
}
|
||||
for(auto& it : s_allCacheNodes)
|
||||
delete it;
|
||||
s_allCacheNodes.clear();
|
||||
g_deallocateQueue.clear();
|
||||
}
|
||||
|
||||
static void ProcessDeallocations()
|
||||
{
|
||||
|
@ -931,7 +909,6 @@ public:
|
|||
};
|
||||
|
||||
std::vector<uint32> BufferCacheNode::g_deallocateQueue;
|
||||
|
||||
IntervalTree2<MPTR, BufferCacheNode> g_gpuBufferCache;
|
||||
|
||||
void LatteBufferCache_removeSingleNodeFromTree(BufferCacheNode* node)
|
||||
|
@ -1009,10 +986,16 @@ void LatteBufferCache_processDeallocations()
|
|||
|
||||
void LatteBufferCache_init(size_t bufferSize)
|
||||
{
|
||||
cemu_assert_debug(g_gpuBufferCache.empty());
|
||||
g_gpuBufferHeap.reset(new VHeap(nullptr, (uint32)bufferSize));
|
||||
g_renderer->bufferCache_init((uint32)bufferSize);
|
||||
}
|
||||
|
||||
void LatteBufferCache_UnloadAll()
|
||||
{
|
||||
BufferCacheNode::UnloadAll();
|
||||
}
|
||||
|
||||
void LatteBufferCache_getStats(uint32& heapSize, uint32& allocationSize, uint32& allocNum)
|
||||
{
|
||||
g_gpuBufferHeap->getStats(heapSize, allocationSize, allocNum);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
void LatteBufferCache_init(size_t bufferSize);
|
||||
void LatteBufferCache_UnloadAll();
|
||||
|
||||
uint32 LatteBufferCache_retrieveDataInCache(MPTR physAddress, uint32 size);
|
||||
void LatteBufferCache_copyStreamoutDataToCache(MPTR physAddress, uint32 size, uint32 streamoutBufferOffset);
|
||||
|
|
|
@ -125,7 +125,7 @@ uint32 LatteCP_readU32Deprc()
|
|||
readDistance = (sint32)(gxRingBufferWritePtr - gxRingBufferReadPtr);
|
||||
if (readDistance != 0)
|
||||
break;
|
||||
if (!Latte_IsActive())
|
||||
if (Latte_GetStopSignal())
|
||||
LatteThread_Exit();
|
||||
|
||||
// still no command data available, do some other tasks
|
||||
|
@ -172,7 +172,7 @@ void LatteCP_waitForNWords(uint32 numWords)
|
|||
if (readDistance >= waitDistance)
|
||||
break;
|
||||
|
||||
if (!Latte_IsActive())
|
||||
if (Latte_GetStopSignal())
|
||||
LatteThread_Exit();
|
||||
|
||||
// still no command data available, do some other tasks
|
||||
|
|
|
@ -373,6 +373,7 @@ uint8 LatteMRT::GetActiveColorBufferMask(const LatteDecompilerShader* pixelShade
|
|||
if ((colorBufferWidth < (sint32)scissorAccessWidth) ||
|
||||
(colorBufferHeight < (sint32)scissorAccessHeight))
|
||||
{
|
||||
// log this?
|
||||
colorBufferMask &= ~(1<<i);
|
||||
}
|
||||
|
||||
|
|
|
@ -144,7 +144,7 @@ LatteShaderPSInputTable* LatteSHRC_GetPSInputTable()
|
|||
return &_activePSImportTable;
|
||||
}
|
||||
|
||||
bool LatteSHRC_RemoveFromCache(LatteDecompilerShader* shader)
|
||||
void LatteSHRC_RemoveFromCache(LatteDecompilerShader* shader)
|
||||
{
|
||||
bool removed = false;
|
||||
auto& cache = LatteSHRC_GetCacheByType(shader->shaderType);
|
||||
|
@ -156,10 +156,14 @@ bool LatteSHRC_RemoveFromCache(LatteDecompilerShader* shader)
|
|||
}
|
||||
else if (baseIt->second == shader)
|
||||
{
|
||||
if (baseIt->second->next)
|
||||
cache.emplace(shader->baseHash, baseIt->second->next);
|
||||
else
|
||||
cache.erase(baseIt);
|
||||
cemu_assert_debug(baseIt->second == shader);
|
||||
cache.erase(baseIt);
|
||||
if (shader->next)
|
||||
{
|
||||
cemu_assert_debug(shader->baseHash == shader->next->baseHash);
|
||||
cache.emplace(shader->baseHash, shader->next);
|
||||
}
|
||||
shader->next = 0;
|
||||
removed = true;
|
||||
}
|
||||
else
|
||||
|
@ -176,7 +180,7 @@ bool LatteSHRC_RemoveFromCache(LatteDecompilerShader* shader)
|
|||
}
|
||||
}
|
||||
}
|
||||
return removed;
|
||||
cemu_assert(removed);
|
||||
}
|
||||
|
||||
void LatteSHRC_RemoveFromCacheByHash(uint64 shader_base_hash, uint64 shader_aux_hash, LatteConst::ShaderType type)
|
||||
|
@ -1009,3 +1013,16 @@ void LatteSHRC_Init()
|
|||
cemu_assert_debug(sGeometryShaders.empty());
|
||||
cemu_assert_debug(sPixelShaders.empty());
|
||||
}
|
||||
|
||||
void LatteSHRC_UnloadAll()
|
||||
{
|
||||
while(!sVertexShaders.empty())
|
||||
LatteShader_free(sVertexShaders.begin()->second);
|
||||
cemu_assert_debug(sVertexShaders.empty());
|
||||
while(!sGeometryShaders.empty())
|
||||
LatteShader_free(sGeometryShaders.begin()->second);
|
||||
cemu_assert_debug(sGeometryShaders.empty());
|
||||
while(!sPixelShaders.empty())
|
||||
LatteShader_free(sPixelShaders.begin()->second);
|
||||
cemu_assert_debug(sPixelShaders.empty());
|
||||
}
|
|
@ -3,6 +3,7 @@
|
|||
#include "Cafe/HW/Latte/ISA/RegDefines.h"
|
||||
|
||||
void LatteSHRC_Init();
|
||||
void LatteSHRC_UnloadAll();
|
||||
|
||||
void LatteSHRC_ResetCachedShaderHash();
|
||||
void LatteShaderSHRC_UpdateFetchShader();
|
||||
|
@ -117,11 +118,12 @@ void LatteShader_DumpShader(uint64 baseHash, uint64 auxHash, LatteDecompilerShad
|
|||
void LatteShader_DumpRawShader(uint64 baseHash, uint64 auxHash, uint32 type, uint8* programCode, uint32 programLen);
|
||||
|
||||
// shader cache file
|
||||
void LatteShaderCache_load();
|
||||
void LatteShaderCache_Load();
|
||||
void LatteShaderCache_Close();
|
||||
|
||||
void LatteShaderCache_writeSeparableVertexShader(uint64 shaderBaseHash, uint64 shaderAuxHash, uint8* fetchShader, uint32 fetchShaderSize, uint8* vertexShader, uint32 vertexShaderSize, uint32* contextRegisters, bool usesGeometryShader);
|
||||
void LatteShaderCache_writeSeparableGeometryShader(uint64 shaderBaseHash, uint64 shaderAuxHash, uint8* geometryShader, uint32 geometryShaderSize, uint8* gsCopyShader, uint32 gsCopyShaderSize, uint32* contextRegisters, uint32* hleSpecialState, uint32 vsRingParameterCount);
|
||||
void LatteShaderCache_writeSeparablePixelShader(uint64 shaderBaseHash, uint64 shaderAuxHash, uint8* pixelShader, uint32 pixelShaderSize, uint32* contextRegisters, bool usesGeometryShader);
|
||||
|
||||
// todo - sort this
|
||||
// todo - refactor this
|
||||
sint32 LatteDecompiler_getTextureSamplerBaseIndex(LatteConst::ShaderType shaderType);
|
|
@ -53,7 +53,7 @@ struct
|
|||
sint32 pipelineFileCount;
|
||||
}g_shaderCacheLoaderState;
|
||||
|
||||
FileCache* fc_shaderCacheGeneric = nullptr; // contains hardware and Cemu version independent shader information
|
||||
FileCache* s_shaderCacheGeneric = nullptr; // contains hardware and version independent shader information
|
||||
|
||||
#define SHADER_CACHE_GENERIC_EXTRA_VERSION 2 // changing this constant will invalidate all hardware-independent cache files
|
||||
|
||||
|
@ -62,7 +62,7 @@ FileCache* fc_shaderCacheGeneric = nullptr; // contains hardware and Cemu versio
|
|||
#define SHADER_CACHE_TYPE_PIXEL (2)
|
||||
|
||||
bool LatteShaderCache_readSeparableShader(uint8* shaderInfoData, sint32 shaderInfoSize);
|
||||
void LatteShaderCache_loadVulkanPipelineCache(uint64 cacheTitleId);
|
||||
void LatteShaderCache_LoadVulkanPipelineCache(uint64 cacheTitleId);
|
||||
bool LatteShaderCache_updatePipelineLoadingProgress();
|
||||
void LatteShaderCache_ShowProgress(const std::function <bool(void)>& loadUpdateFunc, bool isPipelines);
|
||||
|
||||
|
@ -216,7 +216,7 @@ void LatteShaderCache_drawBackgroundImage(ImTextureID texture, int width, int he
|
|||
ImGui::PopStyleVar(2);
|
||||
}
|
||||
|
||||
void LatteShaderCache_load()
|
||||
void LatteShaderCache_Load()
|
||||
{
|
||||
shaderCacheScreenStats.compiledShaderCount = 0;
|
||||
shaderCacheScreenStats.vertexShaderCount = 0;
|
||||
|
@ -251,21 +251,21 @@ void LatteShaderCache_load()
|
|||
LatteShaderCache_handleDeprecatedCacheFiles(pathGeneric, pathGenericPre1_25_0, pathGenericPre1_16_0);
|
||||
// calculate extraVersion for transferable and precompiled shader cache
|
||||
uint32 transferableExtraVersion = SHADER_CACHE_GENERIC_EXTRA_VERSION;
|
||||
fc_shaderCacheGeneric = FileCache::Open(pathGeneric.generic_wstring(), false, transferableExtraVersion); // legacy extra version (1.25.0 - 1.25.1b)
|
||||
if(!fc_shaderCacheGeneric)
|
||||
fc_shaderCacheGeneric = FileCache::Open(pathGeneric.generic_wstring(), true, LatteShaderCache_getShaderCacheExtraVersion(cacheTitleId));
|
||||
if(!fc_shaderCacheGeneric)
|
||||
s_shaderCacheGeneric = FileCache::Open(pathGeneric, false, transferableExtraVersion); // legacy extra version (1.25.0 - 1.25.1b)
|
||||
if(!s_shaderCacheGeneric)
|
||||
s_shaderCacheGeneric = FileCache::Open(pathGeneric, true, LatteShaderCache_getShaderCacheExtraVersion(cacheTitleId));
|
||||
if(!s_shaderCacheGeneric)
|
||||
{
|
||||
// no shader cache available yet
|
||||
cemuLog_log(LogType::Force, "Unable to open or create shader cache file \"{}\"", _pathToUtf8(pathGeneric));
|
||||
LatteShaderCache_finish();
|
||||
return;
|
||||
}
|
||||
fc_shaderCacheGeneric->UseCompression(false);
|
||||
s_shaderCacheGeneric->UseCompression(false);
|
||||
|
||||
// load/compile cached shaders
|
||||
sint32 entryCount = fc_shaderCacheGeneric->GetMaximumFileIndex();
|
||||
g_shaderCacheLoaderState.shaderFileCount = fc_shaderCacheGeneric->GetFileCount();
|
||||
sint32 entryCount = s_shaderCacheGeneric->GetMaximumFileIndex();
|
||||
g_shaderCacheLoaderState.shaderFileCount = s_shaderCacheGeneric->GetFileCount();
|
||||
g_shaderCacheLoaderState.loadedShaderFiles = 0;
|
||||
|
||||
// get game background loading image
|
||||
|
@ -304,13 +304,13 @@ void LatteShaderCache_load()
|
|||
|
||||
auto LoadShadersUpdate = [&]() -> bool
|
||||
{
|
||||
if (loadIndex >= (uint32)fc_shaderCacheGeneric->GetMaximumFileIndex())
|
||||
if (loadIndex >= (uint32)s_shaderCacheGeneric->GetMaximumFileIndex())
|
||||
return false;
|
||||
LatteShaderCache_updateCompileQueue(SHADER_CACHE_COMPILE_QUEUE_SIZE - 2);
|
||||
uint64 name1;
|
||||
uint64 name2;
|
||||
std::vector<uint8> fileData;
|
||||
if (!fc_shaderCacheGeneric->GetFileByIndex(loadIndex, &name1, &name2, fileData))
|
||||
if (!s_shaderCacheGeneric->GetFileByIndex(loadIndex, &name1, &name2, fileData))
|
||||
{
|
||||
loadIndex++;
|
||||
return true;
|
||||
|
@ -320,7 +320,7 @@ void LatteShaderCache_load()
|
|||
{
|
||||
// something is wrong with the stored shader, remove entry from shader cache files
|
||||
cemuLog_log(LogType::Force, "Shader cache entry {} invalid, deleting...", loadIndex);
|
||||
fc_shaderCacheGeneric->DeleteFile({ name1, name2 });
|
||||
s_shaderCacheGeneric->DeleteFile({name1, name2 });
|
||||
}
|
||||
numLoadedShaders++;
|
||||
loadIndex++;
|
||||
|
@ -343,7 +343,7 @@ void LatteShaderCache_load()
|
|||
LatteShaderCache_finish();
|
||||
// if Vulkan then also load pipeline cache
|
||||
if (g_renderer->GetType() == RendererAPI::Vulkan)
|
||||
LatteShaderCache_loadVulkanPipelineCache(cacheTitleId);
|
||||
LatteShaderCache_LoadVulkanPipelineCache(cacheTitleId);
|
||||
|
||||
|
||||
g_renderer->BeginFrame(true);
|
||||
|
@ -376,6 +376,8 @@ void LatteShaderCache_ShowProgress(const std::function <bool(void)>& loadUpdateF
|
|||
|
||||
while (true)
|
||||
{
|
||||
if (Latte_GetStopSignal())
|
||||
break; // thread stop requested, cancel shader loading
|
||||
bool r = loadUpdateFunc();
|
||||
if (!r)
|
||||
break;
|
||||
|
@ -496,13 +498,15 @@ void LatteShaderCache_ShowProgress(const std::function <bool(void)>& loadUpdateF
|
|||
}
|
||||
}
|
||||
|
||||
void LatteShaderCache_loadVulkanPipelineCache(uint64 cacheTitleId)
|
||||
void LatteShaderCache_LoadVulkanPipelineCache(uint64 cacheTitleId)
|
||||
{
|
||||
auto& pipelineCache = VulkanPipelineStableCache::GetInstance();
|
||||
g_shaderCacheLoaderState.pipelineFileCount = pipelineCache.BeginLoading(cacheTitleId);
|
||||
g_shaderCacheLoaderState.loadedPipelines = 0;
|
||||
LatteShaderCache_ShowProgress(LatteShaderCache_updatePipelineLoadingProgress, true);
|
||||
pipelineCache.EndLoading();
|
||||
if(Latte_GetStopSignal())
|
||||
LatteThread_Exit();
|
||||
}
|
||||
|
||||
bool LatteShaderCache_updatePipelineLoadingProgress()
|
||||
|
@ -520,7 +524,7 @@ uint64 LatteShaderCache_getShaderNameInTransferableCache(uint64 baseHash, uint32
|
|||
|
||||
void LatteShaderCache_writeSeparableVertexShader(uint64 shaderBaseHash, uint64 shaderAuxHash, uint8* fetchShader, uint32 fetchShaderSize, uint8* vertexShader, uint32 vertexShaderSize, uint32* contextRegisters, bool usesGeometryShader)
|
||||
{
|
||||
if (!fc_shaderCacheGeneric)
|
||||
if (!s_shaderCacheGeneric)
|
||||
return;
|
||||
MemStreamWriter streamWriter(128 * 1024);
|
||||
// header
|
||||
|
@ -539,12 +543,12 @@ void LatteShaderCache_writeSeparableVertexShader(uint64 shaderBaseHash, uint64 s
|
|||
// write to cache
|
||||
uint64 shaderCacheName = LatteShaderCache_getShaderNameInTransferableCache(shaderBaseHash, SHADER_CACHE_TYPE_VERTEX);
|
||||
std::span<uint8> dataBlob = streamWriter.getResult();
|
||||
fc_shaderCacheGeneric->AddFileAsync({ shaderCacheName, shaderAuxHash }, dataBlob.data(), dataBlob.size());
|
||||
s_shaderCacheGeneric->AddFileAsync({shaderCacheName, shaderAuxHash }, dataBlob.data(), dataBlob.size());
|
||||
}
|
||||
|
||||
void LatteShaderCache_writeSeparableGeometryShader(uint64 shaderBaseHash, uint64 shaderAuxHash, uint8* geometryShader, uint32 geometryShaderSize, uint8* gsCopyShader, uint32 gsCopyShaderSize, uint32* contextRegisters, uint32* hleSpecialState, uint32 vsRingParameterCount)
|
||||
{
|
||||
if (!fc_shaderCacheGeneric)
|
||||
if (!s_shaderCacheGeneric)
|
||||
return;
|
||||
MemStreamWriter streamWriter(128 * 1024);
|
||||
// header
|
||||
|
@ -564,12 +568,12 @@ void LatteShaderCache_writeSeparableGeometryShader(uint64 shaderBaseHash, uint64
|
|||
// write to cache
|
||||
uint64 shaderCacheName = LatteShaderCache_getShaderNameInTransferableCache(shaderBaseHash, SHADER_CACHE_TYPE_GEOMETRY);
|
||||
std::span<uint8> dataBlob = streamWriter.getResult();
|
||||
fc_shaderCacheGeneric->AddFileAsync({ shaderCacheName, shaderAuxHash }, dataBlob.data(), dataBlob.size());
|
||||
s_shaderCacheGeneric->AddFileAsync({shaderCacheName, shaderAuxHash }, dataBlob.data(), dataBlob.size());
|
||||
}
|
||||
|
||||
void LatteShaderCache_writeSeparablePixelShader(uint64 shaderBaseHash, uint64 shaderAuxHash, uint8* pixelShader, uint32 pixelShaderSize, uint32* contextRegisters, bool usesGeometryShader)
|
||||
{
|
||||
if (!fc_shaderCacheGeneric)
|
||||
if (!s_shaderCacheGeneric)
|
||||
return;
|
||||
MemStreamWriter streamWriter(128 * 1024);
|
||||
streamWriter.writeBE<uint8>(1 | (SHADER_CACHE_TYPE_PIXEL << 4)); // version and type (shared field)
|
||||
|
@ -585,7 +589,7 @@ void LatteShaderCache_writeSeparablePixelShader(uint64 shaderBaseHash, uint64 sh
|
|||
// write to cache
|
||||
uint64 shaderCacheName = LatteShaderCache_getShaderNameInTransferableCache(shaderBaseHash, SHADER_CACHE_TYPE_PIXEL);
|
||||
std::span<uint8> dataBlob = streamWriter.getResult();
|
||||
fc_shaderCacheGeneric->AddFileAsync({ shaderCacheName, shaderAuxHash }, dataBlob.data(), dataBlob.size());
|
||||
s_shaderCacheGeneric->AddFileAsync({shaderCacheName, shaderAuxHash }, dataBlob.data(), dataBlob.size());
|
||||
}
|
||||
|
||||
void LatteShaderCache_loadOrCompileSeparableShader(LatteDecompilerShader* shader, uint64 shaderBaseHash, uint64 shaderAuxHash)
|
||||
|
@ -759,6 +763,23 @@ bool LatteShaderCache_readSeparableShader(uint8* shaderInfoData, sint32 shaderIn
|
|||
return false;
|
||||
}
|
||||
|
||||
void LatteShaderCache_Close()
|
||||
{
|
||||
if(s_shaderCacheGeneric)
|
||||
{
|
||||
delete s_shaderCacheGeneric;
|
||||
s_shaderCacheGeneric = nullptr;
|
||||
}
|
||||
if (g_renderer->GetType() == RendererAPI::Vulkan)
|
||||
RendererShaderVk::ShaderCacheLoading_Close();
|
||||
else if (g_renderer->GetType() == RendererAPI::OpenGL)
|
||||
RendererShaderGL::ShaderCacheLoading_Close();
|
||||
|
||||
// if Vulkan then also close pipeline cache
|
||||
if (g_renderer->GetType() == RendererAPI::Vulkan)
|
||||
VulkanPipelineStableCache::GetInstance().Close();
|
||||
}
|
||||
|
||||
#include <wx/msgdlg.h>
|
||||
|
||||
void LatteShaderCache_handleDeprecatedCacheFiles(fs::path pathGeneric, fs::path pathGenericPre1_25_0, fs::path pathGenericPre1_16_0)
|
||||
|
|
|
@ -183,9 +183,8 @@ int Latte_ThreadEntry()
|
|||
|
||||
// before doing anything with game specific shaders, we need to wait for graphic packs to finish loading
|
||||
GraphicPack2::WaitUntilReady();
|
||||
// load/init shader cache file
|
||||
LatteShaderCache_load();
|
||||
|
||||
// load disk shader cache
|
||||
LatteShaderCache_Load();
|
||||
// init registers
|
||||
Latte_LoadInitialRegisters();
|
||||
// let CPU thread know the GPU is done initializing
|
||||
|
@ -196,7 +195,7 @@ int Latte_ThreadEntry()
|
|||
std::this_thread::yield();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
LatteThread_HandleOSScreen();
|
||||
if (!Latte_IsActive())
|
||||
if (Latte_GetStopSignal())
|
||||
LatteThread_Exit();
|
||||
}
|
||||
gxRingBufferReadPtr = gx2WriteGatherPipe.gxRingBuffer;
|
||||
|
@ -232,20 +231,24 @@ void Latte_Stop()
|
|||
sLatteThread.join();
|
||||
}
|
||||
|
||||
bool Latte_IsActive()
|
||||
bool Latte_GetStopSignal()
|
||||
{
|
||||
return sLatteThreadRunning;
|
||||
return !sLatteThreadRunning;
|
||||
}
|
||||
|
||||
void LatteThread_Exit()
|
||||
{
|
||||
if (g_renderer)
|
||||
g_renderer->Shutdown();
|
||||
// clean up vertex/uniform cache
|
||||
LatteBufferCache_UnloadAll();
|
||||
// clean up texture cache
|
||||
LatteTC_UnloadAllTextures();
|
||||
// clean up runtime shader cache
|
||||
// todo
|
||||
// destroy renderer but make sure that g_renderer remains valid until the destructor has finished
|
||||
LatteSHRC_UnloadAll();
|
||||
// close disk cache
|
||||
LatteShaderCache_Close();
|
||||
// destroy renderer but make sure that g_renderer remains valid until the destructor has finished
|
||||
if (g_renderer)
|
||||
{
|
||||
Renderer* renderer = g_renderer.get();
|
||||
|
|
|
@ -13,7 +13,7 @@ bool s_isLoadingShaders{false};
|
|||
|
||||
bool RendererShaderGL::loadBinary()
|
||||
{
|
||||
if (!g_programBinaryCache)
|
||||
if (!s_programBinaryCache)
|
||||
return false;
|
||||
if (m_isGameShader == false || m_isGfxPackShader)
|
||||
return false; // only non-custom
|
||||
|
@ -25,7 +25,7 @@ bool RendererShaderGL::loadBinary()
|
|||
GenerateShaderPrecompiledCacheFilename(m_type, m_baseHash, m_auxHash, h1, h2);
|
||||
sint32 fileSize = 0;
|
||||
std::vector<uint8> cacheFileData;
|
||||
if (!g_programBinaryCache->GetFile({ h1, h2 }, cacheFileData))
|
||||
if (!s_programBinaryCache->GetFile({h1, h2 }, cacheFileData))
|
||||
return false;
|
||||
if (fileSize < sizeof(uint32))
|
||||
{
|
||||
|
@ -51,7 +51,7 @@ bool RendererShaderGL::loadBinary()
|
|||
|
||||
void RendererShaderGL::storeBinary()
|
||||
{
|
||||
if (!g_programBinaryCache)
|
||||
if (!s_programBinaryCache)
|
||||
return;
|
||||
if (!glGetProgramBinary)
|
||||
return;
|
||||
|
@ -72,7 +72,7 @@ void RendererShaderGL::storeBinary()
|
|||
glGetProgramBinary(m_program, binaryLength, NULL, &binaryFormat, storedBinary.data()+sizeof(uint32));
|
||||
*(uint32*)(storedBinary.data() + 0) = binaryFormat;
|
||||
// store
|
||||
g_programBinaryCache->AddFileAsync({ h1, h2 }, storedBinary.data(), storedBinary.size());
|
||||
s_programBinaryCache->AddFileAsync({h1, h2 }, storedBinary.data(), storedBinary.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -247,12 +247,7 @@ void RendererShaderGL::SetUniform4iv(sint32 location, void* data, sint32 count)
|
|||
|
||||
void RendererShaderGL::ShaderCacheLoading_begin(uint64 cacheTitleId)
|
||||
{
|
||||
if (g_programBinaryCache)
|
||||
{
|
||||
delete g_programBinaryCache;
|
||||
g_programBinaryCache = nullptr;
|
||||
}
|
||||
|
||||
cemu_assert_debug(!s_programBinaryCache); // should not be set, ShaderCacheLoading_Close() not called?
|
||||
// determine if cache is enabled
|
||||
bool usePrecompiled = false;
|
||||
switch (ActiveSettings::GetPrecompiledShadersOption())
|
||||
|
@ -279,9 +274,8 @@ void RendererShaderGL::ShaderCacheLoading_begin(uint64 cacheTitleId)
|
|||
{
|
||||
const uint32 cacheMagic = GeneratePrecompiledCacheId();
|
||||
const std::string cacheFilename = fmt::format("{:016x}_gl.bin", cacheTitleId);
|
||||
const std::wstring cachePath = ActiveSettings::GetCachePath("shaderCache/precompiled/{}", cacheFilename).generic_wstring();
|
||||
g_programBinaryCache = FileCache::Open(cachePath, true, cacheMagic);
|
||||
if (g_programBinaryCache == nullptr)
|
||||
s_programBinaryCache = FileCache::Open(ActiveSettings::GetCachePath("shaderCache/precompiled/{}", cacheFilename), true, cacheMagic);
|
||||
if (s_programBinaryCache == nullptr)
|
||||
cemuLog_log(LogType::Force, "Unable to open OpenGL precompiled cache {}", cacheFilename);
|
||||
}
|
||||
s_isLoadingShaders = true;
|
||||
|
@ -292,4 +286,15 @@ void RendererShaderGL::ShaderCacheLoading_end()
|
|||
s_isLoadingShaders = false;
|
||||
}
|
||||
|
||||
FileCache* RendererShaderGL::g_programBinaryCache{};
|
||||
void RendererShaderGL::ShaderCacheLoading_Close()
|
||||
{
|
||||
if(s_programBinaryCache)
|
||||
{
|
||||
delete s_programBinaryCache;
|
||||
s_programBinaryCache = nullptr;
|
||||
}
|
||||
g_compiled_shaders_total = 0;
|
||||
g_compiled_shaders_async = 0;
|
||||
}
|
||||
|
||||
FileCache* RendererShaderGL::s_programBinaryCache{};
|
||||
|
|
|
@ -24,6 +24,7 @@ public:
|
|||
|
||||
static void ShaderCacheLoading_begin(uint64 cacheTitleId);
|
||||
static void ShaderCacheLoading_end();
|
||||
static void ShaderCacheLoading_Close();
|
||||
|
||||
private:
|
||||
GLuint m_program;
|
||||
|
@ -37,6 +38,6 @@ private:
|
|||
bool m_shader_attached{ false };
|
||||
bool m_isCompiled{ false };
|
||||
|
||||
static class FileCache* g_programBinaryCache;
|
||||
static class FileCache* s_programBinaryCache;
|
||||
};
|
||||
|
||||
|
|
|
@ -62,6 +62,7 @@ void Renderer::Shutdown()
|
|||
// imgui
|
||||
ImGui::DestroyContext(imguiTVContext);
|
||||
ImGui::DestroyContext(imguiPadContext);
|
||||
ImGui_ClearFonts();
|
||||
delete imguiFontAtlas;
|
||||
}
|
||||
|
||||
|
|
|
@ -451,3 +451,9 @@ void RendererShaderVk::ShaderCacheLoading_end()
|
|||
// keep g_spirvCache open since we will write to it while the game is running
|
||||
s_isLoadingShadersVk = false;
|
||||
}
|
||||
|
||||
void RendererShaderVk::ShaderCacheLoading_Close()
|
||||
{
|
||||
delete s_spirvCache;
|
||||
s_spirvCache = nullptr;
|
||||
}
|
|
@ -22,7 +22,8 @@ class RendererShaderVk : public RendererShader
|
|||
|
||||
public:
|
||||
static void ShaderCacheLoading_begin(uint64 cacheTitleId);
|
||||
static void ShaderCacheLoading_end();
|
||||
static void ShaderCacheLoading_end();
|
||||
static void ShaderCacheLoading_Close();
|
||||
|
||||
RendererShaderVk(ShaderType type, uint64 baseHash, uint64 auxHash, bool isGameShader, bool isGfxPackShader, const std::string& glslCode);
|
||||
virtual ~RendererShaderVk();
|
||||
|
|
|
@ -117,6 +117,15 @@ void VulkanPipelineStableCache::EndLoading()
|
|||
// keep cache file open for writing of new pipelines
|
||||
}
|
||||
|
||||
void VulkanPipelineStableCache::Close()
|
||||
{
|
||||
if(s_cache)
|
||||
{
|
||||
delete s_cache;
|
||||
s_cache = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
struct CachedPipeline
|
||||
{
|
||||
struct ShaderHash
|
||||
|
|
|
@ -41,6 +41,7 @@ public:
|
|||
bool UpdateLoading(uint32& pipelinesLoadedTotal, uint32& pipelinesMissingShaders);
|
||||
void EndLoading();
|
||||
void LoadPipelineFromCache(std::span<uint8> fileData);
|
||||
void Close(); // called on title exit
|
||||
|
||||
bool HasPipelineCached(uint64 baseHash, uint64 pipelineStateHash);
|
||||
void AddCurrentStateToCache(uint64 baseHash, uint64 pipelineStateHash);
|
||||
|
|
|
@ -103,7 +103,7 @@ void MMURange::mapMem()
|
|||
|
||||
void MMURange::unmapMem()
|
||||
{
|
||||
cemu_assert_debug(false);
|
||||
MemMapper::FreeMemory(memory_base + baseAddress, size, true);
|
||||
m_isMapped = false;
|
||||
}
|
||||
|
||||
|
@ -196,6 +196,15 @@ void memory_mapForCurrentTitle()
|
|||
}
|
||||
}
|
||||
|
||||
void memory_unmapForCurrentTitle()
|
||||
{
|
||||
for (auto& itr : g_mmuRanges)
|
||||
{
|
||||
if (itr->isMapped() && !itr->isMappedEarly())
|
||||
itr->unmapMem();
|
||||
}
|
||||
}
|
||||
|
||||
void memory_logModifiedMemoryRanges()
|
||||
{
|
||||
auto gfxPackMappings = GraphicPack2::GetActiveRAMMappings();
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
void memory_init();
|
||||
void memory_mapForCurrentTitle();
|
||||
void memory_unmapForCurrentTitle();
|
||||
void memory_logModifiedMemoryRanges();
|
||||
|
||||
void memory_enableOverlayArena();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue