diff options
| author | Tauwni <102470988+Tauwni@users.noreply.github.com> | 2026-11-26 04:01:08 +0100 |
|---|---|---|
| committer | Tauwni <102470988+Tauwni@users.noreply.github.com> | 2026-11-26 04:01:08 +0100 |
| commit | 5af6cd3d69dc69baec78aa06fc418fc4bcbf83b5 (patch) | |
| tree | 4529bc04eac714e9c393fb1085bb1d67169843c0 /docs | |
| parent | 459cbb9b19193ffd4fbb18442497bc885de8c728 (diff) | |
| parent | 7f3d0095a2d51892bc7048f24505c37168f25c34 (diff) | |
Merge remote-tracking branch 'origin/main' into gpu-results-m3
# Conflicts:
# docs/gpu_test_results.md
Diffstat (limited to 'docs')
42 files changed, 1387 insertions, 189 deletions
diff --git a/docs/README.md b/docs/README.md index 685634912..1e4aaa2e4 100644 --- a/docs/README.md +++ b/docs/README.md | |||
| @@ -69,7 +69,7 @@ method, scope and caveats. No game data is included. | |||
| 69 | | [mobile.md](mobile.md) | arm64/mobile path: the x86-64 → arm64 static-recompiler groundwork (`tools/x64_recomp.py`), the `.pdata` coverage census (`tools/recomp_census.py`), and what still blocks iOS. | | 69 | | [mobile.md](mobile.md) | arm64/mobile path: the x86-64 → arm64 static-recompiler groundwork (`tools/x64_recomp.py`), the `.pdata` coverage census (`tools/recomp_census.py`), and what still blocks iOS. | |
| 70 | | [first_run_ui.md](first_run_ui.md) | Build the Windows integration and display the offline first-run controller prompts. | | 70 | | [first_run_ui.md](first_run_ui.md) | Build the Windows integration and display the offline first-run controller prompts. | |
| 71 | | [boot.md](boot.md) | The first real boot: the `gta6rt --trace`/`--trace-d3d12` runbook, the startup + D3D12 trace summary (`tools/boot_trace.py`), the triage order and the Q1–Q22 checklist. | | 71 | | [boot.md](boot.md) | The first real boot: the `gta6rt --trace`/`--trace-d3d12` runbook, the startup + D3D12 trace summary (`tools/boot_trace.py`), the triage order and the Q1–Q22 checklist. | |
| 72 | | [retail_boot_chain.md](retail_boot_chain.md) | How far `gta6rt --run` gets with the retail executable: the stops in order and what clears each, the physical-page export shapes, and device slots 26, 48 and 73. | | 72 | | [retail_boot_chain.md](retail_boot_chain.md) | How far `gta6rt --run` gets with the retail executable: the stops in order and what clears each, the physical-page export shapes, device slots 26, 48 and 73, and the device slots the executable calls, counted from the file (`tools/d3d12_device_calls.py`). | |
| 73 | | [retail_boot_intel_host.md](retail_boot_intel_host.md) | The retail boot on an Intel host with 16 GB: which stops of the two boot pages hold there with #7111, the commit-limit stop at the 6.1 GiB physical-page request that #7556 clears, the frame loop to the 900 s timeout with stub pipelines, and what the layer refuses at that depth (the console mesh-shader subobject among it). | | 73 | | [retail_boot_intel_host.md](retail_boot_intel_host.md) | The retail boot on an Intel host with 16 GB: which stops of the two boot pages hold there with #7111, the commit-limit stop at the 6.1 GiB physical-page request that #7556 clears, the frame loop to the 900 s timeout with stub pipelines, and what the layer refuses at that depth (the console mesh-shader subobject among it). | |
| 74 | | [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). | | 74 | | [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). | |
| 75 | | [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. | | 75 | | [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. | |
| @@ -81,14 +81,14 @@ method, scope and caveats. No game data is included. | |||
| 81 | | [d3d12_command_objects.md](d3d12_command_objects.md) | Measured command queue/list/fence/`PresentX` surface; verified vs prior art vs open. | | 81 | | [d3d12_command_objects.md](d3d12_command_objects.md) | Measured command queue/list/fence/`PresentX` surface; verified vs prior art vs open. | |
| 82 | | [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. | | 82 | | [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. | |
| 83 | | [runtime_imports.md](runtime_imports.md) | The 16 shipped modules' measured imports and shim/host/unimplemented split. | | 83 | | [runtime_imports.md](runtime_imports.md) | The 16 shipped modules' measured imports and shim/host/unimplemented split. | |
| 84 | | [linux_proton.md](linux_proton.md) | Building and booting under Proton/Wine on Linux, a healthy boot's timeline, and the test report of one Linux and two Windows machines | | 84 | | [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 | |
| 85 | | [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. | | 85 | | [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. | |
| 86 | | [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). | | 86 | | [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). | |
| 87 | | [audio_hal_exe_calls.md](audio_hal_exe_calls.md) | How the retail executable calls the 22 audio coprocessor, texture layout and DirectStorage imports that have no shim: call sites, constant arguments, and the four calls with a negative-result branch. | | 87 | | [audio_hal_exe_calls.md](audio_hal_exe_calls.md) | How the retail executable calls the 22 audio coprocessor, texture layout and DirectStorage imports that have no shim: call sites, constant arguments, and the four calls with a negative-result branch. | |
| 88 | | [directstorage.md](directstorage.md) | Console DirectStorage: the DLL and ABI the title is expected to use (`DStorageGetFactory`, `dstorage_xs`, `XCRDAPI`), how sure that is and the evidence for it, and what `runtime/shims/dstorage.cpp` serves on the PC. The executable's own imports are unmeasured. | | 88 | | [directstorage.md](directstorage.md) | Console DirectStorage: the DLL and ABI the title is expected to use (`DStorageGetFactory`, `dstorage_xs`, `XCRDAPI`), how sure that is and the evidence for it, and what `runtime/shims/dstorage.cpp` serves on the PC. The executable's own imports are unmeasured. | |
| 89 | | [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. | | 89 | | [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. | |
| 90 | | [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. | | 90 | | [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. | |
| 91 | | [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; 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. | | 91 | | [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. | |
| 92 | | [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`). | | 92 | | [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`). | |
| 93 | | [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. | | 93 | | [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. | |
| 94 | | [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. | | 94 | | [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. | |
diff --git a/docs/boot.md b/docs/boot.md index 2b7186e30..3ba791f88 100644 --- a/docs/boot.md +++ b/docs/boot.md | |||
| @@ -95,9 +95,11 @@ Useful switches: | |||
| 95 | This switch covers imports only; it does not affect the D3D12 outcomes. | 95 | This switch covers imports only; it does not affect the D3D12 outcomes. |
| 96 | * `LEONIDA_SKIP_CPU_CHECK=1` skips the AVX preflight of `--init` and `--run`, which otherwise exits 4 with one line | 96 | * `LEONIDA_SKIP_CPU_CHECK=1` skips the AVX preflight of `--init` and `--run`, which otherwise exits 4 with one line |
| 97 | naming the missing feature on a host without AVX (a QEMU `qemu64` guest; under Rosetta, set | 97 | naming the missing feature on a host without AVX (a QEMU `qemu64` guest; under Rosetta, set |
| 98 | `ROSETTA_ADVERTISE_AVX=1` instead). The game itself still needs AVX, so this is for the #UD emulation work. | 98 | `ROSETTA_ADVERTISE_AVX=1` instead). The game itself still needs AVX, so this is for the #UD emulation work (see |
| 99 | [cpu_features.md](cpu_features.md#hosts-without-avx) for what works on a host without AVX). | ||
| 99 | * `LEONIDA_SKIP_INT3=1` (with `--trace`) steps over each int3 in guest code and logs it once per address as an | 100 | * `LEONIDA_SKIP_INT3=1` (with `--trace`) steps over each int3 in guest code and logs it once per address as an |
| 100 | `int3_skipped` event, so a boot can be followed past soft asserts (an int3 followed by code that carries on). | 101 | `int3_skipped` event, so a boot can be followed past soft asserts (an int3 followed by code that carries on). It is |
| 102 | read when the trace opens. | ||
| 101 | Diagnostic only: a correct run reaches none, so each skipped address is a finding, not a fix. A failed guest file | 103 | Diagnostic only: a correct run reaches none, so each skipped address is a finding, not a fix. A failed guest file |
| 102 | open is always traced as `file_open_failed` (path, error, caller) when `--trace` is on. | 104 | open is always traced as `file_open_failed` (path, error, caller) when `--trace` is on. |
| 103 | * `LEONIDA_STUB_PIPELINES=1` creates a pipeline whose translated shader is missing (no shader library, or no entry | 105 | * `LEONIDA_STUB_PIPELINES=1` creates a pipeline whose translated shader is missing (no shader library, or no entry |
| @@ -116,13 +118,75 @@ Useful switches: | |||
| 116 | diagnostic). | 118 | diagnostic). |
| 117 | * `LEONIDA_DEVICE_FAULT=1` enables Vulkan device-loss diagnostics and checkpoints where available. The first | 119 | * `LEONIDA_DEVICE_FAULT=1` enables Vulkan device-loss diagnostics and checkpoints where available. The first |
| 118 | observed loss prints a `[rt] device-fault:` report to stderr. | 120 | observed loss prints a `[rt] device-fault:` report to stderr. |
| 121 | * `LEONIDA_TITLE_HUD=1` shows live counters in the title bar of the window the title presents in | ||
| 122 | (`runtime/shims/title_hud.h`). It updates twice a second with: | ||
| 123 | - the frame rate and the average and worst frame time from PresentX, or, when no frame came in that half | ||
| 124 | second, how long since the last one (a hang reads "0 fps, no frame for 12.5 s"); | ||
| 125 | - the process's private memory (its commit charge; Wine fills only `PagefileUsage`, which is the same figure) | ||
| 126 | and working set; | ||
| 127 | - its GPU memory: in use and the budget over the device-local heaps, and in use in the other heaps, read from | ||
| 128 | the Vulkan device through `VK_EXT_memory_budget`. Without that extension it falls back to DXGI's | ||
| 129 | `QueryVideoMemoryInfo`, which reads 0 under Wine; with neither the field reads `VRAM n/a`, not a false 0. | ||
| 130 | Both memory figures and their text come from `runtime/src/memory_figures.h`, which the dev overlay shows too; | ||
| 131 | - the graphics and compute pipelines created, and the seconds spent in `vkCreate*Pipelines` in the last half | ||
| 132 | second. A pipeline compiled in the frame shows up there as a hitch. This needs `LEONIDA_MEM_PROBE`; without it | ||
| 133 | the field reads `PSO -`. | ||
| 134 | - the time since the first present. | ||
| 135 | |||
| 136 | A thread of its own sets the text with `SendMessageTimeout`, so a busy window thread never holds a present. | ||
| 137 | * `LEONIDA_DEV_OVERLAY=1` (Windows) shows what the runtime is doing in a small click-through window over the top left | ||
| 138 | corner of the title's window, while that window is in front (`runtime/src/dev_overlay.h`): frames and submissions a | ||
| 139 | second, where a submission's CPU time goes, the phase that is running now and for how long, pipeline builds in | ||
| 140 | flight, indirect draws emitted and skipped, cores, free RAM, and the same private memory and GPU memory figures as | ||
| 141 | `LEONIDA_TITLE_HUD` (`VRAM n/a` without `VK_EXT_memory_budget`). The device publishes its GPU memory figure, and | ||
| 142 | the overlay and the HUD read it at most once per half second. The rates cover the last two seconds. It has its own | ||
| 143 | thread, so it also counts while the title presents nothing, and it is in no capture. `LEONIDA_TITLE_HUD` shows frame | ||
| 144 | times and compile times in the title bar instead; both can be on. | ||
| 119 | * `DISABLE_RTSS_LAYER=1` and `DISABLE_VULKAN_OBS_CAPTURE=1` when MSI Afterburner or OBS is installed; their | 145 | * `DISABLE_RTSS_LAYER=1` and `DISABLE_VULKAN_OBS_CAPTURE=1` when MSI Afterburner or OBS is installed; their |
| 120 | implicit layers add swapchain usage that shows up as validation errors ([testing.md](testing.md), "Known | 146 | implicit layers add swapchain usage that shows up as validation errors ([testing.md](testing.md), "Known |
| 121 | problems"). | 147 | problems"). |
| 122 | * `--overlay DIR` sends the guest's writes to DIR instead of the default `<game-dir>\overlay` (useful when the | 148 | * `--overlay DIR` sends the guest's writes to DIR instead of the default `<game-dir>\overlay` (useful when the |
| 123 | package drive is read-only); the package itself is never written. Set `LEONIDA_WRITE_DIR` to override that folder | 149 | package drive is read-only); the package itself is never written. Set `LEONIDA_WRITE_DIR` to override that folder |
| 124 | for one run (it wins over `--overlay`). For a fresh first-run profile, also set `LEONIDA_SAVE_DIR` to a separate | 150 | for one run (it wins over `--overlay`). For a fresh first-run profile, also set `LEONIDA_SAVE_DIR` to a separate |
| 125 | empty directory for the local game-save provider. | 151 | empty directory for the local game-save provider. The title's `T:` drive (its temporary drive, |
| 152 | where it writes its crash dump `T:\<guid>.dmp` and crash log) is a folder of each process's own inside the overlay, | ||
| 153 | `<overlay>\.gta6rt-temp\<YYYYMMDD-HHMMSS-mmm>-pid<id>` (the process's start time in UTC and its id). | ||
| 154 | The folder is reserved with a create-only `CreateDirectoryW` when `gta6rt` starts the title (or on the first `T:` | ||
| 155 | call): when that name already exists, as after a reused process id in the same millisecond, it takes `-2`, `-3`, | ||
| 156 | ... (up to 1000 names), so a run never writes into a folder that existed before it. The startup line names it | ||
| 157 | (`console paths: GAME: -> ..., writes -> ..., T: -> ...`). | ||
| 158 | Folders of earlier runs are kept, so a run's crash files can be read after it stops; delete them by hand. With | ||
| 159 | one folder for every run, a `CREATE_NEW` of a name an earlier run had left failed with `ERROR_FILE_EXISTS` (80) | ||
| 160 | and no report landed (old upstream issue 7913). | ||
| 161 | |||
| 162 | ### Under Wine on Linux | ||
| 163 | |||
| 164 | The prefix has to supply a `d3d12.dll` that exports `D3D12SerializeVersionedRootSignature`, because the executable | ||
| 165 | imports it. Wine's own `d3d12.dll` does not answer that export for the runtime's shim, and the failure is quiet: | ||
| 166 | the D3D12 trace ends at about 1,658 calls, the startup trace ends in an access violation inside the executable, | ||
| 167 | and the one line that names the cause is | ||
| 168 | `[rt] d3d12_xs: host d3d12.dll has no D3D12SerializeVersionedRootSignature`. The run never reaches | ||
| 169 | `CreateRootSignature`. | ||
| 170 | |||
| 171 | Copying the DLLs a Proton prefix installs is not enough on its own: Wine keeps preferring its own copy next to | ||
| 172 | them. Name them in the overrides. | ||
| 173 | |||
| 174 | ```bash | ||
| 175 | GE=$HOME/GE-Proton11-13-x86_64/files/lib/wine | ||
| 176 | cp "$GE/vkd3d-proton/x86_64-windows/d3d12.dll" \ | ||
| 177 | "$GE/vkd3d-proton/x86_64-windows/d3d12core.dll" \ | ||
| 178 | "$GE/dxvk/x86_64-windows/dxgi.dll" "$WINEPREFIX/drive_c/windows/system32/" | ||
| 179 | export WINEDLLOVERRIDES="d3d12,d3d12core,dxgi=n,b" | ||
| 180 | export LEONIDA_D3D12=vulkan | ||
| 181 | export LEONIDA_SHADERS='Z:\path\to\shaders\spirv' | ||
| 182 | wine ./gta6rt.exe --run 'Z:\path\to\game_scarlett_master.exe' --game-dir 'Z:\path\to\the\package' \ | ||
| 183 | --trace /tmp/boot.jsonl --trace-d3d12 | ||
| 184 | ``` | ||
| 185 | |||
| 186 | With those three DLLs and the override, the same prefix reaches the frame loop: about 1.4 million D3D12 calls in | ||
| 187 | 90 s, no exception, `PresentX ready`, against 1,658 calls and an access violation without them, measured on Wine | ||
| 188 | 11.13 (GE-Proton 11-13) with an RDNA2 iGPU. A prefix that Proton itself created already carries these files and | ||
| 189 | needs no override. | ||
| 126 | 190 | ||
| 127 | ## 3. Triage order | 191 | ## 3. Triage order |
| 128 | 192 | ||
diff --git a/docs/boot_leads.md b/docs/boot_leads.md index 56ec05436..b3e0207f9 100644 --- a/docs/boot_leads.md +++ b/docs/boot_leads.md | |||
| @@ -80,12 +80,14 @@ your own copy or with a synthetic test before you build on it, and record the re | |||
| 80 | - **Finding:** a console descriptor word may be a 32-bit GPU address rather than a heap offset. | 80 | - **Finding:** a console descriptor word may be a 32-bit GPU address rather than a heap offset. |
| 81 | - **Where:** the "descriptor-table record model" listed as open in [d3d12_vulkan.md](d3d12_vulkan.md), next to the | 81 | - **Where:** the "descriptor-table record model" listed as open in [d3d12_vulkan.md](d3d12_vulkan.md), next to the |
| 82 | descriptor-heap start-handle convention in §7 of that page. | 82 | descriptor-heap start-handle convention in §7 of that page. |
| 83 | - **Implement:** census the descriptor words the title writes (count how many are valid addresses inside the arena | 83 | - **Result:** measured by retail descriptor heap census (1,245,184 slots across submits 50, 500 and 5000; RTX 5070, Windows 11). |
| 84 | and how many are not). If the census holds, translate a word to the buffer device address or bindless index it | 84 | The heap holds: 910,244 empty slots; 327,543 free-list links (`value = next slot index`, terminating at `0xFFFFFFFF`); |
| 85 | stands for, the way root-descriptor addresses already go through the arena. | 85 | 261 T# with layer-assigned addresses above 4 GiB; 5,840 V# (3,024 with a null base, 2,816 with a sub-4-GiB base); |
| 86 | - **Test:** a synthetic heap whose words are arena addresses, round-tripped through the translation. | 86 | 1,296 slots of interleaved constant data; and **0 slots that are bare 32-bit GPU addresses**. |
| 87 | - **Record it in:** [d3d12_vulkan.md](d3d12_vulkan.md) with the census counts. | 87 | - **Conclusion:** BL-4 hypothesis is not supported on this stack. Descriptors pack 48-bit addresses into V# / T# fields rather |
| 88 | - **Needs:** game files for the census. | 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). |
| 89 | - **Record it in:** [d3d12_vulkan.md](d3d12_vulkan.md) §3.4 with the census breakdown. | ||
| 90 | - **Needs:** none (census completed and verified). | ||
| 89 | 91 | ||
| 90 | ## BL-5: a possible gap in the shader corpus count | 92 | ## BL-5: a possible gap in the shader corpus count |
| 91 | 93 | ||
diff --git a/docs/buffer_bounds.md b/docs/buffer_bounds.md index f5b4e6a55..a2d566bc1 100644 --- a/docs/buffer_bounds.md +++ b/docs/buffer_bounds.md | |||
| @@ -23,6 +23,11 @@ API-created CBVs mirror the observed inline console descriptor (mode 0, 16-byte | |||
| 23 | 23 | ||
| 24 | - **RDNA2 follows Mesa's GFX11 column**, not the GFX10 one: of 732 cases, 729 match GFX11 and 696 match GFX10. | 24 | - **RDNA2 follows Mesa's GFX11 column**, not the GFX10 one: of 732 cases, 729 match GFX11 and 696 match GFX10. |
| 25 | Every GFX10 miss is an access that only partly fits, for example a raw buffer with `N = 3` read at offset 0. | 25 | Every GFX10 miss is an access that only partly fits, for example a raw buffer with `N = 3` read at offset 0. |
| 26 | - **The offset is not cut to 32 bits.** `index * stride` is a full product and `soffset` is added in 64 bits, so | ||
| 27 | index 0xFFFFFFFF with a 20-byte stride lands tens of GiB past the base and the access has no effect; in 32 bits it | ||
| 28 | would be the 20 bytes below the base, which modes 2 and 3 do not refuse. The translator treats an offset above | ||
| 29 | 0xFFFFFFFF as out of range in every mode. Observed on hardware by five-star-recomp (commit `b9b57e2`), not measured | ||
| 30 | here; `tests/semantic/test_buffer_offset_wrap.py`. | ||
| 26 | - **In raw mode `soffset` is part of the checked offset.** The 3 cases that match neither column are raw reads at | 31 | - **In raw mode `soffset` is part of the checked offset.** The 3 cases that match neither column are raw reads at |
| 27 | offset 8 with `soffset` 8 and `N = 18`: 8 + 8 + 4 > 18, out of range on hardware. | 32 | offset 8 with `soffset` 8 and `N = 18`: 8 + 8 + 4 > 18, out of range on hardware. |
| 28 | - Loads and stores agree in every case. | 33 | - Loads and stores agree in every case. |
diff --git a/docs/bvh.md b/docs/bvh.md index 203a88c2d..ee4316672 100644 --- a/docs/bvh.md +++ b/docs/bvh.md | |||
| @@ -123,8 +123,42 @@ So the "`u16` table at header `0x130`" of section 4 is not a table: it is these | |||
| 123 | (a root pointer, the element offset and the parent offset, the last usually negative; hence "often monotonic"). With `offsetToPrimRemap` 0 everywhere there is no | 123 | (a root pointer, the element offset and the parent offset, the last usually negative; hence "often monotonic"). With `offsetToPrimRemap` 0 everywhere there is no |
| 124 | primitive remap table either, and the element region allocates 64 bytes per element, `numElements` of them, padded | 124 | primitive remap table either, and the element region allocates 64 bytes per element, `numElements` of them, padded |
| 125 | to 128 bytes (a stride, not a record layout: section 4a describes the packed arrays inside it). | 125 | to 128 bytes (a stride, not a record layout: section 4a describes the packed arrays inside it). |
| 126 | **Open:** where the parent array starts and how big it is. Neither `offsetToParents + 4 * unit` against the header end | 126 | **The parent table (BUILD-1390).** The traversal shader finds the entry for the 64-byte unit `u` at |
| 127 | or `offsetToElements`, nor a size of `4 *` the node or element count, holds on every stream. | 127 | `offsetToParents + 4 * (u - offsetToElements / 64)` (`XboxBvh4Node_GetParentTableOffset` and |
| 128 | `XboxBvh4Node_LoadParentPointer`, L3254-L3275 of the `.hlsli` above, 32-bit arithmetic). It only looks up the | ||
| 129 | parent of a box node: the node it climbs from is the last non-triangle node (L6212), asserted to be above `TRI3` | ||
| 130 | (L6265). The table is laid out for the box nodes only: | ||
| 131 | |||
| 132 | * *Start:* `offsetToParents = 0x40 - (((offsetToNodes - offsetToElements) / 16) & ~127)`. The element units' | ||
| 133 | entries take `(offsetToNodes - offsetToElements) / 16` bytes; their whole 128-byte blocks sit below the header | ||
| 134 | end, which is why the word is negative from 32 element units up. The first box node's entry is then at | ||
| 135 | `offsetToParents + (offsetToNodes - offsetToElements) / 16`, in `[0x40, 0xc0)`. | ||
| 136 | * *Extent:* one entry per box unit (a BOX16 node takes one, a BOX32 node two) from the first box entry, and | ||
| 137 | `offsetToElements` is the end of the last one rounded up to 128 bytes. The bytes between the header end and the | ||
| 138 | first box entry, and after the last one, are the only slack. | ||
| 139 | * *Not shipped:* the bytes from `0x40` to `offsetToElements` are all zero; rehydration writes the entries | ||
| 140 | (`tools/bvh_rehydrate.py`, which matches the library byte for byte on 8 samples, §4a). | ||
| 141 | * *The units the header counts:* `totalSizeIn64BNodes + 1` is the end of the last box group in 64-byte units plus | ||
| 142 | `ceil((4 + 8 * levels) / 64)` units for the level table (§4a). The level table's units have no entry, so the end | ||
| 143 | `offsetToParents + 4 * (totalSizeIn64BNodes + 1 - offsetToElements / 64)` taken from the header alone, rounded up | ||
| 144 | to 128, lands on `offsetToElements` on only 259,456 of the 272,858 box-rooted streams. | ||
| 145 | |||
| 146 | Measured over every stream of both packs, with a scratch probe over the `tools/bvh_index.py` scan and then with | ||
| 147 | `tools/bvh_packing_check.py`, which now checks all three (§4a): 272,874 streams (271,627 complete and 10 joined in | ||
| 148 | `core_bvh4.rpf`, 1,237 in `shared_minigame000_bvh4.rpf`). Counts only. | ||
| 149 | |||
| 150 | | rule | holds on | | ||
| 151 | |---|---| | ||
| 152 | | `[0x40, offsetToElements)` is zero | 272,874 / 272,874 | | ||
| 153 | | `offsetToParents` from the start rule | 272,874 / 272,874 | | ||
| 154 | | `offsetToElements` from the extent rule (box root) | 272,858 / 272,858 | | ||
| 155 | | `totalSizeIn64BNodes + 1` = box groups' end plus the level table's units (box root) | 272,858 / 272,858 | | ||
| 156 | | leaf root (`numElements` 1): `offsetToElements` `0x80`, `offsetToNodes` `0x100`, `offsetToParents` `0x40`, `totalSizeIn64BNodes` 3 | 16 / 16 | | ||
| 157 | | no slack after the last box entry | 8,973 (1 to 31 entries on the rest) | | ||
| 158 | |||
| 159 | **Hypothesis:** the console builder sizes the table from the box nodes it wrote and aligns it the same way for | ||
| 160 | updatable or top-level structures. Every measured stream has `flags` `0x81020006`, a BLAS without the updatable | ||
| 161 | bit `0x00040000`, so where an updatable structure keeps its leaves' entries is not measured. | ||
| 128 | 162 | ||
| 129 | The `flags` word has version `6` in its low 16 bits. It also sets `0x80000000` (bottom level), `0x00020000` | 163 | The `flags` word has version `6` in its low 16 bits. It also sets `0x80000000` (bottom level), `0x00020000` |
| 130 | (offline) and `0x01000000` (dehydrated). It does not set `0x00010000` (compressed). The sample is therefore a | 164 | (offline) and `0x01000000` (dehydrated). It does not set `0x00010000` (compressed). The sample is therefore a |
| @@ -506,6 +540,7 @@ bytes form exactly one tree: | |||
| 506 | * a box pointer names a node of its own width on a lower level; | 540 | * a box pointer names a node of its own width on a lower level; |
| 507 | * a TRI0 pointer names a leaf slot `offsetToElements + 64 * k` with `k < numElements`; | 541 | * a TRI0 pointer names a leaf slot `offsetToElements + 64 * k` with `k < numElements`; |
| 508 | * nothing points to the root, and every other node and every leaf has exactly one parent; | 542 | * nothing points to the root, and every other node and every leaf has exactly one parent; |
| 543 | * the parent table is not shipped and its start and extent follow the element and box regions (§3.1); | ||
| 509 | * every vertex-order byte is a permutation; | 544 | * every vertex-order byte is a permutation; |
| 510 | * every stored override lies inside `sceneBounds` in the leaf frame. | 545 | * every stored override lies inside `sceneBounds` in the leaf frame. |
| 511 | 546 | ||
diff --git a/docs/cpu_features.md b/docs/cpu_features.md index 5ecea005f..47ffd81dc 100644 --- a/docs/cpu_features.md +++ b/docs/cpu_features.md | |||
| @@ -69,3 +69,22 @@ in the image. | |||
| 69 | answers is not measured here. | 69 | answers is not measured here. |
| 70 | 70 | ||
| 71 | Not measured: which of these sites a boot reaches, and in which order. | 71 | Not measured: which of these sites a boot reaches, and in which order. |
| 72 | |||
| 73 | ### Hosts without AVX | ||
| 74 | |||
| 75 | Measured on one host: Intel Xeon X5675 (Westmere, SSE4.2; no AVX, AVX2, FMA, BMI2 or XSAVE), Fedora 44, | ||
| 76 | `wine-11.21 (Staging)`, Intel SDE 10.13.1, and a local `gta6rt.exe` build from 2026-11-24. | ||
| 77 | |||
| 78 | - **What works without AVX:** building the native Linux runtime and Vulkan test tools (`ctest`), running the Vulkan GPU | ||
| 79 | suite (`scripts/run_gpu_tests.py`), shader translation and asset export (`make_game.py` stages). | ||
| 80 | - **Running `gta6rt` directly:** `--init` and `--run` exit 4 at the AVX preflight. With `LEONIDA_SKIP_CPU_CHECK=1`, | ||
| 81 | the preflight is skipped and the guest faults on its first AVX instruction. | ||
| 82 | - **Under Intel SDE (`sde64 -hsw`):** without `-chip_check_disable 1`, SDE aborts on `clzero` instead of raising | ||
| 83 | `SIGILL` for `gta6rt`'s handler. With `-chip_check_disable 1`, the guest passes its first AVX instruction and reaches | ||
| 84 | `InitializeApiImplEx2` (offline) after ~110 s, then stops before any window or D3D12 call: SDE traps an `int 3` | ||
| 85 | without `-raise-int3`, and with `-raise-int3` the process terminates with `SIGSEGV` (`LEONIDA_SKIP_INT3=1` with | ||
| 86 | `--trace` did not change this, recording `0` `int3_skipped` events). Adding `-ptr-raise` causes Pin to abort with an | ||
| 87 | internal instrumentation error under Wine's exception handling. | ||
| 88 | - **Outcome on this host:** no useful path to boot `gta6rt --run` was found under SDE + Wine. | ||
| 89 | |||
| 90 | Not measured: other emulators (such as QEMU TCG with AVX2) or Rosetta 2. | ||
diff --git a/docs/d3d12_command_objects.md b/docs/d3d12_command_objects.md index 1aef12206..eea693c70 100644 --- a/docs/d3d12_command_objects.md +++ b/docs/d3d12_command_objects.md | |||
| @@ -136,8 +136,41 @@ following each `0x40`/`0x48`/`0x60`/`0x120` call back to its receiver. | |||
| 136 | 136 | ||
| 137 | So the four slots' callers are in the game executable, which the package does not contain (the | 137 | So the four slots' callers are in the game executable, which the package does not contain (the |
| 138 | same blocker as RT-5). Confidence for slots 8, 9, 12 and 36 stays **Open**: the table in §2.1 is | 138 | same blocker as RT-5). Confidence for slots 8, 9, 12 and 36 stays **Open**: the table in §2.1 is |
| 139 | still the SDK baseline. Once the executable is available, `tools/d3d12_iid_scan.py` run on it | 139 | still the SDK baseline. |
| 140 | shows whether it carries these IIDs, and its call sites through them give the slots. | 140 | |
| 141 | **Measured on the retail executable** (`python -I tools/d3d12_iid_scan.py`, 80 SDK IIDs read from | ||
| 142 | the Windows SDK 10.0.26100 `d3d12.h`): the image carries 13 of them, and it carries the whole | ||
| 143 | queue/allocator/list/fence set except the two base/second-generation names: | ||
| 144 | |||
| 145 | | IID | In the executable | | ||
| 146 | |---|---| | ||
| 147 | | `ID3D12CommandQueue` | present | | ||
| 148 | | `ID3D12CommandAllocator` | present | | ||
| 149 | | `ID3D12GraphicsCommandList` | present (one slot-73 site; startup lists use the console IID below) | | ||
| 150 | | `ID3D12Fence` | present | | ||
| 151 | | `ID3D12CommandList` (base) | absent | | ||
| 152 | | `ID3D12Fence1` | absent | | ||
| 153 | |||
| 154 | The other carried IIDs are `ID3D12CommandSignature`, `ID3D12DescriptorHeap`, `ID3D12Device11`, | ||
| 155 | `ID3D12PipelineState`, `ID3D12QueryHeap`, `ID3D12Resource`, `ID3D12RootSignature`, | ||
| 156 | `ID3D12StateObject` and `ID3D12StateObjectProperties`; the image imports only | ||
| 157 | `D3D12ConfigureVirtualMemoryX`, `D3D12SerializeVersionedRootSignature` and | ||
| 158 | `D3D12XboxCreateDevice` from `d3d12_xs.dll`. `ID3D12Device11` | ||
| 159 | (`{5405C344-D457-444E-B4DD-2366E45AEE39}`, `d3d12.h:24502,35748`, `.rdata` `0x1461E0638`) is the | ||
| 160 | `riid` the executable passes to `D3D12XboxCreateDevice` (`0x14247856C` → `0x1424785B7`), which is | ||
| 161 | why both `d3d12_iid_scan.py` and `is_device_iid` in `runtime/shims/d3d12_xs_device.cpp` recognise | ||
| 162 | it during [retail_boot_chain.md](retail_boot_chain.md). | ||
| 163 | |||
| 164 | A carried IID is necessary but not sufficient: it says the binary can ask for the interface, not | ||
| 165 | where it does. The slots stay **Open** until a call site is followed. | ||
| 166 | |||
| 167 | One console command-list IID is outside `d3d12.h`, so the scan cannot see it, and a proxy has to | ||
| 168 | answer it rather than forward it to the PC device: `{C3827890-4024-474C-98CF-645B51DC4874}` | ||
| 169 | (`.rdata` `0x1461E0668`), passed to Xbox device slot 73 (`CreateCommandListX`) in renderer startup | ||
| 170 | at `0x142478B56` → `0x142478B71` ([retail_boot_chain.md](retail_boot_chain.md) §3.3, | ||
| 171 | [#523](https://github.com/ubiquitarianism/leonida/issues/523)); the carried | ||
| 172 | `IID_ID3D12GraphicsCommandList` (`0x1461ECFA0`) is passed to slot 73 at a separate site | ||
| 173 | (`0x1417F6D1D` → `0x1417F6D34`). | ||
| 141 | 174 | ||
| 142 | ### 2.2 Queue, allocator and fence | 175 | ### 2.2 Queue, allocator and fence |
| 143 | 176 | ||
| @@ -565,6 +598,10 @@ shape and the shift around them, but the shape alone does not single the method | |||
| 565 | | 55 (`+0x1b8`) | **51** | `DiscardResource` | `(resource, null)` at `0x6dcb`, after the pending barriers are flushed through slot 26 | | 598 | | 55 (`+0x1b8`) | **51** | `DiscardResource` | `(resource, null)` at `0x6dcb`, after the pending barriers are flushed through slot 26 | |
| 566 | | 59 (`+0x1d8`) | — | console only (shape) | four calls, two shapes: `(1, blob, size)` at `0x6b5a` and `0x6d53`, the blob a run of qwords whose first is `0xf3080 \| (qword count & 0x7f)`; and `(0, &qword, 8)` with the qword 1 at `0x6e52` and `0x6eb8`, only when a profiling bit of the context is set (`0x6e2a`). The first argument is set as a byte (`mov dl, 1` / `xor edx, edx`). It looks like one slot for both ends of a GPU event; no public method takes a bool first. With 55 at +4 and 61 at +2, the two slots the console lacks are among 56–60 | | 599 | | 59 (`+0x1d8`) | — | console only (shape) | four calls, two shapes: `(1, blob, size)` at `0x6b5a` and `0x6d53`, the blob a run of qwords whose first is `0xf3080 \| (qword count & 0x7f)`; and `(0, &qword, 8)` with the qword 1 at `0x6e52` and `0x6eb8`, only when a profiling bit of the context is set (`0x6e2a`). The first argument is set as a byte (`mov dl, 1` / `xor edx, edx`). It looks like one slot for both ends of a GPU event; no public method takes a bool first. With 55 at +4 and 61 at +2, the two slots the console lacks are among 56–60 | |
| 567 | | 61 (`+0x1e8`) | **59** | `ExecuteIndirect` | `(signature, 1, argument buffer, offset, null, 0)` at `0x59a0` | | 600 | | 61 (`+0x1e8`) | **59** | `ExecuteIndirect` | `(signature, 1, argument buffer, offset, null, 0)` at `0x59a0` | |
| 601 | | 71 (`+0x238`) | — | console only | `Write32BitValueBottomOfPipeX(address, u32 value, flush, flags)`: the 32-bit value, written into the title's memory once the list's work has run (the list values, [d3d12_xs_console_abi.md §5.5](d3d12_xs_console_abi.md)) | | ||
| 602 | | 72 (`+0x240`) | — | console only | `Write64BitValueBottomOfPipeX(address, u64 value, flush, flags)`: the 64-bit value; flags 1 ask for a GPU timestamp and 2 for a system timestamp instead of the value the call carried | | ||
| 603 | | 73 (`+0x248`) | — | console only | `Wait32BitValueX`: a wait on the 32-bit value; the list values hold the queue until it compares true or times out (§5.5 there) | | ||
| 604 | | 74 (`+0x250`) | — | console only | `Wait64BitValueX`: the same on the 64-bit value | | ||
| 568 | | 85 (`+0x2a8`) | — | `CopyTextureRegion` shape (inferred) | run: `(stack pointer, 0, 0)`, twice per dispatch. Statically six arguments, `(&dst, 0, 0, 0, &src, null)`: the public `CopyTextureRegion` (PC 16) with two `D3D12_TEXTURE_COPY_LOCATION`s, not one pointer. At `0x7147` dst is `{texture, SUBRESOURCE_INDEX, 0}` and src `{buffer, PLACED_FOOTPRINT, footprint}`, the footprint from device slot 38 (`GetCopyableFootprints`, `0x708b`); at `0x7191` both are subresource 0 (texture to texture). The caller also clears the next stack argument (`0x70e7`); whether the method takes a seventh is open, as is what console slot 16 is | | 605 | | 85 (`+0x2a8`) | — | `CopyTextureRegion` shape (inferred) | run: `(stack pointer, 0, 0)`, twice per dispatch. Statically six arguments, `(&dst, 0, 0, 0, &src, null)`: the public `CopyTextureRegion` (PC 16) with two `D3D12_TEXTURE_COPY_LOCATION`s, not one pointer. At `0x7147` dst is `{texture, SUBRESOURCE_INDEX, 0}` and src `{buffer, PLACED_FOOTPRINT, footprint}`, the footprint from device slot 38 (`GetCopyableFootprints`, `0x708b`); at `0x7191` both are subresource 0 (texture to texture). The caller also clears the next stack argument (`0x70e7`); whether the method takes a seventh is open, as is what console slot 16 is | |
| 569 | | 141 (`+0x468`) | — | console only | `(2, GPU VA, size, n)` at `0x65f8`: binds a buffer the DLL names `FFX_XBox_ComputeScratch`; `n` is the bound pipeline's scratch value from pipeline slot 11 (see above) | | 606 | | 141 (`+0x468`) | — | console only | `(2, GPU VA, size, n)` at `0x65f8`: binds a buffer the DLL names `FFX_XBox_ComputeScratch`; `n` is the bound pipeline's scratch value from pipeline slot 11 (see above) | |
| 570 | 607 | ||
| @@ -573,6 +610,20 @@ So the console list has four more methods than the PC list between `ResourceBarr | |||
| 573 | Mapping the console list as "PC plus a constant" is wrong. The BVH builder adds 37, 39, 43 and 45 (the rest of the | 610 | Mapping the console list as "PC plus a constant" is wrong. The BVH builder adds 37, 39, 43 and 45 (the rest of the |
| 574 | +4 root group) and the console-only 71, 73, 80, 146 (`Barrier`) and 148 (sections 3.3 and 3.3a). | 611 | +4 root group) and the console-only 71, 73, 80, 146 (`Barrier`) and 148 (sections 3.3 and 3.3a). |
| 575 | 612 | ||
| 613 | **The two value-write slots.** Slots 71 and 72 are the console's value writes and 73 and 74 the waits that go with | ||
| 614 | them. The slot numbers are measured, not read: the retail title's own trace calls slot 71 with a title address and | ||
| 615 | a value, slot 72 with a title address and the flags word and slot 74 with a wait's arguments, and the value writes | ||
| 616 | are at 71/72 rather than at 69/70; and `XboxBvhBuilder.dll` reads a 32-bit value write at `+0x238` (slot 71) and a masked wait at `+0x248` | ||
| 617 | (slot 73). The call shapes are xcl's (crates/xcl/src/hle/d3d12x/list_x.rs, GPL-2.0) and the deferred | ||
| 618 | bottom-of-pipe write model is VIctory's (crates/victory-gpu/src/list.rs, GPL-3.0): the write is not a GPU command, | ||
| 619 | it is a CPU write into the title's memory, made after the submission that recorded it has run. Both projects are | ||
| 620 | cited for facts and for the model only, no code copied. The runtime has two writers for them, one per list: the list | ||
| 621 | values (`runtime/shims/d3d12_xs_list_values.h`, on by default) for the lists they track, with the waits of slots 73 | ||
| 622 | and 74; and the GPU-label path (`runtime/src/vulkan_gpu_labels.h`, `LEONIDA_GPU_LABELS=1`) for the others. Both | ||
| 623 | land a write whose address is a GPU address arena offset in the arena, never at that number in host memory, and one | ||
| 624 | on a page of xmem's that the title's view keeps `PAGE_NOACCESS` through xmem's own mapping of the physical page | ||
| 625 | (`runtime/src/value_write_sink.h`). | ||
| 626 | |||
| 576 | **The list object is wider than its vtable, and this is what that width is for.** Before a root-argument or dispatch | 627 | **The list object is wider than its vtable, and this is what that width is for.** Before a root-argument or dispatch |
| 577 | call the DLL checks a write cursor at `+0x18` against a limit (`+0x30` for root arguments, `+0x28` for a dispatch). While there is room, | 628 | call the DLL checks a write cursor at `+0x18` against a limit (`+0x30` for root arguments, `+0x28` for a dispatch). While there is room, |
| 578 | it writes the command into that buffer itself instead of calling: a root argument is a header word from the | 629 | it writes the command into that buffer itself instead of calling: a root argument is a header word from the |
diff --git a/docs/d3d12_vulkan.md b/docs/d3d12_vulkan.md index e23985ecb..91c4fd333 100644 --- a/docs/d3d12_vulkan.md +++ b/docs/d3d12_vulkan.md | |||
| @@ -337,16 +337,17 @@ What is implemented (all of it testable without the game): | |||
| 337 | - **UAV clears** (`ClearUnorderedAccessViewUint` / `ClearUnorderedAccessViewFloat`). The CPU handle's slot is read | 337 | - **UAV clears** (`ClearUnorderedAccessViewUint` / `ClearUnorderedAccessViewFloat`). The CPU handle's slot is read |
| 338 | while recording as the GFX10 descriptor a shader would load (section 3.4), so the clear works with any | 338 | while recording as the GFX10 descriptor a shader would load (section 3.4), so the clear works with any |
| 339 | view-creation code that writes them and with descriptors the game builds itself; the GPU handle is not needed. | 339 | view-creation code that writes them and with descriptors the game builds itself; the GPU handle is not needed. |
| 340 | A T# gives the view's format (FORMAT plus DST_SEL, which tells BGRA from RGBA), mip and layers; a 3D view clears | 340 | A T# gives the view's format (FORMAT plus DST_SEL, which tells BGRA from RGBA), mip and layers. A tagged 3D |
| 341 | every slice of its mip. A V# gives a byte range: its address minus the resource's `GetGPUVirtualAddress`, and | 341 | UAV selects `FirstWSlice` and `WSize`. An untagged 3D T# covers every slice of the bound resource's selected |
| 342 | mip. A V# gives a byte range: its address minus the resource's `GetGPUVirtualAddress`, and | ||
| 342 | NUM_RECORDS bytes (stride 0, no format: raw), records (a stride: structured) or elements (a format: typed). A view | 343 | NUM_RECORDS bytes (stride 0, no format: raw), records (a stride: structured) or elements (a format: typed). A view |
| 343 | that reaches past the end of the buffer stops there, as the hardware's bounds check would. | 344 | that reaches past the end of the buffer stops there, as the hardware's bounds check would. |
| 344 | - Values follow D3D's rules (`runtime/src/uav_clear.h`): Uint copies the low bits of each value into its channel | 345 | - Values follow D3D's rules (`runtime/src/uav_clear.h`): Uint copies the low bits of each value into its channel |
| 345 | with no conversion, whatever the format's type; Float converts (UNORM/SNORM clamp and round to nearest, NaN is | 346 | with no conversion, whatever the format's type; Float converts (UNORM/SNORM clamp and round to nearest, NaN is |
| 346 | 0; 16-bit and the packed 11/10-bit floats round to nearest even). A raw or structured view takes value 0 for | 347 | 0; 16-bit and the packed 11/10-bit floats round toward zero, a finite value too large becoming the largest |
| 347 | every 32-bit word (Float: its bits). D3D11 calls Float on an integer view invalid and D3D12 does not say; here | 348 | finite). A raw or structured view takes value 0 for every 32-bit word (Float: its bits). D3D11 calls Float on an |
| 348 | the value is converted (toward zero, clamped, NaN 0) so the result is defined. These are checked against | 349 | integer view invalid and D3D12 does not say; here the value is converted (toward zero, clamped, NaN 0) so the |
| 349 | hand-computed elements in `d3d12_uav_clear_test`. | 350 | result is defined. These are checked against hand-computed elements in `d3d12_uav_clear_test`. |
| 350 | - Buffers: elements of up to 4 bytes repeat in every aligned word, so `vkCmdFillBuffer` writes the aligned middle | 351 | - Buffers: elements of up to 4 bytes repeat in every aligned word, so `vkCmdFillBuffer` writes the aligned middle |
| 351 | and `vkCmdCopyBuffer` copies the unaligned ends from it (an 8-bit view at an odd offset, say). 8- and 16-byte | 352 | and `vkCmdCopyBuffer` copies the unaligned ends from it (an 8-bit view at an odd offset, say). 8- and 16-byte |
| 352 | elements are written with `vkCmdUpdateBuffer` (up to 64 KiB) and doubled with copies. A rectangle is an | 353 | elements are written with `vkCmdUpdateBuffer` (up to 64 KiB) and doubled with copies. A rectangle is an |
| @@ -366,16 +367,18 @@ What is implemented (all of it testable without the game): | |||
| 366 | - Textures: the values become one element of the view's format, and that element is cleared into the image as | 367 | - Textures: the values become one element of the view's format, and that element is cleared into the image as |
| 367 | the value that decodes it in the image's own format, so a typeless texture viewed as UINT gets exactly the bits | 368 | the value that decodes it in the image's own format, so a typeless texture viewed as UINT gets exactly the bits |
| 368 | asked for. Exact for every typed-UAV format except the SNORM pattern `0x80..` (Vulkan writes -1.0 as `0x81..`) | 369 | asked for. Exact for every typed-UAV format except the SNORM pattern `0x80..` (Vulkan writes -1.0 as `0x81..`) |
| 369 | and NaN payloads. A whole view is `vkCmdClearColorImage`; rectangles are `vkCmdClearAttachments` in a | 370 | and NaN payloads on the Vulkan color-clear paths. A whole, matching-format 3D mip uses `vkCmdClearColorImage`. |
| 370 | dynamic-rendering scope, so a texture created with `ALLOW_UNORDERED_ACCESS` also gets `COLOR_ATTACHMENT` usage | 371 | Direct lists can use `vkCmdClearAttachments` for rectangles on attachment-capable 1D/2D images. |
| 371 | when its format supports it. Both run in place in `GENERAL`, the UAV layout. Rectangle clears of volumes, or of | 372 | Unpredicated partial 3D W ranges (`FirstWSlice`/`WSize`) and 3D XY rectangles use the same transfer path |
| 372 | formats without attachment support, are refused as `unsupported`. | 373 | on direct and compute lists. It encodes the clear value in the view format, fills up to 64 KiB of scratch, |
| 374 | and copies tiles one Z slice at a time in `GENERAL`. This requires matching view and backing formats, with | ||
| 375 | the existing exception for emulated `R9G9B9E5` on `R32_UINT`. | ||
| 373 | - The clear is fenced as the UAV state widened to transfers, so a following UAV barrier, transition, or enhanced | 376 | - The clear is fenced as the UAV state widened to transfers, so a following UAV barrier, transition, or enhanced |
| 374 | barrier from `SYNC_CLEAR_UNORDERED_ACCESS_VIEW` sees it. | 377 | barrier from `SYNC_CLEAR_UNORDERED_ACCESS_VIEW` sees it. |
| 375 | - Under `SetPredication`, a whole-view texture clear runs as one rectangle through the attachment path, as | 378 | - Under `SetPredication`, a direct list clears an attachment-capable 1D/2D UAV through its attachment view. |
| 376 | render-target clears do, so conditional rendering applies. Buffer clears, and texture clears that cannot use an | 379 | A whole view becomes one rectangle so conditional rendering applies. Buffer clears and the direct-list |
| 377 | attachment, are transfers that conditional rendering does not cover; they run unconditionally and are counted | 380 | whole-mip transfer fallback run unconditionally and count toward `unpredicated_copies`. Direct and compute |
| 378 | with the copies (`unpredicated_copies`). | 381 | lists refuse predicated partial-W or rectangular 3D clears before submission. |
| 379 | - **Layout tracking** (`LayoutTracker`): the current Vulkan layout of every image subresource, so barriers start | 382 | - **Layout tracking** (`LayoutTracker`): the current Vulkan layout of every image subresource, so barriers start |
| 380 | from the real layout instead of the application's `before`. This is how implicit promotion and decay work: a | 383 | from the real layout instead of the application's `before`. This is how implicit promotion and decay work: a |
| 381 | texture in `COMMON` sits in `GENERAL`, which every promotable access can use, so a later barrier naming the | 384 | texture in `COMMON` sits in `GENERAL`, which every promotable access can use, so a later barrier naming the |
| @@ -484,6 +487,13 @@ What is implemented (all of it testable without the game): | |||
| 484 | `E_INVALIDARG` for such a render target, since no other format can view its image. Without that format, | 487 | `E_INVALIDARG` for such a render target, since no other format can view its image. Without that format, |
| 485 | render targets are refused as before; depth-stencil and UAV creation are | 488 | render targets are refused as before; depth-stencil and UAV creation are |
| 486 | unsupported for this format. | 489 | unsupported for this format. |
| 490 | - A `CopyTextureRegion` of the depth plane between two depth formats with the same depth encoding but not the | ||
| 491 | same `VkFormat` (`D32_SFLOAT_S8_UINT` and `D32_SFLOAT`, `D16_UNORM_S8_UINT` and `D16_UNORM`, | ||
| 492 | `D24_UNORM_S8_UINT` and `X8_D24_UNORM_PACK32`) goes image → transfer scratch → image too, depth aspect on both | ||
| 493 | sides (`vulkan_replay.h`, `depth_format_pair`; `replay_copy_offset_test`). `vkCmdCopyImage` requires | ||
| 494 | depth/stencil formats to match exactly (`VUID-vkCmdCopyImage-srcImage-01548`), and an NVIDIA driver (RTX 4070 | ||
| 495 | Laptop, 621.40) handed the `D32_SFLOAT_S8_UINT` → `D32_SFLOAT` pair wrote past the end of the `D32_SFLOAT` | ||
| 496 | image: the world-start `WRITE_INVALID` device loss, with the fault at the first byte after the image. | ||
| 487 | - reserved resources and `GetResourceTiling` (section 4.2); | 497 | - reserved resources and `GetResourceTiling` (section 4.2); |
| 488 | - query heaps for occlusion, timestamps and pipeline statistics, and `GetTimestampFrequency` on the queue | 498 | - query heaps for occlusion, timestamps and pipeline statistics, and `GetTimestampFrequency` on the queue |
| 489 | (section 4.6); | 499 | (section 4.6); |
| @@ -500,8 +510,36 @@ What is implemented (all of it testable without the game): | |||
| 500 | and the initial state or `D3D12_BARRIER_LAYOUT` is not used, because new textures start `UNDEFINED` and move | 510 | and the initial state or `D3D12_BARRIER_LAYOUT` is not used, because new textures start `UNDEFINED` and move |
| 501 | on first use. The newer arguments are answered as the PC runtime answers them. `d3d12_method_variants_test` | 511 | on first use. The newer arguments are answered as the PC runtime answers them. `d3d12_method_variants_test` |
| 502 | compares each answer below with the host runtime live, measured on an RTX 4090 (driver 621.14): | 512 | compares each answer below with the host runtime live, measured on an RTX 4090 (driver 621.14): |
| 503 | - `CreateCommandSignature` (`ID3D12CommandSignature`) and `ID3D12GraphicsCommandList::ExecuteIndirect` (including | 513 | - `CreateCommandSignature` and `ExecuteIndirect`: a signature consisting of a single DRAW or DRAW_INDEXED |
| 504 | GPU-written `CountBuffer` via Vulkan 1.2 core `vkCmdDrawIndirectCount` / `vkCmdDrawIndexedIndirectCount`). | 514 | operation inherits the graphics state of its command list. The Vulkan replay snapshots the same pipeline, root |
| 515 | data, render targets, IA bindings and raster state as a direct draw, then reads the records on the GPU inside | ||
| 516 | that draw's rendering scope. A padded stride is supported; it is not evidence that a signature is simple. | ||
| 517 | A compound graphics signature still emits no draw, but its written VB/IB and root bindings are reset for the | ||
| 518 | next command, even if no record is interpreted. Untouched slots and previously recorded draws retain their state. | ||
| 519 | See the [D3D12 state-leakage contract](https://microsoft.github.io/DirectX-Specs/d3d/IndirectDrawing.html#state-leakage). | ||
| 520 | Fixed- and GPU-counted batches use the device's enabled indirect features and limits. The current graphics | ||
| 521 | path covers triangle lists on direct command lists. A bundle can defer a single operation with no count | ||
| 522 | buffer: its argument-buffer identity and byte offset are recorded once; each `ExecuteBundle` captures the | ||
| 523 | 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 | pixels with two different parent bindings; the layer fixture also checks marker order and captured views. | ||
| 526 | Compound graphics signatures, non-unit instance divisors | ||
| 527 | 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. | ||
| 529 | To omit indirect graphics without changing direct drawing or compute, set | ||
| 530 | `LEONIDA_INDIRECT_DRAWS=off` before starting the process. This applies to the Vulkan-backed D3D12 | ||
| 531 | command list, including ordinary bundle draws when replayed on a parent. Validation and compound | ||
| 532 | root/IA resets still happen. Only exact lowercase `off` disables drawing; unset, empty, and other | ||
| 533 | values (including the old `raw` spelling) retain the normal capability-checked path. There is no | ||
| 534 | bare draw mode. The former `raw` setting logs an obsolescence notice on first policy use. | ||
| 535 | Each skip reason logs once. Progress lines give cumulative recorded commands, Vulkan emissions, | ||
| 536 | recording skips and replay skips. Replaying a command list can emit a recorded command more than once. | ||
| 537 | By default, a GPU pass bounds draw vertex/index and instance counts, dispatch group counts, and total | ||
| 538 | work across each command list (2^27 units). Unfilled all-ones records produce zero work and spend no budget. | ||
| 539 | Cumulative observed clamp and zero counts are reported every 60 presented frames. Counted calls read at most MaxCommandCount records. The stateful draw or dispatch reads | ||
| 540 | private scratch. Exhausting the diagnostic counter slots only disables readback of those counters. | ||
| 541 | `LEONIDA_INDIRECT_CLAMP=0` disables this pass. `LEONIDA_INDIRECT_GROUP_BUDGET=N` further bounds each | ||
| 542 | indirect dispatch, preserving X first, then Y and Z (1–65535 groups). It also works with the clamp disabled. | ||
| 505 | - Optional `VK_KHR_acceleration_structure` + `VK_KHR_deferred_host_operations` + `VK_KHR_ray_query`: | 543 | - Optional `VK_KHR_acceleration_structure` + `VK_KHR_deferred_host_operations` + `VK_KHR_ray_query`: |
| 506 | `ID3D12Device5::GetRaytracingAccelerationStructurePrebuildInfo`, `ID3D12GraphicsCommandList4::BuildRaytracingAccelerationStructure` | 544 | `ID3D12Device5::GetRaytracingAccelerationStructurePrebuildInfo`, `ID3D12GraphicsCommandList4::BuildRaytracingAccelerationStructure` |
| 507 | (BLAS + TLAS), `vkGetBufferDeviceAddress` in `ID3D12Resource::GetGPUVirtualAddress()`, and RT-aware `UAV` | 545 | (BLAS + TLAS), `vkGetBufferDeviceAddress` in `ID3D12Resource::GetGPUVirtualAddress()`, and RT-aware `UAV` |
| @@ -674,7 +712,16 @@ side inwards: | |||
| 674 | storage view gets an index the storage arrays hold, and a read-only one goes above where there is room. | 712 | storage view gets an index the storage arrays hold, and a read-only one goes above where there is room. |
| 675 | Index 0 is reserved, so 256 descriptors hold 255 live views in each 1D-array storage binding. | 713 | Index 0 is reserved, so 256 descriptors hold 255 live views in each 1D-array storage binding. |
| 676 | - Index 0 of every array is a fallback (a 1x1 image of zeros, a nearest clamping sampler), because a miss is | 714 | - Index 0 of every array is a fallback (a 1x1 image of zeros, a nearest clamping sampler), because a miss is |
| 677 | index 0. | 715 | index 0. It stands for a null descriptor (a zero T#, an empty heap slot, a view the layer refused) and is of |
| 716 | the kind the instruction asks for: the translator picks the binding by the instruction's dimension (a cube | ||
| 717 | reads the 2D-array binding) and the view by the T#'s class, so each dimension and class reads zeros. The | ||
| 718 | storage arrays' fallbacks never share an image with the sampled ones, so a store or atomic through a null | ||
| 719 | UAV cannot show in a later read through a null SRV. Where the device has `VK_EXT_robustness2`'s | ||
| 720 | `nullDescriptor` (`VulkanDeviceInfo::null_descriptor`, enabled alone) they are null descriptors, and the | ||
| 721 | store or atomic is dropped and a load reads zero, as on the console; without it they are 1x1 images of their | ||
| 722 | own. A null V# (all zeros) needs no fallback: every access through it is out of range (`NUM_RECORDS` 0), so | ||
| 723 | loads give 0 and stores and atomics do nothing (`tests/semantic/test_null_vsharp.py`). Checked on the GPU by | ||
| 724 | `vk_null_descriptor_test` (every dimension and class, both kinds of storage fallback). | ||
| 678 | - Changes are queued and written by `flush()`, one write a slot, so a view that is removed before the next | 725 | - Changes are queued and written by `flush()`, one write a slot, so a view that is removed before the next |
| 679 | flush is never written. | 726 | flush is never written. |
| 680 | - `flush()` also uploads the table to its buffer: device-local memory, written from a mapped staging copy when | 727 | - `flush()` also uploads the table to its buffer: device-local memory, written from a mapped staging copy when |
| @@ -741,7 +788,14 @@ descriptor, as D3D12 refuses it), and stencil-plane views (`PlaneSlice` 1, as | |||
| 741 | `X24_TYPELESS_G8_UINT` or `X32_TYPELESS_G8X24_UINT`) are an 8_UINT T# that set 0 shows through the stencil | 788 | `X24_TYPELESS_G8_UINT` or `X32_TYPELESS_G8X24_UINT`) are an 8_UINT T# that set 0 shows through the stencil |
| 742 | aspect, in its float-typed sampled arrays like other single-sampled UINT views. Other gaps include descriptors | 789 | aspect, in its float-typed sampled arrays like other single-sampled UINT views. Other gaps include descriptors |
| 743 | the game writes itself, which need | 790 | the game writes itself, which need |
| 744 | the execute-time scan of section 3.4 (only descriptors made through the device are registered); the literal S#s of shaders (`literal_samplers` in the index), | 791 | the execute-time scan of section 3.4 (only descriptors made through the device are registered). A retail |
| 792 | descriptor heap census (BL-4, measuring the primary 1,245,184-slot console CBV/SRV/UAV heap across submissions | ||
| 793 | 50, 500, and 5000 on RTX 5070 / Windows 11) confirms the slot distribution: 910,244 empty slots; 327,543 single-dword | ||
| 794 | free-list links (`value = slot_index + 1`, ending at `0xFFFFFFFF`); 261 T# with layer-assigned addresses above 4 GiB; | ||
| 795 | 5,840 V# (3,024 with a null base, 2,816 with a sub-4-GiB arena base); 1,296 slots containing interleaved constant data | ||
| 796 | (IEEE-754 floats); and zero bare 32-bit GPU addresses. Console descriptors do not store standalone 32-bit pointer words; | ||
| 797 | buffer and image base addresses are packed into standard 48-bit V# and T# records conforming to the arena layout | ||
| 798 | (modeled by model-level reference contract suite `tests/test_descriptor_address_translation.py`); the literal S#s of shaders (`literal_samplers` in the index), | ||
| 745 | which `rt::d3d12::register_samplers` registers without a heap slot but which nothing passes to it yet (the call at | 799 | which `rt::d3d12::register_samplers` registers without a heap slot but which nothing passes to it yet (the call at |
| 746 | pipeline creation comes with the shader index, #291); | 800 | pipeline creation comes with the shader index, #291); |
| 747 | custom border colours without VK_EXT_custom_border_color, and minimum/maximum filters, anisotropy or mirror-once addressing without the Vulkan | 801 | custom border colours without VK_EXT_custom_border_color, and minimum/maximum filters, anisotropy or mirror-once addressing without the Vulkan |
| @@ -835,6 +889,17 @@ The compute path, end to end: | |||
| 835 | `LEONIDA_ARENA_LOG=1` also logs one line per VA handed out, per refused allocation, and per upload or readback | 889 | `LEONIDA_ARENA_LOG=1` also logs one line per VA handed out, per refused allocation, and per upload or readback |
| 836 | buffer VA outside the arena. | 890 | buffer VA outside the arena. |
| 837 | - Default-heap buffers are 64 KiB-aligned ranges in it, zeroed through its mapping; their console VA is the offset. | 891 | - Default-heap buffers are 64 KiB-aligned ranges in it, zeroed through its mapping; their console VA is the offset. |
| 892 | - Every access to its free-block map is under the arena's mutex, and a walk holds no iterator across a call | ||
| 893 | (`runtime/src/arena_blocks.h`): each step reads a block's offset and size, lets its iterator go, looks the next | ||
| 894 | block up from the map again, and re-finds a candidate by offset before it cuts it. A map access outside the lock | ||
| 895 | makes a concurrent walk step into a node an insert rebalanced away or a release freed — measured once: an access | ||
| 896 | violation reading the nil flag of a null map child at 0x19, inside `arena_allocate` for a slot-133 shadow buffer | ||
| 897 | (the arena's first block used to be inserted by `create_arena` with no lock, and an insert rewrites child links). | ||
| 898 | The arena checks `free + live == size - reserved` on every allocation and release (O(1)) and walks the whole | ||
| 899 | block map only when that fails or `LEONIDA_ARENA_CHECK=1` is set; a `double_free` or a release of a range past | ||
| 900 | the arena (`outside_arena`) is reported instead of being let into the map, and those lines are rate-limited to | ||
| 901 | one per 5 s. `arena_blocks_test` (CPU) covers first fit, coalescing, a title keep-out, the walk cut under it, the | ||
| 902 | bad releases and one lock with many threads. | ||
| 838 | - Shader-visible descriptor heaps also live in it: the CPU handle is its host mapping and the GPU handle is the VA, | 903 | - Shader-visible descriptor heaps also live in it: the CPU handle is its host mapping and the GPU handle is the VA, |
| 839 | so descriptor bytes the application writes itself are what shaders load. | 904 | so descriptor bytes the application writes itself are what shaders load. |
| 840 | - Upload and readback buffers keep their own memory, and their VA is their device address minus the heap base. | 905 | - Upload and readback buffers keep their own memory, and their VA is their device address minus the heap base. |
| @@ -1221,11 +1286,22 @@ and any validation error fails them. | |||
| 1221 | `IDXGIFactory4::CreateSwapChainForHwnd`, `IDXGISwapChain3::GetCurrentBackBufferIndex`, `GetBuffer` + `GetDesc()`, | 1286 | `IDXGIFactory4::CreateSwapChainForHwnd`, `IDXGISwapChain3::GetCurrentBackBufferIndex`, `GetBuffer` + `GetDesc()`, |
| 1222 | backbuffer `CreateRenderTargetView` + clear + readback verification + `Present`, and `ResizeBuffers` with 0 | 1287 | backbuffer `CreateRenderTargetView` + clear + readback verification + `Present`, and `ResizeBuffers` with 0 |
| 1223 | validation errors. | 1288 | validation errors. |
| 1289 | - `d3d12_stateful_indirect_pixels`, `d3d12_stateful_indirect_multi_pixels` and | ||
| 1290 | `d3d12_stateful_indirect_counted_pixels`: positive D3D12-to-Vulkan graphics tests. Compare every readback | ||
| 1291 | pixel with both a direct-draw reference and a known pattern for each draw kind; the counted variant fills | ||
| 1292 | its argument and count buffers by GPU copy before use. | ||
| 1224 | - `d3d12_indirect_rt_test`: validates `ID3D12Device::CreateCommandSignature` + `ExecuteIndirect` with a GPU | 1293 | - `d3d12_indirect_rt_test`: validates `ID3D12Device::CreateCommandSignature` + `ExecuteIndirect` with a GPU |
| 1225 | `CountBuffer` (`vkCmdDrawIndirectCount`, `count = 0` skipped and `count = 1` rendered) and optional | 1294 | `CountBuffer` (`vkCmdDrawIndirectCount`, `count = 0` skipped and `count = 1` rendered), a draw whose record asks |
| 1295 | for four billion instances (clamped on the GPU, section 4.7), and a native Vulkan counted-draw reference over the | ||
| 1296 | same suballocated argument/count offsets (`count = 0` leaves the clear colour, `count = 1` renders; it is | ||
| 1297 | independent of the D3D12 command replay); optional | ||
| 1226 | `VK_KHR_acceleration_structure` + `VK_KHR_ray_query` (`GetRaytracingAccelerationStructurePrebuildInfo`, BLAS + TLAS | 1298 | `VK_KHR_acceleration_structure` + `VK_KHR_ray_query` (`GetRaytracingAccelerationStructurePrebuildInfo`, BLAS + TLAS |
| 1227 | `BuildRaytracingAccelerationStructure`, and a `RayQueryKHR` compute shader verifying hit vs. miss; clean SKIP on | 1299 | `BuildRaytracingAccelerationStructure`, and a `RayQueryKHR` compute shader verifying hit vs. miss; clean SKIP on |
| 1228 | GPUs without RT). | 1300 | GPUs without RT). |
| 1301 | - `indirect_clamp_test`: the `ExecuteIndirect` argument clamp pass itself (section 4.7), with no game files: every | ||
| 1302 | argument kind (draw, draw indexed, dispatch, mesh dispatch) and the counted variants, in-range records | ||
| 1303 | bit-identical, garbage records bounded, records and counts past `max_command_count` empty, and the per-batch work | ||
| 1304 | budget saturating; clean SKIP without a Vulkan device. | ||
| 1229 | - `d3d12_gcl8_test`: the public `ID3D12GraphicsCommandList8` surface: `QueryInterface` for its IID, | 1305 | - `d3d12_gcl8_test`: the public `ID3D12GraphicsCommandList8` surface: `QueryInterface` for its IID, |
| 1230 | `OMSetFrontAndBackStencilRef(1, 2)` with the recorded values, and the reference count around the query. It | 1306 | `OMSetFrontAndBackStencilRef(1, 2)` with the recorded values, and the reference count around the query. It |
| 1231 | creates only an allocator and a list, so it needs no GPU or Vulkan loader. | 1307 | creates only an allocator and a list, so it needs no GPU or Vulkan loader. |
| @@ -1621,6 +1697,18 @@ The copies: | |||
| 1621 | cannot fit between the title's address reservations can use a separate mapped buffer. The buffer's device address | 1697 | cannot fit between the title's address reservations can use a separate mapped buffer. The buffer's device address |
| 1622 | must fit as a positive 47-bit offset from the arena base. The same window cap and dirty-page refresh apply. | 1698 | must fit as a positive 47-bit offset from the arena base. The same window cap and dirty-page refresh apply. |
| 1623 | `LEONIDA_STREAM_BUFFER_WINDOWS=0` requires the window to fit in the arena. | 1699 | `LEONIDA_STREAM_BUFFER_WINDOWS=0` requires the window to fit in the arena. |
| 1700 | - A **window that is refused** (the budget is spent, the arena is full, or the pages are not committed yet) is backed | ||
| 1701 | by a persistent geometry copy of exactly the requested range (`LEONIDA_GEOMETRY_MB`) instead; when no copy can be | ||
| 1702 | made either, the view is written with **no base and no records** — loads return 0 and stores are dropped. A raw | ||
| 1703 | title address is never left in a V# or a root view: `heap_base + a raw VA` is not an allocation, and a store there | ||
| 1704 | loses the device. The refusal and the count of zero-size views are logged. | ||
| 1705 | - A **stream pool** (the title's CPU view paired with a 16-24 GiB GPU-only | ||
| 1706 | alias) is not windowed per request. The GPU-only pages are translated to the CPU view of the same frames (rule B in | ||
| 1707 | that note), and **one mapping serves a page-aligned readable run** of the pool (at most 1 MiB, a geometry copy when | ||
| 1708 | the cap allows, a window otherwise). Both addresses of the pair are entered in the table, so a V# naming either | ||
| 1709 | reaches that one mapping instead of asking for a second one; `LEONIDA_GEOMETRY_MB` is the preferred backing. | ||
| 1710 | Acceleration-structure destinations and scratch also resolve through the table, and a structure no window holds | ||
| 1711 | whole gets a copy of its whole range, so the BVH builder's commands are recorded. | ||
| 1624 | - `LEONIDA_GEOMETRY_MB` sets the device-local memory cap for streamed buffer views. The default is 0. | 1712 | - `LEONIDA_GEOMETRY_MB` sets the device-local memory cap for streamed buffer views. The default is 0. |
| 1625 | A positive cap enables persistent copies of placed buffer SRVs and buffer descriptors in title memory. | 1713 | A positive cap enables persistent copies of placed buffer SRVs and buffer descriptors in title memory. |
| 1626 | A GPU-only reservation uses its paired CPU mapping. Matching source ranges share one copy. | 1714 | A GPU-only reservation uses its paired CPU mapping. Matching source ranges share one copy. |
| @@ -1679,6 +1767,15 @@ The runtime allocates image keys from `0x100000000` (4 GiB) in 256-byte steps, a | |||
| 1679 | heap of 256 MiB or less (214 MiB on an RTX 3090 with driver 616.56), so the 256 MiB default arena lands in | 1767 | heap of 256 MiB or less (214 MiB on an RTX 3090 with driver 616.56), so the 256 MiB default arena lands in |
| 1680 | system memory there. Asking that heap for it broke VUID-vkAllocateMemory-pAllocateInfo-01713 even though the | 1768 | system memory there. Asking that heap for it broke VUID-vkAllocateMemory-pAllocateInfo-01713 even though the |
| 1681 | driver returned `VK_SUCCESS` (reported by CharlyRien). | 1769 | driver returned `VK_SUCCESS` (reported by CharlyRien). |
| 1770 | - With Resizable BAR a driver can still leave the `DEVICE_LOCAL | HOST_VISIBLE` type out of a large buffer's | ||
| 1771 | `memoryTypeBits`. On an RTX 5070 Ti (NVIDIA 617.42, Windows 11) an arena-shaped buffer of 4,090 MiB may use | ||
| 1772 | it and one of 4,092 MiB may not, so `LEONIDA_ARENA_MB=4096` (4,095 MiB) put the whole arena in system memory. | ||
| 1773 | `create_arena` tries smaller sizes in 16 MiB steps, by at most an eighth, and keeps the largest whose | ||
| 1774 | requirements allow that type and fit its heap. Placing the arena in ReBAR does not guarantee a reduction in | ||
| 1775 | host commit. An [RTX 4080 comparison](https://github.com/ubiquitarianism/leonida/pull/1732#issuecomment-7159574385) | ||
| 1776 | confirmed ReBAR placement and measured higher process private bytes. The runtime logs the size cap: | ||
| 1777 | `GPU address arena: 4080 MiB of the 4095 MiB asked for, capped by the device's Resizable BAR memory types`. | ||
| 1778 | Without Resizable BAR nothing changes. | ||
| 1682 | - M4+: allocate the arena `DEVICE_LOCAL` and stage CPU writes (descriptor heaps, shader blobs, buffer uploads) | 1779 | - M4+: allocate the arena `DEVICE_LOCAL` and stage CPU writes (descriptor heaps, shader blobs, buffer uploads) |
| 1683 | through a host-visible staging buffer, copied before the commands that use them. The hash table is not in the | 1780 | through a host-visible staging buffer, copied before the commands that use them. The hash table is not in the |
| 1684 | arena either: it is a normal storage buffer in `DEVICE_LOCAL` memory, uploaded from a mapped staging copy before | 1781 | arena either: it is a normal storage buffer in `DEVICE_LOCAL` memory, uploaded from a mapped staging copy before |
| @@ -1754,7 +1851,10 @@ The game can use D3D12 descriptors in three ways, and the layer must handle all | |||
| 1754 | No sampler-indexing entry had a matched layout. Putting the resource heap first when both flags are set, then the | 1851 | No sampler-indexing entry had a matched layout. Putting the resource heap first when both flags are set, then the |
| 1755 | sampler in the next dword, remains a hypothesis. D3D-329's adjacent SGPR examples alone do not establish it. | 1852 | sampler in the next dword, remains a hypothesis. D3D-329's adjacent SGPR examples alone do not establish it. |
| 1756 | The runtime snapshots the bound resource and sampler heap pointers in that order after the explicit | 1853 | The runtime snapshots the bound resource and sampler heap pointers in that order after the explicit |
| 1757 | arguments for direct and indirect compute dispatches with an inline signature. An unbound heap contributes | 1854 | arguments for direct and indirect compute dispatches with an inline signature. Bound console descriptor heap |
| 1855 | base addresses are remapped through `console_descriptor_table_va` so that user SGPRs receive the arena copy's | ||
| 1856 | shader virtual address (where GPU descriptor reads land, preventing `READ_INVALID` device loss during world | ||
| 1857 | load), while unshadowed host heaps remain unchanged. An unbound heap contributes | ||
| 1758 | zero, and rebinding affects later commands. A heap that cannot fit in the inline user data is reported once, | 1858 | zero, and rebinding affects later commands. A heap that cannot fit in the inline user data is reported once, |
| 1759 | and a signature whose compute arguments spill gets nothing written (logged once). Set | 1859 | and a signature whose compute arguments spill gets nothing written (logged once). Set |
| 1760 | `LEONIDA_COMPUTE_DIRECT_HEAPS=0` to restore the previous compute arguments. | 1860 | `LEONIDA_COMPUTE_DIRECT_HEAPS=0` to restore the previous compute arguments. |
| @@ -1769,11 +1869,18 @@ The game can use D3D12 descriptors in three ways, and the layer must handle all | |||
| 1769 | and mesh from s16 (issue #14, comment 7143020922, on a `boot-prototype` run; not reproduced in this | 1869 | and mesh from s16 (issue #14, comment 7143020922, on a `boot-prototype` run; not reproduced in this |
| 1770 | repository). A mesh signature that fills the window leaves no room there: a heap past s31 of the mesh shader | 1870 | repository). A mesh signature that fills the window leaves no room there: a heap past s31 of the mesh shader |
| 1771 | (push dword 24 or later) is logged once. A signature that keeps the s0 graphics layout, or whose arguments fill | 1871 | (push dword 24 or later) is logged once. A signature that keeps the s0 graphics layout, or whose arguments fill |
| 1772 | s31, gets none (logged once). `d3d12_graphics_direct_heaps_test` checks the recorded draws and what a vertex | 1872 | s31, gets none (logged once). `d3d12_graphics_direct_heaps_test` checks the recorded draws and reads back |
| 1773 | and a pixel shader read, with and without the flags; `d3d12_mesh_test` checks that a mesh draw records the | 1873 | what vertex and pixel shaders saw with and without the flags. On a mesh-capable device it also checks the |
| 1774 | vertex draw's dwords, a resource-only rebind, a signature ending at s30 and one on the s0 layout (recorded | 1874 | heap pointers read by the mesh and pixel stages after a rebind. `d3d12_mesh_test` checks the recorded dwords |
| 1775 | arguments only; no GPU read through a mesh shader). Set `LEONIDA_GRAPHICS_DIRECT_HEAPS=0` to restore the | 1875 | for a vertex draw, a resource-only rebind, a signature ending at s30 and one on the s0 layout. |
| 1776 | previous draw arguments. | 1876 | Set `LEONIDA_GRAPHICS_DIRECT_HEAPS=0` to restore the previous draw arguments. |
| 1877 | Missing console V# backing leaves a settled zero descriptor. Every 32 submissions a heap probes up to | ||
| 1878 | eight of these slots in round-robin order, including independent UAV-counter failures. | ||
| 1879 | Console resource heap copies and shader-visible CBV/SRV/UAV heaps with at least 65,536 slots request | ||
| 1880 | 64 MiB of zeroed padding after their last descriptor. `LEONIDA_HEAP_GUARD_MB` sets the padding in MiB | ||
| 1881 | (0 disables it). When arena space is tight, allocation can fall back to the heap alone. Only indices | ||
| 1882 | inside the reserved padding read null slots. Console slots containing data instead of a recognized image | ||
| 1883 | or buffer descriptor have their first 16 bytes cleared in the GPU copy. The title keeps its original bytes. | ||
| 1777 | 3. **Game-built descriptor memory.** The game writes raw T#/S# bytes into a heap itself, without calling | 1884 | 3. **Game-built descriptor memory.** The game writes raw T#/S# bytes into a heap itself, without calling |
| 1778 | `CreateShaderResourceView`. The shaders then read those bytes exactly as in case 1. | 1885 | `CreateShaderResourceView`. The shaders then read those bytes exactly as in case 1. |
| 1779 | 1886 | ||
| @@ -1873,8 +1980,8 @@ The layer's descriptor model: | |||
| 1873 | The emulated RGB9E5 raw `R32_UINT` storage view is formatted and is exempt. Vulkan 1.3 permits these SPIR-V | 1980 | The emulated RGB9E5 raw `R32_UINT` storage view is formatted and is exempt. Vulkan 1.3 permits these SPIR-V |
| 1874 | capabilities even without the legacy `shaderStorageImage{Read,Write}WithoutFormat` feature bits. The | 1981 | capabilities even without the legacy `shaderStorageImage{Read,Write}WithoutFormat` feature bits. The |
| 1875 | caller-owned device test leaves both legacy bits off and masks each per-format bit to verify safe rejection. | 1982 | caller-owned device test leaves both legacy bits off and masks each per-format bit to verify safe rejection. |
| 1876 | `ClearUnorderedAccessView*` refuses partial W ranges and 1D/3D format reinterprets: the transfer clear | 1983 | `ClearUnorderedAccessView*` reads the W range from these descriptor bytes even after a descriptor copy. |
| 1877 | cannot target a slice interval or guarantee preserving the reinterpreted bits. | 1984 | General 1D/3D backing-format reinterpretation remains unsupported. |
| 1878 | Shader access to the new UAVs requires `robustImageAccess` (whole-mip CPU clears do not). | 1985 | Shader access to the new UAVs requires `robustImageAccess` (whole-mip CPU clears do not). |
| 1879 | A separate native D3D12 probe on the RTX 4090 and UHD 770 clipped typed writes to the view's W range. | 1986 | A separate native D3D12 probe on the RTX 4090 and UHD 770 clipped typed writes to the view's W range. |
| 1880 | WARP 10.0.26100.9818 rebased the view but did not clip writes past a finite `WSize` in that probe. The | 1987 | WARP 10.0.26100.9818 rebased the view but did not clip writes past a finite `WSize` in that probe. The |
| @@ -2068,7 +2175,21 @@ sets them, and it does so twice. | |||
| 2068 | 2175 | ||
| 2069 | `amd_fidelityfx_upscaler_xbox.dll` does neither. Its 29 `RTS0` parts carry `Flags = 0`, and no instruction in it uses | 2176 | `amd_fidelityfx_upscaler_xbox.dll` does neither. Its 29 `RTS0` parts carry `Flags = 0`, and no instruction in it uses |
| 2070 | the constant `0x3000000`. So the bits are not a property of every console root signature; this builder adds them. The | 2177 | the constant `0x3000000`. So the bits are not a property of every console root signature; this builder adds them. The |
| 2071 | game executable is not in the package, so whether its root signatures carry them is open. | 2178 | retail executable's root signatures do not carry them either (old upstream PR 7140): its direct call passes a 1.1 |
| 2179 | description with `Flags = 0x80` (`LOCAL_ROOT_SIGNATURE`), and its root-signature decoder reads `Flags` as a | ||
| 2180 | zero-extended 16-bit value. | ||
| 2181 | |||
| 2182 | The mask stays unconditional, because it can't touch a public flag: it clears bits 24-31 | ||
| 2183 | (`kXboxRootSignatureFlagHighByte`, `runtime/shims/d3d12_xs_rootsig.h`), and every public | ||
| 2184 | `D3D12_ROOT_SIGNATURE_FLAGS` value is in bits 0-11 (the highest is `SAMPLER_HEAP_DIRECTLY_INDEXED`, `0x800`). So it is | ||
| 2185 | safe on every descriptor and blob, whatever built it. `root_sig_public_flags_test` pins this: | ||
| 2186 | |||
| 2187 | - the helpers keep every flag value in `[0, 0xFFFF]`; | ||
| 2188 | - the shims' serializers give the host's blob byte for byte for each public flag the host takes. Where the host | ||
| 2189 | refuses only `CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED` or `SAMPLER_HEAP_DIRECTLY_INDEXED` (Windows 10's in-box `d3d12.dll`), | ||
| 2190 | they serialize on purpose: the blob is the host's blob without those bits, with the full flags in `RTS0` and a valid | ||
| 2191 | container hash (`kDirectlyIndexedFlags`, `runtime/shims/d3d12_xs_rootsig.h`); | ||
| 2192 | - a blob with `0x03000080` comes back as `0x80`. | ||
| 2072 | 2193 | ||
| 2073 | **Version 1.2 on older runtimes.** The in-box `d3d12.dll` of Windows 10 (measured on 22H2, 10.0.19045, without the | 2194 | **Version 1.2 on older runtimes.** The in-box `d3d12.dll` of Windows 10 (measured on 22H2, 10.0.19045, without the |
| 2074 | Agility SDK) and of Windows 11 23H2 (#361) serializes root signatures only up to 1.1. On Windows 10 it rejects even an | 2195 | Agility SDK) and of Windows 11 23H2 (#361) serializes root signatures only up to 1.1. On Windows 10 it rejects even an |
| @@ -2282,7 +2403,12 @@ Pipeline creation: | |||
| 2282 | and pipeline-cache UUID. When the file is absent or incompatible, the runtime starts with an empty cache. | 2403 | and pipeline-cache UUID. When the file is absent or incompatible, the runtime starts with an empty cache. |
| 2283 | The offline checker matches the runtime's layout and subgroup request for compute shaders with no descriptor | 2404 | The offline checker matches the runtime's layout and subgroup request for compute shaders with no descriptor |
| 2284 | bindings and the standard 144-byte push-constant range. | 2405 | bindings and the standard 144-byte push-constant range. |
| 2285 | The runtime writes its own `pipeline_cache.session.bin` on device teardown. A compatible session file | 2406 | The runtime writes its own `pipeline_cache.session.bin` on device teardown, and, since a title never releases its |
| 2407 | device, when `gta6rt` ends with the device alive: at the run's exit, at a console close and from an | ||
| 2408 | unhandled-exception filter (a fault in the title or its DLLs, the int3 after a device loss). The title's own | ||
| 2409 | `SetUnhandledExceptionFilter` is served by the runtime, which keeps its filter first and passes the exception on. | ||
| 2410 | That exit write (`save_pipeline_caches_at_exit`, `shims/d3d12_compile_exit.h`) waits 1 s for a build still running | ||
| 2411 | on a title thread, then writes the pipelines finished so far, with 3 s for the write itself. A compatible session file | ||
| 2286 | initializes the live cache directly if there is no offline seed. With both files present the session cache | 2412 | initializes the live cache directly if there is no offline seed. With both files present the session cache |
| 2287 | merges into the offline seed. `LEONIDA_DIRECT_SESSION_CACHE=0` also uses a merge when only the session exists. | 2413 | merges into the offline seed. `LEONIDA_DIRECT_SESSION_CACHE=0` also uses a merge when only the session exists. |
| 2288 | The files must match the Vulkan vendor, device and pipeline-cache UUID. Vulkan supplies an opaque snapshot. | 2414 | The files must match the Vulkan vendor, device and pipeline-cache UUID. Vulkan supplies an opaque snapshot. |
| @@ -2296,13 +2422,112 @@ Pipeline creation: | |||
| 2296 | has no active builds. These snapshots have an additional 512 MiB ceiling. The driver fills a mapped staging | 2422 | has no active builds. These snapshots have an additional 512 MiB ceiling. The driver fills a mapped staging |
| 2297 | file directly. A successful snapshot atomically replaces the session. An interrupted write preserves the | 2423 | file directly. A successful snapshot atomically replaces the session. An interrupted write preserves the |
| 2298 | previous cache; the next launch removes unheld staging files older than ten minutes. | 2424 | previous cache; the next launch removes unheld staging files older than ten minutes. |
| 2425 | While the compute warm-up has builds queued that idle checkpoint never starts, and a boot that ends by a crash, | ||
| 2426 | a device loss or a kill never reaches teardown, so neither file used to keep that boot's compute pipelines. | ||
| 2427 | Compute pipelines are therefore journaled one file each (`src/pipeline_cache_journal.h`): | ||
| 2428 | `pipeline_cache.d/cs-<hash>.bin` beside the session file, named by a hash of the SPIR-V words, the stage flags and | ||
| 2429 | subgroup request, the push-constant range and the bindless layout. A build creates a `VkPipelineCache` from its | ||
| 2430 | file (if the header names this device and pipeline-cache UUID) and creates the pipeline against it; when the | ||
| 2431 | driver reports a compile (creation feedback without `APPLICATION_PIPELINE_CACHE_HIT`, or no file), that cache is | ||
| 2432 | written back to the file at once, through a staging file renamed over it. Without a file, and with | ||
| 2433 | `pipelineCreationCacheControl`, the shared cache is first asked with | ||
| 2434 | `VK_PIPELINE_CREATE_FAIL_ON_PIPELINE_COMPILE_REQUIRED_BIT` when it was seeded from a file, so the offline seed | ||
| 2435 | still serves a first boot. NVIDIA 630.20 answers that flag with a compiled pipeline (seconds) instead of | ||
| 2436 | `VK_PIPELINE_COMPILE_REQUIRED`, so the first answer that took 250 ms or more without the cache-hit bit stops the | ||
| 2437 | asking, and that pipeline is built again against its journal cache so it gets a file (a fast answer without the | ||
| 2438 | bit is the driver's own disk cache, and a valid one; `LEONIDA_PIPELINE_JOURNAL_ASK_SHARED=0`: never ask). All | ||
| 2439 | driver calls of a compute build (shader module, journal cache, pipeline) run in one turn of the compile gate, with | ||
| 2440 | no file I/O in it: from the journal a build takes milliseconds, the warm-up worker makes them back to back, and | ||
| 2441 | three warm boots whose cache and module calls were outside the gate lost the device in a `vkQueueSubmit` 20-25 s | ||
| 2442 | in (no GPU fault, no TDR). The files take 2-3 MiB a pipeline on that driver (about 3.6 GiB for the 1700 a boot | ||
| 2443 | builds); `LEONIDA_PIPELINE_JOURNAL_BYTES` (32 GiB by default) caps them. At a device's first pipeline, staging files | ||
| 2444 | older than ten minutes are removed and, past the budget, the least recently used files until three quarters of it | ||
| 2445 | is left: a file's modification time is its last use (written, or touched, at most hourly, when a build finds its | ||
| 2446 | pipeline there), so files no build names any more after a translator regeneration go first. | ||
| 2447 | Measured on an RTX 4070 Ti (driver 630.20): 17 compute modules of 0.6-0.7 MB SPIR-V took 222 s to compile and | ||
| 2448 | 0.04 s to create from their cache; a boot's ~1000 warm-up builds of 128 KiB or more took 81 s cold and 1.8 s from | ||
| 2449 | the journal, and the submissions' compile-gate waits went from 77 s to none. Nsight Aftermath crash dumps | ||
| 2450 | (`LEONIDA_AFTERMATH=1`) appear to make the driver compile again whatever the caches hold: boots loading the same | ||
| 2451 | 317 MB session file logged no compute build of 2 s or more without Aftermath and 88-95 with it. The | ||
| 2452 | VK_NV_device_diagnostics_config flags alone do not (vk_pipeline_check `--nv-diagnostics`: 17 of 17 cache hits). | ||
| 2453 | `LEONIDA_PIPELINE_JOURNAL=0` (or `LEONIDA_PIPELINE_CACHE_BYTES=0`) turns the journal off. | ||
| 2454 | `LEONIDA_PIPELINE_CACHE_DIR=<folder>` moves the journal with the other files, so builds of gta6rt in several | ||
| 2455 | folders can share one; the file names and the driver's checks keep a pipeline from one build from being taken | ||
| 2456 | for another's. | ||
| 2457 | `gta6rt --precompile-pipelines [--threads N] [--big-threads N] [--all] [--smallest-first] [--limit N] | ||
| 2458 | [--min-bytes N] [--max-bytes N] [--filter PART]... [--list]` fills the journal ahead of play, with no game: it | ||
| 2459 | creates the Vulkan device as `--run` does (so the same environment gives the same journal names and driver keys: | ||
| 2460 | LEONIDA_SHADERS, LEONIDA_PIPELINE_CACHE_DIR, and LEONIDA_DEVICE_FAULT/LEONIDA_AFTERMATH, whose diagnostics config | ||
| 2461 | makes other pipelines) and builds every compute entry of the library through the dispatch path | ||
| 2462 | (`build_compute_pipeline`), largest first, on below-normal-priority threads. Entries with a usable journal file are | ||
| 2463 | skipped (only their header is read), so it can be stopped and started again. Running as gta6rt.exe it also fills | ||
| 2464 | NVIDIA's disk cache, which that driver keys by the executable's name. Measured on an RTX 4070 Ti (driver 630.20), | ||
| 2465 | 4 threads: modules of 3.6-5.8 MB took 46-145 s each, 12 in 312 s, about 3.5 GB of host memory each while in the | ||
| 2466 | driver (14.5 GB peak for four). Graphics pipelines are not covered: they are built at a title's draw from its PSO | ||
| 2467 | description and the bound formats, and take milliseconds. | ||
| 2468 | `LEONIDA_COMPILE_HELPER=1` (`shims/d3d12_compile_helper.h`) keeps first-ever compiles out of the title's process: | ||
| 2469 | the driver's locks, which a long `vkCreateComputePipelines` holds and a `vkQueueSubmit` of the same process waits | ||
| 2470 | for, are per process. A compute build of `LEONIDA_COMPILE_HELPER_MIN_BYTES` or more (128 KiB) with no journal file | ||
| 2471 | writes a request beside the journal (`requests/<name>.req`: the entry and a priority, 0 for a use, the module size | ||
| 2472 | for a warm-up) and starts the helper at the first one (`gta6rt --compile-server --parent <pid>`, the same executable | ||
| 2473 | and environment, so the same device and journal names). With asynchronous builds (`LEONIDA_ASYNC_PIPELINES=1`, the | ||
| 2474 | intended mode) nothing waits: the build answers deferred, the variant goes back to idle, the dispatch is skipped and | ||
| 2475 | counted, and each later use looks at the request (a file check, the module is not read again) until the journal | ||
| 2476 | file is there and the pipeline is created from it, a cache hit. A warm-up only asks, in either mode, so the warm-up | ||
| 2477 | worker writes its requests ahead and the helper's threads (`LEONIDA_COMPILE_HELPER_THREADS`, 2) build them in | ||
| 2478 | parallel, the most urgent first; a warm-up the helper builds is never held back while the title submits. Without | ||
| 2479 | asynchronous builds a dispatch waits for its file, holding nothing of the driver's (`LEONIDA_COMPILE_HELPER_WAIT_MS`, | ||
| 2480 | default 120 s, 0 for no limit). A failure (`requests/<name>.failed`, the helper gone) builds the pipeline here as | ||
| 2481 | before, and so does a request that is no longer listed (`<name>.req` gone with no answer) or one still pending after | ||
| 2482 | `LEONIDA_COMPILE_HELPER_PENDING_MS` (default 120 s): the helper cannot hold a dispatch forever. The helper | ||
| 2483 | checks that its journal name is the one asked for before it compiles (the name is a hash of the module and the | ||
| 2484 | device, no driver call), ends with the process that started it, runs alone per journal, | ||
| 2485 | and with nothing asked fills the rest of the library, smallest module first, on | ||
| 2486 | `LEONIDA_COMPILE_HELPER_IDLE_THREADS` (1, always one fewer than its threads) at idle priority; the journal names it | ||
| 2487 | worked out are kept in `requests/names.idx` (with each module's size and time and what the names depend on), so a | ||
| 2488 | later helper does not read every module again. `requests/<name>.building` is a lock file a process holds for the | ||
| 2489 | whole build (no sharing, deleted by the OS when that process ends, killed or not), whose contents name the process: | ||
| 2490 | the helper and `--precompile-pipelines` leave an entry its holder is building to it, and a file no process holds is | ||
| 2491 | stale whatever process id it names. Measured, RTX 4070 Ti, | ||
| 2492 | driver 630.20, a boot with an empty journal and the helper waiting (no asynchronous builds): the helper compiled 171 | ||
| 2493 | pipelines of 128 KiB or more (148 s in its driver), every one of them was a hit in the title's process (at most | ||
| 2494 | 2 ms), and no submission waited at the compile gate. | ||
| 2495 | Under Proton, pass a Wine path, for example | ||
| 2496 | `LEONIDA_PIPELINE_CACHE_DIR='Z:\opt\leonida\cache'`. Async warm-up workers publish to the same directory. | ||
| 2497 | For a disposable session, `LEONIDA_PIPELINE_JOURNAL_SEED_DIR=<absolute existing directory>` can name a separate, | ||
| 2498 | trusted read-only set of per-key compute journal files. The runtime prefers a compatible writable entry, then tries | ||
| 2499 | the same key in the seed; both use the existing size and device/driver header checks. A seed hit neither copies an | ||
| 2500 | entry nor refreshes its mtime. All writes, LRU touches, staging cleanup, eviction and byte accounting belong to the | ||
| 2501 | writable journal only, including replacement of an incompatible local file. The seed must be distinct from the | ||
| 2502 | writable `pipeline_cache.d`, not its ancestor or descendant; an explicitly unusable or overlapping root disables | ||
| 2503 | the journal. This setting does not grant access or authenticate cache data. Use only trusted, privately produced | ||
| 2504 | files on a read-only mount/ACL with stable, disjoint directories and no linked files between them. Leave unset for | ||
| 2505 | the original single-directory behavior. Per-key names are unchanged: externally precompiled files for the same | ||
| 2506 | pipeline identity can be read without a persistent *writable* shared journal. | ||
| 2507 | During normal runtime, a compatible local or external entry is used before requesting the helper. | ||
| 2508 | The offline precompiler and compile-server instead read and populate only the writable journal, even | ||
| 2509 | when a separate seed is configured. An external hit is not a published response to a helper request; | ||
| 2510 | its readiness check still requires a compatible file at the requested writable path. Both modes validate | ||
| 2511 | the configured directory pair before enabling journaling. | ||
| 2512 | To check the two tiers without game files, build `d3d12_compute_journal_test`, then run | ||
| 2513 | `python scripts/check_compute_journal_overlay.py <path-to-d3d12_compute_journal_test.exe> --require-hit`. | ||
| 2514 | This uses four fresh processes, two authored compute shaders and a disposable cache. It checks dispatch results, | ||
| 2515 | reported application-cache hits (where supported), local publications, and that old seed contents/mtime stay put. | ||
| 2299 | `LEONIDA_TRACE_PIPELINE_COMPILE=1` records each graphics and compute build's trigger, thread, elapsed time, | 2516 | `LEONIDA_TRACE_PIPELINE_COMPILE=1` records each graphics and compute build's trigger, thread, elapsed time, |
| 2300 | SPIR-V size, shader names and Vulkan application-cache feedback (1 hit, 0 miss, -1 unavailable). It also | 2517 | SPIR-V size, shader names and Vulkan application-cache feedback (1 hit, 0 miss, -1 unavailable). It also |
| 2301 | times cache reads, merges, writes and draw/dispatch pipeline lookups that take at least 1 ms. | 2518 | times cache reads, merges, writes and draw/dispatch pipeline lookups that take at least 1 ms. |
| 2302 | `LEONIDA_ASYNC_PIPELINES=1` schedules cold first-use builds on the warm-up worker ahead of speculative work. | 2519 | `LEONIDA_ASYNC_PIPELINES=1` schedules cold first-use builds on the warm-up worker ahead of speculative work; how long |
| 2303 | Replay skips a draw or dispatch while its pipeline is pending. Later uses find the completed handle. | 2520 | a submission waits for them, and what is skipped, is "Pipelines still being built" below. Strict replay builds |
| 2304 | A skipped dispatch can lose a one-time resource update. Synchronous first use is the default and strict | 2521 | synchronously and waits for every build. `LEONIDA_COMPUTE_WARMUP=0` restricts the worker to pipelines requested by |
| 2305 | replay always uses it. `LEONIDA_COMPUTE_WARMUP=0` restricts the worker to pipelines requested by the title. | 2522 | the title. |
| 2523 | A queued build holds no reference to its PSO or device (`PipelineCompiler`, `runtime/shims/d3d12_pipeline_compile.h`). | ||
| 2524 | A PSO's last release drops its queued builds and returns at once; one already running is left to finish, and the | ||
| 2525 | worker deletes the PSO after it (`PipelineState::last_release`). The PSO's device reference goes at the release, so | ||
| 2526 | the release that tears the device down waits for that build, drops the device's cache checkpoint, and the last | ||
| 2527 | device stops and joins the worker before any Vulkan object goes; the session cache is written after that. gta6rt, | ||
| 2528 | which ends with the device alive, drops the queue and waits up to 2 s for a running build before `ExitProcess` and on | ||
| 2529 | a console Ctrl+C, Ctrl+Break or close; after that nothing is queued, and a first use builds in place | ||
| 2530 | (`d3d12_compile_teardown_test`). | ||
| 2306 | `GetCachedBlob` records the vendor, device, driver version, `pipelineCacheUUID` and a SHA-256 of the description | 2531 | `GetCachedBlob` records the vendor, device, driver version, `pipelineCacheUUID` and a SHA-256 of the description |
| 2307 | without `Flags`, sealed by a checksum (`runtime/src/cached_pso.h`). The answers are the host's, measured on an | 2532 | without `Flags`, sealed by a checksum (`runtime/src/cached_pso.h`). The answers are the host's, measured on an |
| 2308 | RTX 3060 and WARP: the same description is accepted; another | 2533 | RTX 3060 and WARP: the same description is accepted; another |
| @@ -2326,6 +2551,69 @@ Pipeline creation: | |||
| 2326 | serialized size and bytes are each device's own (the host's empty library is 900 bytes, the layer's 16). | 2551 | serialized size and bytes are each device's own (the host's empty library is 900 bytes, the layer's 16). |
| 2327 | - Not compared: the calls the host runtime faults on (`Serialize(nullptr, n)`, `StorePipeline` with a null PSO, | 2552 | - Not compared: the calls the host runtime faults on (`Serialize(nullptr, n)`, `StorePipeline` with a null PSO, |
| 2328 | `Load*` with a null name or description); the layer answers `E_INVALIDARG` for each. | 2553 | `Load*` with a null name or description); the layer answers `E_INVALIDARG` for each. |
| 2554 | - Compiles at draw time: the first draw of a graphics pipeline, the first dispatch of a compute pipeline the warm-up | ||
| 2555 | has not built, and each variant are compiled for the submission that needs them. `prepare()` leaves each one that is | ||
| 2556 | not built yet to `PipelineCompiles`, once per pipeline and variant; `VulkanQueue::execute_now` then compiles them | ||
| 2557 | side by side on the device's workers (`runtime/src/pipeline_workers.h`), the submitting thread among them, and writes | ||
| 2558 | the command buffer when all are built. Every draw and dispatch has its own pipeline: none is left to a later frame. A | ||
| 2559 | pipeline the driver refuses has the result it had when `prepare()` built it: a draw or an indirect dispatch fails the | ||
| 2560 | submission, a dispatch is dropped (strict replay: fails it too). The resource lock is held while they compile, as it | ||
| 2561 | is when each is compiled alone, so a PSO released meanwhile waits for the submission. The workers have ended before | ||
| 2562 | the session cache is read at device teardown. `LEONIDA_PIPELINE_THREADS=<n>` sets the workers: unset, half the | ||
| 2563 | logical processors and at most 8; `0` compiles each pipeline on the submitting thread where `prepare()` meets it. | ||
| 2564 | Large pipelines (below) are compiled within a memory budget, and the variants of one PSO one after another. | ||
| 2565 | `LEONIDA_ASYNC_PIPELINES=1` is not changed: its builds stay on the compile worker. Measured with synthetic programs | ||
| 2566 | never compiled before and the warm-up off (RTX 3080, NVIDIA 621.24, Windows 11, 16 logical processors, 8 workers, | ||
| 2567 | three runs each): the first submission of 192 graphics pipelines takes 126 to 143 ms instead of 861 to 882, of 192 | ||
| 2568 | variants 124 to 130 instead of 856 to 863, of 96 compute pipelines 74 to 81 instead of 486 to 519, and the process | ||
| 2569 | holds about 50 MiB more (the driver keeps memory for each thread that compiles). One `VkPipelineCache` is enough: one | ||
| 2570 | cache per thread, merged, was about as fast. Tested by `pipeline_workers`, `replay_pipeline_compiles` and | ||
| 2571 | `d3d12_pipeline_workers`. | ||
| 2572 | - Large pipelines: a compile takes the driver some hundred bytes of memory for each byte of SPIR-V | ||
| 2573 | ([pipeline_check.md](pipeline_check.md), "Limiting concurrent compilation of large modules"), so compute modules over | ||
| 2574 | 128 KiB and graphics pipelines of 1 MiB or more compile side by side only while their estimates (512 bytes for each | ||
| 2575 | byte of SPIR-V) fit a budget: three quarters of the smaller of the free RAM and the room under the commit limit, read | ||
| 2576 | again whenever a place at the gate (`runtime/src/large_module_gate.h`, one for the process) is given or returned. One | ||
| 2577 | always gets in when none is, so a pipeline larger than the budget compiles alone. An estimate counts in full until | ||
| 2578 | the compile ends, although the driver has taken part of it by then. They get in in the order they came; while the | ||
| 2579 | first in line does not fit, the next behind it that does may pass, as long as all that have passed it would fit the | ||
| 2580 | budget together with it, so that a stream of small ones does not keep it out. The ones a submission waits for (and | ||
| 2581 | those of `LEONIDA_ASYNC_PIPELINES`) go before the warm-up's, which take a quarter of the budget at most and none while | ||
| 2582 | a submission that has large ones is compiling on its workers. A thread that waits for its place holds no PSO's lock, | ||
| 2583 | and one that has a place waits for none. `PipelineCompiles::build` gives a submission | ||
| 2584 | as many jobs for large ones as its smallest could be in at once, largest first; where the next one does not fit, the | ||
| 2585 | job compiles small ones in the meantime. `LEONIDA_SERIAL_BIG_COMPILES=1` compiles them one after another instead, as | ||
| 2586 | before there was a budget, `=0` has no limit, `LEONIDA_BIG_COMPILE_BUDGET_MB` fixes the budget. Measured with | ||
| 2587 | synthetic integer modules never compiled before and the warm-up off (RTX 3080, NVIDIA 621.24, Ryzen 7 5800X3D, 8 | ||
| 2588 | workers and the submitting thread, three alternating runs each): the first submission of 16 modules of 256 KiB takes | ||
| 2589 | 0.8 s instead of 4.0 to 4.8 s, 16 of 512 KiB 2.0 to 2.2 s instead of 10.2 to 11.4, 15 of 1 MiB 5.8 to 6.1 s instead | ||
| 2590 | of 29.2 to 31.2, 12 of 0.5 to 2 MiB 8.0 to 10.5 s instead of 38.9 to 39.9. While the 15 of 1 MiB compile, private | ||
| 2591 | memory peaks 656 to 676 MiB over what it was, instead of 140 to 147 (one compile takes 85 to 131 bytes for each byte | ||
| 2592 | of SPIR-V here, and the driver keeps memory for each thread that compiles). With a budget of 1536 MiB, two at once, | ||
| 2593 | they take 18.5 s and peak 202 MiB over. Not measured: other drivers, and the title. Tested by `big_compile_gate`, | ||
| 2594 | `replay_pipeline_compiles` and `d3d12_big_compute`. | ||
| 2595 | |||
| 2596 | **Pipelines still being built** (`PipelineState::queue_build` in `runtime/shims/d3d12_vulkan_device.cpp`). Lazy | ||
| 2597 | pipelines are built at first use, and on the 4070 Ti (NVIDIA 630.20) a large compute pipeline takes the driver 3-10 s, | ||
| 2598 | some 37 s. A submission builds the ones it needs through `PipelineCompiles` and `PipelineWorkers` (above), with | ||
| 2599 | `resource_mutex_` released while they compile and the large ones within the memory budget of `LargeModuleGate`. | ||
| 2600 | #2098 had a second path here, a pre-pass in `VulkanQueue::execute` that built them one after another on the | ||
| 2601 | submitting thread; at the maintainers' decision it was replaced by this one when #2098 was merged. | ||
| 2602 | |||
| 2603 | - **Asynchronous builds** (`LEONIDA_ASYNC_PIPELINES=1`). Prepare asks `queue_build`, which answers the handle once | ||
| 2604 | built and otherwise queues one compile-worker job at replay's priority and answers null: the draw or dispatch is | ||
| 2605 | skipped, the list's other commands replay as recorded, and a later submission uses the pipeline. The job also starts | ||
| 2606 | at record time already: at `SetPipelineState` for compute and at each draw for graphics, with the variant its bound | ||
| 2607 | targets give (`request_pipeline_build`). A compute build the compile helper is still making (`LEONIDA_COMPILE_HELPER`) | ||
| 2608 | publishes nothing, so its next use asks again. | ||
| 2609 | - **Warm-ups while the title submits.** A compute warm-up holds the compile gate for its whole create, and every | ||
| 2610 | submission waits behind it: a native boot's submissions waited 140 s in all at the gate behind compute warm-ups, and | ||
| 2611 | past the story load the worker went through 694 warm-ups of modules over 128 KiB (those over 640 KiB take 4-25 s | ||
| 2612 | each) against 25 such builds a dispatch asked for (measured with a 128 KiB limit). With | ||
| 2613 | `LEONIDA_COMPUTE_WARMUP_LIVE_MAX_BYTES=<n>` a warm-up of a module over n bytes of SPIR-V is not started while the | ||
| 2614 | title submits (a submission in the last second, `src/pipeline_wait.h`); the pipeline is built at its first use | ||
| 2615 | instead. Opt-in: unset or 0, every warm-up runs, as on `main`, and `LargeModuleGate` (#1889) orders them behind a | ||
| 2616 | submission's compiles. Smaller warm-ups, and every warm-up before the first submission, run as before. | ||
| 2329 | 2617 | ||
| 2330 | **Open:** whether the game uses `D3D12_PIPELINE_STATE_STREAM_DESC` for mesh/RT and which subobject types appear. | 2618 | **Open:** whether the game uses `D3D12_PIPELINE_STATE_STREAM_DESC` for mesh/RT and which subobject types appear. |
| 2331 | The trace will enumerate them. | 2619 | The trace will enumerate them. |
| @@ -2784,11 +3072,20 @@ The console has two list topologies Vulkan lacks: rectangle list (`IASetPrimitiv | |||
| 2784 | allocations. `LEONIDA_TITLE_IMAGE_POOL=0` selects individual allocation for every image. With | 3072 | allocations. `LEONIDA_TITLE_IMAGE_POOL=0` selects individual allocation for every image. With |
| 2785 | `LEONIDA_MEM_PROBE` enabled, the texture census also reports logical Vulkan backing bytes for the registered | 3073 | `LEONIDA_MEM_PROBE` enabled, the texture census also reports logical Vulkan backing bytes for the registered |
| 2786 | slot-70 and slot-133 images and the portion on non-device-local types. | 3074 | slot-70 and slot-133 images and the portion on non-device-local types. |
| 3075 | - A refresh pass visits a snapshot of the title-image registry, taken under its mutex, instead of walking the | ||
| 3076 | registry itself. Filling a texture can submit, a submission destroys a retired image, and that image's destructor | ||
| 3077 | erases its registry entry. Windows' mutex is recursive for its owner, so the erase lands inside the pass, and a walk | ||
| 3078 | over the map itself would step into a freed node (measured: an access violation reading the nil flag of a null | ||
| 3079 | child, 0x19, in `Device::refresh_title_textures`). The snapshot also holds a reference to each entry, so an entry | ||
| 3080 | retired during the pass is still alive when its turn comes. | ||
| 2787 | - Sampled title images can use device-local memory even when Vulkan host image copies require a | 3081 | - Sampled title images can use device-local memory even when Vulkan host image copies require a |
| 2788 | host-visible memory type. The runtime queries the same image with and without host-transfer usage. | 3082 | host-visible memory type. The runtime queries the same image with and without host-transfer usage. |
| 2789 | When only the latter permits plain device-local backing, it detiles the complete image into a reusable | 3083 | When only the latter permits plain device-local backing, it detiles the complete image into a reusable |
| 2790 | staging buffer and transfers all its mips and layers together. Linear slot-133 placements retain host | 3084 | staging buffer and transfers all its mips and layers together. Linear slot-133 placements retain host |
| 2791 | copies. An allocation failure retries the original host-copyable image. `LEONIDA_TITLE_IMAGE_STAGING=0` | 3085 | copies. On a device without `VK_EXT_host_image_copy` every colour title image, linear placements too, takes the |
| 3086 | staged upload: the refresh before a submission has no other way to fill one, and without it the title's textures | ||
| 3087 | stayed zero (a flat green intro movie). An allocation failure retries the original host-copyable image. | ||
| 3088 | `LEONIDA_TITLE_IMAGE_STAGING=0` | ||
| 2792 | restores the original placement policy. With `LEONIDA_MEM_PROBE`, each title image class logs its | 3089 | restores the original placement policy. With `LEONIDA_MEM_PROBE`, each title image class logs its |
| 2793 | Vulkan memory type mask, mask without host transfer, and selected type. | 3090 | Vulkan memory type mask, mask without host transfer, and selected type. |
| 2794 | - `WriteToSubresource`/`ReadFromSubresource` (implemented in `d3d12_vulkan_device.cpp`) complete before they | 3091 | - `WriteToSubresource`/`ReadFromSubresource` (implemented in `d3d12_vulkan_device.cpp`) complete before they |
| @@ -2861,6 +3158,16 @@ The console has two list topologies Vulkan lacks: rectangle list (`IASetPrimitiv | |||
| 2861 | image when both layouts are opaque, since D3D12 leaves an alias's contents undefined until reinitialized, and is | 3158 | image when both layouts are opaque, since D3D12 leaves an alias's contents undefined until reinitialized, and is |
| 2862 | refused only for a non-opaque layout. Before this, the retail boot stopped on the title's assert while it created | 3159 | refused only for a non-opaque layout. Before this, the retail boot stopped on the title's assert while it created |
| 2863 | its D16 depth targets on an RDNA2 iGPU under RADV. A refused depth placement is logged (no trace line covers it). | 3160 | its D16 depth targets on an RDNA2 iGPU under RADV. A refused depth placement is logged (no trace line covers it). |
| 3161 | Where the provider (`Resource::enable_depth_stencil_uav`) has no unordered-access form of a texture it answers | ||
| 3162 | `E_INVALIDARG` or `E_NOTIMPL`, and slots 76 and 133 then make the texture without unordered access, as before the | ||
| 3163 | provider: slot 76 as a committed depth-stencil texture, slot 133 through its stand-in (the title-placed texture, or | ||
| 3164 | the committed one). The first such refusal per slot is logged (`xs_proxy_mock` checks the refusal against a mock | ||
| 3165 | provider). Any other failure (out of memory, the backing itself, a refused placement) is passed on as before. | ||
| 3166 | Console D16S8 (format 118) made as `D24_UNORM_S8_UINT` via `pc_format()` (the default on GPUs with D24S8 | ||
| 3167 | attachments, such as NVIDIA) keeps its UAVs through the widened `R16_TYPELESS` + `R8_UINT` storage planes: | ||
| 3168 | plane-0 barriers convert between 24-bit UNORM words in transfer scratch and `R32_SFLOAT` via `Depth24Converter` | ||
| 3169 | and blit between the intermediate `R32_FLOAT` image and `R16_UNORM` (viewed as `R16_UINT` or `R16_UNORM`), while | ||
| 3170 | plane 1 copies stencil bytes directly (`xbox_d16s8_d24_storage` with `LEONIDA_CONSOLE_D16S8=d24`). | ||
| 2864 | - Legacy and enhanced texture transitions copy the selected planes and layers to or from their storage images. | 3171 | - Legacy and enhanced texture transitions copy the selected planes and layers to or from their storage images. |
| 2865 | Fence-ordered graphics and compute queues can share UAV access. A dedicated compute family can perform | 3172 | Fence-ordered graphics and compute queues can share UAV access. A dedicated compute family can perform |
| 2866 | the plane transfer itself when `VK_KHR_maintenance10` and the format's depth/stencil copy flags allow it. | 3173 | the plane transfer itself when `VK_KHR_maintenance10` and the format's depth/stencil copy flags allow it. |
| @@ -3365,7 +3672,11 @@ will forward to. The queue-side calls ignore which queue they came on (one `VkQu | |||
| 3365 | `WaitFrameEventX` returns at the next origin with the next token (1, 2, 3, ...; 0 is the null token) and does not | 3672 | `WaitFrameEventX` returns at the next origin with the next token (1, 2, 3, ...; 0 is the null token) and does not |
| 3366 | return while `latency` presented frames are still waiting for their vblank. A frame presented before the origin event | 3673 | return while `latency` presented frames are still waiting for their vblank. A frame presented before the origin event |
| 3367 | is armed is not paced (`PresentX` does not hold it for a vblank), so it is shown at once and never waits for a vblank: | 3674 | is armed is not paced (`PresentX` does not hold it for a vblank), so it is shown at once and never waits for a vblank: |
| 3368 | blank presents of a loading screen do not delay the first wait. A wait that comes late returns at once | 3675 | blank presents of a loading screen do not delay the first wait. At most `latency` frames are in flight once the event |
| 3676 | is armed: a present into a full queue (several presents with no wait between them) replaces the newest queued frame | ||
| 3677 | and takes its vblank, like a mailbox, so the replaced frame is never shown (no display statistic) and the older ones | ||
| 3678 | keep their vblanks. However many presents come between two waits, the next wait passes when the oldest frame is | ||
| 3679 | shown. A wait that comes late returns at once | ||
| 3369 | with the newest passed origin; the missed ones are skipped. A finite timeout gives | 3680 | with the newest passed origin; the missed ones are skipped. A finite timeout gives |
| 3370 | `HRESULT_FROM_WIN32(WAIT_TIMEOUT)`; nothing registered, or suspended, gives `HRESULT_FROM_WIN32(ERROR_INVALID_STATE)`. | 3681 | `HRESULT_FROM_WIN32(WAIT_TIMEOUT)`; nothing registered, or suspended, gives `HRESULT_FROM_WIN32(ERROR_INVALID_STATE)`. |
| 3371 | `LEONIDA_PRESENT_UNCAP` (any non-empty value other than "0", read when the object is made) takes the frame-rate | 3682 | `LEONIDA_PRESENT_UNCAP` (any non-empty value other than "0", read when the object is made) takes the frame-rate |
| @@ -3381,8 +3692,11 @@ will forward to. The queue-side calls ignore which queue they came on (one `VkQu | |||
| 3381 | `SuspendX`/`ResumeX` so suspended pauses are excluded), computing nearest-rank `p50`/`p95`/`p99` and the mean drift | 3692 | `SuspendX`/`ResumeX` so suspended pauses are excluded), computing nearest-rank `p50`/`p95`/`p99` and the mean drift |
| 3382 | against the active target interval (`FramePacer::pacing_summary()`). On teardown after at least one present, | 3693 | against the active target interval (`FramePacer::pacing_summary()`). On teardown after at least one present, |
| 3383 | `XboxPresentation` logs a single `[rt] present: pacing summary ...` line on stderr, which `tools/boot_trace.py` | 3694 | `XboxPresentation` logs a single `[rt] present: pacing summary ...` line on stderr, which `tools/boot_trace.py` |
| 3384 | surfaces beside the D3D12 call counts. Confirmed on a fake clock by `frame_pacer_test` (known 100-frame distribution, | 3695 | surfaces beside the D3D12 call counts. The intervals are between `PresentX` calls, not between frames shown: a frame |
| 3385 | positive and negative drift, ring-buffer wrap-around, suspend/resume exclusion, uncapped mode) and by | 3696 | replaced in a full queue (see the latency limit above) still counts as a present with its real interval, so the |
| 3697 | percentiles describe the title's present cadence, and a burst of presents between two waits shows up as short | ||
| 3698 | intervals. Confirmed on a fake clock by `frame_pacer_test` (known 100-frame distribution, | ||
| 3699 | positive and negative drift, ring-buffer wrap-around, suspend/resume exclusion, uncapped mode, replaced frames) and by | ||
| 3386 | `tests/test_boot_trace.py`. | 3700 | `tests/test_boot_trace.py`. |
| 3387 | - *`PresentX`*: 0 planes presents a black frame (no token needed). 1 plane blits plane 0's first resource (a | 3701 | - *`PresentX`*: 0 planes presents a black frame (no token needed). 1 plane blits plane 0's first resource (a |
| 3388 | single-sample 2D colour texture in `PRESENT`) to the swapchain image, limited to `pSrcViewRects[0]` when set | 3702 | single-sample 2D colour texture in `PRESENT`) to the swapchain image, limited to `pSrcViewRects[0]` when set |
| @@ -3578,8 +3892,11 @@ will forward to. The queue-side calls ignore which queue they came on (one `VkQu | |||
| 3578 | - *Frame capture* (`LEONIDA_CAPTURE=<dir>`, `LEONIDA_CAPTURE_EVERY=<n>`, `LEONIDA_CAPTURE_LIMIT=<n>`): writes | 3892 | - *Frame capture* (`LEONIDA_CAPTURE=<dir>`, `LEONIDA_CAPTURE_EVERY=<n>`, `LEONIDA_CAPTURE_LIMIT=<n>`): writes |
| 3579 | every n-th presented frame (default 30, at most 24) to `<dir>/frame_NNNNN.ppm`, a binary P6 of the swapchain image | 3893 | every n-th presented frame (default 30, at most 24) to `<dir>/frame_NNNNN.ppm`, a binary P6 of the swapchain image |
| 3580 | converted to 8-bit RGB, and appends one line per frame to `<dir>/index.txt` with the extent and the mean RGB. Off | 3894 | converted to 8-bit RGB, and appends one line per frame to `<dir>/index.txt` with the extent and the mean RGB. Off |
| 3581 | unless the variable is set, and the folder is created. This is what a check reads when it has to know what the | 3895 | unless the variable is set, and the folder is created. Disk-only sampling copies frames 1, 1+n, 1+2n, … to host |
| 3582 | layer actually presented: the window is not readable in every setup (under Wine it is not even mapped), and the | 3896 | staging until the file limit is reached; intervening frames still present normally. This avoids a full-image |
| 3897 | transfer on every present when only occasional samples were requested. An explicit continuous readback request | ||
| 3898 | and the temporary splash inspection still copy each frame they need. This lets a check inspect what the layer | ||
| 3899 | actually presented: the window is not readable in every setup (under Wine it is not even mapped), and the | ||
| 3583 | mean is enough to tell a real frame from a black one. `d3d12_present_test` turns it on and checks the files against | 3900 | mean is enough to tell a real frame from a black one. `d3d12_present_test` turns it on and checks the files against |
| 3584 | the colour it clears to. | 3901 | the colour it clears to. |
| 3585 | - *`SuspendX`/`ResumeX`*: suspend drops the interval, the origin event and the frames in flight, wakes blocked waits | 3902 | - *`SuspendX`/`ResumeX`*: suspend drops the interval, the origin event and the frames in flight, wakes blocked waits |
| @@ -3601,7 +3918,8 @@ will forward to. The queue-side calls ignore which queue they came on (one `VkQu | |||
| 3601 | (placement, point/bilinear, alpha overlay, HDR10 and PQ conversions, refusals; against a CPU model), token errors, | 3918 | (placement, point/bilinear, alpha overlay, HDR10 and PQ conversions, refusals; against a CPU model), token errors, |
| 3602 | statistics, suspend/resume, `ImmediateThresholdPercent` with a late frame at several thresholds (immediate mode | 3919 | statistics, suspend/resume, `ImmediateThresholdPercent` with a late frame at several thresholds (immediate mode |
| 3603 | chosen, or not for 0, below the lateness, on time) and with `LEONIDA_PRESENT_NO_TEAR=1`, 30 frames at 60 Hz in real | 3920 | chosen, or not for 0, below the lateness, on time) and with `LEONIDA_PRESENT_NO_TEAR=1`, 30 frames at 60 Hz in real |
| 3604 | time; skipped, exit 77, without a Vulkan device). `frame_pacer_test` also sweeps `decide_present_sync`. | 3921 | time; skipped, exit 77, without a Vulkan device). `frame_pacer_test` also sweeps `decide_present_sync`, and checks |
| 3922 | that 1000 presents between two waits leave at most `latency` frames in flight (latency 1, 2 and 3). | ||
| 3605 | 3923 | ||
| 3606 | ### 4.6 Queries | 3924 | ### 4.6 Queries |
| 3607 | 3925 | ||
| @@ -3624,15 +3942,20 @@ Implemented (`QueryHeap` in `runtime/shims/d3d12_vulkan_device.cpp`, the query c | |||
| 3624 | (`compare_invalid_arguments`, "query heap:", RTX 5070 / 621.14): `E_INVALIDARG` for no queries, a node other than | 3942 | (`compare_invalid_arguments`, "query heap:", RTX 5070 / 621.14): `E_INVALIDARG` for no queries, a node other than |
| 3625 | node 0, or a type past `PIPELINE_STATISTICS1` (7), checked before the output; a valid description with a null | 3943 | node 0, or a type past `PIPELINE_STATISTICS1` (7), checked before the output; a valid description with a null |
| 3626 | output is then `E_UNEXPECTED`, not `S_FALSE`. | 3944 | output is then `E_UNEXPECTED`, not `S_FALSE`. |
| 3627 | - **Stream-output statistics** (D3D-302). The layer has no stream output: a graphics PSO with `StreamOutput` | 3945 | - **Stream-output statistics** (D3D-302). The layer still refuses `StreamOutput` PSOs and does not implement |
| 3628 | entries is refused and `SOSetTargets` is not implemented, so no primitive reaches a stream and every | 3946 | `SOSetTargets`, so no primitive reaches a stream yet. With `VK_EXT_transform_feedback` enabled on the device |
| 3629 | `SO_STATISTICS_STREAM0..3` query counts 0 written and 0 needed. An `SO_STATISTICS` heap is therefore made without | 3947 | (`D3D-TRANSFORM-FEEDBACK-DEVICE`) and its `transformFeedbackQueries` property set, an `SO_STATISTICS` heap is a |
| 3630 | a `VkQueryPool`: `BeginQuery`/`EndQuery` record nothing in Vulkan (D3D12's call rules are still kept, and the | 3948 | real `VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT` pool begun and ended indexed on the stream |
| 3949 | (`vkCmdBeginQueryIndexedEXT` / `vkCmdEndQueryIndexedEXT`), and `ResolveQueryData` copies the two 64-bit results per | ||
| 3950 | query (16 bytes: `NumPrimitivesWritten`, `PrimitivesStorageNeeded`), in the same order; with no stream output they | ||
| 3951 | are 0. A stream at or above the device's `maxTransformFeedbackStreams` runs nothing and resolves zero, as if the | ||
| 3952 | heap had no pool. Without the feature, the property, or a nonzero `maxTransformFeedbackStreams`, the heap is made | ||
| 3953 | without a `VkQueryPool`: `BeginQuery`/`EndQuery` run nothing in Vulkan (D3D12's call rules are still kept, and the | ||
| 3631 | heap's queries track ended or not as the others do), they overlap no other query, and `ResolveQueryData` writes | 3954 | heap's queries track ended or not as the others do), they overlap no other query, and `ResolveQueryData` writes |
| 3632 | zeros (`vkCmdFillBuffer`, 16 bytes per query: `NumPrimitivesWritten`, `PrimitivesStorageNeeded`), with no | 3955 | zeros (`vkCmdFillBuffer`, 16 bytes per query), with no statistics split since nothing is dispatched. Two |
| 3633 | statistics split since nothing is dispatched. When stream output lands, the heap becomes a | 3956 | overlapping `SO_STATISTICS` queries on one stream would be two active indexed queries in one pool |
| 3634 | `VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT` pool begun with `vkCmdBeginQueryIndexedEXT` on the stream, whose two | 3957 | (`VUID-vkCmdBeginQueryIndexedEXT-queryPool-04753`), so `prepare()` refuses such a list |
| 3635 | results are in the same order. | 3958 | (`ReplayResult::invalid_query`); queries on different streams are fine. |
| 3636 | - **Recording.** The list keeps D3D12's rules for the calls: timestamps only have `EndQuery`; every other query is | 3959 | - **Recording.** The list keeps D3D12's rules for the calls: timestamps only have `EndQuery`; every other query is |
| 3637 | begun and ended in the same list with the same type, is not begun again while it runs, and is not resolved while | 3960 | begun and ended in the same list with the same type, is not begun again while it runs, and is not resolved while |
| 3638 | it runs; resolve offsets are multiples of 8. A list closed with a query still running reports `E_INVALIDARG` and | 3961 | it runs; resolve offsets are multiples of 8. A list closed with a query still running reports `E_INVALIDARG` and |
| @@ -3769,6 +4092,26 @@ Not implemented yet: | |||
| 3769 | one Vulkan indirect call. Use a compute expansion pass that writes a Vulkan-shaped indirect buffer, or | 4092 | one Vulkan indirect call. Use a compute expansion pass that writes a Vulkan-shaped indirect buffer, or |
| 3770 | `VK_NV_device_generated_commands` on NVIDIA. Start with the simple signatures; the trace will show which | 4093 | `VK_NV_device_generated_commands` on NVIDIA. Start with the simple signatures; the trace will show which |
| 3771 | signatures the game creates. | 4094 | signatures the game creates. |
| 4095 | - The indirect arguments are clamped on the GPU before the command reads them (D3D-17's replay, | ||
| 4096 | `runtime/src/vulkan_indirect_clamp.h`, shader `runtime/src/indirect_clamp.comp`). The title's own compute writes | ||
| 4097 | them, and a pass the replay drops (an async pipeline that is not built yet, a stub pipeline, | ||
| 4098 | `LEONIDA_SKIP_COMPUTE`) or mistranslates leaves whatever the memory held: a dispatch of billions of groups or a | ||
| 4099 | draw of four billion vertices runs until the host resets the display driver. One small compute pass per | ||
| 4100 | `ExecuteIndirect` call copies the active records into device-local scratch with their values bounded - 2^24 | ||
| 4101 | vertices or indices, 2^26 vertex instances (count times instances), 65 535 groups per dimension, 2^20 groups per | ||
| 4102 | dispatch and a 2^27-unit work budget per call that saturates through an atomic compare-and-swap - and writes an | ||
| 4103 | empty record past `min(count, max_command_count)` and past the budget, and the clamped count word a `*Count` draw | ||
| 4104 | then reads (so the count is at most `maxDrawCount`, VUID-vkCmdDrawIndirectCount-countBuffer-02717). The indirect | ||
| 4105 | command reads that scratch. A draw emits the pass before its rendering scope opens: `vkCmdCopyBuffer` and a | ||
| 4106 | memory barrier with a transfer access are not allowed inside a dynamic-rendering scope. The records are | ||
| 4107 | bit-identical to the application's when they are within the limits, the argument and count buffers are left | ||
| 4108 | untouched, and the scratch comes from a per-submission pool (`vulkan_scratch.h`) that a list with many indirect | ||
| 4109 | calls reuses. `LEONIDA_INDIRECT_CLAMP=0` reads the application's buffer again, as before. The pass's counters | ||
| 4110 | (records checked, records clamped, counts clamped, records past the budget) are copied to one host-visible slot | ||
| 4111 | per call, read once the submission completes, logged in full at the first use and then rate-limited. Covered by | ||
| 4112 | `indirect_clamp_test` (every kind and the counted variants, | ||
| 4113 | in-range and garbage records, the budget), by `d3d12_m4_compute_test` (a garbage dispatch record beside the | ||
| 4114 | in-range one) and by `d3d12_indirect_rt_test` (a draw whose instance count is garbage). | ||
| 3772 | - Predication (`SetPredication`) maps to `VK_EXT_conditional_rendering` (D3D-18). Done: `GraphicsCommandList:: | 4115 | - Predication (`SetPredication`) maps to `VK_EXT_conditional_rendering` (D3D-18). Done: `GraphicsCommandList:: |
| 3773 | SetPredication` records a `Predication` command (`runtime/src/command_list.h`; offset 8-byte aligned, op | 4116 | SetPredication` records a `Predication` command (`runtime/src/command_list.h`; offset 8-byte aligned, op |
| 3774 | `EQUAL_ZERO` or `NOT_EQUAL_ZERO`, a null buffer turns it off). The replay (`runtime/src/vulkan_replay.h`) begins | 4117 | `EQUAL_ZERO` or `NOT_EQUAL_ZERO`, a null buffer turns it off). The replay (`runtime/src/vulkan_replay.h`) begins |
| @@ -4028,7 +4371,8 @@ uint32 mask; // slot count - 1 | |||
| 4028 | struct entry { // 10 uints = 40 bytes | 4371 | struct entry { // 10 uints = 40 bytes |
| 4029 | uint32 key[8]; // T#: 8 dwords; S#: 4 dwords then 0xFFFFFFFF x4 | 4372 | uint32 key[8]; // T#: 8 dwords; S#: 4 dwords then 0xFFFFFFFF x4 |
| 4030 | uint32 index; // bindless index | 4373 | uint32 index; // bindless index |
| 4031 | uint32 pad; // unused by the shader | 4374 | uint32 kind; // 0 empty; bit 31 occupied; bits 0..5 the sampled arrays the index is bound in, |
| 4375 | // bits 8..11 its storage arrays (one bit per ImageDimension) | ||
| 4032 | } entries[mask + 1]; | 4376 | } entries[mask + 1]; |
| 4033 | ``` | 4377 | ``` |
| 4034 | 4378 | ||
| @@ -4041,6 +4385,18 @@ struct entry { // 10 uints = 40 bytes | |||
| 4041 | `runtime/test/descriptor_table_test.cpp`. | 4385 | `runtime/test/descriptor_table_test.cpp`. |
| 4042 | - Probe: `slot = (h + k) & mask` for `k = 0..7`; the first entry whose eight key dwords match yields its | 4386 | - Probe: `slot = (h + k) & mask` for `k = 0..7`; the first entry whose eight key dwords match yields its |
| 4043 | `index`; no match yields 0. | 4387 | `index`; no match yields 0. |
| 4388 | - `kind` says which arrays that index is good for, because it was given out in the T#'s own dimension's index space | ||
| 4389 | (`runtime/src/vulkan_bindless.h`, `ImageDimension`): bit `d` is dimension `d`'s sampled array, bit `8 + d` its | ||
| 4390 | storage arrays. A module whose `index.json` meta says `"descriptor_table": "tagged"` reads it and uses the index | ||
| 4391 | only in an array the entry names, else index 0 of the array its instruction reads; an absent key is the old plain | ||
| 4392 | layout, which reads only the index. `DescriptorTable::insert` takes the kind, and `BindlessSet::image_kind_at` | ||
| 4393 | derives it from what was bound at the index (its own arrays, storage views, and the 2D copy of a 2D-array image's | ||
| 4394 | first layer, whose slot records that image as its owner so another dimension's image with the same slot number does | ||
| 4395 | not inherit it). One layout serves the device: any module whose meta says `tagged` makes the table tagged, because | ||
| 4396 | the kind word is additive (a plain module ignores the word and reads the index, which the tagged layout keeps at | ||
| 4397 | the same place), so a plain majority never turns it off; no tagged module is the old plain layout. | ||
| 4398 | `LEONIDA_DESCRIPTOR_TABLE=plain|tagged` overrides, and the runtime says so loudly when an override forces plain | ||
| 4399 | while tagged modules exist. | ||
| 4044 | - The layer must keep the table sparse enough that no live key needs more than eight probes. When all eight slots are occupied, | 4400 | - The layer must keep the table sparse enough that no live key needs more than eight probes. When all eight slots are occupied, |
| 4045 | the runtime tries to move one resident to the next empty slot within that resident's own probe window. | 4401 | the runtime tries to move one resident to the next empty slot within that resident's own probe window. |
| 4046 | A relocation requires an idle flush because it overwrites a live slot. Grow when this fails or when the next | 4402 | A relocation requires an idle flush because it overwrites a live slot. Grow when this fails or when the next |
| @@ -4048,8 +4404,9 @@ struct entry { // 10 uints = 40 bytes | |||
| 4048 | the rebuild, at a point where no in-flight command buffer reads the old table. | 4404 | the rebuild, at a point where no in-flight command buffer reads the old table. |
| 4049 | - Insert on `CreateShaderResourceView`, `CreateUnorderedAccessView`, `CreateSampler`, `CopyDescriptors` and heap | 4405 | - Insert on `CreateShaderResourceView`, `CreateUnorderedAccessView`, `CreateSampler`, `CopyDescriptors` and heap |
| 4050 | scans. A duplicate key updates the index in place. | 4406 | scans. A duplicate key updates the index in place. |
| 4051 | - Index 0 is the fallback: a 1×1 texture and a default sampler (and a valid dummy storage image for the storage | 4407 | - Index 0 is the fallback: a 1×1 texture and a default sampler (and, for the storage arrays, a null descriptor |
| 4052 | arrays). The translator returns 0 on a miss, so index 0 must always be valid. | 4408 | with `VK_EXT_robustness2` `nullDescriptor` or else a storage image apart from the sampled ones). The translator |
| 4409 | returns 0 on a miss, so index 0 must always be valid. | ||
| 4053 | - The table buffer is a normal storage buffer, not part of the arena. It can be host-visible and updated directly | 4410 | - The table buffer is a normal storage buffer, not part of the arena. It can be host-visible and updated directly |
| 4054 | (host-coherent, or flushed before submit); if the game is sensitive to PCIe traffic, stage it like any other | 4411 | (host-coherent, or flushed before submit); if the game is sensitive to PCIe traffic, stage it like any other |
| 4055 | upload. The shader only reads it. | 4412 | upload. The shader only reads it. |
diff --git a/docs/d3d12_xs_console_abi.md b/docs/d3d12_xs_console_abi.md index e1ec05fc7..986acf680 100644 --- a/docs/d3d12_xs_console_abi.md +++ b/docs/d3d12_xs_console_abi.md | |||
| @@ -161,6 +161,7 @@ end; on a full buffer they call the vtable method the record stands for (Package | |||
| 161 | | 41, 43, 45 | `Set*RootDescriptor*` / table | Package + sibling layer | | 161 | | 41, 43, 45 | `Set*RootDescriptor*` / table | Package + sibling layer | |
| 162 | | 48 | `IASetVertexBuffers` | Sibling layer | | 162 | | 48 | `IASetVertexBuffers` | Sibling layer | |
| 163 | | 51 | `ClearDepthStencilView` | Sibling layer | | 163 | | 51 | `ClearDepthStencilView` | Sibling layer | |
| 164 | | 71-74 | memory writes and waits (newer layout; 69-72 older) | **Measured here**, §5.5 | | ||
| 164 | | 80 | `ExecuteIndirect` | Sibling layer (note: the package measured slot 80 as a console-only call, a `Dispatch`-with-extra-word shape; slot assignments past 61 differ between the two sources — unconfirmed) | | 165 | | 80 | `ExecuteIndirect` | Sibling layer (note: the package measured slot 80 as a console-only call, a `Dispatch`-with-extra-word shape; slot assignments past 61 differ between the two sources — unconfirmed) | |
| 165 | | 83 | `CopyTextureRegionX` (older layout) | Sibling layer; the package measured a `CopyTextureRegion`-shaped call at slot 85 — consistent with the newer layout (+2) | | 166 | | 83 | `CopyTextureRegionX` (older layout) | Sibling layer; the package measured a `CopyTextureRegion`-shaped call at slot 85 — consistent with the newer layout (+2) | |
| 166 | | 108 | `ResolveSubresourceRegion` | Sibling layer | | 167 | | 108 | `ResolveSubresourceRegion` | Sibling layer | |
| @@ -189,6 +190,88 @@ console-shaped either way. | |||
| 189 | | 12 | `CopyTextureRegion` | Sibling layer | | 190 | | 12 | `CopyTextureRegion` | Sibling layer | |
| 190 | | 13 | `CopyResource` | Sibling layer | | 191 | | 13 | `CopyResource` | Sibling layer | |
| 191 | 192 | ||
| 193 | ### 5.5 Memory writes and waits | ||
| 194 | |||
| 195 | The list has bottom-of-pipe writes of a 32- or 64-bit value into title memory and waits that stop the queue until | ||
| 196 | a 32- or 64-bit value in memory compares true against a reference. Neither has a D3D12 or Vulkan command; the | ||
| 197 | runtime models both (`runtime/shims/d3d12_xs_list_values.h`, the list cut and `execute_with_values` in | ||
| 198 | `d3d12_xs_device.cpp`). | ||
| 199 | |||
| 200 | | Older slot | Newer slot | Method | Evidence | | ||
| 201 | |---:|---:|---|---| | ||
| 202 | | 68 | 70 | depth bounds `(min, max)` as floats | Sibling layer; the retail title calls 70 (unmodelled, a no-op) | | ||
| 203 | | 69 | 71 | `write32(address, value, flush, flags)` | Sibling layer; **measured here** on retail 1.0.2.1 | | ||
| 204 | | 70 | 72 | `write64(address, value, flush, flags)`: flags 1 stores the GPU timestamp, 2 the system one (QPC) | Sibling layer; **measured here** (flags 1 and 0 seen) | | ||
| 205 | | 71 | 73 | `wait32(address, comparison, reference, word)` | Sibling layer; not called by the retail title in the boots measured | | ||
| 206 | | 72 | 74 | `wait64(address, comparison, reference, word)` | Sibling layer; **measured here** | | ||
| 207 | | 73 | 75 | pixel-shader depth order (state) | Sibling layer; the retail title calls 75 (a no-op) | | ||
| 208 | |||
| 209 | Measured here (retail 1.0.2.1, boots to the story load; temporary per-call logging, not committed): | ||
| 210 | |||
| 211 | - The lists record before the queue proxy has detected the layout (§1.1): the first value calls arrive with the | ||
| 212 | layout still unknown. The runtime takes an undetected layout as the newer one, the title's, as it already does for | ||
| 213 | `ExecuteIndirect` at 61. | ||
| 214 | - Up to the story load (~150 s): about 12 000 `write32` (small counters and a constant tag in a ring of 72-byte | ||
| 215 | records), 16 000 `write64` (all with flags 1, GPU timestamps, in begin/end pairs) and 4 100 `wait64`, one per | ||
| 216 | frame, `>=` a reference that rises by one each frame, at the start of a direct list, always met when the list is | ||
| 217 | submitted (the CPU writes that value). | ||
| 218 | - From the story load on: job chains across the queues. Compute lists (the title uses five compute queues) and | ||
| 219 | direct lists `wait64(address, >=, tag)`, mostly as their first calls and sometimes after two to five calls of | ||
| 220 | work, for addresses that other lists `write64(address, tag)` with flags 0: direct lists write tags as their first | ||
| 221 | calls and wait for compute results; compute lists wait for those tags and write theirs near their end. Before | ||
| 222 | this runtime modelled the writes, every such wait was unmet at submission and ran on. | ||
| 223 | - Comparison code 7 is the only one seen; the codes are taken as `D3D12_COMPARISON_FUNC` (memory OP reference, as | ||
| 224 | the sibling layer does). The wait's fourth word had 1 in its low 32 bits each time; it is not used. | ||
| 225 | |||
| 226 | The runtime's model: | ||
| 227 | |||
| 228 | - A write lands after the list part it was recorded in has run: the queue proxy signals a fence of its own behind | ||
| 229 | the part and a pump thread stores the value with the CPU once the fence is reached | ||
| 230 | (`leonida::kernel_writes::store`: one locked access for an aligned value, so a title thread polling it never | ||
| 231 | reads half of it, and pinned like any host write, so the slot-133 shadows see it). Later than the console, never | ||
| 232 | earlier. Writes land in submission order across queues: the pump reads the fences newest write first, so a write | ||
| 233 | whose work waited for an older one is never seen done before it. | ||
| 234 | - Two targets that store cannot reach (`runtime/src/value_write_sink.h`). An address in the GPU address arena's | ||
| 235 | range is an arena offset, a default-heap buffer, not a host address: it is asked before any host store and lands | ||
| 236 | in the arena's own mapping (one in the arena's reserved start or a sparse buffer is dropped). A page of xmem's that | ||
| 237 | the title's view keeps `PAGE_NOACCESS` (a GPU-only window), where the store faults, lands through xmem's own | ||
| 238 | mapping of the physical page. Counted as `writes_arena` and `writes_title_pages`. In the boots to the story load no | ||
| 239 | write failed the host store (0 of 63 219), so both are a safety net. | ||
| 240 | - `write64` flags 1 and 2 take the GPU's timestamp at the write's place in the list: an `EndQuery(TIMESTAMP)` on | ||
| 241 | the real list (the Vulkan layer writes it at the bottom of the pipe) and a `ResolveQueryData` of that one slot into | ||
| 242 | a readback ring of the device's, read when the write lands. Flag 1 lands those ticks, which count at the queue's | ||
| 243 | `GetTimestampFrequency` (what the queue proxy answers the title's frequency query with, newer layout slot 18); | ||
| 244 | flag 2 lands the `QueryPerformanceCounter` value at which the GPU took them, through the queue's clock | ||
| 245 | calibration (renewed every second), never later than the landing. A write that lands before its part has run | ||
| 246 | (recorded before a wait whose gate holds the part) takes the CPU's clock at landing instead, as before. The | ||
| 247 | title's GPU timing reads these values back, in begin/end pairs. | ||
| 248 | - A wait recorded before any work of the part stands at the part's start; writes recorded before that first wait | ||
| 249 | land before the queue stands at it (behind the work submitted before the part), as the title's frame lists and | ||
| 250 | job-tag writers need. A wait recorded after work, or after a write that follows a wait, cuts the list: | ||
| 251 | the real list so far is closed as a part, recording goes on in a spare real list on the same allocator, and the | ||
| 252 | state set so far (heaps, root signatures and arguments, pipeline, viewports, scissors, targets, vertex and index | ||
| 253 | buffers, blend factor, stencil reference, predication; what an executed bundle set, and nothing from before a | ||
| 254 | `ClearState`) is set on it again. A cut that would split an open query waits for the query's `EndQuery`. | ||
| 255 | Bundles record neither method (`ExecuteBundle` names one real list, so a bundle cannot be cut). | ||
| 256 | - At submission each part's waits are checked: met ones cost nothing; one that a write still in flight will meet | ||
| 257 | becomes a queue `Wait` on that write's fence (the GPU orders the two queues); any other makes the queue `Wait` on | ||
| 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, | ||
| 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 | ||
| 262 | meanwhile. | ||
| 263 | - A gate opens after `LEONIDA_VALUE_WAIT_TIMEOUT_MS` (default 200) whatever memory holds, counted from when the | ||
| 264 | gates before it on its queue opened, and logged once per address. An address that timed out three times in a row | ||
| 265 | (the last 256 addresses are counted) gets 4 ms. Once four gates in a row timed out, so does every wait for an | ||
| 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 | ||
| 267 | meets within the rest of the full timeout gives its address the full timeout from then on. | ||
| 268 | `LEONIDA_LIST_VALUES=0` drops both methods, as before. After `stop_list_values` (the process is ending) nothing | ||
| 269 | new is landed or opened. | ||
| 270 | - 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 | ||
| 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 | ||
| 273 | order of the call and the title's thread does not wait (the console's CPU does not either). | ||
| 274 | |||
| 192 | ## 6. Root arguments | 275 | ## 6. Root arguments |
| 193 | 276 | ||
| 194 | Sibling-layer measurements on retail titles: | 277 | Sibling-layer measurements on retail titles: |
diff --git a/docs/d3d12_xs_surface.md b/docs/d3d12_xs_surface.md index 0cae107f7..460b50d29 100644 --- a/docs/d3d12_xs_surface.md +++ b/docs/d3d12_xs_surface.md | |||
| @@ -450,6 +450,124 @@ before treating it as new. For `OMSetFrontAndBackStencilRef` the signature is id | |||
| 450 | GCL8-compiled game calls it at the public slot; SCARAB's placement after GCL6 would land in the | 450 | GCL8-compiled game calls it at the public slot; SCARAB's placement after GCL6 would land in the |
| 451 | wrong slot. Leonida's public-chain command list already has it at GCL8. | 451 | wrong slot. Leonida's public-chain command list already has it at GCL8. |
| 452 | 452 | ||
| 453 | ### 5.2 Arity and receiver of device slots 86, 101, 108, 132 and 133 (and offset `+0x418` / 131) | ||
| 454 | |||
| 455 | These six offsets are called in the title's executable; five reach the device and `+0x418` (131) | ||
| 456 | does not. `+0x2B0`, `+0x328`, `+0x360` and `+0x418`-`+0x428` are past every published interface, | ||
| 457 | so they are console slots on whatever object the call is made on, and the receiver is not | ||
| 458 | automatically the device: the console runtime repeats offsets across object vtables. The whole | ||
| 459 | image has **243** indirect calls `call [reg+disp]` at these six offsets; most of them are *not* on | ||
| 460 | the device, and a count that ignores the receiver overstates the device surface by an order of | ||
| 461 | magnitude. | ||
| 462 | |||
| 463 | The receiver is proven by a backward definition chain from the `call` that ends in a full-width load | ||
| 464 | of the device pointer. The title keeps that pointer in a block of `.data` aliases | ||
| 465 | (`0x1475DF000`-`0x1475DF048` and `0x148759D00`) that one constructor fills with the same value | ||
| 466 | (`0x1424785D4`-`0x142478621` copies the qword at `0x1475DF048` into the other eleven). A site whose | ||
| 467 | chain ends in one of those globals is a device site. A site whose chain ends in a *different* | ||
| 468 | global, in an argument of unknown provenance or in the return of a helper is counted but not | ||
| 469 | attributed. | ||
| 470 | |||
| 471 | | Slot | Offset | Raw sites | Sites on the device | Receiver at those sites | Registers / stack at those sites | What the device sites support | | ||
| 472 | |---:|---|---:|---:|---|---|---| | ||
| 473 | | 86 | `+0x2B0` | 37 | **1** (`0x142479A87`) | `[0x1475DF000]` (alias of the device pointer) | `rcx`=device, `rdx`=&desc (first qword `0x2B0`), `r8`=&`IID_ID3D12PipelineState`, `r9`=&out | three-argument, `riid`-out PSO stream creation (`CreatePipelineState` in [d3d12_vulkan.md](d3d12_vulkan.md) §3.1) | | ||
| 474 | | 101 | `+0x328` | 28 | **1** (`0x1424813EF`) | `[0x1475DF018]` (alias) | `rcx`=device, `rdx`=&desc (dword 0 = `3`, dword 4 = index, `+8` = pointer), `r8`=&`IID_ID3D12StateObject`, `r9`=&out | three-argument, `riid`-out state-object creation with a leading type word `3` (`CreateStateObject` in [d3d12_vulkan.md](d3d12_vulkan.md) §3.1) | | ||
| 475 | | 108 | `+0x360` | 31 | **2** (`0x140ABFDA9`, `0x140ABFE07`) | vtable fetched from the device (`[0x1475DF030]` / `[0x1475DF035]`); `rdx` is the device itself: the slot returns a 16-byte struct, so the MSVC x64 ABI puts the hidden return buffer in `rcx` and `this` moves to `rdx` | `rcx`=&16-byte `D3D12_RESOURCE_ALLOCATION_INFO` return, `rdx`=device, `r8d`=1 (`visibleMask`), `r9d`=1 (`numResourceDescs`), `[rsp+0x20]`=&56-byte `D3D12_RESOURCE_DESC`, `[rsp+0x28]`=&24-byte scratch (`D3D12_RESOURCE_ALLOCATION_INFO1`-sized) | allocation-info query over one 56-byte resource description (4 KiB small-resource retry; routed as `GetResourceAllocationInfo2` in [d3d12_vulkan.md](d3d12_vulkan.md) §3.1) | | ||
| 476 | | 131 | `+0x418` | 26 | **0** | - | - | the offset is called, but only on non-device receivers here; a device form is unproven | | ||
| 477 | | 132 | `+0x420` | 47 | **1** (`0x1424745E4`) | `[0x1475DF048]` (the alias the copy loop reads) | `rcx`=device, `edx`=3 | single small enum/int argument | | ||
| 478 | | 133 | `+0x428` | 74 | **5** (`0x14006DD85`, `0x14193DFF8`, `0x14193E2D4`, `0x141E8684C`, `0x1456F802B`) | `[0x1475DF048]` or `[0x148759D00]` | `rcx`=device, `rdx`=GPU VA, `r8`=&`D3D12_RESOURCE_DESC`, `r9d`=state (`6`, `0xFFFFFFFF` or a register), `[rsp+0x20]`=clear, `[rsp+0x28]`=&`IID_ID3D12Resource`, `[rsp+0x30]`=&out | six-argument placed-resource creation, stable across all five sites | | ||
| 479 | |||
| 480 | Per slot: | ||
| 481 | |||
| 482 | - **86.** The `riid` at `0x1461E06B8` is `765a30f3-f624-4c6f-a828-ace948622445`, | ||
| 483 | `IID_ID3D12PipelineState` (§3), so the device form creates a PSO: `(desc, riid, out)`, which | ||
| 484 | [d3d12_vulkan.md](d3d12_vulkan.md) §3.1 (`runtime/shims/d3d12_xs_device.cpp`) routes as | ||
| 485 | `CreatePipelineState` to PC slot 47 (`ID3D12Device2::CreatePipelineState`). The | ||
| 486 | descriptor's first qword is the slot number itself (`mov qword ptr [rdx], 0x2B0`), i.e. the | ||
| 487 | caller keeps a command record. A second caller reaches the pair 86/87 on *another* object: at | ||
| 488 | `0x14258FC20`-`0x14258FC56` it loads the vtable into `r8`, sets `edx`, branches on a byte and | ||
| 489 | calls `+0x2B8` or `+0x2B0` with that one argument, then tags the returned qword `4` or `3`. So | ||
| 490 | the recorder form is one argument and a returned value, and the device form is the three-argument | ||
| 491 | creation; do not generalise either to the other. A shim that only knows 86 will miss the 87 | ||
| 492 | branch. | ||
| 493 | - **101.** The `riid` at `0x1461E06D8` is `47016943-fca8-4594-93ea-af258b55346d`, | ||
| 494 | `IID_ID3D12StateObject` (SDK `d3d12.h:44486`, not in the 28-IID set of §3). The descriptor is | ||
| 495 | `{dword 3, dword index, pointer}`: `[rdx]` is the type word `3` (`D3D12_STATE_OBJECT_TYPE_RAYTRACING_PIPELINE` | ||
| 496 | or collection), `[rdx+4]` an index into the table the caller just filled (`0x142481350`-`0x1424813BD`) | ||
| 497 | and `[rdx+8]` a pointer (`rdi`). That is the DXR state-object side of the game, routed in | ||
| 498 | [d3d12_vulkan.md](d3d12_vulkan.md) §3.1 (`runtime/shims/d3d12_xs_device.cpp`) as | ||
| 499 | `CreateStateObject(desc, riid, out)` to PC slot 62 (`ID3D12Device5::CreateStateObject`). | ||
| 500 | - **108.** No GUID is compared at either site. Both sit in one function, `0x140ABFAE0`-`0x140ABFE6C` | ||
| 501 | (reached through the thunk at `0x140ABFAD0`), which first computes the surface size and then makes | ||
| 502 | the one call twice at most. The 5th argument is a 56-byte `D3D12_RESOURCE_DESC`: the callee reads | ||
| 503 | `Dimension` at `+0`, `Alignment` at `+8`, `Width` at `+0x10`, `Height` at `+0x18`, | ||
| 504 | `DepthOrArraySize` at `+0x1C`, `Format` at `+0x20`, `Layout` at `+0x2C` and `Flags` at `+0x30`, and | ||
| 505 | writes back the 4-texel-aligned `Width`/`Height` for block-compressed formats | ||
| 506 | (`0x140ABFB2B`-`0x140ABFB40`). `Format` becomes bits per pixel through `0x144D9F3C0`, which indexes | ||
| 507 | the 128/96/64/32/16/8/4-bit table at `0x1461ED5B8`; dimension 4 (3D) with `Layout` 0 has `Layout` | ||
| 508 | set to the console word `0x105` (`0x140ABFD4B`-`0x140ABFD57`), dimension 3 (2D) takes the tile-shape | ||
| 509 | table, and a buffer is plain `Width × Height × Depth × bits`. When the whole surface is under | ||
| 510 | `0x80008` bits it writes `Alignment = 0x1000`, asks for that alignment, and if the returned alignment | ||
| 511 | is not `0x1000` clears `Alignment` to 0 and calls again (`0x140ABFDBF`-`0x140ABFE07`) — the retry the | ||
| 512 | SDK's small-resource sample does with `D3D12_SMALL_RESOURCE_PLACEMENT_ALIGNMENT` (4096, | ||
| 513 | `d3d12.h:1304`), and the 4 KiB small-texture alignment the host layer already answers | ||
| 514 | ([d3d12_vulkan.md](d3d12_vulkan.md) §4.2). The 16-byte return is `{SizeInBytes, Alignment}` and the | ||
| 515 | code traps unless the high dword of `SizeInBytes` is 0, so a returned size has to fit 32 bits | ||
| 516 | (`0x140ABFE15`). | ||
| 517 | That is the argument list, return placement and struct use of | ||
| 518 | `ID3D12Device4::GetResourceAllocationInfo1(visibleMask, numResourceDescs, pResourceDescs, | ||
| 519 | pResourceAllocationInfo1)` (`d3d12.h:12418-12422`), including a 24-byte | ||
| 520 | `D3D12_RESOURCE_ALLOCATION_INFO1` buffer as the 4th argument (`d3d12.h:2965-2970`); | ||
| 521 | [d3d12_vulkan.md](d3d12_vulkan.md) §3.1 (`runtime/shims/d3d12_xs_device.cpp`) serves it by | ||
| 522 | expanding the 56-byte `D3D12_RESOURCE_DESC` (normalising `0x105` and Xbox flag bits) and routing to | ||
| 523 | PC slot 68 (`ID3D12Device8::GetResourceAllocationInfo2`). **Measured**: the shape, the struct | ||
| 524 | offsets, `0x1000`/`0x105`, the retry and the assert. **Open**: the exact console wire method name | ||
| 525 | (`GetResourceAllocationInfo1` vs `GetResourceAllocationInfoX` / `2`) — no IID or symbol string is | ||
| 526 | present at the sites. | ||
| 527 | - **131.** Twenty-six sites, none on the device. Two are on sub-objects reached through another | ||
| 528 | global (`0x1415A487D` indexes a table at `[rax+0x28]`), one at `0x14437CFED` follows slot 130 | ||
| 529 | (`+0x410`) on the same receiver and reads the out dword it wrote, and the rest are on arguments | ||
| 530 | whose caller does not carry the device. The shape there is `(dword* out)` with a returned value | ||
| 531 | that a site compares (`0x141F9BE30`), plus a four-argument form | ||
| 532 | (`0xC280`, `0x20000`, `0`, `0xFFFFFFFFFF00` at `0x141560994`). It sits in the 0x400 block with | ||
| 533 | 132/133, and both of those do have device sites, so a device form is plausible but not shown: | ||
| 534 | do not implement it on the strength of these sites. | ||
| 535 | - **132.** The only device site passes `edx=3` and nothing else. Off the device the same offset is | ||
| 536 | a predicate taking one 32-bit constant (`2`, `3`, `0xFFF7E7A4`, `0xBD8817DB`) and returning in | ||
| 537 | `al` (`test al, al` at `0x14118ABB4`), which reads as a feature or capability query; that family's | ||
| 538 | receiver is not the device, so `3` cannot be read as a capability id for the device form yet. | ||
| 539 | - **133.** All five device sites are identical: VA, a console `D3D12_RESOURCE_DESC` (Xbox `Flags` | ||
| 540 | bits above the PC ones), state, clear, `IID_ID3D12Resource`, out. That is the same shape and the | ||
| 541 | same `riid` the retail run logged (`retail_boot_chain.md` §3.4, "device slot 133 places a | ||
| 542 | resource at a virtual address"), measured independently here from the same `riid` constant at | ||
| 543 | `0x1463FA690` in three different sites, all `696442be-a72e-4059-bc79-5b5c98040fad`. | ||
| 544 | Static and run agree on six arguments and on the order. This is the strongest row of the six. | ||
| 545 | Off the device the same offset is a different shape - `this` only, returning an object, at | ||
| 546 | `0x14107D67F`; `this` + `0` at `0x143BF0C50` - so 133 on another receiver is not this method. | ||
| 547 | |||
| 548 | The co-occurrence fits the block reading: 108 is called alongside 106/107/109/110/111 in | ||
| 549 | `0x140504AB0`, 131 alongside 57 in `0x14123C630`/`0x14123CD70`, and 132 with 133 in | ||
| 550 | `0x1403D2260`, `0x14060C420`, `0x14060CA50`, `0x141394800` and `0x141597B60`, always with the same | ||
| 551 | argument (`rdx` = the struct that carries the size/VA). None of those receivers is proven to be | ||
| 552 | the device, so the pairing says "one feature area", not "same arity" and not "device slot". | ||
| 553 | |||
| 554 | What this does not say: | ||
| 555 | |||
| 556 | - A raw site count is not a device count. The largest raw buckets are argument-provenance sites | ||
| 557 | (26 of 47 at 132, 40 of 74 at 133), many of them in wrapper code that re-dispatches on an | ||
| 558 | inherited or returned pointer. The same offset also carries a different arity off the device | ||
| 559 | (`0x14107D67F`, `0x143BF0C50` above), so an offset alone never names a method. | ||
| 560 | - `rdx`, `r8` and `r9` at a site can be dead for the method; only the setup within the last few | ||
| 561 | instructions is listed. The arity above is the *caller's* setup, not a header. | ||
| 562 | - No symbol string appears at any of the six call-site groups. On the device, 86, 101, 108 and | ||
| 563 | 133 match the routes in [d3d12_vulkan.md](d3d12_vulkan.md) §3.1 and | ||
| 564 | [retail_boot_chain.md](retail_boot_chain.md) §3.4 (`CreatePipelineState`, `CreateStateObject`, | ||
| 565 | `GetResourceAllocationInfo2` and `CreatePlacedResourceX` in | ||
| 566 | `runtime/shims/d3d12_xs_device.cpp`). Offsets `+0x418` (131) and `+0x420` (132) remain unnamed | ||
| 567 | here, and 131 has no device receiver. | ||
| 568 | - The proxy table must still be long enough: slot 133 is the highest slot the title reaches, so a | ||
| 569 | 128-entry table faults (retail observation) and anything below 134 is a guess. | ||
| 570 | |||
| 453 | ## 6. Command lists and `CreateCommandList` | 571 | ## 6. Command lists and `CreateCommandList` |
| 454 | 572 | ||
| 455 | The one measured console command-list rule, quoted from the UMD: | 573 | The one measured console command-list rule, quoted from the UMD: |
| @@ -675,7 +793,7 @@ evidence. | |||
| 675 | | 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 | |
| 676 | |---|---|---| | 794 | |---|---|---| |
| 677 | | #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 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). | |
| 678 | | #2 device/heap/queue/command-list slots | **partly measured** | 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. | |
| 679 | | #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. | |
| 680 | | #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. | |
| 681 | | #5 VA range / arena capacity | **still unknown** | — | | 799 | | #5 VA range / arena capacity | **still unknown** | — | |
| @@ -693,8 +811,9 @@ evidence. | |||
| 693 | | free-function dispositions | **answered as a list** | 7 standard + 16 console-only; Leonida serves 4 today. | | 811 | | free-function dispositions | **answered as a list** | 7 standard + 16 console-only; Leonida serves 4 today. | |
| 694 | 812 | ||
| 695 | The honest summary: SCARAB closes the **export/IID contract** and the **DMA-list rule**, and gives | 813 | The honest summary: SCARAB closes the **export/IID contract** and the **DMA-list rule**, and gives |
| 696 | a **name-level map** of the extension surface. It does not close presentation, slots, struct | 814 | a **name-level map** of the extension surface. It does not close presentation, the slot map, |
| 697 | layouts, numeric flags or tiling. | 815 | struct layouts, numeric flags or tiling; §5.2 adds five device slots to what the game itself |
| 816 | answers (leaving offset `+0x418` / 131 open with 0 device sites). | ||
| 698 | 817 | ||
| 699 | ## 10. Claims that did not hold up | 818 | ## 10. Claims that did not hold up |
| 700 | 819 | ||
diff --git a/docs/design.md b/docs/design.md index daeb4eb42..dcbbd4d63 100644 --- a/docs/design.md +++ b/docs/design.md | |||
| @@ -68,8 +68,12 @@ This writes `reports/exe/` (JSON plus a readable summary). Check it in this orde | |||
| 68 | 68 | ||
| 69 | 1. **Section entropy.** Sections near 8.0 bits/byte are still encrypted or compressed. If `.text` is one of them, | 69 | 1. **Section entropy.** Sections near 8.0 bits/byte are still encrypted or compressed. If `.text` is one of them, |
| 70 | nothing else can be done yet. | 70 | nothing else can be done yet. |
| 71 | 2. **Import table.** Each DLL is marked `bundled` (in the game folder), `system` (present on this Windows), or | 71 | 2. **Import table.** Each DLL is marked `bundled` (in the game folder, any case), `system` (present on this Windows), |
| 72 | `shim` (needs a reimplementation). The `shim` list is the real to-do list. | 72 | or `shim` (needs a reimplementation). The `shim` list is the real to-do list. On Linux or macOS, `system` is |
| 73 | checked in the Wine prefix's `system32` and its `apisetschema.dll` (`$WINEPREFIX`, else `~/.wine`), so the | ||
| 74 | list matches the Windows one. With no prefix, a DLL that is neither bundled nor owned by the runtime's shims | ||
| 75 | is `system (unverified)` (`"where": "unverified"` in the JSON) and is listed after the to-do. The report's | ||
| 76 | `system_dlls` field says where `system` was checked. | ||
| 73 | 3. **.pdata function count.** This gives function boundaries for patching and later analysis. | 77 | 3. **.pdata function count.** This gives function boundaries for patching and later analysis. |
| 74 | 4. **Inline command-list writes.** `python -I tools/inline_scan.py <game>\game_scarlett_master.exe --sites` (a few | 78 | 4. **Inline command-list writes.** `python -I tools/inline_scan.py <game>\game_scarlett_master.exe --sites` (a few |
| 75 | minutes; it streams `dumpbin /disasm`; it exits 2 when it reads no instructions). "UNCHECKED 0" means every | 79 | minutes; it streams `dumpbin /disasm`; it exits 2 when it reads no instructions). "UNCHECKED 0" means every |
| @@ -91,6 +95,17 @@ This writes `reports/exe/` (JSON plus a readable summary). Check it in this orde | |||
| 91 | Then `runtime\build\gta6rt.exe --dry-run <exe>` maps the image and binds every import to the shim table without | 95 | Then `runtime\build\gta6rt.exe --dry-run <exe>` maps the image and binds every import to the shim table without |
| 92 | running any game code. It reports what it couldn't bind. | 96 | running any game code. It reports what it couldn't bind. |
| 93 | 97 | ||
| 98 | The PE report's `resources` field (the Markdown's "Resources" section) lists the resource types with entry and | ||
| 99 | byte counts and reads the first `RT_VERSION` block. It gives the fixed file info's numbers (`file_version`, | ||
| 100 | `product_version`, `flags` and `flag_names`, `os`, `type`, `subtype`, `date`), the `translations`, and per string | ||
| 101 | table (`lang_codepage`) each standard key with its value's length (`chars`) and SHA-256 (of the value as UTF-8, | ||
| 102 | without its NUL). The values are never written, as they can name the title: two builds compare by hash. A key | ||
| 103 | outside the standard names, and a named resource type, are hashed or counted instead. A damaged tree or block | ||
| 104 | (cut short, a loop, a bad signature) is listed in `problems` and the rest of the report is still written. stdout | ||
| 105 | gets one line per image with a version block: its two versions and its key count. The 1.0.2.1 executable has no | ||
| 106 | resource directory (data directory 2 is zero and no `VS_VERSION_INFO` key is anywhere in the file), so its report | ||
| 107 | says `none`; 14 of the package's other 16 PE files carry a version block. | ||
| 108 | |||
| 94 | ## Reproduce the shader tests | 109 | ## Reproduce the shader tests |
| 95 | 110 | ||
| 96 | Build the hand-written tests where LLVM supports AMDGPU and SPIRV-Tools is available. Run the generated shaders | 111 | Build the hand-written tests where LLVM supports AMDGPU and SPIRV-Tools is available. Run the generated shaders |
| @@ -287,16 +302,16 @@ How the generated SPIR-V expects the runtime to work: | |||
| 287 | | 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**. | |
| 288 | | `s_load_dword*` with `vcc` 64-bit base pointer | SMEM `s_load_dword*` accepts `vcc` (`{vcc_lo, vcc_hi}`, hardware `s[106:107]`) as its 64-bit base pointer in `Gen.scalar_load`, loading `%vcc` as the low dword and `%vcc_hi` as the high dword; `s_buffer_load*` still requires a 4-dword V# and rejects 2-dword `vcc`. Source: RDNA2 ISA SMEM `SBASE` encoding (`sbase = 53` -> `s[106:107] = vcc`). Confirmed by corpus count over the 2,684-shader pipeline library compute corpus (79 shaders use `vcc` as the `s_load` base: 72 `s_load_dwordx4 sgpr, vcc`, 6 `s_load_dwordx8 sgpr, vcc`, 1 `s_load_dwordx4 slist, vcc`; all 79 translate and pass `spirv-val` under `--wave64-emulate`) and CPU-checked by `tests/semantic/test_sload_vcc_base.py` (`spirv-as` + `spirv-val`) and `tests/semantic/test_scalar_mem_smem.py` (both halves and the resulting addresses); **not GPU-verified**: the synthetic `runtime/test/shaders/cs_smem_vcc_base.asm` reads back eight seeded words through the pair in the standard GPU runner. | | 303 | | `s_load_dword*` with `vcc` 64-bit base pointer | SMEM `s_load_dword*` accepts `vcc` (`{vcc_lo, vcc_hi}`, hardware `s[106:107]`) as its 64-bit base pointer in `Gen.scalar_load`, loading `%vcc` as the low dword and `%vcc_hi` as the high dword; `s_buffer_load*` still requires a 4-dword V# and rejects 2-dword `vcc`. Source: RDNA2 ISA SMEM `SBASE` encoding (`sbase = 53` -> `s[106:107] = vcc`). Confirmed by corpus count over the 2,684-shader pipeline library compute corpus (79 shaders use `vcc` as the `s_load` base: 72 `s_load_dwordx4 sgpr, vcc`, 6 `s_load_dwordx8 sgpr, vcc`, 1 `s_load_dwordx4 slist, vcc`; all 79 translate and pass `spirv-val` under `--wave64-emulate`) and CPU-checked by `tests/semantic/test_sload_vcc_base.py` (`spirv-as` + `spirv-val`) and `tests/semantic/test_scalar_mem_smem.py` (both halves and the resulting addresses); **not GPU-verified**: the synthetic `runtime/test/shaders/cs_smem_vcc_base.asm` reads back eight seeded words through the pair in the standard GPU runner. | |
| 289 | | 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. | |
| 290 | | 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. A source lane inactive under EXEC is used when `fi` is 1; otherwise `bound_ctrl` decides. DPP8 always writes an enabled lane: `fi` 1 reads the inactive source, `fi` 0 uses 0. DPP16/8 never leaves its 16/8-lane group, so this is exact on every subgroup at least that wide; under `--wave64-emulate` the exchange goes through the workgroup buffer like the other cross-lane ops. GPU-checked with `runtime/test/shaders/cs_dpp*.asm` on an RTX 3070 and hardware-measured on an RX 6800. On an RX 6700 XT (gfx1031), `tools/crosslane_fuzz.py --dpp-sweep --oracle hw` checks every DPP16 control × `bound_ctrl` × `fi`, every `row_mask`/`bank_mask` pair and the DPP8 selects in wave32 and wave64: 14,412 cases, all matching these rules (BUILD-162, `docs/shader_validation.md` FUZZ-7). The ballot of the source lanes' EXEC bits and the shuffle are each stored to a Function variable of their own (`Gen.eager`): SPIRV-Cross (MoltenVK) inlines a single-use result into the expression that uses it, which put the ballot on the right of a short-circuiting `&&` and the shuffle in a ternary's arm, so lanes out of their row skipped the ballot and row_shr:1's lane 1 found lane 0 inactive (`cs_dpp_ops` on MoltenVK; SHADER-529). A store is a statement every lane runs. For native FI=0, the source-lane ballot bit also selects the shuffle index: an absent or EXEC-off source is redirected to the current subgroup lane before `OpGroupNonUniformShuffle`, because masking an undefined shuffle result afterwards is not sufficient; FI=1 is unchanged. CPU-checked by `tests/semantic/test_dpp_eager_subgroup.py::test_fi0_shuffle_index_is_ballot_safe` with a hand-written `quad_perm` case whose active lane 6 reads absent lane 7 in a seven-invocation wave; **not GPU-verified**. Checked in SPIRV-Cross 1.3.239's MSL for the `cs_dpp*` tests (each op is now its own statement) and by `tests/semantic/test_dpp_eager_subgroup.py`; not yet run on a Mac. Semantics from the RDNA2 ISA, AMD LLVM modifier syntax and the GPUOpen DPP notes. | | 305 | | DPP | VOP1/VOP2 `_dpp` applies to src0. DPP16 controls (`quad_perm`, `row_shl/shr/ror/share/xmask/mirror/half_mirror`) and DPP8 (`dpp8` + `fi`) select the source lane, then `row_mask` (one bit per 16-lane row) and `bank_mask` (one bit per 4-lane bank) decide which destination lanes update. A lane whose row/bank is off is not written. A source lane outside the row is invalid: `bound_ctrl` 1 uses 0 as src0, otherwise the lane is not written. Hardware applies src0 float modifiers (`neg`/`abs`) after the invalid-lane zero selection, so `-src0` on an invalid lane yields `-0.0f` (`0x80000000`) and `\|src0\|` yields `+0.0f` (HW-DPP-NEG-INVALID-LANE, measured on RDNA3 (gfx1101) RX 7800 XT, RDNA2 not measured; tested by `tests/semantic/test_dpp_bound_ctrl_modifiers.py`). A source lane inactive under EXEC is used when `fi` is 1; otherwise `bound_ctrl` decides. DPP8 always writes an enabled lane: `fi` 1 reads the inactive source, `fi` 0 uses 0. DPP16/8 never leaves its 16/8-lane group, so this is exact on every subgroup at least that wide; under `--wave64-emulate` the exchange goes through the workgroup buffer like the other cross-lane ops. GPU-checked with `runtime/test/shaders/cs_dpp*.asm` on an RTX 3070 and hardware-measured on an RX 6800. On an RX 6700 XT (gfx1031), `tools/crosslane_fuzz.py --dpp-sweep --oracle hw` checks every DPP16 control × `bound_ctrl` × `fi`, every `row_mask`/`bank_mask` pair and the DPP8 selects in wave32 and wave64: 14,412 cases, all matching these rules (BUILD-162, `docs/shader_validation.md` FUZZ-7). The ballot of the source lanes' EXEC bits and the shuffle are each stored to a Function variable of their own (`Gen.eager`): SPIRV-Cross (MoltenVK) inlines a single-use result into the expression that uses it, which put the ballot on the right of a short-circuiting `&&` and the shuffle in a ternary's arm, so lanes out of their row skipped the ballot and row_shr:1's lane 1 found lane 0 inactive (`cs_dpp_ops` on MoltenVK; SHADER-529). A store is a statement every lane runs. For native FI=0, the source-lane ballot bit also selects the shuffle index: an absent or EXEC-off source is redirected to the current subgroup lane before `OpGroupNonUniformShuffle`, because masking an undefined shuffle result afterwards is not sufficient; FI=1 is unchanged. CPU-checked by `tests/semantic/test_dpp_eager_subgroup.py::test_fi0_shuffle_index_is_ballot_safe` with a hand-written `quad_perm` case whose active lane 6 reads absent lane 7 in a seven-invocation wave; **not GPU-verified**. Checked in SPIRV-Cross 1.3.239's MSL for the `cs_dpp*` tests (each op is now its own statement) and by `tests/semantic/test_dpp_eager_subgroup.py`; not yet run on a Mac. Semantics from the RDNA2 ISA, AMD LLVM modifier syntax and the GPUOpen DPP notes. | |
| 291 | | DPP on a VOPC compare | A VOPC compare whose src0 field is a DPP marker (250 for DPP16, 233/234 for DPP8) takes src0 through the DPP lane selection of the row above and writes VCC: a lane's bit is `compare(src0 of the selected lane, its own src1)`, with 0 for src0 when the selected lane is out of its row or inactive (`bound_ctrl` 1, or DPP8 with `fi` 0). The second word has the layout of a VOP2's DPP word. `llvm-mc` has no decoding for it on gfx10 (LLVM 21.1.8 rejects the first word for `gfx1013`; LLVM defines the form from GFX11 on), so `tools/shader_disasm.py` prints it: it decodes the pair with the first word turned into `v_max_f32` into `v0`, which takes the same second word, and gives the line the compare's name, a `vcc_lo` destination and the real encoding back (`with_vopc_dpp`); `tools/rdna2_decode.py` decodes it directly. **Only the forms where every lane writes its bit are translated**: `row_mask` and `bank_mask` 0xF and either `bound_ctrl` 1 or DPP8. Any other form, and `v_cmpx`, is refused (`DPP compare with lanes that keep their mask bit`), because what a lane DPP leaves unwritten does to its VCC bit is not measured. Found in 3 of the 2,684 pipeline-library compute programs of 1.0.2.1: 4 `v_cmp_gt_f32` each, with `quad_perm:[1,0,3,2]`, `quad_perm:[2,3,0,1]`, `row_ror:8` (all `bound_ctrl:1`, masks 0xF) and `dpp8:[4,5,6,7,0,1,2,3]`, beside `v_min/max_f32_dpp` and `v_mov_b32_dpp` on the same lanes. **Not measured on hardware**: the rule follows from the encoding, from LLVM's GFX11 definition of the same form and from the VOP2 DPP rules measured in the row above; the sweep that measured those (`tools/crosslane_fuzz.py --dpp-sweep --oracle hw`) does not cover compares. Lane values are checked in `tests/semantic/test_dpp_compare.py` (the SPIR-V interpreter) and on a GPU with `runtime/test/shaders/cs_dpp_cmp.asm`. | | 306 | | DPP on a VOPC compare | A VOPC compare whose src0 field is a DPP marker (250 for DPP16, 233/234 for DPP8) takes src0 through the DPP lane selection of the row above and writes VCC: a lane's bit is `compare(src0 of the selected lane, its own src1)`, with 0 for src0 when the selected lane is out of its row or inactive (`bound_ctrl` 1, or DPP8 with `fi` 0). The second word has the layout of a VOP2's DPP word. `llvm-mc` has no decoding for it on gfx10 (LLVM 21.1.8 rejects the first word for `gfx1013`; LLVM defines the form from GFX11 on), so `tools/shader_disasm.py` prints it: it decodes the pair with the first word turned into `v_max_f32` into `v0`, which takes the same second word, and gives the line the compare's name, a `vcc_lo` destination and the real encoding back (`with_vopc_dpp`); `tools/rdna2_decode.py` decodes it directly. **Only the forms where every lane writes its bit are translated**: `row_mask` and `bank_mask` 0xF and either `bound_ctrl` 1 or DPP8. Any other form, and `v_cmpx`, is refused (`DPP compare with lanes that keep their mask bit`), because what a lane DPP leaves unwritten does to its VCC bit is not measured. Found in 3 of the 2,684 pipeline-library compute programs of 1.0.2.1: 4 `v_cmp_gt_f32` each, with `quad_perm:[1,0,3,2]`, `quad_perm:[2,3,0,1]`, `row_ror:8` (all `bound_ctrl:1`, masks 0xF) and `dpp8:[4,5,6,7,0,1,2,3]`, beside `v_min/max_f32_dpp` and `v_mov_b32_dpp` on the same lanes. **Not measured on hardware**: the rule follows from the encoding, from LLVM's GFX11 definition of the same form and from the VOP2 DPP rules measured in the row above; the sweep that measured those (`tools/crosslane_fuzz.py --dpp-sweep --oracle hw`) does not cover compares. Lane values are checked in `tests/semantic/test_dpp_compare.py` (the SPIR-V interpreter) and on a GPU with `runtime/test/shaders/cs_dpp_cmp.asm`. | |
| 292 | | EXEC | A per-invocation `active` flag. VALU writes and exports are masked by it, scalar ops aren't, and `v_cmpx`, saveexec and EXEC writes update it. Measured on native gfx1100 (8 threads): a `v_mov_b32` under `EXEC=0x0F` leaves the other lanes untouched, `EXEC=0` writes nothing, a store writes only active lanes and `v_cmpx_gt_u32` narrows EXEC (4 of 4 cases); note that AMD clang 20 rejects `v_add_co_u32`, `v_sub_co_u32`, `v_add_co_ci_u32` and `v_mad_u64_u32` for `gfx1100`, `gfx1101` and `gfx1102`, so this toolchain could not reproduce the RX 7600 result below, which leaves open whether those parts support the opcodes and says only that they could not be assembled here. **A pixel is written when its lane was on in EXEC at the last `exp ... vm` the path executed (if it executed one) and at the last export to the color target; a path with no export at all goes by EXEC at the end.** The `vm` half is the RDNA2 ISA reference guide's rule (30-November-2020, §11.1 and §11.2.1: EXEC at the export is the valid mask and the final one sent is used; an `exp null ... vm` carries only the mask). The color half is measured: an export sends data only for the lanes that are on, a later export to the same target replaces the earlier one for the whole wave, and a lane with no data from the last one is not written even when a later `exp null done vm` marks it valid. So `exp mrt0 done` (no `vm`) with every lane on, followed by an EXEC write, still writes every pixel, and EXEC off at that export and back on afterwards writes none. **Measured on RDNA2** (AMD Radeon iGPU, gfx1036, driver 26.10.1) with the pixel-shader oracle of #3061 (`ps_oracle.py`), hand-written ISA as the pixel shader of a real draw (wave64 stage): 18 programs that cut EXEC to half of the target before, between or after `exp mrt0` (with and without `vm` and `done`) and `exp null done vm`; all 18 fit the rule, 6 of them differed from the translator, which until 2026-11-23 discarded by EXEC at the end on a path without `vm` and kept the older export's value (or the output's initial value) for a lane that was off at the last color export. The latches (`%vm_mask`, `%col_mask_mrtN`) are only emitted where a path can write EXEC after a `vm` or color export; everywhere else EXEC at the end is the same mask and the SPIR-V is unchanged. With several color targets a pixel stays when any target got an export from its lane (Vulkan cannot skip one attachment per pixel; not measured, the oracle's pipeline has one target); `mrtz` is not part of the color mask (not measured). **Measuring exports needs `s_waitcnt expcnt(0)` after each one**: an export is asynchronous, and without the wait the hardware takes the data and the EXEC of a later moment (`v_mov v9, A; exp mrt0 v9 done vm; v_mov v9, B` shows B, and an EXEC write right after the export decides which pixels are written, which looks like "EXEC at the end decides"); 64 `s_nop 15` have the same effect as the wait. Checked on the CPU by `tests/semantic/test_export_valid_mask.py` and on the GPU by `runtime/test/shaders/ps_exp_color_mask.asm` (RTX 5080 and the Radeon). VALU scalar lane-mask destinations (`v_cmp_*`, `v_add_co_u32`, `v_add_co_ci_u32`, `v_sub_co_u32`, `v_sub_co_ci_u32`, `v_subrev_co_u32`, `v_subrev_co_ci_u32`, `v_mad_u64_u32`, `v_mad_i64_i32`) write 0 for lanes off in EXEC (`SDST[lane] = EXEC[lane] ? bit : 0`, AMD RDNA2 ISA). Until 2026-11-22 the six `*_co_*` ops and `v_mad_u64_u32`/`v_mad_i64_i32` did not AND the carry/sign bit with `active`, so inactive lanes leaked 1 bits into `VCC`/SGPR masks (`s_bcnt1`, `s_cbranch_vccz`, `v_cndmask_b32`). Checked on the CPU by `tests/semantic/test_carry_exec_mask.py` (wave32, wave64, and `--wave64-emulate` structure), and **hardware-verified on an AMD RX 7600 (gfx1102)** with `v_add_co_u32` and `v_add_co_ci_u32` carrying on every active lane: VCC reads `0xffffffff` with full EXEC, `0x0000ffff` for the mask `0x0000ffff` and `0xaaaaaaaa` for `0xaaaaaaaa` in wave32, `vcc_lo = 0x0000ffff` with `vcc_hi = 0x0000000f` for the same partial mask in wave64, and `0` when EXEC is 0 even with VCC preloaded to all ones; with one carrying lane under mask `0x0000ffff` VCC is `0x00000001`, and `v_sub_co_u32`/`v_subrev_co_u32` with a borrow under that mask give `0x0000ffff` too. The `*_co_ci_` forms, `v_mad_u64_u32` and `v_mad_i64_i32` share the same path but were not measured separately; it is also GPU-verified on native RDNA2 (gfx1036, AMD Radeon Graphics) with partial EXEC masks (inactive lanes write 0 in sdst for `v_add_co_u32` and `v_mad_u64_u32`). In a shader that writes EXEC, a run of two or more lane-local VALU instructions (no cross-lane read, no lane-mask, SCC, carry or EXEC write) sits inside one `if (active)` and writes its VGPRs directly, instead of an `OpSelect(active, new, old)` per write: the same result, but the driver predicates the run with its own EXEC instead of keeping both values live. On an RX 5700 XT (RADV) a pixel shader with 8 divergent if/else regions of `v_fma`/`v_mul`/`v_add`/`v_min`/`v_max` went from 0.85 ms to 0.69 ms (the same program as native SPIR-V: 0.65 ms). Not under `--wave64-emulate`. Checked by `tests/semantic/test_active_runs.py`. | | 307 | | EXEC | A per-invocation `active` flag. VALU writes and exports are masked by it, scalar ops aren't, and `v_cmpx`, saveexec and EXEC writes update it. Measured on native gfx1100 (8 threads): a `v_mov_b32` under `EXEC=0x0F` leaves the other lanes untouched, `EXEC=0` writes nothing, a store writes only active lanes and `v_cmpx_gt_u32` narrows EXEC (4 of 4 cases); note that AMD clang 20 rejects `v_add_co_u32`, `v_sub_co_u32`, `v_add_co_ci_u32` and `v_mad_u64_u32` for `gfx1100`, `gfx1101` and `gfx1102`, so this toolchain could not reproduce the RX 7600 result below, which leaves open whether those parts support the opcodes and says only that they could not be assembled here. **A pixel is written when its lane was on in EXEC at the last `exp ... vm` the path executed (if it executed one) and at the last export to the color target; a path with no export at all goes by EXEC at the end.** The `vm` half is the RDNA2 ISA reference guide's rule (30-November-2020, §11.1 and §11.2.1: EXEC at the export is the valid mask and the final one sent is used; an `exp null ... vm` carries only the mask). The color half is measured: an export sends data only for the lanes that are on, a later export to the same target replaces the earlier one for the whole wave, and a lane with no data from the last one is not written even when a later `exp null done vm` marks it valid. So `exp mrt0 done` (no `vm`) with every lane on, followed by an EXEC write, still writes every pixel, and EXEC off at that export and back on afterwards writes none. **Measured on RDNA2** (AMD Radeon iGPU, gfx1036, driver 26.10.1) with the pixel-shader oracle of #3061 (`ps_oracle.py`), hand-written ISA as the pixel shader of a real draw (wave64 stage): 18 programs that cut EXEC to half of the target before, between or after `exp mrt0` (with and without `vm` and `done`) and `exp null done vm`; all 18 fit the rule, 6 of them differed from the translator, which until 2026-11-23 discarded by EXEC at the end on a path without `vm` and kept the older export's value (or the output's initial value) for a lane that was off at the last color export. The latches (`%vm_mask`, `%col_mask_mrtN`) are only emitted where a path can write EXEC after a `vm` or color export; everywhere else EXEC at the end is the same mask and the SPIR-V is unchanged. With several color targets a pixel stays when any target got an export from its lane (Vulkan cannot skip one attachment per pixel; not measured, the oracle's pipeline has one target); `mrtz` is not part of the color mask (not measured). **Measuring exports needs `s_waitcnt expcnt(0)` after each one**: an export is asynchronous, and without the wait the hardware takes the data and the EXEC of a later moment (`v_mov v9, A; exp mrt0 v9 done vm; v_mov v9, B` shows B, and an EXEC write right after the export decides which pixels are written, which looks like "EXEC at the end decides"); 64 `s_nop 15` have the same effect as the wait. Checked on the CPU by `tests/semantic/test_export_valid_mask.py` and on the GPU by `runtime/test/shaders/ps_exp_color_mask.asm` (RTX 5080 and the Radeon). VALU scalar lane-mask destinations (`v_cmp_*`, `v_add_co_u32`, `v_add_co_ci_u32`, `v_sub_co_u32`, `v_sub_co_ci_u32`, `v_subrev_co_u32`, `v_subrev_co_ci_u32`, `v_mad_u64_u32`, `v_mad_i64_i32`) write 0 for lanes off in EXEC (`SDST[lane] = EXEC[lane] ? bit : 0`, AMD RDNA2 ISA). Until 2026-11-22 the six `*_co_*` ops and `v_mad_u64_u32`/`v_mad_i64_i32` did not AND the carry/sign bit with `active`, so inactive lanes leaked 1 bits into `VCC`/SGPR masks (`s_bcnt1`, `s_cbranch_vccz`, `v_cndmask_b32`). Checked on the CPU by `tests/semantic/test_carry_exec_mask.py` (wave32, wave64, and `--wave64-emulate` structure), and **hardware-verified on an AMD RX 7600 (gfx1102)** with `v_add_co_u32` and `v_add_co_ci_u32` carrying on every active lane: VCC reads `0xffffffff` with full EXEC, `0x0000ffff` for the mask `0x0000ffff` and `0xaaaaaaaa` for `0xaaaaaaaa` in wave32, `vcc_lo = 0x0000ffff` with `vcc_hi = 0x0000000f` for the same partial mask in wave64, and `0` when EXEC is 0 even with VCC preloaded to all ones; with one carrying lane under mask `0x0000ffff` VCC is `0x00000001`, and `v_sub_co_u32`/`v_subrev_co_u32` with a borrow under that mask give `0x0000ffff` too. The `*_co_ci_` forms, `v_mad_u64_u32` and `v_mad_i64_i32` share the same path but were not measured separately; it is also GPU-verified on native RDNA2 (gfx1036, AMD Radeon Graphics) with partial EXEC masks (inactive lanes write 0 in sdst for `v_add_co_u32` and `v_mad_u64_u32`). In a shader that writes EXEC, a run of two or more lane-local VALU instructions (no cross-lane read, no lane-mask, SCC, carry or EXEC write) sits inside one `if (active)` and writes its VGPRs directly, instead of an `OpSelect(active, new, old)` per write: the same result, but the driver predicates the run with its own EXEC instead of keeping both values live. On an RX 5700 XT (RADV) a pixel shader with 8 divergent if/else regions of `v_fma`/`v_mul`/`v_add`/`v_min`/`v_max` went from 0.85 ms to 0.69 ms (the same program as native SPIR-V: 0.65 ms). Not under `--wave64-emulate`. Checked by `tests/semantic/test_active_runs.py`. | |
| 293 | | `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. | |
| 294 | | Control flow | Reducible graphs use structured branches and natural loops. Irreducible graphs use the dispatch-loop form, which can also be forced with `--dispatch-loop` for comparisons. The control-flow unit test checks 18,228 generated graphs. Irreducible graphs use node splitting (`cfg_structure.split_irreducible`, up to `min(2*N, N+64)` blocks) and fall back to the dispatch-loop form when capped; it can also be forced with `--dispatch-loop` for comparisons. `cfg_structure.structure`, `cfg_structure.run`, and `rdna2spirv.assemble`'s structured emitter are iterative and hoist each guarded member's dominated tail continuation out of its enclosing guard (exact by strict dominance: no block outside the guard's subtree can target the continuation), keeping `OpSelectionMerge` nesting O(1) on sequential diamond/loop chains instead of nesting O(N) deep and hitting Python's recursion limit on multi-thousand-block shaders (e.g. 2,000 sequential diamonds nest to depth 2 instead of 2,000). The control-flow unit test (`tests/test_cfg_structure.py`) checks 20,000 generated graphs plus 2,000-diamond, 1,200-loop, and 1,500-early-exit chains. AMD A/B checks compare the two forms for selected pixel shaders with defined test inputs. For shaders that never export colour, the comparison checks pixel coverage. **Nesting is bounded (SHADER-299):** a tree deeper than `MAX_STRUCTURED_DEPTH` (16) is emitted in the dispatch-loop form instead, since `spirv-val` time grows roughly with the cube of the measured nesting depth. **Nesting is bounded (SHADER-299, SHADER-427):** a tree deeper than `MAX_STRUCTURED_DEPTH` (64; `--max-structured-depth N`, 0 = no bound) is emitted in the dispatch-loop form instead, since `spirv-val` time grows roughly with the cube of the measured nesting depth. Before #1904, over the 1.0.2.1 corpus (26,503 modules, `spirv-val` 2026.4): the deepest block of a module is nested 118 constructs deep, 12,963 modules are structured (median 15) and 6,000 of those are deeper than 16; an estimated 85% of the corpus's `spirv-val` time is in modules nested 20 or deeper. Median `spirv-val` time for the same module in each form: depth 20 181 -> 129 ms (1.4x), 30 507 -> 371 (1.4x), 50 1,712 -> 738 (2.3x), 64 2,692 -> 1,163 (2.3x), 77 5,122 -> 1,130 (4.5x), and the deepest (118) 13,683 -> 1,352 ms (10.1x). Depth 5-12 shows no gain (at depth 6 the flat form is slightly slower), which is why the bound first sat at 16. Since #1904 (`cfg_structure` hoists tails) the deepest tree in the corpus is 29: of 12,944 structured modules, 1,031 are deeper than 16 (747 CS, 284 PS), 57 deeper than 20, 24 deeper than 24. For those 1,031 the flat form saves only 12% of `spirv-val` time (1,235 -> 1,091 s summed, slowest module 8.3 -> 5.9 s), while on an RTX 5070 Ti (NVIDIA 621.24) it compiles slower: the 284 pixel shaders 1.67x (827 -> 1,382 s summed, two rounds), four compute modules at depth 19-24 2.0x (297 -> 591 s, 1.6-2.7x each), so the bound now sits above the corpus (SHADER-427). Both forms pass `spirv-val` on a 200-shader slice (200/200 each), and `gen.nesting` records the tree depth. AMD's Windows driver adds a reason to keep the structured form (SHADER-995): on a Radeon gfx1036 iGPU (32.0.21042.62) the dispatch-loop module of `XboxBvhBuilder.dll`'s `LeafRehydration` (tree depth 18, a 581-case switch) takes 34 minutes to create (XXDESIGN), where its structured module is created in 2.9 s; ten other programs of that DLL compile in the dispatch-loop form there in 0.4-40 s, 2.5-5x their structured time ([embedded_shaders.md](embedded_shaders.md), section 7). | | 309 | | Control flow | Reducible graphs use structured branches and natural loops. Irreducible graphs use the dispatch-loop form, which can also be forced with `--dispatch-loop` for comparisons. The control-flow unit test checks 18,228 generated graphs. Irreducible graphs use node splitting (`cfg_structure.split_irreducible`, up to `min(2*N, N+64)` blocks) and fall back to the dispatch-loop form when capped; it can also be forced with `--dispatch-loop` for comparisons. `cfg_structure.structure`, `cfg_structure.run`, and `rdna2spirv.assemble`'s structured emitter are iterative and hoist each guarded member's dominated tail continuation out of its enclosing guard (exact by strict dominance: no block outside the guard's subtree can target the continuation), keeping `OpSelectionMerge` nesting O(1) on sequential diamond/loop chains instead of nesting O(N) deep and hitting Python's recursion limit on multi-thousand-block shaders (e.g. 2,000 sequential diamonds nest to depth 2 instead of 2,000). The control-flow unit test (`tests/test_cfg_structure.py`) checks 20,000 generated graphs plus 2,000-diamond, 1,200-loop, and 1,500-early-exit chains. `capped_tree()` also runs `cfg_structure.unwrap_known_pc_guards` (shared with `wave64_emulate_opt`) to unwrap tautological `("guard", g, ...)` nodes whenever abstract interpretation proves `%pc == g` on all incoming paths (e.g. post-dominating merge blocks after diamonds and loops); this keeps `ms_wave_info_s3`'s `s_barrier` in uniform top-level control flow (fixing an AMD Windows LLPC `0xC0000005` pipeline-creation crash on AMD Ryzen 5 7600 RDNA2 iGPU driver `24.10.24`, `4096/4096` exact on AMD RDNA2 and RTX 4070 SUPER) and avoids false `needs_barrier_rounds` triggers (`SHADER-STRUCTURED-PC-UNWRAP`). AMD A/B checks compare the two forms for selected pixel shaders with defined test inputs. For shaders that never export colour, the comparison checks pixel coverage. **Nesting is bounded (SHADER-299):** a tree deeper than `MAX_STRUCTURED_DEPTH` (16) is emitted in the dispatch-loop form instead, since `spirv-val` time grows roughly with the cube of the measured nesting depth. **Nesting is bounded (SHADER-299, SHADER-427):** a tree deeper than `MAX_STRUCTURED_DEPTH` (64; `--max-structured-depth N`, 0 = no bound) is emitted in the dispatch-loop form instead, since `spirv-val` time grows roughly with the cube of the measured nesting depth. Before #1904, over the 1.0.2.1 corpus (26,503 modules, `spirv-val` 2026.4): the deepest block of a module is nested 118 constructs deep, 12,963 modules are structured (median 15) and 6,000 of those are deeper than 16; an estimated 85% of the corpus's `spirv-val` time is in modules nested 20 or deeper. Median `spirv-val` time for the same module in each form: depth 20 181 -> 129 ms (1.4x), 30 507 -> 371 (1.4x), 50 1,712 -> 738 (2.3x), 64 2,692 -> 1,163 (2.3x), 77 5,122 -> 1,130 (4.5x), and the deepest (118) 13,683 -> 1,352 ms (10.1x). Depth 5-12 shows no gain (at depth 6 the flat form is slightly slower), which is why the bound first sat at 16. Since #1904 (`cfg_structure` hoists tails) the deepest tree in the corpus is 29: of 12,944 structured modules, 1,031 are deeper than 16 (747 CS, 284 PS), 57 deeper than 20, 24 deeper than 24. For those 1,031 the flat form saves only 12% of `spirv-val` time (1,235 -> 1,091 s summed, slowest module 8.3 -> 5.9 s), while on an RTX 5070 Ti (NVIDIA 621.24) it compiles slower: the 284 pixel shaders 1.67x (827 -> 1,382 s summed, two rounds), four compute modules at depth 19-24 2.0x (297 -> 591 s, 1.6-2.7x each), so the bound now sits above the corpus (SHADER-427). Both forms pass `spirv-val` on a 200-shader slice (200/200 each), and `gen.nesting` records the tree depth. AMD's Windows driver adds a reason to keep the structured form (SHADER-995): on a Radeon gfx1036 iGPU (32.0.21042.62) the dispatch-loop module of `XboxBvhBuilder.dll`'s `LeafRehydration` (tree depth 18, a 581-case switch) takes 34 minutes to create (XXDESIGN), where its structured module is created in 2.9 s; ten other programs of that DLL compile in the dispatch-loop form there in 0.4-40 s, 2.5-5x their structured time ([embedded_shaders.md](embedded_shaders.md), section 7). | |
| 295 | | Loop guard | Each loop counts header visits per invocation and exits through its structured merge at `--loop-limit N` (default 65536, zero disables). Counters reset on entry, including nested EXEC retries and atomic loops. A PC-dispatch visit counts a dispatch iteration. Natural exits within the budget preserve their outputs. Five-star-recomp (b12a952) reported a story-load timeout when the shader input made its exit condition unreachable. | | 310 | | Loop guard | Each loop counts header visits per invocation and exits through its structured merge at `--loop-limit N` (default 65536, zero disables). Counters reset on entry, including nested EXEC retries and atomic loops. A PC-dispatch visit counts a dispatch iteration. Natural exits within the budget preserve their outputs. Five-star-recomp (b12a952) reported a story-load timeout when the shader input made its exit condition unreachable. | |
| 296 | | User data | **Push constants, 144 bytes:** dwords 0–31 = initial s0–s31 (the user SGPRs the console driver loads from the root signature: descriptor-table pointers, constants and so on), dwords 32–33 = the 64-bit **heap base**, dwords 34–35 = the **code base**: the Xbox VA where the runtime uploaded this shader's whole FSSM blob. `--mesh-compute` modules add dwords 36–37, the output buffer address (152 bytes; see "Mesh shaders as compute"). `--pc-tail-ubo` keeps only dwords 0–31 here (128 bytes) and moves the rest to a uniform block (see "Push-constant tail as a uniform block"). The runtime has to reproduce the console driver's root-signature-to-user-SGPR mapping; that comes from the exe or driver behaviour. **Mesh shaders** read their root SGPRs through the graphics root window: s16..s31 come from dwords 8..23 (where a VS, PS or GS reads s8..s23), s8..s15 are 0, s0..s7 dwords 0..7; the index records `"root_window": {"sgpr": 16, "dword": 8}` (D3D-448-GRAPHICS, `docs/d3d12_vulkan.md` 3.5). Checked by `tests/semantic/test_ms_root_window.py` (MeshEXT and `--mesh-compute`, CPU interpreter) and `d3d12_mesh_test` (RX 9070 XT). | | 311 | | User data | **Push constants, 144 bytes:** dwords 0–31 = initial s0–s31 (the user SGPRs the console driver loads from the root signature: descriptor-table pointers, constants and so on), dwords 32–33 = the 64-bit **heap base**, dwords 34–35 = the **code base**: the Xbox VA where the runtime uploaded this shader's whole FSSM blob. `--mesh-compute` modules add dwords 36–37, the output buffer address (152 bytes; see "Mesh shaders as compute"). `--pc-tail-ubo` keeps only dwords 0–31 here (128 bytes) and moves the rest to a uniform block (see "Push-constant tail as a uniform block"). The runtime has to reproduce the console driver's root-signature-to-user-SGPR mapping; that comes from the exe or driver behaviour. **Mesh shaders** read their root SGPRs through the graphics root window: s16..s31 come from dwords 8..23 (where a VS, PS or GS reads s8..s23), s8..s15 are 0, s0..s7 dwords 0..7; the index records `"root_window": {"sgpr": 16, "dword": 8}` (D3D-448-GRAPHICS, `docs/d3d12_vulkan.md` 3.5). Checked by `tests/semantic/test_ms_root_window.py` (MeshEXT and `--mesh-compute`, CPU interpreter) and `d3d12_mesh_test` (RX 9070 XT). | |
| 297 | | Direct resource heap | In the matched Prop/Tree BatchCull compute signature the two explicit tables and scalar constant occupy s4–s6. Bind the resource heap's uint32 arena-relative byte address at s7 (push-constant byte 28). The program supplies a zero high word and scales the resource index by 32 bytes. Other stages and signatures consume different SGPRs. See [descriptor heaps and the bindless model](d3d12_vulkan.md#34-descriptor-heaps-and-the-bindless-model) for the evidence and graphics examples. | | 312 | | Direct resource heap | In the matched Prop/Tree BatchCull compute signature the two explicit tables and scalar constant occupy s4–s6. Bind the resource heap's uint32 arena-relative byte address at s7 (push-constant byte 28). The program supplies a zero high word and scales the resource index by 32 bytes. Other stages and signatures consume different SGPRs. See [descriptor heaps and the bindless model](d3d12_vulkan.md#34-descriptor-heaps-and-the-bindless-model) for the evidence and graphics examples. | |
| 298 | | Xbox GPU addresses | Shaders build Xbox GPU virtual addresses, and some force the high dword to 0 (descriptor tables in the low 4 GB). Every memory access goes to **heap base + Xbox VA**, so the runtime maps the console's GPU address window into one host buffer-device-address allocation. | | 313 | | Xbox GPU addresses | Shaders build Xbox GPU virtual addresses, and some force the high dword to 0 (descriptor tables in the low 4 GB). Every memory access goes to **heap base + Xbox VA**, so the runtime maps the console's GPU address window into one host buffer-device-address allocation. | |
| 299 | | Code-embedded data | 155 VS/PS had "undecodable words". They're **constant tables inside the code range** (float values like 0x3EF7…, plus zeros), read through `s_getpc_b64` + `s_add_u32`/`s_addc_u32` + `s_load` (147 of 155). The translator re-anchors each instruction to its true FSSM offset by matching encodings (when the llvm-mc messages give one offset per rejected word, `shader_ir.parse_file`'s `invalid_at`, those words are skipped exactly and nothing is searched forward: a forward search let a data word printed as a copy of a later instruction take that instruction's place and lose every one after it; counted on the 1.0.2.1 pipeline library with #327's vcc-tuple decoding, 36 compute programs that stopped at "cannot re-anchor" now translate and pass `spirv-val`, none lost; `tests/semantic/test_reanchor_llvm_offsets.py`), translates only code reachable from entry (a branch into data is rejected), and turns `s_getpc_b64` into code base + next-instruction offset. **The runtime uploads each shader's FSSM blob into the heap and passes that VA as the code base.** Re-anchoring compares bytes exactly, except that VOP3P `op_sel_hi[2]` (bit 14) is ignored on two-source packed ops: the compiler stores 0 there, and LLVM prints its default of 1. Unused VOP3/VOP3P `SRC1` (bits 49:41) and `SRC2` (bits 58:50) fields are also ignored when stored as 0 and printed as `0x80`: LLVM 23 re-encodes a source it doesn't read as inline constant 0 (one-source `v_rcp`/`v_log`/`v_sqrt_f32_e64`, two-source `v_sub_f32_e64`/`v_cmp_*_e64`/`v_mul_lo_u32`/`v_pk_mul_f16`). Both checks for clean listings and re-anchoring use the parsed operand count to apply this exception only to unused sources. A used source encoded as 0 reads `s0` and is never treated as inline zero. `tests/semantic/test_printed_encoding.py` checks used `SRC1`/`SRC2` and an unused field with synthetic listings. Confirmed by a count over the corpus with LLVM 23.1.5: without it, 1,471 of the 1,473 shaders with embedded data are rejected ("reachable instruction with normalized encoding"); with it, all 1,473 translate and pass `spirv-val`. Runs with LLVM 21 already translated all of them, so older LLVMs presumably print the stored 0 (not re-checked). Data words that decode with ignored fields set are printed re-encoded (e.g. `0xbe8d2242` as `s_rfe_b64` `0xbe802242`), so they can never match. Since the decoder consumed the same length, they are anchored in sequence and marked. A shader that can *reach* a marked word is rejected; none of the corpus does. All 155 now translate. A reachable instruction that falls through into words llvm-mc skipped (it printed no instruction there) is rejected too, as `fall-through into undecodable words`: until SHADER-813 the reachable path ended there without a word, so everything after the gap (exports, stores) was dropped from a module that still passed `spirv-val`. No VS/PS of the corpus has such a gap on a reachable path; in the FidelityFX FSPX programs it is the `v_dot4_i32_i8 ... op_sel` words LLVM 23 cannot decode (`docs/fspx.md`), so those programs are now refused instead of translated without their stores, until those words are decoded (#2038, #2323). `tests/test_rdna2spirv_decode.py` (`test_fall_through_into_undecodable_words_is_refused`). | | 314 | | Code-embedded data | 155 VS/PS had "undecodable words". They're **constant tables inside the code range** (float values like 0x3EF7…, plus zeros), read through `s_getpc_b64` + `s_add_u32`/`s_addc_u32` + `s_load` (147 of 155). The translator re-anchors each instruction to its true FSSM offset by matching encodings (when the llvm-mc messages give one offset per rejected word, `shader_ir.parse_file`'s `invalid_at`, those words are skipped exactly and nothing is searched forward: a forward search let a data word printed as a copy of a later instruction take that instruction's place and lose every one after it; counted on the 1.0.2.1 pipeline library with #327's vcc-tuple decoding, 36 compute programs that stopped at "cannot re-anchor" now translate and pass `spirv-val`, none lost; `tests/semantic/test_reanchor_llvm_offsets.py`), translates only code reachable from entry (a branch into data is rejected), and turns `s_getpc_b64` into code base + next-instruction offset. **The runtime uploads each shader's FSSM blob into the heap and passes that VA as the code base.** Re-anchoring compares bytes exactly, except that VOP3P `op_sel_hi[2]` (bit 14) is ignored on two-source packed ops: the compiler stores 0 there, and LLVM prints its default of 1. Unused VOP3/VOP3P `SRC1` (bits 49:41) and `SRC2` (bits 58:50) fields are also ignored when stored as 0 and printed as `0x80`: LLVM 23 re-encodes a source it doesn't read as inline constant 0 (one-source `v_rcp`/`v_log`/`v_sqrt_f32_e64`, two-source `v_sub_f32_e64`/`v_cmp_*_e64`/`v_mul_lo_u32`/`v_pk_mul_f16`). Both checks for clean listings and re-anchoring use the parsed operand count to apply this exception only to unused sources. A used source encoded as 0 reads `s0` and is never treated as inline zero. `tests/semantic/test_printed_encoding.py` checks used `SRC1`/`SRC2` and an unused field with synthetic listings. Confirmed by a count over the corpus with LLVM 23.1.5: without it, 1,471 of the 1,473 shaders with embedded data are rejected ("reachable instruction with normalized encoding"); with it, all 1,473 translate and pass `spirv-val`. Runs with LLVM 21 already translated all of them, so older LLVMs presumably print the stored 0 (not re-checked). Data words that decode with ignored fields set are printed re-encoded (e.g. `0xbe8d2242` as `s_rfe_b64` `0xbe802242`), so they can never match. Since the decoder consumed the same length, they are anchored in sequence and marked. A shader that can *reach* a marked word is rejected; none of the corpus does. All 155 now translate. A reachable instruction that falls through into words llvm-mc skipped (it printed no instruction there) is rejected too, as `fall-through into undecodable words`: until SHADER-813 the reachable path ended there without a word, so everything after the gap (exports, stores) was dropped from a module that still passed `spirv-val`. No VS/PS of the corpus has such a gap on a reachable path; in the FidelityFX FSPX programs it is the `v_dot4_i32_i8 ... op_sel` words LLVM 23 cannot decode (`docs/fspx.md`), so those programs are now refused instead of translated without their stores, until those words are decoded (#2038, #2323). `tests/test_rdna2spirv_decode.py` (`test_fall_through_into_undecodable_words_is_refused`). The exact re-anchoring path tries the same repair as the forward search for a `v_dot4_i32_i8` with an inline-integer S1 whose stored op_sel_hi (5) llvm-mc prints as the default (7), `restore_dot4_inline_sel`, before it marks the word: without it such a program is refused as "reachable instruction with normalized encoding" whenever its listing also reports rejected words. Counted on the 29 FidelityFX DLL programs (1.0.2.1, LLVM 21.1.8): 22 translate without it, 24 with it, all 24 pass `spirv-val`; `tests/semantic/test_reanchor_dot4_inline_sel.py`. | |
| 300 | | VOP3 opcode 0x140 | LLVM disassembly of the synthetic words in `tests/test_rdna2_decode.py` gives `v_mad_legacy_f32` on gfx1010 through gfx1013 and `v_fma_legacy_f32` on gfx1030. The direct decoder defaults to gfx1013, matching the disassembler CLI. Checked by the unit test `test_vop3_legacy_mad_fma_target` in `tests/test_rdna2_decode.py`, which decodes the same words directly and runs the Python disassembler backend for gfx1013 and gfx1030. | | 315 | | VOP3 opcode 0x140 | LLVM disassembly of the synthetic words in `tests/test_rdna2_decode.py` gives `v_mad_legacy_f32` on gfx1010 through gfx1013 and `v_fma_legacy_f32` on gfx1030. The direct decoder defaults to gfx1013, matching the disassembler CLI. Checked by the unit test `test_vop3_legacy_mad_fma_target` in `tests/test_rdna2_decode.py`, which decodes the same words directly and runs the Python disassembler backend for gfx1013 and gfx1030. | |
| 301 | | Printed encodings | A listing is LLVM's text for what it decoded, not the bytes it read, so the translator checks the two against each other: the re-anchoring above for listings with undecodable words, and, for every other listing whose header names its code range and whose blob sits next to it (`fssm/`, or `fspx/` for FSPX), each instruction's printed encoding against the bytes at its offset, with the same exceptions (`same_encoding`). A difference is `Unsupported`, naming the instruction, its offset and both byte strings, instead of a translation of the field as 0. The case that prompted it: llvm-mc's gfx1013 decoder (LLVM 21.1.8) drops the VOP3 `op_sel` bits (word 0, bits 14:11) of a 16-bit VOPC compare: `0a 08 a9 d4 01 05 02 00` disassembles as `v_cmp_lt_u16_e64 s10, v1, v2` and re-encodes with the bits cleared (its assembler rejects `op_sel` on VOPC for gfx1013 and gfx1030 alike). Counted over the 1.0.2.1 corpus: the 25,030 clean listings hold 30,335,381 instructions, and none differs from its bytes beyond those exceptions (754); the 166 16-bit VOPC compares (154 shaders, all `f16`) have `op_sel` clear. Hand-written listings, `run_gpu_tests.py`'s `code 0x0..0x0 (synthetic)` listings and a blob that doesn't hold the listing's code range (the tests' header-only FSSM) are not checked. `tests/semantic/test_printed_encoding.py` (a dropped VOPC `op_sel`, a later instruction, the SRC2 exception, and the unchecked cases). One difference is repaired instead of refused: a `v_fma_mix*` literal that llvm-mc prints cut to its low 16 bits (and re-encodes with a zero high half). llvm-mc 23.1.5 prints some of these literals in full as `lit(V)` (an f32 source, or a low half that is an inline constant; LLVM 21 printed the inline constant and dropped the literal word) and still re-encodes only the low half: `tools/shader_ir.py` reads `lit(V)` as V, and the same repair applies (5,733 such operands in the pipeline library, [shader_library.md](shader_library.md)). When the 8 instruction bytes match (`same_encoding` with all three sources counted as used, so a live `s0` can't pass as an inline 0) and the printed literal is the stored one's low half, every source the bytes encode as the literal (SRC field `0xff`) takes the stored 32 bits, so a source with `op_sel_hi` and `op_sel` set reads the high half instead of +0.0. Seen in one program of the FidelityFX DLL's `FSPX` code ([fspx.md](fspx.md)): src0 the low half, src2 the high half; the game's clean listings have no such difference (the count above). That the hardware gives op_sel's high half of the literal to that source is not measured; it is what Mesa's ACO compiler relies on (public: `optimize_constants()` in `src/amd/compiler/aco_optimizer.cpp`, Mesa `main` at `bb986060`, packs two constants as the two f16 halves of one literal, read through `v_fma_mix`'s `op_sel_hi` with the second source extracting the high half), and what the console compiler emitted here. `tools/fma_mix_literal_probe.py --oracle hw` measures it on an AMD GPU (the instruction's exact bytes through `tools/hw_oracle`; not run on one yet). `tests/semantic/test_fma_mix_literal.py` (the value through the interpreter, the re-anchoring path, an inline constant with the literal's printed value left alone, and the refused cases, a live source printed as inline 0 among them). A second shape is repaired too (`mix_inline_literal`): LLVM 21's form above. llvm-mc 21.1.8 (`-mcpu=gfx1013`) prints a `v_fma_mix*` literal whose low 16 bits are the f16 value of an inline constant as that constant and re-encodes the instruction in **8** bytes: every SRC field that held `0xff` holds the inline code, and the literal word is gone (`0x3f800000`, 1.0 as an f32 source, prints as `0`; `0x3c003800` as `0.5`, losing the high half 1.0). Swept with llvm-mc 21.1.8 over all 65,536 low halves under three high halves: exactly 90 low halves print this way (0..64, -1..-16, ±0.5, ±1.0, ±2.0, ±4.0, 1/(2π) as f16: `MIX_INLINE_F16`), whatever the high half; llvm-mc 23.1.6 prints all of them as `lit(V)`. The printed 8 bytes are 4 short of what the decoder read, so the later offsets of a clean listing were 4 low and its first such instruction was refused as a dropped field (one FSPX program, `tupacfan04`'s count in #8683). When every differing SRC field is `0xff` in the blob and the inline code of the stored literal's low half in the print, and the rest of the 8 bytes match exactly (`same_encoding`, all three sources live), each such source reads the stored 32 bits with the stored neg and abs (`NEG_HI`) bits, the instruction takes the 12 stored bytes, and the following offsets move up by 4 (also on the re-anchoring path). Any other difference stays `Unsupported`. CPU-checked by `tests/semantic/test_fma_mix_literal.py` (`FmaMixInlineLiteralTest`: an f32 source, two f16 halves, neg and abs, all 90 codes, both listing paths, the refused cases). | | 316 | | Printed encodings | A listing is LLVM's text for what it decoded, not the bytes it read, so the translator checks the two against each other: the re-anchoring above for listings with undecodable words, and, for every other listing whose header names its code range and whose blob sits next to it (`fssm/`, or `fspx/` for FSPX), each instruction's printed encoding against the bytes at its offset, with the same exceptions (`same_encoding`). A difference is `Unsupported`, naming the instruction, its offset and both byte strings, instead of a translation of the field as 0. The case that prompted it: llvm-mc's gfx1013 decoder (LLVM 21.1.8) drops the VOP3 `op_sel` bits (word 0, bits 14:11) of a 16-bit VOPC compare: `0a 08 a9 d4 01 05 02 00` disassembles as `v_cmp_lt_u16_e64 s10, v1, v2` and re-encodes with the bits cleared (its assembler rejects `op_sel` on VOPC for gfx1013 and gfx1030 alike). Counted over the 1.0.2.1 corpus: the 25,030 clean listings hold 30,335,381 instructions, and none differs from its bytes beyond those exceptions (754); the 166 16-bit VOPC compares (154 shaders, all `f16`) have `op_sel` clear. Hand-written listings, `run_gpu_tests.py`'s `code 0x0..0x0 (synthetic)` listings and a blob that doesn't hold the listing's code range (the tests' header-only FSSM) are not checked. `tests/semantic/test_printed_encoding.py` (a dropped VOPC `op_sel`, a later instruction, the SRC2 exception, and the unchecked cases). One difference is repaired instead of refused: a `v_fma_mix*` literal that llvm-mc prints cut to its low 16 bits (and re-encodes with a zero high half). llvm-mc 23.1.5 prints some of these literals in full as `lit(V)` (an f32 source, or a low half that is an inline constant; LLVM 21 printed the inline constant and dropped the literal word) and still re-encodes only the low half: `tools/shader_ir.py` reads `lit(V)` as V, and the same repair applies (5,733 such operands in the pipeline library, [shader_library.md](shader_library.md)). When the 8 instruction bytes match (`same_encoding` with all three sources counted as used, so a live `s0` can't pass as an inline 0) and the printed literal is the stored one's low half, every source the bytes encode as the literal (SRC field `0xff`) takes the stored 32 bits, so a source with `op_sel_hi` and `op_sel` set reads the high half instead of +0.0. Seen in one program of the FidelityFX DLL's `FSPX` code ([fspx.md](fspx.md)): src0 the low half, src2 the high half; the game's clean listings have no such difference (the count above). That the hardware gives op_sel's high half of the literal to that source is not measured; it is what Mesa's ACO compiler relies on (public: `optimize_constants()` in `src/amd/compiler/aco_optimizer.cpp`, Mesa `main` at `bb986060`, packs two constants as the two f16 halves of one literal, read through `v_fma_mix`'s `op_sel_hi` with the second source extracting the high half), and what the console compiler emitted here. `tools/fma_mix_literal_probe.py --oracle hw` measures it on an AMD GPU (the instruction's exact bytes through `tools/hw_oracle`; not run on one yet). `tests/semantic/test_fma_mix_literal.py` (the value through the interpreter, the re-anchoring path, an inline constant with the literal's printed value left alone, and the refused cases, a live source printed as inline 0 among them). A second shape is repaired too (`mix_inline_literal`): LLVM 21's form above. llvm-mc 21.1.8 (`-mcpu=gfx1013`) prints a `v_fma_mix*` literal whose low 16 bits are the f16 value of an inline constant as that constant and re-encodes the instruction in **8** bytes: every SRC field that held `0xff` holds the inline code, and the literal word is gone (`0x3f800000`, 1.0 as an f32 source, prints as `0`; `0x3c003800` as `0.5`, losing the high half 1.0). Swept with llvm-mc 21.1.8 over all 65,536 low halves under three high halves: exactly 90 low halves print this way (0..64, -1..-16, ±0.5, ±1.0, ±2.0, ±4.0, 1/(2π) as f16: `MIX_INLINE_F16`), whatever the high half; llvm-mc 23.1.6 prints all of them as `lit(V)`. The printed 8 bytes are 4 short of what the decoder read, so the later offsets of a clean listing were 4 low and its first such instruction was refused as a dropped field (one FSPX program, `tupacfan04`'s count in #8683). When every differing SRC field is `0xff` in the blob and the inline code of the stored literal's low half in the print, and the rest of the 8 bytes match exactly (`same_encoding`, all three sources live), each such source reads the stored 32 bits with the stored neg and abs (`NEG_HI`) bits, the instruction takes the 12 stored bytes, and the following offsets move up by 4 (also on the re-anchoring path). Any other difference stays `Unsupported`. CPU-checked by `tests/semantic/test_fma_mix_literal.py` (`FmaMixInlineLiteralTest`: an f32 source, two f16 halves, neg and abs, all 90 codes, both listing paths, the refused cases). | |
| 302 | | Global memory | `global_load/store_dword*`: address = (64-bit SGPR base + zero-extended 32-bit VGPR offset, or a 64-bit VGPR address) + the instruction offset, translated through the heap base. Inactive lanes don't access memory, and loads merge their previous values with OpPhi. The offset is the **signed 12-bit** byte value as llvm-mc prints it, -2048..2047 (`offset:-4` is the field 0xffc; llvm-mc rejects `offset:0xffc` and disassembles that field as `offset:-4`, so no repo path delivers the raw unsigned field), added to the address as is; a tool that printed the raw field (`0xffc`) would mean the same offset, and a value outside 12 bits is rejected. Measured on an AMD Radeon RX 6800 (gfx1030) running `global_load_dword` as a raw compute kernel, wave32 and wave64 alike, with the dword at byte n = 0x10000000+n and the pointer at 0x1000: offset 0 reads 0x10001000, -4 0x10000ffc, -2048 0x10000800, 2044 0x100017fc, -1024 0x10000c00. The translator used to subtract 0x1000 from an already negative value (4096 bytes too low). Checked by `tests/semantic/test_global_mem_offset.py` (both addressing modes, dword/x2/x4, byte/short loads and stores at -4, -2048, 2047 and 0) and the GPU test `runtime/test/shaders/cs_global_neg_offset.asm` (`vk_compute_test ... 40 dump`). | | 317 | | Global memory | `global_load/store_dword*`: address = (64-bit SGPR base + zero-extended 32-bit VGPR offset, or a 64-bit VGPR address) + the instruction offset, translated through the heap base. Inactive lanes don't access memory, and loads merge their previous values with OpPhi. The offset is the **signed 12-bit** byte value as llvm-mc prints it, -2048..2047 (`offset:-4` is the field 0xffc; llvm-mc rejects `offset:0xffc` and disassembles that field as `offset:-4`, so no repo path delivers the raw unsigned field), added to the address as is; a tool that printed the raw field (`0xffc`) would mean the same offset, and a value outside 12 bits is rejected. Measured on an AMD Radeon RX 6800 (gfx1030) running `global_load_dword` as a raw compute kernel, wave32 and wave64 alike, with the dword at byte n = 0x10000000+n and the pointer at 0x1000: offset 0 reads 0x10001000, -4 0x10000ffc, -2048 0x10000800, 2044 0x100017fc, -1024 0x10000c00. The translator used to subtract 0x1000 from an already negative value (4096 bytes too low). Checked by `tests/semantic/test_global_mem_offset.py` (both addressing modes, dword/x2/x4, byte/short loads and stores at -4, -2048, 2047 and 0) and the GPU test `runtime/test/shaders/cs_global_neg_offset.asm` (`vk_compute_test ... 40 dump`). | |
| @@ -306,12 +321,13 @@ How the generated SPIR-V expects the runtime to work: | |||
| 306 | | 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. | | 321 | | 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. | |
| 307 | | 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). | | 322 | | 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). | |
| 308 | | 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`. | | 323 | | 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`. | |
| 309 | | 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). | | 324 | | 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). | |
| 310 | | 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). | | 325 | | 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). | |
| 311 | | 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. | | 326 | | 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. | |
| 327 | | 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. | | ||
| 312 | | 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. | | 328 | | 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. | |
| 313 | | 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). | | 329 | | 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). | |
| 314 | | Descriptor hash table | `uint mask; entries[mask+1] of 10 uints: key[0..7], index, pad`. 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). | | 330 | | 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). | |
| 315 | | 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 per output component (`%fmt_dec_c0`…`%fmt_dec_c3`) 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). Now the four functions hold 565 instructions and no branch, and that module is 56,763 bytes. The decode functions take the format code and the element's four dwords as a `v4uint`, so their 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. 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-per-component 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. 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. | | 331 | | 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 per output component (`%fmt_dec_c0`…`%fmt_dec_c3`) 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). Now the four functions hold 565 instructions and no branch, and that module is 56,763 bytes. The decode functions take the format code and the element's four dwords as a `v4uint`, so their 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. 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-per-component 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. 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. | |
| 316 | | 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) | | 332 | | 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) | |
| 317 | | `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`. | | 333 | | `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`. | |
| @@ -394,6 +410,7 @@ How the generated SPIR-V expects the runtime to work: | |||
| 394 | | Denormal flush and special results in `v_rcp_f32`, `v_rsq_f32`, `v_sqrt_f32`, `v_log_f32`, `v_exp_f32`, `v_rcp_iflag_f32` | Measured on an RX 6800 (gfx1030, not the console's gfx1013) with raw kernels in both wave sizes and all four IEEE/DX10_CLAMP combinations: all six read a denormal input as a zero of its sign and flush a denormal result, even with MODE's denormal field set to keep them. `v_rcp_f32(±0)` = ±inf, `v_rsq_f32(-0)` = -inf, `v_sqrt_f32(-0)` = -0, `v_log_f32(±0)` = -inf, `v_rcp_f32(FLT_MAX)` = +0, `v_exp_f32(-127)` = +0, `v_exp_f32(128)` = +inf, and every invalid result (`v_sqrt_f32`/`v_rsq_f32`/`v_log_f32` of a negative, …) is `0xffc00000`. Each is within 1 ulp of correctly rounded on the values tried, and `v_rcp_iflag_f32` is bit-identical to `v_rcp_f32`. **Not modelled yet:** the translator leaves all six on Vulkan's default denormal handling, and the ±0 and negative inputs above stay undefined in the emitted SPIR-V (`OpFDiv` by zero, `Sqrt`/`Log2` of a negative), as listed in the multiply-add and output modifiers row; the `clamp`/`omod` bits on `v_cvt_f32_*` and `v_rcp_iflag_f32` are modelled there. Source: [@shelbykb2's hardware words](https://github.com/ItsNotRexed/Leonida/issues/634#issuecomment-7074348963), not the ISA text. The corpus only ever writes MODE's FP_ROUND field and carries `mul:2`/`mul:4`/`div:2` on 102,365 float instructions (a compiler does not emit one that is ignored), so the inferred f32 state, IEEE off with denormals flushed, is the one to model. Corpus count (`tools/shader_profile.py`, 26,503 shaders; the shader count of each op deduplicates its `_e32`/`_e64` forms): `v_rcp_f32` 17,393 shaders / 424,863 occurrences, `v_rsq_f32` 17,221 / 269,310, `v_sqrt_f32` 14,511 / 201,422, `v_log_f32` 8,454 / 90,199, `v_exp_f32` 8,603 / 148,846, `v_rcp_iflag_f32` 7,395 / 34,852; 20,193 shaders (76.2%) use at least one, 1,169,492 occurrences (2.6% of the corpus's 44,406,870 instructions). | | 410 | | Denormal flush and special results in `v_rcp_f32`, `v_rsq_f32`, `v_sqrt_f32`, `v_log_f32`, `v_exp_f32`, `v_rcp_iflag_f32` | Measured on an RX 6800 (gfx1030, not the console's gfx1013) with raw kernels in both wave sizes and all four IEEE/DX10_CLAMP combinations: all six read a denormal input as a zero of its sign and flush a denormal result, even with MODE's denormal field set to keep them. `v_rcp_f32(±0)` = ±inf, `v_rsq_f32(-0)` = -inf, `v_sqrt_f32(-0)` = -0, `v_log_f32(±0)` = -inf, `v_rcp_f32(FLT_MAX)` = +0, `v_exp_f32(-127)` = +0, `v_exp_f32(128)` = +inf, and every invalid result (`v_sqrt_f32`/`v_rsq_f32`/`v_log_f32` of a negative, …) is `0xffc00000`. Each is within 1 ulp of correctly rounded on the values tried, and `v_rcp_iflag_f32` is bit-identical to `v_rcp_f32`. **Not modelled yet:** the translator leaves all six on Vulkan's default denormal handling, and the ±0 and negative inputs above stay undefined in the emitted SPIR-V (`OpFDiv` by zero, `Sqrt`/`Log2` of a negative), as listed in the multiply-add and output modifiers row; the `clamp`/`omod` bits on `v_cvt_f32_*` and `v_rcp_iflag_f32` are modelled there. Source: [@shelbykb2's hardware words](https://github.com/ItsNotRexed/Leonida/issues/634#issuecomment-7074348963), not the ISA text. The corpus only ever writes MODE's FP_ROUND field and carries `mul:2`/`mul:4`/`div:2` on 102,365 float instructions (a compiler does not emit one that is ignored), so the inferred f32 state, IEEE off with denormals flushed, is the one to model. Corpus count (`tools/shader_profile.py`, 26,503 shaders; the shader count of each op deduplicates its `_e32`/`_e64` forms): `v_rcp_f32` 17,393 shaders / 424,863 occurrences, `v_rsq_f32` 17,221 / 269,310, `v_sqrt_f32` 14,511 / 201,422, `v_log_f32` 8,454 / 90,199, `v_exp_f32` 8,603 / 148,846, `v_rcp_iflag_f32` 7,395 / 34,852; 20,193 shaders (76.2%) use at least one, 1,169,492 occurrences (2.6% of the corpus's 44,406,870 instructions). | |
| 395 | | f16 transcendentals (`v_exp_f16`, `v_log_f16`, `v_rcp_f16`, `v_rsq_f16`, `v_sqrt_f16`, `v_sin_f16`, `v_cos_f16`) | Measured on an RX 6700 XT (gfx1031, not the console's gfx1013) with `tools/f16_trans_sweep.py`: all 65,536 inputs of each op, wave32 and wave64 (identical on every input), five MODEs (FUZZ-29). With f16 denormals kept (`denorm_mode_16_64 = 3`, the assembler default and what the translator assumes), `v_exp/log/rcp/rsq/sqrt_f16` are **correctly rounded on every input that is not a NaN** (0 ulp). `v_sin/v_cos_f16` take turns and reduce them exactly over the whole f16 range (no ±256 limit): compared with sin/cos(2πx), every result for \|x\| > 1 is bit-exact, and for \|x\| ≤ 1 only 14 (sin) and 4 (cos) of 30,722 are 1 ulp off. So the translator's rule (widen to f32, the GLSL.std.450 function, round to nearest even back to f16) matches the hardware as far as the driver's f32 function is accurate. For sin/cos that holds only once the angle is reduced in turns first (#594): with the f32 product 6.2831855 · x, 16,366 sin and 2,036 cos inputs are more than 1 ulp off, up to 9,944 ulp (sin of 64,640 turns: 0.0267 instead of 0). With `denorm_mode_16_64 = 0`, a denormal operand reads as a zero of its sign, and a denormal result is written as a zero of its sign. That differs from the f32 ops in the row above, which flush in both modes. The f16 field of FP_ROUND is ignored: round toward zero gives the same words as round to nearest on every input. IEEE changes only signalling NaNs. With IEEE off they pass through unchanged; with IEEE on they are quieted (bit 9 set). Payload and sign are kept either way, and quiet NaNs pass unchanged in every mode. Where SPIR-V leaves the result undefined, the hardware gives: log(±0) = -inf, rcp(±0) = ±inf, rsq(+0) = +inf, rsq(-0) = -inf, sqrt(-0) = -0, and `0xfe00` for log/rsq/sqrt of a negative (-inf included) and for sin/cos(±inf). `v_exp_f16`/`v_log_f16` give the same counts on gfx1036 (RDNA2, AMD Windows driver; SHADER-135). Since 2026-11-22 the translator selects those hardware words for `v_rcp_f16`, `v_rsq_f16` and `v_sqrt_f16` itself (the operand is replaced by 1.0 for the f32 `OpFDiv`/`InverseSqrt`/`Sqrt`, which SPIR-V leaves undefined at 0 or below 0) and `0xfe00` is the negative quiet NaN; checked bit for bit through the interpreter by `tests/semantic/test_valu_rcp_f16.py`, `test_valu_rsq_f16.py` and `test_valu_sqrt_f16.py` against exactly rounded references. The undefined cases of `v_exp_f16`/`v_log_f16`/`v_sin_f16`/`v_cos_f16` are still left to the driver. **Not modelled yet:** `Gen.f16_bits` quiets every NaN (the hardware keeps a signalling NaN with IEEE off), and the undefined cases above are left to the driver. | | 411 | | f16 transcendentals (`v_exp_f16`, `v_log_f16`, `v_rcp_f16`, `v_rsq_f16`, `v_sqrt_f16`, `v_sin_f16`, `v_cos_f16`) | Measured on an RX 6700 XT (gfx1031, not the console's gfx1013) with `tools/f16_trans_sweep.py`: all 65,536 inputs of each op, wave32 and wave64 (identical on every input), five MODEs (FUZZ-29). With f16 denormals kept (`denorm_mode_16_64 = 3`, the assembler default and what the translator assumes), `v_exp/log/rcp/rsq/sqrt_f16` are **correctly rounded on every input that is not a NaN** (0 ulp). `v_sin/v_cos_f16` take turns and reduce them exactly over the whole f16 range (no ±256 limit): compared with sin/cos(2πx), every result for \|x\| > 1 is bit-exact, and for \|x\| ≤ 1 only 14 (sin) and 4 (cos) of 30,722 are 1 ulp off. So the translator's rule (widen to f32, the GLSL.std.450 function, round to nearest even back to f16) matches the hardware as far as the driver's f32 function is accurate. For sin/cos that holds only once the angle is reduced in turns first (#594): with the f32 product 6.2831855 · x, 16,366 sin and 2,036 cos inputs are more than 1 ulp off, up to 9,944 ulp (sin of 64,640 turns: 0.0267 instead of 0). With `denorm_mode_16_64 = 0`, a denormal operand reads as a zero of its sign, and a denormal result is written as a zero of its sign. That differs from the f32 ops in the row above, which flush in both modes. The f16 field of FP_ROUND is ignored: round toward zero gives the same words as round to nearest on every input. IEEE changes only signalling NaNs. With IEEE off they pass through unchanged; with IEEE on they are quieted (bit 9 set). Payload and sign are kept either way, and quiet NaNs pass unchanged in every mode. Where SPIR-V leaves the result undefined, the hardware gives: log(±0) = -inf, rcp(±0) = ±inf, rsq(+0) = +inf, rsq(-0) = -inf, sqrt(-0) = -0, and `0xfe00` for log/rsq/sqrt of a negative (-inf included) and for sin/cos(±inf). `v_exp_f16`/`v_log_f16` give the same counts on gfx1036 (RDNA2, AMD Windows driver; SHADER-135). Since 2026-11-22 the translator selects those hardware words for `v_rcp_f16`, `v_rsq_f16` and `v_sqrt_f16` itself (the operand is replaced by 1.0 for the f32 `OpFDiv`/`InverseSqrt`/`Sqrt`, which SPIR-V leaves undefined at 0 or below 0) and `0xfe00` is the negative quiet NaN; checked bit for bit through the interpreter by `tests/semantic/test_valu_rcp_f16.py`, `test_valu_rsq_f16.py` and `test_valu_sqrt_f16.py` against exactly rounded references. The undefined cases of `v_exp_f16`/`v_log_f16`/`v_sin_f16`/`v_cos_f16` are still left to the driver. **Not modelled yet:** `Gen.f16_bits` quiets every NaN (the hardware keeps a signalling NaN with IEEE off), and the undefined cases above are left to the driver. | |
| 396 | | f64 literal sources | For `v_cvt_f32_f64` and either source of `v_add_f64`, a literal dword supplies bits 63:32 and bits 31:0 are zero. For `v_cvt_f32_f64`, `v_rcp_f64`, `v_rsq_f64`, `v_sqrt_f64`, `v_frexp_mant_f64`, `v_frexp_exp_i32_f64` and either source of `v_add_f64`, a literal dword supplies bits 63:32 and bits 31:0 are zero. Inline integers are sign-extended and inline floats use their binary64 value. For example, gfx1030 `llvm-mc` encodes 1.5 as the literal word `0x3ff80000`. The synthetic `tests/semantic/fixtures/f64_literals.asm` checks both source words in the translated SPIR-V, including the distinction between the printed literal `0x1` and inline `1`. [LLVM AMDGPU operand conversions](https://releases.llvm.org/15.0.0/docs/AMDGPUOperandSyntax.html#integer-literals) In the synthetic `unary_f64_literals.asm`, LLVM gfx1030 encodes the five unary literal sources in trailing dwords. The regression checks the emitted high and low operand words for reciprocal, reciprocal square root and square root. It executes the integer-only frexp paths: for 6.0 the mantissa words are (0, 0x3fe80000) and the exponent is 3. The full fixture passes Vulkan 1.2 validation; the semantic interpreter cannot execute its Float64 instructions. The rule keys on the literal's printed width, not only its value: LLVM pads nothing, so a value that fits one literal dword prints in at most 8 hex digits, and a spelling of more than 8 is the whole binary64 constant (the full-width form `tools/f64_diff.py` writes: `0x0000000012345678` is the low word `0x12345678` and a zero high word, while `0x12345678` stays the high word). gfx1013 `llvm-mc` refuses a literal wider than 32 bits for these ops ("invalid operand"), so a listing from the game carries only the one-dword form and its words do not change. The wider form used to be refused by the four rounding ops; they now read the whole constant, which is what the differential check's generated programs needed. `tests/semantic/test_f64_literal_whole.py` checks those emitted words for `v_sqrt_f64`, `v_rsq_f64`, `v_rcp_f64`, the four rounding ops and the frexp exponent path, next to the one-dword, padded-width and inline-integer controls; `tests/test_f64_diff.py` checks that the CPU reference reads a literal the same way; `tools/f64_diff.py`'s CPU reference judged the whole-literal `v_add_f64`/`v_rsq_f64`/`v_sqrt_f64` programs as mismatches before the change. | | 412 | | f64 literal sources | For `v_cvt_f32_f64` and either source of `v_add_f64`, a literal dword supplies bits 63:32 and bits 31:0 are zero. For `v_cvt_f32_f64`, `v_rcp_f64`, `v_rsq_f64`, `v_sqrt_f64`, `v_frexp_mant_f64`, `v_frexp_exp_i32_f64` and either source of `v_add_f64`, a literal dword supplies bits 63:32 and bits 31:0 are zero. Inline integers are sign-extended and inline floats use their binary64 value. For example, gfx1030 `llvm-mc` encodes 1.5 as the literal word `0x3ff80000`. The synthetic `tests/semantic/fixtures/f64_literals.asm` checks both source words in the translated SPIR-V, including the distinction between the printed literal `0x1` and inline `1`. [LLVM AMDGPU operand conversions](https://releases.llvm.org/15.0.0/docs/AMDGPUOperandSyntax.html#integer-literals) In the synthetic `unary_f64_literals.asm`, LLVM gfx1030 encodes the five unary literal sources in trailing dwords. The regression checks the emitted high and low operand words for reciprocal, reciprocal square root and square root. It executes the integer-only frexp paths: for 6.0 the mantissa words are (0, 0x3fe80000) and the exponent is 3. The full fixture passes Vulkan 1.2 validation; the semantic interpreter cannot execute its Float64 instructions. The rule keys on the literal's printed width, not only its value: LLVM pads nothing, so a value that fits one literal dword prints in at most 8 hex digits, and a spelling of more than 8 is the whole binary64 constant (the full-width form `tools/f64_diff.py` writes: `0x0000000012345678` is the low word `0x12345678` and a zero high word, while `0x12345678` stays the high word). gfx1013 `llvm-mc` refuses a literal wider than 32 bits for these ops ("invalid operand"), so a listing from the game carries only the one-dword form and its words do not change. The wider form used to be refused by the four rounding ops; they now read the whole constant, which is what the differential check's generated programs needed. `tests/semantic/test_f64_literal_whole.py` checks those emitted words for `v_sqrt_f64`, `v_rsq_f64`, `v_rcp_f64`, the four rounding ops and the frexp exponent path, next to the one-dword, padded-width and inline-integer controls; `tests/test_f64_diff.py` checks that the CPU reference reads a literal the same way; `tools/f64_diff.py`'s CPU reference judged the whole-literal `v_add_f64`/`v_rsq_f64`/`v_sqrt_f64` programs as mismatches before the change. | |
| 413 | | 32-bit literal source of a signed 64-bit vector op (`v_cmp(x)_*_i64`, `v_ashrrev_i64` S1, `v_mad_i64_i32` S2) | A VALU literal is one dword and llvm-mc prints `-100` as `0xffffff9c` (both encode to the same bytes on gfx1030). In an i64 operand that dword is sign-extended to 64 bits (`{-1, num.i32}`), in a u64/b64 operand zero-extended (`{0, num.u32}`) ([LLVM AMDGPU operand syntax, Conversion of Integer Values](https://releases.llvm.org/15.0.0/docs/AMDGPUOperandSyntax.html#integer-literals); `Gen.valu_imm_i64`). So `v_cmp_lt_i64 vcc_lo, 5, 0xffffff9c` = 0, `v_ashrrev_i64 v[10:11], 4, 0xffffff9c` = 0xFFFFFFFF_FFFFFFF9 and `v_mad_i64_i32 v[10:11], vcc_lo, 1, 1, 0xffffff9c` = -99, the same as the decimal spelling and the explicit pair. `v_cmp_*_u64`, `v_lshlrev_b64`, `v_lshrrev_b64` and `v_mad_u64_u32` S2 still zero-extend a literal, a positive literal (`0x7fffffff`) stays positive, and the inline constants (-16..64) were already full-width. f64 literals keep their own rule (row above). The vector half of the scalar rule for `s_ashr_i64`, `s_bfe_i64` and `s_flbit_i32_i64` (#978). Confirmed by `tests/semantic/test_valu_signed_literal64.py` (CPU, the three spellings agree; 5 of its 8 tests fail on the previous translator, which zero-extended the printed literal) and by the llvm-mc gfx1030 encodings of `-100` and `0xffffff9c`. Not measured on hardware. | | ||
| 397 | | `v_cvt_f32_f64` output modifiers | Convert to f32, apply `mul:2`, `mul:4`, or `div:2` if present, then apply `clamp` to [0, 1] if requested. [LLVM GFX10 assembler tests](https://github.com/llvm/llvm-project/blob/main/llvm/test/MC/AMDGPU/gfx10_asm_vop1.s#L3044-L3054) confirm the modifier encodings. `tests/test_f64_conversion.py` checks the resulting SPIR-V data flow. | | 414 | | `v_cvt_f32_f64` output modifiers | Convert to f32, apply `mul:2`, `mul:4`, or `div:2` if present, then apply `clamp` to [0, 1] if requested. [LLVM GFX10 assembler tests](https://github.com/llvm/llvm-project/blob/main/llvm/test/MC/AMDGPU/gfx10_asm_vop1.s#L3044-L3054) confirm the modifier encodings. `tests/test_f64_conversion.py` checks the resulting SPIR-V data flow. | |
| 398 | | 32-bit integers to binary64 | `v_cvt_f64_i32` sign-extends the input value and `v_cvt_f64_u32` treats it as unsigned. Every 32-bit integer is exactly representable in binary64. The low word goes in the first destination VGPR. **The output scaling is gated by `MODE`, measured by @fiestorra**: on a gfx1036 iGPU (Radeon(TM) Graphics, drivers `31.0.24002.92` and `32.0.21045.29003` (the same counts on both), raw ISA through `tools/hw_oracle`, `tools/f64_omod_probe.py`, 6 inputs x 5 modifier forms x 5 MODEs, wave32 and wave64 identical) `mul:2`/`mul:4`/`div:2` scale the binary64 result only under `IEEE=0` with `denorm_mode_16_64=0`; under `denorm_mode_16_64=3`, which is what the translator assumes, and under `IEEE=1` they are ignored, while `clamp` applies in every MODE — so only `clamp` reaches `dst_f64` for these two ops, as `v_ldexp_f64` already does. For input `0x80000001`, SPIRV-Tools constant folding reproduced both words of each result in the synthetic `ps_int32_to_f64.s` fixture. [AMD RDNA 2 ISA, VOP1 conversions](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf) | | 415 | | 32-bit integers to binary64 | `v_cvt_f64_i32` sign-extends the input value and `v_cvt_f64_u32` treats it as unsigned. Every 32-bit integer is exactly representable in binary64. The low word goes in the first destination VGPR. **The output scaling is gated by `MODE`, measured by @fiestorra**: on a gfx1036 iGPU (Radeon(TM) Graphics, drivers `31.0.24002.92` and `32.0.21045.29003` (the same counts on both), raw ISA through `tools/hw_oracle`, `tools/f64_omod_probe.py`, 6 inputs x 5 modifier forms x 5 MODEs, wave32 and wave64 identical) `mul:2`/`mul:4`/`div:2` scale the binary64 result only under `IEEE=0` with `denorm_mode_16_64=0`; under `denorm_mode_16_64=3`, which is what the translator assumes, and under `IEEE=1` they are ignored, while `clamp` applies in every MODE — so only `clamp` reaches `dst_f64` for these two ops, as `v_ldexp_f64` already does. For input `0x80000001`, SPIRV-Tools constant folding reproduced both words of each result in the synthetic `ps_int32_to_f64.s` fixture. [AMD RDNA 2 ISA, VOP1 conversions](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf) | |
| 399 | | `v_add_f64` output modifiers | The double sum is scaled by `mul:2`, `mul:4` or `div:2` if present, then clamped to [0, 1] if `clamp` is set, as for f32 (`clamp_mods_f64`, GLSL.std.450 `FClamp` on the double, so a NaN result and the sign of a -0 result are left to the driver, also as for f32). **Until 2026-11-22 both were ignored.** Source: LLVM AMDGPU defines it as `VOP3Inst<"v_add_f64", VOP3_Profile<VOP_F64_F64_F64>>` (VOP3Instructions.td), and `VOPProfile` sets `HasClamp` (f64 is a modifier type) and `HasOMod` (floating-point destination) (SIInstrInfo.td). It is the only f64 arithmetic the translator handles; `v_cvt_f32_f64` has the row above. `tests/test_f64_output_modifiers.py` checks the SPIR-V data flow; `runtime/test/shaders/ps_f64_mods.asm` is the GPU test (needs `shaderFloat64`, which `vk_harness` now enables when the fragment shader declares `Float64`), passed on an NVIDIA RTX 6000 Ada (driver 615.71.09, Linux; 4096/4096 pixels exact, and the `main` translator gives the predicted old words). | | 416 | | `v_add_f64` output modifiers | The double sum is scaled by `mul:2`, `mul:4` or `div:2` if present, then clamped to [0, 1] if `clamp` is set, as for f32 (`clamp_mods_f64`, GLSL.std.450 `FClamp` on the double, so a NaN result and the sign of a -0 result are left to the driver, also as for f32). **Until 2026-11-22 both were ignored.** Source: LLVM AMDGPU defines it as `VOP3Inst<"v_add_f64", VOP3_Profile<VOP_F64_F64_F64>>` (VOP3Instructions.td), and `VOPProfile` sets `HasClamp` (f64 is a modifier type) and `HasOMod` (floating-point destination) (SIInstrInfo.td). It is the only f64 arithmetic the translator handles; `v_cvt_f32_f64` has the row above. `tests/test_f64_output_modifiers.py` checks the SPIR-V data flow; `runtime/test/shaders/ps_f64_mods.asm` is the GPU test (needs `shaderFloat64`, which `vk_harness` now enables when the fragment shader declares `Float64`), passed on an NVIDIA RTX 6000 Ada (driver 615.71.09, Linux; 4096/4096 pixels exact, and the `main` translator gives the predicted old words). | |
| @@ -417,6 +434,7 @@ How the generated SPIR-V expects the runtime to work: | |||
| 417 | | 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`. | | 434 | | Workgroup memory limit (SHADER-309) | A compute shader's Workgroup variables, the LDS array plus `%x_buf` (the wave64 exchange, 2·L + 6·W + 7 dwords, or the 3 barrier-round counts, which move into the LDS array when they would push the total past 16,384 B: see "Barrier-round count in LDS (SHADER-579)"), must fit in the device's `maxComputeSharedMemorySize`. `spirv-val` does not check device limits, and RADV (Mesa 27.0.0-devel, RX 7600) dies with SIGFPE in `vkCreateComputePipelines` on a module 4 bytes over 64 KiB (#1721, hand-built repro by YaBulochka). The limit differs per device: 65536 on RADV and NVIDIA, 32768 on the AMD Windows driver (RX 9070 XT, 32.0.32029.2010) and Intel (UHD 770, 101.7092), measured by towade in #1745; the Vulkan minimum is 16384. The translator runs offline, so it has two parts. (1) `rdna2spirv.py` keeps every module under a hard cap, `MAX_SHARED_BYTES` (`--max-shared-memory`, default 65536): the LDS array is the program's need (RSRC2 LDS_SIZE, or the end of the furthest constant-offset access, counted exactly from the offset and the access width: a b32 at offset 65,532 ends at 16,384 dwords) rounded up to a power of two; when that plus `%x_buf` is over the cap but the need still fits, the array shrinks to the RSRC2 allocation and its accesses are bounds-checked (below); when the need itself does not fit (a 64 KiB LDS under `--wave64-emulate`) the shader is refused (`Unsupported`, with the byte counts). The array is clipped to 16,384 dwords, but an RSRC2 allocation over the cap (LDS_SIZE above 128 units, so 66,048 B or more) is counted at its full size and refused, native or emulated, instead of being cut. LDS bounds: RDNA2 LDS does not wrap, and an access outside the workgroup's allocation reads 0 and its write is dropped (RDNA2 ISA sections 3.6.1 and 3.6.6). The wrapped power-of-two array aliases such an access onto a valid word, so when a program's constant offsets reach past its RSRC2 allocation, or the array was shrunk, the array is the allocation and `Gen.lds_access` checks every dword (`index < allocation`, else a read or an atomic's old value is 0 and the write or atomic is skipped): `ds_read*`/`ds_write*` of every width (b64/b96/b128 and read2/write2 per dword), the sub-dword reads and writes, every LDS atomic, `ds_cmpst`, `ds_mskor`, `ds_wrxchg*`. `ds_swizzle`/`ds_bpermute`/`ds_permute` do not use `%lds`; `ds_append`/`ds_consume` were already refused. Every other shader keeps the wrapped array and emits no check, as before. **No game shader takes this path.** Counted over a 1.0.2.1 corpus by towade (#1882, counts only), and again at `main` `aa2988cc` by running `translate()` on every CS: with the exact need (offset + access width), none of the 485 LDS-using CS reaches past its RSRC2 allocation with a constant offset, and none is shrunk, natively or with `--wave64-emulate`. So none gets a bounds check (no `OpULessThan` added), and only the synthetic tests below exercise it. The earlier "16 of 486" came from the older offset + 4-dword estimate; at `aa2988cc` that bound flags 37 of the 485, all inside their allocation. Hypothesis, not yet counted over the corpus: the 16 of 486 LDS-using CS that index past LDS_SIZE with constant offsets (the Compute shaders row) now read 0 there, as the ISA says, where they used to read the wrapped word. Counted over a 1.0.2.1 corpus by towade (#1882, counts only): with the exact need (offset + access width) none of the 485 LDS-using CS reaches past its RSRC2 allocation with a constant offset, so none gets a bounds check (no `OpULessThan` added, native or emulated); the "16 of 486" in the Compute shaders row came from the older offset + 4-dword estimate. `%x_buf` is already sized to the workgroup's waves, so it has nothing to give back. `lds_bytes` in `index.json` is the module's whole Workgroup total (LDS, `%x_buf`, a mesh shader's `%ms_counts`). (2) The D3D12 shim's `create_compute` compares `lds_bytes` with the device's `maxComputeSharedMemorySize` and refuses the pipeline with a log line (`E_NOTIMPL`) instead of creating an invalid one. Pinned by `tests/semantic/test_cs_shared_memory_limit.py` (Workgroup bytes counted from the emitted SPIR-V: under the cap unchanged, shrunk to the 51,200 B allocation and bounds-checked, the exact-cap boundary, an access ending at 64 KiB counted exactly, a 64 KiB LDS refused when emulated and accepted natively, a native 66,048 B allocation refused, run through `spirv_mini_interp`: an out-of-range write dropped with the word it would wrap to intact, out-of-range reads (b32, u16) giving 0, a b64 write straddling the allocation's end, out-of-range atomics returning 0 and changing nothing, and an in-range shader with no check; `lds_bytes` equal to the SPIR-V total) and `shader_library_test` (`lds_bytes` read from the index). Confirmed by those CPU tests only; GPU runs (RADV; AMD Windows and Intel at 32 KiB) are pending. Not covered: mesh shaders against `maxMeshSharedMemorySize`. | |
| 418 | | 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`. | | 435 | | Wave64 leading-bit scans | With `--wave64-emulate`, `s_flbit_i32_b32` and `s_flbit_i32` of a lane mask use the same wave-wide exchange as `s_bcnt1` and `s_ff1`. These reads prevent lane-local EXEC-zero folding and require synchronized scheduling in wave-divergent blocks. Plain scalar inputs still allow the fold. Hand-written compute shaders in `tests/semantic/test_wave64_emulate_opt.py` check EXECZ at 64 and 128 threads and a branch on SCC taken by just one wave at 128 threads. The strict CPU workgroup interpreter observes the unsigned scan of VCC_LO = 8 returning 28 in the expected invocations. Both scan forms pass `spirv-val --target-env vulkan1.2`. | |
| 419 | | 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.** | | 436 | | Wave64 emulation: scalar exits from a folded EXECZ region | A folded lane-local `s_cbranch_execz`/`execnz` region may leave to its join from inside, for example `s_cmp` + `s_cbranch_scc0/scc1` straight to the label that restores EXEC. The ISA then skips the rest of the region for the whole wave. `find_local_exec_folds` in `tools/wave64_emulate_opt.py` builds the region's sub-CFG with an exit node for every edge to the join, so `cfg_structure.structure` puts each later block of the region behind a `%pc` guard; the exit node itself emits nothing. Before this the edge was dropped and the block after the branch ran whenever the lane was active. Confirmed on the CPU against the native wave64 translation and the ISA: `tests/semantic/test_wave64_emulate_opt.py` `test_folded_region_scalar_branch_to_join_skips_the_rest` (taken and not-taken `scc0`/`scc1`, 64 and 128 threads, the region still folded) fails before the change on the four taken cases. **Not GPU-verified.** | |
| 437 | | Wave64 emulation: 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). | | ||
| 420 | | 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. | | 438 | | 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. | |
| 421 | | Metadata index | `spirv/index.json`: one entry per translated shader with its stage, `wave64` / `subgroup_size`, SPIR-V capabilities and extensions, the Vulkan **features** to enable (barycentrics, interlock, mesh, geometry, Float64, Int64, buffer device address, write-without-format, `shaderFmaFloat32` for `--fma khr`, …), `needs_maintenance8`, the descriptor bindings it uses (set 0), push-constant size, `local_size`, `user_sgprs` (CS), `lds_bytes`, mesh `max_vertices`/`max_primitives`/`params`, geometry inputs/outputs, vertex-input locations and types, full `vertex_input_signature` (ISG1 register/mask/system-value/component-type, for PSO lookup), `wave64_emulated` (true for VS/PS/GS wave64, which the translator emits as per-subgroup code with no cross-half exchange, and for compute/mesh translated with `--wave64-emulate`; the runtime does not use it: it reads `wave64`, `subgroup_size` and `wave64_exchange`), `dynamic_format` (runtime V# FORMAT: codes outside FORMATS decode to 0) / `fixed_format_codes`, `src_sha256` and optional `fssm_sha256` (via `--fssm-dir`), PS system inputs, `bary_fallback_input` (`--bary-fallback`: the location of the barycentric input), `mesh_compute` (`--mesh-compute`: the slot layout and push-constant size), `pc_tail` (`--pc-tail-ubo`: the set, binding and size of the uniform block that holds the push-constant tail), and input/output locations. A shader translated with `--wave64-emulate` carries `wave64_exchange: "workgroup"` and `subgroup_size: null`: any subgroup size is exact, request none. Otherwise `subgroup_size` (64 for wave64, 32) is what the PSO asks for through `VkPipelineShaderStageRequiredSubgroupSizeCreateInfo` where the device lists the stage in `requiredSubgroupSizeStages` (docs/d3d12_vulkan.md section 3.2): that list is the driver's, not "compute/mesh only". The AMD Windows driver reports FRAGMENT, COMPUTE, TASK and MESH (measured on a Radeon 880M, driver 26.11.2, sizes 32..64), and current Mesa RADV on GFX10+ reports COMPUTE, FRAGMENT and task/mesh (`src/amd/vulkan/radv_physical_device.c`, `requiredSubgroupSizeStages`, Mesa main at 152b9cde; older Mesa: compute only), so wave64 pixel shaders can run exact there. NVIDIA lists every stage but only size 32, so there a native wave64 shader cannot get 64 and wave64 PS/VS/GS stay 2x32. A runtime can create every pipeline at load time from it without parsing SPIR-V. | | 439 | | Metadata index | `spirv/index.json`: one entry per translated shader with its stage, `wave64` / `subgroup_size`, SPIR-V capabilities and extensions, the Vulkan **features** to enable (barycentrics, interlock, mesh, geometry, Float64, Int64, buffer device address, write-without-format, `shaderFmaFloat32` for `--fma khr`, …), `needs_maintenance8`, the descriptor bindings it uses (set 0), push-constant size, `local_size`, `user_sgprs` (CS), `lds_bytes`, mesh `max_vertices`/`max_primitives`/`params`, geometry inputs/outputs, vertex-input locations and types, full `vertex_input_signature` (ISG1 register/mask/system-value/component-type, for PSO lookup), `wave64_emulated` (true for VS/PS/GS wave64, which the translator emits as per-subgroup code with no cross-half exchange, and for compute/mesh translated with `--wave64-emulate`; the runtime does not use it: it reads `wave64`, `subgroup_size` and `wave64_exchange`), `dynamic_format` (runtime V# FORMAT: codes outside FORMATS decode to 0) / `fixed_format_codes`, `src_sha256` and optional `fssm_sha256` (via `--fssm-dir`), PS system inputs, `bary_fallback_input` (`--bary-fallback`: the location of the barycentric input), `mesh_compute` (`--mesh-compute`: the slot layout and push-constant size), `pc_tail` (`--pc-tail-ubo`: the set, binding and size of the uniform block that holds the push-constant tail), and input/output locations. A shader translated with `--wave64-emulate` carries `wave64_exchange: "workgroup"` and `subgroup_size: null`: any subgroup size is exact, request none. Otherwise `subgroup_size` (64 for wave64, 32) is what the PSO asks for through `VkPipelineShaderStageRequiredSubgroupSizeCreateInfo` where the device lists the stage in `requiredSubgroupSizeStages` (docs/d3d12_vulkan.md section 3.2): that list is the driver's, not "compute/mesh only". The AMD Windows driver reports FRAGMENT, COMPUTE, TASK and MESH (measured on a Radeon 880M, driver 26.11.2, sizes 32..64), and current Mesa RADV on GFX10+ reports COMPUTE, FRAGMENT and task/mesh (`src/amd/vulkan/radv_physical_device.c`, `requiredSubgroupSizeStages`, Mesa main at 152b9cde; older Mesa: compute only), so wave64 pixel shaders can run exact there. NVIDIA lists every stage but only size 32, so there a native wave64 shader cannot get 64 and wave64 PS/VS/GS stay 2x32. A runtime can create every pipeline at load time from it without parsing SPIR-V. | |
| 422 | | Full-corpus pipeline build | `vk_pipeline_check <spirv dir> pipeline_cache.bin --jobs 4` on an RTX 4060 Ti (NVIDIA 595 driver): **all 26,503 shaders become real pipelines, 0 failures** (cs 2,689, ps 12,101, ms 9,282, vs 2,236, gs 195; graphics stages with generated stub partners). Compile time 40,784 s of CPU (2.84 h wall on 4 threads): cs 23,633 s (mean 8.8 s; the ray-tracing ScreenProbes/RTShadowTrace shaders take 2-19 min each), ps 11,481 s, ms 5,395 s, vs 275 s. The resulting `VkPipelineCache` is 3.81 GB; seeding a run with it makes those pipelines instant, which is what a fast first boot needs. The cache is per driver and GPU, and a shader whose SPIR-V changes compiles again (the checker resumes from the file). Neither register storage (one variable per register) nor smaller SPIR-V cut NVIDIA compile time: the big ray-tracing shaders are expensive as such, so the runtime should compile them in the background rather than block on them. | | 440 | | Full-corpus pipeline build | `vk_pipeline_check <spirv dir> pipeline_cache.bin --jobs 4` on an RTX 4060 Ti (NVIDIA 595 driver): **all 26,503 shaders become real pipelines, 0 failures** (cs 2,689, ps 12,101, ms 9,282, vs 2,236, gs 195; graphics stages with generated stub partners). Compile time 40,784 s of CPU (2.84 h wall on 4 threads): cs 23,633 s (mean 8.8 s; the ray-tracing ScreenProbes/RTShadowTrace shaders take 2-19 min each), ps 11,481 s, ms 5,395 s, vs 275 s. The resulting `VkPipelineCache` is 3.81 GB; seeding a run with it makes those pipelines instant, which is what a fast first boot needs. The cache is per driver and GPU, and a shader whose SPIR-V changes compiles again (the checker resumes from the file). Neither register storage (one variable per register) nor smaller SPIR-V cut NVIDIA compile time: the big ray-tracing shaders are expensive as such, so the runtime should compile them in the background rather than block on them. | |
| @@ -515,10 +533,10 @@ How the generated SPIR-V expects the runtime to work: | |||
| 515 | | 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`. | | 533 | | 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`. | |
| 516 | | `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.** | | 534 | | `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.** | |
| 517 | | 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. | | 535 | | 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. | |
| 518 | | 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, so the 32-lane run repacks the vertices rather than halving the waves; tier A/B words are keyed on the vertex index, which makes this the stricter test. `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`. | | 536 | | 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`. | |
| 519 | | Wave64 graphics: a uniform vote under whole-quad EXEC (SHADER-W64-WQM-UVOTE) | SHADER-10 (the row above) takes a `vccz`/`vccnz` on a wave-uniform compare for no lane vote only while EXEC is the launch mask. A pixel shader that needs derivatives starts with `s_wqm_b64 exec, exec`, and LLVM branches on uniform conditions inside that region in the same form: `v_cmp_* sN, <scalars>` / `s_and_b64 vcc, exec, s[N:N+1]` / `s_cbranch_vccnz` (or the compare straight into VCC). **That is exact too, for a compare of immediates and scalars**: it is the same in every lane, so its mask is every lane of EXEC or none; EXEC is the whole quads of the launch mask, a quad is four consecutive lanes and never straddles the two 32-lane halves, and a half that runs has a launch lane, so EXEC has a lane in every half that runs and each half votes as the wave does. Both sides of the branch may then have code and scalars of their own (if/else, a uniform loop back edge), as under the launch mask. `tools/wave64_halves.py` carries it as a dataflow fact (`q`: EXEC is the whole quads of the launch mask), set by `s_wqm_b64 exec, exec` while EXEC is the launch mask and dropped by every other write to EXEC; `uniform_cmp` and the `s_and_b64 .., exec, ..` of a uniform mask accept it next to the launch mask. **What stays tier C, and why**: a VGPR source, even one SHADER-10 calls uniform (it was written under the launch mask, and the helper lanes EXEC now includes never got it, so they compare what they held; a VGPR written inside the region is refused as well, because the analysis does not tell the two apart); the whole quads of a narrowed EXEC, and any narrowing after the `s_wqm_b64` (a half can be empty); whole quads saved and put back later, or made in a register and copied to EXEC (only the write by `s_wqm_b64 exec, exec` is modelled); and a compare on a path where a scalar was read out of a uniform VGPR from a lane the launch mask may not have written, by `v_readlane_b32` at any time or by `v_readfirstlane_b32` while EXEC was not the launch mask (`qr`, kept for the rest of the path: SHADER-10 treats such a scalar as uniform, this rule does not build on that). **Corpus** (1.0.2.1, all 26,503, `wave64_halves.analyse` on every wave64 VS/PS/GS, with SHADER-W64-SDST-PAIR on `main` `3ed8e50b7` as the baseline, because the listings name the compare's destination by one register and without that rule the vote is hidden behind `tainted-branch`): **452 pixel shaders go from tier C to A**, no shader moves the other way and no vertex or geometry shader moves: A 5,267 to 5,719, B 397, C 7,741 to 7,289 (PS 3,545/34/7,395 to 3,997/34/6,943). Reasons: `unsafe-vote-branch` 7,362 to 6,861, `tainted-exec` 5,829 to 5,793, `stale-scalar` 3,287 to 3,254, the others unchanged; 802 shaders still have `unsafe-vote-branch` as their only reason. CPU-checked by `tests/semantic/test_wave64_halves_wqm_uvote.py`: the accepted forms in both printed forms of the destination, ten near misses that stay tier C, and a vertex and a pixel shader run on the wave interpreter as one wave of 64 lanes and as two of 32, equal and equal to the derived words with s4 = 9 and s4 = 1 (every lane covered there: the interpreters do not model a helper lane in a quad swap, so partial coverage rests on the argument above). GPU-checked by `ps_w64_a_wqm_uniform_vote` (`w64_graphics.py`: an if/else on a compare into VCC, the LLVM form through an SGPR pair and a loop closed by the vote, all under `s_wqm_b64 exec, exec`, EXEC put back before the export), which gives the words its header derives on an NVIDIA GeForce RTX 4070 Ti (Linux, driver 620.70.06, 32 only). That device has one subgroup size, so the 64-lane image was not drawn there and the full-screen draw has no partly covered quad; the run confirms the translated SPIR-V against the ISA reference, not native RDNA2 behaviour. | | 537 | | Wave64 graphics: a uniform vote under whole-quad EXEC (SHADER-W64-WQM-UVOTE) | SHADER-10 (the row above) takes a `vccz`/`vccnz` on a wave-uniform compare for no lane vote only while EXEC is the launch mask. A pixel shader that needs derivatives starts with `s_wqm_b64 exec, exec`, and LLVM branches on uniform conditions inside that region in the same form: `v_cmp_* sN, <scalars>` / `s_and_b64 vcc, exec, s[N:N+1]` / `s_cbranch_vccnz` (or the compare straight into VCC). **That is exact too, for a compare of immediates and scalars**: it is the same in every lane, so its mask is every lane of EXEC or none; EXEC is the whole quads of the launch mask, a quad is four consecutive lanes and never straddles the two 32-lane halves, and a half that runs has a launch lane, so EXEC has a lane in every half that runs and each half votes as the wave does. Both sides of the branch may then have code and scalars of their own (if/else, a uniform loop back edge), as under the launch mask. `tools/wave64_halves.py` carries it as a dataflow fact (`q`: EXEC is the whole quads of the launch mask), set by `s_wqm_b64 exec, exec` while EXEC is the launch mask and dropped by every other write to EXEC; `uniform_cmp` and the `s_and_b64 .., exec, ..` of a uniform mask accept it next to the launch mask. **What stays tier C, and why**: a VGPR source, even one SHADER-10 calls uniform (it was written under the launch mask, and the helper lanes EXEC now includes never got it, so they compare what they held; a VGPR written inside the region is refused as well, because the analysis does not tell the two apart); the whole quads of a narrowed EXEC, and any narrowing after the `s_wqm_b64` (a half can be empty); whole quads saved and put back later, or made in a register and copied to EXEC (only the write by `s_wqm_b64 exec, exec` is modelled); and a compare on a path where a scalar was read out of a uniform VGPR from a lane the launch mask may not have written, by `v_readlane_b32` at any time or by `v_readfirstlane_b32` while EXEC was not the launch mask (`qr`, kept for the rest of the path: SHADER-10 treats such a scalar as uniform, this rule does not build on that). **Corpus** (1.0.2.1, all 26,503, `wave64_halves.analyse` on every wave64 VS/PS/GS, with SHADER-W64-SDST-PAIR on `main` `3ed8e50b7` as the baseline, because the listings name the compare's destination by one register and without that rule the vote is hidden behind `tainted-branch`): **452 pixel shaders go from tier C to A**, no shader moves the other way and no vertex or geometry shader moves: A 5,267 to 5,719, B 397, C 7,741 to 7,289 (PS 3,545/34/7,395 to 3,997/34/6,943). Reasons: `unsafe-vote-branch` 7,362 to 6,861, `tainted-exec` 5,829 to 5,793, `stale-scalar` 3,287 to 3,254, the others unchanged; 802 shaders still have `unsafe-vote-branch` as their only reason. CPU-checked by `tests/semantic/test_wave64_halves_wqm_uvote.py`: the accepted forms in both printed forms of the destination, ten near misses that stay tier C, and a vertex and a pixel shader run on the wave interpreter as one wave of 64 lanes and as two of 32, equal and equal to the derived words with s4 = 9 and s4 = 1 (every lane covered there: the interpreters do not model a helper lane in a quad swap, so partial coverage rests on the argument above). GPU-checked by `ps_w64_a_wqm_uniform_vote` (`w64_graphics.py`: an if/else on a compare into VCC, the LLVM form through an SGPR pair and a loop closed by the vote, all under `s_wqm_b64 exec, exec`, EXEC put back before the export), which gives the words its header derives on an NVIDIA GeForce RTX 4070 Ti (Linux, driver 620.70.06, 32 only). That device has one subgroup size, so the 64-lane image was not drawn there and the full-screen draw has no partly covered quad; the run confirms the translated SPIR-V against the ISA reference, not native RDNA2 behaviour. | |
| 520 | | GFX10.1 (console gfx1013) / GFX10.3 (gfx1030, gfx1036 oracle) opcode differences | Found by disassembling every opcode of every GFX10 encoding (SOP1/SOP2/SOPK/SOPC/SOPP, SMEM, VOP1/VOP2/VOPC/VOP3/VOP3P, DS, FLAT/GLOBAL/SCRATCH, MUBUF/MTBUF, MIMG) with LLVM 21 `llvm-mc` for `-mcpu=gfx1013` and for `gfx1030`/`gfx1036` (the two gfx103x lists are identical). Every other opcode slot decodes to the same mnemonic on both, so the hardware-oracle rows measured on gfx1036 are about the same instructions the console runs (the microarchitectures still differ, which no opcode table shows). **On gfx1013 only:** `v_mac_f32`/`v_mad_f32` (VOP2 0x1f, VOP3 0x11f/0x141) and `v_mac_legacy_f32`/`v_mad_legacy_f32` (VOP2 0x06, VOP3 0x106/0x140), translated (rows above; not measurable on gfx103x, where 0x06/0x106/0x140 are the fused `v_fmac_legacy_f32`/`v_fma_legacy_f32`); `v_mul_lo_i32` (VOP3 0x16b; `Unsupported` until #3504 translates it); `s_get_waveid_in_workgroup` (SMEM 0x2a), translated in compute and mesh shaders; scalar stores (`s_store_dword*`, `s_buffer_store_dword*`), scalar atomics (`s_atomic_*`, `s_buffer_atomic_*`, 32- and 64-bit), scalar scratch (`s_scratch_load/store_dword*`), `s_dcache_wb`, `s_dcache_discard(_x2)` and the 31 LDS `ds_*_src2_*` forms, all `Unsupported`. **On gfx103x only:** `v_dot2c_f32_f16`, `v_dot4c_i32_i8`, the VOP3P `v_dot2_f32_f16`, `v_dot2_i32_i16`/`u32_u16`, `v_dot4_i32_i8`/`u32_u8`, `v_dot8_i32_i4`/`u32_u4`, `v_fmac_legacy_f32`/`v_fma_legacy_f32`, `global_load/store_dword_addtid`, `global_atomic_csub`, `buffer_atomic_csub`. The console's code can't contain these; the translator handles the integer dot products (rows above, measured on gfx1036) and refuses the rest, so a listing disassembled for the wrong target (VOP2 0x06 printed as `v_fmac_legacy_f32`) fails loudly instead of being translated as a fused multiply-add. Not covered by the sweep: opcodes whose operand template did not decode on either target, and behaviour that differs without an opcode change. | | 538 | | GFX10.1 (console gfx1013) / GFX10.3 (gfx1030, gfx1036 oracle) opcode differences | Found by disassembling every opcode of every GFX10 encoding (SOP1/SOP2/SOPK/SOPC/SOPP, SMEM, VOP1/VOP2/VOPC/VOP3/VOP3P, DS, FLAT/GLOBAL/SCRATCH, MUBUF/MTBUF, MIMG) with LLVM 21 `llvm-mc` for `-mcpu=gfx1013` and for `gfx1030`/`gfx1036` (the two gfx103x lists are identical). Every other opcode slot decodes to the same mnemonic on both, so the hardware-oracle rows measured on gfx1036 are about the same instructions the console runs (the microarchitectures still differ, which no opcode table shows). **On gfx1013 only:** `v_mac_f32`/`v_mad_f32` (VOP2 0x1f, VOP3 0x11f/0x141) and `v_mac_legacy_f32`/`v_mad_legacy_f32` (VOP2 0x06, VOP3 0x106/0x140), translated (rows above; not measurable on gfx103x, where 0x06/0x106/0x140 are the fused `v_fmac_legacy_f32`/`v_fma_legacy_f32`); `v_mul_lo_i32` (VOP3 0x16b; `Unsupported` until #3504 translates it); `s_get_waveid_in_workgroup` (SMEM 0x2a), translated in compute and mesh shaders; scalar stores (`s_store_dword*`, `s_buffer_store_dword*`), scalar atomics (`s_atomic_*`, `s_buffer_atomic_*`, 32- and 64-bit), scalar scratch (`s_scratch_load/store_dword*`), `s_dcache_wb`, `s_dcache_discard(_x2)` and the 31 LDS `ds_*_src2_*` forms, all `Unsupported`. **On gfx103x only:** `v_dot2c_f32_f16`, `v_dot4c_i32_i8`, the VOP3P `v_dot2_f32_f16`, `v_dot2_i32_i16`/`u32_u16`, `v_dot4_i32_i8`/`u32_u8`, `v_dot8_i32_i4`/`u32_u4`, `v_fmac_legacy_f32`/`v_fma_legacy_f32`, `global_load/store_dword_addtid`, `global_atomic_csub`, `buffer_atomic_csub`. The console's code can't contain these; the translator handles the integer dot products (rows above, measured on gfx1036) and refuses the rest, so a listing disassembled for the wrong target (VOP2 0x06 printed as `v_fmac_legacy_f32`) fails loudly instead of being translated as a fused multiply-add. Not covered by the sweep: opcodes whose operand template did not decode on either target, and behaviour that differs without an opcode change. | |
| 521 | | Buffer bounds checking | MUBUF `buffer_load*`, `buffer_store*`, and `buffer_atomic*` enforce `num_records` (V# word 2). Out-of-bounds stores/atomics skip memory access completely and out-of-bounds loads return 0 without a load. **The RX 6800 measurement behind RAW loads** (`buffer_load_dword`/`x2`/`x3`/`x4`, stride 0, no `idxen`, OOB_SELECT 3; the per-mode rule below covers every mode, stride and `idxen`): the byte offset O = inst_offset + soffset + (offen ? vaddr : 0) is exact (nothing truncated, and the address keeps base & 3), and dword i is data when O + 4·i + 4 ≤ num_records, else 0, 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), for x1/x2/x4 with V# word3 0x31016fac (OOB_SELECT 3) at offsets 0..63 per lane, NUM_RECORDS 17..23 and 0x1000, base & 3 = 0 and 3: a dword at 0xf with NUM_RECORDS 18 is 0 (a start-only check reads it); x4 at 3 with 18 gives three data dwords and 0 for the fourth, which starts at 15 < 18 (so neither a whole-load nor a per-dword start check), and the zero is a whole 0, not partial bytes; x4 at offset:13 with 20 gives data, 0, 0, 0; inst_offset, soffset and offen are summed before the check; base & 3 = 3 flips at the same offsets. `x3` gets the rule without a measurement. **Per-mode check (V# OOB_SELECT, word3 bits [29:28])**, for every MUBUF/MTBUF access, as measured natively on RDNA2 (gfx1036, 732 cases, `docs/buffer_bounds.md`; Mesa's GFX11 column, not its GFX10 one). `idx` = `vindex` (0 without `idxen`), `off` = inst_offset + vaddr offset (offen), `offs` = `off` + soffset. A dword at byte 4·k of the access is out of range when: **0 STRUCTURED_WITH_OFFSET** `idx >= num_records` or `off + 4k + 4 > stride`; **1 STRUCTURED** `idx >= num_records` (no `idxen`: idx 0, so only `num_records == 0`); **2 DISABLED** `num_records == 0`; **3 RAW** `offs + 4k + 4 > num_records` (`idx * stride` is in the address, not in the check). A literal word3 (`s_mov_b32` earlier in the block) folds the mode, a run-time one selects with `OpSelect`. Multi-dword accesses, measured on the Radeon 880M (gfx1150, a valid proxy: gfx1036 follows the same column and gfx1150 matched it bit-exactly): in modes 0 and 3 **`buffer_load_dwordx2..x4` and `buffer_store_dwordx2..x4` are per dword**, for loads and stores alike (x4 at off 20 of 32 in RAW loads/stores 3 dwords, at 28 one, at 32 none; mode 0 likewise at the stride); modes 1 and 2 check once and always take the whole access. **A typed element (`buffer_load_format_*`, `buffer_store_format_*`) is all or nothing and ends at its format's size** (32_32_32_32 at off 20 of 32 reads or writes nothing), and an atomic checks its dword's end like a dword access. The translator does the same: per-dword guarded loads and stores for modes 0 and 3 (a store that straddled the edge used to write past it), the element size from the instruction's format, a literal word3 or the V#. The same oracle confirmed the terms (504 `buffer_load_dword` probes, idxen/offen/inst_offset/soffset at the stride and record edges, 0 disagreements): mode 0's `off` has `inst_offset` and no soffset, mode 1 reads nothing but the index, mode 3 adds inst_offset and soffset. `s_buffer_load` (SMEM) is separate: it keeps the `num_records` bound of the Scalar/buffer row and ignores OOB_SELECT (the same pattern for 0 to 3). **Swizzle**: SWIZZLE_ENABLE (V# word1 bit 31, Mesa `gfx10-rsrc.json` line 326; word1 [31:30] on GFX11, `gfx11-rsrc.json` line 259) and ADD_TID_ENABLE (word3 bit 23, line 337) change the address and the bounds in every mode and are modelled; see the Swizzled buffer addressing row. SWIZZLE_ENABLE and ADD_TID_ENABLE are modelled; see the Swizzled buffer addressing row. SWIZZLE_ENABLE (V# word1 bit 31, Mesa `gfx10-rsrc.json` line 326; word1 [31:30] on GFX11, `gfx11-rsrc.json` line 259) and ADD_TID_ENABLE (word3 bit 23, line 337) change the address and the bounds in every mode and are not modelled: a literal V# with either set is `Unsupported`, a run-time V# with them is translated unswizzled, which is silently wrong (known gap). Until 2026-11-22 the translator ignored OOB_SELECT and checked by stride alone (`offset < num_records`, `index < num_records`, or `offset < num_records * stride`): a V# with word3 = 0 (mode 0, stride 0) was fully readable and is now always out of range, as on hardware, so the test harnesses' output V# is `0x31016fac` now (`vk_compute_test`, the interpreter tests, `cs_bounds.asm`, `cs_fmt_1010102.asm`, `cs_store.asm`). **How confirmed**: the native RDNA2 measurement (gfx1036) and the gfx1150 oracle (RDNA3.5, same column); GPU test `cs_oob_select.asm` (every mode, literal and run-time V#, words derived from the rules) on an NVIDIA RTX 5070 and an AMD Radeon 880M, which checks the translation, not RDNA2; `tests/semantic/test_buffer_oob_select.py` (a hand-written table of 33 cases over the four modes, loads and stores, both V# forms, plus the multi-dword stores and typed elements); `cs_oob_tail.asm` pins the end-based edge, per-dword x4 loads and stores and the all-or-nothing element, where Mesa's GFX10 column gives other words. **RDNA1 (gfx1011, Navi 12) follows the same RDNA2/GFX11 column**: `tools/buffer_bounds_probe.py` ran 12 one-lane 4-byte `buffer_load_dword` cases at wave32 and wave64 through `tools/hw_oracle` (24 groups, 0 wave32/64 differences); all matched the measured column and 8 disagreed with Mesa's GFX10 column (SHADER-341, results in `docs/buffer_bounds.md`). **Unmeasured**: gfx1013/GFX10.1 itself (see `docs/buffer_bounds.md`), swizzle, unaligned addresses, and the mode 1/2 boundary of `buffer_load_dwordx2..x4` on RDNA2 hardware proper (the gfx1150 proxy shows all dwords in). Checked by `tests/semantic/test_value_semantics.py` (`RawBufferTailBounds`: the RX 6800 rows, values and the addresses loaded) and the GPU tests `runtime/test/shaders/cs_bounds.asm` (AMD Radeon RX 9070 XT, RX 6800), `cs_buf_tail.asm` (RX 6800, Vulkan, driver 26.11.2; aligned offsets only, since the translator's `Aligned 4` loads at byte-exact addresses were not checked on a Vulkan driver) `cs_oob_select.asm` and `cs_oob_tail.asm`. `cs_fmt_xy_xyz.asm` shows the whole element deciding for `_xy` and `_xyz` too, measured natively on a Radeon 680M (gfx1035, RDNA2): components that end inside num_records, in an element that doesn't, read 0 and store nothing. | | 539 | | Buffer bounds checking | MUBUF `buffer_load*`, `buffer_store*`, and `buffer_atomic*` enforce `num_records` (V# word 2). Out-of-bounds stores/atomics skip memory access completely and out-of-bounds loads return 0 without a load. **The RX 6800 measurement behind RAW loads** (`buffer_load_dword`/`x2`/`x3`/`x4`, stride 0, no `idxen`, OOB_SELECT 3; the per-mode rule below covers every mode, stride and `idxen`): the byte offset O = inst_offset + soffset + (offen ? vaddr : 0) is exact (nothing truncated, and the address keeps base & 3), and dword i is data when O + 4·i + 4 ≤ num_records, else 0, 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), for x1/x2/x4 with V# word3 0x31016fac (OOB_SELECT 3) at offsets 0..63 per lane, NUM_RECORDS 17..23 and 0x1000, base & 3 = 0 and 3: a dword at 0xf with NUM_RECORDS 18 is 0 (a start-only check reads it); x4 at 3 with 18 gives three data dwords and 0 for the fourth, which starts at 15 < 18 (so neither a whole-load nor a per-dword start check), and the zero is a whole 0, not partial bytes; x4 at offset:13 with 20 gives data, 0, 0, 0; inst_offset, soffset and offen are summed before the check; base & 3 = 3 flips at the same offsets. `x3` gets the rule without a measurement. **Per-mode check (V# OOB_SELECT, word3 bits [29:28])**, for every MUBUF/MTBUF access, as measured natively on RDNA2 (gfx1036, 732 cases, `docs/buffer_bounds.md`; Mesa's GFX11 column, not its GFX10 one). `idx` = `vindex` (0 without `idxen`), `off` = inst_offset + vaddr offset (offen), `offs` = `off` + soffset. A dword at byte 4·k of the access is out of range when: **0 STRUCTURED_WITH_OFFSET** `idx >= num_records` or `off + 4k + 4 > stride`; **1 STRUCTURED** `idx >= num_records` (no `idxen`: idx 0, so only `num_records == 0`); **2 DISABLED** `num_records == 0`; **3 RAW** `offs + 4k + 4 > num_records` (`idx * stride` is in the address, not in the check). A literal word3 (`s_mov_b32` earlier in the block) folds the mode, a run-time one selects with `OpSelect`. Multi-dword accesses, measured on the Radeon 880M (gfx1150, a valid proxy: gfx1036 follows the same column and gfx1150 matched it bit-exactly): in modes 0 and 3 **`buffer_load_dwordx2..x4` and `buffer_store_dwordx2..x4` are per dword**, for loads and stores alike (x4 at off 20 of 32 in RAW loads/stores 3 dwords, at 28 one, at 32 none; mode 0 likewise at the stride); modes 1 and 2 check once and always take the whole access. **A typed element (`buffer_load_format_*`, `buffer_store_format_*`) is all or nothing and ends at its format's size** (32_32_32_32 at off 20 of 32 reads or writes nothing), and an atomic checks its dword's end like a dword access. The translator does the same: per-dword guarded loads and stores for modes 0 and 3 (a store that straddled the edge used to write past it), the element size from the instruction's format, a literal word3 or the V#. The same oracle confirmed the terms (504 `buffer_load_dword` probes, idxen/offen/inst_offset/soffset at the stride and record edges, 0 disagreements): mode 0's `off` has `inst_offset` and no soffset, mode 1 reads nothing but the index, mode 3 adds inst_offset and soffset. **Offsets that do not fit 32 bits**: the hardware adds `idx * stride` (a full product) and soffset to the 48-bit base without wrapping, so `idx` 0xFFFFFFFF with a 20-byte stride lands tens of GiB past the base and has no effect, where a 32-bit offset would turn it into base − 20, inside a view that covers a whole pool (mode 3 does not check the index, mode 2 checks nothing). The translator forms `off + soffset + idx * stride` (and the swizzled offset) in 64 bits as well and treats a value above 0xFFFFFFFF as out of range in every mode; literal modes 0 and 1 without soffset skip it, their index check already bounds the product. Rule and hardware observation from five-star-recomp (ThatRecompDev, GPL-3, commit `b9b57e2`), not measured by us; CPU-checked by `tests/semantic/test_buffer_offset_wrap.py` (raw and disabled, literal and run-time V#, index −1 and off 0xFFFFFFF0 + soffset 0x20; each fails with 32-bit arithmetic). Until 2026-11-24 the offset was 32-bit. `s_buffer_load` (SMEM) is separate: it keeps the `num_records` bound of the Scalar/buffer row and ignores OOB_SELECT (the same pattern for 0 to 3). **Swizzle**: SWIZZLE_ENABLE (V# word1 bit 31, Mesa `gfx10-rsrc.json` line 326; word1 [31:30] on GFX11, `gfx11-rsrc.json` line 259) and ADD_TID_ENABLE (word3 bit 23, line 337) change the address and the bounds in every mode and are modelled; see the Swizzled buffer addressing row. SWIZZLE_ENABLE and ADD_TID_ENABLE are modelled; see the Swizzled buffer addressing row. SWIZZLE_ENABLE (V# word1 bit 31, Mesa `gfx10-rsrc.json` line 326; word1 [31:30] on GFX11, `gfx11-rsrc.json` line 259) and ADD_TID_ENABLE (word3 bit 23, line 337) change the address and the bounds in every mode and are not modelled: a literal V# with either set is `Unsupported`, a run-time V# with them is translated unswizzled, which is silently wrong (known gap). Until 2026-11-22 the translator ignored OOB_SELECT and checked by stride alone (`offset < num_records`, `index < num_records`, or `offset < num_records * stride`): a V# with word3 = 0 (mode 0, stride 0) was fully readable and is now always out of range, as on hardware, so the test harnesses' output V# is `0x31016fac` now (`vk_compute_test`, the interpreter tests, `cs_bounds.asm`, `cs_fmt_1010102.asm`, `cs_store.asm`). **How confirmed**: the native RDNA2 measurement (gfx1036) and the gfx1150 oracle (RDNA3.5, same column); GPU test `cs_oob_select.asm` (every mode, literal and run-time V#, words derived from the rules) on an NVIDIA RTX 5070 and an AMD Radeon 880M, which checks the translation, not RDNA2; `tests/semantic/test_buffer_oob_select.py` (a hand-written table of 33 cases over the four modes, loads and stores, both V# forms, plus the multi-dword stores and typed elements); `cs_oob_tail.asm` pins the end-based edge, per-dword x4 loads and stores and the all-or-nothing element, where Mesa's GFX10 column gives other words. **RDNA1 (gfx1011, Navi 12) follows the same RDNA2/GFX11 column**: `tools/buffer_bounds_probe.py` ran 12 one-lane 4-byte `buffer_load_dword` cases at wave32 and wave64 through `tools/hw_oracle` (24 groups, 0 wave32/64 differences); all matched the measured column and 8 disagreed with Mesa's GFX10 column (SHADER-341, results in `docs/buffer_bounds.md`). **Unmeasured**: gfx1013/GFX10.1 itself (see `docs/buffer_bounds.md`), swizzle, unaligned addresses, and the mode 1/2 boundary of `buffer_load_dwordx2..x4` on RDNA2 hardware proper (the gfx1150 proxy shows all dwords in). Checked by `tests/semantic/test_value_semantics.py` (`RawBufferTailBounds`: the RX 6800 rows, values and the addresses loaded) and the GPU tests `runtime/test/shaders/cs_bounds.asm` (AMD Radeon RX 9070 XT, RX 6800), `cs_buf_tail.asm` (RX 6800, Vulkan, driver 26.11.2; aligned offsets only, since the translator's `Aligned 4` loads at byte-exact addresses were not checked on a Vulkan driver) `cs_oob_select.asm` and `cs_oob_tail.asm`. `cs_fmt_xy_xyz.asm` shows the whole element deciding for `_xy` and `_xyz` too, measured natively on a Radeon 680M (gfx1035, RDNA2): components that end inside num_records, in an element that doesn't, read 0 and store nothing. | |
| 522 | | 8/16-bit MUBUF d16 loads and stores | (The plain `buffer_load_{u,s}byte`/`{u,s}short` are `Gen.buffer_load_sub`'s; `tests/semantic/test_buffer_sub_dword.py` checks them too.) The `_d16` loads (`buffer_load_{u,s}byte_d16[_hi]`, `buffer_load_short_d16[_hi]`) write one 16-bit half of `vdata` (`_hi` the high one; a byte zero- or sign-extended to 16 bits) and keep the other. `buffer_store_byte`/`short` write the low 8/16 bits of `vdata` (the `_d16_hi` forms its high half). The address is `buffer_address`'s, and the bounds check covers the access's own size, 1 or 2 bytes, as for a typed element of that size (`elem="fmt"`, format 1 or 7). Out of range, a load gives 0 (in the half it writes, for d16; **not measured** for d16) and a store writes nothing. Each byte is its own access, so a 16-bit one that crosses a dword is exact; in a swizzled buffer the next dword is `step` bytes on. A store merges each byte into its dword with atomic and/or, as buffer byte format stores do. Inactive lanes neither load nor store, and the first-read analysis counts a d16 load's `vdata` as read. Until 2026-11-22 these ten raised `Unsupported`. CPU-checked by `tests/semantic/test_buffer_sub_dword.py` (every op at byte offsets 0 to 7, the edge of `num_records`, an inactive lane, rejected forms). GPU fixture `cs_w32_buffer_sub16` (the six d16 loads with their kept half and the sign extension, the two `_d16_hi` stores taking bits 23:16 / 31:16), passes on llvmpipe (Mesa 26.0.8) and on an NVIDIA RTX 5090 (595.99.02, @tylerstraub on #1864), all eight words; GPU fixture `cs_w32_buffer_store_sub` for the plain `buffer_store_byte`/`buffer_store_short` (Box16Rehydration's blocker, @YaBulochka on #1864), including a short at byte 3 that writes its high byte into the next dword, passes on llvmpipe with LLVM 21 and 23, and on an Apple M4 (MoltenVK 1.4.2) once the second dword of a 16-bit load is indexed from the first one's pointer instead of a second pointer converted from the same address, which Apple's compiler read as 0 (@sovljanskii on #1864). | | 540 | | 8/16-bit MUBUF d16 loads and stores | (The plain `buffer_load_{u,s}byte`/`{u,s}short` are `Gen.buffer_load_sub`'s; `tests/semantic/test_buffer_sub_dword.py` checks them too.) The `_d16` loads (`buffer_load_{u,s}byte_d16[_hi]`, `buffer_load_short_d16[_hi]`) write one 16-bit half of `vdata` (`_hi` the high one; a byte zero- or sign-extended to 16 bits) and keep the other. `buffer_store_byte`/`short` write the low 8/16 bits of `vdata` (the `_d16_hi` forms its high half). The address is `buffer_address`'s, and the bounds check covers the access's own size, 1 or 2 bytes, as for a typed element of that size (`elem="fmt"`, format 1 or 7). Out of range, a load gives 0 (in the half it writes, for d16; **not measured** for d16) and a store writes nothing. Each byte is its own access, so a 16-bit one that crosses a dword is exact; in a swizzled buffer the next dword is `step` bytes on. A store merges each byte into its dword with atomic and/or, as buffer byte format stores do. Inactive lanes neither load nor store, and the first-read analysis counts a d16 load's `vdata` as read. Until 2026-11-22 these ten raised `Unsupported`. CPU-checked by `tests/semantic/test_buffer_sub_dword.py` (every op at byte offsets 0 to 7, the edge of `num_records`, an inactive lane, rejected forms). GPU fixture `cs_w32_buffer_sub16` (the six d16 loads with their kept half and the sign extension, the two `_d16_hi` stores taking bits 23:16 / 31:16), passes on llvmpipe (Mesa 26.0.8) and on an NVIDIA RTX 5090 (595.99.02, @tylerstraub on #1864), all eight words; GPU fixture `cs_w32_buffer_store_sub` for the plain `buffer_store_byte`/`buffer_store_short` (Box16Rehydration's blocker, @YaBulochka on #1864), including a short at byte 3 that writes its high byte into the next dword, passes on llvmpipe with LLVM 21 and 23, and on an Apple M4 (MoltenVK 1.4.2) once the second dword of a 16-bit load is indexed from the first one's pointer instead of a second pointer converted from the same address, which Apple's compiler read as 0 (@sovljanskii on #1864). | |
| 523 | | Swizzled buffer addressing (V# SWIZZLE_ENABLE, ADD_TID_ENABLE) | MUBUF/MTBUF `buffer_load*`, `buffer_store*`, `buffer_atomic*`, `buffer_load_format_*`/`buffer_store_format_*` and `tbuffer_load/store_format_*` follow the rules measured natively on RDNA2 (`AMD Radeon(TM) Graphics`, gfx1036, Windows driver `32.0.21042.62`, wave32 and wave64; `tools/buffer_swizzle_probe.py`, SHADER-343). MUBUF/MTBUF `buffer_load*`, `buffer_store*`, `buffer_atomic*`, `buffer_load_format_*`/`buffer_store_format_*` and `tbuffer_load_format_*` follow the RDNA2 ISA ("RDNA 2" Instruction Set Architecture, 8.1.5 Buffer Addressing, "Swizzled Buffer Addressing" and tables 33, 35 and 37). Fields, Mesa 24.0.6 `src/amd/registers/gfx10-rsrc.json` (`SQ_BUF_RSRC_WORD1`, `SQ_BUF_RSRC_WORD3` and its `_gfx103` twin, the same bits): `SWIZZLE_ENABLE` word1 bit 31, `STRIDE` word1 `[29:16]`, `INDEX_STRIDE` word3 `[22:21]` (`IS = 8 << n`, i.e., 8, 16, 32 or 64), `ADD_TID_ENABLE` word3 bit 23; element size is fixed at 4 bytes (`word3[20:19]` and `word1[30]` do not alter addressing or stepping). **Effective index:** `index = idxen ? vindex : 0)`, where `lane` is the wave lane (`thread_id[5:0]` within the wave, wrapping at 32 in wave32 and 64 in wave64; `Gen.wave_lane`); **`idxen = 1` completely ignores `ADD_TID_ENABLE`** (linear or swizzled, address and bounds, loads/stores/typed/atomics). **Activation:** `SWIZZLE_ENABLE` activates (`swz_active`) only when `idxen = 1` or `ADD_TID_ENABLE = 1`; with neither, addressing is linear (`base + soffset + off`) and `OOB_SELECT 3` stays RAW even when `stride ≠ 0`. **Address formula (when `swz_active`):** `off = uint32((offen ? vaddr : 0) + inst_offset)` (32-bit wrap), `buffer_offset = (index / IS · stride + (off & ~3)) · IS + (index % IS) · 4 + (off & 3)`, `address = base + soffset + buffer_offset` (confirmed byte-exact for IS 8/16/32/64, non-4-multiple strides, stride 0, and unaligned offsets). **Two swizzle sub-modes:** (1) **Scratch swizzle** (`SWIZZLE_ENABLE = 1`, `idxen = 0`, `ADD_TID_ENABLE = 1`): raw multi-dword `buffer_load/store_dwordx2..x4` step by **`+4 · IS`** bytes per dword (and unaligned 4-byte raw accesses crossing a dword boundary split across `+4 · IS` on hardware), while **typed formats > 4 bytes** (8/12/16-byte MUBUF and MTBUF loads/stores, regardless of component count) and **8-byte `buffer_atomic_*_x2`** are **suppressed** (loads return 0, stores/atomics are no-ops, even in `OOB_SELECT 2`); typed formats ≤ 4 bytes work normally. (2) **Indexed swizzle** (`SWIZZLE_ENABLE = 1`, `idxen = 1`, regardless of `ADD_TID_ENABLE`): raw `x2..x4`, typed formats (8/12/16 bytes), and `buffer_atomic_*_x2` step **linearly by `+4` bytes** from the swizzled base address, even across `IS` boundaries, and typed formats > 4 bytes execute normally. **Bounds (`OOB_SELECT`):** modes 0, 1 and 2 follow the Buffer bounds checking row with `idx = index`; **`OOB_SELECT 3` with `swz_active` and `stride ≠ 0`** checks **`uint64(index) + uint64(soffset) >= num_records` or `off + payload > stride`** (per-dword for raw `x1..x4`, whole element for typed), while inactive swizzle or `stride = 0` keeps the RAW check `uint64(off) + uint64(soffset) + payload > num_records` (no 32-bit wrap on `off + soffset`, whereas `vaddr + inst_offset` wraps at 32 bits before bounds checking). A literal word1 / word3 (`s_mov_b32` earlier in the block) folds each bit; a run-time V# selects dynamically with `L = swz_u · (3 + INDEX_STRIDE)` (IS = 1 gives the linear address). Until 2026-11-22 the translator added `vindex + lane` when `idxen = 1` and `ADD_TID_ENABLE = 1`, swizzled even when both were 0, stepped all swizzled multi-dword/typed accesses by `4 · IS`, allowed > 4-byte typed/atomic_x2 accesses in scratch-swizzle mode, omitted `soffset` from swizzled mode 3's index check, and wrapped `off + soffset` at 32 bits in RAW mode 3. **How confirmed:** native RDNA2 measurement on `AMD Radeon(TM) Graphics` (gfx1036, Windows driver `32.0.21042.62`, wave32 & wave64) via `tools/buffer_swizzle_probe.py --oracle both` (22/22 cases across 8 groups match bit-exactly, 0 unexpected mismatches, 0 unexpected wave32/64 diffs, 64-thread `ADD_TID_ENABLE` wave-lane wrap verified at both wave sizes); CPU semantic tests `tests/semantic/test_buffer_swizzle.py` (literal and run-time V#, both sub-modes, mode 3 `soffset`, 32-bit wrap, typed/`atomic_x2` suppression, and `cs_buf_swizzle.asm`); `tests/test_buffer_swizzle_probe.py`. **Remaining approximations / unmeasured:** unaligned raw accesses splitting across `+4 · IS` in scratch-swizzle mode (the translator uses `Aligned 4` PSB loads/stores), general typed-format / `buffer_atomic_*_x2` natural alignment suppression (`16_UINT` at odd offsets, `32_*` at non-4B offsets, `atomic_*_x2` at non-8B addresses, observed on gfx1036 in both linear and swizzled modes), and GFX11's two-bit `SWIZZLE_ENABLE` (`word1[31:30]`). SWIZZLE_ENABLE word1 bit 31, STRIDE word1 [29:16], INDEX_STRIDE word3 [22:21] (IS = 8, 16, 32 or 64 indices), ADD_TID_ENABLE word3 bit 23; there is no ELEMENT_SIZE field, the element is fixed at 4 bytes (ISA 8.1.5; LLVM `SIInstrInfo::getScratchRsrcWords23` sets it only up to GFX8). `index` = (idxen ? vindex : 0) + (ADD_TID_ENABLE ? lane : 0), where the lane is thread_id[5:0] within the wave (`Gen.wave_lane`), swizzled or not: table 33 adds the thread id with no swizzle condition and table 36's ring column is linear with add_tid. `offset` = (offen ? vaddr : 0) + inst_offset, without soffset. Swizzled: buffer_offset = (index / IS · stride + offset / 4 · 4) · IS + index % IS · 4 + offset % 4, address = base + soffset + buffer_offset, so dword k of a multi-dword access (and of a typed element over 4 bytes) is 4 · IS bytes after dword k − 1, not 4. Bounds as in Buffer bounds checking, with `idx` = `index` (the lane included), except that OOB_SELECT 3 with SWIZZLE_ENABLE and stride ≠ 0 checks `index >= num_records` or `off + 4k + 4 > stride` (table 35), like mode 0; stride 0 keeps the raw check. A literal word1 / word3 (`s_mov_b32` earlier in the block) folds each bit. A run-time word1 makes IS = 2^(SWIZZLE_ENABLE · (3 + INDEX_STRIDE)): IS = 1 is the linear address, so one formula serves both and nothing is selected but the mode 3 check; a run-time word3 multiplies the lane by ADD_TID_ENABLE. Cost, measured on the 116 shaders of `runtime/test/shaders` that both versions translate (all `spirv-val` clean before and after): the 56 with a MUBUF access through a run-time V# grow by 15.1 % in SPIR-V lines (+10.4 % over all 116), 30 to 45 instructions per access (address, lane, 4 per extra dword, a select per dword of the bounds check); a literal linear V# gives the same SPIR-V as before. Outside compute and mesh shaders the lane is `SubgroupLocalInvocationId`, so a VS, PS or GS with a run-time V# now declares `GroupNonUniform`. The offset arithmetic is 32-bit, like the linear address. Until 2026-11-22 a literal V# with either bit was `Unsupported` and a run-time one was translated unswizzled. **How confirmed**: Mesa/LLVM and AMD's ISA reference (fields and formula), not measured on hardware; `tests/semantic/test_buffer_swizzle.py` (hand-worked addresses for IS 8/16/64, index msb/lsb, soffset after the swizzle, the mode 3 rule with and without a stride, per-dword x2/x3/x4 loads and stores, a 16-byte typed element, ADD_TID on lane 5 linear and swizzled, each with a literal and a run-time V#); GPU test `runtime/test/shaders/cs_buf_swizzle.asm` (check.py, `scripts/run_gpu_tests.py`), which checks the translation, not RDNA2. **Unmeasured**: the swizzled layout on RDNA2 hardware, offsets that are not dword aligned (the ISA requires alignment for swizzled accesses; the translation adds offset % 4), wrap of the 32-bit offset, and GFX11's two-bit SWIZZLE_ENABLE (word1 [31:30]). **Unmeasured** (the layout itself is measured: `docs/shader_validation.md`, SHADER-343, gfx1036, 22 of 22 cases bit-exact): offsets that are not dword aligned (the ISA requires alignment for swizzled accesses; the translation adds offset % 4), wrap of the 32-bit offset, and GFX11's two-bit SWIZZLE_ENABLE (word1 [31:30]). In the corpus `SCRATCH_EN` is 0 in every CS, so a swizzled V# can only come from a descriptor the game writes itself. | | 541 | | Swizzled buffer addressing (V# SWIZZLE_ENABLE, ADD_TID_ENABLE) | MUBUF/MTBUF `buffer_load*`, `buffer_store*`, `buffer_atomic*`, `buffer_load_format_*`/`buffer_store_format_*` and `tbuffer_load/store_format_*` follow the rules measured natively on RDNA2 (`AMD Radeon(TM) Graphics`, gfx1036, Windows driver `32.0.21042.62`, wave32 and wave64; `tools/buffer_swizzle_probe.py`, SHADER-343). MUBUF/MTBUF `buffer_load*`, `buffer_store*`, `buffer_atomic*`, `buffer_load_format_*`/`buffer_store_format_*` and `tbuffer_load_format_*` follow the RDNA2 ISA ("RDNA 2" Instruction Set Architecture, 8.1.5 Buffer Addressing, "Swizzled Buffer Addressing" and tables 33, 35 and 37). Fields, Mesa 24.0.6 `src/amd/registers/gfx10-rsrc.json` (`SQ_BUF_RSRC_WORD1`, `SQ_BUF_RSRC_WORD3` and its `_gfx103` twin, the same bits): `SWIZZLE_ENABLE` word1 bit 31, `STRIDE` word1 `[29:16]`, `INDEX_STRIDE` word3 `[22:21]` (`IS = 8 << n`, i.e., 8, 16, 32 or 64), `ADD_TID_ENABLE` word3 bit 23; element size is fixed at 4 bytes (`word3[20:19]` and `word1[30]` do not alter addressing or stepping). **Effective index:** `index = idxen ? vindex : 0)`, where `lane` is the wave lane (`thread_id[5:0]` within the wave, wrapping at 32 in wave32 and 64 in wave64; `Gen.wave_lane`); **`idxen = 1` completely ignores `ADD_TID_ENABLE`** (linear or swizzled, address and bounds, loads/stores/typed/atomics). **Activation:** `SWIZZLE_ENABLE` activates (`swz_active`) only when `idxen = 1` or `ADD_TID_ENABLE = 1`; with neither, addressing is linear (`base + soffset + off`) and `OOB_SELECT 3` stays RAW even when `stride ≠ 0`. **Address formula (when `swz_active`):** `off = uint32((offen ? vaddr : 0) + inst_offset)` (32-bit wrap), `buffer_offset = (index / IS · stride + (off & ~3)) · IS + (index % IS) · 4 + (off & 3)`, `address = base + soffset + buffer_offset` (confirmed byte-exact for IS 8/16/32/64, non-4-multiple strides, stride 0, and unaligned offsets). **Two swizzle sub-modes:** (1) **Scratch swizzle** (`SWIZZLE_ENABLE = 1`, `idxen = 0`, `ADD_TID_ENABLE = 1`): raw multi-dword `buffer_load/store_dwordx2..x4` step by **`+4 · IS`** bytes per dword (and unaligned 4-byte raw accesses crossing a dword boundary split across `+4 · IS` on hardware), while **typed formats > 4 bytes** (8/12/16-byte MUBUF and MTBUF loads/stores, regardless of component count) and **8-byte `buffer_atomic_*_x2`** are **suppressed** (loads return 0, stores/atomics are no-ops, even in `OOB_SELECT 2`); typed formats ≤ 4 bytes work normally. (2) **Indexed swizzle** (`SWIZZLE_ENABLE = 1`, `idxen = 1`, regardless of `ADD_TID_ENABLE`): raw `x2..x4`, typed formats (8/12/16 bytes), and `buffer_atomic_*_x2` step **linearly by `+4` bytes** from the swizzled base address, even across `IS` boundaries, and typed formats > 4 bytes execute normally. **Bounds (`OOB_SELECT`):** modes 0, 1 and 2 follow the Buffer bounds checking row with `idx = index`; **`OOB_SELECT 3` with `swz_active` and `stride ≠ 0`** checks **`uint64(index) + uint64(soffset) >= num_records` or `off + payload > stride`** (per-dword for raw `x1..x4`, whole element for typed), while inactive swizzle or `stride = 0` keeps the RAW check `uint64(off) + uint64(soffset) + payload > num_records` (no 32-bit wrap on `off + soffset`, whereas `vaddr + inst_offset` wraps at 32 bits before bounds checking). A literal word1 / word3 (`s_mov_b32` earlier in the block) folds each bit; a run-time V# selects dynamically with `L = swz_u · (3 + INDEX_STRIDE)` (IS = 1 gives the linear address). Until 2026-11-22 the translator added `vindex + lane` when `idxen = 1` and `ADD_TID_ENABLE = 1`, swizzled even when both were 0, stepped all swizzled multi-dword/typed accesses by `4 · IS`, allowed > 4-byte typed/atomic_x2 accesses in scratch-swizzle mode, omitted `soffset` from swizzled mode 3's index check, and wrapped `off + soffset` at 32 bits in RAW mode 3. **How confirmed:** native RDNA2 measurement on `AMD Radeon(TM) Graphics` (gfx1036, Windows driver `32.0.21042.62`, wave32 & wave64) via `tools/buffer_swizzle_probe.py --oracle both` (22/22 cases across 8 groups match bit-exactly, 0 unexpected mismatches, 0 unexpected wave32/64 diffs, 64-thread `ADD_TID_ENABLE` wave-lane wrap verified at both wave sizes); CPU semantic tests `tests/semantic/test_buffer_swizzle.py` (literal and run-time V#, both sub-modes, mode 3 `soffset`, 32-bit wrap, typed/`atomic_x2` suppression, and `cs_buf_swizzle.asm`); `tests/test_buffer_swizzle_probe.py`. **Remaining approximations / unmeasured:** unaligned raw accesses splitting across `+4 · IS` in scratch-swizzle mode (the translator uses `Aligned 4` PSB loads/stores), general typed-format / `buffer_atomic_*_x2` natural alignment suppression (`16_UINT` at odd offsets, `32_*` at non-4B offsets, `atomic_*_x2` at non-8B addresses, observed on gfx1036 in both linear and swizzled modes), and GFX11's two-bit `SWIZZLE_ENABLE` (`word1[31:30]`). SWIZZLE_ENABLE word1 bit 31, STRIDE word1 [29:16], INDEX_STRIDE word3 [22:21] (IS = 8, 16, 32 or 64 indices), ADD_TID_ENABLE word3 bit 23; there is no ELEMENT_SIZE field, the element is fixed at 4 bytes (ISA 8.1.5; LLVM `SIInstrInfo::getScratchRsrcWords23` sets it only up to GFX8). `index` = (idxen ? vindex : 0) + (ADD_TID_ENABLE ? lane : 0), where the lane is thread_id[5:0] within the wave (`Gen.wave_lane`), swizzled or not: table 33 adds the thread id with no swizzle condition and table 36's ring column is linear with add_tid. `offset` = (offen ? vaddr : 0) + inst_offset, without soffset. Swizzled: buffer_offset = (index / IS · stride + offset / 4 · 4) · IS + index % IS · 4 + offset % 4, address = base + soffset + buffer_offset, so dword k of a multi-dword access (and of a typed element over 4 bytes) is 4 · IS bytes after dword k − 1, not 4. Bounds as in Buffer bounds checking, with `idx` = `index` (the lane included), except that OOB_SELECT 3 with SWIZZLE_ENABLE and stride ≠ 0 checks `index >= num_records` or `off + 4k + 4 > stride` (table 35), like mode 0; stride 0 keeps the raw check. A literal word1 / word3 (`s_mov_b32` earlier in the block) folds each bit. A run-time word1 makes IS = 2^(SWIZZLE_ENABLE · (3 + INDEX_STRIDE)): IS = 1 is the linear address, so one formula serves both and nothing is selected but the mode 3 check; a run-time word3 multiplies the lane by ADD_TID_ENABLE. Cost, measured on the 116 shaders of `runtime/test/shaders` that both versions translate (all `spirv-val` clean before and after): the 56 with a MUBUF access through a run-time V# grow by 15.1 % in SPIR-V lines (+10.4 % over all 116), 30 to 45 instructions per access (address, lane, 4 per extra dword, a select per dword of the bounds check); a literal linear V# gives the same SPIR-V as before. Outside compute and mesh shaders the lane is `SubgroupLocalInvocationId`, so a VS, PS or GS with a run-time V# now declares `GroupNonUniform`. The offset arithmetic is 32-bit, like the linear address. Until 2026-11-22 a literal V# with either bit was `Unsupported` and a run-time one was translated unswizzled. **How confirmed**: Mesa/LLVM and AMD's ISA reference (fields and formula), not measured on hardware; `tests/semantic/test_buffer_swizzle.py` (hand-worked addresses for IS 8/16/64, index msb/lsb, soffset after the swizzle, the mode 3 rule with and without a stride, per-dword x2/x3/x4 loads and stores, a 16-byte typed element, ADD_TID on lane 5 linear and swizzled, each with a literal and a run-time V#); GPU test `runtime/test/shaders/cs_buf_swizzle.asm` (check.py, `scripts/run_gpu_tests.py`), which checks the translation, not RDNA2. **Unmeasured**: the swizzled layout on RDNA2 hardware, offsets that are not dword aligned (the ISA requires alignment for swizzled accesses; the translation adds offset % 4), wrap of the 32-bit offset, and GFX11's two-bit SWIZZLE_ENABLE (word1 [31:30]). **Unmeasured** (the layout itself is measured: `docs/shader_validation.md`, SHADER-343, gfx1036, 22 of 22 cases bit-exact): offsets that are not dword aligned (the ISA requires alignment for swizzled accesses; the translation adds offset % 4), wrap of the 32-bit offset, and GFX11's two-bit SWIZZLE_ENABLE (word1 [31:30]). In the corpus `SCRATCH_EN` is 0 in every CS, so a swizzled V# can only come from a descriptor the game writes itself. | |
| 524 | | `v_permlane16_b32` / `v_permlanex16_b32` with the source lane off in EXEC (SHADER-74) | The VOP3 modifier `op_sel:[FI, BOUND_CTRL]` decides what a lane gets when the lane it reads is off in EXEC. **FI=1** (`op_sel` bit 0, encoding 0x0800): the source lane's value, as before. **FI=0** (the default): the destination lane is not written and keeps its old value when BOUND_CTRL=0, and gets 0 when BOUND_CTRL=1 (`op_sel` bit 1, 0x1000). A source lane that is on gives its value whatever FI / BOUND_CTRL are, and a lane that is itself off is never written (normal EXEC rule). The translator shuffles the active bit with the same selector as the value (also in `--wave64-emulate`, where it is a second exchange). On a native subgroup the two shuffles are combined with bitwise masks, not a scalar select: absent source lanes are redirected to the calling lane first (as `ds_lane_read`), the value and the activity bit are fetched through the redirected index, and `ok` masks the shuffled value over the old one (over zero with BOUND_CTRL=1) and the destination write is masked too, so the ballot and both shuffles run before lane predication — MoltenVK 1.4.2 and MoltenVK main at SPIRV-Cross aa217aeb lowered the scalar select to a short-circuiting Metal ternary and the FI=0 lanes read the source lane's value instead, which `cs_w32_permlane_fi` caught on an Apple M1 Max (#5895); `v_permlanex16_b32` pairs the rows 0↔1 and 2↔3 of a wave64 as before. Until SHADER-74 every case returned the source value (right only for FI=1). Source of the bit mapping: LLVM `llvm.amdgcn.permlane16/permlanex16 <old> <src0> <src1> <src2> <fi> <bound_control>` (IntrinsicsAMDGPU.td) is selected in `VOP3Instructions.td` (`PermlanePat`) with `fi` as the `src0` op_sel bit and `bound_control` as the `src1` one, and the CodeGen tests `llvm.amdgcn.permlane.ll` print `op_sel:[1,0]` for FI and `op_sel:[0,1]` for BOUND_CTRL; `llvm-mc -mcpu=gfx1013` encodes `op_sel:[1,0]` as 0x0800 and `op_sel:[0,1]` as 0x1000 in the second byte pair of the first word (0xD777 / 0xD778). Behaviour: hardware measurement on RDNA2 (Ryzen 7950X3D iGPU, raw kernel, wave64 and wave32 consistent; the same on RDNA3.5) by aslan2142 in [#374](https://github.com/ItsNotRexed/Leonida/issues/374#issuecomment-7071597516). Pinned by `runtime/test/shaders/cs_w32_permlane_fi.asm` (EXEC 0x55555555, every active lane's source is off; out[0..7] = 1000 0 4 1 1000 0 52 49) in `check.py` and `scripts/run_gpu_tests.py`, and on the CPU by `tests/semantic/test_permlane_fi.py`. | | 542 | | `v_permlane16_b32` / `v_permlanex16_b32` with the source lane off in EXEC (SHADER-74) | The VOP3 modifier `op_sel:[FI, BOUND_CTRL]` decides what a lane gets when the lane it reads is off in EXEC. **FI=1** (`op_sel` bit 0, encoding 0x0800): the source lane's value, as before. **FI=0** (the default): the destination lane is not written and keeps its old value when BOUND_CTRL=0, and gets 0 when BOUND_CTRL=1 (`op_sel` bit 1, 0x1000). A source lane that is on gives its value whatever FI / BOUND_CTRL are, and a lane that is itself off is never written (normal EXEC rule). The translator shuffles the active bit with the same selector as the value (also in `--wave64-emulate`, where it is a second exchange). On a native subgroup the two shuffles are combined with bitwise masks, not a scalar select: absent source lanes are redirected to the calling lane first (as `ds_lane_read`), the value and the activity bit are fetched through the redirected index, and `ok` masks the shuffled value over the old one (over zero with BOUND_CTRL=1) and the destination write is masked too, so the ballot and both shuffles run before lane predication — MoltenVK 1.4.2 and MoltenVK main at SPIRV-Cross aa217aeb lowered the scalar select to a short-circuiting Metal ternary and the FI=0 lanes read the source lane's value instead, which `cs_w32_permlane_fi` caught on an Apple M1 Max (#5895); `v_permlanex16_b32` pairs the rows 0↔1 and 2↔3 of a wave64 as before. Until SHADER-74 every case returned the source value (right only for FI=1). Source of the bit mapping: LLVM `llvm.amdgcn.permlane16/permlanex16 <old> <src0> <src1> <src2> <fi> <bound_control>` (IntrinsicsAMDGPU.td) is selected in `VOP3Instructions.td` (`PermlanePat`) with `fi` as the `src0` op_sel bit and `bound_control` as the `src1` one, and the CodeGen tests `llvm.amdgcn.permlane.ll` print `op_sel:[1,0]` for FI and `op_sel:[0,1]` for BOUND_CTRL; `llvm-mc -mcpu=gfx1013` encodes `op_sel:[1,0]` as 0x0800 and `op_sel:[0,1]` as 0x1000 in the second byte pair of the first word (0xD777 / 0xD778). Behaviour: hardware measurement on RDNA2 (Ryzen 7950X3D iGPU, raw kernel, wave64 and wave32 consistent; the same on RDNA3.5) by aslan2142 in [#374](https://github.com/ItsNotRexed/Leonida/issues/374#issuecomment-7071597516). Pinned by `runtime/test/shaders/cs_w32_permlane_fi.asm` (EXEC 0x55555555, every active lane's source is off; out[0..7] = 1000 0 4 1 1000 0 52 49) in `check.py` and `scripts/run_gpu_tests.py`, and on the CPU by `tests/semantic/test_permlane_fi.py`. | |
diff --git a/docs/first_light.md b/docs/first_light.md index 9eaff8f37..c3cb2bf1d 100644 --- a/docs/first_light.md +++ b/docs/first_light.md | |||
| @@ -70,9 +70,7 @@ python -I tools/first_light.py --check --out ~/leonida-work/first_light/out | |||
| 70 | 70 | ||
| 71 | `--check` on an existing folder re-runs the harness through the same fresh path and `check_image` as the test; a | 71 | `--check` on an existing folder re-runs the harness through the same fresh path and `check_image` as the test; a |
| 72 | harness that exits 0 without writing, an all-opaque image and a swapped-U/V image all exit 1. The test has | 72 | harness that exits 0 without writing, an all-opaque image and a swapped-U/V image all exit 1. The test has |
| 73 | twenty-five cases: the two package-gated draw/manifest checks, the `--check` command, four oracle fixtures, the | 73 | 48 cases; `python -I tests/test_first_light.py -v` prints each one. |
| 74 | mesh depth fit, a preview with non-finite readback channels, the stage files of two shaders with the same name, two | ||
| 75 | OBJ parsing checks, seven checks of the textured path (section 6) and six CPU checks of `--camera` (section 7). | ||
| 76 | 74 | ||
| 77 | `first_light.py` carves `shaders.rpf` if the work folder does not have it, translates only the chosen pair, converts | 75 | `first_light.py` carves `shaders.rpf` if the work folder does not have it, translates only the chosen pair, converts |
| 78 | the OBJ to the harness's mesh file (`u32 vertex_count, u32 index_count`, `(x,y,z,u,v) f32` vertices, `u32` | 76 | the OBJ to the harness's mesh file (`u32 vertex_count, u32 index_count`, `(x,y,z,u,v) f32` vertices, `u32` |
| @@ -140,10 +138,10 @@ The CPU oracle (`check_image`) samples the decoded `R8G8B8A8_UNORM` texture bili | |||
| 140 | `centre_uv` and each `uv_probes` entry and requires the GPU readback to match within `0.02` (rejecting the | 138 | `centre_uv` and each `uv_probes` entry and requires the GPU readback to match within `0.02` (rejecting the |
| 141 | magenta unbound-texture fallback and wrong-colour probes). Verified on Windows 11 with an NVIDIA GeForce RTX 3060 | 139 | magenta unbound-texture fallback and wrong-colour probes). Verified on Windows 11 with an NVIDIA GeForce RTX 3060 |
| 142 | (driver 621.24, Vulkan 1.4.357): **12,804/16,384 (0.781)** covered. Without `LEONIDA_FIRST_LIGHT_DIR`, | 140 | (driver 621.24, Vulkan 1.4.357): **12,804/16,384 (0.781)** covered. Without `LEONIDA_FIRST_LIGHT_DIR`, |
| 143 | `python -I tests/test_first_light.py -v` runs **46 tests: 42 passed, 4 skipped** (the 3 package-gated | 141 | `python -I tests/test_first_light.py -v` runs **48 tests: 44 passed, 4 skipped** (the 3 package-gated |
| 144 | `FirstLightTests` require `LEONIDA_FIRST_LIGHT_DIR`, and `test_harness_rejects_wrapped_tsharp_va_overflow` needs a | 142 | `FirstLightTests` require `LEONIDA_FIRST_LIGHT_DIR`, and `test_harness_rejects_wrapped_tsharp_va_overflow` needs a |
| 145 | built `vk_harness`; the 4 `OracleTests` and the other 11 `TexturedOracleTests` run without a package). With | 143 | built `vk_harness`; the 4 `OracleTests` and the other 11 `TexturedOracleTests` run without a package). With |
| 146 | `LEONIDA_FIRST_LIGHT_DIR` set against a local package run (and `vk_harness` built) none of the 46 is skipped. | 144 | `LEONIDA_FIRST_LIGHT_DIR` set against a local package run (and `vk_harness` built) none of the 48 is skipped. |
| 147 | 145 | ||
| 148 | ```sh | 146 | ```sh |
| 149 | python -I tools/first_light.py --game "<package>" --work ~/leonida-work \ | 147 | python -I tools/first_light.py --game "<package>" --work ~/leonida-work \ |
diff --git a/docs/first_run_ui.md b/docs/first_run_ui.md index d7b2fe5e5..66b147ddb 100644 --- a/docs/first_run_ui.md +++ b/docs/first_run_ui.md | |||
| @@ -30,7 +30,7 @@ Run the title offline. The Winsock shim permits loopback and the WinHTTP shim re | |||
| 30 | & (Join-Path $port 'gta6rt.exe') --first-run-ui (Join-Path $game 'game_scarlett_master.exe') | 30 | & (Join-Path $port 'gta6rt.exe') --first-run-ui (Join-Path $game 'game_scarlett_master.exe') |
| 31 | ``` | 31 | ``` |
| 32 | 32 | ||
| 33 | The profile selects Vulkan, a 2 GiB graphics address arena, on-demand pipelines, console root-argument layout, GPU completion labels, frame pacing and the keyboard gamepad. Explicit environment settings take precedence; a variable that is set but empty does not count. Speech synthesis through the host's own runtime is not part of the profile: `LEONIDA_LOCAL_SPEECH=1` turns it on, and without it the silent voice answers. The switches are listed in [`runtime/README.md`](../runtime/README.md). The package directory is the working directory. Guest output goes under `first-run-ui/overlay` beside the runtime, and sparse physical-memory backing uses `first-run-ui/xmem` on that volume. Use `--overlay DIR` or the absolute directory in `LEONIDA_XMEM_BACKING_DIR` to choose other writable locations. | 33 | The profile selects Vulkan, a 2 GiB graphics address arena, on-demand pipelines, console root-argument layout, frame pacing and the keyboard gamepad in its focused mode (`LEONIDA_KEYBOARD_PAD=1`: keys count only while the title window has focus, so typing into another program presses nothing on a consent page; scripted presses still run). GPU completion labels (`LEONIDA_GPU_LABELS`) are not part of it: the list values land the title's list writes, and two writers of one address could rewind a counter. Explicit environment settings take precedence; a variable that is set but empty does not count. Speech synthesis through the host's own runtime is not part of the profile: `LEONIDA_LOCAL_SPEECH=1` turns it on, and without it the silent voice answers. The switches are listed in [`runtime/README.md`](../runtime/README.md). The package directory is the working directory. Guest output goes under `first-run-ui/overlay` beside the runtime, and sparse physical-memory backing uses `first-run-ui/xmem` on that volume. Use `--overlay DIR` or the absolute directory in `LEONIDA_XMEM_BACKING_DIR` to choose other writable locations. |
| 34 | 34 | ||
| 35 | ## Contributions | 35 | ## Contributions |
| 36 | 36 | ||
diff --git a/docs/fspx.md b/docs/fspx.md index 6fa4a4c8d..a959423e4 100644 --- a/docs/fspx.md +++ b/docs/fspx.md | |||
| @@ -276,12 +276,92 @@ title calls device slot 57 (`+0x1c8`) with `IID_ID3D12PipelineState` (`{765a30f3 | |||
| 276 | - `state blob`: `+0x000` version tag (`0x4005d800` in 15,632 records, `0x4005d808` in 9,159, `0x4005d810` in 6), | 276 | - `state blob`: `+0x000` version tag (`0x4005d800` in 15,632 records, `0x4005d808` in 9,159, `0x4005d810` in 6), |
| 277 | `+0x004` family (`4` in 12,735 or `6` in 12,062), `+0x02c = 2`, `+0x07c` (`0xcc0010` / `0` / `0xcc0011`), | 277 | `+0x004` family (`4` in 12,735 or `6` in 12,062), `+0x02c = 2`, `+0x07c` (`0xcc0010` / `0` / `0xcc0011`), |
| 278 | `+0x0f4 = 5`, `+0x0f8 = 1`, `+0x0fc = 0x33333333` (`0.1f`), `+0x100..+0x11c` (`0x00060006` x8), `+0x150 = 0x40`, | 278 | `+0x0f4 = 5`, `+0x0f8 = 1`, `+0x0fc = 0x33333333` (`0.1f`), `+0x100..+0x11c` (`0x00060006` x8), `+0x150 = 0x40`, |
| 279 | `+0x158 = 0xffffffff`, `+0x17c = 0x10000a00`. Unidentified offsets are logged once per offset while safe default | 279 | `+0x158 = 0xffffffff`, `+0x17c = 0x10000a00`. The colour-target, depth, stencil and raster registers are decoded |
| 280 | raster/depth/blend state is used. | 280 | (next paragraphs); depth bias is not. |
| 281 | - `stage blob`: `+0x00 = 2` (graphics stage blob), `+0x04` payload size (`196` in 208 B blobs), `+0x08 = 0x66`, | 281 | - `stage blob`: `+0x00 = 2` (graphics stage blob), `+0x04` payload size (`196` in 208 B blobs), `+0x08 = 0x66`, |
| 282 | `+0x0c = 0x40 | flags`, followed by records `0x41` (32 B input/output signature), `0x42` (32 B output signature) | 282 | `+0x0c = 0x40 | flags`, followed by records `0x41` (32 B input/output signature), `0x42` (32 B output signature) |
| 283 | and `0x43` (20 B: tag + 16 B opaque digest). | 283 | and `0x43` (20 B: tag + 16 B opaque digest). |
| 284 | 284 | ||
| 285 | **State blob A: the colour-target registers (RT-SLOT57-BLEND-STATE).** Blob A is the console driver's serialized | ||
| 286 | pipeline state, and its shared block holds context register values in the RDNA2 layout (Mesa's gfx10 register | ||
| 287 | headers). Measured on 1.0.2.1 over all 5,680 distinct blobs, which the 25,471 graphics records reference: | ||
| 288 | |||
| 289 | - **Shape:** 380 + 8k bytes (k = 0..5) for vertex-shader pipelines, and 464 + 8k (k = 0..7) for mesh pipelines. The | ||
| 290 | mesh pipelines' stage block is 84 bytes longer, so every offset after `+0x28` moves by 84 there; the offsets below | ||
| 291 | are the vertex ones. Word 0 is `0x4005d800` with bits 3 and 4 free in all 25,471 records. | ||
| 292 | - **`+0x78` `CB_TARGET_MASK`:** four component bits (R, G, B, A, as in `D3D12_COLOR_WRITE_ENABLE`) per target: | ||
| 293 | `0xf` in 16,650 records, `0xff` in 2,805, `0xffffff` in 2,561. In 17,626 records the targets it enables are exactly | ||
| 294 | `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 | ||
| 295 | pipelines below. The others leave a target with a format unwritten. | ||
| 296 | - **`+0x7c` `CB_COLOR_CONTROL`:** ROP3 `0xcc` (copy) in every record, so no logic op. | ||
| 297 | - **`+0xd0..+0xec` `CB_BLEND0..7_CONTROL`:** one word per target. There are 34 distinct values, every one an | ||
| 298 | in-range RDNA2 blend: factors 0 to 20 with neither `BOTH_*` value, `COMB_FCN` 0 to 4, `SEPARATE_ALPHA_BLEND` set | ||
| 299 | wherever `ENABLE` is, and `DISABLE_ROP3` set in all. By target 0: `0x80000000` (blending off) in 15,373 records, | ||
| 300 | `0xe5010504` (colour `SRC_ALPHA`/`INV_SRC_ALPHA`, alpha `ONE`/`INV_SRC_ALPHA`) in 3,456, `0xf1010f01` (colour | ||
| 301 | `ONE`/`SRC1_COLOR`, alpha `ONE`/`SRC1_ALPHA`) in 1,931, and `0xe5040504` in 1,387. 10,135 records blend on at least | ||
| 302 | one of their targets. | ||
| 303 | - **`+0x100..+0x11c`:** eight more per-target words that follow `CB_BLENDn` (`0x06000600` where blending is off). | ||
| 304 | They fit `SX_MRTn_BLEND_OPT`, whose `COMB_FCN` 6 is "blend disabled". They aren't read. | ||
| 305 | |||
| 306 | `runtime/src/native_pso.h` (`decode_state_a_blend`, `d3d12_blend`) maps each target's `CB_BLENDn_CONTROL` and | ||
| 307 | `CB_TARGET_MASK` nibble to a `D3D12_RENDER_TARGET_BLEND_DESC`, and `fill_blend_state` in | ||
| 308 | `runtime/shims/d3d12_xs_native_pso.h` uses it for every native PSO: | ||
| 309 | |||
| 310 | - **Before:** every target had blending off and wrote every component, so the first-run pages after #939 drew glyph | ||
| 311 | quads solid, artwork hard-edged and composited backgrounds black. | ||
| 312 | - **With the decoded state:** the pages, the legal screens and the loading slideshow draw as on console (RTX 4070 | ||
| 313 | Laptop). | ||
| 314 | - **Integer targets:** a target with a `UINT` or `SINT` format never blends, as the colour block bypasses blending | ||
| 315 | there and D3D12 refuses a PSO that asks for it. One library pipeline enables `MAX` on an `R8_UINT` target beside | ||
| 316 | two others. | ||
| 317 | - **Stand-in targets:** where `B4G4R4A4_UNORM` is not renderable, the Vulkan layer draws it into an RGBA8 stand-in | ||
| 318 | and refuses blending there (`E_NOTIMPL`, the output is quantized before it). The factory then retries the pipeline | ||
| 319 | with blending off on those targets only (`shims/d3d12_xs_native_pso_fallback.h`), instead of leaving it to the PC | ||
| 320 | description path. On an RTX 4070 Laptop that is the same library pipeline (the first one the title creates). Only a | ||
| 321 | pipeline that blends a `B4G4R4A4` target is retried: `E_NOTIMPL` also stands for refusals unrelated to blending (a | ||
| 322 | rect list without its geometry stage, mesh limits, `FullyCovered`, a dual-source output that does not fit | ||
| 323 | `Location 0, Index 1`), and those keep the blend the title asked for. | ||
| 324 | - **Dual-source:** the 1,937 records that blend with `SRC1` factors get them as `D3D12_BLEND_SRC1_*`. The Vulkan | ||
| 325 | layer then moves the pixel shader's `SV_Target1` from `Location 1` to `Location 0, Index 1` | ||
| 326 | (`runtime/src/dual_source_fragment.h`, RT-DUAL-SOURCE-BLEND). | ||
| 327 | - **Kept on the defaults:** a blob of another shape, or a target with a factor or function this path does not take, | ||
| 328 | keeps the whole pipeline on the defaults and is logged. | ||
| 329 | |||
| 330 | **State blob A: the depth, stencil and raster registers (RT-SLOT57-DEPTH-RASTER).** The same shared block, at the | ||
| 331 | same vertex-pipeline offsets (+84 in mesh pipelines). The register layouts and their checks against blob B are below, | ||
| 332 | measured over all 25,471 graphics records: | ||
| 333 | |||
| 334 | - **`+0x9c` `PA_CL_CLIP_CNTL`:** `DX_CLIP_SPACE_DEF` set in every record. Both z clips are off in 960 records and on | ||
| 335 | in the rest, so the near and far planes always agree. | ||
| 336 | - **`+0xa0` `PA_SU_SC_MODE_CNTL`:** no culling in 13,534 records, back faces in 11,873 and front faces in 62. | ||
| 337 | `FACE` (clockwise is front) is clear in all but 2, `POLY_MODE` is 0 in all, and the polygon-offset enables are set | ||
| 338 | in all. | ||
| 339 | - **`+0xb8` `DB_DEPTH_CONTROL`:** | ||
| 340 | - with no DSV in blob B, `Z_ENABLE` is clear in 7,040 of 7,079 records; | ||
| 341 | - `STENCIL_ENABLE` is set only with formats that have stencil; | ||
| 342 | - `DEPTH_BOUNDS_ENABLE` and bits 30-31 are clear in all; | ||
| 343 | - `BACKFACE_ENABLE` is set in all; | ||
| 344 | - the test is off (`0x007007f0`) in 9,062 records, otherwise mostly `GEQUAL` (a reversed depth range), with `LESS`, | ||
| 345 | `LEQUAL`, `EQUAL` and `NOTEQUAL` in some. | ||
| 346 | - **`+0xbc` `DB_STENCIL_CONTROL`:** nonzero in 5,512 of the 6,213 records with stencil on, and in 2 without. The ops | ||
| 347 | used are `KEEP`, `REPLACE_TEST`, `ADD_WRAP`, `ZERO` and `INVERT`. | ||
| 348 | - **`+0xc0`/`+0xc4` `DB_STENCILREFMASK(_BF)`:** the two faces have the same read and write masks in every stencil | ||
| 349 | record, and `STENCILOPVAL` is 1 in all. `STENCILTESTVAL` (bits 7:0, the reference) is 0 in all 6,213 stencil records, front and | ||
| 350 | 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. | ||
| 351 | |||
| 352 | `runtime/src/native_pso.h` (`decode_state_a_depth_raster`, `d3d12_depth_raster`) maps them to | ||
| 353 | `D3D12_DEPTH_STENCIL_DESC` and the cull, front-face and depth-clip fields of `D3D12_RASTERIZER_DESC`, and | ||
| 354 | `fill_depth_raster_state` in `runtime/shims/d3d12_xs_native_pso.h` uses them for every native PSO: | ||
| 355 | |||
| 356 | - **Before:** depth `ALWAYS` with writes wherever there was a DSV, no stencil, no culling and depth clip on. | ||
| 357 | - **With the decoded state:** every one of the 25,471 records maps. A pipeline without a DSV keeps depth and stencil | ||
| 358 | off. | ||
| 359 | - **Not decoded:** depth bias (`PA_SU_POLY_OFFSET_*`). Its D3D12 units depend on the depth format, so it stays 0. | ||
| 360 | The polygon-offset enables in `PA_SU_SC_MODE_CNTL` are set in all 25,471 records. The values look like the floats at | ||
| 361 | `+0xac`/`+0xb0` (scale and offset), which are both 0 in 23,987 records and nonzero in about 1,480. | ||
| 362 | - **Front face:** `FACE` is the only field whose effect can't be seen before a world frame. It maps to | ||
| 363 | `FrontCounterClockwise = !FACE`, as RADV and PAL program it. | ||
| 364 | |||
| 285 | ## Translation status | 365 | ## Translation status |
| 286 | 366 | ||
| 287 | In wave64, VALU compares and carry outputs write both predicate words. Conditional selects and carry inputs | 367 | In wave64, VALU compares and carry outputs write both predicate words. Conditional selects and carry inputs |
diff --git a/docs/gamedata.md b/docs/gamedata.md index a05fd1ea5..bcaa55f4d 100644 --- a/docs/gamedata.md +++ b/docs/gamedata.md | |||
| @@ -1416,7 +1416,8 @@ bounded by the largest field. The generic conversion follows the parser's own co | |||
| 1416 | - `x/y/z/w` is a vector tuple. | 1416 | - `x/y/z/w` is a vector tuple. |
| 1417 | - `content=` is the array body. `short_array`, `float_array` and `float16_array` give number lists; | 1417 | - `content=` is the array body. `short_array`, `float_array` and `float16_array` give number lists; |
| 1418 | `vector2_array`, `vec3v_array`, `matrix33` and `matrix34` give tuples. | 1418 | `vector2_array`, `vec3v_array`, `matrix33` and `matrix34` give tuples. |
| 1419 | - `type="Class"` is a polymorphic object `{"$type": ...}`, and `type="NULL"` is `None`. | 1419 | - `type="Class"` is a polymorphic object `{"$type": ...}`, including an empty object with no fields or text. |
| 1420 | Explicit scalar/vector/array/reference conventions and nonempty text keep their values; `type="NULL"` is `None`. | ||
| 1420 | - `ref=` is `{"$ref": ...}`. | 1421 | - `ref=` is `{"$ref": ...}`. |
| 1421 | - All-`Item` children are a list, or a dict when every one carries `key=`. A repeated tag is a list. A text-only | 1422 | - All-`Item` children are a list, or a dict when every one carries `key=`. A repeated tag is a list. A text-only |
| 1422 | element is its text. Any other attribute is kept as `"@name"`. | 1423 | element is its text. Any other attribute is kept as `"@name"`. |
| @@ -1440,11 +1441,13 @@ On the 1.0.2.1 carve of `common.rpf` the run takes about 5 s, with 0 conversion | |||
| 1440 | | arrays | 13,449 | | 1441 | | arrays | 13,449 | |
| 1441 | | lists | 13,465 | | 1442 | | lists | 13,465 | |
| 1442 | | keyed maps | 526 | | 1443 | | keyed maps | 526 | |
| 1443 | | polymorphic objects | 6,490 (317 `type` classes over 6,903 typed elements) | | 1444 | | polymorphic objects | 6,663 (317 `type` classes over 6,903 typed elements) | |
| 1444 | | `NULL` pointers | 278 | | 1445 | | `NULL` pointers | 278 | |
| 1445 | | references | 924 | | 1446 | | references | 924 | |
| 1446 | | elements with extra attributes | 5,262 | | 1447 | | elements with extra attributes | 5,262 | |
| 1447 | 1448 | ||
| 1449 | The object count includes 173 empty instances across 13 documents (54 types). | ||
| 1450 | |||
| 1448 | The 7 roots missing from the 118 occur only in documents that are not well-formed. Counts only: the JSON that | 1451 | The 7 roots missing from the 118 occur only in documents that are not well-formed. Counts only: the JSON that |
| 1449 | `--out` writes is the game's data and stays local. `tests/test_gamedata_reader.py` checks every convention, | 1452 | `--out` writes is the game's data and stays local. `tests/test_gamedata_reader.py` checks every convention, |
| 1450 | both dispatch tables, that streaming equals a whole-tree conversion, and the CLI, on synthetic XML. | 1453 | both dispatch tables, that streaming equals a whole-tree conversion, and the CLI, on synthetic XML. |
diff --git a/docs/gameinput.md b/docs/gameinput.md index feed39153..1301a4a49 100644 --- a/docs/gameinput.md +++ b/docs/gameinput.md | |||
| @@ -37,10 +37,42 @@ SDL3 is available in one of these ways: | |||
| 37 | - **A local copy of that tarball**: extract it and pass `-DFETCHCONTENT_SOURCE_DIR_SDL3=<path to SDL3-3.4.20>`; it is | 37 | - **A local copy of that tarball**: extract it and pass `-DFETCHCONTENT_SOURCE_DIR_SDL3=<path to SDL3-3.4.20>`; it is |
| 38 | built the same way, without a download. | 38 | built the same way, without a download. |
| 39 | 39 | ||
| 40 | Without any of these, or with `-DLEONIDA_SDL3=OFF`, configure prints a message and `gta6rt` is built without the shim: | 40 | Without any of these, or with `-DLEONIDA_SDL3=OFF`, configure prints a message and `gta6rt` is built without the SDL3 |
| 41 | it has no `GameInputCreate`, as before, so the loader binds it to the host's `GameInput.dll` or the unimplemented | 41 | shim. It links `runtime/shims/gameinput_no_sdl.cpp` instead, which still serves `GameInputCreate` (by name and as |
| 42 | thunk. `gameinput_test` and `gameinput_probe` are not built, and CTest lists `gameinput` as not run (disabled) rather | 42 | `gameinput.dll!#1`): with no devices, or with `LEONIDA_INPUT_SCRIPT` set with one scripted pad (see |
| 43 | than failing. | 43 | [Scripted input without SDL3](#scripted-input-without-sdl3)). `gameinput_test` and `gameinput_probe` are not built, |
| 44 | and CTest lists `gameinput` and `gameinput_script` as not run (disabled) rather than failing; `gameinput_no_sdl` and | ||
| 45 | `gameinput_no_sdl_script` run instead. | ||
| 46 | |||
| 47 | ### Scripted input without SDL3 | ||
| 48 | |||
| 49 | The Windows artifacts of CI and offline builds have no SDL3. Without a device, the title waits at its first "press A" | ||
| 50 | prompt forever, so no headless or CI run could get past it. With `LEONIDA_INPUT_SCRIPT` set, such a build serves one | ||
| 51 | scripted pad, driven by the script alone: | ||
| 52 | |||
| 53 | - **The device:** an Xbox One gamepad named `Scripted pad (Leonida)`, connected from the first `GameInputCreate`. It | ||
| 54 | is reported by `RegisterDeviceCallback` enumeration (blocking on the caller's thread, async from a thread of the | ||
| 55 | shim, or through `IGameInputDispatcher::Dispatch` once the title made a dispatcher) and found by `FindDeviceFromId`. | ||
| 56 | It is already connected, so a callback registered without enumeration hears nothing. | ||
| 57 | - **The readings:** `GetCurrentReading`, `GetNextReading` and `GetPreviousReading`, with gamepad, UI navigation, | ||
| 58 | controller axis and controller button state. A reading is taken when the title asks for one and the script's state | ||
| 59 | has changed since the last, so no thread polls; the history keeps the last 64 readings. | ||
| 60 | - **The timeline:** the same as with SDL3 (`runtime/shims/gameinput_script.h` holds the parser, the timeline and the | ||
| 61 | log lines for both): seconds from the first `GameInputCreate`, each press held 300 ms, then released. | ||
| 62 | - **Not served:** reading callbacks, aggregate devices, rumble and every other device. Those slots answer `E_NOTIMPL` | ||
| 63 | and log the slot once. Controllers and the [keyboard pad](#keyboard-pad) still need SDL3. | ||
| 64 | |||
| 65 | The start of the run logs one line with the counts, and each press logs the same lines as with SDL3: | ||
| 66 | |||
| 67 | ```text | ||
| 68 | [rt] gameinput: served without SDL3: one scripted pad for LEONIDA_INPUT_SCRIPT (3 scripted press(es), 0 rejected); controllers and the keyboard pad need SDL3 | ||
| 69 | [rt] gameinput: scripted press of button 0 at 40.0 s | ||
| 70 | [rt] gameinput: press a@40.0 (Scripted pad (Leonida)) | ||
| 71 | ``` | ||
| 72 | |||
| 73 | A press is logged when the title reads it, so a press the title never reads is not logged. `LEONIDA_INPUT_LOG=0` | ||
| 74 | turns the `press` lines off. Without `LEONIDA_INPUT_SCRIPT`, the shim serves no devices and answers `E_NOTIMPL` for | ||
| 75 | every slot past `Release`, as before. | ||
| 44 | 76 | ||
| 45 | `scripts/build_runtime.ps1` (what `make_game.py` runs) builds the shim only on its CMake path, when Visual Studio's | 77 | `scripts/build_runtime.ps1` (what `make_game.py` runs) builds the shim only on its CMake path, when Visual Studio's |
| 46 | C++ CMake tools are installed. Its direct-`cl.exe` fallback compiles a fixed file list without the shim and warns | 78 | C++ CMake tools are installed. Its direct-`cl.exe` fallback compiles a fixed file list without the shim and warns |
| @@ -81,7 +113,8 @@ The title reads gamepads only, so keyboard input has to arrive as a gamepad. Wit | |||
| 81 | shim attaches one SDL virtual gamepad named `Keyboard pad (Leonida)` and presses its buttons from the keyboard on | 113 | shim attaches one SDL virtual gamepad named `Keyboard pad (Leonida)` and presses its buttons from the keyboard on |
| 82 | every poll. It then goes through the same path as a real pad: a device object, the next free player slot, readings, | 114 | every poll. It then goes through the same path as a real pad: a device object, the next free player slot, readings, |
| 83 | reading and device callbacks, and UI navigation derived from its buttons. It reports no rumble motors. It is off by | 115 | reading and device callbacks, and UI navigation derived from its buttons. It reports no rumble motors. It is off by |
| 84 | default. | 116 | default. If SDL fails to attach or open the keyboard pad, the shim retries after one second while the pad is |
| 117 | enabled. Only the first failure in a continuous series is logged; turning the pad off and back on retries immediately. | ||
| 85 | 118 | ||
| 86 | | key | button | | 119 | | key | button | |
| 87 | |---|---| | 120 | |---|---| |
| @@ -302,7 +335,7 @@ line is logged when it takes effect); tracking goes on underneath, so clearing i | |||
| 302 | | `LEONIDA_PROMPTS_SWITCH_MS` | `300` | shortest time between two changes of the active input family, 0..2000 ms | | 335 | | `LEONIDA_PROMPTS_SWITCH_MS` | `300` | shortest time between two changes of the active input family, 0..2000 ms | |
| 303 | | `LEONIDA_GAMEINPUT_THREAD` | `1` | `0` stops the background poll thread; only `rt::gameinput::poll()` then reads the pads (tests) | | 336 | | `LEONIDA_GAMEINPUT_THREAD` | `1` | `0` stops the background poll thread; only `rt::gameinput::poll()` then reads the pads (tests) | |
| 304 | | `LEONIDA_KEYBOARD_PAD` | `off` | `1` adds the [keyboard pad](#keyboard-pad), read while this process has focus; `always` reads keys whatever has focus | | 337 | | `LEONIDA_KEYBOARD_PAD` | `off` | `1` adds the [keyboard pad](#keyboard-pad), read while this process has focus; `always` reads keys whatever has focus | |
| 305 | | `LEONIDA_INPUT_SCRIPT` | unset | With the keyboard pad enabled, set comma-separated `button@seconds` entries, e.g. `a@2,a@4,start@6`. The first pad update reads the script once at startup and starts the clock. `reload_config()` does not reread it. Each press lasts 300 ms. Buttons are `a b x y start back lb rb up down left right`. Spaces around entries are allowed. Empty entries, unknown buttons and invalid times (including negative or non-finite values) are counted and ignored. | | 338 | | `LEONIDA_INPUT_SCRIPT` | unset | Comma-separated `button@seconds` entries, e.g. `a@2,a@4,start@6`. With SDL3 they drive the keyboard pad, which has to be enabled; without SDL3 they drive [one scripted pad](#scripted-input-without-sdl3), the only device. The first pad update (without SDL3, the first `GameInputCreate`) reads the script once at startup and starts the clock. `reload_config()` does not reread it. Each press lasts 300 ms. Buttons are `a b x y start back lb rb up down left right`. Spaces around entries are allowed. Empty entries, unknown buttons and invalid times (including negative or non-finite values) are counted and ignored. | |
| 306 | | `LEONIDA_MOUSE_SENSITIVITY` | `1` | scales how far the mouse moves the keyboard pad's right stick, 0.1..10 | | 339 | | `LEONIDA_MOUSE_SENSITIVITY` | `1` | scales how far the mouse moves the keyboard pad's right stick, 0.1..10 | |
| 307 | 340 | ||
| 308 | SDL's own hints (`SDL_JOYSTICK_*`, see SDL's `SDL_hints.h`) also apply, for example `SDL_JOYSTICK_HIDAPI_PS5=0` to | 341 | SDL's own hints (`SDL_JOYSTICK_*`, see SDL's `SDL_hints.h`) also apply, for example `SDL_JOYSTICK_HIDAPI_PS5=0` to |
| @@ -457,6 +490,14 @@ rests on a transcription rather than on a side-by-side compile. | |||
| 457 | button, the touchpad, a trigger or a stick, stick drift and a one-count mouse jitter ignored, a real mouse movement | 490 | button, the touchpad, a trigger or a stick, stick drift and a one-count mouse jitter ignored, a real mouse movement |
| 458 | counted, the 300 ms window on the real clock, and `LEONIDA_PROMPTS` forcing, changing, ignoring an unknown value | 491 | counted, the 300 ms window on the real clock, and `LEONIDA_PROMPTS` forcing, changing, ignoring an unknown value |
| 459 | and clearing. | 492 | and clearing. |
| 493 | - `gameinput_no_sdl_test` (CTest, only in a build without SDL3, no controller): `gameinput_no_sdl` checks the | ||
| 494 | identity-only object (both names served, `AddRef`/`Release`, `E_NOTIMPL` without touching the out-parameter). | ||
| 495 | `gameinput_no_sdl_script` sets `LEONIDA_INPUT_SCRIPT` with overlapping presses, a mixed-case name, `rsup` and three | ||
| 496 | rejected entries, puts the shim on a fake clock and checks the scripted pad: blocking, async and dispatcher | ||
| 497 | enumeration (and none without enumeration, for another status or another kind), the device info, `FindDeviceFromId`, | ||
| 498 | the buttons, UI navigation and right stick read at chosen times (held for 0.3 s, a later press of the same button | ||
| 499 | not cut short, nothing after the script), no new reading without a change, `GetPreviousReading` and | ||
| 500 | `GetNextReading`, no motion, and reading callbacks answering `E_NOTIMPL`. | ||
| 460 | - `gameinput_test` (CTest, no controller): turns SDL's real backends off and drives the shim through | 501 | - `gameinput_test` (CTest, no controller): turns SDL's real backends off and drives the shim through |
| 461 | `rt::shims::find` with SDL virtual joysticks, an Xbox-style pad with trigger motors, a DualSense (Sony | 502 | `rt::shims::find` with SDL virtual joysticks, an Xbox-style pad with trigger motors, a DualSense (Sony |
| 462 | `054c:0ce6`) and a pad without trigger motors. It checks enumeration and device callbacks, the button, stick, | 503 | `054c:0ce6`) and a pad without trigger motors. It checks enumeration and device callbacks, the button, stick, |
diff --git a/docs/gbuffer.md b/docs/gbuffer.md index de76f4746..9813a3306 100644 --- a/docs/gbuffer.md +++ b/docs/gbuffer.md | |||
| @@ -82,3 +82,16 @@ captured PSO): | |||
| 82 | verified against the lighting pass). | 82 | verified against the lighting pass). |
| 83 | - The runtime must therefore bind the PSO's declared `RTVFormats[]` rather than inferring `R16G16B16A16_FLOAT` for all | 83 | - The runtime must therefore bind the PSO's declared `RTVFormats[]` rather than inferring `R16G16B16A16_FLOAT` for all |
| 84 | G-buffer attachments from `OSG1` or `exp ... compr`. | 84 | G-buffer attachments from `OSG1` or `exp ... compr`. |
| 85 | |||
| 86 | ## 4. Reproducing the census (`tools/gbuffer_census.py`) | ||
| 87 | |||
| 88 | ```powershell | ||
| 89 | python -I tools/gbuffer_census.py <work>\shaders\dxbc [--disasm <dir>] [--payload-coverage] | ||
| 90 | ``` | ||
| 91 | |||
| 92 | Reads `index.json`, each pixel shader's `OSG1` output signature, and the matching `.s` listing under `--disasm` | ||
| 93 | (default `<dxbc>\disasm`), and prints JSON counts for four cohorts (all indexed PS, case-folded `deferred` entry | ||
| 94 | names, case-sensitive `Deferred` stems, and `PS_DeferredTextured` stems) with declared target counts, signature | ||
| 95 | layouts, and observed `exp mrtN` export modes (`compr` vs `uncompressed`). With `--payload-coverage`, it also counts | ||
| 96 | distinct whole FSSM payloads per cohort and histograms how many indexed entries share each payload. Standard library | ||
| 97 | only; outputs counts and layouts only (no shader text). | ||
diff --git a/docs/gpu_test_results.md b/docs/gpu_test_results.md index 1d9a2ddbf..ee43b96cb 100644 --- a/docs/gpu_test_results.md +++ b/docs/gpu_test_results.md | |||
| @@ -6,13 +6,18 @@ post counts and pass/fail lines there, never game shaders, logs or private paths | |||
| 6 | 6 | ||
| 7 | | GPU | Driver, OS | Commit | build.py | check.py | run_gpu_tests.py | Failed | Entry | | 7 | | GPU | Driver, OS | Commit | build.py | check.py | run_gpu_tests.py | Failed | Entry | |
| 8 | |---|---|---|---|---|---|---|---| | 8 | |---|---|---|---|---|---|---|---| |
| 9 | | NVIDIA GeForce RTX 5070 Ti (Blackwell), subgroup 32 | NVIDIA 621.01, Windows 11 26300.9457 | `e0b08c7` | not run; pre-disassembled subset | run via run_gpu_tests.py | **Subset:** 82/98 passed, 16 skipped (native); 98/98 passed (`LEONIDA_W64_EMULATE=1`); Python assembler, no spirv-val. ctest 280/280 (MSVC) | none in the subset | [local note](../gpu-test-results/RTX5070Ti-62101.txt) | | ||
| 9 | | NVIDIA GeForce RTX 3080 Ti (Ampere), subgroup 32..32 | NVIDIA 616.92, Windows 11 26300.9974 | `d478a92` | not run; pre-disassembled subset | run via run_gpu_tests.py | **Subset:** 81/97 passed, 16 skipped (native); 97/97 passed (`LEONIDA_W64_EMULATE=1`); Python assembler, no spirv-val | none in the subset | [local note](../gpu-test-results/RTX3080Ti-61692.txt) | | 10 | | NVIDIA GeForce RTX 3080 Ti (Ampere), subgroup 32..32 | NVIDIA 616.92, Windows 11 26300.9974 | `d478a92` | not run; pre-disassembled subset | run via run_gpu_tests.py | **Subset:** 81/97 passed, 16 skipped (native); 97/97 passed (`LEONIDA_W64_EMULATE=1`); Python assembler, no spirv-val | none in the subset | [local note](../gpu-test-results/RTX3080Ti-61692.txt) | |
| 10 | | AMD Radeon RX 9070 GRE (RDNA4, GFX1201), subgroup 32..64 | RADV, Mesa 26.3.1-arch3.5, Vulkan 1.4.363, CachyOS | `05961f0` | 264/264 translated and valid | 203/206 pass, 3 skipped | 218/235 passed, 16 skipped (native and emulated) | `ms_wave_info_s3`, flaky (see below) | [local note](../gpu-test-results/RX9070GRE.txt) | | 11 | | AMD Radeon RX 9070 GRE (RDNA4, GFX1201), subgroup 32..64 | RADV, Mesa 26.3.1-arch3.5, Vulkan 1.4.363, CachyOS | `05961f0` | 264/264 translated and valid | 203/206 pass, 3 skipped | 218/235 passed, 16 skipped (native and emulated) | `ms_wave_info_s3`, flaky (see below) | [local note](../gpu-test-results/RX9070GRE.txt) | |
| 11 | | AMD Radeon RX 9070 XT (RDNA4, GFX1201), subgroup 32..64 | AMD 26.11.2 (LLPC), Vulkan 1.4.359, Windows 11 26300.9550 | `5d74c27` | not run | not run | 224/241 passed, 16 skipped, 1 failed (native); 225/241 passed, 0 failed (`LEONIDA_W64_EMULATE=1`) | `ms_wave_info_s3`, every native run, flaky emulated (see below) | [local note](../gpu-test-results/RX9070XT.txt) | | 12 | | AMD Radeon RX 9070 XT (RDNA4, GFX1201), subgroup 32..64 | AMD 26.11.2 (LLPC), Vulkan 1.4.359, Windows 11 26200.9974 | `58be9cd` | exit 0 (native and emulated) | 219/222 pass, 3 skipped (mesh fixtures build.py does not build) | 236/252 passed, 16 skipped, 0 failed (native and `LEONIDA_W64_EMULATE=1`) | none | [local note](../gpu-test-results/RX9070XT.txt) | |
| 13 | | AMD Radeon RX 9070 (RDNA4, GFX1201), subgroup 32..64 | AMD 26.11.2 (LLPC), 32.0.32029.2010, Vulkan 1.4.359, Windows 11 26200.9974 | `d0da7da` | not run | not run | 231/249 passed, 16 skipped, 2 failed (native and `LEONIDA_W64_EMULATE=1` alike) | `cs_imgload_tfe`, `cs_imgload_d16_tfe`: the fixtures' expectation (#98); `ms_wave_info_s3` passes | [local note](../gpu-test-results/RX9070.txt) | | ||
| 14 | | AMD Radeon Graphics, Ryzen 5 7600X iGPU (RDNA2, gfx1036), subgroup 32..64 | AMD 26.11.2, 32.0.21045.29003, Vulkan 1.4.315, Windows 11 26200.9974 | `d0da7da` | not run | not run | 224/249 passed, 23 skipped, 2 failed (native and `LEONIDA_W64_EMULATE=1` alike) | `cs_imgload_tfe`, `cs_imgload_d16_tfe`: the fixtures' expectation (#98) | [local note](../gpu-test-results/Raphael-7600X-Win.txt) | | ||
| 12 | | AMD Radeon RX 7900 GRE (RDNA3, gfx1100), subgroup 32..64 | AMD proprietary 26.11.2 (LLPC), Vulkan 1.4.359, Windows 11 x64 | `5d74c27` | 247/247 translated and valid | run via run_gpu_tests.py | 225/241 passed, 16 skipped | none | [#166](https://github.com/ItsNotRexed/Leonida/issues/166#issuecomment-7115041436) | | 15 | | AMD Radeon RX 7900 GRE (RDNA3, gfx1100), subgroup 32..64 | AMD proprietary 26.11.2 (LLPC), Vulkan 1.4.359, Windows 11 x64 | `5d74c27` | 247/247 translated and valid | run via run_gpu_tests.py | 225/241 passed, 16 skipped | none | [#166](https://github.com/ItsNotRexed/Leonida/issues/166#issuecomment-7115041436) | |
| 13 | | Intel Graphics (Meteor Lake, Xe-LPG), subgroup 8..32 | ANV, Mesa 26.2.7, Vulkan 1.4.354, Fedora 45 | `84347bb` | 279/279 translated and valid | 177/219 pass, 40 skipped, 2 failed | 194/248 passed, 52 skipped (native); 226/248 passed, 20 skipped (`LEONIDA_W64_EMULATE=1`) | `cs_imgload_tfe`, `cs_imgload_d16_tfe` (#31; pass with #98) | [local note](../gpu-test-results/IntelMTL.txt) | | 16 | | Intel Graphics (Meteor Lake, Xe-LPG), subgroup 8..32 | ANV, Mesa 26.2.7, Vulkan 1.4.354, Fedora 45 | `84347bb` | 279/279 translated and valid | 177/219 pass, 40 skipped, 2 failed | 194/248 passed, 52 skipped (native); 226/248 passed, 20 skipped (`LEONIDA_W64_EMULATE=1`) | `cs_imgload_tfe`, `cs_imgload_d16_tfe` (#31; pass with #98) | [local note](../gpu-test-results/IntelMTL.txt) | |
| 17 | | NVIDIA GeForce RTX 5070 Ti (Blackwell), subgroup 32..32 | NVIDIA 617.42, Vulkan 1.4.351, Windows 11 Pro 26300 | `21625bc` | 257/257 translated and valid (run_gpu_tests.py) | run via run_gpu_tests.py | 197/248 passed, 49 skipped, 2 failed (native); 229/248 passed, 17 skipped, 2 failed (`LEONIDA_W64_EMULATE=1`) | `cs_imgload_tfe`, `cs_imgload_d16_tfe` (#31) | [local note](../gpu-test-results/RTX5070Ti.txt) | | ||
| 14 | | Apple M5 Pro (16-core GPU, Metal 4), subgroup 4..32 | MoltenVK 1.4.2 (Homebrew), Vulkan 1.4.357, macOS 26.7.3 (25G342) | `d42773d07` | 280/280 translated and valid | 175/219 pass, 39 skipped, 5 failed | 183/248 passed, 61 skipped, 4 failed (native); 214/248 passed, 30 skipped, 4 failed (`LEONIDA_W64_EMULATE=1`) | `cs_fma_fused` (known row), `cs_imgload_tfe`, `cs_imgload_d16_tfe` (pass with #291), `ps_imgatomic` flake (#543) | [local note](../gpu-test-results/AppleM5Pro.txt) | | 18 | | Apple M5 Pro (16-core GPU, Metal 4), subgroup 4..32 | MoltenVK 1.4.2 (Homebrew), Vulkan 1.4.357, macOS 26.7.3 (25G342) | `d42773d07` | 280/280 translated and valid | 175/219 pass, 39 skipped, 5 failed | 183/248 passed, 61 skipped, 4 failed (native); 214/248 passed, 30 skipped, 4 failed (`LEONIDA_W64_EMULATE=1`) | `cs_fma_fused` (known row), `cs_imgload_tfe`, `cs_imgload_d16_tfe` (pass with #291), `ps_imgatomic` flake (#543) | [local note](../gpu-test-results/AppleM5Pro.txt) | |
| 15 | | Apple M3 (10-core GPU), subgroup 32 | MoltenVK 1.4.2 (Homebrew), Vulkan 1.4.357, macOS 26.5.1 (25F80) | `626d1281a` | stops at `cs_dpp_cmp` on `main`; 297/297 translated and valid with #1444 | 183/231 pass, 43 skipped, 5 failed (with #1444) | 192/263 passed, 68 skipped, 3 failed (native); 225/263 passed, 35 skipped, 3 failed (`LEONIDA_W64_EMULATE=1`) | `cs_fma_fused` (known row), `ps_ssharp` (expected on Metal), `cs_imgatomic_ext` (fixed by #1518); check.py also `ps_ij_computed`, `ps_interp_f16_high` (no PerVertexKHR, #822); KosmicKrisp: 187/263, `cs_bvh`, `cs_bvh32` (#1212), `ps_cndmask_sign_mods`, `ps_valu16_mad_sel`, `cs_imgatomic_ext` | [local note](../gpu-test-results/AppleM3.txt) | | 19 | | Apple M3 (10-core GPU), subgroup 32 | MoltenVK 1.4.2 (Homebrew), Vulkan 1.4.357, macOS 26.5.1 (25F80) | `626d1281a` | stops at `cs_dpp_cmp` on `main`; 297/297 translated and valid with #1444 | 183/231 pass, 43 skipped, 5 failed (with #1444) | 192/263 passed, 68 skipped, 3 failed (native); 225/263 passed, 35 skipped, 3 failed (`LEONIDA_W64_EMULATE=1`) | `cs_fma_fused` (known row), `ps_ssharp` (expected on Metal), `cs_imgatomic_ext` (fixed by #1518); check.py also `ps_ij_computed`, `ps_interp_f16_high` (no PerVertexKHR, #822); KosmicKrisp: 187/263, `cs_bvh`, `cs_bvh32` (#1212), `ps_cndmask_sign_mods`, `ps_valu16_mad_sel`, `cs_imgatomic_ext` | [local note](../gpu-test-results/AppleM3.txt) | |
| 20 | | NVIDIA GeForce RTX 3080 (Ampere, GA102, 10 GB GDDR6X), subgroup 32..32 | NVIDIA 580.178.04, Vulkan 1.4.312, Ubuntu 26.04 LTS | `d2cd6c0` | not run | not run | 197/248 passed, 49 skipped, 2 failed (native); 229/248 passed, 17 skipped, 2 failed (`LEONIDA_W64_EMULATE=1`) | `cs_imgload_tfe`, `cs_imgload_d16_tfe` (#31; see #280) | [local note](../gpu-test-results/RTX3080.txt) | | ||
| 16 | 21 | ||
| 17 | ## AMD Radeon RX 9070 GRE — 2026-11-23 | 22 | ## AMD Radeon RX 9070 GRE — 2026-11-23 |
| 18 | 23 | ||
| @@ -38,43 +43,38 @@ Every pixel test other than the flaky mesh fixture was exact (4096/4096). | |||
| 38 | AI-assisted (Hermes Agent): built `main` at `05961f0`, ran `build.py`, `check.py` and | 43 | AI-assisted (Hermes Agent): built `main` at `05961f0`, ran `build.py`, `check.py` and |
| 39 | `run_gpu_tests.py` (native and emulated) on this GPU, and verified the isolated reruns of the one failure. | 44 | `run_gpu_tests.py` (native and emulated) on this GPU, and verified the isolated reruns of the one failure. |
| 40 | 45 | ||
| 41 | ## AMD Radeon RX 9070 XT — 2026-11-23 | 46 | ## AMD Radeon RX 9070 XT — 2026-11-24 |
| 42 | 47 | ||
| 43 | ``` | 48 | ``` |
| 44 | GPU: AMD Radeon RX 9070 XT (RDNA4 / GFX1201, Navi 48, PCI 1002:7550), subgroup 32..64 | 49 | GPU: AMD Radeon RX 9070 XT (RDNA4 / GFX1201, Navi 48, PCI 1002:7550), subgroup 32..64 |
| 45 | Driver: AMD proprietary 26.11.2 (LLPC), Vulkan 1.4.359 | 50 | Driver: AMD proprietary 26.11.2 (LLPC), Vulkan 1.4.359 |
| 46 | Subgroup: 32..64 (minSubgroupSize 32, maxSubgroupSize 64; default 64, subgroupSizeControl) | 51 | Subgroup: 32..64 (minSubgroupSize 32, maxSubgroupSize 64; default 64, subgroupSizeControl) |
| 47 | OS: Windows 11, 10.0.26300.9550 | 52 | OS: Windows 11, 10.0.26200.9974 |
| 48 | Commit: 5d74c272363f2703265d44e6aaab1a1df8ddfaf3 (main, 2026-11-23) | 53 | Commit: 58be9cdf8df9a31bc7f6c068991f1aed381f7f4d (main, 2026-11-24) |
| 49 | Tools: llvm-mc from ROCm/AOMP 18.0-12 (LLVM 19.0.0git), SPIRV-Tools v2026.4, | 54 | Tools: llvm-mc LLVM 23.1.6 (conda-forge, AMDGPU target), SPIRV-Tools v2026.4, |
| 50 | CMake 4.4.5, Visual Studio 17 2022 generator, MSVC 19.44.35230.0, Python 3.11.9 | 55 | CMake 4.4.4, Visual Studio 17 2022 generator, MSVC 14.44.35207, Python 3.12.10 |
| 51 | run_gpu_tests.py: 247 shaders: 247 translated, 247 pass spirv-val | 56 | run_gpu_tests.py: 261 shaders: 261 translated, 261 pass spirv-val |
| 52 | native: 224/241 passed, 16 skipped, 1 failed | 57 | native: 236/252 passed, 16 skipped, 0 failed |
| 53 | LEONIDA_W64_EMULATE=1: 225/241 passed, 16 skipped, 0 failed | 58 | LEONIDA_W64_EMULATE=1: 236/252 passed, 16 skipped, 0 failed |
| 54 | Failed: ms_wave_info_s3: at (0,0) got (-1,-1,-1,-1), want (0.0078,0.0078,0.5,1.0). | 59 | build.py: exit 0, native and emulated (6 mesh fixtures need a DXBC container and are not built) |
| 55 | Native: 3 of 3 isolated --filter reruns failed. Emulated: the full-suite | 60 | check.py: 219 of 222 pass, 3 skipped (those mesh fixtures), native and emulated |
| 56 | run passed it, then 1 of 3 isolated reruns passed, so the emulated path | 61 | Failed: none |
| 57 | is flaky here while native fails every time. Same signature as #6172 / | ||
| 58 | #5273 and as the RTX 4060 record (#8752), where it failed 3 of 3. | ||
| 59 | Skipped: 16 skips are the documented "run by d3d12_*_test / w64_graphics.py" cases. | 62 | Skipped: 16 skips are the documented "run by d3d12_*_test / w64_graphics.py" cases. |
| 60 | ``` | 63 | ``` |
| 61 | 64 | ||
| 62 | Setup: `cmake -S runtime -B runtime/build` (default Visual Studio 17 2022 generator) and | 65 | Setup: `cmake -S runtime -B runtime/build` (default Visual Studio 17 2022 generator) and |
| 63 | `cmake --build runtime/build --config RelWithDebInfo`. The suite ran on the AMD LLPC driver with | 66 | `cmake --build runtime/build --config RelWithDebInfo`; then `run_gpu_tests.py`, and `build.py <out>` with |
| 64 | the project's own `vk_harness`, `vk_compute_test` and `vk_store_test` binaries; no implicit layer | 67 | `check.py <out> runtime/build/RelWithDebInfo`, each once without and once with `LEONIDA_W64_EMULATE=1`. The suites |
| 65 | beyond the Vulkan SDK's. Every other pixel and compute case was exact. | 68 | ran on the AMD LLPC driver with the project's own `vk_harness`, `vk_compute_test` and `vk_store_test` binaries; no |
| 66 | 69 | implicit layer beyond the Vulkan SDK's. | |
| 67 | The one failure is worth a note for #6172: on this machine the native 64-wide path fails | 70 | |
| 68 | `ms_wave_info_s3` on every run, while `LEONIDA_W64_EMULATE=1` passes it most of the time, which is | 71 | This replaces the 2026-11-23 record (`5d74c27`), which had `ms_wave_info_s3` failing on every native run and |
| 69 | the shape a lane-set-dependent race takes rather than a driver-specific miscompile. It also | 72 | `build.py` / `check.py` not run. On `58be9cd` the same driver passes `ms_wave_info_s3` with 4096/4096 exact pixels in |
| 70 | reproduces with an AMD proprietary driver, so the symptom is not tied to RADV or to Mesa's shader | 73 | both full runs and in 3 of 3 isolated `--filter` reruns each way, and the D3D12-side columns are measured for the |
| 71 | cache. | 74 | first time on this card. The two `cs_imgload*_tfe` failures of earlier runs are gone with the fixture fix (#892). |
| 72 | 75 | ||
| 73 | `build.py` and `check.py` (the D3D12-side rows in the table) were not run here; the counts above | 76 | AI-assisted: built `main` at `58be9cd` with MSVC, ran the three scripts native and under `LEONIDA_W64_EMULATE=1`, |
| 74 | come from `run_gpu_tests.py`, which builds and translates the same fixtures. | 77 | and reran `ms_wave_info_s3` in isolation three times each way. |
| 75 | |||
| 76 | AI-assisted (Cline): built `main` at `5d74c27` with MSVC, ran `run_gpu_tests.py` native and under | ||
| 77 | `LEONIDA_W64_EMULATE=1`, and reran the failure in isolation three times each way. | ||
| 78 | 78 | ||
| 79 | ## AMD Radeon RX 7900 GRE — 2026-11-23 | 79 | ## AMD Radeon RX 7900 GRE — 2026-11-23 |
| 80 | 80 | ||
diff --git a/docs/i18n/README.md b/docs/i18n/README.md index 35fa1ef96..82cb57c29 100644 --- a/docs/i18n/README.md +++ b/docs/i18n/README.md | |||
| @@ -24,3 +24,8 @@ A language is added when a contributor volunteers to maintain it and keeps the s | |||
| 24 | | Deutsch (`de`) | [`de/quickstart.md`](de/quickstart.md) | `aa2988cc` | `@zGLados` | | 24 | | Deutsch (`de`) | [`de/quickstart.md`](de/quickstart.md) | `aa2988cc` | `@zGLados` | |
| 25 | | Italiano (`it`) | [`it/quickstart.md`](it/quickstart.md) | `49475796` | `@MeNoSkills` | | 25 | | Italiano (`it`) | [`it/quickstart.md`](it/quickstart.md) | `49475796` | `@MeNoSkills` | |
| 26 | | العربية (`ar`) | [`ar/quickstart.md`](ar/quickstart.md) | `561b65a` | `@Mohamed-Leo` | | 26 | | العربية (`ar`) | [`ar/quickstart.md`](ar/quickstart.md) | `561b65a` | `@Mohamed-Leo` | |
| 27 | |||
| 28 | ## Other community translations | ||
| 29 | |||
| 30 | - French translation of [`CONTRIBUTING.md`](../../CONTRIBUTING.md): [`fr/contributing.md`](fr/contributing.md), synced | ||
| 31 | with commit `1ab957b3`. No maintainer is named in the file. | ||
diff --git a/docs/i18n/it/quickstart.md b/docs/i18n/it/quickstart.md index d42f35727..432b1eb72 100644 --- a/docs/i18n/it/quickstart.md +++ b/docs/i18n/it/quickstart.md | |||
| @@ -96,8 +96,8 @@ python -I make_game.py --wave64-emulate off # auto (predefinito), on | |||
| 96 | ``` | 96 | ``` |
| 97 | 97 | ||
| 98 | La fase `check` viene eseguita sempre per prima; poi, quando sono selezionate, `shaders`, `assets` e `runtime` vengono eseguite insieme (non dipendono l'una dall'altra). `pipelines` parte quando gli shader tradotti sono pronti. | 98 | La fase `check` viene eseguita sempre per prima; poi, quando sono selezionate, `shaders`, `assets` e `runtime` vengono eseguite insieme (non dipendono l'una dall'altra). `pipelines` parte quando gli shader tradotti sono pronti. |
| 99 | `pipelines` crea ogni shader tradotto sul driver della tua GPU e salva una cache delle pipeline, così al primo | 99 | `pipelines` crea ogni shader tradotto sul driver della tua GPU e salva una cache delle pipeline in |
| 100 | avvio non devono essere compilati. La traduzione degli shader è il passaggio più lungo: usa `--jobs` processi | 100 | `pipeline_cache.bin` (in `--out`). La traduzione degli shader è il passaggio più lungo: usa `--jobs` processi |
| 101 | (per impostazione predefinita metà dei thread della CPU). | 101 | (per impostazione predefinita metà dei thread della CPU). |
| 102 | 102 | ||
| 103 | - **`--wave64-emulate`**: traduce gli shader compute e mesh wave64 in modo che siano esatti con qualunque | 103 | - **`--wave64-emulate`**: traduce gli shader compute e mesh wave64 in modo che siano esatti con qualunque |
diff --git a/docs/i18n/ja/quickstart.md b/docs/i18n/ja/quickstart.md index 2924be033..d9a45926f 100644 --- a/docs/i18n/ja/quickstart.md +++ b/docs/i18n/ja/quickstart.md | |||
| @@ -84,8 +84,8 @@ python -I make_game.py --wave64-emulate off # auto(既定)、on〠| |||
| 84 | ``` | 84 | ``` |
| 85 | 85 | ||
| 86 | `check` ステージは常に最初に実行され、選択した場合は `shaders`、`assets`、`runtime` が同時に実行されます(互いに依存しません)。`pipelines` は翻訳済みのシェーダーが揃い次第開始されます。このステージは | 86 | `check` ステージは常に最初に実行され、選択した場合は `shaders`、`assets`、`runtime` が同時に実行されます(互いに依存しません)。`pipelines` は翻訳済みのシェーダーが揃い次第開始されます。このステージは |
| 87 | 翻訳済みの各シェーダーをあなたの GPU ドライバー上で生成してパイプラインキャッシュを保存するので、初回起動時の | 87 | 翻訳済みの各シェーダーをあなたの GPU ドライバー上で生成し、パイプラインキャッシュを `--out` の |
| 88 | コンパイルが不要になります。最も時間がかかるのはシェーダーの翻訳で、`--jobs` 個のプロセスで実行されます | 88 | `pipeline_cache.bin` に保存します。最も時間がかかるのはシェーダーの翻訳で、`--jobs` 個のプロセスで実行されます |
| 89 | (既定では CPU スレッド数の半分)。 | 89 | (既定では CPU スレッド数の半分)。 |
| 90 | 90 | ||
| 91 | - **`--wave64-emulate`**: wave64 の compute / mesh シェーダーを、どのサブグループサイズでも正確になるように | 91 | - **`--wave64-emulate`**: wave64 の compute / mesh シェーダーを、どのサブグループサイズでも正確になるように |
diff --git a/docs/i18n/pl-PL/quickstart.md b/docs/i18n/pl-PL/quickstart.md index 29cfb6a08..3bad5af88 100644 --- a/docs/i18n/pl-PL/quickstart.md +++ b/docs/i18n/pl-PL/quickstart.md | |||
| @@ -95,8 +95,8 @@ python -I make_game.py --wave64-emulate off # auto (domyślnie), on l | |||
| 95 | ``` | 95 | ``` |
| 96 | 96 | ||
| 97 | Etap `check` zawsze wykonuje się pierwszy; następnie, jeśli zostały wybrane, `shaders`, `assets` i `runtime` wykonują się równocześnie (nie zależą od siebie). Etap `pipelines` startuje, gdy przetłumaczone shadery są gotowe. Ten etap | 97 | Etap `check` zawsze wykonuje się pierwszy; następnie, jeśli zostały wybrane, `shaders`, `assets` i `runtime` wykonują się równocześnie (nie zależą od siebie). Etap `pipelines` startuje, gdy przetłumaczone shadery są gotowe. Ten etap |
| 98 | tworzy każdy przetłumaczony shader na sterowniku Twojej karty graficznej i zapisuje cache potoków, żeby pierwsze | 98 | tworzy każdy przetłumaczony shader na sterowniku Twojej karty graficznej i zapisuje cache potoków |
| 99 | uruchomienie nie musiało ich kompilować. Tłumaczenie shaderów trwa najdłużej i domyślnie używa połowy wątków | 99 | w `pipeline_cache.bin` (w `--out`). Tłumaczenie shaderów trwa najdłużej i domyślnie używa połowy wątków |
| 100 | procesora (można to zmienić przez `--jobs`). | 100 | procesora (można to zmienić przez `--jobs`). |
| 101 | 101 | ||
| 102 | - **`--wave64-emulate`**: decyduje, czy shadery compute i mesh wave64 są tłumaczone tak, by były dokładne przy | 102 | - **`--wave64-emulate`**: decyduje, czy shadery compute i mesh wave64 są tłumaczone tak, by były dokładne przy |
diff --git a/docs/i18n/ru/quickstart.md b/docs/i18n/ru/quickstart.md index 818e47fe4..4b1d89a80 100644 --- a/docs/i18n/ru/quickstart.md +++ b/docs/i18n/ru/quickstart.md | |||
| @@ -112,10 +112,12 @@ python -I make_game.py --game "D:\путь\к\пакету" --wav # ещё и Op | |||
| 112 | python -I make_game.py --wave64-emulate off # auto (по умолчанию), on или off | 112 | python -I make_game.py --wave64-emulate off # auto (по умолчанию), on или off |
| 113 | ``` | 113 | ``` |
| 114 | 114 | ||
| 115 | Этапы идут в таком порядке: `check`, `shaders`, `assets`, `runtime`, `pipelines`. Последний создаёт все | 115 | `check` всегда идёт первым; затем выбранные `shaders`, `assets` и `runtime` выполняются одновременно (они не |
| 116 | переведённые шейдеры на драйвере вашей видеокарты, проверяет, что они компилируются, сообщает о пропущенных и | 116 | зависят друг от друга). `pipelines` начинается, как только готовы переведённые шейдеры и, если в этот запуск входит |
| 117 | сохраняет кеш конвейеров в `pipeline_cache.bin` в `--out`. Runtime этот кеш пока не загружает, так что первую | 117 | `runtime`, этот этап закончил пересобирать `vk_pipeline_check`, так что он может идти параллельно с остатком |
| 118 | загрузку он не ускоряет. Перевод шейдеров самый долгий: он выполняется в `--jobs` процессов (по умолчанию | 118 | `assets`. Этап `pipelines` создаёт все переведённые шейдеры на драйвере вашей видеокарты, проверяет, что они |
| 119 | компилируются, сообщает о пропущенных и сохраняет кеш конвейеров в `pipeline_cache.bin` в `--out`. Runtime этот | ||
| 120 | кеш пока не загружает, так что первую загрузку он не ускоряет. Перевод шейдеров самый долгий: он выполняется в `--jobs` процессов (по умолчанию | ||
| 119 | половина потоков процессора). | 121 | половина потоков процессора). |
| 120 | 122 | ||
| 121 | - **`--wave64-emulate`**: переводить ли compute- и mesh-шейдеры wave64 так, чтобы они работали точно при любом | 123 | - **`--wave64-emulate`**: переводить ли compute- и mesh-шейдеры wave64 так, чтобы они работали точно при любом |
diff --git a/docs/linux.md b/docs/linux.md index f051ca84a..c9ea03b84 100644 --- a/docs/linux.md +++ b/docs/linux.md | |||
| @@ -16,6 +16,7 @@ names; the build lists anything it can't find before it starts. | |||
| 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` | |
| 19 | | `scripts/run_game_wine.sh`: one retail run under Wine, headless or visible, counts only ([linux_proton.md](linux_proton.md#running-the-game-under-wine-with-one-command)) | Native (`bash`) around the Windows `gta6rt` | `tests/test_run_game_wine.py` and `tests/test_game_run_summary.py`, without the game | | ||
| 19 | 20 | ||
| 20 | ## Build the port | 21 | ## Build the port |
| 21 | 22 | ||
| @@ -118,3 +119,36 @@ python3 -I tests/test_<name>.py # one standard- | |||
| 118 | 119 | ||
| 119 | [testing.md](testing.md) covers the GPU tests (`scripts/run_gpu_tests.py`), running them on llvmpipe, and choosing | 120 | [testing.md](testing.md) covers the GPU tests (`scripts/run_gpu_tests.py`), running them on llvmpipe, and choosing |
| 120 | the GPU. | 121 | the GPU. |
| 122 | |||
| 123 | ### Without root (micromamba) | ||
| 124 | |||
| 125 | If you cannot install distribution packages (no `sudo`), you can install `llvm-tools` and `spirv-tools` into a | ||
| 126 | user-owned folder with [micromamba](https://mamba.readthedocs.io/en/latest/installation/micromamba-installation.html) | ||
| 127 | (x86-64 glibc; for ARM64 use `linux-aarch64` from the micromamba guide; musl/Alpine is not natively supported) and let | ||
| 128 | CMake fetch its pinned, hash-checked Vulkan headers if the system does not provide them: | ||
| 129 | |||
| 130 | ```bash | ||
| 131 | LEO=$HOME/leonida-tools | ||
| 132 | mkdir -p "$LEO/bin" "$LEO/mamba" | ||
| 133 | # Note: `latest` is unpinned and downloaded without signature verification; inspect or pin per the micromamba guide. | ||
| 134 | curl -fsSLo "$LEO/micromamba.tar.bz2" https://micro.mamba.pm/api/micromamba/linux-64/latest | ||
| 135 | tar -xjf "$LEO/micromamba.tar.bz2" -C "$LEO/bin" --strip-components=1 bin/micromamba | ||
| 136 | |||
| 137 | export MAMBA_ROOT_PREFIX="$LEO/mamba" | ||
| 138 | "$LEO/bin/micromamba" create -y -n leonida -c conda-forge --override-channels "llvm-tools>=21" spirv-tools | ||
| 139 | export PATH="$LEO/mamba/envs/leonida/bin:$PATH" | ||
| 140 | |||
| 141 | cmake -S runtime -B runtime/build/linux -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_VULKAN_HEADERS_FETCH=ON | ||
| 142 | cmake --build runtime/build/linux --parallel "$(nproc)" | ||
| 143 | LLVM_MC=llvm-mc LEONIDA_VK_DEVICE="<part of your GPU name>" \ | ||
| 144 | python3 -I scripts/run_gpu_tests.py --build runtime/build/linux --work "$LEO/run" --require-pass | tee "$LEO/run.log" | ||
| 145 | echo "runner exit: ${PIPESTATUS[0]}" | ||
| 146 | ``` | ||
| 147 | |||
| 148 | Notes: | ||
| 149 | - `LEONIDA_VK_DEVICE` selects the physical GPU by substring so the runner does not fall back to Mesa's `llvmpipe`. | ||
| 150 | - Keep `$LEO` on a filesystem without `noexec` (`findmnt -no OPTIONS "$LEO"`). | ||
| 151 | - System prerequisites still needed: a working Vulkan driver/loader (`vulkaninfo --summary`), `cmake`, `ninja`, `g++` | ||
| 152 | (or `clang++`), `python3`, `curl`, `tar`, and `bzip2`. | ||
| 153 | - Cleanup: delete `$LEO` and `runtime/build/linux`. micromamba also writes `~/.conda/environments.txt` and | ||
| 154 | `~/.mamba/pkgs/urls.txt` (delete only those files if you already use conda). | ||
diff --git a/docs/linux_proton.md b/docs/linux_proton.md index f98aacf14..de4760d70 100644 --- a/docs/linux_proton.md +++ b/docs/linux_proton.md | |||
| @@ -53,12 +53,61 @@ the layout the comments at their top describe (`/opt/leonida` for traces, overla | |||
| 53 | `__GL_SHADER_DISK_CACHE_SKIP_CLEANUP=1`. | 53 | `__GL_SHADER_DISK_CACHE_SKIP_CLEANUP=1`. |
| 54 | - **Input:** a pad through GameInput/SDL3, or the keyboard pad (`LEONIDA_KEYBOARD_PAD=always`), or a script: | 54 | - **Input:** a pad through GameInput/SDL3, or the keyboard pad (`LEONIDA_KEYBOARD_PAD=always`), or a script: |
| 55 | `LEONIDA_INPUT_SCRIPT=a@210,a@240` presses A at those seconds (any length since this branch; it was cut at 63 | 55 | `LEONIDA_INPUT_SCRIPT=a@210,a@240` presses A at those seconds (any length since this branch; it was cut at 63 |
| 56 | characters before). | 56 | characters before). The script also works in a build without SDL3, where it drives one scripted pad |
| 57 | ([docs/gameinput.md](gameinput.md#scripted-input-without-sdl3)); pads and the keyboard pad need SDL3. | ||
| 57 | - **Window:** frames are presented in the title's own window; `LEONIDA_PRESENT_WINDOW=own|hidden` chooses otherwise. | 58 | - **Window:** frames are presented in the title's own window; `LEONIDA_PRESENT_WINDOW=own|hidden` chooses otherwise. |
| 58 | 59 | ||
| 59 | Three setup mistakes each give a blank or empty picture without an error: the executable's embedded shaders missing | 60 | Three setup mistakes each give a blank or empty picture without an error: the executable's embedded shaders missing |
| 60 | from the library (`exe/index.json`), a build without SDL3 (no pad), and a BCPack predictor file that was never | 61 | from the library (`exe/index.json`), a build without SDL3 and without `LEONIDA_INPUT_SCRIPT` (no pad, so nothing |
| 61 | generated (`tools/build_dstorage_history.py`; without it the loading art and most BC7 textures stay empty). | 62 | gets past the first prompt; set a script, or build with SDL3 for a pad or the keyboard pad), and a BCPack predictor |
| 63 | file that was never generated (`tools/build_dstorage_history.py`; without it the loading art and most BC7 textures | ||
| 64 | stay empty). | ||
| 65 | |||
| 66 | ## Running the game under Wine with one command | ||
| 67 | |||
| 68 | `scripts/run_game_wine.sh` makes one bounded, silent run of the retail game under Wine and prints counts only. It | ||
| 69 | complements `scripts/run_wine_session.sh` (the runtime's unit tests under Wine) and the `systemd --user` boot | ||
| 70 | wrappers described above: it needs no fixed paths, and its output is a summary that can go into an issue. | ||
| 71 | |||
| 72 | ```sh | ||
| 73 | scripts/run_game_wine.sh --build <build folder or checkout> --exe <game executable> --game-dir <package folder> \ | ||
| 74 | --shaders <translated library> --out <new run folder> --device 1002:744c --seconds 600 | ||
| 75 | ``` | ||
| 76 | |||
| 77 | `--help` lists every input. Each path comes from an argument or from `LEONIDA_GAME_EXE`, `LEONIDA_GAME_DIR` and | ||
| 78 | `LEONIDA_SHADERS`; `WINE` names another Wine (Proton's `files/bin/wine`), and `WINEPREFIX` (or `--prefix`) a prefix to | ||
| 79 | reuse instead of a new one in the run folder. | ||
| 80 | |||
| 81 | What it needs: | ||
| 82 | |||
| 83 | - **Wine** (the `wine` on `PATH`, or `WINE`), `timeout`, `flock`, `setsid` and Python 3. | ||
| 84 | - **A Vulkan driver** for the GPU (Mesa's RADV was tested). `--device VID:DID` pins it through | ||
| 85 | `MESA_VK_DEVICE_SELECT`; without it the script warns that Mesa picks the device. | ||
| 86 | - **A display.** By default the run is headless: a private `kwin_wayland --virtual --xwayland` session under | ||
| 87 | `dbus-run-session`, with its own `XDG_RUNTIME_DIR` in the run folder, so nothing appears on the desktop. Its | ||
| 88 | rootless Xwayland offers DRI3, which RADV needs to present; Xvfb has none, so without `kwin_wayland` the script | ||
| 89 | says what is missing instead of falling back. `--visible` opens the window on the current `DISPLAY` instead. | ||
| 90 | - **A runtime build**: a folder with `gta6rt.exe` and `gta6rt_tls_host.dll`, or a checkout, whose `runtime/` it | ||
| 91 | cross-builds first with clang-cl and xwin (`XWIN_DIR`, see [linux.md](linux.md#the-runtime-under-wine-or-proton)). | ||
| 92 | |||
| 93 | What it does: | ||
| 94 | |||
| 95 | - **Sound off:** Wine's audio drivers are disabled through `WINEDLLOVERRIDES`, PulseAudio, PipeWire and ALSA point | ||
| 96 | at nothing, and `LEONIDA_AUDIO=silent` makes the runtime serve its silent output endpoint | ||
| 97 | ([runtime_imports.md](runtime_imports.md)); the summary says whether it was served. | ||
| 98 | - **Limits:** a hard time limit (`--seconds`, then SIGTERM and SIGKILL 10 s later), a lock so one run happens at a | ||
| 99 | time (`--lock`, by default in `XDG_RUNTIME_DIR`), and teardown of Wine and the whole session on exit, time-out or | ||
| 100 | signal. | ||
| 101 | - **Traces:** `gta6rt --run` with `--trace` and `--trace-d3d12`, a fresh `--overlay` and save folder in the run | ||
| 102 | folder. Every other `LEONIDA_*` variable reaches the runtime unchanged, so `LEONIDA_INPUT_SCRIPT=a@210,a@240` | ||
| 103 | presses A as above. Arguments after `--` go to `gta6rt`. | ||
| 104 | - **Summary:** `tools/game_run_summary.py` prints the run time, how it ended, exceptions by code, D3D12 calls by | ||
| 105 | outcome, presents, the most frequent failing calls and the `[rt]` lines by category with numbers masked. It never | ||
| 106 | prints a log line. `--screenshot-every S` captures the game window into the run folder (ImageMagick's `import` and | ||
| 107 | `xprop`). | ||
| 108 | |||
| 109 | The run folder's `stderr.log`, `boot.jsonl` and screenshots can show or quote what the title prints, so they stay on | ||
| 110 | your machine; share the summary. | ||
| 62 | 111 | ||
| 63 | ## What a healthy boot looks like (Linux machine) | 112 | ## What a healthy boot looks like (Linux machine) |
| 64 | 113 | ||
diff --git a/docs/mobile.md b/docs/mobile.md index 5ea35ca04..d2a8b9dca 100644 --- a/docs/mobile.md +++ b/docs/mobile.md | |||
| @@ -28,7 +28,7 @@ of the x86-64 → arm64 groundwork. | |||
| 28 | |---|---|---| | 28 | |---|---|---| |
| 29 | | x86-64 decoder | `tools/x64_recomp.py` `disasm`/`decode_one` | prefixes/REX, ModRM+SIB, RIP-relative and moffs addressing, hi8 regs (`ah`/`ch`/`dh`/`bh`), `Iv`/`Iz`/`J` immediates incl. imm64, groups 1–5/8/15/1A/11, VEX stubs | | 29 | | x86-64 decoder | `tools/x64_recomp.py` `disasm`/`decode_one` | prefixes/REX, ModRM+SIB, RIP-relative and moffs addressing, hi8 regs (`ah`/`ch`/`dh`/`bh`), `Iv`/`Iz`/`J` immediates incl. imm64, groups 1–5/8/15/1A/11, VEX stubs | |
| 30 | | arm64 assembler | `tools/x64_recomp.py` `Asm` | integer/logical/bitfield/shift/multiply/load-store/branch/system encoders, label fixups, `li()` with `pad4` for self-referential constant materialization | | 30 | | arm64 assembler | `tools/x64_recomp.py` `Asm` | integer/logical/bitfield/shift/multiply/load-store/branch/system encoders, label fixups, `li()` with `pad4` for self-referential constant materialization | |
| 31 | | Translator | `tools/x64_recomp.py` `FunctionTranslator` | linear-sweep over decoded insns; lazy flag analysis picks arm-NZCV when one producer covers a consumer, else materializes canonical x86 EFLAGS in the ctx block; unsupported insns emit `brk` and land in `stats["unhandled"]` | | 31 | | Translator | `tools/x64_recomp.py` `FunctionTranslator` | linear-sweep over decoded insns; lazy flag analysis picks arm-NZCV when one producer covers a consumer, else materializes canonical x86 EFLAGS in the ctx block; a shift or rotate by `cl` may leave the flags alone (x86 changes none for a count of 0), so a consumer behind one reads the ctx word and the writer before it stores its word too; unsupported insns emit `brk` and land in `stats["unhandled"]` | |
| 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 | |
diff --git a/docs/models.md b/docs/models.md index 85b805feb..ba1cd5433 100644 --- a/docs/models.md +++ b/docs/models.md | |||
| @@ -799,7 +799,7 @@ the drawable's local joint palette through the drawable and ped tables, and emit | |||
| 799 | in [character_skeleton.md](character_skeleton.md#skinned-glb-export). On the 1.0.2.1 package, the | 799 | in [character_skeleton.md](character_skeleton.md#skinned-glb-export). On the 1.0.2.1 package, the |
| 800 | head (8,983 v) and biker jacket (9,818 v) produce one skin with 596 ped joints (703 with the | 800 | head (8,983 v) and biker jacket (9,818 v) produce one skin with 596 ped joints (703 with the |
| 801 | jacket's `GM_U01_*` helpers); every weight sums to 255 and the rest-pose reconstruction error is | 801 | jacket's `GM_U01_*` helpers); every weight sums to 255 and the rest-pose reconstruction error is |
| 802 | 6e-8 m. `python -I tests/test_skinned_glb.py` runs 24 synthetic tests and needs no game files. | 802 | 6e-8 m. `python -I tests/test_skinned_glb.py` runs 30 synthetic tests and needs no game files. |
| 803 | 803 | ||
| 804 | `tools/glb_inspect.py` reads such a GLB back without a library, so an export can be checked | 804 | `tools/glb_inspect.py` reads such a GLB back without a library, so an export can be checked |
| 805 | before it is opened in a viewer: | 805 | before it is opened in a viewer: |
diff --git a/docs/movies.md b/docs/movies.md index e8df76d29..252bef758 100644 --- a/docs/movies.md +++ b/docs/movies.md | |||
| @@ -114,8 +114,9 @@ and then only to a temporary file that is deleted. | |||
| 114 | 114 | ||
| 115 | On this archive both tools find the same 515 streams, the same 8,831,336,892 bytes, 1,094,744 bytes of zero | 115 | On this archive both tools find the same 515 streams, the same 8,831,336,892 bytes, 1,094,744 bytes of zero |
| 116 | padding and 22,812 bytes after the last stream. Those 22,812 are 3,884 zero bytes and the 18,928-byte RPF trailer | 116 | padding and 22,812 bytes after the last stream. Those 22,812 are 3,884 zero bytes and the 18,928-byte RPF trailer |
| 117 | (counted by reading the tail directly); `bink_index.py` now counts them as zero padding and `rpf_trailer`, which for | 117 | (counted by reading the tail directly). A read-only rerun of `bink_index.py` at `2d53a8055` on 2026-11-23 |
| 118 | this archive gives `unread_bytes` 0 and zero padding 1,098,628 (derived from the measured tail, not a rerun). Running `bink_index.py` on the 515 carved | 118 | confirmed 1,098,628 bytes of zero padding, 18,928 trailer bytes and 0 unread bytes. The archive matched the |
| 119 | 1.0.2.1 manifest by size and SHA-256. Running `bink_index.py` on the 515 carved | ||
| 119 | `.bk2` files finds 515 streams with zero unread bytes, which confirms the stored sizes cover each file exactly. | 120 | `.bk2` files finds 515 streams with zero unread bytes, which confirms the stored sizes cover each file exactly. |
| 120 | 121 | ||
| 121 | ## 4. Decoding | 122 | ## 4. Decoding |
diff --git a/docs/pipeline_check.md b/docs/pipeline_check.md index d5d76cb93..4d5be5e35 100644 --- a/docs/pipeline_check.md +++ b/docs/pipeline_check.md | |||
| @@ -256,7 +256,7 @@ acceptance only. | |||
| 256 | 256 | ||
| 257 | A SPIR-V module larger than 4 MiB is "large". [#884](https://github.com/ItsNotRexed/Leonida/issues/884) | 257 | A SPIR-V module larger than 4 MiB is "large". [#884](https://github.com/ItsNotRexed/Leonida/issues/884) |
| 258 | showed why that matters: several compiles that each needed gigabytes of host RAM ran at the same time. Large | 258 | showed why that matters: several compiles that each needed gigabytes of host RAM ran at the same time. Large |
| 259 | modules now share a memory budget (`runtime/test/large_module_gate.h`): each one reserves 512 bytes of RAM per | 259 | modules now share a memory budget (`runtime/src/large_module_gate.h`): each one reserves 512 bytes of RAM per |
| 260 | SPIR-V byte, and they enter the driver while their reservations fit three quarters of the memory available when | 260 | SPIR-V byte, and they enter the driver while their reservations fit three quarters of the memory available when |
| 261 | the run starts, up to `--jobs` of them. One large module always gets in when none is compiling, so a module | 261 | the run starts, up to `--jobs` of them. One large module always gets in when none is compiling, so a module |
| 262 | bigger than the whole budget still compiles, alone among the large ones. Small modules are never held back. On | 262 | bigger than the whole budget still compiles, alone among the large ones. Small modules are never held back. On |
| @@ -457,6 +457,10 @@ driver gives it the same cache key in both programs. Measured on Windows with an | |||
| 457 | `VK_KHR_maintenance8` into the pipeline cache key even for compute shaders, so the checker enables both whenever | 457 | `VK_KHR_maintenance8` into the pipeline cache key even for compute shaders, so the checker enables both whenever |
| 458 | supported and keeps `meshShaderQueries` on. | 458 | supported and keeps `meshShaderQueries` on. |
| 459 | - On a Windows RTX 5070 Ti (617.42), a compute-only seed missed with mesh features omitted and hit with the supported mesh and mesh-query features enabled on both devices. The shader, push constants and pipeline layout were identical. Cache-producing runs request this device configuration for every selected shader batch. | 459 | - On a Windows RTX 5070 Ti (617.42), a compute-only seed missed with mesh features omitted and hit with the supported mesh and mesh-query features enabled on both devices. The shader, push constants and pipeline layout were identical. Cache-producing runs request this device configuration for every selected shader batch. |
| 460 | - On Windows with an AMD Radeon RX 7900 XT, `VK_EXT_transform_feedback` (with `transformFeedback` enabled, and | ||
| 461 | `geometryStreams` when the device offers it) is part of the key: the runtime enables it whenever the extension is | ||
| 462 | present (D3D-302), so the checker enables it too. Without it, `pipeline_cache_seed` failed 3 of 3 on that GPU and | ||
| 463 | passed 3 of 3 on `main`. NVIDIA leaves it out of the key, which is why it did not show up on the RTX 3080 Ti. | ||
| 460 | - The executable's file name is part of the key; its folder is not. A copy of the checker under another name | 464 | - The executable's file name is part of the key; its folder is not. A copy of the checker under another name |
| 461 | misses the cache the original wrote, and the runtime's device hits the checker's cache only from a program | 465 | misses the cache the original wrote, and the runtime's device hits the checker's cache only from a program |
| 462 | with the checker's file name. So on this driver a cache written by `vk_pipeline_check.exe` does not hit in | 466 | with the checker's file name. So on this driver a cache written by `vk_pipeline_check.exe` does not hit in |
diff --git a/docs/progress_dashboard.md b/docs/progress_dashboard.md index 88647e1f0..8a99ebd8b 100644 --- a/docs/progress_dashboard.md +++ b/docs/progress_dashboard.md | |||
| @@ -13,6 +13,21 @@ start ..\leonida_progress\progress.html | |||
| 13 | The page is one self-contained HTML file: no network, no packages, it opens from disk. The project logo | 13 | The page is one self-contained HTML file: no network, no packages, it opens from disk. The project logo |
| 14 | (`assets/logo.png`) is embedded in it, and the page follows the system theme until you pick one with its theme button. | 14 | (`assets/logo.png`) is embedded in it, and the page follows the system theme until you pick one with its theme button. |
| 15 | 15 | ||
| 16 | Use a CTest JUnit report when the run includes tests configured with `SKIP_RETURN_CODE`. CTest can log those | ||
| 17 | skips as `Test Passed.` in `LastTest.log`. `--ctest-junit` replaces the local log with the report, which preserves | ||
| 18 | the skipped status. Use `--junit` to add independent runs. A new file name for each run keeps an aborted CTest run | ||
| 19 | from reusing an older report. | ||
| 20 | |||
| 21 | ```powershell | ||
| 22 | $report = Join-Path $env:TEMP ("leonida-ctest-{0}.xml" -f [guid]::NewGuid()) | ||
| 23 | ctest --test-dir runtime/build -C RelWithDebInfo --output-on-failure --output-junit $report | ||
| 24 | if (Test-Path -LiteralPath $report -PathType Leaf) { | ||
| 25 | python -I tools/progress_dashboard.py --out ..\leonida_progress --ctest-junit $report | ||
| 26 | } else { | ||
| 27 | throw "CTest did not produce a JUnit report (exit $LASTEXITCODE)." | ||
| 28 | } | ||
| 29 | ``` | ||
| 30 | |||
| 16 | ## Sources | 31 | ## Sources |
| 17 | 32 | ||
| 18 | Each source is optional. A missing one is listed under "Sources" on the page; it is never counted as zero or as a failure. | 33 | Each source is optional. A missing one is listed under "Sources" on the page; it is never counted as zero or as a failure. |
diff --git a/docs/related_projects.md b/docs/related_projects.md index b1e8e77ec..a3a58ff99 100644 --- a/docs/related_projects.md +++ b/docs/related_projects.md | |||
| @@ -139,6 +139,24 @@ re-measured on this package by `tools/navmesh_nodes.py` | |||
| 139 | confirmed by the lane-graph heights. The label is consistent with the count, but not settled by it: nine in ten | 139 | confirmed by the lane-graph heights. The label is consistent with the count, but not settled by it: nine in ten |
| 140 | lane nodes stand on polygons with both bit 8 and bit 13, and which bit or combination means road surface is open. | 140 | lane nodes stand on polygons with both bit 8 and bit 13, and which bit or combination means road surface is open. |
| 141 | 141 | ||
| 142 | ## Marvisak/VIctory | ||
| 143 | |||
| 144 | <https://github.com/Marvisak/VIctory> | ||
| 145 | |||
| 146 | A Windows compatibility project for Xbox Series. Its GPU layer translates console command streams to host | ||
| 147 | Direct3D 12. | ||
| 148 | |||
| 149 | **Licence:** **GPL-3.0-or-later**, as declared in the [workspace manifest][victory-workspace] and the | ||
| 150 | [README][victory-readme]. The [GPU crate][victory-gpu] inherits the workspace licence. | ||
| 151 | |||
| 152 | **What we use it for:** prior art for deferring CPU-side value writes until the recorded command-list work has | ||
| 153 | completed, as discussed in [#622](https://github.com/ubiquitarianism/leonida/pull/622). That PR uses synthetic | ||
| 154 | tests to verify the ordering of submissions and writes in Leonida's own implementation. | ||
| 155 | |||
| 156 | [victory-workspace]: https://github.com/Marvisak/VIctory/blob/ffe310eb2098e52169f4c44db5ffdabf43a72622/Cargo.toml | ||
| 157 | [victory-readme]: https://github.com/Marvisak/VIctory/blob/ffe310eb2098e52169f4c44db5ffdabf43a72622/README.md#license | ||
| 158 | [victory-gpu]: https://github.com/Marvisak/VIctory/blob/ffe310eb2098e52169f4c44db5ffdabf43a72622/crates/victory-gpu/Cargo.toml | ||
| 159 | |||
| 142 | ## microsoft/libHttpClient | 160 | ## microsoft/libHttpClient |
| 143 | 161 | ||
| 144 | <https://github.com/microsoft/libHttpClient> | 162 | <https://github.com/microsoft/libHttpClient> |
diff --git a/docs/retail_boot_chain.md b/docs/retail_boot_chain.md index e693b2a2b..70953f46b 100644 --- a/docs/retail_boot_chain.md +++ b/docs/retail_boot_chain.md | |||
| @@ -106,3 +106,53 @@ not an `E_NOTIMPL`. | |||
| 106 | 106 | ||
| 107 | These are one run's first failures, not a list of what is missing. Every stand-in above is local and untested | 107 | These are one run's first failures, not a list of what is missing. Every stand-in above is local and untested |
| 108 | beyond "the title goes on to the next call". Nothing has reached a draw or a present yet. | 108 | beyond "the title goes on to the next call". Nothing has reached a draw or a present yet. |
| 109 | |||
| 110 | ## 5. The device slots the executable calls, from the file (RT-566) | ||
| 111 | |||
| 112 | The chain above finds the next slot by running the title; `tools/d3d12_device_calls.py` reads the file alone, | ||
| 113 | without running anything, and reports the statically resolved `ID3D12Device` vtable call sites for the device paths | ||
| 114 | it follows: | ||
| 115 | |||
| 116 | ```sh | ||
| 117 | python -I tools/d3d12_device_calls.py <game>/game_scarlett_master.exe --out <work>/device_calls | ||
| 118 | ``` | ||
| 119 | |||
| 120 | It writes `<exe>.device_calls.txt` (slot numbers and counts only) and `.json` (the same, plus each site's RVA for | ||
| 121 | local follow-up; don't paste that part) into the `--out` folder. It reads the executable only, so a slot called only | ||
| 122 | from a bundled DLL is absent from it: slot 76, for one, isn't in the census, yet `docs/d3d12_vulkan.md` (the slot 76 | ||
| 123 | row of its contract table, and §4.2) records the FidelityFX upscaler DLL creating its resources through it. A slot | ||
| 124 | missing from the census is not a slot the title never uses. The method, in its docstring: it finds the | ||
| 125 | `D3D12XboxCreateDevice` call sites, follows the out-pointer in `r9` to the global or stack slot it fills and the | ||
| 126 | globals the device is copied to, and counts per slot the `mov vtable,[device]` → `call [vtable+disp]` (or | ||
| 127 | `call reg`, or a call to a dispatch routine with the method in `rax`) sites, with `disp / 8` as the slot. A | ||
| 128 | dispatch routine counts only when its code reaches `jmp rax` or `call rax` without writing `rax`, calling or | ||
| 129 | returning first; a call to any other target with a method in `rax` is reported as not resolved. Per slot it shows | ||
| 130 | calls and tail jumps, whether the device is in `rcx` or in `rdx` (the return-buffer form of §3.1), and an | ||
| 131 | argument-count estimate. Slots 0-43 carry the PC method names, which the console keeps where measured (8, 9, 14, 26, | ||
| 132 | 36); past 43 only the slots `runtime/shims/d3d12_xs_device.h` and §3 name are named. | ||
| 133 | |||
| 134 | The walk follows forward branches within a function (a `jmp rel32` there is a branch, not a tail call) and keeps | ||
| 135 | a fact at a join only when both paths agree. What it doesn't see, and says so: the device reached through an object | ||
| 136 | member, a function parameter or a getter's return value; a path it loses, such as a loop's back edge; an indexed | ||
| 137 | method load. The report counts the vtable loads with no matched call, the calls with a method in `rax` | ||
| 138 | to a target that isn't a verified dispatch routine, the calls that are handed the device (not followed into), and | ||
| 139 | the stores of the device to non-stack memory. A slot can be called more often than the report says, or on a | ||
| 140 | path it doesn't follow, so a slot with no row (12 and 51, for example) isn't shown to be uncalled. | ||
| 141 | |||
| 142 | On the 1.0.2.1 executable it finds one `D3D12XboxCreateDevice` call site writing a global and 95 sites across | ||
| 143 | 42 slots: 94 indirect vtable calls and one indirect vtable tail jump (at slot 2), with no dispatch call resolved; | ||
| 144 | the `rdx` form at slots 25, 26 and 108 only; and 12 sites it reports as not resolved. Every device slot | ||
| 145 | the chain above reached (8, 26, 48, 73, 133) is among them; slots like 49, 55, 57, 61, 70, 71, 74, 81, 86, 101, | ||
| 146 | 108, 119, 127 and 132 are called but have no name in this repository yet. | ||
| 147 | |||
| 148 | For some of the unnamed slots there is a call shape from an independent static read with a different scanner, by | ||
| 149 | TreXito (in the review of old upstream PR 7998), with the same site counts for 49, 50, 55, 57, 71 and 81. These | ||
| 150 | are their reads, not this tool's: | ||
| 151 | |||
| 152 | | Slot | What the call is (TreXito's read) | | ||
| 153 | |---:|---| | ||
| 154 | | 49 | Only behind an OS-version gate; no run reaches it today | | ||
| 155 | | 50 | Only on a fatal path that ends in `int3` | | ||
| 156 | | 55 | `CreateDerivedPipelineState(base, n, records, riid, out)`, on a PSO-cache hit (old upstream PR 7759) | | ||
| 157 | | 57 | `(desc, IID_ID3D12PipelineState, out)`, the native-record graphics pipeline | | ||
| 158 | | 81 | `(object, a constant flags argument, &count, out)`; the result is used only on success | | ||
diff --git a/docs/rpf.md b/docs/rpf.md index 7bc656845..8b374ce42 100644 --- a/docs/rpf.md +++ b/docs/rpf.md | |||
| @@ -129,6 +129,17 @@ scanners on a 48 MiB gap and checks that each one's Python heap peak stays under | |||
| 129 | The carve is read-only and works on any `.rpf`, `.ttpf` or archive-like file. It does not decrypt the TOC, use | 129 | The carve is read-only and works on any `.rpf`, `.ttpf` or archive-like file. It does not decrypt the TOC, use |
| 130 | keys, or write anything outside the output directory. | 130 | keys, or write anything outside the output directory. |
| 131 | 131 | ||
| 132 | Once one or more archives have been carved under `<work>\carve`, `tools/classify_carve.py` groups every entry by | ||
| 133 | signature using only the per-archive `index.json` files (no carved payload reads): | ||
| 134 | |||
| 135 | ```powershell | ||
| 136 | python -I tools/classify_carve.py <work>\carve | ||
| 137 | ``` | ||
| 138 | |||
| 139 | It classifies each entry as `bink2` (`KB2x`), `rbf0` (`52424630`), `respage` (`42400000`), `gpu-zerohdr` (16+ leading | ||
| 140 | zero bytes), or `other:<hex>` (first 4 bytes), prints a summary table, and writes `<work>\carve\types.json` with | ||
| 141 | overall and per-archive file counts, total bytes, and `min`/`max`/`median` (`median_low`) byte sizes. | ||
| 142 | |||
| 132 | ## Recovery tools | 143 | ## Recovery tools |
| 133 | 144 | ||
| 134 | `tools/rpf9dump` is a bulk exporter built on the Core library from | 145 | `tools/rpf9dump` is a bulk exporter built on the Core library from |
diff --git a/docs/runtime_imports.md b/docs/runtime_imports.md index 3d6efb25f..e38dfbf74 100644 --- a/docs/runtime_imports.md +++ b/docs/runtime_imports.md | |||
| @@ -290,10 +290,17 @@ and the `api-ms-win-core-file-*` sets a GDK title links against. | |||
| 290 | passed to the host unchanged. `--game-dir` defaults to the image's folder. `gta6rt` makes it and `--overlay` | 290 | passed to the host unchanged. `--game-dir` defaults to the image's folder. `gta6rt` makes it and `--overlay` |
| 291 | absolute at startup, so a bare image name (`gta6rt --run game.exe` from the game folder) and a relative folder | 291 | absolute at startup, so a bare image name (`gta6rt --run game.exe` from the game folder) and a relative folder |
| 292 | both keep naming the same place after the title changes its current directory (CTest `run_tiny_game_dir`). | 292 | both keep naming the same place after the title changes its current directory (CTest `run_tiny_game_dir`). |
| 293 | `G:\` is the same folder as `GAME:`, and `T:\` is a scratch folder, `<overlay>\.gta6rt-temp`, that `GAME:` does | 293 | `G:\` is the same folder as `GAME:`, and `T:\` is a scratch folder that `GAME:` does not see (RT-218; the other |
| 294 | not see (RT-218; the other console layers map those two drives this way, and only the executable can say which | 294 | console layers map those two drives this way, and only the executable can say which spelling GTA VI uses). Each |
| 295 | spelling GTA VI uses). A path under `--game-dir` or the overlay is always a host path, so a package that sits on | 295 | process has its own, `<overlay>\.gta6rt-temp\<YYYYMMDD-HHMMSS-mmm>-pid<id>` (start time in UTC and process id, |
| 296 | a host drive `G:` keeps working, and with no folders configured `G:` and `T:` stay host drives. | 296 | `rt::fs::scratch_dir()`, named on the startup line), as the console's temporary drive is empty at launch and |
| 297 | shared with no other run: with one folder for all runs, a `CREATE_NEW` of a name an earlier run left failed with | ||
| 298 | `ERROR_FILE_EXISTS` (old upstream issue 7913). `rt::fs::reserve_unique_dir` reserves it once per overlay with a | ||
| 299 | create-only `CreateDirectoryW`; a name that already exists (a reused process id in the same millisecond) is skipped | ||
| 300 | for `-2`, `-3`, ... up to 1000 names, after which `T:` paths fail with `ERROR_INVALID_NAME` and the reason is | ||
| 301 | printed once. Earlier runs' folders are kept, never reused, and `T:\..` cannot reach them. A path under | ||
| 302 | `--game-dir` or the overlay is always a host path, so a package that sits on a host drive `G:` keeps working, and | ||
| 303 | with no folders configured `G:` and `T:` stay host drives. | ||
| 297 | `T:\` is a drive root like `GAME:\`: its folder is made on the first `T:` call, so it is a folder before anything | 304 | `T:\` is a drive root like `GAME:\`: its folder is made on the first `T:` call, so it is a folder before anything |
| 298 | is written there, and removing or moving it fails with `ERROR_ACCESS_DENIED`. | 305 | is written there, and removing or moving it fails with `ERROR_ACCESS_DENIED`. |
| 299 | - An open that can write, and `DeleteFile`, use the overlay: `--overlay DIR`, default `<game-dir>\overlay`. A | 306 | - An open that can write, and `DeleteFile`, use the overlay: `--overlay DIR`, default `<game-dir>\overlay`. A |
| @@ -317,7 +324,9 @@ and the `api-ms-win-core-file-*` sets a GDK title links against. | |||
| 317 | package has, fails with `ERROR_ALREADY_EXISTS`; a missing parent with `ERROR_PATH_NOT_FOUND`. | 324 | package has, fails with `ERROR_ALREADY_EXISTS`; a missing parent with `ERROR_PATH_NOT_FOUND`. |
| 318 | - `RemoveDirectory*` needs the folder empty in the title's view (`ERROR_DIR_NOT_EMPTY` otherwise). An overlay folder is | 325 | - `RemoveDirectory*` needs the folder empty in the title's view (`ERROR_DIR_NOT_EMPTY` otherwise). An overlay folder is |
| 319 | removed; a package folder is hidden by a `.gta6rt-dir` marker inside its marker folder, and stays on disk. A marker | 326 | removed; a package folder is hidden by a `.gta6rt-dir` marker inside its marker folder, and stays on disk. A marker |
| 320 | folder on its own (left by a file deleted below it) does not hide anything. | 327 | folder on its own (left by a file deleted below it) does not hide anything. A remove and a write-open or |
| 328 | `CreateDirectory*` inside the folder on another thread are ordered as on the host: one goes first, and the create | ||
| 329 | fails with `ERROR_PATH_NOT_FOUND` or the remove with `ERROR_DIR_NOT_EMPTY`, never both succeeding. | ||
| 321 | - `MoveFile*` writes the destination in the overlay. A package file is copied there and its old name deleted by a | 330 | - `MoveFile*` writes the destination in the overlay. A package file is copied there and its old name deleted by a |
| 322 | marker; an overlay file or an overlay-only folder is renamed. An existing destination needs | 331 | marker; an overlay file or an overlay-only folder is renamed. An existing destination needs |
| 323 | `MOVEFILE_REPLACE_EXISTING` even when only the package has it. Moving a package folder fails with | 332 | `MOVEFILE_REPLACE_EXISTING` even when only the package has it. Moving a package folder fails with |
| @@ -411,6 +420,22 @@ families are not listed. The sources are the Microsoft Learn pages for the D3D12 | |||
| 411 | (`gaming/gdk/docs/reference/system/<family>/functions/<name>`); `D3D12XboxCreateDevice` is matched by name from the | 420 | (`gaming/gdk/docs/reference/system/<family>/functions/<name>`); `D3D12XboxCreateDevice` is matched by name from the |
| 412 | measurement in `d3d12_vulkan.md`, because its page could not be found. | 421 | measurement in `d3d12_vulkan.md`, because its page could not be found. |
| 413 | 422 | ||
| 423 | ### Delay imports and thread events: where the loader differs from Windows | ||
| 424 | |||
| 425 | - **Delay imports are bound eagerly.** `Loader::bind_imports` (`runtime/src/pe_loader.cpp`) binds the delay-import | ||
| 426 | table at load time, like the import table, so `--dry-run` shows the whole import surface. A delay-loaded DLL or | ||
| 427 | function that nothing serves becomes an unimplemented thunk, which follows `LEONIDA_UNIMPLEMENTED` at its first | ||
| 428 | call (return 0 by default). On Windows the delay-load helper raises `0xC06D007E` (module not found) or | ||
| 429 | `0xC06D007F` (procedure not found) at that call instead, and a title can catch it and take a fallback; that fallback | ||
| 430 | never runs here. `--trace` writes a `delay_import_unimplemented` event (`module`, `import`) for each such import | ||
| 431 | when the image is loaded. | ||
| 432 | - **Thread events reach TLS callbacks in TLS slot order.** A new thread's `DLL_THREAD_ATTACH` runs the mapped | ||
| 433 | modules' TLS callbacks in the order of their TLS slots (`DLL_THREAD_DETACH` in reverse). A module takes the lowest | ||
| 434 | free slot when it is mapped, before its imports are loaded, so the executable's callbacks run before those of the | ||
| 435 | DLLs it imports; a slot freed by an unloaded module goes to the next one. Windows does not document its order, so a | ||
| 436 | title that depends on DLL-first order would see a difference here. Mapped DLLs' `DllMain` gets no thread events | ||
| 437 | (`runtime/README.md`, PE loader). | ||
| 438 | |||
| 414 | ## Run-time loaded modules | 439 | ## Run-time loaded modules |
| 415 | 440 | ||
| 416 | Not every console module is reached through an import table. `libHttpClient.GDK.dll` and `XCurl.dll` both use the | 441 | Not every console module is reached through an import table. `libHttpClient.GDK.dll` and `XCurl.dll` both use the |
diff --git a/docs/shader_library.md b/docs/shader_library.md index 3ef944a52..41cea0685 100644 --- a/docs/shader_library.md +++ b/docs/shader_library.md | |||
| @@ -178,7 +178,7 @@ them and the state key is the record's state blob. The step is redone as a whole | |||
| 178 | `llvm-mc`, the wave64 mode or the flags change (`library_build.json`, written last), and a clash of both keys between | 178 | `llvm-mc`, the wave64 mode or the flags change (`library_build.json`, written last), and a clash of both keys between |
| 179 | different modules fails it, as for the FSPX step. Graphics pipelines are not translated by the build. | 179 | different modules fails it, as for the FSPX step. Graphics pipelines are not translated by the build. |
| 180 | 180 | ||
| 181 | ### Resuming a compute-only batch on Linux | 181 | ### Resuming a compute-only batch on Linux or native Windows |
| 182 | 182 | ||
| 183 | Run `tools/shader_library.py` with `--stages cs --disasm --jobs 2` and the carved containers, or select the | 183 | Run `tools/shader_library.py` with `--stages cs --disasm --jobs 2` and the carved containers, or select the |
| 184 | kind-6 hashes with `--compute-hashes`. For an unpacked library with its input `index.json`, use the compute batch. | 184 | kind-6 hashes with `--compute-hashes`. For an unpacked library with its input `index.json`, use the compute batch. |
| @@ -187,14 +187,27 @@ kind-6 hashes with `--compute-hashes`. For an unpacked library with its input `i | |||
| 187 | python3 -I scripts/translate_pipeline_compute.py /path/to/unpacked --out /path/to/spirv/library --wave64-emulate | 187 | python3 -I scripts/translate_pipeline_compute.py /path/to/unpacked --out /path/to/spirv/library --wave64-emulate |
| 188 | ``` | 188 | ``` |
| 189 | 189 | ||
| 190 | Use a dedicated output folder. The two workers run at nice 19. Each has a 768 MiB address-space limit and uses one | 190 | Use a dedicated output folder and a stable, trusted SPIRV-Tools installation on PATH. On Linux the two workers |
| 191 | SPIRV-Tools process at a time (four processes total). `--jobs 1` uses a single worker and `--memory-mib` changes | 191 | run at nice 19. Each has a 768 MiB address-space limit and uses one SPIRV-Tools process at a time (four processes |
| 192 | the per-process limit. A rerun checks each module against its checksum and the listing, source container, FSPX | 192 | total). On native Windows CPython, a BelowNormal coordinator and up to two gated workers run with a 768 MiB |
| 193 | **committed memory** cap per process (not total virtual address space). Each worker's kill-on-close Job permits | ||
| 194 | only itself and one tool process. The parent verifies job membership before sending work; the child rechecks the | ||
| 195 | effective limits. A no-share file open keeps the pack exclusive through worker exit. An incompatible outer Job | ||
| 196 | or a failed limit/lock check stops the build; there is no unbounded Windows mode. A hard stop can leave temporary | ||
| 197 | scratch files, but cannot partially replace the index. `--jobs 1` uses a single translating worker and | ||
| 198 | `--memory-mib` changes the per-process limit. A rerun checks each module against its checksum and the listing, source container, FSPX | ||
| 193 | sidecars, toolchain and wave mode. It retries failures. Only validated modules enter the runtime index. Its | 199 | sidecars, toolchain and wave mode. It retries failures. Only validated modules enter the runtime index. Its |
| 194 | atomic replacement follows both workers, so an interrupted run leaves the previous index readable. A partial | 200 | atomic replacement follows both workers, so an interrupted run leaves the previous index readable. A partial |
| 195 | run exits nonzero and writes the reasons to `failures.json`, keyed by kind-6 and kind-0 SHA-256. Old modules | 201 | run exits nonzero and writes the reasons to `failures.json`, keyed by kind-6 and kind-0 SHA-256. Old modules |
| 196 | can still be used by a runtime that already opened the preceding index. | 202 | can still be used by a runtime that already opened the preceding index. |
| 197 | 203 | ||
| 204 | The coordinator and each shard explicitly apply `--wave64-emulate`, `--loop-limit`, `--descriptor-hash` and | ||
| 205 | `--compact-spirv`; requesting compaction requires both translator support and `spirv-opt`. The cache key includes | ||
| 206 | those settings, compiler sources, builder and tool hashes. `.compute-cache/worker-receipt.json` records the exact | ||
| 207 | options and input-name digest for each shard; compare its `index_sha256` with the actual published index before | ||
| 208 | using it. This is an audit file, not a completion marker. A pre-upgrade cache key is not reused as evidence for | ||
| 209 | a new builder. | ||
| 210 | |||
| 198 | Among 2,680 compute programs, 46 start with two 12-byte literal-bearing VOP3 NOP hash carriers. Their body | 211 | Among 2,680 compute programs, 46 start with two 12-byte literal-bearing VOP3 NOP hash carriers. Their body |
| 199 | starts at byte 24. The three-record form starts at byte 36. The no-op measurements are in `docs/fspx.md`. | 212 | starts at byte 24. The three-record form starts at byte 36. The no-op measurements are in `docs/fspx.md`. |
| 200 | A hash literal can resemble an instruction. `shader_library.py` excludes both complete carrier records before | 213 | A hash literal can resemble an instruction. `shader_library.py` excludes both complete carrier records before |
| @@ -223,8 +236,13 @@ What stops the rest, by the translator's message: | |||
| 223 | `gfx1030` they don't either. The FSSM shaders don't use these tuples; the pipeline builds use them often. The translator | 236 | `gfx1030` they don't either. The FSSM shaders don't use these tuples; the pipeline builds use them often. The translator |
| 224 | now decodes these words from the blob with `rdna2_decode` (`restore_vcc_tuples`) and reads them as the | 237 | now decodes these words from the blob with `rdna2_decode` (`restore_vcc_tuples`) and reads them as the |
| 225 | `[s100,...,vcc_lo,vcc_hi]` lists it already takes (design.md *Scalar/buffer memory*); synthetic cases are in | 238 | `[s100,...,vcc_lo,vcc_hi]` lists it already takes (design.md *Scalar/buffer memory*); synthetic cases are in |
| 226 | `tests/semantic/test_vcc_tuple_fallback.py`. The count above was measured before this change; it has not been | 239 | `tests/semantic/test_vcc_tuple_fallback.py`. The junk llvm-mc prints at such a word's second dword is often longer |
| 227 | re-run on the real library. | 240 | than that dword (an 8-byte `exp`, say) and swallows the instruction after the tuple too, so the words after a restored |
| 241 | instruction are decoded from the blob until the stream is back at one llvm-mc printed. A word llvm-mc itself rejected | ||
| 242 | is not taken for swallowed code and stays refused. They are decoded for the program's own wave size: in wave64 a | ||
| 243 | swallowed VOP3 compare writes an SGPR pair. The table above was measured before both changes. Measured since, | ||
| 244 | over the 2,684 compute programs (llvm-mc 21.1.8): 1,816 translate with the tuples alone and 2,567 with the swallowed | ||
| 245 | instructions, all of which pass `spirv-val`; the modules of the 1,816 are byte-identical. | ||
| 228 | * **443: an instruction llvm-mc prints with another encoding than the blob's** (`v_fma_mix*`, `v_interp_p2_f16`): | 246 | * **443: an instruction llvm-mc prints with another encoding than the blob's** (`v_fma_mix*`, `v_interp_p2_f16`): |
| 229 | the existing `check_printed_encodings` refusal. | 247 | the existing `check_printed_encodings` refusal. |
| 230 | * **90 CS: "CS thread-group-size SGPR"**: RSRC2 `TG_SIZE_EN`, which no FSSM compute shader sets. | 248 | * **90 CS: "CS thread-group-size SGPR"**: RSRC2 `TG_SIZE_EN`, which no FSSM compute shader sets. |
diff --git a/docs/shader_validation.md b/docs/shader_validation.md index ac33debfa..f97182ee8 100644 --- a/docs/shader_validation.md +++ b/docs/shader_validation.md | |||
| @@ -1668,6 +1668,29 @@ Measured on an RX 6700 (gfx1031, AMD Windows driver 32.0.21045.29003, ROCm wheel | |||
| 1668 | each value is staged once, and that the kernels assemble for gfx1031. A fake oracle plays the GPU to check the exit | 1668 | each value is staged once, and that the kernels assemble for gfx1031. A fake oracle plays the GPU to check the exit |
| 1669 | codes. On a GFX10 GPU the test runs UNORM8 and checks the controls. | 1669 | codes. On a GFX10 GPU the test runs UNORM8 and checks the controls. |
| 1670 | 1670 | ||
| 1671 | ### d16 rounding of image loads and samples (`tools/d16_image_probe.py`) | ||
| 1672 | |||
| 1673 | The image counterpart to `tools/d16_format_probe.py` checks how a GFX10 GPU (RDNA1/RDNA2, through `tools/hw_oracle`) | ||
| 1674 | rounds d16 image results to f16 across three paths: `image_load` (unnormalized integer coordinates), point-filtered | ||
| 1675 | `image_sample_lz`, and bilinear `image_sample_lz` (`--frac` texels to the right of the texel centre), in wave32 and | ||
| 1676 | wave64. It covers `unorm8`, `snorm8`, `unorm16`, `snorm16`, `float16` (control: returns its own bits), and `float32` | ||
| 1677 | (1,024 patterns starting with exact f16 halfway points such as `0x3f7ff000` and `0x3f7fb000` plus their neighbours). | ||
| 1678 | Point loads and point samples are compared against the candidate rules of `tools/d16_format_probe.py` (`rte`, | ||
| 1679 | `f32_rte`, and their toward-zero and denormal-flushing variants), while bilinear d16 samples are compared against the | ||
| 1680 | hardware's own f32 bilinear sample rounded to nearest even or toward zero. | ||
| 1681 | |||
| 1682 | ``` | ||
| 1683 | python -I tools/d16_image_probe.py --formats unorm8,unorm16 --waves 32,64 --frac 0.5 --json out.json | ||
| 1684 | python -I tools/d16_image_probe.py --hw-arch gfx1031 --json out.json | ||
| 1685 | python -I tools/d16_image_probe.py --self-test | ||
| 1686 | python -I tests/test_d16_image_probe.py | ||
| 1687 | ``` | ||
| 1688 | |||
| 1689 | Exit status is 0 when the sweep ran, 1 when wave32 and wave64 disagree, 2 on a harness or control error (f32 load | ||
| 1690 | mismatch, point sample differing from load, `float16` mismatch, or misaligned texture), and 77 when the hardware oracle | ||
| 1691 | is unavailable or the GPU is not GFX10. `tests/test_d16_image_probe.py` covers the rules, texel generators, descriptors, | ||
| 1692 | and exit codes without a GPU or game files. | ||
| 1693 | |||
| 1671 | ### Widening a 16-bit float NaN in a typed buffer load (`tools/f16_widen_probe.py`) | 1694 | ### Widening a 16-bit float NaN in a typed buffer load (`tools/f16_widen_probe.py`) |
| 1672 | 1695 | ||
| 1673 | A typed buffer load of a half NaN had never been measured: `tools/mem_diff.py` decoded 16_FLOAT with | 1696 | A typed buffer load of a half NaN had never been measured: `tools/mem_diff.py` decoded 16_FLOAT with |
| @@ -2329,6 +2352,27 @@ completing draws (`89` non-clear exact + `64` clear-only exact across `573/573` | |||
| 2329 | `ps_sweep.py compare --exact`. All `3` whole-corpus shaders combining raw barycentrics and `v_interp_*_f16` also draw | 2352 | `ps_sweep.py compare --exact`. All `3` whole-corpus shaders combining raw barycentrics and `v_interp_*_f16` also draw |
| 2330 | bit-for-bit identically (`3/3` draws, `11/11` targets) against `default` on the RX 6650 XT. | 2353 | bit-for-bit identically (`3/3` draws, `11/11` targets) against `default` on the RX 6650 XT. |
| 2331 | 2354 | ||
| 2355 | ### Op-scoped mutation testing for `tests/semantic` (`tools/semantic_mutants.py`) | ||
| 2356 | |||
| 2357 | `tools/semantic_mutants.py` checks which one-line bugs in `tools/rdna2spirv.py` a given `tests/semantic` file would | ||
| 2358 | miss. You scope the slice by instruction branch (`--op`), translator method (`--function`), or 1-based line range | ||
| 2359 | (`--lines`); it generates one-line mutants (swapped SPIR-V and `GLSL.std.450` opcode pairs, comparison polarity and | ||
| 2360 | signedness flips, `self.cu(N)` off-by-one constants, swapped `OpSelect` arms, and duplicated trailing operands) in a | ||
| 2361 | private temporary copy of `tools/` and runs the test file against each copy through `LEONIDA_TOOLS_DIR` (the same hook | ||
| 2362 | used by `tests/semantic/test_mutations.py`), leaving the repository untouched. | ||
| 2363 | |||
| 2364 | ``` | ||
| 2365 | python -I tools/semantic_mutants.py tests/semantic/test_alu_sad.py --op v_sad_u8 | ||
| 2366 | python -I tools/semantic_mutants.py tests/semantic/test_alu_sad.py --op v_sad_u8 --list | ||
| 2367 | python -I tools/semantic_mutants.py tests/semantic/test_alu_sad.py --op v_sad_u8 --timeout 120 | ||
| 2368 | python -I tests/test_semantic_mutants.py | ||
| 2369 | ``` | ||
| 2370 | |||
| 2371 | Any mutant the test file still passes is reported as `SURVIVED` (read each lead before adding cases, since some mutants | ||
| 2372 | are equivalent). Exit status is 0 when every mutant is caught, 1 when any survives, and 2 on a usage error or when the | ||
| 2373 | unmutated baseline fails. Synthetic only (no GPU or game files); `tests/test_semantic_mutants.py` covers mutant | ||
| 2374 | generation, scoping, and CLI exit codes. | ||
| 2375 | |||
| 2332 | ## Coverage plan and cost | 2376 | ## Coverage plan and cost |
| 2333 | 2377 | ||
| 2334 | Start with straight-line scalar/vector ALU because it is deterministic, needs no descriptors and | 2378 | Start with straight-line scalar/vector ALU because it is deterministic, needs no descriptors and |
diff --git a/docs/testing.md b/docs/testing.md index ffe729d24..671c5548c 100644 --- a/docs/testing.md +++ b/docs/testing.md | |||
| @@ -9,11 +9,12 @@ issue][claims] helps more. | |||
| 9 | 9 | ||
| 10 | This page collects the setup steps and the problems testers have run into so far. | 10 | This page collects the setup steps and the problems testers have run into so far. |
| 11 | 11 | ||
| 12 | [claims]: https://github.com/ubiquitarianism/leonida/issues/14 | 12 | [claims]: https://github.com/ubiquitarianism/leonida/issues?q=is%3Aissue%20is%3Aopen%20in%3Atitle%20%22Coordinating%20who%20works%20on%20what%22 |
| 13 | 13 | ||
| 14 | ## What you need | 14 | ## What you need |
| 15 | 15 | ||
| 16 | - **Python 3.11+.** `scripts/run_gpu_tests.py` needs at least 3.10. | 16 | - **Python 3.12+**, which `make_game.py` requires (it stops with "Python 3.12 or newer is needed" on an older one, so |
| 17 | its tests fail there too). `scripts/run_gpu_tests.py` on its own runs on 3.10 or newer. | ||
| 17 | - **`llvm-mc` with the AMDGPU target** (LLVM 21+). The official LLVM Windows release has no AMDGPU target. On | 18 | - **`llvm-mc` with the AMDGPU target** (LLVM 21+). The official LLVM Windows release has no AMDGPU target. On |
| 18 | Windows, use one of: | 19 | Windows, use one of: |
| 19 | - `scripts\build_llvm_mc.ps1`, which builds a native `llvm-mc.exe` (needs git and the Visual Studio C++ tools); | 20 | - `scripts\build_llvm_mc.ps1`, which builds a native `llvm-mc.exe` (needs git and the Visual Studio C++ tools); |
| @@ -661,8 +662,12 @@ also advertises the feature but returns a wrong third `BaryCoordKHR` component, | |||
| 661 | expected (#5933: Vega 8, PCI 1002:15E7, driver 31.0.21921.13001). `ps_bary`, `ps_persp_bary` and `ps_ij_computed` | 662 | expected (#5933: Vega 8, PCI 1002:15E7, driver 31.0.21921.13001). `ps_bary`, `ps_persp_bary` and `ps_ij_computed` |
| 662 | fail natively; through the fallback `ps_bary` and `ps_persp_bary` pass. `tools/vk_subgroup_info.py` reports | 663 | fail natively; through the fallback `ps_bary` and `ps_persp_bary` pass. `tools/vk_subgroup_info.py` reports |
| 663 | `barycentric_fallback` for these PCI IDs under `VK_DRIVER_ID_AMD_PROPRIETARY`, so `make_game.py` and | 664 | `barycentric_fallback` for these PCI IDs under `VK_DRIVER_ID_AMD_PROPRIETARY`, so `make_game.py` and |
| 664 | `run_gpu_tests.py` turn the fallback on by themselves there, with the same `LEONIDA_BARY_FALLBACK` override. RADV and | 665 | `run_gpu_tests.py` turn the fallback on by themselves there, with the same `LEONIDA_BARY_FALLBACK` override. RADV |
| 665 | other GCN 5 GPUs are not covered: none has been measured. | 666 | (Mesa 26.2.6) on the same Vega 8 doesn't list `VK_KHR_fragment_shader_barycentric` at all, though it sets the |
| 667 | `fragmentShaderBarycentric` feature, so the four raw-barycentric tests skip there and pass with | ||
| 668 | `LEONIDA_BARY_FALLBACK=1`, and `ps_interp_f16_high` passes through the f16 fallback that `run_gpu_tests.py` turns on | ||
| 669 | by itself ([#166 entry](https://github.com/ItsNotRexed/Leonida/issues/166#issuecomment-7109387712)). Other GCN 5 GPUs | ||
| 670 | are not covered: none has been measured. | ||
| 666 | 671 | ||
| 667 | ## Macs: 16-bit interpolation without PerVertexKHR | 672 | ## Macs: 16-bit interpolation without PerVertexKHR |
| 668 | 673 | ||
| @@ -785,6 +790,7 @@ game's device ignores it`, so leaving them set cannot slow a game down (`run_tin | |||
| 785 | | `d3d12_descriptor_test` reports that the set had room for fewer than 5001 2D views and 2100 samplers, and the device logs that the bindless set holds fewer samplers than a full shader-visible sampler heap | The device's descriptor limits, or its `vkGetDescriptorSetLayoutSupport`, allow no bigger bindless set ([d3d12_vulkan.md](d3d12_vulkan.md) section 5). MoltenVK's answer is ignored, since it rejects every layout of `maxPerSetDescriptors` (1212) or more although it runs the full set | Expected where the limits are low. The test still checks the last index of each array and that the next view and sampler are refused | | 790 | | `d3d12_descriptor_test` reports that the set had room for fewer than 5001 2D views and 2100 samplers, and the device logs that the bindless set holds fewer samplers than a full shader-visible sampler heap | The device's descriptor limits, or its `vkGetDescriptorSetLayoutSupport`, allow no bigger bindless set ([d3d12_vulkan.md](d3d12_vulkan.md) section 5). MoltenVK's answer is ignored, since it rejects every layout of `maxPerSetDescriptors` (1212) or more although it runs the full set | Expected where the limits are low. The test still checks the last index of each array and that the next view and sampler are refused | |
| 786 | | `cs_dpp_ops` fails on a Mac with MoltenVK 1.4.2: `out[0..7] = 100 100 11 ...`, want `100 10 11 ...` | MoltenVK 1.4.2's SPIRV-Cross moves the DPP lowering's subgroup ballot and shuffle into a short-circuiting `&&` and `?:`, so only some lanes run them and lane 1 sees its source lane 0 as inactive. SPIRV-Cross `5c372ffb` (in MoltenVK `main`) keeps them out of `?:`; a ballot on the right of `&&` is still moved there in SPIRV-Cross `57e4efcc` | Fixed in the translator (SHADER-529, #3227): it stores the ballot and the shuffle to variables of their own, so the MSL that MoltenVK 1.4.2 generates (`MVK_CONFIG_DEBUG=1`) runs each as a statement in every lane. Translate again with current `main`; MoltenVK `main` and KosmicKrisp are no longer needed for it. A pass alone does not show the fix: an Apple M5 Pro (macOS 26.5.1) returns the right words with 1.4.2 even when the ballot is on the right of `&&` | | 791 | | `cs_dpp_ops` fails on a Mac with MoltenVK 1.4.2: `out[0..7] = 100 100 11 ...`, want `100 10 11 ...` | MoltenVK 1.4.2's SPIRV-Cross moves the DPP lowering's subgroup ballot and shuffle into a short-circuiting `&&` and `?:`, so only some lanes run them and lane 1 sees its source lane 0 as inactive. SPIRV-Cross `5c372ffb` (in MoltenVK `main`) keeps them out of `?:`; a ballot on the right of `&&` is still moved there in SPIRV-Cross `57e4efcc` | Fixed in the translator (SHADER-529, #3227): it stores the ballot and the shuffle to variables of their own, so the MSL that MoltenVK 1.4.2 generates (`MVK_CONFIG_DEBUG=1`) runs each as a statement in every lane. Translate again with current `main`; MoltenVK `main` and KosmicKrisp are no longer needed for it. A pass alone does not show the fix: an Apple M5 Pro (macOS 26.5.1) returns the right words with 1.4.2 even when the ballot is on the right of `&&` | |
| 787 | | `check.py`'s `cs_fma_fused` fails on a Mac with MoltenVK 1.4.2: word 7 reads `15360` (`0x3c00`), want `29521` (`0x7351`) | The f16 multiply-add (round to odd). The MSL of 1.4.2 and of MoltenVK `main` differ only in SPIRV-Cross's precise-arithmetic helpers (`[[clang::optnone]]` and `fma(l, r, 0)` against `math_mode(safe)` and `fma(l, r, -0.0)`, the SHADER-182 / SHADER-234 change) | Expected with MoltenVK 1.4.2; it passes with MoltenVK `main` | | 792 | | `check.py`'s `cs_fma_fused` fails on a Mac with MoltenVK 1.4.2: word 7 reads `15360` (`0x3c00`), want `29521` (`0x7351`) | The f16 multiply-add (round to odd). The MSL of 1.4.2 and of MoltenVK `main` differ only in SPIRV-Cross's precise-arithmetic helpers (`[[clang::optnone]]` and `fma(l, r, 0)` against `math_mode(safe)` and `fma(l, r, -0.0)`, the SHADER-182 / SHADER-234 change) | Expected with MoltenVK 1.4.2; it passes with MoltenVK `main` | |
| 793 | | `ps_imgatomic` fails in about two of three runs on a Mac with MoltenVK 1.4.2: 1 to 6 of the 256 image-atomic texels are wrong while the render target is exact, for example `2D umax texel 48: got 0x00000d45, want 0x00000dc7` | MoltenVK 1.4.2 lowers the four `OpAtomic*` on image texels to Metal's texture atomics (`atomic_fetch_max`, `atomic_fetch_min` and `atomic_fetch_or` on `access::read_write` textures), and the texels read back the way a read-modify-write that is not atomic between two groups of fragment threads leaves them. A wrong `umax` texel always holds the id of one of its own 64 pixels, the largest of only some of them: on an Apple M5 it was the last pixel of the texel's first four rows in 43 of 90 cases, with all 32 larger ids gone. A wrong `umin` texel mirrors that (the first pixel of its last four rows in 39 of 48). The `or` image did not differ in 150 runs there. It is not the translator's first-lane broadcast of the descriptor index (54 of 60 runs fail with the index used directly) and not the readback (42 of 60 fail with the copies in a submission of their own after the draw). Measured on an Apple M5 (macOS 27.2.1, 101 of 150 runs fail) and an M5 Pro (#543) | Expected with MoltenVK 1.4.2. KosmicKrisp passed the same module and binary 10 times of 10 on the M5 Pro (#543). The macOS CI job does not reach it: on the runner's paravirtual device the test skips because its bindless set does not fit the descriptor limits. Do not weaken the test's expected texels | | ||
| 788 | | `gs_tri` and `ms_tri` fail on a Mac | MoltenVK has no geometry stage and no `VK_EXT_mesh_shader` | Current `main` reports them as skipped | | 794 | | `gs_tri` and `ms_tri` fail on a Mac | MoltenVK has no geometry stage and no `VK_EXT_mesh_shader` | Current `main` reports them as skipped | |
| 789 | | With `LEONIDA_W64_EMULATE=1` on llvmpipe, the `ms_*` tests fail. Measured with Mesa 26.3.1: on x86_64 at 256-bit vectors (the default there) all six abort with "LLVM ERROR: Cannot emit physreg copy instruction"; on arm64 (128-bit) `ms_tri` draws nothing (the frame stays at the clear color); on x86_64 at 128 bits (`LP_NATIVE_VECTOR_WIDTH=128`) `ms_tri` happened to draw correctly, but with Mesa 26.0.3 `ms_wave_info_s3` and `ms_v5_workgroup` draw nothing there (4 of 6 pass, [measured by @TreXito](https://github.com/ItsNotRexed/Leonida/pull/3838#issuecomment-7086696759)) ([measured runs](https://github.com/ItsNotRexed/Leonida/issues/3127#issuecomment-7086469679)) | An llvmpipe bug: a mesh shader's runtime `CullPrimitiveEXT` is stored through an invalid `bitcast <N x i1> to <N x float>` (TEST-782, #3127; see "Without a GPU: Mesa llvmpipe") | Run the mesh tests on llvmpipe without `LEONIDA_W64_EMULATE`, or add `LEONIDA_MESH_COMPUTE=1` (the compute fallback): with it all 6 `ms_*` pass emulated on llvmpipe (x86_64, 256-bit) | | 795 | | With `LEONIDA_W64_EMULATE=1` on llvmpipe, the `ms_*` tests fail. Measured with Mesa 26.3.1: on x86_64 at 256-bit vectors (the default there) all six abort with "LLVM ERROR: Cannot emit physreg copy instruction"; on arm64 (128-bit) `ms_tri` draws nothing (the frame stays at the clear color); on x86_64 at 128 bits (`LP_NATIVE_VECTOR_WIDTH=128`) `ms_tri` happened to draw correctly, but with Mesa 26.0.3 `ms_wave_info_s3` and `ms_v5_workgroup` draw nothing there (4 of 6 pass, [measured by @TreXito](https://github.com/ItsNotRexed/Leonida/pull/3838#issuecomment-7086696759)) ([measured runs](https://github.com/ItsNotRexed/Leonida/issues/3127#issuecomment-7086469679)) | An llvmpipe bug: a mesh shader's runtime `CullPrimitiveEXT` is stored through an invalid `bitcast <N x i1> to <N x float>` (TEST-782, #3127; see "Without a GPU: Mesa llvmpipe") | Run the mesh tests on llvmpipe without `LEONIDA_W64_EMULATE`, or add `LEONIDA_MESH_COMPUTE=1` (the compute fallback): with it all 6 `ms_*` pass emulated on llvmpipe (x86_64, 256-bit) | |
| 790 | | 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` | | 796 | | 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` | |
| @@ -797,7 +803,7 @@ game's device ignores it`, so leaving them set cannot slow a game down (`run_tin | |||
| 797 | | A Windows CI artifact run under Wine by hand: `d3d12_compute` and the other tests that read `LEONIDA_TEST_*_SPV` end with exit 3 and no message | The `.spv` paths are compiled in as `D:/a/Leonida/Leonida/runtime/build/generated/...`; the prefix has no `D:` drive and the test isn't run from the artifact folder | Run it from the artifact folder (the tests then find `generated/<name>.spv` there) or through `scripts/run_wine_tests.py`, which maps that drive for the run; current `main` names the file it couldn't copy (`cannot copy ...: File not found`) | | 803 | | A Windows CI artifact run under Wine by hand: `d3d12_compute` and the other tests that read `LEONIDA_TEST_*_SPV` end with exit 3 and no message | The `.spv` paths are compiled in as `D:/a/Leonida/Leonida/runtime/build/generated/...`; the prefix has no `D:` drive and the test isn't run from the artifact folder | Run it from the artifact folder (the tests then find `generated/<name>.spv` there) or through `scripts/run_wine_tests.py`, which maps that drive for the run; current `main` names the file it couldn't copy (`cannot copy ...: File not found`) | |
| 798 | | Linux cross-build: CMake can't find `clang-cl-19` (or another versioned `clang-cl-<N>`) although `clang-19` and `lld-19` are installed | On Debian and Ubuntu, the versioned `clang-cl-<N>` link is in the `clang-tools-<N>` package, not in `clang-<N>` (`/usr/lib/llvm-<N>/bin/clang-cl` comes from it too); `lld-link-<N>`, `llvm-lib`, `llvm-rc` and `llvm-mt` come from `lld-<N>` and `llvm-<N>` | `sudo apt-get install clang-tools-19 lld-19 llvm-19` (Ubuntu 24.04 has 19 and 20), then pass the versioned names as in [the cross-build](#the-windows-runtime-on-linux-under-wine-or-proton) | | 804 | | Linux cross-build: CMake can't find `clang-cl-19` (or another versioned `clang-cl-<N>`) although `clang-19` and `lld-19` are installed | On Debian and Ubuntu, the versioned `clang-cl-<N>` link is in the `clang-tools-<N>` package, not in `clang-<N>` (`/usr/lib/llvm-<N>/bin/clang-cl` comes from it too); `lld-link-<N>`, `llvm-lib`, `llvm-rc` and `llvm-mt` come from `lld-<N>` and `llvm-<N>` | `sudo apt-get install clang-tools-19 lld-19 llvm-19` (Ubuntu 24.04 has 19 and 20), then pass the versioned names as in [the cross-build](#the-windows-runtime-on-linux-under-wine-or-proton) | |
| 799 | | Under Ubuntu's Wine 9.0, `wineboot --init` (and every Wine program after it) stops at once with `free(): invalid pointer` or a segmentation fault, before printing anything else; the prefix holds only a `wineserver` file | That Wine opens `/run/user/<uid>` for its server directory, whether `XDG_RUNTIME_DIR` is set or not, and aborts when the folder doesn't exist. The login manager makes it for a desktop session; a container or a shell started without a login session (a root shell in Docker, a CI runner image) has none | Create it before starting Wine: `mkdir -p /run/user/$(id -u) && chmod 700 /run/user/$(id -u)` (setting `XDG_RUNTIME_DIR` alone doesn't help), delete the half-made prefix, and run `wineboot --init` again | | 805 | | Under Ubuntu's Wine 9.0, `wineboot --init` (and every Wine program after it) stops at once with `free(): invalid pointer` or a segmentation fault, before printing anything else; the prefix holds only a `wineserver` file | That Wine opens `/run/user/<uid>` for its server directory, whether `XDG_RUNTIME_DIR` is set or not, and aborts when the folder doesn't exist. The login manager makes it for a desktop session; a container or a shell started without a login session (a root shell in Docker, a CI runner image) has none | Create it before starting Wine: `mkdir -p /run/user/$(id -u) && chmod 700 /run/user/$(id -u)` (setting `XDG_RUNTIME_DIR` alone doesn't help), delete the half-made prefix, and run `wineboot --init` again | |
| 800 | | `run_gpu_tests.py` fails on a `dict \| None` annotation | Python older than 3.10 | Use Python 3.11+ | | 806 | | `run_gpu_tests.py` fails on a `dict \| None` annotation | Python older than 3.10 | Use Python 3.12+ | |
| 801 | | `vulkaninfo` lists `Microsoft Direct3D12 (<gpu>)` next to the real GPU and the tests run on it | The Windows "OpenCL™, OpenGL® and Vulkan® Compatibility Pack" installs Mesa's Dozen, a Vulkan-on-D3D12 layer that reports `DISCRETE_GPU` like the native card | Current `main` prefers a native ICD over Microsoft's vendor (`0x1414`) in the runtime and every harness; set `LEONIDA_VK_DEVICE=<part of the real GPU name>` to select explicitly. See #915. | | 807 | | `vulkaninfo` lists `Microsoft Direct3D12 (<gpu>)` next to the real GPU and the tests run on it | The Windows "OpenCL™, OpenGL® and Vulkan® Compatibility Pack" installs Mesa's Dozen, a Vulkan-on-D3D12 layer that reports `DISCRETE_GPU` like the native card | Current `main` prefers a native ICD over Microsoft's vendor (`0x1414`) in the runtime and every harness; set `LEONIDA_VK_DEVICE=<part of the real GPU name>` to select explicitly. See #915. | |
| 802 | | A GPU test that uses `image_load` (or lighting built from real shaders) reads zeros from its image; @Silliana saw every texel except pixel (0,0) come back zero in their own layer (#603, not reproduced here) | In this runtime the shader turns the T# words into an index through the descriptor hash table (`runtime/src/descriptor_table.h`: a miss gives index 0), and index 0 is a 1×1 image of zeros (`runtime/src/vulkan_bindless.h`), so a hand-built or zeroed T# that was never registered reads zeros even at (0,0). The translator does not compare coordinates with the T# size, and `cs_imgload.asm` only uses its T# words as a hash key | Register the descriptor through the runtime (for D3D12, create it with `CreateShaderResourceView`) so its T# hits the table, with the image's real width and height (stored as size − 1, see `runtime/src/gfx10_descriptors.h`) | | 808 | | A GPU test that uses `image_load` (or lighting built from real shaders) reads zeros from its image; @Silliana saw every texel except pixel (0,0) come back zero in their own layer (#603, not reproduced here) | In this runtime the shader turns the T# words into an index through the descriptor hash table (`runtime/src/descriptor_table.h`: a miss gives index 0), and index 0 is a 1×1 image of zeros (`runtime/src/vulkan_bindless.h`), so a hand-built or zeroed T# that was never registered reads zeros even at (0,0). The translator does not compare coordinates with the T# size, and `cs_imgload.asm` only uses its T# words as a hash key | Register the descriptor through the runtime (for D3D12, create it with `CreateShaderResourceView`) so its T# hits the table, with the image's real width and height (stored as size − 1, see `runtime/src/gfx10_descriptors.h`) | |
| 803 | | `cs_sample_lz_int_d16`, `ps_sample_implicit_sint`, `ps_ssharp`, `ps_tex`, `ps_texture_mip0`, `ps_texture_sample` and `ps_texture_sample_d16` crash (exit -11 or 139) on an Intel GPU on Linux, while NVIDIA and llvmpipe pass them (TEST-399) | A bug in Mesa ANV's shader compiler: compiling these texture-sampling shaders, `nir_opt_gcm` (`nir_opt_gcm.c:430`, `gcm_schedule_early_src`) dereferences a phi source an earlier pass has freed. The SPIR-V passes `spirv-val`. Seen with Mesa 26.1.6 (Arrow Lake) and 26.2.7 (Iris Xe, ADL GT2); Mesa 26.3.1 and `main` (bb98606) pass the whole suite on the same Iris Xe | Use Mesa 26.3.1 or newer. To check a newer Mesa without installing it, build its Intel Vulkan driver and point `VK_DRIVER_FILES` at its `src/intel/vulkan/intel_devenv_icd.x86_64.json` | | 809 | | `cs_sample_lz_int_d16`, `ps_sample_implicit_sint`, `ps_ssharp`, `ps_tex`, `ps_texture_mip0`, `ps_texture_sample` and `ps_texture_sample_d16` crash (exit -11 or 139) on an Intel GPU on Linux, while NVIDIA and llvmpipe pass them (TEST-399) | A bug in Mesa ANV's shader compiler: compiling these texture-sampling shaders, `nir_opt_gcm` (`nir_opt_gcm.c:430`, `gcm_schedule_early_src`) dereferences a phi source an earlier pass has freed. The SPIR-V passes `spirv-val`. Seen with Mesa 26.1.6 (Arrow Lake) and 26.2.7 (Iris Xe, ADL GT2); Mesa 26.3.1 and `main` (bb98606) pass the whole suite on the same Iris Xe | Use Mesa 26.3.1 or newer. To check a newer Mesa without installing it, build its Intel Vulkan driver and point `VK_DRIVER_FILES` at its `src/intel/vulkan/intel_devenv_icd.x86_64.json` | |
diff --git a/docs/world.md b/docs/world.md index 7d0951465..84ce585ff 100644 --- a/docs/world.md +++ b/docs/world.md | |||
| @@ -784,7 +784,12 @@ joaat of the GTA V class names, and every member below is named by the resource' | |||
| 784 | 784 | ||
| 785 | Two more grass-list members are named by joaat from a brute force over common engine words: `slodID` (0xB0, member hash `9fe78fd1`) and `SLODArchetypeList` (0x158, `b451fc98`), so grass lists carry their own link to an SLOD archetype set next to `IsSLODList`. The other unnamed members stay as hashes in the schema. | 785 | Two more grass-list members are named by joaat from a brute force over common engine words: `slodID` (0xB0, member hash `9fe78fd1`) and `SLODArchetypeList` (0x158, `b451fc98`), so grass lists carry their own link to an SLOD archetype set next to `IsSLODList`. The other unnamed members stay as hashes in the schema. |
| 786 | 786 | ||
| 787 | An `InstanceList` is a u64 (low 12 bits: 1-based block index; bits 20+: offset in that block) and a u16 count. | 787 | An `InstanceList` is a u64 (low 20 bits: 1-based block index; bits 20+: offset in that block) and a u16 count. |
| 788 | That is the pointer form of [psin.md](psin.md) and [ped_catalogues.md](ped_catalogues.md); `instance_lists.py`, | ||
| 789 | `world_interior_names.py`, `world_lights_paths.py` and `world_index.py` read it through | ||
| 790 | `world_index.split_pointer`. Bits 12-19 are the block number's high bits, so they stay zero below 4,096 blocks. Over the 232,846 `0x7a` resources of `levels.rpf`, `story000.rpf`, `shared_minigame000.rpf` and | ||
| 791 | `packs.rpf`, the most blocks one has is 1,760. Every non-null array (`0x52`) and string (`0x42`) pointer there | ||
| 792 | has bits 12-19 at zero, so a 12-bit reading would find the same block for each of them. | ||
| 788 | Instance blocks are usually in the physical buffer, so the tool joins each resource's virtual and physical | 793 | Instance blocks are usually in the physical buffer, so the tool joins each resource's virtual and physical |
| 789 | streams from its block map (+0x08 -> +8 virtual count, +9 physical count). | 794 | streams from its block map (+0x08 -> +8 virtual count, +9 physical count). |
| 790 | 795 | ||
diff --git a/docs/world_lights_paths.md b/docs/world_lights_paths.md index f619f9a33..ca5595cb1 100644 --- a/docs/world_lights_paths.md +++ b/docs/world_lights_paths.md | |||
| @@ -52,8 +52,8 @@ archetype; entity lights belong to one entity. | |||
| 52 | `lightFadeDistance` `+0x28d`, `shadowFadeDistance` `+0x28e`, `lightType` `+0x291` (1 point, 2 spot, 4 capsule, 32 seen but not named), | 52 | `lightFadeDistance` `+0x28d`, `shadowFadeDistance` `+0x28e`, `lightType` `+0x291` (1 point, 2 spot, 4 capsule, 32 seen but not named), |
| 53 | `groupId` `+0x292`. Its member table has 100 entries. | 53 | `groupId` `+0x292`. Its member table has 100 entries. |
| 54 | 54 | ||
| 55 | Pointers are pool references (1-based block number in bits 0..11, byte offset from bit 20) or `0x5xxxxxxx` | 55 | Pointers are pool references (1-based block number in bits 0..19, byte offset from bit 20, as in |
| 56 | system pointers. A pool reference whose offset is `0x500`..`0x5ff` also has | 56 | [world.md](world.md#instanced-props-and-grass)) or `0x5xxxxxxx` system pointers. A pool reference whose offset is `0x500`..`0x5ff` also has |
| 57 | the shape of a `0x5xxxxxxx` pointer, so the reader tries the pool form first and only then a system pointer. | 57 | the shape of a `0x5xxxxxxx` pointer, so the reader tries the pool form first and only then a system pointer. |
| 58 | 58 | ||
| 59 | | Measure | Count | | 59 | | Measure | Count | |
diff --git a/docs/xcl_compare.md b/docs/xcl_compare.md index 07d3e42e4..cd7a0b6a0 100644 --- a/docs/xcl_compare.md +++ b/docs/xcl_compare.md | |||
| @@ -71,5 +71,5 @@ What the differences come down to: | |||
| 71 | | XUser, XGameSave folder | #279 and #3363 (open). | | 71 | | XUser, XGameSave folder | #279 and #3363 (open). | |
| 72 | | `XAudio2Create` | RT-197, #3831 (open). | | 72 | | `XAudio2Create` | RT-197, #3831 (open). | |
| 73 | | `d3d12_xs.dll!D3D12CreateDevice` not found (16 D3D12.X checks) | The runtime serves the console's `D3D12XboxCreateDevice`; the title asks for `D3D12CreateDevice`. Whether the console's `d3d12_xs.dll` exports that name is not measured here. | | 73 | | `d3d12_xs.dll!D3D12CreateDevice` not found (16 D3D12.X checks) | The runtime serves the console's `D3D12XboxCreateDevice`; the title asks for `D3D12CreateDevice`. Whether the console's `d3d12_xs.dll` exports that name is not measured here. | |
| 74 | | `kernelx.dll` imports `XMemAlloc`, `XMemVirtualAlloc`, `TitleMemoryStatus`, `GetConsoleType`, `SetThreadName`/`GetThreadName`; `xmem.dll` physical pages; `xcrdapi.dll!DStorageGetFactory`; `MFResetDXGIDeviceManagerX` | Unimplemented here. None is in the measured imports of the shipped modules ([runtime_imports.md](runtime_imports.md)), and the executable is not available to measure, so they are leads, not known needs. `xmem.dll!XMemAlloc` is served; the same name under `kernelx.dll` is not. | | 74 | | `kernelx.dll` imports `XMemAlloc`, `XMemVirtualAlloc`, `TitleMemoryStatus`, `GetConsoleType`, `SetThreadName`/`GetThreadName`; `xmem.dll` physical pages; `xcrdapi.dll!DStorageGetFactory`; `MFResetDXGIDeviceManagerX` | These are the XCL title's bindings, not the game's. The executable's own import table and call sites are measured at `1cc6e3c1` ([runtime_imports.md](runtime_imports.md#the-retail-executable-rt-5)): `xmem.dll!XMemAlloc`, `XMemFree` and `XMemVirtualAlloc` bind (the last at 23 measured call sites), and the four `xmem.dll` physical-page calls (`XMemAllocatePhysicalPages`, `XMemFreePhysicalPages`, `XMemMapPhysicalPages`, `XMemMapPhysicalPagesScatter`) are served; the same names under `kernelx.dll` are not. `XCRDAPI.dll!DStorageGetFactory` is a measured import served by `dstorage.cpp` (since `2d7be48de`). `TitleMemoryStatus`, `GetConsoleType`, `SetThreadName`/`GetThreadName` and `MFResetDXGIDeviceManagerX` are not in that table, so they remain leads, not known needs. | |
| 75 | | The title's window is not a hidden 1920x1080 tool window | An XCL design choice (its console screen), not a console fact. | | 75 | | The title's window is not a hidden 1920x1080 tool window | An XCL design choice (its console screen), not a console fact. | |
diff --git a/docs/xdxr.md b/docs/xdxr.md index 1b8a4cc27..24e9429f0 100644 --- a/docs/xdxr.md +++ b/docs/xdxr.md | |||
| @@ -132,7 +132,7 @@ static reference, reached through a table (#7516), so 2 of them are calls of ano | |||
| 132 | | `GetRaytracingAccelerationStructurePrebuildInfo(INPUTS*, XDXR_STREAM_DESC*, PREBUILD_INFO*)` | 3 | the layer's sizes | | 132 | | `GetRaytracingAccelerationStructurePrebuildInfo(INPUTS*, XDXR_STREAM_DESC*, PREBUILD_INFO*)` | 3 | the layer's sizes | |
| 133 | | `BuildRaytracingAccelerationStructureBatched2X(GCL6*, UINT, BATCHED_DESC2*)` | 6 (8) | one layer build per element (§1), with its postbuild descriptions | | 133 | | `BuildRaytracingAccelerationStructureBatched2X(GCL6*, UINT, BATCHED_DESC2*)` | 6 (8) | one layer build per element (§1), with its postbuild descriptions | |
| 134 | | `CopyRaytracingAccelerationStructure(GCL4*, dest, source, mode)` | 2 | the layer's copy | | 134 | | `CopyRaytracingAccelerationStructure(GCL4*, dest, source, mode)` | 2 | the layer's copy | |
| 135 | | `RehydrateRaytracingAccelerationStructureBatched2X(GCL8*, UINT, BUILD_DESC*, UINT64*)` | 4 | `E_NOTIMPL` for now | | 135 | | `RehydrateRaytracingAccelerationStructureBatched2X(GCL8*, UINT, BUILD_DESC*, UINT64*)` | 4 | rebuilds each structure from source geometry; refuses source-only stream without geometry | |
| 136 | 136 | ||
| 137 | **Where it differs from the DLL:** | 137 | **Where it differs from the DLL:** |
| 138 | - **Stream records (§3):** they tune the console builder's heuristics, so they are ignored (logged once). The result | 138 | - **Stream records (§3):** they tune the console builder's heuristics, so they are ignored (logged once). The result |
| @@ -140,8 +140,23 @@ static reference, reached through a table (#7516), so 2 of them are calls of ano | |||
| 140 | - **Validation errors:** the DLL throws them as C++ exceptions. A shim must not throw into the title, so an element | 140 | - **Validation errors:** the DLL throws them as C++ exceptions. A shim must not throw into the title, so an element |
| 141 | the DLL would refuse is skipped with a log line. The offline-statistics postbuild type (`0x10`, §4) is one of | 141 | the DLL would refuse is skipped with a log line. The offline-statistics postbuild type (`0x10`, §4) is one of |
| 142 | those. | 142 | those. |
| 143 | - **Rehydration** is the next step: rebuild each structure on the GPU from the source geometry its description | 143 | - **Rehydration (`RehydrateRaytracingAccelerationStructureBatched2X`):** Rebuilds each structure on the GPU from |
| 144 | carries ([bvh.md](bvh.md) §4a), in the leaf frame `compressionParams` gives. | 144 | the source geometry its description carries ([bvh.md](bvh.md) §4a). The leaf frame `compressionParams` gives is |
| 145 | **not applied yet**: the leaves are built from the geometry as the description has it. | ||
| 146 | What the 4th parameter (`const UINT64* source_data`, mangling `PEB_K`) conveys is a **hypothesis**: it points to | ||
| 147 | the array of source buffer addresses for offline dehydrated console streams (e.g. rehydration inputs). | ||
| 148 | When geometry is provided (`NumDescs > 0`), the shim issues `BuildRaytracingAccelerationStructure` to construct | ||
| 149 | traversable GPU BVH nodes. That is a fresh build: the title sets `SourceAccelerationStructureData` to the | ||
| 150 | dehydrated stream, so the shim clears it and the `PERFORM_UPDATE` flag (logged once), which would otherwise make | ||
| 151 | the layer refit from the stream's bytes. The title passes `ScratchAccelerationStructureData = 0` (measured on the retail | ||
| 152 | title), so the shim supplies scratch, or the layer would reject the build: one new buffer per call, in which each | ||
| 153 | element has its own 256-byte-aligned region sized via `GetRaytracingAccelerationStructurePrebuildInfo`. The | ||
| 154 | layer's XDXR builder leaves the dependency between builds to the caller's barrier and the title puts none between | ||
| 155 | the elements of a batch, so no two builds, in a batch, on one list or on lists recorded in parallel, share scratch | ||
| 156 | bytes. The layer's command list holds the buffer until it is Reset or released, and the layer destroys it after | ||
| 157 | the submission that used it has retired. When `source_data` is supplied without geometry, the shim logs once and | ||
| 158 | refuses with `E_NOTIMPL`: offline console dehydrated streams cannot be directly deserialized by PC Vulkan/D3D12 | ||
| 159 | drivers ([bvh.md](bvh.md) §4/§4a). Empty structures (`NumDescs == 0` without source) are logged and skipped. | ||
| 145 | 160 | ||
| 146 | `xbox_bvh_builder_test` calls every export through the shim registry, the way the title's imports bind, and | 161 | `xbox_bvh_builder_test` calls every export through the shim registry, the way the title's imports bind, and |
| 147 | `xdxr_bvh.py check-build` checks the BLAS, TLAS and compacted BLAS it builds (ctest `xbox_bvh_builder_check`). | 162 | `xdxr_bvh.py check-build` checks the BLAS, TLAS and compacted BLAS it builds (ctest `xbox_bvh_builder_check`). |
diff --git a/docs/xmem_exe_calls.md b/docs/xmem_exe_calls.md index 99b62fbe1..071cb6b7f 100644 --- a/docs/xmem_exe_calls.md +++ b/docs/xmem_exe_calls.md | |||
| @@ -1,11 +1,12 @@ | |||
| 1 | # XMem: how the retail executable calls it (RT-5) | 1 | # XMem: how the retail executable calls it (RT-5) |
| 2 | 2 | ||
| 3 | `game_scarlett_master.exe` imports 12 functions from `xmem.dll` (`docs/runtime_imports.md`, "The retail executable"). | 3 | `game_scarlett_master.exe` imports 12 functions from `xmem.dll` (`docs/runtime_imports.md`, "The retail executable"). |
| 4 | Seven have no shim yet. This page records, from the file alone, how the executable calls them: how many call sites each | 4 | This page records, from the file alone, how the executable calls them: how many call sites each has and the constant |
| 5 | has and the constant arguments those sites pass. Nothing was run: `tools/import_call_sites.py` finds the call sites, and | 5 | arguments those sites pass. Nothing was run: `tools/import_call_sites.py` finds the call sites, and the instructions |
| 6 | the instructions that load the argument registers before each call were read by hand. No code or data of the executable | 6 | that load the argument registers before each call were read by hand. No code or data of the executable is quoted, only |
| 7 | is quoted, only the constants a call passes and the counts. Measured at `main` `1cc6e3c1`, SHA-256 | 7 | the constants a call passes and the counts. The call sites were measured at `main` `1cc6e3c1`, SHA-256 |
| 8 | `e95020b2fa4a721db3df59fdecf75621730ac559d8835252f6c3b658d5a08993`. | 8 | `e95020b2fa4a721db3df59fdecf75621730ac559d8835252f6c3b658d5a08993`; the shim column below is the current state, and |
| 9 | it has moved since then: `042c5f378` (#6919) gave every one of the 12 imports a shim (seven had none at `1cc6e3c1`). | ||
| 9 | 10 | ||
| 10 | ```powershell | 11 | ```powershell |
| 11 | python -I tools/import_call_sites.py game_scarlett_master.exe --dll xmem.dll --dll d3d12_xs.dll --dll xg_xs.dll | 12 | python -I tools/import_call_sites.py game_scarlett_master.exe --dll xmem.dll --dll d3d12_xs.dll --dll xg_xs.dll |
| @@ -15,19 +16,19 @@ The tool finds each import's thunk (`jmp [rip+disp32]` through its address-table | |||
| 15 | instructions that reach it. Its counts cover direct calls only, and a stray `E8`/`E9` byte could add one, so they are | 16 | instructions that reach it. Its counts cover direct calls only, and a stray `E8`/`E9` byte could add one, so they are |
| 16 | bounds, not a proof that every site is reached. | 17 | bounds, not a proof that every site is reached. |
| 17 | 18 | ||
| 18 | | Import | Call sites | Shim at `main` `1cc6e3c1` | | 19 | | Import | Call sites | Shim at `main` (since #6919) | |
| 19 | |---|---:|---| | 20 | |---|---:|---| |
| 20 | | `XMemVirtualAlloc` | 23 | yes, refuses every one of these 23 (below) | | 21 | | `XMemVirtualAlloc` | 23 | yes, all 23 types served (below) | |
| 21 | | `XMemMapPhysicalPages` | 12 | no | | 22 | | `XMemMapPhysicalPages` | 12 | yes (pagefile-backed 64 KiB pool) | |
| 22 | | `XMemAllocatePhysicalPages` | 4 | no | | 23 | | `XMemAllocatePhysicalPages` | 4 | yes | |
| 23 | | `XMemFreePhysicalPages` | 3 | no | | 24 | | `XMemFreePhysicalPages` | 3 | yes | |
| 24 | | `XMemMapPhysicalPagesScatter` | 2 | no | | 25 | | `XMemMapPhysicalPagesScatter` | 2 | yes | |
| 25 | | `XMemAlloc` | 3 | yes | | 26 | | `XMemAlloc` | 3 | yes | |
| 26 | | `XMemFree` | 3 (2 calls, 1 tail jump) | yes | | 27 | | `XMemFree` | 3 (2 calls, 1 tail jump) | yes | |
| 27 | | `XMemGetWorkingSetStatistics` | 3 | yes | | 28 | | `XMemGetWorkingSetStatistics` | 3 | yes | |
| 28 | | `XMemTransferMemory` | 1 | yes | | 29 | | `XMemTransferMemory` | 1 | yes | |
| 29 | | `XMemIsToolsMemAvailable` | 1 | no | | 30 | | `XMemIsToolsMemAvailable` | 1 | yes (returns `FALSE`) | |
| 30 | | `XMemAllocDefault`, `XMemFreeDefault` | 1 tail jump each, no call | no | | 31 | | `XMemAllocDefault`, `XMemFreeDefault` | 1 tail jump each, no call | yes | |
| 31 | 32 | ||
| 32 | The executable also exports one symbol, `__XMemAllocationHooks__`. | 33 | The executable also exports one symbol, `__XMemAllocationHooks__`. |
| 33 | 34 | ||
| @@ -50,10 +51,16 @@ The 23 sites pass these constants (`allocation_type`, `attributes`, `protect`; t | |||
| 50 | | `0x20406000` | `0x27` | `0x1004`, `0x1404`, `0x8404`, `0x2404`, `0x2004` | 5 (one each) | | 51 | | `0x20406000` | `0x27` | `0x1004`, `0x1404`, `0x8404`, `0x2404`, `0x2004` | 5 (one each) | |
| 51 | | `0x42000` | `0x7` | `0x1` | 1 | | 52 | | `0x42000` | `0x7` | `0x1` | 1 | |
| 52 | 53 | ||
| 53 | Every `attributes` value is nonzero, and `runtime/shims/xmem.cpp` returns `ERROR_NOT_SUPPORTED` for a nonzero value | 54 | Every `attributes` value is nonzero. Since #6919 `runtime/shims/xmem.cpp` does not decode them: `XMemVirtualAlloc` |
| 54 | ("until their host mapping is known"), so none of the 23 calls succeeds there. Past that check the shim would also | 55 | records the word (`xmem_attributes` in the startup trace) and accepts it. All 23 allocation types are served as well. |
| 55 | refuse the calls with `allocation_type` `0x20003000` (5 sites: the 2 MiB page mode) and those with bits it does not | 56 | The page-mode mask is `kXmem64kPages` `0x20400000`, which *is* `MEM_LARGE_PAGES | MEM_PHYSICAL`, so `0x20406000` |
| 56 | know: `0x4000` in `0x20406000` (5 sites) and `0x40000` in `0x42000` (1 site). | 57 | (`0x20400000 | MEM_RESERVE | MEM_REPLACE_PLACEHOLDER`) selects the 64 KiB page mode and replaces part of the |
| 58 | placeholder — `test_placeholders` in `runtime/test/xmem_test.cpp` allocates that exact shape and maps physical pages | ||
| 59 | into the carved window. The 23 sites divide as 17 in the 64 KiB mode (3 committed, 8 reserve-only windows, 1 plain | ||
| 60 | commit, 5 placeholder replacements), five in the 2 MiB mode `0x20000000` (committed 2 MiB-aligned through | ||
| 61 | `VirtualAlloc2`), and one `0x42000` = `MEM_RESERVE | MEM_RESERVE_PLACEHOLDER`, the ~185 MiB reservation the five | ||
| 62 | windows are carved out of (`docs/retail_boot_chain.md`, stops 10-11). That agrees with `docs/runtime_imports.md` | ||
| 63 | ("The retail executable", `xmem.dll` notes), which records the same 2 MiB and placeholder paths. | ||
| 57 | 64 | ||
| 58 | The `protect` values are not Win32 protections alone. The Windows SDK's `winnt.h` defines the graphics page protections | 65 | The `protect` values are not Win32 protections alone. The Windows SDK's `winnt.h` defines the graphics page protections |
| 59 | the high bits match: `PAGE_GRAPHICS_NOACCESS` `0x800`, `_READONLY` `0x1000`, `_READWRITE` `0x2000`, `_EXECUTE_READ` | 66 | the high bits match: `PAGE_GRAPHICS_NOACCESS` `0x800`, `_READONLY` `0x1000`, `_READWRITE` `0x2000`, `_EXECUTE_READ` |
| @@ -81,13 +88,14 @@ those two facts. The meaning of `flags`, and whether the page numbers in `pageAr | |||
| 81 | are **unmeasured**. | 88 | are **unmeasured**. |
| 82 | 89 | ||
| 83 | The sequence in the first function that calls them is: `XMemAllocatePhysicalPages`, then `XMemVirtualAlloc` of a range | 90 | The sequence in the first function that calls them is: `XMemAllocatePhysicalPages`, then `XMemVirtualAlloc` of a range |
| 84 | with `0x20402000` and attributes `0x23`, then `XMemMapPhysicalPages` of those pages at that range. So the physical-page calls depend on the | 91 | with `0x20402000` and attributes `0x23`, then `XMemMapPhysicalPages` of those pages at that range. That path no longer |
| 85 | attribute check above: until `XMemVirtualAlloc` accepts these attribute words, the map calls are never reached from | 92 | stops at `XMemVirtualAlloc`: since #6919 it accepts that attribute word and the reserve-only 64 KiB window. |
| 86 | there. | 93 | |
| 87 | 94 | The host's own AWE functions need `SeLockMemoryPrivilege`, which an ordinary user does not hold, so the shim emulates | |
| 88 | The host's own AWE functions need `SeLockMemoryPrivilege`, which an ordinary user does not hold, so a shim would | 95 | the pool rather than forwarding (#6919): a pagefile-backed section in 64 KiB pages, committed at once on Wine (and on demand on native Windows) and given |
| 89 | emulate the pool (a pagefile-backed section of 64 KiB pages, with views placed at the reserved range) instead of | 96 | physical memory as it is touched, with views placed at the reserved range. Pages keep their contents while unmapped or |
| 90 | forwarding. That is a design note, not a measurement. | 97 | mapped elsewhere, and one page can be mapped at several addresses. The attribute word is recorded, still not decoded, |
| 98 | and every page is 64 KiB, which all four callers' arithmetic agrees with (`runtime/shims/xmem.cpp`). | ||
| 91 | 99 | ||
| 92 | ## The other imports | 100 | ## The other imports |
| 93 | 101 | ||