GLSL: factor out the emission of struct members.

This will be needed for emitting UBO and SSBO interface
blocks.

Bug: tint:1223
Change-Id: I1cdc75b67a4fe612dcf8094a7d73b8bf1f85f40a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/67242
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Stephen White <senorblanco@chromium.org>
This commit is contained in:
Stephen White 2021-10-21 19:49:44 +00:00 committed by Tint LUCI CQ
parent 8fca34546b
commit 38ed53ce8f
2 changed files with 34 additions and 27 deletions

View File

@ -2450,7 +2450,13 @@ bool GeneratorImpl::EmitTypeAndName(std::ostream& out,
bool GeneratorImpl::EmitStructType(TextBuffer* b, const sem::Struct* str) {
auto storage_class_uses = str->StorageClassUsage();
line(b) << "struct " << StructName(str) << " {";
{
EmitStructMembers(b, str);
line(b) << "};";
return true;
}
bool GeneratorImpl::EmitStructMembers(TextBuffer* b, const sem::Struct* str) {
ScopedIndent si(b);
for (auto* mem : str->Members()) {
auto name = builder_.Symbols().NameFor(mem->Name());
@ -2482,10 +2488,6 @@ bool GeneratorImpl::EmitStructType(TextBuffer* b, const sem::Struct* str) {
}
out << post << ";";
}
}
line(b) << "};";
return true;
}

View File

@ -322,6 +322,11 @@ class GeneratorImpl : public TextGenerator {
/// @param ty the struct to generate
/// @returns true if the struct is emitted
bool EmitStructType(TextBuffer* buffer, const sem::Struct* ty);
/// Handles generating the members of a structure
/// @param buffer the text buffer that the struct members will be written to
/// @param ty the struct to generate
/// @returns true if the struct members are emitted
bool EmitStructMembers(TextBuffer* buffer, const sem::Struct* ty);
/// Handles a unary op expression
/// @param out the output of the expression stream
/// @param expr the expression to emit