xshader: use 3-bank ballots and double-buffered reads in page_waves #555

Merged
glovepost merged 1 commit from upstream-pr/555 into main 2026-12-01 15:05:00 +00:00
glovepost commented 2026-11-29 23:07:21 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by glovepost on 2026-11-29T23:07:21Z.


Split out from #523 per review. Adds LDS-budget-aware 3-bank page_bits ballots and double-buffered page_lane_values reads in page_waves so tb_page_ballot and tb_page_read drop their pre-clear / post-read barriers when static groupshared usage leaves room under the 32 KiB D3D12 limit.

Changes

  • tools/shader-compiler/src/hlsl.rs: add groupshared_bytes to statically size declared groupshared arrays (#define bounds and expressions included, returning None if dynamic/unknown).
  • tools/shader-compiler/src/hlsl/page_waves.rs: switch declarations(group, branchless, existing_lds) to 3-bank page_bits and double-buffered page_lane_values with tb_page_init(tid) initial zeroing when the existing groupshared footprint fits within 32 KiB, falling back to single-buffer / legacy form otherwise.
  • tools/shader-compiler/src/hlsl/fspx_wave.rs, driver/pipeline.rs, mesh.rs, emitter/output.rs: compute existing_lds and emit tb_page_init(tb_wave_tid);.
  • tools/shader-compiler/src/tests/hlsl/page_waves.rs: test groupshared_bytes and validate roomy, 128-thread mesh, branchless, single-read, and full-LDS fallback forms with DXC + DXV.

Verification

  • python3 tuxbox.py check --no-gpu passed 9/9 checks:
    • Python tests: 739 run, 1 skipped, 0 failed
    • Shader compiler tests: 650 + 3 + 2 passed (host_profiles unchanged)
    • DXBC tests: 120 passed
    • XG layout tests: 24 passed, 1 ignored; XG entry point tests: 7 passed
    • Storage codec tests: 22 passed
    • ACP HAL tests: 9 passed
    • D3D12 Windows typecheck: passed
  • Tested against 258 recorded ProjectScarlett shader requests using runtime DXC 1.9 (1.9.2609.5) flags (-disable-lifetime-markers -fnew-inlining-behavior, plus -O1 for cs_6_6): 213/213 translated shaders compiled with 0 DXC segfaults (45 unsupported by xshader, identical to origin/main).
  • tools/stage_baseline.py cpu across the 58 locally recorded tools/reference/stage-baseline/sample.json requests (89 translations):
    • 89/89 compiled (0 regressions), 83/89 byte-identical DXIL.
    • On the 6 changed translations: HLSL bytes +0.074% (2,073,746 -> 2,075,276), DXIL bytes +0.827% (822,464 -> 829,268). (DXC wall-clock runtime rose across the 83 identical shaders alike during the back-to-back run, so no standalone DXC compile-time claim is made.)
  • GPU tests (tuxbox.py check) and ProjectScarlett were not run against this split branch.

AI-assisted: split, rebased, and tested with LLM tooling.

<!-- greyfinch-sync:brcly/TuxBox:issue:5556141725 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/555). Originally posted by [glovepost](https://github.com/glovepost) on 2026-11-29T23:07:21Z. --- Split out from #523 per review. Adds LDS-budget-aware 3-bank `page_bits` ballots and double-buffered `page_lane_values` reads in `page_waves` so `tb_page_ballot` and `tb_page_read` drop their pre-clear / post-read barriers when static `groupshared` usage leaves room under the 32 KiB D3D12 limit. ### Changes - `tools/shader-compiler/src/hlsl.rs`: add `groupshared_bytes` to statically size declared `groupshared` arrays (`#define` bounds and expressions included, returning `None` if dynamic/unknown). - `tools/shader-compiler/src/hlsl/page_waves.rs`: switch `declarations(group, branchless, existing_lds)` to 3-bank `page_bits` and double-buffered `page_lane_values` with `tb_page_init(tid)` initial zeroing when the existing `groupshared` footprint fits within 32 KiB, falling back to single-buffer / legacy form otherwise. - `tools/shader-compiler/src/hlsl/fspx_wave.rs`, `driver/pipeline.rs`, `mesh.rs`, `emitter/output.rs`: compute `existing_lds` and emit `tb_page_init(tb_wave_tid);`. - `tools/shader-compiler/src/tests/hlsl/page_waves.rs`: test `groupshared_bytes` and validate roomy, 128-thread mesh, branchless, single-read, and full-LDS fallback forms with DXC + DXV. ### Verification - `python3 tuxbox.py check --no-gpu` passed 9/9 checks: - Python tests: 739 run, 1 skipped, 0 failed - Shader compiler tests: 650 + 3 + 2 passed (`host_profiles` unchanged) - DXBC tests: 120 passed - XG layout tests: 24 passed, 1 ignored; XG entry point tests: 7 passed - Storage codec tests: 22 passed - ACP HAL tests: 9 passed - D3D12 Windows typecheck: passed - Tested against 258 recorded ProjectScarlett shader requests using runtime DXC 1.9 (`1.9.2609.5`) flags (`-disable-lifetime-markers -fnew-inlining-behavior`, plus `-O1` for `cs_6_6`): `213/213` translated shaders compiled with **0 DXC segfaults** (`45` unsupported by `xshader`, identical to `origin/main`). - `tools/stage_baseline.py cpu` across the 58 locally recorded `tools/reference/stage-baseline/sample.json` requests (`89` translations): - `89/89` compiled (`0` regressions), `83/89` byte-identical DXIL. - On the `6` changed translations: HLSL bytes `+0.074%` (`2,073,746 -> 2,075,276`), DXIL bytes `+0.827%` (`822,464 -> 829,268`). (DXC wall-clock runtime rose across the `83` identical shaders alike during the back-to-back run, so no standalone DXC compile-time claim is made.) - GPU tests (`tuxbox.py check`) and ProjectScarlett were not run against this split branch. AI-assisted: split, rebased, and tested with LLM tooling.
glovepost commented 2026-11-30 00:50:21 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by glovepost on 2026-11-30T00:50:21Z.


Rebased onto main (f482572a, commit 0e531c563eb4) with no functional changes from c25f3735, and ran the changed GPU checks on NVIDIA:

  • Command: TUXBOX_CHECK_JOBS=2 DXC=<dxc> python3 tuxbox.py check --changed --adapter 10de:1e84 --proton <proton> --prefix <prefix> --windows-dxc <windows-dxc>
  • GPU / driver / backend: NVIDIA GeForce RTX 2070 SUPER (10de:1e84), driver 620.73.04, GE-Proton11-14
  • Results: Lanes and fixtures on the GPU (lanes-bindless-compute, lanes-compute-root, lanes-compute-root-recovery, lanes-raster-tables, lanes-shader-cache) and Shader translator on the GPU all passed (13 passed, 0 failed, 0 not run).
  • Still missing: AMD GPU checks. ProjectScarlett was not run on this commit.

Evidence: TuxBox check of 0e531c563eb4, no uncommitted changes, GPU 10de:1e84: 13 passed, 0 failed, 0 not run

<!-- greyfinch-sync:brcly/TuxBox:comment:7265620419 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/555#issuecomment-7265620419). Originally posted by [glovepost](https://github.com/glovepost) on 2026-11-30T00:50:21Z. --- Rebased onto `main` (`f482572a`, commit `0e531c563eb4`) with no functional changes from `c25f3735`, and ran the changed GPU checks on NVIDIA: - **Command:** `TUXBOX_CHECK_JOBS=2 DXC=<dxc> python3 tuxbox.py check --changed --adapter 10de:1e84 --proton <proton> --prefix <prefix> --windows-dxc <windows-dxc>` - **GPU / driver / backend:** NVIDIA GeForce RTX 2070 SUPER (`10de:1e84`), driver `620.73.04`, `GE-Proton11-14` - **Results:** `Lanes and fixtures on the GPU` (`lanes-bindless-compute`, `lanes-compute-root`, `lanes-compute-root-recovery`, `lanes-raster-tables`, `lanes-shader-cache`) and `Shader translator on the GPU` all passed (**13 passed, 0 failed, 0 not run**). - **Still missing:** AMD GPU checks. ProjectScarlett was not run on this commit. `Evidence: TuxBox check of 0e531c563eb4, no uncommitted changes, GPU 10de:1e84: 13 passed, 0 failed, 0 not run`
NickStallman commented 2026-11-30 01:26:54 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-30T01:26:54Z.


The AMD check you were missing, on 0e531c56: AMD iGPU (1002:13c0, RADV, Mesa 26.0.8, GE-Proton11-14, Linux), full python tuxbox.py check: 199 pass, 0 fail. A game was loading on the other card for part of it. ProjectScarlett was not run on this commit.

Evidence: TuxBox check of 0e531c563e, no uncommitted changes, GPU 1002:13c0: 14 passed, 0 failed, 0 not run

<!-- greyfinch-sync:brcly/TuxBox:comment:7266144218 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/555#issuecomment-7266144218). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-30T01:26:54Z. --- The AMD check you were missing, on 0e531c56: AMD iGPU (`1002:13c0`, RADV, Mesa 26.0.8, GE-Proton11-14, Linux), full `python tuxbox.py check`: 199 pass, 0 fail. A game was loading on the other card for part of it. ProjectScarlett was not run on this commit. Evidence: TuxBox check of 0e531c563eb4, no uncommitted changes, GPU 1002:13c0: 14 passed, 0 failed, 0 not run
Claudineijoseprill commented 2026-11-30 03:35:41 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by Claudineijoseprill on 2026-11-30T03:35:41Z.


AMD discrete RDNA 1 run, on 0e531c56: Radeon RX 5700 XT (1002:731f, RADV, Mesa 25.2.8, GE-Proton11-14, Ubuntu 24.04), python tuxbox.py check --changed with --proton, --prefix and --windows-dxc: 101 pass, 9 fail.

Every gate matches a full check of unchanged main (f482572a) on the same machine; no regressions. The 9 failures are features this card or driver lacks and fail the same on main: 5 lanes-mesh-* and translated-mesh (no mesh shaders), bvh64-query and bvh32-query (no ray tracing), and pixel-interp (flat and half fail with pipeline E_INVALIDARG; RADV doesn't expose VK_KHR_fragment_shader_barycentric on this card).

Not run: a game.

Evidence: TuxBox check of 0e531c563e, no uncommitted changes, GPU default adapter: 11 passed, 2 failed, 0 not run

One note on the new test in src/tests/hlsl/page_waves.rs: it looks for dxc and dxv only at $HOME/.local/bin and returns early otherwise, so on machines that keep them elsewhere (e.g. on PATH from a distro or the devcontainer) it passes without compiling anything. Here they happen to be at that path, so it ran and passed. Resolving them from PATH (or DXC) would keep it from silently skipping.

<!-- greyfinch-sync:brcly/TuxBox:comment:7268026514 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/555#issuecomment-7268026514). Originally posted by [Claudineijoseprill](https://github.com/Claudineijoseprill) on 2026-11-30T03:35:41Z. --- AMD discrete RDNA 1 run, on 0e531c56: Radeon RX 5700 XT (`1002:731f`, RADV, Mesa 25.2.8, GE-Proton11-14, Ubuntu 24.04), `python tuxbox.py check --changed` with `--proton`, `--prefix` and `--windows-dxc`: 101 pass, 9 fail. Every gate matches a full check of unchanged `main` (f482572a) on the same machine; no regressions. The 9 failures are features this card or driver lacks and fail the same on `main`: 5 `lanes-mesh-*` and `translated-mesh` (no mesh shaders), `bvh64-query` and `bvh32-query` (no ray tracing), and `pixel-interp` (`flat` and `half` fail with pipeline `E_INVALIDARG`; RADV doesn't expose `VK_KHR_fragment_shader_barycentric` on this card). Not run: a game. Evidence: TuxBox check of 0e531c563eb4, no uncommitted changes, GPU default adapter: 11 passed, 2 failed, 0 not run One note on the new test in `src/tests/hlsl/page_waves.rs`: it looks for `dxc` and `dxv` only at `$HOME/.local/bin` and returns early otherwise, so on machines that keep them elsewhere (e.g. on `PATH` from a distro or the devcontainer) it passes without compiling anything. Here they happen to be at that path, so it ran and passed. Resolving them from `PATH` (or `DXC`) would keep it from silently skipping.
brcly commented 2026-11-30 04:12:11 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-30T04:12:11Z.


Heads-up: main just landed a large cleanup (up to e5d2e913), so this PR needs a rebase.

  • Formatting: the whole workspace is now formatted with rustfmt (see the new rustfmt.toml).
  • Lints: every crate denies unwrap(), lossy as casts and undocumented unsafe outside tests.
  • CI: it now also runs cargo fmt --check, rustdoc with warnings denied, and Miri on the providers' unit tests.

The least painful way is to format your branch first, so the rebase only shows real changes:

git fetch origin
git checkout origin/main -- rustfmt.toml
cargo fmt --all && git commit -am "rustfmt"
git rebase origin/main

Then run python tuxbox.py check --no-gpu, which now includes the format step.

If clippy flags something new:

  • A cast: use From for widening, TryFrom for narrowing, and a mask for bit fields.
  • An unwrap(): use ?, or expect with the reason it can't fail.
  • An unsafe block: it needs a // SAFETY: comment.

CONTRIBUTING's "Code checks" section lists the commands. Thanks!

<!-- greyfinch-sync:brcly/TuxBox:comment:7268560147 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/555#issuecomment-7268560147). Originally posted by [brcly](https://github.com/brcly) on 2026-11-30T04:12:11Z. --- Heads-up: main just landed a large cleanup (up to e5d2e913), so this PR needs a rebase. - **Formatting:** the whole workspace is now formatted with rustfmt (see the new `rustfmt.toml`). - **Lints:** every crate denies `unwrap()`, lossy `as` casts and undocumented `unsafe` outside tests. - **CI:** it now also runs `cargo fmt --check`, rustdoc with warnings denied, and Miri on the providers' unit tests. The least painful way is to format your branch first, so the rebase only shows real changes: ```sh git fetch origin git checkout origin/main -- rustfmt.toml cargo fmt --all && git commit -am "rustfmt" git rebase origin/main ``` Then run `python tuxbox.py check --no-gpu`, which now includes the format step. If clippy flags something new: - **A cast:** use `From` for widening, `TryFrom` for narrowing, and a mask for bit fields. - **An `unwrap()`:** use `?`, or `expect` with the reason it can't fail. - **An `unsafe` block:** it needs a `// SAFETY:` comment. CONTRIBUTING's "Code checks" section lists the commands. Thanks!
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
brcly/TuxBox!555
No description provided.