Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It is invalid to apply both Restrict and Aliased to the same <id> #2408

Merged
merged 3 commits into from
Feb 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion source/val/validate_decorations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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));

Expand Down
4 changes: 0 additions & 4 deletions test/opt/aggressive_dead_code_elim_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -5161,7 +5160,6 @@ OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %output
OpExecutionMode %main OriginUpperLeft
OpDecorate %1 Restrict
OpDecorate %1 Aliased
Copy link
Contributor Author

@sarahM0 sarahM0 Feb 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I deleted OpDecorate %1 Aliased to stop it from failing. Would you double check if it needs to be replaced with something or the test is still valuable? same for ParitallyDeadDecorationGroupDifferentGroupDecorate.

%1 = OpDecorationGroup
OpGroupDecorate %1 %var %output
%void = OpTypeVoid
Expand All @@ -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
Expand All @@ -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
Expand Down
69 changes: 50 additions & 19 deletions test/val/val_decoration_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2303,18 +2303,18 @@ 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
%int = OpTypeInt 32 0
%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

Expand All @@ -2341,18 +2341,18 @@ 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
%int = OpTypeInt 32 0
%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

Expand Down Expand Up @@ -2383,18 +2383,18 @@ 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
%int = OpTypeInt 32 0
%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

Expand All @@ -2415,18 +2415,18 @@ 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
%int = OpTypeInt 32 0
%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

Expand Down Expand Up @@ -2460,21 +2460,21 @@ 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
%int = OpTypeInt 32 0
%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
Expand Down Expand Up @@ -2514,18 +2514,18 @@ 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
%int = OpTypeInt 32 0
%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

Expand Down Expand Up @@ -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."
Expand Down