Shaders: a folded program refused for a lane mask read as data is folded again with every lane-mask branch taken wave-wide #501

Open
ntsthay wants to merge 1 commit from ntsthay/fold-every-lane into Main AGit
Contributor

Contributor role (optional)

  • Fluxer ID:

What it changes

On a 32-lane host, the folded form (docs/wave64-folded.md) turned some programs down with "a lane mask holding lanes elsewhere read as data". Those programs then fell to the approximate local waves. Three of them in GTA VI 1.0.2.1 do this:

  • CS_ClusterLightsWorldSpace (d3e5b737ea7cc150)
  • CS_ClusterLightsWorldSpaceIntensityBased (55d2bce91ec9abcc)
  • CS_RTConstantCostShadowsTileClassificationNormalCones (2620618869072a85)

The light clustering programs walk the set bits of a ballot in a scalar loop (s_ff1, then the bit is cleared), with the mask carried around the loop. The tile classifier takes a lane rank (v_mbcnt) of EXEC as it was restored after a one-lane section. The bits these masks hold are fixed by the console's rules: a VOPC writes 0 for lanes that do not run, and the scalar operations work on plain dwords. The lowering refuses them only because, with per-lane branches, it cannot prove that every lane with a set bit reaches the block where it would take the ballot.

folded() in emit/mod.rs now tries once more after that refusal. It structures the program again with every branch on a lane mask taken wave-wide, then tracks and lowers it again. In the folded form one host wave holds one whole console wave, so wave-wide branches are the console's own control flow. Every block then has all its lanes (every_lane), and the ballot mask_dword takes is the console's mask. folded() already does this for programs with LDS or barriers (wave_wide_branches); this applies it after the refusal, for any folded program.

  • It only runs after the refusal, so a program that translates today comes out byte for byte as before.
  • Programs whose dispatch is counted in threads (a spilled user-data table) keep the refusal. The lanes past the count stay under partial_active, which the lowering ANDs into active masks only, and a whole-wave ballot would count them.
  • DARNER_WAVE_WHY=1 prints WAVE64-FOLD refused for a mask read as data: <n> lane-mask branches taken wave-wide.

How it was tested

  • Tested revision: the commit of this PR on main d91d8e4.
  • Two new GPU tests in emit/folded_tests.rs. Both are refused with "a lane mask holding lanes elsewhere read as data" before the change and pass after it, bit for bit against the console's lanes.
    • a_ballot_walked_bit_by_bit_reaches_every_lane: the light clustering loop, plain and inside a v_cmpx / s_cbranch_execz region.
    • a_lane_rank_after_a_first_lane_section_counts_the_lanes_restored: the tile classifier's lane rank.
  • cargo test -p darner-shader --lib folded: 27 passed, on an RTX 4080 under Proton (proton-cachyos, driver 620.73).
  • cargo clippy --workspace --all-targets --locked -- -D warnings, and the same with --all-features: clean.
  • cargo test -p darner-shader --lib under Proton: every test passes but four, the same four that fail on main in this Wine (stub_pipeline_is_created, a_ray_query_program_validates_and_makes_a_pipeline_on_warp, split_lds_wave32_read_after_read_barrier_coalescing_and_parity, whole_wave_sections_keep_rounding_mode_changes; #349 is about them).
  • darner translate of the title with DARNER_HOST_WAVE=32 DARNER_WAVE_WHY=1: the three programs now come out folded (before wave-wide), after 77, 77 and 108 lane-mask branches taken wave-wide. In a census of the whole title, they were three of the 16 programs still in an approximate form.
  • Changes a default: yes, for those three programs only. They used to translate approximately and now translate exactly. Every other program translates as before.
  • In game (RTX 4080, Series S profile, hardware RT, DLAA): a 4-minute unattended run from a story save on our integration branch, which carries this commit, with the three programs folded. No device loss, and nothing out of place in the captured frames. Frames took about 41 ms, GPU-bound, with ray reconstruction on; I did not measure this change against main side by side.

Checklist

  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md.
  • I recorded this PR's dependencies below.
    • None.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs:
    • #33 makes CS_ClusterLightsWorldSpace exact on 32-lane hosts another way, by putting it on the wave-wide list (group barriers in the branches). Here it folds instead, so one host wave holds the whole console wave and needs no barriers. I have not measured the two forms against each other. If both land, the program should take only one of them.
    • #312 changes how folded v_readfirstlane and v_movrel are treated. It does not touch folded() or the refusal this PR retries on.
## Contributor role (optional) - Fluxer ID: ## What it changes On a 32-lane host, the folded form (`docs/wave64-folded.md`) turned some programs down with "a lane mask holding lanes elsewhere read as data". Those programs then fell to the approximate local waves. Three of them in GTA VI 1.0.2.1 do this: - `CS_ClusterLightsWorldSpace` (`d3e5b737ea7cc150`) - `CS_ClusterLightsWorldSpaceIntensityBased` (`55d2bce91ec9abcc`) - `CS_RTConstantCostShadowsTileClassificationNormalCones` (`2620618869072a85`) The light clustering programs walk the set bits of a ballot in a scalar loop (`s_ff1`, then the bit is cleared), with the mask carried around the loop. The tile classifier takes a lane rank (`v_mbcnt`) of EXEC as it was restored after a one-lane section. The bits these masks hold are fixed by the console's rules: a VOPC writes 0 for lanes that do not run, and the scalar operations work on plain dwords. The lowering refuses them only because, with per-lane branches, it cannot prove that every lane with a set bit reaches the block where it would take the ballot. `folded()` in `emit/mod.rs` now tries once more after that refusal. It structures the program again with every branch on a lane mask taken wave-wide, then tracks and lowers it again. In the folded form one host wave holds one whole console wave, so wave-wide branches are the console's own control flow. Every block then has all its lanes (`every_lane`), and the ballot `mask_dword` takes is the console's mask. `folded()` already does this for programs with LDS or barriers (`wave_wide_branches`); this applies it after the refusal, for any folded program. - It only runs after the refusal, so a program that translates today comes out byte for byte as before. - Programs whose dispatch is counted in threads (a spilled user-data table) keep the refusal. The lanes past the count stay under `partial_active`, which the lowering ANDs into active masks only, and a whole-wave ballot would count them. - `DARNER_WAVE_WHY=1` prints `WAVE64-FOLD refused for a mask read as data: <n> lane-mask branches taken wave-wide`. ## How it was tested - Tested revision: the commit of this PR on main `d91d8e4`. - Two new GPU tests in `emit/folded_tests.rs`. Both are refused with "a lane mask holding lanes elsewhere read as data" before the change and pass after it, bit for bit against the console's lanes. - `a_ballot_walked_bit_by_bit_reaches_every_lane`: the light clustering loop, plain and inside a `v_cmpx` / `s_cbranch_execz` region. - `a_lane_rank_after_a_first_lane_section_counts_the_lanes_restored`: the tile classifier's lane rank. - `cargo test -p darner-shader --lib folded`: 27 passed, on an RTX 4080 under Proton (proton-cachyos, driver 620.73). - `cargo clippy --workspace --all-targets --locked -- -D warnings`, and the same with `--all-features`: clean. - `cargo test -p darner-shader --lib` under Proton: every test passes but four, the same four that fail on main in this Wine (`stub_pipeline_is_created`, `a_ray_query_program_validates_and_makes_a_pipeline_on_warp`, `split_lds_wave32_read_after_read_barrier_coalescing_and_parity`, `whole_wave_sections_keep_rounding_mode_changes`; #349 is about them). - `darner translate` of the title with `DARNER_HOST_WAVE=32 DARNER_WAVE_WHY=1`: the three programs now come out `folded (before wave-wide)`, after 77, 77 and 108 lane-mask branches taken wave-wide. In a census of the whole title, they were three of the 16 programs still in an approximate form. - Changes a default: yes, for those three programs only. They used to translate approximately and now translate exactly. Every other program translates as before. - In game (RTX 4080, Series S profile, hardware RT, DLAA): a 4-minute unattended run from a story save on our integration branch, which carries this commit, with the three programs folded. No device loss, and nothing out of place in the captured frames. Frames took about 41 ms, GPU-bound, with ray reconstruction on; I did not measure this change against main side by side. ## Checklist - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. - [x] I recorded this PR's dependencies below. - None. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: - #33 makes `CS_ClusterLightsWorldSpace` exact on 32-lane hosts another way, by putting it on the wave-wide list (group barriers in the branches). Here it folds instead, so one host wave holds the whole console wave and needs no barriers. I have not measured the two forms against each other. If both land, the program should take only one of them. - #312 changes how folded `v_readfirstlane` and `v_movrel` are treated. It does not touch `folded()` or the refusal this PR retries on.
ntsthay changed title from Shaders: a folded program refused for a lane mask read as data is folded again with every lane-mask branch taken wave-wide to [pr-fix][shaders] Shaders: a folded program refused for a lane mask read as data is folded again with every lane-mask branch taken wave-wide 2026-12-05 04:48:10 +00:00
First-time contributor

Tested merged on c8258f9 through a complete 16-minute release shader preload (41.9 MB log) + two 30,000+ frame Series X gameplay sessions on RTX 5070 Ti (DARNER_RDNA_FLOAT=2, DARNER_SAMPLED_MARKS=0):

  • Built cleanly (clippy --all-features -D warnings & tests passing) and ran without shader crashes or visual regressions.
  • Diagnostic data point from our preload log: one remaining compute shader still failed with converter shader.dxil v1: GFX10 code at 0xae80: a lane mask holding lanes elsewhere read as data is not supported — hash dbdbf36298727135 (stage="compute", 329–455 ms), in case that dump helps extend coverage further.
Tested merged on `c8258f9` through a complete 16-minute release shader preload (`41.9 MB` log) + two 30,000+ frame Series X gameplay sessions on RTX 5070 Ti (`DARNER_RDNA_FLOAT=2`, `DARNER_SAMPLED_MARKS=0`): - Built cleanly (`clippy --all-features -D warnings` & tests passing) and ran without shader crashes or visual regressions. - **Diagnostic data point from our preload log**: one remaining compute shader still failed with `converter shader.dxil v1: GFX10 code at 0xae80: a lane mask holding lanes elsewhere read as data is not supported` — hash `dbdbf36298727135` (`stage="compute"`, `329–455 ms`), in case that dump helps extend coverage further.
TrustNo1 changed title from [pr-fix][shaders] Shaders: a folded program refused for a lane mask read as data is folded again with every lane-mask branch taken wave-wide to Shaders: a folded program refused for a lane mask read as data is folded again with every lane-mask branch taken wave-wide 2026-12-06 03:27:54 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/501/head:ntsthay/fold-every-lane'
git switch 'ntsthay/fold-every-lane'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'Main'
git merge --no-ff 'ntsthay/fold-every-lane'
git switch 'ntsthay/fold-every-lane'
git rebase 'Main'
git switch 'Main'
git merge --ff-only 'ntsthay/fold-every-lane'
git switch 'ntsthay/fold-every-lane'
git rebase 'Main'
git switch 'Main'
git merge --no-ff 'ntsthay/fold-every-lane'
git switch 'Main'
git merge --squash 'ntsthay/fold-every-lane'
git switch 'Main'
git merge --ff-only 'ntsthay/fold-every-lane'
git switch 'Main'
git merge 'ntsthay/fold-every-lane'
git push origin 'Main'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
TrustNo1/Darner!501
No description provided.