Returns the number of components consumed by types that support a component decoration.
| 228 | // Returns the number of components consumed by types that support a component |
| 229 | // decoration. |
| 230 | uint32_t NumConsumedComponents(ValidationState_t& _, const Instruction* type) { |
| 231 | uint32_t num_components = 0; |
| 232 | switch (type->opcode()) { |
| 233 | case spv::Op::OpTypeInt: |
| 234 | case spv::Op::OpTypeFloat: |
| 235 | // 64-bit types consume two components. |
| 236 | if (type->GetOperandAs<uint32_t>(1) == 64) { |
| 237 | num_components = 2; |
| 238 | } else { |
| 239 | num_components = 1; |
| 240 | } |
| 241 | break; |
| 242 | case spv::Op::OpTypeVector: |
| 243 | case spv::Op::OpTypeVectorIdEXT: |
| 244 | // Vectors consume components equal to the underlying type's consumption |
| 245 | // times the number of elements in the vector. Note that 3- and 4-element |
| 246 | // vectors cannot have a component decoration (i.e. assumed to be zero). |
| 247 | num_components = |
| 248 | NumConsumedComponents(_, _.FindDef(type->GetOperandAs<uint32_t>(1))); |
| 249 | num_components *= _.GetDimension(type->id()); |
| 250 | break; |
| 251 | case spv::Op::OpTypeArray: |
| 252 | // Skip the array. |
| 253 | return NumConsumedComponents(_, |
| 254 | _.FindDef(type->GetOperandAs<uint32_t>(1))); |
| 255 | case spv::Op::OpTypePointer: |
| 256 | if (_.addressing_model() == |
| 257 | spv::AddressingModel::PhysicalStorageBuffer64 && |
| 258 | type->GetOperandAs<spv::StorageClass>(1) == |
| 259 | spv::StorageClass::PhysicalStorageBuffer) { |
| 260 | return 2; |
| 261 | } |
| 262 | break; |
| 263 | default: |
| 264 | // This is an error that is validated elsewhere. |
| 265 | break; |
| 266 | } |
| 267 | |
| 268 | return num_components; |
| 269 | } |
| 270 | |
| 271 | // Populates |locations| (and/or |output_index1_locations|) with the use |
| 272 | // location and component coordinates for |variable|. Indices are calculated as |
no test coverage detected