1fd4e5da5Sopenharmony_ci// Copyright (c) 2017 Google Inc.
2fd4e5da5Sopenharmony_ci//
3fd4e5da5Sopenharmony_ci// Licensed under the Apache License, Version 2.0 (the "License");
4fd4e5da5Sopenharmony_ci// you may not use this file except in compliance with the License.
5fd4e5da5Sopenharmony_ci// You may obtain a copy of the License at
6fd4e5da5Sopenharmony_ci//
7fd4e5da5Sopenharmony_ci//     http://www.apache.org/licenses/LICENSE-2.0
8fd4e5da5Sopenharmony_ci//
9fd4e5da5Sopenharmony_ci// Unless required by applicable law or agreed to in writing, software
10fd4e5da5Sopenharmony_ci// distributed under the License is distributed on an "AS IS" BASIS,
11fd4e5da5Sopenharmony_ci// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12fd4e5da5Sopenharmony_ci// See the License for the specific language governing permissions and
13fd4e5da5Sopenharmony_ci// limitations under the License.
14fd4e5da5Sopenharmony_ci
15fd4e5da5Sopenharmony_ci#include <string>
16fd4e5da5Sopenharmony_ci#include <vector>
17fd4e5da5Sopenharmony_ci
18fd4e5da5Sopenharmony_ci#include "pass_utils.h"
19fd4e5da5Sopenharmony_ci#include "test/opt/assembly_builder.h"
20fd4e5da5Sopenharmony_ci#include "test/opt/pass_fixture.h"
21fd4e5da5Sopenharmony_ci
22fd4e5da5Sopenharmony_cinamespace spvtools {
23fd4e5da5Sopenharmony_cinamespace opt {
24fd4e5da5Sopenharmony_cinamespace {
25fd4e5da5Sopenharmony_ci
26fd4e5da5Sopenharmony_ciusing ReplaceInvalidOpcodeTest = PassTest<::testing::Test>;
27fd4e5da5Sopenharmony_ci
28fd4e5da5Sopenharmony_ciTEST_F(ReplaceInvalidOpcodeTest, ReplaceInstruction) {
29fd4e5da5Sopenharmony_ci  const std::string text = R"(
30fd4e5da5Sopenharmony_ci; CHECK: [[special_const:%\w+]] = OpConstant %float -6.2598534e+18
31fd4e5da5Sopenharmony_ci; CHECK: [[constant:%\w+]] = OpConstantComposite %v4float [[special_const]] [[special_const]] [[special_const]] [[special_const]]
32fd4e5da5Sopenharmony_ci; CHECK-NOT: OpImageSampleImplicitLod
33fd4e5da5Sopenharmony_ci; CHECK: OpStore [[:%\w+]] [[constant]]
34fd4e5da5Sopenharmony_ci                OpCapability Shader
35fd4e5da5Sopenharmony_ci          %1 = OpExtInstImport "GLSL.std.450"
36fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
37fd4e5da5Sopenharmony_ci               OpEntryPoint Vertex %main "main" %3 %gl_VertexIndex %5
38fd4e5da5Sopenharmony_ci               OpSource GLSL 400
39fd4e5da5Sopenharmony_ci               OpSourceExtension "GL_ARB_separate_shader_objects"
40fd4e5da5Sopenharmony_ci               OpSourceExtension "GL_ARB_shading_language_420pack"
41fd4e5da5Sopenharmony_ci               OpName %main "main"
42fd4e5da5Sopenharmony_ci               OpDecorate %3 Location 0
43fd4e5da5Sopenharmony_ci               OpDecorate %gl_VertexIndex BuiltIn VertexIndex
44fd4e5da5Sopenharmony_ci               OpMemberDecorate %_struct_6 0 BuiltIn Position
45fd4e5da5Sopenharmony_ci               OpDecorate %_struct_6 Block
46fd4e5da5Sopenharmony_ci       %void = OpTypeVoid
47fd4e5da5Sopenharmony_ci          %8 = OpTypeFunction %void
48fd4e5da5Sopenharmony_ci      %float = OpTypeFloat 32
49fd4e5da5Sopenharmony_ci         %10 = OpTypeImage %float 2D 0 0 0 1 Unknown
50fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_10 = OpTypePointer UniformConstant %10
51fd4e5da5Sopenharmony_ci         %12 = OpTypeSampler
52fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_12 = OpTypePointer UniformConstant %12
53fd4e5da5Sopenharmony_ci         %14 = OpTypeSampledImage %10
54fd4e5da5Sopenharmony_ci    %v4float = OpTypeVector %float 4
55fd4e5da5Sopenharmony_ci    %v2float = OpTypeVector %float 2
56fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
57fd4e5da5Sopenharmony_ci          %3 = OpVariable %_ptr_Output_v4float Output
58fd4e5da5Sopenharmony_ci        %int = OpTypeInt 32 1
59fd4e5da5Sopenharmony_ci%_ptr_Input_int = OpTypePointer Input %int
60fd4e5da5Sopenharmony_ci%gl_VertexIndex = OpVariable %_ptr_Input_int Input
61fd4e5da5Sopenharmony_ci  %_struct_6 = OpTypeStruct %v4float
62fd4e5da5Sopenharmony_ci%_ptr_Output__struct_6 = OpTypePointer Output %_struct_6
63fd4e5da5Sopenharmony_ci          %5 = OpVariable %_ptr_Output__struct_6 Output
64fd4e5da5Sopenharmony_ci      %int_0 = OpConstant %int 0
65fd4e5da5Sopenharmony_ci    %float_0 = OpConstant %float 0
66fd4e5da5Sopenharmony_ci         %23 = OpConstantComposite %v2float %float_0 %float_0
67fd4e5da5Sopenharmony_ci         %24 = OpVariable %_ptr_UniformConstant_10 UniformConstant
68fd4e5da5Sopenharmony_ci         %25 = OpVariable %_ptr_UniformConstant_12 UniformConstant
69fd4e5da5Sopenharmony_ci       %main = OpFunction %void None %8
70fd4e5da5Sopenharmony_ci         %26 = OpLabel
71fd4e5da5Sopenharmony_ci         %27 = OpLoad %12 %25
72fd4e5da5Sopenharmony_ci         %28 = OpLoad %10 %24
73fd4e5da5Sopenharmony_ci         %29 = OpSampledImage %14 %28 %27
74fd4e5da5Sopenharmony_ci         %30 = OpImageSampleImplicitLod %v4float %29 %23
75fd4e5da5Sopenharmony_ci         %31 = OpAccessChain %_ptr_Output_v4float %5 %int_0
76fd4e5da5Sopenharmony_ci               OpStore %31 %30
77fd4e5da5Sopenharmony_ci               OpReturn
78fd4e5da5Sopenharmony_ci               OpFunctionEnd)";
79fd4e5da5Sopenharmony_ci
80fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<ReplaceInvalidOpcodePass>(text, false);
81fd4e5da5Sopenharmony_ci}
82fd4e5da5Sopenharmony_ci
83fd4e5da5Sopenharmony_ciTEST_F(ReplaceInvalidOpcodeTest, ReplaceInstructionInNonEntryPoint) {
84fd4e5da5Sopenharmony_ci  const std::string text = R"(
85fd4e5da5Sopenharmony_ci; CHECK: [[special_const:%\w+]] = OpConstant %float -6.2598534e+18
86fd4e5da5Sopenharmony_ci; CHECK: [[constant:%\w+]] = OpConstantComposite %v4float [[special_const]] [[special_const]] [[special_const]] [[special_const]]
87fd4e5da5Sopenharmony_ci; CHECK-NOT: OpImageSampleImplicitLod
88fd4e5da5Sopenharmony_ci; CHECK: OpStore [[:%\w+]] [[constant]]
89fd4e5da5Sopenharmony_ci               OpCapability Shader
90fd4e5da5Sopenharmony_ci          %1 = OpExtInstImport "GLSL.std.450"
91fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
92fd4e5da5Sopenharmony_ci               OpEntryPoint Vertex %main "main" %3 %gl_VertexIndex %5
93fd4e5da5Sopenharmony_ci               OpSource GLSL 400
94fd4e5da5Sopenharmony_ci               OpSourceExtension "GL_ARB_separate_shader_objects"
95fd4e5da5Sopenharmony_ci               OpSourceExtension "GL_ARB_shading_language_420pack"
96fd4e5da5Sopenharmony_ci               OpName %main "main"
97fd4e5da5Sopenharmony_ci               OpDecorate %3 Location 0
98fd4e5da5Sopenharmony_ci               OpDecorate %gl_VertexIndex BuiltIn VertexIndex
99fd4e5da5Sopenharmony_ci               OpMemberDecorate %_struct_6 0 BuiltIn Position
100fd4e5da5Sopenharmony_ci               OpDecorate %_struct_6 Block
101fd4e5da5Sopenharmony_ci       %void = OpTypeVoid
102fd4e5da5Sopenharmony_ci          %8 = OpTypeFunction %void
103fd4e5da5Sopenharmony_ci      %float = OpTypeFloat 32
104fd4e5da5Sopenharmony_ci         %10 = OpTypeImage %float 2D 0 0 0 1 Unknown
105fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_10 = OpTypePointer UniformConstant %10
106fd4e5da5Sopenharmony_ci         %12 = OpTypeSampler
107fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_12 = OpTypePointer UniformConstant %12
108fd4e5da5Sopenharmony_ci         %14 = OpTypeSampledImage %10
109fd4e5da5Sopenharmony_ci    %v4float = OpTypeVector %float 4
110fd4e5da5Sopenharmony_ci    %v2float = OpTypeVector %float 2
111fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
112fd4e5da5Sopenharmony_ci          %3 = OpVariable %_ptr_Output_v4float Output
113fd4e5da5Sopenharmony_ci        %int = OpTypeInt 32 1
114fd4e5da5Sopenharmony_ci%_ptr_Input_int = OpTypePointer Input %int
115fd4e5da5Sopenharmony_ci%gl_VertexIndex = OpVariable %_ptr_Input_int Input
116fd4e5da5Sopenharmony_ci  %_struct_6 = OpTypeStruct %v4float
117fd4e5da5Sopenharmony_ci%_ptr_Output__struct_6 = OpTypePointer Output %_struct_6
118fd4e5da5Sopenharmony_ci          %5 = OpVariable %_ptr_Output__struct_6 Output
119fd4e5da5Sopenharmony_ci      %int_0 = OpConstant %int 0
120fd4e5da5Sopenharmony_ci    %float_0 = OpConstant %float 0
121fd4e5da5Sopenharmony_ci         %23 = OpConstantComposite %v2float %float_0 %float_0
122fd4e5da5Sopenharmony_ci         %24 = OpVariable %_ptr_UniformConstant_10 UniformConstant
123fd4e5da5Sopenharmony_ci         %25 = OpVariable %_ptr_UniformConstant_12 UniformConstant
124fd4e5da5Sopenharmony_ci       %main = OpFunction %void None %8
125fd4e5da5Sopenharmony_ci         %26 = OpLabel
126fd4e5da5Sopenharmony_ci         %27 = OpFunctionCall %void %28
127fd4e5da5Sopenharmony_ci               OpReturn
128fd4e5da5Sopenharmony_ci               OpFunctionEnd
129fd4e5da5Sopenharmony_ci         %28 = OpFunction %void None %8
130fd4e5da5Sopenharmony_ci         %29 = OpLabel
131fd4e5da5Sopenharmony_ci         %30 = OpLoad %12 %25
132fd4e5da5Sopenharmony_ci         %31 = OpLoad %10 %24
133fd4e5da5Sopenharmony_ci         %32 = OpSampledImage %14 %31 %30
134fd4e5da5Sopenharmony_ci         %33 = OpImageSampleImplicitLod %v4float %32 %23
135fd4e5da5Sopenharmony_ci         %34 = OpAccessChain %_ptr_Output_v4float %5 %int_0
136fd4e5da5Sopenharmony_ci               OpStore %34 %33
137fd4e5da5Sopenharmony_ci               OpReturn
138fd4e5da5Sopenharmony_ci               OpFunctionEnd)";
139fd4e5da5Sopenharmony_ci
140fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<ReplaceInvalidOpcodePass>(text, false);
141fd4e5da5Sopenharmony_ci}
142fd4e5da5Sopenharmony_ci
143fd4e5da5Sopenharmony_ciTEST_F(ReplaceInvalidOpcodeTest, ReplaceInstructionMultipleEntryPoints) {
144fd4e5da5Sopenharmony_ci  const std::string text = R"(
145fd4e5da5Sopenharmony_ci; CHECK: [[special_const:%\w+]] = OpConstant %float -6.2598534e+18
146fd4e5da5Sopenharmony_ci; CHECK: [[constant:%\w+]] = OpConstantComposite %v4float [[special_const]] [[special_const]] [[special_const]] [[special_const]]
147fd4e5da5Sopenharmony_ci; CHECK-NOT: OpImageSampleImplicitLod
148fd4e5da5Sopenharmony_ci; CHECK: OpStore [[:%\w+]] [[constant]]
149fd4e5da5Sopenharmony_ci; CHECK-NOT: OpImageSampleImplicitLod
150fd4e5da5Sopenharmony_ci; CHECK: OpStore [[:%\w+]] [[constant]]
151fd4e5da5Sopenharmony_ci                OpCapability Shader
152fd4e5da5Sopenharmony_ci          %1 = OpExtInstImport "GLSL.std.450"
153fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
154fd4e5da5Sopenharmony_ci               OpEntryPoint Vertex %main "main" %3 %gl_VertexIndex %5
155fd4e5da5Sopenharmony_ci               OpEntryPoint Vertex %main2 "main2" %3 %gl_VertexIndex %5
156fd4e5da5Sopenharmony_ci               OpSource GLSL 400
157fd4e5da5Sopenharmony_ci               OpSourceExtension "GL_ARB_separate_shader_objects"
158fd4e5da5Sopenharmony_ci               OpSourceExtension "GL_ARB_shading_language_420pack"
159fd4e5da5Sopenharmony_ci               OpName %main "main"
160fd4e5da5Sopenharmony_ci               OpName %main2 "main2"
161fd4e5da5Sopenharmony_ci               OpDecorate %3 Location 0
162fd4e5da5Sopenharmony_ci               OpDecorate %gl_VertexIndex BuiltIn VertexIndex
163fd4e5da5Sopenharmony_ci               OpMemberDecorate %_struct_6 0 BuiltIn Position
164fd4e5da5Sopenharmony_ci               OpDecorate %_struct_6 Block
165fd4e5da5Sopenharmony_ci       %void = OpTypeVoid
166fd4e5da5Sopenharmony_ci          %8 = OpTypeFunction %void
167fd4e5da5Sopenharmony_ci      %float = OpTypeFloat 32
168fd4e5da5Sopenharmony_ci         %10 = OpTypeImage %float 2D 0 0 0 1 Unknown
169fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_10 = OpTypePointer UniformConstant %10
170fd4e5da5Sopenharmony_ci         %12 = OpTypeSampler
171fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_12 = OpTypePointer UniformConstant %12
172fd4e5da5Sopenharmony_ci         %14 = OpTypeSampledImage %10
173fd4e5da5Sopenharmony_ci    %v4float = OpTypeVector %float 4
174fd4e5da5Sopenharmony_ci    %v2float = OpTypeVector %float 2
175fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
176fd4e5da5Sopenharmony_ci          %3 = OpVariable %_ptr_Output_v4float Output
177fd4e5da5Sopenharmony_ci        %int = OpTypeInt 32 1
178fd4e5da5Sopenharmony_ci%_ptr_Input_int = OpTypePointer Input %int
179fd4e5da5Sopenharmony_ci%gl_VertexIndex = OpVariable %_ptr_Input_int Input
180fd4e5da5Sopenharmony_ci  %_struct_6 = OpTypeStruct %v4float
181fd4e5da5Sopenharmony_ci%_ptr_Output__struct_6 = OpTypePointer Output %_struct_6
182fd4e5da5Sopenharmony_ci          %5 = OpVariable %_ptr_Output__struct_6 Output
183fd4e5da5Sopenharmony_ci      %int_0 = OpConstant %int 0
184fd4e5da5Sopenharmony_ci    %float_0 = OpConstant %float 0
185fd4e5da5Sopenharmony_ci         %23 = OpConstantComposite %v2float %float_0 %float_0
186fd4e5da5Sopenharmony_ci         %24 = OpVariable %_ptr_UniformConstant_10 UniformConstant
187fd4e5da5Sopenharmony_ci         %25 = OpVariable %_ptr_UniformConstant_12 UniformConstant
188fd4e5da5Sopenharmony_ci       %main = OpFunction %void None %8
189fd4e5da5Sopenharmony_ci         %26 = OpLabel
190fd4e5da5Sopenharmony_ci         %27 = OpLoad %12 %25
191fd4e5da5Sopenharmony_ci         %28 = OpLoad %10 %24
192fd4e5da5Sopenharmony_ci         %29 = OpSampledImage %14 %28 %27
193fd4e5da5Sopenharmony_ci         %30 = OpImageSampleImplicitLod %v4float %29 %23
194fd4e5da5Sopenharmony_ci         %31 = OpAccessChain %_ptr_Output_v4float %5 %int_0
195fd4e5da5Sopenharmony_ci               OpStore %31 %30
196fd4e5da5Sopenharmony_ci               OpReturn
197fd4e5da5Sopenharmony_ci               OpFunctionEnd
198fd4e5da5Sopenharmony_ci      %main2 = OpFunction %void None %8
199fd4e5da5Sopenharmony_ci         %46 = OpLabel
200fd4e5da5Sopenharmony_ci         %47 = OpLoad %12 %25
201fd4e5da5Sopenharmony_ci         %48 = OpLoad %10 %24
202fd4e5da5Sopenharmony_ci         %49 = OpSampledImage %14 %48 %47
203fd4e5da5Sopenharmony_ci         %50 = OpImageSampleImplicitLod %v4float %49 %23
204fd4e5da5Sopenharmony_ci         %51 = OpAccessChain %_ptr_Output_v4float %5 %int_0
205fd4e5da5Sopenharmony_ci               OpStore %51 %50
206fd4e5da5Sopenharmony_ci               OpReturn
207fd4e5da5Sopenharmony_ci               OpFunctionEnd)";
208fd4e5da5Sopenharmony_ci
209fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<ReplaceInvalidOpcodePass>(text, false);
210fd4e5da5Sopenharmony_ci}
211fd4e5da5Sopenharmony_ciTEST_F(ReplaceInvalidOpcodeTest, DontReplaceInstruction) {
212fd4e5da5Sopenharmony_ci  const std::string text = R"(
213fd4e5da5Sopenharmony_ci                OpCapability Shader
214fd4e5da5Sopenharmony_ci          %1 = OpExtInstImport "GLSL.std.450"
215fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
216fd4e5da5Sopenharmony_ci               OpEntryPoint Fragment %main "main" %3 %gl_VertexIndex %5
217fd4e5da5Sopenharmony_ci               OpSource GLSL 400
218fd4e5da5Sopenharmony_ci               OpSourceExtension "GL_ARB_separate_shader_objects"
219fd4e5da5Sopenharmony_ci               OpSourceExtension "GL_ARB_shading_language_420pack"
220fd4e5da5Sopenharmony_ci               OpName %main "main"
221fd4e5da5Sopenharmony_ci               OpDecorate %3 Location 0
222fd4e5da5Sopenharmony_ci               OpDecorate %gl_VertexIndex BuiltIn VertexIndex
223fd4e5da5Sopenharmony_ci               OpMemberDecorate %_struct_6 0 BuiltIn Position
224fd4e5da5Sopenharmony_ci               OpDecorate %_struct_6 Block
225fd4e5da5Sopenharmony_ci       %void = OpTypeVoid
226fd4e5da5Sopenharmony_ci          %8 = OpTypeFunction %void
227fd4e5da5Sopenharmony_ci      %float = OpTypeFloat 32
228fd4e5da5Sopenharmony_ci         %10 = OpTypeImage %float 2D 0 0 0 1 Unknown
229fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_10 = OpTypePointer UniformConstant %10
230fd4e5da5Sopenharmony_ci         %12 = OpTypeSampler
231fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_12 = OpTypePointer UniformConstant %12
232fd4e5da5Sopenharmony_ci         %14 = OpTypeSampledImage %10
233fd4e5da5Sopenharmony_ci    %v4float = OpTypeVector %float 4
234fd4e5da5Sopenharmony_ci    %v2float = OpTypeVector %float 2
235fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
236fd4e5da5Sopenharmony_ci          %3 = OpVariable %_ptr_Output_v4float Output
237fd4e5da5Sopenharmony_ci        %int = OpTypeInt 32 1
238fd4e5da5Sopenharmony_ci%_ptr_Input_int = OpTypePointer Input %int
239fd4e5da5Sopenharmony_ci%gl_VertexIndex = OpVariable %_ptr_Input_int Input
240fd4e5da5Sopenharmony_ci  %_struct_6 = OpTypeStruct %v4float
241fd4e5da5Sopenharmony_ci%_ptr_Output__struct_6 = OpTypePointer Output %_struct_6
242fd4e5da5Sopenharmony_ci          %5 = OpVariable %_ptr_Output__struct_6 Output
243fd4e5da5Sopenharmony_ci      %int_0 = OpConstant %int 0
244fd4e5da5Sopenharmony_ci    %float_0 = OpConstant %float 0
245fd4e5da5Sopenharmony_ci         %23 = OpConstantComposite %v2float %float_0 %float_0
246fd4e5da5Sopenharmony_ci         %24 = OpVariable %_ptr_UniformConstant_10 UniformConstant
247fd4e5da5Sopenharmony_ci         %25 = OpVariable %_ptr_UniformConstant_12 UniformConstant
248fd4e5da5Sopenharmony_ci       %main = OpFunction %void None %8
249fd4e5da5Sopenharmony_ci         %26 = OpLabel
250fd4e5da5Sopenharmony_ci         %27 = OpLoad %12 %25
251fd4e5da5Sopenharmony_ci         %28 = OpLoad %10 %24
252fd4e5da5Sopenharmony_ci         %29 = OpSampledImage %14 %28 %27
253fd4e5da5Sopenharmony_ci         %30 = OpImageSampleImplicitLod %v4float %29 %23
254fd4e5da5Sopenharmony_ci         %31 = OpAccessChain %_ptr_Output_v4float %5 %int_0
255fd4e5da5Sopenharmony_ci               OpStore %31 %30
256fd4e5da5Sopenharmony_ci               OpReturn
257fd4e5da5Sopenharmony_ci               OpFunctionEnd)";
258fd4e5da5Sopenharmony_ci
259fd4e5da5Sopenharmony_ci  auto result = SinglePassRunAndDisassemble<ReplaceInvalidOpcodePass>(
260fd4e5da5Sopenharmony_ci      text, /* skip_nop = */ true, /* do_validation = */ false);
261fd4e5da5Sopenharmony_ci  EXPECT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result));
262fd4e5da5Sopenharmony_ci}
263fd4e5da5Sopenharmony_ci
264fd4e5da5Sopenharmony_ciTEST_F(ReplaceInvalidOpcodeTest, MultipleEntryPointsDifferentStage) {
265fd4e5da5Sopenharmony_ci  const std::string text = R"(
266fd4e5da5Sopenharmony_ci                OpCapability Shader
267fd4e5da5Sopenharmony_ci          %1 = OpExtInstImport "GLSL.std.450"
268fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
269fd4e5da5Sopenharmony_ci               OpEntryPoint Vertex %main "main" %3 %gl_VertexIndex %5
270fd4e5da5Sopenharmony_ci               OpEntryPoint Fragment %main2 "main2" %3 %gl_VertexIndex %5
271fd4e5da5Sopenharmony_ci               OpSource GLSL 400
272fd4e5da5Sopenharmony_ci               OpSourceExtension "GL_ARB_separate_shader_objects"
273fd4e5da5Sopenharmony_ci               OpSourceExtension "GL_ARB_shading_language_420pack"
274fd4e5da5Sopenharmony_ci               OpName %main "main"
275fd4e5da5Sopenharmony_ci               OpName %main2 "main2"
276fd4e5da5Sopenharmony_ci               OpDecorate %3 Location 0
277fd4e5da5Sopenharmony_ci               OpDecorate %gl_VertexIndex BuiltIn VertexIndex
278fd4e5da5Sopenharmony_ci               OpMemberDecorate %_struct_6 0 BuiltIn Position
279fd4e5da5Sopenharmony_ci               OpDecorate %_struct_6 Block
280fd4e5da5Sopenharmony_ci       %void = OpTypeVoid
281fd4e5da5Sopenharmony_ci          %8 = OpTypeFunction %void
282fd4e5da5Sopenharmony_ci      %float = OpTypeFloat 32
283fd4e5da5Sopenharmony_ci         %10 = OpTypeImage %float 2D 0 0 0 1 Unknown
284fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_10 = OpTypePointer UniformConstant %10
285fd4e5da5Sopenharmony_ci         %12 = OpTypeSampler
286fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_12 = OpTypePointer UniformConstant %12
287fd4e5da5Sopenharmony_ci         %14 = OpTypeSampledImage %10
288fd4e5da5Sopenharmony_ci    %v4float = OpTypeVector %float 4
289fd4e5da5Sopenharmony_ci    %v2float = OpTypeVector %float 2
290fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
291fd4e5da5Sopenharmony_ci          %3 = OpVariable %_ptr_Output_v4float Output
292fd4e5da5Sopenharmony_ci        %int = OpTypeInt 32 1
293fd4e5da5Sopenharmony_ci%_ptr_Input_int = OpTypePointer Input %int
294fd4e5da5Sopenharmony_ci%gl_VertexIndex = OpVariable %_ptr_Input_int Input
295fd4e5da5Sopenharmony_ci  %_struct_6 = OpTypeStruct %v4float
296fd4e5da5Sopenharmony_ci%_ptr_Output__struct_6 = OpTypePointer Output %_struct_6
297fd4e5da5Sopenharmony_ci          %5 = OpVariable %_ptr_Output__struct_6 Output
298fd4e5da5Sopenharmony_ci      %int_0 = OpConstant %int 0
299fd4e5da5Sopenharmony_ci    %float_0 = OpConstant %float 0
300fd4e5da5Sopenharmony_ci         %23 = OpConstantComposite %v2float %float_0 %float_0
301fd4e5da5Sopenharmony_ci         %24 = OpVariable %_ptr_UniformConstant_10 UniformConstant
302fd4e5da5Sopenharmony_ci         %25 = OpVariable %_ptr_UniformConstant_12 UniformConstant
303fd4e5da5Sopenharmony_ci       %main = OpFunction %void None %8
304fd4e5da5Sopenharmony_ci         %26 = OpLabel
305fd4e5da5Sopenharmony_ci         %27 = OpLoad %12 %25
306fd4e5da5Sopenharmony_ci         %28 = OpLoad %10 %24
307fd4e5da5Sopenharmony_ci         %29 = OpSampledImage %14 %28 %27
308fd4e5da5Sopenharmony_ci         %30 = OpImageSampleImplicitLod %v4float %29 %23
309fd4e5da5Sopenharmony_ci         %31 = OpAccessChain %_ptr_Output_v4float %5 %int_0
310fd4e5da5Sopenharmony_ci               OpStore %31 %30
311fd4e5da5Sopenharmony_ci               OpReturn
312fd4e5da5Sopenharmony_ci               OpFunctionEnd
313fd4e5da5Sopenharmony_ci      %main2 = OpFunction %void None %8
314fd4e5da5Sopenharmony_ci         %46 = OpLabel
315fd4e5da5Sopenharmony_ci         %47 = OpLoad %12 %25
316fd4e5da5Sopenharmony_ci         %48 = OpLoad %10 %24
317fd4e5da5Sopenharmony_ci         %49 = OpSampledImage %14 %48 %47
318fd4e5da5Sopenharmony_ci         %50 = OpImageSampleImplicitLod %v4float %49 %23
319fd4e5da5Sopenharmony_ci         %51 = OpAccessChain %_ptr_Output_v4float %5 %int_0
320fd4e5da5Sopenharmony_ci               OpStore %51 %50
321fd4e5da5Sopenharmony_ci               OpReturn
322fd4e5da5Sopenharmony_ci               OpFunctionEnd)";
323fd4e5da5Sopenharmony_ci
324fd4e5da5Sopenharmony_ci  auto result = SinglePassRunAndDisassemble<ReplaceInvalidOpcodePass>(
325fd4e5da5Sopenharmony_ci      text, /* skip_nop = */ true, /* do_validation = */ false);
326fd4e5da5Sopenharmony_ci  EXPECT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result));
327fd4e5da5Sopenharmony_ci}
328fd4e5da5Sopenharmony_ci
329fd4e5da5Sopenharmony_ciTEST_F(ReplaceInvalidOpcodeTest, DontReplaceLinkage) {
330fd4e5da5Sopenharmony_ci  const std::string text = R"(
331fd4e5da5Sopenharmony_ci                OpCapability Shader
332fd4e5da5Sopenharmony_ci                OpCapability Linkage
333fd4e5da5Sopenharmony_ci          %1 = OpExtInstImport "GLSL.std.450"
334fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
335fd4e5da5Sopenharmony_ci               OpEntryPoint Vertex %main "main" %3 %gl_VertexIndex %5
336fd4e5da5Sopenharmony_ci               OpSource GLSL 400
337fd4e5da5Sopenharmony_ci               OpSourceExtension "GL_ARB_separate_shader_objects"
338fd4e5da5Sopenharmony_ci               OpSourceExtension "GL_ARB_shading_language_420pack"
339fd4e5da5Sopenharmony_ci               OpName %main "main"
340fd4e5da5Sopenharmony_ci               OpDecorate %3 Location 0
341fd4e5da5Sopenharmony_ci               OpDecorate %gl_VertexIndex BuiltIn VertexIndex
342fd4e5da5Sopenharmony_ci               OpMemberDecorate %_struct_6 0 BuiltIn Position
343fd4e5da5Sopenharmony_ci               OpDecorate %_struct_6 Block
344fd4e5da5Sopenharmony_ci       %void = OpTypeVoid
345fd4e5da5Sopenharmony_ci          %8 = OpTypeFunction %void
346fd4e5da5Sopenharmony_ci      %float = OpTypeFloat 32
347fd4e5da5Sopenharmony_ci         %10 = OpTypeImage %float 2D 0 0 0 1 Unknown
348fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_10 = OpTypePointer UniformConstant %10
349fd4e5da5Sopenharmony_ci         %12 = OpTypeSampler
350fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_12 = OpTypePointer UniformConstant %12
351fd4e5da5Sopenharmony_ci         %14 = OpTypeSampledImage %10
352fd4e5da5Sopenharmony_ci    %v4float = OpTypeVector %float 4
353fd4e5da5Sopenharmony_ci    %v2float = OpTypeVector %float 2
354fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
355fd4e5da5Sopenharmony_ci          %3 = OpVariable %_ptr_Output_v4float Output
356fd4e5da5Sopenharmony_ci        %int = OpTypeInt 32 1
357fd4e5da5Sopenharmony_ci%_ptr_Input_int = OpTypePointer Input %int
358fd4e5da5Sopenharmony_ci%gl_VertexIndex = OpVariable %_ptr_Input_int Input
359fd4e5da5Sopenharmony_ci  %_struct_6 = OpTypeStruct %v4float
360fd4e5da5Sopenharmony_ci%_ptr_Output__struct_6 = OpTypePointer Output %_struct_6
361fd4e5da5Sopenharmony_ci          %5 = OpVariable %_ptr_Output__struct_6 Output
362fd4e5da5Sopenharmony_ci      %int_0 = OpConstant %int 0
363fd4e5da5Sopenharmony_ci    %float_0 = OpConstant %float 0
364fd4e5da5Sopenharmony_ci         %23 = OpConstantComposite %v2float %float_0 %float_0
365fd4e5da5Sopenharmony_ci         %24 = OpVariable %_ptr_UniformConstant_10 UniformConstant
366fd4e5da5Sopenharmony_ci         %25 = OpVariable %_ptr_UniformConstant_12 UniformConstant
367fd4e5da5Sopenharmony_ci       %main = OpFunction %void None %8
368fd4e5da5Sopenharmony_ci         %26 = OpLabel
369fd4e5da5Sopenharmony_ci         %27 = OpLoad %12 %25
370fd4e5da5Sopenharmony_ci         %28 = OpLoad %10 %24
371fd4e5da5Sopenharmony_ci         %29 = OpSampledImage %14 %28 %27
372fd4e5da5Sopenharmony_ci         %30 = OpImageSampleImplicitLod %v4float %29 %23
373fd4e5da5Sopenharmony_ci         %31 = OpAccessChain %_ptr_Output_v4float %5 %int_0
374fd4e5da5Sopenharmony_ci               OpStore %31 %30
375fd4e5da5Sopenharmony_ci               OpReturn
376fd4e5da5Sopenharmony_ci               OpFunctionEnd)";
377fd4e5da5Sopenharmony_ci
378fd4e5da5Sopenharmony_ci  auto result = SinglePassRunAndDisassemble<ReplaceInvalidOpcodePass>(
379fd4e5da5Sopenharmony_ci      text, /* skip_nop = */ true, /* do_validation = */ false);
380fd4e5da5Sopenharmony_ci  EXPECT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result));
381fd4e5da5Sopenharmony_ci}
382fd4e5da5Sopenharmony_ci
383fd4e5da5Sopenharmony_ciTEST_F(ReplaceInvalidOpcodeTest, BarrierDontReplace) {
384fd4e5da5Sopenharmony_ci  const std::string text = R"(
385fd4e5da5Sopenharmony_ci            OpCapability Shader
386fd4e5da5Sopenharmony_ci       %1 = OpExtInstImport "GLSL.std.450"
387fd4e5da5Sopenharmony_ci            OpMemoryModel Logical GLSL450
388fd4e5da5Sopenharmony_ci            OpEntryPoint GLCompute %main "main"
389fd4e5da5Sopenharmony_ci            OpExecutionMode %main LocalSize 1 1 1
390fd4e5da5Sopenharmony_ci            OpSource GLSL 450
391fd4e5da5Sopenharmony_ci            OpSourceExtension "GL_GOOGLE_cpp_style_line_directive"
392fd4e5da5Sopenharmony_ci            OpSourceExtension "GL_GOOGLE_include_directive"
393fd4e5da5Sopenharmony_ci            OpName %main "main"
394fd4e5da5Sopenharmony_ci    %void = OpTypeVoid
395fd4e5da5Sopenharmony_ci       %3 = OpTypeFunction %void
396fd4e5da5Sopenharmony_ci    %uint = OpTypeInt 32 0
397fd4e5da5Sopenharmony_ci  %uint_2 = OpConstant %uint 2
398fd4e5da5Sopenharmony_ci%uint_264 = OpConstant %uint 264
399fd4e5da5Sopenharmony_ci    %main = OpFunction %void None %3
400fd4e5da5Sopenharmony_ci       %5 = OpLabel
401fd4e5da5Sopenharmony_ci            OpControlBarrier %uint_2 %uint_2 %uint_264
402fd4e5da5Sopenharmony_ci            OpReturn
403fd4e5da5Sopenharmony_ci            OpFunctionEnd)";
404fd4e5da5Sopenharmony_ci
405fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_UNIVERSAL_1_2);
406fd4e5da5Sopenharmony_ci  auto result = SinglePassRunAndDisassemble<ReplaceInvalidOpcodePass>(
407fd4e5da5Sopenharmony_ci      text, /* skip_nop = */ true, /* do_validation = */ false);
408fd4e5da5Sopenharmony_ci  EXPECT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result));
409fd4e5da5Sopenharmony_ci}
410fd4e5da5Sopenharmony_ci
411fd4e5da5Sopenharmony_ciTEST_F(ReplaceInvalidOpcodeTest, BarrierReplace) {
412fd4e5da5Sopenharmony_ci  const std::string text = R"(
413fd4e5da5Sopenharmony_ci; CHECK-NOT: OpControlBarrier
414fd4e5da5Sopenharmony_ci            OpCapability Shader
415fd4e5da5Sopenharmony_ci       %1 = OpExtInstImport "GLSL.std.450"
416fd4e5da5Sopenharmony_ci            OpMemoryModel Logical GLSL450
417fd4e5da5Sopenharmony_ci            OpEntryPoint Vertex %main "main"
418fd4e5da5Sopenharmony_ci            OpExecutionMode %main LocalSize 1 1 1
419fd4e5da5Sopenharmony_ci            OpSource GLSL 450
420fd4e5da5Sopenharmony_ci            OpSourceExtension "GL_GOOGLE_cpp_style_line_directive"
421fd4e5da5Sopenharmony_ci            OpSourceExtension "GL_GOOGLE_include_directive"
422fd4e5da5Sopenharmony_ci            OpName %main "main"
423fd4e5da5Sopenharmony_ci    %void = OpTypeVoid
424fd4e5da5Sopenharmony_ci       %3 = OpTypeFunction %void
425fd4e5da5Sopenharmony_ci    %uint = OpTypeInt 32 0
426fd4e5da5Sopenharmony_ci  %uint_2 = OpConstant %uint 2
427fd4e5da5Sopenharmony_ci%uint_264 = OpConstant %uint 264
428fd4e5da5Sopenharmony_ci    %main = OpFunction %void None %3
429fd4e5da5Sopenharmony_ci       %5 = OpLabel
430fd4e5da5Sopenharmony_ci            OpControlBarrier %uint_2 %uint_2 %uint_264
431fd4e5da5Sopenharmony_ci            OpReturn
432fd4e5da5Sopenharmony_ci            OpFunctionEnd)";
433fd4e5da5Sopenharmony_ci
434fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_UNIVERSAL_1_2);
435fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<ReplaceInvalidOpcodePass>(text, false);
436fd4e5da5Sopenharmony_ci}
437fd4e5da5Sopenharmony_ci
438fd4e5da5Sopenharmony_ci// Since version 1.3 OpControlBarriers are allowed is more shaders.
439fd4e5da5Sopenharmony_ci// https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpControlBarrier
440fd4e5da5Sopenharmony_ciTEST_F(ReplaceInvalidOpcodeTest, BarrierDontReplaceV13) {
441fd4e5da5Sopenharmony_ci  const std::string text = R"(
442fd4e5da5Sopenharmony_ci            OpCapability Shader
443fd4e5da5Sopenharmony_ci       %1 = OpExtInstImport "GLSL.std.450"
444fd4e5da5Sopenharmony_ci            OpMemoryModel Logical GLSL450
445fd4e5da5Sopenharmony_ci            OpEntryPoint Vertex %main "main"
446fd4e5da5Sopenharmony_ci            OpExecutionMode %main LocalSize 1 1 1
447fd4e5da5Sopenharmony_ci            OpSource GLSL 450
448fd4e5da5Sopenharmony_ci            OpSourceExtension "GL_GOOGLE_cpp_style_line_directive"
449fd4e5da5Sopenharmony_ci            OpSourceExtension "GL_GOOGLE_include_directive"
450fd4e5da5Sopenharmony_ci            OpName %main "main"
451fd4e5da5Sopenharmony_ci    %void = OpTypeVoid
452fd4e5da5Sopenharmony_ci       %3 = OpTypeFunction %void
453fd4e5da5Sopenharmony_ci    %uint = OpTypeInt 32 0
454fd4e5da5Sopenharmony_ci  %uint_2 = OpConstant %uint 2
455fd4e5da5Sopenharmony_ci%uint_264 = OpConstant %uint 264
456fd4e5da5Sopenharmony_ci    %main = OpFunction %void None %3
457fd4e5da5Sopenharmony_ci       %5 = OpLabel
458fd4e5da5Sopenharmony_ci            OpControlBarrier %uint_2 %uint_2 %uint_264
459fd4e5da5Sopenharmony_ci            OpReturn
460fd4e5da5Sopenharmony_ci            OpFunctionEnd)";
461fd4e5da5Sopenharmony_ci
462fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_UNIVERSAL_1_3);
463fd4e5da5Sopenharmony_ci  auto result = SinglePassRunAndDisassemble<ReplaceInvalidOpcodePass>(
464fd4e5da5Sopenharmony_ci      text, /* skip_nop = */ true, /* do_validation = */ false);
465fd4e5da5Sopenharmony_ci  EXPECT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result));
466fd4e5da5Sopenharmony_ci}
467fd4e5da5Sopenharmony_ci
468fd4e5da5Sopenharmony_ciTEST_F(ReplaceInvalidOpcodeTest, MessageTest) {
469fd4e5da5Sopenharmony_ci  const std::string text = R"(
470fd4e5da5Sopenharmony_ci               OpCapability Shader
471fd4e5da5Sopenharmony_ci          %1 = OpExtInstImport "GLSL.std.450"
472fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
473fd4e5da5Sopenharmony_ci               OpEntryPoint Vertex %main "main" %3 %gl_VertexIndex %5
474fd4e5da5Sopenharmony_ci               OpSource GLSL 400
475fd4e5da5Sopenharmony_ci          %6 = OpString "test.hlsl"
476fd4e5da5Sopenharmony_ci               OpSourceExtension "GL_ARB_separate_shader_objects"
477fd4e5da5Sopenharmony_ci               OpSourceExtension "GL_ARB_shading_language_420pack"
478fd4e5da5Sopenharmony_ci               OpName %main "main"
479fd4e5da5Sopenharmony_ci               OpDecorate %3 Location 0
480fd4e5da5Sopenharmony_ci               OpDecorate %gl_VertexIndex BuiltIn VertexIndex
481fd4e5da5Sopenharmony_ci               OpMemberDecorate %_struct_7 0 BuiltIn Position
482fd4e5da5Sopenharmony_ci               OpDecorate %_struct_7 Block
483fd4e5da5Sopenharmony_ci       %void = OpTypeVoid
484fd4e5da5Sopenharmony_ci          %9 = OpTypeFunction %void
485fd4e5da5Sopenharmony_ci      %float = OpTypeFloat 32
486fd4e5da5Sopenharmony_ci         %11 = OpTypeImage %float 2D 0 0 0 1 Unknown
487fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_11 = OpTypePointer UniformConstant %11
488fd4e5da5Sopenharmony_ci         %13 = OpTypeSampler
489fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
490fd4e5da5Sopenharmony_ci         %15 = OpTypeSampledImage %11
491fd4e5da5Sopenharmony_ci    %v4float = OpTypeVector %float 4
492fd4e5da5Sopenharmony_ci    %v2float = OpTypeVector %float 2
493fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
494fd4e5da5Sopenharmony_ci          %3 = OpVariable %_ptr_Output_v4float Output
495fd4e5da5Sopenharmony_ci        %int = OpTypeInt 32 1
496fd4e5da5Sopenharmony_ci%_ptr_Input_int = OpTypePointer Input %int
497fd4e5da5Sopenharmony_ci%gl_VertexIndex = OpVariable %_ptr_Input_int Input
498fd4e5da5Sopenharmony_ci  %_struct_7 = OpTypeStruct %v4float
499fd4e5da5Sopenharmony_ci%_ptr_Output__struct_7 = OpTypePointer Output %_struct_7
500fd4e5da5Sopenharmony_ci          %5 = OpVariable %_ptr_Output__struct_7 Output
501fd4e5da5Sopenharmony_ci      %int_0 = OpConstant %int 0
502fd4e5da5Sopenharmony_ci    %float_0 = OpConstant %float 0
503fd4e5da5Sopenharmony_ci         %24 = OpConstantComposite %v2float %float_0 %float_0
504fd4e5da5Sopenharmony_ci         %25 = OpVariable %_ptr_UniformConstant_11 UniformConstant
505fd4e5da5Sopenharmony_ci         %26 = OpVariable %_ptr_UniformConstant_13 UniformConstant
506fd4e5da5Sopenharmony_ci       %main = OpFunction %void None %9
507fd4e5da5Sopenharmony_ci         %27 = OpLabel
508fd4e5da5Sopenharmony_ci               OpLine %6 2 4
509fd4e5da5Sopenharmony_ci         %28 = OpLoad %13 %26
510fd4e5da5Sopenharmony_ci         %29 = OpLoad %11 %25
511fd4e5da5Sopenharmony_ci         %30 = OpSampledImage %15 %29 %28
512fd4e5da5Sopenharmony_ci         %31 = OpImageSampleImplicitLod %v4float %30 %24
513fd4e5da5Sopenharmony_ci         %32 = OpAccessChain %_ptr_Output_v4float %5 %int_0
514fd4e5da5Sopenharmony_ci               OpStore %32 %31
515fd4e5da5Sopenharmony_ci               OpReturn
516fd4e5da5Sopenharmony_ci               OpFunctionEnd)";
517fd4e5da5Sopenharmony_ci
518fd4e5da5Sopenharmony_ci  std::vector<Message> messages = {
519fd4e5da5Sopenharmony_ci      {SPV_MSG_WARNING, "test.hlsl", 2, 4,
520fd4e5da5Sopenharmony_ci       "Removing ImageSampleImplicitLod instruction because of incompatible "
521fd4e5da5Sopenharmony_ci       "execution model."}};
522fd4e5da5Sopenharmony_ci  SetMessageConsumer(GetTestMessageConsumer(messages));
523fd4e5da5Sopenharmony_ci  auto result = SinglePassRunAndDisassemble<ReplaceInvalidOpcodePass>(
524fd4e5da5Sopenharmony_ci      text, /* skip_nop = */ true, /* do_validation = */ false);
525fd4e5da5Sopenharmony_ci  EXPECT_EQ(Pass::Status::SuccessWithChange, std::get<1>(result));
526fd4e5da5Sopenharmony_ci}
527fd4e5da5Sopenharmony_ci
528fd4e5da5Sopenharmony_ciTEST_F(ReplaceInvalidOpcodeTest, MultipleMessageTest) {
529fd4e5da5Sopenharmony_ci  const std::string text = R"(
530fd4e5da5Sopenharmony_ci               OpCapability Shader
531fd4e5da5Sopenharmony_ci          %1 = OpExtInstImport "GLSL.std.450"
532fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
533fd4e5da5Sopenharmony_ci               OpEntryPoint Vertex %main "main" %3 %gl_VertexIndex %5
534fd4e5da5Sopenharmony_ci               OpSource GLSL 400
535fd4e5da5Sopenharmony_ci          %6 = OpString "test.hlsl"
536fd4e5da5Sopenharmony_ci               OpSourceExtension "GL_ARB_separate_shader_objects"
537fd4e5da5Sopenharmony_ci               OpSourceExtension "GL_ARB_shading_language_420pack"
538fd4e5da5Sopenharmony_ci               OpName %main "main"
539fd4e5da5Sopenharmony_ci               OpDecorate %3 Location 0
540fd4e5da5Sopenharmony_ci               OpDecorate %gl_VertexIndex BuiltIn VertexIndex
541fd4e5da5Sopenharmony_ci               OpMemberDecorate %_struct_7 0 BuiltIn Position
542fd4e5da5Sopenharmony_ci               OpDecorate %_struct_7 Block
543fd4e5da5Sopenharmony_ci       %void = OpTypeVoid
544fd4e5da5Sopenharmony_ci          %9 = OpTypeFunction %void
545fd4e5da5Sopenharmony_ci      %float = OpTypeFloat 32
546fd4e5da5Sopenharmony_ci         %11 = OpTypeImage %float 2D 0 0 0 1 Unknown
547fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_11 = OpTypePointer UniformConstant %11
548fd4e5da5Sopenharmony_ci         %13 = OpTypeSampler
549fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
550fd4e5da5Sopenharmony_ci         %15 = OpTypeSampledImage %11
551fd4e5da5Sopenharmony_ci    %v4float = OpTypeVector %float 4
552fd4e5da5Sopenharmony_ci    %v2float = OpTypeVector %float 2
553fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
554fd4e5da5Sopenharmony_ci          %3 = OpVariable %_ptr_Output_v4float Output
555fd4e5da5Sopenharmony_ci        %int = OpTypeInt 32 1
556fd4e5da5Sopenharmony_ci%_ptr_Input_int = OpTypePointer Input %int
557fd4e5da5Sopenharmony_ci%gl_VertexIndex = OpVariable %_ptr_Input_int Input
558fd4e5da5Sopenharmony_ci  %_struct_7 = OpTypeStruct %v4float
559fd4e5da5Sopenharmony_ci%_ptr_Output__struct_7 = OpTypePointer Output %_struct_7
560fd4e5da5Sopenharmony_ci          %5 = OpVariable %_ptr_Output__struct_7 Output
561fd4e5da5Sopenharmony_ci      %int_0 = OpConstant %int 0
562fd4e5da5Sopenharmony_ci    %float_0 = OpConstant %float 0
563fd4e5da5Sopenharmony_ci         %24 = OpConstantComposite %v2float %float_0 %float_0
564fd4e5da5Sopenharmony_ci         %25 = OpVariable %_ptr_UniformConstant_11 UniformConstant
565fd4e5da5Sopenharmony_ci         %26 = OpVariable %_ptr_UniformConstant_13 UniformConstant
566fd4e5da5Sopenharmony_ci       %main = OpFunction %void None %9
567fd4e5da5Sopenharmony_ci         %27 = OpLabel
568fd4e5da5Sopenharmony_ci               OpLine %6 2 4
569fd4e5da5Sopenharmony_ci         %28 = OpLoad %13 %26
570fd4e5da5Sopenharmony_ci         %29 = OpLoad %11 %25
571fd4e5da5Sopenharmony_ci         %30 = OpSampledImage %15 %29 %28
572fd4e5da5Sopenharmony_ci         %31 = OpImageSampleImplicitLod %v4float %30 %24
573fd4e5da5Sopenharmony_ci               OpLine %6 12 4
574fd4e5da5Sopenharmony_ci         %41 = OpImageSampleProjImplicitLod %v4float %30 %24
575fd4e5da5Sopenharmony_ci         %32 = OpAccessChain %_ptr_Output_v4float %5 %int_0
576fd4e5da5Sopenharmony_ci               OpStore %32 %31
577fd4e5da5Sopenharmony_ci               OpReturn
578fd4e5da5Sopenharmony_ci               OpFunctionEnd)";
579fd4e5da5Sopenharmony_ci
580fd4e5da5Sopenharmony_ci  std::vector<Message> messages = {
581fd4e5da5Sopenharmony_ci      {SPV_MSG_WARNING, "test.hlsl", 2, 4,
582fd4e5da5Sopenharmony_ci       "Removing ImageSampleImplicitLod instruction because of incompatible "
583fd4e5da5Sopenharmony_ci       "execution model."},
584fd4e5da5Sopenharmony_ci      {SPV_MSG_WARNING, "test.hlsl", 12, 4,
585fd4e5da5Sopenharmony_ci       "Removing ImageSampleProjImplicitLod instruction because of "
586fd4e5da5Sopenharmony_ci       "incompatible "
587fd4e5da5Sopenharmony_ci       "execution model."}};
588fd4e5da5Sopenharmony_ci  SetMessageConsumer(GetTestMessageConsumer(messages));
589fd4e5da5Sopenharmony_ci  auto result = SinglePassRunAndDisassemble<ReplaceInvalidOpcodePass>(
590fd4e5da5Sopenharmony_ci      text, /* skip_nop = */ true, /* do_validation = */ false);
591fd4e5da5Sopenharmony_ci  EXPECT_EQ(Pass::Status::SuccessWithChange, std::get<1>(result));
592fd4e5da5Sopenharmony_ci}
593fd4e5da5Sopenharmony_ci
594fd4e5da5Sopenharmony_ci}  // namespace
595fd4e5da5Sopenharmony_ci}  // namespace opt
596fd4e5da5Sopenharmony_ci}  // namespace spvtools
597