Skip to content

Commit

Permalink
runtime: Disable default link feature on metal crate (#21)
Browse files Browse the repository at this point in the history
Since we're only using a few types from the `metal` crate, this helper
library has no reason or need to link against framework libraries (i.e.
we don't call global static functions on them). Disable the `link`
feature on the `metal` crate.

> [!CAUTION]
> For now this won't disable it on the `core-graphics-types` crate until
gfx-rs/metal-rs#330 is merged.
  • Loading branch information
MarijnS95 authored Jul 23, 2024
1 parent bd661d4 commit 700fce9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ targets = [
]

[dependencies]
metal = "0.29"
metal = { version = "0.29", default-features = false }
6 changes: 4 additions & 2 deletions runtime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

[![Banner](../banner.png)](https://traverseresearch.nl)

[`saxaboom-runtime`] provides the runtime structures and interop with the [`metal`] crate needed to make use of the `metallib` shaders generated by [`saxaboom`] (bindings for [Metal shader converter]).
[`saxaboom-runtime`] provides the runtime `repr(C)` definitions for structures and interop with the [`metal`] crate needed to make use of the `metallib` shaders generated by [`saxaboom`] (bindings for [Metal shader converter]).

## Usage

Expand All @@ -21,11 +21,13 @@ Add this to your `Cargo.toml`:
saxaboom-runtime = "0.1.0"
```

Example to create a descriptor to a buffer:

```rust,no_run
use saxaboom_runtime::ffi::IRDescriptorTableEntry;
let gpu_address = 0; // TODO: Read from metal::Buffer::gpu_address()
let metadata = IRDescriptorTableEntry::buffer_metadata(&todo!("Fill saxaboom_runtime::BufferView"));
let metadata = IRDescriptorTableEntry::buffer_metadata(todo!("Fill saxaboom_runtime::BufferView"));
let buffer_descriptor = IRDescriptorTableEntry::buffer(gpu_address, metadata);
```

Expand Down
10 changes: 7 additions & 3 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Contains `repr(C)` definitions for structures used at runtime.
#![doc = include_str!("../README.md")]

#[allow(
clippy::useless_transmute,
Expand Down Expand Up @@ -30,8 +30,12 @@ impl ffi::IRDescriptorTableEntry {
///
/// This function is a port of the `IRDescriptorTableSetBuffer` function in the `metal_irconverter_runtime.h` header.
/// See <https://developer.apple.com/metal/shader-converter/> for more info.
// TODO: The docs say "buffer view" for metadata: can we take a BufferView struct and set `Self::buffer_metadata()` instead?
// There are special constructors for atomic/counter buffers after all...
// TODO: This function seems to have no reason to exist, in favour of `buffer_view()` the
// `metadata` argument here needs to be constructed in the exact same way. However, for a
// full buffer descriptor, setting the metadata to `0` seems to be fine?
// TODO: The docs say "buffer view" for metadata: can we take a BufferView struct and set
// `Self::buffer_metadata()` instead? There are special constructors for atomic/counter buffers
// after all...
#[doc(alias = "IRDescriptorTableSetBuffer")]
pub fn buffer(gpu_address: u64, metadata: u64) -> Self {
Self {
Expand Down

0 comments on commit 700fce9

Please sign in to comment.