spirv-fuzz: Fix PartialCount (#4159)

Fixes #4158.
This commit is contained in:
Vasyl Teliman 2021-03-05 13:13:28 +02:00 committed by GitHub
parent f7043c0de6
commit 7d514cf1c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 13 deletions

View File

@ -77,12 +77,14 @@ bool TransformationSetLoopControl::IsApplicable(
}
}
if ((message_.loop_control() &
(SpvLoopControlPeelCountMask | SpvLoopControlPartialCountMask)) &&
!(PeelCountIsSupported(ir_context) &&
PartialCountIsSupported(ir_context))) {
// At least one of PeelCount or PartialCount is used, but the SPIR-V version
// in question does not support these loop controls.
// Check that PeelCount and PartialCount are supported if used.
if ((message_.loop_control() & SpvLoopControlPeelCountMask) &&
!PeelCountIsSupported(ir_context)) {
return false;
}
if ((message_.loop_control() & SpvLoopControlPartialCountMask) &&
!PartialCountIsSupported(ir_context)) {
return false;
}
@ -183,14 +185,16 @@ bool TransformationSetLoopControl::LoopControlBitIsAddedByTransformation(
bool TransformationSetLoopControl::PartialCountIsSupported(
opt::IRContext* ir_context) {
// TODO(afd): We capture the universal environments for which this loop
// control is definitely not supported. The check should be refined on
// demand for other target environments.
// TODO(afd): We capture the environments for which this loop control is
// definitely not supported. The check should be refined on demand for other
// target environments.
switch (ir_context->grammar().target_env()) {
case SPV_ENV_UNIVERSAL_1_0:
case SPV_ENV_UNIVERSAL_1_1:
case SPV_ENV_UNIVERSAL_1_2:
case SPV_ENV_UNIVERSAL_1_3:
case SPV_ENV_VULKAN_1_0:
case SPV_ENV_VULKAN_1_1:
return false;
default:
return true;

View File

@ -958,8 +958,10 @@ TEST(TransformationSetLoopControlTest, CheckSPIRVVersionsRespected) {
context.get(), validator_options, kConsoleMessageConsumer));
TransformationContext transformation_context(
MakeUnique<FactManager>(context.get()), validator_options);
TransformationSetLoopControl transformation(
10, SpvLoopControlPeelCountMask | SpvLoopControlPartialCountMask, 4, 4);
TransformationSetLoopControl peel_count(
10, SpvLoopControlPeelCountMask, 4, 0);
TransformationSetLoopControl partial_count(
10, SpvLoopControlPartialCountMask, 0, 4);
switch (env) {
case SPV_ENV_UNIVERSAL_1_0:
@ -971,14 +973,18 @@ TEST(TransformationSetLoopControlTest, CheckSPIRVVersionsRespected) {
// PeelCount and PartialCount were introduced in SPIRV 1.4, so are not
// valid in the context of older versions.
ASSERT_FALSE(
transformation.IsApplicable(context.get(), transformation_context));
peel_count.IsApplicable(context.get(), transformation_context));
ASSERT_FALSE(
partial_count.IsApplicable(context.get(), transformation_context));
break;
case SPV_ENV_UNIVERSAL_1_4:
case SPV_ENV_UNIVERSAL_1_5:
case SPV_ENV_VULKAN_1_1_SPIRV_1_4:
case SPV_ENV_VULKAN_1_2:
ASSERT_TRUE(
transformation.IsApplicable(context.get(), transformation_context));
peel_count.IsApplicable(context.get(), transformation_context));
ASSERT_TRUE(
partial_count.IsApplicable(context.get(), transformation_context));
break;
default:
assert(false && "Unhandled environment");