veloren_voxygen/render/pipelines/
blit.rs1pub struct BindGroup {
2 pub(in super::super) bind_group: wgpu::BindGroup,
3}
4
5pub struct BlitLayout {
6 pub layout: wgpu::BindGroupLayout,
7}
8
9impl BlitLayout {
10 pub fn new(device: &wgpu::Device) -> Self {
11 Self {
12 layout: device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
13 label: None,
14 entries: &[
15 wgpu::BindGroupLayoutEntry {
17 binding: 0,
18 visibility: wgpu::ShaderStages::FRAGMENT,
19 ty: wgpu::BindingType::Texture {
20 sample_type: wgpu::TextureSampleType::Float { filterable: true },
21 view_dimension: wgpu::TextureViewDimension::D2,
22 multisampled: false,
23 },
24 count: None,
25 },
26 wgpu::BindGroupLayoutEntry {
27 binding: 1,
28 visibility: wgpu::ShaderStages::FRAGMENT,
29 ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering),
30 count: None,
31 },
32 ],
33 }),
34 }
35 }
36
37 pub fn bind(
38 &self,
39 device: &wgpu::Device,
40 src_color: &wgpu::TextureView,
41 sampler: &wgpu::Sampler,
42 ) -> BindGroup {
43 let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
44 label: None,
45 layout: &self.layout,
46 entries: &[
47 wgpu::BindGroupEntry {
48 binding: 0,
49 resource: wgpu::BindingResource::TextureView(src_color),
50 },
51 wgpu::BindGroupEntry {
52 binding: 1,
53 resource: wgpu::BindingResource::Sampler(sampler),
54 },
55 ],
56 });
57
58 BindGroup { bind_group }
59 }
60}
61
62pub struct BlitPipeline {
63 pub pipeline: wgpu::RenderPipeline,
64}
65
66impl BlitPipeline {
67 pub fn new(
68 device: &wgpu::Device,
69 vs_module: &wgpu::ShaderModule,
70 fs_module: &wgpu::ShaderModule,
71 surface_config: &wgpu::SurfaceConfiguration,
72 layout: &BlitLayout,
73 ) -> Self {
74 common_base::span!(_guard, "BlitPipeline::new");
75 let render_pipeline_layout =
76 device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
77 label: Some("Blit pipeline layout"),
78 push_constant_ranges: &[],
79 bind_group_layouts: &[&layout.layout],
80 });
81
82 let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
83 label: Some("Blit pipeline"),
84 layout: Some(&render_pipeline_layout),
85 vertex: wgpu::VertexState {
86 module: vs_module,
87 entry_point: "main",
88 buffers: &[],
89 },
90 primitive: wgpu::PrimitiveState {
91 topology: wgpu::PrimitiveTopology::TriangleList,
92 strip_index_format: None,
93 front_face: wgpu::FrontFace::Ccw,
94 cull_mode: None,
95 unclipped_depth: false,
96 polygon_mode: wgpu::PolygonMode::Fill,
97 conservative: false,
98 },
99 depth_stencil: None,
100 multisample: wgpu::MultisampleState {
101 count: 1,
102 mask: !0,
103 alpha_to_coverage_enabled: false,
104 },
105 fragment: Some(wgpu::FragmentState {
106 module: fs_module,
107 entry_point: "main",
108 targets: &[Some(wgpu::ColorTargetState {
109 format: surface_config.format,
110 blend: None,
111 write_mask: wgpu::ColorWrites::ALL,
112 })],
113 }),
114 multiview: None,
115 });
116
117 Self {
118 pipeline: render_pipeline,
119 }
120 }
121}