refactor: use built-in {integer}::power_of_two methods (#5909)

This commit is contained in:
Erich Gubler 2024-07-04 21:34:19 -06:00 committed by GitHub
parent 4816a2d1bd
commit d41b9ab29f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 5 additions and 14 deletions

View File

@ -84,7 +84,6 @@ use crate::{
BasePass, BindGroupStateChange, ColorAttachmentError, DrawError, MapPassErr,
PassErrorScope, RenderCommandError, StateChange,
},
conv,
device::{
AttachmentData, Device, DeviceError, MissingDownlevelFlags, RenderPassContext,
SHADER_STAGE_COUNT,
@ -287,7 +286,7 @@ impl RenderBundleEncoder {
},
sample_count: {
let sc = desc.sample_count;
if sc == 0 || sc > 32 || !conv::is_power_of_two_u32(sc) {
if sc == 0 || sc > 32 || !sc.is_power_of_two() {
return Err(CreateRenderBundleError::InvalidSampleCount(sc));
}
sc

View File

@ -2,14 +2,6 @@ use wgt::TextureFormatFeatures;
use crate::resource::{self, TextureDescriptor};
pub fn is_power_of_two_u16(val: u16) -> bool {
val != 0 && (val & (val - 1)) == 0
}
pub fn is_power_of_two_u32(val: u32) -> bool {
val != 0 && (val & (val - 1)) == 0
}
pub fn is_valid_copy_src_texture_format(
format: wgt::TextureFormat,
aspect: wgt::TextureAspect,
@ -233,7 +225,7 @@ pub fn check_texture_dimension_size(
return Err(Tde::LimitExceeded { dim, given, limit });
}
}
if sample_size == 0 || sample_size > sample_limit || !is_power_of_two_u32(sample_size) {
if sample_size == 0 || sample_size > sample_limit || !sample_size.is_power_of_two() {
return Err(Tde::InvalidSampleCount(sample_size));
}

View File

@ -3176,7 +3176,7 @@ impl<A: HalApi> Device<A> {
let samples = {
let sc = desc.multisample.count;
if sc == 0 || sc > 32 || !conv::is_power_of_two_u32(sc) {
if sc == 0 || sc > 32 || !sc.is_power_of_two() {
return Err(pipeline::CreateRenderPipelineError::InvalidSampleCount(sc));
}
sc

View File

@ -102,7 +102,7 @@ mod stateless;
mod texture;
use crate::{
binding_model, command, conv,
binding_model, command,
hal_api::HalApi,
lock::{rank, Mutex, RwLock},
pipeline,
@ -323,7 +323,7 @@ pub(crate) trait ResourceUses:
fn invalid_resource_state<T: ResourceUses>(state: T) -> bool {
// Is power of two also means "is one bit set". We check for this as if
// we're in any exclusive state, we must only be in a single state.
state.any_exclusive() && !conv::is_power_of_two_u16(state.bits())
state.any_exclusive() && !state.bits().is_power_of_two()
}
/// Returns true if the transition from one state to another does not require