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