check_aliased_guard covers the addresses known when the cells are first armed.
This covers the later case: the page is guarded at A and B, then reported at C
as well, with the cells' mapping moved at every address as xmem's note_mapping
does once the peers are updated. The next submission must ask for the other
addresses again and guard C, so a write through C faults and is copied at the
submission after it. Without the re-ask in ShadowPages::update_aliased, C stays
writable and the write through it is never copied.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
One conflict, runtime/README.md: this branch rewrote the LEONIDA_SHADOW_ALIAS_MS
row, main (#2163) added the LEONIDA_SHADOW_KEEP row after it. Both rows kept;
the keep row's "aliased" now reads "aliased while they can't be guarded at every
address", since aliased pages are no longer copied without a sign of a write.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Between periodic refresh_title_textures passes, synchronous slot-70 view creation and the async fill worker checked TextureReadability with a constant generation, missing title_memory_map range changes since the last pass. Track the map generation on TextureReadability and consult title_memory_map::changes_since outside refresh passes so unmapped or decommitted pages defer before hashing and newly mapped pages publish immediately without waiting for a submission.
Also mark mix_words and hash_bytes LEONIDA_GUARDED_NO_BUILTIN using an unaligned 64-bit load so clang-cl cannot emit CRT memcpy calls inside the __try frame, and classify non-title read faults over unmapped title pages in xmem::physical_page_fault as FaultExit::passed_guarded.
A page xmem maps at two addresses was copied whole at every refresh, since
a guard on one view doesn't fault a write through the other: about 1 GB a
submission after the story load on a retail boot. ShadowPages now arms the
geometry watch's cells of each aliased 64 KiB block at every address it is
mapped and copies a block only when a cell's version moved. xmem tells the
cells of a mapping change after updating the peers, and of list value
writes made through the section.
AI-assisted; tested under WineHQ 11.22 and GE-Proton11-14 on an RTX 3090
(NVIDIA 590.48.01).
OreoFR's point on #2098 holds: with LEONIDA_TEXTURE_REFRESH_ASYNC=1 the before-execute hook only wakes the refresh
worker (request_title_refresh), so a slot-133 texture the title maps, writes and uses in its next submission (a video
plane) can be read empty by that submission while the worker has not come to it.
The hook now first fills, on the submitting thread, the mapped textures that were never filled (mapped && !fills),
with try_to_lock on the registry: the worker may hold it for a fill that needs this queue, so it does not wait. A
fill that needs generic staging is left to the worker, as the pass does. Everything else stays on the worker.
Test: d3d12_mapped_plane_async (d3d12_existing_heap_test --mapped-plane-async, which sets the switch itself) maps a
written R8 plane and copies it to a readback buffer in the first submission, with host image copies and with the
staged upload; every byte must be the written one.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On a driver that refuses importing a section view (RADV: amdgpu userptr takes
anonymous memory only), the layer answers with a shadow at the same title VA,
so the `may_refuse` early return never fires. The forward readback still
passes through the shadow, but a shadow is never written back, so the new
reverse-copy check failed on an AMD iGPU under Wine. Check the caller's pages
only when the buffer is a real import.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
refresh_title_textures hashes every byte of a mapped texture of up to 4 MiB each sixth pass, straight from the
title's pages. In a real boot those pages are write-combined, where ordinary loads are not cached: on the intro one
such hash took 36 ms on average and up to 78 ms, so every sixth pass cost one to two frames and the title presented
24 frames a second where it paces itself for 30. The bytes now come through copy_guarded's streaming copy, as the
fill of the same texture already does, and the copy is hashed: 0.4 to 1.1 ms.
The test places a mapped plane in ordinary and in write-combined pages and changes one byte the sampled hash does not
cover.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The merged image descriptor writer binds a Texture3D or Texture1D UAV only with VulkanDeviceInfo::robust_image_access (#939's rule: such views are read and written without a format), and the runtime's own device sets it wherever the GPU has the feature. The base's test of a slot 71 view of a placed Texture3D built its device without the flag, so the view was no longer bound and write_placed_texture_view answered false.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
One squashed commit of a fork that was developed on a Linux/Proton machine and
tested on two native Windows machines. On all of them the retail 1.0.2.1
package now launches, shows its launch movie, first-run pages and landing
prompt, runs the story load to its end with the loading slideshow drawing its
artwork, and enters the world phase. A first world frame is not verified yet.
docs/linux_proton.md has the setup, a healthy boot's timeline, the machines
and where it stops.
Runtime: frames in the title's own window; DirectStorage pinned reads,
page-list scatter/gather, BCPack and unshuffle with a locally generated
predictor file; pooled, device-local and deferred image backing for streamed
and placed textures; enhanced barriers into LAYOUT_UNDEFINED; a bindless table
that degrades instead of refusing a submission; a descriptor hash finalizer
(off until a library carries it); directly indexed heap offsets for compute
dispatches and VS/PS/GS draws; title buffer windows outside a fragmented
arena; opt-in device-local copies of streamed buffer views; write-fault
retries under the tracker lock, shared trackers and write-watched title memory
for native Windows; device-loss, compute-input and memory probes.
Translator: loop bounds at structured exits, the eight FidelityFX programs
that use a packed-dot form the disassembler skips, buffer bounds modes per
view kind, a compaction option, the hash finalizer option.
Tools and scripts: Linux boot scripts (Wine/Proton, no network), a Windows
boot script, the paired compute translation script.
No game data. AI-assisted (Claude Code and Codex agents), reviewed and booted
by people on the machines named in docs/linux_proton.md.
Co-authored-by: Plaaasma <47513553+Plaaasma@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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.
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>
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>
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>
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>
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
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>
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>
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>
- 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>
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>
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>
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>