Set up module hierarchy

This commit is contained in:
Dzmitry Malyshau 2018-09-14 08:06:48 -04:00
parent f246d33bfe
commit e887fc5b93
7 changed files with 133 additions and 101 deletions

View File

@ -1,13 +0,0 @@
use hal;
pub struct CommandBuffer<B: hal::Backend> {
raw: B::CommandBuffer,
}
pub struct RenderPass<B: hal::Backend> {
raw: B::CommandBuffer,
}
pub struct ComputePass<B: hal::Backend> {
raw: B::CommandBuffer,
}

5
src/command/compute.rs Normal file
View File

@ -0,0 +1,5 @@
use hal;
pub struct ComputePass<B: hal::Backend> {
raw: B::CommandBuffer,
}

27
src/command/mod.rs Normal file
View File

@ -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<B: hal::Backend> {
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!()
}

27
src/command/render.rs Normal file
View File

@ -0,0 +1,27 @@
use hal;
use {CommandBufferHandle, RenderPassHandle};
pub struct RenderPass<B: hal::Backend> {
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!()
}

View File

@ -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<B: hal::Backend> {
pub raw: B::Device,
pub gpu: hal::Gpu<B>,
}
pub struct Buffer<B: hal::Backend> {
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!()
}

View File

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

View File

@ -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<back::Instance>;
pub type AdapterHandle = Handle<hal::Adapter<B>>;
pub type DeviceHandle = Handle<device::Device<B>>;
pub type BufferHandle = Handle<device::Buffer<B>>;
pub type CommandBufferHandle = Handle<command::CommandBuffer<B>>;
pub type RenderPassHandle = Handle<command::RenderPass<B>>;
pub type ComputePassHandle = Handle<command::ComputePass<B>>;
// 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<Device<B>>;
pub type BufferHandle = Handle<Buffer<B>>;
pub type CommandBufferHandle = Handle<CommandBuffer<B>>;
pub type RenderPassHandle = Handle<RenderPass<B>>;
pub type ComputePassHandle = Handle<ComputePass<B>>;