Skip to content

Commit

Permalink
don't compile certain pipelines async
Browse files Browse the repository at this point in the history
  • Loading branch information
SamoZ256 committed Oct 28, 2024
1 parent 4e3f94e commit 7906733
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
25 changes: 21 additions & 4 deletions src/Cafe/HW/Latte/Renderer/Metal/MetalPipelineCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,23 @@ static void queuePipeline(MetalPipelineCompiler* v)
g_compilePipelineCondVar.notify_one();
}

// make a guess if a pipeline is not essential
// non-essential means that skipping these drawcalls shouldn't lead to permanently corrupted graphics
bool IsAsyncPipelineAllowed(const MetalAttachmentsInfo& attachmentsInfo, Vector2i extend, uint32 indexCount)
{
if (extend.x == 1600 && extend.y == 1600)
return false; // Splatoon ink mechanics use 1600x1600 R8 and R8G8 framebuffers, this resolution is rare enough that we can just blacklist it globally

if (attachmentsInfo.depthFormat != Latte::E_GX2SURFFMT::INVALID_FORMAT)
return true; // aggressive filter but seems to work well so far

// small index count (3,4,5,6) is often associated with full-viewport quads (which are considered essential due to often being used to generate persistent textures)
if (indexCount <= 6)
return false;

return true;
}

MetalPipelineCache* g_mtlPipelineCache = nullptr;

MetalPipelineCache& MetalPipelineCache::GetInstance()
Expand All @@ -94,7 +111,7 @@ MetalPipelineCache::~MetalPipelineCache()
}
}

PipelineObject* MetalPipelineCache::GetRenderPipelineState(const LatteFetchShader* fetchShader, const LatteDecompilerShader* vertexShader, const LatteDecompilerShader* geometryShader, const LatteDecompilerShader* pixelShader, const MetalAttachmentsInfo& lastUsedAttachmentsInfo, const MetalAttachmentsInfo& activeAttachmentsInfo, const LatteContextRegister& lcr)
PipelineObject* MetalPipelineCache::GetRenderPipelineState(const LatteFetchShader* fetchShader, const LatteDecompilerShader* vertexShader, const LatteDecompilerShader* geometryShader, const LatteDecompilerShader* pixelShader, const MetalAttachmentsInfo& lastUsedAttachmentsInfo, const MetalAttachmentsInfo& activeAttachmentsInfo, Vector2i extend, uint32 indexCount, const LatteContextRegister& lcr)
{
uint64 hash = CalculatePipelineHash(fetchShader, vertexShader, geometryShader, pixelShader, lastUsedAttachmentsInfo, activeAttachmentsInfo, lcr);
PipelineObject*& pipelineObj = m_pipelineCache[hash];
Expand All @@ -108,9 +125,8 @@ PipelineObject* MetalPipelineCache::GetRenderPipelineState(const LatteFetchShade
compiler->InitFromState(fetchShader, vertexShader, geometryShader, pixelShader, lastUsedAttachmentsInfo, activeAttachmentsInfo, lcr, fbosMatch);

bool allowAsyncCompile = false;
// TODO: uncomment
if (GetConfig().async_compile)
allowAsyncCompile = true;//IsAsyncPipelineAllowed(indexCount);
allowAsyncCompile = IsAsyncPipelineAllowed(activeAttachmentsInfo, extend, indexCount);

if (allowAsyncCompile)
{
Expand All @@ -124,7 +140,8 @@ PipelineObject* MetalPipelineCache::GetRenderPipelineState(const LatteFetchShade
}
else
{
compiler->Compile(false, true, true);
// Also force compile to ensure that the pipeline is ready
cemu_assert_debug(compiler->Compile(true, true, true));
delete compiler;
}

Expand Down
3 changes: 2 additions & 1 deletion src/Cafe/HW/Latte/Renderer/Metal/MetalPipelineCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "Cafe/HW/Latte/Renderer/Metal/MetalPipelineCompiler.h"
#include "util/helpers/ConcurrentQueue.h"
#include "util/helpers/fspinlock.h"
#include "util/math/vector2.h"

class MetalPipelineCache
{
Expand All @@ -12,7 +13,7 @@ class MetalPipelineCache
MetalPipelineCache(class MetalRenderer* metalRenderer);
~MetalPipelineCache();

PipelineObject* GetRenderPipelineState(const LatteFetchShader* fetchShader, const LatteDecompilerShader* vertexShader, const LatteDecompilerShader* geometryShader, const LatteDecompilerShader* pixelShader, const class MetalAttachmentsInfo& lastUsedAttachmentsInfo, const class MetalAttachmentsInfo& activeAttachmentsInfo, const LatteContextRegister& lcr);
PipelineObject* GetRenderPipelineState(const LatteFetchShader* fetchShader, const LatteDecompilerShader* vertexShader, const LatteDecompilerShader* geometryShader, const LatteDecompilerShader* pixelShader, const class MetalAttachmentsInfo& lastUsedAttachmentsInfo, const class MetalAttachmentsInfo& activeAttachmentsInfo, Vector2i extend, uint32 indexCount, const LatteContextRegister& lcr);

// Cache loading
uint32 BeginLoading(uint64 cacheTitleId); // returns count of pipelines stored in cache
Expand Down
2 changes: 1 addition & 1 deletion src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ void MetalRenderer::draw_execute(uint32 baseVertex, uint32 baseInstance, uint32
auto renderCommandEncoder = GetRenderCommandEncoder();

// Render pipeline state
PipelineObject* pipelineObj = m_pipelineCache->GetRenderPipelineState(fetchShader, vertexShader, geometryShader, pixelShader, m_state.m_lastUsedFBO.m_attachmentsInfo, m_state.m_activeFBO.m_attachmentsInfo, LatteGPUState.contextNew);
PipelineObject* pipelineObj = m_pipelineCache->GetRenderPipelineState(fetchShader, vertexShader, geometryShader, pixelShader, m_state.m_lastUsedFBO.m_attachmentsInfo, m_state.m_activeFBO.m_attachmentsInfo, m_state.m_activeFBO.m_fbo->m_size, count, LatteGPUState.contextNew);
if (!pipelineObj->m_pipeline)
return;

Expand Down

0 comments on commit 7906733

Please sign in to comment.