Mesh outputs: a primitive's cull starts false (changes translation output) #55

Manually merged
github merged 1 commit from gh-pr/55/head into gh-pr/55/base 2026-11-27 03:15:58 +00:00
Owner

@⁠Sr-0w on GitHub · 2026-11-26 05:04 UTC · original
Sr-0w:shaders/mesh-cull-written-once → main · +18 −9 · 3 files · 1 commits · merged 2026-11-26 06:49 UTC

Fixes #54.

What

A direct-export mesh program initialises every primitive of its count right after SetMeshOutputCounts (MeshDeclarations.InitialPrimitives). The initial SV_CullPrimitive value is now false instead of true. A primitive is still initialised as the degenerate triangle (0, 0, 0), which covers no pixel, so a primitive the program never exports still draws nothing. Every primitive also stays initialised, which keeps the VIctory #587 guard against NVIDIA's hang. The cut epilogue, which writes true later, is unchanged.

Why

AMD's driver (RX 7800 XT, 64-lane mesh waves) keeps a primitive culled once its SV_CullPrimitive has been written true. A later false is lost, while a later true is kept. Every translated mesh program wrote true first and the real value at its export, so on this GPU no mesh primitive ever reached the rasterizer.

It reproduces without the game, with the existing cases run on the GPU (FIVESTAR_TEST_ADAPTER=hardware):

MeshShaderTests + MeshRoundBoundTests on the RX 7800 XT before after
native mesh cases (dxc and the DXIL backend) every one draws 0 pixels, all counters 0 pass
fallback cases (msfb_*) pass pass
total most fail 24 / 24 pass

The rule was narrowed by editing the translated ms_ngg_strips. Primitive counts at the clipper, versus WARP's 15:

change clipper
none 0
no cull = true before the export 15
initial cull = false 15
only cull = true initialised, indices not 0
no primitive output at all 16 (the case's culled primitive is drawn)

A hand-written mesh shader with no rewrite draws on the same GPU, and its counters are right (clipper 1, PS 256).

In game (a retail game, RX 7800 XT, world frame, main 6c87fd14 + #52 + #53)

before after
traced mesh draws: MS primitives / clipper / PS 0 / 0 / 0 (128 of 128 draws) up to 23,320 / 23,320 / 35,995 per draw
depth buffer, pixels written 0 3,686,400 (the whole screen; the terrain's relief is visible)
G-buffer normal target empty vehicles (cars, a truck, a pickup)
median world frame (last 200) 377 ms 975 ms (the world's geometry is now drawn, and part of its pipelines are still building)

The presented image of the traced runs above is black before and after the fix, but that comes from the draw trace (--d3d12-trace-draws with target dumps): an untraced run with the fix shows the night city on the horizon, with the terrain now drawn as a dark foreground in front of it (its albedo is still black, as in Status.md), at about 9 fps on the in-game counter.

Tests

  • MeshRoundBoundTests now checks that the initial write is tris = (0,0,0) with cull = false, and that no cull = true appears before the export.
  • Every suite passes on WARP (Shaders 492, Loader 430, Architecture 31, Cli 13, Formats 23, Debugger 2).
  • The mesh suites pass on the RX 7800 XT (24 / 24).
  • docs/shader-translation.md is updated.

🤖 Generated with Claude Code

**@⁠Sr-0w** on GitHub · 2026-11-26 05:04 UTC · [original](https://github.com/ThatRecompDev/five-star-recomp/pull/55) `Sr-0w:shaders/mesh-cull-written-once` → `main` · +18 −9 · 3 files · 1 commits · merged 2026-11-26 06:49 UTC Fixes #54. ## What A direct-export mesh program initialises every primitive of its count right after `SetMeshOutputCounts` (`MeshDeclarations.InitialPrimitives`). The initial `SV_CullPrimitive` value is now `false` instead of `true`. A primitive is still initialised as the degenerate triangle `(0, 0, 0)`, which covers no pixel, so a primitive the program never exports still draws nothing. Every primitive also stays initialised, which keeps the VIctory #587 guard against NVIDIA's hang. The cut epilogue, which writes `true` later, is unchanged. ## Why AMD's driver (RX 7800 XT, 64-lane mesh waves) keeps a primitive culled once its `SV_CullPrimitive` has been written `true`. A later `false` is lost, while a later `true` is kept. Every translated mesh program wrote `true` first and the real value at its export, so on this GPU no mesh primitive ever reached the rasterizer. It reproduces without the game, with the existing cases run on the GPU (`FIVESTAR_TEST_ADAPTER=hardware`): | `MeshShaderTests` + `MeshRoundBoundTests` on the RX 7800 XT | before | after | |---|---|---| | native mesh cases (dxc and the DXIL backend) | every one draws 0 pixels, all counters 0 | pass | | fallback cases (`msfb_*`) | pass | pass | | total | most fail | 24 / 24 pass | The rule was narrowed by editing the translated `ms_ngg_strips`. Primitive counts at the clipper, versus WARP's 15: | change | clipper | |---|---| | none | 0 | | no `cull = true` before the export | 15 | | initial `cull = false` | 15 | | only `cull = true` initialised, indices not | 0 | | no primitive output at all | 16 (the case's culled primitive is drawn) | A hand-written mesh shader with no rewrite draws on the same GPU, and its counters are right (clipper 1, PS 256). ## In game (a retail game, RX 7800 XT, world frame, main 6c87fd14 + #52 + #53) | | before | after | |---|---|---| | traced mesh draws: MS primitives / clipper / PS | 0 / 0 / 0 (128 of 128 draws) | up to 23,320 / 23,320 / 35,995 per draw | | depth buffer, pixels written | 0 | 3,686,400 (the whole screen; the terrain's relief is visible) | | G-buffer normal target | empty | vehicles (cars, a truck, a pickup) | | median world frame (last 200) | 377 ms | 975 ms (the world's geometry is now drawn, and part of its pipelines are still building) | The presented image of the traced runs above is black before and after the fix, but that comes from the draw trace (`--d3d12-trace-draws` with target dumps): an untraced run with the fix shows the night city on the horizon, with the terrain now drawn as a dark foreground in front of it (its albedo is still black, as in Status.md), at about 9 fps on the in-game counter. ## Tests - `MeshRoundBoundTests` now checks that the initial write is `tris = (0,0,0)` with `cull = false`, and that no `cull = true` appears before the export. - Every suite passes on WARP (Shaders 492, Loader 430, Architecture 31, Cli 13, Formats 23, Debugger 2). - The mesh suites pass on the RX 7800 XT (24 / 24). - `docs/shader-translation.md` is updated. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A direct-export mesh program initialised every primitive of its count right after SetMeshOutputCounts as the
triangle (0, 0, 0) with SV_CullPrimitive true, and its export later wrote the real indices and cull. AMD's driver (RX
7800 XT) keeps a primitive culled once its cull was written true: the export's false was lost, so every mesh pass
handed the rasterizer no primitive (hardware counters: mesh invocations, 0 mesh primitives, 0 clipper, 0 pixel
shader), and the world's G-buffer stayed empty. On that GPU every native mesh case of MeshShaderTests drew no pixel
with FIVESTAR_TEST_ADAPTER=hardware; a later true is kept, and the indices may be written twice.

The cull now starts false. The degenerate triangle (0, 0, 0) still covers no pixel for a primitive the program never
exports, and every primitive stays initialised (uninitialised ones hung NVIDIA's mesh pipeline, VIctory #587). The cut
epilogue's later true is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 03:15:56 +00:00
github manually merged commit 751ea7277a into gh-pr/55/base 2026-11-27 03:15:58 +00:00
Author
Owner

@⁠ThatRecompDev on GitHub · 2026-11-26 07:30 UTC · original

this is a great find, and the repro table without the game makes it really convincing

the degenerate (0,0,0) init still covers the NVIDIA hang guard, so I'm happy with it. it went in with the translator batch, booting it here now to check nothing regresses on our side

thanks for chasing this down

**@⁠ThatRecompDev** on GitHub · 2026-11-26 07:30 UTC · [original](https://github.com/ThatRecompDev/five-star-recomp/pull/55#issuecomment-7185524733) this is a great find, and the repro table without the game makes it really convincing the degenerate (0,0,0) init still covers the NVIDIA hang guard, so I'm happy with it. it went in with the translator batch, booting it here now to check nothing regresses on our side thanks for chasing this down
This discussion has been locked. Commenting is limited to contributors.
No description provided.