shader: look up an input channel without underflowing #56
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!56
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/56/head"
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?
@9hvn9yt2vk-netizen on GitHub · 2026-11-23 23:58 UTC · original
9hvn9yt2vk-netizen:find-input-underflow→main· +58 −1 · 2 files · 1 commits · merged 2026-11-24 00:34 UTCfind_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.
@9hvn9yt2vk-netizen on GitHub · 2026-11-23 23:59 UTC · original
juwwww
@DaviTostes on GitHub · 2026-11-24 00:02 UTC · original
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).
@lordon1a on GitHub · 2026-11-24 00:17 UTC · original
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.
@tedin7 on GitHub · 2026-11-24 00:37 UTC · original
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.