shader: look up an input channel without underflowing #56
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/56"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by 9hvn9yt2vk-netizen on 2026-11-23T23:58:57Z.
find_input matched each input element with
(row and channel in the element).then_some((id, channel - e.col)). then_some evaluates its argument first, so the subtraction ran for every element, also those whose first channel is past the one asked for. In a build with overflow checks (tests, debug runs) a pixel shader reading a channel below any element that starts at z or w panicked, whichever row that element was in, and packed inputs such as a float2 in .zw are common. Release builds wrapped and threw the value away.then() computes it only when the element holds the channel.
Found with a random-input harness over pixel, vertex and mesh programs with matching signatures. The new test panics without the fix.
Imported from Marvisak/VIctory. Originally posted by 9hvn9yt2vk-netizen on 2026-11-23T23:59:45Z.
juwwww
Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T00:02:53Z.
Tested
5fbea47stacked on #39 on Arch Linux x86_64, rustc 1.98.1: pass.mainalone does not build on Linux (E0425 invictory-gpu), so the check uses #39 as the base; the merge is clean.cargo test --workspace: 156 passed, 0 failed, 3 ignored, including the new tests this PR adds inemit/mod.rs(55 lines).AI-assisted (DeepSeek V4.1 Flash coding agent).
Imported from Marvisak/VIctory. Originally posted by lordon1a on 2026-11-24T00:17:26Z.
Verified
5fbea4730on Windows 11 (x86_64-pc-windows-gnullvm,rustc 1.100.0, applied cleanly tomain@35b054ec0): pass.cargo xtask policy: 150 files okcargo test -p victory-shader: 58 passed, 0 failed (includingreading_a_channel_below_an_input_element_does_not_underflow)crates/victory-shader/src/emit/lower.rstomain): 1 failed (reading_a_channel_below_an_input_element_does_not_underflowpanics on underflow as expected).AI-assisted.
Imported from Marvisak/VIctory. Originally posted by tedin7 on 2026-11-24T00:37:16Z.
checked: this was already merged (
8fe0b74) while I was running these, so this is a post-merge confirmation of5fbea47rather than a pre-merge review.Environment: Linux x86_64 (Debian, kernel 6.12), Rust 1.98.1 from rust-toolchain.toml, cargo -j4, no game files, no GPU.
What I ran (in a throwaway worktree of the PR head
5fbea47, base97c78d1):cargo test -j4 -p victory-shader: 52 passed, 0 failed.cargo clippy -j4 -p victory-shader --tests: no new warnings from this change. One existing dead_code warning (constant_colorin the test code), unrelated to this PR.lower.rsfrom the base commit (97c78d1, withthen_some) and rancargo test -p victory-shader reading_a_channel.reading_a_channel_below_an_input_element_does_not_underflowFAILED with "attempt to subtract with overflow" at lower.rs:1017. With the PR'slower.rsit passes. So the test guards the fix.git merge-treeof the PR head against main at the time was clean.Review notes:
then_someevaluateschannel - e.coleagerly for every element, andthen(|| ...)only when the range check passes. The range check already makes the subtraction safe.then_someuses in the workspace for a similar eager-arithmetic pattern and found none that can overflow (casts and lookups only).Not verified:
cargo test --workspaceon Linux. Main does not buildvictory-gpuon Linux at the moment (E0425,host_resourceis#[cfg(windows)]but used from code that is not), as the earlier Linux check on this PR also found; #39 looks like the fix. Also not verified: Windows runtime, D3D12, any GPU or dxil validation.