diff --git a/include/mbgl/renderer/renderer.hpp b/include/mbgl/renderer/renderer.hpp index 4d2e7936376..71771b9828c 100644 --- a/include/mbgl/renderer/renderer.hpp +++ b/include/mbgl/renderer/renderer.hpp @@ -113,10 +113,6 @@ class Renderer { void reduceMemoryUse(); void clearData(); -#if MLN_RENDER_BACKEND_OPENGL - void enableAndroidEmulatorGoldfishMitigation(bool enable); -#endif - private: class Impl; std::unique_ptr impl; diff --git a/platform/android/MapLibreAndroid/src/cpp/map_renderer.cpp b/platform/android/MapLibreAndroid/src/cpp/map_renderer.cpp index 9fd889e05ef..fc235a67f4c 100644 --- a/platform/android/MapLibreAndroid/src/cpp/map_renderer.cpp +++ b/platform/android/MapLibreAndroid/src/cpp/map_renderer.cpp @@ -13,27 +13,6 @@ #include "android_renderer_backend.hpp" #include "map_renderer_runnable.hpp" -#if MLN_RENDER_BACKEND_OPENGL -#include - -namespace { -std::string androidSysProp(const char* key) { - assert(strlen(key) < PROP_NAME_MAX); - if (__system_property_find(key) == nullptr) { - return ""; - } - char prop[PROP_VALUE_MAX + 1]; - __system_property_get(key, prop); - return prop; -} - -bool inEmulator() { - return androidSysProp("ro.kernel.qemu") == "1" || androidSysProp("ro.boot.qemu") == "1" || - androidSysProp("ro.hardware.egl") == "emulation"; -} -} // namespace -#endif - namespace mbgl { namespace android { @@ -253,14 +232,6 @@ void MapRenderer::onSurfaceCreated(JNIEnv& env, const jni::Object(backend->getImpl(), pixelRatio, localIdeographFontFamily); rendererRef = std::make_unique>(*renderer, mailboxData.getMailbox()); -#if MLN_RENDER_BACKEND_OPENGL - // If we're running the emulator with the OpenGL backend, we're going to crash eventually, - // unless we enable this mitigation. - if (inEmulator()) { - renderer->enableAndroidEmulatorGoldfishMitigation(true); - } -#endif - backend->setSwapBehavior(swapBehaviorFlush ? gfx::Renderable::SwapBehaviour::Flush : gfx::Renderable::SwapBehaviour::NoFlush); diff --git a/src/mbgl/gfx/index_vector.hpp b/src/mbgl/gfx/index_vector.hpp index c5ba77e82e5..ed42dac7da0 100644 --- a/src/mbgl/gfx/index_vector.hpp +++ b/src/mbgl/gfx/index_vector.hpp @@ -2,7 +2,6 @@ #include #include -#include #include #include @@ -41,15 +40,8 @@ class IndexVectorBase { void setBuffer(std::unique_ptr&& value) { buffer = std::move(value); } #endif // MLN_DRAWABLE_RENDERER - std::chrono::duration getLastModified() const { return lastModified; } - bool isModifiedAfter(std::chrono::duration t) const { return t < lastModified; } - - void updateModified() { - if (dirty) { - lastModified = util::MonotonicTimer::now(); - dirty = false; - } - } + bool getDirty() const { return dirty; } + void setDirty(bool value = true) { dirty = value; } bool isReleased() const { return released; } @@ -107,8 +99,6 @@ class IndexVectorBase { #endif // MLN_DRAWABLE_RENDERER bool dirty = true; bool released = false; - - std::chrono::duration lastModified = util::MonotonicTimer::now(); }; using IndexVectorBasePtr = std::shared_ptr; diff --git a/src/mbgl/gl/drawable_gl.cpp b/src/mbgl/gl/drawable_gl.cpp index 80404029ad0..70ad47a91c2 100644 --- a/src/mbgl/gl/drawable_gl.cpp +++ b/src/mbgl/gl/drawable_gl.cpp @@ -18,7 +18,6 @@ DrawableGL::DrawableGL(std::string name_) impl(std::make_unique()) {} DrawableGL::~DrawableGL() { - impl->indexBuffer = {0, nullptr}; impl->attributeBuffers.clear(); } @@ -192,12 +191,8 @@ void DrawableGL::upload(gfx::UploadPass& uploadPass) { auto& glContext = static_cast(context); constexpr auto usage = gfx::BufferUsageType::StaticDraw; - // Create an index buffer if necessary - if (impl->indexes) { - impl->indexes->updateModified(); - } - if (impl->indexes && - (!impl->indexes->getBuffer() || !attributeUpdateTime || impl->indexes->isModifiedAfter(*attributeUpdateTime))) { + // Create an index buffer if necessary} + if (impl->indexes && (!impl->indexes->getBuffer() || impl->indexes->getDirty())) { MLN_TRACE_ZONE(build indexes); auto indexBufferResource{ uploadPass.createIndexBufferResource(impl->indexes->data(), impl->indexes->bytes(), usage)}; @@ -205,6 +200,7 @@ void DrawableGL::upload(gfx::UploadPass& uploadPass) { std::move(indexBufferResource)); auto buffer = std::make_unique(std::move(indexBuffer)); impl->indexes->setBuffer(std::move(buffer)); + impl->indexes->setDirty(false); } // Build the vertex attributes and bindings, if necessary diff --git a/src/mbgl/gl/drawable_gl_impl.hpp b/src/mbgl/gl/drawable_gl_impl.hpp index 37bf3f8a31b..787c5289611 100644 --- a/src/mbgl/gl/drawable_gl_impl.hpp +++ b/src/mbgl/gl/drawable_gl_impl.hpp @@ -39,8 +39,6 @@ class DrawableGL::Impl final { gfx::AttributeDataType vertexType = static_cast(-1); AttributeBindingArray attributeBindings; - - gfx::IndexBuffer indexBuffer = {0, nullptr}; std::vector attributeBuffers; UniformBufferArrayGL uniformBuffers; diff --git a/src/mbgl/mtl/drawable.cpp b/src/mbgl/mtl/drawable.cpp index 90caacc9bdb..ce8a7d800cd 100644 --- a/src/mbgl/mtl/drawable.cpp +++ b/src/mbgl/mtl/drawable.cpp @@ -191,13 +191,13 @@ void Drawable::draw(PaintParameters& parameters) const { bindUniformBuffers(renderPass); bindTextures(renderPass); - if (!impl->indexes->getBuffer() || !attributeUpdateTime || impl->indexes->isModifiedAfter(*attributeUpdateTime)) { + if (!impl->indexes->getBuffer() || impl->indexes->getDirty()) { assert(!"Index buffer not uploaded"); return; } const auto* indexBuffer = getMetalBuffer(impl->indexes); - if (!indexBuffer || !attributeUpdateTime || impl->indexes->isModifiedAfter(*attributeUpdateTime)) { + if (!indexBuffer || impl->indexes->getDirty()) { assert(!"Index buffer not uploaded"); return; } @@ -546,19 +546,14 @@ void Drawable::upload(gfx::UploadPass& uploadPass_) { auto& context = static_cast(contextBase); constexpr auto usage = gfx::BufferUsageType::StaticDraw; - if (impl->indexes) { - impl->indexes->updateModified(); - } - // We need either raw index data or a buffer already created from them. // We can have a buffer and no indexes, but only if it's not marked dirty. - if (!impl->indexes || (impl->indexes->empty() && (!impl->indexes->getBuffer() || !attributeUpdateTime || - impl->indexes->isModifiedAfter(*attributeUpdateTime)))) { + if (!impl->indexes || (impl->indexes->empty() && (!impl->indexes->getBuffer() || impl->indexes->getDirty()))) { assert(!"Missing index data"); return; } - if (!impl->indexes->getBuffer() || !attributeUpdateTime || impl->indexes->isModifiedAfter(*attributeUpdateTime)) { + if (!impl->indexes->getBuffer() || impl->indexes->getDirty()) { // Create or update a buffer for the index data. We don't update any // existing buffer because it may still be in use by the previous frame. auto indexBufferResource{uploadPass.createIndexBufferResource( @@ -568,6 +563,7 @@ void Drawable::upload(gfx::UploadPass& uploadPass_) { auto buffer = std::make_unique(std::move(indexBuffer)); impl->indexes->setBuffer(std::move(buffer)); + impl->indexes->setDirty(false); } const bool buildAttribs = !impl->vertexDesc || !vertexAttributes || !attributeUpdateTime || @@ -593,7 +589,6 @@ void Drawable::upload(gfx::UploadPass& uploadPass_) { usage, attributeUpdateTime, vertexBuffers); - impl->attributeBuffers = std::move(vertexBuffers); vertexAttributes->visitAttributes([](gfx::VertexAttribute& attrib) { attrib.setDirty(false); }); @@ -667,7 +662,6 @@ void Drawable::upload(gfx::UploadPass& uploadPass_) { usage, attributeUpdateTime, instanceBuffers); - impl->instanceBuffers = std::move(instanceBuffers); // clear dirty flag instanceAttributes->visitAttributes([](gfx::VertexAttribute& attrib) { attrib.setDirty(false); }); diff --git a/src/mbgl/mtl/drawable_impl.hpp b/src/mbgl/mtl/drawable_impl.hpp index 0ed0ca71714..1938050e756 100644 --- a/src/mbgl/mtl/drawable_impl.hpp +++ b/src/mbgl/mtl/drawable_impl.hpp @@ -45,10 +45,7 @@ class Drawable::Impl final { std::size_t vertexCount = 0; gfx::AttributeDataType vertexType = gfx::AttributeDataType::Invalid; - std::vector attributeBuffers; gfx::AttributeBindingArray attributeBindings; - - std::vector instanceBuffers; gfx::AttributeBindingArray instanceBindings; UniformBufferArray uniformBuffers; diff --git a/src/mbgl/mtl/upload_pass.cpp b/src/mbgl/mtl/upload_pass.cpp index f003e06142c..a4719310129 100644 --- a/src/mbgl/mtl/upload_pass.cpp +++ b/src/mbgl/mtl/upload_pass.cpp @@ -159,7 +159,7 @@ gfx::AttributeBindingArray UploadPass::buildAttributeBindings( const gfx::VertexAttributeArray& overrides, const gfx::BufferUsageType usage, const std::optional> lastUpdate, - /*out*/ std::vector>& outBuffers) { + /*out*/ std::vector>&) { MLN_TRACE_FUNC(); gfx::AttributeBindingArray bindings; diff --git a/src/mbgl/renderer/buckets/circle_bucket.cpp b/src/mbgl/renderer/buckets/circle_bucket.cpp index 378370639c1..c54cd593920 100644 --- a/src/mbgl/renderer/buckets/circle_bucket.cpp +++ b/src/mbgl/renderer/buckets/circle_bucket.cpp @@ -74,7 +74,6 @@ void CircleBucket::update(const FeatureStates& states, uploaded = false; sharedVertices->updateModified(); - sharedTriangles->updateModified(); } } diff --git a/src/mbgl/renderer/buckets/fill_bucket.cpp b/src/mbgl/renderer/buckets/fill_bucket.cpp index 88ae37f04f1..5ba1da72f52 100644 --- a/src/mbgl/renderer/buckets/fill_bucket.cpp +++ b/src/mbgl/renderer/buckets/fill_bucket.cpp @@ -113,8 +113,6 @@ void FillBucket::update(const FeatureStates& states, uploaded = false; sharedVertices->updateModified(); - sharedBasicLineIndexes->updateModified(); - sharedTriangles->updateModified(); } } diff --git a/src/mbgl/renderer/buckets/fill_extrusion_bucket.cpp b/src/mbgl/renderer/buckets/fill_extrusion_bucket.cpp index 58942cfbe8c..ae2356a9f98 100644 --- a/src/mbgl/renderer/buckets/fill_extrusion_bucket.cpp +++ b/src/mbgl/renderer/buckets/fill_extrusion_bucket.cpp @@ -206,7 +206,6 @@ void FillExtrusionBucket::update(const FeatureStates& states, uploaded = false; sharedVertices->updateModified(); - sharedTriangles->updateModified(); } } diff --git a/src/mbgl/renderer/buckets/hillshade_bucket.cpp b/src/mbgl/renderer/buckets/hillshade_bucket.cpp index dd020479a59..991fe45a16b 100644 --- a/src/mbgl/renderer/buckets/hillshade_bucket.cpp +++ b/src/mbgl/renderer/buckets/hillshade_bucket.cpp @@ -57,7 +57,6 @@ void HillshadeBucket::clear() { indices.clear(); vertices.updateModified(); - indices.updateModified(); uploaded = false; } @@ -121,7 +120,6 @@ void HillshadeBucket::setMask(TileMask&& mask_) { } vertices.updateModified(); - indices.updateModified(); } bool HillshadeBucket::hasData() const { diff --git a/src/mbgl/renderer/buckets/line_bucket.cpp b/src/mbgl/renderer/buckets/line_bucket.cpp index bf67d23bf40..f8c0198a728 100644 --- a/src/mbgl/renderer/buckets/line_bucket.cpp +++ b/src/mbgl/renderer/buckets/line_bucket.cpp @@ -168,7 +168,6 @@ void LineBucket::update(const FeatureStates& states, uploaded = false; sharedVertices->updateModified(); - sharedTriangles->updateModified(); } } diff --git a/src/mbgl/renderer/buckets/raster_bucket.cpp b/src/mbgl/renderer/buckets/raster_bucket.cpp index b7073f5df25..3ec3371e387 100644 --- a/src/mbgl/renderer/buckets/raster_bucket.cpp +++ b/src/mbgl/renderer/buckets/raster_bucket.cpp @@ -47,7 +47,6 @@ void RasterBucket::clear() { indices.clear(); vertices.updateModified(); - indices.updateModified(); uploaded = false; } @@ -118,7 +117,6 @@ void RasterBucket::setMask(TileMask&& mask_) { } vertices.updateModified(); - indices.updateModified(); } bool RasterBucket::hasData() const { diff --git a/src/mbgl/renderer/buckets/symbol_bucket.hpp b/src/mbgl/renderer/buckets/symbol_bucket.hpp index 6fdfe1041e1..9960c72fc6d 100644 --- a/src/mbgl/renderer/buckets/symbol_bucket.hpp +++ b/src/mbgl/renderer/buckets/symbol_bucket.hpp @@ -161,9 +161,6 @@ class SymbolBucket final : public Bucket { if (sharedOpacityVertices) { sharedOpacityVertices->updateModified(); } - if (sharedTriangles) { - sharedTriangles->updateModified(); - } } std::shared_ptr sharedVertices = std::make_shared(); diff --git a/src/mbgl/renderer/layers/render_heatmap_layer.hpp b/src/mbgl/renderer/layers/render_heatmap_layer.hpp index 49dec62b0a5..7f04191925b 100644 --- a/src/mbgl/renderer/layers/render_heatmap_layer.hpp +++ b/src/mbgl/renderer/layers/render_heatmap_layer.hpp @@ -33,10 +33,6 @@ class RenderHeatmapLayer final : public RenderLayer { const std::shared_ptr&, const RenderTree&, UniqueChangeRequestVec&) override; - - /// Remove all the drawables for tiles - /// @return The number of drawables actually removed. - std::size_t removeAllDrawables() override; #endif private: @@ -67,6 +63,10 @@ class RenderHeatmapLayer final : public RenderLayer { /// Remove all drawables for the tile from the layer group /// @return The number of drawables actually removed. std::size_t removeTile(RenderPass, const OverscaledTileID&) override; + + /// Remove all the drawables for tiles + /// @return The number of drawables actually removed. + std::size_t removeAllDrawables() override; #endif // Paint properties diff --git a/src/mbgl/renderer/layers/render_raster_layer.cpp b/src/mbgl/renderer/layers/render_raster_layer.cpp index a639c3e478b..837741d843f 100644 --- a/src/mbgl/renderer/layers/render_raster_layer.cpp +++ b/src/mbgl/renderer/layers/render_raster_layer.cpp @@ -340,8 +340,8 @@ void RenderRasterLayer::update(gfx::ShaderRegistry& shaders, [&](const gfx::UniqueDrawableBuilder& builder, gfx::Drawable* drawable, const RasterBucket& bucket) { // The bucket may later add, remove, or change masking. In that case, the tile's // shared data and segments are not updated, and it needs to be re-created. - if (drawable && (bucket.sharedVertices->isModifiedAfter(drawable->createTime) || - bucket.sharedTriangles->isModifiedAfter(drawable->createTime))) { + if (drawable && + (bucket.sharedVertices->isModifiedAfter(drawable->createTime) || bucket.sharedTriangles->getDirty())) { return false; } @@ -464,8 +464,7 @@ void RenderRasterLayer::update(gfx::ShaderRegistry& shaders, } }); - if (tileUpdateTime && (bucket.vertices.isModifiedAfter(*tileUpdateTime) || - bucket.indices.isModifiedAfter(*tileUpdateTime))) { + if (tileUpdateTime && (bucket.vertices.isModifiedAfter(*tileUpdateTime) || bucket.indices.getDirty())) { removeTile(renderPass, tileID); cleared = true; } diff --git a/src/mbgl/renderer/layers/render_symbol_layer.hpp b/src/mbgl/renderer/layers/render_symbol_layer.hpp index be0d512a03d..a1e483313ab 100644 --- a/src/mbgl/renderer/layers/render_symbol_layer.hpp +++ b/src/mbgl/renderer/layers/render_symbol_layer.hpp @@ -98,9 +98,6 @@ class RenderSymbolLayer final : public RenderLayer { const std::shared_ptr&, const RenderTree&, UniqueChangeRequestVec&) override; - - /// Remove all the drawables for tiles - std::size_t removeAllDrawables() override; #endif // MLN_DRAWABLE_RENDERER protected: @@ -122,6 +119,9 @@ class RenderSymbolLayer final : public RenderLayer { /// Remove all drawables for the tile from the layer group std::size_t removeTile(RenderPass, const OverscaledTileID&) override; + + /// Remove all the drawables for tiles + std::size_t removeAllDrawables() override; #endif // MLN_DRAWABLE_RENDERER private: diff --git a/src/mbgl/renderer/render_layer.hpp b/src/mbgl/renderer/render_layer.hpp index 417d1750325..be8d6da94cb 100644 --- a/src/mbgl/renderer/render_layer.hpp +++ b/src/mbgl/renderer/render_layer.hpp @@ -191,9 +191,6 @@ class RenderLayer { /// Returns the current renderability mode of the layer bool isLayerRenderable() const noexcept { return isRenderable; } - - /// Remove all the drawables for tiles - virtual std::size_t removeAllDrawables(); #endif using Dependency = style::expression::Dependency; @@ -250,6 +247,9 @@ class RenderLayer { /// @return The number of drawables actually removed. virtual std::size_t removeTile(RenderPass, const OverscaledTileID&); + /// Remove all the drawables for tiles + virtual std::size_t removeAllDrawables(); + /// Update `renderTileIDs` from `renderTiles` void updateRenderTileIDs(); diff --git a/src/mbgl/renderer/render_orchestrator.cpp b/src/mbgl/renderer/render_orchestrator.cpp index 58ea59f69e6..21ae10f54bd 100644 --- a/src/mbgl/renderer/render_orchestrator.cpp +++ b/src/mbgl/renderer/render_orchestrator.cpp @@ -993,13 +993,6 @@ void RenderOrchestrator::updateLayers(gfx::ShaderRegistry& shaders, for (const auto& item : items) { auto& renderLayer = item.layer.get(); -#if MLN_RENDER_BACKEND_OPENGL - // Android Emulator: Goldfish is *very* broken. This will prevent a crash - // inside the GL translation layer at the cost of emulator performance. - if (androidGoldfishMitigationEnabled) { - renderLayer.removeAllDrawables(); - } -#endif renderLayer.update(shaders, context, state, updateParameters, renderTree, changes); } addChanges(changes); diff --git a/src/mbgl/renderer/render_orchestrator.hpp b/src/mbgl/renderer/render_orchestrator.hpp index f703de4a8b9..56ee9790e26 100644 --- a/src/mbgl/renderer/render_orchestrator.hpp +++ b/src/mbgl/renderer/render_orchestrator.hpp @@ -61,10 +61,6 @@ class RenderOrchestrator final : public GlyphManagerObserver, public ImageManage const std::optional& localFontFamily_); ~RenderOrchestrator() override; -#if MLN_RENDER_BACKEND_OPENGL - void enableAndroidEmulatorGoldfishMitigation(bool enable) { androidGoldfishMitigationEnabled = enable; } -#endif - void markContextLost() { contextLost = true; }; // TODO: Introduce RenderOrchestratorObserver. void setObserver(RendererObserver*); @@ -216,10 +212,6 @@ class RenderOrchestrator final : public GlyphManagerObserver, public ImageManage bool placedSymbolDataCollected = false; bool tileCacheEnabled = true; -#if MLN_RENDER_BACKEND_OPENGL - bool androidGoldfishMitigationEnabled{false}; -#endif - // Vectors with reserved capacity of layerImpls->size() to avoid // reallocation on each frame. std::vector> filteredLayersForSource; diff --git a/src/mbgl/renderer/renderer.cpp b/src/mbgl/renderer/renderer.cpp index 611144d2aba..0df78b07199 100644 --- a/src/mbgl/renderer/renderer.cpp +++ b/src/mbgl/renderer/renderer.cpp @@ -152,10 +152,4 @@ void Renderer::clearData() { impl->orchestrator.clearData(); } -#if MLN_RENDER_BACKEND_OPENGL -void Renderer::enableAndroidEmulatorGoldfishMitigation(bool enable) { - impl->orchestrator.enableAndroidEmulatorGoldfishMitigation(enable); -} -#endif - } // namespace mbgl diff --git a/src/mbgl/vulkan/drawable.cpp b/src/mbgl/vulkan/drawable.cpp index fb87dcdb8b4..6c4997048ca 100644 --- a/src/mbgl/vulkan/drawable.cpp +++ b/src/mbgl/vulkan/drawable.cpp @@ -144,13 +144,12 @@ void Drawable::upload(gfx::UploadPass& uploadPass_) { // We need either raw index data or a buffer already created from them. // We can have a buffer and no indexes, but only if it's not marked dirty. - if (!impl->indexes || (impl->indexes->empty() && (!impl->indexes->getBuffer() || !attributeUpdateTime || - impl->indexes->isModifiedAfter(*attributeUpdateTime)))) { + if (!impl->indexes || (impl->indexes->empty() && (!impl->indexes->getBuffer() || impl->indexes->getDirty()))) { assert(!"Missing index data"); return; } - if (!impl->indexes->getBuffer() || !attributeUpdateTime || impl->indexes->isModifiedAfter(*attributeUpdateTime)) { + if (!impl->indexes->getBuffer() || impl->indexes->getDirty()) { // Create a buffer for the index data. We don't update any // existing buffer because it may still be in use by the previous frame. auto indexBufferResource{uploadPass.createIndexBufferResource( @@ -160,6 +159,7 @@ void Drawable::upload(gfx::UploadPass& uploadPass_) { auto buffer = std::make_unique(std::move(indexBuffer)); impl->indexes->setBuffer(std::move(buffer)); + impl->indexes->setDirty(false); } const bool buildAttribs = !vertexAttributes || !attributeUpdateTime ||