1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
|
#pragma once
#if defined(NCINE_PROFILING) || defined(DOXYGEN_GENERATING_OUTPUT)
#include "RenderCommand.h"
namespace nCine
{
/// Gathers statistics about the rendering subsystem
class RenderStatistics
{
friend class ScreenViewport;
friend class RenderQueue;
friend class RenderBuffersManager;
friend class Texture;
friend class Geometry;
friend class DrawableNode;
friend class RenderVaoPool;
friend class RenderCommandPool;
public:
class Commands
{
public:
std::uint32_t vertices;
std::uint32_t commands;
std::uint32_t transparents;
std::uint32_t instances;
std::uint32_t batchSize;
Commands()
: vertices(0), commands(0), transparents(0), instances(0), batchSize(0) {}
private:
void reset()
{
vertices = 0;
commands = 0;
transparents = 0;
instances = 0;
batchSize = 0;
}
friend RenderStatistics;
};
class Buffers
{
public:
std::uint32_t count;
std::uint32_t size;
std::uint32_t usedSpace;
Buffers()
: count(0), size(0), usedSpace(0) {}
private:
void reset()
{
count = 0;
size = 0;
usedSpace = 0;
}
friend RenderStatistics;
};
class Textures
{
public:
std::uint32_t count;
std::uint32_t dataSize;
Textures()
: count(0), dataSize(0) {}
private:
void reset()
{
count = 0;
dataSize = 0;
}
friend RenderStatistics;
};
class CustomBuffers
{
public:
std::uint32_t count;
std::uint32_t dataSize;
CustomBuffers()
: count(0), dataSize(0) {}
private:
void reset()
{
count = 0;
dataSize = 0;
}
friend RenderStatistics;
};
class VaoPool
{
public:
std::uint32_t size;
std::uint32_t capacity;
std::uint32_t reuses;
std::uint32_t bindings;
VaoPool()
: size(0), capacity(0), reuses(0), bindings(0) {}
private:
void reset()
{
size = 0;
capacity = 0;
reuses = 0;
bindings = 0;
}
friend RenderStatistics;
};
class CommandPool
{
public:
std::uint32_t usedSize;
std::uint32_t freeSize;
std::uint32_t retrievals;
CommandPool()
: usedSize(0), freeSize(0), retrievals(0) {}
private:
void reset()
{
usedSize = 0;
freeSize = 0;
retrievals = 0;
}
friend RenderStatistics;
};
/// Returns the aggregated command statistics for all types
static inline const Commands& GetAllCommands() {
return allCommands_;
}
/// Returns the commnad statistics for the specified type
static inline const Commands& GetCommands(RenderCommand::Type type) {
return typedCommands_[(std::int32_t)type];
}
/// Returns the buffer statistics for the specified type
static inline const Buffers& GetBuffers(RenderBuffersManager::BufferTypes type) {
return typedBuffers_[(std::int32_t)type];
}
/// Returns aggregated texture statistics
static inline const Textures& GetTextures() {
return textures_;
}
/// Returns aggregated custom VBOs statistics
static inline const CustomBuffers& GetCustomVBOs() {
return customVbos_;
}
/// Returns aggregated custom IBOs statistics
static inline const CustomBuffers& GetCustomIBOs() {
return customIbos_;
}
/// Returns the number of `DrawableNodes` culled because outside of the screen
static inline std::uint32_t GetCulled() {
return culledNodes_[(index_ + 1) % 2];
}
/// Returns statistics about the VAO pool
static inline const VaoPool& GetVaoPool() {
return vaoPool_;
}
/// Returns statistics about the render command pools
static inline const CommandPool& GetCommandPool() {
return commandPool_;
}
private:
static Commands allCommands_;
static Commands typedCommands_[(std::int32_t)RenderCommand::Type::Count];
static Buffers typedBuffers_[(std::int32_t)RenderBuffersManager::BufferTypes::Count];
static Textures textures_;
static CustomBuffers customVbos_;
static CustomBuffers customIbos_;
static std::uint32_t index_;
static std::uint32_t culledNodes_[2];
static VaoPool vaoPool_;
static CommandPool commandPool_;
static void Reset();
static void GatherStatistics(const RenderCommand& command);
static void GatherStatistics(const RenderBuffersManager::ManagedBuffer& buffer);
static inline void GatherVaoPoolStatistics(std::uint32_t poolSize, std::uint32_t poolCapacity)
{
vaoPool_.size = poolSize;
vaoPool_.capacity = poolCapacity;
}
static inline void GatherCommandPoolStatistics(std::uint32_t usedSize, std::uint32_t freeSize)
{
commandPool_.usedSize = usedSize;
commandPool_.freeSize = freeSize;
}
static inline void AddTexture(std::uint32_t datasize)
{
textures_.count++;
textures_.dataSize += datasize;
}
static inline void RemoveTexture(std::uint32_t datasize)
{
textures_.count--;
textures_.dataSize -= datasize;
}
static inline void AddCustomVbo(std::uint32_t datasize)
{
customVbos_.count++;
customVbos_.dataSize += datasize;
}
static inline void RemoveCustomVbo(std::uint32_t datasize)
{
customVbos_.count--;
customVbos_.dataSize -= datasize;
}
static inline void AddCustomIbo(std::uint32_t datasize)
{
customIbos_.count++;
customIbos_.dataSize += datasize;
}
static inline void RemoveCustomIbo(std::uint32_t datasize)
{
customIbos_.count--;
customIbos_.dataSize -= datasize;
}
static inline void AddCulledNode()
{
culledNodes_[index_]++;
}
static inline void AddVaoPoolReuse()
{
vaoPool_.reuses++;
}
static inline void AddVaoPoolBinding()
{
vaoPool_.bindings++;
}
static inline void AddCommandPoolRetrieval()
{
commandPool_.retrievals++;
}
};
}
#endif
|