| 2100 | } |
| 2101 | |
| 2102 | spv_result_t ValidateImageQuerySizeLod(ValidationState_t& _, |
| 2103 | const Instruction* inst) { |
| 2104 | const uint32_t result_type = inst->type_id(); |
| 2105 | if (!_.IsIntScalarOrVectorType(result_type)) { |
| 2106 | return _.diag(SPV_ERROR_INVALID_DATA, inst) |
| 2107 | << "Expected Result Type to be int scalar or vector type"; |
| 2108 | } |
| 2109 | |
| 2110 | const uint32_t image_type = _.GetOperandTypeId(inst, 2); |
| 2111 | if (_.GetIdOpcode(image_type) != spv::Op::OpTypeImage) { |
| 2112 | return _.diag(SPV_ERROR_INVALID_DATA, inst) |
| 2113 | << "Expected Image to be of type OpTypeImage"; |
| 2114 | } |
| 2115 | |
| 2116 | ImageTypeInfo info; |
| 2117 | if (!GetImageTypeInfo(_, image_type, &info)) { |
| 2118 | return _.diag(SPV_ERROR_INVALID_DATA, inst) |
| 2119 | << "Corrupt image type definition"; |
| 2120 | } |
| 2121 | |
| 2122 | uint32_t expected_num_components = info.arrayed; |
| 2123 | switch (info.dim) { |
| 2124 | case spv::Dim::Dim1D: |
| 2125 | expected_num_components += 1; |
| 2126 | break; |
| 2127 | case spv::Dim::Dim2D: |
| 2128 | case spv::Dim::Cube: |
| 2129 | expected_num_components += 2; |
| 2130 | break; |
| 2131 | case spv::Dim::Dim3D: |
| 2132 | expected_num_components += 3; |
| 2133 | break; |
| 2134 | default: |
| 2135 | return _.diag(SPV_ERROR_INVALID_DATA, inst) |
| 2136 | << "Image 'Dim' must be 1D, 2D, 3D or Cube"; |
| 2137 | } |
| 2138 | |
| 2139 | if (info.multisampled != 0) { |
| 2140 | return _.diag(SPV_ERROR_INVALID_DATA, inst) << "Image 'MS' must be 0"; |
| 2141 | } |
| 2142 | |
| 2143 | const auto target_env = _.context()->target_env; |
| 2144 | if (spvIsVulkanEnv(target_env)) { |
| 2145 | if (info.sampled != 1) { |
| 2146 | return _.diag(SPV_ERROR_INVALID_DATA, inst) |
| 2147 | << _.VkErrorID(4659) |
| 2148 | << "OpImageQuerySizeLod must only consume an \"Image\" operand " |
| 2149 | "whose type has its \"Sampled\" operand set to 1"; |
| 2150 | } |
| 2151 | } |
| 2152 | |
| 2153 | uint32_t result_num_components = _.GetDimension(result_type); |
| 2154 | if (result_num_components != expected_num_components) { |
| 2155 | return _.diag(SPV_ERROR_INVALID_DATA, inst) |
| 2156 | << "Result Type has " << result_num_components << " components, " |
| 2157 | << "but " << expected_num_components << " expected"; |
| 2158 | } |
| 2159 |
no test coverage detected