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