Evaluate shader lane-mask selects iteratively #1103

Manually merged
github merged 1 commit from github-bot/gh-1103 into main 2026-11-29 00:28:04 +00:00 AGit
Owner

@⁠ghptc on GitHub · 2026-11-28 13:17 UTC · original
ghptc:fix/iterative-lane-mask-select → main · +61 −14 · 1 files · 1 commits · merged 2026-11-29 00:24 UTC

The shader structurer builds ordered decision diagrams for lane masks. An unresolved Boolean select recursively evaluated its low and high cofactors. Even a narrow diagram with one node per variable consumed a native call frame per level. The node budget bounds diagram size, but a valid diagram can be deep.

This patch evaluates the same cofactors with an explicit work list. Each entry records the unresolved high branch and the low result. Low precedes high, and node interning and memoization still occur after both results are known. The new semantic regression selects between two independent outputs using a six-variable parity mask and checks all 256 assignments and a repeated select.

Reproduction and measurements

On Windows, or using a Windows-target test executable under Proton, run the shader structuring suite:

cargo test --release --locked -p victory-shader --lib structure::tests

For the stack measurement, use a 2 MiB test thread and create 16, 64, or 256 ordered lane atoms. Starting with true, walk the variables in reverse order and build each node with false as its low child and the preceding result as its high child. Negate the resulting conjunction and verify that negating the result returns the original canonical node. Sample the address of a black-boxed local in a non-inlined observer on entry to the original select, or at each descent in the iterative select. Reset the min, max, and visit count before the first negation.

Variables Visits in both builds Original address span Patched address span
16 33 2,048 B 0 B
64 129 8,192 B 0 B
256 513 32,768 B 0 B

The span measures variation across visits at that sampling site. The routine still uses a fixed call frame and allocates space for its explicit work list. A separate stack sample on the existing divergent-if fixture reached this function from the normal shader structurer. No stack overflow occurred in these bounded tests.

A separate uninstrumented timing test applied the structurer 4,096 times per batch to the same small divergent-if program. After warm-up, ten release samples per revision in A/B/B/A process order gave medians of 10.357 ms before and 10.886 ms after (about 5.1% slower on that fixture). This patch trades some shallow-case CPU time for bounded native stack use in this operation. Windows x64 MSVC-target release tests ran on Proton. Native Windows and representative shader-corpus performance remain unmeasured.

**@⁠ghptc** on GitHub · 2026-11-28 13:17 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1103) `ghptc:fix/iterative-lane-mask-select` → `main` · +61 −14 · 1 files · 1 commits · merged 2026-11-29 00:24 UTC The shader structurer builds ordered decision diagrams for lane masks. An unresolved Boolean select recursively evaluated its low and high cofactors. Even a narrow diagram with one node per variable consumed a native call frame per level. The node budget bounds diagram size, but a valid diagram can be deep. This patch evaluates the same cofactors with an explicit work list. Each entry records the unresolved high branch and the low result. Low precedes high, and node interning and memoization still occur after both results are known. The new semantic regression selects between two independent outputs using a six-variable parity mask and checks all 256 assignments and a repeated select. ### Reproduction and measurements On Windows, or using a Windows-target test executable under Proton, run the shader structuring suite: ```text cargo test --release --locked -p victory-shader --lib structure::tests ``` For the stack measurement, use a 2 MiB test thread and create 16, 64, or 256 ordered lane atoms. Starting with true, walk the variables in reverse order and build each node with false as its low child and the preceding result as its high child. Negate the resulting conjunction and verify that negating the result returns the original canonical node. Sample the address of a black-boxed local in a non-inlined observer on entry to the original select, or at each descent in the iterative select. Reset the min, max, and visit count before the first negation. | Variables | Visits in both builds | Original address span | Patched address span | | --- | ---: | ---: | ---: | | 16 | 33 | 2,048 B | 0 B | | 64 | 129 | 8,192 B | 0 B | | 256 | 513 | 32,768 B | 0 B | The span measures variation across visits at that sampling site. The routine still uses a fixed call frame and allocates space for its explicit work list. A separate stack sample on the existing divergent-if fixture reached this function from the normal shader structurer. No stack overflow occurred in these bounded tests. A separate uninstrumented timing test applied the structurer 4,096 times per batch to the same small divergent-if program. After warm-up, ten release samples per revision in A/B/B/A process order gave medians of 10.357 ms before and 10.886 ms after (about 5.1% slower on that fixture). This patch trades some shallow-case CPU time for bounded native stack use in this operation. Windows x64 MSVC-target release tests ran on Proton. Native Windows and representative shader-corpus performance remain unmeasured.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 14:33:23 +00:00
Author
Owner

@⁠ghptc on GitHub · 2026-11-28 13:23 UTC · original

Windows Clippy reported the same two diagnostics on this PR and its exact upstream base, 63b902f: let_and_return in shader emission and manual_is_multiple_of in the shadow worker. With #957 applied locally to 1a35cb3, both locked workspace Clippy checks passed for Windows MSVC on Rust 1.98.1, including --all-features, with -D warnings. Upstream CI log

**@⁠ghptc** on GitHub · 2026-11-28 13:23 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1103#issuecomment-7239896736) Windows Clippy reported the same two diagnostics on this PR and its exact upstream base, `63b902f`: `let_and_return` in shader emission and `manual_is_multiple_of` in the shadow worker. With #957 applied locally to `1a35cb3`, both locked workspace Clippy checks passed for Windows MSVC on Rust 1.98.1, including `--all-features`, with `-D warnings`. [Upstream CI log](https://github.com/trustno1-coder/VIctory-NVIDIA/actions/runs/46104876336/job/140855261577)
github-bot force-pushed github-bot/gh-1103 from 1a35cb316a to 92906a74d3 2026-11-28 19:55:00 +00:00 Compare
github-bot referenced this pull request from a commit 2026-11-29 00:27:22 +00:00
github manually merged commit 6346a79098 into main 2026-11-29 00:28:04 +00:00
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!1103
No description provided.