tombox-xshader: parse 24-byte ISGN/OSGN signatures and synthesize Durango vertex fetch attributes #120

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

@⁠adriaespii on GitHub · 2026-11-22 12:56 UTC · original
adriaespii:contrib/xshader-durango-isgn-fetch-synthesis → main · +127 −20 · 6 files · 1 commits · closed without merging

Summary

This PR fixes signature parsing for 24-byte Direct3D 10/11 & FXC ISGN/OSGN chunks and synthesizes vertex attribute VGPR initialization (v4..vN) for Durango vertex shaders calling runtime fetch subroutines via s_swappc_b64 s[0:1], s[0:1], addressing the blocker described in docs/BLOCKERS.md:221.

Context & Problem

In docs/BLOCKERS.md:221:

Those two VS still fail: every variant starts with s_swappc_b64 s[0:1], s[0:1], a call to a fetch shader that the console runtime builds from the input layout. Needed: synthesize the attribute fetch (VGPR assignment from the Durango input metadata).

Investigating the pipeline revealed:

  1. crates/tombox-xshader/src/meta.rs previously hardcoded signature element stride to 32 bytes (which corresponds to ISG1/OSG1 in Direct3D 11.1+ / DX12 with [stream: u32, name_off: u32, ...]).
  2. Xbox One shaders compiled by FXC use the 24-byte element layout (ISGN/OSGN, with [name_off: u32, index: u32, ...]). Because stride was 32 bytes, parsing ISGN chunks failed or corrupted offsets, leaving input_sig empty in ShaderExtract.
  3. Because input_sig was empty, hlsl.rs generated an empty struct SIn and skipped the vertex attribute prologue (v4..vN).
  4. Furthermore, FXC Durango signatures often emit rw_mask == 0 while setting the active component bitmask (mask != 0). The previous check e.rw_mask != 0 in hlsl.rs skipped registers where rw_mask == 0.

Key Changes

  1. parse_signature (crates/tombox-xshader/src/meta.rs):
    • Dynamically supports both 24-byte (ISGN/OSGN) and 32-byte (ISG1/OSG1) element strides.
    • Detects 24-byte stride when 8 + count * 32 > body.len() or when the first element's offset points to the 24-byte table layout.
  2. extract (crates/tombox-xshader/src/lib.rs):
    • Falls back to ISGN/OSGN chunk bodies if ISG1/OSG1 is absent.
  3. HLSL Generation & ABI (crates/tombox-xshader/src/hlsl.rs):
    • In resource inference (infer_resources), recognizes s_swappc_b64 as a no-op fetch call when is_durango(&ex.fssm) (even if root signature RTS0 is absent).
    • In vertex attribute prologue synthesis, accepts active input registers with mask != 0 for Durango shaders when rw_mask is 0, correctly populating v4..v7, v8..v11, etc. from i.i0, i.i1.
  4. Unit Tests:
    • meta::tests::parses_both_24byte_isgn_and_32byte_isg1_signatures: verifies parsing both 24-byte and 32-byte chunk bodies.
    • tests/synthetic.rs: added durango_vertex_fetch_call_synthesizes_attributes_from_input_signature, verifying that a Durango vertex shader with s_swappc_b64 and an FXC input signature generates struct SIn, POSITION0/COLOR0 semantics, and v4..v11 attribute assignments.

Verification

  • cargo check -p tombox-xshader: Clean (0 errors).
  • cargo test -p tombox-xshader --test synthetic: 12/12 passed.
  • cargo test -p tombox-xshader --lib: 62/62 passed.
**@⁠adriaespii** on GitHub · 2026-11-22 12:56 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/120) `adriaespii:contrib/xshader-durango-isgn-fetch-synthesis` → `main` · +127 −20 · 6 files · 1 commits · closed without merging ### Summary This PR fixes signature parsing for 24-byte Direct3D 10/11 & FXC ISGN/OSGN chunks and synthesizes vertex attribute VGPR initialization (v4..vN) for Durango vertex shaders calling runtime fetch subroutines via s_swappc_b64 s[0:1], s[0:1], addressing the blocker described in docs/BLOCKERS.md:221. ### Context & Problem In docs/BLOCKERS.md:221: > Those two VS still fail: every variant starts with s_swappc_b64 s[0:1], s[0:1], a call to a fetch shader that the console runtime builds from the input layout. Needed: synthesize the attribute fetch (VGPR assignment from the Durango input metadata). Investigating the pipeline revealed: 1. crates/tombox-xshader/src/meta.rs previously hardcoded signature element stride to 32 bytes (which corresponds to ISG1/OSG1 in Direct3D 11.1+ / DX12 with [stream: u32, name_off: u32, ...]). 2. Xbox One shaders compiled by FXC use the 24-byte element layout (ISGN/OSGN, with [name_off: u32, index: u32, ...]). Because stride was 32 bytes, parsing ISGN chunks failed or corrupted offsets, leaving input_sig empty in ShaderExtract. 3. Because input_sig was empty, hlsl.rs generated an empty struct SIn and skipped the vertex attribute prologue (v4..vN). 4. Furthermore, FXC Durango signatures often emit rw_mask == 0 while setting the active component bitmask (mask != 0). The previous check e.rw_mask != 0 in hlsl.rs skipped registers where rw_mask == 0. ### Key Changes 1. parse_signature (crates/tombox-xshader/src/meta.rs): - Dynamically supports both 24-byte (ISGN/OSGN) and 32-byte (ISG1/OSG1) element strides. - Detects 24-byte stride when 8 + count * 32 > body.len() or when the first element's offset points to the 24-byte table layout. 2. extract (crates/tombox-xshader/src/lib.rs): - Falls back to ISGN/OSGN chunk bodies if ISG1/OSG1 is absent. 3. HLSL Generation & ABI (crates/tombox-xshader/src/hlsl.rs): - In resource inference (infer_resources), recognizes s_swappc_b64 as a no-op fetch call when is_durango(&ex.fssm) (even if root signature RTS0 is absent). - In vertex attribute prologue synthesis, accepts active input registers with mask != 0 for Durango shaders when rw_mask is 0, correctly populating v4..v7, v8..v11, etc. from i.i0, i.i1. 4. Unit Tests: - meta::tests::parses_both_24byte_isgn_and_32byte_isg1_signatures: verifies parsing both 24-byte and 32-byte chunk bodies. - tests/synthetic.rs: added durango_vertex_fetch_call_synthesizes_attributes_from_input_signature, verifying that a Durango vertex shader with s_swappc_b64 and an FXC input signature generates struct SIn, POSITION0/COLOR0 semantics, and v4..v11 attribute assignments. ### Verification - cargo check -p tombox-xshader: Clean (0 errors). - cargo test -p tombox-xshader --test synthetic: 12/12 passed. - cargo test -p tombox-xshader --lib: 62/62 passed.
Durango vertex shaders start with s_swappc_b64 s[0:1], s[0:1] (a call to a fetch shader built by the runtime) and receive vertex attributes starting at v4.

Previously, parse_signature assumed 32-byte elements (ISG1/OSG1 from D3D11.1+/DX12), failing to parse 24-byte ISGN/OSGN chunks produced by FXC for Xbox One Durango shaders, leaving input_sig empty.

1. meta.rs: support both 24-byte (ISGN/OSGN) and 32-byte (ISG1/OSG1) signature element strides.
2. lib.rs: extract ISGN/OSGN when ISG1/OSG1 is absent.
3. hlsl.rs:
   - Handle s_swappc_b64 in resource inference when is_durango(&ex.fssm).
   - In vertex attribute VGPR initialization, accept active elements with mask != 0 for Durango shaders when rw_mask is 0.
4. Added offline unit tests in meta.rs and synthetic.rs.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:10:42 +00:00
github-bot closed this pull request 2026-11-26 06:10:42 +00:00
Author
Owner

@⁠adriaespii on GitHub · 2026-11-22 13:40 UTC · original

Hi @⁠omonkeyz, thanks for the review!

I have addressed the requested changes:

  1. **Tag-based element stride in \parse_signature**: Passed the chunk FourCC tag (\ISGN/\OSGN/\PCSG\ vs \ISG1/\OSG1) into \parse_signature(tag, body)\ across \meta.rs, \lib.rs, \gcn.rs, and tests to select the 24-byte vs 32-byte stride directly from the tag rather than inspecting offsets.
  2. \SV_ViewportArrayIndex\ refusal for Durango: Retained the
    ot lowered\ refusal for Durango shaders when \osig.iter().any(|e| e.sysval == 5).
  3. Comment lines removed: Stripped all added comment lines; verified with .github/scripts/pr_gate.py --base upstream/main --head HEAD\ (passed cleanly with 0 problems).
  4. Rebased cleanly onto current \upstream/main.

Ready for your re-review whenever you have a moment. Thanks!

**@⁠adriaespii** on GitHub · 2026-11-22 13:40 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/120#issuecomment-7079978039) Hi @⁠omonkeyz, thanks for the review! I have addressed the requested changes: 1. **Tag-based element stride in \parse_signature\**: Passed the chunk FourCC tag (\ISGN\/\OSGN\/\PCSG\ vs \ISG1\/\OSG1\) into \parse_signature(tag, body)\ across \meta.rs\, \lib.rs\, \gcn.rs\, and tests to select the 24-byte vs 32-byte stride directly from the tag rather than inspecting offsets. 2. **\SV_ViewportArrayIndex\ refusal for Durango**: Retained the \ ot lowered\ refusal for Durango shaders when \osig.iter().any(|e| e.sysval == 5)\. 3. **Comment lines removed**: Stripped all added comment lines; verified with \.github/scripts/pr_gate.py --base upstream/main --head HEAD\ (passed cleanly with 0 problems). 4. Rebased cleanly onto current \upstream/main\. Ready for your re-review whenever you have a moment. Thanks!
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 14:28 UTC · original

Applied in 5339418 (merged in c8a8a8f) with your authorship kept, thanks! One small adjustment on the applied copy: main already exempts its own Durango path from the SV_ViewportArrayIndex refusal, so that original condition (self.durango.is_none()) was kept rather than making the refusal unconditional.

**@⁠omonkeyz** on GitHub · 2026-11-22 14:28 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/120#issuecomment-7080566383) Applied in 5339418 (merged in c8a8a8f) with your authorship kept, thanks! One small adjustment on the applied copy: main already exempts its own Durango path from the SV_ViewportArrayIndex refusal, so that original condition (self.durango.is_none()) was kept rather than making the refusal unconditional.
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 13:23 UTC · original · requested changes

Thanks! Three changes needed: (1) pick the 24-byte vs 32-byte element stride from the chunk tag (ISGN/OSGN vs ISG1/OSG1), passed into parse_signature, instead of guessing from the first name offset; (2) keep the SV_ViewportArrayIndex 'not lowered' refusal for Durango shaders too, unless this PR actually lowers it (otherwise it silently emits wrong output); (3) remove the added comment lines (the gate lists them). The ISGN parsing and the s_swappc_b64 handling look right.

**@⁠omonkeyz** on GitHub · 2026-11-22 13:23 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/120#pullrequestreview-6012472254) · **requested changes** Thanks! Three changes needed: (1) pick the 24-byte vs 32-byte element stride from the chunk tag (ISGN/OSGN vs ISG1/OSG1), passed into parse_signature, instead of guessing from the first name offset; (2) keep the SV_ViewportArrayIndex 'not lowered' refusal for Durango shaders too, unless this PR actually lowers it (otherwise it silently emits wrong output); (3) remove the added comment lines (the gate lists them). The ISGN parsing and the s_swappc_b64 handling look right.

Pull request closed

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