Skip to content

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

Open
Etr0p wants to merge 27 commits into
ItsNotRexed:mainfrom
Etr0p:title-va-address-space
Open

Etr0p wants to merge 27 commits into
ItsNotRexed:mainfrom
Etr0p:title-va-address-space

Conversation

@Etr0p

@Etr0p Etr0p commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in #8683 (comment)

Depends on: #8225, which contains #7218. This branch is #8225's head (14dc9af52) plus the commits below. It merges cleanly with main (867d922f0, git merge-tree).

What

A translated shader computes heap_base + console_va, with heap_base the GPU address arena's device address (docs/d3d12_vulkan.md §3.3). The title doesn't always use VAs the layer chose:

These are user-mode Windows addresses far above 4 GiB, past the arena, so heap_base + VA reads nothing the layer made. #7218's "Not decided here" section leaves this open. This PR makes the layer replace such an address, wherever it sees one, with the console VA of a GPU copy of that memory.

Where the address is When it is replaced
Root CBV/SRV/UAV (Set*Root*View) when the argument is set (GraphicsCommandList::address)
CBV and buffer SRV/UAV V#s the layer writes (Create*View, slot 70, counter V#s) when the descriptor is written
Buffer V#s the title writes into a shader-visible CBV/SRV/UAV heap itself before each ExecuteCommandLists, in place: only tables the submitted lists bind, and only the slots their root signatures declare

The copies:

Unchanged: GetGPUVirtualAddress still answers the title's VA. Vertex, index, copy and immediate-write calls still resolve it through the buffer VA index, which knows slot-133 buffers by that VA.

For a heap the title backs with its own memory (__XMemAllocationHooks__, #7021), TitleVaAliases::set_descriptor_source is a hook. It lets the layer that keeps that mapping copy the title's own writes into the layer's heap before the scan. This PR adds the hook only; #7021 isn't in its base.

Why this option

The title's VA can't sit inside the arena: the arena is at most 4095 MiB, and descriptor tables must stay below 4 GiB. So a dense arena or a single heap_base can't cover it. Biasing alone (option 1 of #7218's design note) fails for V#s, as §3.3 measured. A copy in the arena gives every kind of address a small VA, and it reuses #8225's per-submission copy.

Tested

Windows 11 26200, MSVC 14.44 RelWithDebInfo, LEONIDA_VK_VALIDATION=1, 0 validation errors. RTX 5070 Ti Laptop (NVIDIA 621.24) and Radeon 610M (AMD 26.11.2).

  • d3d12_title_va_test (new). It uses the translator's address contract shader (cs_user_data.comp, two new modes). Pass on both GPUs.
    • Slot-133 buffers on read-write and write-combined pages, data written after creation: buffer V# read 64/64; root view read and written 64/64.
    • Title memory standing for a constant ring: a V# the CPU writes into a bound table itself 64/64 (rewritten before the submission), a created CBV 64/64, a root view 64/64.
    • Negative controls (8 hold): a second title buffer's data is never what the first one's V# reads (0/64); an arena buffer's V# keeps its VA; a range is forgotten when its buffer is released; a raw arena V# and a T#-shaped slot in a scanned table keep their bytes; committed memory that isn't the title's, and a title range with no committed page, are left alone and counted.
    • Not covered: the test device doesn't import pages, so both page kinds took the arena shadow. The import + bias path isn't exercised.
  • title_va_alias_test (new, no GPU). Range edges, replacement, the free gap a window must stay in, the title-memory ranges, counters: pass.
  • Existing tests. d3d12_compute_test, d3d12_existing_heap_test and xs_proxy_mock_test pass on both GPUs.

Retail boot, counts only. RTX 5070 Ti, my own copy of the game, local boot stack plus this branch, two 120 s runs, LEONIDA_ARENA_MB=512. The 174 MiB slot-133 shadow, the other slot-133 buffers and a 64 KiB title-memory window all fit in the arena, none refused.

  • Per frame: 1 root view and 3 layer-written V#s name the title's memory, all translated; 0 are left as is. Vertex views in a title range: 2 per frame, resolved through the buffer index.
  • Bound-table scan: no V# with a base outside the arena in the bound slots. With the title's own heap backing (d3d12_xs: honour __XMemAllocationHooks__ for descriptor heaps and translate CPU handles #7021) mirrored into the layer's heap on the second run, 216 slots the title wrote itself were pulled in, and none of them was a buffer V# naming the title's memory: 0 table V#s translated, 0 left untranslated. So the out-of-arena transform V# of docs/retail_boot_chain.md: the first UI draw reads its transform through a V# outside the arena (RT-753) #8862 §3.5 (measured on Linux/Wine/RADV) does not show on this Windows/NVIDIA stack. The root view and layer-written V#s above are the title-memory addresses it uses here.
  • Scan cost per ExecuteCommandLists: mean 7.2 µs and 13.5 µs on the two runs, maximum 184 µs.
  • The presented image and the off-screen target are still all zero (71 + 70 readbacks, 0 non-zero pixels of 8,294,400). So on this stack the addresses are now right but the frame stays black for another reason. One candidate, measured on another branch: most of the title's ReadFiles into uncommitted xmem physical pages fail. The second run included a local patch that commits those pages before the read, and the image was still zero. These two runs had no ReadFile failure counter, so they don't say how many reads still failed. This PR is still needed for those draws to read the right memory, but it doesn't make the frame appear here.

Related

#8991 keeps a placed buffer's heap range alive after its heap is released. That's a separate arena-lifetime fix with no overlap: this PR's windows live until the device goes, and the arena shadow is released with its resource like a committed buffer.

Known limits

AI-assisted (Claude Code).

🤖 Generated with Claude Code

Pipodi and others added 27 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>
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).
… buffer V#s the layer writes

Xbox device slot 133 places a buffer at the title's own VA, about 1.5 TiB on
Windows, while a translated shader computes heap_base + console VA with
heap_base the arena's device address. A root view or V# naming that VA
missed the buffer. The layer now translates an address inside a
title-placed buffer where it writes it (root CBV/SRV/UAV, CBV and buffer
SRV/UAV V#s): to the arena offset of the slot-133 shadow, which now lives
in the GPU address arena when it fits, or to an import's device address
minus heap_base. New tests: title_va_alias_test, d3d12_title_va_test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ugh an arena window

A root view or buffer V# may name the title's own memory outside any
slot-133 buffer (a per-frame constant ring, ItsNotRexed#8862 section 3.5). The
layer now makes a 64 KiB-aligned window of those pages in the GPU
address arena, copies it before every submission like a slot-133
shadow, and names that copy instead: for root views when set, for V#s
the layer writes, and for buffer V#s the title writes into a bound
CBV/SRV/UAV table itself, rewritten in place before each submission.
Counters per kind, LEONIDA_TITLE_WINDOWS_MB caps the windows (64 MiB).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… declared slots and is timed

The xmem shims record what they hand the title (XMemAlloc, XMemAllocDefault,
XMemVirtualAlloc, the title's VirtualAlloc); an address outside those ranges
is left as it was and counted. The submit-time scan reads only the
CBV/SRV/UAV slots the bound table's root signature declares, and its cost
is accumulated per ExecuteCommandLists. Section 3.3 describes the three
places addresses are replaced and the two kinds of copy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…, not the GLSL keyword out

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er variables

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…are pulled in before the scan

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ed value

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

@Grimkeh Grimkeh left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent Linux CPU review

What changed: title-chosen buffer VAs (slot 133 / root views / V#s) remapped through arena copies (title_va_alias.h); docs in d3d12_vulkan.md; new CPU/GPU test targets.

Checked: diff + docs read; title_va_alias_test.cpp present (full link needs runtime build). Large surface — alias rules look consistent with the doc table.

No game files. Flag: end-to-end d3d12_title_va is Windows/GPU; CPU alias unit test is the portable check.

@AAyberkU

Copy link
Copy Markdown
Contributor

A data point for the set_descriptor_source hook, measured on the retail title on Windows 11 / RTX 5060 Ti (NVIDIA). The stack is #2490, #7021, #7880, #7448, #8304/#7218/#8225, with title-VA biasing of root views and CreateConstantBufferView done locally in the same spirit as this PR.

At the UI composite draw, SetGraphicsRootDescriptorTable points into a descriptor heap the title backs with its own memory (#7021's custom range). The title-side backing at that table holds descriptors the title wrote itself: non-zero, rewritten every frame, with the table base advancing through a per-frame ring inside the heap. The layer's real shader-visible heap at the same offsets is all zero, because no API call sees those plain CPU stores. So every constant or descriptor read in those shaders returns zero. Probe results are on #6750: title shader stages that read no constants work, and every stage that reads constants yields nothing.

So on this stack the hook isn't optional: without copying the title's own heap writes into the layer's heap before submission, the bound tables are empty whatever address translation follows. I'm merging this PR next with the hook wired to #7021's backing, and will report the scan counters (title-written slots pulled in, buffer V#s translated or left) and whether any pixels appear.

AI-assisted (Claude Code).

@AAyberkU

Copy link
Copy Markdown
Contributor

Follow-up with a correction to the comment above. After fixing a mix-up between a non-shader-visible and a shader-visible heap in my dump:

  • The title-written data at the bound table is not buffer V#s. It is inline dwords that read as unit-range floats, a white colour word and small integers. In about 360k synced 16-byte chunks, 0 had a 48-bit base inside a title range. That matches your "216 slots pulled in, none a buffer V# naming the title's memory" on Windows/NVIDIA.
  • The real shader-visible heap at those offsets is still all zero without a copy.
  • I tried a local copy of changed non-zero chunks from the title's heap backing into the real heap before every ExecuteCommandListsX, done from a CPU snapshot, since reading the BAR-resident heap back made each submit take seconds. It moves about 330k chunks on the first submit, then 0 to 50 per submit, and frames keep flowing. The UI VS still produces no coverage.

So the empty table is real, but it isn't the only fault for that draw. Next I'm looking at the VS's other loads (pointer-table loads through heap_base) and at ordering (title writes after the pre-submit copy). I'll report again with your branch merged.

AI-assisted (Claude Code).

@MatyEjsr

Copy link
Copy Markdown

Tested 6d1f046da6083c623bf78f2438f37c988df6b3f8 (merged cleanly onto main 867d922f0; builds on Depends on: #8225) on Windows 11 x64, MSVC 14.44 (RelWithDebInfo, 8 parallel jobs), Vulkan SDK 1.4.363.0, NVIDIA GeForce RTX 3090 (driver 617.42) — synthetic tests only, no game files.

Verification results

  • git diff --check and python -I scripts/check_no_game_data.py across all 16 changed files: clean (exit 0).
  • Full runtime build (cmake --build runtime/build --config RelWithDebInfo --parallel 8, 608 targets including gta6rt.exe): succeeded (exit 0).
  • Targeted GPU + CPU tests with LEONIDA_VK_VALIDATION=1 (9/9 passed, 0 Vulkan validation errors):
    • title_va_alias: pass
    • d3d12_title_va: pass (read-write and write-combined pages: 64/64 V# read, 0/64 negative control, 64/64 root view read+write; constant-ring title memory: 64/64 CPU-written table V# rewritten before submission, 64/64 created CBV, 64/64 root view; arena V# and T#-shaped negative controls preserved; non-title and reserved-only ranges left untranslated and counted)
    • d3d12_existing_heap: pass (8/8 OpenExistingHeapFromAddress cases match both host NVIDIA GeForce RTX 3090 and WARP; existing-heap import and all slot-133 import/shadow cases including 64 MiB write-combined and half-committed ranges pass)
    • d3d12_compute, d3d12_fspx_compute, d3d12_buffer_uav, d3d12_bundle, xs_proxy_mock, xmem: all pass
    • Also spot-checked d3d12_title_va_test with LEONIDA_TITLE_WINDOWS_MB=0: logs the cap refusal and leaves title memory untranslated as expected.
  • Full runtime suite (ctest --test-dir runtime/build -C RelWithDebInfo -j 8 --output-on-failure): 275/277 passed (11 skipped without game/optional assets, 1 disabled). The 2 failures (d3d12_vulkan_device line 6574 tiles == 1 and d3d12_depth_resolve) reproduce identically on unmodified main (867d922f0), so 0 regressions from this PR.

Code review findings

  1. Cross-window views can overrun into unrelated arena memory (runtime/src/title_va_alias.h:64-72, 87-93 and runtime/shims/d3d12_vulkan_device.cpp:203-214)

    • TitleVaAliases::resolve(va, bytes, kind) returns immediately whenever shader_va(va) != va, which only checks va < it->second.end and ignores bytes. If a 64 KiB window [base, base + 64 KiB) is already mapped at arena offset A and a later view in the same constant ring starts at base + 0xF800 with bytes = 0x1000 (straddling the 64 KiB boundary), resolve() returns A + 0xF800, and reads past A + 0x10000 hit whatever unrelated allocation sits next in the arena.
    • In the reverse order, if [base + 0x10000, base + 0x20000) already exists at offset A and a view starts at base + 0xF800 with bytes = 0x1000, resolve_title_memory() clips end to hi = base + 0x10000 via aliases.gap(), allocates a non-contiguous window [base, base + 0x10000) at offset B, and still returns B + 0xF800 — again reading past B + 0x10000 into unrelated arena memory.
  2. Alignment loss when start is clamped to lo (runtime/shims/d3d12_vulkan_device.cpp:208, 222, 239)

    • arena_allocate(size, kTitleWindowAlign, offset, arena_buffer) aligns offset to 64 KiB, and out = offset + (va - start). Whenever lo > (va & ~(kTitleWindowAlign - 1)) (e.g., an XMemAlloc block at a 16-byte-aligned address, or a preceding slot-133 buffer ending at a non-256-byte or non-4-byte offset within the same 64 KiB page), va - start changes va's low bits — dropping 256-byte CBV alignment or even 4-byte buffer_reference_align = 4 alignment for shader dword loads. Preserving start's low offset (or aligning offset modulo the required alignment) avoids this.
  3. Unrounded size passed to add_title_memory() in XMemVirtualAlloc and TitleVirtualAlloc (runtime/shims/xmem.cpp:411-418, 715-719)

    • xmem_virtual_alloc() takes size by value and rounds address down to base_granularity (4 KiB/64 KiB/2 MiB) and requested + size up to page_granularity, but XMemVirtualAlloc() calls add_title_memory(result, size) with the caller's original unrounded size (and TitleVirtualAlloc() likewise pairs VirtualAlloc's page-rounded-down result with the caller's unrounded size). When committing at an unaligned address inside a reserved region, [result, result + size) stops short of the actual committed end — and if requested - base >= size, does not even cover address itself.
  4. Consecutive Set*RootDescriptorTable dedup can drop a larger descriptor count (runtime/shims/d3d12_com.cpp:1249-1250)

    • else if (va && p->table_descriptors && (tables_.empty() || tables_.back().first != va)) tables_.push_back({va, p->table_descriptors});
    • If the same table_va is bound consecutively to two root parameters where the second declares more descriptors than the first, the second bind is skipped instead of updating tables_.back().second = std::max(tables_.back().second, p->table_descriptors), leaving the higher slots unscanned (unlike ExecuteCommandLists, which merges duplicates with std::max).
  5. Minor notes

    • Hook teardown race (runtime/src/title_va_alias.h:94-101, 114-123, 180-189, 200-206): resolve(), scan_table(), and pull_descriptors() copy (fn, context) under hook_mutex_ and invoke fn(context, ...) after releasing the lock; ~Device() calling clear_hooks(&state_) does not synchronize with any concurrent thread already inside a callback before DeviceState is destroyed.
    • Import-path coverage in runtime/test/d3d12_title_va_test.cpp:485-494: info.host_pointer_alignment = d.host_pointer_alignment; is omitted (unlike d3d12_existing_heap_test.cpp:394), which is why the read-write test case takes the arena shadow instead of exercising the VK_EXT_external_memory_host import + bias path already wired up in check_kind().
    • New MSVC /W4 warning: runtime/shims/xmem.cpp:348 (xmem_virtual_alloc: warning C4100: 'attributes': unreferenced parameter) after splitting out the XMemVirtualAlloc wrapper.

AI-assisted review and GPU test report.

@padhossein

Copy link
Copy Markdown
Contributor

AI-assisted independent Linux verification of 6d1f046. CMake/CTest: title_va_alias passed (1/1) with GCC 14.2. The same test passed with ASan and UBSan enabled (leak checking disabled in this environment). The synthetic cs_user_data.comp compiled for Vulkan 1.3 and its binary passed spirv-val for that target. This covers CPU alias bookkeeping and fixture validation. The Windows d3d12_title_va readback was outside this run; AMD Vulkan with validation enabled is the remaining follow-up.

@lohant27-netizen

Copy link
Copy Markdown

Tested 6d1f046da on Windows 11 (10.0.26300), NVIDIA GeForce RTX 5070 (driver 32.0.16.2101, subgroup 32), MSVC with SDK 10.0.26100, Release, merged onto main 867d922f0 together with #9189, #9137, #9068, #9175, #9176 and #9132 (no conflicts): pass.

@Marukooh

Copy link
Copy Markdown
Contributor

Independent checks of 6d1f046 on a cumulative boot stack, with Wine 11.22, NVIDIA RTX 5070 Ti (620.73.04), clang-cl 23 and Vulkan. AI-assisted.

  • title_va_alias passed natively. d3d12_title_va and d3d12_existing_heap both passed under Wine. The cumulative stack also has the console-shaped list proxy. The synthetic fixture initially faulted because it used PC ID3D12GraphicsCommandList calls against that proxy; passing /*console_lists=*/false to create_device_proxy, as in d3d12_compute_test, resolved the fault. The title path still uses the console ABI.
  • A guarded 125 s offline retail run recorded 3,240 successful visible one-plane PresentX calls. The title-memory window was copied into the GPU arena. The visible frame was black in three samples with cursor capture disabled. The log also reported an imported slot-133 buffer with a GPU address below the arena whose relative address did not fit a V#.
  • A temporary pass-through ReadFile counter at title imports observed at least 512 successes and one EOF, with no ERROR_NOACCESS in the instrumented calls. No DirectStorage queue entry failure was logged. This measures the imports exercised by this run, not requests routed through other file APIs.

Counts only, no retail bytes, logs or derived assets attached.

@tiagonleal

Copy link
Copy Markdown

checked: #91376d1f046 | base: main@867d922f0 + #9137 merged locally (clean, auto-merged d3d12_com.cpp and d3d12_vulkan_device.cpp) | on: Windows 11 Pro 26300, MSVC 14.44 (VS 2022), RTX 5070 Ti (NVIDIA 617.42, ReBAR), Vulkan SDK 1.4.363, no game run | result: builds clean; the PR's tests pass, also under the Khronos validation layer; full runtime ctest 275/277, and the 2 failures fail the same way on main here (main@867d922f0 alone: 273/275, the same two).

  • ctest -R "title_va|existing_heap|xs_proxy_mock": 9/9 pass (title_va_alias, d3d12_title_va, d3d12_existing_heap, the six xs_proxy_mock* modes).
  • LEONIDA_VK_VALIDATION=1 on d3d12_title_va and d3d12_existing_heap: both pass, 0 validation messages. On this GPU the import of the test's pages is refused (HRESULT 0x80004001) and the slot-133 buffer goes the shadow route, the retail case your header names; the 64 MiB write-combined shadow copies in 7.6 ms (8.4 GB/s) per submission.
  • Full ctest -j 4 --timeout 300: 275/277. d3d12_vulkan_device and d3d12_depth_resolve exit 1 with every comparison at 0 mismatches; both fail identically on a main@867d922f0 build on this machine (the TEST-1698 pair on this GPU), so they predate the PR; the two new tests (title_va_alias, d3d12_title_va) are the difference in count.

One review finding, with a probe: a window is sized by the first address that names its pages, [va & ~64K, align_up(va + bytes)). After that, TitleVaAliases::resolve translates any address inside the range through shader_va(va) and never looks at bytes, so a later, longer view that starts inside the window and ends past it is translated with its tail outside the copy. The tail then reads whatever the arena has after the window. A local probe against title_va_alias.h at this head: add(ring, 0x10000, arena) (the window a 256-byte CBV at ring + 0xFF00 pulls in), then resolve(ring + 0xFF80, 0x1000, created_view) returns arena + 0xFF80, so the last 0xF80 bytes of that 4 KiB view lie outside the 64 KiB copy. A per-frame constant ring hands out views of varying sizes across 64 KiB boundaries, so this can happen on the retail path, and nothing counts it. Two ways to close it:

  • in resolve, check va + bytes <= range.end; when it fails, ask the resolver for a window covering the union. The old window's shadow stays registered and refreshed, so VAs already handed out keep working, and add replaces the alias entry;

  • at the least, count and log it as untranslated.

  • A smaller one: add_title_memory merges a commit into the reservation that holds it under the reservation's base, and remove_title_memory(base) erases by exact key. Freeing a block whose base was merged away is therefore a no-op, and its range stays "title memory". That's benign while those pages stay the title's, but worth a comment.

  • Log wording nit: create_shadow_buffer prints "does not fit the GPU address arena (raise LEONIDA_ARENA_MB)" also when the device has no arena at all (!device_.arena.mapped), as in d3d12_existing_heap here, where it fires for a 3 KiB shadow; raising the arena does nothing in that case.

Not run: a retail boot (no game run in this check), AMD.

AI-assisted (Claude Code, Claude Opus 5.5).
agent: yes

@GustawMatuszewski

Copy link
Copy Markdown

Independent check of 6d1f046da on Linux: pass, plus which slot-133 path RADV actually takes. Not a review of the design; no stake in the branch.

Hardware line: GPU: AMD RX 9060 XT (RDNA4/GFX1200), RADV Mesa 26.0.8, Ubuntu 26.04. Kernel 7.0.0-43-generic, Wine 10.0, clang-cl-19 + xwin SDK 10.0.26100 for the Windows cross-build. Fresh clone of refs/pull/9137/head (6d1f046da6083c623bf78f2438f37c988df6b3f8), synthetic tests only, no game files or game-derived input.

Builds

Build Result
Linux native cmake -S runtime -B runtime/build/linux (RelWithDebInfo, Ninja) OK, 43 s, 0 errors
Windows cross-build runtime/cmake/clang-cl-xwin.cmake (clang-cl-19, lld-link-19) OK, 687 targets, 3 m 56 s, 0 errors

Counts, with main 867d922f0 built the same way on the same box as a control

run this head main 867d922f0
Linux ctest 65 tests: 63 passed, 0 failed, 2 skipped (shader_library_corpus, vk_sync_validation), exit 0 64 tests: 62 passed, 0 failed, 2 skipped
runtime/test/shaders/build.py 270 shaders: 270 translated, 270 pass spirv-val same
runtime/test/shaders/check.py 208 of 211 pass, 3 skipped, 0 fail 208 of 211, 0 fail
scripts/run_gpu_tests.py --build runtime/build/linux 224/241 passed, 16 skipped, 1 failed 224/241, 16 skipped, the same 1
vk_pipeline_check (269-module index) 269/269 modules ok, 0 failed (112 cs, 3 gs, 136 ps, 18 vs) 269/269, 0 failed
Wine ctest -R "^d3d12" on the Windows build 105 tests: 97 passed, 8 failed 106 tests: 98 passed, the same 8
Wine targeted subset (18 tests: new tests, slot-133, subresource, proxies) 17 passed, 1 failed base lacks 2 of the 18

The one run_gpu_tests.py failure is ms_wave_info_s3 at (0,0): got (-1,-1,-1,-1), want (0.0078,0.0078,0.5,1.0). It fails identically on the control at 867d922f0 (--filter ms_wave_info: 0/1, same message), so it is not from this PR.

The 8 Wine d3d12 failures carry the same names on both trees: d3d12_vulkan_device, d3d12_indirect_dispatch_count, d3d12_clear, d3d12_depth_resolve, d3d12_heap_properties, d3d12_indirect_rt, d3d12_residency, d3d12_clear_formats. Test-count difference: this head's base predates three tests main has since gained (d3d12_predication_atomic_copy, d3d12_pso_validation, xg_xs) and adds two of its own (d3d12_title_va, title_va_alias).

The PR's own tests on RADV/RDNA4

  • title_va_alias: pass (Linux native and under Wine).
  • d3d12_title_va: exit 0.
  • d3d12_existing_heap: exit 0, including the section-view case that took the fallback before.
  • xs_proxy_mock 6/6 (incl. no_handler), xmem pass, d3d12_buffer_tiles / d3d12_texture_tiles / d3d12_placed_dimensions / d3d12_subresource_copy / d3d12_compute pass.

Counts printed by d3d12_title_va on this GPU: read-write and write-combined pages — V# 64/64 words matched, 0/64 read the other buffer (negative control), root view read+write 64/64; title constant ring — table V# 64/64 (rewritten before the submission: yes), created CBV 64/64, root view 64/64, with the arena-V# and T#-shaped-slot negative controls held; title-placed buffers reached through a root view and a buffer V# with all 8 descriptor-level negative controls held; 1 window, 64 KiB, refreshed before each submission.

Which path RADV takes (the part I would want to know as the author). The import still fails on this stack: the layer logged two refusals, E_NOTIMPL (-2147467263) and E_OUTOFMEMORY (-2147024882), so every title-placed range goes through #8225's shadow, the same as the RDNA3.5 result on Mesa 26.0.8. The line 186 expectation now holds anyway, and the shader-side reach comes from the new arena copies, not from VK_EXT_external_memory_host. The shadow copy of 256 KiB took 0.024 ms (~10.5 GiB/s), paid per submission. In d3d12_title_va the arena peaked at 0.4 of 256.0 MiB (0.1%, 14 allocations, 0 refused), and the "does not fit the GPU address arena, so it has its own memory" branch was exercised too (255, 256 and 3 KiB shadows), so both shadow placements are covered on RDNA4.

No game files touched or quoted; logs are counts and the tools' own output. AI-assisted (Claude Code).

@MarcPique

Copy link
Copy Markdown

checked: #9137@6d1f046d | with: MSVC 19.44.35228, RelWithDebInfo, ctest -R '^(title_va_alias|d3d12_title_va)$' -V run on each selected adapter | on: Windows 11 26200, RTX 4090 (32.0.16.1656) and Ryzen 7800X3D Radeon Graphics (32.0.13066.12) | result: 2/2 passed on each adapter, with the device selection and result checks confirmed in verbose output.

On both GPUs the fixture read all 64 expected words through a buffer V# and read/wrote all 64 through a root view, for both page kinds on the shadow path. The constant ring fixture read 64/64 through each of the CPU-written table V#, created CBV, and root view. The negative controls held on both GPUs.

Retail cross-check on the RTX 4090 only: ASTROWwwW:ladder-frame@a1751a9f0 plus the same local graphics integration as the slot-70 check, now with the #8225/#9137 runtime delta. The build made Vulkan draws and ran through the 240 s limit. Three window captures across that run showed black in the client area. The synthetic fixture wires the CPU-written descriptor source, and the local retail integration currently exercises the root/created-view paths without wiring that optional source hook.

agent: yes

@AAyberkU

Copy link
Copy Markdown
Contributor

Heads-up for rebasing onto the maintainers' forge main (git.notrexed.dev/enx/leonida main @ 2ac385837, which reports are now asked to use as base): forge main already carries #7218 (refresh) and #8225, plus its own commit 097e9f46e ("first present: tokens the proxy handed out are presentable, title-placed buffers found at their VA"). That commit adds a member alias_title_va(std::uint64_t va) in d3d12_vulkan_device.cpp with different semantics: it registers the buffer at the title VA in the context's buffer index, guarded by title_alias_ as a bool. This PR's ab1fbff adds alias_title_va(std::uint64_t shader_va), which registers a title_va_aliases range with title_alias_ as a shader VA. Cherry-picking this PR's own commits onto forge main conflicts right there. The two need different names; the lookup-by-VA alias and the shader-VA alias can coexist.

AI-assisted (Claude Code).

@AAyberkU

Copy link
Copy Markdown
Contributor

Measured with this PR plus #7021 on the retail title (1.0.2.1), Windows 11, RTX 5060 Ti. I wired set_descriptor_source to #7021's title-backed heaps locally: per bound-table window it copies the 16-byte units whose title-side bytes changed since the last pull, and a per-heap snapshot keeps both your rewrites and the layer's own Create*View slots.

Counters at 1,800 presents:

  • root views: 1,801 translated, 0 left
  • created views: 6,119 translated, 0 left
  • table V#s: 0 translated, 0 left
  • vertex views in title ranges: 3,602
  • one table scan per submit, about 10 µs on average

Title descriptors pulled: 0. The UI pass's bound table is scanned for the root signature's declared count, which is 1 descriptor (32 B). In the title-backed heap that slot is zero. The data the title writes itself starts at the next slot and spans at least 3 more. So a declared-slots-only pull and scan misses it. Either the PC root signature under-declares what the translated shader reads, or the console's table base or stride differs from it.

Draws still produce no coverage. Next locally: widen the pulled and scanned window in title-backed heaps (a fixed span past the declared count, or the whole changed heap per submit) and recheck.

AI-assisted (Claude Code).

@AAyberkU

Copy link
Copy Markdown
Contributor

Follow-up to the scan-window note above. I widened both sides locally. The descriptor source now copies the whole changed title-backed heap (#7021 backing, snapshot-diffed) over the layer's heap before each submit. The scan covers max(declared, 64) slots.

  • Pull: 354,934 16-byte units on the first submit, then about 0 to 350 per submit. The scan costs about 6 ms per submit on average (max 30 ms) at 64 slots.
  • Counters at 1,200 presents:
    • root views: 1,201 translated, 0 left
    • created views: 4,803 translated, 0 left
    • table V#s: 0 translated, 1,564 left. The extra slots hold V#-shaped words whose bases are outside the title's XMem ranges or uncommitted, so they are not real V#s.
  • Coverage: unchanged. The UI VS still covers nothing (built-in PS probe), and the blit PS still writes zero into its intermediate.

So having the title's own table data in the GPU-visible heap is not enough for these draws. My next suspect is how the translated shaders form the table address from the user SGPRs the layer passes (KkelebekK's heap_base + ((s8 & ~3) | s9 << 32) + offset with s9 forced to 0), rather than the memory contents. I'll log the user-SGPR words the layer emits for that draw and compare them with the table's arena VA.

AI-assisted (Claude Code).

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.