Skip to content

Commit

Permalink
spirv-val: Accept valid OpSizeOf instructions (#5879)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
svenvh authored Nov 13, 2024
1 parent 692529b commit 35e5f11
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions source/val/validate_id.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand All @@ -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) &&
Expand Down
21 changes: 21 additions & 0 deletions test/val/val_misc_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 35e5f11

Please sign in to comment.