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

@@ -18,6 +18,7 @@
#include <mbgl/shaders/mtl/shader_program.hpp>
#include <mbgl/util/logging.hpp>
#include <mbgl/util/variant.hpp>
#include <mbgl/util/hash.hpp>
#include <Metal/Metal.hpp>
@@ -210,7 +211,11 @@ void Drawable::draw(PaintParameters& parameters) const {
encoder->setFrontFacingWinding(mapWindingMode(cullMode.winding));
if (!impl->pipelineState) {
impl->pipelineState = shaderMTL.getRenderPipelineState(renderable, impl->vertexDesc, getColorMode());
impl->pipelineState = shaderMTL.getRenderPipelineState(
renderable,
impl->vertexDesc,
getColorMode(),
mbgl::util::hash(getColorMode().hash(), impl->vertexDescHash));
}
if (impl->pipelineState) {
encoder->setRenderPipelineState(impl->pipelineState.get());
@@ -563,6 +568,9 @@ void Drawable::upload(gfx::UploadPass& uploadPass_) {
if (impl->attributeBindings != attributeBindings_) {
impl->attributeBindings = std::move(attributeBindings_);
// hash
std::size_t hash{0};
// Create a layout descriptor for each attribute
auto vertDesc = NS::RetainPtr(MTL::VertexDescriptor::vertexDescriptor());
@@ -595,10 +603,18 @@ void Drawable::upload(gfx::UploadPass& uploadPass_) {
vertDesc->attributes()->setObject(attribDesc.get(), index);
vertDesc->layouts()->setObject(layoutDesc.get(), index);
mbgl::util::hash_combine(hash,
mbgl::util::hash(index,
binding->attribute.offset,
binding->attribute.dataType,
binding->vertexStride,
static_cast<bool>(binding->vertexBufferResource)));
index += 1;
}
impl->vertexDesc = std::move(vertDesc);
impl->vertexDescHash = hash;
impl->pipelineState.reset();
}
}