tombox-xshader: opt-in user-data CBV fallback for shaders without RTS0 #158

Closed
github-bot wants to merge 1 commit from gh-pr/158/head into gh-pr/158/base
Owner

@⁠AntonioEspana on GitHub · 2026-11-22 16:46 UTC · original
AntonioEspana:user-data-cbv → main · +255 −6 · 8 files · 1 commits · closed without merging

First step of the fallback discussed in the issue: user SGPRs only, fed from a bind-time CBV. No runtime descriptor resolution yet.

What it does

  • Opt-in API: hlsl::translate_user_data(ex) and hlsl::translate_linked_user_data(ex, feeds_ps). translate / translate_linked are unchanged and produce byte-identical HLSL.
  • Selection: the fallback applies only when the shader has no root signature (ex.root_sig.is_none()) and is not a Durango layout. With a root signature, the opt-in call returns exactly the static path (asserted in the test).
  • ABI (src/user_data_abi.rs): one CBV per stage at b0, space4000005 (TB_USER_DATA_REGISTER / TB_USER_DATA_SPACE), 32 dwords (256 bytes). Dword N is the initial value of sN, for s0..s31.
  • Translator (src/hlsl/user_data.rs): when the fallback is active, the shader declares cbuffer TbUserData { uint4 tb_ud[8]; }. Every declared sN with N < 32 is initialised from tb_ud right after the register declarations, before the stage's system-value assignments. System SGPRs (CS group id, MS s3, AS s2..s4, GS s3) therefore still win. This covers VS/PS/GS, CS, MS and AS.
  • Translated::user_data_base: Option<usize>: Some(base) when the shader needs the CBV, where base is the stage's first root-parameter SGPR (the same user_base() the static path uses). None otherwise.
  • user_data_abi::pack(root_sig, base, args): for d3d12_xs at draw time. It lays out root arguments with the static path's mapping (table = 1 dword, root descriptor = 2, constants = num32, consecutive from base). It refuses on a count or kind mismatch and on anything past s31, instead of truncating.

Not in this PR

  • d3d12_xs wiring: appending the CBV to the root signature and filling it per draw. I kept this PR to the translator so it stays one change. Happy to do it next, or to add it here if you prefer.
  • The memory-based root ABI and descriptor resolution (step 2).

Module name

You suggested hlsl/rootmem.rs, but that file already exists (the root-memory CS path). So the new code is in hlsl/user_data.rs. The ABI constants are in user_data_abi.rs, next to centroid_abi.rs / gds_abi.rs. global.rs and global_abi.rs are untouched.

Observation (not changed here)

On the static Scarlett path (non-Durango, non-root-memory), user SGPRs mapped to a root Constants parameter are declared but never initialised. A PS with RTS0 [Constants num32=4] that reads s8 gets uint s8 = 0u;. That is why the WARP test compares against the static layout (pack with the static mapping) rather than the static path's output. Is that expected on Scarlett, or a gap worth an issue?

Tests

  • src/user_data_abi.rs unit tests: packing order, refusals, byte layout.
  • tests/exec_mem/user_data.rs (WARP):
    • user_data_sgprs_read_the_bound_buffer: a PS without RTS0 reads s0, s8, s17, s31. The test binds a root CBV at b0, space4000005 and checks the render target.
    • user_data_follows_the_static_root_layout:
      • Checks that the opt-in call with RTS0 equals the static path, and that the default path has no TbUserData.
      • Packs a [Table, Constants×3] root layout at the reported base (8) and checks that s8..s11 receive the table pointer and the three constants on WARP.

Ran locally on Windows (WARP): cargo test -p tombox-xshader: all passed, 0 failed (5 new: 3 unit, 2 WARP). The ignored tests are the fixture/hardware ones.

I don't have a console or dumps. All checks are synthetic.

**@⁠AntonioEspana** on GitHub · 2026-11-22 16:46 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/158) `AntonioEspana:user-data-cbv` → `main` · +255 −6 · 8 files · 1 commits · closed without merging First step of the fallback discussed in the issue: user SGPRs only, fed from a bind-time CBV. No runtime descriptor resolution yet. ### What it does - **Opt-in API:** `hlsl::translate_user_data(ex)` and `hlsl::translate_linked_user_data(ex, feeds_ps)`. `translate` / `translate_linked` are unchanged and produce byte-identical HLSL. - **Selection:** the fallback applies only when the shader has no root signature (`ex.root_sig.is_none()`) and is not a Durango layout. With a root signature, the opt-in call returns exactly the static path (asserted in the test). - **ABI** (`src/user_data_abi.rs`): one CBV per stage at `b0, space4000005` (`TB_USER_DATA_REGISTER` / `TB_USER_DATA_SPACE`), 32 dwords (256 bytes). Dword N is the initial value of sN, for s0..s31. - **Translator** (`src/hlsl/user_data.rs`): when the fallback is active, the shader declares `cbuffer TbUserData { uint4 tb_ud[8]; }`. Every declared sN with N < 32 is initialised from `tb_ud` right after the register declarations, before the stage's system-value assignments. System SGPRs (CS group id, MS `s3`, AS `s2..s4`, GS `s3`) therefore still win. This covers VS/PS/GS, CS, MS and AS. - **`Translated::user_data_base: Option<usize>`:** `Some(base)` when the shader needs the CBV, where base is the stage's first root-parameter SGPR (the same `user_base()` the static path uses). `None` otherwise. - **`user_data_abi::pack(root_sig, base, args)`:** for d3d12_xs at draw time. It lays out root arguments with the static path's mapping (table = 1 dword, root descriptor = 2, constants = num32, consecutive from `base`). It refuses on a count or kind mismatch and on anything past s31, instead of truncating. ### Not in this PR - **d3d12_xs wiring:** appending the CBV to the root signature and filling it per draw. I kept this PR to the translator so it stays one change. Happy to do it next, or to add it here if you prefer. - The memory-based root ABI and descriptor resolution (step 2). ### Module name You suggested `hlsl/rootmem.rs`, but that file already exists (the root-memory CS path). So the new code is in `hlsl/user_data.rs`. The ABI constants are in `user_data_abi.rs`, next to `centroid_abi.rs` / `gds_abi.rs`. `global.rs` and `global_abi.rs` are untouched. ### Observation (not changed here) On the static Scarlett path (non-Durango, non-root-memory), user SGPRs mapped to a root `Constants` parameter are declared but never initialised. A PS with RTS0 `[Constants num32=4]` that reads s8 gets `uint s8 = 0u;`. That is why the WARP test compares against the static *layout* (`pack` with the static mapping) rather than the static path's output. Is that expected on Scarlett, or a gap worth an issue? ### Tests - `src/user_data_abi.rs` unit tests: packing order, refusals, byte layout. - `tests/exec_mem/user_data.rs` (WARP): - `user_data_sgprs_read_the_bound_buffer`: a PS without RTS0 reads s0, s8, s17, s31. The test binds a root CBV at `b0, space4000005` and checks the render target. - `user_data_follows_the_static_root_layout`: - Checks that the opt-in call with RTS0 equals the static path, and that the default path has no `TbUserData`. - Packs a `[Table, Constants×3]` root layout at the reported base (8) and checks that s8..s11 receive the table pointer and the three constants on WARP. Ran locally on Windows (WARP): `cargo test -p tombox-xshader`: all passed, 0 failed (5 new: 3 unit, 2 WARP). The ignored tests are the fixture/hardware ones. I don't have a console or dumps. All checks are synthetic.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:12:07 +00:00
github-bot closed this pull request 2026-11-26 06:12:07 +00:00
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 17:10 UTC · original

Applied in e4505ea (merged in 43d17b0) with your authorship kept, thanks. I left out the runs/ output file, since generated run logs don't go in the repo. Your report that root-constant user SGPRs are left uninitialised on the static Scarlett path is now recorded in docs/BLOCKERS.md with your repro.

**@⁠omonkeyz** on GitHub · 2026-11-22 17:10 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/158#issuecomment-7082630559) Applied in e4505ea (merged in 43d17b0) with your authorship kept, thanks. I left out the runs/ output file, since generated run logs don't go in the repo. Your report that root-constant user SGPRs are left uninitialised on the static Scarlett path is now recorded in docs/BLOCKERS.md with your repro.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.