| 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::{MTLTextureType, NSUInteger}; |
| 9 |
use objc::runtime::{NO, YES}; |
| 10 |
|
| 11 |
/// See <https://developer.apple.com/documentation/metal/mtldatatype> |
| 12 |
#[repr(u64)] |
| 13 |
#[allow(non_camel_case_types)] |
| 14 |
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] |
| 15 |
pub enum MTLDataType { |
| 16 |
None = 0, |
| 17 |
|
| 18 |
Struct = 1, |
| 19 |
Array = 2, |
| 20 |
|
| 21 |
Float = 3, |
| 22 |
Float2 = 4, |
| 23 |
Float3 = 5, |
| 24 |
Float4 = 6, |
| 25 |
|
| 26 |
Float2x2 = 7, |
| 27 |
Float2x3 = 8, |
| 28 |
Float2x4 = 9, |
| 29 |
|
| 30 |
Float3x2 = 10, |
| 31 |
Float3x3 = 11, |
| 32 |
Float3x4 = 12, |
| 33 |
|
| 34 |
Float4x2 = 13, |
| 35 |
Float4x3 = 14, |
| 36 |
Float4x4 = 15, |
| 37 |
|
| 38 |
Half = 16, |
| 39 |
Half2 = 17, |
| 40 |
Half3 = 18, |
| 41 |
Half4 = 19, |
| 42 |
|
| 43 |
Half2x2 = 20, |
| 44 |
Half2x3 = 21, |
| 45 |
Half2x4 = 22, |
| 46 |
|
| 47 |
Half3x2 = 23, |
| 48 |
Half3x3 = 24, |
| 49 |
Half3x4 = 25, |
| 50 |
|
| 51 |
Half4x2 = 26, |
| 52 |
Half4x3 = 27, |
| 53 |
Half4x4 = 28, |
| 54 |
|
| 55 |
Int = 29, |
| 56 |
Int2 = 30, |
| 57 |
Int3 = 31, |
| 58 |
Int4 = 32, |
| 59 |
|
| 60 |
UInt = 33, |
| 61 |
UInt2 = 34, |
| 62 |
UInt3 = 35, |
| 63 |
UInt4 = 36, |
| 64 |
|
| 65 |
Short = 37, |
| 66 |
Short2 = 38, |
| 67 |
Short3 = 39, |
| 68 |
Short4 = 40, |
| 69 |
|
| 70 |
UShort = 41, |
| 71 |
UShort2 = 42, |
| 72 |
UShort3 = 43, |
| 73 |
UShort4 = 44, |
| 74 |
|
| 75 |
Char = 45, |
| 76 |
Char2 = 46, |
| 77 |
Char3 = 47, |
| 78 |
Char4 = 48, |
| 79 |
|
| 80 |
UChar = 49, |
| 81 |
UChar2 = 50, |
| 82 |
UChar3 = 51, |
| 83 |
UChar4 = 52, |
| 84 |
|
| 85 |
Bool = 53, |
| 86 |
Bool2 = 54, |
| 87 |
Bool3 = 55, |
| 88 |
Bool4 = 56, |
| 89 |
|
| 90 |
Texture = 58, |
| 91 |
Sampler = 59, |
| 92 |
Pointer = 60, |
| 93 |
R8Unorm = 62, |
| 94 |
R8Snorm = 63, |
| 95 |
R16Unorm = 64, |
| 96 |
R16Snorm = 65, |
| 97 |
RG8Unorm = 66, |
| 98 |
RG8Snorm = 67, |
| 99 |
RG16Unorm = 68, |
| 100 |
RG16Snorm = 69, |
| 101 |
RGBA8Unorm = 70, |
| 102 |
RGBA8Unorm_sRGB = 71, |
| 103 |
RGBA8Snorm = 72, |
| 104 |
RGBA16Unorm = 73, |
| 105 |
RGBA16Snorm = 74, |
| 106 |
RGB10A2Unorm = 75, |
| 107 |
RG11B10Float = 76, |
| 108 |
RGB9E5Float = 77, |
| 109 |
|
| 110 |
RenderPipeline = 78, |
| 111 |
ComputePipeline = 79, |
| 112 |
IndirectCommandBuffer = 80, |
| 113 |
|
| 114 |
Long = 81, |
| 115 |
Long2 = 82, |
| 116 |
Long3 = 83, |
| 117 |
Long4 = 84, |
| 118 |
|
| 119 |
ULong = 85, |
| 120 |
ULong2 = 86, |
| 121 |
ULong3 = 87, |
| 122 |
ULong4 = 88, |
| 123 |
|
| 124 |
VisibleFunctionTable = 115, |
| 125 |
IntersectionFunctionTable = 116, |
| 126 |
PrimitiveAccelerationStructure = 117, |
| 127 |
InstanceAccelerationStructure = 118, |
| 128 |
|
| 129 |
BFloat = 121, |
| 130 |
BFloat2 = 122, |
| 131 |
BFloat3 = 123, |
| 132 |
BFloat4 = 124, |
| 133 |
} |
| 134 |
|
| 135 |
/// See <https://developer.apple.com/documentation/metal/mtlargumenttype> |
| 136 |
#[repr(u64)] |
| 137 |
#[deprecated( |
| 138 |
note = "Since: iOS 8.0–16.0, iPadOS 8.0–16.0, macOS 10.11–13.0, Mac Catalyst 13.1–16.0, tvOS 9.0–16.0" |
| 139 |
)] |
| 140 |
#[allow(non_camel_case_types)] |
| 141 |
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] |
| 142 |
pub enum MTLArgumentType { |
| 143 |
Buffer = 0, |
| 144 |
ThreadgroupMemory = 1, |
| 145 |
Texture = 2, |
| 146 |
Sampler = 3, |
| 147 |
ImageblockData = 16, |
| 148 |
Imageblock = 17, |
| 149 |
} |
| 150 |
|
| 151 |
/// See <https://developer.apple.com/documentation/metal/mtlargumentaccess> |
| 152 |
#[repr(u64)] |
| 153 |
#[allow(non_camel_case_types)] |
| 154 |
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] |
| 155 |
pub enum MTLArgumentAccess { |
| 156 |
ReadOnly = 0, |
| 157 |
ReadWrite = 1, |
| 158 |
WriteOnly = 2, |
| 159 |
} |
| 160 |
|
| 161 |
/// See <https://developer.apple.com/documentation/metal/mtlstructmember> |
| 162 |
pub enum MTLStructMember {} |
| 163 |
|
| 164 |
foreign_obj_type! { |
| 165 |
type CType = MTLStructMember; |
| 166 |
pub struct StructMember; |
| 167 |
} |
| 168 |
|
| 169 |
impl StructMemberRef { |
| 170 |
pub fn name(&self) -> &str { |
| 171 |
unsafe { |
| 172 |
let name = msg_send![self, name]; |
| 173 |
crate::nsstring_as_str(name) |
| 174 |
} |
| 175 |
} |
| 176 |
|
| 177 |
pub fn offset(&self) -> NSUInteger { |
| 178 |
unsafe { msg_send![self, offset] } |
| 179 |
} |
| 180 |
|
| 181 |
pub fn data_type(&self) -> MTLDataType { |
| 182 |
unsafe { msg_send![self, dataType] } |
| 183 |
} |
| 184 |
|
| 185 |
pub fn struct_type(&self) -> MTLStructType { |
| 186 |
unsafe { msg_send![self, structType] } |
| 187 |
} |
| 188 |
|
| 189 |
pub fn array_type(&self) -> MTLArrayType { |
| 190 |
unsafe { msg_send![self, arrayType] } |
| 191 |
} |
| 192 |
} |
| 193 |
|
| 194 |
pub enum MTLStructMemberArray {} |
| 195 |
|
| 196 |
foreign_obj_type! { |
| 197 |
type CType = MTLStructMemberArray; |
| 198 |
pub struct StructMemberArray; |
| 199 |
} |
| 200 |
|
| 201 |
impl StructMemberArrayRef { |
| 202 |
pub fn object_at(&self, index: NSUInteger) -> Option<&StructMemberRef> { |
| 203 |
unsafe { msg_send![self, objectAtIndexedSubscript: index] } |
| 204 |
} |
| 205 |
|
| 206 |
pub fn count(&self) -> NSUInteger { |
| 207 |
unsafe { msg_send![self, count] } |
| 208 |
} |
| 209 |
} |
| 210 |
|
| 211 |
/// See <https://developer.apple.com/documentation/metal/mtlstructtype> |
| 212 |
pub enum MTLStructType {} |
| 213 |
|
| 214 |
foreign_obj_type! { |
| 215 |
type CType = MTLStructType; |
| 216 |
pub struct StructType; |
| 217 |
} |
| 218 |
|
| 219 |
impl StructTypeRef { |
| 220 |
pub fn members(&self) -> &StructMemberArrayRef { |
| 221 |
unsafe { msg_send![self, members] } |
| 222 |
} |
| 223 |
|
| 224 |
pub fn member_from_name(&self, name: &str) -> Option<&StructMemberRef> { |
| 225 |
let nsname = crate::nsstring_from_str(name); |
| 226 |
|
| 227 |
unsafe { msg_send![self, memberByName: nsname] } |
| 228 |
} |
| 229 |
} |
| 230 |
|
| 231 |
/// See <https://developer.apple.com/documentation/metal/mtlarraytype> |
| 232 |
pub enum MTLArrayType {} |
| 233 |
|
| 234 |
foreign_obj_type! { |
| 235 |
type CType = MTLArrayType; |
| 236 |
pub struct ArrayType; |
| 237 |
} |
| 238 |
|
| 239 |
impl ArrayTypeRef { |
| 240 |
pub fn array_length(&self) -> NSUInteger { |
| 241 |
unsafe { msg_send![self, arrayLength] } |
| 242 |
} |
| 243 |
|
| 244 |
pub fn stride(&self) -> NSUInteger { |
| 245 |
unsafe { msg_send![self, stride] } |
| 246 |
} |
| 247 |
|
| 248 |
pub fn element_type(&self) -> MTLDataType { |
| 249 |
unsafe { msg_send![self, elementType] } |
| 250 |
} |
| 251 |
|
| 252 |
pub fn element_struct_type(&self) -> MTLStructType { |
| 253 |
unsafe { msg_send![self, elementStructType] } |
| 254 |
} |
| 255 |
|
| 256 |
pub fn element_array_type(&self) -> MTLArrayType { |
| 257 |
unsafe { msg_send![self, elementArrayType] } |
| 258 |
} |
| 259 |
} |
| 260 |
|
| 261 |
/// <https://developer.apple.com/documentation/metal/mtlargument> |
| 262 |
#[deprecated( |
| 263 |
note = "Since iOS 8.0–16.0, iPadOS 8.0–16.0, macOS 10.11–13.0, Mac Catalyst 13.1–16.0, tvOS 9.0–16.0" |
| 264 |
)] |
| 265 |
pub enum MTLArgument {} |
| 266 |
|
| 267 |
foreign_obj_type! { |
| 268 |
type CType = MTLArgument; |
| 269 |
pub struct Argument; |
| 270 |
} |
| 271 |
|
| 272 |
impl ArgumentRef { |
| 273 |
pub fn name(&self) -> &str { |
| 274 |
unsafe { |
| 275 |
let name = msg_send![self, name]; |
| 276 |
crate::nsstring_as_str(name) |
| 277 |
} |
| 278 |
} |
| 279 |
|
| 280 |
pub fn type_(&self) -> MTLArgumentType { |
| 281 |
unsafe { msg_send![self, type] } |
| 282 |
} |
| 283 |
|
| 284 |
pub fn access(&self) -> MTLArgumentAccess { |
| 285 |
unsafe { msg_send![self, access] } |
| 286 |
} |
| 287 |
|
| 288 |
pub fn index(&self) -> NSUInteger { |
| 289 |
unsafe { msg_send![self, index] } |
| 290 |
} |
| 291 |
|
| 292 |
pub fn is_active(&self) -> bool { |
| 293 |
unsafe { msg_send_bool![self, isActive] } |
| 294 |
} |
| 295 |
|
| 296 |
pub fn buffer_alignment(&self) -> NSUInteger { |
| 297 |
unsafe { msg_send![self, bufferAlignment] } |
| 298 |
} |
| 299 |
|
| 300 |
pub fn buffer_data_size(&self) -> NSUInteger { |
| 301 |
unsafe { msg_send![self, bufferDataSize] } |
| 302 |
} |
| 303 |
|
| 304 |
pub fn buffer_data_type(&self) -> MTLDataType { |
| 305 |
unsafe { msg_send![self, bufferDataType] } |
| 306 |
} |
| 307 |
|
| 308 |
pub fn buffer_struct_type(&self) -> &StructTypeRef { |
| 309 |
unsafe { msg_send![self, bufferStructType] } |
| 310 |
} |
| 311 |
|
| 312 |
pub fn threadgroup_memory_alignment(&self) -> NSUInteger { |
| 313 |
unsafe { msg_send![self, threadgroupMemoryAlignment] } |
| 314 |
} |
| 315 |
|
| 316 |
pub fn threadgroup_memory_data_size(&self) -> NSUInteger { |
| 317 |
unsafe { msg_send![self, threadgroupMemoryDataSize] } |
| 318 |
} |
| 319 |
|
| 320 |
pub fn texture_type(&self) -> MTLTextureType { |
| 321 |
unsafe { msg_send![self, textureType] } |
| 322 |
} |
| 323 |
|
| 324 |
pub fn texture_data_type(&self) -> MTLDataType { |
| 325 |
unsafe { msg_send![self, textureDataType] } |
| 326 |
} |
| 327 |
} |
| 328 |
|
| 329 |
/// See <https://developer.apple.com/documentation/metal/mtlargumentdescriptor> |
| 330 |
pub enum MTLArgumentDescriptor {} |
| 331 |
|
| 332 |
foreign_obj_type! { |
| 333 |
type CType = MTLArgumentDescriptor; |
| 334 |
pub struct ArgumentDescriptor; |
| 335 |
} |
| 336 |
|
| 337 |
impl ArgumentDescriptor { |
| 338 |
pub fn new<'a>() -> &'a ArgumentDescriptorRef { |
| 339 |
unsafe { |
| 340 |
let class = class!(MTLArgumentDescriptor); |
| 341 |
msg_send![class, argumentDescriptor] |
| 342 |
} |
| 343 |
} |
| 344 |
} |
| 345 |
|
| 346 |
impl ArgumentDescriptorRef { |
| 347 |
pub fn set_data_type(&self, ty: MTLDataType) { |
| 348 |
unsafe { msg_send![self, setDataType: ty] } |
| 349 |
} |
| 350 |
|
| 351 |
pub fn set_index(&self, index: NSUInteger) { |
| 352 |
unsafe { msg_send![self, setIndex: index] } |
| 353 |
} |
| 354 |
|
| 355 |
pub fn set_access(&self, access: MTLArgumentAccess) { |
| 356 |
unsafe { msg_send![self, setAccess: access] } |
| 357 |
} |
| 358 |
|
| 359 |
pub fn set_array_length(&self, length: NSUInteger) { |
| 360 |
unsafe { msg_send![self, setArrayLength: length] } |
| 361 |
} |
| 362 |
|
| 363 |
pub fn set_texture_type(&self, ty: MTLTextureType) { |
| 364 |
unsafe { msg_send![self, setTextureType: ty] } |
| 365 |
} |
| 366 |
} |