tombox-xshader: generate the pass-through hull shader for tessellation #312

Closed
github-bot wants to merge 3 commits from gh-pr/312/head into gh-pr/312/base
Owner

@⁠nickfmbg on GitHub · 2026-11-23 17:36 UTC · original
nickfmbg:tess-hs-passthrough → main · +988 −7 · 10 files · 3 commits · closed without merging

Library / area: tombox-xshader: new tess_abi.rs, plus hlsl/tess.rs (passthrough_hull, Partitioning, PASSTHROUGH_VS, shared patch_struct), tests/tess.rs, and a docs/BLOCKERS.md entry.

Exports changed (exports.txt rows): None.

Source of the behaviour:

  • TF ring layout: Mesa src/amd/common/nir/ac_nir_lower_tess_io_to_mem.c (MIT). In hs_store_tess_factors_for_tessellator, the factors of a patch are at tf_offset + rel_patch_id * (outer + inner) * 4: triangles as outer[0..3] then inner, quads as outer[0..4] then inner[0..2], and isolines with GL's outer[1] before outer[0]. GFX6–8 adds a 4-byte base, because hs_store_dynamic_control_word_gfx6 writes 0x80000000 at the start of the ring. The fixed-function tessellator reads this layout, so it is the same whichever compiler wrote the HS.
  • The isoline D3D mapping is measured, not assumed. The WARP test shows ring dword 0 is the line detail and dword 1 the line density.

Step 3a of #294, stacked on #301, which is stacked on #295. Only the last commit is new here.

What it does

  • passthrough_hull(hs, ds, partitioning, layout) returns a PC hull shader plus its vertex shader, for the pipeline in the #294 design (the console HS runs elsewhere and writes the TF ring).
    • Domain, output topology and control-point counts come from PSV0.
    • The control-point output is the domain shader's input signature, so they link.
    • The patch-constant function loads every factor of patch tb_patch_offset + SV_PrimitiveID from tb_tf at the hardware offsets above.
  • tess_abi.rs: tb_tf is t0 and the TbTess root constants (tb_tf_offset, tb_patch_offset) are b0, both in a new internal space, 4000006. It also has the offset helpers d3d12_xs will use.
  • patch_struct now takes the domain. It always declares the domain's full SV_TessFactor / SV_InsideTessFactor arrays, so the hull and domain shaders produce the same patch struct even when the console DS declared only some factors. Domain shader output for the step-2 cases is unchanged.

Not in this PR

  • Translating the console hull program: needs the ring descriptor source (#294, question 1).
  • Partitioning and max tess factor: not in PSV0, so they are an argument here. d3d12_xs has to get them from the console HS state (#294, question 3).
  • The d3d12_xs draw path.

All four are recorded in the new BLOCKERS entry.

Tests (tests/tess.rs, 6 new)

  • GPU (WARP):

    • Two quad patches with factors 2 and 4 in the ring render through the translated console DS. Each half lands on its own factor grid, and every pixel's DS patch id equals the tessellator's SV_PrimitiveID.
    • A GFX6–8 ring (control word, a 20-byte TF offset, patch offset 1, a decoy factor in slot 0) gives the identical image. Reading the same ring as GFX9+ does not.
    • Isoline semantics, with a native DS logging SV_DomainLocation to a UAV: ring (3, 2) gives lines at v = 0 and 0.5 with 4 points each.
  • Mutation checks, done locally: a wrong patch stride, a dropped GFX6–8 shift and reversed factor order each make a GPU test fail.

  • Generated text for the quad/GFX6–8 and tri/GFX9+ cases, and DXC compilation for all 3 domains × 4 partitionings × 2 layouts.

  • Refusals: a non-hull TessInfo, a domain mismatch, a control-point mismatch, invalid output topologies, a DS without tess info, and a non-domain stage.

  • cargo test -p tombox-xshader passes

  • No game or console files and no binaries included

  • No fake success; anything not possible is left missing with a note

🤖 Generated with Claude Code

**@⁠nickfmbg** on GitHub · 2026-11-23 17:36 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/312) `nickfmbg:tess-hs-passthrough` → `main` · +988 −7 · 10 files · 3 commits · closed without merging **Library / area:** `tombox-xshader`: new `tess_abi.rs`, plus `hlsl/tess.rs` (`passthrough_hull`, `Partitioning`, `PASSTHROUGH_VS`, shared `patch_struct`), `tests/tess.rs`, and a `docs/BLOCKERS.md` entry. **Exports changed (exports.txt rows):** None. **Source of the behaviour:** - **TF ring layout:** Mesa `src/amd/common/nir/ac_nir_lower_tess_io_to_mem.c` (MIT). In `hs_store_tess_factors_for_tessellator`, the factors of a patch are at `tf_offset + rel_patch_id * (outer + inner) * 4`: triangles as outer[0..3] then inner, quads as outer[0..4] then inner[0..2], and isolines with GL's outer[1] before outer[0]. GFX6–8 adds a 4-byte base, because `hs_store_dynamic_control_word_gfx6` writes `0x80000000` at the start of the ring. The fixed-function tessellator reads this layout, so it is the same whichever compiler wrote the HS. - **The isoline D3D mapping is measured, not assumed.** The WARP test shows ring dword 0 is the line detail and dword 1 the line density. Step 3a of #294, stacked on #301, which is stacked on #295. Only the last commit is new here. ### What it does - **`passthrough_hull(hs, ds, partitioning, layout)`** returns a PC hull shader plus its vertex shader, for the pipeline in the #294 design (the console HS runs elsewhere and writes the TF ring). - Domain, output topology and control-point counts come from PSV0. - The control-point output is the domain shader's input signature, so they link. - The patch-constant function loads every factor of patch `tb_patch_offset + SV_PrimitiveID` from `tb_tf` at the hardware offsets above. - **`tess_abi.rs`:** `tb_tf` is t0 and the `TbTess` root constants (`tb_tf_offset`, `tb_patch_offset`) are b0, both in a new internal space, 4000006. It also has the offset helpers d3d12_xs will use. - **`patch_struct` now takes the domain.** It always declares the domain's full `SV_TessFactor` / `SV_InsideTessFactor` arrays, so the hull and domain shaders produce the same patch struct even when the console DS declared only some factors. Domain shader output for the step-2 cases is unchanged. ### Not in this PR - **Translating the console hull program:** needs the ring descriptor source (#294, question 1). - **Partitioning and max tess factor:** not in PSV0, so they are an argument here. d3d12_xs has to get them from the console HS state (#294, question 3). - **The d3d12_xs draw path.** All four are recorded in the new BLOCKERS entry. ### Tests (`tests/tess.rs`, 6 new) - **GPU (WARP):** - Two quad patches with factors 2 and 4 in the ring render through the translated console DS. Each half lands on its own factor grid, and every pixel's DS patch id equals the tessellator's `SV_PrimitiveID`. - A GFX6–8 ring (control word, a 20-byte TF offset, patch offset 1, a decoy factor in slot 0) gives the identical image. Reading the same ring as GFX9+ does not. - Isoline semantics, with a native DS logging `SV_DomainLocation` to a UAV: ring (3, 2) gives lines at v = 0 and 0.5 with 4 points each. - **Mutation checks, done locally:** a wrong patch stride, a dropped GFX6–8 shift and reversed factor order each make a GPU test fail. - **Generated text** for the quad/GFX6–8 and tri/GFX9+ cases, and DXC compilation for all 3 domains × 4 partitionings × 2 layouts. - **Refusals:** a non-hull TessInfo, a domain mismatch, a control-point mismatch, invalid output topologies, a DS without tess info, and a non-domain stage. - [x] `cargo test -p tombox-xshader` passes - [x] No game or console files and no binaries included - [x] No fake success; anything not possible is left `missing` with a note 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Read the PSVRuntimeInfo hull union (input and output control points,
tessellator domain, output primitive) and domain union (input control
points, output-position byte, domain at the aligned +8), plus the
patch-constant vector count at +26, into GsInfo::tess. Out-of-range
fields and other stages give None. No translation behaviour changes;
step 1 of the tessellation plan in #294.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Stage::Domain now translates to ds_5_0. The domain attribute and
OutputPatch size come from PSV0, the patch-constant input from PSG1
(tess factors grouped by semantic), the control points from the input
signature. Live entry registers are seeded with the hardware VS-stage
domain shader inputs (Mesa declare_tes_input_vgprs): v0/v1 tess u/v,
v2 rel patch id, v3 patch id, both ids from SV_PrimitiveID. Outputs
use the VS export path.

Off-chip ring reads, the NGG ES form and hull shaders stay refused.
Step 2 of #294. tests/tess.rs renders tessellated quad patches on WARP
bit-exact against a native HLSL domain shader.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
passthrough_hull builds the PC hull shader and its vertex shader for
the #294 pipeline. The patch-constant function reads each patch's
factors from tb_tf (t0, space 4000006) in the hardware TF ring layout:
tf_offset + rel_patch * (outer + inner) * 4, plus 4 after the GFX6-8
control word (Mesa hs_store_tess_factors_for_tessellator). Domain,
topology and control points come from PSV0; partitioning is an
argument until it is sourced from the console HS state.

patch_struct now always declares the domain's full factor arrays so the
hull and domain shaders link. WARP tests cover per-patch factors, the
GFX6-8 control word with both offsets, and the isoline mapping (ring
dword 0 = line detail, dword 1 = line density). BLOCKERS gets a hull /
domain stage entry.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:18:15 +00:00
github-bot closed this pull request 2026-11-26 06:18:15 +00:00
Author
Owner

@⁠MeNoSkills on GitHub · 2026-11-23 19:21 UTC · original

Independent run of this PR's tests/tess.rs (11 tests) on an RTX 4070 Ti (Windows 10 19045) and on WARP, release build: 11 passed, 0 failed on both, including gpu_translated_domain_shader_matches_native_hlsl_on_a_tessellated_quad, gpu_passthrough_hull_takes_each_patch_factors_from_the_ring, gpu_passthrough_hull_honours_the_gfx6_control_word_and_both_offsets and gpu_isoline_ring_dword0_is_line_detail_and_dword1_is_line_density. tests/synthetic.rs passes 24/24 on WARP and hardware with the touched lines. tests/mesh.rs passes 24/24 with TOMBOX_EXEC_HW=1; on this machine's WARP its GPU tests fail with "WARP reports MeshShaderTier 0", which is the same on unmodified main (older WARP has no mesh support).

**@⁠MeNoSkills** on GitHub · 2026-11-23 19:21 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/312#issuecomment-7111490891) Independent run of this PR's `tests/tess.rs` (11 tests) on an RTX 4070 Ti (Windows 10 19045) and on WARP, release build: 11 passed, 0 failed on both, including `gpu_translated_domain_shader_matches_native_hlsl_on_a_tessellated_quad`, `gpu_passthrough_hull_takes_each_patch_factors_from_the_ring`, `gpu_passthrough_hull_honours_the_gfx6_control_word_and_both_offsets` and `gpu_isoline_ring_dword0_is_line_detail_and_dword1_is_line_density`. `tests/synthetic.rs` passes 24/24 on WARP and hardware with the touched lines. `tests/mesh.rs` passes 24/24 with `TOMBOX_EXEC_HW=1`; on this machine's WARP its GPU tests fail with "WARP reports MeshShaderTier 0", which is the same on unmodified main (older WARP has no mesh support).
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-25 13:49 UTC · original

Applied on main in aac1f6e (cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.

**@⁠omonkeyz** on GitHub · 2026-11-25 13:49 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/312#issuecomment-7164340652) Applied on main in aac1f6e (cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.

Pull request closed

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