Skip to content

shader-compiler: Lower wave32 masked DPP prefixes and totals in wave allocation - #181

Merged
brcly merged 4 commits into
brcly:mainfrom
s3rius:shaderx/wave32-masked-dpp
Nov 26, 2026
Merged

brcly merged 4 commits into
brcly:mainfrom
s3rius:shaderx/wave32-masked-dpp

Conversation

@s3rius

@s3rius s3rius commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Lower wave32 masked DPP prefixes and totals in wave allocation. prepare now handles prefixes (always) and pixel totals (always); compute totals are left for wave_sum. Added lower_problematic_totals/total_to_wave_active_sum in wave_alloc.rs and, in the lockstep-failure branch of pipeline.rs, lowers the totals that wave_sum rejects on divergent control flow to WaveActiveSum before re-validating. Extracted check_region from wave_sum.rs so wave_alloc reuses the exact per-region control-flow check. Full suite: 303 lib + 2 integration pass; 30/32 target shaders compile (the 2 remaining fail on a pre-existing, unrelated constant-lane gather limitation).

Verified on Lanes

A pull request is not merged until Lanes passes on a GPU. Run:

python tuxbox.py check
  • python tuxbox.py check passed on this branch
  • Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below

GPU, driver and backend:

Paste the summary printed at the end:

Summary
  passed   Build the shader compiler (8s)
  passed   Python tests (3s)
  passed   Shader compiler tests (3s)
  passed   DXBC tests (0s)
  passed   XG layout tests (1s)
  passed   D3D12 Windows typecheck (1s)
  passed   Build (28s)
  passed   Lanes and fixtures on the GPU (261s)
  passed   D3D12 regression controls (683s)
  passed   Shader translator on the GPU (662s)

All checks passed. Attach the GPU results to the pull request

Checks

CI runs the Python unit tests, the shader compiler, DXBC, and XG layout tests, and a Windows typecheck of tuxbox-d3d12.

If this pull request changes evidence JSON, regenerate the results table and the progress map and include both files:

python tuxbox.py status > docs/RESULTS.md
python tuxbox.py status --svg docs/progress.svg

@s3rius
s3rius marked this pull request as draft November 25, 2026 17:40
@brcly

brcly commented Nov 25, 2026

Copy link
Copy Markdown
Owner

im gonna hold on this for now, as locally, this caused compilation failures for myself. i will look into it

@s3rius
s3rius marked this pull request as ready for review November 25, 2026 19:32
@s3rius
s3rius force-pushed the shaderx/wave32-masked-dpp branch from 663e87d to b6a1d4c Compare November 25, 2026 19:58
@s3rius

s3rius commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

@brcly , okay, did some updates tho. Can you try it once again? It also was failing on my machine before. Now it passes.

@tsunderejay

Copy link
Copy Markdown

Automated review against current main found a blocking correctness issue: the new wave32/fallback paths no-op DPP bodies without retaining the previous liveness proof for scratch registers. A later read of a nopped temporary can therefore receive stale/undefined data, and this also regresses the older wave64 pixel lowering. Please restore/adapt the dead-register proof and add a negative test. The current smoke test also does not write/verify the prefix result, so it cannot detect a numerical miscompile.

@s3rius s3rius changed the title Lower wave32 masked DPP prefixes and totals in wave allocation shader-compiler: Lower wave32 masked DPP prefixes and totals in wave allocation Nov 25, 2026
@s3rius
s3rius marked this pull request as draft November 25, 2026 23:27
@s3rius
s3rius marked this pull request as ready for review November 26, 2026 00:00
@s3rius
s3rius marked this pull request as draft November 26, 2026 00:00
@s3rius
s3rius marked this pull request as ready for review November 26, 2026 00:22
@s3rius
s3rius force-pushed the shaderx/wave32-masked-dpp branch from 5c0f31d to b488e50 Compare November 26, 2026 00:23
@s3rius

s3rius commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

@tsunderejay, can you re-verify this PR with the latest changes?

@s3rius
s3rius force-pushed the shaderx/wave32-masked-dpp branch from b488e50 to eeb5ee0 Compare November 26, 2026 00:25
@s3rius

s3rius commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Okay, nevermind. I rebased on main and it has more errors now.

@brcly

brcly commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Gonna hold off on this just now as I'm working on a fix for differentiating AMD and Nvidia GPU's

Main will be updated when it's implemented.

I will eventually move to branches and such; it's just in this part of development. I'm trying to get something that's as close to "working" as possible before going after certain individual improvements.

I didn't expect this repo to blow up as quickly as it did and for so many people to help drive it to a usable state.

I thank you for your efforts so far, we'll get there!

@s3rius

s3rius commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Okay. NP. Do you have any direction which I can look that that will not interfere with your upcoming changes?

@s3rius
s3rius force-pushed the shaderx/wave32-masked-dpp branch from eeb5ee0 to 38842d2 Compare November 26, 2026 01:45
@s3rius

s3rius commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Rebased on top of main with applying changes.

@s3rius
s3rius force-pushed the shaderx/wave32-masked-dpp branch from 38842d2 to 679e2fe Compare November 26, 2026 03:07
@s3rius

s3rius commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Rebased once again + ran GPU tests.

@s3rius
s3rius force-pushed the shaderx/wave32-masked-dpp branch 2 times, most recently from 42c8c2d to c1758cf Compare November 26, 2026 12:55
@brcly

brcly commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Thanks for sticking with this through the rebases. I tested it merged onto current main (f3149ab), with #226, #210 and #225 alongside it for the GPU check. Two things need fixing before it can merge.

1. lanes-shader-cache-wave-alloc fails on AMD

  • NVIDIA (RTX 4070 Ti SUPER, GE-Proton11-14): the full tuxbox.py check passed.
  • AMD (Radeon 610M 1002:13c0, RADV Mesa 26.3.1, GE-Proton11-14, host wave 32-64): this was the only failure, with wave-alloc shader stored the wrong prefix result (or stored nothing).

This looks like a race in the test rather than in the lowering. In the translated HLSL all 32 threads are active at the final buffer_store_dword, and each stores its own prefix value to byte offset 0 (v8 = 0). Which write lands last isn't defined, so the readback is 0 only if lane 0's store happens to win. The test comment expects a single active lane, but s_or_saveexec_b32 s0, -1 enables all of them, and exec is then restored to s0, which every thread sees as set.

Suggested fix: give each lane its own offset (keep the thread ID before v0 is overwritten) and check all 32 values against 0..31. That removes the race and tests the prefix result much more thoroughly.

2. Two game shaders stop translating

I translated 40,548 recorded ProjectScarlett requests with main and with this PR merged onto it:

Build Requests that translate
main 35,832
with this PR 35,830

None are gained and two are lost (009e1e82…, 1dc7a878…). Both translate on main and are refused here with wave reduction in divergent control flow. It looks like the new check rejects programs the existing path already handles. Could it fall back to the previous behaviour when it can't prove the new lowering?

On these recorded requests the PR doesn't translate anything main refuses. Is there a program it newly enables? That would make a good coverage case.

@s3rius
s3rius force-pushed the shaderx/wave32-masked-dpp branch from c1758cf to e162cb2 Compare November 26, 2026 15:58
Signed-off-by: Pavel Kirilin <s3riussan@gmail.com>
Signed-off-by: Pavel Kirilin <s3riussan@gmail.com>
Signed-off-by: Pavel Kirilin <s3riussan@gmail.com>
Signed-off-by: Pavel Kirilin <s3riussan@gmail.com>
@s3rius
s3rius force-pushed the shaderx/wave32-masked-dpp branch from e162cb2 to 0fd78a7 Compare November 26, 2026 16:00
@s3rius

s3rius commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Hello. Thanks for your reply.

  1. This should be addressed now.
  2. About missing translations. First of, the behavior for missing shaders was fixed. If this wave lowering cannot happen, it fallsback to the previous behavior now. Which makes the whole corpus of requests pass. I also ran this PR against my 48040 collected requests and also got the same 37452 translated requests as on main. However, I'm sure that in previous runs I had some shaders that were failing exactly because of this issue. Could be that one of requests fixed emitting such requests. But it's just good to support anyway.

@brcly
brcly merged commit 0eb91a8 into brcly:main Nov 26, 2026
2 checks passed
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.

3 participants