| 1314 | } |
| 1315 | |
| 1316 | spv_result_t ValidateSampledImage(ValidationState_t& _, |
| 1317 | const Instruction* inst) { |
| 1318 | auto type_inst = _.FindDef(inst->type_id()); |
| 1319 | if (type_inst->opcode() != spv::Op::OpTypeSampledImage) { |
| 1320 | return _.diag(SPV_ERROR_INVALID_DATA, inst) |
| 1321 | << "Expected Result Type to be OpTypeSampledImage."; |
| 1322 | } |
| 1323 | |
| 1324 | const uint32_t image_type = _.GetOperandTypeId(inst, 2); |
| 1325 | if (_.GetIdOpcode(image_type) != spv::Op::OpTypeImage) { |
| 1326 | return _.diag(SPV_ERROR_INVALID_DATA, inst) |
| 1327 | << "Expected Image to be of type OpTypeImage."; |
| 1328 | } |
| 1329 | |
| 1330 | ImageTypeInfo info; |
| 1331 | if (!GetImageTypeInfo(_, image_type, &info)) { |
| 1332 | return _.diag(SPV_ERROR_INVALID_DATA, inst) |
| 1333 | << "Corrupt image type definition"; |
| 1334 | } |
| 1335 | |
| 1336 | // Image operands must match except for depth. |
| 1337 | auto sampled_image_id = type_inst->GetOperandAs<uint32_t>(1); |
| 1338 | if (sampled_image_id != image_type) { |
| 1339 | ImageTypeInfo sampled_info; |
| 1340 | if (!GetImageTypeInfo(_, sampled_image_id, &sampled_info)) { |
| 1341 | return _.diag(SPV_ERROR_INVALID_DATA, inst) |
| 1342 | << "Corrupt image type definition"; |
| 1343 | } |
| 1344 | if (info.sampled_type != sampled_info.sampled_type || |
| 1345 | info.dim != sampled_info.dim || info.arrayed != sampled_info.arrayed || |
| 1346 | info.multisampled != sampled_info.multisampled || |
| 1347 | info.sampled != sampled_info.sampled || |
| 1348 | info.format != sampled_info.format || |
| 1349 | info.access_qualifier != sampled_info.access_qualifier) { |
| 1350 | return _.diag(SPV_ERROR_INVALID_DATA, inst) |
| 1351 | << "Image operands must match result image operands except for " |
| 1352 | "depth"; |
| 1353 | } |
| 1354 | } |
| 1355 | |
| 1356 | if (spvIsVulkanEnv(_.context()->target_env)) { |
| 1357 | if (info.sampled != 1) { |
| 1358 | return _.diag(SPV_ERROR_INVALID_DATA, inst) |
| 1359 | << _.VkErrorID(6671) |
| 1360 | << "Expected Image 'Sampled' parameter to be 1 for Vulkan " |
| 1361 | "environment."; |
| 1362 | } |
| 1363 | } else { |
| 1364 | if (info.sampled != 0 && info.sampled != 1) { |
| 1365 | return _.diag(SPV_ERROR_INVALID_DATA, inst) |
| 1366 | << "Expected Image 'Sampled' parameter to be 0 or 1"; |
| 1367 | } |
| 1368 | } |
| 1369 | |
| 1370 | if (info.dim == spv::Dim::SubpassData) { |
| 1371 | return _.diag(SPV_ERROR_INVALID_DATA, inst) |
| 1372 | << "Expected Image 'Dim' parameter to be not SubpassData."; |
| 1373 | } |
no test coverage detected