Rendering statistics view (#3322)
Co-authored-by: Bart Louwers <bart@emeel.net>
This commit is contained in:
@@ -2,14 +2,27 @@
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <mbgl/util/color.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
namespace style {
|
||||
class Style;
|
||||
class SymbolLayer;
|
||||
} // namespace style
|
||||
|
||||
namespace gfx {
|
||||
|
||||
struct RenderingStats {
|
||||
RenderingStats() = default;
|
||||
bool isZero() const;
|
||||
|
||||
/// Frame CPU encoding time (milliseconds)
|
||||
double encodingTime = 0.0;
|
||||
/// Frame CPU rendering time (milliseconds)
|
||||
double renderingTime = 0.0;
|
||||
|
||||
/// Number of frames rendered
|
||||
int numFrames = 0;
|
||||
/// Number of draw calls (`glDrawElements`, `drawIndexedPrimitives`, etc.) executed during the most recent frame
|
||||
@@ -41,25 +54,40 @@ struct RenderingStats {
|
||||
|
||||
/// Number of active buffers
|
||||
int numBuffers = 0;
|
||||
/// Number of active offscreen frame buffers
|
||||
int numFrameBuffers = 0;
|
||||
|
||||
/// Number of active index buffers
|
||||
int numIndexBuffers = 0;
|
||||
/// Sum of index buffers update sizes
|
||||
std::size_t indexUpdateBytes = 0;
|
||||
|
||||
/// Number of active vertex buffers
|
||||
int numVertexBuffers = 0;
|
||||
/// Sum of vertex buffers update sizes
|
||||
std::size_t vertexUpdateBytes = 0;
|
||||
|
||||
/// Number of active uniform buffers
|
||||
int numUniformBuffers = 0;
|
||||
/// Number of times a uniform buffer is updated
|
||||
int numUniformUpdates = 0;
|
||||
/// Sum of uniform buffers update sizes
|
||||
std::size_t uniformUpdateBytes = 0;
|
||||
|
||||
/// Total texture memory
|
||||
int memTextures = 0;
|
||||
/// Total buffer memory
|
||||
int memBuffers = 0;
|
||||
/// Total index buffer memory
|
||||
int memIndexBuffers = 0;
|
||||
/// Total vertex buffer memory
|
||||
int memVertexBuffers = 0;
|
||||
/// Total uniform buffer memory
|
||||
int memUniformBuffers = 0;
|
||||
|
||||
/// Number of stencil buffer clears
|
||||
int stencilClears = 0;
|
||||
/// Number of stencil buffer updates
|
||||
int stencilUpdates = 0;
|
||||
|
||||
RenderingStats& operator+=(const RenderingStats&);
|
||||
@@ -69,5 +97,38 @@ struct RenderingStats {
|
||||
#endif
|
||||
};
|
||||
|
||||
class RenderingStatsView final {
|
||||
public:
|
||||
struct Options {
|
||||
float updateInterval = 0.25f;
|
||||
bool verbose = false;
|
||||
Color textColor = Color::red();
|
||||
float textSize = 4.0f;
|
||||
};
|
||||
|
||||
RenderingStatsView() = default;
|
||||
RenderingStatsView(const Options& options_)
|
||||
: options(options_) {}
|
||||
~RenderingStatsView() = default;
|
||||
|
||||
void create(style::Style& style);
|
||||
void destroy(style::Style& style);
|
||||
|
||||
mbgl::style::SymbolLayer* getLayer(style::Style& style);
|
||||
|
||||
void update(style::Style& style, const gfx::RenderingStats& stats);
|
||||
|
||||
protected:
|
||||
const std::string layerID = "rendering-stats";
|
||||
const std::string sourceID = layerID + "-source";
|
||||
|
||||
Options options;
|
||||
|
||||
double lastUpdate = 0.0;
|
||||
uint32_t frameCount = 0;
|
||||
double encodingTime = 0.0;
|
||||
double renderingTime = 0.0;
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -11,7 +11,7 @@ class UniformBufferGL final : public gfx::UniformBuffer {
|
||||
UniformBufferGL(const UniformBufferGL&);
|
||||
|
||||
public:
|
||||
UniformBufferGL(const void* data, std::size_t size_, IBufferAllocator& allocator);
|
||||
UniformBufferGL(Context& context, const void* data, std::size_t size_, IBufferAllocator& allocator);
|
||||
~UniformBufferGL() override;
|
||||
|
||||
UniformBufferGL(UniformBufferGL&& rhs) noexcept;
|
||||
@@ -27,6 +27,8 @@ public:
|
||||
void update(const void* data, std::size_t dataSize) override;
|
||||
|
||||
private:
|
||||
Context& context;
|
||||
|
||||
// unique id used for debugging and profiling purposes
|
||||
// localID should not be used as unique id because a const buffer pool is managed using IBufferAllocator
|
||||
// Currently unique IDs for constant buffers are only used when Tracy profiling is enabled
|
||||
|
||||
@@ -145,6 +145,9 @@ public:
|
||||
void setDebug(MapDebugOptions);
|
||||
MapDebugOptions getDebug() const;
|
||||
|
||||
bool isRenderingStatsViewEnabled() const;
|
||||
void enableRenderingStatsView(bool value);
|
||||
|
||||
bool isFullyLoaded() const;
|
||||
void dumpDebugLogs() const;
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <mbgl/style/sprite.hpp>
|
||||
#include <mbgl/text/glyph.hpp>
|
||||
#include <mbgl/shaders/shader_source.hpp>
|
||||
#include <mbgl/gfx/rendering_stats.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
@@ -47,8 +48,7 @@ public:
|
||||
RenderMode mode;
|
||||
bool needsRepaint; // In continous mode, shows that there are ongoig transitions.
|
||||
bool placementChanged;
|
||||
double frameEncodingTime;
|
||||
double frameRenderingTime;
|
||||
gfx::RenderingStats renderingStats;
|
||||
};
|
||||
|
||||
virtual void onCameraWillChange(CameraChangeMode) {}
|
||||
@@ -58,7 +58,7 @@ public:
|
||||
virtual void onDidFinishLoadingMap() {}
|
||||
virtual void onDidFailLoadingMap(MapLoadError, const std::string&) {}
|
||||
virtual void onWillStartRenderingFrame() {}
|
||||
virtual void onDidFinishRenderingFrame(RenderFrameStatus) {}
|
||||
virtual void onDidFinishRenderingFrame(const RenderFrameStatus&) {}
|
||||
virtual void onWillStartRenderingMap() {}
|
||||
virtual void onDidFinishRenderingMap(RenderMode) {}
|
||||
virtual void onDidFinishLoadingStyle() {}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <mbgl/tile/tile_id.hpp>
|
||||
#include <mbgl/util/font_stack.hpp>
|
||||
#include <mbgl/gfx/rendering_stats.hpp>
|
||||
#include <mbgl/text/glyph_range.hpp>
|
||||
#include <mbgl/tile/tile_operation.hpp>
|
||||
#include <mbgl/gfx/backend.hpp>
|
||||
@@ -51,6 +52,13 @@ public:
|
||||
onDidFinishRenderingFrame(mode, repaint, placementChanged);
|
||||
}
|
||||
|
||||
virtual void onDidFinishRenderingFrame(RenderMode mode,
|
||||
bool repaint,
|
||||
bool placementChanged,
|
||||
const gfx::RenderingStats& stats) {
|
||||
onDidFinishRenderingFrame(mode, repaint, placementChanged, stats.encodingTime, stats.renderingTime);
|
||||
}
|
||||
|
||||
/// Final frame
|
||||
virtual void onDidFinishRenderingMap() {}
|
||||
|
||||
|
||||
@@ -89,6 +89,10 @@ public:
|
||||
const PropertyValue<SymbolPlacementType>& getSymbolPlacement() const;
|
||||
void setSymbolPlacement(const PropertyValue<SymbolPlacementType>&);
|
||||
|
||||
static PropertyValue<bool> getDefaultSymbolScreenSpace();
|
||||
const PropertyValue<bool>& getSymbolScreenSpace() const;
|
||||
void setSymbolScreenSpace(const PropertyValue<bool>&);
|
||||
|
||||
static PropertyValue<float> getDefaultSymbolSortKey();
|
||||
const PropertyValue<float>& getSymbolSortKey() const;
|
||||
void setSymbolSortKey(const PropertyValue<float>&);
|
||||
|
||||
@@ -70,7 +70,7 @@ public:
|
||||
const mbgl::unordered_map<std::string, std::string>& additionalDefines);
|
||||
|
||||
/// Called at the end of a frame.
|
||||
void performCleanup() override {}
|
||||
void performCleanup() override;
|
||||
void reduceMemoryUsage() override {}
|
||||
|
||||
gfx::UniqueDrawableBuilder createDrawableBuilder(std::string name) override;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/gfx/vertex_buffer.hpp>
|
||||
#include <mbgl/vulkan/buffer_resource.hpp>
|
||||
|
||||
#include <memory>
|
||||
@@ -9,12 +10,10 @@ namespace vulkan {
|
||||
|
||||
class VertexBufferResource : public gfx::VertexBufferResource {
|
||||
public:
|
||||
VertexBufferResource() noexcept = delete;
|
||||
VertexBufferResource(BufferResource&& buffer_) noexcept
|
||||
: buffer(std::move(buffer_)) {}
|
||||
VertexBufferResource(BufferResource&& buffer_) noexcept;
|
||||
VertexBufferResource(VertexBufferResource&& other) noexcept
|
||||
: buffer(std::move(other.buffer)) {}
|
||||
~VertexBufferResource() noexcept override = default;
|
||||
~VertexBufferResource() noexcept override;
|
||||
|
||||
std::size_t getSizeInBytes() const noexcept { return buffer.getSizeInBytes(); }
|
||||
const void* contents() const noexcept { return buffer.contents(); }
|
||||
|
||||
Reference in New Issue
Block a user