Skip to content

Mesh shaders: seed v5 as groupIndex * NumThreads + lane - #2

Open
TheAirborneCoder wants to merge 10000 commits into
TheAirborneCoder:mainfrom
ItsNotRexed:main
Open

TheAirborneCoder wants to merge 10000 commits into
TheAirborneCoder:mainfrom
ItsNotRexed:main

Conversation

@TheAirborneCoder

Copy link
Copy Markdown
Owner

What and why

The mesh prologue in tools/rdna2spirv.py wrote the linear workgroup index straight into v5, identical and unshifted for every invocation. The game's mesh entry reads v5 from the first active lane and shifts it right by 7 before using it as the meshlet/group index (lane-0 v5 >> 7 goes into an LDS broadcast to both waves, then is compared against the meshlet count in the header). That only works if v5 holds the first launch vertex ID, groupIndex * 128 + lane.

With the old seeding the shader computes groupIndex >> 7: every group below 128 resolves to meshlet 0, and each block of 128 groups shares one meshlet, so most geometry is drawn as duplicates of a few meshlets.

Fix: seed v5 per invocation as linearGroupIndex * NumThreads + LocalInvocationIndex, with NumThreads from PSV0 (128 in this corpus). The s3 seeding already matches. Comments and the Mesh shaders row in docs/design.md are updated.

Evidence:

  • The >> 7 is in the game's native mesh entry sequence, before the meshlet header read.
  • TomBox (MIT/Apache), an independent translator of the same ABI, uses v5 = gid.x * numThreads + gi (crates/tombox-xshader/src/hlsl/mesh.rs, ~line 227).
  • Matches AMD's NGG launch model on GFX10.3, where v5 is the per-lane vertex-ID slot.

Tested

  • python -m py_compile tools/rdna2spirv.py passes.
  • Not yet run: the translator over the corpus (spirv-val before/after) and the ms_tri GPU test. ms_tri has no >> 7 step, so it would not catch this regression either way.
  • Not confirmed on Xbox hardware. It rests on the game's own code plus TomBox's independent mapping.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.
    (The existing mesh row is updated. Leave this unchecked unless you want to add a confirmation note.)

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.