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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
use Backend;
use queue::capability::{Capability, Supports};
use std::borrow::Borrow;
use std::marker::PhantomData;
mod compute;
mod graphics;
mod raw;
mod render_pass;
mod transfer;
pub use self::graphics::*;
pub use self::raw::{
ClearValueRaw, ClearColorRaw, ClearDepthStencilRaw, DescriptorSetOffset,
RawCommandBuffer, CommandBufferFlags, Level as RawLevel, CommandBufferInheritanceInfo,
};
pub use self::render_pass::*;
pub use self::transfer::*;
pub trait Shot {}
pub enum OneShot { }
impl Shot for OneShot {}
pub enum MultiShot { }
impl Shot for MultiShot {}
pub trait Level { }
pub enum Primary { }
impl Level for Primary { }
pub enum Secondary { }
impl Level for Secondary { }
pub trait Submittable<B: Backend, C: Capability, L: Level>: Borrow<B::CommandBuffer> {}
pub type SecondaryCommandBuffer<B, C, S = OneShot> = CommandBuffer<B, C, S, Secondary>;
pub struct CommandBuffer<B: Backend, C, S = OneShot, L = Primary, R = <B as Backend>::CommandBuffer> {
pub(crate) raw: R,
pub(crate) _marker: PhantomData<(B, C, S, L)>
}
impl<B, C, S, L, R> Borrow<R> for CommandBuffer<B, C, S, L, R>
where
R: RawCommandBuffer<B>,
B: Backend<CommandBuffer = R>
{
fn borrow(&self) -> &B::CommandBuffer {
&self.raw
}
}
impl<B: Backend, C, K: Capability + Supports<C>, S, L: Level> Submittable<B, K, L> for CommandBuffer<B, C, S, L> {}
impl<B: Backend, C> CommandBuffer<B, C, OneShot, Primary> {
pub unsafe fn begin(&mut self) {
let flags = CommandBufferFlags::ONE_TIME_SUBMIT;
self.raw.begin(flags, CommandBufferInheritanceInfo::default());
}
}
impl<B: Backend, C> CommandBuffer<B, C, MultiShot, Primary> {
pub unsafe fn begin(
&mut self,
allow_pending_resubmit: bool,
) {
let flags = if allow_pending_resubmit {
CommandBufferFlags::SIMULTANEOUS_USE
} else {
CommandBufferFlags::empty()
};
self.raw.begin(flags, CommandBufferInheritanceInfo::default());
}
}
impl<B: Backend, C> CommandBuffer<B, C, OneShot, Secondary> {
pub unsafe fn begin(
&mut self,
inheritance: CommandBufferInheritanceInfo<B>,
) {
let flags = CommandBufferFlags::ONE_TIME_SUBMIT;
self.raw.begin(flags, inheritance);
}
}
impl<B: Backend, C> CommandBuffer<B, C, MultiShot, Secondary> {
pub unsafe fn begin(
&mut self,
allow_pending_resubmit: bool,
inheritance: CommandBufferInheritanceInfo<B>,
) {
let flags = if allow_pending_resubmit {
CommandBufferFlags::SIMULTANEOUS_USE
} else {
CommandBufferFlags::empty()
};
self.raw.begin(flags, inheritance);
}
}
impl<B: Backend, C, S: Shot, L: Level> CommandBuffer<B, C, S, L> {
pub unsafe fn new(raw: B::CommandBuffer) -> Self {
CommandBuffer {
raw,
_marker: PhantomData,
}
}
pub unsafe fn finish(&mut self) {
self.raw.finish();
}
pub unsafe fn downgrade<D>(&mut self) -> &mut CommandBuffer<B, D, S>
where
C: Supports<D>
{
::std::mem::transmute(self)
}
}
impl<B: Backend, C, S: Shot> CommandBuffer<B, C, S, Primary> {
pub unsafe fn execute_commands<'a, I, T, K>(&mut self, cmd_buffers: I)
where
K: Capability,
T: 'a + Submittable<B, K, Secondary>,
I: IntoIterator<Item = &'a T>,
C: Supports<K>,
{
self.raw.execute_commands(cmd_buffers.into_iter().map(|cmb| cmb.borrow()));
}
}