From 2904985aee4de2fd67d697242a267f5ec31814ce Mon Sep 17 00:00:00 2001 From: Spencer Fricke <115671160+spencer-lunarg@users.noreply.github.com> Date: Mon, 15 Apr 2024 23:56:12 +0900 Subject: [PATCH] spirv-val: Add Vulkan check for Rect Dim in OpTypeImage (#5644) --- source/val/validate_image.cpp | 10 +++++++++- source/val/validation_state.cpp | 2 ++ test/val/val_image_test.cpp | 15 +++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/source/val/validate_image.cpp b/source/val/validate_image.cpp index f62c3a26c3..bfcb310db5 100644 --- a/source/val/validate_image.cpp +++ b/source/val/validate_image.cpp @@ -914,7 +914,15 @@ spv_result_t ValidateTypeImage(ValidationState_t& _, const Instruction* inst) { if (info.dim == spv::Dim::SubpassData && info.arrayed != 0) { return _.diag(SPV_ERROR_INVALID_DATA, inst) - << _.VkErrorID(6214) << "Dim SubpassData requires Arrayed to be 0"; + << _.VkErrorID(6214) + << "Dim SubpassData requires Arrayed to be 0 in the Vulkan " + "environment"; + } + + if (info.dim == spv::Dim::Rect) { + return _.diag(SPV_ERROR_INVALID_DATA, inst) + << _.VkErrorID(9638) + << "Dim must not be Rect in the Vulkan environment"; } } diff --git a/source/val/validation_state.cpp b/source/val/validation_state.cpp index 896849930e..87322d2b96 100644 --- a/source/val/validation_state.cpp +++ b/source/val/validation_state.cpp @@ -2351,6 +2351,8 @@ std::string ValidationState_t::VkErrorID(uint32_t id, return VUID_WRAP(VUID-StandaloneSpirv-OpEntryPoint-08722); case 8973: return VUID_WRAP(VUID-StandaloneSpirv-Pointer-08973); + case 9638: + return VUID_WRAP(VUID-StandaloneSpirv-OpTypeImage-09638); default: return ""; // unknown id } diff --git a/test/val/val_image_test.cpp b/test/val/val_image_test.cpp index 35b76fc5b5..44ccf2d641 100644 --- a/test/val/val_image_test.cpp +++ b/test/val/val_image_test.cpp @@ -786,6 +786,21 @@ TEST_F(ValidateImage, TypeImageWrongArrayForSubpassDataVulkan) { HasSubstr("Dim SubpassData requires Arrayed to be 0")); } +TEST_F(ValidateImage, TypeImageDimRectVulkan) { + const std::string code = GetShaderHeader("OpCapability InputAttachment\n") + + R"( +%img_type = OpTypeImage %f32 Rect 0 1 0 2 Unknown +)" + TrivialMain(); + + CompileSuccessfully(code.c_str()); + ASSERT_EQ(SPV_ERROR_INVALID_CAPABILITY, + ValidateInstructions(SPV_ENV_VULKAN_1_0)); + // Can't actually hit VUID-StandaloneSpirv-OpTypeImage-09638 + EXPECT_THAT( + getDiagnosticString(), + AnyVUID("TypeImage requires one of these capabilities: SampledRect")); +} + TEST_F(ValidateImage, TypeImageWrongSampledTypeForTileImageDataEXT) { const std::string code = GetShaderHeader( "OpCapability TileImageColorReadAccessEXT\n"