From 6dbe11cea5fc5b79f56efc86be2e87e06f7d7e0c Mon Sep 17 00:00:00 2001 From: Yury Date: Mon, 28 Oct 2024 10:54:52 +0300 Subject: [PATCH] Tube mtl api --- cidre/src/mtl.rs | 10 ---------- cidre/src/mtl/acceleration_structure.rs | 5 ++++- cidre/src/mtl/argument_encoder.rs | 10 ++++++++-- cidre/src/mtl/command_buffer.rs | 8 +++++++- cidre/src/mtl/command_encoder.rs | 10 ++++++++-- cidre/src/mtl/command_queue.rs | 8 +++++++- cidre/src/mtl/compute_pipeline.rs | 13 +++++++++++-- cidre/src/mtl/counters.rs | 13 ++++++++++--- cidre/src/mtl/depth_stencil.rs | 13 ++++++++++--- cidre/src/mtl/event.rs | 11 +++++++++-- cidre/src/mtl/fence.rs | 10 ++++++++-- cidre/src/mtl/heap.rs | 8 +++++++- cidre/src/mtl/library.rs | 18 +++++++++++++++--- cidre/src/mtl/render_pipeline.rs | 21 ++++++++++++++++++--- cidre/src/mtl/residency_set.rs | 11 +++++++++-- cidre/src/mtl/resource.rs | 10 +++++++--- cidre/src/mtl/sampler.rs | 15 ++++++++++++--- cidre/src/mtl/texture.rs | 6 +++++- 18 files changed, 155 insertions(+), 45 deletions(-) diff --git a/cidre/src/mtl.rs b/cidre/src/mtl.rs index c40ee209..4da90fc9 100644 --- a/cidre/src/mtl.rs +++ b/cidre/src/mtl.rs @@ -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; diff --git a/cidre/src/mtl/acceleration_structure.rs b/cidre/src/mtl/acceleration_structure.rs index c84742bb..859584a8 100644 --- a/cidre/src/mtl/acceleration_structure.rs +++ b/cidre/src/mtl/acceleration_structure.rs @@ -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>; #[objc::msg_send(primitiveDataBuffer)] pub fn primitive_data_buf(&self) -> Option<&mtl::Buf>; diff --git a/cidre/src/mtl/argument_encoder.rs b/cidre/src/mtl/argument_encoder.rs index e3bf828f..8ff1d617 100644 --- a/cidre/src/mtl/argument_encoder.rs +++ b/cidre/src/mtl/argument_encoder.rs @@ -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; + + #[objc::msg_send(label)] + pub fn label(&self) -> Option>; #[objc::msg_send(encodedLength)] pub fn encoded_len(&self) -> usize; diff --git a/cidre/src/mtl/command_buffer.rs b/cidre/src/mtl/command_buffer.rs index fb44d4a8..625d937d 100644 --- a/cidre/src/mtl/command_buffer.rs +++ b/cidre/src/mtl/command_buffer.rs @@ -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; + + #[objc::msg_send(label)] + pub fn label(&self) -> Option>; #[objc::msg_send(commandQueue)] pub fn cmd_queue(&self) -> &mtl::CmdQueue; diff --git a/cidre/src/mtl/command_encoder.rs b/cidre/src/mtl/command_encoder.rs index 90fe996b..03bca3bc 100644 --- a/cidre/src/mtl/command_encoder.rs +++ b/cidre/src/mtl/command_encoder.rs @@ -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 @@ -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; + + #[objc::msg_send(label)] + pub fn label(&self) -> Option>; /// Declares that all command generation from the encoder is completed. /// diff --git a/cidre/src/mtl/command_queue.rs b/cidre/src/mtl/command_queue.rs index f60f952a..e4db8e0c 100644 --- a/cidre/src/mtl/command_queue.rs +++ b/cidre/src/mtl/command_queue.rs @@ -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; + + #[objc::msg_send(label)] + pub fn label(&self) -> Option>; #[objc::msg_send(commandBuffer)] pub fn new_cmd_buf(&self) -> Option>; diff --git a/cidre/src/mtl/compute_pipeline.rs b/cidre/src/mtl/compute_pipeline.rs index 5949074a..1abdebb8 100644 --- a/cidre/src/mtl/compute_pipeline.rs +++ b/cidre/src/mtl/compute_pipeline.rs @@ -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>; #[objc::msg_send(threadGroupSizeIsMultipleOfThreadExecutionWidth)] pub fn thread_group_size_is_multiple_of_thread_execution_width(&self) -> bool; @@ -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; + + #[objc::msg_send(label)] + pub fn label(&self) -> Option>; #[objc::msg_send(maxTotalThreadsPerThreadgroup)] pub fn max_total_threads_per_threadgroup(&self) -> usize; diff --git a/cidre/src/mtl/counters.rs b/cidre/src/mtl/counters.rs index 94fe0626..91a2cd51 100644 --- a/cidre/src/mtl/counters.rs +++ b/cidre/src/mtl/counters.rs @@ -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. @@ -7,7 +7,11 @@ define_obj_type!( ); impl CounterSampleBuf { - define_mtl!(device, label); + #[objc::msg_send(device)] + pub fn device(&self) -> arc::R; + + #[objc::msg_send(label)] + pub fn label(&self) -> Option>; } #[derive(Debug)] @@ -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>; /// The number of instances of a counter set’s data that a counter sample buffer can store. #[objc::msg_send(sampleCount)] diff --git a/cidre/src/mtl/depth_stencil.rs b/cidre/src/mtl/depth_stencil.rs index 7fab7747..25ee4f47 100644 --- a/cidre/src/mtl/depth_stencil.rs +++ b/cidre/src/mtl/depth_stencil.rs @@ -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)] @@ -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>; } define_obj_type!( @@ -161,7 +164,11 @@ define_obj_type!( ); impl State { - define_mtl!(label, device); + #[objc::msg_send(device)] + pub fn device(&self) -> arc::R; + + #[objc::msg_send(label)] + pub fn label(&self) -> Option>; } #[link(name = "mtl", kind = "static")] diff --git a/cidre/src/mtl/event.rs b/cidre/src/mtl/event.rs index 1792764a..fa541a28 100644 --- a/cidre/src/mtl/event.rs +++ b/cidre/src/mtl/event.rs @@ -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; + + #[objc::msg_send(label)] + pub fn label(&self) -> Option>; } define_obj_type!( @@ -45,7 +51,8 @@ define_obj_type!( ); impl SharedEventHandle { - define_mtl!(label); + #[objc::msg_send(label)] + pub fn label(&self) -> Option>; } define_obj_type!( diff --git a/cidre/src/mtl/fence.rs b/cidre/src/mtl/fence.rs index 71091f7a..ff2e44c9 100644 --- a/cidre/src/mtl/fence.rs +++ b/cidre/src/mtl/fence.rs @@ -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 @@ -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; + + #[objc::msg_send(label)] + pub fn label(&self) -> Option>; } diff --git a/cidre/src/mtl/heap.rs b/cidre/src/mtl/heap.rs index a5341da9..06d1423e 100644 --- a/cidre/src/mtl/heap.rs +++ b/cidre/src/mtl/heap.rs @@ -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; + + #[objc::msg_send(label)] + pub fn label(&self) -> Option>; #[objc::msg_send(size)] pub fn size(&self) -> usize; diff --git a/cidre/src/mtl/library.rs b/cidre/src/mtl/library.rs index a98e0789..31eb72a6 100644 --- a/cidre/src/mtl/library.rs +++ b/cidre/src/mtl/library.rs @@ -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; #[objc::msg_send(attributeIndex)] pub fn attr_index(&self) -> usize; @@ -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; + + #[objc::msg_send(label)] + pub fn label(&self) -> Option>; #[objc::msg_send(name)] pub fn name(&self) -> arc::R; @@ -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; + + #[objc::msg_send(label)] + pub fn label(&self) -> Option>; /// The array contains ns::String objects, with the name of each function in library. #[objc::msg_send(functionNames)] diff --git a/cidre/src/mtl/render_pipeline.rs b/cidre/src/mtl/render_pipeline.rs index 74d6df5c..4b25fe1d 100644 --- a/cidre/src/mtl/render_pipeline.rs +++ b/cidre/src/mtl/render_pipeline.rs @@ -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; + + #[objc::msg_send(label)] + pub fn label(&self) -> Option>; #[objc::msg_send(maxTotalThreadsPerThreadgroup)] pub fn max_total_threads_per_threadgroup(&self) -> usize; @@ -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; + + #[objc::msg_send(label)] + pub fn label(&self) -> Option>; #[objc::msg_send(tileFunction)] pub fn tile_fn(&self) -> &mtl::Fn; @@ -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>; /// Optional shader function responsible for determining how many threadgroups of the mesh shader to run, /// can optionally provide payload data for the mesh stage. diff --git a/cidre/src/mtl/residency_set.rs b/cidre/src/mtl/residency_set.rs index 5621cb8b..da9dd0df 100644 --- a/cidre/src/mtl/residency_set.rs +++ b/cidre/src/mtl/residency_set.rs @@ -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>; /// If non-zero, defines the number of allocations for which to initialize the internal arrays. Defaults to zero. #[objc::msg_send(initialCapacity)] @@ -29,7 +32,11 @@ define_obj_type!( ); impl ResidencySet { - define_mtl!(device, label); + #[objc::msg_send(device)] + pub fn device(&self) -> arc::R; + + #[objc::msg_send(label)] + pub fn label(&self) -> Option>; /// The memory footprint of the set in bytes at the last commit operation. /// This may include internal allocations as well. diff --git a/cidre/src/mtl/resource.rs b/cidre/src/mtl/resource.rs index 30a38202..4ddaeab6 100644 --- a/cidre/src/mtl/resource.rs +++ b/cidre/src/mtl/resource.rs @@ -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)] @@ -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; + + #[objc::msg_send(label)] + pub fn label(&self) -> Option>; } #[cfg(test)] diff --git a/cidre/src/mtl/sampler.rs b/cidre/src/mtl/sampler.rs index 7a1cb380..4aa2f2fd 100644 --- a/cidre/src/mtl/sampler.rs +++ b/cidre/src/mtl/sampler.rs @@ -1,4 +1,4 @@ -use crate::{define_mtl, define_obj_type, ns, objc}; +use crate::{arc, define_mtl, define_obj_type, mtl, ns, objc}; #[doc(alias = "MTLSamplerMinMagFilter")] #[derive(Debug, Copy, Clone, Eq, PartialEq)] @@ -47,7 +47,10 @@ define_obj_type!( ); impl Desc { - define_mtl!(label, set_label); + define_mtl!(set_label); + + #[objc::msg_send(label)] + pub fn label(&self) -> Option>; #[objc::msg_send(minFilter)] pub fn min_filter(&self) -> MinMagFilter; @@ -79,5 +82,11 @@ 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; + + #[objc::msg_send(label)] + pub fn label(&self) -> Option>; } diff --git a/cidre/src/mtl/texture.rs b/cidre/src/mtl/texture.rs index 12b9a2a6..6d6a2e3c 100644 --- a/cidre/src/mtl/texture.rs +++ b/cidre/src/mtl/texture.rs @@ -90,7 +90,11 @@ define_obj_type!( ); impl SharedTextureHandle { - define_mtl!(device, label); + #[objc::msg_send(device)] + pub fn device(&self) -> arc::R; + + #[objc::msg_send(label)] + pub fn label(&self) -> Option>; } define_opts!(