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 18 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
2 changes: 1 addition & 1 deletion platform/android/MapLibreAndroid/src/cpp/map_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ void MapRenderer::onSurfaceCreated(JNIEnv& env, const jni::Object<AndroidSurface
// 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);
renderer->enableAndroidEmulatorGoldfishMitigation(false);
alexcristici marked this conversation as resolved.
Show resolved Hide resolved
}
#endif

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
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/vulkan/drawable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -160,6 +159,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 = !vertexAttributes || !attributeUpdateTime ||
Expand Down
Loading