From 66243f12c98cb2aa5ee3d0d8e4adbe0e31b8353e Mon Sep 17 00:00:00 2001 From: aloucks Date: Sat, 28 Mar 2020 10:45:18 -0400 Subject: [PATCH] [rs] Add VertexStateDescriptor (#221) The vertex state properties are now bundled in the VertexStateDescriptor which matches the spec. Fixes #220 --- wgpu/examples/boids/main.rs | 28 ++++++++++++---------- wgpu/examples/cube/main.rs | 36 +++++++++++++++------------- wgpu/examples/hello-triangle/main.rs | 6 +++-- wgpu/examples/mipmap/main.rs | 20 +++++++++------- wgpu/examples/msaa-line/main.rs | 14 ++++++----- wgpu/examples/shadow/main.rs | 12 ++++++---- wgpu/examples/skybox/main.rs | 6 +++-- wgpu/src/lib.rs | 21 ++++++++++------ 8 files changed, 84 insertions(+), 59 deletions(-) diff --git a/wgpu/examples/boids/main.rs b/wgpu/examples/boids/main.rs index 41ceb228d8..be2b80a4de 100644 --- a/wgpu/examples/boids/main.rs +++ b/wgpu/examples/boids/main.rs @@ -120,19 +120,21 @@ impl framework::Example for Example { write_mask: wgpu::ColorWrite::ALL, }], depth_stencil_state: None, - index_format: wgpu::IndexFormat::Uint16, - vertex_buffers: &[ - wgpu::VertexBufferDescriptor { - stride: 4 * 4, - step_mode: wgpu::InputStepMode::Instance, - attributes: &vertex_attr_array![0 => Float2, 1 => Float2], - }, - wgpu::VertexBufferDescriptor { - stride: 2 * 4, - step_mode: wgpu::InputStepMode::Vertex, - attributes: &vertex_attr_array![2 => Float2], - }, - ], + vertex_state: wgpu::VertexStateDescriptor { + index_format: wgpu::IndexFormat::Uint16, + vertex_buffers: &[ + wgpu::VertexBufferDescriptor { + stride: 4 * 4, + step_mode: wgpu::InputStepMode::Instance, + attributes: &vertex_attr_array![0 => Float2, 1 => Float2], + }, + wgpu::VertexBufferDescriptor { + stride: 2 * 4, + step_mode: wgpu::InputStepMode::Vertex, + attributes: &vertex_attr_array![2 => Float2], + }, + ], + }, sample_count: 1, sample_mask: !0, alpha_to_coverage_enabled: false, diff --git a/wgpu/examples/cube/main.rs b/wgpu/examples/cube/main.rs index 4d78131af1..07aa217f7c 100644 --- a/wgpu/examples/cube/main.rs +++ b/wgpu/examples/cube/main.rs @@ -268,23 +268,25 @@ impl framework::Example for Example { write_mask: wgpu::ColorWrite::ALL, }], depth_stencil_state: None, - index_format: wgpu::IndexFormat::Uint16, - vertex_buffers: &[wgpu::VertexBufferDescriptor { - stride: vertex_size as wgpu::BufferAddress, - step_mode: wgpu::InputStepMode::Vertex, - attributes: &[ - wgpu::VertexAttributeDescriptor { - format: wgpu::VertexFormat::Float4, - offset: 0, - shader_location: 0, - }, - wgpu::VertexAttributeDescriptor { - format: wgpu::VertexFormat::Float2, - offset: 4 * 4, - shader_location: 1, - }, - ], - }], + vertex_state: wgpu::VertexStateDescriptor { + index_format: wgpu::IndexFormat::Uint16, + vertex_buffers: &[wgpu::VertexBufferDescriptor { + stride: vertex_size as wgpu::BufferAddress, + step_mode: wgpu::InputStepMode::Vertex, + attributes: &[ + wgpu::VertexAttributeDescriptor { + format: wgpu::VertexFormat::Float4, + offset: 0, + shader_location: 0, + }, + wgpu::VertexAttributeDescriptor { + format: wgpu::VertexFormat::Float2, + offset: 4 * 4, + shader_location: 1, + }, + ], + }], + }, sample_count: 1, sample_mask: !0, alpha_to_coverage_enabled: false, diff --git a/wgpu/examples/hello-triangle/main.rs b/wgpu/examples/hello-triangle/main.rs index edee6ef7e9..8d7f6e22e0 100644 --- a/wgpu/examples/hello-triangle/main.rs +++ b/wgpu/examples/hello-triangle/main.rs @@ -68,8 +68,10 @@ async fn run(event_loop: EventLoop<()>, window: Window) { write_mask: wgpu::ColorWrite::ALL, }], depth_stencil_state: None, - index_format: wgpu::IndexFormat::Uint16, - vertex_buffers: &[], + vertex_state: wgpu::VertexStateDescriptor { + index_format: wgpu::IndexFormat::Uint16, + vertex_buffers: &[], + }, sample_count: 1, sample_mask: !0, alpha_to_coverage_enabled: false, diff --git a/wgpu/examples/mipmap/main.rs b/wgpu/examples/mipmap/main.rs index 0c2581104d..1c019c411e 100644 --- a/wgpu/examples/mipmap/main.rs +++ b/wgpu/examples/mipmap/main.rs @@ -133,8 +133,10 @@ impl Example { write_mask: wgpu::ColorWrite::ALL, }], depth_stencil_state: None, - index_format: wgpu::IndexFormat::Uint16, - vertex_buffers: &[], + vertex_state: wgpu::VertexStateDescriptor { + index_format: wgpu::IndexFormat::Uint16, + vertex_buffers: &[], + }, sample_count: 1, sample_mask: !0, alpha_to_coverage_enabled: false, @@ -355,12 +357,14 @@ impl framework::Example for Example { write_mask: wgpu::ColorWrite::ALL, }], depth_stencil_state: None, - index_format: wgpu::IndexFormat::Uint16, - vertex_buffers: &[wgpu::VertexBufferDescriptor { - stride: vertex_size as wgpu::BufferAddress, - step_mode: wgpu::InputStepMode::Vertex, - attributes: &vertex_attr_array![0 => Float4], - }], + vertex_state: wgpu::VertexStateDescriptor { + index_format: wgpu::IndexFormat::Uint16, + vertex_buffers: &[wgpu::VertexBufferDescriptor { + stride: vertex_size as wgpu::BufferAddress, + step_mode: wgpu::InputStepMode::Vertex, + attributes: &vertex_attr_array![0 => Float4], + }], + }, sample_count: 1, sample_mask: !0, alpha_to_coverage_enabled: false, diff --git a/wgpu/examples/msaa-line/main.rs b/wgpu/examples/msaa-line/main.rs index 3859d6dfeb..243925d359 100644 --- a/wgpu/examples/msaa-line/main.rs +++ b/wgpu/examples/msaa-line/main.rs @@ -69,12 +69,14 @@ impl Example { write_mask: wgpu::ColorWrite::ALL, }], depth_stencil_state: None, - index_format: wgpu::IndexFormat::Uint16, - vertex_buffers: &[wgpu::VertexBufferDescriptor { - stride: std::mem::size_of::() as wgpu::BufferAddress, - step_mode: wgpu::InputStepMode::Vertex, - attributes: &vertex_attr_array![0 => Float2, 1 => Float4], - }], + vertex_state: wgpu::VertexStateDescriptor { + index_format: wgpu::IndexFormat::Uint16, + vertex_buffers: &[wgpu::VertexBufferDescriptor { + stride: std::mem::size_of::() as wgpu::BufferAddress, + step_mode: wgpu::InputStepMode::Vertex, + attributes: &vertex_attr_array![0 => Float2, 1 => Float4], + }], + }, sample_count, sample_mask: !0, alpha_to_coverage_enabled: false, diff --git a/wgpu/examples/shadow/main.rs b/wgpu/examples/shadow/main.rs index 8cf497a52e..b76b22900f 100644 --- a/wgpu/examples/shadow/main.rs +++ b/wgpu/examples/shadow/main.rs @@ -467,8 +467,10 @@ impl framework::Example for Example { stencil_read_mask: 0, stencil_write_mask: 0, }), - index_format: wgpu::IndexFormat::Uint16, - vertex_buffers: &[vb_desc.clone()], + vertex_state: wgpu::VertexStateDescriptor { + index_format: wgpu::IndexFormat::Uint16, + vertex_buffers: &[vb_desc.clone()], + }, sample_count: 1, sample_mask: !0, alpha_to_coverage_enabled: false, @@ -599,8 +601,10 @@ impl framework::Example for Example { stencil_read_mask: 0, stencil_write_mask: 0, }), - index_format: wgpu::IndexFormat::Uint16, - vertex_buffers: &[vb_desc], + vertex_state: wgpu::VertexStateDescriptor { + index_format: wgpu::IndexFormat::Uint16, + vertex_buffers: &[vb_desc], + }, sample_count: 1, sample_mask: !0, alpha_to_coverage_enabled: false, diff --git a/wgpu/examples/skybox/main.rs b/wgpu/examples/skybox/main.rs index e68076f55d..e8a08c4d05 100644 --- a/wgpu/examples/skybox/main.rs +++ b/wgpu/examples/skybox/main.rs @@ -128,9 +128,11 @@ impl framework::Example for Skybox { alpha_blend: wgpu::BlendDescriptor::REPLACE, write_mask: wgpu::ColorWrite::ALL, }], + vertex_state: wgpu::VertexStateDescriptor { + index_format: wgpu::IndexFormat::Uint16, + vertex_buffers: &[], + }, depth_stencil_state: None, - index_format: wgpu::IndexFormat::Uint16, - vertex_buffers: &[], sample_count: 1, sample_mask: !0, alpha_to_coverage_enabled: false, diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index 88bcbe7ff3..5065ea5f4f 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -310,6 +310,16 @@ pub struct ProgrammableStageDescriptor<'a> { pub entry_point: &'a str, } +/// The vertex input state for a render pipeline. +#[derive(Clone, Debug)] +pub struct VertexStateDescriptor<'a> { + /// The format of any index buffers used with this pipeline. + pub index_format: IndexFormat, + + /// The format of any vertex buffers used with this pipeline. + pub vertex_buffers: &'a [VertexBufferDescriptor<'a>], +} + /// A description of a vertex buffer. #[derive(Clone, Debug)] pub struct VertexBufferDescriptor<'a> { @@ -346,11 +356,8 @@ pub struct RenderPipelineDescriptor<'a> { /// The effect of draw calls on the depth and stencil aspects of the output target, if any. pub depth_stencil_state: Option, - /// The format of any index buffers used with this pipeline. - pub index_format: IndexFormat, - - /// The format of any vertex buffers used with this pipeline. - pub vertex_buffers: &'a [VertexBufferDescriptor<'a>], + /// The vertex input state for this pipeline. + pub vertex_state: VertexStateDescriptor<'a>, /// The number of samples calculated per pixel (for MSAA). pub sample_count: u32, @@ -719,7 +726,7 @@ impl Device { let temp_color_states = desc.color_states.to_vec(); let temp_vertex_buffers = desc - .vertex_buffers + .vertex_state.vertex_buffers .iter() .map(|vbuf| pipe::VertexBufferLayoutDescriptor { array_stride: vbuf.stride, @@ -750,7 +757,7 @@ impl Device { .as_ref() .map_or(ptr::null(), |p| p as *const _), vertex_state: pipe::VertexStateDescriptor { - index_format: desc.index_format, + index_format: desc.vertex_state.index_format, vertex_buffers: temp_vertex_buffers.as_ptr(), vertex_buffers_length: temp_vertex_buffers.len(), },