RT-RADV-IMPORT-PINS: d3d12: free declined host imports at once and pin the pages of live ones (RADV CS rejection) #1539
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!1539
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1539/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@aslan2142 on GitHub · 2026-11-25 03:52 UTC · original
aslan2142:radv-import-pins→main· +255 −12 · 5 files · 4 commits · merged 2026-11-25 08:28 UTCItem:
RT-RADV-IMPORT-PINS, NateWeav's claim (#14). The finding, the measurements and the design are theirs (that comment and #14). This implements their description on currentmain, as offered in #14. @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).
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 #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 <[email protected]>b07b9ecb0) into radv-import-pins d4f3e0bbc63f81d46ac' into HEAD 8665eee910@aslan2142 on GitHub · 2026-11-25 08:28 UTC · original
Merged, with the maintainer's approval, after merging
maininto it. @NateWeav, thank you: the finding, the measurements and the design are yours. This only implements your description, and the commits say so.mainloses its Vulkan device right after the first present on RADV. With it,mainruns the retail boot for 15 minutes on an RDNA2 iGPU without a crash (counts in the description).main+ this branch (llvmpipe and an RDNA2 iGPU): nothing goes from pass to fail.d3d12_geometry_viewsgoes from fail to pass on the iGPU.kernel_writes_testandd3d12_title_va_testcover the hold/release pin and the declined import.RT-SHADOW-ALIAS-GUARD(the copy cost, about 600 MiB per submission here), is being carried the same way, with credit, from your description in #14.main3f81d46ac+8665eee91: it merges cleanly; the semantic suite passes (487 files, 6,279 tests, 0 files failed); the 14 docs and writer tests pass;check_no_game_data.pyis clean on the 5 changed files.AI-assisted (Claude Code, Claude Opus 5.5).
@adrianmjim on GitHub · 2026-11-25 09:04 UTC · original
Post-merge note. I tested
d4f3e0bbcapplied ontomain42537e7b6; the merged head8665eee91only adds a merge ofmainon top. The test machine is Windows with an AMD Radeon RX 7900 XT (RDNA3) and AMD driver 32.0.32029.2010 (26.11.2). The card has no Resizable BAR, the OS is Windows 11 build 26300, and the build is VS 2022 RelWithDebInfo. Host-pointer imports are taken on this driver, so this is the pin path on real AMD hardware, not llvmpipe. No game files.The new checks come from
d3d12_title_va_test.exewithLEONIDA_GEOMETRY_MB=16 LEONIDA_VK_VALIDATION=1:So the import over a shadow's pages was taken, and the pin held 64 KiB. There were no validation messages.
d3d12_geometry_views: with the default arena this test fails on this card onmaintoo. On a GPU without Resizable BAR the 256 MiB arena fills the 256 MiB BAR heap, so the views can't be allocated ("CPU-written table V# 0/64"); that is #1678, unrelated to this PR. WithLEONIDA_ARENA_MB=240the whole test passes with this PR: 64/64 for the table V#, the CBV and the root view, and the four lines above unchanged.Other ctests:
d3d12_geometry_viewswith the default arena, as above. The 23 are:kernel_writes,xmem_write_watch,title_write_watch,title_write_watch_onvk_host_at_aliasing,vk_host_region_importd3d12_existing_heap(plus_no_write_watchand_write_watch),d3d12_xmem_placed,d3d12_console_descriptor_heapxbox_linear_texture_map,xbox_linear_gpu_stagingd3d12_title_va,d3d12_geometry,d3d12_geometry_views,d3d12_title_index_window,d3d12_title_vertex_windowd3d12_api_descriptor_copy(and_off),d3d12_rebound_tables(and_off),d3d12_rebound_second_devicectest -j 6: 398 of 402 without failures (385 passed, 13 skipped), 4 failed. Three failures are the same as onmain:d3d12_texture_tiles,d3d12_clearandd3d12_geometry_views. The fourth,xmem_no_write_watch, failed once under-j 6and passes 3 of 3 alone, on this PR and onmain.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
for_each_pin, called by every shadow-tracker refresh and every geometry-watch arm, now takes its mutex and walks every live pin, even for ranges no import touches. Before, it returned at once on a zero count. A boot comparing the shadow and descriptor-heap refresh times before and after would show whether that matters.@djrolfes on GitHub · 2026-11-25 11:20 UTC · original
Independent NVIDIA/Wine follow-up of the exact two implementation commits (
599fe9f22+9f82f136f) is now building locally. RTX 3070 Ti 8 GiB, NVIDIA 620.73.04, Wine 11.22, clang-cl/xwin; main42537e7b6+ 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.
@djrolfes on GitHub · 2026-11-25 11:26 UTC · original · edited 2026-11-25 19:14 UTC
First NVIDIA follow-up at local head 02f20b221 (exact
599fe9f22+9f82f136fimplementation 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.