diff --git a/wgpu-core/src/command/allocator.rs b/wgpu-core/src/command/allocator.rs index ea6ddbe095..cf8a39ed75 100644 --- a/wgpu-core/src/command/allocator.rs +++ b/wgpu-core/src/command/allocator.rs @@ -154,7 +154,7 @@ impl CommandAllocator { pending: Vec::new(), }, ); - Ok(CommandAllocator { + Ok(Self { queue_family, internal_thread_id, inner: Mutex::new(Inner { pools }), diff --git a/wgpu-core/src/command/bundle.rs b/wgpu-core/src/command/bundle.rs index b522efce9d..f8c07cff3e 100644 --- a/wgpu-core/src/command/bundle.rs +++ b/wgpu-core/src/command/bundle.rs @@ -93,7 +93,7 @@ impl RenderBundleEncoder { base: Option>, ) -> Result { span!(_guard, INFO, "RenderBundleEncoder::new"); - Ok(RenderBundleEncoder { + Ok(Self { base: base.unwrap_or_else(BasePass::new), parent_id, context: RenderPassContext { @@ -330,7 +330,7 @@ struct IndexState { impl IndexState { fn new() -> Self { - IndexState { + Self { buffer: None, format: wgt::IndexFormat::default(), range: 0..0, @@ -385,7 +385,7 @@ struct VertexState { impl VertexState { fn new() -> Self { - VertexState { + Self { buffer: None, range: 0..0, stride: 0, @@ -424,7 +424,7 @@ struct BindState { impl BindState { fn new() -> Self { - BindState { + Self { bind_group: None, dynamic_offsets: 0..0, is_dirty: false, diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index f46dc29f79..9a7734db3f 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -70,7 +70,7 @@ pub struct ComputePass { impl ComputePass { pub fn new(parent_id: id::CommandEncoderId) -> Self { - ComputePass { + Self { base: BasePass::new(), parent_id, } diff --git a/wgpu-core/src/command/mod.rs b/wgpu-core/src/command/mod.rs index db8c2e7ef6..e8c84e56ea 100644 --- a/wgpu-core/src/command/mod.rs +++ b/wgpu-core/src/command/mod.rs @@ -128,7 +128,7 @@ pub struct BasePass { impl BasePass { fn new() -> Self { - BasePass { + Self { commands: Vec::new(), dynamic_offsets: Vec::new(), string_data: Vec::new(), @@ -138,7 +138,7 @@ impl BasePass { #[cfg(feature = "trace")] fn from_ref(base: BasePassRef) -> Self { - BasePass { + Self { commands: base.commands.to_vec(), dynamic_offsets: base.dynamic_offsets.to_vec(), string_data: base.string_data.to_vec(), diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index 1e9456c770..25bdece3f7 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -152,7 +152,7 @@ pub struct RenderPass { impl RenderPass { pub fn new(parent_id: id::CommandEncoderId, desc: RenderPassDescriptor) -> Self { - RenderPass { + Self { base: BasePass::new(), parent_id, color_targets: desc.color_attachments.iter().cloned().collect(), diff --git a/wgpu-core/src/device/life.rs b/wgpu-core/src/device/life.rs index 8bf7417692..d6f4b02f74 100644 --- a/wgpu-core/src/device/life.rs +++ b/wgpu-core/src/device/life.rs @@ -100,7 +100,7 @@ struct NonReferencedResources { impl NonReferencedResources { fn new() -> Self { - NonReferencedResources { + Self { buffers: Vec::new(), images: Vec::new(), image_views: Vec::new(), @@ -225,7 +225,7 @@ pub(crate) struct LifetimeTracker { impl LifetimeTracker { pub fn new() -> Self { - LifetimeTracker { + Self { mapped: Vec::new(), future_suspected_buffers: Vec::new(), future_suspected_textures: Vec::new(), diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index d52ab168b2..505a6df97a 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -272,7 +272,7 @@ impl Device { None => (), } - Ok(Device { + Ok(Self { raw, adapter_id, cmd_allocator, @@ -923,8 +923,8 @@ pub enum DeviceError { impl From for DeviceError { fn from(err: hal::device::OomOrDeviceLost) -> Self { match err { - hal::device::OomOrDeviceLost::OutOfMemory(_) => DeviceError::OutOfMemory, - hal::device::OomOrDeviceLost::DeviceLost(_) => DeviceError::Lost, + hal::device::OomOrDeviceLost::OutOfMemory(_) => Self::OutOfMemory, + hal::device::OomOrDeviceLost::DeviceLost(_) => Self::Lost, } } } @@ -934,14 +934,14 @@ impl DeviceError { match err { gfx_memory::HeapsError::AllocationError(hal::device::AllocationError::OutOfMemory( _, - )) => DeviceError::OutOfMemory, + )) => Self::OutOfMemory, _ => panic!("Unable to allocate memory: {:?}", err), } } fn from_bind(err: hal::device::BindError) -> Self { match err { - hal::device::BindError::OutOfMemory(_) => DeviceError::OutOfMemory, + hal::device::BindError::OutOfMemory(_) => Self::OutOfMemory, _ => panic!("failed to bind memory: {}", err), } } diff --git a/wgpu-core/src/device/queue.rs b/wgpu-core/src/device/queue.rs index 727982a741..b903e56c9d 100644 --- a/wgpu-core/src/device/queue.rs +++ b/wgpu-core/src/device/queue.rs @@ -37,7 +37,7 @@ pub(crate) struct PendingWrites { impl PendingWrites { pub fn new() -> Self { - PendingWrites { + Self { command_buffer: None, temp_buffers: Vec::new(), } diff --git a/wgpu-core/src/device/trace.rs b/wgpu-core/src/device/trace.rs index 273178a076..d41e8c9e6e 100644 --- a/wgpu-core/src/device/trace.rs +++ b/wgpu-core/src/device/trace.rs @@ -154,7 +154,7 @@ impl Trace { tracing::info!("Tracing into '{:?}'", path); let mut file = std::fs::File::create(path.join(FILE_NAME))?; file.write_all(b"[\n")?; - Ok(Trace { + Ok(Self { path: path.to_path_buf(), file, config: ron::ser::PrettyConfig::default(), diff --git a/wgpu-core/src/hub.rs b/wgpu-core/src/hub.rs index 0733d7c5a0..dbbe5959ac 100644 --- a/wgpu-core/src/hub.rs +++ b/wgpu-core/src/hub.rs @@ -36,7 +36,7 @@ pub struct IdentityManager { impl Default for IdentityManager { fn default() -> Self { - IdentityManager { + Self { free: Default::default(), epochs: Default::default(), } @@ -45,7 +45,7 @@ impl Default for IdentityManager { impl IdentityManager { pub fn from_index(min_index: u32) -> Self { - IdentityManager { + Self { free: (0..min_index).collect(), epochs: vec![1; min_index as usize], } @@ -292,7 +292,7 @@ impl<'a, T> Token<'a, T> { assert_ne!(old, 0, "Root token was dropped"); active.set(old + 1); }); - Token { level: PhantomData } + Self { level: PhantomData } } } @@ -303,7 +303,7 @@ impl Token<'static, Root> { assert_eq!(0, active.replace(1), "Root token is already active"); }); - Token { level: PhantomData } + Self { level: PhantomData } } } @@ -381,7 +381,7 @@ pub struct Registry> { impl> Registry { fn new(backend: Backend, factory: &F, kind: &'static str) -> Self { - Registry { + Self { identity: factory.spawn(0), data: RwLock::new(Storage { map: Vec::new(), @@ -393,7 +393,7 @@ impl> Registry { } fn without_backend(factory: &F, kind: &'static str) -> Self { - Registry { + Self { identity: factory.spawn(1), data: RwLock::new(Storage { map: Vec::new(), @@ -508,7 +508,7 @@ pub struct Hub { impl Hub { fn new(factory: &F) -> Self { - Hub { + Self { adapters: Registry::new(B::VARIANT, factory, "Adapter"), devices: Registry::new(B::VARIANT, factory, "Device"), swap_chains: Registry::new(B::VARIANT, factory, "SwapChain"), @@ -668,7 +668,7 @@ pub struct Hubs { impl Hubs { fn new(factory: &F) -> Self { - Hubs { + Self { #[cfg(vulkan)] vulkan: Hub::new(factory), #[cfg(metal)] @@ -691,7 +691,7 @@ pub struct Global { impl Global { pub fn new(name: &str, factory: G, backends: wgt::BackendBit) -> Self { span!(_guard, INFO, "Global::new"); - Global { + Self { instance: Instance::new(name, 1, backends), surfaces: Registry::without_backend(&factory, "Surface"), hubs: Hubs::new(&factory), diff --git a/wgpu-core/src/id.rs b/wgpu-core/src/id.rs index 2a00f06f1b..7a1201be2e 100644 --- a/wgpu-core/src/id.rs +++ b/wgpu-core/src/id.rs @@ -39,7 +39,7 @@ enum SerialId { impl From> for SerialId { fn from(id: Id) -> Self { let (index, epoch, backend) = id.unzip(); - SerialId::Id(index, epoch, backend) + Self::Id(index, epoch, backend) } } #[cfg(feature = "replay")] diff --git a/wgpu-core/src/instance.rs b/wgpu-core/src/instance.rs index 4732c68bbf..d82545a955 100644 --- a/wgpu-core/src/instance.rs +++ b/wgpu-core/src/instance.rs @@ -50,7 +50,7 @@ impl Instance { None } }; - Instance { + Self { #[cfg(vulkan)] vulkan: map((Backend::Vulkan, gfx_backend_vulkan::Instance::create)), #[cfg(metal)] @@ -200,7 +200,7 @@ impl Adapter { .max(MIN_PUSH_CONSTANT_SIZE), // As an extension, the default is always 0, so define a separate minimum. }; - Adapter { + Self { raw, features, limits, @@ -235,7 +235,7 @@ impl AdapterInfo { device_type, } = adapter_info; - AdapterInfo { + Self { name, vendor, device, @@ -302,8 +302,8 @@ pub enum AdapterInputs<'a, I> { impl AdapterInputs<'_, I> { fn find(&self, b: Backend) -> Option { match *self { - AdapterInputs::IdSet(ids, ref fun) => ids.iter().find(|id| fun(id) == b).cloned(), - AdapterInputs::Mask(bits, ref fun) => { + Self::IdSet(ids, ref fun) => ids.iter().find(|id| fun(id) == b).cloned(), + Self::Mask(bits, ref fun) => { if bits.contains(b.into()) { Some(fun(b)) } else { diff --git a/wgpu-core/src/lib.rs b/wgpu-core/src/lib.rs index f111d7ec9f..63df2334a1 100644 --- a/wgpu-core/src/lib.rs +++ b/wgpu-core/src/lib.rs @@ -96,7 +96,7 @@ impl Clone for RefCount { fn clone(&self) -> Self { let old_size = unsafe { self.0.as_ref() }.fetch_add(1, Ordering::AcqRel); assert!(old_size < Self::MAX); - RefCount(self.0) + Self(self.0) } } @@ -142,7 +142,7 @@ impl MultiRefCount { fn new() -> Self { let bx = Box::new(AtomicUsize::new(1)); let ptr = Box::into_raw(bx); - MultiRefCount(unsafe { ptr::NonNull::new_unchecked(ptr) }) + Self(unsafe { ptr::NonNull::new_unchecked(ptr) }) } fn inc(&self) { @@ -169,7 +169,7 @@ struct LifeGuard { impl LifeGuard { fn new() -> Self { let bx = Box::new(AtomicUsize::new(1)); - LifeGuard { + Self { ref_count: ptr::NonNull::new(Box::into_raw(bx)).map(RefCount), submission_index: AtomicUsize::new(0), } diff --git a/wgpu-core/src/track/buffer.rs b/wgpu-core/src/track/buffer.rs index 5c557257c2..e4999a9ae4 100644 --- a/wgpu-core/src/track/buffer.rs +++ b/wgpu-core/src/track/buffer.rs @@ -26,7 +26,7 @@ impl PendingTransition { impl Default for BufferState { fn default() -> Self { - BufferState { + Self { first: None, last: BufferUse::empty(), } diff --git a/wgpu-core/src/track/mod.rs b/wgpu-core/src/track/mod.rs index b96e954143..5c2db99e14 100644 --- a/wgpu-core/src/track/mod.rs +++ b/wgpu-core/src/track/mod.rs @@ -32,7 +32,7 @@ pub struct Unit { impl Unit { /// Create a new unit from a given usage. fn new(usage: U) -> Self { - Unit { + Self { first: None, last: usage, } @@ -199,7 +199,7 @@ impl fmt::Debug for ResourceTracker { impl ResourceTracker { /// Create a new empty tracker. pub fn new(backend: wgt::Backend) -> Self { - ResourceTracker { + Self { map: FastHashMap::default(), temp: Vec::new(), backend, @@ -514,7 +514,7 @@ pub(crate) struct TrackerSet { impl TrackerSet { /// Create an empty set. pub fn new(backend: wgt::Backend) -> Self { - TrackerSet { + Self { buffers: ResourceTracker::new(backend), textures: ResourceTracker::new(backend), views: ResourceTracker::new(backend), diff --git a/wgpu-core/src/track/range.rs b/wgpu-core/src/track/range.rs index 13376d97b0..458861e1a9 100644 --- a/wgpu-core/src/track/range.rs +++ b/wgpu-core/src/track/range.rs @@ -18,13 +18,13 @@ pub struct RangedStates { impl RangedStates { pub fn empty() -> Self { - RangedStates { + Self { ranges: SmallVec::new(), } } pub fn from_range(range: Range, value: T) -> Self { - RangedStates { + Self { ranges: iter::once((range, value)).collect(), } } @@ -32,7 +32,7 @@ impl RangedStates { /// Construct a new instance from a slice of ranges. #[cfg(test)] pub fn from_slice(values: &[(Range, T)]) -> Self { - RangedStates { + Self { ranges: values.iter().cloned().collect(), } } diff --git a/wgpu-core/src/track/texture.rs b/wgpu-core/src/track/texture.rs index 5e9f488da4..6d1d4a5935 100644 --- a/wgpu-core/src/track/texture.rs +++ b/wgpu-core/src/track/texture.rs @@ -45,7 +45,7 @@ impl PendingTransition { impl TextureState { pub fn new(mip_level_count: hal::image::Level, array_layer_count: hal::image::Layer) -> Self { - TextureState { + Self { mips: iter::repeat_with(|| { PlaneStates::from_range(0..array_layer_count, Unit::new(TextureUse::UNINITIALIZED)) }) diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 4b2f1cfe73..a2df03f5bc 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -66,8 +66,8 @@ pub enum PowerPreference { } impl Default for PowerPreference { - fn default() -> PowerPreference { - PowerPreference::Default + fn default() -> Self { + Self::Default } } @@ -106,7 +106,7 @@ bitflags::bitflags! { impl From for BackendBit { fn from(backend: Backend) -> Self { - BackendBit::from_bits(1 << backend as u32).unwrap() + Self::from_bits(1 << backend as u32).unwrap() } } @@ -364,7 +364,7 @@ pub struct Limits { impl Default for Limits { fn default() -> Self { - Limits { + Self { max_bind_groups: 4, max_dynamic_uniform_buffers_per_pipeline_layout: 8, max_dynamic_storage_buffers_per_pipeline_layout: 4, @@ -476,7 +476,7 @@ pub enum BlendOperation { impl Default for BlendOperation { fn default() -> Self { - BlendOperation::Add + Self::Add } } @@ -513,7 +513,7 @@ impl BlendDescriptor { impl Default for BlendDescriptor { fn default() -> Self { - BlendDescriptor::REPLACE + Self::REPLACE } } @@ -536,7 +536,7 @@ pub struct ColorStateDescriptor { impl From for ColorStateDescriptor { fn from(format: TextureFormat) -> Self { - ColorStateDescriptor { + Self { format, alpha_blend: BlendDescriptor::REPLACE, color_blend: BlendDescriptor::REPLACE, @@ -589,7 +589,7 @@ pub enum FrontFace { impl Default for FrontFace { fn default() -> Self { - FrontFace::Ccw + Self::Ccw } } @@ -609,7 +609,7 @@ pub enum CullMode { impl Default for CullMode { fn default() -> Self { - CullMode::None + Self::None } } @@ -629,7 +629,7 @@ pub enum PolygonMode { impl Default for PolygonMode { fn default() -> Self { - PolygonMode::Fill + Self::Fill } } @@ -874,7 +874,7 @@ bitflags::bitflags! { impl Default for ColorWrite { fn default() -> Self { - ColorWrite::ALL + Self::ALL } } @@ -946,7 +946,7 @@ pub enum IndexFormat { impl Default for IndexFormat { fn default() -> Self { - IndexFormat::Uint32 + Self::Uint32 } } @@ -976,7 +976,7 @@ pub enum StencilOperation { impl Default for StencilOperation { fn default() -> Self { - StencilOperation::Keep + Self::Keep } } @@ -1009,7 +1009,7 @@ impl StencilStateFaceDescriptor { impl Default for StencilStateFaceDescriptor { fn default() -> Self { - StencilStateFaceDescriptor::IGNORE + Self::IGNORE } } @@ -1040,7 +1040,7 @@ pub enum CompareFunction { impl CompareFunction { pub fn needs_ref_value(self) -> bool { match self { - CompareFunction::Never | CompareFunction::Always => false, + Self::Never | Self::Always => false, _ => true, } } @@ -1145,32 +1145,29 @@ pub enum VertexFormat { impl VertexFormat { pub fn size(&self) -> u64 { match self { - VertexFormat::Uchar2 - | VertexFormat::Char2 - | VertexFormat::Uchar2Norm - | VertexFormat::Char2Norm => 2, - VertexFormat::Uchar4 - | VertexFormat::Char4 - | VertexFormat::Uchar4Norm - | VertexFormat::Char4Norm - | VertexFormat::Ushort2 - | VertexFormat::Short2 - | VertexFormat::Ushort2Norm - | VertexFormat::Short2Norm - | VertexFormat::Half2 - | VertexFormat::Float - | VertexFormat::Uint - | VertexFormat::Int => 4, - VertexFormat::Ushort4 - | VertexFormat::Short4 - | VertexFormat::Ushort4Norm - | VertexFormat::Short4Norm - | VertexFormat::Half4 - | VertexFormat::Float2 - | VertexFormat::Uint2 - | VertexFormat::Int2 => 8, - VertexFormat::Float3 | VertexFormat::Uint3 | VertexFormat::Int3 => 12, - VertexFormat::Float4 | VertexFormat::Uint4 | VertexFormat::Int4 => 16, + Self::Uchar2 | Self::Char2 | Self::Uchar2Norm | Self::Char2Norm => 2, + Self::Uchar4 + | Self::Char4 + | Self::Uchar4Norm + | Self::Char4Norm + | Self::Ushort2 + | Self::Short2 + | Self::Ushort2Norm + | Self::Short2Norm + | Self::Half2 + | Self::Float + | Self::Uint + | Self::Int => 4, + Self::Ushort4 + | Self::Short4 + | Self::Ushort4Norm + | Self::Short4Norm + | Self::Half4 + | Self::Float2 + | Self::Uint2 + | Self::Int2 => 8, + Self::Float3 | Self::Uint3 | Self::Int3 => 12, + Self::Float4 | Self::Uint4 | Self::Int4 => 16, } } } @@ -1357,37 +1354,37 @@ pub struct Color { } impl Color { - pub const TRANSPARENT: Self = Color { + pub const TRANSPARENT: Self = Self { r: 0.0, g: 0.0, b: 0.0, a: 0.0, }; - pub const BLACK: Self = Color { + pub const BLACK: Self = Self { r: 0.0, g: 0.0, b: 0.0, a: 1.0, }; - pub const WHITE: Self = Color { + pub const WHITE: Self = Self { r: 1.0, g: 1.0, b: 1.0, a: 1.0, }; - pub const RED: Self = Color { + pub const RED: Self = Self { r: 1.0, g: 0.0, b: 0.0, a: 1.0, }; - pub const GREEN: Self = Color { + pub const GREEN: Self = Self { r: 0.0, g: 1.0, b: 0.0, a: 1.0, }; - pub const BLUE: Self = Color { + pub const BLUE: Self = Self { r: 0.0, g: 0.0, b: 1.0, @@ -1421,12 +1418,12 @@ pub struct Origin3d { } impl Origin3d { - pub const ZERO: Self = Origin3d { x: 0, y: 0, z: 0 }; + pub const ZERO: Self = Self { x: 0, y: 0, z: 0 }; } impl Default for Origin3d { fn default() -> Self { - Origin3d::ZERO + Self::ZERO } } @@ -1443,7 +1440,7 @@ pub struct Extent3d { impl Default for Extent3d { fn default() -> Self { - Extent3d { + Self { width: 1, height: 1, depth: 1, @@ -1504,7 +1501,7 @@ pub enum TextureAspect { impl Default for TextureAspect { fn default() -> Self { - TextureAspect::All + Self::All } } @@ -1539,7 +1536,7 @@ pub enum AddressMode { impl Default for AddressMode { fn default() -> Self { - AddressMode::ClampToEdge + Self::ClampToEdge } } @@ -1561,7 +1558,7 @@ pub enum FilterMode { impl Default for FilterMode { fn default() -> Self { - FilterMode::Nearest + Self::Nearest } } @@ -1832,8 +1829,7 @@ pub enum BindingType { impl BindingType { pub fn has_dynamic_offset(&self) -> bool { match *self { - BindingType::UniformBuffer { dynamic, .. } - | BindingType::StorageBuffer { dynamic, .. } => dynamic, + Self::UniformBuffer { dynamic, .. } | Self::StorageBuffer { dynamic, .. } => dynamic, _ => false, } }