From 9f989cbe4f1206145ee2cefa2281e8804066246a Mon Sep 17 00:00:00 2001 From: adrianmjim <11887815+adrianmjim@users.noreply.github.com> Date: Wed, 25 Nov 2026 08:13:58 +0100 Subject: [PATCH 1/2] d3d12: geometry views fall back to system memory when the BAR window is full (RT-GEOMETRY-VIEWS-NO-REBAR) LEONIDA_GEOMETRY_MB views required DEVICE_LOCAL | HOST_VISIBLE memory. Without Resizable BAR the only such heap is the 256 MiB BAR window, and the default 256 MiB GPU address arena (host-visible, preferring device-local) takes all of it. Every 4 MiB view block then failed with VK_ERROR_OUT_OF_DEVICE_MEMORY, no view was made, and translated shaders read zeros: d3d12_geometry_views failed on an RX 7900 XT without Resizable BAR (CPU-written table V# 0/64). A device-local block that cannot be allocated now goes to host-visible system memory, logged once. Views that fit in the BAR stay there. --- docs/d3d12_vulkan.md | 7 +++++-- runtime/shims/d3d12_title_buffer_windows.h | 17 +++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/docs/d3d12_vulkan.md b/docs/d3d12_vulkan.md index e23985ecb3..fbd8a86e6e 100644 --- a/docs/d3d12_vulkan.md +++ b/docs/d3d12_vulkan.md @@ -1621,8 +1621,10 @@ The copies: cannot fit between the title's address reservations can use a separate mapped buffer. The buffer's device address must fit as a positive 47-bit offset from the arena base. The same window cap and dirty-page refresh apply. `LEONIDA_STREAM_BUFFER_WINDOWS=0` requires the window to fit in the arena. -- `LEONIDA_GEOMETRY_MB` sets the device-local memory cap for streamed buffer views. The default is 0. +- `LEONIDA_GEOMETRY_MB` sets the memory cap for streamed buffer views. The default is 0. A positive cap enables persistent copies of placed buffer SRVs and buffer descriptors in title memory. + The copies go in device-local host-visible memory. Without Resizable BAR that is the 256 MiB BAR window, which + the default arena can fill; a block that finds no room there goes to host-visible system memory (logged once). A GPU-only reservation uses its paired CPU mapping. Matching source ranges share one copy. The resource descriptor heap keeps its console indices and original CPU bytes. Its shader-visible copy encodes each resolved buffer's offset from the arena base. CPU writes through either physical mapping, @@ -1678,7 +1680,8 @@ The runtime allocates image keys from `0x100000000` (4 GiB) in 256-byte steps, a `runtime/src/vulkan_memory.h`, beside D3D-96's `resizable_bar`). Without Resizable BAR the only `DEVICE_LOCAL | HOST_VISIBLE` type sits in a heap of 256 MiB or less (214 MiB on an RTX 3090 with driver 616.56), so the 256 MiB default arena lands in system memory there. Asking that heap for it broke VUID-vkAllocateMemory-pAllocateInfo-01713 even though the - driver returned `VK_SUCCESS` (reported by CharlyRien). + driver returned `VK_SUCCESS` (reported by CharlyRien). A heap of exactly 256 MiB does hold it: on an RX 7900 XT + without Resizable BAR (AMD 32.0.32029.2010) the arena fills the whole BAR heap. - M4+: allocate the arena `DEVICE_LOCAL` and stage CPU writes (descriptor heaps, shader blobs, buffer uploads) through a host-visible staging buffer, copied before the commands that use them. The hash table is not in the arena either: it is a normal storage buffer in `DEVICE_LOCAL` memory, uploaded from a mapped staging copy before diff --git a/runtime/shims/d3d12_title_buffer_windows.h b/runtime/shims/d3d12_title_buffer_windows.h index 5531d29a43..e25a1ed3e6 100644 --- a/runtime/shims/d3d12_title_buffer_windows.h +++ b/runtime/shims/d3d12_title_buffer_windows.h @@ -20,6 +20,7 @@ class TitleBufferWindows { }; std::vector blocks_; VkDeviceSize reserved_{}; + bool logged_host_fallback_ = false; public: VkDeviceSize reserved() const { return reserved_; } @@ -63,9 +64,21 @@ class TitleBufferWindows { vk.vkDestroyBuffer(d.info.device, b.buffer, nullptr); return false; } - b.memory = d.allocate(req, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | - (device_local ? VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT : 0), + constexpr VkMemoryPropertyFlags host_access = + VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; + b.memory = d.allocate(req, host_access | (device_local ? VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT : 0), VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, nullptr, true); + if (!b.memory && device_local) { + // Without Resizable BAR the only device-local host-visible heap is the 256 MiB BAR window, and the + // default GPU address arena can fill it. A view in system memory is slower to read but still correct. + b.memory = d.allocate(req, host_access, 0, nullptr, true); + if (b.memory && !logged_host_fallback_) { + logged_host_fallback_ = true; + std::fprintf(stderr, "[rt] d3d12: no device-local host-visible memory left for a %llu KiB block of " + "buffer views, so it is in system memory\n", + static_cast(b.capacity >> 10)); + } + } void* host{}; if (b.memory && vk.vkBindBufferMemory(d.info.device, b.buffer, b.memory, 0) == VK_SUCCESS && vk.vkMapMemory(d.info.device, b.memory, 0, VK_WHOLE_SIZE, 0, &host) == VK_SUCCESS) { From 3db487a818edffa1910962f1b24da04bf3b5289c Mon Sep 17 00:00:00 2001 From: adrianmjim <11887815+adrianmjim@users.noreply.github.com> Date: Wed, 25 Nov 2026 09:38:58 +0100 Subject: [PATCH 2/2] docs: geometry views prefer device-local memory, with the system-memory fallback --- docs/d3d12_vulkan.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/d3d12_vulkan.md b/docs/d3d12_vulkan.md index fbd8a86e6e..f6a4f285a1 100644 --- a/docs/d3d12_vulkan.md +++ b/docs/d3d12_vulkan.md @@ -1623,7 +1623,7 @@ The copies: `LEONIDA_STREAM_BUFFER_WINDOWS=0` requires the window to fit in the arena. - `LEONIDA_GEOMETRY_MB` sets the memory cap for streamed buffer views. The default is 0. A positive cap enables persistent copies of placed buffer SRVs and buffer descriptors in title memory. - The copies go in device-local host-visible memory. Without Resizable BAR that is the 256 MiB BAR window, which + The copies prefer device-local host-visible memory. Without Resizable BAR that is the 256 MiB BAR window, which the default arena can fill; a block that finds no room there goes to host-visible system memory (logged once). A GPU-only reservation uses its paired CPU mapping. Matching source ranges share one copy. The resource descriptor heap keeps its console indices and original CPU bytes. Its shader-visible copy