spirv-val: Label Vulkan VUID 04734 (#4739)

This commit is contained in:
sfricke-samsung 2022-03-04 09:07:24 -06:00 committed by GitHub
parent 598bc6744a
commit d1addc44b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 12 deletions

View File

@ -596,23 +596,23 @@ spv_result_t ValidateVariable(ValidationState_t& _, const Instruction* inst) {
}
}
}
}
// Vulkan Appendix A: Check that if contains initializer, then
// storage class is Output, Private, or Function.
if (inst->operands().size() > 3 && storage_class != SpvStorageClassOutput &&
storage_class != SpvStorageClassPrivate &&
storage_class != SpvStorageClassFunction) {
if (spvIsVulkanEnv(_.context()->target_env)) {
// Initializers in Vulkan are only allowed in some storage clases
if (inst->operands().size() > 3) {
if (storage_class == SpvStorageClassWorkgroup) {
auto init_id = inst->GetOperandAs<uint32_t>(3);
auto init = _.FindDef(init_id);
if (init->opcode() != SpvOpConstantNull) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "Variable initializers in Workgroup storage class are "
"limited to OpConstantNull";
<< _.VkErrorID(4734) << "OpVariable, <id> '"
<< _.getIdName(inst->id())
<< "', initializers are limited to OpConstantNull in "
"Workgroup "
"storage class";
}
} else {
} else if (storage_class != SpvStorageClassOutput &&
storage_class != SpvStorageClassPrivate &&
storage_class != SpvStorageClassFunction) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< _.VkErrorID(4651) << "OpVariable, <id> '"
<< _.getIdName(inst->id())

View File

@ -1882,6 +1882,8 @@ std::string ValidationState_t::VkErrorID(uint32_t id,
return VUID_WRAP(VUID-StandaloneSpirv-OpMemoryBarrier-04732);
case 4733:
return VUID_WRAP(VUID-StandaloneSpirv-OpMemoryBarrier-04733);
case 4734:
return VUID_WRAP(VUID-StandaloneSpirv-OpVariable-04734);
case 4780:
return VUID_WRAP(VUID-StandaloneSpirv-Result-04780);
case 4915:

View File

@ -4259,8 +4259,10 @@ OpFunctionEnd
CompileSuccessfully(spirv.c_str(), SPV_ENV_VULKAN_1_0);
EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_0));
EXPECT_THAT(getDiagnosticString(),
HasSubstr("Variable initializers in Workgroup storage class are "
"limited to OpConstantNull"));
AnyVUID(" VUID-StandaloneSpirv-OpVariable-04734"));
EXPECT_THAT(getDiagnosticString(),
HasSubstr("OpVariable, <id> '5[%5]', initializers are limited to "
"OpConstantNull in Workgroup storage class"));
}
TEST_F(ValidateMemory, VulkanInitializerWithWorkgroupStorageClassGood) {