| 1 |
// Copyright 2017 GFX developers |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or |
| 4 |
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or |
| 5 |
// http://opensource.org/licenses/MIT>, at your option. This file may not be |
| 6 |
// copied, modified, or distributed except according to those terms. |
| 7 |
|
| 8 |
use super::*; |
| 9 |
|
| 10 |
use objc::runtime::{NO, YES}; |
| 11 |
|
| 12 |
/// See <https://developer.apple.com/documentation/metal/mtlblendfactor> |
| 13 |
#[repr(u64)] |
| 14 |
#[allow(non_camel_case_types)] |
| 15 |
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] |
| 16 |
pub enum MTLBlendFactor { |
| 17 |
Zero = 0, |
| 18 |
One = 1, |
| 19 |
SourceColor = 2, |
| 20 |
OneMinusSourceColor = 3, |
| 21 |
SourceAlpha = 4, |
| 22 |
OneMinusSourceAlpha = 5, |
| 23 |
DestinationColor = 6, |
| 24 |
OneMinusDestinationColor = 7, |
| 25 |
DestinationAlpha = 8, |
| 26 |
OneMinusDestinationAlpha = 9, |
| 27 |
SourceAlphaSaturated = 10, |
| 28 |
BlendColor = 11, |
| 29 |
OneMinusBlendColor = 12, |
| 30 |
BlendAlpha = 13, |
| 31 |
OneMinusBlendAlpha = 14, |
| 32 |
Source1Color = 15, |
| 33 |
OneMinusSource1Color = 16, |
| 34 |
Source1Alpha = 17, |
| 35 |
OneMinusSource1Alpha = 18, |
| 36 |
} |
| 37 |
|
| 38 |
/// See <https://developer.apple.com/documentation/metal/mtlblendoperation> |
| 39 |
#[repr(u64)] |
| 40 |
#[allow(non_camel_case_types)] |
| 41 |
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] |
| 42 |
pub enum MTLBlendOperation { |
| 43 |
Add = 0, |
| 44 |
Subtract = 1, |
| 45 |
ReverseSubtract = 2, |
| 46 |
Min = 3, |
| 47 |
Max = 4, |
| 48 |
} |
| 49 |
|
| 50 |
bitflags::bitflags! { |
| 51 |
/// See <https://developer.apple.com/documentation/metal/mtlcolorwritemask> |
| 52 |
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] |
| 53 |
pub struct MTLColorWriteMask: NSUInteger { |
| 54 |
const None = 0; |
| 55 |
const Red = 0x1 << 3; |
| 56 |
const Green = 0x1 << 2; |
| 57 |
const Blue = 0x1 << 1; |
| 58 |
const Alpha = 0x1 << 0; |
| 59 |
const All = 0xf; |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
/// See <https://developer.apple.com/documentation/metal/mtlprimitivetopologyclass> |
| 64 |
#[repr(u64)] |
| 65 |
#[allow(non_camel_case_types)] |
| 66 |
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] |
| 67 |
pub enum MTLPrimitiveTopologyClass { |
| 68 |
Unspecified = 0, |
| 69 |
Point = 1, |
| 70 |
Line = 2, |
| 71 |
Triangle = 3, |
| 72 |
} |
| 73 |
|
| 74 |
// TODO: MTLTessellationPartitionMode |
| 75 |
// TODO: MTLTessellationFactorStepFunction |
| 76 |
// TODO: MTLTessellationFactorFormat |
| 77 |
// TODO: MTLTessellationControlPointIndexType |
| 78 |
|
| 79 |
/// See <https://developer.apple.com/documentation/metal/mtlrenderpipelinecolorattachmentdescriptor> |
| 80 |
pub enum MTLRenderPipelineColorAttachmentDescriptor {} |
| 81 |
|
| 82 |
foreign_obj_type! { |
| 83 |
type CType = MTLRenderPipelineColorAttachmentDescriptor; |
| 84 |
pub struct RenderPipelineColorAttachmentDescriptor; |
| 85 |
} |
| 86 |
|
| 87 |
impl RenderPipelineColorAttachmentDescriptorRef { |
| 88 |
pub fn pixel_format(&self) -> MTLPixelFormat { |
| 89 |
unsafe { msg_send![self, pixelFormat] } |
| 90 |
} |
| 91 |
|
| 92 |
pub fn set_pixel_format(&self, pixel_format: MTLPixelFormat) { |
| 93 |
unsafe { msg_send![self, setPixelFormat: pixel_format] } |
| 94 |
} |
| 95 |
|
| 96 |
pub fn is_blending_enabled(&self) -> bool { |
| 97 |
unsafe { msg_send_bool![self, isBlendingEnabled] } |
| 98 |
} |
| 99 |
|
| 100 |
pub fn set_blending_enabled(&self, enabled: bool) { |
| 101 |
unsafe { msg_send![self, setBlendingEnabled: enabled] } |
| 102 |
} |
| 103 |
|
| 104 |
pub fn source_rgb_blend_factor(&self) -> MTLBlendFactor { |
| 105 |
unsafe { msg_send![self, sourceRGBBlendFactor] } |
| 106 |
} |
| 107 |
|
| 108 |
pub fn set_source_rgb_blend_factor(&self, blend_factor: MTLBlendFactor) { |
| 109 |
unsafe { msg_send![self, setSourceRGBBlendFactor: blend_factor] } |
| 110 |
} |
| 111 |
|
| 112 |
pub fn destination_rgb_blend_factor(&self) -> MTLBlendFactor { |
| 113 |
unsafe { msg_send![self, destinationRGBBlendFactor] } |
| 114 |
} |
| 115 |
|
| 116 |
pub fn set_destination_rgb_blend_factor(&self, blend_factor: MTLBlendFactor) { |
| 117 |
unsafe { msg_send![self, setDestinationRGBBlendFactor: blend_factor] } |
| 118 |
} |
| 119 |
|
| 120 |
pub fn rgb_blend_operation(&self) -> MTLBlendOperation { |
| 121 |
unsafe { msg_send![self, rgbBlendOperation] } |
| 122 |
} |
| 123 |
|
| 124 |
pub fn set_rgb_blend_operation(&self, blend_operation: MTLBlendOperation) { |
| 125 |
unsafe { msg_send![self, setRgbBlendOperation: blend_operation] } |
| 126 |
} |
| 127 |
|
| 128 |
pub fn source_alpha_blend_factor(&self) -> MTLBlendFactor { |
| 129 |
unsafe { msg_send![self, sourceAlphaBlendFactor] } |
| 130 |
} |
| 131 |
|
| 132 |
pub fn set_source_alpha_blend_factor(&self, blend_factor: MTLBlendFactor) { |
| 133 |
unsafe { msg_send![self, setSourceAlphaBlendFactor: blend_factor] } |
| 134 |
} |
| 135 |
|
| 136 |
pub fn destination_alpha_blend_factor(&self) -> MTLBlendFactor { |
| 137 |
unsafe { msg_send![self, destinationAlphaBlendFactor] } |
| 138 |
} |
| 139 |
|
| 140 |
pub fn set_destination_alpha_blend_factor(&self, blend_factor: MTLBlendFactor) { |
| 141 |
unsafe { msg_send![self, setDestinationAlphaBlendFactor: blend_factor] } |
| 142 |
} |
| 143 |
|
| 144 |
pub fn alpha_blend_operation(&self) -> MTLBlendOperation { |
| 145 |
unsafe { msg_send![self, alphaBlendOperation] } |
| 146 |
} |
| 147 |
|
| 148 |
pub fn set_alpha_blend_operation(&self, blend_operation: MTLBlendOperation) { |
| 149 |
unsafe { msg_send![self, setAlphaBlendOperation: blend_operation] } |
| 150 |
} |
| 151 |
|
| 152 |
pub fn write_mask(&self) -> MTLColorWriteMask { |
| 153 |
unsafe { msg_send![self, writeMask] } |
| 154 |
} |
| 155 |
|
| 156 |
pub fn set_write_mask(&self, mask: MTLColorWriteMask) { |
| 157 |
unsafe { msg_send![self, setWriteMask: mask] } |
| 158 |
} |
| 159 |
} |
| 160 |
|
| 161 |
/// See <https://developer.apple.com/documentation/metal/mtlrenderpipelinereflection> |
| 162 |
pub enum MTLRenderPipelineReflection {} |
| 163 |
|
| 164 |
foreign_obj_type! { |
| 165 |
type CType = MTLRenderPipelineReflection; |
| 166 |
pub struct RenderPipelineReflection; |
| 167 |
} |
| 168 |
|
| 169 |
impl RenderPipelineReflection { |
| 170 |
#[cfg(feature = "private")] |
| 171 |
pub unsafe fn new( |
| 172 |
vertex_data: *mut std::ffi::c_void, |
| 173 |
fragment_data: *mut std::ffi::c_void, |
| 174 |
vertex_desc: *mut std::ffi::c_void, |
| 175 |
device: &DeviceRef, |
| 176 |
options: u64, |
| 177 |
flags: u64, |
| 178 |
) -> Self { |
| 179 |
let class = class!(MTLRenderPipelineReflection); |
| 180 |
let this: RenderPipelineReflection = msg_send![class, alloc]; |
| 181 |
let this_alias: *mut Object = msg_send![this.as_ref(), initWithVertexData:vertex_data |
| 182 |
fragmentData:fragment_data |
| 183 |
serializedVertexDescriptor:vertex_desc |
| 184 |
device:device |
| 185 |
options:options |
| 186 |
flags:flags]; |
| 187 |
if this_alias.is_null() { |
| 188 |
panic!("[MTLRenderPipelineReflection init] failed"); |
| 189 |
} |
| 190 |
this |
| 191 |
} |
| 192 |
} |
| 193 |
|
| 194 |
impl RenderPipelineReflectionRef { |
| 195 |
/// An array of objects that describe the arguments of a fragment function. |
| 196 |
pub fn fragment_arguments(&self) -> &ArgumentArrayRef { |
| 197 |
unsafe { msg_send![self, fragmentArguments] } |
| 198 |
} |
| 199 |
|
| 200 |
/// An array of objects that describe the arguments of a vertex function. |
| 201 |
pub fn vertex_arguments(&self) -> &ArgumentArrayRef { |
| 202 |
unsafe { msg_send![self, vertexArguments] } |
| 203 |
} |
| 204 |
|
| 205 |
/// An array of objects that describe the arguments of a tile shading function. |
| 206 |
pub fn tile_arguments(&self) -> &ArgumentArrayRef { |
| 207 |
unsafe { msg_send![self, tileArguments] } |
| 208 |
} |
| 209 |
} |
| 210 |
|
| 211 |
/// TODO: Find documentation link. |
| 212 |
pub enum MTLArgumentArray {} |
| 213 |
|
| 214 |
foreign_obj_type! { |
| 215 |
type CType = MTLArgumentArray; |
| 216 |
pub struct ArgumentArray; |
| 217 |
} |
| 218 |
|
| 219 |
impl ArgumentArrayRef { |
| 220 |
pub fn object_at(&self, index: NSUInteger) -> Option<&ArgumentRef> { |
| 221 |
unsafe { msg_send![self, objectAtIndexedSubscript: index] } |
| 222 |
} |
| 223 |
|
| 224 |
pub fn count(&self) -> NSUInteger { |
| 225 |
unsafe { msg_send![self, count] } |
| 226 |
} |
| 227 |
} |
| 228 |
|
| 229 |
/// See <https://developer.apple.com/documentation/metal/mtlcomputepipelinereflection> |
| 230 |
pub enum MTLComputePipelineReflection {} |
| 231 |
|
| 232 |
foreign_obj_type! { |
| 233 |
type CType = MTLComputePipelineReflection; |
| 234 |
pub struct ComputePipelineReflection; |
| 235 |
} |
| 236 |
|
| 237 |
impl ComputePipelineReflectionRef { |
| 238 |
/// An array of objects that describe the arguments of a compute function. |
| 239 |
pub fn arguments(&self) -> &ArgumentArrayRef { |
| 240 |
unsafe { msg_send![self, arguments] } |
| 241 |
} |
| 242 |
} |
| 243 |
|
| 244 |
/// See <https://developer.apple.com/documentation/metal/mtlmeshrenderpipelinedescriptor> |
| 245 |
/// Only available in (macos(13.0), ios(16.0)) |
| 246 |
pub enum MTLMeshRenderPipelineDescriptor {} |
| 247 |
|
| 248 |
foreign_obj_type! { |
| 249 |
type CType = MTLMeshRenderPipelineDescriptor; |
| 250 |
pub struct MeshRenderPipelineDescriptor; |
| 251 |
} |
| 252 |
|
| 253 |
impl MeshRenderPipelineDescriptor { |
| 254 |
pub fn new() -> Self { |
| 255 |
unsafe { |
| 256 |
let class = class!(MTLMeshRenderPipelineDescriptor); |
| 257 |
msg_send![class, new] |
| 258 |
} |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
impl MeshRenderPipelineDescriptorRef { |
| 263 |
pub fn color_attachments(&self) -> &RenderPipelineColorAttachmentDescriptorArrayRef { |
| 264 |
unsafe { msg_send![self, colorAttachments] } |
| 265 |
} |
| 266 |
|
| 267 |
pub fn depth_attachment_pixel_format(&self) -> MTLPixelFormat { |
| 268 |
unsafe { msg_send![self, depthAttachmentPixelFormat] } |
| 269 |
} |
| 270 |
|
| 271 |
pub fn set_depth_attachment_pixel_format(&self, pixel_format: MTLPixelFormat) { |
| 272 |
unsafe { msg_send![self, setDepthAttachmentPixelFormat: pixel_format] } |
| 273 |
} |
| 274 |
|
| 275 |
pub fn fragment_buffers(&self) -> Option<&PipelineBufferDescriptorArrayRef> { |
| 276 |
unsafe { msg_send![self, fragmentBuffers] } |
| 277 |
} |
| 278 |
|
| 279 |
pub fn fragment_function(&self) -> Option<&FunctionRef> { |
| 280 |
unsafe { msg_send![self, fragmentFunction] } |
| 281 |
} |
| 282 |
|
| 283 |
pub fn set_fragment_function(&self, function: Option<&FunctionRef>) { |
| 284 |
unsafe { msg_send![self, setFragmentFunction: function] } |
| 285 |
} |
| 286 |
|
| 287 |
pub fn is_alpha_to_coverage_enabled(&self) -> bool { |
| 288 |
unsafe { msg_send_bool![self, isAlphaToCoverageEnabled] } |
| 289 |
} |
| 290 |
|
| 291 |
pub fn set_alpha_to_coverage_enabled(&self, enabled: bool) { |
| 292 |
unsafe { msg_send![self, setAlphaToCoverageEnabled: enabled] } |
| 293 |
} |
| 294 |
|
| 295 |
pub fn is_alpha_to_one_enabled(&self) -> bool { |
| 296 |
unsafe { msg_send_bool![self, isAlphaToOneEnabled] } |
| 297 |
} |
| 298 |
|
| 299 |
pub fn set_alpha_to_one_enabled(&self, enabled: bool) { |
| 300 |
unsafe { msg_send![self, setAlphaToOneEnabled: enabled] } |
| 301 |
} |
| 302 |
|
| 303 |
pub fn is_rasterization_enabled(&self) -> bool { |
| 304 |
unsafe { msg_send_bool![self, isRasterizationEnabled] } |
| 305 |
} |
| 306 |
|
| 307 |
pub fn set_rasterization_enabled(&self, enabled: bool) { |
| 308 |
unsafe { msg_send![self, setRasterizationEnabled: enabled] } |
| 309 |
} |
| 310 |
|
| 311 |
pub fn label(&self) -> &str { |
| 312 |
unsafe { |
| 313 |
let label = msg_send![self, label]; |
| 314 |
crate::nsstring_as_str(label) |
| 315 |
} |
| 316 |
} |
| 317 |
|
| 318 |
pub fn set_label(&self, label: &str) { |
| 319 |
unsafe { |
| 320 |
let nslabel = crate::nsstring_from_str(label); |
| 321 |
let () = msg_send![self, setLabel: nslabel]; |
| 322 |
} |
| 323 |
} |
| 324 |
|
| 325 |
pub fn max_total_threadgroups_per_mesh_grid(&self) -> NSUInteger { |
| 326 |
unsafe { msg_send![self, maxTotalThreadgroupsPerMeshGrid] } |
| 327 |
} |
| 328 |
|
| 329 |
pub fn set_max_total_threadgroups_per_mesh_grid( |
| 330 |
&self, |
| 331 |
max_total_threadgroups_per_mesh_grid: NSUInteger, |
| 332 |
) { |
| 333 |
unsafe { |
| 334 |
msg_send![ |
| 335 |
self, |
| 336 |
setMaxTotalThreadgroupsPerMeshGrid: max_total_threadgroups_per_mesh_grid |
| 337 |
] |
| 338 |
} |
| 339 |
} |
| 340 |
|
| 341 |
pub fn max_total_threads_per_mesh_threadgroup(&self) -> NSUInteger { |
| 342 |
unsafe { msg_send![self, maxTotalThreadsPerMeshThreadgroup] } |
| 343 |
} |
| 344 |
|
| 345 |
pub fn set_max_total_threads_per_mesh_threadgroup( |
| 346 |
&self, |
| 347 |
max_total_threads_per_mesh_threadgroup: NSUInteger, |
| 348 |
) { |
| 349 |
unsafe { |
| 350 |
msg_send![ |
| 351 |
self, |
| 352 |
setMaxTotalThreadsPerMeshThreadgroup: max_total_threads_per_mesh_threadgroup |
| 353 |
] |
| 354 |
} |
| 355 |
} |
| 356 |
|
| 357 |
pub fn max_total_threads_per_object_threadgroup(&self) -> NSUInteger { |
| 358 |
unsafe { msg_send![self, maxTotalThreadsPerObjectThreadgroup] } |
| 359 |
} |
| 360 |
|
| 361 |
pub fn set_max_total_threads_per_object_threadgroup( |
| 362 |
&self, |
| 363 |
max_total_threads_per_object_threadgroup: NSUInteger, |
| 364 |
) { |
| 365 |
unsafe { |
| 366 |
msg_send![ |
| 367 |
self, |
| 368 |
setMaxTotalThreadsPerObjectThreadgroup: max_total_threads_per_object_threadgroup |
| 369 |
] |
| 370 |
} |
| 371 |
} |
| 372 |
|
| 373 |
pub fn max_vertex_amplification_count(&self) -> NSUInteger { |
| 374 |
unsafe { msg_send![self, maxVertexAmplificationCount] } |
| 375 |
} |
| 376 |
|
| 377 |
pub fn set_max_vertex_amplification_count(&self, max_vertex_amplification_count: NSUInteger) { |
| 378 |
unsafe { |
| 379 |
msg_send![ |
| 380 |
self, |
| 381 |
setMaxVertexAmplificationCount: max_vertex_amplification_count |
| 382 |
] |
| 383 |
} |
| 384 |
} |
| 385 |
|
| 386 |
pub fn mesh_buffers(&self) -> Option<&PipelineBufferDescriptorArrayRef> { |
| 387 |
unsafe { msg_send![self, meshBuffers] } |
| 388 |
} |
| 389 |
|
| 390 |
pub fn mesh_function(&self) -> Option<&FunctionRef> { |
| 391 |
unsafe { msg_send![self, meshFunction] } |
| 392 |
} |
| 393 |
|
| 394 |
pub fn set_mesh_function(&self, function: Option<&FunctionRef>) { |
| 395 |
unsafe { msg_send![self, setMeshFunction: function] } |
| 396 |
} |
| 397 |
|
| 398 |
pub fn mesh_threadgroup_size_is_multiple_of_thread_execution_width(&self) -> bool { |
| 399 |
unsafe { msg_send_bool![self, isMeshThreadgroupSizeIsMultipleOfThreadExecutionWidth] } |
| 400 |
} |
| 401 |
|
| 402 |
pub fn set_mesh_threadgroup_size_is_multiple_of_thread_execution_width( |
| 403 |
&self, |
| 404 |
mesh_threadgroup_size_is_multiple_of_thread_execution_width: bool, |
| 405 |
) { |
| 406 |
unsafe { |
| 407 |
msg_send![ |
| 408 |
self, |
| 409 |
setMeshThreadgroupSizeIsMultipleOfThreadExecutionWidth: |
| 410 |
mesh_threadgroup_size_is_multiple_of_thread_execution_width |
| 411 |
] |
| 412 |
} |
| 413 |
} |
| 414 |
|
| 415 |
pub fn object_buffers(&self) -> Option<&PipelineBufferDescriptorArrayRef> { |
| 416 |
unsafe { msg_send![self, objectBuffers] } |
| 417 |
} |
| 418 |
|
| 419 |
pub fn object_function(&self) -> Option<&FunctionRef> { |
| 420 |
unsafe { msg_send![self, objectFunction] } |
| 421 |
} |
| 422 |
|
| 423 |
pub fn set_object_function(&self, function: Option<&FunctionRef>) { |
| 424 |
unsafe { msg_send![self, setObjectFunction: function] } |
| 425 |
} |
| 426 |
|
| 427 |
pub fn object_threadgroup_size_is_multiple_of_thread_execution_width(&self) -> bool { |
| 428 |
unsafe { |
| 429 |
msg_send_bool![ |
| 430 |
self, |
| 431 |
isObjectThreadgroupSizeIsMultipleOfThreadExecutionWidth |
| 432 |
] |
| 433 |
} |
| 434 |
} |
| 435 |
|
| 436 |
pub fn set_object_threadgroup_size_is_multiple_of_thread_execution_width( |
| 437 |
&self, |
| 438 |
object_threadgroup_size_is_multiple_of_thread_execution_width: bool, |
| 439 |
) { |
| 440 |
unsafe { |
| 441 |
msg_send![ |
| 442 |
self, |
| 443 |
setObjectThreadgroupSizeIsMultipleOfThreadExecutionWidth: |
| 444 |
object_threadgroup_size_is_multiple_of_thread_execution_width |
| 445 |
] |
| 446 |
} |
| 447 |
} |
| 448 |
|
| 449 |
pub fn payload_memory_length(&self) -> NSUInteger { |
| 450 |
unsafe { msg_send![self, payloadMemoryLength] } |
| 451 |
} |
| 452 |
|
| 453 |
pub fn set_payload_memory_length(&self, payload_memory_length: NSUInteger) { |
| 454 |
unsafe { msg_send![self, setPayloadMemoryLength: payload_memory_length] } |
| 455 |
} |
| 456 |
|
| 457 |
pub fn raster_sample_count(&self) -> NSUInteger { |
| 458 |
unsafe { msg_send![self, rasterSampleCount] } |
| 459 |
} |
| 460 |
|
| 461 |
pub fn set_raster_sample_count(&self, raster_sample_count: NSUInteger) { |
| 462 |
unsafe { msg_send![self, setRasterSampleCount: raster_sample_count] } |
| 463 |
} |
| 464 |
|
| 465 |
pub fn stencil_attachment_pixel_format(&self) -> MTLPixelFormat { |
| 466 |
unsafe { msg_send![self, stencilAttachmentPixelFormat] } |
| 467 |
} |
| 468 |
|
| 469 |
pub fn set_stencil_attachment_pixel_format(&self, pixel_format: MTLPixelFormat) { |
| 470 |
unsafe { msg_send![self, setStencilAttachmentPixelFormat: pixel_format] } |
| 471 |
} |
| 472 |
|
| 473 |
pub fn reset(&self) { |
| 474 |
unsafe { msg_send![self, reset] } |
| 475 |
} |
| 476 |
} |
| 477 |
|
| 478 |
/// See <https://developer.apple.com/documentation/metal/mtlrenderpipelinedescriptor> |
| 479 |
pub enum MTLRenderPipelineDescriptor {} |
| 480 |
|
| 481 |
foreign_obj_type! { |
| 482 |
type CType = MTLRenderPipelineDescriptor; |
| 483 |
pub struct RenderPipelineDescriptor; |
| 484 |
} |
| 485 |
|
| 486 |
impl RenderPipelineDescriptor { |
| 487 |
pub fn new() -> Self { |
| 488 |
unsafe { |
| 489 |
let class = class!(MTLRenderPipelineDescriptor); |
| 490 |
msg_send![class, new] |
| 491 |
} |
| 492 |
} |
| 493 |
} |
| 494 |
|
| 495 |
impl RenderPipelineDescriptorRef { |
| 496 |
pub fn label(&self) -> &str { |
| 497 |
unsafe { |
| 498 |
let label = msg_send![self, label]; |
| 499 |
crate::nsstring_as_str(label) |
| 500 |
} |
| 501 |
} |
| 502 |
|
| 503 |
pub fn set_label(&self, label: &str) { |
| 504 |
unsafe { |
| 505 |
let nslabel = crate::nsstring_from_str(label); |
| 506 |
let () = msg_send![self, setLabel: nslabel]; |
| 507 |
} |
| 508 |
} |
| 509 |
|
| 510 |
pub fn vertex_function(&self) -> Option<&FunctionRef> { |
| 511 |
unsafe { msg_send![self, vertexFunction] } |
| 512 |
} |
| 513 |
|
| 514 |
pub fn set_vertex_function(&self, function: Option<&FunctionRef>) { |
| 515 |
unsafe { msg_send![self, setVertexFunction: function] } |
| 516 |
} |
| 517 |
|
| 518 |
pub fn fragment_function(&self) -> Option<&FunctionRef> { |
| 519 |
unsafe { msg_send![self, fragmentFunction] } |
| 520 |
} |
| 521 |
|
| 522 |
pub fn set_fragment_function(&self, function: Option<&FunctionRef>) { |
| 523 |
unsafe { msg_send![self, setFragmentFunction: function] } |
| 524 |
} |
| 525 |
|
| 526 |
pub fn vertex_descriptor(&self) -> Option<&VertexDescriptorRef> { |
| 527 |
unsafe { msg_send![self, vertexDescriptor] } |
| 528 |
} |
| 529 |
|
| 530 |
pub fn set_vertex_descriptor(&self, descriptor: Option<&VertexDescriptorRef>) { |
| 531 |
unsafe { msg_send![self, setVertexDescriptor: descriptor] } |
| 532 |
} |
| 533 |
|
| 534 |
/// DEPRECATED - aliases rasterSampleCount property |
| 535 |
pub fn sample_count(&self) -> NSUInteger { |
| 536 |
unsafe { msg_send![self, sampleCount] } |
| 537 |
} |
| 538 |
|
| 539 |
/// DEPRECATED - aliases rasterSampleCount property |
| 540 |
pub fn set_sample_count(&self, count: NSUInteger) { |
| 541 |
unsafe { msg_send![self, setSampleCount: count] } |
| 542 |
} |
| 543 |
|
| 544 |
pub fn raster_sample_count(&self) -> NSUInteger { |
| 545 |
unsafe { msg_send![self, rasterSampleCount] } |
| 546 |
} |
| 547 |
|
| 548 |
pub fn set_raster_sample_count(&self, count: NSUInteger) { |
| 549 |
unsafe { msg_send![self, setRasterSampleCount: count] } |
| 550 |
} |
| 551 |
|
| 552 |
pub fn max_vertex_amplification_count(&self) -> NSUInteger { |
| 553 |
unsafe { msg_send![self, maxVertexAmplificationCount] } |
| 554 |
} |
| 555 |
|
| 556 |
pub fn set_max_vertex_amplification_count(&self, count: NSUInteger) { |
| 557 |
unsafe { msg_send![self, setMaxVertexAmplificationCount: count] } |
| 558 |
} |
| 559 |
|
| 560 |
pub fn is_alpha_to_coverage_enabled(&self) -> bool { |
| 561 |
unsafe { msg_send_bool![self, isAlphaToCoverageEnabled] } |
| 562 |
} |
| 563 |
|
| 564 |
pub fn set_alpha_to_coverage_enabled(&self, enabled: bool) { |
| 565 |
unsafe { msg_send![self, setAlphaToCoverageEnabled: enabled] } |
| 566 |
} |
| 567 |
|
| 568 |
pub fn is_alpha_to_one_enabled(&self) -> bool { |
| 569 |
unsafe { msg_send_bool![self, isAlphaToOneEnabled] } |
| 570 |
} |
| 571 |
|
| 572 |
pub fn set_alpha_to_one_enabled(&self, enabled: bool) { |
| 573 |
unsafe { msg_send![self, setAlphaToOneEnabled: enabled] } |
| 574 |
} |
| 575 |
|
| 576 |
pub fn is_rasterization_enabled(&self) -> bool { |
| 577 |
unsafe { msg_send_bool![self, isRasterizationEnabled] } |
| 578 |
} |
| 579 |
|
| 580 |
pub fn set_rasterization_enabled(&self, enabled: bool) { |
| 581 |
unsafe { msg_send![self, setRasterizationEnabled: enabled] } |
| 582 |
} |
| 583 |
|
| 584 |
pub fn color_attachments(&self) -> &RenderPipelineColorAttachmentDescriptorArrayRef { |
| 585 |
unsafe { msg_send![self, colorAttachments] } |
| 586 |
} |
| 587 |
|
| 588 |
pub fn depth_attachment_pixel_format(&self) -> MTLPixelFormat { |
| 589 |
unsafe { msg_send![self, depthAttachmentPixelFormat] } |
| 590 |
} |
| 591 |
|
| 592 |
pub fn set_depth_attachment_pixel_format(&self, pixel_format: MTLPixelFormat) { |
| 593 |
unsafe { msg_send![self, setDepthAttachmentPixelFormat: pixel_format] } |
| 594 |
} |
| 595 |
|
| 596 |
pub fn stencil_attachment_pixel_format(&self) -> MTLPixelFormat { |
| 597 |
unsafe { msg_send![self, stencilAttachmentPixelFormat] } |
| 598 |
} |
| 599 |
|
| 600 |
pub fn set_stencil_attachment_pixel_format(&self, pixel_format: MTLPixelFormat) { |
| 601 |
unsafe { msg_send![self, setStencilAttachmentPixelFormat: pixel_format] } |
| 602 |
} |
| 603 |
|
| 604 |
pub fn input_primitive_topology(&self) -> MTLPrimitiveTopologyClass { |
| 605 |
unsafe { msg_send![self, inputPrimitiveTopology] } |
| 606 |
} |
| 607 |
|
| 608 |
pub fn set_input_primitive_topology(&self, topology: MTLPrimitiveTopologyClass) { |
| 609 |
unsafe { msg_send![self, setInputPrimitiveTopology: topology] } |
| 610 |
} |
| 611 |
|
| 612 |
#[cfg(feature = "private")] |
| 613 |
pub unsafe fn serialize_vertex_data(&self) -> *mut std::ffi::c_void { |
| 614 |
use std::ptr; |
| 615 |
let flags = 0; |
| 616 |
let err: *mut Object = ptr::null_mut(); |
| 617 |
msg_send![self, newSerializedVertexDataWithFlags:flags |
| 618 |
error:err] |
| 619 |
} |
| 620 |
|
| 621 |
#[cfg(feature = "private")] |
| 622 |
pub unsafe fn serialize_fragment_data(&self) -> *mut std::ffi::c_void { |
| 623 |
msg_send![self, serializeFragmentData] |
| 624 |
} |
| 625 |
|
| 626 |
pub fn support_indirect_command_buffers(&self) -> bool { |
| 627 |
unsafe { msg_send_bool![self, supportIndirectCommandBuffers] } |
| 628 |
} |
| 629 |
|
| 630 |
pub fn set_support_indirect_command_buffers(&self, support: bool) { |
| 631 |
unsafe { msg_send![self, setSupportIndirectCommandBuffers: support] } |
| 632 |
} |
| 633 |
|
| 634 |
pub fn vertex_buffers(&self) -> Option<&PipelineBufferDescriptorArrayRef> { |
| 635 |
unsafe { msg_send![self, vertexBuffers] } |
| 636 |
} |
| 637 |
|
| 638 |
pub fn fragment_buffers(&self) -> Option<&PipelineBufferDescriptorArrayRef> { |
| 639 |
unsafe { msg_send![self, fragmentBuffers] } |
| 640 |
} |
| 641 |
|
| 642 |
// TODO: tesselation stuff |
| 643 |
|
| 644 |
/// API_AVAILABLE(macos(11.0), ios(14.0)); |
| 645 |
/// Marshal to Rust Vec |
| 646 |
pub fn binary_archives(&self) -> Vec<BinaryArchive> { |
| 647 |
unsafe { |
| 648 |
let archives: *mut Object = msg_send![self, binaryArchives]; |
| 649 |
let count: NSUInteger = msg_send![archives, count]; |
| 650 |
(0..count) |
| 651 |
.map(|i| { |
| 652 |
let a = msg_send![archives, objectAtIndex: i]; |
| 653 |
BinaryArchive::from_ptr(a) |
| 654 |
}) |
| 655 |
.collect() |
| 656 |
} |
| 657 |
} |
| 658 |
|
| 659 |
/// API_AVAILABLE(macos(11.0), ios(14.0)); |
| 660 |
/// Marshal from Rust slice |
| 661 |
pub fn set_binary_archives(&self, archives: &[&BinaryArchiveRef]) { |
| 662 |
let ns_array = Array::<BinaryArchive>::from_slice(archives); |
| 663 |
unsafe { msg_send![self, setBinaryArchives: ns_array] } |
| 664 |
} |
| 665 |
|
| 666 |
/// API_AVAILABLE(macos(11.0), ios(14.0)); |
| 667 |
pub fn fragment_linked_functions(&self) -> &LinkedFunctionsRef { |
| 668 |
unsafe { msg_send![self, fragmentLinkedFunctions] } |
| 669 |
} |
| 670 |
|
| 671 |
/// API_AVAILABLE(macos(11.0), ios(14.0)); |
| 672 |
pub fn set_fragment_linked_functions(&self, functions: &LinkedFunctionsRef) { |
| 673 |
unsafe { msg_send![self, setFragmentLinkedFunctions: functions] } |
| 674 |
} |
| 675 |
|
| 676 |
pub fn reset(&self) { |
| 677 |
unsafe { msg_send![self, reset] } |
| 678 |
} |
| 679 |
} |
| 680 |
|
| 681 |
/// See <https://developer.apple.com/documentation/metal/mtlrenderpipelinestate> |
| 682 |
pub enum MTLRenderPipelineState {} |
| 683 |
|
| 684 |
foreign_obj_type! { |
| 685 |
type CType = MTLRenderPipelineState; |
| 686 |
pub struct RenderPipelineState; |
| 687 |
} |
| 688 |
|
| 689 |
impl RenderPipelineStateRef { |
| 690 |
pub fn device(&self) -> &DeviceRef { |
| 691 |
unsafe { msg_send![self, device] } |
| 692 |
} |
| 693 |
|
| 694 |
pub fn label(&self) -> &str { |
| 695 |
unsafe { |
| 696 |
let label = msg_send![self, label]; |
| 697 |
crate::nsstring_as_str(label) |
| 698 |
} |
| 699 |
} |
| 700 |
|
| 701 |
/// Only available on (macos(11.0), ios(14.0)) |
| 702 |
pub fn new_intersection_function_table_with_descriptor( |
| 703 |
&self, |
| 704 |
descriptor: &IntersectionFunctionTableDescriptorRef, |
| 705 |
stage: MTLRenderStages, |
| 706 |
) -> IntersectionFunctionTable { |
| 707 |
unsafe { |
| 708 |
msg_send![self, newIntersectionFunctionTableWithDescriptor: descriptor |
| 709 |
stage:stage] |
| 710 |
} |
| 711 |
} |
| 712 |
|
| 713 |
/// Only available on (macos(11.0), ios(14.0)) |
| 714 |
pub fn function_handle_with_function( |
| 715 |
&self, |
| 716 |
function: &FunctionRef, |
| 717 |
stage: MTLRenderStages, |
| 718 |
) -> Option<&FunctionHandleRef> { |
| 719 |
unsafe { |
| 720 |
msg_send![self, functionHandleWithFunction: function |
| 721 |
stage:stage] |
| 722 |
} |
| 723 |
} |
| 724 |
|
| 725 |
/// Only available on (macos(11.0), ios(14.0)) |
| 726 |
pub fn new_visible_function_table_with_descriptor( |
| 727 |
&self, |
| 728 |
descriptor: &VisibleFunctionTableDescriptorRef, |
| 729 |
stage: MTLRenderStages, |
| 730 |
) -> VisibleFunctionTable { |
| 731 |
unsafe { msg_send![self, newVisibleFunctionTableWithDescriptor: descriptor stage:stage] } |
| 732 |
} |
| 733 |
} |
| 734 |
|
| 735 |
/// See <https://developer.apple.com/documentation/metal/mtlrenderpipelinecolorattachmentdescriptorarray> |
| 736 |
pub enum MTLRenderPipelineColorAttachmentDescriptorArray {} |
| 737 |
|
| 738 |
foreign_obj_type! { |
| 739 |
type CType = MTLRenderPipelineColorAttachmentDescriptorArray; |
| 740 |
pub struct RenderPipelineColorAttachmentDescriptorArray; |
| 741 |
} |
| 742 |
|
| 743 |
impl RenderPipelineColorAttachmentDescriptorArrayRef { |
| 744 |
pub fn object_at( |
| 745 |
&self, |
| 746 |
index: NSUInteger, |
| 747 |
) -> Option<&RenderPipelineColorAttachmentDescriptorRef> { |
| 748 |
unsafe { msg_send![self, objectAtIndexedSubscript: index] } |
| 749 |
} |
| 750 |
|
| 751 |
pub fn set_object_at( |
| 752 |
&self, |
| 753 |
index: NSUInteger, |
| 754 |
attachment: Option<&RenderPipelineColorAttachmentDescriptorRef>, |
| 755 |
) { |
| 756 |
unsafe { |
| 757 |
msg_send![self, setObject:attachment |
| 758 |
atIndexedSubscript:index] |
| 759 |
} |
| 760 |
} |
| 761 |
} |