UniformOrBuffer - 0: none; 1: uniform; 2: buffer
| 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 | { |
no test coverage detected