Fix Metal frame glitch on older devices (#2379)

This commit is contained in:
Stefan Karschti
2024-05-15 15:30:28 +03:00
committed by GitHub
parent 8e479eea96
commit aff5693fb9
6 changed files with 57 additions and 4 deletions

View File

@@ -83,7 +83,14 @@ ShaderProgram::~ShaderProgram() noexcept = default;
MTLRenderPipelineStatePtr ShaderProgram::getRenderPipelineState(const gfx::Renderable& renderable,
const MTLVertexDescriptorPtr& vertexDescriptor,
const gfx::ColorMode& colorMode) const {
const gfx::ColorMode& colorMode,
const std::optional<std::size_t> reuseHash) const {
if (reuseHash.has_value()) {
// we'd like to reuse a previous value
if (auto it = renderPipelineStateCache.find(reuseHash.value()); it != renderPipelineStateCache.end())
return it->second;
}
auto pool = NS::TransferPtr(NS::AutoreleasePool::alloc()->init());
const auto& renderableResource = renderable.getResource<RenderableResource>();
@@ -165,6 +172,11 @@ MTLRenderPipelineStatePtr ShaderProgram::getRenderPipelineState(const gfx::Rende
assert(false);
}
if (reuseHash.has_value()) {
// store the value for future reuse
renderPipelineStateCache[reuseHash.value()] = rps;
}
return rps;
}