diff --git a/docs/design.md b/docs/design.md index daeb4eb425..bd92153630 100644 --- a/docs/design.md +++ b/docs/design.md @@ -284,6 +284,7 @@ How the generated SPIR-V expects the runtime to work: | Piece | Contract | |---|---| | Heap-relative buffer device addresses | `Gen.host_addr` sign-extends the low 48 bits of the effective VA after adding any byte offset, then adds `%heap_base`. The runtime stores `device_address - heap_base` in a V#'s 48-bit base field. NVIDIA's Windows driver can place an imported buffer below the heap, so that offset is negative. Zero extension made the resulting device address too high by `2^48`. Console user-mode VAs below `2^47` and full-width root descriptor addresses already within the signed 48-bit range retain their values. A 64-bit base-plus-offset sum gives the correct address for effective VAs in that range, including when the sum crosses zero. Each new shader's `index.json` entry carries `"vsharp_base_sign_extended": true`. Check the field on all loaded entries before enabling below-arena imports for a library, because older modules can share an index with newly translated ones. `tests/semantic/test_vsharp_sext48.py` checks the emitted shifts, both reads against synthetic memory, and the metadata field. | +| SPIR-V compaction | The optional `--compact-spirv` pass runs after assembly and before the requested validation. It asks `spirv-opt` to preserve stage interfaces, descriptor bindings and specialization constants. `tests/test_native_tool_paths.py` checks that a synthetic compute module with dead arithmetic shrinks and passes Vulkan 1.2 validation. | | Null sources in 64-bit integer VALU compares | `v_cmp` and `v_cmpx` relations `eq`, `ne`, `lt`, `le`, `gt`, `ge` on `u64` and `i64` read `null` as the 64-bit value 0 in either source, like immediate `0`. Register pairs and immediates retain their existing semantics; `v_cmp` writes the active lane's comparison to VCC/SGPR, while `v_cmpx` narrows EXEC without changing VCC. Source: RDNA2 ISA special operand `null` reads zero; LLVM `llvm-mc -mcpu=gfx1013` accepts the encoding. CPU-checked by `tests/semantic/test_vcmp64_null_src.py` (both sources, signed/unsigned ordering, equality, e32/e64, EXEC and inactive lanes); **not GPU-verified, no corpus count**. | | `s_load_dword*` with `vcc` 64-bit base pointer | SMEM `s_load_dword*` accepts `vcc` (`{vcc_lo, vcc_hi}`, hardware `s[106:107]`) as its 64-bit base pointer in `Gen.scalar_load`, loading `%vcc` as the low dword and `%vcc_hi` as the high dword; `s_buffer_load*` still requires a 4-dword V# and rejects 2-dword `vcc`. Source: RDNA2 ISA SMEM `SBASE` encoding (`sbase = 53` -> `s[106:107] = vcc`). Confirmed by corpus count over the 2,684-shader pipeline library compute corpus (79 shaders use `vcc` as the `s_load` base: 72 `s_load_dwordx4 sgpr, vcc`, 6 `s_load_dwordx8 sgpr, vcc`, 1 `s_load_dwordx4 slist, vcc`; all 79 translate and pass `spirv-val` under `--wave64-emulate`) and CPU-checked by `tests/semantic/test_sload_vcc_base.py` (`spirv-as` + `spirv-val`) and `tests/semantic/test_scalar_mem_smem.py` (both halves and the resulting addresses); **not GPU-verified**: the synthetic `runtime/test/shaders/cs_smem_vcc_base.asm` reads back eight seeded words through the pair in the standard GPU runner. | | Execution model | One invocation = one lane. Compute and mesh waves derive lanes from the workgroup-local index; other stages use the subgroup lane. A wave = a subgroup, so cross-lane ops (`ds_swizzle`, `v_permlane*`, `v_readlane`/`v_writelane`, `v_mbcnt`) become subgroup shuffles. Wave32 pixel shaders split a 64-lane physical subgroup into two logical waves: lane IDs are `SubgroupLocalInvocationId & 31`, shuffle sources retain the current half (`& 32`), and ballots/votes use that half's 32-bit word. A value the translator knows is uniform (the bindless descriptor index) is read from the half's first running lane, never from a fixed lane, which need not be running (SHADER-1016). Other stage/wave combinations still require subgroup size == wave size or wave64 emulation. **Requires subgroup size == wave size** (wave32 maps directly onto NVIDIA GPUs; wave64 shaders need a 64-wide subgroup or emulation). `v_readlane_b32`/`v_writelane_b32` mask the lane select with 63 in wave64 (`S1[5:0]`) and 31 in wave32 (`S1[4:0]`); until SHADER-52 both used 63, so a wave32 select ≥ 32 pointed past a 32-wide subgroup. GPU-checked with `cs_w32_lane_wrap.asm` (lane 40 → 8). For the fragment-half rule, `ps_bitmask_perm` produced 4096/4096 exact pixels on an AMD Radeon RX 5700 XT; Vulkan reported a default subgroup size of 64 (range 32..64), but does not permit pinning fragment subgroup size on this device. CPU semantic tests compare a 64-lane wave32 pixel subgroup against two 32-lane subgroups for reads/writes, permutations, ballots, and votes. | diff --git a/tests/test_make_game_translator_flags.py b/tests/test_make_game_translator_flags.py index ffae8710d9..668deb79bd 100644 --- a/tests/test_make_game_translator_flags.py +++ b/tests/test_make_game_translator_flags.py @@ -217,6 +217,9 @@ def test_the_flags_reach_the_shaders_stage(self): self.assertEqual(pre, ("--no-float-controls", "--bary-fallback", "--mesh-compute")) self.assertEqual(sh, pre) + def test_compact_spirv_reaches_the_shaders_stage(self): + self.assertEqual(self.run_main("--compact-spirv"), (("--compact-spirv",),) * 2) + def test_no_flags_by_default(self): pre, sh = self.run_main() self.assertEqual(pre, ())