From 8f421ced3e052a4b1b16d25ad2e18d089c2332de Mon Sep 17 00:00:00 2001 From: sfricke-samsung <46493288+sfricke-samsung@users.noreply.github.com> Date: Fri, 19 Mar 2021 06:02:48 -0700 Subject: [PATCH] spirv-val: Label VUID 04643 (#4202) --- source/val/validate_memory.cpp | 1 + source/val/validate_type.cpp | 1 + source/val/validation_state.cpp | 14 ++++++++------ test/val/val_misc_test.cpp | 24 ++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/source/val/validate_memory.cpp b/source/val/validate_memory.cpp index 4dd6d9415..a4bc0faba 100644 --- a/source/val/validate_memory.cpp +++ b/source/val/validate_memory.cpp @@ -466,6 +466,7 @@ spv_result_t ValidateVariable(ValidationState_t& _, const Instruction* inst) { if (!_.IsValidStorageClass(storage_class)) { return _.diag(SPV_ERROR_INVALID_BINARY, inst) + << _.VkErrorID(4643) << "Invalid storage class for target environment"; } diff --git a/source/val/validate_type.cpp b/source/val/validate_type.cpp index 685064caa..612fc5c2c 100644 --- a/source/val/validate_type.cpp +++ b/source/val/validate_type.cpp @@ -463,6 +463,7 @@ spv_result_t ValidateTypePointer(ValidationState_t& _, if (!_.IsValidStorageClass(storage_class)) { return _.diag(SPV_ERROR_INVALID_BINARY, inst) + << _.VkErrorID(4643) << "Invalid storage class for target environment"; } diff --git a/source/val/validation_state.cpp b/source/val/validation_state.cpp index 1d2d09b1e..db86fd25e 100644 --- a/source/val/validation_state.cpp +++ b/source/val/validation_state.cpp @@ -1255,12 +1255,12 @@ bool ValidationState_t::IsValidStorageClass( case SpvStorageClassFunction: case SpvStorageClassPushConstant: case SpvStorageClassPhysicalStorageBuffer: - case SpvStorageClassRayPayloadNV: - case SpvStorageClassIncomingRayPayloadNV: - case SpvStorageClassHitAttributeNV: - case SpvStorageClassCallableDataNV: - case SpvStorageClassIncomingCallableDataNV: - case SpvStorageClassShaderRecordBufferNV: + case SpvStorageClassRayPayloadKHR: + case SpvStorageClassIncomingRayPayloadKHR: + case SpvStorageClassHitAttributeKHR: + case SpvStorageClassCallableDataKHR: + case SpvStorageClassIncomingCallableDataKHR: + case SpvStorageClassShaderRecordBufferKHR: return true; default: return false; @@ -1694,6 +1694,8 @@ std::string ValidationState_t::VkErrorID(uint32_t id, return VUID_WRAP(VUID-StandaloneSpirv-None-04641); case 4642: return VUID_WRAP(VUID-StandaloneSpirv-None-04642); + case 4643: + return VUID_WRAP(VUID-StandaloneSpirv-None-04643); case 4651: return VUID_WRAP(VUID-StandaloneSpirv-OpVariable-04651); case 4652: diff --git a/test/val/val_misc_test.cpp b/test/val/val_misc_test.cpp index 499b5b28a..b0e46bf95 100644 --- a/test/val/val_misc_test.cpp +++ b/test/val/val_misc_test.cpp @@ -273,6 +273,30 @@ TEST_F(ValidateMisc, UndefVoid) { EXPECT_THAT(getDiagnosticString(), HasSubstr("Cannot create undefined values with void type")); } + +TEST_F(ValidateMisc, VulkanInvalidStorageClass) { + const std::string spirv = R"( +OpCapability Shader +OpMemoryModel Logical GLSL450 +OpEntryPoint Vertex %func "shader" +%int = OpTypeInt 32 0 +%ptr = OpTypePointer CrossWorkgroup %int +%var = OpVariable %ptr CrossWorkgroup +%void = OpTypeVoid +%void_f = OpTypeFunction %void +%func = OpFunction %void None %void_f +%label = OpLabel + OpReturn + OpFunctionEnd +)"; + + CompileSuccessfully(spirv, SPV_ENV_VULKAN_1_0); + ASSERT_EQ(SPV_ERROR_INVALID_BINARY, ValidateInstructions(SPV_ENV_VULKAN_1_0)); + EXPECT_THAT(getDiagnosticString(), + AnyVUID("VUID-StandaloneSpirv-None-04643")); + EXPECT_THAT(getDiagnosticString(), + HasSubstr("Invalid storage class for target environment")); +} } // namespace } // namespace val } // namespace spvtools