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

Function GetBaseAlignment

Source/SpireCore/SpirVCodeGen.cpp:430–462  ·  view source on GitHub ↗

UniformOrBuffer - 0: none; 1: uniform; 2: buffer

Source from the content-addressed store, hash-verified

428
429 //UniformOrBuffer - 0: none; 1: uniform; 2: buffer
430 int GetBaseAlignment(ILType* Type, int UniformOrBuffer)
431 {
432 auto RoundUpTo = [](int x, int r)
433 {
434 if (x%r)
435 x += r - x%r;
436 return x;
437 };
438 if (auto basicType = dynamic_cast<ILBasicType*>(Type))
439 {
440 return Type->GetAlignment();
441 }
442 else if (auto arrayType = dynamic_cast<ILArrayType*>(Type))
443 {
444 int elementAlignment = GetBaseAlignment(arrayType->BaseType.Ptr(), UniformOrBuffer);
445 if (UniformOrBuffer == 1)
446 elementAlignment = RoundUpTo(elementAlignment, 16);
447 return elementAlignment;
448 }
449 else if (auto structType = dynamic_cast<ILStructType*>(Type))
450 {
451 int maxAlignment = -1;
452 for (auto &member : structType->Members)
453 {
454 int memberAlignment = GetBaseAlignment(member.Type.Ptr(), UniformOrBuffer);
455 maxAlignment = std::max(maxAlignment, memberAlignment);
456 }
457 if (UniformOrBuffer == 1)
458 maxAlignment = RoundUpTo(maxAlignment, 16);
459 return maxAlignment;
460 }
461 return -1;
462 }
463
464 int GetSize(ILType* Type, int UniformOrBuffer)
465 {

Callers 2

GetSizeFunction · 0.85
DefineTypeMethod · 0.85

Calls 1

PtrMethod · 0.45

Tested by

no test coverage detected