validate StorageImageMultisampled capability (#4062)

* validate StorageImageMultisampled capability

The StorageImageMultisampled capability is required when declaring
an image type with with Multisampled==1 and it's a storage image (Sampled == 2)

Fixes #4061

* Allow SubpassData with Multisampled and Sampled==2
This commit is contained in:
David Neto 2020-12-10 10:40:46 -05:00 committed by GitHub
parent 3b85234542
commit 7170218b8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 0 deletions

View File

@ -829,6 +829,15 @@ spv_result_t ValidateTypeImage(ValidationState_t& _, const Instruction* inst) {
}
}
if (info.multisampled && (info.sampled == 2) &&
(info.dim != SpvDimSubpassData)) {
if (!_.HasCapability(SpvCapabilityStorageImageMultisample)) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Capability StorageImageMultisample is required when using "
"multisampled storage image";
}
}
return SPV_SUCCESS;
}

View File

@ -584,6 +584,43 @@ TEST_F(ValidateImage, TypeImageWrongFormatForSubpassData) {
HasSubstr("Dim SubpassData requires format Unknown"));
}
TEST_F(ValidateImage, TypeImageMultisampleStorageImage_MissingCapability) {
const std::string code = GetShaderHeader("", false) +
R"(
%img_type = OpTypeImage %f32 2D 0 0 1 2 Rgba32f
)";
CompileSuccessfully(code.c_str());
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()) << code;
EXPECT_THAT(getDiagnosticString(),
HasSubstr("Capability StorageImageMultisample is required when "
"using multisampled storage image"));
}
TEST_F(ValidateImage, TypeImageMultisampleStorageImage_UsesCapability) {
const std::string code =
GetShaderHeader("OpCapability StorageImageMultisample\n", false) +
R"(
%img_type = OpTypeImage %f32 2D 0 0 1 2 Rgba32f
)";
CompileSuccessfully(code.c_str());
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()) << code;
EXPECT_THAT(getDiagnosticString(), Eq(""));
}
TEST_F(ValidateImage, TypeImageMultisampleSubpassData_OK) {
const std::string code =
GetShaderHeader("OpCapability InputAttachment\n", false) +
R"(
%img_type = OpTypeImage %f32 SubpassData 0 0 1 2 Unknown
)";
CompileSuccessfully(code.c_str());
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()) << code;
EXPECT_THAT(getDiagnosticString(), Eq(""));
}
TEST_F(ValidateImage, TypeSampledImageNotImage) {
const std::string code = GetShaderHeader("", false) + R"(
%simg_type = OpTypeSampledImage %f32