SpiecsEngine
 
Loading...
Searching...
No Matches
ImguiVideoMemoryRuntimeHUD.cpp
Go to the documentation of this file.
1/**
2* @file ImguiVideoMemoryRuntimeHUD.cpp.
3* @brief The ImguiVideoMemoryRuntimeHUD Class Implementation.
4* @author Spices.
5*/
6
7#include "Pchheader.h"
9#include "Debugger/Perf/NsightPerfGPUProfilerHUD.h"
10#include "Render/Vulkan/VulkanRenderBackend.h"
11
12namespace Spices {
13
15 const std::string& panelName ,
16 FrameInfo& frameInfo
17 )
18 : ImguiSlate(panelName, frameInfo)
19 {}
20
22 {
24
25 if (!m_IsSlateOn) return;
26
27 /**
28 * @brief Instance a VkPhysicalDeviceMemoryBudgetPropertiesEXT.
29 */
30 VkPhysicalDeviceMemoryBudgetPropertiesEXT memoryBudgetProperties{};
31 memoryBudgetProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT;
32 memoryBudgetProperties.pNext = nullptr;
33
34 /**
35 * @brief Instance a VkPhysicalDeviceMemoryProperties2.
36 */
37 VkPhysicalDeviceMemoryProperties2 memoryProperties{};
38 memoryProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2;
39 memoryProperties.pNext = &memoryBudgetProperties;
40
41 /**
42 * @brief Query memory data this frame.
43 */
44 vkGetPhysicalDeviceMemoryProperties2(VulkanRenderBackend::GetState().m_PhysicalDevice, &memoryProperties);
45
46 uint64_t nHeaps = memoryProperties.memoryProperties.memoryHeapCount;
47 VkDeviceSize usage = 0;
48 VkDeviceSize budget = 0;
49
50 for (uint64_t i = 0; i < nHeaps; i++)
51 {
52 usage += memoryBudgetProperties.heapUsage[i];
53 budget += memoryBudgetProperties.heapBudget[i];
54 }
55
56 /**
57 * @brief Begin render VideoMemoryRuntimeHUD.
58 */
59 Begin();
60
61 ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(2.0f, 4.0f));
62
63 /**
64 * @brief Search String.
65 */
66 static std::string searchString;
67 static bool isEnableSearch = false;
68
69 /**
70 * @brief Begin render Search Input Text.
71 */
72 {
73 SPICES_PROFILE_ZONEN("ImguiVideoMemoryRuntimeHUD::Search");
74
75 ImGui::Spacing();
76 ImGui::PushItemWidth(m_PanelSize.x - ImGuiH::GetLineItemSize().x * 2.0f - ImGui::GetStyle().WindowPadding.x);
77 static char search[256] = {};
78 if (ImGui::InputTextWithHint("##", ICON_TEXT(ICON_MD_SEARCH, Search), search, 128))
79 {
80 searchString = std::string(search);
81 if (searchString.size() == 0) isEnableSearch = false;
82 else isEnableSearch = true;
83 }
84 ImGui::PopItemWidth();
85
86 ImGui::SameLine(m_PanelSize.x - ImGuiH::GetLineItemSize().x * 2.0f);
87 ImGui::Button(ICON_MD_FILTER_ALT, ImGuiH::GetLineItemSize());
88 ImGui::SameLine(m_PanelSize.x - ImGuiH::GetLineItemSize().x * 1.0f);
89 ImGui::Button(ICON_MD_REORDER, ImGuiH::GetLineItemSize());
90 ImGui::Spacing();
91 }
92
93 float columeWidth = ImGuiH::GetLineItemSize().x * 6.5f;
94
95 {
96 SPICES_PROFILE_ZONEN("ImguiVideoMemoryRuntimeHUD::Total");
97
98 ImGuiH::DrawTreeTitle("Memory Total", nullptr, [&]() {
99 ImGuiH::DrawPropertyItem("Usage:", columeWidth, nullptr, [&]() {
100 ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x - ImGuiH::GetLineItemSize().x);
101 char buffer[256] = {};
102 ImGui::InputTextWithHint("##", ICON_TEXT_ROW(" ", ConvertBytestoString(usage).c_str()), buffer, sizeof(buffer));
103 ImGui::PopItemWidth();
104 ImGui::SameLine();
106 });
107 ImGuiH::DrawPropertyItem("Budget:", columeWidth, nullptr, [&]() {
108 ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x - ImGuiH::GetLineItemSize().x);
109 char buffer[256] = {};
110 ImGui::InputTextWithHint("##", ICON_TEXT_ROW(" ", ConvertBytestoString(budget).c_str()), buffer, sizeof(buffer));
111 ImGui::PopItemWidth();
112 ImGui::SameLine();
114 });
115 ImGuiH::DrawPropertyItem("Heap Count:", columeWidth, nullptr, [&]() {
116 ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x - ImGuiH::GetLineItemSize().x);
117 char buffer[256] = {};
118 ImGui::InputTextWithHint("##", ICON_TEXT_ROW(" ", std::to_string(nHeaps).c_str()), buffer, sizeof(buffer));
119 ImGui::PopItemWidth();
120 ImGui::SameLine();
122 });
123 });
124 }
125
126 {
127 SPICES_PROFILE_ZONEN("ImguiVideoMemoryRuntimeHUD::Heaps");
128
129 for (int i = 0; i < nHeaps; i++)
130 {
131 std::stringstream s;
132 s << "Memory Heap Index: " << i;
133
134 ImGuiH::DrawTreeTitle(s.str(), nullptr, [&]() {
135 ImGuiH::DrawPropertyItem("Usage:", columeWidth, nullptr, [&]() {
136 ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x - ImGuiH::GetLineItemSize().x);
137 char buffer[256] = {};
138 ImGui::InputTextWithHint("##", ICON_TEXT_ROW(" ", ConvertBytestoString(memoryBudgetProperties.heapUsage[i]).c_str()), buffer, sizeof(buffer));
139 ImGui::PopItemWidth();
140 ImGui::SameLine();
142 });
143 ImGuiH::DrawPropertyItem("Budget:", columeWidth, nullptr, [&]() {
144 ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x - ImGuiH::GetLineItemSize().x);
145 char buffer[256] = {};
146 ImGui::InputTextWithHint("##", ICON_TEXT_ROW(" ", ConvertBytestoString(memoryBudgetProperties.heapBudget[i]).c_str()), buffer, sizeof(buffer));
147 ImGui::PopItemWidth();
148 ImGui::SameLine();
150 });
151 ImGuiH::DrawPropertyItem("Heap Count:", columeWidth, nullptr, [&]() {
152 ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x - ImGuiH::GetLineItemSize().x);
153 char buffer[256] = {};
154 ImGui::InputTextWithHint("##", ICON_TEXT_ROW(" ", ConvertMemoryFlagtoString(memoryProperties.memoryProperties.memoryHeaps[i].flags).c_str()), buffer, sizeof(buffer));
155 ImGui::PopItemWidth();
156 ImGui::SameLine();
158 });
159 });
160 }
161 }
162
163 ImGui::PopStyleVar();
164
165 /**
166 * @brief End render VideoMemoryRuntimeHUD.
167 */
168 End();
169 }
170
172 {
174
175 if (bytes / 1024.0f < 1.0f)
176 {
177 std::stringstream ss;
178 ss << bytes << "bytes";
179
180 return ss.str();
181 }
182 else if (bytes / 1024.0f / 1024.0f < 1.0f)
183 {
184 std::stringstream ss;
185 ss << bytes / 1024.0f << " KB";
186
187 return ss.str();
188 }
189 else if (bytes / 1024.0f / 1024.0f / 1024.0f < 1.0f)
190 {
191 std::stringstream ss;
192 ss << bytes / 1024.0f / 1024.0f << " MB";
193
194 return ss.str();
195 }
196 else if (bytes / 1024.0f / 1024.0f / 1024.0f / 1024.0f < 1.0f)
197 {
198 std::stringstream ss;
199 ss << bytes / 1024.0f / 1024.0f / 1024.0f << " GB";
200
201 return ss.str();
202 }
203 else
204 {
205 std::stringstream ss;
206 ss << bytes / 1024.0f / 1024.0f / 1024.0f / 1024.0f << " TB";
207
208 return ss.str();
209 }
210 }
211
212 std::string ImguiVideoMemoryRuntimeHUD::ConvertMemoryFlagtoString(VkMemoryHeapFlags flag)
213 {
215
216 switch (flag)
217 {
218 case VK_MEMORY_HEAP_DEVICE_LOCAL_BIT:
219 return "Device Local";
220 case VK_MEMORY_HEAP_MULTI_INSTANCE_BIT: // NOTICE THAT: enum value also represents "VK_MEMORY_HEAP_MULTI_INSTANCE_BIT_KHR"
221 return "Multiple Instance";
222 default:
223 // In case that it does NOT correspond to device local memory
224 return "Host Local";
225 }
226 }
227}
#define ICON_TEXT(icon, text)
Definition ImguiHelper.h:24
#define ICON_TEXT_ROW(icon, text)
Definition ImguiHelper.h:25
#define SPICES_PROFILE_ZONEN(...)
#define SPICES_PROFILE_ZONE
FrameInfo Class. This class defines the FrameInfo data.
Definition FrameInfo.h:32
static bool DrawResetIcon(const bool &isMove)
Draw Reset Icon.
static void DrawPropertyItem(const std::string &itemName, float columeWidth, std::function< void()> nameFunc, std::function< void()> valFunc)
Draw a single property.
static void DrawTreeTitle(const std::string &treeName, std::function< void()> optionFunc, std::function< void()> treeFunc)
Draw a stylized tree title bar.
The ImGuiH Class. This class defines helper function for slate render.
Definition ImguiHelper.h:61
void End()
End a slate.
ImguiSlate(const std::string &panelName, FrameInfo &frameInfo)
Constructor Function. Init with Slate's name.
Definition ImguiUtils.h:35
This Class defines the basic behaves of specific slate. When we add an new Slate, we need inherit fro...
Definition ImguiUtils.h:27
std::string ConvertBytestoString(uint64_t bytes)
Convert bytes to string(GB/MB/KB).
virtual void OnRender() override
This interface is called On SlateRenderer Render.
ImguiVideoMemoryRuntimeHUD(const std::string &panelName, FrameInfo &frameInfo)
Constructor Function.
std::string ConvertMemoryFlagtoString(VkMemoryHeapFlags flag)
Convert memory flags to string.