mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 15:48:58 +00:00
LEONIDA_DEV_OVERLAY (#2137) showed the working set and free RAM, with no GPU memory and no private memory. It now shows both, from the same code as the title HUD: - src/memory_figures.h holds VramBudget, the private-bytes choice (the larger of PrivateUsage and PagefileUsage, since Wine fills only the latter), the "RAM ..." and "VRAM ..." text with "n/a" where there is no figure, and a publisher for the device's GPU memory figure. No Vulkan, and Win32 only under _WIN32, so the overlay's test still builds on every host. - A device with VK_EXT_memory_budget publishes a reader when it is created and withdraws it first thing when it is destroyed (the lock is held during a read, so a reader never outlives its device). latest_vram() calls the reader at most once per 500 ms for both views. The HUD reads it instead of its own per-device lambda. - The overlay's last line is now "RAM 2.5 GB (ws 1.0) VRAM 3.5/16.0 GB +0.5 shared"; cores and free RAM keep their own line. Tests: dev_overlay_test checks the text with and without figures, the private-bytes fallback, and the publisher (one read per refresh, only the publishing device withdraws). title_hud_test checks that a HUD without its own source shows the published figure. d3d12_vram_budget_test checks that the device publishes its figure while it lives and withdraws it on release. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
47 lines
2.1 KiB
C++
47 lines
2.1 KiB
C++
#pragma once
|
|
|
|
// VK_EXT_memory_budget: how much GPU memory this process uses and may use, read from the Vulkan device itself. The
|
|
// device publishes it (memory_figures.h) for the title HUD (shims/title_hud.h, LEONIDA_TITLE_HUD) and the dev overlay
|
|
// (dev_overlay.h, LEONIDA_DEV_OVERLAY); DXGI's QueryVideoMemoryInfo, which the HUD read before, is 0 under Wine. The
|
|
// sums depend only on the two Vulkan structures, so a test can feed them made-up heaps.
|
|
|
|
#ifndef VK_NO_PROTOTYPES
|
|
#define VK_NO_PROTOTYPES
|
|
#endif
|
|
#include <vulkan/vulkan.h>
|
|
|
|
#include <cstdint>
|
|
|
|
#include "memory_figures.h" // VramBudget
|
|
|
|
namespace leonida {
|
|
|
|
inline VramBudget sum_vram_budget(const VkPhysicalDeviceMemoryProperties& memory,
|
|
const VkPhysicalDeviceMemoryBudgetPropertiesEXT& budget) {
|
|
VramBudget out;
|
|
for (std::uint32_t i = 0; i < memory.memoryHeapCount && i < VK_MAX_MEMORY_HEAPS; ++i) {
|
|
if (memory.memoryHeaps[i].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) {
|
|
out.local_usage += budget.heapUsage[i];
|
|
out.local_budget += budget.heapBudget[i];
|
|
} else {
|
|
out.shared_usage += budget.heapUsage[i];
|
|
}
|
|
}
|
|
out.available = out.local_budget != 0;
|
|
return out;
|
|
}
|
|
|
|
// Reads the budget now. `physical` must have VK_EXT_memory_budget (enabled on the logical device, as the runtime's
|
|
// device does). One vkGetPhysicalDeviceMemoryProperties2 call, which needs no external synchronization, so another
|
|
// thread (the HUD's or the overlay's) may call it while the device is in use.
|
|
inline VramBudget query_vram_budget(PFN_vkGetPhysicalDeviceMemoryProperties2 get_memory_properties2,
|
|
VkPhysicalDevice physical) {
|
|
if (!get_memory_properties2 || physical == VK_NULL_HANDLE) return {};
|
|
VkPhysicalDeviceMemoryBudgetPropertiesEXT budget{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT};
|
|
VkPhysicalDeviceMemoryProperties2 properties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2, &budget};
|
|
get_memory_properties2(physical, &properties);
|
|
return sum_vram_budget(properties.memoryProperties, budget);
|
|
}
|
|
|
|
} // namespace leonida
|