39 Size structMemberOffset = 0;
40 Size maxMemberAlignment = 1;
42 for (uint32_t i = 0, e = structType.
getNumElements(); i < e; ++i) {
44 Size memberAlignment = 1;
48 structMemberOffset = llvm::alignTo(structMemberOffset, memberAlignment);
49 memberTypes.push_back(memberType);
54 assert(memberSize != std::numeric_limits<Size>().
max() ||
60 structMemberOffset += memberSize;
61 maxMemberAlignment =
std::max(maxMemberAlignment, memberAlignment);
68 size = llvm::alignTo(structMemberOffset, maxMemberAlignment);
69 alignment = maxMemberAlignment;
82 if (isa<spirv::ScalarType>(type)) {
83 alignment = getScalarTypeAlignment(type);
88 if (
auto structType = dyn_cast<spirv::StructType>(type))
90 if (
auto arrayType = dyn_cast<spirv::ArrayType>(type))
92 if (
auto vectorType = dyn_cast<VectorType>(type))
94 if (
auto arrayType = dyn_cast<spirv::RuntimeArrayType>(type)) {
95 size = std::numeric_limits<Size>().max();
98 if (isa<spirv::PointerType>(type)) {
102 llvm_unreachable(
"unhandled SPIR-V type");
109 auto elementType = vectorType.getElementType();
110 Size elementSize = 0;
111 Size elementAlignment = 1;
113 auto memberType =
decorateType(elementType, elementSize, elementAlignment);
119 size = elementSize * numElements;
120 alignment = numElements == 2 ? elementAlignment * 2 : elementAlignment * 4;
129 Size elementSize = 0;
130 Size elementAlignment = 1;
132 auto memberType =
decorateType(elementType, elementSize, elementAlignment);
136 size = elementSize * numElements;
137 alignment = elementAlignment;
144 Size elementSize = 0;
146 auto memberType =
decorateType(elementType, elementSize, alignment);
151 VulkanLayoutUtils::getScalarTypeAlignment(
Type scalarType) {
164 auto ptrType = dyn_cast<spirv::PointerType>(type);
169 auto storageClass = ptrType.getStorageClass();
170 auto structType = dyn_cast<spirv::StructType>(ptrType.getPointeeType());
175 switch (storageClass) {
176 case spirv::StorageClass::Uniform:
177 case spirv::StorageClass::StorageBuffer:
178 case spirv::StorageClass::PushConstant:
179 case spirv::StorageClass::PhysicalStorageBuffer:
static Value max(ImplicitLocOpBuilder &builder, Value value, Value bound)
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
unsigned getIntOrFloatBitWidth() const
Return the bit width of an integer or a float type, assert failure on other types.
static bool isLegalType(Type type)
Checks whether a type is legal in terms of Vulkan layout info decoration.
static spirv::StructType decorateType(spirv::StructType structType)
Returns a new StructType with layout decoration.
Type getElementType() const
unsigned getNumElements() const
static ArrayType get(Type elementType, unsigned elementCount)
Type getElementType() const
static RuntimeArrayType get(Type elementType)
void getMemberDecorations(SmallVectorImpl< StructType::MemberDecorationInfo > &memberDecorations) const
bool isIdentified() const
Returns true if the StructType is identified.
unsigned getNumElements() const
Type getElementType(unsigned) const
static StructType get(ArrayRef< Type > memberTypes, ArrayRef< OffsetInfo > offsetInfo={}, ArrayRef< MemberDecorationInfo > memberDecorations={})
Construct a literal StructType with at least one member.
Include the generated interface declarations.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...