Skip to content

Commit

Permalink
Debug logging of untouched index buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
alasram committed Sep 17, 2024
1 parent 0e0c8da commit f536534
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/mbgl/gl/drawable_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <mbgl/shaders/gl/shader_program_gl.hpp>
#include <mbgl/util/instrumentation.hpp>
#include <mbgl/util/logging.hpp>
#include <mbgl/gl/index_buffer_resource.hpp>

namespace mbgl {
namespace gl {
Expand All @@ -31,6 +32,8 @@ void DrawableGL::draw(PaintParameters& parameters) const {

auto& context = static_cast<gl::Context&>(parameters.context);

impl->drawTouchBuffer();

if (shader) {
const auto& shaderGL = static_cast<const ShaderProgramGL&>(*shader);
if (shaderGL.getGLProgramID() != context.program.getCurrentValue()) {
Expand Down Expand Up @@ -281,5 +284,10 @@ void DrawableGL::unbindTextures() const {
}
}

void DrawableGL::Impl::drawTouchBuffer() {
const auto& indexBuf = static_cast<IndexBufferGL&>(*indexes->getBuffer());
indexBuf.buffer->getResource<gl::IndexBufferResource>().drawTouched = true;
}

} // namespace gl
} // namespace mbgl
2 changes: 2 additions & 0 deletions src/mbgl/gl/drawable_gl_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class DrawableGL::Impl final {
GLfloat pointSize = 0.0f;

size_t vertexAttrId = 0;

void drawTouchBuffer();
};

struct DrawableGL::DrawSegmentGL final : public gfx::Drawable::DrawSegment {
Expand Down
16 changes: 16 additions & 0 deletions src/mbgl/gl/index_buffer_resource.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <mbgl/gl/context.hpp>
#include <mbgl/gl/index_buffer_resource.hpp>
#include <mbgl/util/instrumentation.hpp>
#include <mbgl/util/logging.hpp>

namespace mbgl {
namespace gl {
Expand All @@ -16,6 +17,21 @@ IndexBufferResource::~IndexBufferResource() noexcept {
auto& stats = buffer.get_deleter().context.renderingStats();
stats.memIndexBuffers -= byteSize;
assert(stats.memIndexBuffers >= 0);

static int numDestroyedBuffers = 0;
static int numTouchedBuffers = 0;
++numDestroyedBuffers;

if (!drawTouched) {
Log::Error(
Event::OpenGL,
std::string(
"################### Calling ~IndexBufferResource on a resource that is never touched by a draw. ") +
std::to_string(numDestroyedBuffers) + " total destroyed index buffers, " +
std::to_string(numTouchedBuffers) + " total destroyed and touched by a draw.");
} else {
++numTouchedBuffers;
}
}

} // namespace gl
Expand Down
2 changes: 2 additions & 0 deletions src/mbgl/gl/index_buffer_resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class IndexBufferResource : public gfx::IndexBufferResource {

UniqueBuffer buffer;
int byteSize;

bool drawTouched = false;
};

} // namespace gl
Expand Down

0 comments on commit f536534

Please sign in to comment.