diff --git a/src/writer/glsl/generator_impl.cc b/src/writer/glsl/generator_impl.cc index 2bbef36770..e9f23195dc 100644 --- a/src/writer/glsl/generator_impl.cc +++ b/src/writer/glsl/generator_impl.cc @@ -2450,42 +2450,44 @@ 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) << " {"; - { - ScopedIndent si(b); - for (auto* mem : str->Members()) { - auto name = builder_.Symbols().NameFor(mem->Name()); + EmitStructMembers(b, str); + line(b) << "};"; - 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()) { - for (auto* deco : decl->decorations) { - if (auto* interpolate = deco->As()) { - auto mod = interpolation_to_modifiers(interpolate->type, - interpolate->sampling); - if (mod.empty()) { - diagnostics_.add_error(diag::System::Writer, - "unsupported interpolation"); - return false; - } + auto out = line(b); + + std::string pre, post; + + if (auto* decl = mem->Declaration()) { + for (auto* deco : decl->decorations) { + if (auto* interpolate = deco->As()) { + auto mod = interpolation_to_modifiers(interpolate->type, + 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; } diff --git a/src/writer/glsl/generator_impl.h b/src/writer/glsl/generator_impl.h index 4f9e8910ba..ba82fa82cf 100644 --- a/src/writer/glsl/generator_impl.h +++ b/src/writer/glsl/generator_impl.h @@ -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