mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-14 15:46:28 +00:00
Flatten ast::Decoration class hierarchy
Remove the decoration groupings (Array, Function, Struct, StructMember, Type, Variable), such that all *Decoration classes now subclass ast::Decoration directly. This allows for decorations to be used in multiple places; for example, builtin decorations are now valid for both variables and struct members. Checking that decoration lists only contain decorations that are valid for the node that they are attached to is now done inside the validator. Change-Id: Ie8c0e53e5730a7dedea50a1dec8f26f9e7b00e8d Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44320 Commit-Queue: James Price <jrprice@google.com> Reviewed-by: Ben Clayton <bclayton@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
f1773c6700
commit
95d4077648
@@ -47,7 +47,7 @@ Transform::Output EmitVertexPointSize::Run(const Program* in) {
|
||||
f32, // type
|
||||
false, // is_const
|
||||
nullptr, // constructor
|
||||
ast::VariableDecorationList{
|
||||
ast::DecorationList{
|
||||
out.create<ast::BuiltinDecoration>(Source{},
|
||||
ast::Builtin::kPointSize),
|
||||
});
|
||||
|
||||
@@ -101,7 +101,7 @@ Transform::Output FirstIndexOffset::Run(const Program* in) {
|
||||
|
||||
CloneContext ctx(&out, in);
|
||||
ctx.ReplaceAll([&](ast::Variable* var) -> ast::Variable* {
|
||||
for (ast::VariableDecoration* dec : var->decorations()) {
|
||||
for (ast::Decoration* dec : var->decorations()) {
|
||||
if (auto* blt_dec = dec->As<ast::BuiltinDecoration>()) {
|
||||
ast::Builtin blt_type = blt_dec->value();
|
||||
if (blt_type == ast::Builtin::kVertexIndex) {
|
||||
@@ -157,7 +157,7 @@ ast::Variable* FirstIndexOffset::State::AddUniformBuffer() {
|
||||
ast::StructMemberList members;
|
||||
uint32_t offset = 0;
|
||||
if (has_vertex_index) {
|
||||
ast::StructMemberDecorationList member_dec;
|
||||
ast::DecorationList member_dec;
|
||||
member_dec.push_back(
|
||||
dst->create<ast::StructMemberOffsetDecoration>(Source{}, offset));
|
||||
members.push_back(dst->create<ast::StructMember>(
|
||||
@@ -168,7 +168,7 @@ ast::Variable* FirstIndexOffset::State::AddUniformBuffer() {
|
||||
}
|
||||
|
||||
if (has_instance_index) {
|
||||
ast::StructMemberDecorationList member_dec;
|
||||
ast::DecorationList member_dec;
|
||||
member_dec.push_back(
|
||||
dst->create<ast::StructMemberOffsetDecoration>(Source{}, offset));
|
||||
members.push_back(dst->create<ast::StructMember>(
|
||||
@@ -178,7 +178,7 @@ ast::Variable* FirstIndexOffset::State::AddUniformBuffer() {
|
||||
offset += 4;
|
||||
}
|
||||
|
||||
ast::StructDecorationList decos;
|
||||
ast::DecorationList decos;
|
||||
decos.push_back(dst->create<ast::StructBlockDecoration>(Source{}));
|
||||
|
||||
auto* struct_type = dst->create<type::Struct>(
|
||||
@@ -192,7 +192,7 @@ ast::Variable* FirstIndexOffset::State::AddUniformBuffer() {
|
||||
struct_type, // type
|
||||
false, // is_const
|
||||
nullptr, // constructor
|
||||
ast::VariableDecorationList{
|
||||
ast::DecorationList{
|
||||
dst->create<ast::BindingDecoration>(Source{}, binding),
|
||||
dst->create<ast::GroupDecoration>(Source{}, group),
|
||||
});
|
||||
@@ -227,7 +227,7 @@ ast::VariableDeclStatement* FirstIndexOffset::State::CreateFirstIndexOffset(
|
||||
dst->create<type::U32>(), // type
|
||||
true, // is_const
|
||||
constructor, // constructor
|
||||
ast::VariableDecorationList{}); // decorations
|
||||
ast::DecorationList{}); // decorations
|
||||
return dst->create<ast::VariableDeclStatement>(Source{}, var);
|
||||
}
|
||||
|
||||
|
||||
@@ -135,7 +135,7 @@ void VertexPulling::State::FindOrInsertVertexIndexIfUsed() {
|
||||
GetI32Type(), // type
|
||||
false, // is_const
|
||||
nullptr, // constructor
|
||||
ast::VariableDecorationList{
|
||||
ast::DecorationList{
|
||||
ctx.dst->create<ast::BuiltinDecoration>(Source{},
|
||||
ast::Builtin::kVertexIndex),
|
||||
});
|
||||
@@ -182,7 +182,7 @@ void VertexPulling::State::FindOrInsertInstanceIndexIfUsed() {
|
||||
GetI32Type(), // type
|
||||
false, // is_const
|
||||
nullptr, // constructor
|
||||
ast::VariableDecorationList{
|
||||
ast::DecorationList{
|
||||
ctx.dst->create<ast::BuiltinDecoration>(Source{},
|
||||
ast::Builtin::kInstanceIndex),
|
||||
});
|
||||
@@ -210,7 +210,7 @@ void VertexPulling::State::ConvertVertexInputVariablesToPrivate() {
|
||||
ctx.Clone(v->type()), // type
|
||||
false, // is_const
|
||||
nullptr, // constructor
|
||||
ast::VariableDecorationList{}); // decorations
|
||||
ast::DecorationList{}); // decorations
|
||||
location_to_var[location] = replacement;
|
||||
location_replacements.emplace_back(LocationReplacement{v, replacement});
|
||||
break;
|
||||
@@ -224,13 +224,13 @@ void VertexPulling::State::AddVertexStorageBuffers() {
|
||||
// The array inside the struct definition
|
||||
auto* internal_array_type = ctx.dst->create<type::Array>(
|
||||
GetU32Type(), 0,
|
||||
ast::ArrayDecorationList{
|
||||
ast::DecorationList{
|
||||
ctx.dst->create<ast::StrideDecoration>(Source{}, 4u),
|
||||
});
|
||||
|
||||
// Creating the struct type
|
||||
ast::StructMemberList members;
|
||||
ast::StructMemberDecorationList member_dec;
|
||||
ast::DecorationList member_dec;
|
||||
member_dec.push_back(
|
||||
ctx.dst->create<ast::StructMemberOffsetDecoration>(Source{}, 0u));
|
||||
|
||||
@@ -238,7 +238,7 @@ void VertexPulling::State::AddVertexStorageBuffers() {
|
||||
Source{}, ctx.dst->Symbols().Register(kStructBufferName),
|
||||
internal_array_type, std::move(member_dec)));
|
||||
|
||||
ast::StructDecorationList decos;
|
||||
ast::DecorationList decos;
|
||||
decos.push_back(ctx.dst->create<ast::StructBlockDecoration>(Source{}));
|
||||
|
||||
auto* struct_type = ctx.dst->create<type::Struct>(
|
||||
@@ -256,7 +256,7 @@ void VertexPulling::State::AddVertexStorageBuffers() {
|
||||
struct_type, // type
|
||||
false, // is_const
|
||||
nullptr, // constructor
|
||||
ast::VariableDecorationList{
|
||||
ast::DecorationList{
|
||||
ctx.dst->create<ast::BindingDecoration>(Source{}, i),
|
||||
ctx.dst->create<ast::GroupDecoration>(Source{}, cfg.pulling_group),
|
||||
});
|
||||
@@ -276,11 +276,11 @@ ast::BlockStatement* VertexPulling::State::CreateVertexPullingPreamble() const {
|
||||
Source{}, ctx.dst->create<ast::Variable>(
|
||||
Source{}, // source
|
||||
ctx.dst->Symbols().Register(kPullingPosVarName), // symbol
|
||||
ast::StorageClass::kFunction, // storage_class
|
||||
GetI32Type(), // type
|
||||
false, // is_const
|
||||
nullptr, // constructor
|
||||
ast::VariableDecorationList{})); // decorations
|
||||
ast::StorageClass::kFunction, // storage_class
|
||||
GetI32Type(), // type
|
||||
false, // is_const
|
||||
nullptr, // constructor
|
||||
ast::DecorationList{})); // decorations
|
||||
|
||||
// |kPullingPosVarName| refers to the byte location of the current read. We
|
||||
// declare a variable in the shader to avoid having to reuse Expression
|
||||
|
||||
Reference in New Issue
Block a user