mtl-rs 0.1.12

Rust bindings for Apple's Metal API
use objc2::{
    extern_class, extern_conformance, extern_methods,
    rc::{Allocated, Retained},
};
use objc2_foundation::{CopyingHelper, NSCopying, NSObject, NSObjectProtocol};

use crate::*;

extern_class!(
    /// Describes a compute pipeline state.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtl4computepipelinedescriptor?language=objc)
    #[unsafe(super(MTL4PipelineDescriptor, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct MTL4ComputePipelineDescriptor;
);

extern_conformance!(
    unsafe impl NSCopying for MTL4ComputePipelineDescriptor {}
);

unsafe impl CopyingHelper for MTL4ComputePipelineDescriptor {
    type Result = Self;
}

extern_conformance!(
    unsafe impl NSObjectProtocol for MTL4ComputePipelineDescriptor {}
);

impl MTL4ComputePipelineDescriptor {
    extern_methods!(
        /// A descriptor representing the compute pipeline's function.
        ///
        /// You don't assign instances of ``MTL4FunctionDescriptor`` to this property directly, instead
        /// assign an instance of one of its subclasses, such as ``MTL4LibraryFunctionDescriptor``, which
        /// represents a function from a Metal library.
        #[unsafe(method(computeFunctionDescriptor))]
        #[unsafe(method_family = none)]
        pub fn compute_function_descriptor(&self) -> Option<Retained<MTL4FunctionDescriptor>>;

        /// Setter for [`computeFunctionDescriptor`][Self::computeFunctionDescriptor].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setComputeFunctionDescriptor:))]
        #[unsafe(method_family = none)]
        pub fn set_compute_function_descriptor(
            &self,
            compute_function_descriptor: Option<&MTL4FunctionDescriptor>,
        );

        /// A boolean value indicating whether each dimension of the threadgroup size is a multiple of its
        /// corresponding thread execution width.
        #[unsafe(method(threadGroupSizeIsMultipleOfThreadExecutionWidth))]
        #[unsafe(method_family = none)]
        pub fn thread_group_size_is_multiple_of_thread_execution_width(&self) -> bool;

        /// Setter for [`threadGroupSizeIsMultipleOfThreadExecutionWidth`][Self::threadGroupSizeIsMultipleOfThreadExecutionWidth].
        #[unsafe(method(setThreadGroupSizeIsMultipleOfThreadExecutionWidth:))]
        #[unsafe(method_family = none)]
        pub fn set_thread_group_size_is_multiple_of_thread_execution_width(
            &self,
            thread_group_size_is_multiple_of_thread_execution_width: bool,
        );

        /// The maximum total number of threads that Metal can execute in a single threadgroup for the
        /// compute function.
        #[unsafe(method(maxTotalThreadsPerThreadgroup))]
        #[unsafe(method_family = none)]
        pub fn max_total_threads_per_threadgroup(&self) -> usize;

        /// Setter for [`maxTotalThreadsPerThreadgroup`][Self::maxTotalThreadsPerThreadgroup].
        #[unsafe(method(setMaxTotalThreadsPerThreadgroup:))]
        #[unsafe(method_family = none)]
        pub fn set_max_total_threads_per_threadgroup(
            &self,
            max_total_threads_per_threadgroup: usize,
        );

        /// The required number of threads per threadgroup for compute dispatches.
        ///
        /// When you set this value, you are responsible for ensuring that the `threadsPerThreadgroup` argument of any compute
        /// dispatch matches it.
        ///
        /// Setting this property is optional, except in cases where the pipeline uses *CooperativeTensors*.
        ///
        /// This property's default value is `0`, which disables its effect.
        #[unsafe(method(requiredThreadsPerThreadgroup))]
        #[unsafe(method_family = none)]
        pub fn required_threads_per_threadgroup(&self) -> MTLSize;

        /// Setter for [`requiredThreadsPerThreadgroup`][Self::requiredThreadsPerThreadgroup].
        #[unsafe(method(setRequiredThreadsPerThreadgroup:))]
        #[unsafe(method_family = none)]
        pub fn set_required_threads_per_threadgroup(
            &self,
            required_threads_per_threadgroup: MTLSize,
        );

        /// A boolean value indicating whether the compute pipeline supports linking binary functions.
        #[unsafe(method(supportBinaryLinking))]
        #[unsafe(method_family = none)]
        pub fn support_binary_linking(&self) -> bool;

        /// Setter for [`supportBinaryLinking`][Self::supportBinaryLinking].
        #[unsafe(method(setSupportBinaryLinking:))]
        #[unsafe(method_family = none)]
        pub fn set_support_binary_linking(
            &self,
            support_binary_linking: bool,
        );

        /// An object that contains information about functions to link to the compute pipeline.
        #[unsafe(method(staticLinkingDescriptor))]
        #[unsafe(method_family = none)]
        pub fn static_linking_descriptor(&self) -> Option<Retained<MTL4StaticLinkingDescriptor>>;

        /// Setter for [`staticLinkingDescriptor`][Self::staticLinkingDescriptor].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setStaticLinkingDescriptor:))]
        #[unsafe(method_family = none)]
        pub fn set_static_linking_descriptor(
            &self,
            static_linking_descriptor: Option<&MTL4StaticLinkingDescriptor>,
        );

        /// A value indicating whether the pipeline supports Metal indirect command buffers.
        #[unsafe(method(supportIndirectCommandBuffers))]
        #[unsafe(method_family = none)]
        pub fn support_indirect_command_buffers(&self) -> MTL4IndirectCommandBufferSupportState;

        /// Setter for [`supportIndirectCommandBuffers`][Self::supportIndirectCommandBuffers].
        #[unsafe(method(setSupportIndirectCommandBuffers:))]
        #[unsafe(method_family = none)]
        pub fn set_support_indirect_command_buffers(
            &self,
            support_indirect_command_buffers: MTL4IndirectCommandBufferSupportState,
        );

        /// Resets the descriptor to its default values.
        #[unsafe(method(reset))]
        #[unsafe(method_family = none)]
        pub fn reset(&self);
    );
}

/// Methods declared on superclass `NSObject`.
impl MTL4ComputePipelineDescriptor {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;
    );
}