diff options
| author | OreoFR <29048345+OreoFR@users.noreply.github.com> | 2026-11-30 14:19:22 +0100 |
|---|---|---|
| committer | OreoFR <29048345+OreoFR@users.noreply.github.com> | 2026-11-30 14:19:22 +0100 |
| commit | e7d32a034a452b3442ee03a0df6fceab13cf2d81 (patch) | |
| tree | 7dba3f45303a0f170ded844696dcca6cf51eff8b /docs | |
| parent | dfad96ba7cf04946a87eb0ec7620623b24bb56cc (diff) | |
| parent | f9f3ec4c68de13f0fe167f7619072613ba77d1c8 (diff) | |
Merge origin/main (f9f3ec4c6) into the carry of #1994
Current main after #2566; no new conflicts on top of the earlier carry merge.
Co-authored-by: ShotTechOp <anurag7870977875@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/README.md | 26 | ||||
| -rw-r--r-- | docs/audio_hal_exe_calls.md | 12 | ||||
| -rw-r--r-- | docs/boot.md | 13 | ||||
| -rw-r--r-- | docs/boot_leads.md | 39 | ||||
| -rw-r--r-- | docs/change_gate.md | 313 | ||||
| -rw-r--r-- | docs/d3d12_command_objects.md | 83 | ||||
| -rw-r--r-- | docs/d3d12_vulkan.md | 400 | ||||
| -rw-r--r-- | docs/d3d12_xs_console_abi.md | 32 | ||||
| -rw-r--r-- | docs/d3d12_xs_surface.md | 4 | ||||
| -rw-r--r-- | docs/descriptor_lookup_ampere.md | 68 | ||||
| -rw-r--r-- | docs/design.md | 35 | ||||
| -rw-r--r-- | docs/directstorage.md | 22 | ||||
| -rw-r--r-- | docs/fspx.md | 45 | ||||
| -rw-r--r-- | docs/gameinput.md | 12 | ||||
| -rw-r--r-- | docs/gdk_public_reference.md | 101 | ||||
| -rw-r--r-- | docs/i18n/ar/quickstart.md | 4 | ||||
| -rw-r--r-- | docs/linux.md | 4 | ||||
| -rw-r--r-- | docs/measuring_fps.md | 93 | ||||
| -rw-r--r-- | docs/mobile.md | 2 | ||||
| -rw-r--r-- | docs/mod-menu.md | 57 | ||||
| -rw-r--r-- | docs/port_status.md | 6 | ||||
| -rw-r--r-- | docs/prompt_glyphs.md | 84 | ||||
| -rw-r--r-- | docs/running.md | 19 | ||||
| -rw-r--r-- | docs/runtime_ctest_hosts.md | 105 | ||||
| -rw-r--r-- | docs/test_inventory.md | 41 | ||||
| -rw-r--r-- | docs/testing.md | 13 |
26 files changed, 1489 insertions, 144 deletions
diff --git a/docs/README.md b/docs/README.md index a0eeee400..435291599 100644 --- a/docs/README.md +++ b/docs/README.md | |||
| @@ -10,7 +10,7 @@ method, scope and caveats. No game data is included. | |||
| 10 | |---|---| | 10 | |---|---| |
| 11 | | [design.md](design.md) | Overall project design, asset status, translator contract and open blockers. | | 11 | | [design.md](design.md) | Overall project design, asset status, translator contract and open blockers. | |
| 12 | | [related_projects.md](related_projects.md) | Prior art we may read and the licence boundaries on it. | | 12 | | [related_projects.md](related_projects.md) | Prior art we may read and the licence boundaries on it. | |
| 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, and a status table: BL-2, BL-5 and BL-6 are done, BL-3 and BL-4 have open pull requests, BL-1 waits for a retail confirmation. | |
| 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 | | [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. | |
| @@ -21,6 +21,8 @@ method, scope and caveats. No game data is included. | |||
| 21 | | [dev-tools.md](dev-tools.md) | The development CLI `scripts/dev.py`: `discover` (text or `--json`, schema version 1) lists the boot-trace analyzer and the guest-scene runner with their help commands and prerequisites, without running them; live attach, pause, step and screenshots are not available through it. | | 21 | | [dev-tools.md](dev-tools.md) | The development CLI `scripts/dev.py`: `discover` (text or `--json`, schema version 1) lists the boot-trace analyzer and the guest-scene runner with their help commands and prerequisites, without running them; live attach, pause, step and screenshots are not available through it. | |
| 22 | | [agent_collaboration.md](agent_collaboration.md) | How contributors' coding agents work together through GitHub: which machine profile takes which work, the `AGENT-MSG`, `RUN` and `TEST-WANTED` blocks, and the evidence tags. A convention, not a measurement. | | 22 | | [agent_collaboration.md](agent_collaboration.md) | How contributors' coding agents work together through GitHub: which machine profile takes which work, the `AGENT-MSG`, `RUN` and `TEST-WANTED` blocks, and the evidence tags. A convention, not a measurement. | |
| 23 | | [history/README.md](history/README.md) | The original repository's surviving history as portable, hashed text: the 251 `old-pr/*` branch tips and the 135 indexed old issues, with the script that regenerates them ([#563](https://github.com/ubiquitarianism/leonida/issues/563)). | | 23 | | [history/README.md](history/README.md) | The original repository's surviving history as portable, hashed text: the 251 `old-pr/*` branch tips and the 135 indexed old issues, with the script that regenerates them ([#563](https://github.com/ubiquitarianism/leonida/issues/563)). | |
| 24 | | [port_status.md](port_status.md) | Where the port stands: Leonida's runtime and shader pipeline as the base, what was patched in from VIctory, and what is still open. | | ||
| 25 | | [port_plan.md](port_plan.md) | What the title needs that Leonida's runtime does not do yet, taken from VIctory, in the order the title hits it and where each fix lands. | | ||
| 24 | 26 | ||
| 25 | ## Archives and assets | 27 | ## Archives and assets |
| 26 | 28 | ||
| @@ -77,6 +79,7 @@ method, scope and caveats. No game data is included. | |||
| 77 | | [modding.md](modding.md) | The mod format: a `mods/<folder>/mod.json` next to `gta6rt.exe` or under `--mods DIR`, swapping a named (or `joaat`) archetype for another; the `tools/leonida_mods.py` manager (`Mods.bat` on Windows, `Mods.sh` on Linux and macOS); load order, the start-up log, and the fact that a swap waits for the executable's archetype lookup address (RT-5). | | 79 | | [modding.md](modding.md) | The mod format: a `mods/<folder>/mod.json` next to `gta6rt.exe` or under `--mods DIR`, swapping a named (or `joaat`) archetype for another; the `tools/leonida_mods.py` manager (`Mods.bat` on Windows, `Mods.sh` on Linux and macOS); load order, the start-up log, and the fact that a swap waits for the executable's archetype lookup address (RT-5). | |
| 78 | | [descriptor_lookup_apple.md](descriptor_lookup_apple.md) | M3 Max GPU timings for texture and sampler descriptor lookups at 1k, 10k and 100k live entries. | | 80 | | [descriptor_lookup_apple.md](descriptor_lookup_apple.md) | M3 Max GPU timings for texture and sampler descriptor lookups at 1k, 10k and 100k live entries. | |
| 79 | | [descriptor_lookup_ada.md](descriptor_lookup_ada.md) | RTX 4070 SUPER (Ada, Windows) timings for the same lookups in VRAM, host-visible and ReBAR memory. | | 81 | | [descriptor_lookup_ada.md](descriptor_lookup_ada.md) | RTX 4070 SUPER (Ada, Windows) timings for the same lookups in VRAM, host-visible and ReBAR memory. | |
| 82 | | [descriptor_lookup_ampere.md](descriptor_lookup_ampere.md) | RTX 3070 (Ampere, Windows, PCIe 3.0 x16, ReBAR off) timings for the same lookups in VRAM, host-visible and 214 MiB BAR1 memory. | | ||
| 80 | | [descriptor_lookup_intel.md](descriptor_lookup_intel.md) | Intel UHD Graphics 770 (Xe-LP, Windows, driver 101.6129) timings for the same lookups at 1k–100k live entries; both memory placements within 0.6% of each other. | | 83 | | [descriptor_lookup_intel.md](descriptor_lookup_intel.md) | Intel UHD Graphics 770 (Xe-LP, Windows, driver 101.6129) timings for the same lookups at 1k–100k live entries; both memory placements within 0.6% of each other. | |
| 81 | | [d3d12_xs_surface.md](d3d12_xs_surface.md) | The 116-slot `d3d12_xs.dll` export surface; 83/83 standard GUIDs match the PC SDK. | | 84 | | [d3d12_xs_surface.md](d3d12_xs_surface.md) | The 116-slot `d3d12_xs.dll` export surface; 83/83 standard GUIDs match the PC SDK. | |
| 82 | | [xdxr.md](xdxr.md) | `BATCHED_DESC2` (`0x50`) and `XDXR_STREAM_DESC` (`0x10`) from `XboxBvhBuilder.dll`'s reads; stream records' offsets and defaults; offline statistics not in the package. | | 85 | | [xdxr.md](xdxr.md) | `BATCHED_DESC2` (`0x50`) and `XDXR_STREAM_DESC` (`0x10`) from `XboxBvhBuilder.dll`'s reads; stream records' offsets and defaults; offline statistics not in the package. | |
| @@ -84,6 +87,7 @@ method, scope and caveats. No game data is included. | |||
| 84 | | [d3d12_command_objects.md](d3d12_command_objects.md) | Measured command queue/list/fence/`PresentX` surface; verified vs prior art vs open. | | 87 | | [d3d12_command_objects.md](d3d12_command_objects.md) | Measured command queue/list/fence/`PresentX` surface; verified vs prior art vs open. | |
| 85 | | [xbox_d3d12_xs.md](xbox_d3d12_xs.md) | The `d3d12_xs` graphics ABI quoted from Microsoft's public GDK reference: root signatures, state objects, DXIL libraries, hit groups, shader cache sessions; which pages are missing or NDA-gated. | | 88 | | [xbox_d3d12_xs.md](xbox_d3d12_xs.md) | The `d3d12_xs` graphics ABI quoted from Microsoft's public GDK reference: root signatures, state objects, DXIL libraries, hit groups, shader cache sessions; which pages are missing or NDA-gated. | |
| 86 | | [runtime_imports.md](runtime_imports.md) | The 16 shipped modules' measured imports and shim/host/unimplemented split. | | 89 | | [runtime_imports.md](runtime_imports.md) | The 16 shipped modules' measured imports and shim/host/unimplemented split. | |
| 90 | | [gdk_public_reference.md](gdk_public_reference.md) | How to use the public PC GDK reference and headers to write shims for the imported console APIs: what it covers (XGameRuntime, XTaskQueue, XUser, XStore, XGameSave, GameInput), what it does not (`d3d12_xs`, NDA), the 4-step method, a measured table of which imported names have a public page (2026-11-29) and the lines not to cross. | | ||
| 87 | | [linux_proton.md](linux_proton.md) | Building and booting under Proton/Wine on Linux, one bounded game run with `scripts/run_game_wine.sh`, a healthy boot's timeline, and the test report of one Linux and two Windows machines | | 91 | | [linux_proton.md](linux_proton.md) | Building and booting under Proton/Wine on Linux, one bounded game run with `scripts/run_game_wine.sh`, a healthy boot's timeline, and the test report of one Linux and two Windows machines | |
| 88 | | [xmem_exe_calls.md](xmem_exe_calls.md) | How the retail executable calls `xmem.dll`: call sites and constant arguments per import (`tools/import_call_sites.py`), the 23 `XMemVirtualAlloc` calls that all pass an attribute word, and the inferred shape of the physical-page family. | | 92 | | [xmem_exe_calls.md](xmem_exe_calls.md) | How the retail executable calls `xmem.dll`: call sites and constant arguments per import (`tools/import_call_sites.py`), the 23 `XMemVirtualAlloc` calls that all pass an attribute word, and the inferred shape of the physical-page family. | |
| 89 | | [exe_fail_fast.md](exe_fail_fast.md) | Where the retail executable stops itself (`int3`) on an import's result: 78 sites over 27 imports (`tools/import_fail_fast.py`), grouped by how `main` binds each import (all 13 non-host fatal-checked imports now bind to shims; 0 unbound). | | 93 | | [exe_fail_fast.md](exe_fail_fast.md) | Where the retail executable stops itself (`int3`) on an import's result: 78 sites over 27 imports (`tools/import_fail_fast.py`), grouped by how `main` binds each import (all 13 non-host fatal-checked imports now bind to shims; 0 unbound). | |
| @@ -92,11 +96,14 @@ method, scope and caveats. No game data is included. | |||
| 92 | | [cpu_features.md](cpu_features.md) | CPU instructions in the executable a desktop CPU may lack (`tools/cpu_feature_scan.py`): 19 SSE4a, 10 CLZERO and 4 MONITORX/MWAITX sites (AMD only) and 8 CLWB sites (Intel since Ice Lake), all real code; `#UD` on hosts without them. | | 96 | | [cpu_features.md](cpu_features.md) | CPU instructions in the executable a desktop CPU may lack (`tools/cpu_feature_scan.py`): 19 SSE4a, 10 CLZERO and 4 MONITORX/MWAITX sites (AMD only) and 8 CLWB sites (Intel since Ice Lake), all real code; `#UD` on hosts without them. | |
| 93 | | [xcl_compare.md](xcl_compare.md) | XCL's synthetic test title under `gta6rt --run` and under XCL (`tools/xcl_compare.py`): 5 of 50 checks pass here, both hangs are the documented manual-queue terminate deadlock, and each other difference mapped to an open item or a lead. | | 97 | | [xcl_compare.md](xcl_compare.md) | XCL's synthetic test title under `gta6rt --run` and under XCL (`tools/xcl_compare.py`): 5 of 50 checks pass here, both hangs are the documented manual-queue terminate deadlock, and each other difference mapped to an open item or a lead. | |
| 94 | | [gameinput.md](gameinput.md) | The GameInput shim on SDL3: `GameInputCreate` and the v0 `IGameInput`/`IGameInputDevice`/`IGameInputReading`/`IGameInputDispatcher` surface on any SDL gamepad, DualSense adaptive-trigger approximation and lightbar, force-feedback motors and trigger haptics through SDL's haptic API; without SDL3, one scripted pad for `LEONIDA_INPUT_SCRIPT`; 261 checks on virtual joysticks and a fake haptic backend; by hand on an Xbox Series X pad (Bluetooth) and a DualSense (USB). 261 checks on virtual joysticks and a fake haptic backend, not yet tried on a real pad. | | 98 | | [gameinput.md](gameinput.md) | The GameInput shim on SDL3: `GameInputCreate` and the v0 `IGameInput`/`IGameInputDevice`/`IGameInputReading`/`IGameInputDispatcher` surface on any SDL gamepad, DualSense adaptive-trigger approximation and lightbar, force-feedback motors and trigger haptics through SDL's haptic API; without SDL3, one scripted pad for `LEONIDA_INPUT_SCRIPT`; 261 checks on virtual joysticks and a fake haptic backend; by hand on an Xbox Series X pad (Bluetooth) and a DualSense (USB). 261 checks on virtual joysticks and a fake haptic backend, not yet tried on a real pad. | |
| 95 | | [prompt_glyphs.md](prompt_glyphs.md) | The title's one button-prompt movie (a Scaleform GFX of 38 Xbox glyph sprites, `platform_xbsx.input_icons.Main_Button_<N>`): where it is in `data.rpf`, its tags and canvas sizes, which N is which button, which class of the larger movies asks for a glyph and when, the original PlayStation-style replacement `tools/ps_prompt_glyphs.py` builds, the keyboard-and-mouse set `tools/pc_prompt_glyphs.py` traces from the player's pictures, how the runtime serves the one for the device in use, and why the glyphs cannot follow a switch of device during play. | | 99 | | [prompt_glyphs.md](prompt_glyphs.md) | The title's one button-prompt movie (a Scaleform GFX of 38 Xbox glyph sprites, `platform_xbsx.input_icons.Main_Button_<N>`): where it is in `data.rpf`, its tags and canvas sizes, which N is which button, which class of the larger movies asks for a glyph and when, the original PlayStation-style replacement `tools/ps_prompt_glyphs.py` builds, the keyboard-and-mouse set `tools/pc_prompt_glyphs.py` draws itself (key caps fitted to the Xbox glyphs' size) or traces from the player's pictures, `tools/prompt_glyph_movies.py`, which builds both for the launcher and make_game.py, how the runtime serves the one for the device in use, and why the glyphs cannot follow a switch of device during play. | |
| 96 | | [vi_patch.md](vi_patch.md) | ZiZc3's VI-Patch (game patches for the PS5 build) on the Xbox executable: the title's frame limiter and the 60 fps patch that is always on (RVAs `0x224359a`, `0x1e0fc62`), no vignette behind `LEONIDA_VIPATCH_NO_VIGNETTE=1` (the `spotmeter_aiming` and `spotmeter_fast` exposure profiles), and why the other six are not found or not ported; no licence, so only what each patch does is taken. | | 100 | | [vi_patch.md](vi_patch.md) | ZiZc3's VI-Patch (game patches for the PS5 build) on the Xbox executable: the title's frame limiter and the 60 fps patch that is always on (RVAs `0x224359a`, `0x1e0fc62`), no vignette behind `LEONIDA_VIPATCH_NO_VIGNETTE=1` (the `spotmeter_aiming` and `spotmeter_fast` exposure profiles), and why the other six are not found or not ported; no licence, so only what each patch does is taken. | |
| 97 | | [victory_gap_media.md](victory_gap_media.md) | VIctory's audio, DSP, media, speech and GameInput modules against Leonida, export by export: what was already the same, what `port/gap-media` ported (the XInput/keyboard GameInput shim for builds without SDL3, `#1` registration, silent speech, the local-only Media Foundation resolver) and what is left (Opus decoding, diagnostics aids). | | 101 | | [victory_gap_media.md](victory_gap_media.md) | VIctory's audio, DSP, media, speech and GameInput modules against Leonida, export by export: what was already the same, what `port/gap-media` ported (the XInput/keyboard GameInput shim for builds without SDL3, `#1` registration, silent speech, the local-only Media Foundation resolver) and what is left (Opus decoding, diagnostics aids). | |
| 102 | | [victory_gap_gpu.md](victory_gap_gpu.md) | VIctory against Leonida on the console D3D12 surface (`d3d12x`, display, FidelityFX, DirectStorage, the GPU crate): what was the same, what `port/gap-gpu` ported and what is left. | | ||
| 103 | | [victory_gap_system.md](victory_gap_system.md) | VIctory against Leonida in the system modules and the loader (kernel, xmem, files, lifecycle, xsystem, xpackage...): what `port/gap-system` ported, each piece naming its VIctory source. | | ||
| 98 | | [saves.md](saves.md) | Save containers: `JSAV` (index + JSON story save, byte-exact rebuild), `ASAV` header, `SLAYER1` packed copy (not decoded); `tools/saves.py` and import into the offline `XGameSave` folder; key hashes are case-sensitive joaat (`tools/save_keys.py`). | | 104 | | [saves.md](saves.md) | Save containers: `JSAV` (index + JSON story save, byte-exact rebuild), `ASAV` header, `SLAYER1` packed copy (not decoded); `tools/saves.py` and import into the offline `XGameSave` folder; key hashes are case-sensitive joaat (`tools/save_keys.py`). | |
| 99 | | [pipeline_check.md](pipeline_check.md) | Driver-level corpus check: the full corpus, 26,503 of 26,503 modules and pipelines, 0 failures (RTX 4060 Ti); an earlier 10/12-shard run, 22,092 modules and 2,217 compute pipelines, also had 0 failures. Driver-level corpus check: 10/12 shards, 22,092 modules, 2,217 compute pipelines, 0 failures. | | 105 | | [pipeline_check.md](pipeline_check.md) | Driver-level corpus check: the full corpus, 26,503 of 26,503 modules and pipelines, 0 failures (RTX 4060 Ti); an earlier 10/12-shard run, 22,092 modules and 2,217 compute pipelines, also had 0 failures. Driver-level corpus check: 10/12 shards, 22,092 modules, 2,217 compute pipelines, 0 failures. | |
| 106 | | [runtime_ctest_hosts.md](runtime_ctest_hosts.md) | The runtime ctest suite on two hosts, Wine and native Windows 10, on one Pascal card: the 19 failures that are Wine's host, the 5 that reproduce (ours), and the 6 that only fail natively, deterministic, including a SegFault. | | ||
| 100 | | [multi_gpu_validation.md](multi_gpu_validation.md) | Running disjoint shards on eight identical RDNA1/RADV GPUs: PCI-BDF pinning, base controls, per-card logs, the V540 farm's aggregate results and its known driver limitations. | | 107 | | [multi_gpu_validation.md](multi_gpu_validation.md) | Running disjoint shards on eight identical RDNA1/RADV GPUs: PCI-BDF pinning, base controls, per-card logs, the V540 farm's aggregate results and its known driver limitations. | |
| 101 | | [shader_validation.md](shader_validation.md) | Differential CPU/GPU validation design and the current CPU interpreter prototype. | | 108 | | [shader_validation.md](shader_validation.md) | Differential CPU/GPU validation design and the current CPU interpreter prototype. | |
| 102 | | [isa_coverage.md](isa_coverage.md) | RDNA2 ISA coverage of the translator against AMD's machine-readable XML: which of its 1,153 instructions have a rule, and which matched names are not RDNA2. | | 109 | | [isa_coverage.md](isa_coverage.md) | RDNA2 ISA coverage of the translator against AMD's machine-readable XML: which of its 1,153 instructions have a rule, and which matched names are not RDNA2. | |
| @@ -114,6 +121,21 @@ method, scope and caveats. No game data is included. | |||
| 114 | | [mission_logic.md](mission_logic.md) | Mission state tables: 0x20 record layout (band counter, byte offsets), the 64-byte pool element with world transforms, case-folding joaat keys, 53.5 % of states named, 113 state-set clusters covering 82.4 % of files. | | 121 | | [mission_logic.md](mission_logic.md) | Mission state tables: 0x20 record layout (band counter, byte offsets), the 64-byte pool element with world transforms, case-folding joaat keys, 53.5 % of states named, 113 state-set clusters covering 82.4 % of files. | |
| 115 | | [gbuffer.md](gbuffer.md) | Deferred G-buffer targets (`PS_DeferredTextured` and all 2,989 `*Deferred*` pixel shaders, `PROC-146`): 5- and 6-target `OSG1`/`PSV0` signatures (`float32` + `exp ... compr` on all outputs), the 24-bit octahedral normal split across `mrt1.gba` (`2047.5` scale, `1/255` byte packing), sqrt-encoded `mrt2`, byte IDs in `mrt3.zw`, float motion in `mrt4`, and why binding `f16` targets mangles the normal bytes. | | 122 | | [gbuffer.md](gbuffer.md) | Deferred G-buffer targets (`PS_DeferredTextured` and all 2,989 `*Deferred*` pixel shaders, `PROC-146`): 5- and 6-target `OSG1`/`PSV0` signatures (`float32` + `exp ... compr` on all outputs), the 24-bit octahedral normal split across `mrt1.gba` (`2047.5` scale, `1/255` byte packing), sqrt-encoded `mrt2`, byte IDs in `mrt3.zw`, float motion in `mrt4`, and why binding `f16` targets mangles the normal bytes. | |
| 116 | 123 | ||
| 124 | ## Runtime features, tools and proposals | ||
| 125 | |||
| 126 | | Document | What it covers | | ||
| 127 | |---|---| | ||
| 128 | | [measuring_fps.md](measuring_fps.md) | How to measure frame rates of the D3D12 runtime (`d3d12/`): look in the findings first, turn a switch inside one run with `LEONIDA_AB`, separate runs, which log number means what, what to write before reporting a cause. | | ||
| 129 | | [d3d12/docs/findings.md](../d3d12/docs/findings.md) | What was measured of the D3D12 runtime's frame on several PCs: where a frame goes, switches by turns with their spread, what was not worth it, picture faults and what they were. | | ||
| 130 | | [d3d12/docs/switches.md](../d3d12/docs/switches.md) | The `LEONIDA_*` variables the D3D12 runtime names, made from its sources (`tools/d3d12_switches.py`): how each is read, whether `LEONIDA_AB` can turn it, the sentence of the code's comment. | | ||
| 131 | | [launcher.md](launcher.md) | The Leonida Launcher: the desktop window with navigation, a PLAY button, status line and pages; Leonida's own design, no game assets. | | ||
| 132 | | [mod-menu.md](mod-menu.md) | The in-game trainer menu drawn by the D3D12 runtime (`d3d12/`): on by default, `LEONIDA_MENU=0` turns it off; single player only, nothing online. | | ||
| 133 | | [lua-modding.md](lua-modding.md) | Lua 5.4 mods in the D3D12 runtime: a folder in `mods\` with the same `mod.json` the mod manager lists, and a script next to it. | | ||
| 134 | | [ultrawide.md](ultrawide.md) | How the output size goes from the window to the title and back to the screen, and what the opt-in 21:9 and 32:9 settings change; measured versus hypothesis marked. | | ||
| 135 | | [test_inventory.md](test_inventory.md) | The subsystem test map and prerequisite catalog (`tools/test_inventory.py`, DX-10): how test modules across `tests/` and `runtime/test/` are discovered and grouped. | | ||
| 136 | | [junit_triage.md](junit_triage.md) | Comparing two JUnit XML reports (`tools/junit_triage.py`, e.g. from `ctest --output-junit`): aggregate counts only, never test names or output. | | ||
| 137 | | [change_gate.md](change_gate.md) | A proposal, not implemented: a change gate for module boundaries, function complexity and doubled text, with the numbers measured on the merge history. | | ||
| 138 | |||
| 117 | ## Other languages | 139 | ## Other languages |
| 118 | 140 | ||
| 119 | Community quickstarts (stable onboarding text only; English docs remain authoritative): [i18n/README.md](i18n/README.md) (`fr`, `pt-BR`, `pt-PT`, `zh-CN`, `pl-PL`, `tr`, `ru`, `ja`, `es`, `it`, `de`, `ar`, `vi`). | 141 | Community quickstarts (stable onboarding text only; English docs remain authoritative): [i18n/README.md](i18n/README.md) (`fr`, `pt-BR`, `pt-PT`, `zh-CN`, `pl-PL`, `tr`, `ru`, `ja`, `es`, `it`, `de`, `ar`, `vi`). |
diff --git a/docs/audio_hal_exe_calls.md b/docs/audio_hal_exe_calls.md index a500e16fc..42ec9fd78 100644 --- a/docs/audio_hal_exe_calls.md +++ b/docs/audio_hal_exe_calls.md | |||
| @@ -26,7 +26,7 @@ Every one of the 22 has at least one site, so none is dead code the linker kept. | |||
| 26 | | `AcpHalReleaseShapeContexts` | 1 | called with a handle read from the first global; result not used | | 26 | | `AcpHalReleaseShapeContexts` | 1 | called with a handle read from the first global; result not used | |
| 27 | | `ApuCreateHeap` | 1 | second argument `0x226e00`; the result is tested for a negative value | | 27 | | `ApuCreateHeap` | 1 | second argument `0x226e00`; the result is tested for a negative value | |
| 28 | | `ApuAlloc` | 1 | second argument `0`, third a computed value, fourth `0x800`; the result is not used at the site | | 28 | | `ApuAlloc` | 1 | second argument `0`, third a computed value, fourth `0x800`; the result is not used at the site | |
| 29 | | `ApuFree` | 1 tail jump | no call, only a tail jump from a wrapper | | 29 | | `ApuFree` | 1 tail jump | the `site` is a whole function that is one `jmp` to the thunk (`0x1443aea10`), so it forwards its arguments unchanged and adds no arity of its own | |
| 30 | | `ApuIsVirtualAddressValid` | 4 | second argument `0x40`, `0x80`, `0x800`, `0x800`; the result byte is tested | | 30 | | `ApuIsVirtualAddressValid` | 4 | second argument `0x40`, `0x80`, `0x800`, `0x800`; the result byte is tested | |
| 31 | | `ApuMapVirtualAddress` | 4 | the same pointer and the same four constants as `ApuIsVirtualAddressValid`, one after the other; the 32-bit result is stored in a per-entry record | | 31 | | `ApuMapVirtualAddress` | 4 | the same pointer and the same four constants as `ApuIsVirtualAddressValid`, one after the other; the 32-bit result is stored in a per-entry record | |
| 32 | | `ApuMapApuAddress` | 2 | the argument is a 32-bit value read from those records; the result is tested for null, so it is a pointer | | 32 | | `ApuMapApuAddress` | 2 | the argument is a 32-bit value read from those records; the result is tested for null, so it is a pointer | |
| @@ -39,14 +39,14 @@ turns such an address back into a pointer. That is an inference from the shapes; | |||
| 39 | 39 | ||
| 40 | | Import | Sites | What the sites show | | 40 | | Import | Sites | What the sites show | |
| 41 | |---|---:|---| | 41 | |---|---:|---| |
| 42 | | `XApuConnect` | 1 | no argument loaded in the lines before the call was read | | 42 | | `XApuConnect` | 1 | three arguments, the addresses of three `.data` globals (`0x149B69890`, `0x149B698A8`, `0x149B68960`), in `rcx`/`rdx`/`r8`; the result is tested as non-negative (`setns`) | |
| 43 | | `XApuDisconnect` | 1 | first argument a handle read from a global, second `0x20`; the global is set to 0 right after | | 43 | | `XApuDisconnect` | 1 | first argument a handle read from a global, second `0x20`; the global is set to 0 right after | |
| 44 | | `XApuEnqueueCommand` | 4 | the same global handle, a pointer to a stack-built command, and 0 | | 44 | | `XApuEnqueueCommand` | 4 | the same global handle, a pointer to a stack-built command, and 0 | |
| 45 | | `XApuDequeueResult` | 1 | the same global handle and a second argument; the result is tested for a negative value | | 45 | | `XApuDequeueResult` | 1 | the same handle global, and a 16-byte stack buffer as the second argument; a negative result jumps out, otherwise the record is read from buffer `+0x20`/`+0x24` | |
| 46 | | `XApuGetResultCount` | 1 | no argument read | | 46 | | `XApuGetResultCount` | 1 | the queue handle global and a second argument `0`; the result count is tested for zero and both branches are taken on it | |
| 47 | | `XDspConnectWithMaximumStreamLimit` | 1 | fourth argument `0x80`; the result is compared with 0 and turned into a boolean that is true for 0 | | 47 | | `XDspConnectWithMaximumStreamLimit` | 1 | fourth argument `0x80`; the result is compared with 0 and turned into a boolean that is true for 0 | |
| 48 | | `XDspActivate` | 1 | the result is tested | | 48 | | `XDspActivate` | 1 | a wrapper that swaps the incoming `r8`/`r9` before calling; the result is tested | |
| 49 | | `XDspSubmitCommand` | 1 | two arguments, both taken from registers; not read further | | 49 | | `XDspSubmitCommand` | 1 | a two-argument wrapper that swaps the incoming registers (`rcx` <- `rdx`, `rdx` <- old `rcx`) before calling, so the published order is the reverse of the wrapper's | |
| 50 | | `XDspDeactivate`, `XDspDisconnect` | 1 tail jump each | no call | | 50 | | `XDspDeactivate`, `XDspDisconnect` | 1 tail jump each | no call | |
| 51 | 51 | ||
| 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 |
diff --git a/docs/boot.md b/docs/boot.md index 06b34a11d..688d91dd1 100644 --- a/docs/boot.md +++ b/docs/boot.md | |||
| @@ -109,6 +109,10 @@ Useful switches: | |||
| 109 | read when the trace opens. | 109 | read when the trace opens. |
| 110 | Diagnostic only: a correct run reaches none, so each skipped address is a finding, not a fix. A failed guest file | 110 | Diagnostic only: a correct run reaches none, so each skipped address is a finding, not a fix. A failed guest file |
| 111 | open is always traced as `file_open_failed` (path, error, caller) when `--trace` is on. | 111 | open is always traced as `file_open_failed` (path, error, caller) when `--trace` is on. |
| 112 | * `LEONIDA_SKIP_ASSERTS=N` steps over up to N int3 in guest code, with or without `--trace`, and prints each one | ||
| 113 | as `[rt] LEONIDA_SKIP_ASSERTS: int3 at <module>+0x... stepped over (k of N)`; the next one after N ends the run as | ||
| 114 | before. An int3 in a host module is never stepped over. The same caveat: each skipped address is a finding | ||
| 115 | ([runtime/README.md](../runtime/README.md), "Guest asserts"). | ||
| 112 | * `LEONIDA_STUB_PIPELINES=1` creates a pipeline whose translated shader is missing (no shader library, or no entry | 116 | * `LEONIDA_STUB_PIPELINES=1` creates a pipeline whose translated shader is missing (no shader library, or no entry |
| 113 | for its program) as a stub instead of failing `CreateGraphicsPipelineState` / `CreateComputePipelineState`. | 117 | for its program) as a stub instead of failing `CreateGraphicsPipelineState` / `CreateComputePipelineState`. |
| 114 | A graphics pipeline with a vertex stage (MVP-GPU-04) is a real Vulkan pipeline built from the built-in stages in | 118 | A graphics pipeline with a vertex stage (MVP-GPU-04) is a real Vulkan pipeline built from the built-in stages in |
| @@ -133,6 +137,13 @@ Useful switches: | |||
| 133 | diagnostic). | 137 | diagnostic). |
| 134 | * `LEONIDA_DEVICE_FAULT=1` enables Vulkan device-loss diagnostics and checkpoints where available. The first | 138 | * `LEONIDA_DEVICE_FAULT=1` enables Vulkan device-loss diagnostics and checkpoints where available. The first |
| 135 | observed loss prints a `[rt] device-fault:` report to stderr. | 139 | observed loss prints a `[rt] device-fault:` report to stderr. |
| 140 | * `LEONIDA_IO_TRACE=<file>` writes one line for every read the title asks for (`runtime/shims/io_trace.h`): | ||
| 141 | - `ds`: a DirectStorage request, with its file, file offset, source and destination sizes, zlib and BCPack, and the | ||
| 142 | request's name; | ||
| 143 | - `rf`: a ReadFile, ReadFileEx or ReadFileScatter on a disk file, with its path, offset and size. | ||
| 144 | |||
| 145 | Each line starts with the local time, as the `mem-probe` lines do. Each line is flushed at once and the file can be | ||
| 146 | read while the game runs, so the last reads before a crash or a device loss name what the title was loading. | ||
| 136 | * `LEONIDA_TITLE_HUD=1` shows live counters in the title bar of the window the title presents in | 147 | * `LEONIDA_TITLE_HUD=1` shows live counters in the title bar of the window the title presents in |
| 137 | (`runtime/shims/title_hud.h`). It updates twice a second with: | 148 | (`runtime/shims/title_hud.h`). It updates twice a second with: |
| 138 | - the frame rate and the average and worst frame time from PresentX, or, when no frame came in that half | 149 | - the frame rate and the average and worst frame time from PresentX, or, when no frame came in that half |
| @@ -258,7 +269,7 @@ order. It maps each question to the event to look for; it does not answer them. | |||
| 258 | 269 | ||
| 259 | | # | Question | Signal in the first trace | | 270 | | # | Question | Signal in the first trace | |
| 260 | |---|---|---| | 271 | |---|---|---| |
| 261 | | 1 | `D3D12XboxCreateDevice` 24-word params and flags | first `D3D12XboxCreateDevice` in the D3D12 trace; the shim prints the 24 words as an `[rt]` line in the same log, with or without `--trace-d3d12` (grep `^\[rt\]`); accept unknown flags | | 272 | | 1 | `D3D12XboxCreateDevice` 0x50-byte params and flags | first `D3D12XboxCreateDevice` in the D3D12 trace; the shim prints the twenty dwords as an `[rt]` line in the same log, with or without `--trace-d3d12` (grep `^\[rt\]`); accept unknown flags. The struct is 0x50 bytes (20 dwords), not 24 words: at the single retail call site it is a stack local of a `0x228` frame whose saved `xmm6` begins at `+0x200`, and three 32-byte stores zero it up to `+0x4F`. Only `+0x00 = 0x00020004`, `+0x08 = 0x00100000`, `+0x28 = 1` and `+0x3C = 0x20` are fixed; `+0x20` and `+0x24` carry two bytes of launch state and `+0x30`-`+0x4F` stay zero. Adapter is null, the IID is `{5405C344-D457-444E-B4DD-2366E45AEE39}` | |
| 262 | | 2 | Xbox device/heap/queue/command-list slots | queue, fence and allocator method names in the D3D12 trace; device slots past the PC vtable print an `[rt] d3d12_xs: device slot …` line instead and record nothing; compare with the SDK vtable | | 273 | | 2 | Xbox device/heap/queue/command-list slots | queue, fence and allocator method names in the D3D12 trace; device slots past the PC vtable print an `[rt] d3d12_xs: device slot …` line instead and record nothing; compare with the SDK vtable | |
| 263 | | 3 | Root signature → `s0..s31` | `CreateRootSignature`, `SetGraphicsRootSignature`, then the shader's user-SGPR reads; mask `0x03000000` on a copy | | 274 | | 3 | Root signature → `s0..s31` | `CreateRootSignature`, `SetGraphicsRootSignature`, then the shader's user-SGPR reads; mask `0x03000000` on a copy | |
| 264 | | 4 | Descriptor bytes and heap increments | first `CreateShaderResourceView`/`CreateSampler` and the first draw; dump the heap bytes and compare with the T#/S# parser | | 275 | | 4 | Descriptor bytes and heap increments | first `CreateShaderResourceView`/`CreateSampler` and the first draw; dump the heap bytes and compare with the T#/S# parser | |
diff --git a/docs/boot_leads.md b/docs/boot_leads.md index b3e0207f9..c45c590eb 100644 --- a/docs/boot_leads.md +++ b/docs/boot_leads.md | |||
| @@ -1,9 +1,19 @@ | |||
| 1 | # Boot leads: open findings and how to implement them | 1 | # Boot leads: open findings and how to implement them |
| 2 | 2 | ||
| 3 | Open leads that may move the retail boot further, each with where it lands in this repository and how to check it. | 3 | Leads that may move the retail boot further, each with where it lands in this repository and how to check it. |
| 4 | Every item is a **hypothesis**: it has not been measured against this package or run in this runtime. Confirm it on | 4 | Every lead started as a **hypothesis**. Its **Status** line says whether a merged pull request has answered it, an |
| 5 | your own copy or with a synthetic test before you build on it, and record the result in the document named under | 5 | open one is working on it, or nothing has yet. What is not marked done there has not been measured against this |
| 6 | **Record it in**. | 6 | package or run in this runtime: confirm it on your own copy or with a synthetic test before you build on it, and |
| 7 | record the result in the document named under **Record it in**. | ||
| 8 | |||
| 9 | | Lead | Status | | ||
| 10 | |---|---| | ||
| 11 | | BL-1 TLS from module index 0 | Done on `main` with a synthetic test; the retail confirmation is pending | | ||
| 12 | | BL-2 Feature level at device creation | Done: #913 | | ||
| 13 | | BL-3 Replay the console command list | In progress: #1050 (open) | | ||
| 14 | | BL-4 Descriptor words as 32-bit addresses | Done: #1166 (no bare 32-bit addresses in the census) | | ||
| 15 | | BL-5 Shader corpus count | Done: #882 (a counting difference; the carve misses nothing) | | ||
| 16 | | BL-6 Frame pacing drift reporting | Done: #891; real numbers still need a retail run | | ||
| 7 | 17 | ||
| 8 | ## Rules | 18 | ## Rules |
| 9 | 19 | ||
| @@ -52,6 +62,12 @@ your own copy or with a synthetic test before you build on it, and record the re | |||
| 52 | succeed when asked for 12.0. | 62 | succeed when asked for 12.0. |
| 53 | - **Where:** `CheckFeatureSupport` reports levels up to 12_1 (`runtime/shims/d3d12_vulkan_device.cpp`, the | 63 | - **Where:** `CheckFeatureSupport` reports levels up to 12_1 (`runtime/shims/d3d12_vulkan_device.cpp`, the |
| 54 | `D3D12_FEATURE_FEATURE_LEVELS` case); the Xbox entry point is in `runtime/shims/d3d12_xs_device.cpp`. | 64 | `D3D12_FEATURE_FEATURE_LEVELS` case); the Xbox entry point is in `runtime/shims/d3d12_xs_device.cpp`. |
| 65 | - **Status:** done by #913 (merged in `531aa4f5`). The minimum was the problem, not the reported level: the host path | ||
| 66 | of `D3D12XboxCreateDevice` asked the PC `D3D12CreateDevice` for 12_0 as its minimum, which refuses every adapter | ||
| 67 | below it. `rt::d3d12_xs::create_host_device` now asks for `kHostDeviceFloor` = 11_0, and the device reports its | ||
| 68 | own highest level. `xs_proxy_mock_test` covers mock hosts that top out at 11_0 through 12_2. The write-up is in | ||
| 69 | [d3d12_xs_surface.md](d3d12_xs_surface.md) ("Feature level at device creation (BL-2)"). Still open: reproducing the | ||
| 70 | original failure on the Wine or Proton host it came from. | ||
| 55 | - **Implement:** read the level the title passes at creation and make the layer accept the full range it can | 71 | - **Implement:** read the level the title passes at creation and make the layer accept the full range it can |
| 56 | satisfy, returning the highest supported level through the feature-level query rather than failing creation on a | 72 | satisfy, returning the highest supported level through the feature-level query rather than failing creation on a |
| 57 | lower request. Report 12_2 only where mesh shaders and ray tracing are present | 73 | lower request. Report 12_2 only where mesh shaders and ray tracing are present |
| @@ -67,6 +83,8 @@ your own copy or with a synthetic test before you build on it, and record the re | |||
| 67 | list is closed or executed than by translating each call as it is made. | 83 | list is closed or executed than by translating each call as it is made. |
| 68 | - **Where:** the "console list tail" listed as open in the README's D3D12 → Vulkan row and in | 84 | - **Where:** the "console list tail" listed as open in the README's D3D12 → Vulkan row and in |
| 69 | [d3d12_vulkan.md](d3d12_vulkan.md); call orders are in [d3d12_command_objects.md](d3d12_command_objects.md). | 85 | [d3d12_vulkan.md](d3d12_vulkan.md); call orders are in [d3d12_command_objects.md](d3d12_command_objects.md). |
| 86 | - **Status:** in progress in #1050 (open: "replay the console list's inline records as their vtable calls"). Read it | ||
| 87 | and its review before starting work of your own here. | ||
| 70 | - **Implement:** record the console-only calls into a per-list buffer, then translate them to Vulkan in order at | 88 | - **Implement:** record the console-only calls into a per-list buffer, then translate them to Vulkan in order at |
| 71 | `Close`/`Execute`. Keep calls that must take effect immediately (those whose results the title reads back) out of | 89 | `Close`/`Execute`. Keep calls that must take effect immediately (those whose results the title reads back) out of |
| 72 | the buffer. | 90 | the buffer. |
| @@ -86,6 +104,8 @@ your own copy or with a synthetic test before you build on it, and record the re | |||
| 86 | 1,296 slots of interleaved constant data; and **0 slots that are bare 32-bit GPU addresses**. | 104 | 1,296 slots of interleaved constant data; and **0 slots that are bare 32-bit GPU addresses**. |
| 87 | - **Conclusion:** BL-4 hypothesis is not supported on this stack. Descriptors pack 48-bit addresses into V# / T# fields rather | 105 | - **Conclusion:** BL-4 hypothesis is not supported on this stack. Descriptors pack 48-bit addresses into V# / T# fields rather |
| 88 | than exposing bare 32-bit pointer words. Characterized by model-level reference contract suite `tests/test_descriptor_address_translation.py` (53 tests modeling the documented arena bitfield partitioning and address extraction contracts). | 106 | than exposing bare 32-bit pointer words. Characterized by model-level reference contract suite `tests/test_descriptor_address_translation.py` (53 tests modeling the documented arena bitfield partitioning and address extraction contracts). |
| 107 | - **Status:** done by #1166 (merged in `95eacfa7c`): the census found no bare 32-bit addresses, so the | ||
| 108 | hypothesis is not supported on this stack. | ||
| 89 | - **Record it in:** [d3d12_vulkan.md](d3d12_vulkan.md) §3.4 with the census breakdown. | 109 | - **Record it in:** [d3d12_vulkan.md](d3d12_vulkan.md) §3.4 with the census breakdown. |
| 90 | - **Needs:** none (census completed and verified). | 110 | - **Needs:** none (census completed and verified). |
| 91 | 111 | ||
| @@ -96,6 +116,12 @@ your own copy or with a synthetic test before you build on it, and record the re | |||
| 96 | misses. | 116 | misses. |
| 97 | - **Where:** the carve and library tools (`make_game.py`, `tools/shader_carve.py`, `tools/shader_library.py`) and | 117 | - **Where:** the carve and library tools (`make_game.py`, `tools/shader_carve.py`, `tools/shader_library.py`) and |
| 98 | [shader_library.md](shader_library.md). | 118 | [shader_library.md](shader_library.md). |
| 119 | - **Status:** done by #882 (merged in `71f99e22`): a counting difference, not a gap. 26,503 counts carved `DXBC` | ||
| 120 | containers and 26,698 counts the `FSSM` payloads in them; the 195 extra are vertex-shader containers that also hold | ||
| 121 | the export-shader build of the same shader for a legacy geometry-shader pipeline. `tools/fssm_unpack.py` prints | ||
| 122 | both counts and a line per stage; the table is in [shader_library.md](shader_library.md) ("Containers and | ||
| 123 | programs"). Still open: which payload a geometry-shader pipeline selects ([fssm_crosscheck.md](fssm_crosscheck.md) | ||
| 124 | §6); the 195 export-stage variants are not translated yet. | ||
| 99 | - **Implement:** list how programs are enumerated (per file, per container, per variant) and print a breakdown by | 125 | - **Implement:** list how programs are enumerated (per file, per container, per variant) and print a breakdown by |
| 100 | stage. If the 195 are a counting difference, document it. If they are real, find where the carve skips them and fix | 126 | stage. If the 195 are a counting difference, document it. If they are real, find where the carve skips them and fix |
| 101 | that, not the count. | 127 | that, not the count. |
| @@ -110,6 +136,11 @@ your own copy or with a synthetic test before you build on it, and record the re | |||
| 110 | figures make that visible. | 136 | figures make that visible. |
| 111 | - **Where:** the frame pacer in `runtime/src/frame_pacer.h` and its `PresentX` wiring in | 137 | - **Where:** the frame pacer in `runtime/src/frame_pacer.h` and its `PresentX` wiring in |
| 112 | `runtime/shims/xbox_present.cpp`. | 138 | `runtime/shims/xbox_present.cpp`. |
| 139 | - **Status:** done by #891 (merged in `3ba069eb`). `FramePacer` keeps ring buffers of frame times and | ||
| 140 | origin-to-present latencies (`frame_pacing_window` = 1024), `XboxPresentation` logs a pacing summary at teardown, | ||
| 141 | and `tools/boot_trace.py` reports it (p50/p95/p99, mean and drift against target); | ||
| 142 | `runtime/test/frame_pacer_test.cpp` checks it with a fake clock. Recorded in [d3d12_vulkan.md](d3d12_vulkan.md) | ||
| 143 | ("Pacing drift reporting (BL-6)") and [boot.md](boot.md). Still open: numbers from a retail run. | ||
| 113 | - **Implement:** record frame times in a ring buffer and report p50, p95 and p99 plus the drift of the mean against | 144 | - **Implement:** record frame times in a ring buffer and report p50, p95 and p99 plus the drift of the mean against |
| 114 | the target interval, in the run summary beside the existing D3D12 counts ([boot.md](boot.md)). | 145 | the target interval, in the run summary beside the existing D3D12 counts ([boot.md](boot.md)). |
| 115 | - **Test:** extend `runtime/test/frame_pacer_test.cpp` with a fake clock feeding known intervals, asserting the | 146 | - **Test:** extend `runtime/test/frame_pacer_test.cpp` with a fake clock feeding known intervals, asserting the |
diff --git a/docs/change_gate.md b/docs/change_gate.md new file mode 100644 index 000000000..5b4dcb355 --- /dev/null +++ b/docs/change_gate.md | |||
| @@ -0,0 +1,313 @@ | |||
| 1 | # Proposal: a change gate for module boundaries, function complexity and doubled text | ||
| 2 | |||
| 3 | **Status: a proposal for the maintainer's decision; nothing on this page is implemented, and the pull request that | ||
| 4 | adds it changes no other file. The numbers were measured at `dde82f2` on the tree and on the 300 squash merges | ||
| 5 | that end with it (one merge round on 2026-11-23 in the original repository, whose history this one carries), with a standard-library prototype that is | ||
| 6 | not part of this pull request.** | ||
| 7 | |||
| 8 | GitHub's search counts 3,680 pull requests merged in the original repository from 2026-11-21 to 2026-11-23. [AGENTS.md](../AGENTS.md) is | ||
| 9 | written for the coding agents that many contributors use, and the template asks about them. Review and CI catch | ||
| 10 | what a diff shows and what a test exercises. Three things a diff does not show: a new dependency on another part of | ||
| 11 | the tree, hidden behind a `sys.path` insert; a function that has grown past the point where a person or an agent can | ||
| 12 | change it without breaking a case it did not look at; and text that a merge doubled. This page proposes one | ||
| 13 | deterministic check for those three. It compares a pull request with its base, blocks only what the pull request | ||
| 14 | adds, tolerates what is already on `main`, and tells the author why a finding matters and how to fix it. Because CI | ||
| 15 | had finished on few pull requests when they were merged (section 1.4), it runs where the code is written and in the | ||
| 16 | merge round as well as in CI. | ||
| 17 | |||
| 18 | Claims are marked: | ||
| 19 | |||
| 20 | - **Measured** — counted on the tree or the history at `dde82f2`; section 6 says how. | ||
| 21 | - **Proposed** — what this page asks the maintainer to accept. | ||
| 22 | - **Open** — a question for the maintainer, collected in section 5. | ||
| 23 | |||
| 24 | ## 1. What was measured | ||
| 25 | |||
| 26 | ### 1.1 Dependencies between parts of the tree | ||
| 27 | |||
| 28 | **Measured.** Python files reach each other through 1,262 `sys.path.insert` calls, which is why 1,527 imports carry | ||
| 29 | `# noqa: E402`. Resolving those paths gives 2,182 import edges between repository files. | ||
| 30 | These boundaries hold today with no exception: | ||
| 31 | |||
| 32 | - `make_game.py` imports only `tools/`. | ||
| 33 | - `viewer/` imports nothing from the repository. | ||
| 34 | - `tools/` never imports `scripts/`, `make_game.py` or `viewer/`; `scripts/` never imports `tests/`. | ||
| 35 | - No import cycle crosses two areas; inside `tools/` there are two, each of two files | ||
| 36 | (`tools/calibrated_texture.py` with `tools/ttpf_mips.py`, `tools/hw_oracle/drm.py` with `tools/hw_oracle/runner.py`). | ||
| 37 | - No production C++ file (`runtime/src`, `runtime/shims`, `runtime/xma_decoder`) includes a `runtime/test` file, and | ||
| 38 | no file-level `#include` cycle exists. | ||
| 39 | |||
| 40 | One boundary is crossed: production code imports test code through 39 edges from 32 files. 26 edges go from | ||
| 41 | `tools/` to `tests/`, 22 of them to `tests/semantic/spirv_mini_interp.py`, which is in effect a shared reference | ||
| 42 | interpreter kept in a test folder; 8 go from `tools/` and 5 from `scripts/` to the GPU fixture helpers in | ||
| 43 | `runtime/test/shaders`. The `scripts/` ones are test runners (`scripts/run_gpu_tests.py`, | ||
| 44 | `scripts/bench_wave64.py`) using the fixture helpers they run, and the rules below allow them. Two of the 300 merges | ||
| 45 | added another edge from `tools/`, both new tools that copied the pattern (`tools/wave_diff.py:53` in `db77244`, | ||
| 46 | `tools/div_fixup_diff.py:104` in `5e54bda`). | ||
| 47 | |||
| 48 | To be fair to the current setup: 31 of the 32 importing files are themselves imported by a test, so an edit to | ||
| 49 | `spirv_mini_interp.py` that breaks a tool makes a test fail once CI runs (section 1.4 shows how often it has not | ||
| 50 | run by the merge). What the edge costs even then is legibility. The file looks like test code, and nothing beside it says that 22 tools depend on | ||
| 51 | it; an author, human or agent, edits it with that context missing. | ||
| 52 | |||
| 53 | The C++ runtime has one directory-level cycle: `runtime/shims` includes `runtime/src` 27 times, and `runtime/src` | ||
| 54 | includes `runtime/shims` 7 times, all from `runtime/src/main.cpp` and `runtime/src/pe_loader.cpp`. Whether that is the | ||
| 55 | intended layering is question 5 in section 5. | ||
| 56 | |||
| 57 | ### 1.2 Function complexity | ||
| 58 | |||
| 59 | **Measured**, cyclomatic complexity (McCabe for Python, lizard's CCN for C++; section 6): | ||
| 60 | |||
| 61 | | Area | Functions | Complexity 11-20 | 21-50 | Above 50 | Largest | | ||
| 62 | |---|---|---|---|---|---| | ||
| 63 | | `tools/` (Python) | 5,579 | 774 | 399 | 95 | 1,261 | | ||
| 64 | | `make_game.py` and `scripts/` | 291 | 37 | 15 | 3 | 280 | | ||
| 65 | | `runtime/src` and `runtime/shims` (C++) | 2,514 | 165 | 88 | 27 | 370 | | ||
| 66 | |||
| 67 | The largest is `Gen._insn` in `tools/rdna2spirv.py` (line 6722): 4,889 lines and a complexity of 1,261 in an | ||
| 68 | 18,229-line file. One `if`/`elif` chain of 182 arms holds nearly all of that; section 2.3 judges such a function arm | ||
| 69 | by arm. | ||
| 70 | |||
| 71 | What the 300 merges did to production functions, checked with the rule proposed in section 2.3: | ||
| 72 | 89 findings in 48 pull requests. Each was labelled after reading its diff | ||
| 73 | (section 6 says by whom): 66 made a function measurably harder to change (new nested logic, a 9 -> 20 or 10 -> 27 | ||
| 74 | jump, an optional feature threaded through an existing function), 21 are correct measurements whose value is | ||
| 75 | arguable, and 2 are artefacts of the tool (section 2.3 lists them). Examples of the first kind: | ||
| 76 | |||
| 77 | | Commit | Function | Complexity before -> after | | ||
| 78 | |---|---|---| | ||
| 79 | | `0a8a552` | `export_bank` in `tools/awc_opus.py` | 19 -> 30 | | ||
| 80 | | `9a9ca1e` | `ExecuteIndirect` in `runtime/shims/d3d12_com.cpp` | 10 -> 27 | | ||
| 81 | | `21e72aa` | `scan_offsets` in `tools/smh_groom.py` | 9 -> 20 | | ||
| 82 | | `86d1c86` | `verify_manifest` in `tools/manifest_verifier.py` | 23 -> 33 | | ||
| 83 | | `c1aa89e` | `verify` in `tools/world_drawable_verify.py` (new) | 34 | | ||
| 84 | |||
| 85 | ### 1.3 Text doubled by a merge | ||
| 86 | |||
| 87 | **Measured.** Eight blocks of six or more lines repeat within the same file on `main`, the trace of a pull request | ||
| 88 | merged twice or a conflict resolved by keeping both sides (line numbers of the first and last non-blank line of each | ||
| 89 | copy; the last row is the first nine lines of the row four above it, which appear a third time): | ||
| 90 | |||
| 91 | | File | First copy | Second copy | | ||
| 92 | |---|---|---| | ||
| 93 | | `docs/models.md` | 568-651 | 653-736 | | ||
| 94 | | `docs/animation.md` | 971-1023 | 1052-1104 | | ||
| 95 | | `docs/animation.md` | 1025-1050 | 1106-1131 | | ||
| 96 | | `docs/shader_validation.md` | 1998-2040 | 2061-2103 | | ||
| 97 | | `docs/gbuffer.md` | 13-49 | 52-88 | | ||
| 98 | | `docs/testing.md` | 337-353 | 355-371 | | ||
| 99 | | `docs/design.md` | 576-590 | 592-606 | | ||
| 100 | | `docs/shader_validation.md` | 2061-2069 | 2174-2182 | | ||
| 101 | |||
| 102 | The existing guards pass on all of them: `tests/test_docs_repeated_lines.py` compares prose lines at most three lines | ||
| 103 | apart and `tests/test_docs_list_items.py` list items at most eight apart, which a doubled section of 84 lines never | ||
| 104 | is. `scripts/merge_check.py` finds the doubling when it is run before a merge round; nothing finds it after. No new | ||
| 105 | doubled block appeared in the 300 merges, so this part of the check guards a failure that is rare now, not frequent. | ||
| 106 | |||
| 107 | ### 1.4 Whether a check runs before the merge | ||
| 108 | |||
| 109 | **Measured** in the original repository. GitHub's search returned 1,000 of the 1,252 pull requests merged there on 2026-11-23 (it stops at 1,000); | ||
| 110 | all of them came from forks. The CI workflow on the head commit each was merged with had: | ||
| 111 | |||
| 112 | | CI workflow at merge | Pull requests | | ||
| 113 | |---|---| | ||
| 114 | | passed | 55 | | ||
| 115 | | failed | 282 | | ||
| 116 | | queued, pending or still running | 661 | | ||
| 117 | | cancelled, or no run | 2 | | ||
| 118 | |||
| 119 | After a merge the push run does not finish either: 164 of the last 165 CI runs for pushes to `main` were cancelled | ||
| 120 | by the next push, and the last one was still pending when read (2026-11-23, about 20:00 UTC). At `867d922` three | ||
| 121 | documentation tests fail on `main`. `tests/test_docs_cli_flags.py` and `tests/test_docs_links.py` have failed since `cc67780`, and later | ||
| 122 | merges changed the items they report; `tests/test_docs_design_rows.py` has failed since `0980bea` (both found with | ||
| 123 | `git bisect`). Neither pull request had a finished CI run when it was merged. | ||
| 124 | |||
| 125 | So a check that lives only in a CI job would have run before the merge for about one pull request in eighteen. This repository merges the same way: of | ||
| 126 | its 40 most recently merged pull requests (read on 2026-11-24 at about 03:20 UTC), 19 had no CI run at merge, 18 had | ||
| 127 | at least one failing CI job, 2 had jobs still pending and 1 had only passing or skipped jobs. | ||
| 128 | Section 2.1 therefore puts it where the code is written and where merges are decided, not only in CI. | ||
| 129 | |||
| 130 | ## 2. The proposed check | ||
| 131 | |||
| 132 | ### 2.1 How it runs | ||
| 133 | |||
| 134 | **Proposed.** One standard-library script under `scripts/`, run with `python -I` like the other tools. The same | ||
| 135 | command gives the same verdict in three places: | ||
| 136 | |||
| 137 | - **By the author, before opening or updating the pull request.** It compares the working tree with the merge base | ||
| 138 | of `origin/main`. [AGENTS.md](../AGENTS.md) gives an agent the command, and the pull request's `Tested` section | ||
| 139 | names the result, the way it names the tests that were run. | ||
| 140 | - **In the merge round, before the push.** One command takes the round's pull requests in merge order and checks each | ||
| 141 | against `main` plus the ones before it, the way `scripts/merge_check.py` checks a round for repeated merges. It | ||
| 142 | needs no runner, so it does not wait for CI approval or a free runner slot. | ||
| 143 | - **In CI, when the pull request's run is approved.** It compares the test merge with its first parent, as the | ||
| 144 | `change-scope` job of `ci.yml` already does. | ||
| 145 | - It looks only at what the pull request changed: the files it touched are parsed again, the import and include | ||
| 146 | graphs are re-linked, and the functions whose lines changed are measured on both sides. On the 300 merges the | ||
| 147 | prototype took 80 ms per pull request (90th percentile 170 ms, slowest 1.9 s); building the state | ||
| 148 | of a whole tree from cold takes 8.2 s, so a CI job without a cache costs about ten seconds. | ||
| 149 | - What is on the base is tolerated by construction, so there is no baseline list for every pull request to edit and | ||
| 150 | conflict on. The one shared file is the exception list (section 2.5), which changes only when a reviewer approves an | ||
| 151 | exception. | ||
| 152 | - No model, no network, no service: the verdict is the same on every machine. C++ complexity uses lizard, pinned in | ||
| 153 | the CI job; everything else is the standard library. | ||
| 154 | |||
| 155 | ### 2.2 The rules | ||
| 156 | |||
| 157 | **Proposed.** "Blocks" means the CI job fails; "reports" means the finding is listed and the job passes. | ||
| 158 | |||
| 159 | | ID | Rule | Kind | On `main` today | Findings in the 300 merges | | ||
| 160 | |---|---|---|---|---| | ||
| 161 | | P1 | `make_game.py` imports only `tools/` | blocks | 0 | 0 | | ||
| 162 | | P2 | `viewer/` imports nothing from the repository | blocks | 0 | 0 | | ||
| 163 | | P3 | `tools/` does not import `scripts/`, `make_game.py` or `viewer/` | blocks | 0 | 0 | | ||
| 164 | | P4 | `tools/` does not import `tests/` or `runtime/` | blocks | 34 edges, tolerated | 2 | | ||
| 165 | | P5 | `scripts/` does not import `tests/`, `make_game.py` or `viewer/` | blocks | 0 | 0 | | ||
| 166 | | P6 | no new or larger Python import cycle | blocks | 2 cycles, tolerated | 0 | | ||
| 167 | | C1 | production C++ does not include `runtime/test` | blocks | 0 | 0 | | ||
| 168 | | C2 | no new or larger `#include` cycle | blocks | 0 | 0 | | ||
| 169 | | D1 | no new block of six lines repeated within one Markdown file | blocks | 8 blocks, tolerated | 0 | | ||
| 170 | | X1 | a new production function has complexity 10 or lower | blocks | — | 44 in 23 pull requests | | ||
| 171 | | X2 | a changed production function at 10 or lower stays at 12 or lower (`main`: 15) | blocks | — | 4 in 4 pull requests | | ||
| 172 | | X3 | a changed production function above 10 grows by at most 2 (`main`: 5) | blocks | — | 41 in 31 pull requests | | ||
| 173 | | R1 | a block of six or more code lines that duplicates code elsewhere | reports | — | 138 | | ||
| 174 | | R2 | an added skip or suppression (`unittest.skip`, `# noqa` other than E402, `# type: ignore`, ...) | reports | — | 24 | | ||
| 175 | |||
| 176 | An edge counts as new when it exists in the pull request and not in its base; a cycle counts as new when it is not | ||
| 177 | contained in one cycle of the base. Existing edges and cycles are never reported again. | ||
| 178 | |||
| 179 | ### 2.3 The complexity rules in detail | ||
| 180 | |||
| 181 | **Proposed.** | ||
| 182 | |||
| 183 | - Production code only: `tools/`, `scripts/`, `make_game.py`, `viewer/`, `runtime/src`, `runtime/shims` and | ||
| 184 | `runtime/xma_decoder`. Tests are left out; a test that checks forty cases in a row is long, not tangled. | ||
| 185 | - Python complexity is McCabe's: one plus each `if`/`elif`, conditional expression, `for`, `while`, `except`, each | ||
| 186 | extra operand of `and`/`or`, each `for` and `if` of a comprehension, and each `case`. Nested functions are measured | ||
| 187 | on their own. C++ uses lizard's CCN. | ||
| 188 | - A function counts as changed when any of its lines changed; it is compared with the function of the same qualified | ||
| 189 | name in the base. | ||
| 190 | - Dispatch functions are judged one arm at a time. A function is a dispatch function when one `if`/`elif` chain | ||
| 191 | testing a single subject against constants (`op == "..."`, `name in (...)`, `isinstance(x, ...)`) has at least | ||
| 192 | eight arms and holds at least half of its decision points. A new arm then needs a complexity of 10 or lower, a | ||
| 193 | changed arm keeps the +2 allowance, and code outside the arms may grow by 2. Adding a translator rule as one more | ||
| 194 | arm of `Gen._insn` passes; adding a 14-branch arm does not. | ||
| 195 | - `main` and `wmain` may grow by 5 instead of 2, because argument and input checks land there. In the 300 merges | ||
| 196 | this let 18 additions through, all labelled arguable: argument and input checks, and one +3 of other logic in | ||
| 197 | `tools/hashdict.py`. `make_game.py` `main` going from 53 to 59 in one pull request still fails. | ||
| 198 | - Known artefacts, both from the 300 merges: `slot_name` in `runtime/shims/d3d12_xs_device.cpp` grew by five `case` | ||
| 199 | labels of a name table (a C++ function is judged whole, since lizard reports no arms); the `VulkanPresenter` | ||
| 200 | constructor in `runtime/src/vulkan_present.h` gained a parameter, so its name changed and it was judged as a new | ||
| 201 | function. A renamed or moved function is judged as new in the same way. | ||
| 202 | |||
| 203 | ### 2.4 What the author sees | ||
| 204 | |||
| 205 | **Proposed.** Every finding carries four parts: why the rule exists, exactly what triggered it, a fix chosen from the | ||
| 206 | shape of the change, and how to ask for an exception. The same findings are written three ways: a GitHub annotation on | ||
| 207 | the line in the pull request's diff, a job summary with the full text, and plain text for a local run. The prototype's | ||
| 208 | output for `0a8a552`, which grew `export_bank` from 19 to 30: | ||
| 209 | |||
| 210 | ```text | ||
| 211 | ERROR X3 tools/awc_opus.py:381 export_bank went from complexity 19 to 30; a changed function may end at 21 | ||
| 212 | why: A function this branchy is too large to change safely: neither a person nor a coding agent keeps all its cases in view, so an edit breaks a case it did not look at. | ||
| 213 | what: export_bank at tools/awc_opus.py:381-439: complexity 19 -> 30 (limit 10) | ||
| 214 | what: added lines that carry decision points (11 on 8 lines): 383, 385, 397, 403, 432-433, 435, 437 | ||
| 215 | what: tools/awc_opus.py:383 (+1): if cue_sheet: | ||
| 216 | what: tools/awc_opus.py:385 (+1): if os.path.exists(sheet): | ||
| 217 | what: tools/awc_opus.py:397 (+1): if cue_sheet: | ||
| 218 | what: tools/awc_opus.py:403 (+3): if cue_sheet and rate == 48000 and samples > 0: | ||
| 219 | what: tools/awc_opus.py:435 (+2): verified = {cid: limit for cid, limit in frame_limits.items() if channel_counts[cid] == 1} | ||
| 220 | fix: 4 of the added branches test `cue_sheet` (lines 383, 397, 403, 432): that is one optional feature threaded through export_bank. Put its steps into a function of their own and call it where the feature applies. | ||
| 221 | fix: It passes at complexity 21 or lower (now 30): moving 9 decision points out is enough. | ||
| 222 | else: If the rule is wrong for this case, add {"rule": "X3", "path": "tools/awc_opus.py", "key": "export_bank", "reason": "..."} to gate_rules.json in this pull request; it counts once a reviewer approves it. | ||
| 223 | |||
| 224 | ``` | ||
| 225 | |||
| 226 | and for `5e54bda`, the second of the two new imports of test code: | ||
| 227 | |||
| 228 | ```text | ||
| 229 | ERROR P4 tools/div_fixup_diff.py:104 new import tools/div_fixup_diff.py -> tests/semantic/spirv_mini_interp.py: tools/ must not import tests/ or runtime/ files (existing edges are tolerated, new ones are not) | ||
| 230 | why: Hidden cross-module coupling: the imported file is changed as if nothing on this side depended on it, so an edit there can break this file without the author or reviewer expecting it. | ||
| 231 | what: tools/div_fixup_diff.py:104 imports tests/semantic/spirv_mini_interp.py (import spirv_mini_interp) | ||
| 232 | fix: `spirv_mini_interp` is shared code kept in a test folder: 21 other tools/ files already import it (tools/buffer_swizzle_probe.py, tools/bvh_tri_probe.py, tools/f32_fuzz.py, ...). Move tests/semantic/spirv_mini_interp.py to tools/ in its own pull request (the tests then import it from tools/), and import it from there. | ||
| 233 | fix: Do not add tests/semantic to sys.path from tools/div_fixup_diff.py: that is the hidden edge this rule stops. | ||
| 234 | else: If the rule is wrong for this case, add {"rule": "P4", "path": "tools/div_fixup_diff.py", "key": "tests/semantic/spirv_mini_interp.py", "reason": "..."} to gate_rules.json in this pull request; it counts once a reviewer approves it. | ||
| 235 | |||
| 236 | ``` | ||
| 237 | |||
| 238 | ### 2.5 Exceptions | ||
| 239 | |||
| 240 | **Proposed.** A finding that is wrong for a case is not fixed by working around the check. The author adds an entry | ||
| 241 | with the rule, the path, the edge or function and a reason to one exception file at the repository root, in the same | ||
| 242 | pull request; the finding then turns into a note, and the entry is visible in the diff for the reviewer to approve or | ||
| 243 | refuse. An entry that no longer matches anything is reported so the file does not grow stale. | ||
| 244 | |||
| 245 | ## 3. What it does not do | ||
| 246 | |||
| 247 | - It changes no existing code and asks nobody to fix what is already on `main`. The 34 imports of test code from | ||
| 248 | `tools/`, the two import cycles and the eight doubled blocks stay until someone chooses to fix them (section 4). | ||
| 249 | - It does not judge whether code is correct; the tests and the reviewer still do that. | ||
| 250 | - It blocks nothing on code duplication or on skips: the tests copy their templates on purpose, and nearly every skip | ||
| 251 | added in the 300 merges was a missing tool, platform or numpy, which is legitimate. | ||
| 252 | - It needs no model and no service. The author adapted it from a gate they use in their own projects; there, a local | ||
| 253 | model chose which documents an agent should read before a change. That part is left out here: the rules file and | ||
| 254 | the messages say what applies to a change, and the same verdict comes out on every machine. | ||
| 255 | |||
| 256 | ## 4. Rollout | ||
| 257 | |||
| 258 | **Proposed**, each step its own pull request: | ||
| 259 | |||
| 260 | 1. This page, for the decision. | ||
| 261 | 2. The implementation: the script with its merge-round mode, the rules and exception files, a standard-library test | ||
| 262 | file under `tests/` (the CI loop picks it up, as `tests/test_ci_registration.py` requires), a job on | ||
| 263 | `ubuntu-24.04`, a few lines in [AGENTS.md](../AGENTS.md) that give an agent the local command and the map of which | ||
| 264 | area may import which, and one line in the pull request template for the result. | ||
| 265 | 3. Follow-up items for the coordination issue, for anyone to claim: move `tests/semantic/spirv_mini_interp.py`, | ||
| 266 | `tests/semantic/spirv_wave_interp.py` and `tests/spirv_interp.py` under `tools/` (removes 25 of the 34 imports | ||
| 267 | of test code from `tools/` at once); delete the second copy of each doubled block in section 1.3; split the largest production | ||
| 268 | functions, starting with those changed most often. | ||
| 269 | |||
| 270 | ## 5. Decisions for the maintainer | ||
| 271 | |||
| 272 | **Open.** | ||
| 273 | |||
| 274 | 1. Are the boundaries in section 2.2 the intended ones? In particular P4: should the reference interpreters move | ||
| 275 | under `tools/` (proposed), or should `tests/semantic` be declared a library that tools may import? | ||
| 276 | 2. Complexity: production code only, limit 10 for a new function, +2 for a changed one (+5 for `main`), dispatch | ||
| 277 | arms judged one by one — accept, or which number to change? | ||
| 278 | 3. Should the job block from the first day (proposed), given the 48 of 300 pull requests it would have | ||
| 279 | stopped and the share of those that were real? | ||
| 280 | 4. Should the merge round run it before each push (proposed, since CI has not finished for most merges; section 1.4), | ||
| 281 | and should a pull request whose author reports no result be sent back? Where should the CI job live, in `ci.yml` | ||
| 282 | or a workflow of its own, and who approves an entry in the exception file? | ||
| 283 | 5. `runtime/src` includes `runtime/shims` from `main.cpp` and `pe_loader.cpp`, and the shims include `runtime/src`: | ||
| 284 | is the loader the composition root that may include both, or should one direction be forbidden? | ||
| 285 | |||
| 286 | ## 6. How the numbers were measured | ||
| 287 | |||
| 288 | - Tree: `dde82f2`. History: the 300 single-parent squash merges that end with it (`dde82f2` and the 299 before it), | ||
| 289 | each compared with its parent; the commit below them is the root of the shallow clone and only served as a base. | ||
| 290 | - Python imports: resolved from the AST, through each file's own directory and every `sys.path` set-up it performs | ||
| 291 | (`insert`, `append`, slice assignment, `extend`, paths from `conftest.py` and from an imported helper). | ||
| 292 | `importlib` loads with a constant path count as edges. The resolver is a heuristic; it left no import of a | ||
| 293 | repository module unresolved in the measured areas. | ||
| 294 | - C++ includes: quoted includes only, resolved against the including file's directory and then the union of the | ||
| 295 | include directories in `runtime/CMakeLists.txt`. | ||
| 296 | - Complexity: Python on the AST with the definition in section 2.3; C++ with lizard 1.24.1. | ||
| 297 | - Duplication: windows of six significant lines (whitespace normalised; blank lines, comments and lines with fewer | ||
| 298 | than four non-space characters skipped). | ||
| 299 | - Every blocking finding was labelled by reading its diff, by one reader: the coding agent that ran the backtest. | ||
| 300 | Each label has a one-line reason (most generated from the label's class and the measured change, five written by | ||
| 301 | hand), and the list can be posted here on request. "Genuine" and "arguable" are a | ||
| 302 | judgement about value; every finding except the 2 artefacts is a correct measurement under the rule as written. | ||
| 303 | - Not measured: how often the rules with no finding in the window (P1 to P3, P5, P6, C1, C2, D1) would be wrong. | ||
| 304 | The prototype's own test builds a small repository in which every rule fires once. | ||
| 305 | - The 300 merges are one merge round of the original repository (committed between 09:35 and 11:23 UTC-6 on 2026-11-23) of pull requests opened | ||
| 306 | over a longer time; rates per pull request may differ in other rounds. | ||
| 307 | - The merge counts in the introduction come from GitHub's search (`is:pr is:merged merged:<date>`), read on | ||
| 308 | 2026-11-23 at about 20:00 UTC. | ||
| 309 | - Section 1.4: the GraphQL search for pull requests merged on 2026-11-23, with the check suites of each one's last | ||
| 310 | commit, taking the suite of the workflow named CI; the push runs from the Actions list for `main`; the first failing | ||
| 311 | commit of each documentation test by `git bisect` between the oldest commit of the window and `867d922`, and each | ||
| 312 | pull request's checks from its page. All read on 2026-11-23 at about 20:00 UTC, before that repository went private. The | ||
| 313 | figures for this repository come from the checks of its 40 most recently merged pull requests. | ||
diff --git a/docs/d3d12_command_objects.md b/docs/d3d12_command_objects.md index 2b4c2d873..92653e2ea 100644 --- a/docs/d3d12_command_objects.md +++ b/docs/d3d12_command_objects.md | |||
| @@ -120,7 +120,7 @@ these four slots. Measured on 1.0.2.1 (counts only): | |||
| 120 | | Image | `ID3D12*` IIDs it contains | Imports from `d3d12_xs.dll` | Calls at `0x40`/`0x48`/`0x60`/`0x120` on the device | | 120 | | Image | `ID3D12*` IIDs it contains | Imports from `d3d12_xs.dll` | Calls at `0x40`/`0x48`/`0x60`/`0x120` on the device | |
| 121 | |---|---|---|---| | 121 | |---|---|---|---| |
| 122 | | `XboxBvhBuilder.dll` | `PipelineState`, `RootSignature` | `D3D12SerializeVersionedRootSignature` | none: no indirect call at any of the four offsets | | 122 | | `XboxBvhBuilder.dll` | `PipelineState`, `RootSignature` | `D3D12SerializeVersionedRootSignature` | none: no indirect call at any of the four offsets | |
| 123 | | `amd_fidelityfx_upscaler_xbox.dll` | `CommandSignature`, `DescriptorHeap`, `Device`, `Heap`, `PipelineState`, `Resource`, `RootSignature`, `RootSignatureDeserializer` | `D3D12CreateRootSignatureDeserializer` | none: the 3 calls at `0x40` are `ID3D12Resource::Map` on a resource it has just created, the 29 at `0x48` are `Close`/`Unmap`-shaped calls with no `(type, &IID, &out)` arguments, the 4 at `0x60` are a function-pointer field in a plain struct (no vtable load), and there are none at `0x120` | | 123 | | `amd_fidelityfx_upscaler_xbox.dll` | `CommandSignature`, `DescriptorHeap`, `Device`, `Heap`, `PipelineState`, `Resource`, `RootSignature`, `RootSignatureDeserializer` | `D3D12CreateRootSignatureDeserializer` | none: the 3 calls at `0x40` are `ID3D12Resource::Map` on a resource it has just created, the 29 at `0x48` are `Close`/`Unmap`-shaped calls with no `(type, &IID, &out)` arguments (§2.1a explains why that shape rules out `CreateCommandAllocator`), the 4 at `0x60` are a function-pointer field in a plain struct (no vtable load), and there are none at `0x120` | |
| 124 | | `amd_fidelityfx_loader_xbox.dll`, `Bink2Scarlett.dll` | none | none | — | | 124 | | `amd_fidelityfx_loader_xbox.dll`, `Bink2Scarlett.dll` | none | none | — | |
| 125 | 125 | ||
| 126 | Neither image contains the IID of `ID3D12CommandQueue`, `ID3D12CommandAllocator`, | 126 | Neither image contains the IID of `ID3D12CommandQueue`, `ID3D12CommandAllocator`, |
| @@ -172,6 +172,83 @@ at `0x142478B56` → `0x142478B71` ([retail_boot_chain.md](retail_boot_chain.md) | |||
| 172 | `IID_ID3D12GraphicsCommandList` (`0x1461ECFA0`) is passed to slot 73 at a separate site | 172 | `IID_ID3D12GraphicsCommandList` (`0x1461ECFA0`) is passed to slot 73 at a separate site |
| 173 | (`0x1417F6D1D` → `0x1417F6D34`). | 173 | (`0x1417F6D1D` → `0x1417F6D34`). |
| 174 | 174 | ||
| 175 | ### 2.1a A byte offset is not a method: `0x48` and `0x50` | ||
| 176 | |||
| 177 | `0x48` and `0x50` are the worst pair in the whole surface because the same two numbers name a | ||
| 178 | *device factory* in one receiver and two *descriptor-heap getters* in another. The offset alone | ||
| 179 | therefore decides nothing; a call site has to be resolved to its receiver's interface first. On | ||
| 180 | the device (this page's subject) `0x48` is `CreateCommandAllocator` and `0x50` is not used at | ||
| 181 | all. On an `ID3D12DescriptorHeap` the same two offsets are `GetCPUDescriptorHandleForHeapStart` | ||
| 182 | and `GetGPUDescriptorHandleForHeapStart`, because `ID3D12DescriptorHeap` inherits | ||
| 183 | `IUnknown` + `ID3D12Object` + `ID3D12DeviceChild` (eight slots) and puts `GetDesc` at `0x40`, | ||
| 184 | the CPU getter at `0x48` and the GPU getter at `0x50` (`d3d12.h:5768`, `:5775`, `:5782`). | ||
| 185 | |||
| 186 | | Receiver | `0x48` | `0x50` | | ||
| 187 | |---|---|---| | ||
| 188 | | `ID3D12Device` | `CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE, REFIID, void**)`, `HRESULT` | — (no call site in the image) | | ||
| 189 | | `ID3D12CommandQueue` (§2.2) | `CopyTileMappings(...)`, `HRESULT` | `ExecuteCommandLists(...)`, no return | | ||
| 190 | | `ID3D12DescriptorHeap` | `GetCPUDescriptorHandleForHeapStart()`, 8-byte handle in `RAX` | `GetGPUDescriptorHandleForHeapStart()`, 8-byte handle in `RAX` | | ||
| 191 | |||
| 192 | Three interfaces, three meanings at each offset, and the shapes do not overlap, which is what | ||
| 193 | makes the resolution possible: a device factory call is `(rcx = device, edx = type, rdx = &IID, | ||
| 194 | r8 = &out)` and tests `eax`; a heap getter is `(rcx = heap)` alone and consumes `rax`; a queue | ||
| 195 | call passes list arrays or does not return a value. | ||
| 196 | |||
| 197 | **Measured, device side.** The device object lives in the global `0x148759D00` and is set up in | ||
| 198 | `0x142478440`. That function has six sites at `+0x48`: two are the device | ||
| 199 | (`0x142478B2D` with `xor edx, edx` and `0x142478C3B` with `mov edx, 2`), each passing | ||
| 200 | `&IID_ID3D12CommandAllocator` at `0x1461E0658` | ||
| 201 | (`6102dee4-af59-4b09-b999-b44d73f09b24`, `d3d12.h:5192`) and a distinct out slot; two are | ||
| 202 | `ID3D12GraphicsCommandList::Close` on the list it just created, and two are no-argument calls on | ||
| 203 | the globals `0x1475E7390`/`0x1475E7420` (the getter shape). Across the whole image, scanning the rip-relative | ||
| 204 | device load in front of every `+0x48` and `+0x50` call site finds **2 device sites at `0x48` and | ||
| 205 | none at `0x50`**: the game never calls anything at device `0x50`, so a replacement runtime | ||
| 206 | should leave that slot inert rather than guess a meaning for it. | ||
| 207 | |||
| 208 | **Measured, heap side.** `0x141CF3280` is the clearest anchor. It calls device `0x70` | ||
| 209 | (`CreateDescriptorHeap`, see §4.2 for that slot) with a `D3D12_DESCRIPTOR_HEAP_DESC` and | ||
| 210 | `&IID_ID3D12DescriptorHeap` (`0x1461E0628`, `8efb471d-616c-4f49-90f7-127bb763fa51`, | ||
| 211 | `d3d12.h:5763`), then calls the returned object at `0x48` and `0x50` with only `this`: it caches | ||
| 212 | the CPU handle, asserts it equals the expected base address, and subtracts it from the GPU | ||
| 213 | handle to store the GPU−CPU base delta. `0x141C744F0` does the same `0x70`/`0x48` pair and | ||
| 214 | strides the returned CPU handle by the `GetDescriptorHandleIncrementSize` value from device | ||
| 215 | `0x78` while filling a descriptor array. Both are `create → get handle → arithmetic`, which is | ||
| 216 | what the two getters are for. | ||
| 217 | |||
| 218 | | Shape | Site | Receiver | | ||
| 219 | |---|---|---| | ||
| 220 | | CPU getter, base for a descriptor array | `0x141C74559` | heap returned by device `0x70` | | ||
| 221 | | CPU getter, asserted against the expected base | `0x141CF3358` | heap returned by device `0x70` | | ||
| 222 | | GPU getter, minus the CPU handle = base delta | `0x141CF3392` | heap returned by device `0x70` | | ||
| 223 | |||
| 224 | **How often the shapes collide.** Of the 33 functions that contain a `+0x70` call and a `+0x48` | ||
| 225 | call, and the 81 that contain `+0x70` and `+0x50`, 19 trace a `+0x48`/`+0x50` receiver back to | ||
| 226 | the `CreateDescriptorHeap` return: 47 sites, 14 of them passing only `this`. In a heap-creating | ||
| 227 | function, a bare `(this)` call at `0x48`/`0x50` whose result comes back in `RAX` is therefore a | ||
| 228 | getter, and the `(type, &IID, &out)` form at the same offset is the device factory. | ||
| 229 | |||
| 230 | **Where one hop is not enough.** Four shapes in the same function population are *not* heap | ||
| 231 | getters and would be misfiled by offset alone: | ||
| 232 | |||
| 233 | - `0x14080C3E0` passes `plVar1[1]`, an inner object, at `0x48`/`0x50` and tests the returned | ||
| 234 | `char`: a boolean pair, not handles; | ||
| 235 | - `0x14049E200` passes an out buffer in `rdx` at `0x50`, the C `RetVal` variant from | ||
| 236 | `d3d12.h:5784`; | ||
| 237 | - `0x140087040` is a dispatch thunk that forwards `rdx`/`r8` to whichever slot matches a tag | ||
| 238 | byte, so both offsets show two extra argument registers there; | ||
| 239 | - `0x141993B30` reloads `rcx` from a factory global before its `0x50` call, so a trace that only | ||
| 240 | remembers "this register once held the heap" mislabels it. | ||
| 241 | |||
| 242 | Confidence: the device/handle distinction is **Measured**; the getter *names* come from the SDK | ||
| 243 | declarations and are matched to the measured `create → handle → arithmetic` shape, not read from | ||
| 244 | the runtime, which the package does not ship (§1.1). | ||
| 245 | |||
| 246 | Reproduce: the receiver scan disassembles each function holding a `+0x70` call, tracks the | ||
| 247 | `RAX` return into the registers and stack slots it is stored to, and prints the argument | ||
| 248 | registers in front of every `+0x48`/`+0x50` call that resolves to that object; the device side | ||
| 249 | resolves rip-relative globals to `0x148759D00` the same way. Ghidra's decompiler of | ||
| 250 | `0x141CF3280`, `0x141C744F0` and `0x142478440` shows the same three shapes in one screen. | ||
| 251 | |||
| 175 | ### 2.2 Queue, allocator and fence | 252 | ### 2.2 Queue, allocator and fence |
| 176 | 253 | ||
| 177 | `ID3D12CommandQueue` is declared at `d3d12.h:8701`. It has 19 slots (0–18); its own methods start | 254 | `ID3D12CommandQueue` is declared at `d3d12.h:8701`. It has 19 slots (0–18); its own methods start |
| @@ -749,7 +826,9 @@ surface, not the command objects: | |||
| 749 | 826 | ||
| 750 | - device slots 1/14/15/16/18/19/27/38 in desktop order; slot 14 is `CreateDescriptorHeap`; | 827 | - device slots 1/14/15/16/18/19/27/38 in desktop order; slot 14 is `CreateDescriptorHeap`; |
| 751 | - device slot 62 is called as `CreateComputePipelineState` (the PC interface's slot 62 is | 828 | - device slot 62 is called as `CreateComputePipelineState` (the PC interface's slot 62 is |
| 752 | `CreateStateObject`), and slot 76 is Xbox texture creation; | 829 | `CreateStateObject`), and slot 76 is Xbox texture creation. In the retail executable slot 62 measures five |
| 830 | parameters, `(desc, 0, 0, &riid, &out)`, which the three-argument PC method loses, and the executable itself | ||
| 831 | never calls slot 76 (the callers in this bullet are the package DLLs); | ||
| 753 | - descriptor-heap `GetCPU/GPUDescriptorHandleForHeapStart` (heap slots 9/10) return the 8-byte | 832 | - descriptor-heap `GetCPU/GPUDescriptorHandleForHeapStart` (heap slots 9/10) return the 8-byte |
| 754 | handle in RAX; | 833 | handle in RAX; |
| 755 | - Xbox root-signature descriptors carry flags `0x03000000`, masked on a copy; | 834 | - Xbox root-signature descriptors carry flags `0x03000000`, masked on a copy; |
diff --git a/docs/d3d12_vulkan.md b/docs/d3d12_vulkan.md index c5c4c4922..8548a5ac6 100644 --- a/docs/d3d12_vulkan.md +++ b/docs/d3d12_vulkan.md | |||
| @@ -164,7 +164,7 @@ The design is therefore an **IR per command list**: | |||
| 164 | here, while the host hands out a video list (`E_NOINTERFACE` for `ID3D12GraphicsCommandList`), so they are not | 164 | here, while the host hands out a video list (`E_NOINTERFACE` for `ID3D12GraphicsCommandList`), so they are not |
| 165 | compared. | 165 | compared. |
| 166 | - `Close` freezes the IR. `ExecuteBundle` is accepted only on a direct list, with an already-closed bundle as its callee; the bundle's recorded commands and calls are replayed at the call site, so the source can be reused or reset without changing the parent. Command-list creation and reset require an allocator of the same type. A bundle cannot be submitted directly to a command queue. | 166 | - `Close` freezes the IR. `ExecuteBundle` is accepted only on a direct list, with an already-closed bundle as its callee; the bundle's recorded commands and calls are replayed at the call site, so the source can be reused or reset without changing the parent. Command-list creation and reset require an allocator of the same type. A bundle cannot be submitted directly to a command queue. |
| 167 | - Bundle restrictions are checked while recording for the IR operations currently implemented here (barriers, clears, copies, resolves, `SetPredication`, `DiscardResource`, the atomic copies, `RSSetViewports`, `RSSetScissorRects`, `OMSetRenderTargets` and `ClearState`; `WriteBufferImmediate` is allowed in a bundle); those calls are not legal inside a D3D12 bundle and make `Close` return `E_INVALIDARG`. `d3d12_bundle_forbidden_test` measured the last four on the PC runtime without the debug layer: the bundle's `Close` fails (`E_FAIL`, where this layer gives `E_INVALIDARG`) on the default adapter and on WARP, and executing a bundle whose `Close` failed crashes the runtime, so the layer refuses it in `ExecuteBundle` instead. A bundle has no render targets, viewport or root signature of its own, so its state calls (pipeline state, root signature and arguments, vertex and index buffers, topology, blend factor, stencil references) and its draws and dispatches are kept as they were called, and `ExecuteBundle` plays them on the parent through the same members the application would have called. A draw then snapshots the parent's state plus what the bundle set, and what the bundle set stays on the parent afterwards. Commands that need no state (markers, immediate writes) are copied between them in order. `d3d12_bundle_test` measured the rule on the PC runtime, where the default adapter (an RTX 4060 Ti) and WARP drew the same picture in every case it ran. A bundle's draws see the parent's render targets, viewport and scissor, root signature and arguments (also when the bundle sets the same root signature first, so those arguments stay), and vertex and index buffers. A bundle starts with the pipeline state it was created or reset with, not the parent's. After `ExecuteBundle` the parent has that pipeline state and whatever else the bundle set: topology, root arguments, vertex and index buffers, and a different root signature with the bundle's arguments in place of the parent's. Topology: the default adapter takes the parent's when the bundle sets none. That is more lenient than Microsoft's stated rule (topology is undefined when a bundle begins), and WARP follows the rule by removing the device when a bundle draws or hands back without one, so a bundle should set it; the layer follows the default adapter. A bundle that sets a root argument before any root signature crashes the NVIDIA driver (the layer applies it to the parent's signature). The deferred calls are checked when they play, against the parent's root signature, so a bad one makes the parent's `Close` fail, not the bundle's. A per-list state setter must go through the deferred path (`defer()` in `d3d12_com.cpp`, replaying through a private member that does not trace) to work in a bundle. Not deferred yet: `ExecuteIndirect` in a bundle, and bundle `Dispatch` has no GPU test. | 167 | - Bundle restrictions are checked while recording for the IR operations currently implemented here (barriers, clears, copies, resolves, `SetPredication`, `DiscardResource`, the atomic copies, `RSSetViewports`, `RSSetScissorRects`, `OMSetRenderTargets` and `ClearState`; `WriteBufferImmediate` is allowed in a bundle); those calls are not legal inside a D3D12 bundle and make `Close` return `E_INVALIDARG`. `d3d12_bundle_forbidden_test` measured the last four on the PC runtime without the debug layer: the bundle's `Close` fails (`E_FAIL`, where this layer gives `E_INVALIDARG`) on the default adapter and on WARP, and executing a bundle whose `Close` failed crashes the runtime, so the layer refuses it in `ExecuteBundle` instead. A bundle has no render targets, viewport or root signature of its own, so its state calls (pipeline state, root signature and arguments, vertex and index buffers, topology, blend factor, stencil references) and its draws and dispatches are kept as they were called, and `ExecuteBundle` plays them on the parent through the same members the application would have called. A draw then snapshots the parent's state plus what the bundle set, and what the bundle set stays on the parent afterwards. Commands that need no state (markers, immediate writes) are copied between them in order. `d3d12_bundle_test` measured the rule on the PC runtime, where the default adapter (an RTX 4060 Ti) and WARP drew the same picture in every case it ran. A bundle's draws see the parent's render targets, viewport and scissor, root signature and arguments (also when the bundle sets the same root signature first, so those arguments stay), and vertex and index buffers. A bundle starts with the pipeline state it was created or reset with, not the parent's. After `ExecuteBundle` the parent has that pipeline state and whatever else the bundle set: topology, root arguments, vertex and index buffers, and a different root signature with the bundle's arguments in place of the parent's. Topology: the default adapter takes the parent's when the bundle sets none. That is more lenient than Microsoft's stated rule (topology is undefined when a bundle begins), and WARP follows the rule by removing the device when a bundle draws or hands back without one, so a bundle should set it; the layer follows the default adapter. A bundle that sets a root argument before any root signature crashes the NVIDIA driver (the layer applies it to the parent's signature). The deferred calls are checked when they play, against the parent's root signature, so a bad one makes the parent's `Close` fail, not the bundle's. A per-list state setter must go through the deferred path (`defer()` in `d3d12_com.cpp`, replaying through a private member that does not trace) to work in a bundle. `ExecuteIndirect` in a bundle is deferred the same way (see `CreateCommandSignature` and `ExecuteIndirect` below): a single DRAW, DRAW_INDEXED, DISPATCH or DISPATCH_MESH operation with no count buffer plays at each `ExecuteBundle` with the parent's state at that call, and a count buffer or a signature with root or IA arguments makes the bundle's `Close` fail. `d3d12_bundle_indirect_dispatch` measured the DISPATCH case on the PC runtime (an RTX 4060, driver 610.88, and WARP, Windows 11 10.0.26300.9974): a bundle created with a compute pipeline and no root signature, executed twice with a different root UAV bound on the parent each time, wrote each run's counters through the parent's root UAV of that call, also when the bundle set the parent's root signature first, and a direct `Dispatch` right after the second `ExecuteBundle` (behind a UAV barrier, with no rebind) still wrote through the parent's root UAV, so the parent keeps its root signature and arguments. Both host adapters return `E_INVALIDARG` from the bundle's `Close` for a count buffer and for a root-constant signature, the code this layer gives. Bundle `Dispatch` itself has no GPU test. |
| 168 | - What `Close` returns after one recorded call is compared with the PC runtime over WARP (no debug layer) by | 168 | - What `Close` returns after one recorded call is compared with the PC runtime over WARP (no debug layer) by |
| 169 | `d3d12_close_parity_test`, 116 cases on fresh lists, nothing executed. 85 agree (three of them enhanced texture | 169 | `d3d12_close_parity_test`, 116 cases on fresh lists, nothing executed. 85 agree (three of them enhanced texture |
| 170 | barriers, two into `LAYOUT_UNDEFINED`: section 4.3); the other 31 are listed in the | 170 | barriers, two into `LAYOUT_UNDEFINED`: section 4.3); the other 31 are listed in the |
| @@ -400,9 +400,10 @@ What is implemented (all of it testable without the game): | |||
| 400 | - **Device** (`runtime/shims/d3d12_vulkan_device.cpp`): an `ID3D12Device11` (PC ABI, 80 slots) that the Xbox-ABI | 400 | - **Device** (`runtime/shims/d3d12_vulkan_device.cpp`): an `ID3D12Device11` (PC ABI, 80 slots) that the Xbox-ABI |
| 401 | proxy (`d3d12_xs_device.cpp`) forwards to, so slot 14's heap-handle conversion and slot 76's resource creation | 401 | proxy (`d3d12_xs_device.cpp`) forwards to, so slot 14's heap-handle conversion and slot 76's resource creation |
| 402 | work unchanged. It creates the objects above, plus: | 402 | work unchanged. It creates the objects above, plus: |
| 403 | - descriptor heaps whose slots are 32 bytes (`GetDescriptorHandleIncrementSize`; the console's increments are | 403 | - descriptor heaps whose slots are 32 bytes (`GetDescriptorHandleIncrementSize`). The game asks the device for the |
| 404 | question 4). RTV/DSV slots hold a `TargetView`; shader-visible heaps return a GPU handle, but nothing reads it | 404 | increment and derives heap sizes and handle strides from the answer (measured, section 3.4), so the shim returns |
| 405 | yet; | 405 | its own host slot size. RTV/DSV slots hold a `TargetView`; shader-visible heaps return a GPU handle, but nothing |
| 406 | reads it yet; | ||
| 406 | - `CreateRenderTargetView` / `CreateDepthStencilView` for whole resources, `TEXTURE1D`, `TEXTURE1DARRAY` (D3D-63), | 407 | - `CreateRenderTargetView` / `CreateDepthStencilView` for whole resources, `TEXTURE1D`, `TEXTURE1DARRAY` (D3D-63), |
| 407 | `TEXTURE2D`, `TEXTURE2DMS`, `TEXTURE2DARRAY` and `TEXTURE2DMSARRAY` (a slice range; `ArraySize` -1 is every | 408 | `TEXTURE2D`, `TEXTURE2DMS`, `TEXTURE2DARRAY` and `TEXTURE2DMSARRAY` (a slice range; `ArraySize` -1 is every |
| 408 | slice from the first on, as on the host, `d3d12_view_slices_test`); | 409 | slice from the first on, as on the host, `d3d12_view_slices_test`); |
| @@ -523,6 +524,8 @@ What is implemented (all of it testable without the game): | |||
| 523 | direct parent's state at that call. Count buffers and compound signatures remain invalid in bundles. | 524 | direct parent's state at that call. Count buffers and compound signatures remain invalid in bundles. |
| 524 | `d3d12_bundle_indirect_warp` and `d3d12_bundle_indirect_layer` compare DRAW and DRAW_INDEXED against direct | 525 | `d3d12_bundle_indirect_warp` and `d3d12_bundle_indirect_layer` compare DRAW and DRAW_INDEXED against direct |
| 525 | pixels with two different parent bindings; the layer fixture also checks marker order and captured views. | 526 | pixels with two different parent bindings; the layer fixture also checks marker order and captured views. |
| 527 | `d3d12_bundle_indirect_dispatch` checks DISPATCH the same way against the counters WARP and the default | ||
| 528 | adapter write (bundle section above). | ||
| 526 | Compound graphics signatures, non-unit instance divisors | 529 | Compound graphics signatures, non-unit instance divisors |
| 527 | and unsupported capabilities stay guarded. A GPU-counted draw currently requires | 530 | and unsupported capabilities stay guarded. A GPU-counted draw currently requires |
| 528 | `maxDrawIndirectCount == UINT32_MAX`: Vulkan also limits the raw counter value, not just the caller's maximum. | 531 | `maxDrawIndirectCount == UINT32_MAX`: Vulkan also limits the raw counter value, not just the caller's maximum. |
| @@ -886,7 +889,42 @@ The compute path, end to end: | |||
| 886 | D3D-448); the compute bind point uses it. | 889 | D3D-448); the compute bind point uses it. |
| 887 | - **GPU address arena** (section 3.3, when the device has `bufferDeviceAddress`): one host-visible, | 890 | - **GPU address arena** (section 3.3, when the device has `bufferDeviceAddress`): one host-visible, |
| 888 | device-addressable buffer, 256 MiB by default (`LEONIDA_ARENA_MB`, at most 4095 MiB, so every VA fits 32-bit | 891 | device-addressable buffer, 256 MiB by default (`LEONIDA_ARENA_MB`, at most 4095 MiB, so every VA fits 32-bit |
| 889 | table pointers). | 892 | table pointers). `LEONIDA_ARENA_MB` bounds the address range; with sparse binding it is not memory. |
| 893 | - **Backing blocks** (`runtime/src/arena_backing.h`). Where the device has `sparseBinding`, | ||
| 894 | `sparseResidencyBuffer`, `residencyNonResidentStrict`, a sparse address space at least as large as the arena and | ||
| 895 | a queue with the sparse binding bit to spare (`pick_arena_bind_queue`: RADV's sparse-only family), the arena is a | ||
| 896 | sparse buffer and its memory comes in units bound in 2 MiB blocks: a block is bound when the first allocation | ||
| 897 | needs it, before the allocation is handed out, and unbound once its last allocation is released and the GPU has | ||
| 898 | passed the retire ticket of the release (`submitted_retire_ticket() + 1`, checked at the start of every | ||
| 899 | `ExecuteCommandLists` against `completed_retire_ticket()`), then its memory is freed. Binds go to that queue alone | ||
| 900 | and are waited for there, so a bind never sits behind a submission that waits for a fence the CPU signals later. | ||
| 901 | - **Only with signed V# offsets.** A driver can place a sparse buffer anywhere relative to ordinary ones: RADV | ||
| 902 | (Mesa 26.3.1, natively and under Wine) gives sparse buffers a range of their own 64 TiB above them | ||
| 903 | (0xffffc00100200000 against 0xffff800100010000), so with a sparse arena every buffer outside it (geometry copies, | ||
| 904 | title windows and shadows outside it, upload buffers) lies below heap_base, at a negative offset. A shader that | ||
| 905 | sign-extends a V#'s 48-bit base (docs/design.md, "Heap-relative buffer device addresses") reaches it, since RADV | ||
| 906 | hands out addresses from one 2^47 half of the 48-bit space, so any two lie within 2^47 of each other. One that | ||
| 907 | zero-extends does not. The device counts each loaded module's `vsharp_base_sign_extended` marker | ||
| 908 | (`VsharpBaseCensus`, `runtime/src/shader_library.h`) and logs | ||
| 909 | `V# bases: signed offsets from heap_base (N of N modules sign-extend)`. The arena is sparse only when every module | ||
| 910 | sign-extends (or `LEONIDA_IMPORT_BELOW_ARENA=1` says to read bases signed). With older modules it stays one | ||
| 911 | allocation and one line says why. `TitleBufferWindows::shader_reachable` checks every block made outside the | ||
| 912 | arena against the same range when it is made, and a block it refuses is logged with both addresses. | ||
| 913 | `d3d12_title_va_game_device` and `d3d12_geometry_views_game_device` run the title-memory tests on the device the | ||
| 914 | game makes (with the bind queue), so on RADV their windows and geometry copies are read through negative offsets. | ||
| 915 | - No allocation crosses a unit: one no larger than a block stays inside one block, a larger one takes whole blocks | ||
| 916 | of its own. So each allocation is one run of one mapping, and the CPU reaches an arena offset through | ||
| 917 | `DeviceState::arena_host()` (one table read; null, with a line, for a range without memory), or | ||
| 918 | `ArenaBacking::with_host()` for an offset the caller does not hold (value writes, `read_arena`). A D3D12 heap in the | ||
| 919 | arena lends its unit's memory to reserved resources' tiles at the heap's place in that unit. | ||
| 920 | - The block size is measured, not tuned: a world run had about 5,000 live arena allocations averaging 160 KiB | ||
| 921 | (790 MiB live, 990 MiB peak end, 4,095 MiB asked). 2 MiB is a multiple of the 64 KiB sparse page, keeps a 4 GiB | ||
| 922 | arena within the 4,096 memory objects some Windows drivers allow (2,048 at most, about 500 at that peak), and is | ||
| 923 | amdgpu's large page. | ||
| 924 | - Without those capabilities (llvmpipe: a 2 GiB sparse address space and one queue) one allocation backs the whole | ||
| 925 | arena, as before, through the same accessors. `arena_backing_test` (CPU) and `arena_sparse_gpu_test` (a real | ||
| 926 | device; skipped without sparse binding) check both. The arena's line at device release (and with a console | ||
| 927 | heap's log) reads `GPU address arena: bound N MiB now (peak P, U units of 2 MiB blocks, sparse)`. | ||
| 890 | - It is also no larger than the device's `maxBufferSize` (Vulkan 1.3) and, counting the buffer's memory | 928 | - It is also no larger than the device's `maxBufferSize` (Vulkan 1.3) and, counting the buffer's memory |
| 891 | requirement, `maxMemoryAllocationSize` (Vulkan 1.1), whichever is smaller (`runtime/src/arena_size.h`). When a | 929 | requirement, `maxMemoryAllocationSize` (Vulkan 1.1), whichever is smaller (`runtime/src/arena_size.h`). When a |
| 892 | limit cuts the request, one log line names the limit and the size used. `arena_size_test` (CPU) checks the | 930 | limit cuts the request, one log line names the limit and the size used. `arena_size_test` (CPU) checks the |
| @@ -1732,7 +1770,9 @@ The copies: | |||
| 1732 | cover (the title remaps its pool frames instead), and the tracker follows the pages. | 1770 | cover (the title remaps its pool frames instead), and the tracker follows the pages. |
| 1733 | A tracker the window shared with a copy still live keeps its extent (a retirement never splits one). A window that | 1771 | A tracker the window shared with a copy still live keeps its extent (a retirement never splits one). A window that |
| 1734 | cannot fit between the title's address reservations can use a separate mapped buffer. The buffer's device address | 1772 | cannot fit between the title's address reservations can use a separate mapped buffer. The buffer's device address |
| 1735 | must fit as a positive 47-bit offset from the arena base. The same window cap and dirty-page refresh apply. | 1773 | must lie within reach of a V# base from the arena base: a positive offset below 2^47, or, when every loaded shader |
| 1774 | sign-extends the base, anywhere within 2^47 on either side (`TitleBufferWindows::shader_reachable`). The same | ||
| 1775 | window cap and dirty-page refresh apply. | ||
| 1736 | `LEONIDA_STREAM_BUFFER_WINDOWS=0` requires the window to fit in the arena. | 1776 | `LEONIDA_STREAM_BUFFER_WINDOWS=0` requires the window to fit in the arena. |
| 1737 | - **What the GPU wrote goes back.** The same return copy serves slot-133 shadows (a buffer the driver would not | 1777 | - **What the GPU wrote goes back.** The same return copy serves slot-133 shadows (a buffer the driver would not |
| 1738 | import, a compute result the title reads again): the ranges are recorded through the alias of the buffer's pages and | 1778 | import, a compute result the title reads again): the ranges are recorded through the alias of the buffer's pages and |
| @@ -2140,15 +2180,90 @@ The game can use D3D12 descriptors in three ways, and the layer must handle all | |||
| 2140 | Missing console V# backing leaves a zero descriptor in the copy. Each V# half of a console resource heap's copy | 2180 | Missing console V# backing leaves a zero descriptor in the copy. Each V# half of a console resource heap's copy |
| 2141 | (the buffer V# and the UAV counter) has a record in host RAM of what it resolved to: the title's base and span, | 2181 | (the buffer V# and the UAV counter) has a record in host RAM of what it resolved to: the title's base and span, |
| 2142 | the device address its copy names, and whether it resolved or waits (`src/console_heap_slot_records.h`, written | 2182 | the device address its copy names, and whether it resolved or waits (`src/console_heap_slot_records.h`, written |
| 2143 | only by `fix_console_slot`). Two indexes find the halves near a range, by base and by target, per power-of-two | 2183 | only by `fix_console_slot`). Two indexes, by base and by target, hold the halves by their exact range: halves |
| 2144 | span class and 64 KiB-or-larger granule. Releases (a backing, a title-window or geometry block), alias ranges | 2184 | naming the same range share one group (with a resolved and a waiting list, each half's place in it kept, so a |
| 2185 | half moves or goes in O(1)), and the groups are ordered by start per power-of-two class of their length. A change | ||
| 2186 | visits exactly the halves whose range overlaps it; an addition visits the waiting halves whose range starts inside | ||
| 2187 | it, since a V# resolves only through a backing, alias range, copy or title memory that holds its base (title memory | ||
| 2188 | is told as the merged range that holds it); each half once per index in a submission, however many changes name | ||
| 2189 | it. The groups compared to find them are those plus, for a removal, per class, the ones that start less than one | ||
| 2190 | class length before it and end before it. | ||
| 2191 | Releases (a backing, a title-window or geometry block), alias ranges | ||
| 2145 | removed or replaced (`TitleVaAliases` tells its listeners as it happens, `forget_copy` included) and additions | 2192 | removed or replaced (`TitleVaAliases` tells its listeners as it happens, `forget_copy` included) and additions |
| 2146 | (a backing, an alias range, title memory) go on an unbounded per-device list; at the next submission each heap | 2193 | (a backing, an alias range, title memory) go on an unbounded per-device list; at the next submission each heap |
| 2147 | fixes again exactly the slots whose records a change touches: a release or removal every half naming it, an | 2194 | fixes again exactly the slots whose records a change touches: a release or removal every half naming it, an |
| 2148 | addition the waiting halves over it. Nothing walks the heap or reads the copy for this. A zeroed range, a slot | 2195 | addition the waiting halves whose base it holds. Nothing walks the heap or reads the copy for this. A zeroed range, a slot |
| 2149 | the title rewrote and a heap destroyed drop their records. `console_heap_slot_records_test` checks that a release | 2196 | the title rewrote and a heap destroyed drop their records. `console_heap_slot_records_test` checks that a release |
| 2150 | of a buffer 10 of 60,010 slots name looks at those 10, and compares the copy with a full re-resolution through | 2197 | of a buffer 10 of 60,010 slots name looks at those 10, that a 40-byte release among 300,000 slots packed into 74 |
| 2151 | random writes, releases, additions and alias changes. | 2198 | blocks of 64 KiB looks at the 3 it overlaps, and compares the copy with a full re-resolution through random |
| 2199 | writes, releases, additions and alias changes. | ||
| 2200 | A title-written T# has a record too, under the exact base address it names (`bind_title_image` looks textures up | ||
| 2201 | by that address, or by the other view of texture-pool memory): bound, or waiting for a texture there (no texture, | ||
| 2202 | or one whose type, samples, mips, layers, image or views do not fit the T#), or waiting for room in its bindless | ||
| 2203 | array. A texture registered, replaced or published at an address (`note_image_address`, a title texture's | ||
| 2204 | placement, a streamed texture's image), or gone from it (`forget_image`, a placement removed), goes on the same | ||
| 2205 | list, and the next submission fixes again exactly the T#s naming that address; freed bindless entries fix the | ||
| 2206 | T#s waiting for room. Nothing looks at a waiting T# otherwise: before, a round robin tried the waiting slots again | ||
| 2207 | for 500 µs a submission (`LEONIDA_CONSOLE_RETRY_US`), which in world runs took tens of submissions to come round | ||
| 2208 | and counted every look as a T# "naming no texture" again. A texture that goes takes its T#s out of the descriptor | ||
| 2209 | hash table at once (`forget_image_views_locked`), so a shader reading the slot gets the fallback; the slot then | ||
| 2210 | waits for the next texture at the address, which a texture streamed out and back in needs. A V# half whose | ||
| 2211 | geometry copy was refused for lack of room waits for room the same way: the slots are fixed again when geometry | ||
| 2212 | copies are freed (`GeometryViews::free_generation`), not only when something is added over their base. | ||
| 2213 | A T# with no texture at its address is counted by what the address is (`unbound T#s by reason` in the heap's log | ||
| 2214 | line): title memory, a texture of the layer's own that is gone, an address whose low 32 bits are one of the | ||
| 2215 | layer's texture addresses with other high bits (the texture there with the T#'s shape, with another, or gone), | ||
| 2216 | or none of these. The heap's `slot records` line gives the T#s recorded, those waiting, the T# fixes that left | ||
| 2217 | one waiting and the refills since the last line. `d3d12_tsharp_refill_test` samples, through the last of 60,001 | ||
| 2218 | waiting slots, a texture made after the T# was written, at the first submission after it appears. T#s are a third | ||
| 2219 | index of the same kind, keyed by their address: a texture change visits exactly the T#s recorded for that address, | ||
| 2220 | and the records waiting for room are kept in a list per kind, which a change saying room was made visits whole. | ||
| 2221 | The title rebuilds T#s of the layer's textures from 32 bits: the unbound T#s of one world run named 0x7f0000021400 | ||
| 2222 | for the layer's 0x100021400, and 0x2ef600 for 0x1002ef600 (bits 32-39 clear, 0x7f or 0 in bits 40-47). Such an | ||
| 2223 | address outside the title's memory names the layer's texture with the same low 32 bits (`tsharp_texture_key`, | ||
| 2224 | while fewer than 2^24 texture addresses were handed out): `bind_title_image` looks it up there, and the T# waits | ||
| 2225 | under that address, where the texture's creation is announced. Before, such T#s waited under the title's form, | ||
| 2226 | which no arrival names, and the run showed no refill at all; `d3d12_tsharp_refill_test` writes both forms before | ||
| 2227 | the texture exists and expects them bound at the first submission after it appears. | ||
| 2228 | A V# the title rewrote whose range another half of the heap waits for is answered as that half was | ||
| 2229 | (`ConsoleHeapSlotRecords::waiting_answer`), without walking the alias table, backings, geometry copies and title | ||
| 2230 | memory again: a waiting record is fixed again by every change that could let it resolve, so while it waits its | ||
| 2231 | answer stands. The changes noted since the submission's list was taken are applied to the heap first | ||
| 2232 | (`sync_slot_changes`), and the submission's own changes before the rewritten slots, so an answer is never older | ||
| 2233 | than a change that concerns it. In one world run 70% of the 2,100 rewritten V# halves a submission resolved to | ||
| 2234 | nothing at about 9 µs each. | ||
| 2235 | **A console resource heap read in place.** When the page mirror holds every page of the heap (a reservation xmem | ||
| 2236 | placed in the mirror's range), there is no copy of the whole heap and no page tracker of its own. Its pages have | ||
| 2237 | two homes. At the title's address (the mirror) the home is the title's bytes exactly, as for any page: the title | ||
| 2238 | keeps plain data inline in its heap pages and points V#s at it (run 64w3: four words a compute program reads as | ||
| 2239 | its sizes, `[512 256 1280 720]`), so a V# or a title pointer into those pages must read what the title wrote, and | ||
| 2240 | GPU stores there are written back as for any page. At the table address, below 4 GiB of the arena (25,865 of | ||
| 2241 | 26,503 shaders keep 32 bits of a descriptor-table pointer), each page has a filtered copy of its own | ||
| 2242 | (`TitleMirror::alias`: a second home per page, bound there in the same batches as the mirror's binds, so the one | ||
| 2243 | wait orders a reader of either address), in a range of whole arena blocks with no arena memory behind it; the null | ||
| 2244 | slots after the heap are that range's rest, unbound, which reads zero. The filter writes only that copy | ||
| 2245 | (`filter_heap_page`), refilled when a 256-byte piece of the title's page changed (the upload's sums compare the | ||
| 2246 | title's bytes with the title's) or write-back changed it. Each slot that changed since it was last filtered, or | ||
| 2247 | that a change of the address space touched, is filtered: a V# half whose base lies in the arena, in the mirror | ||
| 2248 | (named to it as any reader names title memory) or in a buffer of ours is kept as the title wrote it | ||
| 2249 | (`reachable_as_written`); a half nothing holds is null whole, all four words (a shader reading it as a V# would | ||
| 2250 | fault at heap_base + its base: the "resolved to nothing" classes of the heap's log line), never three of four; a | ||
| 2251 | T# is kept as written and bound; words that decode as neither are null, as a shader taking them as a V# would | ||
| 2252 | fault. The filter runs inside the mirror's fills, under its lock, so it takes no other lock of ours: a V# the mirror | ||
| 2253 | does not hold reads null until the heap's refresh resolves it as a copied slot was, and a T# is bound there too, | ||
| 2254 | its dword 6 in the copy then taking the bindless index word (`tsharp_index_word`, docs/design.md "Bindless index in | ||
| 2255 | the T#"; 0, the fallback, from the filter until then and while the T# waits; the title's dword 6 stays in its | ||
| 2256 | bytes), each result written into the copy unless the title rewrote the slot meanwhile (`finish_in_place`). Lock | ||
| 2257 | order: `console_heap_mutex`, then the mirror's, then the change list's. Table pointers reach shaders in user SGPRs, | ||
| 2258 | which the layer sets to the table address (`console_descriptor_table_va`) for every module; a table pointer a | ||
| 2259 | shader loads from memory is the title's address and reads the title's bytes there: V#s as written (the mirror | ||
| 2260 | holds what they name, or the read faults as on any unfiltered memory) and T#s without the index word, which a | ||
| 2261 | module of the index-word contract reads as the fallback. A heap the mirror does not hold (a device without the | ||
| 2262 | mirror, memory outside its range) is copied as before. `d3d12_heap_in_place_test` checks that the GPU reads the | ||
| 2263 | filtered slots at the table address while the title's bytes never change, that a rewrite reaches the GPU at the | ||
| 2264 | next refresh, that inline data reads exactly through a V# while the table reads it filtered, that a GPU store into | ||
| 2265 | the heap goes back, and that the null slots read zero; `title_mirror_hooks_test` checks the alias without a GPU | ||
| 2266 | and `vk_heap_alias_test` a second binding on a device. | ||
| 2152 | Console resource heap copies and shader-visible CBV/SRV/UAV heaps with at least 65,536 slots request | 2267 | Console resource heap copies and shader-visible CBV/SRV/UAV heaps with at least 65,536 slots request |
| 2153 | 64 MiB of zeroed padding after their last descriptor. `LEONIDA_HEAP_GUARD_MB` sets the padding in MiB | 2268 | 64 MiB of zeroed padding after their last descriptor. `LEONIDA_HEAP_GUARD_MB` sets the padding in MiB |
| 2154 | (0 disables it). When arena space is tight, allocation can fall back to the heap alone. Only indices | 2269 | (0 disables it). When arena space is tight, allocation can fall back to the heap alone. Only indices |
| @@ -2174,7 +2289,9 @@ The layer's descriptor model: | |||
| 2174 | which is the assumption to verify. If it uses an opaque format, the layer must translate at bind time. | 2289 | which is the assumption to verify. If it uses an opaque format, the layer must translate at bind time. |
| 2175 | - At execution, for each bound table (or the whole bound heap when direct indexing is enabled), the layer walks | 2290 | - At execution, for each bound table (or the whole bound heap when direct indexing is enabled), the layer walks |
| 2176 | the declared descriptor range with the heap's stride, parses each T#/S#, and ensures a bindless entry exists: | 2291 | the declared descriptor range with the heap's stride, parses each T#/S#, and ensures a bindless entry exists: |
| 2177 | - image T# → `VkImageView` (format, view type, mip range, array layers) → bindless image index; | 2292 | - image T# → `VkImageView` (format, view type, mip range, array layers) → bindless image index, which the layer |
| 2293 | writes into dword 6 of the T# where shaders read it (the console heap copy's slot, or the layer's own heap), with | ||
| 2294 | the arrays it is bound in (`docs/design.md`, "Bindless index in the T#"); the hash table keeps the key as written; | ||
| 2178 | - sampler S# → `VkSampler` (filter, address modes, LOD, compare, anisotropy) → bindless sampler index; | 2295 | - sampler S# → `VkSampler` (filter, address modes, LOD, compare, anisotropy) → bindless sampler index; |
| 2179 | - buffer V# / CBV → no Vulkan view; the descriptor already contains a console VA the shader dereferences. | 2296 | - buffer V# / CBV → no Vulkan view; the descriptor already contains a console VA the shader dereferences. |
| 2180 | - **Buffer UAVs.** `CreateUnorderedAccessView` on a buffer writes a V# in the first 16 bytes of the slot (the rest of | 2297 | - **Buffer UAVs.** `CreateUnorderedAccessView` on a buffer writes a V# in the first 16 bytes of the slot (the rest of |
| @@ -2213,10 +2330,34 @@ The layer's descriptor model: | |||
| 2213 | the bound heap, and cache parsed descriptors by key so unchanged slots cost nothing. **Open:** whether the game | 2330 | the bound heap, and cache parsed descriptors by key so unchanged slots cost nothing. **Open:** whether the game |
| 2214 | uses unbounded tables; the trace will show the root-signature ranges. | 2331 | uses unbounded tables; the trace will show the root-signature ranges. |
| 2215 | - The heap stride is the value the layer returns from `GetDescriptorHandleIncrementSize`. Prior art forwards device | 2332 | - The heap stride is the value the layer returns from `GetDescriptorHandleIncrementSize`. Prior art forwards device |
| 2216 | slot 15 (`GetDescriptorHandleIncrementSize`) unchanged, but the actual increment values are still **Open**. Choose | 2333 | slot 15 (`GetDescriptorHandleIncrementSize`) unchanged. **Measured** in the executable: every one of the 943 |
| 2217 | 32 bytes for CBV/SRV/UAV (the T# size) and 32 bytes for samplers (16 bytes of S# plus padding) pending the console | 2334 | indirect calls through `[device vtable + 0x78]` was resolved by tracing `rcx` from its function's start; ten reach |
| 2218 | value. The game may hardcode the console increments or infer them from shader address arithmetic; the shader's | 2335 | the device itself: `rcx` is loaded rip-relative from the BSS device global `0x148759D00` or from one of its aliases |
| 2219 | shift amount gives the stride it expects, and the layer must match it. | 2336 | `0x1475DF000`-`0x1475DF048`, the same global the measured device calls in section 7.1 use (the load is |
| 2337 | `mov rcx, qword ptr [rip + displacement]`, so the literal address does not appear in the instruction). | ||
| 2338 | The other 933 call the same slot on another object (queue, factory, wrapper) and are counted but not attributed. | ||
| 2339 | |||
| 2340 | | site | descriptor heap type (`edx`) | what the return does | | ||
| 2341 | | --- | --- | --- | | ||
| 2342 | | `0x141C7456B` | 0 (`CBV_SRV_UAV`) | `add rdi, rax` in the slot loop: the increment advances the GPU handle stored in each entry | | ||
| 2343 | | `0x141F75FDD` | 0 (`CBV_SRV_UAV`) | the same handle-stride loop | | ||
| 2344 | | `0x142478E42` | 0 (`CBV_SRV_UAV`) | stored for later: `mov dword ptr [rip + 0x516E1AE], eax` | | ||
| 2345 | | `0x142478E5F` | 1 (`SAMPLER`) | discarded | | ||
| 2346 | | `0x142478E71` | 2 (`RTV`) | discarded | | ||
| 2347 | | `0x142478E83` | 3 (`DSV`) | discarded | | ||
| 2348 | | `0x142478E9A` | 4 (`NUM_DESCRIPTOR_HEAP_TYPES`) | discarded | | ||
| 2349 | | `0x145C5FF2F` | 0 (`CBV_SRV_UAV`) | `imul rsi, rax` and `imul rdi, rax`: two buffer sizes, each then rounded up to 64 KiB | | ||
| 2350 | | `0x145CABB18` | 0 (`CBV_SRV_UAV`) | `mov ecx, eax; div rcx`: slot count from a byte count, handed to the heap-size path (`0x141CF3280`) that multiplies it back | | ||
| 2351 | | `0x141CF32BE` | `edx` argument of its wrapper | `imul rdi, r12`: size = count x increment; the callers pass type 0 (`0x145CABB00`) or forward their own argument `0x145A54700`, itself called with types 1, 2 and 3 | | ||
| 2352 | |||
| 2353 | So the game queries the increment and derives sizes, divisions and handles from the answer: it does not hardcode a | ||
| 2354 | stride, and it is the getter, not the shader's shift, that decides it here. The layer must therefore return the | ||
| 2355 | host heap's own increment per type, never a console constant, or every size and handle walk above is wrong. In the | ||
| 2356 | two table builders the CPU-side record stride is `0x40` while the handle advances by the returned value, so the | ||
| 2357 | increment is a slot stride and a record can be wider than one slot. The bootstrap queried all five enum values but | ||
| 2358 | cached only type 0; types 1-4 reach the getter only through `0x141CF3280`. **Open:** the numeric console values | ||
| 2359 | themselves, and the console slot sizes behind them (32 bytes for CBV/SRV/UAV and for samplers stays this layer's | ||
| 2360 | choice); the shader's shift amount still has to match whatever stride the layer hands out. | ||
| 2220 | - `CopyDescriptors` copies raw bytes. If the descriptor was produced by our `Create*View`, the copy is a valid | 2361 | - `CopyDescriptors` copies raw bytes. If the descriptor was produced by our `Create*View`, the copy is a valid |
| 2221 | T#/S#; if it came from game memory, it is still valid raw data. No re-encoding is needed. | 2362 | T#/S#; if it came from game memory, it is still valid raw data. No re-encoding is needed. |
| 2222 | - Handle validation: a GPU descriptor handle is an arena VA; the heap registry maps the containing range to a | 2363 | - Handle validation: a GPU descriptor handle is an arena VA; the heap registry maps the containing range to a |
| @@ -3264,13 +3405,13 @@ The console has two list topologies Vulkan lacks: rectangle list (`IASetPrimitiv | |||
| 3264 | 3405 | ||
| 3265 | | D3D12 / Xbox object | Vulkan / layer object | Notes | | 3406 | | D3D12 / Xbox object | Vulkan / layer object | Notes | |
| 3266 | |---|---|---| | 3407 | |---|---|---| |
| 3267 | | `ID3D12Device` … `ID3D12Device11` | one `Device` object with the public chain plus measured Xbox overrides | The shipped BVH builder names Device11; slots 1/15/18/19/27/38 matched desktop in prior art, slot 48 is called as `(desc, riid, out)` with `IID_ID3D12CommandQueue` (PC slot 48 is `OpenExistingHeapFromAddress`; the 32-byte desc is a PC `D3D12_COMMAND_QUEUE_DESC` plus four Xbox words, logged once, and the proxy takes the slot 8 path with the PC prefix and only `DISABLE_GPU_TIMEOUT` kept), slot 62 is called as `CreateComputePipelineState`, slot 76 is Xbox texture creation, and heap slots 9/10 return in RAX. Unknown Xbox IIDs/slots are logged and refused. | | 3408 | | `ID3D12Device` … `ID3D12Device11` | one `Device` object with the public chain plus measured Xbox overrides | The shipped BVH builder names Device11; slots 1/15/18/19/27/38 matched desktop in prior art, slot 48 is called as `(desc, riid, out)` with `IID_ID3D12CommandQueue` (PC slot 48 is `OpenExistingHeapFromAddress`; the 32-byte desc is a PC `D3D12_COMMAND_QUEUE_DESC` plus four Xbox words, logged once, and the proxy takes the slot 8 path with the PC prefix and only `DISABLE_GPU_TIMEOUT` kept), slot 62 is called at `0x14247FE66` as a create with `(desc, 0, 0, &riid, &out)` — five parameters with an explicit IID/out pair, where the PC method it forwards to, `CreateComputePipelineState`, takes three — and static Capstone disassembly over the executable's `.text` (following the device globals `0x148759D00` and `0x1475DF000`–`0x1475DF048` from renderer init `0x142478440`) finds no device call site for slot 76 (`+0x260`; none of the 57 indirect `call [reg+0x260]` sites in `.text` loads a device global); its only measured caller is the shipped FidelityFX upscaler, with the seven `CreateCommittedResource` arguments ([d3d12_command_objects.md](d3d12_command_objects.md) §3.5a), and heap slots 9/10 return in RAX. Unknown Xbox IIDs/slots are logged and refused. | |
| 3268 | | `ID3D12CommandQueue` | one leased `VkQueue` per live queue: direct queues on the graphics family, compute queues on an async-compute family and copy queues on a transfer-only (DMA) family when the GPU has them (`src/queue_families.h`), else graphics-family leases | Distinct Vulkan queues allow cross-queue waits and signals to make progress. With more than one family in use, buffers, images, the arena and staging are created `VK_SHARING_MODE_CONCURRENT` over those families, so no ownership transfers are needed. Barriers on copy and compute queues are narrowed to the stages their family has; render-target and depth clears are refused there (as in D3D12), and the D24/RGB96 copy conversions and bindless flushes stay off a transfer-only queue. Tested by `vk_queue_test`. `PresentX`, `SuspendX`, `ResumeX` are Xbox queue methods, not in the public vtable; public GDKX samples present only through them (§4.5). Call shapes known, slots **Open**. | | 3409 | | `ID3D12CommandQueue` | one leased `VkQueue` per live queue: direct queues on the graphics family, compute queues on an async-compute family and copy queues on a transfer-only (DMA) family when the GPU has them (`src/queue_families.h`), else graphics-family leases | Distinct Vulkan queues allow cross-queue waits and signals to make progress. With more than one family in use, buffers, images, the arena and staging are created `VK_SHARING_MODE_CONCURRENT` over those families, so no ownership transfers are needed. Barriers on copy and compute queues are narrowed to the stages their family has; render-target and depth clears are refused there (as in D3D12), and the D24/RGB96 copy conversions and bindless flushes stay off a transfer-only queue. Tested by `vk_queue_test`. `PresentX`, `SuspendX`, `ResumeX` are Xbox queue methods, not in the public vtable; public GDKX samples present only through them (§4.5). Call shapes known, slots **Open**. | |
| 3269 | | `ID3D12CommandAllocator` | IR arena + `VkCommandPool` | Reset only when the previous submission's fence is complete. | | 3410 | | `ID3D12CommandAllocator` | IR arena + `VkCommandPool` | Reset only when the previous submission's fence is complete. | |
| 3270 | | `ID3D12GraphicsCommandList` … `8` | `CommandList` with IR | Replay at `ExecuteCommandLists`; bundles inlined. Supports render passes, mesh dispatch, enhanced barriers; records the GCL8 front/back stencil references (applied only once a pipeline path consumes them). `Draw` views are inlined and moved into the command stream (D3D-289), eliminating per-draw heap allocations. | | 3411 | | `ID3D12GraphicsCommandList` … `8` | `CommandList` with IR | Replay at `ExecuteCommandLists`; bundles inlined. Supports render passes, mesh dispatch, enhanced barriers; records the GCL8 front/back stencil references (applied only once a pipeline path consumes them). `Draw` views are inlined and moved into the command stream (D3D-289), eliminating per-draw heap allocations. | |
| 3271 | | `ID3D12RootSignature` | `RootSignature` + `VkPipelineLayout` | Deserialize the blob with the host `D3D12CreateVersionedRootSignatureDeserializer` when possible; clear the measured `0x03000000` flag byte on a copy first; fall back to a local parser. Build the user-SGPR map and static samplers. | | 3412 | | `ID3D12RootSignature` | `RootSignature` + `VkPipelineLayout` | Deserialize the blob with the host `D3D12CreateVersionedRootSignatureDeserializer` when possible; clear the measured `0x03000000` flag byte on a copy first; fall back to a local parser. Build the user-SGPR map and static samplers. | |
| 3272 | | `ID3D12PipelineState` | `VkPipeline` + a `PipelineInfo` | Shader hash → SPIR-V + index entry; PSO state → Vulkan state; dynamic state where possible. The BVH builder's compute PSOs arrive at device slot 62 with a plain `D3D12_COMPUTE_PIPELINE_STATE_DESC`. | | 3413 | | `ID3D12PipelineState` | `VkPipeline` + a `PipelineInfo` | Shader hash → SPIR-V + index entry; PSO state → Vulkan state; dynamic state where possible. The BVH builder's compute PSOs arrive at device slot 62 with a plain `D3D12_COMPUTE_PIPELINE_STATE_DESC`. | |
| 3273 | | `ID3D12DescriptorHeap` | `DescriptorHeap` (shadow + optional arena range) | CBV/SRV/UAV and sampler heaps can be shader-visible; RTV/DSV are host-only. Start handles use the measured RAX return at heap slots 9/10. Increments are layer-chosen (32/32) pending the console value. | | 3414 | | `ID3D12DescriptorHeap` | `DescriptorHeap` (shadow + optional arena range) | CBV/SRV/UAV and sampler heaps can be shader-visible; RTV/DSV are host-only. Start handles use the measured RAX return at heap slots 9/10. The game derives heap sizes and handle strides from `GetDescriptorHandleIncrementSize` (measured call sites, section 3.4), so the layer returns its own slot size (32/32) rather than a console value. | |
| 3274 | | `ID3D12Resource` | `Resource` (a range in the arena buffer; a separate `VkImage` for textures) | Committed, placed and reserved. Reserved buffers use sparse memory where supported (section 4.2). Xbox textures may arrive through device slot 76. `GetGPUVirtualAddress` returns a console VA (a buffer offset or an image key). | | 3415 | | `ID3D12Resource` | `Resource` (a range in the arena buffer; a separate `VkImage` for textures) | Committed, placed and reserved. Reserved buffers use sparse memory where supported (section 4.2). Xbox textures may arrive through device slot 76. `GetGPUVirtualAddress` returns a console VA (a buffer offset or an image key). | |
| 3275 | | `ID3D12Heap` | `Heap` (a reserved VA range) | Buffer ranges are backed by the arena; images get ranges of shared blocks or their own `VkDeviceMemory` (section 3.3). Residency calls are no-ops. True buffer/image aliasing inside a heap is **Open**. | | 3416 | | `ID3D12Heap` | `Heap` (a reserved VA range) | Buffer ranges are backed by the arena; images get ranges of shared blocks or their own `VkDeviceMemory` (section 3.3). Residency calls are no-ops. True buffer/image aliasing inside a heap is **Open**. | |
| 3276 | | `ID3D12Fence` / `ID3D12Fence1` | `Fence` over a timeline `VkSemaphore` | `GetCompletedValue` = counter value; `SetEventOnCompletion` = wait thread + Win32 event; CPU `Signal` = host signal. | | 3417 | | `ID3D12Fence` / `ID3D12Fence1` | `Fence` over a timeline `VkSemaphore` | `GetCompletedValue` = counter value; `SetEventOnCompletion` = wait thread + Win32 event; CPU `Signal` = host signal. | |
| @@ -3636,7 +3777,10 @@ The console has two list topologies Vulkan lacks: rectangle list (`IASetPrimitiv | |||
| 3636 | the mips from there on are filled and only the descriptor keys of views that start there or later are published. | 3777 | the mips from there on are filled and only the descriptor keys of views that start there or later are published. |
| 3637 | The others stay on the fallback (`PendingImage::first_mip`) until a later fill has their mips. The image still has | 3778 | The others stay on the fallback (`PendingImage::first_mip`) until a later fill has their mips. The image still has |
| 3638 | memory for every mip: `LEONIDA_TITLE_PARTIAL_MIPS_MB` (2048) limits the image memory of the textures filled in | 3779 | memory for every mip: `LEONIDA_TITLE_PARTIAL_MIPS_MB` (2048) limits the image memory of the textures filled in |
| 3639 | part. Arrays, cubes and volumes are filled whole or not at all. | 3780 | part. Arrays, cubes and volumes are filled whole or not at all. `LEONIDA_TITLE_STREAM_BUDGET_MB` (16 by default, `0` |
| 3781 | for unlimited) bounds newly streamed unmapped texture uploads and partial-mip upgrades per `refresh_title_textures` | ||
| 3782 | pass (deferring excess textures via `watch.touch` to the next submission while never deferring mapped video planes, | ||
| 3783 | already-filled dynamic updates, or the first streamed texture of a pass). | ||
| 3640 | - Small optimal Vulkan images synthesized for slot-70 texture views share memory pages. Each slice meets the | 3784 | - Small optimal Vulkan images synthesized for slot-70 texture views share memory pages. Each slice meets the |
| 3641 | image's size, alignment and memory type requirements. The GPU retirement queue destroys the image before its | 3785 | image's size, alignment and memory type requirements. The GPU retirement queue destroys the image before its |
| 3642 | slice can be reused. Large images, dedicated-only images, and failed pool allocations use individual memory | 3786 | slice can be reused. Large images, dedicated-only images, and failed pool allocations use individual memory |
| @@ -3652,11 +3796,15 @@ The console has two list topologies Vulkan lacks: rectangle list (`IASetPrimitiv | |||
| 3652 | - Sampled title images can use device-local memory even when Vulkan host image copies require a | 3796 | - Sampled title images can use device-local memory even when Vulkan host image copies require a |
| 3653 | host-visible memory type. The runtime queries the same image with and without host-transfer usage. | 3797 | host-visible memory type. The runtime queries the same image with and without host-transfer usage. |
| 3654 | When only the latter permits plain device-local backing, it detiles the complete image into a reusable | 3798 | When only the latter permits plain device-local backing, it detiles the complete image into a reusable |
| 3655 | staging buffer and transfers all its mips and layers together. Linear slot-133 placements retain host | 3799 | staging buffer and transfers all its mips and layers together. Linear slot-133 placements use host |
| 3656 | copies. On a device without `VK_EXT_host_image_copy` every colour title image, linear placements too, takes the | 3800 | copies when the image supports them. |
| 3657 | staged upload: the refresh before a submission has no other way to fill one, and without it the title's textures | 3801 | A CPU-visible, single-sampled colour title image that needs no format conversion uses the staged upload |
| 3658 | stayed zero (a flat green intro movie). An allocation failure retries the original host-copyable image. | 3802 | if the device, format or image usage lacks host-transfer support, or if the host-transfer image has no |
| 3659 | `LEONIDA_TITLE_IMAGE_STAGING=0` | 3803 | compatible memory type. The runtime logs that last case once per Vulkan format. A GTX 1050 Ti on |
| 3804 | NVIDIA 582.66 reported it for R8_UNORM, R8G8B8A8_UNORM and BC1_RGBA_UNORM_BLOCK. | ||
| 3805 | [GTX 1050 Ti test results](https://github.com/ubiquitarianism/leonida/pull/1894#issuecomment-7174515492) | ||
| 3806 | When both placements are available, an allocation failure on the staged path retries the original | ||
| 3807 | host-copyable image. `LEONIDA_TITLE_IMAGE_STAGING=0` | ||
| 3660 | restores the original placement policy. With `LEONIDA_MEM_PROBE`, each title image class logs its | 3808 | restores the original placement policy. With `LEONIDA_MEM_PROBE`, each title image class logs its |
| 3661 | Vulkan memory type mask, mask without host transfer, and selected type. | 3809 | Vulkan memory type mask, mask without host transfer, and selected type. |
| 3662 | - `WriteToSubresource`/`ReadFromSubresource` (implemented in `d3d12_vulkan_device.cpp`) complete before they | 3810 | - `WriteToSubresource`/`ReadFromSubresource` (implemented in `d3d12_vulkan_device.cpp`) complete before they |
| @@ -3678,7 +3826,8 @@ The console has two list topologies Vulkan lacks: rectangle list (`IASetPrimitiv | |||
| 3678 | the host refuses and the layer copies on purpose. | 3826 | the host refuses and the layer copies on purpose. |
| 3679 | - A driver can report `VK_FORMAT_FEATURE_2_HOST_IMAGE_TRANSFER_BIT_EXT` for a format, create the image with | 3827 | - A driver can report `VK_FORMAT_FEATURE_2_HOST_IMAGE_TRANSFER_BIT_EXT` for a format, create the image with |
| 3680 | host-transfer usage, and then give it no memory type (`memoryTypeBits = 0`). This was measured on a GTX 1050 Ti | 3828 | host-transfer usage, and then give it no memory type (`memoryTypeBits = 0`). This was measured on a GTX 1050 Ti |
| 3681 | with NVIDIA 582.78, and the validation layer of Vulkan SDK 1.4.363 reports nothing. Such a texture is made again | 3829 | with NVIDIA 582.78 and again with 582.66 on Windows 10 (#1364), where the same image without host-transfer usage |
| 3830 | takes device-local memory; the validation layer of Vulkan SDK 1.4.363 reports nothing. Such a texture is made again | ||
| 3682 | without host-transfer usage before it is bound, and takes the staging path. `d3d12_vulkan_device_test` and | 3831 | without host-transfer usage before it is bound, and takes the staging path. `d3d12_vulkan_device_test` and |
| 3683 | `d3d12_subresource_copy_test` force this branch on any GPU with `VulkanDeviceInfo::force_host_transfer_retry` | 3832 | `d3d12_subresource_copy_test` force this branch on any GPU with `VulkanDeviceInfo::force_host_transfer_retry` |
| 3684 | (their third CPU-copy path; the second compares it with the host runtime). | 3833 | (their third CPU-copy path; the second compares it with the host runtime). |
| @@ -3879,13 +4028,52 @@ The console has two list topologies Vulkan lacks: rectangle list (`IASetPrimitiv | |||
| 3879 | and 2^32 in alpha match WARP). `d3d12_clear_test` compares full and rectangular D3D12 readbacks with WARP across | 4028 | and 2^32 in alpha match WARP). `d3d12_clear_test` compares full and rectangular D3D12 readbacks with WARP across |
| 3880 | UNORM, SNORM, FLOAT, all 15 exposed UINT/SINT render targets (11 value vectors, including 8-/16-/10-/2-bit range | 4029 | UNORM, SNORM, FLOAT, all 15 exposed UINT/SINT render targets (11 value vectors, including 8-/16-/10-/2-bit range |
| 3881 | boundaries) and depth/stencil; `clear_color_test` checks both replay paths for 19 integer formats without a GPU, | 4030 | boundaries) and depth/stencil; `clear_color_test` checks both replay paths for 19 integer formats without a GPU, |
| 3882 | including unchanged float values. SRGB clears are omitted from the comparison: the | 4031 | including unchanged float values. SRGB clears are omitted from that comparison; `d3d12_clear_formats_test` |
| 3883 | linear→sRGB encoding rounds differently at the `.5` boundary on WARP vs Vulkan (a 1-ulp driver difference). | 4032 | compares them (next item). |
| 3884 | **Open:** on NVIDIA RTX 5080 (driver 616.56) clears that land exactly on a `.5` UNORM/SNORM step round down where | 4033 | **Open:** on NVIDIA RTX 5080 (driver 616.56) clears that land exactly on a `.5` UNORM/SNORM step round down where |
| 3885 | WARP rounds up: `R8G8B8A8_UNORM`/`SNORM` 0.5 store `7f`/`3f` vs WARP `80`/`40`, and a `D16_UNORM` 0.5 depth clear | 4034 | WARP rounds up: `R8G8B8A8_UNORM`/`SNORM` 0.5 store `7f`/`3f` vs WARP `80`/`40`, and a `D16_UNORM` 0.5 depth clear |
| 3886 | stores `0x7fff` vs WARP `0x8000` (all on `main` before this change; same 1-ulp class as SRGB, not addressed here). | 4035 | stores `0x7fff` vs WARP `0x8000` (all on `main` before this change; same 1-ulp class as SRGB, not addressed here). |
| 3887 | `D32_FLOAT` and `D32_FLOAT_S8X24_UINT` match WARP. | 4036 | `D32_FLOAT` and `D32_FLOAT_S8X24_UINT` match WARP. |
| 3888 | This does not add typed-view reinterpretation of typeless resources. | 4037 | This does not add typed-view reinterpretation of typeless resources. |
| 4038 | - **sRGB RTV clears (D3D-CLEAR-SRGB-ENCODE):** `ClearRenderTargetView` through an `R8G8B8A8_UNORM_SRGB` or | ||
| 4039 | `B8G8R8A8_UNORM_SRGB` view encodes the colour channels in the layer and hands Vulkan the linear value of the | ||
| 4040 | resulting code (`srgb8_from_linear` and `srgb8_linear` in `vulkan_replay.h`); alpha is linear and rounds like | ||
| 4041 | UNORM. Before, the linear float went to `vkCmdClearColorImage` or `vkCmdClearAttachments` as it was and the GPU | ||
| 4042 | encoded it, so the stored byte depended on the GPU: 0.5 was `bb` on an Intel Iris Xe and `bc` on WARP and an | ||
| 4043 | NVIDIA RTX 4060. **Measured** (Windows 11 build 26100, WARP 10.0.26100.5074, Iris Xe with Intel 32.0.101.7092, RTX | ||
| 4044 | 4060 Laptop with NVIDIA 616.92; a scratch program cleared 256-slice sRGB targets through the layer and through | ||
| 4045 | WARP, a whole view and a rectangle each, and bisected over float bit patterns): | ||
| 4046 | - No driver is wrong. D3D permits FLOAT → SRGB a tolerance of 0.6 of a step (Direct3D 11.3 functional | ||
| 4047 | specification, 3.2.3.8), and each implementation puts the 255 steps between two codes somewhere else: measured | ||
| 4048 | against the halfway point of the ideal curve, the Iris Xe's sit between 0.18 of a code below and 0.33 above, the | ||
| 4049 | RTX 4060's within 0.10 and WARP's between 0.29 below and 0.34 above. On each GPU both Vulkan commands have the | ||
| 4050 | same 255 steps. Of 60 000 random values (half uniform in 0..1, half log-uniform from 1e-6) the Iris Xe stored | ||
| 4051 | another byte than WARP for 6 649 and the RTX 4060 for 3 648, never more than one code away. | ||
| 4052 | - WARP takes the value to 12 bits first and encodes that: `j = floor(x * 4095 + 0.5)` with the product rounded to | ||
| 4053 | single precision, then the nearest code of the IEC 61966-2-1 curve at `j / 4095`. The 255 floats at which WARP's | ||
| 4054 | byte changes are the 255 this rule gives (with the product in exact arithmetic only 188 are: `0x3f018018` times | ||
| 4055 | 4095 is 2071.4999986, which a float rounds to 2071.5), and WARP agrees with it on 84 582 further values: every | ||
| 4056 | 12-bit value, five floats around each of the 4 095 places between two of them, the 60 000 random ones, 0, 1, | ||
| 4057 | values outside 0..1, NaN and both infinities. It is not the nearest code of the ideal curve for 2 852 of the | ||
| 4058 | 60 000 (0.0004 is 2, the curve gives 1.32). | ||
| 4059 | - WARP and both GPUs store the linear value of a code as that code, for all 256 codes and with both commands. That | ||
| 4060 | value is the one farthest from any implementation's steps, so it is what the layer hands over; a GPU whose | ||
| 4061 | encoding is more than half a code off at one of these values would still differ. | ||
| 4062 | - Each GPU's own D3D12 driver stores what its Vulkan driver stores (the same byte for 84 582 of 84 582 values, on | ||
| 4063 | both GPUs): the encoding is the hardware's. So the layer used to store the bytes of the D3D12 driver of the GPU it | ||
| 4064 | ran on, and now stores WARP's on every GPU, which differ from the Intel driver's for those 6 649 of 60 000 values | ||
| 4065 | and from the NVIDIA driver's for 3 648. That is the choice made before for the ties of UNORM clears and for D24: | ||
| 4066 | the layer converts, WARP is the reference, and a host driver that does otherwise is a host quirk. | ||
| 4067 | |||
| 4068 | `clear_color_test` (no GPU) pins 38 values to the bytes WARP stored, checks that every code encodes to itself and | ||
| 4069 | that the result is the same under each floating-point rounding mode. `d3d12_clear_formats_test` clears both formats | ||
| 4070 | to the UNORM colours, the value of every code and the value halfway between every two codes (176 colours each, as | ||
| 4071 | a whole view and as a rectangle): against WARP, 178 of the 352 cases differed on the Iris Xe and 170 on the RTX | ||
| 4072 | 4060 before, none after (the five UNORM colours alone differed in 10 of 10 cases on the Iris Xe and in none on the | ||
| 4073 | RTX 4060). `d3d12_state_sweep_test` compares with the D3D12 driver of the same adapter and cleared its sRGB targets | ||
| 4074 | to 0.2, 0.4 and 0.6, of which the first two are codes 124 and 170 on WARP and 123 and 169 on the Iris Xe; it now | ||
| 4075 | clears them to the values of codes 124, 170 and 203, so its eight sRGB cases compare the blending whichever way | ||
| 4076 | the host encodes. A draw into an sRGB target is still encoded by the GPU. | ||
| 3889 | - **Depth clears.** Microsoft documents a `[0, 1]` clamp. On Windows 11 build 26100, both WARP and native D3D12 on | 4077 | - **Depth clears.** Microsoft documents a `[0, 1]` clamp. On Windows 11 build 26100, both WARP and native D3D12 on |
| 3890 | an RTX 5070 Ti (610.74) preserved finite out-of-range `D32_FLOAT` values and quiet NaN in full and rectangle | 4078 | an RTX 5070 Ti (610.74) preserved finite out-of-range `D32_FLOAT` values and quiet NaN in full and rectangle |
| 3891 | clears. Replay preserves those values when the Vulkan device has enabled `VK_EXT_depth_range_unrestricted`. | 4079 | clears. Replay preserves those values when the Vulkan device has enabled `VK_EXT_depth_range_unrestricted`. |
| @@ -3901,6 +4089,49 @@ The console has two list topologies Vulkan lacks: rectangle list (`IASetPrimitiv | |||
| 3901 | and the specular sparkles. Create them with the format the game asks for (`R8G8B8A8_UNORM` and the like) and don't | 4089 | and the specular sparkles. Create them with the format the game asks for (`R8G8B8A8_UNORM` and the like) and don't |
| 3902 | substitute a wider or float format for them. | 4090 | substitute a wider or float format for them. |
| 3903 | 4091 | ||
| 4092 | <a id="xg-swizzle-linear-path"></a> | ||
| 4093 | #### The title already supports the linear tile path (`XG-SWIZZLE-LINEAR-PATH`) | ||
| 4094 | |||
| 4095 | Read statically in 1.0.2.1; nothing was executed. Both `xg_xs.dll` imports are adjacent IAT thunks: | ||
| 4096 | `XGCreateTextureComputer` at `0x145F3FF40` (`JMP [0x146793F60]`) and `XGSuggestSwizzleMode` at | ||
| 4097 | `0x145F3FF50` (`JMP [0x146793F68]`). | ||
| 4098 | |||
| 4099 | `XGSuggestSwizzleMode` has one shape at both call sites, `0x140C4B3CE` (in `0x140C4B030`) and | ||
| 4100 | `0x144ECCCA2` (in `0x144ECC940`). The helper loads the description's tile-class byte `[desc+8]`, | ||
| 4101 | compares it with `0xFF` (`0x140C4B3B5`, `0x144ECCB00`/`0x144ECCB28`) and calls only on equality, so | ||
| 4102 | the class is unknown. The arguments are `RCX` = the description block being filled, `RDX` = 0 | ||
| 4103 | (`XOR EDX,EDX`) and `R8` = `RCX+0x2C` (`LEA R8,[RCX+0x2C]`), the block's 32-bit tile-mode field — | ||
| 4104 | i.e. `XGSuggestSwizzleMode(desc, NULL, &desc->tileMode)`. Both helpers zero the block at `+0x28` | ||
| 4105 | first, so that field is 0 unless a class is known; a known class writes `0x100 | class` (with | ||
| 4106 | `0x102` and `0x10A` as special cases) and never 0. The result the callee writes is therefore the | ||
| 4107 | mode, and 0 is already the value the title uses for "linear" everywhere. | ||
| 4108 | |||
| 4109 | The consumers test that mode word as tiled with `CMP x,0x100` plus `BT x,9` (bits 8 and 9) and | ||
| 4110 | run the linear arithmetic on the `0` result: | ||
| 4111 | |||
| 4112 | - `0x14555E9E0`, test at `0x14555EA2C`: 0 stores 0 at `[out+8]` and returns | ||
| 4113 | `pitch*(row+…) + x` at `0x14555EA45`. | ||
| 4114 | - `0x14193DE10`, test at `0x14193DE73`: 0 goes to `0x14193DE9E` (which builds a layout through | ||
| 4115 | `0x140C4B030` at `0x14193E06B` and then calls `0x1416F7100` from `0x14193DF4B`), not to the | ||
| 4116 | tiled branch at `0x14193E314`. | ||
| 4117 | - `0x1404F4210`, test at `0x1404F448A`: 0 takes `0x1404F44E4`. | ||
| 4118 | - `0x145121690` takes its non-`0x980` path and calls the computer's `+0x40` with offset 0 and a | ||
| 4119 | `pitch*height` span. | ||
| 4120 | |||
| 4121 | What a shim can do with that: `XGSuggestSwizzleMode` writes `0` and returns `S_OK`, and | ||
| 4122 | `XGCreateTextureComputer` can hand back an object whose slots used at these sites (2, 8, 10 and | ||
| 4123 | `+0x40`) pass the byte offset through and report the full linear row span. The linear paths above | ||
| 4124 | compute `pitch*row + x` themselves and ask the object only for an offset, so nothing has to model | ||
| 4125 | a tile. `FUN_145121980` (`0x145121980`) is not the mode test but a cache: `0x144DB9180` keys it on | ||
| 4126 | the description bytes, `0xE` and `(flags&0xFF)<<16 | mode`, and it builds a tiled layout only on a | ||
| 4127 | miss, so an identity computer still has to answer whatever that branch asks. | ||
| 4128 | |||
| 4129 | What is not established: `0x102` and `0x10A` are written by the two helpers, but the four | ||
| 4130 | consumers above only special-case `0x100` and bit 9, so whether the variants are meant to be tiled | ||
| 4131 | was not measured. The physical layout of a non-zero mode is not new here either | ||
| 4132 | ([textures.md](textures.md), `runtime/src/gfx10_tiling.h`); 0 is the choice of the linear layout, | ||
| 4133 | not a description of one. | ||
| 4134 | |||
| 3904 | ### 4.3 Barriers and layouts | 4135 | ### 4.3 Barriers and layouts |
| 3905 | 4136 | ||
| 3906 | Plain buffer copies order earlier transfer writes on the same queue before reading or writing the next range. | 4137 | Plain buffer copies order earlier transfer writes on the same queue before reading or writing the next range. |
| @@ -4852,13 +5083,13 @@ to be recovered from call sites (or the NDA GDK headers, if a developer has acce | |||
| 4852 | | No ESRAM | Xbox Series X\|S uses unified GDDR6; ESRAM was Xbox One | Do not implement ESRAM-era APIs. The `d3d12_xs.cpp` comment about "ESRAM-era extensions" should be read as Xbox One, not Series. | | 5083 | | No ESRAM | Xbox Series X\|S uses unified GDDR6; ESRAM was Xbox One | Do not implement ESRAM-era APIs. The `d3d12_xs.cpp` comment about "ESRAM-era extensions" should be read as Xbox One, not Series. | |
| 4853 | | Binning | The GDK topic index names Xbox binning modes (NDA content) | Should be a no-op if the game uses it only as an optimisation: it changes how a render pass uses on-chip memory, not the result. Log and ignore for the first boot; revisit for performance. **Open** whether the game relies on binning for correctness. | | 5084 | | Binning | The GDK topic index names Xbox binning modes (NDA content) | Should be a no-op if the game uses it only as an optimisation: it changes how a render pass uses on-chip memory, not the result. Log and ignore for the first boot; revisit for performance. **Open** whether the game relies on binning for correctness. | |
| 4854 | | DCC / texture compatibility | Public release note for `D3D12XBOX_RESOURCE_FLAG_FORCE_TEXTURE_COMPATIBILITY` | Let Vulkan choose compression; fail if the game aliases/reads raw compressed data. | | 5085 | | DCC / texture compatibility | Public release note for `D3D12XBOX_RESOURCE_FLAG_FORCE_TEXTURE_COMPATIBILITY` | Let Vulkan choose compression; fail if the game aliases/reads raw compressed data. | |
| 4855 | | PresentX / present planes / frame events | Public GDK samples (MIT/zlib), §4.5 | Likely the only present path of a GDKX title. Presenter + vblank-timed frame events; 1-2 planes composed into the Vulkan swapchain (placement, filter, alpha overlay, HDR10 conversions). Call shapes known; slots/layouts **Open**. | | 5086 | | PresentX / present planes / frame events | Public GDK samples (MIT/zlib), §4.5; the device calls are measured (§7.1) | Likely the only present path of a GDKX title. Presenter + vblank-timed frame events; 1-2 planes composed into the Vulkan swapchain (placement, filter, alpha overlay, HDR10 conversions). Call shapes known; the four frame-call slots are **Measured** called, on one device pointer; plane/parameter layouts **Open**. | |
| 4856 | | Device slots 48/73/78/79/80 | Public HLE `Freminet`/`ScarlettX` (third-party, not Microsoft documentation) | `d3d12_xs_device.cpp` routes `CreateCommandQueueX` (48), `CreateCommandListX` (73), `SetFrameIntervalX` (78), `ScheduleFrameEventX` (79) and `WaitFrameEventX` (80) before it indexes the PC vtable. Queue and list creation use the existing create paths. The frame-event calls are a per-device token counter: `WaitFrameEventX` returns at once with a fresh non-zero token, because there is no vblank source before a presenter exists. The five indices can be moved with `LEONIDA_XS_QUEUE_X_SLOT`, `LEONIDA_XS_LIST_X_SLOT`, `LEONIDA_XS_FRAME_INTERVAL_SLOT`, `LEONIDA_XS_SCHEDULE_EVENT_SLOT` and `LEONIDA_XS_WAIT_EVENT_SLOT` (3..127; a value that names a slot the proxy already handles keeps that slot's handler); a trace that disagrees wins. | | 5087 | | Device slots 48/73/78/79/80 | Public HLE `Freminet`/`ScarlettX` (third-party, not Microsoft documentation); 78-80 **Measured** in the executable at the documented arities (§7.1) | `d3d12_xs_device.cpp` routes `CreateCommandQueueX` (48), `CreateCommandListX` (73), `SetFrameIntervalX` (78), `ScheduleFrameEventX` (79) and `WaitFrameEventX` (80) before it indexes the PC vtable. Queue and list creation use the existing create paths. The frame-event calls are a per-device token counter: `WaitFrameEventX` returns at once with a fresh non-zero token, because there is no vblank source before a presenter exists. The five indices can be moved with `LEONIDA_XS_QUEUE_X_SLOT`, `LEONIDA_XS_LIST_X_SLOT`, `LEONIDA_XS_FRAME_INTERVAL_SLOT`, `LEONIDA_XS_SCHEDULE_EVENT_SLOT` and `LEONIDA_XS_WAIT_EVENT_SLOT` (3..127; a value that names a slot the proxy already handles keeps that slot's handler); a trace that disagrees wins. | |
| 4857 | | Indirect argument type 105 | The retail title's startup creates five one-argument command signatures (device slot 41) with no root signature; one has type 105 and a 12-byte stride. Its two `ExecuteIndirect` sites, read statically, set the compute state first, as the `DISPATCH` sites do, and pass one command from the same argument buffer, on a second command list | `d3d12_xs_device.cpp` creates it as `DISPATCH` (`D3D12_DISPATCH_ARGUMENTS`). What the console does differently for it is **Open**. | | 5088 | | Indirect argument type 105 | The retail title's startup creates five one-argument command signatures (device slot 41) with no root signature; one has type 105 and a 12-byte stride. Its two `ExecuteIndirect` sites, read statically, set the compute state first, as the `DISPATCH` sites do, and pass one command from the same argument buffer, on a second command list | `d3d12_xs_device.cpp` creates it as `DISPATCH` (`D3D12_DISPATCH_ARGUMENTS`). What the console does differently for it is **Open**. | |
| 4858 | | Device slot 61 | The retail title's boot under `gta6rt --run` (stop 20 of the RT-5 measurements in #6910): called as `(desc, dest handle)` once per sampler | `d3d12_xs_device.cpp` routes it to the PC `CreateSampler` (slot 22) with the description's PC `D3D12_SAMPLER_DESC` prefix, for a caller in an image the guest loader mapped; the PC slot 61 is `CreateMetaCommand`, which any other caller (a host test driving the device through the proxy) still gets. The layout of the description beyond the PC fields is **Open**. | | 5089 | | Device slot 61 | The retail title's boot under `gta6rt --run` (stop 20 of the RT-5 measurements in #6910): called as `(desc, dest handle)` once per sampler | `d3d12_xs_device.cpp` routes it to the PC `CreateSampler` (slot 22) with the description's PC `D3D12_SAMPLER_DESC` prefix, for a caller in an image the guest loader mapped; the PC slot 61 is `CreateMetaCommand`, which any other caller (a host test driving the device through the proxy) still gets. The layout of the description beyond the PC fields is **Open**. | |
| 4859 | | Device slot 74 | The retail title's boot under `gta6rt --run`: called as `(pointer, u32, pointer)` | **Stand-in.** `d3d12_xs_device.cpp` answers `S_OK` and does nothing, for a caller in an image the guest loader mapped; the PC slot 74 is `ShaderCacheControl`, which the call does not fit and which any other caller still gets. What the console method is, and what it should do, is **Open**. | | 5090 | | Device slot 74 | The retail title's boot under `gta6rt --run`: called as `(pointer, u32, pointer)` | **Stand-in.** `d3d12_xs_device.cpp` answers `S_OK` and does nothing, for a caller in an image the guest loader mapped; the PC slot 74 is `ShaderCacheControl`, which the call does not fit and which any other caller still gets. What the console method is, and what it should do, is **Open**. | |
| 4860 | | Command-allocator slot 9 | The retail title's boot under `gta6rt --run`: called past the 9-slot PC allocator, as `(function pointer, context, ...)`; `SetAllocatorCallbackX` is the name the commit that added it uses | **Stand-in.** The allocator proxy records the callback and its context (`allocator_proxy_callback`, `allocator_proxy_callback_context`) and answers `S_OK`. **Nothing calls the callback**: the Vulkan layer backs command buffers itself. Whether the title depends on being called back is **Open**. | | 5091 | | Command-allocator slot 9 | The retail title's boot under `gta6rt --run`: called past the 9-slot PC allocator, as `(function pointer, context, ...)`; `SetAllocatorCallbackX` is the name the commit that added it uses | **Stand-in.** The allocator proxy records the callback and its context (`allocator_proxy_callback`, `allocator_proxy_callback_context`) and answers `S_OK`. **Nothing calls the callback**: the Vulkan layer backs command buffers itself. Whether the title depends on being called back is **Open**. | |
| 4861 | | Device slot 81, queue `PresentX`/`SuspendX`/`ResumeX` | XCL (GPL-2.0-only, third-party): `GetFrameStatisticsX` at device slot 81, `PresentX` at queue slot 30 (older runtime layout) or 32 (newer); `SuspendX`/`ResumeX` slots unmeasured | `set_presentation_handler` forwards 78-81 and the queue routes to a presenter (`attach_xbox_presentation`). Without one, slot 81 answers `S_OK` with a zero count (no statistics yet; the answer the retail boot through the story load was measured with, where the public samples' "not available yet" is `S_FALSE`; a null count, or a count above zero with no array, is `E_POINTER`); `PresentX` goes to the presentation the device proxy builds itself on the first call (`queue_present_x`: in the title's window or one of the runtime's, `LEONIDA_PRESENT_WINDOW`), which takes its frame tokens from the same source as the device's `WaitFrameEventX`; every other queue slot past the PC table answers `S_OK` and does nothing, except slot 31 (next row). `PresentX` is slot 30 on a queue in the older layout and slot 32 on a queue detected as the newer one (a fence reaching slot 16 or 17, or `SignalX` at 25), never both: in the newer layout slot 30 is another method. Slot 81 moves with `LEONIDA_XS_FRAME_STATISTICS_SLOT` (3..127); `LEONIDA_XS_PRESENT_X_SLOT` pins `PresentX` to one slot whatever the layout; `SuspendX` and `ResumeX` are routed only when `LEONIDA_XS_SUSPEND_X_SLOT` / `LEONIDA_XS_RESUME_X_SLOT` are set (queue slots 19..127; two routes on one slot are refused with a log). | | 5092 | | Device slot 81, queue `PresentX`/`SuspendX`/`ResumeX` | XCL (GPL-2.0-only, third-party): `GetFrameStatisticsX` at device slot 81, `PresentX` at queue slot 30 (older runtime layout) or 32 (newer); `SuspendX`/`ResumeX` slots unmeasured; slot 81 **Measured** called (§7.1) | `set_presentation_handler` forwards 78-81 and the queue routes to a presenter (`attach_xbox_presentation`). Without one, slot 81 answers `S_OK` with a zero count (no statistics yet; the answer the retail boot through the story load was measured with, where the public samples' "not available yet" is `S_FALSE`; a null count, or a count above zero with no array, is `E_POINTER`); `PresentX` goes to the presentation the device proxy builds itself on the first call (`queue_present_x`: in the title's window or one of the runtime's, `LEONIDA_PRESENT_WINDOW`), which takes its frame tokens from the same source as the device's `WaitFrameEventX`; every other queue slot past the PC table answers `S_OK` and does nothing, except slot 31 (next row). `PresentX` is slot 30 on a queue in the older layout and slot 32 on a queue detected as the newer one (a fence reaching slot 16 or 17, or `SignalX` at 25), never both: in the newer layout slot 30 is another method. Slot 81 moves with `LEONIDA_XS_FRAME_STATISTICS_SLOT` (3..127); `LEONIDA_XS_PRESENT_X_SLOT` pins `PresentX` to one slot whatever the layout; `SuspendX` and `ResumeX` are routed only when `LEONIDA_XS_SUSPEND_X_SLOT` / `LEONIDA_XS_RESUME_X_SLOT` are set (queue slots 19..127; two routes on one slot are refused with a log). | |
| 4862 | | Queue slot 31, `CopyPageMappingsBatchX` | Arguments `(count, batches, pool, pool pages, flags)`, a 24-byte batch `{UINT64 destination; UINT32 range count; const range* ranges}` and a 12-byte range `{UINT32 kind, start, count}`: read statically from the retail executable's call site and the code that fills the batches (#968), corroborated by the same call shape in a public project's queue (VIctory, `copy_page_mappings`, where the newer layout puts it at 29), and the pool-size argument equalled the page count of the title's own `XMemAllocatePhysicalPages` call in a boot | Every range goes to xmem's `copy_page_mappings_fn` (`d3d12_xs_device.cpp`, `queue_copy_page_mappings`): kind 0 maps pool pages `start, start + 1, ...` at the destination, 1 maps pool page `start` at every destination page, 2 unmaps, 3 leaves the destination as it is; each range moves the destination on by `count` pages. A destination page gets a second view of the physical page mapped at its source page, and the same view at the paired CPU range when the destination is a GPU-only reservation (`title_gpu_views`), where the layer reads that memory. `S_OK` when every range was applied, `E_INVALIDARG` (logged once) for a range past the pool, an unknown kind or one xmem refuses; without xmem linked (tests of the proxy alone) the slot answers `S_OK` like the other console-only slots. Tested by `xmem_test` and `xs_proxy_mock_test`. **Known gap:** the mappings change when the call is made, not when the queue reaches the batch, as on the console; whether earlier queued work still reads a destination page then is not measured. | | 5093 | | Queue slot 31, `CopyPageMappingsBatchX` | Arguments `(count, batches, pool, pool pages, flags)`, a 24-byte batch `{UINT64 destination; UINT32 range count; const range* ranges}` and a 12-byte range `{UINT32 kind, start, count}`: read statically from the retail executable's call site and the code that fills the batches (#968), corroborated by the same call shape in a public project's queue (VIctory, `copy_page_mappings`, where the newer layout puts it at 29), and the pool-size argument equalled the page count of the title's own `XMemAllocatePhysicalPages` call in a boot | Every range goes to xmem's `copy_page_mappings_fn` (`d3d12_xs_device.cpp`, `queue_copy_page_mappings`): kind 0 maps pool pages `start, start + 1, ...` at the destination, 1 maps pool page `start` at every destination page, 2 unmaps, 3 leaves the destination as it is; each range moves the destination on by `count` pages. A destination page gets a second view of the physical page mapped at its source page, and the same view at the paired CPU range when the destination is a GPU-only reservation (`title_gpu_views`), where the layer reads that memory. `S_OK` when every range was applied, `E_INVALIDARG` (logged once) for a range past the pool, an unknown kind or one xmem refuses; without xmem linked (tests of the proxy alone) the slot answers `S_OK` like the other console-only slots. Tested by `xmem_test` and `xs_proxy_mock_test`. **Known gap:** the mappings change when the call is made, not when the queue reaches the batch, as on the console; whether earlier queued work still reads a destination page then is not measured. | |
| 4863 | | VRS | Public `D3D12_SHADING_RATE` / `D3D12_AXIS_SHADING_RATE` | `VK_KHR_fragment_shading_rate`; `RSSetShadingRate`/image-based rate map to `vkCmdSetFragmentShadingRateKHR`. | | 5094 | | VRS | Public `D3D12_SHADING_RATE` / `D3D12_AXIS_SHADING_RATE` | `VK_KHR_fragment_shading_rate`; `RSSetShadingRate`/image-based rate map to `vkCmdSetFragmentShadingRateKHR`. | |
| 4864 | | Mesh shader tier | Public `D3D12_MESH_SHADER_TIER` | `VK_EXT_mesh_shader`; the 9,282 translated mesh shaders make this a hard requirement for any content that uses them. | | 5095 | | Mesh shader tier | Public `D3D12_MESH_SHADER_TIER` | `VK_EXT_mesh_shader`; the 9,282 translated mesh shaders make this a hard requirement for any content that uses them. | |
| @@ -4930,34 +5161,79 @@ when it cannot sample the submission lock for that long. A progress warning leav | |||
| 4930 | device state intact. The driver checkpoint and fault-info queries run after Vulkan reports device loss. This mode | 5161 | device state intact. The driver checkpoint and fault-info queries run after Vulkan reports device loss. This mode |
| 4931 | is off by default. | 5162 | is off by default. |
| 4932 | 5163 | ||
| 5164 | Each fault address is also looked up in this process (RT-FAULT-ADDRESS-OWNER). On Windows, `VirtualQuery` of the | ||
| 5165 | same number gives the region's base, allocation base, state, protection and type. A GPU address isn't a CPU one, | ||
| 5166 | but a host import, a range of the title's memory and a raw CPU pointer that reached a shader all share the | ||
| 5167 | number. With `LEONIDA_ADDRESS_BINDINGS=1` as well, the device enables `VK_EXT_device_address_binding_report`, and | ||
| 5168 | a debug messenger records the GPU virtual address range of every buffer, image and allocation the driver binds | ||
| 5169 | and unbinds (`runtime/src/address_binding.h`). The fault report then lists, for each address: | ||
| 5170 | - the live objects that contain the address ("containing"), and those that only share its reported page, whose | ||
| 5171 | size is the fault's `addressPrecision` ("on the page"); | ||
| 5172 | - the live objects that end nearest below it and start nearest above it; | ||
| 5173 | - up to 16 recently unbound objects that held it, with their type, range, handle and the times they were bound | ||
| 5174 | and unbound. | ||
| 5175 | |||
| 5176 | "Nothing live or recently unbound there" means that no object of this device had that GPU address. On an | ||
| 5177 | RTX 5070 Ti the world-start loss of 1.0.2.1 reported write addresses far above every bound range, at about 50,000 | ||
| 5178 | binds. The record keeps the last 16,384 unbinds and costs one map entry per live binding. | ||
| 5179 | |||
| 5180 | There is one record per process. A second Vulkan instance in the same process (a second device) is refused a | ||
| 5181 | messenger, and its device doesn't enable the extension, so the two devices' GPU addresses aren't mixed. If | ||
| 5182 | `LEONIDA_ADDRESS_BINDINGS=1` is set but no messenger records the device, the fault report says that the bindings | ||
| 5183 | were not recorded, so this can't be mistaken for "nothing live or recently unbound there". | ||
| 5184 | |||
| 4933 | Each dispatch line carries a `seq`: a number every recorded dispatch gets, across queues and submissions, in the | 5185 | Each dispatch line carries a `seq`: a number every recorded dispatch gets, across queues and submissions, in the |
| 4934 | order the submissions were recorded. The list keeps the last 64, so its numbers can have gaps where a submission | 5186 | order the submissions were recorded. The list keeps the last 64, so its numbers can have gaps where a submission |
| 4935 | recorded more than that. | 5187 | recorded more than that. |
| 4936 | 5188 | ||
| 4937 | **AMD breadcrumbs.** NVIDIA's checkpoints say where a queue stopped; RADV has none. With `LEONIDA_DEVICE_MARKERS=1` | 5189 | **AMD breadcrumbs.** NVIDIA's checkpoints say where a queue stopped; RADV has none. With `LEONIDA_DEVICE_MARKERS=1` |
| 4938 | as well, on a device with `VK_AMD_buffer_marker`, every numbered dispatch writes its `seq` into its queue's slot of | 5190 | as well, on a device with `VK_AMD_buffer_marker`, every numbered dispatch and every draw writes its `seq` into its |
| 4939 | one persistent buffer twice (`src/vulkan_device_markers.h`): at top of pipe before the dispatch (started) and at | 5191 | queue's slot of one persistent buffer twice (`src/vulkan_device_markers.h`): at top of pipe before the work |
| 4940 | bottom of pipe after it (finished), with `vkCmdWriteBufferMarker2AMD` (or `vkCmdWriteBufferMarkerAMD` without | 5192 | (started) and at bottom of pipe after it (finished), with `vkCmdWriteBufferMarker2AMD` (or |
| 4941 | synchronization2). A bottom-of-pipe write waits for all earlier work on the queue, so the finished value is the last | 5193 | `vkCmdWriteBufferMarkerAMD` without synchronization2). Draws and dispatches share the numbering, so the 64-entry |
| 4942 | dispatch before which everything had completed, and the queue's dispatches after it up to the started value are the | 5194 | dispatch list has gaps where draws ran. A bottom-of-pipe write waits for all earlier work on the queue, so the |
| 4943 | ones the GPU began and did not finish. The oldest of them is the likely hang. The buffer is host-visible and | 5195 | finished value is the last item before which everything had completed, and the queue's items after it up to the |
| 4944 | coherent, in system memory where the device has such a type, so it can still be read after a device loss. The loss | 5196 | started value are the ones the GPU began and did not finish. The oldest of them is the likely hang. The buffer is |
| 4945 | and stall reports then add lines like these (the shader names are made up): | 5197 | host-visible and coherent, in system memory where the device has such a type, so it can still be read after a device |
| 5198 | loss. The loss and stall reports then add lines like these (the shader names are made up): | ||
| 4946 | 5199 | ||
| 4947 | ``` | 5200 | ``` |
| 4948 | [rt] device-markers: AMD buffer markers, read after the device loss; best-effort: only what the GPU wrote before it stopped, and a reset may have lost the last writes | 5201 | [rt] device-markers: AMD buffer markers, read after the device loss; best-effort: only what the GPU wrote before it stopped, and a reset may have lost the last writes |
| 4949 | [rt] device-markers: queue 0000000012345678 (compute) finished seq=1203 started seq=1205; started, not finished: 1204 1205 | 5202 | [rt] device-markers: queue 0000000012345678 (compute) finished seq=1203 started seq=1205; started, not finished: 1204 1205 |
| 5203 | [rt] device-markers: finished: seq=1203 execute=88 queue=0000000012345678 (compute) list=0 command=16 shader=cs_example_b | ||
| 4950 | [rt] device-markers: likely hang: seq=1204 execute=88 queue=0000000012345678 (compute) list=0 command=17 shader=cs_example_a | 5204 | [rt] device-markers: likely hang: seq=1204 execute=88 queue=0000000012345678 (compute) list=0 command=17 shader=cs_example_a |
| 4951 | [rt] device-markers: queue 00000000123456a0 (direct) idle: finished seq=1199, nothing started after it; next submitted seq=1206 not started (waiting, or behind other work of the queue) | 5205 | [rt] device-markers: in flight: seq=1205 execute=88 queue=0000000012345678 (compute) list=0 command=18 shader=cs_example_a |
| 5206 | [rt] device-markers: queue 00000000123456a0 (direct) finished seq=1199 started seq=1200; started, not finished: 1200 | ||
| 5207 | [rt] device-markers: finished: seq=1199 execute=89 queue=00000000123456a0 (direct) list=1 command=1 shader=cs_example_c | ||
| 5208 | [rt] device-markers: likely hang: seq=1200 execute=89 queue=00000000123456a0 (direct) list=1 command=7 draw=indexed count=3480 instances=1 pipeline=vs vs_example ps ps_example pass=draw 4 since command 2 (3 colours + depth, 1920x1080) | ||
| 4952 | [rt] device-fault: submitted dispatch seq=1204 execute=88 queue=0000000012345678 (compute) list=0 command=17 shader=cs_example_a groups=64,1,1 <- likely hang (device-markers) | 5209 | [rt] device-fault: submitted dispatch seq=1204 execute=88 queue=0000000012345678 (compute) list=0 command=17 shader=cs_example_a groups=64,1,1 <- likely hang (device-markers) |
| 4953 | ``` | 5210 | ``` |
| 4954 | 5211 | ||
| 4955 | A separate history of the last 16,384 dispatches names the likely hang when it has already left the 64-entry list. | 5212 | A draw line gives its kind (`indexed`, `vertices`, `mesh`, with `-quads` for a quad list and `-indirect` or |
| 4956 | An idle queue (finished equals started) is not called hung: if it still has dispatches submitted, it was waiting | 5213 | `-indirect-count` for arguments from a buffer) and counts (vertex or index count and instances, a mesh dispatch's |
| 4957 | on a semaphore or stuck in work that is not a dispatch (a draw, a copy). The values are what the GPU wrote before | 5214 | `groups`, an indirect draw's `max` records and `stride`), its pipeline named as the `LEONIDA_GPU_PROFILE` lines name |
| 4958 | it stopped; after a loss and a ring reset they may be stale, so read them as a pointer, not a proof. The cost with | 5215 | it (`gpu_profile::label`: each stage's tag and entry name, or `pso 0x...`), and its place among the draws of the list |
| 4959 | the switch on is two marker writes per dispatch (a command-processor write and an end-of-pipe event, no wait) plus | 5216 | to the same targets: `pass=draw 4 since command 2` is the fourth draw to these targets since command 2. An idle queue |
| 4960 | one entry in the history; with it off nothing is recorded. Without the extension, or without | 5217 | gets a `not started:` line for its next submitted item. When `VK_EXT_device_fault` reports an address, a |
| 5218 | `device-fault: last started draw (device-markers):` line per queue follows the address lines, with `(not finished)` | ||
| 5219 | or `(finished)` and `<- likely hang` when it is the queue's likely hang. | ||
| 5220 | |||
| 5221 | Granularity: a pair per draw, as per dispatch. The replay opens a rendering scope per draw, so the started write goes | ||
| 5222 | before the draw's helper passes (quad index expansion, indirect clamp; a hang there is named as the draw's) and the | ||
| 5223 | finished one after the scope ends, both outside a render pass instance. The extension allows them inside one too | ||
| 5224 | (`vk.xml`: `renderpass="both"`, and conditional rendering does not apply), which the legacy graphics ExecuteIndirect | ||
| 5225 | path, drawing in the caller's scope, uses; `vk_device_markers_test` writes a pair inside an open scope under | ||
| 5226 | validation. RADV (`radv_CmdWriteMarkerToMemoryAMD`) emits the cache flushes already pending, then a top-of-pipe write | ||
| 5227 | as one write-confirmed COPY_DATA (the command processor waits for that write only) and any other stage as one | ||
| 5228 | bottom-of-pipe EOP event (no wait): at most 24 dwords per draw, against the hundreds the draw's own scope and state | ||
| 5229 | take. A pair per run of one pipeline would be cheaper but could not name the draw, so it was not chosen. | ||
| 5230 | |||
| 5231 | A separate history of the last 65,536 dispatches and draws (about 6 MiB) names the likely hang when it has already | ||
| 5232 | left the 64-entry list, and names every draw. An idle queue (finished equals started) is not called hung: if it | ||
| 5233 | still has work submitted, it was waiting on a semaphore or stuck in work that is neither (a copy, a barrier). The | ||
| 5234 | values are what the GPU wrote before it stopped; after a loss and a ring reset they may be stale, so read them as a | ||
| 5235 | pointer, not a proof. The cost with the switch on is two marker writes per dispatch and per draw plus one entry in | ||
| 5236 | the history; with it off nothing is recorded. Without the extension, or without | ||
| 4961 | `LEONIDA_DEVICE_FAULT`, the runtime logs one `device-markers: unavailable` line and runs as before. | 5237 | `LEONIDA_DEVICE_FAULT`, the runtime logs one `device-markers: unavailable` line and runs as before. |
| 4962 | 5238 | ||
| 4963 | For a local pre-submit inspection, also set `LEONIDA_COMPUTE_INPUTS` to comma-separated shader name fragments and | 5239 | For a local pre-submit inspection, also set `LEONIDA_COMPUTE_INPUTS` to comma-separated shader name fragments and |
| @@ -4993,6 +5269,12 @@ store, load, mesh, geometry and BVH tests; this layer is the other half. | |||
| 4993 | 5269 | ||
| 4994 | ### 5.1 Descriptor hash table details | 5270 | ### 5.1 Descriptor hash table details |
| 4995 | 5271 | ||
| 5272 | Since the T# index word (`docs/design.md`, "Bindless index in the T#") the table serves only what the word does not | ||
| 5273 | reach: every S#, and the T#s a translated module cannot trace to a heap slot (1,062 of the 439,415 T# operands of | ||
| 5274 | the 1.0.2.1 corpus, in 108 modules). A T# loaded from a heap the layer writes carries its index and kind in dword 6 | ||
| 5275 | and is never looked up. Every T# key is still inserted, as the title wrote it: a T# outside the heaps is found by | ||
| 5276 | those words. | ||
| 5277 | |||
| 4996 | The exact layout the shader reads (from `tools/rdna2spirv.py`, `desc_lookup`): | 5278 | The exact layout the shader reads (from `tools/rdna2spirv.py`, `desc_lookup`): |
| 4997 | 5279 | ||
| 4998 | ``` | 5280 | ``` |
| @@ -5283,6 +5565,25 @@ folded into the table below with the measurement basis noted per row; nothing is | |||
| 5283 | is wrapped. The public chain is a usable base for those methods, not a guess. | 5565 | is wrapped. The public chain is a usable base for those methods, not a guess. |
| 5284 | - The BVH builder receives the device and command lists from the caller; prior art runs it exactly that way. | 5566 | - The BVH builder receives the device and command lists from the caller; prior art runs it exactly that way. |
| 5285 | 5567 | ||
| 5568 | **Measured: the presentation slots 78, 79, 80 and 81 are called, on the device** (D3D12-PRESENT-SLOTS-MEASURED). | ||
| 5569 | All eight device sites load the one device pointer from the BSS global `0x148759D00` into `rcx` and call through | ||
| 5570 | `[[rcx] + offset]`; that is the same global the layer's known device calls use (e.g. `CreateCommittedResource`, | ||
| 5571 | slot 27, at `0x142481bce`), and many subsystems load it rip-relative, as they would a device singleton. The | ||
| 5572 | other `call [reg+offset]` sites at those offsets belong to other interfaces that share the PC slot numbers, so they are | ||
| 5573 | counted but not attributed. Arity and arguments are the register and stack words written before each site: | ||
| 5574 | |||
| 5575 | | slot | offset | raw sites | device sites | receiver | arguments (registers, then stack) | what it is | | ||
| 5576 | |---:|---|---:|---:|---|---|---| | ||
| 5577 | | 78 | `0x270` | 31 | 1 | `[0x148759D00]` | `0x14247abd8`: `rdx`=0 (output), `r8d`=`edi` (latency word from the interval table indexed at `0x14247ab95`), `r9d`=2 or 3 (flags, same table), `[rsp+0x20]`=0 | `SetFrameIntervalX`, 4 arguments (output NULL, latency, flags, 0). Its function (`0x14247ab10`) has three callers on the frame-interval paths; the slot itself has one site. | | ||
| 5578 | | 79 | `0x278` | 40 | 3 | `[0x148759D00]` | `0x14247abfc`: `rdx`=0 (event), `r8d`=`edi` (offset), `r9d`=0 (reserved), `[rsp+0x20]`=0. `0x142478de4`: `rdx`=2, `r8`=0, `r9`=0, `[rsp+0x20]`=0. `0x1424900e3`: same as the previous site. | `ScheduleFrameEventX`, 4 arguments (event, offset, null, flags 0). Event 0 is `ORIGIN`; event 2 is unlabelled and only appears on the two later sites. | | ||
| 5579 | | 80 | `0x280` | 42 | 3 | `[0x148759D00]` | `0x142482405`: `rdx`=2 (event), `r8d`=`0xFFFFFFFF` (INFINITE), `r9`=0 (reserved), `[rsp+0x20]`=0 (flags), `[rsp+0x28]`=`&[rsp+0x68]` (token out). `0x142482448`: `rdx`=0, `r8d`=INFINITE, `r9`=0, `[rsp+0x20]`=2 (flags), `[rsp+0x28]`=`&global token`. `0x142484637`: `rdx`=0, `r8d`=INFINITE, `r9`=0, `[rsp+0x20]`=0, `[rsp+0x28]`=`&[rsp+0x30]`. | `WaitFrameEventX`, 5 arguments (event, INFINITE, null, flags, token out) — the per-frame wait, once at the top of the loop; event 0 with flag 2 on the path that arms the origin, event 2 on the other. | | ||
| 5580 | | 81 | `0x288` | 522 | 1 | `[0x148759D00]` | `0x142482710`: `rdx`=token (`[r9 + r8*8]`, the previous round's entry of a 4-slot ring), `r8d`=`0x11100` (type mask), `r9`=`&count` (`[rsp+0x2c]`, seeded with 6), `[rsp+0x20]`=`&[rsp+0x30]` (0x38-byte statistics array) | `GetFrameStatisticsX`, 4 arguments. After the call it walks the returned entries and matches type `0x10000` (`FRAME_INTERVAL`) and `0x1000` (`FRAME_EVENT`), exactly the documented shape. | | ||
| 5581 | |||
| 5582 | The sites also confirm the order the samples use: interval, schedule, then a wait per frame; the statistics call reads | ||
| 5583 | a token that an earlier wait wrote. Flag 2 on the wait is the one XCL gives the "write the token even on timeout" | ||
| 5584 | meaning. `PresentX` itself is not in this set (it is a queue slot, §4.5); 78-81 are device slots beyond the public | ||
| 5585 | vtable order, as the prior art said. | ||
| 5586 | |||
| 5286 | **Corrects.** | 5587 | **Corrects.** |
| 5287 | 5588 | ||
| 5288 | - **Device creation.** `D3D12XboxCreateDevice` is the entry point. The 24-word params struct is only logged, so | 5589 | - **Device creation.** `D3D12XboxCreateDevice` is the entry point. The 24-word params struct is only logged, so |
| @@ -5303,8 +5604,7 @@ folded into the table below with the measurement basis noted per row; nothing is | |||
| 5303 | 5604 | ||
| 5304 | **Narrows.** | 5605 | **Narrows.** |
| 5305 | 5606 | ||
| 5306 | - Presentation slots and struct layouts (`PresentX` and plane parameters; call shapes are known from public samples, §4.5), command-list extensions, and queue/fence creation slots remain | 5607 | - Presentation slots 78-81 are now measured, with arity and receiver (above); the plane/parameter struct layouts, the queue `PresentX`/`SuspendX`/`ResumeX` slots (prior art only), command-list extensions, and queue/fence creation slots remain **Open**. |
| 5307 | unknown; the prior art explicitly stops before them. | ||
| 5308 | - Descriptor start-handle ABI is known; descriptor bytes and heap increments are still **Open**. Slot 15 is | 5608 | - Descriptor start-handle ABI is known; descriptor bytes and heap increments are still **Open**. Slot 15 is |
| 5309 | forwarded unchanged, but the actual increment values were not measured. | 5609 | forwarded unchanged, but the actual increment values were not measured. |
| 5310 | - Texture creation ABI and the `0x101` value are known; the tiled data layout, detile path and DCC remain | 5610 | - Texture creation ABI and the `0x101` value are known; the tiled data layout, detile path and DCC remain |
| @@ -5356,11 +5656,11 @@ nothing is copied from their trees. | |||
| 5356 | | # | Question | How to resolve | | 5656 | | # | Question | How to resolve | |
| 5357 | |---|---|---| | 5657 | |---|---|---| |
| 5358 | | 1 | The device entry point is now named `D3D12XboxCreateDevice(adapter, params, riid, out)`. What do its 24-word params and flag bits mean? | Public documentation and the executable's call sites. Log the words and accept any flag bits; do not treat a wrong params layout as fatal until the fields are understood. | | 5658 | | 1 | The device entry point is now named `D3D12XboxCreateDevice(adapter, params, riid, out)`. What do its 24-word params and flag bits mean? | Public documentation and the executable's call sites. Log the words and accept any flag bits; do not treat a wrong params layout as fatal until the fields are understood. | |
| 5359 | | 2 | Which Xbox device/heap/queue/command-list slots differ? Prior art measured device slots 62 and 76 and descriptor-heap slots 9/10; slot 14 is the public `CreateDescriptorHeap`, with only the returned heap's start-handle return wrapped. **Partly measured** with the FSR DLL ([d3d12_command_objects.md §3.5a](d3d12_command_objects.md)): device slots 14, 15, 16, 18, 19, 27, 38, 62 and 76 at their expected shapes (24 in the code, not called), slot 67 a console-only pipeline call; command-list slots 14, 15, 25 and 26 at their PC positions, then shifted (+4 from `SetDescriptorHeaps` at 32, +2 at `ExecuteIndirect` at 61), with console-only methods at 85 and 141. The BVH builder's call sites add the rest of the +4 root group (37, 39, 43, 45) and console slots 71, 73, 80, 146 (the GCL7 `Barrier`) and 148 (an upload allocator whose pointer is also the GPU address) ([d3d12_command_objects.md §3.3, §3.3a](d3d12_command_objects.md)). A second, retail-title measurement adds console slots 83 (`CopyTextureRegion`), 84 (`CopyResource`), 26 (barriers), 127 (direct mesh dispatch — not the PC position, GCL6 slot 79), 59 (a second indirect/mesh dispatch path) and 96 (an async-compute budget call) (section 7). Presentation, queue and fence slots remain unknown. | Trace every `QueryInterface` and every method slot with per-slot hit counters. A wrong slot shows as an immediate crash or wrong argument; compare against the SDK vtable. | | 5659 | | 2 | Which Xbox device/heap/queue/command-list slots differ? Prior art measured device slots 62 and 76 and descriptor-heap slots 9/10; slot 14 is the public `CreateDescriptorHeap`, with only the returned heap's start-handle return wrapped. **Partly measured** with the FSR DLL ([d3d12_command_objects.md §3.5a](d3d12_command_objects.md)): device slots 14, 15, 16, 18, 19, 27, 38, 62 and 76 at their expected shapes (24 in the code, not called), slot 67 a console-only pipeline call; command-list slots 14, 15, 25 and 26 at their PC positions, then shifted (+4 from `SetDescriptorHeaps` at 32, +2 at `ExecuteIndirect` at 61), with console-only methods at 85 and 141. The BVH builder's call sites add the rest of the +4 root group (37, 39, 43, 45) and console slots 71, 73, 80, 146 (the GCL7 `Barrier`) and 148 (an upload allocator whose pointer is also the GPU address) ([d3d12_command_objects.md §3.3, §3.3a](d3d12_command_objects.md)). A second, retail-title measurement adds console slots 83 (`CopyTextureRegion`), 84 (`CopyResource`), 26 (barriers), 127 (direct mesh dispatch — not the PC position, GCL6 slot 79), 59 (a second indirect/mesh dispatch path) and 96 (an async-compute budget call) (section 7). Presentation slots 78-81 are measured ([§7.1](#71-what-this-confirms-corrects-and-narrows)); the rest of presentation, queue and fence slots remain unknown. | Trace every `QueryInterface` and every method slot with per-slot hit counters. A wrong slot shows as an immediate crash or wrong argument; compare against the SDK vtable. | |
| 5360 | | 3 | How does the console map a root signature to `s0..s31` (order, per-stage visibility, spills above 32 dwords, static samplers, direct-heap base)? | **Compute partly measured** by a sibling project's console-compiler output (section 7): parameters inline in user SGPRs from `s4` in root order while each fits whole; the first that does not fit, and all after it, go into a packed array addressed by a 40-bit pointer at `s[0:1]`; thread-group ids follow the user SGPRs. That matches this repo's CS census (lowest CS pointer SGPR `s4`). VS/PS/MS bases remain open. Static samplers: no sampling instruction was found reading one from a driver table (SHADER-735, section 3.5; 0.66% undetermined); which S# is a static sampler remains open. Dump the game's root-signature blobs with the host deserializer; mask the `0x03000000` flag byte on a copy first; match against the per-shader user-SGPR read sets. If a signature exceeds 32 dwords, reverse the spill pointer from the shader. | | 5660 | | 3 | How does the console map a root signature to `s0..s31` (order, per-stage visibility, spills above 32 dwords, static samplers, direct-heap base)? | **Compute partly measured** by a sibling project's console-compiler output (section 7): parameters inline in user SGPRs from `s4` in root order while each fits whole; the first that does not fit, and all after it, go into a packed array addressed by a 40-bit pointer at `s[0:1]`; thread-group ids follow the user SGPRs. That matches this repo's CS census (lowest CS pointer SGPR `s4`). VS/PS/MS bases remain open. Static samplers: no sampling instruction was found reading one from a driver table (SHADER-735, section 3.5; 0.66% undetermined); which S# is a static sampler remains open. Dump the game's root-signature blobs with the host deserializer; mask the `0x03000000` flag byte on a copy first; match against the per-shader user-SGPR read sets. If a signature exceeds 32 dwords, reverse the spill pointer from the shader. | |
| 5361 | | 4 | Are Xbox descriptor bytes GFX10 T#/S#, and what are the heap increments? Does the game use `Create*View` or build descriptors itself? | Dump a shader-visible heap after the first `CreateShaderResourceView` and after the first draw; compare the bytes the shader loads with the T# parser. The start-handle return ABI is known (RAX); the increment values still need measuring. | | 5661 | | 4 | Are Xbox descriptor bytes GFX10 T#/S#, and what are the heap increments? Does the game use `Create*View` or build descriptors itself? | Dump a shader-visible heap after the first `CreateShaderResourceView` and after the first draw; compare the bytes the shader loads with the T# parser. The start-handle return ABI is known (RAX). The game calls `GetDescriptorHandleIncrementSize` itself (ten device sites, all five heap types, section 3.4) and sizes heaps and handles from the answer; the numeric console values still need measuring, by hooking slot 15 and logging the answer. | |
| 5362 | | 5 | What is the buffer/descriptor/code VA range, and what arena capacity is needed? | Log every `GetGPUVirtualAddress` and every descriptor base; track the high-water mark. Choose a capacity; grow at a frame boundary if needed. | | 5662 | | 5 | What is the buffer/descriptor/code VA range, and what arena capacity is needed? | Log every `GetGPUVirtualAddress` and every descriptor base; track the high-water mark. Choose a capacity; grow at a frame boundary if needed. | |
| 5363 | | 6 | Which swapchain/present path is used: DXGI, `PresentX`, or both? | **Partly answered from public samples (§4.5):** GDKX samples use `PresentX` + frame events and no DXGI swapchain (DXGI only for `IDXGIDevice1`→adapter→output). Hypothesis for the game, not observed: same. Still open: vtable slots, `D3D12XBOX_*` layouts, and whether the game also creates a swapchain. Check imports and the first present call. Implement the `PresentX` + frame-event presenter first; keep DXGI swapchain as fallback. | | 5663 | | 6 | Which swapchain/present path is used: DXGI, `PresentX`, or both? | **Answered for the device half (measured, §7.1):** the game calls the frame-event device slots 78-81 on its device pointer, the same path the GDKX samples use; those samples present with `PresentX` and no DXGI swapchain (DXGI only for `IDXGIDevice1`→adapter→output). Still open: the queue `PresentX` slot the game calls, `SuspendX`/`ResumeX`, the `D3D12XBOX_*` layouts, and whether it also creates a swapchain. Check imports and the first present call. Implement the `PresentX` + frame-event presenter first; keep DXGI swapchain as fallback. | |
| 5364 | | 7 | Does the game build acceleration structures through the standard D3D12 calls or through `XboxBvhBuilder`'s own compute path? | Log `BuildRaytracingAccelerationStructure`, `CopyRaytracingAccelerationStructure`, `Emit...PostbuildInfo`, and the builder's command-list method calls on the first RT frame. The builder's container carries a DXIL bitcode blob and a console `XBCH` record; the record is `FSSM` and all 52 programs pass `spirv-val` ([embedded_shaders.md](embedded_shaders.md)). If the builder path is used, translate the `XBCH` record rather than the bitcode. | | 5664 | | 7 | Does the game build acceleration structures through the standard D3D12 calls or through `XboxBvhBuilder`'s own compute path? | Log `BuildRaytracingAccelerationStructure`, `CopyRaytracingAccelerationStructure`, `Emit...PostbuildInfo`, and the builder's command-list method calls on the first RT frame. The builder's container carries a DXIL bitcode blob and a console `XBCH` record; the record is `FSSM` and all 52 programs pass `spirv-val` ([embedded_shaders.md](embedded_shaders.md)). If the builder path is used, translate the `XBCH` record rather than the bitcode. | |
| 5365 | | 8 | What are the layouts of `D3D12XBOX_XDXR_STREAM_DESC`, the batched build desc, and the offline statistics desc? | **Measured** from `XboxBvhBuilder.dll`'s reads ([xdxr.md](xdxr.md)): `BATCHED_DESC2` (`0x50`) and `XDXR_STREAM_DESC` (`0x10`) with every field's offset, and the stream records' offsets, types and defaults. Still open: the record names, and the offline statistics layout, which the DLL never writes (it rejects that postbuild type). | | 5665 | | 8 | What are the layouts of `D3D12XBOX_XDXR_STREAM_DESC`, the batched build desc, and the offline statistics desc? | **Measured** from `XboxBvhBuilder.dll`'s reads ([xdxr.md](xdxr.md)): `BATCHED_DESC2` (`0x50`) and `XDXR_STREAM_DESC` (`0x10`) with every field's offset, and the stream records' offsets, types and defaults. Still open: the record names, and the offline statistics layout, which the DLL never writes (it rejects that postbuild type). | |
| 5366 | | 9 | Xbox texture creation is device slot 76 with layout `0x101` (tiled) or `0x1` (row-major). What is the tiled data layout, and does the game upload console-tiled or DCC data? | Trace slot 76, `CopyTextureRegion` and the resource descs. If the game uploads console-tiled data, add a detile step or a matching layout. | | 5666 | | 9 | Xbox texture creation is device slot 76 with layout `0x101` (tiled) or `0x1` (row-major). What is the tiled data layout, and does the game upload console-tiled or DCC data? | Trace slot 76, `CopyTextureRegion` and the resource descs. If the game uploads console-tiled data, add a detile step or a matching layout. | |
diff --git a/docs/d3d12_xs_console_abi.md b/docs/d3d12_xs_console_abi.md index 986acf680..fc3c75a17 100644 --- a/docs/d3d12_xs_console_abi.md +++ b/docs/d3d12_xs_console_abi.md | |||
| @@ -258,15 +258,29 @@ The runtime's model: | |||
| 258 | a gate fence that is signalled once memory compares true. The Vulkan layer holds the queue's later work behind | 258 | a gate fence that is signalled once memory compares true. The Vulkan layer holds the queue's later work behind |
| 259 | that wait without blocking the submitting thread (`src/queue_holds.h`). The pump only decides; a second thread, | 259 | that wait without blocking the submitting thread (`src/queue_holds.h`). The pump only decides; a second thread, |
| 260 | the releaser, signals the gates, because that Signal runs the work the layer held behind them (the held | 260 | the releaser, signals the gates, because that Signal runs the work the layer held behind them (the held |
| 261 | submission, the shadow refresh, a deferred Present), and the pump keeps landing writes and timing gates out | 261 | submission, the shadow refresh, a deferred Present), and the pump keeps landing writes and looking at gates |
| 262 | meanwhile. | 262 | meanwhile. Other queues' work, which does not wait for the gate, goes on. |
| 263 | - A gate opens after `LEONIDA_VALUE_WAIT_TIMEOUT_MS` (default 200) whatever memory holds, counted from when the | 263 | - A gate is held until memory compares true, however long that takes: there is no timeout. It goes without its |
| 264 | gates before it on its queue opened, and logged once per address. An address that timed out three times in a row | 264 | value only when nothing else can make progress (`src/list_value_progress.h`): the releaser is idle, no title |
| 265 | (the last 256 addresses are counted) gets 4 ms. Once four gates in a row timed out, so does every wait for an | 265 | `ExecuteCommandLists` is in progress, and no write group or remap of the pump runs on the GPU (one whose Signal the |
| 266 | address no wait was ever met for, until a gate cut short is met within its 4 ms; a wait cut short that memory | 266 | layer holds behind a gate, a relayed wait or a title fence is not running). Then, for a queue's first held gate: |
| 267 | meets within the rest of the full timeout gives its address the full timeout from then on. | 267 | - **cycle**: what would write its value is held behind a gate that depends, through further held writes, on its |
| 268 | `LEONIDA_LIST_VALUES=0` drops both methods, as before. After `stop_list_values` (the process is ending) nothing | 268 | own queue: released at once; |
| 269 | new is landed or opened. | 269 | - **present**: the title has presented since the gate was held (the present stands behind the held work): the |
| 270 | oldest gate that no held write could meet goes; a gate whose writer is held behind another queue's gate waits for | ||
| 271 | that one, so a chain unwinds in order; | ||
| 272 | - **stalled**: the title has made no queue call for 2 s and the gate has stood as long: its threads wait for the | ||
| 273 | held work (a deadlock through the title's CPU). | ||
| 274 | At device loss every gate goes. Each release is logged with the gate, its queue, the wait (address, comparison, | ||
| 275 | reference, memory) and the reason; a released wait is then watched for 10 s and, if memory meets it, counted and | ||
| 276 | logged with how much later (`met after release`). The periodic `list values so far` line counts gates held, met and | ||
| 277 | released unmet by reason, and names the oldest gate still held. The rule follows VIctory-Belobug-AMD's queue line | ||
| 278 | (`crates/victory-gpu/src/queue/behind.rs` `step`, `queue.rs` `release_held`: a held wait is forced only at a present | ||
| 279 | with nothing else runnable). The fixed 200 ms timeout (`LEONIDA_VALUE_WAIT_TIMEOUT_MS`) and its 4 ms demotions are | ||
| 280 | gone: at the slow frames of a Linux world run (seconds a frame), 14-63 gates per run timed out with memory one | ||
| 281 | step below a rising reference, the writer's value not there yet. `LEONIDA_LIST_VALUES=0` drops both methods, as | ||
| 282 | before. After `stop_list_values` (the process is ending) nothing new is landed or opened, and a held gate does not | ||
| 283 | delay it. | ||
| 270 | - Queue slot 31 (`CopyPageMappingsBatchX`, section 4) waits at most 16 ms for the queue's earlier work. Work held | 284 | - Queue slot 31 (`CopyPageMappingsBatchX`, section 4) waits at most 16 ms for the queue's earlier work. Work held |
| 271 | behind a gate takes longer: the remap is then deferred to the releaser, which runs it once the queue's write | 285 | behind a gate takes longer: the remap is then deferred to the releaser, which runs it once the queue's write |
| 272 | fence passes the call's point and only then opens a gate the queue's later work waits on, so the GPU sees the | 286 | fence passes the call's point and only then opens a gate the queue's later work waits on, so the GPU sees the |
diff --git a/docs/d3d12_xs_surface.md b/docs/d3d12_xs_surface.md index 460b50d29..753529f98 100644 --- a/docs/d3d12_xs_surface.md +++ b/docs/d3d12_xs_surface.md | |||
| @@ -687,7 +687,7 @@ Mesa are public code compiled against the GDK headers, and docs.xbox.com is Micr | |||
| 687 | | Device frame calls | Slots **78** `SetFrameIntervalX`, **79** `ScheduleFrameEventX`, **80** `WaitFrameEventX`, **81** `GetFrameStatisticsX` (0-based, `QueryInterface` = 0). XCL's [`frame.rs`](https://github.com/ivall/xcl/blob/95bda116cfc1b118156901984052ff5698dbf4cc/crates/xcl/src/hle/d3d12x/frame.rs) numbers the calls and documents the arguments; ebiten's `ID3D12Device` vtable has `SetFrameIntervalX`/`ScheduleFrameEventX`/`WaitFrameEventX` at 78/79/80 and leaves 81 unnamed ([`d3d12_windows.go`](https://github.com/hajimehoshi/ebiten/blob/d438df689b19544c82543ad522b36be86a5a60b7/internal/graphicsdriver/directx/d3d12_windows.go)). | **Confirms** all four slots, two independent public sources. | | 687 | | Device frame calls | Slots **78** `SetFrameIntervalX`, **79** `ScheduleFrameEventX`, **80** `WaitFrameEventX`, **81** `GetFrameStatisticsX` (0-based, `QueryInterface` = 0). XCL's [`frame.rs`](https://github.com/ivall/xcl/blob/95bda116cfc1b118156901984052ff5698dbf4cc/crates/xcl/src/hle/d3d12x/frame.rs) numbers the calls and documents the arguments; ebiten's `ID3D12Device` vtable has `SetFrameIntervalX`/`ScheduleFrameEventX`/`WaitFrameEventX` at 78/79/80 and leaves 81 unnamed ([`d3d12_windows.go`](https://github.com/hajimehoshi/ebiten/blob/d438df689b19544c82543ad522b36be86a5a60b7/internal/graphicsdriver/directx/d3d12_windows.go)). | **Confirms** all four slots, two independent public sources. | |
| 688 | | `D3D12XBOX_FRAME_STATISTICS` | The MIT FramePacing sample names `Type`, `Interval`, `Event`, `Render`/`Present`/`Display` with `PlaneIndex`, and `Display.PercentScanned`; it treats `S_FALSE` or a count below the request as "not available yet" ([`FramePacing.cpp`](https://github.com/microsoft/Xbox-GDK-Samples/blob/b1e77b6ac10f95b07296025fda171ca2ddc42dbe/Samples/Graphics/FramePacing/FramePacing.cpp)). XCL's implementation writes `Type` at +0, origin at +0x10 and flip at +0x18, so its record is at least 0x20 bytes ([`frame.rs`](https://github.com/ivall/xcl/blob/95bda116cfc1b118156901984052ff5698dbf4cc/crates/xcl/src/hle/d3d12x/frame.rs)). | **Partly confirms** the field meanings and the two timestamp offsets; the full record layout and the union members stay unmeasured. | | 688 | | `D3D12XBOX_FRAME_STATISTICS` | The MIT FramePacing sample names `Type`, `Interval`, `Event`, `Render`/`Present`/`Display` with `PlaneIndex`, and `Display.PercentScanned`; it treats `S_FALSE` or a count below the request as "not available yet" ([`FramePacing.cpp`](https://github.com/microsoft/Xbox-GDK-Samples/blob/b1e77b6ac10f95b07296025fda171ca2ddc42dbe/Samples/Graphics/FramePacing/FramePacing.cpp)). XCL's implementation writes `Type` at +0, origin at +0x10 and flip at +0x18, so its record is at least 0x20 bytes ([`frame.rs`](https://github.com/ivall/xcl/blob/95bda116cfc1b118156901984052ff5698dbf4cc/crates/xcl/src/hle/d3d12x/frame.rs)). | **Partly confirms** the field meanings and the two timestamp offsets; the full record layout and the union members stay unmeasured. | |
| 689 | | Token and timeout | `D3D12XBOX_FRAME_PIPELINE_TOKEN` is a 64-bit integer with 0 as `..._NULL` (ebiten). Microsoft's Game Streaming page says `WaitFrameEventX` returns the token at frame start and `PresentX` sends it with the frame to the client ([Learn](https://learn.microsoft.com/en-us/gaming/gdk/docs/features/common/game-streaming/game-streaming-latency-compensation-deep-dive)). XCL's implementation issues 48-bit nonzero tokens (mask `0xFFFF_FFFF_FFFF`), i.e. it leaves the top 16 bits unused, returns `S_FALSE` on a finite timeout, writes the token on timeout only with flag 2, and returns `E_INVALIDARG` for an unscheduled event; `ScheduleFrameEventX` returns `S_FALSE` or `0x10000000` when it starts the clock. | **Confirms** the 64-bit storage and the `0` null. **Contradicts** this layer's `HRESULT_FROM_WIN32(WAIT_TIMEOUT)` on timeout (XCL: `S_FALSE`) and `ERROR_INVALID_STATE` for an unscheduled event (XCL: `E_INVALIDARG`); both are recorded here, not changed in this PR. The 48-bit range is XCL's implementation choice, not a documented mask. | | 689 | | Token and timeout | `D3D12XBOX_FRAME_PIPELINE_TOKEN` is a 64-bit integer with 0 as `..._NULL` (ebiten). Microsoft's Game Streaming page says `WaitFrameEventX` returns the token at frame start and `PresentX` sends it with the frame to the client ([Learn](https://learn.microsoft.com/en-us/gaming/gdk/docs/features/common/game-streaming/game-streaming-latency-compensation-deep-dive)). XCL's implementation issues 48-bit nonzero tokens (mask `0xFFFF_FFFF_FFFF`), i.e. it leaves the top 16 bits unused, returns `S_FALSE` on a finite timeout, writes the token on timeout only with flag 2, and returns `E_INVALIDARG` for an unscheduled event; `ScheduleFrameEventX` returns `S_FALSE` or `0x10000000` when it starts the clock. | **Confirms** the 64-bit storage and the `0` null. **Contradicts** this layer's `HRESULT_FROM_WIN32(WAIT_TIMEOUT)` on timeout (XCL: `S_FALSE`) and `ERROR_INVALID_STATE` for an unscheduled event (XCL: `E_INVALIDARG`); both are recorded here, not changed in this PR. The 48-bit range is XCL's implementation choice, not a documented mask. | |
| 690 | | `D3D12XBOX_CREATE_DEVICE_PARAMETERS` | Public field names and (for ebiten's version) x64 offsets: `Version` @0, `ProcessDebugFlags` @4, `GraphicsCommandQueueRingSizeBytes` @8, `pOffchipTessellationBuffer` @0x10, `GraphicsScratchMemorySizeBytes` @0x18, `ComputeScratchMemorySizeBytes` @0x1C, `DisableGeometryShaderAllocations` @0x20, `DisableTessellationShaderAllocations` @0x24, `DisableDXR` @0x28, `DisableAutomaticDPBBBreakBatchEvents` @0x2C, `pDXRStackBuffer` @0x30, `DXRStackBufferOverrideSizeBytes` @0x38, `CreateDeviceFlags` @0x3C, `AutoHDRPaperWhiteLevelNits` @0x40, `DisableAutomaticCommandSegmentChaining` @0x44 ([`d3d12_windows.go`](https://github.com/hajimehoshi/ebiten/blob/d438df689b19544c82543ad522b36be86a5a60b7/internal/graphicsdriver/directx/d3d12_windows.go)). The MIT samples add `AmplificationShaderIndirectArgsBufferSize` and `AmplificationShaderPayloadBufferSize` by name ([`SimpleDeviceAndSwapChain.cpp`](https://github.com/microsoft/Xbox-GDK-Samples/blob/b1e77b6ac10f95b07296025fda171ca2ddc42dbe/Samples/IntroGraphics/SimpleDeviceAndSwapChain/SimpleDeviceAndSwapChain.cpp)). | **Partly confirms.** Seventeen named fields cover the first 18 words (word 3 is the x64 alignment pad at 0x0C); the samples name two more fields without a public layout. A 24-word (96-byte) block still has at least four words with no public name or meaning. | | 690 | | `D3D12XBOX_CREATE_DEVICE_PARAMETERS` | Public field names and (for ebiten's version) x64 offsets: `Version` @0, `ProcessDebugFlags` @4, `GraphicsCommandQueueRingSizeBytes` @8, `pOffchipTessellationBuffer` @0x10, `GraphicsScratchMemorySizeBytes` @0x18, `ComputeScratchMemorySizeBytes` @0x1C, `DisableGeometryShaderAllocations` @0x20, `DisableTessellationShaderAllocations` @0x24, `DisableDXR` @0x28, `DisableAutomaticDPBBBreakBatchEvents` @0x2C, `pDXRStackBuffer` @0x30, `DXRStackBufferOverrideSizeBytes` @0x38, `CreateDeviceFlags` @0x3C, `AutoHDRPaperWhiteLevelNits` @0x40, `DisableAutomaticCommandSegmentChaining` @0x44 ([`d3d12_windows.go`](https://github.com/hajimehoshi/ebiten/blob/d438df689b19544c82543ad522b36be86a5a60b7/internal/graphicsdriver/directx/d3d12_windows.go)). The MIT samples add `AmplificationShaderIndirectArgsBufferSize` and `AmplificationShaderPayloadBufferSize` by name ([`SimpleDeviceAndSwapChain.cpp`](https://github.com/microsoft/Xbox-GDK-Samples/blob/b1e77b6ac10f95b07296025fda171ca2ddc42dbe/Samples/IntroGraphics/SimpleDeviceAndSwapChain/SimpleDeviceAndSwapChain.cpp)). | **Partly confirms.** Seventeen named fields cover the first 18 words (word 3 is the x64 alignment pad at 0x0C); the samples name two more fields without a public layout. At the one retail call site the block is 0x50 bytes (20 dwords typified by the field list), so the two dwords at 0x48 and 0x4C are the ones with no public name, and both are zero there. | |
| 691 | | Root-signature flags `0x03000000` | Not documented: the [graphics index](https://docs.xbox.com/_llms/en/apis/gdk-apis/graphics-api-reference.txt) has no `D3D12_ROOT_SIGNATURE_FLAGS` entry, and both URL forms under `docs.xbox.com/reference/graphics/` (`d3d12` and `d3d12_xs`) return 404. | **Leaves provisional.** Keep masking the byte on a copy; no public bit meaning. | | 691 | | Root-signature flags `0x03000000` | Not documented: the [graphics index](https://docs.xbox.com/_llms/en/apis/gdk-apis/graphics-api-reference.txt) has no `D3D12_ROOT_SIGNATURE_FLAGS` entry, and both URL forms under `docs.xbox.com/reference/graphics/` (`d3d12` and `d3d12_xs`) return 404. | **Leaves provisional.** Keep masking the byte on a copy; no public bit meaning. | |
| 692 | | `CheckFeatureSupport(D3D12_OPTIONS)` with 0x40 bytes | Microsoft publishes the 15-field PC structure, 0x3C bytes, with no extra member ([`D3D12_FEATURE_DATA_D3D12_OPTIONS`](https://docs.xbox.com/reference/graphics/d3d12/structs/d3d12_feature_data_d3d12_options_public.md)); its `CheckFeatureSupport` page says a size mismatch is `E_INVALIDARG` ([`CheckFeatureSupport`](https://docs.xbox.com/reference/graphics/d3d12/interfaces/id3d12device/methods/id3d12device_checkfeaturesupport_public.md)). XCL measured XDefiant asking 0x40 and retries with 0x3C, zeroing the tail ([`HANDOFF.md`](https://github.com/ivall/xcl/blob/95bda116cfc1b118156901984052ff5698dbf4cc/HANDOFF.md), [`real.rs`](https://github.com/ivall/xcl/blob/95bda116cfc1b118156901984052ff5698dbf4cc/crates/xcl/src/hle/d3d12x/real.rs)). | **Confirms the 0x40 request size; leaves the extra 4 bytes unknown.** The measurement fixes the size, not the field. No public source names them; `MaxGPUVirtualAddressBitsPerProcess` is a member of the separate `D3D12_FEATURE_DATA_GPU_VIRTUAL_ADDRESS_SUPPORT`, not a published member of `D3D12_OPTIONS`. The repository's accept-and-zero-tail behaviour matches the observed failure and is safe. | | 692 | | `CheckFeatureSupport(D3D12_OPTIONS)` with 0x40 bytes | Microsoft publishes the 15-field PC structure, 0x3C bytes, with no extra member ([`D3D12_FEATURE_DATA_D3D12_OPTIONS`](https://docs.xbox.com/reference/graphics/d3d12/structs/d3d12_feature_data_d3d12_options_public.md)); its `CheckFeatureSupport` page says a size mismatch is `E_INVALIDARG` ([`CheckFeatureSupport`](https://docs.xbox.com/reference/graphics/d3d12/interfaces/id3d12device/methods/id3d12device_checkfeaturesupport_public.md)). XCL measured XDefiant asking 0x40 and retries with 0x3C, zeroing the tail ([`HANDOFF.md`](https://github.com/ivall/xcl/blob/95bda116cfc1b118156901984052ff5698dbf4cc/HANDOFF.md), [`real.rs`](https://github.com/ivall/xcl/blob/95bda116cfc1b118156901984052ff5698dbf4cc/crates/xcl/src/hle/d3d12x/real.rs)). | **Confirms the 0x40 request size; leaves the extra 4 bytes unknown.** The measurement fixes the size, not the field. No public source names them; `MaxGPUVirtualAddressBitsPerProcess` is a member of the separate `D3D12_FEATURE_DATA_GPU_VIRTUAL_ADDRESS_SUPPORT`, not a published member of `D3D12_OPTIONS`. The repository's accept-and-zero-tail behaviour matches the observed failure and is safe. | |
| 693 | 693 | ||
| @@ -792,7 +792,7 @@ evidence. | |||
| 792 | 792 | ||
| 793 | | Leonida unknown | Status after SCARAB (and §7.1) | What is actually new | | 793 | | Leonida unknown | Status after SCARAB (and §7.1) | What is actually new | |
| 794 | |---|---|---| | 794 | |---|---|---| |
| 795 | | #1 device entry point and 24-word params | **described** | The separate console device export exists at ordinal 13 and is named `D3D12ConsCreateDevice` internally / `D3D12XboxCreateDevice` publicly; the params struct is named `D3D12CONS_CREATE_DEVICE_PARAMETERS`. Public sources name 17 fields and their x64 offsets, plus two more field names; a 24-word block still has at least four words unaccounted (§7.1). | | 795 | | #1 device entry point and 0x50-byte params | **described** | The separate console device export exists at ordinal 13 and is named `D3D12ConsCreateDevice` internally / `D3D12XboxCreateDevice` publicly; the params struct is named `D3D12CONS_CREATE_DEVICE_PARAMETERS`. Public sources name 17 fields and their x64 offsets, plus two more field names; the block measures 0x50 bytes (20 dwords) at the one retail call site, so the two dwords at 0x48/0x4C are the ones left unnamed (§7.1). | |
| 796 | | #2 device/heap/queue/command-list slots | **partly measured** | §5.2 measures the arity and receiver of device slots 86, 101, 108, 132 and 133 (86, 101, 108 and 133 match the routes in [d3d12_vulkan.md](d3d12_vulkan.md) §3.1 and [retail_boot_chain.md](retail_boot_chain.md) §3.4); offset `+0x418` (131) has no device receiver, so it stays open. SCARAB has no console slot map. Its appended-after-GCL6 model conflicts with the SDK's GCL8/GCL9 methods (§5.1). Public §7.1 gives the presentation slots (device 78-81, queue 30/32); the heap and command-list slot map is still unknown. Do not use SCARAB as a slot source. | | 796 | | #2 device/heap/queue/command-list slots | **partly measured** | §5.2 measures the arity and receiver of device slots 86, 101, 108, 132 and 133 (86, 101, 108 and 133 match the routes in [d3d12_vulkan.md](d3d12_vulkan.md) §3.1 and [retail_boot_chain.md](retail_boot_chain.md) §3.4); offset `+0x418` (131) has no device receiver, so it stays open. SCARAB has no console slot map. Its appended-after-GCL6 model conflicts with the SDK's GCL8/GCL9 methods (§5.1). Public §7.1 gives the presentation slots (device 78-81, queue 30/32); the heap and command-list slot map is still unknown. Do not use SCARAB as a slot source. | |
| 797 | | #3 root signature → `s0..s31` | **still unknown** | Only flag names (`D3D12CONS_ROOT_SIGNATURE_FLAG_FORCE_MEMORY_BASED_ABI`, `_RAYTRACING`); no mapping. Leonida's own register-based/spill facts already go further. | | 797 | | #3 root signature → `s0..s31` | **still unknown** | Only flag names (`D3D12CONS_ROOT_SIGNATURE_FLAG_FORCE_MEMORY_BASED_ABI`, `_RAYTRACING`); no mapping. Leonida's own register-based/spill facts already go further. | |
| 798 | | #4 descriptor bytes and increments | **still unknown** | No measured increment. `D3D12CONS_DESCRIPTOR_HEAP_TYPE_SAMPLER_UNBOUNDED` is a new name, not a size. | | 798 | | #4 descriptor bytes and increments | **still unknown** | No measured increment. `D3D12CONS_DESCRIPTOR_HEAP_TYPE_SAMPLER_UNBOUNDED` is a new name, not a size. | |
diff --git a/docs/descriptor_lookup_ampere.md b/docs/descriptor_lookup_ampere.md new file mode 100644 index 000000000..440d7ec06 --- /dev/null +++ b/docs/descriptor_lookup_ampere.md | |||
| @@ -0,0 +1,68 @@ | |||
| 1 | # Descriptor lookup cost on NVIDIA RTX 3070 (Ampere) | ||
| 2 | |||
| 3 | Divergent lookups in host-visible system RAM showed a steep cliff once the table reached 100,000 entries on this PCIe 3.0 x16 Ampere card with Resizable BAR off. On the GPU-only memory type, one million logical lane lookups took 270.3 µs at 1,000 live descriptors, 773.3 µs at 10,000 and 2,502.6 µs at 100,000 for divergent misses, and 73.0, 94.3 and 231.9 µs for divergent texture hits. The 214 MiB BAR1 memory type (`DEVICE_LOCAL | HOST_VISIBLE | HOST_COHERENT`, exposed even with Resizable BAR disabled) stayed within 0.5% of GPU-only in every cell across all three sizes. By contrast, host-visible memory outside VRAM stayed within 10% of GPU-only at 1,000 entries and within 16% at 10,000, but at 100,000 entries it was 5.0× slower for uniform texture hits, 14.2× slower for divergent texture hits, 21.9× slower for divergent T#+S# pairs and 22.6× slower for divergent misses. These are synthetic compute results from one GeForce RTX 3070 on an idle Windows 11 desktop with NVIDIA driver 621.24. The benchmark ran unchanged at `5d74c27` (with the current default `--warmup-ms 300`). | ||
| 4 | |||
| 5 | ## Measurements | ||
| 6 | |||
| 7 | Each cell is gross GPU time in **µs per million logical lane lookups**, including key reads and result accumulation. The benchmark also prints a figure with a key-read baseline subtracted (summarised below). The table uses its gross column so it compares directly with the [RTX 4070 SUPER (Ada) run](descriptor_lookup_ada.md). | ||
| 8 | |||
| 9 | | Live descriptors | Memory type | Uniform T# hit | Uniform S# hit | Divergent T# hit | Divergent T#+S# pair | Divergent miss | | ||
| 10 | |---:|:---|---:|---:|---:|---:|---:| | ||
| 11 | | 1,000 | GPU-only | 15.0 | 15.1 | 73.0 | 68.2 | 270.3 | | ||
| 12 | | 1,000 | Host-visible | 16.5 | 16.4 | 71.3 | 69.9 | 267.6 | | ||
| 13 | | 1,000 | BAR1 (`host_device_local`) | 15.0 | 15.1 | 73.0 | 68.2 | 270.3 | | ||
| 14 | | 10,000 | GPU-only | 15.5 | 15.0 | 94.3 | 115.9 | 773.3 | | ||
| 15 | | 10,000 | Host-visible | 16.8 | 17.0 | 104.4 | 134.4 | 880.7* | | ||
| 16 | | 10,000 | BAR1 (`host_device_local`) | 15.5 | 15.0 | 94.4 | 115.4 | 771.7 | | ||
| 17 | | 100,000 | GPU-only | 21.7 | 15.7 | 231.9 | 216.6 | 2,502.6 | | ||
| 18 | | 100,000 | Host-visible | 108.0 | 18.4 | 3,290.5 | 4,734.5 | 56,519.6* | | ||
| 19 | | 100,000 | BAR1 (`host_device_local`) | 21.7 | 15.8 | 231.8 | 216.7 | 2,499.3 | | ||
| 20 | |||
| 21 | \* Shortened by the benchmark's Windows timeout guard in all 12 rounds (see Method). | ||
| 22 | |||
| 23 | Net timings (after subtracting the matching key-read baseline) at 100,000 entries were: GPU-only `14.6`, `8.6`, `207.6`, `204.5`, `2,478.3`; BAR1 `14.6`, `8.6`, `207.5`, `204.6`, `2,475.1`; Host-visible `101.0`, `11.5`, `3,265.5`, `4,722.4`, `56,495.1*` µs per million. | ||
| 24 | |||
| 25 | At 100,000 entries on type 1 (GPU-only), a divergent T# dispatch took 3.89 ms, a T#+S# dispatch took 7.27 ms and a divergent miss dispatch took 41.99 ms. Each paired iteration resolves two descriptors. | ||
| 26 | |||
| 27 | GPU-only is type 1, `DEVICE_LOCAL`, on heap 0 (8,018 MiB). Host-visible is type 3, `HOST_VISIBLE | HOST_COHERENT` without `HOST_CACHED`, on heap 1 (16,345 MiB, not device-local). BAR1 (`host_device_local`, selected by `--memory rebar`) is type 5, `DEVICE_LOCAL | HOST_VISIBLE | HOST_COHERENT`, on heap 2 (214 MiB). Resizable BAR was **off**: `nvidia-smi` reported a 256 MiB BAR1 aperture (227 MiB used, 29 MiB free at idle), and every allocation on type 5 still succeeded up to the 20.0 MiB table. On this card, keeping the descriptor table out of non-device-local host-visible RAM matters far more at 100,000 entries than on the [Ada PCIe 4.0 + ReBAR card](descriptor_lookup_ada.md) (14.2×–22.6× penalty on divergent traffic here vs 1.45×–2.5× there), while the 214 MiB BAR1 heap remained within 0.5% of GPU-only VRAM in every cell whenever the table fit inside it. | ||
| 28 | |||
| 29 | At 100,000 entries on GPU-only and BAR1, the 12 round medians split deterministically by which table size ran first in the process: the four rounds that started with 1,000 entries (rounds 1, 5, 8 and 12) measured 167.4–167.9 µs per million for divergent T# hits and 1,791.5–1,791.9 for divergent misses; the four that started with 10,000 entries (rounds 3, 6, 7 and 10) measured 231.8–232.1 and 2,498.4–2,505.4; and the four that started with 100,000 entries (rounds 2, 4, 9 and 11) measured 232.2–232.9 and 2,581.9–2,591.8. The table medians follow the eight rounds that did not start at 1,000 entries. The cause was not measured. | ||
| 30 | |||
| 31 | The tables contain 90% T# texture keys and 10% S# sampler keys. Their allocations were 163,844, 2,621,444 and 20,971,524 bytes (0.156, 2.50 and 20.0 MiB). The capacities were 4,096, 65,536 and 524,288 slots, at 24.4%, 15.3% and 19.1% load. At 100,000 entries the ordinary uniform hit runs covered all 90,000 textures or all 10,000 samplers. Each workgroup shared a key for each iteration. The separate hot-key control (`uniform_hot_tsharp`) reused one texture and measured 12.8–13.1 µs per million gross (5.7–6.8 µs net) across all three memory types and sizes. Divergent misses visited 1,024, 16,384 and 131,072 distinct absent keys across the three sizes. Cache residency and memory traffic were unmeasured. | ||
| 32 | |||
| 33 | ## Method and replay | ||
| 34 | |||
| 35 | Each dispatch used 4,096 groups of 64 lanes and 64 iterations. The RTX 3070 reported 32-lane subgroups (`minSubgroupSize = maxSubgroupSize = 32`). The denominator was 16,777,216 logical lookups per single-key dispatch and 33,554,432 per paired dispatch, counting the texture and sampler separately. Vulkan timestamps bracketed one dispatch. The compute queue advertised 64 valid bits and a 1 ns tick period. | ||
| 36 | |||
| 37 | Each cell is the median of 12 process medians, each from 25 timed dispatches after five warmups plus the default `--warmup-ms 300` clock-warmup window (TEST-277). The 11 scenarios ran in the benchmark's fixed order. There were 36 processes: three memory types in each of 12 rounds. Across them there were 29,124 timed dispatches. Every process exited 0, wrote nothing to stderr and reported `timing_status` `ok` on all 1,188 rows. The run used the default Windows Vulkan loader with validation layers off and `DISABLE_RTSS_LAYER=1` and `DISABLE_VULKAN_OBS_CAPTURE=1` set to keep overlay layers out of the run; desktop GPU utilization at idle was 2% (993 MiB VRAM used, P5). | ||
| 38 | |||
| 39 | As in the [Ada run](descriptor_lookup_ada.md), this run kept the default `--max-dispatch-ms 120` guard to stay clear of the Windows 2 s GPU timeout (TDR). Only host-visible cells were shortened, all 12 of 12 rounds: at 10,000 entries, `divergent_miss` ran with 13–26 iterations (median dispatch 4.38 ms, range 1.60–6.37 ms); at 100,000 entries, `divergent_miss` ran with 19 iterations in all 12 rounds (median dispatch 281.51 ms, range 276.11–285.21 ms) and `latency_divergent` (outside the summary table; gross median 8,135.0 µs per million) ran with 26 iterations in all 12 rounds (median dispatch 55.45 ms, range 47.57–56.15 ms). | ||
| 40 | |||
| 41 | From a Leonida checkout on Windows, with Visual Studio C++ tools, CMake + Ninja, Windows SDK 10.0.26100+ and Vulkan headers (`VULKAN_SDK` or `-DLEONIDA_VULKAN_HEADERS_FETCH=ON`): | ||
| 42 | |||
| 43 | ```powershell | ||
| 44 | runtime\build\vk_descriptor_bench.exe --list-devices | ||
| 45 | runtime\build\vk_descriptor_bench.exe --self-test | ||
| 46 | $env:DISABLE_RTSS_LAYER = "1" | ||
| 47 | $env:DISABLE_VULKAN_OBS_CAPTURE = "1" | ||
| 48 | foreach ($memory in 'device', 'host', 'rebar') { | ||
| 49 | runtime\build\vk_descriptor_bench.exe --device 0 --memory $memory --sizes 1000,10000,100000 ` | ||
| 50 | --groups 4096 --iters 64 --warmup 5 --reps 25 --warmup-ms 300 --csv | ||
| 51 | } | ||
| 52 | ``` | ||
| 53 | |||
| 54 | Device 0 was the RTX 3070, the only Vulkan device. For the full 12-round series, let A, B and C denote 1k, 10k and 100k. The rounds used the same size orders and starting memory types as the [M3 Max](descriptor_lookup_apple.md) and [Ada](descriptor_lookup_ada.md) runs: the first six size orders were ABC, CBA, BAC, CAB, ACB and BCA, starting with `device`, `host`, `device`, `device`, `host` and `host` respectively; the next six reversed the sequence of rounds and swapped the starting memory type in each, with `rebar` third in every round. | ||
| 55 | |||
| 56 | ## System | ||
| 57 | |||
| 58 | | | | | ||
| 59 | |:---|:---| | ||
| 60 | | GPU | NVIDIA GeForce RTX 3070 (Ampere), 8,192 MiB (discrete) | | ||
| 61 | | PCI id | `0x10de:0x2488`, subsystem `0x404e1458` | | ||
| 62 | | Link | PCIe 3.0 x16 (current and maximum reported by `nvidia-smi`; B450 AORUS M) | | ||
| 63 | | Resizable BAR | Off (BAR1 aperture 256 MiB, `nvidia-smi -q -d MEMORY`; Vulkan heap 2 reports 214 MiB `DEVICE_LOCAL \| HOST_VISIBLE \| HOST_COHERENT`) | | ||
| 64 | | Subgroup size | 32 | | ||
| 65 | | Driver | NVIDIA 621.24 (`nvidia-smi`), Vulkan API 1.4.357 | | ||
| 66 | | OS | Windows 11 Pro 26H2, build 26300.9974 | | ||
| 67 | | Vulkan headers | 1.4.363.0 (`-DLEONIDA_VULKAN_HEADERS_FETCH=ON`) | | ||
| 68 | | Compiler | Visual Studio 18 Professional (MSVC 19.51.36260.0), `RelWithDebInfo` via CMake + Ninja | | ||
diff --git a/docs/design.md b/docs/design.md index 621338f51..5dd3f33d0 100644 --- a/docs/design.md +++ b/docs/design.md | |||
| @@ -300,9 +300,9 @@ How the generated SPIR-V expects the runtime to work: | |||
| 300 | |---|---| | 300 | |---|---| |
| 301 | | Heap-relative buffer device addresses | `Gen.host_addr` sign-extends the low 48 bits of the effective VA after adding any byte offset, then adds `%heap_base`. The runtime stores `device_address - heap_base` in a V#'s 48-bit base field. NVIDIA's Windows driver can place an imported buffer below the heap, so that offset is negative. Zero extension made the resulting device address too high by `2^48`. Console user-mode VAs below `2^47` and full-width root descriptor addresses already within the signed 48-bit range retain their values. A 64-bit base-plus-offset sum gives the correct address for effective VAs in that range, including when the sum crosses zero. Each new shader's `index.json` entry carries `"vsharp_base_sign_extended": true`. Check the field on all loaded entries before enabling below-arena imports for a library, because older modules can share an index with newly translated ones. `tests/semantic/test_vsharp_sext48.py` checks the emitted shifts, both reads against synthetic memory, and the metadata field. | | 301 | | Heap-relative buffer device addresses | `Gen.host_addr` sign-extends the low 48 bits of the effective VA after adding any byte offset, then adds `%heap_base`. The runtime stores `device_address - heap_base` in a V#'s 48-bit base field. NVIDIA's Windows driver can place an imported buffer below the heap, so that offset is negative. Zero extension made the resulting device address too high by `2^48`. Console user-mode VAs below `2^47` and full-width root descriptor addresses already within the signed 48-bit range retain their values. A 64-bit base-plus-offset sum gives the correct address for effective VAs in that range, including when the sum crosses zero. Each new shader's `index.json` entry carries `"vsharp_base_sign_extended": true`. Check the field on all loaded entries before enabling below-arena imports for a library, because older modules can share an index with newly translated ones. `tests/semantic/test_vsharp_sext48.py` checks the emitted shifts, both reads against synthetic memory, and the metadata field. | |
| 302 | | Null sources in 64-bit integer VALU compares | `v_cmp` and `v_cmpx` relations `eq`, `ne`, `lt`, `le`, `gt`, `ge` on `u64` and `i64` read `null` as the 64-bit value 0 in either source, like immediate `0`. Register pairs and immediates retain their existing semantics; `v_cmp` writes the active lane's comparison to VCC/SGPR, while `v_cmpx` narrows EXEC without changing VCC. Source: RDNA2 ISA special operand `null` reads zero; LLVM `llvm-mc -mcpu=gfx1013` accepts the encoding. CPU-checked by `tests/semantic/test_vcmp64_null_src.py` (both sources, signed/unsigned ordering, equality, e32/e64, EXEC and inactive lanes); **not GPU-verified, no corpus count**. | | 302 | | Null sources in 64-bit integer VALU compares | `v_cmp` and `v_cmpx` relations `eq`, `ne`, `lt`, `le`, `gt`, `ge` on `u64` and `i64` read `null` as the 64-bit value 0 in either source, like immediate `0`. Register pairs and immediates retain their existing semantics; `v_cmp` writes the active lane's comparison to VCC/SGPR, while `v_cmpx` narrows EXEC without changing VCC. Source: RDNA2 ISA special operand `null` reads zero; LLVM `llvm-mc -mcpu=gfx1013` accepts the encoding. CPU-checked by `tests/semantic/test_vcmp64_null_src.py` (both sources, signed/unsigned ordering, equality, e32/e64, EXEC and inactive lanes); **not GPU-verified, no corpus count**. | |
| 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); **GPU-checked** with the synthetic `runtime/test/shaders/cs_smem_vcc_base.asm`, which reads back the eight seeded words through the pair in the standard GPU runner (`0x7210..0x7217`): on an AMD Radeon gfx1036 iGPU (Ryzen 7 7800X3D, Windows 11, driver 32.0.21045.29003) and, under `LEONIDA_W64_EMULATE=1`, on an NVIDIA GeForce RTX 4090 (Windows 11, driver 32.0.16.2124); without the emulation the fixture skips on the 4090 (no 64-wide compute subgroup). Still not measured: those eight words of one fixture are the whole hardware check, the 79-program corpus count stays a translation count, and there is no native 32-wide-subgroup run of this form. | |
| 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. Out-of-row `in_bounds` clamps `safe_sg` to own subgroup lane `sgl` (never constant lane 0). For native FI=0, the active-lane ballot bit selects the shuffle index (`OpSelect(bit, safe_sg, sgl)`); for native FI=1 on a VGPR source, a `%true` present-lane ballot bit similarly redirects unlaunched/absent lanes in a partial subgroup to `sgl` (treating absent lanes as invalid while still fetching EXEC-off launched lanes). CPU-checked by `tests/semantic/test_dpp_eager_subgroup.py` and `tests/semantic/test_absent_lane_ub.py`, and GPU-checked on a Radeon gfx1036 RDNA2 iGPU (RADV, `tests/test_absent_lane_gpu.py`, partial 5-thread CS and 1×1 PS with `LEONIDA_VK_VALIDATION=1`). 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 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`). | | 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). Under `--wave64-emulate` too: a round ends a segment only at a cross-lane exchange, a barrier or a memory-ordering point, none of which a lane-local instruction is, so a run never crosses a segment boundary (`Gen.insns` checks this). Checked by `tests/semantic/test_active_runs.py` (`EmulatedWave64ActiveRuns` for the emulated form). | | 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). Under `--wave64-emulate` too: a round ends a segment only at a cross-lane exchange, a barrier or a memory-ordering point, none of which a lane-local instruction is, so a run never crosses a segment boundary (`Gen.insns` checks this). Checked by `tests/semantic/test_active_runs.py` (`EmulatedWave64ActiveRuns` for the emulated form). | |
| 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. | |
| @@ -322,14 +322,16 @@ How the generated SPIR-V expects the runtime to work: | |||
| 322 | | 8/16-bit global stores and d16 loads | `global_store_byte`/`short` write the low 8/16 bits of the data VGPR (the `_d16_hi` forms its high half). `global_load_{u,s}byte_d16` and `global_load_short_d16` write the low 16 bits of `vdst` (the `_hi` forms the high 16) and keep the other half; `ubyte` zero-extends and `sbyte` sign-extends the byte to 16 bits. The address is the `global_load/store` one (`Gen.global_address`). The access goes one byte at a time, so a 16-bit access that crosses a dword (at byte 3) is exact too. A store merges each byte into its dword with atomic and/or, which keeps neighbouring bytes even when another lane writes them, as buffer byte stores do. A load reads each byte. Inactive lanes neither store nor load. The first-read analysis counts a d16 load's `vdst` as read, for the half it keeps. `global_load/store_dword_addtid` (lane-id and M0 addressing) raise `Unsupported`; until 2026-11-22 they crashed with `IndexError`, and the ten sub-dword ops raised `Unsupported`. CPU-checked by `tests/semantic/test_global_sub_dword.py` (every byte offset 0 to 7 for each op, an inactive lane, rejected forms, the first-read analysis). **Hardware-measured natively on `gfx1100`** (RX 7900 XTX, driver 26.10.1) with `tools/hw_oracle`, 16 cases that use the output buffer as scratch memory (seven stores, nine d16 loads), all matching: `b8`/`b16` change only the addressed bytes (`0x11223344` with `0xbeef` stored at offset 2 reads back `0xbeef3344`), `_d16_hi` stores take the data VGPR's high half (`0x12340000` at offset 0 gives `0x11221234`), a 16-bit store at offset 3 splits across the dword exactly (`0xfe223344` then `0x556677ca`), `ubyte`/`sbyte` d16 loads fill the low 16 bits of `vdst` and keep the other half (`0x85` gives `0xbeefff85` from a `0xbeef0000` vdst, `0x7f` gives `0xbeef007f`), `short`/`short_hi` d16 loads fill the low/high 16 and keep the rest, and both dword-crossing loads at offset 3 are exact (`0xbeef8811`, `0x88110000`). Not measured: an inactive lane. GPU-checked by `runtime/test/shaders/cs_global_mem_ext.asm` for two of the ten ops (one lane, `saddr` addressing, on a Radeon 610M (gfx1036, RADV, Mesa 26.2.6) and an RTX 4070 Ti (NVIDIA 620.70.06), Linux): `global_store_short` at byte 3 of a dword changes only its two bytes, across both dwords, and `global_load_sbyte_d16_hi` sign-extends a byte into the high half of `vdst` and keeps the low half. **Not GPU-verified:** the other eight ops and an inactive lane. | | 322 | | 8/16-bit global stores and d16 loads | `global_store_byte`/`short` write the low 8/16 bits of the data VGPR (the `_d16_hi` forms its high half). `global_load_{u,s}byte_d16` and `global_load_short_d16` write the low 16 bits of `vdst` (the `_hi` forms the high 16) and keep the other half; `ubyte` zero-extends and `sbyte` sign-extends the byte to 16 bits. The address is the `global_load/store` one (`Gen.global_address`). The access goes one byte at a time, so a 16-bit access that crosses a dword (at byte 3) is exact too. A store merges each byte into its dword with atomic and/or, which keeps neighbouring bytes even when another lane writes them, as buffer byte stores do. A load reads each byte. Inactive lanes neither store nor load. The first-read analysis counts a d16 load's `vdst` as read, for the half it keeps. `global_load/store_dword_addtid` (lane-id and M0 addressing) raise `Unsupported`; until 2026-11-22 they crashed with `IndexError`, and the ten sub-dword ops raised `Unsupported`. CPU-checked by `tests/semantic/test_global_sub_dword.py` (every byte offset 0 to 7 for each op, an inactive lane, rejected forms, the first-read analysis). **Hardware-measured natively on `gfx1100`** (RX 7900 XTX, driver 26.10.1) with `tools/hw_oracle`, 16 cases that use the output buffer as scratch memory (seven stores, nine d16 loads), all matching: `b8`/`b16` change only the addressed bytes (`0x11223344` with `0xbeef` stored at offset 2 reads back `0xbeef3344`), `_d16_hi` stores take the data VGPR's high half (`0x12340000` at offset 0 gives `0x11221234`), a 16-bit store at offset 3 splits across the dword exactly (`0xfe223344` then `0x556677ca`), `ubyte`/`sbyte` d16 loads fill the low 16 bits of `vdst` and keep the other half (`0x85` gives `0xbeefff85` from a `0xbeef0000` vdst, `0x7f` gives `0xbeef007f`), `short`/`short_hi` d16 loads fill the low/high 16 and keep the rest, and both dword-crossing loads at offset 3 are exact (`0xbeef8811`, `0x88110000`). Not measured: an inactive lane. GPU-checked by `runtime/test/shaders/cs_global_mem_ext.asm` for two of the ten ops (one lane, `saddr` addressing, on a Radeon 610M (gfx1036, RADV, Mesa 26.2.6) and an RTX 4070 Ti (NVIDIA 620.70.06), Linux): `global_store_short` at byte 3 of a dword changes only its two bytes, across both dwords, and `global_load_sbyte_d16_hi` sign-extends a byte into the high half of `vdst` and keeps the low half. **Not GPU-verified:** the other eight ops and an inactive lane. | |
| 323 | | Literal samplers | Some shaders build their S# from immediates (for example `0x92, 0xC00000, 0x14500000, 0`). The runtime registers those in the descriptor hash table too, by scanning the translated shaders' constant S# values, not only S#s the game binds. The translator lists them per shader (`literal_samplers` in the index). `CreateGraphicsPipelineState` and `CreateComputePipelineState` register each stage's list in the descriptor hash table, since no heap slot names these S#s. Until 2026-11-22 nothing called `register_samplers` (#1169) outside its test, so such a shader's lookup found the fallback sampler and sampled with the wrong filter. The game's `$PS_PassthroughCopy` drew a coordinate ramp point-sampled: worst error 0.0078, against 0.00049 once registered. Checked by `d3d12_m2_textured_test` (`ps_m2_literal.asm`: no key before the PSO, a sampler index after it). | | 323 | | Literal samplers | Some shaders build their S# from immediates (for example `0x92, 0xC00000, 0x14500000, 0`). The runtime registers those in the descriptor hash table too, by scanning the translated shaders' constant S# values, not only S#s the game binds. The translator lists them per shader (`literal_samplers` in the index). `CreateGraphicsPipelineState` and `CreateComputePipelineState` register each stage's list in the descriptor hash table, since no heap slot names these S#s. Until 2026-11-22 nothing called `register_samplers` (#1169) outside its test, so such a shader's lookup found the fallback sampler and sampled with the wrong filter. The game's `$PS_PassthroughCopy` drew a coordinate ramp point-sampled: worst error 0.0078, against 0.00049 once registered. Checked by `d3d12_m2_textured_test` (`ps_m2_literal.asm`: no key before the PSO, a sampler index after it). | |
| 324 | | Pipeline-library scalar operands | A scalar load may use VCC as a 64-bit pointer. In wave32 programs using that operand, scalar pair moves and XORs preserve both address words. Read its low and high data words, gathering a native wave's mask bits when a half is mask-valued. An emulated wave64 mask-valued pointer is refused. Where LLVM rejects a scalar, image or buffer tuple ending in VCC, recover the tuple from its original bytes before following branches. Hand-built memory and decoder cases in `test_library_compute_forms.py` and `test_vcc_tuple_fallback.py`. | | 324 | | Pipeline-library scalar operands | A scalar load may use VCC as a 64-bit pointer. In wave32 programs using that operand, scalar pair moves and XORs preserve both address words. Read its low and high data words, gathering a native wave's mask bits when a half is mask-valued. An emulated wave64 mask-valued pointer is refused. Where LLVM rejects a scalar, image or buffer tuple ending in VCC, recover the tuple from its original bytes before following branches. Hand-built memory and decoder cases in `test_library_compute_forms.py` and `test_vcc_tuple_fallback.py`. | |
| 325 | | Scalar/buffer memory | `s_load*`, `s_buffer_load*`, `buffer_load*` and `buffer_store*` use buffer device addresses (`PhysicalStorageBuffer64`). LLVM `VCCTuple` scalar register lists ending in `vcc_lo,vcc_hi` (e.g. `[s100,s101,s102,s103,s104,s105,vcc_lo,vcc_hi]`, `[s92,...,s105,vcc_lo,vcc_hi]`, seen in 6 FidelityFX FSPX shaders) are parsed as `slist` operands in `tools/shader_ir.py`, clear `vcc` from the lane-mask state in `tools/lane_masks.py`, and route `sN` slots to `%sgpr` and `vcc_lo`/`vcc_hi` to `%vcc`/`%vcc_hi` across SMEM loads, T#/S#/V# descriptor reads, and `global_*` `saddr`. `src_scc` reads `%scc` (0 or 1, RDNA2 inline constant 253), matching `scc`. `image_atomic_*` and `image_atomic_cmpswap` accept `a16` packed 16-bit unsigned coordinates (low half first, matching `image_store`). CPU-checked by `tests/semantic/test_fspx_rules.py` and validated with `spirv-val` (native and `--wave64-emulate`). **Not GPU-verified.** The base comes from the 64-bit SGPR pointer or the V# (dword0 \ \| dword1[15:0] << 32), and the stride is V# dword1[29:16]. **The runtime must put the game's GPU heap in buffer-device-addressable memory at the same addresses the game writes into descriptors** (or remap them). `s_load*` and `s_buffer_load*` take an immediate or an SGPR offset, or both at once (llvm-mc prints `sOFF offset:IMM`). Rules, measured on AMD Radeon RX 6800 (gfx1030, Windows driver 32.0.21045.29003) by running the instructions as a raw compute kernel, wave32 and wave64 (155 runs, every result either 0 or the stored data, wave32 = wave64 in every dword): **address** = (base & ~3) + (sOFF & ~3) + (IMM & ~3) + 4·i for dword i: base, sOFF and IMM are each truncated to a multiple of 4, then added (`s_buffer_load_dword s9, s[24:27], 0x3` with base & 3 = 1 reads +0, not bytes 4..7; sOFF 3 + IMM 3 reads +0 and sOFF 2 + IMM 6 reads +4, where truncating the sum gives +4 and +8; sOFF 8 + IMM 4 reads +12; the same for `s_load*` with pointer & 3 = 1 or 3). **`s_buffer_load*` bound**: dword i is 0, and memory is not read, when (sOFF & ~3) + (IMM & ~3) + 4·i + 4 > limit, with limit = NUM_RECORDS (V# dword2) bytes when the stride is 0 and NUM_RECORDS × stride bytes when it is not. Per dword (x4 at 0xc with NUM_RECORDS 21: data, data, 0, 0; x8 at 0 with 21: five data, three 0), on the truncated offset (IMM 0x10 with NUM_RECORDS 18: 0; IMM 0x13 with 21: the dword at +0x10; sOFF 0xe + IMM 2 with 16: the dword at +0xc; sOFF 0x10 + IMM 4 with 20: 0), not seeing base & 3 (base & 3 = 3, IMM 0x13, NUM_RECORDS 20: data); with a stride the test is still on bytes (stride 4, NUM_RECORDS 5: IMM 0x10 data, 0x14 0; stride 1, NUM_RECORDS 17: IMM 0x10 is 0, so it is not an index test). IMM is unsigned (0xffffc reads +0xffffc). OOB_SELECT (V# word3[29:28]) 0, 1, 2 and 3 gave the same pattern (7 probes per value). **`s_load*`**: no bound (+0x1ffffc reads the dword there); IMM is sign-extended from 21 bits and added in 64 bits (sOFF 8 + IMM −4 reads +4 where zero-extension reads 4 GiB further; sOFF 0xb + IMM −1 reads +4, so the negative IMM is truncated on its own: −1 → −4). **Negative sums** (SHADER-336), measured on the integrated GPU of a Ryzen 9 9950X3D (gfx1036, RDNA2, Windows driver 32.0.21045.16010) with `tools/smem_neg_probe.py --oracle hw`, wave32 = wave64: `s_load` with IMM −4 or −0x40 and no sOFF, sOFF 4 + IMM −8, sOFF 0xc + IMM −0x20 and the x2 form with sOFF 4 + IMM −0x10 read below the pointer at the 64-bit signed sum, and sOFF 6 + IMM −1 reads +0 (4 + −4, each term truncated on its own). `s_buffer_load` adds sOFF and IMM without wrapping at 32 bits: sOFF 0xfffffffc + IMM 8 and sOFF 0xfffffff0 + IMM 0x20 give 0 (past NUM_RECORDS 0x100), and sOFF 0xfffffffc, 0x80000000 and 0x7ffffffc alone give 0 (the translator has the same rule in both offset forms since #1686). An `s_buffer_load` IMM with bit 20 set (llvm-mc rejects it; −4, −0x10, 0x100000 and 0x100004 were encoded by hand) reads data that is neither 0 nor the buffer's own words, differently in wave32 and wave64: the bound does not hold for that encoding, so no compiler output uses it and the translator does not model it. `SmemHardwareRuleTests` in `tests/semantic/test_scalar_mem_smem.py` runs these rows with sOFF in a register and with sOFF known. **Measured since** on native RDNA2 (gfx1036, the Radeon iGPU of a Ryzen 7 9800X3D, Windows driver 32.0.21042.62) through `tools/hw_oracle`, one raw kernel, wave32 = wave64 in every dword (22 cases): **`x16`** takes the per-dword bound like x8 (`s_buffer_load_dwordx16` at offset 0 with NUM_RECORDS 0x24 gives nine data dwords and seven 0; offset 0x20 with 0x40 gives eight and eight; offset 4 with 0x3d gives fourteen and two; stride 4 with NUM_RECORDS 9 gives nine and seven), and `s_load_dwordx16` reads all sixteen; **NUM_RECORDS ≥ 2^31** is compared unsigned (0x80000000 and 0xffffffff with offset 0x10, and 0x80000000 with an x4 at 0x2f0, all read data); **NUM_RECORDS × stride ≥ 2^32** does not wrap (stride 4 × 0x40000001, stride 0x100 × 0x01000001 and stride 0x40 × 0x04000004 wrap to 4, 0x100 and 0x100 in 32 bits, yet offsets 0x10, 0x200 and 0x2f0 read data), as the translator's 64-bit product assumes; **V# dword1[31:30]** = 1, 2 or 3 changes nothing (a dword at 0x10, an x4 at 0xf8 with NUM_RECORDS 0x100 giving two data and two 0, and the same with stride 8 and NUM_RECORDS 4 at 0x18). Not measured: gfx1013 (PS5) itself. **Bound edges**, measured on the same GPU and driver with `tools/hw_oracle` (wave32 = wave64, every read inside a seeded region): `s_buffer_load_dwordx16` is bounded per dword like x8 (NUM_RECORDS 0x14 gives d0..d4 and 0 for d5..d15; 0x20 with IMM or sOFF 8 gives d0..d5); NUM_RECORDS × stride is not cut to 32 bits (stride 0x1000 × 0x100000 and 0x2000 × 0x80000 = 2^32, stride 8 × 0x20000001 = 2^32 + 8: all four dwords of an x4 at 0 are data; stride 8 × 1 gives two); NUM_RECORDS 0x80000000 and 0xFFFFFFFF are unsigned (an x4 at 0 reads all four). These are the rules the translator already used; `SmemHardwareRuleTests` pins them too (a 32-bit product, a signed NUM_RECORDS or one bound for the whole load each fail a test). Not measured: `x16` (gets the x8 rule), NUM_RECORDS ≥ 2^31 and NUM_RECORDS × stride ≥ 2^32, V# dword1[31:30], and gfx1013 (PS5) itself. `s_load`/`s_buffer_load` with sOFF + IMM < 0 (a negative IMM without sOFF included; the translator uses the 64-bit signed sum, an inference), an `s_buffer_load` IMM with bit 20 set (llvm-mc rejects it) or a negative one (kept as the 32-bit value: for stride 0 that is past any NUM_RECORDS below 4 GiB), `x16` (gets the x8 rule), sOFF ≥ 2^31, NUM_RECORDS ≥ 2^31 and NUM_RECORDS × stride ≥ 2^32, V# dword1[31:30], and gfx1013 (PS5) itself. The translator checks each `s_buffer_load` dword with its own structured `if` and an `OpPhi` with 0, so an out-of-range dword issues no load (when descriptor limit and offset are compile-time constants, in-range dwords fold to straight-line loads and out-of-range dwords emit constant zero without branches); `s_load` stays straight-line. Before this the translator added base + sOFF + IMM unaligned, had no `s_buffer_load` bound and zero-extended a negative `s_load` IMM. Checked by `tests/semantic/test_scalar_mem_smem.py` (`SmemHardwareRuleTests`, the measurement's rows, values and the addresses read; `SmemSoffsetImmTranslatorTests`) and by the GPU tests `runtime/test/shaders/cs_smem_soffset_imm.asm`, `cs_smem_bounds.asm`, `cs_smem_stride_align.asm` and `cs_smem_sload_neg.asm` (never run that one with a translator that zero-extends the immediate: it reads 4 GiB past the heap), all in `check.py` and `scripts/run_gpu_tests.py`, which pass on the RX 6800 (Vulkan, driver 26.11.2). See *Buffer bounds checking* below for the MUBUF `num_records` checks. **A constant SGPR offset** (`s_mov_b32 s12, C`, folded at translate time) is added as the run-time path adds `sOFF`: zero-extended, `& ~3`, after the immediate has been normalised (unsigned for `s_buffer_load`, 21-bit signed for `s_load`), with no 32-bit wrap. Until 2026-11-22 (#1686) the fold added it before the truncation, so `s12 = -4` with `offset:20` read byte 16 instead of being out of range, and an `s_load` `sOFF` of 2^20 or more was sign-extended from 21 bits (found by @Impre-visible; hardware measured by @Pierre-Kookis on gfx1036: 0xFFFFFFFC + 20 reads 0). CPU-checked by `tests/semantic/test_smem_const_offset.py` (each case constant vs run-time offset, and against the measured rule). Where llvm-mc rejects such a tuple, `restore_vcc_tuples` decodes it from the blob, and with it the instructions its junk text swallowed, up to the next instruction llvm-mc printed (corpus count: `docs/shader_library.md`, section 5). | | 325 | | Scalar/buffer memory | `s_load*`, `s_buffer_load*`, `buffer_load*` and `buffer_store*` use buffer device addresses (`PhysicalStorageBuffer64`). LLVM `VCCTuple` scalar register lists ending in `vcc_lo,vcc_hi` (e.g. `[s100,s101,s102,s103,s104,s105,vcc_lo,vcc_hi]`, `[s92,...,s105,vcc_lo,vcc_hi]`, seen in 6 FidelityFX FSPX shaders) are parsed as `slist` operands in `tools/shader_ir.py`, clear `vcc` from the lane-mask state in `tools/lane_masks.py`, and route `sN` slots to `%sgpr` and `vcc_lo`/`vcc_hi` to `%vcc`/`%vcc_hi` across SMEM loads, T#/S#/V# descriptor reads, and `global_*` `saddr`. `src_scc` reads `%scc` (0 or 1, RDNA2 inline constant 253), matching `scc`. `image_atomic_*` and `image_atomic_cmpswap` accept `a16` packed 16-bit unsigned coordinates (low half first, matching `image_store`). CPU-checked by `tests/semantic/test_fspx_rules.py` and validated with `spirv-val` (native and `--wave64-emulate`). **Not GPU-verified.** The base comes from the 64-bit SGPR pointer or the V# (dword0 \ \| dword1[15:0] << 32), and the stride is V# dword1[29:16]. **The runtime must put the game's GPU heap in buffer-device-addressable memory at the same addresses the game writes into descriptors** (or remap them). `s_load*` and `s_buffer_load*` take an immediate or an SGPR offset, or both at once (llvm-mc prints `sOFF offset:IMM`). Rules, measured on AMD Radeon RX 6800 (gfx1030, Windows driver 32.0.21045.29003) by running the instructions as a raw compute kernel, wave32 and wave64 (155 runs, every result either 0 or the stored data, wave32 = wave64 in every dword): **address** = (base & ~3) + (sOFF & ~3) + (IMM & ~3) + 4·i for dword i: base, sOFF and IMM are each truncated to a multiple of 4, then added (`s_buffer_load_dword s9, s[24:27], 0x3` with base & 3 = 1 reads +0, not bytes 4..7; sOFF 3 + IMM 3 reads +0 and sOFF 2 + IMM 6 reads +4, where truncating the sum gives +4 and +8; sOFF 8 + IMM 4 reads +12; the same for `s_load*` with pointer & 3 = 1 or 3). **`s_buffer_load*` bound**: dword i is 0, and memory is not read, when (sOFF & ~3) + (IMM & ~3) + 4·i + 4 > limit, with limit = NUM_RECORDS (V# dword2) bytes when the stride is 0 and NUM_RECORDS × stride bytes when it is not. Per dword (x4 at 0xc with NUM_RECORDS 21: data, data, 0, 0; x8 at 0 with 21: five data, three 0), on the truncated offset (IMM 0x10 with NUM_RECORDS 18: 0; IMM 0x13 with 21: the dword at +0x10; sOFF 0xe + IMM 2 with 16: the dword at +0xc; sOFF 0x10 + IMM 4 with 20: 0), not seeing base & 3 (base & 3 = 3, IMM 0x13, NUM_RECORDS 20: data); with a stride the test is still on bytes (stride 4, NUM_RECORDS 5: IMM 0x10 data, 0x14 0; stride 1, NUM_RECORDS 17: IMM 0x10 is 0, so it is not an index test). IMM is unsigned (0xffffc reads +0xffffc). OOB_SELECT (V# word3[29:28]) 0, 1, 2 and 3 gave the same pattern (7 probes per value). **`s_load*`**: no bound (+0x1ffffc reads the dword there); IMM is sign-extended from 21 bits and added in 64 bits (sOFF 8 + IMM −4 reads +4 where zero-extension reads 4 GiB further; sOFF 0xb + IMM −1 reads +4, so the negative IMM is truncated on its own: −1 → −4). **Negative sums** (SHADER-336), measured on the integrated GPU of a Ryzen 9 9950X3D (gfx1036, RDNA2, Windows driver 32.0.21045.16010) with `tools/smem_neg_probe.py --oracle hw`, wave32 = wave64: `s_load` with IMM −4 or −0x40 and no sOFF, sOFF 4 + IMM −8, sOFF 0xc + IMM −0x20 and the x2 form with sOFF 4 + IMM −0x10 read below the pointer at the 64-bit signed sum, and sOFF 6 + IMM −1 reads +0 (4 + −4, each term truncated on its own). `s_buffer_load` adds sOFF and IMM without wrapping at 32 bits: sOFF 0xfffffffc + IMM 8 and sOFF 0xfffffff0 + IMM 0x20 give 0 (past NUM_RECORDS 0x100), and sOFF 0xfffffffc, 0x80000000 and 0x7ffffffc alone give 0 (the translator has the same rule in both offset forms since #1686). An `s_buffer_load` IMM with bit 20 set (llvm-mc rejects it; −4, −0x10, 0x100000 and 0x100004 were encoded by hand) reads data that is neither 0 nor the buffer's own words, differently in wave32 and wave64: the bound does not hold for that encoding, so no compiler output uses it and the translator does not model it. `SmemHardwareRuleTests` in `tests/semantic/test_scalar_mem_smem.py` runs these rows with sOFF in a register and with sOFF known. **Measured since** on native RDNA2 (gfx1036, the Radeon iGPU of a Ryzen 7 9800X3D, Windows driver 32.0.21042.62) through `tools/hw_oracle`, one raw kernel, wave32 = wave64 in every dword (22 cases): **`x16`** takes the per-dword bound like x8 (`s_buffer_load_dwordx16` at offset 0 with NUM_RECORDS 0x24 gives nine data dwords and seven 0; offset 0x20 with 0x40 gives eight and eight; offset 4 with 0x3d gives fourteen and two; stride 4 with NUM_RECORDS 9 gives nine and seven), and `s_load_dwordx16` reads all sixteen; **NUM_RECORDS ≥ 2^31** is compared unsigned (0x80000000 and 0xffffffff with offset 0x10, and 0x80000000 with an x4 at 0x2f0, all read data); **NUM_RECORDS × stride ≥ 2^32** does not wrap (stride 4 × 0x40000001, stride 0x100 × 0x01000001 and stride 0x40 × 0x04000004 wrap to 4, 0x100 and 0x100 in 32 bits, yet offsets 0x10, 0x200 and 0x2f0 read data), as the translator's 64-bit product assumes; **V# dword1[31:30]** = 1, 2 or 3 changes nothing (a dword at 0x10, an x4 at 0xf8 with NUM_RECORDS 0x100 giving two data and two 0, and the same with stride 8 and NUM_RECORDS 4 at 0x18). Not measured: gfx1013 (PS5) itself. **Bound edges**, measured on the same GPU and driver with `tools/hw_oracle` (wave32 = wave64, every read inside a seeded region): `s_buffer_load_dwordx16` is bounded per dword like x8 (NUM_RECORDS 0x14 gives d0..d4 and 0 for d5..d15; 0x20 with IMM or sOFF 8 gives d0..d5); NUM_RECORDS × stride is not cut to 32 bits (stride 0x1000 × 0x100000 and 0x2000 × 0x80000 = 2^32, stride 8 × 0x20000001 = 2^32 + 8: all four dwords of an x4 at 0 are data; stride 8 × 1 gives two); NUM_RECORDS 0x80000000 and 0xFFFFFFFF are unsigned (an x4 at 0 reads all four). These are the rules the translator already used; `SmemHardwareRuleTests` pins them too (a 32-bit product, a signed NUM_RECORDS or one bound for the whole load each fail a test). Not measured: `x16` (gets the x8 rule), NUM_RECORDS ≥ 2^31 and NUM_RECORDS × stride ≥ 2^32, V# dword1[31:30], and gfx1013 (PS5) itself. `s_load`/`s_buffer_load` with sOFF + IMM < 0 (a negative IMM without sOFF included; the translator uses the 64-bit signed sum, an inference), an `s_buffer_load` IMM with bit 20 set (llvm-mc rejects it) or a negative one (kept as the 32-bit value: for stride 0 that is past any NUM_RECORDS below 4 GiB), `x16` (gets the x8 rule), sOFF ≥ 2^31, NUM_RECORDS ≥ 2^31 and NUM_RECORDS × stride ≥ 2^32, V# dword1[31:30], and gfx1013 (PS5) itself. The translator checks each `s_buffer_load` dword with its own structured `if` and an `OpPhi` with 0 when the last dword is out of range (otherwise one wide load, row *Wide scalar loads*), so an out-of-range dword issues no load (when descriptor limit and offset are compile-time constants, in-range dwords fold to straight-line loads and out-of-range dwords emit constant zero without branches); `s_load` stays straight-line. Before this the translator added base + sOFF + IMM unaligned, had no `s_buffer_load` bound and zero-extended a negative `s_load` IMM. Checked by `tests/semantic/test_scalar_mem_smem.py` (`SmemHardwareRuleTests`, the measurement's rows, values and the addresses read; `SmemSoffsetImmTranslatorTests`) and by the GPU tests `runtime/test/shaders/cs_smem_soffset_imm.asm`, `cs_smem_bounds.asm`, `cs_smem_stride_align.asm` and `cs_smem_sload_neg.asm` (never run that one with a translator that zero-extends the immediate: it reads 4 GiB past the heap), all in `check.py` and `scripts/run_gpu_tests.py`, which pass on the RX 6800 (Vulkan, driver 26.11.2). See *Buffer bounds checking* below for the MUBUF `num_records` checks. **A constant SGPR offset** (`s_mov_b32 s12, C`, folded at translate time) is added as the run-time path adds `sOFF`: zero-extended, `& ~3`, after the immediate has been normalised (unsigned for `s_buffer_load`, 21-bit signed for `s_load`), with no 32-bit wrap. Until 2026-11-22 (#1686) the fold added it before the truncation, so `s12 = -4` with `offset:20` read byte 16 instead of being out of range, and an `s_load` `sOFF` of 2^20 or more was sign-extended from 21 bits (found by @Impre-visible; hardware measured by @Pierre-Kookis on gfx1036: 0xFFFFFFFC + 20 reads 0). CPU-checked by `tests/semantic/test_smem_const_offset.py` (each case constant vs run-time offset, and against the measured rule). Where llvm-mc rejects such a tuple, `restore_vcc_tuples` decodes it from the blob, and with it the instructions its junk text swallowed, up to the next instruction llvm-mc printed (corpus count: `docs/shader_library.md`, section 5). | |
| 326 | | Wide scalar loads | `s_load_dwordx2/4/8/16` and `s_buffer_load_dwordx2/4/8/16` read their dwords as the fewest wide loads SPIR-V types allow (`Gen.scalar_load`'s `wide`: `uvec4`, then `uvec2`, each `Aligned 4`), not one `uint` per dword. An `s_buffer_load` whose bound is a run-time value tests its last dword once (off + 4·N ≤ limit; the ends grow with i, so then every dword is in range) and takes the wide loads, else calls an outlined per-width compact counted-loop helper `%sbuf_slow_{ro\|rw}_xN(host, off, lim)` (emitted on demand for each used `(N, ro)` pair with `N ∈ {2, 4, 8, 16}` returning `%arr_sbuf_xN`, with `OpLoopMerge ... DontUnroll`, overflow-safe trip count `lim >= off ? min((lim - off) >> 2, N) : 0`, ONE `OpLoad %uint ... Aligned 4` in the loop body, and a zero-initialized `Function`-scope `%arr_sbuf_xN`, preserving exact per-dword bounds: out-of-range dwords stay 0 and are not read; coherent `glc`/`dlc` loads stay on the inline `MakePointerVisible\|NonPrivatePointer` path). Provably non-aliasing scalar loads go through a `NonWritable` `Block` (`%sl_blk1` / `%sl_blk2` / `%sl_blk4`, including `%sbuf_slow_ro_xN` via `%_ptr_PSB_sl_blk1`) determined per load by `analyse_scalar_load_ro` (read-only modules with no PSB write, descriptor-heap `s_load*` from a 32-bit user SGPR with `hi = 0` whose base is not written and whose loaded dwords are consumed solely as T#/S#/V# descriptors, `s_getpc_b64` loads, loads with no PSB write reachable before or after in the CFG, and loads whose symbolic descriptor/slot origin is disjoint from every PSB write in the module; conservatively disabled whenever `s_dcache_*` appears alongside a write), so RADV/ACO emits SMEM (`s_load_dword..s_load_dwordx16`) on both fast and slow paths even in shaders that also write buffers; loads that may alias a module store/atomic use a mutable `Block` (`%sl_rw_blk2` / `%sl_rw_blk4`) or `%_ptr_PSB_arr` (`%sbuf_slow_rw_xN`) without `NonWritable`, keeping `tools/valu_fuzz.py --family mem` (which stores and loads back through the same base origin) exact. Why: Mesa `spirv_to_nir` always inlines `OpFunctionCall`, so unrolling `N` mutable `OpLoad`s inside `%sbuf_slow_xN` still exploded on wide-load-heavy shaders; a `DontUnroll` single-load loop with `NonWritable` `%sl_blk1` keeps the slow path to one SMEM `s_load_dword` per site (40× `s_buffer_load_dwordx16` synthetic shader on `gfx1036` RADV: 40 `s_load_dwordx16`, 40 `s_load_dword`, 0 `global_load`, 0 `v_readfirstlane`, 0 `scratch_`). **Confirmed** by `tests/semantic/test_wide_scalar_load.py`, `tests/semantic/test_smem_nonwritable_outline.py` (fixture `cs_smem_nonwritable_outline.asm`: per-load `NonWritable` on disjoint CBV/descriptor-heap loads alongside `buffer_store`, mutable fallback on same-root aliasing, mixed RO/RW helpers sharing `%fn_sbuf_slow_x4`, `s_dcache_inv` conservative fallback, partial-OOB and all-OOB read checks, `spirv-val --target-env vulkan1.2`, `check_absent_lane_ub.py`), `SmemHardwareRuleTests` in `tests/semantic/test_scalar_mem_smem.py`, and `tools/valu_fuzz.py --family mem --programs 200` (400/400 wave32+wave64) on the Radeon iGPU (`gfx1036`, RADV). Count over the corpus (1.0.2.1): x2 268,659 in 22,943 modules, x4 550,938 in 24,268, x8 120,295 in 16,539, x16 65,758 in 16,200 (25,878 modules in all); 0 modules have `s_dcache_inv`, `s_gl1_inv` or `s_dcache_wb`. | | ||
| 326 | | 2D array resource dimensions | For `image_get_resinfo` on a 2D array, X/Y are the width/height at the requested mip, Z is the view layer count and W is its mip count. The query reads the sampled array at binding 3. A native gfx1036 kernel returned (19,11,5,3), (9,5,5,3) and (4,2,5,3) for the three mips of a synthetic array. On RTX 5080 and Radeon Graphics the translated query matched those tuples and returned (4,2,3,2) at relative mip 1 with a view starting at mip 1 and covering three layers. The registered `ps_array_resinfo` draw checks all 4096 pixels against (8,8,12,1). | | 327 | | 2D array resource dimensions | For `image_get_resinfo` on a 2D array, X/Y are the width/height at the requested mip, Z is the view layer count and W is its mip count. The query reads the sampled array at binding 3. A native gfx1036 kernel returned (19,11,5,3), (9,5,5,3) and (4,2,5,3) for the three mips of a synthetic array. On RTX 5080 and Radeon Graphics the translated query matched those tuples and returned (4,2,3,2) at relative mip 1 with a view starting at mip 1 and covering three layers. The registered `ps_array_resinfo` draw checks all 4096 pixels against (8,8,12,1). | |
| 327 | | Images and samplers | `image_sample_l` on 2D arrays used to read its LOD from the array layer; it now reads the LOD after all coordinates. `image_get_lod` and `image_gather4_lz` also work on 2D arrays. With `d16` every sample result is f16, packed two to a VGPR from the low half (the packed D16 of GFX10, as LLVM returns D16 image data); `image_sample_c_lz`/`_c_lz_o` follow it too, and until 2026-11-21 their compare result was written as f32 bits, which read as 0 in the low half. Checked by `tests/test_translate.py` (`test_depth_compare_sample_result_width`) and GPU-checked with `runtime/test/shaders/ps_sample_c_lz.asm` (`vk_texture_test dref`: a D32 texture and a LESS_OR_EQUAL compare sampler) on an NVIDIA GeForce RTX 2060 SUPER (Linux, driver 620.70.06): 4096/4096 pixels exact for f32 and `d16`; with the old translator the `d16` result read 0 in the 2048 pixels whose compare passes. | | 328 | | Images and samplers | `image_sample_l` on 2D arrays used to read its LOD from the array layer; it now reads the LOD after all coordinates. `image_get_lod` and `image_gather4_lz` also work on 2D arrays. With `d16` every sample result is f16, packed two to a VGPR from the low half (the packed D16 of GFX10, as LLVM returns D16 image data); `image_sample_c_lz`/`_c_lz_o` follow it too, and until 2026-11-21 their compare result was written as f32 bits, which read as 0 in the low half. Checked by `tests/test_translate.py` (`test_depth_compare_sample_result_width`) and GPU-checked with `runtime/test/shaders/ps_sample_c_lz.asm` (`vk_texture_test dref`: a D32 texture and a LESS_OR_EQUAL compare sampler) on an NVIDIA GeForce RTX 2060 SUPER (Linux, driver 620.70.06): 4096/4096 pixels exact for f32 and `d16`; with the old translator the `d16` result read 0 in the 2048 pixels whose compare passes. | |
| 328 | | Images and samplers (T# dimension) | The hardware addresses an image with the T#'s own TYPE (`SQ_IMG_RSRC_WORD3` [31:28]); an instruction's `DIM` only says which coordinates it supplies. The bindless set therefore gives each image its index in **its** dimension's array (`runtime/src/vulkan_bindless.h`), and an instruction of another dimension must not use that index blindly. Pairs: a **2D-array or cube T# read by a 2D instruction** is its slice 0 (legal; the runtime binds a 2D view of the T#'s first layer at the image's own index in the 2D arrays, `BindlessSet::MirrorViews`, and the entry's kind names 2D; the mirror records that image as its owner, so an image of another dimension at the same slot number does not inherit it); every other mismatch - a **2D T# read by a 2D-array instruction** (it has one layer but no 2D-array view), a **3D T# read by a 2D op**, a 1D T#, a multisample T# read by a single-sample op, a 2D T# read by a 3D op - has no view of the instruction's shape and reads that dimension's fallback (index 0, a 1x1 image of zeros), never another image. So each entry carries a kind word next to its index: the translator reads it from the table (`%desc_lookup_fn` returns (index, kind) as a `uvec2` in a `descriptor_table` tagged module), tests the bit for the array its instruction reads with `OpBitFieldUExtract` and picks index 0 otherwise (`Gen.desc_sampled_index`). A store, atomic or `glc` coherent read follows the storage bits instead (`Gen.desc_storage_index`): a T# of another dimension, or one whose image has only a sampled view, goes to that dimension's storage fallback, where writes and atomics are dropped (a null descriptor with `VK_EXT_robustness2`, else a 1x1 image apart from the sampled fallbacks). Checked by `tests/semantic/test_tsharp_dimension.py` (each dimension's bit, the storage rule, the fallback operand, the plain layout and the meta marker) and by `runtime/test/vk_bindless_test.cpp`, which draws a 2D sampling shader with a 3D T# whose index equals a 2D image's: 0 bad pixels with tagged modules, 4096 per pass with plain ones (that module reads the 2D image at that index); it also binds a 2D-array T# whose mirror it reads, removes it, and puts a 3D T# at the same slot number to show the two index spaces stay separate. GPU-checked on an NVIDIA GeForce RTX 4070 Ti (driver 32.0.16.3020). `image_get_lod`, `image_load_mip` and `image_get_resinfo` name the bit but read the fallback on a mismatch. **Not measured on native RDNA2**: the pair table follows the ISA's TYPE addressing and Mesa's `ac_nir_lower_*` views; `tools/hw_oracle` was not used. | | 329 | | Images and samplers (T# dimension) | The hardware addresses an image with the T#'s own TYPE (`SQ_IMG_RSRC_WORD3` [31:28]); an instruction's `DIM` only says which coordinates it supplies. The bindless set therefore gives each image its index in **its** dimension's array (`runtime/src/vulkan_bindless.h`), and an instruction of another dimension must not use that index blindly. Pairs: a **2D-array or cube T# read by a 2D instruction** is its slice 0 (legal; the runtime binds a 2D view of the T#'s first layer at the image's own index in the 2D arrays, `BindlessSet::MirrorViews`, and the entry's kind names 2D; the mirror records that image as its owner, so an image of another dimension at the same slot number does not inherit it); every other mismatch - a **2D T# read by a 2D-array instruction** (it has one layer but no 2D-array view), a **3D T# read by a 2D op**, a 1D T#, a multisample T# read by a single-sample op, a 2D T# read by a 3D op - has no view of the instruction's shape and reads that dimension's fallback (index 0, a 1x1 image of zeros), never another image. So each entry carries a kind word next to its index: the translator reads it from the table (`%desc_lookup_fn` returns (index, kind) as a `uvec2` in a `descriptor_table` tagged module), tests the bit for the array its instruction reads with `OpBitFieldUExtract` and picks index 0 otherwise (`Gen.desc_sampled_index`). A store, atomic or `glc` coherent read follows the storage bits instead (`Gen.desc_storage_index`): a T# of another dimension, or one whose image has only a sampled view, goes to that dimension's storage fallback, where writes and atomics are dropped (a null descriptor with `VK_EXT_robustness2`, else a 1x1 image apart from the sampled fallbacks). Checked by `tests/semantic/test_tsharp_dimension.py` (each dimension's bit, the storage rule, the fallback operand, the plain layout and the meta marker) and by `runtime/test/vk_bindless_test.cpp`, which draws a 2D sampling shader with a 3D T# whose index equals a 2D image's: 0 bad pixels with tagged modules, 4096 per pass with plain ones (that module reads the 2D image at that index); it also binds a 2D-array T# whose mirror it reads, removes it, and puts a 3D T# at the same slot number to show the two index spaces stay separate. GPU-checked on an NVIDIA GeForce RTX 4070 Ti (driver 32.0.16.3020). `image_get_lod`, `image_load_mip` and `image_get_resinfo` name the bit but read the fallback on a mismatch. **Not measured on native RDNA2**: the pair table follows the ISA's TYPE addressing and Mesa's `ac_nir_lower_*` views; `tools/hw_oracle` was not used. | |
| 329 | | Images and samplers (core) | Bindless. Set 0: binding 0 = 2D sampled images, 1 = samplers, 2 = descriptor hash table (storage buffer), 3 = 2D-array images (**cube textures are bound here as 6-layer 2D-array views**, cube arrays as 6N layers: the shader already selected the face with `v_cube*`), 4 = r32ui storage images, 5 = 1D, 6 = 3D. A cube sample's s and t come in [1, 2] and its third coordinate is 8·slice + face, as the hardware takes them (Mesa `ac_nir_lower_tex_coords.c`, LLPC `ImageBuilder.cpp`); the view is read at (s − 1, t − 1), layer 6·slice + face. GPU-checked with `runtime/test/shaders/ps_cube_sample.asm` (`vk_texture_test cube`). For a native Metal path, `tools/spirv_metal_set0.py` sizes set 0's runtime arrays from `vulkan_bindless.h` and moves each binding to its own argument-buffer ID range (binding b starts at the capacities of bindings 0..b-1 added up), to convert with SPIRV-Cross `--msl-decoration-binding`: SPIRV-Cross 1.4.363.0 otherwise puts every runtime array at one ID and comments all but one out as "Overlapping binding" (SHADER-161). `cs_imgstore` converted this way writes all 3×64 texels correctly in a native Metal dispatch on an Apple A18 Pro. | | 330 | | Images and samplers (core) | Bindless. Set 0: binding 0 = 2D sampled images, 1 = samplers, 2 = descriptor hash table (storage buffer), 3 = 2D-array images (**cube textures are bound here as 6-layer 2D-array views**, cube arrays as 6N layers: the shader already selected the face with `v_cube*`), 4 = r32ui storage images, 5 = 1D, 6 = 3D. A cube sample's s and t come in [1, 2] and its third coordinate is 8·slice + face, as the hardware takes them (Mesa `ac_nir_lower_tex_coords.c`, LLPC `ImageBuilder.cpp`); the view is read at (s − 1, t − 1), layer 6·slice + face. GPU-checked with `runtime/test/shaders/ps_cube_sample.asm` (`vk_texture_test cube`). For a native Metal path, `tools/spirv_metal_set0.py` sizes set 0's runtime arrays from `vulkan_bindless.h` and moves each binding to its own argument-buffer ID range (binding b starts at the capacities of bindings 0..b-1 added up), to convert with SPIRV-Cross `--msl-decoration-binding`: SPIRV-Cross 1.4.363.0 otherwise puts every runtime array at one ID and comments all but one out as "Overlapping binding" (SHADER-161). `cs_imgstore` converted this way writes all 3×64 texels correctly in a native Metal dispatch on an Apple A18 Pro. | |
| 330 | | Typed buffer loads | The format is V# word3[18:12] (GFX10_FORMAT, from Mesa's `gfx10-rsrc.json`, saved as `tools\gfx10_formats.json`). Supported: f32 ×1–4, u32 ×1–4, i32 ×1–4 (formats 21/63/73/76), f16 ×1/2/4, unorm8 ×1/2/4, snorm8 ×1/2/4, uint8 ×1/2/4, sint8 ×1/2/4, unorm16 ×1/2/4, snorm16 ×1/2/4, uint16 ×1/2/4, sint16 ×1/2/4, 10-10-10-2 and 2-10-10-10 unorm, and, since 2026-11-22, the other GFX10 buffer codes 1–77 (every USCALED/SSCALED, 10_11_11 and 11_11_10 FLOAT, the 10_10_10_2 and 2_10_10_10 families, 8_8_8_8 and 16_16_16_16 SINT and SCALED; see *Typed buffer formats*). Others (code 0 and 78 up) give 0. The 8- and 16-bit UINT/SINT formats 5, 6, 11, 12, 18, 19, 28, 61 and 70 were missing until 2026-11-22 and read 0: UINT channels zero-extend, SINT channels sign-extend, d16 packs them as 16-bit integers, measured natively on gfx1036 (wave32 and wave64) with `tools/hw_oracle` and checked word for word by `tests/semantic/test_buffer_format_narrow_int.py`; GPU-checked by `runtime/test/shaders/cs_fmt_int_narrow.asm`, whose 136 expected words are the same program run natively on gfx1036 (exact on an RTX 5080 and on the gfx1036 iGPU through Vulkan). Full-width SINT accesses preserve integer bits. D16 SINT loads saturate to signed 16-bit and D16 stores sign-extend, covered by the synthetic `cs_fmt_sint32.asm` readback. DST_SEL swizzle is applied (0→0, 1→1.0f for float/norm or integer 1 for UINT/SINT, 4..7→X..W). Missing channels repeat the format's own (component *c* = *c* mod *n*), measured on an RX 6700 (SHADER-86). UNORM/SNORM give the correctly rounded quotient by (2ⁿ−1), as the hardware does (0 mismatches vs hardware over 395,776 conversions on that GPU). It is built with integer ops (`Gen.norm_bits`): x/(2ⁿ−1) in binary is x's bits repeated, so a 64-bit multiply by the repeat pattern, `FindUMsb` and the round bit give the f32 exactly (the tail never ends, so there are no ties). `OpFDiv` is not enough on the GPU: Vulkan allows it 2.5 ULP, and on an RX 6700 (AMD Windows 26.11.2) and an RTX 5090 it returned the reciprocal-multiply bits (8_UNORM 130/256 exact, #599). Checked against exact values in `tests/semantic/test_norm_decode.py` (every value up to 8 bits, edges and the reciprocal-multiply misses for 10, 15 and 16 bits). 8_SNORM (2), 16_SNORM (8) and 8_8_SNORM (15) were missing until 2026-11-22 and decoded to 0. Format names list the channel widths from the top bit, so `2_10_10_10` (50) is R10G10B10A2 and `10_10_10_2` (44) has a 2-bit x (Mesa `gfx10_format_table.py`, `ac_formats.c`). Until 2026-11-22 the two were swapped, in stores too. Until 2026-11-21 an element that started mid-dword re-read dword 0 for its tail (`need` was `ceil(size/4)` and only the first dword was shifted); loads now take `need = ceil((byte_shift + size) / 4)` dwords and shift the whole window so the packed stream starts at the element (FUZZ-5, leftover from #234). The 10:10:10:2 order is checked by `cs_fmt_1010102` in `tests/semantic/test_value_semantics.py` (the shader decodes the format, so a GPU run can't check it). Mid-dword spanning elements are checked by `tests/semantic/test_buffer_load_format.py` (`CrossingDwordBoundary`); repeat / UNORM / DST_SEL 1 by the SHADER-86 cases in the same file. The `_xy` and `_xyz` forms (buffer and tbuffer) are GPU-checked by `cs_fmt_xy_xyz.asm`, whose words were measured natively on a Radeon 680M (gfx1035, RDNA2): they write only their 2 or 3 VGPRs, and missing channels repeat there too (TEST-185). | | 331 | | Typed buffer loads | The format is V# word3[18:12] (GFX10_FORMAT, from Mesa's `gfx10-rsrc.json`, saved as `tools\gfx10_formats.json`). Supported: f32 ×1–4, u32 ×1–4, i32 ×1–4 (formats 21/63/73/76), f16 ×1/2/4, unorm8 ×1/2/4, snorm8 ×1/2/4, uint8 ×1/2/4, sint8 ×1/2/4, unorm16 ×1/2/4, snorm16 ×1/2/4, uint16 ×1/2/4, sint16 ×1/2/4, 10-10-10-2 and 2-10-10-10 unorm, and, since 2026-11-22, the other GFX10 buffer codes 1–77 (every USCALED/SSCALED, 10_11_11 and 11_11_10 FLOAT, the 10_10_10_2 and 2_10_10_10 families, 8_8_8_8 and 16_16_16_16 SINT and SCALED; see *Typed buffer formats*). Others (code 0 and 78 up) give 0. The 8- and 16-bit UINT/SINT formats 5, 6, 11, 12, 18, 19, 28, 61 and 70 were missing until 2026-11-22 and read 0: UINT channels zero-extend, SINT channels sign-extend, d16 packs them as 16-bit integers, measured natively on gfx1036 (wave32 and wave64) with `tools/hw_oracle` and checked word for word by `tests/semantic/test_buffer_format_narrow_int.py`; GPU-checked by `runtime/test/shaders/cs_fmt_int_narrow.asm`, whose 136 expected words are the same program run natively on gfx1036 (exact on an RTX 5080 and on the gfx1036 iGPU through Vulkan). Full-width SINT accesses preserve integer bits. D16 SINT loads saturate to signed 16-bit and D16 stores sign-extend, covered by the synthetic `cs_fmt_sint32.asm` readback. DST_SEL swizzle is applied (0→0, 1→1.0f for float/norm or integer 1 for UINT/SINT, 4..7→X..W). Missing channels repeat the format's own (component *c* = *c* mod *n*), measured on an RX 6700 (SHADER-86). UNORM/SNORM give the correctly rounded quotient by (2ⁿ−1), as the hardware does (0 mismatches vs hardware over 395,776 conversions on that GPU). It is built with integer ops (`Gen.norm_bits`): x/(2ⁿ−1) in binary is x's bits repeated, so a 64-bit multiply by the repeat pattern, `FindUMsb` and the round bit give the f32 exactly (the tail never ends, so there are no ties). `OpFDiv` is not enough on the GPU: Vulkan allows it 2.5 ULP, and on an RX 6700 (AMD Windows 26.11.2) and an RTX 5090 it returned the reciprocal-multiply bits (8_UNORM 130/256 exact, #599). Checked against exact values in `tests/semantic/test_norm_decode.py` (every value up to 8 bits, edges and the reciprocal-multiply misses for 10, 15 and 16 bits). 8_SNORM (2), 16_SNORM (8) and 8_8_SNORM (15) were missing until 2026-11-22 and decoded to 0. Format names list the channel widths from the top bit, so `2_10_10_10` (50) is R10G10B10A2 and `10_10_10_2` (44) has a 2-bit x (Mesa `gfx10_format_table.py`, `ac_formats.c`). Until 2026-11-22 the two were swapped, in stores too. Until 2026-11-21 an element that started mid-dword re-read dword 0 for its tail (`need` was `ceil(size/4)` and only the first dword was shifted); loads now take `need = ceil((byte_shift + size) / 4)` dwords and shift the whole window so the packed stream starts at the element (FUZZ-5, leftover from #234). The 10:10:10:2 order is checked by `cs_fmt_1010102` in `tests/semantic/test_value_semantics.py` (the shader decodes the format, so a GPU run can't check it). Mid-dword spanning elements are checked by `tests/semantic/test_buffer_load_format.py` (`CrossingDwordBoundary`); repeat / UNORM / DST_SEL 1 by the SHADER-86 cases in the same file. The `_xy` and `_xyz` forms (buffer and tbuffer) are GPU-checked by `cs_fmt_xy_xyz.asm`, whose words were measured natively on a Radeon 680M (gfx1035, RDNA2): they write only their 2 or 3 VGPRs, and missing channels repeat there too (TEST-185). | |
| 331 | | Descriptor hash table | `uint mask; entries[mask+1] of 10 uints: key[0..7], index, kind`. The last word is 0 in an empty slot; otherwise bit 31 marks it occupied and bits 0..5 / 8..11 name the sampled / storage arrays the index is bound in (docs/d3d12_vulkan.md section 5.1, "Images and samplers (T# dimension)" below). A module reads it only when its index entry says `"descriptor_table": "tagged"`; `--descriptor-table plain` leaves the word unread and gives byte-identical modules to the translator before the marker (checked with a 5-instruction pixel shader: old and plain output are the same bytes). The key is a T# or a padded S#. FNV-1a over the eight key words selects the first slot by default. With `--descriptor-hash=fnv1a_fmix32` the shader applies MurmurHash3 fmix32 before masking the slot. Every translated module then records `"descriptor_hash": "fnv1a_fmix32"` in its index entry. An absent key means `fnv1a`. The runtime and shader must select the same hash. The shared SPIR-V lookup probes up to eight slots and returns index 0 on a miss. The runtime supplies a fallback at index 0 and maps live descriptor keys to bindless indices. Outside the wave64 emulation, the lookup's result goes through `OpGroupNonUniformBroadcastFirst` before it indexes the image or sampler array. The lookup key words come from SGPRs, so every invocation in a subgroup has the same index; the broadcast is an identity on all drivers and marks the value uniform for the compiler. It declares `GroupNonUniform` and `GroupNonUniformBallot`, without a shuffle capability or subgroup-lane input. The shader index records the capabilities; its `features` field lists optional Vulkan device features. Mesa ANV 26.2.7 on an Intel Alder Lake-S UHD (Xe-LP, Linux) segfaults in `vkCreate*Pipelines` on a sampler index taken straight from the probe loop when that sampler serves both a float and an integer image (`cs_sample_lz_int_d16`, `ps_ssharp`); with the broadcast both pass. Checked by the unit test `test_lookup_result_is_broadcast_before_use` in `tests/test_desc_cache.py` (standard library only: no GPU, LLVM or SPIRV-Tools). | | 332 | | Descriptor hash table | `uint mask; entries[mask+1] of 10 uints: key[0..7], index, kind`. The last word is 0 in an empty slot; otherwise bit 31 marks it occupied and bits 0..5 / 8..11 name the sampled / storage arrays the index is bound in (docs/d3d12_vulkan.md section 5.1, "Images and samplers (T# dimension)" below). A module reads it only when its index entry says `"descriptor_table": "tagged"`; `--descriptor-table plain` leaves the word unread and gives byte-identical modules to the translator before the marker (checked with a 5-instruction pixel shader: old and plain output are the same bytes). The key is a T# or a padded S#. FNV-1a over the eight key words selects the first slot by default. With `--descriptor-hash=fnv1a_fmix32` the shader applies MurmurHash3 fmix32 before masking the slot. Every translated module then records `"descriptor_hash": "fnv1a_fmix32"` in its index entry. An absent key means `fnv1a`. The runtime and shader must select the same hash. The shared SPIR-V lookup probes up to eight slots and returns index 0 on a miss. The runtime supplies a fallback at index 0 and maps live descriptor keys to bindless indices. Outside the wave64 emulation, the lookup's result goes through `OpGroupNonUniformBroadcastFirst` before it indexes the image or sampler array. The lookup key words come from SGPRs, so every invocation in a subgroup has the same index; the broadcast is an identity on all drivers and marks the value uniform for the compiler. It declares `GroupNonUniform` and `GroupNonUniformBallot`, without a shuffle capability or subgroup-lane input. The shader index records the capabilities; its `features` field lists optional Vulkan device features. Mesa ANV 26.2.7 on an Intel Alder Lake-S UHD (Xe-LP, Linux) segfaults in `vkCreate*Pipelines` on a sampler index taken straight from the probe loop when that sampler serves both a float and an integer image (`cs_sample_lz_int_d16`, `ps_ssharp`); with the broadcast both pass. Checked by the unit test `test_lookup_result_is_broadcast_before_use` in `tests/test_desc_cache.py` (standard library only: no GPU, LLVM or SPIRV-Tools). | |
| 332 | | Run-time format decode cost | A `buffer_load_format_*` whose format comes from the V# is decoded by table, without a branch: one shared function, `%fmt_dec(format, element, component)`, reads the format's kind, channel count and channel widths from the module table `%fmt_desc_tab`, and the kind picks the conversion with `OpSelect`; the exact UNORM/SNORM quotient comes from the shared `%fmt_norm_bits`, whose width's 64-bit repeat constant is read from `%fmt_norm_rep_tab`. A code outside the table gives zeros, a format with fewer channels repeats its own (component *c* = *c* mod *n*), and the element size is selected from the format alone (`%fmt_size_tab`), the per-lane byte offset added once. Until 2026-11-23 the shared function instead held every format's decode and a binary search over the codes (`OpSelectionMerge` with `DontFlatten`): 3,498 instructions and 306 branches in the module of a shader with one dynamic-format load (250,869 bytes). Then four functions, one per output component, held 565 instructions and no branch, and that module was 56,763 bytes; every load called all four. Over the 1.0.2.1 corpus the 11,400 shaders that use this path all translate and pass \spirv-val\ (the previous translator included), and their modules shrink from 11,163,872,428 to 10,454,474,528 bytes (-6.35%). The 15,103 shaders without a run-time FORMAT come out byte for byte identical (checked on a 297-shader sample, every 51st of them). The values are unchanged: every one of the 128 codes gives the same words as the branch search, checked by `tests/semantic/test_format_decode_table.py` (each code against a reference decoded from the raw bits with exact quotients, plus the branch-free and shared shape). The old translation was confirmed on an RTX 4090 (621.01) against the decode-everything translation: identical output buffers for all 128 codes in four configurations (four byte alignments, out-of-range records, constant DST_SEL), xyzw and d16_xyzw. Since 2026-11-27 the component is the function's last parameter (154 instructions), and a load calls it once per register it writes, with the component that register's DST_SEL picks (DST_SEL − 4; a register whose DST_SEL is 0, 1 or reserved discards the call's value): `buffer_load_format_x` makes one call, not four. The values are the same by construction (the four components' channel width and offset are computed as before and the parameter selects one), checked against the previous translator by the mini interpreter on 22,528 loads (`_x` … `_xyzw` and `d16_x` … `d16_xyzw`, all 128 codes, random DST_SEL, byte alignments and out-of-range records) and on an RTX 4070 Laptop (621.40) by the typed-load GPU tests; `tests/semantic/test_buffer_format_decode_one.py` counts the calls. The function takes the format code, the element's four dwords as a `v4uint` and the component, so its function type has a structure of its own: a type of `uint` × 5 repeats the type of the `x_round` helpers, and SPIR-V forbids two non-aggregate types with the same structure. The branch-free decode costs more ALU per load than the search (every kind's conversion is computed and one is kept), so it trades run time for module size and compile time. | | 333 | | Bindless index in the T# | On the console a texture access loads the T# and samples; the hash-table lookup above made every access hash the eight T# words and probe up to eight table slots (in the tiled-lighting pixel shader, 62 lookups and 19,714 RADV instructions against 3,080 in the native program). **What pack and runtime agree on:** in every heap shaders read, the layer writes dword 6 of each T# as `0xA << 28 \| storage kind << 23 \| sampled kind << 16 \| index`: the tag `0xA` in [31:28], the table's storage kind bits 8..12 in [27:23], its sampled kind bits 0..6 in [22:16] and the bindless index in [15:0] (`runtime/src/gfx10_descriptors.h`, `tsharp_index_word`). **Index 0** is the fallback of the array the instruction reads: the word is 0 while the T# has no entry (no texture at its address yet, a stream pending, no room in its array), for index 0 itself and for an index past 16 bits, and a shader reads index and kind 0 unless the word has the tag **and** dword 3 names an image (TYPE 8..15, bit 31), so a V#, a data slot or a zero slot read as a T# never passes. Then, as for a table entry, the kind bit of the instruction's array decides between the index and that array's fallback. The heaps: the copies of the console resource heaps (`fix_console_slot`, fixed again whenever the texture at the T#'s address comes, goes or is replaced, or the T#'s entry is replaced) and the layer's own heaps (`write_image_descriptor`; `scan_title_table` refreshes bound tables; a view `LEONIDA_PIPELINE_COMPILE=on-demand` defers gets its word when it is made, `materialize_table`). Dword 6 is the hardware's compression metadata, which no Vulkan view uses; the title's own bytes and the T#'s table key keep the title's dword 6 (`tsharp_key` strips the word from bytes read back from the layer's heaps). **Translator** (`Gen.tsharp_index_sgpr`, `tools/descriptor_sources.py`): a forward SGPR dataflow over the basic blocks marks each image instruction whose T# dword 6 is dword 6 of a heap slot: an `s_load` from a 32-bit pointer in a user SGPR (a descriptor table or a directly indexed heap, `docs/d3d12_vulkan.md` section 3.4) at slot position 24 (a static offset is checked; a run-time one is the heap index times 32), followed through copies, joins of two such loads, SGPRs parked in VGPR lanes (`v_writelane`/`v_readlane`) and VCC used as two more SGPRs. Those instructions read index and kind from the word, with no memory access and no lookup. Any other T# keeps the lookup inside a uniform branch taken only when its dword 6 has no tag, so a heap T# the dataflow could not place costs no probe either (`Gen.tsharp_lookup`). S#s keep the lookup: the console sampler heaps are the title's pages read in place, and S#s have no free field. **Older packs** are told apart by the module meta: every module this translator writes has `"tsharp_index": "dword6"` (with its counts `tsharp_index_reads` and `tsharp_lookups`); the runtime counts them (`TsharpIndexCensus`) and writes the word when any module reads it, logging `T# index word: written into the heaps' T#s (all N modules)` or `not read`. A pack without the key keeps working as before: no word is written and its modules find every T# by its words. A library mixing both is logged, since its older modules then miss heap T#s (their copy's dword 6 is not the key). `LEONIDA_CONSOLE_HEAP_GPU`'s pass copies T#s as written, so with an index-word pack the resource heaps are fixed on the CPU (logged once, `runtime/README.md`). Modules change, so pipeline keys change with them. **Counts** (`tools/descriptor_source_census.py`): 1.0.2.1 carve, 26,503 listings: 439,415 image instructions with a T# in 17,540 modules; 437,263 take the whole T# from such a heap load (257,962 static, 179,301 run-time offset), 1,916 are lost at joins or computed, 235 come from another base, 1 from a 64-bit pointer, none from a title buffer through a V#, none built from constants and none edited in dword 6. No scalar instruction reads dword 5, 6 or 7 of a heap T# (dword 1: 8,065, 2: 12,069, 3: 9,177, 4: 3, 0: 1), so the shaders' own maths never sees the word. The translator marks 438,693 (99.84%; 17,474 of the 17,540 modules keep no T# lookup) before the VCC rule, which only adds. Pipeline library, 2,684 programs: 113,585 of 157,410 (72%; 1,649 of 2,235 modules), the rest mostly pointers rebuilt through paths the dataflow does not follow (those run the branch above). Of the carve's 366,628 S# operands, 188,732 come from heap loads, 146,036 are literal and 31,860 from elsewhere. **Cost**, RADV (Mesa 26.3.1) on an RX 7900 XTX, `vk_pipeline_check --stats`: the lighting shader above, instructions 19,714 → 17,568, latency 73,690 → 32,458, inverse throughput 16,453 → 7,468, spilled SGPRs 31 → 17 (its 20 remaining lookups are S#s); a heavy compute shader from the pipeline library (screen-probe ray activation), instructions 40,901 → 36,046, latency 88,291 → 52,359, inverse throughput 20,579 → 13,451, spilled SGPRs 1,007 → 43. **Checked by** `tests/semantic/test_tsharp_index_word.py` (the interpreter reads the image the word names with no table bound; an untagged word, a 3D kind for a 2D load, a dword 3 that names no image and a zero slot read the fallback; a 64-bit-pointer T# looks the table up only without the word; the fixture `ps_tsharp_index_word.s` with a T# loaded in either arm of a branch; the dataflow's static and run-time offsets, a slot read as two halves, VGPR-lane spills, VCC, and the sources that keep the lookup), `runtime/test/gfx10_descriptors_test.cpp` (the word's bits and the key), `shader_library_test` (the census) and the Wine suite's d3d12 tests, which read the word back through `bindless_hash_lookup`. GPU-checked on the Ryzen 9 7950X3D's integrated GPU (RADV RAPHAEL_MENDOCINO, Mesa 26.3.1): `ps_texture_sample` and `ps_table_fetch` load their T# through a table pointer as the title's shaders do and `vk_texture_test` writes the word: the gradient sample and 4096 exact pixels each for SINT, UINT and the miss control (a dword 6 without the tag reads index 0), with no T# lookup in either module. | |
| 334 | | Run-time format decode cost | A `buffer_load_format_*` whose format comes from the V# is decoded by table, without a branch: one shared function, `%fmt_dec(format, element, component)`, reads the format's kind, channel count and channel widths from the module table `%fmt_desc_tab`, and the kind picks the conversion with `OpSelect`; the exact UNORM/SNORM quotient comes from the shared `%fmt_norm_bits`, whose width's 64-bit repeat constant is read from `%fmt_norm_rep_tab`. A code outside the table gives zeros, a format with fewer channels repeats its own (component *c* = *c* mod *n*), and the element size is selected from the format alone (`%fmt_size_tab`), the per-lane byte offset added once. Until 2026-11-23 the shared function instead held every format's decode and a binary search over the codes (`OpSelectionMerge` with `DontFlatten`): 3,498 instructions and 306 branches in the module of a shader with one dynamic-format load (250,869 bytes). Then four functions, one per output component, held 565 instructions and no branch, and that module was 56,763 bytes; every load called all four. Over the 1.0.2.1 corpus the 11,400 shaders that use this path all translate and pass \spirv-val\ (the previous translator included), and their modules shrink from 11,163,872,428 to 10,454,474,528 bytes (-6.35%). The 15,103 shaders without a run-time FORMAT come out byte for byte identical (checked on a 297-shader sample, every 51st of them). The values are unchanged: every one of the 128 codes gives the same words as the branch search, checked by `tests/semantic/test_format_decode_table.py` (each code against a reference decoded from the raw bits with exact quotients, plus the branch-free and shared shape). The old translation was confirmed on an RTX 4090 (621.01) against the decode-everything translation: identical output buffers for all 128 codes in four configurations (four byte alignments, out-of-range records, constant DST_SEL), xyzw and d16_xyzw. Since 2026-11-27 the component is the function's last parameter, and a load calls it once per register it writes, with the component that register's DST_SEL picks (DST_SEL − 4; a register whose DST_SEL is 0, 1 or reserved discards the call's value): `buffer_load_format_x` makes one call, not four. The component decoder wraps the requested component to a source channel, extracts that channel's six-bit width, and sums the preceding widths for its bit offset. The earlier width selection could truncate a run-time R32_UINT (FORMAT 20) load in wave64-emulated compute on an RTX 5070 Ti (610.74). The synthetic GPU fixture `runtime/test/shaders/cs_w64x_dynamic_r32_uint.asm` checks that all 32 bits survive. The component-call lowering was checked against the previous translator by the mini interpreter on 22,528 loads (`_x` … `_xyzw` and `d16_x` … `d16_xyzw`, all 128 codes, random DST_SEL, byte alignments and out-of-range records) and on an RTX 4070 Laptop (621.40) by the typed-load GPU tests; `tests/semantic/test_buffer_format_decode_one.py` counts the calls. The function takes the format code, the element's four dwords as a `v4uint` and the component, so its function type has a structure of its own: a type of `uint` × 5 repeats the type of the `x_round` helpers, and SPIR-V forbids two non-aggregate types with the same structure. The branch-free decode costs more ALU per load than the search (every kind's conversion is computed and one is kept), so it trades run time for module size and compile time. | | ||
| 333 | | 3D explicit-gradient texture samples | For `image_sample_d` and `image_sample_d_cl` on a 3D view, the first six address VGPRs contain dP/dx.xyz and dP/dy.xyz. XYZ and the optional minimum LOD follow. With `a16`, the six derivative VGPRs still hold f32; the following two words contain packed f16 coordinates and the optional clamp. The hand-written `tests/semantic/fixtures/volume_gradients.asm` checks the source registers of both gradients, coordinates and clamp. LLVM gfx1030 assembles all four forms and their modules validate for Vulkan 1.2. [LLVM GFX10 address sizing](https://reviews.llvm.org/D102231) and [SPIR-V Grad operands](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Image_Operands) | | 335 | | 3D explicit-gradient texture samples | For `image_sample_d` and `image_sample_d_cl` on a 3D view, the first six address VGPRs contain dP/dx.xyz and dP/dy.xyz. XYZ and the optional minimum LOD follow. With `a16`, the six derivative VGPRs still hold f32; the following two words contain packed f16 coordinates and the optional clamp. The hand-written `tests/semantic/fixtures/volume_gradients.asm` checks the source registers of both gradients, coordinates and clamp. LLVM gfx1030 assembles all four forms and their modules validate for Vulkan 1.2. [LLVM GFX10 address sizing](https://reviews.llvm.org/D102231) and [SPIR-V Grad operands](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Image_Operands) | |
| 334 | | `image_sample_c_l` | Scalar 2D depth comparison (`dmask:0x1`) takes the f32 reference, XY coordinates and explicit mip in that order. Under A16 the reference stays full-width; XY share a VGPR and LOD uses the next low half. D16 returns the comparison in the low half of the destination. Confirmed against LLVM AMDGPU's `llvm.amdgcn.image.sample[.a16].dim.ll` lowering and synthetic Vulkan 1.2 modules in `test_explicit_mip_depth_compare`. | | 336 | | `image_sample_c_l` | Scalar 2D depth comparison (`dmask:0x1`) takes the f32 reference, XY coordinates and explicit mip in that order. Under A16 the reference stays full-width; XY share a VGPR and LOD uses the next low half. D16 returns the comparison in the low half of the destination. Confirmed against LLVM AMDGPU's `llvm.amdgcn.image.sample[.a16].dim.ll` lowering and synthetic Vulkan 1.2 modules in `test_explicit_mip_depth_compare`. | |
| 335 | | Packed sample addresses | GFX10 `image_sample_d` with `a16` keeps the non-G16 gradients as f32 and packs the following coordinates as f16 pairs, following LLVM's GFX10 operand layout. `test_a16_sample_gradients_use_full_vgprs` checks the emitted gradient operands, and `ps_texture_grad_a16` checks coordinate selection with a single-mip texture on RTX 5080. The same holds for every extra argument before the coordinates (LLVM `getAddrSizeMIMGOp`: one word each, then the gradients, then the packed halves; llvm-mc takes `v[0:2]` for a 2D `image_sample_c_b ... a16`): an `image_sample_b` bias keeps its VGPR with the f16 in the low half, an `image_sample_c_lz` z-compare its f32 VGPR, and `image_sample_d_cl` its four f32 gradients, with the clamp the half right after the coordinates (an f16 pad may follow it). Until 2026-11-21 those were unpacked as pairs too, and the clamp was taken from the last half. GPU-checked on an NVIDIA GeForce RTX 2060 SUPER (Linux, driver 620.70.06) with `ps_texture_bias_a16`, `ps_sample_c_lz_a16` (`vk_texture_test dref_a16`) and `ps_texture_grad_cl_a16`, which draws on the `--two-mip` texture with the clamp 0 on the left half and 1 on the right: 4096/4096 pixels exact each. The old reading got 4,032 bias pixels and both depth-compare results in 2,048 pixels wrong, a clamp taken from the pad read mip 1 on the left half, and the sample without its clamp mip 0 on the right half (2,048 pixels each). | | 337 | | Packed sample addresses | GFX10 `image_sample_d` with `a16` keeps the non-G16 gradients as f32 and packs the following coordinates as f16 pairs, following LLVM's GFX10 operand layout. `test_a16_sample_gradients_use_full_vgprs` checks the emitted gradient operands, and `ps_texture_grad_a16` checks coordinate selection with a single-mip texture on RTX 5080. The same holds for every extra argument before the coordinates (LLVM `getAddrSizeMIMGOp`: one word each, then the gradients, then the packed halves; llvm-mc takes `v[0:2]` for a 2D `image_sample_c_b ... a16`): an `image_sample_b` bias keeps its VGPR with the f16 in the low half, an `image_sample_c_lz` z-compare its f32 VGPR, and `image_sample_d_cl` its four f32 gradients, with the clamp the half right after the coordinates (an f16 pad may follow it). Until 2026-11-21 those were unpacked as pairs too, and the clamp was taken from the last half. GPU-checked on an NVIDIA GeForce RTX 2060 SUPER (Linux, driver 620.70.06) with `ps_texture_bias_a16`, `ps_sample_c_lz_a16` (`vk_texture_test dref_a16`) and `ps_texture_grad_cl_a16`, which draws on the `--two-mip` texture with the clamp 0 on the left half and 1 on the right: 4096/4096 pixels exact each. The old reading got 4,032 bias pixels and both depth-compare results in 2,048 pixels wrong, a clamp taken from the pad read mip 1 on the left half, and the sample without its clamp mip 0 on the right half (2,048 pixels each). | |
| @@ -440,6 +442,7 @@ How the generated SPIR-V expects the runtime to work: | |||
| 440 | | 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`. | | 442 | | 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`. | |
| 441 | | 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`. | | 443 | | 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`. | |
| 442 | | 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 | | 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.** | |
| 445 | | Pure scalar-spill VGPRs (`v_writelane_b32` / `v_readlane_b32`) | A VGPR touched only by immediate-lane `v_writelane_b32` (non-VGPR source) and immediate-lane `v_readlane_b32` (never read or written as a vector operand, never aliased by `v_movrel*`/`v_swaprel_b32`, and with every read lane definitely written on all CFG paths before it is read) is lowered to parked `%sgpr` slots (`lane_masks.scalar_spills`, `Gen.scalar_spills`) across all stages and wave sizes (wave32 and wave64), instead of emitting `OpGroupNonUniformShuffle`. On RDNA2 hardware `v_writelane_b32`/`v_readlane_b32` ignore `EXEC` and access physical lane `K` even when lane `K` is inactive; in Vulkan SPIR-V, `OpGroupNonUniformShuffle` from an inactive or unlaunched invocation (e.g. a small fragment triangle or post-discard wave) is undefined and returns stale VGPR bits, which corrupted spilled V# base addresses in wave32 fragment shaders. Confirmed by corpus count over the full 1.0.2.1 shader corpus (`1,031` wave32 and `385` wave64 pure scalar-spill VGPRs, `0` mixed; all `1,173` `v_writelane_b32` shaders translate and pass `spirv-val`), CPU-checked by `tests/semantic/test_wave32_pixel_subgroup64.py` (`test_scalar_spill_vgpr_survives_absent_lanes`, absent lanes `0..3` and single-quad waves on 32- and 64-lane subgroups), and GPU-confirmed on an AMD Radeon RX 7900 XTX (RADV Mesa 26.3.1, two 240 s fast-load runs at `0.0 s` warm graphics PSO compile time, zero GPUVM faults). | | ||
| 443 | | Wave64 emulation: cross-lane reads of missing lanes | With `--wave64-emulate`, a read of another lane's exchange slot (`ds_swizzle_b32`, `ds_bpermute_b32`, `ds_permute_b32`'s targets and data, `v_readlane_b32`, `v_readfirstlane_b32`, DPP and the other reads behind `Gen.x_round`) gives 0 when the source lane doesn't exist in a partial last wave (`Gen.x_lane_word`: `x_wbase + lane < threads`, else 0), as a source lane that isn't running reads 0 on the hardware. The prologue still zeroes those slots, but a read must not depend on it: RADV (Mesa 26.3.1, gfx1036 iGPU and RX 7900 XTX) compiled the store, barrier and load of an exchange behind a branch into `masked_swizzle_amd` with `fetch_inactive` (`RADV_DEBUG=shaders`), so in a 40-thread group lanes 32-39 of `ds_swizzle_b32 offset:swizzle(SWAP,8)` read the missing lanes' registers, garbage that changed between runs. Workgroups whose size is a multiple of 64 emit the same module as before. Confirmed by `runtime/test/shaders/cs_w64x_partial_swizzle.asm` (40 threads: SWAP 8, BROADCAST 16,15 and `ds_bpermute_b32` from lanes 40-47; its 8 words measured natively on gfx1036 through `tools/hw_oracle`): emulated at subgroup 32 (RADV, Mesa 26.3.1), words 2 and 3 wrong before in 20 of 20 runs on the gfx1036 iGPU and 19 of 20 on the RX 7900 XTX, and all 8 words right in 20 of 20 runs on both after; native wave64 and emulated at subgroup 64 right both times. `scripts/run_gpu_tests.py` runs the partial-wave fixtures emulated at subgroup 32, as `check.py` does, since at RADV's default of 64 this fixture passed before the change too; by `crosslane_fuzz.py --wave 64 --ext --dpp --no-maskdata --programs 1000 --seed 48315`, emulated: on the gfx1036 iGPU 993 match and 7 hyp_only (all 40-thread groups, lanes 32-39 reading a swizzle source of 40-47) before, 1000/1000 after, and on the RX 7900 XTX 995 match and 5 hyp_only before, 1000/1000 after; and by `tests/semantic/test_w64x_partial_swizzle.py` (fixture `w64x_partial_swizzle.asm`, 40 and 104 threads, the prologue's zero stores replaced by a poison word in the workgroup interpreter; both cases fail before the change). | | 446 | | Wave64 emulation: cross-lane reads of missing lanes | With `--wave64-emulate`, a read of another lane's exchange slot (`ds_swizzle_b32`, `ds_bpermute_b32`, `ds_permute_b32`'s targets and data, `v_readlane_b32`, `v_readfirstlane_b32`, DPP and the other reads behind `Gen.x_round`) gives 0 when the source lane doesn't exist in a partial last wave (`Gen.x_lane_word`: `x_wbase + lane < threads`, else 0), as a source lane that isn't running reads 0 on the hardware. The prologue still zeroes those slots, but a read must not depend on it: RADV (Mesa 26.3.1, gfx1036 iGPU and RX 7900 XTX) compiled the store, barrier and load of an exchange behind a branch into `masked_swizzle_amd` with `fetch_inactive` (`RADV_DEBUG=shaders`), so in a 40-thread group lanes 32-39 of `ds_swizzle_b32 offset:swizzle(SWAP,8)` read the missing lanes' registers, garbage that changed between runs. Workgroups whose size is a multiple of 64 emit the same module as before. Confirmed by `runtime/test/shaders/cs_w64x_partial_swizzle.asm` (40 threads: SWAP 8, BROADCAST 16,15 and `ds_bpermute_b32` from lanes 40-47; its 8 words measured natively on gfx1036 through `tools/hw_oracle`): emulated at subgroup 32 (RADV, Mesa 26.3.1), words 2 and 3 wrong before in 20 of 20 runs on the gfx1036 iGPU and 19 of 20 on the RX 7900 XTX, and all 8 words right in 20 of 20 runs on both after; native wave64 and emulated at subgroup 64 right both times. `scripts/run_gpu_tests.py` runs the partial-wave fixtures emulated at subgroup 32, as `check.py` does, since at RADV's default of 64 this fixture passed before the change too; by `crosslane_fuzz.py --wave 64 --ext --dpp --no-maskdata --programs 1000 --seed 48315`, emulated: on the gfx1036 iGPU 993 match and 7 hyp_only (all 40-thread groups, lanes 32-39 reading a swizzle source of 40-47) before, 1000/1000 after, and on the RX 7900 XTX 995 match and 5 hyp_only before, 1000/1000 after; and by `tests/semantic/test_w64x_partial_swizzle.py` (fixture `w64x_partial_swizzle.asm`, 40 and 104 threads, the prologue's zero stores replaced by a poison word in the workgroup interpreter; both cases fail before the change). | |
| 444 | | Barycentric fallback (`--bary-fallback`) | For devices without `VK_KHR_fragment_shader_barycentric` (NVIDIA Pascal, for one), and for Mesa ANV's known BaryCoordKHR.i bug (SHADER-925). The raw pair a PS reads comes from an ordinary vec3 input, `%bary`, at the lowest location none of the shader's attributes uses, instead of `BuiltIn BaryCoordKHR`. The module needs neither the `FragmentBarycentricKHR` capability nor the extension, and the index records the location as `bary_fallback_input`. `tools/bary_fallback_gs.py` writes a pass-through geometry shader that supplies (1,0,0), (0,1,0), (0,0,1) at the triangle vertices. GPU-checked on NVIDIA Pascal and Intel Arc B580/Mesa ANV: ANV native `ps_uniform_branch` and `ps_scc_mask32` fail with i=0.0, while the fallback passes and `ps_bary` passes natively. `make_game.py` and `scripts/run_gpu_tests.py` select the fallback automatically for Mesa ANV. `LEONIDA_BARY_FALLBACK=1` forces fallback and `LEONIDA_BARY_FALLBACK=0` forces native barycentrics consistently in both entry points; explicit `--bary-fallback` also forces the fallback in `make_game.py`. The standalone `build.py`/`check.py` path follows the same variable/probe rule. Checked in `tests/semantic/test_bary_fallback.py` and the builder/runner wiring tests. | | 447 | | Barycentric fallback (`--bary-fallback`) | For devices without `VK_KHR_fragment_shader_barycentric` (NVIDIA Pascal, for one), and for Mesa ANV's known BaryCoordKHR.i bug (SHADER-925). The raw pair a PS reads comes from an ordinary vec3 input, `%bary`, at the lowest location none of the shader's attributes uses, instead of `BuiltIn BaryCoordKHR`. The module needs neither the `FragmentBarycentricKHR` capability nor the extension, and the index records the location as `bary_fallback_input`. `tools/bary_fallback_gs.py` writes a pass-through geometry shader that supplies (1,0,0), (0,1,0), (0,0,1) at the triangle vertices. GPU-checked on NVIDIA Pascal and Intel Arc B580/Mesa ANV: ANV native `ps_uniform_branch` and `ps_scc_mask32` fail with i=0.0, while the fallback passes and `ps_bary` passes natively. `make_game.py` and `scripts/run_gpu_tests.py` select the fallback automatically for Mesa ANV. `LEONIDA_BARY_FALLBACK=1` forces fallback and `LEONIDA_BARY_FALLBACK=0` forces native barycentrics consistently in both entry points; explicit `--bary-fallback` also forces the fallback in `make_game.py`. The standalone `build.py`/`check.py` path follows the same variable/probe rule. Checked in `tests/semantic/test_bary_fallback.py` and the builder/runner wiring tests. | |
| 445 | | Wave64 emulation: a folded region at most one lane runs (SHADER-W64-ONE-LANE-FOLD) | A compute shader picks one thread for a tail (clear LDS, then after a barrier sum it up and store) with `v_cmpx_eq_u32 c, v0` or `v_cmp_eq_u32 m, c, v0` + `s_and_saveexec_b64 _, m`. `v0` is LocalInvocationId.x and a wave is 64 consecutive threads, so no two lanes of a wave share it when the group is one row (`size_y * size_z == 1`) or a row is whole waves (`size_x % 64 == 0`); then the compare is true in at most one lane. `_one_lane_in` in `tools/wave64_emulate_opt.py` proves per block, forward over the CFG with intersection at joins, that EXEC is at most one lane: `v0` must not have been written since entry, and the mask goes on through `s_mov_b64`, `s_and_b64` with anything, `s_andn2_b64` of it, a saveexec of it and any later compare (a compare is 0 in inactive lanes). A write of one half of EXEC (`exec_lo`/`exec_hi`, which the emitter writes as that half only) keeps the fact only when EXEC already had it and the half written is within it (a compare): the other half keeps its lanes, so `v_cmp_eq_u32 exec_lo, 0, v0` from a full EXEC leaves lanes 32-63 on. The assembler's short form `v_add_co_ci_u32 vD, src0, src1` (also `sub`, `subrev`) gets its VCC carry-out and carry-in operands when the listing is read (`explicit_carry_vcc` in `tools/rdna2spirv.py`), so every analysis sees the VCC it writes. Where `run` of an `s_cbranch_execz` region is proved so, `find_local_exec_folds` drops the one-store-per-domain and acyclic limits and marks the fold `one_lane` (the region's EXEC writes already must keep a skipped lane inactive, so it stays at most one lane): with one lane the lane's own order of its accesses is the wave's, so `x_memory_order` orders nothing inside it. A one-block region that branches back to itself is emitted as a loop through `cfg_structure.structure` like a multi-block region; emitted straight it ran once (also for a read-only loop, before this row). A `v_readfirstlane_b32` is allowed in such a fold when the region writes no EXEC at all: the lane runs the fold only when active, so it is the first lane of EXEC and the result is its own value (also into `vcc_lo`/`vcc_hi`). Confirmed on the CPU against the plain round emulation in both invocation orders: `tests/semantic/test_wave64_one_lane_fold.py` (128 threads; LDS writes, a barrier, first-lane reads and two stores to one address; a lane of wave 0, of wave 1, or none; the negatives `v_cmpx_eq` of a non-id VGPR, `v0` overwritten, `v_cmpx_gt`, and a 32 x 4 group are not marked one-lane; picks in lanes 32-63 of either wave; a one-block self-loop with and without a store, which ran once before; `v_cmp_eq_u32_e64 exec_lo, 0, v0` from a full EXEC, which was marked one-lane before; and the short and explicit `v_add_co_ci_u32` carry into VCC after a one-lane compare, whose short form was marked one-lane before). One 1024-thread library compute shader goes from 639 to 33 `OpSwitch` cases and passes `spirv-val`. **Not GPU-verified.** | | 448 | | Wave64 emulation: a folded region at most one lane runs (SHADER-W64-ONE-LANE-FOLD) | A compute shader picks one thread for a tail (clear LDS, then after a barrier sum it up and store) with `v_cmpx_eq_u32 c, v0` or `v_cmp_eq_u32 m, c, v0` + `s_and_saveexec_b64 _, m`. `v0` is LocalInvocationId.x and a wave is 64 consecutive threads, so no two lanes of a wave share it when the group is one row (`size_y * size_z == 1`) or a row is whole waves (`size_x % 64 == 0`); then the compare is true in at most one lane. `_one_lane_in` in `tools/wave64_emulate_opt.py` proves per block, forward over the CFG with intersection at joins, that EXEC is at most one lane: `v0` must not have been written since entry, and the mask goes on through `s_mov_b64`, `s_and_b64` with anything, `s_andn2_b64` of it, a saveexec of it and any later compare (a compare is 0 in inactive lanes). A write of one half of EXEC (`exec_lo`/`exec_hi`, which the emitter writes as that half only) keeps the fact only when EXEC already had it and the half written is within it (a compare): the other half keeps its lanes, so `v_cmp_eq_u32 exec_lo, 0, v0` from a full EXEC leaves lanes 32-63 on. The assembler's short form `v_add_co_ci_u32 vD, src0, src1` (also `sub`, `subrev`) gets its VCC carry-out and carry-in operands when the listing is read (`explicit_carry_vcc` in `tools/rdna2spirv.py`), so every analysis sees the VCC it writes. Where `run` of an `s_cbranch_execz` region is proved so, `find_local_exec_folds` drops the one-store-per-domain and acyclic limits and marks the fold `one_lane` (the region's EXEC writes already must keep a skipped lane inactive, so it stays at most one lane): with one lane the lane's own order of its accesses is the wave's, so `x_memory_order` orders nothing inside it. A one-block region that branches back to itself is emitted as a loop through `cfg_structure.structure` like a multi-block region; emitted straight it ran once (also for a read-only loop, before this row). A `v_readfirstlane_b32` is allowed in such a fold when the region writes no EXEC at all: the lane runs the fold only when active, so it is the first lane of EXEC and the result is its own value (also into `vcc_lo`/`vcc_hi`). Confirmed on the CPU against the plain round emulation in both invocation orders: `tests/semantic/test_wave64_one_lane_fold.py` (128 threads; LDS writes, a barrier, first-lane reads and two stores to one address; a lane of wave 0, of wave 1, or none; the negatives `v_cmpx_eq` of a non-id VGPR, `v0` overwritten, `v_cmpx_gt`, and a 32 x 4 group are not marked one-lane; picks in lanes 32-63 of either wave; a one-block self-loop with and without a store, which ran once before; `v_cmp_eq_u32_e64 exec_lo, 0, v0` from a full EXEC, which was marked one-lane before; and the short and explicit `v_add_co_ci_u32` carry into VCC after a one-lane compare, whose short form was marked one-lane before). One 1024-thread library compute shader goes from 639 to 33 `OpSwitch` cases and passes `spirv-val`. **Not GPU-verified.** | |
| @@ -449,7 +452,8 @@ How the generated SPIR-V expects the runtime to work: | |||
| 449 | | Wave-uniform branches | VCC and EXEC are wave-wide registers, but one invocation holds only its own lane's bit. `s_cbranch_vccz/vccnz/execz/execnz` therefore reduce the condition across the subgroup (`OpGroupNonUniformAny`), so the whole wave takes the branch together, as on hardware. Before this, each lane decided alone. A lane could skip scalar instructions that the hardware wave executes (its SGPRs went stale for later code), and cross-lane ops or barriers inside the block saw a split wave. `v_cmp`/`v_cmp_class`/64-bit compares now write 0 for inactive lanes (hardware VOPC behaviour), so the reduction sees the true mask. GPU-checked with `runtime/test/shaders/ps_uniform_branch.asm`: lanes whose own VCC bit is 0 run the block's scalar add when their wave has any set bit. `s_cbranch_scc0/1` stay per lane; SCC is uniform as long as the SGPRs feeding it are. | | 452 | | Wave-uniform branches | VCC and EXEC are wave-wide registers, but one invocation holds only its own lane's bit. `s_cbranch_vccz/vccnz/execz/execnz` therefore reduce the condition across the subgroup (`OpGroupNonUniformAny`), so the whole wave takes the branch together, as on hardware. Before this, each lane decided alone. A lane could skip scalar instructions that the hardware wave executes (its SGPRs went stale for later code), and cross-lane ops or barriers inside the block saw a split wave. `v_cmp`/`v_cmp_class`/64-bit compares now write 0 for inactive lanes (hardware VOPC behaviour), so the reduction sees the true mask. GPU-checked with `runtime/test/shaders/ps_uniform_branch.asm`: lanes whose own VCC bit is 0 run the block's scalar add when their wave has any set bit. `s_cbranch_scc0/1` stay per lane; SCC is uniform as long as the SGPRs feeding it are. | |
| 450 | | Compute shaders | FSSM header word **0x138 = `COMPUTE_PGM_RSRC2`**: USER_SGPR [5:1], TGID_X/Y/Z_EN [9:7], TG_SIZE_EN [10], TIDIG_COMP_CNT [12:11], LDS_SIZE [23:15] in 512-byte units. Words **0x13C/0x140/0x144 = thread-group size**. Counted over all 2,689 CS listings of 1.0.2.1 by the SGPRs each reads before writing (operand roles from `shader_meta._split_operands`, over the code `translate()` keeps; in wave64 code a lane mask printed as one SGPR covers the pair; an earlier check gave 2,281 exact): 2,540 read nothing past the user SGPRs and enabled TGIDs (2,193 up to the last of them, 342 fewer, 5 none), and the other 149 overshoot only through loop-carried registers in the straight-line check: every extra read follows a branch, and the register is written later in program order. Followed through the CFG (written on every path before the read), 22 still overshoot; each extra register is written on some other path (only loop-carried ones in 15), so these are values undefined on some path, not a missing input. Read raw, 268 overshoot: the other 119 are listings with embedded data words, decoded as instructions. 0x110, which looked similar, doesn't match. Layout: s0..user−1 = user data (push constants), then the enabled workgroup IDs (`WorkgroupId`), and v0/v1/v2 = thread ID x/y/z (`LocalInvocationId`, separate VGPRs on GFX10). Example: the 1,013 shaders with RSRC2 `0x998` have 12 user SGPRs, group ID x/y in s12/s13, and compute x = s12·32 + v0. With TG_SIZE_EN (none of the 2,689; 91 compute programs of the pipeline library, [shader_library.md](shader_library.md)) the next SGPR is the thread-group word, which the prologue writes: the number of waves in the group in bits [5:0] and this wave's index in it in bits [11:6], the wave index again in bits [24:20] and bit 31 set in the group's first wave (measured on gfx1036 through `tools/hw_oracle`, #6446: wave32 x 128 threads gives `80000004 00100044 00200084 003000c4`; one library program reads [24:20]; not measured on gfx1013) (Mesa `ac_nir_lower_intrinsics_to_args.c`, GFX6-10: `load_num_subgroups` and `load_subgroup_id` read those fields, and a wave64 compute shader's local invocation index is `mbcnt(~0, tg_size & 0xfc0)`; the library programs read it as `s_and_b32 sN, sTG, 0xfc0`, most of them then `v_mbcnt_lo_u32_b32`). Thread i is in wave i / W, as for `s_get_waveid_in_workgroup`. CPU-checked by `tests/semantic/test_cs_tg_size.py`, including the gfx1036 words. GPU-checked with `runtime/test/shaders/cs_lds.asm` through `runtime/test/vk_compute_test.cpp`: 4 groups × 64 threads, LDS exchange between the two waves of a group behind `s_barrier`, store through a V# into the device-address heap, 0 mismatches. | | 453 | | Compute shaders | FSSM header word **0x138 = `COMPUTE_PGM_RSRC2`**: USER_SGPR [5:1], TGID_X/Y/Z_EN [9:7], TG_SIZE_EN [10], TIDIG_COMP_CNT [12:11], LDS_SIZE [23:15] in 512-byte units. Words **0x13C/0x140/0x144 = thread-group size**. Counted over all 2,689 CS listings of 1.0.2.1 by the SGPRs each reads before writing (operand roles from `shader_meta._split_operands`, over the code `translate()` keeps; in wave64 code a lane mask printed as one SGPR covers the pair; an earlier check gave 2,281 exact): 2,540 read nothing past the user SGPRs and enabled TGIDs (2,193 up to the last of them, 342 fewer, 5 none), and the other 149 overshoot only through loop-carried registers in the straight-line check: every extra read follows a branch, and the register is written later in program order. Followed through the CFG (written on every path before the read), 22 still overshoot; each extra register is written on some other path (only loop-carried ones in 15), so these are values undefined on some path, not a missing input. Read raw, 268 overshoot: the other 119 are listings with embedded data words, decoded as instructions. 0x110, which looked similar, doesn't match. Layout: s0..user−1 = user data (push constants), then the enabled workgroup IDs (`WorkgroupId`), and v0/v1/v2 = thread ID x/y/z (`LocalInvocationId`, separate VGPRs on GFX10). Example: the 1,013 shaders with RSRC2 `0x998` have 12 user SGPRs, group ID x/y in s12/s13, and compute x = s12·32 + v0. With TG_SIZE_EN (none of the 2,689; 91 compute programs of the pipeline library, [shader_library.md](shader_library.md)) the next SGPR is the thread-group word, which the prologue writes: the number of waves in the group in bits [5:0] and this wave's index in it in bits [11:6], the wave index again in bits [24:20] and bit 31 set in the group's first wave (measured on gfx1036 through `tools/hw_oracle`, #6446: wave32 x 128 threads gives `80000004 00100044 00200084 003000c4`; one library program reads [24:20]; not measured on gfx1013) (Mesa `ac_nir_lower_intrinsics_to_args.c`, GFX6-10: `load_num_subgroups` and `load_subgroup_id` read those fields, and a wave64 compute shader's local invocation index is `mbcnt(~0, tg_size & 0xfc0)`; the library programs read it as `s_and_b32 sN, sTG, 0xfc0`, most of them then `v_mbcnt_lo_u32_b32`). Thread i is in wave i / W, as for `s_get_waveid_in_workgroup`. CPU-checked by `tests/semantic/test_cs_tg_size.py`, including the gfx1036 words. GPU-checked with `runtime/test/shaders/cs_lds.asm` through `runtime/test/vk_compute_test.cpp`: 4 groups × 64 threads, LDS exchange between the two waves of a group behind `s_barrier`, store through a V# into the device-address heap, 0 mismatches. | |
| 451 | | 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. | | 454 | | 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. | |
| 452 | | 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). | | 455 | | 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 one `OpSDot` (row *Packed 4x8-bit dot products as SPV_KHR_integer_dot_product*), or with `--integer-dot-fallback` 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). | |
| 456 | | Packed 4x8-bit dot products as SPV_KHR_integer_dot_product | `v_dot4_i32_i8`, `v_dot4c_i32_i8`, `v_dot4_u32_u8` and `v_dot4c_u32_u8` are one instruction of SPV_KHR_integer_dot_product on the two dwords read as `PackedVectorFormat4x8Bit` (`Gen.packed_dot4`): `OpSDot` on `%int` operands for the signed bytes, `OpUDot` for the unsigned ones, and the addend (S2, or the old D of the VOP2 forms) added with `OpIAdd`, which wraps at 32 bits as the instructions do; under `clamp`, `OpSDotAccSat` / `OpUDotAccSat`, which saturate the addend plus the exact sum to the result's signed or unsigned range, as the hardware does (the *Signed-byte dot products* and *Packed integer dot products* rows; the spec computes both "with enough precision to avoid overflow", so the plain forms are the low 32 bits of the exact sum). `op_sel` / `op_sel_hi` on S0 and S1 of `v_dot4_i32_i8` pick 16-bit halves (measured, row above): `Gen.dot4_halves` puts the two halves together into one dword first (two `OpBitFieldUExtract` and one `OpBitFieldInsert`; nothing for the default). Capabilities `DotProductKHR` and `DotProductInput4x8BitPackedKHR`, extension `SPV_KHR_integer_dot_product`, index feature `shaderIntegerDotProduct`, which Vulkan 1.3 requires and the runtime enables (`runtime/src/vulkan13_features.h`; it logs `the GPU has no shaderIntegerDotProduct` without it). The 16-bit forms (`v_dot2_*`) match `OpSDot` / `OpUDot` on 16-bit vectors too, but need `Int16` and `DotProductInputAllKHR` and no module of the corpus has one, so they keep the expanded form, as `v_dot8_*` (4-bit elements have no SPIR-V form). **`--integer-dot-fallback`** keeps the expanded form (four extracts, multiplies and adds) for a device without the feature: `tools/vk_subgroup_info.py` reports `integer_dot_product`, and `make_game.py` turns the flag on where it is false (a Vulkan 1.2 device such as MoltenVK's), as it does `--f16-interp-fallback`. Why: RADV (Mesa 26.3.1) does not re-form `v_dot4` from the expansion, so each one was about 16 VALU instructions. **Confirmed** by `tests/semantic/test_packed_dot4.py` (fixtures `packed_dot4_i8.asm` and `packed_dot4_u8.asm`: the gfx1036-measured words of `test_alu_dot4_i8.py`, both saturations, `op_sel` against the measured rule, the same words under the fallback), `tools/dot_diff.py` (767 of 767 programs on the four ops, 30/34 and 54/57 saturated / wrapped edge results), a wave32 compute program on the GPU with both forms on the Radeon iGPU (gfx1036, RADV 26.3.1) and the RX 7900 XTX: the same eight words, seven of them the gfx1036 hardware measurements (wrapping and clamped sums, `v_dot4c_i32_i8`, mixed-sign bytes) and the eighth the unsigned reference. RADV statistics (`vk_pipeline_check --stats`, RX 7900 XTX) for the FidelityFX passes: `amd_fidelityfx_upscaler_xbox_04` 16,166 → 7,463 instructions, 216 → 96 VGPRs, 7 → 16 waves per SIMD; `_09` 106,348 → 74,888, `_06` 164,387 → 116,896 and `_08` 108,503 → 75,465 instructions with 192 → 120 VGPRs and 8 → 12 waves (static counts with this rule and the *Wide scalar loads* one, which include the per-dword path that row keeps for partly out-of-range loads; the dot products alone gave 105,726 for `_06`); `_27`, without `v_dot4`, 10,019 → 10,027. A synthetic program of 1,024 `v_dot4c_i32_i8` with distinct weights runs in 0.55 ms instead of 5.45 ms on the RX 7900 XTX (the same output words) per 65,536 groups. Count over the corpus (1.0.2.1): the four ops are in 13 modules, all FidelityFX DLL programs (`v_dot4c_i32_i8` 25,813, `v_dot4_i32_i8` 1,458 plain and 89 with `op_sel`; no `clamp`, no `u8` form); translating the 25,878 modules either rule touches gives 25,877 translated and 25,877 passing `spirv-val` before and after (the one left is a pipeline-library program that fails the same way before). | | ||
| 453 | | 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. | | 457 | | 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. | |
| 454 | | 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. | | 458 | | 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. | |
| 455 | | 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. | | 459 | | 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. | |
| @@ -495,7 +499,7 @@ How the generated SPIR-V expects the runtime to work: | |||
| 495 | | Scalar select and pack (`s_cmov_b32`, `s_cmovk_i32`, `s_cmov_b64`, `s_pack_ll/lh/hh_b32_b16`) | `s_cmov_b32` / `s_cmovk_i32`: D = SCC ? S0 : D (`s_cmovk_i32`'s S0 is the 16-bit immediate, sign-extended); SCC is read, not written; the destination must be an SGPR (a lane-mask destination stays `Unsupported`, #210). `s_cmov_b64`: D[63:0] = SCC ? S0[63:0] : D[63:0] on plain 64-bit data pairs (SGPR pair, immediate or `null`), SCC read and not written; a pair that is or has been a lane mask (EXEC, VCC or a mask SGPR) stays `Unsupported` (#210) — conservatively, because a CFG join can drop a register that is a mask on only one path — while 0/-1 EITHER constants are data; selecting a per-lane bit as data would silently return a bool instead of the wave's mask. D[63:0] on plain 64-bit data pairs (SGPR pair, immediate or `null`), SCC read and not written; a pair that is or has been a lane mask stays `Unsupported` (#210). D[63:0], SCC read and not written, on plain 64-bit data pairs (SGPR pair, immediate or `null`); any dword that is or has been a lane mask (EXEC, VCC or a mask SGPR) makes the pair `Unsupported` — conservatively, because a CFG join can drop a register that is a mask on only one path — while 0/-1 EITHER constants are data; selecting a per-lane bit as data would silently return a bool instead of the wave's mask (#210). `s_pack_*`: the low half of D from S0, the high half from S1, the letters naming the half of each (l = 15:0, h = 31:16), S0 first; GFX10 has no `s_pack_hl`; SCC not written. Source: RDNA2 ISA SOP1/SOP2/SOPK and LLVM AMDGPU `SOPInstructions.td` (`S_CMOV_B64 : RDNA2 ISA SOP1/SOP2/SOPK. CPU-checked by `tests/semantic/test_salu_cmov.py` and `test_salu_pack.py`; the translated shaders were run on NVIDIA by reviewers (`s_cmov*`: RDNA2 ISA SOP1/SOP2/SOPK and LLVM AMDGPU [SOPInstructions.td](https://github.com/llvm/llvm-project/blob/2bfedf3338162e2c841a73cd7cd9e98d00add608/llvm/lib/Target/AMDGPU/SOPInstructions.td) (`S_CMOV_B64 : SOP1_64` under `Uses = [SCC]`). CPU-checked by `tests/semantic/test_salu_cmov.py`, `tests/semantic/test_salu_cmov_b64.py` and `test_salu_pack.py`; no corpus count; **not GPU-verified, no corpus count**; the translated shaders were run on NVIDIA by reviewers (`s_cmov_b32/k_i32`: **no corpus count**; Hardware: on native `gfx1036` (Ryzen 9 9950X3D iGPU, Windows 11, driver 26.10.1) `tools/int_hw_probe.py --oracle both --wave both` matches the translator in wave32 and wave64 for all five `salu_cmov_pack` cases and for the 14 `s_cmov_b64` cases (`--group salu_cmov_b64`: GPU-checked for `s_cmov_b32` (`cs_w32_salu64.asm`, SCC = 1 selects S0) and `s_pack_lh_b32_b16` (`cs_w32_int_ext.asm`) on the Radeon iGPU of a Ryzen 9 9950X3D (RDNA2, `gfx1036`, driver 26.10.1) and an RTX 5080 (driver 616.92); `s_cmovk_i32`, `s_cmov_b64` and the other `s_pack_*` forms have no GPU test on main; the translated shaders were also run on NVIDIA by reviewers (`s_cmov_b32/k_i32`: RTX 5090, RTX 4050 and Radeon 740M in #613; `s_pack_*`: RTX 5090 in #449). **Hardware-verified on RDNA2** (`gfx1035`, wave32 and wave64 via `tools/int_hw_probe.py --oracle both`, SHADER-137, SCC kept), and on native gfx1036 (AMD Radeon Graphics, Windows 11, driver 26.10.1) through `tools/hw_oracle`: all five `salu_cmov_pack` cases and the 14 `s_cmov_b64` cases match the translator in wave32 and wave64 (SCC 0 and 1; an SGPR pair, the inline constants -1/-16/64, the literal 0x89abcdef, `null` and the destination itself; SCC = 1 takes S0, 0 keeps D, SCC is never written), `s_cmov_b32` matches under SCC=0 and SCC=1, and `s_pack_ll/lh/hh_b32_b16` is bit-exact on 500 random programs with 0 mismatches (`--oracle translator,hw`). **Hardware-verified on RDNA2** (`gfx1035`, wave32 and wave64 via `tools/int_hw_probe.py --oracle both`, SHADER-137, SCC kept). Also **measured on RDNA2 gfx1036** (Radeon iGPU of a Ryzen 9 9950X3D, Windows 11, driver 26.10.1, `tools/hw_oracle` HIP launcher, rocm-sdk-core clang): `tools/int_hw_probe.py --oracle both --wave both` gives the same words as the translator for all five `salu_cmov_pack` cases in wave32 and wave64, and the 14 `s_cmov_b64` cases of the `salu_cmov_b64` group (`python -I tools/int_hw_probe.py --oracle both --wave both --group salu_cmov_b64`; SCC 0 and 1; source an SGPR pair, the inline constants -1, -16 and 64, the literal 0x89abcdef, `null`, and the destination itself; SCC preset and read back after): SCC preset and read back after) match the translator in wave32 and wave64: SCC = 1 takes S0 (a literal zero-extended, an inline constant sign-extended, `null` gives 0), SCC = 0 keeps D, SCC is never written. Also on `gfx1035` via `int_hw_probe` (SHADER-137, SCC kept), and on `gfx1036` and an RTX 5080 through the fixtures `cs_w32_salu64.asm` (`s_cmov_b32`) and `cs_w32_int_ext.asm` (`s_pack_lh_b32_b16`). `tools/hw_oracle` + `tools/salu_diff.py` verify `s_cmov_b32` under SCC 0/1 and `s_pack_ll/lh/hh_b32_b16` bit-exact on 500 random programs with 0 mismatches. Reviewers ran `s_cmov*` on an RTX 5090, an RTX 4050 and a Radeon 740M (#613) and `s_pack_*` on an RTX 5090 (#449). Measured on native gfx1036 (AMD Radeon Graphics, RDNA2) through tools/hw_oracle and tools/salu_diff.py: s_cmov_b32 verified under SCC=0 and SCC=1 (preserving destination and updating respectively); s_pack_ll/lh/hh_b32_b16 verified bit-exact on 500 random programs with 0 mismatches (--oracle translator,hw). **Not measured on RDNA2.** | | 499 | | Scalar select and pack (`s_cmov_b32`, `s_cmovk_i32`, `s_cmov_b64`, `s_pack_ll/lh/hh_b32_b16`) | `s_cmov_b32` / `s_cmovk_i32`: D = SCC ? S0 : D (`s_cmovk_i32`'s S0 is the 16-bit immediate, sign-extended); SCC is read, not written; the destination must be an SGPR (a lane-mask destination stays `Unsupported`, #210). `s_cmov_b64`: D[63:0] = SCC ? S0[63:0] : D[63:0] on plain 64-bit data pairs (SGPR pair, immediate or `null`), SCC read and not written; a pair that is or has been a lane mask (EXEC, VCC or a mask SGPR) stays `Unsupported` (#210) — conservatively, because a CFG join can drop a register that is a mask on only one path — while 0/-1 EITHER constants are data; selecting a per-lane bit as data would silently return a bool instead of the wave's mask. D[63:0] on plain 64-bit data pairs (SGPR pair, immediate or `null`), SCC read and not written; a pair that is or has been a lane mask stays `Unsupported` (#210). D[63:0], SCC read and not written, on plain 64-bit data pairs (SGPR pair, immediate or `null`); any dword that is or has been a lane mask (EXEC, VCC or a mask SGPR) makes the pair `Unsupported` — conservatively, because a CFG join can drop a register that is a mask on only one path — while 0/-1 EITHER constants are data; selecting a per-lane bit as data would silently return a bool instead of the wave's mask (#210). `s_pack_*`: the low half of D from S0, the high half from S1, the letters naming the half of each (l = 15:0, h = 31:16), S0 first; GFX10 has no `s_pack_hl`; SCC not written. Source: RDNA2 ISA SOP1/SOP2/SOPK and LLVM AMDGPU `SOPInstructions.td` (`S_CMOV_B64 : RDNA2 ISA SOP1/SOP2/SOPK. CPU-checked by `tests/semantic/test_salu_cmov.py` and `test_salu_pack.py`; the translated shaders were run on NVIDIA by reviewers (`s_cmov*`: RDNA2 ISA SOP1/SOP2/SOPK and LLVM AMDGPU [SOPInstructions.td](https://github.com/llvm/llvm-project/blob/2bfedf3338162e2c841a73cd7cd9e98d00add608/llvm/lib/Target/AMDGPU/SOPInstructions.td) (`S_CMOV_B64 : SOP1_64` under `Uses = [SCC]`). CPU-checked by `tests/semantic/test_salu_cmov.py`, `tests/semantic/test_salu_cmov_b64.py` and `test_salu_pack.py`; no corpus count; **not GPU-verified, no corpus count**; the translated shaders were run on NVIDIA by reviewers (`s_cmov_b32/k_i32`: **no corpus count**; Hardware: on native `gfx1036` (Ryzen 9 9950X3D iGPU, Windows 11, driver 26.10.1) `tools/int_hw_probe.py --oracle both --wave both` matches the translator in wave32 and wave64 for all five `salu_cmov_pack` cases and for the 14 `s_cmov_b64` cases (`--group salu_cmov_b64`: GPU-checked for `s_cmov_b32` (`cs_w32_salu64.asm`, SCC = 1 selects S0) and `s_pack_lh_b32_b16` (`cs_w32_int_ext.asm`) on the Radeon iGPU of a Ryzen 9 9950X3D (RDNA2, `gfx1036`, driver 26.10.1) and an RTX 5080 (driver 616.92); `s_cmovk_i32`, `s_cmov_b64` and the other `s_pack_*` forms have no GPU test on main; the translated shaders were also run on NVIDIA by reviewers (`s_cmov_b32/k_i32`: RTX 5090, RTX 4050 and Radeon 740M in #613; `s_pack_*`: RTX 5090 in #449). **Hardware-verified on RDNA2** (`gfx1035`, wave32 and wave64 via `tools/int_hw_probe.py --oracle both`, SHADER-137, SCC kept), and on native gfx1036 (AMD Radeon Graphics, Windows 11, driver 26.10.1) through `tools/hw_oracle`: all five `salu_cmov_pack` cases and the 14 `s_cmov_b64` cases match the translator in wave32 and wave64 (SCC 0 and 1; an SGPR pair, the inline constants -1/-16/64, the literal 0x89abcdef, `null` and the destination itself; SCC = 1 takes S0, 0 keeps D, SCC is never written), `s_cmov_b32` matches under SCC=0 and SCC=1, and `s_pack_ll/lh/hh_b32_b16` is bit-exact on 500 random programs with 0 mismatches (`--oracle translator,hw`). **Hardware-verified on RDNA2** (`gfx1035`, wave32 and wave64 via `tools/int_hw_probe.py --oracle both`, SHADER-137, SCC kept). Also **measured on RDNA2 gfx1036** (Radeon iGPU of a Ryzen 9 9950X3D, Windows 11, driver 26.10.1, `tools/hw_oracle` HIP launcher, rocm-sdk-core clang): `tools/int_hw_probe.py --oracle both --wave both` gives the same words as the translator for all five `salu_cmov_pack` cases in wave32 and wave64, and the 14 `s_cmov_b64` cases of the `salu_cmov_b64` group (`python -I tools/int_hw_probe.py --oracle both --wave both --group salu_cmov_b64`; SCC 0 and 1; source an SGPR pair, the inline constants -1, -16 and 64, the literal 0x89abcdef, `null`, and the destination itself; SCC preset and read back after): SCC preset and read back after) match the translator in wave32 and wave64: SCC = 1 takes S0 (a literal zero-extended, an inline constant sign-extended, `null` gives 0), SCC = 0 keeps D, SCC is never written. Also on `gfx1035` via `int_hw_probe` (SHADER-137, SCC kept), and on `gfx1036` and an RTX 5080 through the fixtures `cs_w32_salu64.asm` (`s_cmov_b32`) and `cs_w32_int_ext.asm` (`s_pack_lh_b32_b16`). `tools/hw_oracle` + `tools/salu_diff.py` verify `s_cmov_b32` under SCC 0/1 and `s_pack_ll/lh/hh_b32_b16` bit-exact on 500 random programs with 0 mismatches. Reviewers ran `s_cmov*` on an RTX 5090, an RTX 4050 and a Radeon 740M (#613) and `s_pack_*` on an RTX 5090 (#449). Measured on native gfx1036 (AMD Radeon Graphics, RDNA2) through tools/hw_oracle and tools/salu_diff.py: s_cmov_b32 verified under SCC=0 and SCC=1 (preserving destination and updating respectively); s_pack_ll/lh/hh_b32_b16 verified bit-exact on 500 random programs with 0 mismatches (--oracle translator,hw). **Not measured on RDNA2.** | |
| 496 | | `v_bfi_b32` | `(S0 & S1) \| (~S0 & S2)` (RDNA2 ISA, VOP3 opcode 330). A literal or known same-block SGPR mask of zero or all ones selects S2 or S1 directly. A contiguous mask uses `OpBitFieldInsert` with S1 shifted down by the field offset, since RDNA2 reads the bits in place. For sparse constant masks the translator precomputes the complement. Runtime masks use the full bitwise expression. Checked by the hand-written `bfi_known_mask.asm` and `tests/semantic/test_bfi_known_mask.py`. | | 500 | | `v_bfi_b32` | `(S0 & S1) \| (~S0 & S2)` (RDNA2 ISA, VOP3 opcode 330). A literal or known same-block SGPR mask of zero or all ones selects S2 or S1 directly. A contiguous mask uses `OpBitFieldInsert` with S1 shifted down by the field offset, since RDNA2 reads the bits in place. For sparse constant masks the translator precomputes the complement. Runtime masks use the full bitwise expression. Checked by the hand-written `bfi_known_mask.asm` and `tests/semantic/test_bfi_known_mask.py`. | |
| 497 | | `v_bfm_b32` | The low five bits of S0 give the width and those of S1 give the offset. The result is the low 32 bits of `((1 << width) - 1) << offset` (RDNA2 ISA §12.12, VOP3 opcode 867). Literal and same-block SGPR constants are folded in the translator, including zero width and shifts that discard the high bits. Runtime operands keep their low-five-bit masks. Checked by `tests/semantic/test_bfm_known_operands.py` and `test_alu_int_misc.py`. | | 501 | | `v_bfm_b32` | The low five bits of S0 give the width and those of S1 give the offset. The result is the low 32 bits of `((1 << width) - 1) << offset` (RDNA2 ISA §12.12, VOP3 opcode 867). Literal and same-block SGPR constants are folded in the translator, including zero width and shifts that discard the high bits. Runtime operands keep their low-five-bit masks. Checked by `tests/semantic/test_bfm_known_operands.py` and `test_alu_int_misc.py`. | |
| 498 | | `s_bfe_u32` / `s_bfe_i32` past bit 31 | offset = S1[4:0], width = S1[22:16] (7 bits; S1 bits 23 to 31 are ignored). When offset + width > 32 the field stops at bit 31: width = min(width, 32 - offset), and `s_bfe_i32` sign-extends from the top bit that exists. Example: `s_bfe_i32 s4, 0xd2f90159, 0x7f001c` gives `0xfffffffd` (4-bit field `0xd`), not `0xd`. SCC = D ≠ 0. Source: measured on gfx1150 (Radeon 880M) with `tools/salu_diff.py --oracle hw`, 4000 random control words, all bit-exact, on gfx1201 (Radeon RX 9070, RDNA4) with 10,000 `salu_diff --oracle hw` programs, 0 mismatches (seed 500 with `--bfe-any`), and **on RDNA2** (AMD Radeon 680M, `gfx1035`: `tools/salu_diff.py --oracle hw,translator --bfe-any --programs 500 --seed 1`, 500/500 match, plus `tools/int_hw_probe.py --oracle both` wave32 and wave64, SHADER-137; and RDNA2 `gfx1036`, Windows 11, driver 26.10.1, `tools/hw_oracle` HIP launcher: `tools/salu_diff.py --oracle translator,hw --bfe-any --ops s_bfe_u32,s_bfe_i32 --programs 2000` with seeds 1, 2 and 3, 6,000 of 6,000 programs pass on both sides, plus seed 4 over every opcode with `--bfe-any`, 2,000 of 2,000, and `int_hw_probe.py`'s `salu_bfe_past31` cases in wave32 and wave64); the translator (`bfe_width`) already did this. `tools/salu_diff.py --oracle hw,translator --bfe-any --programs 500 --seed 1`, 500/500 match, plus `tools/int_hw_probe.py --oracle both` wave32 and wave64, SHADER-137); the translator (`bfe_width`) already did this. Source: measured on gfx1150 (Radeon 880M) with `tools/salu_diff.py --oracle hw`, 4000 random control words, all bit-exact, and on gfx1201 (Radeon RX 9070, RDNA4) with 10,000 `salu_diff --oracle hw` programs, 0 mismatches (seed 500 with `--bfe-any`); the translator (`bfe_width`) already did this. LLVM's v_bfe fold (`constantFoldBFE`) is analogous but has a 5-bit width. **RDNA2 is not measured**; the ISA pseudocode does not say. | | 502 | | `s_bfe_u32` / `s_bfe_i32` past bit 31 | offset = S1[4:0], width = S1[22:16] (7 bits; S1 bits 23 to 31 are ignored). When offset + width > 32 the field stops at bit 31: width = min(width, 32 - offset), and `s_bfe_i32` sign-extends from the top bit that exists. Example: `s_bfe_i32 s4, 0xd2f90159, 0x7f001c` gives `0xfffffffd` (4-bit field `0xd`), not `0xd`. SCC = D ≠ 0. Source: measured on gfx1150 (Radeon 880M) with `tools/salu_diff.py --oracle hw`, 4000 random control words, all bit-exact, on gfx1201 (Radeon RX 9070, RDNA4) with 10,000 `salu_diff --oracle hw` programs, 0 mismatches (seed 500 with `--bfe-any`), and **on RDNA2** (AMD Radeon 680M, `gfx1035`: `tools/salu_diff.py --oracle hw,translator --bfe-any --programs 500 --seed 1`, 500/500 match, plus `tools/int_hw_probe.py --oracle both` wave32 and wave64, SHADER-137; and RDNA2 `gfx1036`, Windows 11, driver 26.10.1, `tools/hw_oracle` HIP launcher: `tools/salu_diff.py --oracle translator,hw --bfe-any --ops s_bfe_u32,s_bfe_i32 --programs 2000` with seeds 1, 2 and 3, 6,000 of 6,000 programs pass on both sides, plus seed 4 over every opcode with `--bfe-any`, 2,000 of 2,000, and `int_hw_probe.py`'s `salu_bfe_past31` cases in wave32 and wave64); the translator (`bfe_width`) already did this. LLVM's v_bfe fold (`constantFoldBFE`) is analogous but has a 5-bit width. | |
| 499 | | 64-bit scalar data ops (`s_brev_b64`, `s_bfe_u64`/`s_bfe_i64`, `s_bitset0_b64`/`s_bitset1_b64`, `s_flbit_i32_b64`/`s_flbit_i32_i64`) | The SGPR pair normally carries 64-bit data. In wave64, `s_flbit_i32_b64` can also gather both halves of a lane mask or EXEC before scanning it. The other operations require scalar data. `test_library_compute_forms.py` checks an empty mask and set bits in either half on native and emulated waves; `tests/semantic/test_lane_mask_bitreplicate_flbit.py` runs EXEC and VCC masks on every lane of a wave64 (the 1.0.2.1 pipeline library reads EXEC this way). `s_brev_b64`: D.lo = reverse(S0.hi), D.hi = reverse(S0.lo). `s_bfe_*64`: offset = S1[5:0], width = S1[22:16]; width 0 gives 0; a field past bit 63 stops there (the 64-bit form of the `s_bfe_u32` rule, LLVM `constantFoldBFE`); SCC = D ≠ 0. `s_bitset*_b64`: bit S0 & 63 of the pair cleared / set. `s_flbit_i32_b64`: zeros above the top 1 from bit 63, −1 for 0; `s_flbit_i32_i64`: the same of ~S0 when S0 < 0, −1 for 0 and −1. None but `s_bfe` writes SCC. Source: RDNA2 ISA SOP1/SOP2. CPU-checked by `tests/semantic/test_salu_brev_b64.py`, `test_salu_bfe_64.py`, `test_salu_bitset_b64.py`, `test_salu_flbit_64.py` (#723, #726, #729, #733). **Hardware-verified** on an AMD Radeon RX 7900 XTX (gfx1100, Windows 11, driver 26.10.1), one raw wave32 kernel per op through `tools/hw_oracle`: `s_brev_b64` of 0x12345678_0000000F has low word 0x1E6A2C48, `s_bfe_u64(0x00000123_45678000, w16 o28)` = 0x1234, `s_bfe_i64(0x00000001_80000000, w2 o31)` has 0xFFFFFFFF in both words, `s_bitset1_b64(0, 40)` has high word 0x100, `s_flbit_i32_b64(0x00010000)` = 47 and `s_flbit_i32_i64(0xFFFFFFFF_FFFF0000)` = 48. These are the words `runtime/test/shaders/cs_w32_salu64.asm` expects. Also **hardware-verified on RDNA2** (`gfx1035`, wave32 and wave64 via `tools/int_hw_probe.py --oracle both`, SHADER-137). | | 503 | | 64-bit scalar data ops (`s_brev_b64`, `s_bfe_u64`/`s_bfe_i64`, `s_bitset0_b64`/`s_bitset1_b64`, `s_flbit_i32_b64`/`s_flbit_i32_i64`) | The SGPR pair normally carries 64-bit data. In wave64, `s_flbit_i32_b64` can also gather both halves of a lane mask or EXEC before scanning it. The other operations require scalar data. `test_library_compute_forms.py` checks an empty mask and set bits in either half on native and emulated waves; `tests/semantic/test_lane_mask_bitreplicate_flbit.py` runs EXEC and VCC masks on every lane of a wave64 (the 1.0.2.1 pipeline library reads EXEC this way). `s_brev_b64`: D.lo = reverse(S0.hi), D.hi = reverse(S0.lo). `s_bfe_*64`: offset = S1[5:0], width = S1[22:16]; width 0 gives 0; a field past bit 63 stops there (the 64-bit form of the `s_bfe_u32` rule, LLVM `constantFoldBFE`); SCC = D ≠ 0. `s_bitset*_b64`: bit S0 & 63 of the pair cleared / set. `s_flbit_i32_b64`: zeros above the top 1 from bit 63, −1 for 0; `s_flbit_i32_i64`: the same of ~S0 when S0 < 0, −1 for 0 and −1. None but `s_bfe` writes SCC. Source: RDNA2 ISA SOP1/SOP2. CPU-checked by `tests/semantic/test_salu_brev_b64.py`, `test_salu_bfe_64.py`, `test_salu_bitset_b64.py`, `test_salu_flbit_64.py` (#723, #726, #729, #733). **Hardware-verified** on an AMD Radeon RX 7900 XTX (gfx1100, Windows 11, driver 26.10.1), one raw wave32 kernel per op through `tools/hw_oracle`: `s_brev_b64` of 0x12345678_0000000F has low word 0x1E6A2C48, `s_bfe_u64(0x00000123_45678000, w16 o28)` = 0x1234, `s_bfe_i64(0x00000001_80000000, w2 o31)` has 0xFFFFFFFF in both words, `s_bitset1_b64(0, 40)` has high word 0x100, `s_flbit_i32_b64(0x00010000)` = 47 and `s_flbit_i32_i64(0xFFFFFFFF_FFFF0000)` = 48. These are the words `runtime/test/shaders/cs_w32_salu64.asm` expects. Also **hardware-verified on RDNA2** (`gfx1035`, wave32 and wave64 via `tools/int_hw_probe.py --oracle both`, SHADER-137). | |
| 500 | | `v_bfe_u32` / `v_bfe_i32` past bit 31 | offset = S1[4:0] and width = S2[4:0]: the bits above are ignored, so an offset of 36 reads as 4 and a width of 32 as 0 (a width of 0 gives 0). When offset + width > 32 the field stops at bit 31, as for `s_bfe`: width = min(width, 32 - offset), and `v_bfe_i32` sign-extends from bit 31. Example: `v_bfe_i32` of `0xd2f90159` with offset 28 and width 16 gives `0xfffffffd` (4-bit field `0xd`), not `0xd`, and `0x80000000` with offset 31 and width 4 gives `0xffffffff`. The translator (`bfe_width` for VGPR or SGPR offset and width, the same cut folded at translation time for constants) already did this. Source: **measured on RDNA2**, AMD Radeon 610M (`gfx1036`, Windows 11, AMD driver 32.0.11016.14003), wave32 and wave64 identical, 16 words over VGPR, inline-constant and literal operands: `tools/int_hw_probe.py --oracle both --group valu_bfe_past31`, 4/4 cases match the translator. The words are pinned on the CPU by `tests/test_int_hw_probe.py` (`ValuBfeMeasuredOnRdna2`). | | 504 | | `v_bfe_u32` / `v_bfe_i32` past bit 31 | offset = S1[4:0] and width = S2[4:0]: the bits above are ignored, so an offset of 36 reads as 4 and a width of 32 as 0 (a width of 0 gives 0). When offset + width > 32 the field stops at bit 31, as for `s_bfe`: width = min(width, 32 - offset), and `v_bfe_i32` sign-extends from bit 31. Example: `v_bfe_i32` of `0xd2f90159` with offset 28 and width 16 gives `0xfffffffd` (4-bit field `0xd`), not `0xd`, and `0x80000000` with offset 31 and width 4 gives `0xffffffff`. The translator (`bfe_width` for VGPR or SGPR offset and width, the same cut folded at translation time for constants) already did this. Source: **measured on RDNA2**, AMD Radeon 610M (`gfx1036`, Windows 11, AMD driver 32.0.11016.14003), wave32 and wave64 identical, 16 words over VGPR, inline-constant and literal operands: `tools/int_hw_probe.py --oracle both --group valu_bfe_past31`, 4/4 cases match the translator. The words are pinned on the CPU by `tests/test_int_hw_probe.py` (`ValuBfeMeasuredOnRdna2`). | |
| 501 | | `s_quadmask_b32`/`_b64`, `s_bitreplicate_b64_b32` | On scalar data (RDNA2 ISA SOP1): `s_quadmask_b32` sets D[i] to the OR of S0[4i+3:4i] for the 8 quads, `s_quadmask_b64` does the same for the 16 quads of the 64-bit S0 (D[63:16] = 0), and both set SCC = D != 0. `s_bitreplicate_b64_b32` copies each bit S0[i] to D[2i] and D[2i+1] and leaves SCC. Built from fixed shift/mask steps, with no loop. Bit replication can also write EXEC, or VCC in wave64 (in wave32 VCC's high word is data, so it stays `Unsupported`). Each lane takes source bit `lane // 2`. `test_library_compute_forms.py` checks both halves of VCC and SCC on native and emulated waves; `tests/semantic/test_lane_mask_bitreplicate_flbit.py` checks VCC, which the 1.0.2.1 pipeline library writes from a constant, on every lane of a wave64. A 32-bit lane-mask source (`exec_lo`/`exec_hi`, `vcc_lo`/`vcc_hi`) of `s_bitreplicate_b64_b32` into a scalar (non-EXEC/VCC) destination reads that half of the wave's mask as data (`Gen.wave_mask`, as `s_ff1_i32_b64` reads one) and replicates it as any scalar (#998, for 6 pipeline-library programs of 1.0.2.1). Confirmed only by the CPU interpreter on every lane of a wave64 (`test_lane_mask_bitreplicate_flbit.py`: EXEC halves and a compare's VCC halves, synthetic lines) and by the ISA pseudocode above; not measured on hardware. Any other lane-mask source (EXEC, VCC or an SGPR that `holds_lane_mask`), and a lane-mask source with an EXEC/VCC destination, raises `Unsupported`: each invocation holds only its own lane's bit, and these ops read the other lanes of a quad or move bits between lanes. Until 2026-11-22 all three were rejected. CPU-checked by `tests/semantic/test_salu_quadmask_bitreplicate.py` (fixed and seeded values, SCC written or kept, immediates, aliasing, lane masks rejected). **Hardware-verified** on an AMD Radeon RX 7900 XTX (gfx1100, Windows 11, driver 26.10.1) through `tools/hw_oracle`, one raw wave32 kernel per op: `s_quadmask_b32(0xF)` = 1 with SCC 1, `(0xF0000000)` = 0x80, `(0x0F0F0F0F)` = 0x55 (the set quads are 0, 2, 4 and 6), `(0)` = 0 with SCC 0; `s_quadmask_b64` of 0xF = 1 and of 0xF0000000_00000000 (quad 15, bits 60..63) = 0x8000 in the low word with D[63:16] = 0; `s_bitreplicate_b64_b32` of 5 = 0x33 and of 0x80000000 = 0xC0000000_00000000, with SCC left as it was. **GPU-checked** by `runtime/test/shaders/cs_w32_new_ops.asm` (`s_quadmask_b32(0x01020408)` = 0x55, `s_quadmask_b64(0x80000000_00000001)` low word 0x8001, `s_bitreplicate_b64_b32(0x80000001)` high word 0xC0000000, with the expected words from the ISA pseudocode), exact on the Radeon iGPU of a Ryzen 9 9950X3D (RDNA2, `gfx1036`, driver 26.10.1) and an RTX 5080 (driver 616.92). **Not GPU-verified.** | | 505 | | `s_quadmask_b32`/`_b64`, `s_bitreplicate_b64_b32` | On scalar data (RDNA2 ISA SOP1): `s_quadmask_b32` sets D[i] to the OR of S0[4i+3:4i] for the 8 quads, `s_quadmask_b64` does the same for the 16 quads of the 64-bit S0 (D[63:16] = 0), and both set SCC = D != 0. `s_bitreplicate_b64_b32` copies each bit S0[i] to D[2i] and D[2i+1] and leaves SCC. Built from fixed shift/mask steps, with no loop. Bit replication can also write EXEC, or VCC in wave64 (in wave32 VCC's high word is data, so it stays `Unsupported`). Each lane takes source bit `lane // 2`. `test_library_compute_forms.py` checks both halves of VCC and SCC on native and emulated waves; `tests/semantic/test_lane_mask_bitreplicate_flbit.py` checks VCC, which the 1.0.2.1 pipeline library writes from a constant, on every lane of a wave64. A 32-bit lane-mask source (`exec_lo`/`exec_hi`, `vcc_lo`/`vcc_hi`) of `s_bitreplicate_b64_b32` into a scalar (non-EXEC/VCC) destination reads that half of the wave's mask as data (`Gen.wave_mask`, as `s_ff1_i32_b64` reads one) and replicates it as any scalar (#998, for 6 pipeline-library programs of 1.0.2.1). Confirmed only by the CPU interpreter on every lane of a wave64 (`test_lane_mask_bitreplicate_flbit.py`: EXEC halves and a compare's VCC halves, synthetic lines) and by the ISA pseudocode above; not measured on hardware. Any other lane-mask source (EXEC, VCC or an SGPR that `holds_lane_mask`), and a lane-mask source with an EXEC/VCC destination, raises `Unsupported`: each invocation holds only its own lane's bit, and these ops read the other lanes of a quad or move bits between lanes. Until 2026-11-22 all three were rejected. CPU-checked by `tests/semantic/test_salu_quadmask_bitreplicate.py` (fixed and seeded values, SCC written or kept, immediates, aliasing, lane masks rejected). **Hardware-verified** on an AMD Radeon RX 7900 XTX (gfx1100, Windows 11, driver 26.10.1) through `tools/hw_oracle`, one raw wave32 kernel per op: `s_quadmask_b32(0xF)` = 1 with SCC 1, `(0xF0000000)` = 0x80, `(0x0F0F0F0F)` = 0x55 (the set quads are 0, 2, 4 and 6), `(0)` = 0 with SCC 0; `s_quadmask_b64` of 0xF = 1 and of 0xF0000000_00000000 (quad 15, bits 60..63) = 0x8000 in the low word with D[63:16] = 0; `s_bitreplicate_b64_b32` of 5 = 0x33 and of 0x80000000 = 0xC0000000_00000000, with SCC left as it was. **GPU-checked** by `runtime/test/shaders/cs_w32_new_ops.asm` (`s_quadmask_b32(0x01020408)` = 0x55, `s_quadmask_b64(0x80000000_00000001)` low word 0x8001, `s_bitreplicate_b64_b32(0x80000001)` high word 0xC0000000, with the expected words from the ISA pseudocode), exact on the Radeon iGPU of a Ryzen 9 9950X3D (RDNA2, `gfx1036`, driver 26.10.1) and an RTX 5080 (driver 616.92). **Not GPU-verified.** | |
| @@ -537,11 +541,11 @@ How the generated SPIR-V expects the runtime to work: | |||
| 537 | | `v_cmp_class_f16`, `v_cmpx_class_f16`, `v_cmp_class_f64`, `v_cmpx_class_f64` | IEEE-754 floating-point class tests against the 10-bit class mask (`0: sNaN, 1: qNaN, 2: -inf, 3: -normal, 4: -denormal, 5: -0, 6: +0, 7: +denormal, 8: +normal, 9: +inf`), writing VCC/SGPR or narrowing EXEC (`v_cmpx`). Computed bit-exactly on integer words (so `sNaN` is never quieted by float ops and `v_cmp(x)_class_f64` does not require `OpCapability Float64`): `f16` reads both the value operand (`op_sel[0]`) and the class mask operand via `src_h` (so float inline constants like `0.5`, `1.0`, `-2.0`, `0.15915494` take their 16-bit binary16 value over a zero high half before SDWA selection, matching `tools/sdwa_diff.py --oracle hw` on RDNA2 `gfx1036`; until 2026-11-23 `cmp_class` read the mask with `src_u`, turning inline float constants into 32-bit binary32 bits and failing `sdwa_diff --ops v_cmp_class_f16` 12/500) and applies `abs`/`neg` on bits `[15:0]`; `f16` reads the selected half (`op_sel[0]`, inline f16 constants via `src_h`) and applies `abs`/`neg` on bits `[15:0]`; `f64` reads the `(lo, hi)` pair (32-bit literals placed in the upper word with `lo = 0` per RDNA2 ISA) and applies `abs`/`neg` on `hi`. Output modifiers (`clamp`, `mul:*`, `div:*`) and unsupported `op_sel` bits raise `Unsupported`. Source: AMD [RDNA 2 ISA reference](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf) (VOPC `V_CMP_CLASS_F16/F64`, `V_CMPX_CLASS_F16/F64`). Checked bit-for-bit across all 10 classes on the CPU (`spirv_mini_interp`) and with `spirv-val` by `tests/semantic/test_alu_cmp_class_f16_f64.py`, and across 500 SDWA programs (`v_cmp_class_f16`, 0 mismatches) via `tools/sdwa_diff.py`; **not GPU-verified** and not run on the shader corpus. . **Hardware-measured natively on `gfx1100`** (RX 7900 XTX, driver 26.10.1) with `tools/hw_oracle`, 85 cases, all matching the operand's own bits: the ten classes on ten `f16` words (`0x7c01` sNaN, `0x7e00` qNaN, `0xfc00` -inf, `0xbc00` -normal, `0x8001` -denormal, `0x8000` -0, `0x0000` +0, `0x0001` +denormal, `0x3c00` +normal, `0x7c00` +inf) and on ten `f64` pairs, each against its own class bit, all ten bits, no bits and the nine other bits (80), plus both `v_cmpx` forms on the launched lane (5). Not measured: `abs`/`neg`/`op_sel`, an inactive lane's `vdst`/`EXEC` under `v_cmpx`, wave64, and the shader corpus. | | 541 | | `v_cmp_class_f16`, `v_cmpx_class_f16`, `v_cmp_class_f64`, `v_cmpx_class_f64` | IEEE-754 floating-point class tests against the 10-bit class mask (`0: sNaN, 1: qNaN, 2: -inf, 3: -normal, 4: -denormal, 5: -0, 6: +0, 7: +denormal, 8: +normal, 9: +inf`), writing VCC/SGPR or narrowing EXEC (`v_cmpx`). Computed bit-exactly on integer words (so `sNaN` is never quieted by float ops and `v_cmp(x)_class_f64` does not require `OpCapability Float64`): `f16` reads both the value operand (`op_sel[0]`) and the class mask operand via `src_h` (so float inline constants like `0.5`, `1.0`, `-2.0`, `0.15915494` take their 16-bit binary16 value over a zero high half before SDWA selection, matching `tools/sdwa_diff.py --oracle hw` on RDNA2 `gfx1036`; until 2026-11-23 `cmp_class` read the mask with `src_u`, turning inline float constants into 32-bit binary32 bits and failing `sdwa_diff --ops v_cmp_class_f16` 12/500) and applies `abs`/`neg` on bits `[15:0]`; `f16` reads the selected half (`op_sel[0]`, inline f16 constants via `src_h`) and applies `abs`/`neg` on bits `[15:0]`; `f64` reads the `(lo, hi)` pair (32-bit literals placed in the upper word with `lo = 0` per RDNA2 ISA) and applies `abs`/`neg` on `hi`. Output modifiers (`clamp`, `mul:*`, `div:*`) and unsupported `op_sel` bits raise `Unsupported`. Source: AMD [RDNA 2 ISA reference](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf) (VOPC `V_CMP_CLASS_F16/F64`, `V_CMPX_CLASS_F16/F64`). Checked bit-for-bit across all 10 classes on the CPU (`spirv_mini_interp`) and with `spirv-val` by `tests/semantic/test_alu_cmp_class_f16_f64.py`, and across 500 SDWA programs (`v_cmp_class_f16`, 0 mismatches) via `tools/sdwa_diff.py`; **not GPU-verified** and not run on the shader corpus. . **Hardware-measured natively on `gfx1100`** (RX 7900 XTX, driver 26.10.1) with `tools/hw_oracle`, 85 cases, all matching the operand's own bits: the ten classes on ten `f16` words (`0x7c01` sNaN, `0x7e00` qNaN, `0xfc00` -inf, `0xbc00` -normal, `0x8001` -denormal, `0x8000` -0, `0x0000` +0, `0x0001` +denormal, `0x3c00` +normal, `0x7c00` +inf) and on ten `f64` pairs, each against its own class bit, all ten bits, no bits and the nine other bits (80), plus both `v_cmpx` forms on the launched lane (5). Not measured: `abs`/`neg`/`op_sel`, an inactive lane's `vdst`/`EXEC` under `v_cmpx`, wave64, and the shader corpus. | |
| 538 | | Float-to-byte pack | `v_cvt_pk_u8_f32` rounds to nearest even (the default MODE round mode; the hardware follows the MODE register's f32 round mode, which the translator ignores, see #358), clamps to [0, 255], and gives 0 for NaN and negative values, then inserts the byte at `src1[1:0]` of `src2` and keeps the other three. NaN is replaced by +0 before `FClamp`, which is undefined for a NaN operand. **Measured natively** on RDNA2 (gfx1036, the Ryzen 7 9800X3D iGPU, AMD driver 25.10, the instruction run through inline assembly): all 256 inputs k + 0.5 round to even, 0.5 gives 0, 0x3f000001 gives 1, +inf and 300.0 give 255, -inf, -1.0, ±0, denormals and quiet, signalling and negative NaNs give 0 (#358). `cs_cvt_pk_u8.asm` holds eight of these words, checked by `check.py`/`run_gpu_tests.py` and bit-for-bit by `tests/semantic/test_cvt_pk_u8.py`. | | 542 | | Float-to-byte pack | `v_cvt_pk_u8_f32` rounds to nearest even (the default MODE round mode; the hardware follows the MODE register's f32 round mode, which the translator ignores, see #358), clamps to [0, 255], and gives 0 for NaN and negative values, then inserts the byte at `src1[1:0]` of `src2` and keeps the other three. NaN is replaced by +0 before `FClamp`, which is undefined for a NaN operand. **Measured natively** on RDNA2 (gfx1036, the Ryzen 7 9800X3D iGPU, AMD driver 25.10, the instruction run through inline assembly): all 256 inputs k + 0.5 round to even, 0.5 gives 0, 0x3f000001 gives 1, +inf and 300.0 give 255, -inf, -1.0, ±0, denormals and quiet, signalling and negative NaNs give 0 (#358). `cs_cvt_pk_u8.asm` holds eight of these words, checked by `check.py`/`run_gpu_tests.py` and bit-for-bit by `tests/semantic/test_cvt_pk_u8.py`. | |
| 539 | | Known approximations | `v_cvt_pkrtz_f16_f32` is now **exact round-toward-zero** (finite overflow gives ±65504, not inf). The GPU smoke test caught the old round-to-nearest version producing inf in `PS_ImposterShadow`. The other f16 packs (`v_cvt_f16_f32`, d16 results, mix ops) round to nearest, which matches the default mode; the ALU ones follow a MODE toward-zero write (see the f16 rounding row). `v_fma_mixlo/mixhi_f16` round the exact `x*y+z` once in every mode (measured on an RDNA2 iGPU, gfx1036, 7 of 7 discriminating tie inputs, SHADER-135); the translator does that in both modes through `Gen.fma_mix_odd`; the ALU ones follow a MODE toward-zero write (below; `v_fma_mixlo/mixhi_f16` round the exact `x*y+z` once in every mode (measured on an RDNA2 iGPU, gfx1036, 7 of 7 discriminating tie inputs, SHADER-135); toward zero the translator does that already, while in nearest-even mode it still narrows an f32 `Fma`, which is 1 f16 ulp off on ties until #1774 (SHADER-296) lands; the ALU ones follow a MODE toward-zero write (below; ALU sites: see the f16 rounding row). MODE: `s_setreg_imm32_b32 hwreg(HW_REG_MODE, 2, 2)` (f16/f64 rounding) is tracked in a per-invocation variable, the only MODE field the corpus writes (9,417 writes in 6,333 shaders: 6,694 toward zero, 2,723 back to nearest even). While it is toward zero, every VALU f16 result except the transcendentals listed below (`v_cvt_f16_f32`, f16 arithmetic, `v_pk_*_f16`, `v_fma_mix{lo,hi}_f16`, `v_interp_p2_f16`) rounds toward zero exactly, with the integer conversion `v_cvt_pkrtz_f16_f32` uses (`f16_bits(rtz=True)`, see the f16 rounding row), and `v_add_f64` steps back one ulp when the TwoSum error shows it rounded away from zero; finite overflow gives the largest finite value. The `v_add_f64` output modifiers apply after that step and round to nearest, so an omod that overflows or lands on a subnormal is not toward zero. **omod versus denormal mode is unmodelled:** the translator applies `mul:2`/`mul:4`/`div:2` regardless of the MODE denormal fields (as before this change), whereas hardware ignores omod when denormals are kept (denorm fields = 3) and applies it when they are flushed (both measured on an RX 6800: `v_add_f64 (1 - 2^-60) mul:2` with denormals kept gave 3ff00000:00000000 nearest and 3fefffff:ffffffff toward zero, unscaled; mul:2 was applied with denormals flushed); the tests therefore claim no omod order. CPU-checked by `tests/test_mode_round.py` (the RX 6800 words for f16 add/sub, `v_fma_mix`, the transcendentals, f64 overflow). f16 add and sub (f16 operands) and `v_pk_add_f16` take the exact TwoSum error of the f32 result into account, so they are exact toward zero too (f32 then f16 rounding alone would be wrong: 2 - 2^-24 is an f32 tie that rounds up to 2.0); f16 FMAs need nothing extra, since their round-to-odd f32 value (SHADER-55) narrows exactly in either mode. `v_fma_mix{lo,hi}_f16` rounds the exact fma once, straight to f16, in both nearest-even and toward-zero modes (measured on AMD RDNA2 gfx1036, finding 7079901079; an RX 6800 gave 0x3fff for 1 * 2 - 2^-30, where rounding to f32 first and then narrowing gives 0x4000): `v_fma_mix{lo,hi}_f16` rounds the exact fma once, straight to f16, in both nearest-even and toward-zero modes (measured on AMD RDNA2 gfx1036 across 7 of 7 discriminating tie inputs with `tools/fma_mix_probe.py --oracle hw`, SHADER-135, finding 7079901079, and on an RX 6800 where toward zero gave 0x3fff for 1 * 2 - 2^-30 vs 0x4000 with double rounding; fixed for nearest mode in SHADER-296 / #1774; see docs/shader_validation.md, "`v_fma_mix*` f16 rounding in nearest mode"): `v_fma_mix{lo,hi}_f16` rounds the exact fma once, straight to f16, toward zero (an RX 6800 gave 0x3fff for 1 * 2 - 2^-30, where rounding to f32 first and then narrowing gives 0x4000): `v_fma_mix{lo,hi}_f16` rounds the exact fma once, straight to f16, in both nearest-even and toward-zero modes (measured on AMD RDNA2 gfx1036 and verified by `tools/fma_mix_probe.py`; finding 7079901079; toward zero an RX 6800 gave 0x3fff for 1 * 2 - 2^-30, where rounding to f32 first and then narrowing gives 0x4000): `Gen.fma_mix_odd` corrects the f32 `Fma` to round-to-odd by the sign of its exact residual (product error by `Fma(x, y, -x*y)`, TwoSum of the sum), which narrows exactly in either direction; the nearest-even path is unchanged (f32 `Fma`, then narrow). `fma_mix_odd` also handles a tiny product ( \| a x*y \| >= < 2^-64: its error underflows or is flushed, so the residual sign is sign(x) xor sign(y), independent of the driver's denormal mode) and an f32 overflow with finite operands (toward zero gives ±FLT_MAX, so f16 ±65504). `v_rcp_f16`, `v_rsq_f16`, `v_sqrt_f16`, `v_sin_f16`, `v_cos_f16`, `v_exp_f16` and `v_log_f16` ignore the rounding mode on hardware, so they always narrow to nearest even; all seven are measured (an RX 6700 XT gave the same words with FP_ROUND round-toward-zero and round-to-nearest on every input of each; see the f16 transcendentals row). `v_rcp_f16`, `v_rsq_f16`, `v_sqrt_f16`, `v_sin_f16`, `v_cos_f16`, `v_exp_f16` and `v_log_f16` ignore the rounding mode on hardware (RX 6800 for the first four, plus an exhaustive 65,536-input RNE vs RTZ sweep of all seven in wave32 and wave64 on native `gfx1036` via `tools/mode_round_probe.py`, SHADER-132: 0/65,536 inputs differ on every op; the same probe also confirmed all 17 f16/f64 RNE vs RTZ cases including `v_cvt_f16_f32`, `v_add/sub/mul/fma_f16`, `v_pk_add/fma_f16`, `v_fma_mix{lo,hi}_f16` and `v_add_f64` overflow saturation in both wave32 and wave64), so they always narrow to nearest even. In nearest mode the hardware rounds once as well: `v_rcp_f16`, `v_rsq_f16`, `v_sqrt_f16`, `v_sin_f16`, `v_cos_f16`, `v_exp_f16` and `v_log_f16` ignore the rounding mode on hardware, so they always narrow to nearest even; all seven are measured (an RX 6700 XT gave the same words with FP_ROUND round-toward-zero and round-to-nearest on every input of each, see the f16 transcendentals row; independently confirmed by an exhaustive 65,536-input RNE vs RTZ sweep of all seven in wave32 and wave64 on native `gfx1036` via `tools/mode_round_probe.py`, SHADER-132: `v_rcp_f16`, `v_rsq_f16`, `v_sqrt_f16` and `v_sin_f16` ignore the rounding mode on hardware (RX 6800: the same words in every mode), so they always narrow to nearest even; `v_cos_f16`, `v_exp_f16` and `v_log_f16` are unmeasured, assumed like those four and treated the same. The "every VALU f16 result rounds toward zero" sentence above therefore excludes these seven; the f16 results of `v_floor/ceil/trunc/rndne/fract_f16` are exact and need no rounding. `tools/fma_mix_probe.py --oracle hw` on an RDNA2 iGPU (gfx1036, SHADER-135) gave the single-rounded word for all seven inputs where the two rules differ by one f16 ulp, as `Gen.fma_mix_odd` produces (docs/shader_validation.md, "`v_fma_mix*` f16 rounding in nearest mode"). In nearest mode the translator still rounds `v_fma_mix{lo,hi}_f16` twice (f32 `Fma`, then narrow), but the hardware rounds once there as well: `tools/fma_mix_probe.py --oracle hw` on an RDNA2 iGPU (gfx1036, SHADER-135) gave the single-rounded word for all seven inputs where the two rules differ by one f16 ulp, so the translator, which rounded twice there (f32 `Fma`, then narrow) until #1774, was one f16 ulp off on exactly those ties (docs/shader_validation.md, "`v_fma_mix*` f16 rounding in nearest mode"; the fix is `Gen.fma_mix_odd` in nearest mode too, SHADER-296). Nearest-mode `v_fma_mix*` still rounds twice (f32 `Fma`, then narrow): main's behaviour, unmeasured. `tools/fma_mix_probe.py --oracle hw` measures it on an AMD GPU, with seven inputs where the two rules differ by one f16 ulp (docs/shader_validation.md). The `v_add_f64` step needs f64 denormals preserved (not flushed) by the driver for subnormal sums. Shaders that never write MODE emit the same code as without this. Writes to other MODE bits (f32 rounding, denormals), directed rounding (+inf/-inf) and register-valued writes are refused, so nothing changes silently; none occur in the corpus. Denormal behaviour is still Vulkan's default. Format conversions in memory and texture units don't follow MODE. `v_mul_legacy_f32` now keeps the `0 × anything = 0` rule like `v_mad_legacy_f32` (GPU-checked with `runtime/test/shaders/ps_legacy_mul.asm` on AMD Radeon RX 9070 XT). \| b \| `, `FastTwoSum`: `bb = r - a`, `e = b - bb`) and steps back one ulp when the rounding error shows it rounded away from zero; finite overflow gives the largest finite value (unordered `TwoSum` `r - x` can overflow to `±inf` and yield `NaN` error for opposite-sign finite operands with ` \| x \| < \| y \| ` near `±DBL_MAX`, e.g. `0x7fdd9bb47daa1333 + 0xffefffffffffffff` found by `@Jolymmiles`; GPU-checked with `runtime/test/shaders/ps_f64_round.asm` on NVIDIA GeForce RTX 5060 Ti, 4096/4096 pixels exact). The `v_add_f64` output modifiers apply after that step and round to nearest, so an omod that overflows or lands on a subnormal is not toward zero. **omod versus denormal mode is unmodelled:** the translator applies `mul:2`/`mul:4`/`div:2` regardless of the MODE denormal fields (as before this change), whereas hardware ignores omod when denormals are kept (denorm fields = 3) and applies it when they are flushed (both measured on an RX 6800: `v_add_f64 (1 - 2^-60) mul:2` with denormals kept gave 3ff00000:00000000 nearest and 3fefffff:ffffffff toward zero, unscaled; mul:2 was applied with denormals flushed); the tests therefore claim no omod order. CPU-checked by `tests/test_mode_round.py` (the RX 6800 words for f16 add/sub, `v_fma_mix`, the transcendentals, f64 overflow). f16 add and sub (f16 operands) and `v_pk_add_f16` take the exact TwoSum error of the f32 result into account, so they are exact toward zero too (f32 then f16 rounding alone would be wrong: 2 - 2^-24 is an f32 tie that rounds up to 2.0); f16 FMAs need nothing extra, since their round-to-odd f32 value (SHADER-55) narrows exactly in either mode. `v_fma_mix{lo,hi}_f16` rounds the exact fma once, straight to f16, in both nearest-even and toward-zero modes (measured on AMD RDNA2 gfx1036 across 7 of 7 discriminating tie inputs with `tools/fma_mix_probe.py --oracle hw`, SHADER-135, finding 7079901079, and on an RX 6800 where toward zero gave 0x3fff for 1 * 2 - 2^-30 vs 0x4000 with double rounding; fixed for nearest mode in SHADER-296 / #1774; see docs/shader_validation.md, "`v_fma_mix*` f16 rounding in nearest mode"): `v_fma_mix{lo,hi}_f16` rounds the exact fma once, straight to f16, toward zero (an RX 6800 gave 0x3fff for 1 * 2 - 2^-30, where rounding to f32 first and then narrowing gives 0x4000): `v_fma_mix{lo,hi}_f16` rounds the exact fma once, straight to f16, in both nearest-even and toward-zero modes (measured on AMD RDNA2 gfx1036 and verified by `tools/fma_mix_probe.py`; finding 7079901079; toward zero an RX 6800 gave 0x3fff for 1 * 2 - 2^-30, where rounding to f32 first and then narrowing gives 0x4000): `Gen.fma_mix_odd` corrects the f32 `Fma` to round-to-odd by the sign of its exact residual (product error by `Fma(x, y, -x*y)`, TwoSum of the sum), which narrows exactly in either direction; the nearest-even path is unchanged (f32 `Fma`, then narrow). `fma_mix_odd` also handles a tiny product ( \| x*y \| < 2^-64: its error underflows or is flushed, so the residual sign is sign(x) xor sign(y), independent of the driver's denormal mode) and an f32 overflow with finite operands (toward zero gives ±FLT_MAX, so f16 ±65504). `v_rcp_f16`, `v_rsq_f16`, `v_sqrt_f16`, `v_sin_f16`, `v_cos_f16`, `v_exp_f16` and `v_log_f16` ignore the rounding mode on hardware (RX 6800 for the first four, plus an exhaustive 65,536-input RNE vs RTZ sweep of all seven in wave32 and wave64 on native `gfx1036` via `tools/mode_round_probe.py`, SHADER-132: 0/65,536 inputs differ on every op; the same probe also confirmed all 17 f16/f64 RNE vs RTZ cases including `v_cvt_f16_f32`, `v_add/sub/mul/fma_f16`, `v_pk_add/fma_f16`, `v_fma_mix{lo,hi}_f16` and `v_add_f64` overflow saturation in both wave32 and wave64), so they always narrow to nearest even. In nearest mode the hardware rounds once as well: `v_rcp_f16`, `v_rsq_f16`, `v_sqrt_f16`, `v_sin_f16`, `v_cos_f16`, `v_exp_f16` and `v_log_f16` ignore the rounding mode on hardware, so they always narrow to nearest even; all seven are measured (an RX 6700 XT gave the same words with FP_ROUND round-toward-zero and round-to-nearest on every input of each; see the f16 transcendentals row). `v_rcp_f16`, `v_rsq_f16`, `v_sqrt_f16` and `v_sin_f16` ignore the rounding mode on hardware (RX 6800: the same words in every mode), so they always narrow to nearest even; `v_cos_f16`, `v_exp_f16` and `v_log_f16` are unmeasured, assumed like those four and treated the same. The "every VALU f16 result rounds toward zero" sentence above therefore excludes these seven; the f16 results of `v_floor/ceil/trunc/rndne/fract_f16` are exact and need no rounding. In nearest mode the translator still rounds `v_fma_mix{lo,hi}_f16` twice (f32 `Fma`, then narrow), but the hardware rounds once there as well: `tools/fma_mix_probe.py --oracle hw` on an RDNA2 iGPU (gfx1036, SHADER-135) gave the single-rounded word for all seven inputs where the two rules differ by one f16 ulp, so the translator, which rounded twice there (f32 `Fma`, then narrow) until #1774, was one f16 ulp off on exactly those ties (docs/shader_validation.md, "`v_fma_mix*` f16 rounding in nearest mode"; the fix is `Gen.fma_mix_odd` in nearest mode too, SHADER-296). Nearest-mode `v_fma_mix*` still rounds twice (f32 `Fma`, then narrow): main's behaviour, unmeasured. `tools/fma_mix_probe.py --oracle hw` measures it on an AMD GPU, with seven inputs where the two rules differ by one f16 ulp (docs/shader_validation.md). The `v_add_f64` step needs f64 denormals preserved (not flushed) by the driver for subnormal sums. Shaders that never write MODE emit the same code as without this. Writes to other MODE bits (f32 rounding, denormals), directed rounding (+inf/-inf) and register-valued writes are refused, so nothing changes silently; none occur in the corpus. Denormal behaviour is still Vulkan's default. Format conversions in memory and texture units don't follow MODE. `v_mul_legacy_f32` now keeps the `0 × anything = 0` rule like `v_mad_legacy_f32` (GPU-checked with `runtime/test/shaders/ps_legacy_mul.asm` on AMD Radeon RX 9070 XT). | | 543 | | Known approximations | `v_cvt_pkrtz_f16_f32` is now **exact round-toward-zero** (finite overflow gives ±65504, not inf). The GPU smoke test caught the old round-to-nearest version producing inf in `PS_ImposterShadow`. The other f16 packs (`v_cvt_f16_f32`, d16 results, mix ops) round to nearest, which matches the default mode; the ALU ones follow a MODE toward-zero write (see the f16 rounding row). `v_fma_mixlo/mixhi_f16` round the exact `x*y+z` once in every mode (measured on an RDNA2 iGPU, gfx1036, 7 of 7 discriminating tie inputs, SHADER-135); the translator does that in both modes through `Gen.fma_mix_odd`; the ALU ones follow a MODE toward-zero write (below; `v_fma_mixlo/mixhi_f16` round the exact `x*y+z` once in every mode (measured on an RDNA2 iGPU, gfx1036, 7 of 7 discriminating tie inputs, SHADER-135); toward zero the translator does that already, while in nearest-even mode it still narrows an f32 `Fma`, which is 1 f16 ulp off on ties until #1774 (SHADER-296) lands; the ALU ones follow a MODE toward-zero write (below; ALU sites: see the f16 rounding row). MODE: `s_setreg_imm32_b32 hwreg(HW_REG_MODE, 2, 2)` (f16/f64 rounding) is tracked in a per-invocation variable, the only MODE field the corpus writes (9,417 writes in 6,333 shaders: 6,694 toward zero, 2,723 back to nearest even). While it is toward zero, every VALU f16 result except the transcendentals listed below (`v_cvt_f16_f32`, f16 arithmetic, `v_pk_*_f16`, `v_fma_mix{lo,hi}_f16`, `v_interp_p2_f16`) rounds toward zero exactly, with the integer conversion `v_cvt_pkrtz_f16_f32` uses (`f16_bits(rtz=True)`, see the f16 rounding row), and `v_add_f64` steps back one ulp when the TwoSum error shows it rounded away from zero; finite overflow gives the largest finite value. The `v_add_f64` output modifiers apply after that step and round to nearest, so an omod that overflows or lands on a subnormal is not toward zero. **omod versus denormal mode is unmodelled:** the translator applies `mul:2`/`mul:4`/`div:2` regardless of the MODE denormal fields (as before this change), whereas hardware ignores omod when denormals are kept (denorm fields = 3) and applies it when they are flushed (both measured on an RX 6800: `v_add_f64 (1 - 2^-60) mul:2` with denormals kept gave 3ff00000:00000000 nearest and 3fefffff:ffffffff toward zero, unscaled; mul:2 was applied with denormals flushed); the tests therefore claim no omod order. CPU-checked by `tests/test_mode_round.py` (the RX 6800 words for f16 add/sub, `v_fma_mix`, the transcendentals, f64 overflow). f16 add and sub (f16 operands) and `v_pk_add_f16` take the exact TwoSum error of the f32 result into account, so they are exact toward zero too (f32 then f16 rounding alone would be wrong: 2 - 2^-24 is an f32 tie that rounds up to 2.0); f16 FMAs need nothing extra, since their round-to-odd f32 value (SHADER-55) narrows exactly in either mode. `v_fma_mix{lo,hi}_f16` rounds the exact fma once, straight to f16, in both nearest-even and toward-zero modes (measured on AMD RDNA2 gfx1036, finding 7079901079; an RX 6800 gave 0x3fff for 1 * 2 - 2^-30, where rounding to f32 first and then narrowing gives 0x4000): `v_fma_mix{lo,hi}_f16` rounds the exact fma once, straight to f16, in both nearest-even and toward-zero modes (measured on AMD RDNA2 gfx1036 across 7 of 7 discriminating tie inputs with `tools/fma_mix_probe.py --oracle hw`, SHADER-135, finding 7079901079, and on an RX 6800 where toward zero gave 0x3fff for 1 * 2 - 2^-30 vs 0x4000 with double rounding; fixed for nearest mode in SHADER-296 / #1774; see docs/shader_validation.md, "`v_fma_mix*` f16 rounding in nearest mode"): `v_fma_mix{lo,hi}_f16` rounds the exact fma once, straight to f16, toward zero (an RX 6800 gave 0x3fff for 1 * 2 - 2^-30, where rounding to f32 first and then narrowing gives 0x4000): `v_fma_mix{lo,hi}_f16` rounds the exact fma once, straight to f16, in both nearest-even and toward-zero modes (measured on AMD RDNA2 gfx1036 and verified by `tools/fma_mix_probe.py`; finding 7079901079; toward zero an RX 6800 gave 0x3fff for 1 * 2 - 2^-30, where rounding to f32 first and then narrowing gives 0x4000): `Gen.fma_mix_odd` corrects the f32 `Fma` to round-to-odd by the sign of its exact residual (product error by `Fma(x, y, -x*y)`, TwoSum of the sum), which narrows exactly in either direction; the nearest-even path is unchanged (f32 `Fma`, then narrow). `fma_mix_odd` also handles a tiny product ( \| a x*y \| >= < 2^-64: its error underflows or is flushed, so the residual sign is sign(x) xor sign(y), independent of the driver's denormal mode) and an f32 overflow with finite operands (toward zero gives ±FLT_MAX, so f16 ±65504). `v_rcp_f16`, `v_rsq_f16`, `v_sqrt_f16`, `v_sin_f16`, `v_cos_f16`, `v_exp_f16` and `v_log_f16` ignore the rounding mode on hardware, so they always narrow to nearest even; all seven are measured (an RX 6700 XT gave the same words with FP_ROUND round-toward-zero and round-to-nearest on every input of each; see the f16 transcendentals row). `v_rcp_f16`, `v_rsq_f16`, `v_sqrt_f16`, `v_sin_f16`, `v_cos_f16`, `v_exp_f16` and `v_log_f16` ignore the rounding mode on hardware (RX 6800 for the first four, plus an exhaustive 65,536-input RNE vs RTZ sweep of all seven in wave32 and wave64 on native `gfx1036` via `tools/mode_round_probe.py`, SHADER-132: 0/65,536 inputs differ on every op; the same probe also confirmed all 17 f16/f64 RNE vs RTZ cases including `v_cvt_f16_f32`, `v_add/sub/mul/fma_f16`, `v_pk_add/fma_f16`, `v_fma_mix{lo,hi}_f16` and `v_add_f64` overflow saturation in both wave32 and wave64), so they always narrow to nearest even. In nearest mode the hardware rounds once as well: `v_rcp_f16`, `v_rsq_f16`, `v_sqrt_f16`, `v_sin_f16`, `v_cos_f16`, `v_exp_f16` and `v_log_f16` ignore the rounding mode on hardware, so they always narrow to nearest even; all seven are measured (an RX 6700 XT gave the same words with FP_ROUND round-toward-zero and round-to-nearest on every input of each, see the f16 transcendentals row; independently confirmed by an exhaustive 65,536-input RNE vs RTZ sweep of all seven in wave32 and wave64 on native `gfx1036` via `tools/mode_round_probe.py`, SHADER-132: `v_rcp_f16`, `v_rsq_f16`, `v_sqrt_f16` and `v_sin_f16` ignore the rounding mode on hardware (RX 6800: the same words in every mode), so they always narrow to nearest even; `v_cos_f16`, `v_exp_f16` and `v_log_f16` are unmeasured, assumed like those four and treated the same. The "every VALU f16 result rounds toward zero" sentence above therefore excludes these seven; the f16 results of `v_floor/ceil/trunc/rndne/fract_f16` are exact and need no rounding. `tools/fma_mix_probe.py --oracle hw` on an RDNA2 iGPU (gfx1036, SHADER-135) gave the single-rounded word for all seven inputs where the two rules differ by one f16 ulp, as `Gen.fma_mix_odd` produces (docs/shader_validation.md, "`v_fma_mix*` f16 rounding in nearest mode"). In nearest mode the translator still rounds `v_fma_mix{lo,hi}_f16` twice (f32 `Fma`, then narrow), but the hardware rounds once there as well: `tools/fma_mix_probe.py --oracle hw` on an RDNA2 iGPU (gfx1036, SHADER-135) gave the single-rounded word for all seven inputs where the two rules differ by one f16 ulp, so the translator, which rounded twice there (f32 `Fma`, then narrow) until #1774, was one f16 ulp off on exactly those ties (docs/shader_validation.md, "`v_fma_mix*` f16 rounding in nearest mode"; the fix is `Gen.fma_mix_odd` in nearest mode too, SHADER-296). Nearest-mode `v_fma_mix*` still rounds twice (f32 `Fma`, then narrow): main's behaviour, unmeasured. `tools/fma_mix_probe.py --oracle hw` measures it on an AMD GPU, with seven inputs where the two rules differ by one f16 ulp (docs/shader_validation.md). The `v_add_f64` step needs f64 denormals preserved (not flushed) by the driver for subnormal sums. Shaders that never write MODE emit the same code as without this. Writes to other MODE bits (f32 rounding, denormals), directed rounding (+inf/-inf) and register-valued writes are refused, so nothing changes silently; none occur in the corpus. Denormal behaviour is still Vulkan's default. Format conversions in memory and texture units don't follow MODE. `v_mul_legacy_f32` now keeps the `0 × anything = 0` rule like `v_mad_legacy_f32` (GPU-checked with `runtime/test/shaders/ps_legacy_mul.asm` on AMD Radeon RX 9070 XT). \| b \| `, `FastTwoSum`: `bb = r - a`, `e = b - bb`) and steps back one ulp when the rounding error shows it rounded away from zero; finite overflow gives the largest finite value (unordered `TwoSum` `r - x` can overflow to `±inf` and yield `NaN` error for opposite-sign finite operands with ` \| x \| < \| y \| ` near `±DBL_MAX`, e.g. `0x7fdd9bb47daa1333 + 0xffefffffffffffff` found by `@Jolymmiles`; GPU-checked with `runtime/test/shaders/ps_f64_round.asm` on NVIDIA GeForce RTX 5060 Ti, 4096/4096 pixels exact). The `v_add_f64` output modifiers apply after that step and round to nearest, so an omod that overflows or lands on a subnormal is not toward zero. **omod versus denormal mode is unmodelled:** the translator applies `mul:2`/`mul:4`/`div:2` regardless of the MODE denormal fields (as before this change), whereas hardware ignores omod when denormals are kept (denorm fields = 3) and applies it when they are flushed (both measured on an RX 6800: `v_add_f64 (1 - 2^-60) mul:2` with denormals kept gave 3ff00000:00000000 nearest and 3fefffff:ffffffff toward zero, unscaled; mul:2 was applied with denormals flushed); the tests therefore claim no omod order. CPU-checked by `tests/test_mode_round.py` (the RX 6800 words for f16 add/sub, `v_fma_mix`, the transcendentals, f64 overflow). f16 add and sub (f16 operands) and `v_pk_add_f16` take the exact TwoSum error of the f32 result into account, so they are exact toward zero too (f32 then f16 rounding alone would be wrong: 2 - 2^-24 is an f32 tie that rounds up to 2.0); f16 FMAs need nothing extra, since their round-to-odd f32 value (SHADER-55) narrows exactly in either mode. `v_fma_mix{lo,hi}_f16` rounds the exact fma once, straight to f16, in both nearest-even and toward-zero modes (measured on AMD RDNA2 gfx1036 across 7 of 7 discriminating tie inputs with `tools/fma_mix_probe.py --oracle hw`, SHADER-135, finding 7079901079, and on an RX 6800 where toward zero gave 0x3fff for 1 * 2 - 2^-30 vs 0x4000 with double rounding; fixed for nearest mode in SHADER-296 / #1774; see docs/shader_validation.md, "`v_fma_mix*` f16 rounding in nearest mode"): `v_fma_mix{lo,hi}_f16` rounds the exact fma once, straight to f16, toward zero (an RX 6800 gave 0x3fff for 1 * 2 - 2^-30, where rounding to f32 first and then narrowing gives 0x4000): `v_fma_mix{lo,hi}_f16` rounds the exact fma once, straight to f16, in both nearest-even and toward-zero modes (measured on AMD RDNA2 gfx1036 and verified by `tools/fma_mix_probe.py`; finding 7079901079; toward zero an RX 6800 gave 0x3fff for 1 * 2 - 2^-30, where rounding to f32 first and then narrowing gives 0x4000): `Gen.fma_mix_odd` corrects the f32 `Fma` to round-to-odd by the sign of its exact residual (product error by `Fma(x, y, -x*y)`, TwoSum of the sum), which narrows exactly in either direction; the nearest-even path is unchanged (f32 `Fma`, then narrow). `fma_mix_odd` also handles a tiny product ( \| x*y \| < 2^-64: its error underflows or is flushed, so the residual sign is sign(x) xor sign(y), independent of the driver's denormal mode) and an f32 overflow with finite operands (toward zero gives ±FLT_MAX, so f16 ±65504). `v_rcp_f16`, `v_rsq_f16`, `v_sqrt_f16`, `v_sin_f16`, `v_cos_f16`, `v_exp_f16` and `v_log_f16` ignore the rounding mode on hardware (RX 6800 for the first four, plus an exhaustive 65,536-input RNE vs RTZ sweep of all seven in wave32 and wave64 on native `gfx1036` via `tools/mode_round_probe.py`, SHADER-132: 0/65,536 inputs differ on every op; the same probe also confirmed all 17 f16/f64 RNE vs RTZ cases including `v_cvt_f16_f32`, `v_add/sub/mul/fma_f16`, `v_pk_add/fma_f16`, `v_fma_mix{lo,hi}_f16` and `v_add_f64` overflow saturation in both wave32 and wave64), so they always narrow to nearest even. In nearest mode the hardware rounds once as well: `v_rcp_f16`, `v_rsq_f16`, `v_sqrt_f16`, `v_sin_f16`, `v_cos_f16`, `v_exp_f16` and `v_log_f16` ignore the rounding mode on hardware, so they always narrow to nearest even; all seven are measured (an RX 6700 XT gave the same words with FP_ROUND round-toward-zero and round-to-nearest on every input of each; see the f16 transcendentals row). `v_rcp_f16`, `v_rsq_f16`, `v_sqrt_f16` and `v_sin_f16` ignore the rounding mode on hardware (RX 6800: the same words in every mode), so they always narrow to nearest even; `v_cos_f16`, `v_exp_f16` and `v_log_f16` are unmeasured, assumed like those four and treated the same. The "every VALU f16 result rounds toward zero" sentence above therefore excludes these seven; the f16 results of `v_floor/ceil/trunc/rndne/fract_f16` are exact and need no rounding. In nearest mode the translator still rounds `v_fma_mix{lo,hi}_f16` twice (f32 `Fma`, then narrow), but the hardware rounds once there as well: `tools/fma_mix_probe.py --oracle hw` on an RDNA2 iGPU (gfx1036, SHADER-135) gave the single-rounded word for all seven inputs where the two rules differ by one f16 ulp, so the translator, which rounded twice there (f32 `Fma`, then narrow) until #1774, was one f16 ulp off on exactly those ties (docs/shader_validation.md, "`v_fma_mix*` f16 rounding in nearest mode"; the fix is `Gen.fma_mix_odd` in nearest mode too, SHADER-296). Nearest-mode `v_fma_mix*` still rounds twice (f32 `Fma`, then narrow): main's behaviour, unmeasured. `tools/fma_mix_probe.py --oracle hw` measures it on an AMD GPU, with seven inputs where the two rules differ by one f16 ulp (docs/shader_validation.md). The `v_add_f64` step needs f64 denormals preserved (not flushed) by the driver for subnormal sums. Shaders that never write MODE emit the same code as without this. Writes to other MODE bits (f32 rounding, denormals), directed rounding (+inf/-inf) and register-valued writes are refused, so nothing changes silently; none occur in the corpus. Denormal behaviour is still Vulkan's default. Format conversions in memory and texture units don't follow MODE. `v_mul_legacy_f32` now keeps the `0 × anything = 0` rule like `v_mad_legacy_f32` (GPU-checked with `runtime/test/shaders/ps_legacy_mul.asm` on AMD Radeon RX 9070 XT). | |
| 540 | | Denormal flush in `v_mad_f32`, `v_mac_f32`, `v_mad_legacy_f32` (SHADER-118) | The three have no f32 denormal support: a subnormal operand, the rounded product or the result reads as signed zero, whatever the MODE register says. `Gen.flush_f32` emits ` \| x \| < FLT_MIN → copysign(0, x)` on the three operands, after the product rounding and (via `Gen.flush_f32_mods`) both before and after `omod`/`clamp`; inf and NaN compare false and pass through, and 0 keeps its sign. Source: LLVM AMDGPU `SIISelLowering.cpp`, `SITargetLowering::isFMADLegal` (llvm-project `1922c0c`), which forms `v_mad_f32`/`v_mac_f32` only when f32 denormals are flushed. Corpus count with `tools/shader_profile.py` over the 26,503 gfx1013 shaders: `v_mad_f32` in 7,298 shaders (139,287 occurrences), `v_mac_f32` in 5,889 (276,806: 265,901 `_e32`, 10,811 `_e64`, 94 `_dpp`), `v_mad_legacy_f32` in 6,059 (24,765); 9,297 shaders (35.1%) use at least one, 440,858 occurrences (0.99% of the corpus's 44,406,870 instructions). **Measured natively on RDNA1** (`AMD Radeon RX 5600 XT`, `gfx1010`, Windows driver `32.0.21045.29003`, `tools/mad_denorm_probe.py --oracle hw`, SHADER-340): 48 of 48 cases match in wave32 and wave64 across `game` (`IEEE=0`, `denorm32=0`), `dx10_clamp=0` and `denorm32=3` (`v_mul_f32(FLT_MIN, 0.5)` confirms `denorm32=3` keeps subnormals on the GPU while the mad/mac ops still flush them), and all 40 non-`omod` cases match under `IEEE=1` (where hardware ignores `mul:2`/`mul:4`/`div:2` as for other f32 VALU ops). Before SHADER-340 the translator ran `flush_f32` only after `clamp_mods`, which gave `FLT_MIN` (`0x00800000`) instead of `+0` (`0x00000000`) on `(1.5*2^-126 - 2^-126) mul:2` (and `0x01000000` on `mul:4`), whereas hardware flushes the sum before `omod` (`+0`) as well as after (`FLT_MIN div:2` → `+0`, `-FLT_MIN div:2` → `-0`). Checked on the CPU by `tests/semantic/test_valu_f32_min3_max3_mad.py` (`DenormalFlushTests`: the flush column, pre- and post-`omod` cases, NaN/inf/zero pass-through, and a sabotaged pass-through that fails) and `tests/test_mad_denorm_probe.py`. No RDNA2 part has these opcodes, and on gfx103x the encodings of `v_mad_legacy_f32` (VOP3 0x140) and `v_mac_legacy_f32` (VOP2 0x06) are the fused `v_fma_legacy_f32` / `v_fmac_legacy_f32`, so a raw-encoding run on a gfx1036 oracle would measure a different instruction (see the GFX10.1/GFX10.3 opcode row). | | 544 | | Denormal flush in `v_mad_f32`, `v_mac_f32`, `v_mad_legacy_f32` (SHADER-118) | The three have no f32 denormal support: a subnormal operand, the rounded product or the result reads as signed zero, whatever the MODE register says. By default (when `FLOAT_CONTROLS` and `FTZ32` are on and the shader has no `v_div_scale_f32`, `v_div_fmas_f32`, `s_denorm_mode`, or `s_setreg*` writing non-zero or non-constant bits into `HW_REG_MODE[5:4]` `FP_DENORM.fp32`), modules declare `OpCapability DenormFlushToZero` + `OpExecutionMode %main DenormFlushToZero 32` (core in SPIR-V 1.4, recorded as `"shaderDenormFlushToZeroFloat32"` in `meta["float_controls"]` alongside `DenormPreserve 16` and `SignedZeroInfNanPreserve 32`), eliding the software `Gen.flush_f32` wrapper and lowering `v_mul_legacy_f32` (and `v_mad_legacy_f32`/`v_mac_legacy_f32`'s product) to the canonical Mesa NIR `fmulz` pattern `OpSelect %float (OpLogicalOr (OpFOrdEqual x %f0) (OpFOrdEqual y %f0)) %f0 (OpFMul x y)` so RADV/ACO fuses it into a single native `v_mul_legacy_f32`. `_disables_ftz32` parses `hwreg(HW_REG_MODE[, offset[, size]])` (default `offset=0, size=32`): writes to disjoint bit ranges such as `hwreg(HW_REG_MODE, 2, 2)` (`FP_ROUND.fp64_fp16`, seen in 6,293 of 28,447 shaders) or `s_setreg_imm32_b32` writing `0` into overlapped `[5:4]` bits keep FTZ32 enabled, while non-zero immediate bits in `[5:4]`, register-valued `s_setreg_b32` overlapping `[5:4]`, or unparseable `HW_REG_MODE` forms conservatively disable FTZ32. Under `--no-ftz32` (or when gated off by `v_div_scale_f32`, `v_div_fmas_f32`, `s_denorm_mode`, `s_setreg*` modifying `HW_REG_MODE[5:4]`, or `--no-float-controls`), `Gen.flush_f32` emits ` \| x \| < FLT_MIN → copysign(0, x)` on the three operands, after the product rounding and (via `Gen.flush_f32_mods`) both before and after `omod`/`clamp`; inf and NaN compare false and pass through, and 0 keeps its sign. Source: LLVM AMDGPU `SIISelLowering.cpp`, `SITargetLowering::isFMADLegal` (llvm-project `1922c0c`), which forms `v_mad_f32`/`v_mac_f32` only when f32 denormals are flushed. Corpus count with `tools/shader_profile.py` over the 26,503 gfx1013 shaders: `v_mad_f32` in 7,298 shaders (139,287 occurrences), `v_mac_f32` in 5,889 (276,806: 265,901 `_e32`, 10,811 `_e64`, 94 `_dpp`), `v_mad_legacy_f32` in 6,059 (24,765); 9,297 shaders (35.1%) use at least one, 440,858 occurrences (0.99% of the corpus's 44,406,870 instructions). **Measured natively on RDNA1** (`AMD Radeon RX 5600 XT`, `gfx1010`, Windows driver `32.0.21045.29003`, `tools/mad_denorm_probe.py --oracle hw`, SHADER-340): 48 of 48 cases match in wave32 and wave64 across `game` (`IEEE=0`, `denorm32=0`), `dx10_clamp=0` and `denorm32=3` (`v_mul_f32(FLT_MIN, 0.5)` confirms `denorm32=3` keeps subnormals on the GPU while the mad/mac ops still flush them), and all 40 non-`omod` cases match under `IEEE=1` (where hardware ignores `mul:2`/`mul:4`/`div:2` as for other f32 VALU ops). Before SHADER-340 the translator ran `flush_f32` only after `clamp_mods`, which gave `FLT_MIN` (`0x00800000`) instead of `+0` (`0x00000000`) on `(1.5*2^-126 - 2^-126) mul:2` (and `0x01000000` on `mul:4`), whereas hardware flushes the sum before `omod` (`+0`) as well as after (`FLT_MIN div:2` → `+0`, `-FLT_MIN div:2` → `-0`). Checked on the CPU and with `spirv-val --target-env vulkan1.2` by `tests/semantic/test_ftz32_fmulz.py` (fixture `ftz32_fmulz.asm`, `HW_REG_MODE` bit-range overlap and gate-off checks, `v_mul_legacy_f32` edge cases in both FTZ32 and `--no-ftz32` modes), `tests/semantic/test_valu_mul_legacy_denorm.py`, `tests/semantic/test_valu_f32_min3_max3_mad.py`, and `tests/test_mad_denorm_probe.py`. No RDNA2 part has these opcodes, and on gfx103x the encodings of `v_mad_legacy_f32` (VOP3 0x140) and `v_mac_legacy_f32` (VOP2 0x06) are the fused `v_fma_legacy_f32` / `v_fmac_legacy_f32`, so a raw-encoding run on a gfx1036 oracle would measure a different instruction (see the GFX10.1/GFX10.3 opcode row). | |
| 541 | | 16-bit high-half reads (`Gen.u16_half` / `Gen.i16_half`, #1506) | Reading the high 16 bits of a 32-bit word emits `OpShiftRightLogical %uint u 16` (`u16_half`) or `OpShiftRightArithmetic %int (as_int(u)) 16` (`i16_half`) alone, without a trailing `OpBitwiseAnd ... 0xFFFF` or `OpBitFieldSExtract ... 0 16` (used for the low half only). On 32-bit inputs `>> 16` already zero- or sign-extends bits 31..16, and AMD's Windows LLPC compiler (measured on RDNA2, drivers 22.40.84.06 in #1506 and 24.10.24 on Ryzen 5 7600 iGPU) miscompiles both `(u >> 16) & 0xFFFF` and `OpBitFieldSExtract (u >> 16) 0 16` after two partial-half writes to `u` by dropping the `>> 16` when the result feeds `OpIAdd`, `OpIMul`, or `OpShiftLeftLogical` (e.g. `(0x41b1 << 1) & 0xFFFF` became `0x0000` instead of `0x8362` in `cs_f16fuzz_s2_163_w64`, `s_bitreplicate`'s `((0x41b1 << 8) \| 0x41b1) & 0x00ff00ff` became `0xb10000` instead of `0x4100b1`, and `SExtract(0x91b1138b >> 16, 0, 16) + 1` became `0x91b10001` instead of `0xffff91b2`). Applies across all 16-bit half readers (`v_*_b16`/`u16`/`i16`, `v_mad_{u,i}16`, `v_min3/max3/med3_{u,i}16`, `v_cvt_f16_{u,i}16`, `v_pack_b32_f16`, `v_frexp_*_f16`, `v_ldexp_f16`, `s_bitreplicate_b64_b32`, and `buffer_store_format_d16_*`). Checked by the unit tests in `tests/test_u16_high_half.py` and `tools/valu_fuzz.py --family f16 --seed 2 --programs 200 --wave both` on AMD Ryzen 5 7600 iGPU (driver 24.10.24: 400/400 native, up from 399/400; 200/200 wave64 emulated on both AMD and NVIDIA). **The packed 16-bit shifts follow the same rule** (`v_pk_lshlrev_b16`, `v_pk_lshrrev_b16`, `v_pk_ashrrev_i16`, since 2026-11-23): the shift amount comes from `OpShiftRightLogical %uint s0 16` then `& 15`, and the value from `OpShiftRight{Logical,Arithmetic} %uint s1 16`, where the code used `OpBitField{S,U}Extract … 16 16`. A field extract at offset 16 is what an AMD Windows driver 25.10.36 on a gfx1036 iGPU reads with the offset taken mod 16, so both result halves got the **low** half of the source: 5 of 2,000 `tools/valu_fuzz.py --family f16 --programs 2000 --seed 1 --wave 32` programs, all in wave32 and none in native wave64 (@Darkz0rz, reported in the coordination issue as SHADER-777). The same 2,000 programs match 2000/2000 on a second gfx1036 (Radeon iGPU of a Ryzen 7 7800X3D, driver 31.0.24002.92), where the field-extract form was already correct, and its SPIR-V does contain the offset-16 extracts, so the change is a lowering that survives both drivers, not a value change: `OpBitField{S,U}Extract(x, 16, 16)` equals `x >> 16` with the matching right shift and `OpBitFieldUExtract(x, 16, 4)` equals `(x >> 16) & 15`, checked for 200,010 inputs including 0, 1, 0xFFFF, 0x10000, 0x80000000, 0xFFFFFFFF, 0x7FFFFFFF and 0x8000. Counted over the 26,503 listings: 1 `v_pk_lshlrev_b16` in 1 compute listing (`op_sel_hi:[0,1]`) and 1 `v_pk_lshrrev_b16` in 1 other (`op_sel:[1,0] op_sel_hi:[0,0]`), no `v_pk_ashrrev_i16` and no `_sdwa` form; those two modules are the only ones whose output changes. Values are checked by the unit tests in `tests/test_pk16_diff.py` and the `ps_ops4` / `ps_ops6` fixtures. **All remaining 16-bit high-half readers follow the same rule (`SHADER-HIGH-HALF-SHARED-READERS`)**: `v_cmp(x)_*_{u16,i16}`, `sdwa_src` `WORD_1` (with and without `sext()`), `v_pk_{add,sub,mul_lo,mad,max,min}_{u16,i16}`, `v_qsad_pk_u16_u8`/`v_mqsad_pk_u16_u8`, `v_sad_u16`, `v_mad_{u32_u16,i32_i16}`, and `image_store d16` now route through `Gen.u16_half` / `Gen.i16_half` so no 16-bit half reader emits `OpBitField{S,U}Extract ... 16 16`. CPU-checked by `tests/semantic/test_high_half_shared_readers.py` (structural + `spirv_mini_interp` parity); not yet GPU-verified. | | 545 | | 16-bit high-half reads (`Gen.u16_half` / `Gen.i16_half`, #1506) | Reading the high 16 bits of a 32-bit word emits `OpShiftRightLogical %uint u 16` (`u16_half`) or `OpShiftRightArithmetic %int (as_int(u)) 16` (`i16_half`) alone, without a trailing `OpBitwiseAnd ... 0xFFFF` or `OpBitFieldSExtract ... 0 16` (used for the low half only). On 32-bit inputs `>> 16` already zero- or sign-extends bits 31..16, and AMD's Windows LLPC compiler (measured on RDNA2, drivers 22.40.84.06 in #1506 and 24.10.24 on Ryzen 5 7600 iGPU) miscompiles both `(u >> 16) & 0xFFFF` and `OpBitFieldSExtract (u >> 16) 0 16` after two partial-half writes to `u` by dropping the `>> 16` when the result feeds `OpIAdd`, `OpIMul`, or `OpShiftLeftLogical` (e.g. `(0x41b1 << 1) & 0xFFFF` became `0x0000` instead of `0x8362` in `cs_f16fuzz_s2_163_w64`, `s_bitreplicate`'s `((0x41b1 << 8) \| 0x41b1) & 0x00ff00ff` became `0xb10000` instead of `0x4100b1`, and `SExtract(0x91b1138b >> 16, 0, 16) + 1` became `0x91b10001` instead of `0xffff91b2`). Applies across all 16-bit half readers (`v_*_b16`/`u16`/`i16`, `v_mad_{u,i}16`, `v_min3/max3/med3_{u,i}16`, `v_cvt_f16_{u,i}16`, `v_pack_b32_f16`, `v_frexp_*_f16`, `v_ldexp_f16`, `s_bitreplicate_b64_b32`, and `buffer_store_format_d16_*`). Checked by the unit tests in `tests/test_u16_high_half.py` and `tools/valu_fuzz.py --family f16 --seed 2 --programs 200 --wave both` on AMD Ryzen 5 7600 iGPU (driver 24.10.24: 400/400 native, up from 399/400; 200/200 wave64 emulated on both AMD and NVIDIA). **The packed 16-bit shifts follow the same rule** (`v_pk_lshlrev_b16`, `v_pk_lshrrev_b16`, `v_pk_ashrrev_i16`, since 2026-11-23): the shift amount comes from `OpShiftRightLogical %uint s0 16` then `& 15`, and the value from `OpShiftRight{Logical,Arithmetic} %uint s1 16`, where the code used `OpBitField{S,U}Extract … 16 16`. A field extract at offset 16 is what an AMD Windows driver 25.10.36 on a gfx1036 iGPU reads with the offset taken mod 16, so both result halves got the **low** half of the source: 5 of 2,000 `tools/valu_fuzz.py --family f16 --programs 2000 --seed 1 --wave 32` programs, all in wave32 and none in native wave64 (@Darkz0rz, reported in the coordination issue as SHADER-777). The same 2,000 programs match 2000/2000 on a second gfx1036 (Radeon iGPU of a Ryzen 7 7800X3D, driver 31.0.24002.92), where the field-extract form was already correct, and its SPIR-V does contain the offset-16 extracts, so the change is a lowering that survives both drivers, not a value change: `OpBitField{S,U}Extract(x, 16, 16)` equals `x >> 16` with the matching right shift and `OpBitFieldUExtract(x, 16, 4)` equals `(x >> 16) & 15`, checked for 200,010 inputs including 0, 1, 0xFFFF, 0x10000, 0x80000000, 0xFFFFFFFF, 0x7FFFFFFF and 0x8000. Counted over the 26,503 listings: 1 `v_pk_lshlrev_b16` in 1 compute listing (`op_sel_hi:[0,1]`) and 1 `v_pk_lshrrev_b16` in 1 other (`op_sel:[1,0] op_sel_hi:[0,0]`), no `v_pk_ashrrev_i16` and no `_sdwa` form; those two modules are the only ones whose output changes. Values are checked by the unit tests in `tests/test_pk16_diff.py` and the `ps_ops4` / `ps_ops6` fixtures. **All remaining 16-bit high-half readers follow the same rule (`SHADER-HIGH-HALF-SHARED-READERS`)**: `v_cmp(x)_*_{u16,i16}`, `sdwa_src` `WORD_1` (with and without `sext()`), `v_pk_{add,sub,mul_lo,mad,max,min}_{u16,i16}`, `v_qsad_pk_u16_u8`/`v_mqsad_pk_u16_u8`, `v_sad_u16`, `v_mad_{u32_u16,i32_i16}`, and `image_store d16` now route through `Gen.u16_half` / `Gen.i16_half` so no 16-bit half reader emits `OpBitField{S,U}Extract ... 16 16`. CPU-checked by `tests/semantic/test_high_half_shared_readers.py` (structural + `spirv_mini_interp` parity); not yet GPU-verified. | |
| 542 | | `v_mac_legacy_f32` | The GFX10.1 VOP2 form of `v_mad_legacy_f32` with D as the addend: D = legacy(S0 * S1) + D, where 0 times anything (inf and NaN included) is +0, with the same denormal flush and VOP3 modifiers. D is read before it is written, as for `v_mac_f32` (LLVM `VOP2Instructions.td`: `V_MAC_LEGACY_F32` has `$src2` tied to `$vdst`). Until 2026-11-22 it raised `Unsupported`. CPU-checked by `MacLegacyF32Tests` in `tests/semantic/test_valu_f32_min3_max3_mad.py` (a 15x8x6 grid against the `v_mad_legacy_f32` reference, the zero rule, clamp/neg, D aliased as a source). **Not GPU-verified**: like the other mad opcodes it exists on gfx1010-1013 only, so no RDNA2 desktop part runs it. | | 546 | | `v_mac_legacy_f32` | The GFX10.1 VOP2 form of `v_mad_legacy_f32` with D as the addend: D = legacy(S0 * S1) + D, where 0 times anything (inf and NaN included) is +0, with the same denormal flush and VOP3 modifiers. D is read before it is written, as for `v_mac_f32` (LLVM `VOP2Instructions.td`: `V_MAC_LEGACY_F32` has `$src2` tied to `$vdst`). Until 2026-11-22 it raised `Unsupported`. CPU-checked by `MacLegacyF32Tests` in `tests/semantic/test_valu_f32_min3_max3_mad.py` (a 15x8x6 grid against the `v_mad_legacy_f32` reference, the zero rule, clamp/neg, D aliased as a source). **Not GPU-verified**: like the other mad opcodes it exists on gfx1010-1013 only, so no RDNA2 desktop part runs it. | |
| 543 | | `v_cmp_*_f64`, `v_cmpx_*_f64` | All 16 binary64 vector compare predicates (`f`, `lt`, `eq`, `le`, `gt`, `lg`, `ge`, `o`, `u`, `nge`, `nlg`, `ngt`, `nle`, `neq`, `nlt`, `tru`) for both `v_cmp_` (VCC/SGPR lane mask) and `v_cmpx_` (EXEC narrowing), lowered in `Gen.compare_f64_cond` via pure 32-bit `%uint` IEEE-754 ordering (NaN detection, `-0.0` canonicalized to `+0.0`, sign-magnitude to monotonic unsigned 64-bit key) with no `Float64` capability required and no denormal flushing. Supports VGPR/SGPR pairs, `fimm`, sign-extended inline integers (`-16..64`), 32-bit upper-half literals, and VOP3 `abs`/`neg` sign-bit modifiers on both sources; inactive lanes write 0 for `v_cmp_*_f64` and stay inactive for `v_cmpx_*_f64`. Source: AMD RDNA2 ISA VOPC/VOP3 binary64 compares. CPU-checked by `tests/semantic/test_cmp_f64.py` (all 16 predicates across full IEEE-754 edge grid including subnormals/1-ULP pairs/±0/±inf/sNaN/qNaN, SGPR pairs, constants, `abs`/`neg`, `v_cmpx_*_f64`, inactive lanes, no `Float64` capability, bad-operand rejections). GPU-checked by `runtime/test/shaders/cs_w32_cmp_f64.asm`: all 16 predicates of both forms on 256 memory-fed pairs (the product of 16 values: ±inf, ±max, the 1-ULP neighbours of ±1, the smallest subnormals, ±0, the smallest normal, a NaN with its payload in the low dword only, a negative quiet NaN), `tru` with the odd threads off (an inactive lane gets VCC 0 and stays off through `v_cmpx_`), and `lt`/`nge` with `abs`/`neg`, all 1536 heap words exact on an RTX 4070 Ti (NVIDIA 620.70.06, Linux) and on llvmpipe (subgroup 8). That run checks the translated SPIR-V on a driver against IEEE-754, not RDNA2 itself; SGPR-pair and constant operands are not in it. Measured on native gfx1100 (single thread, 116 cases): all 16 predicates return IEEE-754 results (`eq` on `NaN` is 0 while `neq`/`nlt`/`nge`/`ngt` are 1, `lg` is 0 for `NaN` with `o`/`u` splitting on it, `eq(+0.0, -0.0)` is 1, `inf` compares equal to itself) and `v_cmpx_*_f64` narrows `EXEC` instead of writing `VCC`. | | 547 | | `v_cmp_*_f64`, `v_cmpx_*_f64` | All 16 binary64 vector compare predicates (`f`, `lt`, `eq`, `le`, `gt`, `lg`, `ge`, `o`, `u`, `nge`, `nlg`, `ngt`, `nle`, `neq`, `nlt`, `tru`) for both `v_cmp_` (VCC/SGPR lane mask) and `v_cmpx_` (EXEC narrowing), lowered in `Gen.compare_f64_cond` via pure 32-bit `%uint` IEEE-754 ordering (NaN detection, `-0.0` canonicalized to `+0.0`, sign-magnitude to monotonic unsigned 64-bit key) with no `Float64` capability required and no denormal flushing. Supports VGPR/SGPR pairs, `fimm`, sign-extended inline integers (`-16..64`), 32-bit upper-half literals, and VOP3 `abs`/`neg` sign-bit modifiers on both sources; inactive lanes write 0 for `v_cmp_*_f64` and stay inactive for `v_cmpx_*_f64`. Source: AMD RDNA2 ISA VOPC/VOP3 binary64 compares. CPU-checked by `tests/semantic/test_cmp_f64.py` (all 16 predicates across full IEEE-754 edge grid including subnormals/1-ULP pairs/±0/±inf/sNaN/qNaN, SGPR pairs, constants, `abs`/`neg`, `v_cmpx_*_f64`, inactive lanes, no `Float64` capability, bad-operand rejections). GPU-checked by `runtime/test/shaders/cs_w32_cmp_f64.asm`: all 16 predicates of both forms on 256 memory-fed pairs (the product of 16 values: ±inf, ±max, the 1-ULP neighbours of ±1, the smallest subnormals, ±0, the smallest normal, a NaN with its payload in the low dword only, a negative quiet NaN), `tru` with the odd threads off (an inactive lane gets VCC 0 and stays off through `v_cmpx_`), and `lt`/`nge` with `abs`/`neg`, all 1536 heap words exact on an RTX 4070 Ti (NVIDIA 620.70.06, Linux) and on llvmpipe (subgroup 8). That run checks the translated SPIR-V on a driver against IEEE-754, not RDNA2 itself; SGPR-pair and constant operands are not in it. Measured on native gfx1100 (single thread, 116 cases): all 16 predicates return IEEE-754 results (`eq` on `NaN` is 0 while `neq`/`nlt`/`nge`/`ngt` are 1, `lg` is 0 for `NaN` with `o`/`u` splitting on it, `eq(+0.0, -0.0)` is 1, `inf` compares equal to itself) and `v_cmpx_*_f64` narrows `EXEC` instead of writing `VCC`. | |
| 544 | | Whole-quad mode (`s_wqm_b64` / `s_wqm_b32`) | A lane mask register holds only this lane's bit, so WQM on one (EXEC, VCC, an SGPR the mask analysis found) ORs the bit of the lane's quad, lanes 4n..4n+3 of the wave: two `OpGroupNonUniformQuadSwap` (horizontal, then vertical; capability `GroupNonUniformQuad`) in the default mode in fragment and compute shaders (quad operations are only guaranteed there; vertex, geometry and mesh shaders shuffle from the quad's four lanes), or the four lanes' values read through `%x_buf` under `--wave64-emulate` (no subgroup operation there). A quad never crosses lane 31/32, so the mask bits are exact per half on a 32-wide subgroup; SCC is a wave vote, so on wave64 it needs a 64-wide subgroup or `--wave64-emulate` (as every wave-wide mask op). The result goes to EXEC, VCC or an SGPR pair as a mask, SCC = the wave-wide any of it (same vote as the other mask ops). A 32-bit form in wave64 (`exec_lo`/`exec_hi`, `vcc_lo`/`vcc_hi`, a half-mask SGPR) writes only its own half (`exec_half_write`) and votes SCC over that half only (`cs_wqm_w64_half`). A source that is not a lane mask (a value loaded from memory, a literal) is data: `((x \| x>>1 \| x>>2 \| x>>3) & 0x11111111) * 15` per 32-bit word and SCC = result != 0, no subgroup operation. Assumptions: in compute and mesh shaders the subgroup lane is `LocalInvocationIndex` mod the subgroup size (as for every cross-lane op); a hardware quad is four consecutive lanes of a wave, and in a pixel shader Vulkan's quad (the 2x2 pixels, helper invocations included) is the same four lanes; GPU-checked on both AMD and NVIDIA with `ps_wqm.asm` (every 2x2 block of a 64x64 target, fully covered). **Helper lanes at a triangle edge, measured on RDNA2** (gfx1036, wave64, raw ISA through `tools/ps_oracle.py` on RADV; `tools/ps_helper_probe.py`, docs/shader_validation.md): a pixel wave's entry EXEC is exactly its covered pixels (helpers off); `s_wqm_b64 exec, exec` turns on exactly the quads with a covered pixel, which are packed from lane 0 (a quad with no covered pixel isn't in the wave); lane % 4 = (x & 1) + 2 (y & 1), so lanes 0-3 are top-left, top-right, bottom-left, bottom-right; a helper's `v_interp` gives its own pixel centre (extrapolated, as precisely as a covered pixel), and its v0/v1 hold its own I/J before `s_wqm` too; without `s_wqm` its VGPRs aren't written; an `exp ... vm` with helpers on in EXEC writes no pixel outside the triangle. Not covered: helper-invocation behaviour at triangle edges is untested, and in native mode an absent invocation in a partial quad (a compute group whose size is not a multiple of 4) gives an undefined value (emulated, the missing lanes of a partial wave read as 0). Before this the instruction was the identity, so helper lanes stayed off (#156 SHADER-34: `s_wqm_b64` appears in 4,285 pixel shaders). GPU-checked with `runtime/test/shaders/cs_wqm_w64.asm`, `cs_wqm_w64_half.asm`, `cs_wqm_w32.asm` and `ps_wqm.asm` on AMD Radeon 880M (subgroup 64) and NVIDIA GeForce RTX 5070 Laptop (subgroup 32; `cs_wqm_w64` there needs `LEONIDA_W64_EMULATE=1`), with and without `--wave64-emulate`. On the plain-data path, `s_wqm_b64` also reads both `%vcc` and `%vcc_hi` when `vcc` holds plain scalar data, and non-mask destinations (`m0`, `null`, and plain-data `vcc`/`vcc_lo`/`vcc_hi`) store the 32/64-bit WQM words directly instead of a per-lane bit (CPU-checked by `tests/semantic/test_wqm_data_vcc_and_dst.py`, not GPU-verified). | | 548 | | Whole-quad mode (`s_wqm_b64` / `s_wqm_b32`) | A lane mask register holds only this lane's bit, so WQM on one (EXEC, VCC, an SGPR the mask analysis found) ORs the bit of the lane's quad, lanes 4n..4n+3 of the wave: two `OpGroupNonUniformQuadSwap` (horizontal, then vertical; capability `GroupNonUniformQuad`) in fragment shaders (where Vulkan guarantees complete 2×2 pixel quads including helper invocations), `OpGroupNonUniformBallot` plus 4-bit quad-nibble extraction in compute, vertex, geometry and mesh shaders (exact on partial quads of any size up to 128 lanes without needing `GroupNonUniformQuad` or shuffles), or the four lanes' values read through `%x_buf` under `--wave64-emulate` (no subgroup operation there). A quad never crosses lane 31/32, so the mask bits are exact per half on a 32-wide subgroup; SCC is a wave vote, so on wave64 it needs a 64-wide subgroup or `--wave64-emulate` (as every wave-wide mask op). The result goes to EXEC, VCC or an SGPR pair as a mask, SCC = the wave-wide any of it (same vote as the other mask ops). A 32-bit form in wave64 (`exec_lo`/`exec_hi`, `vcc_lo`/`vcc_hi`, a half-mask SGPR) writes only its own half (`exec_half_write`) and votes SCC over that half only (`cs_wqm_w64_half`). A source that is not a lane mask (a value loaded from memory, a literal) is data: `((x \| x>>1 \| x>>2 \| x>>3) & 0x11111111) * 15` per 32-bit word and SCC = result != 0, no subgroup operation. Assumptions: in compute and mesh shaders the subgroup lane is `LocalInvocationIndex` mod the subgroup size (as for every cross-lane op); a hardware quad is four consecutive lanes of a wave, and in a pixel shader Vulkan's quad (the 2x2 pixels, helper invocations included) is the same four lanes; GPU-checked on both AMD and NVIDIA with `ps_wqm.asm` (every 2x2 block of a 64x64 target, fully covered). **Helper lanes at a triangle edge, measured on RDNA2** (gfx1036, wave64, raw ISA through `tools/ps_oracle.py` on RADV; `tools/ps_helper_probe.py`, docs/shader_validation.md): a pixel wave's entry EXEC is exactly its covered pixels (helpers off); `s_wqm_b64 exec, exec` turns on exactly the quads with a covered pixel, which are packed from lane 0 (a quad with no covered pixel isn't in the wave); lane % 4 = (x & 1) + 2 (y & 1), so lanes 0-3 are top-left, top-right, bottom-left, bottom-right; a helper's `v_interp` gives its own pixel centre (extrapolated, as precisely as a covered pixel), and its v0/v1 hold its own I/J before `s_wqm` too; without `s_wqm` its VGPRs aren't written; an `exp ... vm` with helpers on in EXEC writes no pixel outside the triangle. Partial quads in CS/VS/GS/MS are now exact natively via ballot nibble extraction (`tests/semantic/test_absent_lane_ub.py`, `tests/test_absent_lane_gpu.py`). Before this the instruction was the identity, so helper lanes stayed off (#156 SHADER-34: `s_wqm_b64` appears in 4,285 pixel shaders). GPU-checked with `runtime/test/shaders/cs_wqm_w64.asm`, `cs_wqm_w64_half.asm`, `cs_wqm_w32.asm` and `ps_wqm.asm` on AMD Radeon 880M (subgroup 64) and NVIDIA GeForce RTX 5070 Laptop (subgroup 32; `cs_wqm_w64` there needs `LEONIDA_W64_EMULATE=1`), with and without `--wave64-emulate`. On the plain-data path, `s_wqm_b64` also reads both `%vcc` and `%vcc_hi` when `vcc` holds plain scalar data, and non-mask destinations (`m0`, `null`, and plain-data `vcc`/`vcc_lo`/`vcc_hi`) store the 32/64-bit WQM words directly instead of a per-lane bit (CPU-checked by `tests/semantic/test_wqm_data_vcc_and_dst.py`, not GPU-verified). | |
| 545 | | `buffer_atomic_{and,or,xor,swap}_x2` | `M = op(M, DATA)` on the 64-bit element at the MUBUF address (two dwords, low first); with `glc` the old 64 bits are returned in `vdata[0:1]`. A bitwise op or an exchange leaves the same memory done one dword at a time, so each dword is its own 32-bit `OpAtomic*` and no Int64 atomics are needed. **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. Each dword is its own 32-bit `OpAtomic*`, so no Int64 atomics are needed; 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. **Bounds:** the check covers the whole 8-byte element, all or nothing, as for a typed 32_32 element (`buffer_address(elem="fmt")`). An out-of-range or inactive lane leaves memory alone and returns 0, as `buffer_atomic` does. How hardware treats a 64-bit atomic that is only partly in range is **not measured**. Still `Unsupported`: `add/sub/min/max_x2` and `cmpswap_x2`. Until 2026-11-22 every `_x2` buffer atomic was rejected. CPU-checked by `tests/semantic/test_buffer_atomics_x2.py` (the four ops with and without `glc`, an element ending exactly at `num_records`, half and fully out of range, seeded values, rejected forms). **Not GPU-verified.** | | 549 | | `buffer_atomic_{and,or,xor,swap}_x2` | `M = op(M, DATA)` on the 64-bit element at the MUBUF address (two dwords, low first); with `glc` the old 64 bits are returned in `vdata[0:1]`. A bitwise op or an exchange leaves the same memory done one dword at a time, so each dword is its own 32-bit `OpAtomic*` and no Int64 atomics are needed. **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. Each dword is its own 32-bit `OpAtomic*`, so no Int64 atomics are needed; 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. **Bounds:** the check covers the whole 8-byte element, all or nothing, as for a typed 32_32 element (`buffer_address(elem="fmt")`). An out-of-range or inactive lane leaves memory alone and returns 0, as `buffer_atomic` does. How hardware treats a 64-bit atomic that is only partly in range is **not measured**. Still `Unsupported`: `add/sub/min/max_x2` and `cmpswap_x2`. Until 2026-11-22 every `_x2` buffer atomic was rejected. CPU-checked by `tests/semantic/test_buffer_atomics_x2.py` (the four ops with and without `glc`, an element ending exactly at `num_records`, half and fully out of range, seeded values, rejected forms). **Not GPU-verified.** | |
| 546 | | Per-lane descriptor selection | The translator executes the first-active-lane read, EXEC selection, scalar descriptor load and remaining-lane retry as ordinary wave instructions. The hand-written `waterfall_table_offset.asm` fixture reads four different buffers and checks every lane on wave32, native wave64 and emulated wave64. The graphics partition analysis accepts an unmodified full-word integer equality as evidence that selected lanes hold the first lane's word. A float comparison accepts both signs of zero. The signed-zero execution fixture produces different raw outputs when a 64-lane group is split and therefore requires tier C. See Marvis's VIctory waterfall analysis (b1c8306, ffe310e) for the distinction between comparing descriptor words and comparing the offset of a descriptor load. | | 550 | | Per-lane descriptor selection | The translator executes the first-active-lane read, EXEC selection, scalar descriptor load and remaining-lane retry as ordinary wave instructions. The hand-written `waterfall_table_offset.asm` fixture reads four different buffers and checks every lane on wave32, native wave64 and emulated wave64. The graphics partition analysis accepts an unmodified full-word integer equality as evidence that selected lanes hold the first lane's word. A float comparison accepts both signs of zero. The signed-zero execution fixture produces different raw outputs when a 64-lane group is split and therefore requires tier C. See Marvis's VIctory waterfall analysis (b1c8306, ffe310e) for the distinction between comparing descriptor words and comparing the offset of a descriptor load. | |
| 547 | | Wave64 graphics: partition invariance (SHADER-10) | A wave64 VS/PS/GS on a 32-wide subgroup is exact **iff its observable results do not change when the wave is cut into two 32-lane halves** (the host forms the subgroups of graphics stages, so there is no partner half to exchange with). `tools/wave64_halves.py` decides it from the code (forward taint dataflow over the basic blocks, plus control dependence on wave-wide votes) and the translator records it in `index.json` as `wave64_graphics` (`A`/`B`/`C`), `wave64_graphics_reasons` (tier C) and `wave64_graphics_idioms` (tier B). **A**: only per-lane arithmetic, votes that skip lane-masked work (`s_cbranch_execz/execnz`; `vccz/vccnz` whose run side starts by narrowing EXEC to that VCC and whose other side is the join, with no code of its own: a half that votes no runs that side, the wave does not; the same holds for `s_cbranch_execz/execnz`: the side that runs when EXEC is zero is taken by a half with no active lane, so it must be the join (or only jumps to it) or the exit of a loop the vote closes, else tier C `unsafe-execz-branch`; `s_cbranch_scc*` after a vote is the same kind of skip, any other reader of that SCC, `s_cselect`/`s_cmov`/`s_addc`, is tier C; a vote is on the mask register's value when it was taken, so a new value in that register before the branch (`v_cmp` into the pair or VCC, `s_mov_b64`, `s_cselect_b64`: none of them writes SCC) ends it, and the branch is judged as a plain SCC branch, SHADER-820), whole-quad masks, `ds_bpermute`/`ds_permute`/`v_permlane16`/`v_permlanex16`/`ds_swizzle` (they stay inside a half), a `ds_bpermute`/`ds_permute` address made from the lane id (`v_mbcnt_lo` then `v_mbcnt_hi` of -1) when it is the same modulo 128 bytes in the wave and in a half (the id is 0..63 there and 0..31 here, equal modulo 32 lanes; sums, differences and bitwise ops with invariant values keep that, a left shift by c multiplies the modulus by 2^c, and the permute uses address bits 2..6 of its half only: `(id ^ 1) << 2` is exact, `id << 1`, a right shift of the id or the low count alone stay tier C `lane-id`), loops closed by `execnz` with no scalar state carried, and the early exit of a pixel kill: `s_cbranch_scc0/scc1` (or `vccz/vccnz`) on a lane mask's own "not empty" (the last SCC writer is a 64-bit logic op into that mask, e.g. `s_andn2_b64 live, live, exec`, or `s_cmp_lg_u64 mask, 0`, and nothing rewrites the mask before the branch) to a block that only sets EXEC from that mask or 0 (`s_mov_b64 exec`, or `s_and_b64 exec` with it), may then export with that EXEC (an export is allowed, not required), and ends (no other code, store or successor), while the run side narrows EXEC into the mask's whole quads before anything but mask arithmetic (`s_mov_b64`, `s_and_b64`, `s_wqm_b64`) runs, the narrowing itself possibly an `s_and_saveexec_b64` / `s_andn2_saveexec_b64` (or `_wrexec_`) whose source is inside, and keeps it inside on every path from there, loops included (a must-dataflow: an EXEC write keeps it inside only when it is provably a subset: `v_cmpx`, `s_and_b64` with one operand known inside, `s_andn2_b64` / `s_andn2_saveexec_b64` whose first operand is, `s_and_saveexec_b64` while inside or from one that is, `s_andn1`/`s_or`/`s_xor_saveexec_b64` only while inside (the latter two also from one that is), and copies, `s_wqm_b64`, `s_or_b64` and `s_xor_b64` of operands known to be inside (0 counts as inside); a saveexec destination holds the old EXEC and a wrexec one the new, each inside only if that EXEC was), and no `exp ... vm` can run before the vote. A half whose mask is empty then writes nothing and discards its pixels in the exit, and in the wave its lanes are off to the end, so the wave discards them too; an exit shared by several kills reads a mask redefined behind the earlier votes and stays tier C. GPU-checked by `ps_w64_a_discard` (below). `s_cbranch_scc*` after a vote is the same kind of skip, any other reader of that SCC, `s_cselect`/`s_cmov`/`s_addc`, is tier C; a vote is on the mask register's value when it was taken, so a new value in that register before the branch (`v_cmp` into the pair or VCC, `s_mov_b64`, `s_cselect_b64`: none of them writes SCC) ends it, and the branch is judged as a plain SCC branch, SHADER-820), whole-quad masks, `ds_bpermute`/`v_permlane16` (they stay inside a half, not GPU-tested here: no fixture; `s_cbranch_scc*` after a vote is the same kind of skip, any other reader of that SCC, `s_cselect`/`s_cmov`/`s_addc`, is tier C), whole-quad masks, `ds_bpermute`/`v_permlane16` (they stay inside a half, not GPU-tested here: no fixture; `ds_swizzle` and `v_permlanex16` likewise; GPU-checked at required 64 and 32 lanes by `ps_w64_a_bpermute`, `ps_w64_a_permlane` (`v_permlane16` and `v_permlanex16`) and `ps_w64_a_swizzle` in `w64_graphics.py`, TEST-433), loops closed by `execnz` with no scalar state carried. `ds_swizzle` and `v_permlanex16` likewise), loops closed by `execnz` with no scalar state carried. A `vccz`/`vccnz` on a wave-uniform compare is no lane vote and is tier A too: a `v_cmp` made while EXEC is the launch mask from untainted immediates, scalars that are no lane mask and VGPRs written from them (optionally ANDed with EXEC, the LLVM form `s_and_b64 vcc, exec, s[..]`) gives every launch lane or none, so each half votes as the wave does and both sides may have code and scalars of their own (if/else, a uniform loop back edge; the mask itself read as data, e.g. exported, is still tier C `cross-lane`), while the same compare under a narrowed EXEC (a half with no active lane votes no and keeps its own scalars) or on a tainted value (`v_readfirstlane` of a varying VGPR, a lane count, an AND with a lane mask) stays tier C; confirmed on the wave interpreter (`UniformVote` in `tests/semantic/test_wave64_halves.py`: 64 lanes against two waves of 32, equal for the accepted forms with s4 = 9 and s4 = 1, different for each near miss) and by `ps_w64_a_uniform_vote`, which gives its derived words on an NVIDIA GeForce RTX 5080 (Linux, driver 580.65.06, 32 only). **B**: also a waterfall loop (`v_readfirstlane` of a varying value, `v_cmp_eq` against the same VGPR, `saveexec`, body, `s_xor exec`, `execnz`; the scalar only used inside the body), a wave-aggregated atomic (`s_bcnt1` of EXEC, `v_mbcnt` rank of that same EXEC, one `buffer_atomic_add` of that count (the count of the mask the rank ranks) by the rank-0 lane only, at a wave-uniform address (a uniform VGPR, or one the elected lane wrote from scalars and constants since EXEC last changed; a per-lane address such as a pixel coordinate is tier C `elected-lane`, since each half elects its own lane and bumps another counter), `v_readfirstlane` of the result with EXEC restored, base + rank as a store address, the rank counting the very mask the atomic's count was taken of (a rank of the entry EXEC or of a saved copy next to a base of the narrowed one is tier C `lane-rank`); the rank alone or the base alone is not a slot: exact as a set of slots, **the order of the slots within a wave is not preserved**, a 64-lane wave takes one run of slots, two halves take two), `v_readfirstlane` / `v_readlane` of a VGPR written from scalars and constants while EXEC was the launch mask (the same in every lane), a `v_writelane` / `v_readlane` spill pair on one constant lane below 32. **C**: anything else that reaches an export, a store's data, a branch or EXEC: lane count / rank / first-lane index / raw lane id (`v_mbcnt` of -1), `v_readlane` of a varying value at any lane (on a wave64 every lane gets hardware lane N, in halves each half gets its own lane N, so lane 7 is as wrong as lane 40; the research note's row 9 is too generous here); an analysis failure is tier C with reason `analysis-error` (the translation does not fail), `v_writelane` to a non-constant or >= 32 lane, a 32-bit access to half of a lane mask (`exec_hi`, `vcc_hi`, a mask pair's odd register), a mask read as data (including a mask combined by `s_and/or/andn2_b64` with a register that is not one: a user value, a loaded mask), a scalar defined behind a wave-wide vote and read where it may not have run (`s_add s5, s5, 1` after `s_cbranch_vccz`; a trip count in an SGPR of a divergent loop: the halves vote differently), a branch on a count, an elected-lane side effect that is not a count, `ds_append`/`ds_consume`. The check is conservative: unknown means C. `--wave64-graphics=warn` (default) marks tier C and counts it in the summary line, `error` refuses it (`Unsupported`), `off` skips the analysis; `python tools/wave64_halves.py --census <spirv>/index.json` prints tier, reason and idiom counts (no names); it complements `tools/wave64_graphics_scan.py` (#1132), which counts candidate cross-half opcodes in the disassembly before translation and decides nothing. **Corpus census** (1.0.2.1, all 26,503 shaders translated at `main` `f847748c` with `--wave64-emulate`, `--census` over that index): 13,405 wave64 graphics shaders (2,236 VS, 10,974 PS, 195 GS, the FSSM header's wave size, see *Wave size*); tier A 4,033 (30.1%), B 85 (0.6%), C 9,287 (69.3%): VS 1,455/79/702, PS 2,383/6/8,585, GS 195/0/0. Tier C reasons (a shader can have several): unsafe-vote-branch 8,285, tainted-branch 6,547, tainted-exec 5,189, cross-lane 4,764, stale-scalar 3,415, mask-half 759, unsafe-execz-branch 583, first-lane 353, waterfall-scalar 161, lane-id 152, lane-count 1. Idiom tags, counted on every shader that carries one whatever its tier (`--census` prints them as "tier B idioms"; 85 shaders are tier B): readfirstlane-uniform 626, lane-spill 287, waterfall 35. (Earlier censuses counted 11,405 shaders, from when the wave size came from code markers: TEST-319 had A 1,919, B 17, C 9,469 with all 195 GS in C; its re-run with the GS ring rule below and #1982 had A 2,117, B 17, C 9,271 with all 195 GS in A.) The lane-id bpermute rule moves no corpus shader. (The TEST-319 census, from when the wave size came from code markers and before the GS ring-address rule below, counted 11,405 shaders: A 1,919, B 17, C 9,469, with all 195 GS in C.) The lane-id bpermute rule moves no corpus shader. **Corpus census** (TEST-319, 1.0.2.1, `--census` over the translated index, re-run with the GS ring rule below and #1982): 11,405 wave64 graphics shaders (1,179 VS, 10,031 PS, 195 GS); tier A 2,117 (18.6%), B 17 (0.1%), C 9,271 (81.3%): VS 479/14/686, PS 1,443/3/8,585, GS 195/0/0. Tier C reasons (a shader can have several): unsafe-vote-branch 8,285, tainted-branch 6,550, tainted-exec 5,189, cross-lane 4,760, stale-scalar 3,415, mask-half 758, unsafe-execz-branch 583, first-lane 353, waterfall-scalar 161, lane-id 152, lane-count 1. 11,405 wave64 graphics shaders (1,179 VS, 10,031 PS, 195 GS); tier A 1,919 (16.8%), B 17 (0.1%), C 9,469 (83.0%): VS 465/14/700, PS 1,454/3/8,574, GS 0/0/195. Tier C reasons (a shader can have several): unsafe-vote-branch 8,175, tainted-branch 6,582, cross-lane 6,111, tainted-exec 4,959, stale-scalar 3,162, mask-half 758, unsafe-execz-branch 583, first-lane 353, lane-id 277, waterfall-scalar 167, lane-count 1. Tier B idioms: readfirstlane-uniform 558, lane-spill 287, waterfall 35. The lane-id bpermute rule moves no corpus shader. **Corpus coverage is not measured here**: it needs a run over the game's shaders by someone who has them. **Rewrite (the only one the emission needs)**: `v_readlane_b32` of a proven-uniform VGPR reads the lane's own copy instead of shuffling from lane N, because a subgroup shuffle from lane >= 32 of a 32-wide subgroup is undefined (143 of 144 test shaders translate byte-identically to origin/main, only `ps_w64_b_readlane_uniform` changed). Everything else tier B needs is what the translator already emits per subgroup: the ballot/count/rank/first-lane words of `wave_mask` are the subgroup's own (the high word is 0), `v_readfirstlane` is the subgroup's first active lane, a waterfall runs once per distinct value of the subgroup. GPU-checked on AMD Radeon 880M (driver 26.11.2; `requiredSubgroupSizeStages` has FRAGMENT, size 32..64) with `runtime/test/shaders/w64_graphics.py`: each `ps_w64_*` fixture drawn with the fragment subgroup size required to 64 (one hardware wave) and to 32 (two halves). `ps_w64_a_skip`, `_b_waterfall`, `_b_readfirstlane`, `_b_readlane_uniform` and `_b_ballot_atomic` (counter 1024 and the 1024 slot words as a set; slot order differs) match each other and the words their headers derive; `_c_bcnt_export`, `_c_lane_id`, `_c_readlane`, `_c_vote_stale`, `_c_vote_else`, `_c_scc_vote`, `_c_execz_sgpr` (an SGPR written on the exec-zero side and exported) and `_c_waterfall_count` differ between 64 and 32 (the detector is right). `ps_w64_a_one_lane` is the case where only one pixel votes yes (so one half votes and the other does not, in the wave and in the halves): its skip regions (`execz`, `vccz`, `vccnz` with a jump-only fall-through) give equal images at 64 and 32; `_c_vote_else` (code on the vote's no side) and `_c_scc_vote` (SCC of a vote as data) differ. `ps_w64_a_discard` (three kills, two of them dropping whole regions so that some halves lose every pixel while the other half of their wave lives) was drawn on an AMD Radeon RX 580 (RADV, Mesa 26.0.8, required size 64, saved with `W64G_SAVE_REF`) and an NVIDIA GeForce RTX 5070 (32 only, driver 620.73.04, compared with `W64G_REF`): both equal the derived words, discarded pixels keeping the clear value, and each other. NVIDIA GeForce RTX 5070 Laptop (32 only, driver 617.42): tier A/B fixtures equal the derived words and the 880M@64 images (`W64G_SAVE_REF` / `W64G_REF`), tier C fixtures differ from the 880M@64 images. `ps_w64_a_permlane`, `_a_swizzle` and `_a_bpermute` (TEST-319: permlane16 neighbour selects, permlanex16 there and back, swizzle quad-permute, swap and broadcast modes, bpermute from lane-id addresses; every read stays in the pixel's 2x2 quad or comes back, so the words do not depend on how pixels are packed into lanes) give the derived words on an NVIDIA GeForce RTX 5070 (Linux, driver 620.73.04, 32 only). With an AMD Radeon RX 580 (Polaris, RADV Mesa 26.0.8) as the 64-lane reference (`W64G_SAVE_REF`; GCN has one subgroup size, 64, in every stage but no FRAGMENT in `requiredSubgroupSizeStages`, so `vk_harness` counts a requested size equal to a device's only size as applied), the RTX 5070 run of every fixture (`W64G_REF`) equals the reference for all 13 tier A/B fixtures and differs from it for all 11 tier C ones, pixel and vertex; the same reads in a vertex shader run on the wave interpreter (64 lanes against two waves of 32, equal) because a GPU's partial vertex waves leave the lanes they would read empty. Vertex shaders: the VS stage cannot be forced on the 880M (no VERTEX in `requiredSubgroupSizeStages`), so VS is covered by the strict wave interpreter (`tests/semantic/test_wave64_halves.py`: 64 lanes against two waves of 32; tier A/B equal, tier C differs); geometry shaders are not tested (the corpus ones are wave64, see *Wave size*; no fixture). 64 lanes against two waves of 32; tier A/B equal, tier C differs), and on RADV also on the GPU (TEST-251): RADV runs the VS stage (NGG) as wave64 by default and as wave32 with `RADV_PERFTEST=gewave32` (GFX10+, seen in the `RADV_DEBUG=shaders` dump: 64-bit EXEC operations against `exec_lo`), so `w64_graphics.py` draws each `vs_w64_*` fixture both ways, 960 zero-area vertices (`VKH_VERTICES`) that store four words each to the heap, with `vs_w64_c_lane_id` as the probe that the wave size changed (largest lane id 63, then 31). RADV packs 62 or 64 vertices into a wave64 and 30 or 32 into a wave32, and the wave32 waves are the two halves of the wave64 ones: each vertex's wave32 lane is its wave64 lane & 31 (`vs_w64_c_lane_id`, all 960 vertices: waves of 64, 62, 64, 62 ... vertices starting at 0, 64, 126, 190 ... against 32, 32, 32, 30 ... starting at 0, 32, 64, 96, 126 ..., a period of 126 both ways; RADV Mesa 26.3.1 on a gfx1036 iGPU (Raphael, found by sskver) and an RX 7900 XTX (NAVI31, RDNA3); TEST-1700. GFX12 gives the same waves and starts, with every wave32 wave inside one half of a wave64 wave: RX 9070 XT, GFX1201, RDNA4, RADV Mesa 26.2.6, sperm's old upstream PR 7354 (GFX1201 data)), so the 32-lane run is the cut into halves that the tiers describe, not a repacking; tier A/B words are keyed on the vertex index. `vs_w64_a_skip`, `_b_waterfall`, `_b_readlane_uniform` (readfirstlane and readlane 40/63 of uniform VGPRs) and `_b_ballot_atomic` (240 slots as a set) give the derived words at both sizes; `_c_bcnt_export`, `_c_readlane` and `_c_lane_id` differ (the detector is right), on an RX 9070 XT (GFX1201) and a Ryzen 9800X3D iGPU (GFX1036, RDNA2), RADV Mesa 26.3.1; geometry shaders are not tested (no fixture; the corpus has 195 wave64 geometry shaders, all tier C, see the census). `_c_bcnt_export`, `_c_readlane` and `_c_lane_id` differ (the detector is right), on an RX 9070 XT (GFX1201) and a Ryzen 9800X3D iGPU (GFX1036, RDNA2), RADV Mesa 26.3.1; geometry shaders likewise (TEST-251): RADV runs the GS stage (NGG) as wave64 by default and as wave32 with `gewave32`, and `w64_graphics.py` draws each `gs_w64_*` fixture after `vs_ids` (960 vertices, 320 triangles, `VKH_GS`), each invocation finding its triangle from `vs_ids`'s vertex number and storing four words to the heap, with `gs_w64_c_lane_id` as the probe (largest lane id 41, RADV puts at most 42 GS invocations in a wave64, then 31). **LDS writes of a legacy GS:** `rdna2spirv.gs_ds` maps one to an output slot from its offset alone and drops the VGPR address (the lane's GSVS area), so `wave64_halves.py` checks only the data a GS `ds_write` writes, not its address; before, a lane id that only formed the GSVS base made the shader tier C `lane-id`. Confirmed three ways: a hand-written GS with the base `lane id * 96` translates, after `spirv-opt -O`, to the same instructions as without it; `gs_w64_a_ring` (that shape) gives the derived records at wave64 and wave32 on both GPUs; and `tests/semantic/test_wave64_halves.py` (`GeometryRing`) keeps the lane id in the written data, or in a memory store's address, tier C. The corpus GS were that false tier C: all 195 contain `v_mbcnt_hi`, all 195 were tier C in the TEST-319 census, and `wave64_halves.py --census` on the corpus translated at `f847748c` puts all 195 in tier A. `_c_bcnt_export`, `_c_readlane` and `_c_lane_id` differ (the detector is right), on an RX 9070 XT (GFX1201) and a Ryzen 9800X3D iGPU (GFX1036, RDNA2), RADV Mesa 26.3.1; geometry shaders are not tested (the corpus ones are wave64, see *Wave size*; no fixture). The corpus GS form their GSVS base from `v_mbcnt_lo/hi` (all 195 contain `v_mbcnt_hi`): they were all a false tier C, and the census above has all 195 at tier A. `wave64_halves.py --census` on a translated corpus shows it. `_c_bcnt_export`, `_c_readlane` and `_c_lane_id` differ (the detector is right), on an RX 9070 XT (GFX1201) and a Ryzen 9800X3D iGPU (GFX1036, RDNA2), RADV Mesa 26.3.1; geometry shaders are not tested (the corpus ones are wave32; no fixture). Not checked: helper lanes of partial quads; `VK_KHR_shader_maximal_reconvergence` is assumed for waterfall and election loops. Tiers A and B assume subgroups of at least 32 lanes: a fragment stage may run fewer live lanes than the subgroup size it reports (Intel UHD 770: gl_SubgroupSize 32, ballot count 16, a shuffle from lane L^16 returns garbage; measured by kapitche, TEST-433), so `w64_graphics.py` skips the tier A/B pixel fixtures on a device whose minimum subgroup size is below 32 when neither the 64 nor the 32 run took effect; deriving the skip from a measured live fragment width (ballot count) in `vk_harness` is a follow-up. **ADD_TID_ENABLE** (SHADER-833, finding by @shdann in #4571): an access with no `idxen` through a V# whose word3 is a literal (`s_mov_b32` earlier in the block, the notion `rdna2spirv` uses for `sgpr_imm`) with bit 23 set takes the wave lane as its index (`idxen` ignores the bit, see *Swizzled buffer addressing*), so its `buffer_load*`/`tbuffer_load*` result and its `buffer_store*`/`tbuffer_store*`/`buffer_atomic*` address carry the raw lane id: tier C `lane-id`. A literal with the bit clear, and every access with `idxen`, are unchanged. **Assumption**: through a run-time V# (loaded from memory or user data) tiers A and B take ADD_TID_ENABLE as 0 for an access without `idxen`; the code cannot say otherwise. The literal is tracked with the same folds `rdna2spirv` applies to `sgpr_imm` (mirrored in `Analysis.literal_sgpr`: `s_mov_b32/b64`, `s_movk_i32`, `s_pack_*`, `s_bfm_b32`, `s_not_b32`, `s_and/lshl/lshr_b32`, `s_mul_i32`; other folded ops count as run-time). The corpus census was not re-measured with this rule: its tier counts above are from before it and may change. Follow-up, needs the game: count the bound V#s with word3 bit 23 set at run time, and re-run `--census`. | | 551 | | Wave64 graphics: partition invariance (SHADER-10) | A wave64 VS/PS/GS on a 32-wide subgroup is exact **iff its observable results do not change when the wave is cut into two 32-lane halves** (the host forms the subgroups of graphics stages, so there is no partner half to exchange with). `tools/wave64_halves.py` decides it from the code (forward taint dataflow over the basic blocks, plus control dependence on wave-wide votes) and the translator records it in `index.json` as `wave64_graphics` (`A`/`B`/`C`), `wave64_graphics_reasons` (tier C) and `wave64_graphics_idioms` (tier B). **A**: only per-lane arithmetic, votes that skip lane-masked work (`s_cbranch_execz/execnz`; `vccz/vccnz` whose run side starts by narrowing EXEC to that VCC and whose other side is the join, with no code of its own: a half that votes no runs that side, the wave does not; the same holds for `s_cbranch_execz/execnz`: the side that runs when EXEC is zero is taken by a half with no active lane, so it must be the join (or only jumps to it) or the exit of a loop the vote closes, else tier C `unsafe-execz-branch`; `s_cbranch_scc*` after a vote is the same kind of skip, any other reader of that SCC, `s_cselect`/`s_cmov`/`s_addc`, is tier C; a vote is on the mask register's value when it was taken, so a new value in that register before the branch (`v_cmp` into the pair or VCC, `s_mov_b64`, `s_cselect_b64`: none of them writes SCC) ends it, and the branch is judged as a plain SCC branch, SHADER-820), whole-quad masks, `ds_bpermute`/`ds_permute`/`v_permlane16`/`v_permlanex16`/`ds_swizzle` (they stay inside a half), a `ds_bpermute`/`ds_permute` address made from the lane id (`v_mbcnt_lo` then `v_mbcnt_hi` of -1) when it is the same modulo 128 bytes in the wave and in a half (the id is 0..63 there and 0..31 here, equal modulo 32 lanes; sums, differences and bitwise ops with invariant values keep that, a left shift by c multiplies the modulus by 2^c, and the permute uses address bits 2..6 of its half only: `(id ^ 1) << 2` is exact, `id << 1`, a right shift of the id or the low count alone stay tier C `lane-id`), loops closed by `execnz` with no scalar state carried, and the early exit of a pixel kill: `s_cbranch_scc0/scc1` (or `vccz/vccnz`) on a lane mask's own "not empty" (the last SCC writer is a 64-bit logic op into that mask, e.g. `s_andn2_b64 live, live, exec`, or `s_cmp_lg_u64 mask, 0`, and nothing rewrites the mask before the branch) to a block that only sets EXEC from that mask or 0 (`s_mov_b64 exec`, or `s_and_b64 exec` with it), may then export with that EXEC (an export is allowed, not required), and ends (no other code, store or successor), while the run side narrows EXEC into the mask's whole quads before anything but mask arithmetic (`s_mov_b64`, `s_and_b64`, `s_wqm_b64`) runs, the narrowing itself possibly an `s_and_saveexec_b64` / `s_andn2_saveexec_b64` (or `_wrexec_`) whose source is inside, and keeps it inside on every path from there, loops included (a must-dataflow: an EXEC write keeps it inside only when it is provably a subset: `v_cmpx`, `s_and_b64` with one operand known inside, `s_andn2_b64` / `s_andn2_saveexec_b64` whose first operand is, `s_and_saveexec_b64` while inside or from one that is, `s_andn1`/`s_or`/`s_xor_saveexec_b64` only while inside (the latter two also from one that is), and copies, `s_wqm_b64`, `s_or_b64` and `s_xor_b64` of operands known to be inside (0 counts as inside); a saveexec destination holds the old EXEC and a wrexec one the new, each inside only if that EXEC was), and no `exp ... vm` can run before the vote. A half whose mask is empty then writes nothing and discards its pixels in the exit, and in the wave its lanes are off to the end, so the wave discards them too; an exit shared by several kills reads a mask redefined behind the earlier votes and stays tier C. GPU-checked by `ps_w64_a_discard` (below). `s_cbranch_scc*` after a vote is the same kind of skip, any other reader of that SCC, `s_cselect`/`s_cmov`/`s_addc`, is tier C; a vote is on the mask register's value when it was taken, so a new value in that register before the branch (`v_cmp` into the pair or VCC, `s_mov_b64`, `s_cselect_b64`: none of them writes SCC) ends it, and the branch is judged as a plain SCC branch, SHADER-820), whole-quad masks, `ds_bpermute`/`v_permlane16` (they stay inside a half, not GPU-tested here: no fixture; `s_cbranch_scc*` after a vote is the same kind of skip, any other reader of that SCC, `s_cselect`/`s_cmov`/`s_addc`, is tier C), whole-quad masks, `ds_bpermute`/`v_permlane16` (they stay inside a half, not GPU-tested here: no fixture; `ds_swizzle` and `v_permlanex16` likewise; GPU-checked at required 64 and 32 lanes by `ps_w64_a_bpermute`, `ps_w64_a_permlane` (`v_permlane16` and `v_permlanex16`) and `ps_w64_a_swizzle` in `w64_graphics.py`, TEST-433), loops closed by `execnz` with no scalar state carried. `ds_swizzle` and `v_permlanex16` likewise), loops closed by `execnz` with no scalar state carried. A `vccz`/`vccnz` on a wave-uniform compare is no lane vote and is tier A too: a `v_cmp` made while EXEC is the launch mask from untainted immediates, scalars that are no lane mask and VGPRs written from them (optionally ANDed with EXEC, the LLVM form `s_and_b64 vcc, exec, s[..]`) gives every launch lane or none, so each half votes as the wave does and both sides may have code and scalars of their own (if/else, a uniform loop back edge; the mask itself read as data, e.g. exported, is still tier C `cross-lane`), while the same compare under a narrowed EXEC (a half with no active lane votes no and keeps its own scalars) or on a tainted value (`v_readfirstlane` of a varying VGPR, a lane count, an AND with a lane mask) stays tier C; confirmed on the wave interpreter (`UniformVote` in `tests/semantic/test_wave64_halves.py`: 64 lanes against two waves of 32, equal for the accepted forms with s4 = 9 and s4 = 1, different for each near miss) and by `ps_w64_a_uniform_vote`, which gives its derived words on an NVIDIA GeForce RTX 5080 (Linux, driver 580.65.06, 32 only). **B**: also a waterfall loop (`v_readfirstlane` of a varying value, `v_cmp_eq` against the same VGPR, `saveexec`, body, `s_xor exec`, `execnz`; the scalar only used inside the body), a wave-aggregated atomic (`s_bcnt1` of EXEC, `v_mbcnt` rank of that same EXEC, one `buffer_atomic_add` of that count (the count of the mask the rank ranks) by the rank-0 lane only, at a wave-uniform address (a uniform VGPR, or one the elected lane wrote from scalars and constants since EXEC last changed; a per-lane address such as a pixel coordinate is tier C `elected-lane`, since each half elects its own lane and bumps another counter), `v_readfirstlane` of the result with EXEC restored, base + rank as a store address, the rank counting the very mask the atomic's count was taken of (a rank of the entry EXEC or of a saved copy next to a base of the narrowed one is tier C `lane-rank`); the rank alone or the base alone is not a slot: exact as a set of slots, **the order of the slots within a wave is not preserved**, a 64-lane wave takes one run of slots, two halves take two), `v_readfirstlane` / `v_readlane` of a VGPR written from scalars and constants while EXEC was the launch mask (the same in every lane), a `v_writelane` / `v_readlane` spill pair on one constant lane below 32. **C**: anything else that reaches an export, a store's data, a branch or EXEC: lane count / rank / first-lane index / raw lane id (`v_mbcnt` of -1), `v_readlane` of a varying value at any lane (on a wave64 every lane gets hardware lane N, in halves each half gets its own lane N, so lane 7 is as wrong as lane 40; the research note's row 9 is too generous here); an analysis failure is tier C with reason `analysis-error` (the translation does not fail), `v_writelane` to a non-constant or >= 32 lane, a 32-bit access to half of a lane mask (`exec_hi`, `vcc_hi`, a mask pair's odd register), a mask read as data (including a mask combined by `s_and/or/andn2_b64` with a register that is not one: a user value, a loaded mask), a scalar defined behind a wave-wide vote and read where it may not have run (`s_add s5, s5, 1` after `s_cbranch_vccz`; a trip count in an SGPR of a divergent loop: the halves vote differently), a branch on a count, an elected-lane side effect that is not a count, `ds_append`/`ds_consume`. The check is conservative: unknown means C. `--wave64-graphics=warn` (default) marks tier C and counts it in the summary line, `error` refuses it (`Unsupported`), `off` skips the analysis; `python tools/wave64_halves.py --census <spirv>/index.json` prints tier, reason and idiom counts (no names); it complements `tools/wave64_graphics_scan.py` (#1132), which counts candidate cross-half opcodes in the disassembly before translation and decides nothing. **Corpus census** (1.0.2.1, all 26,503 shaders translated at `main` `f847748c` with `--wave64-emulate`, `--census` over that index): 13,405 wave64 graphics shaders (2,236 VS, 10,974 PS, 195 GS, the FSSM header's wave size, see *Wave size*); tier A 4,033 (30.1%), B 85 (0.6%), C 9,287 (69.3%): VS 1,455/79/702, PS 2,383/6/8,585, GS 195/0/0. Tier C reasons (a shader can have several): unsafe-vote-branch 8,285, tainted-branch 6,547, tainted-exec 5,189, cross-lane 4,764, stale-scalar 3,415, mask-half 759, unsafe-execz-branch 583, first-lane 353, waterfall-scalar 161, lane-id 152, lane-count 1. Idiom tags, counted on every shader that carries one whatever its tier (`--census` prints them as "tier B idioms"; 85 shaders are tier B): readfirstlane-uniform 626, lane-spill 287, waterfall 35. (Earlier censuses counted 11,405 shaders, from when the wave size came from code markers: TEST-319 had A 1,919, B 17, C 9,469 with all 195 GS in C; its re-run with the GS ring rule below and #1982 had A 2,117, B 17, C 9,271 with all 195 GS in A.) The lane-id bpermute rule moves no corpus shader. (The TEST-319 census, from when the wave size came from code markers and before the GS ring-address rule below, counted 11,405 shaders: A 1,919, B 17, C 9,469, with all 195 GS in C.) The lane-id bpermute rule moves no corpus shader. **Corpus census** (TEST-319, 1.0.2.1, `--census` over the translated index, re-run with the GS ring rule below and #1982): 11,405 wave64 graphics shaders (1,179 VS, 10,031 PS, 195 GS); tier A 2,117 (18.6%), B 17 (0.1%), C 9,271 (81.3%): VS 479/14/686, PS 1,443/3/8,585, GS 195/0/0. Tier C reasons (a shader can have several): unsafe-vote-branch 8,285, tainted-branch 6,550, tainted-exec 5,189, cross-lane 4,760, stale-scalar 3,415, mask-half 758, unsafe-execz-branch 583, first-lane 353, waterfall-scalar 161, lane-id 152, lane-count 1. 11,405 wave64 graphics shaders (1,179 VS, 10,031 PS, 195 GS); tier A 1,919 (16.8%), B 17 (0.1%), C 9,469 (83.0%): VS 465/14/700, PS 1,454/3/8,574, GS 0/0/195. Tier C reasons (a shader can have several): unsafe-vote-branch 8,175, tainted-branch 6,582, cross-lane 6,111, tainted-exec 4,959, stale-scalar 3,162, mask-half 758, unsafe-execz-branch 583, first-lane 353, lane-id 277, waterfall-scalar 167, lane-count 1. Tier B idioms: readfirstlane-uniform 558, lane-spill 287, waterfall 35. The lane-id bpermute rule moves no corpus shader. **Corpus coverage is not measured here**: it needs a run over the game's shaders by someone who has them. **Rewrite (the only one the emission needs)**: `v_readlane_b32` of a proven-uniform VGPR reads the lane's own copy instead of shuffling from lane N, because a subgroup shuffle from lane >= 32 of a 32-wide subgroup is undefined (143 of 144 test shaders translate byte-identically to origin/main, only `ps_w64_b_readlane_uniform` changed). Everything else tier B needs is what the translator already emits per subgroup: the ballot/count/rank/first-lane words of `wave_mask` are the subgroup's own (the high word is 0), `v_readfirstlane` is the subgroup's first active lane, a waterfall runs once per distinct value of the subgroup. GPU-checked on AMD Radeon 880M (driver 26.11.2; `requiredSubgroupSizeStages` has FRAGMENT, size 32..64) with `runtime/test/shaders/w64_graphics.py`: each `ps_w64_*` fixture drawn with the fragment subgroup size required to 64 (one hardware wave) and to 32 (two halves). `ps_w64_a_skip`, `_b_waterfall`, `_b_readfirstlane`, `_b_readlane_uniform` and `_b_ballot_atomic` (counter 1024 and the 1024 slot words as a set; slot order differs) match each other and the words their headers derive; `_c_bcnt_export`, `_c_lane_id`, `_c_readlane`, `_c_vote_stale`, `_c_vote_else`, `_c_scc_vote`, `_c_execz_sgpr` (an SGPR written on the exec-zero side and exported) and `_c_waterfall_count` differ between 64 and 32 (the detector is right). `ps_w64_a_one_lane` is the case where only one pixel votes yes (so one half votes and the other does not, in the wave and in the halves): its skip regions (`execz`, `vccz`, `vccnz` with a jump-only fall-through) give equal images at 64 and 32; `_c_vote_else` (code on the vote's no side) and `_c_scc_vote` (SCC of a vote as data) differ. `ps_w64_a_discard` (three kills, two of them dropping whole regions so that some halves lose every pixel while the other half of their wave lives) was drawn on an AMD Radeon RX 580 (RADV, Mesa 26.0.8, required size 64, saved with `W64G_SAVE_REF`) and an NVIDIA GeForce RTX 5070 (32 only, driver 620.73.04, compared with `W64G_REF`): both equal the derived words, discarded pixels keeping the clear value, and each other. NVIDIA GeForce RTX 5070 Laptop (32 only, driver 617.42): tier A/B fixtures equal the derived words and the 880M@64 images (`W64G_SAVE_REF` / `W64G_REF`), tier C fixtures differ from the 880M@64 images. `ps_w64_a_permlane`, `_a_swizzle` and `_a_bpermute` (TEST-319: permlane16 neighbour selects, permlanex16 there and back, swizzle quad-permute, swap and broadcast modes, bpermute from lane-id addresses; every read stays in the pixel's 2x2 quad or comes back, so the words do not depend on how pixels are packed into lanes) give the derived words on an NVIDIA GeForce RTX 5070 (Linux, driver 620.73.04, 32 only). With an AMD Radeon RX 580 (Polaris, RADV Mesa 26.0.8) as the 64-lane reference (`W64G_SAVE_REF`; GCN has one subgroup size, 64, in every stage but no FRAGMENT in `requiredSubgroupSizeStages`, so `vk_harness` counts a requested size equal to a device's only size as applied), the RTX 5070 run of every fixture (`W64G_REF`) equals the reference for all 13 tier A/B fixtures and differs from it for all 11 tier C ones, pixel and vertex; the same reads in a vertex shader run on the wave interpreter (64 lanes against two waves of 32, equal) because a GPU's partial vertex waves leave the lanes they would read empty. Vertex shaders: the VS stage cannot be forced on the 880M (no VERTEX in `requiredSubgroupSizeStages`), so VS is covered by the strict wave interpreter (`tests/semantic/test_wave64_halves.py`: 64 lanes against two waves of 32; tier A/B equal, tier C differs); geometry shaders are not tested (the corpus ones are wave64, see *Wave size*; no fixture). 64 lanes against two waves of 32; tier A/B equal, tier C differs), and on RADV also on the GPU (TEST-251): RADV runs the VS stage (NGG) as wave64 by default and as wave32 with `RADV_PERFTEST=gewave32` (GFX10+, seen in the `RADV_DEBUG=shaders` dump: 64-bit EXEC operations against `exec_lo`), so `w64_graphics.py` draws each `vs_w64_*` fixture both ways, 960 zero-area vertices (`VKH_VERTICES`) that store four words each to the heap, with `vs_w64_c_lane_id` as the probe that the wave size changed (largest lane id 63, then 31). RADV packs 62 or 64 vertices into a wave64 and 30 or 32 into a wave32, and the wave32 waves are the two halves of the wave64 ones: each vertex's wave32 lane is its wave64 lane & 31 (`vs_w64_c_lane_id`, all 960 vertices: waves of 64, 62, 64, 62 ... vertices starting at 0, 64, 126, 190 ... against 32, 32, 32, 30 ... starting at 0, 32, 64, 96, 126 ..., a period of 126 both ways; RADV Mesa 26.3.1 on a gfx1036 iGPU (Raphael, found by sskver) and an RX 7900 XTX (NAVI31, RDNA3); TEST-1700. GFX12 gives the same waves and starts, with every wave32 wave inside one half of a wave64 wave: RX 9070 XT, GFX1201, RDNA4, RADV Mesa 26.2.6, sperm's old upstream PR 7354 (GFX1201 data)), so the 32-lane run is the cut into halves that the tiers describe, not a repacking; tier A/B words are keyed on the vertex index. `vs_w64_a_skip`, `_b_waterfall`, `_b_readlane_uniform` (readfirstlane and readlane 40/63 of uniform VGPRs) and `_b_ballot_atomic` (240 slots as a set) give the derived words at both sizes; `_c_bcnt_export`, `_c_readlane` and `_c_lane_id` differ (the detector is right), on an RX 9070 XT (GFX1201) and a Ryzen 9800X3D iGPU (GFX1036, RDNA2), RADV Mesa 26.3.1; geometry shaders are not tested (no fixture; the corpus has 195 wave64 geometry shaders, all tier C, see the census). `_c_bcnt_export`, `_c_readlane` and `_c_lane_id` differ (the detector is right), on an RX 9070 XT (GFX1201) and a Ryzen 9800X3D iGPU (GFX1036, RDNA2), RADV Mesa 26.3.1; geometry shaders likewise (TEST-251): RADV runs the GS stage (NGG) as wave64 by default and as wave32 with `gewave32`, and `w64_graphics.py` draws each `gs_w64_*` fixture after `vs_ids` (960 vertices, 320 triangles, `VKH_GS`), each invocation finding its triangle from `vs_ids`'s vertex number and storing four words to the heap, with `gs_w64_c_lane_id` as the probe (largest lane id 41, RADV puts at most 42 GS invocations in a wave64, then 31). **LDS writes of a legacy GS:** `rdna2spirv.gs_ds` maps one to an output slot from its offset alone and drops the VGPR address (the lane's GSVS area), so `wave64_halves.py` checks only the data a GS `ds_write` writes, not its address; before, a lane id that only formed the GSVS base made the shader tier C `lane-id`. Confirmed three ways: a hand-written GS with the base `lane id * 96` translates, after `spirv-opt -O`, to the same instructions as without it; `gs_w64_a_ring` (that shape) gives the derived records at wave64 and wave32 on both GPUs; and `tests/semantic/test_wave64_halves.py` (`GeometryRing`) keeps the lane id in the written data, or in a memory store's address, tier C. The corpus GS were that false tier C: all 195 contain `v_mbcnt_hi`, all 195 were tier C in the TEST-319 census, and `wave64_halves.py --census` on the corpus translated at `f847748c` puts all 195 in tier A. `_c_bcnt_export`, `_c_readlane` and `_c_lane_id` differ (the detector is right), on an RX 9070 XT (GFX1201) and a Ryzen 9800X3D iGPU (GFX1036, RDNA2), RADV Mesa 26.3.1; geometry shaders are not tested (the corpus ones are wave64, see *Wave size*; no fixture). The corpus GS form their GSVS base from `v_mbcnt_lo/hi` (all 195 contain `v_mbcnt_hi`): they were all a false tier C, and the census above has all 195 at tier A. `wave64_halves.py --census` on a translated corpus shows it. `_c_bcnt_export`, `_c_readlane` and `_c_lane_id` differ (the detector is right), on an RX 9070 XT (GFX1201) and a Ryzen 9800X3D iGPU (GFX1036, RDNA2), RADV Mesa 26.3.1; geometry shaders are not tested (the corpus ones are wave32; no fixture). Not checked: helper lanes of partial quads; `VK_KHR_shader_maximal_reconvergence` is assumed for waterfall and election loops. Tiers A and B assume subgroups of at least 32 lanes: a fragment stage may run fewer live lanes than the subgroup size it reports (Intel UHD 770: gl_SubgroupSize 32, ballot count 16, a shuffle from lane L^16 returns garbage; measured by kapitche, TEST-433), so `w64_graphics.py` skips the tier A/B pixel fixtures on a device whose minimum subgroup size is below 32 when neither the 64 nor the 32 run took effect; deriving the skip from a measured live fragment width (ballot count) in `vk_harness` is a follow-up. **ADD_TID_ENABLE** (SHADER-833, finding by @shdann in #4571): an access with no `idxen` through a V# whose word3 is a literal (`s_mov_b32` earlier in the block, the notion `rdna2spirv` uses for `sgpr_imm`) with bit 23 set takes the wave lane as its index (`idxen` ignores the bit, see *Swizzled buffer addressing*), so its `buffer_load*`/`tbuffer_load*` result and its `buffer_store*`/`tbuffer_store*`/`buffer_atomic*` address carry the raw lane id: tier C `lane-id`. A literal with the bit clear, and every access with `idxen`, are unchanged. **Assumption**: through a run-time V# (loaded from memory or user data) tiers A and B take ADD_TID_ENABLE as 0 for an access without `idxen`; the code cannot say otherwise. The literal is tracked with the same folds `rdna2spirv` applies to `sgpr_imm` (mirrored in `Analysis.literal_sgpr`: `s_mov_b32/b64`, `s_movk_i32`, `s_pack_*`, `s_bfm_b32`, `s_not_b32`, `s_and/lshl/lshr_b32`, `s_mul_i32`; other folded ops count as run-time). The corpus census was not re-measured with this rule: its tier counts above are from before it and may change. Follow-up, needs the game: count the bound V#s with word3 bit 23 set at run time, and re-run `--census`. | |
| @@ -565,7 +569,22 @@ How the generated SPIR-V expects the runtime to work: | |||
| 565 | | Out-of-bounds typed buffer loads and `DST_SEL=1` | When a MUBUF `buffer_load_format_{x,xy,xyz,xyzw}` or `buffer_load_format_d16_{x,xy,xyz,xyzw}` is out of bounds (`OOB_SELECT` 0–3, `num_records == 0`, partial-element spill, or swizzled OOB), memory is not accessed and raw data channels (`DST_SEL` 4..7) read 0, while the V# `DST_SEL` swizzle still runs: `DST_SEL=0` returns 0 and `DST_SEL=1` returns `1.0f` (`0x3F800000`, `d16` `0x3C00`) iff V# `FORMAT[6:0]` is a valid float, normalized or scaled buffer format (`1..77` ending in `_UNORM`, `_SNORM`, `_USCALED`, `_SSCALED`, or `_FLOAT`), and integer `1` (`0x00000001`, `d16` `0x0001`) for `UINT`/`SINT`, `INVALID` (`0`), and reserved codes (`78..127`). `d16_x` and `d16_xyz` preserve the unaddressed upper 16 bits of the final destination VGPR, and MTBUF `tbuffer_load_format_*` ignores V# `DST_SEL` on both out-of-bounds and `FORMAT=0` loads (returning 0 in addressed channels). Until 2026-11-22 `Gen.buffer_load_format` clamped the post-swizzle result to 0 when `in_b` was false (`SHADER-429`), dropping `DST_SEL=1` on out-of-bounds loads and returning `1.0f` instead of `1` for `DST_SEL=1` with `FORMAT=0`. For a dynamic MUBUF FORMAT with no decoded data channels (INVALID or reserved), the shader skips the physical load even when the descriptor has a nonempty, in-range span. DST_SEL constants still apply. The interpreter read-log fixture and RTX 4070 readback cover FORMAT 0, 78, 127 and valid control 20. **Hardware-verified on RDNA2** (`gfx1036`, Windows 11, driver `32.0.21042.62`, wave32 and wave64, 746 kernels via `tools/hw_oracle`: all 41 `Gen.FORMATS` across `xyzw`/`d16_xyzw`/`d16_xyz`/`d16_x`, all 128 7-bit `FORMAT` codes `0..127` for both `f32` and `d16`, `OOB_SELECT` 0–3, partial spill, swizzled OOB, MTBUF controls, and inactive EXEC lanes), Vulkan GPU-checked across all 128 7-bit `FORMAT` codes (`xyzw`, `d16_xyzw`, `d16_xyz`, `d16_x`) and the `cs_fmt_*`/`cs_oob_*`/`cs_bounds`/`cs_buf_*` fixtures on NVIDIA GeForce RTX 5090 (driver `32.0.16.1088`) and AMD Radeon Graphics (`gfx1036`, driver `32.0.21042.62`), and CPU/`spirv-val`-checked by `tests/semantic/test_buffer_oob_dst_sel.py`. | | 569 | | Out-of-bounds typed buffer loads and `DST_SEL=1` | When a MUBUF `buffer_load_format_{x,xy,xyz,xyzw}` or `buffer_load_format_d16_{x,xy,xyz,xyzw}` is out of bounds (`OOB_SELECT` 0–3, `num_records == 0`, partial-element spill, or swizzled OOB), memory is not accessed and raw data channels (`DST_SEL` 4..7) read 0, while the V# `DST_SEL` swizzle still runs: `DST_SEL=0` returns 0 and `DST_SEL=1` returns `1.0f` (`0x3F800000`, `d16` `0x3C00`) iff V# `FORMAT[6:0]` is a valid float, normalized or scaled buffer format (`1..77` ending in `_UNORM`, `_SNORM`, `_USCALED`, `_SSCALED`, or `_FLOAT`), and integer `1` (`0x00000001`, `d16` `0x0001`) for `UINT`/`SINT`, `INVALID` (`0`), and reserved codes (`78..127`). `d16_x` and `d16_xyz` preserve the unaddressed upper 16 bits of the final destination VGPR, and MTBUF `tbuffer_load_format_*` ignores V# `DST_SEL` on both out-of-bounds and `FORMAT=0` loads (returning 0 in addressed channels). Until 2026-11-22 `Gen.buffer_load_format` clamped the post-swizzle result to 0 when `in_b` was false (`SHADER-429`), dropping `DST_SEL=1` on out-of-bounds loads and returning `1.0f` instead of `1` for `DST_SEL=1` with `FORMAT=0`. For a dynamic MUBUF FORMAT with no decoded data channels (INVALID or reserved), the shader skips the physical load even when the descriptor has a nonempty, in-range span. DST_SEL constants still apply. The interpreter read-log fixture and RTX 4070 readback cover FORMAT 0, 78, 127 and valid control 20. **Hardware-verified on RDNA2** (`gfx1036`, Windows 11, driver `32.0.21042.62`, wave32 and wave64, 746 kernels via `tools/hw_oracle`: all 41 `Gen.FORMATS` across `xyzw`/`d16_xyzw`/`d16_xyz`/`d16_x`, all 128 7-bit `FORMAT` codes `0..127` for both `f32` and `d16`, `OOB_SELECT` 0–3, partial spill, swizzled OOB, MTBUF controls, and inactive EXEC lanes), Vulkan GPU-checked across all 128 7-bit `FORMAT` codes (`xyzw`, `d16_xyzw`, `d16_xyz`, `d16_x`) and the `cs_fmt_*`/`cs_oob_*`/`cs_bounds`/`cs_buf_*` fixtures on NVIDIA GeForce RTX 5090 (driver `32.0.16.1088`) and AMD Radeon Graphics (`gfx1036`, driver `32.0.21042.62`), and CPU/`spirv-val`-checked by `tests/semantic/test_buffer_oob_dst_sel.py`. | |
| 566 | | `v_div_fixup_f32` | Measured natively on an AMD Radeon(TM) Graphics RDNA2 GPU (`gfx1036`, not the console's `gfx1013`; Windows driver 32.0.21042.62, `tools/hw_oracle`, wave32 and wave64 identical on every case: 256 seeded triples across 4 MODEs plus 73 targeted special-case/modifier rows, 0 mismatches). Computes `div_fixup_f32(S0=quotient, S1=denom, S2=numer)` with pure integer SPIR-V ops under the game's inferred MODE (`IEEE=0`, `denorm32=0`, `DX10_CLAMP=1`): VOP3 `abs` (clear bit 31) then `neg` (flip bit 31) apply bitwise to `S0`/`S1`/`S2` before classification (including NaN payloads); `S1`/`S2` subnormals flush to signed zero (`exp == 0`) while `S0` subnormals are preserved; priority order is (1) `NaN(S2) → S2`, (2) `NaN(S1) → S1` (signalling NaNs pass unchanged under `IEEE=0`, quieted only when `IEEE=1`), (3) `0/0` or `±inf/±inf → 0xFFC00000` (`-qNaN`), (4) `zero(S2) ∨ inf(S1) → ±0.0`, (5) `zero(S1) ∨ inf(S2) → ±inf`, (6) `exp(S2) − exp(S1) ≤ −151 → ±0.0` (pure biased-exponent check, beats `NaN(S0)` and `inf(S0)`; no overflow check), (7) `NaN(S0) → ±inf`, (8) `copysign(S0, sign(S1) ⊕ sign(S2))`. Output modifiers `mul:2`/`mul:4`/`div:2` apply before `clamp`, and `clamp` maps NaN to `+0.0` (`DX10_CLAMP=1`) before `FClamp` to `[0, 1]`. Not modelled: `IEEE=1` sNaN quieting, `denorm32=3` keeping `S1`/`S2` subnormals, and the hardware `omod` `-0 → +0` quirk (same as the other f32 ops). Checked bit-for-bit against 73 measured `gfx1036` words in `tests/semantic/test_alu_div_fixup_f32.py`. | | 570 | | `v_div_fixup_f32` | Measured natively on an AMD Radeon(TM) Graphics RDNA2 GPU (`gfx1036`, not the console's `gfx1013`; Windows driver 32.0.21042.62, `tools/hw_oracle`, wave32 and wave64 identical on every case: 256 seeded triples across 4 MODEs plus 73 targeted special-case/modifier rows, 0 mismatches). Computes `div_fixup_f32(S0=quotient, S1=denom, S2=numer)` with pure integer SPIR-V ops under the game's inferred MODE (`IEEE=0`, `denorm32=0`, `DX10_CLAMP=1`): VOP3 `abs` (clear bit 31) then `neg` (flip bit 31) apply bitwise to `S0`/`S1`/`S2` before classification (including NaN payloads); `S1`/`S2` subnormals flush to signed zero (`exp == 0`) while `S0` subnormals are preserved; priority order is (1) `NaN(S2) → S2`, (2) `NaN(S1) → S1` (signalling NaNs pass unchanged under `IEEE=0`, quieted only when `IEEE=1`), (3) `0/0` or `±inf/±inf → 0xFFC00000` (`-qNaN`), (4) `zero(S2) ∨ inf(S1) → ±0.0`, (5) `zero(S1) ∨ inf(S2) → ±inf`, (6) `exp(S2) − exp(S1) ≤ −151 → ±0.0` (pure biased-exponent check, beats `NaN(S0)` and `inf(S0)`; no overflow check), (7) `NaN(S0) → ±inf`, (8) `copysign(S0, sign(S1) ⊕ sign(S2))`. Output modifiers `mul:2`/`mul:4`/`div:2` apply before `clamp`, and `clamp` maps NaN to `+0.0` (`DX10_CLAMP=1`) before `FClamp` to `[0, 1]`. Not modelled: `IEEE=1` sNaN quieting, `denorm32=3` keeping `S1`/`S2` subnormals, and the hardware `omod` `-0 → +0` quirk (same as the other f32 ops). Checked bit-for-bit against 73 measured `gfx1036` words in `tests/semantic/test_alu_div_fixup_f32.py`. | |
| 567 | | Atomic natural alignment, 64-bit bounds, and `buffer_atomic_{fmin,fmax}` | Measured natively on RDNA2 (AMD Radeon(TM) Graphics, `gfx1036`, Windows driver `32.0.21042.62`, wave32 and wave64 via `tools/hw_oracle/`): **natural alignment** is enforced on every 32-bit and 64-bit buffer/global atomic (`buffer_atomic*`, `buffer_atomic*_x2`, `global_atomic*`, `global_atomic*_x2`), even under `OOB_SELECT = 2` (DISABLED). A 32-bit atomic requires `(addr & 3) == 0` (`offset = 1, 2` and `base + 2, offset = 0` are dropped; `base + 2, offset = 2` succeeds) and a 64-bit `_x2` atomic requires `(addr & 7) == 0` (`offset = 2, 4` and `base + 4, offset = 0` are dropped; `base + 4, offset = 4` succeeds). When dropped (OOB or unaligned), memory is untouched, an active `glc` lane receives `0` (32-bit) or `(0, 0)` (64-bit) in `vdst`/`vdata`, and an inactive lane (`EXEC = 0`) preserves `vdst`/`vdata`. Independently confirmed on a second `gfx1036` (driver `24.10.24`): without the alignment guard, an unaligned SPIR-V `OpAtomicAdd` corrupts the aligned dword (`100 -> 0xDEADBEF3`), whereas with the guard memory stays untouched and `0` is returned. `Gen.atomic_aligned` guards all six atomic emitters on `addr & 3 == 0` / `addr & 7 == 0`, merges `0` via `OpPhi` on skipped paths, and writes through `Gen.dst` so inactive lanes keep their prior register value while active unaligned/OOB lanes receive `0`. **64-bit partial bounds (`buffer_atomic*_x2`)**: the same `gfx1036` wave32/wave64 measurements confirm the all-or-nothing 8-byte bounds rule (`fixed_fmt = 62`) across all four `OOB_SELECT` modes (answering the unmeasured note in the `buffer_atomic_{and,or,xor,swap}_x2` row): mode 3 (RAW) requires `offs + 8 <= num_records` (`0/8` and `8/16` succeed; `0/7`, `0/5`, `0/4`, `8/15`, `8/12` drop cleanly); mode 0 (STRUCTURED_WITH_OFFSET) requires `idx < num_records` and `off + 8 <= stride` (`stride = 8, off = 0`, `stride = 16, off = 8`, `stride = 12, off = 0` succeed; `stride = 7, off = 0` and `stride = 12, off = 8` drop); mode 1 (STRUCTURED) checks `idx < num_records`; mode 2 (DISABLED) checks `num_records != 0`. **`buffer_atomic_{fmin,fmax}`**: lowered via `Gen.buffer_atomic_float` sharing `Gen._emit_atomic_fminmax_cas` (relaxed Device-scope `OpAtomicLoad` seed + `OpAtomicCompareExchange` + `GLSL.std.450` `NMin`/`NMax` CAS loop, no float-atomic extension required), enforcing V# bounds, 4-byte alignment, and `glc` return (`lds` and non-1-VGPR `vdata` raise `Unsupported`). On `gfx1036`, normal floats, `±inf`, `-0` vs `+0` (`fmin(-0, +0) = -0`, `fmax(-0, +0) = +0`), and `qNaN` (returns the non-NaN operand) match `NMin`/`NMax`; **known approximation**: the `gfx1036` L2 atomic unit quiets `sNaN` (`0x7f800001 -> 0x7fc00001`) regardless of `MODE`, while f32 subnormal handling follows the wave's `MODE.denorm32` and preserves sign (independently verified on a second `gfx1036`, wave32/wave64: under `denorm32 = 0`, subnormals flush to signed zero — `fmax(0x80000001, 0x80000002) -> 0x80000000 (-0)`, `fmax(0x00000001, 0x00000002) -> +0` — whereas under `denorm32 = 3`, subnormals are preserved and `NMin`/`NMax` is exact); `NMin`/`NMax` does not model `sNaN` quieting or `denorm32 = 0` subnormal flushing. CPU-checked by `tests/semantic/test_buffer_atomic_fminmax_and_align.py` (value grid, multi-lane CAS contention, OOB/partial-bounds matrix, inactive vs active-unaligned distinction across all six atomic families, and SPIR-V structural checks). | | 571 | | Atomic natural alignment, 64-bit bounds, and `buffer_atomic_{fmin,fmax}` | Measured natively on RDNA2 (AMD Radeon(TM) Graphics, `gfx1036`, Windows driver `32.0.21042.62`, wave32 and wave64 via `tools/hw_oracle/`): **natural alignment** is enforced on every 32-bit and 64-bit buffer/global atomic (`buffer_atomic*`, `buffer_atomic*_x2`, `global_atomic*`, `global_atomic*_x2`), even under `OOB_SELECT = 2` (DISABLED). A 32-bit atomic requires `(addr & 3) == 0` (`offset = 1, 2` and `base + 2, offset = 0` are dropped; `base + 2, offset = 2` succeeds) and a 64-bit `_x2` atomic requires `(addr & 7) == 0` (`offset = 2, 4` and `base + 4, offset = 0` are dropped; `base + 4, offset = 4` succeeds). When dropped (OOB or unaligned), memory is untouched, an active `glc` lane receives `0` (32-bit) or `(0, 0)` (64-bit) in `vdst`/`vdata`, and an inactive lane (`EXEC = 0`) preserves `vdst`/`vdata`. Independently confirmed on a second `gfx1036` (driver `24.10.24`): without the alignment guard, an unaligned SPIR-V `OpAtomicAdd` corrupts the aligned dword (`100 -> 0xDEADBEF3`), whereas with the guard memory stays untouched and `0` is returned. `Gen.atomic_aligned` guards all six atomic emitters on `addr & 3 == 0` / `addr & 7 == 0`, merges `0` via `OpPhi` on skipped paths, and writes through `Gen.dst` so inactive lanes keep their prior register value while active unaligned/OOB lanes receive `0`. **64-bit partial bounds (`buffer_atomic*_x2`)**: the same `gfx1036` wave32/wave64 measurements confirm the all-or-nothing 8-byte bounds rule (`fixed_fmt = 62`) across all four `OOB_SELECT` modes (answering the unmeasured note in the `buffer_atomic_{and,or,xor,swap}_x2` row): mode 3 (RAW) requires `offs + 8 <= num_records` (`0/8` and `8/16` succeed; `0/7`, `0/5`, `0/4`, `8/15`, `8/12` drop cleanly); mode 0 (STRUCTURED_WITH_OFFSET) requires `idx < num_records` and `off + 8 <= stride` (`stride = 8, off = 0`, `stride = 16, off = 8`, `stride = 12, off = 0` succeed; `stride = 7, off = 0` and `stride = 12, off = 8` drop); mode 1 (STRUCTURED) checks `idx < num_records`; mode 2 (DISABLED) checks `num_records != 0`. **`buffer_atomic_{fmin,fmax}`**: lowered via `Gen.buffer_atomic_float` sharing `Gen._emit_atomic_fminmax_cas` (relaxed Device-scope `OpAtomicLoad` seed + `OpAtomicCompareExchange` + `GLSL.std.450` `NMin`/`NMax` CAS loop, no float-atomic extension required), enforcing V# bounds, 4-byte alignment, and `glc` return (`lds` and non-1-VGPR `vdata` raise `Unsupported`). On `gfx1036`, normal floats, `±inf`, `-0` vs `+0` (`fmin(-0, +0) = -0`, `fmax(-0, +0) = +0`), and `qNaN` (returns the non-NaN operand) match `NMin`/`NMax`; **known approximation**: the `gfx1036` L2 atomic unit quiets `sNaN` (`0x7f800001 -> 0x7fc00001`) regardless of `MODE`, while f32 subnormal handling follows the wave's `MODE.denorm32` and preserves sign (independently verified on a second `gfx1036`, wave32/wave64: under `denorm32 = 0`, subnormals flush to signed zero — `fmax(0x80000001, 0x80000002) -> 0x80000000 (-0)`, `fmax(0x00000001, 0x00000002) -> +0` — whereas under `denorm32 = 3`, subnormals are preserved and `NMin`/`NMax` is exact); `NMin`/`NMax` does not model `sNaN` quieting or `denorm32 = 0` subnormal flushing. CPU-checked by `tests/semantic/test_buffer_atomic_fminmax_and_align.py` (value grid, multi-lane CAS contention, OOB/partial-bounds matrix, inactive vs active-unaligned distinction across all six atomic families, and SPIR-V structural checks). | |
| 572 | | Absent-lane subgroup safety | Every native `OpGroupNonUniformShuffle` and `OpGroupNonUniformBroadcast` emitted by `tools/rdna2spirv.py` passes a physical lane index statically proven to name a running invocation in the current subgroup (never constant `%uint_0` or an unguarded lane, which is SPIR-V UB on partial waves and reads stale VGPR bits on RADV that can fault downstream BDA `OpConvertUToPtr` loads): (1) `wave32_first_running_lane()` falls back to `wave_lane()` instead of `0` when the half's `%true` ballot word is empty, and `subgroup_first_running_lane()` (`OpGroupNonUniformBallotFindLSB` + `OpGroupNonUniformAny(%true)` on non-VS stages and `ballot_lsb_by_words` on VS for MoltenVK compatibility, falling back to `subgroup_lane()`) supplies the `EXEC == 0` fallback for `v_readfirstlane_b32` in all non-`wave32_fragment` stages (MS, VS, GS, CS, wave64 PS); (2) `lane_masks.definite_spill_reads()` generalizes `scalar_spills()` to mixed-VGPR constant-lane `v_writelane_b32`/`v_readlane_b32` reloads dominated on all CFG paths with no intervening write to the VGPR (parking them in `%sgpr` with zero shuffles), and remaining native `v_readlane_b32` shuffles check `OpGroupNonUniformBallot(%true)` + `BallotBitExtract` and redirect absent targets to the wave's first running lane (preserving SGPR wave uniformity); (3) native `v_permlane16_b32`/`v_permlanex16_b32` (`FI=1` as well as `FI=0`) and `dpp_insn` (`fi:1` as well as `fi:0`, with out-of-row `in_bounds` clamping to `sgl` instead of `0`) redirect unlaunched/absent lanes to `subgroup_lane()` before `OpGroupNonUniformShuffle` (using bitwise masking + `Gen.eager` to preserve SHADER-529); (4) `ds_append`/`ds_consume` guards its broadcast shuffle against `EXEC == 0` and absent lanes with `subgroup_lane()`, and `ds_permute`/`ds_lane_read` always redirect absent lanes to `subgroup_lane()`; (5) `quad_any` (`s_wqm_b32`/`b64`) uses `OpGroupNonUniformBallot` + quad-nibble extraction in CS/VS/GS/MS (eliminating partial-quad `QuadSwap` and unguarded 4× shuffle UB), keeping `OpGroupNonUniformQuadSwap` only in Fragment shaders where Vulkan guarantees complete 2×2 quads. Confirmed by static SPIR-V invariant checker `tests/semantic/check_absent_lane_ub.py`, strict partial-wave CPU suite `tests/semantic/test_absent_lane_ub.py` (wave32/wave64 PS, VS, CS, MS, `s_load` after `v_readfirstlane_b32`, mixed spills, `v_permlane16`/`x16` `FI=1`, DPP `fi:1`/OOB, `s_wqm`, `ds_append`, negative controls, `spirv-val`, and all hand-written subgroup fixtures), and GPU-checked by `tests/test_absent_lane_gpu.py` on an AMD Ryzen 9 7950X3D RDNA2 iGPU (`gfx1036`, RADV, `LEONIDA_VK_VALIDATION=1`, 5-thread partial CS + 1×1 partial-quad wave32/wave64 PS: 0 faults, 0 validation errors, exact readback). | | ||
| 573 | | Coherent `glc`/`dlc` buffer and global memory | Buffer, global, and scalar memory loads/stores carrying `glc` or `dlc` emit `OpCapability VulkanMemoryModel`, `OpCapability VulkanMemoryModelDeviceScope`, `OpExtension "SPV_KHR_vulkan_memory_model"`, and `OpMemoryModel PhysicalStorageBuffer64 Vulkan`, tagging coherent loads with `Aligned\|MakePointerVisible\|NonPrivatePointer 4 %c1` (Device scope) and coherent stores with `Aligned\|MakePointerAvailable\|NonPrivatePointer 4 %c1` (and upgrading any coherent storage-image ops in the same module to `MakeTexelVisible`/`MakeTexelAvailable\|NonPrivateTexel %c1` instead of the banned `Coherent` decoration). Modules with any coherent buffer/global/scalar load emit `reads_glc_buffer: true` in `shader_meta` so the runtime inserts a cross-dispatch compute barrier. Confirmed against the SPIR-V Vulkan Memory Model spec and validated with `spirv-val --target-env vulkan1.2` + `spirv_mini_interp` in `tests/semantic/test_coherent_buffer_vmm.py`. | | ||
| 574 | | Literal S# sampler specialization | For each compile-time literal S# in `meta["literal_samplers"]` (exact sorted list order), `tools/rdna2spirv.py` declares `%lit_smp_<i> = OpSpecConstant %uint 4294967295` with `SpecId i` and emits `meta["literal_sampler_spec_base"] = 0`. At each sample/gather/get_lod site using that literal S#, `%lit_smp_<i> != 0xFFFFFFFF` selects the specialized bindless sampler index directly (bypassing the FNV-1a `%desc_lookup_fn` probe); when unspecialized (`0xFFFFFFFF`), execution falls back to `%desc_lookup_fn`. Checked with `spirv-val --target-env vulkan1.2` and both specialized and fallback path checks in `tests/semantic/test_literal_sampler_spec.py`. | | ||
| 575 | | Float-only `image_read_typed` elision and table-driven `buffer_store_format` | `Gen.image_read_typed` elides dead `uint`/`sint` runtime branches, format-mask lookups, and `%itx1`/`%itx2` descriptor aliases whenever an `image_load*` or `image_sample*` is provably float-only (every reachable consumer of its dest VGPRs is a pure f32/f16 float op with at least one float consumer, or a literal S# on `image_sample*` enables bilinear/aniso XY or linear mip filtering); `image_gather4*` and integer-consumed ops always keep all three typed branches. Dynamic `buffer_store_format_*` replaces the 77-way `OpSwitch` with a branch-free `%fmt_enc_desc_tab` lookup and shared `%fmt_enc_chan` helper. Checked for bit-for-bit parity across all 77 `Gen.FORMATS` codes (plus BGRA `0xf2e`, 2-component `DST_SEL`, `d16` signedness, and unknown codes) and `spirv-val --target-env vulkan1.2` in `tests/semantic/test_image_float_elide_and_store_table.py`. | | ||
| 576 | | Buffer-write metadata (`writes_buffer` and `buffer_write_slots`) | `tools/shader_meta.py` and `rdna2spirv.shader_meta` always emit `writes_buffer` (`true` iff the shader contains any buffer/tbuffer/global/flat/scalar buffer store or atomic; `false` for read-only, `image_store`/`image_atomic`-only, or LDS-only shaders) and `buffer_write_slots` (`[]` when `writes_buffer` is `false`, a sorted list of root user-SGPR or constant descriptor-table byte offsets when every buffer write is statically traceable, or `"dynamic"` otherwise) so the runtime can gate CPU write-back. Checked by `tests/semantic/test_writes_buffer_meta.py`. | | ||
| 568 | | `m0` and `scc`/`src_scc` lane-mask sources (`SHADER-MASK-SRC-M0-SCC`) | `Gen._maskable_b32`, `lane_masks._maskable_b32`, and `Gen.mask_src` accept `m0`, `scc`, and `src_scc` as scalar bitmask sources, extracting bit `lane & 31` (`0` for lanes `32..63` in 64-bit wave64 mask ops, zero-extending the 32-bit special register per RDNA2 ISA). This keeps `s_and/or/xor/andn2/orn2/nand/nor/xnor/not/cselect_b32` into `exec`/`vcc` on the per-lane mask path (preventing wrong `SCC` and raw non-zero words in `%vcc`) and enables `s_*_saveexec_b32`/`_b64` and `s_*_wrexec_b32`/`_b64` with `m0`/`src_scc`. CPU-checked by `tests/semantic/test_mask_src_m0_scc.py`; **not GPU-verified**. | | 577 | | `m0` and `scc`/`src_scc` lane-mask sources (`SHADER-MASK-SRC-M0-SCC`) | `Gen._maskable_b32`, `lane_masks._maskable_b32`, and `Gen.mask_src` accept `m0`, `scc`, and `src_scc` as scalar bitmask sources, extracting bit `lane & 31` (`0` for lanes `32..63` in 64-bit wave64 mask ops, zero-extending the 32-bit special register per RDNA2 ISA). This keeps `s_and/or/xor/andn2/orn2/nand/nor/xnor/not/cselect_b32` into `exec`/`vcc` on the per-lane mask path (preventing wrong `SCC` and raw non-zero words in `%vcc`) and enables `s_*_saveexec_b32`/`_b64` and `s_*_wrexec_b32`/`_b64` with `m0`/`src_scc`. CPU-checked by `tests/semantic/test_mask_src_m0_scc.py`; **not GPU-verified**. | |
| 578 | | Integer `SV_Target` exports (`UINT`/`SINT`) | When DXBC `OSG1` declares an `SV_Target` (`sysv = 64`) with component type `1` (`UINT`) or `2` (`SINT`), `output_signature_full` records its `(ctype, mask)` on `Gen.mrt_types` / `Gen.mrt_masks`. Pre-CFG (`unpatch_int_mrt_exports`, after `fold_far_branches`), Xbox's default 6-dword FP16 patch slot (`v_cvt_pkrtz_f16_f32` + `exp mrtK ... compr`, matching FSSM template #9 `SPI_SHADER_32_ABGR` on 965/965 integer targets across `dxbc` and `exe` PS) is unpatched in-place: bypassed `pkrtz` ops become `s_nop 0` keeping their original `pc`/`enc`, and `exp mrtK` drops `compr` with raw source operands masked by `OSG1.mask` (unmatched compressed integer exports raise `Unsupported`). `Gen.export` and `assemble` declare `%out_mrtN` as `%v4uint` or `%v4int` (with `%initial_mrt_u`/`%initial_mrt_i` when partial) while leaving `FLOAT` `SV_Target`s unchanged (`%v4float`). Confirmed across 965/965 corpus integer targets against FSSM template #9, Vulkan `VUID-VkGraphicsPipelineCreateInfo-renderPass-06055`, `spirv-val --target-env vulkan1.2`, and `tests/semantic/test_int_mrt_export.py`. | | ||
| 579 | | Native `s_barrier` memory semantics | Native `s_barrier` (and `bar_rounds` barriers in `bar_scheduler` / `bar_scheduler_tail`) emits `OpControlBarrier %c2 %c2 %c948` (`AcquireRelease \| UniformMemory \| WorkgroupMemory \| ImageMemory` = `0x948`, matching emulated wave64 barriers so cross-wave storage buffer and storage image writes ordered by `s_waitcnt` before `s_barrier` are visible across the workgroup). Under `VulkanMemoryModel` (`gen.uses_vmm`), `s_barrier` and `0x948` workgroup control barriers upgrade to `0x6948` (`\| MakeAvailable \| MakeVisible`) in `assemble()` so memory visibility holds even when a coherent `glc`/`dlc` access appears after `s_barrier`. Checked with `spirv-val --target-env vulkan1.2` in `tests/semantic/test_barrier_control.py`. | | ||
| 580 | | `s_mov_b64 vcc, s[a:b]` scalar pair moves | In wave32 shaders (where lane masks are 32-bit `vcc_lo` only) and whenever any instruction uses a descriptor `slist` containing `vcc_lo`/`vcc_hi`, `_translate` marks `wave32_vcc_pointer` / `vcc_scalar_pointer` so `s_mov_b64 vcc, s[a:b]` writes both 32-bit words into `%vcc` and `%vcc_hi` (rather than collapsing `%vcc` to a per-lane 1-bit mask and leaving `%vcc_hi` zero) even across basic blocks or when the source SGPRs held a lane mask elsewhere. Checked across wave32 and wave64 by `tests/semantic/test_vcc_tuple_mov64.py` and verified on all 808 corpus shaders using `[..., vcc_lo, vcc_hi]` + `s_mov_b64 vcc`. | | ||
| 581 | | Partial / non-contiguous `image_store` `dmask` RMW | When `image_store` uses a non-contiguous or upper-channel `dmask` (`dmask not in (0x0, 0x1, 0x3, 0x7, 0xf)`, e.g. `0x8`, `0x9`, `0xd`, `0x2`, `0x4`), `Gen.image_store` enables `StorageImageReadWithoutFormat` and emits `OpImageRead` + `OpVectorShuffle` + `OpImageWrite` on each typed storage view so unset channels keep their prior texel values instead of being overwritten with zero (preserving `MakeTexelVisible`/`MakeTexelAvailable` under `VulkanMemoryModel`). Contiguous low masks (`0x1`, `0x3`, `0x7`, `0xf`) stay write-only. Checked with `spirv-val --target-env vulkan1.2` in `tests/semantic/test_image_store_partial_rmw.py` and verified across all 716 corpus non-contiguous `image_store` ops. | | ||
| 582 | | 64-bit 2D `image_atomic_*` (`R64ui`, Binding 29) | 64-bit 2D image atomics (`dmask:0x3` with 2 VGPRs on `image_atomic_{swap,add,sub,smin,umin,smax,umax,and,or,xor}`, and `dmask:0xf` with 4 VGPRs on `image_atomic_cmpswap`) emit `OpCapability Int64`, `OpCapability Int64Atomics`, `OpCapability Int64ImageEXT`, `OpExtension "SPV_EXT_shader_image_int64"`, and `%simages64` at `DescriptorSet 0, Binding 29` (`OpTypeImage %ulong 2D 0 0 0 2 R64ui`, reporting `shaderImageInt64Atomics` in `shader_meta["features"]`). Operands are packed `(lo \| (hi << 32))` into `%ulong`, executed via `OpImageTexelPointer %_ptr_Image_ulong`, and unpacked back to `(lo, hi)` when `glc` is set. 32-bit `image_atomic_cmpswap` (`dmask:0x3`, 2 VGPRs) stays 32-bit on Bindings 4/7; 64-bit 3D image atomics raise `Unsupported`. Checked with `spirv-val --target-env vulkan1.2` in `tests/semantic/test_image_atomic_int64.py` and verified on all 956 corpus 64-bit `image_atomic_umax` ops. | | ||
| 583 | | Intra-workgroup `s_barrier` memory coherency (`VulkanMemoryModel`) | Under `GLSL450`, `OpControlBarrier 2 2 0x948` (`UniformMemory \| ImageMemory`) orders only `Coherent` memory, so RADV/ACO on Navi31 omits per-CU GL0 vector cache invalidation across `s_barrier`; under `VulkanMemoryModel`, plain PSB `OpLoad`/`OpStore` without `NonPrivatePointer` and plain `OpImageRead`/`OpImageWrite` without `NonPrivateTexel` are invocation-private and still unordered across CUs. When a compute/mesh shader executes `s_barrier` (or runs under `--wave64-emulate` where workgroup barriers separate emulated wave32 halves) and performs both writes and reads on PhysicalStorageBuffer (`bar_psb_coh`: plain `OpStore`/writing `OpAtomic*` + plain `OpLoad`/reading `OpAtomic*`, with at least one plain op) or storage images (`bar_img_coh`: `OpImageWrite`/`OpImageTexelPointer` + `OpImageRead`/`OpImageTexelPointer`, with at least one plain op), `assemble()` enables `VulkanMemoryModel` (`gen.uses_vmm = True` before `bar_sem`/`Coherent` decisions, without setting `reads_glc_buffer`), adds `NonPrivatePointer` to every plain PSB `OpLoad`/`OpStore` (including `%sbuf_slow_*` helpers) and `NonPrivateTexel` to every plain `OpImageRead`/`OpImageWrite`, omits the banned `Coherent` decoration, and upgrades all `0x948` workgroup control barriers to `0x6948` (`MakeAvailable \| MakeVisible`). Shaders with `s_barrier` that lack both writes and reads on PSB or storage images stay on `GLSL450`. Confirmed by RX 7900 XTX (`gfx1100`, RADV/ACO) `[1024,1,1]` wave64 multi-stage `s_barrier` hardware repros (`1024/1024` mismatches under `GLSL450` + `0x948` + `Aligned 4` -> `0/1024` with `VulkanMemoryModel` + `NonPrivatePointer` + `0x6948`), validated with `spirv-val --target-env vulkan1.3` across all 236 affected shaders in the corpus (118 `library` [115 PSB, 5 image, 2 both] + 118 `dxbc` [115 PSB, 3 image], 0 failures, < 0.9% of corpus), and checked in `tests/semantic/test_barrier_vmm_coherency.py` (`fixtures/cs_barrier_psb_coherency.asm`, `fixtures/cs_barrier_img_coherency.asm`). | | ||
| 584 | | V# descriptor `SQ_RSRC_BUF.TYPE == 0` guard | On GFX10/RDNA2 (`SQ_BUF_RSRC_WORD3`), bits `[31:30]` are `TYPE` and must be `0` (`uint32(w[3]) < 0x40000000`) for a valid buffer descriptor (V#); non-zero values identify non-buffer descriptors such as image T#s (`SQ_IMG_RSRC_WORD3[31:28]` = `8..15`, so `w[3][31:30]` is `2` or `3`, e.g. `0x90000fac`). Without a type guard, an `s_buffer_load*` or `buffer_*`/`tbuffer_*` reading a console descriptor-heap slot that holds a T# interprets T# width/height/format bits as a huge `NUM_RECORDS * stride`, bypasses bounds checks, and dereferences `heap_base + sext48(T#.w[0..1])` (unmapped VA), causing live `SQC (data)` `RW: 0` GPUVM faults on RADV. `Gen.scalar_load` (`sbuf == True`) checks `base_slots[3]`: a known literal `< 0x40000000` skips the check, a known literal `>= 0x40000000` forces `lim = 0`, and a run-time word3 emits `is_buf = OpULessThan %bool w3 0x40000000` and gates `lim = OpSelect %ulong is_buf lim 0` (clearing `lim_val` so the guarded branch always runs and `%sbuf_slow_*`/single-dword/coherent paths execute zero loads and return `0`). `Gen.buffer_address` (covering every `buffer_load*`, `buffer_store*`, `buffer_atomic*`, and `tbuffer_*` path across raw, sub-dword, `d16`, format, and swizzled forms) similarly forces `%false` when `lit3 >= 0x40000000` and ANDs `OpULessThan %bool d3 0x40000000` into `fits` when `lit3 is None`, guaranteeing zero memory dereference (loads return `0`, stores and atomics are dropped) across all four `OOB_SELECT` modes. Confirmed against the GFX10.3 `SQ_BUF_RSRC_WORD3.TYPE` specification, live RADV GPUVM fault traces, `spirv-val` (`vulkan1.2` and `vulkan1.3`), and `tests/semantic/test_vsharp_type_guard.py`. | | ||
| 585 | | Unconditional CS & MS LDS OOB bounds (`LDS_BOUNDS`, `--no-lds-bounds`) | RDNA2 LDS does not wrap: an access past the shader's declared allocation returns `0` on reads and drops writes/atomics (ISA §3.6.1, §3.6.6; Mandy `21633b328`). Previously `Gen.lds_bound` was never set on mesh shaders and only set on compute shaders when a static `offset:` exceeded `RSRC2.LDS_SIZE`, leaving 485/485 LDS compute shaders (155 non-power-of-two) and 5/5 LDS mesh shaders (all 5 non-power-of-two: 3 × 10,368 B, 2 × 3,072 B; `PSV0.GroupSharedBytesUsed` matches FSSM `record+0x4c` in 9,282/9,282 MS) wrapping dynamic OOB accesses onto low LDS slots via `OpBitwiseAnd`. Now both CS (`RSRC2.LDS_SIZE * 128`) and MS (`(PSV0.shared + 3) // 4`) set `g.lds_dwords = g.lds_bound = min(g.lds_declared, 16384)` whenever `g.lds_declared > 0` (opt-out via `--no-lds-bounds`), routing every read, write, sub-dword op, wide op, and atomic per-dword through `Gen.lds_access()`. Confirmed against RDNA2 ISA, full-corpus CS/MS LDS census (485 CS + 5 MS, 0 mismatches), `spirv-val --target-env vulkan1.2`, and `tests/semantic/test_lds_unconditional_bounds.py` (`fixtures/cs_lds_dynamic_oob.asm`, `fixtures/ms_lds_dynamic_oob.asm`). | | ||
| 586 | | PS `DB_SHADER_CONTROL` early depth (`EarlyFragmentTests`, `--no-early-depth`) | In an FSSM pixel-shader blob, payload+`0x30` (file offset `0x40`) holds the PS record offset (`0xB0` in 12,101/12,101 corpus PS); stage data begins at `E = 0x10 + rec + 0x54` and `DB_SHADER_CONTROL` is the `u32` at `E + 0x138` (`0x24C`). Bit 12 (`0x1000`, `DEPTH_BEFORE_SHADER`, HLSL `[earlydepthstencil]`) is set in 3,023/12,101 corpus PS (`0x1050`: 1,718, `0x1450`: 705, `0x1010`: 380, `0x1410`: 220; 925 write UAVs, 0 export depth/stencil; matches Mandy `f33940415`/`bf479a3cd`). `fssm_header.db_shader_control()` reads this word and `assemble()` emits `OpExecutionMode %main EarlyFragmentTests` (recorded as `"early_depth": true` in `shader_meta`) whenever bit 12 is set and the PS does not export depth or stencil (`DB_SHADER_CONTROL & 0x7 == 0`, no `exp mrtz` / `DepthReplacing`, and no OSG1 `SV_Depth*`/`SV_StencilRef`; opt-out via `--no-early-depth`). Runtime SPIR-V patchers handle `EarlyFragmentTests` cleanly: `sample_mask_fragment.h` strips `EarlyFragmentTests` when injecting sample masks, while `depth24_fragment.h` intentionally rejects shaders with `EarlyFragmentTests` so the device falls back to unpatched float depth and preserves early-Z semantics. Confirmed by full 12,101-PS corpus census, `spirv-val --target-env vulkan1.2`, and `tests/semantic/test_ps_early_depth.py` (`fixtures/ps_early_depth.asm`, `fixtures/ps_early_depth_mrtz.asm`). | | ||
| 587 | | Defensive mesh epilogue & PS helper-lane quad swizzle | (1) In both `MeshEXT` and `--mesh-compute` epilogues, when `%mli < %msp` and `!%ms_has_prim`, an explicit `else` branch writes `CullPrimitiveEXT = true` (or `1` in `--mesh-compute`) and `(0, 0, 0)` to `%ms_prim_idx[%mli]` so unemitted primitive slots are never left uninitialized (checked in `tests/semantic/test_ms_prim_export.py`). (2) Quad-local `ds_swizzle_b32` in pixel shaders (`QUAD_PERM`, `SWAP` 1–3, `REVERSE` 2/4, `BROADCAST` 2/4, and quad-local `BITMASK_PERM` — covering 101,421/101,421 `ds_swizzle` ops across all 6,141 swizzling corpus PS) lowers through `Gen.ds_quad_swizzle()` using `OpGroupNonUniformQuadBroadcast` / `OpGroupNonUniformQuadSwap` (`OpCapability GroupNonUniformQuad`) instead of `OpGroupNonUniformBallot` + `OpGroupNonUniformShuffle`, so Vulkan 2×2 helper invocations participate on AMD RADV while inactive-in-EXEC lanes still read as `0` and keep their destination. Confirmed by full 12,101-PS corpus census, `spirv-val --target-env vulkan1.2`, and `tests/semantic/test_ps_quad_swizzle.py`. | | ||
| 569 | 588 | ||
| 570 | ### System values confirmed on the corpus (SHADER-4) | 589 | ### System values confirmed on the corpus (SHADER-4) |
| 571 | 590 | ||
diff --git a/docs/directstorage.md b/docs/directstorage.md index d6272e588..10b9390cb 100644 --- a/docs/directstorage.md +++ b/docs/directstorage.md | |||
| @@ -273,16 +273,18 @@ shim beyond the size check it already does. The last one is behaviour the first | |||
| 273 | 256 blocks of a stream. It combines adjacent mips from the same layer with full-stream index anchor | 273 | 256 blocks of a stream. It combines adjacent mips from the same layer with full-stream index anchor |
| 274 | and shared-p-bit constraints. A shared p-bit can relate low red endpoint bits even when its sibling | 274 | and shared-p-bit constraints. A shared p-bit can relate low red endpoint bits even when its sibling |
| 275 | mip supplies only the leading bits. These local fits preserve the recorded precision and exact reference | 275 | mip supplies only the leading bits. These local fits preserve the recorded precision and exact reference |
| 276 | bits. A packed tail whose larger mips are BCPack-coded too has no raw or zlib sibling, so a history field that | 276 | bits. A packed tail whose larger mips are BCPack-coded too has no adjacent raw or zlib sibling, so a history |
| 277 | only such tails use stayed unknown: in the game runs of 2026-11-25 two BC7 tail streams of one pool failed | 277 | field that only such tails use stayed unknown: in the game runs of 2026-11-25 two BC7 tail streams of one pool |
| 278 | with `missing-endpoint` (alpha fields of two history entries). For the streams that still start a chain at a | 278 | failed with `missing-endpoint` (alpha fields of two history entries). For streams that still start a chain at a |
| 279 | missing field, the fitter now decodes the nearest BCPack sibling with the profile so far and fits against it, | 279 | missing field after adjacent-mip fitting, the fitter first pairs their mips with the closest raw or zlib mip on |
| 280 | repeating while a round adds fields. The sibling may sit in the same refused BC7 stream: every block whose | 280 | the same layer across multi-level mip distances, then decodes the nearest BCPack sibling with the profile so far |
| 281 | chains start elsewhere is still determined, and the undetermined ones are left out of the reference. Those | 281 | and fits against it, repeating while a round adds fields. The sibling may sit in the same refused BC7 stream: |
| 282 | fields are fitted, never confirmed, and fill only what the other fits left empty. On the 1.0.2.1 package this | 282 | every block whose chains start elsewhere is still determined, and the undetermined ones are left out of the |
| 283 | raised the BC7 endpoint fields from 4,228 to 4,406 of 6,144; the runtime decoder then refuses 8 of 5,167 BC7 | 283 | reference. Those fields are fitted, never confirmed, and fill only what the earlier fits left empty. On the |
| 284 | streams instead of 60 (both failing requests decode), and the 268 BC6H streams are unchanged (10 refused; a | 284 | 1.0.2.1 package this raised BC6H coverage from 210 to 226 of 256 endpoint rows and 249 to 251 of 256 index rows |
| 285 | 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. | 285 | (0 of 268 BC6H streams refused instead of 10) and raised BC7 endpoint fields from 4,228 to 4,406 of 6,144 (8 of |
| 286 | 5,167 BC7 streams refused instead of 60; both failing requests decode). A profile can still lack endpoint values | ||
| 287 | or exceed the reference consistency tolerance. Such a request reports a decompression error before publication. | ||
| 286 | - The four swizzle modes interleave stripes from request-wide component planes into 16 KiB (mode 1) or | 288 | - The four swizzle modes interleave stripes from request-wide component planes into 16 KiB (mode 1) or |
| 287 | 32 KiB (modes 2–4) groups. The enum names give the successive stripe widths. The shipped BC4 sample | 289 | 32 KiB (modes 2–4) groups. The enum names give the successive stripe widths. The shipped BC4 sample |
| 288 | separates its endpoint planes from indices across the inflated source. The title's compute shader does | 290 | separates its endpoint planes from indices across the inflated source. The title's compute shader does |
diff --git a/docs/fspx.md b/docs/fspx.md index fad6b166b..bb6bc16f2 100644 --- a/docs/fspx.md +++ b/docs/fspx.md | |||
| @@ -297,8 +297,8 @@ title calls device slot 57 (`+0x1c8`) with `IID_ID3D12PipelineState` (`{765a30f3 | |||
| 297 | - `state blob`: `+0x000` version tag (`0x4005d800` in 15,632 records, `0x4005d808` in 9,159, `0x4005d810` in 6), | 297 | - `state blob`: `+0x000` version tag (`0x4005d800` in 15,632 records, `0x4005d808` in 9,159, `0x4005d810` in 6), |
| 298 | `+0x004` family (`4` in 12,735 or `6` in 12,062), `+0x02c = 2`, `+0x07c` (`0xcc0010` / `0` / `0xcc0011`), | 298 | `+0x004` family (`4` in 12,735 or `6` in 12,062), `+0x02c = 2`, `+0x07c` (`0xcc0010` / `0` / `0xcc0011`), |
| 299 | `+0x0f4 = 5`, `+0x0f8 = 1`, `+0x0fc = 0x33333333` (`0.1f`), `+0x100..+0x11c` (`0x00060006` x8), `+0x150 = 0x40`, | 299 | `+0x0f4 = 5`, `+0x0f8 = 1`, `+0x0fc = 0x33333333` (`0.1f`), `+0x100..+0x11c` (`0x00060006` x8), `+0x150 = 0x40`, |
| 300 | `+0x158 = 0xffffffff`, `+0x17c = 0x10000a00`. The colour-target, depth, stencil and raster registers are decoded | 300 | `+0x158 = 0xffffffff`, `+0x17c = 0x10000a00`. The colour-target, depth, stencil, raster and depth-bias registers |
| 301 | (next paragraphs); depth bias is not. | 301 | are decoded (next paragraphs). |
| 302 | - `stage blob`: `+0x00 = 2` (graphics stage blob), `+0x04` payload size (`196` in 208 B blobs), `+0x08 = 0x66`, | 302 | - `stage blob`: `+0x00 = 2` (graphics stage blob), `+0x04` payload size (`196` in 208 B blobs), `+0x08 = 0x66`, |
| 303 | `+0x0c = 0x40 | flags`, followed by records `0x41` (32 B input/output signature), `0x42` (32 B output signature) | 303 | `+0x0c = 0x40 | flags`, followed by records `0x41` (32 B input/output signature), `0x42` (32 B output signature) |
| 304 | and `0x43` (20 B: tag + 16 B opaque digest). | 304 | and `0x43` (20 B: tag + 16 B opaque digest). |
| @@ -310,11 +310,18 @@ headers). Measured on 1.0.2.1 over all 5,680 distinct blobs, which the 25,471 gr | |||
| 310 | - **Shape:** 380 + 8k bytes (k = 0..5) for vertex-shader pipelines, and 464 + 8k (k = 0..7) for mesh pipelines. The | 310 | - **Shape:** 380 + 8k bytes (k = 0..5) for vertex-shader pipelines, and 464 + 8k (k = 0..7) for mesh pipelines. The |
| 311 | mesh pipelines' stage block is 84 bytes longer, so every offset after `+0x28` moves by 84 there; the offsets below | 311 | mesh pipelines' stage block is 84 bytes longer, so every offset after `+0x28` moves by 84 there; the offsets below |
| 312 | are the vertex ones. Word 0 is `0x4005d800` with bits 3 and 4 free in all 25,471 records. | 312 | are the vertex ones. Word 0 is `0x4005d800` with bits 3 and 4 free in all 25,471 records. |
| 313 | - **`+0x78` `CB_TARGET_MASK`:** four component bits (R, G, B, A, as in `D3D12_COLOR_WRITE_ENABLE`) per target: | 313 | - **`+0x78` `CB_SHADER_MASK`:** pixel-shader export mask, four component bits (R, G, B, A) per target: |
| 314 | `0xf` in 16,650 records, `0xff` in 2,805, `0xffffff` in 2,561. In 17,626 records the targets it enables are exactly | 314 | `0xf` in 16,650 records, `0xff` in 2,805, `0xffffff` in 2,561. In 1,937 one-target pipelines it also enables target 1: |
| 315 | `0..rt_count-1` of blob B. In 1,937 it also enables target 1 of a one-target pipeline: those are the dual-source | 315 | those are the dual-source pipelines below. |
| 316 | pipelines below. The others leave a target with a format unwritten. | 316 | - **`+0x7c` `CB_COLOR_CONTROL`:** ROP3 `0xcc` (copy) in every record, so no logic op. `MODE` (bits `[6:4]`) is `0` |
| 317 | - **`+0x7c` `CB_COLOR_CONTROL`:** ROP3 `0xcc` (copy) in every record, so no logic op. | 317 | (`CB_DISABLE`, no colour writes) in 4 records with `rt_count > 0` (all 4 also have `CB_TARGET_MASK == 0`) and |
| 318 | `CB_NORMAL` (`1`) otherwise. | ||
| 319 | - **`+0xcc` `CB_TARGET_MASK`:** actual D3D12 `RenderTargetWriteMask`, four component bits (R, G, B, A, as in | ||
| 320 | `D3D12_COLOR_WRITE_ENABLE`) per target. Across all 25,471 records: 4,553 records with `rt_count > 0` mask off every | ||
| 321 | render-target channel (`+0xcc & rt_mask == 0`, e.g. occlusion/depth-pass queries), and 5,444 more apply partial | ||
| 322 | per-channel or per-target masks (9,997 records total where `CB_TARGET_MASK` narrows `CB_SHADER_MASK`). In all 1,937 | ||
| 323 | dual-source pipelines (`rt_count = 1`), `+0x78` is `0xff` while `+0xcc` is `0xf` (1,936) or `0x7` (1). The effective | ||
| 324 | per-target write mask is `0` when `CB_COLOR_CONTROL.MODE == 0`, otherwise `CB_SHADER_MASK & CB_TARGET_MASK`. | ||
| 318 | - **`+0xd0..+0xec` `CB_BLEND0..7_CONTROL`:** one word per target. There are 34 distinct values, every one an | 325 | - **`+0xd0..+0xec` `CB_BLEND0..7_CONTROL`:** one word per target. There are 34 distinct values, every one an |
| 319 | in-range RDNA2 blend: factors 0 to 20 with neither `BOTH_*` value, `COMB_FCN` 0 to 4, `SEPARATE_ALPHA_BLEND` set | 326 | in-range RDNA2 blend: factors 0 to 20 with neither `BOTH_*` value, `COMB_FCN` 0 to 4, `SEPARATE_ALPHA_BLEND` set |
| 320 | wherever `ENABLE` is, and `DISABLE_ROP3` set in all. By target 0: `0x80000000` (blending off) in 15,373 records, | 327 | wherever `ENABLE` is, and `DISABLE_ROP3` set in all. By target 0: `0x80000000` (blending off) in 15,373 records, |
| @@ -325,8 +332,9 @@ headers). Measured on 1.0.2.1 over all 5,680 distinct blobs, which the 25,471 gr | |||
| 325 | They fit `SX_MRTn_BLEND_OPT`, whose `COMB_FCN` 6 is "blend disabled". They aren't read. | 332 | They fit `SX_MRTn_BLEND_OPT`, whose `COMB_FCN` 6 is "blend disabled". They aren't read. |
| 326 | 333 | ||
| 327 | `runtime/src/native_pso.h` (`decode_state_a_blend`, `d3d12_blend`) maps each target's `CB_BLENDn_CONTROL` and | 334 | `runtime/src/native_pso.h` (`decode_state_a_blend`, `d3d12_blend`) maps each target's `CB_BLENDn_CONTROL` and |
| 328 | `CB_TARGET_MASK` nibble to a `D3D12_RENDER_TARGET_BLEND_DESC`, and `fill_blend_state` in | 335 | effective write-mask nibble (`CB_SHADER_MASK & CB_TARGET_MASK`, zeroed when `CB_COLOR_CONTROL.MODE == 0`) to a |
| 329 | `runtime/shims/d3d12_xs_native_pso.h` uses it for every native PSO: | 336 | `D3D12_RENDER_TARGET_BLEND_DESC`, and `fill_blend_state` in `runtime/shims/d3d12_xs_native_pso.h` uses it for every |
| 337 | native PSO: | ||
| 330 | 338 | ||
| 331 | - **Before:** every target had blending off and wrote every component, so the first-run pages after #939 drew glyph | 339 | - **Before:** every target had blending off and wrote every component, so the first-run pages after #939 drew glyph |
| 332 | quads solid, artwork hard-edged and composited backgrounds black. | 340 | quads solid, artwork hard-edged and composited backgrounds black. |
| @@ -355,8 +363,14 @@ measured over all 25,471 graphics records: | |||
| 355 | - **`+0x9c` `PA_CL_CLIP_CNTL`:** `DX_CLIP_SPACE_DEF` set in every record. Both z clips are off in 960 records and on | 363 | - **`+0x9c` `PA_CL_CLIP_CNTL`:** `DX_CLIP_SPACE_DEF` set in every record. Both z clips are off in 960 records and on |
| 356 | in the rest, so the near and far planes always agree. | 364 | in the rest, so the near and far planes always agree. |
| 357 | - **`+0xa0` `PA_SU_SC_MODE_CNTL`:** no culling in 13,534 records, back faces in 11,873 and front faces in 62. | 365 | - **`+0xa0` `PA_SU_SC_MODE_CNTL`:** no culling in 13,534 records, back faces in 11,873 and front faces in 62. |
| 358 | `FACE` (clockwise is front) is clear in all but 2, `POLY_MODE` is 0 in all, and the polygon-offset enables are set | 366 | `FACE` (clockwise is front) is clear in all but 2, `POLY_MODE` is 0 in all, and `POLY_OFFSET_FRONT_ENABLE` / |
| 359 | in all. | 367 | `POLY_OFFSET_BACK_ENABLE` (bits 11–12) are set in all. |
| 368 | - **`+0xac` `PA_SU_POLY_OFFSET_CLAMP`:** IEEE-754 float `DepthBiasClamp`, nonzero in 851 records (`0.003`, `0.00225`, | ||
| 369 | `0.00375`; all `D16_UNORM` depth targets). | ||
| 370 | - **`+0xb0` `PA_SU_POLY_OFFSET_FRONT_SCALE`:** IEEE-754 float `16.0f * SlopeScaledDepthBias`, nonzero in 1,484 records | ||
| 371 | (`29.0`, `16.0`, `33.35`, `36.25`, `40.0`, `3.2`; divided by `16.0f` for D3D12 `SlopeScaledDepthBias`). | ||
| 372 | - **`+0xb4` `PA_SU_POLY_OFFSET_FRONT_OFFSET`:** IEEE-754 float `DepthBias` (integer ULP offset), nonzero in 631 records | ||
| 373 | (`1.0`, `5.0`; all `D32*` depth targets). | ||
| 360 | - **`+0xb8` `DB_DEPTH_CONTROL`:** | 374 | - **`+0xb8` `DB_DEPTH_CONTROL`:** |
| 361 | - with no DSV in blob B, `Z_ENABLE` is clear in 7,040 of 7,079 records; | 375 | - with no DSV in blob B, `Z_ENABLE` is clear in 7,040 of 7,079 records; |
| 362 | - `STENCIL_ENABLE` is set only with formats that have stencil; | 376 | - `STENCIL_ENABLE` is set only with formats that have stencil; |
| @@ -371,15 +385,16 @@ measured over all 25,471 graphics records: | |||
| 371 | back, so the reference always comes from the title (`OMSetStencilRef`) and the PSO does not need it. 245 records use a back-face function of their own. | 385 | back, so the reference always comes from the title (`OMSetStencilRef`) and the PSO does not need it. 245 records use a back-face function of their own. |
| 372 | 386 | ||
| 373 | `runtime/src/native_pso.h` (`decode_state_a_depth_raster`, `d3d12_depth_raster`) maps them to | 387 | `runtime/src/native_pso.h` (`decode_state_a_depth_raster`, `d3d12_depth_raster`) maps them to |
| 374 | `D3D12_DEPTH_STENCIL_DESC` and the cull, front-face and depth-clip fields of `D3D12_RASTERIZER_DESC`, and | 388 | `D3D12_DEPTH_STENCIL_DESC` and the cull, front-face, depth-clip and depth-bias fields of `D3D12_RASTERIZER_DESC`, and |
| 375 | `fill_depth_raster_state` in `runtime/shims/d3d12_xs_native_pso.h` uses them for every native PSO: | 389 | `fill_depth_raster_state` in `runtime/shims/d3d12_xs_native_pso.h` uses them for every native PSO: |
| 376 | 390 | ||
| 377 | - **Before:** depth `ALWAYS` with writes wherever there was a DSV, no stencil, no culling and depth clip on. | 391 | - **Before:** depth `ALWAYS` with writes wherever there was a DSV, no stencil, no culling and depth clip on. |
| 378 | - **With the decoded state:** every one of the 25,471 records maps. A pipeline without a DSV keeps depth and stencil | 392 | - **With the decoded state:** every one of the 25,471 records maps. A pipeline without a DSV keeps depth and stencil |
| 379 | off. | 393 | off. |
| 380 | - **Not decoded:** depth bias (`PA_SU_POLY_OFFSET_*`). Its D3D12 units depend on the depth format, so it stays 0. | 394 | - **Depth bias:** decoded from `+0xac` (`DepthBiasClamp`), `+0xb0` (`SlopeScaledDepthBias = scale / 16.0f`) and `+0xb4` |
| 381 | The polygon-offset enables in `PA_SU_SC_MODE_CNTL` are set in all 25,471 records. The values look like the floats at | 395 | (`DepthBias`), gated on `PA_SU_SC_MODE_CNTL` bits 11–12 (`POLY_OFFSET_FRONT_ENABLE` / `POLY_OFFSET_BACK_ENABLE`, both |
| 382 | `+0xac`/`+0xb0` (scale and offset), which are both 0 in 23,987 records and nonzero in about 1,480. | 396 | set in all 25,471 records). Non-finite floats or an offset outside `int32_t` range reject the depth/raster state so the |
| 397 | pipeline keeps its defaults. | ||
| 383 | - **Front face:** `FACE` is the only field whose effect can't be seen before a world frame. It maps to | 398 | - **Front face:** `FACE` is the only field whose effect can't be seen before a world frame. It maps to |
| 384 | `FrontCounterClockwise = !FACE`, as RADV and PAL program it. | 399 | `FrontCounterClockwise = !FACE`, as RADV and PAL program it. |
| 385 | 400 | ||
diff --git a/docs/gameinput.md b/docs/gameinput.md index fe1259cc4..1819f0543 100644 --- a/docs/gameinput.md +++ b/docs/gameinput.md | |||
| @@ -643,8 +643,10 @@ holds stays valid after it leaves the history. | |||
| 643 | | nothing newer, or nothing older after the horizon | `GAMEINPUT_E_READING_NOT_FOUND` | | 643 | | nothing newer, or nothing older after the horizon | `GAMEINPUT_E_READING_NOT_FOUND` | |
| 644 | 644 | ||
| 645 | After a pad is plugged back in, its last reading before the unplug leads to the reconnect snapshot, older ones are | 645 | After a pad is plugged back in, its last reading before the unplug leads to the reconnect snapshot, older ones are |
| 646 | `REFERENCE_READING_TOO_OLD`, and sequence numbers carry on. Timestamps are poll times, so a change shorter than one poll | 646 | `REFERENCE_READING_TOO_OLD`, and sequence numbers carry on. Each poll drains SDL's gamepad button and axis events. |
| 647 | (2 ms with the thread) is not seen. | 647 | For each connected pad, events with the same SDL timestamp form one sample. Intermediate samples reach the history |
| 648 | and reading or Guide callbacks, while the final reading uses the current pad snapshot. GameInput timestamps still | ||
| 649 | record when the shim polled. A short press is recoverable when the SDL backend reports its two edges with distinct timestamps. | ||
| 648 | 650 | ||
| 649 | ### Device identity | 651 | ### Device identity |
| 650 | 652 | ||
| @@ -704,8 +706,8 @@ rests on a transcription rather than on a side-by-side compile. | |||
| 704 | - `gameinput_test` (CTest, no controller): turns SDL's real backends off and drives the shim through | 706 | - `gameinput_test` (CTest, no controller): turns SDL's real backends off and drives the shim through |
| 705 | `rt::shims::find` with SDL virtual joysticks, an Xbox-style pad with trigger motors, a DualSense (Sony | 707 | `rt::shims::find` with SDL virtual joysticks, an Xbox-style pad with trigger motors, a DualSense (Sony |
| 706 | `054c:0ce6`) and a pad without trigger motors. It checks enumeration and device callbacks, the button, stick, | 708 | `054c:0ce6`) and a pad without trigger motors. It checks enumeration and device callbacks, the button, stick, |
| 707 | trigger and UI-navigation mapping, reading callbacks and sequence numbers, the reading history (a tap read after | 709 | trigger and UI-navigation mapping, reading callbacks and sequence numbers, the reading history (a button and trigger |
| 708 | the fact, both directions, two pads interleaved and filtered by device, ageing out, held readings, unplug and | 710 | tapped between two shim polls, both directions, two pads interleaved and filtered by device, ageing out, held readings, unplug and |
| 709 | replug), the guide button, motor and trigger | 711 | replug), the guide button, motor and trigger |
| 710 | rumble as SDL receives them, the DualSense effect bytes in each `LEONIDA_DS_TRIGGERS` mode, the lightbar, a | 712 | rumble as SDL receives them, the DualSense effect bytes in each `LEONIDA_DS_TRIGGERS` mode, the lightbar, a |
| 711 | dispatcher and its quota, async and blocking enumeration, unregistering, unplugging and replugging, and three identical pads | 713 | dispatcher and its quota, async and blocking enumeration, unregistering, unplugging and replugging, and three identical pads |
| @@ -755,7 +757,7 @@ These need the game executable or a test on hardware: | |||
| 755 | built against one of those, the vtables need a second set. | 757 | built against one of those, the vtables need a second set. |
| 756 | - **IIDs.** `QueryInterface` answers the v0 IIDs from the public header. | 758 | - **IIDs.** `QueryInterface` answers the v0 IIDs from the public header. |
| 757 | - **Reading history.** Microsoft's [next reading](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/input/gameinput/interfaces/igameinput/methods/igameinput_getnextreading) | 759 | - **Reading history.** Microsoft's [next reading](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/input/gameinput/interfaces/igameinput/methods/igameinput_getnextreading) |
| 758 | and [previous reading](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/input/gameinput/interfaces/igameinput/methods/igameinput_getpreviousreading) pages describe half a second of readings per device and failure when old readings leave the stream. The table above records the shim's HRESULT choices. Changes faster than the poll are not seen. | 760 | and [previous reading](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/input/gameinput/interfaces/igameinput/methods/igameinput_getpreviousreading) pages describe half a second of readings per device and failure when old readings leave the stream. The table above records the shim's HRESULT choices. |
| 759 | `GetTemporalReading` returns `E_NOTIMPL` with a null reading on purpose: Microsoft's | 761 | `GetTemporalReading` returns `E_NOTIMPL` with a null reading on purpose: Microsoft's |
| 760 | [reference page](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/input/gameinput/deprecated/interfaces/igameinput/methods/igameinput_gettemporalreading) | 762 | [reference page](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/input/gameinput/deprecated/interfaces/igameinput/methods/igameinput_gettemporalreading) |
| 761 | says it "was never implemented in v0" and returns `E_NOTIMPL`, and v1 removed it. The v0 header (NuGet | 763 | says it "was never implemented in v0" and returns `E_NOTIMPL`, and v1 removed it. The v0 header (NuGet |
diff --git a/docs/gdk_public_reference.md b/docs/gdk_public_reference.md new file mode 100644 index 000000000..3aa9d9aa5 --- /dev/null +++ b/docs/gdk_public_reference.md | |||
| @@ -0,0 +1,101 @@ | |||
| 1 | # Using the public GDK to write shims | ||
| 2 | |||
| 3 | How to use Microsoft's **public** GDK documentation and headers to implement the console APIs the game imports, | ||
| 4 | without copying Microsoft's files and without touching anything under NDA. A convention for contributors; only the | ||
| 5 | table of public pages is a measurement. | ||
| 6 | |||
| 7 | ## The rule in one line | ||
| 8 | |||
| 9 | Read the public PC GDK reference and headers, then write in your own words only what a shim needs: names, values, | ||
| 10 | signatures and struct layouts. Never commit GDK files, and never use the console GDK, which is under NDA. | ||
| 11 | |||
| 12 | ## What the public GDK gives the project | ||
| 13 | |||
| 14 | - Signatures, enums and structs of the system APIs the game imports: XGameRuntime, XTaskQueue, XUser, XStore, | ||
| 15 | XGameSave and GameInput. | ||
| 16 | - That is what these already implement, and they are the models to follow: | ||
| 17 | - `runtime/shims/xgameruntime.cpp`, `xgameruntime_user.cpp`, `xgameruntime_store.cpp`, | ||
| 18 | `xgameruntime_gamesave.cpp`, `xgameruntime_offline.cpp` | ||
| 19 | - `d3d12/crates/leonida-hle/src/modules/xgameruntime.rs` | ||
| 20 | - `runtime/shims/gameinput*` (see [gameinput.md](gameinput.md)) | ||
| 21 | |||
| 22 | ## What it does not give | ||
| 23 | |||
| 24 | - The console-only graphics surface: `D3D12XboxCreateDevice`, `PresentX`, XDXR and the rest of `d3d12_xs` beyond | ||
| 25 | what the public pages list. [d3d12_xs_surface.md](d3d12_xs_surface.md) and [xbox_d3d12_xs.md](xbox_d3d12_xs.md) | ||
| 26 | say which pages exist and which are missing or NDA-gated. | ||
| 27 | - Those layouts are recovered from the game's own call sites and from public code compiled against the headers | ||
| 28 | (Mesa, ebiten, the Microsoft samples), as [d3d12_vulkan.md](d3d12_vulkan.md) does. They are not guessed, and | ||
| 29 | they are not taken from leaked or NDA material. | ||
| 30 | |||
| 31 | ## The method, in 4 steps | ||
| 32 | |||
| 33 | 1. **Get the public references.** The system API reference at | ||
| 34 | [docs.xbox.com](https://docs.xbox.com/reference/system/xgamestreaming/functions/xgamestreamingsetresolution) | ||
| 35 | (pages under `reference/system/<family>/functions/<name>`), the graphics reference at | ||
| 36 | [devdocs.xbox.com](https://devdocs.xbox.com/reference/graphics/d3d12), and the public PC GDK headers from | ||
| 37 | Microsoft's own download. GameInput is also published as the `Microsoft.GameInput` NuGet package. | ||
| 38 | 2. **List what the game imports**, locally, on your own copy (`dumpbin /imports`). The measured tables are already | ||
| 39 | in [runtime_imports.md](runtime_imports.md), and `tests/test_gdk_runtime_calls.py` checks them. Nothing from the | ||
| 40 | game goes into the repository. | ||
| 41 | 3. **For each missing function**, read its public page and header, then write the declaration and the shim yourself, | ||
| 42 | with a test: `runtime/test/xgameruntime_*_test.cpp` for the C++ runtime, with | ||
| 43 | `runtime/test/fixtures/tiny_gdk_load.cpp` as the model for loading a GDK-style module. | ||
| 44 | 4. **Document it** in [runtime_imports.md](runtime_imports.md), linking the public page you used. Then the usual | ||
| 45 | path: claim it in the coordination issue, open a pull request with a test that fails on `main` and passes with | ||
| 46 | it ([CONTRIBUTING.md](../CONTRIBUTING.md)). | ||
| 47 | |||
| 48 | ## Public pages by family | ||
| 49 | |||
| 50 | MEASURED on 2026-11-29 from a Mac, by HTTP only; the page contents were not read. Each GDK name in | ||
| 51 | [runtime_imports.md](runtime_imports.md) (the names in backticks, not the whole import table) was looked up in two | ||
| 52 | places: the public index at `https://docs.xbox.com/_llms/en/apis/gdk-apis/system-api-reference.txt` (and its XStore | ||
| 53 | part), then directly at `https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/<area>/<family>/<kind>/<name>` | ||
| 54 | (kinds `functions`, `structs`, `enums`, `handles`). A name counts as found when the page answers 200 with that name in | ||
| 55 | its title. The index is incomplete: it leaves out most of XMem and all of XNetworking, whose pages do exist on | ||
| 56 | Microsoft Learn. | ||
| 57 | |||
| 58 | | Family | Contents page | Found | Not found | | ||
| 59 | |---|---|---|---| | ||
| 60 | | XAccessibility | [xaccessibility](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xaccessibility/xaccessibility_members) | 2 | | | ||
| 61 | | XAppCapture | [xappcapture](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xappcapture/xappcapture_members) | 1 | | | ||
| 62 | | XAsync | [xasync](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xasync/xasync_members) | 2 | | | ||
| 63 | | XAsyncProvider | [xasyncprovider](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xasyncprovider/xasyncprovider_members) | 3 | `XAsyncBeginAlloc` | | ||
| 64 | | XDisplay | [xdisplay](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xdisplay/xdisplay_members) | 3 | | | ||
| 65 | | XError | [xerror](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xerror/xerror_members) | 1 | `XErrorReport` | | ||
| 66 | | XGame | [xgame](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xgame/xgame_members) | 3 | | | ||
| 67 | | XGameEvent | [xgameevent](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xgameevent/xgameevent_members) | 1 | | | ||
| 68 | | XGameRuntimeFeature | [xgameruntimefeature](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xgameruntimefeature/xgameruntimefeature_members) | 1 | | | ||
| 69 | | XGameRuntimeInit | [xgameruntimeinit](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xgameruntimeinit/xgameruntimeinit_members) | 1 | | | ||
| 70 | | XGameSave | [xgamesave](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xgamesave/xgamesave_members) | 5 | | | ||
| 71 | | XGameSaveFiles | [xgamesavefiles](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xgamesavefiles/xgamesavefiles_members) | family page only | | | ||
| 72 | | XGameStreaming | [xgamestreaming](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xgamestreaming/xgamestreaming_members) | 3 | | | ||
| 73 | | XGameUI | [xgameui](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xgameui/xgameui_members) | 1 | | | ||
| 74 | | XLauncher | [xlauncher](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xlauncher/xlauncher_members) | 1 | | | ||
| 75 | | XMem | [xmem](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xmem/xmem_members) | 13 | | | ||
| 76 | | XNetworking | [xnetworking](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/networking/xnetworking/xnetworking_members) | 2 | | | ||
| 77 | | XPackage | [xpackage](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xpackage/xpackage_members) | 2 | | | ||
| 78 | | XPersistentLocalStorage | [xpersistentlocalstorage](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xpersistentlocalstorage/xpersistentlocalstorage_members) | 2 | | | ||
| 79 | | XSpeechSynthesizer | [xspeechsynthesizer](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xspeechsynthesizer/xspeechsynthesizer_members) | 2 | | | ||
| 80 | | XStore | [xstore](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xstore/xstore_members) | 4 | `XStoreIsAvailabilityPurchasable` | | ||
| 81 | | XSystem | [xsystem](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xsystem/xsystem_members) | 7 | | | ||
| 82 | | XTaskQueue | [xtaskqueue](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xtaskqueue/xtaskqueue_members) | 4 | `XTaskQueueIsEmpty` | | ||
| 83 | | XThread | [xthread](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xthread/xthread_members) | 2 | | | ||
| 84 | | XUser | [xuser](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xuser/xuser_members) | 11 | `XUserHandle` | | ||
| 85 | | XApu (console audio) | none found | 0 | `XApuConnect`, `XApuDequeueResult`, `XApuDisconnect`, `XApuEnqueueCommand`, `XApuGetResultCount` | | ||
| 86 | | XDsp (console audio) | none found | 0 | `XDspActivate`, `XDspConnectWithMaximumStreamLimit`, `XDspDeactivate`, `XDspDisconnect`, `XDspSubmitCommand` | | ||
| 87 | | XG (console graphics) | none found | 0 | `XGCreateTextureComputer`, `XGSuggestSwizzleMode` | | ||
| 88 | |||
| 89 | "Not found" means no page at the index or at the usual paths on that date; the five names in the upper rows may | ||
| 90 | still be documented under another path or name. For the last three rows no public page was found at all: treat | ||
| 91 | them like `d3d12_xs` above and recover what a shim needs from the game's call sites. | ||
| 92 | |||
| 93 | ## Lines not to cross | ||
| 94 | |||
| 95 | - **Do not copy GDK headers, samples or documentation text into the repository.** They are under Microsoft's | ||
| 96 | licence. Take the facts (names, values, layouts), not the text. | ||
| 97 | - **Nothing from the console GDK or from a leak**, not even to check a value. If a layout is only in NDA material, | ||
| 98 | write down that it is open and recover it from call sites instead. | ||
| 99 | - **The repository's hard rules still apply** ([AGENTS.md](../AGENTS.md)): no keys, no decryption, no protection | ||
| 100 | workarounds, and nothing online. The shims answer offline (`runtime/shims/xgameruntime_offline.cpp`); no Xbox Live | ||
| 101 | or Rockstar services. | ||
diff --git a/docs/i18n/ar/quickstart.md b/docs/i18n/ar/quickstart.md index d28d5fc70..970da67c2 100644 --- a/docs/i18n/ar/quickstart.md +++ b/docs/i18n/ar/quickstart.md | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | # دليل البدء السريع لمشروع Leonida | 3 | # دليل البدء السريع لمشروع Leonida |
| 4 | 4 | ||
| 5 | الوثائق الإنجليزية هي المرجع المعتمد. يستند هذا الدليل إلى المراجعة `561b65a` ويغطي خطوات البدء الأساسية. | 5 | الوثائق الإنجليزية هي المرجع المعتمد. يستند هذا الدليل إلى المراجعة `561b65a` ويغطي خطوات البدء الأساسية. |
| 6 | راجع [ملف README بالإنجليزية](../../../README.md#project-status) لمعرفة حالة المشروع الحالية، و[فهرس الوثائق](../../README.md) للمزيد من التفاصيل. | 6 | راجع [ملف README بالإنجليزية](../../../README.md#where-it-stands) لمعرفة حالة المشروع الحالية، و[فهرس الوثائق](../../README.md) للمزيد من التفاصيل. |
| 7 | 7 | ||
| 8 | ## ما هو Leonida؟ | 8 | ## ما هو Leonida؟ |
| 9 | 9 | ||
| @@ -72,7 +72,7 @@ python -I make_game.py --game "D:\path\to\package" --out "D:\Games\Leonida" --wo | |||
| 72 | 72 | ||
| 73 | يعمل `make_game.py` على Linux، ويجد `llvm-mc` تلقائيًا إذا كان ضمن `PATH`. تأكد من أن نسخته تدعم AMDGPU. | 73 | يعمل `make_game.py` على Linux، ويجد `llvm-mc` تلقائيًا إذا كان ضمن `PATH`. تأكد من أن نسخته تدعم AMDGPU. |
| 74 | يعمل محمّل اللعبة، وهو برنامج Windows، عبر Wine أو Proton. إذا كان لديك بناء Windows جاهز للمحمّل، | 74 | يعمل محمّل اللعبة، وهو برنامج Windows، عبر Wine أو Proton. إذا كان لديك بناء Windows جاهز للمحمّل، |
| 75 | فمرّر مجلده باستخدام `--runtime-build`. راجع [تعليمات البناء والتشغيل على Linux](../../../README.md#running-the-loader-on-linux). | 75 | فمرّر مجلده باستخدام `--runtime-build`. راجع [تعليمات البناء والتشغيل على Linux](../../linux.md). |
| 76 | 76 | ||
| 77 | ## حل المشاكل الشائعة | 77 | ## حل المشاكل الشائعة |
| 78 | 78 | ||
diff --git a/docs/linux.md b/docs/linux.md index 3bc8c1550..b6be52568 100644 --- a/docs/linux.md +++ b/docs/linux.md | |||
| @@ -11,8 +11,8 @@ names; the build lists anything it can't find before it starts. | |||
| 11 | 11 | ||
| 12 | | Piece | On Linux | How it is checked | | 12 | | Piece | On Linux | How it is checked | |
| 13 | |---|---|---| | 13 | |---|---|---| |
| 14 | | `make_game.py`: check, shaders, assets, pipelines | Native | CI (`stdlib-tests-linux`, `translator-tests`, `semantic-tests`) | | 14 | | `make_game.py`: check, shaders, assets, pipelines | Native | CI (`linux-python-and-viewer`, `semantic-tests`) | |
| 15 | | `Build.sh`, `Mods.sh` | Native (`/bin/sh`) | `tests/test_shell_launchers.py`, in the standard-library loop of `stdlib-tests-linux` | | 15 | | `Build.sh`, `Mods.sh` | Native (`/bin/sh`) | `tests/test_shell_launchers.py`, in the standard-library loop of `linux-python-and-viewer` | |
| 16 | | Shader translator, its tests and the GPU test tools (`vk_harness`, `vk_pipeline_check`, ...) | Native, GCC or Clang | CI (`linux-gpu-tools`: GCC, tests on llvmpipe); Clang builds them too, but no CI job uses it yet | | 16 | | Shader translator, its tests and the GPU test tools (`vk_harness`, `vk_pipeline_check`, ...) | Native, GCC or Clang | CI (`linux-gpu-tools`: GCC, tests on llvmpipe); Clang builds them too, but no CI job uses it yet | |
| 17 | | `rpf9dump` (asset export) | Native, .NET 8 or newer | CI builds it on Windows only (the `check` job) | | 17 | | `rpf9dump` (asset export) | Native, .NET 8 or newer | CI builds it on Windows only (the `check` job) | |
| 18 | | `gta6rt`, its shims and their tests | Windows program, under Wine or Proton | Cross-built with clang-cl and xwin; CI runs the Windows build under Wine on pushes to `main` | | 18 | | `gta6rt`, its shims and their tests | Windows program, under Wine or Proton | Cross-built with clang-cl and xwin; CI runs the Windows build under Wine on pushes to `main` | |
diff --git a/docs/measuring_fps.md b/docs/measuring_fps.md new file mode 100644 index 000000000..1a8f902ef --- /dev/null +++ b/docs/measuring_fps.md | |||
| @@ -0,0 +1,93 @@ | |||
| 1 | # Measuring frame rates of the D3D12 runtime | ||
| 2 | |||
| 3 | How to find out whether a change or a switch moves the frame of the Rust D3D12 runtime (`d3d12/`), and how not to fool | ||
| 4 | yourself. It is about method; the measurements are in [d3d12/docs/findings.md](../d3d12/docs/findings.md) and the list | ||
| 5 | of switches in [d3d12/docs/switches.md](../d3d12/docs/switches.md). | ||
| 6 | |||
| 7 | ## 1. Look first | ||
| 8 | |||
| 9 | Search [findings.md](../d3d12/docs/findings.md) for the switch or the function you have in mind, on a fresh `main`. | ||
| 10 | Many switches have been measured there, with the card, the scene, the method and the spread. `LEONIDA_COPYBACK_ELIDE`, for one, | ||
| 11 | has an entry that says "not usable here". | ||
| 12 | |||
| 13 | ## 2. Turn the switch inside one run | ||
| 14 | |||
| 15 | `LEONIDA_AB=<seconds>,<switch>[,<switch>..]` turns switches on and off every so many seconds while the title runs, so | ||
| 16 | both sides are measured in one scene, at one cache temperature, beside the same programs | ||
| 17 | ([`ab.rs`](../d3d12/crates/leonida-gpu/src/ab.rs)): | ||
| 18 | |||
| 19 | - It needs a build with `diagnostics` (the one `d3d12/scripts/build-nvidia.ps1` makes) and more than one second a phase. | ||
| 20 | - Up to eight switches; switch number *n* is on in the phases whose number has bit *n*, so every combination comes round. | ||
| 21 | - Give it to the launcher: `-More @{LEONIDA_AB='4,LEONIDA_STORE_BESIDE'}`. `play-nvidia.ps1` removes the `LEONIDA_*` | ||
| 22 | variables of the window it starts in (four paths aside), so `$env:LEONIDA_AB = ...` before it is lost without a word. | ||
| 23 | The same goes for every variable of section 5. | ||
| 24 | - More than eight names, or a phase of one second or less, and there is no A/B at all, again without a word. Look for | ||
| 25 | the `A/B phase` lines in the log. | ||
| 26 | - A plain on/off switch named there goes by the phase instead of its own variable. For a switch with a value or a list | ||
| 27 | the phase only says whether that value counts, so give the value too, in the same `-More`: without | ||
| 28 | `LEONIDA_GUARD_HOT=<ms>` or the hashes of `LEONIDA_SKIP_TRY_A` both sides are off and the A/B compares nothing with | ||
| 29 | nothing. The same goes for another switch it needs (`LEONIDA_PORT_GUARD` for `LEONIDA_GUARD_HOT`). "See the code" | ||
| 30 | under *Kind* in [switches.md](../d3d12/docs/switches.md) is a sign to look there first. | ||
| 31 | - Only switches the code reads that way follow it; for any | ||
| 32 | other name the phases are logged and nothing changes, so check the name in [switches.md](../d3d12/docs/switches.md) | ||
| 33 | or the code before you believe a "no difference". | ||
| 34 | - Not every switch may be turned in play: `findings.md` has one that ends the title (`LEONIDA_ASYNC_SUBMIT`). | ||
| 35 | - Each phase ends with a line `A/B phase <n> bits <b> on [...]`: frames, mean, median, p90, draws a frame, the card's | ||
| 36 | idle and busy time a frame and the submitting thread's work a frame. The first second of a phase is left out. | ||
| 37 | |||
| 38 | Phases of 3.5 to 4 s worked in the runs of `findings.md` (one PC, one save: "about measuring there"). The idle camera | ||
| 39 | there goes round views of about 24 s with different draw counts, so phases of 15 s measured the views, not the switch. | ||
| 40 | |||
| 41 | Standing, `findings.md` cuts the phases into stretches where the draw count jumps, leaves out the first phase of a | ||
| 42 | stretch and fits a level for each stretch; walking, the switch of bit *b* has runs of 2^*b* phases off and 2^*b* on: | ||
| 43 | each pair of neighbouring runs gives one difference, and their mean is the effect. Give the effect **with its standard | ||
| 44 | error**. The scripts it names for this (`ab_pair.py`, `ab_eff.py`) are not in the repository. | ||
| 45 | |||
| 46 | The standard errors in `findings.md` are mostly 0.2 to 0.6 ms for a standing run of some minutes (up to 0.94) and 1 to | ||
| 47 | 2 ms for a walking one (up to 2.24). Two separate | ||
| 48 | runs of one setting differed by 7 ms in one of its tables (75.0 and 82.1 ms). | ||
| 49 | |||
| 50 | ## 3. When only separate runs will do | ||
| 51 | |||
| 52 | A change of code, or a switch that cannot be turned in play, needs separate runs: | ||
| 53 | |||
| 54 | - The same save for every start. The title rewrites its autosave, so keep a copy and put it back before each start | ||
| 55 | (and the player's own back afterwards). | ||
| 56 | - Alternate (A B B A), in one sitting, with a throwaway run first: on one PC the first measured run after a | ||
| 57 | warm-up came out slowest in both of two series (seen once, 2026-11-30, not in `findings.md`, not explained). | ||
| 58 | - After a translator change, or on a new build, play a while first. Until its pipelines are made, a run measures that. | ||
| 59 | - The same programs in the background, and nothing heavy beside it: no compiler, no test suite. `findings.md` has one build at 16.2 to 17.3 | ||
| 60 | and then 12.8 frames a second; what had changed was the programs that start with Windows. | ||
| 61 | - Check every run for the state you think it was in: it reached the world, it did not stay in the menu, it did not end early. One that | ||
| 62 | stayed in the menu showed 60 throughout (seen once, 2026-11-30). | ||
| 63 | - With two runs a side, do not claim a difference smaller than the spread between runs of the same side. | ||
| 64 | |||
| 65 | ## 4. Which number means what | ||
| 66 | |||
| 67 | - **Frame time, not only frames a second.** The line `leonida_gpu::host: <n> fps, <ms> ms/frame (...)` counts rendered | ||
| 68 | frames. With frame generation the screen shows more; say which you mean, or measure with `-NoFrameGen`. | ||
| 69 | - Report the median and a low percentile, and leave the menu and the loading out. | ||
| 70 | - **A sum over all threads is not a part of the frame.** "All threads", "list calls ... ms", the process's CPU time and | ||
| 71 | a whole-process profile add up work that runs side by side. They can exceed the frame many times over. | ||
| 72 | - **A thread that waits because it has nothing to do costs nothing.** The relay line says its thread waits "beside the | ||
| 73 | submitting thread"; what other threads lost to it is in the line about *settles*. | ||
| 74 | - Draws "left out on purpose" are not missing pipelines; the line gives both counts. | ||
| 75 | - The frame stands at the longest of its walls (the card, the submitting thread, the title). Work taken off another one | ||
| 76 | does not show. Cards and CPUs differ: say the card, driver, CPU, memory, profile, resolution, scene and commit. | ||
| 77 | |||
| 78 | ## 5. Where a frame goes | ||
| 79 | |||
| 80 | All in builds with `diagnostics`; each costs something, so do not read frame rates from the same run. | ||
| 81 | |||
| 82 | | Tool | What it answers | | ||
| 83 | |---|---| | ||
| 84 | | `LEONIDA_TIMELINE=<file>` (with `LEONIDA_TIMELINE_AT`, `LEONIDA_TIMELINE_FRAMES`) | A trace of a few frames for `chrome://tracing` or Perfetto, and a text summary with **the chain of work and waits each present came out of**: the tool for "what does the frame wait for". | | ||
| 85 | | `LEONIDA_PROFILE=<from>,<to>,<ms>,<file>` (with `LEONIDA_PROFILE_ONLY=<thread name>`) | Stack samples by thread, waits included, from inside the process. Always with `LEONIDA_PROFILE_ONLY` and a thread of the runtime: without it the busiest threads are taken, the title's among them, and `findings.md` has a run that a walk of a title's stack ended. For those, use the timeline. | | ||
| 86 | | `LEONIDA_GPU_TIMING=1` with `LEONIDA_D3D12_DRED=1` | The commands' time on the card. The launcher sets `LEONIDA_D3D12_DRED` to `faults`, which is not enough, so give both. Each list is then submitted on its own and `LEONIDA_LATE_WAIT` is off: good for which command costs what, not for how long the frame is. | | ||
| 87 | |||
| 88 | ## 6. Before you report a cause | ||
| 89 | |||
| 90 | 1. Write the prediction and what would refute it before the run. | ||
| 91 | 2. Say **MEASURED** (with *n*), **READ IN CODE** or **ASSUMED**. | ||
| 92 | 3. Try to refute it: if this were the cause, what else would have to be true? Is it on the submitting thread's chain? | ||
| 93 | 4. Post numbers only: no logs, captures, shader or pipeline names that are not already in the repository, addresses of the title, or other game data. | ||
diff --git a/docs/mobile.md b/docs/mobile.md index 583f5cacd..93ddb9a34 100644 --- a/docs/mobile.md +++ b/docs/mobile.md | |||
| @@ -32,7 +32,7 @@ of the x86-64 → arm64 groundwork. | |||
| 32 | | Dispatch runtime | `tools/x64_recomp.py` `emit_rt` | `rt_dispatch` (guest pc → host pc through a generated table), `rt_mkflags` (NZCV+operands → canonical x86 EFLAGS; preserves NZCV), `rt_print` (semihosting result output) | | 32 | | Dispatch runtime | `tools/x64_recomp.py` `emit_rt` | `rt_dispatch` (guest pc → host pc through a generated table), `rt_mkflags` (NZCV+operands → canonical x86 EFLAGS; preserves NZCV), `rt_print` (semihosting result output) | |
| 33 | | Verification | `tools/x64_recomp.py` `build_test_kernel`/`run_kernel` | flat kernel image → `qemu-system-aarch64 -M virt -cpu cortex-a53 -kernel -semihosting`; guest `ret` off the sentinel stack exits and prints `R=xxxxxxxx` (guest edi) | | 33 | | Verification | `tools/x64_recomp.py` `build_test_kernel`/`run_kernel` | flat kernel image → `qemu-system-aarch64 -M virt -cpu cortex-a53 -kernel -semihosting`; guest `ret` off the sentinel stack exits and prints `R=xxxxxxxx` (guest edi) | |
| 34 | | PE census | `tools/recomp_census.py` | walks every `.pdata` function, decodes + translates it, reports coverage %, hazard mnemonics, indirect control flow, unwind-info flags | | 34 | | PE census | `tools/recomp_census.py` | walks every `.pdata` function, decodes + translates it, reports coverage %, hazard mnemonics, indirect control flow, unwind-info flags | |
| 35 | | Tests | `tests/test_x64_recomp.py`, `tests/test_recomp_census.py` | hand-built byte fixtures only; exec tests skip when qemu is absent | | 35 | | Tests | `tests/test_x64_recomp.py`, `tests/test_recomp_census.py` | hand-built byte fixtures only; exec tests skip when qemu is absent (`QEMU_AARCH64` names the binary, else `qemu-system-aarch64` on `PATH`) | |
| 36 | 36 | ||
| 37 | ### Translator contract (as implemented) | 37 | ### Translator contract (as implemented) |
| 38 | 38 | ||
diff --git a/docs/mod-menu.md b/docs/mod-menu.md index 18023dd0f..9ac70e56f 100644 --- a/docs/mod-menu.md +++ b/docs/mod-menu.md | |||
| @@ -216,16 +216,59 @@ the title's. A panic in our own work stops the work and not the title. | |||
| 216 | (what the runtime sees: threads, whether the work ran at once or at the queue's point of rest, the ped, its | 216 | (what the runtime sees: threads, whether the work ran at once or at the queue's point of rest, the ped, its |
| 217 | position and forward vector, wanted level, clock, the weather types, the cheat table), `cheat <n>`, `wanted <n>`, | 217 | position and forward vector, wanted level, clock, the weather types, the cheat table), `cheat <n>`, `wanted <n>`, |
| 218 | `time <h> [m [s]]`, `hours <n>`, `pause <0|1>`, `weather <index|NAME|freeze|free>`, `nudge <dx> <dy> <dz> | 218 | `time <h> [m [s]]`, `hours <n>`, `pause <0|1>`, `weather <index|NAME|freeze|free>`, `nudge <dx> <dy> <dz> |
| 219 | [frames]`. Everything asked and done is written to `%TEMP%\leonida-actions\log.txt` (addresses of the run: not | 219 | [frames]`, `spawn <model name|0x key>` (a vehicle of any model, by the spawn the vehicle cheats call), `god <0|1>` |
| 220 | for the repository). | 220 | and `native <0x hash> [slots]` (below). Everything asked and done is written to `%TEMP%\leonida-actions\log.txt` |
| 221 | (addresses of the run: not for the repository). | ||
| 222 | |||
| 223 | ### Any vehicle, and the natives by their handlers (2026-11-30) | ||
| 224 | |||
| 225 | The nine vehicle cheats are each `mov rcx, <model key>` and a call of one function: `spawn` calls that function | ||
| 226 | (taken from the cheats' own code through the table) with another model's key, the low 64 bits of | ||
| 227 | MurmurHash3_x64_128 (seed 0) of the lower-cased model name (one cheat's key is that hash of its model's name). | ||
| 228 | |||
| 229 | The script natives turned out to be findable after all, by their handlers' shape rather than any table: each | ||
| 230 | handler checks its argument count first and, on a negative one, stores its native's own 64-bit hash where the | ||
| 231 | result goes. `leonida_loader::natives` reads that hash from every handler (6,000 and more in 1.0.2.1, the start of | ||
| 232 | each from the unwind table), so a native is called by its hash: `god` is SET_ENTITY_INVINCIBLE on PLAYER_PED_ID's | ||
| 233 | reference, both by the hashes of modpapi/scripthook-vi's native database (CC BY 4.0). The shape, the call context | ||
| 234 | and the model key's form are kylepelham/El1xr's findings (GPL-3.0). Unit-tested and checked against the executable; | ||
| 235 | god mode not yet seen in the running title. | ||
| 236 | |||
| 237 | Seen in the running title (2026-11-30, run d179, the game actions' first run in the world, a script of commands): | ||
| 238 | every place found; the weather forced to RAIN (previous, next and forced all its type) and let go; the time set to | ||
| 239 | 22:00 and back to 12:00; the wanted level raised to 2 and cleared (the title's state read 2, then 0); the health | ||
| 240 | cheat run; `spawn sanchez` and `spawn airbus` asked of the spawn the cheats call (taken from their code, the same | ||
| 241 | function El1xr's trainer calls): a motorbike on the minimap beside the player, and the airport bus (a model none of | ||
| 242 | the nine cheats holds) in the air just ahead of the player on the deck, falling. All of it ran on the title's thread | ||
| 243 | at the queue's point of rest, not in the hook's own call. The HUD kept two red stars after the wanted level was | ||
| 244 | cleared by the title's function (its state read 0): a clear now also calls CLEAR_PLAYER_WANTED_LEVEL on the | ||
| 245 | player's reference. | ||
| 246 | |||
| 247 | Teleports go through the title's own teleport now when its natives are found: `teleport <x> <y> <z>`, and the | ||
| 248 | menu's Teleport page, call SET_ENTITY_COORDS on PLAYER_PED_ID's reference (the place as four packed floats, the | ||
| 249 | axis flags off and the area cleared), in place of the write of the ped's position below. | ||
| 250 | |||
| 251 | Seen in the running title (run d195): 6,805 natives found by their handlers; PLAYER_PED_ID gave a reference of | ||
| 252 | two slots; god mode on and off with it; and the teleport moved the player at once, but into the bay far from the | ||
| 253 | deck: the place the actions had read (the ped's +0x70) is not in the world's coordinates. The title keeps an | ||
| 254 | entity's place relative to an origin of its own, and GET_ENTITY_COORDS turns it into the world's (the native | ||
| 255 | database says the command decodes +0x70). So the place the actions give (`game_actions::position`, the info line, | ||
| 256 | the Teleport page's own place and its saved spots) is now GET_ENTITY_COORDS on the player, read on the title's | ||
| 257 | thread a few times a second, and `lift <metres>` sets the player that far above it. | ||
| 258 | |||
| 259 | The time of day set while the title still loads can end it: run d197 set 23:00 sixty seconds after the start and the | ||
| 260 | title stopped within two seconds (an access violation, a write of title memory in KERNELBASE on another thread). | ||
| 261 | Set in the world (run d199, at 120 s) it did not, and the night it gave looked as it should (the moon, the stars, | ||
| 262 | the bridge's lights, a lit porch; no one-frame dips or spikes in 545 frames). Scripts set the time once the world is | ||
| 263 | there. | ||
| 221 | 264 | ||
| 222 | ## What is not there yet, and why | 265 | ## What is not there yet, and why |
| 223 | 266 | ||
| 224 | God mode, stamina, fast run and swim, super jump, invisibility, ragdoll, the vehicle items other than the nine | 267 | Stamina, fast run and swim, super jump, invisibility, ragdoll, every weapon item, moon gravity, traffic, |
| 225 | spawns, every weapon item, moon gravity, traffic, pedestrians, police, blackout, strong wind, moving the player | 268 | pedestrians, police, blackout, strong wind, HUD and radio, and the menu's own item for any vehicle (the run script |
| 226 | (teleports), HUD and radio. These items go through `GameActions` (`actions.rs`); for them the backend answers | 269 | has it). These items go through `GameActions` (`actions.rs`); for |
| 227 | with the reason, and the menu shows them dimmed with that reason in the help box. The title's functions for them | 270 | them the backend answers with the reason, and the menu shows them dimmed with that reason in the help box. Most of |
| 228 | were not looked for one by one: the cheat table has none of them, and the script commands (below) have no names. | 271 | them are natives now within reach (above); each needs its hash and its arguments checked. |
| 229 | 272 | ||
| 230 | Moving the player: the ped and its position are known now (above), but the title's function that moves a ped was | 273 | Moving the player: the ped and its position are known now (above), but the title's function that moves a ped was |
| 231 | not found. Looked for among the script commands (below) by their arguments: 46 commands take a 16-byte handle, | 274 | not found. Looked for among the script commands (below) by their arguments: 46 commands take a 16-byte handle, |
diff --git a/docs/port_status.md b/docs/port_status.md index 6b9a7314a..889f369ca 100644 --- a/docs/port_status.md +++ b/docs/port_status.md | |||
| @@ -20,11 +20,9 @@ work folders outside the repository (`G:\gta6port` on the test machine). | |||
| 20 | | Path | What | | 20 | | Path | What | |
| 21 | |---|---| | 21 | |---|---| |
| 22 | | `runtime/`, `tools/`, `make_game.py`, `Build.bat` | Leonida: the product | | 22 | | `runtime/`, `tools/`, `make_game.py`, `Build.bat` | Leonida: the product | |
| 23 | | `victory/` | DexNom/VIctory subtree with full history, the patch source. A background poller fetches `victory/main` every 15 minutes and speaks up only when new commits exist; they are then merged with `python -I scripts/sync_victory.py --merge` and reviewed for fixes to port | | 23 | | `victory/` | DexNom/VIctory subtree with full history (historical patch source; superseded by `d3d12/`) | |
| 24 | | `scripts/sync_victory.py` | Fetches `victory/main`, lists new commits, merges them with `git subtree pull` | | 24 | | remote `victory7900` | avatarmanz/VIctory-7900XTX, a second patch source (fetch only, not merged: it diverges from DexNom's line, 408 commits ahead and 334 behind at the time of adding; much of its recent work is frame time). Polled every 15 minutes in the background. Port from it commit by commit (`git show victory7900/main:<path>`) | |
| 25 | | remote `victory7900` | avatarmanz/VIctory-7900XTX, a second patch source (fetch only, not merged: it diverges from DexNom's line, 408 commits ahead and 334 behind at the time of adding; much of its recent work is frame time). Also polled every 15 minutes in the background. Port from it commit by commit (`git show victory7900/main:<path>`) | | ||
| 26 | | `tools/victory_saves.py` | Converts a VIctory data folder's saves and local storage into gta6rt's layout, so a save made under VIctory skips the first-boot screens | | 25 | | `tools/victory_saves.py` | Converts a VIctory data folder's saves and local storage into gta6rt's layout, so a save made under VIctory skips the first-boot screens | |
| 27 | | `scripts/port_ctl.py` | Drives a reference run of VIctory's runtime (start, pad presses from a file, frame captures, fps lines, stop) | | ||
| 28 | 26 | ||
| 29 | ## Test machine | 27 | ## Test machine |
| 30 | 28 | ||
diff --git a/docs/prompt_glyphs.md b/docs/prompt_glyphs.md index 7fadaa197..c8a0c0164 100644 --- a/docs/prompt_glyphs.md +++ b/docs/prompt_glyphs.md | |||
| @@ -3,8 +3,9 @@ | |||
| 3 | The title draws its button prompts from one Scaleform movie, and it has only the Xbox set: the dump holds no | 3 | The title draws its button prompts from one Scaleform movie, and it has only the Xbox set: the dump holds no |
| 4 | PlayStation or keyboard glyphs. This note records the movie's format, which export is which button and who asks for | 4 | PlayStation or keyboard glyphs. This note records the movie's format, which export is which button and who asks for |
| 5 | them, measured on the user's own `data.rpf`. It holds no shapes. `tools/ps_prompt_glyphs.py` builds an original | 5 | them, measured on the user's own `data.rpf`. It holds no shapes. `tools/ps_prompt_glyphs.py` builds an original |
| 6 | PlayStation set, `tools/pc_prompt_glyphs.py` a keyboard-and-mouse set from pictures the player supplies, and the runtime | 6 | PlayStation set, `tools/pc_prompt_glyphs.py` a keyboard-and-mouse set from its own built-in key caps or from pictures |
| 7 | serves the one for the device in use. | 7 | the player supplies, `tools/prompt_glyph_movies.py` builds both where the runtime looks (from the D3D12 launcher and |
| 8 | make_game.py's runtime stage), and the runtime serves the one for the device in use. | ||
| 8 | 9 | ||
| 9 | ## The movie | 10 | ## The movie |
| 10 | 11 | ||
| @@ -118,11 +119,56 @@ subclasses, no `Main` behaviour, no sound hook); whether the title's loader need | |||
| 118 | 119 | ||
| 119 | ## The keyboard and mouse replacement | 120 | ## The keyboard and mouse replacement |
| 120 | 121 | ||
| 121 | `tools/pc_prompt_glyphs.py` (standard library only) turns a folder of pictures, one `*Main_Button_<N>.png` per N, into | 122 | `tools/pc_prompt_glyphs.py` (standard library only) turns pictures, one per N, into the shapes of the same 38 sprites: |
| 122 | the shapes of the same 38 sprites. The pictures are the player's: the set this was written for was drawn by a friend | 123 | its own built-in set unless a folder of the player's pictures (`*Main_Button_<N>.png`) is named with `--glyphs`. The |
| 123 | of the user from scratch (W/A/S/D and arrow keys with one or more keys lit, a mouse in a circle for the right stick, | 124 | first set it was written for was drawn by a friend of the user from scratch (W/A/S/D and arrow keys with one or more |
| 124 | key caps for the face buttons and shoulders), its licence is not stated, and neither the pictures nor a movie built | 125 | keys lit, a mouse in a circle for the right stick, key caps for the face buttons and shoulders); its licence is not |
| 125 | from them is in the repository. | 126 | stated, and neither those pictures nor a movie built from them is in the repository. |
| 127 | |||
| 128 | ### The built-in set | ||
| 129 | |||
| 130 | Key caps, arrow keys and a mouse drawn by the tool itself (`builtin`, `BUILTIN`): rounded rectangles, quadratic | ||
| 131 | curves, polygons and a stroke font of its own (16 capitals), painted with exact-area anti-aliasing into the same | ||
| 132 | in-memory 4x pictures (264 x 264) that the tracer reads from a player's folder, so the two take one path. No picture, | ||
| 133 | font, Pillow or game file is needed. Black rim (heavier at the bottom, the cap's edge), white face, black label; the | ||
| 134 | lit mouse button is the grey (103, 103, 103); the movement arrows around the mouse are white with a black edge, so | ||
| 135 | they show on a dark scene and a light one. | ||
| 136 | |||
| 137 | | N | shows | N | shows | | ||
| 138 | |---|---|---|---| | ||
| 139 | | 4, 5, 6, 7 | the up, down, left, right arrow key | 25 | C | | ||
| 140 | | 8, 9 | the four arrow keys (inverted T) | 21-24, 26, 29, 59 | the mouse, arrows four ways | | ||
| 141 | | 10 / 11 | up over down / left beside right | 27 / 28 | the mouse, arrows up and down / left and right | | ||
| 142 | | 12, 13, 14, 15 | W, S, A, D | 30, 31 | SPACE, CTRL (wide caps) | | ||
| 143 | | 16 | SHIFT (a wide cap) | 32, 33 | R, F | | ||
| 144 | | 17, 20, 58 | W over A S D (inverted T) | 34 / 36 | TAB (a wide cap) / Q | | ||
| 145 | | 18 / 19 | W over S / A beside D | 35 / 37 | the mouse, right / left button lit | | ||
| 146 | | | | 38, 39 | ESC, M | | ||
| 147 | |||
| 148 | The keys are those of the runtime's on-foot keyboard table (`gameinput/kbm.rs`, `SHARED` and `FOOT_ONLY`) for the pad | ||
| 149 | input of each Xbox glyph; `tests/test_pc_prompt_glyphs.py` reads that table and fails when a label no longer matches. | ||
| 150 | Checked on 2026-11-29: every slot matched (Y is both F and E on foot; the cap shows F, the key that enters and | ||
| 151 | leaves vehicles in both tables). | ||
| 152 | |||
| 153 | **Size.** Players found an earlier set "covered other UI". Measured on the user's movie (each Xbox sprite drawn at 4x | ||
| 154 | with `tools/xbox_prompt_glyphs.py`, opaque bounds and covered area counted; only the numbers are kept, as | ||
| 155 | `XBOX_AREA` in the tool): the Xbox glyphs are not drawn small inside the canvas. The face buttons, sticks, Menu and | ||
| 156 | View are discs of diameter 64 that touch all four edges (3,216 canvas pixels, a 3-pixel black ring around a white | ||
| 157 | disc of diameter 58); the D-pad is a cross that reaches the same edges (2,339-2,345); the bumpers are 64 x 39 at | ||
| 158 | y 12.5..51.5 (2,161), the triggers 61 x 64 (3,496-3,534), the stick presses 64 x 62 (2,534). A square cap of 64 fills | ||
| 159 | the corners the disc leaves empty, and so it reads larger than the glyph it replaces. Every built-in picture | ||
| 160 | therefore stays inside the outline of its slot's Xbox glyph (the circle of radius 32, or the slot's bounds for 16, 25 | ||
| 161 | and 34-37) and covers no more of the canvas than that glyph: a single cap is 48 x 48 (2,235 pixels, against 2,341 for | ||
| 162 | the D-pad and 3,216 for a disc), clusters and pairs 1,120-1,212, the wide caps 56-60 wide and 30-34 tall (never taller | ||
| 163 | than a single cap) with a smaller font for the long names (SHIFT, SPACE, CTRL, TAB; ESC keeps a square cap), TAB and Q | ||
| 164 | inside the bumpers' band, the mice 648 and 1,543. `footprint()` measures it and the test asserts it for every slot. | ||
| 165 | The sprites keep the Xbox glyphs' bounds (the invisible rectangle), so where a prompt's text is laid out does not move. | ||
| 166 | |||
| 167 | **Built, over the user's movie (2026-11-29):** 7,456 bytes of shapes and sprites of the 15,226 (7,770 to spare); | ||
| 168 | drawn back, 0.12 % to 0.61 % of a glyph's opaque area differs from its picture, one pixel in all more than half wrong | ||
| 169 | (N 16). The tool takes a few seconds for the whole set. | ||
| 170 | |||
| 171 | ### From pictures to shapes (either set) | ||
| 126 | 172 | ||
| 127 | - **Pictures.** 8-bit PNG, the 64 x 64 canvas with one more canvas pixel on every side, at a whole multiple (264 x 264 | 173 | - **Pictures.** 8-bit PNG, the 64 x 64 canvas with one more canvas pixel on every side, at a whole multiple (264 x 264 |
| 128 | is 4x), three flat colours with anti-aliased edges: black, white and the grey (103, 103, 103). | 174 | is 4x), three flat colours with anti-aliased edges: black, white and the grey (103, 103, 103). |
| @@ -149,10 +195,15 @@ from them is in the repository. | |||
| 149 | of them). | 195 | of them). |
| 150 | 196 | ||
| 151 | ``` | 197 | ``` |
| 198 | python -I tools/pc_prompt_glyphs.py --from-archive "<package>/data.rpf" --out pc_prompt_glyphs.gfx # built-in set | ||
| 152 | python -I tools/pc_prompt_glyphs.py --glyphs <folder> --from-archive "<package>/data.rpf" --out pc_prompt_glyphs.gfx | 199 | python -I tools/pc_prompt_glyphs.py --glyphs <folder> --from-archive "<package>/data.rpf" --out pc_prompt_glyphs.gfx |
| 200 | python -I tools/pc_prompt_glyphs.py --sheet sheet.png --pictures <folder> # the built-in set drawn back, and as PNGs | ||
| 153 | python -I tools/pc_prompt_glyphs.py --selftest # pictures made by the tool itself, no game file | 201 | python -I tools/pc_prompt_glyphs.py --selftest # pictures made by the tool itself, no game file |
| 154 | ``` | 202 | ``` |
| 155 | 203 | ||
| 204 | The numbers under "Size" and "Check" in this list are for the friend's set; the built-in set's are in the section | ||
| 205 | above. | ||
| 206 | |||
| 156 | ## How the runtime swaps the movie | 207 | ## How the runtime swaps the movie |
| 157 | 208 | ||
| 158 | The D3D12 runtime (`leonida-hle`, `modules/glyphs.rs`, hooked in `modules/dstorage.rs` `execute`) answers the title's | 209 | The D3D12 runtime (`leonida-hle`, `modules/glyphs.rs`, hooked in `modules/dstorage.rs` `execute`) answers the title's |
| @@ -178,11 +229,28 @@ contents is not touched or needed. | |||
| 178 | movie once, about 3 s after it starts: one `the title reads its glyph movie` line in the log of a 15 minute session | 229 | movie once, about 3 s after it starts: one `the title reads its glyph movie` line in the log of a 15 minute session |
| 179 | with the menus opened (2026-11-27). Picking up another device later does not show until the next start; see the | 230 | with the menus opened (2026-11-27). Picking up another device later does not show until the next start; see the |
| 180 | last section. | 231 | last section. |
| 181 | - **Builds.** `python -I tools/ps_prompt_glyphs.py --from-archive "<package>/data.rpf" --out ps_prompt_glyphs.gfx` builds | 232 | - **Built for every player.** `tools/prompt_glyph_movies.py --game <package>` writes both movies into `d3d12/target` |
| 233 | (above `target/diag` and `target/release`, so either build finds them; ignored by git): the keyboard one from the | ||
| 234 | built-in set (or `--pc-glyphs <folder>`), the PlayStation one, each over the title's movie in `<package>/data.rpf` | ||
| 235 | and, if that cannot be read, the standalone movie padded to 28,148 bytes. `d3d12\scripts\play-nvidia.ps1` (and so | ||
| 236 | `scripts\play-d3d12.ps1` and the `play-*` scripts, which go through it; `-PcGlyphs <folder>` for your pictures) runs | ||
| 237 | it before each start when Python is there, and make_game.py runs it in its runtime stage (`--pc-glyphs DIR`). It | ||
| 238 | prints nothing when there is nothing to do and never stops the start or the build: a set it cannot build keeps the | ||
| 239 | Xbox glyphs. A movie of the player's is never touched: a set is skipped while its variable is set (in the launcher, | ||
| 240 | `-More @{LEONIDA_PC_GLYPHS=...}`, since it clears the window's other `LEONIDA_*` variables), and when a movie file | ||
| 241 | this step did not write is in any folder the runtime searches, where this step's own copy is removed so it cannot | ||
| 242 | come first. What it wrote is told by `<movie>.stamp` beside it (the movie's SHA-256 and a digest of the tools, the | ||
| 243 | archive's size and time and the pictures); its own movie is rebuilt only when that digest changes. A cargo clean | ||
| 244 | removes them with `target\`; the next start builds them again. | ||
| 245 | - **Builds by hand.** `python -I tools/ps_prompt_glyphs.py --from-archive "<package>/data.rpf" --out ps_prompt_glyphs.gfx` builds | ||
| 182 | over the title's own movie: the shapes are replaced and every other tag (the ActionScript, export and class tables) is | 246 | over the title's own movie: the shapes are replaced and every other tag (the ActionScript, export and class tables) is |
| 183 | kept as it is, so the title's code finds the symbols as before. The output holds those tags of the game's movie: keep it | 247 | kept as it is, so the title's code finds the symbols as before. The output holds those tags of the game's movie: keep it |
| 184 | on your PC, never commit it. `--pad-inflated 28148 --out ps_prompt_glyphs.gfx` builds the standalone movie | 248 | on your PC, never commit it. `--pad-inflated 28148 --out ps_prompt_glyphs.gfx` builds the standalone movie |
| 185 | (with its own ActionScript block, which has never run in the title) padded to the same length. | 249 | (with its own ActionScript block, which has never run in the title) padded to the same length. |
| 250 | `--mono` draws the PlayStation glyphs in a look close to the PS5's own prompts: white keys and discs with black | ||
| 251 | symbols, and the d-pad as the DualSense's four separate arrow keys pointing at the middle (the pressed ones white, | ||
| 252 | the rest grey). Its sprites have no see-through box behind them: a highlight's colour change showed that box as a | ||
| 253 | black halo. | ||
| 186 | - **Checking it.** Run with `LEONIDA_PROMPTS=playstation` (or `keyboard`) and look in the log for | 254 | - **Checking it.** Run with `LEONIDA_PROMPTS=playstation` (or `keyboard`) and look in the log for |
| 187 | `prompt glyphs: PlayStation movie loaded` (or `keyboard movie loaded`) and `prompt glyphs: the title reads its glyph | 255 | `prompt glyphs: PlayStation movie loaded` (or `keyboard movie loaded`) and `prompt glyphs: the title reads its glyph |
| 188 | movie`, which names the family and the glyphs served. If the second line never appears, the title does not read the | 256 | movie`, which names the family and the glyphs served. If the second line never appears, the title does not read the |
diff --git a/docs/running.md b/docs/running.md index 3587cdc49..526054ab0 100644 --- a/docs/running.md +++ b/docs/running.md | |||
| @@ -37,6 +37,18 @@ Paths are placeholders: `<checkout>` is the repository, `<build>` the folder wit | |||
| 37 | runs used `LEONIDA_SKIP_COMPUTE=<name>,<name>,...` with those programs' names (picked by module size from | 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 | 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. | 39 | drops acceleration-structure builds. The picture then lacks what they draw. |
| 40 | - **The DirectStorage predictor profile.** The runtime decodes the title's BCPack textures with a profile fitted from | ||
| 41 | the local package, `<work>/shaders/bcpack/history.bcph` ([directstorage.md](directstorage.md)). The runtime stage | ||
| 42 | of `make_game.py` regenerates it when the fitter changes; a runtime built without that stage (`cmake` or | ||
| 43 | `scripts/build_runtime.ps1` directly) keeps the old one. Since `2a491668a` the fitter fills the BC7 history fields | ||
| 44 | of packed mip tails, whose missing values made the story load's tail requests fail with `missing-endpoint` | ||
| 45 | (`E_DSTORAGE_DECOMPRESSION_ERROR`; [#2019](https://github.com/ubiquitarianism/leonida/issues/2019), | ||
| 46 | [#2396](https://github.com/ubiquitarianism/leonida/issues/2396)). With an older profile, run | ||
| 47 | `python -I tools/build_dstorage_history.py <package> --out <work>/shaders/bcpack/history.bcph --trainer <build>/bcpack_history_train.exe` | ||
| 48 | once (about 11 minutes here). The runtime's load line then reports 4,406 of 6,144 BC7 endpoint fields (4,228 | ||
| 49 | before). On an RTX 4070 SUPER (Windows 11, NVIDIA 621.01), with the old profile, 7-8 such errors a run and the | ||
| 50 | story load did not finish in 1,800 s (2 runs); with the new one, none, and the run reached the opening sequence | ||
| 51 | (1 run) ([reported by others](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7226672676)). | ||
| 40 | 52 | ||
| 41 | ## Recommended variables (all platforms) | 53 | ## Recommended variables (all platforms) |
| 42 | 54 | ||
| @@ -90,7 +102,7 @@ reasons behind each step: [linux_proton.md](linux_proton.md#amd-on-linux-what-go | |||
| 90 | | `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)) | | 102 | | `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)) | |
| 91 | | `LEONIDA_TITLE_WATCHDOG=0`, `LEONIDA_TITLE_WATCHDOG_KICK=<trap RVA>,<kick RVA>` | the title's hang watchdog ([above](#settings-every-platform-needs)) | | 103 | | `LEONIDA_TITLE_WATCHDOG=0`, `LEONIDA_TITLE_WATCHDOG_KICK=<trap RVA>,<kick RVA>` | the title's hang watchdog ([above](#settings-every-platform-needs)) | |
| 92 | | `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 | | 104 | | `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 | |
| 93 | | `LEONIDA_ARENA_MB=4095`, `LEONIDA_TITLE_WINDOWS_MB=4096`, `LEONIDA_GEOMETRY_MB=6144` | room for the title's buffers in the world | | 105 | | `LEONIDA_ARENA_MB=4095`, `LEONIDA_TITLE_WINDOWS_MB=4096`, `LEONIDA_GEOMETRY_MB=6144` | room for the title's buffers in the world (with sparse binding the arena's size is address range; memory is bound as it is used) | |
| 94 | | `LEONIDA_SHADOW_ALIAS_MS=5000`, `LEONIDA_CONSOLE_FIX_US=0` | carried from earlier boot runs; their effect here was not measured one by one | | 106 | | `LEONIDA_SHADOW_ALIAS_MS=5000`, `LEONIDA_CONSOLE_FIX_US=0` | carried from earlier boot runs; their effect here was not measured one by one | |
| 95 | | `LEONIDA_DEVICE_FAULT=1`, `LEONIDA_DEVICE_MARKERS=1` | device-loss/stall report plus `VK_AMD_buffer_marker` draw/dispatch attribution if the GPU hangs | | 107 | | `LEONIDA_DEVICE_FAULT=1`, `LEONIDA_DEVICE_MARKERS=1` | device-loss/stall report plus `VK_AMD_buffer_marker` draw/dispatch attribution if the GPU hangs | |
| 96 | | `LEONIDA_GPU_LATENCY=1`, `LEONIDA_MEM_PROBE=30`, `LEONIDA_TITLE_HUD=1`, `LEONIDA_DEV_OVERLAY=1` | optional live telemetry and overlays | | 108 | | `LEONIDA_GPU_LATENCY=1`, `LEONIDA_MEM_PROBE=30`, `LEONIDA_TITLE_HUD=1`, `LEONIDA_DEV_OVERLAY=1` | optional live telemetry and overlays | |
| @@ -185,3 +197,8 @@ with the fields of these sections: machine (OS, GPU, driver, RAM), the commit, h | |||
| 185 | pre-compile, the OS and driver settings, every `LEONIDA_*` variable that differs from the defaults (never the | 197 | pre-compile, the OS and driver settings, every `LEONIDA_*` variable that differs from the defaults (never the |
| 186 | watchdog's RVA values), and how far the run got with its frame rate. Keep logs, traces and screenshots on your machine | 198 | watchdog's RVA values), and how far the run got with its frame rate. Keep logs, traces and screenshots on your machine |
| 187 | ([linux_proton.md](linux_proton.md#reporting-a-result)). | 199 | ([linux_proton.md](linux_proton.md#reporting-a-result)). |
| 200 | |||
| 201 | For a run of the D3D12 runtime (`d3d12/`), `python -I tools/d3d12_run_fps.py <log>` reads the frame lines of the | ||
| 202 | launcher's log and gives the frame rate overall and by draws a frame. Two runs never show the same scenes for the same | ||
| 203 | time, so their plain medians do not compare: `--compare <log B>` puts an A and a B side by side per bucket of draws. | ||
| 204 | It prints numbers only, never a log line. | ||
diff --git a/docs/runtime_ctest_hosts.md b/docs/runtime_ctest_hosts.md new file mode 100644 index 000000000..d8d895657 --- /dev/null +++ b/docs/runtime_ctest_hosts.md | |||
| @@ -0,0 +1,105 @@ | |||
| 1 | # The runtime ctest suite on two hosts: Wine and native Windows | ||
| 2 | |||
| 3 | The same runtime test suite, the same GPU model, two hosts: Wine on Linux ([#1150](https://github.com/ubiquitarianism/leonida/issues/1150)) and native Windows 10. The point is not to compare percentages but to separate the failures that belong to Wine's host DLLs from the ones that are ours. A test that fails only under Wine is a limit of the host; a test that fails on both is a bug in the layer, and one that fails only natively is a bug Wine was hiding. | ||
| 4 | |||
| 5 | No game files were used by either run. The suite builds its own fixtures. | ||
| 6 | |||
| 7 | ## The two runs | ||
| 8 | |||
| 9 | | | Wine run (#1150) | Native run (this page) | | ||
| 10 | |---|---|---| | ||
| 11 | | Host | Parrot Linux (Debian 13), Wine 10.0 | Windows 10 Pro 19045, no Wine | | ||
| 12 | | GPU | NVIDIA GPU (Pascal class, 4 GB). Model and PCI id withheld | the same card | | ||
| 13 | | Driver | NVIDIA 555.58 | NVIDIA 582.28 | | ||
| 14 | | Compiler | clang-cl 21 / lld-link, xwin SDK 10.0.26100 | MSVC 19.44 x64, installed SDK | | ||
| 15 | | Commit | `3aa97542` | `58be9cdf` | | ||
| 16 | | Tests run | 304 of 304 | 307 of 308 (one disabled) | | ||
| 17 | | Result | 239 passed, 19 failed, 5 timeouts, 40 skipped — 92% | 278 passed, 11 failed (9 failed, 1 SegFault, 1 timeout), 18 skipped — 96%, 452 s | | ||
| 18 | | ctest valve | `--timeout 120` | `--timeout 120` | | ||
| 19 | |||
| 20 | The commits differ by a day of `main`. Nothing in the 24 Wine failures is a test added between them except `d3d12_existing_heap`, `d3d12_xmem_placed` and `root_sig`, which all exist in both. | ||
| 21 | |||
| 22 | ## 19 Wine failures pass natively | ||
| 23 | |||
| 24 | These are host limits. Wine's `ntdll`/`bcrypt`/`dxgi`/vkd3d answer differently from the Windows DLLs the tests compare against: | ||
| 25 | |||
| 26 | | Test | What Wine does that heals here | | ||
| 27 | |---|---| | ||
| 28 | | `xmem` | protection windows, page charging and read-only faults: Windows virtual-memory semantics Wine does not give | | ||
| 29 | | `file_system` | `ReadFile` into uncommitted pages does not fail with `ERROR_NO_ACCESS` | | ||
| 30 | | `bcrypt_rng`, `bcrypt_rng_seeded` | the unknown-algorithm probe: the shim delegates to Wine's `bcrypt`, which answers another status | | ||
| 31 | | `d3d12_clear`, `d3d12_clear_formats` | no WARP under Wine, so the differential test cannot run | | ||
| 32 | | `dxgi_swapchain` | `CreateSwapChainForHwnd` returned `0x887a0001` against the host's `0x00000000` | | ||
| 33 | | `dstorage` | the timeout with no output after `OpenFile: null or empty path` is Wine's, not ours | | ||
| 34 | | `run_startup_cmdline` | the Wine init-message issue | | ||
| 35 | | `vk_device_filter_tools` | the script ran the `.exe` directly on Linux (`Exec format error`) instead of through Wine | | ||
| 36 | | `root_sig` | the all-zero-checksum Xbox blob: Wine's chained serialization, as the issue suspected | | ||
| 37 | | `d3d12_residency`, `d3d12_fence_timing`, `d3d12_indirect_dispatch_count`, `d3d12_xmem_placed` | the documented host-comparison family | | ||
| 38 | | `d3d12_buffer_tiles`, `d3d12_texture_tiles` | the sparse-residency deadlock: the first `UpdateTileMappings` is refused under Wine and teardown blocks on the queue | | ||
| 39 | | `dxgi_host_parity`, `dxgi_waitable_latency` | the page fault on write to `0x0` only turned into a hang because winedbg attached | | ||
| 40 | |||
| 41 | The four hangs are the clearest case: natively they are ordinary sub-second passes. | ||
| 42 | |||
| 43 | ## 5 Wine failures reproduce natively, so they are ours | ||
| 44 | |||
| 45 | | Test | Measured | | ||
| 46 | |---|---| | ||
| 47 | | `d3d12_vulkan_device` | fails as under Wine | | ||
| 48 | | `d3d12_subresource_copy` | `CPU copies (host image copy): the steps differ from the host's`, line 391 | | ||
| 49 | | `d3d12_heap_properties` | `heap properties committed texture, CUSTOM write-back L0: ours 0x8007000e host 0x0` — our `E_OUTOFMEMORY` where the host creates the resource | | ||
| 50 | | `d3d12_existing_heap` | `a title-placed buffer (device slot 133) could not import its pages…`, line 196 `GetGPUVirtualAddress() == (D3D12_GPU_VIRTUAL_ADDRESS)pages` (`HRESULT 0x80004001`) | | ||
| 51 | | `d3d12_r9g9b9e5_uav` | line 669 `SUCCEEDED(device->CreateCommittedResource(&custom_heap, ..., &cpu_uav.p))` — CPU-heap `HOST_TRANSFER` texture gets `E_OUTOFMEMORY` on Pascal (same root cause as `d3d12_subresource_copy` and `d3d12_heap_properties`, after the expected `GetResourceAllocationInfo format not supported yet: 67` refusal log) | | ||
| 52 | |||
| 53 | ## 6 that only fail natively, deterministic 3 of 3 | ||
| 54 | |||
| 55 | Each was rerun three times alone with `ctest -R '^name$' --repeat until-fail:3`; every repetition failed the same way on this build. | ||
| 56 | |||
| 57 | | Test | Symptom | | ||
| 58 | |---|---| | ||
| 59 | | `d3d12_subgroup` | **SegFault** at 1.4 s, right after `device slot 16 (CreateRootSignature) first call`. Stack-layout-dependent: device slot 14 (`CreateDescriptorHeap`) accepted an unaligned caller stack word (`0x65626f72705f7370`, `"ps_probe"`) as a console heap address whenever the next word happened to equal `32` ([#1328](https://github.com/ubiquitarianism/leonida/pull/1328)); an independent Pascal 4 GB build with a different stack frame passed 3/3 | | ||
| 60 | | `d3d12_set_descriptor_heaps` | `CHECK failed: !blob.empty()` (line 341), after two `upload heaps in system memory (no Resizable BAR)` lines | | ||
| 61 | | `root_signature_oracle` | `FAIL 1.1 with every root-signature flag: Microsoft serializer accepts it` (`Unsupported bit-flag set (root signature flags c7f)` — Windows 10's `d3d12.dll` refuses the SM 6.6 heap-direct bits `0xC00`) | | ||
| 62 | | `d3d12_close_parity` | the compared steps diverge from the host from the third case on | | ||
| 63 | | `d3d12_pso_validation` | line 436 `check_gfx_parity("gfx: Flags=DYNAMIC_DEPTH_BIAS", ...)` (`layer 0x00000000 != host 0x80070057`: Windows 10's runtime refuses `DYNAMIC_DEPTH_BIAS`; the `depth-stencil format not supported: 9999, ...` lines are negative-case logs) | | ||
| 64 | | `xdxr_build_check` | a **Timeout at 120 s** that is not a hang: with `--timeout 400` it passes in **212 s** | | ||
| 65 | |||
| 66 | `d3d12_subgroup` is the most serious: a crash in device slot 14's console-layout heuristic ([#1328](https://github.com/ubiquitarianism/leonida/pull/1328)) that depended on adjacent stack words, which is why neither the `clang-cl` Wine build nor a second MSVC build on the same Pascal 4 GB class hit it. `xdxr_build_check` costs a full-suite run two minutes of wall clock and a false fail on this card; 212 s on a 4 GB Pascal for a DXR build is a plausible ceiling for any low-end machine. | ||
| 67 | |||
| 68 | ## Reading it | ||
| 69 | |||
| 70 | - A native pass does not mean the Wine report was wrong: it means the missing piece was Wine. Both runs stay useful. | ||
| 71 | - Skipped here are 18 (7 retail-package skips plus 11 validation, DXR, conservative-tier-3 and mesh-shader skips); the Wine run skipped 40 for its own reasons. A skip is neither a pass nor a fail and the percentages do not compare one for one. | ||
| 72 | - This run was from an interactive desktop session, where `xgameruntime_offline` and `xgameruntime_offline_hdr` pass (`0.11 s` and `0.03 s`); over a non-interactive SSH session they fail `XDisplayAcquireTimeoutDeferral`. | ||
| 73 | - The implicit Vulkan layers were disabled (`VK_LOADER_LAYERS_DISABLE=~implicit~`): this machine has OBS and RenderDoc layers installed. | ||
| 74 | |||
| 75 | ## Re-measured on `main` `d1dff794` (27 November 2026) | ||
| 76 | |||
| 77 | Two days later, same card and same Windows 10 19045 host, five rows of the tables above re-run three times each | ||
| 78 | (`ctest -R '^name$' --timeout 300`). This is a targeted re-run, not a new full-suite figure: the counts in "The two | ||
| 79 | runs" still describe `58be9cdf`. | ||
| 80 | |||
| 81 | | Test | 25 November | 27 November, `main` `d1dff794` | Covers it now | | ||
| 82 | |---|---|---|---| | ||
| 83 | | `d3d12_subresource_copy` | failed, line 391 (`CPU copies (host image copy): the steps differ from the host's`) | **passes 3/3** (0.55–0.56 s) | [#1364](https://github.com/ubiquitarianism/leonida/pull/1364), merged 24 November | | ||
| 84 | | `d3d12_r9g9b9e5_uav` | failed, line 669 (CPU-heap `HOST_TRANSFER` texture gets `E_OUTOFMEMORY`) | **passes 3/3** (0.31–0.32 s) | [#1364](https://github.com/ubiquitarianism/leonida/pull/1364) | | ||
| 85 | | `d3d12_existing_heap` | failed, line 196 (`0x80004001`) | still fails 3/3; each run logs `texture memory unavailable: 2048 bytes, alignment 1024, type bits 0x0 (vk format 9 256x8)` twice | [#1894](https://github.com/ubiquitarianism/leonida/pull/1894): with its head `2d258c8c` applied to this tree the test passes 3/3 and each run logs `title image has no host-transfer memory type, using staging for Vulkan format` | | ||
| 86 | | `d3d12_heap_properties` | failed on the `0x8007000e` CPU-heap rows | still fails 3/3, now on exactly two rows: `placed buffer` and `placed texture, DEFAULT heap, ALLOW_ALL` give `0x0` in the layer and `0x80070057` on the host | [#1389](https://github.com/ubiquitarianism/leonida/pull/1389) | | ||
| 87 | | `d3d12_vulkan_device` | failed (the `CreateHeap` comparison) | still fails 3/3; the last compared row is now `invalid arguments heap: HARDWARE_PROTECTED: an older host runtime (Windows 10, Windows 11 23H2) refuses it (ours 0x00000000, host 0x80070057)` | [#1389](https://github.com/ubiquitarianism/leonida/pull/1389) | | ||
| 88 | |||
| 89 | Both remaining `d3d12_heap_properties` rows are the same host fact. This GPU reports | ||
| 90 | `D3D12_RESOURCE_HEAP_TIER_1`, and `D3D12_HEAP_FLAG_ALLOW_ALL_BUFFERS_AND_TEXTURES` (the value `0`, no `DENY` flag) is | ||
| 91 | heap tier 2 and greater only, so the host refuses the two `ALLOW_ALL` cases with `E_INVALIDARG` while the | ||
| 92 | `ALLOW_ONLY_*` rows match. The layer accepts them because the console it imitates is tier 2; what has to change is the | ||
| 93 | host comparison in the test, which is what #1389 does. | ||
| 94 | |||
| 95 | The `HARDWARE_PROTECTED` row is the same kind of host gate: Windows 10's `d3d12.dll` refuses the flag with | ||
| 96 | `E_INVALIDARG`, and the layer, like the console, accepts it. Also #1389. | ||
| 97 | |||
| 98 | `d3d12_existing_heap` is not a heap-flag case. The layer builds the title's 256x8 Vulkan format-9 image (2048 bytes, | ||
| 99 | alignment 1024), finds no host-transfer memory type for it and the placed import fails; #1894 stages that upload. The | ||
| 100 | sub-page host buffer imports named above for this test ([#1458](https://github.com/ubiquitarianism/leonida/pull/1458)) | ||
| 101 | are a different path and are still open. | ||
| 102 | |||
| 103 | ## What follows | ||
| 104 | |||
| 105 | The 5 reproduced and the 6 native-only are the actionable list (5 + 6 = 11 failures). Since this run: [#1364](https://github.com/ubiquitarianism/leonida/pull/1364) fixed the Pascal `HOST_TRANSFER` CPU-heap image failure behind `d3d12_subresource_copy`, `d3d12_r9g9b9e5_uav` and the `0x8007000e` rows of `d3d12_heap_properties` and `d3d12_vulkan_device`; open pull requests cover the remaining host-tier-1 heap comparisons ([#1389](https://github.com/ubiquitarianism/leonida/pull/1389)), sub-page host buffer imports on 256-byte UBO GPUs (`d3d12_existing_heap`, [#1458](https://github.com/ubiquitarianism/leonida/pull/1458)), `d3d12_subgroup` ([#1328](https://github.com/ubiquitarianism/leonida/pull/1328)), `d3d12_set_descriptor_heaps` ([#1353](https://github.com/ubiquitarianism/leonida/pull/1353)), `root_signature_oracle` ([#988](https://github.com/ubiquitarianism/leonida/pull/988)), `d3d12_close_parity` ([#989](https://github.com/ubiquitarianism/leonida/pull/989)), `d3d12_pso_validation` ([#967](https://github.com/ubiquitarianism/leonida/pull/967), [#1377](https://github.com/ubiquitarianism/leonida/pull/1377)), and `xdxr_build_check`'s timeout ([#1424](https://github.com/ubiquitarianism/leonida/pull/1424)). | ||
diff --git a/docs/test_inventory.md b/docs/test_inventory.md new file mode 100644 index 000000000..a4a874912 --- /dev/null +++ b/docs/test_inventory.md | |||
| @@ -0,0 +1,41 @@ | |||
| 1 | # Synthetic Test Inventory & Subsystem Map (DX-10) | ||
| 2 | |||
| 3 | This document provides the authoritative subsystem test map and prerequisite catalog for Leonida, implemented under roadmap task **DX-10**. | ||
| 4 | |||
| 5 | ## Overview | ||
| 6 | |||
| 7 | `tools/test_inventory.py` dynamically discovers source test modules across `tests/` and `runtime/test/` (skipping bytecode caches like `__pycache__` and matching `scripts/run_semantic_tests.py` package discovery rules inside `tests/semantic/`). Over 99% of test files are synthetic and run without retail game packages, executables, or proprietary assets. | ||
| 8 | |||
| 9 | ```bash | ||
| 10 | # Generate the full subsystem breakdown and metrics | ||
| 11 | python -I tools/test_inventory.py --summary | ||
| 12 | |||
| 13 | # Output machine-readable JSON inventory | ||
| 14 | python -I tools/test_inventory.py --json | ||
| 15 | |||
| 16 | # Filter tests by subsystem (runtime, shader, tools, viewer) | ||
| 17 | python -I tools/test_inventory.py --subsystem shader | ||
| 18 | |||
| 19 | # Display tests mentioning retail package environment variables (tagged optional vs required) | ||
| 20 | python -I tools/test_inventory.py --gaps | ||
| 21 | ``` | ||
| 22 | |||
| 23 | ## Subsystems | ||
| 24 | |||
| 25 | - **`shader`**: RDNA2 -> SPIR-V translator, float ALU rounding, vector compares, atomics, mesh/wave64 dispatch (`python_unittest`). | ||
| 26 | - **`tools`**: Asset exporters, PE inspection, manifest checkers, BCPack/texture swizzlers, developer scripts (`python_unittest`, `pytest`). | ||
| 27 | - **`runtime`**: D3D12/Vulkan shims, PE loader, root signature parser, XMA2 audio shims, memory and descriptor heaps (`ctest_cpp`). | ||
| 28 | - **`viewer`**: Map viewer HTTP streaming, LOD residency handoffs, camera positioning, world grid chunking (`python_unittest`, `node_test`). | ||
| 29 | |||
| 30 | ## Runners | ||
| 31 | |||
| 32 | - **`python_unittest`**: Pure standard-library Python test suites runnable with `python -I`. | ||
| 33 | - **`ctest_cpp`**: Native C++20 tests built with CMake/Ninja under `runtime/build/`. | ||
| 34 | - **`pytest`**: Tests requiring the virtual environment dependencies pinned in `tests/requirements.txt`. | ||
| 35 | - **`node_test`**: Viewer streaming protocol tests running under Node.js (`node --test`). | ||
| 36 | |||
| 37 | ## Retail-Gated & Optional Retail Checks (`--gaps`) | ||
| 38 | |||
| 39 | `--gaps` surfaces files mentioning `LEONIDA_GAME_DIR`, `LEONIDA_MOVIE`, or `requires_retail_package`, labelling them with `retail_requirement`: | ||
| 40 | - **`optional`**: Tests whose primary suite runs synthetically and only execute an optional retail leg when `LEONIDA_GAME_DIR`/`LEONIDA_MOVIE` is set (printing `SKIP` otherwise, such as `pe_loader_test.cpp`). These still count toward `synthetic` coverage. | ||
| 41 | - **`required`**: Tests strictly gated on retail package prerequisites. | ||
diff --git a/docs/testing.md b/docs/testing.md index d62a0cf99..e84313891 100644 --- a/docs/testing.md +++ b/docs/testing.md | |||
| @@ -701,13 +701,13 @@ for every pull request that touches the runtime, the scripts or a tool the jobs | |||
| 701 | lists them), and you can do the same on Linux without a GPU: | 701 | lists them), and you can do the same on Linux without a GPU: |
| 702 | 702 | ||
| 703 | ```sh | 703 | ```sh |
| 704 | sudo apt-get install -y libvulkan-dev mesa-vulkan-drivers vulkan-tools spirv-tools llvm-19 | 704 | sudo apt-get install -y libvulkan-dev mesa-vulkan-drivers vulkan-tools spirv-tools llvm-21 |
| 705 | cmake -S runtime -B runtime/build/linux && cmake --build runtime/build/linux --parallel | 705 | cmake -S runtime -B runtime/build/linux && cmake --build runtime/build/linux --parallel |
| 706 | python -I scripts/run_gpu_tests.py --build runtime/build/linux --llvm-mc /usr/lib/llvm-19/bin/llvm-mc | 706 | python -I scripts/run_gpu_tests.py --build runtime/build/linux --llvm-mc /usr/lib/llvm-21/bin/llvm-mc |
| 707 | LEONIDA_W64_EMULATE=1 python -I scripts/run_gpu_tests.py --build runtime/build/linux \ | 707 | LEONIDA_W64_EMULATE=1 python -I scripts/run_gpu_tests.py --build runtime/build/linux \ |
| 708 | --llvm-mc /usr/lib/llvm-19/bin/llvm-mc --filter cs_ | 708 | --llvm-mc /usr/lib/llvm-21/bin/llvm-mc --filter cs_ |
| 709 | LEONIDA_BARY_FALLBACK=1 python -I scripts/run_gpu_tests.py --build runtime/build/linux \ | 709 | LEONIDA_BARY_FALLBACK=1 python -I scripts/run_gpu_tests.py --build runtime/build/linux \ |
| 710 | --llvm-mc /usr/lib/llvm-19/bin/llvm-mc | 710 | --llvm-mc /usr/lib/llvm-21/bin/llvm-mc |
| 711 | ``` | 711 | ``` |
| 712 | 712 | ||
| 713 | With Mesa 25.2 (llvmpipe, LLVM 20) the first run passes 52 of 88 and skips 36, the second passes 37 of 39 and | 713 | With Mesa 25.2 (llvmpipe, LLVM 20) the first run passes 52 of 88 and skips 36, the second passes 37 of 39 and |
| @@ -736,7 +736,7 @@ differences. | |||
| 736 | ## Macs in CI | 736 | ## Macs in CI |
| 737 | 737 | ||
| 738 | The `macos` job in `.github/workflows/runtime.yml` builds the runtime on GitHub's `macos-26` arm64 runner and runs | 738 | The `macos` job in `.github/workflows/runtime.yml` builds the runtime on GitHub's `macos-26` arm64 runner and runs |
| 739 | `ctest` and `run_gpu_tests.py` on MoltenVK; `macos-python` in `ci.yml` runs the Python suites. The runner is a VM | 739 | `ctest` and `run_gpu_tests.py` on MoltenVK on pushes to `main`, the daily schedule, and `workflow_dispatch`. The runner is a VM |
| 740 | whose Metal device is "Apple Paravirtual device" (Metal family Mac2, not Apple7): MoltenVK runs on it with 32-wide | 740 | whose Metal device is "Apple Paravirtual device" (Metal family Mac2, not Apple7): MoltenVK runs on it with 32-wide |
| 741 | subgroups, so the wave64 and "32 lanes on request" tests skip there (about 75 of 190 in November 2026), and Mesa's | 741 | subgroups, so the wave64 and "32 lanes on request" tests skip there (about 75 of 190 in November 2026), and Mesa's |
| 742 | KosmicKrisp finds no device. `macos-15` can't build the runtime: Xcode 16's libc++ has no floating-point | 742 | KosmicKrisp finds no device. `macos-15` can't build the runtime: Xcode 16's libc++ has no floating-point |
| @@ -899,6 +899,7 @@ game's device ignores it`, so leaving them set cannot slow a game down (`run_tin | |||
| 899 | | On RADV with Mesa 25.2 (Ubuntu 24.04's default; 25.2.8 measured) or 25.3 (from the source, not run), `cs_w32_salu64` fails with word 2 = `0` (want `0xFFFFFFFF`) and `cs_signed_zero_nan` fails with word 5 = `0` (want `1`). The `cs_signed_zero_nan` failure alone is also measured on RADV 25.0.7 (RX 7800 XT, Debian 13; @mrbean56, #4421) and on ANV 25.2.8 (Intel UHD 630; @theswiss24, #4571); llvmpipe on Mesa 26.0.8 (Ubuntu 26.04) still gives word 5 = `0`, which `check.py` does not judge there (`UNJUDGED_WORDS`) | Two Mesa bugs, not translator bugs (#166). `cs_w32_salu64`: ACO's `combine_add_sub_b2i` reads a temporary without counting the use, so dead-code elimination removes it (`ACO ERROR: ... never defined` with `MESA_SHADER_CACHE_DISABLE=true`); `RADV_DEBUG=llvm` passes. `cs_signed_zero_nan`: NIR's range analysis (`fmul_is_a_number`) calls `0 * x` a number when `x` may be infinite, so the `x != x` check folds to false despite `SignedZeroInfNanPreserve`. The same NIR code is behind llvmpipe's word 5 (#664) and ANV's, since both drivers run NIR; `cs_w32_salu64` is ACO's, so only RADV has it | Expected with these Mesa versions. From the source, the ACO function is gone from Mesa 26.0 and the NIR code was replaced in 26.1 (neither run); RADV from Mesa 26.3.1 passes both on an 8060S (gfx1151) | | 899 | | On RADV with Mesa 25.2 (Ubuntu 24.04's default; 25.2.8 measured) or 25.3 (from the source, not run), `cs_w32_salu64` fails with word 2 = `0` (want `0xFFFFFFFF`) and `cs_signed_zero_nan` fails with word 5 = `0` (want `1`). The `cs_signed_zero_nan` failure alone is also measured on RADV 25.0.7 (RX 7800 XT, Debian 13; @mrbean56, #4421) and on ANV 25.2.8 (Intel UHD 630; @theswiss24, #4571); llvmpipe on Mesa 26.0.8 (Ubuntu 26.04) still gives word 5 = `0`, which `check.py` does not judge there (`UNJUDGED_WORDS`) | Two Mesa bugs, not translator bugs (#166). `cs_w32_salu64`: ACO's `combine_add_sub_b2i` reads a temporary without counting the use, so dead-code elimination removes it (`ACO ERROR: ... never defined` with `MESA_SHADER_CACHE_DISABLE=true`); `RADV_DEBUG=llvm` passes. `cs_signed_zero_nan`: NIR's range analysis (`fmul_is_a_number`) calls `0 * x` a number when `x` may be infinite, so the `x != x` check folds to false despite `SignedZeroInfNanPreserve`. The same NIR code is behind llvmpipe's word 5 (#664) and ANV's, since both drivers run NIR; `cs_w32_salu64` is ACO's, so only RADV has it | Expected with these Mesa versions. From the source, the ACO function is gone from Mesa 26.0 and the NIR code was replaced in 26.1 (neither run); RADV from Mesa 26.3.1 passes both on an 8060S (gfx1151) | |
| 900 | | On an Intel iGPU with ANV from Mesa 25.2 (25.2.8 measured), `cs_fmt_int_narrow` fails with word 34 = `0x00000000` (want `0xFFFFFFFF`); the full dump also has words 49 and 129 = `0x80000000` (want `0x8000FFFF`), natively and under `LEONIDA_W64_EMULATE=1` alike (`check.py`'s comparison stops at the first mismatch, so its line names only word 34). Measured on Gen9 at subgroup sizes 8, 16 and 32 alike (UHD 630, CFL GT2; TEST-1000), and on an Arrow Lake-H Arc 140T (device subgroup 8–32; `Intel(R) Graphics (ARL)`, Xe2; ANV 25.2.8-0ubuntu0.24.04.5, Vulkan 1.4.318) | A Mesa bug, not a translator bug (TEST-1000). The fixture's second source dword `0x8000FFFF` reaches the SSBO as `0x80000000`: the translated module holds it as one `OpConstant %uint` stored by a single dword `OpStore` to PhysicalStorageBuffer, no float operation on the path, yet the raw buffer readback (word 129) shows its low halfword `0xffff` zeroed and its high halfword `0x8000` intact — the bit pattern is a negative f32 denormal and it comes back as `-0`, as if flushed. Words 34 and 49 are a correct `16_16_16_16_SINT` load of the corrupted dword (the neighbouring channels sign-extend correctly). The module requests `DenormPreserve 16` and `SignedZeroInfNanPreserve 32`, not `DenormPreserve 32`, and the same module passes 136/136 on gfx1036 (native `hw_oracle`), llvmpipe, an RTX 2060 SUPER, 5060 Laptop and 5080, an RX 7900 XTX under RADV, Xe-LP (UHD 770, ANV 26.3.1) and Meteor Lake (ANV 26.2.7); adding `OpExecutionMode DenormPreserve 32` by hand fixes all 136 words on both Gen9 and the Arc 140T | Expected with this Mesa. Don't add `DenormPreserve 32` to the translator for it: the game runs f32 denormals flushed (`denorm_mode_32 = 0`, docs/design.md) and the translator leaves denormal handling to the driver. A newer Mesa passes (26.2.7 on Meteor Lake, 26.3.1 on Xe-LP); Gen9 and the Arc 140T with a newer Mesa not run | | 900 | | On an Intel iGPU with ANV from Mesa 25.2 (25.2.8 measured), `cs_fmt_int_narrow` fails with word 34 = `0x00000000` (want `0xFFFFFFFF`); the full dump also has words 49 and 129 = `0x80000000` (want `0x8000FFFF`), natively and under `LEONIDA_W64_EMULATE=1` alike (`check.py`'s comparison stops at the first mismatch, so its line names only word 34). Measured on Gen9 at subgroup sizes 8, 16 and 32 alike (UHD 630, CFL GT2; TEST-1000), and on an Arrow Lake-H Arc 140T (device subgroup 8–32; `Intel(R) Graphics (ARL)`, Xe2; ANV 25.2.8-0ubuntu0.24.04.5, Vulkan 1.4.318) | A Mesa bug, not a translator bug (TEST-1000). The fixture's second source dword `0x8000FFFF` reaches the SSBO as `0x80000000`: the translated module holds it as one `OpConstant %uint` stored by a single dword `OpStore` to PhysicalStorageBuffer, no float operation on the path, yet the raw buffer readback (word 129) shows its low halfword `0xffff` zeroed and its high halfword `0x8000` intact — the bit pattern is a negative f32 denormal and it comes back as `-0`, as if flushed. Words 34 and 49 are a correct `16_16_16_16_SINT` load of the corrupted dword (the neighbouring channels sign-extend correctly). The module requests `DenormPreserve 16` and `SignedZeroInfNanPreserve 32`, not `DenormPreserve 32`, and the same module passes 136/136 on gfx1036 (native `hw_oracle`), llvmpipe, an RTX 2060 SUPER, 5060 Laptop and 5080, an RX 7900 XTX under RADV, Xe-LP (UHD 770, ANV 26.3.1) and Meteor Lake (ANV 26.2.7); adding `OpExecutionMode DenormPreserve 32` by hand fixes all 136 words on both Gen9 and the Arc 140T | Expected with this Mesa. Don't add `DenormPreserve 32` to the translator for it: the game runs f32 denormals flushed (`denorm_mode_32 = 0`, docs/design.md) and the translator leaves denormal handling to the driver. A newer Mesa passes (26.2.7 on Meteor Lake, 26.3.1 on Xe-LP); Gen9 and the Arc 140T with a newer Mesa not run | |
| 901 | | Every test crashes inside `libnvidia-eglcore.so` | NVIDIA's 535 server driver (Ubuntu 24.04's default) | Use driver 615 or newer | | 901 | | Every test crashes inside `libnvidia-eglcore.so` | NVIDIA's 535 server driver (Ubuntu 24.04's default) | Use driver 615 or newer | |
| 902 | | The synthetic `cs_imgstore_cube` test reports 63 bad `r32 sint` texels on a Tesla V100-SXM2-16GB (Volta, NVIDIA 580.178.04, Linux; Vulkan 1.4.312; [#1492](https://github.com/ubiquitarianism/leonida/issues/1492)) | The signed 32-bit cube-storage-write failure is known on that reported host, but its cause has not been isolated. It passes on an RTX 5090 with NVIDIA 621.14 on Windows 11 | No workaround is confirmed. Keep the test's expected values; report the GPU, driver and output if you reproduce it on another setup | | ||
| 902 | | `build.py`: 0 translated, reason `.text` | An old `build.py` with LLVM 19 | Update to current `main` | | 903 | | `build.py`: 0 translated, reason `.text` | An old `build.py` with LLVM 19 | Update to current `main` | |
| 903 | | `vk_harness` doesn't compile: `VK_KHR_maintenance8` names unknown | Vulkan headers older than the SDK the code was written against | Update to current `main` (the code now builds without it), or use current Khronos Vulkan-Headers; conda-forge's package is too old | | 904 | | `vk_harness` doesn't compile: `VK_KHR_maintenance8` names unknown | Vulkan headers older than the SDK the code was written against | Update to current `main` (the code now builds without it), or use current Khronos Vulkan-Headers; conda-forge's package is too old | |
| 904 | | Configure stops with "Vulkan headers too old: ... VK_HEADER_VERSION N" (before: the build stopped at `d3d12_com.h(42): error C3646: 'calibrated': unknown override specifier` and 100+ errors in `d3d12_vulkan_device.cpp`, or at `VkPhysicalDevicePipelineBinaryFeaturesKHR` in `vk_harness.cpp`) | The Windows runtime found Vulkan headers older than v1.3.294 (`runtime/cmake/vulkan_headers_version.cmake`). conda-forge's `vulkan-headers` resolves to 1.3.231 next to `llvm-tools`. Measured on MSVC 14.51: v1.3.294 builds every target, SDK 1.3.280.0 all but `vk_harness` (`VK_KHR_pipeline_binary` is new in v1.3.294), 1.3.231 stops in the D3D12 layer | Point `VULKAN_SDK` at a Vulkan SDK from 1.3.296.0 on or current Khronos Vulkan-Headers, then delete `CMakeCache.txt`; or pass `-DLEONIDA_VULKAN_HEADERS_FETCH=ON` with no other headers installed | | 905 | | Configure stops with "Vulkan headers too old: ... VK_HEADER_VERSION N" (before: the build stopped at `d3d12_com.h(42): error C3646: 'calibrated': unknown override specifier` and 100+ errors in `d3d12_vulkan_device.cpp`, or at `VkPhysicalDevicePipelineBinaryFeaturesKHR` in `vk_harness.cpp`) | The Windows runtime found Vulkan headers older than v1.3.294 (`runtime/cmake/vulkan_headers_version.cmake`). conda-forge's `vulkan-headers` resolves to 1.3.231 next to `llvm-tools`. Measured on MSVC 14.51: v1.3.294 builds every target, SDK 1.3.280.0 all but `vk_harness` (`VK_KHR_pipeline_binary` is new in v1.3.294), 1.3.231 stops in the D3D12 layer | Point `VULKAN_SDK` at a Vulkan SDK from 1.3.296.0 on or current Khronos Vulkan-Headers, then delete `CMakeCache.txt`; or pass `-DLEONIDA_VULKAN_HEADERS_FETCH=ON` with no other headers installed | |
| @@ -918,6 +919,8 @@ game's device ignores it`, so leaving them set cannot slow a game down (`run_tin | |||
| 918 | | On a Mac, `valu_fuzz.py --family f16` reads `+0` where the model wants `-0`, from a multiply whose exact product is -0 (`v_mul_f16`, `v_pk_mul_f16`) or from an FMA whose product and addend are both -0 (`v_fma_f16`, `v_fmac_f16`, `v_pk_fma_f16`) | MoltenVK computes a `NoContraction` multiply as `fma(l, r, +0)`, which drops the sign. MoltenVK 1.4.2 and `main` up to at least `5189f8de` are affected (SHADER-182, [design notes](design.md#translator-status-and-runtime-contract)) | Expected with these MoltenVK versions. To run the rest of the fuzzer clean, add `--skip-op` for each of the five ops. To see them match, install Homebrew's `mesa` and use its KosmicKrisp driver: `LEONIDA_VULKAN_LOADER=/opt/homebrew/opt/vulkan-loader/lib/libvulkan.1.dylib VK_DRIVER_FILES=/opt/homebrew/share/vulkan/icd.d/kosmickrisp_mesa_icd.aarch64.json python3 -I tools/valu_fuzz.py --family f16 --build runtime/build/linux`. Or build MoltenVK with SPIRV-Cross `300681bb` or newer in `ExternalRevisions/SPIRV-Cross_repo_revision`, and point `LEONIDA_VULKAN_LOADER` at its `libMoltenVK.dylib` | | 919 | | On a Mac, `valu_fuzz.py --family f16` reads `+0` where the model wants `-0`, from a multiply whose exact product is -0 (`v_mul_f16`, `v_pk_mul_f16`) or from an FMA whose product and addend are both -0 (`v_fma_f16`, `v_fmac_f16`, `v_pk_fma_f16`) | MoltenVK computes a `NoContraction` multiply as `fma(l, r, +0)`, which drops the sign. MoltenVK 1.4.2 and `main` up to at least `5189f8de` are affected (SHADER-182, [design notes](design.md#translator-status-and-runtime-contract)) | Expected with these MoltenVK versions. To run the rest of the fuzzer clean, add `--skip-op` for each of the five ops. To see them match, install Homebrew's `mesa` and use its KosmicKrisp driver: `LEONIDA_VULKAN_LOADER=/opt/homebrew/opt/vulkan-loader/lib/libvulkan.1.dylib VK_DRIVER_FILES=/opt/homebrew/share/vulkan/icd.d/kosmickrisp_mesa_icd.aarch64.json python3 -I tools/valu_fuzz.py --family f16 --build runtime/build/linux`. Or build MoltenVK with SPIRV-Cross `300681bb` or newer in `ExternalRevisions/SPIRV-Cross_repo_revision`, and point `LEONIDA_VULKAN_LOADER` at its `libMoltenVK.dylib` | |
| 919 | | A pixel shader exporting non-canonical f32 NaNs reads back `0x7fc00000` from an RGBA32F color attachment | KosmicKrisp (Mesa 26.3.1), reproduced on Apple M3 Max, M2 Ultra and M1 Pro ([#3125](https://github.com/ItsNotRexed/Leonida/issues/3125)): `nir_to_msl` emits `(NAN)` for `float`-typed NaN constants (`MESA_KK_DEBUG=msl`); MoltenVK 1.4.2 preserved both tested payloads on the same hardware | `ps_nan_payload` allows the measured canonical word only for the NaN channels and only when `vk_harness` reports `driver: KosmicKrisp`. Finite channels and other drivers still require exact words. Integer or storage-buffer readback still canonicalizes constants that NIR infers as `float` (see the `cs_bvh` row below). | | 920 | | A pixel shader exporting non-canonical f32 NaNs reads back `0x7fc00000` from an RGBA32F color attachment | KosmicKrisp (Mesa 26.3.1), reproduced on Apple M3 Max, M2 Ultra and M1 Pro ([#3125](https://github.com/ItsNotRexed/Leonida/issues/3125)): `nir_to_msl` emits `(NAN)` for `float`-typed NaN constants (`MESA_KK_DEBUG=msl`); MoltenVK 1.4.2 preserved both tested payloads on the same hardware | `ps_nan_payload` allows the measured canonical word only for the NaN channels and only when `vk_harness` reports `driver: KosmicKrisp`. Finite channels and other drivers still require exact words. Integer or storage-buffer readback still canonicalizes constants that NIR infers as `float` (see the `cs_bvh` row below). | |
| 920 | | `cs_bvh` and `cs_bvh32` fail on a Mac with KosmicKrisp: `out[3]` reads `0x7fc00000`, want `0xffffffff` | KosmicKrisp's `nir_to_msl` compiler (Mesa 26.3.1, measured on Apple M2 Ultra, macOS 27.3), not the translator or the buffer format. The triangle branch writes bitcast `float` words and the box branch writes `OpSelect %uint` with `0xffffffff` (`-1`) into the same VGPRs; NIR erases `OpBitcast`, type inference marks the shared register and `bcsel` as `float`, and `nir_to_msl` prints any `float`-typed 32-bit constant in the IEEE-754 NaN range (`0x7f800001..0x7fffffff`, `0xff800001..0xffffffff`) as `(NAN)` (`0x7fc00000`) | Expected with KosmicKrisp in Mesa 26.3.1; MoltenVK 1.4.2 and llvmpipe (Mesa 26.3.1) return `0xffffffff` on the same machine. Do not weaken `vk_compute_test`'s expected BVH words | | 921 | | `cs_bvh` and `cs_bvh32` fail on a Mac with KosmicKrisp: `out[3]` reads `0x7fc00000`, want `0xffffffff` | KosmicKrisp's `nir_to_msl` compiler (Mesa 26.3.1, measured on Apple M2 Ultra, macOS 27.3), not the translator or the buffer format. The triangle branch writes bitcast `float` words and the box branch writes `OpSelect %uint` with `0xffffffff` (`-1`) into the same VGPRs; NIR erases `OpBitcast`, type inference marks the shared register and `bcsel` as `float`, and `nir_to_msl` prints any `float`-typed 32-bit constant in the IEEE-754 NaN range (`0x7f800001..0x7fffffff`, `0xff800001..0xffffffff`) as `(NAN)` (`0x7fc00000`) | Expected with KosmicKrisp in Mesa 26.3.1; MoltenVK 1.4.2 and llvmpipe (Mesa 26.3.1) return `0xffffffff` on the same machine. Do not weaken `vk_compute_test`'s expected BVH words | |
| 922 | | `ps_cndmask_sign_mods` fails on a Mac with KosmicKrisp: all 4096 pixels differ, `(0,0)` reads `0x7fc00000, 0x7fc00000, 0x80000001, 0x7fc00000`, want `0xff800001, 0x7f800001, 0x80000001, 0x7f800001` | The same `nir_to_msl` NaN-constant path as `cs_bvh` above: the shader selects between `float` NaNs with sign and payload (`-NaN`, `+NaN`), and KosmicKrisp prints each such constant as `(NAN)` (`0x7fc00000`). Measured on an Apple M3, macOS 27.0, Mesa 26.3.1 | Expected with KosmicKrisp; the same test passes 4096/4096 on llvmpipe (Mesa 26.3.1) and on MoltenVK 1.4.2 on the same machine | | ||
| 923 | | `ps_valu16_mad_sel` fails on a Mac with KosmicKrisp: all 4096 pixels differ, `(0,0)` reads `0x8003, 0xdb880000, 0x7fc00000, 0x80000000`, want `0x8003, 0xdb880000, 0xffffffff, 0x80000000` | Same cause: a value the shader writes as `0xffffffff` (`-1`) reaches the render target as `0x7fc00000` because `nir_to_msl` types the shared register as `float` and prints the NaN-range constant as `(NAN)`. Measured on an Apple M3, macOS 27.0, Mesa 26.3.1 | Expected with KosmicKrisp; passes 4096/4096 on llvmpipe (Mesa 26.3.1) and on MoltenVK 1.4.2 on the same machine | | ||
| 921 | | `cs_fma_fused` fails on a Mac with KosmicKrisp: word 7 reads `0x7352`, want `0x7351` | The f16 multiply-add (round to odd), computed at run time, comes out as if the product were rounded first: the exact product, 14988, is halfway between the f16 values 14984 (`0x7351`) and 14992 (`0x7352`), the addend is -2^-22, and one rounding gives `0x7351`. Measured on an Apple M3 with Mesa 26.3.1, 20 of 20 runs (the review of #1724). While the fixture's f16 operands were literals the constant was folded exactly, so the test passed there | Expected with KosmicKrisp in Mesa 26.3.1; MoltenVK 1.4.2 and llvmpipe (Mesa 26.3.1) give `0x7351` on the same machine. The f32 words KosmicKrisp splits are accepted under `--fma glsl`; the f16 word is not, since it does not use `Fma` | | 924 | | `cs_fma_fused` fails on a Mac with KosmicKrisp: word 7 reads `0x7352`, want `0x7351` | The f16 multiply-add (round to odd), computed at run time, comes out as if the product were rounded first: the exact product, 14988, is halfway between the f16 values 14984 (`0x7351`) and 14992 (`0x7352`), the addend is -2^-22, and one rounding gives `0x7351`. Measured on an Apple M3 with Mesa 26.3.1, 20 of 20 runs (the review of #1724). While the fixture's f16 operands were literals the constant was folded exactly, so the test passed there | Expected with KosmicKrisp in Mesa 26.3.1; MoltenVK 1.4.2 and llvmpipe (Mesa 26.3.1) give `0x7351` on the same machine. The f32 words KosmicKrisp splits are accepted under `--fma glsl`; the f16 word is not, since it does not use `Fma` | |
| 922 | | CMake stops with "needs the Windows SDK 10.0.26100 or newer", or MSVC reports `'Desc_1_2': is not a member of 'D3D12_VERSIONED_ROOT_SIGNATURE_DESC'` | A Windows SDK older than 10.0.26100 (10.0.22621 is the common one), which has no version 1.2 root signatures | `winget install Microsoft.WindowsSDK.10.0.26100`, or add it in the Visual Studio Installer, then delete `runtime/build` and configure again | | 925 | | CMake stops with "needs the Windows SDK 10.0.26100 or newer", or MSVC reports `'Desc_1_2': is not a member of 'D3D12_VERSIONED_ROOT_SIGNATURE_DESC'` | A Windows SDK older than 10.0.26100 (10.0.22621 is the common one), which has no version 1.2 root signatures | `winget install Microsoft.WindowsSDK.10.0.26100`, or add it in the Visual Studio Installer, then delete `runtime/build` and configure again | |
| 923 | | `scripts/build_runtime.ps1` stops at once: "The checkout path ... contains '%'" (`build_llvm_mc.ps1`: "-Temp ... contains '%'") | A `%` in the checkout's path (or in `-Temp`). cmd.exe expands `%...%` in the generated `_build.cmd` (twice on a `CALL` line), and even with that escaped, `cl` rejects a `%` in the path-valued `/D` definitions of the test targets (`D8038: invalid argument`) however it is quoted. Older scripts failed in configure or a few hundred steps into Ninja instead | Move or clone the checkout (or choose a `-Temp`) in a folder without `%` in its path | | 926 | | `scripts/build_runtime.ps1` stops at once: "The checkout path ... contains '%'" (`build_llvm_mc.ps1`: "-Temp ... contains '%'") | A `%` in the checkout's path (or in `-Temp`). cmd.exe expands `%...%` in the generated `_build.cmd` (twice on a `CALL` line), and even with that escaped, `cl` rejects a `%` in the path-valued `/D` definitions of the test targets (`D8038: invalid argument`) however it is quoted. Older scripts failed in configure or a few hundred steps into Ninja instead | Move or clone the checkout (or choose a `-Temp`) in a folder without `%` in its path | |