gpu: avoid shift overflow in resource::subresource on large mip levels #41
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/41"
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 edsuuu/VI-BR-PORT. Originally posted by ahmetbagci8 on 2026-11-29T18:12:03Z.
Problem
In crates/victory-gpu/src/resource.rs, subresource() shifts desc.width >> mip, u64::from(desc.height) >> mip, and (for 3D textures) u32::from(desc.depth_or_array_size) >> mip without bounding mip. When mip_levels is large (mip >= 32 for 3D depth or mip >= 64 for width/height), this panics with shift overflow in debug builds and wraps modulo 32/64 in release builds.
Fix
Use .checked_shr(mip).unwrap_or(0).max(1) for width, height, and 3D depth, and add unit test subresource_with_large_mip_does_not_overflow_shift.
Verification