mirror of
https://github.com/vulkano-rs/vulkano.git
synced 2024-11-21 22:34:43 +00:00
Use vkGetDeviceQueue2
on Vulkan 1.1 and above (#2466)
This commit is contained in:
parent
8673aea5d0
commit
0fb4a7a437
@ -96,8 +96,8 @@
|
|||||||
//!
|
//!
|
||||||
//! TODO: write
|
//! TODO: write
|
||||||
|
|
||||||
use self::physical::PhysicalDevice;
|
|
||||||
pub(crate) use self::properties::PropertiesFfi;
|
pub(crate) use self::properties::PropertiesFfi;
|
||||||
|
use self::{physical::PhysicalDevice, queue::DeviceQueueInfo};
|
||||||
pub use self::{
|
pub use self::{
|
||||||
properties::Properties,
|
properties::Properties,
|
||||||
queue::{Queue, QueueFamilyProperties, QueueFlags, QueueGuard},
|
queue::{Queue, QueueFamilyProperties, QueueFlags, QueueGuard},
|
||||||
@ -477,12 +477,6 @@ impl Device {
|
|||||||
.map_or(ptr::null(), |func| func as _)
|
.map_or(ptr::null(), |func| func as _)
|
||||||
});
|
});
|
||||||
|
|
||||||
struct QueueToGet {
|
|
||||||
flags: QueueCreateFlags,
|
|
||||||
queue_family_index: u32,
|
|
||||||
id: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut active_queue_family_indices: SmallVec<[_; 2]> =
|
let mut active_queue_family_indices: SmallVec<[_; 2]> =
|
||||||
SmallVec::with_capacity(queue_create_infos.len());
|
SmallVec::with_capacity(queue_create_infos.len());
|
||||||
let mut queues_to_get: SmallVec<[_; 2]> = SmallVec::with_capacity(queue_create_infos.len());
|
let mut queues_to_get: SmallVec<[_; 2]> = SmallVec::with_capacity(queue_create_infos.len());
|
||||||
@ -496,10 +490,13 @@ impl Device {
|
|||||||
} = queue_create_info;
|
} = queue_create_info;
|
||||||
|
|
||||||
active_queue_family_indices.push(queue_family_index);
|
active_queue_family_indices.push(queue_family_index);
|
||||||
queues_to_get.extend((0..queues.len() as u32).map(move |id| QueueToGet {
|
queues_to_get.extend((0..queues.len() as u32).map(move |queue_index| {
|
||||||
flags,
|
DeviceQueueInfo {
|
||||||
queue_family_index,
|
flags,
|
||||||
id,
|
queue_family_index,
|
||||||
|
queue_index,
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -536,15 +533,9 @@ impl Device {
|
|||||||
|
|
||||||
let queues_iter = {
|
let queues_iter = {
|
||||||
let device = device.clone();
|
let device = device.clone();
|
||||||
queues_to_get.into_iter().map(move |queue_to_get| unsafe {
|
queues_to_get
|
||||||
let QueueToGet {
|
.into_iter()
|
||||||
flags,
|
.map(move |queue_info| unsafe { Queue::new(device.clone(), queue_info) })
|
||||||
queue_family_index,
|
|
||||||
id,
|
|
||||||
} = queue_to_get;
|
|
||||||
|
|
||||||
Queue::new(device.clone(), flags, queue_family_index, id)
|
|
||||||
})
|
|
||||||
};
|
};
|
||||||
|
|
||||||
(device, queues_iter)
|
(device, queues_iter)
|
||||||
|
@ -30,31 +30,45 @@ pub struct Queue {
|
|||||||
|
|
||||||
flags: QueueCreateFlags,
|
flags: QueueCreateFlags,
|
||||||
queue_family_index: u32,
|
queue_family_index: u32,
|
||||||
id: u32, // id within family
|
queue_index: u32, // index within family
|
||||||
|
|
||||||
state: Mutex<QueueState>,
|
state: Mutex<QueueState>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Queue {
|
impl Queue {
|
||||||
pub(super) unsafe fn new(
|
pub(super) unsafe fn new(device: Arc<Device>, queue_info: DeviceQueueInfo) -> Arc<Self> {
|
||||||
device: Arc<Device>,
|
let &DeviceQueueInfo {
|
||||||
flags: QueueCreateFlags,
|
flags,
|
||||||
queue_family_index: u32,
|
queue_family_index,
|
||||||
id: u32,
|
queue_index,
|
||||||
) -> Arc<Self> {
|
_ne: _,
|
||||||
let handle = {
|
} = &queue_info;
|
||||||
let fns = device.fns();
|
|
||||||
let mut output = MaybeUninit::uninit();
|
let queue_info_vk = ash::vk::DeviceQueueInfo2 {
|
||||||
(fns.v1_0.get_device_queue)(
|
flags: flags.into(),
|
||||||
device.handle(),
|
queue_family_index,
|
||||||
queue_family_index,
|
queue_index,
|
||||||
id,
|
..Default::default()
|
||||||
output.as_mut_ptr(),
|
|
||||||
);
|
|
||||||
output.assume_init()
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Self::from_handle(device, handle, flags, queue_family_index, id)
|
let fns = device.fns();
|
||||||
|
let mut output = MaybeUninit::uninit();
|
||||||
|
|
||||||
|
if device.api_version() >= Version::V1_1 {
|
||||||
|
(fns.v1_1.get_device_queue2)(device.handle(), &queue_info_vk, output.as_mut_ptr());
|
||||||
|
} else {
|
||||||
|
debug_assert!(queue_info_vk.flags.is_empty());
|
||||||
|
debug_assert!(queue_info_vk.p_next.is_null());
|
||||||
|
(fns.v1_0.get_device_queue)(
|
||||||
|
device.handle(),
|
||||||
|
queue_info_vk.queue_family_index,
|
||||||
|
queue_info_vk.queue_index,
|
||||||
|
output.as_mut_ptr(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let handle = output.assume_init();
|
||||||
|
Self::from_handle(device, handle, queue_info)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Make public
|
// TODO: Make public
|
||||||
@ -62,16 +76,21 @@ impl Queue {
|
|||||||
pub(super) unsafe fn from_handle(
|
pub(super) unsafe fn from_handle(
|
||||||
device: Arc<Device>,
|
device: Arc<Device>,
|
||||||
handle: ash::vk::Queue,
|
handle: ash::vk::Queue,
|
||||||
flags: QueueCreateFlags,
|
queue_info: DeviceQueueInfo,
|
||||||
queue_family_index: u32,
|
|
||||||
id: u32,
|
|
||||||
) -> Arc<Self> {
|
) -> Arc<Self> {
|
||||||
|
let DeviceQueueInfo {
|
||||||
|
flags,
|
||||||
|
queue_family_index,
|
||||||
|
queue_index,
|
||||||
|
_ne: _,
|
||||||
|
} = queue_info;
|
||||||
|
|
||||||
Arc::new(Queue {
|
Arc::new(Queue {
|
||||||
handle,
|
handle,
|
||||||
device: InstanceOwnedDebugWrapper(device),
|
device: InstanceOwnedDebugWrapper(device),
|
||||||
flags,
|
flags,
|
||||||
queue_family_index,
|
queue_family_index,
|
||||||
id,
|
queue_index,
|
||||||
state: Mutex::new(Default::default()),
|
state: Mutex::new(Default::default()),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -96,8 +115,8 @@ impl Queue {
|
|||||||
|
|
||||||
/// Returns the index of this queue within its queue family.
|
/// Returns the index of this queue within its queue family.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn id_within_family(&self) -> u32 {
|
pub fn queue_index(&self) -> u32 {
|
||||||
self.id
|
self.queue_index
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Locks the queue and then calls the provided closure, providing it with an object that
|
/// Locks the queue and then calls the provided closure, providing it with an object that
|
||||||
@ -140,7 +159,7 @@ unsafe impl DeviceOwned for Queue {
|
|||||||
impl PartialEq for Queue {
|
impl PartialEq for Queue {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
self.id == other.id
|
self.queue_index == other.queue_index
|
||||||
&& self.queue_family_index == other.queue_family_index
|
&& self.queue_family_index == other.queue_family_index
|
||||||
&& self.device == other.device
|
&& self.device == other.device
|
||||||
}
|
}
|
||||||
@ -150,12 +169,33 @@ impl Eq for Queue {}
|
|||||||
|
|
||||||
impl Hash for Queue {
|
impl Hash for Queue {
|
||||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||||
self.id.hash(state);
|
self.queue_index.hash(state);
|
||||||
self.queue_family_index.hash(state);
|
self.queue_family_index.hash(state);
|
||||||
self.device.hash(state);
|
self.device.hash(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Parameters to retrieve a [`Queue`] from the device.
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub(super) struct DeviceQueueInfo {
|
||||||
|
pub(super) flags: QueueCreateFlags,
|
||||||
|
pub(super) queue_family_index: u32,
|
||||||
|
pub(super) queue_index: u32,
|
||||||
|
pub(super) _ne: crate::NonExhaustive,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for DeviceQueueInfo {
|
||||||
|
#[inline]
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
flags: QueueCreateFlags::empty(),
|
||||||
|
queue_family_index: 0,
|
||||||
|
queue_index: 0,
|
||||||
|
_ne: crate::NonExhaustive(()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct QueueGuard<'a> {
|
pub struct QueueGuard<'a> {
|
||||||
queue: &'a Arc<Queue>,
|
queue: &'a Arc<Queue>,
|
||||||
_state: MutexGuard<'a, QueueState>,
|
_state: MutexGuard<'a, QueueState>,
|
||||||
|
Loading…
Reference in New Issue
Block a user