1#[allow(unused)]
11pub(crate) use self::pipeline::*;
12pub use self::{
13 future::{now, GpuFuture},
14 pipeline::{
15 AccessFlags, BufferMemoryBarrier, DependencyFlags, DependencyInfo, ImageMemoryBarrier,
16 MemoryBarrier, PipelineStage, PipelineStages, QueueFamilyOwnershipTransfer,
17 },
18};
19use crate::{device::Queue, VulkanError};
20use smallvec::SmallVec;
21use std::{
22 error::Error,
23 fmt::{Display, Formatter},
24 sync::Arc,
25};
26
27pub mod event;
28pub mod fence;
29pub mod future;
30mod pipeline;
31pub mod semaphore;
32
33#[derive(Debug, Clone, PartialEq, Eq)]
39pub enum SharingMode {
41 Exclusive,
43 Concurrent(Vec<u32>), }
46
47impl<'a> From<&'a Arc<Queue>> for SharingMode {
48 #[inline]
49 fn from(_queue: &'a Arc<Queue>) -> SharingMode {
50 SharingMode::Exclusive
51 }
52}
53
54impl<'a> From<&'a [&'a Arc<Queue>]> for SharingMode {
55 #[inline]
56 fn from(queues: &'a [&'a Arc<Queue>]) -> SharingMode {
57 SharingMode::Concurrent(
58 queues
59 .iter()
60 .map(|queue| queue.queue_family_index())
61 .collect(),
62 )
63 }
64}
65
66#[derive(Debug, Clone, PartialEq, Eq, Hash)]
68pub enum Sharing<I>
69where
70 I: IntoIterator<Item = u32>,
71{
72 Exclusive,
74 Concurrent(I),
76}
77
78impl Sharing<SmallVec<[u32; 4]>> {
79 #[inline]
81 pub fn is_exclusive(&self) -> bool {
82 matches!(self, Self::Exclusive)
83 }
84
85 #[inline]
87 pub fn is_concurrent(&self) -> bool {
88 matches!(self, Self::Concurrent(..))
89 }
90
91 pub(crate) fn to_vk(&self) -> (ash::vk::SharingMode, &[u32]) {
92 match self {
93 Sharing::Exclusive => (ash::vk::SharingMode::EXCLUSIVE, [].as_slice()),
94 Sharing::Concurrent(queue_family_indices) => (
95 ash::vk::SharingMode::CONCURRENT,
96 queue_family_indices.as_slice(),
97 ),
98 }
99 }
100}
101
102#[derive(Clone, Copy, Debug, PartialEq, Eq)]
104pub(crate) enum CurrentAccess {
105 CpuExclusive,
107
108 GpuExclusive { gpu_reads: usize, gpu_writes: usize },
113
114 Shared { cpu_reads: usize, gpu_reads: usize },
116}
117
118#[derive(Clone, Debug)]
120pub enum HostAccessError {
121 AccessConflict(AccessConflict),
122 Invalidate(VulkanError),
123 Unmanaged,
124 NotHostMapped,
125 OutOfMappedRange,
126}
127
128impl Error for HostAccessError {
129 fn source(&self) -> Option<&(dyn Error + 'static)> {
130 match self {
131 Self::AccessConflict(err) => Some(err),
132 Self::Invalidate(err) => Some(err),
133 _ => None,
134 }
135 }
136}
137
138impl Display for HostAccessError {
139 fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
140 match self {
141 Self::AccessConflict(_) => {
142 write!(f, "the resource is already in use in a conflicting way")
143 }
144 Self::Unmanaged => write!(f, "the resource is not managed by vulkano"),
145 HostAccessError::Invalidate(_) => write!(f, "invalidating the device memory failed"),
146 HostAccessError::NotHostMapped => {
147 write!(f, "the device memory is not current host-mapped")
148 }
149 HostAccessError::OutOfMappedRange => write!(
150 f,
151 "the requested range is not within the currently mapped range of device memory",
152 ),
153 }
154 }
155}
156
157#[derive(Clone, Debug, PartialEq, Eq)]
159pub enum AccessConflict {
160 HostRead,
162
163 HostWrite,
165
166 DeviceRead,
168
169 DeviceWrite,
171}
172
173impl Error for AccessConflict {}
174
175impl Display for AccessConflict {
176 fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
177 match self {
178 AccessConflict::HostRead => write!(
179 f,
180 "the resource is already locked for reading by the host (CPU)"
181 ),
182 AccessConflict::HostWrite => write!(
183 f,
184 "the resource is already locked for writing by the host (CPU)"
185 ),
186 AccessConflict::DeviceRead => write!(
187 f,
188 "the resource is already locked for reading by the device (GPU)"
189 ),
190 AccessConflict::DeviceWrite => write!(
191 f,
192 "the resource is already locked for writing by the device (GPU)"
193 ),
194 }
195 }
196}