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_SEM_MATRIX_TYPE_H_ 16 #define SRC_SEM_MATRIX_TYPE_H_ 17 18 #include <string> 19 20 #include "src/sem/type.h" 21 22 namespace tint { 23 namespace sem { 24 25 // Forward declaration 26 class Vector; 27 28 /// A matrix type 29 class Matrix : public Castable<Matrix, Type> { 30 public: 31 /// Constructor 32 /// @param column_type the type of a column of the matrix 33 /// @param columns the number of columns in the matrix 34 Matrix(const Vector* column_type, uint32_t columns); 35 /// Move constructor 36 Matrix(Matrix&&); 37 ~Matrix() override; 38 39 /// @returns the type of the matrix type()40 const Type* type() const { return subtype_; } 41 /// @returns the number of rows in the matrix rows()42 uint32_t rows() const { return rows_; } 43 /// @returns the number of columns in the matrix columns()44 uint32_t columns() const { return columns_; } 45 46 /// @returns the column-vector type of the matrix ColumnType()47 const Vector* ColumnType() const { return column_type_; } 48 49 /// @returns the name for this type 50 std::string type_name() const override; 51 52 /// @param symbols the program's symbol table 53 /// @returns the name for this type that closely resembles how it would be 54 /// declared in WGSL. 55 std::string FriendlyName(const SymbolTable& symbols) const override; 56 57 /// @returns true if constructible as per 58 /// https://gpuweb.github.io/gpuweb/wgsl/#constructible-types 59 bool IsConstructible() const override; 60 61 /// @returns the size in bytes of the type. This may include tail padding. 62 uint32_t Size() const override; 63 64 /// @returns the alignment in bytes of the type. This may include tail 65 /// padding. 66 uint32_t Align() const override; 67 68 /// @returns the number of bytes between columns of the matrix 69 uint32_t ColumnStride() const; 70 71 private: 72 const Type* const subtype_; 73 const Vector* const column_type_; 74 const uint32_t rows_; 75 const uint32_t columns_; 76 }; 77 78 } // namespace sem 79 } // namespace tint 80 81 #endif // SRC_SEM_MATRIX_TYPE_H_ 82