mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
Set up module hierarchy
This commit is contained in:
parent
f246d33bfe
commit
e887fc5b93
@ -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
5
src/command/compute.rs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
use hal;
|
||||||
|
|
||||||
|
pub struct ComputePass<B: hal::Backend> {
|
||||||
|
raw: B::CommandBuffer,
|
||||||
|
}
|
||||||
27
src/command/mod.rs
Normal file
27
src/command/mod.rs
Normal 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
27
src/command/render.rs
Normal 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!()
|
||||||
|
}
|
||||||
@ -1,4 +1,6 @@
|
|||||||
use hal;
|
use hal::{self, Device as _Device};
|
||||||
|
|
||||||
|
use {BufferHandle, CommandBufferHandle, DeviceHandle};
|
||||||
|
|
||||||
|
|
||||||
pub type BufferUsage = hal::buffer::Usage;
|
pub type BufferUsage = hal::buffer::Usage;
|
||||||
@ -14,9 +16,25 @@ pub struct CommandBufferDescriptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct Device<B: hal::Backend> {
|
pub struct Device<B: hal::Backend> {
|
||||||
pub raw: B::Device,
|
pub gpu: hal::Gpu<B>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Buffer<B: hal::Backend> {
|
pub struct Buffer<B: hal::Backend> {
|
||||||
pub raw: B::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!()
|
||||||
|
}
|
||||||
|
|||||||
@ -1,4 +1,8 @@
|
|||||||
//use hal;
|
use back;
|
||||||
|
use hal::{self, Instance as _Instance, PhysicalDevice as _PhysicalDevice};
|
||||||
|
|
||||||
|
use {AdapterHandle, Device, DeviceHandle, InstanceHandle};
|
||||||
|
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub enum PowerPreference {
|
pub enum PowerPreference {
|
||||||
@ -14,10 +18,48 @@ pub struct AdapterDescriptor {
|
|||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct Extensions {
|
pub struct Extensions {
|
||||||
anisotropic_filtering: bool,
|
pub anisotropic_filtering: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct DeviceDescriptor {
|
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,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
92
src/lib.rs
92
src/lib.rs
@ -11,91 +11,17 @@ mod device;
|
|||||||
mod handle;
|
mod handle;
|
||||||
mod instance;
|
mod instance;
|
||||||
|
|
||||||
|
pub use self::command::*;
|
||||||
|
pub use self::device::*;
|
||||||
|
pub use self::instance::*;
|
||||||
|
|
||||||
use back::Backend as B;
|
use back::Backend as B;
|
||||||
use hal::Device;
|
|
||||||
|
|
||||||
use handle::Handle;
|
use handle::Handle;
|
||||||
|
|
||||||
|
|
||||||
pub type InstanceHandle = Handle<back::Instance>;
|
pub type InstanceHandle = Handle<back::Instance>;
|
||||||
pub type AdapterHandle = Handle<hal::Adapter<B>>;
|
pub type AdapterHandle = Handle<hal::Adapter<B>>;
|
||||||
pub type DeviceHandle = Handle<device::Device<B>>;
|
pub type DeviceHandle = Handle<Device<B>>;
|
||||||
pub type BufferHandle = Handle<device::Buffer<B>>;
|
pub type BufferHandle = Handle<Buffer<B>>;
|
||||||
pub type CommandBufferHandle = Handle<command::CommandBuffer<B>>;
|
pub type CommandBufferHandle = Handle<CommandBuffer<B>>;
|
||||||
pub type RenderPassHandle = Handle<command::RenderPass<B>>;
|
pub type RenderPassHandle = Handle<RenderPass<B>>;
|
||||||
pub type ComputePassHandle = Handle<command::ComputePass<B>>;
|
pub type ComputePassHandle = Handle<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!()
|
|
||||||
}
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user