Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions docs/d3d12_vulkan.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 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
encodes each resolved buffer's offset from the arena base. CPU writes through either physical mapping,
Expand Down Expand Up @@ -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
Expand Down
17 changes: 15 additions & 2 deletions runtime/shims/d3d12_title_buffer_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class TitleBufferWindows {
};
std::vector<Block> blocks_;
VkDeviceSize reserved_{};
bool logged_host_fallback_ = false;

public:
VkDeviceSize reserved() const { return reserved_; }
Expand Down Expand Up @@ -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<unsigned long long>(b.capacity >> 10));
}
}
Comment on lines +67 to +81

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left this one as it is:

  • Size: b.capacity is the 4 MiB block size, or the view's size when that is larger, so >> 10 loses nothing that matters in a once-only log line.
  • Format: %llu with static_cast<unsigned long long> is how the rest of this header and d3d12_geometry_views.h print sizes, and it is portable on every compiler the runtime builds with.

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) {
Expand Down