Format all files

This commit is contained in:
grovesNL 2018-09-22 16:55:01 -06:00
parent 5759f769b0
commit 105a71d19a
12 changed files with 87 additions and 58 deletions

View File

@ -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"),
},
);
}

View File

@ -13,7 +13,7 @@ bitflags! {
}
#[repr(C)]
pub enum BindingType {
pub enum BindingType {
UniformBuffer = 0,
Sampler = 1,
SampledTexture = 2,

View File

@ -2,7 +2,6 @@ use hal;
use {CommandBuffer, CommandBufferId, ComputePassId};
pub struct ComputePass<B: hal::Backend> {
raw: B::CommandBuffer,
}

View File

@ -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!()
}

View File

@ -2,7 +2,6 @@ use hal;
use {CommandBuffer, CommandBufferId, RenderPassId};
pub struct RenderPass<B: hal::Backend> {
raw: B::CommandBuffer,
}

View File

@ -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) {

View File

@ -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<B: hal::Backend> {
device: B::Device,
@ -35,12 +33,14 @@ pub struct ShaderModule<B: hal::Backend> {
#[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 })
}

View File

@ -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))
}

View File

@ -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;

View File

@ -3,7 +3,6 @@ use resource;
use {BlendStateId, DepthStencilStateId, PipelineLayoutId};
#[repr(C)]
pub enum BlendFactor {
Zero = 0,

View File

@ -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<T> Registry<T> {
}
lazy_static! {
pub(crate) static ref ADAPTER_REGISTRY: Arc<Mutex<Registry<AdapterHandle>>> = Arc::new(Mutex::new(Registry::new()));
pub(crate) static ref DEVICE_REGISTRY: Arc<Mutex<Registry<DeviceHandle>>> = Arc::new(Mutex::new(Registry::new()));
pub(crate) static ref INSTANCE_REGISTRY: Arc<Mutex<Registry<InstanceHandle>>> = Arc::new(Mutex::new(Registry::new()));
pub(crate) static ref SHADER_MODULE_REGISTRY: Arc<Mutex<Registry<ShaderModuleHandle>>> = Arc::new(Mutex::new(Registry::new()));
pub(crate) static ref ADAPTER_REGISTRY: Arc<Mutex<Registry<AdapterHandle>>> =
Arc::new(Mutex::new(Registry::new()));
pub(crate) static ref DEVICE_REGISTRY: Arc<Mutex<Registry<DeviceHandle>>> =
Arc::new(Mutex::new(Registry::new()));
pub(crate) static ref INSTANCE_REGISTRY: Arc<Mutex<Registry<InstanceHandle>>> =
Arc::new(Mutex::new(Registry::new()));
pub(crate) static ref SHADER_MODULE_REGISTRY: Arc<Mutex<Registry<ShaderModuleHandle>>> =
Arc::new(Mutex::new(Registry::new()));
}

View File

@ -1,7 +1,6 @@
use hal;
use {Extent3d};
use Extent3d;
bitflags! {
#[repr(transparent)]