Update wgpu from 0.4 to 0.5 (currently it's not rendering)

This commit is contained in:
Keavon Chambers
2020-05-02 14:44:28 -07:00
parent b30ee294a6
commit 323a951362
12 changed files with 562 additions and 388 deletions
+26 -70
View File
@@ -1,75 +1,41 @@
pub struct PipelineDetails<'a> {
pub vertex_shader: &'a wgpu::ShaderModule,
pub fragment_shader: &'a wgpu::ShaderModule,
pub texture_view: Option<&'a wgpu::TextureView>,
}
pub struct Pipeline {
pub bind_group_layout: wgpu::BindGroupLayout,
pub render_pipeline: wgpu::RenderPipeline,
pub vertex_buffer: wgpu::Buffer,
pub index_buffer: wgpu::Buffer,
pub index_count: u32,
pub texture_bind_group: wgpu::BindGroup,
}
impl Pipeline {
pub fn new(device: &wgpu::Device, pipeline_details: PipelineDetails) -> Self {
let texture_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
pub fn new(device: &wgpu::Device, vertex_shader: &wgpu::ShaderModule, fragment_shader: &wgpu::ShaderModule) -> Self {
let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
bindings: &[
wgpu::BindGroupLayoutBinding {
wgpu::BindGroupLayoutEntry {
binding: 0,
visibility: wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::SampledTexture {
multisampled: false,
dimension: wgpu::TextureViewDimension::D2,
component_type: wgpu::TextureComponentType::Float,
multisampled: false,
},
},
// wgpu::BindGroupLayoutBinding {
// wgpu::BindGroupLayoutEntry {
// binding: 1,
// visibility: wgpu::ShaderStage::FRAGMENT,
// ty: wgpu::BindingType::Sampler,
// },
],
});
let texture_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
layout: &texture_bind_group_layout,
bindings: &[
wgpu::Binding {
binding: 0,
resource: wgpu::BindingResource::TextureView(pipeline_details.texture_view.unwrap()),
},
// wgpu::Binding {
// binding: 1,
// resource: wgpu::BindingResource::Sampler(&texture.sampler),
// }
],
label: None,
});
let render_pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
bind_group_layouts: &[&texture_bind_group_layout],
bind_group_layouts: &[&bind_group_layout],
});
let vertex_buffer_descriptors = wgpu::VertexBufferDescriptor {
stride: std::mem::size_of::<[f32; 2]>() as wgpu::BufferAddress,
step_mode: wgpu::InputStepMode::Vertex,
attributes: &[
wgpu::VertexAttributeDescriptor {
offset: 0,
shader_location: 0,
format: wgpu::VertexFormat::Float2,
},
],
};
let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
layout: &render_pipeline_layout,
vertex_stage: wgpu::ProgrammableStageDescriptor {
module: pipeline_details.vertex_shader,
module: vertex_shader,
entry_point: "main",
},
fragment_stage: Some(wgpu::ProgrammableStageDescriptor {
module: pipeline_details.fragment_shader,
module: fragment_shader,
entry_point: "main",
}),
rasterization_state: Some(wgpu::RasterizationStateDescriptor {
@@ -79,6 +45,7 @@ impl Pipeline {
depth_bias_slope_scale: 0.0,
depth_bias_clamp: 0.0,
}),
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
color_states: &[
wgpu::ColorStateDescriptor {
format: wgpu::TextureFormat::Bgra8UnormSrgb,
@@ -87,39 +54,28 @@ impl Pipeline {
write_mask: wgpu::ColorWrite::ALL,
},
],
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
depth_stencil_state: None,
index_format: wgpu::IndexFormat::Uint16,
vertex_buffers: &[vertex_buffer_descriptors],
vertex_state: wgpu::VertexStateDescriptor {
index_format: wgpu::IndexFormat::Uint16,
vertex_buffers: &[wgpu::VertexBufferDescriptor {
stride: std::mem::size_of::<[f32; 2]>() as wgpu::BufferAddress,
step_mode: wgpu::InputStepMode::Vertex,
attributes: &[wgpu::VertexAttributeDescriptor {
offset: 0,
shader_location: 0,
format: wgpu::VertexFormat::Float2,
},
],
}],
},
sample_count: 1,
sample_mask: !0,
alpha_to_coverage_enabled: false,
});
let vertex_buffer = device.create_buffer_mapped(VERTICES.len(), wgpu::BufferUsage::VERTEX).fill_from_slice(VERTICES);
let index_buffer = device.create_buffer_mapped(INDICES.len(), wgpu::BufferUsage::INDEX).fill_from_slice(INDICES);
let index_count = INDICES.len() as u32;
Self {
bind_group_layout,
render_pipeline,
vertex_buffer,
index_buffer,
index_count,
texture_bind_group,
}
}
}
const VERTICES: &[[f32; 2]] = &[
[-0.0868241, -0.49240386],
[-0.49513406, -0.06958647],
[-0.21918549, 0.44939706],
[0.35966998, 0.3473291],
[0.44147372, -0.2347359],
];
const INDICES: &[u16] = &[
0, 1, 4,
1, 2, 4,
2, 3, 4,
];