From e2595ac0aa53448feb421c1591178b748814055a Mon Sep 17 00:00:00 2001 From: Poly Date: Wed, 3 Feb 2021 20:06:07 +0100 Subject: [PATCH] [wgpu 0.7] Update triangle.rs --- wgpu/src/triangle.rs | 112 +++++++++++++++++++++++-------------------- 1 file changed, 60 insertions(+), 52 deletions(-) diff --git a/wgpu/src/triangle.rs b/wgpu/src/triangle.rs index 61a771d8..d23ce29e 100644 --- a/wgpu/src/triangle.rs +++ b/wgpu/src/triangle.rs @@ -86,8 +86,9 @@ impl Pipeline { entries: &[wgpu::BindGroupLayoutEntry { binding: 0, visibility: wgpu::ShaderStage::VERTEX, - ty: wgpu::BindingType::UniformBuffer { - dynamic: true, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Uniform, + has_dynamic_offset: true, min_binding_size: wgpu::BufferSize::new( mem::size_of::() as u64, ), @@ -109,11 +110,13 @@ impl Pipeline { layout: &constants_layout, entries: &[wgpu::BindGroupEntry { binding: 0, - resource: wgpu::BindingResource::Buffer( - constants_buffer - .raw - .slice(0..std::mem::size_of::() as u64), - ), + resource: wgpu::BindingResource::Buffer { + buffer: &constants_buffer.raw, + offset: 0, + size: wgpu::BufferSize::new( + std::mem::size_of::() as u64, + ), + }, }], }); @@ -124,11 +127,11 @@ impl Pipeline { bind_group_layouts: &[&constants_layout], }); - let vs_module = device.create_shader_module(wgpu::include_spirv!( + let vs_module = device.create_shader_module(&wgpu::include_spirv!( "shader/triangle.vert.spv" )); - let fs_module = device.create_shader_module(wgpu::include_spirv!( + let fs_module = device.create_shader_module(&wgpu::include_spirv!( "shader/triangle.frag.spv" )); @@ -136,49 +139,21 @@ impl Pipeline { device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("iced_wgpu::triangle pipeline"), layout: Some(&layout), - vertex_stage: wgpu::ProgrammableStageDescriptor { + vertex: wgpu::VertexState { module: &vs_module, entry_point: "main", - }, - fragment_stage: Some(wgpu::ProgrammableStageDescriptor { - module: &fs_module, - entry_point: "main", - }), - rasterization_state: Some(wgpu::RasterizationStateDescriptor { - front_face: wgpu::FrontFace::Cw, - cull_mode: wgpu::CullMode::None, - ..Default::default() - }), - primitive_topology: wgpu::PrimitiveTopology::TriangleList, - color_states: &[wgpu::ColorStateDescriptor { - format, - color_blend: wgpu::BlendDescriptor { - src_factor: wgpu::BlendFactor::SrcAlpha, - dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, - operation: wgpu::BlendOperation::Add, - }, - alpha_blend: wgpu::BlendDescriptor { - src_factor: wgpu::BlendFactor::One, - dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, - operation: wgpu::BlendOperation::Add, - }, - write_mask: wgpu::ColorWrite::ALL, - }], - depth_stencil_state: None, - vertex_state: wgpu::VertexStateDescriptor { - index_format: wgpu::IndexFormat::Uint32, - vertex_buffers: &[wgpu::VertexBufferDescriptor { - stride: mem::size_of::() as u64, + buffers: &[wgpu::VertexBufferLayout { + array_stride: mem::size_of::() as u64, step_mode: wgpu::InputStepMode::Vertex, attributes: &[ // Position - wgpu::VertexAttributeDescriptor { + wgpu::VertexAttribute { shader_location: 0, format: wgpu::VertexFormat::Float2, offset: 0, }, // Color - wgpu::VertexAttributeDescriptor { + wgpu::VertexAttribute { shader_location: 1, format: wgpu::VertexFormat::Float4, offset: 4 * 2, @@ -186,11 +161,38 @@ impl Pipeline { ], }], }, - sample_count: u32::from( - antialiasing.map(|a| a.sample_count()).unwrap_or(1), - ), - sample_mask: !0, - alpha_to_coverage_enabled: false, + fragment: Some(wgpu::FragmentState { + module: &fs_module, + entry_point: "main", + targets: &[wgpu::ColorTargetState { + format, + color_blend: wgpu::BlendState { + src_factor: wgpu::BlendFactor::SrcAlpha, + dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, + operation: wgpu::BlendOperation::Add, + }, + alpha_blend: wgpu::BlendState { + src_factor: wgpu::BlendFactor::One, + dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, + operation: wgpu::BlendOperation::Add, + }, + write_mask: wgpu::ColorWrite::ALL, + }], + }), + primitive: wgpu::PrimitiveState { + topology: wgpu::PrimitiveTopology::TriangleList, + front_face: wgpu::FrontFace::Cw, + cull_mode: wgpu::CullMode::None, + ..Default::default() + }, + depth_stencil: None, + multisample: wgpu::MultisampleState { + count: u32::from( + antialiasing.map(|a| a.sample_count()).unwrap_or(1), + ), + mask: !0, + alpha_to_coverage_enabled: false, + }, }); Pipeline { @@ -252,11 +254,15 @@ impl Pipeline { layout: &self.constants_layout, entries: &[wgpu::BindGroupEntry { binding: 0, - resource: wgpu::BindingResource::Buffer( - self.uniforms_buffer.raw.slice( - 0..std::mem::size_of::() as u64, - ), - ), + resource: wgpu::BindingResource::Buffer { + buffer: &self.uniforms_buffer.raw, + offset: 0, + size: wgpu::BufferSize::new(std::mem::size_of::< + Uniforms, + >( + ) + as u64), + }, }], }); } @@ -356,6 +362,7 @@ impl Pipeline { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: Some("iced_wgpu::triangle Render Pass"), color_attachments: &[ wgpu::RenderPassColorAttachmentDescriptor { attachment, @@ -390,6 +397,7 @@ impl Pipeline { self.index_buffer .raw .slice(index_offset * mem::size_of::() as u64..), + wgpu::IndexFormat::Uint32, ); render_pass.set_vertex_buffer(