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

Function getScalarAlignment

source/val/validate_decorations.cpp:256–304  ·  view source on GitHub ↗

Returns scalar alignment of a type.

Source from the content-addressed store, hash-verified

254
255// Returns scalar alignment of a type.
256uint32_t getScalarAlignment(uint32_t type_id, ValidationState_t& vstate) {
257 const auto inst = vstate.FindDef(type_id);
258 const auto& words = inst->words();
259 switch (inst->opcode()) {
260 case spv::Op::OpTypeSampledImage:
261 case spv::Op::OpTypeSampler:
262 case spv::Op::OpTypeImage:
263 if (vstate.HasCapability(spv::Capability::BindlessTextureNV))
264 return vstate.samplerimage_variable_address_mode() / 8;
265 // SPV_EXT_descriptor_heap provides a way to access opaque images, we
266 // assume alignment is validated at runtime as it is determined by the
267 // client API
268 if (vstate.HasCapability(spv::Capability::DescriptorHeapEXT)) return 1;
269 assert(0);
270 return 0;
271 case spv::Op::OpTypeInt:
272 case spv::Op::OpTypeFloat:
273 return words[2] / 8;
274 case spv::Op::OpTypeVector:
275 case spv::Op::OpTypeVectorIdEXT:
276 case spv::Op::OpTypeMatrix:
277 case spv::Op::OpTypeArray:
278 case spv::Op::OpTypeRuntimeArray: {
279 const auto compositeMemberTypeId = words[2];
280 return getScalarAlignment(compositeMemberTypeId, vstate);
281 }
282 case spv::Op::OpTypeStruct: {
283 const auto members = getStructMembers(type_id, vstate);
284 uint32_t max_member_alignment = 1;
285 for (uint32_t memberIdx = 0, numMembers = uint32_t(members.size());
286 memberIdx < numMembers; ++memberIdx) {
287 const auto id = members[memberIdx];
288 uint32_t member_alignment = getScalarAlignment(id, vstate);
289 if (member_alignment > max_member_alignment) {
290 max_member_alignment = member_alignment;
291 }
292 }
293 return max_member_alignment;
294 } break;
295 case spv::Op::OpTypePointer:
296 case spv::Op::OpTypeUntypedPointerKHR:
297 return vstate.pointer_size_and_alignment();
298 default:
299 assert(0);
300 break;
301 }
302
303 return 1;
304}
305
306// Returns size of a struct member. Doesn't include padding at the end of struct
307// or array. Assumes that in the struct case, all members have offsets.

Callers 1

checkLayoutFunction · 0.85

Calls 7

getStructMembersFunction · 0.85
FindDefMethod · 0.80
opcodeMethod · 0.45
HasCapabilityMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected