Skip to content

add loop unrolling optimization pass#32

Open
39ali wants to merge 3 commits intoRust-GPU:mainfrom
39ali:unroll-loop
Open

add loop unrolling optimization pass#32
39ali wants to merge 3 commits intoRust-GPU:mainfrom
39ali:unroll-loop

Conversation

@39ali
Copy link
Copy Markdown

@39ali 39ali commented Apr 20, 2026

this adds a pass that does unrolling for loop using profitability model to make sure we only unroll when it's beneficial

you can run the example : cargo run --example spv-unroll-test examples/spv-unroll-test/shader.spv , shader.spv is based on lib.rs just to have it as a reference

UnrollConfig::default() was chosen for whatever made sense, if anyone has better default values feel free to change it

Currently only 32/64-bit integers work :
f32 / f64: uses OpFOrdLessThan which we don't check for, and float constants need different handling anyway (and floating-point loop bounds aren't statically safe to unroll without exactness guarantees)
u16 / u8: these don't exist as SPIR-V scalar types — they're always widened to u32 in shaders

Negative i32 bounds return None from u64_trip_count due to u32::try_from overflow, so the loop will not unroll.

@39ali 39ali requested a review from eddyb as a code owner April 20, 2026 18:00
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.

1 participant