Blowbox 2017
A 3D Game Engine by Riko Ophorst using DirectX 12
memory_profiler.h
1 #pragma once
2 
3 #include "core/debug/debug_window.h"
4 #include "util/string.h"
5 #include "util/vector.h"
6 #include "util/map.h"
7 #include "renderer/imgui/imgui.h"
8 #include "renderer/d3d12_includes.h"
9 
10 #define BLOWBOX_PROFILER_HISTORY_MAX_SAMPLE_COUNT 2000
11 #define BLOWBOX_PROFILER_HISTORY_MIN_SAMPLE_COUNT 2
12 
13 namespace blowbox
14 {
15  class GpuResource;
16 
23  class MemoryProfiler : public DebugWindow
24  {
25  friend class GpuResource;
26  public:
28  ~MemoryProfiler();
29 
31  void RenderMenu() override;
32 
34  void RenderWindow() override;
35 
37  void NewFrame();
38 
40  void Shutdown();
41 
42  protected:
44  void AddGpuResource(GpuResource* gpu_resource);
45 
47  void RemoveGpuResource(GpuResource* gpu_resource);
48 
53  {
54  ResourceSortType_NAME,
55  ResourceSortType_NAME_REVERTED,
56  ResourceSortType_SIZE,
57  ResourceSortType_SIZE_REVERTED,
58  ResourceSortType_DIMENSION,
59  ResourceSortType_DIMENSION_REVERTED,
60  ResourceSortType_FORMAT,
61  ResourceSortType_FORMAT_REVERTED
62  };
63 
71  struct ResourceData
72  {
75  uint64_t total_size;
76  D3D12_RESOURCE_DIMENSION dimension;
77  DXGI_FORMAT format;
78  uint32_t total_count;
79  };
80 
81  protected:
86  void Condense(bool force = false);
87 
91  void Uncondense();
92 
97  String ConvertDimensionToString(D3D12_RESOURCE_DIMENSION dimension);
98 
103  String ConvertFormatToString(DXGI_FORMAT format);
104 
105  private:
108  bool condense_;
110 
114 
115  ImGuiTextFilter filter_;
117 
118  protected:
121  {
127  inline bool operator() (ResourceData& a, ResourceData& b)
128  {
129  return (a.name < b.name);
130  }
131  };
132 
135  {
141  inline bool operator() (ResourceData& a, ResourceData& b)
142  {
143  return (a.name > b.name);
144  }
145  };
146 
149  {
155  inline bool operator() (ResourceData& a, ResourceData& b)
156  {
157  return (a.total_size < b.total_size);
158  }
159  };
160 
163  {
169  inline bool operator() (ResourceData& a, ResourceData& b)
170  {
171  return (a.total_size > b.total_size);
172  }
173  };
174 
177  {
183  inline bool operator() (ResourceData& a, ResourceData& b)
184  {
185  return (a.dimension < b.dimension);
186  }
187  };
188 
191  {
197  inline bool operator() (ResourceData& a, ResourceData& b)
198  {
199  return (a.dimension > b.dimension);
200  }
201  };
202 
205  {
211  inline bool operator() (ResourceData& a, ResourceData& b)
212  {
213  return (a.format < b.format);
214  }
215  };
216 
219  {
225  inline bool operator() (ResourceData& a, ResourceData& b)
226  {
227  return (a.format > b.format);
228  }
229  };
230  };
231 }
Vector< GpuResource * > unsorted_gpu_resources_
An unsorted array of GpuResources. New entries are added to this array.
Definition: memory_profiler.h:111
Helper struct to compare ResourceData by its format, in the opposite order.
Definition: memory_profiler.h:218
Helper struct to compare ResourceData by its name, in the opposite order.
Definition: memory_profiler.h:134
void Condense(bool force=false)
Condenses all GpuResources in the MemoryProfiler into single entries.
Definition: memory_profiler.cc:387
eastl::vector< T > Vector
Typedef for wrapping the EASTL vector.
Definition: vector.h:14
ResourceSortType
The different sorting types in which resources can be sorted in the MemoryProfiler.
Definition: memory_profiler.h:52
DXGI_FORMAT format
The format of the resource being described.
Definition: memory_profiler.h:77
ImGuiTextFilter filter_
A text filter that is used to filter out ResourceDatas by name from the sorted_gpu_resources_ array...
Definition: memory_profiler.h:115
Base class for DebugWindows.
Definition: debug_window.h:8
String ConvertFormatToString(DXGI_FORMAT format)
Converts a DXGI_FORMAT to a readable string.
Definition: memory_profiler.cc:438
Helper struct to compare ResourceData by its dimension, in the opposite order.
Definition: memory_profiler.h:190
Map< WString, ResourceData > gpu_resources_map_
A map of resource names to ResourceData objects. This map is used to store both the condensed and unc...
Definition: memory_profiler.h:112
bool has_shutdown_
Whether the memory profiler has shutdown.
Definition: memory_profiler.h:106
Helper struct to compare ResourceData by its total size, in the opposite order.
Definition: memory_profiler.h:162
ResourceSortType sort_type_
The sorting type that is used to sort the gpu resources in the sorted_gpu_resources_ array...
Definition: memory_profiler.h:116
D3D12_RESOURCE_DIMENSION dimension
Dimension of the struct.
Definition: memory_profiler.h:76
eastl::map< Key, T > Map
Typedef for wrapping the EASTL map.
Definition: map.h:14
Wraps ID3D12Resource objects.
Definition: gpu_resource.h:19
Helper struct to compare ResourceData by its format.
Definition: memory_profiler.h:204
Helper struct to compare ResourceData by its total size.
Definition: memory_profiler.h:148
Helper struct to compare ResourceData by its dimension.
Definition: memory_profiler.h:176
uint64_t total_size
The total (condensed) size of the different ResourceData.
Definition: memory_profiler.h:75
eastl::wstring WString
Typedef for wrapping the EASTL wstring.
Definition: string.h:20
uint32_t total_count
The number of GpuResources that are condensed in this ResourceData.
Definition: memory_profiler.h:78
eastl::string String
Typedef for wrapping the EASTL string.
Definition: string.h:13
bool show_window_
Whether the memory profiler window should be shown.
Definition: memory_profiler.h:107
Vector< ResourceData > sorted_gpu_resources_
A sorted array of ResourceDatas, based on the gpu_resources_map_. Used by the ImGui MemoryProfiler wi...
Definition: memory_profiler.h:113
void Uncondense()
Uncondenses all the GpuResources in the MemoryProfiler.
Definition: memory_profiler.cc:416
WString name
The name of the resource being described.
Definition: memory_profiler.h:74
void AddGpuResource(GpuResource *gpu_resource)
Adds a GpuResource to the memory profiler.
Definition: memory_profiler.cc:354
Helper struct to compare ResourceData by its name.
Definition: memory_profiler.h:120
String ConvertDimensionToString(D3D12_RESOURCE_DIMENSION dimension)
Converts a D3D12_RESOURCE_DIMENSION to a readable string.
Definition: memory_profiler.cc:422
bool condense_
Whether the different GpuResources in the MemoryProfiler should be condensed or not.
Definition: memory_profiler.h:108
The main Blowbox namespace.
Definition: image.cc:8
void RenderMenu() override
Renders the menu for the Profiler.
Definition: memory_profiler.cc:35
void Shutdown()
Shuts down the profiler.
Definition: memory_profiler.cc:348
void RenderWindow() override
Renders the actual window for the Profiler.
Definition: memory_profiler.cc:66
void NewFrame()
Starts a new profiling frame.
Definition: memory_profiler.cc:342
GpuResource * resource
The resource this ResourceData describes.
Definition: memory_profiler.h:73
bool is_condensed_
Whether the different GpuResources in the MemoryProfiler are condensed.
Definition: memory_profiler.h:109
void RemoveGpuResource(GpuResource *gpu_resource)
Removes a GpuResource from the memory profiler.
Definition: memory_profiler.cc:368
Provides memory profiling statistics.
Definition: memory_profiler.h:23
Used for condensing data into a single struct inside of the MemoryProfiler.
Definition: memory_profiler.h:71