mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-25 00:03:29 +00:00
Run cargo fmt
This commit is contained in:
parent
241aef131a
commit
3975320543
@ -1,25 +1,20 @@
|
||||
extern crate wgpu;
|
||||
fn main() {
|
||||
let instance = wgpu::Instance::new();
|
||||
let adapter = instance.get_adapter(
|
||||
wgpu::AdapterDescriptor {
|
||||
let adapter = instance.get_adapter(wgpu::AdapterDescriptor {
|
||||
power_preference: wgpu::PowerPreference::LowPower,
|
||||
},
|
||||
);
|
||||
let device = adapter.create_device(
|
||||
wgpu::DeviceDescriptor {
|
||||
});
|
||||
let device = adapter.create_device(wgpu::DeviceDescriptor {
|
||||
extensions: wgpu::Extensions {
|
||||
anisotropic_filtering: false,
|
||||
},
|
||||
},
|
||||
);
|
||||
});
|
||||
let vs_bytes = include_bytes!("./../data/hello_triangle.vert.spv");
|
||||
let _vs = device.create_shader_module(vs_bytes);
|
||||
let fs_bytes = include_bytes!("./../data/hello_triangle.frag.spv");
|
||||
let _fs = device.create_shader_module(fs_bytes);
|
||||
|
||||
let cmd_buf = device.create_command_buffer(wgpu::CommandBufferDescriptor {
|
||||
});
|
||||
let cmd_buf = device.create_command_buffer(wgpu::CommandBufferDescriptor {});
|
||||
let queue = device.get_queue();
|
||||
queue.submit(&[cmd_buf]);
|
||||
}
|
||||
|
@ -1,15 +1,14 @@
|
||||
use super::CommandBuffer;
|
||||
|
||||
use hal::{self, Device};
|
||||
use hal::command::RawCommandBuffer;
|
||||
use hal::pool::RawCommandPool;
|
||||
use hal::{self, Device};
|
||||
|
||||
use std::collections::HashMap;
|
||||
//TODO: use `parking_lot::Mutex`?
|
||||
use std::sync::Mutex;
|
||||
use std::thread;
|
||||
|
||||
|
||||
struct CommandPool<B: hal::Backend> {
|
||||
raw: B::CommandPool,
|
||||
available: Vec<CommandBuffer<B>>,
|
||||
@ -39,9 +38,7 @@ impl<B: hal::Backend> CommandAllocator<B> {
|
||||
pub fn allocate(&self, device: &B::Device) -> CommandBuffer<B> {
|
||||
let thread_id = thread::current().id();
|
||||
let mut inner = self.inner.lock().unwrap();
|
||||
let pool = inner.pools
|
||||
.entry(thread_id)
|
||||
.or_insert_with(|| CommandPool {
|
||||
let pool = inner.pools.entry(thread_id).or_insert_with(|| CommandPool {
|
||||
raw: device.create_command_pool(
|
||||
self.queue_family,
|
||||
hal::pool::CommandPoolCreateFlags::RESET_INDIVIDUAL,
|
||||
@ -65,11 +62,7 @@ impl<B: hal::Backend> CommandAllocator<B> {
|
||||
}
|
||||
|
||||
pub fn submit(&self, cmd_buf: CommandBuffer<B>) {
|
||||
self.inner
|
||||
.lock()
|
||||
.unwrap()
|
||||
.pending
|
||||
.push(cmd_buf);
|
||||
self.inner.lock().unwrap().pending.push(cmd_buf);
|
||||
}
|
||||
|
||||
pub fn recycle(&self, mut cmd_buf: CommandBuffer<B>) {
|
||||
@ -86,7 +79,7 @@ impl<B: hal::Backend> CommandAllocator<B> {
|
||||
|
||||
pub fn maintain(&self, device: &B::Device) {
|
||||
let mut inner = self.inner.lock().unwrap();
|
||||
for i in (0 .. inner.pending.len()).rev() {
|
||||
for i in (0..inner.pending.len()).rev() {
|
||||
if device.get_fence_status(&inner.pending[i].fence) {
|
||||
let cmd_buf = inner.pending.swap_remove(i);
|
||||
inner
|
||||
|
@ -15,7 +15,6 @@ use {
|
||||
|
||||
use std::thread::ThreadId;
|
||||
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||
pub enum LoadOp {
|
||||
|
@ -1,15 +1,14 @@
|
||||
use hal::{self, Device as _Device};
|
||||
use hal::queue::RawCommandQueue;
|
||||
use hal::{self, Device as _Device};
|
||||
use {back, binding_model, command, conv, memory, pipeline};
|
||||
|
||||
use std::{ffi, iter, slice};
|
||||
use registry::{self, Items, Registry};
|
||||
use std::{ffi, iter, slice};
|
||||
use {
|
||||
AttachmentStateId, BindGroupLayoutId, BlendStateId, CommandBufferId, DepthStencilStateId, DeviceId,
|
||||
PipelineLayoutId, QueueId, RenderPipelineId, ShaderModuleId,
|
||||
AttachmentStateId, BindGroupLayoutId, BlendStateId, CommandBufferId, DepthStencilStateId,
|
||||
DeviceId, PipelineLayoutId, QueueId, RenderPipelineId, ShaderModuleId,
|
||||
};
|
||||
|
||||
|
||||
pub struct Device<B: hal::Backend> {
|
||||
device: B::Device,
|
||||
queue_group: hal::QueueGroup<B, hal::General>,
|
||||
@ -56,7 +55,9 @@ pub extern "C" fn wgpu_device_create_bind_group_layout(
|
||||
}),
|
||||
&[],
|
||||
);
|
||||
registry::BIND_GROUP_LAYOUT_REGISTRY.lock().register(binding_model::BindGroupLayout {
|
||||
registry::BIND_GROUP_LAYOUT_REGISTRY
|
||||
.lock()
|
||||
.register(binding_model::BindGroupLayout {
|
||||
raw: descriptor_set_layout,
|
||||
})
|
||||
}
|
||||
@ -76,7 +77,9 @@ pub extern "C" fn wgpu_device_create_pipeline_layout(
|
||||
let device = &device_guard.get(device_id).device;
|
||||
let pipeline_layout =
|
||||
device.create_pipeline_layout(descriptor_set_layouts.iter().map(|d| &d.raw), &[]); // TODO: push constants
|
||||
registry::PIPELINE_LAYOUT_REGISTRY.lock().register(binding_model::PipelineLayout {
|
||||
registry::PIPELINE_LAYOUT_REGISTRY
|
||||
.lock()
|
||||
.register(binding_model::PipelineLayout {
|
||||
raw: pipeline_layout,
|
||||
})
|
||||
}
|
||||
@ -86,7 +89,9 @@ pub extern "C" fn wgpu_device_create_blend_state(
|
||||
_device_id: DeviceId,
|
||||
desc: pipeline::BlendStateDescriptor,
|
||||
) -> BlendStateId {
|
||||
registry::BLEND_STATE_REGISTRY.lock().register(pipeline::BlendState {
|
||||
registry::BLEND_STATE_REGISTRY
|
||||
.lock()
|
||||
.register(pipeline::BlendState {
|
||||
raw: conv::map_blend_state_descriptor(desc),
|
||||
})
|
||||
}
|
||||
@ -96,7 +101,9 @@ pub extern "C" fn wgpu_device_create_depth_stencil_state(
|
||||
device_id: DeviceId,
|
||||
desc: pipeline::DepthStencilStateDescriptor,
|
||||
) -> DepthStencilStateId {
|
||||
registry::DEPTH_STENCIL_STATE_REGISTRY.lock().register(pipeline::DepthStencilState {
|
||||
registry::DEPTH_STENCIL_STATE_REGISTRY
|
||||
.lock()
|
||||
.register(pipeline::DepthStencilState {
|
||||
raw: conv::map_depth_stencil_state(desc),
|
||||
})
|
||||
}
|
||||
@ -111,7 +118,9 @@ pub extern "C" fn wgpu_device_create_shader_module(
|
||||
let shader = device
|
||||
.create_shader_module(unsafe { slice::from_raw_parts(desc.code.bytes, desc.code.length) })
|
||||
.unwrap();
|
||||
registry::SHADER_MODULE_REGISTRY.lock().register(ShaderModule { raw: shader })
|
||||
registry::SHADER_MODULE_REGISTRY
|
||||
.lock()
|
||||
.register(ShaderModule { raw: shader })
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@ -126,9 +135,7 @@ pub extern "C" fn wgpu_device_create_command_buffer(
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_device_get_queue(
|
||||
device_id: DeviceId,
|
||||
) -> QueueId {
|
||||
pub extern "C" fn wgpu_device_get_queue(device_id: DeviceId) -> QueueId {
|
||||
device_id
|
||||
}
|
||||
|
||||
@ -140,9 +147,8 @@ pub extern "C" fn wgpu_queue_submit(
|
||||
) {
|
||||
let mut device_guard = registry::DEVICE_REGISTRY.lock();
|
||||
let device = device_guard.get_mut(queue_id);
|
||||
let command_buffer_ids = unsafe {
|
||||
slice::from_raw_parts(command_buffer_ptr, command_buffer_count)
|
||||
};
|
||||
let command_buffer_ids =
|
||||
unsafe { slice::from_raw_parts(command_buffer_ptr, command_buffer_count) };
|
||||
//TODO: submit at once, requires `get_all()`
|
||||
let mut command_buffer_guard = registry::COMMAND_BUFFER_REGISTRY.lock();
|
||||
for &cmb_id in command_buffer_ids {
|
||||
@ -188,7 +194,9 @@ pub extern "C" fn wgpu_device_create_attachment_state(
|
||||
layouts: hal::image::Layout::Undefined..hal::image::Layout::Present, // TODO map
|
||||
}
|
||||
}).collect();
|
||||
registry::ATTACHMENT_STATE_REGISTRY.lock().register(pipeline::AttachmentState { raw: attachments })
|
||||
registry::ATTACHMENT_STATE_REGISTRY
|
||||
.lock()
|
||||
.register(pipeline::AttachmentState { raw: attachments })
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@ -364,5 +372,7 @@ pub extern "C" fn wgpu_device_create_render_pipeline(
|
||||
.create_graphics_pipeline(&pipeline_desc, None)
|
||||
.unwrap();
|
||||
|
||||
registry::RENDER_PIPELINE_REGISTRY.lock().register(pipeline::RenderPipeline { raw: pipeline })
|
||||
registry::RENDER_PIPELINE_REGISTRY
|
||||
.lock()
|
||||
.register(pipeline::RenderPipeline { raw: pipeline })
|
||||
}
|
||||
|
@ -67,7 +67,9 @@ pub extern "C" fn wgpu_instance_get_adapter(
|
||||
PowerPreference::LowPower => low.or(high),
|
||||
PowerPreference::HighPerformance | PowerPreference::Default => high.or(low),
|
||||
};
|
||||
registry::ADAPTER_REGISTRY.lock().register(some.or(other).unwrap())
|
||||
registry::ADAPTER_REGISTRY
|
||||
.lock()
|
||||
.register(some.or(other).unwrap())
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@ -79,5 +81,7 @@ pub extern "C" fn wgpu_adapter_create_device(
|
||||
let adapter = adapter_guard.get_mut(adapter_id);
|
||||
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().register(Device::new(device, queue_group, mem_props))
|
||||
registry::DEVICE_REGISTRY
|
||||
.lock()
|
||||
.register(Device::new(device, queue_group, mem_props))
|
||||
}
|
||||
|
@ -40,7 +40,6 @@ pub use self::resource::*;
|
||||
use back::Backend as B;
|
||||
use registry::Id;
|
||||
|
||||
|
||||
#[repr(C)]
|
||||
pub struct Color {
|
||||
pub r: f32,
|
||||
|
@ -10,9 +10,9 @@ use std::os::raw::c_void;
|
||||
use std::sync::Arc;
|
||||
|
||||
use {
|
||||
AdapterHandle, AttachmentStateHandle, BindGroupLayoutHandle, BlendStateHandle, CommandBufferHandle,
|
||||
DepthStencilStateHandle, DeviceHandle, InstanceHandle, PipelineLayoutHandle,
|
||||
RenderPipelineHandle, ShaderModuleHandle,
|
||||
AdapterHandle, AttachmentStateHandle, BindGroupLayoutHandle, BlendStateHandle,
|
||||
CommandBufferHandle, DepthStencilStateHandle, DeviceHandle, InstanceHandle,
|
||||
PipelineLayoutHandle, RenderPipelineHandle, ShaderModuleHandle,
|
||||
};
|
||||
|
||||
#[cfg(not(feature = "remote"))]
|
||||
@ -60,9 +60,7 @@ impl<T> Items<T> for LocalItems<T> {
|
||||
}
|
||||
|
||||
fn take(&mut self, id: Id) -> T {
|
||||
unsafe {
|
||||
*Box::from_raw(id as *mut T)
|
||||
}
|
||||
unsafe { *Box::from_raw(id as *mut T) }
|
||||
}
|
||||
}
|
||||
|
||||
@ -167,7 +165,8 @@ lazy_static! {
|
||||
pub(crate) static ref DEPTH_STENCIL_STATE_REGISTRY: ConcreteRegistry<DepthStencilStateHandle> =
|
||||
ConcreteRegistry::new();
|
||||
pub(crate) static ref DEVICE_REGISTRY: ConcreteRegistry<DeviceHandle> = ConcreteRegistry::new();
|
||||
pub(crate) static ref COMMAND_BUFFER_REGISTRY: ConcreteRegistry<CommandBufferHandle> = ConcreteRegistry::new();
|
||||
pub(crate) static ref COMMAND_BUFFER_REGISTRY: ConcreteRegistry<CommandBufferHandle> =
|
||||
ConcreteRegistry::new();
|
||||
pub(crate) static ref INSTANCE_REGISTRY: ConcreteRegistry<InstanceHandle> =
|
||||
ConcreteRegistry::new();
|
||||
pub(crate) static ref PIPELINE_LAYOUT_REGISTRY: ConcreteRegistry<PipelineLayoutHandle> =
|
||||
|
@ -1,12 +1,10 @@
|
||||
extern crate wgpu_native as wgn;
|
||||
|
||||
pub use wgn::{
|
||||
Color, Origin3d, Extent3d,
|
||||
AdapterDescriptor, Extensions, DeviceDescriptor, PowerPreference,
|
||||
ShaderModuleDescriptor, CommandBufferDescriptor,
|
||||
AdapterDescriptor, Color, CommandBufferDescriptor, DeviceDescriptor, Extensions, Extent3d,
|
||||
Origin3d, PowerPreference, ShaderModuleDescriptor,
|
||||
};
|
||||
|
||||
|
||||
pub struct Instance {
|
||||
id: wgn::InstanceId,
|
||||
}
|
||||
@ -31,7 +29,6 @@ pub struct Queue {
|
||||
id: wgn::QueueId,
|
||||
}
|
||||
|
||||
|
||||
impl Instance {
|
||||
pub fn new() -> Self {
|
||||
Instance {
|
||||
@ -56,7 +53,7 @@ impl Adapter {
|
||||
|
||||
impl Device {
|
||||
pub fn create_shader_module(&self, spv: &[u8]) -> ShaderModule {
|
||||
let desc = wgn::ShaderModuleDescriptor{
|
||||
let desc = wgn::ShaderModuleDescriptor {
|
||||
code: wgn::ByteArray {
|
||||
bytes: spv.as_ptr(),
|
||||
length: spv.len(),
|
||||
|
Loading…
Reference in New Issue
Block a user