mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-07-04 12:16:10 +00:00
ast/type: Remove Type suffix from all types
They already exist in a `ast::type` namespace, so `ast::type::BlahType` is just stuttering. This is more important now that Is<> and As<> use the full type name. Change-Id: I7c661fe58cdc33ba7e9a95c82c996a799786661f Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34321 Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
03ae9a397f
commit
f1b0e1ee57
@ -19,15 +19,15 @@ namespace ast {
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, AccessControl access) {
|
||||
switch (access) {
|
||||
case AccessControl::kReadOnly: {
|
||||
case ast::AccessControl::kReadOnly: {
|
||||
out << "read_only";
|
||||
break;
|
||||
}
|
||||
case AccessControl::kReadWrite: {
|
||||
case ast::AccessControl::kReadWrite: {
|
||||
out << "read_write";
|
||||
break;
|
||||
}
|
||||
case AccessControl::kWriteOnly: {
|
||||
case ast::AccessControl::kWriteOnly: {
|
||||
out << "write_only";
|
||||
break;
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ class AccessDecoration : public Castable<AccessDecoration, TypeDecoration> {
|
||||
void to_str(std::ostream& out, size_t indent) const override;
|
||||
|
||||
private:
|
||||
AccessControl value_ = AccessControl::kReadWrite;
|
||||
AccessControl value_ = ast::AccessControl::kReadWrite;
|
||||
};
|
||||
|
||||
} // namespace ast
|
||||
|
@ -25,17 +25,17 @@ namespace {
|
||||
using AccessDecorationTest = TestHelper;
|
||||
|
||||
TEST_F(AccessDecorationTest, Creation) {
|
||||
AccessDecoration d{AccessControl::kWriteOnly, Source{}};
|
||||
EXPECT_EQ(AccessControl::kWriteOnly, d.value());
|
||||
AccessDecoration d{ast::AccessControl::kWriteOnly, Source{}};
|
||||
EXPECT_EQ(ast::AccessControl::kWriteOnly, d.value());
|
||||
}
|
||||
|
||||
TEST_F(AccessDecorationTest, Is) {
|
||||
AccessDecoration d{AccessControl::kReadWrite, Source{}};
|
||||
AccessDecoration d{ast::AccessControl::kReadWrite, Source{}};
|
||||
EXPECT_FALSE(d.IsAccess());
|
||||
}
|
||||
|
||||
TEST_F(AccessDecorationTest, ToStr) {
|
||||
AccessDecoration d{AccessControl::kReadOnly, Source{}};
|
||||
AccessDecoration d{ast::AccessControl::kReadOnly, Source{}};
|
||||
std::ostringstream out;
|
||||
d.to_str(out, 0);
|
||||
EXPECT_EQ(out.str(), R"(AccessDecoration{read}
|
||||
|
@ -25,7 +25,7 @@ namespace {
|
||||
using BitcastExpressionTest = TestHelper;
|
||||
|
||||
TEST_F(BitcastExpressionTest, Create) {
|
||||
type::F32Type f32;
|
||||
type::F32 f32;
|
||||
auto* expr = create<IdentifierExpression>("expr");
|
||||
|
||||
BitcastExpression exp(&f32, expr);
|
||||
@ -34,7 +34,7 @@ TEST_F(BitcastExpressionTest, Create) {
|
||||
}
|
||||
|
||||
TEST_F(BitcastExpressionTest, CreateWithSource) {
|
||||
type::F32Type f32;
|
||||
type::F32 f32;
|
||||
auto* expr = create<IdentifierExpression>("expr");
|
||||
|
||||
BitcastExpression exp(Source{Source::Location{20, 2}}, &f32, expr);
|
||||
@ -49,7 +49,7 @@ TEST_F(BitcastExpressionTest, IsBitcast) {
|
||||
}
|
||||
|
||||
TEST_F(BitcastExpressionTest, IsValid) {
|
||||
type::F32Type f32;
|
||||
type::F32 f32;
|
||||
auto* expr = create<IdentifierExpression>("expr");
|
||||
|
||||
BitcastExpression exp(&f32, expr);
|
||||
@ -65,7 +65,7 @@ TEST_F(BitcastExpressionTest, IsValid_MissingType) {
|
||||
}
|
||||
|
||||
TEST_F(BitcastExpressionTest, IsValid_MissingExpr) {
|
||||
type::F32Type f32;
|
||||
type::F32 f32;
|
||||
|
||||
BitcastExpression exp;
|
||||
exp.set_type(&f32);
|
||||
@ -73,14 +73,14 @@ TEST_F(BitcastExpressionTest, IsValid_MissingExpr) {
|
||||
}
|
||||
|
||||
TEST_F(BitcastExpressionTest, IsValid_InvalidExpr) {
|
||||
type::F32Type f32;
|
||||
type::F32 f32;
|
||||
auto* expr = create<IdentifierExpression>("");
|
||||
BitcastExpression e(&f32, expr);
|
||||
EXPECT_FALSE(e.IsValid());
|
||||
}
|
||||
|
||||
TEST_F(BitcastExpressionTest, ToStr) {
|
||||
type::F32Type f32;
|
||||
type::F32 f32;
|
||||
auto* expr = create<IdentifierExpression>("expr");
|
||||
|
||||
BitcastExpression exp(&f32, expr);
|
||||
|
@ -28,7 +28,7 @@ namespace {
|
||||
using BoolLiteralTest = TestHelper;
|
||||
|
||||
TEST_F(BoolLiteralTest, True) {
|
||||
type::BoolType bool_type;
|
||||
type::Bool bool_type;
|
||||
BoolLiteral b{&bool_type, true};
|
||||
ASSERT_TRUE(b.Is<BoolLiteral>());
|
||||
ASSERT_TRUE(b.IsTrue());
|
||||
@ -36,7 +36,7 @@ TEST_F(BoolLiteralTest, True) {
|
||||
}
|
||||
|
||||
TEST_F(BoolLiteralTest, False) {
|
||||
type::BoolType bool_type;
|
||||
type::Bool bool_type;
|
||||
BoolLiteral b{&bool_type, false};
|
||||
ASSERT_TRUE(b.Is<BoolLiteral>());
|
||||
ASSERT_FALSE(b.IsTrue());
|
||||
@ -44,7 +44,7 @@ TEST_F(BoolLiteralTest, False) {
|
||||
}
|
||||
|
||||
TEST_F(BoolLiteralTest, Is) {
|
||||
type::BoolType bool_type;
|
||||
type::Bool bool_type;
|
||||
BoolLiteral b{&bool_type, false};
|
||||
Literal* l = &b;
|
||||
EXPECT_TRUE(l->Is<BoolLiteral>());
|
||||
@ -56,7 +56,7 @@ TEST_F(BoolLiteralTest, Is) {
|
||||
}
|
||||
|
||||
TEST_F(BoolLiteralTest, ToStr) {
|
||||
type::BoolType bool_type;
|
||||
type::Bool bool_type;
|
||||
BoolLiteral t{&bool_type, true};
|
||||
BoolLiteral f{&bool_type, false};
|
||||
|
||||
|
@ -18,11 +18,11 @@ namespace tint {
|
||||
namespace ast {
|
||||
|
||||
TypesBuilder::TypesBuilder(Module* mod)
|
||||
: bool_(mod->create<type::BoolType>()),
|
||||
f32(mod->create<type::F32Type>()),
|
||||
i32(mod->create<type::I32Type>()),
|
||||
u32(mod->create<type::U32Type>()),
|
||||
void_(mod->create<type::VoidType>()),
|
||||
: bool_(mod->create<type::Bool>()),
|
||||
f32(mod->create<type::F32>()),
|
||||
i32(mod->create<type::I32>()),
|
||||
u32(mod->create<type::U32>()),
|
||||
void_(mod->create<type::Void>()),
|
||||
mod_(mod) {}
|
||||
|
||||
Builder::Builder(Context* c, Module* m) : ctx(c), mod(m), ty(m) {}
|
||||
|
@ -52,15 +52,15 @@ class TypesBuilder {
|
||||
explicit TypesBuilder(Module* mod);
|
||||
|
||||
/// A boolean type
|
||||
type::BoolType* const bool_;
|
||||
type::Bool* const bool_;
|
||||
/// A f32 type
|
||||
type::F32Type* const f32;
|
||||
type::F32* const f32;
|
||||
/// A i32 type
|
||||
type::I32Type* const i32;
|
||||
type::I32* const i32;
|
||||
/// A u32 type
|
||||
type::U32Type* const u32;
|
||||
type::U32* const u32;
|
||||
/// A void type
|
||||
type::VoidType* const void_;
|
||||
type::Void* const void_;
|
||||
|
||||
/// @return the tint AST type for the C type `T`.
|
||||
template <typename T>
|
||||
@ -70,86 +70,86 @@ class TypesBuilder {
|
||||
|
||||
/// @return the tint AST type for a 2-element vector of the C type `T`.
|
||||
template <typename T>
|
||||
type::VectorType* vec2() const {
|
||||
return mod_->create<type::VectorType>(Of<T>(), 2);
|
||||
type::Vector* vec2() const {
|
||||
return mod_->create<type::Vector>(Of<T>(), 2);
|
||||
}
|
||||
|
||||
/// @return the tint AST type for a 3-element vector of the C type `T`.
|
||||
template <typename T>
|
||||
type::VectorType* vec3() const {
|
||||
return mod_->create<type::VectorType>(Of<T>(), 3);
|
||||
type::Vector* vec3() const {
|
||||
return mod_->create<type::Vector>(Of<T>(), 3);
|
||||
}
|
||||
|
||||
/// @return the tint AST type for a 4-element vector of the C type `T`.
|
||||
template <typename T>
|
||||
type::Type* vec4() const {
|
||||
return mod_->create<type::VectorType>(Of<T>(), 4);
|
||||
return mod_->create<type::Vector>(Of<T>(), 4);
|
||||
}
|
||||
|
||||
/// @return the tint AST type for a 2x3 matrix of the C type `T`.
|
||||
template <typename T>
|
||||
type::MatrixType* mat2x2() const {
|
||||
return mod_->create<type::MatrixType>(Of<T>(), 2, 2);
|
||||
type::Matrix* mat2x2() const {
|
||||
return mod_->create<type::Matrix>(Of<T>(), 2, 2);
|
||||
}
|
||||
|
||||
/// @return the tint AST type for a 2x3 matrix of the C type `T`.
|
||||
template <typename T>
|
||||
type::MatrixType* mat2x3() const {
|
||||
return mod_->create<type::MatrixType>(Of<T>(), 3, 2);
|
||||
type::Matrix* mat2x3() const {
|
||||
return mod_->create<type::Matrix>(Of<T>(), 3, 2);
|
||||
}
|
||||
|
||||
/// @return the tint AST type for a 2x4 matrix of the C type `T`.
|
||||
template <typename T>
|
||||
type::MatrixType* mat2x4() const {
|
||||
return mod_->create<type::MatrixType>(Of<T>(), 4, 2);
|
||||
type::Matrix* mat2x4() const {
|
||||
return mod_->create<type::Matrix>(Of<T>(), 4, 2);
|
||||
}
|
||||
|
||||
/// @return the tint AST type for a 3x2 matrix of the C type `T`.
|
||||
template <typename T>
|
||||
type::MatrixType* mat3x2() const {
|
||||
return mod_->create<type::MatrixType>(Of<T>(), 2, 3);
|
||||
type::Matrix* mat3x2() const {
|
||||
return mod_->create<type::Matrix>(Of<T>(), 2, 3);
|
||||
}
|
||||
|
||||
/// @return the tint AST type for a 3x3 matrix of the C type `T`.
|
||||
template <typename T>
|
||||
type::MatrixType* mat3x3() const {
|
||||
return mod_->create<type::MatrixType>(Of<T>(), 3, 3);
|
||||
type::Matrix* mat3x3() const {
|
||||
return mod_->create<type::Matrix>(Of<T>(), 3, 3);
|
||||
}
|
||||
|
||||
/// @return the tint AST type for a 3x4 matrix of the C type `T`.
|
||||
template <typename T>
|
||||
type::MatrixType* mat3x4() const {
|
||||
return mod_->create<type::MatrixType>(Of<T>(), 4, 3);
|
||||
type::Matrix* mat3x4() const {
|
||||
return mod_->create<type::Matrix>(Of<T>(), 4, 3);
|
||||
}
|
||||
|
||||
/// @return the tint AST type for a 4x2 matrix of the C type `T`.
|
||||
template <typename T>
|
||||
type::MatrixType* mat4x2() const {
|
||||
return mod_->create<type::MatrixType>(Of<T>(), 2, 4);
|
||||
type::Matrix* mat4x2() const {
|
||||
return mod_->create<type::Matrix>(Of<T>(), 2, 4);
|
||||
}
|
||||
|
||||
/// @return the tint AST type for a 4x3 matrix of the C type `T`.
|
||||
template <typename T>
|
||||
type::MatrixType* mat4x3() const {
|
||||
return mod_->create<type::MatrixType>(Of<T>(), 3, 4);
|
||||
type::Matrix* mat4x3() const {
|
||||
return mod_->create<type::Matrix>(Of<T>(), 3, 4);
|
||||
}
|
||||
|
||||
/// @return the tint AST type for a 4x4 matrix of the C type `T`.
|
||||
template <typename T>
|
||||
type::MatrixType* mat4x4() const {
|
||||
return mod_->create<type::MatrixType>(Of<T>(), 4, 4);
|
||||
type::Matrix* mat4x4() const {
|
||||
return mod_->create<type::Matrix>(Of<T>(), 4, 4);
|
||||
}
|
||||
|
||||
/// @param subtype the array element type
|
||||
/// @param n the array size. 0 represents unbounded
|
||||
/// @return the tint AST type for a array of size `n` of type `T`
|
||||
type::ArrayType* array(type::Type* subtype, uint32_t n) const {
|
||||
return mod_->create<type::ArrayType>(subtype, n);
|
||||
type::Array* array(type::Type* subtype, uint32_t n) const {
|
||||
return mod_->create<type::Array>(subtype, n);
|
||||
}
|
||||
|
||||
/// @return the tint AST type for an array of size `N` of type `T`
|
||||
template <typename T, int N = 0>
|
||||
type::ArrayType* array() const {
|
||||
type::Array* array() const {
|
||||
return array(Of<T>(), N);
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ namespace {
|
||||
using CaseStatementTest = TestHelper;
|
||||
|
||||
TEST_F(CaseStatementTest, Creation_i32) {
|
||||
type::I32Type i32;
|
||||
type::I32 i32;
|
||||
|
||||
CaseSelectorList b;
|
||||
auto* selector = create<SintLiteral>(&i32, 2);
|
||||
@ -47,7 +47,7 @@ TEST_F(CaseStatementTest, Creation_i32) {
|
||||
}
|
||||
|
||||
TEST_F(CaseStatementTest, Creation_u32) {
|
||||
type::U32Type u32;
|
||||
type::U32 u32;
|
||||
|
||||
CaseSelectorList b;
|
||||
auto* selector = create<SintLiteral>(&u32, 2);
|
||||
@ -65,7 +65,7 @@ TEST_F(CaseStatementTest, Creation_u32) {
|
||||
}
|
||||
|
||||
TEST_F(CaseStatementTest, Creation_WithSource) {
|
||||
type::I32Type i32;
|
||||
type::I32 i32;
|
||||
CaseSelectorList b;
|
||||
b.push_back(create<SintLiteral>(&i32, 2));
|
||||
|
||||
@ -88,7 +88,7 @@ TEST_F(CaseStatementTest, IsDefault_WithoutSelectors) {
|
||||
}
|
||||
|
||||
TEST_F(CaseStatementTest, IsDefault_WithSelectors) {
|
||||
type::I32Type i32;
|
||||
type::I32 i32;
|
||||
CaseSelectorList b;
|
||||
b.push_back(create<SintLiteral>(&i32, 2));
|
||||
|
||||
@ -108,7 +108,7 @@ TEST_F(CaseStatementTest, IsValid) {
|
||||
}
|
||||
|
||||
TEST_F(CaseStatementTest, IsValid_NullBodyStatement) {
|
||||
type::I32Type i32;
|
||||
type::I32 i32;
|
||||
CaseSelectorList b;
|
||||
b.push_back(create<SintLiteral>(&i32, 2));
|
||||
|
||||
@ -121,7 +121,7 @@ TEST_F(CaseStatementTest, IsValid_NullBodyStatement) {
|
||||
}
|
||||
|
||||
TEST_F(CaseStatementTest, IsValid_InvalidBodyStatement) {
|
||||
type::I32Type i32;
|
||||
type::I32 i32;
|
||||
CaseSelectorList b;
|
||||
b.push_back(create<SintLiteral>(&i32, 2));
|
||||
|
||||
@ -133,7 +133,7 @@ TEST_F(CaseStatementTest, IsValid_InvalidBodyStatement) {
|
||||
}
|
||||
|
||||
TEST_F(CaseStatementTest, ToStr_WithSelectors_i32) {
|
||||
type::I32Type i32;
|
||||
type::I32 i32;
|
||||
CaseSelectorList b;
|
||||
b.push_back(create<SintLiteral>(&i32, -2));
|
||||
|
||||
@ -150,7 +150,7 @@ TEST_F(CaseStatementTest, ToStr_WithSelectors_i32) {
|
||||
}
|
||||
|
||||
TEST_F(CaseStatementTest, ToStr_WithSelectors_u32) {
|
||||
type::U32Type u32;
|
||||
type::U32 u32;
|
||||
CaseSelectorList b;
|
||||
b.push_back(create<UintLiteral>(&u32, 2));
|
||||
|
||||
@ -167,7 +167,7 @@ TEST_F(CaseStatementTest, ToStr_WithSelectors_u32) {
|
||||
}
|
||||
|
||||
TEST_F(CaseStatementTest, ToStr_WithMultipleSelectors) {
|
||||
type::I32Type i32;
|
||||
type::I32 i32;
|
||||
|
||||
CaseSelectorList b;
|
||||
b.push_back(create<SintLiteral>(&i32, 1));
|
||||
|
@ -33,7 +33,7 @@ namespace {
|
||||
using DecoratedVariableTest = TestHelper;
|
||||
|
||||
TEST_F(DecoratedVariableTest, Creation) {
|
||||
type::I32Type t;
|
||||
type::I32 t;
|
||||
auto* var = create<Variable>("my_var", StorageClass::kFunction, &t);
|
||||
DecoratedVariable dv(var);
|
||||
|
||||
@ -48,7 +48,7 @@ TEST_F(DecoratedVariableTest, Creation) {
|
||||
|
||||
TEST_F(DecoratedVariableTest, CreationWithSource) {
|
||||
Source s{Source::Range{Source::Location{27, 4}, Source::Location{27, 5}}};
|
||||
type::F32Type t;
|
||||
type::F32 t;
|
||||
auto* var = create<Variable>(s, "i", StorageClass::kPrivate, &t);
|
||||
DecoratedVariable dv(var);
|
||||
|
||||
@ -62,7 +62,7 @@ TEST_F(DecoratedVariableTest, CreationWithSource) {
|
||||
}
|
||||
|
||||
TEST_F(DecoratedVariableTest, NoDecorations) {
|
||||
type::I32Type t;
|
||||
type::I32 t;
|
||||
auto* var = create<Variable>("my_var", StorageClass::kFunction, &t);
|
||||
DecoratedVariable dv(var);
|
||||
EXPECT_FALSE(dv.HasLocationDecoration());
|
||||
@ -71,7 +71,7 @@ TEST_F(DecoratedVariableTest, NoDecorations) {
|
||||
}
|
||||
|
||||
TEST_F(DecoratedVariableTest, WithDecorations) {
|
||||
type::F32Type t;
|
||||
type::F32 t;
|
||||
auto* var = create<Variable>("my_var", StorageClass::kFunction, &t);
|
||||
DecoratedVariable dv(var);
|
||||
|
||||
@ -88,7 +88,7 @@ TEST_F(DecoratedVariableTest, WithDecorations) {
|
||||
}
|
||||
|
||||
TEST_F(DecoratedVariableTest, ConstantId) {
|
||||
type::F32Type t;
|
||||
type::F32 t;
|
||||
auto* var = create<Variable>("my_var", StorageClass::kFunction, &t);
|
||||
DecoratedVariable dv(var);
|
||||
|
||||
@ -100,7 +100,7 @@ TEST_F(DecoratedVariableTest, ConstantId) {
|
||||
}
|
||||
|
||||
TEST_F(DecoratedVariableTest, IsValid) {
|
||||
type::I32Type t;
|
||||
type::I32 t;
|
||||
auto* var = create<Variable>("my_var", StorageClass::kNone, &t);
|
||||
DecoratedVariable dv(var);
|
||||
EXPECT_TRUE(dv.IsValid());
|
||||
@ -112,7 +112,7 @@ TEST_F(DecoratedVariableTest, IsDecorated) {
|
||||
}
|
||||
|
||||
TEST_F(DecoratedVariableTest, to_str) {
|
||||
type::F32Type t;
|
||||
type::F32 t;
|
||||
auto* var = create<Variable>("my_var", StorageClass::kFunction, &t);
|
||||
DecoratedVariable dv(var);
|
||||
dv.set_constructor(create<IdentifierExpression>("expr"));
|
||||
|
@ -28,7 +28,7 @@ namespace {
|
||||
using ElseStatementTest = TestHelper;
|
||||
|
||||
TEST_F(ElseStatementTest, Creation) {
|
||||
type::BoolType bool_type;
|
||||
type::Bool bool_type;
|
||||
auto* cond = create<ScalarConstructorExpression>(
|
||||
create<BoolLiteral>(&bool_type, true));
|
||||
auto* body = create<BlockStatement>();
|
||||
@ -55,7 +55,7 @@ TEST_F(ElseStatementTest, IsElse) {
|
||||
}
|
||||
|
||||
TEST_F(ElseStatementTest, HasCondition) {
|
||||
type::BoolType bool_type;
|
||||
type::Bool bool_type;
|
||||
auto* cond = create<ScalarConstructorExpression>(
|
||||
create<BoolLiteral>(&bool_type, true));
|
||||
ElseStatement e(cond, create<BlockStatement>());
|
||||
@ -104,7 +104,7 @@ TEST_F(ElseStatementTest, IsValid_InvalidBodyStatement) {
|
||||
}
|
||||
|
||||
TEST_F(ElseStatementTest, ToStr) {
|
||||
type::BoolType bool_type;
|
||||
type::Bool bool_type;
|
||||
auto* cond = create<ScalarConstructorExpression>(
|
||||
create<BoolLiteral>(&bool_type, true));
|
||||
auto* body = create<BlockStatement>();
|
||||
|
@ -33,23 +33,23 @@ class Expr : public Expression {
|
||||
using ExpressionTest = TestHelper;
|
||||
|
||||
TEST_F(ExpressionTest, set_result_type) {
|
||||
type::I32Type i32;
|
||||
type::I32 i32;
|
||||
|
||||
Expr e;
|
||||
e.set_result_type(&i32);
|
||||
ASSERT_NE(e.result_type(), nullptr);
|
||||
EXPECT_TRUE(e.result_type()->Is<type::I32Type>());
|
||||
EXPECT_TRUE(e.result_type()->Is<type::I32>());
|
||||
}
|
||||
|
||||
TEST_F(ExpressionTest, set_result_type_alias) {
|
||||
type::I32Type i32;
|
||||
type::AliasType a("a", &i32);
|
||||
type::AliasType b("b", &a);
|
||||
type::I32 i32;
|
||||
type::Alias a("a", &i32);
|
||||
type::Alias b("b", &a);
|
||||
|
||||
Expr e;
|
||||
e.set_result_type(&b);
|
||||
ASSERT_NE(e.result_type(), nullptr);
|
||||
EXPECT_TRUE(e.result_type()->Is<type::I32Type>());
|
||||
EXPECT_TRUE(e.result_type()->Is<type::I32>());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -28,14 +28,14 @@ namespace {
|
||||
using FloatLiteralTest = TestHelper;
|
||||
|
||||
TEST_F(FloatLiteralTest, Value) {
|
||||
type::F32Type f32;
|
||||
type::F32 f32;
|
||||
FloatLiteral f{&f32, 47.2f};
|
||||
ASSERT_TRUE(f.Is<FloatLiteral>());
|
||||
EXPECT_EQ(f.value(), 47.2f);
|
||||
}
|
||||
|
||||
TEST_F(FloatLiteralTest, Is) {
|
||||
type::F32Type f32;
|
||||
type::F32 f32;
|
||||
FloatLiteral f{&f32, 42.f};
|
||||
Literal* l = &f;
|
||||
EXPECT_FALSE(l->Is<BoolLiteral>());
|
||||
@ -47,14 +47,14 @@ TEST_F(FloatLiteralTest, Is) {
|
||||
}
|
||||
|
||||
TEST_F(FloatLiteralTest, ToStr) {
|
||||
type::F32Type f32;
|
||||
type::F32 f32;
|
||||
FloatLiteral f{&f32, 42.1f};
|
||||
|
||||
EXPECT_EQ(f.to_str(), "42.099998");
|
||||
}
|
||||
|
||||
TEST_F(FloatLiteralTest, ToName) {
|
||||
type::F32Type f32;
|
||||
type::F32 f32;
|
||||
FloatLiteral f{&f32, 42.1f};
|
||||
EXPECT_EQ(f.name(), "__float42.0999985");
|
||||
}
|
||||
|
@ -282,9 +282,8 @@ Function::ReferencedSamplerVariablesImpl(type::SamplerKind kind) const {
|
||||
|
||||
for (auto* var : referenced_module_variables()) {
|
||||
auto* unwrapped_type = var->type()->UnwrapIfNeeded();
|
||||
if (!var->Is<DecoratedVariable>() ||
|
||||
!unwrapped_type->Is<type::SamplerType>() ||
|
||||
unwrapped_type->As<type::SamplerType>()->kind() != kind) {
|
||||
if (!var->Is<DecoratedVariable>() || !unwrapped_type->Is<type::Sampler>() ||
|
||||
unwrapped_type->As<type::Sampler>()->kind() != kind) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -312,14 +311,12 @@ Function::ReferencedSampledTextureVariablesImpl(bool multisampled) const {
|
||||
|
||||
for (auto* var : referenced_module_variables()) {
|
||||
auto* unwrapped_type = var->type()->UnwrapIfNeeded();
|
||||
if (!var->Is<DecoratedVariable>() ||
|
||||
!unwrapped_type->Is<type::TextureType>()) {
|
||||
if (!var->Is<DecoratedVariable>() || !unwrapped_type->Is<type::Texture>()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((multisampled &&
|
||||
!unwrapped_type->Is<type::MultisampledTextureType>()) ||
|
||||
(!multisampled && !unwrapped_type->Is<type::SampledTextureType>())) {
|
||||
if ((multisampled && !unwrapped_type->Is<type::MultisampledTexture>()) ||
|
||||
(!multisampled && !unwrapped_type->Is<type::SampledTexture>())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -33,8 +33,8 @@ namespace {
|
||||
using FunctionTest = TestHelper;
|
||||
|
||||
TEST_F(FunctionTest, Creation) {
|
||||
type::VoidType void_type;
|
||||
type::I32Type i32;
|
||||
type::Void void_type;
|
||||
type::I32 i32;
|
||||
|
||||
VariableList params;
|
||||
params.push_back(create<Variable>("var", StorageClass::kNone, &i32));
|
||||
@ -48,8 +48,8 @@ TEST_F(FunctionTest, Creation) {
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, Creation_WithSource) {
|
||||
type::VoidType void_type;
|
||||
type::I32Type i32;
|
||||
type::Void void_type;
|
||||
type::I32 i32;
|
||||
|
||||
VariableList params;
|
||||
params.push_back(create<Variable>("var", StorageClass::kNone, &i32));
|
||||
@ -62,8 +62,8 @@ TEST_F(FunctionTest, Creation_WithSource) {
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, AddDuplicateReferencedVariables) {
|
||||
type::VoidType void_type;
|
||||
type::I32Type i32;
|
||||
type::Void void_type;
|
||||
type::I32 i32;
|
||||
|
||||
Variable v("var", StorageClass::kInput, &i32);
|
||||
Function f("func", VariableList{}, &void_type, create<BlockStatement>());
|
||||
@ -82,8 +82,8 @@ TEST_F(FunctionTest, AddDuplicateReferencedVariables) {
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, GetReferenceLocations) {
|
||||
type::VoidType void_type;
|
||||
type::I32Type i32;
|
||||
type::Void void_type;
|
||||
type::I32 i32;
|
||||
|
||||
DecoratedVariable loc1(create<Variable>("loc1", StorageClass::kInput, &i32));
|
||||
loc1.set_decorations({create<LocationDecoration>(0, Source{})});
|
||||
@ -118,8 +118,8 @@ TEST_F(FunctionTest, GetReferenceLocations) {
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, GetReferenceBuiltins) {
|
||||
type::VoidType void_type;
|
||||
type::I32Type i32;
|
||||
type::Void void_type;
|
||||
type::I32 i32;
|
||||
|
||||
DecoratedVariable loc1(create<Variable>("loc1", StorageClass::kInput, &i32));
|
||||
loc1.set_decorations({create<LocationDecoration>(0, Source{})});
|
||||
@ -154,7 +154,7 @@ TEST_F(FunctionTest, GetReferenceBuiltins) {
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, AddDuplicateEntryPoints) {
|
||||
type::VoidType void_type;
|
||||
type::Void void_type;
|
||||
Function f("func", VariableList{}, &void_type, create<BlockStatement>());
|
||||
|
||||
f.add_ancestor_entry_point("main");
|
||||
@ -167,8 +167,8 @@ TEST_F(FunctionTest, AddDuplicateEntryPoints) {
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, IsValid) {
|
||||
type::VoidType void_type;
|
||||
type::I32Type i32;
|
||||
type::Void void_type;
|
||||
type::I32 i32;
|
||||
|
||||
VariableList params;
|
||||
params.push_back(create<Variable>("var", StorageClass::kNone, &i32));
|
||||
@ -182,8 +182,8 @@ TEST_F(FunctionTest, IsValid) {
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, IsValid_EmptyName) {
|
||||
type::VoidType void_type;
|
||||
type::I32Type i32;
|
||||
type::Void void_type;
|
||||
type::I32 i32;
|
||||
|
||||
VariableList params;
|
||||
params.push_back(create<Variable>("var", StorageClass::kNone, &i32));
|
||||
@ -193,7 +193,7 @@ TEST_F(FunctionTest, IsValid_EmptyName) {
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, IsValid_MissingReturnType) {
|
||||
type::I32Type i32;
|
||||
type::I32 i32;
|
||||
|
||||
VariableList params;
|
||||
params.push_back(create<Variable>("var", StorageClass::kNone, &i32));
|
||||
@ -203,8 +203,8 @@ TEST_F(FunctionTest, IsValid_MissingReturnType) {
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, IsValid_NullParam) {
|
||||
type::VoidType void_type;
|
||||
type::I32Type i32;
|
||||
type::Void void_type;
|
||||
type::I32 i32;
|
||||
|
||||
VariableList params;
|
||||
params.push_back(create<Variable>("var", StorageClass::kNone, &i32));
|
||||
@ -215,7 +215,7 @@ TEST_F(FunctionTest, IsValid_NullParam) {
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, IsValid_InvalidParam) {
|
||||
type::VoidType void_type;
|
||||
type::Void void_type;
|
||||
|
||||
VariableList params;
|
||||
params.push_back(create<Variable>("var", StorageClass::kNone, nullptr));
|
||||
@ -225,8 +225,8 @@ TEST_F(FunctionTest, IsValid_InvalidParam) {
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, IsValid_NullBodyStatement) {
|
||||
type::VoidType void_type;
|
||||
type::I32Type i32;
|
||||
type::Void void_type;
|
||||
type::I32 i32;
|
||||
|
||||
VariableList params;
|
||||
params.push_back(create<Variable>("var", StorageClass::kNone, &i32));
|
||||
@ -241,8 +241,8 @@ TEST_F(FunctionTest, IsValid_NullBodyStatement) {
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, IsValid_InvalidBodyStatement) {
|
||||
type::VoidType void_type;
|
||||
type::I32Type i32;
|
||||
type::Void void_type;
|
||||
type::I32 i32;
|
||||
|
||||
VariableList params;
|
||||
params.push_back(create<Variable>("var", StorageClass::kNone, &i32));
|
||||
@ -257,8 +257,8 @@ TEST_F(FunctionTest, IsValid_InvalidBodyStatement) {
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, ToStr) {
|
||||
type::VoidType void_type;
|
||||
type::I32Type i32;
|
||||
type::Void void_type;
|
||||
type::I32 i32;
|
||||
|
||||
auto* block = create<BlockStatement>();
|
||||
block->append(create<DiscardStatement>());
|
||||
@ -277,8 +277,8 @@ TEST_F(FunctionTest, ToStr) {
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, ToStr_WithDecoration) {
|
||||
type::VoidType void_type;
|
||||
type::I32Type i32;
|
||||
type::Void void_type;
|
||||
type::I32 i32;
|
||||
|
||||
auto* block = create<BlockStatement>();
|
||||
block->append(create<DiscardStatement>());
|
||||
@ -299,8 +299,8 @@ TEST_F(FunctionTest, ToStr_WithDecoration) {
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, ToStr_WithParams) {
|
||||
type::VoidType void_type;
|
||||
type::I32Type i32;
|
||||
type::Void void_type;
|
||||
type::I32 i32;
|
||||
|
||||
VariableList params;
|
||||
params.push_back(create<Variable>("var", StorageClass::kNone, &i32));
|
||||
@ -328,16 +328,16 @@ TEST_F(FunctionTest, ToStr_WithParams) {
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, TypeName) {
|
||||
type::VoidType void_type;
|
||||
type::Void void_type;
|
||||
|
||||
Function f("func", {}, &void_type, create<BlockStatement>());
|
||||
EXPECT_EQ(f.type_name(), "__func__void");
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, TypeName_WithParams) {
|
||||
type::VoidType void_type;
|
||||
type::I32Type i32;
|
||||
type::F32Type f32;
|
||||
type::Void void_type;
|
||||
type::I32 i32;
|
||||
type::F32 f32;
|
||||
|
||||
VariableList params;
|
||||
params.push_back(create<Variable>("var1", StorageClass::kNone, &i32));
|
||||
@ -348,7 +348,7 @@ TEST_F(FunctionTest, TypeName_WithParams) {
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, GetLastStatement) {
|
||||
type::VoidType void_type;
|
||||
type::Void void_type;
|
||||
|
||||
VariableList params;
|
||||
auto* body = create<BlockStatement>();
|
||||
@ -361,7 +361,7 @@ TEST_F(FunctionTest, GetLastStatement) {
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, GetLastStatement_nullptr) {
|
||||
type::VoidType void_type;
|
||||
type::Void void_type;
|
||||
|
||||
VariableList params;
|
||||
auto* body = create<BlockStatement>();
|
||||
@ -372,7 +372,7 @@ TEST_F(FunctionTest, GetLastStatement_nullptr) {
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, WorkgroupSize_NoneSet) {
|
||||
type::VoidType void_type;
|
||||
type::Void void_type;
|
||||
Function f("f", {}, &void_type, create<BlockStatement>());
|
||||
uint32_t x = 0;
|
||||
uint32_t y = 0;
|
||||
@ -384,7 +384,7 @@ TEST_F(FunctionTest, WorkgroupSize_NoneSet) {
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, WorkgroupSize) {
|
||||
type::VoidType void_type;
|
||||
type::Void void_type;
|
||||
Function f("f", {}, &void_type, create<BlockStatement>());
|
||||
f.add_decoration(create<WorkgroupDecoration>(2u, 4u, 6u, Source{}));
|
||||
|
||||
|
@ -30,13 +30,13 @@ namespace {
|
||||
using IntLiteralTest = TestHelper;
|
||||
|
||||
TEST_F(IntLiteralTest, Sint_IsInt) {
|
||||
type::I32Type i32;
|
||||
type::I32 i32;
|
||||
SintLiteral i{&i32, 47};
|
||||
ASSERT_TRUE(i.Is<IntLiteral>());
|
||||
}
|
||||
|
||||
TEST_F(IntLiteralTest, Uint_IsInt) {
|
||||
type::I32Type i32;
|
||||
type::I32 i32;
|
||||
UintLiteral i{&i32, 42};
|
||||
EXPECT_TRUE(i.Is<IntLiteral>());
|
||||
}
|
||||
|
@ -56,17 +56,17 @@ bool Module::IsValid() const {
|
||||
if (ty == nullptr) {
|
||||
return false;
|
||||
}
|
||||
if (ty->Is<type::AliasType>()) {
|
||||
auto* alias = ty->As<type::AliasType>();
|
||||
if (ty->Is<type::Alias>()) {
|
||||
auto* alias = ty->As<type::Alias>();
|
||||
if (alias->type() == nullptr) {
|
||||
return false;
|
||||
}
|
||||
if (alias->type()->Is<type::StructType>() &&
|
||||
alias->type()->As<type::StructType>()->name().empty()) {
|
||||
if (alias->type()->Is<type::Struct>() &&
|
||||
alias->type()->As<type::Struct>()->name().empty()) {
|
||||
return false;
|
||||
}
|
||||
} else if (ty->Is<type::StructType>()) {
|
||||
auto* str = ty->As<type::StructType>();
|
||||
} else if (ty->Is<type::Struct>()) {
|
||||
auto* str = ty->As<type::Struct>();
|
||||
if (str->name().empty()) {
|
||||
return false;
|
||||
}
|
||||
@ -91,14 +91,14 @@ std::string Module::to_str() const {
|
||||
for (size_t i = 0; i < indent; ++i) {
|
||||
out << " ";
|
||||
}
|
||||
if (ty->Is<type::AliasType>()) {
|
||||
auto* alias = ty->As<type::AliasType>();
|
||||
if (ty->Is<type::Alias>()) {
|
||||
auto* alias = ty->As<type::Alias>();
|
||||
out << alias->name() << " -> " << alias->type()->type_name() << std::endl;
|
||||
if (alias->type()->Is<type::StructType>()) {
|
||||
alias->type()->As<type::StructType>()->impl()->to_str(out, indent);
|
||||
if (alias->type()->Is<type::Struct>()) {
|
||||
alias->type()->As<type::Struct>()->impl()->to_str(out, indent);
|
||||
}
|
||||
} else if (ty->Is<type::StructType>()) {
|
||||
auto* str = ty->As<type::StructType>();
|
||||
} else if (ty->Is<type::Struct>()) {
|
||||
auto* str = ty->As<type::Struct>();
|
||||
out << str->name() << " ";
|
||||
str->impl()->to_str(out, indent);
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ TEST_F(ModuleTest, ToStrEmitsPreambleAndPostamble) {
|
||||
}
|
||||
|
||||
TEST_F(ModuleTest, LookupFunction) {
|
||||
type::F32Type f32;
|
||||
type::F32 f32;
|
||||
Module m;
|
||||
|
||||
auto* func =
|
||||
@ -65,7 +65,7 @@ TEST_F(ModuleTest, IsValid_Empty) {
|
||||
}
|
||||
|
||||
TEST_F(ModuleTest, IsValid_GlobalVariable) {
|
||||
type::F32Type f32;
|
||||
type::F32 f32;
|
||||
auto* var = create<Variable>("var", StorageClass::kInput, &f32);
|
||||
|
||||
Module m;
|
||||
@ -88,8 +88,8 @@ TEST_F(ModuleTest, IsValid_Invalid_GlobalVariable) {
|
||||
}
|
||||
|
||||
TEST_F(ModuleTest, IsValid_Alias) {
|
||||
type::F32Type f32;
|
||||
type::AliasType alias("alias", &f32);
|
||||
type::F32 f32;
|
||||
type::Alias alias("alias", &f32);
|
||||
|
||||
Module m;
|
||||
m.AddConstructedType(&alias);
|
||||
@ -103,9 +103,9 @@ TEST_F(ModuleTest, IsValid_Null_Alias) {
|
||||
}
|
||||
|
||||
TEST_F(ModuleTest, IsValid_Struct) {
|
||||
type::F32Type f32;
|
||||
type::StructType st("name", {});
|
||||
type::AliasType alias("name", &st);
|
||||
type::F32 f32;
|
||||
type::Struct st("name", {});
|
||||
type::Alias alias("name", &st);
|
||||
|
||||
Module m;
|
||||
m.AddConstructedType(&alias);
|
||||
@ -113,9 +113,9 @@ TEST_F(ModuleTest, IsValid_Struct) {
|
||||
}
|
||||
|
||||
TEST_F(ModuleTest, IsValid_Struct_EmptyName) {
|
||||
type::F32Type f32;
|
||||
type::StructType st("", {});
|
||||
type::AliasType alias("name", &st);
|
||||
type::F32 f32;
|
||||
type::Struct st("", {});
|
||||
type::Alias alias("name", &st);
|
||||
|
||||
Module m;
|
||||
m.AddConstructedType(&alias);
|
||||
@ -123,7 +123,7 @@ TEST_F(ModuleTest, IsValid_Struct_EmptyName) {
|
||||
}
|
||||
|
||||
TEST_F(ModuleTest, IsValid_Function) {
|
||||
type::F32Type f32;
|
||||
type::F32 f32;
|
||||
auto* func =
|
||||
create<Function>("main", VariableList(), &f32, create<BlockStatement>());
|
||||
|
||||
|
@ -28,7 +28,7 @@ namespace {
|
||||
using NullLiteralTest = TestHelper;
|
||||
|
||||
TEST_F(NullLiteralTest, Is) {
|
||||
type::I32Type i32;
|
||||
type::I32 i32;
|
||||
NullLiteral i{&i32};
|
||||
Literal* l = &i;
|
||||
EXPECT_FALSE(l->Is<BoolLiteral>());
|
||||
@ -40,14 +40,14 @@ TEST_F(NullLiteralTest, Is) {
|
||||
}
|
||||
|
||||
TEST_F(NullLiteralTest, ToStr) {
|
||||
type::I32Type i32;
|
||||
type::I32 i32;
|
||||
NullLiteral i{&i32};
|
||||
|
||||
EXPECT_EQ(i.to_str(), "null __i32");
|
||||
}
|
||||
|
||||
TEST_F(NullLiteralTest, Name_I32) {
|
||||
type::I32Type i32;
|
||||
type::I32 i32;
|
||||
NullLiteral i{&i32};
|
||||
EXPECT_EQ("__null__i32", i.name());
|
||||
}
|
||||
|
@ -25,14 +25,14 @@ namespace {
|
||||
using ScalarConstructorExpressionTest = TestHelper;
|
||||
|
||||
TEST_F(ScalarConstructorExpressionTest, Creation) {
|
||||
type::BoolType bool_type;
|
||||
type::Bool bool_type;
|
||||
auto* b = create<BoolLiteral>(&bool_type, true);
|
||||
ScalarConstructorExpression c(b);
|
||||
EXPECT_EQ(c.literal(), b);
|
||||
}
|
||||
|
||||
TEST_F(ScalarConstructorExpressionTest, Creation_WithSource) {
|
||||
type::BoolType bool_type;
|
||||
type::Bool bool_type;
|
||||
auto* b = create<BoolLiteral>(&bool_type, true);
|
||||
ScalarConstructorExpression c(Source{Source::Location{20, 2}}, b);
|
||||
auto src = c.source();
|
||||
@ -41,7 +41,7 @@ TEST_F(ScalarConstructorExpressionTest, Creation_WithSource) {
|
||||
}
|
||||
|
||||
TEST_F(ScalarConstructorExpressionTest, IsValid) {
|
||||
type::BoolType bool_type;
|
||||
type::Bool bool_type;
|
||||
auto* b = create<BoolLiteral>(&bool_type, true);
|
||||
ScalarConstructorExpression c(b);
|
||||
EXPECT_TRUE(c.IsValid());
|
||||
@ -53,7 +53,7 @@ TEST_F(ScalarConstructorExpressionTest, IsValid_MissingLiteral) {
|
||||
}
|
||||
|
||||
TEST_F(ScalarConstructorExpressionTest, ToStr) {
|
||||
type::BoolType bool_type;
|
||||
type::Bool bool_type;
|
||||
auto* b = create<BoolLiteral>(&bool_type, true);
|
||||
ScalarConstructorExpression c(b);
|
||||
std::ostringstream out;
|
||||
|
@ -29,14 +29,14 @@ namespace {
|
||||
using SintLiteralTest = TestHelper;
|
||||
|
||||
TEST_F(SintLiteralTest, Value) {
|
||||
type::I32Type i32;
|
||||
type::I32 i32;
|
||||
SintLiteral i{&i32, 47};
|
||||
ASSERT_TRUE(i.Is<SintLiteral>());
|
||||
EXPECT_EQ(i.value(), 47);
|
||||
}
|
||||
|
||||
TEST_F(SintLiteralTest, Is) {
|
||||
type::I32Type i32;
|
||||
type::I32 i32;
|
||||
SintLiteral i{&i32, 42};
|
||||
Literal* l = &i;
|
||||
EXPECT_FALSE(l->Is<BoolLiteral>());
|
||||
@ -47,20 +47,20 @@ TEST_F(SintLiteralTest, Is) {
|
||||
}
|
||||
|
||||
TEST_F(SintLiteralTest, ToStr) {
|
||||
type::I32Type i32;
|
||||
type::I32 i32;
|
||||
SintLiteral i{&i32, -42};
|
||||
|
||||
EXPECT_EQ(i.to_str(), "-42");
|
||||
}
|
||||
|
||||
TEST_F(SintLiteralTest, Name_I32) {
|
||||
type::I32Type i32;
|
||||
type::I32 i32;
|
||||
SintLiteral i{&i32, 2};
|
||||
EXPECT_EQ("__sint__i32_2", i.name());
|
||||
}
|
||||
|
||||
TEST_F(SintLiteralTest, Name_U32) {
|
||||
type::U32Type u32;
|
||||
type::U32 u32;
|
||||
SintLiteral i{&u32, 2};
|
||||
EXPECT_EQ("__sint__u32_2", i.name());
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ namespace {
|
||||
using StructMemberTest = TestHelper;
|
||||
|
||||
TEST_F(StructMemberTest, Creation) {
|
||||
type::I32Type i32;
|
||||
type::I32 i32;
|
||||
StructMemberDecorationList decorations;
|
||||
decorations.emplace_back(create<StructMemberOffsetDecoration>(4, Source{}));
|
||||
|
||||
@ -44,7 +44,7 @@ TEST_F(StructMemberTest, Creation) {
|
||||
}
|
||||
|
||||
TEST_F(StructMemberTest, CreationWithSource) {
|
||||
type::I32Type i32;
|
||||
type::I32 i32;
|
||||
Source s{Source::Range{Source::Location{27, 4}, Source::Location{27, 8}}};
|
||||
|
||||
StructMember st{s, "a", &i32, {}};
|
||||
@ -58,13 +58,13 @@ TEST_F(StructMemberTest, CreationWithSource) {
|
||||
}
|
||||
|
||||
TEST_F(StructMemberTest, IsValid) {
|
||||
type::I32Type i32;
|
||||
type::I32 i32;
|
||||
StructMember st{"a", &i32, {}};
|
||||
EXPECT_TRUE(st.IsValid());
|
||||
}
|
||||
|
||||
TEST_F(StructMemberTest, IsValid_EmptyName) {
|
||||
type::I32Type i32;
|
||||
type::I32 i32;
|
||||
StructMember st{"", &i32, {}};
|
||||
EXPECT_FALSE(st.IsValid());
|
||||
}
|
||||
@ -75,7 +75,7 @@ TEST_F(StructMemberTest, IsValid_NullType) {
|
||||
}
|
||||
|
||||
TEST_F(StructMemberTest, IsValid_Null_Decoration) {
|
||||
type::I32Type i32;
|
||||
type::I32 i32;
|
||||
StructMemberDecorationList decorations;
|
||||
decorations.emplace_back(create<StructMemberOffsetDecoration>(4, Source{}));
|
||||
decorations.push_back(nullptr);
|
||||
@ -85,7 +85,7 @@ TEST_F(StructMemberTest, IsValid_Null_Decoration) {
|
||||
}
|
||||
|
||||
TEST_F(StructMemberTest, ToStr) {
|
||||
type::I32Type i32;
|
||||
type::I32 i32;
|
||||
StructMemberDecorationList decorations;
|
||||
decorations.emplace_back(create<StructMemberOffsetDecoration>(4, Source{}));
|
||||
|
||||
@ -96,7 +96,7 @@ TEST_F(StructMemberTest, ToStr) {
|
||||
}
|
||||
|
||||
TEST_F(StructMemberTest, ToStrNoDecorations) {
|
||||
type::I32Type i32;
|
||||
type::I32 i32;
|
||||
StructMember st{"a", &i32, {}};
|
||||
std::ostringstream out;
|
||||
st.to_str(out, 2);
|
||||
|
@ -30,7 +30,7 @@ namespace {
|
||||
using StructTest = TestHelper;
|
||||
|
||||
TEST_F(StructTest, Creation) {
|
||||
type::I32Type i32;
|
||||
type::I32 i32;
|
||||
StructMemberList members;
|
||||
members.push_back(
|
||||
create<StructMember>("a", &i32, StructMemberDecorationList()));
|
||||
@ -45,7 +45,7 @@ TEST_F(StructTest, Creation) {
|
||||
}
|
||||
|
||||
TEST_F(StructTest, Creation_WithDecorations) {
|
||||
type::I32Type i32;
|
||||
type::I32 i32;
|
||||
|
||||
StructMemberList members;
|
||||
members.push_back(
|
||||
@ -65,7 +65,7 @@ TEST_F(StructTest, Creation_WithDecorations) {
|
||||
}
|
||||
|
||||
TEST_F(StructTest, CreationWithSourceAndDecorations) {
|
||||
type::I32Type i32;
|
||||
type::I32 i32;
|
||||
|
||||
StructMemberList members;
|
||||
members.emplace_back(
|
||||
@ -92,7 +92,7 @@ TEST_F(StructTest, IsValid) {
|
||||
}
|
||||
|
||||
TEST_F(StructTest, IsValid_Null_StructMember) {
|
||||
type::I32Type i32;
|
||||
type::I32 i32;
|
||||
|
||||
StructMemberList members;
|
||||
members.push_back(
|
||||
@ -104,7 +104,7 @@ TEST_F(StructTest, IsValid_Null_StructMember) {
|
||||
}
|
||||
|
||||
TEST_F(StructTest, IsValid_Invalid_StructMember) {
|
||||
type::I32Type i32;
|
||||
type::I32 i32;
|
||||
|
||||
StructMemberList members;
|
||||
members.push_back(
|
||||
@ -115,7 +115,7 @@ TEST_F(StructTest, IsValid_Invalid_StructMember) {
|
||||
}
|
||||
|
||||
TEST_F(StructTest, ToStr) {
|
||||
type::I32Type i32;
|
||||
type::I32 i32;
|
||||
|
||||
StructMemberList members;
|
||||
members.emplace_back(
|
||||
|
@ -29,7 +29,7 @@ namespace {
|
||||
using SwitchStatementTest = TestHelper;
|
||||
|
||||
TEST_F(SwitchStatementTest, Creation) {
|
||||
type::I32Type i32;
|
||||
type::I32 i32;
|
||||
|
||||
CaseSelectorList lit;
|
||||
lit.push_back(create<SintLiteral>(&i32, 1));
|
||||
@ -61,7 +61,7 @@ TEST_F(SwitchStatementTest, IsSwitch) {
|
||||
}
|
||||
|
||||
TEST_F(SwitchStatementTest, IsValid) {
|
||||
type::I32Type i32;
|
||||
type::I32 i32;
|
||||
|
||||
CaseSelectorList lit;
|
||||
lit.push_back(create<SintLiteral>(&i32, 2));
|
||||
@ -75,7 +75,7 @@ TEST_F(SwitchStatementTest, IsValid) {
|
||||
}
|
||||
|
||||
TEST_F(SwitchStatementTest, IsValid_Null_Condition) {
|
||||
type::I32Type i32;
|
||||
type::I32 i32;
|
||||
|
||||
CaseSelectorList lit;
|
||||
lit.push_back(create<SintLiteral>(&i32, 2));
|
||||
@ -89,7 +89,7 @@ TEST_F(SwitchStatementTest, IsValid_Null_Condition) {
|
||||
}
|
||||
|
||||
TEST_F(SwitchStatementTest, IsValid_Invalid_Condition) {
|
||||
type::I32Type i32;
|
||||
type::I32 i32;
|
||||
|
||||
CaseSelectorList lit;
|
||||
lit.push_back(create<SintLiteral>(&i32, 2));
|
||||
@ -103,7 +103,7 @@ TEST_F(SwitchStatementTest, IsValid_Invalid_Condition) {
|
||||
}
|
||||
|
||||
TEST_F(SwitchStatementTest, IsValid_Null_BodyStatement) {
|
||||
type::I32Type i32;
|
||||
type::I32 i32;
|
||||
|
||||
CaseSelectorList lit;
|
||||
lit.push_back(create<SintLiteral>(&i32, 2));
|
||||
@ -145,7 +145,7 @@ TEST_F(SwitchStatementTest, ToStr_Empty) {
|
||||
}
|
||||
|
||||
TEST_F(SwitchStatementTest, ToStr) {
|
||||
type::I32Type i32;
|
||||
type::I32 i32;
|
||||
|
||||
CaseSelectorList lit;
|
||||
lit.push_back(create<SintLiteral>(&i32, 2));
|
||||
|
@ -20,38 +20,37 @@ namespace tint {
|
||||
namespace ast {
|
||||
namespace type {
|
||||
|
||||
AccessControlType::AccessControlType(AccessControl access, Type* subtype)
|
||||
AccessControl::AccessControl(ast::AccessControl access, Type* subtype)
|
||||
: access_(access), subtype_(subtype) {
|
||||
assert(subtype_);
|
||||
assert(!subtype_->Is<AccessControlType>());
|
||||
assert(!subtype_->Is<AccessControl>());
|
||||
}
|
||||
|
||||
AccessControlType::AccessControlType(AccessControlType&&) = default;
|
||||
AccessControl::AccessControl(AccessControl&&) = default;
|
||||
|
||||
AccessControlType::~AccessControlType() = default;
|
||||
AccessControl::~AccessControl() = default;
|
||||
|
||||
std::string AccessControlType::type_name() const {
|
||||
std::string AccessControl::type_name() const {
|
||||
std::string name = "__access_control_";
|
||||
switch (access_) {
|
||||
case AccessControl::kReadOnly:
|
||||
case ast::AccessControl::kReadOnly:
|
||||
name += "read_only";
|
||||
break;
|
||||
case AccessControl::kWriteOnly:
|
||||
case ast::AccessControl::kWriteOnly:
|
||||
name += "write_only";
|
||||
break;
|
||||
case AccessControl::kReadWrite:
|
||||
case ast::AccessControl::kReadWrite:
|
||||
name += "read_write";
|
||||
break;
|
||||
}
|
||||
return name + subtype_->type_name();
|
||||
}
|
||||
|
||||
uint64_t AccessControlType::MinBufferBindingSize(
|
||||
MemoryLayout mem_layout) const {
|
||||
uint64_t AccessControl::MinBufferBindingSize(MemoryLayout mem_layout) const {
|
||||
return subtype_->MinBufferBindingSize(mem_layout);
|
||||
}
|
||||
|
||||
uint64_t AccessControlType::BaseAlignment(MemoryLayout mem_layout) const {
|
||||
uint64_t AccessControl::BaseAlignment(MemoryLayout mem_layout) const {
|
||||
return subtype_->BaseAlignment(mem_layout);
|
||||
}
|
||||
|
||||
|
@ -25,25 +25,25 @@ namespace ast {
|
||||
namespace type {
|
||||
|
||||
/// An access control type. Holds an access setting and pointer to another type.
|
||||
class AccessControlType : public Castable<AccessControlType, Type> {
|
||||
class AccessControl : public Castable<AccessControl, Type> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param access the access control setting
|
||||
/// @param subtype the access controlled type
|
||||
AccessControlType(AccessControl access, Type* subtype);
|
||||
AccessControl(ast::AccessControl access, Type* subtype);
|
||||
/// Move constructor
|
||||
AccessControlType(AccessControlType&&);
|
||||
~AccessControlType() override;
|
||||
AccessControl(AccessControl&&);
|
||||
~AccessControl() override;
|
||||
|
||||
/// @returns true if the access control is read only
|
||||
bool IsReadOnly() const { return access_ == AccessControl::kReadOnly; }
|
||||
bool IsReadOnly() const { return access_ == ast::AccessControl::kReadOnly; }
|
||||
/// @returns true if the access control is write only
|
||||
bool IsWriteOnly() const { return access_ == AccessControl::kWriteOnly; }
|
||||
bool IsWriteOnly() const { return access_ == ast::AccessControl::kWriteOnly; }
|
||||
/// @returns true if the access control is read/write
|
||||
bool IsReadWrite() const { return access_ == AccessControl::kReadWrite; }
|
||||
bool IsReadWrite() const { return access_ == ast::AccessControl::kReadWrite; }
|
||||
|
||||
/// @returns the access control value
|
||||
AccessControl access_control() const { return access_; }
|
||||
ast::AccessControl access_control() const { return access_; }
|
||||
/// @returns the subtype type
|
||||
Type* type() const { return subtype_; }
|
||||
|
||||
@ -61,7 +61,7 @@ class AccessControlType : public Castable<AccessControlType, Type> {
|
||||
uint64_t BaseAlignment(MemoryLayout mem_layout) const override;
|
||||
|
||||
private:
|
||||
AccessControl access_ = AccessControl::kReadOnly;
|
||||
ast::AccessControl access_ = ast::AccessControl::kReadOnly;
|
||||
Type* subtype_ = nullptr;
|
||||
};
|
||||
|
||||
|
@ -39,38 +39,38 @@ namespace ast {
|
||||
namespace type {
|
||||
namespace {
|
||||
|
||||
using AccessControlTypeTest = TestHelper;
|
||||
using AccessControlTest = TestHelper;
|
||||
|
||||
TEST_F(AccessControlTypeTest, Create) {
|
||||
U32Type u32;
|
||||
AccessControlType a{AccessControl::kReadWrite, &u32};
|
||||
TEST_F(AccessControlTest, Create) {
|
||||
U32 u32;
|
||||
AccessControl a{ast::AccessControl::kReadWrite, &u32};
|
||||
EXPECT_TRUE(a.IsReadWrite());
|
||||
EXPECT_EQ(a.type(), &u32);
|
||||
}
|
||||
|
||||
TEST_F(AccessControlTypeTest, Is) {
|
||||
I32Type i32;
|
||||
TEST_F(AccessControlTest, Is) {
|
||||
I32 i32;
|
||||
|
||||
AccessControlType at{AccessControl::kReadOnly, &i32};
|
||||
AccessControl at{ast::AccessControl::kReadOnly, &i32};
|
||||
Type* ty = &at;
|
||||
EXPECT_TRUE(ty->Is<AccessControlType>());
|
||||
EXPECT_FALSE(ty->Is<AliasType>());
|
||||
EXPECT_FALSE(ty->Is<ArrayType>());
|
||||
EXPECT_FALSE(ty->Is<BoolType>());
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->Is<SamplerType>());
|
||||
EXPECT_FALSE(ty->Is<StructType>());
|
||||
EXPECT_FALSE(ty->Is<TextureType>());
|
||||
EXPECT_FALSE(ty->Is<U32Type>());
|
||||
EXPECT_FALSE(ty->Is<VectorType>());
|
||||
EXPECT_TRUE(ty->Is<AccessControl>());
|
||||
EXPECT_FALSE(ty->Is<Alias>());
|
||||
EXPECT_FALSE(ty->Is<Array>());
|
||||
EXPECT_FALSE(ty->Is<Bool>());
|
||||
EXPECT_FALSE(ty->Is<F32>());
|
||||
EXPECT_FALSE(ty->Is<I32>());
|
||||
EXPECT_FALSE(ty->Is<Matrix>());
|
||||
EXPECT_FALSE(ty->Is<Pointer>());
|
||||
EXPECT_FALSE(ty->Is<Sampler>());
|
||||
EXPECT_FALSE(ty->Is<Struct>());
|
||||
EXPECT_FALSE(ty->Is<Texture>());
|
||||
EXPECT_FALSE(ty->Is<U32>());
|
||||
EXPECT_FALSE(ty->Is<Vector>());
|
||||
}
|
||||
|
||||
TEST_F(AccessControlTypeTest, AccessRead) {
|
||||
I32Type i32;
|
||||
AccessControlType at{AccessControl::kReadOnly, &i32};
|
||||
TEST_F(AccessControlTest, AccessRead) {
|
||||
I32 i32;
|
||||
AccessControl at{ast::AccessControl::kReadOnly, &i32};
|
||||
EXPECT_TRUE(at.IsReadOnly());
|
||||
EXPECT_FALSE(at.IsWriteOnly());
|
||||
EXPECT_FALSE(at.IsReadWrite());
|
||||
@ -78,9 +78,9 @@ TEST_F(AccessControlTypeTest, AccessRead) {
|
||||
EXPECT_EQ(at.type_name(), "__access_control_read_only__i32");
|
||||
}
|
||||
|
||||
TEST_F(AccessControlTypeTest, AccessWrite) {
|
||||
I32Type i32;
|
||||
AccessControlType at{AccessControl::kWriteOnly, &i32};
|
||||
TEST_F(AccessControlTest, AccessWrite) {
|
||||
I32 i32;
|
||||
AccessControl at{ast::AccessControl::kWriteOnly, &i32};
|
||||
EXPECT_FALSE(at.IsReadOnly());
|
||||
EXPECT_TRUE(at.IsWriteOnly());
|
||||
EXPECT_FALSE(at.IsReadWrite());
|
||||
@ -88,9 +88,9 @@ TEST_F(AccessControlTypeTest, AccessWrite) {
|
||||
EXPECT_EQ(at.type_name(), "__access_control_write_only__i32");
|
||||
}
|
||||
|
||||
TEST_F(AccessControlTypeTest, AccessReadWrite) {
|
||||
I32Type i32;
|
||||
AccessControlType at{AccessControl::kReadWrite, &i32};
|
||||
TEST_F(AccessControlTest, AccessReadWrite) {
|
||||
I32 i32;
|
||||
AccessControl at{ast::AccessControl::kReadWrite, &i32};
|
||||
EXPECT_FALSE(at.IsReadOnly());
|
||||
EXPECT_FALSE(at.IsWriteOnly());
|
||||
EXPECT_TRUE(at.IsReadWrite());
|
||||
@ -98,34 +98,34 @@ TEST_F(AccessControlTypeTest, AccessReadWrite) {
|
||||
EXPECT_EQ(at.type_name(), "__access_control_read_write__i32");
|
||||
}
|
||||
|
||||
TEST_F(AccessControlTypeTest, MinBufferBindingSizeU32) {
|
||||
U32Type u32;
|
||||
AccessControlType at{AccessControl::kReadOnly, &u32};
|
||||
TEST_F(AccessControlTest, MinBufferBindingSizeU32) {
|
||||
U32 u32;
|
||||
AccessControl at{ast::AccessControl::kReadOnly, &u32};
|
||||
EXPECT_EQ(4u, at.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
TEST_F(AccessControlTypeTest, MinBufferBindingSizeArray) {
|
||||
U32Type u32;
|
||||
ArrayType array(&u32, 4);
|
||||
TEST_F(AccessControlTest, MinBufferBindingSizeArray) {
|
||||
U32 u32;
|
||||
Array array(&u32, 4);
|
||||
ArrayDecorationList decos;
|
||||
decos.push_back(create<StrideDecoration>(4, Source{}));
|
||||
array.set_decorations(decos);
|
||||
AccessControlType at{AccessControl::kReadOnly, &array};
|
||||
AccessControl at{ast::AccessControl::kReadOnly, &array};
|
||||
EXPECT_EQ(16u, at.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
TEST_F(AccessControlTypeTest, MinBufferBindingSizeRuntimeArray) {
|
||||
U32Type u32;
|
||||
ArrayType array(&u32);
|
||||
TEST_F(AccessControlTest, MinBufferBindingSizeRuntimeArray) {
|
||||
U32 u32;
|
||||
Array array(&u32);
|
||||
ArrayDecorationList decos;
|
||||
decos.push_back(create<StrideDecoration>(4, Source{}));
|
||||
array.set_decorations(decos);
|
||||
AccessControlType at{AccessControl::kReadOnly, &array};
|
||||
AccessControl at{ast::AccessControl::kReadOnly, &array};
|
||||
EXPECT_EQ(4u, at.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
TEST_F(AccessControlTypeTest, MinBufferBindingSizeStruct) {
|
||||
U32Type u32;
|
||||
TEST_F(AccessControlTest, MinBufferBindingSizeStruct) {
|
||||
U32 u32;
|
||||
StructMemberList members;
|
||||
|
||||
StructMemberDecorationList deco;
|
||||
@ -138,41 +138,41 @@ TEST_F(AccessControlTypeTest, MinBufferBindingSizeStruct) {
|
||||
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<Struct>(decos, members);
|
||||
StructType struct_type("struct_type", str);
|
||||
AccessControlType at{AccessControl::kReadOnly, &struct_type};
|
||||
auto* str = create<ast::Struct>(decos, members);
|
||||
Struct struct_type("struct_type", str);
|
||||
AccessControl at{ast::AccessControl::kReadOnly, &struct_type};
|
||||
EXPECT_EQ(16u, at.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(8u, at.MinBufferBindingSize(MemoryLayout::kStorageBuffer));
|
||||
}
|
||||
|
||||
TEST_F(AccessControlTypeTest, BaseAlignmentU32) {
|
||||
U32Type u32;
|
||||
AccessControlType at{AccessControl::kReadOnly, &u32};
|
||||
TEST_F(AccessControlTest, BaseAlignmentU32) {
|
||||
U32 u32;
|
||||
AccessControl at{ast::AccessControl::kReadOnly, &u32};
|
||||
EXPECT_EQ(4u, at.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
TEST_F(AccessControlTypeTest, BaseAlignmentArray) {
|
||||
U32Type u32;
|
||||
ArrayType array(&u32, 4);
|
||||
TEST_F(AccessControlTest, BaseAlignmentArray) {
|
||||
U32 u32;
|
||||
Array array(&u32, 4);
|
||||
ArrayDecorationList decos;
|
||||
decos.push_back(create<StrideDecoration>(4, Source{}));
|
||||
array.set_decorations(decos);
|
||||
AccessControlType at{AccessControl::kReadOnly, &array};
|
||||
AccessControl at{ast::AccessControl::kReadOnly, &array};
|
||||
EXPECT_EQ(16u, at.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
TEST_F(AccessControlTypeTest, BaseAlignmentRuntimeArray) {
|
||||
U32Type u32;
|
||||
ArrayType array(&u32);
|
||||
TEST_F(AccessControlTest, BaseAlignmentRuntimeArray) {
|
||||
U32 u32;
|
||||
Array array(&u32);
|
||||
ArrayDecorationList decos;
|
||||
decos.push_back(create<StrideDecoration>(4, Source{}));
|
||||
array.set_decorations(decos);
|
||||
AccessControlType at{AccessControl::kReadOnly, &array};
|
||||
AccessControl at{ast::AccessControl::kReadOnly, &array};
|
||||
EXPECT_EQ(16u, at.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
TEST_F(AccessControlTypeTest, BaseAlignmentStruct) {
|
||||
U32Type u32;
|
||||
TEST_F(AccessControlTest, BaseAlignmentStruct) {
|
||||
U32 u32;
|
||||
StructMemberList members;
|
||||
|
||||
{
|
||||
@ -187,9 +187,9 @@ TEST_F(AccessControlTypeTest, BaseAlignmentStruct) {
|
||||
}
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<Struct>(decos, members);
|
||||
StructType struct_type("struct_type", str);
|
||||
AccessControlType at{AccessControl::kReadOnly, &struct_type};
|
||||
auto* str = create<ast::Struct>(decos, members);
|
||||
Struct struct_type("struct_type", str);
|
||||
AccessControl at{ast::AccessControl::kReadOnly, &struct_type};
|
||||
EXPECT_EQ(16u, at.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(4u, at.BaseAlignment(MemoryLayout::kStorageBuffer));
|
||||
}
|
||||
|
@ -20,24 +20,24 @@ namespace tint {
|
||||
namespace ast {
|
||||
namespace type {
|
||||
|
||||
AliasType::AliasType(const std::string& name, Type* subtype)
|
||||
Alias::Alias(const std::string& name, Type* subtype)
|
||||
: name_(name), subtype_(subtype) {
|
||||
assert(subtype_);
|
||||
}
|
||||
|
||||
AliasType::AliasType(AliasType&&) = default;
|
||||
Alias::Alias(Alias&&) = default;
|
||||
|
||||
AliasType::~AliasType() = default;
|
||||
Alias::~Alias() = default;
|
||||
|
||||
std::string AliasType::type_name() const {
|
||||
std::string Alias::type_name() const {
|
||||
return "__alias_" + name_ + subtype_->type_name();
|
||||
}
|
||||
|
||||
uint64_t AliasType::MinBufferBindingSize(MemoryLayout mem_layout) const {
|
||||
uint64_t Alias::MinBufferBindingSize(MemoryLayout mem_layout) const {
|
||||
return subtype_->MinBufferBindingSize(mem_layout);
|
||||
}
|
||||
|
||||
uint64_t AliasType::BaseAlignment(MemoryLayout mem_layout) const {
|
||||
uint64_t Alias::BaseAlignment(MemoryLayout mem_layout) const {
|
||||
return subtype_->BaseAlignment(mem_layout);
|
||||
}
|
||||
|
||||
|
@ -24,15 +24,15 @@ namespace ast {
|
||||
namespace type {
|
||||
|
||||
/// A type alias type. Holds a name and pointer to another type.
|
||||
class AliasType : public Castable<AliasType, Type> {
|
||||
class Alias : public Castable<Alias, Type> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param name the alias name
|
||||
/// @param subtype the alias'd type
|
||||
AliasType(const std::string& name, Type* subtype);
|
||||
Alias(const std::string& name, Type* subtype);
|
||||
/// Move constructor
|
||||
AliasType(AliasType&&);
|
||||
~AliasType() override;
|
||||
Alias(Alias&&);
|
||||
~Alias() override;
|
||||
|
||||
/// @returns the alias name
|
||||
const std::string& name() const { return name_; }
|
||||
|
@ -40,155 +40,155 @@ namespace ast {
|
||||
namespace type {
|
||||
namespace {
|
||||
|
||||
using AliasTypeTest = TestHelper;
|
||||
using AliasTest = TestHelper;
|
||||
|
||||
TEST_F(AliasTypeTest, Create) {
|
||||
U32Type u32;
|
||||
AliasType a{"a_type", &u32};
|
||||
TEST_F(AliasTest, Create) {
|
||||
U32 u32;
|
||||
Alias a{"a_type", &u32};
|
||||
EXPECT_EQ(a.name(), "a_type");
|
||||
EXPECT_EQ(a.type(), &u32);
|
||||
}
|
||||
|
||||
TEST_F(AliasTypeTest, Is) {
|
||||
I32Type i32;
|
||||
TEST_F(AliasTest, Is) {
|
||||
I32 i32;
|
||||
|
||||
AliasType at{"a", &i32};
|
||||
Alias at{"a", &i32};
|
||||
Type* ty = &at;
|
||||
EXPECT_FALSE(ty->Is<AccessControlType>());
|
||||
EXPECT_TRUE(ty->Is<AliasType>());
|
||||
EXPECT_FALSE(ty->Is<ArrayType>());
|
||||
EXPECT_FALSE(ty->Is<BoolType>());
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->Is<SamplerType>());
|
||||
EXPECT_FALSE(ty->Is<StructType>());
|
||||
EXPECT_FALSE(ty->Is<TextureType>());
|
||||
EXPECT_FALSE(ty->Is<U32Type>());
|
||||
EXPECT_FALSE(ty->Is<VectorType>());
|
||||
EXPECT_FALSE(ty->Is<AccessControl>());
|
||||
EXPECT_TRUE(ty->Is<Alias>());
|
||||
EXPECT_FALSE(ty->Is<Array>());
|
||||
EXPECT_FALSE(ty->Is<Bool>());
|
||||
EXPECT_FALSE(ty->Is<F32>());
|
||||
EXPECT_FALSE(ty->Is<I32>());
|
||||
EXPECT_FALSE(ty->Is<Matrix>());
|
||||
EXPECT_FALSE(ty->Is<Pointer>());
|
||||
EXPECT_FALSE(ty->Is<Sampler>());
|
||||
EXPECT_FALSE(ty->Is<Struct>());
|
||||
EXPECT_FALSE(ty->Is<Texture>());
|
||||
EXPECT_FALSE(ty->Is<U32>());
|
||||
EXPECT_FALSE(ty->Is<Vector>());
|
||||
}
|
||||
|
||||
TEST_F(AliasTypeTest, TypeName) {
|
||||
I32Type i32;
|
||||
AliasType at{"Particle", &i32};
|
||||
TEST_F(AliasTest, TypeName) {
|
||||
I32 i32;
|
||||
Alias at{"Particle", &i32};
|
||||
EXPECT_EQ(at.type_name(), "__alias_Particle__i32");
|
||||
}
|
||||
|
||||
TEST_F(AliasTypeTest, UnwrapIfNeeded_Alias) {
|
||||
U32Type u32;
|
||||
AliasType a{"a_type", &u32};
|
||||
TEST_F(AliasTest, UnwrapIfNeeded_Alias) {
|
||||
U32 u32;
|
||||
Alias a{"a_type", &u32};
|
||||
EXPECT_EQ(a.name(), "a_type");
|
||||
EXPECT_EQ(a.type(), &u32);
|
||||
EXPECT_EQ(a.UnwrapIfNeeded(), &u32);
|
||||
EXPECT_EQ(u32.UnwrapIfNeeded(), &u32);
|
||||
}
|
||||
|
||||
TEST_F(AliasTypeTest, UnwrapIfNeeded_AccessControl) {
|
||||
U32Type u32;
|
||||
AccessControlType a{AccessControl::kReadOnly, &u32};
|
||||
TEST_F(AliasTest, UnwrapIfNeeded_AccessControl) {
|
||||
U32 u32;
|
||||
AccessControl a{ast::AccessControl::kReadOnly, &u32};
|
||||
EXPECT_EQ(a.type(), &u32);
|
||||
EXPECT_EQ(a.UnwrapIfNeeded(), &u32);
|
||||
}
|
||||
|
||||
TEST_F(AliasTypeTest, UnwrapIfNeeded_MultiLevel) {
|
||||
U32Type u32;
|
||||
AliasType a{"a_type", &u32};
|
||||
AliasType aa{"aa_type", &a};
|
||||
TEST_F(AliasTest, UnwrapIfNeeded_MultiLevel) {
|
||||
U32 u32;
|
||||
Alias a{"a_type", &u32};
|
||||
Alias aa{"aa_type", &a};
|
||||
EXPECT_EQ(aa.name(), "aa_type");
|
||||
EXPECT_EQ(aa.type(), &a);
|
||||
EXPECT_EQ(aa.UnwrapIfNeeded(), &u32);
|
||||
}
|
||||
|
||||
TEST_F(AliasTypeTest, UnwrapIfNeeded_MultiLevel_AliasAccessControl) {
|
||||
U32Type u32;
|
||||
AliasType a{"a_type", &u32};
|
||||
AccessControlType aa{AccessControl::kReadWrite, &a};
|
||||
TEST_F(AliasTest, UnwrapIfNeeded_MultiLevel_AliasAccessControl) {
|
||||
U32 u32;
|
||||
Alias a{"a_type", &u32};
|
||||
AccessControl aa{ast::AccessControl::kReadWrite, &a};
|
||||
EXPECT_EQ(aa.type(), &a);
|
||||
EXPECT_EQ(aa.UnwrapIfNeeded(), &u32);
|
||||
}
|
||||
|
||||
TEST_F(AliasTypeTest, UnwrapAll_TwiceAliasPointerTwiceAlias) {
|
||||
U32Type u32;
|
||||
AliasType a{"a_type", &u32};
|
||||
AliasType aa{"aa_type", &a};
|
||||
PointerType paa{&aa, StorageClass::kUniform};
|
||||
AliasType apaa{"paa_type", &paa};
|
||||
AliasType aapaa{"aapaa_type", &apaa};
|
||||
TEST_F(AliasTest, UnwrapAll_TwiceAliasPointerTwiceAlias) {
|
||||
U32 u32;
|
||||
Alias a{"a_type", &u32};
|
||||
Alias aa{"aa_type", &a};
|
||||
Pointer paa{&aa, StorageClass::kUniform};
|
||||
Alias apaa{"paa_type", &paa};
|
||||
Alias aapaa{"aapaa_type", &apaa};
|
||||
EXPECT_EQ(aapaa.name(), "aapaa_type");
|
||||
EXPECT_EQ(aapaa.type(), &apaa);
|
||||
EXPECT_EQ(aapaa.UnwrapAll(), &u32);
|
||||
EXPECT_EQ(u32.UnwrapAll(), &u32);
|
||||
}
|
||||
|
||||
TEST_F(AliasTypeTest, UnwrapAll_SecondConsecutivePointerBlocksUnrapping) {
|
||||
U32Type u32;
|
||||
AliasType a{"a_type", &u32};
|
||||
AliasType aa{"aa_type", &a};
|
||||
PointerType paa{&aa, StorageClass::kUniform};
|
||||
PointerType ppaa{&paa, StorageClass::kUniform};
|
||||
AliasType appaa{"appaa_type", &ppaa};
|
||||
TEST_F(AliasTest, UnwrapAll_SecondConsecutivePointerBlocksUnrapping) {
|
||||
U32 u32;
|
||||
Alias a{"a_type", &u32};
|
||||
Alias aa{"aa_type", &a};
|
||||
Pointer paa{&aa, StorageClass::kUniform};
|
||||
Pointer ppaa{&paa, StorageClass::kUniform};
|
||||
Alias appaa{"appaa_type", &ppaa};
|
||||
EXPECT_EQ(appaa.UnwrapAll(), &paa);
|
||||
}
|
||||
|
||||
TEST_F(AliasTypeTest, UnwrapAll_SecondNonConsecutivePointerBlocksUnrapping) {
|
||||
U32Type u32;
|
||||
AliasType a{"a_type", &u32};
|
||||
AliasType aa{"aa_type", &a};
|
||||
PointerType paa{&aa, StorageClass::kUniform};
|
||||
AliasType apaa{"apaa_type", &paa};
|
||||
AliasType aapaa{"aapaa_type", &apaa};
|
||||
PointerType paapaa{&aapaa, StorageClass::kUniform};
|
||||
AliasType apaapaa{"apaapaa_type", &paapaa};
|
||||
TEST_F(AliasTest, UnwrapAll_SecondNonConsecutivePointerBlocksUnrapping) {
|
||||
U32 u32;
|
||||
Alias a{"a_type", &u32};
|
||||
Alias aa{"aa_type", &a};
|
||||
Pointer paa{&aa, StorageClass::kUniform};
|
||||
Alias apaa{"apaa_type", &paa};
|
||||
Alias aapaa{"aapaa_type", &apaa};
|
||||
Pointer paapaa{&aapaa, StorageClass::kUniform};
|
||||
Alias apaapaa{"apaapaa_type", &paapaa};
|
||||
EXPECT_EQ(apaapaa.UnwrapAll(), &paa);
|
||||
}
|
||||
|
||||
TEST_F(AliasTypeTest, UnwrapAll_AccessControlPointer) {
|
||||
U32Type u32;
|
||||
AccessControlType a{AccessControl::kReadOnly, &u32};
|
||||
PointerType pa{&a, StorageClass::kUniform};
|
||||
TEST_F(AliasTest, UnwrapAll_AccessControlPointer) {
|
||||
U32 u32;
|
||||
AccessControl a{ast::AccessControl::kReadOnly, &u32};
|
||||
Pointer pa{&a, StorageClass::kUniform};
|
||||
EXPECT_EQ(pa.type(), &a);
|
||||
EXPECT_EQ(pa.UnwrapAll(), &u32);
|
||||
EXPECT_EQ(u32.UnwrapAll(), &u32);
|
||||
}
|
||||
|
||||
TEST_F(AliasTypeTest, UnwrapAll_PointerAccessControl) {
|
||||
U32Type u32;
|
||||
PointerType p{&u32, StorageClass::kUniform};
|
||||
AccessControlType a{AccessControl::kReadOnly, &p};
|
||||
TEST_F(AliasTest, UnwrapAll_PointerAccessControl) {
|
||||
U32 u32;
|
||||
Pointer p{&u32, StorageClass::kUniform};
|
||||
AccessControl a{ast::AccessControl::kReadOnly, &p};
|
||||
EXPECT_EQ(a.type(), &p);
|
||||
EXPECT_EQ(a.UnwrapAll(), &u32);
|
||||
EXPECT_EQ(u32.UnwrapAll(), &u32);
|
||||
}
|
||||
|
||||
TEST_F(AliasTypeTest, MinBufferBindingSizeU32) {
|
||||
U32Type u32;
|
||||
AliasType alias{"alias", &u32};
|
||||
TEST_F(AliasTest, MinBufferBindingSizeU32) {
|
||||
U32 u32;
|
||||
Alias alias{"alias", &u32};
|
||||
EXPECT_EQ(4u, alias.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
TEST_F(AliasTypeTest, MinBufferBindingSizeArray) {
|
||||
U32Type u32;
|
||||
ArrayType array(&u32, 4);
|
||||
TEST_F(AliasTest, MinBufferBindingSizeArray) {
|
||||
U32 u32;
|
||||
Array array(&u32, 4);
|
||||
ArrayDecorationList decos;
|
||||
decos.push_back(create<StrideDecoration>(4, Source{}));
|
||||
array.set_decorations(decos);
|
||||
AliasType alias{"alias", &array};
|
||||
Alias alias{"alias", &array};
|
||||
EXPECT_EQ(16u, alias.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
TEST_F(AliasTypeTest, MinBufferBindingSizeRuntimeArray) {
|
||||
U32Type u32;
|
||||
ArrayType array(&u32);
|
||||
TEST_F(AliasTest, MinBufferBindingSizeRuntimeArray) {
|
||||
U32 u32;
|
||||
Array array(&u32);
|
||||
ArrayDecorationList decos;
|
||||
decos.push_back(create<StrideDecoration>(4, Source{}));
|
||||
array.set_decorations(decos);
|
||||
AliasType alias{"alias", &array};
|
||||
Alias alias{"alias", &array};
|
||||
EXPECT_EQ(4u, alias.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
TEST_F(AliasTypeTest, MinBufferBindingSizeStruct) {
|
||||
U32Type u32;
|
||||
TEST_F(AliasTest, MinBufferBindingSizeStruct) {
|
||||
U32 u32;
|
||||
StructMemberList members;
|
||||
|
||||
{
|
||||
@ -203,41 +203,41 @@ TEST_F(AliasTypeTest, MinBufferBindingSizeStruct) {
|
||||
}
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<Struct>(decos, members);
|
||||
StructType struct_type("struct_type", str);
|
||||
AliasType alias{"alias", &struct_type};
|
||||
auto* str = create<ast::Struct>(decos, members);
|
||||
Struct struct_type("struct_type", str);
|
||||
Alias alias{"alias", &struct_type};
|
||||
EXPECT_EQ(16u, alias.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(8u, alias.MinBufferBindingSize(MemoryLayout::kStorageBuffer));
|
||||
}
|
||||
|
||||
TEST_F(AliasTypeTest, BaseAlignmentU32) {
|
||||
U32Type u32;
|
||||
AliasType alias{"alias", &u32};
|
||||
TEST_F(AliasTest, BaseAlignmentU32) {
|
||||
U32 u32;
|
||||
Alias alias{"alias", &u32};
|
||||
EXPECT_EQ(4u, alias.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
TEST_F(AliasTypeTest, BaseAlignmentArray) {
|
||||
U32Type u32;
|
||||
ArrayType array(&u32, 4);
|
||||
TEST_F(AliasTest, BaseAlignmentArray) {
|
||||
U32 u32;
|
||||
Array array(&u32, 4);
|
||||
ArrayDecorationList decos;
|
||||
decos.push_back(create<StrideDecoration>(4, Source{}));
|
||||
array.set_decorations(decos);
|
||||
AliasType alias{"alias", &array};
|
||||
Alias alias{"alias", &array};
|
||||
EXPECT_EQ(16u, alias.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
TEST_F(AliasTypeTest, BaseAlignmentRuntimeArray) {
|
||||
U32Type u32;
|
||||
ArrayType array(&u32);
|
||||
TEST_F(AliasTest, BaseAlignmentRuntimeArray) {
|
||||
U32 u32;
|
||||
Array array(&u32);
|
||||
ArrayDecorationList decos;
|
||||
decos.push_back(create<StrideDecoration>(4, Source{}));
|
||||
array.set_decorations(decos);
|
||||
AliasType alias{"alias", &array};
|
||||
Alias alias{"alias", &array};
|
||||
EXPECT_EQ(16u, alias.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
TEST_F(AliasTypeTest, BaseAlignmentStruct) {
|
||||
U32Type u32;
|
||||
TEST_F(AliasTest, BaseAlignmentStruct) {
|
||||
U32 u32;
|
||||
StructMemberList members;
|
||||
|
||||
{
|
||||
@ -252,9 +252,9 @@ TEST_F(AliasTypeTest, BaseAlignmentStruct) {
|
||||
}
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<Struct>(decos, members);
|
||||
StructType struct_type("struct_type", str);
|
||||
AliasType alias{"alias", &struct_type};
|
||||
auto* str = create<ast::Struct>(decos, members);
|
||||
Struct struct_type("struct_type", str);
|
||||
Alias alias{"alias", &struct_type};
|
||||
EXPECT_EQ(16u, alias.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(4u, alias.BaseAlignment(MemoryLayout::kStorageBuffer));
|
||||
}
|
||||
|
@ -23,16 +23,15 @@ namespace tint {
|
||||
namespace ast {
|
||||
namespace type {
|
||||
|
||||
ArrayType::ArrayType(Type* subtype) : subtype_(subtype) {}
|
||||
Array::Array(Type* subtype) : subtype_(subtype) {}
|
||||
|
||||
ArrayType::ArrayType(Type* subtype, uint32_t size)
|
||||
: subtype_(subtype), size_(size) {}
|
||||
Array::Array(Type* subtype, uint32_t size) : subtype_(subtype), size_(size) {}
|
||||
|
||||
ArrayType::ArrayType(ArrayType&&) = default;
|
||||
Array::Array(Array&&) = default;
|
||||
|
||||
ArrayType::~ArrayType() = default;
|
||||
Array::~Array() = default;
|
||||
|
||||
uint64_t ArrayType::MinBufferBindingSize(MemoryLayout mem_layout) const {
|
||||
uint64_t Array::MinBufferBindingSize(MemoryLayout mem_layout) const {
|
||||
if (!has_array_stride()) {
|
||||
// Arrays in buffers are required to have a stride.
|
||||
return 0;
|
||||
@ -52,7 +51,7 @@ uint64_t ArrayType::MinBufferBindingSize(MemoryLayout mem_layout) const {
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t ArrayType::BaseAlignment(MemoryLayout mem_layout) const {
|
||||
uint64_t Array::BaseAlignment(MemoryLayout mem_layout) const {
|
||||
if (mem_layout == MemoryLayout::kUniformBuffer) {
|
||||
float aligment = 16; // for a vec4
|
||||
float unaligned = static_cast<float>(subtype_->BaseAlignment(mem_layout));
|
||||
@ -63,7 +62,7 @@ uint64_t ArrayType::BaseAlignment(MemoryLayout mem_layout) const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t ArrayType::array_stride() const {
|
||||
uint32_t Array::array_stride() const {
|
||||
for (auto* deco : decos_) {
|
||||
if (auto* stride = deco->As<StrideDecoration>()) {
|
||||
return stride->stride();
|
||||
@ -72,7 +71,7 @@ uint32_t ArrayType::array_stride() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool ArrayType::has_array_stride() const {
|
||||
bool Array::has_array_stride() const {
|
||||
for (auto* deco : decos_) {
|
||||
if (deco->Is<StrideDecoration>()) {
|
||||
return true;
|
||||
@ -81,7 +80,7 @@ bool ArrayType::has_array_stride() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string ArrayType::type_name() const {
|
||||
std::string Array::type_name() const {
|
||||
assert(subtype_);
|
||||
|
||||
std::string type_name = "__array" + subtype_->type_name();
|
||||
|
@ -28,18 +28,18 @@ namespace ast {
|
||||
namespace type {
|
||||
|
||||
/// An array type. If size is zero then it is a runtime array.
|
||||
class ArrayType : public Castable<ArrayType, Type> {
|
||||
class Array : public Castable<Array, Type> {
|
||||
public:
|
||||
/// Constructor for runtime array
|
||||
/// @param subtype the type of the array elements
|
||||
explicit ArrayType(Type* subtype);
|
||||
explicit Array(Type* subtype);
|
||||
/// Constructor
|
||||
/// @param subtype the type of the array elements
|
||||
/// @param size the number of elements in the array
|
||||
ArrayType(Type* subtype, uint32_t size);
|
||||
Array(Type* subtype, uint32_t size);
|
||||
/// Move constructor
|
||||
ArrayType(ArrayType&&);
|
||||
~ArrayType() override;
|
||||
Array(Array&&);
|
||||
~Array() override;
|
||||
|
||||
/// @returns true if this is a runtime array.
|
||||
/// i.e. the size is determined at runtime
|
||||
|
@ -35,111 +35,111 @@ namespace ast {
|
||||
namespace type {
|
||||
namespace {
|
||||
|
||||
using ArrayTypeTest = TestHelper;
|
||||
using ArrayTest = TestHelper;
|
||||
|
||||
TEST_F(ArrayTypeTest, CreateSizedArray) {
|
||||
U32Type u32;
|
||||
ArrayType arr{&u32, 3};
|
||||
TEST_F(ArrayTest, CreateSizedArray) {
|
||||
U32 u32;
|
||||
Array arr{&u32, 3};
|
||||
EXPECT_EQ(arr.type(), &u32);
|
||||
EXPECT_EQ(arr.size(), 3u);
|
||||
EXPECT_TRUE(arr.Is<ArrayType>());
|
||||
EXPECT_TRUE(arr.Is<Array>());
|
||||
EXPECT_FALSE(arr.IsRuntimeArray());
|
||||
}
|
||||
|
||||
TEST_F(ArrayTypeTest, CreateRuntimeArray) {
|
||||
U32Type u32;
|
||||
ArrayType arr{&u32};
|
||||
TEST_F(ArrayTest, CreateRuntimeArray) {
|
||||
U32 u32;
|
||||
Array arr{&u32};
|
||||
EXPECT_EQ(arr.type(), &u32);
|
||||
EXPECT_EQ(arr.size(), 0u);
|
||||
EXPECT_TRUE(arr.Is<ArrayType>());
|
||||
EXPECT_TRUE(arr.Is<Array>());
|
||||
EXPECT_TRUE(arr.IsRuntimeArray());
|
||||
}
|
||||
|
||||
TEST_F(ArrayTypeTest, Is) {
|
||||
I32Type i32;
|
||||
TEST_F(ArrayTest, Is) {
|
||||
I32 i32;
|
||||
|
||||
ArrayType arr{&i32, 3};
|
||||
Array arr{&i32, 3};
|
||||
Type* ty = &arr;
|
||||
EXPECT_FALSE(ty->Is<AccessControlType>());
|
||||
EXPECT_FALSE(ty->Is<AliasType>());
|
||||
EXPECT_TRUE(ty->Is<ArrayType>());
|
||||
EXPECT_FALSE(ty->Is<BoolType>());
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->Is<SamplerType>());
|
||||
EXPECT_FALSE(ty->Is<StructType>());
|
||||
EXPECT_FALSE(ty->Is<TextureType>());
|
||||
EXPECT_FALSE(ty->Is<U32Type>());
|
||||
EXPECT_FALSE(ty->Is<VectorType>());
|
||||
EXPECT_FALSE(ty->Is<AccessControl>());
|
||||
EXPECT_FALSE(ty->Is<Alias>());
|
||||
EXPECT_TRUE(ty->Is<Array>());
|
||||
EXPECT_FALSE(ty->Is<Bool>());
|
||||
EXPECT_FALSE(ty->Is<F32>());
|
||||
EXPECT_FALSE(ty->Is<I32>());
|
||||
EXPECT_FALSE(ty->Is<Matrix>());
|
||||
EXPECT_FALSE(ty->Is<Pointer>());
|
||||
EXPECT_FALSE(ty->Is<Sampler>());
|
||||
EXPECT_FALSE(ty->Is<Struct>());
|
||||
EXPECT_FALSE(ty->Is<Texture>());
|
||||
EXPECT_FALSE(ty->Is<U32>());
|
||||
EXPECT_FALSE(ty->Is<Vector>());
|
||||
}
|
||||
|
||||
TEST_F(ArrayTypeTest, TypeName) {
|
||||
I32Type i32;
|
||||
ArrayType arr{&i32};
|
||||
TEST_F(ArrayTest, TypeName) {
|
||||
I32 i32;
|
||||
Array arr{&i32};
|
||||
EXPECT_EQ(arr.type_name(), "__array__i32");
|
||||
}
|
||||
|
||||
TEST_F(ArrayTypeTest, TypeName_RuntimeArray) {
|
||||
I32Type i32;
|
||||
ArrayType arr{&i32, 3};
|
||||
TEST_F(ArrayTest, TypeName_RuntimeArray) {
|
||||
I32 i32;
|
||||
Array arr{&i32, 3};
|
||||
EXPECT_EQ(arr.type_name(), "__array__i32_3");
|
||||
}
|
||||
|
||||
TEST_F(ArrayTypeTest, TypeName_WithStride) {
|
||||
I32Type i32;
|
||||
TEST_F(ArrayTest, TypeName_WithStride) {
|
||||
I32 i32;
|
||||
ArrayDecorationList decos;
|
||||
decos.push_back(create<StrideDecoration>(16, Source{}));
|
||||
|
||||
ArrayType arr{&i32, 3};
|
||||
Array arr{&i32, 3};
|
||||
arr.set_decorations(decos);
|
||||
EXPECT_EQ(arr.type_name(), "__array__i32_3_stride_16");
|
||||
}
|
||||
|
||||
TEST_F(ArrayTypeTest, MinBufferBindingSizeNoStride) {
|
||||
U32Type u32;
|
||||
ArrayType arr(&u32, 4);
|
||||
TEST_F(ArrayTest, MinBufferBindingSizeNoStride) {
|
||||
U32 u32;
|
||||
Array arr(&u32, 4);
|
||||
EXPECT_EQ(0u, arr.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
TEST_F(ArrayTypeTest, MinBufferBindingSizeArray) {
|
||||
U32Type u32;
|
||||
TEST_F(ArrayTest, MinBufferBindingSizeArray) {
|
||||
U32 u32;
|
||||
ArrayDecorationList decos;
|
||||
decos.push_back(create<StrideDecoration>(4, Source{}));
|
||||
|
||||
ArrayType arr(&u32, 4);
|
||||
Array arr(&u32, 4);
|
||||
arr.set_decorations(decos);
|
||||
EXPECT_EQ(16u, arr.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
TEST_F(ArrayTypeTest, MinBufferBindingSizeRuntimeArray) {
|
||||
U32Type u32;
|
||||
TEST_F(ArrayTest, MinBufferBindingSizeRuntimeArray) {
|
||||
U32 u32;
|
||||
ArrayDecorationList decos;
|
||||
decos.push_back(create<StrideDecoration>(4, Source{}));
|
||||
|
||||
ArrayType arr(&u32);
|
||||
Array arr(&u32);
|
||||
arr.set_decorations(decos);
|
||||
EXPECT_EQ(4u, arr.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
TEST_F(ArrayTypeTest, BaseAlignmentArray) {
|
||||
U32Type u32;
|
||||
TEST_F(ArrayTest, BaseAlignmentArray) {
|
||||
U32 u32;
|
||||
ArrayDecorationList decos;
|
||||
decos.push_back(create<StrideDecoration>(4, Source{}));
|
||||
|
||||
ArrayType arr(&u32, 4);
|
||||
Array arr(&u32, 4);
|
||||
arr.set_decorations(decos);
|
||||
EXPECT_EQ(16u, arr.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(4u, arr.BaseAlignment(MemoryLayout::kStorageBuffer));
|
||||
}
|
||||
|
||||
TEST_F(ArrayTypeTest, BaseAlignmentRuntimeArray) {
|
||||
U32Type u32;
|
||||
TEST_F(ArrayTest, BaseAlignmentRuntimeArray) {
|
||||
U32 u32;
|
||||
ArrayDecorationList decos;
|
||||
decos.push_back(create<StrideDecoration>(4, Source{}));
|
||||
|
||||
ArrayType arr(&u32);
|
||||
Array arr(&u32);
|
||||
arr.set_decorations(decos);
|
||||
EXPECT_EQ(16u, arr.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(4u, arr.BaseAlignment(MemoryLayout::kStorageBuffer));
|
||||
|
@ -18,13 +18,13 @@ namespace tint {
|
||||
namespace ast {
|
||||
namespace type {
|
||||
|
||||
BoolType::BoolType() = default;
|
||||
Bool::Bool() = default;
|
||||
|
||||
BoolType::BoolType(BoolType&&) = default;
|
||||
Bool::Bool(Bool&&) = default;
|
||||
|
||||
BoolType::~BoolType() = default;
|
||||
Bool::~Bool() = default;
|
||||
|
||||
std::string BoolType::type_name() const {
|
||||
std::string Bool::type_name() const {
|
||||
return "__bool";
|
||||
}
|
||||
|
||||
|
@ -24,13 +24,13 @@ namespace ast {
|
||||
namespace type {
|
||||
|
||||
/// A boolean type
|
||||
class BoolType : public Castable<BoolType, Type> {
|
||||
class Bool : public Castable<Bool, Type> {
|
||||
public:
|
||||
/// Constructor
|
||||
BoolType();
|
||||
Bool();
|
||||
/// Move constructor
|
||||
BoolType(BoolType&&);
|
||||
~BoolType() override;
|
||||
Bool(Bool&&);
|
||||
~Bool() override;
|
||||
|
||||
/// @returns the name for this type
|
||||
std::string type_name() const override;
|
||||
|
@ -31,33 +31,33 @@ namespace ast {
|
||||
namespace type {
|
||||
namespace {
|
||||
|
||||
using BoolTypeTest = TestHelper;
|
||||
using BoolTest = TestHelper;
|
||||
|
||||
TEST_F(BoolTypeTest, Is) {
|
||||
BoolType b;
|
||||
TEST_F(BoolTest, Is) {
|
||||
Bool b;
|
||||
Type* ty = &b;
|
||||
EXPECT_FALSE(ty->Is<AccessControlType>());
|
||||
EXPECT_FALSE(ty->Is<AliasType>());
|
||||
EXPECT_FALSE(ty->Is<ArrayType>());
|
||||
EXPECT_TRUE(ty->Is<BoolType>());
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->Is<SamplerType>());
|
||||
EXPECT_FALSE(ty->Is<StructType>());
|
||||
EXPECT_FALSE(ty->Is<TextureType>());
|
||||
EXPECT_FALSE(ty->Is<U32Type>());
|
||||
EXPECT_FALSE(ty->Is<VectorType>());
|
||||
EXPECT_FALSE(ty->Is<AccessControl>());
|
||||
EXPECT_FALSE(ty->Is<Alias>());
|
||||
EXPECT_FALSE(ty->Is<Array>());
|
||||
EXPECT_TRUE(ty->Is<Bool>());
|
||||
EXPECT_FALSE(ty->Is<F32>());
|
||||
EXPECT_FALSE(ty->Is<I32>());
|
||||
EXPECT_FALSE(ty->Is<Matrix>());
|
||||
EXPECT_FALSE(ty->Is<Pointer>());
|
||||
EXPECT_FALSE(ty->Is<Sampler>());
|
||||
EXPECT_FALSE(ty->Is<Struct>());
|
||||
EXPECT_FALSE(ty->Is<Texture>());
|
||||
EXPECT_FALSE(ty->Is<U32>());
|
||||
EXPECT_FALSE(ty->Is<Vector>());
|
||||
}
|
||||
|
||||
TEST_F(BoolTypeTest, TypeName) {
|
||||
BoolType b;
|
||||
TEST_F(BoolTest, TypeName) {
|
||||
Bool b;
|
||||
EXPECT_EQ(b.type_name(), "__bool");
|
||||
}
|
||||
|
||||
TEST_F(BoolTypeTest, MinBufferBindingSize) {
|
||||
BoolType b;
|
||||
TEST_F(BoolTest, MinBufferBindingSize) {
|
||||
Bool b;
|
||||
EXPECT_EQ(0u, b.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
|
@ -33,15 +33,15 @@ bool IsValidDepthDimension(TextureDimension dim) {
|
||||
|
||||
} // namespace
|
||||
|
||||
DepthTextureType::DepthTextureType(TextureDimension dim) : Base(dim) {
|
||||
DepthTexture::DepthTexture(TextureDimension dim) : Base(dim) {
|
||||
assert(IsValidDepthDimension(dim));
|
||||
}
|
||||
|
||||
DepthTextureType::DepthTextureType(DepthTextureType&&) = default;
|
||||
DepthTexture::DepthTexture(DepthTexture&&) = default;
|
||||
|
||||
DepthTextureType::~DepthTextureType() = default;
|
||||
DepthTexture::~DepthTexture() = default;
|
||||
|
||||
std::string DepthTextureType::type_name() const {
|
||||
std::string DepthTexture::type_name() const {
|
||||
std::ostringstream out;
|
||||
out << "__depth_texture_" << dim();
|
||||
return out.str();
|
||||
|
@ -24,14 +24,14 @@ namespace ast {
|
||||
namespace type {
|
||||
|
||||
/// A depth texture type.
|
||||
class DepthTextureType : public Castable<DepthTextureType, TextureType> {
|
||||
class DepthTexture : public Castable<DepthTexture, Texture> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param dim the dimensionality of the texture
|
||||
explicit DepthTextureType(TextureDimension dim);
|
||||
explicit DepthTexture(TextureDimension dim);
|
||||
/// Move constructor
|
||||
DepthTextureType(DepthTextureType&&);
|
||||
~DepthTextureType() override;
|
||||
DepthTexture(DepthTexture&&);
|
||||
~DepthTexture() override;
|
||||
|
||||
/// @returns the name for this type
|
||||
std::string type_name() const override;
|
||||
|
@ -34,46 +34,46 @@ namespace ast {
|
||||
namespace type {
|
||||
namespace {
|
||||
|
||||
using DepthTextureTypeTest = TestHelper;
|
||||
using DepthTextureTest = TestHelper;
|
||||
|
||||
TEST_F(DepthTextureTypeTest, Is) {
|
||||
DepthTextureType d(TextureDimension::kCube);
|
||||
TEST_F(DepthTextureTest, Is) {
|
||||
DepthTexture d(TextureDimension::kCube);
|
||||
Type* ty = &d;
|
||||
EXPECT_FALSE(ty->Is<AccessControlType>());
|
||||
EXPECT_FALSE(ty->Is<AliasType>());
|
||||
EXPECT_FALSE(ty->Is<ArrayType>());
|
||||
EXPECT_FALSE(ty->Is<BoolType>());
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->Is<SamplerType>());
|
||||
EXPECT_FALSE(ty->Is<StructType>());
|
||||
EXPECT_TRUE(ty->Is<TextureType>());
|
||||
EXPECT_FALSE(ty->Is<U32Type>());
|
||||
EXPECT_FALSE(ty->Is<VectorType>());
|
||||
EXPECT_FALSE(ty->Is<AccessControl>());
|
||||
EXPECT_FALSE(ty->Is<Alias>());
|
||||
EXPECT_FALSE(ty->Is<Array>());
|
||||
EXPECT_FALSE(ty->Is<Bool>());
|
||||
EXPECT_FALSE(ty->Is<F32>());
|
||||
EXPECT_FALSE(ty->Is<I32>());
|
||||
EXPECT_FALSE(ty->Is<Matrix>());
|
||||
EXPECT_FALSE(ty->Is<Pointer>());
|
||||
EXPECT_FALSE(ty->Is<Sampler>());
|
||||
EXPECT_FALSE(ty->Is<Struct>());
|
||||
EXPECT_TRUE(ty->Is<Texture>());
|
||||
EXPECT_FALSE(ty->Is<U32>());
|
||||
EXPECT_FALSE(ty->Is<Vector>());
|
||||
}
|
||||
|
||||
TEST_F(DepthTextureTypeTest, IsTextureType) {
|
||||
DepthTextureType d(TextureDimension::kCube);
|
||||
TextureType* ty = &d;
|
||||
EXPECT_TRUE(ty->Is<DepthTextureType>());
|
||||
EXPECT_FALSE(ty->Is<SampledTextureType>());
|
||||
EXPECT_FALSE(ty->Is<StorageTextureType>());
|
||||
TEST_F(DepthTextureTest, IsTexture) {
|
||||
DepthTexture d(TextureDimension::kCube);
|
||||
Texture* ty = &d;
|
||||
EXPECT_TRUE(ty->Is<DepthTexture>());
|
||||
EXPECT_FALSE(ty->Is<SampledTexture>());
|
||||
EXPECT_FALSE(ty->Is<StorageTexture>());
|
||||
}
|
||||
|
||||
TEST_F(DepthTextureTypeTest, Dim) {
|
||||
DepthTextureType d(TextureDimension::kCube);
|
||||
TEST_F(DepthTextureTest, Dim) {
|
||||
DepthTexture d(TextureDimension::kCube);
|
||||
EXPECT_EQ(d.dim(), TextureDimension::kCube);
|
||||
}
|
||||
|
||||
TEST_F(DepthTextureTypeTest, TypeName) {
|
||||
DepthTextureType d(TextureDimension::kCube);
|
||||
TEST_F(DepthTextureTest, TypeName) {
|
||||
DepthTexture d(TextureDimension::kCube);
|
||||
EXPECT_EQ(d.type_name(), "__depth_texture_cube");
|
||||
}
|
||||
|
||||
TEST_F(DepthTextureTypeTest, MinBufferBindingSize) {
|
||||
DepthTextureType d(TextureDimension::kCube);
|
||||
TEST_F(DepthTextureTest, MinBufferBindingSize) {
|
||||
DepthTexture d(TextureDimension::kCube);
|
||||
EXPECT_EQ(0u, d.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
|
@ -18,21 +18,21 @@ namespace tint {
|
||||
namespace ast {
|
||||
namespace type {
|
||||
|
||||
F32Type::F32Type() = default;
|
||||
F32::F32() = default;
|
||||
|
||||
F32Type::F32Type(F32Type&&) = default;
|
||||
F32::F32(F32&&) = default;
|
||||
|
||||
F32Type::~F32Type() = default;
|
||||
F32::~F32() = default;
|
||||
|
||||
std::string F32Type::type_name() const {
|
||||
std::string F32::type_name() const {
|
||||
return "__f32";
|
||||
}
|
||||
|
||||
uint64_t F32Type::MinBufferBindingSize(MemoryLayout) const {
|
||||
uint64_t F32::MinBufferBindingSize(MemoryLayout) const {
|
||||
return 4;
|
||||
}
|
||||
|
||||
uint64_t F32Type::BaseAlignment(MemoryLayout) const {
|
||||
uint64_t F32::BaseAlignment(MemoryLayout) const {
|
||||
return 4;
|
||||
}
|
||||
|
||||
|
@ -24,13 +24,13 @@ namespace ast {
|
||||
namespace type {
|
||||
|
||||
/// A float 32 type
|
||||
class F32Type : public Castable<F32Type, Type> {
|
||||
class F32 : public Castable<F32, Type> {
|
||||
public:
|
||||
/// Constructor
|
||||
F32Type();
|
||||
F32();
|
||||
/// Move constructor
|
||||
F32Type(F32Type&&);
|
||||
~F32Type() override;
|
||||
F32(F32&&);
|
||||
~F32() override;
|
||||
|
||||
/// @returns the name for this type
|
||||
std::string type_name() const override;
|
||||
|
@ -31,38 +31,38 @@ namespace ast {
|
||||
namespace type {
|
||||
namespace {
|
||||
|
||||
using F32TypeTest = TestHelper;
|
||||
using F32Test = TestHelper;
|
||||
|
||||
TEST_F(F32TypeTest, Is) {
|
||||
F32Type f;
|
||||
TEST_F(F32Test, Is) {
|
||||
F32 f;
|
||||
Type* ty = &f;
|
||||
EXPECT_FALSE(ty->Is<AccessControlType>());
|
||||
EXPECT_FALSE(ty->Is<AliasType>());
|
||||
EXPECT_FALSE(ty->Is<ArrayType>());
|
||||
EXPECT_FALSE(ty->Is<BoolType>());
|
||||
EXPECT_TRUE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->Is<SamplerType>());
|
||||
EXPECT_FALSE(ty->Is<StructType>());
|
||||
EXPECT_FALSE(ty->Is<TextureType>());
|
||||
EXPECT_FALSE(ty->Is<U32Type>());
|
||||
EXPECT_FALSE(ty->Is<VectorType>());
|
||||
EXPECT_FALSE(ty->Is<AccessControl>());
|
||||
EXPECT_FALSE(ty->Is<Alias>());
|
||||
EXPECT_FALSE(ty->Is<Array>());
|
||||
EXPECT_FALSE(ty->Is<Bool>());
|
||||
EXPECT_TRUE(ty->Is<F32>());
|
||||
EXPECT_FALSE(ty->Is<I32>());
|
||||
EXPECT_FALSE(ty->Is<Matrix>());
|
||||
EXPECT_FALSE(ty->Is<Pointer>());
|
||||
EXPECT_FALSE(ty->Is<Sampler>());
|
||||
EXPECT_FALSE(ty->Is<Struct>());
|
||||
EXPECT_FALSE(ty->Is<Texture>());
|
||||
EXPECT_FALSE(ty->Is<U32>());
|
||||
EXPECT_FALSE(ty->Is<Vector>());
|
||||
}
|
||||
|
||||
TEST_F(F32TypeTest, TypeName) {
|
||||
F32Type f;
|
||||
TEST_F(F32Test, TypeName) {
|
||||
F32 f;
|
||||
EXPECT_EQ(f.type_name(), "__f32");
|
||||
}
|
||||
|
||||
TEST_F(F32TypeTest, MinBufferBindingSize) {
|
||||
F32Type f;
|
||||
TEST_F(F32Test, MinBufferBindingSize) {
|
||||
F32 f;
|
||||
EXPECT_EQ(4u, f.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
TEST_F(F32TypeTest, BaseAlignment) {
|
||||
F32Type f;
|
||||
TEST_F(F32Test, BaseAlignment) {
|
||||
F32 f;
|
||||
EXPECT_EQ(4u, f.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
|
@ -18,21 +18,21 @@ namespace tint {
|
||||
namespace ast {
|
||||
namespace type {
|
||||
|
||||
I32Type::I32Type() = default;
|
||||
I32::I32() = default;
|
||||
|
||||
I32Type::I32Type(I32Type&&) = default;
|
||||
I32::I32(I32&&) = default;
|
||||
|
||||
I32Type::~I32Type() = default;
|
||||
I32::~I32() = default;
|
||||
|
||||
std::string I32Type::type_name() const {
|
||||
std::string I32::type_name() const {
|
||||
return "__i32";
|
||||
}
|
||||
|
||||
uint64_t I32Type::MinBufferBindingSize(MemoryLayout) const {
|
||||
uint64_t I32::MinBufferBindingSize(MemoryLayout) const {
|
||||
return 4;
|
||||
}
|
||||
|
||||
uint64_t I32Type::BaseAlignment(MemoryLayout) const {
|
||||
uint64_t I32::BaseAlignment(MemoryLayout) const {
|
||||
return 4;
|
||||
}
|
||||
|
||||
|
@ -24,13 +24,13 @@ namespace ast {
|
||||
namespace type {
|
||||
|
||||
/// A signed int 32 type.
|
||||
class I32Type : public Castable<I32Type, Type> {
|
||||
class I32 : public Castable<I32, Type> {
|
||||
public:
|
||||
/// Constructor
|
||||
I32Type();
|
||||
I32();
|
||||
/// Move constructor
|
||||
I32Type(I32Type&&);
|
||||
~I32Type() override;
|
||||
I32(I32&&);
|
||||
~I32() override;
|
||||
|
||||
/// @returns the name for this type
|
||||
std::string type_name() const override;
|
||||
|
@ -31,38 +31,38 @@ namespace ast {
|
||||
namespace type {
|
||||
namespace {
|
||||
|
||||
using I32TypeTest = TestHelper;
|
||||
using I32Test = TestHelper;
|
||||
|
||||
TEST_F(I32TypeTest, Is) {
|
||||
I32Type i;
|
||||
TEST_F(I32Test, Is) {
|
||||
I32 i;
|
||||
Type* ty = &i;
|
||||
EXPECT_FALSE(ty->Is<AccessControlType>());
|
||||
EXPECT_FALSE(ty->Is<AliasType>());
|
||||
EXPECT_FALSE(ty->Is<ArrayType>());
|
||||
EXPECT_FALSE(ty->Is<BoolType>());
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_TRUE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->Is<SamplerType>());
|
||||
EXPECT_FALSE(ty->Is<StructType>());
|
||||
EXPECT_FALSE(ty->Is<TextureType>());
|
||||
EXPECT_FALSE(ty->Is<U32Type>());
|
||||
EXPECT_FALSE(ty->Is<VectorType>());
|
||||
EXPECT_FALSE(ty->Is<AccessControl>());
|
||||
EXPECT_FALSE(ty->Is<Alias>());
|
||||
EXPECT_FALSE(ty->Is<Array>());
|
||||
EXPECT_FALSE(ty->Is<Bool>());
|
||||
EXPECT_FALSE(ty->Is<F32>());
|
||||
EXPECT_TRUE(ty->Is<I32>());
|
||||
EXPECT_FALSE(ty->Is<Matrix>());
|
||||
EXPECT_FALSE(ty->Is<Pointer>());
|
||||
EXPECT_FALSE(ty->Is<Sampler>());
|
||||
EXPECT_FALSE(ty->Is<Struct>());
|
||||
EXPECT_FALSE(ty->Is<Texture>());
|
||||
EXPECT_FALSE(ty->Is<U32>());
|
||||
EXPECT_FALSE(ty->Is<Vector>());
|
||||
}
|
||||
|
||||
TEST_F(I32TypeTest, TypeName) {
|
||||
I32Type i;
|
||||
TEST_F(I32Test, TypeName) {
|
||||
I32 i;
|
||||
EXPECT_EQ(i.type_name(), "__i32");
|
||||
}
|
||||
|
||||
TEST_F(I32TypeTest, MinBufferBindingSize) {
|
||||
I32Type i;
|
||||
TEST_F(I32Test, MinBufferBindingSize) {
|
||||
I32 i;
|
||||
EXPECT_EQ(4u, i.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
TEST_F(I32TypeTest, BaseAlignment) {
|
||||
I32Type i;
|
||||
TEST_F(I32Test, BaseAlignment) {
|
||||
I32 i;
|
||||
EXPECT_EQ(4u, i.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ namespace tint {
|
||||
namespace ast {
|
||||
namespace type {
|
||||
|
||||
MatrixType::MatrixType(Type* subtype, uint32_t rows, uint32_t columns)
|
||||
Matrix::Matrix(Type* subtype, uint32_t rows, uint32_t columns)
|
||||
: subtype_(subtype), rows_(rows), columns_(columns) {
|
||||
assert(rows > 1);
|
||||
assert(rows < 5);
|
||||
@ -31,24 +31,24 @@ MatrixType::MatrixType(Type* subtype, uint32_t rows, uint32_t columns)
|
||||
assert(columns < 5);
|
||||
}
|
||||
|
||||
MatrixType::MatrixType(MatrixType&&) = default;
|
||||
Matrix::Matrix(Matrix&&) = default;
|
||||
|
||||
MatrixType::~MatrixType() = default;
|
||||
Matrix::~Matrix() = default;
|
||||
|
||||
std::string MatrixType::type_name() const {
|
||||
std::string Matrix::type_name() const {
|
||||
return "__mat_" + std::to_string(rows_) + "_" + std::to_string(columns_) +
|
||||
subtype_->type_name();
|
||||
}
|
||||
|
||||
uint64_t MatrixType::MinBufferBindingSize(MemoryLayout mem_layout) const {
|
||||
VectorType vec(subtype_, rows_);
|
||||
uint64_t Matrix::MinBufferBindingSize(MemoryLayout mem_layout) const {
|
||||
Vector vec(subtype_, rows_);
|
||||
return (columns_ - 1) * vec.BaseAlignment(mem_layout) +
|
||||
vec.MinBufferBindingSize(mem_layout);
|
||||
}
|
||||
|
||||
uint64_t MatrixType::BaseAlignment(MemoryLayout mem_layout) const {
|
||||
VectorType vec(subtype_, rows_);
|
||||
ArrayType arr(&vec, columns_);
|
||||
uint64_t Matrix::BaseAlignment(MemoryLayout mem_layout) const {
|
||||
Vector vec(subtype_, rows_);
|
||||
Array arr(&vec, columns_);
|
||||
return arr.BaseAlignment(mem_layout);
|
||||
}
|
||||
|
||||
|
@ -24,16 +24,16 @@ namespace ast {
|
||||
namespace type {
|
||||
|
||||
/// A matrix type
|
||||
class MatrixType : public Castable<MatrixType, Type> {
|
||||
class Matrix : public Castable<Matrix, Type> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param subtype type matrix type
|
||||
/// @param rows the number of rows in the matrix
|
||||
/// @param columns the number of columns in the matrix
|
||||
MatrixType(Type* subtype, uint32_t rows, uint32_t columns);
|
||||
Matrix(Type* subtype, uint32_t rows, uint32_t columns);
|
||||
/// Move constructor
|
||||
MatrixType(MatrixType&&);
|
||||
~MatrixType() override;
|
||||
Matrix(Matrix&&);
|
||||
~Matrix() override;
|
||||
|
||||
/// @returns the type of the matrix
|
||||
Type* type() const { return subtype_; }
|
||||
|
@ -31,93 +31,93 @@ namespace ast {
|
||||
namespace type {
|
||||
namespace {
|
||||
|
||||
using MatrixTypeTest = TestHelper;
|
||||
using MatrixTest = TestHelper;
|
||||
|
||||
TEST_F(MatrixTypeTest, Creation) {
|
||||
I32Type i32;
|
||||
MatrixType m{&i32, 2, 4};
|
||||
TEST_F(MatrixTest, Creation) {
|
||||
I32 i32;
|
||||
Matrix m{&i32, 2, 4};
|
||||
EXPECT_EQ(m.type(), &i32);
|
||||
EXPECT_EQ(m.rows(), 2u);
|
||||
EXPECT_EQ(m.columns(), 4u);
|
||||
}
|
||||
|
||||
TEST_F(MatrixTypeTest, Is) {
|
||||
I32Type i32;
|
||||
MatrixType m{&i32, 2, 3};
|
||||
TEST_F(MatrixTest, Is) {
|
||||
I32 i32;
|
||||
Matrix m{&i32, 2, 3};
|
||||
Type* ty = &m;
|
||||
EXPECT_FALSE(ty->Is<AccessControlType>());
|
||||
EXPECT_FALSE(ty->Is<AliasType>());
|
||||
EXPECT_FALSE(ty->Is<ArrayType>());
|
||||
EXPECT_FALSE(ty->Is<BoolType>());
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_TRUE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->Is<SamplerType>());
|
||||
EXPECT_FALSE(ty->Is<StructType>());
|
||||
EXPECT_FALSE(ty->Is<TextureType>());
|
||||
EXPECT_FALSE(ty->Is<U32Type>());
|
||||
EXPECT_FALSE(ty->Is<VectorType>());
|
||||
EXPECT_FALSE(ty->Is<AccessControl>());
|
||||
EXPECT_FALSE(ty->Is<Alias>());
|
||||
EXPECT_FALSE(ty->Is<Array>());
|
||||
EXPECT_FALSE(ty->Is<Bool>());
|
||||
EXPECT_FALSE(ty->Is<F32>());
|
||||
EXPECT_FALSE(ty->Is<I32>());
|
||||
EXPECT_TRUE(ty->Is<Matrix>());
|
||||
EXPECT_FALSE(ty->Is<Pointer>());
|
||||
EXPECT_FALSE(ty->Is<Sampler>());
|
||||
EXPECT_FALSE(ty->Is<Struct>());
|
||||
EXPECT_FALSE(ty->Is<Texture>());
|
||||
EXPECT_FALSE(ty->Is<U32>());
|
||||
EXPECT_FALSE(ty->Is<Vector>());
|
||||
}
|
||||
|
||||
TEST_F(MatrixTypeTest, TypeName) {
|
||||
I32Type i32;
|
||||
MatrixType m{&i32, 2, 3};
|
||||
TEST_F(MatrixTest, TypeName) {
|
||||
I32 i32;
|
||||
Matrix m{&i32, 2, 3};
|
||||
EXPECT_EQ(m.type_name(), "__mat_2_3__i32");
|
||||
}
|
||||
|
||||
TEST_F(MatrixTypeTest, MinBufferBindingSize4x2) {
|
||||
I32Type i32;
|
||||
MatrixType m{&i32, 4, 2};
|
||||
TEST_F(MatrixTest, MinBufferBindingSize4x2) {
|
||||
I32 i32;
|
||||
Matrix m{&i32, 4, 2};
|
||||
EXPECT_EQ(32u, m.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(32u, m.MinBufferBindingSize(MemoryLayout::kStorageBuffer));
|
||||
}
|
||||
|
||||
TEST_F(MatrixTypeTest, MinBufferBindingSize3x2) {
|
||||
I32Type i32;
|
||||
MatrixType m{&i32, 3, 2};
|
||||
TEST_F(MatrixTest, MinBufferBindingSize3x2) {
|
||||
I32 i32;
|
||||
Matrix m{&i32, 3, 2};
|
||||
EXPECT_EQ(28u, m.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(28u, m.MinBufferBindingSize(MemoryLayout::kStorageBuffer));
|
||||
}
|
||||
|
||||
TEST_F(MatrixTypeTest, MinBufferBindingSize2x3) {
|
||||
I32Type i32;
|
||||
MatrixType m{&i32, 2, 3};
|
||||
TEST_F(MatrixTest, MinBufferBindingSize2x3) {
|
||||
I32 i32;
|
||||
Matrix m{&i32, 2, 3};
|
||||
EXPECT_EQ(24u, m.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(24u, m.MinBufferBindingSize(MemoryLayout::kStorageBuffer));
|
||||
}
|
||||
|
||||
TEST_F(MatrixTypeTest, MinBufferBindingSize2x2) {
|
||||
I32Type i32;
|
||||
MatrixType m{&i32, 2, 2};
|
||||
TEST_F(MatrixTest, MinBufferBindingSize2x2) {
|
||||
I32 i32;
|
||||
Matrix m{&i32, 2, 2};
|
||||
EXPECT_EQ(16u, m.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(16u, m.MinBufferBindingSize(MemoryLayout::kStorageBuffer));
|
||||
}
|
||||
|
||||
TEST_F(MatrixTypeTest, BaseAlignment4x2) {
|
||||
I32Type i32;
|
||||
MatrixType m{&i32, 4, 2};
|
||||
TEST_F(MatrixTest, BaseAlignment4x2) {
|
||||
I32 i32;
|
||||
Matrix m{&i32, 4, 2};
|
||||
EXPECT_EQ(16u, m.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(16u, m.BaseAlignment(MemoryLayout::kStorageBuffer));
|
||||
}
|
||||
|
||||
TEST_F(MatrixTypeTest, BaseAlignment3x2) {
|
||||
I32Type i32;
|
||||
MatrixType m{&i32, 3, 2};
|
||||
TEST_F(MatrixTest, BaseAlignment3x2) {
|
||||
I32 i32;
|
||||
Matrix m{&i32, 3, 2};
|
||||
EXPECT_EQ(16u, m.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(16u, m.BaseAlignment(MemoryLayout::kStorageBuffer));
|
||||
}
|
||||
|
||||
TEST_F(MatrixTypeTest, BaseAlignment2x3) {
|
||||
I32Type i32;
|
||||
MatrixType m{&i32, 2, 3};
|
||||
TEST_F(MatrixTest, BaseAlignment2x3) {
|
||||
I32 i32;
|
||||
Matrix m{&i32, 2, 3};
|
||||
EXPECT_EQ(16u, m.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(8u, m.BaseAlignment(MemoryLayout::kStorageBuffer));
|
||||
}
|
||||
|
||||
TEST_F(MatrixTypeTest, BaseAlignment2x2) {
|
||||
I32Type i32;
|
||||
MatrixType m{&i32, 2, 2};
|
||||
TEST_F(MatrixTest, BaseAlignment2x2) {
|
||||
I32 i32;
|
||||
Matrix m{&i32, 2, 2};
|
||||
EXPECT_EQ(16u, m.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(8u, m.BaseAlignment(MemoryLayout::kStorageBuffer));
|
||||
}
|
||||
|
@ -21,19 +21,16 @@ namespace tint {
|
||||
namespace ast {
|
||||
namespace type {
|
||||
|
||||
MultisampledTextureType::MultisampledTextureType(TextureDimension dim,
|
||||
Type* type)
|
||||
MultisampledTexture::MultisampledTexture(TextureDimension dim, Type* type)
|
||||
: Base(dim), type_(type) {
|
||||
assert(type_);
|
||||
}
|
||||
|
||||
MultisampledTextureType::MultisampledTextureType(MultisampledTextureType&&) =
|
||||
default;
|
||||
MultisampledTexture::MultisampledTexture(MultisampledTexture&&) = default;
|
||||
|
||||
MultisampledTextureType::~MultisampledTextureType() = default;
|
||||
MultisampledTexture::~MultisampledTexture() = default;
|
||||
|
||||
|
||||
std::string MultisampledTextureType::type_name() const {
|
||||
std::string MultisampledTexture::type_name() const {
|
||||
std::ostringstream out;
|
||||
out << "__multisampled_texture_" << dim() << type_->type_name();
|
||||
return out.str();
|
||||
|
@ -24,16 +24,15 @@ namespace ast {
|
||||
namespace type {
|
||||
|
||||
/// A multisampled texture type.
|
||||
class MultisampledTextureType
|
||||
: public Castable<MultisampledTextureType, TextureType> {
|
||||
class MultisampledTexture : public Castable<MultisampledTexture, Texture> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param dim the dimensionality of the texture
|
||||
/// @param type the data type of the multisampled texture
|
||||
MultisampledTextureType(TextureDimension dim, Type* type);
|
||||
MultisampledTexture(TextureDimension dim, Type* type);
|
||||
/// Move constructor
|
||||
MultisampledTextureType(MultisampledTextureType&&);
|
||||
~MultisampledTextureType() override;
|
||||
MultisampledTexture(MultisampledTexture&&);
|
||||
~MultisampledTexture() override;
|
||||
|
||||
/// @returns the subtype of the sampled texture
|
||||
Type* type() const { return type_; }
|
||||
|
@ -34,58 +34,58 @@ namespace ast {
|
||||
namespace type {
|
||||
namespace {
|
||||
|
||||
using MultisampledTextureTypeTest = TestHelper;
|
||||
using MultisampledTextureTest = TestHelper;
|
||||
|
||||
TEST_F(MultisampledTextureTypeTest, Is) {
|
||||
F32Type f32;
|
||||
MultisampledTextureType s(TextureDimension::kCube, &f32);
|
||||
TEST_F(MultisampledTextureTest, Is) {
|
||||
F32 f32;
|
||||
MultisampledTexture s(TextureDimension::kCube, &f32);
|
||||
Type* ty = &s;
|
||||
EXPECT_FALSE(ty->Is<AccessControlType>());
|
||||
EXPECT_FALSE(ty->Is<AliasType>());
|
||||
EXPECT_FALSE(ty->Is<ArrayType>());
|
||||
EXPECT_FALSE(ty->Is<BoolType>());
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->Is<SamplerType>());
|
||||
EXPECT_FALSE(ty->Is<StructType>());
|
||||
EXPECT_TRUE(ty->Is<TextureType>());
|
||||
EXPECT_FALSE(ty->Is<U32Type>());
|
||||
EXPECT_FALSE(ty->Is<VectorType>());
|
||||
EXPECT_FALSE(ty->Is<AccessControl>());
|
||||
EXPECT_FALSE(ty->Is<Alias>());
|
||||
EXPECT_FALSE(ty->Is<Array>());
|
||||
EXPECT_FALSE(ty->Is<Bool>());
|
||||
EXPECT_FALSE(ty->Is<F32>());
|
||||
EXPECT_FALSE(ty->Is<I32>());
|
||||
EXPECT_FALSE(ty->Is<Matrix>());
|
||||
EXPECT_FALSE(ty->Is<Pointer>());
|
||||
EXPECT_FALSE(ty->Is<Sampler>());
|
||||
EXPECT_FALSE(ty->Is<Struct>());
|
||||
EXPECT_TRUE(ty->Is<Texture>());
|
||||
EXPECT_FALSE(ty->Is<U32>());
|
||||
EXPECT_FALSE(ty->Is<Vector>());
|
||||
}
|
||||
|
||||
TEST_F(MultisampledTextureTypeTest, IsTextureType) {
|
||||
F32Type f32;
|
||||
MultisampledTextureType s(TextureDimension::kCube, &f32);
|
||||
TextureType* ty = &s;
|
||||
EXPECT_FALSE(ty->Is<DepthTextureType>());
|
||||
EXPECT_TRUE(ty->Is<MultisampledTextureType>());
|
||||
EXPECT_FALSE(ty->Is<SampledTextureType>());
|
||||
EXPECT_FALSE(ty->Is<StorageTextureType>());
|
||||
TEST_F(MultisampledTextureTest, IsTexture) {
|
||||
F32 f32;
|
||||
MultisampledTexture s(TextureDimension::kCube, &f32);
|
||||
Texture* ty = &s;
|
||||
EXPECT_FALSE(ty->Is<DepthTexture>());
|
||||
EXPECT_TRUE(ty->Is<MultisampledTexture>());
|
||||
EXPECT_FALSE(ty->Is<SampledTexture>());
|
||||
EXPECT_FALSE(ty->Is<StorageTexture>());
|
||||
}
|
||||
|
||||
TEST_F(MultisampledTextureTypeTest, Dim) {
|
||||
F32Type f32;
|
||||
MultisampledTextureType s(TextureDimension::k3d, &f32);
|
||||
TEST_F(MultisampledTextureTest, Dim) {
|
||||
F32 f32;
|
||||
MultisampledTexture s(TextureDimension::k3d, &f32);
|
||||
EXPECT_EQ(s.dim(), TextureDimension::k3d);
|
||||
}
|
||||
|
||||
TEST_F(MultisampledTextureTypeTest, Type) {
|
||||
F32Type f32;
|
||||
MultisampledTextureType s(TextureDimension::k3d, &f32);
|
||||
TEST_F(MultisampledTextureTest, Type) {
|
||||
F32 f32;
|
||||
MultisampledTexture s(TextureDimension::k3d, &f32);
|
||||
EXPECT_EQ(s.type(), &f32);
|
||||
}
|
||||
|
||||
TEST_F(MultisampledTextureTypeTest, TypeName) {
|
||||
F32Type f32;
|
||||
MultisampledTextureType s(TextureDimension::k3d, &f32);
|
||||
TEST_F(MultisampledTextureTest, TypeName) {
|
||||
F32 f32;
|
||||
MultisampledTexture s(TextureDimension::k3d, &f32);
|
||||
EXPECT_EQ(s.type_name(), "__multisampled_texture_3d__f32");
|
||||
}
|
||||
|
||||
TEST_F(MultisampledTextureTypeTest, MinBufferBindingSize) {
|
||||
F32Type f32;
|
||||
MultisampledTextureType s(TextureDimension::k3d, &f32);
|
||||
TEST_F(MultisampledTextureTest, MinBufferBindingSize) {
|
||||
F32 f32;
|
||||
MultisampledTexture s(TextureDimension::k3d, &f32);
|
||||
EXPECT_EQ(0u, s.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
|
@ -18,18 +18,18 @@ namespace tint {
|
||||
namespace ast {
|
||||
namespace type {
|
||||
|
||||
PointerType::PointerType(Type* subtype, StorageClass storage_class)
|
||||
Pointer::Pointer(Type* subtype, StorageClass storage_class)
|
||||
: subtype_(subtype), storage_class_(storage_class) {}
|
||||
|
||||
std::string PointerType::type_name() const {
|
||||
std::string Pointer::type_name() const {
|
||||
std::ostringstream out;
|
||||
out << "__ptr_" << storage_class_ << subtype_->type_name();
|
||||
return out.str();
|
||||
}
|
||||
|
||||
PointerType::PointerType(PointerType&&) = default;
|
||||
Pointer::Pointer(Pointer&&) = default;
|
||||
|
||||
PointerType::~PointerType() = default;
|
||||
Pointer::~Pointer() = default;
|
||||
|
||||
} // namespace type
|
||||
} // namespace ast
|
||||
|
@ -26,15 +26,15 @@ namespace ast {
|
||||
namespace type {
|
||||
|
||||
/// A pointer type.
|
||||
class PointerType : public Castable<PointerType, Type> {
|
||||
class Pointer : public Castable<Pointer, Type> {
|
||||
public:
|
||||
/// Construtor
|
||||
/// @param subtype the pointee type
|
||||
/// @param storage_class the storage class of the pointer
|
||||
explicit PointerType(Type* subtype, StorageClass storage_class);
|
||||
explicit Pointer(Type* subtype, StorageClass storage_class);
|
||||
/// Move constructor
|
||||
PointerType(PointerType&&);
|
||||
~PointerType() override;
|
||||
Pointer(Pointer&&);
|
||||
~Pointer() override;
|
||||
|
||||
/// @returns the pointee type
|
||||
Type* type() const { return subtype_; }
|
||||
|
@ -31,37 +31,37 @@ namespace ast {
|
||||
namespace type {
|
||||
namespace {
|
||||
|
||||
using PointerTypeTest = TestHelper;
|
||||
using PointerTest = TestHelper;
|
||||
|
||||
TEST_F(PointerTypeTest, Creation) {
|
||||
I32Type i32;
|
||||
PointerType p{&i32, StorageClass::kStorageBuffer};
|
||||
TEST_F(PointerTest, Creation) {
|
||||
I32 i32;
|
||||
Pointer p{&i32, StorageClass::kStorageBuffer};
|
||||
EXPECT_EQ(p.type(), &i32);
|
||||
EXPECT_EQ(p.storage_class(), StorageClass::kStorageBuffer);
|
||||
}
|
||||
|
||||
TEST_F(PointerTypeTest, Is) {
|
||||
I32Type i32;
|
||||
PointerType p{&i32, StorageClass::kFunction};
|
||||
TEST_F(PointerTest, Is) {
|
||||
I32 i32;
|
||||
Pointer p{&i32, StorageClass::kFunction};
|
||||
Type* ty = &p;
|
||||
EXPECT_FALSE(ty->Is<AccessControlType>());
|
||||
EXPECT_FALSE(ty->Is<AliasType>());
|
||||
EXPECT_FALSE(ty->Is<ArrayType>());
|
||||
EXPECT_FALSE(ty->Is<BoolType>());
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_TRUE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->Is<SamplerType>());
|
||||
EXPECT_FALSE(ty->Is<StructType>());
|
||||
EXPECT_FALSE(ty->Is<TextureType>());
|
||||
EXPECT_FALSE(ty->Is<U32Type>());
|
||||
EXPECT_FALSE(ty->Is<VectorType>());
|
||||
EXPECT_FALSE(ty->Is<AccessControl>());
|
||||
EXPECT_FALSE(ty->Is<Alias>());
|
||||
EXPECT_FALSE(ty->Is<Array>());
|
||||
EXPECT_FALSE(ty->Is<Bool>());
|
||||
EXPECT_FALSE(ty->Is<F32>());
|
||||
EXPECT_FALSE(ty->Is<I32>());
|
||||
EXPECT_FALSE(ty->Is<Matrix>());
|
||||
EXPECT_TRUE(ty->Is<Pointer>());
|
||||
EXPECT_FALSE(ty->Is<Sampler>());
|
||||
EXPECT_FALSE(ty->Is<Struct>());
|
||||
EXPECT_FALSE(ty->Is<Texture>());
|
||||
EXPECT_FALSE(ty->Is<U32>());
|
||||
EXPECT_FALSE(ty->Is<Vector>());
|
||||
}
|
||||
|
||||
TEST_F(PointerTypeTest, TypeName) {
|
||||
I32Type i32;
|
||||
PointerType p{&i32, StorageClass::kWorkgroup};
|
||||
TEST_F(PointerTest, TypeName) {
|
||||
I32 i32;
|
||||
Pointer p{&i32, StorageClass::kWorkgroup};
|
||||
EXPECT_EQ(p.type_name(), "__ptr_workgroup__i32");
|
||||
}
|
||||
|
||||
|
@ -21,16 +21,16 @@ namespace tint {
|
||||
namespace ast {
|
||||
namespace type {
|
||||
|
||||
SampledTextureType::SampledTextureType(TextureDimension dim, Type* type)
|
||||
SampledTexture::SampledTexture(TextureDimension dim, Type* type)
|
||||
: Base(dim), type_(type) {
|
||||
assert(type_);
|
||||
}
|
||||
|
||||
SampledTextureType::SampledTextureType(SampledTextureType&&) = default;
|
||||
SampledTexture::SampledTexture(SampledTexture&&) = default;
|
||||
|
||||
SampledTextureType::~SampledTextureType() = default;
|
||||
SampledTexture::~SampledTexture() = default;
|
||||
|
||||
std::string SampledTextureType::type_name() const {
|
||||
std::string SampledTexture::type_name() const {
|
||||
std::ostringstream out;
|
||||
out << "__sampled_texture_" << dim() << type_->type_name();
|
||||
return out.str();
|
||||
|
@ -24,15 +24,15 @@ namespace ast {
|
||||
namespace type {
|
||||
|
||||
/// A sampled texture type.
|
||||
class SampledTextureType : public Castable<SampledTextureType, TextureType> {
|
||||
class SampledTexture : public Castable<SampledTexture, Texture> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param dim the dimensionality of the texture
|
||||
/// @param type the data type of the sampled texture
|
||||
SampledTextureType(TextureDimension dim, Type* type);
|
||||
SampledTexture(TextureDimension dim, Type* type);
|
||||
/// Move constructor
|
||||
SampledTextureType(SampledTextureType&&);
|
||||
~SampledTextureType() override;
|
||||
SampledTexture(SampledTexture&&);
|
||||
~SampledTexture() override;
|
||||
|
||||
/// @returns the subtype of the sampled texture
|
||||
Type* type() const { return type_; }
|
||||
|
@ -33,57 +33,57 @@ namespace ast {
|
||||
namespace type {
|
||||
namespace {
|
||||
|
||||
using SampledTextureTypeTest = TestHelper;
|
||||
using SampledTextureTest = TestHelper;
|
||||
|
||||
TEST_F(SampledTextureTypeTest, Is) {
|
||||
F32Type f32;
|
||||
SampledTextureType s(TextureDimension::kCube, &f32);
|
||||
TEST_F(SampledTextureTest, Is) {
|
||||
F32 f32;
|
||||
SampledTexture s(TextureDimension::kCube, &f32);
|
||||
Type* ty = &s;
|
||||
EXPECT_FALSE(ty->Is<AccessControlType>());
|
||||
EXPECT_FALSE(ty->Is<AliasType>());
|
||||
EXPECT_FALSE(ty->Is<ArrayType>());
|
||||
EXPECT_FALSE(ty->Is<BoolType>());
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->Is<SamplerType>());
|
||||
EXPECT_FALSE(ty->Is<StructType>());
|
||||
EXPECT_TRUE(ty->Is<TextureType>());
|
||||
EXPECT_FALSE(ty->Is<U32Type>());
|
||||
EXPECT_FALSE(ty->Is<VectorType>());
|
||||
EXPECT_FALSE(ty->Is<AccessControl>());
|
||||
EXPECT_FALSE(ty->Is<Alias>());
|
||||
EXPECT_FALSE(ty->Is<Array>());
|
||||
EXPECT_FALSE(ty->Is<Bool>());
|
||||
EXPECT_FALSE(ty->Is<F32>());
|
||||
EXPECT_FALSE(ty->Is<I32>());
|
||||
EXPECT_FALSE(ty->Is<Matrix>());
|
||||
EXPECT_FALSE(ty->Is<Pointer>());
|
||||
EXPECT_FALSE(ty->Is<Sampler>());
|
||||
EXPECT_FALSE(ty->Is<Struct>());
|
||||
EXPECT_TRUE(ty->Is<Texture>());
|
||||
EXPECT_FALSE(ty->Is<U32>());
|
||||
EXPECT_FALSE(ty->Is<Vector>());
|
||||
}
|
||||
|
||||
TEST_F(SampledTextureTypeTest, IsTextureType) {
|
||||
F32Type f32;
|
||||
SampledTextureType s(TextureDimension::kCube, &f32);
|
||||
TextureType* ty = &s;
|
||||
EXPECT_FALSE(ty->Is<DepthTextureType>());
|
||||
EXPECT_TRUE(ty->Is<SampledTextureType>());
|
||||
EXPECT_FALSE(ty->Is<StorageTextureType>());
|
||||
TEST_F(SampledTextureTest, IsTexture) {
|
||||
F32 f32;
|
||||
SampledTexture s(TextureDimension::kCube, &f32);
|
||||
Texture* ty = &s;
|
||||
EXPECT_FALSE(ty->Is<DepthTexture>());
|
||||
EXPECT_TRUE(ty->Is<SampledTexture>());
|
||||
EXPECT_FALSE(ty->Is<StorageTexture>());
|
||||
}
|
||||
|
||||
TEST_F(SampledTextureTypeTest, Dim) {
|
||||
F32Type f32;
|
||||
SampledTextureType s(TextureDimension::k3d, &f32);
|
||||
TEST_F(SampledTextureTest, Dim) {
|
||||
F32 f32;
|
||||
SampledTexture s(TextureDimension::k3d, &f32);
|
||||
EXPECT_EQ(s.dim(), TextureDimension::k3d);
|
||||
}
|
||||
|
||||
TEST_F(SampledTextureTypeTest, Type) {
|
||||
F32Type f32;
|
||||
SampledTextureType s(TextureDimension::k3d, &f32);
|
||||
TEST_F(SampledTextureTest, Type) {
|
||||
F32 f32;
|
||||
SampledTexture s(TextureDimension::k3d, &f32);
|
||||
EXPECT_EQ(s.type(), &f32);
|
||||
}
|
||||
|
||||
TEST_F(SampledTextureTypeTest, TypeName) {
|
||||
F32Type f32;
|
||||
SampledTextureType s(TextureDimension::k3d, &f32);
|
||||
TEST_F(SampledTextureTest, TypeName) {
|
||||
F32 f32;
|
||||
SampledTexture s(TextureDimension::k3d, &f32);
|
||||
EXPECT_EQ(s.type_name(), "__sampled_texture_3d__f32");
|
||||
}
|
||||
|
||||
TEST_F(SampledTextureTypeTest, MinBufferBindingSize) {
|
||||
F32Type f32;
|
||||
SampledTextureType s(TextureDimension::kCube, &f32);
|
||||
TEST_F(SampledTextureTest, MinBufferBindingSize) {
|
||||
F32 f32;
|
||||
SampledTexture s(TextureDimension::kCube, &f32);
|
||||
EXPECT_EQ(0u, s.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
|
@ -30,13 +30,13 @@ std::ostream& operator<<(std::ostream& out, SamplerKind kind) {
|
||||
return out;
|
||||
}
|
||||
|
||||
SamplerType::SamplerType(SamplerKind kind) : kind_(kind) {}
|
||||
Sampler::Sampler(SamplerKind kind) : kind_(kind) {}
|
||||
|
||||
SamplerType::SamplerType(SamplerType&&) = default;
|
||||
Sampler::Sampler(Sampler&&) = default;
|
||||
|
||||
SamplerType::~SamplerType() = default;
|
||||
Sampler::~Sampler() = default;
|
||||
|
||||
std::string SamplerType::type_name() const {
|
||||
std::string Sampler::type_name() const {
|
||||
return std::string("__sampler_") +
|
||||
(kind_ == SamplerKind::kSampler ? "sampler" : "comparison");
|
||||
}
|
||||
|
@ -34,14 +34,14 @@ enum class SamplerKind {
|
||||
std::ostream& operator<<(std::ostream& out, SamplerKind kind);
|
||||
|
||||
/// A sampler type.
|
||||
class SamplerType : public Castable<SamplerType, Type> {
|
||||
class Sampler : public Castable<Sampler, Type> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param kind the kind of sampler
|
||||
explicit SamplerType(SamplerKind kind);
|
||||
explicit Sampler(SamplerKind kind);
|
||||
/// Move constructor
|
||||
SamplerType(SamplerType&&);
|
||||
~SamplerType() override;
|
||||
Sampler(Sampler&&);
|
||||
~Sampler() override;
|
||||
|
||||
/// @returns the sampler type
|
||||
SamplerKind kind() const { return kind_; }
|
||||
|
@ -32,49 +32,49 @@ namespace ast {
|
||||
namespace type {
|
||||
namespace {
|
||||
|
||||
using SamplerTypeTest = TestHelper;
|
||||
using SamplerTest = TestHelper;
|
||||
|
||||
TEST_F(SamplerTypeTest, Creation) {
|
||||
SamplerType s{SamplerKind::kSampler};
|
||||
TEST_F(SamplerTest, Creation) {
|
||||
Sampler s{SamplerKind::kSampler};
|
||||
EXPECT_EQ(s.kind(), SamplerKind::kSampler);
|
||||
}
|
||||
|
||||
TEST_F(SamplerTypeTest, Creation_ComparisonSampler) {
|
||||
SamplerType s{SamplerKind::kComparisonSampler};
|
||||
TEST_F(SamplerTest, Creation_ComparisonSampler) {
|
||||
Sampler s{SamplerKind::kComparisonSampler};
|
||||
EXPECT_EQ(s.kind(), SamplerKind::kComparisonSampler);
|
||||
EXPECT_TRUE(s.IsComparison());
|
||||
}
|
||||
|
||||
TEST_F(SamplerTypeTest, Is) {
|
||||
SamplerType s{SamplerKind::kSampler};
|
||||
TEST_F(SamplerTest, Is) {
|
||||
Sampler s{SamplerKind::kSampler};
|
||||
Type* ty = &s;
|
||||
EXPECT_FALSE(ty->Is<AccessControlType>());
|
||||
EXPECT_FALSE(ty->Is<AliasType>());
|
||||
EXPECT_FALSE(ty->Is<ArrayType>());
|
||||
EXPECT_FALSE(ty->Is<BoolType>());
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_TRUE(ty->Is<SamplerType>());
|
||||
EXPECT_FALSE(ty->Is<StructType>());
|
||||
EXPECT_FALSE(ty->Is<TextureType>());
|
||||
EXPECT_FALSE(ty->Is<U32Type>());
|
||||
EXPECT_FALSE(ty->Is<VectorType>());
|
||||
EXPECT_FALSE(ty->Is<AccessControl>());
|
||||
EXPECT_FALSE(ty->Is<Alias>());
|
||||
EXPECT_FALSE(ty->Is<Array>());
|
||||
EXPECT_FALSE(ty->Is<Bool>());
|
||||
EXPECT_FALSE(ty->Is<F32>());
|
||||
EXPECT_FALSE(ty->Is<I32>());
|
||||
EXPECT_FALSE(ty->Is<Matrix>());
|
||||
EXPECT_FALSE(ty->Is<Pointer>());
|
||||
EXPECT_TRUE(ty->Is<Sampler>());
|
||||
EXPECT_FALSE(ty->Is<Struct>());
|
||||
EXPECT_FALSE(ty->Is<Texture>());
|
||||
EXPECT_FALSE(ty->Is<U32>());
|
||||
EXPECT_FALSE(ty->Is<Vector>());
|
||||
}
|
||||
|
||||
TEST_F(SamplerTypeTest, TypeName_Sampler) {
|
||||
SamplerType s{SamplerKind::kSampler};
|
||||
TEST_F(SamplerTest, TypeName_Sampler) {
|
||||
Sampler s{SamplerKind::kSampler};
|
||||
EXPECT_EQ(s.type_name(), "__sampler_sampler");
|
||||
}
|
||||
|
||||
TEST_F(SamplerTypeTest, TypeName_Comparison) {
|
||||
SamplerType s{SamplerKind::kComparisonSampler};
|
||||
TEST_F(SamplerTest, TypeName_Comparison) {
|
||||
Sampler s{SamplerKind::kComparisonSampler};
|
||||
EXPECT_EQ(s.type_name(), "__sampler_comparison");
|
||||
}
|
||||
|
||||
TEST_F(SamplerTypeTest, MinBufferBindingSize) {
|
||||
SamplerType s{SamplerKind::kSampler};
|
||||
TEST_F(SamplerTest, MinBufferBindingSize) {
|
||||
Sampler s{SamplerKind::kSampler};
|
||||
EXPECT_EQ(0u, s.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
|
@ -150,26 +150,26 @@ std::ostream& operator<<(std::ostream& out, ImageFormat format) {
|
||||
return out;
|
||||
}
|
||||
|
||||
StorageTextureType::StorageTextureType(TextureDimension dim,
|
||||
AccessControl access,
|
||||
ImageFormat format)
|
||||
StorageTexture::StorageTexture(TextureDimension dim,
|
||||
ast::AccessControl access,
|
||||
ImageFormat format)
|
||||
: Base(dim), access_(access), image_format_(format) {
|
||||
assert(IsValidStorageDimension(dim));
|
||||
}
|
||||
|
||||
void StorageTextureType::set_type(Type* const type) {
|
||||
void StorageTexture::set_type(Type* const type) {
|
||||
type_ = type;
|
||||
}
|
||||
|
||||
Type* StorageTextureType::type() const {
|
||||
Type* StorageTexture::type() const {
|
||||
return type_;
|
||||
}
|
||||
|
||||
StorageTextureType::StorageTextureType(StorageTextureType&&) = default;
|
||||
StorageTexture::StorageTexture(StorageTexture&&) = default;
|
||||
|
||||
StorageTextureType::~StorageTextureType() = default;
|
||||
StorageTexture::~StorageTexture() = default;
|
||||
|
||||
std::string StorageTextureType::type_name() const {
|
||||
std::string StorageTexture::type_name() const {
|
||||
std::ostringstream out;
|
||||
out << "__storage_texture_" << access_ << "_" << dim() << "_"
|
||||
<< image_format_;
|
||||
|
@ -66,19 +66,19 @@ enum class ImageFormat {
|
||||
std::ostream& operator<<(std::ostream& out, ImageFormat dim);
|
||||
|
||||
/// A storage texture type.
|
||||
class StorageTextureType : public Castable<StorageTextureType, TextureType> {
|
||||
class StorageTexture : public Castable<StorageTexture, Texture> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param dim the dimensionality of the texture
|
||||
/// @param access the access type for the texture
|
||||
/// @param format the image format of the texture
|
||||
StorageTextureType(TextureDimension dim,
|
||||
AccessControl access,
|
||||
ImageFormat format);
|
||||
StorageTexture(TextureDimension dim,
|
||||
ast::AccessControl access,
|
||||
ImageFormat format);
|
||||
|
||||
/// Move constructor
|
||||
StorageTextureType(StorageTextureType&&);
|
||||
~StorageTextureType() override;
|
||||
StorageTexture(StorageTexture&&);
|
||||
~StorageTexture() override;
|
||||
|
||||
/// @param type the subtype of the storage texture
|
||||
void set_type(Type* const type);
|
||||
@ -87,7 +87,7 @@ class StorageTextureType : public Castable<StorageTextureType, TextureType> {
|
||||
Type* type() const;
|
||||
|
||||
/// @returns the storage access
|
||||
AccessControl access() const { return access_; }
|
||||
ast::AccessControl access() const { return access_; }
|
||||
|
||||
/// @returns the image format
|
||||
ImageFormat image_format() const { return image_format_; }
|
||||
@ -97,7 +97,7 @@ class StorageTextureType : public Castable<StorageTextureType, TextureType> {
|
||||
|
||||
private:
|
||||
Type* type_ = nullptr;
|
||||
AccessControl access_ = AccessControl::kReadOnly;
|
||||
ast::AccessControl access_ = ast::AccessControl::kReadOnly;
|
||||
ImageFormat image_format_ = ImageFormat::kRgba32Float;
|
||||
};
|
||||
|
||||
|
@ -37,107 +37,105 @@ namespace ast {
|
||||
namespace type {
|
||||
namespace {
|
||||
|
||||
using StorageTextureTypeTest = TestHelper;
|
||||
using StorageTextureTest = TestHelper;
|
||||
|
||||
TEST_F(StorageTextureTypeTest, Is) {
|
||||
StorageTextureType s(TextureDimension::k2dArray, AccessControl::kReadOnly,
|
||||
ImageFormat::kRgba32Float);
|
||||
TEST_F(StorageTextureTest, Is) {
|
||||
StorageTexture s(TextureDimension::k2dArray, ast::AccessControl::kReadOnly,
|
||||
ImageFormat::kRgba32Float);
|
||||
Type* ty = &s;
|
||||
EXPECT_FALSE(ty->Is<AccessControlType>());
|
||||
EXPECT_FALSE(ty->Is<AliasType>());
|
||||
EXPECT_FALSE(ty->Is<ArrayType>());
|
||||
EXPECT_FALSE(ty->Is<BoolType>());
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->Is<SamplerType>());
|
||||
EXPECT_FALSE(ty->Is<StructType>());
|
||||
EXPECT_TRUE(ty->Is<TextureType>());
|
||||
EXPECT_FALSE(ty->Is<U32Type>());
|
||||
EXPECT_FALSE(ty->Is<VectorType>());
|
||||
EXPECT_FALSE(ty->Is<AccessControl>());
|
||||
EXPECT_FALSE(ty->Is<Alias>());
|
||||
EXPECT_FALSE(ty->Is<Array>());
|
||||
EXPECT_FALSE(ty->Is<Bool>());
|
||||
EXPECT_FALSE(ty->Is<F32>());
|
||||
EXPECT_FALSE(ty->Is<I32>());
|
||||
EXPECT_FALSE(ty->Is<Matrix>());
|
||||
EXPECT_FALSE(ty->Is<Pointer>());
|
||||
EXPECT_FALSE(ty->Is<Sampler>());
|
||||
EXPECT_FALSE(ty->Is<Struct>());
|
||||
EXPECT_TRUE(ty->Is<Texture>());
|
||||
EXPECT_FALSE(ty->Is<U32>());
|
||||
EXPECT_FALSE(ty->Is<Vector>());
|
||||
}
|
||||
|
||||
TEST_F(StorageTextureTypeTest, IsTextureType) {
|
||||
StorageTextureType s(TextureDimension::k2dArray, AccessControl::kReadOnly,
|
||||
ImageFormat::kRgba32Float);
|
||||
TextureType* ty = &s;
|
||||
EXPECT_FALSE(ty->Is<DepthTextureType>());
|
||||
EXPECT_FALSE(ty->Is<SampledTextureType>());
|
||||
EXPECT_TRUE(ty->Is<StorageTextureType>());
|
||||
TEST_F(StorageTextureTest, IsTexture) {
|
||||
StorageTexture s(TextureDimension::k2dArray, ast::AccessControl::kReadOnly,
|
||||
ImageFormat::kRgba32Float);
|
||||
Texture* ty = &s;
|
||||
EXPECT_FALSE(ty->Is<DepthTexture>());
|
||||
EXPECT_FALSE(ty->Is<SampledTexture>());
|
||||
EXPECT_TRUE(ty->Is<StorageTexture>());
|
||||
}
|
||||
|
||||
TEST_F(StorageTextureTypeTest, Dim) {
|
||||
StorageTextureType s(TextureDimension::k2dArray, AccessControl::kReadOnly,
|
||||
ImageFormat::kRgba32Float);
|
||||
TEST_F(StorageTextureTest, Dim) {
|
||||
StorageTexture s(TextureDimension::k2dArray, ast::AccessControl::kReadOnly,
|
||||
ImageFormat::kRgba32Float);
|
||||
EXPECT_EQ(s.dim(), TextureDimension::k2dArray);
|
||||
}
|
||||
|
||||
TEST_F(StorageTextureTypeTest, Access) {
|
||||
StorageTextureType s(TextureDimension::k2dArray, AccessControl::kReadOnly,
|
||||
ImageFormat::kRgba32Float);
|
||||
EXPECT_EQ(s.access(), AccessControl::kReadOnly);
|
||||
TEST_F(StorageTextureTest, Access) {
|
||||
StorageTexture s(TextureDimension::k2dArray, ast::AccessControl::kReadOnly,
|
||||
ImageFormat::kRgba32Float);
|
||||
EXPECT_EQ(s.access(), ast::AccessControl::kReadOnly);
|
||||
}
|
||||
|
||||
TEST_F(StorageTextureTypeTest, Format) {
|
||||
StorageTextureType s(TextureDimension::k2dArray, AccessControl::kReadOnly,
|
||||
ImageFormat::kRgba32Float);
|
||||
TEST_F(StorageTextureTest, Format) {
|
||||
StorageTexture s(TextureDimension::k2dArray, ast::AccessControl::kReadOnly,
|
||||
ImageFormat::kRgba32Float);
|
||||
EXPECT_EQ(s.image_format(), ImageFormat::kRgba32Float);
|
||||
}
|
||||
|
||||
TEST_F(StorageTextureTypeTest, TypeName) {
|
||||
StorageTextureType s(TextureDimension::k2dArray, AccessControl::kReadOnly,
|
||||
ImageFormat::kRgba32Float);
|
||||
TEST_F(StorageTextureTest, TypeName) {
|
||||
StorageTexture s(TextureDimension::k2dArray, ast::AccessControl::kReadOnly,
|
||||
ImageFormat::kRgba32Float);
|
||||
EXPECT_EQ(s.type_name(), "__storage_texture_read_only_2d_array_rgba32float");
|
||||
}
|
||||
|
||||
TEST_F(StorageTextureTypeTest, F32Type) {
|
||||
TEST_F(StorageTextureTest, F32) {
|
||||
Context ctx;
|
||||
Module mod;
|
||||
Type* s = mod.create<StorageTextureType>(TextureDimension::k2dArray,
|
||||
AccessControl::kReadOnly,
|
||||
ImageFormat::kRgba32Float);
|
||||
Type* s = mod.create<StorageTexture>(TextureDimension::k2dArray,
|
||||
ast::AccessControl::kReadOnly,
|
||||
ImageFormat::kRgba32Float);
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(s->Is<TextureType>());
|
||||
ASSERT_TRUE(s->Is<StorageTextureType>());
|
||||
EXPECT_TRUE(
|
||||
s->As<TextureType>()->As<StorageTextureType>()->type()->Is<F32Type>());
|
||||
ASSERT_TRUE(s->Is<Texture>());
|
||||
ASSERT_TRUE(s->Is<StorageTexture>());
|
||||
EXPECT_TRUE(s->As<Texture>()->As<StorageTexture>()->type()->Is<F32>());
|
||||
}
|
||||
|
||||
TEST_F(StorageTextureTypeTest, U32Type) {
|
||||
TEST_F(StorageTextureTest, U32) {
|
||||
Context ctx;
|
||||
Module mod;
|
||||
Type* s = mod.create<StorageTextureType>(TextureDimension::k2dArray,
|
||||
AccessControl::kReadOnly,
|
||||
ImageFormat::kRg32Uint);
|
||||
Type* s = mod.create<StorageTexture>(TextureDimension::k2dArray,
|
||||
ast::AccessControl::kReadOnly,
|
||||
ImageFormat::kRg32Uint);
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(s->Is<TextureType>());
|
||||
ASSERT_TRUE(s->Is<StorageTextureType>());
|
||||
EXPECT_TRUE(s->As<StorageTextureType>()->type()->Is<U32Type>());
|
||||
ASSERT_TRUE(s->Is<Texture>());
|
||||
ASSERT_TRUE(s->Is<StorageTexture>());
|
||||
EXPECT_TRUE(s->As<StorageTexture>()->type()->Is<U32>());
|
||||
}
|
||||
|
||||
TEST_F(StorageTextureTypeTest, I32Type) {
|
||||
TEST_F(StorageTextureTest, I32) {
|
||||
Context ctx;
|
||||
Module mod;
|
||||
Type* s = mod.create<StorageTextureType>(TextureDimension::k2dArray,
|
||||
AccessControl::kReadOnly,
|
||||
ImageFormat::kRgba32Sint);
|
||||
Type* s = mod.create<StorageTexture>(TextureDimension::k2dArray,
|
||||
ast::AccessControl::kReadOnly,
|
||||
ImageFormat::kRgba32Sint);
|
||||
TypeDeterminer td(&ctx, &mod);
|
||||
|
||||
ASSERT_TRUE(td.Determine()) << td.error();
|
||||
ASSERT_TRUE(s->Is<TextureType>());
|
||||
ASSERT_TRUE(s->Is<StorageTextureType>());
|
||||
EXPECT_TRUE(
|
||||
s->As<TextureType>()->As<StorageTextureType>()->type()->Is<I32Type>());
|
||||
ASSERT_TRUE(s->Is<Texture>());
|
||||
ASSERT_TRUE(s->Is<StorageTexture>());
|
||||
EXPECT_TRUE(s->As<Texture>()->As<StorageTexture>()->type()->Is<I32>());
|
||||
}
|
||||
|
||||
TEST_F(StorageTextureTypeTest, MinBufferBindingSize) {
|
||||
StorageTextureType s(TextureDimension::k2dArray, AccessControl::kReadOnly,
|
||||
ImageFormat::kRgba32Sint);
|
||||
TEST_F(StorageTextureTest, MinBufferBindingSize) {
|
||||
StorageTexture s(TextureDimension::k2dArray, ast::AccessControl::kReadOnly,
|
||||
ImageFormat::kRgba32Sint);
|
||||
EXPECT_EQ(0u, s.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
|
@ -26,18 +26,18 @@ namespace tint {
|
||||
namespace ast {
|
||||
namespace type {
|
||||
|
||||
StructType::StructType(const std::string& name, Struct* impl)
|
||||
Struct::Struct(const std::string& name, ast::Struct* impl)
|
||||
: name_(name), struct_(impl) {}
|
||||
|
||||
StructType::StructType(StructType&&) = default;
|
||||
Struct::Struct(Struct&&) = default;
|
||||
|
||||
StructType::~StructType() = default;
|
||||
Struct::~Struct() = default;
|
||||
|
||||
std::string StructType::type_name() const {
|
||||
std::string Struct::type_name() const {
|
||||
return "__struct_" + name_;
|
||||
}
|
||||
|
||||
uint64_t StructType::MinBufferBindingSize(MemoryLayout mem_layout) const {
|
||||
uint64_t Struct::MinBufferBindingSize(MemoryLayout mem_layout) const {
|
||||
if (!struct_->members().size()) {
|
||||
return 0;
|
||||
}
|
||||
@ -61,7 +61,7 @@ uint64_t StructType::MinBufferBindingSize(MemoryLayout mem_layout) const {
|
||||
return static_cast<uint64_t>(alignment * std::ceil(unaligned / alignment));
|
||||
}
|
||||
|
||||
uint64_t StructType::BaseAlignment(MemoryLayout mem_layout) const {
|
||||
uint64_t Struct::BaseAlignment(MemoryLayout mem_layout) const {
|
||||
uint64_t max = 0;
|
||||
for (auto* member : struct_->members()) {
|
||||
if (member->type()->BaseAlignment(mem_layout) > max) {
|
||||
|
@ -26,15 +26,15 @@ namespace ast {
|
||||
namespace type {
|
||||
|
||||
/// A structure type
|
||||
class StructType : public Castable<StructType, Type> {
|
||||
class Struct : public Castable<Struct, Type> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param name the name of the struct
|
||||
/// @param impl the struct data
|
||||
StructType(const std::string& name, Struct* impl);
|
||||
Struct(const std::string& name, ast::Struct* impl);
|
||||
/// Move constructor
|
||||
StructType(StructType&&);
|
||||
~StructType() override;
|
||||
Struct(Struct&&);
|
||||
~Struct() override;
|
||||
|
||||
/// @returns the struct name
|
||||
const std::string& name() const { return name_; }
|
||||
@ -43,7 +43,7 @@ class StructType : public Castable<StructType, Type> {
|
||||
bool IsBlockDecorated() const { return struct_->IsBlockDecorated(); }
|
||||
|
||||
/// @returns the struct name
|
||||
Struct* impl() const { return struct_; }
|
||||
ast::Struct* impl() const { return struct_; }
|
||||
|
||||
/// @returns the name for the type
|
||||
std::string type_name() const override;
|
||||
@ -60,7 +60,7 @@ class StructType : public Castable<StructType, Type> {
|
||||
|
||||
private:
|
||||
std::string name_;
|
||||
Struct* struct_ = nullptr;
|
||||
ast::Struct* struct_ = nullptr;
|
||||
|
||||
uint64_t LargestMemberBaseAlignment(MemoryLayout mem_layout) const;
|
||||
};
|
||||
|
@ -37,42 +37,42 @@ namespace ast {
|
||||
namespace type {
|
||||
namespace {
|
||||
|
||||
using StructTypeTest = TestHelper;
|
||||
using StructTest = TestHelper;
|
||||
|
||||
TEST_F(StructTypeTest, Creation) {
|
||||
auto* impl = create<Struct>();
|
||||
TEST_F(StructTest, Creation) {
|
||||
auto* impl = create<ast::Struct>();
|
||||
auto* ptr = impl;
|
||||
StructType s{"S", impl};
|
||||
Struct s{"S", impl};
|
||||
EXPECT_EQ(s.impl(), ptr);
|
||||
}
|
||||
|
||||
TEST_F(StructTypeTest, Is) {
|
||||
auto* impl = create<Struct>();
|
||||
StructType s{"S", impl};
|
||||
TEST_F(StructTest, Is) {
|
||||
auto* impl = create<ast::Struct>();
|
||||
Struct s{"S", impl};
|
||||
Type* ty = &s;
|
||||
EXPECT_FALSE(ty->Is<AccessControlType>());
|
||||
EXPECT_FALSE(ty->Is<AliasType>());
|
||||
EXPECT_FALSE(ty->Is<ArrayType>());
|
||||
EXPECT_FALSE(ty->Is<BoolType>());
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->Is<SamplerType>());
|
||||
EXPECT_TRUE(ty->Is<StructType>());
|
||||
EXPECT_FALSE(ty->Is<TextureType>());
|
||||
EXPECT_FALSE(ty->Is<U32Type>());
|
||||
EXPECT_FALSE(ty->Is<VectorType>());
|
||||
EXPECT_FALSE(ty->Is<AccessControl>());
|
||||
EXPECT_FALSE(ty->Is<Alias>());
|
||||
EXPECT_FALSE(ty->Is<Array>());
|
||||
EXPECT_FALSE(ty->Is<Bool>());
|
||||
EXPECT_FALSE(ty->Is<F32>());
|
||||
EXPECT_FALSE(ty->Is<I32>());
|
||||
EXPECT_FALSE(ty->Is<Matrix>());
|
||||
EXPECT_FALSE(ty->Is<Pointer>());
|
||||
EXPECT_FALSE(ty->Is<Sampler>());
|
||||
EXPECT_TRUE(ty->Is<Struct>());
|
||||
EXPECT_FALSE(ty->Is<Texture>());
|
||||
EXPECT_FALSE(ty->Is<U32>());
|
||||
EXPECT_FALSE(ty->Is<Vector>());
|
||||
}
|
||||
|
||||
TEST_F(StructTypeTest, TypeName) {
|
||||
auto* impl = create<Struct>();
|
||||
StructType s{"my_struct", impl};
|
||||
TEST_F(StructTest, TypeName) {
|
||||
auto* impl = create<ast::Struct>();
|
||||
Struct s{"my_struct", impl};
|
||||
EXPECT_EQ(s.type_name(), "__struct_my_struct");
|
||||
}
|
||||
|
||||
TEST_F(StructTypeTest, MinBufferBindingSize) {
|
||||
U32Type u32;
|
||||
TEST_F(StructTest, MinBufferBindingSize) {
|
||||
U32 u32;
|
||||
StructMemberList members;
|
||||
|
||||
{
|
||||
@ -87,16 +87,16 @@ TEST_F(StructTypeTest, MinBufferBindingSize) {
|
||||
}
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<Struct>(decos, members);
|
||||
StructType struct_type("struct_type", str);
|
||||
auto* str = create<ast::Struct>(decos, members);
|
||||
Struct struct_type("struct_type", str);
|
||||
EXPECT_EQ(16u,
|
||||
struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(8u, struct_type.MinBufferBindingSize(MemoryLayout::kStorageBuffer));
|
||||
}
|
||||
|
||||
TEST_F(StructTypeTest, MinBufferBindingSizeArray) {
|
||||
U32Type u32;
|
||||
ArrayType arr(&u32, 4);
|
||||
TEST_F(StructTest, MinBufferBindingSizeArray) {
|
||||
U32 u32;
|
||||
Array arr(&u32, 4);
|
||||
{
|
||||
ArrayDecorationList decos;
|
||||
decos.push_back(create<StrideDecoration>(4, Source{}));
|
||||
@ -121,17 +121,17 @@ TEST_F(StructTypeTest, MinBufferBindingSizeArray) {
|
||||
}
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<Struct>(decos, members);
|
||||
StructType struct_type("struct_type", str);
|
||||
auto* str = create<ast::Struct>(decos, members);
|
||||
Struct struct_type("struct_type", str);
|
||||
EXPECT_EQ(32u,
|
||||
struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(24u,
|
||||
struct_type.MinBufferBindingSize(MemoryLayout::kStorageBuffer));
|
||||
}
|
||||
|
||||
TEST_F(StructTypeTest, MinBufferBindingSizeRuntimeArray) {
|
||||
U32Type u32;
|
||||
ArrayType arr(&u32);
|
||||
TEST_F(StructTest, MinBufferBindingSizeRuntimeArray) {
|
||||
U32 u32;
|
||||
Array arr(&u32);
|
||||
{
|
||||
ArrayDecorationList decos;
|
||||
decos.push_back(create<StrideDecoration>(4, Source{}));
|
||||
@ -156,15 +156,15 @@ TEST_F(StructTypeTest, MinBufferBindingSizeRuntimeArray) {
|
||||
}
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<Struct>(decos, members);
|
||||
StructType struct_type("struct_type", str);
|
||||
auto* str = create<ast::Struct>(decos, members);
|
||||
Struct struct_type("struct_type", str);
|
||||
EXPECT_EQ(12u,
|
||||
struct_type.MinBufferBindingSize(MemoryLayout::kStorageBuffer));
|
||||
}
|
||||
|
||||
TEST_F(StructTypeTest, MinBufferBindingSizeVec2) {
|
||||
U32Type u32;
|
||||
VectorType vec2(&u32, 2);
|
||||
TEST_F(StructTest, MinBufferBindingSizeVec2) {
|
||||
U32 u32;
|
||||
Vector vec2(&u32, 2);
|
||||
|
||||
StructMemberList members;
|
||||
{
|
||||
@ -174,16 +174,16 @@ TEST_F(StructTypeTest, MinBufferBindingSizeVec2) {
|
||||
}
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<Struct>(decos, members);
|
||||
StructType struct_type("struct_type", str);
|
||||
auto* str = create<ast::Struct>(decos, members);
|
||||
Struct struct_type("struct_type", str);
|
||||
EXPECT_EQ(16u,
|
||||
struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(8u, struct_type.MinBufferBindingSize(MemoryLayout::kStorageBuffer));
|
||||
}
|
||||
|
||||
TEST_F(StructTypeTest, MinBufferBindingSizeVec3) {
|
||||
U32Type u32;
|
||||
VectorType vec3(&u32, 3);
|
||||
TEST_F(StructTest, MinBufferBindingSizeVec3) {
|
||||
U32 u32;
|
||||
Vector vec3(&u32, 3);
|
||||
|
||||
StructMemberList members;
|
||||
{
|
||||
@ -193,17 +193,17 @@ TEST_F(StructTypeTest, MinBufferBindingSizeVec3) {
|
||||
}
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<Struct>(decos, members);
|
||||
StructType struct_type("struct_type", str);
|
||||
auto* str = create<ast::Struct>(decos, members);
|
||||
Struct struct_type("struct_type", str);
|
||||
EXPECT_EQ(16u,
|
||||
struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(16u,
|
||||
struct_type.MinBufferBindingSize(MemoryLayout::kStorageBuffer));
|
||||
}
|
||||
|
||||
TEST_F(StructTypeTest, MinBufferBindingSizeVec4) {
|
||||
U32Type u32;
|
||||
VectorType vec4(&u32, 4);
|
||||
TEST_F(StructTest, MinBufferBindingSizeVec4) {
|
||||
U32 u32;
|
||||
Vector vec4(&u32, 4);
|
||||
|
||||
StructMemberList members;
|
||||
{
|
||||
@ -213,16 +213,16 @@ TEST_F(StructTypeTest, MinBufferBindingSizeVec4) {
|
||||
}
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<Struct>(decos, members);
|
||||
StructType struct_type("struct_type", str);
|
||||
auto* str = create<ast::Struct>(decos, members);
|
||||
Struct struct_type("struct_type", str);
|
||||
EXPECT_EQ(16u,
|
||||
struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(16u,
|
||||
struct_type.MinBufferBindingSize(MemoryLayout::kStorageBuffer));
|
||||
}
|
||||
|
||||
TEST_F(StructTypeTest, BaseAlignment) {
|
||||
U32Type u32;
|
||||
TEST_F(StructTest, BaseAlignment) {
|
||||
U32 u32;
|
||||
StructMemberList members;
|
||||
|
||||
{
|
||||
@ -237,15 +237,15 @@ TEST_F(StructTypeTest, BaseAlignment) {
|
||||
}
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<Struct>(decos, members);
|
||||
StructType struct_type("struct_type", str);
|
||||
auto* str = create<ast::Struct>(decos, members);
|
||||
Struct struct_type("struct_type", str);
|
||||
EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(4u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer));
|
||||
}
|
||||
|
||||
TEST_F(StructTypeTest, BaseAlignmentArray) {
|
||||
U32Type u32;
|
||||
ArrayType arr(&u32, 4);
|
||||
TEST_F(StructTest, BaseAlignmentArray) {
|
||||
U32 u32;
|
||||
Array arr(&u32, 4);
|
||||
{
|
||||
ArrayDecorationList decos;
|
||||
decos.push_back(create<StrideDecoration>(4, Source{}));
|
||||
@ -270,15 +270,15 @@ TEST_F(StructTypeTest, BaseAlignmentArray) {
|
||||
}
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<Struct>(decos, members);
|
||||
StructType struct_type("struct_type", str);
|
||||
auto* str = create<ast::Struct>(decos, members);
|
||||
Struct struct_type("struct_type", str);
|
||||
EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(4u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer));
|
||||
}
|
||||
|
||||
TEST_F(StructTypeTest, BaseAlignmentRuntimeArray) {
|
||||
U32Type u32;
|
||||
ArrayType arr(&u32);
|
||||
TEST_F(StructTest, BaseAlignmentRuntimeArray) {
|
||||
U32 u32;
|
||||
Array arr(&u32);
|
||||
{
|
||||
ArrayDecorationList decos;
|
||||
decos.push_back(create<StrideDecoration>(4, Source{}));
|
||||
@ -303,14 +303,14 @@ TEST_F(StructTypeTest, BaseAlignmentRuntimeArray) {
|
||||
}
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<Struct>(decos, members);
|
||||
StructType struct_type("struct_type", str);
|
||||
auto* str = create<ast::Struct>(decos, members);
|
||||
Struct struct_type("struct_type", str);
|
||||
EXPECT_EQ(4u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer));
|
||||
}
|
||||
|
||||
TEST_F(StructTypeTest, BaseAlignmentVec2) {
|
||||
U32Type u32;
|
||||
VectorType vec2(&u32, 2);
|
||||
TEST_F(StructTest, BaseAlignmentVec2) {
|
||||
U32 u32;
|
||||
Vector vec2(&u32, 2);
|
||||
|
||||
StructMemberList members;
|
||||
{
|
||||
@ -320,15 +320,15 @@ TEST_F(StructTypeTest, BaseAlignmentVec2) {
|
||||
}
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<Struct>(decos, members);
|
||||
StructType struct_type("struct_type", str);
|
||||
auto* str = create<ast::Struct>(decos, members);
|
||||
Struct struct_type("struct_type", str);
|
||||
EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(8u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer));
|
||||
}
|
||||
|
||||
TEST_F(StructTypeTest, BaseAlignmentVec3) {
|
||||
U32Type u32;
|
||||
VectorType vec3(&u32, 3);
|
||||
TEST_F(StructTest, BaseAlignmentVec3) {
|
||||
U32 u32;
|
||||
Vector vec3(&u32, 3);
|
||||
|
||||
StructMemberList members;
|
||||
{
|
||||
@ -338,15 +338,15 @@ TEST_F(StructTypeTest, BaseAlignmentVec3) {
|
||||
}
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<Struct>(decos, members);
|
||||
StructType struct_type("struct_type", str);
|
||||
auto* str = create<ast::Struct>(decos, members);
|
||||
Struct struct_type("struct_type", str);
|
||||
EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer));
|
||||
}
|
||||
|
||||
TEST_F(StructTypeTest, BaseAlignmentVec4) {
|
||||
U32Type u32;
|
||||
VectorType vec4(&u32, 4);
|
||||
TEST_F(StructTest, BaseAlignmentVec4) {
|
||||
U32 u32;
|
||||
Vector vec4(&u32, 4);
|
||||
|
||||
StructMemberList members;
|
||||
{
|
||||
@ -356,8 +356,8 @@ TEST_F(StructTypeTest, BaseAlignmentVec4) {
|
||||
}
|
||||
StructDecorationList decos;
|
||||
|
||||
auto* str = create<Struct>(decos, members);
|
||||
StructType struct_type("struct_type", str);
|
||||
auto* str = create<ast::Struct>(decos, members);
|
||||
Struct struct_type("struct_type", str);
|
||||
EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer));
|
||||
}
|
||||
|
@ -53,11 +53,11 @@ std::ostream& operator<<(std::ostream& out, TextureDimension dim) {
|
||||
return out;
|
||||
}
|
||||
|
||||
TextureType::TextureType(TextureDimension dim) : dim_(dim) {}
|
||||
Texture::Texture(TextureDimension dim) : dim_(dim) {}
|
||||
|
||||
TextureType::TextureType(TextureType&&) = default;
|
||||
Texture::Texture(Texture&&) = default;
|
||||
|
||||
TextureType::~TextureType() = default;
|
||||
Texture::~Texture() = default;
|
||||
|
||||
} // namespace type
|
||||
} // namespace ast
|
||||
|
@ -46,14 +46,14 @@ enum class TextureDimension {
|
||||
std::ostream& operator<<(std::ostream& out, TextureDimension dim);
|
||||
|
||||
/// A texture type.
|
||||
class TextureType : public Castable<TextureType, Type> {
|
||||
class Texture : public Castable<Texture, Type> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param dim the dimensionality of the texture
|
||||
explicit TextureType(TextureDimension dim);
|
||||
explicit Texture(TextureDimension dim);
|
||||
/// Move constructor
|
||||
TextureType(TextureType&&);
|
||||
~TextureType() override;
|
||||
Texture(Texture&&);
|
||||
~Texture() override;
|
||||
|
||||
/// @returns the texture dimension
|
||||
TextureDimension dim() const { return dim_; }
|
||||
|
@ -42,8 +42,8 @@ Type::Type(Type&&) = default;
|
||||
Type::~Type() = default;
|
||||
|
||||
Type* Type::UnwrapPtrIfNeeded() {
|
||||
if (Is<PointerType>()) {
|
||||
return As<PointerType>()->type();
|
||||
if (Is<Pointer>()) {
|
||||
return As<Pointer>()->type();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@ -51,10 +51,10 @@ Type* Type::UnwrapPtrIfNeeded() {
|
||||
Type* Type::UnwrapIfNeeded() {
|
||||
auto* where = this;
|
||||
while (true) {
|
||||
if (where->Is<AliasType>()) {
|
||||
where = where->As<AliasType>()->type();
|
||||
} else if (where->Is<AccessControlType>()) {
|
||||
where = where->As<AccessControlType>()->type();
|
||||
if (where->Is<Alias>()) {
|
||||
where = where->As<Alias>()->type();
|
||||
} else if (where->Is<AccessControl>()) {
|
||||
where = where->As<AccessControl>()->type();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
@ -75,19 +75,19 @@ uint64_t Type::BaseAlignment(MemoryLayout) const {
|
||||
}
|
||||
|
||||
bool Type::is_scalar() {
|
||||
return is_float_scalar() || is_integer_scalar() || Is<BoolType>();
|
||||
return is_float_scalar() || is_integer_scalar() || Is<Bool>();
|
||||
}
|
||||
|
||||
bool Type::is_float_scalar() {
|
||||
return Is<F32Type>();
|
||||
return Is<F32>();
|
||||
}
|
||||
|
||||
bool Type::is_float_matrix() {
|
||||
return Is<MatrixType>() && As<MatrixType>()->type()->is_float_scalar();
|
||||
return Is<Matrix>() && As<Matrix>()->type()->is_float_scalar();
|
||||
}
|
||||
|
||||
bool Type::is_float_vector() {
|
||||
return Is<VectorType>() && As<VectorType>()->type()->is_float_scalar();
|
||||
return Is<Vector>() && As<Vector>()->type()->is_float_scalar();
|
||||
}
|
||||
|
||||
bool Type::is_float_scalar_or_vector() {
|
||||
@ -95,25 +95,23 @@ bool Type::is_float_scalar_or_vector() {
|
||||
}
|
||||
|
||||
bool Type::is_integer_scalar() {
|
||||
return Is<U32Type>() || Is<I32Type>();
|
||||
return Is<U32>() || Is<I32>();
|
||||
}
|
||||
|
||||
bool Type::is_unsigned_integer_vector() {
|
||||
return Is<VectorType>() && As<VectorType>()->type()->Is<U32Type>();
|
||||
return Is<Vector>() && As<Vector>()->type()->Is<U32>();
|
||||
}
|
||||
|
||||
bool Type::is_signed_integer_vector() {
|
||||
return Is<VectorType>() && As<VectorType>()->type()->Is<I32Type>();
|
||||
return Is<Vector>() && As<Vector>()->type()->Is<I32>();
|
||||
}
|
||||
|
||||
bool Type::is_unsigned_scalar_or_vector() {
|
||||
return Is<U32Type>() ||
|
||||
(Is<VectorType>() && As<VectorType>()->type()->Is<U32Type>());
|
||||
return Is<U32>() || (Is<Vector>() && As<Vector>()->type()->Is<U32>());
|
||||
}
|
||||
|
||||
bool Type::is_signed_scalar_or_vector() {
|
||||
return Is<I32Type>() ||
|
||||
(Is<VectorType>() && As<VectorType>()->type()->Is<I32Type>());
|
||||
return Is<I32>() || (Is<Vector>() && As<Vector>()->type()->Is<I32>());
|
||||
}
|
||||
|
||||
bool Type::is_integer_scalar_or_vector() {
|
||||
|
@ -18,21 +18,21 @@ namespace tint {
|
||||
namespace ast {
|
||||
namespace type {
|
||||
|
||||
U32Type::U32Type() = default;
|
||||
U32::U32() = default;
|
||||
|
||||
U32Type::~U32Type() = default;
|
||||
U32::~U32() = default;
|
||||
|
||||
U32Type::U32Type(U32Type&&) = default;
|
||||
U32::U32(U32&&) = default;
|
||||
|
||||
std::string U32Type::type_name() const {
|
||||
std::string U32::type_name() const {
|
||||
return "__u32";
|
||||
}
|
||||
|
||||
uint64_t U32Type::MinBufferBindingSize(MemoryLayout) const {
|
||||
uint64_t U32::MinBufferBindingSize(MemoryLayout) const {
|
||||
return 4;
|
||||
}
|
||||
|
||||
uint64_t U32Type::BaseAlignment(MemoryLayout) const {
|
||||
uint64_t U32::BaseAlignment(MemoryLayout) const {
|
||||
return 4;
|
||||
}
|
||||
|
||||
|
@ -24,13 +24,13 @@ namespace ast {
|
||||
namespace type {
|
||||
|
||||
/// A unsigned int 32 type.
|
||||
class U32Type : public Castable<U32Type, Type> {
|
||||
class U32 : public Castable<U32, Type> {
|
||||
public:
|
||||
/// Constructor
|
||||
U32Type();
|
||||
U32();
|
||||
/// Move constructor
|
||||
U32Type(U32Type&&);
|
||||
~U32Type() override;
|
||||
U32(U32&&);
|
||||
~U32() override;
|
||||
|
||||
/// @returns the name for th type
|
||||
std::string type_name() const override;
|
||||
|
@ -32,38 +32,38 @@ namespace ast {
|
||||
namespace type {
|
||||
namespace {
|
||||
|
||||
using U32TypeTest = TestHelper;
|
||||
using U32Test = TestHelper;
|
||||
|
||||
TEST_F(U32TypeTest, Is) {
|
||||
U32Type u;
|
||||
TEST_F(U32Test, Is) {
|
||||
U32 u;
|
||||
Type* ty = &u;
|
||||
EXPECT_FALSE(ty->Is<AccessControlType>());
|
||||
EXPECT_FALSE(ty->Is<AliasType>());
|
||||
EXPECT_FALSE(ty->Is<ArrayType>());
|
||||
EXPECT_FALSE(ty->Is<BoolType>());
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->Is<SamplerType>());
|
||||
EXPECT_FALSE(ty->Is<StructType>());
|
||||
EXPECT_FALSE(ty->Is<TextureType>());
|
||||
EXPECT_TRUE(ty->Is<U32Type>());
|
||||
EXPECT_FALSE(ty->Is<VectorType>());
|
||||
EXPECT_FALSE(ty->Is<AccessControl>());
|
||||
EXPECT_FALSE(ty->Is<Alias>());
|
||||
EXPECT_FALSE(ty->Is<Array>());
|
||||
EXPECT_FALSE(ty->Is<Bool>());
|
||||
EXPECT_FALSE(ty->Is<F32>());
|
||||
EXPECT_FALSE(ty->Is<I32>());
|
||||
EXPECT_FALSE(ty->Is<Matrix>());
|
||||
EXPECT_FALSE(ty->Is<Pointer>());
|
||||
EXPECT_FALSE(ty->Is<Sampler>());
|
||||
EXPECT_FALSE(ty->Is<Struct>());
|
||||
EXPECT_FALSE(ty->Is<Texture>());
|
||||
EXPECT_TRUE(ty->Is<U32>());
|
||||
EXPECT_FALSE(ty->Is<Vector>());
|
||||
}
|
||||
|
||||
TEST_F(U32TypeTest, TypeName) {
|
||||
U32Type u;
|
||||
TEST_F(U32Test, TypeName) {
|
||||
U32 u;
|
||||
EXPECT_EQ(u.type_name(), "__u32");
|
||||
}
|
||||
|
||||
TEST_F(U32TypeTest, MinBufferBindingSize) {
|
||||
U32Type u;
|
||||
TEST_F(U32Test, MinBufferBindingSize) {
|
||||
U32 u;
|
||||
EXPECT_EQ(4u, u.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
TEST_F(U32TypeTest, BaseAlignment) {
|
||||
U32Type u;
|
||||
TEST_F(U32Test, BaseAlignment) {
|
||||
U32 u;
|
||||
EXPECT_EQ(4u, u.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
|
@ -21,25 +21,24 @@ namespace tint {
|
||||
namespace ast {
|
||||
namespace type {
|
||||
|
||||
VectorType::VectorType(Type* subtype, uint32_t size)
|
||||
: subtype_(subtype), size_(size) {
|
||||
Vector::Vector(Type* subtype, uint32_t size) : subtype_(subtype), size_(size) {
|
||||
assert(size_ > 1);
|
||||
assert(size_ < 5);
|
||||
}
|
||||
|
||||
VectorType::VectorType(VectorType&&) = default;
|
||||
Vector::Vector(Vector&&) = default;
|
||||
|
||||
VectorType::~VectorType() = default;
|
||||
Vector::~Vector() = default;
|
||||
|
||||
std::string VectorType::type_name() const {
|
||||
std::string Vector::type_name() const {
|
||||
return "__vec_" + std::to_string(size_) + subtype_->type_name();
|
||||
}
|
||||
|
||||
uint64_t VectorType::MinBufferBindingSize(MemoryLayout mem_layout) const {
|
||||
uint64_t Vector::MinBufferBindingSize(MemoryLayout mem_layout) const {
|
||||
return size_ * subtype_->MinBufferBindingSize(mem_layout);
|
||||
}
|
||||
|
||||
uint64_t VectorType::BaseAlignment(MemoryLayout mem_layout) const {
|
||||
uint64_t Vector::BaseAlignment(MemoryLayout mem_layout) const {
|
||||
if (size_ == 2) {
|
||||
return 2 * subtype_->BaseAlignment(mem_layout);
|
||||
} else if (size_ == 3 || size_ == 4) {
|
||||
|
@ -24,15 +24,15 @@ namespace ast {
|
||||
namespace type {
|
||||
|
||||
/// A vector type.
|
||||
class VectorType : public Castable<VectorType, Type> {
|
||||
class Vector : public Castable<Vector, Type> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param subtype the vector element type
|
||||
/// @param size the number of elements in the vector
|
||||
VectorType(Type* subtype, uint32_t size);
|
||||
Vector(Type* subtype, uint32_t size);
|
||||
/// Move constructor
|
||||
VectorType(VectorType&&);
|
||||
~VectorType() override;
|
||||
Vector(Vector&&);
|
||||
~Vector() override;
|
||||
|
||||
/// @returns the type of the vector elements
|
||||
Type* type() const { return subtype_; }
|
||||
|
@ -31,73 +31,73 @@ namespace ast {
|
||||
namespace type {
|
||||
namespace {
|
||||
|
||||
using VectorTypeTest = TestHelper;
|
||||
using VectorTest = TestHelper;
|
||||
|
||||
TEST_F(VectorTypeTest, Creation) {
|
||||
I32Type i32;
|
||||
VectorType v{&i32, 2};
|
||||
TEST_F(VectorTest, Creation) {
|
||||
I32 i32;
|
||||
Vector v{&i32, 2};
|
||||
EXPECT_EQ(v.type(), &i32);
|
||||
EXPECT_EQ(v.size(), 2u);
|
||||
}
|
||||
|
||||
TEST_F(VectorTypeTest, Is) {
|
||||
I32Type i32;
|
||||
VectorType v{&i32, 4};
|
||||
TEST_F(VectorTest, Is) {
|
||||
I32 i32;
|
||||
Vector v{&i32, 4};
|
||||
Type* ty = &v;
|
||||
EXPECT_FALSE(ty->Is<AccessControlType>());
|
||||
EXPECT_FALSE(ty->Is<AliasType>());
|
||||
EXPECT_FALSE(ty->Is<ArrayType>());
|
||||
EXPECT_FALSE(ty->Is<BoolType>());
|
||||
EXPECT_FALSE(ty->Is<F32Type>());
|
||||
EXPECT_FALSE(ty->Is<I32Type>());
|
||||
EXPECT_FALSE(ty->Is<MatrixType>());
|
||||
EXPECT_FALSE(ty->Is<PointerType>());
|
||||
EXPECT_FALSE(ty->Is<SamplerType>());
|
||||
EXPECT_FALSE(ty->Is<StructType>());
|
||||
EXPECT_FALSE(ty->Is<TextureType>());
|
||||
EXPECT_FALSE(ty->Is<U32Type>());
|
||||
EXPECT_TRUE(ty->Is<VectorType>());
|
||||
EXPECT_FALSE(ty->Is<AccessControl>());
|
||||
EXPECT_FALSE(ty->Is<Alias>());
|
||||
EXPECT_FALSE(ty->Is<Array>());
|
||||
EXPECT_FALSE(ty->Is<Bool>());
|
||||
EXPECT_FALSE(ty->Is<F32>());
|
||||
EXPECT_FALSE(ty->Is<I32>());
|
||||
EXPECT_FALSE(ty->Is<Matrix>());
|
||||
EXPECT_FALSE(ty->Is<Pointer>());
|
||||
EXPECT_FALSE(ty->Is<Sampler>());
|
||||
EXPECT_FALSE(ty->Is<Struct>());
|
||||
EXPECT_FALSE(ty->Is<Texture>());
|
||||
EXPECT_FALSE(ty->Is<U32>());
|
||||
EXPECT_TRUE(ty->Is<Vector>());
|
||||
}
|
||||
|
||||
TEST_F(VectorTypeTest, TypeName) {
|
||||
I32Type i32;
|
||||
VectorType v{&i32, 3};
|
||||
TEST_F(VectorTest, TypeName) {
|
||||
I32 i32;
|
||||
Vector v{&i32, 3};
|
||||
EXPECT_EQ(v.type_name(), "__vec_3__i32");
|
||||
}
|
||||
|
||||
TEST_F(VectorTypeTest, MinBufferBindingSizeVec2) {
|
||||
I32Type i32;
|
||||
VectorType v{&i32, 2};
|
||||
TEST_F(VectorTest, MinBufferBindingSizeVec2) {
|
||||
I32 i32;
|
||||
Vector v{&i32, 2};
|
||||
EXPECT_EQ(8u, v.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
TEST_F(VectorTypeTest, MinBufferBindingSizeVec3) {
|
||||
I32Type i32;
|
||||
VectorType v{&i32, 3};
|
||||
TEST_F(VectorTest, MinBufferBindingSizeVec3) {
|
||||
I32 i32;
|
||||
Vector v{&i32, 3};
|
||||
EXPECT_EQ(12u, v.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
TEST_F(VectorTypeTest, MinBufferBindingSizeVec4) {
|
||||
I32Type i32;
|
||||
VectorType v{&i32, 4};
|
||||
TEST_F(VectorTest, MinBufferBindingSizeVec4) {
|
||||
I32 i32;
|
||||
Vector v{&i32, 4};
|
||||
EXPECT_EQ(16u, v.MinBufferBindingSize(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
TEST_F(VectorTypeTest, BaseAlignmentVec2) {
|
||||
I32Type i32;
|
||||
VectorType v{&i32, 2};
|
||||
TEST_F(VectorTest, BaseAlignmentVec2) {
|
||||
I32 i32;
|
||||
Vector v{&i32, 2};
|
||||
EXPECT_EQ(8u, v.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
TEST_F(VectorTypeTest, BaseAlignmentVec3) {
|
||||
I32Type i32;
|
||||
VectorType v{&i32, 3};
|
||||
TEST_F(VectorTest, BaseAlignmentVec3) {
|
||||
I32 i32;
|
||||
Vector v{&i32, 3};
|
||||
EXPECT_EQ(16u, v.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
TEST_F(VectorTypeTest, BaseAlignmentVec4) {
|
||||
I32Type i32;
|
||||
VectorType v{&i32, 4};
|
||||
TEST_F(VectorTest, BaseAlignmentVec4) {
|
||||
I32 i32;
|
||||
Vector v{&i32, 4};
|
||||
EXPECT_EQ(16u, v.BaseAlignment(MemoryLayout::kUniformBuffer));
|
||||
}
|
||||
|
||||
|
@ -18,13 +18,13 @@ namespace tint {
|
||||
namespace ast {
|
||||
namespace type {
|
||||
|
||||
VoidType::VoidType() = default;
|
||||
Void::Void() = default;
|
||||
|
||||
VoidType::VoidType(VoidType&&) = default;
|
||||
Void::Void(Void&&) = default;
|
||||
|
||||
VoidType::~VoidType() = default;
|
||||
Void::~Void() = default;
|
||||
|
||||
std::string VoidType::type_name() const {
|
||||
std::string Void::type_name() const {
|
||||
return "__void";
|
||||
}
|
||||
|
||||
|
@ -24,13 +24,13 @@ namespace ast {
|
||||
namespace type {
|
||||
|
||||
/// A void type
|
||||
class VoidType : public Castable<VoidType, Type> {
|
||||
class Void : public Castable<Void, Type> {
|
||||
public:
|
||||
/// Constructor
|
||||
VoidType();
|
||||
Void();
|
||||
/// Move constructor
|
||||
VoidType(VoidType&&);
|
||||
~VoidType() override;
|
||||
Void(Void&&);
|
||||
~Void() override;
|
||||
|
||||
/// @returns the name for this type
|
||||
std::string type_name() const override;
|
||||
|
@ -30,7 +30,7 @@ namespace {
|
||||
using TypeConstructorExpressionTest = TestHelper;
|
||||
|
||||
TEST_F(TypeConstructorExpressionTest, Creation) {
|
||||
type::F32Type f32;
|
||||
type::F32 f32;
|
||||
ExpressionList expr;
|
||||
expr.push_back(create<IdentifierExpression>("expr"));
|
||||
|
||||
@ -41,7 +41,7 @@ TEST_F(TypeConstructorExpressionTest, Creation) {
|
||||
}
|
||||
|
||||
TEST_F(TypeConstructorExpressionTest, Creation_WithSource) {
|
||||
type::F32Type f32;
|
||||
type::F32 f32;
|
||||
ExpressionList expr;
|
||||
expr.push_back(create<IdentifierExpression>("expr"));
|
||||
|
||||
@ -57,7 +57,7 @@ TEST_F(TypeConstructorExpressionTest, IsTypeConstructor) {
|
||||
}
|
||||
|
||||
TEST_F(TypeConstructorExpressionTest, IsValid) {
|
||||
type::F32Type f32;
|
||||
type::F32 f32;
|
||||
ExpressionList expr;
|
||||
expr.push_back(create<IdentifierExpression>("expr"));
|
||||
|
||||
@ -66,7 +66,7 @@ TEST_F(TypeConstructorExpressionTest, IsValid) {
|
||||
}
|
||||
|
||||
TEST_F(TypeConstructorExpressionTest, IsValid_EmptyValue) {
|
||||
type::F32Type f32;
|
||||
type::F32 f32;
|
||||
ExpressionList expr;
|
||||
|
||||
TypeConstructorExpression t(&f32, expr);
|
||||
@ -83,7 +83,7 @@ TEST_F(TypeConstructorExpressionTest, IsValid_NullType) {
|
||||
}
|
||||
|
||||
TEST_F(TypeConstructorExpressionTest, IsValid_NullValue) {
|
||||
type::F32Type f32;
|
||||
type::F32 f32;
|
||||
ExpressionList expr;
|
||||
expr.push_back(create<IdentifierExpression>("expr"));
|
||||
expr.push_back(nullptr);
|
||||
@ -93,7 +93,7 @@ TEST_F(TypeConstructorExpressionTest, IsValid_NullValue) {
|
||||
}
|
||||
|
||||
TEST_F(TypeConstructorExpressionTest, IsValid_InvalidValue) {
|
||||
type::F32Type f32;
|
||||
type::F32 f32;
|
||||
ExpressionList expr;
|
||||
expr.push_back(create<IdentifierExpression>(""));
|
||||
|
||||
@ -102,8 +102,8 @@ TEST_F(TypeConstructorExpressionTest, IsValid_InvalidValue) {
|
||||
}
|
||||
|
||||
TEST_F(TypeConstructorExpressionTest, ToStr) {
|
||||
type::F32Type f32;
|
||||
type::VectorType vec(&f32, 3);
|
||||
type::F32 f32;
|
||||
type::Vector vec(&f32, 3);
|
||||
ExpressionList expr;
|
||||
expr.push_back(create<IdentifierExpression>("expr_1"));
|
||||
expr.push_back(create<IdentifierExpression>("expr_2"));
|
||||
|
@ -27,43 +27,43 @@ using TypeManagerTest = testing::Test;
|
||||
|
||||
TEST_F(TypeManagerTest, GetUnregistered) {
|
||||
TypeManager tm;
|
||||
auto* t = tm.Get(std::make_unique<type::I32Type>());
|
||||
auto* t = tm.Get(std::make_unique<type::I32>());
|
||||
ASSERT_NE(t, nullptr);
|
||||
EXPECT_TRUE(t->Is<type::I32Type>());
|
||||
EXPECT_TRUE(t->Is<type::I32>());
|
||||
}
|
||||
|
||||
TEST_F(TypeManagerTest, GetSameTypeReturnsSamePtr) {
|
||||
TypeManager tm;
|
||||
auto* t = tm.Get(std::make_unique<type::I32Type>());
|
||||
auto* t = tm.Get(std::make_unique<type::I32>());
|
||||
ASSERT_NE(t, nullptr);
|
||||
EXPECT_TRUE(t->Is<type::I32Type>());
|
||||
EXPECT_TRUE(t->Is<type::I32>());
|
||||
|
||||
auto* t2 = tm.Get(std::make_unique<type::I32Type>());
|
||||
auto* t2 = tm.Get(std::make_unique<type::I32>());
|
||||
EXPECT_EQ(t, t2);
|
||||
}
|
||||
|
||||
TEST_F(TypeManagerTest, GetDifferentTypeReturnsDifferentPtr) {
|
||||
TypeManager tm;
|
||||
auto* t = tm.Get(std::make_unique<type::I32Type>());
|
||||
auto* t = tm.Get(std::make_unique<type::I32>());
|
||||
ASSERT_NE(t, nullptr);
|
||||
EXPECT_TRUE(t->Is<type::I32Type>());
|
||||
EXPECT_TRUE(t->Is<type::I32>());
|
||||
|
||||
auto* t2 = tm.Get(std::make_unique<type::U32Type>());
|
||||
auto* t2 = tm.Get(std::make_unique<type::U32>());
|
||||
ASSERT_NE(t2, nullptr);
|
||||
EXPECT_NE(t, t2);
|
||||
EXPECT_TRUE(t2->Is<type::U32Type>());
|
||||
EXPECT_TRUE(t2->Is<type::U32>());
|
||||
}
|
||||
|
||||
TEST_F(TypeManagerTest, ResetClearsPreviousData) {
|
||||
TypeManager tm;
|
||||
auto* t = tm.Get(std::make_unique<type::I32Type>());
|
||||
auto* t = tm.Get(std::make_unique<type::I32>());
|
||||
ASSERT_NE(t, nullptr);
|
||||
|
||||
EXPECT_FALSE(tm.types().empty());
|
||||
tm.Reset();
|
||||
EXPECT_TRUE(tm.types().empty());
|
||||
|
||||
auto* t2 = tm.Get(std::make_unique<type::I32Type>());
|
||||
auto* t2 = tm.Get(std::make_unique<type::I32>());
|
||||
ASSERT_NE(t2, nullptr);
|
||||
}
|
||||
|
||||
|
@ -28,14 +28,14 @@ namespace {
|
||||
using UintLiteralTest = TestHelper;
|
||||
|
||||
TEST_F(UintLiteralTest, Value) {
|
||||
type::U32Type u32;
|
||||
type::U32 u32;
|
||||
UintLiteral u{&u32, 47};
|
||||
ASSERT_TRUE(u.Is<UintLiteral>());
|
||||
EXPECT_EQ(u.value(), 47u);
|
||||
}
|
||||
|
||||
TEST_F(UintLiteralTest, Is) {
|
||||
type::U32Type u32;
|
||||
type::U32 u32;
|
||||
UintLiteral u{&u32, 42};
|
||||
Literal* l = &u;
|
||||
EXPECT_FALSE(l->Is<BoolLiteral>());
|
||||
@ -46,7 +46,7 @@ TEST_F(UintLiteralTest, Is) {
|
||||
}
|
||||
|
||||
TEST_F(UintLiteralTest, ToStr) {
|
||||
type::U32Type u32;
|
||||
type::U32 u32;
|
||||
UintLiteral i{&u32, 42};
|
||||
|
||||
EXPECT_EQ(i.to_str(), "42");
|
||||
|
@ -25,7 +25,7 @@ namespace {
|
||||
using VariableDeclStatementTest = TestHelper;
|
||||
|
||||
TEST_F(VariableDeclStatementTest, Creation) {
|
||||
type::F32Type f32;
|
||||
type::F32 f32;
|
||||
auto* var = create<Variable>("a", StorageClass::kNone, &f32);
|
||||
|
||||
VariableDeclStatement stmt(var);
|
||||
@ -33,7 +33,7 @@ TEST_F(VariableDeclStatementTest, Creation) {
|
||||
}
|
||||
|
||||
TEST_F(VariableDeclStatementTest, Creation_WithSource) {
|
||||
type::F32Type f32;
|
||||
type::F32 f32;
|
||||
auto* var = create<Variable>("a", StorageClass::kNone, &f32);
|
||||
|
||||
VariableDeclStatement stmt(Source{Source::Location{20, 2}}, var);
|
||||
@ -48,14 +48,14 @@ TEST_F(VariableDeclStatementTest, IsVariableDecl) {
|
||||
}
|
||||
|
||||
TEST_F(VariableDeclStatementTest, IsValid) {
|
||||
type::F32Type f32;
|
||||
type::F32 f32;
|
||||
auto* var = create<Variable>("a", StorageClass::kNone, &f32);
|
||||
VariableDeclStatement stmt(var);
|
||||
EXPECT_TRUE(stmt.IsValid());
|
||||
}
|
||||
|
||||
TEST_F(VariableDeclStatementTest, IsValid_InvalidVariable) {
|
||||
type::F32Type f32;
|
||||
type::F32 f32;
|
||||
auto* var = create<Variable>("", StorageClass::kNone, &f32);
|
||||
VariableDeclStatement stmt(var);
|
||||
EXPECT_FALSE(stmt.IsValid());
|
||||
@ -67,7 +67,7 @@ TEST_F(VariableDeclStatementTest, IsValid_NullVariable) {
|
||||
}
|
||||
|
||||
TEST_F(VariableDeclStatementTest, ToStr) {
|
||||
type::F32Type f32;
|
||||
type::F32 f32;
|
||||
auto* var = create<Variable>("a", StorageClass::kNone, &f32);
|
||||
|
||||
VariableDeclStatement stmt(Source{Source::Location{20, 2}}, var);
|
||||
|
@ -26,7 +26,7 @@ namespace {
|
||||
using VariableTest = TestHelper;
|
||||
|
||||
TEST_F(VariableTest, Creation) {
|
||||
type::I32Type t;
|
||||
type::I32 t;
|
||||
Variable v("my_var", StorageClass::kFunction, &t);
|
||||
|
||||
EXPECT_EQ(v.name(), "my_var");
|
||||
@ -40,7 +40,7 @@ TEST_F(VariableTest, Creation) {
|
||||
|
||||
TEST_F(VariableTest, CreationWithSource) {
|
||||
Source s{Source::Range{Source::Location{27, 4}, Source::Location{27, 5}}};
|
||||
type::F32Type t;
|
||||
type::F32 t;
|
||||
Variable v(s, "i", StorageClass::kPrivate, &t);
|
||||
|
||||
EXPECT_EQ(v.name(), "i");
|
||||
@ -59,7 +59,7 @@ TEST_F(VariableTest, CreationEmpty) {
|
||||
v.set_storage_class(StorageClass::kWorkgroup);
|
||||
v.set_name("a_var");
|
||||
|
||||
type::I32Type t;
|
||||
type::I32 t;
|
||||
v.set_type(&t);
|
||||
|
||||
EXPECT_EQ(v.name(), "a_var");
|
||||
@ -72,20 +72,20 @@ TEST_F(VariableTest, CreationEmpty) {
|
||||
}
|
||||
|
||||
TEST_F(VariableTest, IsValid) {
|
||||
type::I32Type t;
|
||||
type::I32 t;
|
||||
Variable v{"my_var", StorageClass::kNone, &t};
|
||||
EXPECT_TRUE(v.IsValid());
|
||||
}
|
||||
|
||||
TEST_F(VariableTest, IsValid_WithConstructor) {
|
||||
type::I32Type t;
|
||||
type::I32 t;
|
||||
Variable v{"my_var", StorageClass::kNone, &t};
|
||||
v.set_constructor(create<IdentifierExpression>("ident"));
|
||||
EXPECT_TRUE(v.IsValid());
|
||||
}
|
||||
|
||||
TEST_F(VariableTest, IsValid_MissinName) {
|
||||
type::I32Type t;
|
||||
type::I32 t;
|
||||
Variable v{"", StorageClass::kNone, &t};
|
||||
EXPECT_FALSE(v.IsValid());
|
||||
}
|
||||
@ -101,14 +101,14 @@ TEST_F(VariableTest, IsValid_MissingBoth) {
|
||||
}
|
||||
|
||||
TEST_F(VariableTest, IsValid_InvalidConstructor) {
|
||||
type::I32Type t;
|
||||
type::I32 t;
|
||||
Variable v{"my_var", StorageClass::kNone, &t};
|
||||
v.set_constructor(create<IdentifierExpression>(""));
|
||||
EXPECT_FALSE(v.IsValid());
|
||||
}
|
||||
|
||||
TEST_F(VariableTest, to_str) {
|
||||
type::F32Type t;
|
||||
type::F32 t;
|
||||
Variable v{"my_var", StorageClass::kFunction, &t};
|
||||
std::ostringstream out;
|
||||
v.to_str(out, 2);
|
||||
|
@ -185,16 +185,16 @@ std::vector<ResourceBinding> Inspector::GetUniformBufferResourceBindings(
|
||||
ast::Variable* var = nullptr;
|
||||
ast::Function::BindingInfo binding_info;
|
||||
std::tie(var, binding_info) = ruv;
|
||||
if (!var->type()->Is<ast::type::AccessControlType>()) {
|
||||
if (!var->type()->Is<ast::type::AccessControl>()) {
|
||||
continue;
|
||||
}
|
||||
auto* unwrapped_type = var->type()->UnwrapIfNeeded();
|
||||
|
||||
if (!unwrapped_type->Is<ast::type::StructType>()) {
|
||||
if (!unwrapped_type->Is<ast::type::Struct>()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!unwrapped_type->As<ast::type::StructType>()->IsBlockDecorated()) {
|
||||
if (!unwrapped_type->As<ast::type::Struct>()->IsBlockDecorated()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -307,16 +307,16 @@ std::vector<ResourceBinding> Inspector::GetStorageBufferResourceBindingsImpl(
|
||||
ast::Variable* var = nullptr;
|
||||
ast::Function::BindingInfo binding_info;
|
||||
std::tie(var, binding_info) = rsv;
|
||||
if (!var->type()->Is<ast::type::AccessControlType>()) {
|
||||
if (!var->type()->Is<ast::type::AccessControl>()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto* ac_type = var->type()->As<ast::type::AccessControlType>();
|
||||
auto* ac_type = var->type()->As<ast::type::AccessControl>();
|
||||
if (read_only != ac_type->IsReadOnly()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!var->type()->UnwrapIfNeeded()->Is<ast::type::StructType>()) {
|
||||
if (!var->type()->UnwrapIfNeeded()->Is<ast::type::Struct>()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -353,7 +353,7 @@ std::vector<ResourceBinding> Inspector::GetSampledTextureResourceBindingsImpl(
|
||||
entry.binding = binding_info.binding->value();
|
||||
|
||||
auto* texture_type =
|
||||
var->type()->UnwrapIfNeeded()->As<ast::type::TextureType>();
|
||||
var->type()->UnwrapIfNeeded()->As<ast::type::Texture>();
|
||||
switch (texture_type->dim()) {
|
||||
case ast::type::TextureDimension::k1d:
|
||||
entry.dim = ResourceBinding::TextureDimension::k1d;
|
||||
@ -383,28 +383,28 @@ std::vector<ResourceBinding> Inspector::GetSampledTextureResourceBindingsImpl(
|
||||
|
||||
ast::type::Type* base_type = nullptr;
|
||||
if (multisampled_only) {
|
||||
base_type = texture_type->As<ast::type::MultisampledTextureType>()
|
||||
base_type = texture_type->As<ast::type::MultisampledTexture>()
|
||||
->type()
|
||||
->UnwrapIfNeeded();
|
||||
} else {
|
||||
base_type = texture_type->As<ast::type::SampledTextureType>()
|
||||
base_type = texture_type->As<ast::type::SampledTexture>()
|
||||
->type()
|
||||
->UnwrapIfNeeded();
|
||||
}
|
||||
|
||||
if (base_type->Is<ast::type::ArrayType>()) {
|
||||
base_type = base_type->As<ast::type::ArrayType>()->type();
|
||||
} else if (base_type->Is<ast::type::MatrixType>()) {
|
||||
base_type = base_type->As<ast::type::MatrixType>()->type();
|
||||
} else if (base_type->Is<ast::type::VectorType>()) {
|
||||
base_type = base_type->As<ast::type::VectorType>()->type();
|
||||
if (base_type->Is<ast::type::Array>()) {
|
||||
base_type = base_type->As<ast::type::Array>()->type();
|
||||
} else if (base_type->Is<ast::type::Matrix>()) {
|
||||
base_type = base_type->As<ast::type::Matrix>()->type();
|
||||
} else if (base_type->Is<ast::type::Vector>()) {
|
||||
base_type = base_type->As<ast::type::Vector>()->type();
|
||||
}
|
||||
|
||||
if (base_type->Is<ast::type::F32Type>()) {
|
||||
if (base_type->Is<ast::type::F32>()) {
|
||||
entry.sampled_kind = ResourceBinding::SampledKind::kFloat;
|
||||
} else if (base_type->Is<ast::type::U32Type>()) {
|
||||
} else if (base_type->Is<ast::type::U32>()) {
|
||||
entry.sampled_kind = ResourceBinding::SampledKind::kUInt;
|
||||
} else if (base_type->Is<ast::type::I32Type>()) {
|
||||
} else if (base_type->Is<ast::type::I32>()) {
|
||||
entry.sampled_kind = ResourceBinding::SampledKind::kSInt;
|
||||
} else {
|
||||
entry.sampled_kind = ResourceBinding::SampledKind::kUnknown;
|
||||
|
@ -244,7 +244,7 @@ class InspectorHelper {
|
||||
/// type and offset of a member of the struct
|
||||
/// @param is_block whether or not to decorate as a Block
|
||||
/// @returns a struct type
|
||||
std::unique_ptr<ast::type::StructType> MakeStructType(
|
||||
std::unique_ptr<ast::type::Struct> MakeStructType(
|
||||
const std::string& name,
|
||||
std::vector<std::tuple<ast::type::Type*, uint32_t>> members_info,
|
||||
bool is_block) {
|
||||
@ -269,7 +269,7 @@ class InspectorHelper {
|
||||
|
||||
auto* str = create<ast::Struct>(decos, members);
|
||||
|
||||
return std::make_unique<ast::type::StructType>(name, str);
|
||||
return std::make_unique<ast::type::Struct>(name, str);
|
||||
}
|
||||
|
||||
/// Generates types appropriate for using in an uniform buffer
|
||||
@ -279,13 +279,13 @@ class InspectorHelper {
|
||||
/// @returns a tuple {struct type, access control type}, where the struct has
|
||||
/// the layout for an uniform buffer, and the control type wraps the
|
||||
/// struct.
|
||||
std::tuple<std::unique_ptr<ast::type::StructType>,
|
||||
std::unique_ptr<ast::type::AccessControlType>>
|
||||
std::tuple<std::unique_ptr<ast::type::Struct>,
|
||||
std::unique_ptr<ast::type::AccessControl>>
|
||||
MakeUniformBufferTypes(
|
||||
const std::string& name,
|
||||
std::vector<std::tuple<ast::type::Type*, uint32_t>> members_info) {
|
||||
auto struct_type = MakeStructType(name, members_info, true);
|
||||
auto access_type = std::make_unique<ast::type::AccessControlType>(
|
||||
auto access_type = std::make_unique<ast::type::AccessControl>(
|
||||
ast::AccessControl::kReadOnly, struct_type.get());
|
||||
return {std::move(struct_type), std::move(access_type)};
|
||||
}
|
||||
@ -297,13 +297,13 @@ class InspectorHelper {
|
||||
/// @returns a tuple {struct type, access control type}, where the struct has
|
||||
/// the layout for a storage buffer, and the control type wraps the
|
||||
/// struct.
|
||||
std::tuple<std::unique_ptr<ast::type::StructType>,
|
||||
std::unique_ptr<ast::type::AccessControlType>>
|
||||
std::tuple<std::unique_ptr<ast::type::Struct>,
|
||||
std::unique_ptr<ast::type::AccessControl>>
|
||||
MakeStorageBufferTypes(
|
||||
const std::string& name,
|
||||
std::vector<std::tuple<ast::type::Type*, uint32_t>> members_info) {
|
||||
auto struct_type = MakeStructType(name, members_info, false);
|
||||
auto access_type = std::make_unique<ast::type::AccessControlType>(
|
||||
auto access_type = std::make_unique<ast::type::AccessControl>(
|
||||
ast::AccessControl::kReadWrite, struct_type.get());
|
||||
return {std::move(struct_type), std::move(access_type)};
|
||||
}
|
||||
@ -315,13 +315,13 @@ class InspectorHelper {
|
||||
/// @returns a tuple {struct type, access control type}, where the struct has
|
||||
/// the layout for a read-only storage buffer, and the control type
|
||||
/// wraps the struct.
|
||||
std::tuple<std::unique_ptr<ast::type::StructType>,
|
||||
std::unique_ptr<ast::type::AccessControlType>>
|
||||
std::tuple<std::unique_ptr<ast::type::Struct>,
|
||||
std::unique_ptr<ast::type::AccessControl>>
|
||||
MakeReadOnlyStorageBufferTypes(
|
||||
const std::string& name,
|
||||
std::vector<std::tuple<ast::type::Type*, uint32_t>> members_info) {
|
||||
auto struct_type = MakeStructType(name, members_info, false);
|
||||
auto access_type = std::make_unique<ast::type::AccessControlType>(
|
||||
auto access_type = std::make_unique<ast::type::AccessControl>(
|
||||
ast::AccessControl::kReadOnly, struct_type.get());
|
||||
return {std::move(struct_type), std::move(access_type)};
|
||||
}
|
||||
@ -429,32 +429,32 @@ class InspectorHelper {
|
||||
ast::StorageClass::kUniformConstant, set, binding);
|
||||
}
|
||||
|
||||
/// Generates a SampledTextureType appropriate for the params
|
||||
/// Generates a SampledTexture appropriate for the params
|
||||
/// @param dim the dimensions of the texture
|
||||
/// @param type the data type of the sampled texture
|
||||
/// @returns the generated SampleTextureType
|
||||
std::unique_ptr<ast::type::SampledTextureType> MakeSampledTextureType(
|
||||
std::unique_ptr<ast::type::SampledTexture> MakeSampledTextureType(
|
||||
ast::type::TextureDimension dim,
|
||||
ast::type::Type* type) {
|
||||
return std::make_unique<ast::type::SampledTextureType>(dim, type);
|
||||
return std::make_unique<ast::type::SampledTexture>(dim, type);
|
||||
}
|
||||
|
||||
/// Generates a DepthTextureType appropriate for the params
|
||||
/// Generates a DepthTexture appropriate for the params
|
||||
/// @param dim the dimensions of the texture
|
||||
/// @returns the generated DepthTextureType
|
||||
std::unique_ptr<ast::type::DepthTextureType> MakeDepthTextureType(
|
||||
/// @returns the generated DepthTexture
|
||||
std::unique_ptr<ast::type::DepthTexture> MakeDepthTextureType(
|
||||
ast::type::TextureDimension dim) {
|
||||
return std::make_unique<ast::type::DepthTextureType>(dim);
|
||||
return std::make_unique<ast::type::DepthTexture>(dim);
|
||||
}
|
||||
|
||||
/// Generates a MultisampledTextureType appropriate for the params
|
||||
/// Generates a MultisampledTexture appropriate for the params
|
||||
/// @param dim the dimensions of the texture
|
||||
/// @param type the data type of the sampled texture
|
||||
/// @returns the generated SampleTextureType
|
||||
std::unique_ptr<ast::type::MultisampledTextureType>
|
||||
MakeMultisampledTextureType(ast::type::TextureDimension dim,
|
||||
ast::type::Type* type) {
|
||||
return std::make_unique<ast::type::MultisampledTextureType>(dim, type);
|
||||
std::unique_ptr<ast::type::MultisampledTexture> MakeMultisampledTextureType(
|
||||
ast::type::TextureDimension dim,
|
||||
ast::type::Type* type) {
|
||||
return std::make_unique<ast::type::MultisampledTexture>(dim, type);
|
||||
}
|
||||
|
||||
/// Adds a sampled texture variable to the module
|
||||
@ -645,31 +645,31 @@ class InspectorHelper {
|
||||
TypeDeterminer* td() { return td_.get(); }
|
||||
Inspector* inspector() { return inspector_.get(); }
|
||||
|
||||
ast::type::BoolType* bool_type() { return &bool_type_; }
|
||||
ast::type::F32Type* f32_type() { return &f32_type_; }
|
||||
ast::type::I32Type* i32_type() { return &i32_type_; }
|
||||
ast::type::U32Type* u32_type() { return &u32_type_; }
|
||||
ast::type::ArrayType* u32_array_type(uint32_t count) {
|
||||
ast::type::Bool* bool_type() { return &bool_type_; }
|
||||
ast::type::F32* f32_type() { return &f32_type_; }
|
||||
ast::type::I32* i32_type() { return &i32_type_; }
|
||||
ast::type::U32* u32_type() { return &u32_type_; }
|
||||
ast::type::Array* u32_array_type(uint32_t count) {
|
||||
if (array_type_memo_.find(count) == array_type_memo_.end()) {
|
||||
array_type_memo_[count] =
|
||||
std::make_unique<ast::type::ArrayType>(u32_type(), count);
|
||||
std::make_unique<ast::type::Array>(u32_type(), count);
|
||||
ast::ArrayDecorationList decos;
|
||||
decos.push_back(create<ast::StrideDecoration>(4, Source{}));
|
||||
array_type_memo_[count]->set_decorations(decos);
|
||||
}
|
||||
return array_type_memo_[count].get();
|
||||
}
|
||||
ast::type::VectorType* vec_type(ast::type::Type* type, uint32_t count) {
|
||||
ast::type::Vector* vec_type(ast::type::Type* type, uint32_t count) {
|
||||
if (vector_type_memo_.find(std::tie(type, count)) ==
|
||||
vector_type_memo_.end()) {
|
||||
vector_type_memo_[std::tie(type, count)] =
|
||||
std::make_unique<ast::type::VectorType>(u32_type(), count);
|
||||
std::make_unique<ast::type::Vector>(u32_type(), count);
|
||||
}
|
||||
return vector_type_memo_[std::tie(type, count)].get();
|
||||
}
|
||||
ast::type::VoidType* void_type() { return &void_type_; }
|
||||
ast::type::SamplerType* sampler_type() { return &sampler_type_; }
|
||||
ast::type::SamplerType* comparison_sampler_type() {
|
||||
ast::type::Void* void_type() { return &void_type_; }
|
||||
ast::type::Sampler* sampler_type() { return &sampler_type_; }
|
||||
ast::type::Sampler* comparison_sampler_type() {
|
||||
return &comparison_sampler_type_;
|
||||
}
|
||||
|
||||
@ -688,16 +688,16 @@ class InspectorHelper {
|
||||
std::unique_ptr<TypeDeterminer> td_;
|
||||
std::unique_ptr<Inspector> inspector_;
|
||||
|
||||
ast::type::BoolType bool_type_;
|
||||
ast::type::F32Type f32_type_;
|
||||
ast::type::I32Type i32_type_;
|
||||
ast::type::U32Type u32_type_;
|
||||
ast::type::VoidType void_type_;
|
||||
ast::type::SamplerType sampler_type_;
|
||||
ast::type::SamplerType comparison_sampler_type_;
|
||||
std::map<uint32_t, std::unique_ptr<ast::type::ArrayType>> array_type_memo_;
|
||||
ast::type::Bool bool_type_;
|
||||
ast::type::F32 f32_type_;
|
||||
ast::type::I32 i32_type_;
|
||||
ast::type::U32 u32_type_;
|
||||
ast::type::Void void_type_;
|
||||
ast::type::Sampler sampler_type_;
|
||||
ast::type::Sampler comparison_sampler_type_;
|
||||
std::map<uint32_t, std::unique_ptr<ast::type::Array>> array_type_memo_;
|
||||
std::map<std::tuple<ast::type::Type*, uint32_t>,
|
||||
std::unique_ptr<ast::type::VectorType>>
|
||||
std::unique_ptr<ast::type::Vector>>
|
||||
vector_type_memo_;
|
||||
};
|
||||
|
||||
@ -1234,8 +1234,8 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MissingEntryPoint) {
|
||||
}
|
||||
|
||||
TEST_F(InspectorGetUniformBufferResourceBindingsTest, NonEntryPointFunc) {
|
||||
std::unique_ptr<ast::type::StructType> foo_struct_type;
|
||||
std::unique_ptr<ast::type::AccessControlType> foo_control_type;
|
||||
std::unique_ptr<ast::type::Struct> foo_struct_type;
|
||||
std::unique_ptr<ast::type::AccessControl> foo_control_type;
|
||||
std::tie(foo_struct_type, foo_control_type) =
|
||||
MakeUniformBufferTypes("foo_type", {{i32_type(), 0}});
|
||||
AddUniformBuffer("foo_ub", foo_control_type.get(), 0, 0);
|
||||
@ -1267,7 +1267,7 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MissingBlockDeco) {
|
||||
ast::StructDecorationList decos;
|
||||
|
||||
auto* str = create<ast::Struct>(decos, members);
|
||||
auto foo_type = std::make_unique<ast::type::StructType>("foo_type", str);
|
||||
auto foo_type = std::make_unique<ast::type::Struct>("foo_type", str);
|
||||
|
||||
AddUniformBuffer("foo_ub", foo_type.get(), 0, 0);
|
||||
|
||||
@ -1288,8 +1288,8 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MissingBlockDeco) {
|
||||
}
|
||||
|
||||
TEST_F(InspectorGetUniformBufferResourceBindingsTest, Simple) {
|
||||
std::unique_ptr<ast::type::StructType> foo_struct_type;
|
||||
std::unique_ptr<ast::type::AccessControlType> foo_control_type;
|
||||
std::unique_ptr<ast::type::Struct> foo_struct_type;
|
||||
std::unique_ptr<ast::type::AccessControl> foo_control_type;
|
||||
std::tie(foo_struct_type, foo_control_type) =
|
||||
MakeUniformBufferTypes("foo_type", {{i32_type(), 0}});
|
||||
AddUniformBuffer("foo_ub", foo_control_type.get(), 0, 0);
|
||||
@ -1315,8 +1315,8 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, Simple) {
|
||||
}
|
||||
|
||||
TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleMembers) {
|
||||
std::unique_ptr<ast::type::StructType> foo_struct_type;
|
||||
std::unique_ptr<ast::type::AccessControlType> foo_control_type;
|
||||
std::unique_ptr<ast::type::Struct> foo_struct_type;
|
||||
std::unique_ptr<ast::type::AccessControl> foo_control_type;
|
||||
std::tie(foo_struct_type, foo_control_type) = MakeUniformBufferTypes(
|
||||
"foo_type", {{i32_type(), 0}, {u32_type(), 4}, {f32_type(), 8}});
|
||||
AddUniformBuffer("foo_ub", foo_control_type.get(), 0, 0);
|
||||
@ -1342,8 +1342,8 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleMembers) {
|
||||
}
|
||||
|
||||
TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleUniformBuffers) {
|
||||
std::unique_ptr<ast::type::StructType> ub_struct_type;
|
||||
std::unique_ptr<ast::type::AccessControlType> ub_control_type;
|
||||
std::unique_ptr<ast::type::Struct> ub_struct_type;
|
||||
std::unique_ptr<ast::type::AccessControl> ub_control_type;
|
||||
std::tie(ub_struct_type, ub_control_type) = MakeUniformBufferTypes(
|
||||
"ub_type", {{i32_type(), 0}, {u32_type(), 4}, {f32_type(), 8}});
|
||||
AddUniformBuffer("ub_foo", ub_control_type.get(), 0, 0);
|
||||
@ -1401,8 +1401,8 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleUniformBuffers) {
|
||||
}
|
||||
|
||||
TEST_F(InspectorGetUniformBufferResourceBindingsTest, ContainingArray) {
|
||||
std::unique_ptr<ast::type::StructType> foo_struct_type;
|
||||
std::unique_ptr<ast::type::AccessControlType> foo_control_type;
|
||||
std::unique_ptr<ast::type::Struct> foo_struct_type;
|
||||
std::unique_ptr<ast::type::AccessControl> foo_control_type;
|
||||
std::tie(foo_struct_type, foo_control_type) = MakeUniformBufferTypes(
|
||||
"foo_type", {{i32_type(), 0}, {u32_array_type(4), 4}});
|
||||
AddUniformBuffer("foo_ub", foo_control_type.get(), 0, 0);
|
||||
@ -1428,8 +1428,8 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, ContainingArray) {
|
||||
}
|
||||
|
||||
TEST_F(InspectorGetStorageBufferResourceBindingsTest, Simple) {
|
||||
std::unique_ptr<ast::type::StructType> foo_struct_type;
|
||||
std::unique_ptr<ast::type::AccessControlType> foo_control_type;
|
||||
std::unique_ptr<ast::type::Struct> foo_struct_type;
|
||||
std::unique_ptr<ast::type::AccessControl> foo_control_type;
|
||||
std::tie(foo_struct_type, foo_control_type) =
|
||||
MakeStorageBufferTypes("foo_type", {{i32_type(), 0}});
|
||||
AddStorageBuffer("foo_sb", foo_control_type.get(), 0, 0);
|
||||
@ -1455,8 +1455,8 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, Simple) {
|
||||
}
|
||||
|
||||
TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleMembers) {
|
||||
std::unique_ptr<ast::type::StructType> foo_struct_type;
|
||||
std::unique_ptr<ast::type::AccessControlType> foo_control_type;
|
||||
std::unique_ptr<ast::type::Struct> foo_struct_type;
|
||||
std::unique_ptr<ast::type::AccessControl> foo_control_type;
|
||||
std::tie(foo_struct_type, foo_control_type) = MakeStorageBufferTypes(
|
||||
"foo_type", {{i32_type(), 0}, {u32_type(), 4}, {f32_type(), 8}});
|
||||
AddStorageBuffer("foo_sb", foo_control_type.get(), 0, 0);
|
||||
@ -1482,8 +1482,8 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleMembers) {
|
||||
}
|
||||
|
||||
TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleStorageBuffers) {
|
||||
std::unique_ptr<ast::type::StructType> sb_struct_type;
|
||||
std::unique_ptr<ast::type::AccessControlType> sb_control_type;
|
||||
std::unique_ptr<ast::type::Struct> sb_struct_type;
|
||||
std::unique_ptr<ast::type::AccessControl> sb_control_type;
|
||||
std::tie(sb_struct_type, sb_control_type) = MakeStorageBufferTypes(
|
||||
"sb_type", {{i32_type(), 0}, {u32_type(), 4}, {f32_type(), 8}});
|
||||
AddStorageBuffer("sb_foo", sb_control_type.get(), 0, 0);
|
||||
@ -1541,8 +1541,8 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleStorageBuffers) {
|
||||
}
|
||||
|
||||
TEST_F(InspectorGetStorageBufferResourceBindingsTest, ContainingArray) {
|
||||
std::unique_ptr<ast::type::StructType> foo_struct_type;
|
||||
std::unique_ptr<ast::type::AccessControlType> foo_control_type;
|
||||
std::unique_ptr<ast::type::Struct> foo_struct_type;
|
||||
std::unique_ptr<ast::type::AccessControl> foo_control_type;
|
||||
std::tie(foo_struct_type, foo_control_type) = MakeStorageBufferTypes(
|
||||
"foo_type", {{i32_type(), 0}, {u32_array_type(4), 4}});
|
||||
AddStorageBuffer("foo_sb", foo_control_type.get(), 0, 0);
|
||||
@ -1568,8 +1568,8 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, ContainingArray) {
|
||||
}
|
||||
|
||||
TEST_F(InspectorGetStorageBufferResourceBindingsTest, ContainingRuntimeArray) {
|
||||
std::unique_ptr<ast::type::StructType> foo_struct_type;
|
||||
std::unique_ptr<ast::type::AccessControlType> foo_control_type;
|
||||
std::unique_ptr<ast::type::Struct> foo_struct_type;
|
||||
std::unique_ptr<ast::type::AccessControl> foo_control_type;
|
||||
std::tie(foo_struct_type, foo_control_type) = MakeStorageBufferTypes(
|
||||
"foo_type", {{i32_type(), 0}, {u32_array_type(0), 4}});
|
||||
AddStorageBuffer("foo_sb", foo_control_type.get(), 0, 0);
|
||||
@ -1595,8 +1595,8 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, ContainingRuntimeArray) {
|
||||
}
|
||||
|
||||
TEST_F(InspectorGetStorageBufferResourceBindingsTest, SkipReadOnly) {
|
||||
std::unique_ptr<ast::type::StructType> foo_struct_type;
|
||||
std::unique_ptr<ast::type::AccessControlType> foo_control_type;
|
||||
std::unique_ptr<ast::type::Struct> foo_struct_type;
|
||||
std::unique_ptr<ast::type::AccessControl> foo_control_type;
|
||||
std::tie(foo_struct_type, foo_control_type) =
|
||||
MakeReadOnlyStorageBufferTypes("foo_type", {{i32_type(), 0}});
|
||||
AddStorageBuffer("foo_sb", foo_control_type.get(), 0, 0);
|
||||
@ -1618,8 +1618,8 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, SkipReadOnly) {
|
||||
}
|
||||
|
||||
TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, Simple) {
|
||||
std::unique_ptr<ast::type::StructType> foo_struct_type;
|
||||
std::unique_ptr<ast::type::AccessControlType> foo_control_type;
|
||||
std::unique_ptr<ast::type::Struct> foo_struct_type;
|
||||
std::unique_ptr<ast::type::AccessControl> foo_control_type;
|
||||
std::tie(foo_struct_type, foo_control_type) =
|
||||
MakeReadOnlyStorageBufferTypes("foo_type", {{i32_type(), 0}});
|
||||
AddStorageBuffer("foo_sb", foo_control_type.get(), 0, 0);
|
||||
@ -1647,8 +1647,8 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, Simple) {
|
||||
|
||||
TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest,
|
||||
MultipleStorageBuffers) {
|
||||
std::unique_ptr<ast::type::StructType> sb_struct_type;
|
||||
std::unique_ptr<ast::type::AccessControlType> sb_control_type;
|
||||
std::unique_ptr<ast::type::Struct> sb_struct_type;
|
||||
std::unique_ptr<ast::type::AccessControl> sb_control_type;
|
||||
std::tie(sb_struct_type, sb_control_type) = MakeReadOnlyStorageBufferTypes(
|
||||
"sb_type", {{i32_type(), 0}, {u32_type(), 4}, {f32_type(), 8}});
|
||||
AddStorageBuffer("sb_foo", sb_control_type.get(), 0, 0);
|
||||
@ -1707,8 +1707,8 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest,
|
||||
}
|
||||
|
||||
TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, ContainingArray) {
|
||||
std::unique_ptr<ast::type::StructType> foo_struct_type;
|
||||
std::unique_ptr<ast::type::AccessControlType> foo_control_type;
|
||||
std::unique_ptr<ast::type::Struct> foo_struct_type;
|
||||
std::unique_ptr<ast::type::AccessControl> foo_control_type;
|
||||
std::tie(foo_struct_type, foo_control_type) = MakeReadOnlyStorageBufferTypes(
|
||||
"foo_type", {{i32_type(), 0}, {u32_array_type(4), 4}});
|
||||
AddStorageBuffer("foo_sb", foo_control_type.get(), 0, 0);
|
||||
@ -1736,8 +1736,8 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, ContainingArray) {
|
||||
|
||||
TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest,
|
||||
ContainingRuntimeArray) {
|
||||
std::unique_ptr<ast::type::StructType> foo_struct_type;
|
||||
std::unique_ptr<ast::type::AccessControlType> foo_control_type;
|
||||
std::unique_ptr<ast::type::Struct> foo_struct_type;
|
||||
std::unique_ptr<ast::type::AccessControl> foo_control_type;
|
||||
std::tie(foo_struct_type, foo_control_type) = MakeReadOnlyStorageBufferTypes(
|
||||
"foo_type", {{i32_type(), 0}, {u32_array_type(0), 4}});
|
||||
AddStorageBuffer("foo_sb", foo_control_type.get(), 0, 0);
|
||||
@ -1764,8 +1764,8 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest,
|
||||
}
|
||||
|
||||
TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, SkipNonReadOnly) {
|
||||
std::unique_ptr<ast::type::StructType> foo_struct_type;
|
||||
std::unique_ptr<ast::type::AccessControlType> foo_control_type;
|
||||
std::unique_ptr<ast::type::Struct> foo_struct_type;
|
||||
std::unique_ptr<ast::type::AccessControl> foo_control_type;
|
||||
std::tie(foo_struct_type, foo_control_type) =
|
||||
MakeStorageBufferTypes("foo_type", {{i32_type(), 0}});
|
||||
AddStorageBuffer("foo_sb", foo_control_type.get(), 0, 0);
|
||||
|
@ -2013,7 +2013,7 @@ bool FunctionEmitter::EmitIfStart(const BlockInfo& block_info) {
|
||||
if (!guard_name.empty()) {
|
||||
// Declare the guard variable just before the "if", initialized to true.
|
||||
auto* guard_var = create<ast::Variable>(
|
||||
guard_name, ast::StorageClass::kFunction, parser_impl_.BoolType());
|
||||
guard_name, ast::StorageClass::kFunction, parser_impl_.Bool());
|
||||
guard_var->set_constructor(MakeTrue());
|
||||
auto* guard_decl = create<ast::VariableDeclStatement>(guard_var);
|
||||
AddStatement(guard_decl);
|
||||
@ -2700,8 +2700,8 @@ bool FunctionEmitter::EmitStatement(const spvtools::opt::Instruction& inst) {
|
||||
// So represent a load by a new const definition.
|
||||
auto expr = MakeExpression(inst.GetSingleWordInOperand(0));
|
||||
// The load result type is the pointee type of its operand.
|
||||
assert(expr.type->Is<ast::type::PointerType>());
|
||||
expr.type = expr.type->As<ast::type::PointerType>()->type();
|
||||
assert(expr.type->Is<ast::type::Pointer>());
|
||||
expr.type = expr.type->As<ast::type::Pointer>()->type();
|
||||
return EmitConstDefOrWriteToHoistedVar(inst, expr);
|
||||
}
|
||||
case SpvOpCopyObject: {
|
||||
@ -3061,7 +3061,7 @@ TypedExpression FunctionEmitter::MakeAccessChain(
|
||||
type_mgr_->FindPointerToType(pointee_type_id, storage_class);
|
||||
auto* ast_pointer_type = parser_impl_.ConvertType(pointer_type_id);
|
||||
assert(ast_pointer_type);
|
||||
assert(ast_pointer_type->Is<ast::type::PointerType>());
|
||||
assert(ast_pointer_type->Is<ast::type::Pointer>());
|
||||
current_expr = TypedExpression{ast_pointer_type, next_expr};
|
||||
}
|
||||
return current_expr;
|
||||
@ -3080,7 +3080,7 @@ TypedExpression FunctionEmitter::MakeCompositeExtract(
|
||||
TypedExpression current_expr(MakeOperand(inst, 0));
|
||||
|
||||
auto make_index = [this](uint32_t literal) {
|
||||
ast::type::U32Type u32;
|
||||
ast::type::U32 u32;
|
||||
return create<ast::ScalarConstructorExpression>(
|
||||
create<ast::UintLiteral>(&u32, literal));
|
||||
};
|
||||
@ -3183,13 +3183,13 @@ TypedExpression FunctionEmitter::MakeCompositeExtract(
|
||||
|
||||
ast::Expression* FunctionEmitter::MakeTrue() const {
|
||||
return create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(parser_impl_.BoolType(), true));
|
||||
create<ast::BoolLiteral>(parser_impl_.Bool(), true));
|
||||
}
|
||||
|
||||
ast::Expression* FunctionEmitter::MakeFalse() const {
|
||||
ast::type::BoolType bool_type;
|
||||
ast::type::Bool bool_type;
|
||||
return create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(parser_impl_.BoolType(), false));
|
||||
create<ast::BoolLiteral>(parser_impl_.Bool(), false));
|
||||
}
|
||||
|
||||
TypedExpression FunctionEmitter::MakeVectorShuffle(
|
||||
@ -3207,8 +3207,8 @@ TypedExpression FunctionEmitter::MakeVectorShuffle(
|
||||
|
||||
// Generate an ast::TypeConstructor expression.
|
||||
// Assume the literal indices are valid, and there is a valid number of them.
|
||||
ast::type::VectorType* result_type =
|
||||
parser_impl_.ConvertType(inst.type_id())->As<ast::type::VectorType>();
|
||||
ast::type::Vector* result_type =
|
||||
parser_impl_.ConvertType(inst.type_id())->As<ast::type::Vector>();
|
||||
ast::ExpressionList values;
|
||||
for (uint32_t i = 2; i < inst.NumInOperands(); ++i) {
|
||||
const auto index = inst.GetSingleWordInOperand(i);
|
||||
@ -3257,9 +3257,9 @@ bool FunctionEmitter::RegisterLocallyDefinedValues() {
|
||||
if (type) {
|
||||
if (type->AsPointer()) {
|
||||
const auto* ast_type = parser_impl_.ConvertType(inst.type_id());
|
||||
if (ast_type && ast_type->As<ast::type::PointerType>()) {
|
||||
if (ast_type && ast_type->As<ast::type::Pointer>()) {
|
||||
info->storage_class =
|
||||
ast_type->As<ast::type::PointerType>()->storage_class();
|
||||
ast_type->As<ast::type::Pointer>()->storage_class();
|
||||
}
|
||||
switch (inst.opcode()) {
|
||||
case SpvOpUndef:
|
||||
@ -3301,8 +3301,8 @@ ast::StorageClass FunctionEmitter::GetStorageClassForPointerValue(uint32_t id) {
|
||||
const auto type_id = def_use_mgr_->GetDef(id)->type_id();
|
||||
if (type_id) {
|
||||
auto* ast_type = parser_impl_.ConvertType(type_id);
|
||||
if (ast_type && ast_type->Is<ast::type::PointerType>()) {
|
||||
return ast_type->As<ast::type::PointerType>()->storage_class();
|
||||
if (ast_type && ast_type->Is<ast::type::Pointer>()) {
|
||||
return ast_type->As<ast::type::Pointer>()->storage_class();
|
||||
}
|
||||
}
|
||||
return ast::StorageClass::kNone;
|
||||
@ -3310,13 +3310,13 @@ ast::StorageClass FunctionEmitter::GetStorageClassForPointerValue(uint32_t id) {
|
||||
|
||||
ast::type::Type* FunctionEmitter::RemapStorageClass(ast::type::Type* type,
|
||||
uint32_t result_id) {
|
||||
if (type->Is<ast::type::PointerType>()) {
|
||||
if (type->Is<ast::type::Pointer>()) {
|
||||
// Remap an old-style storage buffer pointer to a new-style storage
|
||||
// buffer pointer.
|
||||
const auto* ast_ptr_type = type->As<ast::type::PointerType>();
|
||||
const auto* ast_ptr_type = type->As<ast::type::Pointer>();
|
||||
const auto sc = GetStorageClassForPointerValue(result_id);
|
||||
if (ast_ptr_type->storage_class() != sc) {
|
||||
return parser_impl_.get_module().create<ast::type::PointerType>(
|
||||
return parser_impl_.get_module().create<ast::type::Pointer>(
|
||||
ast_ptr_type->type(), sc);
|
||||
}
|
||||
}
|
||||
@ -3558,7 +3558,7 @@ bool FunctionEmitter::EmitFunctionCall(const spvtools::opt::Instruction& inst) {
|
||||
<< inst.PrettyPrint();
|
||||
}
|
||||
|
||||
if (result_type->Is<ast::type::VoidType>()) {
|
||||
if (result_type->Is<ast::type::Void>()) {
|
||||
return nullptr != AddStatementForInstruction(
|
||||
create<ast::CallStatement>(call_expr), inst);
|
||||
}
|
||||
@ -3600,8 +3600,8 @@ TypedExpression FunctionEmitter::MakeSimpleSelect(
|
||||
// - you can't select over pointers or pointer vectors, unless you also have
|
||||
// a VariablePointers* capability, which is not allowed in by WebGPU.
|
||||
auto* op_ty = operand1.type;
|
||||
if (op_ty->Is<ast::type::VectorType>() || op_ty->is_float_scalar() ||
|
||||
op_ty->is_integer_scalar() || op_ty->Is<ast::type::BoolType>()) {
|
||||
if (op_ty->Is<ast::type::Vector>() || op_ty->is_float_scalar() ||
|
||||
op_ty->is_integer_scalar() || op_ty->Is<ast::type::Bool>()) {
|
||||
ast::ExpressionList params;
|
||||
params.push_back(operand1.expr);
|
||||
params.push_back(operand2.expr);
|
||||
@ -3711,14 +3711,13 @@ bool FunctionEmitter::EmitSampledImageAccess(
|
||||
auto* lod_operand = MakeOperand(inst, arg_index).expr;
|
||||
// When sampling from a depth texture, the Lod operand must be an unsigned
|
||||
// integer.
|
||||
if (ast::type::PointerType* type =
|
||||
parser_impl_.GetTypeForHandleVar(*image)) {
|
||||
if (ast::type::TextureType* texture_type =
|
||||
type->type()->As<ast::type::TextureType>()) {
|
||||
if (texture_type->Is<ast::type::DepthTextureType>()) {
|
||||
if (ast::type::Pointer* type = parser_impl_.GetTypeForHandleVar(*image)) {
|
||||
if (ast::type::Texture* texture_type =
|
||||
type->type()->As<ast::type::Texture>()) {
|
||||
if (texture_type->Is<ast::type::DepthTexture>()) {
|
||||
// Convert it to an unsigned integer type.
|
||||
lod_operand = ast_module_.create<ast::TypeConstructorExpression>(
|
||||
ast_module_.create<ast::type::U32Type>(),
|
||||
ast_module_.create<ast::type::U32>(),
|
||||
ast::ExpressionList{lod_operand});
|
||||
}
|
||||
}
|
||||
@ -3780,17 +3779,17 @@ ast::ExpressionList FunctionEmitter::MakeCoordinateOperandsForImageAccess(
|
||||
if (!raw_coords.type) {
|
||||
return {};
|
||||
}
|
||||
ast::type::PointerType* type = parser_impl_.GetTypeForHandleVar(*image);
|
||||
ast::type::Pointer* type = parser_impl_.GetTypeForHandleVar(*image);
|
||||
if (!parser_impl_.success()) {
|
||||
Fail();
|
||||
return {};
|
||||
}
|
||||
if (!type || !type->type()->Is<ast::type::TextureType>()) {
|
||||
if (!type || !type->type()->Is<ast::type::Texture>()) {
|
||||
Fail() << "invalid texture type for " << image->PrettyPrint();
|
||||
return {};
|
||||
}
|
||||
ast::type::TextureDimension dim =
|
||||
type->type()->As<ast::type::TextureType>()->dim();
|
||||
type->type()->As<ast::type::Texture>()->dim();
|
||||
// Number of regular coordinates.
|
||||
uint32_t num_axes = 0;
|
||||
bool is_arrayed = false;
|
||||
@ -3829,10 +3828,10 @@ ast::ExpressionList FunctionEmitter::MakeCoordinateOperandsForImageAccess(
|
||||
assert(num_axes <= 3);
|
||||
const auto num_coords_required = num_axes + (is_arrayed ? 1 : 0);
|
||||
uint32_t num_coords_supplied = 0;
|
||||
if (raw_coords.type->Is<ast::type::F32Type>()) {
|
||||
if (raw_coords.type->Is<ast::type::F32>()) {
|
||||
num_coords_supplied = 1;
|
||||
} else if (raw_coords.type->Is<ast::type::VectorType>()) {
|
||||
num_coords_supplied = raw_coords.type->As<ast::type::VectorType>()->size();
|
||||
} else if (raw_coords.type->Is<ast::type::Vector>()) {
|
||||
num_coords_supplied = raw_coords.type->As<ast::type::Vector>()->size();
|
||||
}
|
||||
if (num_coords_supplied == 0) {
|
||||
Fail() << "bad or unsupported coordinate type for image access: "
|
||||
@ -3867,7 +3866,7 @@ ast::ExpressionList FunctionEmitter::MakeCoordinateOperandsForImageAccess(
|
||||
Swizzle(num_axes));
|
||||
// Convert it to an unsigned integer type.
|
||||
result.push_back(ast_module_.create<ast::TypeConstructorExpression>(
|
||||
ast_module_.create<ast::type::U32Type>(),
|
||||
ast_module_.create<ast::type::U32>(),
|
||||
ast::ExpressionList{array_index}));
|
||||
} else {
|
||||
if (num_coords_supplied == num_coords_required) {
|
||||
|
@ -441,7 +441,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer) {
|
||||
)")) << ToString(fe.ast_body());
|
||||
}
|
||||
|
||||
TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_AliasType) {
|
||||
TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Alias) {
|
||||
auto p = parser(test::Assemble(
|
||||
std::string("OpDecorate %arr2uint ArrayStride 16\n") + Preamble() + R"(
|
||||
%ptr = OpTypePointer Function %arr2uint
|
||||
@ -508,7 +508,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Null) {
|
||||
)")) << ToString(fe.ast_body());
|
||||
}
|
||||
|
||||
TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_AliasType_Null) {
|
||||
TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Alias_Null) {
|
||||
auto p = parser(test::Assemble(
|
||||
std::string("OpDecorate %arr2uint ArrayStride 16\n") + Preamble() + R"(
|
||||
%ptr = OpTypePointer Function %arr2uint
|
||||
|
@ -196,7 +196,7 @@ ParserImpl::ParserImpl(Context* ctx, const std::vector<uint32_t>& spv_binary)
|
||||
: Reader(ctx),
|
||||
spv_binary_(spv_binary),
|
||||
fail_stream_(&success_, &errors_),
|
||||
bool_type_(ast_module_.create<ast::type::BoolType>()),
|
||||
bool_type_(ast_module_.create<ast::type::Bool>()),
|
||||
namer_(fail_stream_),
|
||||
enum_converter_(fail_stream_),
|
||||
tools_context_(kInputEnv) {
|
||||
@ -285,7 +285,7 @@ ast::type::Type* ParserImpl::ConvertType(uint32_t type_id) {
|
||||
|
||||
switch (spirv_type->kind()) {
|
||||
case spvtools::opt::analysis::Type::kVoid:
|
||||
return save(ast_module_.create<ast::type::VoidType>());
|
||||
return save(ast_module_.create<ast::type::Void>());
|
||||
case spvtools::opt::analysis::Type::kBool:
|
||||
return save(bool_type_);
|
||||
case spvtools::opt::analysis::Type::kInteger:
|
||||
@ -315,7 +315,7 @@ ast::type::Type* ParserImpl::ConvertType(uint32_t type_id) {
|
||||
case spvtools::opt::analysis::Type::kImage:
|
||||
// Fake it for sampler and texture types. These are handled in an
|
||||
// entirely different way.
|
||||
return save(ast_module_.create<ast::type::VoidType>());
|
||||
return save(ast_module_.create<ast::type::Void>());
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -648,8 +648,8 @@ bool ParserImpl::RegisterEntryPoints() {
|
||||
ast::type::Type* ParserImpl::ConvertType(
|
||||
const spvtools::opt::analysis::Integer* int_ty) {
|
||||
if (int_ty->width() == 32) {
|
||||
ast::type::Type* signed_ty = ast_module_.create<ast::type::I32Type>();
|
||||
ast::type::Type* unsigned_ty = ast_module_.create<ast::type::U32Type>();
|
||||
ast::type::Type* signed_ty = ast_module_.create<ast::type::I32>();
|
||||
ast::type::Type* unsigned_ty = ast_module_.create<ast::type::U32>();
|
||||
signed_type_for_[unsigned_ty] = signed_ty;
|
||||
unsigned_type_for_[signed_ty] = unsigned_ty;
|
||||
return int_ty->IsSigned() ? signed_ty : unsigned_ty;
|
||||
@ -661,7 +661,7 @@ ast::type::Type* ParserImpl::ConvertType(
|
||||
ast::type::Type* ParserImpl::ConvertType(
|
||||
const spvtools::opt::analysis::Float* float_ty) {
|
||||
if (float_ty->width() == 32) {
|
||||
return ast_module_.create<ast::type::F32Type>();
|
||||
return ast_module_.create<ast::type::F32>();
|
||||
}
|
||||
Fail() << "unhandled float width: " << float_ty->width();
|
||||
return nullptr;
|
||||
@ -674,16 +674,15 @@ ast::type::Type* ParserImpl::ConvertType(
|
||||
if (ast_elem_ty == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
auto* this_ty =
|
||||
ast_module_.create<ast::type::VectorType>(ast_elem_ty, num_elem);
|
||||
auto* this_ty = ast_module_.create<ast::type::Vector>(ast_elem_ty, num_elem);
|
||||
// Generate the opposite-signedness vector type, if this type is integral.
|
||||
if (unsigned_type_for_.count(ast_elem_ty)) {
|
||||
auto* other_ty = ast_module_.create<ast::type::VectorType>(
|
||||
auto* other_ty = ast_module_.create<ast::type::Vector>(
|
||||
unsigned_type_for_[ast_elem_ty], num_elem);
|
||||
signed_type_for_[other_ty] = this_ty;
|
||||
unsigned_type_for_[this_ty] = other_ty;
|
||||
} else if (signed_type_for_.count(ast_elem_ty)) {
|
||||
auto* other_ty = ast_module_.create<ast::type::VectorType>(
|
||||
auto* other_ty = ast_module_.create<ast::type::Vector>(
|
||||
signed_type_for_[ast_elem_ty], num_elem);
|
||||
unsigned_type_for_[other_ty] = this_ty;
|
||||
signed_type_for_[this_ty] = other_ty;
|
||||
@ -701,8 +700,8 @@ ast::type::Type* ParserImpl::ConvertType(
|
||||
if (ast_scalar_ty == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
return ast_module_.create<ast::type::MatrixType>(ast_scalar_ty, num_rows,
|
||||
num_columns);
|
||||
return ast_module_.create<ast::type::Matrix>(ast_scalar_ty, num_rows,
|
||||
num_columns);
|
||||
}
|
||||
|
||||
ast::type::Type* ParserImpl::ConvertType(
|
||||
@ -711,7 +710,7 @@ ast::type::Type* ParserImpl::ConvertType(
|
||||
if (ast_elem_ty == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
auto ast_type = std::make_unique<ast::type::ArrayType>(ast_elem_ty);
|
||||
auto ast_type = std::make_unique<ast::type::Array>(ast_elem_ty);
|
||||
if (!ApplyArrayDecorations(rtarr_ty, ast_type.get())) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -752,7 +751,7 @@ ast::type::Type* ParserImpl::ConvertType(
|
||||
<< num_elem;
|
||||
return nullptr;
|
||||
}
|
||||
auto ast_type = std::make_unique<ast::type::ArrayType>(
|
||||
auto ast_type = std::make_unique<ast::type::Array>(
|
||||
ast_elem_ty, static_cast<uint32_t>(num_elem));
|
||||
if (!ApplyArrayDecorations(arr_ty, ast_type.get())) {
|
||||
return nullptr;
|
||||
@ -765,7 +764,7 @@ ast::type::Type* ParserImpl::ConvertType(
|
||||
|
||||
bool ParserImpl::ApplyArrayDecorations(
|
||||
const spvtools::opt::analysis::Type* spv_type,
|
||||
ast::type::ArrayType* ast_type) {
|
||||
ast::type::Array* ast_type) {
|
||||
const auto type_id = type_mgr_->GetId(spv_type);
|
||||
for (auto& decoration : this->GetDecorationsFor(type_id)) {
|
||||
if (decoration.size() == 2 && decoration[0] == SpvDecorationArrayStride) {
|
||||
@ -886,8 +885,8 @@ ast::type::Type* ParserImpl::ConvertType(
|
||||
|
||||
namer_.SuggestSanitizedName(type_id, "S");
|
||||
|
||||
auto* result = ast_module_.create<ast::type::StructType>(
|
||||
namer_.GetName(type_id), ast_struct);
|
||||
auto* result = ast_module_.create<ast::type::Struct>(namer_.GetName(type_id),
|
||||
ast_struct);
|
||||
id_to_type_[type_id] = result;
|
||||
if (num_non_writable_members == members.size()) {
|
||||
read_only_struct_types_.insert(result);
|
||||
@ -927,8 +926,7 @@ ast::type::Type* ParserImpl::ConvertType(
|
||||
ast_storage_class = ast::StorageClass::kStorageBuffer;
|
||||
remap_buffer_block_type_.insert(type_id);
|
||||
}
|
||||
return ast_module_.create<ast::type::PointerType>(ast_elem_ty,
|
||||
ast_storage_class);
|
||||
return ast_module_.create<ast::type::Pointer>(ast_elem_ty, ast_storage_class);
|
||||
}
|
||||
|
||||
bool ParserImpl::RegisterTypes() {
|
||||
@ -975,15 +973,15 @@ bool ParserImpl::EmitScalarSpecConstants() {
|
||||
case SpvOpSpecConstant: {
|
||||
ast_type = ConvertType(inst.type_id());
|
||||
const uint32_t literal_value = inst.GetSingleWordInOperand(0);
|
||||
if (ast_type->Is<ast::type::I32Type>()) {
|
||||
if (ast_type->Is<ast::type::I32>()) {
|
||||
ast_expr =
|
||||
create<ast::ScalarConstructorExpression>(create<ast::SintLiteral>(
|
||||
ast_type, static_cast<int32_t>(literal_value)));
|
||||
} else if (ast_type->Is<ast::type::U32Type>()) {
|
||||
} else if (ast_type->Is<ast::type::U32>()) {
|
||||
ast_expr =
|
||||
create<ast::ScalarConstructorExpression>(create<ast::UintLiteral>(
|
||||
ast_type, static_cast<uint32_t>(literal_value)));
|
||||
} else if (ast_type->Is<ast::type::F32Type>()) {
|
||||
} else if (ast_type->Is<ast::type::F32>()) {
|
||||
float float_value;
|
||||
// Copy the bits so we can read them as a float.
|
||||
std::memcpy(&float_value, &literal_value, sizeof(float_value));
|
||||
@ -1058,7 +1056,7 @@ void ParserImpl::MaybeGenerateAlias(uint32_t type_id,
|
||||
}
|
||||
const auto name = namer_.GetName(type_id);
|
||||
auto* ast_alias_type =
|
||||
ast_module_.create<ast::type::AliasType>(name, ast_underlying_type);
|
||||
ast_module_.create<ast::type::Alias>(name, ast_underlying_type);
|
||||
// Record this new alias as the AST type for this SPIR-V ID.
|
||||
id_to_type_[type_id] = ast_alias_type;
|
||||
ast_module_.AddConstructedType(ast_alias_type);
|
||||
@ -1116,15 +1114,15 @@ bool ParserImpl::EmitModuleScopeVariables() {
|
||||
"SPIR-V type with ID: "
|
||||
<< var.type_id();
|
||||
}
|
||||
if (!ast_type->Is<ast::type::PointerType>()) {
|
||||
if (!ast_type->Is<ast::type::Pointer>()) {
|
||||
return Fail() << "variable with ID " << var.result_id()
|
||||
<< " has non-pointer type " << var.type_id();
|
||||
}
|
||||
}
|
||||
|
||||
auto* ast_store_type = ast_type->As<ast::type::PointerType>()->type();
|
||||
auto* ast_store_type = ast_type->As<ast::type::Pointer>()->type();
|
||||
auto ast_storage_class =
|
||||
ast_type->As<ast::type::PointerType>()->storage_class();
|
||||
ast_type->As<ast::type::Pointer>()->storage_class();
|
||||
auto* ast_var =
|
||||
MakeVariable(var.result_id(), ast_storage_class, ast_store_type);
|
||||
if (var.NumInOperands() > 1) {
|
||||
@ -1170,7 +1168,7 @@ ast::Variable* ParserImpl::MakeVariable(uint32_t id,
|
||||
auto access = read_only_struct_types_.count(type)
|
||||
? ast::AccessControl::kReadOnly
|
||||
: ast::AccessControl::kReadWrite;
|
||||
type = ast_module_.create<ast::type::AccessControlType>(access, type);
|
||||
type = ast_module_.create<ast::type::AccessControl>(access, type);
|
||||
}
|
||||
|
||||
auto* ast_var = create<ast::Variable>(namer_.Name(id), sc, type);
|
||||
@ -1263,22 +1261,22 @@ TypedExpression ParserImpl::MakeConstantExpression(uint32_t id) {
|
||||
// So canonicalization should map that way too.
|
||||
// Currently "null<type>" is missing from the WGSL parser.
|
||||
// See https://bugs.chromium.org/p/tint/issues/detail?id=34
|
||||
if (ast_type->Is<ast::type::U32Type>()) {
|
||||
if (ast_type->Is<ast::type::U32>()) {
|
||||
return {ast_type,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::UintLiteral>(ast_type, spirv_const->GetU32()))};
|
||||
}
|
||||
if (ast_type->Is<ast::type::I32Type>()) {
|
||||
if (ast_type->Is<ast::type::I32>()) {
|
||||
return {ast_type,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(ast_type, spirv_const->GetS32()))};
|
||||
}
|
||||
if (ast_type->Is<ast::type::F32Type>()) {
|
||||
if (ast_type->Is<ast::type::F32>()) {
|
||||
return {ast_type,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(ast_type, spirv_const->GetFloat()))};
|
||||
}
|
||||
if (ast_type->Is<ast::type::BoolType>()) {
|
||||
if (ast_type->Is<ast::type::Bool>()) {
|
||||
const bool value = spirv_const->AsNullConstant()
|
||||
? false
|
||||
: spirv_const->AsBoolConstant()->value();
|
||||
@ -1335,24 +1333,24 @@ ast::Expression* ParserImpl::MakeNullValue(ast::type::Type* type) {
|
||||
auto* original_type = type;
|
||||
type = type->UnwrapIfNeeded();
|
||||
|
||||
if (type->Is<ast::type::BoolType>()) {
|
||||
if (type->Is<ast::type::Bool>()) {
|
||||
return create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(type, false));
|
||||
}
|
||||
if (type->Is<ast::type::U32Type>()) {
|
||||
if (type->Is<ast::type::U32>()) {
|
||||
return create<ast::ScalarConstructorExpression>(
|
||||
create<ast::UintLiteral>(type, 0u));
|
||||
}
|
||||
if (type->Is<ast::type::I32Type>()) {
|
||||
if (type->Is<ast::type::I32>()) {
|
||||
return create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(type, 0));
|
||||
}
|
||||
if (type->Is<ast::type::F32Type>()) {
|
||||
if (type->Is<ast::type::F32>()) {
|
||||
return create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(type, 0.0f));
|
||||
}
|
||||
if (type->Is<ast::type::VectorType>()) {
|
||||
const auto* vec_ty = type->As<ast::type::VectorType>();
|
||||
if (type->Is<ast::type::Vector>()) {
|
||||
const auto* vec_ty = type->As<ast::type::Vector>();
|
||||
ast::ExpressionList ast_components;
|
||||
for (size_t i = 0; i < vec_ty->size(); ++i) {
|
||||
ast_components.emplace_back(MakeNullValue(vec_ty->type()));
|
||||
@ -1360,11 +1358,11 @@ ast::Expression* ParserImpl::MakeNullValue(ast::type::Type* type) {
|
||||
return create<ast::TypeConstructorExpression>(type,
|
||||
std::move(ast_components));
|
||||
}
|
||||
if (type->Is<ast::type::MatrixType>()) {
|
||||
const auto* mat_ty = type->As<ast::type::MatrixType>();
|
||||
if (type->Is<ast::type::Matrix>()) {
|
||||
const auto* mat_ty = type->As<ast::type::Matrix>();
|
||||
// Matrix components are columns
|
||||
auto* column_ty = ast_module_.create<ast::type::VectorType>(mat_ty->type(),
|
||||
mat_ty->rows());
|
||||
auto* column_ty =
|
||||
ast_module_.create<ast::type::Vector>(mat_ty->type(), mat_ty->rows());
|
||||
ast::ExpressionList ast_components;
|
||||
for (size_t i = 0; i < mat_ty->columns(); ++i) {
|
||||
ast_components.emplace_back(MakeNullValue(column_ty));
|
||||
@ -1372,8 +1370,8 @@ ast::Expression* ParserImpl::MakeNullValue(ast::type::Type* type) {
|
||||
return create<ast::TypeConstructorExpression>(type,
|
||||
std::move(ast_components));
|
||||
}
|
||||
if (type->Is<ast::type::ArrayType>()) {
|
||||
auto* arr_ty = type->As<ast::type::ArrayType>();
|
||||
if (type->Is<ast::type::Array>()) {
|
||||
auto* arr_ty = type->As<ast::type::Array>();
|
||||
ast::ExpressionList ast_components;
|
||||
for (size_t i = 0; i < arr_ty->size(); ++i) {
|
||||
ast_components.emplace_back(MakeNullValue(arr_ty->type()));
|
||||
@ -1381,8 +1379,8 @@ ast::Expression* ParserImpl::MakeNullValue(ast::type::Type* type) {
|
||||
return create<ast::TypeConstructorExpression>(original_type,
|
||||
std::move(ast_components));
|
||||
}
|
||||
if (type->Is<ast::type::StructType>()) {
|
||||
auto* struct_ty = type->As<ast::type::StructType>();
|
||||
if (type->Is<ast::type::Struct>()) {
|
||||
auto* struct_ty = type->As<ast::type::Struct>();
|
||||
ast::ExpressionList ast_components;
|
||||
for (auto* member : struct_ty->impl()->members()) {
|
||||
ast_components.emplace_back(MakeNullValue(member->type()));
|
||||
@ -1445,14 +1443,14 @@ ast::type::Type* ParserImpl::GetSignedIntMatchingShape(ast::type::Type* other) {
|
||||
if (other == nullptr) {
|
||||
Fail() << "no type provided";
|
||||
}
|
||||
auto* i32 = ast_module_.create<ast::type::I32Type>();
|
||||
if (other->Is<ast::type::F32Type>() || other->Is<ast::type::U32Type>() ||
|
||||
other->Is<ast::type::I32Type>()) {
|
||||
auto* i32 = ast_module_.create<ast::type::I32>();
|
||||
if (other->Is<ast::type::F32>() || other->Is<ast::type::U32>() ||
|
||||
other->Is<ast::type::I32>()) {
|
||||
return i32;
|
||||
}
|
||||
auto* vec_ty = other->As<ast::type::VectorType>();
|
||||
auto* vec_ty = other->As<ast::type::Vector>();
|
||||
if (vec_ty) {
|
||||
return ast_module_.create<ast::type::VectorType>(i32, vec_ty->size());
|
||||
return ast_module_.create<ast::type::Vector>(i32, vec_ty->size());
|
||||
}
|
||||
Fail() << "required numeric scalar or vector, but got " << other->type_name();
|
||||
return nullptr;
|
||||
@ -1464,14 +1462,14 @@ ast::type::Type* ParserImpl::GetUnsignedIntMatchingShape(
|
||||
Fail() << "no type provided";
|
||||
return nullptr;
|
||||
}
|
||||
auto* u32 = ast_module_.create<ast::type::U32Type>();
|
||||
if (other->Is<ast::type::F32Type>() || other->Is<ast::type::U32Type>() ||
|
||||
other->Is<ast::type::I32Type>()) {
|
||||
auto* u32 = ast_module_.create<ast::type::U32>();
|
||||
if (other->Is<ast::type::F32>() || other->Is<ast::type::U32>() ||
|
||||
other->Is<ast::type::I32>()) {
|
||||
return u32;
|
||||
}
|
||||
auto* vec_ty = other->As<ast::type::VectorType>();
|
||||
auto* vec_ty = other->As<ast::type::Vector>();
|
||||
if (vec_ty) {
|
||||
return ast_module_.create<ast::type::VectorType>(u32, vec_ty->size());
|
||||
return ast_module_.create<ast::type::Vector>(u32, vec_ty->size());
|
||||
}
|
||||
Fail() << "required numeric scalar or vector, but got " << other->type_name();
|
||||
return nullptr;
|
||||
@ -1603,7 +1601,7 @@ ParserImpl::GetMemoryObjectDeclarationForHandle(uint32_t id,
|
||||
}
|
||||
}
|
||||
|
||||
ast::type::PointerType* ParserImpl::GetTypeForHandleVar(
|
||||
ast::type::Pointer* ParserImpl::GetTypeForHandleVar(
|
||||
const spvtools::opt::Instruction& var) {
|
||||
if (!success()) {
|
||||
return nullptr;
|
||||
@ -1726,7 +1724,7 @@ ast::type::PointerType* ParserImpl::GetTypeForHandleVar(
|
||||
// Construct the Tint handle type.
|
||||
ast::type::Type* ast_store_type = nullptr;
|
||||
if (usage.IsSampler()) {
|
||||
ast_store_type = ast_module_.create<ast::type::SamplerType>(
|
||||
ast_store_type = ast_module_.create<ast::type::Sampler>(
|
||||
usage.IsComparisonSampler() ? ast::type::SamplerKind::kComparisonSampler
|
||||
: ast::type::SamplerKind::kSampler);
|
||||
} else if (usage.IsTexture()) {
|
||||
@ -1757,13 +1755,13 @@ ast::type::PointerType* ParserImpl::GetTypeForHandleVar(
|
||||
// OpImage variable with an OpImage*Dref* instruction. In WGSL we must
|
||||
// treat that as a depth texture.
|
||||
if (image_type->depth() || usage.IsDepthTexture()) {
|
||||
ast_store_type = ast_module_.create<ast::type::DepthTextureType>(dim);
|
||||
ast_store_type = ast_module_.create<ast::type::DepthTexture>(dim);
|
||||
} else if (image_type->is_multisampled()) {
|
||||
// Multisampled textures are never depth textures.
|
||||
ast_store_type = ast_module_.create<ast::type::MultisampledTextureType>(
|
||||
ast_store_type = ast_module_.create<ast::type::MultisampledTexture>(
|
||||
dim, ast_sampled_component_type);
|
||||
} else {
|
||||
ast_store_type = ast_module_.create<ast::type::SampledTextureType>(
|
||||
ast_store_type = ast_module_.create<ast::type::SampledTexture>(
|
||||
dim, ast_sampled_component_type);
|
||||
}
|
||||
} else {
|
||||
@ -1774,8 +1772,8 @@ ast::type::PointerType* ParserImpl::GetTypeForHandleVar(
|
||||
if (format == ast::type::ImageFormat::kNone) {
|
||||
return nullptr;
|
||||
}
|
||||
ast_store_type = ast_module_.create<ast::type::StorageTextureType>(
|
||||
dim, access, format);
|
||||
ast_store_type =
|
||||
ast_module_.create<ast::type::StorageTexture>(dim, access, format);
|
||||
}
|
||||
} else {
|
||||
Fail() << "unsupported: UniformConstant variable is not a recognized "
|
||||
@ -1785,7 +1783,7 @@ ast::type::PointerType* ParserImpl::GetTypeForHandleVar(
|
||||
}
|
||||
|
||||
// Form the pointer type.
|
||||
auto* result = ast_module_.create<ast::type::PointerType>(
|
||||
auto* result = ast_module_.create<ast::type::Pointer>(
|
||||
ast_store_type, ast::StorageClass::kUniformConstant);
|
||||
// Remember it for later.
|
||||
handle_type_[&var] = result;
|
||||
|
@ -357,7 +357,7 @@ class ParserImpl : Reader {
|
||||
ast::type::Type* first_operand_type);
|
||||
|
||||
/// @returns the registered boolean type.
|
||||
ast::type::Type* BoolType() const { return bool_type_; }
|
||||
ast::type::Type* Bool() const { return bool_type_; }
|
||||
|
||||
/// Bookkeeping used for tracking the "position" builtin variable.
|
||||
struct BuiltInPositionInfo {
|
||||
@ -433,7 +433,7 @@ class ParserImpl : Reader {
|
||||
/// @param var the OpVariable instruction
|
||||
/// @returns the Tint AST type for the poiner-to-{sampler|texture} or null on
|
||||
/// error
|
||||
ast::type::PointerType* GetTypeForHandleVar(
|
||||
ast::type::Pointer* GetTypeForHandleVar(
|
||||
const spvtools::opt::Instruction& var);
|
||||
|
||||
/// Returns the SPIR-V instruction with the given ID, or nullptr.
|
||||
@ -484,7 +484,7 @@ class ParserImpl : Reader {
|
||||
/// @param ast_type non-null; the AST type to apply decorations to
|
||||
/// @returns true on success.
|
||||
bool ApplyArrayDecorations(const spvtools::opt::analysis::Type* spv_type,
|
||||
ast::type::ArrayType* ast_type);
|
||||
ast::type::Array* ast_type);
|
||||
|
||||
/// Creates a new `ast::Node` owned by the Module. When the Module is
|
||||
/// destructed, the `ast::Node` will also be destructed.
|
||||
@ -592,7 +592,7 @@ class ParserImpl : Reader {
|
||||
// usages implied by usages of the memory-object-declaration.
|
||||
std::unordered_map<const spvtools::opt::Instruction*, Usage> handle_usage_;
|
||||
// The inferred pointer type for the given handle variable.
|
||||
std::unordered_map<const spvtools::opt::Instruction*, ast::type::PointerType*>
|
||||
std::unordered_map<const spvtools::opt::Instruction*, ast::type::Pointer*>
|
||||
handle_type_;
|
||||
};
|
||||
|
||||
|
@ -92,7 +92,7 @@ TEST_F(SpvParserTest, ConvertType_Void) {
|
||||
EXPECT_TRUE(p->BuildInternalModule());
|
||||
|
||||
auto* type = p->ConvertType(1);
|
||||
EXPECT_TRUE(type->Is<ast::type::VoidType>());
|
||||
EXPECT_TRUE(type->Is<ast::type::Void>());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
}
|
||||
|
||||
@ -101,7 +101,7 @@ TEST_F(SpvParserTest, ConvertType_Bool) {
|
||||
EXPECT_TRUE(p->BuildInternalModule());
|
||||
|
||||
auto* type = p->ConvertType(100);
|
||||
EXPECT_TRUE(type->Is<ast::type::BoolType>());
|
||||
EXPECT_TRUE(type->Is<ast::type::Bool>());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
}
|
||||
|
||||
@ -110,7 +110,7 @@ TEST_F(SpvParserTest, ConvertType_I32) {
|
||||
EXPECT_TRUE(p->BuildInternalModule());
|
||||
|
||||
auto* type = p->ConvertType(2);
|
||||
EXPECT_TRUE(type->Is<ast::type::I32Type>());
|
||||
EXPECT_TRUE(type->Is<ast::type::I32>());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
}
|
||||
|
||||
@ -119,7 +119,7 @@ TEST_F(SpvParserTest, ConvertType_U32) {
|
||||
EXPECT_TRUE(p->BuildInternalModule());
|
||||
|
||||
auto* type = p->ConvertType(3);
|
||||
EXPECT_TRUE(type->Is<ast::type::U32Type>());
|
||||
EXPECT_TRUE(type->Is<ast::type::U32>());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
}
|
||||
|
||||
@ -128,7 +128,7 @@ TEST_F(SpvParserTest, ConvertType_F32) {
|
||||
EXPECT_TRUE(p->BuildInternalModule());
|
||||
|
||||
auto* type = p->ConvertType(4);
|
||||
EXPECT_TRUE(type->Is<ast::type::F32Type>());
|
||||
EXPECT_TRUE(type->Is<ast::type::F32>());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
}
|
||||
|
||||
@ -172,22 +172,19 @@ TEST_F(SpvParserTest, ConvertType_VecOverF32) {
|
||||
EXPECT_TRUE(p->BuildInternalModule());
|
||||
|
||||
auto* v2xf32 = p->ConvertType(20);
|
||||
EXPECT_TRUE(v2xf32->Is<ast::type::VectorType>());
|
||||
EXPECT_TRUE(
|
||||
v2xf32->As<ast::type::VectorType>()->type()->Is<ast::type::F32Type>());
|
||||
EXPECT_EQ(v2xf32->As<ast::type::VectorType>()->size(), 2u);
|
||||
EXPECT_TRUE(v2xf32->Is<ast::type::Vector>());
|
||||
EXPECT_TRUE(v2xf32->As<ast::type::Vector>()->type()->Is<ast::type::F32>());
|
||||
EXPECT_EQ(v2xf32->As<ast::type::Vector>()->size(), 2u);
|
||||
|
||||
auto* v3xf32 = p->ConvertType(30);
|
||||
EXPECT_TRUE(v3xf32->Is<ast::type::VectorType>());
|
||||
EXPECT_TRUE(
|
||||
v3xf32->As<ast::type::VectorType>()->type()->Is<ast::type::F32Type>());
|
||||
EXPECT_EQ(v3xf32->As<ast::type::VectorType>()->size(), 3u);
|
||||
EXPECT_TRUE(v3xf32->Is<ast::type::Vector>());
|
||||
EXPECT_TRUE(v3xf32->As<ast::type::Vector>()->type()->Is<ast::type::F32>());
|
||||
EXPECT_EQ(v3xf32->As<ast::type::Vector>()->size(), 3u);
|
||||
|
||||
auto* v4xf32 = p->ConvertType(40);
|
||||
EXPECT_TRUE(v4xf32->Is<ast::type::VectorType>());
|
||||
EXPECT_TRUE(
|
||||
v4xf32->As<ast::type::VectorType>()->type()->Is<ast::type::F32Type>());
|
||||
EXPECT_EQ(v4xf32->As<ast::type::VectorType>()->size(), 4u);
|
||||
EXPECT_TRUE(v4xf32->Is<ast::type::Vector>());
|
||||
EXPECT_TRUE(v4xf32->As<ast::type::Vector>()->type()->Is<ast::type::F32>());
|
||||
EXPECT_EQ(v4xf32->As<ast::type::Vector>()->size(), 4u);
|
||||
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
}
|
||||
@ -202,22 +199,19 @@ TEST_F(SpvParserTest, ConvertType_VecOverI32) {
|
||||
EXPECT_TRUE(p->BuildInternalModule());
|
||||
|
||||
auto* v2xi32 = p->ConvertType(20);
|
||||
EXPECT_TRUE(v2xi32->Is<ast::type::VectorType>());
|
||||
EXPECT_TRUE(
|
||||
v2xi32->As<ast::type::VectorType>()->type()->Is<ast::type::I32Type>());
|
||||
EXPECT_EQ(v2xi32->As<ast::type::VectorType>()->size(), 2u);
|
||||
EXPECT_TRUE(v2xi32->Is<ast::type::Vector>());
|
||||
EXPECT_TRUE(v2xi32->As<ast::type::Vector>()->type()->Is<ast::type::I32>());
|
||||
EXPECT_EQ(v2xi32->As<ast::type::Vector>()->size(), 2u);
|
||||
|
||||
auto* v3xi32 = p->ConvertType(30);
|
||||
EXPECT_TRUE(v3xi32->Is<ast::type::VectorType>());
|
||||
EXPECT_TRUE(
|
||||
v3xi32->As<ast::type::VectorType>()->type()->Is<ast::type::I32Type>());
|
||||
EXPECT_EQ(v3xi32->As<ast::type::VectorType>()->size(), 3u);
|
||||
EXPECT_TRUE(v3xi32->Is<ast::type::Vector>());
|
||||
EXPECT_TRUE(v3xi32->As<ast::type::Vector>()->type()->Is<ast::type::I32>());
|
||||
EXPECT_EQ(v3xi32->As<ast::type::Vector>()->size(), 3u);
|
||||
|
||||
auto* v4xi32 = p->ConvertType(40);
|
||||
EXPECT_TRUE(v4xi32->Is<ast::type::VectorType>());
|
||||
EXPECT_TRUE(
|
||||
v4xi32->As<ast::type::VectorType>()->type()->Is<ast::type::I32Type>());
|
||||
EXPECT_EQ(v4xi32->As<ast::type::VectorType>()->size(), 4u);
|
||||
EXPECT_TRUE(v4xi32->Is<ast::type::Vector>());
|
||||
EXPECT_TRUE(v4xi32->As<ast::type::Vector>()->type()->Is<ast::type::I32>());
|
||||
EXPECT_EQ(v4xi32->As<ast::type::Vector>()->size(), 4u);
|
||||
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
}
|
||||
@ -232,22 +226,19 @@ TEST_F(SpvParserTest, ConvertType_VecOverU32) {
|
||||
EXPECT_TRUE(p->BuildInternalModule());
|
||||
|
||||
auto* v2xu32 = p->ConvertType(20);
|
||||
EXPECT_TRUE(v2xu32->Is<ast::type::VectorType>());
|
||||
EXPECT_TRUE(
|
||||
v2xu32->As<ast::type::VectorType>()->type()->Is<ast::type::U32Type>());
|
||||
EXPECT_EQ(v2xu32->As<ast::type::VectorType>()->size(), 2u);
|
||||
EXPECT_TRUE(v2xu32->Is<ast::type::Vector>());
|
||||
EXPECT_TRUE(v2xu32->As<ast::type::Vector>()->type()->Is<ast::type::U32>());
|
||||
EXPECT_EQ(v2xu32->As<ast::type::Vector>()->size(), 2u);
|
||||
|
||||
auto* v3xu32 = p->ConvertType(30);
|
||||
EXPECT_TRUE(v3xu32->Is<ast::type::VectorType>());
|
||||
EXPECT_TRUE(
|
||||
v3xu32->As<ast::type::VectorType>()->type()->Is<ast::type::U32Type>());
|
||||
EXPECT_EQ(v3xu32->As<ast::type::VectorType>()->size(), 3u);
|
||||
EXPECT_TRUE(v3xu32->Is<ast::type::Vector>());
|
||||
EXPECT_TRUE(v3xu32->As<ast::type::Vector>()->type()->Is<ast::type::U32>());
|
||||
EXPECT_EQ(v3xu32->As<ast::type::Vector>()->size(), 3u);
|
||||
|
||||
auto* v4xu32 = p->ConvertType(40);
|
||||
EXPECT_TRUE(v4xu32->Is<ast::type::VectorType>());
|
||||
EXPECT_TRUE(
|
||||
v4xu32->As<ast::type::VectorType>()->type()->Is<ast::type::U32Type>());
|
||||
EXPECT_EQ(v4xu32->As<ast::type::VectorType>()->size(), 4u);
|
||||
EXPECT_TRUE(v4xu32->Is<ast::type::Vector>());
|
||||
EXPECT_TRUE(v4xu32->As<ast::type::Vector>()->type()->Is<ast::type::U32>());
|
||||
EXPECT_EQ(v4xu32->As<ast::type::Vector>()->size(), 4u);
|
||||
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
}
|
||||
@ -287,67 +278,58 @@ TEST_F(SpvParserTest, ConvertType_MatrixOverF32) {
|
||||
EXPECT_TRUE(p->BuildInternalModule());
|
||||
|
||||
auto* m22 = p->ConvertType(22);
|
||||
EXPECT_TRUE(m22->Is<ast::type::MatrixType>());
|
||||
EXPECT_TRUE(
|
||||
m22->As<ast::type::MatrixType>()->type()->Is<ast::type::F32Type>());
|
||||
EXPECT_EQ(m22->As<ast::type::MatrixType>()->rows(), 2u);
|
||||
EXPECT_EQ(m22->As<ast::type::MatrixType>()->columns(), 2u);
|
||||
EXPECT_TRUE(m22->Is<ast::type::Matrix>());
|
||||
EXPECT_TRUE(m22->As<ast::type::Matrix>()->type()->Is<ast::type::F32>());
|
||||
EXPECT_EQ(m22->As<ast::type::Matrix>()->rows(), 2u);
|
||||
EXPECT_EQ(m22->As<ast::type::Matrix>()->columns(), 2u);
|
||||
|
||||
auto* m23 = p->ConvertType(23);
|
||||
EXPECT_TRUE(m23->Is<ast::type::MatrixType>());
|
||||
EXPECT_TRUE(
|
||||
m23->As<ast::type::MatrixType>()->type()->Is<ast::type::F32Type>());
|
||||
EXPECT_EQ(m23->As<ast::type::MatrixType>()->rows(), 2u);
|
||||
EXPECT_EQ(m23->As<ast::type::MatrixType>()->columns(), 3u);
|
||||
EXPECT_TRUE(m23->Is<ast::type::Matrix>());
|
||||
EXPECT_TRUE(m23->As<ast::type::Matrix>()->type()->Is<ast::type::F32>());
|
||||
EXPECT_EQ(m23->As<ast::type::Matrix>()->rows(), 2u);
|
||||
EXPECT_EQ(m23->As<ast::type::Matrix>()->columns(), 3u);
|
||||
|
||||
auto* m24 = p->ConvertType(24);
|
||||
EXPECT_TRUE(m24->Is<ast::type::MatrixType>());
|
||||
EXPECT_TRUE(
|
||||
m24->As<ast::type::MatrixType>()->type()->Is<ast::type::F32Type>());
|
||||
EXPECT_EQ(m24->As<ast::type::MatrixType>()->rows(), 2u);
|
||||
EXPECT_EQ(m24->As<ast::type::MatrixType>()->columns(), 4u);
|
||||
EXPECT_TRUE(m24->Is<ast::type::Matrix>());
|
||||
EXPECT_TRUE(m24->As<ast::type::Matrix>()->type()->Is<ast::type::F32>());
|
||||
EXPECT_EQ(m24->As<ast::type::Matrix>()->rows(), 2u);
|
||||
EXPECT_EQ(m24->As<ast::type::Matrix>()->columns(), 4u);
|
||||
|
||||
auto* m32 = p->ConvertType(32);
|
||||
EXPECT_TRUE(m32->Is<ast::type::MatrixType>());
|
||||
EXPECT_TRUE(
|
||||
m32->As<ast::type::MatrixType>()->type()->Is<ast::type::F32Type>());
|
||||
EXPECT_EQ(m32->As<ast::type::MatrixType>()->rows(), 3u);
|
||||
EXPECT_EQ(m32->As<ast::type::MatrixType>()->columns(), 2u);
|
||||
EXPECT_TRUE(m32->Is<ast::type::Matrix>());
|
||||
EXPECT_TRUE(m32->As<ast::type::Matrix>()->type()->Is<ast::type::F32>());
|
||||
EXPECT_EQ(m32->As<ast::type::Matrix>()->rows(), 3u);
|
||||
EXPECT_EQ(m32->As<ast::type::Matrix>()->columns(), 2u);
|
||||
|
||||
auto* m33 = p->ConvertType(33);
|
||||
EXPECT_TRUE(m33->Is<ast::type::MatrixType>());
|
||||
EXPECT_TRUE(
|
||||
m33->As<ast::type::MatrixType>()->type()->Is<ast::type::F32Type>());
|
||||
EXPECT_EQ(m33->As<ast::type::MatrixType>()->rows(), 3u);
|
||||
EXPECT_EQ(m33->As<ast::type::MatrixType>()->columns(), 3u);
|
||||
EXPECT_TRUE(m33->Is<ast::type::Matrix>());
|
||||
EXPECT_TRUE(m33->As<ast::type::Matrix>()->type()->Is<ast::type::F32>());
|
||||
EXPECT_EQ(m33->As<ast::type::Matrix>()->rows(), 3u);
|
||||
EXPECT_EQ(m33->As<ast::type::Matrix>()->columns(), 3u);
|
||||
|
||||
auto* m34 = p->ConvertType(34);
|
||||
EXPECT_TRUE(m34->Is<ast::type::MatrixType>());
|
||||
EXPECT_TRUE(
|
||||
m34->As<ast::type::MatrixType>()->type()->Is<ast::type::F32Type>());
|
||||
EXPECT_EQ(m34->As<ast::type::MatrixType>()->rows(), 3u);
|
||||
EXPECT_EQ(m34->As<ast::type::MatrixType>()->columns(), 4u);
|
||||
EXPECT_TRUE(m34->Is<ast::type::Matrix>());
|
||||
EXPECT_TRUE(m34->As<ast::type::Matrix>()->type()->Is<ast::type::F32>());
|
||||
EXPECT_EQ(m34->As<ast::type::Matrix>()->rows(), 3u);
|
||||
EXPECT_EQ(m34->As<ast::type::Matrix>()->columns(), 4u);
|
||||
|
||||
auto* m42 = p->ConvertType(42);
|
||||
EXPECT_TRUE(m42->Is<ast::type::MatrixType>());
|
||||
EXPECT_TRUE(
|
||||
m42->As<ast::type::MatrixType>()->type()->Is<ast::type::F32Type>());
|
||||
EXPECT_EQ(m42->As<ast::type::MatrixType>()->rows(), 4u);
|
||||
EXPECT_EQ(m42->As<ast::type::MatrixType>()->columns(), 2u);
|
||||
EXPECT_TRUE(m42->Is<ast::type::Matrix>());
|
||||
EXPECT_TRUE(m42->As<ast::type::Matrix>()->type()->Is<ast::type::F32>());
|
||||
EXPECT_EQ(m42->As<ast::type::Matrix>()->rows(), 4u);
|
||||
EXPECT_EQ(m42->As<ast::type::Matrix>()->columns(), 2u);
|
||||
|
||||
auto* m43 = p->ConvertType(43);
|
||||
EXPECT_TRUE(m43->Is<ast::type::MatrixType>());
|
||||
EXPECT_TRUE(
|
||||
m43->As<ast::type::MatrixType>()->type()->Is<ast::type::F32Type>());
|
||||
EXPECT_EQ(m43->As<ast::type::MatrixType>()->rows(), 4u);
|
||||
EXPECT_EQ(m43->As<ast::type::MatrixType>()->columns(), 3u);
|
||||
EXPECT_TRUE(m43->Is<ast::type::Matrix>());
|
||||
EXPECT_TRUE(m43->As<ast::type::Matrix>()->type()->Is<ast::type::F32>());
|
||||
EXPECT_EQ(m43->As<ast::type::Matrix>()->rows(), 4u);
|
||||
EXPECT_EQ(m43->As<ast::type::Matrix>()->columns(), 3u);
|
||||
|
||||
auto* m44 = p->ConvertType(44);
|
||||
EXPECT_TRUE(m44->Is<ast::type::MatrixType>());
|
||||
EXPECT_TRUE(
|
||||
m44->As<ast::type::MatrixType>()->type()->Is<ast::type::F32Type>());
|
||||
EXPECT_EQ(m44->As<ast::type::MatrixType>()->rows(), 4u);
|
||||
EXPECT_EQ(m44->As<ast::type::MatrixType>()->columns(), 4u);
|
||||
EXPECT_TRUE(m44->Is<ast::type::Matrix>());
|
||||
EXPECT_TRUE(m44->As<ast::type::Matrix>()->type()->Is<ast::type::F32>());
|
||||
EXPECT_EQ(m44->As<ast::type::Matrix>()->rows(), 4u);
|
||||
EXPECT_EQ(m44->As<ast::type::Matrix>()->columns(), 4u);
|
||||
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
}
|
||||
@ -361,8 +343,8 @@ TEST_F(SpvParserTest, ConvertType_RuntimeArray) {
|
||||
|
||||
auto* type = p->ConvertType(10);
|
||||
ASSERT_NE(type, nullptr);
|
||||
EXPECT_TRUE(type->Is<ast::type::ArrayType>());
|
||||
auto* arr_type = type->As<ast::type::ArrayType>();
|
||||
EXPECT_TRUE(type->Is<ast::type::Array>());
|
||||
auto* arr_type = type->As<ast::type::Array>();
|
||||
EXPECT_TRUE(arr_type->IsRuntimeArray());
|
||||
ASSERT_NE(arr_type, nullptr);
|
||||
EXPECT_EQ(arr_type->size(), 0u);
|
||||
@ -370,7 +352,7 @@ TEST_F(SpvParserTest, ConvertType_RuntimeArray) {
|
||||
EXPECT_FALSE(arr_type->has_array_stride());
|
||||
auto* elem_type = arr_type->type();
|
||||
ASSERT_NE(elem_type, nullptr);
|
||||
EXPECT_TRUE(elem_type->Is<ast::type::U32Type>());
|
||||
EXPECT_TRUE(elem_type->Is<ast::type::U32>());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
}
|
||||
|
||||
@ -397,7 +379,7 @@ TEST_F(SpvParserTest, ConvertType_RuntimeArray_ArrayStride_Valid) {
|
||||
EXPECT_TRUE(p->BuildInternalModule());
|
||||
auto* type = p->ConvertType(10);
|
||||
ASSERT_NE(type, nullptr);
|
||||
auto* arr_type = type->As<ast::type::ArrayType>();
|
||||
auto* arr_type = type->As<ast::type::Array>();
|
||||
EXPECT_TRUE(arr_type->IsRuntimeArray());
|
||||
ASSERT_NE(arr_type, nullptr);
|
||||
EXPECT_EQ(arr_type->array_stride(), 64u);
|
||||
@ -443,8 +425,8 @@ TEST_F(SpvParserTest, ConvertType_Array) {
|
||||
|
||||
auto* type = p->ConvertType(10);
|
||||
ASSERT_NE(type, nullptr);
|
||||
EXPECT_TRUE(type->Is<ast::type::ArrayType>());
|
||||
auto* arr_type = type->As<ast::type::ArrayType>();
|
||||
EXPECT_TRUE(type->Is<ast::type::Array>());
|
||||
auto* arr_type = type->As<ast::type::Array>();
|
||||
EXPECT_FALSE(arr_type->IsRuntimeArray());
|
||||
ASSERT_NE(arr_type, nullptr);
|
||||
EXPECT_EQ(arr_type->size(), 42u);
|
||||
@ -452,7 +434,7 @@ TEST_F(SpvParserTest, ConvertType_Array) {
|
||||
EXPECT_FALSE(arr_type->has_array_stride());
|
||||
auto* elem_type = arr_type->type();
|
||||
ASSERT_NE(elem_type, nullptr);
|
||||
EXPECT_TRUE(elem_type->Is<ast::type::U32Type>());
|
||||
EXPECT_TRUE(elem_type->Is<ast::type::U32>());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
}
|
||||
|
||||
@ -531,8 +513,8 @@ TEST_F(SpvParserTest, ConvertType_ArrayStride_Valid) {
|
||||
|
||||
auto* type = p->ConvertType(10);
|
||||
ASSERT_NE(type, nullptr);
|
||||
EXPECT_TRUE(type->Is<ast::type::ArrayType>());
|
||||
auto* arr_type = type->As<ast::type::ArrayType>();
|
||||
EXPECT_TRUE(type->Is<ast::type::Array>());
|
||||
auto* arr_type = type->As<ast::type::Array>();
|
||||
ASSERT_NE(arr_type, nullptr);
|
||||
ASSERT_EQ(arr_type->array_stride(), 8u);
|
||||
EXPECT_TRUE(arr_type->has_array_stride());
|
||||
@ -581,9 +563,9 @@ TEST_F(SpvParserTest, ConvertType_StructTwoMembers) {
|
||||
|
||||
auto* type = p->ConvertType(10);
|
||||
ASSERT_NE(type, nullptr);
|
||||
EXPECT_TRUE(type->Is<ast::type::StructType>());
|
||||
EXPECT_TRUE(type->Is<ast::type::Struct>());
|
||||
std::stringstream ss;
|
||||
type->As<ast::type::StructType>()->impl()->to_str(ss, 0);
|
||||
type->As<ast::type::Struct>()->impl()->to_str(ss, 0);
|
||||
EXPECT_THAT(ss.str(), Eq(R"(Struct{
|
||||
StructMember{field0: __u32}
|
||||
StructMember{field1: __f32}
|
||||
@ -602,9 +584,9 @@ TEST_F(SpvParserTest, ConvertType_StructWithBlockDecoration) {
|
||||
|
||||
auto* type = p->ConvertType(10);
|
||||
ASSERT_NE(type, nullptr);
|
||||
EXPECT_TRUE(type->Is<ast::type::StructType>());
|
||||
EXPECT_TRUE(type->Is<ast::type::Struct>());
|
||||
std::stringstream ss;
|
||||
type->As<ast::type::StructType>()->impl()->to_str(ss, 0);
|
||||
type->As<ast::type::Struct>()->impl()->to_str(ss, 0);
|
||||
EXPECT_THAT(ss.str(), Eq(R"(Struct{
|
||||
[[block]]
|
||||
StructMember{field0: __u32}
|
||||
@ -627,9 +609,9 @@ TEST_F(SpvParserTest, ConvertType_StructWithMemberDecorations) {
|
||||
|
||||
auto* type = p->ConvertType(10);
|
||||
ASSERT_NE(type, nullptr);
|
||||
EXPECT_TRUE(type->Is<ast::type::StructType>());
|
||||
EXPECT_TRUE(type->Is<ast::type::Struct>());
|
||||
std::stringstream ss;
|
||||
type->As<ast::type::StructType>()->impl()->to_str(ss, 0);
|
||||
type->As<ast::type::Struct>()->impl()->to_str(ss, 0);
|
||||
EXPECT_THAT(ss.str(), Eq(R"(Struct{
|
||||
StructMember{[[ offset 0 ]] field0: __f32}
|
||||
StructMember{[[ offset 8 ]] field1: __vec_2__f32}
|
||||
@ -676,10 +658,10 @@ TEST_F(SpvParserTest, ConvertType_PointerInput) {
|
||||
EXPECT_TRUE(p->BuildInternalModule());
|
||||
|
||||
auto* type = p->ConvertType(3);
|
||||
EXPECT_TRUE(type->Is<ast::type::PointerType>());
|
||||
auto* ptr_ty = type->As<ast::type::PointerType>();
|
||||
EXPECT_TRUE(type->Is<ast::type::Pointer>());
|
||||
auto* ptr_ty = type->As<ast::type::Pointer>();
|
||||
EXPECT_NE(ptr_ty, nullptr);
|
||||
EXPECT_TRUE(ptr_ty->type()->Is<ast::type::F32Type>());
|
||||
EXPECT_TRUE(ptr_ty->type()->Is<ast::type::F32>());
|
||||
EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kInput);
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
}
|
||||
@ -692,10 +674,10 @@ TEST_F(SpvParserTest, ConvertType_PointerOutput) {
|
||||
EXPECT_TRUE(p->BuildInternalModule());
|
||||
|
||||
auto* type = p->ConvertType(3);
|
||||
EXPECT_TRUE(type->Is<ast::type::PointerType>());
|
||||
auto* ptr_ty = type->As<ast::type::PointerType>();
|
||||
EXPECT_TRUE(type->Is<ast::type::Pointer>());
|
||||
auto* ptr_ty = type->As<ast::type::Pointer>();
|
||||
EXPECT_NE(ptr_ty, nullptr);
|
||||
EXPECT_TRUE(ptr_ty->type()->Is<ast::type::F32Type>());
|
||||
EXPECT_TRUE(ptr_ty->type()->Is<ast::type::F32>());
|
||||
EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kOutput);
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
}
|
||||
@ -708,10 +690,10 @@ TEST_F(SpvParserTest, ConvertType_PointerUniform) {
|
||||
EXPECT_TRUE(p->BuildInternalModule());
|
||||
|
||||
auto* type = p->ConvertType(3);
|
||||
EXPECT_TRUE(type->Is<ast::type::PointerType>());
|
||||
auto* ptr_ty = type->As<ast::type::PointerType>();
|
||||
EXPECT_TRUE(type->Is<ast::type::Pointer>());
|
||||
auto* ptr_ty = type->As<ast::type::Pointer>();
|
||||
EXPECT_NE(ptr_ty, nullptr);
|
||||
EXPECT_TRUE(ptr_ty->type()->Is<ast::type::F32Type>());
|
||||
EXPECT_TRUE(ptr_ty->type()->Is<ast::type::F32>());
|
||||
EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kUniform);
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
}
|
||||
@ -724,10 +706,10 @@ TEST_F(SpvParserTest, ConvertType_PointerWorkgroup) {
|
||||
EXPECT_TRUE(p->BuildInternalModule());
|
||||
|
||||
auto* type = p->ConvertType(3);
|
||||
EXPECT_TRUE(type->Is<ast::type::PointerType>());
|
||||
auto* ptr_ty = type->As<ast::type::PointerType>();
|
||||
EXPECT_TRUE(type->Is<ast::type::Pointer>());
|
||||
auto* ptr_ty = type->As<ast::type::Pointer>();
|
||||
EXPECT_NE(ptr_ty, nullptr);
|
||||
EXPECT_TRUE(ptr_ty->type()->Is<ast::type::F32Type>());
|
||||
EXPECT_TRUE(ptr_ty->type()->Is<ast::type::F32>());
|
||||
EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kWorkgroup);
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
}
|
||||
@ -740,10 +722,10 @@ TEST_F(SpvParserTest, ConvertType_PointerUniformConstant) {
|
||||
EXPECT_TRUE(p->BuildInternalModule());
|
||||
|
||||
auto* type = p->ConvertType(3);
|
||||
EXPECT_TRUE(type->Is<ast::type::PointerType>());
|
||||
auto* ptr_ty = type->As<ast::type::PointerType>();
|
||||
EXPECT_TRUE(type->Is<ast::type::Pointer>());
|
||||
auto* ptr_ty = type->As<ast::type::Pointer>();
|
||||
EXPECT_NE(ptr_ty, nullptr);
|
||||
EXPECT_TRUE(ptr_ty->type()->Is<ast::type::F32Type>());
|
||||
EXPECT_TRUE(ptr_ty->type()->Is<ast::type::F32>());
|
||||
EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kUniformConstant);
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
}
|
||||
@ -756,10 +738,10 @@ TEST_F(SpvParserTest, ConvertType_PointerStorageBuffer) {
|
||||
EXPECT_TRUE(p->BuildInternalModule());
|
||||
|
||||
auto* type = p->ConvertType(3);
|
||||
EXPECT_TRUE(type->Is<ast::type::PointerType>());
|
||||
auto* ptr_ty = type->As<ast::type::PointerType>();
|
||||
EXPECT_TRUE(type->Is<ast::type::Pointer>());
|
||||
auto* ptr_ty = type->As<ast::type::Pointer>();
|
||||
EXPECT_NE(ptr_ty, nullptr);
|
||||
EXPECT_TRUE(ptr_ty->type()->Is<ast::type::F32Type>());
|
||||
EXPECT_TRUE(ptr_ty->type()->Is<ast::type::F32>());
|
||||
EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kStorageBuffer);
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
}
|
||||
@ -772,10 +754,10 @@ TEST_F(SpvParserTest, ConvertType_PointerImage) {
|
||||
EXPECT_TRUE(p->BuildInternalModule());
|
||||
|
||||
auto* type = p->ConvertType(3);
|
||||
EXPECT_TRUE(type->Is<ast::type::PointerType>());
|
||||
auto* ptr_ty = type->As<ast::type::PointerType>();
|
||||
EXPECT_TRUE(type->Is<ast::type::Pointer>());
|
||||
auto* ptr_ty = type->As<ast::type::Pointer>();
|
||||
EXPECT_NE(ptr_ty, nullptr);
|
||||
EXPECT_TRUE(ptr_ty->type()->Is<ast::type::F32Type>());
|
||||
EXPECT_TRUE(ptr_ty->type()->Is<ast::type::F32>());
|
||||
EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kImage);
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
}
|
||||
@ -788,10 +770,10 @@ TEST_F(SpvParserTest, ConvertType_PointerPrivate) {
|
||||
EXPECT_TRUE(p->BuildInternalModule());
|
||||
|
||||
auto* type = p->ConvertType(3);
|
||||
EXPECT_TRUE(type->Is<ast::type::PointerType>());
|
||||
auto* ptr_ty = type->As<ast::type::PointerType>();
|
||||
EXPECT_TRUE(type->Is<ast::type::Pointer>());
|
||||
auto* ptr_ty = type->As<ast::type::Pointer>();
|
||||
EXPECT_NE(ptr_ty, nullptr);
|
||||
EXPECT_TRUE(ptr_ty->type()->Is<ast::type::F32Type>());
|
||||
EXPECT_TRUE(ptr_ty->type()->Is<ast::type::F32>());
|
||||
EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kPrivate);
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
}
|
||||
@ -804,10 +786,10 @@ TEST_F(SpvParserTest, ConvertType_PointerFunction) {
|
||||
EXPECT_TRUE(p->BuildInternalModule());
|
||||
|
||||
auto* type = p->ConvertType(3);
|
||||
EXPECT_TRUE(type->Is<ast::type::PointerType>());
|
||||
auto* ptr_ty = type->As<ast::type::PointerType>();
|
||||
EXPECT_TRUE(type->Is<ast::type::Pointer>());
|
||||
auto* ptr_ty = type->As<ast::type::Pointer>();
|
||||
EXPECT_NE(ptr_ty, nullptr);
|
||||
EXPECT_TRUE(ptr_ty->type()->Is<ast::type::F32Type>());
|
||||
EXPECT_TRUE(ptr_ty->type()->Is<ast::type::F32>());
|
||||
EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kFunction);
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
}
|
||||
@ -823,17 +805,17 @@ TEST_F(SpvParserTest, ConvertType_PointerToPointer) {
|
||||
|
||||
auto* type = p->ConvertType(3);
|
||||
EXPECT_NE(type, nullptr);
|
||||
EXPECT_TRUE(type->Is<ast::type::PointerType>());
|
||||
EXPECT_TRUE(type->Is<ast::type::Pointer>());
|
||||
|
||||
auto* ptr_ty = type->As<ast::type::PointerType>();
|
||||
auto* ptr_ty = type->As<ast::type::Pointer>();
|
||||
EXPECT_NE(ptr_ty, nullptr);
|
||||
EXPECT_EQ(ptr_ty->storage_class(), ast::StorageClass::kInput);
|
||||
EXPECT_TRUE(ptr_ty->type()->Is<ast::type::PointerType>());
|
||||
EXPECT_TRUE(ptr_ty->type()->Is<ast::type::Pointer>());
|
||||
|
||||
auto* ptr_ptr_ty = ptr_ty->type()->As<ast::type::PointerType>();
|
||||
auto* ptr_ptr_ty = ptr_ty->type()->As<ast::type::Pointer>();
|
||||
EXPECT_NE(ptr_ptr_ty, nullptr);
|
||||
EXPECT_EQ(ptr_ptr_ty->storage_class(), ast::StorageClass::kOutput);
|
||||
EXPECT_TRUE(ptr_ptr_ty->type()->Is<ast::type::F32Type>());
|
||||
EXPECT_TRUE(ptr_ptr_ty->type()->Is<ast::type::F32>());
|
||||
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
}
|
||||
@ -846,7 +828,7 @@ TEST_F(SpvParserTest, ConvertType_Sampler_PretendVoid) {
|
||||
EXPECT_TRUE(p->BuildInternalModule());
|
||||
|
||||
auto* type = p->ConvertType(1);
|
||||
EXPECT_TRUE(type->Is<ast::type::VoidType>());
|
||||
EXPECT_TRUE(type->Is<ast::type::Void>());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
}
|
||||
|
||||
@ -859,7 +841,7 @@ TEST_F(SpvParserTest, ConvertType_Image_PretendVoid) {
|
||||
EXPECT_TRUE(p->BuildInternalModule());
|
||||
|
||||
auto* type = p->ConvertType(1);
|
||||
EXPECT_TRUE(type->Is<ast::type::VoidType>());
|
||||
EXPECT_TRUE(type->Is<ast::type::Void>());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
}
|
||||
|
||||
@ -872,7 +854,7 @@ TEST_F(SpvParserTest, ConvertType_SampledImage_PretendVoid) {
|
||||
EXPECT_TRUE(p->BuildInternalModule());
|
||||
|
||||
auto* type = p->ConvertType(1);
|
||||
EXPECT_TRUE(type->Is<ast::type::VoidType>());
|
||||
EXPECT_TRUE(type->Is<ast::type::Void>());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
}
|
||||
|
||||
|
@ -318,7 +318,7 @@ Expect<bool> ParserImpl::expect_global_decl() {
|
||||
return Failure::kErrored;
|
||||
|
||||
auto* type = module_.unique_type(std::move(str.value));
|
||||
register_constructed(type->As<ast::type::StructType>()->name(), type);
|
||||
register_constructed(type->As<ast::type::Struct>()->name(), type);
|
||||
module_.AddConstructedType(type);
|
||||
return true;
|
||||
}
|
||||
@ -471,8 +471,7 @@ Maybe<ast::type::Type*> ParserImpl::texture_sampler_types() {
|
||||
if (subtype.errored)
|
||||
return Failure::kErrored;
|
||||
|
||||
return module_.create<ast::type::SampledTextureType>(dim.value,
|
||||
subtype.value);
|
||||
return module_.create<ast::type::SampledTexture>(dim.value, subtype.value);
|
||||
}
|
||||
|
||||
auto ms_dim = multisampled_texture_type();
|
||||
@ -483,8 +482,8 @@ Maybe<ast::type::Type*> ParserImpl::texture_sampler_types() {
|
||||
if (subtype.errored)
|
||||
return Failure::kErrored;
|
||||
|
||||
return module_.create<ast::type::MultisampledTextureType>(ms_dim.value,
|
||||
subtype.value);
|
||||
return module_.create<ast::type::MultisampledTexture>(ms_dim.value,
|
||||
subtype.value);
|
||||
}
|
||||
|
||||
auto storage = storage_texture_type();
|
||||
@ -497,7 +496,7 @@ Maybe<ast::type::Type*> ParserImpl::texture_sampler_types() {
|
||||
if (format.errored)
|
||||
return Failure::kErrored;
|
||||
|
||||
return module_.create<ast::type::StorageTextureType>(
|
||||
return module_.create<ast::type::StorageTexture>(
|
||||
storage->first, storage->second, format.value);
|
||||
}
|
||||
|
||||
@ -509,11 +508,10 @@ Maybe<ast::type::Type*> ParserImpl::texture_sampler_types() {
|
||||
// | SAMPLER_COMPARISON
|
||||
Maybe<ast::type::Type*> ParserImpl::sampler_type() {
|
||||
if (match(Token::Type::kSampler))
|
||||
return module_.create<ast::type::SamplerType>(
|
||||
ast::type::SamplerKind::kSampler);
|
||||
return module_.create<ast::type::Sampler>(ast::type::SamplerKind::kSampler);
|
||||
|
||||
if (match(Token::Type::kComparisonSampler))
|
||||
return module_.create<ast::type::SamplerType>(
|
||||
return module_.create<ast::type::Sampler>(
|
||||
ast::type::SamplerKind::kComparisonSampler);
|
||||
|
||||
return Failure::kNoMatch;
|
||||
@ -642,19 +640,19 @@ ParserImpl::storage_texture_type() {
|
||||
// | TEXTURE_DEPTH_CUBE_ARRAY
|
||||
Maybe<ast::type::Type*> ParserImpl::depth_texture_type() {
|
||||
if (match(Token::Type::kTextureDepth2d))
|
||||
return module_.create<ast::type::DepthTextureType>(
|
||||
return module_.create<ast::type::DepthTexture>(
|
||||
ast::type::TextureDimension::k2d);
|
||||
|
||||
if (match(Token::Type::kTextureDepth2dArray))
|
||||
return module_.create<ast::type::DepthTextureType>(
|
||||
return module_.create<ast::type::DepthTexture>(
|
||||
ast::type::TextureDimension::k2dArray);
|
||||
|
||||
if (match(Token::Type::kTextureDepthCube))
|
||||
return module_.create<ast::type::DepthTextureType>(
|
||||
return module_.create<ast::type::DepthTexture>(
|
||||
ast::type::TextureDimension::kCube);
|
||||
|
||||
if (match(Token::Type::kTextureDepthCubeArray))
|
||||
return module_.create<ast::type::DepthTextureType>(
|
||||
return module_.create<ast::type::DepthTexture>(
|
||||
ast::type::TextureDimension::kCubeArray);
|
||||
|
||||
return Failure::kNoMatch;
|
||||
@ -840,7 +838,7 @@ Expect<ParserImpl::TypedIdentifier> ParserImpl::expect_variable_ident_decl(
|
||||
for (auto* deco : access_decos) {
|
||||
// If we have an access control decoration then we take it and wrap our
|
||||
// type up with that decoration
|
||||
ty = module_.create<ast::type::AccessControlType>(
|
||||
ty = module_.create<ast::type::AccessControl>(
|
||||
deco->As<ast::AccessDecoration>()->value(), ty);
|
||||
}
|
||||
|
||||
@ -900,7 +898,7 @@ Maybe<ast::type::Type*> ParserImpl::type_alias() {
|
||||
if (!type.matched)
|
||||
return add_error(peek(), "invalid type alias");
|
||||
|
||||
auto* alias = module_.create<ast::type::AliasType>(name.value, type.value);
|
||||
auto* alias = module_.create<ast::type::Alias>(name.value, type.value);
|
||||
register_constructed(name.value, alias);
|
||||
|
||||
return alias;
|
||||
@ -958,16 +956,16 @@ Maybe<ast::type::Type*> ParserImpl::type_decl(ast::DecorationList& decos) {
|
||||
}
|
||||
|
||||
if (match(Token::Type::kBool))
|
||||
return module_.create<ast::type::BoolType>();
|
||||
return module_.create<ast::type::Bool>();
|
||||
|
||||
if (match(Token::Type::kF32))
|
||||
return module_.create<ast::type::F32Type>();
|
||||
return module_.create<ast::type::F32>();
|
||||
|
||||
if (match(Token::Type::kI32))
|
||||
return module_.create<ast::type::I32Type>();
|
||||
return module_.create<ast::type::I32>();
|
||||
|
||||
if (match(Token::Type::kU32))
|
||||
return module_.create<ast::type::U32Type>();
|
||||
return module_.create<ast::type::U32>();
|
||||
|
||||
if (t.IsVec2() || t.IsVec3() || t.IsVec4()) {
|
||||
next(); // Consume the peek
|
||||
@ -1025,7 +1023,7 @@ Expect<ast::type::Type*> ParserImpl::expect_type_decl_pointer() {
|
||||
if (subtype.errored)
|
||||
return Failure::kErrored;
|
||||
|
||||
return module_.create<ast::type::PointerType>(subtype.value, sc.value);
|
||||
return module_.create<ast::type::Pointer>(subtype.value, sc.value);
|
||||
});
|
||||
}
|
||||
|
||||
@ -1042,7 +1040,7 @@ Expect<ast::type::Type*> ParserImpl::expect_type_decl_vector(Token t) {
|
||||
if (subtype.errored)
|
||||
return Failure::kErrored;
|
||||
|
||||
return module_.create<ast::type::VectorType>(subtype.value, count);
|
||||
return module_.create<ast::type::Vector>(subtype.value, count);
|
||||
}
|
||||
|
||||
Expect<ast::type::Type*> ParserImpl::expect_type_decl_array(
|
||||
@ -1062,7 +1060,7 @@ Expect<ast::type::Type*> ParserImpl::expect_type_decl_array(
|
||||
size = val.value;
|
||||
}
|
||||
|
||||
auto ty = std::make_unique<ast::type::ArrayType>(subtype.value, size);
|
||||
auto ty = std::make_unique<ast::type::Array>(subtype.value, size);
|
||||
ty->set_decorations(std::move(decos));
|
||||
return module_.unique_type(std::move(ty));
|
||||
});
|
||||
@ -1088,7 +1086,7 @@ Expect<ast::type::Type*> ParserImpl::expect_type_decl_matrix(Token t) {
|
||||
if (subtype.errored)
|
||||
return Failure::kErrored;
|
||||
|
||||
return module_.create<ast::type::MatrixType>(subtype.value, rows, columns);
|
||||
return module_.create<ast::type::Matrix>(subtype.value, rows, columns);
|
||||
}
|
||||
|
||||
// storage_class
|
||||
@ -1135,7 +1133,7 @@ Expect<ast::StorageClass> ParserImpl::expect_storage_class(
|
||||
|
||||
// struct_decl
|
||||
// : struct_decoration_decl* STRUCT IDENT struct_body_decl
|
||||
Maybe<std::unique_ptr<ast::type::StructType>> ParserImpl::struct_decl(
|
||||
Maybe<std::unique_ptr<ast::type::Struct>> ParserImpl::struct_decl(
|
||||
ast::DecorationList& decos) {
|
||||
auto t = peek();
|
||||
auto source = t.source();
|
||||
@ -1155,7 +1153,7 @@ Maybe<std::unique_ptr<ast::type::StructType>> ParserImpl::struct_decl(
|
||||
if (struct_decos.errored)
|
||||
return Failure::kErrored;
|
||||
|
||||
return std::make_unique<ast::type::StructType>(
|
||||
return std::make_unique<ast::type::Struct>(
|
||||
name.value, create<ast::Struct>(source, std::move(struct_decos.value),
|
||||
std::move(body.value)));
|
||||
}
|
||||
@ -1256,7 +1254,7 @@ Maybe<ast::Function*> ParserImpl::function_decl(ast::DecorationList& decos) {
|
||||
// | VOID
|
||||
Maybe<ast::type::Type*> ParserImpl::function_type_decl() {
|
||||
if (match(Token::Type::kVoid))
|
||||
return module_.create<ast::type::VoidType>();
|
||||
return module_.create<ast::type::Void>();
|
||||
|
||||
return type_decl();
|
||||
}
|
||||
@ -2615,19 +2613,19 @@ Maybe<ast::AssignmentStatement*> ParserImpl::assignment_stmt() {
|
||||
Maybe<ast::Literal*> ParserImpl::const_literal() {
|
||||
auto t = peek();
|
||||
if (match(Token::Type::kTrue)) {
|
||||
auto* type = module_.create<ast::type::BoolType>();
|
||||
auto* type = module_.create<ast::type::Bool>();
|
||||
return create<ast::BoolLiteral>(type, true);
|
||||
}
|
||||
if (match(Token::Type::kFalse)) {
|
||||
auto* type = module_.create<ast::type::BoolType>();
|
||||
auto* type = module_.create<ast::type::Bool>();
|
||||
return create<ast::BoolLiteral>(type, false);
|
||||
}
|
||||
if (match(Token::Type::kSintLiteral)) {
|
||||
auto* type = module_.create<ast::type::I32Type>();
|
||||
auto* type = module_.create<ast::type::I32>();
|
||||
return create<ast::SintLiteral>(type, t.to_i32());
|
||||
}
|
||||
if (match(Token::Type::kUintLiteral)) {
|
||||
auto* type = module_.create<ast::type::U32Type>();
|
||||
auto* type = module_.create<ast::type::U32>();
|
||||
return create<ast::UintLiteral>(type, t.to_u32());
|
||||
}
|
||||
if (match(Token::Type::kFloatLiteral)) {
|
||||
@ -2636,7 +2634,7 @@ Maybe<ast::Literal*> ParserImpl::const_literal() {
|
||||
next(); // Consume 'f'
|
||||
add_error(p.source(), "float literals must not be suffixed with 'f'");
|
||||
}
|
||||
auto* type = module_.create<ast::type::F32Type>();
|
||||
auto* type = module_.create<ast::type::F32>();
|
||||
return create<ast::FloatLiteral>(type, t.to_f32());
|
||||
}
|
||||
return Failure::kNoMatch;
|
||||
|
@ -34,7 +34,6 @@
|
||||
#include "src/ast/constructor_expression.h"
|
||||
#include "src/ast/continue_statement.h"
|
||||
#include "src/ast/else_statement.h"
|
||||
#include "src/ast/switch_statement.h"
|
||||
#include "src/ast/function.h"
|
||||
#include "src/ast/if_statement.h"
|
||||
#include "src/ast/literal.h"
|
||||
@ -48,6 +47,7 @@
|
||||
#include "src/ast/struct_decoration.h"
|
||||
#include "src/ast/struct_member.h"
|
||||
#include "src/ast/struct_member_decoration.h"
|
||||
#include "src/ast/switch_statement.h"
|
||||
#include "src/ast/type/storage_texture_type.h"
|
||||
#include "src/ast/type/struct_type.h"
|
||||
#include "src/ast/type/texture_type.h"
|
||||
@ -353,7 +353,7 @@ class ParserImpl {
|
||||
/// `struct_decoration_decl*` provided as |decos|.
|
||||
/// @returns the struct type or nullptr on error
|
||||
/// @param decos the list of decorations for the struct declaration.
|
||||
Maybe<std::unique_ptr<ast::type::StructType>> struct_decl(
|
||||
Maybe<std::unique_ptr<ast::type::Struct>> struct_decl(
|
||||
ast::DecorationList& decos);
|
||||
/// Parses a `struct_body_decl` grammar element, erroring on parse failure.
|
||||
/// @returns the struct members
|
||||
|
@ -35,8 +35,8 @@ TEST_F(ParserImplTest, ConstExpr_TypeDecl) {
|
||||
ASSERT_TRUE(e->Is<ast::TypeConstructorExpression>());
|
||||
|
||||
auto* t = e->As<ast::TypeConstructorExpression>();
|
||||
ASSERT_TRUE(t->type()->Is<ast::type::VectorType>());
|
||||
EXPECT_EQ(t->type()->As<ast::type::VectorType>()->size(), 2u);
|
||||
ASSERT_TRUE(t->type()->Is<ast::type::Vector>());
|
||||
EXPECT_EQ(t->type()->As<ast::type::Vector>()->size(), 2u);
|
||||
|
||||
ASSERT_EQ(t->values().size(), 2u);
|
||||
auto& v = t->values();
|
||||
|
@ -36,10 +36,9 @@ TEST_F(ParserImplTest, DepthTextureType_2d) {
|
||||
EXPECT_TRUE(t.matched);
|
||||
EXPECT_FALSE(t.errored);
|
||||
ASSERT_NE(t.value, nullptr);
|
||||
ASSERT_TRUE(t->Is<ast::type::TextureType>());
|
||||
ASSERT_TRUE(
|
||||
t->As<ast::type::TextureType>()->Is<ast::type::DepthTextureType>());
|
||||
EXPECT_EQ(t->As<ast::type::TextureType>()->dim(),
|
||||
ASSERT_TRUE(t->Is<ast::type::Texture>());
|
||||
ASSERT_TRUE(t->As<ast::type::Texture>()->Is<ast::type::DepthTexture>());
|
||||
EXPECT_EQ(t->As<ast::type::Texture>()->dim(),
|
||||
ast::type::TextureDimension::k2d);
|
||||
EXPECT_FALSE(p->has_error());
|
||||
}
|
||||
@ -50,10 +49,9 @@ TEST_F(ParserImplTest, DepthTextureType_2dArray) {
|
||||
EXPECT_TRUE(t.matched);
|
||||
EXPECT_FALSE(t.errored);
|
||||
ASSERT_NE(t.value, nullptr);
|
||||
ASSERT_TRUE(t->Is<ast::type::TextureType>());
|
||||
ASSERT_TRUE(
|
||||
t->As<ast::type::TextureType>()->Is<ast::type::DepthTextureType>());
|
||||
EXPECT_EQ(t->As<ast::type::TextureType>()->dim(),
|
||||
ASSERT_TRUE(t->Is<ast::type::Texture>());
|
||||
ASSERT_TRUE(t->As<ast::type::Texture>()->Is<ast::type::DepthTexture>());
|
||||
EXPECT_EQ(t->As<ast::type::Texture>()->dim(),
|
||||
ast::type::TextureDimension::k2dArray);
|
||||
EXPECT_FALSE(p->has_error());
|
||||
}
|
||||
@ -64,10 +62,9 @@ TEST_F(ParserImplTest, DepthTextureType_Cube) {
|
||||
EXPECT_TRUE(t.matched);
|
||||
EXPECT_FALSE(t.errored);
|
||||
ASSERT_NE(t.value, nullptr);
|
||||
ASSERT_TRUE(t->Is<ast::type::TextureType>());
|
||||
ASSERT_TRUE(
|
||||
t->As<ast::type::TextureType>()->Is<ast::type::DepthTextureType>());
|
||||
EXPECT_EQ(t->As<ast::type::TextureType>()->dim(),
|
||||
ASSERT_TRUE(t->Is<ast::type::Texture>());
|
||||
ASSERT_TRUE(t->As<ast::type::Texture>()->Is<ast::type::DepthTexture>());
|
||||
EXPECT_EQ(t->As<ast::type::Texture>()->dim(),
|
||||
ast::type::TextureDimension::kCube);
|
||||
EXPECT_FALSE(p->has_error());
|
||||
}
|
||||
@ -78,10 +75,9 @@ TEST_F(ParserImplTest, DepthTextureType_CubeArray) {
|
||||
EXPECT_TRUE(t.matched);
|
||||
EXPECT_FALSE(t.errored);
|
||||
ASSERT_NE(t.value, nullptr);
|
||||
ASSERT_TRUE(t->Is<ast::type::TextureType>());
|
||||
ASSERT_TRUE(
|
||||
t->As<ast::type::TextureType>()->Is<ast::type::DepthTextureType>());
|
||||
EXPECT_EQ(t->As<ast::type::TextureType>()->dim(),
|
||||
ASSERT_TRUE(t->Is<ast::type::Texture>());
|
||||
ASSERT_TRUE(t->As<ast::type::Texture>()->Is<ast::type::DepthTexture>());
|
||||
EXPECT_EQ(t->As<ast::type::Texture>()->dim(),
|
||||
ast::type::TextureDimension::kCubeArray);
|
||||
EXPECT_FALSE(p->has_error());
|
||||
}
|
||||
|
@ -39,14 +39,14 @@ TEST_F(ParserImplTest, FunctionDecl) {
|
||||
|
||||
EXPECT_EQ(f->name(), "main");
|
||||
ASSERT_NE(f->return_type(), nullptr);
|
||||
EXPECT_TRUE(f->return_type()->Is<ast::type::VoidType>());
|
||||
EXPECT_TRUE(f->return_type()->Is<ast::type::Void>());
|
||||
|
||||
ASSERT_EQ(f->params().size(), 2u);
|
||||
EXPECT_EQ(f->params()[0]->name(), "a");
|
||||
EXPECT_EQ(f->params()[1]->name(), "b");
|
||||
|
||||
ASSERT_NE(f->return_type(), nullptr);
|
||||
EXPECT_TRUE(f->return_type()->Is<ast::type::VoidType>());
|
||||
EXPECT_TRUE(f->return_type()->Is<ast::type::Void>());
|
||||
|
||||
auto* body = f->body();
|
||||
ASSERT_EQ(body->size(), 1u);
|
||||
@ -67,10 +67,10 @@ TEST_F(ParserImplTest, FunctionDecl_DecorationList) {
|
||||
|
||||
EXPECT_EQ(f->name(), "main");
|
||||
ASSERT_NE(f->return_type(), nullptr);
|
||||
EXPECT_TRUE(f->return_type()->Is<ast::type::VoidType>());
|
||||
EXPECT_TRUE(f->return_type()->Is<ast::type::Void>());
|
||||
ASSERT_EQ(f->params().size(), 0u);
|
||||
ASSERT_NE(f->return_type(), nullptr);
|
||||
EXPECT_TRUE(f->return_type()->Is<ast::type::VoidType>());
|
||||
EXPECT_TRUE(f->return_type()->Is<ast::type::Void>());
|
||||
|
||||
auto& decorations = f->decorations();
|
||||
ASSERT_EQ(decorations.size(), 1u);
|
||||
@ -105,10 +105,10 @@ fn main() -> void { return; })");
|
||||
|
||||
EXPECT_EQ(f->name(), "main");
|
||||
ASSERT_NE(f->return_type(), nullptr);
|
||||
EXPECT_TRUE(f->return_type()->Is<ast::type::VoidType>());
|
||||
EXPECT_TRUE(f->return_type()->Is<ast::type::Void>());
|
||||
ASSERT_EQ(f->params().size(), 0u);
|
||||
ASSERT_NE(f->return_type(), nullptr);
|
||||
EXPECT_TRUE(f->return_type()->Is<ast::type::VoidType>());
|
||||
EXPECT_TRUE(f->return_type()->Is<ast::type::Void>());
|
||||
|
||||
auto& decorations = f->decorations();
|
||||
ASSERT_EQ(decorations.size(), 2u);
|
||||
@ -150,10 +150,10 @@ fn main() -> void { return; })");
|
||||
|
||||
EXPECT_EQ(f->name(), "main");
|
||||
ASSERT_NE(f->return_type(), nullptr);
|
||||
EXPECT_TRUE(f->return_type()->Is<ast::type::VoidType>());
|
||||
EXPECT_TRUE(f->return_type()->Is<ast::type::Void>());
|
||||
ASSERT_EQ(f->params().size(), 0u);
|
||||
ASSERT_NE(f->return_type(), nullptr);
|
||||
EXPECT_TRUE(f->return_type()->Is<ast::type::VoidType>());
|
||||
EXPECT_TRUE(f->return_type()->Is<ast::type::Void>());
|
||||
|
||||
auto& decos = f->decorations();
|
||||
ASSERT_EQ(decos.size(), 2u);
|
||||
|
@ -36,7 +36,7 @@ TEST_F(ParserImplTest, FunctionHeader) {
|
||||
ASSERT_EQ(f->params().size(), 2u);
|
||||
EXPECT_EQ(f->params()[0]->name(), "a");
|
||||
EXPECT_EQ(f->params()[1]->name(), "b");
|
||||
EXPECT_TRUE(f->return_type()->Is<ast::type::VoidType>());
|
||||
EXPECT_TRUE(f->return_type()->Is<ast::type::Void>());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, FunctionHeader_MissingIdent) {
|
||||
|
@ -30,7 +30,7 @@ TEST_F(ParserImplTest, FunctionTypeDecl_Void) {
|
||||
auto p = parser("void");
|
||||
|
||||
auto& mod = p->get_module();
|
||||
auto* v = mod.create<ast::type::VoidType>();
|
||||
auto* v = mod.create<ast::type::Void>();
|
||||
|
||||
auto e = p->function_type_decl();
|
||||
EXPECT_TRUE(e.matched);
|
||||
@ -43,8 +43,8 @@ TEST_F(ParserImplTest, FunctionTypeDecl_Type) {
|
||||
auto p = parser("vec2<f32>");
|
||||
|
||||
auto& mod = p->get_module();
|
||||
auto* f32 = mod.create<ast::type::F32Type>();
|
||||
auto* vec2 = mod.create<ast::type::VectorType>(f32, 2);
|
||||
auto* f32 = mod.create<ast::type::F32>();
|
||||
auto* vec2 = mod.create<ast::type::Vector>(f32, 2);
|
||||
|
||||
auto e = p->function_type_decl();
|
||||
EXPECT_TRUE(e.matched);
|
||||
|
@ -35,7 +35,7 @@ TEST_F(ParserImplTest, GlobalConstantDecl) {
|
||||
EXPECT_TRUE(e->is_const());
|
||||
EXPECT_EQ(e->name(), "a");
|
||||
ASSERT_NE(e->type(), nullptr);
|
||||
EXPECT_TRUE(e->type()->Is<ast::type::F32Type>());
|
||||
EXPECT_TRUE(e->type()->Is<ast::type::F32>());
|
||||
|
||||
EXPECT_EQ(e->source().range.begin.line, 1u);
|
||||
EXPECT_EQ(e->source().range.begin.column, 7u);
|
||||
|
@ -88,8 +88,8 @@ TEST_F(ParserImplTest, GlobalDecl_TypeAlias) {
|
||||
|
||||
auto& m = p->get_module();
|
||||
ASSERT_EQ(m.constructed_types().size(), 1u);
|
||||
ASSERT_TRUE(m.constructed_types()[0]->Is<ast::type::AliasType>());
|
||||
EXPECT_EQ(m.constructed_types()[0]->As<ast::type::AliasType>()->name(), "A");
|
||||
ASSERT_TRUE(m.constructed_types()[0]->Is<ast::type::Alias>());
|
||||
EXPECT_EQ(m.constructed_types()[0]->As<ast::type::Alias>()->name(), "A");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, GlobalDecl_TypeAlias_StructIdent) {
|
||||
@ -103,12 +103,12 @@ type B = A;)");
|
||||
|
||||
auto& m = p->get_module();
|
||||
ASSERT_EQ(m.constructed_types().size(), 2u);
|
||||
ASSERT_TRUE(m.constructed_types()[0]->Is<ast::type::StructType>());
|
||||
auto* str = m.constructed_types()[0]->As<ast::type::StructType>();
|
||||
ASSERT_TRUE(m.constructed_types()[0]->Is<ast::type::Struct>());
|
||||
auto* str = m.constructed_types()[0]->As<ast::type::Struct>();
|
||||
EXPECT_EQ(str->name(), "A");
|
||||
|
||||
ASSERT_TRUE(m.constructed_types()[1]->Is<ast::type::AliasType>());
|
||||
auto* alias = m.constructed_types()[1]->As<ast::type::AliasType>();
|
||||
ASSERT_TRUE(m.constructed_types()[1]->Is<ast::type::Alias>());
|
||||
auto* alias = m.constructed_types()[1]->As<ast::type::Alias>();
|
||||
EXPECT_EQ(alias->name(), "B");
|
||||
EXPECT_EQ(alias->type(), str);
|
||||
}
|
||||
@ -164,9 +164,9 @@ TEST_F(ParserImplTest, GlobalDecl_ParsesStruct) {
|
||||
|
||||
auto* t = m.constructed_types()[0];
|
||||
ASSERT_NE(t, nullptr);
|
||||
ASSERT_TRUE(t->Is<ast::type::StructType>());
|
||||
ASSERT_TRUE(t->Is<ast::type::Struct>());
|
||||
|
||||
auto* str = t->As<ast::type::StructType>();
|
||||
auto* str = t->As<ast::type::Struct>();
|
||||
EXPECT_EQ(str->name(), "A");
|
||||
EXPECT_EQ(str->impl()->members().size(), 2u);
|
||||
}
|
||||
@ -183,16 +183,16 @@ TEST_F(ParserImplTest, GlobalDecl_Struct_WithStride) {
|
||||
|
||||
auto* t = m.constructed_types()[0];
|
||||
ASSERT_NE(t, nullptr);
|
||||
ASSERT_TRUE(t->Is<ast::type::StructType>());
|
||||
ASSERT_TRUE(t->Is<ast::type::Struct>());
|
||||
|
||||
auto* str = t->As<ast::type::StructType>();
|
||||
auto* str = t->As<ast::type::Struct>();
|
||||
EXPECT_EQ(str->name(), "A");
|
||||
EXPECT_EQ(str->impl()->members().size(), 1u);
|
||||
EXPECT_FALSE(str->IsBlockDecorated());
|
||||
|
||||
const auto* ty = str->impl()->members()[0]->type();
|
||||
ASSERT_TRUE(ty->Is<ast::type::ArrayType>());
|
||||
const auto* arr = ty->As<ast::type::ArrayType>();
|
||||
ASSERT_TRUE(ty->Is<ast::type::Array>());
|
||||
const auto* arr = ty->As<ast::type::Array>();
|
||||
EXPECT_TRUE(arr->has_array_stride());
|
||||
EXPECT_EQ(arr->array_stride(), 4u);
|
||||
}
|
||||
@ -207,9 +207,9 @@ TEST_F(ParserImplTest, GlobalDecl_Struct_WithDecoration) {
|
||||
|
||||
auto* t = m.constructed_types()[0];
|
||||
ASSERT_NE(t, nullptr);
|
||||
ASSERT_TRUE(t->Is<ast::type::StructType>());
|
||||
ASSERT_TRUE(t->Is<ast::type::Struct>());
|
||||
|
||||
auto* str = t->As<ast::type::StructType>();
|
||||
auto* str = t->As<ast::type::Struct>();
|
||||
EXPECT_EQ(str->name(), "A");
|
||||
EXPECT_EQ(str->impl()->members().size(), 1u);
|
||||
EXPECT_TRUE(str->IsBlockDecorated());
|
||||
|
@ -37,7 +37,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithoutConstructor) {
|
||||
ASSERT_NE(e.value, nullptr);
|
||||
|
||||
EXPECT_EQ(e->name(), "a");
|
||||
EXPECT_TRUE(e->type()->Is<ast::type::F32Type>());
|
||||
EXPECT_TRUE(e->type()->Is<ast::type::F32>());
|
||||
EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput);
|
||||
|
||||
EXPECT_EQ(e->source().range.begin.line, 1u);
|
||||
@ -61,7 +61,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithConstructor) {
|
||||
ASSERT_NE(e.value, nullptr);
|
||||
|
||||
EXPECT_EQ(e->name(), "a");
|
||||
EXPECT_TRUE(e->type()->Is<ast::type::F32Type>());
|
||||
EXPECT_TRUE(e->type()->Is<ast::type::F32>());
|
||||
EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput);
|
||||
|
||||
EXPECT_EQ(e->source().range.begin.line, 1u);
|
||||
@ -90,7 +90,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithDecoration) {
|
||||
|
||||
EXPECT_EQ(e->name(), "a");
|
||||
ASSERT_NE(e->type(), nullptr);
|
||||
EXPECT_TRUE(e->type()->Is<ast::type::F32Type>());
|
||||
EXPECT_TRUE(e->type()->Is<ast::type::F32>());
|
||||
EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput);
|
||||
|
||||
EXPECT_EQ(e->source().range.begin.line, 1u);
|
||||
@ -124,7 +124,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithDecoration_MulitpleGroups) {
|
||||
|
||||
EXPECT_EQ(e->name(), "a");
|
||||
ASSERT_NE(e->type(), nullptr);
|
||||
EXPECT_TRUE(e->type()->Is<ast::type::F32Type>());
|
||||
EXPECT_TRUE(e->type()->Is<ast::type::F32>());
|
||||
EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput);
|
||||
|
||||
EXPECT_EQ(e->source().range.begin.line, 1u);
|
||||
|
@ -31,7 +31,7 @@ TEST_F(ParserImplTest, ParamList_Single) {
|
||||
auto p = parser("a : i32");
|
||||
|
||||
auto& mod = p->get_module();
|
||||
auto* i32 = mod.create<ast::type::I32Type>();
|
||||
auto* i32 = mod.create<ast::type::I32>();
|
||||
|
||||
auto e = p->expect_param_list();
|
||||
ASSERT_FALSE(p->has_error()) << p->error();
|
||||
@ -52,9 +52,9 @@ TEST_F(ParserImplTest, ParamList_Multiple) {
|
||||
auto p = parser("a : i32, b: f32, c: vec2<f32>");
|
||||
|
||||
auto& mod = p->get_module();
|
||||
auto* i32 = mod.create<ast::type::I32Type>();
|
||||
auto* f32 = mod.create<ast::type::F32Type>();
|
||||
auto* vec2 = mod.create<ast::type::VectorType>(f32, 2);
|
||||
auto* i32 = mod.create<ast::type::I32>();
|
||||
auto* f32 = mod.create<ast::type::F32>();
|
||||
auto* vec2 = mod.create<ast::type::Vector>(f32, 2);
|
||||
|
||||
auto e = p->expect_param_list();
|
||||
ASSERT_FALSE(p->has_error()) << p->error();
|
||||
|
@ -194,7 +194,7 @@ TEST_F(ParserImplTest, PrimaryExpression_Cast) {
|
||||
auto p = parser("f32(1)");
|
||||
|
||||
auto& mod = p->get_module();
|
||||
auto* f32 = mod.create<ast::type::F32Type>();
|
||||
auto* f32 = mod.create<ast::type::F32>();
|
||||
|
||||
auto e = p->primary_expression();
|
||||
EXPECT_TRUE(e.matched);
|
||||
@ -216,7 +216,7 @@ TEST_F(ParserImplTest, PrimaryExpression_Bitcast) {
|
||||
auto p = parser("bitcast<f32>(1)");
|
||||
|
||||
auto& mod = p->get_module();
|
||||
auto* f32 = mod.create<ast::type::F32Type>();
|
||||
auto* f32 = mod.create<ast::type::F32>();
|
||||
|
||||
auto e = p->primary_expression();
|
||||
EXPECT_TRUE(e.matched);
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user