1 // 2 // Copyright 2020 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 #ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_LAYOUT_H_ 8 #define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_LAYOUT_H_ 9 10 #include "common/angleutils.h" 11 #include "compiler/translator/Types.h" 12 13 namespace sh 14 { 15 16 constexpr const auto kDefaultLayoutBlockStorage = TLayoutBlockStorage::EbsShared; 17 constexpr const auto kDefaultLayoutMatrixPacking = TLayoutMatrixPacking::EmpColumnMajor; 18 constexpr const auto kDefaultStructAlignmentSize = 16; 19 20 // Returns `oldStorage` if `type` has unspecified block storage. 21 // Otherwise returns block storage of `type`. 22 TLayoutBlockStorage Overlay(TLayoutBlockStorage oldStorage, const TType &type); 23 24 // Returns `oldPacking` if `type` has unspecified matrix packing. 25 // Otherwise returns matrix packing of `type`. 26 TLayoutMatrixPacking Overlay(TLayoutMatrixPacking oldPacking, const TType &type); 27 28 // Returns whether or not it is permissable for the block storage to use a packed representation. 29 bool CanBePacked(TLayoutBlockStorage storage); 30 31 // Returns whether or not it is permissable for the layout qualifier to use a packed representation. 32 bool CanBePacked(TLayoutQualifier layoutQualifier); 33 34 // Returns whether or not it is permissable for the type to use a packed representation. 35 bool CanBePacked(const TType &type); 36 37 // Sets the block storage for a type. 38 void SetBlockStorage(TType &type, TLayoutBlockStorage storage); 39 40 // Contains `sizeof` and `alignof` information. 41 struct Layout 42 { 43 size_t sizeOf; 44 size_t alignOf; 45 IdentityLayout46 static Layout Identity() { return {0, 1}; } InvalidLayout47 static Layout Invalid() { return {0, 0}; } BothLayout48 static Layout Both(size_t n) { return {n, n}; } 49 50 void requireAlignment(size_t align, bool pad); 51 52 bool operator==(const Layout &other) const; 53 54 void operator+=(const Layout &other); 55 void operator*=(size_t scale); 56 57 Layout operator+(const Layout &other) const; 58 Layout operator*(size_t scale) const; 59 }; 60 61 struct MetalLayoutOfConfig 62 { 63 bool disablePacking = false; 64 bool maskArray = false; 65 bool treatSamplersAsTextureEnv = false; 66 bool assumeStructsAreTailPadded = false; // Pad to multiple of 16 67 }; 68 69 // Returns the layout of a type if it were to be represented in a Metal program. 70 // This deliberately ignores the TLayoutBlockStorage and TLayoutMatrixPacking of any type. 71 ANGLE_NO_DISCARD Layout MetalLayoutOf(const TType &type, MetalLayoutOfConfig config = {}); 72 73 // Returns the layout of a type if it were to be represented in a GLSL program. 74 ANGLE_NO_DISCARD Layout 75 GlslLayoutOf(const TType &type, 76 TLayoutBlockStorage storage = TLayoutBlockStorage::EbsUnspecified, 77 TLayoutMatrixPacking matrixPacking = TLayoutMatrixPacking::EmpUnspecified, 78 bool maskArray = false); 79 80 // Returns the layout of a structure if it were to be represented in a GLSL program. 81 ANGLE_NO_DISCARD Layout GlslStructLayoutOf(TField const *const *begin, 82 TField const *const *end, 83 TLayoutBlockStorage storage, 84 TLayoutMatrixPacking matrixPacking, 85 bool maskArray = false); 86 87 } // namespace sh 88 89 #endif // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_LAYOUT_H_ 90