Skip to content

Commit

Permalink
MTLResourceID::to_raw()
Browse files Browse the repository at this point in the history
  • Loading branch information
MarijnS95 committed Jan 3, 2025
1 parent e830da7 commit 7c8dd06
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ members = [
[dependencies]
libloading = "0.8"
thiserror = "2.0"

[patch.crates-io]
# Add as_raw: https://github.com/madsmtm/objc2/commit/94f104fd352fb26f191ef9f3c2ccee869ef73703
objc2 = { git = "https://github.com/madsmtm/objc2.git", rev = "94f104fd352fb26f191ef9f3c2ccee869ef73703" }
objc2-metal = { git = "https://github.com/madsmtm/objc2.git", rev = "94f104fd352fb26f191ef9f3c2ccee869ef73703" }
2 changes: 1 addition & 1 deletion runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ 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-metal = { version = "0.2.2", default-features = false, features = ["std", "MTLResource", "MTLBuffer", "MTLTexture", "MTLSampler", "MTLTypes", "MTLAllocation"] }
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 7c8dd06

Please sign in to comment.