1 // Copyright 2020 The Tint Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef SRC_AST_STORAGE_TEXTURE_H_ 16 #define SRC_AST_STORAGE_TEXTURE_H_ 17 18 #include <string> 19 20 #include "src/ast/access.h" 21 #include "src/ast/texture.h" 22 23 namespace tint { 24 namespace ast { 25 26 class Manager; 27 28 /// The image format in the storage texture 29 enum class ImageFormat { 30 kNone = -1, 31 kR8Unorm, 32 kR8Snorm, 33 kR8Uint, 34 kR8Sint, 35 kR16Uint, 36 kR16Sint, 37 kR16Float, 38 kRg8Unorm, 39 kRg8Snorm, 40 kRg8Uint, 41 kRg8Sint, 42 kR32Uint, 43 kR32Sint, 44 kR32Float, 45 kRg16Uint, 46 kRg16Sint, 47 kRg16Float, 48 kRgba8Unorm, 49 kRgba8UnormSrgb, 50 kRgba8Snorm, 51 kRgba8Uint, 52 kRgba8Sint, 53 kBgra8Unorm, 54 kBgra8UnormSrgb, 55 kRgb10A2Unorm, 56 kRg11B10Float, 57 kRg32Uint, 58 kRg32Sint, 59 kRg32Float, 60 kRgba16Uint, 61 kRgba16Sint, 62 kRgba16Float, 63 kRgba32Uint, 64 kRgba32Sint, 65 kRgba32Float, 66 }; 67 68 /// @param out the std::ostream to write to 69 /// @param format the ImageFormat 70 /// @return the std::ostream so calls can be chained 71 std::ostream& operator<<(std::ostream& out, ImageFormat format); 72 73 /// A storage texture type. 74 class StorageTexture : public Castable<StorageTexture, Texture> { 75 public: 76 /// Constructor 77 /// @param pid the identifier of the program that owns this node 78 /// @param src the source of this node 79 /// @param dim the dimensionality of the texture 80 /// @param format the image format of the texture 81 /// @param subtype the storage subtype. Use SubtypeFor() to calculate this. 82 /// @param access_control the access control for the texture. 83 StorageTexture(ProgramID pid, 84 const Source& src, 85 TextureDimension dim, 86 ImageFormat format, 87 const Type* subtype, 88 Access access_control); 89 90 /// Move constructor 91 StorageTexture(StorageTexture&&); 92 ~StorageTexture() override; 93 94 /// @param symbols the program's symbol table 95 /// @returns the name for this type that closely resembles how it would be 96 /// declared in WGSL. 97 std::string FriendlyName(const SymbolTable& symbols) const override; 98 99 /// Clones this type and all transitive types using the `CloneContext` `ctx`. 100 /// @param ctx the clone context 101 /// @return the newly cloned type 102 const StorageTexture* Clone(CloneContext* ctx) const override; 103 104 /// @param format the storage texture image format 105 /// @param builder the ProgramBuilder used to build the returned type 106 /// @returns the storage texture subtype for the given ImageFormat 107 static Type* SubtypeFor(ImageFormat format, ProgramBuilder& builder); 108 109 /// The image format 110 const ImageFormat format; 111 112 /// The storage subtype 113 const Type* const type; 114 115 /// The access control 116 const Access access; 117 }; 118 119 } // namespace ast 120 } // namespace tint 121 122 #endif // SRC_AST_STORAGE_TEXTURE_H_ 123