The console maps a GPU VA to a physical page and reads zero where none is
mapped. With LEONIDA_TITLE_MEMORY=sparse the layer does the same:
- Sparse buffers (windows) over the title's two GPU address windows at
the capture-replay address heap_base + VA: one for [1 GiB, 4 GiB), pieces
of up to 64 GiB for [64 GiB, 448 GiB), made before any import.
- xmem tells physical pages apart (GraphicsListener mapped and pool): each
XMemAllocatePhysicalPages section's own view is imported once, in 256 MiB
pieces when first needed, and mapping, remapping or unmapping a page is a
sparse bind of the VA page to it, or to nothing.
- The title's other GPU memory is imported once per range and bound at its
own address; freeing or decommitting releases it.
- Binds are queued per page and go to the GPU in one vkQueueBindSparse on
the graphics queue when any queue next submits (execute_now), signalling a
timeline that submission and every later one wait for. Memory given up is
freed after its unbinds.
- buffer_at, resource_at and host_at fall back to the windows for VAs no
indexed buffer holds; slot 133 and committed buffers on title memory are
spans of a window. Shaders and descriptors are unchanged.
- A startup self-test binds a host page, reads and writes it from the GPU,
unbinds it and reads zero; the path runs only when it passes. One stderr
line says which path is active and why. Imports stay the default and the
fallback, unchanged (xmem reports physical pages as before without the
variable).
On NVIDIA the bind is outside the Vulkan spec
(VUID-VkSparseMemoryBind-memory-01096: host imports are types 2/3, sparse
buffers list type 1); title_memory.h and docs/d3d12_vulkan.md say so.
d3d12_title_memory_sparse runs the whole title-memory test on this path.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ported from VIctory (GPL-3.0-or-later, Marvisak and contributors, DexNom fork),
victory-gpu queue.rs:697-731 (Written::GpuTimestamp, SystemTimestamp) and
list.rs:1964-1983.
- List slot 72 flag 1, the GPU timestamp: a timestamp query of the device's
own heap (COPY_QUEUE_TIMESTAMP for copy lists) ended where the list is and
resolved into the title address, so the GPU writes its clock there when it
reaches it, in the queue's ticks (GetTimestampFrequency,
GetClockCalibration). An address that is not 8-byte aligned, or a device
without timestamp queries, keeps the CPU clock at recording (logged).
- Flag 2, the system timestamp: QueryPerformanceCounter once the submission
has run, as VIctory stores it. The console queue signals a fence of its own
behind an ExecuteX whose lists asked for one; a thread-pool wait writes the
counter at each address when it completes.
- docs/port_plan.md and docs/port_status.md: what port/d3d12-slots2 does.
Tests: xs_proxy_mock_test (flag 2 stored after the submission, the queue's
fence made once, a reset forgets the stamps), d3d12_title_memory_test on the
RTX 4060 Ti (the GPU timestamp lies between calibrations taken after
recording and after completion; the system timestamp likewise).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ported from VIctory (GPL-3.0-or-later, Marvisak and contributors, DexNom fork),
victory-formats texture.rs (after AMD addrlib, MIT) and victory-gpu
resource.rs:140-170.
- gfx10_tiling.h: leonida::gfx10::TextureLayout and ConsoleTexture: block
dimensions, mip placement and mip tails (smallest first, mip 0 last), array
slices, thin and thick 3D, depth/stencil planes, the console format table;
addresses and detile/tile for linear, the S and D modes (256 B, 4 KiB,
64 KiB) and SW_64KB_R_X (one-mip 2D, Series X or S pipe tables). Other XOR
modes and MSAA are sized only.
- fill_from_title: every mip of every slice (or of the 3D volume) of a slot
70/71 texture is detiled from title memory and uploaded; the layout word is
read as VIctory does (0x100 | mode, 1 linear, 0 the library's pick: linear
1D, Z_X depth, R_X render target, else SW_4KB_S). Depth/stencil, MSAA,
unaddressable modes and memory that is not all there stay zeroed, logged
once each. Series S tables with LEONIDA_DEVICE_TYPE=6.
Tests: gfx10_tiling_test (VIctory's layout tests: block sizes, bijection and
round trips over 10 layouts, hand-checked offsets, mip tails, bytes_from,
planes, SW_64KB_R_X hashes from AMD's PAL, bad input; and one mip equals
TiledSurface2D), d3d12_title_memory_test on the RTX 4060 Ti (a SW_4KB_S 2D
array with a tail, a SW_64KB_D BC1 chain and a thick 3D chain read back per
subresource).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ported from VIctory (GPL-3.0-or-later, Marvisak and contributors, DexNom fork).
- Queue slot 31, CopyPageMappingsBatchX(count, batches, pool, pool pages,
flags) (victory-gpu queue.rs:897-962): each batch's ranges map pool pages in
order (kind 0), one pool page at each page (1), unmap (2) or leave (3),
through the page mapper (rt::d3d12_xs::set_page_mapper). Without one it
answers E_INVALIDARG, as VIctory's does; a range past the pool or a refused
page is logged once and the call answers S_OK.
- rt::xmem::map_alias (victory-hle xmem.rs:754-791): the physical pages
mapped at one range mapped again at another, page by page (the sources read
first, so the ranges may overlap), or unmapped. The title memory there
leaves the GPU and is imported again as XMemMapPhysicalPages does it
(make_gone, PageRuns), so the imports follow the remap. gta6rt sets it.
- Queue slots 23/24, SuspendX/ResumeX: accepted (VIctory leaves them
E_NOTIMPL); nothing suspends a title here.
Tests: xs_proxy_mock_test (the four range kinds, a range past the pool,
no mapper, 23/24), d3d12_title_memory_test on the RTX 4060 Ti (pool pages
aliased into a second window: the CPU and a GPU CopyMemoryToMemoryX read
them there, at heap_base + address; an unmap range takes them off the GPU).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ported from VIctory (GPL-3.0-or-later, Marvisak and contributors, DexNom
fork): victory-hle xmem.rs (hooks, XMemAlloc/XMemFree, XMemAllocDefault)
and victory-gpu resource.rs (use_allocator, Memory::for_resource,
resource_attributes).
- xmem: once the title is mapped, gta6rt reads the exe's export
__XMemAllocationHooks__ (two routine pointers, read at every call).
XMemAlloc/XMemFree call them; the Default variants never do. An
XMemAlloc/XMemFree made from inside the routines takes the default
allocator, and no lock is held across a hook call (the title's handlers
call XMemAllocDefault, which announces GPU blocks to the D3D12 layer).
- XMemAllocDefault decodes the attribute word (title_memory.h): CPU blocks
at the asked alignment; graphics memory types and 32-bit addresses get
pages of their own in the GPU window, made visible to the D3D12 layer and
taken off it before they are freed (stale visible ranges under a new
block are dropped first).
- D3D12 layer (rt::d3d12::set_title_allocator): the title's committed
resources (CreateCommittedResource*, console slots 76/127 through the
proxy) take GetResourceAllocationInfo's size from the allocator with
VIctory's attributes (graphics allocator 128, page size, alignment,
memory type 1/3), zeroed. Buffers are bound to that memory's import, so
their GPU virtual address is the title address; textures report it and
keep their own image memory. Released resources go back through the free
routine (a buffer after the GPU retired the work submitted so far).
Without hooks nothing changes.
- Tests: xmem_test (hook routing with a stand-in export, re-entrancy,
rewritten and null table entries, GPU blocks); d3d12_title_memory_test
(a slot-127 texture and committed buffers at the allocator's addresses,
a GPU copy landing in the title's pages, frees through the hook).
Retail title: its hook takes a 64 MiB render-target pool from
XMemAllocDefault (attributes 0x30808000) and hands both back buffers out of
it; the pool check passes. Next: XboxBvhBuilder.dll throws a C++ exception
right after the first slot 62 pipeline finds no translated shaders.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ported from VIctory (GPL-3.0-or-later, Marvisak and contributors, DexNom fork).
- Device slot 61, CreateSamplerX(desc, handle): the console's 27-word sampler
description (victory-gpu sampler.rs, descriptor.rs:828-832). On the Vulkan
device the S# is written from its hardware fields (per-axis filters, mip
filter, filter mode), the address modes, LODs, anisotropy, comparison and
border colour as VIctory reads them; a real test (LESS..GREATER_EQUAL) makes
a comparison sampler. Any other device gets VIctory's host D3D12 sampler
through CreateSampler (console_sampler_desc).
- Sampler heaps are 16 bytes a slot (descriptor.rs:1-7, 180-183); views,
RTVs and DSVs stay 32. Heap sizes, the increment, copies and the sampler
writes follow the heap type.
- List slots 73/74, WaitValue32/64: the wait goes into the Vulkan list as a
cut point (leonida::MemoryWait). VulkanQueue::execute_parts cuts the lists
at their waits and runs the parts in order (queue.rs submit_cut,
list.rs cut/detach_parts): what comes before an unmet wait runs, the rest is
held until the value is in memory. A per-device poller (250 us
high-resolution timer, only while a wait is held) releases it when another
queue's Write32/64 or a fence's value word gets there; PresentX forces what
is held (queue.rs:113-119); LEONIDA_VALUE_HOLD_MS (default 1000, 0: none)
bounds a hold. Predication carries over a cut. Devices without the handler
keep the ExecuteX check.
Tests: xs_proxy_mock_test (slot 61 fallback, wait handlers, PresentX force),
d3d12_sampler2_test (16-byte slots, S# from console descriptions),
d3d12_title_memory_test (holds met by a later Write32 on another queue, by a
fence signal through the value word, and forced at PresentX).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A GPU address is now the title's CPU address on a capture-replay device
(src/title_memory.h has the design and the RTX 4060 Ti / 616.64
measurements behind it):
- The arena's memory asks for the device address heap_base = 512 GiB
(bufferDeviceAddressCaptureReplay, enabled on the standalone device), and
every range of the title's graphics memory is imported with
VK_EXT_external_memory_host at heap_base + its address (Resource::
create_host_buffer) and registered as a buffer at VA = that address, so
heap_base + VA in shaders and buffer_at in the replay both reach the
title's own bytes, with no copy. LEONIDA_TITLE_MEMORY=0 turns it off.
- xmem places 32-bit graphics memory in [1 GiB, 4 GiB) and the rest in
[64 GiB, 448 GiB) (VIctory xmem.rs:63-88), drops write-combining as VIctory
does (xmem.rs:60-64), and tells the layer what becomes GPU-visible (commits
of graphics memory, mapped physical pages, committed then) and what is
about to go (VirtualFree, unmaps, remaps): rt::xmem::set_graphics_listener,
connected in gta6rt.
- Driver behaviour the imports work around, each measured: imported memory
cannot be sparse-bound (no 2^40 mirror); every import but the first also
takes an ordinary device range right after the arena, so the windows'
device addresses are held by sparse buffers at them and an import takes
its part; imports get addresses 2 MiB at a time, so imports in one 2 MiB
block are merged.
- Device slot 133 binds its buffer to the import that holds its pages.
- Device slots 70/71 (V device.rs:443-444, descriptor.rs:795-818,
resource.rs:2383-2448): buffer views are V#s at the title address; texture
views get a texture keyed by (address, description with words 1 and 13
zeroed), filled from title memory and detiled (gfx10_tiling.h) for one 2D
level of SW_4KB_S or SW_64KB_D; other layouts start zeroed, logged.
- List slots (V list.rs:1294-1431, 1596-1613, 1891-1983): 62
CopyMemoryToMemoryX as copies between the buffers at those addresses,
71/72 Write32/64 as WriteBufferImmediate MARKER_OUT (timestamps: the CPU
clock at recording), 100 DispatchMeshX as DispatchMesh(x, 1, 1) (indirect
dropped, as V does), 148 AllocateUploadMemory from the device's imported
upload blocks, given back at reset; 73/74 WaitValue recorded and waited
for at ExecuteX up to LEONIDA_VALUE_WAIT_MS (100), not held as V holds
them.
d3d12_title_memory_test (RTX 4060 Ti): a compute shader written to the
translator's contract reads title memory through a slot-70 V# in a console
descriptor heap in 32-bit title memory and writes it back through a root UAV
at a title address; a slot-70 SW_64KB_D texture reads back as its texels;
slot 71 V#/T#; list slots 62/71/72/73/148; slot 133 on mapped physical pages;
unmapping and the title's VirtualFree release the imports.
Retail title: every import succeeds (4.5 GB of pools, the 32-bit windows,
slot 133's 174 MB buffer); slot 70 now writes its view. The title still stops
at its breakpoint game_scarlett_master.exe+0x247af2d after its back buffers:
a pool check that slot 70 does not reach.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>