Rust side render pass begin/end

This commit is contained in:
Dzmitry Malyshau 2018-10-01 10:11:44 -04:00
parent 71b170979d
commit da95fe6b1e
4 changed files with 91 additions and 9 deletions

View File

@ -9,6 +9,7 @@ fn main() {
anisotropic_filtering: false,
},
});
let vs_bytes = include_bytes!("./../data/hello_triangle.vert.spv");
let vs_module = device.create_shader_module(vs_bytes);
let fs_bytes = include_bytes!("./../data/hello_triangle.frag.spv");
@ -49,7 +50,25 @@ fn main() {
attachment_state: &attachment_state,
});
let cmd_buf = device.create_command_buffer(wgpu::CommandBufferDescriptor {});
let mut cmd_buf = device.create_command_buffer(wgpu::CommandBufferDescriptor {});
{
let color_view = unimplemented!(); //TODO!
let rpass = cmd_buf.begin_render_pass(wgpu::RenderPassDescriptor {
color_attachments: &[
wgpu::RenderPassColorAttachmentDescriptor {
attachment: &color_view,
load_op: wgpu::LoadOp::Clear,
store_op: wgpu::StoreOp::Store,
clear_color: wgpu::Color::GREEN,
},
],
depth_stencil_attachment: None,
});
rpass.end_pass();
}
let queue = device.get_queue();
queue.submit(&[cmd_buf]);
}

View File

@ -30,16 +30,16 @@ pub enum StoreOp {
}
#[repr(C)]
pub struct RenderPassColorAttachmentDescriptor {
pub attachment: TextureViewId,
pub struct RenderPassColorAttachmentDescriptor<T> {
pub attachment: T,
pub load_op: LoadOp,
pub store_op: StoreOp,
pub clear_color: Color,
}
#[repr(C)]
pub struct RenderPassDepthStencilAttachmentDescriptor {
pub attachment: TextureViewId,
pub struct RenderPassDepthStencilAttachmentDescriptor<T> {
pub attachment: T,
pub depth_load_op: LoadOp,
pub depth_store_op: StoreOp,
pub clear_depth: f32,
@ -49,9 +49,9 @@ pub struct RenderPassDepthStencilAttachmentDescriptor {
}
#[repr(C)]
pub struct RenderPassDescriptor<'a> {
pub color_attachments: &'a [RenderPassColorAttachmentDescriptor],
pub depth_stencil_attachment: RenderPassDepthStencilAttachmentDescriptor,
pub struct RenderPassDescriptor<'a, T: 'a> {
pub color_attachments: &'a [RenderPassColorAttachmentDescriptor<T>],
pub depth_stencil_attachment: Option<RenderPassDepthStencilAttachmentDescriptor<T>>,
}
#[repr(C)]
@ -83,7 +83,7 @@ pub struct CommandBufferDescriptor {}
#[no_mangle]
pub extern "C" fn wgpu_command_buffer_begin_render_pass(
command_buffer_id: CommandBufferId,
_descriptor: RenderPassDescriptor,
_descriptor: RenderPassDescriptor<TextureViewId>,
) -> RenderPassId {
let raw = registry::COMMAND_BUFFER_REGISTRY
.lock()

View File

@ -41,6 +41,7 @@ use back::Backend as B;
use registry::Id;
#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct Color {
pub r: f32,
pub g: f32,
@ -48,7 +49,17 @@ pub struct Color {
pub a: f32,
}
impl Color {
pub const TRANSPARENT : Self = Color { r: 0.0, g: 0.0, b: 0.0, a: 0.0 };
pub const BLACK : Self = Color { r: 0.0, g: 0.0, b: 0.0, a: 1.0 };
pub const WHITE : Self = Color { r: 1.0, g: 1.0, b: 1.0, a: 1.0 };
pub const RED : Self = Color { r: 1.0, g: 0.0, b: 0.0, a: 1.0 };
pub const GREEN : Self = Color { r: 0.0, g: 1.0, b: 0.0, a: 1.0 };
pub const BLUE : Self = Color { r: 0.0, g: 0.0, b: 1.0, a: 1.0 };
}
#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct Origin3d {
pub x: f32,
pub y: f32,
@ -56,6 +67,7 @@ pub struct Origin3d {
}
#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct Extent3d {
pub width: f32,
pub height: f32,

View File

@ -10,6 +10,8 @@ pub use wgn::{
Origin3d, PowerPreference, ShaderModuleDescriptor, ShaderStage,
BindGroupLayoutBinding, TextureFormat,
PrimitiveTopology, BlendStateDescriptor, ColorWriteFlags, DepthStencilStateDescriptor,
RenderPassDescriptor, RenderPassColorAttachmentDescriptor, RenderPassDepthStencilAttachmentDescriptor,
LoadOp, StoreOp,
};
@ -25,6 +27,10 @@ pub struct Device {
id: wgn::DeviceId,
}
pub struct TextureView {
id: wgn::TextureViewId,
}
pub struct BindGroupLayout {
id: wgn::BindGroupLayoutId,
}
@ -57,6 +63,11 @@ pub struct CommandBuffer {
id: wgn::CommandBufferId,
}
pub struct RenderPass<'a> {
id: wgn::RenderPassId,
parent: &'a mut CommandBuffer,
}
pub struct Queue {
id: wgn::QueueId,
}
@ -205,6 +216,46 @@ impl Device {
}
}
impl CommandBuffer {
pub fn begin_render_pass(&mut self, desc: RenderPassDescriptor<&TextureView>) -> RenderPass {
let colors = desc.color_attachments
.iter()
.map(|ca| RenderPassColorAttachmentDescriptor {
attachment: ca.attachment.id,
load_op: ca.load_op,
store_op: ca.store_op,
clear_color: ca.clear_color,
})
.collect::<ArrayVec<[_; 4]>>();
let depth_stencil = desc.depth_stencil_attachment
.map(|dsa| RenderPassDepthStencilAttachmentDescriptor {
attachment: dsa.attachment.id,
depth_load_op: dsa.depth_load_op,
depth_store_op: dsa.depth_store_op,
clear_depth: dsa.clear_depth,
stencil_load_op: dsa.stencil_load_op,
stencil_store_op: dsa.stencil_store_op,
clear_stencil: dsa.clear_stencil,
});
RenderPass {
id: wgn::wgpu_command_buffer_begin_render_pass(self.id, RenderPassDescriptor {
color_attachments: &colors,
depth_stencil_attachment: depth_stencil,
}),
parent: self,
}
}
}
impl<'a> RenderPass<'a> {
pub fn end_pass(self) -> &'a mut CommandBuffer {
wgn::wgpu_render_pass_end_pass(self.id);
self.parent
}
}
impl Queue {
pub fn submit(&self, command_buffers: &[CommandBuffer]) {
wgn::wgpu_queue_submit(