Skip to content

Commit

Permalink
Hide Key implementation detail from the docs
Browse files Browse the repository at this point in the history
  • Loading branch information
marc0246 committed Feb 24, 2025
1 parent c7f931e commit d6c8ffc
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 20 deletions.
23 changes: 12 additions & 11 deletions vulkano-taskgraph/src/descriptor_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
};
use ash::vk;
use bytemuck::{Pod, Zeroable};
use concurrent_slotmap::{epoch, Key, SlotId, SlotMap};
use concurrent_slotmap::{epoch, SlotMap};
use foldhash::HashMap;
use std::{collections::BTreeMap, iter, sync::Arc};
use vulkano::{
Expand Down Expand Up @@ -878,10 +878,10 @@ macro_rules! declare_key {

impl $name {
/// An ID that's guaranteed to be invalid.
pub const INVALID: Self = Self::new(SlotId::INVALID);
pub const INVALID: Self = Self::new(concurrent_slotmap::SlotId::INVALID);

#[inline]
const fn new(slot: SlotId) -> Self {
#[inline(always)]
const fn new(slot: concurrent_slotmap::SlotId) -> Self {
Self {
index: slot.index(),
generation: slot.generation(),
Expand All @@ -891,19 +891,20 @@ macro_rules! declare_key {

impl std::fmt::Debug for $name {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Debug::fmt(&self.as_id(), f)
std::fmt::Debug::fmt(&concurrent_slotmap::Key::as_id(*self), f)
}
}

impl Key for $name {
#[inline]
fn from_id(id: SlotId) -> Self {
#[doc(hidden)]
impl concurrent_slotmap::Key for $name {
#[inline(always)]
fn from_id(id: concurrent_slotmap::SlotId) -> Self {
Self::new(id)
}

#[inline]
fn as_id(self) -> SlotId {
SlotId::new(self.index, self.generation)
#[inline(always)]
fn as_id(self) -> concurrent_slotmap::SlotId {
concurrent_slotmap::SlotId::new(self.index, self.generation)
}
}
};
Expand Down
11 changes: 2 additions & 9 deletions vulkano-taskgraph/src/graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ pub use self::{
use crate::{
linear_map::LinearMap,
resource::{self, AccessTypes, Flight, HostAccessType, ImageLayoutType},
slotmap::{self, Iter, IterMut, SlotMap},
slotmap::{self, declare_key, Iter, IterMut, SlotMap},
Id, InvalidSlotError, Object, ObjectType, QueueFamilyType, Task,
};
use ash::vk;
use concurrent_slotmap::{declare_key, SlotId};
use concurrent_slotmap::SlotId;
use foldhash::HashMap;
use smallvec::SmallVec;
use std::{
Expand Down Expand Up @@ -551,7 +551,6 @@ unsafe impl<W: ?Sized> DeviceOwned for TaskGraph<W> {

declare_key! {
/// The ID type used to refer to a node within a [`TaskGraph`].
#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NodeId;
}

Expand All @@ -561,12 +560,6 @@ impl NodeId {
}
}

impl fmt::Debug for NodeId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&self.0, f)
}
}

/// A node within a [`TaskGraph`] that represents a [`Task`] to be executed along with its resource
/// accesses.
pub struct TaskNode<W: ?Sized> {
Expand Down
2 changes: 2 additions & 0 deletions vulkano-taskgraph/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,7 @@ impl<T> Hash for Id<T> {
}
}

#[doc(hidden)]
impl Key for Id {
#[inline]
fn from_id(id: SlotId) -> Self {
Expand All @@ -842,6 +843,7 @@ impl Key for Id {
}
}

#[doc(hidden)]
impl Key for Id<Framebuffer> {
#[inline]
fn from_id(id: SlotId) -> Self {
Expand Down
44 changes: 44 additions & 0 deletions vulkano-taskgraph/src/slotmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,50 @@ impl<V> Drop for Slot<V> {
}
}

macro_rules! declare_key {
(
$(#[$meta:meta])*
$vis:vis struct $name:ident $(;)?
) => {
$(#[$meta])*
#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(transparent)]
$vis struct $name(concurrent_slotmap::SlotId);

impl Default for $name {
#[inline]
fn default() -> Self {
Self::INVALID
}
}

impl $name {
/// An ID that's guaranteed to be invalid.
pub const INVALID: Self = Self(concurrent_slotmap::SlotId::INVALID);
}

impl std::fmt::Debug for $name {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Debug::fmt(&self.0, f)
}
}

#[doc(hidden)]
impl concurrent_slotmap::Key for $name {
#[inline(always)]
fn from_id(id: concurrent_slotmap::SlotId) -> Self {
Self(id)
}

#[inline(always)]
fn as_id(self) -> concurrent_slotmap::SlotId {
self.0
}
}
};
}
pub(crate) use declare_key;

pub struct Iter<'a, K, V> {
inner: iter::Enumerate<slice::Iter<'a, Slot<V>>>,
marker: PhantomData<fn(K) -> K>,
Expand Down

0 comments on commit d6c8ffc

Please sign in to comment.