Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions source/val/validate_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,8 @@ spv_result_t ValidateTypeForwardPointer(ValidationState_t& _,
<< "Pointer type in OpTypeForwardPointer is not a pointer type.";
}

if (inst->GetOperandAs<uint32_t>(1) !=
pointer_type_inst->GetOperandAs<uint32_t>(1)) {
const auto storage_class = inst->GetOperandAs<SpvStorageClass>(1);
if (storage_class != pointer_type_inst->GetOperandAs<uint32_t>(1)) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "Storage class in OpTypeForwardPointer does not match the "
<< "pointer definition.";
Expand All @@ -569,6 +569,15 @@ spv_result_t ValidateTypeForwardPointer(ValidationState_t& _,
<< "Forward pointers must point to a structure";
}

if (spvIsVulkanEnv(_.context()->target_env)) {
if (storage_class != SpvStorageClassPhysicalStorageBuffer) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< _.VkErrorID(4711)
<< "In Vulkan, OpTypeForwardPointer must have "
<< "a storage class of PhysicalStorageBuffer.";
}
}

return SPV_SUCCESS;
}

Expand Down
2 changes: 2 additions & 0 deletions source/val/validation_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1669,6 +1669,8 @@ std::string ValidationState_t::VkErrorID(uint32_t id,
return VUID_WRAP(VUID-StandaloneSpirv-None-04633);
case 4685:
return VUID_WRAP(VUID-StandaloneSpirv-OpGroupNonUniformBallotBitCount-04685);
case 4711:
return VUID_WRAP(VUID-StandaloneSpirv-OpTypeForwardPointer-04711);
default:
return ""; // unknown id
};
Expand Down
20 changes: 20 additions & 0 deletions test/val/val_data_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,26 @@ OpTypeForwardPointer %1 PhysicalStorageBuffer
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
}

TEST_F(ValidateData, VulkanTypeForwardStorageClass) {
std::string test = R"(
OpCapability Shader
OpCapability PhysicalStorageBufferAddresses
OpMemoryModel Logical GLSL450
OpTypeForwardPointer %1 Uniform
%2 = OpTypeStruct
%3 = OpTypeRuntimeArray %1
%1 = OpTypePointer Uniform %2
)";

CompileSuccessfully(test, SPV_ENV_VULKAN_1_2);
ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_2));
EXPECT_THAT(getDiagnosticString(),
AnyVUID("VUID-StandaloneSpirv-OpTypeForwardPointer-04711"));
EXPECT_THAT(getDiagnosticString(),
HasSubstr("In Vulkan, OpTypeForwardPointer must have "
"a storage class of PhysicalStorageBuffer."));
}

TEST_F(ValidateData, TypeForwardReferenceMustBeForwardPointer) {
std::string test = R"(
OpCapability Shader
Expand Down