Add Tracy instrumentation for CPU and GPU in OpenGL mode. (#2417)

This commit is contained in:
alasram
2024-06-17 10:20:14 -07:00
committed by GitHub
parent 30484d8f50
commit 4f0f3bac51
45 changed files with 1091 additions and 19 deletions

View File

@@ -2,8 +2,10 @@
#include <mbgl/gl/uniform_buffer_gl.hpp>
#include <mbgl/gl/defines.hpp>
#include <mbgl/util/compression.hpp>
#include <mbgl/util/instrumentation.hpp>
#include <mbgl/util/logging.hpp>
#include <atomic>
#include <vector>
#include <cassert>
@@ -12,9 +14,25 @@ namespace gl {
using namespace platform;
namespace {
// Currently unique IDs for constant buffers are only used when Tracy profiling is enabled
#ifdef MLN_TRACY_ENABLE
int64_t generateDebugId() noexcept {
static std::atomic_int64_t counter(0);
return ++counter;
}
#endif
} // namespace
UniformBufferGL::UniformBufferGL(const void* data_, std::size_t size_, IBufferAllocator& allocator_)
: UniformBuffer(size_),
#ifdef MLN_TRACY_ENABLE
uniqueDebugId(generateDebugId()),
#endif
managedBuffer(allocator_, this) {
MLN_TRACE_ALLOC_CONST_BUFFER(uniqueDebugId, size_);
if (size_ > managedBuffer.allocator.pageSize()) {
// Buffer is very large, won't fit in the provided allocator
MBGL_CHECK_ERROR(glGenBuffers(1, &localID));
@@ -30,15 +48,25 @@ UniformBufferGL::UniformBufferGL(const void* data_, std::size_t size_, IBufferAl
UniformBufferGL::UniformBufferGL(UniformBufferGL&& rhs) noexcept
: UniformBuffer(rhs.size),
#ifdef MLN_TRACY_ENABLE
uniqueDebugId(rhs.uniqueDebugId),
#endif
isManagedAllocation(rhs.isManagedAllocation),
localID(rhs.localID),
managedBuffer(std::move(rhs.managedBuffer)) {
managedBuffer.setOwner(this);
#ifdef MLN_TRACY_ENABLE
rhs.uniqueDebugId = -1;
#endif
}
UniformBufferGL::UniformBufferGL(const UniformBufferGL& other)
: UniformBuffer(other),
#ifdef MLN_TRACY_ENABLE
uniqueDebugId(generateDebugId()),
#endif
managedBuffer(other.managedBuffer.allocator, this) {
MLN_TRACE_ALLOC_CONST_BUFFER(uniqueDebugId, other.size);
managedBuffer.setOwner(this);
if (other.isManagedAllocation) {
managedBuffer.allocate(other.managedBuffer.getContents().data(), other.size);
@@ -52,6 +80,10 @@ UniformBufferGL::UniformBufferGL(const UniformBufferGL& other)
}
UniformBufferGL::~UniformBufferGL() {
#ifdef MLN_TRACY_ENABLE
assert(uniqueDebugId > 0);
#endif
MLN_TRACE_FREE_CONST_BUFFER(uniqueDebugId);
if (isManagedAllocation) {
return;
}