spirv-val: Accept valid OpSizeOf instructions (#5879)

Ensure valid `OpSizeOf` instructions are not rejected by spirv-val.
Until now, validation of a valid `OpSizeOf` instruction would fail
with the message that the operand "cannot be a type".

Signed-off-by: Sven van Haastregt <sven.vanhaastregt@arm.com>
This commit is contained in:
Sven van Haastregt 2024-11-13 16:54:31 +01:00 committed by GitHub
parent 692529b941
commit 35e5f1160e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 0 deletions

View File

@ -163,6 +163,7 @@ spv_result_t IdPass(ValidationState_t& _, Instruction* inst) {
!spvOpcodeGeneratesType(opcode) && !spvOpcodeIsDebug(opcode) &&
!inst->IsDebugInfo() && !inst->IsNonSemantic() &&
!spvOpcodeIsDecoration(opcode) && opcode != spv::Op::OpFunction &&
opcode != spv::Op::OpSizeOf &&
opcode != spv::Op::OpCooperativeMatrixLengthNV &&
opcode != spv::Op::OpCooperativeMatrixLengthKHR &&
!spvOpcodeGeneratesUntypedPointer(opcode) &&
@ -185,6 +186,7 @@ spv_result_t IdPass(ValidationState_t& _, Instruction* inst) {
opcode != spv::Op::OpSelectionMerge &&
opcode != spv::Op::OpLoopMerge &&
opcode != spv::Op::OpFunction &&
opcode != spv::Op::OpSizeOf &&
opcode != spv::Op::OpCooperativeMatrixLengthNV &&
opcode != spv::Op::OpCooperativeMatrixLengthKHR &&
!spvOpcodeGeneratesUntypedPointer(opcode) &&

View File

@ -84,6 +84,27 @@ OpMemoryModel Logical GLSL450
HasSubstr("Cannot create undefined values with 8- or 16-bit types"));
}
TEST_F(ValidateMisc, SizeOfValid) {
const std::string spirv = R"(
OpCapability Addresses
OpCapability Kernel
OpMemoryModel Physical64 OpenCL
OpEntryPoint Kernel %f "f"
%void = OpTypeVoid
%i32 = OpTypeInt 32 0
%ptr = OpTypePointer CrossWorkgroup %i32
%fnTy = OpTypeFunction %void
%f = OpFunction %void None %fnTy
%entry = OpLabel
%s = OpSizeOf %i32 %ptr
OpReturn
OpFunctionEnd
)";
CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_1);
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_1));
}
const std::string ShaderClockSpirv = R"(
OpCapability Shader
OpCapability Int64