Commit Graph

20 Commits

Author SHA1 Message Date
e890d0a101 docs: fix inaccurate doc paths/flags/env vars and add recommended variables to running.md
- docs/running.md: add Recommended variables (all platforms) table covering async submit/compile, compile-pool sizing, warm-up throttling, heap sizing, input, and telemetry/fault variables on main; update RX 7900 XTX RADV recipe and Reporting section
- runtime/README.md: document LEONIDA_CLWB_PATCH (runtime/src/cpu_emulation.h)
- AGENTS.md: add port_ctl.py (scripts/port_ctl.py) to numpy/Pillow exception list
- d3d12/docs/replay.md: fix nonexistent --looks flag reference to --flow
- docs/port_plan.md, docs/port_status.md, docs/ultrawide.md, docs/victory_gap_gpu.md, docs/victory_gap_media.md: fix typos (chad_dsp.cpp -> chad.cpp, VIctory tests/fidelityfx.rs -> crates/victory-hle/tests/fidelityfx.rs) and clearly mark unmerged-branch paths (runtime/ ultrawide, frame_step.h, media_foundation.cpp, gameinput_xinput.cpp, d3d12_xs_exports_test.cpp, pipeline_queue.h -> pipeline_wait.h)
- tests/test_docs_cli_flags.py: scan .rs sources and clap #[arg(long)] struct fields for d3d12/docs/*.md flags, treat cargo/git-filter-repo flags as foreign, and add docs/port_plan.md to OTHER_PROJECTS

AI-assisted: Antigravity (Gemini 4 Neon). Verified: 13/13 tests/test_docs_*.py pass and scripts/check_no_game_data.py clean.
2026-11-28 09:09:23 -05:00
c49fe8676d Merge port/rect-lists: rectangle lists through a generated geometry stage 2026-11-25 23:09:44 -05:00
e763de6da2 Merge port/wave64-tiers: wave64 emulation only for tier C shaders, lane-mask fix 2026-11-25 23:09:41 -05:00
1e7b057ef2 runtime: rectangle lists (topology type 19) through a generated geometry stage
The title draws its full-screen passes and tiled lighting as D3D12.X rectangle
lists (pipeline topology type 19, list topology 17), which the Vulkan layer
refused, so those draws were lost. Ported from VIctory (GPL-3.0-or-later,
Marvisak and contributors, DexNom fork; victory-shader emit/rect.rs, 683ad7a99):

- src/rect_list_gs.h/.cpp read the vertex shader's SPIR-V output interface
  (Location outputs of 32-bit float/int/uint, Position, clip/cull distances when
  the shader declares their capability; separate built-ins or glslang's
  gl_PerVertex block, mirrored) and emit a SPIR-V 1.0 geometry shader, cached
  per output signature. VIctory's rule: the corner is the vertex sharing x with
  one other and y with the other; the fourth vertex is a + b - corner for every
  float output (exactly b or a where a or b has the corner's bits), integer
  outputs keep vertex 0's; unequal or non-positive w, coincident vertices or no
  corner stay a triangle. Two triangles, both led by vertex 0 (the provoking
  vertex for flat inputs) and turned as the title's; the primitive ID is passed.
- d3d12_vulkan_device.cpp: a type-19 PSO appends that stage and takes triangle
  lists; every other topology is unchanged. No geometryShader, or a VS the stage
  cannot be made for (no Position, Layer/ViewportIndex), is E_NOTIMPL with a log.
- tests/test_rect_list_gs.py runs the generator through rect_list_gs_tool on
  assembled vertex shaders and interprets the stage on the CPU (corner orders
  TL/BL/BR, TL/BL/TR and the third, unequal w, cache, refusals, spirv-val);
  d3d12_rect_list_test draws three rectangle orders plus a triangle control on
  the GPU (RTX 4060 Ti, 616.64, also under the validation layer).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 22:14:54 -05:00
2269728203 translator: emulate only tier C wave64 compute and mesh shaders (SHADER-10)
With --wave64-emulate, rdna2spirv.compute_halves now runs tools/wave64_halves.py
on every wave64 CS/MS and keeps the workgroup-memory emulation for tier C. Tiers
A and B run natively, one console half per subgroup:

- the thread index is relabelled from the subgroup (SubgroupId * SubgroupSize +
  SubgroupLocalInvocationId), so a subgroup holds threads 32k..32k+31 whatever
  order the host gives; it feeds v0..v2, a mesh shader's v5 / s3, the lane and
  the mesh export slot;
- an LDS access after a conflicting one of the wave (RAW / WAR / WAW, which the
  console's lockstep ordered with no barrier) and a scalar load after a store
  get a workgroup barrier in front, in blocks every invocation runs;
- with no memory write at all, s_barrier is left out;
- the index entry gets wave64_compute (+ reasons / idioms) and subgroup_size 32.

--wave64-emulate-all keeps the old behaviour (module flag WAVE64_TIERS).

The analysis learns the compute rules (exact lane id, the first lane's wave base
of D + lane, one-half EXEC regions, barrier and memory-order checks, group
size) and, for every stage, forms after VIctory's exact idioms: loads from
uniform addresses, all-or-none masks (s_cselect_b64 exec / 0 and their mixes),
uniform compares under a narrowed EXEC where no running half has it empty,
stale scalars only across a vote edge the read does not depend on, the
s_andn2_wrexec waterfall and loads through the waterfall descriptor.

tests/semantic: test_wave64_compute_tiers.py (fixtures cs_w64_half_local,
cs_w64_lds_swap, ms_w64_skeleton; native modules at 32 and 64 lanes, shuffled
placement, subgroups run one after another; negative controls) and
test_wave64_halves_victory.py; spirv_mini_interp gains OpUDiv / OpUMod and
run_workgroup(subgroup_order=...).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 22:14:29 -05:00
eac411eeb2 Merge port/pipelines (in progress, at af4210269): PSOs on worker threads, per-frame wait budget, early list
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	runtime/shims/d3d12_xs_device.cpp
#	runtime/shims/d3d12_xs_slots.h
#	runtime/test/xs_proxy_mock_test.cpp
2026-11-25 22:13:15 -05:00
a4275b1571 d3d12: Write64 timestamps when the GPU gets there; docs for the slot ports
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>
2026-11-25 22:01:13 -05:00
8d25334d12 runtime: PSOs made on worker threads, a per-frame wait budget, the early list
Ported from VIctory's pipeline/make.rs and pipeline/library.rs (GPL-3.0-or-later, Marvisak and
contributors, DexNom fork). The title creates ~60,000 PSOs in its first 20 s; compiled at creation,
its first CreateComputePipelineState held the main thread until the title's 30 s hang detector fired.

- Creation checks the description and the translator's index (program hash and entry, bindless,
  mesh limits, code base, workgroup memory, the module file) and returns. The module, the layout and
  the pipeline are made by a worker (src/pipeline_queue.h: half the logical processors, 2 to 8,
  below normal priority). The SPIR-V is read at creation only where a check on it could refuse the
  PSO on this device; the game's index lists the capabilities, so on the RTX 4060 Ti no module is
  read at creation.
- SetPipelineState starts the build and waits while the frame's budget lasts
  (LEONIDA_PIPELINE_WAIT_MS, 500 per frame and kind, one window the threads share, never for a
  pipeline held over 3 s / 10 s). A draw, mesh draw, dispatch or indirect dispatch recorded without
  a made pipeline is dropped and counted, logged once a second; the list stays valid. Frames are the
  console frame clock's (slot 80); the title's device is bounded from its creation. A device of no
  title (PC interface, tests) waits for the build until a frame begins, so nothing drops there.
- The early list: keys of the PSOs a run bound, in early-pipelines.txt beside pipeline_cache.bin
  (or LEONIDA_EARLY_PIPELINES), started at creation on the next run, depth-only first.
- The title's device reads the 57 MB index on a thread from its creation (about 3.5 s).

Tests: pipeline_queue_test (no GPU: the frame window, queue order, a retired job, drops, the early
list's file) and d3d12_async_pipeline_test (RTX 4060 Ti: 192 PSOs created in ~15 ms, all draws
dropped and counted while held, all drawn once made; the early list written and read back; console
slot 86 makes the stream PSO). vk_pipeline_paths measures monolithic, pipeline-library and
shader-object compiles of translated pixel shaders.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 21:55:47 -05:00
f6dd162511 Merge port/present: title window and Vulkan present, frame clock, 1440p display profile, frame captures
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	docs/port_status.md
2026-11-25 20:26:04 -05:00
7c81b8eef6 docs: presentation, frame clock and display profile on port/present
d3d12_vulkan.md 4.5 describes the wiring (title window, presenting queue,
device clock, screenshots), and its device-slot row now names VIctory's
clock and LEONIDA_XS_FRAME_STATISTICS_SLOT. runtime_imports.md lists the
title's window imports and what sizes its frames (measured: the DXGI mode
does not, the executable's SDR mode does). port_plan.md and port_status.md
give the state.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 20:25:21 -05:00
109828e081 victory/README: Leonida's install folder in the NVIDIA example; plan notes VIctory's NVIDIA settings
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 20:24:53 -05:00
7f672dd30c Merge port/title-memory: title GPU memory imported at its own addresses on Vulkan; slots 70/71, 133; list 62/71/72/100/148
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 20:10:38 -05:00
d5095f59d1 runtime: title memory as GPU memory; console device slots 70/71 and list slots on title addresses
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>
2026-11-25 20:09:59 -05:00
7e4eeb97b7 docs: what VIctory ab34a8b21 offers Leonida (1440p/FSR, FidelityFX, texture streaming)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 20:09:28 -05:00
b6e1689d95 Merge port/d3d12-abi: console D3D12 slot tables from VIctory, Device11 layouts
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 17:40:00 -05:00
79d905c4ce runtime: console D3D12 slot tables from VIctory, with the Device11 switch
The device, queue, list and fence proxies now take each slot's meaning
from data, runtime/shims/d3d12_xs_slots.h, built from victory-gpu
(device.rs:402-458, queue.rs:957-1001, list.rs:2055-2173,
fence.rs:141-154) and Leonida's own measurements, each entry citing its
source; static_asserts refuse two entries for one slot. VIctory's switch
(device.rs:149-168) picks the layout: a device created as ID3D12Device11,
as the title's is, gets the console layouts; any other keeps the PC order
that Leonida's PC-interface tests (device_proxy_test, queue_proxy_test,
tiny_frame) drive. This replaces the guessed +4 list rule and the
PC-order queue and fence proxies for the title.

Console layout:
- Queue: Signal 16, Wait 17, GetTimestampFrequency 18 -> PC 14/15/16;
  GetDesc 28 -> PC 18; ExecuteCommandLists 10 and ExecuteX 35 -> PC 10
  (list proxies unwrapped); Signal2X 34 -> PC 14; PresentX 32 -> the
  device's present handler (set_present_handler), else S_OK, as VIctory
  answers; markers 11-13 ignored; 23/24 (SuspendX/ResumeX) and 31
  (CopyPageMappingsBatchX) refused as open; every other slot refused.
- Fence slot 12: the address of a 64-bit word kept at the real fence's
  completed value. CPU Signal and GetCompletedValue update it at once; a
  console queue Signal registers SetEventOnCompletion on one process-wide
  event whose thread-pool wait re-reads the listed fences.
- Device: 25/26/108 take the return buffer first (V resource.rs:802-811,
  840-849, 2583-2593; Leonida retail_boot_chain 3.1; the title faults at
  26 without it), either order accepted; 48 takes the console queue
  description {type, flags, engine/pipe, queue} (queue.rs:464-495); 69 is
  ignored; 74/75 keep page pools; 127 -> PC CreateCommittedResource3 with
  a PC description and ALLOW_DISPLAY cleared (CreateCommittedResource in
  COMMON before Device10); 57 is refused with its output nulled; 12 makes
  console list proxies; every allocator is wrapped and its slot 9 is
  accepted; a slot from 44 on that no source names is refused instead of
  reaching the PC method at that number.
- List: queries 28-30 -> PC 52-54, the +4 block 32-55, 61 ExecuteIndirect,
  80 DispatchX -> Dispatch, 85/86 -> CopyTextureRegion/CopyResource,
  129 -> DispatchMesh, 139 ResetX -> Reset, 146 -> Barrier; 51 and 70
  (float arguments) through thunks with the real prototype; the 59 marker
  and VIctory's hints and syncs ignored; the console List5/List6 ids
  answered (the list is made as ID3D12GraphicsCommandList).
Both layouts: device 78-81 are VIctory's frame clock (frame.rs), not the
HLE stand-in that returned at once.

Where the sources disagree (evidence from the title wins):
- List: the +4 rule sent 56-58 to the PC queries, 60 to EndEvent and 31
  to ExecuteBundle. VIctory has the queries at 28-30 and names none of
  27, 31, 56-58, 60, which are now refused. Leonida's 59 marker (FSR DLL)
  fits VIctory's newer layout, where ExecuteIndirect moved to 61.
- Device 48: retail_boot_chain 3.2 read a PC description and had to
  clamp Flags; VIctory's layout explains it (the pipe lands there).
- Device 75: PC CreateCommandQueue1 in Leonida, UnregisterPagePool in
  VIctory: VIctory's in the console layout.
- Device 45/46/50: PC Device1/3 methods in Leonida; console methods
  nobody names per VIctory's counts: refused in the console layout.
- Device 67: VIctory leaves it unimplemented with the same (desc, iid,
  out) shape; Leonida's DeserializeComputePipelineStateX (FSR DLL) stays.
- Queue GetDesc: VIctory takes `this` first (queue.rs:950), the device's
  struct returns take the buffer first; the queue accepts both.
- Frame clock: the stand-in made a token on every poll and refused a null
  token; VIctory's (S_FALSE time-outs, a token only with flag 2) paces
  the title.

Open: list 62, 71-74, 100 and 148 still return 0 (no Vulkan-layer path
for title addresses); queue 23/24/31 and device 61/70/71/86 refused;
XboxPresentation is not attached (gta6rt has no window, and its
FramePacer issues its own tokens and models only the origin event); a
title write to the fence word does not move the fence. Not run on the
title: it stops earlier, while DirectStorage is being ported.

Tested (MSVC 19.44, RelWithDebInfo, no Vulkan headers): xs_proxy_mock_test
checks every console queue (128) and list (160) slot against the tables
and through the proxies, the struct returns in both orders, 48, 69,
74/75, 127, 57, the refused device slots, the fence word with deferred
signals, PresentX and the frame clock (40 runs, no failure);
device_proxy_test runs the console layout on WARP. ctest: 116 of 117 pass
without loader; root_sig fails on the base commit too, and loader (no
D3D12 code) times out here. The Vulkan-only tests were not built.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 17:39:29 -05:00
2daf532562 Merge port/audio: APU, DSP and audio coprocessor shims ported from VIctory
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	scripts/build_runtime.ps1
2026-11-25 17:27:11 -05:00
908fb65d8a runtime: port VIctory's audio HLE (xapu, chad, acphal coprocessor, XMA)
Ported from VIctory (victory/crates/victory-hle/src/modules/apu.rs, dsp.rs,
audio.rs; victory-formats/src/xma.rs), GPL-3.0-or-later, Marvisak and
contributors (DexNom fork), keeping its measured ABI: XApu records
(CommandId 0x18, Activate 0x38, Process 0x40, ApuResult 0x50), command
kinds, options and HRESULTs; XDsp StreamDesc 0x1c, Status 16, Command
0x20; IAcpHal slot order, 28-byte messages, command ids 1-3, 5-8, 18;
SHAPE_CONTEXTS 0x60.

- shims/xapu.cpp (xapu.dll): queues and results are real. PLACEHOLDER
  decoding: no Opus decoder is in the repository (VIctory uses the
  opus-pure crate), so a process command parses its packet
  (src/opus_packet.h, RFC 6716 framing as libopus checks it) for its
  frame count, output length and errors, and writes silence. Malformed
  packets fail with BAD_PACKET; rate conversion stays E_NOTIMPL.
- shims/chad_dsp.cpp (chad.dll): completion (status words, tickets) is
  real; convolutions and transforms output silence, as in VIctory.
- shims/acphal.cpp: the coprocessor acknowledges commands with VIctory's
  messages (fmod waits for the first in System_Create; the old stub never
  answered), sets notification words, and decodes enabled XMA contexts on
  a thread into their rings. Context arrays get device addresses that map
  back. Fixes: SHAPE_CONTEXTS is 0x60 (APU addresses are 32-bit; 120
  bytes wrote 24 past the title's structure); AcpHalReleaseShapeContexts
  writes nothing through its argument (the title passes a handle); the
  non-cached heap's device addresses start on a 64 KiB boundary; state
  the decoding thread reads is immortal.
- src/xma_decode.*, src/xma_tables.h: real XMA2 decoding (VIctory's port
  of FFmpeg's WMA Pro decoder) with four fixes from VIctory's history
  that the DexNom snapshot lacks (ba42db643, d4d182204, 03a6f2290,
  4eb0898b3); src/xma_context.*: the context machine, with three more
  (7a5d85e6a, 1054fe87d, 985d8d4b0).

Host output is unchanged: the title's middleware opens WASAPI through
COM (com_shim.cpp forwards CoCreateInstance to the host), as in VIctory.

Tests (CPU only, no game data, in CTest): xma (decoder against a
direct-sum IMDCT, VIctory's frame walk, noise and ring tests), xapu,
chad_dsp, and acphal extended (messages, notification words, the
decoding thread filling a ring). gta6rt --dry-run on 1.0.2.1 binds all
ten xapu/chad imports (unimplemented 11 -> 1: DStorageGetFactory).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 17:25:05 -05:00
c2f5bd7780 docs: shader rules to take from VIctory into Leonida's translator
Loop iteration cap, rectangle lists, literal sampler compare, quad ops and
helper lanes, VS-to-PS linking by signature row, per-program wave64
emulation, and the runtime shader lookup's keys and miss path, each with
the VIctory source and the Leonida place it lands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 16:31:55 -05:00
ed5d8570f1 docs: port plan for taking VIctory's fixes into Leonida's runtime
The title's needs in the order it hits them (system calls before the first
frame, the console D3D12 ABI in front of the Vulkan layer, menus, world),
what VIctory does for each and where it lands in Leonida, and where
Leonida's Vulkan design can cut frame time (imported title memory, buffer
device addresses, resizable BAR, asynchronous submission).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 16:28:27 -05:00