| 2166 | } |
| 2167 | |
| 2168 | spv_result_t ValidateImageQuerySize(ValidationState_t& _, |
| 2169 | const Instruction* inst) { |
| 2170 | const uint32_t result_type = inst->type_id(); |
| 2171 | if (!_.IsIntScalarOrVectorType(result_type)) { |
| 2172 | return _.diag(SPV_ERROR_INVALID_DATA, inst) |
| 2173 | << "Expected Result Type to be int scalar or vector type"; |
| 2174 | } |
| 2175 | |
| 2176 | const uint32_t image_type = _.GetOperandTypeId(inst, 2); |
| 2177 | if (_.GetIdOpcode(image_type) != spv::Op::OpTypeImage) { |
| 2178 | return _.diag(SPV_ERROR_INVALID_DATA, inst) |
| 2179 | << "Expected Image to be of type OpTypeImage"; |
| 2180 | } |
| 2181 | |
| 2182 | ImageTypeInfo info; |
| 2183 | if (!GetImageTypeInfo(_, image_type, &info)) { |
| 2184 | return _.diag(SPV_ERROR_INVALID_DATA, inst) |
| 2185 | << "Corrupt image type definition"; |
| 2186 | } |
| 2187 | |
| 2188 | uint32_t expected_num_components = info.arrayed; |
| 2189 | switch (info.dim) { |
| 2190 | case spv::Dim::Dim1D: |
| 2191 | case spv::Dim::Buffer: |
| 2192 | expected_num_components += 1; |
| 2193 | break; |
| 2194 | case spv::Dim::Dim2D: |
| 2195 | case spv::Dim::Cube: |
| 2196 | case spv::Dim::Rect: |
| 2197 | expected_num_components += 2; |
| 2198 | break; |
| 2199 | case spv::Dim::Dim3D: |
| 2200 | expected_num_components += 3; |
| 2201 | break; |
| 2202 | default: |
| 2203 | return _.diag(SPV_ERROR_INVALID_DATA, inst) |
| 2204 | << "Image 'Dim' must be 1D, Buffer, 2D, Cube, 3D or Rect"; |
| 2205 | } |
| 2206 | |
| 2207 | if (info.dim == spv::Dim::Dim1D || info.dim == spv::Dim::Dim2D || |
| 2208 | info.dim == spv::Dim::Dim3D || info.dim == spv::Dim::Cube) { |
| 2209 | if (info.multisampled != 1 && info.sampled != 0 && info.sampled != 2) { |
| 2210 | return _.diag(SPV_ERROR_INVALID_DATA, inst) |
| 2211 | << "Image must have either 'MS'=1 or 'Sampled'=0 or 'Sampled'=2"; |
| 2212 | } |
| 2213 | } |
| 2214 | |
| 2215 | uint32_t result_num_components = _.GetDimension(result_type); |
| 2216 | if (result_num_components != expected_num_components) { |
| 2217 | return _.diag(SPV_ERROR_INVALID_DATA, inst) |
| 2218 | << "Result Type has " << result_num_components << " components, " |
| 2219 | << "but " << expected_num_components << " expected"; |
| 2220 | } |
| 2221 | |
| 2222 | return SPV_SUCCESS; |
| 2223 | } |
| 2224 | |
| 2225 | spv_result_t ValidateImageQueryFormatOrOrder(ValidationState_t& _, |
no test coverage detected