Add create<T>() method to Module for types

Migrate all uses to use this and the new `unique_type<T>()` and `types()` methods.

Remove the `type_mgr()` accessor. `TypeManager` is now an implementation detail of the module, allowing us to unify the allocation of types and nodes (if we so wish).

Fixes: tint:337
Bug: tint:307
Change-Id: I233fa9dc73d60515dd721f02ea7ba089ef7d374f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/33667
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
Ben Clayton 2020-11-23 19:58:55 +00:00 committed by Commit Bot service account
parent 0fb5168fc7
commit 7e4ffa0064
21 changed files with 236 additions and 262 deletions

View File

@ -17,16 +17,16 @@
namespace tint {
namespace ast {
TypesBuilder::TypesBuilder(TypeManager* tm)
: bool_(tm->Get<ast::type::BoolType>()),
f32(tm->Get<ast::type::F32Type>()),
i32(tm->Get<ast::type::I32Type>()),
u32(tm->Get<ast::type::U32Type>()),
void_(tm->Get<ast::type::VoidType>()),
tm_(tm) {}
TypesBuilder::TypesBuilder(Module* mod)
: bool_(mod->create<ast::type::BoolType>()),
f32(mod->create<ast::type::F32Type>()),
i32(mod->create<ast::type::I32Type>()),
u32(mod->create<ast::type::U32Type>()),
void_(mod->create<ast::type::VoidType>()),
mod_(mod) {}
Builder::Builder(tint::Context* c, tint::ast::Module* m)
: ctx(c), mod(m), ty(&m->type_mgr()) {}
: ctx(c), mod(m), ty(m) {}
Builder::~Builder() = default;
ast::Variable* Builder::Var(const std::string& name,

View File

@ -47,8 +47,8 @@ namespace ast {
class TypesBuilder {
public:
/// Constructor
/// @param tm the type manager
explicit TypesBuilder(TypeManager* tm);
/// @param mod the module
explicit TypesBuilder(Module* mod);
/// A boolean type
ast::type::BoolType* const bool_;
@ -70,80 +70,80 @@ class TypesBuilder {
/// @return the tint AST type for a 2-element vector of the C type `T`.
template <typename T>
ast::type::VectorType* vec2() const {
return tm_->Get<ast::type::VectorType>(Of<T>(), 2);
return mod_->create<ast::type::VectorType>(Of<T>(), 2);
}
/// @return the tint AST type for a 3-element vector of the C type `T`.
template <typename T>
ast::type::VectorType* vec3() const {
return tm_->Get<ast::type::VectorType>(Of<T>(), 3);
return mod_->create<ast::type::VectorType>(Of<T>(), 3);
}
/// @return the tint AST type for a 4-element vector of the C type `T`.
template <typename T>
ast::type::Type* vec4() const {
return tm_->Get<ast::type::VectorType>(Of<T>(), 4);
return mod_->create<ast::type::VectorType>(Of<T>(), 4);
}
/// @return the tint AST type for a 2x3 matrix of the C type `T`.
template <typename T>
ast::type::MatrixType* mat2x2() const {
return tm_->Get<ast::type::MatrixType>(Of<T>(), 2, 2);
return mod_->create<ast::type::MatrixType>(Of<T>(), 2, 2);
}
/// @return the tint AST type for a 2x3 matrix of the C type `T`.
template <typename T>
ast::type::MatrixType* mat2x3() const {
return tm_->Get<ast::type::MatrixType>(Of<T>(), 3, 2);
return mod_->create<ast::type::MatrixType>(Of<T>(), 3, 2);
}
/// @return the tint AST type for a 2x4 matrix of the C type `T`.
template <typename T>
ast::type::MatrixType* mat2x4() const {
return tm_->Get<ast::type::MatrixType>(Of<T>(), 4, 2);
return mod_->create<ast::type::MatrixType>(Of<T>(), 4, 2);
}
/// @return the tint AST type for a 3x2 matrix of the C type `T`.
template <typename T>
ast::type::MatrixType* mat3x2() const {
return tm_->Get<ast::type::MatrixType>(Of<T>(), 2, 3);
return mod_->create<ast::type::MatrixType>(Of<T>(), 2, 3);
}
/// @return the tint AST type for a 3x3 matrix of the C type `T`.
template <typename T>
ast::type::MatrixType* mat3x3() const {
return tm_->Get<ast::type::MatrixType>(Of<T>(), 3, 3);
return mod_->create<ast::type::MatrixType>(Of<T>(), 3, 3);
}
/// @return the tint AST type for a 3x4 matrix of the C type `T`.
template <typename T>
ast::type::MatrixType* mat3x4() const {
return tm_->Get<ast::type::MatrixType>(Of<T>(), 4, 3);
return mod_->create<ast::type::MatrixType>(Of<T>(), 4, 3);
}
/// @return the tint AST type for a 4x2 matrix of the C type `T`.
template <typename T>
ast::type::MatrixType* mat4x2() const {
return tm_->Get<ast::type::MatrixType>(Of<T>(), 2, 4);
return mod_->create<ast::type::MatrixType>(Of<T>(), 2, 4);
}
/// @return the tint AST type for a 4x3 matrix of the C type `T`.
template <typename T>
ast::type::MatrixType* mat4x3() const {
return tm_->Get<ast::type::MatrixType>(Of<T>(), 3, 4);
return mod_->create<ast::type::MatrixType>(Of<T>(), 3, 4);
}
/// @return the tint AST type for a 4x4 matrix of the C type `T`.
template <typename T>
ast::type::MatrixType* mat4x4() const {
return tm_->Get<ast::type::MatrixType>(Of<T>(), 4, 4);
return mod_->create<ast::type::MatrixType>(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`
ast::type::ArrayType* array(ast::type::Type* subtype, uint32_t n) const {
return tm_->Get<ast::type::ArrayType>(subtype, n);
return mod_->create<ast::type::ArrayType>(subtype, n);
}
/// @return the tint AST type for an array of size `N` of type `T`
@ -161,7 +161,7 @@ class TypesBuilder {
template <typename T>
struct CToAST {};
TypeManager* const tm_;
Module* const mod_;
};
/// Helper for building common AST constructs.

View File

@ -17,6 +17,8 @@
#include <memory>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <utility>
#include <vector>
@ -30,6 +32,10 @@ namespace ast {
/// Represents all the source in a given program.
class Module {
template <typename T, typename BASE>
using EnableIfIsType =
typename std::enable_if<std::is_base_of<BASE, T>::value, T>::type;
public:
Module();
/// Move constructor
@ -78,15 +84,12 @@ class Module {
/// @returns a string representation of the module
std::string to_str() const;
/// @returns the Type Manager
ast::TypeManager& type_mgr() { return type_mgr_; }
/// Creates a new `ast::Node` owned by the Module. When the Module is
/// destructed, the `ast::Node` will also be destructed.
/// @param args the arguments to pass to the type constructor
/// @returns the node pointer
template <typename T, typename... ARGS>
T* create(ARGS&&... args) {
EnableIfIsType<T, ast::Node>* create(ARGS&&... args) {
static_assert(std::is_base_of<ast::Node, T>::value,
"T does not derive from ast::Node");
auto uptr = std::make_unique<T>(std::forward<ARGS>(args)...);
@ -95,6 +98,38 @@ class Module {
return ptr;
}
/// Creates a new `ast::Type` owned by the Module.
/// When the Module is destructed, owned Module and the returned
/// `ast::Type` will also be destructed.
/// Types are unique (de-aliased), and so `create()` for the same `T` and
/// arguments will return the same pointer.
/// @param args the arguments to pass to the type constructor
/// @returns the de-aliased type pointer
template <typename T, typename... ARGS>
EnableIfIsType<T, ast::type::Type>* create(ARGS&&... args) {
static_assert(std::is_base_of<ast::type::Type, T>::value,
"T does not derive from ast::type::Type");
return type_mgr_.Get<T>(std::forward<ARGS>(args)...);
}
/// Moves the type `ty` to the Module, returning a pointer to the unique
/// (de-aliased) type.
/// When the Module is destructed, the returned `ast::Type` will also be
/// destructed.
/// @param ty the type to add to the module
/// @returns the de-aliased type pointer
template <typename T>
EnableIfIsType<T, ast::type::Type>* unique_type(std::unique_ptr<T> ty) {
return static_cast<T*>(type_mgr_.Get(std::move(ty)));
}
/// Returns all the declared types in the module
/// @returns the mapping from name string to type.
const std::unordered_map<std::string, std::unique_ptr<ast::type::Type>>&
types() {
return type_mgr_.types();
}
private:
Module(const Module&) = delete;

View File

@ -80,9 +80,9 @@ TEST_F(StorageTextureTypeTest, TypeName) {
TEST_F(StorageTextureTypeTest, F32Type) {
Context ctx;
ast::Module mod;
ast::type::Type* s = mod.type_mgr().Get(std::make_unique<StorageTextureType>(
ast::type::Type* s = mod.create<StorageTextureType>(
TextureDimension::k2dArray, AccessControl::kReadOnly,
ImageFormat::kRgba32Float));
ImageFormat::kRgba32Float);
TypeDeterminer td(&ctx, &mod);
ASSERT_TRUE(td.Determine()) << td.error();
@ -94,9 +94,9 @@ TEST_F(StorageTextureTypeTest, F32Type) {
TEST_F(StorageTextureTypeTest, U32Type) {
Context ctx;
ast::Module mod;
ast::type::Type* s = mod.type_mgr().Get(std::make_unique<StorageTextureType>(
ast::type::Type* s = mod.create<StorageTextureType>(
TextureDimension::k2dArray, AccessControl::kReadOnly,
ImageFormat::kRgba8Unorm));
ImageFormat::kRgba8Unorm);
TypeDeterminer td(&ctx, &mod);
ASSERT_TRUE(td.Determine()) << td.error();
@ -108,9 +108,9 @@ TEST_F(StorageTextureTypeTest, U32Type) {
TEST_F(StorageTextureTypeTest, I32Type) {
Context ctx;
ast::Module mod;
ast::type::Type* s = mod.type_mgr().Get(std::make_unique<StorageTextureType>(
ast::type::Type* s = mod.create<StorageTextureType>(
TextureDimension::k2dArray, AccessControl::kReadOnly,
ImageFormat::kRgba32Sint));
ImageFormat::kRgba32Sint);
TypeDeterminer td(&ctx, &mod);
ASSERT_TRUE(td.Determine()) << td.error();

View File

@ -3253,8 +3253,8 @@ ast::type::Type* FunctionEmitter::RemapStorageClass(ast::type::Type* type,
const auto* ast_ptr_type = type->AsPointer();
const auto sc = GetStorageClassForPointerValue(result_id);
if (ast_ptr_type->storage_class() != sc) {
return parser_impl_.get_module().type_mgr().Get(
std::make_unique<ast::type::PointerType>(ast_ptr_type->type(), sc));
return parser_impl_.get_module().create<ast::type::PointerType>(
ast_ptr_type->type(), sc);
}
}
return type;

View File

@ -196,8 +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_.type_mgr().Get(std::make_unique<ast::type::BoolType>())),
bool_type_(ast_module_.create<ast::type::BoolType>()),
namer_(fail_stream_),
enum_converter_(fail_stream_),
tools_context_(kInputEnv) {
@ -286,8 +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_.type_mgr().Get(std::make_unique<ast::type::VoidType>()));
return save(ast_module_.create<ast::type::VoidType>());
case spvtools::opt::analysis::Type::kBool:
return save(bool_type_);
case spvtools::opt::analysis::Type::kInteger:
@ -317,8 +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_.type_mgr().Get(std::make_unique<ast::type::VoidType>()));
return save(ast_module_.create<ast::type::VoidType>());
default:
break;
}
@ -651,10 +648,8 @@ bool ParserImpl::RegisterEntryPoints() {
ast::type::Type* ParserImpl::ConvertType(
const spvtools::opt::analysis::Integer* int_ty) {
if (int_ty->width() == 32) {
auto* signed_ty =
ast_module_.type_mgr().Get(std::make_unique<ast::type::I32Type>());
auto* unsigned_ty =
ast_module_.type_mgr().Get(std::make_unique<ast::type::U32Type>());
ast::type::Type* signed_ty = ast_module_.create<ast::type::I32Type>();
ast::type::Type* unsigned_ty = ast_module_.create<ast::type::U32Type>();
signed_type_for_[unsigned_ty] = signed_ty;
unsigned_type_for_[signed_ty] = unsigned_ty;
return int_ty->IsSigned() ? signed_ty : unsigned_ty;
@ -666,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_.type_mgr().Get(std::make_unique<ast::type::F32Type>());
return ast_module_.create<ast::type::F32Type>();
}
Fail() << "unhandled float width: " << float_ty->width();
return nullptr;
@ -679,19 +674,17 @@ ast::type::Type* ParserImpl::ConvertType(
if (ast_elem_ty == nullptr) {
return nullptr;
}
auto* this_ty = ast_module_.type_mgr().Get(
std::make_unique<ast::type::VectorType>(ast_elem_ty, num_elem));
auto* this_ty =
ast_module_.create<ast::type::VectorType>(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_.type_mgr().Get(std::make_unique<ast::type::VectorType>(
unsigned_type_for_[ast_elem_ty], num_elem));
auto* other_ty = ast_module_.create<ast::type::VectorType>(
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_.type_mgr().Get(std::make_unique<ast::type::VectorType>(
signed_type_for_[ast_elem_ty], num_elem));
auto* other_ty = ast_module_.create<ast::type::VectorType>(
signed_type_for_[ast_elem_ty], num_elem);
unsigned_type_for_[other_ty] = this_ty;
signed_type_for_[this_ty] = other_ty;
}
@ -708,8 +701,8 @@ ast::type::Type* ParserImpl::ConvertType(
if (ast_scalar_ty == nullptr) {
return nullptr;
}
return ast_module_.type_mgr().Get(std::make_unique<ast::type::MatrixType>(
ast_scalar_ty, num_rows, num_columns));
return ast_module_.create<ast::type::MatrixType>(ast_scalar_ty, num_rows,
num_columns);
}
ast::type::Type* ParserImpl::ConvertType(
@ -722,7 +715,7 @@ ast::type::Type* ParserImpl::ConvertType(
if (!ApplyArrayDecorations(rtarr_ty, ast_type.get())) {
return nullptr;
}
return ast_module_.type_mgr().Get(std::move(ast_type));
return ast_module_.unique_type(std::move(ast_type));
}
ast::type::Type* ParserImpl::ConvertType(
@ -767,7 +760,7 @@ ast::type::Type* ParserImpl::ConvertType(
if (remap_buffer_block_type_.count(elem_type_id)) {
remap_buffer_block_type_.insert(type_mgr_->GetId(arr_ty));
}
return ast_module_.type_mgr().Get(std::move(ast_type));
return ast_module_.unique_type(std::move(ast_type));
}
bool ParserImpl::ApplyArrayDecorations(
@ -892,10 +885,9 @@ ast::type::Type* ParserImpl::ConvertType(
std::move(ast_members));
namer_.SuggestSanitizedName(type_id, "S");
auto ast_struct_type = std::make_unique<ast::type::StructType>(
namer_.GetName(type_id), ast_struct);
auto* result = ast_module_.type_mgr().Get(std::move(ast_struct_type));
auto* result = ast_module_.create<ast::type::StructType>(
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);
@ -935,8 +927,8 @@ ast::type::Type* ParserImpl::ConvertType(
ast_storage_class = ast::StorageClass::kStorageBuffer;
remap_buffer_block_type_.insert(type_id);
}
return ast_module_.type_mgr().Get(
std::make_unique<ast::type::PointerType>(ast_elem_ty, ast_storage_class));
return ast_module_.create<ast::type::PointerType>(ast_elem_ty,
ast_storage_class);
}
bool ParserImpl::RegisterTypes() {
@ -1065,10 +1057,8 @@ void ParserImpl::MaybeGenerateAlias(uint32_t type_id,
return;
}
const auto name = namer_.GetName(type_id);
auto* ast_alias_type = ast_module_.type_mgr()
.Get(std::make_unique<ast::type::AliasType>(
name, ast_underlying_type))
->AsAlias();
auto* ast_alias_type =
ast_module_.create<ast::type::AliasType>(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);
@ -1169,8 +1159,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_.type_mgr().Get(
std::make_unique<ast::type::AccessControlType>(access, type));
type = ast_module_.create<ast::type::AccessControlType>(access, type);
}
auto* ast_var = create<ast::Variable>(namer_.Name(id), sc, type);
@ -1363,9 +1352,8 @@ ast::Expression* ParserImpl::MakeNullValue(ast::type::Type* type) {
if (type->IsMatrix()) {
const auto* mat_ty = type->AsMatrix();
// Matrix components are columns
auto* column_ty =
ast_module_.type_mgr().Get(std::make_unique<ast::type::VectorType>(
mat_ty->type(), mat_ty->rows()));
auto* column_ty = ast_module_.create<ast::type::VectorType>(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));
@ -1446,15 +1434,13 @@ ast::type::Type* ParserImpl::GetSignedIntMatchingShape(ast::type::Type* other) {
if (other == nullptr) {
Fail() << "no type provided";
}
auto* i32 =
ast_module_.type_mgr().Get(std::make_unique<ast::type::I32Type>());
auto* i32 = ast_module_.create<ast::type::I32Type>();
if (other->IsF32() || other->IsU32() || other->IsI32()) {
return i32;
}
auto* vec_ty = other->AsVector();
if (vec_ty) {
return ast_module_.type_mgr().Get(
std::make_unique<ast::type::VectorType>(i32, vec_ty->size()));
return ast_module_.create<ast::type::VectorType>(i32, vec_ty->size());
}
Fail() << "required numeric scalar or vector, but got " << other->type_name();
return nullptr;
@ -1466,15 +1452,13 @@ ast::type::Type* ParserImpl::GetUnsignedIntMatchingShape(
Fail() << "no type provided";
return nullptr;
}
auto* u32 =
ast_module_.type_mgr().Get(std::make_unique<ast::type::U32Type>());
auto* u32 = ast_module_.create<ast::type::U32Type>();
if (other->IsF32() || other->IsU32() || other->IsI32()) {
return u32;
}
auto* vec_ty = other->AsVector();
if (vec_ty) {
return ast_module_.type_mgr().Get(
std::make_unique<ast::type::VectorType>(u32, vec_ty->size()));
return ast_module_.create<ast::type::VectorType>(u32, vec_ty->size());
}
Fail() << "required numeric scalar or vector, but got " << other->type_name();
return nullptr;
@ -1632,11 +1616,9 @@ ast::type::Type* ParserImpl::GetTypeForHandleVar(
}
ast::type::Type* ast_store_type = nullptr;
if (usage.IsSampler()) {
ast_store_type =
ast_module_.type_mgr().Get(std::make_unique<ast::type::SamplerType>(
usage.IsComparisonSampler()
? ast::type::SamplerKind::kComparisonSampler
: ast::type::SamplerKind::kSampler));
ast_store_type = ast_module_.create<ast::type::SamplerType>(
usage.IsComparisonSampler() ? ast::type::SamplerKind::kComparisonSampler
: ast::type::SamplerKind::kSampler);
} else if (usage.IsTexture()) {
const auto* ptr_type = def_use_mgr_->GetDef(var.type_id());
if (!ptr_type) {
@ -1689,17 +1671,14 @@ ast::type::Type* 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_.type_mgr().Get(
std::make_unique<ast::type::DepthTextureType>(dim));
ast_store_type = ast_module_.create<ast::type::DepthTextureType>(dim);
} else if (image_type->is_multisampled()) {
// Multisampled textures are never depth textures.
ast_store_type = ast_module_.type_mgr().Get(
std::make_unique<ast::type::MultisampledTextureType>(
dim, ast_sampled_component_type));
ast_store_type = ast_module_.create<ast::type::MultisampledTextureType>(
dim, ast_sampled_component_type);
} else {
ast_store_type = ast_module_.type_mgr().Get(
std::make_unique<ast::type::SampledTextureType>(
dim, ast_sampled_component_type));
ast_store_type = ast_module_.create<ast::type::SampledTextureType>(
dim, ast_sampled_component_type);
}
} else {
// Make a storage texture.
@ -1731,8 +1710,8 @@ ast::type::Type* ParserImpl::GetTypeForHandleVar(
if (format == ast::type::ImageFormat::kNone) {
return nullptr;
}
ast_store_type = ast_module_.type_mgr().Get(
std::make_unique<ast::type::StorageTextureType>(dim, access, format));
ast_store_type = ast_module_.create<ast::type::StorageTextureType>(
dim, access, format);
}
} else {
Fail() << "unsupported: UniformConstant variable is not a recognized "
@ -1741,8 +1720,8 @@ ast::type::Type* ParserImpl::GetTypeForHandleVar(
return nullptr;
}
// Form the pointer type.
return ast_module_.type_mgr().Get(std::make_unique<ast::type::PointerType>(
ast_store_type, ast::StorageClass::kUniformConstant));
return ast_module_.create<ast::type::PointerType>(
ast_store_type, ast::StorageClass::kUniformConstant);
}
bool ParserImpl::RegisterHandleUsage() {

View File

@ -308,7 +308,7 @@ Expect<bool> ParserImpl::expect_global_decl() {
if (!expect("struct declaration", Token::Type::kSemicolon))
return Failure::kErrored;
auto* type = module_.type_mgr().Get(std::move(str.value));
auto* type = module_.unique_type(std::move(str.value));
register_constructed(type->AsStruct()->name(), type);
module_.AddConstructedType(type);
return true;
@ -462,9 +462,8 @@ Maybe<ast::type::Type*> ParserImpl::texture_sampler_types() {
if (subtype.errored)
return Failure::kErrored;
return module_.type_mgr().Get(
std::make_unique<ast::type::SampledTextureType>(dim.value,
subtype.value));
return module_.create<ast::type::SampledTextureType>(dim.value,
subtype.value);
}
auto ms_dim = multisampled_texture_type();
@ -475,9 +474,8 @@ Maybe<ast::type::Type*> ParserImpl::texture_sampler_types() {
if (subtype.errored)
return Failure::kErrored;
return module_.type_mgr().Get(
std::make_unique<ast::type::MultisampledTextureType>(ms_dim.value,
subtype.value));
return module_.create<ast::type::MultisampledTextureType>(ms_dim.value,
subtype.value);
}
auto storage = storage_texture_type();
@ -490,9 +488,8 @@ Maybe<ast::type::Type*> ParserImpl::texture_sampler_types() {
if (format.errored)
return Failure::kErrored;
return module_.type_mgr().Get(
std::make_unique<ast::type::StorageTextureType>(
storage->first, storage->second, format.value));
return module_.create<ast::type::StorageTextureType>(
storage->first, storage->second, format.value);
}
return Failure::kNoMatch;
@ -503,12 +500,12 @@ Maybe<ast::type::Type*> ParserImpl::texture_sampler_types() {
// | SAMPLER_COMPARISON
Maybe<ast::type::Type*> ParserImpl::sampler_type() {
if (match(Token::Type::kSampler))
return module_.type_mgr().Get(std::make_unique<ast::type::SamplerType>(
ast::type::SamplerKind::kSampler));
return module_.create<ast::type::SamplerType>(
ast::type::SamplerKind::kSampler);
if (match(Token::Type::kComparisonSampler))
return module_.type_mgr().Get(std::make_unique<ast::type::SamplerType>(
ast::type::SamplerKind::kComparisonSampler));
return module_.create<ast::type::SamplerType>(
ast::type::SamplerKind::kComparisonSampler);
return Failure::kNoMatch;
}
@ -636,20 +633,20 @@ ParserImpl::storage_texture_type() {
// | TEXTURE_DEPTH_CUBE_ARRAY
Maybe<ast::type::Type*> ParserImpl::depth_texture_type() {
if (match(Token::Type::kTextureDepth2d))
return module_.type_mgr().Get(std::make_unique<ast::type::DepthTextureType>(
ast::type::TextureDimension::k2d));
return module_.create<ast::type::DepthTextureType>(
ast::type::TextureDimension::k2d);
if (match(Token::Type::kTextureDepth2dArray))
return module_.type_mgr().Get(std::make_unique<ast::type::DepthTextureType>(
ast::type::TextureDimension::k2dArray));
return module_.create<ast::type::DepthTextureType>(
ast::type::TextureDimension::k2dArray);
if (match(Token::Type::kTextureDepthCube))
return module_.type_mgr().Get(std::make_unique<ast::type::DepthTextureType>(
ast::type::TextureDimension::kCube));
return module_.create<ast::type::DepthTextureType>(
ast::type::TextureDimension::kCube);
if (match(Token::Type::kTextureDepthCubeArray))
return module_.type_mgr().Get(std::make_unique<ast::type::DepthTextureType>(
ast::type::TextureDimension::kCubeArray));
return module_.create<ast::type::DepthTextureType>(
ast::type::TextureDimension::kCubeArray);
return Failure::kNoMatch;
}
@ -834,8 +831,8 @@ 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_.type_mgr().Get(std::make_unique<ast::type::AccessControlType>(
deco->AsAccess()->value(), ty));
ty = module_.create<ast::type::AccessControlType>(deco->AsAccess()->value(),
ty);
}
return TypedIdentifier{ty, ident.value, ident.source};
@ -894,8 +891,7 @@ Maybe<ast::type::Type*> ParserImpl::type_alias() {
if (!type.matched)
return add_error(peek(), "invalid type alias");
auto* alias = module_.type_mgr().Get(
std::make_unique<ast::type::AliasType>(name.value, type.value));
auto* alias = module_.create<ast::type::AliasType>(name.value, type.value);
register_constructed(name.value, alias);
return alias->AsAlias();
@ -953,16 +949,16 @@ Maybe<ast::type::Type*> ParserImpl::type_decl(ast::DecorationList& decos) {
}
if (match(Token::Type::kBool))
return module_.type_mgr().Get(std::make_unique<ast::type::BoolType>());
return module_.create<ast::type::BoolType>();
if (match(Token::Type::kF32))
return module_.type_mgr().Get(std::make_unique<ast::type::F32Type>());
return module_.create<ast::type::F32Type>();
if (match(Token::Type::kI32))
return module_.type_mgr().Get(std::make_unique<ast::type::I32Type>());
return module_.create<ast::type::I32Type>();
if (match(Token::Type::kU32))
return module_.type_mgr().Get(std::make_unique<ast::type::U32Type>());
return module_.create<ast::type::U32Type>();
if (t.IsVec2() || t.IsVec3() || t.IsVec4()) {
next(); // Consume the peek
@ -1020,8 +1016,7 @@ Expect<ast::type::Type*> ParserImpl::expect_type_decl_pointer() {
if (subtype.errored)
return Failure::kErrored;
return module_.type_mgr().Get(
std::make_unique<ast::type::PointerType>(subtype.value, sc.value));
return module_.create<ast::type::PointerType>(subtype.value, sc.value);
});
}
@ -1038,8 +1033,7 @@ Expect<ast::type::Type*> ParserImpl::expect_type_decl_vector(Token t) {
if (subtype.errored)
return Failure::kErrored;
return module_.type_mgr().Get(
std::make_unique<ast::type::VectorType>(subtype.value, count));
return module_.create<ast::type::VectorType>(subtype.value, count);
}
Expect<ast::type::Type*> ParserImpl::expect_type_decl_array(
@ -1061,7 +1055,7 @@ Expect<ast::type::Type*> ParserImpl::expect_type_decl_array(
auto ty = std::make_unique<ast::type::ArrayType>(subtype.value, size);
ty->set_decorations(std::move(decos));
return module_.type_mgr().Get(std::move(ty));
return module_.unique_type(std::move(ty));
});
}
@ -1085,8 +1079,7 @@ Expect<ast::type::Type*> ParserImpl::expect_type_decl_matrix(Token t) {
if (subtype.errored)
return Failure::kErrored;
return module_.type_mgr().Get(
std::make_unique<ast::type::MatrixType>(subtype.value, rows, columns));
return module_.create<ast::type::MatrixType>(subtype.value, rows, columns);
}
// storage_class
@ -1254,7 +1247,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_.type_mgr().Get(std::make_unique<ast::type::VoidType>());
return module_.create<ast::type::VoidType>();
return type_decl();
}
@ -2613,25 +2606,23 @@ Maybe<ast::AssignmentStatement*> ParserImpl::assignment_stmt() {
Maybe<ast::Literal*> ParserImpl::const_literal() {
auto t = peek();
if (match(Token::Type::kTrue)) {
auto* type =
module_.type_mgr().Get(std::make_unique<ast::type::BoolType>());
auto* type = module_.create<ast::type::BoolType>();
return create<ast::BoolLiteral>(type, true);
}
if (match(Token::Type::kFalse)) {
auto* type =
module_.type_mgr().Get(std::make_unique<ast::type::BoolType>());
auto* type = module_.create<ast::type::BoolType>();
return create<ast::BoolLiteral>(type, false);
}
if (match(Token::Type::kSintLiteral)) {
auto* type = module_.type_mgr().Get(std::make_unique<ast::type::I32Type>());
auto* type = module_.create<ast::type::I32Type>();
return create<ast::SintLiteral>(type, t.to_i32());
}
if (match(Token::Type::kUintLiteral)) {
auto* type = module_.type_mgr().Get(std::make_unique<ast::type::U32Type>());
auto* type = module_.create<ast::type::U32Type>();
return create<ast::UintLiteral>(type, t.to_u32());
}
if (match(Token::Type::kFloatLiteral)) {
auto* type = module_.type_mgr().Get(std::make_unique<ast::type::F32Type>());
auto* type = module_.create<ast::type::F32Type>();
return create<ast::FloatLiteral>(type, t.to_f32());
}
return Failure::kNoMatch;

View File

@ -30,7 +30,7 @@ TEST_F(ParserImplTest, FunctionTypeDecl_Void) {
auto p = parser("void");
auto& mod = p->get_module();
auto* v = mod.type_mgr().Get(std::make_unique<ast::type::VoidType>());
auto* v = mod.create<ast::type::VoidType>();
auto e = p->function_type_decl();
EXPECT_TRUE(e.matched);
@ -43,9 +43,8 @@ TEST_F(ParserImplTest, FunctionTypeDecl_Type) {
auto p = parser("vec2<f32>");
auto& mod = p->get_module();
auto* f32 = mod.type_mgr().Get(std::make_unique<ast::type::F32Type>());
auto* vec2 =
mod.type_mgr().Get(std::make_unique<ast::type::VectorType>(f32, 2));
auto* f32 = mod.create<ast::type::F32Type>();
auto* vec2 = mod.create<ast::type::VectorType>(f32, 2);
auto e = p->function_type_decl();
EXPECT_TRUE(e.matched);

View File

@ -31,7 +31,7 @@ TEST_F(ParserImplTest, ParamList_Single) {
auto p = parser("a : i32");
auto& mod = p->get_module();
auto* i32 = mod.type_mgr().Get(std::make_unique<ast::type::I32Type>());
auto* i32 = mod.create<ast::type::I32Type>();
auto e = p->expect_param_list();
ASSERT_FALSE(p->has_error()) << p->error();
@ -52,10 +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.type_mgr().Get(std::make_unique<ast::type::I32Type>());
auto* f32 = mod.type_mgr().Get(std::make_unique<ast::type::F32Type>());
auto* vec2 =
mod.type_mgr().Get(std::make_unique<ast::type::VectorType>(f32, 2));
auto* i32 = mod.create<ast::type::I32Type>();
auto* f32 = mod.create<ast::type::F32Type>();
auto* vec2 = mod.create<ast::type::VectorType>(f32, 2);
auto e = p->expect_param_list();
ASSERT_FALSE(p->has_error()) << p->error();

View File

@ -193,7 +193,7 @@ TEST_F(ParserImplTest, PrimaryExpression_Cast) {
auto p = parser("f32(1)");
auto& mod = p->get_module();
auto* f32 = mod.type_mgr().Get(std::make_unique<ast::type::F32Type>());
auto* f32 = mod.create<ast::type::F32Type>();
auto e = p->primary_expression();
EXPECT_TRUE(e.matched);
@ -215,7 +215,7 @@ TEST_F(ParserImplTest, PrimaryExpression_Bitcast) {
auto p = parser("bitcast<f32>(1)");
auto& mod = p->get_module();
auto* f32 = mod.type_mgr().Get(std::make_unique<ast::type::F32Type>());
auto* f32 = mod.create<ast::type::F32Type>();
auto e = p->primary_expression();
EXPECT_TRUE(e.matched);

View File

@ -26,7 +26,7 @@ TEST_F(ParserImplTest, StructBodyDecl_Parses) {
auto p = parser("{a : i32;}");
auto& mod = p->get_module();
auto* i32 = mod.type_mgr().Get(std::make_unique<ast::type::I32Type>());
auto* i32 = mod.create<ast::type::I32Type>();
auto m = p->expect_struct_body_decl();
ASSERT_FALSE(p->has_error());

View File

@ -27,7 +27,7 @@ TEST_F(ParserImplTest, StructMember_Parses) {
auto p = parser("a : i32;");
auto& mod = p->get_module();
auto* i32 = mod.type_mgr().Get(std::make_unique<ast::type::I32Type>());
auto* i32 = mod.create<ast::type::I32Type>();
auto decos = p->decoration_list();
EXPECT_FALSE(decos.errored);
@ -53,7 +53,7 @@ TEST_F(ParserImplTest, StructMember_ParsesWithDecoration) {
auto p = parser("[[offset(2)]] a : i32;");
auto& mod = p->get_module();
auto* i32 = mod.type_mgr().Get(std::make_unique<ast::type::I32Type>());
auto* i32 = mod.create<ast::type::I32Type>();
auto decos = p->decoration_list();
EXPECT_FALSE(decos.errored);
@ -82,7 +82,7 @@ TEST_F(ParserImplTest, StructMember_ParsesWithMultipleDecorations) {
[[offset(4)]] a : i32;)");
auto& mod = p->get_module();
auto* i32 = mod.type_mgr().Get(std::make_unique<ast::type::I32Type>());
auto* i32 = mod.create<ast::type::I32Type>();
auto decos = p->decoration_list();
EXPECT_FALSE(decos.errored);

View File

@ -29,7 +29,7 @@ TEST_F(ParserImplTest, TypeDecl_ParsesType) {
auto p = parser("type a = i32");
auto& mod = p->get_module();
auto* i32 = mod.type_mgr().Get(std::make_unique<ast::type::I32Type>());
auto* i32 = mod.create<ast::type::I32Type>();
auto t = p->type_alias();
EXPECT_FALSE(p->has_error());

View File

@ -48,9 +48,8 @@ TEST_F(ParserImplTest, TypeDecl_Identifier) {
auto& mod = p->get_module();
auto* int_type = mod.type_mgr().Get(std::make_unique<ast::type::I32Type>());
auto* alias_type =
mod.type_mgr().Get(std::make_unique<ast::type::AliasType>("A", int_type));
auto* int_type = mod.create<ast::type::I32Type>();
auto* alias_type = mod.create<ast::type::AliasType>("A", int_type);
p->register_constructed("A", alias_type);
@ -81,7 +80,7 @@ TEST_F(ParserImplTest, TypeDecl_Bool) {
auto p = parser("bool");
auto& mod = p->get_module();
auto* bool_type = mod.type_mgr().Get(std::make_unique<ast::type::BoolType>());
auto* bool_type = mod.create<ast::type::BoolType>();
auto t = p->type_decl();
EXPECT_TRUE(t.matched);
@ -95,7 +94,7 @@ TEST_F(ParserImplTest, TypeDecl_F32) {
auto p = parser("f32");
auto& mod = p->get_module();
auto* float_type = mod.type_mgr().Get(std::make_unique<ast::type::F32Type>());
auto* float_type = mod.create<ast::type::F32Type>();
auto t = p->type_decl();
EXPECT_TRUE(t.matched);
@ -109,7 +108,7 @@ TEST_F(ParserImplTest, TypeDecl_I32) {
auto p = parser("i32");
auto& mod = p->get_module();
auto* int_type = mod.type_mgr().Get(std::make_unique<ast::type::I32Type>());
auto* int_type = mod.create<ast::type::I32Type>();
auto t = p->type_decl();
EXPECT_TRUE(t.matched);
@ -123,7 +122,7 @@ TEST_F(ParserImplTest, TypeDecl_U32) {
auto p = parser("u32");
auto& mod = p->get_module();
auto* uint_type = mod.type_mgr().Get(std::make_unique<ast::type::U32Type>());
auto* uint_type = mod.create<ast::type::U32Type>();
auto t = p->type_decl();
EXPECT_TRUE(t.matched);
@ -740,8 +739,8 @@ TEST_F(ParserImplTest, TypeDecl_Sampler) {
auto p = parser("sampler");
auto& mod = p->get_module();
auto* type = mod.type_mgr().Get(std::make_unique<ast::type::SamplerType>(
ast::type::SamplerKind::kSampler));
auto* type =
mod.create<ast::type::SamplerType>(ast::type::SamplerKind::kSampler);
auto t = p->type_decl();
EXPECT_TRUE(t.matched);
@ -757,9 +756,8 @@ TEST_F(ParserImplTest, TypeDecl_Texture_Old) {
auto& mod = p->get_module();
ast::type::F32Type f32;
auto* type =
mod.type_mgr().Get(std::make_unique<ast::type::SampledTextureType>(
ast::type::TextureDimension::kCube, &f32));
auto* type = mod.create<ast::type::SampledTextureType>(
ast::type::TextureDimension::kCube, &f32);
auto t = p->type_decl();
EXPECT_TRUE(t.matched);
@ -776,9 +774,8 @@ TEST_F(ParserImplTest, TypeDecl_Texture) {
ast::type::F32Type f32;
auto& mod = p->get_module();
auto* type =
mod.type_mgr().Get(std::make_unique<ast::type::SampledTextureType>(
ast::type::TextureDimension::kCube, &f32));
auto* type = mod.create<ast::type::SampledTextureType>(
ast::type::TextureDimension::kCube, &f32);
auto t = p->type_decl();
EXPECT_TRUE(t.matched);

View File

@ -237,7 +237,7 @@ bool BoundArrayAccessorsTransform::ProcessAccessExpression(
return false;
}
} else {
auto* u32 = mod_->type_mgr().Get(std::make_unique<ast::type::U32Type>());
auto* u32 = mod_->create<ast::type::U32Type>();
ast::ExpressionList cast_expr;
cast_expr.push_back(expr->idx_expr());

View File

@ -222,7 +222,7 @@ void VertexPullingTransform::AddVertexStorageBuffers() {
ary_decos.push_back(create<ast::StrideDecoration>(4u, Source{}));
internal_array->set_decorations(std::move(ary_decos));
auto* internal_array_type = mod_->type_mgr().Get(std::move(internal_array));
auto* internal_array_type = mod_->unique_type(std::move(internal_array));
// Creating the struct type
ast::StructMemberList members;
@ -235,10 +235,8 @@ void VertexPullingTransform::AddVertexStorageBuffers() {
ast::StructDecorationList decos;
decos.push_back(create<ast::StructBlockDecoration>(Source{}));
auto* struct_type =
mod_->type_mgr().Get(std::make_unique<ast::type::StructType>(
kStructName,
create<ast::Struct>(std::move(decos), std::move(members))));
auto* struct_type = mod_->create<ast::type::StructType>(
kStructName, create<ast::Struct>(std::move(decos), std::move(members)));
for (uint32_t i = 0; i < vertex_state_->vertex_buffers.size(); ++i) {
// The decorated variable with struct type
@ -411,21 +409,20 @@ ast::Expression* VertexPullingTransform::AccessVec(uint32_t buffer,
}
return create<ast::TypeConstructorExpression>(
mod_->type_mgr().Get(
std::make_unique<ast::type::VectorType>(base_type, count)),
mod_->create<ast::type::VectorType>(base_type, count),
std::move(expr_list));
}
ast::type::Type* VertexPullingTransform::GetU32Type() {
return mod_->type_mgr().Get(std::make_unique<ast::type::U32Type>());
return mod_->create<ast::type::U32Type>();
}
ast::type::Type* VertexPullingTransform::GetI32Type() {
return mod_->type_mgr().Get(std::make_unique<ast::type::I32Type>());
return mod_->create<ast::type::I32Type>();
}
ast::type::Type* VertexPullingTransform::GetF32Type() {
return mod_->type_mgr().Get(std::make_unique<ast::type::F32Type>());
return mod_->create<ast::type::F32Type>();
}
VertexBufferLayoutDescriptor::VertexBufferLayoutDescriptor() = default;

View File

@ -46,10 +46,9 @@ class VertexPullingTransformHelper {
// Create basic module with an entry point and vertex function
void InitBasicModule() {
auto* func = create<ast::Function>(
"main", ast::VariableList{},
mod_->type_mgr().Get(std::make_unique<ast::type::VoidType>()),
create<ast::BlockStatement>());
auto* func = create<ast::Function>("main", ast::VariableList{},
mod_->create<ast::type::VoidType>(),
create<ast::BlockStatement>());
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(func);
@ -125,10 +124,9 @@ TEST_F(VertexPullingTransformTest, Error_InvalidEntryPoint) {
}
TEST_F(VertexPullingTransformTest, Error_EntryPointWrongStage) {
auto* func = create<ast::Function>(
"main", ast::VariableList{},
mod()->type_mgr().Get(std::make_unique<ast::type::VoidType>()),
create<ast::BlockStatement>());
auto* func = create<ast::Function>("main", ast::VariableList{},
mod()->create<ast::type::VoidType>(),
create<ast::BlockStatement>());
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
mod()->AddFunction(func);

View File

@ -83,7 +83,7 @@ void TypeDeterminer::set_referenced_from_function_if_needed(
}
bool TypeDeterminer::Determine() {
for (auto& iter : mod_->type_mgr().types()) {
for (auto& iter : mod_->types()) {
auto& type = iter.second;
if (!type->IsTexture() || !type->AsTexture()->IsStorage()) {
continue;
@ -339,8 +339,7 @@ bool TypeDeterminer::DetermineArrayAccessor(
ret = parent_type->AsVector()->type();
} else if (parent_type->IsMatrix()) {
auto* m = parent_type->AsMatrix();
ret = mod_->type_mgr().Get(
std::make_unique<ast::type::VectorType>(m->type(), m->rows()));
ret = mod_->create<ast::type::VectorType>(m->type(), m->rows());
} else {
set_error(expr->source(), "invalid parent type (" +
parent_type->type_name() +
@ -350,15 +349,15 @@ bool TypeDeterminer::DetermineArrayAccessor(
// If we're extracting from a pointer, we return a pointer.
if (res->IsPointer()) {
ret = mod_->type_mgr().Get(std::make_unique<ast::type::PointerType>(
ret, res->AsPointer()->storage_class()));
ret = mod_->create<ast::type::PointerType>(
ret, res->AsPointer()->storage_class());
} else if (parent_type->IsArray() &&
!parent_type->AsArray()->type()->is_scalar()) {
// If we extract a non-scalar from an array then we also get a pointer. We
// will generate a Function storage class variable to store this
// into.
ret = mod_->type_mgr().Get(std::make_unique<ast::type::PointerType>(
ret, ast::StorageClass::kFunction));
ret =
mod_->create<ast::type::PointerType>(ret, ast::StorageClass::kFunction);
}
expr->set_result_type(ret);
@ -522,13 +521,11 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
}
if (ident->intrinsic() == ast::Intrinsic::kAny ||
ident->intrinsic() == ast::Intrinsic::kAll) {
expr->func()->set_result_type(
mod_->type_mgr().Get(std::make_unique<ast::type::BoolType>()));
expr->func()->set_result_type(mod_->create<ast::type::BoolType>());
return true;
}
if (ident->intrinsic() == ast::Intrinsic::kArrayLength) {
expr->func()->set_result_type(
mod_->type_mgr().Get(std::make_unique<ast::type::U32Type>()));
expr->func()->set_result_type(mod_->create<ast::type::U32Type>());
return true;
}
if (ast::intrinsic::IsFloatClassificationIntrinsic(ident->intrinsic())) {
@ -538,14 +535,12 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
return false;
}
auto* bool_type =
mod_->type_mgr().Get(std::make_unique<ast::type::BoolType>());
auto* bool_type = mod_->create<ast::type::BoolType>();
auto* param_type = expr->params()[0]->result_type()->UnwrapPtrIfNeeded();
if (param_type->IsVector()) {
expr->func()->set_result_type(
mod_->type_mgr().Get(std::make_unique<ast::type::VectorType>(
bool_type, param_type->AsVector()->size())));
expr->func()->set_result_type(mod_->create<ast::type::VectorType>(
bool_type, param_type->AsVector()->size()));
} else {
expr->func()->set_result_type(bool_type);
}
@ -666,8 +661,7 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
std::make_unique<ast::intrinsic::TextureSignature>(param));
if (texture->IsDepth()) {
expr->func()->set_result_type(
mod_->type_mgr().Get(std::make_unique<ast::type::F32Type>()));
expr->func()->set_result_type(mod_->create<ast::type::F32Type>());
return true;
}
@ -688,13 +682,11 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
set_error(expr->source(), "unknown texture type for texture sampling");
return false;
}
expr->func()->set_result_type(
mod_->type_mgr().Get(std::make_unique<ast::type::VectorType>(type, 4)));
expr->func()->set_result_type(mod_->create<ast::type::VectorType>(type, 4));
return true;
}
if (ident->intrinsic() == ast::Intrinsic::kDot) {
expr->func()->set_result_type(
mod_->type_mgr().Get(std::make_unique<ast::type::F32Type>()));
expr->func()->set_result_type(mod_->create<ast::type::F32Type>());
return true;
}
if (ident->intrinsic() == ast::Intrinsic::kOuterProduct) {
@ -711,10 +703,9 @@ bool TypeDeterminer::DetermineIntrinsic(ast::IdentifierExpression* ident,
return false;
}
expr->func()->set_result_type(
mod_->type_mgr().Get(std::make_unique<ast::type::MatrixType>(
mod_->type_mgr().Get(std::make_unique<ast::type::F32Type>()),
param0_type->AsVector()->size(), param1_type->AsVector()->size())));
expr->func()->set_result_type(mod_->create<ast::type::MatrixType>(
mod_->create<ast::type::F32Type>(), param0_type->AsVector()->size(),
param1_type->AsVector()->size()));
return true;
}
if (ident->intrinsic() == ast::Intrinsic::kSelect) {
@ -861,9 +852,8 @@ bool TypeDeterminer::DetermineIdentifier(ast::IdentifierExpression* expr) {
} else if (var->type()->IsPointer()) {
expr->set_result_type(var->type());
} else {
expr->set_result_type(
mod_->type_mgr().Get(std::make_unique<ast::type::PointerType>(
var->type(), var->storage_class())));
expr->set_result_type(mod_->create<ast::type::PointerType>(
var->type(), var->storage_class()));
}
set_referenced_from_function_if_needed(var);
@ -1055,8 +1045,8 @@ bool TypeDeterminer::DetermineMemberAccessor(
// If we're extracting from a pointer, we return a pointer.
if (res->IsPointer()) {
ret = mod_->type_mgr().Get(std::make_unique<ast::type::PointerType>(
ret, res->AsPointer()->storage_class()));
ret = mod_->create<ast::type::PointerType>(
ret, res->AsPointer()->storage_class());
}
} else if (data_type->IsVector()) {
auto* vec = data_type->AsVector();
@ -1067,15 +1057,14 @@ bool TypeDeterminer::DetermineMemberAccessor(
ret = vec->type();
// If we're extracting from a pointer, we return a pointer.
if (res->IsPointer()) {
ret = mod_->type_mgr().Get(std::make_unique<ast::type::PointerType>(
ret, res->AsPointer()->storage_class()));
ret = mod_->create<ast::type::PointerType>(
ret, res->AsPointer()->storage_class());
}
} else {
// The vector will have a number of components equal to the length of the
// swizzle. This assumes the validator will check that the swizzle
// is correct.
ret = mod_->type_mgr().Get(
std::make_unique<ast::type::VectorType>(vec->type(), size));
ret = mod_->create<ast::type::VectorType>(vec->type(), size);
}
} else {
set_error(
@ -1106,13 +1095,11 @@ bool TypeDeterminer::DetermineBinary(ast::BinaryExpression* expr) {
if (expr->IsLogicalAnd() || expr->IsLogicalOr() || expr->IsEqual() ||
expr->IsNotEqual() || expr->IsLessThan() || expr->IsGreaterThan() ||
expr->IsLessThanEqual() || expr->IsGreaterThanEqual()) {
auto* bool_type =
mod_->type_mgr().Get(std::make_unique<ast::type::BoolType>());
auto* bool_type = mod_->create<ast::type::BoolType>();
auto* param_type = expr->lhs()->result_type()->UnwrapPtrIfNeeded();
if (param_type->IsVector()) {
expr->set_result_type(
mod_->type_mgr().Get(std::make_unique<ast::type::VectorType>(
bool_type, param_type->AsVector()->size())));
expr->set_result_type(mod_->create<ast::type::VectorType>(
bool_type, param_type->AsVector()->size()));
} else {
expr->set_result_type(bool_type);
}
@ -1125,20 +1112,18 @@ bool TypeDeterminer::DetermineBinary(ast::BinaryExpression* expr) {
// Note, the ordering here matters. The later checks depend on the prior
// checks having been done.
if (lhs_type->IsMatrix() && rhs_type->IsMatrix()) {
expr->set_result_type(
mod_->type_mgr().Get(std::make_unique<ast::type::MatrixType>(
lhs_type->AsMatrix()->type(), lhs_type->AsMatrix()->rows(),
rhs_type->AsMatrix()->columns())));
expr->set_result_type(mod_->create<ast::type::MatrixType>(
lhs_type->AsMatrix()->type(), lhs_type->AsMatrix()->rows(),
rhs_type->AsMatrix()->columns()));
} else if (lhs_type->IsMatrix() && rhs_type->IsVector()) {
auto* mat = lhs_type->AsMatrix();
expr->set_result_type(mod_->type_mgr().Get(
std::make_unique<ast::type::VectorType>(mat->type(), mat->rows())));
expr->set_result_type(
mod_->create<ast::type::VectorType>(mat->type(), mat->rows()));
} else if (lhs_type->IsVector() && rhs_type->IsMatrix()) {
auto* mat = rhs_type->AsMatrix();
expr->set_result_type(
mod_->type_mgr().Get(std::make_unique<ast::type::VectorType>(
mat->type(), mat->columns())));
mod_->create<ast::type::VectorType>(mat->type(), mat->columns()));
} else if (lhs_type->IsMatrix()) {
// matrix * scalar
expr->set_result_type(lhs_type);
@ -1197,8 +1182,7 @@ bool TypeDeterminer::DetermineStorageTextureSubtype(
case ast::type::ImageFormat::kRg32Uint:
case ast::type::ImageFormat::kRgba16Uint:
case ast::type::ImageFormat::kRgba32Uint: {
tex->set_type(
mod_->type_mgr().Get(std::make_unique<ast::type::U32Type>()));
tex->set_type(mod_->create<ast::type::U32Type>());
return true;
}
@ -1214,8 +1198,7 @@ bool TypeDeterminer::DetermineStorageTextureSubtype(
case ast::type::ImageFormat::kRg32Sint:
case ast::type::ImageFormat::kRgba16Sint:
case ast::type::ImageFormat::kRgba32Sint: {
tex->set_type(
mod_->type_mgr().Get(std::make_unique<ast::type::I32Type>()));
tex->set_type(mod_->create<ast::type::I32Type>());
return true;
}
@ -1226,8 +1209,7 @@ bool TypeDeterminer::DetermineStorageTextureSubtype(
case ast::type::ImageFormat::kRg32Float:
case ast::type::ImageFormat::kRgba16Float:
case ast::type::ImageFormat::kRgba32Float: {
tex->set_type(
mod_->type_mgr().Get(std::make_unique<ast::type::F32Type>()));
tex->set_type(mod_->create<ast::type::F32Type>());
return true;
}

View File

@ -1786,9 +1786,8 @@ TEST_P(Intrinsic_StorageTextureOperation, TextureLoadRo) {
ast::type::I32Type i32;
auto coords_type = get_coords_type(dim, &i32);
ast::type::Type* texture_type =
mod->type_mgr().Get(std::make_unique<ast::type::StorageTextureType>(
dim, ast::AccessControl::kReadOnly, format));
ast::type::Type* texture_type = mod->create<ast::type::StorageTextureType>(
dim, ast::AccessControl::kReadOnly, format);
ast::ExpressionList call_params;
@ -4549,14 +4548,13 @@ TEST_P(TypeDeterminerTextureIntrinsicTest, Call) {
switch (param.texture_kind) {
case ast::intrinsic::test::TextureKind::kRegular:
Var("texture", ast::StorageClass::kNone,
mod->type_mgr().Get<ast::type::SampledTextureType>(
param.texture_dimension, datatype));
mod->create<ast::type::SampledTextureType>(param.texture_dimension,
datatype));
break;
case ast::intrinsic::test::TextureKind::kDepth:
Var("texture", ast::StorageClass::kNone,
mod->type_mgr().Get<ast::type::DepthTextureType>(
param.texture_dimension));
mod->create<ast::type::DepthTextureType>(param.texture_dimension));
break;
}

View File

@ -183,14 +183,13 @@ TEST_P(HlslGeneratorIntrinsicTextureTest, Call) {
switch (param.texture_kind) {
case ast::intrinsic::test::TextureKind::kRegular:
Var("texture", ast::StorageClass::kNone,
mod->type_mgr().Get<ast::type::SampledTextureType>(
param.texture_dimension, datatype));
mod->create<ast::type::SampledTextureType>(param.texture_dimension,
datatype));
break;
case ast::intrinsic::test::TextureKind::kDepth:
Var("texture", ast::StorageClass::kNone,
mod->type_mgr().Get<ast::type::DepthTextureType>(
param.texture_dimension));
mod->create<ast::type::DepthTextureType>(param.texture_dimension));
break;
}

View File

@ -1618,14 +1618,14 @@ TEST_P(IntrinsicTextureTest, Call) {
switch (param.texture_kind) {
case ast::intrinsic::test::TextureKind::kRegular:
tex = Var("texture", ast::StorageClass::kNone,
mod->type_mgr().Get<ast::type::SampledTextureType>(
mod->create<ast::type::SampledTextureType>(
param.texture_dimension, datatype));
break;
case ast::intrinsic::test::TextureKind::kDepth:
tex = Var("texture", ast::StorageClass::kNone,
mod->type_mgr().Get<ast::type::DepthTextureType>(
param.texture_dimension));
tex = Var(
"texture", ast::StorageClass::kNone,
mod->create<ast::type::DepthTextureType>(param.texture_dimension));
break;
}