diff --git a/crates/objc2/src/topics/about_generated/CHANGELOG.md b/crates/objc2/src/topics/about_generated/CHANGELOG.md index 5a838cdd4..d63577499 100644 --- a/crates/objc2/src/topics/about_generated/CHANGELOG.md +++ b/crates/objc2/src/topics/about_generated/CHANGELOG.md @@ -17,6 +17,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). * Added `Eq` implementation for `NSValue` and subclasses. * Added `CopyingHelper` and `MutableCopyingHelper`, which are used to specify the types returned from `NSCopying` and `NSMutableCopying`. +* Added `MTLResourceID::from_raw` and `MTLResourceID::as_raw` to allow + querying the underlying data. ### Changed * Allow using `MainThreadBound` without the `NSThread` feature flag. diff --git a/framework-crates/objc2-metal/src/lib.rs b/framework-crates/objc2-metal/src/lib.rs index 400e036c6..60ddbcfb1 100644 --- a/framework-crates/objc2-metal/src/lib.rs +++ b/framework-crates/objc2-metal/src/lib.rs @@ -61,6 +61,8 @@ mod resource; mod slice; #[cfg(feature = "MTLTexture")] mod texture; +#[cfg(feature = "MTLTypes")] +mod types; #[cfg(feature = "MTLCounters")] pub use self::counters::*; diff --git a/framework-crates/objc2-metal/src/types.rs b/framework-crates/objc2-metal/src/types.rs new file mode 100644 index 000000000..9fbda8e87 --- /dev/null +++ b/framework-crates/objc2-metal/src/types.rs @@ -0,0 +1,30 @@ +use crate::MTLResourceID; + +impl MTLResourceID { + /// Construct a `MTLResourceID` from an ID previously gotten via. + /// `to_raw`. + /// + /// # Safety + /// + /// The documentation for `MTLResourceID` says: + /// + /// > A MTLResourceID represents a specific GPU resource, mutating this + /// > handle is undefined unless the mutation results in the value + /// > equalling an already existing handle of the same resource type. + /// + /// So we've tentatively marked this method as `unsafe`, with the safety + /// requirement that the ID must be valid, i.e. have previously come from + /// [`to_raw`][Self::to_raw] or similar. + /// + /// If you disagree with this assessment, feel free to open an issue! + pub const unsafe fn from_raw(id: u64) -> Self { + Self { _impl: id } + } + + /// Get the underlying data of the ID. + /// + /// May be useful for FFI purposes. + pub const fn to_raw(self) -> u64 { + self._impl + } +}