shader: look up an input channel without underflowing

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.
This commit is contained in:
9hvn9yt2vk-netizen committed 2026-11-24 00:57:59 +01:00
1 parent b9aff99b98
commit 0f198bf66b
2 files changed
+58 -1

No files matched your search

+3 -1
View File
@@ -1013,8 +1013,10 @@ impl<'a> Lower<'a> {
fn find_input(&self, row: u8, channel: u8) -> Option<(usize, u8)> {
self.s.inputs.iter().enumerate().find_map(|(id, e)| {
let r = e.row?;
// `then`, not `then_some`: the channel is only past `col` when
// the condition holds.
(r == u32::from(row) && channel >= e.col && channel < e.col + e.cols)
.then_some((id, channel - e.col))
.then(|| (id, channel - e.col))
})
}