aboutsummaryrefslogtreecommitdiff
path: root/src/video_core/vulkan_common/vulkan_device.cpp
diff options
context:
space:
mode:
authornéo Luigi <85024393+neoluigi4123@users.noreply.github.com>2026-10-31 15:33:09 +0100
committerkraibse <33869366+kraibse@users.noreply.github.com>2026-10-31 18:04:23 +0100
commit82963e6750cef756d2ad4d1115dc9dca420d4313 (patch)
tree8378304104c807b5d08f2985d6e7b75c57c0ae06 /src/video_core/vulkan_common/vulkan_device.cpp
parent2065b1431c0ecfeade61a7e7511889c4800b6bb9 (diff)
1st pass of review: code cleanup & windows test
Assisted-by: Claude Opus 5.5 (review, cleanup and log analysis)
Diffstat (limited to 'src/video_core/vulkan_common/vulkan_device.cpp')
-rw-r--r--src/video_core/vulkan_common/vulkan_device.cpp48
1 files changed, 26 insertions, 22 deletions
diff --git a/src/video_core/vulkan_common/vulkan_device.cpp b/src/video_core/vulkan_common/vulkan_device.cpp
index 915b22aaf5..623ab7c30d 100644
--- a/src/video_core/vulkan_common/vulkan_device.cpp
+++ b/src/video_core/vulkan_common/vulkan_device.cpp
@@ -411,6 +411,16 @@ std::filesystem::path StaticPipelineCacheFilename() {
return shader_dir / "vulkan_static_pipelines.bin";
}
+// What a heap's allocations use. The driver also counts the space in VMA's blocks no allocation
+// uses, but freeing an image gives its share back only once its whole block is empty: the caches,
+// collecting until the usage dropped, evicted thousands of textures in a row without lowering it
+// (title 1).
+u64 AllocatedUsage(VkDeviceSize driver_usage, const VmaBudget& vma_budget) {
+ const VmaStatistics& statistics = vma_budget.statistics;
+ const u64 unused = statistics.blockBytes - statistics.allocationBytes;
+ return driver_usage - (std::min)(driver_usage, unused);
+}
+
} // Anonymous namespace
void Device::RemoveExtension(bool& extension, const std::string& extension_name) {
@@ -1615,26 +1625,16 @@ void Device::ReleaseCustomBorderColorSamplers(size_t count) const {
}
u64 Device::GetDeviceMemoryUsage() const {
- VkPhysicalDeviceMemoryBudgetPropertiesEXT budget;
+ VkPhysicalDeviceMemoryBudgetPropertiesEXT budget{};
budget.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT;
- budget.pNext = nullptr;
physical.GetMemoryProperties(&budget);
- u64 result{};
- for (const size_t heap : valid_heap_memory) {
- result += budget.heapUsage[heap];
- }
- // Space in VMA's blocks that no allocation uses counts as used, but freeing an image gives
- // its share back only once its whole block is empty: the caches, collecting until this drops,
- // evicted thousands of textures in a row without lowering it (title 1). Count only what
- // allocations use.
+ std::array<VmaBudget, VK_MAX_MEMORY_HEAPS> heap_budgets{};
if (allocator != nullptr) {
- std::array<VmaBudget, VK_MAX_MEMORY_HEAPS> heap_budgets{};
vmaGetHeapBudgets(allocator, heap_budgets.data());
- for (const size_t heap : valid_heap_memory) {
- const VmaStatistics& statistics = heap_budgets[heap].statistics;
- const u64 unused = statistics.blockBytes - statistics.allocationBytes;
- result -= (std::min)(result, unused);
- }
+ }
+ u64 result{};
+ for (const size_t heap : valid_heap_memory) {
+ result += AllocatedUsage(budget.heapUsage[heap], heap_budgets[heap]);
}
return result;
}
@@ -1652,16 +1652,15 @@ u64 Device::GetDeviceMemoryBudget() const {
}
// Only the main heap's budget: summing every heap's counted VRAM twice on AMD (an 8 GB card
// reported 8.5 GB) and kept the collector's thresholds above the heap the images fill. What
- // the other heaps use is added, as GetDeviceMemoryUsage() counts it too.
+ // the other heaps use is added the way GetDeviceMemoryUsage() counts it, so the usage reaches
+ // this when the main heap's does its budget.
u64 result = budget.heapBudget[main_heap];
if (heap_size_limit != 0) {
result = (std::min)(result, heap_size_limit);
}
for (const size_t heap : valid_heap_memory) {
if (heap != main_heap) {
- const VmaStatistics& statistics = heap_budgets[heap].statistics;
- const u64 unused = statistics.blockBytes - statistics.allocationBytes;
- result += budget.heapUsage[heap] - (std::min)(budget.heapUsage[heap], unused);
+ result += AllocatedUsage(budget.heapUsage[heap], heap_budgets[heap]);
}
}
return result;
@@ -1681,8 +1680,13 @@ void Device::CollectPhysicalMemoryInfo() {
// EDEN_NX2_VRAM_LIMIT_MIB=<n>: treat every device-local heap as n MiB (small card tests).
if (const char* value = std::getenv("EDEN_NX2_VRAM_LIMIT_MIB")) {
heap_size_limit = std::strtoull(value, nullptr, 10) << 20;
- LOG_INFO(Render_Vulkan, "EDEN_NX2_VRAM_LIMIT_MIB: device-local heaps limited to {} MiB",
- heap_size_limit >> 20);
+ if (heap_size_limit != 0) {
+ LOG_INFO(Render_Vulkan, "EDEN_NX2_VRAM_LIMIT_MIB: device-local heaps limited to {} MiB",
+ heap_size_limit >> 20);
+ } else {
+ LOG_WARNING(Render_Vulkan, "EDEN_NX2_VRAM_LIMIT_MIB={} is not a size in MiB, ignored",
+ value);
+ }
}
const auto limit = [this](u64 size) {
return heap_size_limit != 0 ? (std::min)(size, heap_size_limit) : size;