tombox-xshader / d3d12_xs: Hull and Domain shader translation (tessellation) — design proposal #294
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
library
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/omonkeyz--xbox-emulator#294
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@nickfmbg on GitHub · 2026-11-23 16:37 UTC · original
Area:
tombox-xshader(newhlsl/tess.rs), laterd3d12_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_withreturnsstage 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:
v0patch id,v1rel ids (rel patch id[7:0], control point id[12:8]), then the LS VGPRsSystem SGPRs of the merged HS on GFX10 are
s0off-chip offset,s1merged wave info,s2TF offset,s3scratch offset, then 2 more system SGPRs; user data starts ats8. 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_vgprsfor GFX10 merged VS-TCS) andsrc/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 word0x80000000at 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:
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 twoRWByteAddressBuffers. The ring descriptors are recognised the same way the GS ring table would be, from the internal table ats[0:1].SV_PrimitiveIDfrom 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.SV_DomainLocationfeeds tess u/v andSV_PrimitiveIDfeeds 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.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
ShaderExtract. The patch constant signature already lands inprim_sig(PSG1). Unit tests only.Stages stay
partialuntil real titles' shaders pass, per your criteria in #187.Questions for you
xshaderon 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.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?