Add is_power_of_two function (#603)

This commit is contained in:
Dzmitry Malyshau
2020-04-21 09:29:10 -04:00
committed by Dzmitry Malyshau
parent 11a321131f
commit b71bcc5349

View File

@@ -436,6 +436,10 @@ fn checked_u32_as_u16(value: u32) -> u16 {
value as u16
}
fn is_power_of_two(val: u32) -> bool {
val != 0 && (val & (val - 1)) == 0
}
pub fn map_texture_dimension_size(
dimension: wgt::TextureDimension,
Extent3d {
@@ -458,12 +462,7 @@ pub fn map_texture_dimension_size(
D2 => {
assert_eq!(depth, 1);
assert!(
sample_size == 1
|| sample_size == 2
|| sample_size == 4
|| sample_size == 8
|| sample_size == 16
|| sample_size == 32,
sample_size <= 32 && is_power_of_two(sample_size),
"Invalid sample_count of {}",
sample_size
);