1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-01 16:24:12 +01:00

[hud] Implement memory stats display as a HUD item

This commit is contained in:
Philip Rebohle 2019-12-13 11:37:16 +01:00
parent 3aff573bd4
commit 936f22d2aa
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
3 changed files with 70 additions and 0 deletions

View File

@ -42,6 +42,7 @@ namespace dxvk::hud {
addItem<HudSubmissionStatsItem>("submissions", device);
addItem<HudDrawCallStatsItem>("drawcalls", device);
addItem<HudPipelineStatsItem>("pipelines", device);
addItem<HudMemoryStatsItem>("memory", device);
}

View File

@ -1,5 +1,6 @@
#include "dxvk_hud_item.h"
#include <iomanip>
#include <version.h>
namespace dxvk::hud {
@ -388,4 +389,46 @@ namespace dxvk::hud {
return position;
}
HudMemoryStatsItem::HudMemoryStatsItem(const Rc<DxvkDevice>& device)
: m_device(device), m_memory(device->adapter()->memoryProperties()) {
}
HudMemoryStatsItem::~HudMemoryStatsItem() {
}
void HudMemoryStatsItem::update(dxvk::high_resolution_clock::time_point time) {
for (uint32_t i = 0; i < m_memory.memoryHeapCount; i++)
m_heaps[i] = m_device->getMemoryStats(i);
}
HudPos HudMemoryStatsItem::render(
HudRenderer& renderer,
HudPos position) {
for (uint32_t i = 0; i < m_memory.memoryHeapCount; i++) {
bool isDeviceLocal = m_memory.memoryHeaps[i].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT;
uint64_t memUsedMib = m_heaps[i].memoryUsed >> 20;
uint64_t percentage = (100 * m_heaps[i].memoryUsed) / m_memory.memoryHeaps[i].size;
std::string text = str::format(isDeviceLocal ? "Vidmem" : "Sysmem", " heap ", i, ": ",
std::setfill(' '), std::setw(5), memUsedMib, " MB (", percentage, "%)");
position.y += 16.0f;
renderer.drawText(16.0f,
{ position.x, position.y },
{ 1.0f, 1.0f, 1.0f, 1.0f },
text);
position.y += 4.0f;
}
position.y += 4.0f;
return position;
}
}

View File

@ -296,4 +296,30 @@ namespace dxvk::hud {
};
/**
* \brief HUD item to display memory usage
*/
class HudMemoryStatsItem : public HudItem {
public:
HudMemoryStatsItem(const Rc<DxvkDevice>& device);
~HudMemoryStatsItem();
void update(dxvk::high_resolution_clock::time_point time);
HudPos render(
HudRenderer& renderer,
HudPos position);
private:
Rc<DxvkDevice> m_device;
VkPhysicalDeviceMemoryProperties m_memory;
DxvkMemoryStats m_heaps[VK_MAX_MEMORY_HEAPS];
};
}