ProgramBuilder: Migrate vectors to typ::TypePair
Used as a stepping stone to emitting the ast::Types instead. Bug: tint:724 Change-Id: I19d7df9ab684db598783235c1720586966a232e0 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48683 Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
parent
43073d8aa3
commit
e30ffeb02a
|
@ -65,7 +65,8 @@ TEST_F(AstVectorTest, TypeName) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(AstVectorTest, FriendlyName) {
|
TEST_F(AstVectorTest, FriendlyName) {
|
||||||
auto* v = ty.vec3<f32>();
|
auto* f32 = create<F32>();
|
||||||
|
auto* v = create<Vector>(f32, 3);
|
||||||
EXPECT_EQ(v->FriendlyName(Symbols()), "vec3<f32>");
|
EXPECT_EQ(v->FriendlyName(Symbols()), "vec3<f32>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -355,7 +355,7 @@ TEST_F(IntrinsicTableTest, MatchWithNestedAliasUnwrapping) {
|
||||||
auto* alias_a = ty.alias("alias_a", ty.bool_());
|
auto* alias_a = ty.alias("alias_a", ty.bool_());
|
||||||
auto* alias_b = ty.alias("alias_b", alias_a);
|
auto* alias_b = ty.alias("alias_b", alias_a);
|
||||||
auto* alias_c = ty.alias("alias_c", alias_b);
|
auto* alias_c = ty.alias("alias_c", alias_b);
|
||||||
auto* vec4_of_c = ty.vec4(alias_c);
|
auto vec4_of_c = ty.vec4(alias_c);
|
||||||
auto* alias_d = ty.alias("alias_d", vec4_of_c);
|
auto* alias_d = ty.alias("alias_d", vec4_of_c);
|
||||||
auto* alias_e = ty.alias("alias_e", alias_d);
|
auto* alias_e = ty.alias("alias_e", alias_d);
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
#include "src/ast/u32.h"
|
#include "src/ast/u32.h"
|
||||||
#include "src/ast/uint_literal.h"
|
#include "src/ast/uint_literal.h"
|
||||||
#include "src/ast/variable_decl_statement.h"
|
#include "src/ast/variable_decl_statement.h"
|
||||||
|
#include "src/ast/vector.h"
|
||||||
#include "src/ast/void.h"
|
#include "src/ast/void.h"
|
||||||
#include "src/program.h"
|
#include "src/program.h"
|
||||||
#include "src/program_id.h"
|
#include "src/program_id.h"
|
||||||
|
@ -361,37 +362,40 @@ class ProgramBuilder {
|
||||||
|
|
||||||
/// @param type vector subtype
|
/// @param type vector subtype
|
||||||
/// @return the tint AST type for a 2-element vector of `type`.
|
/// @return the tint AST type for a 2-element vector of `type`.
|
||||||
sem::Vector* vec2(sem::Type* type) const {
|
typ::Vector vec2(typ::Type type) const {
|
||||||
return builder->create<sem::Vector>(type, 2u);
|
return {builder->create<ast::Vector>(type, 2u),
|
||||||
|
builder->create<sem::Vector>(type, 2u)};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @param type vector subtype
|
/// @param type vector subtype
|
||||||
/// @return the tint AST type for a 3-element vector of `type`.
|
/// @return the tint AST type for a 3-element vector of `type`.
|
||||||
sem::Vector* vec3(sem::Type* type) const {
|
typ::Vector vec3(typ::Type type) const {
|
||||||
return builder->create<sem::Vector>(type, 3u);
|
return {builder->create<ast::Vector>(type, 3u),
|
||||||
|
builder->create<sem::Vector>(type, 3u)};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @param type vector subtype
|
/// @param type vector subtype
|
||||||
/// @return the tint AST type for a 4-element vector of `type`.
|
/// @return the tint AST type for a 4-element vector of `type`.
|
||||||
sem::Type* vec4(sem::Type* type) const {
|
typ::Vector vec4(typ::Type type) const {
|
||||||
return builder->create<sem::Vector>(type, 4u);
|
return {builder->create<ast::Vector>(type, 4u),
|
||||||
|
builder->create<sem::Vector>(type, 4u)};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @return the tint AST type for a 2-element vector of the C type `T`.
|
/// @return the tint AST type for a 2-element vector of the C type `T`.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
sem::Vector* vec2() const {
|
typ::Vector vec2() const {
|
||||||
return vec2(Of<T>());
|
return vec2(Of<T>());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @return the tint AST type for a 3-element vector of the C type `T`.
|
/// @return the tint AST type for a 3-element vector of the C type `T`.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
sem::Vector* vec3() const {
|
typ::Vector vec3() const {
|
||||||
return vec3(Of<T>());
|
return vec3(Of<T>());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @return the tint AST type for a 4-element vector of the C type `T`.
|
/// @return the tint AST type for a 4-element vector of the C type `T`.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
sem::Type* vec4() const {
|
typ::Vector vec4() const {
|
||||||
return vec4(Of<T>());
|
return vec4(Of<T>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,13 +49,14 @@ TEST_F(VectorTest, Is) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(VectorTest, TypeName) {
|
TEST_F(VectorTest, TypeName) {
|
||||||
I32 i32;
|
auto* i32 = create<I32>();
|
||||||
Vector v{&i32, 3};
|
auto* v = create<Vector>(i32, 3);
|
||||||
EXPECT_EQ(v.type_name(), "__vec_3__i32");
|
EXPECT_EQ(v->type_name(), "__vec_3__i32");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(VectorTest, FriendlyName) {
|
TEST_F(VectorTest, FriendlyName) {
|
||||||
auto* v = ty.vec3<f32>();
|
auto* f32 = create<F32>();
|
||||||
|
auto* v = create<Vector>(f32, 3);
|
||||||
EXPECT_EQ(v->FriendlyName(Symbols()), "vec3<f32>");
|
EXPECT_EQ(v->FriendlyName(Symbols()), "vec3<f32>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ class Bool;
|
||||||
class F32;
|
class F32;
|
||||||
class I32;
|
class I32;
|
||||||
class U32;
|
class U32;
|
||||||
|
class Vector;
|
||||||
class Void;
|
class Void;
|
||||||
} // namespace ast
|
} // namespace ast
|
||||||
|
|
||||||
|
@ -34,12 +35,13 @@ class Bool;
|
||||||
class F32;
|
class F32;
|
||||||
class I32;
|
class I32;
|
||||||
class U32;
|
class U32;
|
||||||
|
class Vector;
|
||||||
class Void;
|
class Void;
|
||||||
} // namespace sem
|
} // namespace sem
|
||||||
|
|
||||||
namespace typ { // type-pair
|
namespace typ { // type-pair
|
||||||
|
|
||||||
/// Type is a pair of ast::Type and sem::Type pointers used to simplify
|
/// TypePair is a pair of ast::Type and sem::Type pointers used to simplify
|
||||||
/// migration to the new ast::Type nodes.
|
/// migration to the new ast::Type nodes.
|
||||||
///
|
///
|
||||||
/// Type attempts to behave as either an ast::Type or sem::Type:
|
/// Type attempts to behave as either an ast::Type or sem::Type:
|
||||||
|
@ -51,24 +53,24 @@ namespace typ { // type-pair
|
||||||
/// * operator->() returns the sem::Type pointer. Later in the migration this
|
/// * operator->() returns the sem::Type pointer. Later in the migration this
|
||||||
/// will switch to returning the ast::Type pointer.
|
/// will switch to returning the ast::Type pointer.
|
||||||
template <typename AST, typename SEM>
|
template <typename AST, typename SEM>
|
||||||
struct Type {
|
struct TypePair {
|
||||||
/// The ast::Type pointer
|
/// The ast::Type pointer
|
||||||
AST const* const ast = nullptr;
|
AST const* const ast = nullptr;
|
||||||
/// The sem::Type pointer
|
/// The sem::Type pointer
|
||||||
SEM const* const sem = nullptr;
|
SEM const* const sem = nullptr;
|
||||||
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
Type() = default;
|
TypePair() = default;
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param a the ast::Type pointer
|
/// @param a the ast::Type pointer
|
||||||
Type(const AST* a) : ast(a) {} // NOLINT: explicit
|
TypePair(const AST* a) : ast(a) {} // NOLINT: explicit
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param s the sem::Type pointer
|
/// @param s the sem::Type pointer
|
||||||
Type(const SEM* s) : sem(s) {} // NOLINT: explicit
|
TypePair(const SEM* s) : sem(s) {} // NOLINT: explicit
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param a the ast::Type pointer
|
/// @param a the ast::Type pointer
|
||||||
/// @param s the sem::Type pointer
|
/// @param s the sem::Type pointer
|
||||||
Type(const AST* a, const SEM* s) : ast(a), sem(s) {}
|
TypePair(const AST* a, const SEM* s) : ast(a), sem(s) {}
|
||||||
|
|
||||||
/// @returns the ast::Type pointer
|
/// @returns the ast::Type pointer
|
||||||
operator AST*() const { return const_cast<AST*>(ast); }
|
operator AST*() const { return const_cast<AST*>(ast); }
|
||||||
|
@ -78,11 +80,14 @@ struct Type {
|
||||||
SEM* operator->() const { return const_cast<SEM*>(sem); }
|
SEM* operator->() const { return const_cast<SEM*>(sem); }
|
||||||
};
|
};
|
||||||
|
|
||||||
using Bool = Type<ast::Bool, sem::Bool>;
|
using Type = TypePair<ast::Type, sem::Type>;
|
||||||
using F32 = Type<ast::F32, sem::F32>;
|
|
||||||
using I32 = Type<ast::I32, sem::I32>;
|
using Bool = TypePair<ast::Bool, sem::Bool>;
|
||||||
using U32 = Type<ast::U32, sem::U32>;
|
using F32 = TypePair<ast::F32, sem::F32>;
|
||||||
using Void = Type<ast::Void, sem::Void>;
|
using I32 = TypePair<ast::I32, sem::I32>;
|
||||||
|
using U32 = TypePair<ast::U32, sem::U32>;
|
||||||
|
using Vector = TypePair<ast::Vector, sem::Vector>;
|
||||||
|
using Void = TypePair<ast::Void, sem::Void>;
|
||||||
|
|
||||||
} // namespace typ
|
} // namespace typ
|
||||||
|
|
||||||
|
|
|
@ -275,7 +275,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_U32) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(HlslGeneratorImplTest_Type, EmitType_Vector) {
|
TEST_F(HlslGeneratorImplTest_Type, EmitType_Vector) {
|
||||||
auto* vec3 = ty.vec3<f32>();
|
auto vec3 = ty.vec3<f32>();
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
|
|
@ -613,7 +613,7 @@ TEST_F(MslGeneratorImplTest, EmitType_U32) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, EmitType_Vector) {
|
TEST_F(MslGeneratorImplTest, EmitType_Vector) {
|
||||||
auto* vec3 = ty.vec3<f32>();
|
auto vec3 = ty.vec3<f32>();
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ TEST_F(BuilderTest, EntryPoint_Parameters) {
|
||||||
// var col : f32 = (coord.x * loc1);
|
// var col : f32 = (coord.x * loc1);
|
||||||
// }
|
// }
|
||||||
auto f32 = ty.f32();
|
auto f32 = ty.f32();
|
||||||
auto* vec4 = ty.vec4<float>();
|
auto vec4 = ty.vec4<float>();
|
||||||
auto* coord = Param("coord", vec4, {Builtin(ast::Builtin::kPosition)});
|
auto* coord = Param("coord", vec4, {Builtin(ast::Builtin::kPosition)});
|
||||||
auto* loc1 = Param("loc1", f32, {Location(1u)});
|
auto* loc1 = Param("loc1", f32, {Location(1u)});
|
||||||
auto* mul = Mul(Expr(MemberAccessor("coord", "x")), Expr("loc1"));
|
auto* mul = Mul(Expr(MemberAccessor("coord", "x")), Expr("loc1"));
|
||||||
|
|
|
@ -528,7 +528,7 @@ TEST_F(BuilderTest_Type, ReturnsGeneratedU32) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest_Type, GenerateVector) {
|
TEST_F(BuilderTest_Type, GenerateVector) {
|
||||||
auto* vec = ty.vec3<f32>();
|
auto vec = ty.vec3<f32>();
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -543,7 +543,7 @@ TEST_F(BuilderTest_Type, GenerateVector) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest_Type, ReturnsGeneratedVector) {
|
TEST_F(BuilderTest_Type, ReturnsGeneratedVector) {
|
||||||
auto* vec = ty.vec3<i32>();
|
auto vec = ty.vec3<i32>();
|
||||||
auto i32 = ty.i32();
|
auto i32 = ty.i32();
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
|
@ -140,7 +140,7 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_Multiple) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(WgslGeneratorImplTest, Emit_Function_EntryPoint_Parameters) {
|
TEST_F(WgslGeneratorImplTest, Emit_Function_EntryPoint_Parameters) {
|
||||||
auto* vec4 = ty.vec4<f32>();
|
auto vec4 = ty.vec4<f32>();
|
||||||
auto* coord = Param("coord", vec4, {Builtin(ast::Builtin::kPosition)});
|
auto* coord = Param("coord", vec4, {Builtin(ast::Builtin::kPosition)});
|
||||||
auto* loc1 = Param("loc1", ty.f32(), {Location(1u)});
|
auto* loc1 = Param("loc1", ty.f32(), {Location(1u)});
|
||||||
auto* func = Func("frag_main", ast::VariableList{coord, loc1}, ty.void_(),
|
auto* func = Func("frag_main", ast::VariableList{coord, loc1}, ty.void_(),
|
||||||
|
|
|
@ -303,7 +303,7 @@ TEST_F(WgslGeneratorImplTest, EmitType_U32) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(WgslGeneratorImplTest, EmitType_Vector) {
|
TEST_F(WgslGeneratorImplTest, EmitType_Vector) {
|
||||||
auto* vec3 = ty.vec3<f32>();
|
auto vec3 = ty.vec3<f32>();
|
||||||
AST().AddConstructedType(ty.alias("make_type_reachable", vec3));
|
AST().AddConstructedType(ty.alias("make_type_reachable", vec3));
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
Loading…
Reference in New Issue