aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsfricke-samsung <46493288+sfricke-samsung@users.noreply.github.com>2021-01-06 05:51:15 -0800
committerGitHub <noreply@github.com>2021-01-06 08:51:15 -0500
commitd630e5f8c10c2370ec1671d45a20bc877384ba40 (patch)
treeafed4db03d5a8b3fe419935a2b9bf51bc0925cc2
parent1bb80d2778a3d0362365b2490e2174bd56453036 (diff)
downloadspirv-tools-d630e5f8c10c2370ec1671d45a20bc877384ba40.tar.gz
spirv-val: Add Vulkan ImageTexelPointer format check (#4087)
-rw-r--r--source/val/validate_image.cpp14
-rw-r--r--source/val/validation_state.cpp2
-rw-r--r--test/val/val_image_test.cpp137
3 files changed, 152 insertions, 1 deletions
diff --git a/source/val/validate_image.cpp b/source/val/validate_image.cpp
index 561a5a10..e8f65cff 100644
--- a/source/val/validate_image.cpp
+++ b/source/val/validate_image.cpp
@@ -1095,6 +1095,20 @@ spv_result_t ValidateImageTexelPointer(ValidationState_t& _,
"the value 0";
}
}
+
+ if (spvIsVulkanEnv(_.context()->target_env)) {
+ if ((info.format != SpvImageFormatR64i) &&
+ (info.format != SpvImageFormatR64ui) &&
+ (info.format != SpvImageFormatR32f) &&
+ (info.format != SpvImageFormatR32i) &&
+ (info.format != SpvImageFormatR32ui)) {
+ return _.diag(SPV_ERROR_INVALID_DATA, inst)
+ << _.VkErrorID(4658)
+ << "Expected the Image Format in Image to be R64i, R64ui, R32f, "
+ "R32i, or R32ui for Vulkan environment";
+ }
+ }
+
return SPV_SUCCESS;
}
diff --git a/source/val/validation_state.cpp b/source/val/validation_state.cpp
index f458d4f9..e168c019 100644
--- a/source/val/validation_state.cpp
+++ b/source/val/validation_state.cpp
@@ -1667,6 +1667,8 @@ 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 4658:
+ return VUID_WRAP(VUID-StandaloneSpirv-OpImageTexelPointer-04658);
case 4685:
return VUID_WRAP(VUID-StandaloneSpirv-OpGroupNonUniformBallotBitCount-04685);
default:
diff --git a/test/val/val_image_test.cpp b/test/val/val_image_test.cpp
index 4b2c68fb..76663482 100644
--- a/test/val/val_image_test.cpp
+++ b/test/val/val_image_test.cpp
@@ -133,6 +133,7 @@ OpDecorate %uniform_sampler Binding 0
%u32 = OpTypeInt 32 0
%s32 = OpTypeInt 32 1
%u64 = OpTypeInt 64 0
+%s64 = OpTypeInt 64 1
%s32vec2 = OpTypeVector %s32 2
%u32vec2 = OpTypeVector %u32 2
%f32vec2 = OpTypeVector %f32 2
@@ -928,7 +929,7 @@ TEST_F(ValidateImage, ImageTexelPointerImageNotResultTypePointer) {
CompileSuccessfully(GenerateShaderCode(body).c_str());
ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(), HasSubstr("Operand 141[%141] cannot be a "
+ EXPECT_THAT(getDiagnosticString(), HasSubstr("Operand 142[%142] cannot be a "
"type"));
}
@@ -5434,6 +5435,12 @@ static const std::string declarations_image64 = R"(
%ptr_image_u64_buffer_0002_r64ui = OpTypePointer Private %type_image_u64_buffer_0002_r64ui
%private_image_u64_buffer_0002_r64ui = OpVariable %ptr_image_u64_buffer_0002_r64ui Private
)";
+static const std::string declarations_image64i = R"(
+%type_image_s64_buffer_0002_r64i = OpTypeImage %s64 Buffer 0 0 0 2 R64i
+%ptr_Image_s64 = OpTypePointer Image %s64
+%ptr_image_s64_buffer_0002_r64i = OpTypePointer Private %type_image_s64_buffer_0002_r64i
+%private_image_s64_buffer_0002_r64i = OpVariable %ptr_image_s64_buffer_0002_r64i Private
+)";
TEST_F(ValidateImage, Image64MissingCapability) {
CompileSuccessfully(GenerateShaderCode("", "", "Fragment", "",
@@ -5519,6 +5526,134 @@ TEST_F(ValidateImage, ImageTexelPointer64SampleNotZeroForImageWithMSZero) {
"<id> for the value 0"));
}
+TEST_F(ValidateImage, ImageTexelPointerR32uiSuccessVulkan) {
+ const std::string body = R"(
+%texel_ptr = OpImageTexelPointer %ptr_Image_u32 %private_image_u32_buffer_0002_r32ui %u32_0 %u32_0
+)";
+
+ spv_target_env env = SPV_ENV_VULKAN_1_0;
+ CompileSuccessfully(GenerateShaderCode(body, "", "Fragment", "", env).c_str(),
+ env);
+ ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(env));
+}
+
+TEST_F(ValidateImage, ImageTexelPointerR32iSuccessVulkan) {
+ const std::string& declarations = R"(
+%type_image_s32_buffer_0002_r32i = OpTypeImage %s32 Buffer 0 0 0 2 R32i
+%ptr_Image_s32 = OpTypePointer Image %s32
+%ptr_image_s32_buffer_0002_r32i = OpTypePointer Private %type_image_s32_buffer_0002_r32i
+%private_image_s32_buffer_0002_r32i = OpVariable %ptr_image_s32_buffer_0002_r32i Private
+)";
+
+ const std::string body = R"(
+%texel_ptr = OpImageTexelPointer %ptr_Image_s32 %private_image_s32_buffer_0002_r32i %u32_0 %u32_0
+)";
+
+ spv_target_env env = SPV_ENV_VULKAN_1_0;
+ CompileSuccessfully(
+ GenerateShaderCode(body, "", "Fragment", "", env, "GLSL450", declarations)
+ .c_str(),
+ env);
+ ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(env));
+}
+
+TEST_F(ValidateImage, ImageTexelPointerR64uiSuccessVulkan) {
+ const std::string body = R"(
+%texel_ptr = OpImageTexelPointer %ptr_Image_u64 %private_image_u64_buffer_0002_r64ui %u32_0 %u32_0
+)";
+
+ spv_target_env env = SPV_ENV_VULKAN_1_0;
+ CompileSuccessfully(
+ GenerateShaderCode(body, capabilities_and_extensions_image64, "Fragment",
+ "", env, "GLSL450", declarations_image64)
+ .c_str(),
+ env);
+ ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(env));
+}
+
+TEST_F(ValidateImage, ImageTexelPointerR64iSuccessVulkan) {
+ const std::string body = R"(
+%texel_ptr = OpImageTexelPointer %ptr_Image_s64 %private_image_s64_buffer_0002_r64i %u32_0 %u32_0
+)";
+
+ spv_target_env env = SPV_ENV_VULKAN_1_0;
+ CompileSuccessfully(
+ GenerateShaderCode(body, capabilities_and_extensions_image64, "Fragment",
+ "", env, "GLSL450", declarations_image64i)
+ .c_str(),
+ env);
+ ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(env));
+}
+
+TEST_F(ValidateImage, ImageTexelPointerR32fSuccessVulkan) {
+ const std::string& declarations = R"(
+%type_image_f32_buffer_0002_r32f = OpTypeImage %f32 Buffer 0 0 0 2 R32f
+%ptr_image_f32_buffer_0002_r32f = OpTypePointer Private %type_image_f32_buffer_0002_r32f
+%private_image_f32_buffer_0002_r32f = OpVariable %ptr_image_f32_buffer_0002_r32f Private
+)";
+
+ const std::string body = R"(
+%texel_ptr = OpImageTexelPointer %ptr_Image_f32 %private_image_f32_buffer_0002_r32f %u32_0 %u32_0
+)";
+
+ spv_target_env env = SPV_ENV_VULKAN_1_0;
+ CompileSuccessfully(
+ GenerateShaderCode(body, "", "Fragment", "", env, "GLSL450", declarations)
+ .c_str(),
+ env);
+ ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(env));
+}
+
+TEST_F(ValidateImage, ImageTexelPointerRgba32iVulkan) {
+ const std::string& declarations = R"(
+%type_image_s32_buffer_0002_rgba32i = OpTypeImage %s32 Buffer 0 0 0 2 Rgba32i
+%ptr_Image_s32 = OpTypePointer Image %s32
+%ptr_image_s32_buffer_0002_rgba32i = OpTypePointer Private %type_image_s32_buffer_0002_rgba32i
+%private_image_s32_buffer_0002_rgba32i = OpVariable %ptr_image_s32_buffer_0002_rgba32i Private
+)";
+
+ const std::string body = R"(
+%texel_ptr = OpImageTexelPointer %ptr_Image_s32 %private_image_s32_buffer_0002_rgba32i %u32_0 %u32_0
+)";
+
+ spv_target_env env = SPV_ENV_VULKAN_1_0;
+ CompileSuccessfully(
+ GenerateShaderCode(body, "", "Fragment", "", env, "GLSL450", declarations)
+ .c_str(),
+ env);
+ ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
+ EXPECT_THAT(getDiagnosticString(),
+ AnyVUID("VUID-StandaloneSpirv-OpImageTexelPointer-04658"));
+ EXPECT_THAT(getDiagnosticString(),
+ HasSubstr("Expected the Image Format in Image to be R64i, R64ui, "
+ "R32f, R32i, or R32ui for Vulkan environment"));
+}
+
+TEST_F(ValidateImage, ImageTexelPointerRgba16fVulkan) {
+ const std::string& declarations = R"(
+%type_image_s32_buffer_0002_rgba16f = OpTypeImage %s32 Buffer 0 0 0 2 Rgba16f
+%ptr_Image_s32 = OpTypePointer Image %s32
+%ptr_image_s32_buffer_0002_rgba16f = OpTypePointer Private %type_image_s32_buffer_0002_rgba16f
+%private_image_s32_buffer_0002_rgba16f = OpVariable %ptr_image_s32_buffer_0002_rgba16f Private
+)";
+
+ const std::string body = R"(
+%texel_ptr = OpImageTexelPointer %ptr_Image_s32 %private_image_s32_buffer_0002_rgba16f %u32_0 %u32_0
+)";
+
+ spv_target_env env = SPV_ENV_VULKAN_1_0;
+ CompileSuccessfully(
+ GenerateShaderCode(body, "", "Fragment", "", env, "GLSL450", declarations)
+ .c_str(),
+ env);
+ ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
+ EXPECT_THAT(getDiagnosticString(),
+ AnyVUID("VUID-StandaloneSpirv-OpImageTexelPointer-04658"));
+ EXPECT_THAT(getDiagnosticString(),
+ HasSubstr("Expected the Image Format in Image to be R64i, R64ui, "
+ "R32f, R32i, or R32ui for Vulkan environment"));
+}
+
} // namespace
} // namespace val
} // namespace spvtools