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
use crate::backend::RawQueueGroup;
use crate::queue::capability::{Capability, Compute, Graphics, Transfer};
use crate::queue::{CommandQueue, QueueType};
use crate::Backend;
use std::any::Any;
use std::fmt::Debug;
pub trait QueueFamily: Debug + Any + Send + Sync {
fn queue_type(&self) -> QueueType;
fn max_queues(&self) -> usize;
fn supports_graphics(&self) -> bool {
Graphics::supported_by(self.queue_type())
}
fn supports_compute(&self) -> bool {
Compute::supported_by(self.queue_type())
}
fn supports_transfer(&self) -> bool {
Transfer::supported_by(self.queue_type())
}
fn id(&self) -> QueueFamilyId;
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct QueueFamilyId(pub usize);
#[derive(Debug)]
pub struct QueueGroup<B: Backend, C> {
family: QueueFamilyId,
pub queues: Vec<CommandQueue<B, C>>,
}
impl<B: Backend, C> QueueGroup<B, C> {
pub fn family(&self) -> QueueFamilyId {
self.family
}
}
impl<B: Backend, C: Capability> QueueGroup<B, C> {
fn new(raw: RawQueueGroup<B>) -> Self {
assert!(C::supported_by(raw.family.queue_type()));
QueueGroup {
family: raw.family.id(),
queues: raw
.queues
.into_iter()
.map(|q| unsafe { CommandQueue::new(q) })
.collect(),
}
}
}
#[derive(Debug)]
pub struct Queues<B: Backend>(pub(crate) Vec<RawQueueGroup<B>>);
impl<B: Backend> Queues<B> {
pub fn take<C: Capability>(&mut self, id: QueueFamilyId) -> Option<QueueGroup<B, C>> {
self.0
.iter()
.position(|raw| raw.family.id() == id)
.map(|index| QueueGroup::new(self.0.swap_remove(index)))
}
pub fn take_raw(&mut self, id: QueueFamilyId) -> Option<Vec<B::CommandQueue>> {
self.0
.iter()
.position(|raw| raw.family.id() == id)
.map(|index| self.0.swap_remove(index).queues)
}
}