upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorAslan2142 <jan.trencansky@protonmail.com>2026-11-26 15:41:00 +0100
committerGitHub <noreply@github.com>2026-11-26 15:41:00 +0100
commitfbf100b1b10e391625585fe6a8bf4e653662ca9a (patch)
tree497fe3bc8ef8b45d1ac8c68fa9f85196d08f11ad /docs
parent73516a2902a9872e4d21d1bdbbde4e26059497c5 (diff)
parent484b21262a21f9a99148b89ad2458b389faf7bd1 (diff)
Merge pull request #2350 from aslan2142/linux-amd-world
Self-merge by a maintainer, on purpose: current main does not get through the world on Linux/AMD, and this brings the regression fixes (the single-wave round-loop fallback of 9f98dcc61, the wave64 choice driven by llvmpipe) together with eleven PRs the world run needed. Tested on main 73516a290: translator suite 500 files / 6,365 tests, 0 failed; 513 standard-library test files pass; check_no_game_data clean on 80 files; Linux ctest 112/112; Wine suite (clang-cl + xwin, RDNA2 iGPU, RADV) with no test going from pass to fail. Not tested: native Windows, NVIDIA. The included PRs are closed in favour of this one with credit to their authors. AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2).
Diffstat (limited to 'docs')
-rw-r--r--docs/README.md1
-rw-r--r--docs/audio_hal_exe_calls.md20
-rw-r--r--docs/d3d12_vulkan.md221
-rw-r--r--docs/design.md2
-rw-r--r--docs/directstorage.md29
-rw-r--r--docs/gameinput.md9
-rw-r--r--docs/linux_proton.md61
-rw-r--r--docs/running.md142
-rw-r--r--docs/runtime_imports.md26
9 files changed, 493 insertions, 18 deletions
diff --git a/docs/README.md b/docs/README.md
index 8db9cc080..3aec00ea9 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -13,6 +13,7 @@ method, scope and caveats. No game data is included.
13| [boot_leads.md](boot_leads.md) | Open leads that may move the retail boot further (TLS at module index 0, feature level at device creation, command-list replay, descriptor words, shader corpus count, frame pacing), each with where it lands, how to implement it and how to test it. Hypotheses, not measurements. | 13| [boot_leads.md](boot_leads.md) | Open leads that may move the retail boot further (TLS at module index 0, feature level at device creation, command-list replay, descriptor words, shader corpus count, frame pacing), each with where it lands, how to implement it and how to test it. Hypotheses, not measurements. |
14| [rpf.md](rpf.md) | RPF9 archive layout, the carve tools and the unreadable encrypted TOC. | 14| [rpf.md](rpf.md) | RPF9 archive layout, the carve tools and the unreadable encrypted TOC. |
15| [linux.md](linux.md) | Linux in one page: what runs natively and what runs under Wine or Proton, the Ubuntu packages, `Build.sh`, the runtime cross-build, and why there is no native Linux `gta6rt`. | 15| [linux.md](linux.md) | Linux in one page: what runs natively and what runs under Wine or Proton, the Ubuntu packages, `Build.sh`, the runtime cross-build, and why there is no native Linux `gta6rt`. |
16| [running.md](running.md) | Running the game per platform and GPU (Linux/Wine with AMD, Linux/Proton and Windows with NVIDIA, Windows with AMD, Intel, macOS): build, shaders, pipeline pre-compile, driver settings, environment, what to expect; each value measured by us, reported by others (linked) or TBD. |
16| [testing.md](testing.md) | Running the GPU tests on your own GPU: setup per OS, wave64 emulation, running without a GPU on Mesa llvmpipe, and known problems. | 17| [testing.md](testing.md) | Running the GPU tests on your own GPU: setup per OS, wave64 emulation, running without a GPU on Mesa llvmpipe, and known problems. |
17| [gpu_test_results.md](gpu_test_results.md) | Published GPU test results by hardware, driver and commit, with pass, skip and failure counts. | 18| [gpu_test_results.md](gpu_test_results.md) | Published GPU test results by hardware, driver and commit, with pass, skip and failure counts. |
18| [modding.md](modding.md) | The mod format: `mods/<folder>/mod.json`, checked and loaded in name order by `gta6rt`; a swap takes effect once the game's archetype lookup is hooked (needs the executable, RT-5). A mod names game models and holds no game data. | 19| [modding.md](modding.md) | The mod format: `mods/<folder>/mod.json`, checked and loaded in name order by `gta6rt`; a swap takes effect once the game's archetype lookup is hooked (needs the executable, RT-5). A mod names game models and holds no game data. |
diff --git a/docs/audio_hal_exe_calls.md b/docs/audio_hal_exe_calls.md
index c04943c7d..a500e16fc 100644
--- a/docs/audio_hal_exe_calls.md
+++ b/docs/audio_hal_exe_calls.md
@@ -52,6 +52,26 @@ turns such an address back into a pointer. That is an inference from the shapes;
52`XApuEnqueueCommand` and `XApuDequeueResult` share one handle global, which `XApuDisconnect` clears: a command queue 52`XApuEnqueueCommand` and `XApuDequeueResult` share one handle global, which `XApuDisconnect` clears: a command queue
53with a result queue, connected once and torn down once. How `chad.dll`'s handle relates to it is not read. 53with a result queue, connected once and torn down once. How `chad.dll`'s handle relates to it is not read.
54 54
55`runtime/shims/xapu_queue.cpp` serves the five `xapu.dll` imports and `runtime/shims/xapu_chad.cpp` the five
56`chad.dll` ones.
57The `xapu.dll` signatures, structure layouts, command kinds, option bits and error codes come from Marvisak/VIctory
58(<https://github.com/Marvisak/VIctory>, GPL-3.0-or-later, `crates/victory-hle/src/modules/apu.rs` at commit `ffe310e`),
59which runs the retail executable through these calls. Only the facts are used (see
60[related_projects.md](related_projects.md)); the top of `xapu_queue.cpp` lists them. They agree with the shapes above:
61
62| Shape measured here | What the layout says |
63|---|---|
64| `XApuConnect`: a 24-byte title global first, a 16-byte output second | the global is an input of six dwords (processing kind, streams, commands per stream, memory bytes, frames per output, options); the output is the zeroed memory and a result event |
65| `XApuEnqueueCommand`: a stack-built command whose first dword is 1, 2 or 3 and second a stream slot, then 0 | a 24-byte command id (kind, stream, sequence, options, context): 1 activates, 2 deactivates, 3 processes an Opus packet; the third argument is an optional count of the commands accepted |
66| `XApuDequeueResult`: a 0x50-byte result, read at +0, +4 and +0x34 | the command id at +0, the output byte count at +0x34; `0x8AC81001` while none is ready |
67| `XApuDisconnect`: the handle, then `0x20` | the second argument is not read |
68
69What the results carry is the shim's own: each accepted command gets one result in command order, with the error codes
70of the layout. A process result carries the frame count and PCM when `runtime/opus_decoder` is built, and otherwise the
71frame count of the Opus packet's table-of-contents byte (RFC 6716, section 3.1) with zeros in its output (silence).
72`xapu_chad_test` covers the layouts and the silent path; `xapu_opus_test` covers the decoded path with a generated
73packet.
74
55## `xg_xs.dll` and `XCRDAPI.dll` 75## `xg_xs.dll` and `XCRDAPI.dll`
56 76
57| Import | Sites | What the sites show | 77| Import | Sites | What the sites show |
diff --git a/docs/d3d12_vulkan.md b/docs/d3d12_vulkan.md
index 35dbd0f62..98cf32aad 100644
--- a/docs/d3d12_vulkan.md
+++ b/docs/d3d12_vulkan.md
@@ -961,7 +961,8 @@ The compute path, end to end:
961 primitive overestimation no greater than `0.5 - 1/512` pixels, leaving half a minimum grid step within the 961 primitive overestimation no greater than `0.5 - 1/512` pixels, leaving half a minimum grid step within the
962 Tier 1 uncertainty bound. `ConservativeRaster=ON` uses overestimate mode with zero extra overestimation, 962 Tier 1 uncertainty bound. `ConservativeRaster=ON` uses overestimate mode with zero extra overestimation,
963 including unbound-attachment variants. OFF keeps the ordinary pipeline. Missing support, unknown modes, 963 including unbound-attachment variants. OFF keeps the ordinary pipeline. Missing support, unknown modes,
964 wireframe and non-triangle PSOs are refused; conservative TIR (`ForcedSampleCount != 0`) remains `E_NOTIMPL`. 964 wireframe and non-triangle PSOs are refused (a mesh PSO needs no topology type: its module has to output
965 triangles, `conservative_raster::mesh_outputs_triangles`); conservative TIR (`ForcedSampleCount != 0`) remains `E_NOTIMPL`.
965 Tier 2 additionally requires `degenerateTrianglesRasterized` and primitive overestimation plus half a 966 Tier 2 additionally requires `degenerateTrianglesRasterized` and primitive overestimation plus half a
966 device subpixel step no greater than 1/256 pixel. Other eligible devices retain Tier 1. The standalone 967 device subpixel step no greater than 1/256 pixel. Other eligible devices retain Tier 1. The standalone
967 device does not expose Tier 3: the Xbox `SV_InnerCoverage` input mapping has not been confirmed. See 968 device does not expose Tier 3: the Xbox `SV_InnerCoverage` input mapping has not been confirmed. See
@@ -1697,6 +1698,18 @@ The copies:
1697 cannot fit between the title's address reservations can use a separate mapped buffer. The buffer's device address 1698 cannot fit between the title's address reservations can use a separate mapped buffer. The buffer's device address
1698 must fit as a positive 47-bit offset from the arena base. The same window cap and dirty-page refresh apply. 1699 must fit as a positive 47-bit offset from the arena base. The same window cap and dirty-page refresh apply.
1699 `LEONIDA_STREAM_BUFFER_WINDOWS=0` requires the window to fit in the arena. 1700 `LEONIDA_STREAM_BUFFER_WINDOWS=0` requires the window to fit in the arena.
1701- **What the GPU wrote goes back.** The same return copy serves slot-133 shadows (a buffer the driver would not
1702 import, a compute result the title reads again): the ranges are recorded through the alias of the buffer's pages and
1703 the tracker there carries them back. `d3d12_placed_write_back` covers it. A copy is a read-side mirror, so a UAV or a raw write into a window would land in
1704 the copy and the title would never see it ([#1537](https://github.com/ubiquitarianism/leonida/issues/1537), the
1705 `WRITE_INVALID` stop at the world start). Every title range a submission's bindings reach is kept, and the next
1706 refresh copies those ranges from the copy to the title's pages *before* it copies the pages forward, so a page the
1707 title itself wrote in between keeps the title's newer bytes and its GPU result is dropped. Up to 8,192 ranges and
1708 64 MiB a submission (a V# has no read/write bit, so a read-only view costs a copy too; past the caps the ranges are
1709 left behind, logged once). `LEONIDA_TITLE_WRITEBACK=0` turns it off. A batch is fenced: it is kept with the ticket
1710 of the submission that will use it and copied back only when the context reports that ticket retired, so a range
1711 another submission is still writing is never read half done. A queue held deep (console ordering) can leave batches
1712 waiting: past 64 of them the oldest go back without their ticket, logged once.
1700- A **window that is refused** (the budget is spent, the arena is full, or the pages are not committed yet) is backed 1713- A **window that is refused** (the budget is spent, the arena is full, or the pages are not committed yet) is backed
1701 by a persistent geometry copy of exactly the requested range (`LEONIDA_GEOMETRY_MB`) instead; when no copy can be 1714 by a persistent geometry copy of exactly the requested range (`LEONIDA_GEOMETRY_MB`) instead; when no copy can be
1702 made either, the view is written with **no base and no records** — loads return 0 and stores are dropped. A raw 1715 made either, the view is written with **no base and no records** — loads return 0 and stores are dropped. A raw
@@ -1719,6 +1732,22 @@ The copies:
1719 encoding reuses only an independently established geometry view. An explicit table or placed SRV can 1732 encoding reuses only an independently established geometry view. An explicit table or placed SRV can
1720 establish that view. The Vulkan memory probe reports populated views, payload and reserved bytes, 1733 establish that view. The Vulkan memory probe reports populated views, payload and reserved bytes,
1721 upload totals, cap refusals and allocation failures. 1734 upload totals, cap refusals and allocation failures.
1735 - **Where the copies live**: device-local memory through the BAR by default. `LEONIDA_GEOMETRY_HOST=1` puts them
1736 in system memory outside VRAM (write-back where the device offers a cached host type, `=2` write-combined),
1737 as VIctory keeps its copies of title memory (approach only). In a world run on the RX 7900 XTX the copies held
1738 4.4-6 GB of VRAM. The cost moves to the bus: the GPU reads every vertex and index of a copy from system memory,
1739 so a geometry-heavy pass can take longer; measure frame time with and without it before making it a default.
1740 - **When a copy goes**: a view is retired when its title range is freed, decommitted or unmapped, and also when a
1741 remap gives one of its pages another frame or none (`XMemMapPhysicalPages` with pages, the scatter call,
1742 `CopyPageMappingsBatchX`; xmem's `RemapReleases`, `LEONIDA_GEOMETRY_REMAP_RELEASE=0` turns it off): the title
1743 streams by remapping its pools' frames, and before this the copies of what those pages held stayed for the
1744 device's life (`evicted 0` in every world run). A page mapped again to the frame it had is no change. A retired
1745 view leaves the lookups at once, its alias ranges and translated heap slots are invalidated, its stream-pool
1746 extent is forgotten, and its memory is freed only after every ExecuteCommandLists replay in progress at the
1747 retirement has recorded its submissions and those have completed (`kAfterExecutes`). Before it leaves the
1748 refresh it is copied once more from its pages if they are readable: a list recorded before a remap that took the
1749 view's address (a root view) reads the new bytes, as on the console. The next view of the range makes a new copy.
1750 `geometry_views_test` cases 14-16 and `xmem_test` (`test_remap_releases`) cover this without a GPU.
1722- **Which pages changed** since the last refresh: where xmem reserved the title's memory with `MEM_WRITE_WATCH` 1751- **Which pages changed** since the last refresh: where xmem reserved the title's memory with `MEM_WRITE_WATCH`
1723 (`XMemVirtualAlloc`'s ordinary regions and the title's `VirtualAlloc` reservations, not placeholders or 1752 (`XMemVirtualAlloc`'s ordinary regions and the title's `VirtualAlloc` reservations, not placeholders or
1724 physical-page windows), the kernel says (`GetWriteWatch` with reset, its answers kept for every copy over the page: 1753 physical-page windows), the kernel says (`GetWriteWatch` with reset, its answers kept for every copy over the page:
@@ -1805,6 +1834,178 @@ fit on smaller PC GPUs. This is a product requirement, not something the layer c
1805compatible single-mip RGBA8 2D textures (section 4.2). Other descriptions have fully allocated backing. Wider 1834compatible single-mip RGBA8 2D textures (section 4.2). Other descriptions have fully allocated backing. Wider
1806texture coverage and the game's use of tile streaming remain open. 1835texture coverage and the game's use of tile streaming remain open.
1807 1836
1837**Diagnostics for descriptors the title builds itself** (all off by default, logging only unless said otherwise):
1838
1839- `LEONIDA_UNKNOWN_TSHARP=1`: one line for each distinct base address a title-written T# names with no texture there
1840 (its shape, the tiling bits and whether the address is title memory), up to 300 addresses, and every 8192 such
1841 lookups a summary by format, type and tiling.
1842- `LEONIDA_UNBACKED_VSHARP=1`: the buffer V#s `fix_vsharp` writes empty because nothing backs their base; one line for
1843 each of the first 120 distinct bases and every 8192 a summary by 4 GiB range of the base.
1844- `LEONIDA_UPLOAD_LOG=1` (`d3d12_xs_device.cpp`): each upload chunk (CPU base, device address, size) and the first 96,
1845 then every 8192nd, `AllocateUploadMemory` result as an offset into its chunk.
1846- `LEONIDA_UPLOAD_ALIAS=1` (an experiment, changes behaviour): enters each upload chunk's CPU range in the title VA
1847 table, so a V# the title wrote with the CPU pointer `AllocateUploadMemory` handed it is rewritten to the chunk
1848 instead of left empty. A chunk below the arena needs `LEONIDA_IMPORT_BELOW_ARENA=1` as well.
1849
1850#### Address guard (`LEONIDA_ADDRESS_GUARD=1`, `rdna2spirv.py --address-guard`)
1851
1852**Prototype, off by default.**
1853
1854**Why.** The layer rewrites the addresses it can see: root views, the V#s it writes, and the V#s the title writes into
1855shader-visible heaps. It writes an empty V# when nothing backs an address (above). The translator checks a V#'s
1856record count but not its base. Any other address becomes `heap_base` plus an arbitrary value:
1857- a V# a shader builds in SGPRs from data;
1858- a raw `global_`/`flat_` address (530 of the 26,503 shaders of package 1.0.2.1, 69 of the 2,684 pipeline-library
1859 programs);
1860- a stale or offset-like value.
1861
1862On RADV such an access page-faults. Two RX 7900 XTX runs (Mesa 26.3.1, under Wine) ended with the same sequence:
1863- a `gfxhub` fault from client TCP with PERMISSION_FAULTS 0x3;
1864- a compute-ring timeout and "MES failed to respond";
1865- a MODE1 reset ("VRAM is lost").
1866
1867Both faults were 4.8 GiB and 20 GiB above `heap_base`, past the arena's end.
1868
1869"Inside the arena" is not the right bound. Several buffers are legitimately outside it, at a positive offset from
1870`heap_base` (a negative one with `LEONIDA_IMPORT_BELOW_ARENA=1`):
1871- geometry copies;
1872- upload and readback buffers;
1873- imported title memory;
1874- separate window buffers.
1875
1876The guard checks each access against what the runtime actually backs. An access that fails reads 0 and drops its
1877store, so a wild address never reaches the GPU. The overall process follows VIctory
1878([`crates/victory-gpu/src/memory.rs`](https://github.com/marvisak/victory), GPL-3.0). Its page table of 64 KiB pages
1879routes every computed address, and memory no copy holds reads 0 and takes no writes. The structure below is our own:
1880VIctory's table names descriptor views, this one is a bitmap over device addresses.
1881
1882**Structure: a two-level page table of 4 KiB pages over the 48-bit offset space, behind an arena compare.** The
1883check works on the heap offset, the sign-extended 48-bit value `Gen.host_addr` adds to `heap_base`:
1884- **Level 1:** 65,536 words indexed by offset bits 47..32. Each word names the level-2 block of one 4 GiB chunk.
1885- **Level 2:** blocks of 32,768 words, one bit per 4 KiB page (bits 31..12).
1886- **Two fixed blocks:** block 0 is empty and block 1 is full; allocated blocks start at 2.
1887- **Size:** the table is a host-visible buffer of its own, 256 KiB plus 128 KiB per block (8.25 MiB for 62 blocks).
1888
1889Why this structure:
1890- **Pages of 4 KiB** are the GPU's own mapping granularity. A page any byte of a backing touches is mapped as a whole,
1891 so marking pages outward is exact for faults. A 64 KiB page would mark memory that may not be mapped.
1892- **Level 1 by 4 GiB chunk** covers the whole signed 48-bit space (negative offsets index from 0x8000 up). A real run
1893 touches a handful of chunks, so the table stays small.
1894- **Other structures cost more per access.** A sorted range table needs a binary search: about 10 dependent loads for
1895 a thousand backings, against 2 here. A coarse region bitmap plus a fine range table needs a search in the fine part.
1896- **The arena needs no lookup.** It is one fully bound `VkBuffer`, so any offset below its size passes on a compare.
1897 That is the common case: descriptor heaps, default-heap buffers and windows in the arena.
1898
1899**The header.** It sits at arena offset `0x70000`, after the zero page and the quad indices, and holds:
1900- a 64-bit magic (`"LGUARD01"`);
1901- the arena's size (the compare's limit);
1902- the table's address minus `heap_base`;
1903- a refusal count and the last refused offset, which the shaders write.
1904
1905Two sinks follow the header: `0x71000` (zero area, what refused loads read) and `0x78000` (dump area, where refused
1906stores and atomics go). None of `[0x70000, 0x80000)` is handed out. With `LEONIDA_ARENA_NULL_MB` the range lies in the
1907null region, so its offset never moves. `runtime/src/address_guard.h` and `tools/address_guard.py` (the Python
1908reference) hold the format.
1909
1910**Each access.** `Gen.host_addr` takes the access kind (load, store or atomic) and its span. Under `--address-guard`
1911it calls one function per module, `%guard_fn`, which is straight-line at the call site, so no caller's block
1912structure changes. The function computes `end = offset + span - 1` and then decides:
1913- **Passes on a compare:** the runtime's guard is off (no magic), or `offset` and `end` are both below the limit. The
1914 result is `heap_base + offset`. The cost is a 64-bit add, two 64-bit compares and a select.
1915- **Otherwise, a lookup:** the bits of the pages of `offset` and of `end`. That is two independent pairs of dependent
1916 32-bit loads (level 1, then level 2).
1917- **Refused:** an access whose bits are not both set adds 1 to the header's count, writes its offset, and goes to the
1918 zero area (a load) or the dump area (a store or atomic), at its offset within its page. Alignment is kept, and every
1919 span fits inside a sink.
1920- **Atomics** run on the dump area, and their returned value is replaced by 0 (`Gen.guard_zero`). The CAS loops (float
1921 min/max, inc/dec) end there too, as on any other memory.
1922
1923The entry block reads the header's first six dwords once per invocation, from the arena, so that read is always
1924backed. When the base is uniform, as for `s_load`, `s_buffer_load` and a V# from SGPRs plus a uniform offset, the
1925compiler keeps the whole check scalar: one check per instruction, not per lane. A per-lane address (`global_` with a
1926VGPR address, `offen`/`idxen`) is checked per lane, and the slow path runs only for lanes outside the arena.
1927
1928**What is checked.** Every `heap_base` access goes through `host_addr`:
1929- buffer loads and stores (dword, sub-dword, typed, format; swizzled spans are computed at run time);
1930- `global_` loads, stores, sub-dword and atomics;
1931- buffer atomics, `_x2` included;
1932- `s_load` and `s_buffer_load`;
1933- the BVH node reads of `image_bvh*_intersect_ray` (span by node type).
1934
1935These are not checked:
1936- images (T#s go through the hash table, not an address);
1937- LDS;
1938- the `--mesh-compute` output buffer (a runtime address);
1939- `s_getpc` code reads.
1940
1941The translator does not translate `flat_` instructions (they raise `Unsupported`), so none reaches memory today. A
1942translation added later must go through `host_addr` like `global_` does.
1943
1944**Keeping the table current.** The spans are the same backings the console heap pass's backed table uses
1945(`update_gpu_backed`):
1946- every `gpu_backings` entry outside the arena (upload and readback buffers, imports, slot-133 buffers, windows
1947 outside the arena);
1948- the geometry copies' blocks;
1949- the separate window buffers' blocks.
1950
1951`update_address_guard` runs in the queue's `before_execute`, after the heap refresh, the windows and the geometry
1952copies. It differs from that table in four ways:
1953- It rebuilds whenever `backing_generation` or a block layout changed, with no 100 ms limit, because a backing made
1954 since the last submission must not read 0.
1955- It writes only the words that changed, level 2 before level 1.
1956- A chunk keeps its block for good, so a submission still in flight never reads a block that now means another chunk.
1957- When the 62 blocks run out, a new chunk gets the full block (unchecked, as without the guard), and that is logged.
1958
1959A release clears its bits at the next submission. D3D12 forbids releasing memory the GPU still uses, so only a wild
1960access in flight at that moment could still pass.
1961
1962**Cost per access:**
1963- **Fast path:** about 8 scalar or vector ALU operations.
1964- **Outside the arena:** about 40 operations and 4 loads, from a table small enough to stay in cache.
1965- **Per invocation:** 6 uniform header loads.
1966- **Per submission (runtime):** nothing until a backing changes, then a rebuild of the used blocks (128 KiB each)
1967 and a diff.
1968
1969**Switches.**
1970- `--address-guard` records `"address_guard": true` in `index.json`.
1971- `LEONIDA_ADDRESS_GUARD=1` makes the runtime reserve the range, create the table and write the header.
1972- Either alone does nothing: a guarded module on a runtime without the guard finds no magic, and every access passes
1973 after one compare.
1974- Without the flag the module is byte for byte what it was.
1975
1976**What a run with the guard shows.**
1977- One line when the device is made: `[rt] d3d12: address guard on ...`.
1978- At most one line a second: `[rt] d3d12: address guard: N access(es) refused so far (+k), the last at heap offset
1979 0x...`. Each refusal is a wild access that would have reached the GPU. The offset says where to look (above the
1980 arena's end, as in the two faults).
1981- A run that reset the GPU before should keep going, with wrong pixels where a refused access mattered.
1982
1983**Risks and open points.**
1984- A refused access that mattered (a backing the layer never registered) now reads 0 instead of faulting. That is
1985 silent apart from the count.
1986- An access is checked as a whole. A multi-dword load whose first dwords are inside a V# and a backing, but whose
1987 last dword is past both on an unbacked page, reads 0 in full.
1988- The table is read through the GPU's caches. A page whose bit changes while a submission is in flight can be seen
1989 either way by that submission.
1990- Sparse buffers outside the arena are guarded only if they are registered as backings.
1991
1992**Checked:**
1993- `tests/semantic/test_address_guard.py`: the fixture `cs_address_guard` with the guard on, with it off at run time
1994 and without the flag, through `spirv_mini_interp`; the kind and span of each instruction family; the table model;
1995 the constants shared by the translator, the runtime and `tools/address_guard.py`.
1996- `runtime/test/address_guard_test.cpp`: the page table, incremental writes, negative offsets, wrap, chunks and
1997 overflow.
1998- `scripts/run_address_guard_gpu_test.py`: the fixture on a 2 MiB heap whose table backs one page outside the
1999 "arena". Every address it touches is inside the buffer, so no run can fault. With the guard on, the refused loads
2000 read 0 although memory is there, the store and the atomic land in the dump area and the count is 6. With the guard
2001 off, the same module reads that memory. It passed on lavapipe (Mesa 26.3.1).
2002- Corpus (package 1.0.2.1, 2026-11-26):
2003 - `--shard 0/8` of the shaders: 3,313 translated and 3,313 `spirv-val`-valid, with the guard and without.
2004 - The pipeline library: 2,683 of 2,684 translated and valid, with the guard and without (the same one fails
2005 either way).
2006 - Without the flag, every module is byte for byte the same as before the change.
2007 - With it, the SPIR-V grows by 1.8% (shaders) and 1.6% (library).
2008
1808### 3.4 Descriptor heaps and the bindless model 2009### 3.4 Descriptor heaps and the bindless model
1809 2010
1810The game can use D3D12 descriptors in three ways, and the layer must handle all of them: 2011The game can use D3D12 descriptors in three ways, and the layer must handle all of them:
@@ -2415,6 +2616,24 @@ Pipeline creation:
2415 Replacing part of the previous file would corrupt it. 2616 Replacing part of the previous file would corrupt it.
2416 `LEONIDA_PIPELINE_CACHE_BYTES` caps what a session adds, at a checkpoint or at teardown (an offline `pipeline_cache.bin` seed, which the driver hands back as part of the union, is not counted; 4 GiB by default, zero disables 2617 `LEONIDA_PIPELINE_CACHE_BYTES` caps what a session adds, at a checkpoint or at teardown (an offline `pipeline_cache.bin` seed, which the driver hands back as part of the union, is not counted; 4 GiB by default, zero disables
2417 the session file). 2618 the session file).
2619 The session file can't keep a crashed run's compiles: it is written at teardown and at the optional checkpoints
2620 below only. The heavy pipeline cache (RT-HEAVY-PIPELINE-CACHE, `runtime/src/heavy_pipeline_cache.h`) keeps the graphics ones; compute pipelines go to the per-pipeline journal
2621 described below. Every graphics build first asks the corpus cache with
2622 `VK_PIPELINE_CREATE_FAIL_ON_PIPELINE_COMPILE_REQUIRED_BIT`. A pipeline the corpus doesn't have is built against a
2623 second cache, seeded from `pipeline_cache.heavy.bin` next to `pipeline_cache.bin`, so that cache holds only the
2624 corpus's misses.
2625 A build that takes at least `LEONIDA_HEAVY_PIPELINE_CACHE_MS` (500 by default) marks the heavy cache for writing.
2626 A thread of its own writes it whole: 3 s after the newest slow build, and no later than 20 s after the first unwritten
2627 one, through the same staging file and rename as the session cache. A crash therefore loses at most the last 20 s
2628 of slow builds, and the next launch starts with the rest. A write that fails, or whose
2629 `vkGetPipelineCacheData` returns anything but `VK_SUCCESS` (`VK_INCOMPLETE` means the cache grew after the size
2630 query, so the blob is truncated), leaves the previous file in place and the cache dirty: it is tried again 5 s
2631 later, the delay doubling with each failure in a row up to 2 min, so the cache is not left unsaved until teardown
2632 and a write that keeps failing does not spin. At device teardown the thread stops, and the cache is
2633 written if any build went into it. Fast builds are kept that way: without an offline seed every build is a miss,
2634 so they no longer reach `pipeline_cache.session.bin`. `LEONIDA_HEAVY_PIPELINE_CACHE_MS=0` turns the heavy cache off, and with it the
2635 `pipelineCreationCacheControl` feature unless `LEONIDA_PIPELINE_COMPILE=cache-only` asks for it. A cache-only create
2636 (`cache-only`) is left as it is.
2418 `LEONIDA_SKIP_COMPUTE=<part of a name>[,<part>...]` (`all`: every compute program) never builds the matching 2637 `LEONIDA_SKIP_COMPUTE=<part of a name>[,<part>...]` (`all`: every compute program) never builds the matching
2419 compute programs and drops their dispatches, direct and indirect; the first dropped dispatch of each is logged. 2638 compute programs and drops their dispatches, direct and indirect; the first dropped dispatch of each is logged.
2420 It is a way past a program that hangs the GPU while the program or its input is fixed, not a fix. 2639 It is a way past a program that hangs the GPU while the program or its input is fixed, not a fix.
diff --git a/docs/design.md b/docs/design.md
index eee5be2cc..656418c99 100644
--- a/docs/design.md
+++ b/docs/design.md
@@ -372,6 +372,7 @@ How the generated SPIR-V expects the runtime to work:
372| Integer clamp | The VOP3 `clamp` bit on `v_add_nc_u32`, `v_sub_nc_u32`, `v_subrev_nc_u32` saturates the result to [0, 0xFFFFFFFF], and on `v_add_nc_i32`/`v_sub_nc_i32` to [0x80000000, 0x7FFFFFFF]; without it they wrap. GFX9+ semantics: LLVM selects `uaddsat`/`usubsat` and `saddsat`/`ssubsat` to exactly these ops with clamp set. **Until this change clamp was silently ignored on the unsigned ops** (and the signed ones were `Unsupported`). Checked on the CPU by `tests/semantic/test_alu_add_nc_clamp.py`. The carry-out unsigned ops (`v_add_co_u32`, `v_sub_co_u32`, `v_subrev_co_u32`, `v_add_co_ci_u32`, `v_sub_co_ci_u32`, `v_subrev_co_ci_u32`) with VOP3 `clamp` likewise saturate D to `0xFFFFFFFF` on add carry or `0` on sub borrow while still reporting the real carry/borrow bit in `sdst` (**until 2026-11-22 the translator ignored `clamp` on all six**); confirmed natively on RDNA2 (AMD Radeon 680M `gfx1035` wave32 & wave64 via `tools/hw_oracle`, and independently on `gfx1036` in #1746) and CPU-checked by `tests/semantic/test_alu_add_co_clamp.py`. The 16-bit unsigned add/sub (`v_add_nc_u16`, `v_sub_nc_u16`, and the `v_add_u16`/`v_sub_u16`/`v_subrev_u16` `_e64` names) saturate to [0, 0xFFFF] with `clamp` (llvm-mc 21 gfx1030 encodes the bit on them, and LLVM selects i16 `uaddsat`/`usubsat` to them); **until 2026-11-22 the translator wrapped instead**. `clamp` on any other 16-bit integer op raises `Unsupported`. CPU-checked by `tests/semantic/test_alu_u16_clamp.py` (the high half of the destination is kept), **not GPU-verified**. CPU-checked by `tests/semantic/test_alu_u16_clamp.py` (the high half of the destination is kept), and **Hardware-verified on RDNA2** (AMD Radeon 680M, `gfx1035`, Windows 11, driver `26.5.1`, wave32 and wave64 via `tools/int_hw_probe.py --oracle both`, SHADER-137): all 32-bit and 16-bit `*_nc_*` `clamp` cases (including `op_sel` and kept destination half on u16) match hardware bit-for-bit. **Open divergence measured on the same hardware:** `v_add_co_u32`, `v_sub_co_u32`, `v_subrev_co_u32`, `v_add_co_ci_u32`, `v_sub_co_ci_u32` and `v_subrev_co_ci_u32` with `clamp` saturate D (`0xFFFFFFFF` / `0`) while still reporting the real carry/borrow in `sdst`, whereas the translator currently ignores `clamp` on these carry-out ops. | 372| Integer clamp | The VOP3 `clamp` bit on `v_add_nc_u32`, `v_sub_nc_u32`, `v_subrev_nc_u32` saturates the result to [0, 0xFFFFFFFF], and on `v_add_nc_i32`/`v_sub_nc_i32` to [0x80000000, 0x7FFFFFFF]; without it they wrap. GFX9+ semantics: LLVM selects `uaddsat`/`usubsat` and `saddsat`/`ssubsat` to exactly these ops with clamp set. **Until this change clamp was silently ignored on the unsigned ops** (and the signed ones were `Unsupported`). Checked on the CPU by `tests/semantic/test_alu_add_nc_clamp.py`. The carry-out unsigned ops (`v_add_co_u32`, `v_sub_co_u32`, `v_subrev_co_u32`, `v_add_co_ci_u32`, `v_sub_co_ci_u32`, `v_subrev_co_ci_u32`) with VOP3 `clamp` likewise saturate D to `0xFFFFFFFF` on add carry or `0` on sub borrow while still reporting the real carry/borrow bit in `sdst` (**until 2026-11-22 the translator ignored `clamp` on all six**); confirmed natively on RDNA2 (AMD Radeon 680M `gfx1035` wave32 & wave64 via `tools/hw_oracle`, and independently on `gfx1036` in #1746) and CPU-checked by `tests/semantic/test_alu_add_co_clamp.py`. The 16-bit unsigned add/sub (`v_add_nc_u16`, `v_sub_nc_u16`, and the `v_add_u16`/`v_sub_u16`/`v_subrev_u16` `_e64` names) saturate to [0, 0xFFFF] with `clamp` (llvm-mc 21 gfx1030 encodes the bit on them, and LLVM selects i16 `uaddsat`/`usubsat` to them); **until 2026-11-22 the translator wrapped instead**. `clamp` on any other 16-bit integer op raises `Unsupported`. CPU-checked by `tests/semantic/test_alu_u16_clamp.py` (the high half of the destination is kept), **not GPU-verified**. CPU-checked by `tests/semantic/test_alu_u16_clamp.py` (the high half of the destination is kept), and **Hardware-verified on RDNA2** (AMD Radeon 680M, `gfx1035`, Windows 11, driver `26.5.1`, wave32 and wave64 via `tools/int_hw_probe.py --oracle both`, SHADER-137): all 32-bit and 16-bit `*_nc_*` `clamp` cases (including `op_sel` and kept destination half on u16) match hardware bit-for-bit. **Open divergence measured on the same hardware:** `v_add_co_u32`, `v_sub_co_u32`, `v_subrev_co_u32`, `v_add_co_ci_u32`, `v_sub_co_ci_u32` and `v_subrev_co_ci_u32` with `clamp` saturate D (`0xFFFFFFFF` / `0`) while still reporting the real carry/borrow in `sdst`, whereas the translator currently ignores `clamp` on these carry-out ops. |
373| Carry-out subtract of a register from itself | `v_sub_co_u32`, `v_subrev_co_u32`, `v_sub_co_ci_u32` and `v_subrev_co_ci_u32` whose two sources are the same operand (`vD, sdst, vX, vX`) are written out as what x - x gives: D = 0 - carry in and borrow out = carry in (D = 0 and no borrow without a carry in; `clamp` saturates D to 0 on that borrow), with no `OpISubBorrow %x %x`. The values are the same as before; the form is there for AMD's Windows driver, whose compiler dies with an access violation (`0xC0000005` in `amdvlk64.dll`, at `0xafeb87` in 32.0.21037.1004 and `0xaff2d7` in 32.0.21045.29003, Radeon iGPU of a Ryzen 9 9950X3D, gfx1036) creating a native wave64 compute pipeline in which the borrow of an `OpISubBorrow` of one value with itself predicates the value operand of an `OpGroupNonUniformShuffle`. Measured by editing the translated module of a reduced `crosslane_fuzz.py` program (`v_sub_co_u32_e64 v4, s[18:19], v1, v1`, `s_and_saveexec_b64`, `ds_bpermute_b32`): `OpISubBorrow %x %x` crashes 3 of 3, also with the same id written twice, while a borrow of two different registers, `x < x`, `x != x`, `x - 0`, a literal `false` mask, the shuffle of a literal 0 and the same module without the shuffle all compile and run. The `--wave64-emulate` form of the same programs has no shuffle and never crashed. Found with `crosslane_fuzz.py --seed 880317 --wave 64 --w64-native --no-maskdata --dpp --ext --programs 400`: programs 1 and 181 were harness errors (exit 3221225477) on both drivers and match with this form (399 of 400 match, the other one differs only in a hypothesis op, as before). Checked on the CPU by `tests/semantic/test_sub_co_same_operand.py` (wave32 and native wave64 run, the emulated form by its text). **Not counted over the corpus**: whether a game shader subtracts a register from itself with a carry out is unmeasured (no package here), and other ways for that driver to see an `OpISubBorrow` of two equal values (two registers holding the same value) are not covered. | 373| Carry-out subtract of a register from itself | `v_sub_co_u32`, `v_subrev_co_u32`, `v_sub_co_ci_u32` and `v_subrev_co_ci_u32` whose two sources are the same operand (`vD, sdst, vX, vX`) are written out as what x - x gives: D = 0 - carry in and borrow out = carry in (D = 0 and no borrow without a carry in; `clamp` saturates D to 0 on that borrow), with no `OpISubBorrow %x %x`. The values are the same as before; the form is there for AMD's Windows driver, whose compiler dies with an access violation (`0xC0000005` in `amdvlk64.dll`, at `0xafeb87` in 32.0.21037.1004 and `0xaff2d7` in 32.0.21045.29003, Radeon iGPU of a Ryzen 9 9950X3D, gfx1036) creating a native wave64 compute pipeline in which the borrow of an `OpISubBorrow` of one value with itself predicates the value operand of an `OpGroupNonUniformShuffle`. Measured by editing the translated module of a reduced `crosslane_fuzz.py` program (`v_sub_co_u32_e64 v4, s[18:19], v1, v1`, `s_and_saveexec_b64`, `ds_bpermute_b32`): `OpISubBorrow %x %x` crashes 3 of 3, also with the same id written twice, while a borrow of two different registers, `x < x`, `x != x`, `x - 0`, a literal `false` mask, the shuffle of a literal 0 and the same module without the shuffle all compile and run. The `--wave64-emulate` form of the same programs has no shuffle and never crashed. Found with `crosslane_fuzz.py --seed 880317 --wave 64 --w64-native --no-maskdata --dpp --ext --programs 400`: programs 1 and 181 were harness errors (exit 3221225477) on both drivers and match with this form (399 of 400 match, the other one differs only in a hypothesis op, as before). Checked on the CPU by `tests/semantic/test_sub_co_same_operand.py` (wave32 and native wave64 run, the emulated form by its text). **Not counted over the corpus**: whether a game shader subtracts a register from itself with a carry out is unmeasured (no package here), and other ways for that driver to see an `OpISubBorrow` of two equal values (two registers holding the same value) are not covered. |
374| Push-constant tail as a uniform block (`--pc-tail-ubo`) | For devices whose `maxPushConstantsSize` is 128, Vulkan's minimum, which can't take the 144-byte block (152 with `--mesh-compute`): AMD's older Windows drivers on RDNA2 iGPUs (Radeon 680M on 22.40.84.06, 610M on 24.10.16.14, the Ryzen 5 7600's iGPU on 24.10.24; a 610M on 26.11.2 reports 256) and some Intel Arc drivers (D3D-14, `push_constants_need_fallback` in `d3d12_vulkan_device.cpp`). The push-constant block keeps dwords 0–31 (s0–s31, 128 bytes). The tail that follows them by default, the heap base and code base and, with `--mesh-compute`, the output address, becomes `%pc_tail`: a uniform block at **set 1, binding 0** with the same members in the same order at offsets 0, 4, … (16 bytes, 24 with `--mesh-compute`). Set 1 is otherwise unused, so set 0's update-after-bind table doesn't change. The block is declared, and listed in the entry point's interface, only when the shader reads the tail (a memory access through the heap base, `s_getpc_b64`, or the `--mesh-compute` epilogue); the index then records `"pc_tail": {"set": 1, "binding": 0, "bytes": 16}`, and `"push_constant_bytes"` is 128 for every module. `"bindings"` still lists set 0 only. Without the flag nothing changes. **Checked:** `tests/test_pc_tail_ubo.py` (on `cs_store` and `ps_m15`: the block, its interface entry, `spirv-val`, the metadata, no block without a tail read, and the `--mesh-compute` address). The whole hand-written GPU test set in `runtime/test/shaders` is translated with the flag by `build.py` or `scripts/run_gpu_tests.py` under `LEONIDA_PC_TAIL_UBO=1`, and the index's `pc_tail` entries say which modules read the tail; how many do changes as shaders are added, so no count is kept here. The GPU test programs bind the block (`runtime/test/vk_pc_tail.h`; the list is in docs/testing.md), except with `--mesh-compute`, whose tests skip. The D3D12 layer does not yet: it refuses pipelines on a device with fewer than 144 push-constant bytes (`push_constants_fit` in `d3d12_vulkan_device.cpp`). | 374| Push-constant tail as a uniform block (`--pc-tail-ubo`) | For devices whose `maxPushConstantsSize` is 128, Vulkan's minimum, which can't take the 144-byte block (152 with `--mesh-compute`): AMD's older Windows drivers on RDNA2 iGPUs (Radeon 680M on 22.40.84.06, 610M on 24.10.16.14, the Ryzen 5 7600's iGPU on 24.10.24; a 610M on 26.11.2 reports 256) and some Intel Arc drivers (D3D-14, `push_constants_need_fallback` in `d3d12_vulkan_device.cpp`). The push-constant block keeps dwords 0–31 (s0–s31, 128 bytes). The tail that follows them by default, the heap base and code base and, with `--mesh-compute`, the output address, becomes `%pc_tail`: a uniform block at **set 1, binding 0** with the same members in the same order at offsets 0, 4, … (16 bytes, 24 with `--mesh-compute`). Set 1 is otherwise unused, so set 0's update-after-bind table doesn't change. The block is declared, and listed in the entry point's interface, only when the shader reads the tail (a memory access through the heap base, `s_getpc_b64`, or the `--mesh-compute` epilogue); the index then records `"pc_tail": {"set": 1, "binding": 0, "bytes": 16}`, and `"push_constant_bytes"` is 128 for every module. `"bindings"` still lists set 0 only. Without the flag nothing changes. **Checked:** `tests/test_pc_tail_ubo.py` (on `cs_store` and `ps_m15`: the block, its interface entry, `spirv-val`, the metadata, no block without a tail read, and the `--mesh-compute` address). The whole hand-written GPU test set in `runtime/test/shaders` is translated with the flag by `build.py` or `scripts/run_gpu_tests.py` under `LEONIDA_PC_TAIL_UBO=1`, and the index's `pc_tail` entries say which modules read the tail; how many do changes as shaders are added, so no count is kept here. The GPU test programs bind the block (`runtime/test/vk_pc_tail.h`; the list is in docs/testing.md), except with `--mesh-compute`, whose tests skip. The D3D12 layer does not yet: it refuses pipelines on a device with fewer than 144 push-constant bytes (`push_constants_fit` in `d3d12_vulkan_device.cpp`). |
375| Address guard (`--address-guard`) | **Prototype, off by default.** Every `Gen.host_addr` access (buffer, `global_`, scalar and BVH loads, stores and atomics) calls `%guard_fn` with the access's sign-extended 48-bit heap offset, its kind and its span. An access whose first and last byte are below the arena's size passes after one compare. Any other access looks up the 4 KiB pages of its first and last byte in the runtime's two-level page table (level 1 by offset bits 47..32, level 2 one bit per page). A refused load reads the zero area at `heap_base + 0x71000`. A refused store or atomic goes to the dump area at `+ 0x78000`, and an atomic returns 0. Each refusal is counted in the header at `+ 0x70000`. The entry block reads that header once. Without its magic (runtime `LEONIDA_ADDRESS_GUARD` unset) every access passes, and without the flag the module is unchanged byte for byte. The index records `"address_guard": true`. Format: `runtime/src/address_guard.h`, `tools/address_guard.py`; design and costs: `docs/d3d12_vulkan.md` 3.3, "Address guard". **Checked:** `tests/semantic/test_address_guard.py` (fixture `cs_address_guard` through `spirv_mini_interp` with the guard on, off at run time and without the flag; kinds and spans per instruction family; the table model), `runtime/test/address_guard_test.cpp`, and `scripts/run_address_guard_gpu_test.py` (lavapipe, Mesa 26.3.1: the refused loads read 0 over real memory, and the store and the atomic land in the dump area). |
375| `v_mad_u32_u16` / `v_mad_i32_i16` op_sel on S2 and D, and clamp | D = S0.half · S1.half + S2, the halves zero- (u16) or sign-extended (i16), op_sel bit 0 / 1 reading the high half of S0 / S1. The other bits and `clamp` were refused (`Unsupported: op_sel/clamp`) until their results were measured on RDNA2 (AMD Radeon iGPU, gfx1036, Windows driver 26.10.1, raw kernels through `tools/hw_oracle`, wave32 and wave64 alike; EGEN-HW-MAD-U32-U16, 44 words): **op_sel bit 2 adds S2[31:16] zero-extended, in the i16 op too** (`v_mad_i32_i16 d, 3, 3, 0xffff8000 op_sel:[0,0,1,0]` gives `0x00010008`, not 8); an inline float constant there is its f32 pattern (`1.0` adds `0x3f80`); **op_sel bit 3 writes the result shifted left by 16** (low half 0, the old D not kept); **`clamp` saturates the 32-bit sum** to [0, 0xffffffff] (u16) or [0x80000000, 0x7fffffff] (i16), before that shift (the 16-bit product itself never overflows). GPU-checked with `runtime/test/shaders/ps_valu16_mad_sel.asm` (4096/4096 on NVIDIA GeForce RTX 5080, driver 616.92, and the gfx1036 iGPU); CPU-checked by `tests/semantic/test_alu_mad_32_16.py` (40 seeded cases against a Python reference) and `tests/semantic/test_value_semantics.py`. | 376| `v_mad_u32_u16` / `v_mad_i32_i16` op_sel on S2 and D, and clamp | D = S0.half · S1.half + S2, the halves zero- (u16) or sign-extended (i16), op_sel bit 0 / 1 reading the high half of S0 / S1. The other bits and `clamp` were refused (`Unsupported: op_sel/clamp`) until their results were measured on RDNA2 (AMD Radeon iGPU, gfx1036, Windows driver 26.10.1, raw kernels through `tools/hw_oracle`, wave32 and wave64 alike; EGEN-HW-MAD-U32-U16, 44 words): **op_sel bit 2 adds S2[31:16] zero-extended, in the i16 op too** (`v_mad_i32_i16 d, 3, 3, 0xffff8000 op_sel:[0,0,1,0]` gives `0x00010008`, not 8); an inline float constant there is its f32 pattern (`1.0` adds `0x3f80`); **op_sel bit 3 writes the result shifted left by 16** (low half 0, the old D not kept); **`clamp` saturates the 32-bit sum** to [0, 0xffffffff] (u16) or [0x80000000, 0x7fffffff] (i16), before that shift (the 16-bit product itself never overflows). GPU-checked with `runtime/test/shaders/ps_valu16_mad_sel.asm` (4096/4096 on NVIDIA GeForce RTX 5080, driver 616.92, and the gfx1036 iGPU); CPU-checked by `tests/semantic/test_alu_mad_32_16.py` (40 seeded cases against a Python reference) and `tests/semantic/test_value_semantics.py`. |
376| `v_add_nc_i16`, `v_sub_nc_i16` | GFX10 VOP3-only signed 16-bit add and subtract. Without `clamp` they are bit-identical to `v_add_nc_u16`/`v_sub_nc_u16` (the low 16 bits wrap) and take the same path: `op_sel:[s0,s1,dst]` picks each source's half and the destination half, and the other half of D is kept. With `clamp`, the exact sum or difference of the sign-extended halves saturates to [-32768, 32767] (`SClamp`), where the u16 forms saturate to [0, 0xFFFF]. RDNA2 (GFX10.3) dropped reversed 16-bit integer subtraction (`v_subrev_nc_u16` / `v_subrev_nc_i16` do not exist on hardware; `v_subrev_f16` is the only 16-bit reverse subtract opcode). Checked by `tests/semantic/test_valu_add_sub_nc_i16.py` (a value grid with and without `clamp`, `op_sel`, literals, SGPR sources, and untouched half preservation) and **Hardware-verified on AMD RDNA2** (`gfx1036`, wave32 and wave64 via `tools/int_hw_probe.py`, `valu_add_nc_clamp/v_add_sub_nc_i16_clamp`): signed saturation to [-32768, 32767], `op_sel` source selection, and untouched destination half preservation match hardware bit-for-bit. Until 2026-11-22 both raised `Unsupported`. CPU-checked by `tests/semantic/test_valu_add_sub_nc_i16.py` (a value grid with and without `clamp`, `op_sel` including the destination half, and equality with the u16 forms without `clamp`). **GPU-verified** on native RDNA2 (gfx1036, the Radeon iGPU of a Ryzen 7 9800X3D, Windows driver 32.0.21042.62) through `tools/hw_oracle`, one-thread raw kernels: 112 of 112 directed cases (both ops; 0x7FFF+1, 0x8000+1, 0x8000+0xFFFF, 0x7FFF+0x7FFF, 0x8000+0x8000 and others, each with and without `clamp` and with `op_sel` `[0,0,0]`, `[1,0,1]`, `[0,1,0]` and `[1,1,1]`, the destination preset to 0xA5A5A5A5). For example `v_add_nc_i16(0x7FFF, 1)` gives 0x8000 wrapped and 0x7FFF with `clamp`, `v_sub_nc_i16(0x8000, 1) clamp` gives 0x8000, and the destination half `op_sel` doesn't pick keeps its 0xA5A5. `tools/pk16_diff.py --oracle translator,hw --ops v_add_nc_i16,v_sub_nc_i16 --programs 3000 --seed 1`: 3000 of 3000 programs agree with the hardware and the translator. **Not GPU-verified.** Measured on native gfx1100: `clamp` saturates the exact sign-extended sum to [-32768, 32767] and the other half of D is kept. | 377| `v_add_nc_i16`, `v_sub_nc_i16` | GFX10 VOP3-only signed 16-bit add and subtract. Without `clamp` they are bit-identical to `v_add_nc_u16`/`v_sub_nc_u16` (the low 16 bits wrap) and take the same path: `op_sel:[s0,s1,dst]` picks each source's half and the destination half, and the other half of D is kept. With `clamp`, the exact sum or difference of the sign-extended halves saturates to [-32768, 32767] (`SClamp`), where the u16 forms saturate to [0, 0xFFFF]. RDNA2 (GFX10.3) dropped reversed 16-bit integer subtraction (`v_subrev_nc_u16` / `v_subrev_nc_i16` do not exist on hardware; `v_subrev_f16` is the only 16-bit reverse subtract opcode). Checked by `tests/semantic/test_valu_add_sub_nc_i16.py` (a value grid with and without `clamp`, `op_sel`, literals, SGPR sources, and untouched half preservation) and **Hardware-verified on AMD RDNA2** (`gfx1036`, wave32 and wave64 via `tools/int_hw_probe.py`, `valu_add_nc_clamp/v_add_sub_nc_i16_clamp`): signed saturation to [-32768, 32767], `op_sel` source selection, and untouched destination half preservation match hardware bit-for-bit. Until 2026-11-22 both raised `Unsupported`. CPU-checked by `tests/semantic/test_valu_add_sub_nc_i16.py` (a value grid with and without `clamp`, `op_sel` including the destination half, and equality with the u16 forms without `clamp`). **GPU-verified** on native RDNA2 (gfx1036, the Radeon iGPU of a Ryzen 7 9800X3D, Windows driver 32.0.21042.62) through `tools/hw_oracle`, one-thread raw kernels: 112 of 112 directed cases (both ops; 0x7FFF+1, 0x8000+1, 0x8000+0xFFFF, 0x7FFF+0x7FFF, 0x8000+0x8000 and others, each with and without `clamp` and with `op_sel` `[0,0,0]`, `[1,0,1]`, `[0,1,0]` and `[1,1,1]`, the destination preset to 0xA5A5A5A5). For example `v_add_nc_i16(0x7FFF, 1)` gives 0x8000 wrapped and 0x7FFF with `clamp`, `v_sub_nc_i16(0x8000, 1) clamp` gives 0x8000, and the destination half `op_sel` doesn't pick keeps its 0xA5A5. `tools/pk16_diff.py --oracle translator,hw --ops v_add_nc_i16,v_sub_nc_i16 --programs 3000 --seed 1`: 3000 of 3000 programs agree with the hardware and the translator. **Not GPU-verified.** Measured on native gfx1100: `clamp` saturates the exact sign-extended sum to [-32768, 32767] and the other half of D is kept. |
377| Gather sampler LOD | Before choosing the mip for the four fetches in `image_gather4_l(_o)`, clamp the requested LOD to S# word 1's MIN_LOD [11:0] and MAX_LOD [23:12] (unsigned 4.8). `ps_gather_sampler_lod.asm` reads the S# from the heap. On RTX 5080 and Radeon Graphics, a maximum of 0.25 selects the base quadrants and a minimum of 0.75 selects the cyan mip across the 64×64 draw. Without these bounds half of each frame reads the wrong level. Radeon also agreed with native `OpImageGather Lod` (`VK_AMD_texture_gather_bias_lod`) for those bounds. At exactly 0.5, with bounds [0,1], that native draw selected mip 1; the emulation now computes the mip as `Floor(LOD + 0.5)`, ties up, and also selects mip 1 (before SHADER-152 it used `RoundEven`, which selected mip 0). It computes `floor(LOD) + (LOD - floor(LOD) >= 0.5)`, which is exact in binary32, not `Floor(LOD + 0.5)`: that sum rounds `0x3effffff` up to 1.0, and on an RTX 5070 (621.24) the gather then read mip 1 where native `image_sample_l` at the same LOD reads mip 0. | 378| Gather sampler LOD | Before choosing the mip for the four fetches in `image_gather4_l(_o)`, clamp the requested LOD to S# word 1's MIN_LOD [11:0] and MAX_LOD [23:12] (unsigned 4.8). `ps_gather_sampler_lod.asm` reads the S# from the heap. On RTX 5080 and Radeon Graphics, a maximum of 0.25 selects the base quadrants and a minimum of 0.75 selects the cyan mip across the 64×64 draw. Without these bounds half of each frame reads the wrong level. Radeon also agreed with native `OpImageGather Lod` (`VK_AMD_texture_gather_bias_lod`) for those bounds. At exactly 0.5, with bounds [0,1], that native draw selected mip 1; the emulation now computes the mip as `Floor(LOD + 0.5)`, ties up, and also selects mip 1 (before SHADER-152 it used `RoundEven`, which selected mip 0). It computes `floor(LOD) + (LOD - floor(LOD) >= 0.5)`, which is exact in binary32, not `Floor(LOD + 0.5)`: that sum rounds `0x3effffff` up to 1.0, and on an RTX 5070 (621.24) the gather then read mip 1 where native `image_sample_l` at the same LOD reads mip 0. |
@@ -444,6 +445,7 @@ How the generated SPIR-V expects the runtime to work:
444| Scalar copies through VCC | SGPRs 106 and 107 can hold two data words, including a buffer descriptor's count and format. A 64-bit move through VCC preserves both when its reads within the block use them as data. Predicate users and live-out VCC constrain this inference. A wide scalar load into a tuple ending in VCC writes both physical words. The synthetic descriptor fixture checks numeric copies, a round trip, and a subsequent tuple load on wave32 and emulated wave64. | 445| Scalar copies through VCC | SGPRs 106 and 107 can hold two data words, including a buffer descriptor's count and format. A 64-bit move through VCC preserves both when its reads within the block use them as data. Predicate users and live-out VCC constrain this inference. A wide scalar load into a tuple ending in VCC writes both physical words. The synthetic descriptor fixture checks numeric copies, a round trip, and a subsequent tuple load on wave32 and emulated wave64. |
445| Signed-byte dot products | `v_dot4_i32_i8 D, S0, S1, S2` (VOP3P) is S2 plus the sum of the four products of the sign-extended bytes of S0 and S1, modulo 2^32; `v_dot4c_i32_i8 D, S0, S1` (VOP2) adds the same sum to D. Emitted as four pairs of `OpBitFieldSExtract`, `OpIMul` and `OpIAdd`. **Confirmed on RDNA2 hardware** (gfx1036, raw kernels through `tools/hw_oracle`): 10 operand sets, both instructions and both source orders of the accumulating one, with sign-mixed bytes and sums that wrap; the measured words are the table in `tests/semantic/test_alu_dot4_i8.py`. `clamp` and `op_sel`/`op_sel_hi` are translated and checked against the same `gfx1036` hardware table: `clamp` saturates `v_dot4_i32_i8` to signed 32-bit `[-2^31, 2^31-1]` (both overflowing sets), and `op_sel`/`op_sel_hi` pick the 16-bit half of S0/S1 for byte pairs 0..1 and 2..3 (e.g. `op_sel` 2 / `op_sel_hi` 5 exchanges the 16-bit halves of S1, matching all 5 measured sets — the form of the 89 words `llvm-mc` does not decode, [fspx.md](fspx.md)); non-default S2 half selection stays refused. How each `op_sel`/`op_sel_hi` form that can reach the translator is confirmed: (1) `op_sel` 2 / `op_sel_hi` 5 without `clamp` or `neg`, which `llvm-mc` rejects: measured on `gfx1036` (the 5 sets above); `shader_disasm.py` prints it with its real encoding (`tests/semantic/test_fspx_dot4_op_sel_disasm.py`) and `skipped_form` recovers it from a gap in a listing made without that pass. (2) `op_sel` 0 / `op_sel_hi` 5 with an inline integer S1 and no `clamp` or `neg`, which `llvm-mc` decodes but prints with the default `op_sel_hi` 7: `restore_dot4_inline_sel` takes the stored field back, in a clean listing (`check_printed_encodings`) and in both re-anchoring paths; `op_sel_hi[1]` clear makes byte pairs 2..3 read S1's low half, the selection measured in (1), but the word itself was not run on hardware; confirmed by a count over the corpus (29 FidelityFX DLL programs, 1.0.2.1, LLVM 21.1.8: 22 translate without it, 24 with it, all 24 pass `spirv-val`; Code-embedded data row) and pinned by `tests/semantic/test_reanchor_dot4_inline_sel.py`. (3) Every other form `llvm-mc` decodes but prints with the default fields (for example `op_sel_hi` 5 with a VGPR S1, or `op_sel` 1 / `op_sel_hi` 6) is not measured and is refused as a dropped field; `tests/semantic/test_dot4_printed_op_sel.py` checks forms (2) and (3) with hand-built words. A general rule that took the stored fields of any such word (from luizwidmer/palmetto) was not taken for that reason. `neg_lo`/`neg_hi`, which `llvm-mc` accepts on `v_dot4_i32_i8` only, are not ignored (`neg_lo` flips bit 15 and `neg_hi` bit 31 of S0 or S1, and on S2 `neg_hi` clears bit 31 before `neg_lo` flips it; 5 sets under 8 forms, 45 words): any set bit stays Unsupported, while an all-zero field is the plain instruction. Counts: the 29 FSPX programs use the pair 27,271 times (`v_dot4c_i32_i8` 25,813, `v_dot4_i32_i8` 1,458), all in 13 programs; none of the game's own 26,503 shaders has either encoding (0 of the 12,791 words `llvm-mc` cannot decode there with gfx1013). The measured unclamped `op_sel` 2 / `op_sel_hi` 5 form is also recovered from the bytes on a gap in a listing that `shader_disasm.py` did not print it into (`skipped_form`, #984). | 446| Signed-byte dot products | `v_dot4_i32_i8 D, S0, S1, S2` (VOP3P) is S2 plus the sum of the four products of the sign-extended bytes of S0 and S1, modulo 2^32; `v_dot4c_i32_i8 D, S0, S1` (VOP2) adds the same sum to D. Emitted as four pairs of `OpBitFieldSExtract`, `OpIMul` and `OpIAdd`. **Confirmed on RDNA2 hardware** (gfx1036, raw kernels through `tools/hw_oracle`): 10 operand sets, both instructions and both source orders of the accumulating one, with sign-mixed bytes and sums that wrap; the measured words are the table in `tests/semantic/test_alu_dot4_i8.py`. `clamp` and `op_sel`/`op_sel_hi` are translated and checked against the same `gfx1036` hardware table: `clamp` saturates `v_dot4_i32_i8` to signed 32-bit `[-2^31, 2^31-1]` (both overflowing sets), and `op_sel`/`op_sel_hi` pick the 16-bit half of S0/S1 for byte pairs 0..1 and 2..3 (e.g. `op_sel` 2 / `op_sel_hi` 5 exchanges the 16-bit halves of S1, matching all 5 measured sets — the form of the 89 words `llvm-mc` does not decode, [fspx.md](fspx.md)); non-default S2 half selection stays refused. How each `op_sel`/`op_sel_hi` form that can reach the translator is confirmed: (1) `op_sel` 2 / `op_sel_hi` 5 without `clamp` or `neg`, which `llvm-mc` rejects: measured on `gfx1036` (the 5 sets above); `shader_disasm.py` prints it with its real encoding (`tests/semantic/test_fspx_dot4_op_sel_disasm.py`) and `skipped_form` recovers it from a gap in a listing made without that pass. (2) `op_sel` 0 / `op_sel_hi` 5 with an inline integer S1 and no `clamp` or `neg`, which `llvm-mc` decodes but prints with the default `op_sel_hi` 7: `restore_dot4_inline_sel` takes the stored field back, in a clean listing (`check_printed_encodings`) and in both re-anchoring paths; `op_sel_hi[1]` clear makes byte pairs 2..3 read S1's low half, the selection measured in (1), but the word itself was not run on hardware; confirmed by a count over the corpus (29 FidelityFX DLL programs, 1.0.2.1, LLVM 21.1.8: 22 translate without it, 24 with it, all 24 pass `spirv-val`; Code-embedded data row) and pinned by `tests/semantic/test_reanchor_dot4_inline_sel.py`. (3) Every other form `llvm-mc` decodes but prints with the default fields (for example `op_sel_hi` 5 with a VGPR S1, or `op_sel` 1 / `op_sel_hi` 6) is not measured and is refused as a dropped field; `tests/semantic/test_dot4_printed_op_sel.py` checks forms (2) and (3) with hand-built words. A general rule that took the stored fields of any such word (from luizwidmer/palmetto) was not taken for that reason. `neg_lo`/`neg_hi`, which `llvm-mc` accepts on `v_dot4_i32_i8` only, are not ignored (`neg_lo` flips bit 15 and `neg_hi` bit 31 of S0 or S1, and on S2 `neg_hi` clears bit 31 before `neg_lo` flips it; 5 sets under 8 forms, 45 words): any set bit stays Unsupported, while an all-zero field is the plain instruction. Counts: the 29 FSPX programs use the pair 27,271 times (`v_dot4c_i32_i8` 25,813, `v_dot4_i32_i8` 1,458), all in 13 programs; none of the game's own 26,503 shaders has either encoding (0 of the 12,791 words `llvm-mc` cannot decode there with gfx1013). The measured unclamped `op_sel` 2 / `op_sel_hi` 5 form is also recovered from the bytes on a gap in a listing that `shader_disasm.py` did not print it into (`skipped_form`, #984). |
446| Workgroup barriers | `s_barrier` (cs/ms) is one `OpControlBarrier` (workgroup scope, workgroup memory). On RDNA every `s_barrier` counts against the same workgroup barrier and a wave that has ended no longer counts, while Vulkan requires a barrier to be reached by every invocation in uniform control flow. Under `--wave64-emulate` the round loop keeps a single barrier at the top level, so this holds. **Native wave32 compute shaders run in barrier rounds** when an `s_barrier` sits anywhere but a top-level block of the structured tree (one every invocation runs): under a guard, in a loop, or in the dispatch loop (`needs_barrier_rounds`, `bar_scheduler`). That is the emulated loop without its cross-lane part: `s_barrier` ends a segment, each invocation runs its blocks until its next `s_barrier` or the end, then the whole workgroup meets at one `OpControlBarrier` (the same workgroup/acquire-release/workgroup-memory semantics) at the end of the round. A wave that is done no longer holds the others, and a per-round count of the invocations not done (three `Workgroup` words, by round mod 3) ends the loop. A wave that is done no longer holds the others, and a per-round count of the invocations not done (three `Workgroup` words, by round mod 3, or a borrowed LDS word with a large LDS: "Barrier-round count in LDS (SHADER-579)") ends the loop. Cross-lane operations stay subgroup operations, as in the dispatch loop, since a wave's lanes run the same segment. A barrier in a top-level block keeps the single `OpControlBarrier` in place. In the 1.0.2.1 corpus 43 of the 55 wave32 cs shaders with `s_barrier` have one nested (SHADER-91's count), so those 43 now run in rounds. Why: an Intel GPU does not survive the nested form. `cs_barrier_divergent.asm` (two barrier sites in different branches), `cs_barrier_early_end.asm` (the other waves end without a barrier) and `cs_barrier_loop.asm` (a barrier in a loop whose trip count differs per wave) each lose the device (`vkQueueWaitIdle` → `VK_ERROR_DEVICE_LOST`) on an Intel Arrow Lake Xe-LPG iGPU (Windows 32.0.101.8132), and `cs_barrier_divergent` hangs or writes nothing on a UHD 770 (101.6129, #634). With barrier rounds all three pass there and on an RTX 5070 Ti Laptop (617.42). NVIDIA passed them before too (RTX 4070 Ti on 610.88 and 621.24, RTX 5090 on Linux 595.99, RTX 5070 Ti). **Still not proven on the native wave64 path** (wave64 cs and every ms, run natively only on AMD's 64-wide subgroups): there the barrier stays where `s_barrier` is, inside a selection or loop construct in every ms and most wave64 cs shaders of the corpus. Branches are scalar, so whole waves take the same path, and RDNA's own barrier counts the way the shader expects. | 447| Workgroup barriers | `s_barrier` (cs/ms) is one `OpControlBarrier` (workgroup scope, workgroup memory). On RDNA every `s_barrier` counts against the same workgroup barrier and a wave that has ended no longer counts, while Vulkan requires a barrier to be reached by every invocation in uniform control flow. Under `--wave64-emulate` the round loop keeps a single barrier at the top level, so this holds. **Native wave32 compute shaders run in barrier rounds** when an `s_barrier` sits anywhere but a top-level block of the structured tree (one every invocation runs): under a guard, in a loop, or in the dispatch loop (`needs_barrier_rounds`, `bar_scheduler`). That is the emulated loop without its cross-lane part: `s_barrier` ends a segment, each invocation runs its blocks until its next `s_barrier` or the end, then the whole workgroup meets at one `OpControlBarrier` (the same workgroup/acquire-release/workgroup-memory semantics) at the end of the round. A wave that is done no longer holds the others, and a per-round count of the invocations not done (three `Workgroup` words, by round mod 3) ends the loop. A wave that is done no longer holds the others, and a per-round count of the invocations not done (three `Workgroup` words, by round mod 3, or a borrowed LDS word with a large LDS: "Barrier-round count in LDS (SHADER-579)") ends the loop. Cross-lane operations stay subgroup operations, as in the dispatch loop, since a wave's lanes run the same segment. A barrier in a top-level block keeps the single `OpControlBarrier` in place. In the 1.0.2.1 corpus 43 of the 55 wave32 cs shaders with `s_barrier` have one nested (SHADER-91's count), so those 43 now run in rounds. Why: an Intel GPU does not survive the nested form. `cs_barrier_divergent.asm` (two barrier sites in different branches), `cs_barrier_early_end.asm` (the other waves end without a barrier) and `cs_barrier_loop.asm` (a barrier in a loop whose trip count differs per wave) each lose the device (`vkQueueWaitIdle` → `VK_ERROR_DEVICE_LOST`) on an Intel Arrow Lake Xe-LPG iGPU (Windows 32.0.101.8132), and `cs_barrier_divergent` hangs or writes nothing on a UHD 770 (101.6129, #634). With barrier rounds all three pass there and on an RTX 5070 Ti Laptop (617.42). NVIDIA passed them before too (RTX 4070 Ti on 610.88 and 621.24, RTX 5090 on Linux 595.99, RTX 5070 Ti). **Still not proven on the native wave64 path** (wave64 cs and every ms, run natively only on AMD's 64-wide subgroups): there the barrier stays where `s_barrier` is, inside a selection or loop construct in every ms and most wave64 cs shaders of the corpus. Branches are scalar, so whole waves take the same path, and RDNA's own barrier counts the way the shader expects. |
448| Wave64 emulation: single-wave barrier fallback | `translate()` re-translates an emulated compute program as the round loop (`Gen.x_scheduler`) when its inline structured form has an `OpControlBarrier` inside a selection or loop construct (`barriers_under_control_flow`), because a barrier only part of the workgroup reaches hangs NVIDIA (Xid 109). That fallback applies **only to multi-wave plans**. A single-wave workgroup (`plan_structured_emulation` mode `inline_all`, `x_lanes == 64`, also a partial group of fewer than 64 threads) is one wave: `%pc` between blocks comes from scalar state and votes read back from `%x_buf`, so every invocation takes the same path, and lane-local `%pc` exists only inside `emit_folded_region`'s `if (%active)` bodies, which emit no exchange and no barrier. Its barriers stay where the exchanges are, at the top level or under `%pc`-only guards. Why: the round loop keeps nearly the whole register file live across its back edge and through a switch over every segment (thousands of cases in large programs); on RADV/ACO (RX 7900 XTX, Mesa 26.3.1, offline `vk_pipeline_check` compiles only) that drove `aco::spill` past a 12 GiB cap (53 GB uncapped) on a large single-wave program the structured form compiles in 7–8.5 min under 3 GiB, and past 12 GiB in 35 s on a 4.9 MB one that compiles in 5 s at 0.3 GiB structured. ACO's static latency for single-wave programs with loops was 17 to 280 times that of the structured form, with VGPR spills each round, and three such programs (loops of up to thousands of iterations, one round per block visited) hung game runs on that GPU. Confirmed by a count over the 1.0.2.1 corpus: of the 820 single-wave emulated compute shaders of the main set that the fallback had put in the round loop, 666 get an `inline_all` plan, and in all 666 every barrier is at the top level or under constructs whose conditions load only `%pc` (none reads `%active`, a VGPR or `local_id`); the other 154 have no plan and stay rounds either way. Re-translated with this rule, exactly those 666 come out structured, the pipeline library's single-wave rounds drop from 818 to 171 (all 297 of them with loops are structured), and the translated and `spirv-val`-valid counts are unchanged (26,503 main, 2,683 library); recompiled, the 4.9 MB program takes 3.6 s at 0.37 GiB. CPU-checked by `tests/semantic/test_wave64_single_wave_barrier.py` (`wave64_single_wave_barrier.asm`: a cross-half `v_readlane_b32` in a uniform loop and a uniform branch, structured and round forms give the same words, every barrier guard loads only `%pc`), `test_wave64_emulate_opt.py` (`cs_inline_64`/`cs_inline_40`, both wave orders) and `test_loop_ballot_barrier.py`. **Not GPU-verified on NVIDIA**, the platform the fallback was written for. |
447| Barrier-round count in LDS (SHADER-579) | Barrier rounds (see "Workgroup barriers") count the invocations not done in `%x_buf`, three `Workgroup` dwords (#930). On a full 32 KiB LDS that made 32,780 B, 12 bytes over the 32,768 B `maxComputeSharedMemorySize` of the AMD Windows (RX 9070 XT) and Intel (UHD 770) drivers, so the runtime refused those pipelines (2 native wave32 cs in towade's 1.0.2.1 corpus, [finding](https://github.com/ItsNotRexed/Leonida/pull/1882#issuecomment-7084298032)). Rule (`bar_counts_in_lds`): when the shader uses its LDS and the LDS array plus 12 bytes is over 16,384 B (the Vulkan minimum limit, so in practice an array of 16, 32 or 64 KiB), there is no `%x_buf`. The count borrows LDS word 0 at the end of each round (`bar_scheduler_tail`): after the round's barrier every invocation is done or waits at `s_barrier`, so no shader code runs; invocation 0 saves the word in a Function variable and clears it, barrier, every invocation not done adds 1 atomically, barrier, all read the count, barrier, invocation 0 stores the saved word back, barrier. The shader sees its LDS bit for bit as before, and the four extra barriers sit where the whole workgroup already waits, so `s_barrier`'s semantics are unchanged; the cost is four more `OpControlBarrier`s per round in those shaders only. Below the threshold `%x_buf` stays (12 bytes fit every device) with one barrier per round; a shader that never touches its LDS also keeps it (no array to borrow from, 12 B in all). A 32 KiB LDS is now exactly 32,768 B and a 64 KiB one 65,536 B (before: 65,548 B, refused or shrunk to its allocation). Not chosen: putting the count in LDS the shader never touches (unprovable with dynamic addresses), or deciding per device (the translator runs offline). Pinned by `tests/semantic/test_cs_barrier_counts_lds.py` (Workgroup bytes from the emitted SPIR-V and `lds_bytes` for 32 KiB, 64 KiB and small LDS, under a 32 KiB `--max-shared-memory`; ring shifts across 10 barriers that read word 0 and an early-ending wave in the workgroup interpreter, whose LDS starts as 0xDEADBEEF, in both wave orders). Confirmed by those CPU tests only; GPU runs on the 32 KiB devices are pending. | 449| Barrier-round count in LDS (SHADER-579) | Barrier rounds (see "Workgroup barriers") count the invocations not done in `%x_buf`, three `Workgroup` dwords (#930). On a full 32 KiB LDS that made 32,780 B, 12 bytes over the 32,768 B `maxComputeSharedMemorySize` of the AMD Windows (RX 9070 XT) and Intel (UHD 770) drivers, so the runtime refused those pipelines (2 native wave32 cs in towade's 1.0.2.1 corpus, [finding](https://github.com/ItsNotRexed/Leonida/pull/1882#issuecomment-7084298032)). Rule (`bar_counts_in_lds`): when the shader uses its LDS and the LDS array plus 12 bytes is over 16,384 B (the Vulkan minimum limit, so in practice an array of 16, 32 or 64 KiB), there is no `%x_buf`. The count borrows LDS word 0 at the end of each round (`bar_scheduler_tail`): after the round's barrier every invocation is done or waits at `s_barrier`, so no shader code runs; invocation 0 saves the word in a Function variable and clears it, barrier, every invocation not done adds 1 atomically, barrier, all read the count, barrier, invocation 0 stores the saved word back, barrier. The shader sees its LDS bit for bit as before, and the four extra barriers sit where the whole workgroup already waits, so `s_barrier`'s semantics are unchanged; the cost is four more `OpControlBarrier`s per round in those shaders only. Below the threshold `%x_buf` stays (12 bytes fit every device) with one barrier per round; a shader that never touches its LDS also keeps it (no array to borrow from, 12 B in all). A 32 KiB LDS is now exactly 32,768 B and a 64 KiB one 65,536 B (before: 65,548 B, refused or shrunk to its allocation). Not chosen: putting the count in LDS the shader never touches (unprovable with dynamic addresses), or deciding per device (the translator runs offline). Pinned by `tests/semantic/test_cs_barrier_counts_lds.py` (Workgroup bytes from the emitted SPIR-V and `lds_bytes` for 32 KiB, 64 KiB and small LDS, under a 32 KiB `--max-shared-memory`; ring shifts across 10 barriers that read word 0 and an early-ending wave in the workgroup interpreter, whose LDS starts as 0xDEADBEEF, in both wave orders). Confirmed by those CPU tests only; GPU runs on the 32 KiB devices are pending. |
448| LDS | A `Workgroup` uint array sized from LDS_SIZE, rounded up to a power of two that also covers every constant offset (15 of 486 shaders index past LDS_SIZE). Covers `ds_read/write_b32..b128`, `read2/write2` (+`st64`), `u16`/`i16`/`u8`/`i8` reads (also `ds_read_u16_d16`/`_d16_hi` and, since SHADER-85, `ds_read_u8_d16`/`_d16_hi` and `ds_read_i8_d16`/`_d16_hi`: the byte is zero- or sign-extended 8→16 into one half of the destination VGPR and the other half is kept, per the RDNA2 ISA DS opcode descriptions (opcodes 162–165) and as for the u16 d16 reads; GPU-checked with `cs_w32_lds_u8_d16.asm`, byte values 0x80/0xFF/0x7F with a non-zero `offset:`), `b16`/`b8` writes (atomic and/or, so neighbouring lanes don't race; a 16-bit read or write at byte 3 of a dword also reads or writes byte 0 of the next dword, as llc-15 `-mcpu=gfx1030 -mattr=+unaligned-access-mode` emits one `ds_read_u16`/`ds_write_b16 ... offset:3` for an align-1 halfword; until 2026-11-22 the reads extracted 16 bits at bit 24, undefined in SPIR-V, and the writes kept only byte 3; `tests/semantic/test_lds_u16_cross_dword.py`), the add/sub/min/max/and/or/xor atomics with and without return, `wrxchg`, `cmpst` (`OpAtomicCompareExchange` with DATA as comparator and DATA2 as value), and `ds_bpermute_b32` as a subgroup shuffle. GPU-checked with `cs_w32_lds_u8_d16.asm`, byte values 0x80/0xFF/0x7F with a non-zero `offset:`), `b16`/`b8` writes (atomic and/or, so neighbouring lanes don't race), the add/sub/min/max/and/or/xor atomics with and without return, `wrxchg`, `cmpst` (`OpAtomicCompareExchange` with DATA as comparator and DATA2 as value), and `ds_bpermute_b32` as a subgroup shuffle. `ds_permute_b32`, its forward (scatter) form, has no Vulkan equivalent: each source lane that is on in EXEC publishes `((vAddr + offset) >> 2) mod 32` and each destination lane scans the 32 sources of its half and keeps the last one that targets it (a shuffle of target and data per source lane; under `--wave64-emulate` two buffer rounds and a Function variable instead). Per the ISA pseudocode (`tmp[0..63] = 0`; `next if !EXEC[i]` on the source; `VGPR[VDST][i] = tmp[i]` only `if EXEC[i]`): a destination lane nobody targets gets 0, an off source sends nothing, an off destination keeps its VDST, and the half rule above applies as for `ds_bpermute_b32`. When several sources target one lane the ISA leaves the winner unpredictable ("the value from one of the writers"; its pseudocode says the highest-numbered); the translator takes the highest, and nothing may depend on it. Confirmed by the GPU tests `cs_w32_permute.asm` and, per half of a wave64, `cs_w64x_permute.asm` (SHADER-90: rotation, offset, unwritten lane = 0, off destination keeps its value, off source does not win), `cs_w32_partial_permute.asm` (a 20-thread wave32: a launched lane whose source lane was never launched gets 0, and a send to a missing lane is lost; the same words from a raw 20-thread `hw_oracle` kernel on `gfx1036`) and `tests/semantic/test_ds_permute.py`. **Hardware-verified on RDNA2 (`gfx1036`, AMD Ryzen 7 9800X3D iGPU, Linux AMDGPU DRM via `tools/hw_oracle`, wave32 and wave64, SHADER-133)** with `tools/ds_permute_probe.py` (9/9 cases exact in both wave sizes): unaddressed active lanes get 0, off destinations keep VDST, off sources send nothing, 2-/4-/32-way collisions deterministically take the highest-numbered active lane in the 32-lane half (matching the translator), `vAddr + offset` carries from the low 2 bits before `>> 2` mod 32, wave64 runs as two independent 32-lane halves (`+32` wraps within each half), and missing lanes of a partial wave (20 threads in wave32, 40 in wave64) send nothing. A source lane that is off in EXEC reads 0 and an off destination lane keeps its value (RDNA ISA §10.4.4), in wave32 as in wave64. In wave64 the permute also runs as two wave32s: each half reads lanes of its own half. Until 2026-11-21 lanes 32–63 of a 64-wide subgroup read the low half and inactive sources kept their value (`cs_w64x_bpermute`, AMD Radeon 880M); the wave32 path shuffled the raw value until the same day (`cs_bpermute32`: wave32, EXEC without lanes 8–15, so lane 6 reads 0; GPU-checked on RTX 5070 and Radeon 880M). A source lane that doesn't exist, in the missing lanes of a partial wave, also reads 0: the shuffle result is kept only where a ballot of the running invocations has the source lane, since SPIR-V leaves a shuffle from an invocation that isn't running undefined. Before this, RADV returned stale register values that changed between runs (`cs_w64x_partial`, a 40-thread group, native wave64 on AMD RX 6700 XT, RADV Mesa 26.3.1). Writes and atomics run only in active lanes. Indices wrap at the array size, where hardware would return 0 for out-of-range reads. `s_barrier` = `OpControlBarrier` Workgroup/Workgroup, AcquireRelease + WorkgroupMemory. | 450| LDS | A `Workgroup` uint array sized from LDS_SIZE, rounded up to a power of two that also covers every constant offset (15 of 486 shaders index past LDS_SIZE). Covers `ds_read/write_b32..b128`, `read2/write2` (+`st64`), `u16`/`i16`/`u8`/`i8` reads (also `ds_read_u16_d16`/`_d16_hi` and, since SHADER-85, `ds_read_u8_d16`/`_d16_hi` and `ds_read_i8_d16`/`_d16_hi`: the byte is zero- or sign-extended 8→16 into one half of the destination VGPR and the other half is kept, per the RDNA2 ISA DS opcode descriptions (opcodes 162–165) and as for the u16 d16 reads; GPU-checked with `cs_w32_lds_u8_d16.asm`, byte values 0x80/0xFF/0x7F with a non-zero `offset:`), `b16`/`b8` writes (atomic and/or, so neighbouring lanes don't race; a 16-bit read or write at byte 3 of a dword also reads or writes byte 0 of the next dword, as llc-15 `-mcpu=gfx1030 -mattr=+unaligned-access-mode` emits one `ds_read_u16`/`ds_write_b16 ... offset:3` for an align-1 halfword; until 2026-11-22 the reads extracted 16 bits at bit 24, undefined in SPIR-V, and the writes kept only byte 3; `tests/semantic/test_lds_u16_cross_dword.py`), the add/sub/min/max/and/or/xor atomics with and without return, `wrxchg`, `cmpst` (`OpAtomicCompareExchange` with DATA as comparator and DATA2 as value), and `ds_bpermute_b32` as a subgroup shuffle. GPU-checked with `cs_w32_lds_u8_d16.asm`, byte values 0x80/0xFF/0x7F with a non-zero `offset:`), `b16`/`b8` writes (atomic and/or, so neighbouring lanes don't race), the add/sub/min/max/and/or/xor atomics with and without return, `wrxchg`, `cmpst` (`OpAtomicCompareExchange` with DATA as comparator and DATA2 as value), and `ds_bpermute_b32` as a subgroup shuffle. `ds_permute_b32`, its forward (scatter) form, has no Vulkan equivalent: each source lane that is on in EXEC publishes `((vAddr + offset) >> 2) mod 32` and each destination lane scans the 32 sources of its half and keeps the last one that targets it (a shuffle of target and data per source lane; under `--wave64-emulate` two buffer rounds and a Function variable instead). Per the ISA pseudocode (`tmp[0..63] = 0`; `next if !EXEC[i]` on the source; `VGPR[VDST][i] = tmp[i]` only `if EXEC[i]`): a destination lane nobody targets gets 0, an off source sends nothing, an off destination keeps its VDST, and the half rule above applies as for `ds_bpermute_b32`. When several sources target one lane the ISA leaves the winner unpredictable ("the value from one of the writers"; its pseudocode says the highest-numbered); the translator takes the highest, and nothing may depend on it. Confirmed by the GPU tests `cs_w32_permute.asm` and, per half of a wave64, `cs_w64x_permute.asm` (SHADER-90: rotation, offset, unwritten lane = 0, off destination keeps its value, off source does not win), `cs_w32_partial_permute.asm` (a 20-thread wave32: a launched lane whose source lane was never launched gets 0, and a send to a missing lane is lost; the same words from a raw 20-thread `hw_oracle` kernel on `gfx1036`) and `tests/semantic/test_ds_permute.py`. **Hardware-verified on RDNA2 (`gfx1036`, AMD Ryzen 7 9800X3D iGPU, Linux AMDGPU DRM via `tools/hw_oracle`, wave32 and wave64, SHADER-133)** with `tools/ds_permute_probe.py` (9/9 cases exact in both wave sizes): unaddressed active lanes get 0, off destinations keep VDST, off sources send nothing, 2-/4-/32-way collisions deterministically take the highest-numbered active lane in the 32-lane half (matching the translator), `vAddr + offset` carries from the low 2 bits before `>> 2` mod 32, wave64 runs as two independent 32-lane halves (`+32` wraps within each half), and missing lanes of a partial wave (20 threads in wave32, 40 in wave64) send nothing. A source lane that is off in EXEC reads 0 and an off destination lane keeps its value (RDNA ISA §10.4.4), in wave32 as in wave64. In wave64 the permute also runs as two wave32s: each half reads lanes of its own half. Until 2026-11-21 lanes 32–63 of a 64-wide subgroup read the low half and inactive sources kept their value (`cs_w64x_bpermute`, AMD Radeon 880M); the wave32 path shuffled the raw value until the same day (`cs_bpermute32`: wave32, EXEC without lanes 8–15, so lane 6 reads 0; GPU-checked on RTX 5070 and Radeon 880M). A source lane that doesn't exist, in the missing lanes of a partial wave, also reads 0: the shuffle result is kept only where a ballot of the running invocations has the source lane, since SPIR-V leaves a shuffle from an invocation that isn't running undefined. Before this, RADV returned stale register values that changed between runs (`cs_w64x_partial`, a 40-thread group, native wave64 on AMD RX 6700 XT, RADV Mesa 26.3.1). Writes and atomics run only in active lanes. Indices wrap at the array size, where hardware would return 0 for out-of-range reads. `s_barrier` = `OpControlBarrier` Workgroup/Workgroup, AcquireRelease + WorkgroupMemory. |
449| LDS access order within a wave (`Volatile`) | RDNA2 runs a wave in lockstep with an in-order LDS queue, so a `ds_read` issued after a `ds_write` sees every lane's write with no `s_barrier` between them (`cs_w64x_lds_raw`), and a `ds_write` issued after a `ds_read` does not change what that read returned (`cs_w64x_lds_war`). Translated, a lane is an invocation, and the Vulkan memory model orders nothing between invocations without a barrier or an atomic, so a driver's compiler may move an invocation's load ahead of its own earlier store to another address, or merge two loads of one address. Results consistent with these optimizations were observed with AMD's Windows driver 24.30.46 (LLPC, Vulkan 1.3.302) on a Radeon 880M (RDNA3.5, native 64-wide compute subgroups): on `main` `561b65a8` both tests failed on every run with uninitialized Workgroup memory in all eight words, and in `cs_w64x_lds_war` the second read returned the same words as the first. Rule: every plain LDS `OpLoad` and `OpStore` (`lds_load`, `lds_store` and the two ADDTID forms) carries the `Volatile` memory operand, which prevents elimination, duplication or combination of the access ([SPIR-V memory operands](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Memory_Access)). This rule applies to plain accesses only. On that GPU and driver `Volatile` on the store alone or on the load alone made `cs_w64x_lds_raw` return its expected words (hand-edited SPIR-V, 3 of 3 runs each, against 0 of 4 unmodified), and with the rule both tests pass: `run_gpu_tests.py` goes from 210 to 212 of 232 passed with none failing (20 skipped), native and with `LEONIDA_W64_EMULATE=1`. An RTX 5070 Laptop (NVIDIA 621.01) gives the same results before and after (183 of 232 native, 214 emulated; `ms_wave_info_s3` fails both times). The operand changes 17 of the 238 test shaders and nothing but those loads and stores. A [full Xbox 1.0.2.1 corpus comparison](https://github.com/ItsNotRexed/Leonida/pull/6714#issuecomment-7107280378) translated and validated all 26,503 shaders at both 561b65a8 and 58deee34. Only the added operands differed in the 484 compute and 5 mesh modules that changed. The RAW and WAR results establish a workaround on the tested driver. Portable ordering between invocations requires synchronization appropriate to the accesses (see #2345). Under `--wave64-emulate` the halves meet at the round barriers as before; the operand is emitted there too. CPU-checked by `tests/semantic/test_lds_volatile.py` (every plain access form on the wave32, wave64 and emulated paths, and no other access is Volatile). | 451| LDS access order within a wave (`Volatile`) | RDNA2 runs a wave in lockstep with an in-order LDS queue, so a `ds_read` issued after a `ds_write` sees every lane's write with no `s_barrier` between them (`cs_w64x_lds_raw`), and a `ds_write` issued after a `ds_read` does not change what that read returned (`cs_w64x_lds_war`). Translated, a lane is an invocation, and the Vulkan memory model orders nothing between invocations without a barrier or an atomic, so a driver's compiler may move an invocation's load ahead of its own earlier store to another address, or merge two loads of one address. Results consistent with these optimizations were observed with AMD's Windows driver 24.30.46 (LLPC, Vulkan 1.3.302) on a Radeon 880M (RDNA3.5, native 64-wide compute subgroups): on `main` `561b65a8` both tests failed on every run with uninitialized Workgroup memory in all eight words, and in `cs_w64x_lds_war` the second read returned the same words as the first. Rule: every plain LDS `OpLoad` and `OpStore` (`lds_load`, `lds_store` and the two ADDTID forms) carries the `Volatile` memory operand, which prevents elimination, duplication or combination of the access ([SPIR-V memory operands](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Memory_Access)). This rule applies to plain accesses only. On that GPU and driver `Volatile` on the store alone or on the load alone made `cs_w64x_lds_raw` return its expected words (hand-edited SPIR-V, 3 of 3 runs each, against 0 of 4 unmodified), and with the rule both tests pass: `run_gpu_tests.py` goes from 210 to 212 of 232 passed with none failing (20 skipped), native and with `LEONIDA_W64_EMULATE=1`. An RTX 5070 Laptop (NVIDIA 621.01) gives the same results before and after (183 of 232 native, 214 emulated; `ms_wave_info_s3` fails both times). The operand changes 17 of the 238 test shaders and nothing but those loads and stores. A [full Xbox 1.0.2.1 corpus comparison](https://github.com/ItsNotRexed/Leonida/pull/6714#issuecomment-7107280378) translated and validated all 26,503 shaders at both 561b65a8 and 58deee34. Only the added operands differed in the 484 compute and 5 mesh modules that changed. The RAW and WAR results establish a workaround on the tested driver. Portable ordering between invocations requires synchronization appropriate to the accesses (see #2345). Under `--wave64-emulate` the halves meet at the round barriers as before; the operand is emitted there too. CPU-checked by `tests/semantic/test_lds_volatile.py` (every plain access form on the wave32, wave64 and emulated paths, and no other access is Volatile). |
diff --git a/docs/directstorage.md b/docs/directstorage.md
index 919d52282..1618d221f 100644
--- a/docs/directstorage.md
+++ b/docs/directstorage.md
@@ -84,6 +84,19 @@ The first boot with the executable settles most of this: the dry-run report show
84 `DSTORAGE_QUEUE_OPTIONS::AutoSubmitDisabled`). An enqueue into a full queue waits for space, as the reference 84 `DSTORAGE_QUEUE_OPTIONS::AutoSubmitDisabled`). An enqueue into a full queue waits for space, as the reference
85 says; with auto-submit disabled only a `Submit` from another thread frees it. One worker thread per queue runs 85 says; with auto-submit disabled only a `Submit` from another thread frees it. One worker thread per queue runs
86 the submitted entries in order, so every notification follows all the entries before it. 86 the submitted entries in order, so every notification follows all the entries before it.
87- **Reads into physical pages wait for `Submit`**: an automatic submit stops at the first request whose
88 destination is a physical page list; that request and every entry behind it wait for the title's own `Submit`.
89 A title may fill the page-number table such a list points into only in its submit path, so an early read finds
90 page 0 (the entry fails) or the number the slot held before (the data lands in a page that now belongs to
91 something else, with no error). A full queue submits the held entries too, since the title cannot call `Submit`
92 while it waits in an enqueue, and so does `Close`. The idea is from VIctory (`Marvisak/VIctory` `eddde73`, also
93 in `fxceless/victory-fork` `79cfdd9`); the queue here keeps its order, so entries behind a held read wait with
94 it. `LEONIDA_DSTORAGE_HOLD_PAGES=0` restores the automatic submit of everything. A hold ends after
95 `LEONIDA_DSTORAGE_HOLD_MS` milliseconds without a `Submit` (2000 unless set): the held entries are submitted with
96 their page lists as they are, as a timed release, so a path that never calls `Submit` cannot stall for good. `0`
97 is no time limit (a hold of five seconds is then logged once). The `[rt] ds-hold` line counts automatic submits,
98 reads held, full-queue and timed releases, and destination lists that named page 0 when written (`event=`, at
99 each power of two of the counter that moved).
87- **Requests**: copied at enqueue. A file request reads `SourceSize` bytes at `FileOffset` into `Destination`; a 100- **Requests**: copied at enqueue. A file request reads `SourceSize` bytes at `FileOffset` into `Destination`; a
88 memory request copies `Source` to `Destination` (`memmove`, so an overlapping pair is safe); a zlib request 101 memory request copies `Source` to `Destination` (`memmove`, so an overlapping pair is safe); a zlib request
89 inflates those `SourceSize` bytes into `Destination` (below). Checked in this order when the worker reaches the 102 inflates those `SourceSize` bytes into `Destination` (below). Checked in this order when the worker reaches the
@@ -190,7 +203,16 @@ The first boot with the executable settles most of this: the dry-run report show
190 256 blocks of a stream. It combines adjacent mips from the same layer with full-stream index anchor 203 256 blocks of a stream. It combines adjacent mips from the same layer with full-stream index anchor
191 and shared-p-bit constraints. A shared p-bit can relate low red endpoint bits even when its sibling 204 and shared-p-bit constraints. A shared p-bit can relate low red endpoint bits even when its sibling
192 mip supplies only the leading bits. These local fits preserve the recorded precision and exact reference 205 mip supplies only the leading bits. These local fits preserve the recorded precision and exact reference
193 bits. A profile can still lack endpoint values or exceed the reference consistency tolerance. Such a request reports a decompression error before publication. 206 bits. A packed tail whose larger mips are BCPack-coded too has no raw or zlib sibling, so a history field that
207 only such tails use stayed unknown: in the game runs of 2026-11-25 two BC7 tail streams of one pool failed
208 with `missing-endpoint` (alpha fields of two history entries). For the streams that still start a chain at a
209 missing field, the fitter now decodes the nearest BCPack sibling with the profile so far and fits against it,
210 repeating while a round adds fields. The sibling may sit in the same refused BC7 stream: every block whose
211 chains start elsewhere is still determined, and the undetermined ones are left out of the reference. Those
212 fields are fitted, never confirmed, and fill only what the other fits left empty. On the 1.0.2.1 package this
213 raised the BC7 endpoint fields from 4,228 to 4,406 of 6,144; the runtime decoder then refuses 8 of 5,167 BC7
214 streams instead of 60 (both failing requests decode), and the 268 BC6H streams are unchanged (10 refused; a
215 refused BC6H sibling is not used as a reference yet). A profile can still lack endpoint values or exceed the reference consistency tolerance. Such a request reports a decompression error before publication.
194- The four swizzle modes interleave stripes from request-wide component planes into 16 KiB (mode 1) or 216- The four swizzle modes interleave stripes from request-wide component planes into 16 KiB (mode 1) or
195 32 KiB (modes 2–4) groups. The enum names give the successive stripe widths. The shipped BC4 sample 217 32 KiB (modes 2–4) groups. The enum names give the successive stripe widths. The shipped BC4 sample
196 separates its endpoint planes from indices across the inflated source. The title's compute shader does 218 separates its endpoint planes from indices across the inflated source. The title's compute shader does
@@ -213,8 +235,9 @@ The first boot with the executable settles most of this: the dry-run report show
213 235
214`runtime/test/dstorage_test.cpp` (ctest `dstorage`) runs on synthetic files in `%TEMP%` through the registry entries 236`runtime/test/dstorage_test.cpp` (ctest `dstorage`) runs on synthetic files in `%TEMP%` through the registry entries
215under all three module names: `GAME:` reads with an overlay copy winning, offsets, zero size, a range past the end, 237under all three module names: `GAME:` reads with an overlay copy winning, offsets, zero size, a range past the end,
216cancellation, auto-submit, a full queue, status arrays, fences (a CPU fence object that checks the data is in place 238cancellation, auto-submit, reads into physical pages held for `Submit` (a page list changed or filled before it,
217when it is signalled), events, error records, file and queue close with requests in flight, a destination the 239a full queue, the time limit, the switch), a full queue, status arrays, fences (a CPU fence object that checks the
240data is in place when it is signalled), events, error records, file and queue close with requests in flight, a destination the
218process cannot write, four threads enqueueing at once, the interface-id policy (unknown and system ids refused by 241process cannot write, four threads enqueueing at once, the interface-id policy (unknown and system ids refused by
219`QueryInterface`, learned by creating calls), a `GetHandle` handle with its own file position, an event closed (and 242`QueryInterface`, learned by creating calls), a `GetHandle` handle with its own file position, an event closed (and
220its handle value reused) before it is set, and cancelled requests that also had an enqueue error. zlib requests use 243its handle value reused) before it is set, and cancelled requests that also had an enqueue error. zlib requests use
diff --git a/docs/gameinput.md b/docs/gameinput.md
index 1301a4a49..c18d96a05 100644
--- a/docs/gameinput.md
+++ b/docs/gameinput.md
@@ -58,7 +58,8 @@ scripted pad, driven by the script alone:
58 controller axis and controller button state. A reading is taken when the title asks for one and the script's state 58 controller axis and controller button state. A reading is taken when the title asks for one and the script's state
59 has changed since the last, so no thread polls; the history keeps the last 64 readings. 59 has changed since the last, so no thread polls; the history keeps the last 64 readings.
60- **The timeline:** the same as with SDL3 (`runtime/shims/gameinput_script.h` holds the parser, the timeline and the 60- **The timeline:** the same as with SDL3 (`runtime/shims/gameinput_script.h` holds the parser, the timeline and the
61 log lines for both): seconds from the first `GameInputCreate`, each press held 300 ms, then released. 61 log lines for both): seconds from the first `GameInputCreate`, each press held 300 ms (or its own `:hold`, see
62 `LEONIDA_INPUT_SCRIPT` below), then released.
62- **Not served:** reading callbacks, aggregate devices, rumble and every other device. Those slots answer `E_NOTIMPL` 63- **Not served:** reading callbacks, aggregate devices, rumble and every other device. Those slots answer `E_NOTIMPL`
63 and log the slot once. Controllers and the [keyboard pad](#keyboard-pad) still need SDL3. 64 and log the slot once. Controllers and the [keyboard pad](#keyboard-pad) still need SDL3.
64 65
@@ -74,6 +75,10 @@ A press is logged when the title reads it, so a press the title never reads is n
74turns the `press` lines off. Without `LEONIDA_INPUT_SCRIPT`, the shim serves no devices and answers `E_NOTIMPL` for 75turns the `press` lines off. Without `LEONIDA_INPUT_SCRIPT`, the shim serves no devices and answers `E_NOTIMPL` for
75every slot past `Release`, as before. 76every slot past `Release`, as before.
76 77
78`LEONIDA_INPUT_FILE=<path>` drives a run whose display takes no keyboard input (a headless session): every line
79appended to that file names one button of the script's table (`a`, `down`, ...) and becomes a press at once, held
80like a scripted one. The file is read again at most every 250 ms. It is for local runs only.
81
77`scripts/build_runtime.ps1` (what `make_game.py` runs) builds the shim only on its CMake path, when Visual Studio's 82`scripts/build_runtime.ps1` (what `make_game.py` runs) builds the shim only on its CMake path, when Visual Studio's
78C++ CMake tools are installed. Its direct-`cl.exe` fallback compiles a fixed file list without the shim and warns 83C++ CMake tools are installed. Its direct-`cl.exe` fallback compiles a fixed file list without the shim and warns
79about it. 84about it.
@@ -335,7 +340,7 @@ line is logged when it takes effect); tracking goes on underneath, so clearing i
335| `LEONIDA_PROMPTS_SWITCH_MS` | `300` | shortest time between two changes of the active input family, 0..2000 ms | 340| `LEONIDA_PROMPTS_SWITCH_MS` | `300` | shortest time between two changes of the active input family, 0..2000 ms |
336| `LEONIDA_GAMEINPUT_THREAD` | `1` | `0` stops the background poll thread; only `rt::gameinput::poll()` then reads the pads (tests) | 341| `LEONIDA_GAMEINPUT_THREAD` | `1` | `0` stops the background poll thread; only `rt::gameinput::poll()` then reads the pads (tests) |
337| `LEONIDA_KEYBOARD_PAD` | `off` | `1` adds the [keyboard pad](#keyboard-pad), read while this process has focus; `always` reads keys whatever has focus | 342| `LEONIDA_KEYBOARD_PAD` | `off` | `1` adds the [keyboard pad](#keyboard-pad), read while this process has focus; `always` reads keys whatever has focus |
338| `LEONIDA_INPUT_SCRIPT` | unset | Comma-separated `button@seconds` entries, e.g. `a@2,a@4,start@6`. With SDL3 they drive the keyboard pad, which has to be enabled; without SDL3 they drive [one scripted pad](#scripted-input-without-sdl3), the only device. The first pad update (without SDL3, the first `GameInputCreate`) reads the script once at startup and starts the clock. `reload_config()` does not reread it. Each press lasts 300 ms. Buttons are `a b x y start back lb rb up down left right`. Spaces around entries are allowed. Empty entries, unknown buttons and invalid times (including negative or non-finite values) are counted and ignored. | 343| `LEONIDA_INPUT_SCRIPT` | unset | Comma-separated `button@seconds` entries, e.g. `a@2,a@4,start@6`. With SDL3 they drive the keyboard pad, which has to be enabled; without SDL3 they drive [one scripted pad](#scripted-input-without-sdl3), the only device. The first pad update (without SDL3, the first `GameInputCreate`) reads the script once at startup and starts the clock. `reload_config()` does not reread it. Each press lasts 300 ms, or `hold` seconds when the entry is `button@seconds:hold` (more than 0, at most 600). With SDL3 a press then stays down until the title has read the pads six times since it began, but never past 5 s from its start (or its hold, if longer). A title reads its pad once a frame, so at a few seconds a frame a 300 ms press can fall between two reads and never arrive: on the retail title's "Couldn't autosave" prompt, three 300 ms `b` presses did nothing, while 120 presses 0.5 s apart got through; one `b@1100:3` replaces them. Buttons are `a b x y start back lb rb up down left right`. Spaces around entries are allowed. Empty entries, unknown buttons, invalid times (including negative or non-finite values) and invalid holds (0 or less, more than 600, not a number) are counted and ignored. |
339| `LEONIDA_MOUSE_SENSITIVITY` | `1` | scales how far the mouse moves the keyboard pad's right stick, 0.1..10 | 344| `LEONIDA_MOUSE_SENSITIVITY` | `1` | scales how far the mouse moves the keyboard pad's right stick, 0.1..10 |
340 345
341SDL's own hints (`SDL_JOYSTICK_*`, see SDL's `SDL_hints.h`) also apply, for example `SDL_JOYSTICK_HIDAPI_PS5=0` to 346SDL's own hints (`SDL_JOYSTICK_*`, see SDL's `SDL_hints.h`) also apply, for example `SDL_JOYSTICK_HIDAPI_PS5=0` to
diff --git a/docs/linux_proton.md b/docs/linux_proton.md
index de4760d70..b981c2ef2 100644
--- a/docs/linux_proton.md
+++ b/docs/linux_proton.md
@@ -150,6 +150,10 @@ Each item was a stop on at least one of the machines. Tests named in the pull re
150 150
151## Where it stops 151## Where it stops
152 152
153- **Writes into title memory.** A window is a read-side copy, so a UAV or raw write used to stop at the copy: the
154 missing return copy is the `WRITE_INVALID` device loss of #1537. The layer now copies the reached ranges back to
155 the title's pages at the next refresh, before the forward copy, and the title's own newer words win. Not yet
156 measured on a GPU with the world phase in front of it.
153- **Streamed memory that reaches its destination late or not at all.** The title calls queue slot 31 157- **Streamed memory that reaches its destination late or not at all.** The title calls queue slot 31
154 (`CopyPageMappingsBatchX`) about 300 times per boot. With #968 this branch maps each batch's pool pages at the 158 (`CopyPageMappingsBatchX`) about 300 times per boot. With #968 this branch maps each batch's pool pages at the
155 destination and at the paired CPU view the layer reads (`docs/d3d12_vulkan.md`, section 4.9), so most streamed 159 destination and at the paired CPU view the layer reads (`docs/d3d12_vulkan.md`, section 4.9), so most streamed
@@ -166,6 +170,63 @@ Each item was a stop on at least one of the machines. Tests named in the pull re
166- **Under Wine** a thread that takes an access violation while holding the process heap lock can still deadlock 170- **Under Wine** a thread that takes an access violation while holding the process heap lock can still deadlock
167 with xmem's fault handler; the test for it is skipped there. 171 with xmem's fault handler; the test for it is skipped there.
168 172
173## AMD on Linux: what got the world drawn
174
175On 2026-11-26 a Linux machine with an RX 7900 XTX (and a Ryzen 9 7950X3D's RDNA2 iGPU), Mesa 26.3.1 (RADV) and Wine
176drew the first world frames: the opening night street and a sunset street with palms, cars and a character, over
177eight minutes in the world without a GPU hang, at about one frame per six seconds. The runtime was `main` `a73a57e13`
178with #1914, #1957, #1972, #2044, #2097, #2124, #2129, #2144, #2162, #2195 and #2240 merged; they went into `main`
179together with this section. Each step below removed a stop that ended every earlier run; they are in the order
180they were found.
181
1821. **Raise amdgpu's GPU timeout.** `modinfo amdgpu -p` shows `lockup_timeout` with a default of 2000 ms: the kernel
183 resets any ring whose job runs over 2 s. World frames take seconds, so a run ended about 30 s into the world with
184 `ring gfx_0.0.0 timeout` in `journalctl -k`, no page fault, and a black last frame. Raise it as root and reboot:
185 `amdgpu.lockup_timeout=30000,60000,10000,10000` on the kernel command line (graphics, compute, SDMA, video, in
186 ms), or `options amdgpu lockup_timeout=30000,60000,10000,10000` in a file under `/etc/modprobe.d/` followed by an
187 initramfs rebuild. A real hang then freezes that ring, and a desktop on the same GPU, for up to that long, so don't
188 make it unlimited. Windows reporters raise `TdrDelay` for the same reason.
1892. **Native wave64 shaders.** On a GPU that runs wave64 natively (AMD RDNA), translate with
190 `make_game.py --stages shaders --wave64-emulate off`. Before `max_subgroup_decider` (`make_game.py`), the auto
191 mode took the smallest `maxSubgroupSize` over every Vulkan device, so an installed llvmpipe (8) turned emulation on for all
192 23,841 wave64 shaders. Emulated single-wave compute programs were then translated in the round-loop form, which
193 hung the GPU on several library programs and drove RADV's compiler past 12 GiB (53 GB uncapped) on the largest; the
194 translator no longer does that for single-wave programs ([design.md](design.md), row "Wave64 emulation:
195 single-wave barrier fallback").
196 The auto mode now leaves CPU devices out when a GPU is listed and names the device that decided.
1973. **Fill the pipeline journal with the runtime itself.** `gta6rt --precompile-pipelines --threads 16`, under Wine,
198 with the environment of the game run (`LEONIDA_SHADERS`, `LEONIDA_PIPELINE_CACHE_DIR`, `LEONIDA_DEVICE_FAULT`;
199 `--precompile-pipelines` in [d3d12_vulkan.md](d3d12_vulkan.md)). It built 3,693 compute pipelines; the next boot took
200 1,900 of them from the journal in 0.1 s of driver time, and the menus ran at 30 frames/s instead of under one.
201 The `pipeline_cache.bin` that `make_game.py`'s pipelines stage writes with `vk_pipeline_check` gave no hits: 0 of
202 5,526 journal pipeline keys were in its 29,861 objects (9 shader binaries were identical, so the machine code
203 matched and the keys did not). Each of three differences is enough for a miss on RADV:
204 - **The set of shaders:** the runtime's warm-up builds the library's compute programs (`library/index.json`,
205 2,683 modules); the stage builds the main index and `bvh/`, and only 25 library modules are byte-identical to a
206 main-index one.
207 - **Robustness:** on RADV the runtime enables `robustBufferAccess`, `robustBufferAccess2` and `nullDescriptor`;
208 `vk_pipeline_check` turns `robustBufferAccess` off and leaves robustness2 off. RADV puts the robustness state into
209 every shader stage key, so every pipeline, compute and graphics, misses.
210 - **Layout and subgroup request:** for compute with set-0 bindings (2,244 of the 2,683) the checker builds set 0
211 from default bindless features and requests the subgroup size without the runtime's full-subgroups flag; RADV
212 hashes the whole set layout and the stage flags. Graphics would miss anyway: the checker pairs each stage with a
213 stub and fixed state, and RADV hashes the full graphics state.
2144. **Leave out the ray-tracing programs.** 724 library compute programs have 2 MiB of SPIR-V or more (676 of them
215 ray-tracing resolve) and take 89-167 s each in the driver. `LEONIDA_RT_AS=off` drops acceleration-structure builds
216 and copies, and `LEONIDA_SKIP_COMPUTE=<name>,<name>,...` with those programs' `lib_cs_NNNNN` names (picked by
217 module size from `library/index.json`) never builds or dispatches them. The picture then lacks whatever those
218 passes draw.
2195. **Keep the title's hang watchdog kicked.** The title exits on purpose (a write to address 0) when its main loop has
220 not reported for 30 s, which a world load under the runtime exceeds. `LEONIDA_TITLE_WATCHDOG=0` defuses it only
221 together with `LEONIDA_TITLE_WATCHDOG_KICK=<trap RVA>,<kick RVA>` (hex; `runtime/src/main.cpp`); the two values are
222 measured locally and never committed. With `=0` alone the loader logs that the watchdog stays armed.
223
224The rest of that run's environment came from a Linux/Proton report on an RTX 3090: `LEONIDA_ASYNC_PIPELINES=0`,
225`LEONIDA_DEVICE_TYPE=6`, `LEONIDA_MAP_READBACK=1`, `LEONIDA_TITLE_WINDOWS_MB=4096`, `LEONIDA_FRAME_PACING=1` and
226`LEONIDA_PRESENT_NO_TEAR=1`. Still wrong after it: frames alternate between white-out, a correct picture and black;
227some geometry is drawn in the wrong place; VRAM reached 18.3 of 22.3 GB; the run ended on a breakpoint in the title
228after 12 minutes.
229
169## Reporting a result 230## Reporting a result
170 231
171Say the machine (OS, GPU and driver, RAM), the commit, the environment switches that differ from the defaults, and 232Say the machine (OS, GPU and driver, RAM), the commit, the environment switches that differ from the defaults, and
diff --git a/docs/running.md b/docs/running.md
new file mode 100644
index 000000000..3b7e61f64
--- /dev/null
+++ b/docs/running.md
@@ -0,0 +1,142 @@
1# Running the game, per platform and GPU
2
3How the retail game has been run on each platform and GPU so far: the build, the shader pack, the pipeline
4pre-compile, the driver and OS settings, the environment and what to expect. Every value is marked:
5
6- **measured by us**: by the maintainers who wrote this page, on the machine named in that section;
7- **reported by others**: from a public issue or comment, linked; not checked by us;
8- **TBD**: nobody has reported it yet. A report fills it in ([Reporting](#reporting)).
9
10Paths are placeholders: `<checkout>` is the repository, `<build>` the folder with `gta6rt.exe` and
11`gta6rt_tls_host.dll`, `<work>` the work folder `make_game.py` writes, `<cache>` a folder for pipeline caches,
12`<package>` the game's package folder and `<exe>` its executable. Under Wine, a Linux path is passed as `Z:<path>`.
13
14## Settings every platform needs
15
16- **The title's hang watchdog.** The title exits on purpose (a write to address 0) when its main loop has not reported
17 for 30 s, which a world load under the runtime exceeds. `LEONIDA_TITLE_WATCHDOG=0` keeps it from firing only together
18 with `LEONIDA_TITLE_WATCHDOG_KICK=<trap RVA>,<kick RVA>` (hex), two addresses in the executable that each person
19 measures in their own copy (`runtime/src/main.cpp` describes the trap instruction the first must point at). The
20 values are never committed. With `=0` alone the loader logs that the watchdog stays armed. (Measured by us; the
21 watchdog was identified in [#2019](https://github.com/ubiquitarianism/leonida/issues/2019#issuecomment-7172996360).)
22- **The GPU timeout.** World frames take seconds each. The OS's GPU timeout must be longer, or the driver resets the
23 GPU: amdgpu's `lockup_timeout` on Linux, `TdrDelay` on Windows (sections below).
24- **Large ray-tracing programs.** 724 library compute programs have 2 MiB of SPIR-V or more (676 of them ray-tracing
25 resolve) and take 89-167 s each in the driver ([reported by others](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7184700506);
26 the count of 724 also measured by us). `LEONIDA_RT_AS=off` drops acceleration-structure builds and
27 `LEONIDA_SKIP_COMPUTE=<name>,<name>,...` with those programs' names (picked by module size from
28 `<work>/shaders/spirv/library/index.json`) never builds or dispatches them. The picture then lacks what they draw.
29
30## Linux, Wine, AMD RX 7900 XTX (RADV)
31
32Measured by us on 2026-11-26: RX 7900 XTX, Ryzen 9 7950X3D, Linux 7.3, Mesa 26.3.1 (RADV), Wine. Details and the
33reasons behind each step: [linux_proton.md](linux_proton.md#amd-on-linux-what-got-the-world-drawn).
34
35- **Build:** the clang-cl + xwin cross-build ([testing.md](testing.md#the-windows-runtime-on-linux-under-wine-or-proton)),
36 with SDL3 for the keyboard pad.
37- **Shaders:** `python -I make_game.py --stages shaders --wave64-emulate off --work <work> --out <out>`. The GPU runs
38 wave64 natively; emulation is not needed. (`auto` picks the same here since llvmpipe no longer decides.)
39- **Pipeline pre-compile:** `wine <build>/gta6rt.exe --precompile-pipelines --threads 16` with the run's
40 `LEONIDA_SHADERS`, `LEONIDA_PIPELINE_CACHE_DIR` and `LEONIDA_DEVICE_FAULT`, before the first run. It built 3,693
41 compute pipelines. Not `make_game.py --stages pipelines`: its cache never matches the runtime's driver keys.
42- **Driver and OS:** `amdgpu.lockup_timeout=30000,60000,10000,10000` on the kernel command line (the default is
43 2000 ms; reboot needed).
44- **Environment:**
45
46 | Setting | Why |
47 |---|---|
48 | `LEONIDA_D3D12=vulkan` | the Vulkan backend |
49 | `LEONIDA_SHADERS=Z:<work>/shaders/spirv` | the native pack |
50 | `LEONIDA_PIPELINE_CACHE_DIR=Z:<cache>/pso` | the journal the pre-compile filled |
51 | `MESA_SHADER_CACHE_DIR=<cache>/mesa`, `MESA_SHADER_CACHE_MAX_SIZE=16G` | RADV's own cache, large enough for the pack |
52 | `LEONIDA_STARTUP_CACHE_CHECKPOINTS=1` | session cache snapshots during the boot |
53 | `LEONIDA_ASYNC_PIPELINES=0` | draws wait for their pipeline instead of being skipped |
54 | `LEONIDA_SERIAL_BIG_COMPILES=0`, `LEONIDA_COMPUTE_WARMUP_MAX_BYTES=8388608` | warm-up limits, as in the NVIDIA report below |
55 | `LEONIDA_RT_AS=off`, `LEONIDA_SKIP_COMPUTE=<list>` | the large ray-tracing programs ([above](#settings-every-platform-needs)) |
56 | `LEONIDA_TITLE_WATCHDOG=0`, `LEONIDA_TITLE_WATCHDOG_KICK=<trap RVA>,<kick RVA>` | the title's hang watchdog ([above](#settings-every-platform-needs)) |
57 | `LEONIDA_DEVICE_TYPE=6`, `LEONIDA_MAP_READBACK=1`, `LEONIDA_FRAME_PACING=1`, `LEONIDA_PRESENT_NO_TEAR=1` | taken over from the NVIDIA report below; their effect on AMD was not measured one by one |
58 | `LEONIDA_ARENA_MB=4095`, `LEONIDA_TITLE_WINDOWS_MB=4096`, `LEONIDA_GEOMETRY_MB=6144` | room for the title's buffers in the world |
59 | `LEONIDA_CONSOLE_RELEASE_FILTER=1`, `LEONIDA_SHADOW_ALIAS_MS=5000`, `LEONIDA_CONSOLE_FIX_US=0` | carried from earlier boot runs; their effect here was not measured one by one |
60 | `LEONIDA_DEVICE_FAULT=1` | a device-loss report if the GPU hangs |
61 | `LEONIDA_KEYBOARD_PAD=always` | the keyboard as the pad |
62
63- **Command:** from `<package>`, `wine <build>/gta6rt.exe --run Z:<exe> --game-dir Z:<package>`.
64- **What to expect:** menus at 30 frames/s with no in-game compiling; the world after the story load, over eight
65 minutes without a GPU hang, at about one frame per six seconds.
66- **Known problems:** frames alternate between white-out, a correct picture and black; some geometry is drawn in the
67 wrong place; VRAM reached 18.3 of 22.3 GB; the run ended on a breakpoint (`int3`) in the title after 12 minutes.
68
69## Linux, Wine, AMD RDNA2 iGPU (Ryzen 7000, RADV)
70
71Measured by us on 2026-11-25/26, the same machine's integrated GPU (gfx1036), headless, before the watchdog's KICK
72was known. The settings that drew the world on the RX 7900 XTX have not been tried here: TBD.
73
74- **Build, shaders, pipeline pre-compile:** as for the RX 7900 XTX; the iGPU also runs wave64 natively.
75- **Driver and OS:** the same `lockup_timeout` applies (TBD whether the values above are enough here).
76- **Environment:** select the iGPU with `MESA_VK_DEVICE_SELECT=1002:164e` and
77 `MESA_VK_DEVICE_SELECT_FORCE_DEFAULT_DEVICE=1`. A cold compute warm-up made the title crawl at 0.12 frames/s behind
78 our own warm-ups; `LEONIDA_COMPUTE_WARMUP_LIVE_MAX_BYTES=131072` holds large warm-ups back while the title submits
79 (191 frames/s in the menus with it, measured on the RX 7900 XTX).
80- **What to expect:** the boot, the first-run pages and the story load's loading screen (about 1,100 s into a run with
81 a partly warm cache). Every run then ended in the title's watchdog exit, about two minutes into the world load,
82 because only `LEONIDA_TITLE_WATCHDOG=0` was set. World frames: TBD.
83- **Known problems:** TBD beyond the above.
84
85## Linux, Proton, NVIDIA
86
87Reported by others: [#1608, comment 7184700506](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7184700506)
88(RTX 3090 24 GB, NVIDIA 590.48.01, GE-Proton11-14, Debian 13). Not run by us.
89
90- **Build:** clang-cl + xwin cross-build; `main` plus several pull requests and two local changes (listed in the report).
91- **Shaders:** the main corpus, the library and FSPX with llvm-mc 23.1.6. Wave64 emulation: TBD from the report (it is
92 needed on NVIDIA's 32-wide subgroups; `auto` turns it on there).
93- **Pipeline pre-compile:** caches warm from two earlier runs; no separate pre-compile is reported.
94- **Driver and OS:** TBD.
95- **Environment:** `LEONIDA_ASYNC_PIPELINES=0`, `LEONIDA_RT_AS=off`, `LEONIDA_SKIP_COMPUTE=<the 724 programs>`,
96 `LEONIDA_DEVICE_TYPE=6`, `LEONIDA_TITLE_WATCHDOG=0`, `LEONIDA_MAP_READBACK=1`, `LEONIDA_HOST_IMAGE_COPY=0`,
97 `LEONIDA_ARENA_MB=4095`, `LEONIDA_TITLE_WINDOWS_MB=4096`, `LEONIDA_SERIAL_BIG_COMPILES=0`, `LEONIDA_FRAME_PACING=1`,
98 `LEONIDA_PRESENT_NO_TEAR=1`. The report gives the reason for the skip list only: without it the world start waits
99 hours on the ray-tracing programs; with asynchronous pipelines instead the screen stayed black.
100- **Command:** TBD.
101- **What to expect:** the opening night street from about 650 s, at 0.1-0.2 frames/s, no device loss through 934 s.
102 The black stretch before it is graphics pipelines of 1-2.6 MB SPIR-V compiling one at a time, 5-10 s each.
103- **Known problems:** nothing ray-traced is in the picture.
104
105## Windows, NVIDIA
106
107Reported by others: [#2019](https://github.com/ubiquitarianism/leonida/issues/2019) (RTX 5090 32 GB, driver 616.92,
108Windows 11). Not run by us.
109
110- **Build:** `scripts/build_runtime.ps1` with SDL3, RelWithDebInfo.
111- **Shaders:** `make_game.py --stages check,shaders,runtime` (26,503 shaders translated); wave64 emulation as `auto`
112 decides (on for NVIDIA).
113- **Pipeline pre-compile:** TBD.
114- **Driver and OS:** `TdrDelay` and `TdrDdiDelay` raised to 60 s, after which an 8.9 s pipeline build no longer
115 reset the device.
116- **Environment:** `LEONIDA_D3D12=vulkan`, `LEONIDA_KEYBOARD_PAD=always`; the rest TBD.
117- **Command:** `gta6rt.exe --first-run-ui game_scarlett_master.exe` from the package folder.
118- **What to expect:** the first-run UI, then the title's watchdog exit at 145-204 s. With `LEONIDA_TITLE_WATCHDOG=0`
119 (before the KICK variable existed) the boot went on at about 24 frames/s and the machine then bugchecked
120 (`CRITICAL_PROCESS_DIED`) before a world frame. With the KICK values: TBD.
121- **Known problems:** TBD.
122
123## Windows, AMD
124
125TBD: no public report of a game run on Windows with an AMD GPU is known to us. What the code does: on RDNA1 and RDNA2
126under AMD's Windows driver, `make_game.py`'s `auto` translates native wave64, because that driver crashes on many
127emulated wave64 compute pipelines (#857). `TdrDelay` applies as for NVIDIA.
128
129## Intel
130
131TBD.
132
133## macOS (MoltenVK)
134
135TBD.
136
137## Reporting
138
139Post a run in the coordination issue, with the fields of these sections: machine (OS, GPU, driver, RAM), the commit,
140how the shaders were made, the pipeline pre-compile, the OS and driver settings, every `LEONIDA_*` variable that
141differs from the defaults (never the watchdog's RVA values), and how far the run got with its frame rate. Keep logs,
142traces and screenshots on your machine ([linux_proton.md](linux_proton.md#reporting-a-result)).
diff --git a/docs/runtime_imports.md b/docs/runtime_imports.md
index e38dfbf74..e408d223d 100644
--- a/docs/runtime_imports.md
+++ b/docs/runtime_imports.md
@@ -170,7 +170,7 @@ policy "other" (none is counted as returning an `HRESULT`), and they come from s
170| `xg_xs.dll` | 2: `XGCreateTextureComputer`, `XGSuggestSwizzleMode` | texture layout computation | 170| `xg_xs.dll` | 2: `XGCreateTextureComputer`, `XGSuggestSwizzleMode` | texture layout computation |
171| `XCRDAPI.dll` | 1: `DStorageGetFactory` | DirectStorage | 171| `XCRDAPI.dll` | 1: `DStorageGetFactory` | DirectStorage |
172| `chad.dll` | 5: `XDspActivate`, `XDspConnectWithMaximumStreamLimit`, `XDspDeactivate`, `XDspDisconnect`, `XDspSubmitCommand` | the audio DSP | 172| `chad.dll` | 5: `XDspActivate`, `XDspConnectWithMaximumStreamLimit`, `XDspDeactivate`, `XDspDisconnect`, `XDspSubmitCommand` | the audio DSP |
173| `xapu.dll` | 5: `XApuConnect`, `XApuDequeueResult`, `XApuDisconnect`, `XApuEnqueueCommand`, `XApuGetResultCount` | the audio processing unit | 173| `xapu.dll` | 5: `XApuConnect`, `XApuDequeueResult`, `XApuDisconnect`, `XApuEnqueueCommand`, `XApuGetResultCount` | the audio processing unit (Opus decode when `runtime/opus_decoder` is built) |
174| `AcpHal.dll` | 9: `AcpHalAllocateShapeContexts`, `AcpHalCreate`, `AcpHalReleaseShapeContexts`, `ApuAlloc`, `ApuCreateHeap`, `ApuFree`, `ApuIsVirtualAddressValid`, `ApuMapApuAddress`, `ApuMapVirtualAddress` | the audio hardware layer | 174| `AcpHal.dll` | 9: `AcpHalAllocateShapeContexts`, `AcpHalCreate`, `AcpHalReleaseShapeContexts`, `ApuAlloc`, `ApuCreateHeap`, `ApuFree`, `ApuIsVirtualAddressValid`, `ApuMapApuAddress`, `ApuMapVirtualAddress` | the audio hardware layer |
175 175
176The game executable imports two functions from `xg_xs.dll`, the console's texture layout library: 176The game executable imports two functions from `xg_xs.dll`, the console's texture layout library:
@@ -203,17 +203,19 @@ again at detach (reason 0), and there is no `exception`, `error` or `unimplement
203unimplemented imports is reached by the TLS callbacks or the `DllMain`s. 203unimplemented imports is reached by the TLS callbacks or the `DllMain`s.
204 204
205The executable's audio imports `xapu.dll` (`XApuConnect`, `XApuDequeueResult`, `XApuDisconnect`, 205The executable's audio imports `xapu.dll` (`XApuConnect`, `XApuDequeueResult`, `XApuDisconnect`,
206`XApuEnqueueCommand`, `XApuGetResultCount`) and `chad.dll` (`XDspActivate`, `XDspConnectWithMaximumStreamLimit`, 206`XApuEnqueueCommand`, `XApuGetResultCount`) are served by `runtime/shims/xapu_queue.cpp`; `chad.dll`
207`XDspDeactivate`, `XDspDisconnect`, `XDspSubmitCommand`) are served by `runtime/shims/xapu_chad.cpp`. The shapes were 207(`XDspActivate`, `XDspConnectWithMaximumStreamLimit`, `XDspDeactivate`, `XDspDisconnect`, `XDspSubmitCommand`) by
208read statically from the executable's call sites: one each, four for `XApuEnqueueCommand`. Both connects succeed with 208`runtime/shims/xapu_chad.cpp`. The shapes were read statically from the executable's call sites: one each, four for
209a handle; the APU connect also returns a zeroed shared buffer the title writes stream input to and reads output from. 209`XApuEnqueueCommand`. `XApuConnect` reads the title's 24-byte `ConnectInput` (process 1 = Opus at 48 kHz, stream
210Commands are accepted and not processed, so the audio stays silent. A stream open (type 1) and a stream close 210count, commands per stream, a shared buffer, options) and returns `{shared buffer, result event}`; it never writes the
211(type 2) each queue one result of the same type and slot, because the title frees a stream id only when the close 211input. Activate, process, deactivate and reset commands are copied from the title's stack command, and each queues one
212result arrives. `XDspActivate` writes its two outputs as pointers to zeroed memory, which the title reads as "command 212result in order. A process command decodes its Opus packet through `runtime/opus_decoder` (Rust over the BSD-3-Clause
213done" after each `XDspSubmitCommand`. `XApuConnect` leaves its first argument, a global of the title, untouched. The 213`opus-pure`) into the slot's output, honouring first frame, frame count, output length and the deinterleaved option;
214buffer size (128 stream slots), the two results and the zeroed DSP status are hypotheses, explained in the file. 214without the crate the result carries the table-of-contents frame count and silence. The layouts follow Marvisak/VIctory
215`xapu_chad_test` calls all ten in those shapes. With `--trace`, the first call of each, and the first command of each type, is an 215`crates/victory-hle/src/modules/apu.rs` (GPL-3.0-or-later). `XDspActivate` writes its two outputs as pointers to zeroed
216`audio_queue` event. 216memory, which the title reads as "command done" after each `XDspSubmitCommand`; the DSP stays silent. `xapu_chad_test`
217covers the layouts, the queue and the silent path; `xapu_opus_test` the decoded path. With `--trace`, the first call of
218each, and the first command of each type, is an `audio_queue` event.
217The table above was measured before this shim and still lists these ten as unimplemented; they are served now. The call shapes agree with `docs/audio_hal_exe_calls.md`, which was measured with `tools/import_call_sites.py`. 219The table above was measured before this shim and still lists these ten as unimplemented; they are served now. The call shapes agree with `docs/audio_hal_exe_calls.md`, which was measured with `tools/import_call_sites.py`.
218 220
219What this does not show: `--run` has not been run, so the entry point has not been called and no import is known to be 221What this does not show: `--run` has not been run, so the entry point has not been called and no import is known to be