1 module metal.texture; 2 import objc.meta: selector, ObjcExtend; 3 @ObjectiveC final extern(C++): 4 @nogc nothrow: 5 6 import metal.metal; 7 import metal.pixelformat; 8 9 10 ///Modes that determine the texture coordinate at each pixel when a fetch falls outside the bounds of a texture. 11 enum MTLSamplerAddressMode : NSUInteger 12 { 13 ///Texture coordinates are clamped between 0.0 and 1.0, inclusive. 14 ClampToEdge = 0, 15 ///Between -1.0 and 1.0, the texture coordinates are mirrored across the axis; outside -1.0 and 1.0, texture coordinates are clamped. 16 MirrorClampToEdge = 1, 17 ///Texture coordinates wrap to the other side of the texture, effectively keeping only the fractional part of the texture coordinate. 18 Repeat = 2, 19 ///Between -1.0 and 1.0, the texture coordinates are mirrored across the axis; outside -1.0 and 1.0, the image is repeated. 20 MirrorRepeat = 3, 21 ///Out-of-range texture coordinates return transparent zero (0,0,0,0) for images with an alpha channel and return opaque zero (0,0,0,1) for images without an alpha channel. 22 ClampToZero = 4, 23 ///Out-of-range texture coordinates return the value specified by the borderColor property. 24 ClampToBorderColor = 5 25 } 26 27 ///Values that determine the border color for clamped texture values when the sampler address mode is MTLSamplerAddressModeClampToBorderColor. 28 enum MTLSamplerBorderColor : NSUInteger 29 { 30 ///A transparent black color (0,0,0,0) for texture values outside the border. 31 TransparentBlack = 0, 32 ///An opaque black color (0,0,0,1) for texture values outside the border 33 OpaqueBlack = 1, 34 ///An opaque white color (1,1,1,1) for texture values outside the border. 35 OpaqueWhite = 2 36 } 37 38 ///Filtering options for determining which pixel value is returned within a mipmap level. 39 enum MTLSamplerMinMagFilter : NSUInteger 40 { 41 ///Select the single pixel nearest to the sample point. 42 Nearest = 0, 43 ///Select two pixels in each dimension and interpolate linearly between them. 44 Linear = 1 45 } 46 47 ///Filtering options for determining what pixel value is returned with multiple mipmap levels. 48 enum MTLSamplerMipFilter : NSUInteger 49 { 50 ///The texture is sampled from mipmap level 0, and other mipmap levels are ignored. 51 NotMipmapped = 0, 52 ///The nearest mipmap level is selected. 53 Nearest = 1, 54 ///If the filter falls between mipmap levels, both levels are sampled and the results are determined by linear interpolation between levels. 55 Linear = 2 56 } 57 58 ///Options used to specify how a sample compare operation should be performed on a depth texture. 59 enum MTLCompareFunction : NSUInteger 60 { 61 ///A new value never passes the comparison test. 62 Never = 0, 63 ///A new value passes the comparison test if it is less than the existing value. 64 Less = 1, 65 ///A new value passes the comparison test if it is equal to the existing value. 66 Equal = 2, 67 ///A new value passes the comparison test if it is less than or equal to the existing value. 68 LessEqual = 3, 69 ///A new value passes the comparison test if it is greater than the existing value. 70 Greater = 4, 71 ///A new value passes the comparison test if it is not equal to the existing value. 72 NotEqual = 5, 73 ///A new value passes the comparison test if it is greater than or equal to the existing value. 74 GreaterEqual = 6, 75 ///A new value always passes the comparison test. 76 Always = 7 77 78 } 79 80 ///An object that you use to configure a texture sampler. 81 class MTLSamplerDescriptor 82 { 83 @nogc nothrow: 84 mixin ObjcExtend!NSObject; 85 86 @selector("alloc") 87 static MTLSamplerDescriptor alloc(); 88 89 @selector("init") 90 MTLSamplerDescriptor initialize(); 91 92 ///A Boolean value that indicates whether texture coordinates are normalized to the range [0.0, 1.0]. 93 @selector("normalizedCoordinates") 94 BOOL normalizedCoordinates(); 95 96 ///The address mode for the texture depth (r) coordinate. 97 @selector("rAddressMode") 98 MTLSamplerAddressMode rAddressMode(); 99 @selector("setRAddressMode:") 100 MTLSamplerAddressMode rAddressMode(MTLSamplerAddressMode); 101 102 ///The address mode for the texture width (s) coordinate. 103 @selector("sAddressMode") 104 MTLSamplerAddressMode sAddressMode(); 105 @selector("setSAddressMode:") 106 MTLSamplerAddressMode sAddressMode(MTLSamplerAddressMode); 107 108 ///The address mode for the texture height (t) coordinate. 109 @selector("tAddressMode") 110 MTLSamplerAddressMode tAddressMode(); 111 @selector("setTAddressMode:") 112 MTLSamplerAddressMode tAddressMode(MTLSamplerAddressMode); 113 114 ///The border color for clamped texture values. 115 @selector("borderColor") 116 MTLSamplerBorderColor borderColor(); 117 @selector("setBorderColor:") 118 MTLSamplerBorderColor borderColor(MTLSamplerBorderColor); 119 120 ///The filtering option for combining pixels within one mipmap level when the sample footprint is larger than a pixel (minification). 121 @selector("minFilter") 122 MTLSamplerMinMagFilter minFilter(); 123 @selector("setMinFilter:") 124 MTLSamplerMinMagFilter minFilter(MTLSamplerMinMagFilter); 125 126 ///The filtering operation for combining pixels within one mipmap level when the sample footprint is smaller than a pixel (magnification). 127 @selector("magFilter") 128 MTLSamplerMinMagFilter magFilter(); 129 @selector("setMagFilter:") 130 MTLSamplerMinMagFilter magFilter(MTLSamplerMinMagFilter); 131 132 ///The filtering option for combining pixels between two mipmap levels. 133 @selector("mipFilter") 134 MTLSamplerMipFilter mipFilter(); 135 @selector("setMipFilter:") 136 MTLSamplerMipFilter mipFilter(MTLSamplerMipFilter); 137 138 ///The minimum level of detail (LOD) to use when sampling from a texture. 139 @selector("lodMinClamp") 140 float lodMinClamp(); 141 @selector("setLodMinClamp:") 142 float lodMinClamp(float); 143 144 ///The maximum level of detail (LOD) to use when sampling from a texture. 145 @selector("lodMaxClamp") 146 float lodMaxClamp(); 147 @selector("setLodMaxClamp:") 148 float lodMaxClamp(float); 149 150 ///A Boolean value that specifies whether the GPU can use an average level of detail (LOD) when sampling from a texture. 151 @selector("lodAverage") 152 BOOL lodAverage(); 153 @selector("setlodAverage:") 154 BOOL lodAverage(BOOL); 155 156 ///The number of samples that can be taken to improve the quality of sample footprints that are anisotropic. 157 @selector("maxAnisotropy") 158 NSUInteger maxAnisotropy(); 159 @selector("setMaxAnisotropy:") 160 NSUInteger maxAnisotropy(NSUInteger); 161 162 163 ///The sampler comparison function used when performing a sample compare operation on a depth texture. 164 @selector("compareFunction") 165 MTLCompareFunction compareFunction(); 166 @selector("setCompareFunction:") 167 MTLCompareFunction compareFunction(MTLCompareFunction); 168 169 170 ///A Boolean value that specifies whether the sampler can be encoded into an argument buffer. 171 @selector("supportArgumentBuffers") 172 BOOL supportArgumentBuffers(); 173 @selector("setSupportArgumentBuffers:") 174 BOOL supportArgumentBuffers(BOOL); 175 176 ///A string that identifies the sampler. 177 @selector("label") 178 NSString label(); 179 @selector("setLabel:") 180 NSString label(NSString); 181 182 183 } 184 185 ///An object that defines how a texture should be sampled. 186 interface MTLSamplerState 187 { 188 @nogc nothrow: 189 ///The device object that created the sampler. 190 @selector("device") 191 MTLDevice device(); 192 193 ///A string that identifies the sampler. 194 @selector("label") 195 NSString label(); 196 197 @selector("release") 198 void release(); 199 } 200 201 ///A set of options to choose from when creating a texture swizzle pattern. 202 enum MTLTextureSwizzle : ubyte 203 { 204 ///The alpha channel of the source pixel is copied to the destination channel. 205 Alpha = 5, 206 ///The blue channel of the source pixel is copied to the destination channel. 207 Blue = 4, 208 ///The green channel of the source pixel is copied to the destination channel. 209 Green = 3, 210 ///The red channel of the source pixel is copied to the destination channel. 211 Red = 2, 212 ///A value of 1.0 is copied to the destination channel. 213 One = 1, 214 ///A value of 0.0 is copied to the destination channel. 215 Zero = 0 216 } 217 218 extern(C) MTLTextureSwizzleChannels MTLTextureSwizzleChannelsMake(MTLTextureSwizzle r, MTLTextureSwizzle g, MTLTextureSwizzle b, MTLTextureSwizzle a); 219 220 ///A pattern that modifies the data read or sampled from a texture by rearranging or duplicating the elements of a vector. 221 struct MTLTextureSwizzleChannels 222 { 223 MTLTextureSwizzle red; 224 MTLTextureSwizzle green; 225 MTLTextureSwizzle blue; 226 MTLTextureSwizzle alpha; 227 } 228 229 230 ///The dimension of each image, including whether multiple images are arranged into an array or a cube. 231 enum MTLTextureType : NSUInteger 232 { 233 ///A one-dimensional texture image. 234 _1D = 0, 235 ///An array of one-dimensional texture images. 236 _1DArray = 1, 237 ///A two-dimensional texture image. 238 _2D = 2, 239 ///An array of two-dimensional texture images. 240 _2DArray = 3, 241 ///A two-dimensional texture image that uses more than one sample for each pixel. 242 _2DMultisample = 4, 243 ///A cube texture with six two-dimensional images. 244 Cube = 5, 245 //An array of cube textures, each with six two-dimensional images. 246 CubeArray = 6, 247 ///A three-dimensional texture image. 248 _3D = 7, 249 ///An array of two-dimensional texture images that use more than one sample for each pixel. 250 _2DMultisampleArray = 8, 251 ///A texture buffer. 252 TextureBuffer = 9 253 } 254 255 ///An enumeration for the various options that determine how you can use a texture. 256 enum MTLTextureUsage : NSUInteger 257 { 258 ///An enumeration for the various options that determine how you can use a texture. 259 Unknown = 0x0000, 260 ///An option for reading or sampling from the texture in a shader. 261 ShaderRead = 0x0001, 262 ///An option for writing to the texture in a shader. 263 ShaderWrite = 0x0002, 264 ///An option for rendering to the texture in a render pass. 265 RenderTarget = 0x0004, 266 ///An option to create texture views with a different component layout. 267 PixelFormatView = 0x0010 268 } 269 270 enum MTLTextureCompressionType : NSInteger 271 { 272 Lossless = 0, 273 Lossy = 1 274 } 275 276 ///An object that you use to configure new Metal texture objects. 277 class MTLTextureDescriptor 278 { 279 @nogc nothrow: 280 mixin ObjcExtend!NSObject; 281 @selector("alloc") 282 static MTLTextureDescriptor alloc(); 283 @selector("init") 284 MTLTextureDescriptor initialize(); 285 286 ///Creates a texture descriptor object for a 2D texture. 287 @selector("texture2DDescriptorWithPixelFormat:width:height:mipmapped:") 288 static MTLTextureDescriptor texture2DDescriptorWithPixelFormat( 289 MTLPixelFormat, 290 NSUInteger width, 291 NSUInteger height, 292 BOOL mipmapped 293 ); 294 295 ///Creates a texture descriptor object for a cube texture. 296 @selector("textureCubeDescriptorWithPixelFormat:size:mipmapped:") 297 static MTLTextureDescriptor textureCubeDescriptorWithPixelFormat( 298 MTLPixelFormat, 299 NSUInteger size, 300 BOOL mipmapped 301 ); 302 303 ///Creates a texture descriptor object for a texture buffer. 304 @selector("textureBufferDescriptorWithPixelFormat:width:resourceOptions:usage:") 305 static MTLTextureDescriptor textureBufferDescriptorWithPixelFormat( 306 MTLPixelFormat, 307 NSUInteger width, 308 MTLResourceOptions resourceOptions, 309 MTLTextureUsage usage, 310 ); 311 312 ///The dimension and arrangement of texture image data. 313 @selector("textureType") 314 MTLTextureType textureType(); 315 @selector("setTextureType:") 316 MTLTextureType textureType(MTLTextureType); 317 318 ///The size and bit layout of all pixels in the texture. 319 @selector("pixelFormat") 320 MTLPixelFormat pixelFormat(); 321 @selector("setPixelFormat:") 322 MTLPixelFormat pixelFormat(MTLPixelFormat); 323 324 ///The width of the texture image for the base level mipmap, in pixels. 325 @selector("width") 326 NSUInteger width(); 327 @selector("setWidth:") 328 NSUInteger width(NSUInteger); 329 330 ///The height of the texture image for the base level mipmap, in pixels. 331 @selector("height") 332 NSUInteger height(); 333 @selector("setHeight:") 334 NSUInteger height(NSUInteger); 335 336 ///The depth of the texture image for the base level mipmap, in pixels. 337 @selector("depth") 338 NSUInteger depth(); 339 @selector("setDepth:") 340 NSUInteger depth(NSUInteger); 341 342 ///The number of mipmap levels for this texture. 343 @selector("mipmapLevelCount") 344 NSUInteger mipmapLevelCount(); 345 @selector("setMipmapLevelCount:") 346 NSUInteger mipmapLevelCount(NSUInteger); 347 348 ///The number of samples in each fragment. 349 @selector("sampleCount") 350 NSUInteger sampleCount(); 351 @selector("setSampleCount:") 352 NSUInteger sampleCount(NSUInteger); 353 354 ///The number of array elements for this texture. 355 @selector("arrayLength") 356 NSUInteger arrayLength(); 357 @selector("setArrayLength:") 358 NSUInteger arrayLength(NSUInteger); 359 360 ///The behavior of a new memory allocation. 361 @selector("resourceOptions") 362 MTLResourceOptions resourceOptions(); 363 @selector("setResourceOptions:") 364 MTLResourceOptions resourceOptions(MTLResourceOptions); 365 366 ///The CPU cache mode used for the CPU mapping of the texture. 367 @selector("cpuCacheMode") 368 MTLCPUCacheMode cpuCacheMode(); 369 @selector("setCpuCacheMode:") 370 MTLCPUCacheMode cpuCacheMode(MTLCPUCacheMode); 371 372 ///The location and access permissions of the texture. 373 @selector("storageMode") 374 MTLStorageMode storageMode(); 375 @selector("setStorageMode:") 376 MTLStorageMode storageMode(MTLStorageMode); 377 378 ///The texture's hazard tracking mode. 379 @selector("hazardTrackingMode") 380 MTLHazardTrackingMode hazardTrackingMode(); 381 @selector("setHazardTrackingMode:") 382 MTLHazardTrackingMode hazardTrackingMode(MTLHazardTrackingMode); 383 384 ///A Boolean value indicating whether the GPU is allowed to adjust the texture's contents to improve GPU performance. 385 @selector("allowGPUOptimizedContents") 386 BOOL allowGPUOptimizedContents(); 387 @selector("setAllowGPUOptimizedContents:") 388 BOOL allowGPUOptimizedContents(BOOL); 389 390 ///Options that determine how you can use the texture. 391 @selector("usage") 392 MTLTextureUsage usage(); 393 @selector("setUsage:") 394 MTLTextureUsage usage(MTLTextureUsage); 395 396 ///The pattern you want the GPU to apply to pixels when you read or sample pixels from the texture. 397 @selector("swizzle") 398 MTLTextureSwizzleChannels swizzle(); 399 @selector("setSwizzle:") 400 MTLTextureSwizzleChannels swizzle(MTLTextureSwizzleChannels); 401 402 } 403 404 ///A resource that holds formatted image data. 405 interface MTLTexture 406 { 407 @nogc nothrow: 408 409 mixin ObjcExtend!NSObject; 410 411 ///Copies pixel data into a section of a texture slice. 412 @selector("replaceRegion:mipmapLevel:slice:withBytes:bytesPerRow:bytesPerImage:") 413 void replaceRegion( 414 MTLRegion region, 415 NSUInteger mipmapLevel, 416 NSUInteger slice, 417 const(void)* withBytes, 418 NSUInteger bytesPerRow, 419 NSUInteger bytesPerImage 420 ); 421 422 ///Copies a block of pixels into a section of texture slice 0. 423 @selector("replaceRegion:mipmapLevel:withBytes:bytesPerRow:") 424 void replaceRegion( 425 MTLRegion region, 426 NSUInteger mipmapLevel, 427 const(void)* withBytes, 428 NSUInteger bytesPerRow 429 ); 430 431 ///Copies pixel data from the texture to a buffer in system memory. 432 @selector("getBytes:bytesPerRow:bytesPerImage:fromRegion:mipmapLevel:slice:") 433 void getBytes( 434 void* outPixelBytes, 435 NSUInteger bytesPerRow, 436 NSUInteger bytesPerImage, 437 MTLRegion fromRegion, 438 NSUInteger mipmapLevel, 439 NSUInteger slice 440 ); 441 442 ///Copies pixel data from the first slice of the texture to a buffer in system memory. 443 @selector("getBytes:bytesPerRow:fromRegion:mipmapLevel:") 444 void getBytes( 445 void* outPixelBytes, 446 NSUInteger bytesPerRow, 447 MTLRegion fromRegion, 448 NSUInteger mipmapLevel 449 ); 450 451 ///Creates a new view of the texture, reinterpreting its data using a different pixel format. 452 @selector("newTextureViewWithPixelFormat:") 453 MTLTexture newTextureViewPixelFormat(MTLPixelFormat); 454 455 ///Creates a new view of the texture, reinterpreting a subset of its data using a different type and pixel format. 456 @selector("newTextureViewWithPixelFormat:textureType:levels:slices:") 457 MTLTexture newTextureViewWithPixelFormat( 458 MTLPixelFormat pixelFormat, 459 MTLTextureType textureType, 460 NSRange levelRange, 461 NSRange sliceRange 462 ); 463 ///Creates a new view of the texture, reinterpreting a subset of its data using a different type, pixel format, and swizzle pattern. 464 @selector("newTextureViewWithPixelFormat:textureType:levels:slices:swizzle:") 465 MTLTexture newTextureViewWithPixelFormat( 466 MTLPixelFormat pixelFormat, 467 MTLTextureType textureType, 468 NSRange levelRange, 469 NSRange sliceRange, 470 MTLTextureSwizzleChannels swizzle 471 ); 472 473 ///The dimension and arrangement of the texture image data. 474 @selector("textureType") 475 MTLTextureType textureType(); 476 477 ///The format of pixels in the texture. 478 @selector("pixelFormat") 479 MTLPixelFormat pixelFormat(); 480 481 ///The width of the texture image for the base level mipmap, in pixels. 482 @selector("width") 483 NSUInteger width(); 484 485 ///The height of the texture image for the base level mipmap, in pixels. 486 @selector("height") 487 NSUInteger height(); 488 489 ///The depth of the texture image for the base level mipmap, in pixels. 490 @selector("depth") 491 NSUInteger depth(); 492 493 ///The number of mipmap levels in the texture. 494 @selector("mipmapLevelCount") 495 NSUInteger mipmapLevelCount(); 496 497 ///The number of slices in the texture array. 498 @selector("arrayLength") 499 NSUInteger arrayLength(); 500 501 ///The number of samples in each pixel. 502 @selector("sampleCount") 503 NSUInteger sampleCount(); 504 505 ///A Boolean value that indicates whether the texture can only be used as a render target. 506 @selector("framebufferOnly") 507 BOOL framebufferOnly(); 508 alias isFramebufferOnly = framebufferOnly; 509 510 ///Options that determine how you can use the texture. 511 @selector("usage") 512 MTLTextureUsage usage(); 513 514 ///A Boolean value indicating whether the GPU is allowed to adjust the contents of the texture to improve GPU performance. 515 @selector("allowGPUOptimizedContents") 516 BOOL allowGPUOptimizedContents(); 517 518 ///A Boolean indicating whether this texture can be shared with other processes. 519 @selector("shareable") 520 BOOL shareable(); 521 alias isShareable = shareable; 522 523 ///The pattern that the GPU applies to pixels when you read or sample pixels from the texture. 524 @selector("swizzle") 525 MTLTextureSwizzleChannels swizzle(); 526 527 ///The parent texture that the texture was created from, if any. 528 @selector("parentTexture") 529 MTLTexture parentTexture(); 530 531 ///The base level of the parent texture that the texture was created from, if any. 532 @selector("parentRelativeLevel") 533 NSUInteger parentRelativeLevel(); 534 535 ///The base slice of the parent texture that the texture was created from, if any. 536 @selector("parentRelativeSlice") 537 NSUInteger parentRelativeSlice(); 538 539 ///The source buffer that the texture was created from, if any. 540 @selector("buffer") 541 MTLBuffer buffer(); 542 543 ///The offset in the source buffer where the texture's data comes from. 544 @selector("offset") 545 NSUInteger offset(); 546 547 ///The number of bytes in each row of the texture’s source buffer, if applicable. 548 @selector("bufferBytesPerRow") 549 NSUInteger bufferBytesPerRow(); 550 551 ///Creates a new texture handle from a shareable texture. 552 //MTLSharedTextureHandle newSharedTextureHandle(); 553 554 ///Creates a remote texture view for another GPU in the same peer group. 555 @selector("newRemoteTextureViewForDevice:") 556 MTLTexture newRemoteTextureViewForDevice(MTLDevice); 557 558 ///The texture on another GPU that the texture was created from, if any. 559 @selector("remoteStorageTexture") 560 MTLTexture remoteStorageTexture(); 561 562 ///A Boolean value that indicates whether this is a sparse texture. 563 @selector("isSparse") 564 BOOL isSparse(); 565 566 ///The index of the first mipmap in the tail. 567 @selector("firstMipmapInTail") 568 NSUInteger firstMipmapInTail(); 569 570 ///The size of the sparse texture tail, in bytes. 571 @selector("tailSizeInBytes") 572 NSUInteger tailSizeInBytes(); 573 574 @selector("compressionType") 575 MTLTextureCompressionType compressionType(); 576 577 // MTLResourceID gpuResourceID(); 578 579 }