|
30 | 30 | #include "source/val/construct.h" |
31 | 31 | #include "source/val/function.h" |
32 | 32 | #include "spirv-tools/libspirv.h" |
| 33 | +#include "spirv/unified1/spirv.hpp11" |
33 | 34 |
|
34 | 35 | namespace spvtools { |
35 | 36 | namespace val { |
@@ -926,22 +927,16 @@ uint32_t ValidationState_t::GetComponentType(uint32_t id) const { |
926 | 927 |
|
927 | 928 | case spv::Op::OpTypeArray: |
928 | 929 | case spv::Op::OpTypeRuntimeArray: |
929 | | - return inst->word(2); |
930 | | - |
931 | 930 | case spv::Op::OpTypeVector: |
932 | | - return inst->word(2); |
933 | | - |
934 | | - case spv::Op::OpTypeMatrix: |
935 | | - return GetComponentType(inst->word(2)); |
936 | | - |
| 931 | + case spv::Op::OpTypeVectorIdEXT: |
937 | 932 | case spv::Op::OpTypeCooperativeMatrixNV: |
938 | 933 | case spv::Op::OpTypeCooperativeMatrixKHR: |
939 | | - case spv::Op::OpTypeVectorIdEXT: |
940 | | - return inst->word(2); |
941 | | - |
942 | 934 | case spv::Op::OpTypeTensorARM: |
943 | 935 | return inst->word(2); |
944 | 936 |
|
| 937 | + case spv::Op::OpTypeMatrix: |
| 938 | + return GetComponentType(inst->word(2)); |
| 939 | + |
945 | 940 | default: |
946 | 941 | break; |
947 | 942 | } |
@@ -1547,6 +1542,57 @@ bool ValidationState_t::IsTensorType(uint32_t id) const { |
1547 | 1542 | return inst && inst->opcode() == spv::Op::OpTypeTensorARM; |
1548 | 1543 | } |
1549 | 1544 |
|
| 1545 | +// From the spec (SPIRV.html#PhysicalPointerType) |
| 1546 | +bool ValidationState_t::IsPhysicalPointerType(uint32_t id) const { |
| 1547 | + const Instruction* inst = FindDef(id); |
| 1548 | + const spv::Op opcode = inst->opcode(); |
| 1549 | + if (opcode != spv::Op::OpTypePointer && |
| 1550 | + opcode != spv::Op::OpTypeUntypedPointerKHR) { |
| 1551 | + return false; |
| 1552 | + } |
| 1553 | + |
| 1554 | + const spv::AddressingModel am = addressing_model(); |
| 1555 | + if (am == spv::AddressingModel::Logical) { |
| 1556 | + return false; |
| 1557 | + } else if (am == spv::AddressingModel::Physical32 || |
| 1558 | + am == spv::AddressingModel::Physical64) { |
| 1559 | + return true; |
| 1560 | + } else if (am == spv::AddressingModel::PhysicalStorageBuffer64) { |
| 1561 | + const spv::StorageClass storage_class = spv::StorageClass(inst->word(2)); |
| 1562 | + return storage_class == spv::StorageClass::PhysicalStorageBuffer; |
| 1563 | + } |
| 1564 | + |
| 1565 | + assert(0); |
| 1566 | + return false; |
| 1567 | +} |
| 1568 | + |
| 1569 | +// From the spec (SPIRV.html#Numerical) |
| 1570 | +bool ValidationState_t::IsNumericalType(uint32_t id) const { |
| 1571 | + const Instruction* inst = FindDef(id); |
| 1572 | + const spv::Op opcode = inst->opcode(); |
| 1573 | + return opcode == spv::Op::OpTypeInt || opcode == spv::Op::OpTypeFloat; |
| 1574 | +} |
| 1575 | + |
| 1576 | +// From the spec (SPIRV.html#Concrete) |
| 1577 | +bool ValidationState_t::IsConcreteType(uint32_t id) const { |
| 1578 | + const Instruction* inst = FindDef(id); |
| 1579 | + const spv::Op opcode = inst->opcode(); |
| 1580 | + |
| 1581 | + if (opcode == spv::Op::OpTypeStruct) { |
| 1582 | + // all elements must be concrete |
| 1583 | + for (uint32_t i = 1; i < inst->operands().size(); ++i) { |
| 1584 | + if (!IsConcreteType(inst->GetOperandAs<uint32_t>(i))) { |
| 1585 | + return false; |
| 1586 | + } |
| 1587 | + } |
| 1588 | + return true; |
| 1589 | + } |
| 1590 | + |
| 1591 | + const uint32_t component_type = GetComponentType(id); |
| 1592 | + return IsNumericalType(component_type) || |
| 1593 | + IsPhysicalPointerType(component_type); |
| 1594 | +} |
| 1595 | + |
1550 | 1596 | spv_result_t ValidationState_t::CooperativeMatrixShapesMatch( |
1551 | 1597 | const Instruction* inst, uint32_t result_type_id, uint32_t m2, |
1552 | 1598 | bool is_conversion, bool swap_row_col) { |
|
0 commit comments