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 Apr 19, 2022
1 parent e19b9dd commit 55ec417
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ The `DXVK_HUD` environment variable controls a HUD which can display the framera
- `cs`: Shows worker thread statistics.
- `compiler`: Shows shader compiler activity
- `samplers`: Shows the current number of sampler pairs used *[D3D9 Only]*
- `managed_mem`: Shows the amount of memory used for D3DPOOL_MANAGED data *[D3D9 Only]*
- `scale=x`: Scales the HUD by a factor of `x` (e.g. `1.5`)

Additionally, `DXVK_HUD=1` has the same effect as `DXVK_HUD=devinfo,fps`, and `DXVK_HUD=full` enables all available HUD elements.
Expand Down
30 changes: 30 additions & 0 deletions src/d3d9/d3d9_hud.cpp
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,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 55ec417

Please sign in to comment.