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 <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
parent
12ed13d0d4
commit
95c2e95100
|
@ -408,8 +408,8 @@ class ProgramBuilder {
|
||||||
/// @param n vector width in elements
|
/// @param n vector width in elements
|
||||||
/// @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 {
|
||||||
return {builder->create<ast::Vector>(type, n),
|
return {type.ast ? builder->create<ast::Vector>(type, n) : nullptr,
|
||||||
builder->create<sem::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
|
||||||
|
@ -417,8 +417,9 @@ class ProgramBuilder {
|
||||||
/// @param n vector width in elements
|
/// @param n vector width in elements
|
||||||
/// @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 {
|
||||||
return {builder->create<ast::Vector>(source, type, n),
|
return {
|
||||||
builder->create<sem::Vector>(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
|
||||||
|
@ -463,8 +464,10 @@ class ProgramBuilder {
|
||||||
/// @param rows number of rows for the matrix
|
/// @param rows number of rows for the matrix
|
||||||
/// @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 {
|
||||||
return {builder->create<ast::Matrix>(type, rows, columns),
|
return {type.ast ? builder->create<ast::Matrix>(type, rows, columns)
|
||||||
builder->create<sem::Matrix>(type, rows, columns)};
|
: nullptr,
|
||||||
|
type.sem ? builder->create<sem::Matrix>(type, rows, columns)
|
||||||
|
: nullptr};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @param source the Source of the node
|
/// @param source the Source of the node
|
||||||
|
@ -476,72 +479,48 @@ class ProgramBuilder {
|
||||||
typ::Type type,
|
typ::Type type,
|
||||||
uint32_t columns,
|
uint32_t columns,
|
||||||
uint32_t rows) const {
|
uint32_t rows) const {
|
||||||
return {builder->create<ast::Matrix>(source, type, rows, columns),
|
return {type.ast
|
||||||
builder->create<sem::Matrix>(type, rows, columns)};
|
? builder->create<ast::Matrix>(source, type, rows, columns)
|
||||||
|
: nullptr,
|
||||||
|
type.sem ? builder->create<sem::Matrix>(type, rows, columns)
|
||||||
|
: nullptr};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @param type matrix subtype
|
/// @param type matrix subtype
|
||||||
/// @return the tint AST type for a 2x3 matrix of `type`.
|
/// @return the tint AST type for a 2x3 matrix of `type`.
|
||||||
typ::Matrix mat2x2(typ::Type type) const {
|
typ::Matrix mat2x2(typ::Type type) const { return mat(type, 2u, 2u); }
|
||||||
return {builder->create<ast::Matrix>(type, 2u, 2u),
|
|
||||||
builder->create<sem::Matrix>(type, 2u, 2u)};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @param type matrix subtype
|
/// @param type matrix subtype
|
||||||
/// @return the tint AST type for a 2x3 matrix of `type`.
|
/// @return the tint AST type for a 2x3 matrix of `type`.
|
||||||
typ::Matrix mat2x3(typ::Type type) const {
|
typ::Matrix mat2x3(typ::Type type) const { return mat(type, 2u, 3u); }
|
||||||
return {builder->create<ast::Matrix>(type, 3u, 2u),
|
|
||||||
builder->create<sem::Matrix>(type, 3u, 2u)};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @param type matrix subtype
|
/// @param type matrix subtype
|
||||||
/// @return the tint AST type for a 2x4 matrix of `type`.
|
/// @return the tint AST type for a 2x4 matrix of `type`.
|
||||||
typ::Matrix mat2x4(typ::Type type) const {
|
typ::Matrix mat2x4(typ::Type type) const { return mat(type, 2u, 4u); }
|
||||||
return {builder->create<ast::Matrix>(type, 4u, 2u),
|
|
||||||
builder->create<sem::Matrix>(type, 4u, 2u)};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @param type matrix subtype
|
/// @param type matrix subtype
|
||||||
/// @return the tint AST type for a 3x2 matrix of `type`.
|
/// @return the tint AST type for a 3x2 matrix of `type`.
|
||||||
typ::Matrix mat3x2(typ::Type type) const {
|
typ::Matrix mat3x2(typ::Type type) const { return mat(type, 3u, 2u); }
|
||||||
return {builder->create<ast::Matrix>(type, 2u, 3u),
|
|
||||||
builder->create<sem::Matrix>(type, 2u, 3u)};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @param type matrix subtype
|
/// @param type matrix subtype
|
||||||
/// @return the tint AST type for a 3x3 matrix of `type`.
|
/// @return the tint AST type for a 3x3 matrix of `type`.
|
||||||
typ::Matrix mat3x3(typ::Type type) const {
|
typ::Matrix mat3x3(typ::Type type) const { return mat(type, 3u, 3u); }
|
||||||
return {builder->create<ast::Matrix>(type, 3u, 3u),
|
|
||||||
builder->create<sem::Matrix>(type, 3u, 3u)};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @param type matrix subtype
|
/// @param type matrix subtype
|
||||||
/// @return the tint AST type for a 3x4 matrix of `type`.
|
/// @return the tint AST type for a 3x4 matrix of `type`.
|
||||||
typ::Matrix mat3x4(typ::Type type) const {
|
typ::Matrix mat3x4(typ::Type type) const { return mat(type, 3u, 4u); }
|
||||||
return {builder->create<ast::Matrix>(type, 4u, 3u),
|
|
||||||
builder->create<sem::Matrix>(type, 4u, 3u)};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @param type matrix subtype
|
/// @param type matrix subtype
|
||||||
/// @return the tint AST type for a 4x2 matrix of `type`.
|
/// @return the tint AST type for a 4x2 matrix of `type`.
|
||||||
typ::Matrix mat4x2(typ::Type type) const {
|
typ::Matrix mat4x2(typ::Type type) const { return mat(type, 4u, 2u); }
|
||||||
return {builder->create<ast::Matrix>(type, 2u, 4u),
|
|
||||||
builder->create<sem::Matrix>(type, 2u, 4u)};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @param type matrix subtype
|
/// @param type matrix subtype
|
||||||
/// @return the tint AST type for a 4x3 matrix of `type`.
|
/// @return the tint AST type for a 4x3 matrix of `type`.
|
||||||
typ::Matrix mat4x3(typ::Type type) const {
|
typ::Matrix mat4x3(typ::Type type) const { return mat(type, 4u, 3u); }
|
||||||
return {builder->create<ast::Matrix>(type, 3u, 4u),
|
|
||||||
builder->create<sem::Matrix>(type, 3u, 4u)};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @param type matrix subtype
|
/// @param type matrix subtype
|
||||||
/// @return the tint AST type for a 4x4 matrix of `type`.
|
/// @return the tint AST type for a 4x4 matrix of `type`.
|
||||||
typ::Matrix mat4x4(typ::Type type) const {
|
typ::Matrix mat4x4(typ::Type type) const { return mat(type, 4u, 4u); }
|
||||||
return {builder->create<ast::Matrix>(type, 4u, 4u),
|
|
||||||
builder->create<sem::Matrix>(type, 4u, 4u)};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @param columns number of columns for the matrix
|
/// @param columns number of columns for the matrix
|
||||||
/// @param rows number of rows for the matrix
|
/// @param rows number of rows for the matrix
|
||||||
|
@ -613,8 +592,11 @@ class ProgramBuilder {
|
||||||
uint32_t n = 0,
|
uint32_t n = 0,
|
||||||
ast::DecorationList decos = {}) const {
|
ast::DecorationList decos = {}) const {
|
||||||
subtype = MaybeCreateTypename(subtype);
|
subtype = MaybeCreateTypename(subtype);
|
||||||
return {builder->create<ast::Array>(subtype, n, decos),
|
return {subtype.ast ? builder->create<ast::Array>(subtype, n, decos)
|
||||||
builder->create<sem::ArrayType>(subtype, n, std::move(decos))};
|
: nullptr,
|
||||||
|
subtype.sem ? builder->create<sem::ArrayType>(subtype, n,
|
||||||
|
std::move(decos))
|
||||||
|
: nullptr};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @param source the Source of the node
|
/// @param source the Source of the node
|
||||||
|
@ -627,8 +609,12 @@ class ProgramBuilder {
|
||||||
uint32_t n = 0,
|
uint32_t n = 0,
|
||||||
ast::DecorationList decos = {}) const {
|
ast::DecorationList decos = {}) const {
|
||||||
subtype = MaybeCreateTypename(subtype);
|
subtype = MaybeCreateTypename(subtype);
|
||||||
return {builder->create<ast::Array>(source, subtype, n, decos),
|
return {
|
||||||
builder->create<sem::ArrayType>(subtype, n, std::move(decos))};
|
subtype.ast ? builder->create<ast::Array>(source, subtype, n, decos)
|
||||||
|
: nullptr,
|
||||||
|
subtype.sem
|
||||||
|
? builder->create<sem::ArrayType>(subtype, n, std::move(decos))
|
||||||
|
: nullptr};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @param subtype the array element type
|
/// @param subtype the array element type
|
||||||
|
@ -678,8 +664,8 @@ class ProgramBuilder {
|
||||||
type = MaybeCreateTypename(type);
|
type = MaybeCreateTypename(type);
|
||||||
auto sym = builder->Sym(std::forward<NAME>(name));
|
auto sym = builder->Sym(std::forward<NAME>(name));
|
||||||
return {
|
return {
|
||||||
builder->create<ast::Alias>(source, sym, type),
|
type.ast ? builder->create<ast::Alias>(source, sym, type) : nullptr,
|
||||||
builder->create<sem::Alias>(sym, type),
|
type.sem ? builder->create<sem::Alias>(sym, type) : nullptr,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -690,8 +676,10 @@ class ProgramBuilder {
|
||||||
typ::AccessControl access(ast::AccessControl::Access access,
|
typ::AccessControl access(ast::AccessControl::Access access,
|
||||||
typ::Type type) const {
|
typ::Type type) const {
|
||||||
type = MaybeCreateTypename(type);
|
type = MaybeCreateTypename(type);
|
||||||
return {builder->create<ast::AccessControl>(access, type),
|
return {type.ast ? builder->create<ast::AccessControl>(access, type)
|
||||||
builder->create<sem::AccessControl>(access, type)};
|
: nullptr,
|
||||||
|
type.sem ? builder->create<sem::AccessControl>(access, type)
|
||||||
|
: nullptr};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates an access control qualifier type
|
/// Creates an access control qualifier type
|
||||||
|
@ -703,8 +691,11 @@ class ProgramBuilder {
|
||||||
ast::AccessControl::Access access,
|
ast::AccessControl::Access access,
|
||||||
typ::Type type) const {
|
typ::Type type) const {
|
||||||
type = MaybeCreateTypename(type);
|
type = MaybeCreateTypename(type);
|
||||||
return {builder->create<ast::AccessControl>(source, access, type),
|
return {type.ast
|
||||||
builder->create<sem::AccessControl>(access, type)};
|
? builder->create<ast::AccessControl>(source, access, type)
|
||||||
|
: nullptr,
|
||||||
|
type.sem ? builder->create<sem::AccessControl>(access, type)
|
||||||
|
: nullptr};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @param type the type of the pointer
|
/// @param type the type of the pointer
|
||||||
|
@ -713,8 +704,10 @@ class ProgramBuilder {
|
||||||
typ::Pointer pointer(typ::Type type,
|
typ::Pointer pointer(typ::Type type,
|
||||||
ast::StorageClass storage_class) const {
|
ast::StorageClass storage_class) const {
|
||||||
type = MaybeCreateTypename(type);
|
type = MaybeCreateTypename(type);
|
||||||
return {builder->create<ast::Pointer>(type, storage_class),
|
return {type.ast ? builder->create<ast::Pointer>(type, storage_class)
|
||||||
builder->create<sem::Pointer>(type, storage_class)};
|
: nullptr,
|
||||||
|
type.sem ? builder->create<sem::Pointer>(type, storage_class)
|
||||||
|
: nullptr};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @param source the Source of the node
|
/// @param source the Source of the node
|
||||||
|
@ -725,8 +718,11 @@ class ProgramBuilder {
|
||||||
typ::Type type,
|
typ::Type type,
|
||||||
ast::StorageClass storage_class) const {
|
ast::StorageClass storage_class) const {
|
||||||
type = MaybeCreateTypename(type);
|
type = MaybeCreateTypename(type);
|
||||||
return {builder->create<ast::Pointer>(source, type, storage_class),
|
return {type.ast
|
||||||
builder->create<sem::Pointer>(type, storage_class)};
|
? builder->create<ast::Pointer>(source, type, storage_class)
|
||||||
|
: nullptr,
|
||||||
|
type.sem ? builder->create<sem::Pointer>(type, storage_class)
|
||||||
|
: nullptr};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @param storage_class the storage class of the pointer
|
/// @param storage_class the storage class of the pointer
|
||||||
|
@ -778,8 +774,10 @@ class ProgramBuilder {
|
||||||
/// @returns the sampled texture
|
/// @returns the sampled texture
|
||||||
typ::SampledTexture sampled_texture(ast::TextureDimension dims,
|
typ::SampledTexture sampled_texture(ast::TextureDimension dims,
|
||||||
typ::Type subtype) const {
|
typ::Type subtype) const {
|
||||||
return {builder->create<ast::SampledTexture>(dims, subtype),
|
return {subtype.ast ? builder->create<ast::SampledTexture>(dims, subtype)
|
||||||
builder->create<sem::SampledTexture>(dims, subtype)};
|
: nullptr,
|
||||||
|
subtype.sem ? builder->create<sem::SampledTexture>(dims, subtype)
|
||||||
|
: nullptr};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @param source the Source of the node
|
/// @param source the Source of the node
|
||||||
|
@ -789,8 +787,11 @@ class ProgramBuilder {
|
||||||
typ::SampledTexture sampled_texture(const Source& source,
|
typ::SampledTexture sampled_texture(const Source& source,
|
||||||
ast::TextureDimension dims,
|
ast::TextureDimension dims,
|
||||||
typ::Type subtype) const {
|
typ::Type subtype) const {
|
||||||
return {builder->create<ast::SampledTexture>(source, dims, subtype),
|
return {subtype.ast
|
||||||
builder->create<sem::SampledTexture>(dims, subtype)};
|
? builder->create<ast::SampledTexture>(source, dims, subtype)
|
||||||
|
: nullptr,
|
||||||
|
subtype.sem ? builder->create<sem::SampledTexture>(dims, subtype)
|
||||||
|
: nullptr};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @param dims the dimensionality of the texture
|
/// @param dims the dimensionality of the texture
|
||||||
|
@ -798,8 +799,11 @@ class ProgramBuilder {
|
||||||
/// @returns the multisampled texture
|
/// @returns the multisampled texture
|
||||||
typ::MultisampledTexture multisampled_texture(ast::TextureDimension dims,
|
typ::MultisampledTexture multisampled_texture(ast::TextureDimension dims,
|
||||||
typ::Type subtype) const {
|
typ::Type subtype) const {
|
||||||
return {builder->create<ast::MultisampledTexture>(dims, subtype),
|
return {
|
||||||
builder->create<sem::MultisampledTexture>(dims, subtype)};
|
subtype.ast ? builder->create<ast::MultisampledTexture>(dims, subtype)
|
||||||
|
: nullptr,
|
||||||
|
subtype.sem ? builder->create<sem::MultisampledTexture>(dims, subtype)
|
||||||
|
: nullptr};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @param source the Source of the node
|
/// @param source the Source of the node
|
||||||
|
@ -809,8 +813,12 @@ class ProgramBuilder {
|
||||||
typ::MultisampledTexture multisampled_texture(const Source& source,
|
typ::MultisampledTexture multisampled_texture(const Source& source,
|
||||||
ast::TextureDimension dims,
|
ast::TextureDimension dims,
|
||||||
typ::Type subtype) const {
|
typ::Type subtype) const {
|
||||||
return {builder->create<ast::MultisampledTexture>(source, dims, subtype),
|
return {
|
||||||
builder->create<sem::MultisampledTexture>(dims, subtype)};
|
subtype.ast
|
||||||
|
? builder->create<ast::MultisampledTexture>(source, dims, subtype)
|
||||||
|
: nullptr,
|
||||||
|
subtype.sem ? builder->create<sem::MultisampledTexture>(dims, subtype)
|
||||||
|
: nullptr};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @param dims the dimensionality of the texture
|
/// @param dims the dimensionality of the texture
|
||||||
|
|
Loading…
Reference in New Issue