Returns scalar alignment of a type.
| 254 | |
| 255 | // Returns scalar alignment of a type. |
| 256 | uint32_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. |
no test coverage detected