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
#[cfg(feature = "rafx-metal")]
use crate::metal::RafxQueueMetal;
#[cfg(feature = "rafx-vulkan")]
use crate::vulkan::RafxQueueVulkan;
use crate::{
RafxCommandBuffer, RafxCommandPool, RafxCommandPoolDef, RafxFence, RafxPresentSuccessResult,
RafxQueueType, RafxResult, RafxSemaphore, RafxSwapchain,
};
#[derive(Clone, Debug)]
pub enum RafxQueue {
#[cfg(feature = "rafx-vulkan")]
Vk(RafxQueueVulkan),
#[cfg(feature = "rafx-metal")]
Metal(RafxQueueMetal),
}
impl RafxQueue {
pub fn queue_id(&self) -> u32 {
match self {
#[cfg(feature = "rafx-vulkan")]
RafxQueue::Vk(inner) => inner.queue_id(),
#[cfg(feature = "rafx-metal")]
RafxQueue::Metal(inner) => unimplemented!(),
}
}
pub fn queue_type(&self) -> RafxQueueType {
match self {
#[cfg(feature = "rafx-vulkan")]
RafxQueue::Vk(inner) => inner.queue_type(),
#[cfg(feature = "rafx-metal")]
RafxQueue::Metal(inner) => inner.queue_type(),
}
}
pub fn create_command_pool(
&self,
command_pool_def: &RafxCommandPoolDef,
) -> RafxResult<RafxCommandPool> {
Ok(match self {
#[cfg(feature = "rafx-vulkan")]
RafxQueue::Vk(inner) => {
RafxCommandPool::Vk(inner.create_command_pool(command_pool_def)?)
}
#[cfg(feature = "rafx-metal")]
RafxQueue::Metal(_inner) => unimplemented!(),
})
}
pub fn submit(
&self,
command_buffers: &[&RafxCommandBuffer],
wait_semaphores: &[&RafxSemaphore],
signal_semaphores: &[&RafxSemaphore],
signal_fence: Option<&RafxFence>,
) -> RafxResult<()> {
match self {
#[cfg(feature = "rafx-vulkan")]
RafxQueue::Vk(inner) => {
let command_buffers: Vec<_> = command_buffers
.iter()
.map(|x| x.vk_command_buffer().unwrap())
.collect();
let wait_semaphores: Vec<_> = wait_semaphores
.iter()
.map(|x| x.vk_semaphore().unwrap())
.collect();
let signal_semaphores: Vec<_> = signal_semaphores
.iter()
.map(|x| x.vk_semaphore().unwrap())
.collect();
inner.submit(
&command_buffers,
&wait_semaphores,
&signal_semaphores,
signal_fence.map(|x| x.vk_fence().unwrap()),
)
}
#[cfg(feature = "rafx-metal")]
RafxQueue::Metal(_inner) => unimplemented!(),
}
}
pub fn present(
&self,
swapchain: &RafxSwapchain,
wait_semaphores: &[&RafxSemaphore],
image_index: u32,
) -> RafxResult<RafxPresentSuccessResult> {
match self {
#[cfg(feature = "rafx-vulkan")]
RafxQueue::Vk(inner) => {
let wait_semaphores: Vec<_> = wait_semaphores
.iter()
.map(|x| x.vk_semaphore().unwrap())
.collect();
inner.present(
swapchain.vk_swapchain().unwrap(),
&wait_semaphores,
image_index,
)
}
#[cfg(feature = "rafx-metal")]
RafxQueue::Metal(_inner) => unimplemented!(),
}
}
pub fn wait_for_queue_idle(&self) -> RafxResult<()> {
match self {
#[cfg(feature = "rafx-vulkan")]
RafxQueue::Vk(inner) => inner.wait_for_queue_idle(),
#[cfg(feature = "rafx-metal")]
RafxQueue::Metal(_inner) => unimplemented!(),
}
}
#[cfg(feature = "rafx-vulkan")]
pub fn vk_queue(&self) -> Option<&RafxQueueVulkan> {
match self {
#[cfg(feature = "rafx-vulkan")]
RafxQueue::Vk(inner) => Some(inner),
#[cfg(feature = "rafx-metal")]
RafxQueue::Metal(_inner) => None,
}
}
#[cfg(feature = "rafx-metal")]
pub fn metal_queue(&self) -> Option<&RafxQueueMetal> {
match self {
#[cfg(feature = "rafx-vulkan")]
RafxQueue::Vk(_inner) => None,
#[cfg(feature = "rafx-metal")]
RafxQueue::Metal(inner) => Some(inner),
}
}
}