diff options
| author | Claude <noreply@anthropic.com> | 2026-11-26 18:59:07 +0000 |
|---|---|---|
| committer | Claude <noreply@anthropic.com> | 2026-11-26 18:59:07 +0000 |
| commit | 7ffcb8e260d3cedfb0077d924b0be189293c5a2c (patch) | |
| tree | 59285b61ba869fc779ea5586cc0337b292040e6e /docs | |
| parent | 99f913a2883b6416385790dd3861b3890e142cb0 (diff) | |
| parent | f107ae044637ed7b337c96b6aa574c5a96c5da22 (diff) | |
Merge upstream/main into input-out-of-the-box
docs/gameinput.md conflicted on two passages, both kept:
- main's new LEONIDA_INPUT_FILE paragraph, with this branch's sentence on
make_game.py running build_runtime.ps1 with -FetchSdl3 (and --no-sdl3)
added to main's wording of the build paragraph;
- the settings table keeps this branch's LEONIDA_KEYBOARD_PAD default (1,
focused; off removes it), which gameinput.cpp reads, and takes main's longer
LEONIDA_INPUT_SCRIPT row (button@seconds:hold, the six-reads rule), saying
"on unless LEONIDA_KEYBOARD_PAD=off" for the keyboard pad.
No code conflicted. Tested: full ctest, 113 of 113, on Linux (the portable
subset; the gameinput shim is Windows-only).
Changes made by Claude Code (AI-assisted).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JPqXc6svM4pbBagTsVEYA3
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/README.md | 1 | ||||
| -rw-r--r-- | docs/audio_hal_exe_calls.md | 20 | ||||
| -rw-r--r-- | docs/bvh.md | 5 | ||||
| -rw-r--r-- | docs/d3d12_vulkan.md | 253 | ||||
| -rw-r--r-- | docs/design.md | 4 | ||||
| -rw-r--r-- | docs/directstorage.md | 29 | ||||
| -rw-r--r-- | docs/gameinput.md | 30 | ||||
| -rw-r--r-- | docs/linux_proton.md | 70 | ||||
| -rw-r--r-- | docs/running.md | 158 | ||||
| -rw-r--r-- | docs/runtime_imports.md | 26 |
10 files changed, 563 insertions, 33 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 |
| 53 | with a result queue, connected once and torn down once. How `chad.dll`'s handle relates to it is not read. | 53 | with 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. | ||
| 57 | The `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`), | ||
| 59 | which 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 | |||
| 69 | What the results carry is the shim's own: each accepted command gets one result in command order, with the error codes | ||
| 70 | of the layout. A process result carries the frame count and PCM when `runtime/opus_decoder` is built, and otherwise the | ||
| 71 | frame 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 | ||
| 73 | packet. | ||
| 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/bvh.md b/docs/bvh.md index ee4316672..a32b55f9e 100644 --- a/docs/bvh.md +++ b/docs/bvh.md | |||
| @@ -1125,7 +1125,10 @@ elements, so with N elements there are at most (3N - 2) / 4 nodes. `XdxrLayout` | |||
| 1125 | sizes for that many when the build is recorded, and the same numbers answer | 1125 | sizes for that many when the build is recorded, and the same numbers answer |
| 1126 | `GetRaytracingAccelerationStructurePrebuildInfo`. The header's `totalSizeIn64BNodes` counts only the nodes the build | 1126 | `GetRaytracingAccelerationStructurePrebuildInfo`. The header's `totalSizeIn64BNodes` counts only the nodes the build |
| 1127 | wrote. | 1127 | wrote. |
| 1128 | A triangle with a NaN vertex gets an empty box (D3D12 treats it as inactive). So do an instance with mask 0, one with | 1128 | A triangle with a NaN vertex gets an empty box (D3D12 treats it as inactive). So does a triangle with a vertex |
| 1129 | index at or past the geometry's `VertexCount` (every triangle when it is 0): the builder reads no vertex for it, as | ||
| 1130 | the index would address past the vertex buffer, possibly by gigabytes (`vk_xdxr_build_test` case | ||
| 1131 | `blas_vertex_count`). So do an instance with mask 0, one with | ||
| 1129 | no BLAS and one with a singular transform. An instance record holds its BLAS address in 256-byte units in 32 bits, | 1132 | no BLAS and one with a singular transform. An instance record holds its BLAS address in 256-byte units in 32 bits, |
| 1130 | so BLAS addresses must be below 2^40, as console GPU addresses are. Where device addresses are wider (llvmpipe's are | 1133 | so BLAS addresses must be below 2^40, as console GPU addresses are. Where device addresses are wider (llvmpipe's are |
| 1131 | host pointers), the builder takes a bias that is added to the addresses read from instance descs. | 1134 | host pointers), the builder takes a bias that is added to the addresses read from instance descs. |
diff --git a/docs/d3d12_vulkan.md b/docs/d3d12_vulkan.md index 43886af30..e5efa6ed0 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,19 @@ 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. A remap of | ||
| 1741 | physical pages retires nothing: the copies follow the new pages through the refresh. A retired | ||
| 1742 | view leaves the lookups at once, its alias ranges and translated heap slots are invalidated, its stream-pool | ||
| 1743 | extent is forgotten, and its memory is freed only after every ExecuteCommandLists replay in progress at the | ||
| 1744 | retirement has recorded its submissions and those have completed (`kAfterExecutes`). Before it leaves the | ||
| 1745 | refresh it is copied once more from its pages if they are still readable (a heap block freed in memory that | ||
| 1746 | stays committed). The next view of the range makes a new copy. | ||
| 1747 | `geometry_views_test` cases 14-16 cover this without a GPU. | ||
| 1722 | - **Which pages changed** since the last refresh: where xmem reserved the title's memory with `MEM_WRITE_WATCH` | 1748 | - **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 | 1749 | (`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: | 1750 | physical-page windows), the kernel says (`GetWriteWatch` with reset, its answers kept for every copy over the page: |
| @@ -1730,6 +1756,15 @@ The copies: | |||
| 1730 | write-fault handler waits for the trackers' locks while the faulting thread may hold the process heap's lock (the | 1756 | write-fault handler waits for the trackers' locks while the faulting thread may hold the process heap's lock (the |
| 1731 | title's `XMemAlloc` blocks are `_aligned_malloc`'s), so the state changed under those locks allocates from a heap of | 1757 | title's `XMemAlloc` blocks are `_aligned_malloc`'s), so the state changed under those locks allocates from a heap of |
| 1732 | the runtime's own (`leonida::host_heap`), never the process heap. | 1758 | the runtime's own (`leonida::host_heap`), never the process heap. |
| 1759 | - **What the GPU wrote into a copy stays** until the title changes the bytes under it. Some pages are copied at | ||
| 1760 | every refresh without a sign that the title wrote them (mapped at two addresses, left writable, reopened with the | ||
| 1761 | 64 KiB around a written page, write-watched or pinned); copied whole, they overwrote a value a compute program had | ||
| 1762 | stored in the copy for the next frame with the title's unchanged bytes, so it read back as the title's old value | ||
| 1763 | every other frame. `ShadowPages` keeps a 64-bit sum per 256-byte piece of the bytes it copied last | ||
| 1764 | (`runtime/src/shadow_keep.h`) and copies a piece only when the title's bytes differ; a piece zeroed because its page | ||
| 1765 | went away is copied again in full once it comes back. Limit: a title that writes the same bytes again to reset a | ||
| 1766 | value the GPU changed is not seen (that needs the GPU's writes to reach the title's pages). `LEONIDA_SHADOW_KEEP=0` | ||
| 1767 | copies every page as before. | ||
| 1733 | - **Only the title's memory** gets a copy: the blocks and ranges the xmem shims hand the title (`XMemAlloc`, | 1768 | - **Only the title's memory** gets a copy: the blocks and ranges the xmem shims hand the title (`XMemAlloc`, |
| 1734 | `XMemAllocDefault`, `XMemVirtualAlloc`, the title's `VirtualAlloc`). An address anywhere else, the runtime's or a | 1769 | `XMemAllocDefault`, `XMemVirtualAlloc`, the title's `VirtualAlloc`). An address anywhere else, the runtime's or a |
| 1735 | host DLL's memory included, is left as it was and counted, as is an arena VA or a buffer the layer made. | 1770 | host DLL's memory included, is left as it was and counted, as is an arena VA or a buffer the layer made. |
| @@ -1805,6 +1840,178 @@ fit on smaller PC GPUs. This is a product requirement, not something the layer c | |||
| 1805 | compatible single-mip RGBA8 2D textures (section 4.2). Other descriptions have fully allocated backing. Wider | 1840 | compatible single-mip RGBA8 2D textures (section 4.2). Other descriptions have fully allocated backing. Wider |
| 1806 | texture coverage and the game's use of tile streaming remain open. | 1841 | texture coverage and the game's use of tile streaming remain open. |
| 1807 | 1842 | ||
| 1843 | **Diagnostics for descriptors the title builds itself** (all off by default, logging only unless said otherwise): | ||
| 1844 | |||
| 1845 | - `LEONIDA_UNKNOWN_TSHARP=1`: one line for each distinct base address a title-written T# names with no texture there | ||
| 1846 | (its shape, the tiling bits and whether the address is title memory), up to 300 addresses, and every 8192 such | ||
| 1847 | lookups a summary by format, type and tiling. | ||
| 1848 | - `LEONIDA_UNBACKED_VSHARP=1`: the buffer V#s `fix_vsharp` writes empty because nothing backs their base; one line for | ||
| 1849 | each of the first 120 distinct bases and every 8192 a summary by 4 GiB range of the base. | ||
| 1850 | - `LEONIDA_UPLOAD_LOG=1` (`d3d12_xs_device.cpp`): each upload chunk (CPU base, device address, size) and the first 96, | ||
| 1851 | then every 8192nd, `AllocateUploadMemory` result as an offset into its chunk. | ||
| 1852 | - `LEONIDA_UPLOAD_ALIAS=1` (an experiment, changes behaviour): enters each upload chunk's CPU range in the title VA | ||
| 1853 | table, so a V# the title wrote with the CPU pointer `AllocateUploadMemory` handed it is rewritten to the chunk | ||
| 1854 | instead of left empty. A chunk below the arena needs `LEONIDA_IMPORT_BELOW_ARENA=1` as well. | ||
| 1855 | |||
| 1856 | #### Address guard (`LEONIDA_ADDRESS_GUARD=1`, `rdna2spirv.py --address-guard`) | ||
| 1857 | |||
| 1858 | **Prototype, off by default.** | ||
| 1859 | |||
| 1860 | **Why.** The layer rewrites the addresses it can see: root views, the V#s it writes, and the V#s the title writes into | ||
| 1861 | shader-visible heaps. It writes an empty V# when nothing backs an address (above). The translator checks a V#'s | ||
| 1862 | record count but not its base. Any other address becomes `heap_base` plus an arbitrary value: | ||
| 1863 | - a V# a shader builds in SGPRs from data; | ||
| 1864 | - a raw `global_`/`flat_` address (530 of the 26,503 shaders of package 1.0.2.1, 69 of the 2,684 pipeline-library | ||
| 1865 | programs); | ||
| 1866 | - a stale or offset-like value. | ||
| 1867 | |||
| 1868 | On RADV such an access page-faults. Two RX 7900 XTX runs (Mesa 26.3.1, under Wine) ended with the same sequence: | ||
| 1869 | - a `gfxhub` fault from client TCP with PERMISSION_FAULTS 0x3; | ||
| 1870 | - a compute-ring timeout and "MES failed to respond"; | ||
| 1871 | - a MODE1 reset ("VRAM is lost"). | ||
| 1872 | |||
| 1873 | Both faults were 4.8 GiB and 20 GiB above `heap_base`, past the arena's end. | ||
| 1874 | |||
| 1875 | "Inside the arena" is not the right bound. Several buffers are legitimately outside it, at a positive offset from | ||
| 1876 | `heap_base` (a negative one with `LEONIDA_IMPORT_BELOW_ARENA=1`): | ||
| 1877 | - geometry copies; | ||
| 1878 | - upload and readback buffers; | ||
| 1879 | - imported title memory; | ||
| 1880 | - separate window buffers. | ||
| 1881 | |||
| 1882 | The guard checks each access against what the runtime actually backs. An access that fails reads 0 and drops its | ||
| 1883 | store, so a wild address never reaches the GPU. The overall process follows VIctory | ||
| 1884 | ([`crates/victory-gpu/src/memory.rs`](https://github.com/marvisak/victory), GPL-3.0). Its page table of 64 KiB pages | ||
| 1885 | routes every computed address, and memory no copy holds reads 0 and takes no writes. The structure below is our own: | ||
| 1886 | VIctory's table names descriptor views, this one is a bitmap over device addresses. | ||
| 1887 | |||
| 1888 | **Structure: a two-level page table of 4 KiB pages over the 48-bit offset space, behind an arena compare.** The | ||
| 1889 | check works on the heap offset, the sign-extended 48-bit value `Gen.host_addr` adds to `heap_base`: | ||
| 1890 | - **Level 1:** 65,536 words indexed by offset bits 47..32. Each word names the level-2 block of one 4 GiB chunk. | ||
| 1891 | - **Level 2:** blocks of 32,768 words, one bit per 4 KiB page (bits 31..12). | ||
| 1892 | - **Two fixed blocks:** block 0 is empty and block 1 is full; allocated blocks start at 2. | ||
| 1893 | - **Size:** the table is a host-visible buffer of its own, 256 KiB plus 128 KiB per block (8.25 MiB for 62 blocks). | ||
| 1894 | |||
| 1895 | Why this structure: | ||
| 1896 | - **Pages of 4 KiB** are the GPU's own mapping granularity. A page any byte of a backing touches is mapped as a whole, | ||
| 1897 | so marking pages outward is exact for faults. A 64 KiB page would mark memory that may not be mapped. | ||
| 1898 | - **Level 1 by 4 GiB chunk** covers the whole signed 48-bit space (negative offsets index from 0x8000 up). A real run | ||
| 1899 | touches a handful of chunks, so the table stays small. | ||
| 1900 | - **Other structures cost more per access.** A sorted range table needs a binary search: about 10 dependent loads for | ||
| 1901 | a thousand backings, against 2 here. A coarse region bitmap plus a fine range table needs a search in the fine part. | ||
| 1902 | - **The arena needs no lookup.** It is one fully bound `VkBuffer`, so any offset below its size passes on a compare. | ||
| 1903 | That is the common case: descriptor heaps, default-heap buffers and windows in the arena. | ||
| 1904 | |||
| 1905 | **The header.** It sits at arena offset `0x70000`, after the zero page and the quad indices, and holds: | ||
| 1906 | - a 64-bit magic (`"LGUARD01"`); | ||
| 1907 | - the arena's size (the compare's limit); | ||
| 1908 | - the table's address minus `heap_base`; | ||
| 1909 | - a refusal count and the last refused offset, which the shaders write. | ||
| 1910 | |||
| 1911 | Two sinks follow the header: `0x71000` (zero area, what refused loads read) and `0x78000` (dump area, where refused | ||
| 1912 | stores and atomics go). None of `[0x70000, 0x80000)` is handed out. With `LEONIDA_ARENA_NULL_MB` the range lies in the | ||
| 1913 | null region, so its offset never moves. `runtime/src/address_guard.h` and `tools/address_guard.py` (the Python | ||
| 1914 | reference) hold the format. | ||
| 1915 | |||
| 1916 | **Each access.** `Gen.host_addr` takes the access kind (load, store or atomic) and its span. Under `--address-guard` | ||
| 1917 | it calls one function per module, `%guard_fn`, which is straight-line at the call site, so no caller's block | ||
| 1918 | structure changes. The function computes `end = offset + span - 1` and then decides: | ||
| 1919 | - **Passes on a compare:** the runtime's guard is off (no magic), or `offset` and `end` are both below the limit. The | ||
| 1920 | result is `heap_base + offset`. The cost is a 64-bit add, two 64-bit compares and a select. | ||
| 1921 | - **Otherwise, a lookup:** the bits of the pages of `offset` and of `end`. That is two independent pairs of dependent | ||
| 1922 | 32-bit loads (level 1, then level 2). | ||
| 1923 | - **Refused:** an access whose bits are not both set adds 1 to the header's count, writes its offset, and goes to the | ||
| 1924 | zero area (a load) or the dump area (a store or atomic), at its offset within its page. Alignment is kept, and every | ||
| 1925 | span fits inside a sink. | ||
| 1926 | - **Atomics** run on the dump area, and their returned value is replaced by 0 (`Gen.guard_zero`). The CAS loops (float | ||
| 1927 | min/max, inc/dec) end there too, as on any other memory. | ||
| 1928 | |||
| 1929 | The entry block reads the header's first six dwords once per invocation, from the arena, so that read is always | ||
| 1930 | backed. When the base is uniform, as for `s_load`, `s_buffer_load` and a V# from SGPRs plus a uniform offset, the | ||
| 1931 | compiler keeps the whole check scalar: one check per instruction, not per lane. A per-lane address (`global_` with a | ||
| 1932 | VGPR address, `offen`/`idxen`) is checked per lane, and the slow path runs only for lanes outside the arena. | ||
| 1933 | |||
| 1934 | **What is checked.** Every `heap_base` access goes through `host_addr`: | ||
| 1935 | - buffer loads and stores (dword, sub-dword, typed, format; swizzled spans are computed at run time); | ||
| 1936 | - `global_` loads, stores, sub-dword and atomics; | ||
| 1937 | - buffer atomics, `_x2` included; | ||
| 1938 | - `s_load` and `s_buffer_load`; | ||
| 1939 | - the BVH node reads of `image_bvh*_intersect_ray` (span by node type). | ||
| 1940 | |||
| 1941 | These are not checked: | ||
| 1942 | - images (T#s go through the hash table, not an address); | ||
| 1943 | - LDS; | ||
| 1944 | - the `--mesh-compute` output buffer (a runtime address); | ||
| 1945 | - `s_getpc` code reads. | ||
| 1946 | |||
| 1947 | The translator does not translate `flat_` instructions (they raise `Unsupported`), so none reaches memory today. A | ||
| 1948 | translation added later must go through `host_addr` like `global_` does. | ||
| 1949 | |||
| 1950 | **Keeping the table current.** The spans are the same backings the console heap pass's backed table uses | ||
| 1951 | (`update_gpu_backed`): | ||
| 1952 | - every `gpu_backings` entry outside the arena (upload and readback buffers, imports, slot-133 buffers, windows | ||
| 1953 | outside the arena); | ||
| 1954 | - the geometry copies' blocks; | ||
| 1955 | - the separate window buffers' blocks. | ||
| 1956 | |||
| 1957 | `update_address_guard` runs in the queue's `before_execute`, after the heap refresh, the windows and the geometry | ||
| 1958 | copies. It differs from that table in four ways: | ||
| 1959 | - It rebuilds whenever `backing_generation` or a block layout changed, with no 100 ms limit, because a backing made | ||
| 1960 | since the last submission must not read 0. | ||
| 1961 | - It writes only the words that changed, level 2 before level 1. | ||
| 1962 | - A chunk keeps its block for good, so a submission still in flight never reads a block that now means another chunk. | ||
| 1963 | - When the 62 blocks run out, a new chunk gets the full block (unchecked, as without the guard), and that is logged. | ||
| 1964 | |||
| 1965 | A release clears its bits at the next submission. D3D12 forbids releasing memory the GPU still uses, so only a wild | ||
| 1966 | access in flight at that moment could still pass. | ||
| 1967 | |||
| 1968 | **Cost per access:** | ||
| 1969 | - **Fast path:** about 8 scalar or vector ALU operations. | ||
| 1970 | - **Outside the arena:** about 40 operations and 4 loads, from a table small enough to stay in cache. | ||
| 1971 | - **Per invocation:** 6 uniform header loads. | ||
| 1972 | - **Per submission (runtime):** nothing until a backing changes, then a rebuild of the used blocks (128 KiB each) | ||
| 1973 | and a diff. | ||
| 1974 | |||
| 1975 | **Switches.** | ||
| 1976 | - `--address-guard` records `"address_guard": true` in `index.json`. | ||
| 1977 | - `LEONIDA_ADDRESS_GUARD=1` makes the runtime reserve the range, create the table and write the header. | ||
| 1978 | - Either alone does nothing: a guarded module on a runtime without the guard finds no magic, and every access passes | ||
| 1979 | after one compare. | ||
| 1980 | - Without the flag the module is byte for byte what it was. | ||
| 1981 | |||
| 1982 | **What a run with the guard shows.** | ||
| 1983 | - One line when the device is made: `[rt] d3d12: address guard on ...`. | ||
| 1984 | - At most one line a second: `[rt] d3d12: address guard: N access(es) refused so far (+k), the last at heap offset | ||
| 1985 | 0x...`. Each refusal is a wild access that would have reached the GPU. The offset says where to look (above the | ||
| 1986 | arena's end, as in the two faults). | ||
| 1987 | - A run that reset the GPU before should keep going, with wrong pixels where a refused access mattered. | ||
| 1988 | |||
| 1989 | **Risks and open points.** | ||
| 1990 | - A refused access that mattered (a backing the layer never registered) now reads 0 instead of faulting. That is | ||
| 1991 | silent apart from the count. | ||
| 1992 | - An access is checked as a whole. A multi-dword load whose first dwords are inside a V# and a backing, but whose | ||
| 1993 | last dword is past both on an unbacked page, reads 0 in full. | ||
| 1994 | - The table is read through the GPU's caches. A page whose bit changes while a submission is in flight can be seen | ||
| 1995 | either way by that submission. | ||
| 1996 | - Sparse buffers outside the arena are guarded only if they are registered as backings. | ||
| 1997 | |||
| 1998 | **Checked:** | ||
| 1999 | - `tests/semantic/test_address_guard.py`: the fixture `cs_address_guard` with the guard on, with it off at run time | ||
| 2000 | and without the flag, through `spirv_mini_interp`; the kind and span of each instruction family; the table model; | ||
| 2001 | the constants shared by the translator, the runtime and `tools/address_guard.py`. | ||
| 2002 | - `runtime/test/address_guard_test.cpp`: the page table, incremental writes, negative offsets, wrap, chunks and | ||
| 2003 | overflow. | ||
| 2004 | - `scripts/run_address_guard_gpu_test.py`: the fixture on a 2 MiB heap whose table backs one page outside the | ||
| 2005 | "arena". Every address it touches is inside the buffer, so no run can fault. With the guard on, the refused loads | ||
| 2006 | read 0 although memory is there, the store and the atomic land in the dump area and the count is 6. With the guard | ||
| 2007 | off, the same module reads that memory. It passed on lavapipe (Mesa 26.3.1). | ||
| 2008 | - Corpus (package 1.0.2.1, 2026-11-26): | ||
| 2009 | - `--shard 0/8` of the shaders: 3,313 translated and 3,313 `spirv-val`-valid, with the guard and without. | ||
| 2010 | - The pipeline library: 2,683 of 2,684 translated and valid, with the guard and without (the same one fails | ||
| 2011 | either way). | ||
| 2012 | - Without the flag, every module is byte for byte the same as before the change. | ||
| 2013 | - With it, the SPIR-V grows by 1.8% (shaders) and 1.6% (library). | ||
| 2014 | |||
| 1808 | ### 3.4 Descriptor heaps and the bindless model | 2015 | ### 3.4 Descriptor heaps and the bindless model |
| 1809 | 2016 | ||
| 1810 | The game can use D3D12 descriptors in three ways, and the layer must handle all of them: | 2017 | The game can use D3D12 descriptors in three ways, and the layer must handle all of them: |
| @@ -2413,13 +2620,33 @@ Pipeline creation: | |||
| 2413 | merges into the offline seed. `LEONIDA_DIRECT_SESSION_CACHE=0` also uses a merge when only the session exists. | 2620 | merges into the offline seed. `LEONIDA_DIRECT_SESSION_CACHE=0` also uses a merge when only the session exists. |
| 2414 | The files must match the Vulkan vendor, device and pipeline-cache UUID. Vulkan supplies an opaque snapshot. | 2621 | The files must match the Vulkan vendor, device and pipeline-cache UUID. Vulkan supplies an opaque snapshot. |
| 2415 | Replacing part of the previous file would corrupt it. | 2622 | Replacing part of the previous file would corrupt it. |
| 2416 | `LEONIDA_PIPELINE_CACHE_BYTES` caps session writes (256 MiB by default, zero disables the session file). | 2623 | `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 |
| 2624 | the session file). | ||
| 2625 | The session file can't keep a crashed run's compiles: it is written at teardown and at the optional checkpoints | ||
| 2626 | 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 | ||
| 2627 | described below. Every graphics build first asks the corpus cache with | ||
| 2628 | `VK_PIPELINE_CREATE_FAIL_ON_PIPELINE_COMPILE_REQUIRED_BIT`. A pipeline the corpus doesn't have is built against a | ||
| 2629 | second cache, seeded from `pipeline_cache.heavy.bin` next to `pipeline_cache.bin`, so that cache holds only the | ||
| 2630 | corpus's misses. | ||
| 2631 | A build that takes at least `LEONIDA_HEAVY_PIPELINE_CACHE_MS` (500 by default) marks the heavy cache for writing. | ||
| 2632 | 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 | ||
| 2633 | one, through the same staging file and rename as the session cache. A crash therefore loses at most the last 20 s | ||
| 2634 | of slow builds, and the next launch starts with the rest. A write that fails, or whose | ||
| 2635 | `vkGetPipelineCacheData` returns anything but `VK_SUCCESS` (`VK_INCOMPLETE` means the cache grew after the size | ||
| 2636 | query, so the blob is truncated), leaves the previous file in place and the cache dirty: it is tried again 5 s | ||
| 2637 | later, the delay doubling with each failure in a row up to 2 min, so the cache is not left unsaved until teardown | ||
| 2638 | and a write that keeps failing does not spin. At device teardown the thread stops, and the cache is | ||
| 2639 | written if any build went into it. Fast builds are kept that way: without an offline seed every build is a miss, | ||
| 2640 | so they no longer reach `pipeline_cache.session.bin`. `LEONIDA_HEAVY_PIPELINE_CACHE_MS=0` turns the heavy cache off, and with it the | ||
| 2641 | `pipelineCreationCacheControl` feature unless `LEONIDA_PIPELINE_COMPILE=cache-only` asks for it. A cache-only create | ||
| 2642 | (`cache-only`) is left as it is. | ||
| 2417 | `LEONIDA_SKIP_COMPUTE=<part of a name>[,<part>...]` (`all`: every compute program) never builds the matching | 2643 | `LEONIDA_SKIP_COMPUTE=<part of a name>[,<part>...]` (`all`: every compute program) never builds the matching |
| 2418 | compute programs and drops their dispatches, direct and indirect; the first dropped dispatch of each is logged. | 2644 | compute programs at play and drops their dispatches, direct and indirect; the first dropped dispatch of each is |
| 2419 | It is a way past a program that hangs the GPU while the program or its input is fixed, not a fix. | 2645 | logged. It is a way past a program that hangs the GPU while the program or its input is fixed, not a fix. |
| 2646 | `--precompile-pipelines` (below) builds them anyway unless it is given `--skip-listed`. | ||
| 2420 | `LEONIDA_STARTUP_CACHE_CHECKPOINTS=1` also schedules a snapshot after a successful pipeline build, | 2647 | `LEONIDA_STARTUP_CACHE_CHECKPOINTS=1` also schedules a snapshot after a successful pipeline build, |
| 2421 | at most once per 120 seconds. It starts on the compile worker when queued builds have drained and the device | 2648 | at most once per 120 seconds. It starts on the compile worker when queued builds have drained and the device |
| 2422 | has no active builds. These snapshots have an additional 512 MiB ceiling. The driver fills a mapped staging | 2649 | has no active builds. The driver fills a mapped staging |
| 2423 | file directly. A successful snapshot atomically replaces the session. An interrupted write preserves the | 2650 | file directly. A successful snapshot atomically replaces the session. An interrupted write preserves the |
| 2424 | previous cache; the next launch removes unheld staging files older than ten minutes. | 2651 | previous cache; the next launch removes unheld staging files older than ten minutes. |
| 2425 | While the compute warm-up has builds queued that idle checkpoint never starts, and a boot that ends by a crash, | 2652 | While the compute warm-up has builds queued that idle checkpoint never starts, and a boot that ends by a crash, |
| @@ -2455,7 +2682,8 @@ Pipeline creation: | |||
| 2455 | folders can share one; the file names and the driver's checks keep a pipeline from one build from being taken | 2682 | folders can share one; the file names and the driver's checks keep a pipeline from one build from being taken |
| 2456 | for another's. | 2683 | for another's. |
| 2457 | `gta6rt --precompile-pipelines [--threads N] [--big-threads N] [--all] [--smallest-first] [--limit N] | 2684 | `gta6rt --precompile-pipelines [--threads N] [--big-threads N] [--all] [--smallest-first] [--limit N] |
| 2458 | [--min-bytes N] [--max-bytes N] [--filter PART]... [--list]` fills the journal ahead of play, with no game: it | 2685 | [--min-bytes N] [--max-bytes N] [--filter PART]... [--skip-listed] [--list]` fills the journal ahead of play, with |
| 2686 | no game: it | ||
| 2459 | creates the Vulkan device as `--run` does (so the same environment gives the same journal names and driver keys: | 2687 | creates the Vulkan device as `--run` does (so the same environment gives the same journal names and driver keys: |
| 2460 | LEONIDA_SHADERS, LEONIDA_PIPELINE_CACHE_DIR, and LEONIDA_DEVICE_FAULT/LEONIDA_AFTERMATH, whose diagnostics config | 2688 | LEONIDA_SHADERS, LEONIDA_PIPELINE_CACHE_DIR, and LEONIDA_DEVICE_FAULT/LEONIDA_AFTERMATH, whose diagnostics config |
| 2461 | makes other pipelines) and builds every compute entry of the library through the dispatch path | 2689 | makes other pipelines) and builds every compute entry of the library through the dispatch path |
| @@ -2465,6 +2693,19 @@ Pipeline creation: | |||
| 2465 | 4 threads: modules of 3.6-5.8 MB took 46-145 s each, 12 in 312 s, about 3.5 GB of host memory each while in the | 2693 | 4 threads: modules of 3.6-5.8 MB took 46-145 s each, 12 in 312 s, about 3.5 GB of host memory each while in the |
| 2466 | driver (14.5 GB peak for four). Graphics pipelines are not covered: they are built at a title's draw from its PSO | 2694 | driver (14.5 GB peak for four). Graphics pipelines are not covered: they are built at a title's draw from its PSO |
| 2467 | description and the bound formats, and take milliseconds. | 2695 | description and the bound formats, and take milliseconds. |
| 2696 | `LEONIDA_SKIP_COMPUTE` does not narrow the build: it is a play-time setting, players run the pre-compile with the | ||
| 2697 | game's environment, and a program left out here would stay out of the journal after the list is shortened. The run | ||
| 2698 | says how many entries the list names and builds them; `--skip-listed` leaves them out on purpose. The last line | ||
| 2699 | counts what was built (compiled, or found in a cache), what was journaled already or being built by another | ||
| 2700 | process, what failed, and what was left out and why: by `--skip-listed`, not buildable on this device (no SPIR-V, | ||
| 2701 | set-0 bindings without a bindless set, workgroup memory over the limit), or filtered out (`--filter`, the size | ||
| 2702 | bounds, `--limit`). The 89-167 s per program behind the skip list of the large `library/` programs came from | ||
| 2703 | wave64-emulated packs. Measured with a native wave64 pack on an RX 7900 XTX (RADV, Mesa 26.3.1, Wine): all 721 | ||
| 2704 | programs of 2 MiB or more built, 360 of them in 170 s on 32 threads, 2.5-32 s each, the largest (13 MiB) in 28.5 s | ||
| 2705 | alone, at a peak of 14 GiB of RAM for the process. With all of them in the journal and no skip list, two world runs | ||
| 2706 | took them all from the journal (none built in the game) and ended as runs with the skip list do, in an idle-queue | ||
| 2707 | device loss or a stop with the GPU idle ([running.md](running.md#settings-every-platform-needs)); whether their | ||
| 2708 | output is correct is not measured. | ||
| 2468 | `LEONIDA_COMPILE_HELPER=1` (`shims/d3d12_compile_helper.h`) keeps first-ever compiles out of the title's process: | 2709 | `LEONIDA_COMPILE_HELPER=1` (`shims/d3d12_compile_helper.h`) keeps first-ever compiles out of the title's process: |
| 2469 | the driver's locks, which a long `vkCreateComputePipelines` holds and a `vkQueueSubmit` of the same process waits | 2710 | the driver's locks, which a long `vkCreateComputePipelines` holds and a `vkQueueSubmit` of the same process waits |
| 2470 | for, are per process. A compute build of `LEONIDA_COMPILE_HELPER_MIN_BYTES` or more (128 KiB) with no journal file | 2711 | for, are per process. A compute build of `LEONIDA_COMPILE_HELPER_MIN_BYTES` or more (128 KiB) with no journal file |
diff --git a/docs/design.md b/docs/design.md index eee5be2cc..a4b8b8dd8 100644 --- a/docs/design.md +++ b/docs/design.md | |||
| @@ -313,7 +313,7 @@ How the generated SPIR-V expects the runtime to work: | |||
| 313 | | Xbox GPU addresses | Shaders build Xbox GPU virtual addresses, and some force the high dword to 0 (descriptor tables in the low 4 GB). Every memory access goes to **heap base + Xbox VA**, so the runtime maps the console's GPU address window into one host buffer-device-address allocation. | | 313 | | Xbox GPU addresses | Shaders build Xbox GPU virtual addresses, and some force the high dword to 0 (descriptor tables in the low 4 GB). Every memory access goes to **heap base + Xbox VA**, so the runtime maps the console's GPU address window into one host buffer-device-address allocation. | |
| 314 | | Code-embedded data | 155 VS/PS had "undecodable words". They're **constant tables inside the code range** (float values like 0x3EF7…, plus zeros), read through `s_getpc_b64` + `s_add_u32`/`s_addc_u32` + `s_load` (147 of 155). The translator re-anchors each instruction to its true FSSM offset by matching encodings (when the llvm-mc messages give one offset per rejected word, `shader_ir.parse_file`'s `invalid_at`, those words are skipped exactly and nothing is searched forward: a forward search let a data word printed as a copy of a later instruction take that instruction's place and lose every one after it; counted on the 1.0.2.1 pipeline library with #327's vcc-tuple decoding, 36 compute programs that stopped at "cannot re-anchor" now translate and pass `spirv-val`, none lost; `tests/semantic/test_reanchor_llvm_offsets.py`), translates only code reachable from entry (a branch into data is rejected), and turns `s_getpc_b64` into code base + next-instruction offset. **The runtime uploads each shader's FSSM blob into the heap and passes that VA as the code base.** Re-anchoring compares bytes exactly, except that VOP3P `op_sel_hi[2]` (bit 14) is ignored on two-source packed ops: the compiler stores 0 there, and LLVM prints its default of 1. Unused VOP3/VOP3P `SRC1` (bits 49:41) and `SRC2` (bits 58:50) fields are also ignored when stored as 0 and printed as `0x80`: LLVM 23 re-encodes a source it doesn't read as inline constant 0 (one-source `v_rcp`/`v_log`/`v_sqrt_f32_e64`, two-source `v_sub_f32_e64`/`v_cmp_*_e64`/`v_mul_lo_u32`/`v_pk_mul_f16`). Both checks for clean listings and re-anchoring use the parsed operand count to apply this exception only to unused sources. A used source encoded as 0 reads `s0` and is never treated as inline zero. `tests/semantic/test_printed_encoding.py` checks used `SRC1`/`SRC2` and an unused field with synthetic listings. Confirmed by a count over the corpus with LLVM 23.1.5: without it, 1,471 of the 1,473 shaders with embedded data are rejected ("reachable instruction with normalized encoding"); with it, all 1,473 translate and pass `spirv-val`. Runs with LLVM 21 already translated all of them, so older LLVMs presumably print the stored 0 (not re-checked). Data words that decode with ignored fields set are printed re-encoded (e.g. `0xbe8d2242` as `s_rfe_b64` `0xbe802242`), so they can never match. Since the decoder consumed the same length, they are anchored in sequence and marked. A shader that can *reach* a marked word is rejected; none of the corpus does. All 155 now translate. A reachable instruction that falls through into words llvm-mc skipped (it printed no instruction there) is rejected too, as `fall-through into undecodable words`: until SHADER-813 the reachable path ended there without a word, so everything after the gap (exports, stores) was dropped from a module that still passed `spirv-val`. No VS/PS of the corpus has such a gap on a reachable path; in the FidelityFX FSPX programs it is the `v_dot4_i32_i8 ... op_sel` words LLVM 23 cannot decode (`docs/fspx.md`), so those programs are now refused instead of translated without their stores, until those words are decoded (#2038, #2323). `tests/test_rdna2spirv_decode.py` (`test_fall_through_into_undecodable_words_is_refused`). The exact re-anchoring path tries the same repair as the forward search for a `v_dot4_i32_i8` with an inline-integer S1 whose stored op_sel_hi (5) llvm-mc prints as the default (7), `restore_dot4_inline_sel`, before it marks the word: without it such a program is refused as "reachable instruction with normalized encoding" whenever its listing also reports rejected words. Counted on the 29 FidelityFX DLL programs (1.0.2.1, LLVM 21.1.8): 22 translate without it, 24 with it, all 24 pass `spirv-val`; `tests/semantic/test_reanchor_dot4_inline_sel.py`. | | 314 | | Code-embedded data | 155 VS/PS had "undecodable words". They're **constant tables inside the code range** (float values like 0x3EF7…, plus zeros), read through `s_getpc_b64` + `s_add_u32`/`s_addc_u32` + `s_load` (147 of 155). The translator re-anchors each instruction to its true FSSM offset by matching encodings (when the llvm-mc messages give one offset per rejected word, `shader_ir.parse_file`'s `invalid_at`, those words are skipped exactly and nothing is searched forward: a forward search let a data word printed as a copy of a later instruction take that instruction's place and lose every one after it; counted on the 1.0.2.1 pipeline library with #327's vcc-tuple decoding, 36 compute programs that stopped at "cannot re-anchor" now translate and pass `spirv-val`, none lost; `tests/semantic/test_reanchor_llvm_offsets.py`), translates only code reachable from entry (a branch into data is rejected), and turns `s_getpc_b64` into code base + next-instruction offset. **The runtime uploads each shader's FSSM blob into the heap and passes that VA as the code base.** Re-anchoring compares bytes exactly, except that VOP3P `op_sel_hi[2]` (bit 14) is ignored on two-source packed ops: the compiler stores 0 there, and LLVM prints its default of 1. Unused VOP3/VOP3P `SRC1` (bits 49:41) and `SRC2` (bits 58:50) fields are also ignored when stored as 0 and printed as `0x80`: LLVM 23 re-encodes a source it doesn't read as inline constant 0 (one-source `v_rcp`/`v_log`/`v_sqrt_f32_e64`, two-source `v_sub_f32_e64`/`v_cmp_*_e64`/`v_mul_lo_u32`/`v_pk_mul_f16`). Both checks for clean listings and re-anchoring use the parsed operand count to apply this exception only to unused sources. A used source encoded as 0 reads `s0` and is never treated as inline zero. `tests/semantic/test_printed_encoding.py` checks used `SRC1`/`SRC2` and an unused field with synthetic listings. Confirmed by a count over the corpus with LLVM 23.1.5: without it, 1,471 of the 1,473 shaders with embedded data are rejected ("reachable instruction with normalized encoding"); with it, all 1,473 translate and pass `spirv-val`. Runs with LLVM 21 already translated all of them, so older LLVMs presumably print the stored 0 (not re-checked). Data words that decode with ignored fields set are printed re-encoded (e.g. `0xbe8d2242` as `s_rfe_b64` `0xbe802242`), so they can never match. Since the decoder consumed the same length, they are anchored in sequence and marked. A shader that can *reach* a marked word is rejected; none of the corpus does. All 155 now translate. A reachable instruction that falls through into words llvm-mc skipped (it printed no instruction there) is rejected too, as `fall-through into undecodable words`: until SHADER-813 the reachable path ended there without a word, so everything after the gap (exports, stores) was dropped from a module that still passed `spirv-val`. No VS/PS of the corpus has such a gap on a reachable path; in the FidelityFX FSPX programs it is the `v_dot4_i32_i8 ... op_sel` words LLVM 23 cannot decode (`docs/fspx.md`), so those programs are now refused instead of translated without their stores, until those words are decoded (#2038, #2323). `tests/test_rdna2spirv_decode.py` (`test_fall_through_into_undecodable_words_is_refused`). The exact re-anchoring path tries the same repair as the forward search for a `v_dot4_i32_i8` with an inline-integer S1 whose stored op_sel_hi (5) llvm-mc prints as the default (7), `restore_dot4_inline_sel`, before it marks the word: without it such a program is refused as "reachable instruction with normalized encoding" whenever its listing also reports rejected words. Counted on the 29 FidelityFX DLL programs (1.0.2.1, LLVM 21.1.8): 22 translate without it, 24 with it, all 24 pass `spirv-val`; `tests/semantic/test_reanchor_dot4_inline_sel.py`. | |
| 315 | | VOP3 opcode 0x140 | LLVM disassembly of the synthetic words in `tests/test_rdna2_decode.py` gives `v_mad_legacy_f32` on gfx1010 through gfx1013 and `v_fma_legacy_f32` on gfx1030. The direct decoder defaults to gfx1013, matching the disassembler CLI. Checked by the unit test `test_vop3_legacy_mad_fma_target` in `tests/test_rdna2_decode.py`, which decodes the same words directly and runs the Python disassembler backend for gfx1013 and gfx1030. | | 315 | | VOP3 opcode 0x140 | LLVM disassembly of the synthetic words in `tests/test_rdna2_decode.py` gives `v_mad_legacy_f32` on gfx1010 through gfx1013 and `v_fma_legacy_f32` on gfx1030. The direct decoder defaults to gfx1013, matching the disassembler CLI. Checked by the unit test `test_vop3_legacy_mad_fma_target` in `tests/test_rdna2_decode.py`, which decodes the same words directly and runs the Python disassembler backend for gfx1013 and gfx1030. | |
| 316 | | Printed encodings | A listing is LLVM's text for what it decoded, not the bytes it read, so the translator checks the two against each other: the re-anchoring above for listings with undecodable words, and, for every other listing whose header names its code range and whose blob sits next to it (`fssm/`, or `fspx/` for FSPX), each instruction's printed encoding against the bytes at its offset, with the same exceptions (`same_encoding`). A difference is `Unsupported`, naming the instruction, its offset and both byte strings, instead of a translation of the field as 0. The case that prompted it: llvm-mc's gfx1013 decoder (LLVM 21.1.8) drops the VOP3 `op_sel` bits (word 0, bits 14:11) of a 16-bit VOPC compare: `0a 08 a9 d4 01 05 02 00` disassembles as `v_cmp_lt_u16_e64 s10, v1, v2` and re-encodes with the bits cleared (its assembler rejects `op_sel` on VOPC for gfx1013 and gfx1030 alike). Counted over the 1.0.2.1 corpus: the 25,030 clean listings hold 30,335,381 instructions, and none differs from its bytes beyond those exceptions (754); the 166 16-bit VOPC compares (154 shaders, all `f16`) have `op_sel` clear. Hand-written listings, `run_gpu_tests.py`'s `code 0x0..0x0 (synthetic)` listings and a blob that doesn't hold the listing's code range (the tests' header-only FSSM) are not checked. `tests/semantic/test_printed_encoding.py` (a dropped VOPC `op_sel`, a later instruction, the SRC2 exception, and the unchecked cases). One difference is repaired instead of refused: a `v_fma_mix*` literal that llvm-mc prints cut to its low 16 bits (and re-encodes with a zero high half). llvm-mc 23.1.5 prints some of these literals in full as `lit(V)` (an f32 source, or a low half that is an inline constant; LLVM 21 printed the inline constant and dropped the literal word) and still re-encodes only the low half: `tools/shader_ir.py` reads `lit(V)` as V, and the same repair applies (5,733 such operands in the pipeline library, [shader_library.md](shader_library.md)). When the 8 instruction bytes match (`same_encoding` with all three sources counted as used, so a live `s0` can't pass as an inline 0) and the printed literal is the stored one's low half, every source the bytes encode as the literal (SRC field `0xff`) takes the stored 32 bits, so a source with `op_sel_hi` and `op_sel` set reads the high half instead of +0.0. Seen in one program of the FidelityFX DLL's `FSPX` code ([fspx.md](fspx.md)): src0 the low half, src2 the high half; the game's clean listings have no such difference (the count above). That the hardware gives op_sel's high half of the literal to that source is not measured; it is what Mesa's ACO compiler relies on (public: `optimize_constants()` in `src/amd/compiler/aco_optimizer.cpp`, Mesa `main` at `bb986060`, packs two constants as the two f16 halves of one literal, read through `v_fma_mix`'s `op_sel_hi` with the second source extracting the high half), and what the console compiler emitted here. `tools/fma_mix_literal_probe.py --oracle hw` measures it on an AMD GPU (the instruction's exact bytes through `tools/hw_oracle`; not run on one yet). `tests/semantic/test_fma_mix_literal.py` (the value through the interpreter, the re-anchoring path, an inline constant with the literal's printed value left alone, and the refused cases, a live source printed as inline 0 among them). A second shape is repaired too (`mix_inline_literal`): LLVM 21's form above. llvm-mc 21.1.8 (`-mcpu=gfx1013`) prints a `v_fma_mix*` literal whose low 16 bits are the f16 value of an inline constant as that constant and re-encodes the instruction in **8** bytes: every SRC field that held `0xff` holds the inline code, and the literal word is gone (`0x3f800000`, 1.0 as an f32 source, prints as `0`; `0x3c003800` as `0.5`, losing the high half 1.0). Swept with llvm-mc 21.1.8 over all 65,536 low halves under three high halves: exactly 90 low halves print this way (0..64, -1..-16, ±0.5, ±1.0, ±2.0, ±4.0, 1/(2π) as f16: `MIX_INLINE_F16`), whatever the high half; llvm-mc 23.1.6 prints all of them as `lit(V)`. The printed 8 bytes are 4 short of what the decoder read, so the later offsets of a clean listing were 4 low and its first such instruction was refused as a dropped field (one FSPX program, `tupacfan04`'s count in #8683). When every differing SRC field is `0xff` in the blob and the inline code of the stored literal's low half in the print, and the rest of the 8 bytes match exactly (`same_encoding`, all three sources live), each such source reads the stored 32 bits with the stored neg and abs (`NEG_HI`) bits, the instruction takes the 12 stored bytes, and the following offsets move up by 4 (also on the re-anchoring path). Any other difference stays `Unsupported`. CPU-checked by `tests/semantic/test_fma_mix_literal.py` (`FmaMixInlineLiteralTest`: an f32 source, two f16 halves, neg and abs, all 90 codes, both listing paths, the refused cases). | | 316 | | Printed encodings | A listing is LLVM's text for what it decoded, not the bytes it read, so the translator checks the two against each other: the re-anchoring above for listings with undecodable words, and, for every other listing whose header names its code range and whose blob sits next to it (`fssm/`, or `fspx/` for FSPX), each instruction's printed encoding against the bytes at its offset, with the same exceptions (`same_encoding`). A difference is `Unsupported`, naming the instruction, its offset and both byte strings, instead of a translation of the field as 0. The case that prompted it: llvm-mc's gfx1013 decoder (LLVM 21.1.8) drops the VOP3 `op_sel` bits (word 0, bits 14:11) of a 16-bit VOPC compare: `0a 08 a9 d4 01 05 02 00` disassembles as `v_cmp_lt_u16_e64 s10, v1, v2` and re-encodes with the bits cleared (its assembler rejects `op_sel` on VOPC for gfx1013 and gfx1030 alike). Counted over the 1.0.2.1 corpus: the 25,030 clean listings hold 30,335,381 instructions, and none differs from its bytes beyond those exceptions (754); the 166 16-bit VOPC compares (154 shaders, all `f16`) have `op_sel` clear. Hand-written listings, `run_gpu_tests.py`'s `code 0x0..0x0 (synthetic)` listings and a blob that doesn't hold the listing's code range (the tests' header-only FSSM) are not checked. `tests/semantic/test_printed_encoding.py` (a dropped VOPC `op_sel`, a later instruction, the SRC2 exception, and the unchecked cases). One difference is repaired instead of refused: a `v_fma_mix*` literal that llvm-mc prints cut to its low 16 bits (and re-encodes with a zero high half). llvm-mc 23.1.5 prints some of these literals in full as `lit(V)` (an f32 source, or a low half that is an inline constant; LLVM 21 printed the inline constant and dropped the literal word) and still re-encodes only the low half: `tools/shader_ir.py` reads `lit(V)` as V, and the same repair applies (5,733 such operands in the pipeline library, [shader_library.md](shader_library.md)). When the 8 instruction bytes match (`same_encoding` with all three sources counted as used, so a live `s0` can't pass as an inline 0) and the printed literal is the stored one's low half, every source the bytes encode as the literal (SRC field `0xff`) takes the stored 32 bits, so a source with `op_sel_hi` and `op_sel` set reads the high half instead of +0.0. Seen in one program of the FidelityFX DLL's `FSPX` code ([fspx.md](fspx.md)): src0 the low half, src2 the high half; the game's clean listings have no such difference (the count above). That the hardware gives op_sel's high half of the literal to that source is not measured; it is what Mesa's ACO compiler relies on (public: `optimize_constants()` in `src/amd/compiler/aco_optimizer.cpp`, Mesa `main` at `bb986060`, packs two constants as the two f16 halves of one literal, read through `v_fma_mix`'s `op_sel_hi` with the second source extracting the high half), and what the console compiler emitted here. `tools/fma_mix_literal_probe.py --oracle hw` measures it on an AMD GPU (the instruction's exact bytes through `tools/hw_oracle`; not run on one yet). `tests/semantic/test_fma_mix_literal.py` (the value through the interpreter, the re-anchoring path, an inline constant with the literal's printed value left alone, and the refused cases, a live source printed as inline 0 among them). A second shape is repaired too (`mix_inline_literal`): LLVM 21's form above. llvm-mc 21.1.8 (`-mcpu=gfx1013`) prints a `v_fma_mix*` literal whose low 16 bits are the f16 value of an inline constant as that constant and re-encodes the instruction in **8** bytes: every SRC field that held `0xff` holds the inline code, and the literal word is gone (`0x3f800000`, 1.0 as an f32 source, prints as `0`; `0x3c003800` as `0.5`, losing the high half 1.0). Swept with llvm-mc 21.1.8 over all 65,536 low halves under three high halves: exactly 90 low halves print this way (0..64, -1..-16, ±0.5, ±1.0, ±2.0, ±4.0, 1/(2π) as f16: `MIX_INLINE_F16`), whatever the high half; llvm-mc 23.1.6 prints all of them as `lit(V)`. The printed 8 bytes are 4 short of what the decoder read, so the later offsets of a clean listing were 4 low and its first such instruction was refused as a dropped field (one FSPX program, `tupacfan04`'s count in #8683). When every differing SRC field is `0xff` in the blob and the inline code of the stored literal's low half in the print, and the rest of the 8 bytes match exactly (`same_encoding`, all three sources live), each such source reads the stored 32 bits with the stored neg and abs (`NEG_HI`) bits, the instruction takes the 12 stored bytes, and the following offsets move up by 4 (also on the re-anchoring path). Any other difference stays `Unsupported`. CPU-checked by `tests/semantic/test_fma_mix_literal.py` (`FmaMixInlineLiteralTest`: an f32 source, two f16 halves, neg and abs, all 90 codes, both listing paths, the refused cases). A third shape needs no blob: llvm-mc 21.1.8 also prints such a literal cut to its low 16 bits in the text while its printed encoding keeps all 32, so the printed-encoding check passes and the text alone read the high half as +0.0 (an f16 source reads 0 instead of its high half, an f32 source a denormal instead of its value). `restore_text_cut_mix_literal` takes the literal from the printed encoding, on the clean and the re-anchoring paths. Counted on one work folder's listings of 1.0.2.1: 47,910 instructions in 1,218 pipeline-library programs and 6 in one FSPX program, none in the game's own shaders. CPU-checked by `test_text_cut_but_printed_encoding_whole` (with and without a blob) and `test_text_immediate_other_than_the_low_half_is_left_alone`. | |
| 317 | | Global memory | `global_load/store_dword*`: address = (64-bit SGPR base + zero-extended 32-bit VGPR offset, or a 64-bit VGPR address) + the instruction offset, translated through the heap base. Inactive lanes don't access memory, and loads merge their previous values with OpPhi. The offset is the **signed 12-bit** byte value as llvm-mc prints it, -2048..2047 (`offset:-4` is the field 0xffc; llvm-mc rejects `offset:0xffc` and disassembles that field as `offset:-4`, so no repo path delivers the raw unsigned field), added to the address as is; a tool that printed the raw field (`0xffc`) would mean the same offset, and a value outside 12 bits is rejected. Measured on an AMD Radeon RX 6800 (gfx1030) running `global_load_dword` as a raw compute kernel, wave32 and wave64 alike, with the dword at byte n = 0x10000000+n and the pointer at 0x1000: offset 0 reads 0x10001000, -4 0x10000ffc, -2048 0x10000800, 2044 0x100017fc, -1024 0x10000c00. The translator used to subtract 0x1000 from an already negative value (4096 bytes too low). Checked by `tests/semantic/test_global_mem_offset.py` (both addressing modes, dword/x2/x4, byte/short loads and stores at -4, -2048, 2047 and 0) and the GPU test `runtime/test/shaders/cs_global_neg_offset.asm` (`vk_compute_test ... 40 dump`). | | 317 | | Global memory | `global_load/store_dword*`: address = (64-bit SGPR base + zero-extended 32-bit VGPR offset, or a 64-bit VGPR address) + the instruction offset, translated through the heap base. Inactive lanes don't access memory, and loads merge their previous values with OpPhi. The offset is the **signed 12-bit** byte value as llvm-mc prints it, -2048..2047 (`offset:-4` is the field 0xffc; llvm-mc rejects `offset:0xffc` and disassembles that field as `offset:-4`, so no repo path delivers the raw unsigned field), added to the address as is; a tool that printed the raw field (`0xffc`) would mean the same offset, and a value outside 12 bits is rejected. Measured on an AMD Radeon RX 6800 (gfx1030) running `global_load_dword` as a raw compute kernel, wave32 and wave64 alike, with the dword at byte n = 0x10000000+n and the pointer at 0x1000: offset 0 reads 0x10001000, -4 0x10000ffc, -2048 0x10000800, 2044 0x100017fc, -1024 0x10000c00. The translator used to subtract 0x1000 from an already negative value (4096 bytes too low). Checked by `tests/semantic/test_global_mem_offset.py` (both addressing modes, dword/x2/x4, byte/short loads and stores at -4, -2048, 2047 and 0) and the GPU test `runtime/test/shaders/cs_global_neg_offset.asm` (`vk_compute_test ... 40 dump`). | |
| 318 | | Global atomics (`global_atomic_*`, 32-bit) | `add`, `sub`, `smin/umin`, `smax/umax`, `and`, `or`, `xor`, `swap` and `cmpswap` at the `global_load/store` address (same `Gen.global_address`: saddr pair plus zero-extended vaddr, or a 64-bit vaddr with `off`, plus the signed 12-bit offset), as one `OpAtomic*` on the PhysicalStorageBuffer dword, device scope, guarded so inactive lanes don't touch memory. `fmin` and `fmax` (32-bit float) lower to a structured `OpAtomicCompareExchange` CAS loop using GLSL.std.450 `NMin`/`NMax` (no Vulkan float-atomic extension needed; NaN returns the non-NaN operand, `-0.0 < +0.0`). `inc` and `dec` (32-bit unsigned wrapping against `DATA`: `inc` gives `(M >= DATA) ? 0 : M + 1`, `dec` gives `(M == 0 \|\| M > DATA) ? DATA : M + 1`, `dec` gives `(M == 0 With `glc` the pre-op value lands in `vdst`, the first operand; without `glc` there is no `vdst`, and the first-read analysis counts operand 0 as the address (a source). `cmpswap` takes `vdata` as the pair {DATA, CMP}: `M = (M == CMP) ? DATA : M`, as `buffer_atomic_cmpswap`. Still `Unsupported`: the `_x2` 64-bit forms, `inc`/`dec`, the float atomics, and `slc`/`dlc`. `and/or/xor/swap_x2` work on a 64-bit element (two dwords, low first) as one 32-bit atomic per dword, with no Int64 atomics: a bitwise op leaves the same memory that way, since its bits are independent. **Approximation:** an exchange can tear, since two lanes swapping into one element at once can leave one's low dword with the other's high dword (A.lo, B.lo, B.hi, A.hi), and the returned pair comes from two reads, so another lane's 64-bit op on the same element between them can show up half done (as for `ds_and/or/xor_b64`). **Approximation:** the returned pair comes from two reads, so another lane's 64-bit op on the same element between them can show up half done (as for `ds_and/or/xor_b64`). Still `Unsupported`: the other `_x2` forms (`add/sub/min/max/fmin/fmax_x2` carry or compare across the dwords, and `cmpswap_x2` compares all 64 bits), `inc`/`dec`, `fcmpswap`, and `slc`/`dlc`. Until 2026-11-22 every global atomic was rejected. CPU-checked by `tests/semantic/test_global_atomics.py` (all ten ops on a value grid with and without `glc`, `cmpswap`, offsets from -2048 to 2044, `off` addressing, seeded values, rejected forms, the first-read analysis). CPU-checked by `tests/semantic/test_global_atomics.py` (all ten integer ops plus `fmin`/`fmax` on a value grid with and without `glc`, NaN/±0/±inf, multi-lane CAS contention, `cmpswap`, offsets from -2048 to 2044, `off` addressing, seeded values, rejected forms, the first-read analysis) and `tests/semantic/test_global_atomics_x2.py` (the four `_x2` forms with and without `glc`, an offset, seeded values, the carrying forms rejected), and validated with `spirv-val` (native and `--wave64-emulate`). **Not GPU-verified.** \|\| M > DATA) ? DATA : M - 1`, RDNA2 ISA) also lower to a structured `OpAtomicCompareExchange` CAS loop via `Gen.atomic_inc_dec_cas` for both `global_atomic_{inc,dec}` and MUBUF `buffer_atomic_{inc,dec}` (preserving MUBUF bounds checks: OOB/inactive lanes leave memory untouched and return 0 with `glc`). With `glc` the pre-op value lands in `vdst`, the first operand; without `glc` there is no `vdst`, and the first-read analysis counts operand 0 as the address (a source). `cmpswap` takes `vdata` as the pair {DATA, CMP}: `M = (M == CMP) ? DATA : M`, as `buffer_atomic_cmpswap`. `and/or/xor/swap_x2` work on a 64-bit element (two dwords, low first) as one 32-bit atomic per dword: a bitwise op or an exchange leaves the same memory that way, with no Int64 atomics. **Approximation:** the returned pair comes from two reads, so another lane's 64-bit op on the same element between them can show up half done (as for `ds_and/or/xor_b64`). Still `Unsupported`: the other `_x2` forms (`add/sub/min/max/inc/dec/fmin/fmax_x2` carry or compare across the dwords, and `cmpswap_x2` compares all 64 bits), `fcmpswap`, and `slc`/`dlc`. Until 2026-11-22 every global atomic was rejected. CPU-checked by `tests/semantic/test_global_atomics.py` (all ten integer ops plus `fmin`/`fmax` on a value grid with and without `glc`, NaN/±0/±inf, multi-lane CAS contention, `cmpswap`, offsets from -2048 to 2044, `off` addressing, seeded values, rejected forms, the first-read analysis), `tests/semantic/test_atomic_inc_dec.py` (`global_atomic_{inc,dec}` and `buffer_atomic_{inc,dec}` edge grid, wraparound, `glc` vs non-`glc`, signed offsets, `off` addressing, MUBUF bounds/OOB, inactive lanes, multi-lane CAS contention, first-read analysis, rejected `_x2`/`slc`/`dlc` forms), and `tests/semantic/test_global_atomics_x2.py` (the four `_x2` forms with and without `glc`, an offset, seeded values, the carrying forms rejected), and validated with `spirv-val` (native and `--wave64-emulate`). **Not GPU-verified.** | | 318 | | Global atomics (`global_atomic_*`, 32-bit) | `add`, `sub`, `smin/umin`, `smax/umax`, `and`, `or`, `xor`, `swap` and `cmpswap` at the `global_load/store` address (same `Gen.global_address`: saddr pair plus zero-extended vaddr, or a 64-bit vaddr with `off`, plus the signed 12-bit offset), as one `OpAtomic*` on the PhysicalStorageBuffer dword, device scope, guarded so inactive lanes don't touch memory. `fmin` and `fmax` (32-bit float) lower to a structured `OpAtomicCompareExchange` CAS loop using GLSL.std.450 `NMin`/`NMax` (no Vulkan float-atomic extension needed; NaN returns the non-NaN operand, `-0.0 < +0.0`). `inc` and `dec` (32-bit unsigned wrapping against `DATA`: `inc` gives `(M >= DATA) ? 0 : M + 1`, `dec` gives `(M == 0 \|\| M > DATA) ? DATA : M + 1`, `dec` gives `(M == 0 With `glc` the pre-op value lands in `vdst`, the first operand; without `glc` there is no `vdst`, and the first-read analysis counts operand 0 as the address (a source). `cmpswap` takes `vdata` as the pair {DATA, CMP}: `M = (M == CMP) ? DATA : M`, as `buffer_atomic_cmpswap`. Still `Unsupported`: the `_x2` 64-bit forms, `inc`/`dec`, the float atomics, and `slc`/`dlc`. `and/or/xor/swap_x2` work on a 64-bit element (two dwords, low first) as one 32-bit atomic per dword, with no Int64 atomics: a bitwise op leaves the same memory that way, since its bits are independent. **Approximation:** an exchange can tear, since two lanes swapping into one element at once can leave one's low dword with the other's high dword (A.lo, B.lo, B.hi, A.hi), and the returned pair comes from two reads, so another lane's 64-bit op on the same element between them can show up half done (as for `ds_and/or/xor_b64`). **Approximation:** the returned pair comes from two reads, so another lane's 64-bit op on the same element between them can show up half done (as for `ds_and/or/xor_b64`). Still `Unsupported`: the other `_x2` forms (`add/sub/min/max/fmin/fmax_x2` carry or compare across the dwords, and `cmpswap_x2` compares all 64 bits), `inc`/`dec`, `fcmpswap`, and `slc`/`dlc`. Until 2026-11-22 every global atomic was rejected. CPU-checked by `tests/semantic/test_global_atomics.py` (all ten ops on a value grid with and without `glc`, `cmpswap`, offsets from -2048 to 2044, `off` addressing, seeded values, rejected forms, the first-read analysis). CPU-checked by `tests/semantic/test_global_atomics.py` (all ten integer ops plus `fmin`/`fmax` on a value grid with and without `glc`, NaN/±0/±inf, multi-lane CAS contention, `cmpswap`, offsets from -2048 to 2044, `off` addressing, seeded values, rejected forms, the first-read analysis) and `tests/semantic/test_global_atomics_x2.py` (the four `_x2` forms with and without `glc`, an offset, seeded values, the carrying forms rejected), and validated with `spirv-val` (native and `--wave64-emulate`). **Not GPU-verified.** \|\| M > DATA) ? DATA : M - 1`, RDNA2 ISA) also lower to a structured `OpAtomicCompareExchange` CAS loop via `Gen.atomic_inc_dec_cas` for both `global_atomic_{inc,dec}` and MUBUF `buffer_atomic_{inc,dec}` (preserving MUBUF bounds checks: OOB/inactive lanes leave memory untouched and return 0 with `glc`). With `glc` the pre-op value lands in `vdst`, the first operand; without `glc` there is no `vdst`, and the first-read analysis counts operand 0 as the address (a source). `cmpswap` takes `vdata` as the pair {DATA, CMP}: `M = (M == CMP) ? DATA : M`, as `buffer_atomic_cmpswap`. `and/or/xor/swap_x2` work on a 64-bit element (two dwords, low first) as one 32-bit atomic per dword: a bitwise op or an exchange leaves the same memory that way, with no Int64 atomics. **Approximation:** the returned pair comes from two reads, so another lane's 64-bit op on the same element between them can show up half done (as for `ds_and/or/xor_b64`). Still `Unsupported`: the other `_x2` forms (`add/sub/min/max/inc/dec/fmin/fmax_x2` carry or compare across the dwords, and `cmpswap_x2` compares all 64 bits), `fcmpswap`, and `slc`/`dlc`. Until 2026-11-22 every global atomic was rejected. CPU-checked by `tests/semantic/test_global_atomics.py` (all ten integer ops plus `fmin`/`fmax` on a value grid with and without `glc`, NaN/±0/±inf, multi-lane CAS contention, `cmpswap`, offsets from -2048 to 2044, `off` addressing, seeded values, rejected forms, the first-read analysis), `tests/semantic/test_atomic_inc_dec.py` (`global_atomic_{inc,dec}` and `buffer_atomic_{inc,dec}` edge grid, wraparound, `glc` vs non-`glc`, signed offsets, `off` addressing, MUBUF bounds/OOB, inactive lanes, multi-lane CAS contention, first-read analysis, rejected `_x2`/`slc`/`dlc` forms), and `tests/semantic/test_global_atomics_x2.py` (the four `_x2` forms with and without `glc`, an offset, seeded values, the carrying forms rejected), and validated with `spirv-val` (native and `--wave64-emulate`). **Not GPU-verified.** | |
| 319 | | `global_atomic_csub`, `buffer_atomic_csub` (GFX10.3) | `tmp = M; M = (DATA > tmp) ? 0 : tmp - DATA`, unsigned: a subtract clamped at 0 that never wraps; with `glc` the old M comes back. Measured on gfx1036 by @Vonsek (#3193): 162/162 (memory, data) pairs over both forms. Same `OpAtomicCompareExchange` loop as `inc`/`dec` (`Gen.atomic_inc_dec_cas`), so exact under contention; operands, inactive lanes, buffer bounds and `glc` as `inc`/`dec`. Until 2026-11-22 both raised `Unsupported`. CPU-checked by `tests/semantic/test_atomic_csub.py` (a 9×9 value grid, no `glc`, buffer bounds, 32 lanes on one dword against 32 sequential subtracts, seeded values). The translation is not GPU-verified. | | 319 | | `global_atomic_csub`, `buffer_atomic_csub` (GFX10.3) | `tmp = M; M = (DATA > tmp) ? 0 : tmp - DATA`, unsigned: a subtract clamped at 0 that never wraps; with `glc` the old M comes back. Measured on gfx1036 by @Vonsek (#3193): 162/162 (memory, data) pairs over both forms. Same `OpAtomicCompareExchange` loop as `inc`/`dec` (`Gen.atomic_inc_dec_cas`), so exact under contention; operands, inactive lanes, buffer bounds and `glc` as `inc`/`dec`. Until 2026-11-22 both raised `Unsupported`. CPU-checked by `tests/semantic/test_atomic_csub.py` (a 9×9 value grid, no `glc`, buffer bounds, 32 lanes on one dword against 32 sequential subtracts, seeded values). The translation is not GPU-verified. | |
| @@ -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 |
| 215 | under all three module names: `GAME:` reads with an overlay copy winning, offsets, zero size, a range past the end, | 237 | under all three module names: `GAME:` reads with an overlay copy winning, offsets, zero size, a range past the end, |
| 216 | cancellation, auto-submit, a full queue, status arrays, fences (a CPU fence object that checks the data is in place | 238 | cancellation, auto-submit, reads into physical pages held for `Submit` (a page list changed or filled before it, |
| 217 | when it is signalled), events, error records, file and queue close with requests in flight, a destination the | 239 | a full queue, the time limit, the switch), a full queue, status arrays, fences (a CPU fence object that checks the |
| 240 | data is in place when it is signalled), events, error records, file and queue close with requests in flight, a destination the | ||
| 218 | process cannot write, four threads enqueueing at once, the interface-id policy (unknown and system ids refused by | 241 | process 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 |
| 220 | its handle value reused) before it is set, and cancelled requests that also had an enqueue error. zlib requests use | 243 | its 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 ce4ed79f3..cd151d28e 100644 --- a/docs/gameinput.md +++ b/docs/gameinput.md | |||
| @@ -55,10 +55,13 @@ scripted pad, driven by the script alone: | |||
| 55 | shim, or through `IGameInputDispatcher::Dispatch` once the title made a dispatcher) and found by `FindDeviceFromId`. | 55 | shim, or through `IGameInputDispatcher::Dispatch` once the title made a dispatcher) and found by `FindDeviceFromId`. |
| 56 | It is already connected, so a callback registered without enumeration hears nothing. | 56 | It is already connected, so a callback registered without enumeration hears nothing. |
| 57 | - **The readings:** `GetCurrentReading`, `GetNextReading` and `GetPreviousReading`, with gamepad, UI navigation, | 57 | - **The readings:** `GetCurrentReading`, `GetNextReading` and `GetPreviousReading`, with gamepad, UI navigation, |
| 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, so no thread polls, |
| 59 | has changed since the last, so no thread polls; the history keeps the last 64 readings. | 59 | but it first adds one reading for every change the script made since the last, stamped with the script's own time: |
| 60 | a press that starts and ends between two reads of the title is still in the history, where `GetNextReading` finds | ||
| 61 | it, and the readings are the same however often the title reads. 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 | 62 | - **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. | 63 | log lines for both): seconds from the first `GameInputCreate`, each press held 300 ms (or its own `:hold`, see |
| 64 | `LEONIDA_INPUT_SCRIPT` below), then released. | ||
| 62 | - **Not served:** reading callbacks, aggregate devices, rumble and every other device. Those slots answer `E_NOTIMPL` | 65 | - **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. | 66 | and log the slot once. Controllers and the [keyboard pad](#keyboard-pad) still need SDL3. |
| 64 | 67 | ||
| @@ -70,14 +73,21 @@ The start of the run logs one line with the counts, and each press logs the same | |||
| 70 | [rt] gameinput: press a@40.0 (Scripted pad (Leonida)) | 73 | [rt] gameinput: press a@40.0 (Scripted pad (Leonida)) |
| 71 | ``` | 74 | ``` |
| 72 | 75 | ||
| 73 | A press is logged when the title reads it, so a press the title never reads is not logged. `LEONIDA_INPUT_LOG=0` | 76 | A press is logged at the next reading the title asks for, with the script's time of the press, so a press is logged |
| 74 | turns the `press` lines off. Without `LEONIDA_INPUT_SCRIPT`, the shim serves no devices and answers `E_NOTIMPL` for | 77 | once the title reads its pad again. `LEONIDA_INPUT_LOG=0` turns the `press` lines off. `LEONIDA_INPUT_TRACE=1` |
| 78 | (diagnostic, this shim only) logs what the title asks for: the first 128 `GetCurrentReading`, `GetNextReading` and | ||
| 79 | `GetPreviousReading` calls, then every one that returns a pressed button and every 1000th, the device callbacks and | ||
| 80 | `RegisterDeviceCallback` calls, and the first few calls of each reading method. Without `LEONIDA_INPUT_SCRIPT`, the shim serves no devices and answers `E_NOTIMPL` for | ||
| 75 | every slot past `Release`, as before. | 81 | every slot past `Release`, as before. |
| 76 | 82 | ||
| 77 | `scripts/build_runtime.ps1` builds the shim only on its CMake path, when Visual Studio's C++ CMake tools are | 83 | `LEONIDA_INPUT_FILE=<path>` drives a run whose display takes no keyboard input (a headless session): every line |
| 78 | installed. Its direct-`cl.exe` fallback compiles a fixed file list without the shim and warns about it. | 84 | appended to that file names one button of the script's table (`a`, `down`, ...) and becomes a press at once, held |
| 79 | `make_game.py`'s runtime stage on Windows runs it with `-FetchSdl3`, so a build made the usual way has controller, | 85 | like a scripted one. The file is read again at most every 250 ms. It is for local runs only. |
| 80 | keyboard and mouse input; `--no-sdl3` leaves the download out (an installed SDL3 is still used). | 86 | |
| 87 | `scripts/build_runtime.ps1` (what `make_game.py` runs) builds the shim only on its CMake path, when Visual Studio's | ||
| 88 | C++ CMake tools are installed. Its direct-`cl.exe` fallback compiles a fixed file list without the shim and warns | ||
| 89 | about it. `make_game.py`'s runtime stage on Windows runs it with `-FetchSdl3`, so a build made the usual way has | ||
| 90 | controller, keyboard and mouse input; `--no-sdl3` leaves the download out (an installed SDL3 is still used). | ||
| 81 | 91 | ||
| 82 | ## Mapping | 92 | ## Mapping |
| 83 | 93 | ||
| @@ -339,7 +349,7 @@ line is logged when it takes effect); tracking goes on underneath, so clearing i | |||
| 339 | | `LEONIDA_PROMPTS_SWITCH_MS` | `300` | shortest time between two changes of the active input family, 0..2000 ms | | 349 | | `LEONIDA_PROMPTS_SWITCH_MS` | `300` | shortest time between two changes of the active input family, 0..2000 ms | |
| 340 | | `LEONIDA_GAMEINPUT_THREAD` | `1` | `0` stops the background poll thread; only `rt::gameinput::poll()` then reads the pads (tests) | | 350 | | `LEONIDA_GAMEINPUT_THREAD` | `1` | `0` stops the background poll thread; only `rt::gameinput::poll()` then reads the pads (tests) | |
| 341 | | `LEONIDA_KEYBOARD_PAD` | `1` | the [keyboard pad](#keyboard-pad), read while this process has focus; `always` reads keys whatever has focus; `off` removes it | | 351 | | `LEONIDA_KEYBOARD_PAD` | `1` | the [keyboard pad](#keyboard-pad), read while this process has focus; `always` reads keys whatever has focus; `off` removes it | |
| 342 | | `LEONIDA_INPUT_SCRIPT` | unset | Comma-separated `button@seconds` entries, e.g. `a@2,a@4,start@6`. With SDL3 they drive the keyboard pad (on unless `LEONIDA_KEYBOARD_PAD=off`); 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. | | 352 | | `LEONIDA_INPUT_SCRIPT` | unset | Comma-separated `button@seconds` entries, e.g. `a@2,a@4,start@6`. With SDL3 they drive the keyboard pad (on unless `LEONIDA_KEYBOARD_PAD=off`); 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. | |
| 343 | | `LEONIDA_MOUSE_SENSITIVITY` | `1` | scales how far the mouse moves the keyboard pad's right stick, 0.1..10 | | 353 | | `LEONIDA_MOUSE_SENSITIVITY` | `1` | scales how far the mouse moves the keyboard pad's right stick, 0.1..10 | |
| 344 | 354 | ||
| 345 | SDL's own hints (`SDL_JOYSTICK_*`, see SDL's `SDL_hints.h`) also apply, for example `SDL_JOYSTICK_HIDAPI_PS5=0` to | 355 | SDL'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..42487ed49 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,72 @@ 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 | |||
| 175 | On 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 | ||
| 176 | drew the first world frames: the opening night street and a sunset street with palms, cars and a character, over | ||
| 177 | eight minutes in the world without a GPU hang, at about one frame per six seconds. The runtime was `main` `a73a57e13` | ||
| 178 | with #1914, #1957, #1972, #2044, #2097, #2124, #2129, #2144, #2162, #2195 and #2240 merged; they went into `main` | ||
| 179 | together with this section. Each step below removed a stop that ended every earlier run; they are in the order | ||
| 180 | they were found. | ||
| 181 | |||
| 182 | 1. **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. | ||
| 189 | 2. **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. | ||
| 197 | 3. **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 | That run left out the programs `LEONIDA_SKIP_COMPUTE` named, which kept them out of the journal; the pre-compile | ||
| 202 | now builds them too unless it is given `--skip-listed`. | ||
| 203 | The `pipeline_cache.bin` that `make_game.py`'s pipelines stage writes with `vk_pipeline_check` gave no hits: 0 of | ||
| 204 | 5,526 journal pipeline keys were in its 29,861 objects (9 shader binaries were identical, so the machine code | ||
| 205 | matched and the keys did not). Each of three differences is enough for a miss on RADV: | ||
| 206 | - **The set of shaders:** the runtime's warm-up builds the library's compute programs (`library/index.json`, | ||
| 207 | 2,683 modules); the stage builds the main index and `bvh/`, and only 25 library modules are byte-identical to a | ||
| 208 | main-index one. | ||
| 209 | - **Robustness:** on RADV the runtime enables `robustBufferAccess`, `robustBufferAccess2` and `nullDescriptor`; | ||
| 210 | `vk_pipeline_check` turns `robustBufferAccess` off and leaves robustness2 off. RADV puts the robustness state into | ||
| 211 | every shader stage key, so every pipeline, compute and graphics, misses. | ||
| 212 | - **Layout and subgroup request:** for compute with set-0 bindings (2,244 of the 2,683) the checker builds set 0 | ||
| 213 | from default bindless features and requests the subgroup size without the runtime's full-subgroups flag; RADV | ||
| 214 | hashes the whole set layout and the stage flags. Graphics would miss anyway: the checker pairs each stage with a | ||
| 215 | stub and fixed state, and RADV hashes the full graphics state. | ||
| 216 | 4. **Leave out the ray-tracing programs.** 724 library compute programs have 2 MiB of SPIR-V or more (676 of them | ||
| 217 | ray-tracing resolve). The 89-167 s each in the driver were measured with wave64-emulated packs; with the native | ||
| 218 | pack of step 2 they build in seconds, so compile time is not the reason any more. Measured afterwards on the same | ||
| 219 | machine (RX 7900 XTX, RADV, Mesa 26.3.1, Wine): all 721 such programs of that pack built, 360 of them in 170 s on 32 | ||
| 220 | threads, 2.5-32 s each, the largest (13 MiB) in 28.5 s alone, at a peak of 14 GiB of RAM. Two world runs with all | ||
| 221 | of them in the journal and no skip list (one run per build) took them all from the journal and got no further | ||
| 222 | than runs with the skip list: one stopped submitting after 404 s with the GPU idle, the other lost the device | ||
| 223 | about 214 s in with every queue idle, a loss that also happens with the skip list set | ||
| 224 | ([running.md](running.md#settings-every-platform-needs)). Whether their output is correct is not measured, so the | ||
| 225 | longest runs still leave them out. `LEONIDA_RT_AS=off` drops acceleration-structure builds and copies, and | ||
| 226 | `LEONIDA_SKIP_COMPUTE=<name>,<name>,...` with those programs' `lib_cs_NNNNN` names (picked by module size from | ||
| 227 | `library/index.json`) drops their dispatches at play. The picture then lacks whatever those passes draw. | ||
| 228 | 5. **Keep the title's hang watchdog kicked.** The title exits on purpose (a write to address 0) when its main loop has | ||
| 229 | not reported for 30 s, which a world load under the runtime exceeds. `LEONIDA_TITLE_WATCHDOG=0` defuses it only | ||
| 230 | together with `LEONIDA_TITLE_WATCHDOG_KICK=<trap RVA>,<kick RVA>` (hex; `runtime/src/main.cpp`); the two values are | ||
| 231 | measured locally and never committed. With `=0` alone the loader logs that the watchdog stays armed. | ||
| 232 | |||
| 233 | The rest of that run's environment came from a Linux/Proton report on an RTX 3090: `LEONIDA_ASYNC_PIPELINES=0`, | ||
| 234 | `LEONIDA_DEVICE_TYPE=6`, `LEONIDA_MAP_READBACK=1`, `LEONIDA_TITLE_WINDOWS_MB=4096`, `LEONIDA_FRAME_PACING=1` and | ||
| 235 | `LEONIDA_PRESENT_NO_TEAR=1`. Still wrong after it: frames alternate between white-out, a correct picture and black; | ||
| 236 | some geometry is drawn in the wrong place; VRAM reached 18.3 of 22.3 GB; the run ended on a breakpoint in the title | ||
| 237 | after 12 minutes. | ||
| 238 | |||
| 169 | ## Reporting a result | 239 | ## Reporting a result |
| 170 | 240 | ||
| 171 | Say the machine (OS, GPU and driver, RAM), the commit, the environment switches that differ from the defaults, and | 241 | Say 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..77887d23d --- /dev/null +++ b/docs/running.md | |||
| @@ -0,0 +1,158 @@ | |||
| 1 | # Running the game, per platform and GPU | ||
| 2 | |||
| 3 | How the retail game has been run on each platform and GPU so far: the build, the shader pack, the pipeline | ||
| 4 | pre-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 | |||
| 10 | Paths 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). With wave64 emulation they took 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). With a native wave64 pack compile time is no reason to leave them out: on an | ||
| 27 | RX 7900 XTX (RADV, Mesa 26.3.1, Wine) all 721 such programs of that pack built, 360 of them in 170 s on 32 threads, | ||
| 28 | 2.5-32 s each, the largest (13 MiB) in 28.5 s alone, at a peak of 14 GiB of RAM (measured by us). The pipeline | ||
| 29 | pre-compile builds them with the rest. Dispatched at play (measured by us, one run per condition: RX 7900 XTX 24 GB, | ||
| 30 | `LEONIDA_RT_AS=off`, no skip list, all 721 in the journal), they all came from the journal (2,700 compute | ||
| 31 | pipelines from it against 1,900 with the skip list set; none built in the game) and the load reached the world. | ||
| 32 | One run (a local build of `main` with four then-open pull requests) stopped submitting after 404 s with the GPU idle | ||
| 33 | and no GPU fault; the other (`main` `bd6ba97ab`) lost the device about 214 s in, after a read page fault, with | ||
| 34 | every queue idle in the dispatch markers. The same idle-queue device loss also happens with the skip list set, so | ||
| 35 | it is not shown to come from these programs, and running them got no further than the skip list's best runs | ||
| 36 | (about 11 minutes, ending on a title breakpoint). Whether their output is correct is not measured. Our longest | ||
| 37 | runs used `LEONIDA_SKIP_COMPUTE=<name>,<name>,...` with those programs' names (picked by module size from | ||
| 38 | `<work>/shaders/spirv/library/index.json`), which drops their dispatches at play, and `LEONIDA_RT_AS=off`, which | ||
| 39 | drops acceleration-structure builds. The picture then lacks what they draw. | ||
| 40 | |||
| 41 | ## Linux, Wine, AMD RX 7900 XTX (RADV) | ||
| 42 | |||
| 43 | Measured by us on 2026-11-26: RX 7900 XTX, Ryzen 9 7950X3D, Linux 7.3, Mesa 26.3.1 (RADV), Wine. Details and the | ||
| 44 | reasons behind each step: [linux_proton.md](linux_proton.md#amd-on-linux-what-got-the-world-drawn). | ||
| 45 | |||
| 46 | - **Build:** the clang-cl + xwin cross-build ([testing.md](testing.md#the-windows-runtime-on-linux-under-wine-or-proton)), | ||
| 47 | with SDL3 for the keyboard pad. | ||
| 48 | - **Shaders:** `python -I make_game.py --stages shaders --wave64-emulate off --work <work> --out <out>`. The GPU runs | ||
| 49 | wave64 natively; emulation is not needed. (`auto` picks the same here since llvmpipe no longer decides.) | ||
| 50 | - **Pipeline pre-compile:** `wine <build>/gta6rt.exe --precompile-pipelines --threads 16` with the run's | ||
| 51 | `LEONIDA_SHADERS`, `LEONIDA_PIPELINE_CACHE_DIR` and `LEONIDA_DEVICE_FAULT`, before the first run. It built 3,693 | ||
| 52 | compute pipelines. Not `make_game.py --stages pipelines`: its cache never matches the runtime's driver keys. | ||
| 53 | The pre-compile builds the programs `LEONIDA_SKIP_COMPUTE` names too (`--skip-listed` leaves them out) and ends | ||
| 54 | with one line that counts what it built, what was journaled already and what it left out. | ||
| 55 | - **Driver and OS:** `amdgpu.lockup_timeout=30000,60000,10000,10000` on the kernel command line (the default is | ||
| 56 | 2000 ms; reboot needed). | ||
| 57 | - **Environment:** | ||
| 58 | |||
| 59 | | Setting | Why | | ||
| 60 | |---|---| | ||
| 61 | | `LEONIDA_D3D12=vulkan` | the Vulkan backend | | ||
| 62 | | `LEONIDA_SHADERS=Z:<work>/shaders/spirv` | the native pack | | ||
| 63 | | `LEONIDA_PIPELINE_CACHE_DIR=Z:<cache>/pso` | the journal the pre-compile filled | | ||
| 64 | | `MESA_SHADER_CACHE_DIR=<cache>/mesa`, `MESA_SHADER_CACHE_MAX_SIZE=16G` | RADV's own cache, large enough for the pack | | ||
| 65 | | `LEONIDA_STARTUP_CACHE_CHECKPOINTS=1` | session cache snapshots during the boot | | ||
| 66 | | `LEONIDA_ASYNC_PIPELINES=0` | draws wait for their pipeline instead of being skipped | | ||
| 67 | | `LEONIDA_SERIAL_BIG_COMPILES=0`, `LEONIDA_COMPUTE_WARMUP_MAX_BYTES=8388608` | warm-up limits, as in the NVIDIA report below | | ||
| 68 | | `LEONIDA_RT_AS=off`, `LEONIDA_SKIP_COMPUTE=<list>` | the large ray-tracing programs, left out at play as in our longest runs ([above](#settings-every-platform-needs)) | | ||
| 69 | | `LEONIDA_TITLE_WATCHDOG=0`, `LEONIDA_TITLE_WATCHDOG_KICK=<trap RVA>,<kick RVA>` | the title's hang watchdog ([above](#settings-every-platform-needs)) | | ||
| 70 | | `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 | | ||
| 71 | | `LEONIDA_ARENA_MB=4095`, `LEONIDA_TITLE_WINDOWS_MB=4096`, `LEONIDA_GEOMETRY_MB=6144` | room for the title's buffers in the world | | ||
| 72 | | `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 | | ||
| 73 | | `LEONIDA_DEVICE_FAULT=1` | a device-loss report if the GPU hangs | | ||
| 74 | | `LEONIDA_KEYBOARD_PAD=always` | the keyboard as the pad | | ||
| 75 | |||
| 76 | - **Command:** from `<package>`, `wine <build>/gta6rt.exe --run Z:<exe> --game-dir Z:<package>`. | ||
| 77 | - **What to expect:** menus at 30 frames/s with no in-game compiling; the world after the story load, over eight | ||
| 78 | minutes without a GPU hang, at about one frame per six seconds. | ||
| 79 | - **Known problems:** frames alternate between white-out, a correct picture and black; some geometry is drawn in the | ||
| 80 | wrong place; VRAM reached 18.3 of 22.3 GB; the run ended on a breakpoint (`int3`) in the title after 12 minutes. | ||
| 81 | |||
| 82 | ## Linux, Wine, AMD RDNA2 iGPU (Ryzen 7000, RADV) | ||
| 83 | |||
| 84 | Measured by us on 2026-11-25/26, the same machine's integrated GPU (gfx1036), headless, before the watchdog's KICK | ||
| 85 | was known. The settings that drew the world on the RX 7900 XTX have not been tried here: TBD. | ||
| 86 | |||
| 87 | - **Build, shaders, pipeline pre-compile:** as for the RX 7900 XTX; the iGPU also runs wave64 natively. | ||
| 88 | - **Driver and OS:** the same `lockup_timeout` applies (TBD whether the values above are enough here). | ||
| 89 | - **Environment:** select the iGPU with `MESA_VK_DEVICE_SELECT=1002:164e` and | ||
| 90 | `MESA_VK_DEVICE_SELECT_FORCE_DEFAULT_DEVICE=1`. A cold compute warm-up made the title crawl at 0.12 frames/s behind | ||
| 91 | our own warm-ups; `LEONIDA_COMPUTE_WARMUP_LIVE_MAX_BYTES=131072` holds large warm-ups back while the title submits | ||
| 92 | (191 frames/s in the menus with it, measured on the RX 7900 XTX). | ||
| 93 | - **What to expect:** the boot, the first-run pages and the story load's loading screen (about 1,100 s into a run with | ||
| 94 | a partly warm cache). Every run then ended in the title's watchdog exit, about two minutes into the world load, | ||
| 95 | because only `LEONIDA_TITLE_WATCHDOG=0` was set. World frames: TBD. | ||
| 96 | - **Known problems:** TBD beyond the above. | ||
| 97 | |||
| 98 | ## Linux, Proton, NVIDIA | ||
| 99 | |||
| 100 | Reported by others: [#1608, comment 7184700506](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7184700506) | ||
| 101 | (RTX 3090 24 GB, NVIDIA 590.48.01, GE-Proton11-14, Debian 13). Not run by us. | ||
| 102 | |||
| 103 | - **Build:** clang-cl + xwin cross-build; `main` plus several pull requests and two local changes (listed in the report). | ||
| 104 | - **Shaders:** the main corpus, the library and FSPX with llvm-mc 23.1.6. Wave64 emulation: TBD from the report (it is | ||
| 105 | needed on NVIDIA's 32-wide subgroups; `auto` turns it on there). | ||
| 106 | - **Pipeline pre-compile:** caches warm from two earlier runs; no separate pre-compile is reported. | ||
| 107 | - **Driver and OS:** TBD. | ||
| 108 | - **Environment:** `LEONIDA_ASYNC_PIPELINES=0`, `LEONIDA_RT_AS=off`, `LEONIDA_SKIP_COMPUTE=<the 724 programs>`, | ||
| 109 | `LEONIDA_DEVICE_TYPE=6`, `LEONIDA_TITLE_WATCHDOG=0`, `LEONIDA_MAP_READBACK=1`, `LEONIDA_HOST_IMAGE_COPY=0`, | ||
| 110 | `LEONIDA_ARENA_MB=4095`, `LEONIDA_TITLE_WINDOWS_MB=4096`, `LEONIDA_SERIAL_BIG_COMPILES=0`, `LEONIDA_FRAME_PACING=1`, | ||
| 111 | `LEONIDA_PRESENT_NO_TEAR=1`. The report gives the reason for the skip list only: without it the world start waits | ||
| 112 | hours on the ray-tracing programs; with asynchronous pipelines instead the screen stayed black. Those compile times | ||
| 113 | are the report's pack; a native wave64 pack builds them in seconds each ([above](#settings-every-platform-needs)). | ||
| 114 | Where they still take minutes, `gta6rt --precompile-pipelines --big-threads N` bounds how many build at once (each | ||
| 115 | held about 3.5 GB of host memory on an RTX 4070 Ti) and `--skip-listed` leaves the listed ones out. | ||
| 116 | - **Command:** TBD. | ||
| 117 | - **What to expect:** the opening night street from about 650 s, at 0.1-0.2 frames/s, no device loss through 934 s. | ||
| 118 | The black stretch before it is graphics pipelines of 1-2.6 MB SPIR-V compiling one at a time, 5-10 s each. | ||
| 119 | - **Known problems:** nothing ray-traced is in the picture. | ||
| 120 | |||
| 121 | ## Windows, NVIDIA | ||
| 122 | |||
| 123 | Reported by others: [#2019](https://github.com/ubiquitarianism/leonida/issues/2019) (RTX 5090 32 GB, driver 616.92, | ||
| 124 | Windows 11). Not run by us. | ||
| 125 | |||
| 126 | - **Build:** `scripts/build_runtime.ps1` with SDL3, RelWithDebInfo. | ||
| 127 | - **Shaders:** `make_game.py --stages check,shaders,runtime` (26,503 shaders translated); wave64 emulation as `auto` | ||
| 128 | decides (on for NVIDIA). | ||
| 129 | - **Pipeline pre-compile:** TBD. | ||
| 130 | - **Driver and OS:** `TdrDelay` and `TdrDdiDelay` raised to 60 s, after which an 8.9 s pipeline build no longer | ||
| 131 | reset the device. | ||
| 132 | - **Environment:** `LEONIDA_D3D12=vulkan`, `LEONIDA_KEYBOARD_PAD=always`; the rest TBD. | ||
| 133 | - **Command:** `gta6rt.exe --first-run-ui game_scarlett_master.exe` from the package folder. | ||
| 134 | - **What to expect:** the first-run UI, then the title's watchdog exit at 145-204 s. With `LEONIDA_TITLE_WATCHDOG=0` | ||
| 135 | (before the KICK variable existed) the boot went on at about 24 frames/s and the machine then bugchecked | ||
| 136 | (`CRITICAL_PROCESS_DIED`) before a world frame. With the KICK values: TBD. | ||
| 137 | - **Known problems:** TBD. | ||
| 138 | |||
| 139 | ## Windows, AMD | ||
| 140 | |||
| 141 | TBD: 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 | ||
| 142 | under AMD's Windows driver, `make_game.py`'s `auto` translates native wave64, because that driver crashes on many | ||
| 143 | emulated wave64 compute pipelines (#857). `TdrDelay` applies as for NVIDIA. | ||
| 144 | |||
| 145 | ## Intel | ||
| 146 | |||
| 147 | TBD. | ||
| 148 | |||
| 149 | ## macOS (MoltenVK) | ||
| 150 | |||
| 151 | TBD. | ||
| 152 | |||
| 153 | ## Reporting | ||
| 154 | |||
| 155 | Post a run in the coordination issue, with the fields of these sections: machine (OS, GPU, driver, RAM), the commit, | ||
| 156 | how the shaders were made, the pipeline pre-compile, the OS and driver settings, every `LEONIDA_*` variable that | ||
| 157 | differs from the defaults (never the watchdog's RVA values), and how far the run got with its frame rate. Keep logs, | ||
| 158 | traces 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 | ||
| 176 | The game executable imports two functions from `xg_xs.dll`, the console's texture layout library: | 176 | The 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 | |||
| 203 | unimplemented imports is reached by the TLS callbacks or the `DllMain`s. | 203 | unimplemented imports is reached by the TLS callbacks or the `DllMain`s. |
| 204 | 204 | ||
| 205 | The executable's audio imports `xapu.dll` (`XApuConnect`, `XApuDequeueResult`, `XApuDisconnect`, | 205 | The 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 |
| 208 | read 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 |
| 209 | a 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 |
| 210 | Commands are accepted and not processed, so the audio stays silent. A stream open (type 1) and a stream close | 210 | count, 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 | 211 | input. Activate, process, deactivate and reset commands are copied from the title's stack command, and each queues one |
| 212 | result arrives. `XDspActivate` writes its two outputs as pointers to zeroed memory, which the title reads as "command | 212 | result in order. A process command decodes its Opus packet through `runtime/opus_decoder` (Rust over the BSD-3-Clause |
| 213 | done" 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; |
| 214 | buffer size (128 stream slots), the two results and the zeroed DSP status are hypotheses, explained in the file. | 214 | without 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. | 216 | memory, which the title reads as "command done" after each `XDspSubmitCommand`; the DSP stays silent. `xapu_chad_test` |
| 217 | covers the layouts, the queue and the silent path; `xapu_opus_test` the decoded path. With `--trace`, the first call of | ||
| 218 | each, and the first command of each type, is an `audio_queue` event. | ||
| 217 | The 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`. | 219 | The 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 | ||
| 219 | What this does not show: `--run` has not been run, so the entry point has not been called and no import is known to be | 221 | What this does not show: `--run` has not been run, so the entry point has not been called and no import is known to be |