1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use wgpu::ShaderStages;
#[derive(Debug)]
pub struct BindingGroup {
pub wgpu: wgpu::BindGroup,
pub set_index: u32,
}
impl BindingGroup {
pub fn new(set_index: u32, wgpu: wgpu::BindGroup) -> Self {
Self { wgpu, set_index }
}
}
#[derive(Debug)]
pub struct BindingGroupLayout {
pub wgpu: wgpu::BindGroupLayout,
pub size: usize,
pub set_index: u32,
}
impl BindingGroupLayout {
pub fn new(set_index: u32, layout: wgpu::BindGroupLayout, size: usize) -> Self {
Self {
wgpu: layout,
size,
set_index,
}
}
}
pub trait Bind {
fn binding(&self, index: u32) -> wgpu::BindGroupEntry;
}
#[derive(Debug)]
pub enum BindingType {
UniformBuffer,
UniformBufferDynamic,
Sampler,
SampledTexture { multisampled: bool },
}
impl BindingType {
pub fn to_wgpu(&self) -> wgpu::BindingType {
match self {
BindingType::UniformBuffer => wgpu::BindingType::Buffer {
ty: wgpu::BufferBindingType::Uniform,
has_dynamic_offset: false,
min_binding_size: None,
},
BindingType::UniformBufferDynamic => wgpu::BindingType::Buffer {
ty: wgpu::BufferBindingType::Uniform,
has_dynamic_offset: false,
min_binding_size: None,
},
BindingType::SampledTexture { multisampled } => wgpu::BindingType::Texture {
sample_type: wgpu::TextureSampleType::Float { filterable: false },
multisampled: *multisampled,
view_dimension: wgpu::TextureViewDimension::D2,
},
BindingType::Sampler => wgpu::BindingType::Sampler {
comparison: false,
filtering: true,
},
}
}
}
#[derive(Debug)]
pub struct Binding {
pub binding: BindingType,
pub stage: ShaderStages,
}