Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index buffers reverted to dirty flag instead of timestamps #2927

Merged
merged 20 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions include/mbgl/renderer/renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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> impl;
Expand Down
29 changes: 0 additions & 29 deletions platform/android/MapLibreAndroid/src/cpp/map_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,6 @@
#include "android_renderer_backend.hpp"
#include "map_renderer_runnable.hpp"

#if MLN_RENDER_BACKEND_OPENGL
#include <sys/system_properties.h>

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 {

Expand Down Expand Up @@ -253,14 +232,6 @@ void MapRenderer::onSurfaceCreated(JNIEnv& env, const jni::Object<AndroidSurface
renderer = std::make_unique<Renderer>(backend->getImpl(), pixelRatio, localIdeographFontFamily);
rendererRef = std::make_unique<ActorRef<Renderer>>(*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);

Expand Down
14 changes: 2 additions & 12 deletions src/mbgl/gfx/index_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <mbgl/gfx/draw_mode.hpp>
#include <mbgl/util/ignore.hpp>
#include <mbgl/util/monotonic_timer.hpp>

#include <memory>
#include <vector>
Expand Down Expand Up @@ -41,15 +40,8 @@ class IndexVectorBase {
void setBuffer(std::unique_ptr<IndexBufferBase>&& value) { buffer = std::move(value); }
#endif // MLN_DRAWABLE_RENDERER

std::chrono::duration<double> getLastModified() const { return lastModified; }
bool isModifiedAfter(std::chrono::duration<double> 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; }

Expand Down Expand Up @@ -107,8 +99,6 @@ class IndexVectorBase {
#endif // MLN_DRAWABLE_RENDERER
bool dirty = true;
bool released = false;

std::chrono::duration<double> lastModified = util::MonotonicTimer::now();
};

using IndexVectorBasePtr = std::shared_ptr<IndexVectorBase>;
Expand Down
10 changes: 3 additions & 7 deletions src/mbgl/gl/drawable_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ DrawableGL::DrawableGL(std::string name_)
impl(std::make_unique<Impl>()) {}

DrawableGL::~DrawableGL() {
impl->indexBuffer = {0, nullptr};
impl->attributeBuffers.clear();
}

Expand Down Expand Up @@ -192,19 +191,16 @@ void DrawableGL::upload(gfx::UploadPass& uploadPass) {
auto& glContext = static_cast<gl::Context&>(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)};
auto indexBuffer = std::make_unique<gfx::IndexBuffer>(impl->indexes->elements(),
std::move(indexBufferResource));
auto buffer = std::make_unique<IndexBufferGL>(std::move(indexBuffer));
impl->indexes->setBuffer(std::move(buffer));
impl->indexes->setDirty(false);
}

// Build the vertex attributes and bindings, if necessary
Expand Down
2 changes: 0 additions & 2 deletions src/mbgl/gl/drawable_gl_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ class DrawableGL::Impl final {
gfx::AttributeDataType vertexType = static_cast<gfx::AttributeDataType>(-1);

AttributeBindingArray attributeBindings;

gfx::IndexBuffer indexBuffer = {0, nullptr};
std::vector<gfx::UniqueVertexBufferResource> attributeBuffers;

UniformBufferArrayGL uniformBuffers;
Expand Down
16 changes: 5 additions & 11 deletions src/mbgl/mtl/drawable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -546,19 +546,14 @@ void Drawable::upload(gfx::UploadPass& uploadPass_) {
auto& context = static_cast<Context&>(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(
Expand All @@ -568,6 +563,7 @@ void Drawable::upload(gfx::UploadPass& uploadPass_) {
auto buffer = std::make_unique<IndexBuffer>(std::move(indexBuffer));

impl->indexes->setBuffer(std::move(buffer));
impl->indexes->setDirty(false);
}

const bool buildAttribs = !impl->vertexDesc || !vertexAttributes || !attributeUpdateTime ||
Expand All @@ -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); });

Expand Down Expand Up @@ -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); });
Expand Down
3 changes: 0 additions & 3 deletions src/mbgl/mtl/drawable_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ class Drawable::Impl final {
std::size_t vertexCount = 0;
gfx::AttributeDataType vertexType = gfx::AttributeDataType::Invalid;

std::vector<gfx::UniqueVertexBufferResource> attributeBuffers;
gfx::AttributeBindingArray attributeBindings;

std::vector<gfx::UniqueVertexBufferResource> instanceBuffers;
gfx::AttributeBindingArray instanceBindings;

UniformBufferArray uniformBuffers;
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/mtl/upload_pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ gfx::AttributeBindingArray UploadPass::buildAttributeBindings(
const gfx::VertexAttributeArray& overrides,
const gfx::BufferUsageType usage,
const std::optional<std::chrono::duration<double>> lastUpdate,
/*out*/ std::vector<std::unique_ptr<gfx::VertexBufferResource>>& outBuffers) {
/*out*/ std::vector<std::unique_ptr<gfx::VertexBufferResource>>&) {
MLN_TRACE_FUNC();

gfx::AttributeBindingArray bindings;
Expand Down
1 change: 0 additions & 1 deletion src/mbgl/renderer/buckets/circle_bucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ void CircleBucket::update(const FeatureStates& states,
uploaded = false;

sharedVertices->updateModified();
sharedTriangles->updateModified();
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/mbgl/renderer/buckets/fill_bucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ void FillBucket::update(const FeatureStates& states,
uploaded = false;

sharedVertices->updateModified();
sharedBasicLineIndexes->updateModified();
sharedTriangles->updateModified();
}
}

Expand Down
1 change: 0 additions & 1 deletion src/mbgl/renderer/buckets/fill_extrusion_bucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ void FillExtrusionBucket::update(const FeatureStates& states,
uploaded = false;

sharedVertices->updateModified();
sharedTriangles->updateModified();
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/mbgl/renderer/buckets/hillshade_bucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ void HillshadeBucket::clear() {
indices.clear();

vertices.updateModified();
indices.updateModified();

uploaded = false;
}
Expand Down Expand Up @@ -121,7 +120,6 @@ void HillshadeBucket::setMask(TileMask&& mask_) {
}

vertices.updateModified();
indices.updateModified();
}

bool HillshadeBucket::hasData() const {
Expand Down
1 change: 0 additions & 1 deletion src/mbgl/renderer/buckets/line_bucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ void LineBucket::update(const FeatureStates& states,
uploaded = false;

sharedVertices->updateModified();
sharedTriangles->updateModified();
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/mbgl/renderer/buckets/raster_bucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ void RasterBucket::clear() {
indices.clear();

vertices.updateModified();
indices.updateModified();

uploaded = false;
}
Expand Down Expand Up @@ -118,7 +117,6 @@ void RasterBucket::setMask(TileMask&& mask_) {
}

vertices.updateModified();
indices.updateModified();
}

bool RasterBucket::hasData() const {
Expand Down
3 changes: 0 additions & 3 deletions src/mbgl/renderer/buckets/symbol_bucket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,6 @@ class SymbolBucket final : public Bucket {
if (sharedOpacityVertices) {
sharedOpacityVertices->updateModified();
}
if (sharedTriangles) {
sharedTriangles->updateModified();
}
}

std::shared_ptr<VertexVector> sharedVertices = std::make_shared<VertexVector>();
Expand Down
8 changes: 4 additions & 4 deletions src/mbgl/renderer/layers/render_heatmap_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ class RenderHeatmapLayer final : public RenderLayer {
const std::shared_ptr<UpdateParameters>&,
const RenderTree&,
UniqueChangeRequestVec&) override;

/// Remove all the drawables for tiles
/// @return The number of drawables actually removed.
std::size_t removeAllDrawables() override;
#endif

private:
Expand Down Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions src/mbgl/renderer/layers/render_raster_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions src/mbgl/renderer/layers/render_symbol_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@ class RenderSymbolLayer final : public RenderLayer {
const std::shared_ptr<UpdateParameters>&,
const RenderTree&,
UniqueChangeRequestVec&) override;

/// Remove all the drawables for tiles
std::size_t removeAllDrawables() override;
#endif // MLN_DRAWABLE_RENDERER

protected:
Expand All @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions src/mbgl/renderer/render_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down
7 changes: 0 additions & 7 deletions src/mbgl/renderer/render_orchestrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading
Loading