mirror of
https://github.com/KhronosGroup/SPIRV-Tools
synced 2024-11-23 04:00:05 +00:00
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:
parent
60043edfa1
commit
bbd80462f5
@ -116,15 +116,13 @@ spv_result_t ValidateConstantComposite(ValidationState_t& _,
|
||||
inst->GetOperandAs<uint32_t>(constituent_index);
|
||||
const auto constituent = _.FindDef(constituent_id);
|
||||
if (!constituent ||
|
||||
!(SpvOpConstantComposite == constituent->opcode() ||
|
||||
SpvOpSpecConstantComposite == constituent->opcode() ||
|
||||
SpvOpUndef == constituent->opcode())) {
|
||||
!spvOpcodeIsConstantOrUndef(constituent->opcode())) {
|
||||
// The message says "... or undef" because the spec does not say
|
||||
// undef is a constant.
|
||||
return _.diag(SPV_ERROR_INVALID_ID, inst)
|
||||
<< opcode_name << " 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());
|
||||
if (!vector) {
|
||||
|
@ -442,6 +442,22 @@ OpMemoryModel Logical GLSL450
|
||||
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 val
|
||||
} // namespace spvtools
|
||||
|
@ -1715,7 +1715,7 @@ TEST_F(ValidateIdWithMessage,
|
||||
EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
|
||||
EXPECT_THAT(getDiagnosticString(),
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user