Ped head compositing writes BC3/BC7 blocks into placed slot-133 TitleTextures via CopyTextureRegionX (slot 85) and CopyResourceX (slot 86). Previously slot 86 was dropped as unforwarded, and placed BC textures (which cannot carry RT/DS/UAV flags) stayed gpu_written=false, causing place_title_view() and refresh_title_textures() to overwrite GPU-composited ped skin with zeroed CPU pages (intermittent pitch-black heads).
Forward list slot 86 (CopyResourceX) to PC slot 17 (CopyResource); synchronously promote placed texture destinations of CopyTextureRegion/CopyResource/ResolveSubresource to gpu_written=true on ExecuteCommandLists (preserving unmodified mips on partial copies and avoiding fill_unlocked TOCTOU); add UNORM/sRGB mutability on placed textures for cross-alias format_family matching; fix evict_and_replace() gpu_placements cleanup; and add unit + Wine regression tests.
With TMP, TEMP and USERPROFILE all unset, GetTempPathW returns C:\Windows\, and the throwing create_directories/copy_file/ofstream on C:\Windows\leonida_* aborts with 0xc0000409 before the test body runs. runtime/test/test_temp_dir.h grows one entry, testfiles::temp_dir(): LEONIDA_TEST_DIR when set, the current directory when the temp environment is stripped (Windows), else the standard temp resolution. Fifty-two test files and the tiny_game fixture that called GetTempPathA/W or temp_directory_path directly now use it; d3d12_queue_handover_test.cpp also checks the _sopen_s result in capture_stderr instead of silently returning empty stderr. One runtime source function needed the same fallback because tests exercise it: tls_host_clone_dir in runtime/src/pe_loader.cpp (the loader_tls tests). Rebased onto current main after its D3D-448 additions to d3d12_mesh_test.cpp (3-way; the mesh test keeps both). Verification on a Windows VM: stripped environment - the previously crashing d3d12 tests exit 77 (no usable Vulkan device) instead of aborting, file_system_test runs all 505 checks and loader_test all 95 with zero failures; normal environment - identical outcomes; LEONIDA_TEST_DIR honored under a fully stripped environment (the scratch folder observed mid-run inside it, cleaned up after the pass). The finding is whoalin1's (coordination issue #14, 02:37:44Z).
AI-assisted.
Retain staging for shared BC images on devices without host copies and keep the per-image fallback for formats without usable host-transfer backing.
AI-assisted-by: OpenAI Codex (GPT-6)
Splits QueueHolds barrier marking into Holder::note_barrier(seq) called only by
after_held(), preventing run_barriers() polls from stamping spurious barrier_after
flags on queued batches. Also adds name_texture() in check_mapped_plane_byte so
TitleTextureWatch tracks the mapped plane like check_mapped_plane.
AI-assisted: Antigravity (Gemini 4 Neon).
f7c3df172 stopped filling such a texture from the title's pages; its own image then held nothing the GPU
drew. A GPU-written texture placed at the address (render target, depth or UAV) now answers first, for
console T#s (bind_title_image) and slot-70 views (place_title_view), when the description fits: the T#'s
extent and samples, and mips and layers within the target's (TitleGpuPlacements::matches), in any format the
target's image takes a view in (its own, a castable one, or one its view list allows). Otherwise the other
texture answers as before, and the reason is counted (format; extent or samples; mips or layers) in a line
next to the refresh's.
Either order at one address: a render target placed over a texture placed first leaves that texture's
registry entry in place and drops its T# bindings, so they bind again, to the target. The ranges GPU-written
textures cover are kept by the resource (DeviceState::gpu_owned), so a texture placed later at the same
address does not take the target's range away; when the target goes, the texture at its address is filled
from memory again and its T#s find it. D3D12 views the title made of the plain resource itself still name
its own image.
Test: d3d12_existing_heap's "view over a render target" (both orders, and the target's release).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Blocks of older frames in run 58: a texture without GPU-write flags placed over the memory of a GPU-written
one (a render target, depth or UAV texture) was filled from the title's pages there. Those pages never hold
what our GPU renders into the target's image, only what the CPU last put there, and every write mark over
them (a write-back of a GPU copy, a neighbour's write in the same tile) re-uploaded those old bytes. The
registry now keeps the CPU-view range of every GPU-written texture (DeviceState::gpu_owned), and a texture
over such a range is not watched or filled by the refresh (index_texture); one already watched stops when the
target is registered. Test: d3d12_existing_heap's "texture over a render target's memory" (fails without
this: the written 64 KiB piece shows in the texture).
Upload at first use: a title texture no descriptor names is not read, uploaded or watched. Its first
descriptor of any kind (a D3D12 view, a slot-70 view, a T# the title wrote into a console heap: all reach
Resource::note_shader_view) queues it, and the refresh before that submission reads it whole and uploads it.
A texture whose descriptors are all gone later stays on the write-driven path (nothing counts them down).
Reads by written tiles: each texture keeps a hash of its part in every 64 KiB tile (TilePieces). When some
of its tiles were written, those parts are hashed in place first; equal, and the texture is unchanged
without a whole read. The watch reports writes per 64 KiB tile (the geometry cells' fault reopens a whole
tile), so a neighbour in a written tile costs its share of that tile, not a read of all of it.
The 10 s line: textures written or new, read whole, found unchanged by their parts, uploaded, named for the
first time, not named by any descriptor (not read), ms a pass.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
runtime/README.md: the sparse arena changed the LEONIDA_IMPORT_BELOW_ARENA row and the texture work removed the LEONIDA_ORDER_TEXTURE_UPLOADS row next to it; the arena's row is kept and the removed row stays removed.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Before every submission (at most every 16 ms, and not at all when a view held the registry), the refresh hashed
every mapped or stale texture and a round robin of the rest (sampled, a full hash every sixth pass), within
byte and time budgets that could split the planes of one video frame over passes.
Now each title texture filled from memory is watched through the geometry watch's cells: its 64 KiB tiles, at
its CPU view and every other address xmem maps them at, are armed read-only; a write faults once per tile, and
the fault, a mapping change or a kernel write's opening queues the tile (geometry_writes::WriteQueue, new). The
refresh, at every submission and with the registry waited for, takes that queue and reads only the textures over
the written tiles (TitleTextureWatch, src/title_texture_watch.h), arming them again before the read; a texture
nobody wrote costs nothing. A tile that cannot be armed (not committed, pinned, no fault handler) names its
textures at every pass: the one fallback. A fill whose full hash equals the last one uploads nothing. A slot-70
view no longer hashes its texture: it fills only one never filled or known changed.
Removed with the hash pass: LEONIDA_TITLE_TEXTURE_PERIOD_MS, _CHECK_KB, _FILL_MB, _FILL_MS,
LEONIDA_TEXTURE_HASH_BUDGET_US, LEONIDA_TEXTURE_SWEEP_BUDGET_US, LEONIDA_TITLE_EVERY_BUDGET_US,
LEONIDA_TITLE_VIEW_REFRESH_MS and the async mode LEONIDA_TEXTURE_REFRESH_ASYNC (its worker pass, first-use
fills, mapped list and range index). A line every 10 s counts passes, textures looked at, uploaded, unchanged,
written tiles and arms.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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>
Check the host-transfer memory requirements before selecting the backing for a CPU-fillable title texture. Exercise the mapped linear R8 plane with a driver shim that returns no compatible memory types for the host-transfer image.
Reported-by: qhukz13 (PR #1894)
AI-assisted-by: OpenAI Codex (gpt-6.2-astra)
Select the upload path after checking both format features and image usage. Keep required staging available for mapped linear textures and only retry host backing when the image supports it. Exercise both capability failures with synthetic GPU readback.
AI-assisted-by: OpenAI Codex (gpt-6.2-astra)
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>