1 // Copyright (c) 2018 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <string>
16 
17 #include "test/opt/pass_fixture.h"
18 #include "test/opt/pass_utils.h"
19 
20 namespace spvtools {
21 namespace opt {
22 namespace {
23 
24 using StripLineReflectInfoTest = PassTest<::testing::Test>;
25 
TEST_F(StripLineReflectInfoTest,StripHlslSemantic)26 TEST_F(StripLineReflectInfoTest, StripHlslSemantic) {
27   // This is a non-sensical example, but exercises the instructions.
28   std::string before = R"(OpCapability Shader
29 OpCapability Linkage
30 OpExtension "SPV_GOOGLE_decorate_string"
31 OpExtension "SPV_GOOGLE_hlsl_functionality1"
32 OpMemoryModel Logical Simple
33 OpDecorateStringGOOGLE %float HlslSemanticGOOGLE "foobar"
34 OpDecorateStringGOOGLE %void HlslSemanticGOOGLE "my goodness"
35 %void = OpTypeVoid
36 %float = OpTypeFloat 32
37 )";
38   std::string after = R"(OpCapability Shader
39 OpCapability Linkage
40 OpMemoryModel Logical Simple
41 %void = OpTypeVoid
42 %float = OpTypeFloat 32
43 )";
44 
45   SinglePassRunAndCheck<StripReflectInfoPass>(before, after, false);
46 }
47 
TEST_F(StripLineReflectInfoTest,StripHlslCounterBuffer)48 TEST_F(StripLineReflectInfoTest, StripHlslCounterBuffer) {
49   std::string before = R"(OpCapability Shader
50 OpCapability Linkage
51 OpExtension "SPV_GOOGLE_hlsl_functionality1"
52 OpMemoryModel Logical Simple
53 OpDecorateId %void HlslCounterBufferGOOGLE %float
54 %void = OpTypeVoid
55 %float = OpTypeFloat 32
56 )";
57   std::string after = R"(OpCapability Shader
58 OpCapability Linkage
59 OpMemoryModel Logical Simple
60 %void = OpTypeVoid
61 %float = OpTypeFloat 32
62 )";
63 
64   SinglePassRunAndCheck<StripReflectInfoPass>(before, after, false);
65 }
66 
TEST_F(StripLineReflectInfoTest,StripHlslSemanticOnMember)67 TEST_F(StripLineReflectInfoTest, StripHlslSemanticOnMember) {
68   // This is a non-sensical example, but exercises the instructions.
69   std::string before = R"(OpCapability Shader
70 OpCapability Linkage
71 OpExtension "SPV_GOOGLE_decorate_string"
72 OpExtension "SPV_GOOGLE_hlsl_functionality1"
73 OpMemoryModel Logical Simple
74 OpMemberDecorateStringGOOGLE %struct 0 HlslSemanticGOOGLE "foobar"
75 %float = OpTypeFloat 32
76 %_struct_3 = OpTypeStruct %float
77 )";
78   std::string after = R"(OpCapability Shader
79 OpCapability Linkage
80 OpMemoryModel Logical Simple
81 %float = OpTypeFloat 32
82 %_struct_3 = OpTypeStruct %float
83 )";
84 
85   SinglePassRunAndCheck<StripReflectInfoPass>(before, after, false);
86 }
87 
88 }  // namespace
89 }  // namespace opt
90 }  // namespace spvtools
91