Keep mesh shader barriers in their branch context #76

Closed
github-bot wants to merge 1 commit from gh-pr/76/head into gh-pr/76/base
Owner

@⁠thatirishguyyy on GitHub · 2026-11-21 23:31 UTC · original
thatirishguyyy:preserve-mesh-barrier-control-flow → main · +0 −5 · 1 files · 1 commits · closed without merging

The forward-branch emitter closes its branch guard immediately before a mesh s_barrier. This stops mesh_barrier from seeing that the barrier was conditional.

Keep the guard in place so the existing policy can omit a conditional barrier in memory-free shaders and refuse the case when LDS or memory writes are present. The existing unconditional barrier path still runs outside branch guards.

Verification on Windows: 60 passed across the library, mesh and opcode suites, with three fixture-dependent tests ignored. The three previously failing mesh barrier cases now pass, including the triangle rendering test.

**@⁠thatirishguyyy** on GitHub · 2026-11-21 23:31 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/76) `thatirishguyyy:preserve-mesh-barrier-control-flow` → `main` · +0 −5 · 1 files · 1 commits · closed without merging The forward-branch emitter closes its branch guard immediately before a mesh s_barrier. This stops mesh_barrier from seeing that the barrier was conditional. Keep the guard in place so the existing policy can omit a conditional barrier in memory-free shaders and refuse the case when LDS or memory writes are present. The existing unconditional barrier path still runs outside branch guards. Verification on Windows: 60 passed across the library, mesh and opcode suites, with three fixture-dependent tests ignored. The three previously failing mesh barrier cases now pass, including the triangle rendering test.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:09:33 +00:00
github-bot closed this pull request 2026-11-26 06:09:33 +00:00
Author
Owner

@⁠QuentinDanblon on GitHub · 2026-11-21 23:42 UTC · original

Ran this on Windows, head 35bad0a, cargo test -p tombox-xshader --release --test mesh:

WARP RTX 5090 (TOMBOX_EXEC_HW=1)
main (8491769, tombox-xshader unchanged since) 10 passed, 3 failed 10 passed, 3 failed
this PR 13 passed, 0 failed, 1 ignored 13 passed, 0 failed, 1 ignored
this PR merged with #58 15 passed, 0 failed, 1 ignored 15 passed, 0 failed, 1 ignored

It merges cleanly with #58 and #73.

One thing for @⁠omonkeyz to decide, since I reported the same three tests in #70 and left them alone: the five lines removed here were added in 8491769, the commit that made the tests fail, and the tests are older. So either the rule or the tests are stale.

A data point for that choice. I kept the rule as it is on main and only changed the expected barrier count from 3 to 4 locally: gpu_mesh_divergent_barrier_without_memory_writes then passes on WARP and on the 5090, with the expected [2 * 128 + 64, 1, 0x77, 0x88]. So for a shader without LDS or memory writes, both behaviours draw the same thing. They differ only when the shader writes LDS or memory: main translates it with the barrier moved out of the branch guard (every thread syncs, and the guard reopens on the same j flags), this PR goes back to the refusal. I have no title shader that hits that case, so I can't say which one a real game needs.

**@⁠QuentinDanblon** on GitHub · 2026-11-21 23:42 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/76#issuecomment-7071052112) Ran this on Windows, head `35bad0a`, `cargo test -p tombox-xshader --release --test mesh`: | | WARP | RTX 5090 (`TOMBOX_EXEC_HW=1`) | |---|---|---| | main (`8491769`, `tombox-xshader` unchanged since) | 10 passed, 3 failed | 10 passed, 3 failed | | this PR | 13 passed, 0 failed, 1 ignored | 13 passed, 0 failed, 1 ignored | | this PR merged with #58 | 15 passed, 0 failed, 1 ignored | 15 passed, 0 failed, 1 ignored | It merges cleanly with #58 and #73. One thing for @⁠omonkeyz to decide, since I reported the same three tests in #70 and left them alone: the five lines removed here were added in `8491769`, the commit that made the tests fail, and the tests are older. So either the rule or the tests are stale. A data point for that choice. I kept the rule as it is on main and only changed the expected barrier count from 3 to 4 locally: `gpu_mesh_divergent_barrier_without_memory_writes` then passes on WARP and on the 5090, with the expected `[2 * 128 + 64, 1, 0x77, 0x88]`. So for a shader without LDS or memory writes, both behaviours draw the same thing. They differ only when the shader writes LDS or memory: main translates it with the barrier moved out of the branch guard (every thread syncs, and the guard reopens on the same `j` flags), this PR goes back to the refusal. I have no title shader that hits that case, so I can't say which one a real game needs.
Author
Owner

@⁠thatirishguyyy on GitHub · 2026-11-22 02:06 UTC · original

Thanks for verifying this on WARP and the RTX 5090, @⁠QuentinDanblon. Upstream commit 59e5ed75c3 already removes the same barrier hoist. I checked that this PR produces an identical tree when merged into current main. The mesh suite passed on main, including the three cases discussed here. Closing as already addressed.

**@⁠thatirishguyyy** on GitHub · 2026-11-22 02:06 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/76#issuecomment-7072678675) Thanks for verifying this on WARP and the RTX 5090, @⁠QuentinDanblon. Upstream commit 59e5ed75c34bf159090e686e93e87474a232d8aa already removes the same barrier hoist. I checked that this PR produces an identical tree when merged into current main. The mesh suite passed on main, including the three cases discussed here. Closing as already addressed.

Pull request closed

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