diff --git a/src/command.rs b/src/command.rs deleted file mode 100644 index e88c9e1cfa..0000000000 --- a/src/command.rs +++ /dev/null @@ -1,13 +0,0 @@ -use hal; - -pub struct CommandBuffer { - raw: B::CommandBuffer, -} - -pub struct RenderPass { - raw: B::CommandBuffer, -} - -pub struct ComputePass { - raw: B::CommandBuffer, -} diff --git a/src/command/compute.rs b/src/command/compute.rs new file mode 100644 index 0000000000..044880348a --- /dev/null +++ b/src/command/compute.rs @@ -0,0 +1,5 @@ +use hal; + +pub struct ComputePass { + raw: B::CommandBuffer, +} diff --git a/src/command/mod.rs b/src/command/mod.rs new file mode 100644 index 0000000000..762a4a2e78 --- /dev/null +++ b/src/command/mod.rs @@ -0,0 +1,27 @@ +mod compute; +mod render; + +pub use self::compute::*; +pub use self::render::*; + +use hal; + +use {CommandBufferHandle, ComputePassHandle, RenderPassHandle}; + + +pub struct CommandBuffer { + raw: B::CommandBuffer, +} + +pub extern "C" +fn command_buffer_begin_render_pass( + command_buffer: CommandBufferHandle +) -> RenderPassHandle { + unimplemented!() +} + +pub extern "C" +fn command_buffer_begin_compute_pass( +) -> ComputePassHandle { + unimplemented!() +} diff --git a/src/command/render.rs b/src/command/render.rs new file mode 100644 index 0000000000..701386a16c --- /dev/null +++ b/src/command/render.rs @@ -0,0 +1,27 @@ +use hal; + +use {CommandBufferHandle, RenderPassHandle}; + + +pub struct RenderPass { + raw: B::CommandBuffer, +} + +pub extern "C" +fn render_pass_draw( + pass: RenderPassHandle, vertex_count: u32, instance_count: u32, first_vertex: u32, first_instance: u32 +) { + unimplemented!() +} + +pub extern "C" +fn render_pass_draw_indexed( + pass: RenderPassHandle, index_count: u32, instance_count: u32, first_index: u32, vertex_offset: i32, first_instance: u32 +) { + unimplemented!() +} + +pub extern "C" +fn render_pass_end(pass: RenderPassHandle) -> CommandBufferHandle { + unimplemented!() +} diff --git a/src/device.rs b/src/device.rs index a27dbf46b3..90775deb2c 100644 --- a/src/device.rs +++ b/src/device.rs @@ -1,4 +1,6 @@ -use hal; +use hal::{self, Device as _Device}; + +use {BufferHandle, CommandBufferHandle, DeviceHandle}; pub type BufferUsage = hal::buffer::Usage; @@ -14,9 +16,25 @@ pub struct CommandBufferDescriptor { } pub struct Device { - pub raw: B::Device, + pub gpu: hal::Gpu, } pub struct Buffer { pub raw: B::Buffer, } + +pub extern "C" +fn device_create_buffer( + device: DeviceHandle, desc: BufferDescriptor +) -> BufferHandle { + //let unbound = device.raw.create_buffer(desc.size, desc.usage).unwrap(); + //let reqs = device.raw.get_buffer_requirements(&unbound); + unimplemented!() +} + +pub extern "C" +fn device_create_command_buffer( + device: DeviceHandle, desc: CommandBufferDescriptor +) -> CommandBufferHandle { + unimplemented!() +} diff --git a/src/instance.rs b/src/instance.rs index 055c0cd865..388d9f160c 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -1,4 +1,8 @@ -//use hal; +use back; +use hal::{self, Instance as _Instance, PhysicalDevice as _PhysicalDevice}; + +use {AdapterHandle, Device, DeviceHandle, InstanceHandle}; + #[repr(C)] pub enum PowerPreference { @@ -14,10 +18,48 @@ pub struct AdapterDescriptor { #[repr(C)] pub struct Extensions { - anisotropic_filtering: bool, + pub anisotropic_filtering: bool, } #[repr(C)] pub struct DeviceDescriptor { - pub extension: Extensions, + pub extensions: Extensions, +} + +pub extern "C" +fn create_instance() -> InstanceHandle { + let inst = back::Instance::create("wgpu", 1); + InstanceHandle::new(inst) +} + +pub extern "C" +fn instance_get_adapter( + instance: InstanceHandle, desc: AdapterDescriptor +) -> AdapterHandle { + let (mut low, mut high, mut other) = (None, None, None); + for adapter in instance.enumerate_adapters() { + match adapter.info.device_type { + hal::adapter::DeviceType::IntegratedGpu => low = Some(adapter), + hal::adapter::DeviceType::DiscreteGpu => high = Some(adapter), + _ => other = Some(adapter), + } + } + + let some = match desc.power_preference { + PowerPreference::LowPower => low.or(high), + PowerPreference::HighPerformance | + PowerPreference::Default => high.or(low), + }; + AdapterHandle::new(some.or(other).unwrap()) +} + +pub extern "C" +fn adapter_create_device( + adapter: AdapterHandle, desc: DeviceDescriptor +) -> DeviceHandle { + let queue_family = &adapter.queue_families[0]; + let gpu = adapter.physical_device.open(&[(queue_family, &[1f32])]).unwrap(); + DeviceHandle::new(Device { + gpu, + }) } diff --git a/src/lib.rs b/src/lib.rs index ad15c58203..aed275dd49 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,91 +11,17 @@ mod device; mod handle; mod instance; +pub use self::command::*; +pub use self::device::*; +pub use self::instance::*; + use back::Backend as B; -use hal::Device; - use handle::Handle; - pub type InstanceHandle = Handle; pub type AdapterHandle = Handle>; -pub type DeviceHandle = Handle>; -pub type BufferHandle = Handle>; -pub type CommandBufferHandle = Handle>; -pub type RenderPassHandle = Handle>; -pub type ComputePassHandle = Handle>; - -// Instance logic - -pub extern "C" -fn create_instance() -> InstanceHandle { - unimplemented!() -} - -pub extern "C" -fn instance_get_adapter( - instance: InstanceHandle, desc: instance::AdapterDescriptor -) -> AdapterHandle { - unimplemented!() -} - -pub extern "C" -fn adapter_create_device( - adapter: AdapterHandle, desc: instance::DeviceDescriptor -) -> DeviceHandle { - unimplemented!() -} - -// Device logic - -pub extern "C" -fn device_create_buffer( - device: DeviceHandle, desc: device::BufferDescriptor -) -> BufferHandle { - //let unbound = device.raw.create_buffer(desc.size, desc.usage).unwrap(); - //let reqs = device.raw.get_buffer_requirements(&unbound); - unimplemented!() -} - -pub extern "C" -fn device_create_command_buffer( - device: DeviceHandle, desc: device::CommandBufferDescriptor -) -> CommandBufferHandle { - unimplemented!() -} - -// Command Buffer logic - -pub extern "C" -fn command_buffer_begin_render_pass( - command_buffer: CommandBufferHandle -) -> RenderPassHandle { - unimplemented!() -} - -pub extern "C" -fn command_buffer_begin_compute_pass( -) -> ComputePassHandle { - unimplemented!() -} - -// Render Pass logic - -pub extern "C" -fn render_pass_draw( - pass: RenderPassHandle, vertex_count: u32, instance_count: u32, first_vertex: u32, first_instance: u32 -) { - unimplemented!() -} - -pub extern "C" -fn render_pass_draw_indexed( - pass: RenderPassHandle, index_count: u32, instance_count: u32, first_index: u32, vertex_offset: i32, first_instance: u32 -) { - unimplemented!() -} - -pub extern "C" -fn render_pass_end(pass: RenderPassHandle) -> CommandBufferHandle { - unimplemented!() -} +pub type DeviceHandle = Handle>; +pub type BufferHandle = Handle>; +pub type CommandBufferHandle = Handle>; +pub type RenderPassHandle = Handle>; +pub type ComputePassHandle = Handle>;