diff --git a/wgpu-native/src/command/allocator.rs b/wgpu-native/src/command/allocator.rs index 1272f2d86a..07ce1bfe98 100644 --- a/wgpu-native/src/command/allocator.rs +++ b/wgpu-native/src/command/allocator.rs @@ -3,7 +3,15 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use super::CommandBuffer; -use crate::{hub::GfxBackend, track::TrackerSet, DeviceId, Features, LifeGuard, Stored, SubmissionIndex}; +use crate::{ + hub::GfxBackend, + track::TrackerSet, + DeviceId, + Features, + LifeGuard, + Stored, + SubmissionIndex, +}; use hal::{command::CommandBuffer as _, device::Device as _, pool::CommandPool as _}; use parking_lot::Mutex; diff --git a/wgpu-native/src/command/bind.rs b/wgpu-native/src/command/bind.rs index aaad91577b..e6e04365bf 100644 --- a/wgpu-native/src/command/bind.rs +++ b/wgpu-native/src/command/bind.rs @@ -35,9 +35,7 @@ pub enum LayoutChange<'a> { #[derive(Debug)] pub enum Provision { Unchanged, - Changed { - was_compatible: bool, - }, + Changed { was_compatible: bool }, } struct TakeSome { @@ -94,9 +92,7 @@ impl BindGroupEntry { self.dynamic_offsets.clear(); self.dynamic_offsets.extend_from_slice(offsets); - Provision::Changed { - was_compatible, - } + Provision::Changed { was_compatible } } pub fn expect_layout(&mut self, bind_group_layout_id: BindGroupLayoutId) -> LayoutChange { @@ -107,8 +103,9 @@ impl BindGroupEntry { Some(BindGroupPair { layout_id, ref group_id, - }) if layout_id == bind_group_layout_id => - LayoutChange::Match(group_id.value, &self.dynamic_offsets), + }) if layout_id == bind_group_layout_id => { + LayoutChange::Match(group_id.value, &self.dynamic_offsets) + } Some(_) | None => LayoutChange::Mismatch, } } else { @@ -147,7 +144,7 @@ impl Binder { pub(crate) fn new(max_bind_groups: u32) -> Self { Self { pipeline_layout_id: None, - entries: smallvec![Default::default(); max_bind_groups as usize] + entries: smallvec![Default::default(); max_bind_groups as usize], } } @@ -181,8 +178,11 @@ impl Binder { Provision::Changed { was_compatible, .. } => { let compatible_count = self.compatible_count(); if index < compatible_count { - let end = compatible_count - .min(if was_compatible { index + 1 } else { self.entries.len() }); + let end = compatible_count.min(if was_compatible { + index + 1 + } else { + self.entries.len() + }); log::trace!("\t\tbinding up to {}", end); Some(( self.pipeline_layout_id?, diff --git a/wgpu-native/src/command/compute.rs b/wgpu-native/src/command/compute.rs index badfefa3ff..5278cc2999 100644 --- a/wgpu-native/src/command/compute.rs +++ b/wgpu-native/src/command/compute.rs @@ -184,7 +184,13 @@ pub extern "C" fn wgpu_compute_pass_insert_debug_marker( // Compute-specific routines -pub fn compute_pass_dispatch(global: &Global, pass_id: ComputePassId, x: u32, y: u32, z: u32) { +pub fn compute_pass_dispatch( + global: &Global, + pass_id: ComputePassId, + x: u32, + y: u32, + z: u32, +) { let hub = B::hub(global); let mut token = Token::root(); let (mut pass_guard, _) = hub.compute_passes.write(&mut token); @@ -291,8 +297,7 @@ pub fn compute_pass_set_pipeline( ); } } - LayoutChange::Match(..) | - LayoutChange::Unchanged => {} + LayoutChange::Match(..) | LayoutChange::Unchanged => {} LayoutChange::Mismatch => { is_compatible = false; } diff --git a/wgpu-native/src/command/mod.rs b/wgpu-native/src/command/mod.rs index 605fdd4c46..4313ffe504 100644 --- a/wgpu-native/src/command/mod.rs +++ b/wgpu-native/src/command/mod.rs @@ -50,15 +50,7 @@ use hal::{adapter::PhysicalDevice as _, command::CommandBuffer as _, device::Dev #[cfg(feature = "local")] use std::marker::PhantomData; -use std::{ - borrow::Borrow, - collections::hash_map::Entry, - iter, - mem, - ptr, - slice, - thread::ThreadId, -}; +use std::{borrow::Borrow, collections::hash_map::Entry, iter, mem, ptr, slice, thread::ThreadId}; pub struct RenderBundle { @@ -292,17 +284,15 @@ pub fn command_encoder_begin_render_pass( } let texture_id = match view.inner { TextureViewInner::Native { ref source_id, .. } => source_id.value, - TextureViewInner::SwapChain {..} => - panic!("Unexpected depth/stencil use of swapchain image!"), + TextureViewInner::SwapChain { .. } => { + panic!("Unexpected depth/stencil use of swapchain image!") + } }; let texture = &texture_guard[texture_id]; assert!(texture.usage.contains(TextureUsage::OUTPUT_ATTACHMENT)); - let old_layout = match trackers - .textures - .query(texture_id, view.range.clone()) - { + let old_layout = match trackers.textures.query(texture_id, view.range.clone()) { Some(usage) => { conv::map_texture_state( usage, @@ -355,40 +345,42 @@ pub fn command_encoder_begin_render_pass( view.samples, sample_count, "All attachments must have the same sample_count" ); - let first_use = trackers.views - .init(at.attachment, &view.life_guard.ref_count, (), ()); + let first_use = + trackers + .views + .init(at.attachment, &view.life_guard.ref_count, (), ()); let layouts = match view.inner { TextureViewInner::Native { ref source_id, .. } => { let texture = &texture_guard[source_id.value]; assert!(texture.usage.contains(TextureUsage::OUTPUT_ATTACHMENT)); - let old_layout = match trackers - .textures - .query(source_id.value, view.range.clone()) - { - Some(usage) => conv::map_texture_state(usage, hal::format::Aspects::COLOR).1, - None => { - // Required sub-resources have inconsistent states, we need to - // issue individual barriers instead of relying on the render pass. - let pending = trackers.textures.change_replace( - source_id.value, - &texture.life_guard.ref_count, - view.range.clone(), - TextureUsage::OUTPUT_ATTACHMENT, - ); - barriers.extend(pending.map(|pending| { - log::trace!("\tcolor {:?}", pending); - hal::memory::Barrier::Image { - states: pending.to_states(), - target: &texture.raw, - families: None, - range: pending.selector, - } - })); - hal::image::Layout::ColorAttachmentOptimal - } - }; + let old_layout = + match trackers.textures.query(source_id.value, view.range.clone()) { + Some(usage) => { + conv::map_texture_state(usage, hal::format::Aspects::COLOR).1 + } + None => { + // Required sub-resources have inconsistent states, we need to + // issue individual barriers instead of relying on the render pass. + let pending = trackers.textures.change_replace( + source_id.value, + &texture.life_guard.ref_count, + view.range.clone(), + TextureUsage::OUTPUT_ATTACHMENT, + ); + barriers.extend(pending.map(|pending| { + log::trace!("\tcolor {:?}", pending); + hal::memory::Barrier::Image { + states: pending.to_states(), + target: &texture.raw, + families: None, + range: pending.selector, + } + })); + hal::image::Layout::ColorAttachmentOptimal + } + }; old_layout .. hal::image::Layout::ColorAttachmentOptimal } TextureViewInner::SwapChain { .. } => { @@ -403,7 +395,11 @@ pub fn command_encoder_begin_render_pass( } let end = hal::image::Layout::Present; - let start = if first_use { hal::image::Layout::Undefined } else { end }; + let start = if first_use { + hal::image::Layout::Undefined + } else { + end + }; start .. end } }; @@ -427,40 +423,42 @@ pub fn command_encoder_begin_render_pass( view.samples, 1, "All resolve_targets must have a sample_count of 1" ); - let first_use = trackers.views - .init(resolve_target, &view.life_guard.ref_count, (), ()); + let first_use = + trackers + .views + .init(resolve_target, &view.life_guard.ref_count, (), ()); let layouts = match view.inner { TextureViewInner::Native { ref source_id, .. } => { let texture = &texture_guard[source_id.value]; assert!(texture.usage.contains(TextureUsage::OUTPUT_ATTACHMENT)); - let old_layout = match trackers - .textures - .query(source_id.value, view.range.clone()) - { - Some(usage) => conv::map_texture_state(usage, hal::format::Aspects::COLOR).1, - None => { - // Required sub-resources have inconsistent states, we need to - // issue individual barriers instead of relying on the render pass. - let pending = trackers.textures.change_replace( - source_id.value, - &texture.life_guard.ref_count, - view.range.clone(), - TextureUsage::OUTPUT_ATTACHMENT, - ); - barriers.extend(pending.map(|pending| { - log::trace!("\tresolve {:?}", pending); - hal::memory::Barrier::Image { - states: pending.to_states(), - target: &texture.raw, - families: None, - range: pending.selector, - } - })); - hal::image::Layout::ColorAttachmentOptimal - } - }; + let old_layout = + match trackers.textures.query(source_id.value, view.range.clone()) { + Some(usage) => { + conv::map_texture_state(usage, hal::format::Aspects::COLOR).1 + } + None => { + // Required sub-resources have inconsistent states, we need to + // issue individual barriers instead of relying on the render pass. + let pending = trackers.textures.change_replace( + source_id.value, + &texture.life_guard.ref_count, + view.range.clone(), + TextureUsage::OUTPUT_ATTACHMENT, + ); + barriers.extend(pending.map(|pending| { + log::trace!("\tresolve {:?}", pending); + hal::memory::Barrier::Image { + states: pending.to_states(), + target: &texture.raw, + families: None, + range: pending.selector, + } + })); + hal::image::Layout::ColorAttachmentOptimal + } + }; old_layout .. hal::image::Layout::ColorAttachmentOptimal } TextureViewInner::SwapChain { .. } => { @@ -475,7 +473,11 @@ pub fn command_encoder_begin_render_pass( } let end = hal::image::Layout::Present; - let start = if first_use { hal::image::Layout::Undefined } else { end }; + let start = if first_use { + hal::image::Layout::Undefined + } else { + end + }; start .. end } }; @@ -604,12 +606,16 @@ pub fn command_encoder_begin_render_pass( let fb = { let attachments = e.key().all().map(|&id| match view_guard[id].inner { TextureViewInner::Native { ref raw, .. } => raw, - TextureViewInner::SwapChain { ref image, .. } => Borrow::borrow(image), + TextureViewInner::SwapChain { ref image, .. } => { + Borrow::borrow(image) + } }); unsafe { - device - .raw - .create_framebuffer(&render_pass, attachments, extent.unwrap()) + device.raw.create_framebuffer( + &render_pass, + attachments, + extent.unwrap(), + ) } .unwrap() }; @@ -655,9 +661,7 @@ pub fn command_encoder_begin_render_pass( uint32: conv::map_color_u32(&at.clear_color), }, }; - Some(hal::command::ClearValue { - color: value, - }) + Some(hal::command::ClearValue { color: value }) } } }) diff --git a/wgpu-native/src/command/render.rs b/wgpu-native/src/command/render.rs index 40f31ee86e..2c4c8a9797 100644 --- a/wgpu-native/src/command/render.rs +++ b/wgpu-native/src/command/render.rs @@ -21,13 +21,13 @@ use crate::{ Stored, }; #[cfg(feature = "local")] -use crate::{gfx_select, RawString, RenderBundleId, hub::GLOBAL}; +use crate::{gfx_select, hub::GLOBAL, RawString, RenderBundleId}; use hal::command::CommandBuffer as _; -use std::{iter, ops::Range}; #[cfg(feature = "local")] use std::slice; +use std::{iter, ops::Range}; #[derive(Debug, PartialEq)] enum OptionalState { @@ -644,8 +644,7 @@ pub fn render_pass_set_pipeline( ); } } - LayoutChange::Match(..) | - LayoutChange::Unchanged => {} + LayoutChange::Match(..) | LayoutChange::Unchanged => {} LayoutChange::Mismatch => { is_compatible = false; } @@ -704,7 +703,9 @@ pub extern "C" fn wgpu_render_pass_set_pipeline( } pub fn render_pass_set_blend_color( - global: &Global, pass_id: RenderPassId, color: &Color + global: &Global, + pass_id: RenderPassId, + color: &Color, ) { let hub = B::hub(global); let mut token = Token::root(); @@ -725,7 +726,9 @@ pub extern "C" fn wgpu_render_pass_set_blend_color(pass_id: RenderPassId, color: } pub fn render_pass_set_stencil_reference( - global: &Global, pass_id: RenderPassId, value: u32 + global: &Global, + pass_id: RenderPassId, + value: u32, ) { let hub = B::hub(global); let mut token = Token::root(); @@ -741,9 +744,7 @@ pub fn render_pass_set_stencil_reference( #[cfg(feature = "local")] #[no_mangle] -pub extern "C" fn wgpu_render_pass_set_stencil_reference( - pass_id: RenderPassId, value: u32 -) { +pub extern "C" fn wgpu_render_pass_set_stencil_reference(pass_id: RenderPassId, value: u32) { gfx_select!(pass_id => render_pass_set_stencil_reference(&*GLOBAL, pass_id, value)) } diff --git a/wgpu-native/src/conv.rs b/wgpu-native/src/conv.rs index 4af1ab45ed..60495e12be 100644 --- a/wgpu-native/src/conv.rs +++ b/wgpu-native/src/conv.rs @@ -311,7 +311,10 @@ fn map_stencil_operation(stencil_operation: pipeline::StencilOperation) -> hal:: } } -pub(crate) fn map_texture_format(texture_format: resource::TextureFormat, features: Features) -> hal::format::Format { +pub(crate) fn map_texture_format( + texture_format: resource::TextureFormat, + features: Features, +) -> hal::format::Format { use crate::resource::TextureFormat as Tf; use hal::format::Format as H; match texture_format { @@ -371,16 +374,20 @@ pub(crate) fn map_texture_format(texture_format: resource::TextureFormat, featur // Depth and stencil formats Tf::Depth32Float => H::D32Sfloat, - Tf::Depth24Plus => if features.supports_texture_d24_s8 { - H::D24UnormS8Uint - } else { - H::D32Sfloat + Tf::Depth24Plus => { + if features.supports_texture_d24_s8 { + H::D24UnormS8Uint + } else { + H::D32Sfloat + } + } + Tf::Depth24PlusStencil8 => { + if features.supports_texture_d24_s8 { + H::D24UnormS8Uint + } else { + H::D32SfloatS8Uint + } } - Tf::Depth24PlusStencil8 => if features.supports_texture_d24_s8 { - H::D24UnormS8Uint - } else { - H::D32SfloatS8Uint - }, } } diff --git a/wgpu-native/src/device.rs b/wgpu-native/src/device.rs index 18f0b6320e..ac07e7f8c6 100644 --- a/wgpu-native/src/device.rs +++ b/wgpu-native/src/device.rs @@ -3,9 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #[cfg(feature = "local")] -use crate::{ - instance::Limits, -}; +use crate::instance::Limits; use crate::{ binding_model, command, @@ -71,7 +69,7 @@ use std::{ ops::Range, ptr, slice, - sync::atomic::{Ordering}, + sync::atomic::Ordering, }; @@ -277,7 +275,10 @@ impl PendingResources { } fn triage_referenced( - &mut self, global: &Global, trackers: &mut TrackerSet, mut token: &mut Token> + &mut self, + global: &Global, + trackers: &mut TrackerSet, + mut token: &mut Token>, ) { // Before destruction, a resource is expected to have the following strong refs: // - in resource itself @@ -567,11 +568,16 @@ impl Device { features: Features { max_bind_groups, supports_texture_d24_s8, - } + }, } } - fn maintain(&self, global: &Global, force_wait: bool, token: &mut Token) -> Vec { + fn maintain( + &self, + global: &Global, + force_wait: bool, + token: &mut Token, + ) -> Vec { let mut pending = self.pending.lock(); let mut trackers = self.trackers.lock(); @@ -683,7 +689,9 @@ impl Device { // Ensure `D24Plus` textures cannot be copied match desc.format { TextureFormat::Depth24Plus | TextureFormat::Depth24PlusStencil8 => { - assert!(!desc.usage.intersects(TextureUsage::COPY_SRC | TextureUsage::COPY_DST)); + assert!(!desc + .usage + .intersects(TextureUsage::COPY_SRC | TextureUsage::COPY_DST)); } _ => {} } @@ -1031,9 +1039,7 @@ pub extern "C" fn wgpu_texture_destroy(texture_id: TextureId) { gfx_select!(texture_id => texture_destroy(&*GLOBAL, texture_id)) } -pub fn texture_view_destroy( - global: &Global, texture_view_id: TextureViewId -) { +pub fn texture_view_destroy(global: &Global, texture_view_id: TextureViewId) { let hub = B::hub(global); let mut token = Token::root(); let (device_guard, mut token) = hub.devices.read(&mut token); @@ -1041,10 +1047,10 @@ pub fn texture_view_destroy( let (texture_view_guard, _) = hub.texture_views.read(&mut token); let view = &texture_view_guard[texture_view_id]; let device_id = match view.inner { - resource::TextureViewInner::Native { ref source_id, .. } => - texture_guard[source_id.value].device_id.value, - resource::TextureViewInner::SwapChain { .. } => - panic!("Can't destroy a swap chain image"), + resource::TextureViewInner::Native { ref source_id, .. } => { + texture_guard[source_id.value].device_id.value + } + resource::TextureViewInner::SwapChain { .. } => panic!("Can't destroy a swap chain image"), }; device_guard[device_id].pending.lock().destroy( ResourceId::TextureView(texture_view_id), @@ -1295,7 +1301,11 @@ pub fn device_create_bind_group( .buffers .use_extend(&*buffer_guard, bb.buffer, (), usage) .unwrap(); - assert!(buffer.usage.contains(usage), "Expected buffer usage {:?}", usage); + assert!( + buffer.usage.contains(usage), + "Expected buffer usage {:?}", + usage + ); let end = if bb.size == 0 { None @@ -1315,7 +1325,8 @@ pub fn device_create_bind_group( } binding_model::BindingResource::Sampler(id) => { assert_eq!(decl.ty, binding_model::BindingType::Sampler); - let sampler = used.samplers + let sampler = used + .samplers .use_extend(&*sampler_guard, id, (), ()) .unwrap(); hal::pso::Descriptor::Sampler(&sampler.raw) @@ -1336,21 +1347,26 @@ pub fn device_create_bind_group( .use_extend(&*texture_view_guard, id, (), ()) .unwrap(); match view.inner { - resource::TextureViewInner::Native { ref raw, ref source_id } => { - let texture = used.textures - .use_extend( - &*texture_guard, - source_id.value, - view.range.clone(), - usage, - ) - .unwrap(); - assert!(texture.usage.contains(usage)); - - hal::pso::Descriptor::Image(raw, image_layout) + resource::TextureViewInner::Native { + ref raw, + ref source_id, + } => { + let texture = used + .textures + .use_extend( + &*texture_guard, + source_id.value, + view.range.clone(), + usage, + ) + .unwrap(); + assert!(texture.usage.contains(usage)); + + hal::pso::Descriptor::Image(raw, image_layout) + } + resource::TextureViewInner::SwapChain { .. } => { + panic!("Unable to create a bind group with a swap chain image") } - resource::TextureViewInner::SwapChain { .. } => - panic!("Unable to create a bind group with a swap chain image"), } } }; @@ -1470,7 +1486,9 @@ pub fn device_create_command_encoder( value: device_id, ref_count: device.life_guard.ref_count.clone(), }; - let mut comb = device.com_allocator.allocate(dev_stored, &device.raw, device.features); + let mut comb = device + .com_allocator + .allocate(dev_stored, &device.raw, device.features); unsafe { comb.raw.last_mut().unwrap().begin( hal::command::CommandBufferFlags::ONE_TIME_SUBMIT, @@ -1537,9 +1555,15 @@ pub fn queue_submit( if let Some((view_id, fbo)) = comb.used_swap_chain.take() { let sem = match texture_view_guard[view_id.value].inner { resource::TextureViewInner::Native { .. } => unreachable!(), - resource::TextureViewInner::SwapChain { ref source_id, ref mut framebuffer, .. } => { - assert!(framebuffer.is_none(), - "Using a swap chain in multiple framebuffers is not supported yet"); + resource::TextureViewInner::SwapChain { + ref source_id, + ref mut framebuffer, + .. + } => { + assert!( + framebuffer.is_none(), + "Using a swap chain in multiple framebuffers is not supported yet" + ); *framebuffer = Some(fbo); &swap_chain_guard[source_id.value].semaphore } @@ -1621,8 +1645,7 @@ pub fn queue_submit( }; unsafe { - device.queue_group.queues[0] - .submit(submission, Some(&fence)); + device.queue_group.queues[0].submit(submission, Some(&fence)); } (submit_index, fence) @@ -2034,13 +2057,17 @@ pub fn device_create_swap_chain( formats ); } - if desc.width < caps.extents.start().width || - desc.width > caps.extents.end().width || - desc.height < caps.extents.start().height || - desc.height > caps.extents.end().height + if desc.width < caps.extents.start().width + || desc.width > caps.extents.end().width + || desc.height < caps.extents.start().height + || desc.height > caps.extents.end().height { - log::warn!("Requested size {}x{} is outside of the supported range: {:?}", - desc.width, desc.height, caps.extents); + log::warn!( + "Requested size {}x{} is outside of the supported range: {:?}", + desc.width, + desc.height, + caps.extents + ); } unsafe { diff --git a/wgpu-native/src/hub.rs b/wgpu-native/src/hub.rs index a8e6008998..b4f1328311 100644 --- a/wgpu-native/src/hub.rs +++ b/wgpu-native/src/hub.rs @@ -148,7 +148,8 @@ impl Storage { pub fn remove(&mut self, id: I) -> Option { let (index, epoch, _) = id.unzip(); - self.map.remove(index as usize) + self.map + .remove(index as usize) .map(|(value, storage_epoch)| { assert_eq!(epoch, storage_epoch); value @@ -390,7 +391,10 @@ impl Default for Hub { #[derive(Debug, Default)] pub struct Hubs { - #[cfg(any(not(any(target_os = "ios", target_os = "macos")), feature = "gfx-backend-vulkan"))] + #[cfg(any( + not(any(target_os = "ios", target_os = "macos")), + feature = "gfx-backend-vulkan" + ))] vulkan: Hub, #[cfg(any(target_os = "ios", target_os = "macos"))] metal: Hub, @@ -422,7 +426,10 @@ pub trait GfxBackend: hal::Backend { fn get_surface_mut(surface: &mut Surface) -> &mut Self::Surface; } -#[cfg(any(not(any(target_os = "ios", target_os = "macos")), feature = "gfx-backend-vulkan"))] +#[cfg(any( + not(any(target_os = "ios", target_os = "macos")), + feature = "gfx-backend-vulkan" +))] impl GfxBackend for backend::Vulkan { const VARIANT: Backend = Backend::Vulkan; fn hub(global: &Global) -> &Hub { diff --git a/wgpu-native/src/instance.rs b/wgpu-native/src/instance.rs index 8000fa62b7..fd6c932782 100644 --- a/wgpu-native/src/instance.rs +++ b/wgpu-native/src/instance.rs @@ -15,26 +15,24 @@ use crate::{ DeviceId, }; #[cfg(feature = "local")] -use crate::{gfx_select, SurfaceId, hub::GLOBAL}; +use crate::{gfx_select, hub::GLOBAL, SurfaceId}; #[cfg(feature = "local")] use bitflags::bitflags; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; -use hal::{ - self, - Instance as _, - adapter::PhysicalDevice as _, - queue::QueueFamily as _, -}; +use hal::{self, adapter::PhysicalDevice as _, queue::QueueFamily as _, Instance as _}; #[cfg(feature = "local")] use std::marker::PhantomData; #[derive(Debug)] pub struct Instance { - #[cfg(any(not(any(target_os = "ios", target_os = "macos")), feature = "gfx-backend-vulkan"))] + #[cfg(any( + not(any(target_os = "ios", target_os = "macos")), + feature = "gfx-backend-vulkan" + ))] vulkan: Option, #[cfg(any(target_os = "ios", target_os = "macos"))] metal: gfx_backend_metal::Instance, @@ -47,7 +45,10 @@ pub struct Instance { impl Instance { pub fn new(name: &str, version: u32) -> Self { Instance { - #[cfg(any(not(any(target_os = "ios", target_os = "macos")), feature = "gfx-backend-vulkan"))] + #[cfg(any( + not(any(target_os = "ios", target_os = "macos")), + feature = "gfx-backend-vulkan" + ))] vulkan: gfx_backend_vulkan::Instance::create(name, version).ok(), #[cfg(any(target_os = "ios", target_os = "macos"))] metal: gfx_backend_metal::Instance::create(name, version).unwrap(), @@ -63,7 +64,10 @@ type GfxSurface = ::Surface; #[derive(Debug)] pub struct Surface { - #[cfg(any(not(any(target_os = "ios", target_os = "macos")), feature = "gfx-backend-vulkan"))] + #[cfg(any( + not(any(target_os = "ios", target_os = "macos")), + feature = "gfx-backend-vulkan" + ))] pub(crate) vulkan: Option>, #[cfg(any(target_os = "ios", target_os = "macos"))] pub(crate) metal: GfxSurface, @@ -219,7 +223,12 @@ pub fn wgpu_create_surface(raw_handle: raw_window_handle::RawWindowHandle) -> Su .register_identity(PhantomData, surface, &mut token) } -#[cfg(all(feature = "local", unix, not(target_os = "ios"), not(target_os = "macos")))] +#[cfg(all( + feature = "local", + unix, + not(target_os = "ios"), + not(target_os = "macos") +))] #[no_mangle] pub extern "C" fn wgpu_create_surface_from_xlib( display: *mut *const std::ffi::c_void, @@ -294,7 +303,10 @@ pub fn request_adapter( let id_dx12 = find_input(Backend::Dx12); let id_dx11 = find_input(Backend::Dx11); - #[cfg(any(not(any(target_os = "ios", target_os = "macos")), feature = "gfx-backend-vulkan"))] + #[cfg(any( + not(any(target_os = "ios", target_os = "macos")), + feature = "gfx-backend-vulkan" + ))] let mut adapters_vk = match instance.vulkan { Some(ref inst) if id_vulkan.is_some() => { let adapters = inst.enumerate_adapters(); @@ -360,7 +372,10 @@ pub fn request_adapter( let mut token = Token::root(); let mut selected = preferred_gpu.unwrap_or(0); - #[cfg(any(not(any(target_os = "ios", target_os = "macos")), feature = "gfx-backend-vulkan"))] + #[cfg(any( + not(any(target_os = "ios", target_os = "macos")), + feature = "gfx-backend-vulkan" + ))] { if selected < adapters_vk.len() { let adapter = Adapter { @@ -446,12 +461,11 @@ pub fn adapter_request_device( let family = adapter .queue_families .iter() - .find(|family| { - family.queue_type().supports_graphics() - }) + .find(|family| family.queue_type().supports_graphics()) .unwrap(); let mut gpu = unsafe { - adapter.physical_device + adapter + .physical_device .open(&[(family, &[1.0])], hal::Features::empty()) .unwrap() }; @@ -516,8 +530,6 @@ pub fn adapter_get_info(global: &Global, adapter_id: AdapterId) - } #[cfg(feature = "local")] -pub fn wgpu_adapter_get_info( - adapter_id: AdapterId -) -> AdapterInfo { +pub fn wgpu_adapter_get_info(adapter_id: AdapterId) -> AdapterInfo { gfx_select!(adapter_id => adapter_get_info(&*GLOBAL, adapter_id)) } diff --git a/wgpu-native/src/lib.rs b/wgpu-native/src/lib.rs index 4fab5a8355..bb6c010941 100644 --- a/wgpu-native/src/lib.rs +++ b/wgpu-native/src/lib.rs @@ -10,7 +10,10 @@ pub mod backend { pub use gfx_backend_empty::Backend as Empty; #[cfg(any(target_os = "ios", target_os = "macos"))] pub use gfx_backend_metal::Backend as Metal; - #[cfg(any(not(any(target_os = "ios", target_os = "macos")), feature = "gfx-backend-vulkan"))] + #[cfg(any( + not(any(target_os = "ios", target_os = "macos")), + feature = "gfx-backend-vulkan" + ))] pub use gfx_backend_vulkan::Backend as Vulkan; } @@ -36,8 +39,8 @@ pub use self::instance::*; pub use self::pipeline::*; pub use self::resource::*; pub use self::swap_chain::*; -pub use hal::pso::read_spirv; pub use hal::adapter::AdapterInfo; +pub use hal::pso::read_spirv; use std::{ os::raw::c_char, diff --git a/wgpu-native/src/swap_chain.rs b/wgpu-native/src/swap_chain.rs index 5b23b54625..666ade3282 100644 --- a/wgpu-native/src/swap_chain.rs +++ b/wgpu-native/src/swap_chain.rs @@ -48,12 +48,7 @@ use crate::{ #[cfg(feature = "local")] use crate::{gfx_select, hub::GLOBAL}; -use hal::{ - self, - device::Device as _, - queue::CommandQueue as _, - window::PresentationSurface as _, -}; +use hal::{self, device::Device as _, queue::CommandQueue as _, window::PresentationSurface as _}; #[cfg(feature = "local")] use std::marker::PhantomData; @@ -89,7 +84,11 @@ pub struct SwapChainDescriptor { } impl SwapChainDescriptor { - pub(crate) fn to_hal(&self, num_frames: u32, features: &Features) -> hal::window::SwapchainConfig { + pub(crate) fn to_hal( + &self, + num_frames: u32, + features: &Features, + ) -> hal::window::SwapchainConfig { let mut config = hal::window::SwapchainConfig::new( self.width, self.height, @@ -155,12 +154,8 @@ pub fn swap_chain_get_next_texture( log::warn!("acquire_image() failed ({:?}), reconfiguring swapchain", e); let desc = sc.desc.to_hal(sc.num_frames, &device.features); unsafe { - suf - .configure_swapchain(&device.raw, desc) - .unwrap(); - suf - .acquire_image(FRAME_TIMEOUT_MS * 1_000_000) - .unwrap() + suf.configure_swapchain(&device.raw, desc).unwrap(); + suf.acquire_image(FRAME_TIMEOUT_MS * 1_000_000).unwrap() } } } @@ -193,15 +188,16 @@ pub fn swap_chain_get_next_texture( let (view_id, _) = hub.texture_views.new_identity(view_id_in); hub.texture_views.register(view_id, view, &mut token); - assert!(sc.acquired_view_id.is_none(), "Swap chain image is already acquired"); + assert!( + sc.acquired_view_id.is_none(), + "Swap chain image is already acquired" + ); sc.acquired_view_id = Some(Stored { value: view_id, ref_count, }); - SwapChainOutput { - view_id, - } + SwapChainOutput { view_id } } #[cfg(feature = "local")] @@ -221,22 +217,21 @@ pub fn swap_chain_present(global: &Global, swap_chain_id: SwapCha let sc = &mut swap_chain_guard[swap_chain_id]; let device = &mut device_guard[sc.device_id.value]; - let view_id = sc.acquired_view_id + let view_id = sc + .acquired_view_id .take() .expect("Swap chain image is not acquired"); let (view, _) = hub.texture_views.unregister(view_id.value, &mut token); let (image, framebuffer) = match view.inner { resource::TextureViewInner::Native { .. } => unreachable!(), - resource::TextureViewInner::SwapChain { image, framebuffer, .. } => (image, framebuffer), + resource::TextureViewInner::SwapChain { + image, framebuffer, .. + } => (image, framebuffer), }; let err = unsafe { let queue = &mut device.queue_group.queues[0]; - queue.present_surface( - B::get_surface_mut(surface), - image, - Some(&sc.semaphore), - ) + queue.present_surface(B::get_surface_mut(surface), image, Some(&sc.semaphore)) }; if let Err(e) = err { log::warn!("present failed: {:?}", e);