spirv-val: Label standalone Vulkan VUID (#4091)

This commit is contained in:
sfricke-samsung 2021-01-07 06:00:05 -08:00 committed by GitHub
parent aa005e8bd4
commit ad77ed7a8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 63 additions and 6 deletions

View File

@ -824,7 +824,7 @@ spv_result_t ValidateTypeImage(ValidationState_t& _, const Instruction* inst) {
if (spvIsVulkanEnv(target_env) || spvIsWebGPUEnv(target_env)) {
if (info.sampled == 0) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Sampled must be 1 or 2 in the "
<< _.VkErrorID(4657) << "Sampled must be 1 or 2 in the "
<< (spvIsVulkanEnv(target_env) ? "Vulkan" : "WebGPU")
<< " environment.";
}

View File

@ -585,7 +585,8 @@ spv_result_t ValidateVariable(ValidationState_t& _, const Instruction* inst) {
storage_class != SpvStorageClassFunction) {
if (spvIsVulkanOrWebGPUEnv(_.context()->target_env)) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "OpVariable, <id> '" << _.getIdName(inst->id())
<< _.VkErrorID(4651) << "OpVariable, <id> '"
<< _.getIdName(inst->id())
<< "', has a disallowed initializer & storage class "
<< "combination.\n"
<< "From " << spvLogStringForEnv(_.context()->target_env)

View File

@ -221,7 +221,7 @@ spv_result_t ValidateMemorySemantics(ValidationState_t& _,
if (opcode == SpvOpMemoryBarrier && !num_memory_order_set_bits) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< spvOpcodeString(opcode)
<< _.VkErrorID(4649) << spvOpcodeString(opcode)
<< ": Vulkan specification requires Memory Semantics to have "
"one "
"of the following bits set: Acquire, Release, "
@ -231,7 +231,7 @@ spv_result_t ValidateMemorySemantics(ValidationState_t& _,
if (opcode == SpvOpMemoryBarrier && !includes_storage_class) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< spvOpcodeString(opcode)
<< _.VkErrorID(4649) << spvOpcodeString(opcode)
<< ": expected Memory Semantics to include a Vulkan-supported "
"storage class";
}

View File

@ -56,7 +56,7 @@ spv_result_t ValidateShaderClock(ValidationState_t& _,
std::tie(is_int32, is_const_int32, value) = _.EvalInt32IfConst(scope);
if (is_const_int32 && value != SpvScopeSubgroup && value != SpvScopeDevice) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Scope must be Subgroup or Device";
<< _.VkErrorID(4652) << "Scope must be Subgroup or Device";
}
// Result Type must be a 64 - bit unsigned integer type or

View File

@ -459,11 +459,13 @@ spv_result_t ValidateExecutionMode(ValidationState_t& _,
if (spvIsVulkanEnv(_.context()->target_env)) {
if (mode == SpvExecutionModeOriginLowerLeft) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< _.VkErrorID(4653)
<< "In the Vulkan environment, the OriginLowerLeft execution mode "
"must not be used.";
}
if (mode == SpvExecutionModePixelCenterInteger) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< _.VkErrorID(4654)
<< "In the Vulkan environment, the PixelCenterInteger execution "
"mode must not be used.";
}

View File

@ -99,7 +99,7 @@ spv_result_t ValidateExecutionScope(ValidationState_t& _,
if (spvOpcodeIsNonUniformGroupOperation(opcode) &&
value != SpvScopeSubgroup) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< spvOpcodeString(opcode)
<< _.VkErrorID(4642) << spvOpcodeString(opcode)
<< ": in Vulkan environment Execution scope is limited to "
<< "Subgroup";
}

View File

@ -1667,8 +1667,22 @@ std::string ValidationState_t::VkErrorID(uint32_t id,
return VUID_WRAP(VUID-ShadingRateKHR-ShadingRateKHR-04492);
case 4633:
return VUID_WRAP(VUID-StandaloneSpirv-None-04633);
case 4642:
return VUID_WRAP(VUID-StandaloneSpirv-None-04642);
case 4649:
return VUID_WRAP(VUID-StandaloneSpirv-OpMemoryBarrier-04649);
case 4651:
return VUID_WRAP(VUID-StandaloneSpirv-OpVariable-04651);
case 4652:
return VUID_WRAP(VUID-StandaloneSpirv-OpReadClockKHR-04652);
case 4653:
return VUID_WRAP(VUID-StandaloneSpirv-OriginLowerLeft-04653);
case 4654:
return VUID_WRAP(VUID-StandaloneSpirv-PixelCenterInteger-04654);
case 4656:
return VUID_WRAP(VUID-StandaloneSpirv-OpTypeImage-04656);
case 4657:
return VUID_WRAP(VUID-StandaloneSpirv-OpTypeImage-04657);
case 4658:
return VUID_WRAP(VUID-StandaloneSpirv-OpImageTexelPointer-04658);
case 4669:

View File

@ -920,6 +920,8 @@ OpMemoryBarrier %device %none
CompileSuccessfully(GenerateShaderCode(body), SPV_ENV_VULKAN_1_0);
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
EXPECT_THAT(getDiagnosticString(),
AnyVUID("VUID-StandaloneSpirv-OpMemoryBarrier-04649"));
EXPECT_THAT(
getDiagnosticString(),
HasSubstr("MemoryBarrier: Vulkan specification requires Memory Semantics "
@ -934,6 +936,8 @@ OpMemoryBarrier %device %acquire
CompileSuccessfully(GenerateShaderCode(body), SPV_ENV_VULKAN_1_0);
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
EXPECT_THAT(getDiagnosticString(),
AnyVUID("VUID-StandaloneSpirv-OpMemoryBarrier-04649"));
EXPECT_THAT(getDiagnosticString(),
HasSubstr("MemoryBarrier: expected Memory Semantics to include a "
"Vulkan-supported storage class"));
@ -946,6 +950,8 @@ OpMemoryBarrier %device %acquire_release_subgroup
CompileSuccessfully(GenerateShaderCode(body), SPV_ENV_VULKAN_1_0);
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
EXPECT_THAT(getDiagnosticString(),
AnyVUID("VUID-StandaloneSpirv-OpMemoryBarrier-04649"));
EXPECT_THAT(getDiagnosticString(),
HasSubstr("MemoryBarrier: expected Memory Semantics to include a "
"Vulkan-supported storage class"));

View File

@ -827,6 +827,8 @@ TEST_F(ValidateImage, TypeImage_Vulkan_Sampled0_Invalid) {
CompileSuccessfully(code.c_str());
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
EXPECT_THAT(getDiagnosticString(),
AnyVUID("VUID-StandaloneSpirv-OpTypeImage-04657"));
EXPECT_THAT(getDiagnosticString(),
HasSubstr("Sampled must be 1 or 2 in the Vulkan environment."));
}

View File

@ -630,6 +630,8 @@ OpFunctionEnd
)";
CompileSuccessfully(spirv.c_str(), SPV_ENV_VULKAN_1_1);
EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_1));
EXPECT_THAT(getDiagnosticString(),
AnyVUID("VUID-StandaloneSpirv-OpVariable-04651"));
EXPECT_THAT(
getDiagnosticString(),
HasSubstr("OpVariable, <id> '5[%5]', has a disallowed initializer & "

View File

@ -227,6 +227,30 @@ OpFunctionEnd)";
HasSubstr("Scope must be Subgroup or Device"));
}
TEST_F(ValidateMisc, VulkanShaderClockWorkgroupScope) {
const std::string spirv = ShaderClockSpriv + R"(
%3 = OpTypeFunction %void
%ulong = OpTypeInt 64 0
%uint = OpTypeInt 32 0
%_ptr_Function_ulong = OpTypePointer Function %ulong
%workgroup = OpConstant %uint 2
%uint_1 = OpConstant %uint 1
%main = OpFunction %void None %3
%5 = OpLabel
%time1 = OpVariable %_ptr_Function_ulong Function
%11 = OpReadClockKHR %ulong %workgroup
OpStore %time1 %11
OpReturn
OpFunctionEnd)";
CompileSuccessfully(spirv, SPV_ENV_VULKAN_1_0);
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
EXPECT_THAT(getDiagnosticString(),
AnyVUID("VUID-StandaloneSpirv-OpReadClockKHR-04652"));
EXPECT_THAT(getDiagnosticString(),
HasSubstr("Scope must be Subgroup or Device"));
}
TEST_F(ValidateMisc, UndefVoid) {
const std::string spirv = R"(
OpCapability Shader

View File

@ -110,6 +110,8 @@ OpExecutionMode %main OriginLowerLeft
spv_target_env env = SPV_ENV_VULKAN_1_0;
CompileSuccessfully(spirv, env);
EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
EXPECT_THAT(getDiagnosticString(),
AnyVUID("VUID-StandaloneSpirv-OriginLowerLeft-04653"));
EXPECT_THAT(getDiagnosticString(),
HasSubstr("In the Vulkan environment, the OriginLowerLeft "
"execution mode must not be used."));
@ -127,6 +129,8 @@ OpExecutionMode %main PixelCenterInteger
spv_target_env env = SPV_ENV_VULKAN_1_0;
CompileSuccessfully(spirv, env);
EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
EXPECT_THAT(getDiagnosticString(),
AnyVUID("VUID-StandaloneSpirv-PixelCenterInteger-04654"));
EXPECT_THAT(getDiagnosticString(),
HasSubstr("In the Vulkan environment, the PixelCenterInteger "
"execution mode must not be used."));

View File

@ -141,6 +141,8 @@ TEST_P(GroupNonUniform, Vulkan1p1) {
EXPECT_EQ(SPV_SUCCESS, result);
} else {
EXPECT_EQ(SPV_ERROR_INVALID_DATA, result);
EXPECT_THAT(getDiagnosticString(),
AnyVUID("VUID-StandaloneSpirv-None-04642"));
EXPECT_THAT(
getDiagnosticString(),
HasSubstr(