mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-16 00:17:03 +00:00
sem::Matrix: Pass the column type to the constructor
It's common to want this when indexing matrices. Change-Id: Ic60a3a8d05873119d78a3cb0860d129e33ac3525 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49880 Reviewed-by: James Price <jrprice@google.com> Commit-Queue: Ben Clayton <bclayton@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
b432f232b5
commit
6c1cf6569e
@@ -15,18 +15,22 @@
|
||||
#include "src/sem/matrix_type.h"
|
||||
|
||||
#include "src/program_builder.h"
|
||||
#include "src/sem/vector_type.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::sem::Matrix);
|
||||
|
||||
namespace tint {
|
||||
namespace sem {
|
||||
|
||||
Matrix::Matrix(Type* subtype, uint32_t rows, uint32_t columns)
|
||||
: subtype_(subtype), rows_(rows), columns_(columns) {
|
||||
TINT_ASSERT(rows > 1);
|
||||
TINT_ASSERT(rows < 5);
|
||||
TINT_ASSERT(columns > 1);
|
||||
TINT_ASSERT(columns < 5);
|
||||
Matrix::Matrix(Vector* column_type, uint32_t columns)
|
||||
: subtype_(column_type->type()),
|
||||
column_type_(column_type),
|
||||
rows_(column_type->size()),
|
||||
columns_(columns) {
|
||||
TINT_ASSERT(rows_ > 1);
|
||||
TINT_ASSERT(rows_ < 5);
|
||||
TINT_ASSERT(columns_ > 1);
|
||||
TINT_ASSERT(columns_ < 5);
|
||||
}
|
||||
|
||||
Matrix::Matrix(Matrix&&) = default;
|
||||
@@ -47,8 +51,8 @@ std::string Matrix::FriendlyName(const SymbolTable& symbols) const {
|
||||
|
||||
Matrix* Matrix::Clone(CloneContext* ctx) const {
|
||||
// Clone arguments outside of create() call to have deterministic ordering
|
||||
auto* ty = ctx->Clone(type());
|
||||
return ctx->dst->create<Matrix>(ty, rows_, columns_);
|
||||
auto* column_type = ctx->Clone(ColumnType());
|
||||
return ctx->dst->create<Matrix>(column_type, columns_);
|
||||
}
|
||||
|
||||
} // namespace sem
|
||||
|
||||
@@ -22,14 +22,16 @@
|
||||
namespace tint {
|
||||
namespace sem {
|
||||
|
||||
// Forward declaration
|
||||
class Vector;
|
||||
|
||||
/// A matrix type
|
||||
class Matrix : public Castable<Matrix, Type> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param subtype type matrix type
|
||||
/// @param rows the number of rows in the matrix
|
||||
/// @param column_type the type of a column of the matrix
|
||||
/// @param columns the number of columns in the matrix
|
||||
Matrix(Type* subtype, uint32_t rows, uint32_t columns);
|
||||
Matrix(Vector* column_type, uint32_t columns);
|
||||
/// Move constructor
|
||||
Matrix(Matrix&&);
|
||||
~Matrix() override;
|
||||
@@ -41,6 +43,9 @@ class Matrix : public Castable<Matrix, Type> {
|
||||
/// @returns the number of columns in the matrix
|
||||
uint32_t columns() const { return columns_; }
|
||||
|
||||
/// @returns the column-vector type of the matrix
|
||||
Vector* ColumnType() const { return column_type_; }
|
||||
|
||||
/// @returns the name for this type
|
||||
std::string type_name() const override;
|
||||
|
||||
@@ -56,6 +61,7 @@ class Matrix : public Castable<Matrix, Type> {
|
||||
|
||||
private:
|
||||
Type* const subtype_;
|
||||
Vector* const column_type_;
|
||||
uint32_t const rows_;
|
||||
uint32_t const columns_;
|
||||
};
|
||||
|
||||
@@ -24,7 +24,8 @@ using MatrixTest = TestHelper;
|
||||
|
||||
TEST_F(MatrixTest, Creation) {
|
||||
I32 i32;
|
||||
Matrix m{&i32, 2, 4};
|
||||
Vector c{&i32, 2};
|
||||
Matrix m{&c, 4};
|
||||
EXPECT_EQ(m.type(), &i32);
|
||||
EXPECT_EQ(m.rows(), 2u);
|
||||
EXPECT_EQ(m.columns(), 4u);
|
||||
@@ -32,7 +33,8 @@ TEST_F(MatrixTest, Creation) {
|
||||
|
||||
TEST_F(MatrixTest, Is) {
|
||||
I32 i32;
|
||||
Matrix m{&i32, 2, 3};
|
||||
Vector c{&i32, 2};
|
||||
Matrix m{&c, 4};
|
||||
Type* ty = &m;
|
||||
EXPECT_FALSE(ty->Is<AccessControl>());
|
||||
EXPECT_FALSE(ty->Is<Alias>());
|
||||
@@ -51,12 +53,15 @@ TEST_F(MatrixTest, Is) {
|
||||
|
||||
TEST_F(MatrixTest, TypeName) {
|
||||
I32 i32;
|
||||
Matrix m{&i32, 2, 3};
|
||||
Vector c{&i32, 2};
|
||||
Matrix m{&c, 3};
|
||||
EXPECT_EQ(m.type_name(), "__mat_2_3__i32");
|
||||
}
|
||||
|
||||
TEST_F(MatrixTest, FriendlyName) {
|
||||
Matrix m{ty.i32(), 3, 2};
|
||||
I32 i32;
|
||||
Vector c{&i32, 3};
|
||||
Matrix m{&c, 2};
|
||||
EXPECT_EQ(m.FriendlyName(Symbols()), "mat2x3<i32>");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user