diff --git a/README.md b/README.md index 7da0418e432..a06ce708dc7 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/d3d9/d3d9_hud.cpp b/src/d3d9/d3d9_hud.cpp index e37a5a0e370..8a90eefee83 100644 --- a/src/d3d9/d3d9_hud.cpp +++ b/src/d3d9/d3d9_hud.cpp @@ -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; + } + } \ No newline at end of file diff --git a/src/d3d9/d3d9_hud.h b/src/d3d9/d3d9_hud.h index b500e48b6f1..e6c6652558a 100644 --- a/src/d3d9/d3d9_hud.h +++ b/src/d3d9/d3d9_hud.h @@ -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 { @@ -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; + + }; + } \ No newline at end of file diff --git a/src/d3d9/d3d9_swapchain.cpp b/src/d3d9/d3d9_swapchain.cpp index 830c0e56fcd..a5cfc349ef2 100644 --- a/src/d3d9/d3d9_swapchain.cpp +++ b/src/d3d9/d3d9_swapchain.cpp @@ -1092,6 +1092,7 @@ namespace dxvk { if (m_hud != nullptr) { m_hud->addItem("api", 1, GetApiName()); m_hud->addItem("samplers", -1, m_parent); + m_hud->addItem("managed_mem", -1, m_parent); } }