tint/ast: Migrate to utils::Vector

Change-Id: I10dd2feeaeb86a1ee7769d2bfd172e49c2805cb3
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/97843
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton
2022-08-02 17:03:35 +00:00
committed by Dawn LUCI CQ
parent 34d46731bb
commit 783b169bf4
277 changed files with 6823 additions and 5056 deletions

View File

@@ -107,7 +107,7 @@ std::tuple<ComponentType, CompositionType> CalculateComponentAndComposition(cons
std::tuple<InterpolationType, InterpolationSampling> CalculateInterpolationData(
const sem::Type* type,
const ast::AttributeList& attributes) {
utils::VectorRef<const ast::Attribute*> attributes) {
auto* interpolation_attribute = ast::GetAttribute<ast::InterpolateAttribute>(attributes);
if (type->is_integer_scalar_or_vector()) {
return {InterpolationType::kFlat, InterpolationSampling::kNone};
@@ -608,7 +608,7 @@ const ast::Function* Inspector::FindEntryPointByName(const std::string& name) {
void Inspector::AddEntryPointInOutVariables(std::string name,
const sem::Type* type,
const ast::AttributeList& attributes,
utils::VectorRef<const ast::Attribute*> attributes,
std::vector<StageVariable>& variables) const {
// Skip builtins.
if (ast::HasAttribute<ast::BuiltinAttribute>(attributes)) {
@@ -647,7 +647,7 @@ void Inspector::AddEntryPointInOutVariables(std::string name,
bool Inspector::ContainsBuiltin(ast::BuiltinValue builtin,
const sem::Type* type,
const ast::AttributeList& attributes) const {
utils::VectorRef<const ast::Attribute*> attributes) const {
auto* unwrapped_type = type->UnwrapRef();
if (auto* struct_ty = unwrapped_type->As<sem::Struct>()) {

View File

@@ -170,7 +170,7 @@ class Inspector {
/// @param variables the list to add the variables to
void AddEntryPointInOutVariables(std::string name,
const sem::Type* type,
const ast::AttributeList& attributes,
utils::VectorRef<const ast::Attribute*> attributes,
std::vector<StageVariable>& variables) const;
/// Recursively determine if the type contains builtin.
@@ -178,7 +178,7 @@ class Inspector {
/// Otherwise, check `attributes` for the attribute.
bool ContainsBuiltin(ast::BuiltinValue builtin,
const sem::Type* type,
const ast::AttributeList& attributes) const;
utils::VectorRef<const ast::Attribute*> attributes) const;
/// Gathers all the texture resource bindings of the given type for the given
/// entry point.

File diff suppressed because it is too large Load Diff

View File

@@ -27,32 +27,36 @@ namespace tint::inspector {
InspectorBuilder::InspectorBuilder() = default;
InspectorBuilder::~InspectorBuilder() = default;
void InspectorBuilder::MakeEmptyBodyFunction(std::string name, ast::AttributeList attributes) {
Func(name, {}, ty.void_(), {Return()}, attributes);
void InspectorBuilder::MakeEmptyBodyFunction(std::string name,
utils::VectorRef<const ast::Attribute*> attributes) {
Func(name, utils::Empty, ty.void_(), utils::Vector{Return()}, attributes);
}
void InspectorBuilder::MakeCallerBodyFunction(std::string caller,
std::vector<std::string> callees,
ast::AttributeList attributes) {
ast::StatementList body;
body.reserve(callees.size() + 1);
utils::VectorRef<std::string> callees,
utils::VectorRef<const ast::Attribute*> attributes) {
utils::Vector<const ast::Statement*, 8> body;
body.Reserve(callees.Length() + 1);
for (auto callee : callees) {
body.push_back(CallStmt(Call(callee)));
body.Push(CallStmt(Call(callee)));
}
body.push_back(Return());
body.Push(Return());
Func(caller, {}, ty.void_(), body, attributes);
Func(caller, utils::Empty, ty.void_(), body, attributes);
}
const ast::Struct* InspectorBuilder::MakeInOutStruct(
std::string name,
std::vector<std::tuple<std::string, uint32_t>> inout_vars) {
ast::StructMemberList members;
const ast::Struct* InspectorBuilder::MakeInOutStruct(std::string name,
utils::VectorRef<InOutInfo> inout_vars) {
utils::Vector<const ast::StructMember*, 8> members;
for (auto var : inout_vars) {
std::string member_name;
uint32_t location;
std::tie(member_name, location) = var;
members.push_back(Member(member_name, ty.u32(), {Location(location), Flat()}));
members.Push(Member(member_name, ty.u32(),
utils::Vector{
Location(location),
Flat(),
}));
}
return Structure(name, members);
}
@@ -61,17 +65,15 @@ const ast::Function* InspectorBuilder::MakePlainGlobalReferenceBodyFunction(
std::string func,
std::string var,
const ast::Type* type,
ast::AttributeList attributes) {
ast::StatementList stmts;
stmts.emplace_back(Decl(Var("local_" + var, type)));
stmts.emplace_back(Assign("local_" + var, var));
stmts.emplace_back(Return());
return Func(func, {}, ty.void_(), stmts, attributes);
utils::VectorRef<const ast::Attribute*> attributes) {
utils::Vector<const ast::Statement*, 3> stmts;
stmts.Push(Decl(Var("local_" + var, type)));
stmts.Push(Assign("local_" + var, var));
stmts.Push(Return());
return Func(func, utils::Empty, ty.void_(), std::move(stmts), std::move(attributes));
}
bool InspectorBuilder::ContainsName(const std::vector<StageVariable>& vec,
const std::string& name) {
bool InspectorBuilder::ContainsName(utils::VectorRef<StageVariable> vec, const std::string& name) {
for (auto& s : vec) {
if (s.name == name) {
return true;
@@ -84,35 +86,38 @@ std::string InspectorBuilder::StructMemberName(size_t idx, const ast::Type* type
return std::to_string(idx) + type->FriendlyName(Symbols());
}
const ast::Struct* InspectorBuilder::MakeStructType(const std::string& name,
std::vector<const ast::Type*> member_types) {
ast::StructMemberList members;
const ast::Struct* InspectorBuilder::MakeStructType(
const std::string& name,
utils::VectorRef<const ast::Type*> member_types) {
utils::Vector<const ast::StructMember*, 8> members;
for (auto* type : member_types) {
members.push_back(MakeStructMember(members.size(), type, {}));
members.Push(MakeStructMember(members.Length(), type, {}));
}
return MakeStructTypeFromMembers(name, std::move(members));
}
const ast::Struct* InspectorBuilder::MakeStructTypeFromMembers(const std::string& name,
ast::StructMemberList members) {
const ast::Struct* InspectorBuilder::MakeStructTypeFromMembers(
const std::string& name,
utils::VectorRef<const ast::StructMember*> members) {
return Structure(name, std::move(members));
}
const ast::StructMember* InspectorBuilder::MakeStructMember(size_t index,
const ast::Type* type,
ast::AttributeList attributes) {
const ast::StructMember* InspectorBuilder::MakeStructMember(
size_t index,
const ast::Type* type,
utils::VectorRef<const ast::Attribute*> attributes) {
return Member(StructMemberName(index, type), type, std::move(attributes));
}
const ast::Struct* InspectorBuilder::MakeUniformBufferType(
const std::string& name,
std::vector<const ast::Type*> member_types) {
utils::VectorRef<const ast::Type*> member_types) {
return MakeStructType(name, member_types);
}
std::function<const ast::TypeName*()> InspectorBuilder::MakeStorageBufferTypes(
const std::string& name,
std::vector<const ast::Type*> member_types) {
utils::VectorRef<const ast::Type*> member_types) {
MakeStructType(name, member_types);
return [this, name] { return ty.type_name(name); };
}
@@ -122,7 +127,7 @@ void InspectorBuilder::AddUniformBuffer(const std::string& name,
uint32_t group,
uint32_t binding) {
GlobalVar(name, type, ast::StorageClass::kUniform,
ast::AttributeList{
utils::Vector{
create<ast::BindingAttribute>(binding),
create<ast::GroupAttribute>(group),
});
@@ -138,7 +143,7 @@ void InspectorBuilder::AddStorageBuffer(const std::string& name,
uint32_t group,
uint32_t binding) {
GlobalVar(name, type, ast::StorageClass::kStorage, access,
ast::AttributeList{
utils::Vector{
create<ast::BindingAttribute>(binding),
create<ast::GroupAttribute>(group),
});
@@ -147,15 +152,15 @@ void InspectorBuilder::AddStorageBuffer(const std::string& name,
void InspectorBuilder::MakeStructVariableReferenceBodyFunction(
std::string func_name,
std::string struct_name,
std::vector<std::tuple<size_t, const ast::Type*>> members) {
ast::StatementList stmts;
utils::VectorRef<std::tuple<size_t, const ast::Type*>> members) {
utils::Vector<const ast::Statement*, 8> stmts;
for (auto member : members) {
size_t member_idx;
const ast::Type* member_type;
std::tie(member_idx, member_type) = member;
std::string member_name = StructMemberName(member_idx, member_type);
stmts.emplace_back(Decl(Var("local" + member_name, member_type)));
stmts.Push(Decl(Var("local" + member_name, member_type)));
}
for (auto member : members) {
@@ -164,17 +169,17 @@ void InspectorBuilder::MakeStructVariableReferenceBodyFunction(
std::tie(member_idx, member_type) = member;
std::string member_name = StructMemberName(member_idx, member_type);
stmts.emplace_back(Assign("local" + member_name, MemberAccessor(struct_name, member_name)));
stmts.Push(Assign("local" + member_name, MemberAccessor(struct_name, member_name)));
}
stmts.emplace_back(Return());
stmts.Push(Return());
Func(func_name, {}, ty.void_(), stmts);
Func(func_name, utils::Empty, ty.void_(), stmts);
}
void InspectorBuilder::AddSampler(const std::string& name, uint32_t group, uint32_t binding) {
GlobalVar(name, sampler_type(),
ast::AttributeList{
utils::Vector{
create<ast::BindingAttribute>(binding),
create<ast::GroupAttribute>(group),
});
@@ -184,7 +189,7 @@ void InspectorBuilder::AddComparisonSampler(const std::string& name,
uint32_t group,
uint32_t binding) {
GlobalVar(name, comparison_sampler_type(),
ast::AttributeList{
utils::Vector{
create<ast::BindingAttribute>(binding),
create<ast::GroupAttribute>(group),
});
@@ -195,7 +200,7 @@ void InspectorBuilder::AddResource(const std::string& name,
uint32_t group,
uint32_t binding) {
GlobalVar(name, type,
ast::AttributeList{
utils::Vector{
create<ast::BindingAttribute>(binding),
create<ast::GroupAttribute>(group),
});
@@ -211,17 +216,15 @@ const ast::Function* InspectorBuilder::MakeSamplerReferenceBodyFunction(
const std::string& sampler_name,
const std::string& coords_name,
const ast::Type* base_type,
ast::AttributeList attributes) {
utils::VectorRef<const ast::Attribute*> attributes) {
std::string result_name = "sampler_result";
ast::StatementList stmts;
stmts.emplace_back(Decl(Var(result_name, ty.vec(base_type, 4))));
stmts.emplace_back(
Assign(result_name, Call("textureSample", texture_name, sampler_name, coords_name)));
stmts.emplace_back(Return());
return Func(func_name, {}, ty.void_(), stmts, attributes);
utils::Vector stmts{
Decl(Var(result_name, ty.vec(base_type, 4))),
Assign(result_name, Call("textureSample", texture_name, sampler_name, coords_name)),
Return(),
};
return Func(func_name, utils::Empty, ty.void_(), std::move(stmts), std::move(attributes));
}
const ast::Function* InspectorBuilder::MakeSamplerReferenceBodyFunction(
@@ -231,18 +234,16 @@ const ast::Function* InspectorBuilder::MakeSamplerReferenceBodyFunction(
const std::string& coords_name,
const std::string& array_index,
const ast::Type* base_type,
ast::AttributeList attributes) {
utils::VectorRef<const ast::Attribute*> attributes) {
std::string result_name = "sampler_result";
ast::StatementList stmts;
stmts.emplace_back(Decl(Var("sampler_result", ty.vec(base_type, 4))));
stmts.emplace_back(Assign("sampler_result", Call("textureSample", texture_name, sampler_name,
coords_name, array_index)));
stmts.emplace_back(Return());
return Func(func_name, {}, ty.void_(), stmts, attributes);
utils::Vector stmts{
Decl(Var("sampler_result", ty.vec(base_type, 4))),
Assign("sampler_result",
Call("textureSample", texture_name, sampler_name, coords_name, array_index)),
Return(),
};
return Func(func_name, utils::Empty, ty.void_(), std::move(stmts), std::move(attributes));
}
const ast::Function* InspectorBuilder::MakeComparisonSamplerReferenceBodyFunction(
@@ -252,17 +253,16 @@ const ast::Function* InspectorBuilder::MakeComparisonSamplerReferenceBodyFunctio
const std::string& coords_name,
const std::string& depth_name,
const ast::Type* base_type,
ast::AttributeList attributes) {
utils::VectorRef<const ast::Attribute*> attributes) {
std::string result_name = "sampler_result";
ast::StatementList stmts;
stmts.emplace_back(Decl(Var("sampler_result", base_type)));
stmts.emplace_back(Assign("sampler_result", Call("textureSampleCompare", texture_name,
sampler_name, coords_name, depth_name)));
stmts.emplace_back(Return());
return Func(func_name, {}, ty.void_(), stmts, attributes);
utils::Vector stmts{
Decl(Var("sampler_result", base_type)),
Assign("sampler_result",
Call("textureSampleCompare", texture_name, sampler_name, coords_name, depth_name)),
Return(),
};
return Func(func_name, utils::Empty, ty.void_(), std::move(stmts), std::move(attributes));
}
const ast::Type* InspectorBuilder::GetBaseType(ResourceBinding::SampledKind sampled_kind) {
@@ -306,7 +306,7 @@ void InspectorBuilder::AddStorageTexture(const std::string& name,
uint32_t group,
uint32_t binding) {
GlobalVar(name, type,
ast::AttributeList{
utils::Vector{
create<ast::BindingAttribute>(binding),
create<ast::GroupAttribute>(group),
});
@@ -316,14 +316,14 @@ const ast::Function* InspectorBuilder::MakeStorageTextureBodyFunction(
const std::string& func_name,
const std::string& st_name,
const ast::Type* dim_type,
ast::AttributeList attributes) {
ast::StatementList stmts;
utils::VectorRef<const ast::Attribute*> attributes) {
utils::Vector stmts{
Decl(Var("dim", dim_type)),
Assign("dim", Call("textureDimensions", st_name)),
Return(),
};
stmts.emplace_back(Decl(Var("dim", dim_type)));
stmts.emplace_back(Assign("dim", Call("textureDimensions", st_name)));
stmts.emplace_back(Return());
return Func(func_name, {}, ty.void_(), stmts, attributes);
return Func(func_name, utils::Empty, ty.void_(), std::move(stmts), std::move(attributes));
}
std::function<const ast::Type*()> InspectorBuilder::GetTypeFunction(ComponentType component,

View File

@@ -44,28 +44,31 @@ class InspectorBuilder : public ProgramBuilder {
/// Generates an empty function
/// @param name name of the function created
/// @param attributes the function attributes
void MakeEmptyBodyFunction(std::string name, ast::AttributeList attributes);
void MakeEmptyBodyFunction(std::string name,
utils::VectorRef<const ast::Attribute*> attributes);
/// Generates a function that calls other functions
/// @param caller name of the function created
/// @param callees names of the functions to be called
/// @param attributes the function attributes
void MakeCallerBodyFunction(std::string caller,
std::vector<std::string> callees,
ast::AttributeList attributes);
utils::VectorRef<std::string> callees,
utils::VectorRef<const ast::Attribute*> attributes);
/// InOutInfo is a tuple of name and location for a structure member
using InOutInfo = std::tuple<std::string, uint32_t>;
/// Generates a struct that contains user-defined IO members
/// @param name the name of the generated struct
/// @param inout_vars tuples of {name, loc} that will be the struct members
/// @returns a structure object
const ast::Struct* MakeInOutStruct(std::string name,
std::vector<std::tuple<std::string, uint32_t>> inout_vars);
const ast::Struct* MakeInOutStruct(std::string name, utils::VectorRef<InOutInfo> inout_vars);
// TODO(crbug.com/tint/697): Remove this.
/// Add In/Out variables to the global variables
/// @param inout_vars tuples of {in, out} that will be added as entries to the
/// global variables
void AddInOutVariables(std::vector<std::tuple<std::string, std::string>> inout_vars);
void AddInOutVariables(utils::VectorRef<std::tuple<std::string, std::string>> inout_vars);
// TODO(crbug.com/tint/697): Remove this.
/// Generates a function that references in/out variables
@@ -73,9 +76,10 @@ class InspectorBuilder : public ProgramBuilder {
/// @param inout_vars tuples of {in, out} that will be converted into out = in
/// calls in the function body
/// @param attributes the function attributes
void MakeInOutVariableBodyFunction(std::string name,
std::vector<std::tuple<std::string, std::string>> inout_vars,
ast::AttributeList attributes);
void MakeInOutVariableBodyFunction(
std::string name,
utils::VectorRef<std::tuple<std::string, std::string>> inout_vars,
utils::VectorRef<const ast::Attribute*> attributes);
// TODO(crbug.com/tint/697): Remove this.
/// Generates a function that references in/out variables and calls another
@@ -89,9 +93,8 @@ class InspectorBuilder : public ProgramBuilder {
const ast::Function* MakeInOutVariableCallerBodyFunction(
std::string caller,
std::string callee,
std::vector<std::tuple<std::string, std::string>> inout_vars,
ast::AttributeList attributes);
utils::VectorRef<std::tuple<std::string, std::string>> inout_vars,
utils::VectorRef<const ast::Attribute*> attributes);
/// Generates a function that references module-scoped, plain-typed constant
/// or variable.
@@ -100,15 +103,16 @@ class InspectorBuilder : public ProgramBuilder {
/// @param type type of the const being referenced
/// @param attributes the function attributes
/// @returns a function object
const ast::Function* MakePlainGlobalReferenceBodyFunction(std::string func,
std::string var,
const ast::Type* type,
ast::AttributeList attributes);
const ast::Function* MakePlainGlobalReferenceBodyFunction(
std::string func,
std::string var,
const ast::Type* type,
utils::VectorRef<const ast::Attribute*> attributes);
/// @param vec Vector of StageVariable to be searched
/// @param name Name to be searching for
/// @returns true if name is in vec, otherwise false
bool ContainsName(const std::vector<StageVariable>& vec, const std::string& name);
bool ContainsName(utils::VectorRef<StageVariable> vec, const std::string& name);
/// Builds a string for accessing a member in a generated struct
/// @param idx index of member
@@ -121,14 +125,15 @@ class InspectorBuilder : public ProgramBuilder {
/// @param member_types a vector of member types
/// @returns a struct type
const ast::Struct* MakeStructType(const std::string& name,
std::vector<const ast::Type*> member_types);
utils::VectorRef<const ast::Type*> member_types);
/// Generates a struct type from a list of member nodes.
/// @param name name for the struct type
/// @param members a vector of members
/// @returns a struct type
const ast::Struct* MakeStructTypeFromMembers(const std::string& name,
ast::StructMemberList members);
const ast::Struct* MakeStructTypeFromMembers(
const std::string& name,
utils::VectorRef<const ast::StructMember*> members);
/// Generates a struct member with a specified index and type.
/// @param index index of the field within the struct
@@ -137,14 +142,14 @@ class InspectorBuilder : public ProgramBuilder {
/// @returns a struct member
const ast::StructMember* MakeStructMember(size_t index,
const ast::Type* type,
ast::AttributeList attributes);
utils::VectorRef<const ast::Attribute*> attributes);
/// Generates types appropriate for using in an uniform buffer
/// @param name name for the type
/// @param member_types a vector of member types
/// @returns a struct type that has the layout for an uniform buffer.
const ast::Struct* MakeUniformBufferType(const std::string& name,
std::vector<const ast::Type*> member_types);
utils::VectorRef<const ast::Type*> member_types);
/// Generates types appropriate for using in a storage buffer
/// @param name name for the type
@@ -152,7 +157,7 @@ class InspectorBuilder : public ProgramBuilder {
/// @returns a function that returns the created structure.
std::function<const ast::TypeName*()> MakeStorageBufferTypes(
const std::string& name,
std::vector<const ast::Type*> member_types);
utils::VectorRef<const ast::Type*> member_types);
/// Adds an uniform buffer variable to the program
/// @param name the name of the variable
@@ -181,14 +186,16 @@ class InspectorBuilder : public ProgramBuilder {
uint32_t group,
uint32_t binding);
/// MemberInfo is a tuple of member index and type.
using MemberInfo = std::tuple<size_t, const ast::Type*>;
/// Generates a function that references a specific struct variable
/// @param func_name name of the function created
/// @param struct_name name of the struct variabler to be accessed
/// @param members list of members to access, by index and type
void MakeStructVariableReferenceBodyFunction(
std::string func_name,
std::string struct_name,
std::vector<std::tuple<size_t, const ast::Type*>> members);
void MakeStructVariableReferenceBodyFunction(std::string func_name,
std::string struct_name,
utils::VectorRef<MemberInfo> members);
/// Adds a regular sampler variable to the program
/// @param name the name of the variable
@@ -225,12 +232,13 @@ class InspectorBuilder : public ProgramBuilder {
/// @param base_type sampler base type
/// @param attributes the function attributes
/// @returns a function that references all of the values specified
const ast::Function* MakeSamplerReferenceBodyFunction(const std::string& func_name,
const std::string& texture_name,
const std::string& sampler_name,
const std::string& coords_name,
const ast::Type* base_type,
ast::AttributeList attributes);
const ast::Function* MakeSamplerReferenceBodyFunction(
const std::string& func_name,
const std::string& texture_name,
const std::string& sampler_name,
const std::string& coords_name,
const ast::Type* base_type,
utils::VectorRef<const ast::Attribute*> attributes);
/// Generates a function that references a specific sampler variable
/// @param func_name name of the function created
@@ -241,13 +249,14 @@ class InspectorBuilder : public ProgramBuilder {
/// @param base_type sampler base type
/// @param attributes the function attributes
/// @returns a function that references all of the values specified
const ast::Function* MakeSamplerReferenceBodyFunction(const std::string& func_name,
const std::string& texture_name,
const std::string& sampler_name,
const std::string& coords_name,
const std::string& array_index,
const ast::Type* base_type,
ast::AttributeList attributes);
const ast::Function* MakeSamplerReferenceBodyFunction(
const std::string& func_name,
const std::string& texture_name,
const std::string& sampler_name,
const std::string& coords_name,
const std::string& array_index,
const ast::Type* base_type,
utils::VectorRef<const ast::Attribute*> attributes);
/// Generates a function that references a specific comparison sampler
/// variable.
@@ -259,13 +268,14 @@ class InspectorBuilder : public ProgramBuilder {
/// @param base_type sampler base type
/// @param attributes the function attributes
/// @returns a function that references all of the values specified
const ast::Function* MakeComparisonSamplerReferenceBodyFunction(const std::string& func_name,
const std::string& texture_name,
const std::string& sampler_name,
const std::string& coords_name,
const std::string& depth_name,
const ast::Type* base_type,
ast::AttributeList attributes);
const ast::Function* MakeComparisonSamplerReferenceBodyFunction(
const std::string& func_name,
const std::string& texture_name,
const std::string& sampler_name,
const std::string& coords_name,
const std::string& depth_name,
const ast::Type* base_type,
utils::VectorRef<const ast::Attribute*> attributes);
/// Gets an appropriate type for the data in a given texture type.
/// @param sampled_kind type of in the texture
@@ -301,10 +311,11 @@ class InspectorBuilder : public ProgramBuilder {
/// @param dim_type type expected by textureDimensons to return
/// @param attributes the function attributes
/// @returns a function that references all of the values specified
const ast::Function* MakeStorageTextureBodyFunction(const std::string& func_name,
const std::string& st_name,
const ast::Type* dim_type,
ast::AttributeList attributes);
const ast::Function* MakeStorageTextureBodyFunction(
const std::string& func_name,
const std::string& st_name,
const ast::Type* dim_type,
utils::VectorRef<const ast::Attribute*> attributes);
/// Get a generator function that returns a type appropriate for a stage
/// variable with the given combination of component and composition type.