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 14 15 16 enum MTLCPUCacheMode : NSUInteger 17 { 18 DefaultCache = 0, 19 WriteCombined = 1 20 } 21 22 immutable NSUInteger MTLResourceCPUCacheModeShift = 0; 23 immutable NSUInteger MTLResourceCPUCacheModeMask = 0xf << MTLResourceCPUCacheModeShift; 24 immutable NSUInteger MTLResourceStorageModeShift = 4; 25 immutable NSUInteger MTLResourceStorageModeMask = 0xf << MTLResourceStorageModeShift; 26 immutable NSUInteger MTLResourceHazardTrackingModeShift = 8; 27 immutable NSUInteger MTLResourceHazardTrackingModeMask = 0x3 << MTLResourceHazardTrackingModeShift; 28 29 enum MTLStorageMode : NSUInteger 30 { 31 ///The resource is stored in system memory and is accessible to both the CPU and the GPU. 32 Shared = 0, 33 ///The CPU and GPU may maintain separate copies of the resource, and any changes must be explicitly synchronized. 34 Managed = 1, 35 ///The resource can be accessed only by the GPU. 36 Private = 2, 37 ///The resource’s contents can be accessed only by the GPU and only exist temporarily during a render pass. 38 Memoryless 39 } 40 41 enum MTLHazardTrackingMode : NSUInteger 42 { 43 ///An option specifying that the default tracking mode should be used. 44 Default = 0, 45 ///An option specifying that the app must prevent hazards when modifying this object's contents. 46 Untracked = 1, 47 ///An option specifying that Metal prevents hazards when modifying this object's contents. 48 Tracked = 2 49 } 50 51 ///Optional arguments used to set the behavior of a resource. 52 enum MTLResourceOptions : NSUInteger 53 { 54 ///The default CPU cache mode for the resource, which guarantees that read and write operations are executed in the expected order. 55 DefaultCache = MTLCPUCacheMode.DefaultCache << MTLResourceCPUCacheModeShift, 56 ///A write-combined CPU cache mode that is optimized for resources that the CPU writes into, but never reads. 57 CPUCacheModeWriteCombined = MTLCPUCacheMode.WriteCombined << MTLResourceCPUCacheModeShift, 58 ///The resource is stored in system memory and is accessible to both the CPU and the GPU. 59 StorageModeShared = MTLStorageMode.Shared << MTLResourceStorageModeShift, 60 ///The CPU and GPU may maintain separate copies of the resource, which you need to explicitly synchronize. 61 StorageModeManaged = MTLStorageMode.Managed << MTLResourceStorageModeShift, 62 ///The resource can be accessed only by the GPU. 63 StorageModePrivate = MTLStorageMode.Private << MTLResourceStorageModeShift, 64 ///The resource’s contents can be accessed only by the GPU and only exist temporarily during a render pass. 65 StorageModeMemoryless = MTLStorageMode.Memoryless << MTLResourceStorageModeShift, 66 ///An option specifying that the default tracking mode should be used. 67 HazardTrackingModeDefault = MTLHazardTrackingMode.Default << MTLResourceHazardTrackingModeShift, 68 ///An option specifying that Metal prevents hazards when modifying this object's contents. 69 HazardTrackingModeTracked = MTLHazardTrackingMode.Tracked << MTLResourceHazardTrackingModeShift, 70 ///An option specifying that the app must prevent hazards when modifying this object's contents. 71 HazardTrackingModeUntracked = MTLHazardTrackingMode.Untracked << MTLResourceHazardTrackingModeShift, 72 } 73 74 ///The coordinates for the front upper-left corner of a region. 75 struct MTLOrigin 76 { 77 NSUInteger x, y, z; 78 } 79 ///Returns a new origin with the specified coordinates. 80 extern(C) MTLOrigin MTLOriginMake(NSUInteger x, NSUInteger y, NSUInteger z); 81 82 struct MTLRegion 83 { 84 ///The coordinates of the front upper-left corner of the region. 85 MTLOrigin origin; 86 ///The dimensions of the region. 87 MTLSize size; 88 } 89 90 91 extern class MTLRenderPipelineState 92 { 93 static MTLRenderPipelineState alloc() @selector("alloc"); 94 MTLRenderPipelineState init() @selector("init"); 95 96 MTLDevice device() @selector("device"); 97 NSString label() @selector("label"); 98 99 } 100 101 enum MTLTriangleFillMode : NSUInteger 102 { 103 ///Rasterize triangle and triangle strip primitives as filled triangles. 104 Fill = 0, 105 ///Rasterize triangle and triangle strip primitives as lines. 106 Lines = 1 107 } 108 109 enum MTLWinding : NSUInteger 110 { 111 ///Primitives whose vertices are specified in clockwise order are front-facing. 112 Clockwise = 0, 113 ///Primitives whose vertices are specified in counter-clockwise order are front-facing. 114 CounterClockwise = 1 115 } 116 117 struct MTLViewport 118 { 119 double originX = 0; 120 double originY = 0; 121 double width = 0; 122 double height = 0; 123 double znear = 0; 124 double zfar = 0; 125 } 126 127 enum MTLCullMode : NSUInteger 128 { 129 ///Does not cull any primitives. 130 None = 0, 131 ///Culls front-facing primitives. 132 Front = 1, 133 ///Culls back-facing primitives. 134 Back = 2 135 } 136 137 extern class MTLFunction 138 { 139 140 } 141 142 struct MTLClearColor 143 { 144 float red, green, blue, alpha; 145 } 146 147 MTLClearColor MTLClearColorMake(double red = 0.0, double green = 0.0, double blue = 0.0, double alpha = 1.0); 148 149 extern class MTLRenderPassAttachmentDescriptor : NSObject 150 { 151 } 152 153 extern class MTLRenderPassColorAttachmentDescriptor : MTLRenderPassAttachmentDescriptor 154 { 155 ///The color to use when clearing the color attachment. 156 @selector("clearColor") 157 MTLClearColor clearColor(); 158 @selector("setClearColor:") 159 MTLClearColor clearColor(MTLClearColor); 160 } 161 162 extern class MTLRenderPassColorAttachmentDescriptorArray : NSObject 163 { 164 @selector("setObject:atIndexedSubscript:") 165 void setObjectAtIndexedSubscript(MTLRenderPassColorAttachmentDescriptor attachment, NSUInteger attachmentIndex); 166 167 @selector("objectIndexedAtSubscript:") 168 MTLRenderPassColorAttachmentDescriptor objectIndexedAtSubscript(NSUInteger attachmentIndex); 169 170 MTLRenderPassColorAttachmentDescriptor opIndex(NSUInteger index) 171 { 172 return objectIndexedAtSubscript(index); 173 } 174 175 void opIndexAssign(MTLRenderPassColorAttachmentDescriptor attachment, NSUInteger index) 176 { 177 setObjectAtIndexedSubscript(attachment, index); 178 } 179 } 180 181 enum MTLMultisampleDepthResolveFilter : NSUInteger 182 { 183 ///No filter is applied. 184 Sample0 = 0, 185 ///The GPU compares all depth samples in the pixel and selects the sample with the smallest value. 186 Min, 187 ///The GPU compares all depth samples in the pixel and selects the sample with the largest value. 188 Max 189 } 190 extern class MTLRenderPassDepthAttachmentDescriptor : MTLRenderPassAttachmentDescriptor 191 { 192 double clearDepth = 1.0; 193 MTLMultisampleDepthResolveFilter depthResolveFilter = MTLMultisampleDepthResolveFilter.Sample0; 194 } 195 196 enum MTLMultisampleStencilResolveFilter : NSUInteger 197 { 198 Sample0 = 0, 199 DepthResolvedSample = 1 200 } 201 extern class MTLRenderPassStencilAttachmentDescriptor : MTLRenderPassAttachmentDescriptor 202 { 203 MTLMultisampleStencilResolveFilter stencilResolveFilter = MTLMultisampleStencilResolveFilter.Sample0; 204 uint clearStencil; 205 } 206 207 struct MTLSize 208 { 209 NSUInteger width; 210 NSUInteger height; 211 NSUInteger depth; 212 } 213 struct MTLSizeAndAlign 214 { 215 NSUInteger size; 216 NSUInteger align_; 217 } 218 219 struct MTLSamplePosition 220 { 221 float x; 222 float y; 223 } 224 225 enum MTLPrimitiveType : NSUInteger 226 { 227 ///Rasterize a point at each vertex. The vertex shader must provide [[point_size]], or the point size is undefined. 228 Point = 0, 229 ///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. 230 Line = 1, 231 ///Rasterize a line between each pair of adjacent vertices, resulting in a series of connected lines (also called a polyline). 232 LineStrip = 2, 233 ///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. 234 Triangle = 3, 235 ///For every three adjacent vertices, rasterize a triangle. 236 TriangleStrip 237 } 238 239 enum MTLIndexType : NSUInteger 240 { 241 ///A 16-bit unsigned integer used as a primitive index. 242 UInt16 = 0, 243 ///A 32-bit unsigned integer used as a primitive index. 244 UInt32 = 1 245 } 246 247 interface MTLCounterSampleBuffer 248 { 249 ///Transforms samples of a GPU’s counter set from the driver’s internal format to a standard Metal data structure. 250 @selector("resolveCounterRange:") 251 NSData resolveCounterRange(NSRange range); 252 } 253 254 alias MTLCoordinate2D = MTLSamplePosition; 255 256 MTLSize MTLSizeMake(NSUInteger width, NSUInteger height, NSUInteger depth); 257 MTLCoordinate2D MTLCoordinate2DMake(float x, float y); 258 259 extern interface MTLRasterizationRateMap 260 { 261 ///The device object that created the rate map. 262 MTLDevice device() @selector("device"); 263 ///A string that identifies the rate map. 264 NSString label() @selector("label"); 265 ///The number of layers in the rate map. 266 NSUInteger layerCount() @selector("layerCount"); 267 ///The logical size, in pixels, of the viewport coordinate system. 268 MTLSize screenSize() @selector("screenSize"); 269 270 ///Returns the dimensions, in pixels, of the area in the render target affected by the rasterization rate map. 271 @selector("physicalSizeForLayer:") 272 MTLSize physicalSizeForLayer(NSUInteger layerIndex); 273 274 ///The granularity, in physical pixels, at which the rasterization rate varies. 275 MTLSize physicalGranularity() @selector("physicalGranularity"); 276 277 ///Converts a point in logical viewport coordinates to the corresponding physical coordinates in a render layer. 278 @selector("mapScreenToPhysicalCoordinates:forLayer:") 279 MTLCoordinate2D mapScreenToPhysicalCoordinates(MTLCoordinate2D screenCoordinates, NSUInteger layerIndex); 280 281 ///Converts a point in physical coordinates inside a layer to its corresponding logical viewport coordinates. 282 @selector("mapPhysicalToScreenCoordinates:forLayer:") 283 MTLCoordinate2D mapPhysicalToScreenCoordinates(MTLCoordinate2D physicalCoordinates, NSUInteger layerIndex); 284 285 ///The size and alignment requirements to contain the coordinate transformation information in this rate map. 286 @selector("parameterBufferSizeAndAlign") 287 MTLSizeAndAlign parameterBufferSizeAndAlign(); 288 289 ///Copies the parameter data into the provided buffer. 290 @selector("copyParameterDataToBuffer:offset:") 291 void copyParameterDataToBuffer(MTLBuffer buffer, NSUInteger offset); 292 293 294 } 295 296 297 298 ///A description of where to store GPU counter information at the start and end of a render pass. 299 extern class MTLRenderPassSampleBufferAttachmentDescriptor : NSObject 300 { 301 ///The sample buffer to write new GPU counter samples to. 302 @selector("sampleBuffer") 303 MTLCounterSampleBuffer sampleBuffer(); 304 @selector("setSampleBuffer:") 305 MTLCounterSampleBuffer sampleBuffer(MTLCounterSampleBuffer sampleBuffer); 306 307 ///The index the Metal device object should use to store GPU counters when starting the render pass’s vertex stage. 308 @selector("startOfVertexSampleIndex") 309 NSUInteger startOfVertexSampleIndex(); 310 @selector("setStartOfVertexSampleIndex:") 311 NSUInteger startOfVertexSampleIndex(NSUInteger); 312 313 ///The index the Metal device object should use to store GPU counters when ending the render pass’s vertex stage. 314 @selector("endOfVertexSampleIndex") 315 NSUInteger endOfVertexSampleIndex(); 316 @selector("setEndOfVertexSampleIndex:") 317 NSUInteger endOfVertexSampleIndex(NSUInteger); 318 319 ///The index the Metal device object should use to store GPU counters when starting the render pass’s fragment stage. 320 @selector("startOfFragmentSampleIndex") 321 NSUInteger startOfFragmentSampleIndex(); 322 @selector("setStartOfFragmentSampleIndex:") 323 NSUInteger startOfFragmentSampleIndex(NSUInteger); 324 325 ///The index the Metal device object should use to store GPU counters when ending the render pass’s fragment stage. 326 @selector("endOfFragmentSampleIndex") 327 NSUInteger endOfFragmentSampleIndex(); 328 @selector("setEndOfFragmentSampleIndex:") 329 NSUInteger endOfFragmentSampleIndex(NSUInteger); 330 331 332 } 333 334 extern class MTLRenderPassSampleBufferAttachmentDescriptorArray : NSObject 335 { 336 ///Returns the descriptor object for the specified sample buffer attachment. 337 @selector("objectAtIndexedSubscript:") 338 MTLRenderPassSampleBufferAttachmentDescriptor objectAtIndexedSubscript(NSUInteger attachmentIndex); 339 340 ///Sets the descriptor object for the specified sample buffer attachment. 341 @selector("setObject:atIndexedSubscript:") 342 void setObjectAtIndexedSubscript(MTLRenderPassSampleBufferAttachmentDescriptor attachment, NSUInteger attachmentIndex); 343 } 344 345 ///A group of render targets that hold the results of a render pass. 346 extern class MTLRenderPassDescriptor 347 { 348 ///Creates a default render pass descriptor. 349 @selector("renderPassDescriptor") 350 static MTLRenderPassDescriptor renderPassDescriptor(); 351 352 ///An array of state information for attachments that store color data. 353 @selector("colorAttachments") 354 MTLRenderPassColorAttachmentDescriptorArray colorAttachments(); 355 356 ///State information for an attachment that stores depth data. 357 @selector("depthAttachment") 358 MTLRenderPassDepthAttachmentDescriptor depthAttachment(); 359 @selector("setDepthAttachment:") 360 MTLRenderPassDepthAttachmentDescriptor depthAttachment(MTLRenderPassDepthAttachmentDescriptor); 361 362 ///State information for an attachment that stores stencil data. 363 @selector("stencilAttachment") 364 MTLRenderPassStencilAttachmentDescriptor stencilAttachment(); 365 @selector("setStencilAttachment:") 366 MTLRenderPassStencilAttachmentDescriptor stencilAttachment(MTLRenderPassStencilAttachmentDescriptor); 367 368 ///A buffer where the GPU writes visibility test results when fragments pass depth and stencil tests. 369 @selector("visibilityResultBuffer") 370 MTLBuffer visibilityResultBuffer(); 371 @selector("setVisibilityResultBuffer:") 372 MTLBuffer visibilityResultBuffer(MTLBuffer); 373 374 ///The number of active layers that all attachments must have for layered rendering. 375 @selector("renderTargetArrayLength") 376 NSUInteger renderTargetArrayLength(); 377 @selector("setRenderTargetArrayLength:") 378 NSUInteger renderTargetArrayLength(NSUInteger); 379 380 /// The width, in pixels, to constrain the render target to. 381 @selector("renderTargetWidth") 382 NSUInteger renderTargetWidth(); 383 @selector("setRenderTargetWidth:") 384 NSUInteger renderTargetWidth(NSUInteger); 385 386 ///The height, in pixels, to constrain the render target to. 387 @selector("renderTargetHeight") 388 NSUInteger renderTargetHeight(); 389 @selector("setRenderTargetHeight:") 390 NSUInteger renderTargetHeight(NSUInteger); 391 392 393 ///Sets the programmable sample positions for a render pass. 394 @selector("setSamplePositions:count:") 395 void setSamplePositions(const MTLSamplePosition positions, NSUInteger count); 396 397 @selector("getSamplePositions:count:") 398 NSUInteger getSamplePositions(MTLSamplePosition positions, NSUInteger count); 399 400 ///The per-sample size, in bytes, of the largest explicit imageblock layout in the render pass. 401 @selector("imageBlockSampleLength") 402 NSUInteger imageBlockSampleLength(); 403 @selector("setImageBlockSampleLength:") 404 NSUInteger imageBlockSampleLength(NSUInteger); 405 406 ///The per-tile size, in bytes, of the persistent threadgroup memory allocation. 407 @selector("threadgroupMemoryLength") 408 NSUInteger threadgroupMemoryLength(); 409 @selector("setThreadgroupMemoryLength:") 410 NSUInteger threadgroupMemoryLength(NSUInteger); 411 412 ///The tile width, in pixels. 413 @selector("tileWidth") 414 NSUInteger tileWidth(); 415 @selector("setTileWidth:") 416 NSUInteger tileWidth(NSUInteger); 417 418 419 ///The tile height, in pixels. 420 @selector("tileHeight") 421 NSUInteger tileHeight(); 422 @selector("setTileHeight:") 423 NSUInteger tileHeight(NSUInteger); 424 425 ///The raster sample count for the render pass when the render pass doesn’t have explicit attachments. 426 @selector("defaultRasterSampleCount") 427 NSUInteger defaultRasterSampleCount(); 428 @selector("setDefaultRasterSampleCount:") 429 NSUInteger defaultRasterSampleCount(NSUInteger); 430 431 ///The rasterization rate map to use when executing the render pass. 432 @selector("rasterizationRateMap") 433 MTLRasterizationRateMap rasterizationRateMap(); 434 @selector("setRasterizationRateMap:") 435 MTLRasterizationRateMap rasterizationRateMap(MTLRasterizationRateMap); 436 437 ///The array of sample buffers that the render pass can access. 438 @selector("sampleBufferAttachments") 439 MTLRenderPassSampleBufferAttachmentDescriptorArray sampleBufferAttachments(); 440 441 } 442 443 444 445 enum MTLColorWriteMask : NSUInteger 446 { 447 None = 0, 448 Red = 0x1 << 3, 449 Green = 0x1 << 2, 450 Blue = 0x1 << 1, 451 Alpha = 0x1 << 0, 452 All = 0xf 453 } 454 455 enum MTLBlendOperation : NSUInteger 456 { 457 ///Add portions of both source and destination pixel values. 458 Add = 0, 459 ///Subtract a portion of the destination pixel values from a portion of the source. 460 Subtract = 1, 461 ///Subtract a portion of the source values from a portion of the destination pixel values. 462 ReverseSubtract = 2, 463 ///Minimum of the source and destination pixel values. 464 Min = 3, 465 ///Maximum of the source and destination pixel values. 466 Max = 4 467 } 468 469 enum MTLBlendFactor : NSUInteger 470 { 471 Zero = 0, 472 One = 1, 473 ///Blend factor of source values. 474 SourceColor = 2, 475 ///Blend factor of one minus source values. 476 OneMinusSourceColor = 3, 477 ///Blend factor of source alpha. 478 SourceAlpha = 4, 479 ///Blend factor of one minus source alpha. 480 OneMinusSourceAlpha = 5, 481 ///Blend factor of destination values. 482 DestinationColor = 6, 483 ///Blend factor of one minus destination values. 484 OneMinusDestinationColor = 7, 485 ///Blend factor of one minus destination values. 486 DestinationAlpha = 8, 487 ///Blend factor of one minus destination alpha. 488 OneMinusDestinationAlpha = 9, 489 ///Blend factor of the minimum of either source alpha or one minus destination alpha. 490 SourceAlphaSaturated = 10, 491 ///Blend factor of RGB values. 492 BlendColor = 11, 493 ///Blend factor of one minus RGB values. 494 OneMinusBlendColor = 12, 495 ///Blend factor of alpha value. 496 BlendAlpha = 13, 497 ///Blend factor of one minus alpha value. 498 OneMinusBlendAlpha = 14, 499 ///Blend factor of source values. This option supports dual-source blending and reads from the second color output of the fragment function. 500 Source1Color = 15, 501 ///Blend factor of one minus source values. This option supports dual-source blending and reads from the second color output of the fragment function. 502 OneMinusSource1Color = 16, 503 ///Blend factor of source alpha. This option supports dual-source blending and reads from the second color output of the fragment function. 504 Source1Alpha = 17, 505 ///Blend factor of one minus source alpha. This option supports dual-source blending and reads from the second color output of the fragment function. 506 OneMinusSource1Alpha = 18 507 508 } 509 510 extern class MTLRenderPipelineColorAttachmentDescriptor 511 { 512 ///The pixel format of the color attachment’s texture. 513 MTLPixelFormat pixelFormat() @selector("pixelFormat"); 514 MTLPixelFormat pixelFormat(MTLPixelFormat) @selector("setPixelFormat:"); 515 516 ///A bitmask that restricts which color channels are written into the texture. 517 @selector("writeMask") 518 MTLColorWriteMask writeMask(); 519 @selector("setWriteMask:") 520 MTLColorWriteMask writeMask(MTLColorWriteMask); 521 522 ///A Boolean value that determines whether blending is enabled. 523 @selector("blendingEnabled") 524 BOOL isBlendingEnabled(); 525 @selector("setBlendingEnabled:") 526 BOOL blendingEnabled(BOOL); 527 528 ///The blend operation assigned for the alpha data. 529 @selector("alphaBlendOperation") 530 MTLBlendOperation alphaBlendOperation(); 531 @selector("setAlphaBlendOperation:") 532 MTLBlendOperation alphaBlendOperation(MTLBlendOperation); 533 534 ///The blend operation assigned for the RGB data. 535 @selector("rgbBlendOperation") 536 MTLBlendOperation rgbBlendOperation(); 537 @selector("setRgbBlendOperation:") 538 MTLBlendOperation rgbBlendOperation(MTLBlendOperation); 539 540 ///The destination blend factor (DBF) used by the alpha blend operation. 541 @selector("destinationAlphaBlendFactor") 542 MTLBlendFactor destinationAlphaBlendFactor(); 543 @selector("setDestinationAlphaBlendFactor:") 544 MTLBlendFactor destinationAlphaBlendFactor(MTLBlendFactor); 545 546 ///The destination blend factor (DBF) used by the RGB blend operation. 547 @selector("destinationRGBBlendFactor") 548 MTLBlendFactor destinationRGBBlendFactor(); 549 @selector("setDestinationRGBBlendFactor:") 550 MTLBlendFactor destinationRGBBlendFactor(MTLBlendFactor); 551 552 ///The source blend factor (SBF) used by the alpha blend operation. 553 @selector("sourceAlphaBlendFactor") 554 MTLBlendFactor sourceAlphaBlendFactor(); 555 @selector("setSourceAlphaBlendFactor:") 556 MTLBlendFactor sourceAlphaBlendFactor(MTLBlendFactor); 557 558 ///The source blend factor (SBF) used by the RGB blend operation. 559 @selector("sourceRGBBlendFactor") 560 MTLBlendFactor sourceRGBBlendFactor(); 561 @selector("setSourceRGBBlendFactor:") 562 MTLBlendFactor sourceRGBBlendFactor(MTLBlendFactor); 563 564 565 566 567 } 568 569 extern class MTLRenderPipelineColorAttachmentDescriptorArray : NSObject 570 { 571 override static MTLRenderPipelineColorAttachmentDescriptorArray alloc() @selector("alloc"); 572 override MTLRenderPipelineColorAttachmentDescriptorArray initialize() @selector("init"); 573 574 @selector("setObject:atIndexedSubscript:") 575 void setObjectAtIndexedSubscript(MTLRenderPipelineColorAttachmentDescriptor attachment, NSUInteger attachmentIndex); 576 577 @selector("objectAtIndexedSubscript:") 578 MTLRenderPipelineColorAttachmentDescriptor objectAtIndexedSubscript(NSUInteger attachmentIndex); 579 580 extern(D) final MTLRenderPipelineColorAttachmentDescriptor opIndex(NSUInteger index) 581 { 582 return objectAtIndexedSubscript(index); 583 } 584 extern(D) final void opIndexAssign(NSUInteger index, MTLRenderPipelineColorAttachmentDescriptor v) 585 { 586 setObjectAtIndexedSubscript(v, index); 587 } 588 } 589 590 extern class MTLRenderPipelineDescriptor : NSObject 591 { 592 // mixin ObjectiveCOpCall; 593 override static MTLRenderPipelineDescriptor alloc() @selector("alloc"); 594 override MTLRenderPipelineDescriptor initialize() @selector("init"); 595 596 ///A string that identifies the render pipeline descriptor. 597 NSString label() @selector("label"); 598 NSString label(NSString) @selector("setLabel:"); 599 600 ///The vertex function the pipeline calls to process vertices. 601 MTLFunction vertexFunction() @selector("vertexFunction"); 602 MTLFunction vertexFunction(MTLFunction) @selector("setVertexFunction:"); 603 604 ///The fragment function the pipeline calls to process fragments. 605 MTLFunction fragmentFunction() @selector("fragmentFunction"); 606 MTLFunction fragmentFunction(MTLFunction) @selector("setFragmentFunction:"); 607 608 ///The organization of vertex data in an attribute’s argument table. 609 MTLVertexDescriptor vertexDescriptor() @selector("vertexDescriptor"); 610 MTLVertexDescriptor vertexDescriptor(MTLVertexDescriptor) @selector("setVertexDescriptor:"); 611 612 613 ///An array of attachments that store color data. 614 MTLRenderPipelineColorAttachmentDescriptorArray colorAttachments() @selector("colorAttachments"); 615 616 ///The pixel format of the attachment that stores depth data. 617 MTLPixelFormat depthAttachmentPixelFormat() @selector("depthAttachmentPixelFormat"); 618 MTLPixelFormat depthAttachmentPixelFormat(MTLPixelFormat) @selector("setDepthAttachmentPixelFormat:"); 619 620 ///The pixel format of the attachment that stores stencil data. 621 MTLPixelFormat stencilAttachmentPixelFormat() @selector("stencilAttachmentPixelFormat"); 622 MTLPixelFormat stencilAttachmentPixelFormat(MTLPixelFormat) @selector("setStencilAttachmentPixelFormat:"); 623 624 625 } 626 interface MTLIOCommandQueue 627 { 628 629 } 630 631 extern class MTLIOCommandQueueDescriptor : NSObject 632 { 633 634 } 635 636 637 extern class MTLDevice 638 { 639 640 ///Creates a queue you use to submit rendering and computation commands to a GPU. 641 @selector("newCommandQueue") 642 MTLCommandQueue newCommandQueue(); 643 644 ///Creates a queue you use to submit rendering and computation commands to a GPU that has a fixed number of uncompleted command buffers. 645 @selector("newCommandQueueWithMaxCommandBufferCount:") 646 MTLCommandQueue newCommandQueue(NSUInteger maxCommandBufferCount); 647 648 ///Creates a buffer the method clears with zero values, length is size in bytes. 649 @selector("newBufferWithLength:options:") 650 MTLBuffer newBuffer(NSUInteger length, MTLResourceOptions options); 651 652 ///Allocates a new buffer of a given length and initializes its contents by copying existing data into it. 653 @selector("newBufferWithBytes:length:options:") 654 MTLBuffer newBuffer(const(void)* pointer, NSUInteger length, MTLResourceOptions options); 655 656 ///Creates a new texture instance. 657 @selector("newTextureWithDescriptor:") 658 MTLTexture newTextureWithDescriptor(MTLTextureDescriptor descriptor); 659 660 661 ///Synchronously creates a Metal library instance by compiling the functions in a source string. 662 @selector("newLibraryWithSource:options:error:") 663 MTLLibrary newLibraryWithSource(NSString source, MTLCompileOptions options, NSError* error = null); 664 665 ///Creates a Metal library instance that contains the functions from your app’s default Metal library. 666 @selector("newDefaultLibrary") 667 MTLLibrary newDefaultLibrary(); 668 669 670 671 672 ///Creates an input/output command queue you use to submit commands that load assets from the file system into GPU resources or system memory. 673 @selector("newIOCommandQueueWithDescriptor:error:") 674 MTLIOCommandQueue newIOCommandQueueWithDescriptor(MTLIOCommandQueueDescriptor descriptor, NSError* error = null); 675 676 ///Synchronously creates a render pipeline state. 677 @selector("newRenderPipelineStateWithDescriptor:error:") 678 MTLRenderPipelineState newRenderPipelineStateWithDescriptor(MTLRenderPipelineDescriptor descriptor, NSError* error = null); 679 680 ///Returns a Boolean value that indicates whether the GPU can sample a texture with a specific number of sample points. 681 @selector("supportsTextureSampleCount:") 682 BOOL supportsTextureSampleCount(NSUInteger sampleCount); 683 684 ///Creates a sampler state instance. 685 MTLSamplerState newSamplerStateWithDescriptor(MTLSamplerDescriptor descriptor); 686 687 688 } 689 690 ///A block of code invoked after a drawable is presented. 691 alias MTLDrawablePresentedHandler = extern(C) void function(MTLDrawable); 692 693 694 695 ///A displayable resource that can be rendered or written to. 696 extern interface MTLDrawable 697 { 698 ///A positive integer that identifies the drawable. 699 @selector("drawableID") 700 NSUInteger drawableID(); 701 702 ///Presents the drawable onscreen as soon as possible. 703 @selector("present") 704 void present(); 705 706 ///Presents the drawable onscreen at a specific host time. 707 @selector("presentAtTime:") 708 void present(CFTimeInterval presentationTime); 709 710 ///Presents the drawable onscreen as soon as possible after a previous drawable is visible for the specified duration. 711 @selector("presentAfterMinimumDuration:") 712 void presentAfterMinimumDuration(CFTimeInterval duration); 713 714 715 ///Registers a block of code to be called immediately after the drawable is presented. 716 @selector("addPresentedHandler:") 717 void addPresentedHandler(MTLDrawablePresentedHandler); 718 719 ///The host time, in seconds, when the drawable was displayed onscreen. 720 @selector("presentedTime") 721 CFTimeInterval presentedTime(); 722 } 723 724 725 MTLSamplePosition MTLSamplePositionMake(float x, float y); 726 MTLCommandBuffer MTLCreateSystemDefaultDevice(); 727 728 ///An instance you use to create, submit, and schedule command buffers to a specific GPU device to run the commands within those buffers. 729 extern interface MTLCommandQueue 730 { 731 ///Returns a command buffer from the command queue that you configure with a descriptor. 732 @selector("commandBufferWithDescriptor:") 733 MTLCommandBuffer commandBuffer(MTLCommandBufferDescriptor* descriptor); 734 735 ///Returns a command buffer from the command queue that maintains strong references to resources. 736 @selector("commandBuffer") 737 MTLCommandBuffer commandBuffer(); 738 739 ///Returns a command buffer from the command queue that doesn’t maintain strong references to resources. 740 @selector("commandBufferWithUnretainedReferences") 741 MTLCommandBuffer commandBufferWithUnretainedReferences(); 742 743 ///An optional name that can help you identify the command queue. 744 @selector("label") 745 NSString label(); 746 @selector("setLabel:") 747 NSString label(NSString); 748 749 } 750 751 ///A Metal drawable associated with a Core Animation layer. 752 extern interface CAMetalDrawable : MTLDrawable 753 { 754 ///A Metal texture object that contains the drawable’s contents. 755 @selector("texture") 756 MTLTexture texture(); 757 ///The layer that owns this drawable object. 758 // @selector("layer") 759 // CAMetalLayer layer(); 760 } 761 762 763 764 extern interface MTLBuffer 765 { 766 ///Creates a texture that shares its storage with the buffer. 767 @selector("newTextureWithDescriptor:offset:bytesPerRow:") 768 MTLTexture newTextureWithDescriptor( 769 MTLTextureDescriptor, 770 NSUInteger offset, 771 NSUInteger bytesPerRow 772 ); 773 774 775 ///Gets the system address of the buffer’s storage allocation. 776 void* contents() @selector("contents"); 777 ///Informs the GPU that the CPU has modified a section of the buffer. 778 void didModifyRange(NSRange) @selector("didModifyRange:"); 779 780 ///Adds a debug marker string to a specific buffer range. 781 @selector("addDebugMarker:range:") 782 void addDebugMarker(NSString marker, NSRange range); 783 784 ///Removes all debug marker strings from the buffer. 785 @selector("removeAllDebugMarkers") 786 void removeAllDebugMarkers(); 787 788 ///The logical size of the buffer, in bytes. 789 @selector("length") 790 NSUInteger length(); 791 792 @selector("dealloc") 793 void dealloc(); 794 } 795 796 ///An object you use to synchronize access to Metal resources. 797 extern interface MTLEvent 798 { 799 ///The device object that created the event. 800 @selector("device") 801 MTLDevice device(); 802 803 ///A string that identifies the event. 804 @selector("label") 805 NSString label(); 806 } 807 }