Replace Type::(Is|As)Matrix with Castable

Change-Id: I861aed231604a8bfba1f4cf3659b4863556fc3c4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34268
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2020-11-30 23:30:58 +00:00
parent 9857f81e94
commit d8457c15f1
32 changed files with 144 additions and 140 deletions

View File

@ -27,6 +27,7 @@
#include "src/ast/type/bool_type.h" #include "src/ast/type/bool_type.h"
#include "src/ast/type/f32_type.h" #include "src/ast/type/f32_type.h"
#include "src/ast/type/i32_type.h" #include "src/ast/type/i32_type.h"
#include "src/ast/type/matrix_type.h"
#include "src/ast/type/pointer_type.h" #include "src/ast/type/pointer_type.h"
#include "src/ast/type/struct_type.h" #include "src/ast/type/struct_type.h"
#include "src/ast/type/u32_type.h" #include "src/ast/type/u32_type.h"
@ -56,7 +57,7 @@ TEST_F(AccessControlTypeTest, Is) {
EXPECT_FALSE(ty->Is<BoolType>()); EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>()); EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->Is<I32Type>()); EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix()); EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->IsPointer()); EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler()); EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->IsStruct()); EXPECT_FALSE(ty->IsStruct());

View File

@ -28,6 +28,7 @@
#include "src/ast/type/bool_type.h" #include "src/ast/type/bool_type.h"
#include "src/ast/type/f32_type.h" #include "src/ast/type/f32_type.h"
#include "src/ast/type/i32_type.h" #include "src/ast/type/i32_type.h"
#include "src/ast/type/matrix_type.h"
#include "src/ast/type/pointer_type.h" #include "src/ast/type/pointer_type.h"
#include "src/ast/type/struct_type.h" #include "src/ast/type/struct_type.h"
#include "src/ast/type/u32_type.h" #include "src/ast/type/u32_type.h"
@ -57,7 +58,7 @@ TEST_F(AliasTypeTest, Is) {
EXPECT_FALSE(ty->Is<BoolType>()); EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>()); EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->Is<I32Type>()); EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix()); EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->IsPointer()); EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler()); EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->IsStruct()); EXPECT_FALSE(ty->IsStruct());

View File

@ -23,6 +23,7 @@
#include "src/ast/type/bool_type.h" #include "src/ast/type/bool_type.h"
#include "src/ast/type/f32_type.h" #include "src/ast/type/f32_type.h"
#include "src/ast/type/i32_type.h" #include "src/ast/type/i32_type.h"
#include "src/ast/type/matrix_type.h"
#include "src/ast/type/u32_type.h" #include "src/ast/type/u32_type.h"
namespace tint { namespace tint {
@ -61,7 +62,7 @@ TEST_F(ArrayTypeTest, Is) {
EXPECT_FALSE(ty->Is<BoolType>()); EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>()); EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->Is<I32Type>()); EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix()); EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->IsPointer()); EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler()); EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->IsStruct()); EXPECT_FALSE(ty->IsStruct());

View File

@ -19,6 +19,7 @@
#include "src/ast/type/array_type.h" #include "src/ast/type/array_type.h"
#include "src/ast/type/f32_type.h" #include "src/ast/type/f32_type.h"
#include "src/ast/type/i32_type.h" #include "src/ast/type/i32_type.h"
#include "src/ast/type/matrix_type.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
@ -36,7 +37,7 @@ TEST_F(BoolTypeTest, Is) {
EXPECT_TRUE(ty->Is<BoolType>()); EXPECT_TRUE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>()); EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->Is<I32Type>()); EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix()); EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->IsPointer()); EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler()); EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->IsStruct()); EXPECT_FALSE(ty->IsStruct());

View File

@ -21,6 +21,7 @@
#include "src/ast/type/bool_type.h" #include "src/ast/type/bool_type.h"
#include "src/ast/type/f32_type.h" #include "src/ast/type/f32_type.h"
#include "src/ast/type/i32_type.h" #include "src/ast/type/i32_type.h"
#include "src/ast/type/matrix_type.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
@ -38,7 +39,7 @@ TEST_F(DepthTextureTypeTest, Is) {
EXPECT_FALSE(ty->Is<BoolType>()); EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>()); EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->Is<I32Type>()); EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix()); EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->IsPointer()); EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler()); EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->IsStruct()); EXPECT_FALSE(ty->IsStruct());

View File

@ -19,6 +19,7 @@
#include "src/ast/type/array_type.h" #include "src/ast/type/array_type.h"
#include "src/ast/type/bool_type.h" #include "src/ast/type/bool_type.h"
#include "src/ast/type/i32_type.h" #include "src/ast/type/i32_type.h"
#include "src/ast/type/matrix_type.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
@ -36,7 +37,7 @@ TEST_F(F32TypeTest, Is) {
EXPECT_FALSE(ty->Is<BoolType>()); EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_TRUE(ty->Is<F32Type>()); EXPECT_TRUE(ty->Is<F32Type>());
EXPECT_FALSE(ty->Is<I32Type>()); EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix()); EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->IsPointer()); EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler()); EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->IsStruct()); EXPECT_FALSE(ty->IsStruct());

View File

@ -19,6 +19,7 @@
#include "src/ast/type/array_type.h" #include "src/ast/type/array_type.h"
#include "src/ast/type/bool_type.h" #include "src/ast/type/bool_type.h"
#include "src/ast/type/f32_type.h" #include "src/ast/type/f32_type.h"
#include "src/ast/type/matrix_type.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
@ -36,7 +37,7 @@ TEST_F(I32TypeTest, Is) {
EXPECT_FALSE(ty->Is<BoolType>()); EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>()); EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_TRUE(ty->Is<I32Type>()); EXPECT_TRUE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix()); EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->IsPointer()); EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler()); EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->IsStruct()); EXPECT_FALSE(ty->IsStruct());

View File

@ -35,10 +35,6 @@ MatrixType::MatrixType(MatrixType&&) = default;
MatrixType::~MatrixType() = default; MatrixType::~MatrixType() = default;
bool MatrixType::IsMatrix() const {
return true;
}
std::string MatrixType::type_name() const { std::string MatrixType::type_name() const {
return "__mat_" + std::to_string(rows_) + "_" + std::to_string(columns_) + return "__mat_" + std::to_string(rows_) + "_" + std::to_string(columns_) +
subtype_->type_name(); subtype_->type_name();

View File

@ -35,9 +35,6 @@ class MatrixType : public Castable<MatrixType, Type> {
MatrixType(MatrixType&&); MatrixType(MatrixType&&);
~MatrixType() override; ~MatrixType() override;
/// @returns true if the type is a matrix type
bool IsMatrix() const override;
/// @returns the type of the matrix /// @returns the type of the matrix
Type* type() const { return subtype_; } Type* type() const { return subtype_; }
/// @returns the number of rows in the matrix /// @returns the number of rows in the matrix

View File

@ -46,7 +46,7 @@ TEST_F(MatrixTypeTest, Is) {
EXPECT_FALSE(ty->Is<BoolType>()); EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>()); EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->Is<I32Type>()); EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_TRUE(ty->IsMatrix()); EXPECT_TRUE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->IsPointer()); EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler()); EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->IsStruct()); EXPECT_FALSE(ty->IsStruct());

View File

@ -20,6 +20,7 @@
#include "src/ast/type/bool_type.h" #include "src/ast/type/bool_type.h"
#include "src/ast/type/f32_type.h" #include "src/ast/type/f32_type.h"
#include "src/ast/type/i32_type.h" #include "src/ast/type/i32_type.h"
#include "src/ast/type/matrix_type.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
@ -38,7 +39,7 @@ TEST_F(MultisampledTextureTypeTest, Is) {
EXPECT_FALSE(ty->Is<BoolType>()); EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>()); EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->Is<I32Type>()); EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix()); EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->IsPointer()); EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler()); EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->IsStruct()); EXPECT_FALSE(ty->IsStruct());

View File

@ -20,6 +20,7 @@
#include "src/ast/type/bool_type.h" #include "src/ast/type/bool_type.h"
#include "src/ast/type/f32_type.h" #include "src/ast/type/f32_type.h"
#include "src/ast/type/i32_type.h" #include "src/ast/type/i32_type.h"
#include "src/ast/type/matrix_type.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
@ -45,7 +46,7 @@ TEST_F(PointerTypeTest, Is) {
EXPECT_FALSE(ty->Is<BoolType>()); EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>()); EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->Is<I32Type>()); EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix()); EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_TRUE(ty->IsPointer()); EXPECT_TRUE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler()); EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->IsStruct()); EXPECT_FALSE(ty->IsStruct());

View File

@ -20,6 +20,7 @@
#include "src/ast/type/bool_type.h" #include "src/ast/type/bool_type.h"
#include "src/ast/type/f32_type.h" #include "src/ast/type/f32_type.h"
#include "src/ast/type/i32_type.h" #include "src/ast/type/i32_type.h"
#include "src/ast/type/matrix_type.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
@ -38,7 +39,7 @@ TEST_F(SampledTextureTypeTest, Is) {
EXPECT_FALSE(ty->Is<BoolType>()); EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>()); EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->Is<I32Type>()); EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix()); EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->IsPointer()); EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler()); EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->IsStruct()); EXPECT_FALSE(ty->IsStruct());

View File

@ -20,6 +20,7 @@
#include "src/ast/type/bool_type.h" #include "src/ast/type/bool_type.h"
#include "src/ast/type/f32_type.h" #include "src/ast/type/f32_type.h"
#include "src/ast/type/i32_type.h" #include "src/ast/type/i32_type.h"
#include "src/ast/type/matrix_type.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
@ -48,7 +49,7 @@ TEST_F(SamplerTypeTest, Is) {
EXPECT_FALSE(ty->Is<BoolType>()); EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>()); EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->Is<I32Type>()); EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix()); EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->IsPointer()); EXPECT_FALSE(ty->IsPointer());
EXPECT_TRUE(ty->IsSampler()); EXPECT_TRUE(ty->IsSampler());
EXPECT_FALSE(ty->IsStruct()); EXPECT_FALSE(ty->IsStruct());

View File

@ -23,6 +23,7 @@
#include "src/ast/type/bool_type.h" #include "src/ast/type/bool_type.h"
#include "src/ast/type/f32_type.h" #include "src/ast/type/f32_type.h"
#include "src/ast/type/i32_type.h" #include "src/ast/type/i32_type.h"
#include "src/ast/type/matrix_type.h"
#include "src/type_determiner.h" #include "src/type_determiner.h"
namespace tint { namespace tint {
@ -42,7 +43,7 @@ TEST_F(StorageTextureTypeTest, Is) {
EXPECT_FALSE(ty->Is<BoolType>()); EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>()); EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->Is<I32Type>()); EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix()); EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->IsPointer()); EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler()); EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->IsStruct()); EXPECT_FALSE(ty->IsStruct());

View File

@ -26,6 +26,7 @@
#include "src/ast/type/bool_type.h" #include "src/ast/type/bool_type.h"
#include "src/ast/type/f32_type.h" #include "src/ast/type/f32_type.h"
#include "src/ast/type/i32_type.h" #include "src/ast/type/i32_type.h"
#include "src/ast/type/matrix_type.h"
#include "src/ast/type/u32_type.h" #include "src/ast/type/u32_type.h"
#include "src/ast/type/vector_type.h" #include "src/ast/type/vector_type.h"
@ -53,7 +54,7 @@ TEST_F(StructTypeTest, Is) {
EXPECT_FALSE(ty->Is<BoolType>()); EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>()); EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->Is<I32Type>()); EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix()); EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->IsPointer()); EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler()); EXPECT_FALSE(ty->IsSampler());
EXPECT_TRUE(ty->IsStruct()); EXPECT_TRUE(ty->IsStruct());

View File

@ -66,10 +66,6 @@ Type* Type::UnwrapAll() {
return UnwrapIfNeeded()->UnwrapPtrIfNeeded()->UnwrapIfNeeded(); return UnwrapIfNeeded()->UnwrapPtrIfNeeded()->UnwrapIfNeeded();
} }
bool Type::IsMatrix() const {
return false;
}
bool Type::IsPointer() const { bool Type::IsPointer() const {
return false; return false;
} }
@ -115,7 +111,7 @@ bool Type::is_float_scalar() {
} }
bool Type::is_float_matrix() { bool Type::is_float_matrix() {
return IsMatrix() && AsMatrix()->type()->is_float_scalar(); return Is<MatrixType>() && As<MatrixType>()->type()->is_float_scalar();
} }
bool Type::is_float_vector() { bool Type::is_float_vector() {
@ -150,11 +146,6 @@ bool Type::is_integer_scalar_or_vector() {
return is_unsigned_scalar_or_vector() || is_signed_scalar_or_vector(); return is_unsigned_scalar_or_vector() || is_signed_scalar_or_vector();
} }
const MatrixType* Type::AsMatrix() const {
assert(IsMatrix());
return static_cast<const MatrixType*>(this);
}
const PointerType* Type::AsPointer() const { const PointerType* Type::AsPointer() const {
assert(IsPointer()); assert(IsPointer());
return static_cast<const PointerType*>(this); return static_cast<const PointerType*>(this);
@ -190,11 +181,6 @@ const VoidType* Type::AsVoid() const {
return static_cast<const VoidType*>(this); return static_cast<const VoidType*>(this);
} }
MatrixType* Type::AsMatrix() {
assert(IsMatrix());
return static_cast<MatrixType*>(this);
}
PointerType* Type::AsPointer() { PointerType* Type::AsPointer() {
assert(IsPointer()); assert(IsPointer());
return static_cast<PointerType*>(this); return static_cast<PointerType*>(this);

View File

@ -23,7 +23,6 @@ namespace tint {
namespace ast { namespace ast {
namespace type { namespace type {
class MatrixType;
class PointerType; class PointerType;
class SamplerType; class SamplerType;
class StructType; class StructType;
@ -42,8 +41,6 @@ class Type : public Castable<Type> {
Type(Type&&); Type(Type&&);
~Type() override; ~Type() override;
/// @returns true if the type is a matrix type
virtual bool IsMatrix() const;
/// @returns true if the type is a ptr type /// @returns true if the type is a ptr type
virtual bool IsPointer() const; virtual bool IsPointer() const;
/// @returns true if the type is a sampler /// @returns true if the type is a sampler
@ -113,8 +110,6 @@ class Type : public Castable<Type> {
/// @returns true if this type is an integer scalar or vector /// @returns true if this type is an integer scalar or vector
bool is_integer_scalar_or_vector(); bool is_integer_scalar_or_vector();
/// @returns the type as a matrix type
const MatrixType* AsMatrix() const;
/// @returns the type as a pointer type /// @returns the type as a pointer type
const PointerType* AsPointer() const; const PointerType* AsPointer() const;
/// @returns the type as a sampler type /// @returns the type as a sampler type
@ -130,8 +125,6 @@ class Type : public Castable<Type> {
/// @returns the type as a void type /// @returns the type as a void type
const VoidType* AsVoid() const; const VoidType* AsVoid() const;
/// @returns the type as a matrix type
MatrixType* AsMatrix();
/// @returns the type as a pointer type /// @returns the type as a pointer type
PointerType* AsPointer(); PointerType* AsPointer();
/// @returns the type as a sampler type /// @returns the type as a sampler type

View File

@ -20,6 +20,7 @@
#include "src/ast/type/bool_type.h" #include "src/ast/type/bool_type.h"
#include "src/ast/type/f32_type.h" #include "src/ast/type/f32_type.h"
#include "src/ast/type/i32_type.h" #include "src/ast/type/i32_type.h"
#include "src/ast/type/matrix_type.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
@ -37,7 +38,7 @@ TEST_F(U32TypeTest, Is) {
EXPECT_FALSE(ty->Is<BoolType>()); EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>()); EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->Is<I32Type>()); EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix()); EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->IsPointer()); EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler()); EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->IsStruct()); EXPECT_FALSE(ty->IsStruct());

View File

@ -20,6 +20,7 @@
#include "src/ast/type/bool_type.h" #include "src/ast/type/bool_type.h"
#include "src/ast/type/f32_type.h" #include "src/ast/type/f32_type.h"
#include "src/ast/type/i32_type.h" #include "src/ast/type/i32_type.h"
#include "src/ast/type/matrix_type.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
@ -45,7 +46,7 @@ TEST_F(VectorTypeTest, Is) {
EXPECT_FALSE(ty->Is<BoolType>()); EXPECT_FALSE(ty->Is<BoolType>());
EXPECT_FALSE(ty->Is<F32Type>()); EXPECT_FALSE(ty->Is<F32Type>());
EXPECT_FALSE(ty->Is<I32Type>()); EXPECT_FALSE(ty->Is<I32Type>());
EXPECT_FALSE(ty->IsMatrix()); EXPECT_FALSE(ty->Is<MatrixType>());
EXPECT_FALSE(ty->IsPointer()); EXPECT_FALSE(ty->IsPointer());
EXPECT_FALSE(ty->IsSampler()); EXPECT_FALSE(ty->IsSampler());
EXPECT_FALSE(ty->IsStruct()); EXPECT_FALSE(ty->IsStruct());

View File

@ -387,8 +387,8 @@ std::vector<ResourceBinding> Inspector::GetSampledTextureResourceBindingsImpl(
if (base_type->Is<ast::type::ArrayType>()) { if (base_type->Is<ast::type::ArrayType>()) {
base_type = base_type->As<ast::type::ArrayType>()->type(); base_type = base_type->As<ast::type::ArrayType>()->type();
} else if (base_type->IsMatrix()) { } else if (base_type->Is<ast::type::MatrixType>()) {
base_type = base_type->AsMatrix()->type(); base_type = base_type->As<ast::type::MatrixType>()->type();
} else if (base_type->IsVector()) { } else if (base_type->IsVector()) {
base_type = base_type->AsVector()->type(); base_type = base_type->AsVector()->type();
} }

View File

@ -1359,8 +1359,8 @@ ast::Expression* ParserImpl::MakeNullValue(ast::type::Type* type) {
return create<ast::TypeConstructorExpression>(type, return create<ast::TypeConstructorExpression>(type,
std::move(ast_components)); std::move(ast_components));
} }
if (type->IsMatrix()) { if (type->Is<ast::type::MatrixType>()) {
const auto* mat_ty = type->AsMatrix(); const auto* mat_ty = type->As<ast::type::MatrixType>();
// Matrix components are columns // Matrix components are columns
auto* column_ty = ast_module_.create<ast::type::VectorType>(mat_ty->type(), auto* column_ty = ast_module_.create<ast::type::VectorType>(mat_ty->type(),
mat_ty->rows()); mat_ty->rows());

View File

@ -276,58 +276,67 @@ TEST_F(SpvParserTest, ConvertType_MatrixOverF32) {
EXPECT_TRUE(p->BuildInternalModule()); EXPECT_TRUE(p->BuildInternalModule());
auto* m22 = p->ConvertType(22); auto* m22 = p->ConvertType(22);
EXPECT_TRUE(m22->IsMatrix()); EXPECT_TRUE(m22->Is<ast::type::MatrixType>());
EXPECT_TRUE(m22->AsMatrix()->type()->Is<ast::type::F32Type>()); EXPECT_TRUE(
EXPECT_EQ(m22->AsMatrix()->rows(), 2u); m22->As<ast::type::MatrixType>()->type()->Is<ast::type::F32Type>());
EXPECT_EQ(m22->AsMatrix()->columns(), 2u); EXPECT_EQ(m22->As<ast::type::MatrixType>()->rows(), 2u);
EXPECT_EQ(m22->As<ast::type::MatrixType>()->columns(), 2u);
auto* m23 = p->ConvertType(23); auto* m23 = p->ConvertType(23);
EXPECT_TRUE(m23->IsMatrix()); EXPECT_TRUE(m23->Is<ast::type::MatrixType>());
EXPECT_TRUE(m23->AsMatrix()->type()->Is<ast::type::F32Type>()); EXPECT_TRUE(
EXPECT_EQ(m23->AsMatrix()->rows(), 2u); m23->As<ast::type::MatrixType>()->type()->Is<ast::type::F32Type>());
EXPECT_EQ(m23->AsMatrix()->columns(), 3u); EXPECT_EQ(m23->As<ast::type::MatrixType>()->rows(), 2u);
EXPECT_EQ(m23->As<ast::type::MatrixType>()->columns(), 3u);
auto* m24 = p->ConvertType(24); auto* m24 = p->ConvertType(24);
EXPECT_TRUE(m24->IsMatrix()); EXPECT_TRUE(m24->Is<ast::type::MatrixType>());
EXPECT_TRUE(m24->AsMatrix()->type()->Is<ast::type::F32Type>()); EXPECT_TRUE(
EXPECT_EQ(m24->AsMatrix()->rows(), 2u); m24->As<ast::type::MatrixType>()->type()->Is<ast::type::F32Type>());
EXPECT_EQ(m24->AsMatrix()->columns(), 4u); EXPECT_EQ(m24->As<ast::type::MatrixType>()->rows(), 2u);
EXPECT_EQ(m24->As<ast::type::MatrixType>()->columns(), 4u);
auto* m32 = p->ConvertType(32); auto* m32 = p->ConvertType(32);
EXPECT_TRUE(m32->IsMatrix()); EXPECT_TRUE(m32->Is<ast::type::MatrixType>());
EXPECT_TRUE(m32->AsMatrix()->type()->Is<ast::type::F32Type>()); EXPECT_TRUE(
EXPECT_EQ(m32->AsMatrix()->rows(), 3u); m32->As<ast::type::MatrixType>()->type()->Is<ast::type::F32Type>());
EXPECT_EQ(m32->AsMatrix()->columns(), 2u); EXPECT_EQ(m32->As<ast::type::MatrixType>()->rows(), 3u);
EXPECT_EQ(m32->As<ast::type::MatrixType>()->columns(), 2u);
auto* m33 = p->ConvertType(33); auto* m33 = p->ConvertType(33);
EXPECT_TRUE(m33->IsMatrix()); EXPECT_TRUE(m33->Is<ast::type::MatrixType>());
EXPECT_TRUE(m33->AsMatrix()->type()->Is<ast::type::F32Type>()); EXPECT_TRUE(
EXPECT_EQ(m33->AsMatrix()->rows(), 3u); m33->As<ast::type::MatrixType>()->type()->Is<ast::type::F32Type>());
EXPECT_EQ(m33->AsMatrix()->columns(), 3u); EXPECT_EQ(m33->As<ast::type::MatrixType>()->rows(), 3u);
EXPECT_EQ(m33->As<ast::type::MatrixType>()->columns(), 3u);
auto* m34 = p->ConvertType(34); auto* m34 = p->ConvertType(34);
EXPECT_TRUE(m34->IsMatrix()); EXPECT_TRUE(m34->Is<ast::type::MatrixType>());
EXPECT_TRUE(m34->AsMatrix()->type()->Is<ast::type::F32Type>()); EXPECT_TRUE(
EXPECT_EQ(m34->AsMatrix()->rows(), 3u); m34->As<ast::type::MatrixType>()->type()->Is<ast::type::F32Type>());
EXPECT_EQ(m34->AsMatrix()->columns(), 4u); EXPECT_EQ(m34->As<ast::type::MatrixType>()->rows(), 3u);
EXPECT_EQ(m34->As<ast::type::MatrixType>()->columns(), 4u);
auto* m42 = p->ConvertType(42); auto* m42 = p->ConvertType(42);
EXPECT_TRUE(m42->IsMatrix()); EXPECT_TRUE(m42->Is<ast::type::MatrixType>());
EXPECT_TRUE(m42->AsMatrix()->type()->Is<ast::type::F32Type>()); EXPECT_TRUE(
EXPECT_EQ(m42->AsMatrix()->rows(), 4u); m42->As<ast::type::MatrixType>()->type()->Is<ast::type::F32Type>());
EXPECT_EQ(m42->AsMatrix()->columns(), 2u); EXPECT_EQ(m42->As<ast::type::MatrixType>()->rows(), 4u);
EXPECT_EQ(m42->As<ast::type::MatrixType>()->columns(), 2u);
auto* m43 = p->ConvertType(43); auto* m43 = p->ConvertType(43);
EXPECT_TRUE(m43->IsMatrix()); EXPECT_TRUE(m43->Is<ast::type::MatrixType>());
EXPECT_TRUE(m43->AsMatrix()->type()->Is<ast::type::F32Type>()); EXPECT_TRUE(
EXPECT_EQ(m43->AsMatrix()->rows(), 4u); m43->As<ast::type::MatrixType>()->type()->Is<ast::type::F32Type>());
EXPECT_EQ(m43->AsMatrix()->columns(), 3u); EXPECT_EQ(m43->As<ast::type::MatrixType>()->rows(), 4u);
EXPECT_EQ(m43->As<ast::type::MatrixType>()->columns(), 3u);
auto* m44 = p->ConvertType(44); auto* m44 = p->ConvertType(44);
EXPECT_TRUE(m44->IsMatrix()); EXPECT_TRUE(m44->Is<ast::type::MatrixType>());
EXPECT_TRUE(m44->AsMatrix()->type()->Is<ast::type::F32Type>()); EXPECT_TRUE(
EXPECT_EQ(m44->AsMatrix()->rows(), 4u); m44->As<ast::type::MatrixType>()->type()->Is<ast::type::F32Type>());
EXPECT_EQ(m44->AsMatrix()->columns(), 4u); EXPECT_EQ(m44->As<ast::type::MatrixType>()->rows(), 4u);
EXPECT_EQ(m44->As<ast::type::MatrixType>()->columns(), 4u);
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
} }

View File

@ -621,8 +621,8 @@ TEST_P(MatrixTest, Parse) {
EXPECT_FALSE(t.errored); EXPECT_FALSE(t.errored);
ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_NE(t.value, nullptr) << p->error();
ASSERT_FALSE(p->has_error()); ASSERT_FALSE(p->has_error());
EXPECT_TRUE(t->IsMatrix()); EXPECT_TRUE(t->Is<ast::type::MatrixType>());
auto* mat = t->AsMatrix(); auto* mat = t->As<ast::type::MatrixType>();
EXPECT_EQ(mat->rows(), params.rows); EXPECT_EQ(mat->rows(), params.rows);
EXPECT_EQ(mat->columns(), params.columns); EXPECT_EQ(mat->columns(), params.columns);
} }

View File

@ -184,8 +184,8 @@ bool BoundArrayAccessorsTransform::ProcessArrayAccessor(
} }
auto* ret_type = expr->array()->result_type()->UnwrapAll(); auto* ret_type = expr->array()->result_type()->UnwrapAll();
if (!ret_type->Is<ast::type::ArrayType>() && !ret_type->IsMatrix() && if (!ret_type->Is<ast::type::ArrayType>() &&
!ret_type->IsVector()) { !ret_type->Is<ast::type::MatrixType>() && !ret_type->IsVector()) {
return true; return true;
} }
@ -204,7 +204,7 @@ bool BoundArrayAccessorsTransform::ProcessArrayAccessor(
} else { } else {
// The row accessor would have been an embedded array accessor and already // The row accessor would have been an embedded array accessor and already
// handled, so we just need to do columns here. // handled, so we just need to do columns here.
uint32_t size = ret_type->AsMatrix()->columns(); uint32_t size = ret_type->As<ast::type::MatrixType>()->columns();
if (!ProcessAccessExpression(expr, size)) { if (!ProcessAccessExpression(expr, size)) {
return false; return false;
} }

View File

@ -337,8 +337,8 @@ bool TypeDeterminer::DetermineArrayAccessor(
ret = parent_type->As<ast::type::ArrayType>()->type(); ret = parent_type->As<ast::type::ArrayType>()->type();
} else if (parent_type->IsVector()) { } else if (parent_type->IsVector()) {
ret = parent_type->AsVector()->type(); ret = parent_type->AsVector()->type();
} else if (parent_type->IsMatrix()) { } else if (parent_type->Is<ast::type::MatrixType>()) {
auto* m = parent_type->AsMatrix(); auto* m = parent_type->As<ast::type::MatrixType>();
ret = mod_->create<ast::type::VectorType>(m->type(), m->rows()); ret = mod_->create<ast::type::VectorType>(m->type(), m->rows());
} else { } else {
set_error(expr->source(), "invalid parent type (" + set_error(expr->source(), "invalid parent type (" +
@ -790,7 +790,7 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
} }
break; break;
case IntrinsicDataType::kMatrix: case IntrinsicDataType::kMatrix:
if (!result_types.back()->IsMatrix()) { if (!result_types.back()->Is<ast::type::MatrixType>()) {
set_error(expr->source(), "incorrect type for " + ident->name() + set_error(expr->source(), "incorrect type for " + ident->name() +
". Requires matrix value"); ". Requires matrix value");
return false; return false;
@ -819,7 +819,8 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
} }
// The determinant returns the component type of the columns // The determinant returns the component type of the columns
if (ident->intrinsic() == ast::Intrinsic::kDeterminant) { if (ident->intrinsic() == ast::Intrinsic::kDeterminant) {
expr->func()->set_result_type(result_types[0]->AsMatrix()->type()); expr->func()->set_result_type(
result_types[0]->As<ast::type::MatrixType>()->type());
return true; return true;
} }
expr->func()->set_result_type(result_types[0]); expr->func()->set_result_type(result_types[0]);
@ -1111,23 +1112,25 @@ bool TypeDeterminer::DetermineBinary(ast::BinaryExpression* expr) {
// Note, the ordering here matters. The later checks depend on the prior // Note, the ordering here matters. The later checks depend on the prior
// checks having been done. // checks having been done.
if (lhs_type->IsMatrix() && rhs_type->IsMatrix()) { if (lhs_type->Is<ast::type::MatrixType>() &&
rhs_type->Is<ast::type::MatrixType>()) {
expr->set_result_type(mod_->create<ast::type::MatrixType>( expr->set_result_type(mod_->create<ast::type::MatrixType>(
lhs_type->AsMatrix()->type(), lhs_type->AsMatrix()->rows(), lhs_type->As<ast::type::MatrixType>()->type(),
rhs_type->AsMatrix()->columns())); lhs_type->As<ast::type::MatrixType>()->rows(),
rhs_type->As<ast::type::MatrixType>()->columns()));
} else if (lhs_type->IsMatrix() && rhs_type->IsVector()) { } else if (lhs_type->Is<ast::type::MatrixType>() && rhs_type->IsVector()) {
auto* mat = lhs_type->AsMatrix(); auto* mat = lhs_type->As<ast::type::MatrixType>();
expr->set_result_type( expr->set_result_type(
mod_->create<ast::type::VectorType>(mat->type(), mat->rows())); mod_->create<ast::type::VectorType>(mat->type(), mat->rows()));
} else if (lhs_type->IsVector() && rhs_type->IsMatrix()) { } else if (lhs_type->IsVector() && rhs_type->Is<ast::type::MatrixType>()) {
auto* mat = rhs_type->AsMatrix(); auto* mat = rhs_type->As<ast::type::MatrixType>();
expr->set_result_type( expr->set_result_type(
mod_->create<ast::type::VectorType>(mat->type(), mat->columns())); mod_->create<ast::type::VectorType>(mat->type(), mat->columns()));
} else if (lhs_type->IsMatrix()) { } else if (lhs_type->Is<ast::type::MatrixType>()) {
// matrix * scalar // matrix * scalar
expr->set_result_type(lhs_type); expr->set_result_type(lhs_type);
} else if (rhs_type->IsMatrix()) { } else if (rhs_type->Is<ast::type::MatrixType>()) {
// scalar * matrix // scalar * matrix
expr->set_result_type(rhs_type); expr->set_result_type(rhs_type);
} else if (lhs_type->IsVector() && rhs_type->IsVector()) { } else if (lhs_type->IsVector() && rhs_type->IsVector()) {

View File

@ -1385,9 +1385,9 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Matrix_Scalar) {
ASSERT_TRUE(td()->DetermineResultType(&expr)) << td()->error(); ASSERT_TRUE(td()->DetermineResultType(&expr)) << td()->error();
ASSERT_NE(expr.result_type(), nullptr); ASSERT_NE(expr.result_type(), nullptr);
ASSERT_TRUE(expr.result_type()->IsMatrix()); ASSERT_TRUE(expr.result_type()->Is<ast::type::MatrixType>());
auto* mat = expr.result_type()->AsMatrix(); auto* mat = expr.result_type()->As<ast::type::MatrixType>();
EXPECT_TRUE(mat->type()->Is<ast::type::F32Type>()); EXPECT_TRUE(mat->type()->Is<ast::type::F32Type>());
EXPECT_EQ(mat->rows(), 3u); EXPECT_EQ(mat->rows(), 3u);
EXPECT_EQ(mat->columns(), 2u); EXPECT_EQ(mat->columns(), 2u);
@ -1413,9 +1413,9 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Scalar_Matrix) {
ASSERT_TRUE(td()->DetermineResultType(&expr)) << td()->error(); ASSERT_TRUE(td()->DetermineResultType(&expr)) << td()->error();
ASSERT_NE(expr.result_type(), nullptr); ASSERT_NE(expr.result_type(), nullptr);
ASSERT_TRUE(expr.result_type()->IsMatrix()); ASSERT_TRUE(expr.result_type()->Is<ast::type::MatrixType>());
auto* mat = expr.result_type()->AsMatrix(); auto* mat = expr.result_type()->As<ast::type::MatrixType>();
EXPECT_TRUE(mat->type()->Is<ast::type::F32Type>()); EXPECT_TRUE(mat->type()->Is<ast::type::F32Type>());
EXPECT_EQ(mat->rows(), 3u); EXPECT_EQ(mat->rows(), 3u);
EXPECT_EQ(mat->columns(), 2u); EXPECT_EQ(mat->columns(), 2u);
@ -1494,9 +1494,9 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Matrix_Matrix) {
ASSERT_TRUE(td()->DetermineResultType(&expr)) << td()->error(); ASSERT_TRUE(td()->DetermineResultType(&expr)) << td()->error();
ASSERT_NE(expr.result_type(), nullptr); ASSERT_NE(expr.result_type(), nullptr);
ASSERT_TRUE(expr.result_type()->IsMatrix()); ASSERT_TRUE(expr.result_type()->Is<ast::type::MatrixType>());
auto* mat = expr.result_type()->AsMatrix(); auto* mat = expr.result_type()->As<ast::type::MatrixType>();
EXPECT_TRUE(mat->type()->Is<ast::type::F32Type>()); EXPECT_TRUE(mat->type()->Is<ast::type::F32Type>());
EXPECT_EQ(mat->rows(), 4u); EXPECT_EQ(mat->rows(), 4u);
EXPECT_EQ(mat->columns(), 4u); EXPECT_EQ(mat->columns(), 4u);
@ -2018,9 +2018,9 @@ TEST_F(TypeDeterminerTest, Intrinsic_OuterProduct) {
EXPECT_TRUE(td()->DetermineResultType(&expr)); EXPECT_TRUE(td()->DetermineResultType(&expr));
ASSERT_NE(expr.result_type(), nullptr); ASSERT_NE(expr.result_type(), nullptr);
ASSERT_TRUE(expr.result_type()->IsMatrix()); ASSERT_TRUE(expr.result_type()->Is<ast::type::MatrixType>());
auto* mat = expr.result_type()->AsMatrix(); auto* mat = expr.result_type()->As<ast::type::MatrixType>();
EXPECT_TRUE(mat->type()->Is<ast::type::F32Type>()); EXPECT_TRUE(mat->type()->Is<ast::type::F32Type>());
EXPECT_EQ(mat->rows(), 3u); EXPECT_EQ(mat->rows(), 3u);
EXPECT_EQ(mat->columns(), 2u); EXPECT_EQ(mat->columns(), 2u);

View File

@ -373,9 +373,10 @@ bool GeneratorImpl::EmitBinary(std::ostream& pre,
// Multiplying by a matrix requires the use of `mul` in order to get the // Multiplying by a matrix requires the use of `mul` in order to get the
// type of multiply we desire. // type of multiply we desire.
if (expr->op() == ast::BinaryOp::kMultiply && if (expr->op() == ast::BinaryOp::kMultiply &&
((lhs_type->IsVector() && rhs_type->IsMatrix()) || ((lhs_type->IsVector() && rhs_type->Is<ast::type::MatrixType>()) ||
(lhs_type->IsMatrix() && rhs_type->IsVector()) || (lhs_type->Is<ast::type::MatrixType>() && rhs_type->IsVector()) ||
(lhs_type->IsMatrix() && rhs_type->IsMatrix()))) { (lhs_type->Is<ast::type::MatrixType>() &&
rhs_type->Is<ast::type::MatrixType>()))) {
out << "mul("; out << "mul(";
if (!EmitExpression(pre, out, expr->lhs())) { if (!EmitExpression(pre, out, expr->lhs())) {
return false; return false;
@ -1553,8 +1554,8 @@ bool GeneratorImpl::EmitZeroValue(std::ostream& out, ast::type::Type* type) {
out << "0u"; out << "0u";
} else if (type->IsVector()) { } else if (type->IsVector()) {
return EmitZeroValue(out, type->AsVector()->type()); return EmitZeroValue(out, type->AsVector()->type());
} else if (type->IsMatrix()) { } else if (type->Is<ast::type::MatrixType>()) {
auto* mat = type->AsMatrix(); auto* mat = type->As<ast::type::MatrixType>();
for (uint32_t i = 0; i < (mat->rows() * mat->columns()); i++) { for (uint32_t i = 0; i < (mat->rows() * mat->columns()); i++) {
if (i != 0) { if (i != 0) {
out << ", "; out << ", ";
@ -1726,8 +1727,8 @@ std::string GeneratorImpl::generate_storage_buffer_index_expression(
// or u32 which are all 4 bytes. When we get f16 or other types we'll // or u32 which are all 4 bytes. When we get f16 or other types we'll
// have to ask the type for the byte size. // have to ask the type for the byte size.
out << "4"; out << "4";
} else if (ary_type->IsMatrix()) { } else if (ary_type->Is<ast::type::MatrixType>()) {
auto* mat = ary_type->AsMatrix(); auto* mat = ary_type->As<ast::type::MatrixType>();
if (mat->columns() == 2) { if (mat->columns() == 2) {
out << "8"; out << "8";
} else { } else {
@ -1770,13 +1771,15 @@ bool GeneratorImpl::EmitStorageBufferAccessor(std::ostream& pre,
std::string access_method = is_store ? "Store" : "Load"; std::string access_method = is_store ? "Store" : "Load";
if (result_type->IsVector()) { if (result_type->IsVector()) {
access_method += std::to_string(result_type->AsVector()->size()); access_method += std::to_string(result_type->AsVector()->size());
} else if (result_type->IsMatrix()) { } else if (result_type->Is<ast::type::MatrixType>()) {
access_method += std::to_string(result_type->AsMatrix()->rows()); access_method +=
std::to_string(result_type->As<ast::type::MatrixType>()->rows());
} }
// If we aren't storing then we need to put in the outer cast. // If we aren't storing then we need to put in the outer cast.
if (!is_store) { if (!is_store) {
if (result_type->is_float_scalar_or_vector() || result_type->IsMatrix()) { if (result_type->is_float_scalar_or_vector() ||
result_type->Is<ast::type::MatrixType>()) {
out << "asfloat("; out << "asfloat(";
} else if (result_type->is_signed_scalar_or_vector()) { } else if (result_type->is_signed_scalar_or_vector()) {
out << "asint("; out << "asint(";
@ -1796,8 +1799,8 @@ bool GeneratorImpl::EmitStorageBufferAccessor(std::ostream& pre,
return false; return false;
} }
if (result_type->IsMatrix()) { if (result_type->Is<ast::type::MatrixType>()) {
auto* mat = result_type->AsMatrix(); auto* mat = result_type->As<ast::type::MatrixType>();
// TODO(dsinclair): This is assuming 4 byte elements. Will need to be fixed // TODO(dsinclair): This is assuming 4 byte elements. Will need to be fixed
// if we get matrixes of f16 or f64. // if we get matrixes of f16 or f64.
@ -2064,8 +2067,8 @@ bool GeneratorImpl::EmitType(std::ostream& out,
out << "float"; out << "float";
} else if (type->Is<ast::type::I32Type>()) { } else if (type->Is<ast::type::I32Type>()) {
out << "int"; out << "int";
} else if (type->IsMatrix()) { } else if (type->Is<ast::type::MatrixType>()) {
auto* mat = type->AsMatrix(); auto* mat = type->As<ast::type::MatrixType>();
if (!EmitType(out, mat->type(), "")) { if (!EmitType(out, mat->type(), "")) {
return false; return false;
} }

View File

@ -204,8 +204,8 @@ uint32_t GeneratorImpl::calculate_alignment_size(ast::type::Type* type) {
type->IsU32()) { type->IsU32()) {
return 4; return 4;
} }
if (type->IsMatrix()) { if (type->Is<ast::type::MatrixType>()) {
auto* mat = type->AsMatrix(); auto* mat = type->As<ast::type::MatrixType>();
// TODO(dsinclair): Handle MatrixStride // TODO(dsinclair): Handle MatrixStride
// https://github.com/gpuweb/gpuweb/issues/773 // https://github.com/gpuweb/gpuweb/issues/773
uint32_t type_size = calculate_alignment_size(mat->type()); uint32_t type_size = calculate_alignment_size(mat->type());
@ -939,8 +939,8 @@ bool GeneratorImpl::EmitZeroValue(ast::type::Type* type) {
out_ << "0u"; out_ << "0u";
} else if (type->IsVector()) { } else if (type->IsVector()) {
return EmitZeroValue(type->AsVector()->type()); return EmitZeroValue(type->AsVector()->type());
} else if (type->IsMatrix()) { } else if (type->Is<ast::type::MatrixType>()) {
return EmitZeroValue(type->AsMatrix()->type()); return EmitZeroValue(type->As<ast::type::MatrixType>()->type());
} else if (type->Is<ast::type::ArrayType>()) { } else if (type->Is<ast::type::ArrayType>()) {
out_ << "{"; out_ << "{";
if (!EmitZeroValue(type->As<ast::type::ArrayType>()->type())) { if (!EmitZeroValue(type->As<ast::type::ArrayType>()->type())) {
@ -1819,8 +1819,8 @@ bool GeneratorImpl::EmitType(ast::type::Type* type, const std::string& name) {
out_ << "float"; out_ << "float";
} else if (type->Is<ast::type::I32Type>()) { } else if (type->Is<ast::type::I32Type>()) {
out_ << "int"; out_ << "int";
} else if (type->IsMatrix()) { } else if (type->Is<ast::type::MatrixType>()) {
auto* mat = type->AsMatrix(); auto* mat = type->As<ast::type::MatrixType>();
if (!EmitType(mat->type(), "")) { if (!EmitType(mat->type(), "")) {
return false; return false;
} }

View File

@ -150,7 +150,8 @@ ast::type::MatrixType* GetNestedMatrixType(ast::type::Type* type) {
while (type->Is<ast::type::ArrayType>()) { while (type->Is<ast::type::ArrayType>()) {
type = type->As<ast::type::ArrayType>()->type(); type = type->As<ast::type::ArrayType>()->type();
} }
return type->IsMatrix() ? type->AsMatrix() : nullptr; return type->Is<ast::type::MatrixType>() ? type->As<ast::type::MatrixType>()
: nullptr;
} }
uint32_t intrinsic_to_glsl_method(ast::type::Type* type, uint32_t intrinsic_to_glsl_method(ast::type::Type* type,
@ -1203,8 +1204,8 @@ bool Builder::is_constructor_const(ast::Expression* expr, bool is_global_init) {
ast::type::Type* subtype = result_type->UnwrapAll(); ast::type::Type* subtype = result_type->UnwrapAll();
if (subtype->IsVector()) { if (subtype->IsVector()) {
subtype = subtype->AsVector()->type()->UnwrapAll(); subtype = subtype->AsVector()->type()->UnwrapAll();
} else if (subtype->IsMatrix()) { } else if (subtype->Is<ast::type::MatrixType>()) {
subtype = subtype->AsMatrix()->type()->UnwrapAll(); subtype = subtype->As<ast::type::MatrixType>()->type()->UnwrapAll();
} else if (subtype->Is<ast::type::ArrayType>()) { } else if (subtype->Is<ast::type::ArrayType>()) {
subtype = subtype->As<ast::type::ArrayType>()->type()->UnwrapAll(); subtype = subtype->As<ast::type::ArrayType>()->type()->UnwrapAll();
} else if (subtype->IsStruct()) { } else if (subtype->IsStruct()) {
@ -1280,7 +1281,7 @@ uint32_t Builder::GenerateTypeConstructorExpression(
// If the result and value types are the same we can just use the object. // If the result and value types are the same we can just use the object.
// If the result is not a vector then we should have validated that the // If the result is not a vector then we should have validated that the
// value type is a correctly sized vector so we can just use it directly. // value type is a correctly sized vector so we can just use it directly.
if (result_type == value_type || result_type->IsMatrix() || if (result_type == value_type || result_type->Is<ast::type::MatrixType>() ||
result_type->Is<ast::type::ArrayType>() || result_type->IsStruct()) { result_type->Is<ast::type::ArrayType>() || result_type->IsStruct()) {
out << "_" << id; out << "_" << id;
@ -2426,8 +2427,8 @@ uint32_t Builder::GenerateTypeIfNeeded(ast::type::Type* type) {
push_type(spv::Op::OpTypeFloat, {result, Operand::Int(32)}); push_type(spv::Op::OpTypeFloat, {result, Operand::Int(32)});
} else if (type->Is<ast::type::I32Type>()) { } else if (type->Is<ast::type::I32Type>()) {
push_type(spv::Op::OpTypeInt, {result, Operand::Int(32), Operand::Int(1)}); push_type(spv::Op::OpTypeInt, {result, Operand::Int(32), Operand::Int(1)});
} else if (type->IsMatrix()) { } else if (type->Is<ast::type::MatrixType>()) {
if (!GenerateMatrixType(type->AsMatrix(), result)) { if (!GenerateMatrixType(type->As<ast::type::MatrixType>(), result)) {
return 0; return 0;
} }
} else if (type->IsPointer()) { } else if (type->IsPointer()) {

View File

@ -27,8 +27,9 @@
#include "src/ast/literal.h" #include "src/ast/literal.h"
#include "src/ast/module.h" #include "src/ast/module.h"
#include "src/ast/struct_member.h" #include "src/ast/struct_member.h"
#include "src/ast/type/array_type.h"
#include "src/ast/type/access_control_type.h" #include "src/ast/type/access_control_type.h"
#include "src/ast/type/array_type.h"
#include "src/ast/type/matrix_type.h"
#include "src/ast/type/storage_texture_type.h" #include "src/ast/type/storage_texture_type.h"
#include "src/ast/type_constructor_expression.h" #include "src/ast/type_constructor_expression.h"
#include "src/context.h" #include "src/context.h"

View File

@ -439,8 +439,8 @@ bool GeneratorImpl::EmitType(ast::type::Type* type) {
out_ << "f32"; out_ << "f32";
} else if (type->Is<ast::type::I32Type>()) { } else if (type->Is<ast::type::I32Type>()) {
out_ << "i32"; out_ << "i32";
} else if (type->IsMatrix()) { } else if (type->Is<ast::type::MatrixType>()) {
auto* mat = type->AsMatrix(); auto* mat = type->As<ast::type::MatrixType>();
out_ << "mat" << mat->columns() << "x" << mat->rows() << "<"; out_ << "mat" << mat->columns() << "x" << mat->rows() << "<";
if (!EmitType(mat->type())) { if (!EmitType(mat->type())) {
return false; return false;