Fix validation of constant matrices (#2794)

Fixes #2793

* Don't special case matrix validation compared to other composites
  * just check the constituents are constants or undefs
  * later checking validates the column type
  * new test
This commit is contained in:
alan-baker 2019-08-14 11:26:41 -04:00 committed by GitHub
parent 60043edfa1
commit bbd80462f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 5 deletions

View File

@ -116,15 +116,13 @@ spv_result_t ValidateConstantComposite(ValidationState_t& _,
inst->GetOperandAs<uint32_t>(constituent_index); inst->GetOperandAs<uint32_t>(constituent_index);
const auto constituent = _.FindDef(constituent_id); const auto constituent = _.FindDef(constituent_id);
if (!constituent || if (!constituent ||
!(SpvOpConstantComposite == constituent->opcode() || !spvOpcodeIsConstantOrUndef(constituent->opcode())) {
SpvOpSpecConstantComposite == constituent->opcode() ||
SpvOpUndef == constituent->opcode())) {
// The message says "... or undef" because the spec does not say // The message says "... or undef" because the spec does not say
// undef is a constant. // undef is a constant.
return _.diag(SPV_ERROR_INVALID_ID, inst) return _.diag(SPV_ERROR_INVALID_ID, inst)
<< opcode_name << " Constituent <id> '" << opcode_name << " Constituent <id> '"
<< _.getIdName(constituent_id) << _.getIdName(constituent_id)
<< "' is not a constant composite or undef."; << "' is not a constant or undef.";
} }
const auto vector = _.FindDef(constituent->type_id()); const auto vector = _.FindDef(constituent->type_id());
if (!vector) { if (!vector) {

View File

@ -442,6 +442,22 @@ OpMemoryModel Logical GLSL450
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3)); EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
} }
TEST_F(ValidateConstant, NullMatrix) {
std::string spirv = R"(
OpCapability Shader
OpCapability Linkage
OpMemoryModel Logical GLSL450
%float = OpTypeFloat 32
%v2float = OpTypeVector %float 2
%mat2x2 = OpTypeMatrix %v2float 2
%null_vector = OpConstantNull %v2float
%null_matrix = OpConstantComposite %mat2x2 %null_vector %null_vector
)";
CompileSuccessfully(spirv);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
}
} // namespace } // namespace
} // namespace val } // namespace val
} // namespace spvtools } // namespace spvtools

View File

@ -1715,7 +1715,7 @@ TEST_F(ValidateIdWithMessage,
EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions()); EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
EXPECT_THAT(getDiagnosticString(), EXPECT_THAT(getDiagnosticString(),
HasSubstr("OpSpecConstantComposite Constituent <id> '7[%7]' is " HasSubstr("OpSpecConstantComposite Constituent <id> '7[%7]' is "
"not a constant composite or undef.")); "not a constant or undef."));
} }
// Invalid: Composite contains a column that is *not* a vector (it's an array) // Invalid: Composite contains a column that is *not* a vector (it's an array)