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    #[cfg_attr(feature = "bytemuck", derive(bytemuck::Zeroable, bytemuck::Pod))]
34    pub struct Semantics: u32 {
35        /// No memory semantics.
36        const NONE = 0;
37
38        /// On an atomic instruction, orders memory operations provided in program
39        /// order after this atomic instruction against this atomic instruction. On
40        /// a barrier, orders memory operations provided in program order after this
41        /// barrier against atomic instructions before this barrier.
42        const ACQUIRE = 0x2;
43
44        /// On an atomic instruction, orders memory operations provided in program
45        /// order before this atomic instruction against this atomic instruction. On
46        /// a barrier, orders memory operations provided in program order before
47        /// this barrier against atomic instructions after this barrier.
48        const RELEASE = 0x4;
49
50        /// Has the properties of both [`Self::ACQUIRE`] and [`Self::RELEASE`] semantics. It
51        /// is used for read-modify-write operations.
52        const ACQUIRE_RELEASE = 0x8;
53
54        /// All observers see this memory access in the same order with respect to
55        /// other sequentially-consistent memory accesses from this invocation.
56        /// If the declared memory model is `vulkan`, `SEQUENTIALLY_CONST` must
57        /// not be used.
58        const SEQUENTIALLY_CONST = 0x10;
59
60        /// Apply the memory-ordering constraints to
61        /// [`crate::storage_class::StorageBuffer`],
62        /// [`crate::storage_class::PhysicalStorageBuffer`], or
63        /// [`crate::storage_class::Uniform`] Storage Class memory.
64        const UNIFORM_MEMORY = 0x40;
65
66        /// Apply the memory-ordering constraints to subgroup memory.
67        const SUBGROUP_MEMORY = 0x80;
68
69        /// Apply the memory-ordering constraints to
70        /// [`crate::storage_class::Workgroup`] Storage Class memory.
71        const WORKGROUP_MEMORY = 0x100;
72
73        /// Apply the memory-ordering constraints to
74        /// [`crate::storage_class::CrossWorkgroup`] Storage Class memory.
75        const CROSS_WORKGROUP_MEMORY = 0x200;
76
77        /// Apply the memory-ordering constraints to
78        /// [`crate::storage_class::AtomicCounter`] Storage Class memory.
79        const ATOMIC_COUNTER_MEMORY = 0x400;
80
81        /// Apply the memory-ordering constraints to image contents (types declared
82        /// by `OpTypeImage`), or to accesses done through pointers to the
83        /// [`crate::storage_class::Image`] Storage Class.
84        const IMAGE_MEMORY = 0x800;
85
86        /// Apply the memory-ordering constraints to the
87        /// [`crate::storage_class::Output`] Storage Class memory.
88        const OUTPUT_MEMORY = 0x1000;
89
90        /// Perform an availability operation on all references in the selected
91        /// storage classes.
92        const MAKE_AVAILABLE = 0x2000;
93
94        /// Perform a visibility operation on all references in the selected
95        /// storage classes.
96        const MAKE_VISIBLE = 0x4000;
97
98        /// This access cannot be eliminated, duplicated, or combined with
99        /// other accesses.
100        const VOLATILE = 0x8000;
101    }
102}