ProjectScarlett start menu: compute roots, faster compiles, watchdog pause #216

Open
github-bot wants to merge 12 commits from github-bot/gh-216 into main AGit
Owner

@⁠bbijsterbosch on GitHub · 2026-11-26 08:50 UTC · original
bbijsterbosch:projectscarlett/start-menu → main · +1667 −103 · 57 files · 12 commits · draft

Summary

With this branch, ProjectScarlett 1.0.2.1 boots to its start menu on an NVIDIA laptop GPU under GE-Proton11-14. When the menu was up, no stand-in pipeline was bound (null usage … compute=0 raster=0).

Stand-ins remain during boot. 288 distinct stages had no translation (207 compute, 45 pixel, 32 mesh, 4 vertex). With the default 20 s deadline, many large compute pipelines also returned a stand-in while their driver compile went on.

The run used these twelve commits on ac4f099. They are now rebased onto main (773278a) without conflicts. Each commit builds on its own and passes the translator tests. The only addition to the build that ran is a one-line test fix (a missing strides field in an inline-arena test initializer).

Translator (xshader)

Commit Change
lower long jumps and waterfall lane reads A s_getpc/s_add_u32/s_addc_u32/s_setpc long jump with a provable target becomes a branch. A waterfall loop that gives each lane the value of the lane it names becomes a single group gather through the compute swizzle exchange.
lower DPP16 row-shift prefix sums The wave32 compaction scan (four row_shr adds, v_permlanex16, upper-row add) becomes WavePrefixSum. A select-then-copy into the accumulator is first merged into one select.
follow SCC through packed-root pointer masks SCC provenance is a 107th state word: s_cselect/s_addc/s_subb are accepted when SCC came from plain data.
take root table SGPRs from FSSM user-data records A user-data record that names a table pointer's SGPR overrides the per-stage default.
keep unproved uniform loops in the full-mask mode Structured loops with wave-uniform scalars translate and keep the emitter's watchdog. VCC is accepted as an SMEM offset.
or jump flags together in compute programs Compute guards use | and j = j | (c). The resolve kernels' unoptimised DXIL has a third fewer blocks, and DXC optimises them in 45 s instead of 83–110 s.
refuse translations beyond DXC's memory budget HLSL above 8 MiB is refused. Two 10 MB programs had taken 11 GB of DXC memory each.
read heap buffer strides from the runtime's table With root SRV t1, space32766 in the root, heap-loaded buffer descriptors get word 1 (the stride) from the runtime, so heap-indexed IDXEN accesses translate.

Runtime (d3d12, dxbc)

  • Compute programs bound to the root the title pairs them with:
    • Roots with more than two tables, or with root descriptors and constants after the tables, are accepted when the user data confirms every binding.
    • A pipeline root replaces an embedded RTS0.
    • Literal samplers that a root without flag 0x800 lacks become private statics. A root that reflection cannot describe gets a samplers-only extension, bound around each dispatch.
    • Paged heaps keep a per-slot buffer stride table, from view creation and descriptor copies. A program refused only for want of strides is retried with that table appended as a root SRV, and each dispatch binds it.
    • A rejected raster stream records its guest root and stages under the existing capture variables.
  • clzero: ProjectScarlett's hot clearing routine (RVA 0x4E8AA10) gets AVX stores in place of five clzero loops. On hosts without CLZERO, every call used to trap five times, about four million exceptions in half an hour.
  • Hang watchdog: ProjectScarlett's watchdog is paused while a title thread waits on a translation or a driver compile. It used to crash the title after long waits.

Both title patches write nothing unless the code matches 1.0.2.1 byte for byte. TUXBOX_KEEP_TITLE_WATCHDOG=1 keeps the watchdog.

Launcher

  • The -O0 compile cap scales with the HLSL size: 90 s per MB, between 90 and 600 s. The 2.5 MB resolve kernels used to time out on every boot.
  • Game runs set VKD3D_SHADER_DEBUG=err, so DXIL conversion failures name the construct the shader compiler rejected.

Host-profile record

host_profiles.txt changes for the saveexec and empty programs on every profile. Their jump-flag guards are now joined with | (commit "or jump flags together in compute programs"). Nothing else in the record changes.

Verified on Lanes

A pull request is not merged until Lanes passes on a GPU. Run:

python tuxbox.py check
  • python tuxbox.py check passed on this branch. Not yet. The first run shared its prefix with a running ProjectScarlett session, and every guest launch timed out after 15 s before it started. It will be rerun with the game closed, and the summary added here.
  • Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below.
    • The clzero and watchdog patches match ProjectScarlett 1.0.2.1 code bytes and change nothing elsewhere, so Lanes cannot exercise them. Their unit tests check the byte matching.
    • The translator lowerings have unit tests built from the ProjectScarlett instruction sequences. They are not yet in check_translator_gpu.py.
    • The runtime root and stride binding could be covered by a Lanes scenario, but none has been added yet.

GPU, driver and backend: NVIDIA RTX 3000 Ada Generation Laptop GPU (10de:2838, host profile wave 32-32), driver 620.73.04, Proton backend with GE-Proton11-14 (vkd3d-proton v3.1-83-gcae8353ed), Linux 7.3.5.

  • This changes code both vendors run, and the check passed on an AMD and an NVIDIA card (why). Otherwise, say which vendor still needs to run it: AMD still needs to run it. NVIDIA has only the ProjectScarlett run below so far.

Paste the summary printed at the end:

(pending: rerun of python tuxbox.py check)

ProjectScarlett 1.0.2.1 with this build at its start menu, from the game log:

TuxBox d3d12_xs: host profile: adapter=10de:2838 wave=32-32 section-import=aliased descriptor-bytes=32/32
TuxBox d3d12_xs: replaced clzero loops at RVA 0x4e8aa10 with AVX stores (host lacks CLZERO)
TuxBox d3d12_xs: pausing the title's hang watchdog (RVA 0x71b6330) while shaders compile
TuxBox d3d12_xs: translated a compute shader with the heap stride table
TuxBox d3d12_xs: null usage interval recorded=0 display_bound=0 tracked=0 overflow=0 overflow_display_bound=0 compute=0 raster=0 interval=279 trigger=present_sample
TuxBox d3d12_xs: presented 124 frames in 10s, 142055 in total

Checks

CI runs the Python unit tests, the shader compiler, DXBC, and XG layout tests, and a Windows typecheck of tuxbox-d3d12.

These ran locally on the rebased tip, as in CI:

Check Result
python -m unittest discover -s tests -q 371 tests, OK (18 skipped)
cargo test … tools/shader-compiler 334 passed; before the rebase, it also passed at every translator commit
cargo test -p tuxbox-dxbc --features native-bindings 66 passed
cargo test -p tuxbox-xg-layout 14 passed
cargo check --target x86_64-pc-windows-msvc -p tuxbox-d3d12 clean, also with --tests, here and at every runtime commit before the rebase

No evidence JSON changes.

🤖 Generated with Claude Code

**@⁠bbijsterbosch** on GitHub · 2026-11-26 08:50 UTC · [original](https://github.com/brcly/TuxBox/pull/216) `bbijsterbosch:projectscarlett/start-menu` → `main` · +1667 −103 · 57 files · 12 commits · draft ## Summary With this branch, ProjectScarlett 1.0.2.1 boots to its start menu on an NVIDIA laptop GPU under GE-Proton11-14. When the menu was up, no stand-in pipeline was bound (`null usage … compute=0 raster=0`). Stand-ins remain during boot. 288 distinct stages had no translation (207 compute, 45 pixel, 32 mesh, 4 vertex). With the default 20 s deadline, many large compute pipelines also returned a stand-in while their driver compile went on. The run used these twelve commits on `ac4f099`. They are now rebased onto `main` (`773278a`) without conflicts. Each commit builds on its own and passes the translator tests. The only addition to the build that ran is a one-line test fix (a missing `strides` field in an inline-arena test initializer). ### Translator (`xshader`) | Commit | Change | | --- | --- | | lower long jumps and waterfall lane reads | A `s_getpc`/`s_add_u32`/`s_addc_u32`/`s_setpc` long jump with a provable target becomes a branch. A waterfall loop that gives each lane the value of the lane it names becomes a single group gather through the compute swizzle exchange. | | lower DPP16 row-shift prefix sums | The wave32 compaction scan (four `row_shr` adds, `v_permlanex16`, upper-row add) becomes `WavePrefixSum`. A select-then-copy into the accumulator is first merged into one select. | | follow SCC through packed-root pointer masks | SCC provenance is a 107th state word: `s_cselect`/`s_addc`/`s_subb` are accepted when SCC came from plain data. | | take root table SGPRs from FSSM user-data records | A user-data record that names a table pointer's SGPR overrides the per-stage default. | | keep unproved uniform loops in the full-mask mode | Structured loops with wave-uniform scalars translate and keep the emitter's watchdog. VCC is accepted as an SMEM offset. | | or jump flags together in compute programs | Compute guards use `\|` and `j = j \| (c)`. The resolve kernels' unoptimised DXIL has a third fewer blocks, and DXC optimises them in 45 s instead of 83–110 s. | | refuse translations beyond DXC's memory budget | HLSL above 8 MiB is refused. Two 10 MB programs had taken 11 GB of DXC memory each. | | read heap buffer strides from the runtime's table | With root SRV `t1, space32766` in the root, heap-loaded buffer descriptors get word 1 (the stride) from the runtime, so heap-indexed IDXEN accesses translate. | ### Runtime (`d3d12`, `dxbc`) - **Compute programs bound to the root the title pairs them with:** - Roots with more than two tables, or with root descriptors and constants after the tables, are accepted when the user data confirms every binding. - A pipeline root replaces an embedded RTS0. - Literal samplers that a root without flag 0x800 lacks become private statics. A root that reflection cannot describe gets a samplers-only extension, bound around each dispatch. - Paged heaps keep a per-slot buffer stride table, from view creation and descriptor copies. A program refused only for want of strides is retried with that table appended as a root SRV, and each dispatch binds it. - A rejected raster stream records its guest root and stages under the existing capture variables. - **clzero:** ProjectScarlett's hot clearing routine (RVA 0x4E8AA10) gets AVX stores in place of five `clzero` loops. On hosts without CLZERO, every call used to trap five times, about four million exceptions in half an hour. - **Hang watchdog:** ProjectScarlett's watchdog is paused while a title thread waits on a translation or a driver compile. It used to crash the title after long waits. Both title patches write nothing unless the code matches 1.0.2.1 byte for byte. `TUXBOX_KEEP_TITLE_WATCHDOG=1` keeps the watchdog. ### Launcher - The -O0 compile cap scales with the HLSL size: 90 s per MB, between 90 and 600 s. The 2.5 MB resolve kernels used to time out on every boot. - Game runs set `VKD3D_SHADER_DEBUG=err`, so DXIL conversion failures name the construct the shader compiler rejected. ### Host-profile record `host_profiles.txt` changes for the `saveexec` and `empty` programs on every profile. Their jump-flag guards are now joined with `|` (commit "or jump flags together in compute programs"). Nothing else in the record changes. ## Verified on Lanes A pull request is not merged until Lanes passes on a GPU. Run: ```sh python tuxbox.py check ``` - [ ] `python tuxbox.py check` passed on this branch. **Not yet.** The first run shared its prefix with a running ProjectScarlett session, and every guest launch timed out after 15 s before it started. It will be rerun with the game closed, and the summary added here. - [ ] Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below. - The clzero and watchdog patches match ProjectScarlett 1.0.2.1 code bytes and change nothing elsewhere, so Lanes cannot exercise them. Their unit tests check the byte matching. - The translator lowerings have unit tests built from the ProjectScarlett instruction sequences. They are not yet in `check_translator_gpu.py`. - The runtime root and stride binding could be covered by a Lanes scenario, but none has been added yet. GPU, driver and backend: NVIDIA RTX 3000 Ada Generation Laptop GPU (10de:2838, host profile wave 32-32), driver 620.73.04, Proton backend with GE-Proton11-14 (vkd3d-proton v3.1-83-gcae8353ed), Linux 7.3.5. - [ ] This changes code both vendors run, and the check passed on an AMD and an NVIDIA card ([why](../CONTRIBUTING.md#amd-and-nvidia)). Otherwise, say which vendor still needs to run it: **AMD still needs to run it. NVIDIA has only the ProjectScarlett run below so far.** Paste the summary printed at the end: ```text (pending: rerun of python tuxbox.py check) ``` ProjectScarlett 1.0.2.1 with this build at its start menu, from the game log: ```text TuxBox d3d12_xs: host profile: adapter=10de:2838 wave=32-32 section-import=aliased descriptor-bytes=32/32 TuxBox d3d12_xs: replaced clzero loops at RVA 0x4e8aa10 with AVX stores (host lacks CLZERO) TuxBox d3d12_xs: pausing the title's hang watchdog (RVA 0x71b6330) while shaders compile TuxBox d3d12_xs: translated a compute shader with the heap stride table TuxBox d3d12_xs: null usage interval recorded=0 display_bound=0 tracked=0 overflow=0 overflow_display_bound=0 compute=0 raster=0 interval=279 trigger=present_sample TuxBox d3d12_xs: presented 124 frames in 10s, 142055 in total ``` ## Checks CI runs the Python unit tests, the shader compiler, DXBC, and XG layout tests, and a Windows typecheck of `tuxbox-d3d12`. These ran locally on the rebased tip, as in CI: | Check | Result | | --- | --- | | `python -m unittest discover -s tests -q` | 371 tests, OK (18 skipped) | | `cargo test … tools/shader-compiler` | 334 passed; before the rebase, it also passed at every translator commit | | `cargo test -p tuxbox-dxbc --features native-bindings` | 66 passed | | `cargo test -p tuxbox-xg-layout` | 14 passed | | `cargo check --target x86_64-pc-windows-msvc -p tuxbox-d3d12` | clean, also with `--tests`, here and at every runtime commit before the rebase | No evidence JSON changes. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
ProjectScarlett's compute programs reach code beyond a short jump with
s_getpc_b64, s_add_u32 lo, s_addc_u32 hi (0 or -1) and s_setpc_b64. With a
constant offset that lands on an instruction, and no branch into the
sequence, it becomes a branch like the existing two-instruction form. A
sequence that cannot be proven stays indirect.

A waterfall loop (v_readfirstlane, v_cmpx_eq, v_readlane and v_mov,
s_andn2_wrexec, s_cbranch_execnz) gives every lane the value held by the
lane its own VGPR names. When the loop has exactly that shape and the
scalars it leaves behind are dead, it is lowered to one group gather:
every lane publishes its value through the compute swizzle exchange and
reads the lane it names within its 64-lane block. Two more ProjectScarlett
programs translate.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ProjectScarlett's compaction kernels build an inclusive wave32 prefix sum
from four row_shr adds, a v_permlanex16_b32 that carries lane 15 of the
other row, and an add under the upper-row EXEC, after a SAVEEXEC that
enables every lane. That sequence becomes one WavePrefixSum, with the
permute's register given the lower row's total as before.

Some of these reductions first select into a spare register and copy it
to the accumulator. The copy is now the same select into the accumulator,
so the reduction starts from the form the matcher knows, and the spare
register keeps its value.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The packed-root analysis refused any s_cselect_b32, s_addc_u32 or
s_subb_u32 because SCC might carry bits of a root address. It now tracks
where SCC came from as a 107th state word: a consumer is admitted when the
last SCC writer on every path read plain data, and still refused when it
read part of a pointer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Root tables were assumed to arrive in consecutive user SGPRs from a fixed
start per stage. The FSSM user-data records name the parameter of each
table pointer and its SGPR, so where a record names the SGPR it decides.
A vertex program that starts with s_swappc_b64 s4, s4 (4b929a1c), for
one, still receives its tables in s8 and s9.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
In the whole-wave mode a program without a termination proof was refused
unless its loops went through the block dispatcher. When every scalar it
writes stays wave-uniform, the lanes take each branch together and leave
each loop together, watchdog included, so structured programs now
translate with the watchdog kept. A termination proof is still tried
first and drops it.

Scalar loads may also take VCC (s106/s107) as their offset in this mode,
where comparison masks are wave-uniform ballots.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A guard over pending forward jumps was `!(j1 || j2 || ...)` and each
taken branch `if (c) j = true;`. Both make a block per flag, and a guard
can name hundreds. Compute programs compile unoptimised or under a DXC
time budget, so they now use `|` and `j = j | (c)`: the raytracing
resolve kernels' unoptimised DXIL lost a third of its blocks, and DXC
finished optimising them in 45 s instead of 83-110 s. Optimised graphics
stages keep `||`, which DXC folds into smaller code.

Which labels are pending at an instruction now comes from the earliest
branch to each label rather than a scan of every branch per instruction.

The host-profile record changes for the saveexec and empty programs, on
every profile, because their guards now use `|`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
DXC needs about 1.1 GB of memory per MB of generated HLSL at -O0. Two
10 MB ProjectScarlett programs took 11 GB each while the title ran and
starved it. A translation above 8 MiB of HLSL is now refused instead of
being handed to the compiler.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A buffer descriptor loaded from the resource heap and then read with
IDXEN needs its element stride, which the console keeps in bits 16..29 of
V# word 1. Translated programs never see the console V#, so these were
refused ("raw buffer IDXEN needs the console descriptor stride").

When the root carries the runtime's stride table (root SRV t1,
space32766, one u32 per guest heap slot), a heap descriptor load fills
word 1 from it, and IDXEN on that descriptor decodes the stride from
there. Without the table nothing changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The console binds by user SGPR, so a title can pair a program with a root
other than the one it was compiled for.

- Compute roots with more than two tables, or with root descriptors and
  constants after the tables. The FSSM reader accepts descriptors in later
  tables and constants in a later parameter when a root is given, and
  reflection accepts the root only when the user data confirms every
  binding. Root constants keep their parameter, and a reflected root
  moves that parameter to the register the program reads.
- A pipeline root replaces an embedded RTS0, as for mesh stages, and the
  binding reader ignores the embedded root.
- Literal samplers that a root without sampler-heap indexing (flag 0x800)
  lacks become private static samplers (space32765). A root that
  reflection cannot describe gets a copy with only those samplers added,
  bound around each dispatch.
- The heap stride table for the translator: each paged heap keeps the
  console buffer stride of every guest slot, from view creation and
  descriptor copies, in a mapped upload buffer. A program refused only for
  want of strides is translated again with that table as an appended root
  SRV (t1, space32766), which each dispatch binds.
- A raster stream the host rejects records its guest root and stages under
  TUXBOX_CAPTURE_RASTER_ROOTS or TUXBOX_CAPTURE_SHADER_INPUTS.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ProjectScarlett 1.0.2.1 calls one clearing routine (RVA 0x4E8AA10) a few
hundred times a second. Its fast path is five clzero loops, so on a host
without CLZERO every call raised five exceptions for the trap fallback:
about four million in half an hour on an Intel host, each logged by Wine.

When the routine's bytes match exactly and the host has AVX2, the fast
path is replaced, before title code runs, by AVX stores over the same
range that end in the routine's own tail. The overflow slow path keeps
its clzero loops and the trap fallback.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ProjectScarlett 1.0.2.1 runs a watchdog thread that crashes the title on
purpose when its heartbeat has not moved for 30 one-second checks or a
registered thread has not checked in for 300 seconds. A title thread
waiting on a shader translation or a driver compile can take that long
under TuxBox, and the run then ended with the store to address 0 after
"presented N frames in 40s".

The watchdog skips both checks while bit 0 of its pause flag is set.
TuxBox sets that bit while any title thread waits on a translation or a
pipeline compile, and clears it five seconds after the last wait ends, so
released threads can check in. A bit the title set itself is never
cleared. Nothing is written unless the watchdog's code matches this build
byte for byte, and TUXBOX_KEEP_TITLE_WATCHDOG=1 leaves it alone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The raytracing resolve kernels translate to about 2.5 MB of HLSL each,
and one needs about 77 s at -O0 while the title runs with four compiling
at once, so the fixed 90 s cap refused them on every boot. The cap is now
90 s per MB of HLSL, at least the old 90 s and at most 600 s.

DXIL conversion failures report only a result code on VKD3D_DEBUG. Game
runs now set VKD3D_SHADER_DEBUG=err as well, unless it is already set, so
the log says which construct the shader compiler rejected.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:55:11 +00:00
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/216/head:github-bot/gh-216'
git switch 'github-bot/gh-216'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-216'
git switch 'github-bot/gh-216'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-216'
git switch 'github-bot/gh-216'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-216'
git switch 'main'
git merge --squash 'github-bot/gh-216'
git switch 'main'
git merge --ff-only 'github-bot/gh-216'
git switch 'main'
git merge 'github-bot/gh-216'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.