veloren_voxygen/render/pipelines/
blit.rs

1pub 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                    // Color source
16                    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: Some("main"),
88                buffers: &[],
89                compilation_options: Default::default(),
90            },
91            primitive: wgpu::PrimitiveState {
92                topology: wgpu::PrimitiveTopology::TriangleList,
93                strip_index_format: None,
94                front_face: wgpu::FrontFace::Ccw,
95                cull_mode: None,
96                unclipped_depth: false,
97                polygon_mode: wgpu::PolygonMode::Fill,
98                conservative: false,
99            },
100            depth_stencil: None,
101            multisample: wgpu::MultisampleState {
102                count: 1,
103                mask: !0,
104                alpha_to_coverage_enabled: false,
105            },
106            fragment: Some(wgpu::FragmentState {
107                module: fs_module,
108                entry_point: Some("main"),
109                targets: &[Some(wgpu::ColorTargetState {
110                    format: surface_config.format,
111                    blend: None,
112                    write_mask: wgpu::ColorWrites::ALL,
113                })],
114                compilation_options: Default::default(),
115            }),
116            multiview: None,
117            cache: None,
118        });
119
120        Self {
121            pipeline: render_pipeline,
122        }
123    }
124}