tombox-xshader, d3d12_xs: Durango user SGPR layout, CBV scalar loads, and pipeline root signature piping #79

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

@⁠adriaespii on GitHub · 2026-11-22 01:04 UTC · original
adriaespii:contrib/durango-user-sgpr-bindings → main · +195 −12 · 5 files · 87 commits · closed without merging

Summary

Fixes Durango (Xbox One GCN) user SGPR parameter binding, scalar memory loads (\s_load_dword*) from Constant Buffer Views (CBVs), and pipes pipeline \ID3D12RootSignature\ bytecode to graphics and compute translation.

Resolves the Trackmania black window translation blocker where shaders failed with:
\ase sN is not a root table pointer (Desc { table: 0, off: ... })\ and graphics PSOs failed with \pso_ok=0, shaders ok=4 fail=124.

Root Cause & Changes

  1. Durango User SGPR ABI (\crates/tombox-xshader/src/hlsl.rs):
    • Durango (GCN / GFX7) maps user parameters directly starting at \s0\ for compute, \s2\ for vertex shaders using \s_swappc_b64 s[0:1], s[0:1]\ (vertex fetch calling convention), and \s0\ for other graphics stages (pixel shader, etc.), unlike Scarlett RDNA2 which assumes \s8\ / \s4.
    • Added \ShaderExtract::is_durango()\ helper to recognize Durango containers (\ ssm).
  2. SMEM / SMRD Scalar Constant Buffer Loads (\crates/tombox-xshader/src/hlsl.rs):
    • In GCN/Durango shaders, constant buffer pointers (such as root CBVs or CBVs loaded from descriptor tables) are read directly with scalar reads (\s_load_dword[x2/x4], SMEM op <= 4).
    • In \infer_tbuf_types, when base register \\ resolves via \desc_candidates\ to a descriptor / CBV, record \Res::Cb(slot)\ and track \cb_size, removing destination registers from descriptor tracking.
    • If \\ has \Sym::Desc { table: pt, .. }\ as a table pointer fallback, resolve to \pt.
    • In \emit_insn, if \self.res.get(&idx)\ has \Res::Cb\ or \Res::Buf, emit the CBV/buffer load (using universal data width \1u32 << (ins.op & 7)) instead of skipping it as a descriptor fetch.
  3. Pipeline Root Signature Piping (\crates/compat/d3d12_xs/src/device_wrap.rs, \shader_xlat.rs):
    • Stripped Durango and Scarlett shaders often do not carry an \RTS0\ chunk in their DXBC container; their root layout is provided at PSO creation time via \ID3D12RootSignature.
    • In \device_wrap.rs, extract root signature bytes from \ID3D12RootSignature\ (
      d(&desc, 0)) via \crate::console_slots_mesh::root_data\ in \CreateGraphicsPipelineState_X\ and \CreateComputePipelineState_X.
    • Added \ ranslate_for_targets_with_root\ and \prefetch_with_root\ in \shader_xlat.rs\ to pass external root signature bytes into \ ranslate_uncached_with.

Verification

  • Added 3 synthetic tests in \crates/tombox-xshader/tests/synthetic.rs:
    • \durango_pixel_shader_user_base_0_and_cbv_load: validates \user_base = 0\ and root CBV scalar load emission.
    • \durango_vertex_shader_swappc_user_base_2: validates vertex shader \s_swappc_b64\ continuation shifting \user_base\ to 2.
    • \durango_cbv_loaded_from_descriptor_table: validates scalar loads from CBVs fetched through descriptor tables without failing as invalid table pointers.
  • Ran test suite:
    • \cargo test -p tombox-xshader --test synthetic: 12 passed, 0 failed.
    • \cargo test -p tombox-xshader --lib: 26 passed, 0 failed.
    • \cargo test -p d3d12_xs --lib: 410 passed, 0 failed.
**@⁠adriaespii** on GitHub · 2026-11-22 01:04 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/79) `adriaespii:contrib/durango-user-sgpr-bindings` → `main` · +195 −12 · 5 files · 87 commits · closed without merging ### Summary Fixes Durango (Xbox One GCN) user SGPR parameter binding, scalar memory loads (\s_load_dword*\) from Constant Buffer Views (CBVs), and pipes pipeline \ID3D12RootSignature\ bytecode to graphics and compute translation. Resolves the Trackmania black window translation blocker where shaders failed with: \ase sN is not a root table pointer (Desc { table: 0, off: ... })\ and graphics PSOs failed with \pso_ok=0, shaders ok=4 fail=124\. ### Root Cause & Changes 1. **Durango User SGPR ABI (\crates/tombox-xshader/src/hlsl.rs\)**: - Durango (GCN / GFX7) maps user parameters directly starting at \s0\ for compute, \s2\ for vertex shaders using \s_swappc_b64 s[0:1], s[0:1]\ (vertex fetch calling convention), and \s0\ for other graphics stages (pixel shader, etc.), unlike Scarlett RDNA2 which assumes \s8\ / \s4\. - Added \ShaderExtract::is_durango()\ helper to recognize Durango containers (\ ssm\). 2. **SMEM / SMRD Scalar Constant Buffer Loads (\crates/tombox-xshader/src/hlsl.rs\)**: - In GCN/Durango shaders, constant buffer pointers (such as root CBVs or CBVs loaded from descriptor tables) are read directly with scalar reads (\s_load_dword[x2/x4]\, SMEM op <= 4). - In \infer_tbuf_types\, when base register \\ resolves via \desc_candidates\ to a descriptor / CBV, record \Res::Cb(slot)\ and track \cb_size\, removing destination registers from descriptor tracking. - If \\ has \Sym::Desc { table: pt, .. }\ as a table pointer fallback, resolve to \pt\. - In \emit_insn\, if \self.res.get(&idx)\ has \Res::Cb\ or \Res::Buf\, emit the CBV/buffer load (using universal data width \1u32 << (ins.op & 7)\) instead of skipping it as a descriptor fetch. 3. **Pipeline Root Signature Piping (\crates/compat/d3d12_xs/src/device_wrap.rs\, \shader_xlat.rs\)**: - Stripped Durango and Scarlett shaders often do not carry an \RTS0\ chunk in their DXBC container; their root layout is provided at PSO creation time via \ID3D12RootSignature\. - In \device_wrap.rs\, extract root signature bytes from \ID3D12RootSignature\ (\ d(&desc, 0)\) via \crate::console_slots_mesh::root_data\ in \CreateGraphicsPipelineState_X\ and \CreateComputePipelineState_X\. - Added \ ranslate_for_targets_with_root\ and \prefetch_with_root\ in \shader_xlat.rs\ to pass external root signature bytes into \ ranslate_uncached_with\. ### Verification - Added 3 synthetic tests in \crates/tombox-xshader/tests/synthetic.rs\: - \durango_pixel_shader_user_base_0_and_cbv_load\: validates \user_base = 0\ and root CBV scalar load emission. - \durango_vertex_shader_swappc_user_base_2\: validates vertex shader \s_swappc_b64\ continuation shifting \user_base\ to 2. - \durango_cbv_loaded_from_descriptor_table\: validates scalar loads from CBVs fetched through descriptor tables without failing as invalid table pointers. - Ran test suite: - \cargo test -p tombox-xshader --test synthetic\: 12 passed, 0 failed. - \cargo test -p tombox-xshader --lib\: 26 passed, 0 failed. - \cargo test -p d3d12_xs --lib\: 410 passed, 0 failed.
- Set Durango user SGPR base to s0 for compute, s2 for vertex shaders with s_swappc_b64 continuation, and s0 for other graphics stages.
- In infer_tbuf_types and emit_insn, resolve scalar memory reads (s_load_dword*, SMEM op <= 4) from CBVs as constant buffer loads instead of failing with 'base sN is not a root table pointer'.
- Pipe pipeline ID3D12RootSignature bytecode in device_wrap.rs (CreateGraphicsPipelineState_X and CreateComputePipelineState_X) to translate_for_targets_with_root so stripped Durango shaders receive their external root layout.
- Add regression unit tests in synthetic.rs covering Durango pixel shader root CBVs, vertex shader s_swappc_b64 calling convention, and CBVs loaded through descriptor tables.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:09:40 +00:00
github-bot closed this pull request 2026-11-26 06:09:40 +00:00
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 13:12 UTC · original

Main's history was rewritten, which auto-closed this PR (sorry for the noise). Main now has its own Durango user-SGPR path and s_swappc/s_setpc handling. Please rebase onto it and keep only what main still lacks (the root-keyed prefetch cache). Also drop the tb_nrm commit from #77. To resubmit: git fetch this repo, branch from the current main, cherry-pick only your own commits (the old branch is based on the previous history and cannot be merged), and open a new PR.

**@⁠omonkeyz** on GitHub · 2026-11-22 13:12 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/79#issuecomment-7079645950) Main's history was rewritten, which auto-closed this PR (sorry for the noise). Main now has its own Durango user-SGPR path and s_swappc/s_setpc handling. Please rebase onto it and keep only what main still lacks (the root-keyed prefetch cache). Also drop the tb_nrm commit from #77. To resubmit: `git fetch` this repo, branch from the current `main`, cherry-pick only your own commits (the old branch is based on the previous history and cannot be merged), and open a new PR.

Pull request closed

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