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
pub mod capability;
pub mod family;
use std::iter;
use std::any::Any;
use std::borrow::Borrow;
use std::marker::PhantomData;
use command::{Primary, Submittable};
use error::HostExecutionError;
use pso;
use window::SwapImageIndex;
use Backend;
pub use self::capability::{
Capability, Supports,
Compute, Graphics, General, Transfer,
};
pub use self::family::{
QueueFamily, QueueFamilyId, QueueGroup, Queues,
};
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum QueueType {
General,
Graphics,
Compute,
Transfer,
}
pub struct Submission<Ic, Iw, Is> {
pub command_buffers: Ic,
pub wait_semaphores: Iw,
pub signal_semaphores: Is,
}
pub trait RawCommandQueue<B: Backend>: Any + Send + Sync {
unsafe fn submit<'a, T, Ic, S, Iw, Is>(
&mut self, submission: Submission<Ic, Iw, Is>, fence: Option<&B::Fence>
) where
T: 'a + Borrow<B::CommandBuffer>,
Ic: IntoIterator<Item = &'a T>,
S: 'a + Borrow<B::Semaphore>,
Iw: IntoIterator<Item = (&'a S, pso::PipelineStage)>,
Is: IntoIterator<Item = &'a S>;
unsafe fn present<'a, W, Is, S, Iw>(&mut self, swapchains: Is, wait_semaphores: Iw) -> Result<(), ()>
where
Self: Sized,
W: 'a + Borrow<B::Swapchain>,
Is: IntoIterator<Item = (&'a W, SwapImageIndex)>,
S: 'a + Borrow<B::Semaphore>,
Iw: IntoIterator<Item = &'a S>;
fn wait_idle(&self) -> Result<(), HostExecutionError>;
}
pub struct CommandQueue<B: Backend, C>(B::CommandQueue, PhantomData<C>);
impl<B: Backend, C: Capability> CommandQueue<B, C> {
pub unsafe fn new(raw: B::CommandQueue) -> Self {
CommandQueue(raw, PhantomData)
}
pub fn as_raw(&self) -> &B::CommandQueue {
&self.0
}
pub unsafe fn as_raw_mut(&mut self) -> &mut B::CommandQueue {
&mut self.0
}
pub fn into_raw(self) -> B::CommandQueue {
self.0
}
pub unsafe fn submit<'a, T, Ic, S, Iw, Is>(&mut self,
submission: Submission<Ic, Iw, Is>,
fence: Option<&B::Fence>,
) where
T: 'a + Submittable<B, C, Primary>,
Ic: IntoIterator<Item = &'a T>,
S: 'a + Borrow<B::Semaphore>,
Iw: IntoIterator<Item = (&'a S, pso::PipelineStage)>,
Is: IntoIterator<Item = &'a S>,
{
self.0.submit(submission, fence)
}
pub unsafe fn submit_nosemaphores<'a, T, I>(
&mut self, command_buffers: I, fence: Option<&B::Fence>
) where
T: 'a + Submittable<B, C, Primary>,
I: IntoIterator<Item = &'a T>
{
let submission = Submission {
command_buffers,
wait_semaphores: iter::empty(),
signal_semaphores: iter::empty(),
};
self.submit::<_, _, B::Semaphore, _, _>(submission, fence)
}
pub unsafe fn present<'a, W, Is, S, Iw>(&mut self, swapchains: Is, wait_semaphores: Iw) -> Result<(), ()>
where
W: 'a + Borrow<B::Swapchain>,
Is: IntoIterator<Item = (&'a W, SwapImageIndex)>,
S: 'a + Borrow<B::Semaphore>,
Iw: IntoIterator<Item = &'a S>,
{
self.0.present(swapchains, wait_semaphores)
}
pub fn wait_idle(&self) -> Result<(), HostExecutionError> {
self.0.wait_idle()
}
pub unsafe fn downgrade<D>(&mut self) -> &mut CommandQueue<B, D>
where
C: Supports<D>,
{
::std::mem::transmute(self)
}
}