Have TypesBuilder vector and matrix methods return ast types

Bug: tint:724
Change-Id: I7bf0d36572ff332e1ecc606f2aa61414a6d74377
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/51664
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton 2021-05-20 14:57:58 +00:00 committed by Tint LUCI CQ
parent b966265f5a
commit d3e80fd36c
2 changed files with 6 additions and 16 deletions

View File

@ -404,8 +404,7 @@ class ProgramBuilder {
/// @return the tint AST type for a `n`-element vector of `type`. /// @return the tint AST type for a `n`-element vector of `type`.
typ::Vector vec(typ::Type type, uint32_t n) const { typ::Vector vec(typ::Type type, uint32_t n) const {
type = MaybeCreateTypename(type); type = MaybeCreateTypename(type);
return {type.ast ? builder->create<ast::Vector>(type, n) : nullptr, return {builder->create<ast::Vector>(type, n)};
type.sem ? builder->create<sem::Vector>(type, n) : nullptr};
} }
/// @param source the Source of the node /// @param source the Source of the node
@ -414,9 +413,7 @@ class ProgramBuilder {
/// @return the tint AST type for a `n`-element vector of `type`. /// @return the tint AST type for a `n`-element vector of `type`.
typ::Vector vec(const Source& source, typ::Type type, uint32_t n) const { typ::Vector vec(const Source& source, typ::Type type, uint32_t n) const {
type = MaybeCreateTypename(type); type = MaybeCreateTypename(type);
return { return {builder->create<ast::Vector>(source, type, n)};
type.ast ? builder->create<ast::Vector>(source, type, n) : nullptr,
type.sem ? builder->create<sem::Vector>(type, n) : nullptr};
} }
/// @param type vector subtype /// @param type vector subtype
@ -462,10 +459,7 @@ class ProgramBuilder {
/// @return the tint AST type for a matrix of `type` /// @return the tint AST type for a matrix of `type`
typ::Matrix mat(typ::Type type, uint32_t columns, uint32_t rows) const { typ::Matrix mat(typ::Type type, uint32_t columns, uint32_t rows) const {
type = MaybeCreateTypename(type); type = MaybeCreateTypename(type);
return {type.ast ? builder->create<ast::Matrix>(type, rows, columns) return {builder->create<ast::Matrix>(type, rows, columns)};
: nullptr,
type.sem ? builder->create<sem::Matrix>(vec(type, rows), columns)
: nullptr};
} }
/// @param source the Source of the node /// @param source the Source of the node
@ -477,11 +471,7 @@ class ProgramBuilder {
typ::Type type, typ::Type type,
uint32_t columns, uint32_t columns,
uint32_t rows) const { uint32_t rows) const {
return {type.ast return {builder->create<ast::Matrix>(source, type, rows, columns)};
? builder->create<ast::Matrix>(source, type, rows, columns)
: nullptr,
type.sem ? builder->create<sem::Matrix>(vec(type, rows), columns)
: nullptr};
} }
/// @param type matrix subtype /// @param type matrix subtype

View File

@ -237,10 +237,8 @@ bool operator!=(std::nullptr_t, const TypePair<AST, SEM>& rhs) {
using Type = TypePair<ast::Type, sem::Type>; using Type = TypePair<ast::Type, sem::Type>;
using Matrix = TypePair<ast::Matrix, sem::Matrix>;
using Pointer = TypePair<ast::Pointer, sem::Pointer>; using Pointer = TypePair<ast::Pointer, sem::Pointer>;
using Struct = TypePair<ast::Struct, sem::Struct>; using Struct = TypePair<ast::Struct, sem::Struct>;
using Vector = TypePair<ast::Vector, sem::Vector>;
using Bool = Ptr<ast::Bool>; using Bool = Ptr<ast::Bool>;
using U32 = Ptr<ast::U32>; using U32 = Ptr<ast::U32>;
@ -254,6 +252,8 @@ using SampledTexture = Ptr<ast::SampledTexture>;
using StorageTexture = Ptr<ast::StorageTexture>; using StorageTexture = Ptr<ast::StorageTexture>;
using Texture = Ptr<ast::Texture>; using Texture = Ptr<ast::Texture>;
using Sampler = Ptr<ast::Sampler>; using Sampler = Ptr<ast::Sampler>;
using Matrix = Ptr<ast::Matrix>;
using Vector = Ptr<ast::Vector>;
// Helpers // Helpers