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 #include "src/sem/matrix_type.h"
16
17 #include "src/program_builder.h"
18 #include "src/sem/vector_type.h"
19
20 TINT_INSTANTIATE_TYPEINFO(tint::sem::Matrix);
21
22 namespace tint {
23 namespace sem {
24
Matrix(const Vector * column_type,uint32_t columns)25 Matrix::Matrix(const Vector* column_type, uint32_t columns)
26 : subtype_(column_type->type()),
27 column_type_(column_type),
28 rows_(column_type->Width()),
29 columns_(columns) {
30 TINT_ASSERT(AST, rows_ > 1);
31 TINT_ASSERT(AST, rows_ < 5);
32 TINT_ASSERT(AST, columns_ > 1);
33 TINT_ASSERT(AST, columns_ < 5);
34 }
35
36 Matrix::Matrix(Matrix&&) = default;
37
38 Matrix::~Matrix() = default;
39
type_name() const40 std::string Matrix::type_name() const {
41 return "__mat_" + std::to_string(rows_) + "_" + std::to_string(columns_) +
42 subtype_->type_name();
43 }
44
FriendlyName(const SymbolTable & symbols) const45 std::string Matrix::FriendlyName(const SymbolTable& symbols) const {
46 std::ostringstream out;
47 out << "mat" << columns_ << "x" << rows_ << "<"
48 << subtype_->FriendlyName(symbols) << ">";
49 return out.str();
50 }
51
IsConstructible() const52 bool Matrix::IsConstructible() const {
53 return true;
54 }
55
Size() const56 uint32_t Matrix::Size() const {
57 return column_type_->Align() * columns();
58 }
59
Align() const60 uint32_t Matrix::Align() const {
61 return column_type_->Align();
62 }
63
ColumnStride() const64 uint32_t Matrix::ColumnStride() const {
65 return column_type_->Align();
66 }
67
68 } // namespace sem
69 } // namespace tint
70