diff options
| author | nicolas <44988633+nschlaepfer@users.noreply.github.com> | 2026-11-21 21:58:55 -0700 |
|---|---|---|
| committer | nicolas <44988633+nschlaepfer@users.noreply.github.com> | 2026-11-21 21:58:55 -0700 |
| commit | 5190d597c8c6efd4cefa615df79e7c1a5f008775 (patch) | |
| tree | b61d71980b1fdbfb7552873b320a84416263c770 /docs | |
| parent | b72fc5a4fec776ffa4b19d37c7bf8d62836e3df5 (diff) | |
| parent | 067d3e8b97189fcf272dc699fdbb871eae496660 (diff) | |
Merge keyboard-pad coverage with controller reading history
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/README.md | 1 | ||||
| -rw-r--r-- | docs/d3d12_command_objects.md | 70 | ||||
| -rw-r--r-- | docs/d3d12_vulkan.md | 218 | ||||
| -rw-r--r-- | docs/design.md | 19 | ||||
| -rw-r--r-- | docs/gameinput.md | 39 | ||||
| -rw-r--r-- | docs/rsc8_audio.md | 251 | ||||
| -rw-r--r-- | docs/shader_validation.md | 8 | ||||
| -rw-r--r-- | docs/testing.md | 7 |
8 files changed, 565 insertions, 48 deletions
diff --git a/docs/README.md b/docs/README.md index d207328ff..954b98b64 100644 --- a/docs/README.md +++ b/docs/README.md | |||
| @@ -41,6 +41,7 @@ method, scope and caveats. No game data is included. | |||
| 41 | | Document | Measured content | | 41 | | Document | Measured content | |
| 42 | |---|---| | 42 | |---|---| |
| 43 | | [audio.md](audio.md) | AWC banks: Opus, PCM and XMA2; lossless Ogg Opus repack and WAV paths. | | 43 | | [audio.md](audio.md) | AWC banks: Opus, PCM and XMA2; lossless Ogg Opus repack and WAV paths. | |
| 44 | | [rsc8_audio.md](rsc8_audio.md) | 641,428 `RSC8` v8001 resources across 4 archives: 100% AWC tag `0x5c` facial/lip-sync `crClipDictionary` paired with 48 kHz mono Opus dialogue, 0 hidden audio containers. | | ||
| 44 | | [awc_shorts.md](awc_shorts.md) | Export short streamed-music idents/stings by duration; stereo-aware, no re-encode. | | 45 | | [awc_shorts.md](awc_shorts.md) | Export short streamed-music idents/stings by duration; stereo-aware, no re-encode. | |
| 45 | | [audio_config.md](audio_config.md) | The music/radio record table: 1,589 records, exact durations, AWC stream ids; no start offsets. | | 46 | | [audio_config.md](audio_config.md) | The music/radio record table: 1,589 records, exact durations, AWC stream ids; no start offsets. | |
| 46 | | [radio_stations.md](radio_stations.md) | Audio-config station blocks: 19 records, boundary u32, content-id lists; VCRR 80/80 mapping; no start offsets. | | 47 | | [radio_stations.md](radio_stations.md) | Audio-config station blocks: 19 records, boundary u32, content-id lists; VCRR 80/80 mapping; no start offsets. | |
diff --git a/docs/d3d12_command_objects.md b/docs/d3d12_command_objects.md index a064eb5bd..8dd9fcadb 100644 --- a/docs/d3d12_command_objects.md +++ b/docs/d3d12_command_objects.md | |||
| @@ -295,10 +295,76 @@ passes a builder-specific object that also implements the interface. The byte of | |||
| 295 | the field meanings and the method at `+0x490` are **Open**. | 295 | the field meanings and the method at `+0x490` are **Open**. |
| 296 | 296 | ||
| 297 | This is the most important compatibility finding on this page. A replacement command list that | 297 | This is the most important compatibility finding on this page. A replacement command list that |
| 298 | implements only the public GCL7/GCL8 vtable is safe for the game's own public calls, but it is | 298 | implements only the public GCL7/GCL8 vtable is **not** safe to hand to `XboxBvhBuilder`'s build path. (Section 3.5a |
| 299 | **not** safe to hand to `XboxBvhBuilder`'s build path. The helper will touch fields the public | 299 | shows it is not safe for console-compiled callers' public calls either: the console list order differs from the PC |
| 300 | order past slot 26.) The helper will touch fields the public | ||
| 300 | object does not define and call `+0x490`, which a public-only vtable does not have. | 301 | object does not define and call `+0x490`, which a public-only vtable does not have. |
| 301 | 302 | ||
| 303 | ### 3.5a The FSR DLL as a second device client | ||
| 304 | |||
| 305 | `amd_fidelityfx_upscaler_xbox.dll` is a second shipped module compiled against the console device, the second | ||
| 306 | measured client of the console **command list** after the BVH builder (section 3.3), and the first one run. It is run | ||
| 307 | by `fsr_dispatch_test` with its measured Xbox backend | ||
| 308 | descriptor ([d3d12_vulkan.md Appendix A.3](d3d12_vulkan.md)), on a PC device behind the Xbox-ABI proxy, and its | ||
| 309 | command recorder (RVA `0x59a0`) was read with Ghidra 12.2 through REA. RVAs are from image base `0x180000000`. The | ||
| 310 | run's command-list calls are the same 13, in the same order, on an RTX 2000 Ada (driver 597.06) and on WARP. | ||
| 311 | |||
| 312 | **Device.** At context creation it calls slots 14, 15, 18, 19, 27, 38 and 76 and heap slot 9, all with the shapes the | ||
| 313 | PC order and the measured overrides predict; slot 76 takes the seven `CreateCommittedResource` arguments. During | ||
| 314 | `ffxDispatch` it adds 16 `CreateRootSignature` and heap slot 10 (the recorder also has a path that calls 24 | ||
| 315 | `CopyDescriptorsSimple`, not taken in this run), plus its two compute-pipeline paths: | ||
| 316 | |||
| 317 | - **Slot 67** (call at `0x56d9`) is **not** the PC `CreateProtectedResourceSession1`: it takes `(desc, riid, out)` | ||
| 318 | with `IID_ID3D12PipelineState` and a console-only desc: the root signature at `+0x00`, two pointers into the DLL | ||
| 319 | with sizes (`0x1c` and `0x14` bytes here) at `+0x08`..`+0x20`, and a copy of a code blob at `+0x28` with its size | ||
| 320 | at `+0x30` (`0x1080` bytes here; most likely the shader's native code). The proxy used to forward it to the PC | ||
| 321 | method at the same index; it now refuses it (`E_NOTIMPL`). When it fails, the DLL takes slot 62. | ||
| 322 | - **Slot 62** (call at `0x5825`) takes the measured `(D3D12_COMPUTE_PIPELINE_STATE_DESC*, 0, 0, riid, out)`. The PC | ||
| 323 | runtime refuses the DLL's code (`E_FAIL`): it is not a PC shader. The DLL's pipeline function then returns | ||
| 324 | `0x8000000d` (`0x4b85`), but the dispatch goes on, records the null pipeline and faults (`0x65ff`), which is where a | ||
| 325 | PC device stops. | ||
| 326 | - The DLL's 29 shaders are `DXBC` containers with `SFI0`, `ISG1`, `OSG1`, `PSV0`, `RTS0`, `HASH` and `ACCC` parts | ||
| 327 | and no `DXIL`. The `ACCC` payload starts with the tag `FSPX` in all 29; the game's own native shaders are `FSSM` | ||
| 328 | inside `XBCH` ([design.md](design.md)). What `FSPX` holds, and whether the existing unpacker and translator can | ||
| 329 | take it, is open; running FSR needs that, not the executable. | ||
| 330 | |||
| 331 | **Command list.** The console list is **not** the PC order past `ResourceBarrier`. Each row is backed by the | ||
| 332 | argument shape at the call and, where marked "run", by the call seen in the run. Rows marked "inferred" fit the | ||
| 333 | shape and the shift around them, but the shape alone does not single the method out: | ||
| 334 | |||
| 335 | | Console slot (offset) | PC slot | Method | Evidence | | ||
| 336 | |---|---|---|---| | ||
| 337 | | 14 (`+0x70`) | 14 | `Dispatch` | the vtable path of the inline dispatch at `0x59a0`; the BVH builder's `Dispatch(1,1,1)` at `+0x70` | | ||
| 338 | | 15 (`+0x78`) | 15 | `CopyBufferRegion` | run: `(resource, 0, resource, …)` | | ||
| 339 | | 25 (`+0xc8`) | 25 | `SetPipelineState` | `(pipeline)` at `0x59a0` | | ||
| 340 | | 26 (`+0xd0`) | 26 | `ResourceBarrier` | run: `(1, barriers)`; the BVH builder's `+0xd0` | | ||
| 341 | | 32 (`+0x100`) | **28** | `SetDescriptorHeaps` | run: `(1, &heap)`, the heap a device-proxy descriptor heap | | ||
| 342 | | 33 (`+0x108`) | **29** | `SetComputeRootSignature` (inferred) | one pointer argument, the first call at `0x59a0` (null in the run, where pipeline creation had failed) | | ||
| 343 | | 35 (`+0x118`) | **31** | `SetComputeRootDescriptorTable` | `(index, heap GPU start + offset)` at `0x59a0` | | ||
| 344 | | 41 (`+0x148`) | **37** | `SetComputeRootConstantBufferView` (inferred) | `(index, 64-bit GPU VA from the constant allocator)` at `0x6738`; the root SRV/UAV setters take the same shape | | ||
| 345 | | 53 (`+0x1a8`) | **49** | `ClearUnorderedAccessViewUint` | run: `(GPU handle, CPU handle, resource, …)` | | ||
| 346 | | 61 (`+0x1e8`) | **59** | `ExecuteIndirect` | `(signature, 1, argument buffer, offset, null, 0)` at `0x59a0` | | ||
| 347 | | 85 (`+0x2a8`) | — | console only | run: `(stack pointer, 0, 0)`, twice per dispatch | | ||
| 348 | | 141 (`+0x468`) | — | console only | `(2, GPU VA, size, n)` at `0x65f8`: binds a buffer the DLL names `FFX_XBox_ComputeScratch` | | ||
| 349 | |||
| 350 | So the console list has four more methods than the PC list between `ResourceBarrier` (26) and `SetDescriptorHeaps` | ||
| 351 | (console 32), and two fewer between `ClearUnorderedAccessViewUint` (console 53) and `ExecuteIndirect` (console 61). | ||
| 352 | Mapping the console list as "PC plus a constant" is wrong. The BVH builder's `+0x490` (slot 146) is also past the | ||
| 353 | end of the PC list, like 141. | ||
| 354 | |||
| 355 | **The list object is wider than its vtable, and this is what that width is for.** Before a root-argument or dispatch | ||
| 356 | call the DLL checks a write cursor at `+0x18` against a limit (`+0x30` for root arguments, `+0x28` for a dispatch). While there is room, | ||
| 357 | it writes the command into that buffer itself instead of calling: a root argument is a header word from the | ||
| 358 | per-root-parameter table at `+0x344` and then the value (32 bits for a descriptor table, 64 for the slot-41 GPU VA), | ||
| 359 | a dispatch four words (`0x4002c400`, or `(flag | 0x1000ba00) << 2`, then x, y, z). | ||
| 360 | It sets a flag byte at `+0x140`, stores a flag at `+0x141` from the | ||
| 361 | pipeline, and copies 32 bytes of the pipeline object (from its `+0x10`) to `+0x544`. These are the fields | ||
| 362 | section 3.4 measured in the BVH builder's helper without a meaning (`+0x18`, `+0x30`, `+0x140`, `+0x344`, `+0x544`). | ||
| 363 | **With the cursor at the limit, every command goes through the vtable**: that is how `fsr_dispatch_test` records | ||
| 364 | them, and it is the simplest contract for a layer that does not want to decode these packets. Whether the game's | ||
| 365 | executable makes the same check before writing is unknown until it is available; it is compiled against the same | ||
| 366 | console headers. | ||
| 367 | |||
| 302 | ### 3.5 What the package does not measure | 368 | ### 3.5 What the package does not measure |
| 303 | 369 | ||
| 304 | There is no shipped client for `ID3D12CommandQueue`, `ID3D12Fence`, `ID3D12CommandAllocator`, | 370 | There is no shipped client for `ID3D12CommandQueue`, `ID3D12Fence`, `ID3D12CommandAllocator`, |
diff --git a/docs/d3d12_vulkan.md b/docs/d3d12_vulkan.md index bb3f1172f..fce09833a 100644 --- a/docs/d3d12_vulkan.md +++ b/docs/d3d12_vulkan.md | |||
| @@ -172,6 +172,29 @@ What is implemented (all of it testable without the game): | |||
| 172 | range and buffer bound is checked before anything is written. A copy runs in `TRANSFER_SRC`/`TRANSFER_DST`, or | 172 | range and buffer bound is checked before anything is written. A copy runs in `TRANSFER_SRC`/`TRANSFER_DST`, or |
| 173 | in place in `GENERAL` when the texture is in `COMMON`: that is D3D12's implicit promotion to a copy state. | 173 | in place in `GENERAL` when the texture is in `COMMON`: that is D3D12's implicit promotion to a copy state. |
| 174 | A 3D mip is one subresource. Boxed volume transfers preserve the full footprint's row and slice strides. | 174 | A 3D mip is one subresource. Boxed volume transfers preserve the full footprint's row and slice strides. |
| 175 | **D24_UNORM_S8_UINT without a native D24** (the Radeon 880M, AMD hardware generally, RADV): the layer stores | ||
| 176 | `D32_SFLOAT_S8_UINT` and makes it behave as D24 (`src/depth24.h`, `src/vulkan_depth24.h`). A footprint | ||
| 177 | of the depth plane holds 24-bit UNORM words (bits 0-23; the top byte is unspecified, the PC runtime reads it as | ||
| 178 | nothing and writes 0), the stencil plane is plain bytes. An upload converts the words with a compute pass | ||
| 179 | (`src/depth24_convert.comp`, integer arithmetic) into a scratch buffer of floats, the nearest float to | ||
| 180 | `d / 16777215`, which `vkCmdCopyBufferToImage` then moves into the image; a readback copies the image into the | ||
| 181 | scratch and the pass writes the words (a float is multiplied by 16777215 in float and rounded to nearest, ties to | ||
| 182 | even, which is what WARP and AMD's D3D12 driver do; NaN and negatives are 0, 1 and above the maximum). Every | ||
| 183 | 24-bit word makes the round trip unchanged (checked on all 16777216 by `depth24_convert_test`). Texture to | ||
| 184 | texture copies move the floats as they are. `ClearDepthStencilView` of any D24 texture, native or stored as D32, clears with the float of the quantised value (an exact 24-bit value, so no driver tie rounding is left), | ||
| 185 | so the texture reads back as D3D's quantisation of the clear value. The scratch buffers and descriptors live | ||
| 186 | until the submission that used them completes. A copy larger than the device's `maxStorageBufferRange` (128 MiB at | ||
| 187 | least) is split into several dispatches, by slices or by rows of one slice. The dispatch runs even under a | ||
| 188 | `SetPredication` that would skip copies: the layer runs copies unpredicated (section 4.7) and the conversion | ||
| 189 | must go with them, so conditional rendering is ended around it. The D3D11.3 functional spec (3.2.3.6, FLOAT to | ||
| 190 | UNORM) says: NaN is 0, the value is clamped to 0..1, multiplied by 2^n - 1 in float, 0.5 is added and the | ||
| 191 | fraction dropped, with a tolerance of 0.6 ULP on the integer side; read literally a tie rounds up, and 3.2.2 | ||
| 192 | lists this conversion as an exception to round-to-nearest-even without fixing ties. WARP and AMD's D3D12 driver | ||
| 193 | were measured to round the float product to nearest even (2.5 gives 2, 0.5 gives 0), which the tolerance | ||
| 194 | allows; NVIDIA's D3D12 driver (and a native D24 clear in its Vulkan driver) breaks some of those ties the other way; | ||
| 195 | the layer follows WARP and AMD there, a measurement and not a rule of the spec. Not covered: a depth test or | ||
| 196 | a depth write by the rasteriser works on D32 and may differ from D24 by up to the 24-bit step, and a depth | ||
| 197 | texture sampled in a shader sees the float; only copies, clears and readbacks are bit-exact. | ||
| 175 | `ResolveSubresource` becomes `vkCmdResolveImage` in the same layouts as a copy: a multisampled colour | 198 | `ResolveSubresource` becomes `vkCmdResolveImage` in the same layouts as a copy: a multisampled colour |
| 176 | subresource into a single-sampled one of the same size and format. `ResolveSubresourceRegion` uses the same | 199 | subresource into a single-sampled one of the same size and format. `ResolveSubresourceRegion` uses the same |
| 177 | Vulkan operation for non-integer colour with average mode, taking a source rectangle (or the entire subresource) | 200 | Vulkan operation for non-integer colour with average mode, taking a source rectangle (or the entire subresource) |
| @@ -240,31 +263,38 @@ What is implemented (all of it testable without the game): | |||
| 240 | - `CopyDescriptors` / `CopyDescriptorsSimple`. A descriptor is the bytes of its slot, so a copy is a byte copy: | 263 | - `CopyDescriptors` / `CopyDescriptorsSimple`. A descriptor is the bytes of its slot, so a copy is a byte copy: |
| 241 | the destination and source range lists are walked together, one descriptor at a time, and null size arrays | 264 | the destination and source range lists are walked together, one descriptor at a time, and null size arrays |
| 242 | mean one descriptor per range; | 265 | mean one descriptor per range; |
| 243 | - committed buffers (upload and readback heaps mapped persistently and zeroed) and 2D textures in the common | 266 | - committed buffers (upload and readback heaps mapped persistently and zeroed), 1D textures and 1D arrays, and |
| 244 | render-target, depth and texture formats (typeless families become mutable-format images), plus non-attachment | 267 | 2D textures in the common render-target, depth and texture formats (typeless families become mutable-format |
| 245 | 3D textures with mipmapped upload, image copy and readback, and multisampled 2D textures (single-mip render | 268 | images), plus non-attachment 3D textures with mipmapped upload, image copy and readback, and multisampled 2D |
| 246 | targets or depth-stencils, in the sample counts the GPU has for the format); | 269 | textures (single-mip render targets or depth-stencils, in the sample counts the GPU has for the format); |
| 247 | - packed `R9G9B9E5_SHAREDEXP` textures map to `VK_FORMAT_E5B9G9R9_UFLOAT_PACK32` for uploads and sampled views; | 270 | - packed `R9G9B9E5_SHAREDEXP` textures map to `VK_FORMAT_E5B9G9R9_UFLOAT_PACK32` for uploads and sampled views; |
| 248 | - the descriptor shader samples `B5G5R5A1_UNORM` through a 2D SRV. Opaque and transparent red check bit 15, | 271 | - the descriptor shader samples `B5G5R5A1_UNORM` through a 2D SRV. Opaque and transparent red check bit 15, |
| 249 | and mixed-channel texels check the five-bit color fields; | 272 | and mixed-channel texels check the five-bit color fields; |
| 273 | - `R10G10B10_XR_BIAS_A2_UNORM` maps to `VK_FORMAT_A2B10G10R10_UNORM_PACK32`, the same packed 10:10:10:2 | ||
| 274 | layout; the bias and scale are the application's shader work. Like the PC runtime, it accepts only a | ||
| 275 | single-mip, single-sample 2D texture: extra mips, multisampling and 3D are refused in creation, allocation | ||
| 276 | and footprints. Format support reports `TEXTURE2D` and `CAST_WITHIN_BIT_LAYOUT`, not the host's display, | ||
| 277 | back-buffer-cast or video-processor bits; | ||
| 278 | - `CheckFeatureSupport` for feature levels (up to 12_1), architecture, D3D12 options (`OPTIONS`, | ||
| 279 | `OPTIONS2`–`5`, `7`–`9`, `11`, `13`–`21`), GPU virtual-address support, format support, format plane counts, | ||
| 280 | multisample quality levels, shader model and root signature version. | ||
| 250 | - `CheckFeatureSupport` for feature levels (up to 12_1), architecture, D3D12 options, GPU virtual-address | 281 | - `CheckFeatureSupport` for feature levels (up to 12_1), architecture, D3D12 options, GPU virtual-address |
| 251 | support, format support, multisample quality levels, shader model and root signature version. | 282 | support, format support, multisample quality levels, shader model and root signature version. |
| 252 | `D3D12_OPTIONS8` reports unaligned block textures when the Vulkan logical device enables BC texture compression. | 283 | `D3D12_OPTIONS8` reports unaligned block textures when the Vulkan logical device enables BC texture compression. |
| 253 | Other queries are logged and refused until the trace shows what the game asks (question 11); | 284 | Other queries, including `OPTIONS1`, `6`, `10` and `12`, are logged and refused until the trace shows what |
| 254 | - `CheckFeatureSupport` for feature levels (up to 12_1), architecture, D3D12 options (`OPTIONS` and `OPTIONS2`–`5`, `7`, `9`, `11`, `13`–`21`), GPU virtual-address | 285 | the game asks (question 11); |
| 255 | support, format support and multisample quality levels. Other queries (including `OPTIONS1`/`6`/`8`/`10`/`12`, `FORMAT_INFO`, `SHADER_MODEL`, and `ROOT_SIGNATURE` left to sibling PRs) are logged and refused until the trace | ||
| 256 | shows what the game asks (question 11); | ||
| 257 | support, format support, multisample quality levels, shader model and root signature version. Other queries are | ||
| 258 | logged and refused until the trace shows what the game asks (question 11); | ||
| 259 | - Single-sampled `A8_UNORM` 2D textures use one byte per texel in `VK_FORMAT_R8_UNORM`. Their SRVs expose | 286 | - Single-sampled `A8_UNORM` 2D textures use one byte per texel in `VK_FORMAT_R8_UNORM`. Their SRVs expose |
| 260 | (0, 0, 0, A) before applying the caller's component mapping. Format support includes `MIP` when the Vulkan | 287 | (0, 0, 0, A) before applying the caller's component mapping. Format support includes `MIP` when the Vulkan |
| 261 | image supports multiple levels. Render-target, depth-stencil and UAV creation are unsupported for this format. | 288 | image supports multiple levels. Render-target, depth-stencil and UAV creation are unsupported for this format. |
| 262 | support, format support, format plane counts, multisample quality levels, shader model and root signature | 289 | support, format support, format plane counts, multisample quality levels, shader model and root signature |
| 263 | version. Other queries are logged and refused until the trace shows what the game asks (question 11); | 290 | version. Other queries are logged and refused until the trace shows what the game asks (question 11); |
| 291 | Other queries, including `OPTIONS1`, `6`, `10` and `12`, are logged and refused until the trace shows what | ||
| 292 | the game asks (question 11); | ||
| 264 | - reserved resources and `GetResourceTiling` (section 4.2); | 293 | - reserved resources and `GetResourceTiling` (section 4.2); |
| 265 | - query heaps for occlusion, timestamps and pipeline statistics, and `GetTimestampFrequency` on the queue | 294 | - query heaps for occlusion, timestamps and pipeline statistics, and `GetTimestampFrequency` on the queue |
| 266 | (section 4.6); | 295 | (section 4.6); |
| 267 | - `GetCopyableFootprints` for buffers, 2D textures and volumes, including BC1–7 and the two-plane depth-stencil formats. | 296 | - `GetCopyableFootprints` for buffers, 1D and 1D-array textures, 2D textures and volumes, including BC1–7 and the |
| 297 | two-plane depth-stencil formats. | ||
| 268 | The test compares every output with the PC runtime's; that comparison found that planar | 298 | The test compares every output with the PC runtime's; that comparison found that planar |
| 269 | depth-stencil rows are padded to 512 bytes, not 256. | 299 | depth-stencil rows are padded to 512 bytes, not 256. |
| 270 | - the `1`/`2`/`3` variants as wrappers over the methods above (D3D-28): `CreateCommittedResource1/2/3`, | 300 | - the `1`/`2`/`3` variants as wrappers over the methods above (D3D-28): `CreateCommittedResource1/2/3`, |
| @@ -355,6 +385,9 @@ side inwards: | |||
| 355 | `CreateSampler` an S#; each then makes sure set 0 has the view or sampler and the table has the key. Details: | 385 | `CreateSampler` an S#; each then makes sure set 0 has the view or sampler and the table has the key. Details: |
| 356 | - The key is the descriptor's bytes, so a copied descriptor needs nothing more, and an unordered-access view | 386 | - The key is the descriptor's bytes, so a copied descriptor needs nothing more, and an unordered-access view |
| 357 | and a shader-resource view of the same mip are one entry. | 387 | and a shader-resource view of the same mip are one entry. |
| 388 | - A D3D12 comparison sampler with function NEVER and an ordinary sampler both encode zero in the hardware | ||
| 389 | depth comparison field. The layer marks the NEVER comparison in S# word 3, bit 12 (unused with | ||
| 390 | DERIV_ADJUST_EN clear) to give it a separate lookup key and a comparison-enabled Vulkan sampler. | ||
| 358 | - A view the layer cannot show (below) leaves a null descriptor, all zeros, which finds the fallback. | 391 | - A view the layer cannot show (below) leaves a null descriptor, all zeros, which finds the fallback. |
| 359 | - A texture is named in its T#s by an address of its own, above 4 GiB and 256 bytes apart, that nothing | 392 | - A texture is named in its T#s by an address of its own, above 4 GiB and 256 bytes apart, that nothing |
| 360 | dereferences; its entries leave the set and the table when it is destroyed. | 393 | dereferences; its entries leave the set and the table when it is destroyed. |
| @@ -382,8 +415,9 @@ Known gaps in the descriptor path: buffer shader-resource and unordered-access v | |||
| 382 | (the V# a shader would load for them; the structure is in `gfx10_descriptors.h`, the views are not written); | 415 | (the V# a shader would load for them; the structure is in `gfx10_descriptors.h`, the views are not written); |
| 383 | views of 1D and multisampled textures, 3D storage views and typeless volume SRVs; depth-plane views (`R24_UNORM_X8_TYPELESS`, | 416 | views of 1D and multisampled textures, 3D storage views and typeless volume SRVs; depth-plane views (`R24_UNORM_X8_TYPELESS`, |
| 384 | `R32_FLOAT_X8X24_TYPELESS`) are a T# of the texture's depth format (8_24_UNORM, X24_8_32_FLOAT) through the | 417 | `R32_FLOAT_X8X24_TYPELESS`) are a T# of the texture's depth format (8_24_UNORM, X24_8_32_FLOAT) through the |
| 385 | depth aspect, each on its own family only (the other family's is a null descriptor, as D3D12 refuses it), and | 418 | depth aspect (the texture's backing format, so X24_8_32_FLOAT for a D24 texture where the layer stores it as |
| 386 | stencil-plane views (`PlaneSlice` 1, as | 419 | `D32_SFLOAT_S8_UINT`), each on its own family only (the other family's is a null |
| 420 | descriptor, as D3D12 refuses it), and stencil-plane views (`PlaneSlice` 1, as | ||
| 387 | `X24_TYPELESS_G8_UINT` or `X32_TYPELESS_G8X24_UINT`) are an 8_UINT T# that set 0 shows through the stencil | 421 | `X24_TYPELESS_G8_UINT` or `X32_TYPELESS_G8X24_UINT`) are an 8_UINT T# that set 0 shows through the stencil |
| 388 | aspect, in its float-typed sampled arrays like other UINT views; descriptors the game writes itself, which need | 422 | aspect, in its float-typed sampled arrays like other UINT views; descriptors the game writes itself, which need |
| 389 | the execute-time scan of section 3.4 (only descriptors made through the device are registered); static samplers | 423 | the execute-time scan of section 3.4 (only descriptors made through the device are registered); static samplers |
| @@ -403,7 +437,7 @@ rectangular clears of overlapping slice ranges against both Windows WARP and exp | |||
| 403 | Known gaps: buffer and constant-buffer views (UAV clears read the descriptor bytes, so they do not wait on view | 437 | Known gaps: buffer and constant-buffer views (UAV clears read the descriptor bytes, so they do not wait on view |
| 404 | creation), root signatures, PSOs, draws, typeless volume RTVs, | 438 | creation), root signatures, PSOs, draws, typeless volume RTVs, |
| 405 | placed resources, `GetGPUVirtualAddress` (the shared buffer arena), depth-stencil resolves, | 439 | placed resources, `GetGPUVirtualAddress` (the shared buffer arena), depth-stencil resolves, |
| 406 | 1D textures and the swapchain; | 440 | the swapchain; |
| 407 | default-heap buffers are not zero-filled yet; a fence cannot be signalled to a lower value (Vulkan timelines only | 441 | default-heap buffers are not zero-filled yet; a fence cannot be signalled to a lower value (Vulkan timelines only |
| 408 | increase; such a signal is reported and dropped); the GCL8 | 442 | increase; such a signal is reported and dropped); the GCL8 |
| 409 | front/back stencil references are recorded but not applied, because there is no pipeline or draw path for them to | 443 | front/back stencil references are recorded but not applied, because there is no pipeline or draw path for them to |
| @@ -412,8 +446,9 @@ affect. | |||
| 412 | Build `runtime/` (Vulkan SDK and Python 3 on `PATH`) and run `ctest --test-dir <build> --output-on-failure` for the | 446 | Build `runtime/` (Vulkan SDK and Python 3 on `PATH`) and run `ctest --test-dir <build> --output-on-failure` for the |
| 413 | CPU tests: | 447 | CPU tests: |
| 414 | - `command_list_test` covers the recording rules. | 448 | - `command_list_test` covers the recording rules. |
| 415 | - `d3d12_state_map_test` covers both state tables, subresource and barrier-range decoding, and layout tracking. On | 449 | - `d3d12_state_map_test` covers both state tables, subresource and barrier-range decoding, layout tracking, the |
| 416 | Windows it also checks every D3D12 constant the IR copies against the SDK's `d3d12.h`. | 450 | subresource ranges `DiscardResource` prepares, and Resizable BAR detection. On Windows it also checks every D3D12 |
| 451 | constant the IR copies against the SDK's `d3d12.h`. | ||
| 417 | - `gfx10_descriptors_test` covers the T#, S# and V#: every field alone at its bit position, round trips, what | 452 | - `gfx10_descriptors_test` covers the T#, S# and V#: every field alone at its bit position, round trips, what |
| 418 | decoding refuses and ignores, the T#s the image test shaders build, sampler words as radv writes them, and the | 453 | decoding refuses and ignores, the T#s the image test shaders build, sampler words as radv writes them, and the |
| 419 | format table. `tests/test_gfx10_descriptors.py` compares that table with `tools/gfx10_formats.json`. | 454 | format table. `tests/test_gfx10_descriptors.py` compares that table with `tools/gfx10_formats.json`. |
| @@ -456,7 +491,7 @@ and any validation error fails them. | |||
| 456 | Results come back through D3D12 itself (`CopyTextureRegion` into a readback heap, then `Map`): the render | 491 | Results come back through D3D12 itself (`CopyTextureRegion` into a readback heap, then `Map`): the render |
| 457 | target, the depth and stencil planes, and a never-written texture (which must be zero). A second list uploads a | 492 | target, the depth and stencil planes, and a never-written texture (which must be zero). A second list uploads a |
| 458 | pattern and copies it on: whole into a texture created in `COMMON`, a boxed part into a smaller texture, a BC1 | 493 | pattern and copies it on: whole into a texture created in `COMMON`, a boxed part into a smaller texture, a BC1 |
| 459 | round trip and a buffer region. A 4x multisampled render target is cleared through a `TEXTURE2DMS` view and | 494 | round trip, a 1D texture and a 1D-array layer, and a buffer region. A 4x multisampled render target is cleared through a `TEXTURE2DMS` view and |
| 460 | resolved into a texture that is read back; the multisampled shapes D3D12 refuses are refused, and so is a | 495 | resolved into a texture that is read back; the multisampled shapes D3D12 refuses are refused, and so is a |
| 461 | resolve from a single-sampled texture. `GetCopyableFootprints` is compared with the PC runtime's, and a short | 496 | resolve from a single-sampled texture. `GetCopyableFootprints` is compared with the PC runtime's, and a short |
| 462 | run repeats on a standalone device, the path `LEONIDA_D3D12=vulkan` takes. | 497 | run repeats on a standalone device, the path `LEONIDA_D3D12=vulkan` takes. |
| @@ -493,15 +528,28 @@ and any validation error fails them. | |||
| 493 | `invalid_copy`. A fix needs a staging copy through a buffer. The test prints these as known differences. | 528 | `invalid_copy`. A fix needs a staging copy through a buffer. The test prints these as known differences. |
| 494 | - **`TEXTURE1D`** resources are not supported by the layer (creation, footprints and allocation info refuse | 529 | - **`TEXTURE1D`** resources are not supported by the layer (creation, footprints and allocation info refuse |
| 495 | them), so 1D copies are not compared. | 530 | them), so 1D copies are not compared. |
| 496 | - **`D24_UNORM_S8_UINT` on a GPU without it (the Radeon 880M)**: the layer stores `D32_SFLOAT_S8_UINT`, and an | 531 | - On a GPU with a native D24, a readback leaves the unspecified `X8` byte of the depth plane untouched where the PC |
| 497 | upload or readback copies the bits without converting 24-bit unorm to float, so the values a D24 texture | 532 | runtime writes 0; the comparison ignores it. Where the layer stores D24 as D32 (see section 3.2) it writes 0. |
| 498 | holds are not the ones the game wrote. Only the bit-preserving copies (`CopyResource`, box and slice copies | ||
| 499 | between two D24 textures) are checked there, against the layer's own readback of the source; the upload | ||
| 500 | and readback paths are not compared. A fix needs a conversion pass (compute) around such copies. | ||
| 501 | - On a GPU with D24, a readback leaves the unspecified `X8` byte of the depth plane untouched where the PC | ||
| 502 | runtime writes 0; the comparison ignores it. | ||
| 503 | A PC driver's copy flushes denormal float depth to zero, so the test keeps its values normal. A | 533 | A PC driver's copy flushes denormal float depth to zero, so the test keeps its values normal. A |
| 504 | `LEONIDA_HOST_ADAPTER` that matches no adapter fails the run instead of skipping the comparisons. | 534 | `LEONIDA_HOST_ADAPTER` that matches no adapter fails the run instead of skipping the comparisons. |
| 535 | - D24 against the host (`d3d12_depth24_compare.h`, `depth24_convert_test`): the D24S8 row of the copy test | ||
| 536 | above runs with random 24-bit words on every GPU, the Radeon 880M's `D32_SFLOAT_S8_UINT` fallback included | ||
| 537 | (72 regions, byte for byte, upload, readback and copies). `d3d12_depth24_compare.h` clears 5215 depth values | ||
| 538 | (steps, half steps and the floats around them, powers of two, random) as a whole-view clear of a 4x4 texture | ||
| 539 | (the first 160) and as one rectangle clear per value of a wide texture, with a stencil value, and compares both | ||
| 540 | planes read back. The layer is checked against the reference (`depth24_quantize`), and against the host byte for byte | ||
| 541 | where the host agrees with it; NVIDIA's host rounds some ties the other way (478 of 5215 values) and is logged as a host quirk, not a failure. It also clears an | ||
| 542 | `R24G8_TYPELESS` texture through a typed D24 DSV (200 values, compared the same way), and reports whether | ||
| 543 | shader-resource views of both planes (`R24_UNORM_X8_TYPELESS`, `X24_TYPELESS_G8_UINT`) write the T# of the | ||
| 544 | texture's backing format (D3D-75): X24_8_32_FLOAT for the depth plane where the layer stores the texture as | ||
| 545 | `D32_SFLOAT_S8_UINT`, 8_24_UNORM where the GPU has D24, and 8_UINT for the stencil plane. An SRV read is not compared with the host (no shader runs in these tests and the host's | ||
| 546 | descriptor is opaque). It also runs an upload and readback under a `SetPredication` that skips copies, which the | ||
| 547 | layer must still convert and which is compared with the host's unpredicated run. `depth24_convert_test` runs the | ||
| 548 | compute pass on the GPU for all 16777216 words (to float, and back), 16777216 float bit patterns against | ||
| 549 | `depth24_quantize` (with a 1 MiB range so the copy splits into 65 dispatches), and a pitched copy at an offset | ||
| 550 | split by a 1 KiB range. It tests the pass, which needs no D24 absence, on whatever device | ||
| 551 | `VK_LOADER_DRIVERS_SELECT` picks; the layer's own D24 path (the D3D12 tests above) is used only on a GPU without | ||
| 552 | D24 depth-attachment support, so run those with the AMD driver selected (the Radeon 880M, RADV). | ||
| 505 | - `d3d12_method_variants_test`: each variant against the method it wraps, on the device directly (the proxy's | 553 | - `d3d12_method_variants_test`: each variant against the method it wraps, on the device directly (the proxy's |
| 506 | slot 76 is the Xbox texture method, not `CreateCommittedResource3`). It runs 12 creation cases (buffers on the | 554 | slot 76 is the Xbox texture method, not `CreateCommittedResource3`). It runs 12 creation cases (buffers on the |
| 507 | three heap types, textures, a volume, a multisampled target, and three shapes the base refuses) through every | 555 | three heap types, textures, a volume, a multisampled target, and three shapes the base refuses) through every |
| @@ -668,8 +716,11 @@ The layer's descriptor model: | |||
| 668 | - RTV/DSV creation builds a `VkImageView` and stores it in the host-side heap; `OMSetRenderTargets` resolves those | 716 | - RTV/DSV creation builds a `VkImageView` and stores it in the host-side heap; `OMSetRenderTargets` resolves those |
| 669 | handles to views for the rendering scope. RTV/DSV descriptors are never shader-visible. | 717 | handles to views for the rendering scope. RTV/DSV descriptors are never shader-visible. |
| 670 | - View creation maps `D3D12_SRV_DIMENSION`/`D3D12_UAV_DIMENSION` to `VkImageViewType`, the mip and layer ranges, | 718 | - View creation maps `D3D12_SRV_DIMENSION`/`D3D12_UAV_DIMENSION` to `VkImageViewType`, the mip and layer ranges, |
| 671 | sample count, and `D3D12_SHADER_COMPONENT_MAPPING` to `VkComponentMapping`. `ResourceMinLODClamp` needs | 719 | sample count, and `D3D12_SHADER_COMPONENT_MAPPING` to `VkComponentMapping`. Single-sampled 2D colour SRVs |
| 672 | `VK_EXT_image_view_min_lod`; log if the device lacks it instead of silently ignoring the clamp. | 720 | apply the T# minimum LOD in resource mip coordinates. A clamp inside the exposed mip range uses |
| 721 | `VK_EXT_image_view_min_lod`. If the logical device lacks the feature, the runtime logs the unsupported view | ||
| 722 | and its descriptor resolves to the fallback. A clamp at or below the first mip needs no extension. Above the | ||
| 723 | last mip, the view retains its dimensions and maps sampled channels to zero while preserving constant channels. | ||
| 673 | - Set 0 is a fixed bindless layout. The GPU tests use 4096 sampled 2D images, 1024 samplers, 1024 2D-array | 724 | - Set 0 is a fixed bindless layout. The GPU tests use 4096 sampled 2D images, 1024 samplers, 1024 2D-array |
| 674 | images, 256 1D, 256 3D, 1024 storage images and 256 per storage dimension/class; start there and grow by | 725 | images, 256 1D, 256 3D, 1024 storage images and 256 per storage dimension/class; start there and grow by |
| 675 | recreating the set at a frame boundary. Use `UPDATE_AFTER_BIND` and `PARTIALLY_BOUND` so a new view does not | 726 | recreating the set at a frame boundary. Use `UPDATE_AFTER_BIND` and `PARTIALLY_BOUND` so a new view does not |
| @@ -882,6 +933,15 @@ The trace will enumerate them. | |||
| 882 | there, so 1.1 is what the game can rely on everywhere. A higher request is clamped down like the shader model, and | 933 | there, so 1.1 is what the game can rely on everywhere. A higher request is clamped down like the shader model, and |
| 883 | an undefined value is refused. Measured against the host PC runtime (616.86): 1.0-1.2 echo the request, and a | 934 | an undefined value is refused. Measured against the host PC runtime (616.86): 1.0-1.2 echo the request, and a |
| 884 | wrong `DataSize` is `E_INVALIDARG`; the host crashed on a null buffer, so the test never gives it one. | 935 | wrong `DataSize` is `E_INVALIDARG`; the host crashed on a null buffer, so the test never gives it one. |
| 936 | - `D3D12_FEATURE_D3D12_OPTIONS1`: answer from the Vulkan device's subgroups. `WaveOps` is true only when every | ||
| 937 | operation group the wave intrinsics map to is present (`BASIC`, `VOTE`, `BALLOT`, `SHUFFLE`, `ARITHMETIC`), | ||
| 938 | because D3D12 promises them all behind that one bool. `WaveLaneCountMin`/`Max` are the subgroup size range | ||
| 939 | (`VkPhysicalDeviceSubgroupSizeControlProperties`, or the single `subgroupSize` without those 1.3 properties). | ||
| 940 | `TotalLaneCount` has no Vulkan equivalent: D3D12 counts every lane of the device, and the layer answers one full | ||
| 941 | wave, so a game that sizes work from it plans for less parallelism than the GPU has, never more. Measured | ||
| 942 | against the host PC runtime (616.86) on an RTX 5070: `S_OK` with `WaveOps` 1, lanes 32..32 and a total of 6144, | ||
| 943 | and `E_INVALIDARG` for a `DataSize` one field too short or too long. The host crashed the process on a null | ||
| 944 | buffer, so the layer refuses one without asking the host (as with root signatures). | ||
| 885 | - `D3D12_OPTIONS` families: report the tier the Vulkan feature set can honour (resource binding tier 3 when | 945 | - `D3D12_OPTIONS` families: report the tier the Vulkan feature set can honour (resource binding tier 3 when |
| 886 | descriptor indexing and update-after-bind are available), plus wave ops, 16-bit, barycentrics, render passes, | 946 | descriptor indexing and update-after-bind are available), plus wave ops, 16-bit, barycentrics, render passes, |
| 887 | VRS, mesh shader tier, and RT tier 1.1 only if the layer can honour them. The game may branch on these; a false | 947 | VRS, mesh shader tier, and RT tier 1.1 only if the layer can honour them. The game may branch on these; a false |
| @@ -922,6 +982,14 @@ The trace will enumerate them. | |||
| 922 | on the PC runtime, so none here either. Texture sizes are the driver's on both runtimes, so only buffer sizes, | 982 | on the PC runtime, so none here either. Texture sizes are the driver's on both runtimes, so only buffer sizes, |
| 923 | alignments and invalid descriptions are compared with the host. One known difference: a mip count beyond the | 983 | alignments and invalid descriptions are compared with the host. One known difference: a mip count beyond the |
| 924 | full chain is invalid here (Vulkan can't create it), while the PC runtime still answers with a size. | 984 | full chain is invalid here (Vulkan can't create it), while the PC runtime still answers with a size. |
| 985 | - `GetAdapterLuid` (implemented): `VkPhysicalDeviceIDProperties::deviceLUID`, which on Windows is the DXGI | ||
| 986 | adapter's LUID; `d3d12_fence_timing_test` finds it with `IDXGIFactory4::EnumAdapterByLuid` (RTX 4090, driver | ||
| 987 | 621.14). A driver that reports `deviceLUIDValid = VK_FALSE` gets a zero LUID, logged. | ||
| 988 | - `GetCustomHeapProperties` (implemented): the D3D12 documentation's table for a NUMA adapter, matching the | ||
| 989 | `UMA = FALSE` that `D3D12_FEATURE_ARCHITECTURE` reports: `DEFAULT` is `NOT_AVAILABLE`/`L1`, `UPLOAD` | ||
| 990 | `WRITE_COMBINE`/`L0`, `READBACK` `WRITE_BACK`/`L0`, `GPU_UPLOAD` `WRITE_COMBINE`/`L1`, all with type `CUSTOM` and | ||
| 991 | node masks 1. `CUSTOM`, unknown types and node masks above 1 get an all-zero answer, logged. The test compares | ||
| 992 | `DEFAULT`, `UPLOAD` and `READBACK` byte for byte with the host runtime's answer (RTX 4090: identical). | ||
| 925 | - Residency and power (D3D-33) are no-ops that still check their arguments (`d3d12_vulkan_device.cpp`, tested in | 993 | - Residency and power (D3D-33) are no-ops that still check their arguments (`d3d12_vulkan_device.cpp`, tested in |
| 926 | `d3d12_vulkan_device_test`). Vulkan has no residency API: memory from `vkAllocateMemory` stays usable until | 994 | `d3d12_vulkan_device_test`). Vulkan has no residency API: memory from `vkAllocateMemory` stays usable until |
| 927 | `vkFreeMemory`, and paging under pressure is the kernel driver's job, so every pageable object is always resident. | 995 | `vkFreeMemory`, and paging under pressure is the kernel driver's job, so every pageable object is always resident. |
| @@ -972,8 +1040,10 @@ The trace will enumerate them. | |||
| 972 | `CheckFeatureSupport` still reports `TiledResourcesTier` as not supported, so a game that checks it creates | 1040 | `CheckFeatureSupport` still reports `TiledResourcesTier` as not supported, so a game that checks it creates |
| 973 | committed resources instead; raising the tier is a decision for when the trace shows what the game does. The Xbox tiled layout word `0x101` is accepted as `64KB_UNDEFINED_SWIZZLE` (**Assumption**: | 1041 | committed resources instead; raising the tier is a decision for when the trace shows what the game does. The Xbox tiled layout word `0x101` is accepted as `64KB_UNDEFINED_SWIZZLE` (**Assumption**: |
| 974 | that the console uses it for reserved resources too). | 1042 | that the console uses it for reserved resources too). |
| 975 | - `GetResourceTiling`: the standard 64 KiB tile shapes, standard and packed mips (a mip is packed from the first | 1043 | - `GetResourceTiling`: the standard 64 KiB tile shapes, standard and packed mips (a mip stays standard while it is |
| 976 | one smaller than a tile on any axis, as an NVIDIA GPU does; D3D11.3 functional spec 5.9.2.8.5 only requires that | 1044 | wider than half the tile or taller than the tile, depth not counting, as AMD's PC runtime does on RDNA2 and RDNA4 |
| 1045 | and so, most likely, the console (D3D-65); an NVIDIA GPU packs from the first mip smaller than a tile on any axis. | ||
| 1046 | D3D11.3 functional spec 5.9.2.8.5 only requires that | ||
| 977 | a mip filling a tile in every dimension stays standard, a smaller one "may or may not be packed, depending on the | 1047 | a mip filling a tile in every dimension stays standard, a smaller one "may or may not be packed, depending on the |
| 978 | IHV"), each standard mip's tile counts, and the tile order (each array slice holds | 1048 | IHV"), each standard mip's tile counts, and the tile order (each array slice holds |
| 979 | its standard mips, then its packed tiles). The test compares the tile shape and the tile counts of the mips both | 1049 | its standard mips, then its packed tiles). The test compares the tile shape and the tile counts of the mips both |
| @@ -993,7 +1063,7 @@ The trace will enumerate them. | |||
| 993 | Tile shapes agree in all 17 texture layouts, and 11 of them match exactly; in the other 6, AMD keeps more | 1063 | Tile shapes agree in all 17 texture layouts, and 11 of them match exactly; in the other 6, AMD keeps more |
| 994 | mips as standard tiles before the packed tail: | 1064 | mips as standard tiles before the packed tail: |
| 995 | 1065 | ||
| 996 | | Layout | Tile | Standard mips: ours | AMD | | 1066 | | Layout | Tile | Standard mips: NVIDIA (the layer before D3D-65) | AMD (the layer now) | |
| 997 | |---|---|---|---| | 1067 | |---|---|---|---| |
| 998 | | 1000x300 RGBA8 sRGB, 3 slices | 128x128 | 2 | 4 | | 1068 | | 1000x300 RGBA8 sRGB, 3 slices | 128x128 | 2 | 4 | |
| 999 | | 2048x1024 BC7, 2 slices | 256x256 | 3 | 4 | | 1069 | | 2048x1024 BC7, 2 slices | 256x256 | 3 | 4 | |
| @@ -1002,9 +1072,15 @@ The trace will enumerate them. | |||
| 1002 | | 4096x64 BGRA8 | 128x128 | 0 | 6 | | 1072 | | 4096x64 BGRA8 | 128x128 | 0 | 6 | |
| 1003 | | 256x256x64 RGBA8 volume | 32x32x16 | 3 | 4 | | 1073 | | 256x256x64 RGBA8 volume | 32x32x16 | 3 | 4 | |
| 1004 | 1074 | ||
| 1005 | All 17 AMD results fit "a mip is packed once every axis is at most half the tile's largest side" | 1075 | An RDNA2 GPU (the Ryzen 7 9800X3D's, driver 32.0.21045.5002) gives the same splits as the RDNA4 one |
| 1006 | (**Hypothesis**: one driver, one GPU). Which split the console's runtime uses, and so which one the layer should | 1076 | ([#374](https://github.com/ItsNotRexed/Leonida/issues/374#issuecomment-7071869388)). With 30 more layouts that |
| 1007 | follow, is **Open** ([#374](https://github.com/ItsNotRexed/Leonida/issues/374#issuecomment-7071680820)). | 1077 | probe the edges (a mip exactly at or just past half a tile, thin and tall textures, non-square 2D and volume |
| 1078 | tiles), the rule that fits all 47 on both GPUs is: **a mip stays standard while it is wider than half the tile or | ||
| 1079 | taller than the tile; depth does not count**. An earlier "every axis at most half the tile's largest side" fitted | ||
| 1080 | the first 17 but missed four tall or deep edge cases. All 47 layouts and AMD's values are in | ||
| 1081 | `runtime/test/resource_tiling_test.cpp`; the packed tile count is AMD's in 45 of them, and AMD reserves one more | ||
| 1082 | for the two deep volumes that pack from mip 0. The console is RDNA2, so the layer follows this rule (D3D-65; | ||
| 1083 | **Assumption**: that the console's runtime splits like the PC's AMD driver). | ||
| 1008 | - `UpdateTileMappings` / `CopyTileMappings` log once and do nothing. What that loses: two resources mapped to the | 1084 | - `UpdateTileMappings` / `CopyTileMappings` log once and do nothing. What that loses: two resources mapped to the |
| 1009 | same heap tiles do not alias, and a tile unmapped or remapped keeps its contents. If the trace shows the game | 1085 | same heap tiles do not alias, and a tile unmapped or remapped keeps its contents. If the trace shows the game |
| 1010 | relies on either, the next step is sparse binding (`sparseBinding`, `sparseResidencyImage2D`) with the heaps | 1086 | relies on either, the next step is sparse binding (`sparseBinding`, `sparseResidencyImage2D`) with the heaps |
| @@ -1178,12 +1254,31 @@ mapped stages/accesses, and if no single layout serves all uses, use `GENERAL` a | |||
| 1178 | - `SetEventOnCompletion(value, hEvent)`: a small wait thread calls `vkWaitSemaphores` and `SetEvent`. Reuse one | 1254 | - `SetEventOnCompletion(value, hEvent)`: a small wait thread calls `vkWaitSemaphores` and `SetEvent`. Reuse one |
| 1179 | thread with a condition variable; do not create a thread per fence. | 1255 | thread with a condition variable; do not create a thread per fence. |
| 1180 | - `GetCompletedValue` is `vkGetSemaphoreCounterValue`; CPU `Signal` is `vkSignalSemaphore`. | 1256 | - `GetCompletedValue` is `vkGetSemaphoreCounterValue`; CPU `Signal` is `vkSignalSemaphore`. |
| 1257 | - `SetEventOnMultipleFenceCompletion` (implemented). With a null event it is one blocking `vkWaitSemaphores` over | ||
| 1258 | every fence's semaphore, with `VK_SEMAPHORE_WAIT_ANY_BIT` for `D3D12_MULTIPLE_FENCE_WAIT_FLAG_ANY` and no flag for | ||
| 1259 | `ALL`. With an event, each fence's existing wait thread counts down one shared waiter (1 for `ANY`, the fence | ||
| 1260 | count for `ALL`, kept as the API's unsigned `UINT`) and the hit that reaches zero sets the event, so no thread is | ||
| 1261 | added; later hits stay at zero (`d3d12_fence_waiter_test` checks counts past `INT_MAX`). Values already reached are | ||
| 1262 | counted before the call returns; zero fences set the event at once. Other flags, a null array with a non-zero | ||
| 1263 | count, or a fence from elsewhere are `E_INVALIDARG`. A fence released while an event waits on it drops the wait | ||
| 1264 | and the event is never set. | ||
| 1181 | - The swapchain owns acquire/present semaphores and N frames in flight. A present waits for the frame's | 1265 | - The swapchain owns acquire/present semaphores and N frames in flight. A present waits for the frame's |
| 1182 | render-finished semaphore; the next acquire waits for the image's present-complete semaphore. | 1266 | render-finished semaphore; the next acquire waits for the image's present-complete semaphore. |
| 1183 | - Queue types: a direct queue maps to a graphics+compute queue, a compute queue to a compute-only family if one | 1267 | - Queue types: a direct queue maps to a graphics+compute queue, a compute queue to a compute-only family if one |
| 1184 | exists, a copy queue to a transfer-only family. If the host exposes only one family, serialize and log; async | 1268 | exists, a copy queue to a transfer-only family. If the host exposes only one family, serialize and log; async |
| 1185 | compute is a performance feature, not a correctness one. | 1269 | compute is a performance feature, not a correctness one. |
| 1186 | - `GetTimestampFrequency`/`GetClockCalibration` use `VK_EXT_calibrated_timestamps` where available. | 1270 | - `GetTimestampFrequency`/`GetClockCalibration` use `VK_EXT_calibrated_timestamps` where available. |
| 1271 | `GetClockCalibration` (implemented) returns the GPU stamp in device ticks (`1e9 / timestampPeriod` per second, | ||
| 1272 | the units of `GetTimestampFrequency`) and the CPU stamp in `QueryPerformanceCounter` units. When the device has | ||
| 1273 | `VK_KHR_calibrated_timestamps` or `VK_EXT_calibrated_timestamps` enabled (`VulkanDeviceInfo::calibrated_timestamps`; | ||
| 1274 | the standalone device enables whichever the GPU has) and offers the `DEVICE` and `QUERY_PERFORMANCE_COUNTER` | ||
| 1275 | domains, it is one `vkGetCalibratedTimestampsKHR` call. Otherwise the queue waits until idle, submits a | ||
| 1276 | `vkCmdWriteTimestamp` and waits for it, and answers with the midpoint of the `QueryPerformanceCounter` reads | ||
| 1277 | around that submission. This stalls the queue, which is acceptable for a call made once per profiling capture. A | ||
| 1278 | queue family with `timestampValidBits = 0` fails with `E_FAIL`. `d3d12_fence_timing_test` takes two calibrations | ||
| 1279 | 50 ms apart and compares the GPU and CPU intervals. On an RTX 4090 (driver 621.14) the gap is 2 us with calibrated | ||
| 1280 | timestamps, 20 us with the fallback, and 0.4 ms with the fallback under the validation layer. The test fails | ||
| 1281 | above 2 ms. | ||
| 1187 | 1282 | ||
| 1188 | ### 4.5 Swapchain and present | 1283 | ### 4.5 Swapchain and present |
| 1189 | 1284 | ||
| @@ -1330,7 +1425,14 @@ Not implemented yet: | |||
| 1330 | `vkCmdClearDepthStencilImage` ignore conditional rendering. The standalone device enables the extension and its | 1425 | `vkCmdClearDepthStencilImage` ignore conditional rendering. The standalone device enables the extension and its |
| 1331 | `conditionalRendering` feature when the GPU has them, and then creates buffers with | 1426 | `conditionalRendering` feature when the GPU has them, and then creates buffers with |
| 1332 | `VK_BUFFER_USAGE_CONDITIONAL_RENDERING_BIT_EXT`; without it a predicated list is rejected (`unsupported`). | 1427 | `VK_BUFFER_USAGE_CONDITIONAL_RENDERING_BIT_EXT`; without it a predicated list is rejected (`unsupported`). |
| 1333 | Checked by part E of `vk_command_replay_test` on an NVIDIA GeForce RTX 3070. | 1428 | `D3D12_RESOURCE_STATE_PREDICATION` is the same bit as `INDIRECT_ARGUMENT` (and `SYNC_PREDICATION` / |
| 1429 | `ACCESS_PREDICATION` the same as `EXECUTE_INDIRECT` / `INDIRECT_ARGUMENT`), so with the extension enabled | ||
| 1430 | barriers into and out of that state also cover `VK_ACCESS_CONDITIONAL_RENDERING_READ_BIT_EXT` at | ||
| 1431 | `VK_PIPELINE_STAGE_CONDITIONAL_RENDERING_BIT_EXT`, where the predicate is read: without it a `ResolveQueryData` | ||
| 1432 | into the predicate had no dependency on the read (`vulkan_access`, `vulkan_barrier_scope`). | ||
| 1433 | Checked by part E of `vk_command_replay_test` on an NVIDIA GeForce RTX 3070, and end to end by | ||
| 1434 | `d3d12_vulkan_device_test` (an occlusion query resolved into a predicate, through legacy and enhanced barriers) | ||
| 1435 | on an NVIDIA GeForce RTX 5070. | ||
| 1334 | Open: | 1436 | Open: |
| 1335 | - Copies and resolves. D3D12 predicates `CopyBufferRegion`, `CopyTextureRegion`, `CopyResource` and | 1437 | - Copies and resolves. D3D12 predicates `CopyBufferRegion`, `CopyTextureRegion`, `CopyResource` and |
| 1336 | `ResolveSubresource`; Vulkan's conditional rendering does not cover transfer commands, so they run | 1438 | `ResolveSubresource`; Vulkan's conditional rendering does not cover transfer commands, so they run |
| @@ -1682,7 +1784,7 @@ Xodus is LGPL-2.1 and is cited only for its coverage number, not as a code sourc | |||
| 1682 | | # | Question | How to resolve | | 1784 | | # | Question | How to resolve | |
| 1683 | |---|---|---| | 1785 | |---|---|---| |
| 1684 | | 1 | The device entry point is now named `D3D12XboxCreateDevice(adapter, params, riid, out)`. What do its 24-word params and flag bits mean? | Public documentation and the executable's call sites. Log the words and accept any flag bits; do not treat a wrong params layout as fatal until the fields are understood. | | 1786 | | 1 | The device entry point is now named `D3D12XboxCreateDevice(adapter, params, riid, out)`. What do its 24-word params and flag bits mean? | Public documentation and the executable's call sites. Log the words and accept any flag bits; do not treat a wrong params layout as fatal until the fields are understood. | |
| 1685 | | 2 | Which Xbox device/heap/queue/command-list slots differ? Prior art measured device slots 62 and 76 and descriptor-heap slots 9/10; slot 14 is the public `CreateDescriptorHeap`, with only the returned heap's start-handle return wrapped. Presentation, command-list, queue and fence slots remain unknown. | Trace every `QueryInterface` and every method slot with per-slot hit counters. A wrong slot shows as an immediate crash or wrong argument; compare against the SDK vtable. | | 1787 | | 2 | Which Xbox device/heap/queue/command-list slots differ? Prior art measured device slots 62 and 76 and descriptor-heap slots 9/10; slot 14 is the public `CreateDescriptorHeap`, with only the returned heap's start-handle return wrapped. **Partly measured** with the FSR DLL ([d3d12_command_objects.md §3.5a](d3d12_command_objects.md)): device slots 14, 15, 16, 18, 19, 27, 38, 62 and 76 at their expected shapes (24 in the code, not called), slot 67 a console-only pipeline call; command-list slots 14, 15, 25 and 26 at their PC positions, then shifted (+4 from `SetDescriptorHeaps` at 32, +2 at `ExecuteIndirect` at 61), with console-only methods at 85 and 141. Presentation, queue and fence slots remain unknown. | Trace every `QueryInterface` and every method slot with per-slot hit counters. A wrong slot shows as an immediate crash or wrong argument; compare against the SDK vtable. | |
| 1686 | | 3 | How does the console map a root signature to `s0..s31` (order, per-stage visibility, spills above 32 dwords, static samplers, direct-heap base)? | Dump the game's root-signature blobs with the host deserializer; mask the `0x03000000` flag byte on a copy first; match against the per-shader user-SGPR read sets. If a signature exceeds 32 dwords, reverse the spill pointer from the shader. | | 1788 | | 3 | How does the console map a root signature to `s0..s31` (order, per-stage visibility, spills above 32 dwords, static samplers, direct-heap base)? | Dump the game's root-signature blobs with the host deserializer; mask the `0x03000000` flag byte on a copy first; match against the per-shader user-SGPR read sets. If a signature exceeds 32 dwords, reverse the spill pointer from the shader. | |
| 1687 | | 4 | Are Xbox descriptor bytes GFX10 T#/S#, and what are the heap increments? Does the game use `Create*View` or build descriptors itself? | Dump a shader-visible heap after the first `CreateShaderResourceView` and after the first draw; compare the bytes the shader loads with the T# parser. The start-handle return ABI is known (RAX); the increment values still need measuring. | | 1789 | | 4 | Are Xbox descriptor bytes GFX10 T#/S#, and what are the heap increments? Does the game use `Create*View` or build descriptors itself? | Dump a shader-visible heap after the first `CreateShaderResourceView` and after the first draw; compare the bytes the shader loads with the T# parser. The start-handle return ABI is known (RAX); the increment values still need measuring. | |
| 1688 | | 5 | What is the buffer/descriptor/code VA range, and what arena capacity is needed? | Log every `GetGPUVirtualAddress` and every descriptor base; track the high-water mark. Choose a capacity; grow at a frame boundary if needed. | | 1790 | | 5 | What is the buffer/descriptor/code VA range, and what arena capacity is needed? | Log every `GetGPUVirtualAddress` and every descriptor base; track the high-water mark. Choose a capacity; grow at a frame boundary if needed. | |
| @@ -1871,10 +1973,50 @@ on a PC device behind the Xbox-ABI proxy). Measured: | |||
| 1871 | `ffxCreateContextDescUpscaleVersion` in the chain; 4.1.2 is rejected as invalid, 4.1.1 and 4.0.0 are accepted. | 1973 | `ffxCreateContextDescUpscaleVersion` in the chain; 4.1.2 is rejected as invalid, 4.1.1 and 4.0.0 are accepted. |
| 1872 | - With all of that, `ffxCreateContext` returns `FFX_API_RETURN_ERROR` with no message, no XMem allocation and no | 1974 | - With all of that, `ffxCreateContext` returns `FFX_API_RETURN_ERROR` with no message, no XMem allocation and no |
| 1873 | call on the device proxy, for the PC DX12 backend descriptor (`0x2`), for the same `{header, device}` layout | 1975 | call on the device proxy, for the PC DX12 backend descriptor (`0x2`), for the same `{header, device}` layout |
| 1874 | under the Xbox backend id (`0x02000000`, `0x02000001`, `0x02000002`), and with no backend descriptor at all. So | 1976 | under `0x02000000`, `0x02000001` and `0x02000002`, and with no backend descriptor at all. |
| 1875 | the build does not recognise the PC backend descriptor, and the Xbox one (`FFX_API_BACKEND_ID_XBOX` is declared | 1977 | - **The Xbox backend descriptor, measured from the DLL** (Ghidra 12.2 through REA; RVAs, image base `0x180000000`): |
| 1876 | in the public `ffx_api.h`, its descriptors are not) is unknown. Hypothesis: it is the GDK's Xbox D3D12 backend | 1978 | - `ffxCreateContext` (`0x11d0`) picks its one provider (`ffxProvider_FSR4_Int8` by RTTI) by finding a device in |
| 1877 | descriptor; the executable's `ffxCreateContext` call site would show its type and layout. | 1979 | the chain: type 4 (`GET_VERSIONS`) at `+0x18`, types `0x10009` and **`0x01000002`** at `+0x10`. |
| 1980 | - The provider's create (`0xc9b0`) wants `CreateContextDescUpscale` (`0x10000`) first, checks the version | ||
| 1981 | descriptor (`0x1000b`, 4.0.0 to 4.1.1), then walks `pNext` for **type `0x01000002`: `{header, device}`, the device | ||
| 1982 | at `+0x10`**, the same layout as the PC DX12 descriptor. Two of them, or none, is `FFX_API_RETURN_ERROR` | ||
| 1983 | without a message: that is what the ids above got. An optional type `0x01000003` sets function pointers: when the | ||
| 1984 | one at `+0x20` is set (with `+0x28`), the backend calls it instead of `CreateHeap` (device slot 28, `0x7390`); what | ||
| 1985 | its other fields do is open. | ||
| 1986 | - The HRESULT checks at the calls seen here (`0x33d4`, `0x65b3`, `0x74a8`) go through one helper (`0x1c60`): | ||
| 1987 | `FormatMessageW` of the code, then `throw 1`. | ||
| 1988 | - **Run with that descriptor** (`fsr_dispatch_test`, PC device on an RTX 2000 Ada, driver 597.06, behind the | ||
| 1989 | Xbox-ABI proxy): the DLL creates its backend through the proxy. Device slots called: 14 `CreateDescriptorHeap` (5), | ||
| 1990 | 15 `GetDescriptorHandleIncrementSize`, 18 `CreateShaderResourceView`, 19 `CreateUnorderedAccessView` and **76** (4), | ||
| 1991 | plus heap slot **9** `GetCPUDescriptorHandleForHeapStart` (Xbox RAX form). No earlier test in this repository | ||
| 1992 | reached slot 76 or heap slot 9 with a real client; their measured shapes hold. Slot 76 is called with the 7 | ||
| 1993 | arguments of `CreateCommittedResource` | ||
| 1994 | (heap properties, heap flags, resource desc, state, clear value, IID, out; call at `0x33cc`), the desc being the | ||
| 1995 | 56-byte `D3D12_RESOURCE_DESC` with layout `0x101` and the word 3 at `+0x34`. | ||
| 1996 | - On that GPU it stops at its 4th slot-76 texture: 1920x1080 `DXGI_FORMAT_R9G9B9E5_SHAREDEXP` with | ||
| 1997 | `ALLOW_UNORDERED_ACCESS`, which the NVIDIA driver refuses (`E_INVALIDARG`); WARP creates it. The console build | ||
| 1998 | creates it, so the console takes that format as a UAV. On the same GPU Vulkan has no `STORAGE_IMAGE` support for | ||
| 1999 | `VK_FORMAT_E5B9G9R9_UFLOAT_PACK32` either (vulkaninfo, driver 597.06), so the layer needs an emulation (32-bit | ||
| 2000 | storage plus a pack/unpack) where a GPU lacks it. | ||
| 2001 | - With that one texture created as `R32_UINT` instead (the test's PC stand-in, `standin_slot76`), or as is on | ||
| 2002 | WARP, `ffxCreateContext` and `ffxDestroyContext` both return OK. Device slots called: 14 (5), 15 (26), 18 (10), | ||
| 2003 | 19 (16), **27 | ||
| 2004 | `CreateCommittedResource` (4)**, **38 `GetCopyableFootprints` (4)**, 76 (10); heap slot 9 (26). So the console | ||
| 2005 | device also serves the PC `CreateCommittedResource` at slot 27, and slots 14, 15, 18, 19, 27 and 38 keep their PC | ||
| 2006 | positions for this client. No compute pipeline or root signature is created at context creation. | ||
| 2007 | - On that context, one `ffxDispatch` recorded into a logging command list measures the **console command list**: | ||
| 2008 | slots 14, 15, 25 and 26 are at their PC positions, then `SetDescriptorHeaps` is at 32 (PC 28), the compute root | ||
| 2009 | setters four slots later (33, 35, 41; two of them inferred from their shapes), `ExecuteIndirect` two slots later | ||
| 2010 | (61), and there are console-only methods at 85 and 141. The list object also carries a write cursor and limits | ||
| 2011 | (`+0x18`, `+0x28`, `+0x30`) the DLL writes commands through while there is room. Table and evidence: | ||
| 2012 | [d3d12_command_objects.md §3.5a](d3d12_command_objects.md). | ||
| 2013 | Device slot 67 is a console-only compute-pipeline call (a code blob in its desc), not the PC method at that | ||
| 2014 | index; the proxy now refuses it. The dispatch stops where the PC runtime refuses the DLL's compute code at slot | ||
| 2015 | 62: the DLL's shaders carry an `ACCC` part instead of DXIL. | ||
| 2016 | - Its `throw 1` reaches the caller: `_CxxThrowException` finds no image base for a manually mapped image, so the | ||
| 2017 | DLL's own handlers cannot catch it (the loader gap `tiny_game`'s `LEONIDA_RUN_EH` check also shows). | ||
| 2018 | - `xmem.dll!XMemGetWorkingSetStatistics` takes two arguments, `(0x20000001, stats*)`, at all seven call sites; | ||
| 2019 | the one-argument shim wrote through the constant. Fixed in `runtime/shims/xmem.cpp`. | ||
| 1878 | 2020 | ||
| 1879 | ### A.4 Other DLLs and the executable | 2021 | ### A.4 Other DLLs and the executable |
| 1880 | 2022 | ||
diff --git a/docs/design.md b/docs/design.md index fbab3a5ea..04f81f1ea 100644 --- a/docs/design.md +++ b/docs/design.md | |||
| @@ -149,7 +149,7 @@ Full-scan indexes are also saved to `%LOCALAPPDATA%\RpfPreview\Indexes`, so the | |||
| 149 | `adder` = 0xB779A091). On day one, rerun with `--extra <exe>` so PSO field and type names resolve. Without the exe | 149 | `adder` = 0xB779A091). On day one, rerun with `--extra <exe>` so PSO field and type names resolve. Without the exe |
| 150 | only about 1% do. | 150 | only about 1% do. |
| 151 | - Runtime shims: all of `xmem.dll` is shimmed with the measured argument shapes (`XMemAlloc`, `XMemFree`, | 151 | - Runtime shims: all of `xmem.dll` is shimmed with the measured argument shapes (`XMemAlloc`, `XMemFree`, |
| 152 | `XMemVirtualQuery(process, address, out64)`, `XMemGetWorkingSetStatistics(out)`). The `d3d12_xs` root-signature | 152 | `XMemVirtualQuery(process, address, out64)`, `XMemGetWorkingSetStatistics(kind, out)`, with `kind` 0x20000001 at all seven FSR call sites). The `d3d12_xs` root-signature |
| 153 | serializer forwards to the PC `d3d12.dll` after clearing the Xbox flag byte; the deserializer forwards unchanged. | 153 | serializer forwards to the PC `d3d12.dll` after clearing the Xbox flag byte; the deserializer forwards unchanged. |
| 154 | `D3D12XboxCreateDevice` returns an Xbox-ABI proxy over the PC device: every PC vtable slot is forwarded with | 154 | `D3D12XboxCreateDevice` returns an Xbox-ABI proxy over the PC device: every PC vtable slot is forwarded with |
| 155 | `this` adjusted, Xbox slot 62 is `CreateComputePipelineState`, and Xbox slot 76 maps resource creation to | 155 | `this` adjusted, Xbox slot 62 is `CreateComputePipelineState`, and Xbox slot 76 maps resource creation to |
| @@ -244,6 +244,7 @@ How the generated SPIR-V expects the runtime to work: | |||
| 244 | | `s_absdiff_i32`, `s_mul_hi_i32` | `s_absdiff_i32`: D = \|S0 − S1\| with the 32-bit difference wrapped first (0x7FFFFFFF − 0x80000000 → 1; a difference of −2³¹ stays 0x80000000), SCC = D ≠ 0. `s_mul_hi_i32`: high word of the signed 64-bit product, SCC kept. From the RDNA2 ISA pseudocode; checked on the CPU by `tests/semantic/test_salu_absdiff_mul_hi.py`, **not yet GPU-verified**. | | 244 | | `s_absdiff_i32`, `s_mul_hi_i32` | `s_absdiff_i32`: D = \|S0 − S1\| with the 32-bit difference wrapped first (0x7FFFFFFF − 0x80000000 → 1; a difference of −2³¹ stays 0x80000000), SCC = D ≠ 0. `s_mul_hi_i32`: high word of the signed 64-bit product, SCC kept. From the RDNA2 ISA pseudocode; checked on the CPU by `tests/semantic/test_salu_absdiff_mul_hi.py`, **not yet GPU-verified**. | |
| 245 | | SCC from scalar ALU | `s_and/or/xor/andn2/orn2/nand/nor/xnor_b32` and `s_lshl/lshr_b32` set SCC = result ≠ 0, `s_add/sub_i32` and `s_addk_i32` set it to signed overflow, `s_min_u32`/`s_max_u32` to S0 < S1 / S0 > S1, and `s_min_i32`/`s_max_i32` to the same compared signed: SCC is 1 when S0 is the one chosen, and a tie chooses S1 (RDNA2 ISA, S_MIN_I32: D = S0 < S1 ? S0 : S1, SCC = 1 if S0 is chosen). **Before this fix these ops left SCC unchanged**, so a following `s_cbranch_scc*` read a stale flag, and until 2026-11-21 `s_min_i32`/`s_max_i32` set SCC on a tie. 32-bit scalar shifts now mask the amount to 5 bits. GPU-checked with `runtime/test/shaders/ps_scc.asm` and `ps_scc_minmax.asm` (NVIDIA GeForce RTX 2060 SUPER, Linux, driver 620.70.06: 4096/4096 pixels exact, and all 4096 differ with the old translator). **On lane masks in a wave32 program** (a source is EXEC, VCC or a mask SGPR, or the result goes to EXEC) the 32-bit bitwise ops' result is the whole wave's mask, so SCC is a subgroup vote (`OpGroupNonUniformAny`), as for the `_b64` forms. Until 2026-11-22 each lane took its own bit: `s_and_b32 s0, vcc_lo, exec_lo; s_cbranch_scc0` skipped the block in lanes whose bit was 0, and a loop closed by `s_andn2_b32 exec_lo, ...; s_cbranch_scc1` let each lane leave early. Found and checked by `tools/cf_diff.py` (FUZZ-8, CPU differential against the ISA model); GPU test `runtime/test/shaders/ps_scc_mask32.asm` passes (s5 == 8 on 2,048 pixels, 192 of them with bit 0, and s5 == 7 on 2,048) on an NVIDIA RTX 4050 Laptop (Linux, driver 620.73.04, natively and under `LEONIDA_W64_EMULATE=1`) and an AMD Radeon 740M (RADV, Mesa 26.3.1), and on an RTX 2060 SUPER per #634. A 32-bit op on one half of a wave64 mask still takes the lane's bit (its SCC would be a vote of that half). | | 245 | | SCC from scalar ALU | `s_and/or/xor/andn2/orn2/nand/nor/xnor_b32` and `s_lshl/lshr_b32` set SCC = result ≠ 0, `s_add/sub_i32` and `s_addk_i32` set it to signed overflow, `s_min_u32`/`s_max_u32` to S0 < S1 / S0 > S1, and `s_min_i32`/`s_max_i32` to the same compared signed: SCC is 1 when S0 is the one chosen, and a tie chooses S1 (RDNA2 ISA, S_MIN_I32: D = S0 < S1 ? S0 : S1, SCC = 1 if S0 is chosen). **Before this fix these ops left SCC unchanged**, so a following `s_cbranch_scc*` read a stale flag, and until 2026-11-21 `s_min_i32`/`s_max_i32` set SCC on a tie. 32-bit scalar shifts now mask the amount to 5 bits. GPU-checked with `runtime/test/shaders/ps_scc.asm` and `ps_scc_minmax.asm` (NVIDIA GeForce RTX 2060 SUPER, Linux, driver 620.70.06: 4096/4096 pixels exact, and all 4096 differ with the old translator). **On lane masks in a wave32 program** (a source is EXEC, VCC or a mask SGPR, or the result goes to EXEC) the 32-bit bitwise ops' result is the whole wave's mask, so SCC is a subgroup vote (`OpGroupNonUniformAny`), as for the `_b64` forms. Until 2026-11-22 each lane took its own bit: `s_and_b32 s0, vcc_lo, exec_lo; s_cbranch_scc0` skipped the block in lanes whose bit was 0, and a loop closed by `s_andn2_b32 exec_lo, ...; s_cbranch_scc1` let each lane leave early. Found and checked by `tools/cf_diff.py` (FUZZ-8, CPU differential against the ISA model); GPU test `runtime/test/shaders/ps_scc_mask32.asm` passes (s5 == 8 on 2,048 pixels, 192 of them with bit 0, and s5 == 7 on 2,048) on an NVIDIA RTX 4050 Laptop (Linux, driver 620.73.04, natively and under `LEONIDA_W64_EMULATE=1`) and an AMD Radeon 740M (RADV, Mesa 26.3.1), and on an RTX 2060 SUPER per #634. A 32-bit op on one half of a wave64 mask still takes the lane's bit (its SCC would be a vote of that half). | |
| 246 | | Far branches | `s_getpc_b64; s_add_u32 K; s_addc_u32 0/−1; s_setpc_b64` on the same pair is a branch beyond `s_branch`'s ±32K-dword range. It's folded into one branch to (address after `s_getpc`) + K before CFG construction. | | 246 | | Far branches | `s_getpc_b64; s_add_u32 K; s_addc_u32 0/−1; s_setpc_b64` on the same pair is a branch beyond `s_branch`'s ±32K-dword range. It's folded into one branch to (address after `s_getpc`) + K before CFG construction. | |
| 247 | | No-op SOPP/SMEM (`s_icache_inv`, `s_ttracedata`, `s_ttracedata_imm`, `s_code_end`, `s_version`) | Instruction-cache invalidate, thread-trace data, end-of-code padding and the ISA version marker have no register, memory, SCC, VCC or EXEC effect, so they are in `NOOPS` with `s_nop` / `v_nop` / `v_pipeflush`. The data-cache invalidations (`buffer_gl0_inv`, `buffer_gl1_inv`, `s_dcache_inv`, `s_gl1_inv`) concern coherence between waves and stay `Unsupported`. Source: RDNA2 ISA SOPP/SOPK/SMEM. CPU-checked by `tests/semantic/test_sopp_noops.py` (values, SCC and VCC survive; the data-cache invalidations are still rejected). | | ||
| 247 | | Buffer format stores | `buffer_store_format_*` and `_d16_*` encode every format the loads decode (the same FORMATS table: f32/u32, f16, unorm/snorm 8/16/10-10-10-2, uint 8/16). 1–2-byte elements are merged into their dword with atomic and/or so neighbours are kept. The atomics use element 0 of the array at the aligned dword address, which also compiles on MoltenVK 1.4.0 (checked with `cs_store` on an Apple M3 Max and Mesa llvmpipe). d16 data is unpacked first (f16 → float for float kinds, 16-bit integers for integer kinds). Before this, only four f32 formats, rgba16f and rgba8 unorm were stored, and everything else silently stored nothing. GPU-checked with `runtime/test/shaders/cs_store.asm` (rgba8 unorm, R10G10B10A2 (`2_10_10_10`), two r16f halves of one dword, d16 rgba16f: exact, neighbours untouched). `buffer_load_format_d16_*` packs pairs the same way. | | 248 | | Buffer format stores | `buffer_store_format_*` and `_d16_*` encode every format the loads decode (the same FORMATS table: f32/u32, f16, unorm/snorm 8/16/10-10-10-2, uint 8/16). 1–2-byte elements are merged into their dword with atomic and/or so neighbours are kept. The atomics use element 0 of the array at the aligned dword address, which also compiles on MoltenVK 1.4.0 (checked with `cs_store` on an Apple M3 Max and Mesa llvmpipe). d16 data is unpacked first (f16 → float for float kinds, 16-bit integers for integer kinds). Before this, only four f32 formats, rgba16f and rgba8 unorm were stored, and everything else silently stored nothing. GPU-checked with `runtime/test/shaders/cs_store.asm` (rgba8 unorm, R10G10B10A2 (`2_10_10_10`), two r16f halves of one dword, d16 rgba16f: exact, neighbours untouched). `buffer_load_format_d16_*` packs pairs the same way. | |
| 248 | | `s_lshl1..4_add_u32` | D = (S0 << N) + S1. SCC = the sum taken in 64 bits is ≥ 2³², so a bit shifted out of S0 sets it as well as a carry out of the add (RDNA ISA pseudocode: `tmp = (64'U(S0) << N) + 64'U(S1)`). Checked on the CPU by `tests/semantic/test_salu_lshl_add.py`, **not yet GPU-verified**. | | 249 | | `s_lshl1..4_add_u32` | D = (S0 << N) + S1. SCC = the sum taken in 64 bits is ≥ 2³², so a bit shifted out of S0 sets it as well as a carry out of the add (RDNA ISA pseudocode: `tmp = (64'U(S0) << N) + 64'U(S1)`). Checked on the CPU by `tests/semantic/test_salu_lshl_add.py`, **not yet GPU-verified**. | |
| 249 | | Other additions | `image_gather4_l(_o)`: no explicit-LOD gather in core Vulkan, so four `OpImageFetch` at mip round(LOD) in gather order. Each of the four texel coordinates goes through the S#'s own address mode, read from S# word0 (`CLAMP_X` = bits [2:0], `CLAMP_Y` = [5:3]; fields from Mesa `src/amd/registers/gfx10-rsrc.json`, values `SQ_TEX_*` in Mesa `gfx6.json`, matching RADV's `radv_tex_wrap` mapping of Vulkan address modes): 0 wrap (`c mod n`), 1 mirror (`c mod 2n`, reflected), 2 clamp to the last texel, 3 mirror-once (`-1-c` for negative `c`, then clamped), as in Vulkan's address-mode definitions. A literal S# (`s_mov_b32` earlier in the block) is decoded at translation time; otherwise the mode is read from the SGPR at run time. A literal S# with a border mode (4-7: half-border, border colour) or `FORCE_UNNORMALIZED` is `Unsupported`; a run-time S# can't be judged, so modes 4-7 act as clamp-to-edge there and `FORCE_UNNORMALIZED` (word0 bit 15) is not applied (coordinates are still scaled by the image size). Those two are the remaining approximations; the unnormalized rules (texel-unit coordinates, mip 0) weren't confirmed on hardware, so they were not guessed. GPU-checked with `runtime/test/shaders/ps_gather_wrap.asm` (`vk_texture_test`; expected values derived by hand in its header; six border cases, three literal and three run-time S#) on AMD (Radeon 880M, wave64) and NVIDIA RTX 5070. `image_gather4_lz_o`: `OpImageGather … Offset`. `image_store` on 1D (bindings 17–19, `Image1D`) and with a16 coordinates. `ds_swizzle BITMASK_PERM` ("pippi" masks; GPU-checked). `v_add_f64`, `v_cvt_f32_f64` (`Float64`). `v_mul/mad_i32_i24`, `v_alignbyte_b32`, `v_xnor_b32`, `v_ffbh_i32`, `v_swap_b32`, `s_abs_i32`, `s_bfm_b32/b64`, 64-bit ordered and `v_cmpx` compares, 16-bit compares, 8/16-bit global loads, `neg(…)` constant operands (GPU-checked where listed in `runtime/test/shaders`). | | 250 | | Other additions | `image_gather4_l(_o)`: no explicit-LOD gather in core Vulkan, so four `OpImageFetch` at mip round(LOD) in gather order. Each of the four texel coordinates goes through the S#'s own address mode, read from S# word0 (`CLAMP_X` = bits [2:0], `CLAMP_Y` = [5:3]; fields from Mesa `src/amd/registers/gfx10-rsrc.json`, values `SQ_TEX_*` in Mesa `gfx6.json`, matching RADV's `radv_tex_wrap` mapping of Vulkan address modes): 0 wrap (`c mod n`), 1 mirror (`c mod 2n`, reflected), 2 clamp to the last texel, 3 mirror-once (`-1-c` for negative `c`, then clamped), as in Vulkan's address-mode definitions. A literal S# (`s_mov_b32` earlier in the block) is decoded at translation time; otherwise the mode is read from the SGPR at run time. A literal S# with a border mode (4-7: half-border, border colour) or `FORCE_UNNORMALIZED` is `Unsupported`; a run-time S# can't be judged, so modes 4-7 act as clamp-to-edge there and `FORCE_UNNORMALIZED` (word0 bit 15) is not applied (coordinates are still scaled by the image size). Those two are the remaining approximations; the unnormalized rules (texel-unit coordinates, mip 0) weren't confirmed on hardware, so they were not guessed. GPU-checked with `runtime/test/shaders/ps_gather_wrap.asm` (`vk_texture_test`; expected values derived by hand in its header; six border cases, three literal and three run-time S#) on AMD (Radeon 880M, wave64) and NVIDIA RTX 5070. `image_gather4_lz_o`: `OpImageGather … Offset`. `image_store` on 1D (bindings 17–19, `Image1D`) and with a16 coordinates. `ds_swizzle BITMASK_PERM` ("pippi" masks; GPU-checked). `v_add_f64`, `v_cvt_f32_f64` (`Float64`). `v_mul/mad_i32_i24`, `v_alignbyte_b32`, `v_xnor_b32`, `v_ffbh_i32`, `v_swap_b32`, `s_abs_i32`, `s_bfm_b32/b64`, 64-bit ordered and `v_cmpx` compares, 16-bit compares, 8/16-bit global loads, `neg(…)` constant operands (GPU-checked where listed in `runtime/test/shaders`). | |
| @@ -260,22 +261,32 @@ How the generated SPIR-V expects the runtime to work: | |||
| 260 | | Multiply-add with a literal | `v_fmamk_f32`/`v_madmk_f32` are D = S0 × K + S1 and `v_fmaak_f32`/`v_madak_f32` are D = S0 × S1 + K, K being the 32-bit literal. LLVM prints them `vdst, src0, K, vsrc1` and `vdst, src0, vsrc1, K`, so in print order all four are a[1] × a[2] + a[3] (fused for fmamk/fmaak). **Until 2026-11-21 fmamk and madmk computed S0 × S1 + K.** Source: RDNA2 ISA (V_FMAMK_F32, V_MADMK_F32) and the operand fields of the llvm-mc encoding. Checked by `tests/semantic` and GPU-checked with `runtime/test/shaders/ps_fma_literal.asm` on an NVIDIA GeForce RTX 2060 SUPER (Linux, driver 620.70.06): 4096/4096 pixels exact, and 4096/4096 differ with the old translator. | | 261 | | Multiply-add with a literal | `v_fmamk_f32`/`v_madmk_f32` are D = S0 × K + S1 and `v_fmaak_f32`/`v_madak_f32` are D = S0 × S1 + K, K being the 32-bit literal. LLVM prints them `vdst, src0, K, vsrc1` and `vdst, src0, vsrc1, K`, so in print order all four are a[1] × a[2] + a[3] (fused for fmamk/fmaak). **Until 2026-11-21 fmamk and madmk computed S0 × S1 + K.** Source: RDNA2 ISA (V_FMAMK_F32, V_MADMK_F32) and the operand fields of the llvm-mc encoding. Checked by `tests/semantic` and GPU-checked with `runtime/test/shaders/ps_fma_literal.asm` on an NVIDIA GeForce RTX 2060 SUPER (Linux, driver 620.70.06): 4096/4096 pixels exact, and 4096/4096 differ with the old translator. | |
| 261 | | Multiply-add and output modifiers | `v_mac_f32` is the VOP2 form of `v_mad_f32`, **not** of `v_fma_f32`: the product is rounded before the add (`OpFMul` + `OpFAdd`, both `NoContraction`). It used to emit `Fma`, one ULP off on some inputs. Source: LLVM `SIInstrInfo.cpp` `getNewFMAInst` (`V_MAC_F32` -> `V_MAD_F32_e64`, `V_FMAC_F32` -> `V_FMA_F32_e64`). VOP3 `clamp` and `mul:2`/`mul:4`/`div:2` now apply to `v_cvt_f32_i32`/`u32`/`ubyte0..3`, `v_cvt_f32_f16` and `v_rcp_iflag_f32` (they were dropped). Source: LLVM `VOPProfileI2F` (`Ins64 = $src0, $clamp, $omod`) and the float-source profiles. Found by `tools/f32_fuzz.py` (FUZZ-3: an exact-arithmetic model against the translated SPIR-V; 0 mismatches over 10,000 seeded programs after the fix) and pinned by `runtime/test/shaders/ps_f32_mods.asm` (`tests/semantic/test_f32_valu.py`); **not yet GPU-verified**. Still open: on some inputs the ISA defines a result but the emitted SPIR-V is undefined: `v_rcp_f32(±0)` (`OpFDiv` by zero), `v_rsq_f32`/`v_log_f32` of ±0 or a negative, `v_sqrt_f32` of a negative, `v_cvt_pk_u8_f32(NaN)` (`FClamp`). | | 262 | | Multiply-add and output modifiers | `v_mac_f32` is the VOP2 form of `v_mad_f32`, **not** of `v_fma_f32`: the product is rounded before the add (`OpFMul` + `OpFAdd`, both `NoContraction`). It used to emit `Fma`, one ULP off on some inputs. Source: LLVM `SIInstrInfo.cpp` `getNewFMAInst` (`V_MAC_F32` -> `V_MAD_F32_e64`, `V_FMAC_F32` -> `V_FMA_F32_e64`). VOP3 `clamp` and `mul:2`/`mul:4`/`div:2` now apply to `v_cvt_f32_i32`/`u32`/`ubyte0..3`, `v_cvt_f32_f16` and `v_rcp_iflag_f32` (they were dropped). Source: LLVM `VOPProfileI2F` (`Ins64 = $src0, $clamp, $omod`) and the float-source profiles. Found by `tools/f32_fuzz.py` (FUZZ-3: an exact-arithmetic model against the translated SPIR-V; 0 mismatches over 10,000 seeded programs after the fix) and pinned by `runtime/test/shaders/ps_f32_mods.asm` (`tests/semantic/test_f32_valu.py`); **not yet GPU-verified**. Still open: on some inputs the ISA defines a result but the emitted SPIR-V is undefined: `v_rcp_f32(±0)` (`OpFDiv` by zero), `v_rsq_f32`/`v_log_f32` of ±0 or a negative, `v_sqrt_f32` of a negative, `v_cvt_pk_u8_f32(NaN)` (`FClamp`). | |
| 262 | | Wave64 handling | Wave size is detected per shader from the code (64-bit EXEC writes, `exec_hi`, `v_mbcnt_hi`, `*_saveexec_b64`/`*_wrexec_b64`, and 64-bit lane-mask SOP ops `s_bcnt[01]_i32_b64` / `s_ff[01]_i32_b64` / `s_wqm_b64` / `s_bfm_b64` even when the mask is an ordinary SGPR pair; mesh shaders are always wave64). Until 2026-11-21 a mask-only wave64 program with no EXEC markers was translated as wave32, so `s_bcnt1_i32_b64` counted one half (#210). GPU-checked with `runtime/test/shaders/cs_w64_mask_detect.asm` (48 set bits of `(lane & 5) != 0`) on NVIDIA GeForce RTX 5060 under `LEONIDA_W64_EMULATE=1`. The hardware lane is exact in compute and mesh shaders (LocalInvocationIndex mod 64 or 32) and is used by `v_mbcnt` and EXEC writes. In other stages it's the subgroup lane. Constant EXEC writes (`s_mov_b32 exec_lo/exec_hi, K`) set each lane from its own bit of K; before, any non-zero constant turned every lane on. A register written to `exec_hi` sets lanes 32–63 only. GPU-checked with `runtime/test/shaders/cs_exec64.asm`: lanes 16–47 enabled from two constants, exact on a 32-wide-subgroup GPU. Still approximate on 32-wide subgroups: cross-lane ops between the two halves of a wave64 (readlane/permlane/DPP/shuffles across lane 31/32, wave-wide reductions). The metadata index marks every wave64 shader so a runtime can request `requiredSubgroupSize = 64` where supported (AMD), which makes those exact too. | | 263 | | Wave64 handling | Wave size is detected per shader from the code (64-bit EXEC writes, `exec_hi`, `v_mbcnt_hi`, `*_saveexec_b64`/`*_wrexec_b64`, and 64-bit lane-mask SOP ops `s_bcnt[01]_i32_b64` / `s_ff[01]_i32_b64` / `s_wqm_b64` / `s_bfm_b64` even when the mask is an ordinary SGPR pair; mesh shaders are always wave64). Until 2026-11-21 a mask-only wave64 program with no EXEC markers was translated as wave32, so `s_bcnt1_i32_b64` counted one half (#210). GPU-checked with `runtime/test/shaders/cs_w64_mask_detect.asm` (48 set bits of `(lane & 5) != 0`) on NVIDIA GeForce RTX 5060 under `LEONIDA_W64_EMULATE=1`. The hardware lane is exact in compute and mesh shaders (LocalInvocationIndex mod 64 or 32) and is used by `v_mbcnt` and EXEC writes. In other stages it's the subgroup lane. Constant EXEC writes (`s_mov_b32 exec_lo/exec_hi, K`) set each lane from its own bit of K; before, any non-zero constant turned every lane on. A register written to `exec_hi` sets lanes 32–63 only. GPU-checked with `runtime/test/shaders/cs_exec64.asm`: lanes 16–47 enabled from two constants, exact on a 32-wide-subgroup GPU. Still approximate on 32-wide subgroups: cross-lane ops between the two halves of a wave64 (readlane/permlane/DPP/shuffles across lane 31/32, wave-wide reductions). The metadata index marks every wave64 shader so a runtime can request `requiredSubgroupSize = 64` where supported (AMD), which makes those exact too. | |
| 264 | | Lane select (`v_readlane_b32` / `v_writelane_b32`) | The lane is **S1[4:0] in wave32** and S1[5:0] in wave64, from an SGPR or a constant, and EXEC is ignored (RDNA 3 ISA guide pseudocode for both opcodes; RDNA 2 has the same encoding and gives no pseudocode). **Until #488 (SHADER-52) a wave32 shader masked with 63 as well**: a lane select of 32 or more wrote no lane, and a read shuffled from a lane past the end of a 32-wide subgroup, which SPIR-V leaves undefined (NVIDIA wraps it, so reads happened to come out right there). Found by the FUZZ-7 cross-lane fuzzer: 23 of 100 random wave32 programs, each minimized to `s_mov_b32 s28, K; v_writelane_b32 vD, x, s28` with K ≥ 32. GPU-checked with `runtime/test/shaders/cs_w32_lane_wrap.asm` (25 16 777 777) on NVIDIA GeForce RTX 5060 (#488) and RTX 4090 (subgroup 32, driver 621.14); `tests/test_translate.py` checks the masks in the SPIR-V, and `tests/semantic/test_wave32_lane_select.py` runs the shader across 32 lanes, where a mask of 63 is an out-of-range shuffle. | | ||
| 263 | | Wave64 emulation (`--wave64-emulate`) | Wave64 compute and mesh shaders exact on **any** subgroup size (32-wide NVIDIA, Intel, AMD in wave32 mode), with no subgroup operation at all. One invocation is still one lane. Everything a lane needs from the rest of its wave goes through a Workgroup buffer `%x_buf`: votes (`s_cbranch_vccz/vccnz/execz/execnz`, SCC of mask ops, `s_cmp` of masks), whole-mask words (`s_bcnt1`, `s_ff1`, `v_mbcnt`), `v_readlane`, `v_readfirstlane`, `ds_bpermute`, `ds_swizzle`, `v_permlane16/x16`. The program runs in rounds: in each round every wave that is neither done nor waiting at `s_barrier` runs one segment of its program (a basic block, cut at each cross-lane op), then the whole workgroup meets at one `OpControlBarrier` (Workgroup, AcquireRelease, workgroup + uniform + image memory) that sits in uniform control flow, because every invocation runs every round. A cross-lane op ends its segment after the lane has stored its value (per-lane data, double-buffered by round parity) or ORed its bit (two mask words per wave, three slots by round mod 3, each slot cleared two rounds after it was read); the code after it runs one round later, when all 64 lanes have written. SSA values live across a cut go through Function variables. `s_barrier` is a scheduler state: the wave stops running segments until every wave that isn't done is waiting, which is also how hardware counts finished waves. A memory access that conflicts with an earlier one in the same segment (read after write, write after read, write after write; LDS and buffer/image memory separately) starts a new round, so two halves of a wave in different subgroups access memory in instruction order, as the lanes of one hardware wave do; not ordered: scalar loads of memory the wave wrote, and sampling an image it wrote. The missing lanes of a partial last wave read as 0. Without the flag the output is unchanged, apart from two fixes that apply to every wave64 compute/mesh shader: `v_writelane_b32` selects the lane by the wave lane (on a 32-wide subgroup writes to lanes 32–63 were lost; `cs_w64x_writelane`), and `ds_bpermute_b32` (see the LDS row). Fewer rounds, same results: a whole-mask read (`s_bcnt1`, `v_mbcnt_lo/hi`, ...) of the value of the same register (or EXEC) that an earlier read in the block already exchanged reuses that exchange (the value's identity is the SSA id last stored to the register, forgotten at block start and at any label); and a block that ends in a voted branch (`s_cbranch_vccz/vccnz/execz/execnz`) runs its successor in the round that reads the vote, since that segment only reads the vote and picks the next block (an inner loop in the scheduler, flag `%x_chain`). Both rules are pinned by `cs_w64x_mask_reuse` (a mask register and EXEC rewritten between reads), `cs_w64x_mask_reuse2` (EXEC read twice, a read after a buffer store, one half of a mask pair rewritten while the other is kept, a voted branch whose successor starts with a load of the other half's earlier store) and `cs_w64x_chain_barrier` (a voted branch whose successor starts with `s_barrier`, two waves): expected values from the ISA, first run on the AMD 880M with its native 64-wide subgroup, then emulated on both GPUs; `tests/test_translate.py` counts the exchanges in the SPIR-V (one per value, a new one after a rewrite of the register or EXEC), and the translator refuses (`Unsupported`) a voted branch whose segment was not started by the vote's own round. `scripts/bench_wave64.py` times `cs_bench_mix` native and emulated and checks the emulated output bytes against the native AMD run. Cost: one workgroup barrier per segment, and `%x_buf` = (2·L + 6·W + 7) dwords for L invocations in W waves, counted in `lds_bytes`. GPU-checked on NVIDIA GeForce RTX 5070 Laptop (subgroup 32, driver 617.42) and AMD Radeon 880M (subgroup 64, AMD driver 26.11.2 LLPC): `check.py` 38/39 (the mesh test runs in the other script) and `scripts/run_gpu_tests.py` 40/40 on both with `LEONIDA_W64_EMULATE=1`, including every wave64 test (`cs_wavemask`, `cs_wave64_ballot`, `cs_wm_*`) and the cross-half suite `cs_w64x_*` / `ms_w64x_ballot`: readlane and writelane at lanes ≥ 32, readfirstlane with only upper lanes active, branches voted by one lane of either half, ballot + `v_mbcnt_lo/hi` compaction over 64 lanes (also in a mesh shader, 4096/4096 pixels), a 128-thread workgroup whose two waves take different branches, `s_barrier` between waves with different loop counts, LDS read-after-write and write-after-read across the halves without a barrier, a load, ballot and load in one block, and a partial wave (group 40). Without the flag the same RTX 5070 passes 19/37 (the wave64 tests skip there). Not covered: VS/PS/GS (no workgroup memory or barrier there). | | 265 | | Wave64 emulation (`--wave64-emulate`) | Wave64 compute and mesh shaders exact on **any** subgroup size (32-wide NVIDIA, Intel, AMD in wave32 mode), with no subgroup operation at all. One invocation is still one lane. Everything a lane needs from the rest of its wave goes through a Workgroup buffer `%x_buf`: votes (`s_cbranch_vccz/vccnz/execz/execnz`, SCC of mask ops, `s_cmp` of masks), whole-mask words (`s_bcnt1`, `s_ff1`, `v_mbcnt`), `v_readlane`, `v_readfirstlane`, `ds_bpermute`, `ds_swizzle`, `v_permlane16/x16`. The program runs in rounds: in each round every wave that is neither done nor waiting at `s_barrier` runs one segment of its program (a basic block, cut at each cross-lane op), then the whole workgroup meets at one `OpControlBarrier` (Workgroup, AcquireRelease, workgroup + uniform + image memory) that sits in uniform control flow, because every invocation runs every round. A cross-lane op ends its segment after the lane has stored its value (per-lane data, double-buffered by round parity) or ORed its bit (two mask words per wave, three slots by round mod 3, each slot cleared two rounds after it was read); the code after it runs one round later, when all 64 lanes have written. SSA values live across a cut go through Function variables. `s_barrier` is a scheduler state: the wave stops running segments until every wave that isn't done is waiting, which is also how hardware counts finished waves. A memory access that conflicts with an earlier one in the same segment (read after write, write after read, write after write; LDS and buffer/image memory separately) starts a new round, so two halves of a wave in different subgroups access memory in instruction order, as the lanes of one hardware wave do; not ordered: scalar loads of memory the wave wrote, and sampling an image it wrote. The missing lanes of a partial last wave read as 0. Without the flag the output is unchanged, apart from two fixes that apply to every wave64 compute/mesh shader: `v_writelane_b32` selects the lane by the wave lane (on a 32-wide subgroup writes to lanes 32–63 were lost; `cs_w64x_writelane`), and `ds_bpermute_b32` (see the LDS row). Fewer rounds, same results: a whole-mask read (`s_bcnt1`, `v_mbcnt_lo/hi`, ...) of the value of the same register (or EXEC) that an earlier read in the block already exchanged reuses that exchange (the value's identity is the SSA id last stored to the register, forgotten at block start and at any label); and a block that ends in a voted branch (`s_cbranch_vccz/vccnz/execz/execnz`) runs its successor in the round that reads the vote, since that segment only reads the vote and picks the next block (an inner loop in the scheduler, flag `%x_chain`). Both rules are pinned by `cs_w64x_mask_reuse` (a mask register and EXEC rewritten between reads), `cs_w64x_mask_reuse2` (EXEC read twice, a read after a buffer store, one half of a mask pair rewritten while the other is kept, a voted branch whose successor starts with a load of the other half's earlier store) and `cs_w64x_chain_barrier` (a voted branch whose successor starts with `s_barrier`, two waves): expected values from the ISA, first run on the AMD 880M with its native 64-wide subgroup, then emulated on both GPUs; `tests/test_translate.py` counts the exchanges in the SPIR-V (one per value, a new one after a rewrite of the register or EXEC), and the translator refuses (`Unsupported`) a voted branch whose segment was not started by the vote's own round. `scripts/bench_wave64.py` times `cs_bench_mix` native and emulated and checks the emulated output bytes against the native AMD run. Cost: one workgroup barrier per segment, and `%x_buf` = (2·L + 6·W + 7) dwords for L invocations in W waves, counted in `lds_bytes`. GPU-checked on NVIDIA GeForce RTX 5070 Laptop (subgroup 32, driver 617.42) and AMD Radeon 880M (subgroup 64, AMD driver 26.11.2 LLPC): `check.py` 38/39 (the mesh test runs in the other script) and `scripts/run_gpu_tests.py` 40/40 on both with `LEONIDA_W64_EMULATE=1`, including every wave64 test (`cs_wavemask`, `cs_wave64_ballot`, `cs_wm_*`) and the cross-half suite `cs_w64x_*` / `ms_w64x_ballot`: readlane and writelane at lanes ≥ 32, readfirstlane with only upper lanes active, branches voted by one lane of either half, ballot + `v_mbcnt_lo/hi` compaction over 64 lanes (also in a mesh shader, 4096/4096 pixels), a 128-thread workgroup whose two waves take different branches, `s_barrier` between waves with different loop counts, LDS read-after-write and write-after-read across the halves without a barrier, a load, ballot and load in one block, and a partial wave (group 40). Without the flag the same RTX 5070 passes 19/37 (the wave64 tests skip there). Not covered: VS/PS/GS (no workgroup memory or barrier there). | |
| 264 | | 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, …), `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: 64-wide subgroups can only be requested for compute/mesh, so graphics wave64 stays emulated 2x32 until cross-half ops go through LDS; also true for compute/mesh translated with `--wave64-emulate`, which then carry `wave64_exchange: "workgroup"` and `subgroup_size: null`: any subgroup size is exact, request none), `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, and input/output locations. A runtime can create every pipeline at load time from it without parsing SPIR-V. | | 266 | | 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, …), `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: 64-wide subgroups can only be requested for compute/mesh, so graphics wave64 stays emulated 2x32 until cross-half ops go through LDS; also true for compute/mesh translated with `--wave64-emulate`, which then carry `wave64_exchange: "workgroup"` and `subgroup_size: null`: any subgroup size is exact, request none), `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, and input/output locations. A runtime can create every pipeline at load time from it without parsing SPIR-V. | |
| 265 | | 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. | | 267 | | 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. | |
| 266 | | Wave-uniform branches | VCC and EXEC are wave-wide registers, but one invocation holds only its own lane's bit. `s_cbranch_vccz/vccnz/execz/execnz` therefore reduce the condition across the subgroup (`OpGroupNonUniformAny`), so the whole wave takes the branch together, as on hardware. Before this, each lane decided alone. A lane could skip scalar instructions that the hardware wave executes (its SGPRs went stale for later code), and cross-lane ops or barriers inside the block saw a split wave. `v_cmp`/`v_cmp_class`/64-bit compares now write 0 for inactive lanes (hardware VOPC behaviour), so the reduction sees the true mask. GPU-checked with `runtime/test/shaders/ps_uniform_branch.asm`: lanes whose own VCC bit is 0 run the block's scalar add when their wave has any set bit. `s_cbranch_scc0/1` stay per lane; SCC is uniform as long as the SGPRs feeding it are. | | 268 | | Wave-uniform branches | VCC and EXEC are wave-wide registers, but one invocation holds only its own lane's bit. `s_cbranch_vccz/vccnz/execz/execnz` therefore reduce the condition across the subgroup (`OpGroupNonUniformAny`), so the whole wave takes the branch together, as on hardware. Before this, each lane decided alone. A lane could skip scalar instructions that the hardware wave executes (its SGPRs went stale for later code), and cross-lane ops or barriers inside the block saw a split wave. `v_cmp`/`v_cmp_class`/64-bit compares now write 0 for inactive lanes (hardware VOPC behaviour), so the reduction sees the true mask. GPU-checked with `runtime/test/shaders/ps_uniform_branch.asm`: lanes whose own VCC bit is 0 run the block's scalar add when their wave has any set bit. `s_cbranch_scc0/1` stay per lane; SCC is uniform as long as the SGPRs feeding it are. | |
| 267 | | Compute shaders | FSSM header word **0x138 = `COMPUTE_PGM_RSRC2`**: USER_SGPR [5:1], TGID_X/Y/Z_EN [9:7], TG_SIZE_EN [10], TIDIG_COMP_CNT [12:11], LDS_SIZE [23:15] in 512-byte units. Words **0x13C/0x140/0x144 = thread-group size**. This was checked against what all 2,689 CS read before writing: 2,281 match exactly, and the rest overshoot only through loop-carried registers in the straight-line check. 0x110, which looked similar, doesn't match. Layout: s0..user−1 = user data (push constants), then the enabled workgroup IDs (`WorkgroupId`), and v0/v1/v2 = thread ID x/y/z (`LocalInvocationId`, separate VGPRs on GFX10). Example: the 1,013 shaders with RSRC2 `0x998` have 12 user SGPRs, group ID x/y in s12/s13, and compute x = s12·32 + v0. Shaders with TG_SIZE_EN are rejected for now. GPU-checked with `runtime/test/shaders/cs_lds.asm` through `runtime/test/vk_compute_test.cpp`: 4 groups × 64 threads, LDS exchange between the two waves of a group behind `s_barrier`, store through a V# into the device-address heap, 0 mismatches. | | 269 | | Compute shaders | FSSM header word **0x138 = `COMPUTE_PGM_RSRC2`**: USER_SGPR [5:1], TGID_X/Y/Z_EN [9:7], TG_SIZE_EN [10], TIDIG_COMP_CNT [12:11], LDS_SIZE [23:15] in 512-byte units. Words **0x13C/0x140/0x144 = thread-group size**. This was checked against what all 2,689 CS read before writing: 2,281 match exactly, and the rest overshoot only through loop-carried registers in the straight-line check. 0x110, which looked similar, doesn't match. Layout: s0..user−1 = user data (push constants), then the enabled workgroup IDs (`WorkgroupId`), and v0/v1/v2 = thread ID x/y/z (`LocalInvocationId`, separate VGPRs on GFX10). Example: the 1,013 shaders with RSRC2 `0x998` have 12 user SGPRs, group ID x/y in s12/s13, and compute x = s12·32 + v0. Shaders with TG_SIZE_EN are rejected for now. GPU-checked with `runtime/test/shaders/cs_lds.asm` through `runtime/test/vk_compute_test.cpp`: 4 groups × 64 threads, LDS exchange between the two waves of a group behind `s_barrier`, store through a V# into the device-address heap, 0 mismatches. | |
| 268 | | Workgroup barriers | `s_barrier` (cs/ms) is one `OpControlBarrier` (workgroup scope, workgroup memory). On RDNA every `s_barrier` counts against the same workgroup barrier and a wave that has ended no longer counts, while Vulkan requires a barrier to be reached by every invocation in uniform control flow. Under `--wave64-emulate` the round loop keeps a single barrier at the top level, so this holds. **On the native path it is not proven:** the barrier stays where `s_barrier` is, and in the 1.0.2.1 corpus it sits inside a selection or loop construct in 43 of the 55 wave32 cs shaders with `s_barrier` (always native) and in every ms and most wave64 cs shaders when they run natively (AMD). Branches are scalar, so whole waves take the same path. No hang has been seen: `cs_barrier_divergent.asm` (two barrier sites in different branches), an early end of the other waves and a per-wave loop count all pass on NVIDIA RTX 4070 Ti (drivers 610.88 and 621.24) and RTX 5090 (Linux 595.99). SHADER-91 tracks this; a barrier-only round scheduler (the emulated loop without its cross-lane part) is the fix if a hang shows up. | | 270 | | Workgroup barriers | `s_barrier` (cs/ms) is one `OpControlBarrier` (workgroup scope, workgroup memory). On RDNA every `s_barrier` counts against the same workgroup barrier and a wave that has ended no longer counts, while Vulkan requires a barrier to be reached by every invocation in uniform control flow. Under `--wave64-emulate` the round loop keeps a single barrier at the top level, so this holds. **On the native path it is not proven:** the barrier stays where `s_barrier` is, and in the 1.0.2.1 corpus it sits inside a selection or loop construct in 43 of the 55 wave32 cs shaders with `s_barrier` (always native) and in every ms and most wave64 cs shaders when they run natively (AMD). Branches are scalar, so whole waves take the same path. No hang has been seen: `cs_barrier_divergent.asm` (two barrier sites in different branches), an early end of the other waves and a per-wave loop count all pass on NVIDIA RTX 4070 Ti (drivers 610.88 and 621.24) and RTX 5090 (Linux 595.99). SHADER-91 tracks this; a barrier-only round scheduler (the emulated loop without its cross-lane part) is the fix if a hang shows up. | |
| 271 | | LDS | A `Workgroup` uint array sized from LDS_SIZE, rounded up to a power of two that also covers every constant offset (15 of 486 shaders index past LDS_SIZE). Covers `ds_read/write_b32..b128`, `read2/write2` (+`st64`), `u16`/`i16`/`u8`/`i8` reads (also `ds_read_u16_d16`/`_d16_hi` and, since SHADER-85, `ds_read_u8_d16`/`_d16_hi` and `ds_read_i8_d16`/`_d16_hi`: the byte is zero- or sign-extended 8→16 into one half of the destination VGPR and the other half is kept, per the RDNA2 ISA DS opcode descriptions (opcodes 162–165) and as for the u16 d16 reads; GPU-checked with `cs_w32_lds_u8_d16.asm`, byte values 0x80/0xFF/0x7F with a non-zero `offset:`), `b16`/`b8` writes (atomic and/or, so neighbouring lanes don't race), the add/sub/min/max/and/or/xor atomics with and without return, `wrxchg`, `cmpst` (`OpAtomicCompareExchange` with DATA as comparator and DATA2 as value), and `ds_bpermute_b32` as a subgroup shuffle. `ds_permute_b32`, its forward (scatter) form, has no Vulkan equivalent: each source lane that is on in EXEC publishes `((vAddr + offset) >> 2) mod 32` and each destination lane scans the 32 sources of its half and keeps the last one that targets it (a shuffle of target and data per source lane; under `--wave64-emulate` two buffer rounds and a Function variable instead). Per the ISA pseudocode (`tmp[0..63] = 0`; `next if !EXEC[i]` on the source; `VGPR[VDST][i] = tmp[i]` only `if EXEC[i]`): a destination lane nobody targets gets 0, an off source sends nothing, an off destination keeps its VDST, and the half rule above applies as for `ds_bpermute_b32`. When several sources target one lane the ISA leaves the winner unpredictable ("the value from one of the writers"; its pseudocode says the highest-numbered); the translator takes the highest, and nothing may depend on it. Confirmed by the GPU tests `cs_w32_permute.asm` and, per half of a wave64, `cs_w64x_permute.asm` (SHADER-90: rotation, offset, unwritten lane = 0, off destination keeps its value, off source does not win) and `tests/semantic/test_ds_permute.py`. A source lane that is off in EXEC reads 0 and an off destination lane keeps its value (RDNA ISA §10.4.4), in wave32 as in wave64. In wave64 the permute also runs as two wave32s: each half reads lanes of its own half. Until 2026-11-21 lanes 32–63 of a 64-wide subgroup read the low half and inactive sources kept their value (`cs_w64x_bpermute`, AMD Radeon 880M); the wave32 path shuffled the raw value until the same day (`cs_bpermute32`: wave32, EXEC without lanes 8–15, so lane 6 reads 0; GPU-checked on RTX 5070 and Radeon 880M). A source lane that doesn't exist, in the missing lanes of a partial wave, also reads 0: the shuffle result is kept only where a ballot of the running invocations has the source lane, since SPIR-V leaves a shuffle from an invocation that isn't running undefined. Before this, RADV returned stale register values that changed between runs (`cs_w64x_partial`, a 40-thread group, native wave64 on AMD RX 6700 XT, RADV Mesa 26.3.1). Writes and atomics run only in active lanes. Indices wrap at the array size, where hardware would return 0 for out-of-range reads. `s_barrier` = `OpControlBarrier` Workgroup/Workgroup, AcquireRelease + WorkgroupMemory. | | ||
| 272 | | `ds_cmpst_b32` | The non-returning compare-and-store: `M = (M == data0) ? data1 : M`, the same `OpAtomicCompareExchange` as `ds_cmpst_rtn_b32` with the old value dropped (operands vaddr, data0, data1). Source: RDNA2 ISA DS_CMPST_B32. CPU-checked by `tests/semantic/test_lds_atomics_values.py`. **Not GPU-verified.** | | ||
| 269 | | LDS | A `Workgroup` uint array sized from LDS_SIZE, rounded up to a power of two that also covers every constant offset (15 of 486 shaders index past LDS_SIZE). Covers `ds_read/write_b32..b128`, `read2/write2` (+`st64`), `u16`/`i16`/`u8`/`i8` reads (also `ds_read_u16_d16`/`_d16_hi` and, since SHADER-85, `ds_read_u8_d16`/`_d16_hi` and `ds_read_i8_d16`/`_d16_hi`: the byte is zero- or sign-extended 8→16 into one half of the destination VGPR and the other half is kept, per the RDNA2 ISA DS opcode descriptions (opcodes 162–165) and as for the u16 d16 reads; GPU-checked with `cs_w32_lds_u8_d16.asm`, byte values 0x80/0xFF/0x7F with a non-zero `offset:`), `b16`/`b8` writes (atomic and/or, so neighbouring lanes don't race), the add/sub/min/max/and/or/xor atomics with and without return, `wrxchg`, `cmpst` (`OpAtomicCompareExchange` with DATA as comparator and DATA2 as value), and `ds_bpermute_b32` as a subgroup shuffle. `ds_permute_b32`, its forward (scatter) form, has no Vulkan equivalent: each source lane that is on in EXEC publishes `((vAddr + offset) >> 2) mod 32` and each destination lane scans the 32 sources of its half and keeps the last one that targets it (a shuffle of target and data per source lane; under `--wave64-emulate` two buffer rounds and a Function variable instead). Per the ISA pseudocode (`tmp[0..63] = 0`; `next if !EXEC[i]` on the source; `VGPR[VDST][i] = tmp[i]` only `if EXEC[i]`): a destination lane nobody targets gets 0, an off source sends nothing, an off destination keeps its VDST, and the half rule above applies as for `ds_bpermute_b32`. When several sources target one lane the ISA leaves the winner unpredictable ("the value from one of the writers"; its pseudocode says the highest-numbered); the translator takes the highest, and nothing may depend on it. Confirmed by the GPU tests `cs_w32_permute.asm` and, per half of a wave64, `cs_w64x_permute.asm` (SHADER-90: rotation, offset, unwritten lane = 0, off destination keeps its value, off source does not win) and `tests/semantic/test_ds_permute.py`. In wave64 the permute runs as two wave32s (RDNA ISA §10.4.4): each half reads lanes of its own half, and a source lane that is off in EXEC reads 0. Until 2026-11-21 lanes 32–63 of a 64-wide subgroup read the low half and inactive sources kept their value (`cs_w64x_bpermute`, AMD Radeon 880M). A source lane that doesn't exist, in the missing lanes of a partial wave, also reads 0: the shuffle result is kept only where a ballot of the running invocations has the source lane, since SPIR-V leaves a shuffle from an invocation that isn't running undefined. Before this, RADV returned stale register values that changed between runs (`cs_w64x_partial`, a 40-thread group, native wave64 on AMD RX 6700 XT, RADV Mesa 26.3.1). Writes and atomics run only in active lanes. Indices wrap at the array size, where hardware would return 0 for out-of-range reads. `s_barrier` = `OpControlBarrier` Workgroup/Workgroup, AcquireRelease + WorkgroupMemory. | | 273 | | LDS | A `Workgroup` uint array sized from LDS_SIZE, rounded up to a power of two that also covers every constant offset (15 of 486 shaders index past LDS_SIZE). Covers `ds_read/write_b32..b128`, `read2/write2` (+`st64`), `u16`/`i16`/`u8`/`i8` reads (also `ds_read_u16_d16`/`_d16_hi` and, since SHADER-85, `ds_read_u8_d16`/`_d16_hi` and `ds_read_i8_d16`/`_d16_hi`: the byte is zero- or sign-extended 8→16 into one half of the destination VGPR and the other half is kept, per the RDNA2 ISA DS opcode descriptions (opcodes 162–165) and as for the u16 d16 reads; GPU-checked with `cs_w32_lds_u8_d16.asm`, byte values 0x80/0xFF/0x7F with a non-zero `offset:`), `b16`/`b8` writes (atomic and/or, so neighbouring lanes don't race), the add/sub/min/max/and/or/xor atomics with and without return, `wrxchg`, `cmpst` (`OpAtomicCompareExchange` with DATA as comparator and DATA2 as value), and `ds_bpermute_b32` as a subgroup shuffle. `ds_permute_b32`, its forward (scatter) form, has no Vulkan equivalent: each source lane that is on in EXEC publishes `((vAddr + offset) >> 2) mod 32` and each destination lane scans the 32 sources of its half and keeps the last one that targets it (a shuffle of target and data per source lane; under `--wave64-emulate` two buffer rounds and a Function variable instead). Per the ISA pseudocode (`tmp[0..63] = 0`; `next if !EXEC[i]` on the source; `VGPR[VDST][i] = tmp[i]` only `if EXEC[i]`): a destination lane nobody targets gets 0, an off source sends nothing, an off destination keeps its VDST, and the half rule above applies as for `ds_bpermute_b32`. When several sources target one lane the ISA leaves the winner unpredictable ("the value from one of the writers"; its pseudocode says the highest-numbered); the translator takes the highest, and nothing may depend on it. Confirmed by the GPU tests `cs_w32_permute.asm` and, per half of a wave64, `cs_w64x_permute.asm` (SHADER-90: rotation, offset, unwritten lane = 0, off destination keeps its value, off source does not win) and `tests/semantic/test_ds_permute.py`. In wave64 the permute runs as two wave32s (RDNA ISA §10.4.4): each half reads lanes of its own half, and a source lane that is off in EXEC reads 0. Until 2026-11-21 lanes 32–63 of a 64-wide subgroup read the low half and inactive sources kept their value (`cs_w64x_bpermute`, AMD Radeon 880M). A source lane that doesn't exist, in the missing lanes of a partial wave, also reads 0: the shuffle result is kept only where a ballot of the running invocations has the source lane, since SPIR-V leaves a shuffle from an invocation that isn't running undefined. Before this, RADV returned stale register values that changed between runs (`cs_w64x_partial`, a 40-thread group, native wave64 on AMD RX 6700 XT, RADV Mesa 26.3.1). Writes and atomics run only in active lanes. Indices wrap at the array size, where hardware would return 0 for out-of-range reads. `s_barrier` = `OpControlBarrier` Workgroup/Workgroup, AcquireRelease + WorkgroupMemory. | |
| 274 | | LDS 2-address b64 (`ds_read2_b64`, `ds_write2_b64`, `ds_read2st64_b64`, `ds_write2st64_b64`) | Two elements at vaddr + offset0·unit and vaddr + offset1·unit, unit = 8 bytes (×64 for st64); each element is two consecutive dwords, low first. `read2_b64` fills v[d:d+3] after all four loads (a vdst overlapping vaddr is safe); `write2_b64` takes two VGPR pairs. The b32 forms share the code with unit 4. Source: RDNA2 ISA DS 2-address forms. CPU-checked by `tests/semantic/test_lds_read2_write2_b64.py` (compute listings, LDS as a Workgroup variable). **Not GPU-verified.** | | ||
| 270 | | Compute workgroup IDs Y/Z | With four user SGPRs and only TGID_Y and TGID_Z enabled (RSRC2 `0x308`), s4 receives Y and s5 receives Z. The synthetic `cs_workgroup_yz.asm` fixture checks a 2 × 3 × 4 dispatch and each of its 24 origins against a CPU reference. | | 275 | | Compute workgroup IDs Y/Z | With four user SGPRs and only TGID_Y and TGID_Z enabled (RSRC2 `0x308`), s4 receives Y and s5 receives Z. The synthetic `cs_workgroup_yz.asm` fixture checks a 2 × 3 × 4 dispatch and each of its 24 origins against a CPU reference. | |
| 271 | | Typed image stores | `image_store` (2D, 2D array, 3D) writes the dmask components (missing ones = 0). The image's numeric type lives in the T# (word 1 FORMAT [28:20], 512 GFX10 formats), so it is decided at run time. A 512-bit table built from `tools/gfx10_formats.json` (30 UINT and 15 SINT formats) picks a **sint**, **uint** or **float** view (bindings 8 + 3·dim + class; dim 0 = 2D, 1 = 2D array, 2 = 3D; class 0 float, 1 uint, 2 sint). Views have Unknown format (`shaderStorageImageWriteWithoutFormat`). **The runtime binds every storage image into all three arrays of its dimension, or at least the one matching its format.** The earlier path wrote only component 0 as `r32ui`, which was wrong for every other format. GPU-checked with `runtime/test/shaders/cs_imgstore.asm` through `runtime/test/vk_store_test.cpp`: rgba8 unorm, r32 uint and r32 sint images, every texel correct. | | 276 | | Typed image stores | `image_store` (2D, 2D array, 3D) writes the dmask components (missing ones = 0). The image's numeric type lives in the T# (word 1 FORMAT [28:20], 512 GFX10 formats), so it is decided at run time. A 512-bit table built from `tools/gfx10_formats.json` (30 UINT and 15 SINT formats) picks a **sint**, **uint** or **float** view (bindings 8 + 3·dim + class; dim 0 = 2D, 1 = 2D array, 2 = 3D; class 0 float, 1 uint, 2 sint). Views have Unknown format (`shaderStorageImageWriteWithoutFormat`). **The runtime binds every storage image into all three arrays of its dimension, or at least the one matching its format.** The earlier path wrote only component 0 as `r32ui`, which was wrong for every other format. GPU-checked with `runtime/test/shaders/cs_imgstore.asm` through `runtime/test/vk_store_test.cpp`: rgba8 unorm, r32 uint and r32 sint images, every texel correct. | |
| 272 | | Typed image loads | `image_load` on 1D/2D/2D-array/3D images uses the same T# FORMAT tables as stores: UINT/SINT formats are read with `OpImageRead` through the uint/sint storage views (`shaderStorageImageReadWithoutFormat`), everything else with `OpImageFetch` through the float sampled view as before. Results are the raw bits of the dmask components. **The runtime binds integer-format images into the uint/sint storage arrays of their dimension** (bindings 8–19), as for stores. Before this, every load went through the float view, which is undefined for integer formats. GPU-checked with `runtime/test/shaders/cs_imgload.asm` (r32 uint read back exactly). | | 277 | | Typed image loads | `image_load` on 1D/2D/2D-array/3D images uses the same T# FORMAT tables as stores: UINT/SINT formats are read with `OpImageRead` through the uint/sint storage views (`shaderStorageImageReadWithoutFormat`), everything else with `OpImageFetch` through the float sampled view as before. Results are the raw bits of the dmask components. **The runtime binds integer-format images into the uint/sint storage arrays of their dimension** (bindings 8–19), as for stores. Before this, every load went through the float view, which is undefined for integer formats. GPU-checked with `runtime/test/shaders/cs_imgload.asm` (r32 uint read back exactly). | |
| 273 | | SDWA | `_sdwa` forms: each source is narrowed to `src0_sel`/`src1_sel` (BYTE_n/WORD_n, zero-extended, or sign-extended under `sext()`) **before** neg/abs and the op. A VGPR result goes to `dst_sel`, with `dst_unused` setting the other bits: PAD = 0, SEXT = sign copies above the field, PRESERVE = old bits kept. VOPC has no `dst_sel`, and GFX10 `v_cmpx` has no written destination. **Until 2026-11-20 the selects were silently ignored.** That affected 3,826 of the 13,926 translated shaders: they passed `spirv-val` but computed wrong values. GPU-checked with `runtime/test/shaders/ps_sdwa.asm` and `ps_ops.asm` (also `v_pk_fma_f16`, `v_min3_u32`, `v_max3_i32`, `v_bfe_i32`): byte/word source selects, `sext()`, `UNUSED_PRESERVE` into WORD_1 and `UNUSED_SEXT` at BYTE_2 all match on every pixel. | | 278 | | SDWA | `_sdwa` forms: each source is narrowed to `src0_sel`/`src1_sel` (BYTE_n/WORD_n, zero-extended, or sign-extended under `sext()`) **before** neg/abs and the op. A VGPR result goes to `dst_sel`, with `dst_unused` setting the other bits: PAD = 0, SEXT = sign copies above the field, PRESERVE = old bits kept. VOPC has no `dst_sel`, and GFX10 `v_cmpx` has no written destination. **Until 2026-11-20 the selects were silently ignored.** That affected 3,826 of the 13,926 translated shaders: they passed `spirv-val` but computed wrong values. GPU-checked with `runtime/test/shaders/ps_sdwa.asm` and `ps_ops.asm` (also `v_pk_fma_f16`, `v_min3_u32`, `v_max3_i32`, `v_bfe_i32`): byte/word source selects, `sext()`, `UNUSED_PRESERVE` into WORD_1 and `UNUSED_SEXT` at BYTE_2 all match on every pixel. | |
| 274 | | Byte permute | `v_perm_b32`: result byte i = BYTE_PERMUTE({src0, src1}, selector byte i), src1 = bytes 0–3 (AMD "RDNA 2" ISA reference, VOP3 opcode 836 V_PERM_B32, `byte_permute` pseudocode, page 189 of the PDF). Selector 0–7 picks that byte; **8, 9, 10, 11 give 0xff if bit 7 of byte 1, 3, 5, 7 is set, else 0x00**; 12 gives 0x00; 13 and above give 0xff. **Until 2026-11-21 selectors 8–11 gave 0x00 regardless of the sign bit**. In the 26,503-shader disassembled corpus (measured via `tools/feature_scan.py`), 0 of 10,500 shaders (11,930 `v_perm_b32` instructions) use selectors 8–11 or >= 13: all 11,258 immediate and 672 constant-register selectors (0 unresolved) use only bytes 0–7 (36,234) and 12 (11,486). GPU-checked with `runtime/test/shaders/ps_ops7.asm` (also `v_alignbit_b32` with a shift of 36, `v_med3_i32` vs `v_med3_u32`) and `ps_ops8.asm` (`v_mul_hi_u32/i32`, `v_bcnt_u32_b32`, `v_ffbl_b32`, `v_ffbh_u32` of 0, `v_xad_u32`, `v_add3_u32`), 4096/4096 pixels on an AMD Radeon iGPU (Ryzen 7 9800X3D, RDNA2, AMD driver 25.10.36) and an NVIDIA GeForce RTX 5070 (driver 621.24); before the fix `ps_ops7` gave 0x00000000 for the sign-selector word on both. Also executed by `tests/semantic/test_value_semantics.py`. | | 279 | | Byte permute | `v_perm_b32`: result byte i = BYTE_PERMUTE({src0, src1}, selector byte i), src1 = bytes 0–3 (AMD "RDNA 2" ISA reference, VOP3 opcode 836 V_PERM_B32, `byte_permute` pseudocode, page 189 of the PDF). Selector 0–7 picks that byte; **8, 9, 10, 11 give 0xff if bit 7 of byte 1, 3, 5, 7 is set, else 0x00**; 12 gives 0x00; 13 and above give 0xff. **Until 2026-11-21 selectors 8–11 gave 0x00 regardless of the sign bit**. In the 26,503-shader disassembled corpus (measured via `tools/feature_scan.py`), 0 of 10,500 shaders (11,930 `v_perm_b32` instructions) use selectors 8–11 or >= 13: all 11,258 immediate and 672 constant-register selectors (0 unresolved) use only bytes 0–7 (36,234) and 12 (11,486). GPU-checked with `runtime/test/shaders/ps_ops7.asm` (also `v_alignbit_b32` with a shift of 36, `v_med3_i32` vs `v_med3_u32`) and `ps_ops8.asm` (`v_mul_hi_u32/i32`, `v_bcnt_u32_b32`, `v_ffbl_b32`, `v_ffbh_u32` of 0, `v_xad_u32`, `v_add3_u32`), 4096/4096 pixels on an AMD Radeon iGPU (Ryzen 7 9800X3D, RDNA2, AMD driver 25.10.36) and an NVIDIA GeForce RTX 5070 (driver 621.24); before the fix `ps_ops7` gave 0x00000000 for the sign-selector word on both. Also executed by `tests/semantic/test_value_semantics.py`. | |
| 275 | | Sum of absolute differences (`v_sad_u8`, `v_sad_hi_u8`, `v_sad_u16`, `v_sad_u32`, `v_msad_u8`) | Unsigned, wrapping at 32 bits, with ABSDIFF(x, y) = `UMax − UMin`: `v_sad_u8` = S2 + the sum over the four bytes; `v_sad_hi_u8` = (that byte sum << 16) + S2; `v_sad_u16` = S2 + the sum over the two halves; `v_sad_u32` = \|S0 − S1\| + S2; `v_msad_u8` skips a byte where S1's byte is 0. `clamp` raises `Unsupported`: the ISA pseudocode doesn't say what it does to these ops. Source: RDNA2 ISA VOP3 opcodes 346–349 and 369 (pseudocode re-read for this row). CPU-checked by `tests/semantic/test_alu_sad.py` (#544): a 9×9 grid of edge words per op, 40 seeded cases, masked bytes, an SGPR source, `clamp` rejected; the PR also reports a 300-case differential run per op with 0 mismatches. None of them is in the translated corpus, and none is GPU-checked. | | 280 | | Sum of absolute differences (`v_sad_u8`, `v_sad_hi_u8`, `v_sad_u16`, `v_sad_u32`, `v_msad_u8`) | Unsigned, wrapping at 32 bits, with ABSDIFF(x, y) = `UMax − UMin`: `v_sad_u8` = S2 + the sum over the four bytes; `v_sad_hi_u8` = (that byte sum << 16) + S2; `v_sad_u16` = S2 + the sum over the two halves; `v_sad_u32` = \|S0 − S1\| + S2; `v_msad_u8` skips a byte where S1's byte is 0. `clamp` raises `Unsupported`: the ISA pseudocode doesn't say what it does to these ops. Source: RDNA2 ISA VOP3 opcodes 346–349 and 369 (pseudocode re-read for this row). CPU-checked by `tests/semantic/test_alu_sad.py` (#544): a 9×9 grid of edge words per op, 40 seeded cases, masked bytes, an SGPR source, `clamp` rejected; the PR also reports a 300-case differential run per op with 0 mismatches. None of them is in the translated corpus, and none is GPU-checked. | |
| 281 | | `v_mqsad_u32_u8` | Four masked byte-SADs with full 32-bit accumulators: D[k] = S2[k] + `v_msad_u8` of the 32-bit window S0[8k+31:8k] of the 64-bit S0 against S1, wrapping at 32 bits (S2 and D are four VGPRs). Every source is read before the first write; `clamp` raises `Unsupported`. Source: RDNA ISA pseudocode. CPU-checked by `tests/semantic/test_alu_mqsad_u32.py`. **Not GPU-verified.** | | ||
| 276 | | `s_sext_i32_i8`, `s_sext_i32_i16`, `s_flbit_i32` | The first two sign-extend the low byte or the low half of S0 to 32 bits (`OpBitFieldSExtract`). `s_flbit_i32` counts how many bits in a row from the MSB equal the sign bit, and gives −1 when all bits are the same (0 and −1); it is the scalar form of `v_ffbh_i32` and goes through the same code. None of the three writes SCC. Source: RDNA2 ISA SOP1 opcodes 23, 25 and 26. CPU-checked by `tests/semantic/test_salu_sext_flbit.py` (#549): edge words with SCC starting at 0 and at 1, and 30 seeded values with long runs of sign bits. Not in the translated corpus, not GPU-checked. | | 282 | | `s_sext_i32_i8`, `s_sext_i32_i16`, `s_flbit_i32` | The first two sign-extend the low byte or the low half of S0 to 32 bits (`OpBitFieldSExtract`). `s_flbit_i32` counts how many bits in a row from the MSB equal the sign bit, and gives −1 when all bits are the same (0 and −1); it is the scalar form of `v_ffbh_i32` and goes through the same code. None of the three writes SCC. Source: RDNA2 ISA SOP1 opcodes 23, 25 and 26. CPU-checked by `tests/semantic/test_salu_sext_flbit.py` (#549): edge words with SCC starting at 0 and at 1, and 30 seeded values with long runs of sign bits. Not in the translated corpus, not GPU-checked. | |
| 277 | | `v_lerp_u8` | Per byte i: `D.b[i] = (S0.b[i] + S1.b[i] + (S2.b[i] & 1)) >> 1`, an unsigned average where bit 0 of S2's byte decides whether 0.5 rounds up. The 9-bit sum shifted right by 1 fits back in its byte, so nothing carries between bytes. `clamp` raises `Unsupported` (the ISA doesn't define it for this op). Source: RDNA2 ISA VOP3 opcode 333. CPU-checked by `tests/semantic/test_alu_lerp_u8.py` (#577): a 9×9×5 grid of edge and rounding words, 40 seeded cases, an SGPR source with an inline S2, `clamp` rejected. Not in the translated corpus, not GPU-checked. | | 283 | | `v_lerp_u8` | Per byte i: `D.b[i] = (S0.b[i] + S1.b[i] + (S2.b[i] & 1)) >> 1`, an unsigned average where bit 0 of S2's byte decides whether 0.5 rounds up. The 9-bit sum shifted right by 1 fits back in its byte, so nothing carries between bytes. `clamp` raises `Unsupported` (the ISA doesn't define it for this op). Source: RDNA2 ISA VOP3 opcode 333. CPU-checked by `tests/semantic/test_alu_lerp_u8.py` (#577): a 9×9×5 grid of edge and rounding words, 40 seeded cases, an SGPR source with an inline S2, `clamp` rejected. Not in the translated corpus, not GPU-checked. | |
| 284 | | Scalar select and pack (`s_cmov_b32`, `s_cmovk_i32`, `s_pack_ll/lh/hh_b32_b16`) | `s_cmov_b32` / `s_cmovk_i32`: D = SCC ? S0 : D (`s_cmovk_i32`'s S0 is the 16-bit immediate, sign-extended); SCC is read, not written; the destination must be an SGPR (a lane-mask destination, and `s_cmov_b64`, stay `Unsupported`, #210). `s_pack_*`: the low half of D from S0, the high half from S1, the letters naming the half of each (l = 15:0, h = 31:16), S0 first; GFX10 has no `s_pack_hl`; SCC not written. Source: RDNA2 ISA SOP1/SOP2/SOPK. CPU-checked by `tests/semantic/test_salu_cmov.py` and `test_salu_pack.py`; the translated shaders were run on NVIDIA by reviewers (`s_cmov*`: RTX 5090, RTX 4050 and Radeon 740M in #613; `s_pack_*`: RTX 5090 in #449). **Not measured on RDNA2.** | | ||
| 285 | | 64-bit scalar data ops (`s_brev_b64`, `s_bfe_u64`/`s_bfe_i64`, `s_bitset0_b64`/`s_bitset1_b64`, `s_flbit_i32_b64`/`s_flbit_i32_i64`) | The SGPR pair is 64-bit data, as for `s_lshl_b64`; a pair that `lane_masks.py` marks as a lane mask (or EXEC) stays `Unsupported` (#210). `s_brev_b64`: D.lo = reverse(S0.hi), D.hi = reverse(S0.lo). `s_bfe_*64`: offset = S1[5:0], width = S1[22:16]; width 0 gives 0; a field past bit 63 stops there (the 64-bit form of the `s_bfe_u32` rule, LLVM `constantFoldBFE`); SCC = D ≠ 0. `s_bitset*_b64`: bit S0 & 63 of the pair cleared / set. `s_flbit_i32_b64`: zeros above the top 1 from bit 63, −1 for 0; `s_flbit_i32_i64`: the same of ~S0 when S0 < 0, −1 for 0 and −1. None but `s_bfe` writes SCC. Source: RDNA2 ISA SOP1/SOP2. CPU-checked by `tests/semantic/test_salu_brev_b64.py`, `test_salu_bfe_64.py`, `test_salu_bitset_b64.py`, `test_salu_flbit_64.py` (#723, #726, #729, #733). **Not GPU-verified.** | | ||
| 286 | | Vector integer additions (`v_mul_hi_u32_u24`/`v_mul_hi_i32_i24`, `v_lshrrev_b64`/`v_ashrrev_i64`, `v_qsad_pk_u16_u8`/`v_mqsad_pk_u16_u8`) | `v_mul_hi_*24`: the high 32 bits of the 48-bit product of the low 24 bits, zero-extended (u24) or sign-extended from bit 23 (i24); the high halves of `v_mul_u32_u24` / `v_mul_i32_i24`. `v_lshrrev_b64` / `v_ashrrev_i64`: the pair (or a 64-bit constant) shifted right by S0 & 63, logically or arithmetically, through the `v_lshlrev_b64` code. `v_qsad_pk_u16_u8` / `v_mqsad_pk_u16_u8`: D.u16[k] = (S2.u16[k] + byte SAD of the 32-bit window S0[8k+31:8k] against S1) & 0xFFFF; the m form skips bytes where S1's byte is 0; `clamp` raises `Unsupported`. Source: RDNA ISA pseudocode. CPU-checked by `tests/semantic/test_alu_mul_hi_24.py`, `test_alu_shift_b64.py`, `test_alu_qsad.py`; run on NVIDIA by reviewers (`v_mul_hi_*24`: RTX 5090 and RTX 5070 in #440; `v_qsad`/`v_mqsad`: 24 cases bit-exact on an RTX 3060 in #623). **Not measured on RDNA2.** | | ||
| 287 | | Constant and ordered VOPC, `v_cvt_off_f32_i4`, `v_pipeflush` | `v_cmp(x)_f_*` is always false, `v_cmp(x)_t_*` (integers) and `v_cmp(x)_tru_*` (floats) always true; `v_cmp(x)_o_{f32,f16}` is true when neither source is NaN, `_u_` when either is (`OpIsNan`); the result goes through the usual VOPC path (VCC, an SGPR mask, or EXEC for `v_cmpx`; off lanes give 0). `v_cvt_off_f32_i4`: D = sext(S0[3:0]) / 16 (the ISA's CVT_OFF_TABLE, -0.5 .. 0.4375), exact, output modifiers apply. `v_pipeflush` only flushes the VALU pipeline and is translated as nothing, like `v_nop`. Source: RDNA2 ISA VOPC and VOP1. CPU-checked by `tests/semantic/test_vopc_const_ordered.py`, `test_alu_cvt_off.py`, `test_valu_pipeflush.py`; the float compares were run on an RTX 5090 (16 draws, quiet and signalling NaNs) and the suite on RTX 4050 / Radeon 740M in #620; `v_pipeflush` on RTX 5090 / RTX 3060 in #735. | | ||
| 278 | | Relative VGPR moves (`v_movrel*`) | The VGPR file is a Function-scope uint array, so `v_movrels_b32`/`v_movreld_b32`/`v_movrelsd_b32` become dynamic array accesses at `reg + M0` (the whole of M0, as the RDNA2 ISA's opcode descriptions say). `v_movrelsd_2_b32` (VOP1 opcode 72) offsets each side by its own field: VGPR[D + M0[25:16]] = VGPR[S0 + M0[9:0]], other M0 bits ignored (RDNA2 ISA §12.8 opcode description and the RDNA3 ISA; the RDNA2 §6.6 summary table prints M0[7:0] for the source). The write keeps inactive lanes. Not modelled: the hardware's range check against the wave's VGPR allocation (an out-of-range source reads VGPR0, an out-of-range write is dropped). CPU-checked by `tests/semantic/test_alu_movrelsd_2.py` (including set ignored M0 bits); GPU-checked with `runtime/test/shaders/cs_movrelsd_2.asm` (the ISA's own example, v25 ← v17 with M0 = (20 << 16) \| 10) on NVIDIA RTX 4050 Laptop (Ada) and AMD Radeon 740M (RADV). | | 288 | | Relative VGPR moves (`v_movrel*`) | The VGPR file is a Function-scope uint array, so `v_movrels_b32`/`v_movreld_b32`/`v_movrelsd_b32` become dynamic array accesses at `reg + M0` (the whole of M0, as the RDNA2 ISA's opcode descriptions say). `v_movrelsd_2_b32` (VOP1 opcode 72) offsets each side by its own field: VGPR[D + M0[25:16]] = VGPR[S0 + M0[9:0]], other M0 bits ignored (RDNA2 ISA §12.8 opcode description and the RDNA3 ISA; the RDNA2 §6.6 summary table prints M0[7:0] for the source). The write keeps inactive lanes. Not modelled: the hardware's range check against the wave's VGPR allocation (an out-of-range source reads VGPR0, an out-of-range write is dropped). CPU-checked by `tests/semantic/test_alu_movrelsd_2.py` (including set ignored M0 bits); GPU-checked with `runtime/test/shaders/cs_movrelsd_2.asm` (the ISA's own example, v25 ← v17 with M0 = (20 << 16) \| 10) on NVIDIA RTX 4050 Laptop (Ada) and AMD Radeon 740M (RADV). | |
| 289 | | d16 and f16 format narrowing | The f16 of every d16 result (image samples and gathers, the `image_sample_c_lz` compare result, typed buffer loads) and of the f16 formats a typed buffer store writes is narrowed with integer round to nearest even (`Gen.f16_bits`; #489, #711), not with `PackHalf2x16`. AMD drivers lower `PackHalf2x16` to `v_cvt_pkrtz_f16_f32`, which rounds toward zero (#489), and there about half of all unorm8, unorm16 and snorm8 values loaded with d16 came out 1 ulp low (123 of 256, 31,742 of 65,536 and 110 of 256). The memory results are packed by `pack_f16_pair_int`, never by `f16_pack2`: they come from the texture and buffer units, not the VALU whose rounding `MODE.FP_ROUND` sets (#753). Round to nearest even for these conversions is inferred, as in #489, not measured. #489's own narrower, `f32_to_f16_int`, was folded into `f16_bits` on 2026-11-22: the two gave the same bits on 30,648 inputs (every f32 exponent, ties, the subnormal and overflow edges, NaN), and `f16_bits` lost its one GLSL.std.450 instruction (`UMin`) so the packer stays free of them. Checked by `tests/test_translate.py` (`test_depth_compare_sample_result_width`, `test_buffer_format_f16_narrowing_avoids_packhalf2x16`), `tests/test_d16_pack.py` and `tests/semantic/test_buffer_load_format.py` (`D16NormalizedRounding`). | | ||
| 279 | | Float-to-int saturation | `v_cvt_u32_f32` and `v_cvt_i32_f32` truncate toward zero, saturate out-of-range values (including infinities) to the destination bounds, and return zero for NaN. The conversion operand is kept in range before emitting SPIR-V `OpConvertFToU`/`OpConvertFToS`. Source: AMD [RDNA 2 ISA reference](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf), §12.8, VOP1 opcodes 7 and 8. The synthetic `cs_cvt_f32_sat.asm` fixture is checked bit-for-bit by `tests/semantic/test_float_to_int.py`. | | 290 | | Float-to-int saturation | `v_cvt_u32_f32` and `v_cvt_i32_f32` truncate toward zero, saturate out-of-range values (including infinities) to the destination bounds, and return zero for NaN. The conversion operand is kept in range before emitting SPIR-V `OpConvertFToU`/`OpConvertFToS`. Source: AMD [RDNA 2 ISA reference](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf), §12.8, VOP1 opcodes 7 and 8. The synthetic `cs_cvt_f32_sat.asm` fixture is checked bit-for-bit by `tests/semantic/test_float_to_int.py`. | |
| 280 | | `v_cvt_flr_i32_f32`, `v_cvt_rpi_i32_f32` | RDNA ISA pseudocode: `f32_to_i32(floor(S0))` and `f32_to_i32(floor(S0 + 0.5))`, the `+ 0.5` rounded in binary32 like any f32 add (so 0.49999997 gives 1, where an exact round-half-up would give 0). `f32_to_i32` saturates as in the row above: INT_MAX / INT_MIN at or past ±2³¹ and for ±inf, 0 for NaN. Source neg/abs apply first. Checked on the CPU by `tests/semantic/test_alu_cvt_flr_rpi.py`, **not yet GPU-verified**. | | 291 | | `v_cvt_flr_i32_f32`, `v_cvt_rpi_i32_f32` | RDNA ISA pseudocode: `f32_to_i32(floor(S0))` and `f32_to_i32(floor(S0 + 0.5))`, the `+ 0.5` rounded in binary32 like any f32 add (so 0.49999997 gives 1, where an exact round-half-up would give 0). `f32_to_i32` saturates as in the row above: INT_MAX / INT_MIN at or past ±2³¹ and for ±inf, 0 for NaN. Source neg/abs apply first. Checked on the CPU by `tests/semantic/test_alu_cvt_flr_rpi.py`, **not yet GPU-verified**. | |
| 281 | | f16 rounding (SHADER-55, SHADER-56) | **Narrowing to f16 uses integer ops, not `PackHalf2x16`.** Every f16 ALU result (`v_*_f16` VOP1/VOP2/VOP3, `v_pk_*_f16`, `v_cvt_f16_f32`, `v_interp_p2_f16`, `v_fma_mix*`) and `v_cvt_pkrtz_f16_f32` go through `Gen.f16_bits` (round to nearest even, or round toward zero for pkrtz; f16 denormals kept, f32 denormal inputs give ±0, NaN stays a quiet NaN). GLSL.std.450 leaves `PackHalf2x16`'s rounding to the implementation, and drivers fold a `PackHalf2x16` → `UnpackHalf2x16` round trip to a no-op, so the next f16 op saw the unrounded f32: #513 (RTX 6000 Ada, `--wave64-emulate`, `v_pk_add_f16` → `v_pk_mul_f16` 1 ulp off), and pkrtz giving round-to-nearest on llvmpipe. **f16 FMAs round once** (`v_fma_f16`, `v_fmac_f16`, `v_pk_fma_f16`): x·y is exact in f32, TwoSum gives the exact error of the f32 sum, and round-to-odd at f32 then rounds correctly to f16. An RX 6700 matched a correctly rounded f16 FMA in 12,612 of 12,612 cases (#374); `Fma` then narrowing double-rounded. Checked by `tests/semantic/test_f16_int_convert.py` (edges + seeded sweep against Python's binary16), `tests/semantic/test_f16_fma_rounding.py` (exact rational reference; built near-tie cases fail on the old translation) and `tools/valu_fuzz.py --family f16` on an RTX 6000 Ada. Image/buffer d16 packing (#489) and the 16-bit interpolant quantize (#512) are separate. `v_fma_mix*` with f32 sources still uses `Fma`. | | 292 | | f16 rounding (SHADER-55, SHADER-56) | **Narrowing to f16 uses integer ops, not `PackHalf2x16`.** Every f16 ALU result (`v_*_f16` VOP1/VOP2/VOP3, `v_pk_*_f16`, `v_cvt_f16_f32`, `v_interp_p2_f16`, `v_fma_mix*`) and `v_cvt_pkrtz_f16_f32` go through `Gen.f16_bits` (round to nearest even, or round toward zero for pkrtz; f16 denormals kept, f32 denormal inputs give ±0, NaN stays a quiet NaN). GLSL.std.450 leaves `PackHalf2x16`'s rounding to the implementation, and drivers fold a `PackHalf2x16` → `UnpackHalf2x16` round trip to a no-op, so the next f16 op saw the unrounded f32: #513 (RTX 6000 Ada, `--wave64-emulate`, `v_pk_add_f16` → `v_pk_mul_f16` 1 ulp off), and pkrtz giving round-to-nearest on llvmpipe. **f16 FMAs round once** (`v_fma_f16`, `v_fmac_f16`, `v_pk_fma_f16`): x·y is exact in f32, TwoSum gives the exact error of the f32 sum, and round-to-odd at f32 then rounds correctly to f16. An RX 6700 matched a correctly rounded f16 FMA in 12,612 of 12,612 cases (#374); `Fma` then narrowing double-rounded. Checked by `tests/semantic/test_f16_int_convert.py` (edges + seeded sweep against Python's binary16), `tests/semantic/test_f16_fma_rounding.py` (exact rational reference; built near-tie cases fail on the old translation) and `tools/valu_fuzz.py --family f16` on an RTX 6000 Ada. Image/buffer d16 packing (#489) and the 16-bit interpolant quantize (#512) are separate. `v_fma_mix*` with f32 sources still uses `Fma`. | |
| @@ -310,8 +321,10 @@ cross-half code on 32-wide subgroups. | |||
| 310 | ## Day one, in order | 321 | ## Day one, in order |
| 311 | 322 | ||
| 312 | 1. `scripts\first_look.ps1 -Exe ...` checks the exe is plain, lists the imports to shim, and does a dry run. | 323 | 1. `scripts\first_look.ps1 -Exe ...` checks the exe is plain, lists the imports to shim, and does a dry run. |
| 313 | 2. Find the RPF9 table-of-contents key and decryption in the exe, then add a table reader to `rpf9_carve.py`. Carved | 324 | 2. Read the RPF9 table of contents only where it is already plain on disk. Five archives have tables that look packed |
| 314 | blobs then get real names and types, and the remaining unread data shows what it is. | 325 | or encrypted; under the ground rules above they stay unread and are recorded, not decrypted. Where a table is |
| 326 | readable, a reader in `rpf9_carve.py` gives carved blobs real names and types, and the remaining unread data shows | ||
| 327 | what it is. | ||
| 315 | 3. Find the texture and mesh resource structures in the exe (their loaders give exact field layouts), which turns | 328 | 3. Find the texture and mesh resource structures in the exe (their loaders give exact field layouts), which turns |
| 316 | carved blobs into named textures and meshes. | 329 | carved blobs into named textures and meshes. |
| 317 | 4. Shader translation: already complete for all 26,503 shaders (see *Translator status*); the day-one work is | 330 | 4. Shader translation: already complete for all 26,503 shaders (see *Translator status*); the day-one work is |
diff --git a/docs/gameinput.md b/docs/gameinput.md index 2faa2fdbc..bab5d423d 100644 --- a/docs/gameinput.md +++ b/docs/gameinput.md | |||
| @@ -62,6 +62,37 @@ controller-button array (`GetControllerButtonState`, indexed in SDL's `SDL_Gamep | |||
| 62 | - Player LEDs (and SDL's default lightbar colour) follow connection order: the first pad is player 1, and a pad | 62 | - Player LEDs (and SDL's default lightbar colour) follow connection order: the first pad is player 1, and a pad |
| 63 | plugged in later takes the lowest free slot. | 63 | plugged in later takes the lowest free slot. |
| 64 | 64 | ||
| 65 | ## Keyboard pad | ||
| 66 | |||
| 67 | The title reads gamepads only, so keyboard input has to arrive as a gamepad. With `LEONIDA_KEYBOARD_PAD` set, the | ||
| 68 | shim attaches one SDL virtual gamepad named `Keyboard pad (Leonida)` and presses its buttons from the keyboard on | ||
| 69 | every poll. It then goes through the same path as a real pad: a device object, the next free player slot, readings, | ||
| 70 | reading and device callbacks, and UI navigation derived from its buttons. It reports no rumble motors. It is off by | ||
| 71 | default. | ||
| 72 | |||
| 73 | | key | button | | ||
| 74 | |---|---| | ||
| 75 | | arrow keys | d-pad | | ||
| 76 | | Enter | `A` | | ||
| 77 | | Backspace | `B` | | ||
| 78 | | X | `X` | | ||
| 79 | | Y | `Y` | | ||
| 80 | | Q / E | left / right shoulder | | ||
| 81 | | Esc | `Menu` | | ||
| 82 | | Tab | `View` | | ||
| 83 | |||
| 84 | This is enough to drive menus and press prompts. The sticks and triggers stay at rest: moving with WASD and aiming | ||
| 85 | with the mouse are for a later change. Letters are Windows virtual-key codes, so `Y` is the key labelled Y on the | ||
| 86 | active layout (it sits where Z does on a QWERTY keyboard with a German layout). | ||
| 87 | |||
| 88 | Keys are read with `GetAsyncKeyState`, which needs no window or message loop (SDL's keyboard is part of its video | ||
| 89 | subsystem, which this build leaves out) and works under Wine. With `LEONIDA_KEYBOARD_PAD=1` keys count only while a | ||
| 90 | window of this process is in the foreground, so typing in another application presses nothing, and every button is | ||
| 91 | released when focus moves away. `LEONIDA_KEYBOARD_PAD=always` reads them whatever has focus; a console tool such as | ||
| 92 | `gameinput_probe` needs it, because its console window belongs to the terminal, not to the tool. | ||
| 93 | |||
| 94 | To try it by hand: `set LEONIDA_KEYBOARD_PAD=always`, then `gameinput_probe --seconds 20` and press keys. | ||
| 95 | |||
| 65 | ## Rumble and triggers | 96 | ## Rumble and triggers |
| 66 | 97 | ||
| 67 | `IGameInputDevice::SetRumbleState` takes four motor levels, 0..1. The two body motors go to `SDL_RumbleGamepad` on | 98 | `IGameInputDevice::SetRumbleState` takes four motor levels, 0..1. The two body motors go to `SDL_RumbleGamepad` on |
| @@ -101,6 +132,7 @@ An effect is sent only when its bytes change, so a steady level costs one report | |||
| 101 | | `LEONIDA_DS_LIGHTBAR` | unset | `RRGGBB` (hex) sets the DualSense/DualShock 4 lightbar when the pad connects; `off` turns it dark; unset keeps SDL's player colour | | 132 | | `LEONIDA_DS_LIGHTBAR` | unset | `RRGGBB` (hex) sets the DualSense/DualShock 4 lightbar when the pad connects; `off` turns it dark; unset keeps SDL's player colour | |
| 102 | | `LEONIDA_RUMBLE` | `1` | `0` turns all rumble and trigger output off | | 133 | | `LEONIDA_RUMBLE` | `1` | `0` turns all rumble and trigger output off | |
| 103 | | `LEONIDA_GAMEINPUT_THREAD` | `1` | `0` stops the background poll thread; only `rt::gameinput::poll()` then reads the pads (tests) | | 134 | | `LEONIDA_GAMEINPUT_THREAD` | `1` | `0` stops the background poll thread; only `rt::gameinput::poll()` then reads the pads (tests) | |
| 135 | | `LEONIDA_KEYBOARD_PAD` | `off` | `1` adds the [keyboard pad](#keyboard-pad), read while this process has focus; `always` reads keys whatever has focus | | ||
| 104 | 136 | ||
| 105 | SDL's own hints (`SDL_JOYSTICK_*`, see SDL's `SDL_hints.h`) also apply, for example `SDL_JOYSTICK_HIDAPI_PS5=0` to | 137 | SDL's own hints (`SDL_JOYSTICK_*`, see SDL's `SDL_hints.h`) also apply, for example `SDL_JOYSTICK_HIDAPI_PS5=0` to |
| 106 | leave a DualSense to the generic driver, or `SDL_GAMECONTROLLERCONFIG` to add a mapping for an unknown pad. | 138 | leave a DualSense to the generic driver, or `SDL_GAMECONTROLLERCONFIG` to add a mapping for an unknown pad. |
| @@ -171,7 +203,9 @@ shim fills (`GameInputDeviceInfo` 320 bytes with `deviceFamily` at 96 and the in | |||
| 171 | the fact, both directions, two pads interleaved and filtered by device, ageing out, held readings, unplug and | 203 | the fact, both directions, two pads interleaved and filtered by device, ageing out, held readings, unplug and |
| 172 | replug), the guide button, motor and trigger | 204 | replug), the guide button, motor and trigger |
| 173 | rumble as SDL receives them, the DualSense effect bytes in each `LEONIDA_DS_TRIGGERS` mode, the lightbar, a | 205 | rumble as SDL receives them, the DualSense effect bytes in each `LEONIDA_DS_TRIGGERS` mode, the lightbar, a |
| 174 | dispatcher, async and blocking enumeration, unregistering, and unplugging and replugging. | 206 | dispatcher, async and blocking enumeration, unregistering, and unplugging and replugging. The keyboard pad is |
| 207 | driven through `rt::gameinput::set_keyboard_source` with fake keys and focus: every binding, two keys at once, no | ||
| 208 | input out of focus, release on focus loss, the `always` mode, and turning it off and on again. | ||
| 175 | - `gameinput_probe [--seconds N] [--rumble]` (by hand, with a pad connected): lists the pads, plays each motor and | 209 | - `gameinput_probe [--seconds N] [--rumble]` (by hand, with a pad connected): lists the pads, plays each motor and |
| 176 | trigger for a second with `--rumble`, then prints the live reading. | 210 | trigger for a second with `--rumble`, then prints the live reading. |
| 177 | 211 | ||
| @@ -192,5 +226,8 @@ These need the game executable or a test on hardware: | |||
| 192 | - **`UnregisterCallback` timeout** is not honoured; it waits for a callback that is running. | 226 | - **`UnregisterCallback` timeout** is not honoured; it waits for a callback that is running. |
| 193 | - **Device family**: every pad is reported as `GameInputFamilyXboxOne`; a title that filters on family sees only | 227 | - **Device family**: every pad is reported as `GameInputFamilyXboxOne`; a title that filters on family sees only |
| 194 | that. | 228 | that. |
| 229 | - **Keyboard pad as a second pad**: it is one more connected gamepad, so with a controller plugged in the title sees | ||
| 230 | two. A title that follows only the first pad it saw, or asks the player to press a button to pick the active pad, | ||
| 231 | may ignore one of them; whether the game does either is unknown. | ||
| 195 | - **DualSense effect parameters**: the `06` (vibration) and `01` (resistance) byte meanings follow SDL's | 232 | - **DualSense effect parameters**: the `06` (vibration) and `01` (resistance) byte meanings follow SDL's |
| 196 | `testcontroller.c`; how strong 255 feels and what frequency suits the Xbox signal needs a session on a real pad. | 233 | `testcontroller.c`; how strong 255 feels and what frequency suits the Xbox signal needs a session on a real pad. |
diff --git a/docs/rsc8_audio.md b/docs/rsc8_audio.md new file mode 100644 index 000000000..bc7d96314 --- /dev/null +++ b/docs/rsc8_audio.md | |||
| @@ -0,0 +1,251 @@ | |||
| 1 | # `RSC8` audio-bank resources (AWC tag `0x5c`) | ||
| 2 | |||
| 3 | **Status: decoded at container, object-graph, property, animation-block and track-directory level; stdlib decoder in [`tools/rsc8_audio.py`](../tools/rsc8_audio.py).** | ||
| 4 | |||
| 5 | [story.md](story.md) measured 225,281 raw `RSC8` (version `8001` / `0x1F41`) headers in `story000.rpf` | ||
| 6 | (plus 1,957 in `shared_minigame000.rpf` and 9 in `story000_restofworld.rpf`), and the mission-music | ||
| 7 | search recorded in [audio.md](audio.md#mission-music-home-sweet-home) (#716) left `RSC8` as the only | ||
| 8 | undecoded mission-side container. | ||
| 9 | |||
| 10 | Full-package scanning resolves what `RSC8` is: | ||
| 11 | |||
| 12 | - **`RSC8` v8001 is not an audio codec or standalone audio container.** | ||
| 13 | - **641,428 of 641,428** `RSC8` resources across the package (`8,183,359,968` bytes total) sit inside | ||
| 14 | standard little-endian **`ADAT` (AWC)** banks as **chunk tag `0x5c`**. Zero `RSC8` headers occur | ||
| 15 | outside `ADAT` anywhere, zero `0x5c` chunks hold non-`RSC8` data, and zero `RSC8` resources appear | ||
| 16 | under any other AWC chunk tag. | ||
| 17 | - **641,428 of 641,428** `0x5c` entries belong to an AWC stream that also carries a sibling **`0x55`** | ||
| 18 | audio payload and **`0x76`** format chunk declaring **48 kHz mono Opus** (`codec = 0x0B`, `channels = 1`, | ||
| 19 | `sample_rate = 48000`). | ||
| 20 | - Inside tag `0x5c`, the payload is an unencrypted RAGE **`crClipDictionary` + `crClipAnimation` + | ||
| 21 | `crAnimationDictionary` + `crAnimation`** facial / lip-sync animation resource whose clip duration | ||
| 22 | tracks the companion Opus dialogue line (typically with a short lip-sync blend margin). Zero `RSC8` | ||
| 23 | resources contain an embedded audio container (`ADAT`, `OggS`/`OpusHead`, or `RIFF WAVE`). | ||
| 24 | - Consequently, `RSC8` cannot hold undecoded mission music, closing that residual item from #716. | ||
| 25 | |||
| 26 | Every figure below is an aggregate measurement from one local Xbox Series 1.0.2.1 package. No game | ||
| 27 | strings, asset names, dialogue lines, audio streams or raw payloads are committed here or emitted by | ||
| 28 | `tools/rsc8_audio.py`. | ||
| 29 | |||
| 30 | ## Corpus counts | ||
| 31 | |||
| 32 | | Archive | `ADAT` banks | `ADAT` streams | Bytes in `ADAT` | `RSC8` (`0x5c`) | `RSC8` outside `ADAT` | `RSC8` tag bytes | `u32@+0x08` sum | Paired `0x55` Opus (48 kHz mono) | | ||
| 33 | |---|---:|---:|---:|---:|---:|---:|---:|---:| | ||
| 34 | | `audio.rpf` | 7,160 | 1,606,241 | 28,505,691,492 | 414,181 | 0 | 5,470,286,400 | 5,465,316,228 | 414,181 / 414,181 | | ||
| 35 | | `story000.rpf` | 63,861 | 234,458 | 9,423,830,212 | 225,281 | 0 | 2,680,074,288 | 2,677,370,916 | 225,281 / 225,281 | | ||
| 36 | | `shared_minigame000.rpf` | 638 | 4,334 | 359,078,504 | 1,957 | 0 | 32,927,792 | 32,904,308 | 1,957 / 1,957 | | ||
| 37 | | `story000_restofworld.rpf` | 15 | 76 | 8,908,216 | 9 | 0 | 71,488 | 71,380 | 9 / 9 | | ||
| 38 | | **Total (4 archives)** | **71,674** | **1,845,109** | **38,297,508,424** | **641,428** | **0** | **8,183,359,968** | **8,175,662,832** | **641,428 / 641,428** | | ||
| 39 | |||
| 40 | Eight additional archives were scanned in full and contain **0** `RSC8` headers: `anim.rpf`, | ||
| 41 | `packs.rpf`, `core_restofworld.rpf`, `data.rpf`, `textures.rpf`, `story000_script.rpf`, `common.rpf`, | ||
| 42 | and `script.rpf`. | ||
| 43 | |||
| 44 | ### Resolution of the `docs/story.md` raw gaps | ||
| 45 | |||
| 46 | The uninflatable raw regions noted in [story.md](story.md) are unencrypted `ADAT` (AWC) audio banks: | ||
| 47 | |||
| 48 | - **`story000.rpf` GiB 5–13**: `63,861` `ADAT` banks spanning `9,423,830,212` bytes (`8.78 GiB`), | ||
| 49 | containing `753` streamed-music (`0x48`) banks (matching #716) and `225,281` spoken dialogue streams | ||
| 50 | with `0x5c` facial clips. The `u32@+0x08` sum (`2,677,370,916` bytes = `2.49 GiB`) matches | ||
| 51 | [story.md](story.md) to the exact byte; the remainder of the `8.78 GiB` region is the sibling Opus | ||
| 52 | speech audio (`0x55`), streamed-music chunks (`0x48`), and per-stream audio metadata tags. | ||
| 53 | - **`shared_minigame000.rpf` 360 MB unread gap**: `638` `ADAT` banks spanning `359,078,504` bytes | ||
| 54 | (`99.2%` of the `362.1 MB` unread span), containing `7` streamed-music (`0x48`) banks and `1,957` | ||
| 55 | `0x5c` facial clips (`u32@+0x08` sum `32,904,308` bytes, matching [story.md](story.md)). | ||
| 56 | - **`story000_restofworld.rpf` 8.96 MB unread gap**: `15` `ADAT` banks spanning `8,908,216` bytes | ||
| 57 | (`99.4%` of the gap), containing `13` streamed-music (`0x48`) tags and `9` `0x5c` facial clips. | ||
| 58 | |||
| 59 | ## Companion AWC speech tags | ||
| 60 | |||
| 61 | Beyond the three tags documented in [audio.md](audio.md) (`0x55` stream data, `0x76` format, `0x48` | ||
| 62 | streamed-music descriptor), speech streams carrying `0x5c` consistently carry these sibling tags: | ||
| 63 | |||
| 64 | | Tag | Role | Measured layout | | ||
| 65 | |---:|---|---| | ||
| 66 | | `0x55` | Audio stream payload | 2048-byte Opus packet blocks (`codec = 0x0B`, mono, 48 kHz) | | ||
| 67 | | `0x76` | Audio format | 32 bytes (`+0x00 u32` samples, `+0x08 u16` sample rate, `+0x1C u8` codec, `+0x1D u8` channels) | | ||
| 68 | | `0x5c` | Facial / lip-sync clip | Unencrypted `RSC8` resource (`crClipDictionary` + `crAnimation`) | | ||
| 69 | | `0x36` | Peak envelope | Array of `u16` amplitude peaks | | ||
| 70 | | `0xa3` | Opus seek table | `u32` cumulative sample offsets per 2048-byte Opus block (step `0x2D00 = 11,520` = `12 × 960` samples) | | ||
| 71 | | `0xb2` | Loudness curve | `(u32 sample_index, f32 dB)` pairs sampled every `4,800` samples (`100 ms` at 48 kHz) | | ||
| 72 | | `0xbd` | Event / marker block | 16-byte header starting with magic `0xE5C74063` | | ||
| 73 | |||
| 74 | ## Binary format of `RSC8` (version `8001`) | ||
| 75 | |||
| 76 | All integers and IEEE-754 floats are little-endian. Every `RSC8` tag payload is 16-byte aligned. | ||
| 77 | |||
| 78 | ### 1. Outer 16-byte wrapper (`+0x00..+0x0F`) | ||
| 79 | |||
| 80 | ``` | ||
| 81 | +0x00 4s "RSC8" | ||
| 82 | +0x04 u32 version 0x00001F41 (8001) on 641,227 clips; 0x01001F41 on 201 audio.rpf clips | ||
| 83 | +0x08 u32 body_size exact byte length after +0x0C: tag_size == body_size + 12 (641,428 / 641,428) | ||
| 84 | +0x0C u32 flags always 1 (641,428 / 641,428) | ||
| 85 | +0x10 ... virtual segment (`virtual_size == tag_size - 0x10 == body_size - 4`) | ||
| 86 | ``` | ||
| 87 | |||
| 88 | Every internal 64-bit pointer uses virtual base **`0x50000000`** relative to **`+0x10`**: | ||
| 89 | |||
| 90 | ``` | ||
| 91 | file_offset = 0x10 + (u64_ptr - 0x50000000) | ||
| 92 | ``` | ||
| 93 | |||
| 94 | The `201` `audio.rpf` clips with `version = 0x01001F41` (`version & 0xFFFF == 8001`, flag bit 24 set) | ||
| 95 | use the identical binary structure, pointer base, animation block format, and sorted track directory | ||
| 96 | as `0x00001F41`. | ||
| 97 | |||
| 98 | ### 2. Root `crClipDictionary` (`virt+0x00..virt+0xAF`) | ||
| 99 | |||
| 100 | | Virtual offset | Size | Type | Meaning | | ||
| 101 | |---:|---:|---|---| | ||
| 102 | | `+0x00` | 8 | `u64` | `0` (vtable placeholder) | | ||
| 103 | | `+0x08` | 8 | `vptr` | Block-map node pointer (`+0x08 u32 = 1`) | | ||
| 104 | | `+0x38` | 16 | `atString` | 16-byte SSO dictionary name (see §3) | | ||
| 105 | | `+0x48` | 8 | `vptr` | Clip `atMap` bucket array (`+0x50 u32 = 11` buckets, `+0x58 u32 = 1` entry) | | ||
| 106 | | `+0x68` | 4 | `u32` | `stream_hash` (`stream_hash & 0x1FFFFFFF == AWC stream_id` on 100% of `story000` / `minigame` / `restofworld` and ~99% of `audio.rpf`) | | ||
| 107 | | `+0x6C` | 4 | `u32` | Dictionary flags (`2`) | | ||
| 108 | | `+0x70` | 12 | `atArray` | `vptr` (`+0x70`), `u16 count`, `u16 capacity` (`+0x78`) of 16-byte `(vptr anim_dict, u32 hash, u32 1)` entries | | ||
| 109 | | `+0x80` | 8 | `vptr` | Secondary hash `atMap` (`+0x88 u32 = 11` buckets, `+0x90 u32 = 1` entry) | | ||
| 110 | | `+0xA0` | 8 | `vptr` | Pointer to `crProperties` table | | ||
| 111 | | `+0xA8` | 4 | `u32` | Exact byte size of the `crProperties` table | | ||
| 112 | |||
| 113 | ### 3. 16-byte SSO `atString` (`virt+0x38` and `crClipAnimation+0x28`) | ||
| 114 | |||
| 115 | The same 16-byte short-string-optimized layout appears for both the dictionary name and the clip name: | ||
| 116 | |||
| 117 | - **Inline mode (`raw[15] & 0x80 != 0`)**: `length = raw[15] & 0x7F` (`<= 14`), NUL-terminated ASCII | ||
| 118 | stored directly in `raw[0 : length + 1]`. | ||
| 119 | - **Heap mode (`raw[15] & 0x80 == 0`)**: `+0x00 vptr` to NUL-terminated ASCII string in the virtual | ||
| 120 | segment, `+0x08 u16 length`, `+0x0A u16 capacity` (`>= length + 1`), `+0x0C u32 flags = 1`. | ||
| 121 | |||
| 122 | ### 4. `crProperties` (`props_ptr`, length `props_size`) | ||
| 123 | |||
| 124 | | Relative offset | Size | Type | Meaning | | ||
| 125 | |---:|---:|---|---| | ||
| 126 | | `+0x10` | 8 | `vptr` | Pointer to the `crClipAnimation` object | | ||
| 127 | | `+0x18` | 4 | `u32` | `prop_count` (measured range `3..7`, predominantly `4` or `5`) | | ||
| 128 | | `+0x1C` | 4 | `u32` | `prop_capacity` | | ||
| 129 | | `+0x70` | `prop_count * 0x48` | descriptors | Fixed `0x48`-byte property descriptors | | ||
| 130 | | tail | variable | attributes | Contiguous typed attribute records tiling cleanly to `props_size` | | ||
| 131 | |||
| 132 | Typed attribute records begin with `(u32 key_hash, u32 type_id)`: | ||
| 133 | |||
| 134 | | `type_id` | Record size | Payload | Common key hashes | | ||
| 135 | |---:|---:|---|---| | ||
| 136 | | `0xFFFF0004` | `0x40` | String attribute (`+0x18 u64` string length) | | | ||
| 137 | | `0xFFFF000E` | `0x20` | 16-byte GUID attribute | | | ||
| 138 | | `0xFFFF0003` | `0x0C` | Boolean (`+0x08 u32`) | | | ||
| 139 | | `0xFFFF0002` | `0x0C` | Integer (`+0x08 u32`) | `0x10BF2F94` = frame rate (`60` Hz) | | ||
| 140 | | `0xFFFF0001` | `0x0C` | Float (`+0x08 f32`) | `0xAAA6AF06` = lead-in / blend (`0.166667` = `1/6` s) | | ||
| 141 | |||
| 142 | ### 5. `crClipAnimation` (`clip_ptr`, `0xA0` bytes) and `crAnimation` descriptor (`anim_desc_ptr`, `0x70` bytes) | ||
| 143 | |||
| 144 | `crClipAnimation`: | ||
| 145 | |||
| 146 | | Relative offset | Size | Type | Meaning | | ||
| 147 | |---:|---:|---|---| | ||
| 148 | | `+0x28` | 16 | `atString` | 16-byte SSO clip name | | ||
| 149 | | `+0x48` | 8 | `vptr` | Back-pointer to `crProperties` | | ||
| 150 | | `+0x58` | 4 | `u32` | `clip_hash` (matches root `stream_hash`) | | ||
| 151 | | `+0x68` | 8 | `vptr` | Pointer to `crAnimation` descriptor | | ||
| 152 | | `+0x94` | 4 | `f32` | Clip duration in seconds (`== (total_frames - 1) / fps`) | | ||
| 153 | | `+0x98` | 4 | `f32` | Playback rate (`1.0`) | | ||
| 154 | |||
| 155 | `crAnimation` descriptor: | ||
| 156 | |||
| 157 | | Relative offset | Size | Type | Meaning | | ||
| 158 | |---:|---:|---|---| | ||
| 159 | | `+0x18` | 8 | `vptr` | Pointer to `crAnimationDictionary` | | ||
| 160 | | `+0x30` | 8 | `vptr` | Pointer to NUL-terminated animation name string | | ||
| 161 | | `+0x48` | 4 | `u32` | `max_block_size`: maximum `anim_size` across all packed animation blocks | | ||
| 162 | | `+0x50` | 12 | `atArray` | `vptr` (`+0x50`), `u16 block_count`, `u16 block_capacity` (`+0x58`) of `vptr` to packed `crAnimation` blocks | | ||
| 163 | | `+0x60` | 12 | `atArray` | `vptr` (`+0x60`), `u16 track_count`, `u16 track_capacity` (`+0x68`) of 12-byte track directory entries | | ||
| 164 | |||
| 165 | ### 6. Packed `crAnimation` blocks and sorted track directory | ||
| 166 | |||
| 167 | Each pointer in `anim_desc+0x50` targets a packed `crAnimation` block (typically at `virt+0xB0`, | ||
| 168 | though the resource allocator occasionally places the track directory at `virt+0xB0` and the first | ||
| 169 | block after it, or splits long dialogue animations across `2` or `3` blocks): | ||
| 170 | |||
| 171 | ``` | ||
| 172 | +0x00 u32 signature | ||
| 173 | +0x04 u32 payload_size always anim_size - 32 | ||
| 174 | +0x08 u32 reserved 0 | ||
| 175 | +0x0C u32 chunk_data_offset <= payload_size | ||
| 176 | +0x10 u32 anim_size total packed block size in bytes (>= 32) | ||
| 177 | +0x14 u16 format_version always 2 | ||
| 178 | +0x16 u16 frame_count frames in this block | ||
| 179 | +0x18 u32 extra_flags | ||
| 180 | +0x1C u16 sub_count | ||
| 181 | +0x1E u16 track_format_tag always 11 | ||
| 182 | +0x20 ... compressed facial animation bitstream (`payload_size` bytes) | ||
| 183 | ``` | ||
| 184 | |||
| 185 | Multi-block animations share their boundary frame between consecutive blocks, so across `N` blocks: | ||
| 186 | |||
| 187 | ``` | ||
| 188 | total_frames = sum(block.frame_count) - (N - 1) | ||
| 189 | clip_duration = (total_frames - 1) / fps | ||
| 190 | max_block_size = max(block.anim_size) | ||
| 191 | ``` | ||
| 192 | |||
| 193 | The sorted track directory (`anim_desc+0x60`) holds `track_count` (`90` on all `story000`, `minigame`, | ||
| 194 | and `restofworld` clips; `90`, `88`, or `87` on `audio.rpf`) × 12-byte records in ascending | ||
| 195 | (non-decreasing) unsigned `track_id_hash` order: | ||
| 196 | |||
| 197 | ``` | ||
| 198 | +0x00 u32 track_id_hash sorted ascending (non-decreasing) across the directory | ||
| 199 | +0x04 u32 schema_hash constant 0x364D3BDB | ||
| 200 | +0x08 u32 track_type 3 (vector/quaternion-style) or 4 (scalar facial weight) | ||
| 201 | ``` | ||
| 202 | |||
| 203 | ## Full-corpus validation results | ||
| 204 | |||
| 205 | `tools/rsc8_audio.py` validates every resource against 24 structural integrity checks (wrapper size, | ||
| 206 | version, flags, 16-byte alignment, SSO strings, `crProperties`, `crClipAnimation`, `crAnimation` | ||
| 207 | descriptor, all packed `crAnimation` blocks, `max_block_size`, exact frame-to-duration agreement, | ||
| 208 | sorted track directory, and absence of embedded audio containers). | ||
| 209 | |||
| 210 | | Archive | Valid `RSC8` | Invalid `RSC8` | Version `0x00001F41` / `0x01001F41` | `stream_id` match / mismatch | Blocks `1` / `2` / `3` | Dict name heap / inline | Frame range | | ||
| 211 | |---|---:|---:|---:|---:|---:|---:|---:| | ||
| 212 | | `story000_restofworld.rpf` | 9 | 0 | 9 / 0 | 9 / 0 | 9 / 0 / 0 | 9 / 0 | 50–246 | | ||
| 213 | | `shared_minigame000.rpf` | 1,957 | 0 | 1,957 / 0 | 1,957 / 0 | 1,957 / 0 / 0 | 1,638 / 319 | 46–937 | | ||
| 214 | | `story000.rpf` | 225,281 | 0 | 225,281 / 0 | 225,281 / 0 | 225,273 / 8 / 0 | 216,814 / 8,467 | 17–1,706 | | ||
| 215 | | `audio.rpf` | 414,181 | 0 | 413,980 / 201 | 409,881 / 4,300 | 414,151 / 28 / 2 | 377,008 / 37,173 | 11–1,399 | | ||
| 216 | | **Total** | **641,428** | **0** | **641,227 / 201** | **637,128 / 4,300** | **641,390 / 36 / 2** | **595,469 / 45,959** | **11–1,706** | | ||
| 217 | |||
| 218 | *(Note: in `audio.rpf`, 4,300 structurally valid speech clips — 1.04% of `audio.rpf` — assign an | ||
| 219 | internal `RSC8` clip-name hash whose low 29 bits differ from the enclosing AWC `stream_id`; | ||
| 220 | `tools/rsc8_audio.py` reports `stream_id_matches` separately from structural validity. On the full | ||
| 221 | 641,428-clip corpus, all 24 structural checks pass with **0** failures.)* | ||
| 222 | |||
| 223 | ## What remains undecoded | ||
| 224 | |||
| 225 | - Individual facial keyframe curves inside the compressed `crAnimation` bitstream (`block+0x20 .. block+anim_size`, | ||
| 226 | `format_version = 2`, `track_format_tag = 11`). Decoding facial rigs/blendshape evaluation belongs to | ||
| 227 | the animation runtime, not audio extraction. | ||
| 228 | - The semantic difference (if any) of version flag bit 24 (`0x01001F41`) on the 201 `audio.rpf` clips; | ||
| 229 | structurally all 201 parse identically to `0x00001F41`. | ||
| 230 | |||
| 231 | ## Reproduce | ||
| 232 | |||
| 233 | ```powershell | ||
| 234 | # Run synthetic unit tests (stdlib only, no game files needed) | ||
| 235 | python -I tests/test_rsc8_audio.py | ||
| 236 | |||
| 237 | # Validate RSC8 resources in an archive (summary only, zero game strings emitted) | ||
| 238 | python -I tools/rsc8_audio.py <package>\pack\story000_restofworld\story000_restofworld.rpf --summary-only | ||
| 239 | python -I tools/rsc8_audio.py <package>\pack\shared_minigame000\shared_minigame000.rpf --summary-only | ||
| 240 | python -I tools/rsc8_audio.py <package>\pack\story000\story000.rpf --summary-only | ||
| 241 | python -I tools/rsc8_audio.py <package>\audio.rpf --summary-only | ||
| 242 | |||
| 243 | # Optional per-clip structural JSON/CSV export to a local work directory | ||
| 244 | python -I tools/rsc8_audio.py <package>\pack\shared_minigame000\shared_minigame000.rpf <work>\rsc8.csv | ||
| 245 | ``` | ||
| 246 | |||
| 247 | ## No-sharing rule | ||
| 248 | |||
| 249 | Do not commit archives, extracted `.awc` banks, `.rsc8` blobs, Ogg Opus streams, or asset-name dumps. | ||
| 250 | `tools/rsc8_audio.py` never writes game strings or raw payloads; `tests/test_rsc8_audio.py` uses | ||
| 251 | synthesized bytes only. | ||
diff --git a/docs/shader_validation.md b/docs/shader_validation.md index 9da3e5444..f76eb7522 100644 --- a/docs/shader_validation.md +++ b/docs/shader_validation.md | |||
| @@ -314,10 +314,10 @@ every scalar. `vk_compute_test` reads them back with `VKC_OUT_WORDS` / `VKC_DUMP | |||
| 314 | EXEC is modelled as the DPP "invalid source" case (vD kept). That is now measured, with the same result on both: | 314 | EXEC is modelled as the DPP "invalid source" case (vD kept). That is now measured, with the same result on both: |
| 315 | @aslan2142 on RDNA2 and @AlxcBTW on RDNA3.5 (#374). FI = 1 returns the source lane's value, FI = 0 leaves the | 315 | @aslan2142 on RDNA2 and @AlxcBTW on RDNA3.5 (#374). FI = 1 returns the source lane's value, FI = 0 leaves the |
| 316 | destination unwritten and FI = 0 with BOUND_CTRL gives 0; #580 (SHADER-74) makes the translator do that. The | 316 | destination unwritten and FI = 0 with BOUND_CTRL gives 0; #580 (SHADER-74) makes the translator do that. The |
| 317 | fuzzer has not caught up: its docstring (`tools/crosslane_fuzz.py`) still calls the case unmeasured and | 317 | fuzzer's docstring (`tools/crosslane_fuzz.py`, since #750) already says it was measured, but `op_permlane` still |
| 318 | `op_permlane` still tags it `hyp`, so a program that hits it and mismatches is filed as `hyp_only` instead of | 318 | tags the case `hyp` because the translator models it only with #580, so a program that hits it and mismatches |
| 319 | `mismatch`, whatever the translator does (one that matches still counts as `match`). The model (vD kept) | 319 | is filed as `hyp_only` instead of `mismatch` (one that matches still counts as `match`). The model (vD kept) |
| 320 | already matches the measurement; dropping the tag is a follow-up. | 320 | already matches the measurement; dropping the tag once #580 lands is a follow-up. |
| 321 | `--permlane-fetch-inactive` models FI = 1 instead. | 321 | `--permlane-fetch-inactive` models FI = 1 instead. |
| 322 | - **Modes.** Wave32 runs natively. Wave64 runs with `--wave64-emulate`; `--w64-native` adds the plain build, | 322 | - **Modes.** Wave32 runs natively. Wave64 runs with `--wave64-emulate`; `--w64-native` adds the plain build, |
| 323 | which on a 32-wide subgroup is the documented cross-half approximation and is expected to mismatch. | 323 | which on a 32-wide subgroup is the documented cross-half approximation and is expected to mismatch. |
diff --git a/docs/testing.md b/docs/testing.md index 9cfd45051..b94beb9fe 100644 --- a/docs/testing.md +++ b/docs/testing.md | |||
| @@ -111,6 +111,13 @@ With more than one GPU, pick one through the Vulkan loader, for example | |||
| 111 | `VK_LOADER_DRIVERS_SELECT=*amd*` or `VK_LOADER_DRIVERS_SELECT=nv-vk*` (or `VK_DRIVER_FILES=<path to the ICD json>`). | 111 | `VK_LOADER_DRIVERS_SELECT=*amd*` or `VK_LOADER_DRIVERS_SELECT=nv-vk*` (or `VK_DRIVER_FILES=<path to the ICD json>`). |
| 112 | `vulkaninfo --summary` shows which devices the loader then sees. | 112 | `vulkaninfo --summary` shows which devices the loader then sees. |
| 113 | 113 | ||
| 114 | Two GPUs of one vendor share one driver, so the loader cannot tell them apart (an RTX 5070 Ti next to an RTX 3060, | ||
| 115 | say; without a choice the D3D12 tests take the last discrete GPU). `LEONIDA_VK_DEVICE` names the GPU by part of its | ||
| 116 | name, without case: `LEONIDA_VK_DEVICE=5070` or `LEONIDA_VK_DEVICE=radeon`. The D3D12 tests (`vk_test_device.h`) | ||
| 117 | and the layer's standalone device read it, and a value that matches no device fails the run instead of testing | ||
| 118 | another GPU. For the host side of the comparison tests, `LEONIDA_HOST_ADAPTER` picks the D3D12 adapter the same way. | ||
| 119 | The GPU tools of `runtime/test/shaders` (`vk_compute_test`, `vk_harness`, ...) do not read it yet. | ||
| 120 | |||
| 114 | ## Known problems | 121 | ## Known problems |
| 115 | 122 | ||
| 116 | | What you see | Cause | What to do | | 123 | | What you see | Cause | What to do | |