MTLTypes.hpp
1 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 2 // 3 // Metal/MTLTypes.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 "MTLTypes.hpp" 30 31 namespace MTL 32 { 33 struct Origin 34 { 35 Origin() = default; 36 37 Origin(NS::UInteger x, NS::UInteger y, NS::UInteger z); 38 39 static Origin Make(NS::UInteger x, NS::UInteger y, NS::UInteger z); 40 41 NS::UInteger x; 42 NS::UInteger y; 43 NS::UInteger z; 44 } _MTL_PACKED; 45 46 struct Size 47 { 48 Size() = default; 49 50 Size(NS::UInteger width, NS::UInteger height, NS::UInteger depth); 51 52 static Size Make(NS::UInteger width, NS::UInteger height, NS::UInteger depth); 53 54 NS::UInteger width; 55 NS::UInteger height; 56 NS::UInteger depth; 57 } _MTL_PACKED; 58 59 struct Region 60 { 61 Region() = default; 62 63 Region(NS::UInteger x, NS::UInteger width); 64 65 Region(NS::UInteger x, NS::UInteger y, NS::UInteger width, NS::UInteger height); 66 67 Region(NS::UInteger x, NS::UInteger y, NS::UInteger z, NS::UInteger width, NS::UInteger height, NS::UInteger depth); 68 69 static Region Make1D(NS::UInteger x, NS::UInteger width); 70 71 static Region Make2D(NS::UInteger x, NS::UInteger y, NS::UInteger width, NS::UInteger height); 72 73 static Region Make3D(NS::UInteger x, NS::UInteger y, NS::UInteger z, NS::UInteger width, NS::UInteger height, NS::UInteger depth); 74 75 MTL::Origin origin; 76 MTL::Size size; 77 } _MTL_PACKED; 78 79 struct SamplePosition; 80 81 using Coordinate2D = SamplePosition; 82 83 struct SamplePosition 84 { 85 SamplePosition() = default; 86 87 SamplePosition(float _x, float _y); 88 89 static SamplePosition Make(float x, float y); 90 91 float x; 92 float y; 93 } _MTL_PACKED; 94 95 struct ResourceID 96 { 97 uint64_t _impl; 98 } _MTL_PACKED; 99 100 } 101 102 _MTL_INLINE MTL::Origin::Origin(NS::UInteger _x, NS::UInteger _y, NS::UInteger _z) 103 : x(_x) 104 , y(_y) 105 , z(_z) 106 { 107 } 108 109 _MTL_INLINE MTL::Origin MTL::Origin::Make(NS::UInteger x, NS::UInteger y, NS::UInteger z) 110 { 111 return Origin(x, y, z); 112 } 113 114 _MTL_INLINE MTL::Size::Size(NS::UInteger _width, NS::UInteger _height, NS::UInteger _depth) 115 : width(_width) 116 , height(_height) 117 , depth(_depth) 118 { 119 } 120 121 _MTL_INLINE MTL::Size MTL::Size::Make(NS::UInteger width, NS::UInteger height, NS::UInteger depth) 122 { 123 return Size(width, height, depth); 124 } 125 126 _MTL_INLINE MTL::Region::Region(NS::UInteger x, NS::UInteger width) 127 : origin(x, 0, 0) 128 , size(width, 1, 1) 129 { 130 } 131 132 _MTL_INLINE MTL::Region::Region(NS::UInteger x, NS::UInteger y, NS::UInteger width, NS::UInteger height) 133 : origin(x, y, 0) 134 , size(width, height, 1) 135 { 136 } 137 138 _MTL_INLINE MTL::Region::Region(NS::UInteger x, NS::UInteger y, NS::UInteger z, NS::UInteger width, NS::UInteger height, NS::UInteger depth) 139 : origin(x, y, z) 140 , size(width, height, depth) 141 { 142 } 143 144 _MTL_INLINE MTL::Region MTL::Region::Make1D(NS::UInteger x, NS::UInteger width) 145 { 146 return Region(x, width); 147 } 148 149 _MTL_INLINE MTL::Region MTL::Region::Make2D(NS::UInteger x, NS::UInteger y, NS::UInteger width, NS::UInteger height) 150 { 151 return Region(x, y, width, height); 152 } 153 154 _MTL_INLINE MTL::Region MTL::Region::Make3D(NS::UInteger x, NS::UInteger y, NS::UInteger z, NS::UInteger width, NS::UInteger height, NS::UInteger depth) 155 { 156 return Region(x, y, z, width, height, depth); 157 } 158 159 _MTL_INLINE MTL::SamplePosition::SamplePosition(float _x, float _y) 160 : x(_x) 161 , y(_y) 162 { 163 } 164 165 _MTL_INLINE MTL::SamplePosition MTL::SamplePosition::Make(float x, float y) 166 { 167 return SamplePosition(x, y); 168 }