MTLBuffer.hpp
1 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 2 // 3 // Metal/MTLBuffer.hpp 4 // 5 // Copyright 2020-2024 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 at 10 // 11 // http://www.apache.org/licenses/LICENSE-2.0 12 // 13 // Unless required by applicable law or agreed to in writing, software 14 // 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 and 17 // limitations under the License. 18 // 19 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 20 21 #pragma once 22 23 #include "MTLDefines.hpp" 24 #include "MTLHeaderBridge.hpp" 25 #include "MTLPrivate.hpp" 26 27 #include <Foundation/Foundation.hpp> 28 29 #include "MTLResource.hpp" 30 31 namespace MTL 32 { 33 class Buffer : public NS::Referencing<Buffer, Resource> 34 { 35 public: 36 NS::UInteger length() const; 37 38 void* contents(); 39 40 void didModifyRange(NS::Range range); 41 42 class Texture* newTexture(const class TextureDescriptor* descriptor, NS::UInteger offset, NS::UInteger bytesPerRow); 43 44 void addDebugMarker(const NS::String* marker, NS::Range range); 45 46 void removeAllDebugMarkers(); 47 48 class Buffer* remoteStorageBuffer() const; 49 50 class Buffer* newRemoteBufferViewForDevice(const class Device* device); 51 52 uint64_t gpuAddress() const; 53 }; 54 55 } 56 57 // property: length 58 _MTL_INLINE NS::UInteger MTL::Buffer::length() const 59 { 60 return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(length)); 61 } 62 63 // method: contents 64 _MTL_INLINE void* MTL::Buffer::contents() 65 { 66 return Object::sendMessage<void*>(this, _MTL_PRIVATE_SEL(contents)); 67 } 68 69 // method: didModifyRange: 70 _MTL_INLINE void MTL::Buffer::didModifyRange(NS::Range range) 71 { 72 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(didModifyRange_), range); 73 } 74 75 // method: newTextureWithDescriptor:offset:bytesPerRow: 76 _MTL_INLINE MTL::Texture* MTL::Buffer::newTexture(const MTL::TextureDescriptor* descriptor, NS::UInteger offset, NS::UInteger bytesPerRow) 77 { 78 return Object::sendMessage<MTL::Texture*>(this, _MTL_PRIVATE_SEL(newTextureWithDescriptor_offset_bytesPerRow_), descriptor, offset, bytesPerRow); 79 } 80 81 // method: addDebugMarker:range: 82 _MTL_INLINE void MTL::Buffer::addDebugMarker(const NS::String* marker, NS::Range range) 83 { 84 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(addDebugMarker_range_), marker, range); 85 } 86 87 // method: removeAllDebugMarkers 88 _MTL_INLINE void MTL::Buffer::removeAllDebugMarkers() 89 { 90 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(removeAllDebugMarkers)); 91 } 92 93 // property: remoteStorageBuffer 94 _MTL_INLINE MTL::Buffer* MTL::Buffer::remoteStorageBuffer() const 95 { 96 return Object::sendMessage<MTL::Buffer*>(this, _MTL_PRIVATE_SEL(remoteStorageBuffer)); 97 } 98 99 // method: newRemoteBufferViewForDevice: 100 _MTL_INLINE MTL::Buffer* MTL::Buffer::newRemoteBufferViewForDevice(const MTL::Device* device) 101 { 102 return Object::sendMessage<MTL::Buffer*>(this, _MTL_PRIVATE_SEL(newRemoteBufferViewForDevice_), device); 103 } 104 105 // property: gpuAddress 106 _MTL_INLINE uint64_t MTL::Buffer::gpuAddress() const 107 { 108 return Object::sendMessage<uint64_t>(this, _MTL_PRIVATE_SEL(gpuAddress)); 109 }