rendy_command/
capability.rs1pub use rendy_core::hal::queue::QueueType;
4
5#[derive(Clone, Copy, Debug)]
7pub struct Transfer;
8
9#[derive(Clone, Copy, Debug)]
11pub struct Execute;
12
13#[derive(Clone, Copy, Debug)]
15pub struct Compute;
16
17#[derive(Clone, Copy, Debug)]
19pub struct Graphics;
20
21#[derive(Clone, Copy, Debug)]
23pub struct General;
24
25pub trait Capability: Copy + std::fmt::Debug + 'static {
27 fn from_queue_type(queue_type: QueueType) -> Option<Self>;
30
31 fn into_queue_type(self) -> QueueType;
33}
34
35impl Capability for QueueType {
36 fn from_queue_type(queue_type: QueueType) -> Option<Self> {
37 Some(queue_type)
38 }
39
40 fn into_queue_type(self) -> QueueType {
41 self
42 }
43}
44
45impl Capability for Transfer {
46 fn from_queue_type(_queue_type: QueueType) -> Option<Self> {
47 Some(Transfer)
48 }
49
50 fn into_queue_type(self) -> QueueType {
51 QueueType::Transfer
52 }
53}
54
55impl Capability for Execute {
56 fn from_queue_type(queue_type: QueueType) -> Option<Self> {
57 match queue_type {
58 QueueType::Transfer => None,
59 _ => Some(Execute),
60 }
61 }
62
63 fn into_queue_type(self) -> QueueType {
64 QueueType::General
65 }
66}
67
68impl Capability for Compute {
69 fn from_queue_type(queue_type: QueueType) -> Option<Self> {
70 match queue_type {
71 QueueType::Compute | QueueType::General => Some(Compute),
72 _ => None,
73 }
74 }
75
76 fn into_queue_type(self) -> QueueType {
77 QueueType::Compute
78 }
79}
80
81impl Capability for Graphics {
82 fn from_queue_type(queue_type: QueueType) -> Option<Self> {
83 match queue_type {
84 QueueType::Graphics | QueueType::General => Some(Graphics),
85 _ => None,
86 }
87 }
88
89 fn into_queue_type(self) -> QueueType {
90 QueueType::Graphics
91 }
92}
93
94impl Capability for General {
95 fn from_queue_type(queue_type: QueueType) -> Option<Self> {
96 match queue_type {
97 QueueType::General => Some(General),
98 _ => None,
99 }
100 }
101
102 fn into_queue_type(self) -> QueueType {
103 QueueType::General
104 }
105}
106
107pub trait Supports<C>: Capability {
109 fn supports(&self) -> Option<C>;
111
112 fn assert(&self) {
114 assert!(self.supports().is_some());
115 }
116}
117
118impl Supports<Transfer> for Transfer {
119 fn supports(&self) -> Option<Transfer> {
120 Some(Transfer)
121 }
122}
123
124impl Supports<Transfer> for Compute {
125 fn supports(&self) -> Option<Transfer> {
126 Some(Transfer)
127 }
128}
129
130impl Supports<Transfer> for Graphics {
131 fn supports(&self) -> Option<Transfer> {
132 Some(Transfer)
133 }
134}
135
136impl Supports<Transfer> for General {
137 fn supports(&self) -> Option<Transfer> {
138 Some(Transfer)
139 }
140}
141
142impl Supports<Execute> for Compute {
143 fn supports(&self) -> Option<Execute> {
144 Some(Execute)
145 }
146}
147
148impl Supports<Execute> for Graphics {
149 fn supports(&self) -> Option<Execute> {
150 Some(Execute)
151 }
152}
153
154impl Supports<Execute> for General {
155 fn supports(&self) -> Option<Execute> {
156 Some(Execute)
157 }
158}
159
160impl Supports<Compute> for Compute {
161 fn supports(&self) -> Option<Compute> {
162 Some(Compute)
163 }
164}
165
166impl Supports<Compute> for General {
167 fn supports(&self) -> Option<Compute> {
168 Some(Compute)
169 }
170}
171
172impl Supports<Graphics> for Graphics {
173 fn supports(&self) -> Option<Graphics> {
174 Some(Graphics)
175 }
176}
177
178impl Supports<Graphics> for General {
179 fn supports(&self) -> Option<Graphics> {
180 Some(Graphics)
181 }
182}
183
184impl<C> Supports<C> for QueueType
185where
186 C: Capability,
187{
188 fn supports(&self) -> Option<C> {
189 C::from_queue_type(*self)
190 }
191}