diff options
| author | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-26 16:55:04 -0500 |
|---|---|---|
| committer | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-26 16:55:04 -0500 |
| commit | df92abca8ee2a8f9093efea7fcaa4dadc3ddaebc (patch) | |
| tree | 97ef8f95544fe263049d3f7360823f16100de209 /docs | |
| parent | 49a0b69fcdb80db1f2a44ce7ca0ab8dfdec1e403 (diff) | |
| parent | e5a7c8942678b323f655939c81f5d8855d20c248 (diff) | |
Merge main e5a7c8942 into shadow-aliased-guard (#1867)
One conflict, runtime/README.md: this branch rewrote the LEONIDA_SHADOW_ALIAS_MS
row, main (#2163) added the LEONIDA_SHADOW_KEEP row after it. Both rows kept;
the keep row's "aliased" now reads "aliased while they can't be guarded at every
address", since aliased pages are no longer copied without a sign of a write.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 | 317 | ||||
| -rw-r--r-- | docs/design.md | 8 | ||||
| -rw-r--r-- | docs/directstorage.md | 29 | ||||
| -rw-r--r-- | docs/gameinput.md | 22 | ||||
| -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, 612 insertions, 44 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..45d4b4be4 100644 --- a/docs/d3d12_vulkan.md +++ b/docs/d3d12_vulkan.md | |||
| @@ -680,9 +680,13 @@ side inwards: | |||
| 680 | covers a full 2048-sampler D3D12 heap plus room for literal and static S#s. | 680 | covers a full 2048-sampler D3D12 heap plus room for literal and static S#s. |
| 681 | - 2D images: up to 65536. | 681 | - 2D images: up to 65536. |
| 682 | - storage arrays: up to 4096 each, capped by their dimension's sampled array or by 256 for storage-only 1D arrays. | 682 | - storage arrays: up to 4096 each, capped by their dimension's sampled array or by 256 for storage-only 1D arrays. |
| 683 | - 2D-array images up to 16384, 3D and 1D images up to 4096 each (the title streams more cube maps, texture | 683 | - 2D-array, 3D and 1D images: up to 65536 each, as many as 2D, grown together (one count for the three while the |
| 684 | arrays and 1D lookups than the defaults hold: each distinct T# of one takes its own index, and a native boot | 684 | limits stop them short of it), so no dimension is favoured. A texture keeps an index for each distinct T# of |
| 685 | filled the 1024 2D-array and 256 1D indices during the story load). | 685 | it for as long as it lives, and which dimensions its textures have is the title's choice: a native boot |
| 686 | filled the default 1024 2D-array and 256 1D indices during the story load, and world runs filled the 4096 1D | ||
| 687 | indices of the sizes before this with 4092 T#s of 4090 live 1D textures. The bound is memory, not the | ||
| 688 | device's limits (RADV allows 8388606 sampled images): every element of every array is in each generation's | ||
| 689 | descriptor pool, used or not. | ||
| 686 | 690 | ||
| 687 | Growth leaves 64 descriptors of each limit to the other sets of a pipeline layout. It also stays within | 691 | Growth leaves 64 descriptors of each limit to the other sets of a pipeline layout. It also stays within |
| 688 | `maxPerSetDescriptors`, which never shrinks the default counts, because a layout past it may still be | 692 | `maxPerSetDescriptors`, which never shrinks the default counts, because a layout past it may still be |
| @@ -698,9 +702,18 @@ side inwards: | |||
| 698 | shader reads the fallback. `d3d12_descriptor_test` then fills each short array to its last index and checks that | 702 | shader reads the fallback. `d3d12_descriptor_test` then fills each short array to its last index and checks that |
| 699 | the next view and sampler are refused. | 703 | the next view and sampler are refused. |
| 700 | The MS arrays keep their default counts. On an RTX 5070 (driver 621.24, 1048576 of each type | 704 | The MS arrays keep their default counts. On an RTX 5070 (driver 621.24, 1048576 of each type |
| 701 | and 4000 samplers) the set has 65536 2D images, 3936 samplers, 16384 2D-array, 4096 3D and 4096 1D images and | 705 | and 4000 samplers) the set has 65536 2D, 2D-array, 3D and 1D images each, 3936 samplers and 4096 storage indices |
| 702 | 4096 storage indices in each dimension: 152929 descriptors, 5-10 MiB at 32-64 bytes a descriptor. The device prints the counts it chose, and | 706 | in each dimension: 325729 descriptors with the MS pairs, 10-20 MiB at 32-64 bytes a descriptor. RADV (Mesa 26.3, |
| 703 | `bindless_sizing_test` checks the rules on synthetic limits. | 707 | the Raphael iGPU and the RX 7900 XTX) and llvmpipe get the same image counts and 4096 samplers. The device prints |
| 708 | the counts it chose (`bindless set:`), `bindless_sizing_test` checks the rules on synthetic limits, and | ||
| 709 | `vk_bindless_dimensions_test` reads 5000 live 1D, 2D-array and 3D images each through their indices in a set | ||
| 710 | sized from the device's own limits. | ||
| 711 | - A T# the title writes into a console descriptor heap that set 0 has no room for is refused, and counted in the | ||
| 712 | heap's `unbound T#s by reason` line, as `the bindless array of the T#'s dimension is full` (or `the bindless | ||
| 713 | storage arrays of the T#'s dimension are full` for a UAV whose dimension has free indices only above the shorter | ||
| 714 | storage arrays), not as `no view for the T#'s format or range`. The first such refusal of a dimension also logs | ||
| 715 | `a bindless image array is full; dimension N (name)` with the indices, the T#s and textures that hold them and how | ||
| 716 | many of those textures are still registered at their address (a texture's indices go back when it goes). | ||
| 704 | - An image view has one index in its dimension (2D, 2D array, 3D, 1D, 2DMS, 2DMS array or 1D array), shared by the | 717 | - An image view has one index in its dimension (2D, 2D array, 3D, 1D, 2DMS, 2DMS array or 1D array), shared by the |
| 705 | bindings for that dimension. The runtime adds sampled-image bindings in pairs for 2DMS and 2DMS array: | 718 | bindings for that dimension. The runtime adds sampled-image bindings in pairs for 2DMS and 2DMS array: |
| 706 | 20/21 for floating-point and normalized color, 22/23 for unsigned integers, and 24/25 for signed integers. | 719 | 20/21 for floating-point and normalized color, 22/23 for unsigned integers, and 24/25 for signed integers. |
| @@ -961,7 +974,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 | 974 | 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, | 975 | 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, | 976 | 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`. | 977 | wireframe and non-triangle PSOs are refused (a mesh PSO needs no topology type: its module has to output |
| 978 | 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 | 979 | 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 | 980 | 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 | 981 | device does not expose Tier 3: the Xbox `SV_InnerCoverage` input mapping has not been confirmed. See |
| @@ -1301,7 +1315,8 @@ and any validation error fails them. | |||
| 1301 | - `indirect_clamp_test`: the `ExecuteIndirect` argument clamp pass itself (section 4.7), with no game files: every | 1315 | - `indirect_clamp_test`: the `ExecuteIndirect` argument clamp pass itself (section 4.7), with no game files: every |
| 1302 | argument kind (draw, draw indexed, dispatch, mesh dispatch) and the counted variants, in-range records | 1316 | argument kind (draw, draw indexed, dispatch, mesh dispatch) and the counted variants, in-range records |
| 1303 | bit-identical, garbage records bounded, records and counts past `max_command_count` empty, and the per-batch work | 1317 | bit-identical, garbage records bounded, records and counts past `max_command_count` empty, and the per-batch work |
| 1304 | budget saturating; clean SKIP without a Vulkan device. | 1318 | budget saturating; dispatch records bounded by the device's `maxComputeWorkGroupCount` (70 000 x 1 x 1 kept and run |
| 1319 | where the device allows it, cut and counted where it does not); clean SKIP without a Vulkan device. | ||
| 1305 | - `d3d12_gcl8_test`: the public `ID3D12GraphicsCommandList8` surface: `QueryInterface` for its IID, | 1320 | - `d3d12_gcl8_test`: the public `ID3D12GraphicsCommandList8` surface: `QueryInterface` for its IID, |
| 1306 | `OMSetFrontAndBackStencilRef(1, 2)` with the recorded values, and the reference count around the query. It | 1321 | `OMSetFrontAndBackStencilRef(1, 2)` with the recorded values, and the reference count around the query. It |
| 1307 | creates only an allocator and a list, so it needs no GPU or Vulkan loader. | 1322 | creates only an allocator and a list, so it needs no GPU or Vulkan loader. |
| @@ -1697,6 +1712,21 @@ The copies: | |||
| 1697 | cannot fit between the title's address reservations can use a separate mapped buffer. The buffer's device address | 1712 | 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. | 1713 | 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. | 1714 | `LEONIDA_STREAM_BUFFER_WINDOWS=0` requires the window to fit in the arena. |
| 1715 | - **What the GPU wrote goes back.** The same return copy serves slot-133 shadows (a buffer the driver would not | ||
| 1716 | import, a compute result the title reads again): the ranges are recorded through the alias of the buffer's pages and | ||
| 1717 | 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 | ||
| 1718 | the copy and the title would never see it ([#1537](https://github.com/ubiquitarianism/leonida/issues/1537), the | ||
| 1719 | `WRITE_INVALID` stop at the world start). Every title range a submission's bindings reach is kept, and the next | ||
| 1720 | refresh copies those ranges from the copy to the title's pages *before* it copies the pages forward, so a page the | ||
| 1721 | title itself wrote in between keeps the title's newer bytes and its GPU result is dropped. The copy back asks the | ||
| 1722 | write watch first (the refresh's own asking comes after it, so a hot page's last answer is a submission old), passes | ||
| 1723 | over pages whose mapping changed, that a kernel write may be filling or that xmem maps at another address too, and | ||
| 1724 | writes only the 256-byte pieces where the copy differs from the title's bytes: a read-only view writes nothing and | ||
| 1725 | its pages stay guarded. Up to 8,192 ranges and 64 MiB a submission (a V# has no read/write bit, so every view | ||
| 1726 | reached is compared; past the caps the ranges are left behind, logged once). `LEONIDA_TITLE_WRITEBACK=0` turns it off. A batch is fenced: it is kept with the ticket | ||
| 1727 | of the submission that will use it and copied back only when the context reports that ticket retired, so a range | ||
| 1728 | another submission is still writing is never read half done. A queue held deep (console ordering) can leave batches | ||
| 1729 | 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 | 1730 | - 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 | 1731 | 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 | 1732 | made either, the view is written with **no base and no records** — loads return 0 and stores are dropped. A raw |
| @@ -1719,6 +1749,19 @@ The copies: | |||
| 1719 | encoding reuses only an independently established geometry view. An explicit table or placed SRV can | 1749 | 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, | 1750 | establish that view. The Vulkan memory probe reports populated views, payload and reserved bytes, |
| 1721 | upload totals, cap refusals and allocation failures. | 1751 | upload totals, cap refusals and allocation failures. |
| 1752 | - **Where the copies live**: device-local memory through the BAR by default. `LEONIDA_GEOMETRY_HOST=1` puts them | ||
| 1753 | in system memory outside VRAM (write-back where the device offers a cached host type, `=2` write-combined), | ||
| 1754 | as VIctory keeps its copies of title memory (approach only). In a world run on the RX 7900 XTX the copies held | ||
| 1755 | 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, | ||
| 1756 | so a geometry-heavy pass can take longer; measure frame time with and without it before making it a default. | ||
| 1757 | - **When a copy goes**: a view is retired when its title range is freed, decommitted or unmapped. A remap of | ||
| 1758 | physical pages retires nothing: the copies follow the new pages through the refresh. A retired | ||
| 1759 | view leaves the lookups at once, its alias ranges and translated heap slots are invalidated, its stream-pool | ||
| 1760 | extent is forgotten, and its memory is freed only after every ExecuteCommandLists replay in progress at the | ||
| 1761 | retirement has recorded its submissions and those have completed (`kAfterExecutes`). Before it leaves the | ||
| 1762 | refresh it is copied once more from its pages if they are still readable (a heap block freed in memory that | ||
| 1763 | stays committed). The next view of the range makes a new copy. | ||
| 1764 | `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` | 1765 | - **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 | 1766 | (`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: | 1767 | physical-page windows), the kernel says (`GetWriteWatch` with reset, its answers kept for every copy over the page: |
| @@ -1730,6 +1773,15 @@ The copies: | |||
| 1730 | write-fault handler waits for the trackers' locks while the faulting thread may hold the process heap's lock (the | 1773 | 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 | 1774 | 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. | 1775 | the runtime's own (`leonida::host_heap`), never the process heap. |
| 1776 | - **What the GPU wrote into a copy stays** until the title changes the bytes under it. Some pages are copied at | ||
| 1777 | every refresh without a sign that the title wrote them (mapped at two addresses, left writable, reopened with the | ||
| 1778 | 64 KiB around a written page, write-watched or pinned); copied whole, they overwrote a value a compute program had | ||
| 1779 | stored in the copy for the next frame with the title's unchanged bytes, so it read back as the title's old value | ||
| 1780 | every other frame. `ShadowPages` keeps a 64-bit sum per 256-byte piece of the bytes it copied last | ||
| 1781 | (`runtime/src/shadow_keep.h`) and copies a piece only when the title's bytes differ; a piece zeroed because its page | ||
| 1782 | went away is copied again in full once it comes back. Limit: a title that writes the same bytes again to reset a | ||
| 1783 | value the GPU changed is not seen (that needs the GPU's writes to reach the title's pages). `LEONIDA_SHADOW_KEEP=0` | ||
| 1784 | 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`, | 1785 | - **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 | 1786 | `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. | 1787 | 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 +1857,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 | 1857 | 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. | 1858 | texture coverage and the game's use of tile streaming remain open. |
| 1807 | 1859 | ||
| 1860 | **Diagnostics for descriptors the title builds itself** (all off by default, logging only unless said otherwise): | ||
| 1861 | |||
| 1862 | - `LEONIDA_UNKNOWN_TSHARP=1`: one line for each distinct base address a title-written T# names with no texture there | ||
| 1863 | (its shape, the tiling bits and whether the address is title memory), up to 300 addresses, and every 8192 such | ||
| 1864 | lookups a summary by format, type and tiling. | ||
| 1865 | - `LEONIDA_UNBACKED_VSHARP=1`: the buffer V#s `fix_vsharp` writes empty because nothing backs their base; one line for | ||
| 1866 | each of the first 120 distinct bases and every 8192 a summary by 4 GiB range of the base. | ||
| 1867 | - `LEONIDA_UPLOAD_LOG=1` (`d3d12_xs_device.cpp`): each upload chunk (CPU base, device address, size) and the first 96, | ||
| 1868 | then every 8192nd, `AllocateUploadMemory` result as an offset into its chunk. | ||
| 1869 | - `LEONIDA_UPLOAD_ALIAS=1` (an experiment, changes behaviour): enters each upload chunk's CPU range in the title VA | ||
| 1870 | table, so a V# the title wrote with the CPU pointer `AllocateUploadMemory` handed it is rewritten to the chunk | ||
| 1871 | instead of left empty. A chunk below the arena needs `LEONIDA_IMPORT_BELOW_ARENA=1` as well. | ||
| 1872 | |||
| 1873 | #### Address guard (`LEONIDA_ADDRESS_GUARD=1`, `rdna2spirv.py --address-guard`) | ||
| 1874 | |||
| 1875 | **Prototype, off by default.** | ||
| 1876 | |||
| 1877 | **Why.** The layer rewrites the addresses it can see: root views, the V#s it writes, and the V#s the title writes into | ||
| 1878 | shader-visible heaps. It writes an empty V# when nothing backs an address (above). The translator checks a V#'s | ||
| 1879 | record count but not its base. Any other address becomes `heap_base` plus an arbitrary value: | ||
| 1880 | - a V# a shader builds in SGPRs from data; | ||
| 1881 | - a raw `global_`/`flat_` address (530 of the 26,503 shaders of package 1.0.2.1, 69 of the 2,684 pipeline-library | ||
| 1882 | programs); | ||
| 1883 | - a stale or offset-like value. | ||
| 1884 | |||
| 1885 | On RADV such an access page-faults. Two RX 7900 XTX runs (Mesa 26.3.1, under Wine) ended with the same sequence: | ||
| 1886 | - a `gfxhub` fault from client TCP with PERMISSION_FAULTS 0x3; | ||
| 1887 | - a compute-ring timeout and "MES failed to respond"; | ||
| 1888 | - a MODE1 reset ("VRAM is lost"). | ||
| 1889 | |||
| 1890 | Both faults were 4.8 GiB and 20 GiB above `heap_base`, past the arena's end. | ||
| 1891 | |||
| 1892 | "Inside the arena" is not the right bound. Several buffers are legitimately outside it, at a positive offset from | ||
| 1893 | `heap_base` (a negative one with `LEONIDA_IMPORT_BELOW_ARENA=1`): | ||
| 1894 | - geometry copies; | ||
| 1895 | - upload and readback buffers; | ||
| 1896 | - imported title memory; | ||
| 1897 | - separate window buffers. | ||
| 1898 | |||
| 1899 | The guard checks each access against what the runtime actually backs. An access that fails reads 0 and drops its | ||
| 1900 | store, so a wild address never reaches the GPU. The overall process follows VIctory | ||
| 1901 | ([`crates/victory-gpu/src/memory.rs`](https://github.com/marvisak/victory), GPL-3.0). Its page table of 64 KiB pages | ||
| 1902 | routes every computed address, and memory no copy holds reads 0 and takes no writes. The structure below is our own: | ||
| 1903 | VIctory's table names descriptor views, this one is a bitmap over device addresses. | ||
| 1904 | |||
| 1905 | **Structure: a two-level page table of 4 KiB pages over the 48-bit offset space, behind an arena compare.** The | ||
| 1906 | check works on the heap offset, the sign-extended 48-bit value `Gen.host_addr` adds to `heap_base`: | ||
| 1907 | - **Level 1:** 65,536 words indexed by offset bits 47..32. Each word names the level-2 block of one 4 GiB chunk. | ||
| 1908 | - **Level 2:** blocks of 32,768 words, one bit per 4 KiB page (bits 31..12). | ||
| 1909 | - **Two fixed blocks:** block 0 is empty and block 1 is full; allocated blocks start at 2. | ||
| 1910 | - **Size:** the table is a host-visible buffer of its own, 256 KiB plus 128 KiB per block (8.25 MiB for 62 blocks). | ||
| 1911 | |||
| 1912 | Why this structure: | ||
| 1913 | - **Pages of 4 KiB** are the GPU's own mapping granularity. A page any byte of a backing touches is mapped as a whole, | ||
| 1914 | so marking pages outward is exact for faults. A 64 KiB page would mark memory that may not be mapped. | ||
| 1915 | - **Level 1 by 4 GiB chunk** covers the whole signed 48-bit space (negative offsets index from 0x8000 up). A real run | ||
| 1916 | touches a handful of chunks, so the table stays small. | ||
| 1917 | - **Other structures cost more per access.** A sorted range table needs a binary search: about 10 dependent loads for | ||
| 1918 | a thousand backings, against 2 here. A coarse region bitmap plus a fine range table needs a search in the fine part. | ||
| 1919 | - **The arena needs no lookup.** It is one fully bound `VkBuffer`, so any offset below its size passes on a compare. | ||
| 1920 | That is the common case: descriptor heaps, default-heap buffers and windows in the arena. | ||
| 1921 | |||
| 1922 | **The header.** It sits at arena offset `0x70000`, after the zero page and the quad indices, and holds: | ||
| 1923 | - a 64-bit magic (`"LGUARD01"`); | ||
| 1924 | - the arena's size (the compare's limit); | ||
| 1925 | - the table's address minus `heap_base`; | ||
| 1926 | - a refusal count and the last refused offset, which the shaders write. | ||
| 1927 | |||
| 1928 | Two sinks follow the header: `0x71000` (zero area, what refused loads read) and `0x78000` (dump area, where refused | ||
| 1929 | stores and atomics go). None of `[0x70000, 0x80000)` is handed out. With `LEONIDA_ARENA_NULL_MB` the range lies in the | ||
| 1930 | null region, so its offset never moves. `runtime/src/address_guard.h` and `tools/address_guard.py` (the Python | ||
| 1931 | reference) hold the format. | ||
| 1932 | |||
| 1933 | **Each access.** `Gen.host_addr` takes the access kind (load, store or atomic) and its span. Under `--address-guard` | ||
| 1934 | it calls one function per module, `%guard_fn`, which is straight-line at the call site, so no caller's block | ||
| 1935 | structure changes. The function computes `end = offset + span - 1` and then decides: | ||
| 1936 | - **Passes on a compare:** the runtime's guard is off (no magic), or `offset` and `end` are both below the limit. The | ||
| 1937 | result is `heap_base + offset`. The cost is a 64-bit add, two 64-bit compares and a select. | ||
| 1938 | - **Otherwise, a lookup:** the bits of the pages of `offset` and of `end`. That is two independent pairs of dependent | ||
| 1939 | 32-bit loads (level 1, then level 2). | ||
| 1940 | - **Refused:** an access whose bits are not both set adds 1 to the header's count, writes its offset, and goes to the | ||
| 1941 | zero area (a load) or the dump area (a store or atomic), at its offset within its page. Alignment is kept, and every | ||
| 1942 | span fits inside a sink. | ||
| 1943 | - **Atomics** run on the dump area, and their returned value is replaced by 0 (`Gen.guard_zero`). The CAS loops (float | ||
| 1944 | min/max, inc/dec) end there too, as on any other memory. | ||
| 1945 | |||
| 1946 | The entry block reads the header's first six dwords once per invocation, from the arena, so that read is always | ||
| 1947 | backed. When the base is uniform, as for `s_load`, `s_buffer_load` and a V# from SGPRs plus a uniform offset, the | ||
| 1948 | compiler keeps the whole check scalar: one check per instruction, not per lane. A per-lane address (`global_` with a | ||
| 1949 | VGPR address, `offen`/`idxen`) is checked per lane, and the slow path runs only for lanes outside the arena. | ||
| 1950 | |||
| 1951 | **What is checked.** Every `heap_base` access goes through `host_addr`: | ||
| 1952 | - buffer loads and stores (dword, sub-dword, typed, format; swizzled spans are computed at run time); | ||
| 1953 | - `global_` loads, stores, sub-dword and atomics; | ||
| 1954 | - buffer atomics, `_x2` included; | ||
| 1955 | - `s_load` and `s_buffer_load`; | ||
| 1956 | - the BVH node reads of `image_bvh*_intersect_ray` (span by node type). | ||
| 1957 | |||
| 1958 | These are not checked: | ||
| 1959 | - images (T#s go through the hash table, not an address); | ||
| 1960 | - LDS; | ||
| 1961 | - the `--mesh-compute` output buffer (a runtime address); | ||
| 1962 | - `s_getpc` code reads. | ||
| 1963 | |||
| 1964 | The translator does not translate `flat_` instructions (they raise `Unsupported`), so none reaches memory today. A | ||
| 1965 | translation added later must go through `host_addr` like `global_` does. | ||
| 1966 | |||
| 1967 | **Keeping the table current.** The spans are the same backings the console heap pass's backed table uses | ||
| 1968 | (`update_gpu_backed`): | ||
| 1969 | - every `gpu_backings` entry outside the arena (upload and readback buffers, imports, slot-133 buffers, windows | ||
| 1970 | outside the arena); | ||
| 1971 | - the geometry copies' blocks; | ||
| 1972 | - the separate window buffers' blocks. | ||
| 1973 | |||
| 1974 | `update_address_guard` runs in the queue's `before_execute`, after the heap refresh, the windows and the geometry | ||
| 1975 | copies. It differs from that table in four ways: | ||
| 1976 | - It rebuilds whenever `backing_generation` or a block layout changed, with no 100 ms limit, because a backing made | ||
| 1977 | since the last submission must not read 0. | ||
| 1978 | - It writes only the words that changed, level 2 before level 1. | ||
| 1979 | - A chunk keeps its block for good, so a submission still in flight never reads a block that now means another chunk. | ||
| 1980 | - When the 62 blocks run out, a new chunk gets the full block (unchecked, as without the guard), and that is logged. | ||
| 1981 | |||
| 1982 | A release clears its bits at the next submission. D3D12 forbids releasing memory the GPU still uses, so only a wild | ||
| 1983 | access in flight at that moment could still pass. | ||
| 1984 | |||
| 1985 | **Cost per access:** | ||
| 1986 | - **Fast path:** about 8 scalar or vector ALU operations. | ||
| 1987 | - **Outside the arena:** about 40 operations and 4 loads, from a table small enough to stay in cache. | ||
| 1988 | - **Per invocation:** 6 uniform header loads. | ||
| 1989 | - **Per submission (runtime):** nothing until a backing changes, then a rebuild of the used blocks (128 KiB each) | ||
| 1990 | and a diff. | ||
| 1991 | |||
| 1992 | **Switches.** | ||
| 1993 | - `--address-guard` records `"address_guard": true` in `index.json`. | ||
| 1994 | - `LEONIDA_ADDRESS_GUARD=1` makes the runtime reserve the range, create the table and write the header. | ||
| 1995 | - Either alone does nothing: a guarded module on a runtime without the guard finds no magic, and every access passes | ||
| 1996 | after one compare. | ||
| 1997 | - Without the flag the module is byte for byte what it was. | ||
| 1998 | |||
| 1999 | **What a run with the guard shows.** | ||
| 2000 | - One line when the device is made: `[rt] d3d12: address guard on ...`. | ||
| 2001 | - At most one line a second: `[rt] d3d12: address guard: N access(es) refused so far (+k), the last at heap offset | ||
| 2002 | 0x...`. Each refusal is a wild access that would have reached the GPU. The offset says where to look (above the | ||
| 2003 | arena's end, as in the two faults). | ||
| 2004 | - A run that reset the GPU before should keep going, with wrong pixels where a refused access mattered. | ||
| 2005 | |||
| 2006 | **Risks and open points.** | ||
| 2007 | - A refused access that mattered (a backing the layer never registered) now reads 0 instead of faulting. That is | ||
| 2008 | silent apart from the count. | ||
| 2009 | - An access is checked as a whole. A multi-dword load whose first dwords are inside a V# and a backing, but whose | ||
| 2010 | last dword is past both on an unbacked page, reads 0 in full. | ||
| 2011 | - The table is read through the GPU's caches. A page whose bit changes while a submission is in flight can be seen | ||
| 2012 | either way by that submission. | ||
| 2013 | - Sparse buffers outside the arena are guarded only if they are registered as backings. | ||
| 2014 | |||
| 2015 | **Checked:** | ||
| 2016 | - `tests/semantic/test_address_guard.py`: the fixture `cs_address_guard` with the guard on, with it off at run time | ||
| 2017 | and without the flag, through `spirv_mini_interp`; the kind and span of each instruction family; the table model; | ||
| 2018 | the constants shared by the translator, the runtime and `tools/address_guard.py`. | ||
| 2019 | - `runtime/test/address_guard_test.cpp`: the page table, incremental writes, negative offsets, wrap, chunks and | ||
| 2020 | overflow. | ||
| 2021 | - `scripts/run_address_guard_gpu_test.py`: the fixture on a 2 MiB heap whose table backs one page outside the | ||
| 2022 | "arena". Every address it touches is inside the buffer, so no run can fault. With the guard on, the refused loads | ||
| 2023 | read 0 although memory is there, the store and the atomic land in the dump area and the count is 6. With the guard | ||
| 2024 | off, the same module reads that memory. It passed on lavapipe (Mesa 26.3.1). | ||
| 2025 | - Corpus (package 1.0.2.1, 2026-11-26): | ||
| 2026 | - `--shard 0/8` of the shaders: 3,313 translated and 3,313 `spirv-val`-valid, with the guard and without. | ||
| 2027 | - The pipeline library: 2,683 of 2,684 translated and valid, with the guard and without (the same one fails | ||
| 2028 | either way). | ||
| 2029 | - Without the flag, every module is byte for byte the same as before the change. | ||
| 2030 | - With it, the SPIR-V grows by 1.8% (shaders) and 1.6% (library). | ||
| 2031 | |||
| 1808 | ### 3.4 Descriptor heaps and the bindless model | 2032 | ### 3.4 Descriptor heaps and the bindless model |
| 1809 | 2033 | ||
| 1810 | The game can use D3D12 descriptors in three ways, and the layer must handle all of them: | 2034 | The game can use D3D12 descriptors in three ways, and the layer must handle all of them: |
| @@ -1874,8 +2098,18 @@ The game can use D3D12 descriptors in three ways, and the layer must handle all | |||
| 1874 | heap pointers read by the mesh and pixel stages after a rebind. `d3d12_mesh_test` checks the recorded dwords | 2098 | heap pointers read by the mesh and pixel stages after a rebind. `d3d12_mesh_test` checks the recorded dwords |
| 1875 | for a vertex draw, a resource-only rebind, a signature ending at s30 and one on the s0 layout. | 2099 | for a vertex draw, a resource-only rebind, a signature ending at s30 and one on the s0 layout. |
| 1876 | Set `LEONIDA_GRAPHICS_DIRECT_HEAPS=0` to restore the previous draw arguments. | 2100 | Set `LEONIDA_GRAPHICS_DIRECT_HEAPS=0` to restore the previous draw arguments. |
| 1877 | Missing console V# backing leaves a settled zero descriptor. Every 32 submissions a heap probes up to | 2101 | Missing console V# backing leaves a zero descriptor in the copy. Each V# half of a console resource heap's copy |
| 1878 | eight of these slots in round-robin order, including independent UAV-counter failures. | 2102 | (the buffer V# and the UAV counter) has a record in host RAM of what it resolved to: the title's base and span, |
| 2103 | the device address its copy names, and whether it resolved or waits (`src/console_heap_slot_records.h`, written | ||
| 2104 | only by `fix_console_slot`). Two indexes find the halves near a range, by base and by target, per power-of-two | ||
| 2105 | span class and 64 KiB-or-larger granule. Releases (a backing, a title-window or geometry block), alias ranges | ||
| 2106 | removed or replaced (`TitleVaAliases` tells its listeners as it happens, `forget_copy` included) and additions | ||
| 2107 | (a backing, an alias range, title memory) go on an unbounded per-device list; at the next submission each heap | ||
| 2108 | fixes again exactly the slots whose records a change touches: a release or removal every half naming it, an | ||
| 2109 | addition the waiting halves over it. Nothing walks the heap or reads the copy for this. A zeroed range, a slot | ||
| 2110 | the title rewrote and a heap destroyed drop their records. `console_heap_slot_records_test` checks that a release | ||
| 2111 | of a buffer 10 of 60,010 slots name looks at those 10, and compares the copy with a full re-resolution through | ||
| 2112 | random writes, releases, additions and alias changes. | ||
| 1879 | Console resource heap copies and shader-visible CBV/SRV/UAV heaps with at least 65,536 slots request | 2113 | Console resource heap copies and shader-visible CBV/SRV/UAV heaps with at least 65,536 slots request |
| 1880 | 64 MiB of zeroed padding after their last descriptor. `LEONIDA_HEAP_GUARD_MB` sets the padding in MiB | 2114 | 64 MiB of zeroed padding after their last descriptor. `LEONIDA_HEAP_GUARD_MB` sets the padding in MiB |
| 1881 | (0 disables it). When arena space is tight, allocation can fall back to the heap alone. Only indices | 2115 | (0 disables it). When arena space is tight, allocation can fall back to the heap alone. Only indices |
| @@ -2413,13 +2647,33 @@ Pipeline creation: | |||
| 2413 | merges into the offline seed. `LEONIDA_DIRECT_SESSION_CACHE=0` also uses a merge when only the session exists. | 2647 | 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. | 2648 | 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. | 2649 | 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). | 2650 | `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 |
| 2651 | the session file). | ||
| 2652 | The session file can't keep a crashed run's compiles: it is written at teardown and at the optional checkpoints | ||
| 2653 | 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 | ||
| 2654 | described below. Every graphics build first asks the corpus cache with | ||
| 2655 | `VK_PIPELINE_CREATE_FAIL_ON_PIPELINE_COMPILE_REQUIRED_BIT`. A pipeline the corpus doesn't have is built against a | ||
| 2656 | second cache, seeded from `pipeline_cache.heavy.bin` next to `pipeline_cache.bin`, so that cache holds only the | ||
| 2657 | corpus's misses. | ||
| 2658 | A build that takes at least `LEONIDA_HEAVY_PIPELINE_CACHE_MS` (500 by default) marks the heavy cache for writing. | ||
| 2659 | 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 | ||
| 2660 | one, through the same staging file and rename as the session cache. A crash therefore loses at most the last 20 s | ||
| 2661 | of slow builds, and the next launch starts with the rest. A write that fails, or whose | ||
| 2662 | `vkGetPipelineCacheData` returns anything but `VK_SUCCESS` (`VK_INCOMPLETE` means the cache grew after the size | ||
| 2663 | query, so the blob is truncated), leaves the previous file in place and the cache dirty: it is tried again 5 s | ||
| 2664 | later, the delay doubling with each failure in a row up to 2 min, so the cache is not left unsaved until teardown | ||
| 2665 | and a write that keeps failing does not spin. At device teardown the thread stops, and the cache is | ||
| 2666 | written if any build went into it. Fast builds are kept that way: without an offline seed every build is a miss, | ||
| 2667 | so they no longer reach `pipeline_cache.session.bin`. `LEONIDA_HEAVY_PIPELINE_CACHE_MS=0` turns the heavy cache off, and with it the | ||
| 2668 | `pipelineCreationCacheControl` feature unless `LEONIDA_PIPELINE_COMPILE=cache-only` asks for it. A cache-only create | ||
| 2669 | (`cache-only`) is left as it is. | ||
| 2417 | `LEONIDA_SKIP_COMPUTE=<part of a name>[,<part>...]` (`all`: every compute program) never builds the matching | 2670 | `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. | 2671 | 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. | 2672 | logged. It is a way past a program that hangs the GPU while the program or its input is fixed, not a fix. |
| 2673 | `--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, | 2674 | `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 | 2675 | 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 | 2676 | 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 | 2677 | 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. | 2678 | 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, | 2679 | While the compute warm-up has builds queued that idle checkpoint never starts, and a boot that ends by a crash, |
| @@ -2455,7 +2709,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 | 2709 | 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. | 2710 | for another's. |
| 2457 | `gta6rt --precompile-pipelines [--threads N] [--big-threads N] [--all] [--smallest-first] [--limit N] | 2711 | `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 | 2712 | [--min-bytes N] [--max-bytes N] [--filter PART]... [--skip-listed] [--list]` fills the journal ahead of play, with |
| 2713 | no game: it | ||
| 2459 | creates the Vulkan device as `--run` does (so the same environment gives the same journal names and driver keys: | 2714 | 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 | 2715 | 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 | 2716 | makes other pipelines) and builds every compute entry of the library through the dispatch path |
| @@ -2465,6 +2720,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 | 2720 | 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 | 2721 | 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. | 2722 | description and the bound formats, and take milliseconds. |
| 2723 | `LEONIDA_SKIP_COMPUTE` does not narrow the build: it is a play-time setting, players run the pre-compile with the | ||
| 2724 | game's environment, and a program left out here would stay out of the journal after the list is shortened. The run | ||
| 2725 | says how many entries the list names and builds them; `--skip-listed` leaves them out on purpose. The last line | ||
| 2726 | counts what was built (compiled, or found in a cache), what was journaled already or being built by another | ||
| 2727 | process, what failed, and what was left out and why: by `--skip-listed`, not buildable on this device (no SPIR-V, | ||
| 2728 | set-0 bindings without a bindless set, workgroup memory over the limit), or filtered out (`--filter`, the size | ||
| 2729 | bounds, `--limit`). The 89-167 s per program behind the skip list of the large `library/` programs came from | ||
| 2730 | wave64-emulated packs. Measured with a native wave64 pack on an RX 7900 XTX (RADV, Mesa 26.3.1, Wine): all 721 | ||
| 2731 | 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 | ||
| 2732 | 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 | ||
| 2733 | took them all from the journal (none built in the game) and ended as runs with the skip list do, in an idle-queue | ||
| 2734 | device loss or a stop with the GPU idle ([running.md](running.md#settings-every-platform-needs)); whether their | ||
| 2735 | 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: | 2736 | `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 | 2737 | 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 | 2738 | for, are per process. A compute build of `LEONIDA_COMPILE_HELPER_MIN_BYTES` or more (128 KiB) with no journal file |
| @@ -4098,11 +4366,22 @@ Not implemented yet: | |||
| 4098 | `LEONIDA_SKIP_COMPUTE`) or mistranslates leaves whatever the memory held: a dispatch of billions of groups or a | 4366 | `LEONIDA_SKIP_COMPUTE`) or mistranslates leaves whatever the memory held: a dispatch of billions of groups or a |
| 4099 | draw of four billion vertices runs until the host resets the display driver. One small compute pass per | 4367 | draw of four billion vertices runs until the host resets the display driver. One small compute pass per |
| 4100 | `ExecuteIndirect` call copies the active records into device-local scratch with their values bounded - 2^24 | 4368 | `ExecuteIndirect` call copies the active records into device-local scratch with their values bounded - 2^24 |
| 4101 | vertices or indices, 2^26 vertex instances (count times instances), 65 535 groups per dimension, 2^20 groups per | 4369 | vertices or indices, 2^26 vertex instances (count times instances), the device's `maxComputeWorkGroupCount` groups |
| 4102 | dispatch and a 2^27-unit work budget per call that saturates through an atomic compare-and-swap - and writes an | 4370 | per dimension for a dispatch (65 535 for a mesh dispatch), 2^20 groups per dispatch and a 2^27-unit work budget per |
| 4371 | call that saturates through an atomic compare-and-swap - and writes an | ||
| 4103 | empty record past `min(count, max_command_count)` and past the budget, and the clamped count word a `*Count` draw | 4372 | empty record past `min(count, max_command_count)` and past the budget, and the clamped count word a `*Count` draw |
| 4104 | then reads (so the count is at most `maxDrawCount`, VUID-vkCmdDrawIndirectCount-countBuffer-02717). The indirect | 4373 | then reads (so the count is at most `maxDrawCount`, VUID-vkCmdDrawIndirectCount-countBuffer-02717). A draw record |
| 4105 | command reads that scratch. A draw emits the pass before its rendering scope opens: `vkCmdCopyBuffer` and a | 4374 | of 2^23 vertices or indices an instance or more is a slot the title has not filled: it runs empty and charges |
| 4375 | nothing (RT-INDIRECT-DRAW-UNFILLED-COUNT). Before, each was cut to 2^24 and charged that, so eight of them used up | ||
| 4376 | the budget and every later draw in the list ran empty; a census in a VIctory fork found 90 such records in one | ||
| 4377 | list. A dispatch record's groups per dimension follow the device (#2230): the title's tile | ||
| 4378 | passes ask for 67 440 groups in x at 2560x1440 (found in the VIctory-Belobug-AMD fork of VIctory, | ||
| 4379 | `crates/victory-gpu/src/indirect.rs`), RADV runs 2^32 - 1 in x in one dispatch, and the cut at 65 535 dropped the | ||
| 4380 | last 1 905 tiles of the pass. A device that allows less (llvmpipe: 65 535) still gets the record cut at its | ||
| 4381 | limit: running the rest would take more dispatches with a group-ID base the translated shader does not read. The | ||
| 4382 | counters' `indirect clamp dispatch:` line (every 10 s while dispatch records are clamped) gives the records, those | ||
| 4383 | wider than 65 535 in x, the widest x that ran and those cut at the device's limits, so a run shows which case it | ||
| 4384 | is. The indirect command reads that scratch. A draw emits the pass before its rendering scope opens: `vkCmdCopyBuffer` and a | ||
| 4106 | memory barrier with a transfer access are not allowed inside a dynamic-rendering scope. The records are | 4385 | memory barrier with a transfer access are not allowed inside a dynamic-rendering scope. The records are |
| 4107 | bit-identical to the application's when they are within the limits, the argument and count buffers are left | 4386 | bit-identical to the application's when they are within the limits, the argument and count buffers are left |
| 4108 | untouched, and the scratch comes from a per-submission pool (`vulkan_scratch.h`) that a list with many indirect | 4387 | untouched, and the scratch comes from a per-submission pool (`vulkan_scratch.h`) that a list with many indirect |
diff --git a/docs/design.md b/docs/design.md index eee5be2cc..7bff52e7f 100644 --- a/docs/design.md +++ b/docs/design.md | |||
| @@ -303,7 +303,7 @@ How the generated SPIR-V expects the runtime to work: | |||
| 303 | | `s_load_dword*` with `vcc` 64-bit base pointer | SMEM `s_load_dword*` accepts `vcc` (`{vcc_lo, vcc_hi}`, hardware `s[106:107]`) as its 64-bit base pointer in `Gen.scalar_load`, loading `%vcc` as the low dword and `%vcc_hi` as the high dword; `s_buffer_load*` still requires a 4-dword V# and rejects 2-dword `vcc`. Source: RDNA2 ISA SMEM `SBASE` encoding (`sbase = 53` -> `s[106:107] = vcc`). Confirmed by corpus count over the 2,684-shader pipeline library compute corpus (79 shaders use `vcc` as the `s_load` base: 72 `s_load_dwordx4 sgpr, vcc`, 6 `s_load_dwordx8 sgpr, vcc`, 1 `s_load_dwordx4 slist, vcc`; all 79 translate and pass `spirv-val` under `--wave64-emulate`) and CPU-checked by `tests/semantic/test_sload_vcc_base.py` (`spirv-as` + `spirv-val`) and `tests/semantic/test_scalar_mem_smem.py` (both halves and the resulting addresses); **not GPU-verified**: the synthetic `runtime/test/shaders/cs_smem_vcc_base.asm` reads back eight seeded words through the pair in the standard GPU runner. | | 303 | | `s_load_dword*` with `vcc` 64-bit base pointer | SMEM `s_load_dword*` accepts `vcc` (`{vcc_lo, vcc_hi}`, hardware `s[106:107]`) as its 64-bit base pointer in `Gen.scalar_load`, loading `%vcc` as the low dword and `%vcc_hi` as the high dword; `s_buffer_load*` still requires a 4-dword V# and rejects 2-dword `vcc`. Source: RDNA2 ISA SMEM `SBASE` encoding (`sbase = 53` -> `s[106:107] = vcc`). Confirmed by corpus count over the 2,684-shader pipeline library compute corpus (79 shaders use `vcc` as the `s_load` base: 72 `s_load_dwordx4 sgpr, vcc`, 6 `s_load_dwordx8 sgpr, vcc`, 1 `s_load_dwordx4 slist, vcc`; all 79 translate and pass `spirv-val` under `--wave64-emulate`) and CPU-checked by `tests/semantic/test_sload_vcc_base.py` (`spirv-as` + `spirv-val`) and `tests/semantic/test_scalar_mem_smem.py` (both halves and the resulting addresses); **not GPU-verified**: the synthetic `runtime/test/shaders/cs_smem_vcc_base.asm` reads back eight seeded words through the pair in the standard GPU runner. | |
| 304 | | Execution model | One invocation = one lane. Compute and mesh waves derive lanes from the workgroup-local index; other stages use the subgroup lane. A wave = a subgroup, so cross-lane ops (`ds_swizzle`, `v_permlane*`, `v_readlane`/`v_writelane`, `v_mbcnt`) become subgroup shuffles. Wave32 pixel shaders split a 64-lane physical subgroup into two logical waves: lane IDs are `SubgroupLocalInvocationId & 31`, shuffle sources retain the current half (`& 32`), and ballots/votes use that half's 32-bit word. A value the translator knows is uniform (the bindless descriptor index) is read from the half's first running lane, never from a fixed lane, which need not be running (SHADER-1016). Other stage/wave combinations still require subgroup size == wave size or wave64 emulation. **Requires subgroup size == wave size** (wave32 maps directly onto NVIDIA GPUs; wave64 shaders need a 64-wide subgroup or emulation). `v_readlane_b32`/`v_writelane_b32` mask the lane select with 63 in wave64 (`S1[5:0]`) and 31 in wave32 (`S1[4:0]`); until SHADER-52 both used 63, so a wave32 select ≥ 32 pointed past a 32-wide subgroup. GPU-checked with `cs_w32_lane_wrap.asm` (lane 40 → 8). For the fragment-half rule, `ps_bitmask_perm` produced 4096/4096 exact pixels on an AMD Radeon RX 5700 XT; Vulkan reported a default subgroup size of 64 (range 32..64), but does not permit pinning fragment subgroup size on this device. CPU semantic tests compare a 64-lane wave32 pixel subgroup against two 32-lane subgroups for reads/writes, permutations, ballots, and votes. | | 304 | | Execution model | One invocation = one lane. Compute and mesh waves derive lanes from the workgroup-local index; other stages use the subgroup lane. A wave = a subgroup, so cross-lane ops (`ds_swizzle`, `v_permlane*`, `v_readlane`/`v_writelane`, `v_mbcnt`) become subgroup shuffles. Wave32 pixel shaders split a 64-lane physical subgroup into two logical waves: lane IDs are `SubgroupLocalInvocationId & 31`, shuffle sources retain the current half (`& 32`), and ballots/votes use that half's 32-bit word. A value the translator knows is uniform (the bindless descriptor index) is read from the half's first running lane, never from a fixed lane, which need not be running (SHADER-1016). Other stage/wave combinations still require subgroup size == wave size or wave64 emulation. **Requires subgroup size == wave size** (wave32 maps directly onto NVIDIA GPUs; wave64 shaders need a 64-wide subgroup or emulation). `v_readlane_b32`/`v_writelane_b32` mask the lane select with 63 in wave64 (`S1[5:0]`) and 31 in wave32 (`S1[4:0]`); until SHADER-52 both used 63, so a wave32 select ≥ 32 pointed past a 32-wide subgroup. GPU-checked with `cs_w32_lane_wrap.asm` (lane 40 → 8). For the fragment-half rule, `ps_bitmask_perm` produced 4096/4096 exact pixels on an AMD Radeon RX 5700 XT; Vulkan reported a default subgroup size of 64 (range 32..64), but does not permit pinning fragment subgroup size on this device. CPU semantic tests compare a 64-lane wave32 pixel subgroup against two 32-lane subgroups for reads/writes, permutations, ballots, and votes. | |
| 305 | | DPP | VOP1/VOP2 `_dpp` applies to src0. DPP16 controls (`quad_perm`, `row_shl/shr/ror/share/xmask/mirror/half_mirror`) and DPP8 (`dpp8` + `fi`) select the source lane, then `row_mask` (one bit per 16-lane row) and `bank_mask` (one bit per 4-lane bank) decide which destination lanes update. A lane whose row/bank is off is not written. A source lane outside the row is invalid: `bound_ctrl` 1 uses 0 as src0, otherwise the lane is not written. Hardware applies src0 float modifiers (`neg`/`abs`) after the invalid-lane zero selection, so `-src0` on an invalid lane yields `-0.0f` (`0x80000000`) and `\|src0\|` yields `+0.0f` (HW-DPP-NEG-INVALID-LANE, measured on RDNA3 (gfx1101) RX 7800 XT, RDNA2 not measured; tested by `tests/semantic/test_dpp_bound_ctrl_modifiers.py`). A source lane inactive under EXEC is used when `fi` is 1; otherwise `bound_ctrl` decides. DPP8 always writes an enabled lane: `fi` 1 reads the inactive source, `fi` 0 uses 0. DPP16/8 never leaves its 16/8-lane group, so this is exact on every subgroup at least that wide; under `--wave64-emulate` the exchange goes through the workgroup buffer like the other cross-lane ops. GPU-checked with `runtime/test/shaders/cs_dpp*.asm` on an RTX 3070 and hardware-measured on an RX 6800. On an RX 6700 XT (gfx1031), `tools/crosslane_fuzz.py --dpp-sweep --oracle hw` checks every DPP16 control × `bound_ctrl` × `fi`, every `row_mask`/`bank_mask` pair and the DPP8 selects in wave32 and wave64: 14,412 cases, all matching these rules (BUILD-162, `docs/shader_validation.md` FUZZ-7). The ballot of the source lanes' EXEC bits and the shuffle are each stored to a Function variable of their own (`Gen.eager`): SPIRV-Cross (MoltenVK) inlines a single-use result into the expression that uses it, which put the ballot on the right of a short-circuiting `&&` and the shuffle in a ternary's arm, so lanes out of their row skipped the ballot and row_shr:1's lane 1 found lane 0 inactive (`cs_dpp_ops` on MoltenVK; SHADER-529). A store is a statement every lane runs. For native FI=0, the source-lane ballot bit also selects the shuffle index: an absent or EXEC-off source is redirected to the current subgroup lane before `OpGroupNonUniformShuffle`, because masking an undefined shuffle result afterwards is not sufficient; FI=1 is unchanged. CPU-checked by `tests/semantic/test_dpp_eager_subgroup.py::test_fi0_shuffle_index_is_ballot_safe` with a hand-written `quad_perm` case whose active lane 6 reads absent lane 7 in a seven-invocation wave; **not GPU-verified**. Checked in SPIRV-Cross 1.3.239's MSL for the `cs_dpp*` tests (each op is now its own statement) and by `tests/semantic/test_dpp_eager_subgroup.py`; not yet run on a Mac. Semantics from the RDNA2 ISA, AMD LLVM modifier syntax and the GPUOpen DPP notes. | | 305 | | DPP | VOP1/VOP2 `_dpp` applies to src0. DPP16 controls (`quad_perm`, `row_shl/shr/ror/share/xmask/mirror/half_mirror`) and DPP8 (`dpp8` + `fi`) select the source lane, then `row_mask` (one bit per 16-lane row) and `bank_mask` (one bit per 4-lane bank) decide which destination lanes update. A lane whose row/bank is off is not written. A source lane outside the row is invalid: `bound_ctrl` 1 uses 0 as src0, otherwise the lane is not written. Hardware applies src0 float modifiers (`neg`/`abs`) after the invalid-lane zero selection, so `-src0` on an invalid lane yields `-0.0f` (`0x80000000`) and `\|src0\|` yields `+0.0f` (HW-DPP-NEG-INVALID-LANE, measured on RDNA3 (gfx1101) RX 7800 XT, RDNA2 not measured; tested by `tests/semantic/test_dpp_bound_ctrl_modifiers.py`). A source lane inactive under EXEC is used when `fi` is 1; otherwise `bound_ctrl` decides. DPP8 always writes an enabled lane: `fi` 1 reads the inactive source, `fi` 0 uses 0. DPP16/8 never leaves its 16/8-lane group, so this is exact on every subgroup at least that wide; under `--wave64-emulate` the exchange goes through the workgroup buffer like the other cross-lane ops. GPU-checked with `runtime/test/shaders/cs_dpp*.asm` on an RTX 3070 and hardware-measured on an RX 6800. On an RX 6700 XT (gfx1031), `tools/crosslane_fuzz.py --dpp-sweep --oracle hw` checks every DPP16 control × `bound_ctrl` × `fi`, every `row_mask`/`bank_mask` pair and the DPP8 selects in wave32 and wave64: 14,412 cases, all matching these rules (BUILD-162, `docs/shader_validation.md` FUZZ-7). The ballot of the source lanes' EXEC bits and the shuffle are each stored to a Function variable of their own (`Gen.eager`): SPIRV-Cross (MoltenVK) inlines a single-use result into the expression that uses it, which put the ballot on the right of a short-circuiting `&&` and the shuffle in a ternary's arm, so lanes out of their row skipped the ballot and row_shr:1's lane 1 found lane 0 inactive (`cs_dpp_ops` on MoltenVK; SHADER-529). A store is a statement every lane runs. For native FI=0, the source-lane ballot bit also selects the shuffle index: an absent or EXEC-off source is redirected to the current subgroup lane before `OpGroupNonUniformShuffle`, because masking an undefined shuffle result afterwards is not sufficient; FI=1 is unchanged. CPU-checked by `tests/semantic/test_dpp_eager_subgroup.py::test_fi0_shuffle_index_is_ballot_safe` with a hand-written `quad_perm` case whose active lane 6 reads absent lane 7 in a seven-invocation wave; **not GPU-verified**. Checked in SPIRV-Cross 1.3.239's MSL for the `cs_dpp*` tests (each op is now its own statement) and by `tests/semantic/test_dpp_eager_subgroup.py`; not yet run on a Mac. Semantics from the RDNA2 ISA, AMD LLVM modifier syntax and the GPUOpen DPP notes. | |
| 306 | | DPP on a VOPC compare | A VOPC compare whose src0 field is a DPP marker (250 for DPP16, 233/234 for DPP8) takes src0 through the DPP lane selection of the row above and writes VCC: a lane's bit is `compare(src0 of the selected lane, its own src1)`, with 0 for src0 when the selected lane is out of its row or inactive (`bound_ctrl` 1, or DPP8 with `fi` 0). The second word has the layout of a VOP2's DPP word. `llvm-mc` has no decoding for it on gfx10 (LLVM 21.1.8 rejects the first word for `gfx1013`; LLVM defines the form from GFX11 on), so `tools/shader_disasm.py` prints it: it decodes the pair with the first word turned into `v_max_f32` into `v0`, which takes the same second word, and gives the line the compare's name, a `vcc_lo` destination and the real encoding back (`with_vopc_dpp`); `tools/rdna2_decode.py` decodes it directly. **Only the forms where every lane writes its bit are translated**: `row_mask` and `bank_mask` 0xF and either `bound_ctrl` 1 or DPP8. Any other form, and `v_cmpx`, is refused (`DPP compare with lanes that keep their mask bit`), because what a lane DPP leaves unwritten does to its VCC bit is not measured. Found in 3 of the 2,684 pipeline-library compute programs of 1.0.2.1: 4 `v_cmp_gt_f32` each, with `quad_perm:[1,0,3,2]`, `quad_perm:[2,3,0,1]`, `row_ror:8` (all `bound_ctrl:1`, masks 0xF) and `dpp8:[4,5,6,7,0,1,2,3]`, beside `v_min/max_f32_dpp` and `v_mov_b32_dpp` on the same lanes. **Not measured on hardware**: the rule follows from the encoding, from LLVM's GFX11 definition of the same form and from the VOP2 DPP rules measured in the row above; the sweep that measured those (`tools/crosslane_fuzz.py --dpp-sweep --oracle hw`) does not cover compares. Lane values are checked in `tests/semantic/test_dpp_compare.py` (the SPIR-V interpreter) and on a GPU with `runtime/test/shaders/cs_dpp_cmp.asm`. | | 306 | | DPP on a VOPC compare | A VOPC compare whose src0 field is a DPP marker (250 for DPP16, 233/234 for DPP8) takes src0 through the DPP lane selection of the row above and writes VCC: a lane's bit is `compare(src0 of the selected lane, its own src1)`, with 0 for src0 when the selected lane is out of its row or inactive (`bound_ctrl` 1, or DPP8 with `fi` 0). The second word has the layout of a VOP2's DPP word. `llvm-mc` has no decoding for it on gfx10 (LLVM 21.1.8 rejects the first word for `gfx1013`; LLVM defines the form from GFX11 on), so `tools/shader_disasm.py` prints it: it decodes the pair with the first word turned into `v_max_f32` into `v0`, which takes the same second word, and gives the line the compare's name, a `vcc_lo` destination and the real encoding back (`with_vopc_dpp`); `tools/rdna2_decode.py` decodes it directly. **Only the forms where every lane writes its bit are translated**: `row_mask` and `bank_mask` 0xF and either `bound_ctrl` 1 or DPP8. Any other form is refused (`DPP compare with lanes DPP leaves unwritten`), because what such a lane writes is measured only on RDNA3, not on RDNA2. On RDNA3 (gfx1101, RX 7800 XT, `tools/hw_oracle`, wave32 and wave64; [measurement](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7161289307)) a lane DPP leaves unwritten does not keep its bit: `v_cmp` writes 0 to its VCC bit and `v_cmpx` turns it off in EXEC. That holds for an invalid source with `bound_ctrl` 0, and for a lane `row_mask` or `bank_mask` turns off, even with `bound_ctrl` 1. Translating these forms on RDNA2 (gfx1013) would need the same measurement there. `v_cmpx` in DPP form takes the same lane selection and the same forms, and writes EXEC as the plain `v_cmpx` does (a lane that was off stays off); it prints no destination, so its src0 is the first operand (SHADER-VOPCX-DPP). Found in 3 of the 2,684 pipeline-library compute programs of 1.0.2.1: 4 `v_cmp_gt_f32` each, with `quad_perm:[1,0,3,2]`, `quad_perm:[2,3,0,1]`, `row_ror:8` (all `bound_ctrl:1`, masks 0xF) and `dpp8:[4,5,6,7,0,1,2,3]`, beside `v_min/max_f32_dpp` and `v_mov_b32_dpp` on the same lanes. `v_cmpx` in DPP form is in 78 of the 18,837 graphics programs of the pipeline library (all pixel shaders, 113 instructions), all `v_cmpx_gt_f32_dpp vN, -vM quad_perm:[2,3,0,1] row_mask:0xf bank_mask:0xf bound_ctrl:1 fi:1`, a compare against the lane two above or below in its quad. **Not measured on RDNA2 hardware**: the rule follows from the encoding, from LLVM's GFX11 definition of the same form and from the VOP2 DPP rules measured in the row above; the sweep that measured those (`tools/crosslane_fuzz.py --dpp-sweep --oracle hw`) does not cover compares. The RDNA3 measurement above also ran the translated forms (`bound_ctrl` 1, masks 0xF): an invalid source lane gets the compare of a 0 source, as the rule says. Lane values are checked in `tests/semantic/test_dpp_compare.py` (the SPIR-V interpreter) and on a GPU with `runtime/test/shaders/cs_dpp_cmp.asm` and, for `v_cmpx`, `cs_dpp_cmpx.asm` (RTX 4070 Laptop, native wave32 and `--wave64-emulate`). | |
| 307 | | EXEC | A per-invocation `active` flag. VALU writes and exports are masked by it, scalar ops aren't, and `v_cmpx`, saveexec and EXEC writes update it. Measured on native gfx1100 (8 threads): a `v_mov_b32` under `EXEC=0x0F` leaves the other lanes untouched, `EXEC=0` writes nothing, a store writes only active lanes and `v_cmpx_gt_u32` narrows EXEC (4 of 4 cases); note that AMD clang 20 rejects `v_add_co_u32`, `v_sub_co_u32`, `v_add_co_ci_u32` and `v_mad_u64_u32` for `gfx1100`, `gfx1101` and `gfx1102`, so this toolchain could not reproduce the RX 7600 result below, which leaves open whether those parts support the opcodes and says only that they could not be assembled here. **A pixel is written when its lane was on in EXEC at the last `exp ... vm` the path executed (if it executed one) and at the last export to the color target; a path with no export at all goes by EXEC at the end.** The `vm` half is the RDNA2 ISA reference guide's rule (30-November-2020, §11.1 and §11.2.1: EXEC at the export is the valid mask and the final one sent is used; an `exp null ... vm` carries only the mask). The color half is measured: an export sends data only for the lanes that are on, a later export to the same target replaces the earlier one for the whole wave, and a lane with no data from the last one is not written even when a later `exp null done vm` marks it valid. So `exp mrt0 done` (no `vm`) with every lane on, followed by an EXEC write, still writes every pixel, and EXEC off at that export and back on afterwards writes none. **Measured on RDNA2** (AMD Radeon iGPU, gfx1036, driver 26.10.1) with the pixel-shader oracle of #3061 (`ps_oracle.py`), hand-written ISA as the pixel shader of a real draw (wave64 stage): 18 programs that cut EXEC to half of the target before, between or after `exp mrt0` (with and without `vm` and `done`) and `exp null done vm`; all 18 fit the rule, 6 of them differed from the translator, which until 2026-11-23 discarded by EXEC at the end on a path without `vm` and kept the older export's value (or the output's initial value) for a lane that was off at the last color export. The latches (`%vm_mask`, `%col_mask_mrtN`) are only emitted where a path can write EXEC after a `vm` or color export; everywhere else EXEC at the end is the same mask and the SPIR-V is unchanged. With several color targets a pixel stays when any target got an export from its lane (Vulkan cannot skip one attachment per pixel; not measured, the oracle's pipeline has one target); `mrtz` is not part of the color mask (not measured). **Measuring exports needs `s_waitcnt expcnt(0)` after each one**: an export is asynchronous, and without the wait the hardware takes the data and the EXEC of a later moment (`v_mov v9, A; exp mrt0 v9 done vm; v_mov v9, B` shows B, and an EXEC write right after the export decides which pixels are written, which looks like "EXEC at the end decides"); 64 `s_nop 15` have the same effect as the wait. Checked on the CPU by `tests/semantic/test_export_valid_mask.py` and on the GPU by `runtime/test/shaders/ps_exp_color_mask.asm` (RTX 5080 and the Radeon). VALU scalar lane-mask destinations (`v_cmp_*`, `v_add_co_u32`, `v_add_co_ci_u32`, `v_sub_co_u32`, `v_sub_co_ci_u32`, `v_subrev_co_u32`, `v_subrev_co_ci_u32`, `v_mad_u64_u32`, `v_mad_i64_i32`) write 0 for lanes off in EXEC (`SDST[lane] = EXEC[lane] ? bit : 0`, AMD RDNA2 ISA). Until 2026-11-22 the six `*_co_*` ops and `v_mad_u64_u32`/`v_mad_i64_i32` did not AND the carry/sign bit with `active`, so inactive lanes leaked 1 bits into `VCC`/SGPR masks (`s_bcnt1`, `s_cbranch_vccz`, `v_cndmask_b32`). Checked on the CPU by `tests/semantic/test_carry_exec_mask.py` (wave32, wave64, and `--wave64-emulate` structure), and **hardware-verified on an AMD RX 7600 (gfx1102)** with `v_add_co_u32` and `v_add_co_ci_u32` carrying on every active lane: VCC reads `0xffffffff` with full EXEC, `0x0000ffff` for the mask `0x0000ffff` and `0xaaaaaaaa` for `0xaaaaaaaa` in wave32, `vcc_lo = 0x0000ffff` with `vcc_hi = 0x0000000f` for the same partial mask in wave64, and `0` when EXEC is 0 even with VCC preloaded to all ones; with one carrying lane under mask `0x0000ffff` VCC is `0x00000001`, and `v_sub_co_u32`/`v_subrev_co_u32` with a borrow under that mask give `0x0000ffff` too. The `*_co_ci_` forms, `v_mad_u64_u32` and `v_mad_i64_i32` share the same path but were not measured separately; it is also GPU-verified on native RDNA2 (gfx1036, AMD Radeon Graphics) with partial EXEC masks (inactive lanes write 0 in sdst for `v_add_co_u32` and `v_mad_u64_u32`). In a shader that writes EXEC, a run of two or more lane-local VALU instructions (no cross-lane read, no lane-mask, SCC, carry or EXEC write) sits inside one `if (active)` and writes its VGPRs directly, instead of an `OpSelect(active, new, old)` per write: the same result, but the driver predicates the run with its own EXEC instead of keeping both values live. On an RX 5700 XT (RADV) a pixel shader with 8 divergent if/else regions of `v_fma`/`v_mul`/`v_add`/`v_min`/`v_max` went from 0.85 ms to 0.69 ms (the same program as native SPIR-V: 0.65 ms). Not under `--wave64-emulate`. Checked by `tests/semantic/test_active_runs.py`. | | 307 | | EXEC | A per-invocation `active` flag. VALU writes and exports are masked by it, scalar ops aren't, and `v_cmpx`, saveexec and EXEC writes update it. Measured on native gfx1100 (8 threads): a `v_mov_b32` under `EXEC=0x0F` leaves the other lanes untouched, `EXEC=0` writes nothing, a store writes only active lanes and `v_cmpx_gt_u32` narrows EXEC (4 of 4 cases); note that AMD clang 20 rejects `v_add_co_u32`, `v_sub_co_u32`, `v_add_co_ci_u32` and `v_mad_u64_u32` for `gfx1100`, `gfx1101` and `gfx1102`, so this toolchain could not reproduce the RX 7600 result below, which leaves open whether those parts support the opcodes and says only that they could not be assembled here. **A pixel is written when its lane was on in EXEC at the last `exp ... vm` the path executed (if it executed one) and at the last export to the color target; a path with no export at all goes by EXEC at the end.** The `vm` half is the RDNA2 ISA reference guide's rule (30-November-2020, §11.1 and §11.2.1: EXEC at the export is the valid mask and the final one sent is used; an `exp null ... vm` carries only the mask). The color half is measured: an export sends data only for the lanes that are on, a later export to the same target replaces the earlier one for the whole wave, and a lane with no data from the last one is not written even when a later `exp null done vm` marks it valid. So `exp mrt0 done` (no `vm`) with every lane on, followed by an EXEC write, still writes every pixel, and EXEC off at that export and back on afterwards writes none. **Measured on RDNA2** (AMD Radeon iGPU, gfx1036, driver 26.10.1) with the pixel-shader oracle of #3061 (`ps_oracle.py`), hand-written ISA as the pixel shader of a real draw (wave64 stage): 18 programs that cut EXEC to half of the target before, between or after `exp mrt0` (with and without `vm` and `done`) and `exp null done vm`; all 18 fit the rule, 6 of them differed from the translator, which until 2026-11-23 discarded by EXEC at the end on a path without `vm` and kept the older export's value (or the output's initial value) for a lane that was off at the last color export. The latches (`%vm_mask`, `%col_mask_mrtN`) are only emitted where a path can write EXEC after a `vm` or color export; everywhere else EXEC at the end is the same mask and the SPIR-V is unchanged. With several color targets a pixel stays when any target got an export from its lane (Vulkan cannot skip one attachment per pixel; not measured, the oracle's pipeline has one target); `mrtz` is not part of the color mask (not measured). **Measuring exports needs `s_waitcnt expcnt(0)` after each one**: an export is asynchronous, and without the wait the hardware takes the data and the EXEC of a later moment (`v_mov v9, A; exp mrt0 v9 done vm; v_mov v9, B` shows B, and an EXEC write right after the export decides which pixels are written, which looks like "EXEC at the end decides"); 64 `s_nop 15` have the same effect as the wait. Checked on the CPU by `tests/semantic/test_export_valid_mask.py` and on the GPU by `runtime/test/shaders/ps_exp_color_mask.asm` (RTX 5080 and the Radeon). VALU scalar lane-mask destinations (`v_cmp_*`, `v_add_co_u32`, `v_add_co_ci_u32`, `v_sub_co_u32`, `v_sub_co_ci_u32`, `v_subrev_co_u32`, `v_subrev_co_ci_u32`, `v_mad_u64_u32`, `v_mad_i64_i32`) write 0 for lanes off in EXEC (`SDST[lane] = EXEC[lane] ? bit : 0`, AMD RDNA2 ISA). Until 2026-11-22 the six `*_co_*` ops and `v_mad_u64_u32`/`v_mad_i64_i32` did not AND the carry/sign bit with `active`, so inactive lanes leaked 1 bits into `VCC`/SGPR masks (`s_bcnt1`, `s_cbranch_vccz`, `v_cndmask_b32`). Checked on the CPU by `tests/semantic/test_carry_exec_mask.py` (wave32, wave64, and `--wave64-emulate` structure), and **hardware-verified on an AMD RX 7600 (gfx1102)** with `v_add_co_u32` and `v_add_co_ci_u32` carrying on every active lane: VCC reads `0xffffffff` with full EXEC, `0x0000ffff` for the mask `0x0000ffff` and `0xaaaaaaaa` for `0xaaaaaaaa` in wave32, `vcc_lo = 0x0000ffff` with `vcc_hi = 0x0000000f` for the same partial mask in wave64, and `0` when EXEC is 0 even with VCC preloaded to all ones; with one carrying lane under mask `0x0000ffff` VCC is `0x00000001`, and `v_sub_co_u32`/`v_subrev_co_u32` with a borrow under that mask give `0x0000ffff` too. The `*_co_ci_` forms, `v_mad_u64_u32` and `v_mad_i64_i32` share the same path but were not measured separately; it is also GPU-verified on native RDNA2 (gfx1036, AMD Radeon Graphics) with partial EXEC masks (inactive lanes write 0 in sdst for `v_add_co_u32` and `v_mad_u64_u32`). In a shader that writes EXEC, a run of two or more lane-local VALU instructions (no cross-lane read, no lane-mask, SCC, carry or EXEC write) sits inside one `if (active)` and writes its VGPRs directly, instead of an `OpSelect(active, new, old)` per write: the same result, but the driver predicates the run with its own EXEC instead of keeping both values live. On an RX 5700 XT (RADV) a pixel shader with 8 divergent if/else regions of `v_fma`/`v_mul`/`v_add`/`v_min`/`v_max` went from 0.85 ms to 0.69 ms (the same program as native SPIR-V: 0.65 ms). Not under `--wave64-emulate`. Checked by `tests/semantic/test_active_runs.py`. | |
| 308 | | `s_*_saveexec_b32/b64`, `s_andn1/andn2_wrexec_b32/b64` | RDNA2 ISA SOP1. saveexec: `D = EXEC; EXEC = f(S0, EXEC); SCC = (EXEC != 0)`. wrexec: `EXEC = f(S0, EXEC); D = EXEC`. `f` is one of `and`, `or`, `xor`, `andn1` (`~S0 & EXEC`), `andn2` (`S0 & ~EXEC`), `orn1` (`~S0 \| EXEC`), `orn2` (`S0 \| ~EXEC`), `nand`, `nor`, `xnor`, the table in `Gen.EXEC_LOGIC`. The definitions match `tools/cf_ref.py` `_SAVEEXEC`, the FUZZ-8 model. Each invocation holds its own lane's bit (0 or ~0), so `f` is the bitwise op on that bit. A lane EXEC had off becomes active when `f` gives 1 for it (`nand`, `nor`, `orn1`, `orn2`, `xnor`, ...), as on hardware, and SCC is the wave vote. Until 2026-11-22 only `and`/`or`/`andn2_saveexec` and `andn2_wrexec` were translated. CPU-checked by `tests/semantic/test_saveexec_variants.py` (all ten saveexec kinds in wave32 and wave64, both wrexec kinds, partial EXEC and S0, an empty result, every lane against `cf_ref._SAVEEXEC`) and by `tools/cf_diff.py` (300 programs × wave32/64 still pass). Hardware-verified on native RDNA2 (`gfx1036`, Windows 11, driver `32.0.21045.29003`, wave32 & wave64, 0 mismatches): all 10 `saveexec` kinds and both `wrexec` kinds (`andn1`/`andn2`) match bit-for-bit on non-symmetric masks (`src0 = 0x0F0F0F0F`, `exec = 0x33333333` in wave32; `0x0F0F0F0F_00FF00FF` / `0x33333333_55555555` in wave64), zero-result `SCC = 0`, wave64 upper-32-bit-only `new_exec = 0x00000001_00000000` setting `SCC = 1`, and `sdst == src0` register aliasing (`s4, s4` and `s[4:5], s[4:5]`) reading original `src0` before writing old `EXEC` to `sdst`. **Not GPU-verified** for the seven new kinds. Measured on native gfx1100 (single 8-lane workgroup, 36 programs): all ten `saveexec` kinds and both `wrexec` forms follow `f` for three `S0`/`EXEC` pairs, including lanes `EXEC` had off being switched back on (`nand` with `S0=0x03`, `EXEC=0x0F` leaves `0xFFFFFFFC`, activating lanes 4-7), `D` holding the old `EXEC` for `saveexec` and the new one for `wrexec`, and `SCC` the `EXEC != 0` vote. | | 308 | | `s_*_saveexec_b32/b64`, `s_andn1/andn2_wrexec_b32/b64` | RDNA2 ISA SOP1. saveexec: `D = EXEC; EXEC = f(S0, EXEC); SCC = (EXEC != 0)`. wrexec: `EXEC = f(S0, EXEC); D = EXEC`. `f` is one of `and`, `or`, `xor`, `andn1` (`~S0 & EXEC`), `andn2` (`S0 & ~EXEC`), `orn1` (`~S0 \| EXEC`), `orn2` (`S0 \| ~EXEC`), `nand`, `nor`, `xnor`, the table in `Gen.EXEC_LOGIC`. The definitions match `tools/cf_ref.py` `_SAVEEXEC`, the FUZZ-8 model. Each invocation holds its own lane's bit (0 or ~0), so `f` is the bitwise op on that bit. A lane EXEC had off becomes active when `f` gives 1 for it (`nand`, `nor`, `orn1`, `orn2`, `xnor`, ...), as on hardware, and SCC is the wave vote. Until 2026-11-22 only `and`/`or`/`andn2_saveexec` and `andn2_wrexec` were translated. CPU-checked by `tests/semantic/test_saveexec_variants.py` (all ten saveexec kinds in wave32 and wave64, both wrexec kinds, partial EXEC and S0, an empty result, every lane against `cf_ref._SAVEEXEC`) and by `tools/cf_diff.py` (300 programs × wave32/64 still pass). Hardware-verified on native RDNA2 (`gfx1036`, Windows 11, driver `32.0.21045.29003`, wave32 & wave64, 0 mismatches): all 10 `saveexec` kinds and both `wrexec` kinds (`andn1`/`andn2`) match bit-for-bit on non-symmetric masks (`src0 = 0x0F0F0F0F`, `exec = 0x33333333` in wave32; `0x0F0F0F0F_00FF00FF` / `0x33333333_55555555` in wave64), zero-result `SCC = 0`, wave64 upper-32-bit-only `new_exec = 0x00000001_00000000` setting `SCC = 1`, and `sdst == src0` register aliasing (`s4, s4` and `s[4:5], s[4:5]`) reading original `src0` before writing old `EXEC` to `sdst`. **Not GPU-verified** for the seven new kinds. Measured on native gfx1100 (single 8-lane workgroup, 36 programs): all ten `saveexec` kinds and both `wrexec` forms follow `f` for three `S0`/`EXEC` pairs, including lanes `EXEC` had off being switched back on (`nand` with `S0=0x03`, `EXEC=0x0F` leaves `0xFFFFFFFC`, activating lanes 4-7), `D` holding the old `EXEC` for `saveexec` and the new one for `wrexec`, and `SCC` the `EXEC != 0` vote. | |
| 309 | | Control flow | Reducible graphs use structured branches and natural loops. Irreducible graphs use the dispatch-loop form, which can also be forced with `--dispatch-loop` for comparisons. The control-flow unit test checks 18,228 generated graphs. Irreducible graphs use node splitting (`cfg_structure.split_irreducible`, up to `min(2*N, N+64)` blocks) and fall back to the dispatch-loop form when capped; it can also be forced with `--dispatch-loop` for comparisons. `cfg_structure.structure`, `cfg_structure.run`, and `rdna2spirv.assemble`'s structured emitter are iterative and hoist each guarded member's dominated tail continuation out of its enclosing guard (exact by strict dominance: no block outside the guard's subtree can target the continuation), keeping `OpSelectionMerge` nesting O(1) on sequential diamond/loop chains instead of nesting O(N) deep and hitting Python's recursion limit on multi-thousand-block shaders (e.g. 2,000 sequential diamonds nest to depth 2 instead of 2,000). The control-flow unit test (`tests/test_cfg_structure.py`) checks 20,000 generated graphs plus 2,000-diamond, 1,200-loop, and 1,500-early-exit chains. `capped_tree()` also runs `cfg_structure.unwrap_known_pc_guards` (shared with `wave64_emulate_opt`) to unwrap tautological `("guard", g, ...)` nodes whenever abstract interpretation proves `%pc == g` on all incoming paths (e.g. post-dominating merge blocks after diamonds and loops); this keeps `ms_wave_info_s3`'s `s_barrier` in uniform top-level control flow (fixing an AMD Windows LLPC `0xC0000005` pipeline-creation crash on AMD Ryzen 5 7600 RDNA2 iGPU driver `24.10.24`, `4096/4096` exact on AMD RDNA2 and RTX 4070 SUPER) and avoids false `needs_barrier_rounds` triggers (`SHADER-STRUCTURED-PC-UNWRAP`). AMD A/B checks compare the two forms for selected pixel shaders with defined test inputs. For shaders that never export colour, the comparison checks pixel coverage. **Nesting is bounded (SHADER-299):** a tree deeper than `MAX_STRUCTURED_DEPTH` (16) is emitted in the dispatch-loop form instead, since `spirv-val` time grows roughly with the cube of the measured nesting depth. **Nesting is bounded (SHADER-299, SHADER-427):** a tree deeper than `MAX_STRUCTURED_DEPTH` (64; `--max-structured-depth N`, 0 = no bound) is emitted in the dispatch-loop form instead, since `spirv-val` time grows roughly with the cube of the measured nesting depth. Before #1904, over the 1.0.2.1 corpus (26,503 modules, `spirv-val` 2026.4): the deepest block of a module is nested 118 constructs deep, 12,963 modules are structured (median 15) and 6,000 of those are deeper than 16; an estimated 85% of the corpus's `spirv-val` time is in modules nested 20 or deeper. Median `spirv-val` time for the same module in each form: depth 20 181 -> 129 ms (1.4x), 30 507 -> 371 (1.4x), 50 1,712 -> 738 (2.3x), 64 2,692 -> 1,163 (2.3x), 77 5,122 -> 1,130 (4.5x), and the deepest (118) 13,683 -> 1,352 ms (10.1x). Depth 5-12 shows no gain (at depth 6 the flat form is slightly slower), which is why the bound first sat at 16. Since #1904 (`cfg_structure` hoists tails) the deepest tree in the corpus is 29: of 12,944 structured modules, 1,031 are deeper than 16 (747 CS, 284 PS), 57 deeper than 20, 24 deeper than 24. For those 1,031 the flat form saves only 12% of `spirv-val` time (1,235 -> 1,091 s summed, slowest module 8.3 -> 5.9 s), while on an RTX 5070 Ti (NVIDIA 621.24) it compiles slower: the 284 pixel shaders 1.67x (827 -> 1,382 s summed, two rounds), four compute modules at depth 19-24 2.0x (297 -> 591 s, 1.6-2.7x each), so the bound now sits above the corpus (SHADER-427). Both forms pass `spirv-val` on a 200-shader slice (200/200 each), and `gen.nesting` records the tree depth. AMD's Windows driver adds a reason to keep the structured form (SHADER-995): on a Radeon gfx1036 iGPU (32.0.21042.62) the dispatch-loop module of `XboxBvhBuilder.dll`'s `LeafRehydration` (tree depth 18, a 581-case switch) takes 34 minutes to create (XXDESIGN), where its structured module is created in 2.9 s; ten other programs of that DLL compile in the dispatch-loop form there in 0.4-40 s, 2.5-5x their structured time ([embedded_shaders.md](embedded_shaders.md), section 7). | | 309 | | Control flow | Reducible graphs use structured branches and natural loops. Irreducible graphs use the dispatch-loop form, which can also be forced with `--dispatch-loop` for comparisons. The control-flow unit test checks 18,228 generated graphs. Irreducible graphs use node splitting (`cfg_structure.split_irreducible`, up to `min(2*N, N+64)` blocks) and fall back to the dispatch-loop form when capped; it can also be forced with `--dispatch-loop` for comparisons. `cfg_structure.structure`, `cfg_structure.run`, and `rdna2spirv.assemble`'s structured emitter are iterative and hoist each guarded member's dominated tail continuation out of its enclosing guard (exact by strict dominance: no block outside the guard's subtree can target the continuation), keeping `OpSelectionMerge` nesting O(1) on sequential diamond/loop chains instead of nesting O(N) deep and hitting Python's recursion limit on multi-thousand-block shaders (e.g. 2,000 sequential diamonds nest to depth 2 instead of 2,000). The control-flow unit test (`tests/test_cfg_structure.py`) checks 20,000 generated graphs plus 2,000-diamond, 1,200-loop, and 1,500-early-exit chains. `capped_tree()` also runs `cfg_structure.unwrap_known_pc_guards` (shared with `wave64_emulate_opt`) to unwrap tautological `("guard", g, ...)` nodes whenever abstract interpretation proves `%pc == g` on all incoming paths (e.g. post-dominating merge blocks after diamonds and loops); this keeps `ms_wave_info_s3`'s `s_barrier` in uniform top-level control flow (fixing an AMD Windows LLPC `0xC0000005` pipeline-creation crash on AMD Ryzen 5 7600 RDNA2 iGPU driver `24.10.24`, `4096/4096` exact on AMD RDNA2 and RTX 4070 SUPER) and avoids false `needs_barrier_rounds` triggers (`SHADER-STRUCTURED-PC-UNWRAP`). AMD A/B checks compare the two forms for selected pixel shaders with defined test inputs. For shaders that never export colour, the comparison checks pixel coverage. **Nesting is bounded (SHADER-299):** a tree deeper than `MAX_STRUCTURED_DEPTH` (16) is emitted in the dispatch-loop form instead, since `spirv-val` time grows roughly with the cube of the measured nesting depth. **Nesting is bounded (SHADER-299, SHADER-427):** a tree deeper than `MAX_STRUCTURED_DEPTH` (64; `--max-structured-depth N`, 0 = no bound) is emitted in the dispatch-loop form instead, since `spirv-val` time grows roughly with the cube of the measured nesting depth. Before #1904, over the 1.0.2.1 corpus (26,503 modules, `spirv-val` 2026.4): the deepest block of a module is nested 118 constructs deep, 12,963 modules are structured (median 15) and 6,000 of those are deeper than 16; an estimated 85% of the corpus's `spirv-val` time is in modules nested 20 or deeper. Median `spirv-val` time for the same module in each form: depth 20 181 -> 129 ms (1.4x), 30 507 -> 371 (1.4x), 50 1,712 -> 738 (2.3x), 64 2,692 -> 1,163 (2.3x), 77 5,122 -> 1,130 (4.5x), and the deepest (118) 13,683 -> 1,352 ms (10.1x). Depth 5-12 shows no gain (at depth 6 the flat form is slightly slower), which is why the bound first sat at 16. Since #1904 (`cfg_structure` hoists tails) the deepest tree in the corpus is 29: of 12,944 structured modules, 1,031 are deeper than 16 (747 CS, 284 PS), 57 deeper than 20, 24 deeper than 24. For those 1,031 the flat form saves only 12% of `spirv-val` time (1,235 -> 1,091 s summed, slowest module 8.3 -> 5.9 s), while on an RTX 5070 Ti (NVIDIA 621.24) it compiles slower: the 284 pixel shaders 1.67x (827 -> 1,382 s summed, two rounds), four compute modules at depth 19-24 2.0x (297 -> 591 s, 1.6-2.7x each), so the bound now sits above the corpus (SHADER-427). Both forms pass `spirv-val` on a 200-shader slice (200/200 each), and `gen.nesting` records the tree depth. AMD's Windows driver adds a reason to keep the structured form (SHADER-995): on a Radeon gfx1036 iGPU (32.0.21042.62) the dispatch-loop module of `XboxBvhBuilder.dll`'s `LeafRehydration` (tree depth 18, a 581-case switch) takes 34 minutes to create (XXDESIGN), where its structured module is created in 2.9 s; ten other programs of that DLL compile in the dispatch-loop form there in 0.4-40 s, 2.5-5x their structured time ([embedded_shaders.md](embedded_shaders.md), section 7). | |
| @@ -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. | |
| @@ -430,7 +431,7 @@ How the generated SPIR-V expects the runtime to work: | |||
| 430 | | Wave64 handling | Wave size is detected per shader from the code (64-bit EXEC writes, `exec_hi`, `v_mbcnt_hi`, `*_saveexec_b64`/`*_wrexec_b64`, and 64-bit lane-mask SOP ops `s_bcnt[01]_i32_b64` / `s_ff[01]_i32_b64` / `s_wqm_b64` / `s_bfm_b64` even when the mask is an ordinary SGPR pair; mesh shaders are always wave64). In wave32 code (a header or FSPX dispatch state that says so) `s_bfm_b64` is 64-bit data instead: the translator writes `((1 << (S0 & 63)) - 1) << (S1 & 63)` to the pair, `tools/lane_masks.py` leaves it data, and it doesn't count against an FSPX program's wave32 state. The pipeline library's wave32 compute programs build an S# in place with it (`s_bfm_b64 s[88:89], 2, 54`, then `s_mov_b64` of words 2-3; 958 programs, [shader_library.md](shader_library.md)). Only constant operands are translated there; none other is seen. `tests/semantic/test_wave32_bfm64_data.py`. Wave size comes from the sidecar `fssm/<name>.fssm` header flags word `u32[0xD4]` bit 5 (`0x20` = wave32, `0` = wave64; `fssm_header.wave_size()`), cross-checked against wave64/wave32 code markers (`WAVE64_RE` / `WAVE32_RE`: a contradicting header and code listing raises `Unsupported`), and falls back to the code-marker heuristic (64-bit EXEC/VCC writes, `exec_hi`, `v_mbcnt_hi`, `*_saveexec_b64`/`*_wrexec_b64`, and 64-bit lane-mask SOP ops `s_bcnt[01]_i32_b64` / `s_ff[01]_i32_b64` / `s_wqm_b64` / `s_bfm_b64`, plus wave64 for mesh shaders) when no `FSSM`-magic sidecar is present (synthetic listings). **An FSPX program** (the FidelityFX DLL's, no FSSM blob) takes its wave size from its dispatch state instead: kind 0 word 4 bit 20, set = wave32 (`fspx/<name>.json` `wave32`). Only a strict marker (`WAVE64_RE` against wave32, `WAVE32_RE` against wave64) contradicts it and raises `Unsupported`; a `_b64` op on `vcc` or `exec` does not, since these programs move `vcc` as an ordinary SGPR pair. Without that field the heuristic stays. Confirmed on the 29 programs of 1.0.2.1: strict markers never contradict the bit, the `RSRC1` VGPR granule fits it in all 21 programs that decode cleanly, and `PSV0` lane counts agree with it in all 5 that state one ([fspx.md](fspx.md), "Kind 0: dispatch state"). Translated with the bit, the 4 programs the heuristic got wrong change size, and the other 22 translated modules are byte-identical. CPU-checked by `tests/semantic/test_fspx_wave_size.py`, including a `v_readlane_b32` whose result differs between the two sizes; `vk_pipeline_check` builds all 26 modules. Not GPU-checked on these programs' own data. Confirmed across all 26,503 corpus blobs with 0 contradictions against GFX10 SOP1/SOP2/SOPC/VOP3 encodings: 23,841 wave64 (1,154 CS, 195 GS, 9,282 MS, 10,974 PS, 2,236 VS) and 2,662 wave32 (1,535 CS, 1,127 PS); the code-marker heuristic alone misclassified 2,287 markerless wave64 shaders as wave32 (287 CS: 162 straight-line and 125 branchy, including 11 with `v_readlane_b32`, 35 `v_readfirstlane_b32`, 29 `ds_swizzle_b32`, 14 `s_barrier`; 943 PS: 906 straight-line and 37 branchy; 1,057 VS: 1,020 straight-line and 37 branchy); CPU-checked by `tests/test_fssm_header.py` and `tests/test_fssm_wave_size.py`. Until 2026-11-21 a mask-only wave64 program with no EXEC markers was translated as wave32, so `s_bcnt1_i32_b64` counted one half (#210). GPU-checked with `runtime/test/shaders/cs_w64_mask_detect.asm` (48 set bits of `(lane & 5) != 0`) on NVIDIA GeForce RTX 5060 under `LEONIDA_W64_EMULATE=1`. The hardware lane is exact in compute and mesh shaders (LocalInvocationIndex mod 64 or 32) and is used by `v_mbcnt` and EXEC writes. In other stages it's the subgroup lane. Constant EXEC writes (`s_mov_b32 exec_lo/exec_hi, K`) set each lane from its own bit of K, as `(K >> lane) & 1` (shift and mask: Intel's Windows driver evaluated `OpBitFieldUExtract` of a constant that fits in 16 bits with the lane taken mod 16, so `exec_lo = 0xffff` ran all 32 lanes; GPU-checked with `runtime/test/shaders/cs_exec_const.asm` on Intel UHD Graphics 770, driver 32.0.101.6129, and NVIDIA GeForce RTX 4080 SUPER); before, any non-zero constant turned every lane on. A register written to `exec_hi` sets lanes 32–63 only. VCC's halves follow the same rule while VCC holds a lane mask: a 32-bit write to `vcc_lo` sets lanes 0–31 of the mask and one to `vcc_hi` lanes 32–63 (until 2026-11-22 a `vcc_lo` write set all 64 lanes and a `vcc_hi` write never reached the mask that `s_cbranch_vccz`/`v_cndmask` read; CPU-checked by `tests/semantic/test_wave64_vcc_half_write.py`, not GPU-checked). Mask and `0`/`-1` half-writes to `vcc_lo`/`vcc_hi` keep VCC tracked as a lane mask across subsequent ops (`s_bcnt1_i32_b64`, further half-writes), whereas plain-data writes (`s_buffer_load_dword vcc_lo`, `s_load_dword`, scalar ALU, non-mask constants) end VCC's mask state and store the scalar word across all 64 lanes instead of updating only one mask half (confirmed on 1 wave64 PS in the 1.0.2.1 corpus and `tests/semantic/test_wave64_vcc_half_write.py`). GPU-checked with `runtime/test/shaders/cs_exec64.asm`: lanes 16–47 enabled from two constants, exact on a 32-wide-subgroup GPU. Still approximate on 32-wide subgroups: cross-lane ops between the two halves of a wave64 (readlane/permlane/DPP/shuffles across lane 31/32, wave-wide reductions). The metadata index marks every wave64 shader so a runtime can request `requiredSubgroupSize = 64` where supported (AMD), which makes those exact too. | | 431 | | Wave64 handling | Wave size is detected per shader from the code (64-bit EXEC writes, `exec_hi`, `v_mbcnt_hi`, `*_saveexec_b64`/`*_wrexec_b64`, and 64-bit lane-mask SOP ops `s_bcnt[01]_i32_b64` / `s_ff[01]_i32_b64` / `s_wqm_b64` / `s_bfm_b64` even when the mask is an ordinary SGPR pair; mesh shaders are always wave64). In wave32 code (a header or FSPX dispatch state that says so) `s_bfm_b64` is 64-bit data instead: the translator writes `((1 << (S0 & 63)) - 1) << (S1 & 63)` to the pair, `tools/lane_masks.py` leaves it data, and it doesn't count against an FSPX program's wave32 state. The pipeline library's wave32 compute programs build an S# in place with it (`s_bfm_b64 s[88:89], 2, 54`, then `s_mov_b64` of words 2-3; 958 programs, [shader_library.md](shader_library.md)). Only constant operands are translated there; none other is seen. `tests/semantic/test_wave32_bfm64_data.py`. Wave size comes from the sidecar `fssm/<name>.fssm` header flags word `u32[0xD4]` bit 5 (`0x20` = wave32, `0` = wave64; `fssm_header.wave_size()`), cross-checked against wave64/wave32 code markers (`WAVE64_RE` / `WAVE32_RE`: a contradicting header and code listing raises `Unsupported`), and falls back to the code-marker heuristic (64-bit EXEC/VCC writes, `exec_hi`, `v_mbcnt_hi`, `*_saveexec_b64`/`*_wrexec_b64`, and 64-bit lane-mask SOP ops `s_bcnt[01]_i32_b64` / `s_ff[01]_i32_b64` / `s_wqm_b64` / `s_bfm_b64`, plus wave64 for mesh shaders) when no `FSSM`-magic sidecar is present (synthetic listings). **An FSPX program** (the FidelityFX DLL's, no FSSM blob) takes its wave size from its dispatch state instead: kind 0 word 4 bit 20, set = wave32 (`fspx/<name>.json` `wave32`). Only a strict marker (`WAVE64_RE` against wave32, `WAVE32_RE` against wave64) contradicts it and raises `Unsupported`; a `_b64` op on `vcc` or `exec` does not, since these programs move `vcc` as an ordinary SGPR pair. Without that field the heuristic stays. Confirmed on the 29 programs of 1.0.2.1: strict markers never contradict the bit, the `RSRC1` VGPR granule fits it in all 21 programs that decode cleanly, and `PSV0` lane counts agree with it in all 5 that state one ([fspx.md](fspx.md), "Kind 0: dispatch state"). Translated with the bit, the 4 programs the heuristic got wrong change size, and the other 22 translated modules are byte-identical. CPU-checked by `tests/semantic/test_fspx_wave_size.py`, including a `v_readlane_b32` whose result differs between the two sizes; `vk_pipeline_check` builds all 26 modules. Not GPU-checked on these programs' own data. Confirmed across all 26,503 corpus blobs with 0 contradictions against GFX10 SOP1/SOP2/SOPC/VOP3 encodings: 23,841 wave64 (1,154 CS, 195 GS, 9,282 MS, 10,974 PS, 2,236 VS) and 2,662 wave32 (1,535 CS, 1,127 PS); the code-marker heuristic alone misclassified 2,287 markerless wave64 shaders as wave32 (287 CS: 162 straight-line and 125 branchy, including 11 with `v_readlane_b32`, 35 `v_readfirstlane_b32`, 29 `ds_swizzle_b32`, 14 `s_barrier`; 943 PS: 906 straight-line and 37 branchy; 1,057 VS: 1,020 straight-line and 37 branchy); CPU-checked by `tests/test_fssm_header.py` and `tests/test_fssm_wave_size.py`. Until 2026-11-21 a mask-only wave64 program with no EXEC markers was translated as wave32, so `s_bcnt1_i32_b64` counted one half (#210). GPU-checked with `runtime/test/shaders/cs_w64_mask_detect.asm` (48 set bits of `(lane & 5) != 0`) on NVIDIA GeForce RTX 5060 under `LEONIDA_W64_EMULATE=1`. The hardware lane is exact in compute and mesh shaders (LocalInvocationIndex mod 64 or 32) and is used by `v_mbcnt` and EXEC writes. In other stages it's the subgroup lane. Constant EXEC writes (`s_mov_b32 exec_lo/exec_hi, K`) set each lane from its own bit of K, as `(K >> lane) & 1` (shift and mask: Intel's Windows driver evaluated `OpBitFieldUExtract` of a constant that fits in 16 bits with the lane taken mod 16, so `exec_lo = 0xffff` ran all 32 lanes; GPU-checked with `runtime/test/shaders/cs_exec_const.asm` on Intel UHD Graphics 770, driver 32.0.101.6129, and NVIDIA GeForce RTX 4080 SUPER); before, any non-zero constant turned every lane on. A register written to `exec_hi` sets lanes 32–63 only. VCC's halves follow the same rule while VCC holds a lane mask: a 32-bit write to `vcc_lo` sets lanes 0–31 of the mask and one to `vcc_hi` lanes 32–63 (until 2026-11-22 a `vcc_lo` write set all 64 lanes and a `vcc_hi` write never reached the mask that `s_cbranch_vccz`/`v_cndmask` read; CPU-checked by `tests/semantic/test_wave64_vcc_half_write.py`, not GPU-checked). Mask and `0`/`-1` half-writes to `vcc_lo`/`vcc_hi` keep VCC tracked as a lane mask across subsequent ops (`s_bcnt1_i32_b64`, further half-writes), whereas plain-data writes (`s_buffer_load_dword vcc_lo`, `s_load_dword`, scalar ALU, non-mask constants) end VCC's mask state and store the scalar word across all 64 lanes instead of updating only one mask half (confirmed on 1 wave64 PS in the 1.0.2.1 corpus and `tests/semantic/test_wave64_vcc_half_write.py`). GPU-checked with `runtime/test/shaders/cs_exec64.asm`: lanes 16–47 enabled from two constants, exact on a 32-wide-subgroup GPU. Still approximate on 32-wide subgroups: cross-lane ops between the two halves of a wave64 (readlane/permlane/DPP/shuffles across lane 31/32, wave-wide reductions). The metadata index marks every wave64 shader so a runtime can request `requiredSubgroupSize = 64` where supported (AMD), which makes those exact too. | |
| 431 | | Lane select (`v_readlane_b32` / `v_writelane_b32`) | The lane is **S1[4:0] in wave32** and S1[5:0] in wave64, from an SGPR or a constant, and EXEC is ignored (RDNA 3 ISA guide pseudocode for both opcodes; RDNA 2 has the same encoding and gives no pseudocode). **Until #488 (SHADER-52) a wave32 shader masked with 63 as well**: a lane select of 32 or more wrote no lane, and a read shuffled from a lane past the end of a 32-wide subgroup, which SPIR-V leaves undefined (NVIDIA wraps it, so reads happened to come out right there). Found by the FUZZ-7 cross-lane fuzzer: 23 of 100 random wave32 programs, each minimized to `s_mov_b32 s28, K; v_writelane_b32 vD, x, s28` with K ≥ 32. GPU-checked with `runtime/test/shaders/cs_w32_lane_wrap.asm` (25 16 777 777) on NVIDIA GeForce RTX 5060 (#488) and RTX 4090 (subgroup 32, driver 621.14); `tests/test_translate.py` checks the masks in the SPIR-V, and `tests/semantic/test_wave32_lane_select.py` runs the shader across 32 lanes, where a mask of 63 is an out-of-range shuffle. | | 432 | | Lane select (`v_readlane_b32` / `v_writelane_b32`) | The lane is **S1[4:0] in wave32** and S1[5:0] in wave64, from an SGPR or a constant, and EXEC is ignored (RDNA 3 ISA guide pseudocode for both opcodes; RDNA 2 has the same encoding and gives no pseudocode). **Until #488 (SHADER-52) a wave32 shader masked with 63 as well**: a lane select of 32 or more wrote no lane, and a read shuffled from a lane past the end of a 32-wide subgroup, which SPIR-V leaves undefined (NVIDIA wraps it, so reads happened to come out right there). Found by the FUZZ-7 cross-lane fuzzer: 23 of 100 random wave32 programs, each minimized to `s_mov_b32 s28, K; v_writelane_b32 vD, x, s28` with K ≥ 32. GPU-checked with `runtime/test/shaders/cs_w32_lane_wrap.asm` (25 16 777 777) on NVIDIA GeForce RTX 5060 (#488) and RTX 4090 (subgroup 32, driver 621.14); `tests/test_translate.py` checks the masks in the SPIR-V, and `tests/semantic/test_wave32_lane_select.py` runs the shader across 32 lanes, where a mask of 63 is an out-of-range shuffle. | |
| 432 | | First active lane in a vertex shader (`v_readfirstlane_b32`, MoltenVK) | A native `v_readfirstlane_b32` is a ballot of the EXEC lanes, its lowest set bit, and a shuffle from that lane (lane 0 when no lane is on). **In a vertex shader the lowest bit is taken with `FindILsb` over the ballot's four words** (the lowest non-zero word wins), not with `OpGroupNonUniformBallotFindLSB`. The two give the same lane, because a ballot has no bit at or above the subgroup size. Other stages keep `BallotFindLSB`; the `--wave64-emulate` form already used `FindILsb` on its two mask words. Why: MoltenVK lowers `BallotFindLSB`, like the `SubgroupSize` built-in, to Metal's `threads_per_simdgroup` input, which a vertex function can't declare ("invalid 'threads_per_simdgroup' attribute for input declaration in a vertex function"), so every VS with a readfirstlane failed to compile there. **Confirmed on an Apple M4 (MoltenVK 1.4.2):** hand-written VS with `subgroupBallotFindLSB` or `gl_SubgroupSize` fail, and ballot, shuffle, broadcast-first, elect, votes, and ballot + `findLSB` + shuffle (32- and 64-lane forms) create. Corpus (1.0.2.1, translated from `4eb6155d`): 572 of the 2,236 VS contain `v_readfirstlane_b32`, and exactly those 572 modules change; all 2,236 stay `spirv-val`-valid. VS pipelines on the M4 go from 667 to 672 of 2,236 on main (the rest fail on the subgroup lane built-in, #1784), and from 1,662 to 2,233 with #1784's vertex-subgroup workaround (its flag is not on main) (the 571 `threads_per_simdgroup` failures are gone). `tests/semantic/test_vs_readfirstlane.py` runs it on the wave interpreter with the first EXEC lane in word 0 and word 1. | | 433 | | First active lane in a vertex shader (`v_readfirstlane_b32`, MoltenVK) | A native `v_readfirstlane_b32` is a ballot of the EXEC lanes, its lowest set bit, and a shuffle from that lane (lane 0 when no lane is on). **In a vertex shader the lowest bit is taken with `FindILsb` over the ballot's four words** (the lowest non-zero word wins), not with `OpGroupNonUniformBallotFindLSB`. The two give the same lane, because a ballot has no bit at or above the subgroup size. Other stages keep `BallotFindLSB`; the `--wave64-emulate` form already used `FindILsb` on its two mask words. Why: MoltenVK lowers `BallotFindLSB`, like the `SubgroupSize` built-in, to Metal's `threads_per_simdgroup` input, which a vertex function can't declare ("invalid 'threads_per_simdgroup' attribute for input declaration in a vertex function"), so every VS with a readfirstlane failed to compile there. **Confirmed on an Apple M4 (MoltenVK 1.4.2):** hand-written VS with `subgroupBallotFindLSB` or `gl_SubgroupSize` fail, and ballot, shuffle, broadcast-first, elect, votes, and ballot + `findLSB` + shuffle (32- and 64-lane forms) create. Corpus (1.0.2.1, translated from `4eb6155d`): 572 of the 2,236 VS contain `v_readfirstlane_b32`, and exactly those 572 modules change; all 2,236 stay `spirv-val`-valid. VS pipelines on the M4 go from 667 to 672 of 2,236 on main (the rest fail on the subgroup lane built-in, #1784), and from 1,662 to 2,233 with #1784's vertex-subgroup workaround (its flag is not on main) (the 571 `threads_per_simdgroup` failures are gone). `tests/semantic/test_vs_readfirstlane.py` runs it on the wave interpreter with the first EXEC lane in word 0 and word 1. | |
| 433 | | Wave64 emulation (`--wave64-emulate`) | Wave64 compute and mesh shaders exact on **any** subgroup size (32-wide NVIDIA, Intel, AMD in wave32 mode), with no subgroup operation at all. One invocation is still one lane. Everything a lane needs from the rest of its wave goes through a Workgroup buffer `%x_buf`: votes (`s_cbranch_vccz/vccnz/execz/execnz`, SCC of mask ops, `s_cmp` of masks), whole-mask words (`s_bcnt1`, `s_ff1`, `v_mbcnt`), `v_readlane`, `v_readfirstlane`, `ds_bpermute`, `ds_swizzle`, `v_permlane16/x16`. The program runs in rounds: in each round every wave that is neither done nor waiting at `s_barrier` runs one segment of its program (a basic block, cut at each cross-lane op), then the whole workgroup meets at one `OpControlBarrier` (Workgroup, AcquireRelease, workgroup + uniform + image memory) that sits in uniform control flow, because every invocation runs every round. A cross-lane op ends its segment after the lane has stored its value (per-lane data, double-buffered by round parity) or ORed its bit (two mask words per wave, three slots by round mod 3, each slot cleared two rounds after it was read); the code after it runs one round later, when all 64 lanes have written. SSA values live across a cut go through Function variables. `s_barrier` is a scheduler state: the wave stops running segments until every wave that isn't done is waiting, which is also how hardware counts finished waves. A memory access that conflicts with an earlier one in the same segment (read after write, write after read, write after write; LDS and buffer/image memory separately) starts a new round, so two halves of a wave in different subgroups access memory in instruction order, as the lanes of one hardware wave do. A scalar load (`s_load*`, `s_buffer_load*`) counts as a buffer read: until #1587 it was left out, so a store and a later scalar load of the same address shared a segment and the half in the other subgroup could load before this half had stored (`valu_fuzz.py --family mem --emulate`: lanes 32-63 read the fill pattern after an `s_buffer_load`/`s_load` of the slot lane 0 had written, on RDNA1 RADV and an RTX 5060; `v_readfirstlane_b32`, which gives that slot, already reads the whole wave). Pinned by `tests/semantic/test_w64x_scalar_load_order.py` (no segment of the emitted rounds accesses buffer memory after a write or writes after a read; three of its five cases fail without the rule). Confirmed by that CPU test and the ordering argument above; the race does not show on an RX 7900 XTX (AMD 26.10.1 LLPC, Windows 11): `valu_fuzz.py --family mem --seed 5 --programs 21 --wave 64 --emulate` matches 21/21 before and after the rule (3 runs each), so a GPU reproduction on RDNA1/RADV (where #1587 was found) is still pending. Not ordered: sampling an image the wave wrote. The missing lanes of a partial last wave read as 0. Without the flag the output is unchanged, apart from two fixes that apply to every wave64 compute/mesh shader: `v_writelane_b32` selects the lane by the wave lane (on a 32-wide subgroup writes to lanes 32–63 were lost; `cs_w64x_writelane`), and `ds_bpermute_b32` (see the LDS row). Fewer rounds, same results: a whole-mask read (`s_bcnt1`, `v_mbcnt_lo/hi`, ...) of the value of the same register (or EXEC) that an earlier read in the block already exchanged reuses that exchange (the value's identity is the SSA id last stored to the register, forgotten at block start and at any label); and a block that ends in a voted branch (`s_cbranch_vccz/vccnz/execz/execnz`) runs its successor in the round that reads the vote, since that segment only reads the vote and picks the next block (an inner loop in the scheduler, flag `%x_chain`). Both rules are pinned by `cs_w64x_mask_reuse` (a mask register and EXEC rewritten between reads), `cs_w64x_mask_reuse2` (EXEC read twice, a read after a buffer store, one half of a mask pair rewritten while the other is kept, a voted branch whose successor starts with a load of the other half's earlier store) and `cs_w64x_chain_barrier` (a voted branch whose successor starts with `s_barrier`, two waves): expected values from the ISA, first run on the AMD 880M with its native 64-wide subgroup, then emulated on both GPUs; `tests/test_translate.py` counts the exchanges in the SPIR-V (one per value, a new one after a rewrite of the register or EXEC), and the translator refuses (`Unsupported`) a voted branch whose segment was not started by the vote's own round. Under `--wave64-emulate`, `tools/wave64_emulate_opt.py` runs three exact CFG/dataflow passes to eliminate redundant scheduler rounds and global `OpSwitch` blow-up (#884): (1) backward `SCC` liveness skips `scc_from_mask` / `scc_any_half` votes on lane-mask ops (`s_*_saveexec_*`, `s_andn1/andn2_wrexec_*`, `s_and/or/xor/andn2/orn2/nand/nor/xnor/not_b64`, `s_wqm_*`) whenever `SCC` is dead-out (never read before an unconditional overwrite or `s_endpgm`), (2) safe lane-local `s_cbranch_execz`/`execnz` region folding inlines single-entry, single-exit post-dominated regions with no cross-lane ops, no `s_barrier`, no unmasked side effects, no `write_all_lanes` mask spills, no `EXEC`-widening, no live-out scalars, and for each memory domain (`mem`/`lds`) either read-only accesses or an acyclic single write/atomic behind `if (%active)` (issuing any uniform `x_memory_order` split/barrier before the branch — including scalar `s_load*`/`s_buffer_load*` per #1587 — and chaining single-predecessor continuations), and (3) structured emulation (`plan_structured_emulation`, `control_flow = "emulated wave64 structured"`) removes the global round-loop `OpSwitch` on multi-superblock reducible CFGs without non-uniform 32-bit half-mask SCC: single-wave workgroups (`<= 64` threads) run 100% inline structured SPIR-V with direct workgroup barriers (`0` `OpSwitch`, `0` `x_spill`, strictly monotone GEN/KILL 4-bit `dirty_in` memory ordering across blocks and loop back-edges), while multi-wave workgroups (`> 64` threads, without divergent `s_barrier`) emit post-dominating spine blocks and barrier-free guards/loops (including live-out scalars, single-write stores, `EXEC`-widening, and read-only loops) inline and isolate any remaining wave-divergent barrier regions into local mini-schedulers (or a tail scheduler at early `s_endpgm`). Checked on the CPU by `tests/semantic/test_wave64_emulate_opt.py` (40/64/128/256-thread workgroup interpreter with strict uniform barrier checks, ScreenProbes-shaped chains, nested/reused `saveexec` folds, single-store WAR/RAW ordering, single-wave `inline_all` loop-carried WAR, monotone `dirty_in` regression after `x_round`, multi-wave `structured_hybrid` + local `mini_scheduler`, divergent `s_barrier` fallback, `cs_w64x_saveexec_b64.s` fixture, and negative controls; **not yet GPU-verified** for the structured emulation pass). In addition, `wave64_emulate_opt.py` excludes lane-mask `s_flbit_i32_b32`/`s_flbit_i32` and mixed mask+data `s_cmp_eq_u64`/`s_cmp_lg_u64` from folded/sync-free blocks and `Gen.x_memory_order` skips `ds_nop` (matching `_x_memory_order_access`), pinned by `tests/semantic/test_wave64_emulate_barriers.py` (CPU workgroup interpreter only, not GPU-checked). (1) backward `SCC` liveness skips `scc_from_mask` / `scc_any_half` votes on lane-mask ops (`s_*_saveexec_*`, `s_andn1/andn2_wrexec_*`, `s_and/or/xor/andn2/orn2/nand/nor/xnor/not_b64`, `s_wqm_*`) whenever `SCC` is dead-out (never read before an unconditional overwrite or `s_endpgm`), and (2) safe lane-local `s_cbranch_execz`/`execnz` region folding inlines single-entry, single-exit post-dominated regions with no cross-lane ops, no `s_barrier`, no memory/LDS writes, no unmasked side effects, no `write_all_lanes` mask spills, no `EXEC`-widening, and no live-out scalars behind `if (%active)` (issuing any uniform `x_memory_order` split before the branch — including scalar `s_load*`/`s_buffer_load*` per #1587 — and chaining single-predecessor continuations), keeping all 64 lanes of each wave in the same scheduler round. Checked on the CPU by `tests/semantic/test_wave64_emulate_opt.py` (64-thread and 128-thread workgroup interpreter with uniform barrier checks, ScreenProbes-shaped chains, nested/reused `saveexec` folds, internal loop, `cs_w64x_saveexec_b64.s` fixture, RAW memory/scalar-load ordering, and negative controls for live-out scalars, stores, cross-lane ops, and EXEC-widening). `scripts/bench_wave64.py` times `cs_bench_mix` native and emulated and checks the emulated output bytes against the native AMD run. Cost: one workgroup barrier per segment, and `%x_buf` = (2·L + 6·W + 7) dwords for L invocations in W waves, counted in `lds_bytes`. GPU-checked on NVIDIA GeForce RTX 5070 Laptop (subgroup 32, driver 617.42) and AMD Radeon 880M (subgroup 64, AMD driver 26.11.2 LLPC): `check.py` 38/39 (the mesh test runs in the other script) and `scripts/run_gpu_tests.py` 40/40 on both with `LEONIDA_W64_EMULATE=1`, including every wave64 test (`cs_wavemask`, `cs_wave64_ballot`, `cs_wm_*`) and the cross-half suite `cs_w64x_*` / `ms_w64x_ballot`: readlane and writelane at lanes ≥ 32, readfirstlane with only upper lanes active, branches voted by one lane of either half, ballot + `v_mbcnt_lo/hi` compaction over 64 lanes (also in a mesh shader, 4096/4096 pixels), a 128-thread workgroup whose two waves take different branches, `s_barrier` between waves with different loop counts, LDS read-after-write and write-after-read across the halves without a barrier, a load, ballot and load in one block, and a partial wave (group 40). Without the flag the same RTX 5070 passes 19/37 (the wave64 tests skip there). Not covered: VS/PS/GS (no workgroup memory or barrier there). Known driver bug: AMD's Windows shader compiler for RDNA2 crashes (access violation in `vkCreateComputePipelines`) on many emulated compute shaders with LDS (#857: drivers 32.0.21030 to 32.0.21045.29003, iGPUs and RX 6000; 23.20.44, RDNA3, RDNA4, RADV and NVIDIA are fine), so `make_game.py --wave64-emulate auto` leaves emulation off when the runtime's GPU is such a device and runs wave64 natively (`rdna2_amd_windows` in `tools/vk_subgroup_info.py`, by PCI device ID and driver ID). | | 434 | | Wave64 emulation (`--wave64-emulate`) | Wave64 compute and mesh shaders exact on **any** subgroup size (32-wide NVIDIA, Intel, AMD in wave32 mode), with no subgroup operation at all. One invocation is still one lane. Everything a lane needs from the rest of its wave goes through a Workgroup buffer `%x_buf`: votes (`s_cbranch_vccz/vccnz/execz/execnz`, SCC of mask ops, `s_cmp` of masks), whole-mask words (`s_bcnt1`, `s_ff1`, `v_mbcnt`), `v_readlane`, `v_readfirstlane`, `ds_bpermute`, `ds_swizzle`, `v_permlane16/x16`. The program runs in rounds: in each round every wave that is neither done nor waiting at `s_barrier` runs one segment of its program (a basic block, cut at each cross-lane op), then the whole workgroup meets at one `OpControlBarrier` (Workgroup, AcquireRelease, workgroup + uniform + image memory) that sits in uniform control flow, because every invocation runs every round. A cross-lane op ends its segment after the lane has stored its value (per-lane data, double-buffered by round parity) or ORed its bit (two mask words per wave, three slots by round mod 3, each slot cleared two rounds after it was read); the code after it runs one round later, when all 64 lanes have written. SSA values live across a cut go through Function variables. `s_barrier` is a scheduler state: the wave stops running segments until every wave that isn't done is waiting, which is also how hardware counts finished waves. A memory access that conflicts with an earlier one in the same segment (read after write, write after read, write after write; LDS and buffer/image memory separately) starts a new round, so two halves of a wave in different subgroups access memory in instruction order, as the lanes of one hardware wave do. A scalar load (`s_load*`, `s_buffer_load*`) counts as a buffer read: until #1587 it was left out, so a store and a later scalar load of the same address shared a segment and the half in the other subgroup could load before this half had stored (`valu_fuzz.py --family mem --emulate`: lanes 32-63 read the fill pattern after an `s_buffer_load`/`s_load` of the slot lane 0 had written, on RDNA1 RADV and an RTX 5060; `v_readfirstlane_b32`, which gives that slot, already reads the whole wave). Pinned by `tests/semantic/test_w64x_scalar_load_order.py` (no segment of the emitted rounds accesses buffer memory after a write or writes after a read; three of its five cases fail without the rule). Confirmed by that CPU test and the ordering argument above; the race does not show on an RX 7900 XTX (AMD 26.10.1 LLPC, Windows 11): `valu_fuzz.py --family mem --seed 5 --programs 21 --wave 64 --emulate` matches 21/21 before and after the rule (3 runs each), so a GPU reproduction on RDNA1/RADV (where #1587 was found) is still pending. Not ordered: sampling an image the wave wrote. The missing lanes of a partial last wave read as 0. Without the flag the output is unchanged, apart from two fixes that apply to every wave64 compute/mesh shader: `v_writelane_b32` selects the lane by the wave lane (on a 32-wide subgroup writes to lanes 32–63 were lost; `cs_w64x_writelane`), and `ds_bpermute_b32` (see the LDS row). Fewer rounds, same results: a whole-mask read (`s_bcnt1`, `v_mbcnt_lo/hi`, ...) of the value of the same register (or EXEC) that an earlier read in the block already exchanged reuses that exchange (the value's identity is the SSA id last stored to the register, forgotten at block start and at any label); and a block that ends in a voted branch (`s_cbranch_vccz/vccnz/execz/execnz`) runs its successor in the round that reads the vote, since that segment only reads the vote and picks the next block (an inner loop in the scheduler, flag `%x_chain`). Both rules are pinned by `cs_w64x_mask_reuse` (a mask register and EXEC rewritten between reads), `cs_w64x_mask_reuse2` (EXEC read twice, a read after a buffer store, one half of a mask pair rewritten while the other is kept, a voted branch whose successor starts with a load of the other half's earlier store) and `cs_w64x_chain_barrier` (a voted branch whose successor starts with `s_barrier`, two waves): expected values from the ISA, first run on the AMD 880M with its native 64-wide subgroup, then emulated on both GPUs; `tests/test_translate.py` counts the exchanges in the SPIR-V (one per value, a new one after a rewrite of the register or EXEC), and the translator refuses (`Unsupported`) a voted branch whose segment was not started by the vote's own round. Under `--wave64-emulate`, `tools/wave64_emulate_opt.py` runs three exact CFG/dataflow passes to eliminate redundant scheduler rounds and global `OpSwitch` blow-up (#884): (1) backward `SCC` liveness skips `scc_from_mask` / `scc_any_half` votes on lane-mask ops (`s_*_saveexec_*`, `s_andn1/andn2_wrexec_*`, `s_and/or/xor/andn2/orn2/nand/nor/xnor/not_b64`, `s_wqm_*`) whenever `SCC` is dead-out (never read before an unconditional overwrite or `s_endpgm`), (2) safe lane-local `s_cbranch_execz`/`execnz` region folding inlines single-entry, single-exit post-dominated regions with no cross-lane ops, no `s_barrier`, no unmasked side effects, no `write_all_lanes` mask spills, no `EXEC`-widening, no live-out scalars, and for each memory domain (`mem`/`lds`) either read-only accesses or an acyclic single write/atomic behind `if (%active)` (issuing any uniform `x_memory_order` split/barrier before the branch — including scalar `s_load*`/`s_buffer_load*` per #1587 — and chaining single-predecessor continuations), and (3) structured emulation (`plan_structured_emulation`, `control_flow = "emulated wave64 structured"`) removes the global round-loop `OpSwitch` on multi-superblock reducible CFGs without non-uniform 32-bit half-mask SCC: single-wave workgroups (`<= 64` threads) run 100% inline structured SPIR-V with direct workgroup barriers (`0` `OpSwitch`, `0` `x_spill`, strictly monotone GEN/KILL 4-bit `dirty_in` memory ordering across blocks and loop back-edges), while multi-wave workgroups (`> 64` threads) emit post-dominating spine blocks and barrier-free guards/loops (including live-out scalars, single-write stores, `EXEC`-widening, and read-only loops) inline and isolate any remaining wave-divergent barrier regions into local mini-schedulers (or a tail scheduler from the first early `s_endpgm`, or the first `s_barrier` under a guard or in a loop, to the end: waves on different paths may meet at different `s_barrier` sites, which only the rounds model; the NGG mesh epilogue, `s_cbranch_vccnz` over an `s_barrier`, is the common case). Checked on the CPU by `tests/semantic/test_wave64_emulate_opt.py` (40/64/128/256-thread workgroup interpreter with strict uniform barrier checks, ScreenProbes-shaped chains, nested/reused `saveexec` folds, single-store WAR/RAW ordering, single-wave `inline_all` loop-carried WAR, monotone `dirty_in` regression after `x_round`, multi-wave `structured_hybrid` + local `mini_scheduler`, divergent `s_barrier` in the tail rounds, guarded `s_barrier` epilogue, `cs_w64x_saveexec_b64.s` fixture, and negative controls; **not yet GPU-verified** for the structured emulation pass). In addition, `wave64_emulate_opt.py` excludes lane-mask `s_flbit_i32_b32`/`s_flbit_i32` and mixed mask+data `s_cmp_eq_u64`/`s_cmp_lg_u64` from folded/sync-free blocks and `Gen.x_memory_order` skips `ds_nop` (matching `_x_memory_order_access`), pinned by `tests/semantic/test_wave64_emulate_barriers.py` (CPU workgroup interpreter only, not GPU-checked). (1) backward `SCC` liveness skips `scc_from_mask` / `scc_any_half` votes on lane-mask ops (`s_*_saveexec_*`, `s_andn1/andn2_wrexec_*`, `s_and/or/xor/andn2/orn2/nand/nor/xnor/not_b64`, `s_wqm_*`) whenever `SCC` is dead-out (never read before an unconditional overwrite or `s_endpgm`), and (2) safe lane-local `s_cbranch_execz`/`execnz` region folding inlines single-entry, single-exit post-dominated regions with no cross-lane ops, no `s_barrier`, no memory/LDS writes, no unmasked side effects, no `write_all_lanes` mask spills, no `EXEC`-widening, and no live-out scalars behind `if (%active)` (issuing any uniform `x_memory_order` split before the branch — including scalar `s_load*`/`s_buffer_load*` per #1587 — and chaining single-predecessor continuations), keeping all 64 lanes of each wave in the same scheduler round. Checked on the CPU by `tests/semantic/test_wave64_emulate_opt.py` (64-thread and 128-thread workgroup interpreter with uniform barrier checks, ScreenProbes-shaped chains, nested/reused `saveexec` folds, internal loop, `cs_w64x_saveexec_b64.s` fixture, RAW memory/scalar-load ordering, and negative controls for live-out scalars, stores, cross-lane ops, and EXEC-widening). `scripts/bench_wave64.py` times `cs_bench_mix` native and emulated and checks the emulated output bytes against the native AMD run. Cost: one workgroup barrier per segment, and `%x_buf` = (2·L + 6·W + 7) dwords for L invocations in W waves, counted in `lds_bytes`. GPU-checked on NVIDIA GeForce RTX 5070 Laptop (subgroup 32, driver 617.42) and AMD Radeon 880M (subgroup 64, AMD driver 26.11.2 LLPC): `check.py` 38/39 (the mesh test runs in the other script) and `scripts/run_gpu_tests.py` 40/40 on both with `LEONIDA_W64_EMULATE=1`, including every wave64 test (`cs_wavemask`, `cs_wave64_ballot`, `cs_wm_*`) and the cross-half suite `cs_w64x_*` / `ms_w64x_ballot`: readlane and writelane at lanes ≥ 32, readfirstlane with only upper lanes active, branches voted by one lane of either half, ballot + `v_mbcnt_lo/hi` compaction over 64 lanes (also in a mesh shader, 4096/4096 pixels), a 128-thread workgroup whose two waves take different branches, `s_barrier` between waves with different loop counts, LDS read-after-write and write-after-read across the halves without a barrier, a load, ballot and load in one block, and a partial wave (group 40). Without the flag the same RTX 5070 passes 19/37 (the wave64 tests skip there). Not covered: VS/PS/GS (no workgroup memory or barrier there). Known driver bug: AMD's Windows shader compiler for RDNA2 crashes (access violation in `vkCreateComputePipelines`) on many emulated compute shaders with LDS (#857: drivers 32.0.21030 to 32.0.21045.29003, iGPUs and RX 6000; 23.20.44, RDNA3, RDNA4, RADV and NVIDIA are fine), so `make_game.py --wave64-emulate auto` leaves emulation off when the runtime's GPU is such a device and runs wave64 natively (`rdna2_amd_windows` in `tools/vk_subgroup_info.py`, by PCI device ID and driver ID). | |
| 434 | | Workgroup memory limit (SHADER-309) | A compute shader's Workgroup variables, the LDS array plus `%x_buf` (the wave64 exchange, 2·L + 6·W + 7 dwords, or the 3 barrier-round counts, which move into the LDS array when they would push the total past 16,384 B: see "Barrier-round count in LDS (SHADER-579)"), must fit in the device's `maxComputeSharedMemorySize`. `spirv-val` does not check device limits, and RADV (Mesa 27.0.0-devel, RX 7600) dies with SIGFPE in `vkCreateComputePipelines` on a module 4 bytes over 64 KiB (#1721, hand-built repro by YaBulochka). The limit differs per device: 65536 on RADV and NVIDIA, 32768 on the AMD Windows driver (RX 9070 XT, 32.0.32029.2010) and Intel (UHD 770, 101.7092), measured by towade in #1745; the Vulkan minimum is 16384. The translator runs offline, so it has two parts. (1) `rdna2spirv.py` keeps every module under a hard cap, `MAX_SHARED_BYTES` (`--max-shared-memory`, default 65536): the LDS array is the program's need (RSRC2 LDS_SIZE, or the end of the furthest constant-offset access, counted exactly from the offset and the access width: a b32 at offset 65,532 ends at 16,384 dwords) rounded up to a power of two; when that plus `%x_buf` is over the cap but the need still fits, the array shrinks to the RSRC2 allocation and its accesses are bounds-checked (below); when the need itself does not fit (a 64 KiB LDS under `--wave64-emulate`) the shader is refused (`Unsupported`, with the byte counts). The array is clipped to 16,384 dwords, but an RSRC2 allocation over the cap (LDS_SIZE above 128 units, so 66,048 B or more) is counted at its full size and refused, native or emulated, instead of being cut. LDS bounds: RDNA2 LDS does not wrap, and an access outside the workgroup's allocation reads 0 and its write is dropped (RDNA2 ISA sections 3.6.1 and 3.6.6). The wrapped power-of-two array aliases such an access onto a valid word, so when a program's constant offsets reach past its RSRC2 allocation, or the array was shrunk, the array is the allocation and `Gen.lds_access` checks every dword (`index < allocation`, else a read or an atomic's old value is 0 and the write or atomic is skipped): `ds_read*`/`ds_write*` of every width (b64/b96/b128 and read2/write2 per dword), the sub-dword reads and writes, every LDS atomic, `ds_cmpst`, `ds_mskor`, `ds_wrxchg*`. `ds_swizzle`/`ds_bpermute`/`ds_permute` do not use `%lds`; `ds_append`/`ds_consume` were already refused. Every other shader keeps the wrapped array and emits no check, as before. **No game shader takes this path.** Counted over a 1.0.2.1 corpus by towade (#1882, counts only), and again at `main` `aa2988cc` by running `translate()` on every CS: with the exact need (offset + access width), none of the 485 LDS-using CS reaches past its RSRC2 allocation with a constant offset, and none is shrunk, natively or with `--wave64-emulate`. So none gets a bounds check (no `OpULessThan` added), and only the synthetic tests below exercise it. The earlier "16 of 486" came from the older offset + 4-dword estimate; at `aa2988cc` that bound flags 37 of the 485, all inside their allocation. Hypothesis, not yet counted over the corpus: the 16 of 486 LDS-using CS that index past LDS_SIZE with constant offsets (the Compute shaders row) now read 0 there, as the ISA says, where they used to read the wrapped word. Counted over a 1.0.2.1 corpus by towade (#1882, counts only): with the exact need (offset + access width) none of the 485 LDS-using CS reaches past its RSRC2 allocation with a constant offset, so none gets a bounds check (no `OpULessThan` added, native or emulated); the "16 of 486" in the Compute shaders row came from the older offset + 4-dword estimate. `%x_buf` is already sized to the workgroup's waves, so it has nothing to give back. `lds_bytes` in `index.json` is the module's whole Workgroup total (LDS, `%x_buf`, a mesh shader's `%ms_counts`). (2) The D3D12 shim's `create_compute` compares `lds_bytes` with the device's `maxComputeSharedMemorySize` and refuses the pipeline with a log line (`E_NOTIMPL`) instead of creating an invalid one. Pinned by `tests/semantic/test_cs_shared_memory_limit.py` (Workgroup bytes counted from the emitted SPIR-V: under the cap unchanged, shrunk to the 51,200 B allocation and bounds-checked, the exact-cap boundary, an access ending at 64 KiB counted exactly, a 64 KiB LDS refused when emulated and accepted natively, a native 66,048 B allocation refused, run through `spirv_mini_interp`: an out-of-range write dropped with the word it would wrap to intact, out-of-range reads (b32, u16) giving 0, a b64 write straddling the allocation's end, out-of-range atomics returning 0 and changing nothing, and an in-range shader with no check; `lds_bytes` equal to the SPIR-V total) and `shader_library_test` (`lds_bytes` read from the index). Confirmed by those CPU tests only; GPU runs (RADV; AMD Windows and Intel at 32 KiB) are pending. Not covered: mesh shaders against `maxMeshSharedMemorySize`. | | 435 | | Workgroup memory limit (SHADER-309) | A compute shader's Workgroup variables, the LDS array plus `%x_buf` (the wave64 exchange, 2·L + 6·W + 7 dwords, or the 3 barrier-round counts, which move into the LDS array when they would push the total past 16,384 B: see "Barrier-round count in LDS (SHADER-579)"), must fit in the device's `maxComputeSharedMemorySize`. `spirv-val` does not check device limits, and RADV (Mesa 27.0.0-devel, RX 7600) dies with SIGFPE in `vkCreateComputePipelines` on a module 4 bytes over 64 KiB (#1721, hand-built repro by YaBulochka). The limit differs per device: 65536 on RADV and NVIDIA, 32768 on the AMD Windows driver (RX 9070 XT, 32.0.32029.2010) and Intel (UHD 770, 101.7092), measured by towade in #1745; the Vulkan minimum is 16384. The translator runs offline, so it has two parts. (1) `rdna2spirv.py` keeps every module under a hard cap, `MAX_SHARED_BYTES` (`--max-shared-memory`, default 65536): the LDS array is the program's need (RSRC2 LDS_SIZE, or the end of the furthest constant-offset access, counted exactly from the offset and the access width: a b32 at offset 65,532 ends at 16,384 dwords) rounded up to a power of two; when that plus `%x_buf` is over the cap but the need still fits, the array shrinks to the RSRC2 allocation and its accesses are bounds-checked (below); when the need itself does not fit (a 64 KiB LDS under `--wave64-emulate`) the shader is refused (`Unsupported`, with the byte counts). The array is clipped to 16,384 dwords, but an RSRC2 allocation over the cap (LDS_SIZE above 128 units, so 66,048 B or more) is counted at its full size and refused, native or emulated, instead of being cut. LDS bounds: RDNA2 LDS does not wrap, and an access outside the workgroup's allocation reads 0 and its write is dropped (RDNA2 ISA sections 3.6.1 and 3.6.6). The wrapped power-of-two array aliases such an access onto a valid word, so when a program's constant offsets reach past its RSRC2 allocation, or the array was shrunk, the array is the allocation and `Gen.lds_access` checks every dword (`index < allocation`, else a read or an atomic's old value is 0 and the write or atomic is skipped): `ds_read*`/`ds_write*` of every width (b64/b96/b128 and read2/write2 per dword), the sub-dword reads and writes, every LDS atomic, `ds_cmpst`, `ds_mskor`, `ds_wrxchg*`. `ds_swizzle`/`ds_bpermute`/`ds_permute` do not use `%lds`; `ds_append`/`ds_consume` were already refused. Every other shader keeps the wrapped array and emits no check, as before. **No game shader takes this path.** Counted over a 1.0.2.1 corpus by towade (#1882, counts only), and again at `main` `aa2988cc` by running `translate()` on every CS: with the exact need (offset + access width), none of the 485 LDS-using CS reaches past its RSRC2 allocation with a constant offset, and none is shrunk, natively or with `--wave64-emulate`. So none gets a bounds check (no `OpULessThan` added), and only the synthetic tests below exercise it. The earlier "16 of 486" came from the older offset + 4-dword estimate; at `aa2988cc` that bound flags 37 of the 485, all inside their allocation. Hypothesis, not yet counted over the corpus: the 16 of 486 LDS-using CS that index past LDS_SIZE with constant offsets (the Compute shaders row) now read 0 there, as the ISA says, where they used to read the wrapped word. Counted over a 1.0.2.1 corpus by towade (#1882, counts only): with the exact need (offset + access width) none of the 485 LDS-using CS reaches past its RSRC2 allocation with a constant offset, so none gets a bounds check (no `OpULessThan` added, native or emulated); the "16 of 486" in the Compute shaders row came from the older offset + 4-dword estimate. `%x_buf` is already sized to the workgroup's waves, so it has nothing to give back. `lds_bytes` in `index.json` is the module's whole Workgroup total (LDS, `%x_buf`, a mesh shader's `%ms_counts`). (2) The D3D12 shim's `create_compute` compares `lds_bytes` with the device's `maxComputeSharedMemorySize` and refuses the pipeline with a log line (`E_NOTIMPL`) instead of creating an invalid one. Pinned by `tests/semantic/test_cs_shared_memory_limit.py` (Workgroup bytes counted from the emitted SPIR-V: under the cap unchanged, shrunk to the 51,200 B allocation and bounds-checked, the exact-cap boundary, an access ending at 64 KiB counted exactly, a 64 KiB LDS refused when emulated and accepted natively, a native 66,048 B allocation refused, run through `spirv_mini_interp`: an out-of-range write dropped with the word it would wrap to intact, out-of-range reads (b32, u16) giving 0, a b64 write straddling the allocation's end, out-of-range atomics returning 0 and changing nothing, and an in-range shader with no check; `lds_bytes` equal to the SPIR-V total) and `shader_library_test` (`lds_bytes` read from the index). Confirmed by those CPU tests only; GPU runs (RADV; AMD Windows and Intel at 32 KiB) are pending. Not covered: mesh shaders against `maxMeshSharedMemorySize`. | |
| 435 | | Wave64 leading-bit scans | With `--wave64-emulate`, `s_flbit_i32_b32` and `s_flbit_i32` of a lane mask use the same wave-wide exchange as `s_bcnt1` and `s_ff1`. These reads prevent lane-local EXEC-zero folding and require synchronized scheduling in wave-divergent blocks. Plain scalar inputs still allow the fold. Hand-written compute shaders in `tests/semantic/test_wave64_emulate_opt.py` check EXECZ at 64 and 128 threads and a branch on SCC taken by just one wave at 128 threads. The strict CPU workgroup interpreter observes the unsigned scan of VCC_LO = 8 returning 28 in the expected invocations. Both scan forms pass `spirv-val --target-env vulkan1.2`. | | 436 | | Wave64 leading-bit scans | With `--wave64-emulate`, `s_flbit_i32_b32` and `s_flbit_i32` of a lane mask use the same wave-wide exchange as `s_bcnt1` and `s_ff1`. These reads prevent lane-local EXEC-zero folding and require synchronized scheduling in wave-divergent blocks. Plain scalar inputs still allow the fold. Hand-written compute shaders in `tests/semantic/test_wave64_emulate_opt.py` check EXECZ at 64 and 128 threads and a branch on SCC taken by just one wave at 128 threads. The strict CPU workgroup interpreter observes the unsigned scan of VCC_LO = 8 returning 28 in the expected invocations. Both scan forms pass `spirv-val --target-env vulkan1.2`. | |
| 436 | | Wave64 emulation: scalar exits from a folded EXECZ region | A folded lane-local `s_cbranch_execz`/`execnz` region may leave to its join from inside, for example `s_cmp` + `s_cbranch_scc0/scc1` straight to the label that restores EXEC. The ISA then skips the rest of the region for the whole wave. `find_local_exec_folds` in `tools/wave64_emulate_opt.py` builds the region's sub-CFG with an exit node for every edge to the join, so `cfg_structure.structure` puts each later block of the region behind a `%pc` guard; the exit node itself emits nothing. Before this the edge was dropped and the block after the branch ran whenever the lane was active. Confirmed on the CPU against the native wave64 translation and the ISA: `tests/semantic/test_wave64_emulate_opt.py` `test_folded_region_scalar_branch_to_join_skips_the_rest` (taken and not-taken `scc0`/`scc1`, 64 and 128 threads, the region still folded) fails before the change on the four taken cases. **Not GPU-verified.** | | 437 | | Wave64 emulation: scalar exits from a folded EXECZ region | A folded lane-local `s_cbranch_execz`/`execnz` region may leave to its join from inside, for example `s_cmp` + `s_cbranch_scc0/scc1` straight to the label that restores EXEC. The ISA then skips the rest of the region for the whole wave. `find_local_exec_folds` in `tools/wave64_emulate_opt.py` builds the region's sub-CFG with an exit node for every edge to the join, so `cfg_structure.structure` puts each later block of the region behind a `%pc` guard; the exit node itself emits nothing. Before this the edge was dropped and the block after the branch ran whenever the lane was active. Confirmed on the CPU against the native wave64 translation and the ISA: `tests/semantic/test_wave64_emulate_opt.py` `test_folded_region_scalar_branch_to_join_skips_the_rest` (taken and not-taken `scc0`/`scc1`, 64 and 128 threads, the region still folded) fails before the change on the four taken cases. **Not GPU-verified.** | |
| @@ -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 1301a4a49..e0df71085 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,10 +73,17 @@ 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 | ||
| 83 | `LEONIDA_INPUT_FILE=<path>` drives a run whose display takes no keyboard input (a headless session): every line | ||
| 84 | appended to that file names one button of the script's table (`a`, `down`, ...) and becomes a press at once, held | ||
| 85 | like a scripted one. The file is read again at most every 250 ms. It is for local runs only. | ||
| 86 | |||
| 77 | `scripts/build_runtime.ps1` (what `make_game.py` runs) builds the shim only on its CMake path, when Visual Studio's | 87 | `scripts/build_runtime.ps1` (what `make_game.py` runs) builds the shim only on its CMake path, when Visual Studio's |
| 78 | C++ CMake tools are installed. Its direct-`cl.exe` fallback compiles a fixed file list without the shim and warns | 88 | C++ CMake tools are installed. Its direct-`cl.exe` fallback compiles a fixed file list without the shim and warns |
| 79 | about it. | 89 | about it. |
| @@ -335,7 +345,7 @@ line is logged when it takes effect); tracking goes on underneath, so clearing i | |||
| 335 | | `LEONIDA_PROMPTS_SWITCH_MS` | `300` | shortest time between two changes of the active input family, 0..2000 ms | | 345 | | `LEONIDA_PROMPTS_SWITCH_MS` | `300` | shortest time between two changes of the active input family, 0..2000 ms | |
| 336 | | `LEONIDA_GAMEINPUT_THREAD` | `1` | `0` stops the background poll thread; only `rt::gameinput::poll()` then reads the pads (tests) | | 346 | | `LEONIDA_GAMEINPUT_THREAD` | `1` | `0` stops the background poll thread; only `rt::gameinput::poll()` then reads the pads (tests) | |
| 337 | | `LEONIDA_KEYBOARD_PAD` | `off` | `1` adds the [keyboard pad](#keyboard-pad), read while this process has focus; `always` reads keys whatever has focus | | 347 | | `LEONIDA_KEYBOARD_PAD` | `off` | `1` adds the [keyboard pad](#keyboard-pad), read while this process has focus; `always` reads keys whatever has focus | |
| 338 | | `LEONIDA_INPUT_SCRIPT` | unset | Comma-separated `button@seconds` entries, e.g. `a@2,a@4,start@6`. With SDL3 they drive the keyboard pad, which has to be enabled; without SDL3 they drive [one scripted pad](#scripted-input-without-sdl3), the only device. The first pad update (without SDL3, the first `GameInputCreate`) reads the script once at startup and starts the clock. `reload_config()` does not reread it. Each press lasts 300 ms. Buttons are `a b x y start back lb rb up down left right`. Spaces around entries are allowed. Empty entries, unknown buttons and invalid times (including negative or non-finite values) are counted and ignored. | | 348 | | `LEONIDA_INPUT_SCRIPT` | unset | Comma-separated `button@seconds` entries, e.g. `a@2,a@4,start@6`. With SDL3 they drive the keyboard pad, which has to be enabled; without SDL3 they drive [one scripted pad](#scripted-input-without-sdl3), the only device. The first pad update (without SDL3, the first `GameInputCreate`) reads the script once at startup and starts the clock. `reload_config()` does not reread it. Each press lasts 300 ms, or `hold` seconds when the entry is `button@seconds:hold` (more than 0, at most 600). With SDL3 a press then stays down until the title has read the pads six times since it began, but never past 5 s from its start (or its hold, if longer). A title reads its pad once a frame, so at a few seconds a frame a 300 ms press can fall between two reads and never arrive: on the retail title's "Couldn't autosave" prompt, three 300 ms `b` presses did nothing, while 120 presses 0.5 s apart got through; one `b@1100:3` replaces them. Buttons are `a b x y start back lb rb up down left right`. Spaces around entries are allowed. Empty entries, unknown buttons, invalid times (including negative or non-finite values) and invalid holds (0 or less, more than 600, not a number) are counted and ignored. | |
| 339 | | `LEONIDA_MOUSE_SENSITIVITY` | `1` | scales how far the mouse moves the keyboard pad's right stick, 0.1..10 | | 349 | | `LEONIDA_MOUSE_SENSITIVITY` | `1` | scales how far the mouse moves the keyboard pad's right stick, 0.1..10 | |
| 340 | 350 | ||
| 341 | SDL's own hints (`SDL_JOYSTICK_*`, see SDL's `SDL_hints.h`) also apply, for example `SDL_JOYSTICK_HIDAPI_PS5=0` to | 351 | 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..161e3153d --- /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_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 |