Skip to content

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

Closed
tibzejoker wants to merge 19 commits into
ProjectLeonida:mainfrom
tibzejoker:slot133-shadow
Closed

tibzejoker wants to merge 19 commits into
ProjectLeonida:mainfrom
tibzejoker:slot133-shadow

Conversation

@tibzejoker

Copy link
Copy Markdown
Contributor

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:

  • The buffer: host-visible and coherent (device-local too with ReBAR, as upload heaps choose), persistently mapped. Its console VA is the title's VA, registered in the buffer VA index exactly like an imported buffer, so views and immediate writes by that VA resolve to it. Map() returns the title's own pages.
  • The fill: at creation, and again before every ExecuteCommandLists submission, from the committed pages. A VirtualQuery walk 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 is VulkanContext::set_before_execute, called at the top of VulkanQueue::execute_now.
  • Write-combined regions are read with streaming loads (MOVNTDQA, SSE4.1). A plain memcpy from WC pages measured 253 MiB/s, against about 4-5 GiB/s with streaming loads.
  • No copy-back: GPU writes to the shadow aren't copied back to the pages, as the code comment says.
  • Unchanged: the import path, and textures (which get the committed texture in their barrier-layout state). The plain DEFAULT buffer stays as a last resort if the shadow itself can't be made.

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_test and device_proxy_test pass.

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

Pipodi and others added 18 commits November 23, 2026 16:30
…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>
@SkillIssueXO

Copy link
Copy Markdown

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.

  • Unmodified 49410a52: 27/27 focused test executions. d3d12_existing_heap, device_proxy, device_proxy_trace, and all six xs_proxy_mock modes each passed three times. The small WC and uncached cases reported protection 0x404 and 0x204 and exercised the shadow path.
  • 174 MiB mixed-region case: 3/3 pass. A test-only extension to d3d12_existing_heap_test split a VirtualAlloc2 placeholder into adjacent 74 MiB WC, 96 MiB read-write, and 4 MiB uncommitted regions, verified with VirtualQuery. The fallback kept the supplied GPU VA. Two fence-separated GPU copies each matched a different CPU-written pattern across all 170 MiB of committed data and read zeros from the 4 MiB tail.
  • Parent control a3eae955: 3/3 failures with the same test source. The fallback returned a different GPU VA, so the new check stopped before readback.

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

@venetanji

Copy link
Copy Markdown
Contributor

@tibzejoker, a focused clang-cl follow-up for your exact head 49410a52fc6684f09692d551815fd385c73be7fc: commit 300a4bc1e, based directly on this PR. It is one file / three added lines and is ready to cherry-pick if useful.

The repository's default x64 clang-cl configuration rejects _mm_stream_load_si128 in copy_guarded with four errors: the intrinsic requires sse4.1, while the caller is compiled for baseline x64. The commit gives only copy_guarded a Clang/x64 target("sse4.1") attribute, retaining the existing streaming loads without adding global CPU flags. The guard excludes the MSVC compiler path.

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
  • Unmodified exact head: four SSE4.1 intrinsic errors in the Vulkan-device object, with no extra CPU flags.
  • Patched exact head: all three targets build under the same default flags; six xs_proxy_mock modes pass under Wine 11.20.
  • A separate synthetic probe using the source copy helpers passes 22,528 ordinary/streaming aligned and unaligned copies with destination guards, plus a readable/reserved/no-access/read-only page walk. Removing the three-line attribute from that probe reproduces the same four compile errors. The fixed object retains four movntdqa instructions.

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

Copy link
Copy Markdown
Contributor Author

@venetanji thanks: cherry-picked as 14dc9af52 with your authorship. The target("sse4.1") attribute applies only to the streaming-copy function under Clang, and the MSVC path is unchanged. Rebuilt with MSVC: d3d12_existing_heap passes on an RTX 4090 with validation (all shadow cases, including the 64 MiB WC range, and 8 of 8 host cases). AI-assisted (Claude Code).

@MartinIndra02

Copy link
Copy Markdown
Contributor

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 14dc9af52, merged locally with current main 867d922f0 (d3d12_vulkan_device.cpp auto-merged).

Test Result
d3d12_existing_heap_test.exe exit 0. Slot-133 buffers on a VirtualAlloc range, 64 bytes into a page, and a section view: GPU VA is the address, a GPU copy reads the CPU's writes. The write-combined range goes through the shadow path: each submission reads the pages' latest bytes. vulkan vs host WARP: 8 OpenExistingHeapFromAddress cases match
xs_proxy_mock_test.exe exit 0, PASS (9 allocations refused on purpose)
allocator_proxy_test.exe exit 0, 3 backend(s) passed
gta6rt builds

Notes:

  • The shadow cost the PR logs, measured on this machine: slot-133 shadow buffer of 256 KiB: ... 0.044 ms, and of 65536 KiB: ... 13.541 ms (4726 MiB/s), paid at every submission. A title that places one large write-combined buffer and submits several times per frame would spend most of a 16 ms frame copying. The log line says so. If big shadows are expected in practice, copying only on a dirty write (a write watch, or comparing against the last copy) may be needed later.
  • d3d12_existing_heap_test.cpp lines 335 and 355: warning C4456: declaration of 'pages' hides previous local declaration (new in this PR; the target is /W4).

@SkillIssueXO

Copy link
Copy Markdown

Follow-up to the RTX 5070 Ti A/B above (serialized reads passed). Question: can refresh_shadows rewrite a shadow that an earlier submission still uses? Tested 49410a52; 14dc9af52 only adds a Clang-gated attribute, so its MSVC build is identical.

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.

  • VulkanQueue::execute_now runs before_execute_ right after wait_for_room() (runtime/src/vulkan_backend.h:2161-2163). wait_for_room() (L2972) only blocks at kMaxQueuedCommandBuffers = 64. DeviceState::refresh_shadows (runtime/shims/d3d12_vulkan_device.cpp:713-729) takes only shadow_mutex and never consults the retire tickets, so it writes mapped shadows while earlier submissions are still executing.
  • For a valid guest that's invisible while the copy writes the title's current bytes: in-flight work reads bytes the guest leaves alone, and they're rewritten with the same values. GPU writes being overwritten is the documented one-way limit (L2102-2103).
  • The exception: copy_title_pages zeroes the whole VirtualQuery run when copy_guarded faults (L130-131). If the title decommits one page nothing uses while a refresh copies that run, every committed byte of the run reads 0 until the next refresh.

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 --ab-refresh mode in d3d12_existing_heap_test uses a 128 MiB write-combined slot-133 shadow. S1 interleaves independent busy copies with 64 copies of the shadow's first MiB into a readback buffer. S2, executed right after S1 without waiting, copies that MiB once more. The guest acts 2 ms into S2's refresh and never touches the first MiB. S1 was still running when S2's refresh returned in all 60 runs. 20 runs per row:

Guest action during S2's refresh 49410a52: S1 samples wrong S2 wrong + fix: S1 samples wrong S2 wrong
rewrites a disjoint 1 MiB 0/1280 0/20 0/1280 0/20
decommitted the last 64 KiB before S2 (serialized) 0/1280 0/20 0/1280 0/20
decommits the last 64 KiB now 895/1280 (20/20 runs) 20/20 0/1280 0/20

The PR's own d3d12_existing_heap_test passes with and without the fix. A CPU probe of the same two functions (verbatim L89-134) gives the same split: 70/70 corrupted, 0/70 with the fix, 0/70 for both controls, on WC and RW.

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

@Doorriiaann

Copy link
Copy Markdown

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. gta6rt cross-built with clang-cl 19 + xwin (SDK 10.0.26100), SDL3 GameInput shim on. Own 1.0.2.1 copy, gta6rt --run, LEONIDA_D3D12=vulkan, translated shader work folder, network off. The run is inside a gamescope window.

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

without this PR with this PR
run length 149 s (stopped by me) 120 s (stopped by me)
ExecuteCommandLists failed, "unknown resource" 226,187 of 452,770 0 of 325,710
DrawInstanced 678,724 488,559
exceptions 0 0
peak memory (scope) 12.7 GB 10.7 GB

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 ctest d3d12_existing_heap under Wine.

AI-assisted: yes

@aidity

aidity commented Nov 23, 2026

Copy link
Copy Markdown

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.

@GustawMatuszewski

Copy link
Copy Markdown
Contributor

Independent verification of head 14dc9af52, not a review of the design (I have no stake in the branch).

Hardware line: AMD Radeon 890M Graphics (RADV STRIX1, RDNA3.5), RADV / Mesa 26.0.8-1ubuntu0.3, kernel 7.0.0-43-generic, Wine 11.18 Staging, Xwayland. Own clone of refs/pull/8225/head, no game files. (Note the Mesa: this is the older stack than @miguelsilva5989's 26.2.6 run, which matters for the error code below.)

Counts

run result
d3d12_existing_heap under Wine on RADV exit 0, every expectation passes — including the #7218 line 186 that failed before this head: pagefile-backed section view gets the title's VA and a GPU copy reads the CPU's writes through the shadow; also the write-combined, uncached, 64 MiB WC and half-committed shadow cases
Linux native build of the same head, full ctest 61 tests, 59 passed, 0 failed, 2 skipped (shader_library_corpus, vk_sync_validation), 37.4 s, exit 0
Wine ctest -R ^d3d12 inconclusive: aborted after 8 of 104 tests (1 passed, 7 timeouts at -j 2 under Wine on this box). Says nothing about your head.
shadow copy, from the test's own log 256 KiB in 0.006–0.026 ms (9.5–43 GiB/s)

Why RADV always takes the fallback (the trigger path this head sees on Mesa ≤ 26.0.8). vkGetMemoryHostPointerPropertiesEXT answers a memory type for any pointer (radv_device.c validates nothing), so the layer's pre-checks pass; then vkAllocateMemory refuses the pagefile-backed section view, and 26.0.8 predates Mesa !40574, so the failure is VK_ERROR_UNKNOWN, not VK_ERROR_INVALID_EXTERNAL_HANDLE. The layer logged both faces of it: E_FAIL (0x80004005) and E_OUTOFMEMORY (0x8007000E), each ending in create_shadow_buffer. strace of the whole test: 10 DRM_IOCTL_AMDGPU_GEM_USERPTR, 8 = 0, 2 = -1 EPERM.

The refusal is in the kernel, not fixable from Vulkan: libdrm's amdgpu_create_bo_from_user_mem sets AMDGPU_GEM_USERPTR_ANONONLY, and amdgpu_ttm_tt_get_user_pages() returns -EPERM for any VMA with vm_file — which is exactly what a pagefile-backed section view (MEM_MAPPED, the form xmem gives the title's physical pages) is. Full line-referenced analysis of the Mesa/libdrm/kernel path: #7218 (comment).

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 heap_base + VA access stays out of scope, as documented.

AI-assisted (Claude Code).

@GustawMatuszewski

Copy link
Copy Markdown
Contributor

RDNA4 verification of head 14dc9af52 (independent run, no stake in the branch).

Hardware line: GPU: AMD RX 9060 XT (RDNA4/GFX1200), RADV / Mesa 26.0.8-1ubuntu0.3, Ubuntu 26.04 LTS, kernel 7.0.0-43-generic, Wine 10.0, real Xwayland display. Own fresh clone of refs/pull/8225/head; no game files. (This is the RDNA4 desktop row that was still missing: the earlier AMD rows are RDNA3.5 890M, RDNA3 RX 7900 XT, RDNA2 Raphael/RX 580.)

Builds — both from a clean clone, 0 error: lines:

build result
Linux runtime, cmake -S runtime -B runtime/build/linux RelWithDebInfo OK
Windows runtime cross-build (runtime/cmake/clang-cl-xwin.cmake, clang-cl-19, xwin SDK 10.0.26100) OK

Counts

run result
Linux ctest 64/64 passed, 0 failed, 2 skipped (shader_library_corpus, vk_sync_validation), 82.6 s — matches the 64/64 baseline
d3d12_existing_heap under Wine on RADV exit 0 — every expectation passes, including the #7218 line-186 case
Wine ctest -R ^d3d12 (104 tests, -j8) 70 passed, 9 failed, 25 skipped, 32.5 s; serial rerun of the 9: 8 deterministic, d3d12_present passes solo (only fails under -j8 Xwayland contention)

The probe's failing case from #7218 now passes on RDNA4: the pagefile-backed section view (MEM_MAPPED, the form xmem gives the title's physical pages) gets the title's VA and a GPU copy reads the CPU's writes through the shadow. Same for the write-combined, uncached, 64 MiB WC and half-committed cases:

vulkan slot-133 buffer: section view, 262144 bytes: GPU VA is the address, a GPU copy reads the CPU's writes
vulkan slot-133 shadow: write-combined range, 262144 bytes (262144 committed): GPU VA is the address, each submission reads the pages' latest bytes
vulkan slot-133 shadow: 64 MiB write-combined range, 67108864 bytes (67108864 committed): GPU VA is the address, each submission reads the pages' latest bytes
[rt] d3d12: slot-133 shadow buffer of 256 KiB: copied from the title's pages in 0.016 ms (15528 MiB/s), paid at every submission

The import is still refused by the kernel (E_FAIL / E_OUTOFMEMORY logged, same two HRESULTs as on the 890M), so as documented this is the shadow path, not a successful import. d3d12_existing_heap also now passes inside the Wine ctest run (test 167), which it did not at the #7218 head on this GPU.

The 8 deterministic Wine failures are the pre-existing RADV set, the same d3d12 failures the #7218 head produced on this same GPU (plus d3d12_existing_heap, which now passes): d3d12_vulkan_device, d3d12_indirect_dispatch_count, d3d12_clear, d3d12_depth_resolve, d3d12_residency, d3d12_heap_properties, d3d12_indirect_rt, d3d12_clear_formats. host D3D12 is Wine's, so the host comparison is skipped by the test itself.

AI-assisted (Claude Code).

tibzejoker pushed a commit to tibzejoker/Leonida that referenced this pull request Nov 23, 2026
…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>
dadnotdaddy pushed a commit to dadnotdaddy/Leonida that referenced this pull request Nov 23, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.