diff --git a/source/val/validate_decorations.cpp b/source/val/validate_decorations.cpp index cccf69127c..344265224f 100644 --- a/source/val/validate_decorations.cpp +++ b/source/val/validate_decorations.cpp @@ -1028,6 +1028,10 @@ bool AtMostOncePerMember(SpvDecoration decoration) { // Returns the string name for |decoration|. const char* GetDecorationName(SpvDecoration decoration) { switch (decoration) { + case SpvDecorationAliased: + return "Aliased"; + case SpvDecorationRestrict: + return "Restrict"; case SpvDecorationArrayStride: return "ArrayStride"; case SpvDecorationOffset: @@ -1054,7 +1058,8 @@ spv_result_t CheckDecorationsCompatibility(ValidationState_t& vstate) { // An Array of pairs where the decorations in the pair cannot both be applied // to the same id. static const SpvDecoration mutually_exclusive_per_id[][2] = { - {SpvDecorationBlock, SpvDecorationBufferBlock}}; + {SpvDecorationBlock, SpvDecorationBufferBlock}, + {SpvDecorationRestrict, SpvDecorationAliased}}; static const auto num_mutually_exclusive_per_id_pairs = sizeof(mutually_exclusive_per_id) / (2 * sizeof(SpvDecoration)); diff --git a/test/opt/aggressive_dead_code_elim_test.cpp b/test/opt/aggressive_dead_code_elim_test.cpp index 3e09a0575f..8b9b40a044 100644 --- a/test/opt/aggressive_dead_code_elim_test.cpp +++ b/test/opt/aggressive_dead_code_elim_test.cpp @@ -5151,7 +5151,6 @@ OpFunctionEnd TEST_F(AggressiveDCETest, ParitallyDeadDecorationGroup) { const std::string text = R"( ; CHECK: OpDecorate [[grp:%\w+]] Restrict -; CHECK: OpDecorate [[grp]] Aliased ; CHECK: [[grp]] = OpDecorationGroup ; CHECK: OpGroupDecorate [[grp]] [[output:%\w+]] ; CHECK: [[output]] = OpVariable {{%\w+}} Output @@ -5161,7 +5160,6 @@ OpMemoryModel Logical GLSL450 OpEntryPoint Fragment %main "main" %output OpExecutionMode %main OriginUpperLeft OpDecorate %1 Restrict -OpDecorate %1 Aliased %1 = OpDecorationGroup OpGroupDecorate %1 %var %output %void = OpTypeVoid @@ -5185,7 +5183,6 @@ OpFunctionEnd TEST_F(AggressiveDCETest, ParitallyDeadDecorationGroupDifferentGroupDecorate) { const std::string text = R"( ; CHECK: OpDecorate [[grp:%\w+]] Restrict -; CHECK: OpDecorate [[grp]] Aliased ; CHECK: [[grp]] = OpDecorationGroup ; CHECK: OpGroupDecorate [[grp]] [[output:%\w+]] ; CHECK-NOT: OpGroupDecorate @@ -5196,7 +5193,6 @@ OpMemoryModel Logical GLSL450 OpEntryPoint Fragment %main "main" %output OpExecutionMode %main OriginUpperLeft OpDecorate %1 Restrict -OpDecorate %1 Aliased %1 = OpDecorationGroup OpGroupDecorate %1 %output OpGroupDecorate %1 %var diff --git a/test/val/val_decoration_test.cpp b/test/val/val_decoration_test.cpp index 1247a16f54..d77f336334 100644 --- a/test/val/val_decoration_test.cpp +++ b/test/val/val_decoration_test.cpp @@ -2303,10 +2303,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 +2314,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 +2341,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 +2352,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 +2383,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 +2394,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 +2415,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 +2426,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 +2460,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 +2471,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 +2514,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 +2525,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 @@ -5097,6 +5097,37 @@ TEST_F(ValidateDecorations, NoUnsignedWrapExtInstGLSLGood) { EXPECT_THAT(getDiagnosticString(), Eq("")); } +TEST_F(ValidateDecorations, AliasedandRestrictBad) { + const std::string body = R"( +OpCapability Shader +%1 = OpExtInstImport "GLSL.std.450" +OpMemoryModel Logical GLSL450 +OpEntryPoint GLCompute %main "main" +OpExecutionMode %main LocalSize 1 1 1 +OpSource GLSL 430 +OpMemberDecorate %Output 0 Offset 0 +OpDecorate %Output BufferBlock +OpDecorate %dataOutput Restrict +OpDecorate %dataOutput Aliased +%void = OpTypeVoid +%3 = OpTypeFunction %void +%float = OpTypeFloat 32 +%Output = OpTypeStruct %float +%_ptr_Uniform_Output = OpTypePointer Uniform %Output +%dataOutput = OpVariable %_ptr_Uniform_Output Uniform +%main = OpFunction %void None %3 +%5 = OpLabel +OpReturn +OpFunctionEnd +)"; + + CompileSuccessfully(body.c_str()); + ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions()); + EXPECT_THAT( + getDiagnosticString(), + HasSubstr("decorated with both Aliased and Restrict is not allowed")); +} + // TODO(dneto): For NoUnsignedWrap and NoUnsignedWrap, permit // "OpExtInst for instruction numbers specified in the extended // instruction-set specifications as accepting this decoration."