Repository navigation
RT-RADV-IMPORT-PINS: d3d12: free declined host imports at once and pin the pages of live ones (RADV CS rejection) - #1539
Conversation
create_host_buffer returned E_NOTIMPL for an import the driver put below
the arena with its memory still allocated. The resource's destructor then
handed that memory to the deferred queue, so it outlived the next
submission while the shadow buffer made instead over the same address
guarded its page read-only. On RADV a read-only page under a live
VK_EXT_external_memory_host import makes the kernel reject that
submission and every later one ("The CS has been rejected", then
VK_ERROR_DEVICE_LOST).
Every return after vkCreateBuffer that declines the import now destroys
the buffer and frees the memory before it returns; nothing was submitted
with them, since the resource is registered only on success. A counter of
live slot-133 imports (rt::d3d12::title_host_imports) lets a test see it.
The finding and the design are NateWeav's (coordination issue ProjectLeonida#14,
comments 7141859164 and 7142359977); this implements their description.
Test: d3d12_title_va_test in its imports-on mode (d3d12_geometry_views)
places two buffers, at a page start and 4 bytes into a page, submits with
each alive and checks that no import memory outlives a declined import.
On the RDNA2 iGPU under Wine both land below the arena, the path fixed
here.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RADV checks the pages of a VK_EXT_external_memory_host import again at every submission, and once one of them is read-only the kernel rejects that submission and every later one. The slot-133 shadow trackers and the geometry watch make copied title pages read-only to see the next write, and a page can be both under a shadow and under a live import. A new leonida::kernel_writes::hold pins a range until release() and opens it. Unlike begin_write it records the pin when no opener is set yet (no tracker exists), so a tracker made later passes over the pages too; ShadowPages and the geometry watch already pass over pinned pages. The slot-133 import (create_host_buffer) and the console descriptor heap import take the pin before vkAllocateMemory, so no guard lands between the writability check and the import, and end it on every path that frees the memory: a declined or failed import and the release. The finding and the design are NateWeav's (coordination issue ProjectLeonida#14, comments 7141859164 and 7142359977); this implements their description. As in their tree the pin is unconditional; a driver gate is not done. Tests: kernel_writes_test checks hold and release on the pin set (no opener, with an opener, alongside a file read's pin). d3d12_title_va_test in its imports-on mode makes a shadow over pages, checks that its tracker guards them, then imports the same pages and checks that two submissions leave them writable, that the pin ends with the import and that the tracker guards them again afterwards. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Merged, with the maintainer's approval, after merging
AI-assisted (Claude Code, Claude Opus 5.5). |
|
Post-merge note. I tested The new checks come from So the import over a shadow's pages was taken, and the pin held 64 KiB. There were no validation messages.
Other ctests:
I didn't measure the cost of keeping every live import pinned for its whole lifetime, because that needs a retail boot. On this driver page-aligned slot-133 buffers are imported, and every live import now holds a pin. The pin count is global, so |
|
Independent NVIDIA/Wine follow-up of the exact two implementation commits (599fe9f + 9f82f13) is now building locally. RTX 3070 Ti 8 GiB, NVIDIA 620.73.04, Wine 11.22, clang-cl/xwin; main 42537e7 + owned startup/FSPX/input fixes, isolated task worktree. The pre-pinning control intermittently logs VK_ERROR_OUT_OF_HOST_MEMORY for 512-byte to small-MiB allocations despite substantial free memory. Latest bounded run stopped at 33.336 s on a title assertion after a format-19 1280x720 depth placement returned E_OUTOFMEMORY, before any scripted input. Peak sampled total GPU use 2,347 MiB; minimum available RAM 13.97 GiB. Kernel journal in that run records three host-memory mapping failures. Main’s allocation mutex and six-retry policy are already present in this control. This differs from #1558’s original unsupported D16S8-UAV refusal, which is fixed in the candidate. This is consistent with (not proof of) the guarded-page/import interaction your patch addresses. I am testing kernel_writes and title-VA/geometry cases before repeating the bounded retail control. No skipped compute, assertion or watchdog bypass; package read-only and network isolated. No new implementation claim; raw logs/addresses remain local. AI-assisted. |
|
First NVIDIA follow-up at local head 02f20b221 (exact 599fe9f + 9f82f13 implementation commits) is green: kernel_writes, d3d12_title_va, d3d12_geometry_views, gameinput and gameinput_script pass 5/5 under isolated Wine. The subsequent 180-second bounded retail run completes its limit with no vkAllocateMemory failure log and zero kernel host-memory mapping failures in that interval (the preceding unpinned run had 16 rate-limited allocation-error logs and three kernel mapping failures before a fatal depth-allocation assertion). 25,450/25,450 native graphics PSOs and 16,852 presents succeeded; no fatal title exception or device-loss log. Visually still first-run setup, not a world frame. Assertions/watchdog enabled, no skips/stubs. This is one before/after observation, not a reliability claim or proof that every earlier allocation failure had the same cause. Continuing the bounded comparison. RTX 3070 Ti / NVIDIA 620.73.04 / Wine 11.22. AI-assisted; raw evidence stays local. Count correction: the earlier total accidentally summed the presentation and queue trace layers. This count now uses only XboxPresentation::PresentX, excluding the duplicate queue-layer event. Other observations and limitations are unchanged. |
Item:
RT-RADV-IMPORT-PINS, NateWeav's claim (#14 (comment)). The finding, the measurements and the design are theirs (that comment and #14 (comment)). This implements their description on currentmain, as offered in #14 (comment). @NateWeav, if you'd rather open your own patch, say so and this one closes.Not included:
RT-SHADOW-ALIAS-GUARD(their second claim, the copy cost after the fix).What and why
On RADV, making a page read-only while a
VK_EXT_external_memory_hostimport of it is live makes the kernel reject that submission and every later one:radv/amdgpu: The CS has been rejected, thenVK_ERROR_DEVICE_LOST. The slot-133 shadow trackers guard copied title pages exactly that way, somainloses its device right after the first present on RADV.create_host_buffer(runtime/shims/d3d12_vulkan_device.cpp) now destroys the buffer and frees the memory on every decline aftervkCreateBuffer: below the arena, host-pointer properties, a type or offset mismatch, a failed allocation or bind. Before, the memory waited in the deferred queue while the shadow made instead guarded the same page.kernel_writes::holdpin over their pages (runtime/src/title_page_watch.h, newhold/release) beforevkAllocateMemory, and release it on every path that frees the memory (decline,fail(), the resource destructor,remove_console_heap).ShadowPagesand the geometry watch already pass over pinned pages. A hold records the pin even before a tracker exists and lifts a guard already on the range. Taking it before the allocation means no guard can land between the writability check and the import.Tests
kernel_writes_test: 9 checks of hold and release.d3d12_title_va_test(imports-on mode,d3d12_geometry_views):check_declined_imports: no import memory outlives a declined import across a submission (on the RDNA2 iGPU both buffers land below the arena, the path the first change fixes);check_import_over_shadow: a shadow's tracker guards its pages (control), an import of the same pages keeps them writable across two submissions, the pin ends with the import and the guard returns. On llvmpipe the import is taken and pinned; on the iGPU it is declined and no pin is left.d3d12_geometry_viewsgoes from fail to pass on the iGPU.Measured on the retail boot (RDNA2 iGPU, RADV, Wine; counts only)
mainint3after the device lossAI-assisted (Claude Code, Claude Opus 5.5).