Skip to content

Shaders: narrow divergent scalar state detection - #14

Open
mohammadallami75-ops wants to merge 4 commits into
r4tedx:shader/wave-per-groupfrom
mohammadallami75-ops:shader/refined-scalar-state
Open

mohammadallami75-ops wants to merge 4 commits into
r4tedx:shader/wave-per-groupfrom
mohammadallami75-ops:shader/refined-scalar-state

Conversation

@mohammadallami75-ops

@mohammadallami75-ops mohammadallami75-ops commented Nov 24, 2026 •

Copy link
Copy Markdown

Part 2 of the scalar-state review. The base is shader/wave-per-group at c734600, which carries r4tedx’s broadened mask handling and the fixtures from #13.

Shader change

The detector identifies Wave64 compute shaders where a scalar updated in divergent control flow is read after the paths rejoin. Eligible shaders use console flow to preserve the wave-wide scalar value. Wave32 programs, non-compute stages and analysis that exceeds the diagram size limit keep their existing lowering. Unsupported console-flow cases can fall back to per-lane lowering.

Windows CI follow-up

The previous CI run stopped with an access violation in the shader test process. The four new portable scalar fixtures ran WARP outside the lock already shared by the VALU and waterfall tests. d21eb16 takes the same lock for their readbacks. Shader translation is identical to 7d97aa8.

Synthetic verification

  • On the RTX 2080 SUPER (driver 621.01, host Wave32), the scalar patch corrected all four previously reported readback cases.
  • With the CI follow-up, all 25 focused tests passed with 12 test threads and DXIL validation. The four portable fixtures still matched their CPU reference on the RTX and on WARP. Shader-test Clippy and rustfmt passed.
  • The pending offline comparison is c734600 versus d21eb16 at 32-32 and 32-64. A second physical Wave32 adapter run is still open. The reviewer also plans to bring two existing translator safeguards into the base before merge. Game rendering and frame rate remain unmeasured.

AI-assisted.

Keep the maintainer's joined-mask lowering, preserve the distinct scalar-state detection, and retain both regression sets.

AI-assisted.
@mohammadallami75-ops

Copy link
Copy Markdown
Author

Updated this branch to c734600 in 7d97aa8. The merge keeps r4tedx's joined-mask handling and gives scalar values that survive divergent Wave64 control flow the same wave-wide execution as on the console. The fallback and both sets of regression tests are retained.

I ran the same synthetic shaders and compared GPU readback against a CPU reference on an RTX 2080 SUPER (driver 621.01, host Wave32). Counts are for one adapter run.

Case Base c734600 PR 7d97aa8
Counter read after a divergent loop 2/128 128/128
Counter read after nested divergent loops 8/128 128/128
Two branches update one scalar, one console wave per group 0/128 128/128
Same branches, two console waves per group 128/256 256/256

The four portable control cases also matched on WARP. All 44 focused tests passed, and the shader suite finished with 173 passed and 1 ignored. The asset policy passed. The workspace run had one loader fixture failure because the portable linker rejected the MSVC delay-load option. Both loader fixture tests passed with the equivalent option in a separate scratch checkout.

For any offline title comparison, the relevant pair is now c734600 against 7d97aa8 at 32-32 and 32-64. I used synthetic inputs only. Title rendering and frame rate remain unmeasured.

AI-assisted.

@r4tedx r4tedx left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of 7d97aa8 (thanks for the update). The code looks sound to me, and I'm not merging yet. Two checks are still open.

What I checked:

  • The joined-mask rule is unchanged (lower.rs:621-638). The new detector skips mask phis, including exit masks grown from zero, and an_exit_mask_grown_from_zero_does_not_count_as_scalar_state covers that.
  • Splitting the mask-read check out of whole gives the same reads_whole as before. The flag reaches the console-structure pass (mod.rs:365), and the per-lane fallback clears it, so every lowering pass makes the same choice.
  • Tests: the base has 35 split tests and this PR has 44. None were removed.

Runs, all one at a time with --test-threads=1, synthetic only, no title data, no hardware adapter:

  • cargo test -p victory-shader --lib emit::split_tests with no hardware adapter listed (CI-like): 44 passed, 0 failed. The 4 per-lane cases print "WARP: per-lane readback exact", and the console-flow cases skip.
  • With WARP standing in for every adapter: the same 31 base failures as on c734600, plus 3 from the new console-flow cases. That's expected, because WARP has 4 lanes and those cases need a 32-lane adapter.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.

Open before merge:

  1. The offline before/after count (c734600 vs 7d97aa8, 32-32 and 32-64), which you asked for. I'll post it here when it's done.
  2. A 32-lane hardware run of the three new console-flow tests (both scalar-counter loop tests and disjoint_branch_paths_update_the_same_scalar_in_order). So far only your RTX 2080 SUPER has run them. If a tester can run them on another 32-lane card, that would cover it.
  3. Merge risk: the base shader/wave-per-group doesn't have 1aade1f (implicit-derivative sample guard) or 7147671 (recursion guard on a mask copied dword by dword). This PR sends more programs into the console flow, so I'll bring those into the base first.

Nit, optional: lower.rs:619 wants_console_flow |= scalar_console_flow ignores no_console_flow. On a 32-lane host with a multi-wave LDS group, this makes a console-flow attempt that is bound to fail before the per-lane fallback. The output is still right (divergent_scalar_state_uses_console_flow_per_wave asserts the fallback), but it costs translate time. Gating it on no_console_flow.is_none() would avoid that.

Scope note for the description: Wave32 programs and non-compute stages keep the old lowering, and so does a probe that hits the diagram size limit. That's safe, just narrower than "every scalar that survives divergence".

AI-assisted

Run the new scalar readback fixtures under the existing GPU test lock. The fixtures all open WARP and could otherwise overlap each other and the VALU and waterfall tests, which already use the lock to avoid access violations during parallel runs.

AI-assisted.
@mohammadallami75-ops

Copy link
Copy Markdown
Author

Thanks for the review. I followed up on the parallel Windows test crash in d21eb16. The four portable scalar fixtures now share the existing GPU test lock with VALU and waterfall tests. I couldn’t reproduce the access violation locally. With the lock, all four 25-test parallel runs passed with DXIL validation, and the full local shader suite passed (173 passed, 1 ignored). Windows CI is green.

I updated the description to reflect the narrower scope. The follow-up only touches the test harness, so the offline comparison is still c734600 versus the current head at 32-32 and 32-64. The second Wave32 hardware run and the two base guards are still open.

AI-assisted.

@r4tedx r4tedx left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. d21eb16 looks right. It takes the same valu_tests::ONE_AT_A_TIME static the VALU and waterfall fixtures take, with the same poison handling. Nothing on the call path takes it a second time, and only test code changes. Each fixture builds its own Host and Validator, so this is the known concurrent-WARP crash (valu_tests.rs:166-171), not a hidden defect.

Two things are needed before this can merge:

  1. Conflict with the base. shader/wave-per-group is now at 6551f22 (#17). git merge-tree reports a conflict at the end of split_tests.rs, where both sides add tests. Keeping both sides resolves it.
  2. The new fixtures ignore VICTORY_WARP=1. per_lane_scalar_case calls adapters().unwrap_or_default() and Host::on (split_tests.rs:1480), and those open hardware adapters whatever the variable says. After the merge, please switch it to the base's hardware_adapters(), as d96a6cb did for the other split tests. Until then we can't run these fixtures here: our tests are on the software adapter only for now.

Still open from the earlier review: the offline count c734600 vs the head at 32-32 and 32-64, a 32-lane run of the three console-flow tests, and 1aade1f/7147671 going into the base first.

AI-assisted.

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.

2 participants