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
use super::UniformProperty;
use crate::texture::{TextureComponentType, TextureFormat, TextureViewDimension};

bitflags::bitflags! {
    pub struct BindingShaderStage: u32 {
        const VERTEX = 1;
        const FRAGMENT = 2;
        const COMPUTE = 4;
    }
}

#[derive(Hash, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
pub struct BindingDescriptor {
    pub name: String,
    pub index: u32,
    pub bind_type: BindType,
    pub shader_stage: BindingShaderStage,
}

#[derive(Hash, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
pub enum BindType {
    Uniform {
        dynamic: bool,
        property: UniformProperty,
    },
    StorageBuffer {
        dynamic: bool,
        readonly: bool,
    },
    Sampler {
        comparison: bool,
    },
    SampledTexture {
        multisampled: bool,
        dimension: TextureViewDimension,
        component_type: TextureComponentType,
    },
    StorageTexture {
        dimension: TextureViewDimension,
        format: TextureFormat,
        readonly: bool,
    },
}

impl BindType {
    pub fn get_uniform_size(&self) -> Option<u64> {
        match self {
            BindType::Uniform { property, .. } => Some(property.get_size()),
            _ => None,
        }
    }
}