aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/val/validate_decorations.cpp7
-rw-r--r--test/val/val_decoration_test.cpp71
2 files changed, 57 insertions, 21 deletions
diff --git a/source/val/validate_decorations.cpp b/source/val/validate_decorations.cpp
index cccf6912..f75c3af1 100644
--- a/source/val/validate_decorations.cpp
+++ b/source/val/validate_decorations.cpp
@@ -909,6 +909,13 @@ spv_result_t CheckDecorationsOfBuffers(ValidationState_t& vstate) {
: (push_constant ? "PushConstant" : "StorageBuffer");
if (spvIsVulkanEnv(vstate.context()->target_env)) {
+ if (storage_buffer &&
+ hasDecoration(id, SpvDecorationBufferBlock, vstate)) {
+ return vstate.diag(SPV_ERROR_INVALID_ID, vstate.FindDef(var_id))
+ << "Storage buffer id '" << var_id
+ << " In Vulkan, BufferBlock is disallowed on variables in "
+ "the StorageBuffer storage class";
+ }
// Vulkan 14.5.1: Check Block decoration for PushConstant variables.
if (push_constant && !hasDecoration(id, SpvDecorationBlock, vstate)) {
return vstate.diag(SPV_ERROR_INVALID_ID, vstate.FindDef(id))
diff --git a/test/val/val_decoration_test.cpp b/test/val/val_decoration_test.cpp
index 1247a16f..61150bc4 100644
--- a/test/val/val_decoration_test.cpp
+++ b/test/val/val_decoration_test.cpp
@@ -2101,6 +2101,37 @@ TEST_F(ValidateDecorations, BlockArrayBadAlignmentWithVulkan1_1StillBad) {
"member 1 at offset 8 is not aligned to 16"));
}
+TEST_F(ValidateDecorations, VulkanBufferBlockOnStorageBufferBad) {
+ std::string spirv = R"(
+ OpCapability Shader
+ OpExtension "SPV_KHR_storage_buffer_storage_class"
+ OpMemoryModel Logical GLSL450
+ OpEntryPoint Fragment %1 "main"
+ OpExecutionMode %1 OriginUpperLeft
+
+ OpDecorate %struct BufferBlock
+
+ %void = OpTypeVoid
+ %voidfn = OpTypeFunction %void
+ %float = OpTypeFloat 32
+ %struct = OpTypeStruct %float
+ %ptr = OpTypePointer StorageBuffer %struct
+ %var = OpVariable %ptr StorageBuffer
+
+ %1 = OpFunction %void None %voidfn
+ %label = OpLabel
+ OpReturn
+ OpFunctionEnd
+)";
+
+ CompileSuccessfully(spirv, SPV_ENV_VULKAN_1_1);
+ EXPECT_EQ(SPV_ERROR_INVALID_ID,
+ ValidateAndRetrieveValidationState(SPV_ENV_VULKAN_1_1));
+ EXPECT_THAT(getDiagnosticString(),
+ HasSubstr("In Vulkan, BufferBlock is disallowed on variables in "
+ "the StorageBuffer storage class"));
+}
+
TEST_F(ValidateDecorations, PushConstantArrayBaseAlignmentGood) {
// Tests https://github.com/KhronosGroup/SPIRV-Tools/issues/1664
// From GLSL vertex shader:
@@ -2303,10 +2334,10 @@ TEST_F(ValidateDecorations, MultiplePushConstantsSingleEntryPointGood) {
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %1 "main"
OpExecutionMode %1 OriginUpperLeft
-
+
OpDecorate %struct Block
OpMemberDecorate %struct 0 Offset 0
-
+
%void = OpTypeVoid
%voidfn = OpTypeFunction %void
%float = OpTypeFloat 32
@@ -2314,7 +2345,7 @@ TEST_F(ValidateDecorations, MultiplePushConstantsSingleEntryPointGood) {
%int_0 = OpConstant %int 0
%struct = OpTypeStruct %float
%ptr = OpTypePointer PushConstant %struct
- %ptr_float = OpTypePointer PushConstant %float
+ %ptr_float = OpTypePointer PushConstant %float
%pc1 = OpVariable %ptr PushConstant
%pc2 = OpVariable %ptr PushConstant
@@ -2341,10 +2372,10 @@ TEST_F(ValidateDecorations,
OpEntryPoint Vertex %1 "func1"
OpEntryPoint Fragment %2 "func2"
OpExecutionMode %2 OriginUpperLeft
-
+
OpDecorate %struct Block
OpMemberDecorate %struct 0 Offset 0
-
+
%void = OpTypeVoid
%voidfn = OpTypeFunction %void
%float = OpTypeFloat 32
@@ -2352,7 +2383,7 @@ TEST_F(ValidateDecorations,
%int_0 = OpConstant %int 0
%struct = OpTypeStruct %float
%ptr = OpTypePointer PushConstant %struct
- %ptr_float = OpTypePointer PushConstant %float
+ %ptr_float = OpTypePointer PushConstant %float
%pc1 = OpVariable %ptr PushConstant
%pc2 = OpVariable %ptr PushConstant
@@ -2383,10 +2414,10 @@ TEST_F(ValidateDecorations,
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %1 "main"
OpExecutionMode %1 OriginUpperLeft
-
+
OpDecorate %struct Block
OpMemberDecorate %struct 0 Offset 0
-
+
%void = OpTypeVoid
%voidfn = OpTypeFunction %void
%float = OpTypeFloat 32
@@ -2394,7 +2425,7 @@ TEST_F(ValidateDecorations,
%int_0 = OpConstant %int 0
%struct = OpTypeStruct %float
%ptr = OpTypePointer PushConstant %struct
- %ptr_float = OpTypePointer PushConstant %float
+ %ptr_float = OpTypePointer PushConstant %float
%pc1 = OpVariable %ptr PushConstant
%pc2 = OpVariable %ptr PushConstant
@@ -2415,10 +2446,10 @@ TEST_F(ValidateDecorations, VulkanMultiplePushConstantsSingleEntryPointBad) {
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %1 "main"
OpExecutionMode %1 OriginUpperLeft
-
+
OpDecorate %struct Block
OpMemberDecorate %struct 0 Offset 0
-
+
%void = OpTypeVoid
%voidfn = OpTypeFunction %void
%float = OpTypeFloat 32
@@ -2426,7 +2457,7 @@ TEST_F(ValidateDecorations, VulkanMultiplePushConstantsSingleEntryPointBad) {
%int_0 = OpConstant %int 0
%struct = OpTypeStruct %float
%ptr = OpTypePointer PushConstant %struct
- %ptr_float = OpTypePointer PushConstant %float
+ %ptr_float = OpTypePointer PushConstant %float
%pc1 = OpVariable %ptr PushConstant
%pc2 = OpVariable %ptr PushConstant
@@ -2460,10 +2491,10 @@ TEST_F(ValidateDecorations,
OpEntryPoint Vertex %1 "func1"
OpEntryPoint Fragment %2 "func2"
OpExecutionMode %2 OriginUpperLeft
-
+
OpDecorate %struct Block
OpMemberDecorate %struct 0 Offset 0
-
+
%void = OpTypeVoid
%voidfn = OpTypeFunction %void
%float = OpTypeFloat 32
@@ -2471,10 +2502,10 @@ TEST_F(ValidateDecorations,
%int_0 = OpConstant %int 0
%struct = OpTypeStruct %float
%ptr = OpTypePointer PushConstant %struct
- %ptr_float = OpTypePointer PushConstant %float
+ %ptr_float = OpTypePointer PushConstant %float
%pc1 = OpVariable %ptr PushConstant
%pc2 = OpVariable %ptr PushConstant
-
+
%sub1 = OpFunction %void None %voidfn
%label_sub1 = OpLabel
%3 = OpAccessChain %ptr_float %pc1 %int_0
@@ -2514,10 +2545,10 @@ TEST_F(ValidateDecorations,
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %1 "main"
OpExecutionMode %1 OriginUpperLeft
-
+
OpDecorate %struct Block
OpMemberDecorate %struct 0 Offset 0
-
+
%void = OpTypeVoid
%voidfn = OpTypeFunction %void
%float = OpTypeFloat 32
@@ -2525,7 +2556,7 @@ TEST_F(ValidateDecorations,
%int_0 = OpConstant %int 0
%struct = OpTypeStruct %float
%ptr = OpTypePointer PushConstant %struct
- %ptr_float = OpTypePointer PushConstant %float
+ %ptr_float = OpTypePointer PushConstant %float
%pc1 = OpVariable %ptr PushConstant
%pc2 = OpVariable %ptr PushConstant
@@ -2841,8 +2872,6 @@ TEST_F(ValidateDecorations,
OpEntryPoint Fragment %1 "main"
OpExecutionMode %1 OriginUpperLeft
- OpDecorate %struct BufferBlock
-
%void = OpTypeVoid
%voidfn = OpTypeFunction %void
%float = OpTypeFloat 32