ProgramBuilder: Migrate matrices to typ::TypePair Used as a stepping stone to emitting the ast::Types instead. Bug: tint:724 Change-Id: Ic81f0a00456e91ac089df32193c4323c2e779c29 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48684 Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: Antonio Maiorano <amaiorano@google.com>
diff --git a/src/program_builder.h b/src/program_builder.h index 805dba3..1dec6d9 100644 --- a/src/program_builder.h +++ b/src/program_builder.h
@@ -30,6 +30,7 @@ #include "src/ast/i32.h" #include "src/ast/if_statement.h" #include "src/ast/loop_statement.h" +#include "src/ast/matrix.h" #include "src/ast/member_accessor_expression.h" #include "src/ast/module.h" #include "src/ast/return_statement.h" @@ -401,109 +402,118 @@ /// @param type matrix subtype /// @return the tint AST type for a 2x3 matrix of `type`. - sem::Matrix* mat2x2(sem::Type* type) const { - return builder->create<sem::Matrix>(type, 2u, 2u); + typ::Matrix mat2x2(typ::Type type) const { + return {builder->create<ast::Matrix>(type, 2u, 2u), + builder->create<sem::Matrix>(type, 2u, 2u)}; } /// @param type matrix subtype /// @return the tint AST type for a 2x3 matrix of `type`. - sem::Matrix* mat2x3(sem::Type* type) const { - return builder->create<sem::Matrix>(type, 3u, 2u); + typ::Matrix mat2x3(typ::Type type) const { + return {builder->create<ast::Matrix>(type, 3u, 2u), + builder->create<sem::Matrix>(type, 3u, 2u)}; } /// @param type matrix subtype /// @return the tint AST type for a 2x4 matrix of `type`. - sem::Matrix* mat2x4(sem::Type* type) const { - return builder->create<sem::Matrix>(type, 4u, 2u); + typ::Matrix mat2x4(typ::Type type) const { + return {builder->create<ast::Matrix>(type, 4u, 2u), + builder->create<sem::Matrix>(type, 4u, 2u)}; } /// @param type matrix subtype /// @return the tint AST type for a 3x2 matrix of `type`. - sem::Matrix* mat3x2(sem::Type* type) const { - return builder->create<sem::Matrix>(type, 2u, 3u); + typ::Matrix mat3x2(typ::Type type) const { + return {builder->create<ast::Matrix>(type, 2u, 3u), + builder->create<sem::Matrix>(type, 2u, 3u)}; } /// @param type matrix subtype /// @return the tint AST type for a 3x3 matrix of `type`. - sem::Matrix* mat3x3(sem::Type* type) const { - return builder->create<sem::Matrix>(type, 3u, 3u); + typ::Matrix mat3x3(typ::Type type) const { + return {builder->create<ast::Matrix>(type, 3u, 3u), + builder->create<sem::Matrix>(type, 3u, 3u)}; } /// @param type matrix subtype /// @return the tint AST type for a 3x4 matrix of `type`. - sem::Matrix* mat3x4(sem::Type* type) const { - return builder->create<sem::Matrix>(type, 4u, 3u); + typ::Matrix mat3x4(typ::Type type) const { + return {builder->create<ast::Matrix>(type, 4u, 3u), + builder->create<sem::Matrix>(type, 4u, 3u)}; } /// @param type matrix subtype /// @return the tint AST type for a 4x2 matrix of `type`. - sem::Matrix* mat4x2(sem::Type* type) const { - return builder->create<sem::Matrix>(type, 2u, 4u); + typ::Matrix mat4x2(typ::Type type) const { + return {builder->create<ast::Matrix>(type, 2u, 4u), + builder->create<sem::Matrix>(type, 2u, 4u)}; } /// @param type matrix subtype /// @return the tint AST type for a 4x3 matrix of `type`. - sem::Matrix* mat4x3(sem::Type* type) const { - return builder->create<sem::Matrix>(type, 3u, 4u); + typ::Matrix mat4x3(typ::Type type) const { + return {builder->create<ast::Matrix>(type, 3u, 4u), + builder->create<sem::Matrix>(type, 3u, 4u)}; } /// @param type matrix subtype /// @return the tint AST type for a 4x4 matrix of `type`. - sem::Matrix* mat4x4(sem::Type* type) const { - return builder->create<sem::Matrix>(type, 4u, 4u); + typ::Matrix mat4x4(typ::Type type) const { + return {builder->create<ast::Matrix>(type, 4u, 4u), + builder->create<sem::Matrix>(type, 4u, 4u)}; } /// @return the tint AST type for a 2x3 matrix of the C type `T`. template <typename T> - sem::Matrix* mat2x2() const { + typ::Matrix mat2x2() const { return mat2x2(Of<T>()); } /// @return the tint AST type for a 2x3 matrix of the C type `T`. template <typename T> - sem::Matrix* mat2x3() const { + typ::Matrix mat2x3() const { return mat2x3(Of<T>()); } /// @return the tint AST type for a 2x4 matrix of the C type `T`. template <typename T> - sem::Matrix* mat2x4() const { + typ::Matrix mat2x4() const { return mat2x4(Of<T>()); } /// @return the tint AST type for a 3x2 matrix of the C type `T`. template <typename T> - sem::Matrix* mat3x2() const { + typ::Matrix mat3x2() const { return mat3x2(Of<T>()); } /// @return the tint AST type for a 3x3 matrix of the C type `T`. template <typename T> - sem::Matrix* mat3x3() const { + typ::Matrix mat3x3() const { return mat3x3(Of<T>()); } /// @return the tint AST type for a 3x4 matrix of the C type `T`. template <typename T> - sem::Matrix* mat3x4() const { + typ::Matrix mat3x4() const { return mat3x4(Of<T>()); } /// @return the tint AST type for a 4x2 matrix of the C type `T`. template <typename T> - sem::Matrix* mat4x2() const { + typ::Matrix mat4x2() const { return mat4x2(Of<T>()); } /// @return the tint AST type for a 4x3 matrix of the C type `T`. template <typename T> - sem::Matrix* mat4x3() const { + typ::Matrix mat4x3() const { return mat4x3(Of<T>()); } /// @return the tint AST type for a 4x4 matrix of the C type `T`. template <typename T> - sem::Matrix* mat4x4() const { + typ::Matrix mat4x4() const { return mat4x4(Of<T>()); }
diff --git a/src/typepair.h b/src/typepair.h index 7638880..9a5ee20 100644 --- a/src/typepair.h +++ b/src/typepair.h
@@ -25,6 +25,7 @@ class Bool; class F32; class I32; +class Matrix; class U32; class Vector; class Void; @@ -34,6 +35,7 @@ class Bool; class F32; class I32; +class Matrix; class U32; class Vector; class Void; @@ -85,6 +87,7 @@ using Bool = TypePair<ast::Bool, sem::Bool>; using F32 = TypePair<ast::F32, sem::F32>; using I32 = TypePair<ast::I32, sem::I32>; +using Matrix = TypePair<ast::Matrix, sem::Matrix>; using U32 = TypePair<ast::U32, sem::U32>; using Vector = TypePair<ast::Vector, sem::Vector>; using Void = TypePair<ast::Void, sem::Void>;
diff --git a/src/writer/hlsl/generator_impl_type_test.cc b/src/writer/hlsl/generator_impl_type_test.cc index 5d8bfd6..f24dd4d 100644 --- a/src/writer/hlsl/generator_impl_type_test.cc +++ b/src/writer/hlsl/generator_impl_type_test.cc
@@ -135,7 +135,7 @@ } TEST_F(HlslGeneratorImplTest_Type, EmitType_Matrix) { - auto* mat2x3 = ty.mat2x3<f32>(); + auto mat2x3 = ty.mat2x3<f32>(); GeneratorImpl& gen = Build();
diff --git a/src/writer/msl/generator_impl_type_test.cc b/src/writer/msl/generator_impl_type_test.cc index e489cba..33aefd0 100644 --- a/src/writer/msl/generator_impl_type_test.cc +++ b/src/writer/msl/generator_impl_type_test.cc
@@ -154,7 +154,7 @@ } TEST_F(MslGeneratorImplTest, EmitType_Matrix) { - auto* mat2x3 = ty.mat2x3<f32>(); + auto mat2x3 = ty.mat2x3<f32>(); GeneratorImpl& gen = Build();
diff --git a/src/writer/spirv/builder_type_test.cc b/src/writer/spirv/builder_type_test.cc index 3fe6541..2f4a6d3 100644 --- a/src/writer/spirv/builder_type_test.cc +++ b/src/writer/spirv/builder_type_test.cc
@@ -232,7 +232,7 @@ } TEST_F(BuilderTest_Type, GenerateMatrix) { - auto* mat2x3 = ty.mat2x3<f32>(); + auto mat2x3 = ty.mat2x3<f32>(); spirv::Builder& b = Build(); @@ -248,7 +248,7 @@ } TEST_F(BuilderTest_Type, ReturnsGeneratedMatrix) { - auto* mat = ty.mat4x3<i32>(); + auto mat = ty.mat4x3<i32>(); auto i32 = ty.i32(); spirv::Builder& b = Build();
diff --git a/src/writer/wgsl/generator_impl_type_test.cc b/src/writer/wgsl/generator_impl_type_test.cc index 296294b..c4f3e4a 100644 --- a/src/writer/wgsl/generator_impl_type_test.cc +++ b/src/writer/wgsl/generator_impl_type_test.cc
@@ -140,7 +140,7 @@ } TEST_F(WgslGeneratorImplTest, EmitType_Matrix) { - auto* mat2x3 = ty.mat2x3<f32>(); + auto mat2x3 = ty.mat2x3<f32>(); AST().AddConstructedType(ty.alias("make_type_reachable", mat2x3)); GeneratorImpl& gen = Build();