diff options
Diffstat (limited to 'wgpu/src/triangle.rs')
-rw-r--r-- | wgpu/src/triangle.rs | 57 |
1 files changed, 30 insertions, 27 deletions
diff --git a/wgpu/src/triangle.rs b/wgpu/src/triangle.rs index 2f255940..168ff953 100644 --- a/wgpu/src/triangle.rs +++ b/wgpu/src/triangle.rs @@ -127,21 +127,19 @@ impl Pipeline { bind_group_layouts: &[&constants_layout], }); - let vs_module = device.create_shader_module(&wgpu::include_spirv!( - "shader/triangle.vert.spv" - )); - - let fs_module = device.create_shader_module(&wgpu::include_spirv!( - "shader/triangle.frag.spv" - )); + let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { + label: Some("iced_wgpu::triangle::shader"), + source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed(include_str!("shader/triangle.wgsl"))), + flags: wgpu::ShaderFlags::all() + }); let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("iced_wgpu::triangle pipeline"), layout: Some(&layout), vertex: wgpu::VertexState { - module: &vs_module, - entry_point: "main", + module: &shader, + entry_point: "vs_main", buffers: &[wgpu::VertexBufferLayout { array_stride: mem::size_of::<Vertex2D>() as u64, step_mode: wgpu::InputStepMode::Vertex, @@ -149,40 +147,41 @@ impl Pipeline { // Position wgpu::VertexAttribute { shader_location: 0, - format: wgpu::VertexFormat::Float2, + format: wgpu::VertexFormat::Float32x2, offset: 0, }, // Color wgpu::VertexAttribute { shader_location: 1, - format: wgpu::VertexFormat::Float4, + format: wgpu::VertexFormat::Float32x4, offset: 4 * 2, }, ], }], }, fragment: Some(wgpu::FragmentState { - module: &fs_module, - entry_point: "main", + module: &shader, + entry_point: "fs_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, - }, + blend: Some(wgpu::BlendState { + color: wgpu::BlendComponent { + src_factor: wgpu::BlendFactor::SrcAlpha, + dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, + operation: wgpu::BlendOperation::Add, + }, + alpha: wgpu::BlendComponent { + 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, @@ -261,7 +260,8 @@ impl Pipeline { Uniforms, >( ) - as u64), + as + u64), }, }], }); @@ -303,6 +303,8 @@ impl Pipeline { vertex_buffer.copy_from_slice(vertices); } + println!("Indices: {} - Index Size: {}", indices_size, self.index_buffer.size); + { let mut index_buffer = staging_belt.write_buffer( encoder, @@ -331,6 +333,7 @@ impl Pipeline { let uniforms = bytemuck::cast_slice(&uniforms); + if let Some(uniforms_size) = wgpu::BufferSize::new(uniforms.len() as u64) { @@ -364,8 +367,8 @@ impl Pipeline { encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("iced_wgpu::triangle render pass"), color_attachments: &[ - wgpu::RenderPassColorAttachmentDescriptor { - attachment, + wgpu::RenderPassColorAttachment { + view: attachment, resolve_target, ops: wgpu::Operations { load, store: true }, }, |