mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
Format all files
This commit is contained in:
parent
5759f769b0
commit
105a71d19a
@ -2,18 +2,30 @@ extern crate wgpu_native as wgn;
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let instance = wgn::create_instance();
|
let instance = wgn::create_instance();
|
||||||
let adapter = wgn::instance_get_adapter(instance, wgn::AdapterDescriptor {
|
let adapter = wgn::instance_get_adapter(
|
||||||
|
instance,
|
||||||
|
wgn::AdapterDescriptor {
|
||||||
power_preference: wgn::PowerPreference::LowPower,
|
power_preference: wgn::PowerPreference::LowPower,
|
||||||
});
|
},
|
||||||
let device = wgn::adapter_create_device(adapter, wgn::DeviceDescriptor {
|
);
|
||||||
|
let device = wgn::adapter_create_device(
|
||||||
|
adapter,
|
||||||
|
wgn::DeviceDescriptor {
|
||||||
extensions: wgn::Extensions {
|
extensions: wgn::Extensions {
|
||||||
anisotropic_filtering: false,
|
anisotropic_filtering: false,
|
||||||
},
|
},
|
||||||
});
|
},
|
||||||
let _vs = wgn::device_create_shader_module(device, wgn::ShaderModuleDescriptor {
|
);
|
||||||
|
let _vs = wgn::device_create_shader_module(
|
||||||
|
device,
|
||||||
|
wgn::ShaderModuleDescriptor {
|
||||||
code: include_bytes!("./shaders/hello_triangle.vert.spv"),
|
code: include_bytes!("./shaders/hello_triangle.vert.spv"),
|
||||||
});
|
},
|
||||||
let _fs = wgn::device_create_shader_module(device, wgn::ShaderModuleDescriptor {
|
);
|
||||||
|
let _fs = wgn::device_create_shader_module(
|
||||||
|
device,
|
||||||
|
wgn::ShaderModuleDescriptor {
|
||||||
code: include_bytes!("./shaders/hello_triangle.frag.spv"),
|
code: include_bytes!("./shaders/hello_triangle.frag.spv"),
|
||||||
});
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,6 @@ use hal;
|
|||||||
|
|
||||||
use {CommandBuffer, CommandBufferId, ComputePassId};
|
use {CommandBuffer, CommandBufferId, ComputePassId};
|
||||||
|
|
||||||
|
|
||||||
pub struct ComputePass<B: hal::Backend> {
|
pub struct ComputePass<B: hal::Backend> {
|
||||||
raw: B::CommandBuffer,
|
raw: B::CommandBuffer,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,9 +6,10 @@ pub use self::render::*;
|
|||||||
|
|
||||||
use hal;
|
use hal;
|
||||||
|
|
||||||
use {BufferId, Color, CommandBufferId, ComputePassId, Origin3d,
|
use {
|
||||||
RenderPassId, TextureViewId, TextureId};
|
BufferId, Color, CommandBufferId, ComputePassId, Origin3d, RenderPassId, TextureId,
|
||||||
|
TextureViewId,
|
||||||
|
};
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub enum LoadOp {
|
pub enum LoadOp {
|
||||||
@ -72,13 +73,12 @@ pub struct CommandBufferDescriptor;
|
|||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn command_buffer_begin_render_pass(
|
pub extern "C" fn command_buffer_begin_render_pass(
|
||||||
command_buffer: CommandBufferId
|
command_buffer: CommandBufferId,
|
||||||
) -> RenderPassId {
|
) -> RenderPassId {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn command_buffer_begin_compute_pass(
|
pub extern "C" fn command_buffer_begin_compute_pass() -> ComputePassId {
|
||||||
) -> ComputePassId {
|
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,6 @@ use hal;
|
|||||||
|
|
||||||
use {CommandBuffer, CommandBufferId, RenderPassId};
|
use {CommandBuffer, CommandBufferId, RenderPassId};
|
||||||
|
|
||||||
|
|
||||||
pub struct RenderPass<B: hal::Backend> {
|
pub struct RenderPass<B: hal::Backend> {
|
||||||
raw: B::CommandBuffer,
|
raw: B::CommandBuffer,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,11 +2,12 @@ use hal;
|
|||||||
|
|
||||||
use resource;
|
use resource;
|
||||||
|
|
||||||
|
pub(crate) fn map_buffer_usage(
|
||||||
pub(crate) fn map_buffer_usage(usage: resource::BufferUsageFlags) -> (hal::buffer::Usage, hal::memory::Properties) {
|
usage: resource::BufferUsageFlags,
|
||||||
use resource::BufferUsageFlags as W;
|
) -> (hal::buffer::Usage, hal::memory::Properties) {
|
||||||
use hal::buffer::Usage as U;
|
use hal::buffer::Usage as U;
|
||||||
use hal::memory::Properties as P;
|
use hal::memory::Properties as P;
|
||||||
|
use resource::BufferUsageFlags as W;
|
||||||
|
|
||||||
let mut hal_memory = P::empty();
|
let mut hal_memory = P::empty();
|
||||||
if usage.contains(W::MAP_READ) {
|
if usage.contains(W::MAP_READ) {
|
||||||
|
|||||||
@ -4,10 +4,8 @@ use {conv, memory, pipeline, resource};
|
|||||||
use registry;
|
use registry;
|
||||||
use {BufferId, CommandBufferId, DeviceId, ShaderModuleId};
|
use {BufferId, CommandBufferId, DeviceId, ShaderModuleId};
|
||||||
|
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct CommandBufferDescriptor {
|
pub struct CommandBufferDescriptor {}
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Device<B: hal::Backend> {
|
pub struct Device<B: hal::Backend> {
|
||||||
device: B::Device,
|
device: B::Device,
|
||||||
@ -35,12 +33,14 @@ pub struct ShaderModule<B: hal::Backend> {
|
|||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn device_create_shader_module(
|
pub extern "C" fn device_create_shader_module(
|
||||||
device_id: DeviceId, desc: pipeline::ShaderModuleDescriptor
|
device_id: DeviceId,
|
||||||
|
desc: pipeline::ShaderModuleDescriptor,
|
||||||
) -> ShaderModuleId {
|
) -> ShaderModuleId {
|
||||||
let device_registry = registry::DEVICE_REGISTRY.lock().unwrap();
|
let device_registry = registry::DEVICE_REGISTRY.lock().unwrap();
|
||||||
let device = device_registry.get(device_id).unwrap();
|
let device = device_registry.get(device_id).unwrap();
|
||||||
let shader = device.device.create_shader_module(desc.code).unwrap();
|
let shader = device.device.create_shader_module(desc.code).unwrap();
|
||||||
registry::SHADER_MODULE_REGISTRY.lock().unwrap().register(ShaderModule {
|
registry::SHADER_MODULE_REGISTRY
|
||||||
raw: shader,
|
.lock()
|
||||||
})
|
.unwrap()
|
||||||
|
.register(ShaderModule { raw: shader })
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,6 @@ use hal::{self, Instance as _Instance, PhysicalDevice as _PhysicalDevice};
|
|||||||
use registry;
|
use registry;
|
||||||
use {AdapterId, Device, DeviceId, InstanceId};
|
use {AdapterId, Device, DeviceId, InstanceId};
|
||||||
|
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub enum PowerPreference {
|
pub enum PowerPreference {
|
||||||
Default = 0,
|
Default = 0,
|
||||||
@ -28,22 +27,30 @@ pub struct DeviceDescriptor {
|
|||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn create_instance() -> InstanceId {
|
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 mut registry = registry::INSTANCE_REGISTRY.lock().unwrap();
|
||||||
let inst = ::back::Instance::create("wgpu", 1);
|
let inst = ::back::Instance::create("wgpu", 1);
|
||||||
registry.register(inst)
|
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!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn instance_get_adapter(
|
pub extern "C" fn instance_get_adapter(
|
||||||
instance_id: InstanceId, desc: AdapterDescriptor
|
instance_id: InstanceId,
|
||||||
|
desc: AdapterDescriptor,
|
||||||
) -> AdapterId {
|
) -> AdapterId {
|
||||||
let instance_registry = registry::INSTANCE_REGISTRY.lock().unwrap();
|
let instance_registry = registry::INSTANCE_REGISTRY.lock().unwrap();
|
||||||
let instance = instance_registry.get(instance_id).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 {
|
let some = match desc.power_preference {
|
||||||
PowerPreference::LowPower => low.or(high),
|
PowerPreference::LowPower => low.or(high),
|
||||||
PowerPreference::HighPerformance |
|
PowerPreference::HighPerformance | PowerPreference::Default => high.or(low),
|
||||||
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]
|
#[no_mangle]
|
||||||
pub extern "C" fn adapter_create_device(
|
pub extern "C" fn adapter_create_device(adapter_id: AdapterId, desc: DeviceDescriptor) -> DeviceId {
|
||||||
adapter_id: AdapterId, desc: DeviceDescriptor
|
|
||||||
) -> DeviceId {
|
|
||||||
let mut adapter_registry = registry::ADAPTER_REGISTRY.lock().unwrap();
|
let mut adapter_registry = registry::ADAPTER_REGISTRY.lock().unwrap();
|
||||||
let adapter = adapter_registry.get_mut(adapter_id).unwrap();
|
let adapter = adapter_registry.get_mut(adapter_id).unwrap();
|
||||||
let (device, queue_group) = adapter.open_with::<_, hal::General>(1, |_qf| true).unwrap();
|
let (device, queue_group) = adapter.open_with::<_, hal::General>(1, |_qf| true).unwrap();
|
||||||
let mem_props = adapter.physical_device.memory_properties();
|
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))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,14 +1,20 @@
|
|||||||
#[macro_use] extern crate bitflags;
|
#[macro_use]
|
||||||
#[macro_use] extern crate lazy_static;
|
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")]
|
#[cfg(feature = "gfx-backend-dx12")]
|
||||||
extern crate gfx_backend_dx12 as back;
|
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")]
|
#[cfg(feature = "gfx-backend-metal")]
|
||||||
extern crate gfx_backend_metal as back;
|
extern crate gfx_backend_metal as back;
|
||||||
#[cfg(not(any(feature = "gfx-backend-vulkan", feature = "gfx-backend-dx12", feature = "gfx-backend-metal")))]
|
#[cfg(feature = "gfx-backend-vulkan")]
|
||||||
extern crate gfx_backend_empty as back;
|
extern crate gfx_backend_vulkan as back;
|
||||||
|
|
||||||
extern crate gfx_hal as hal;
|
extern crate gfx_hal as hal;
|
||||||
extern crate gfx_memory as memory;
|
extern crate gfx_memory as memory;
|
||||||
|
|||||||
@ -3,7 +3,6 @@ use resource;
|
|||||||
|
|
||||||
use {BlendStateId, DepthStencilStateId, PipelineLayoutId};
|
use {BlendStateId, DepthStencilStateId, PipelineLayoutId};
|
||||||
|
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub enum BlendFactor {
|
pub enum BlendFactor {
|
||||||
Zero = 0,
|
Zero = 0,
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
use std::{borrow, cmp, fmt, ops, ptr};
|
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
use std::{borrow, cmp, fmt, ops, ptr};
|
||||||
|
|
||||||
use hal::backend::FastHashMap;
|
use hal::backend::FastHashMap;
|
||||||
use {AdapterHandle, DeviceHandle, InstanceHandle, ShaderModuleHandle};
|
use {AdapterHandle, DeviceHandle, InstanceHandle, ShaderModuleHandle};
|
||||||
@ -36,8 +36,12 @@ impl<T> Registry<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub(crate) static ref ADAPTER_REGISTRY: Arc<Mutex<Registry<AdapterHandle>>> = Arc::new(Mutex::new(Registry::new()));
|
pub(crate) static ref ADAPTER_REGISTRY: Arc<Mutex<Registry<AdapterHandle>>> =
|
||||||
pub(crate) static ref DEVICE_REGISTRY: Arc<Mutex<Registry<DeviceHandle>>> = Arc::new(Mutex::new(Registry::new()));
|
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 DEVICE_REGISTRY: Arc<Mutex<Registry<DeviceHandle>>> =
|
||||||
pub(crate) static ref SHADER_MODULE_REGISTRY: Arc<Mutex<Registry<ShaderModuleHandle>>> = Arc::new(Mutex::new(Registry::new()));
|
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()));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
use hal;
|
use hal;
|
||||||
|
|
||||||
use {Extent3d};
|
use Extent3d;
|
||||||
|
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user