Skip to content

Commit

Permalink
Tube mtl api
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Oct 28, 2024
1 parent 83ddf35 commit 6dbe11c
Show file tree
Hide file tree
Showing 18 changed files with 155 additions and 45 deletions.
10 changes: 0 additions & 10 deletions cidre/src/mtl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,21 +294,11 @@ pub use capture_manager::CaptureManager;

#[macro_export]
macro_rules! define_mtl {
(device) => {
#[$crate::objc::msg_send(device)]
pub fn device(&self) -> &crate::mtl::Device;
};

(set_label) => {
#[$crate::objc::msg_send(setLabel:)]
pub fn set_label(&mut self, val: Option<&crate::ns::String>);
};

(label) => {
#[$crate::objc::msg_send(label)]
pub fn label(&self) -> Option<&crate::ns::String>;
};

(width) => {
#[$crate::objc::msg_send(width)]
pub fn width(&self) -> usize;
Expand Down
5 changes: 4 additions & 1 deletion cidre/src/mtl/acceleration_structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ impl GeometryDesc {
#[objc::msg_send(setAllowDuplicateIntersectionFunctionInvocation:)]
pub fn set_allow_duplicate_intersection_fn_invocation(&mut self, val: bool);

define_mtl!(label, set_label);
define_mtl!(set_label);

#[objc::msg_send(label)]
pub fn label(&self) -> Option<arc::R<ns::String>>;

#[objc::msg_send(primitiveDataBuffer)]
pub fn primitive_data_buf(&self) -> Option<&mtl::Buf>;
Expand Down
10 changes: 8 additions & 2 deletions cidre/src/mtl/argument_encoder.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
use crate::{define_mtl, define_obj_type, mtl, ns, objc};
use crate::{arc, define_mtl, define_obj_type, mtl, ns, objc};

define_obj_type!(pub ArgEncoder(ns::Id));

impl ArgEncoder {
define_mtl!(device, label, set_label);
define_mtl!(set_label);

#[objc::msg_send(device)]
pub fn device(&self) -> arc::R<mtl::Device>;

#[objc::msg_send(label)]
pub fn label(&self) -> Option<arc::R<ns::String>>;

#[objc::msg_send(encodedLength)]
pub fn encoded_len(&self) -> usize;
Expand Down
8 changes: 7 additions & 1 deletion cidre/src/mtl/command_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ define_obj_type!(
);

impl CmdBuf {
define_mtl!(device, label, set_label, push_debug_group, pop_debug_group);
define_mtl!(set_label, push_debug_group, pop_debug_group);

#[objc::msg_send(device)]
pub fn device(&self) -> arc::R<mtl::Device>;

#[objc::msg_send(label)]
pub fn label(&self) -> Option<arc::R<ns::String>>;

#[objc::msg_send(commandQueue)]
pub fn cmd_queue(&self) -> &mtl::CmdQueue;
Expand Down
10 changes: 8 additions & 2 deletions cidre/src/mtl/command_encoder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::ops::DerefMut;

use crate::{arc, define_mtl, define_obj_type, define_opts, ns, objc};
use crate::{arc, define_mtl, define_obj_type, define_opts, mtl, ns, objc};

define_opts!(
/// Describes how a resource will be used by a shader through an argument buffer
Expand Down Expand Up @@ -46,7 +46,13 @@ define_obj_type!(
);

impl CmdEncoder {
define_mtl!(device, label, set_label, push_debug_group, pop_debug_group);
define_mtl!(set_label, push_debug_group, pop_debug_group);

#[objc::msg_send(device)]
pub fn device(&self) -> arc::R<mtl::Device>;

#[objc::msg_send(label)]
pub fn label(&self) -> Option<arc::R<ns::String>>;

/// Declares that all command generation from the encoder is completed.
///
Expand Down
8 changes: 7 additions & 1 deletion cidre/src/mtl/command_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ define_obj_type!(
);

impl CmdQueue {
define_mtl!(device, label, set_label);
define_mtl!(set_label);

#[objc::msg_send(device)]
pub fn device(&self) -> arc::R<mtl::Device>;

#[objc::msg_send(label)]
pub fn label(&self) -> Option<arc::R<ns::String>>;

#[objc::msg_send(commandBuffer)]
pub fn new_cmd_buf(&self) -> Option<arc::R<mtl::CmdBuf>>;
Expand Down
13 changes: 11 additions & 2 deletions cidre/src/mtl/compute_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ define_obj_type!(
);

impl Desc {
define_mtl!(label, set_label);
define_mtl!(set_label);

#[objc::msg_send(label)]
pub fn label(&self) -> Option<arc::R<ns::String>>;

#[objc::msg_send(threadGroupSizeIsMultipleOfThreadExecutionWidth)]
pub fn thread_group_size_is_multiple_of_thread_execution_width(&self) -> bool;
Expand Down Expand Up @@ -51,7 +54,13 @@ define_obj_type!(
);

impl State {
define_mtl!(device, label, gpu_resource_id);
define_mtl!(gpu_resource_id);

#[objc::msg_send(device)]
pub fn device(&self) -> arc::R<mtl::Device>;

#[objc::msg_send(label)]
pub fn label(&self) -> Option<arc::R<ns::String>>;

#[objc::msg_send(maxTotalThreadsPerThreadgroup)]
pub fn max_total_threads_per_threadgroup(&self) -> usize;
Expand Down
13 changes: 10 additions & 3 deletions cidre/src/mtl/counters.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{arc, define_mtl, define_obj_type, ns, objc};
use crate::{arc, define_mtl, define_obj_type, mtl, ns, objc};

define_obj_type!(
/// A specialized memory buffer that stores a GPU’s counter set data.
Expand All @@ -7,7 +7,11 @@ define_obj_type!(
);

impl CounterSampleBuf {
define_mtl!(device, label);
#[objc::msg_send(device)]
pub fn device(&self) -> arc::R<mtl::Device>;

#[objc::msg_send(label)]
pub fn label(&self) -> Option<arc::R<ns::String>>;
}

#[derive(Debug)]
Expand Down Expand Up @@ -49,7 +53,10 @@ define_obj_type!(
);

impl Desc {
define_mtl!(label, set_label, storage_mode);
define_mtl!(set_label, storage_mode);

#[objc::msg_send(label)]
pub fn label(&self) -> Option<arc::R<ns::String>>;

/// The number of instances of a counter set’s data that a counter sample buffer can store.
#[objc::msg_send(sampleCount)]
Expand Down
13 changes: 10 additions & 3 deletions cidre/src/mtl/depth_stencil.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{arc, define_mtl, define_obj_type, ns, objc};
use crate::{arc, define_mtl, define_obj_type, mtl, ns, objc};

#[doc(alias = "MTLCompareFunction")]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
Expand Down Expand Up @@ -151,7 +151,10 @@ impl DepthStencilDesc {
self._set_back_face_stencil(None)
}

define_mtl!(label, set_label);
define_mtl!(set_label);

#[objc::msg_send(label)]
pub fn label(&self) -> Option<arc::R<ns::String>>;
}

define_obj_type!(
Expand All @@ -161,7 +164,11 @@ define_obj_type!(
);

impl State {
define_mtl!(label, device);
#[objc::msg_send(device)]
pub fn device(&self) -> arc::R<mtl::Device>;

#[objc::msg_send(label)]
pub fn label(&self) -> Option<arc::R<ns::String>>;
}

#[link(name = "mtl", kind = "static")]
Expand Down
11 changes: 9 additions & 2 deletions cidre/src/mtl/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ define_obj_type!(
);

impl Event {
define_mtl!(device, label, set_label);
define_mtl!(set_label);

#[objc::msg_send(device)]
pub fn device(&self) -> arc::R<mtl::Device>;

#[objc::msg_send(label)]
pub fn label(&self) -> Option<arc::R<ns::String>>;
}

define_obj_type!(
Expand Down Expand Up @@ -45,7 +51,8 @@ define_obj_type!(
);

impl SharedEventHandle {
define_mtl!(label);
#[objc::msg_send(label)]
pub fn label(&self) -> Option<arc::R<ns::String>>;
}

define_obj_type!(
Expand Down
10 changes: 8 additions & 2 deletions cidre/src/mtl/fence.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{define_mtl, define_obj_type, ns};
use crate::{arc, define_mtl, define_obj_type, mtl, ns, objc};

define_obj_type!(
/// An object that can capture, track, and manage resource dependencies
Expand All @@ -12,5 +12,11 @@ define_obj_type!(
);

impl Fence {
define_mtl!(device, label, set_label);
define_mtl!(set_label);

#[objc::msg_send(device)]
pub fn device(&self) -> arc::R<mtl::Device>;

#[objc::msg_send(label)]
pub fn label(&self) -> Option<arc::R<ns::String>>;
}
8 changes: 7 additions & 1 deletion cidre/src/mtl/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,13 @@ impl Desc {
define_obj_type!(pub Heap(ns::Id));

impl Heap {
define_mtl!(device, label, set_label, hazard_tracking_mode, res_opts);
define_mtl!(set_label, hazard_tracking_mode, res_opts);

#[objc::msg_send(device)]
pub fn device(&self) -> arc::R<mtl::Device>;

#[objc::msg_send(label)]
pub fn label(&self) -> Option<arc::R<ns::String>>;

#[objc::msg_send(size)]
pub fn size(&self) -> usize;
Expand Down
18 changes: 15 additions & 3 deletions cidre/src/mtl/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ define_obj_type!(

impl VertexAttr {
#[objc::msg_send(name)]
pub fn name(&self) -> &ns::String;
pub fn name(&self) -> arc::R<ns::String>;

#[objc::msg_send(attributeIndex)]
pub fn attr_index(&self) -> usize;
Expand Down Expand Up @@ -260,7 +260,13 @@ define_obj_type!(
);

impl Fn {
define_mtl!(device, label, set_label);
define_mtl!(set_label);

#[objc::msg_send(device)]
pub fn device(&self) -> arc::R<mtl::Device>;

#[objc::msg_send(label)]
pub fn label(&self) -> Option<arc::R<ns::String>>;

#[objc::msg_send(name)]
pub fn name(&self) -> arc::R<ns::String>;
Expand Down Expand Up @@ -295,7 +301,13 @@ define_obj_type!(
unsafe impl Send for Lib {}

impl Lib {
define_mtl!(device, label, set_label);
define_mtl!(set_label);

#[objc::msg_send(device)]
pub fn device(&self) -> arc::R<mtl::Device>;

#[objc::msg_send(label)]
pub fn label(&self) -> Option<arc::R<ns::String>>;

/// The array contains ns::String objects, with the name of each function in library.
#[objc::msg_send(functionNames)]
Expand Down
21 changes: 18 additions & 3 deletions cidre/src/mtl/render_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,13 @@ define_obj_type!(pub FnsDesc(ns::Id));
define_obj_type!(pub State(ns::Id));

impl State {
define_mtl!(device, label, gpu_resource_id);
define_mtl!(gpu_resource_id);

#[objc::msg_send(device)]
pub fn device(&self) -> arc::R<mtl::Device>;

#[objc::msg_send(label)]
pub fn label(&self) -> Option<arc::R<ns::String>>;

#[objc::msg_send(maxTotalThreadsPerThreadgroup)]
pub fn max_total_threads_per_threadgroup(&self) -> usize;
Expand Down Expand Up @@ -358,7 +364,13 @@ define_obj_type!(
);

impl TileRenderPipelineDesc {
define_mtl!(reset, label, set_label);
define_mtl!(set_label);

#[objc::msg_send(device)]
pub fn device(&self) -> arc::R<mtl::Device>;

#[objc::msg_send(label)]
pub fn label(&self) -> Option<arc::R<ns::String>>;

#[objc::msg_send(tileFunction)]
pub fn tile_fn(&self) -> &mtl::Fn;
Expand Down Expand Up @@ -394,7 +406,10 @@ impl TileRenderPipelineDesc {
define_obj_type!(pub MeshRenderPipelineDesc(ns::Id));

impl MeshRenderPipelineDesc {
define_mtl!(reset, label, set_label);
define_mtl!(reset, set_label);

#[objc::msg_send(label)]
pub fn label(&self) -> Option<arc::R<ns::String>>;

/// Optional shader function responsible for determining how many threadgroups of the mesh shader to run,
/// can optionally provide payload data for the mesh stage.
Expand Down
11 changes: 9 additions & 2 deletions cidre/src/mtl/residency_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ extern "C" {
}

impl ResidencySetDesc {
define_mtl!(label, set_label);
define_mtl!(set_label);

#[objc::msg_send(label)]
pub fn label(&self) -> Option<arc::R<ns::String>>;

/// If non-zero, defines the number of allocations for which to initialize the internal arrays. Defaults to zero.
#[objc::msg_send(initialCapacity)]
Expand All @@ -29,7 +32,11 @@ define_obj_type!(
);

impl ResidencySet {
define_mtl!(device, label);
#[objc::msg_send(device)]
pub fn device(&self) -> arc::R<mtl::Device>;

#[objc::msg_send(label)]
pub fn label(&self) -> Option<arc::R<ns::String>>;

/// The memory footprint of the set in bytes at the last commit operation.
/// This may include internal allocations as well.
Expand Down
10 changes: 7 additions & 3 deletions cidre/src/mtl/resource.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::mem::transmute;

use crate::{define_mtl, define_obj_type, define_opts, mtl};
use crate::{arc, define_mtl, define_obj_type, define_opts, mtl, ns, objc};

/// Options for set_purgeable call.
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
Expand Down Expand Up @@ -153,14 +153,18 @@ define_obj_type!(

impl Res {
define_mtl!(
device,
label,
set_label,
cpu_cache_mode,
storage_mode,
hazard_tracking_mode,
res_opts
);

#[objc::msg_send(device)]
pub fn device(&self) -> arc::R<mtl::Device>;

#[objc::msg_send(label)]
pub fn label(&self) -> Option<arc::R<ns::String>>;
}

#[cfg(test)]
Expand Down
Loading

0 comments on commit 6dbe11c

Please sign in to comment.