mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-21 22:33:49 +00:00
Merge pull request #5 from grovesNL/resource
Add resource and binding model types
This commit is contained in:
commit
de806ee108
@ -1,6 +1,76 @@
|
||||
use hal;
|
||||
|
||||
use {BindGroupLayoutHandle, BufferHandle, SamplerHandle, TextureViewHandle};
|
||||
|
||||
bitflags! {
|
||||
#[repr(transparent)]
|
||||
pub struct ShaderStageFlags: u32 {
|
||||
const NONE = 0;
|
||||
const VERTEX = 1;
|
||||
const FRAGMENT = 2;
|
||||
const COMPUTE = 4;
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub enum BindingType {
|
||||
UniformBuffer = 0,
|
||||
Sampler = 1,
|
||||
SampledTexture = 2,
|
||||
StorageBuffer = 3,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct BindGroupLayoutBinding {
|
||||
pub binding: u32,
|
||||
pub visibility: ShaderStageFlags,
|
||||
pub ty: BindingType,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct BindGroupLayoutDescriptor<'a> {
|
||||
pub bindings: &'a [BindGroupLayoutBinding],
|
||||
}
|
||||
|
||||
pub struct BindGroupLayout {
|
||||
// TODO
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct PipelineLayoutDescriptor<'a> {
|
||||
pub bind_group_layouts: &'a [BindGroupLayoutHandle],
|
||||
}
|
||||
|
||||
pub struct PipelineLayout<B: hal::Backend> {
|
||||
raw: B::PipelineLayout,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct BufferBinding {
|
||||
pub buffer: BufferHandle,
|
||||
pub offset: u32,
|
||||
pub size: u32,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub enum BindingResource {
|
||||
Buffer(BufferBinding),
|
||||
Sampler(SamplerHandle),
|
||||
TextureView(TextureViewHandle),
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct Binding {
|
||||
pub binding: u32,
|
||||
pub resource: BindingResource,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct BindGroupDescriptor<'a> {
|
||||
pub layout: BindGroupLayout,
|
||||
pub bindings: &'a [Binding],
|
||||
}
|
||||
|
||||
pub struct BindGroup {
|
||||
// TODO
|
||||
}
|
||||
|
@ -6,13 +6,70 @@ pub use self::render::*;
|
||||
|
||||
use hal;
|
||||
|
||||
use {CommandBufferHandle, ComputePassHandle, RenderPassHandle};
|
||||
use {BufferHandle, Color, CommandBufferHandle, ComputePassHandle, Origin3d,
|
||||
RenderPassHandle, TextureViewHandle, TextureHandle};
|
||||
|
||||
|
||||
#[repr(C)]
|
||||
pub enum LoadOp {
|
||||
Clear = 0,
|
||||
Load = 1,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub enum StoreOp {
|
||||
Store = 0,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct RenderPassColorAttachmentDescriptor {
|
||||
pub attachment: TextureViewHandle,
|
||||
pub load_op: LoadOp,
|
||||
pub store_op: StoreOp,
|
||||
pub clear_color: Color,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct RenderPassDepthStencilAttachmentDescriptor {
|
||||
pub attachment: TextureViewHandle,
|
||||
pub depth_load_op: LoadOp,
|
||||
pub depth_store_op: StoreOp,
|
||||
pub clear_depth: f32,
|
||||
pub stencil_load_op: LoadOp,
|
||||
pub stencil_store_op: StoreOp,
|
||||
pub clear_stencil: u32,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct RenderPassDescriptor<'a> {
|
||||
pub color_attachments: &'a [RenderPassColorAttachmentDescriptor],
|
||||
pub depth_stencil_attachment: RenderPassDepthStencilAttachmentDescriptor,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct BufferCopyView {
|
||||
pub buffer: BufferHandle,
|
||||
pub offset: u32,
|
||||
pub row_pitch: u32,
|
||||
pub image_height: u32,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct TextureCopyView {
|
||||
pub texture: TextureHandle,
|
||||
pub level: u32,
|
||||
pub slice: u32,
|
||||
pub origin: Origin3d,
|
||||
//TODO: pub aspect: TextureAspect,
|
||||
}
|
||||
|
||||
pub struct CommandBuffer<B: hal::Backend> {
|
||||
raw: B::CommandBuffer,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct CommandBufferDescriptor;
|
||||
|
||||
pub extern "C"
|
||||
fn command_buffer_begin_render_pass(
|
||||
command_buffer: CommandBufferHandle
|
||||
|
40
src/conv.rs
Normal file
40
src/conv.rs
Normal file
@ -0,0 +1,40 @@
|
||||
use hal;
|
||||
|
||||
use resource;
|
||||
|
||||
|
||||
pub(crate) fn map_buffer_usage(usage: resource::BufferUsageFlags) -> (hal::buffer::Usage, hal::memory::Properties) {
|
||||
use resource::BufferUsageFlags as W;
|
||||
use hal::buffer::Usage as U;
|
||||
use hal::memory::Properties as P;
|
||||
|
||||
let mut hal_memory = P::empty();
|
||||
if usage.contains(W::MAP_READ) {
|
||||
hal_memory |= P::CPU_VISIBLE | P::CPU_CACHED;
|
||||
}
|
||||
if usage.contains(W::MAP_WRITE) {
|
||||
hal_memory |= P::CPU_VISIBLE;
|
||||
}
|
||||
|
||||
let mut hal_usage = U::empty();
|
||||
if usage.contains(W::TRANSFER_SRC) {
|
||||
hal_usage |= U::TRANSFER_SRC;
|
||||
}
|
||||
if usage.contains(W::TRANSFER_DST) {
|
||||
hal_usage |= U::TRANSFER_DST;
|
||||
}
|
||||
if usage.contains(W::INDEX) {
|
||||
hal_usage |= U::INDEX;
|
||||
}
|
||||
if usage.contains(W::VERTEX) {
|
||||
hal_usage |= U::VERTEX;
|
||||
}
|
||||
if usage.contains(W::UNIFORM) {
|
||||
hal_usage |= U::UNIFORM;
|
||||
}
|
||||
if usage.contains(W::STORAGE) {
|
||||
hal_usage |= U::STORAGE;
|
||||
}
|
||||
|
||||
(hal_usage, hal_memory)
|
||||
}
|
@ -1,17 +1,9 @@
|
||||
use hal::{self, Device as _Device, QueueGroup};
|
||||
use {memory, pipeline};
|
||||
use {conv, memory, pipeline, resource};
|
||||
|
||||
use {BufferHandle, CommandBufferHandle, DeviceHandle, ShaderModuleHandle};
|
||||
|
||||
|
||||
pub type BufferUsage = hal::buffer::Usage;
|
||||
|
||||
#[repr(C)]
|
||||
pub struct BufferDescriptor {
|
||||
pub size: u64,
|
||||
pub usage: BufferUsage,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct CommandBufferDescriptor {
|
||||
}
|
||||
@ -36,17 +28,15 @@ impl<B: hal::Backend> Device<B> {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Buffer<B: hal::Backend> {
|
||||
pub raw: B::UnboundBuffer,
|
||||
}
|
||||
|
||||
pub extern "C"
|
||||
fn device_create_buffer(
|
||||
device: DeviceHandle, desc: BufferDescriptor
|
||||
device: DeviceHandle, desc: resource::BufferDescriptor
|
||||
) -> BufferHandle {
|
||||
let buffer = device.device.create_buffer(desc.size, desc.usage).unwrap();
|
||||
BufferHandle::new(Buffer {
|
||||
let (usage, memory_properties) = conv::map_buffer_usage(desc.usage);
|
||||
let buffer = device.device.create_buffer(desc.size as u64, usage).unwrap();
|
||||
BufferHandle::new(resource::Buffer {
|
||||
raw: buffer,
|
||||
memory_properties,
|
||||
})
|
||||
}
|
||||
|
||||
|
29
src/lib.rs
29
src/lib.rs
@ -13,6 +13,7 @@ extern crate gfx_hal as hal;
|
||||
extern crate gfx_memory as memory;
|
||||
|
||||
mod binding_model;
|
||||
mod conv;
|
||||
mod command;
|
||||
mod device;
|
||||
mod handle;
|
||||
@ -30,12 +31,40 @@ pub use self::resource::*;
|
||||
use back::Backend as B;
|
||||
use handle::Handle;
|
||||
|
||||
#[repr(C)]
|
||||
pub struct Color {
|
||||
pub r: f32,
|
||||
pub g: f32,
|
||||
pub b: f32,
|
||||
pub a: f32,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct Origin3d {
|
||||
pub x: f32,
|
||||
pub y: f32,
|
||||
pub z: f32,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct Extent3d {
|
||||
pub width: f32,
|
||||
pub height: f32,
|
||||
pub depth: f32,
|
||||
}
|
||||
|
||||
pub type InstanceHandle = Handle<back::Instance>;
|
||||
pub type AdapterHandle = Handle<hal::Adapter<B>>;
|
||||
pub type DeviceHandle = Handle<Device<B>>;
|
||||
pub type BufferHandle = Handle<Buffer<B>>;
|
||||
|
||||
// Resource
|
||||
pub type TextureViewHandle = Handle<TextureView>;
|
||||
pub type TextureHandle = Handle<Texture>;
|
||||
pub type SamplerHandle = Handle<Sampler>;
|
||||
|
||||
// Binding model
|
||||
pub type BindGroupLayoutHandle = Handle<BindGroupLayout>;
|
||||
pub type PipelineLayoutHandle = Handle<PipelineLayout<B>>;
|
||||
|
||||
// Pipeline
|
||||
|
@ -33,12 +33,12 @@ pub enum BlendOperation {
|
||||
bitflags! {
|
||||
#[repr(transparent)]
|
||||
pub struct ColorWriteFlags: u32 {
|
||||
const NONE = 0x0;
|
||||
const RED = 0x1;
|
||||
const GREEN = 0x2;
|
||||
const BLUE = 0x4;
|
||||
const ALPHA = 0x8;
|
||||
const ALL = 0x15;
|
||||
const NONE = 0;
|
||||
const RED = 1;
|
||||
const GREEN = 2;
|
||||
const BLUE = 4;
|
||||
const ALPHA = 8;
|
||||
const ALL = 15;
|
||||
}
|
||||
}
|
||||
|
||||
|
109
src/resource.rs
109
src/resource.rs
@ -1,3 +1,46 @@
|
||||
use hal;
|
||||
|
||||
use {Extent3d};
|
||||
|
||||
|
||||
bitflags! {
|
||||
#[repr(transparent)]
|
||||
pub struct BufferUsageFlags: u32 {
|
||||
const NONE = 0;
|
||||
const MAP_READ = 1;
|
||||
const MAP_WRITE = 2;
|
||||
const TRANSFER_SRC = 4;
|
||||
const TRANSFER_DST = 8;
|
||||
const INDEX = 16;
|
||||
const VERTEX = 32;
|
||||
const UNIFORM = 64;
|
||||
const STORAGE = 128;
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct BufferDescriptor {
|
||||
pub size: u32,
|
||||
pub usage: BufferUsageFlags,
|
||||
}
|
||||
|
||||
pub struct Buffer<B: hal::Backend> {
|
||||
pub(crate) raw: B::UnboundBuffer,
|
||||
pub(crate) memory_properties: hal::memory::Properties,
|
||||
// TODO: mapping, unmap()
|
||||
}
|
||||
|
||||
pub struct TextureView {
|
||||
// TODO
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub enum TextureDimension {
|
||||
D1,
|
||||
D2,
|
||||
D3,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub enum TextureFormat {
|
||||
R8g8b8a8Unorm = 0,
|
||||
@ -6,6 +49,46 @@ pub enum TextureFormat {
|
||||
D32FloatS8Uint = 3,
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
#[repr(transparent)]
|
||||
pub struct TextureUsageFlags: u32 {
|
||||
const NONE = 0;
|
||||
const TRANSFER_SRC = 1;
|
||||
const TRANSFER_DST = 2;
|
||||
const SAMPLED = 4;
|
||||
const STORAGE = 8;
|
||||
const OUTPUT_ATTACHMENT = 16;
|
||||
const PRESENT = 32;
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct TextureDescriptor {
|
||||
pub size: Extent3d,
|
||||
pub array_size: u32,
|
||||
pub dimension: TextureDimension,
|
||||
pub format: TextureFormat,
|
||||
pub usage: TextureUsageFlags,
|
||||
}
|
||||
|
||||
pub struct Texture {
|
||||
// TODO: create_texture_view()
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub enum AddressMode {
|
||||
ClampToEdge = 0,
|
||||
Repeat = 1,
|
||||
MirrorRepeat = 2,
|
||||
ClampToBorderColor = 3,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub enum FilterMode {
|
||||
Nearest = 0,
|
||||
Linear = 1,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub enum CompareFunction {
|
||||
Never = 0,
|
||||
@ -17,3 +100,29 @@ pub enum CompareFunction {
|
||||
GreaterEqual = 6,
|
||||
Always = 7,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub enum BorderColor {
|
||||
TransparentBlack = 0,
|
||||
OpaqueBlack = 1,
|
||||
OpaqueWhite = 2,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct SamplerDescriptor {
|
||||
pub r_address_mode: AddressMode,
|
||||
pub s_address_mode: AddressMode,
|
||||
pub t_address_mode: AddressMode,
|
||||
pub mag_filter: FilterMode,
|
||||
pub min_filter: FilterMode,
|
||||
pub mipmap_filer: FilterMode,
|
||||
pub lod_min_clamp: f32,
|
||||
pub lod_max_clamp: f32,
|
||||
pub max_anisotropy: u32,
|
||||
pub compare_function: CompareFunction,
|
||||
pub border_color: BorderColor,
|
||||
}
|
||||
|
||||
pub struct Sampler {
|
||||
// TODO
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user