Skip to content

d3d12_xs: device slot 133 (CreatePlacedResourceX) makes a buffer on the title's own pages (VK_EXT_external_memory_host) - #7218

Merged
ItsNotRexed merged 20 commits into
ProjectLeonida:mainfrom
tibzejoker:slot133-host-va
Nov 23, 2026
Merged

ItsNotRexed merged 20 commits into
ProjectLeonida:mainfrom
tibzejoker:slot133-host-va

Conversation

@tibzejoker

@tibzejoker tibzejoker commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue: #6750 (comment) (design note: #6750 (comment))

Depends on: #6953 (the proxy table must reach slot 133). Relates to #6995 (xmem physical pages) and #6915 (docs/retail_boot_chain.md, §3.4).

What and why

Xbox device slot 133 is the console's CreatePlacedResourceX: (va, desc, state, clear, riid, out). The retail title places a buffer at the VA of a physical-page range it has just mapped. Until now the slot either jumped through a missing entry or, in #6915's local stand-in, got an unrelated committed buffer, so what the title writes at va never reached the GPU.

  • d3d12_xs: slot 133 masks the Xbox flag bits down to the PC ones, makes a buffer's layout ROW_MAJOR (as slot 76 does), and hands the call to a handler that the device behind the proxy registers (set_placed_at_va_handler). With no handler (a PC device), it answers E_NOTIMPL whatever the arguments, as d3d12_xs: the device proxy table covers slot 133, so slots past the PC vtable refuse instead of jumping to 0 #6953's table does. The handler keeps d3d12_xs_device.cpp linkable without the Vulkan layer (the mock tests).
  • Vulkan layer: create_buffer_at_host_address 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. The resource's console VA is the title's own VA, so views and immediate writes the title names by that VA resolve to it through the buffer VA index. Textures are E_NOTIMPL and a VA off the import alignment is E_INVALIDARG.
  • The extension: the device (and vk_test_device.h) enables VK_EXT_external_memory_host when present. The same import backs ID3D12Device3::OpenExistingHeapFromAddress, which now answers as the host runtime does (8 cases, below) instead of E_NOTIMPL. CheckFeatureSupport(EXISTING_HEAPS) follows the extension. Placed resources in such a heap are refused and logged for now.

Not decided here: a shader computes heap_base + console_va, so the title's own V#s that point into these pages don't reach them. That needs the single address space of docs/d3d12_vulkan.md §3.3 (options in the design note above). This PR makes the data path and the VA bookkeeping right without picking one.

Tested

RTX 4090, driver 617.42, Windows 11 26200, MSVC 2022 RelWithDebInfo:

AI-assisted: yes (Claude Code).

🤖 Generated with Claude Code

On Windows: pair it with a read-write physical-page mapping

On main, the title's physical-page views keep PAGE_WRITECOMBINE, and this PR refuses to import write-combined pages (a WC import read wrong bytes on an RTX 5090 and two RTX 4090s), so on retail the 182 MiB slot-133 buffer takes the ordinary-buffer fallback. With one of #7492 / #7499 / #7550 (views mapped PAGE_READWRITE), the same buffer imports: measured on an RX 9070 XT (@jimokulou2-ops) and an RTX 5060 Ti (@Exopus-0x65f7ad0, with #7550). Merged with current main at 4336b7a2a (clean).

Pipodi and others added 5 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>
@Marukooh

Copy link
Copy Markdown
Contributor

Independent synthetic test of 9545ba80 under CachyOS, Wine 11.22, clang-cl 23.1.5/xwin SDK 10.0.26100, RTX 5070 Ti / NVIDIA 620.73.04. The host exposes VK_EXT_external_memory_host with 4096-byte minimum host pointer alignment.

The stock head does not compile with this SDK and clang-cl: constexpr auto kPcResourceFlags = static_cast<D3D12_RESOURCE_FLAGS>(0x7ff) is outside the SDK enum's constant-expression range. Keeping the mask as constexpr std::uint32_t kPcResourceFlags = 0x7ff; and leaving the cast after the AND fixed the build.

With that one-line change, xs_proxy_mock and d3d12_existing_heap both passed. In both the VirtualAlloc and section-view slot-133 fixtures, the GPU copied back all 262,144 bytes of the CPU-written data and the reported GPU VA matched. Native-host comparison cases were skipped by the test under Wine. Khronos validation was unavailable to Wine on this machine; the successful run was without that layer. This was synthetic; retail integration has not been verified with this PR yet.

AI-assisted (Codex).

@eugen1763

Copy link
Copy Markdown

Retail-path integration test of 9545ba80 on offline Windows 11 / Mesa lavapipe 26.3.1, clang-cl 23.1.4 and SDK 10.0.26100, on top of the preceding boot fixes. I used the integer mask workaround noted above.

The handler is registered in create_vulkan_device, but the retail gta6rt --run path uses create_vulkan_device_standalone, which constructs Device directly. Before moving the registration to the shared Device constructor, slot 133 reached the proxy but did not call the import handler and the run stopped there. With that single registration move, the trace records one successful Xbox CreatePlacedResourceX call, then one successful CreateDescriptorHeap. The next stop is the existing descriptor-heap handle check (#7021). This verifies the standalone retail path reached the host-pointer import; it does not verify shader access through the title VA or a rendered frame.

AI-assisted (Codex).

@umnitus

umnitus commented Nov 23, 2026

Copy link
Copy Markdown

Independent native Windows / RTX 3060 check at 9545ba80f89924fd730fdbec3e3870da8cb81ea2 (NVIDIA 621.14, clang-cl 23.1.6/xwin SDK 10.0.26100).

I reproduced the clang-cl build error at d3d12_xs_device.cpp:1342: the constexpr value 2047 is outside this SDK enum's [0, 511] range. For diagnosis I kept the mask as an integer, limited it to 0x1ff for this SDK, and read the incoming flags via memcpy. This was a local diagnostic change.

With that build, xs_proxy_mock passed, but d3d12_existing_heap did not complete on my native Windows setup. Direct runs with validation on and off both exited with 0xC0000008. An unbuffered rerun selected the RTX 3060 and printed the upload-heaps message, then exited before the first existing-heap check reported a result. This run did not verify the slot-133 readback. The crash site and cause are still unconfirmed.

AI-assisted testing.

…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>
@Marukooh

Copy link
Copy Markdown
Contributor

Retail follow-up on 9545ba80, using the same Wine 11.22 and RTX 5070 Ti / 620.73.04 setup as the synthetic report above. I backported the host-memory route into the local boot stack, replacing the #7075 stand-in.

There is a missing registration on the retail path. The patch registers set_placed_at_va_handler(&create_buffer_at_host_address) in create_vulkan_device, which the existing-heap fixture calls. D3D12XboxCreateDevice uses create_vulkan_device_standalone, which constructs its own Device and never registers the handler. Baseline retail reached slot 133 and stopped before the handler ran. Adding the same registration in the standalone constructor path let the buffer import succeed. The run then created all five descriptor heaps and reached device slot 70, without using #7075's committed stand-in.

A common registration point for both device factories, or the one-line registration in the standalone factory, closes the gap. The retail test was offline with the local 1.0.2.1 package. Outcomes only. AI-assisted (Codex).

# Conflicts:
#	runtime/shims/d3d12_xs_device.cpp
@tibzejoker

Copy link
Copy Markdown
Contributor Author

Thanks all three. 626beeb8 takes in both review fixes and merges current main (the only conflict was the slot_name table next to the new frame-event slots 78–80).

  • clang-cl / SDK 10.0.26100 (@Marukooh, @umnitus): the mask is now constexpr std::uint32_t kPcResourceFlags = 0x7ff, and the cast to D3D12_RESOURCE_FLAGS is applied to the masked value at run time. I kept 0x7ff instead of 0x1ff so a newer SDK's flags above 0x100 still pass through. Built with MSVC here, so an independent clang-cl build would still help.
  • Standalone retail path (@eugen1763): the handler is now registered in the Device constructor, so create_vulkan_device and create_vulkan_device_standalone (gta6rt --run) both get it. Thanks for running it to CreateDescriptorHeap and d3d12_xs: honour __XMemAllocationHooks__ for descriptor heaps and translate CPU handles #7021: that's the first retail confirmation the import is reached.
  • 0xC0000008 on the RTX 3060 (@umnitus): it ends before the first check() line prints. That function's first calls are the refusal checks from d3d12: existing-heap opens and CreateLifetimeTracker answer the host's argument errors (D3D round 3b) #4538 on main, including OpenExistingHeapFromFileMapping((HANDLE)0x1234), whose GetHandleInformation on a bogus handle raises STATUS_INVALID_HANDLE when strict handle checking is on (Application Verifier, a debugger, or some security tools). Could you run d3d12_existing_heap_test from main on the same setup? If it exits the same way, it's that existing check and not this PR. I'd then propose a separate fix.

Retested at 626beeb8 on the RTX 4090 (617.42) with Vulkan validation: both slot-133 cases (VirtualAlloc range and section view) read back the CPU's writes, the 8 OpenExistingHeapFromAddress cases match NVIDIA and WARP, and xs_proxy_mock passes.

@ruvenesh

Copy link
Copy Markdown

Review note (stray submodule bump). The diff at 626beeb8f changes the third_party/rpf9-explorer gitlink from e2939175c (what main has) to 917e9b9c7. The PR description doesn't mention it and none of the touched runtime files use that submodule, so it looks like it came in with the pr-6953 merge or a local git submodule update. Suggest resetting it, e.g. git checkout origin/main -- third_party/rpf9-explorer and amending or adding a commit, so that merging this doesn't move the pointer. Found by reading the diff only (gh pr diff). I did not build or run this PR. #7240 and #7235 don't touch the submodule. AI-assisted (Claude Code).

… found in review)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tibzejoker

Copy link
Copy Markdown
Contributor Author

@ruvenesh thanks, right: it came in with a local merge. 2b584ec2 resets third_party/rpf9-explorer to main's e2939175, and the PR no longer touches the submodule. AI-assisted (Claude Code).

@sneylol

sneylol commented Nov 23, 2026

Copy link
Copy Markdown

Tested on the retail executable (own 1.0.2.1 copy, Windows 11 26200, RX 9070 XT, AMD Windows driver, LEONIDA_D3D12=vulkan). Integration of main 8575d36 + #6919 + #6964 + #4313 + #6582 + #4348 + #7076 + #6953 + this PR. Result: concern, then pass with a one-line fix.

Concern: the handler is never registered on the path gta6rt takes. set_placed_at_va_handler is called only in create_vulkan_device, the path the tests use through vk_test_device.h. D3D12XboxCreateDevice with LEONIDA_D3D12=vulkan goes through create_vulkan_device_standalone (d3d12_xs.cpp:175), which builds its Device at the second new Device(info) without registering it. So on a real boot g_placed_at_va stays null, and slot 133 returns E_NOTIMPL silently: no CreatePlacedResourceX: va=... line, and the title asserts just as with #6953 alone. The standalone path does enable VK_EXT_external_memory_host (the host_pointer_alignment block), so only the registration is missing.

With that one line added before new Device(info) in create_vulkan_device_standalone:

rt::d3d12_xs::set_placed_at_va_handler(&create_buffer_at_host_address);

the title's call goes through:

[rt] d3d12_xs: slot 133 CreatePlacedResourceX: va=... dimension=1 width=182452224 xbox flags=0x20004 state=0xffffffff -> a buffer on the title's pages
[d3d12-trace] #1182 Xbox CreatePlacedResourceX (device slot 133) ok

That's a 174 MiB buffer imported from the title's three mapped windows (#6919's maps), on AMD with no validation complaints in this build. The title then creates a descriptor heap (slot 14) and reads its CPU start (heap slot 9), and stops on a new assert past this PR. I'm looking at that one next.

One run each way, counts and API names only. AI-assisted (Claude Code).

@tibzejoker

Copy link
Copy Markdown
Contributor Author

@sneylol thanks, that's the first AMD retail run. The registration gap you hit was in 9545ba80, and 626beeb8 fixed it (same finding as @eugen1763's): the handler is now registered in the Device constructor, which create_vulkan_device_standalone's new Device(info) goes through too, so no extra line is needed at the current head 2b584ec2. Good to see the 174 MiB import over #6919's three windows pass on RDNA4 with no validation complaints. AI-assisted (Claude Code).

@Stalkerino

Copy link
Copy Markdown

Tested the #7218 slot-133 implementation with both device factories wired up, on CachyOS, Wine 11.22, Mesa 26.3.1. The same runtime and inputs give different results on RADV and lavapipe.

Buffer passed to CreatePlacedResourceX RX 9070 XT / RADV lavapipe
Private VirtualAlloc, 256 KiB S_OK, GPU copy matches CPU writes S_OK, copy matches
Section view, 256 KiB E_OUTOFMEMORY, null resource S_OK, copy matches
XMem buffer, 174 MiB, 2,784 distinct 64 KiB frames in three adjacent windows E_OUTOFMEMORY, null resource S_OK, returned GPU VA matches requested VA

The last case is a synthetic guest using the public runtime entry point. I also ran my local copy offline with each backend. At the first 174 MiB placement RADV returns 0x8007000e. Lavapipe succeeds at that same call and the game creates its first descriptor heap. The full-size test checks placement and the reported address. Byte-for-byte GPU readback was tested on the 256 KiB cases indicated above.

This narrows the remaining hardware issue to the section-backed case. The independent sparse binding / copy control on this Radeon may be useful for the backing-memory work. AI-assisted testing.

@umnitus

umnitus commented Nov 23, 2026

Copy link
Copy Markdown

Retested on Windows / RTX 3060, NVIDIA 621.14, clang-cl/xwin SDK 10.0.26100. Updated head 2b584ec builds unmodified, and xs_proxy_mock passes. The stock d3d12_existing_heap test exits with 0xC0000008 on both 2b584ec and main 8575d36, with validation on and off.

On 2b584ec, omitting only the OpenExistingHeapFromFileMapping(0x1234) assertion in the local test let the rest pass with validation enabled. Both slot-133 fixtures read back all 262,144 bytes, and all eight host comparisons matched both native NVIDIA D3D12 and WARP. AI-assisted testing.

… 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>
@tibzejoker

Copy link
Copy Markdown
Contributor Author

@Stalkerino thanks, that's the case I couldn't see on NVIDIA. RADV refusing the section view fits amdgpu userptr, which won't pin shared, file-backed mappings, while anonymous memory imports. 588ef0b5e keeps the boot going there: when the import fails for any reason other than a misaligned VA, slot 133 now creates an ordinary DEFAULT buffer of the same description (what #6915's stand-in did) and logs it once. On RADV the title gets its resource and reaches the descriptor heap as on lavapipe. Its writes at that VA just don't reach the buffer there, and the log says so. A real fix for RADV would need the pages to come from importable memory (anonymous, or a Vulkan allocation the xmem mapper hands out), which belongs to the backing-memory item rather than this PR.

@umnitus thanks for confirming the 0xC0000008 is the OpenExistingHeapFromFileMapping(0x1234) check already on main, and for the clean clang-cl run on the RTX 3060. Since it isn't this PR's, I'll post it as a finding in #7231.

Retested at 588ef0b5e on the RTX 4090 with validation: both slot-133 fixtures, 8 of 8 host cases, xs_proxy_mock PASS. AI-assisted (Claude Code).

@justr4mzi

Copy link
Copy Markdown
Contributor

Independent native Windows 11 / MSVC 19.44.35230.0 / AMD Radeon RX 6700 XT (gfx1031, Vulkan 1.4.335, driver 2.0.372) verification of 588ef0b5e:

  • d3d12_existing_heap_test.exe (standard and LEONIDA_VK_VALIDATION=1): PASS (exit 0, 0 validation errors).
    • On native Windows AMD Vulkan driver (AMD Radeon RX 6700 XT), both slot 133 (CreatePlacedResourceX) VK_EXT_external_memory_host fixtures succeed directly without needing the fallback (vulkan slot-133 buffer: VirtualAlloc range, 262144 bytes: GPU VA is the address, a GPU copy reads the CPU's writes and vulkan slot-133 buffer: section view, 262144 bytes: GPU VA is the address, a GPU copy reads the CPU's writes).
    • All 8 OpenExistingHeapFromAddress cases match both host AMD Radeon RX 6700 XT D3D12 and host WARP.
  • xs_proxy_mock_test.exe and device_proxy_test.exe (WARP): PASS (exit 0).

AI-assisted (Gemini, Antigravity).

@byPreaZy

Copy link
Copy Markdown

checked: #7218 (branch includes dep #6953) | with: applied the diff on main 6312c05, built xs_proxy_mock_test and d3d12_existing_heap_test (MSVC 14.44, Ninja RelWithDebInfo) | on: Windows 11, AMD Radeon RX 9060 XT (RDNA4) | result: PASS

  • xs_proxy_mock_test: PASS (9 allocations refused on purpose); slot 133 reaches the handler seam and E_NOTIMPLs without one
  • d3d12_existing_heap_test: the VK_EXT_external_memory_host import works on RDNA4 — VirtualAlloc range, page-offset and section-view buffers all report the title VA as the GPU VA and a GPU copy reads the CPU's writes; cache-modifier and partly-committed ranges fall back to ordinary buffers as documented; OpenExistingHeapFromAddress answers match the host runtime in all 8 cases on both the RX 9060 XT and WARP

AI-assisted check.

hexxone pushed a commit to hexxone/Leonida that referenced this pull request Nov 23, 2026
…difiers, so GPU-shared memory imports

PAGE_WRITECOMBINE and PAGE_NOCACHE are how the console marks memory the GPU shares (a committed pool with protect
0x404, measured locally). host_protect kept them, so the host committed write-combined pages, and the D3D12 layer's
import of a buffer placed there (VK_EXT_external_memory_host, ItsNotRexed#7218) refuses write-combined pages. host_protect now
drops both cache modifiers along with the PAGE_GRAPHICS_* bits; a physical-page view already does (ItsNotRexed#7492).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 8bf9bbe)
ramenbellic added a commit to ramenbellic/Leonida that referenced this pull request Nov 23, 2026
ramenbellic added a commit to ramenbellic/Leonida that referenced this pull request Nov 23, 2026
@FRaccie

FRaccie commented Nov 23, 2026

Copy link
Copy Markdown

Tested and read a3eae955d; the two commits since (df62408b8, 1d4d2952e) only touch d3d12_existing_heap_test.cpp, so the code points below still apply to 1d4d2952e.

Test on NVIDIA GeForce RTX 3070, driver 610.88, Windows 11 (MSVC 14.44, RelWithDebInfo): pass. d3d12_existing_heap passes (slot-133 import on a VirtualAlloc range, at 64 bytes into a page and on a section view; the cache-modifier and partial-commit fallbacks; 8 of 8 OpenExistingHeapFromAddress cases match the host driver and WARP). xs_proxy_mock 6/6. Full ctest -j 2: no new failures against main. That run was without the validation layer; others above have run the current head with it.

Code read, four points not raised above:

  1. Views the layer writes for an imported buffer carry the title's host address (runtime/shims/d3d12_vulkan_device.cpp:1986, va_ = start; GetGPUVirtualAddress at :2230). The PR body covers the title's own V#s, but the layer's buffer SRV/UAV writers (:6280/6290, :6485/6489) and root CBV/SRV views built from GetGPUVirtualAddress() put the same value in the V# base, and the translated shader computes heap_base + VA. docs/d3d12_vulkan.md §3.3 records an out-of-arena V# faulting the draw and losing the submission, so on a driver where the import succeeds this looks like device loss rather than the fallback's stale read. Detecting or logging it in the view writers might be enough until §3.3 is decided.
  2. a3eae955d has no effect on textures (:6979). create_at_host_address maps the layout to a legacy state and calls create_committed, whose texture branch (:8324) creates the image without the state and registers it UNDEFINED (:2200); the refusal checks only run in create_committed_validated. So a texture placed with layout 0x6 still starts undefined, and the "retry with COMMON" branch can't trigger. The test passes 0x6 and only checks S_OK.
  3. EXISTING_HEAPS reports TRUE while its main uses return E_NOTIMPL (:8005): OpenExistingHeapFromFileMapping (:7019) and placing a resource into an opened heap (:7114). The host runtime supports both once it reports the feature.
  4. An imported range can overlap arena console VAs (:1999). Imports go into the same BufferVaIndex as default-heap buffers, whose VAs are offsets in [0, arena size); nothing checks [address, address + Width) against that, and find takes the nearest start below the VA. Plausible where host addresses are low (Wine), not measured. Sending an overlapping range to the fallback would be a cheap guard.

No game data used.

dadnotdaddy pushed a commit to dadnotdaddy/Leonida that referenced this pull request Nov 23, 2026
…ResourceX) makes a buffer on the title's own pages (VK_EXT_external_memory_host)

Squashed from ItsNotRexed#7218 by tibzejoker, head 4fb24d2 (security scan PASS).

Head moved from the scanned c3fe825 to 4fb24d2 (two commits: page-base import with bind offset, committed texture fallback); the new commits were re-scanned (prescan: no flags; Haiku read: PASS). Contains ItsNotRexed#6953. Conflicts with ItsNotRexed#6964/ItsNotRexed#7078: the slot-26 handler and the slot-133 handler both kept; device_slot_overridden lists 25/26/56 and 133.
dadnotdaddy pushed a commit to dadnotdaddy/Leonida that referenced this pull request Nov 23, 2026
…d by the proxy (a null SRV for now, its raw words logged), not the PC CreatePlacedResource1 (retail boot chain stop 14)

Squashed from ItsNotRexed#7066 by tedin7, head 1d8d1d3 (security scan PASS).

Conflicts with ItsNotRexed#6964/ItsNotRexed#7218/ItsNotRexed#6954: slot 26, slot 133 and this PR's route_xbox_device_slot helper all kept; the helper's queue route calls ItsNotRexed#6954's proxy_create_command_queue_xbox (32-byte description) instead of the slot-8 path it was written against. device_slot_overridden, the header and the mock test's check list take the union.
dadnotdaddy pushed a commit to dadnotdaddy/Leonida that referenced this pull request Nov 23, 2026
… memory the title's XMem hook gives (slots 27, 53, 76, 127)

Squashed from ItsNotRexed#7411 by garuspl, head 9335d6b (security scan PASS).

Taken as its own commit 9335d6b on top of ItsNotRexed#7235 and the newer ItsNotRexed#7218 already here: the branch merges an older ItsNotRexed#7218 head, whose slot-133 code and Vulkan-device import would undo ItsNotRexed#7218's review fixes. The proxy file's reorder keeps slot 26 and the route_xbox_device_slot helper ahead of the committed-resource code, places ItsNotRexed#7218's current slot-133 handler where this PR's copy was (g_placed_at_va declared once, above), and keeps the slot 25/26/48/56/70/133 entries in the slot names, device_slot_overridden, the header and the mock test's check list.
dadnotdaddy pushed a commit to dadnotdaddy/Leonida that referenced this pull request Nov 23, 2026
…VK_FORMAT_A8_UNORM_KHR (VK_KHR_maintenance5)

Squashed from ItsNotRexed#7403 by mrp1no, head 18b0bfb (security scan PASS).

Conflict in vk_test_device.h only: the test device enables both VK_EXT_external_memory_host (ItsNotRexed#7218) and VK_KHR_maintenance5 (this PR) when asked.
dadnotdaddy pushed a commit to dadnotdaddy/Leonida that referenced this pull request Nov 23, 2026
…eatePlacedResourceX) makes a buffer on the title's own pages (VK_EXT_external_memory_host)

Squashed from ItsNotRexed#7218 by tibzejoker, head 1d4d295 (security scan PASS). Delta from 4fb24d2: 6545c9c, a3eae95, df62408, 1d4d295.
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.
… arena's VA window takes the fallback

From review (@FRaccie):
- The texture fallback called create_committed, which takes the state without checking it (textures start
  undefined and take their first command's layout), so the barrier-layout state and its COMMON retry did
  nothing. It now goes through create_committed_validated, as CreateCommittedResource does: RENDER_TARGET on a
  texture without ALLOW_RENDER_TARGET is refused and the COMMON retry answers; a description the checks refuse
  outright is refused.
- An imported buffer's VA is its host address, in the same BufferVaIndex as default-heap buffers, whose VAs are
  offsets in [0, arena size). A host address inside that window (low addresses, as under Wine) would shadow arena
  buffers in the nearest-start lookup, so such a range is not imported and the fallback answers.

d3d12_existing_heap_test checks the two texture cases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tibzejoker

Copy link
Copy Markdown
Contributor Author

@FRaccie thanks for the careful read. 3644c72a5:

  1. Right, the layout did nothing for textures. create_committed takes the state without checking it, and a texture starts undefined and takes its first command's layout. The fallback now goes through create_committed_validated, as CreateCommittedResource does. RENDER_TARGET on a texture without ALLOW_RENDER_TARGET is refused, and the COMMON retry answers; a description the checks refuse outright (12 mips on 64x64) is refused rather than created. d3d12_existing_heap_test checks both.
  2. Added the cheap guard. A host address below the arena size isn't imported: that range takes the fallback, with a log line. On native Windows the imports are far above the window and are unaffected (the three import cases still verify VA equality and readback).
  3. Agreed, a layer-written V# with an imported buffer's host VA is out of the arena. That is §3.3, and d3d12: shaders reach buffers at the title's own VAs (slot 133, title memory) through arena copies the layer names in root views and V#s #9137 (@Etr0p, on 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) is the change that makes shaders reach those VAs (single address space), so I've kept it out of this PR rather than add a second, partial answer here. On retail, no submission was lost to it on the RTX 4090 runs (0 device-lost), but I haven't instrumented the view writers.
  4. EXISTING_HEAPS reporting TRUE comes from D3D-258 (2b2effeac) on main, not from this PR. Worth its own item: the report and the two E_NOTIMPL paths should agree.

AI-assisted (Claude Code).

@OliverMarcusson

Copy link
Copy Markdown

Tested 3644c72a (merged cleanly onto main 5d74c272) on NVIDIA GeForce RTX 5070 Ti (driver 621.01, Vulkan 1.4.357), Windows 11 10.0.26200, MSVC 19.44 (RelWithDebInfo, Windows SDK 10.0.26100.0): pass.

  • ctest -C RelWithDebInfo -R ^(d3d12_existing_heap|xs_proxy_mock|device_proxy)$: 3/3 PASS
    • d3d12_existing_heap: PASS (0.32 s; cache modifier 0x400, reported protection 0x404: ordinary-buffer fallback verified, cache modifier 0x200, reported protection 0x204: ordinary-buffer fallback verified)
    • xs_proxy_mock: PASS (9 allocations refused on purpose)
    • device_proxy: PASS (0 failures)

AI-assisted (Gemini).

Impre-visible pushed a commit to Impre-visible/Leonida that referenced this pull request Nov 23, 2026
…difiers, so GPU-shared memory imports

PAGE_WRITECOMBINE and PAGE_NOCACHE are how the console marks memory the GPU shares (a committed pool with protect
0x404, measured locally). host_protect kept them, so the host committed write-combined pages, and the D3D12 layer's
import of a buffer placed there (VK_EXT_external_memory_host, ItsNotRexed#7218) refuses write-combined pages. host_protect now
drops both cache modifiers along with the PAGE_GRAPHICS_* bits; a physical-page view already does (ItsNotRexed#7492).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 8bf9bbe)
Signed-off-by: local <local@localhost>
Impre-visible pushed a commit to Impre-visible/Leonida that referenced this pull request Nov 23, 2026
…e resource of a slot 70 view of that address

Device slot 70 makes a shader-resource view from a description and a console
address, with no resource object. It asked only the device behind the proxy
for a buffer at that address, and that device knows the buffer by the title's
address only when it could put the buffer on the title's own pages. When it
could not (the import is refused, or the device is a PC one), the slot 133
buffer has an address of its own, nothing was found, and the title's
descriptor got the null view.

The proxy now remembers every buffer a slot 133 call made by the range the
title placed it at, whichever way it was made (the placed-at-VA handler, PC
CreateCommittedResource3 or CreateCommittedResource), and slot 70 asks there
first, then the device's provider. An entry holds no reference. An object
attached to the resource as private data removes the entry when the resource
dies, and a device proxy's entries go with it. The newest buffer over an
address answers, so a range the title places again is the new buffer's.

xs_proxy_mock_test: check_slot70_placed_buffer covers both creation paths
and the handler path, the element range, the cut at the buffer's end, the
addresses around two buffers, a texture, the provider fallback and its
order, a range placed twice, a released buffer and a released device. The
check of the placed-at-VA handler in check_levels hands out a mock resource
instead of a made-up pointer, since the proxy now asks the object for
ID3D12Resource.

Depends on: ItsNotRexed#7066 (slot 70), ItsNotRexed#7218 or ItsNotRexed#7075 (slot 133), ItsNotRexed#6953 (the table
reaches slot 133), and ItsNotRexed#7235 for the mock's SetPrivateDataInterface.

(cherry picked from commit 7387445)
Signed-off-by: local <local@localhost>
@ItsNotRexed
ItsNotRexed merged commit 664aff2 into ProjectLeonida:main Nov 23, 2026
0 of 5 checks passed
ItsNotRexed pushed a commit that referenced this pull request Nov 23, 2026
…inter import

xmem commits physical pages on first touch (#7556), so a range the title has
mapped but not written yet is still MEM_RESERVE when it places a buffer on it
through device slot 133, and the Vulkan layer's import (#7218) refuses reserved
pages and answers with its fallback buffer, which the title's writes never reach.

Slot 133 now calls a registered pages hook (set_placed_at_va_pages_hook, next to
set_placed_at_va_handler) with the buffer's range before the handler; gta6rt
registers rt::xmem::commit_physical_range. A failed commit is logged once and the
handler still runs. Textures don't call it. The Vulkan layer doesn't link xmem.

Tests: xs_proxy_mock_test checks the hook order, arguments, failure and texture
cases; the new d3d12_xmem_placed_test places a buffer on untouched xmem physical
pages and checks the fallback without the hook, and with it the import and a GPU
copy reading the CPU's writes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
LeonardoIz pushed a commit to LeonardoIz/Leonida that referenced this pull request Nov 23, 2026
…inter import

xmem commits physical pages on first touch (ProjectLeonida#7556), so a range the title has
mapped but not written yet is still MEM_RESERVE when it places a buffer on it
through device slot 133, and the Vulkan layer's import (ProjectLeonida#7218) refuses reserved
pages and answers with its fallback buffer, which the title's writes never reach.

Slot 133 now calls a registered pages hook (set_placed_at_va_pages_hook, next to
set_placed_at_va_handler) with the buffer's range before the handler; gta6rt
registers rt::xmem::commit_physical_range. A failed commit is logged once and the
handler still runs. Textures don't call it. The Vulkan layer doesn't link xmem.

Tests: xs_proxy_mock_test checks the hook order, arguments, failure and texture
cases; the new d3d12_xmem_placed_test places a buffer on untouched xmem physical
pages and checks the fallback without the hook, and with it the import and a GPU
copy reading the CPU's writes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.