Skip to content

Commit

Permalink
[d3d9] Add HUD item for managed memory
Browse files Browse the repository at this point in the history
  • Loading branch information
K0bin committed Mar 11, 2022
1 parent 6a11cd8 commit fe27aec
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/d3d9/d3d9_hud.cpp
Expand Up @@ -33,4 +33,34 @@ namespace dxvk::hud {
return position;
}

HudManagedMemory::HudManagedMemory(D3D9DeviceEx* device)
: m_device (device)
, m_memoryText ("") {}


void HudManagedMemory::update(dxvk::high_resolution_clock::time_point time) {
D3D9MemoryAllocator* allocator = m_device->GetAllocator();
m_memoryText = str::format(allocator->AllocatedMemory() >> 20, " MiB, Used: ", allocator->UsedMemory() >> 20, " MiB, Mapped: ", allocator->MappedMemory() >> 20, " MiB");
}


HudPos HudManagedMemory::render(
HudRenderer& renderer,
HudPos position) {
position.y += 16.0f;

renderer.drawText(16.0f,
{ position.x, position.y },
{ 0.0f, 1.0f, 0.75f, 1.0f },
"Managed memory:");

renderer.drawText(16.0f,
{ position.x + 200.0f, position.y },
{ 1.0f, 1.0f, 1.0f, 1.0f },
m_memoryText);

position.y += 8.0f;
return position;
}

}
25 changes: 24 additions & 1 deletion src/d3d9/d3d9_hud.h
Expand Up @@ -6,7 +6,7 @@
namespace dxvk::hud {

/**
* \brief HUD item to display DXVK version
* \brief HUD item to display sampler count
*/
class HudSamplerCount : public HudItem {

Expand All @@ -28,4 +28,27 @@ namespace dxvk::hud {

};

/**
* \brief HUD item to display managed texture memory
*/
class HudManagedMemory : public HudItem {

public:

HudManagedMemory(D3D9DeviceEx* device);

void update(dxvk::high_resolution_clock::time_point time);

HudPos render(
HudRenderer& renderer,
HudPos position);

private:

D3D9DeviceEx* m_device;

std::string m_memoryText;

};

}
1 change: 1 addition & 0 deletions src/d3d9/d3d9_swapchain.cpp
Expand Up @@ -1080,6 +1080,7 @@ namespace dxvk {
if (m_hud != nullptr) {
m_hud->addItem<hud::HudClientApiItem>("api", 1, GetApiName());
m_hud->addItem<hud::HudSamplerCount>("samplers", -1, m_parent);
m_hud->addItem<hud::HudManagedMemory>("managed_mem", -1, m_parent);
}
}

Expand Down

0 comments on commit fe27aec

Please sign in to comment.