3#include "InspectorGuiHelper.h"
6#include "Resources/MeshManager.h"
7#include "Resources/BufferManager.h"
9#include "MemoryContext.h"
17 struct MeshInspectorItem
26void Cogs::Core::meshInspector(
Context * context,
bool * show)
29 ImGui::SetNextWindowSize(ImVec2(600, 1000), ImGuiCond_Once);
33 const std::vector<ResourceBase*> meshResources = context->meshManager->getAllocatedResources();
36 size_t totalByteSize = 0;
37 size_t totalStreamCount = 0;
38 std::vector<MeshInspectorItem> meshes;
39 meshes.reserve(meshResources.size());
41 if (resource->getSlot() == 0xFFFFFFFF)
continue;
42 assert(resource->getType() == ResourceTypes::Mesh);
43 Mesh* mesh =
reinterpret_cast<Mesh*
>(resource);
45 size_t byteSizeMesh = 0;
46 for (
const DataStream& stream : mesh->streams) {
47 byteSizeMesh += stream.size();
49 totalByteSize += byteSizeMesh;
50 totalStreamCount += mesh->streams.size();
51 meshes.push_back({ .mesh = mesh, .byteSize = byteSizeMesh });
55 const char* sortings[] = {
58 "Sort by usage and size"
60 static int sorting = 0;
66 std::sort(meshes.begin(), meshes.end(),
67 [](
const MeshInspectorItem& a,
const MeshInspectorItem& b)
69 return b.byteSize < a.byteSize;
74 std::sort(meshes.begin(), meshes.end(),
75 [](
const MeshInspectorItem& a,
const MeshInspectorItem& b)
77 if (a.mesh->referenceCount() == b.mesh->referenceCount()) return b.byteSize < a.byteSize;
78 return b.mesh->referenceCount() < a.mesh->referenceCount();
87 std::string windowHeader;
88 windowHeader.reserve(50);
89 windowHeader.append(
"Meshes [");
90 windowHeader.append(std::to_string(meshes.size()));
91 windowHeader.append(
" meshes, ");
92 windowHeader.append(std::to_string(totalStreamCount));
93 windowHeader.append(
" streams, ");
94 appendBytesize(windowHeader, totalByteSize);
95 windowHeader.append(
"]");
97 guiBegin(windowHeader, show);
100 ImGui::Combo(
"##sorting", &sorting, sortings, IM_ARRAYSIZE(sortings), 10);
106 for (
const MeshInspectorItem& item : meshes) {
108 header.append(std::to_string(line++));
110 if (std::string_view name = item.mesh->getName(); !name.empty()) {
114 header.append(
"Mesh");
118 appendBytesize(header, item.byteSize);
120 header.append(std::to_string(item.mesh->referenceCount()));
121 header.append(
" refs]");
122 showMesh(context, item.mesh, header);
129void Cogs::Core::bufferInspector(
Context * context,
bool * show)
132 ImGui::SetNextWindowSize(ImVec2(600, 1000), ImGuiCond_Once);
134 std::vector<ResourceBase*> buffers = context->bufferManager->getAllocatedResources();
136 guiBegin(
"Buffers", show);
142 mem += buffer->
size();
145 ImGui::Text(
"Count: %zu Mem: %zu bytes", buffers.size(), mem);
153 std::string_view name = buffer->
getName();
156 header =
"Buffer " + std::to_string(
id);
159 header = std::string(name);
161 header +=
" (" + std::to_string(buffer->
size()) +
" bytes)";
163 ImGui::PushID(buffer);
165 if (ImGui::TreeNode(header.c_str())) {
169 bool isResident = buffer->isResident();
170 bool hasChanged = buffer->hasChanged();
172 ImGui::Checkbox(
"Vertex Buffer", &isVB);
173 ImGui::Checkbox(
"Index Buffer", &isIB);
174 ImGui::Checkbox(
"Resident", &isResident);
175 ImGui::Checkbox(
"Changed", &hasChanged);
177 ImGui::Text(
"Size: %zu", buffer->
size());
189void Cogs::Core::engineInspector(
Context * context,
bool * show)
192 ImGui::SetNextWindowSize(ImVec2(600, 400), ImGuiCond_Once);
194 std::string title =
"Engine Statistics";
195 guiBegin(title, show);
197 auto & memory = *context->
memory;
199 if (ImGui::CollapsingHeader(
"Memory Allocation")) {
200 ImGui::Columns(5,
"Stats");
202 ImGui::Text(
"Type"); ImGui::NextColumn();
203 ImGui::Text(
"Count"); ImGui::NextColumn();
204 ImGui::Text(
"Bytes"); ImGui::NextColumn();
205 ImGui::Text(
"Peak Count"); ImGui::NextColumn();
206 ImGui::Text(
"Peak Bytes"); ImGui::Separator(); ImGui::NextColumn();
208 struct AllocatorStats
213 {
"Base", memory.baseAllocator },
214 {
"Resources", memory.resourceAllocator },
215 {
"Components", memory.componentAllocator },
216 {
"Strings", memory.getStringsAllocator()},
219 for (
auto & a : allocators) {
220 ImGui::Text(
"%s", a.name); ImGui::NextColumn();
221 ImGui::Text(
"%zu", getAllocationCount(a.allocator)); ImGui::NextColumn();
222 ImGui::Text(
"%zu", getAllocatedBytes(a.allocator)); ImGui::NextColumn();
223 ImGui::Text(
"%zu", getPeakCount(a.allocator)); ImGui::NextColumn();
224 ImGui::Text(
"%zu", getPeakBytes(a.allocator)); ImGui::NextColumn();
A Context instance contains all the services, systems and runtime components needed to use Cogs.
std::unique_ptr< struct MemoryContext > memory
Memory and allocation info.
Base allocator implementation.
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
bool isVertexBuffer() const
Gets if the buffer data is usable as a vertex data.
size_t size() const
Size of the buffer in bytes.
bool isIndexBuffer() const
Gets if the buffer data is usable as index buffer data.
Contains a stream of data used by Mesh resources.
Meshes contain streams of vertex data in addition to index data and options defining geometry used fo...
Base class for engine resources.
StringView getName() const
Get the name of the resource.