This commit is contained in:
janis 2026-10-24 16:44:29 +02:00
parent 65bae2196a
commit c20cee38de
Signed by: janis
SSH key fingerprint: SHA256:bB1qbbqmDXZNT0KKD5c2Dfjg53JGhj7B3CFcLIzSqq8
3 changed files with 34 additions and 5 deletions

View file

@ -4,6 +4,7 @@ version = "0.1.0"
edition = "2024"
[dependencies]
renderer_macros = { path = "renderer_macros" }
tinyvec = { workspace = true }
arrayvec = { workspace = true }
indexmap = { workspace = true }

View file

@ -3,6 +3,10 @@ name = "renderer_macros"
version = "0.1.0"
edition = "2024"
[lib]
proc-macro = true
[dependencies]
proc-macro2 = "1.0"
quote = "1.0"
syn = "2"

View file

@ -858,16 +858,17 @@ pub(crate) mod asdf {
};
use ash::vk;
use ash::vk::Handle;
use crate::{device::DeviceInner, util::DebugName};
pub mod traits {
/// A trait describing an object owned by some manager-type, which is
/// responsible for destroying it.
pub trait ExternallyManagedObject<T> {
pub trait ExternallyManagedObject<Owner> {
/// # Safety
/// The caller must ensure this function is only called once for a given object.
unsafe fn destroy(self, owner: &T);
unsafe fn destroy(self, owner: &Owner);
}
/// A trait describing an object which can have a debug name assigned to it.
@ -1043,6 +1044,29 @@ pub(crate) mod asdf {
}
}
impl<T, O> std::fmt::Debug for DeviceObject<T, O>
where
T: std::fmt::Debug + traits::ExternallyManagedObject<O>,
O: AsRef<super::DeviceInner>,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut fmt = f.debug_struct(core::any::type_name::<T>());
let inner: &T = &self.inner;
fmt.field_with("device", |f| {
write!(
f,
"0x{:x}",
self.inner.owner().as_ref().raw.handle().as_raw()
)
})
.field_with("handle", |f| write!(f, "{inner:?}"))
.field("name", &self.name);
fmt.finish()
}
}
impl<T, O> Deref for DeviceObject<T, O>
where
T: traits::ExternallyManagedObject<O>,
@ -1051,7 +1075,7 @@ pub(crate) mod asdf {
type Target = T;
fn deref(&self) -> &Self::Target {
&*self.inner
&self.inner
}
}
@ -1061,7 +1085,7 @@ pub(crate) mod asdf {
O: AsRef<super::DeviceInner>,
{
fn deref_mut(&mut self) -> &mut Self::Target {
&mut *self.inner
&mut self.inner
}
}