Commit Graph

14 Commits

Author SHA1 Message Date
f9c68577e3 d3d12: slot 133 textures answer GetGPUVirtualAddress with the title address
A retail title places a 256x256 R32_FLOAT texture through Xbox device slot 133
and then clears it through the value GetGPUVirtualAddress returns, used as a CPU
pointer. The layer answers 0 for a texture, as D3D12 does, so the title wrote
256 KB at address 0. XCL measured the same clear and returns the address the
title placed the resource at (its PR #168).

A slot-133 placed texture still gets its committed fallback image, but records
the title address and reports it from GetGPUVirtualAddress. Ordinary textures
still answer 0 and buffers are unchanged. The pixels do not alias the title's
pages yet, so a write through the address is not uploaded; that is the
page-mapper work and is called out in docs/d3d12_vulkan.md.

Tests: d3d12_existing_heap_test checks that the RENDER_TARGET layout and the
COMMON retry both answer the title address; it exits 0, and gta6rt links.

AI-assisted: DeepSeek V4.1 Flash 1017 (Alibaba Token Plan); coordinated by Qwen4 Max Preview.
2026-11-24 01:29:22 +01:00
3644c72a57 d3d12: slot-133 texture layouts are validated; an import reaching the 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>
2026-11-23 22:29:53 +01:00
1d4d2952e8 d3d12_existing_heap_test: the cache-modifier loop's buffer no longer hides the function's pages (C4456)
Found in review under MSVC /W4: the loop's local 'pages' shadowed the function's own. Renamed to
cached_pages; no behaviour change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 21:06:13 +01:00
df62408b84 d3d12_existing_heap_test: a driver may refuse the section-view import (RADV userptr is anonymous-only)
RADV imports host memory through amdgpu userptr, which libdrm creates anonymous-only, so it refuses a
view of a pagefile-backed section with EPERM (RX 9060 XT under Wine, found in review), and the layer
answers with its fallback as designed. The section-view case now accepts that outcome and checks the
fallback resource exists; NVIDIA and AMD's Windows driver still import it, and the readback is still
checked there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 20:48:47 +01:00
a3eae955dc d3d12: slot 133's third argument is a barrier layout; a placed texture 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>
2026-11-23 19:10:29 +01:00
6545c9c530 tests: check reported cache protection in existing-heap fixture
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: https://github.com/ItsNotRexed/Leonida/issues/7913#issuecomment-7109390728

Depends on: #7218

AI-assisted: Codex
2026-11-23 19:03:21 +01:00
4fb24d2faa d3d12: a texture at slot 133 gets an ordinary committed texture instead 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>
2026-11-23 18:37:44 +01:00
228cb9ec6c d3d12: slot 133 imports from the page that holds the address and binds 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>
2026-11-23 18:33:50 +01:00
c3fe825290 d3d12_existing_heap_test: don't compare the host's heap Alignment, which 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>
2026-11-23 17:55:50 +01:00
310773a01c d3d12: slot 133 review fixes: no write-combined import, committed-range 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>
2026-11-23 17:49:03 +01:00
9545ba80f8 d3d12_xs: device slot 133 (CreatePlacedResourceX) makes a buffer on the 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, #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 #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>
2026-11-23 17:08:20 +01:00
4d3d1e4448 d3d12: a write-combined range opens as a WRITE_COMBINE existing heap, 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>
2026-11-23 16:36:33 +01:00
4eeb61b301 d3d12: OpenExistingHeapFromAddress backs a heap with the caller's memory (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>
2026-11-23 16:33:40 +01:00
6b690ec3a1 d3d12: OpenExistingHeapFromAddress, OpenExistingHeapFromFileMapping and CreateLifetimeTracker answer the host's argument errors 2026-11-22 21:12:10 -05:00