Skip to content

Commit

Permalink
refactor: use built-in {integer}::power_of_two methods (gfx-rs#5909)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErichDonGubler authored Jul 5, 2024
1 parent 4816a2d commit d41b9ab
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 14 deletions.
3 changes: 1 addition & 2 deletions wgpu-core/src/command/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ use crate::{
BasePass, BindGroupStateChange, ColorAttachmentError, DrawError, MapPassErr,
PassErrorScope, RenderCommandError, StateChange,
},
conv,
device::{
AttachmentData, Device, DeviceError, MissingDownlevelFlags, RenderPassContext,
SHADER_STAGE_COUNT,
Expand Down Expand Up @@ -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
Expand Down
10 changes: 1 addition & 9 deletions wgpu-core/src/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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));
}

Expand Down
2 changes: 1 addition & 1 deletion wgpu-core/src/device/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions wgpu-core/src/track/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d41b9ab

Please sign in to comment.