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_TEXTURE_H_ 16 #define SRC_AST_TEXTURE_H_ 17 18 #include "src/ast/type.h" 19 20 namespace tint { 21 namespace ast { 22 23 /// The dimensionality of the texture 24 enum class TextureDimension { 25 /// Invalid texture 26 kNone = -1, 27 /// 1 dimensional texture 28 k1d, 29 /// 2 dimensional texture 30 k2d, 31 /// 2 dimensional array texture 32 k2dArray, 33 /// 3 dimensional texture 34 k3d, 35 /// cube texture 36 kCube, 37 /// cube array texture 38 kCubeArray, 39 }; 40 41 /// @param out the std::ostream to write to 42 /// @param dim the TextureDimension 43 /// @return the std::ostream so calls can be chained 44 std::ostream& operator<<(std::ostream& out, TextureDimension dim); 45 46 /// @param dim the TextureDimension to query 47 /// @return true if the given TextureDimension is an array texture 48 bool IsTextureArray(TextureDimension dim); 49 50 /// Returns the number of axes in the coordinate used for accessing 51 /// the texture, where an access is one of: sampling, fetching, load, 52 /// or store. 53 /// None -> 0 54 /// 1D -> 1 55 /// 2D, 2DArray -> 2 56 /// 3D, Cube, CubeArray -> 3 57 /// Note: To sample a cube texture, the coordinate has 3 dimensions, 58 /// but textureDimensions on a cube or cube array returns a 2-element 59 /// size, representing the (x,y) size of each cube face, in texels. 60 /// @param dim the TextureDimension to query 61 /// @return number of dimensions in a coordinate for the dimensionality 62 int NumCoordinateAxes(TextureDimension dim); 63 64 /// A texture type. 65 class Texture : public Castable<Texture, Type> { 66 public: 67 /// Constructor 68 /// @param pid the identifier of the program that owns this node 69 /// @param src the source of this node 70 /// @param dim the dimensionality of the texture 71 Texture(ProgramID pid, const Source& src, TextureDimension dim); 72 /// Move constructor 73 Texture(Texture&&); 74 ~Texture() override; 75 76 /// The texture dimension 77 const TextureDimension dim; 78 }; 79 80 } // namespace ast 81 } // namespace tint 82 83 #endif // SRC_AST_TEXTURE_H_ 84