From: David Neto Date: Tue, 2 Feb 2016 17:12:48 +0000 (-0500) Subject: Validation of mask operand capabilities is more data driven X-Git-Tag: upstream/2018.6~1351 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=adb8725900a4bddc80dfc6892de1f1a8603e888e;p=platform%2Fupstream%2FSPIRV-Tools.git Validation of mask operand capabilities is more data driven Use spvOperandIsConcreteMask to determine if an operand is a bitmask. Check its individual bits in a generic way. --- diff --git a/source/validate_instruction.cpp b/source/validate_instruction.cpp index c1a9574..586dfa5 100644 --- a/source/validate_instruction.cpp +++ b/source/validate_instruction.cpp @@ -92,23 +92,26 @@ spv_result_t CapCheck(ValidationState_t& _, for (int i = 0; i < inst->num_operands; ++i) { const auto& operand = inst->operands[i]; const auto word = inst->words[operand.offset]; - auto caps = RequiredCapabilities(_.grammar(), operand.type, word); - if (!_.HasAnyOf(caps)) - return CapabilityError(_, i + 1, inst->opcode, - ToString(caps, _.grammar())); - if (operand.type == SPV_OPERAND_TYPE_IMAGE) - for (auto individual_operand : - {SpvImageOperandsBiasMask, SpvImageOperandsLodMask, - SpvImageOperandsGradMask, SpvImageOperandsConstOffsetMask, - SpvImageOperandsOffsetMask, SpvImageOperandsConstOffsetsMask, - SpvImageOperandsSampleMask, SpvImageOperandsMinLodMask}) - if (word & individual_operand) { - caps = RequiredCapabilities(_.grammar(), SPV_OPERAND_TYPE_IMAGE, - individual_operand); - if (!_.HasAnyOf(caps)) + if (spvOperandIsConcreteMask(operand.type)) { + // Check for required capabilities for each bit position of the mask. + for (uint32_t mask_bit = 0x80000000; mask_bit; mask_bit >>= 1) { + if (word & mask_bit) { + const auto caps = + RequiredCapabilities(_.grammar(), operand.type, mask_bit); + if (!_.HasAnyOf(caps)) { return CapabilityError(_, i + 1, inst->opcode, ToString(caps, _.grammar())); + } } + } + } else { + // Check the operand word as a whole. + const auto caps = RequiredCapabilities(_.grammar(), operand.type, word); + if (!_.HasAnyOf(caps)) { + return CapabilityError(_, i + 1, inst->opcode, + ToString(caps, _.grammar())); + } + } } return SPV_SUCCESS; }