use objc2::{
extern_class, extern_conformance, extern_methods, msg_send,
rc::{Allocated, Retained},
runtime::{NSObject, ProtocolObject},
};
use objc2_foundation::{CopyingHelper, NSCopying, NSObjectProtocol, NSString};
use crate::{
MTLLinkedFunctions, MTLPipelineBufferDescriptorArray, MTLStageInputOutputDescriptor, library::MTLFunction,
};
extern_class!(
#[unsafe(super(NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct MTLComputePipelineDescriptor;
);
extern_conformance!(
unsafe impl NSCopying for MTLComputePipelineDescriptor {}
);
unsafe impl CopyingHelper for MTLComputePipelineDescriptor {
type Result = Self;
}
extern_conformance!(
unsafe impl NSObjectProtocol for MTLComputePipelineDescriptor {}
);
impl MTLComputePipelineDescriptor {
extern_methods!(
#[unsafe(method(computeFunction))]
#[unsafe(method_family = none)]
pub fn compute_function(&self) -> Option<Retained<ProtocolObject<dyn MTLFunction>>>;
#[unsafe(method(setComputeFunction:))]
#[unsafe(method_family = none)]
pub fn set_compute_function(
&self,
compute_function: Option<&ProtocolObject<dyn MTLFunction>>,
);
#[unsafe(method(maxTotalThreadsPerThreadgroup))]
#[unsafe(method_family = none)]
pub fn max_total_threads_per_threadgroup(&self) -> usize;
#[unsafe(method(setMaxTotalThreadsPerThreadgroup:))]
#[unsafe(method_family = none)]
pub fn set_max_total_threads_per_threadgroup(
&self,
value: usize,
);
#[unsafe(method(stageInputDescriptor))]
#[unsafe(method_family = none)]
pub fn stage_input_descriptor(&self) -> Option<Retained<MTLStageInputOutputDescriptor>>;
#[unsafe(method(setStageInputDescriptor:))]
#[unsafe(method_family = none)]
pub fn set_stage_input_descriptor(
&self,
descriptor: Option<&MTLStageInputOutputDescriptor>,
);
#[unsafe(method(buffers))]
#[unsafe(method_family = none)]
pub fn buffers(&self) -> Retained<MTLPipelineBufferDescriptorArray>;
#[unsafe(method(supportIndirectCommandBuffers))]
#[unsafe(method_family = none)]
pub fn support_indirect_command_buffers(&self) -> bool;
#[unsafe(method(setSupportIndirectCommandBuffers:))]
#[unsafe(method_family = none)]
pub fn set_support_indirect_command_buffers(
&self,
enabled: bool,
);
#[unsafe(method(linkedFunctions))]
#[unsafe(method_family = none)]
pub fn linked_functions(&self) -> Option<Retained<MTLLinkedFunctions>>;
#[unsafe(method(setLinkedFunctions:))]
#[unsafe(method_family = none)]
pub fn set_linked_functions(
&self,
linked: Option<&MTLLinkedFunctions>,
);
#[unsafe(method(reset))]
#[unsafe(method_family = none)]
pub fn reset(&self);
#[unsafe(method(shaderValidation))]
#[unsafe(method_family = none)]
pub fn shader_validation(&self) -> crate::pipeline::MTLShaderValidation;
#[unsafe(method(setShaderValidation:))]
#[unsafe(method_family = none)]
pub fn set_shader_validation(
&self,
value: crate::pipeline::MTLShaderValidation,
);
#[unsafe(method(requiredThreadsPerThreadgroup))]
#[unsafe(method_family = none)]
pub fn required_threads_per_threadgroup(&self) -> crate::types::MTLSize;
#[unsafe(method(setRequiredThreadsPerThreadgroup:))]
#[unsafe(method_family = none)]
pub fn set_required_threads_per_threadgroup(
&self,
size: crate::types::MTLSize,
);
);
}
impl MTLComputePipelineDescriptor {
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>;
);
}
#[allow(unused)]
impl MTLComputePipelineDescriptor {
fn label(&self) -> Option<String> {
let label: Option<Retained<NSString>> = unsafe { msg_send![self, label] };
label.map(|s| s.to_string())
}
fn set_label(
&self,
label: Option<&str>,
) {
unsafe {
let _: () = msg_send![self, setLabel: label.map(NSString::from_str).as_deref()];
}
}
}