tombox-xshader: translate domain shaders (hardware VS stage) #301

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

@⁠nickfmbg on GitHub · 2026-11-23 17:04 UTC · original
nickfmbg:tess-ds → main · +616 −7 · 7 files · 2 commits · closed without merging

Library / area: tombox-xshader (new hlsl/tess.rs; hlsl.rs: Stage::Domain profile, entry point, input-register seeding, PS linkage). New WARP test file tests/tess.rs.

Exports changed (exports.txt rows): None.

Source of the behaviour:

  • Hardware VS-stage domain shader inputs: v0 tess u, v1 tess v, v2 rel patch id, v3 patch id. From Mesa src/amd/vulkan/radv_shader_args.c, declare_tes_input_vgprs (MIT), used by MESA_SHADER_TESS_EVAL when not as_es. Same order on GFX6–10, so it also fits Durango.
  • HLSL domain-shader entry shape ([domain], SV_DomainLocation float2/float3, OutputPatch, patch-constant struct with SV_TessFactor / SV_InsideTessFactor arrays): the D3D11/12 domain shader definition.

Step 2 of #294, stacked on #295 (uses GsInfo::tess). Only the last commit is new here.

What it does

  • Stage::Domain translates to ds_5_0 (compiled as ds_6_2). The domain attribute and the OutputPatch size come from PSV0. The patch-constant input comes from PSG1 (prim_sig), with tess factors grouped into arrays by semantic name. The control-point struct is the input signature.
  • Entry seeding: v0 = asuint(SV_DomainLocation.x), v1 = asuint(.y), v2 = v3 = SV_PrimitiveID. Only registers that are live at entry are seeded. Outputs use the existing VS export path. A DS output feeding a PS gets the same interpolation linkage as a VS.
  • rel patch id = patch id: in the #294 design the off-chip ring holds every patch of the draw, so the patch's index within the ring is its global id.

What it does not do (refused, unchanged)

  • Control-point and patch-constant reads. On the console these come from the off-chip ring, through buffer loads whose descriptor comes from the driver's ring table. That descriptor isn't modelled, so such a load still fails resource resolution exactly as before. The OutputPatch and SPatch parameters are declared only so the PC pipeline links. Open question 1 in #294.
  • The NGG form. When the DS runs as ES inside an NGG GS, its inputs follow the 5 GS VGPRs. Only the hardware-VS form is handled.
  • Hull shaders still return stage Hull not supported yet, so no title PSO with tessellation is built yet. Runtime behaviour in d3d12_xs is unchanged.
  • Assumed, to check against a console DS: the console compiler reads SV_DomainLocation.x/.y straight from v0/v1, with no swizzle. The hardware tessellator is D3D's, so this is the natural mapping, but no console fixture has confirmed it yet.

Tests (tests/tess.rs)

  • gpu_translated_domain_shader_matches_native_hlsl_on_a_tessellated_quad, on WARP. A hand-assembled console DS (v_cvt_f32_u32, v_add_f32, exp pos0, exp param0) is translated and drawn as 2 quad patches at tess factor 4, with a PC VS + HS + PS. The 16x16 target is compared bit-exact with the same pipeline using a native HLSL DS of the same maths. It also checks per pixel that:

    • every pixel is covered;
    • the DS patch id equals the PS's tessellator-provided SV_PrimitiveID;
    • each patch lands in its half of the target;
    • u/v lie on the factor-4 grid.
  • Mutation checks, done locally: flipping the patch id, swapping u and v, and mirroring v each make the test fail.

  • Translation tests: the quad entry point and seeding (unread v2 is not seeded), triangle (float3, patch data element), isoline (no control points, no OutputPatch). All compile with DXC.

  • Refusals: no PSV0 tess info, hull tess info on a DS, a DS without outputs, and Hull still unsupported.

  • 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:04 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/301) `nickfmbg:tess-ds` → `main` · +616 −7 · 7 files · 2 commits · closed without merging **Library / area:** `tombox-xshader` (new `hlsl/tess.rs`; `hlsl.rs`: `Stage::Domain` profile, entry point, input-register seeding, PS linkage). New WARP test file `tests/tess.rs`. **Exports changed (exports.txt rows):** None. **Source of the behaviour:** - Hardware VS-stage domain shader inputs: `v0` tess u, `v1` tess v, `v2` rel patch id, `v3` patch id. From Mesa `src/amd/vulkan/radv_shader_args.c`, `declare_tes_input_vgprs` (MIT), used by `MESA_SHADER_TESS_EVAL` when not `as_es`. Same order on GFX6–10, so it also fits Durango. - HLSL domain-shader entry shape (`[domain]`, `SV_DomainLocation` float2/float3, `OutputPatch`, patch-constant struct with `SV_TessFactor` / `SV_InsideTessFactor` arrays): the D3D11/12 domain shader definition. Step 2 of #294, stacked on #295 (uses `GsInfo::tess`). Only the last commit is new here. ### What it does - `Stage::Domain` translates to `ds_5_0` (compiled as `ds_6_2`). The domain attribute and the `OutputPatch` size come from PSV0. The patch-constant input comes from PSG1 (`prim_sig`), with tess factors grouped into arrays by semantic name. The control-point struct is the input signature. - Entry seeding: `v0 = asuint(SV_DomainLocation.x)`, `v1 = asuint(.y)`, `v2 = v3 = SV_PrimitiveID`. Only registers that are live at entry are seeded. Outputs use the existing VS export path. A DS output feeding a PS gets the same interpolation linkage as a VS. - `rel patch id = patch id`: in the #294 design the off-chip ring holds every patch of the draw, so the patch's index within the ring is its global id. ### What it does not do (refused, unchanged) - **Control-point and patch-constant reads.** On the console these come from the off-chip ring, through buffer loads whose descriptor comes from the driver's ring table. That descriptor isn't modelled, so such a load still fails resource resolution exactly as before. The `OutputPatch` and `SPatch` parameters are declared only so the PC pipeline links. Open question 1 in #294. - **The NGG form.** When the DS runs as ES inside an NGG GS, its inputs follow the 5 GS VGPRs. Only the hardware-VS form is handled. - **Hull shaders** still return `stage Hull not supported yet`, so no title PSO with tessellation is built yet. Runtime behaviour in d3d12_xs is unchanged. - **Assumed, to check against a console DS:** the console compiler reads `SV_DomainLocation.x/.y` straight from `v0/v1`, with no swizzle. The hardware tessellator is D3D's, so this is the natural mapping, but no console fixture has confirmed it yet. ### Tests (`tests/tess.rs`) - `gpu_translated_domain_shader_matches_native_hlsl_on_a_tessellated_quad`, on WARP. A hand-assembled console DS (`v_cvt_f32_u32`, `v_add_f32`, `exp pos0`, `exp param0`) is translated and drawn as 2 quad patches at tess factor 4, with a PC VS + HS + PS. The 16x16 target is compared bit-exact with the same pipeline using a native HLSL DS of the same maths. It also checks per pixel that: - every pixel is covered; - the DS patch id equals the PS's tessellator-provided `SV_PrimitiveID`; - each patch lands in its half of the target; - u/v lie on the factor-4 grid. - **Mutation checks, done locally:** flipping the patch id, swapping u and v, and mirroring v each make the test fail. - Translation tests: the quad entry point and seeding (unread `v2` is not seeded), triangle (`float3`, patch data element), isoline (no control points, no `OutputPatch`). All compile with DXC. - Refusals: no PSV0 tess info, hull tess info on a DS, a DS without outputs, and Hull still unsupported. - [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]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:17:51 +00:00
github-bot closed this pull request 2026-11-26 06:17:51 +00:00
Author
Owner

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

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

**@⁠omonkeyz** on GitHub · 2026-11-25 13:48 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/301#issuecomment-7164330048) Applied on main in 3e70f78 (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.