spirv_std/memory.rs
1//! Types for handling memory ordering constraints for concurrent memory access.
2
3// NOTE(eddyb) "&-masking with zero", likely due to `NONE = 0` in `bitflags!`.
4#![allow(clippy::bad_bit_mask)]
5
6/// Specification for how large of a scope some instructions should operate on - used when calling
7/// functions that take a configurable scope.
8#[derive(Debug, PartialEq, Eq)]
9pub enum Scope {
10 /// Crosses multiple devices.
11 CrossDevice = 0,
12
13 /// The current device.
14 Device = 1,
15
16 /// The current workgroup.
17 Workgroup = 2,
18
19 /// The current subgroup.
20 Subgroup = 3,
21
22 /// The current invocation.
23 Invocation = 4,
24
25 /// The current queue family.
26 QueueFamily = 5,
27}
28
29bitflags::bitflags! {
30 /// Memory semantics to determine how some operations should function - used when calling such
31 /// configurable operations.
32 #[repr(transparent)]
33 #[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
34 #[cfg_attr(feature = "bytemuck", derive(bytemuck::Zeroable, bytemuck::Pod))]
35 pub struct Semantics: u32 {
36 /// No memory semantics.
37 const NONE = 0;
38
39 /// On an atomic instruction, orders memory operations provided in program
40 /// order after this atomic instruction against this atomic instruction. On
41 /// a barrier, orders memory operations provided in program order after this
42 /// barrier against atomic instructions before this barrier.
43 const ACQUIRE = 0x2;
44
45 /// On an atomic instruction, orders memory operations provided in program
46 /// order before this atomic instruction against this atomic instruction. On
47 /// a barrier, orders memory operations provided in program order before
48 /// this barrier against atomic instructions after this barrier.
49 const RELEASE = 0x4;
50
51 /// Has the properties of both [`Self::ACQUIRE`] and [`Self::RELEASE`] semantics. It
52 /// is used for read-modify-write operations.
53 const ACQUIRE_RELEASE = 0x8;
54
55 /// All observers see this memory access in the same order with respect to
56 /// other sequentially-consistent memory accesses from this invocation.
57 /// If the declared memory model is `vulkan`, `SEQUENTIALLY_CONST` must
58 /// not be used.
59 const SEQUENTIALLY_CONST = 0x10;
60
61 /// Apply the memory-ordering constraints to
62 /// [`crate::storage_class::StorageBuffer`],
63 /// [`crate::storage_class::PhysicalStorageBuffer`], or
64 /// [`crate::storage_class::Uniform`] Storage Class memory.
65 const UNIFORM_MEMORY = 0x40;
66
67 /// Apply the memory-ordering constraints to subgroup memory.
68 const SUBGROUP_MEMORY = 0x80;
69
70 /// Apply the memory-ordering constraints to
71 /// [`crate::storage_class::Workgroup`] Storage Class memory.
72 const WORKGROUP_MEMORY = 0x100;
73
74 /// Apply the memory-ordering constraints to
75 /// [`crate::storage_class::CrossWorkgroup`] Storage Class memory.
76 const CROSS_WORKGROUP_MEMORY = 0x200;
77
78 /// Apply the memory-ordering constraints to
79 /// [`crate::storage_class::AtomicCounter`] Storage Class memory.
80 const ATOMIC_COUNTER_MEMORY = 0x400;
81
82 /// Apply the memory-ordering constraints to image contents (types declared
83 /// by `OpTypeImage`), or to accesses done through pointers to the
84 /// [`crate::storage_class::Image`] Storage Class.
85 const IMAGE_MEMORY = 0x800;
86
87 /// Apply the memory-ordering constraints to the
88 /// [`crate::storage_class::Output`] Storage Class memory.
89 const OUTPUT_MEMORY = 0x1000;
90
91 /// Perform an availability operation on all references in the selected
92 /// storage classes.
93 const MAKE_AVAILABLE = 0x2000;
94
95 /// Perform a visibility operation on all references in the selected
96 /// storage classes.
97 const MAKE_VISIBLE = 0x4000;
98
99 /// This access cannot be eliminated, duplicated, or combined with
100 /// other accesses.
101 const VOLATILE = 0x8000;
102 }
103}
104
105#[cfg(all(test, feature = "bytemuck"))]
106mod test_bytemuck {
107 fn is_pod<T: bytemuck::Pod>() {}
108
109 #[test]
110 fn test() {
111 is_pod::<crate::memory::Semantics>();
112 is_pod::<crate::ray_tracing::RayFlags>();
113 }
114}