From 15cfb3570cbd0209d1c4c85ec8f9b87cf7d882d5 Mon Sep 17 00:00:00 2001 From: Alex Cristici Date: Wed, 15 Nov 2023 17:36:21 +0200 Subject: [PATCH] Fixed metal vertex attribute update render tests (#1867) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- include/mbgl/mtl/vertex_attribute.hpp | 3 +++ src/mbgl/mtl/drawable_impl.hpp | 4 ++-- src/mbgl/mtl/vertex_attribute.cpp | 13 +++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/include/mbgl/mtl/vertex_attribute.hpp b/include/mbgl/mtl/vertex_attribute.hpp index 0658b8253..6ec027e5c 100644 --- a/include/mbgl/mtl/vertex_attribute.hpp +++ b/include/mbgl/mtl/vertex_attribute.hpp @@ -56,6 +56,9 @@ public: return newAttrs; } + /// Indicates whether any values have changed + bool isDirty() const override; + private: gfx::UniqueVertexAttribute create(int index, gfx::AttributeDataType dataType, std::size_t count) const override { return gfx::UniqueVertexAttribute(new VertexAttribute(index, dataType, count)); diff --git a/src/mbgl/mtl/drawable_impl.hpp b/src/mbgl/mtl/drawable_impl.hpp index ad141d586..42ba332b6 100644 --- a/src/mbgl/mtl/drawable_impl.hpp +++ b/src/mbgl/mtl/drawable_impl.hpp @@ -6,11 +6,11 @@ #include #include #include -#include #include #include #include #include +#include #include #include #include @@ -44,7 +44,7 @@ public: gfx::IndexVectorBasePtr indexes; std::size_t vertexCount = 0; gfx::AttributeDataType vertexType = gfx::AttributeDataType::Invalid; - gfx::VertexAttributeArray vertexAttributes; + VertexAttributeArray vertexAttributes; std::vector attributeBuffers; diff --git a/src/mbgl/mtl/vertex_attribute.cpp b/src/mbgl/mtl/vertex_attribute.cpp index d904393cb..b7647fccd 100644 --- a/src/mbgl/mtl/vertex_attribute.cpp +++ b/src/mbgl/mtl/vertex_attribute.cpp @@ -33,5 +33,18 @@ const gfx::UniqueVertexBufferResource& VertexAttribute::getBuffer(gfx::VertexAtt return attrib_.getBuffer(); } +bool VertexAttributeArray::isDirty() const { + return std::any_of(attrs.begin(), attrs.end(), [](const auto& kv) { + if (kv.second) { + // If we have shared data, the dirty flag from that overrides ours + const auto& attrib = static_cast(*kv.second); + if (const auto& shared = attrib.getSharedRawData()) { + return shared->getDirty(); + } + } + return kv.second && kv.second->isDirty(); + }); +} + } // namespace mtl } // namespace mbgl