Repository navigation
Runtime: zero-fill default-heap buffers outside the arena (D3D-71) - #655
Conversation
|
Tested b9cf389 on RTX 5070, driver 621.24, Windows 11: pass. Clean build links, ctest 15/15 including bink_decode and bink_audio. The branch is far behind main (about 2,300 commits), so a rebase is probably needed before merge. |
D3D12 committed resources start zeroed unless the heap has
CREATE_NOT_ZEROED. Arena buffers are zeroed through its mapping, but
device-local buffers outside it were not ("default-heap buffers are not
zero-filled yet"). They are now queued on the context and filled with
vkCmdFillBuffer by the next submission on any queue, ahead of its lists.
That submission publishes the same initialisation semaphore as the
storage-image setup, so a list on another queue that uses the buffer first
waits for the fill. A buffer destroyed before any submission leaves the
queue, and a failed submission puts its fills back.
A queue being destroyed now clears that shared semaphore if it published
it: the queue is idle, so the work is done, and a later submission on
another queue would otherwise wait on a destroyed semaphore. With buffer
fills publishing it often, d3d12_vulkan_device_test hit exactly that
(vkQueueSubmit: invalid pWaitSemaphores, then a crash).
d3d12_vulkan_device_test (a device without the arena) reads a fresh
default buffer back as zeros after dirtying recycled memory, and checks
that a CREATE_NOT_ZEROED buffer written in the same list keeps the copy.
b9cf389 to
63ab7be
Compare
|
Independent native D3D12 WARP vs Leonida RTX 4060Ti placed-buffer alias validation. On current main f847748, Resource::create_placed_buffer() unconditionally memset(device_.arena.mapped + va_, 0, desc_.Width) in runtime/shims/d3d12_vulkan_device.cpp. Synthetic DEFAULT heap 2x64KiB and placed buffer A offset 0: GPU upload distinct pattern, fenced readback A exact; CreatePlacedResource B at SAME offset 0 but NEVER use or transition B; fenced readback A. Native WARP A stays exact 0/65536 wrong; Leonida RTX A becomes 65280/65536 wrong, byte0 expected 93 got 0, no VUID. Disjoint B at offset65536 passes on both. Prior GPU work fenced; B never used. Repro source/results in new local LeonidaRuntimeGapAuditRound3_20261122 only, no proprietary data. Your PR #655 body explicitly says placed buffers are never filled, yet current #655 patch changes only committed default buffer path and retains create_placed_buffer memset from main. Could you incorporate removing the initialization and a native-vs-Vulkan overlapped unused B regression into your existing PR, or advise scope? To avoid competing with your initialization claim I am not submitting a separate PR for this bug. AI-assisted synthetic investigation. |
|
Tested 63ab7be on Windows 11 (MSVC BuildTools 2022, Ninja, RelWithDebInfo, -j 4; no Vulkan validation layer installed), one GPU at a time, device line confirmed: AMD Radeon RDNA2 iGPU (driver 26.10.1) and NVIDIA RTX 5080 (driver 616.92). Ran AI-assisted. |
Flyander
left a comment
There was a problem hiding this comment.
Review of the default-heap zero-fill path.
| zero_buffers.swap(context_.zero_pending_); // any queue can fill a buffer | ||
| } | ||
| for (const auto& zero : zero_buffers) | ||
| context_.vk.vkCmdFillBuffer(command_buffer, zero.buffer, 0, VK_WHOLE_SIZE, 0); |
There was a problem hiding this comment.
[P2] Cover the trailing bytes of non-four-byte buffers
VK_WHOLE_SIZE does not fill a trailing 1–3 bytes when the remaining buffer length is not a multiple of four; Vulkan specifies that it fills only the nearest smaller multiple. This code accepts any nonzero Width, and the buffer is allocated at that exact size, so a committed buffer of 5 bytes gets only a 4-byte zero-fill and its final byte remains stale. Please ensure initialization covers the complete D3D12 buffer range. Vulkan vkCmdFillBuffer specification.
Item: D3D-71 (claimed in #374)
Rebuilt on
mainnow that #291 is merged: one commit on top ofmain, with no dependency left.main's backend has changed since the first version (split locks, several queues), so the change is re-implemented rather than rebased.D3D12 committed resources start zeroed unless the heap has
D3D12_HEAP_FLAG_CREATE_NOT_ZEROED. Arena buffers are zeroed through its mapping, but device-local buffers outside it were not; the layer only logged "default-heap buffers are not zero-filled yet".Change
VulkanContext::zero_on_next_submit(id, buffer)queues the buffer, guarded bystorage_mutex_likenote_storage_image. The nextExecuteCommandListson any queue recordsvkCmdFillBufferfor each queued buffer and a transfer → all-commands barrier, ahead of its lists.CREATE_NOT_ZEROEDskips the fill. Placed buffers (create_placed_buffer) are never filled, since D3D12 doesn't zero them and they may alias live data. The log line is removed.A latent bug this exposed (fixed here).
~VulkanQueuenever cleared the shared initialisation semaphore when it was the one that published it. So a later submission on another queue could wait on a destroyed semaphore. Storage-image setup rarely triggers this; buffer fills do. Without the fix,d3d12_vulkan_device_testfailed with "vkQueueSubmit(): pWaitSemaphores[0] Invalid VkSemaphore", then crashed. The destructor now clears the semaphore after its idle wait, when the work is known to be finished.Test (
d3d12_vulkan_device_test, whose device has no arena): a default buffer is filled with0xaband released, then a new one is read back as all zeros. ACREATE_NOT_ZEROEDbuffer written by a copy earlier in the same list reads back the copy. As before, the zero check also passes without the fill on NVIDIA, whose driver hands out zeroed allocations; it guards the behaviour rather than reproducing the bug there.Tested on NVIDIA GeForce RTX 4070 SUPER, driver 32.0.16.1088, Windows 11, MSVC 2022:
ctestpasses 129/129.LEONIDA_VK_VALIDATION=1,d3d12_vulkan_device_test,d3d12_compute_test,d3d12_draw_test,d3d12_descriptor_testandd3d12_present_testpass with 0 validation errors.No game files. AI-assisted.