mirror of
https://github.com/cemu-project/Cemu.git
synced 2025-07-07 23:41:18 +12:00
cache output shaders
This commit is contained in:
parent
b088ddcfab
commit
28e553eb1a
5 changed files with 77 additions and 14 deletions
38
src/Cafe/HW/Latte/Renderer/Metal/MetalOutputShaderCache.cpp
Normal file
38
src/Cafe/HW/Latte/Renderer/Metal/MetalOutputShaderCache.cpp
Normal file
|
@ -0,0 +1,38 @@
|
|||
#include "Cafe/HW/Latte/Renderer/Metal/MetalOutputShaderCache.h"
|
||||
#include "Cafe/HW/Latte/Renderer/Metal/RendererShaderMtl.h"
|
||||
|
||||
MetalOutputShaderCache::~MetalOutputShaderCache()
|
||||
{
|
||||
for (uint8 i = 0; i < METAL_OUTPUT_SHADER_CACHE_SIZE; i++)
|
||||
{
|
||||
if (m_cache[i])
|
||||
m_cache[i]->release();
|
||||
}
|
||||
}
|
||||
|
||||
MTL::RenderPipelineState* MetalOutputShaderCache::GetPipeline(RendererOutputShader* shader, uint8 shaderIndex, bool usesSRGB)
|
||||
{
|
||||
uint8 cacheIndex = (usesSRGB ? METAL_SHADER_TYPE_COUNT : 0) + shaderIndex;
|
||||
auto& renderPipelineState = m_cache[cacheIndex];
|
||||
if (renderPipelineState)
|
||||
return renderPipelineState;
|
||||
|
||||
// Create a new render pipeline state
|
||||
auto vertexShaderMtl = static_cast<RendererShaderMtl*>(shader->GetVertexShader())->GetFunction();
|
||||
auto fragmentShaderMtl = static_cast<RendererShaderMtl*>(shader->GetFragmentShader())->GetFunction();
|
||||
|
||||
auto renderPipelineDescriptor = MTL::RenderPipelineDescriptor::alloc()->init();
|
||||
renderPipelineDescriptor->setVertexFunction(vertexShaderMtl);
|
||||
renderPipelineDescriptor->setFragmentFunction(fragmentShaderMtl);
|
||||
renderPipelineDescriptor->colorAttachments()->object(0)->setPixelFormat(usesSRGB ? MTL::PixelFormatBGRA8Unorm_sRGB : MTL::PixelFormatBGRA8Unorm);
|
||||
|
||||
NS::Error* error = nullptr;
|
||||
renderPipelineState = m_mtlr->GetDevice()->newRenderPipelineState(renderPipelineDescriptor, &error);
|
||||
if (error)
|
||||
{
|
||||
cemuLog_log(LogType::Force, "error creating output render pipeline state: {}", error->localizedDescription()->utf8String());
|
||||
error->release();
|
||||
}
|
||||
|
||||
return renderPipelineState;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue