Repository navigation
d3d12: a slot-133 buffer whose pages can't be imported is a shadow at the title's VA, re-copied before each submit - #8225
tibzejoker wants to merge 19 commits into
Conversation
…e PC vtable refuse with E_NOTIMPL The retail title calls device slot 133, past the 128-entry table; the call read an empty entry and jumped to 0. Every slot beyond the PC device's vtable now reaches the generic thunk. Mock test covers slot 133. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ory (VK_EXT_external_memory_host) The retail executable opens the 64 KiB graphics region it has just committed with XMemVirtualAlloc through device slot 48 right after its first queue and fence; the layer answered E_NOTIMPL and the title asserted. The call now answers as the host runtime does on an RTX 4090 and WARP (six cases measured in d3d12_existing_heap_test): the base of a VirtualAlloc allocation committed read-write over its whole size opens a heap of that size, 64 KiB aligned, CUSTOM / WRITE_BACK / L0, SHARED | SHARED_CROSS_ADAPTER | ALLOW_SHADER_ATOMICS; an inner address, a partial or reserve-only commit and a read-only range are E_INVALIDARG. The backing is the range itself, imported with VK_EXT_external_memory_host, which the device and the test device enable when present. CheckFeatureSupport(EXISTING_HEAPS) follows the extension. Placed resources in such a heap are refused (E_NOTIMPL, logged) until the placed path addresses memory outside the arena. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… an uncached one is refused Measured on the RTX 4090 and WARP: PAGE_READWRITE | PAGE_WRITECOMBINE is accepted with CPUPageProperty WRITE_COMBINE, PAGE_READWRITE | PAGE_NOCACHE is E_INVALIDARG. Two new cases in d3d12_existing_heap_test; 8 of 8 match both host devices. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he title's own pages Xbox device slot 133 is (va, desc, state, clear, riid, out): the title places a buffer at the VA of a physical-page range it has just mapped (docs/retail_boot_chain.md 3.4, ItsNotRexed#6915). The proxy now hands it to a handler the Vulkan layer registers (set_placed_at_va_handler), which imports [va, va + width) with VK_EXT_external_memory_host and binds a VkBuffer to it: the CPU's writes there are the GPU's reads with no copy, and the resource's console VA is the title's VA, so views and immediate writes the title names by that VA resolve to it through the buffer VA index. The Xbox flag bits above the PC ones are dropped and the layout made ROW_MAJOR, as slot 76 does; textures are E_NOTIMPL, a misaligned VA E_INVALIDARG, and with no handler (a PC device) the slot refuses with E_NOTIMPL as ItsNotRexed#6953's table does. Not decided here: a shader that adds heap_base to the title's VA (its own V#s) does not reach these pages; that needs the single address space of docs/d3d12_vulkan.md 3.3. d3d12_existing_heap_test: on a VirtualAlloc range and on a view of a pagefile-backed section (the form xmem's physical pages take), the buffer's GPU VA is the address and a GPU copy to a READBACK buffer reads a pattern the CPU wrote after creation; Vulkan validation clean on an RTX 4090. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ler registered by every Vulkan device The PC flag mask was a D3D12_RESOURCE_FLAGS constant past the SDK's last enumerator, which clang-cl with SDK 10.0.26100 refuses as a constant expression; it is an integer now, cast after the AND. The slot-133 handler was registered in create_vulkan_device only, so the standalone device gta6rt --run creates never served the slot; the Device constructor registers it now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # runtime/shims/d3d12_xs_device.cpp
… found in review) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… not import the title's pages RADV under Wine refuses to import a view of a pagefile-backed section (E_OUTOFMEMORY on an RX 9070 XT, found in review), which is the form xmem's physical pages take, so the retail boot stopped at the first 174 MiB placement. An import failure other than a misaligned VA now gives an ordinary DEFAULT buffer of the same description, as ItsNotRexed#6915's stand-in did, logged once: the boot goes on, and the title's writes at that VA don't reach it on such a driver. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…commit re-added it, found in review) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ge check, immediate free, proxy test - A write-combined (or uncached) page in the range is not imported: an RTX 5090 imported such a range and read wrong bytes back (found in review). It takes the ordinary-buffer fallback. - The whole range must be committed, walked with VirtualQuery across allocations (the retail buffer spans three mapped windows); otherwise E_INVALIDARG instead of undefined behaviour in Vulkan. - The imported memory is freed as soon as the submitted work has retired (wait_retire_ticket), not after the next submission: VK_EXT_external_memory_host needs the caller's pages to outlive it, and a title may free them right after releasing the resource. - The PC flag mask is 0x5ff: 0x200, which the host refuses, is dropped. Slot 133 is listed in device_slot_overridden. - xs_proxy_mock_test registers a handler and checks slot 133's argument positions, the flag mask (0x20204 -> 0x4), the ROW_MAJOR rewrite and the iid; d3d12_existing_heap_test checks the write-combined fallback and the partly committed refusal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ich varies from run to run The host runtime answers 64 KiB on some runs and 4 MiB on others for the same allocation (RX 9070 XT, RTX 5090, WARP; found in review), which made the test fail about 1 run in 40. The layer's Alignment must still be 64 KiB for an opened heap, and the host's either of the two values. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s at the offset; uncommitted pages fall back The title places small buffers inside a page too: a 16-byte UAV at a 64-byte-aligned address on an RTX 5090 (found in review), which the import refused with E_INVALIDARG, halting the boot. The import now starts at the page holding the address and the buffer is bound at the offset; an offset off the buffer's alignment takes the ordinary-buffer fallback. A range not fully committed (xmem commits on first touch) also falls back instead of failing. Only a null address or a zero width are E_INVALIDARG. d3d12_existing_heap_test: a buffer 64 bytes into a page reads back the CPU's writes at its own VA; a 1-byte offset and a partly committed range fall back. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ad of E_NOTIMPL The retail title places textures at slot 133 too, and asserted on the E_NOTIMPL (found in review). A texture now gets an ordinary committed DEFAULT texture of the same description, as slot 76 gives one, logged once; it is not on the title's pages. The proxy rewrites a texture's Xbox layout word to UNKNOWN (a buffer's to ROW_MAJOR), as slot 76 does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Wine can report a requested write-combined allocation as ordinary read/write memory. Check the observed protection and retain the fallback expectation when a cache modifier is present; otherwise verify the read/write import. Add PAGE_NOCACHE to keep the unsafe-protection guard covered under Wine. Claim: ItsNotRexed#7913 (comment) Depends on: ItsNotRexed#7218 AI-assisted: Codex
…e starts in the matching state The title's third word at slot 133 is a D3D12_BARRIER_LAYOUT, not a resource state (measured by @dracbat on a retail boot: 0x6 SHADER_RESOURCE for its RT/DS textures, 0x3 UNORDERED_ACCESS for its RT+UAV ones, 0xFFFFFFFF UNDEFINED for the 182 MiB buffer), as PC CreatePlacedResource2 takes it. The proxy passes it to the handler, and a texture's ordinary committed fallback starts in the equivalent legacy state (UNDEFINED and unlisted values give COMMON; a state the description refuses retries with COMMON, so the title always gets its resource). Buffers are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…the title's VA When VK_EXT_external_memory_host refuses the title's pages (write-combined or uncached pages, pages not committed yet, no extension, or the driver's import budget: about 64 MiB on an RTX 3070 Ti), the fallback was an ordinary DEFAULT buffer with neither the title's VA nor its data, so the title's descriptors resolved to nothing (slot 70 wrote a null SRV) and UI draws sampled nothing. The fallback is now a host-visible buffer (VRAM through Resizable BAR where upload buffers use it) whose console VA is the title's address, filled from the title's pages at creation and again before every submission of command lists (VulkanContext::set_before_execute, called from VulkanQueue::execute_now). Only committed, readable pages are read; the rest is zero. GPU writes to the shadow are not copied back. The first per-submission copy of each buffer size is timed and logged. Write-combined pages are read with MOVNTDQA: memcpy read 64 MiB of them in 253 ms on a Core i9-13900K, MOVNTDQA in 13 to 17 ms. Tests: write-combined, uncached, 64 MiB write-combined and half-committed ranges in d3d12_existing_heap_test, two patterns over two submissions each, 0 validation errors on an RTX 4090. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Independent native Windows A/B on RTX 5070 Ti (621.24), Ryzen 7 9850X3D, Windows 11 build 26300, MSVC 19.44.35230 / SDK 10.0.26100, Ninja RelWithDebInfo, Vulkan validation off.
The 174 MiB shadow’s first logged refresh in each run took 18.240, 15.767, and 16.223 ms. These are timings for the CPU-side refresh, with serialized synthetic copies. Synthetic data only. AI-assisted (Codex). |
|
@tibzejoker, a focused clang-cl follow-up for your exact head The repository's default x64 clang-cl configuration rejects Reproduced and checked with clang-cl 23.1.3, xwin SDK 10.0.26100, RelWithDebInfo, on an i9-10900K: cmake -S runtime -B out/scarlett-windows -G Ninja \
--toolchain "$PWD/runtime/cmake/clang-cl-xwin.cmake" \
-DXWIN_DIR=/path/to/xwin-sdk -DLEONIDA_VULKAN_HEADERS_FETCH=ON
cmake --build out/scarlett-windows \
--target gta6rt xs_proxy_mock_test d3d12_existing_heap_test -j 6
No GPU or retail result is claimed by this compiler check; MSVC and hosts lacking SSE4.1 were not tested. No game files were used. Claimed in #8186: #8186 (comment). Depends on: #8225, #7218. AI-assisted: yes (Codex). |
Clang's baseline x64 target cannot inline _mm_stream_load_si128 into copy_guarded. Give only that function the target feature the existing intrinsic requires; keep the MSVC path and global build flags unchanged. Depends on: ItsNotRexed#8225. Claimed in ItsNotRexed#8186, comment7110252121. AI-assisted: yes (Codex).
|
@venetanji thanks: cherry-picked as |
|
Independent build + test: PASS (two notes) AI-assisted (Claude Code). Windows 11 x64, MSVC 19.44.35220, Ninja RelWithDebInfo, NVIDIA GeForce RTX 3080 driver 621.24 / 32.0.16.2124 (Vulkan layer), plus host WARP. Head
Notes:
|
|
Follow-up to the RTX 5070 Ti A/B above (serialized reads passed). Question: can Yes. That's harmless while the copy writes the title's current bytes, but a fault mid-copy zeroes the whole committed run under in-flight readers.
GPU end-to-end (RTX 5070 Ti, 621.24, Ryzen 7 9850X3D, Windows 11 26300, MSVC 19.44.35230, Ninja RelWithDebInfo, Vulkan-Headers 1.4.363 as pinned; validation layers not installed). A local
The PR's own Smallest fix (L130-131): redo a faulting run page by page, so only the pages that fault read as zeros. This is the exact patch measured above; the normal path is unchanged (128 MiB refresh 17.6 vs 18.4 ms): const bool streaming = (region.Protect & PAGE_WRITECOMBINE) != 0;
if (!read) {
std::memset(to + at, 0, run);
} else if (!copy_guarded(to + at, from + at, run, streaming)) {
// A page was decommitted after the VirtualQuery: only the pages that fault read as zeros.
for (std::size_t off = 0; off < run;) {
const std::size_t in_page = reinterpret_cast<std::uintptr_t>(from + at + off) & 4095;
const std::size_t n = std::min<std::size_t>(run - off, 4096 - in_page);
if (!copy_guarded(to + at + off, from + at + off, n, streaming)) std::memset(to + at + off, 0, n);
off += n;
}
}Synthetic data only, no game files. AI-assisted (Claude Code). |
|
Independent retail check of 14dc9af on Linux / Proton 11.0 (wine-11.0) / NVIDIA: pass (A/B, same stack with and without this PR). Setup: Debian 13 (kernel 6.12.115), Ryzen 5 5600X, 32 GB RAM, RTX 3070 8 GB, NVIDIA 610.57.04. Base (both runs): ladder-frame a1751a9 + #7584 b170ab9, #7448 a6b31d5, #7403 b3a53b8, plus local changes: #7110's a9c5960 layout and B5G5R5A1 rule, queue slot 35 (the #7286 rule, through the list unwrap), a cap of 2 concurrent compute pipeline compiles, and the PresentX window shown before its swapchain. This PR was merged by hand into that stack: slot 133 hands a buffer to this PR's handler first and keeps the existing stand-in for everything else (the resolution #8304 describes).
Slot 133's handler returned success on the first buffer (182 MB; only the first call is logged). Not shown: the frames are still black (device slot 57 is unserved on this stack). Not measured: whether the import or the shadow path served the buffer, per-submit cost, and AI-assisted: yes |
|
Windows RX 580, driver 31.0.21924.61, i7-10700F, MSVC 14.44: d3d12_existing_heap passes with this branch integrated over #7218. This includes the cache-modified and partly committed ranges and successive-submit readback cases, addressing the ordinary-buffer fallback seen in our earlier startup run. vk_xbox_physical, vk_xbox_paging and queue_proxy also pass with the before-execute hook combined with #5381's physical-page backend. No assertion skipping or debugger argument rewriting. Testing the slot-70 view routing next; no rendered frame or gameplay claim. No game data or logs included. |
|
Independent verification of head Hardware line: AMD Radeon 890M Graphics (RADV STRIX1, RDNA3.5), RADV / Mesa 26.0.8-1ubuntu0.3, kernel Counts
Why RADV always takes the fallback (the trigger path this head sees on Mesa ≤ 26.0.8). The refusal is in the kernel, not fixable from Vulkan: libdrm's So on RADV/RDNA the shadow is not an edge case: every slot-133 range built from physical-page views takes it, and this head is what makes those draws resolve at the title's VA instead of vanishing. Shader AI-assisted (Claude Code). |
|
RDNA4 verification of head Hardware line: GPU: AMD RX 9060 XT (RDNA4/GFX1200), RADV / Mesa 26.0.8-1ubuntu0.3, Ubuntu 26.04 LTS, kernel Builds — both from a clean clone, 0
Counts
The probe's failing case from #7218 now passes on RDNA4: the pagefile-backed section view ( The import is still refused by the kernel ( The 8 deterministic Wine failures are the pre-existing RADV set, the same d3d12 failures the #7218 head produced on this same GPU (plus AI-assisted (Claude Code). |
…te since the last submission ItsNotRexed#8225 re-copies every live shadow in full before each ExecuteCommandLists: 174 MiB on retail, about 20 ms per submission. Now each shadow (ShadowPages) keeps the title's read-write pages read-only between submissions, cache attribute kept (PAGE_READONLY | PAGE_WRITECOMBINE for write-combined pages). A write faults; a vectored handler, first in the chain, makes the 64 KiB around it writable again and lets the write go on. Before each submission a VirtualQuery walk copies the pages that are read-write again (written, newly committed, or newly mapped), protects them first, and skips the ones still protected. Pages not committed are zeroed once. What a write fault can't see is handled so the GPU still gets every write: - a physical page xmem maps at more than one address: xmem reports it (title_page_watch.h) and the shadow copies it at every submission; - kernel writes, which fail with ERROR_NOACCESS on a read-only page instead of faulting: the title's ReadFile, ReadFileEx and ReadFileScatter go through new file shims that pin and open the destination first (until the call returns, or until the OVERLAPPED completes) and retry once on ERROR_NOACCESS; - pages that can't be protected (VirtualProtect refuses, copy-on-write or the title's own read-only pages, or no handler) are copied at every submission, as before. A run of pages that faults during the copy is redone page by page, so only a decommitted page reads as zeros. Tests (d3d12_existing_heap_test): a pattern, then one rewritten page, an unchanged submission and a write from another thread, on half-committed, write-combined and offset ranges; pages committed, decommitted and recommitted under a live shadow; a write through a second view of the page, which does not arrive without the alias mark (the negative control) and arrives with it; a plain ReadFile into a watched page fails with ERROR_NOACCESS (control) and succeeds, synchronous and overlapped, through the shims' path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n't be imported is a shadow at the title's VA, re-copied before each submit Squashed from ItsNotRexed#8225 by tibzejoker, head 14dc9af (security scan PASS). Own commits 49410a5 and 14dc9af; test conflict with ItsNotRexed#7218's refresh resolved by renaming the loop's locals. Merged with 097e9f4 (fallback buffer aliased at the title's VA): the shadow is the path now, since it holds the title's bytes. The alias stays only behind it, for a shadow that cannot be allocated, so draws still resolve instead of failing with an unknown resource.
Claimed in the coordination issue: #8047 (comment)
Depends on: #7218. This branch is #7218's head plus one commit,
49410a52.What and why
#7218 imports the title's slot-133 pages with
VK_EXT_external_memory_host. When the import is refused, it falls back to an ordinary DEFAULT buffer. A refusal happens for write-combined or uncached pages, uncommitted pages, a missing extension, or the driver's import budget, which @Silliana measured at ~64 MiB cumulative on an RTX 3070 Ti. That fallback buffer has neither the title's VA nor its data, so the title's views name an address no buffer holds: slot 70 writes a null SRV (@Silliana), and the UI passes sample nothing (@controldebils).With this change, a refused buffer import gets a shadow instead:
Map()returns the title's own pages.ExecuteCommandListssubmission, from the committed pages. AVirtualQuerywalk copies committed readable regions and zeroes the rest, and the copy sits in an SEH frame, so a page decommitted mid-copy reads as zeros instead of faulting. The per-submit hook isVulkanContext::set_before_execute, called at the top ofVulkanQueue::execute_now.MOVNTDQA, SSE4.1). A plainmemcpyfrom WC pages measured 253 MiB/s, against about 4-5 GiB/s with streaming loads.Cost, and what's not done
Measured on an i9-13900K + RTX 4090, with a shader build running alongside: a 64 MiB WC range re-copies in 12.7-17 ms, and 256 KiB in 0.05-0.07 ms. Every live shadow is re-copied in full on each submission, so a fully shadowed 182 MiB retail range would cost roughly 40-50 ms per
ExecuteCommandLists. That's enough to get correct frames on drivers that can't import, not to make them fast. The follow-up is copying only dirty pages (#5381's tracking) or only the ranges the submitted lists reference. Concurrent submissions serialize on the shadow mutex during the copy. On drivers that import, like the RTX 4090 with read-write pages (#7492 / #7499 / #7550), none of this runs.Tested
RTX 4090, driver 617.42, Windows 11 26200, MSVC 2022 RelWithDebInfo,
LEONIDA_VK_VALIDATION=1, 0 validation errors:d3d12_existing_heap_test, new cases: a write-combined range, an uncached range, a 64 MiB WC range and a half-committed range. Each checks that the GPU VA equals the address, then writes a pattern after creation, reads it back through a GPU copy in the next submission, and repeats with a second pattern on the following submission. The half-committed range matches on its committed half, reads zero elsewhere, and nothing faults. Under Wine, the reported-protection logic from d3d12_xs: device slot 133 (CreatePlacedResourceX) makes a buffer on the title's own pages (VK_EXT_external_memory_host) #7218 is kept, so the helper passes whether the range is imported or shadowed.xs_proxy_mock_testanddevice_proxy_testpass.Not run: Wine, a GPU without ReBAR or without the extension, and the retail boot (my copy's shaders are still translating). Synthetic only, no game data.
AI-assisted: yes (Claude Code).
🤖 Generated with Claude Code