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,42 +2450,44 @@ bool GeneratorImpl::EmitTypeAndName(std::ostream& out,
bool GeneratorImpl::EmitStructType(TextBuffer* b, const sem::Struct* str) { bool GeneratorImpl::EmitStructType(TextBuffer* b, const sem::Struct* str) {
auto storage_class_uses = str->StorageClassUsage(); auto storage_class_uses = str->StorageClassUsage();
line(b) << "struct " << StructName(str) << " {"; line(b) << "struct " << StructName(str) << " {";
{ EmitStructMembers(b, str);
ScopedIndent si(b); line(b) << "};";
for (auto* mem : str->Members()) {
auto name = builder_.Symbols().NameFor(mem->Name());
auto* ty = mem->Type(); return true;
}
auto out = line(b); bool GeneratorImpl::EmitStructMembers(TextBuffer* b, const sem::Struct* str) {
ScopedIndent si(b);
for (auto* mem : str->Members()) {
auto name = builder_.Symbols().NameFor(mem->Name());
std::string pre, post; auto* ty = mem->Type();
if (auto* decl = mem->Declaration()) { auto out = line(b);
for (auto* deco : decl->decorations) {
if (auto* interpolate = deco->As<ast::InterpolateDecoration>()) { std::string pre, post;
auto mod = interpolation_to_modifiers(interpolate->type,
interpolate->sampling); if (auto* decl = mem->Declaration()) {
if (mod.empty()) { for (auto* deco : decl->decorations) {
diagnostics_.add_error(diag::System::Writer, if (auto* interpolate = deco->As<ast::InterpolateDecoration>()) {
"unsupported interpolation"); auto mod = interpolation_to_modifiers(interpolate->type,
return false; interpolate->sampling);
} if (mod.empty()) {
diagnostics_.add_error(diag::System::Writer,
"unsupported interpolation");
return false;
} }
} }
} }
out << pre;
if (!EmitTypeAndName(out, ty, ast::StorageClass::kNone,
ast::Access::kReadWrite, name)) {
return false;
}
out << post << ";";
} }
out << pre;
if (!EmitTypeAndName(out, ty, ast::StorageClass::kNone,
ast::Access::kReadWrite, name)) {
return false;
}
out << post << ";";
} }
line(b) << "};";
return true; return true;
} }

View File

@ -322,6 +322,11 @@ class GeneratorImpl : public TextGenerator {
/// @param ty the struct to generate /// @param ty the struct to generate
/// @returns true if the struct is emitted /// @returns true if the struct is emitted
bool EmitStructType(TextBuffer* buffer, const sem::Struct* ty); 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 /// Handles a unary op expression
/// @param out the output of the expression stream /// @param out the output of the expression stream
/// @param expr the expression to emit /// @param expr the expression to emit