tombox-xshader / d3d12_xs: Hull and Domain shader translation (tessellation) — design proposal #294

Open
opened 2026-11-26 06:17:35 +00:00 by github-bot · 0 comments
Owner

@⁠nickfmbg on GitHub · 2026-11-23 16:37 UTC · original

Area: tombox-xshader (new hlsl/tess.rs), later d3d12_xs (draw path).
Milestone: "All shader stages translated" — Hull and Domain are the two stages at none.
Seen in: Trackmania game_scan, 4 hull + 4 domain Durango shaders (BLOCKERS "Trackmania shader translation gaps"). Today translate_with returns stage Hull not supported yet.

I'd like to take this on. Before writing the translator part I want to agree the approach, because part of the ABI is compiler-chosen and I don't have a dump to check it against.

What the hardware runs

On RDNA2 a D3D tessellation pipeline does not run as VS → HS → DS. It runs as:

D3D stage Hardware stage Inputs set by the hardware Where outputs go
VS LS, merged into the HS program vertex id etc. LDS
HS (control point + patch constant phases) HS, one program v0 patch id, v1 rel ids (rel patch id [7:0], control point id [12:8]), then the LS VGPRs per-vertex and per-patch outputs to the off-chip ring (VRAM); tess factors to the TF ring
tessellator fixed function reads the TF ring
DS ES inside the NGG GS (or VS) after the GS VGPRs: tess u, tess v, rel patch id, patch id parameter/position exports like a VS

System SGPRs of the merged HS on GFX10 are s0 off-chip offset, s1 merged wave info, s2 TF offset, s3 scratch offset, then 2 more system SGPRs; user data starts at s8. That matches the "8 system SGPRs" rule this repo already uses for merged ES/GS/MS.

Sources: Mesa src/amd/vulkan/radv_shader_args.c (MESA_SHADER_TESS_CTRL, declare_tes_input_vgprs, declare_vs_input_vgprs for GFX10 merged VS-TCS) and src/amd/common/nir/ac_nir_lower_tess_io_to_mem.c, both MIT.

The TF ring layout is fixed by the hardware, since the fixed-function tessellator reads it. For GFX9 and later the factors for a patch sit at tf_offset + rel_patch_id * (outer + inner) * 4, outer first, then inner. Isolines swap their two factors. GFX6–8 also writes a dynamic control word 0x80000000 at offset 0 and shifts the factors by 4, which is relevant to Durango (hs_store_tess_factors_for_tessellator, hs_store_dynamic_control_word_gfx6).

The off-chip and LDS layouts are chosen by the compiler. Mesa's layout is documented at the top of the lowering file. The console compiler's layout is unknown to me.

Proposed design: emulate the rings, don't decode the layout

The console compiler builds HS and DS against the same layout, so I don't need to know it. I only need to give both stages the same memory and the same system values:

  1. The HS runs as a compute pass. One thread group per batch of patches, one lane per HS invocation. This is the model the translator already uses (lanes, exec_lo, LDS, barriers). The LS part fetches vertices with the vertex id taken from the index buffer. Its buffer stores into the off-chip ring and the TF ring become stores into two RWByteAddressBuffers. The ring descriptors are recognised the same way the GS ring table would be, from the internal table at s[0:1].
  2. A pass-through PC hull shader. Generated from PSV0 (domain, partitioning, output primitive, control point counts). Its patch constant function reads the factors for SV_PrimitiveID from the TF buffer in the hardware format above. It outputs no control-point data the DS needs: the DS reads that from the off-chip buffer.
  3. The DS is translated like the VS. SV_DomainLocation feeds tess u/v and SV_PrimitiveID feeds patch id / rel patch id. Its off-chip loads read the same buffer with the off-chip offset seeded the way the HS saw it. Its exports become DS outputs.
  4. d3d12_xs inserts the HS compute dispatch in front of a draw whose PSO has HS/DS, and binds both buffers. Patch topology comes from the console PSO.

This avoids splitting one console HS program into D3D's control-point and patch-constant phases. That split is not possible in general: the console program computes both in one pass, with cross-lane LDS traffic between them.

Plan, in reviewable PRs

  1. Metadata (no behaviour change): parse PSV0 HS/DS runtime info (input/output control points, domain, output primitive, output-position-present) into ShaderExtract. The patch constant signature already lands in prim_sig (PSG1). Unit tests only.
  2. DS translation: hardware VGPRs from Mesa, off-chip loads against a bound buffer. WARP exec tests with hand-assembled DS programs and a synthetic off-chip buffer, bit-exact.
  3. HS compute translation and the pass-through hull shader: TF ring and off-chip stores. WARP tests render a tessellated patch from a hand-assembled HS+DS pair and check exact output pixels and TF buffer contents.
  4. d3d12_xs draw path, behind an env gate that is off by default.

Stages stay partial until real titles' shaders pass, per your criteria in #187.

Questions for you

  1. Could someone with the Trackmania dump run xshader on one of the 4 Durango hull shaders and one domain shader? I'd need the ISA disassembly, or just the answers to: which SGPRs and VGPRs are read before they're written; how the off-chip and TF ring descriptors are obtained (s[0:1] table? which offsets?); and whether there's a control word store. That is enough to confirm or correct the register model above without committing any game data.
  2. Do any Scarlett titles you have contain HS/DS (e.g. the UE5 Series title or Matrix Awakens)? Then I'd do Scarlett first and Durango second.
  3. Partitioning (integer / fractional odd / fractional even / pow2) and max tess factor aren't in PSV0, and the DXIL bitcode is NOBC. On the console they should be in the HS program's register state (VGT_TF_PARAM). Do you know where the FSSM register block keeps it?
  4. Is "HS as a compute pass + pass-through PC hull shader" acceptable to you and the graphics lead? The alternative, translating into D3D's two-phase HS, can't represent the console's single-pass program in general.
**@⁠nickfmbg** on GitHub · 2026-11-23 16:37 UTC · [original](https://github.com/omonkeyz/xbox-emulator/issues/294) **Area:** `tombox-xshader` (new `hlsl/tess.rs`), later `d3d12_xs` (draw path). **Milestone:** "All shader stages translated" — Hull and Domain are the two stages at `none`. **Seen in:** Trackmania game_scan, 4 hull + 4 domain Durango shaders (BLOCKERS "Trackmania shader translation gaps"). Today `translate_with` returns `stage Hull not supported yet`. I'd like to take this on. Before writing the translator part I want to agree the approach, because part of the ABI is compiler-chosen and I don't have a dump to check it against. ## What the hardware runs On RDNA2 a D3D tessellation pipeline does not run as VS → HS → DS. It runs as: | D3D stage | Hardware stage | Inputs set by the hardware | Where outputs go | |---|---|---|---| | VS | LS, merged into the HS program | vertex id etc. | LDS | | HS (control point + patch constant phases) | HS, one program | `v0` patch id, `v1` rel ids (rel patch id `[7:0]`, control point id `[12:8]`), then the LS VGPRs | per-vertex and per-patch outputs to the off-chip ring (VRAM); tess factors to the TF ring | | tessellator | fixed function | reads the TF ring | | | DS | ES inside the NGG GS (or VS) | after the GS VGPRs: tess u, tess v, rel patch id, patch id | parameter/position exports like a VS | System SGPRs of the merged HS on GFX10 are `s0` off-chip offset, `s1` merged wave info, `s2` TF offset, `s3` scratch offset, then 2 more system SGPRs; user data starts at `s8`. That matches the "8 system SGPRs" rule this repo already uses for merged ES/GS/MS. Sources: Mesa `src/amd/vulkan/radv_shader_args.c` (`MESA_SHADER_TESS_CTRL`, `declare_tes_input_vgprs`, `declare_vs_input_vgprs` for GFX10 merged VS-TCS) and `src/amd/common/nir/ac_nir_lower_tess_io_to_mem.c`, both MIT. **The TF ring layout is fixed by the hardware**, since the fixed-function tessellator reads it. For GFX9 and later the factors for a patch sit at `tf_offset + rel_patch_id * (outer + inner) * 4`, outer first, then inner. Isolines swap their two factors. GFX6–8 also writes a dynamic control word `0x80000000` at offset 0 and shifts the factors by 4, which is relevant to Durango (`hs_store_tess_factors_for_tessellator`, `hs_store_dynamic_control_word_gfx6`). **The off-chip and LDS layouts are chosen by the compiler.** Mesa's layout is documented at the top of the lowering file. The console compiler's layout is unknown to me. ## Proposed design: emulate the rings, don't decode the layout The console compiler builds HS and DS against the same layout, so I don't need to know it. I only need to give both stages the same memory and the same system values: 1. **The HS runs as a compute pass.** One thread group per batch of patches, one lane per HS invocation. This is the model the translator already uses (lanes, `exec_lo`, LDS, barriers). The LS part fetches vertices with the vertex id taken from the index buffer. Its buffer stores into the off-chip ring and the TF ring become stores into two `RWByteAddressBuffer`s. The ring descriptors are recognised the same way the GS ring table would be, from the internal table at `s[0:1]`. 2. **A pass-through PC hull shader.** Generated from PSV0 (domain, partitioning, output primitive, control point counts). Its patch constant function reads the factors for `SV_PrimitiveID` from the TF buffer in the hardware format above. It outputs no control-point data the DS needs: the DS reads that from the off-chip buffer. 3. **The DS is translated like the VS.** `SV_DomainLocation` feeds tess u/v and `SV_PrimitiveID` feeds patch id / rel patch id. Its off-chip loads read the same buffer with the off-chip offset seeded the way the HS saw it. Its exports become DS outputs. 4. **d3d12_xs** inserts the HS compute dispatch in front of a draw whose PSO has HS/DS, and binds both buffers. Patch topology comes from the console PSO. This avoids splitting one console HS program into D3D's control-point and patch-constant phases. That split is not possible in general: the console program computes both in one pass, with cross-lane LDS traffic between them. ## Plan, in reviewable PRs 1. **Metadata (no behaviour change):** parse PSV0 HS/DS runtime info (input/output control points, domain, output primitive, output-position-present) into `ShaderExtract`. The patch constant signature already lands in `prim_sig` (PSG1). Unit tests only. 2. **DS translation:** hardware VGPRs from Mesa, off-chip loads against a bound buffer. WARP exec tests with hand-assembled DS programs and a synthetic off-chip buffer, bit-exact. 3. **HS compute translation and the pass-through hull shader:** TF ring and off-chip stores. WARP tests render a tessellated patch from a hand-assembled HS+DS pair and check exact output pixels and TF buffer contents. 4. **d3d12_xs draw path**, behind an env gate that is off by default. Stages stay `partial` until real titles' shaders pass, per your criteria in #187. ## Questions for you 1. Could someone with the Trackmania dump run `xshader` on one of the 4 Durango hull shaders and one domain shader? I'd need the ISA disassembly, or just the answers to: which SGPRs and VGPRs are read before they're written; how the off-chip and TF ring descriptors are obtained (s[0:1] table? which offsets?); and whether there's a control word store. That is enough to confirm or correct the register model above without committing any game data. 2. Do any Scarlett titles you have contain HS/DS (e.g. the UE5 Series title or Matrix Awakens)? Then I'd do Scarlett first and Durango second. 3. Partitioning (integer / fractional odd / fractional even / pow2) and max tess factor aren't in PSV0, and the DXIL bitcode is `NOBC`. On the console they should be in the HS program's register state (VGT_TF_PARAM). Do you know where the FSSM register block keeps it? 4. Is "HS as a compute pass + pass-through PC hull shader" acceptable to you and the graphics lead? The alternative, translating into D3D's two-phase HS, can't represent the console's single-pass program in general.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:17:35 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.