Repository navigation
Runtime: put the descriptor table in device-local memory (D3D-76) - #696
Conversation
6ca6d9a to
aa21d11
Compare
|
A recoverable queue-submit failure loses a newly registered SRV on aa21d11. The next ExecuteCommandLists succeeds, but the shader reads the fallback for all 64 texels. The same retry on parent c432cdc returns the intended texture. I extended the synthetic d3d12_descriptor_test locally. After its existing 8×8 texture and set 0 had been uploaded and sampled successfully, I created a second SRV on that texture with R and B swapped. I then executed an empty closed D3D12 list twice, without changing the descriptor in between. For the error case, a proc-address wrapper returned VK_ERROR_OUT_OF_HOST_MEMORY on the first vkQueueSubmit without forwarding it, then forwarded every subsequent call. The runtime reported unsupported for that first execute, success for the retry, and the subsequent queue fence completed. The existing compute shader sampled using the new SRV bytes and the original wrap sampler on the runtime's set 0.
At (0,0) the expected swapped RGBA8 was (128,0,0,255); the fallback was (0,0,0,0). RTX 5080, Windows, driver 616.92, Khronos validation enabled. The stock test passed on both revisions. The upload, retry, sampling and readback ran on the real device. The single submit error was injected. upload_table() consumes take_changes() and clears table_dirty_ during command recording, before VulkanQueue::execute knows whether the transfer was submitted. Retaining the upload obligation until successful submission, or forcing a full table upload after a rejected submit, would let this retry recover. The test primes the fallback and table first, so the finding is specific to a later incremental insertion. |
aa21d11 to
f6f9dea
Compare
|
The one failing check is Everything that touches this change is green: |
|
Tested f6f9dea merged onto main 762893f on NVIDIA GeForce RTX 4060 Ti (Ada), driver 32.0.16.2124 (NVIDIA 621.24), Windows 11 Home 26300, MSVC 2022 / Ninja, Vulkan SDK 1.4.363: pass.
AI-assisted. |
f6f9dea to
db3dc92
Compare
|
Reproduced the shape of it and fixed it in Fix:
New head: |
|
Re-ran the original submit-injection probe on db3dc92, RTX 5080 / NVIDIA 616.92, Windows 11, Khronos validation enabled. The wrapper returned VK_ERROR_OUT_OF_HOST_MEMORY once without forwarding the first vkQueueSubmit. The first execute reported unsupported, then the unchanged closed list succeeded and its fence completed. The shader read the expected swapped SRV for 64/64 texels; zero matched the unknown-key fallback. Pixel (0,0) was (128,0,0,255). Before the fix, including on f6f9dea, the same retry returned (0,0,0,0) for all 64. The no-injection control also matched 64/64, the stock descriptor test exited 0, and the validation layer reported no errors. This verifies the commit callback on the normal queue submission path for the incremental insertion case I reported. |
db3dc92 to
c0ec562
Compare
AI-assisted. Set 0 binding 2 is the table every T#/S# lookup probes. BindlessSet allocated it HOST_VISIBLE | HOST_COHERENT and flush() memcpy'd into the mapping, so a divergent lookup read it over PCIe: 19.5x slower for T#+S# pairs and 46.2x for a divergent miss at 100k entries on an RTX 2060 SUPER (vk_descriptor_bench, ItsNotRexed#639; 58-796x on the 5080). The table now lives in DEVICE_LOCAL (HOST_VISIBLE kept as a fallback for a device without it). flush() takes the command buffer that will use the set and uploads only what changed: the whole table from a mapped staging buffer when the buffers were just created (first use or growth), and the changed slots with vkCmdUpdateBuffer otherwise, which copies the data into the command buffer while recording so no staging bytes are read at execution. A TRANSFER_WRITE -> SHADER_READ barrier follows, before the draws. DescriptorTable tracks the slots that insert, replace, erase, clear and grow touched, including both slots of a relocation, so a flush no longer rebuilds an 80 MiB table for one descriptor. A command buffer whose vkQueueSubmit is rejected never runs the upload, so the set keeps the obligation: VulkanQueue::execute reports the submit result through a commit callback, and the set rebuilds the table on the next flush, which also reports flush_needs_idle() and makes the device wait before it. The same wait now honours the pre-existing contract for replaced/erased entries and for growth (the device ignored flush_needs_idle() before), and frees the retired buffers once the queue is idle instead of at teardown. Verified on an NVIDIA RTX 2060 SUPER, Linux 620.73.04, Vulkan 1.4.357: - ctest 10/10, including descriptor_table cases for the change list, relocation marking and consume-once reads. - vk_bindless_test with LEONIDA_VK_VALIDATION=1: 14 draws (probe depth, erase, relocation, growth 64 -> 512 slots, rebind, failed-submit retry, other view, removal) read back exact, table in device-local memory in both descriptor-indexing configurations. With the retry disabled the test is red. - GPU suite 64/91 with the same 27 64-wide skips as main, 0 failures; 91/91 with LEONIDA_W64_EMULATE=1. No game data; synthetic fixtures only.
c0ec562 to
e6eaecd
Compare
|
Thank you — that is the confirmation the fix needed, and it pins the mechanism: the retry path is the commit callback, not the old memcpy. One honest caveat: you re-ran
So the case you exercised is the same scenario with a different copy underneath it. If the extended Current head |
|
Tested e6eaecd on Windows 11, NVIDIA GeForce RTX 3060 (Ampere), driver 616.64, Vulkan SDK 1.4.363.1, clang-cl 23 + lld-link against the MSVC 14.44 CRT and Windows SDK 10.0.26100: pass.
So on Windows the HOST_VISIBLE penalty at 100k is larger than on the RTX 2060 SUPER/Linux run (46.2×). The 214 MiB |
|
Thank you — third GPU, first on Windows with clang-cl, and the first on the final head. The 28/29 with validation is useful: the one failure is the Your 121.5x is the strongest number in the thread, and it also caught something worth fixing in my own write-up: with
On the older 80 MiB table the same benchmark measured 46.2x / 19.5x, so the penalty tracks the footprint — and Windows/WDDM roughly doubles it at the same 20 MiB size (your 121.5x). Both directions point the same way: the table belongs in DEVICE_LOCAL, and the remaining placement work (SHADER-100) is still worth doing. I have updated the PR body with your numbers and the re-run. Thanks again for the injection-free data point on the loader path. |
D3D-76 (see #313). Depends on: #639, whose benchmark this measures with.
Every
T#/S#lookup in a translated shader probes the table at set 0 binding 2.BindlessSetallocated itHOST_VISIBLE | HOST_COHERENTandflush()memcpy'd into the mapping, so divergent lookups read it over PCIe. Measured withvk_descriptor_benchon an RTX 2060 SUPER (Linux, 620.73.04, Vulkan 1.4.357; default sizes, full run, net wave µs/1M lookups):T#+S#pairs at 100k: 757 vs 3,145 (4.2×). The penalty scales with the table's footprint: on the pre-relocation 2M-slot / 80 MiB table the same benchmark measured 46.2× and 19.5×.main's relocation strategy (make_probe_slot) has already brought the 100k table to 524,288 slots / 20.00 MiB / 19.1% load, which is the size this run uses; @rafaelpssz measured 121.5× / 89× at that same 20 MiB size on Windows/Ampere, so the placement still matters and stays in SHADER-100.What changed
DEVICE_LOCAL | TRANSFER_DST(withHOST_VISIBLE | HOST_COHERENTkept as a fallback for a device without device-local memory), plus a mapped staging buffer.flush(VkCommandBuffer)uploads only the slots whose entries changed — the whole table when it grew or was never uploaded — recordsvkCmdCopyBufferand aTRANSFER_WRITE → SHADER_READbarrier in the command buffer thatset_bindless_preparealready hands it. No API or shader-contract change.DescriptorTablenow records the slots that insert, replace, erase, clear and grow touch (including both slots of a relocation), so a flush no longer rebuilds an 80 MiB table for one new descriptor.vkCmdUpdateBuffer, which copies into the command buffer while recording; the mapped staging buffer is written only for buffers that were just created (first use or growth), so a copy still in flight never reads bytes the CPU rewrites.vkQueueSubmitkeeps the upload pending:VulkanQueue::executereports the submit result back (set_bindless_commit), and the set forces a full table upload on the retry (table_upload_result(false)), which also reportsflush_needs_idle(). @Vonsek's recovered-submit case on the first revision (aa21d11) is the regression test.flush_needs_idle()(it ignored it before): replaced/erased entries and growth wait for the queue before flushing, and retired buffers are freed once the device is idle instead of at teardown.Verified on NVIDIA RTX 2060 SUPER, Linux 620.73.04, Vulkan 1.4.357:
ctest: 10/10, including a newdescriptor_tablecase for the change list (insert/replace/erase/grow, consume-once,read_slot, out-of-range refused).vk_bindless_testwithLEONIDA_VK_VALIDATION=1: 14 draws (probe depth, erase, growth 64 → 1024 slots with the binding rewritten, rebind, a failed-submit retry, other view, removal) read back exact, and both descriptor-indexing configurations report the table in device-local memory. Mutation check for the retry: with it disabled, the failed-submit draw reports 8192 bad pixels.762893f): 64/91 pass with the same 27 skips asmain(all 64-wide subgroup), 0 failures; 91/91 withLEONIDA_W64_EMULATE=1.The anchor the shader contract advertises is untouched:
desc_probeintools/rdna2spirv.pyand the 10-dword entry layout are the same. AI-assisted. No game data; synthetic fixtures only.