diff --git a/examples/hello_triangle/main.rs b/examples/hello_triangle/main.rs index 8ebcc108f..3025ea6f8 100644 --- a/examples/hello_triangle/main.rs +++ b/examples/hello_triangle/main.rs @@ -2,18 +2,30 @@ extern crate wgpu_native as wgn; fn main() { let instance = wgn::create_instance(); - let adapter = wgn::instance_get_adapter(instance, wgn::AdapterDescriptor { - power_preference: wgn::PowerPreference::LowPower, - }); - let device = wgn::adapter_create_device(adapter, wgn::DeviceDescriptor { - extensions: wgn::Extensions { - anisotropic_filtering: false, + let adapter = wgn::instance_get_adapter( + instance, + wgn::AdapterDescriptor { + power_preference: wgn::PowerPreference::LowPower, }, - }); - let _vs = wgn::device_create_shader_module(device, wgn::ShaderModuleDescriptor { - code: include_bytes!("./shaders/hello_triangle.vert.spv"), - }); - let _fs = wgn::device_create_shader_module(device, wgn::ShaderModuleDescriptor { - code: include_bytes!("./shaders/hello_triangle.frag.spv"), - }); + ); + let device = wgn::adapter_create_device( + adapter, + wgn::DeviceDescriptor { + extensions: wgn::Extensions { + anisotropic_filtering: false, + }, + }, + ); + let _vs = wgn::device_create_shader_module( + device, + wgn::ShaderModuleDescriptor { + code: include_bytes!("./shaders/hello_triangle.vert.spv"), + }, + ); + let _fs = wgn::device_create_shader_module( + device, + wgn::ShaderModuleDescriptor { + code: include_bytes!("./shaders/hello_triangle.frag.spv"), + }, + ); } diff --git a/wgpu-native/src/binding_model.rs b/wgpu-native/src/binding_model.rs index 5bbc5a007..ca8df9052 100644 --- a/wgpu-native/src/binding_model.rs +++ b/wgpu-native/src/binding_model.rs @@ -13,7 +13,7 @@ bitflags! { } #[repr(C)] -pub enum BindingType { +pub enum BindingType { UniformBuffer = 0, Sampler = 1, SampledTexture = 2, diff --git a/wgpu-native/src/command/compute.rs b/wgpu-native/src/command/compute.rs index 10fef286b..daff85ff3 100644 --- a/wgpu-native/src/command/compute.rs +++ b/wgpu-native/src/command/compute.rs @@ -2,7 +2,6 @@ use hal; use {CommandBuffer, CommandBufferId, ComputePassId}; - pub struct ComputePass { raw: B::CommandBuffer, } diff --git a/wgpu-native/src/command/mod.rs b/wgpu-native/src/command/mod.rs index d096df1fa..5a90af140 100644 --- a/wgpu-native/src/command/mod.rs +++ b/wgpu-native/src/command/mod.rs @@ -6,9 +6,10 @@ pub use self::render::*; use hal; -use {BufferId, Color, CommandBufferId, ComputePassId, Origin3d, - RenderPassId, TextureViewId, TextureId}; - +use { + BufferId, Color, CommandBufferId, ComputePassId, Origin3d, RenderPassId, TextureId, + TextureViewId, +}; #[repr(C)] pub enum LoadOp { @@ -72,13 +73,12 @@ pub struct CommandBufferDescriptor; #[no_mangle] pub extern "C" fn command_buffer_begin_render_pass( - command_buffer: CommandBufferId + command_buffer: CommandBufferId, ) -> RenderPassId { unimplemented!() } #[no_mangle] -pub extern "C" fn command_buffer_begin_compute_pass( -) -> ComputePassId { +pub extern "C" fn command_buffer_begin_compute_pass() -> ComputePassId { unimplemented!() } diff --git a/wgpu-native/src/command/render.rs b/wgpu-native/src/command/render.rs index 98b936542..f77d1edcd 100644 --- a/wgpu-native/src/command/render.rs +++ b/wgpu-native/src/command/render.rs @@ -2,7 +2,6 @@ use hal; use {CommandBuffer, CommandBufferId, RenderPassId}; - pub struct RenderPass { raw: B::CommandBuffer, } diff --git a/wgpu-native/src/conv.rs b/wgpu-native/src/conv.rs index 39d55b2ca..238d6a8f0 100644 --- a/wgpu-native/src/conv.rs +++ b/wgpu-native/src/conv.rs @@ -2,11 +2,12 @@ use hal; use resource; - -pub(crate) fn map_buffer_usage(usage: resource::BufferUsageFlags) -> (hal::buffer::Usage, hal::memory::Properties) { - use resource::BufferUsageFlags as W; +pub(crate) fn map_buffer_usage( + usage: resource::BufferUsageFlags, +) -> (hal::buffer::Usage, hal::memory::Properties) { use hal::buffer::Usage as U; use hal::memory::Properties as P; + use resource::BufferUsageFlags as W; let mut hal_memory = P::empty(); if usage.contains(W::MAP_READ) { diff --git a/wgpu-native/src/device.rs b/wgpu-native/src/device.rs index 60c2d731e..37ef45d64 100644 --- a/wgpu-native/src/device.rs +++ b/wgpu-native/src/device.rs @@ -4,10 +4,8 @@ use {conv, memory, pipeline, resource}; use registry; use {BufferId, CommandBufferId, DeviceId, ShaderModuleId}; - #[repr(C)] -pub struct CommandBufferDescriptor { -} +pub struct CommandBufferDescriptor {} pub struct Device { device: B::Device, @@ -35,12 +33,14 @@ pub struct ShaderModule { #[no_mangle] pub extern "C" fn device_create_shader_module( - device_id: DeviceId, desc: pipeline::ShaderModuleDescriptor + device_id: DeviceId, + desc: pipeline::ShaderModuleDescriptor, ) -> ShaderModuleId { let device_registry = registry::DEVICE_REGISTRY.lock().unwrap(); let device = device_registry.get(device_id).unwrap(); let shader = device.device.create_shader_module(desc.code).unwrap(); - registry::SHADER_MODULE_REGISTRY.lock().unwrap().register(ShaderModule { - raw: shader, - }) + registry::SHADER_MODULE_REGISTRY + .lock() + .unwrap() + .register(ShaderModule { raw: shader }) } diff --git a/wgpu-native/src/instance.rs b/wgpu-native/src/instance.rs index 3415a900b..d9943958e 100644 --- a/wgpu-native/src/instance.rs +++ b/wgpu-native/src/instance.rs @@ -3,7 +3,6 @@ use hal::{self, Instance as _Instance, PhysicalDevice as _PhysicalDevice}; use registry; use {AdapterId, Device, DeviceId, InstanceId}; - #[repr(C)] pub enum PowerPreference { Default = 0, @@ -28,22 +27,30 @@ pub struct DeviceDescriptor { #[no_mangle] pub extern "C" fn create_instance() -> InstanceId { - #[cfg(any(feature = "gfx-backend-vulkan", feature = "gfx-backend-dx12", feature = "gfx-backend-metal"))] + #[cfg(any( + feature = "gfx-backend-vulkan", + feature = "gfx-backend-dx12", + feature = "gfx-backend-metal" + ))] { let mut registry = registry::INSTANCE_REGISTRY.lock().unwrap(); let inst = ::back::Instance::create("wgpu", 1); registry.register(inst) } - #[cfg(not(any(feature = "gfx-backend-vulkan", feature = "gfx-backend-dx12", feature = "gfx-backend-metal")))] + #[cfg(not(any( + feature = "gfx-backend-vulkan", + feature = "gfx-backend-dx12", + feature = "gfx-backend-metal" + )))] { unimplemented!() } } - #[no_mangle] pub extern "C" fn instance_get_adapter( - instance_id: InstanceId, desc: AdapterDescriptor + instance_id: InstanceId, + desc: AdapterDescriptor, ) -> AdapterId { let instance_registry = registry::INSTANCE_REGISTRY.lock().unwrap(); let instance = instance_registry.get(instance_id).unwrap(); @@ -58,19 +65,22 @@ pub extern "C" fn instance_get_adapter( let some = match desc.power_preference { PowerPreference::LowPower => low.or(high), - PowerPreference::HighPerformance | - PowerPreference::Default => high.or(low), + PowerPreference::HighPerformance | PowerPreference::Default => high.or(low), }; - registry::ADAPTER_REGISTRY.lock().unwrap().register(some.or(other).unwrap()) + registry::ADAPTER_REGISTRY + .lock() + .unwrap() + .register(some.or(other).unwrap()) } #[no_mangle] -pub extern "C" fn adapter_create_device( - adapter_id: AdapterId, desc: DeviceDescriptor -) -> DeviceId { +pub extern "C" fn adapter_create_device(adapter_id: AdapterId, desc: DeviceDescriptor) -> DeviceId { let mut adapter_registry = registry::ADAPTER_REGISTRY.lock().unwrap(); let adapter = adapter_registry.get_mut(adapter_id).unwrap(); let (device, queue_group) = adapter.open_with::<_, hal::General>(1, |_qf| true).unwrap(); let mem_props = adapter.physical_device.memory_properties(); - registry::DEVICE_REGISTRY.lock().unwrap().register(Device::new(device, queue_group, mem_props)) + registry::DEVICE_REGISTRY + .lock() + .unwrap() + .register(Device::new(device, queue_group, mem_props)) } diff --git a/wgpu-native/src/lib.rs b/wgpu-native/src/lib.rs index e56160fa4..d53af324c 100644 --- a/wgpu-native/src/lib.rs +++ b/wgpu-native/src/lib.rs @@ -1,14 +1,20 @@ -#[macro_use] extern crate bitflags; -#[macro_use] extern crate lazy_static; +#[macro_use] +extern crate bitflags; +#[macro_use] +extern crate lazy_static; -#[cfg(feature = "gfx-backend-vulkan")] -extern crate gfx_backend_vulkan as back; #[cfg(feature = "gfx-backend-dx12")] extern crate gfx_backend_dx12 as back; +#[cfg(not(any( + feature = "gfx-backend-vulkan", + feature = "gfx-backend-dx12", + feature = "gfx-backend-metal" +)))] +extern crate gfx_backend_empty as back; #[cfg(feature = "gfx-backend-metal")] extern crate gfx_backend_metal as back; -#[cfg(not(any(feature = "gfx-backend-vulkan", feature = "gfx-backend-dx12", feature = "gfx-backend-metal")))] -extern crate gfx_backend_empty as back; +#[cfg(feature = "gfx-backend-vulkan")] +extern crate gfx_backend_vulkan as back; extern crate gfx_hal as hal; extern crate gfx_memory as memory; diff --git a/wgpu-native/src/pipeline.rs b/wgpu-native/src/pipeline.rs index 9757b950f..54d3626ff 100644 --- a/wgpu-native/src/pipeline.rs +++ b/wgpu-native/src/pipeline.rs @@ -3,7 +3,6 @@ use resource; use {BlendStateId, DepthStencilStateId, PipelineLayoutId}; - #[repr(C)] pub enum BlendFactor { Zero = 0, diff --git a/wgpu-native/src/registry.rs b/wgpu-native/src/registry.rs index e0bb48e82..c418c2827 100644 --- a/wgpu-native/src/registry.rs +++ b/wgpu-native/src/registry.rs @@ -1,5 +1,5 @@ -use std::{borrow, cmp, fmt, ops, ptr}; use std::sync::{Arc, Mutex}; +use std::{borrow, cmp, fmt, ops, ptr}; use hal::backend::FastHashMap; use {AdapterHandle, DeviceHandle, InstanceHandle, ShaderModuleHandle}; @@ -36,8 +36,12 @@ impl Registry { } lazy_static! { - pub(crate) static ref ADAPTER_REGISTRY: Arc>> = Arc::new(Mutex::new(Registry::new())); - pub(crate) static ref DEVICE_REGISTRY: Arc>> = Arc::new(Mutex::new(Registry::new())); - pub(crate) static ref INSTANCE_REGISTRY: Arc>> = Arc::new(Mutex::new(Registry::new())); - pub(crate) static ref SHADER_MODULE_REGISTRY: Arc>> = Arc::new(Mutex::new(Registry::new())); + pub(crate) static ref ADAPTER_REGISTRY: Arc>> = + Arc::new(Mutex::new(Registry::new())); + pub(crate) static ref DEVICE_REGISTRY: Arc>> = + Arc::new(Mutex::new(Registry::new())); + pub(crate) static ref INSTANCE_REGISTRY: Arc>> = + Arc::new(Mutex::new(Registry::new())); + pub(crate) static ref SHADER_MODULE_REGISTRY: Arc>> = + Arc::new(Mutex::new(Registry::new())); } diff --git a/wgpu-native/src/resource.rs b/wgpu-native/src/resource.rs index defc23431..6913af100 100644 --- a/wgpu-native/src/resource.rs +++ b/wgpu-native/src/resource.rs @@ -1,7 +1,6 @@ use hal; -use {Extent3d}; - +use Extent3d; bitflags! { #[repr(transparent)]