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). |
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