From 35e5f1160ecd2b963682e14e869001a60160a0c4 Mon Sep 17 00:00:00 2001 From: Sven van Haastregt Date: Wed, 13 Nov 2024 16:54:31 +0100 Subject: [PATCH] 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 --- source/val/validate_id.cpp | 2 ++ test/val/val_misc_test.cpp | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/source/val/validate_id.cpp b/source/val/validate_id.cpp index 0d1e84123..00be150cb 100644 --- a/source/val/validate_id.cpp +++ b/source/val/validate_id.cpp @@ -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) && diff --git a/test/val/val_misc_test.cpp b/test/val/val_misc_test.cpp index 5304c59e0..2188e037c 100644 --- a/test/val/val_misc_test.cpp +++ b/test/val/val_misc_test.cpp @@ -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