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
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
// Generated by `scripts/generate.js`

use utils::vk_traits::*;

/// Wrapper for [VkShaderStageFlags](https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VkShaderStageFlags.html).
///
/// Use the macro `VkShaderStageFlags!` as an alternative method to create a structure. For example, these two snippets return the same value:
/// ```
/// VkShaderStageFlags!(vertex, tessellation_control)
/// ```
/// ```
/// VkShaderStageFlags {
///     vertex: true,
///     tessellation_control: true,
///     ..VkShaderStageFlags::none()
/// }
/// ```
#[derive(Debug, Clone)]
pub struct VkShaderStageFlags {
    pub vertex: bool,
    pub tessellation_control: bool,
    pub tessellation_evaluation: bool,
    pub geometry: bool,
    pub fragment: bool,
    pub compute: bool,
    pub all_graphics: bool,
    pub raygen_khr: bool,
    pub any_hit_khr: bool,
    pub closest_hit_khr: bool,
    pub miss_khr: bool,
    pub intersection_khr: bool,
    pub callable_khr: bool,
    pub task_nv: bool,
    pub mesh_nv: bool,
}

#[doc(hidden)]
pub type RawVkShaderStageFlags = u32;

impl VkWrappedType<RawVkShaderStageFlags> for VkShaderStageFlags {
    fn vk_to_raw(src: &VkShaderStageFlags, dst: &mut RawVkShaderStageFlags) {
        *dst = 0;
        if src.vertex { *dst |= 0x00000001; }
        if src.tessellation_control { *dst |= 0x00000002; }
        if src.tessellation_evaluation { *dst |= 0x00000004; }
        if src.geometry { *dst |= 0x00000008; }
        if src.fragment { *dst |= 0x00000010; }
        if src.compute { *dst |= 0x00000020; }
        if src.all_graphics { *dst |= 0x0000001F; }
        if src.raygen_khr { *dst |= 0x00000100; }
        if src.any_hit_khr { *dst |= 0x00000200; }
        if src.closest_hit_khr { *dst |= 0x00000400; }
        if src.miss_khr { *dst |= 0x00000800; }
        if src.intersection_khr { *dst |= 0x00001000; }
        if src.callable_khr { *dst |= 0x00002000; }
        if src.task_nv { *dst |= 0x00000040; }
        if src.mesh_nv { *dst |= 0x00000080; }
    }
}

impl VkRawType<VkShaderStageFlags> for RawVkShaderStageFlags {
    fn vk_to_wrapped(src: &RawVkShaderStageFlags) -> VkShaderStageFlags {
        VkShaderStageFlags {
            vertex: (src & 0x00000001) != 0,
            tessellation_control: (src & 0x00000002) != 0,
            tessellation_evaluation: (src & 0x00000004) != 0,
            geometry: (src & 0x00000008) != 0,
            fragment: (src & 0x00000010) != 0,
            compute: (src & 0x00000020) != 0,
            all_graphics: (src & 0x0000001F) != 0,
            raygen_khr: (src & 0x00000100) != 0,
            any_hit_khr: (src & 0x00000200) != 0,
            closest_hit_khr: (src & 0x00000400) != 0,
            miss_khr: (src & 0x00000800) != 0,
            intersection_khr: (src & 0x00001000) != 0,
            callable_khr: (src & 0x00002000) != 0,
            task_nv: (src & 0x00000040) != 0,
            mesh_nv: (src & 0x00000080) != 0,
        }
    }
}

impl Default for VkShaderStageFlags {
    fn default() -> VkShaderStageFlags {
        VkShaderStageFlags {
            vertex: false,
            tessellation_control: false,
            tessellation_evaluation: false,
            geometry: false,
            fragment: false,
            compute: false,
            all_graphics: false,
            raygen_khr: false,
            any_hit_khr: false,
            closest_hit_khr: false,
            miss_khr: false,
            intersection_khr: false,
            callable_khr: false,
            task_nv: false,
            mesh_nv: false,
        }
    }
}

impl VkShaderStageFlags {
    
    /// Return a structure with all flags to `false`.
    pub fn none() -> Self {
        VkShaderStageFlags {
            vertex: false,
            tessellation_control: false,
            tessellation_evaluation: false,
            geometry: false,
            fragment: false,
            compute: false,
            all_graphics: false,
            raygen_khr: false,
            any_hit_khr: false,
            closest_hit_khr: false,
            miss_khr: false,
            intersection_khr: false,
            callable_khr: false,
            task_nv: false,
            mesh_nv: false,
        }
    }
    
    /// Return a structure with all flags to `true`.
    pub fn all() -> Self {
        VkShaderStageFlags {
            vertex: true,
            tessellation_control: true,
            tessellation_evaluation: true,
            geometry: true,
            fragment: true,
            compute: true,
            all_graphics: true,
            raygen_khr: true,
            any_hit_khr: true,
            closest_hit_khr: true,
            miss_khr: true,
            intersection_khr: true,
            callable_khr: true,
            task_nv: true,
            mesh_nv: true,
        }
    }
    
    /// Return the numerical bit flags corresponding to the structure (as described in the Vulkan specs).
    pub fn to_u32(&self) -> u32 {
        0
        + if self.vertex { 0x00000001 } else { 0 }
        + if self.tessellation_control { 0x00000002 } else { 0 }
        + if self.tessellation_evaluation { 0x00000004 } else { 0 }
        + if self.geometry { 0x00000008 } else { 0 }
        + if self.fragment { 0x00000010 } else { 0 }
        + if self.compute { 0x00000020 } else { 0 }
        + if self.all_graphics { 0x0000001F } else { 0 }
        + if self.raygen_khr { 0x00000100 } else { 0 }
        + if self.any_hit_khr { 0x00000200 } else { 0 }
        + if self.closest_hit_khr { 0x00000400 } else { 0 }
        + if self.miss_khr { 0x00000800 } else { 0 }
        + if self.intersection_khr { 0x00001000 } else { 0 }
        + if self.callable_khr { 0x00002000 } else { 0 }
        + if self.task_nv { 0x00000040 } else { 0 }
        + if self.mesh_nv { 0x00000080 } else { 0 }
    }
    
    /// Create a structure corresponding to the specified numerical bit flags.
    pub fn from_u32(value: u32) -> Self {
        VkShaderStageFlags {
            vertex: value & 0x00000001 > 0,
            tessellation_control: value & 0x00000002 > 0,
            tessellation_evaluation: value & 0x00000004 > 0,
            geometry: value & 0x00000008 > 0,
            fragment: value & 0x00000010 > 0,
            compute: value & 0x00000020 > 0,
            all_graphics: value & 0x0000001F > 0,
            raygen_khr: value & 0x00000100 > 0,
            any_hit_khr: value & 0x00000200 > 0,
            closest_hit_khr: value & 0x00000400 > 0,
            miss_khr: value & 0x00000800 > 0,
            intersection_khr: value & 0x00001000 > 0,
            callable_khr: value & 0x00002000 > 0,
            task_nv: value & 0x00000040 > 0,
            mesh_nv: value & 0x00000080 > 0,
        }
    }
}

#[doc(hidden)]
#[macro_export]
macro_rules! VkShaderStageFlags {
    ( $( $x:ident ),* ) => {
        VkShaderStageFlags {
            $($x: true,)*
            ..VkShaderStageFlags::none()
        }
    }
}