You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Lack of unrolling and very high register usage #462
Can also be rewritten in a way that will probably produce some helpful runtime code in SPIR-V since I suspect the hint will be lost in translation:
constMAX_BUCKET_SIZE:usize = 512;constWORKGROUP_SIZE:u32 = 256;for index in(local_invocation_id..matches_count.min(MAX_BUCKET_SIZE)asu32).step_by(WORKGROUP_SIZEasusize){
It is not difficult for me to see that there will be at most two loop iterations here per invocation. However, it is not something compiler sees today.
The result is much higher register usage, impacting occupancy in a big way.
Rewriting it to inner function that is called twice with explicit bounds checks fixes register usage (though I hit #461 when doing so), but is far from idiomatic Rust and is quite painful to do manually in all such cases.
I wish end-to-end compilation chain was aware of things like this, it is a very important pattern for performance.
In fact loop unrolling is extremely bad right now, even fixed loops with 3-4 iterations and one or several simply ALU instructions in it are not unrolled and balloon register usage.
There's an extension called SPV_KHR_expect_assume that adds OpAssumeTrueKHR and OpExpectKHR. The Vulkan part VK_KHR_shader_expect_assume is promoted to be required in Vulkan1.4. So we could even emit those, and have a fallback to unreachable.
Problem: rspirv on crates.io doesn't provide those symbols yet... gfx-rs/rspirv#259
Unreachable should have the same effect as the second loop example I have provided. Handling of loops feels completely broken right now in terms of optimizations.
Activity
Firestar99 commentedon Nov 26, 2025
assert_uncheckedcallscrate::intrinsics::assume, so looking into ourassumecodegen, it's just getting discarded:rust-gpu/crates/rustc_codegen_spirv/src/builder/intrinsics.rs
Lines 376 to 383 in 6bb1066
rust-gpu/crates/rustc_codegen_spirv/src/builder/builder_methods.rs
Lines 1950 to 1953 in d5c290e
However, what isn't getting ignored is
unreachable:rust-gpu/crates/rustc_codegen_spirv/src/builder/builder_methods.rs
Lines 1541 to 1543 in d5c290e
Could you try something like this?
If this works, I'm willing to just wire
assumeto be thatFirestar99 commentedon Nov 26, 2025
There's an extension called SPV_KHR_expect_assume that adds
OpAssumeTrueKHRandOpExpectKHR. The Vulkan partVK_KHR_shader_expect_assumeis promoted to be required in Vulkan1.4. So we could even emit those, and have a fallback to unreachable.Problem:
rspirvon crates.io doesn't provide those symbols yet... gfx-rs/rspirv#259nazar-pc commentedon Nov 26, 2025
Unreachable should have the same effect as the second loop example I have provided. Handling of loops feels completely broken right now in terms of optimizations.
39ali commentedon Apr 20, 2026
i've hit a similar issue, i'll fix this in
spirtand if the pr passes i'll update rust-gpu as well