| 1729 | } |
| 1730 | |
| 1731 | spv_result_t ValidateImageFetch(ValidationState_t& _, const Instruction* inst) { |
| 1732 | uint32_t actual_result_type = 0; |
| 1733 | if (spv_result_t error = GetActualResultType(_, inst, &actual_result_type)) { |
| 1734 | return error; |
| 1735 | } |
| 1736 | |
| 1737 | const spv::Op opcode = inst->opcode(); |
| 1738 | if (!_.IsIntVectorType(actual_result_type) && |
| 1739 | !_.IsFloatVectorType(actual_result_type)) { |
| 1740 | return _.diag(SPV_ERROR_INVALID_DATA, inst) |
| 1741 | << "Expected " << GetActualResultTypeStr(opcode) |
| 1742 | << " to be int or float vector type"; |
| 1743 | } |
| 1744 | |
| 1745 | if (_.GetDimension(actual_result_type) != 4) { |
| 1746 | return _.diag(SPV_ERROR_INVALID_DATA, inst) |
| 1747 | << "Expected " << GetActualResultTypeStr(opcode) |
| 1748 | << " to have 4 components"; |
| 1749 | } |
| 1750 | |
| 1751 | const uint32_t image_type = _.GetOperandTypeId(inst, 2); |
| 1752 | if (_.GetIdOpcode(image_type) != spv::Op::OpTypeImage) { |
| 1753 | return _.diag(SPV_ERROR_INVALID_DATA, inst) |
| 1754 | << "Expected Image to be of type OpTypeImage"; |
| 1755 | } |
| 1756 | |
| 1757 | ImageTypeInfo info; |
| 1758 | if (!GetImageTypeInfo(_, image_type, &info)) { |
| 1759 | return _.diag(SPV_ERROR_INVALID_DATA, inst) |
| 1760 | << "Corrupt image type definition"; |
| 1761 | } |
| 1762 | |
| 1763 | if (_.GetIdOpcode(info.sampled_type) != spv::Op::OpTypeVoid) { |
| 1764 | const uint32_t result_component_type = |
| 1765 | _.GetComponentType(actual_result_type); |
| 1766 | if (result_component_type != info.sampled_type) { |
| 1767 | return _.diag(SPV_ERROR_INVALID_DATA, inst) |
| 1768 | << "Expected Image 'Sampled Type' to be the same as " |
| 1769 | << GetActualResultTypeStr(opcode) << " components"; |
| 1770 | } |
| 1771 | } |
| 1772 | |
| 1773 | if (info.dim == spv::Dim::Cube) { |
| 1774 | return _.diag(SPV_ERROR_INVALID_DATA, inst) << "Image 'Dim' cannot be Cube"; |
| 1775 | } |
| 1776 | |
| 1777 | if (info.sampled != 1) { |
| 1778 | return _.diag(SPV_ERROR_INVALID_DATA, inst) |
| 1779 | << "Expected Image 'Sampled' parameter to be 1"; |
| 1780 | } |
| 1781 | |
| 1782 | if (spv_result_t result = |
| 1783 | ValidateImageCoordinate(_, inst, info, /* word_index = */ 3)) |
| 1784 | return result; |
| 1785 | |
| 1786 | if (spv_result_t result = |
| 1787 | ValidateImageOperands(_, inst, info, /* word_index = */ 6)) |
| 1788 | return result; |
no test coverage detected