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

Method ProcessShader

Source/SpireCore/CodeGenerator.cpp:320–552  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

318 }
319
320 virtual void ProcessShader(ShaderIR * shader) override
321 {
322 currentShader = shader;
323 auto pipeline = shader->Shader->Pipeline;
324 compiledShader = new ILShader();
325 compiledShader->Name = EscapeCodeName(shader->Shader->Name);
326 compiledShader->Position = shader->Shader->Position;
327
328 GenerateParameterBindingInfo(shader);
329
330 TranslateStages(pipeline->SyntaxNode);
331 result.Program->Shaders.Add(compiledShader);
332
333 genericTypeMappings.Clear();
334
335 // pass 1: iterating all worlds
336 // create ILWorld and ILRecordType objects for all worlds
337
338 for (auto & world : pipeline->Worlds)
339 {
340 auto w = new ILWorld();
341 auto recordType = new ILRecordType();
342 recordType->TypeName = world.Key;
343 genericTypeMappings[world.Key] = recordType;
344 w->Name = world.Key;
345 w->OutputType = recordType;
346 w->Attributes = CopyLayoutAttributes(world.Value);
347 w->Shader = compiledShader.Ptr();
348 w->IsAbstract = world.Value->IsAbstract();
349 auto impOps = pipeline->GetImportOperatorsFromSourceWorld(world.Key);
350 w->Position = world.Value->Position;
351 compiledShader->Worlds[world.Key] = w;
352 }
353
354 // pass 2: iterating all worlds:
355 // 1) Gather list of components for each world, and store it in worldComps dictionary.
356 // 2) For each abstract world, add its components to record type
357
358 Dictionary<String, List<ComponentDefinitionIR*>> worldComps;
359 auto worlds = From(pipeline->Worlds).Select([](KeyValuePair<String, WorldSyntaxNode*> kv) {return kv.Key; }).Concat(FromSingle(String("<uniform>")));
360 //worlds.Add("<uniform>");
361 for (auto world : worlds)
362 {
363 // gather list of components
364 List<ComponentDefinitionIR*> components;
365 for (auto & compDef : shader->Definitions)
366 if (compDef->World == world)
367 components.Add(compDef.Ptr());
368 // for abstract world, fill in record type now
369 if (world != "<uniform>" && pipeline->Worlds[world]()->IsAbstract())
370 {
371 auto compiledWorld = compiledShader->Worlds[world]();
372 for (auto & comp : components)
373 {
374 ILObjectDefinition compDef;
375 compDef.Attributes = CopyLayoutAttributes(comp->SyntaxNode.Ptr());
376 compDef.Name = comp->UniqueName;
377 compDef.Type = TranslateExpressionType(comp->Type.Ptr());

Callers 1

CompileMethod · 0.80

Calls 15

EscapeCodeNameFunction · 0.85
FromFunction · 0.85
FromSingleFunction · 0.85
StringClass · 0.85
DependencySortFunction · 0.85
ILParameterClass · 0.85
IsAbstractMethod · 0.80
ConcatMethod · 0.80
IsInputMethod · 0.80
IsOutputMethod · 0.80

Tested by

no test coverage detected