Skip to content

Commit

Permalink
Upgrade to objc2 0.6 and objc2-metal 0.3
Browse files Browse the repository at this point in the history
`objc2-metal` has a new `to_raw()` function for converting
`MTLResourceID` to its raw representation, as used in a few structures
as a raw integer.

Note also that a new `MTLAllocation` interface was added to Metal.  Even
if that interface is _optional_, current `objc2` design requires this
trait to be part of the hierarchy (and the feature explicitly enabled)
to get access to all "descendant" interfaces (`MTLResource`, which
provides `MTLBuffer` and `MTLTexture`).
  • Loading branch information
MarijnS95 committed Jan 24, 2025
1 parent e830da7 commit c686b0d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
4 changes: 2 additions & 2 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ targets = [
]

[dependencies]
objc2 = { version = "0.5", default-features = false }
objc2-metal = { version = "0.2.2", default-features = false, features = ["std", "MTLResource", "MTLBuffer", "MTLTexture", "MTLSampler", "MTLTypes"] }
objc2 = { version = "0.6", default-features = false }
objc2-metal = { version = "0.3", default-features = false, features = ["std", "MTLAllocation", "MTLResource", "MTLBuffer", "MTLTexture", "MTLSampler", "MTLTypes"] }
12 changes: 4 additions & 8 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub mod bindings {
pub use bindings as ffi;

use objc2::runtime::ProtocolObject;
use objc2_metal::{MTLBuffer, MTLResourceID, MTLSamplerState, MTLTexture};
use objc2_metal::{MTLBuffer, MTLSamplerState, MTLTexture};

/// Rust version of `IRBufferView` using [`metal`] types.
#[doc(alias = "IRBufferView")]
Expand Down Expand Up @@ -59,9 +59,7 @@ impl ffi::IRDescriptorTableEntry {
Self {
gpuVA: buffer_view.buffer.gpuAddress() + buffer_view.buffer_offset,
textureViewID: match buffer_view.texture_buffer_view {
Some(texture) => unsafe {
std::mem::transmute::<MTLResourceID, u64>(texture.gpuResourceID())
},
Some(texture) => unsafe { texture.gpuResourceID() }.to_raw(),
None => 0,
},
metadata: Self::buffer_metadata(buffer_view),
Expand All @@ -77,9 +75,7 @@ impl ffi::IRDescriptorTableEntry {
const METADATA: u32 = 0; // According to the current docs, the metadata must be 0
Self {
gpuVA: 0,
textureViewID: unsafe {
std::mem::transmute::<MTLResourceID, u64>(argument.gpuResourceID())
},
textureViewID: unsafe { argument.gpuResourceID() }.to_raw(),
metadata: min_lod_clamp.to_bits() as u64 | (METADATA as u64) << 32,
}
}
Expand All @@ -91,7 +87,7 @@ impl ffi::IRDescriptorTableEntry {
#[doc(alias = "IRDescriptorTableSetSampler")]
pub fn sampler(argument: &ProtocolObject<dyn MTLSamplerState>, lod_bias: f32) -> Self {
Self {
gpuVA: unsafe { std::mem::transmute::<MTLResourceID, u64>(argument.gpuResourceID()) },
gpuVA: unsafe { argument.gpuResourceID() }.to_raw(),
textureViewID: 0,
metadata: lod_bias.to_bits() as u64,
}
Expand Down

0 comments on commit c686b0d

Please sign in to comment.