MCPcopy Create free account
hub / github.com/KhronosGroup/SPIRV-Tools / getPackedAlignment

Method getPackedAlignment

source/opt/struct_packing_pass.cpp:168–224  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

166}
167
168uint32_t StructPackingPass::getPackedAlignment(
169 const analysis::Type& type) const {
170 switch (type.kind()) {
171 case analysis::Type::kArray: {
172 // Get alignment of base type and round up to minimum alignment
173 const uint32_t minAlignment = isPackingVec4Padded(packingRules_) ? 16 : 1;
174 return std::max<uint32_t>(
175 minAlignment, getPackedAlignment(*type.AsArray()->element_type()));
176 }
177 case analysis::Type::kStruct: {
178 // Rule 9. Struct alignment is maximum alignmnet of its members
179 uint32_t alignment = 1;
180
181 for (const analysis::Type* elementType :
182 type.AsStruct()->element_types()) {
183 alignment =
184 std::max<uint32_t>(alignment, getPackedAlignment(*elementType));
185 }
186
187 if (isPackingVec4Padded(packingRules_))
188 alignment = std::max<uint32_t>(alignment, 16u);
189
190 return alignment;
191 }
192 default: {
193 const uint32_t baseAlignment = getPackedBaseSize(type);
194
195 // Scalar block layout always uses alignment for the most basic component
196 if (isPackingScalar(packingRules_)) return baseAlignment;
197
198 if (const analysis::Matrix* matrixType = type.AsMatrix()) {
199 // Rule 5/7
200 if (isPackingVec4Padded(packingRules_) ||
201 matrixType->element_count() == 3)
202 return baseAlignment * 4;
203 else
204 return baseAlignment * matrixType->element_count();
205 } else if (const analysis::Vector* vectorType = type.AsVector()) {
206 // Rule 1
207 if (vectorType->element_count() == 1) return baseAlignment;
208
209 // Rule 2
210 if (vectorType->element_count() == 2 ||
211 vectorType->element_count() == 4)
212 return baseAlignment * vectorType->element_count();
213
214 // Rule 3
215 if (vectorType->element_count() == 3) return baseAlignment * 4;
216 } else {
217 // Rule 1
218 return baseAlignment;
219 }
220 }
221 }
222 assert(0 && "Unrecognized type to get packed alignment");
223 return 0;
224}
225

Callers

nothing calls this directly

Calls 10

isPackingVec4PaddedFunction · 0.85
getPackedBaseSizeFunction · 0.85
isPackingScalarFunction · 0.85
kindMethod · 0.80
AsArrayMethod · 0.80
AsStructMethod · 0.80
AsMatrixMethod · 0.80
AsVectorMethod · 0.80
element_typeMethod · 0.45
element_countMethod · 0.45

Tested by

no test coverage detected