using pipeline

This commit is contained in:
Piotrek
2021-04-12 12:09:25 +02:00
parent 93c535626a
commit c83ccead11
+26 -23
View File
@@ -48,27 +48,19 @@ impl App {
}; };
let swapchain = device.create_swap_chain(&surface, &swapchain_desc); let swapchain = device.create_swap_chain(&surface, &swapchain_desc);
// Create pipeline // Pipeline stuff
let vert_module = device.create_shader_module(&wgpu::include_spirv!(".bin\\shader.vert.spv"));
let frag_module = device.create_shader_module(&wgpu::include_spirv!(".bin\\shader.frag.spv"));
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: Some("Render Pipeline Layout"), label: Some("Render Pipeline Layout"),
bind_group_layouts: &[], bind_group_layouts: &[],
push_constant_ranges: &[], push_constant_ranges: &[],
}); });
let vert_state = wgpu::VertexState { //vert
let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { module: &device.create_shader_module(&wgpu::include_spirv!(".bin\\shader.vert.spv")),
label: Some("Render Pipeline"),
layout: Some(&pipeline_layout),
// Vertex shader
vertex: wgpu::VertexState {
module: &vert_module,
entry_point: "main", entry_point: "main",
buffers: &[], buffers: &[],
}, };
// Fragment shader let frag_state = wgpu::FragmentState { // frag
fragment: Some(wgpu::FragmentState { module: &device.create_shader_module(&wgpu::include_spirv!(".bin\\shader.frag.spv")),
module: &frag_module,
entry_point: "main", entry_point: "main",
targets: &[wgpu::ColorTargetState { targets: &[wgpu::ColorTargetState {
format: swapchain_desc.format, format: swapchain_desc.format,
@@ -76,23 +68,30 @@ impl App {
color_blend: wgpu::BlendState::REPLACE, color_blend: wgpu::BlendState::REPLACE,
write_mask: wgpu::ColorWrite::ALL, write_mask: wgpu::ColorWrite::ALL,
}], }],
}), };
// Other let prim_state = wgpu::PrimitiveState { // primitive
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList, topology: wgpu::PrimitiveTopology::TriangleList,
strip_index_format: None, strip_index_format: None,
front_face: wgpu::FrontFace::Ccw, front_face: wgpu::FrontFace::Ccw,
cull_mode: wgpu::CullMode::Back, cull_mode: wgpu::CullMode::Back,
polygon_mode: wgpu::PolygonMode::Fill, polygon_mode: wgpu::PolygonMode::Fill,
}, };
depth_stencil: None, let multisample_state = wgpu::MultisampleState { // multisample
multisample: wgpu::MultisampleState {
count: 1, count: 1,
mask: !0, mask: !0,
alpha_to_coverage_enabled: false, alpha_to_coverage_enabled: false,
}, };
});
// Create pipeline
let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: Some("Render Pipeline"),
layout: Some(&pipeline_layout),
vertex: vert_state,
fragment: Some(frag_state),
primitive: prim_state,
depth_stencil: None,
multisample: multisample_state,
});
// Save values in app // Save values in app
Self { surface, device, queue, swapchain_desc, swapchain, pipeline } Self { surface, device, queue, swapchain_desc, swapchain, pipeline }
@@ -133,7 +132,8 @@ impl App {
store: true, store: true,
}; };
let _render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("Render Pass"), let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Render Pass"),
color_attachments: &[ color_attachments: &[
wgpu::RenderPassColorAttachmentDescriptor { wgpu::RenderPassColorAttachmentDescriptor {
attachment: &frame.view, attachment: &frame.view,
@@ -143,6 +143,9 @@ impl App {
], ],
depth_stencil_attachment: None, depth_stencil_attachment: None,
}); });
render_pass.set_pipeline(&self.pipeline);
render_pass.draw(0..3, 0..1);
} }
// Submit encoder (command buffer) // Submit encoder (command buffer)