MCPcopy Create free account
hub / github.com/csyonghe/Spire / UpdateModuleLibrary

Method UpdateModuleLibrary

Source/SpireLib/SpireLib.cpp:592–647  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

590 }
591
592 void UpdateModuleLibrary(List<CompileUnit> & units, SpireDiagnosticSink * sink)
593 {
594 Spire::Compiler::CompileResult result;
595 compiler->Compile(result, *compileContext.Last(), units, Options);
596 for (auto & shader : compileContext.Last()->Symbols.Shaders)
597 {
598 if (!states.Last().modules.ContainsKey(shader.Key))
599 {
600 RefPtr<SpireModule> newModule = new SpireModule();
601 auto & meta = *newModule;
602 meta.Id = SpireModule::IdAllocator++;
603 meta.Name = shader.Key;
604 int offset = 0;
605 for (auto attrib : shader.Value->SyntaxNode->GetModifiersOfType<SimpleAttribute>())
606 meta.Attribs[attrib->Key] = attrib->Value.Content;
607 for (auto & comp : shader.Value->Components)
608 {
609 if (comp.Value->Implementations.Count() != 1)
610 continue;
611 auto impl = comp.Value->Implementations.First();
612 if (!impl->SyntaxNode->IsRequire() && !impl->SyntaxNode->IsParam())
613 continue;
614 ComponentMetaData compMeta;
615 compMeta.Name = comp.Key;
616 compMeta.Type = comp.Value->Type->DataType;
617 compMeta.TypeName = compMeta.Type->ToString();
618 if (auto specialize = impl->SyntaxNode->FindSpecializeModifier())
619 {
620 for (auto val : specialize->Values)
621 {
622 compMeta.Values.Add(dynamic_cast<ConstantExpressionSyntaxNode*>(val.Ptr())->IntValue);
623 }
624 compMeta.IsSpecialize = true;
625 }
626 if (compMeta.Type->GetBindableResourceType() == BindableResourceType::NonBindable)
627 {
628 compMeta.Alignment = (int)GetTypeAlignment(compMeta.Type.Ptr(), LayoutRule::Std140);
629 compMeta.Size = (int)GetTypeSize(compMeta.Type.Ptr(), LayoutRule::Std140);
630 offset = RoundToAlignment(offset, compMeta.Alignment);
631 compMeta.Offset = offset;
632 offset += compMeta.Size;
633 }
634 if (impl->SyntaxNode->IsRequire())
635 meta.Requirements.Add(compMeta);
636 else
637 meta.Parameters.Add(compMeta);
638 }
639 states.Last().modules.Add(shader.Key, newModule);
640 }
641 }
642 if (sink)
643 {
644 sink->diagnostics.AddRange(result.sink.diagnostics);
645 sink->errorCount += result.GetErrorCount();
646 }
647 }
648
649 int LoadModuleSource(CoreLib::String src, CoreLib::String fileName, SpireDiagnosticSink* sink)

Callers

nothing calls this directly

Calls 15

GetTypeAlignmentFunction · 0.85
GetTypeSizeFunction · 0.85
IsParamMethod · 0.80
AddRangeMethod · 0.80
RoundToAlignmentFunction · 0.50
CompileMethod · 0.45
ContainsKeyMethod · 0.45
CountMethod · 0.45
IsRequireMethod · 0.45
ToStringMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected