Keep mesh shader barriers in their branch context #76

Closed
thatirishguyyy wants to merge 0 commits from upstream-pr/76 into main
thatirishguyyy commented 2026-11-21 23:31:20 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by thatirishguyyy on 2026-11-21T23:31:20Z.


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.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:issue:6535803896 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/76). Originally posted by [thatirishguyyy](https://github.com/thatirishguyyy) on 2026-11-21T23:31:20Z. --- 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.
QuentinDanblon commented 2026-11-21 23:42:31 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by QuentinDanblon on 2026-11-21T23:42:31Z.


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.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7071052112 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/76#issuecomment-7071052112). Originally posted by [QuentinDanblon](https://github.com/QuentinDanblon) on 2026-11-21T23:42:31Z. --- 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.
thatirishguyyy commented 2026-11-22 02:06:47 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by thatirishguyyy on 2026-11-22T02:06:47Z.


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.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7072678675 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/76#issuecomment-7072678675). Originally posted by [thatirishguyyy](https://github.com/thatirishguyyy) on 2026-11-22T02:06:47Z. --- 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

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
omonkeyz/xbox-emulator!76
No description provided.