From 95c2e95100ed1774f31afa521cdfad5f433dcc34 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Wed, 28 Apr 2021 12:58:13 +0000 Subject: [PATCH] ProgramBuilder: Don't wrap nullptr types Once we start migrating over to just creating `ast::Type`s instead of a AST+SEM pair, we're going to start having the sem::Type of the TypePair be nullptr. Only create composite AST / SEM types if the inner type has a non-nullptr AST / SEM type. Bug: tint:724 Change-Id: I9bec53d1be4e8dc43f5d6c86fc5f968bf61fb41e Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49344 Commit-Queue: Ben Clayton Kokoro: Kokoro Reviewed-by: Antonio Maiorano --- src/program_builder.h | 140 ++++++++++++++++++++++-------------------- 1 file changed, 74 insertions(+), 66 deletions(-) diff --git a/src/program_builder.h b/src/program_builder.h index 94f410cffd..4d6f52a13b 100644 --- a/src/program_builder.h +++ b/src/program_builder.h @@ -408,8 +408,8 @@ class ProgramBuilder { /// @param n vector width in elements /// @return the tint AST type for a `n`-element vector of `type`. typ::Vector vec(typ::Type type, uint32_t n) const { - return {builder->create(type, n), - builder->create(type, n)}; + return {type.ast ? builder->create(type, n) : nullptr, + type.sem ? builder->create(type, n) : nullptr}; } /// @param source the Source of the node @@ -417,8 +417,9 @@ class ProgramBuilder { /// @param n vector width in elements /// @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 { - return {builder->create(source, type, n), - builder->create(type, n)}; + return { + type.ast ? builder->create(source, type, n) : nullptr, + type.sem ? builder->create(type, n) : nullptr}; } /// @param type vector subtype @@ -463,8 +464,10 @@ class ProgramBuilder { /// @param rows number of rows for the matrix /// @return the tint AST type for a matrix of `type` typ::Matrix mat(typ::Type type, uint32_t columns, uint32_t rows) const { - return {builder->create(type, rows, columns), - builder->create(type, rows, columns)}; + return {type.ast ? builder->create(type, rows, columns) + : nullptr, + type.sem ? builder->create(type, rows, columns) + : nullptr}; } /// @param source the Source of the node @@ -476,72 +479,48 @@ class ProgramBuilder { typ::Type type, uint32_t columns, uint32_t rows) const { - return {builder->create(source, type, rows, columns), - builder->create(type, rows, columns)}; + return {type.ast + ? builder->create(source, type, rows, columns) + : nullptr, + type.sem ? builder->create(type, rows, columns) + : nullptr}; } /// @param type matrix subtype /// @return the tint AST type for a 2x3 matrix of `type`. - typ::Matrix mat2x2(typ::Type type) const { - return {builder->create(type, 2u, 2u), - builder->create(type, 2u, 2u)}; - } + typ::Matrix mat2x2(typ::Type type) const { return mat(type, 2u, 2u); } /// @param type matrix subtype /// @return the tint AST type for a 2x3 matrix of `type`. - typ::Matrix mat2x3(typ::Type type) const { - return {builder->create(type, 3u, 2u), - builder->create(type, 3u, 2u)}; - } + typ::Matrix mat2x3(typ::Type type) const { return mat(type, 2u, 3u); } /// @param type matrix subtype /// @return the tint AST type for a 2x4 matrix of `type`. - typ::Matrix mat2x4(typ::Type type) const { - return {builder->create(type, 4u, 2u), - builder->create(type, 4u, 2u)}; - } + typ::Matrix mat2x4(typ::Type type) const { return mat(type, 2u, 4u); } /// @param type matrix subtype /// @return the tint AST type for a 3x2 matrix of `type`. - typ::Matrix mat3x2(typ::Type type) const { - return {builder->create(type, 2u, 3u), - builder->create(type, 2u, 3u)}; - } + typ::Matrix mat3x2(typ::Type type) const { return mat(type, 3u, 2u); } /// @param type matrix subtype /// @return the tint AST type for a 3x3 matrix of `type`. - typ::Matrix mat3x3(typ::Type type) const { - return {builder->create(type, 3u, 3u), - builder->create(type, 3u, 3u)}; - } + typ::Matrix mat3x3(typ::Type type) const { return mat(type, 3u, 3u); } /// @param type matrix subtype /// @return the tint AST type for a 3x4 matrix of `type`. - typ::Matrix mat3x4(typ::Type type) const { - return {builder->create(type, 4u, 3u), - builder->create(type, 4u, 3u)}; - } + typ::Matrix mat3x4(typ::Type type) const { return mat(type, 3u, 4u); } /// @param type matrix subtype /// @return the tint AST type for a 4x2 matrix of `type`. - typ::Matrix mat4x2(typ::Type type) const { - return {builder->create(type, 2u, 4u), - builder->create(type, 2u, 4u)}; - } + typ::Matrix mat4x2(typ::Type type) const { return mat(type, 4u, 2u); } /// @param type matrix subtype /// @return the tint AST type for a 4x3 matrix of `type`. - typ::Matrix mat4x3(typ::Type type) const { - return {builder->create(type, 3u, 4u), - builder->create(type, 3u, 4u)}; - } + typ::Matrix mat4x3(typ::Type type) const { return mat(type, 4u, 3u); } /// @param type matrix subtype /// @return the tint AST type for a 4x4 matrix of `type`. - typ::Matrix mat4x4(typ::Type type) const { - return {builder->create(type, 4u, 4u), - builder->create(type, 4u, 4u)}; - } + typ::Matrix mat4x4(typ::Type type) const { return mat(type, 4u, 4u); } /// @param columns number of columns for the matrix /// @param rows number of rows for the matrix @@ -613,8 +592,11 @@ class ProgramBuilder { uint32_t n = 0, ast::DecorationList decos = {}) const { subtype = MaybeCreateTypename(subtype); - return {builder->create(subtype, n, decos), - builder->create(subtype, n, std::move(decos))}; + return {subtype.ast ? builder->create(subtype, n, decos) + : nullptr, + subtype.sem ? builder->create(subtype, n, + std::move(decos)) + : nullptr}; } /// @param source the Source of the node @@ -627,8 +609,12 @@ class ProgramBuilder { uint32_t n = 0, ast::DecorationList decos = {}) const { subtype = MaybeCreateTypename(subtype); - return {builder->create(source, subtype, n, decos), - builder->create(subtype, n, std::move(decos))}; + return { + subtype.ast ? builder->create(source, subtype, n, decos) + : nullptr, + subtype.sem + ? builder->create(subtype, n, std::move(decos)) + : nullptr}; } /// @param subtype the array element type @@ -678,8 +664,8 @@ class ProgramBuilder { type = MaybeCreateTypename(type); auto sym = builder->Sym(std::forward(name)); return { - builder->create(source, sym, type), - builder->create(sym, type), + type.ast ? builder->create(source, sym, type) : nullptr, + type.sem ? builder->create(sym, type) : nullptr, }; } @@ -690,8 +676,10 @@ class ProgramBuilder { typ::AccessControl access(ast::AccessControl::Access access, typ::Type type) const { type = MaybeCreateTypename(type); - return {builder->create(access, type), - builder->create(access, type)}; + return {type.ast ? builder->create(access, type) + : nullptr, + type.sem ? builder->create(access, type) + : nullptr}; } /// Creates an access control qualifier type @@ -703,8 +691,11 @@ class ProgramBuilder { ast::AccessControl::Access access, typ::Type type) const { type = MaybeCreateTypename(type); - return {builder->create(source, access, type), - builder->create(access, type)}; + return {type.ast + ? builder->create(source, access, type) + : nullptr, + type.sem ? builder->create(access, type) + : nullptr}; } /// @param type the type of the pointer @@ -713,8 +704,10 @@ class ProgramBuilder { typ::Pointer pointer(typ::Type type, ast::StorageClass storage_class) const { type = MaybeCreateTypename(type); - return {builder->create(type, storage_class), - builder->create(type, storage_class)}; + return {type.ast ? builder->create(type, storage_class) + : nullptr, + type.sem ? builder->create(type, storage_class) + : nullptr}; } /// @param source the Source of the node @@ -725,8 +718,11 @@ class ProgramBuilder { typ::Type type, ast::StorageClass storage_class) const { type = MaybeCreateTypename(type); - return {builder->create(source, type, storage_class), - builder->create(type, storage_class)}; + return {type.ast + ? builder->create(source, type, storage_class) + : nullptr, + type.sem ? builder->create(type, storage_class) + : nullptr}; } /// @param storage_class the storage class of the pointer @@ -778,8 +774,10 @@ class ProgramBuilder { /// @returns the sampled texture typ::SampledTexture sampled_texture(ast::TextureDimension dims, typ::Type subtype) const { - return {builder->create(dims, subtype), - builder->create(dims, subtype)}; + return {subtype.ast ? builder->create(dims, subtype) + : nullptr, + subtype.sem ? builder->create(dims, subtype) + : nullptr}; } /// @param source the Source of the node @@ -789,8 +787,11 @@ class ProgramBuilder { typ::SampledTexture sampled_texture(const Source& source, ast::TextureDimension dims, typ::Type subtype) const { - return {builder->create(source, dims, subtype), - builder->create(dims, subtype)}; + return {subtype.ast + ? builder->create(source, dims, subtype) + : nullptr, + subtype.sem ? builder->create(dims, subtype) + : nullptr}; } /// @param dims the dimensionality of the texture @@ -798,8 +799,11 @@ class ProgramBuilder { /// @returns the multisampled texture typ::MultisampledTexture multisampled_texture(ast::TextureDimension dims, typ::Type subtype) const { - return {builder->create(dims, subtype), - builder->create(dims, subtype)}; + return { + subtype.ast ? builder->create(dims, subtype) + : nullptr, + subtype.sem ? builder->create(dims, subtype) + : nullptr}; } /// @param source the Source of the node @@ -809,8 +813,12 @@ class ProgramBuilder { typ::MultisampledTexture multisampled_texture(const Source& source, ast::TextureDimension dims, typ::Type subtype) const { - return {builder->create(source, dims, subtype), - builder->create(dims, subtype)}; + return { + subtype.ast + ? builder->create(source, dims, subtype) + : nullptr, + subtype.sem ? builder->create(dims, subtype) + : nullptr}; } /// @param dims the dimensionality of the texture