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

Function GetSize

Source/SpireCore/SpirVCodeGen.cpp:464–493  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

462 }
463
464 int GetSize(ILType* Type, int UniformOrBuffer)
465 {
466 auto RoundUpTo = [](int x, int r)
467 {
468 if (x%r)
469 x += r - x%r;
470 return x;
471 };
472
473 if (auto basicType = dynamic_cast<ILBasicType*>(Type))
474 {
475 return Type->GetSize();
476 }
477 else if (auto arrayType = dynamic_cast<ILArrayType*>(Type))
478 {
479 return GetSize(arrayType->BaseType.Ptr(), UniformOrBuffer) * arrayType->ArrayLength;
480 }
481 else if (auto structType = dynamic_cast<ILStructType*>(Type))
482 {
483 int rs = 0;
484 for (auto &member : structType->Members)
485 {
486 int memberAlignment = GetBaseAlignment(member.Type.Ptr(), UniformOrBuffer);
487 rs = RoundUpTo(rs, memberAlignment);
488 rs += GetSize(member.Type.Ptr(), UniformOrBuffer);
489 }
490 return rs;
491 }
492 return 0;
493 }
494
495 enum class IDClass
496 {

Callers 1

DefineTypeMethod · 0.85

Calls 2

GetBaseAlignmentFunction · 0.85
PtrMethod · 0.45

Tested by

no test coverage detected