SPB Git

spb/forge Public MIT

Forge — LLM training from scratch in pure C++20 + Metal on Apple Silicon.

C++ 61.2% C 23% Python 7.6% TeX 7.2% CMake 1.1%
27.4 KB · 804 lines cpp
Raw Blame History
1//-------------------------------------------------------------------------------------------------------------------------------------------------------------2//3// Metal/MTLTexture.hpp4//5// Copyright 2020-2025 Apple Inc.6//7// Licensed under the Apache License, Version 2.0 (the "License");8// you may not use this file except in compliance with the License.9// You may obtain a copy of the License at10//11//     http://www.apache.org/licenses/LICENSE-2.012//13// Unless required by applicable law or agreed to in writing, software14// distributed under the License is distributed on an "AS IS" BASIS,15// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.16// See the License for the specific language governing permissions and17// limitations under the License.18//19//-------------------------------------------------------------------------------------------------------------------------------------------------------------2021#pragma once2223#include "../Foundation/Foundation.hpp"24#include "MTLDefines.hpp"25#include "MTLHeaderBridge.hpp"26#include "MTLPixelFormat.hpp"27#include "MTLPrivate.hpp"28#include "MTLResource.hpp"29#include "MTLTypes.hpp"30#include <IOSurface/IOSurfaceRef.h>3132namespace MTL33{34class Buffer;35class Device;36class Resource;37class SharedTextureHandle;38class Texture;39class TextureDescriptor;40class TextureViewDescriptor;41}4243namespace MTL44{45_MTL_ENUM(NS::UInteger, TextureType) {46    TextureType1D = 0,47    TextureType1DArray = 1,48    TextureType2D = 2,49    TextureType2DArray = 3,50    TextureType2DMultisample = 4,51    TextureTypeCube = 5,52    TextureTypeCubeArray = 6,53    TextureType3D = 7,54    TextureType2DMultisampleArray = 8,55    TextureTypeTextureBuffer = 9,56};5758_MTL_ENUM(uint8_t, TextureSwizzle) {59    TextureSwizzleZero = 0,60    TextureSwizzleOne = 1,61    TextureSwizzleRed = 2,62    TextureSwizzleGreen = 3,63    TextureSwizzleBlue = 4,64    TextureSwizzleAlpha = 5,65};6667_MTL_ENUM(NS::Integer, TextureCompressionType) {68    TextureCompressionTypeLossless = 0,69    TextureCompressionTypeLossy = 1,70};7172_MTL_OPTIONS(NS::UInteger, TextureUsage) {73    TextureUsageUnknown = 0,74    TextureUsageShaderRead = 1,75    TextureUsageShaderWrite = 1 << 1,76    TextureUsageRenderTarget = 1 << 2,77    TextureUsagePixelFormatView = 1 << 4,78    TextureUsageShaderAtomic = 1 << 5,79};8081struct TextureSwizzleChannels82{8384    TextureSwizzleChannels(MTL::TextureSwizzle r, MTL::TextureSwizzle g, MTL::TextureSwizzle b, MTL::TextureSwizzle a);8586    TextureSwizzleChannels();8788    static TextureSwizzleChannels Default();8990    static TextureSwizzleChannels Make(MTL::TextureSwizzle r, MTL::TextureSwizzle g, MTL::TextureSwizzle b, MTL::TextureSwizzle a);9192    MTL::TextureSwizzle           red;93    MTL::TextureSwizzle           green;94    MTL::TextureSwizzle           blue;95    MTL::TextureSwizzle           alpha;96} _MTL_PACKED;9798class SharedTextureHandle : public NS::SecureCoding<SharedTextureHandle>99{100public:101    static SharedTextureHandle* alloc();102103    Device*                     device() const;104105    SharedTextureHandle*        init();106107    NS::String*                 label() const;108};109class TextureDescriptor : public NS::Copying<TextureDescriptor>110{111public:112    static TextureDescriptor* alloc();113114    bool                      allowGPUOptimizedContents() const;115116    NS::UInteger              arrayLength() const;117118    TextureCompressionType    compressionType() const;119120    CPUCacheMode              cpuCacheMode() const;121122    NS::UInteger              depth() const;123124    HazardTrackingMode        hazardTrackingMode() const;125126    NS::UInteger              height() const;127128    TextureDescriptor*        init();129130    NS::UInteger              mipmapLevelCount() const;131132    PixelFormat               pixelFormat() const;133134    SparsePageSize            placementSparsePageSize() const;135136    ResourceOptions           resourceOptions() const;137138    NS::UInteger              sampleCount() const;139140    void                      setAllowGPUOptimizedContents(bool allowGPUOptimizedContents);141142    void                      setArrayLength(NS::UInteger arrayLength);143144    void                      setCompressionType(MTL::TextureCompressionType compressionType);145146    void                      setCpuCacheMode(MTL::CPUCacheMode cpuCacheMode);147148    void                      setDepth(NS::UInteger depth);149150    void                      setHazardTrackingMode(MTL::HazardTrackingMode hazardTrackingMode);151152    void                      setHeight(NS::UInteger height);153154    void                      setMipmapLevelCount(NS::UInteger mipmapLevelCount);155156    void                      setPixelFormat(MTL::PixelFormat pixelFormat);157158    void                      setPlacementSparsePageSize(MTL::SparsePageSize placementSparsePageSize);159160    void                      setResourceOptions(MTL::ResourceOptions resourceOptions);161162    void                      setSampleCount(NS::UInteger sampleCount);163164    void                      setStorageMode(MTL::StorageMode storageMode);165166    void                      setSwizzle(MTL::TextureSwizzleChannels swizzle);167168    void                      setTextureType(MTL::TextureType textureType);169170    void                      setUsage(MTL::TextureUsage usage);171172    void                      setWidth(NS::UInteger width);173174    StorageMode               storageMode() const;175176    TextureSwizzleChannels    swizzle() const;177178    static TextureDescriptor* texture2DDescriptor(MTL::PixelFormat pixelFormat, NS::UInteger width, NS::UInteger height, bool mipmapped);179180    static TextureDescriptor* textureBufferDescriptor(MTL::PixelFormat pixelFormat, NS::UInteger width, MTL::ResourceOptions resourceOptions, MTL::TextureUsage usage);181182    static TextureDescriptor* textureCubeDescriptor(MTL::PixelFormat pixelFormat, NS::UInteger size, bool mipmapped);183184    TextureType               textureType() const;185186    TextureUsage              usage() const;187188    NS::UInteger              width() const;189};190class TextureViewDescriptor : public NS::Copying<TextureViewDescriptor>191{192public:193    static TextureViewDescriptor* alloc();194195    TextureViewDescriptor*        init();196197    NS::Range                     levelRange() const;198199    PixelFormat                   pixelFormat() const;200201    void                          setLevelRange(NS::Range levelRange);202203    void                          setPixelFormat(MTL::PixelFormat pixelFormat);204205    void                          setSliceRange(NS::Range sliceRange);206207    void                          setSwizzle(MTL::TextureSwizzleChannels swizzle);208209    void                          setTextureType(MTL::TextureType textureType);210211    NS::Range                     sliceRange() const;212213    TextureSwizzleChannels        swizzle() const;214215    TextureType                   textureType() const;216};217class Texture : public NS::Referencing<Texture, Resource>218{219public:220    bool                   allowGPUOptimizedContents() const;221222    NS::UInteger           arrayLength() const;223224    Buffer*                buffer() const;225    NS::UInteger           bufferBytesPerRow() const;226227    NS::UInteger           bufferOffset() const;228229    TextureCompressionType compressionType() const;230231    NS::UInteger           depth() const;232233    NS::UInteger           firstMipmapInTail() const;234235    [[deprecated("please use isFramebufferOnly instead")]]236    bool                 framebufferOnly() const;237238    void                 getBytes(void* pixelBytes, NS::UInteger bytesPerRow, NS::UInteger bytesPerImage, MTL::Region region, NS::UInteger level, NS::UInteger slice);239    void                 getBytes(void* pixelBytes, NS::UInteger bytesPerRow, MTL::Region region, NS::UInteger level);240241    ResourceID           gpuResourceID() const;242243    NS::UInteger         height() const;244245    IOSurfaceRef         iosurface() const;246    NS::UInteger         iosurfacePlane() const;247248    bool                 isFramebufferOnly() const;249250    bool                 isShareable() const;251252    bool                 isSparse() const;253254    NS::UInteger         mipmapLevelCount() const;255256    Texture*             newRemoteTextureViewForDevice(const MTL::Device* device);257258    SharedTextureHandle* newSharedTextureHandle();259260    Texture*             newTextureView(MTL::PixelFormat pixelFormat);261    Texture*             newTextureView(MTL::PixelFormat pixelFormat, MTL::TextureType textureType, NS::Range levelRange, NS::Range sliceRange);262    Texture*             newTextureView(const MTL::TextureViewDescriptor* descriptor);263    Texture*             newTextureView(MTL::PixelFormat pixelFormat, MTL::TextureType textureType, NS::Range levelRange, NS::Range sliceRange, MTL::TextureSwizzleChannels swizzle);264265    NS::UInteger         parentRelativeLevel() const;266267    NS::UInteger         parentRelativeSlice() const;268269    Texture*             parentTexture() const;270271    PixelFormat          pixelFormat() const;272273    Texture*             remoteStorageTexture() const;274275    void                 replaceRegion(MTL::Region region, NS::UInteger level, NS::UInteger slice, const void* pixelBytes, NS::UInteger bytesPerRow, NS::UInteger bytesPerImage);276    void                 replaceRegion(MTL::Region region, NS::UInteger level, const void* pixelBytes, NS::UInteger bytesPerRow);277278    Resource*            rootResource() const;279280    NS::UInteger         sampleCount() const;281282    [[deprecated("please use isShareable instead")]]283    bool                   shareable() const;284285    TextureSparseTier      sparseTextureTier() const;286287    TextureSwizzleChannels swizzle() const;288289    NS::UInteger           tailSizeInBytes() const;290291    TextureType            textureType() const;292293    TextureUsage           usage() const;294295    NS::UInteger           width() const;296};297298}299_MTL_INLINE MTL::TextureSwizzleChannels::TextureSwizzleChannels(MTL::TextureSwizzle r, MTL::TextureSwizzle g, MTL::TextureSwizzle b, MTL::TextureSwizzle a)300    : red(r)301    , green(g)302    , blue(b)303    , alpha(a)304{305}306307_MTL_INLINE MTL::TextureSwizzleChannels::TextureSwizzleChannels()308    : red(MTL::TextureSwizzleRed)309    , green(MTL::TextureSwizzleGreen)310    , blue(MTL::TextureSwizzleBlue)311    , alpha(MTL::TextureSwizzleAlpha)312{313}314315_MTL_INLINE MTL::TextureSwizzleChannels MTL::TextureSwizzleChannels::Default()316{317    return MTL::TextureSwizzleChannels();318}319320_MTL_INLINE MTL::TextureSwizzleChannels MTL::TextureSwizzleChannels::Make(MTL::TextureSwizzle r, MTL::TextureSwizzle g, MTL::TextureSwizzle b, MTL::TextureSwizzle a)321{322    return TextureSwizzleChannels(r, g, b, a);323}324325_MTL_INLINE MTL::SharedTextureHandle* MTL::SharedTextureHandle::alloc()326{327    return NS::Object::alloc<MTL::SharedTextureHandle>(_MTL_PRIVATE_CLS(MTLSharedTextureHandle));328}329330_MTL_INLINE MTL::Device* MTL::SharedTextureHandle::device() const331{332    return Object::sendMessage<MTL::Device*>(this, _MTL_PRIVATE_SEL(device));333}334335_MTL_INLINE MTL::SharedTextureHandle* MTL::SharedTextureHandle::init()336{337    return NS::Object::init<MTL::SharedTextureHandle>();338}339340_MTL_INLINE NS::String* MTL::SharedTextureHandle::label() const341{342    return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(label));343}344345_MTL_INLINE MTL::TextureDescriptor* MTL::TextureDescriptor::alloc()346{347    return NS::Object::alloc<MTL::TextureDescriptor>(_MTL_PRIVATE_CLS(MTLTextureDescriptor));348}349350_MTL_INLINE bool MTL::TextureDescriptor::allowGPUOptimizedContents() const351{352    return Object::sendMessage<bool>(this, _MTL_PRIVATE_SEL(allowGPUOptimizedContents));353}354355_MTL_INLINE NS::UInteger MTL::TextureDescriptor::arrayLength() const356{357    return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(arrayLength));358}359360_MTL_INLINE MTL::TextureCompressionType MTL::TextureDescriptor::compressionType() const361{362    return Object::sendMessage<MTL::TextureCompressionType>(this, _MTL_PRIVATE_SEL(compressionType));363}364365_MTL_INLINE MTL::CPUCacheMode MTL::TextureDescriptor::cpuCacheMode() const366{367    return Object::sendMessage<MTL::CPUCacheMode>(this, _MTL_PRIVATE_SEL(cpuCacheMode));368}369370_MTL_INLINE NS::UInteger MTL::TextureDescriptor::depth() const371{372    return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(depth));373}374375_MTL_INLINE MTL::HazardTrackingMode MTL::TextureDescriptor::hazardTrackingMode() const376{377    return Object::sendMessage<MTL::HazardTrackingMode>(this, _MTL_PRIVATE_SEL(hazardTrackingMode));378}379380_MTL_INLINE NS::UInteger MTL::TextureDescriptor::height() const381{382    return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(height));383}384385_MTL_INLINE MTL::TextureDescriptor* MTL::TextureDescriptor::init()386{387    return NS::Object::init<MTL::TextureDescriptor>();388}389390_MTL_INLINE NS::UInteger MTL::TextureDescriptor::mipmapLevelCount() const391{392    return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(mipmapLevelCount));393}394395_MTL_INLINE MTL::PixelFormat MTL::TextureDescriptor::pixelFormat() const396{397    return Object::sendMessage<MTL::PixelFormat>(this, _MTL_PRIVATE_SEL(pixelFormat));398}399400_MTL_INLINE MTL::SparsePageSize MTL::TextureDescriptor::placementSparsePageSize() const401{402    return Object::sendMessage<MTL::SparsePageSize>(this, _MTL_PRIVATE_SEL(placementSparsePageSize));403}404405_MTL_INLINE MTL::ResourceOptions MTL::TextureDescriptor::resourceOptions() const406{407    return Object::sendMessage<MTL::ResourceOptions>(this, _MTL_PRIVATE_SEL(resourceOptions));408}409410_MTL_INLINE NS::UInteger MTL::TextureDescriptor::sampleCount() const411{412    return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(sampleCount));413}414415_MTL_INLINE void MTL::TextureDescriptor::setAllowGPUOptimizedContents(bool allowGPUOptimizedContents)416{417    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setAllowGPUOptimizedContents_), allowGPUOptimizedContents);418}419420_MTL_INLINE void MTL::TextureDescriptor::setArrayLength(NS::UInteger arrayLength)421{422    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setArrayLength_), arrayLength);423}424425_MTL_INLINE void MTL::TextureDescriptor::setCompressionType(MTL::TextureCompressionType compressionType)426{427    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setCompressionType_), compressionType);428}429430_MTL_INLINE void MTL::TextureDescriptor::setCpuCacheMode(MTL::CPUCacheMode cpuCacheMode)431{432    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setCpuCacheMode_), cpuCacheMode);433}434435_MTL_INLINE void MTL::TextureDescriptor::setDepth(NS::UInteger depth)436{437    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setDepth_), depth);438}439440_MTL_INLINE void MTL::TextureDescriptor::setHazardTrackingMode(MTL::HazardTrackingMode hazardTrackingMode)441{442    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setHazardTrackingMode_), hazardTrackingMode);443}444445_MTL_INLINE void MTL::TextureDescriptor::setHeight(NS::UInteger height)446{447    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setHeight_), height);448}449450_MTL_INLINE void MTL::TextureDescriptor::setMipmapLevelCount(NS::UInteger mipmapLevelCount)451{452    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setMipmapLevelCount_), mipmapLevelCount);453}454455_MTL_INLINE void MTL::TextureDescriptor::setPixelFormat(MTL::PixelFormat pixelFormat)456{457    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setPixelFormat_), pixelFormat);458}459460_MTL_INLINE void MTL::TextureDescriptor::setPlacementSparsePageSize(MTL::SparsePageSize placementSparsePageSize)461{462    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setPlacementSparsePageSize_), placementSparsePageSize);463}464465_MTL_INLINE void MTL::TextureDescriptor::setResourceOptions(MTL::ResourceOptions resourceOptions)466{467    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setResourceOptions_), resourceOptions);468}469470_MTL_INLINE void MTL::TextureDescriptor::setSampleCount(NS::UInteger sampleCount)471{472    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setSampleCount_), sampleCount);473}474475_MTL_INLINE void MTL::TextureDescriptor::setStorageMode(MTL::StorageMode storageMode)476{477    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setStorageMode_), storageMode);478}479480_MTL_INLINE void MTL::TextureDescriptor::setSwizzle(MTL::TextureSwizzleChannels swizzle)481{482    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setSwizzle_), swizzle);483}484485_MTL_INLINE void MTL::TextureDescriptor::setTextureType(MTL::TextureType textureType)486{487    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setTextureType_), textureType);488}489490_MTL_INLINE void MTL::TextureDescriptor::setUsage(MTL::TextureUsage usage)491{492    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setUsage_), usage);493}494495_MTL_INLINE void MTL::TextureDescriptor::setWidth(NS::UInteger width)496{497    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setWidth_), width);498}499500_MTL_INLINE MTL::StorageMode MTL::TextureDescriptor::storageMode() const501{502    return Object::sendMessage<MTL::StorageMode>(this, _MTL_PRIVATE_SEL(storageMode));503}504505_MTL_INLINE MTL::TextureSwizzleChannels MTL::TextureDescriptor::swizzle() const506{507    return Object::sendMessage<MTL::TextureSwizzleChannels>(this, _MTL_PRIVATE_SEL(swizzle));508}509510_MTL_INLINE MTL::TextureDescriptor* MTL::TextureDescriptor::texture2DDescriptor(MTL::PixelFormat pixelFormat, NS::UInteger width, NS::UInteger height, bool mipmapped)511{512    return Object::sendMessage<MTL::TextureDescriptor*>(_MTL_PRIVATE_CLS(MTLTextureDescriptor), _MTL_PRIVATE_SEL(texture2DDescriptorWithPixelFormat_width_height_mipmapped_), pixelFormat, width, height, mipmapped);513}514515_MTL_INLINE MTL::TextureDescriptor* MTL::TextureDescriptor::textureBufferDescriptor(MTL::PixelFormat pixelFormat, NS::UInteger width, MTL::ResourceOptions resourceOptions, MTL::TextureUsage usage)516{517    return Object::sendMessage<MTL::TextureDescriptor*>(_MTL_PRIVATE_CLS(MTLTextureDescriptor), _MTL_PRIVATE_SEL(textureBufferDescriptorWithPixelFormat_width_resourceOptions_usage_), pixelFormat, width, resourceOptions, usage);518}519520_MTL_INLINE MTL::TextureDescriptor* MTL::TextureDescriptor::textureCubeDescriptor(MTL::PixelFormat pixelFormat, NS::UInteger size, bool mipmapped)521{522    return Object::sendMessage<MTL::TextureDescriptor*>(_MTL_PRIVATE_CLS(MTLTextureDescriptor), _MTL_PRIVATE_SEL(textureCubeDescriptorWithPixelFormat_size_mipmapped_), pixelFormat, size, mipmapped);523}524525_MTL_INLINE MTL::TextureType MTL::TextureDescriptor::textureType() const526{527    return Object::sendMessage<MTL::TextureType>(this, _MTL_PRIVATE_SEL(textureType));528}529530_MTL_INLINE MTL::TextureUsage MTL::TextureDescriptor::usage() const531{532    return Object::sendMessage<MTL::TextureUsage>(this, _MTL_PRIVATE_SEL(usage));533}534535_MTL_INLINE NS::UInteger MTL::TextureDescriptor::width() const536{537    return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(width));538}539540_MTL_INLINE MTL::TextureViewDescriptor* MTL::TextureViewDescriptor::alloc()541{542    return NS::Object::alloc<MTL::TextureViewDescriptor>(_MTL_PRIVATE_CLS(MTLTextureViewDescriptor));543}544545_MTL_INLINE MTL::TextureViewDescriptor* MTL::TextureViewDescriptor::init()546{547    return NS::Object::init<MTL::TextureViewDescriptor>();548}549550_MTL_INLINE NS::Range MTL::TextureViewDescriptor::levelRange() const551{552    return Object::sendMessage<NS::Range>(this, _MTL_PRIVATE_SEL(levelRange));553}554555_MTL_INLINE MTL::PixelFormat MTL::TextureViewDescriptor::pixelFormat() const556{557    return Object::sendMessage<MTL::PixelFormat>(this, _MTL_PRIVATE_SEL(pixelFormat));558}559560_MTL_INLINE void MTL::TextureViewDescriptor::setLevelRange(NS::Range levelRange)561{562    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setLevelRange_), levelRange);563}564565_MTL_INLINE void MTL::TextureViewDescriptor::setPixelFormat(MTL::PixelFormat pixelFormat)566{567    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setPixelFormat_), pixelFormat);568}569570_MTL_INLINE void MTL::TextureViewDescriptor::setSliceRange(NS::Range sliceRange)571{572    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setSliceRange_), sliceRange);573}574575_MTL_INLINE void MTL::TextureViewDescriptor::setSwizzle(MTL::TextureSwizzleChannels swizzle)576{577    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setSwizzle_), swizzle);578}579580_MTL_INLINE void MTL::TextureViewDescriptor::setTextureType(MTL::TextureType textureType)581{582    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setTextureType_), textureType);583}584585_MTL_INLINE NS::Range MTL::TextureViewDescriptor::sliceRange() const586{587    return Object::sendMessage<NS::Range>(this, _MTL_PRIVATE_SEL(sliceRange));588}589590_MTL_INLINE MTL::TextureSwizzleChannels MTL::TextureViewDescriptor::swizzle() const591{592    return Object::sendMessage<MTL::TextureSwizzleChannels>(this, _MTL_PRIVATE_SEL(swizzle));593}594595_MTL_INLINE MTL::TextureType MTL::TextureViewDescriptor::textureType() const596{597    return Object::sendMessage<MTL::TextureType>(this, _MTL_PRIVATE_SEL(textureType));598}599600_MTL_INLINE bool MTL::Texture::allowGPUOptimizedContents() const601{602    return Object::sendMessage<bool>(this, _MTL_PRIVATE_SEL(allowGPUOptimizedContents));603}604605_MTL_INLINE NS::UInteger MTL::Texture::arrayLength() const606{607    return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(arrayLength));608}609610_MTL_INLINE MTL::Buffer* MTL::Texture::buffer() const611{612    return Object::sendMessage<MTL::Buffer*>(this, _MTL_PRIVATE_SEL(buffer));613}614615_MTL_INLINE NS::UInteger MTL::Texture::bufferBytesPerRow() const616{617    return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(bufferBytesPerRow));618}619620_MTL_INLINE NS::UInteger MTL::Texture::bufferOffset() const621{622    return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(bufferOffset));623}624625_MTL_INLINE MTL::TextureCompressionType MTL::Texture::compressionType() const626{627    return Object::sendMessage<MTL::TextureCompressionType>(this, _MTL_PRIVATE_SEL(compressionType));628}629630_MTL_INLINE NS::UInteger MTL::Texture::depth() const631{632    return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(depth));633}634635_MTL_INLINE NS::UInteger MTL::Texture::firstMipmapInTail() const636{637    return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(firstMipmapInTail));638}639640_MTL_INLINE bool MTL::Texture::framebufferOnly() const641{642    return Object::sendMessage<bool>(this, _MTL_PRIVATE_SEL(isFramebufferOnly));643}644645_MTL_INLINE void MTL::Texture::getBytes(void* pixelBytes, NS::UInteger bytesPerRow, NS::UInteger bytesPerImage, MTL::Region region, NS::UInteger level, NS::UInteger slice)646{647    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(getBytes_bytesPerRow_bytesPerImage_fromRegion_mipmapLevel_slice_), pixelBytes, bytesPerRow, bytesPerImage, region, level, slice);648}649650_MTL_INLINE void MTL::Texture::getBytes(void* pixelBytes, NS::UInteger bytesPerRow, MTL::Region region, NS::UInteger level)651{652    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(getBytes_bytesPerRow_fromRegion_mipmapLevel_), pixelBytes, bytesPerRow, region, level);653}654655_MTL_INLINE MTL::ResourceID MTL::Texture::gpuResourceID() const656{657    return Object::sendMessage<MTL::ResourceID>(this, _MTL_PRIVATE_SEL(gpuResourceID));658}659660_MTL_INLINE NS::UInteger MTL::Texture::height() const661{662    return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(height));663}664665_MTL_INLINE IOSurfaceRef MTL::Texture::iosurface() const666{667    return Object::sendMessage<IOSurfaceRef>(this, _MTL_PRIVATE_SEL(iosurface));668}669670_MTL_INLINE NS::UInteger MTL::Texture::iosurfacePlane() const671{672    return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(iosurfacePlane));673}674675_MTL_INLINE bool MTL::Texture::isFramebufferOnly() const676{677    return Object::sendMessage<bool>(this, _MTL_PRIVATE_SEL(isFramebufferOnly));678}679680_MTL_INLINE bool MTL::Texture::isShareable() const681{682    return Object::sendMessage<bool>(this, _MTL_PRIVATE_SEL(isShareable));683}684685_MTL_INLINE bool MTL::Texture::isSparse() const686{687    return Object::sendMessage<bool>(this, _MTL_PRIVATE_SEL(isSparse));688}689690_MTL_INLINE NS::UInteger MTL::Texture::mipmapLevelCount() const691{692    return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(mipmapLevelCount));693}694695_MTL_INLINE MTL::Texture* MTL::Texture::newRemoteTextureViewForDevice(const MTL::Device* device)696{697    return Object::sendMessage<MTL::Texture*>(this, _MTL_PRIVATE_SEL(newRemoteTextureViewForDevice_), device);698}699700_MTL_INLINE MTL::SharedTextureHandle* MTL::Texture::newSharedTextureHandle()701{702    return Object::sendMessage<MTL::SharedTextureHandle*>(this, _MTL_PRIVATE_SEL(newSharedTextureHandle));703}704705_MTL_INLINE MTL::Texture* MTL::Texture::newTextureView(MTL::PixelFormat pixelFormat)706{707    return Object::sendMessage<MTL::Texture*>(this, _MTL_PRIVATE_SEL(newTextureViewWithPixelFormat_), pixelFormat);708}709710_MTL_INLINE MTL::Texture* MTL::Texture::newTextureView(MTL::PixelFormat pixelFormat, MTL::TextureType textureType, NS::Range levelRange, NS::Range sliceRange)711{712    return Object::sendMessage<MTL::Texture*>(this, _MTL_PRIVATE_SEL(newTextureViewWithPixelFormat_textureType_levels_slices_), pixelFormat, textureType, levelRange, sliceRange);713}714715_MTL_INLINE MTL::Texture* MTL::Texture::newTextureView(const MTL::TextureViewDescriptor* descriptor)716{717    return Object::sendMessage<MTL::Texture*>(this, _MTL_PRIVATE_SEL(newTextureViewWithDescriptor_), descriptor);718}719720_MTL_INLINE MTL::Texture* MTL::Texture::newTextureView(MTL::PixelFormat pixelFormat, MTL::TextureType textureType, NS::Range levelRange, NS::Range sliceRange, MTL::TextureSwizzleChannels swizzle)721{722    return Object::sendMessage<MTL::Texture*>(this, _MTL_PRIVATE_SEL(newTextureViewWithPixelFormat_textureType_levels_slices_swizzle_), pixelFormat, textureType, levelRange, sliceRange, swizzle);723}724725_MTL_INLINE NS::UInteger MTL::Texture::parentRelativeLevel() const726{727    return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(parentRelativeLevel));728}729730_MTL_INLINE NS::UInteger MTL::Texture::parentRelativeSlice() const731{732    return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(parentRelativeSlice));733}734735_MTL_INLINE MTL::Texture* MTL::Texture::parentTexture() const736{737    return Object::sendMessage<MTL::Texture*>(this, _MTL_PRIVATE_SEL(parentTexture));738}739740_MTL_INLINE MTL::PixelFormat MTL::Texture::pixelFormat() const741{742    return Object::sendMessage<MTL::PixelFormat>(this, _MTL_PRIVATE_SEL(pixelFormat));743}744745_MTL_INLINE MTL::Texture* MTL::Texture::remoteStorageTexture() const746{747    return Object::sendMessage<MTL::Texture*>(this, _MTL_PRIVATE_SEL(remoteStorageTexture));748}749750_MTL_INLINE void MTL::Texture::replaceRegion(MTL::Region region, NS::UInteger level, NS::UInteger slice, const void* pixelBytes, NS::UInteger bytesPerRow, NS::UInteger bytesPerImage)751{752    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(replaceRegion_mipmapLevel_slice_withBytes_bytesPerRow_bytesPerImage_), region, level, slice, pixelBytes, bytesPerRow, bytesPerImage);753}754755_MTL_INLINE void MTL::Texture::replaceRegion(MTL::Region region, NS::UInteger level, const void* pixelBytes, NS::UInteger bytesPerRow)756{757    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(replaceRegion_mipmapLevel_withBytes_bytesPerRow_), region, level, pixelBytes, bytesPerRow);758}759760_MTL_INLINE MTL::Resource* MTL::Texture::rootResource() const761{762    return Object::sendMessage<MTL::Resource*>(this, _MTL_PRIVATE_SEL(rootResource));763}764765_MTL_INLINE NS::UInteger MTL::Texture::sampleCount() const766{767    return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(sampleCount));768}769770_MTL_INLINE bool MTL::Texture::shareable() const771{772    return Object::sendMessage<bool>(this, _MTL_PRIVATE_SEL(isShareable));773}774775_MTL_INLINE MTL::TextureSparseTier MTL::Texture::sparseTextureTier() const776{777    return Object::sendMessage<MTL::TextureSparseTier>(this, _MTL_PRIVATE_SEL(sparseTextureTier));778}779780_MTL_INLINE MTL::TextureSwizzleChannels MTL::Texture::swizzle() const781{782    return Object::sendMessage<MTL::TextureSwizzleChannels>(this, _MTL_PRIVATE_SEL(swizzle));783}784785_MTL_INLINE NS::UInteger MTL::Texture::tailSizeInBytes() const786{787    return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(tailSizeInBytes));788}789790_MTL_INLINE MTL::TextureType MTL::Texture::textureType() const791{792    return Object::sendMessage<MTL::TextureType>(this, _MTL_PRIVATE_SEL(textureType));793}794795_MTL_INLINE MTL::TextureUsage MTL::Texture::usage() const796{797    return Object::sendMessage<MTL::TextureUsage>(this, _MTL_PRIVATE_SEL(usage));798}799800_MTL_INLINE NS::UInteger MTL::Texture::width() const801{802    return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(width));803}804