1 module metal.metal; 2 3 version(D_ObjectiveC) 4 { 5 extern(Objective-C): 6 7 public import objc.runtime; 8 import metal.library; 9 import metal.vertexdescriptor; 10 import metal.pixelformat; 11 import metal.commandbuffer; 12 import metal.texture; 13 import metal.blitcommandencoder; 14 15 16 17 enum MTLCPUCacheMode : NSUInteger 18 { 19 DefaultCache = 0, 20 WriteCombined = 1 21 } 22 23 immutable NSUInteger MTLResourceCPUCacheModeShift = 0; 24 immutable NSUInteger MTLResourceCPUCacheModeMask = 0xf << MTLResourceCPUCacheModeShift; 25 immutable NSUInteger MTLResourceStorageModeShift = 4; 26 immutable NSUInteger MTLResourceStorageModeMask = 0xf << MTLResourceStorageModeShift; 27 immutable NSUInteger MTLResourceHazardTrackingModeShift = 8; 28 immutable NSUInteger MTLResourceHazardTrackingModeMask = 0x3 << MTLResourceHazardTrackingModeShift; 29 30 enum MTLStorageMode : NSUInteger 31 { 32 ///The resource is stored in system memory and is accessible to both the CPU and the GPU. 33 Shared = 0, 34 ///The CPU and GPU may maintain separate copies of the resource, and any changes must be explicitly synchronized. 35 Managed = 1, 36 ///The resource can be accessed only by the GPU. 37 Private = 2, 38 ///The resource’s contents can be accessed only by the GPU and only exist temporarily during a render pass. 39 Memoryless 40 } 41 42 enum MTLHazardTrackingMode : NSUInteger 43 { 44 ///An option specifying that the default tracking mode should be used. 45 Default = 0, 46 ///An option specifying that the app must prevent hazards when modifying this object's contents. 47 Untracked = 1, 48 ///An option specifying that Metal prevents hazards when modifying this object's contents. 49 Tracked = 2 50 } 51 52 ///Optional arguments used to set the behavior of a resource. 53 enum MTLResourceOptions : NSUInteger 54 { 55 ///The default CPU cache mode for the resource, which guarantees that read and write operations are executed in the expected order. 56 DefaultCache = MTLCPUCacheMode.DefaultCache << MTLResourceCPUCacheModeShift, 57 ///A write-combined CPU cache mode that is optimized for resources that the CPU writes into, but never reads. 58 CPUCacheModeWriteCombined = MTLCPUCacheMode.WriteCombined << MTLResourceCPUCacheModeShift, 59 ///The resource is stored in system memory and is accessible to both the CPU and the GPU. 60 StorageModeShared = MTLStorageMode.Shared << MTLResourceStorageModeShift, 61 ///The CPU and GPU may maintain separate copies of the resource, which you need to explicitly synchronize. 62 StorageModeManaged = MTLStorageMode.Managed << MTLResourceStorageModeShift, 63 ///The resource can be accessed only by the GPU. 64 StorageModePrivate = MTLStorageMode.Private << MTLResourceStorageModeShift, 65 ///The resource’s contents can be accessed only by the GPU and only exist temporarily during a render pass. 66 StorageModeMemoryless = MTLStorageMode.Memoryless << MTLResourceStorageModeShift, 67 ///An option specifying that the default tracking mode should be used. 68 HazardTrackingModeDefault = MTLHazardTrackingMode.Default << MTLResourceHazardTrackingModeShift, 69 ///An option specifying that Metal prevents hazards when modifying this object's contents. 70 HazardTrackingModeTracked = MTLHazardTrackingMode.Tracked << MTLResourceHazardTrackingModeShift, 71 ///An option specifying that the app must prevent hazards when modifying this object's contents. 72 HazardTrackingModeUntracked = MTLHazardTrackingMode.Untracked << MTLResourceHazardTrackingModeShift, 73 } 74 75 ///The coordinates for the front upper-left corner of a region. 76 struct MTLOrigin 77 { 78 NSUInteger x, y, z; 79 } 80 ///Returns a new origin with the specified coordinates. 81 extern(C) MTLOrigin MTLOriginMake(NSUInteger x, NSUInteger y, NSUInteger z); 82 83 struct MTLRegion 84 { 85 ///The coordinates of the front upper-left corner of the region. 86 MTLOrigin origin; 87 ///The dimensions of the region. 88 MTLSize size; 89 } 90 91 92 extern interface MTLRenderPipelineState 93 { 94 void release() @selector("release"); 95 MTLDevice device() @selector("device"); 96 NSString label() @selector("label"); 97 } 98 99 enum MTLTriangleFillMode : NSUInteger 100 { 101 ///Rasterize triangle and triangle strip primitives as filled triangles. 102 Fill = 0, 103 ///Rasterize triangle and triangle strip primitives as lines. 104 Lines = 1 105 } 106 107 enum MTLWinding : NSUInteger 108 { 109 ///Primitives whose vertices are specified in clockwise order are front-facing. 110 Clockwise = 0, 111 ///Primitives whose vertices are specified in counter-clockwise order are front-facing. 112 CounterClockwise = 1 113 } 114 115 struct MTLViewport 116 { 117 double originX = 0; 118 double originY = 0; 119 double width = 0; 120 double height = 0; 121 double znear = 0; 122 double zfar = 0; 123 } 124 125 enum MTLCullMode : NSUInteger 126 { 127 ///Does not cull any primitives. 128 None = 0, 129 ///Culls front-facing primitives. 130 Front = 1, 131 ///Culls back-facing primitives. 132 Back = 2 133 } 134 135 extern class MTLFunction 136 { 137 138 } 139 140 struct MTLClearColor 141 { 142 float red, green, blue, alpha; 143 } 144 145 MTLClearColor MTLClearColorMake(double red = 0.0, double green = 0.0, double blue = 0.0, double alpha = 1.0); 146 147 ///Options that modify a store action. 148 enum MTLStoreActionOptions : NSUInteger 149 { 150 ///An option that doesn't modify the intended behavior of a store action. 151 None = 0, 152 ///An option that stores data in a sample-position–agnostic representation. 153 CustomSamplePositions = 1 << 0 154 } 155 156 ///A render target that serves as the output destination for pixels generated by a render pass. 157 extern class MTLRenderPassAttachmentDescriptor : NSObject 158 { 159 ///The texture object associated with this attachment. 160 @selector("texture") 161 MTLTexture texture(); 162 @selector("setTexture:") 163 MTLTexture texture(MTLTexture); 164 165 ///The mipmap level of the texture used for rendering to the attachment. 166 @selector("level") 167 NSUInteger level(); 168 @selector("setLevel:") 169 NSUInteger level(NSUInteger); 170 171 ///The slice of the texture used for rendering to the attachment. 172 @selector("slice") 173 NSUInteger slice(); 174 @selector("setSlice:") 175 NSUInteger slice(NSUInteger); 176 177 ///The action performed by this attachment at the start of a rendering pass for a render command encoder. 178 @selector("loadAction") 179 MTLLoadAction loadAction(); 180 @selector("setLoadAction:") 181 MTLLoadAction loadAction(MTLLoadAction); 182 183 184 ///The action performed by this attachment at the end of a rendering pass for a render command encoder. 185 @selector("storeAction") 186 MTLStoreAction storeAction(); 187 @selector("setStoreAction:") 188 MTLStoreAction storeAction(MTLStoreAction); 189 190 ///The options that modify the store action performed by this attachment. 191 @selector("storeActionOptions") 192 MTLStoreActionOptions storeActionOptions(); 193 @selector("setStoreActionOptions:") 194 MTLStoreActionOptions storeActionOptions(MTLStoreActionOptions); 195 196 ///The destination texture used when resolving multisampled texture data into single sample values 197 @selector("resolveTexture") 198 MTLTexture resolveTexture(); 199 @selector("setResolveTexture:") 200 MTLTexture resolveTexture(MTLTexture); 201 ///The mipmap level of the texture used for the multisample resolve action. 202 @selector("resolveLevel") 203 NSUInteger resolveLevel(); 204 @selector("setResolveLevel:") 205 NSUInteger resolveLevel(NSUInteger); 206 ///The slice of the texture used for the multisample resolve action. 207 @selector("resolveSlice") 208 NSUInteger resolveSlice(); 209 @selector("setResolveSlice:") 210 NSUInteger resolveSlice(NSUInteger); 211 ///The depth plane of the texture used for the multisample resolve action. 212 @selector("resolveDepthPlane") 213 NSUInteger resolveDepthPlane(); 214 @selector("setResolveDepthPlane:") 215 NSUInteger resolveDepthPlane(NSUInteger); 216 217 } 218 219 ///Types of actions performed for an attachment at the start of a rendering pass. 220 enum MTLLoadAction: NSUInteger 221 { 222 ///The GPU has permission to discard the existing contents of the attachment at the start of the render pass, replacing them with arbitrary data. 223 DontCare = 0, 224 ///The GPU preserves the existing contents of the attachment at the start of the render pass. 225 Load = 1, 226 ///The GPU writes a value to every pixel in the attachment at the start of the render pass. 227 Clear = 2, 228 } 229 230 ///Types of actions performed for an attachment at the end of a rendering pass. 231 enum MTLStoreAction: NSUInteger 232 { 233 ///The GPU has permission to discard the rendered contents of the attachment at the end of the render pass, replacing them with arbitrary data. 234 DontCare = 0, 235 ///The GPU stores the rendered contents to the texture. 236 Store = 1, 237 ///The GPU resolves the multisampled data to one sample per pixel and stores the data to the resolve texture, discarding the multisample data afterwards. 238 MultisampleResolve = 2, 239 ///The GPU stores the multisample data to the multisample texture, resolves the data to a sample per pixel, and stores the data to the resolve texture. 240 StoreAndMultisampleResolve = 3, 241 ///The app will specify the store action when it encodes the render pass. 242 Unknown = 4, 243 ///The GPU stores depth data in a sample-position–agnostic representation. 244 CustomSampleDepthStore, 245 } 246 247 extern class MTLRenderPassColorAttachmentDescriptor : MTLRenderPassAttachmentDescriptor 248 { 249 ///The color to use when clearing the color attachment. 250 @selector("clearColor") 251 MTLClearColor clearColor(); 252 @selector("setClearColor:") 253 MTLClearColor clearColor(MTLClearColor); 254 } 255 256 extern class MTLRenderPassColorAttachmentDescriptorArray : NSObject 257 { 258 @selector("setObject:atIndexedSubscript:") 259 void setObjectAtIndexedSubscript(MTLRenderPassColorAttachmentDescriptor attachment, NSUInteger attachmentIndex); 260 261 @selector("objectIndexedAtSubscript:") 262 MTLRenderPassColorAttachmentDescriptor objectIndexedAtSubscript(NSUInteger attachmentIndex); 263 264 final extern(D) MTLRenderPassColorAttachmentDescriptor opIndex(NSUInteger index) 265 { 266 return objectIndexedAtSubscript(index); 267 } 268 269 final extern(D) void opIndexAssign(MTLRenderPassColorAttachmentDescriptor attachment, NSUInteger index) 270 { 271 setObjectAtIndexedSubscript(attachment, index); 272 } 273 } 274 275 enum MTLMultisampleDepthResolveFilter : NSUInteger 276 { 277 ///No filter is applied. 278 Sample0 = 0, 279 ///The GPU compares all depth samples in the pixel and selects the sample with the smallest value. 280 Min, 281 ///The GPU compares all depth samples in the pixel and selects the sample with the largest value. 282 Max 283 } 284 285 ///A depth render target that serves as the output destination for depth pixels generated by a render pass. 286 extern class MTLRenderPassDepthAttachmentDescriptor : MTLRenderPassAttachmentDescriptor 287 { 288 ///The depth to use when clearing the depth attachment. 289 @selector("clearDepth") 290 double clearDepth(); 291 @selector("setClearDepth:") 292 double clearDepth(double); 293 294 ///The filter used for an MSAA depth resolve operation. 295 @selector("depthResolveFilter") 296 MTLMultisampleDepthResolveFilter depthResolveFilter(); 297 @selector("setDepthResolveFilter:") 298 MTLMultisampleDepthResolveFilter depthResolveFilter(MTLMultisampleDepthResolveFilter); 299 } 300 301 enum MTLMultisampleStencilResolveFilter : NSUInteger 302 { 303 Sample0 = 0, 304 DepthResolvedSample = 1 305 } 306 307 ///A stencil render target that serves as the output destination for stencil pixels generated by a render pass. 308 309 extern class MTLRenderPassStencilAttachmentDescriptor : MTLRenderPassAttachmentDescriptor 310 { 311 ///The filter used for stencil multisample resolve. 312 @selector("stencilResolveFilter") 313 MTLMultisampleStencilResolveFilter stencilResolveFilter(); 314 @selector("setStencilResolveFilter:") 315 MTLMultisampleStencilResolveFilter stencilResolveFilter(MTLMultisampleStencilResolveFilter); 316 317 ///The value to use when clearing the stencil attachment. 318 @selector("clearStencil") 319 uint clearStencil(); 320 @selector("setClearStencil:") 321 uint clearStencil(uint); 322 } 323 324 struct MTLSize 325 { 326 NSUInteger width; 327 NSUInteger height; 328 NSUInteger depth; 329 } 330 struct MTLSizeAndAlign 331 { 332 NSUInteger size; 333 NSUInteger align_; 334 } 335 336 struct MTLSamplePosition 337 { 338 float x; 339 float y; 340 } 341 342 enum MTLPrimitiveType : NSUInteger 343 { 344 ///Rasterize a point at each vertex. The vertex shader must provide [[point_size]], or the point size is undefined. 345 Point = 0, 346 ///Rasterize a line between each separate pair of vertices, resulting in a series of unconnected lines. If there are an odd number of vertices, the last vertex is ignored. 347 Line = 1, 348 ///Rasterize a line between each pair of adjacent vertices, resulting in a series of connected lines (also called a polyline). 349 LineStrip = 2, 350 ///For every separate set of three vertices, rasterize a triangle. If the number of vertices is not a multiple of three, either one or two vertices is ignored. 351 Triangle = 3, 352 ///For every three adjacent vertices, rasterize a triangle. 353 TriangleStrip 354 } 355 356 enum MTLIndexType : NSUInteger 357 { 358 ///A 16-bit unsigned integer used as a primitive index. 359 UInt16 = 0, 360 ///A 32-bit unsigned integer used as a primitive index. 361 UInt32 = 1 362 } 363 364 interface MTLCounterSampleBuffer 365 { 366 ///Transforms samples of a GPU’s counter set from the driver’s internal format to a standard Metal data structure. 367 @selector("resolveCounterRange:") 368 NSData resolveCounterRange(NSRange range); 369 } 370 371 alias MTLCoordinate2D = MTLSamplePosition; 372 373 MTLSize MTLSizeMake(NSUInteger width, NSUInteger height, NSUInteger depth); 374 MTLCoordinate2D MTLCoordinate2DMake(float x, float y); 375 376 extern interface MTLRasterizationRateMap 377 { 378 ///The device object that created the rate map. 379 MTLDevice device() @selector("device"); 380 ///A string that identifies the rate map. 381 NSString label() @selector("label"); 382 ///The number of layers in the rate map. 383 NSUInteger layerCount() @selector("layerCount"); 384 ///The logical size, in pixels, of the viewport coordinate system. 385 MTLSize screenSize() @selector("screenSize"); 386 387 ///Returns the dimensions, in pixels, of the area in the render target affected by the rasterization rate map. 388 @selector("physicalSizeForLayer:") 389 MTLSize physicalSizeForLayer(NSUInteger layerIndex); 390 391 ///The granularity, in physical pixels, at which the rasterization rate varies. 392 MTLSize physicalGranularity() @selector("physicalGranularity"); 393 394 ///Converts a point in logical viewport coordinates to the corresponding physical coordinates in a render layer. 395 @selector("mapScreenToPhysicalCoordinates:forLayer:") 396 MTLCoordinate2D mapScreenToPhysicalCoordinates(MTLCoordinate2D screenCoordinates, NSUInteger layerIndex); 397 398 ///Converts a point in physical coordinates inside a layer to its corresponding logical viewport coordinates. 399 @selector("mapPhysicalToScreenCoordinates:forLayer:") 400 MTLCoordinate2D mapPhysicalToScreenCoordinates(MTLCoordinate2D physicalCoordinates, NSUInteger layerIndex); 401 402 ///The size and alignment requirements to contain the coordinate transformation information in this rate map. 403 @selector("parameterBufferSizeAndAlign") 404 MTLSizeAndAlign parameterBufferSizeAndAlign(); 405 406 ///Copies the parameter data into the provided buffer. 407 @selector("copyParameterDataToBuffer:offset:") 408 void copyParameterDataToBuffer(MTLBuffer buffer, NSUInteger offset); 409 410 411 } 412 413 414 415 ///A description of where to store GPU counter information at the start and end of a render pass. 416 extern class MTLRenderPassSampleBufferAttachmentDescriptor : NSObject 417 { 418 ///The sample buffer to write new GPU counter samples to. 419 @selector("sampleBuffer") 420 MTLCounterSampleBuffer sampleBuffer(); 421 @selector("setSampleBuffer:") 422 MTLCounterSampleBuffer sampleBuffer(MTLCounterSampleBuffer sampleBuffer); 423 424 ///The index the Metal device object should use to store GPU counters when starting the render pass’s vertex stage. 425 @selector("startOfVertexSampleIndex") 426 NSUInteger startOfVertexSampleIndex(); 427 @selector("setStartOfVertexSampleIndex:") 428 NSUInteger startOfVertexSampleIndex(NSUInteger); 429 430 ///The index the Metal device object should use to store GPU counters when ending the render pass’s vertex stage. 431 @selector("endOfVertexSampleIndex") 432 NSUInteger endOfVertexSampleIndex(); 433 @selector("setEndOfVertexSampleIndex:") 434 NSUInteger endOfVertexSampleIndex(NSUInteger); 435 436 ///The index the Metal device object should use to store GPU counters when starting the render pass’s fragment stage. 437 @selector("startOfFragmentSampleIndex") 438 NSUInteger startOfFragmentSampleIndex(); 439 @selector("setStartOfFragmentSampleIndex:") 440 NSUInteger startOfFragmentSampleIndex(NSUInteger); 441 442 ///The index the Metal device object should use to store GPU counters when ending the render pass’s fragment stage. 443 @selector("endOfFragmentSampleIndex") 444 NSUInteger endOfFragmentSampleIndex(); 445 @selector("setEndOfFragmentSampleIndex:") 446 NSUInteger endOfFragmentSampleIndex(NSUInteger); 447 448 449 } 450 451 extern class MTLRenderPassSampleBufferAttachmentDescriptorArray : NSObject 452 { 453 ///Returns the descriptor object for the specified sample buffer attachment. 454 @selector("objectAtIndexedSubscript:") 455 MTLRenderPassSampleBufferAttachmentDescriptor objectAtIndexedSubscript(NSUInteger attachmentIndex); 456 457 ///Sets the descriptor object for the specified sample buffer attachment. 458 @selector("setObject:atIndexedSubscript:") 459 void setObjectAtIndexedSubscript(MTLRenderPassSampleBufferAttachmentDescriptor attachment, NSUInteger attachmentIndex); 460 } 461 462 ///A depth and stencil state object that specifies the depth and stencil configuration and operations used in a render pass. 463 extern interface MTLDepthStencilState 464 { 465 ///The device from which this state object was created. 466 @selector("device") 467 MTLDevice device(); 468 469 ///A string that identifies this object. 470 @selector("label") 471 NSString label(); 472 } 473 474 ///An object that configures new MTLDepthStencilState objects. 475 extern class MTLDepthStencilDescriptor : NSObject 476 { 477 @selector("alloc") 478 override static MTLDepthStencilDescriptor alloc(); 479 480 @selector("init") 481 override MTLDepthStencilDescriptor initialize(); 482 alias ini = initialize; 483 484 ///The comparison that is performed between a fragment’s depth value and the depth value in the attachment, which determines whether to discard the fragment. 485 @selector("depthCompareFunction") 486 MTLCompareFunction depthCompareFunction(); 487 @selector("setDepthCompareFunction:") 488 MTLCompareFunction depthCompareFunction(MTLCompareFunction); 489 490 ///A Boolean value that indicates whether depth values can be written to the depth attachment. 491 @selector("depthWriteEnabled") 492 BOOL depthWriteEnabled(); 493 @selector("setDepthWriteEnabled:") 494 BOOL depthWriteEnabled(BOOL); 495 alias isDepthWriteEnabled = depthWriteEnabled; 496 497 // ///The stencil descriptor for back-facing primitives. 498 // @selector("backFaceStencil") 499 // MTLStencilDescriptor backFaceStencil(); 500 // @selector("setBackFaceStencil:") 501 // MTLStencilDescriptor backFaceStencil(MTLStencilDescriptor); 502 503 // ///The stencil descriptor for front-facing primitives. 504 // @selector("frontFaceStencil") 505 // MTLStencilDescriptor frontFaceStencil(); 506 // @selector("setFrontFaceStencil:") 507 // MTLStencilDescriptor frontFaceStencil(MTLStencilDescriptor); 508 509 ///A string that identifies this object. 510 @selector("label") 511 NSString label(); 512 @selector("setLabel:") 513 NSString label(NSString); 514 515 516 } 517 518 519 520 ///A group of render targets that hold the results of a render pass. 521 extern class MTLRenderPassDescriptor 522 { 523 @selector("new") 524 static MTLRenderPassDescriptor new_(); 525 526 ///Creates a default render pass descriptor. 527 @selector("renderPassDescriptor") 528 static MTLRenderPassDescriptor renderPassDescriptor(); 529 530 ///An array of state information for attachments that store color data. 531 @selector("colorAttachments") 532 MTLRenderPassColorAttachmentDescriptorArray colorAttachments(); 533 534 ///State information for an attachment that stores depth data. 535 @selector("depthAttachment") 536 MTLRenderPassDepthAttachmentDescriptor depthAttachment(); 537 @selector("setDepthAttachment:") 538 MTLRenderPassDepthAttachmentDescriptor depthAttachment(MTLRenderPassDepthAttachmentDescriptor); 539 540 ///State information for an attachment that stores stencil data. 541 @selector("stencilAttachment") 542 MTLRenderPassStencilAttachmentDescriptor stencilAttachment(); 543 @selector("setStencilAttachment:") 544 MTLRenderPassStencilAttachmentDescriptor stencilAttachment(MTLRenderPassStencilAttachmentDescriptor); 545 546 ///A buffer where the GPU writes visibility test results when fragments pass depth and stencil tests. 547 @selector("visibilityResultBuffer") 548 MTLBuffer visibilityResultBuffer(); 549 @selector("setVisibilityResultBuffer:") 550 MTLBuffer visibilityResultBuffer(MTLBuffer); 551 552 ///The number of active layers that all attachments must have for layered rendering. 553 @selector("renderTargetArrayLength") 554 NSUInteger renderTargetArrayLength(); 555 @selector("setRenderTargetArrayLength:") 556 NSUInteger renderTargetArrayLength(NSUInteger); 557 558 /// The width, in pixels, to constrain the render target to. 559 @selector("renderTargetWidth") 560 NSUInteger renderTargetWidth(); 561 @selector("setRenderTargetWidth:") 562 NSUInteger renderTargetWidth(NSUInteger); 563 564 ///The height, in pixels, to constrain the render target to. 565 @selector("renderTargetHeight") 566 NSUInteger renderTargetHeight(); 567 @selector("setRenderTargetHeight:") 568 NSUInteger renderTargetHeight(NSUInteger); 569 570 571 ///Sets the programmable sample positions for a render pass. 572 @selector("setSamplePositions:count:") 573 void setSamplePositions(const MTLSamplePosition positions, NSUInteger count); 574 575 @selector("getSamplePositions:count:") 576 NSUInteger getSamplePositions(MTLSamplePosition positions, NSUInteger count); 577 578 ///The per-sample size, in bytes, of the largest explicit imageblock layout in the render pass. 579 @selector("imageBlockSampleLength") 580 NSUInteger imageBlockSampleLength(); 581 @selector("setImageBlockSampleLength:") 582 NSUInteger imageBlockSampleLength(NSUInteger); 583 584 ///The per-tile size, in bytes, of the persistent threadgroup memory allocation. 585 @selector("threadgroupMemoryLength") 586 NSUInteger threadgroupMemoryLength(); 587 @selector("setThreadgroupMemoryLength:") 588 NSUInteger threadgroupMemoryLength(NSUInteger); 589 590 ///The tile width, in pixels. 591 @selector("tileWidth") 592 NSUInteger tileWidth(); 593 @selector("setTileWidth:") 594 NSUInteger tileWidth(NSUInteger); 595 596 597 ///The tile height, in pixels. 598 @selector("tileHeight") 599 NSUInteger tileHeight(); 600 @selector("setTileHeight:") 601 NSUInteger tileHeight(NSUInteger); 602 603 ///The raster sample count for the render pass when the render pass doesn’t have explicit attachments. 604 @selector("defaultRasterSampleCount") 605 NSUInteger defaultRasterSampleCount(); 606 @selector("setDefaultRasterSampleCount:") 607 NSUInteger defaultRasterSampleCount(NSUInteger); 608 609 ///The rasterization rate map to use when executing the render pass. 610 @selector("rasterizationRateMap") 611 MTLRasterizationRateMap rasterizationRateMap(); 612 @selector("setRasterizationRateMap:") 613 MTLRasterizationRateMap rasterizationRateMap(MTLRasterizationRateMap); 614 615 ///The array of sample buffers that the render pass can access. 616 @selector("sampleBufferAttachments") 617 MTLRenderPassSampleBufferAttachmentDescriptorArray sampleBufferAttachments(); 618 619 } 620 621 622 623 enum MTLColorWriteMask : NSUInteger 624 { 625 None = 0, 626 Red = 0x1 << 3, 627 Green = 0x1 << 2, 628 Blue = 0x1 << 1, 629 Alpha = 0x1 << 0, 630 All = 0xf 631 } 632 633 enum MTLBlendOperation : NSUInteger 634 { 635 ///Add portions of both source and destination pixel values. 636 Add = 0, 637 ///Subtract a portion of the destination pixel values from a portion of the source. 638 Subtract = 1, 639 ///Subtract a portion of the source values from a portion of the destination pixel values. 640 ReverseSubtract = 2, 641 ///Minimum of the source and destination pixel values. 642 Min = 3, 643 ///Maximum of the source and destination pixel values. 644 Max = 4 645 } 646 647 enum MTLBlendFactor : NSUInteger 648 { 649 Zero = 0, 650 One = 1, 651 ///Blend factor of source values. 652 SourceColor = 2, 653 ///Blend factor of one minus source values. 654 OneMinusSourceColor = 3, 655 ///Blend factor of source alpha. 656 SourceAlpha = 4, 657 ///Blend factor of one minus source alpha. 658 OneMinusSourceAlpha = 5, 659 ///Blend factor of destination values. 660 DestinationColor = 6, 661 ///Blend factor of one minus destination values. 662 OneMinusDestinationColor = 7, 663 ///Blend factor of one minus destination values. 664 DestinationAlpha = 8, 665 ///Blend factor of one minus destination alpha. 666 OneMinusDestinationAlpha = 9, 667 ///Blend factor of the minimum of either source alpha or one minus destination alpha. 668 SourceAlphaSaturated = 10, 669 ///Blend factor of RGB values. 670 BlendColor = 11, 671 ///Blend factor of one minus RGB values. 672 OneMinusBlendColor = 12, 673 ///Blend factor of alpha value. 674 BlendAlpha = 13, 675 ///Blend factor of one minus alpha value. 676 OneMinusBlendAlpha = 14, 677 ///Blend factor of source values. This option supports dual-source blending and reads from the second color output of the fragment function. 678 Source1Color = 15, 679 ///Blend factor of one minus source values. This option supports dual-source blending and reads from the second color output of the fragment function. 680 OneMinusSource1Color = 16, 681 ///Blend factor of source alpha. This option supports dual-source blending and reads from the second color output of the fragment function. 682 Source1Alpha = 17, 683 ///Blend factor of one minus source alpha. This option supports dual-source blending and reads from the second color output of the fragment function. 684 OneMinusSource1Alpha = 18 685 686 } 687 688 extern class MTLRenderPipelineColorAttachmentDescriptor 689 { 690 ///The pixel format of the color attachment’s texture. 691 @selector("pixelFormat") 692 MTLPixelFormat pixelFormat(); 693 @selector("setPixelFormat:") 694 MTLPixelFormat pixelFormat(MTLPixelFormat); 695 696 ///A bitmask that restricts which color channels are written into the texture. 697 @selector("writeMask") 698 MTLColorWriteMask writeMask(); 699 @selector("setWriteMask:") 700 MTLColorWriteMask writeMask(MTLColorWriteMask); 701 702 ///A Boolean value that determines whether blending is enabled. 703 @selector("blendingEnabled") 704 BOOL isBlendingEnabled(); 705 @selector("setBlendingEnabled:") 706 BOOL blendingEnabled(BOOL); 707 708 ///The blend operation assigned for the alpha data. 709 @selector("alphaBlendOperation") 710 MTLBlendOperation alphaBlendOperation(); 711 @selector("setAlphaBlendOperation:") 712 MTLBlendOperation alphaBlendOperation(MTLBlendOperation); 713 714 ///The blend operation assigned for the RGB data. 715 @selector("rgbBlendOperation") 716 MTLBlendOperation rgbBlendOperation(); 717 @selector("setRgbBlendOperation:") 718 MTLBlendOperation rgbBlendOperation(MTLBlendOperation); 719 720 ///The destination blend factor (DBF) used by the alpha blend operation. 721 @selector("destinationAlphaBlendFactor") 722 MTLBlendFactor destinationAlphaBlendFactor(); 723 @selector("setDestinationAlphaBlendFactor:") 724 MTLBlendFactor destinationAlphaBlendFactor(MTLBlendFactor); 725 726 ///The destination blend factor (DBF) used by the RGB blend operation. 727 @selector("destinationRGBBlendFactor") 728 MTLBlendFactor destinationRGBBlendFactor(); 729 @selector("setDestinationRGBBlendFactor:") 730 MTLBlendFactor destinationRGBBlendFactor(MTLBlendFactor); 731 732 ///The source blend factor (SBF) used by the alpha blend operation. 733 @selector("sourceAlphaBlendFactor") 734 MTLBlendFactor sourceAlphaBlendFactor(); 735 @selector("setSourceAlphaBlendFactor:") 736 MTLBlendFactor sourceAlphaBlendFactor(MTLBlendFactor); 737 738 ///The source blend factor (SBF) used by the RGB blend operation. 739 @selector("sourceRGBBlendFactor") 740 MTLBlendFactor sourceRGBBlendFactor(); 741 @selector("setSourceRGBBlendFactor:") 742 MTLBlendFactor sourceRGBBlendFactor(MTLBlendFactor); 743 744 745 746 747 } 748 749 extern class MTLRenderPipelineColorAttachmentDescriptorArray : NSObject 750 { 751 override static MTLRenderPipelineColorAttachmentDescriptorArray alloc() @selector("alloc"); 752 override MTLRenderPipelineColorAttachmentDescriptorArray initialize() @selector("init"); 753 alias ini = initialize; 754 755 @selector("setObject:atIndexedSubscript:") 756 void setObjectAtIndexedSubscript(MTLRenderPipelineColorAttachmentDescriptor attachment, NSUInteger attachmentIndex); 757 758 @selector("objectAtIndexedSubscript:") 759 MTLRenderPipelineColorAttachmentDescriptor objectAtIndexedSubscript(NSUInteger attachmentIndex); 760 761 extern(D) final MTLRenderPipelineColorAttachmentDescriptor opIndex(NSUInteger index) 762 { 763 return objectAtIndexedSubscript(index); 764 } 765 extern(D) final void opIndexAssign(NSUInteger index, MTLRenderPipelineColorAttachmentDescriptor v) 766 { 767 setObjectAtIndexedSubscript(v, index); 768 } 769 } 770 771 extern class MTLRenderPipelineDescriptor : NSObject 772 { 773 // mixin ObjectiveCOpCall; 774 override static MTLRenderPipelineDescriptor alloc() @selector("alloc"); 775 override MTLRenderPipelineDescriptor initialize() @selector("init"); 776 alias ini = initialize; 777 778 ///A string that identifies the render pipeline descriptor. 779 NSString label() @selector("label"); 780 NSString label(NSString) @selector("setLabel:"); 781 782 ///The vertex function the pipeline calls to process vertices. 783 MTLFunction vertexFunction() @selector("vertexFunction"); 784 MTLFunction vertexFunction(MTLFunction) @selector("setVertexFunction:"); 785 786 ///The fragment function the pipeline calls to process fragments. 787 MTLFunction fragmentFunction() @selector("fragmentFunction"); 788 MTLFunction fragmentFunction(MTLFunction) @selector("setFragmentFunction:"); 789 790 ///The organization of vertex data in an attribute’s argument table. 791 MTLVertexDescriptor vertexDescriptor() @selector("vertexDescriptor"); 792 MTLVertexDescriptor vertexDescriptor(MTLVertexDescriptor) @selector("setVertexDescriptor:"); 793 794 795 ///An array of attachments that store color data. 796 MTLRenderPipelineColorAttachmentDescriptorArray colorAttachments() @selector("colorAttachments"); 797 798 ///The pixel format of the attachment that stores depth data. 799 MTLPixelFormat depthAttachmentPixelFormat() @selector("depthAttachmentPixelFormat"); 800 MTLPixelFormat depthAttachmentPixelFormat(MTLPixelFormat) @selector("setDepthAttachmentPixelFormat:"); 801 802 ///The pixel format of the attachment that stores stencil data. 803 MTLPixelFormat stencilAttachmentPixelFormat() @selector("stencilAttachmentPixelFormat"); 804 MTLPixelFormat stencilAttachmentPixelFormat(MTLPixelFormat) @selector("setStencilAttachmentPixelFormat:"); 805 806 807 } 808 interface MTLIOCommandQueue 809 { 810 811 } 812 813 extern class MTLIOCommandQueueDescriptor : NSObject 814 { 815 816 } 817 818 ///The render stages at which a synchronization command is triggered. 819 enum MTLRenderStages : NSUInteger 820 { 821 ///The vertex rendering stage. 822 Vertex = 1 << 0, 823 ///The fragment rendering stage. 824 Fragment = 1 << 1, 825 ///The tile rendering stage. 826 Tile = 1 << 2, 827 Mesh = 1 << 4, 828 Object = 1 << 3 829 } 830 831 ///An object that can capture, track, and manage resource dependencies across command encoders. 832 extern interface MTLFence 833 { 834 ///The device object that created the fence. 835 @selector("device") 836 MTLDevice device(); 837 838 ///A string that identifies the fence. 839 @selector("label") 840 NSString label(); 841 842 @selector("setLabel:") 843 NSString label(NSString); 844 } 845 846 enum MTLGPUFamily : NSInteger 847 { 848 ///Represents the Metal 3 features. 849 Metal3 = 5001, 850 ///Represents the Apple family 8 GPU features that correspond to the Apple A15 and M2 GPUs. 851 Apple8 = 1008, 852 ///Represents the Apple family 7 GPU features that correspond to the Apple A14 and M1 GPUs. 853 Apple7 = 1007, 854 ///Represents the Apple family 6 GPU features that correspond to the Apple A13 GPUs. 855 Apple6 = 1006, 856 ///Represents the Apple family 5 GPU features that correspond to the Apple A12 GPUs. 857 Apple5 = 1005, 858 ///Represents the Apple family 4 GPU features that correspond to the Apple A11 GPUs. 859 Apple4 = 1004, 860 ///Represents the Apple family 3 GPU features that correspond to the Apple A9 and A10 GPUs. 861 Apple3 = 1003, 862 ///Represents the Apple family 2 GPU features that correspond to the Apple A8 GPUs. 863 Apple2 = 1002, 864 ///Represents the Apple family 1 GPU features that correspond to the Apple A7 GPUs. 865 Apple1 = 1001, 866 ///Represents the Common family 3 GPU features. 867 Common3 = 3003, 868 ///Represents the Common family 2 GPU features. 869 Common2 = 3002, 870 ///Represents the Common family 1 GPU features. 871 Common1 = 3001, 872 ///Represents the Mac family 2 GPU features. 873 Mac2 = 2002, 874 ///Represents the Mac family 1 GPU features. deprecated 875 Mac1 = 2001 876 } 877 878 ///The values that determine the limits and capabilities of argument buffers. 879 enum MTLArgumentBuffersTier : NSUInteger 880 { 881 ///Tier 1 argument buffers are supported on all iOS, tvOS, and macOS GPUs. 882 Tier1 = 0, 883 ///Tier 2 argument buffers are supported on all macOS discrete GPUs. 884 Tier2 = 1 885 } 886 887 ///The main Metal interface to a GPU that apps use to draw graphics and run computations in parallel. 888 extern interface MTLDevice 889 { 890 ///The full name of the GPU device. 891 @selector("name") 892 NSString name(); 893 894 ///Returns a Boolean value that indicates whether the GPU device supports the feature set of a specific GPU family. 895 @selector("supportsFamily:") 896 BOOL supportsFamily(MTLGPUFamily); 897 898 ///Returns the GPU device’s support tier for argument buffers. 899 @selector("argumentBuffersSupport") 900 MTLArgumentBuffersTier argumentBuffersSupport(); 901 902 903 ///Creates a queue you use to submit rendering and computation commands to a GPU. 904 @selector("newCommandQueue") 905 MTLCommandQueue newCommandQueue(); 906 907 ///Creates a queue you use to submit rendering and computation commands to a GPU that has a fixed number of uncompleted command buffers. 908 @selector("newCommandQueueWithMaxCommandBufferCount:") 909 MTLCommandQueue newCommandQueue(NSUInteger maxCommandBufferCount); 910 911 ///Creates a buffer the method clears with zero values, length is size in bytes. 912 @selector("newBufferWithLength:options:") 913 MTLBuffer newBuffer(NSUInteger length, MTLResourceOptions options); 914 915 ///Allocates a new buffer of a given length and initializes its contents by copying existing data into it. 916 @selector("newBufferWithBytes:length:options:") 917 MTLBuffer newBuffer(const(void)* pointer, NSUInteger length, MTLResourceOptions options); 918 919 ///Creates a new texture instance. 920 @selector("newTextureWithDescriptor:") 921 MTLTexture newTextureWithDescriptor(MTLTextureDescriptor descriptor); 922 923 924 ///Synchronously creates a Metal library instance by compiling the functions in a source string. 925 @selector("newLibraryWithSource:options:error:") 926 MTLLibrary newLibraryWithSource(NSString source, MTLCompileOptions options, NSError* error = null); 927 928 ///Creates a Metal library instance that contains the functions from your app’s default Metal library. 929 @selector("newDefaultLibrary") 930 MTLLibrary newDefaultLibrary(); 931 932 ///Creates a new memory fence instance. 933 @selector("newFence") 934 MTLFence newFence(); 935 936 937 ///Creates an input/output command queue you use to submit commands that load assets from the file system into GPU resources or system memory. 938 @selector("newIOCommandQueueWithDescriptor:error:") 939 MTLIOCommandQueue newIOCommandQueueWithDescriptor(MTLIOCommandQueueDescriptor descriptor, NSError* error = null); 940 941 ///Synchronously creates a render pipeline state. 942 @selector("newRenderPipelineStateWithDescriptor:error:") 943 MTLRenderPipelineState newRenderPipelineStateWithDescriptor(MTLRenderPipelineDescriptor descriptor, NSError* error = null); 944 945 ///Creates a depth-stencil state instance. 946 @selector("newDepthStencilStateWithDescriptor:") 947 MTLDepthStencilState newDepthStencilStateWithDescriptor(MTLDepthStencilDescriptor); 948 949 ///Returns a Boolean value that indicates whether the GPU can sample a texture with a specific number of sample points. 950 @selector("supportsTextureSampleCount:") 951 BOOL supportsTextureSampleCount(NSUInteger sampleCount); 952 953 ///Creates a sampler state instance. 954 @selector("newSamplerStateWithDescriptor:") 955 MTLSamplerState newSamplerStateWithDescriptor(MTLSamplerDescriptor descriptor); 956 957 ///Returns the minimum alignment the GPU device requires to create a texture buffer from a buffer. 958 @selector("minimumTextureBufferAlignmentForPixelFormat:") 959 NSUInteger minimumTextureBufferAlignmentForPixelFormat(MTLPixelFormat); 960 961 } 962 963 ///A block of code invoked after a drawable is presented. 964 alias MTLDrawablePresentedHandler = extern(C) void function(MTLDrawable); 965 966 967 968 ///A displayable resource that can be rendered or written to. 969 extern interface MTLDrawable 970 { 971 ///A positive integer that identifies the drawable. 972 @selector("drawableID") 973 NSUInteger drawableID(); 974 975 ///Presents the drawable onscreen as soon as possible. 976 @selector("present") 977 void present(); 978 979 ///Presents the drawable onscreen at a specific host time. 980 @selector("presentAtTime:") 981 void present(CFTimeInterval presentationTime); 982 983 ///Presents the drawable onscreen as soon as possible after a previous drawable is visible for the specified duration. 984 @selector("presentAfterMinimumDuration:") 985 void presentAfterMinimumDuration(CFTimeInterval duration); 986 987 988 ///Registers a block of code to be called immediately after the drawable is presented. 989 @selector("addPresentedHandler:") 990 void addPresentedHandler(MTLDrawablePresentedHandler); 991 992 ///The host time, in seconds, when the drawable was displayed onscreen. 993 @selector("presentedTime") 994 CFTimeInterval presentedTime(); 995 } 996 997 998 MTLSamplePosition MTLSamplePositionMake(float x, float y); 999 MTLCommandBuffer MTLCreateSystemDefaultDevice(); 1000 1001 ///An instance you use to create, submit, and schedule command buffers to a specific GPU device to run the commands within those buffers. 1002 extern interface MTLCommandQueue 1003 { 1004 ///Returns a command buffer from the command queue that you configure with a descriptor. 1005 @selector("commandBufferWithDescriptor:") 1006 MTLCommandBuffer commandBuffer(MTLCommandBufferDescriptor* descriptor); 1007 1008 ///Returns a command buffer from the command queue that maintains strong references to resources. 1009 @selector("commandBuffer") 1010 MTLCommandBuffer commandBuffer(); 1011 1012 ///Returns a command buffer from the command queue that doesn’t maintain strong references to resources. 1013 @selector("commandBufferWithUnretainedReferences") 1014 MTLCommandBuffer commandBufferWithUnretainedReferences(); 1015 1016 ///The GPU device that creates the command queue. 1017 @selector("device") 1018 MTLDevice device(); 1019 1020 ///An optional name that can help you identify the command queue. 1021 @selector("label") 1022 NSString label(); 1023 @selector("setLabel:") 1024 NSString label(NSString); 1025 1026 } 1027 1028 ///A Metal drawable associated with a Core Animation layer. 1029 extern interface CAMetalDrawable : MTLDrawable 1030 { 1031 ///A Metal texture object that contains the drawable’s contents. 1032 @selector("texture") 1033 MTLTexture texture(); 1034 ///The layer that owns this drawable object. 1035 // @selector("layer") 1036 // CAMetalLayer layer(); 1037 } 1038 1039 ///An allocation of memory that is accessible to a GPU. 1040 extern interface MTLResource 1041 { 1042 ///The device object that created the resource. 1043 @selector("device") 1044 MTLDevice device(); 1045 1046 ///A string that identifies the resource. 1047 @selector("label") 1048 NSString label(); 1049 @selector("setLabel:") 1050 NSString label(NSString); 1051 } 1052 1053 ///An encoder that writes GPU commands into a command buffer. 1054 extern interface MTLCommandEncoder 1055 { 1056 ///Declares that all command generation from the encoder is completed. 1057 @selector("endEncoding") 1058 void endEncoding(); 1059 1060 ///Inserts a debug string into the captured frame data. 1061 @selector("insertDebugSignpost:") 1062 void insertDebugSignpost(NSString); 1063 1064 ///Pushes a specific string onto a stack of debug group strings for the command encoder. 1065 @selector("pushDebugGroup:") 1066 void pushDebugGroup(NSString); 1067 1068 ///Pops the latest string off of a stack of debug group strings for the command encoder. 1069 @selector("popDebugGroup") 1070 void popDebugGroup(); 1071 1072 ///The Metal device from which the command encoder was created. 1073 @selector("device") 1074 MTLDevice device(); 1075 1076 ///A string that labels the command encoder. 1077 @selector("label") 1078 NSString label(); 1079 1080 @selector("setLabel:") 1081 NSString label(NSString); 1082 } 1083 1084 1085 extern interface MTLBuffer 1086 { 1087 ///Creates a texture that shares its storage with the buffer. 1088 @selector("newTextureWithDescriptor:offset:bytesPerRow:") 1089 MTLTexture newTextureWithDescriptor( 1090 MTLTextureDescriptor, 1091 NSUInteger offset, 1092 NSUInteger bytesPerRow 1093 ); 1094 1095 1096 ///Gets the system address of the buffer’s storage allocation. 1097 void* contents() @selector("contents"); 1098 ///Informs the GPU that the CPU has modified a section of the buffer. 1099 void didModifyRange(NSRange) @selector("didModifyRange:"); 1100 1101 ///Adds a debug marker string to a specific buffer range. 1102 @selector("addDebugMarker:range:") 1103 void addDebugMarker(NSString marker, NSRange range); 1104 1105 ///Removes all debug marker strings from the buffer. 1106 @selector("removeAllDebugMarkers") 1107 void removeAllDebugMarkers(); 1108 1109 ///The logical size of the buffer, in bytes. 1110 @selector("length") 1111 NSUInteger length(); 1112 1113 @selector("retain") 1114 void retain(); 1115 1116 @selector("release") 1117 void release(); 1118 1119 @selector("dealloc") 1120 void dealloc(); 1121 } 1122 1123 ///An object you use to synchronize access to Metal resources. 1124 extern interface MTLEvent 1125 { 1126 ///The device object that created the event. 1127 @selector("device") 1128 MTLDevice device(); 1129 1130 ///A string that identifies the event. 1131 @selector("label") 1132 NSString label(); 1133 } 1134 1135 extern class CALayer : NSObject 1136 { 1137 } 1138 1139 extern class CAMetalLayer : CALayer 1140 { 1141 @selector("pixelFormat") 1142 MTLPixelFormat pixelFormat(); 1143 @selector("setPixelFormat:") 1144 MTLPixelFormat pixelFormat(MTLPixelFormat); 1145 1146 @selector("device") 1147 MTLDevice device(); 1148 1149 @selector("drawableSize") 1150 CGSize drawableSize(); 1151 @selector("drawableSize:") 1152 CGSize drawableSize(CGSize); 1153 1154 @selector("nextDrawable") 1155 CAMetalDrawable nextDrawable(); 1156 } 1157 ///The basic type for all floating-point values. 1158 version(watchOS) 1159 alias CGFloat = float; 1160 else 1161 alias CGFloat = double; 1162 1163 ///A structure that contains a point in a two-dimensional coordinate system. 1164 struct CGPoint 1165 { 1166 CGFloat x = 0, y = 0; 1167 enum zero = CGPoint(0,0); 1168 } 1169 ///A structure that contains width and height values. 1170 struct CGSize 1171 { 1172 double width = 0; 1173 double height = 0; 1174 /// The size whose width and height are both zero. 1175 enum zero = CGSize(0, 0); 1176 } 1177 ///A structure that contains the location and dimensions of a rectangle. 1178 struct CGRect 1179 { 1180 CGPoint origin; 1181 CGSize size; 1182 } 1183 1184 /** 1185 Returns a size with the specified dimension values. 1186 1187 Params: 1188 width = A width value. 1189 height = A height value. 1190 Returns: Returns a CGSize structure with the specified width and height. 1191 */ 1192 CGSize CGSizeMake(float width, float height); 1193 }