1 // 2 // Copyright 2002 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 7 #if defined(_MSC_VER) 8 # pragma warning(disable : 4718) 9 #endif 10 #include "compiler/translator/msl/UtilsMSL.h" 11 #include <algorithm> 12 #include <climits> 13 #include "compiler/translator/HashNames.h" 14 #include "compiler/translator/ImmutableString.h" 15 #include "compiler/translator/InfoSink.h" 16 #include "compiler/translator/IntermNode.h" 17 #include "compiler/translator/SymbolTable.h" 18 #include "compiler/translator/Types.h" 19 20 namespace sh 21 { 22 getBasicMetalString(const TType * t)23const char *getBasicMetalString(const TType *t) 24 { 25 switch (t->getBasicType()) 26 { 27 case EbtVoid: 28 return "void"; 29 case EbtFloat: 30 return "float"; 31 case EbtInt: 32 return "int"; 33 case EbtUInt: 34 return "uint32_t"; 35 case EbtBool: 36 return "bool"; 37 case EbtYuvCscStandardEXT: 38 return "yuvCscStandardEXT"; 39 case EbtSampler2D: 40 return "sampler2D"; 41 case EbtSampler3D: 42 return "sampler3D"; 43 case EbtSamplerCube: 44 return "samplerCube"; 45 case EbtSamplerExternalOES: 46 return "samplerExternalOES"; 47 case EbtSamplerExternal2DY2YEXT: 48 return "__samplerExternal2DY2YEXT"; 49 case EbtSampler2DRect: 50 return "sampler2DRect"; 51 case EbtSampler2DArray: 52 return "sampler2DArray"; 53 case EbtSampler2DMS: 54 return "sampler2DMS"; 55 case EbtSampler2DMSArray: 56 return "sampler2DMSArray"; 57 case EbtSamplerCubeArray: 58 return "samplerCubeArray"; 59 case EbtISampler2D: 60 return "isampler2D"; 61 case EbtISampler3D: 62 return "isampler3D"; 63 case EbtISamplerCube: 64 return "isamplerCube"; 65 case EbtISampler2DArray: 66 return "isampler2DArray"; 67 case EbtISampler2DMS: 68 return "isampler2DMS"; 69 case EbtISampler2DMSArray: 70 return "isampler2DMSArray"; 71 case EbtISamplerCubeArray: 72 return "isamplerCubeArray"; 73 case EbtUSampler2D: 74 return "usampler2D"; 75 case EbtUSampler3D: 76 return "usampler3D"; 77 case EbtUSamplerCube: 78 return "usamplerCube"; 79 case EbtUSampler2DArray: 80 return "usampler2DArray"; 81 case EbtUSampler2DMS: 82 return "usampler2DMS"; 83 case EbtUSampler2DMSArray: 84 return "usampler2DMSArray"; 85 case EbtUSamplerCubeArray: 86 return "usamplerCubeArray"; 87 case EbtSampler2DShadow: 88 return "sampler2DShadow"; 89 case EbtSamplerCubeShadow: 90 return "samplerCubeShadow"; 91 case EbtSampler2DArrayShadow: 92 return "sampler2DArrayShadow"; 93 case EbtSamplerCubeArrayShadow: 94 return "samplerCubeArrayShadow"; 95 case EbtStruct: 96 return "structure"; 97 case EbtInterfaceBlock: 98 return "interface block"; 99 case EbtImage2D: 100 return "texture2d"; 101 case EbtIImage2D: 102 return "texture2d<int>"; 103 case EbtUImage2D: 104 return "texture2d<uint32_t>"; 105 case EbtImage3D: 106 return "texture3d"; 107 case EbtIImage3D: 108 return "texture3d<int>"; 109 case EbtUImage3D: 110 return "texture3d<uint32_t>"; 111 case EbtImage2DArray: 112 if (t->isUnsizedArray()) 113 { 114 return "array_ref<texture2d>"; 115 } 116 else 117 { 118 return "NOT_IMPLEMENTED"; 119 } 120 case EbtIImage2DArray: 121 if (t->isUnsizedArray()) 122 { 123 return "array_ref<texture2d<int>>"; 124 } 125 else 126 { 127 return "NOT_IMPLEMENTED"; 128 } 129 case EbtUImage2DArray: 130 if (t->isUnsizedArray()) 131 { 132 return "array_ref<texture2d<uint32_t>>"; 133 } 134 else 135 { 136 return "NOT_IMPLEMENTED"; 137 } 138 case EbtImageCube: 139 return "texturecube"; 140 case EbtIImageCube: 141 return "texturecube<int>"; 142 case EbtUImageCube: 143 return "texturecube<uint32_t>"; 144 case EbtImageCubeArray: 145 if (t->isUnsizedArray()) 146 { 147 return "array_ref<texturecube>"; 148 } 149 else 150 { 151 return "NOT_IMPLEMENTED"; 152 } 153 case EbtIImageCubeArray: 154 if (t->isUnsizedArray()) 155 { 156 return "array_ref<texturecube<int>>"; 157 } 158 else 159 { 160 return "NOT_IMPLEMENTED"; 161 } 162 case EbtUImageCubeArray: 163 if (t->isUnsizedArray()) 164 { 165 return "array_ref<texturecube<uint32_t>>"; 166 } 167 else 168 { 169 return "NOT_IMPLEMENTED"; 170 } 171 case EbtAtomicCounter: 172 return "atomic_uint"; 173 case EbtSamplerVideoWEBGL: 174 return "$samplerVideoWEBGL"; 175 default: 176 UNREACHABLE(); 177 return "unknown type"; 178 } 179 } 180 getBuiltInMetalTypeNameString(const TType * t)181const char *getBuiltInMetalTypeNameString(const TType *t) 182 { 183 if (t->isMatrix()) 184 { 185 switch (t->getCols()) 186 { 187 case 2: 188 switch (t->getRows()) 189 { 190 case 2: 191 return "float2"; 192 case 3: 193 return "float2x3"; 194 case 4: 195 return "float2x4"; 196 default: 197 UNREACHABLE(); 198 return nullptr; 199 } 200 case 3: 201 switch (t->getRows()) 202 { 203 case 2: 204 return "float3x2"; 205 case 3: 206 return "float3"; 207 case 4: 208 return "float3x4"; 209 default: 210 UNREACHABLE(); 211 return nullptr; 212 } 213 case 4: 214 switch (t->getRows()) 215 { 216 case 2: 217 return "float4x2"; 218 case 3: 219 return "float4x3"; 220 case 4: 221 return "float4"; 222 default: 223 UNREACHABLE(); 224 return nullptr; 225 } 226 default: 227 UNREACHABLE(); 228 return nullptr; 229 } 230 } 231 if (t->isVector()) 232 { 233 switch (t->getBasicType()) 234 { 235 case EbtFloat: 236 switch (t->getNominalSize()) 237 { 238 case 2: 239 return "float2"; 240 case 3: 241 return "float3"; 242 case 4: 243 return "float4"; 244 default: 245 UNREACHABLE(); 246 return nullptr; 247 } 248 case EbtInt: 249 switch (t->getNominalSize()) 250 { 251 case 2: 252 return "int2"; 253 case 3: 254 return "int3"; 255 case 4: 256 return "int4"; 257 default: 258 UNREACHABLE(); 259 return nullptr; 260 } 261 case EbtBool: 262 switch (t->getNominalSize()) 263 { 264 case 2: 265 return "bool2"; 266 case 3: 267 return "bool3"; 268 case 4: 269 return "bool4"; 270 default: 271 UNREACHABLE(); 272 return nullptr; 273 } 274 case EbtUInt: 275 switch (t->getNominalSize()) 276 { 277 case 2: 278 return "uint2"; 279 case 3: 280 return "uint3"; 281 case 4: 282 return "uint4"; 283 default: 284 UNREACHABLE(); 285 return nullptr; 286 } 287 default: 288 UNREACHABLE(); 289 return nullptr; 290 } 291 } 292 ASSERT(t->getBasicType() != EbtStruct); 293 ASSERT(t->getBasicType() != EbtInterfaceBlock); 294 return getBasicMetalString(t); 295 } 296 GetMetalTypeName(const TType & type,ShHashFunction64 hashFunction,NameMap * nameMap)297ImmutableString GetMetalTypeName(const TType &type, ShHashFunction64 hashFunction, NameMap *nameMap) 298 { 299 if (type.getBasicType() == EbtStruct) 300 return HashName(type.getStruct(), hashFunction, nameMap); 301 else 302 return ImmutableString(getBuiltInMetalTypeNameString(&type)); 303 } 304 305 } // namespace sh 306