kronos_compute/core/
flags.rs

1//! Bitflag types for Kronos API
2
3use bitflags::bitflags;
4use crate::sys::VkFlags;
5
6bitflags! {
7    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8    pub struct VkQueueFlags: VkFlags {
9        const COMPUTE = 0x00000002;
10        const TRANSFER = 0x00000004;
11        const SPARSE_BINDING = 0x00000008;
12    }
13}
14
15bitflags! {
16    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
17    pub struct VkMemoryPropertyFlags: VkFlags {
18        const DEVICE_LOCAL = 0x00000001;
19        const HOST_VISIBLE = 0x00000002;
20        const HOST_COHERENT = 0x00000004;
21        const HOST_CACHED = 0x00000008;
22        const LAZILY_ALLOCATED = 0x00000010;
23    }
24}
25
26bitflags! {
27    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
28    pub struct VkBufferUsageFlags: VkFlags {
29        const TRANSFER_SRC = 0x00000001;
30        const TRANSFER_DST = 0x00000002;
31        const UNIFORM_BUFFER = 0x00000010;
32        const STORAGE_BUFFER = 0x00000020;
33        const INDIRECT_BUFFER = 0x00000100;
34    }
35}
36
37bitflags! {
38    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
39    pub struct VkBufferCreateFlags: VkFlags {
40        const SPARSE_BINDING = 0x00000001;
41        const SPARSE_RESIDENCY = 0x00000002;
42        const SPARSE_ALIASED = 0x00000004;
43    }
44}
45
46bitflags! {
47    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
48    pub struct VkCommandBufferUsageFlags: VkFlags {
49        const ONE_TIME_SUBMIT = 0x00000001;
50        const RENDER_PASS_CONTINUE = 0x00000002;
51        const SIMULTANEOUS_USE = 0x00000004;
52    }
53}
54
55bitflags! {
56    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
57    pub struct VkCommandPoolCreateFlags: VkFlags {
58        const TRANSIENT = 0x00000001;
59        const RESET_COMMAND_BUFFER = 0x00000002;
60    }
61}
62
63bitflags! {
64    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
65    pub struct VkShaderStageFlags: VkFlags {
66        const COMPUTE = 0x00000020;
67        const ALL = 0x7FFFFFFF;
68    }
69}
70
71bitflags! {
72    #[repr(transparent)]
73    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
74    pub struct VkPipelineStageFlags: VkFlags {
75        const TOP_OF_PIPE = 0x00000001;
76        const COMPUTE_SHADER = 0x00000800;
77        const BOTTOM_OF_PIPE = 0x00002000;
78        const HOST = 0x00004000;
79        const ALL_COMMANDS = 0x00010000;
80    }
81}
82
83bitflags! {
84    #[repr(transparent)]
85    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
86    pub struct VkAccessFlags: VkFlags {
87        const INDIRECT_COMMAND_READ = 0x00000001;
88        const UNIFORM_READ = 0x00000008;
89        const SHADER_READ = 0x00000020;
90        const SHADER_WRITE = 0x00000040;
91        const TRANSFER_READ = 0x00000800;
92        const TRANSFER_WRITE = 0x00001000;
93        const HOST_READ = 0x00002000;
94        const HOST_WRITE = 0x00004000;
95        const MEMORY_READ = 0x00008000;
96        const MEMORY_WRITE = 0x00010000;
97    }
98}
99
100bitflags! {
101    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
102    pub struct VkPipelineCreateFlags: VkFlags {
103        const DISABLE_OPTIMIZATION = 0x00000001;
104        const ALLOW_DERIVATIVES = 0x00000002;
105        const DERIVATIVE = 0x00000004;
106    }
107}
108
109bitflags! {
110    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
111    pub struct VkDescriptorPoolCreateFlags: VkFlags {
112        const FREE_DESCRIPTOR_SET = 0x00000001;
113        const UPDATE_AFTER_BIND = 0x00000002;
114    }
115}
116
117bitflags! {
118    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
119    pub struct VkDescriptorPoolResetFlags: VkFlags {
120        // Reserved for future use
121        const RESERVED = 0;
122    }
123}
124
125bitflags! {
126    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
127    pub struct VkFenceCreateFlags: VkFlags {
128        const SIGNALED = 0x00000001;
129    }
130}
131
132bitflags! {
133    #[repr(transparent)]
134    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
135    pub struct VkDependencyFlags: VkFlags {
136        const BY_REGION = 0x00000001;
137    }
138}
139
140bitflags! {
141    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
142    pub struct VkSemaphoreWaitFlags: VkFlags {
143        const ANY = 0x00000001;
144    }
145}
146
147bitflags! {
148    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
149    pub struct VkPipelineShaderStageCreateFlags: VkFlags {
150        // Reserved for future use
151        const RESERVED = 0;
152    }
153}
154
155// Type aliases for flags that don't have specific bits
156pub type VkInstanceCreateFlags = VkFlags;
157pub type VkDeviceCreateFlags = VkFlags;
158pub type VkDeviceQueueCreateFlags = VkFlags;
159pub type VkMemoryMapFlags = VkFlags;
160pub type VkSemaphoreCreateFlags = VkFlags;
161pub type VkEventCreateFlags = VkFlags;
162pub type VkQueryPoolCreateFlags = VkFlags;
163pub type VkPipelineLayoutCreateFlags = VkFlags;
164pub type VkDescriptorSetLayoutCreateFlags = VkFlags;
165
166#[cfg(test)]
167mod tests {
168    use super::*;
169    
170    #[test]
171    fn test_queue_flags() {
172        let compute_transfer = VkQueueFlags::COMPUTE | VkQueueFlags::TRANSFER;
173        assert!(compute_transfer.contains(VkQueueFlags::COMPUTE));
174        assert!(compute_transfer.contains(VkQueueFlags::TRANSFER));
175        assert!(!compute_transfer.contains(VkQueueFlags::SPARSE_BINDING));
176        
177        let all = VkQueueFlags::all();
178        assert!(all.contains(VkQueueFlags::COMPUTE));
179        assert!(all.contains(VkQueueFlags::TRANSFER));
180        assert!(all.contains(VkQueueFlags::SPARSE_BINDING));
181    }
182    
183    #[test]
184    fn test_memory_property_flags() {
185        let host_visible = VkMemoryPropertyFlags::HOST_VISIBLE | VkMemoryPropertyFlags::HOST_COHERENT;
186        assert!(host_visible.contains(VkMemoryPropertyFlags::HOST_VISIBLE));
187        assert!(host_visible.contains(VkMemoryPropertyFlags::HOST_COHERENT));
188        assert!(!host_visible.contains(VkMemoryPropertyFlags::DEVICE_LOCAL));
189        
190        assert!(VkMemoryPropertyFlags::empty().is_empty());
191    }
192    
193    #[test]
194    fn test_buffer_usage_flags() {
195        let storage_transfer = VkBufferUsageFlags::STORAGE_BUFFER | VkBufferUsageFlags::TRANSFER_DST;
196        assert!(storage_transfer.contains(VkBufferUsageFlags::STORAGE_BUFFER));
197        assert!(storage_transfer.contains(VkBufferUsageFlags::TRANSFER_DST));
198        assert!(!storage_transfer.contains(VkBufferUsageFlags::UNIFORM_BUFFER));
199        
200        // Test intersection
201        let transfer_only = VkBufferUsageFlags::TRANSFER_SRC | VkBufferUsageFlags::TRANSFER_DST;
202        let intersection = storage_transfer & transfer_only;
203        assert_eq!(intersection, VkBufferUsageFlags::TRANSFER_DST);
204    }
205    
206    #[test]
207    fn test_pipeline_stage_flags() {
208        let compute_stage = VkPipelineStageFlags::COMPUTE_SHADER;
209        assert!(compute_stage.contains(VkPipelineStageFlags::COMPUTE_SHADER));
210        assert!(!compute_stage.contains(VkPipelineStageFlags::HOST));
211        
212        let all_commands = VkPipelineStageFlags::ALL_COMMANDS;
213        assert!(!all_commands.is_empty());
214    }
215    
216    #[test]
217    fn test_access_flags() {
218        let shader_access = VkAccessFlags::SHADER_READ | VkAccessFlags::SHADER_WRITE;
219        assert!(shader_access.contains(VkAccessFlags::SHADER_READ));
220        assert!(shader_access.contains(VkAccessFlags::SHADER_WRITE));
221        assert!(!shader_access.contains(VkAccessFlags::HOST_READ));
222        
223        // Test removal
224        let read_only = shader_access - VkAccessFlags::SHADER_WRITE;
225        assert_eq!(read_only, VkAccessFlags::SHADER_READ);
226    }
227    
228    #[test]
229    fn test_shader_stage_flags() {
230        let compute = VkShaderStageFlags::COMPUTE;
231        assert!(compute.contains(VkShaderStageFlags::COMPUTE));
232        assert!(!compute.contains(VkShaderStageFlags::ALL));
233        
234        let all = VkShaderStageFlags::ALL;
235        assert!(all.contains(VkShaderStageFlags::COMPUTE));
236    }
237    
238    #[test]
239    fn test_fence_create_flags() {
240        let signaled = VkFenceCreateFlags::SIGNALED;
241        assert!(!signaled.is_empty());
242        assert!(signaled.contains(VkFenceCreateFlags::SIGNALED));
243        
244        let empty = VkFenceCreateFlags::empty();
245        assert!(empty.is_empty());
246    }
247}