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:
parent
8fca34546b
commit
38ed53ce8f
|
@ -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<ast::InterpolateDecoration>()) {
|
||||
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<ast::InterpolateDecoration>()) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue