1fd4e5da5Sopenharmony_ci// Copyright (c) 2022 Google LLC
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
17fd4e5da5Sopenharmony_ci#include "test/opt/pass_fixture.h"
18fd4e5da5Sopenharmony_ci#include "test/opt/pass_utils.h"
19fd4e5da5Sopenharmony_ci
20fd4e5da5Sopenharmony_cinamespace spvtools {
21fd4e5da5Sopenharmony_cinamespace opt {
22fd4e5da5Sopenharmony_cinamespace {
23fd4e5da5Sopenharmony_ci
24fd4e5da5Sopenharmony_cistruct ExecutionModelAndBuiltIn {
25fd4e5da5Sopenharmony_ci  const char* execution_model;
26fd4e5da5Sopenharmony_ci  const char* built_in;
27fd4e5da5Sopenharmony_ci  const bool use_v4uint;
28fd4e5da5Sopenharmony_ci};
29fd4e5da5Sopenharmony_ci
30fd4e5da5Sopenharmony_ciusing AddVolatileDecorationTest =
31fd4e5da5Sopenharmony_ci    PassTest<::testing::TestWithParam<ExecutionModelAndBuiltIn>>;
32fd4e5da5Sopenharmony_ci
33fd4e5da5Sopenharmony_ciTEST_P(AddVolatileDecorationTest, InMain) {
34fd4e5da5Sopenharmony_ci  const auto& tc = GetParam();
35fd4e5da5Sopenharmony_ci  const std::string execution_model(tc.execution_model);
36fd4e5da5Sopenharmony_ci  const std::string built_in(tc.built_in);
37fd4e5da5Sopenharmony_ci  const std::string var_type =
38fd4e5da5Sopenharmony_ci      tc.use_v4uint ? "%_ptr_Input_v4uint" : "%_ptr_Input_uint";
39fd4e5da5Sopenharmony_ci  const std::string var_load_type = tc.use_v4uint ? "%v4uint" : "%uint";
40fd4e5da5Sopenharmony_ci
41fd4e5da5Sopenharmony_ci  const std::string text =
42fd4e5da5Sopenharmony_ci      std::string(R"(OpCapability RuntimeDescriptorArray
43fd4e5da5Sopenharmony_ciOpCapability RayTracingKHR
44fd4e5da5Sopenharmony_ciOpCapability SubgroupBallotKHR
45fd4e5da5Sopenharmony_ciOpExtension "SPV_EXT_descriptor_indexing"
46fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_ray_tracing"
47fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_shader_ballot"
48fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
49fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
50fd4e5da5Sopenharmony_ciOpEntryPoint )") +
51fd4e5da5Sopenharmony_ci      execution_model + std::string(R"( %main "main" %var
52fd4e5da5Sopenharmony_ciOpSource GLSL 460
53fd4e5da5Sopenharmony_ciOpSourceExtension "GL_EXT_nonuniform_qualifier"
54fd4e5da5Sopenharmony_ciOpSourceExtension "GL_KHR_ray_tracing"
55fd4e5da5Sopenharmony_ciOpName %main "main"
56fd4e5da5Sopenharmony_ciOpName %fn "fn"
57fd4e5da5Sopenharmony_ciOpName %StorageBuffer "StorageBuffer"
58fd4e5da5Sopenharmony_ciOpMemberName %StorageBuffer 0 "index"
59fd4e5da5Sopenharmony_ciOpMemberName %StorageBuffer 1 "red"
60fd4e5da5Sopenharmony_ciOpName %sbo "sbo"
61fd4e5da5Sopenharmony_ciOpName %images "images"
62fd4e5da5Sopenharmony_ciOpMemberDecorate %StorageBuffer 0 Offset 0
63fd4e5da5Sopenharmony_ciOpMemberDecorate %StorageBuffer 1 Offset 4
64fd4e5da5Sopenharmony_ciOpDecorate %StorageBuffer BufferBlock
65fd4e5da5Sopenharmony_ciOpDecorate %sbo DescriptorSet 0
66fd4e5da5Sopenharmony_ciOpDecorate %sbo Binding 0
67fd4e5da5Sopenharmony_ciOpDecorate %images DescriptorSet 0
68fd4e5da5Sopenharmony_ciOpDecorate %images Binding 1
69fd4e5da5Sopenharmony_ciOpDecorate %images NonWritable
70fd4e5da5Sopenharmony_ci)") + std::string(R"(
71fd4e5da5Sopenharmony_ci; CHECK: OpDecorate [[var:%\w+]] BuiltIn )") +
72fd4e5da5Sopenharmony_ci      built_in + std::string(R"(
73fd4e5da5Sopenharmony_ci; CHECK: OpDecorate [[var]] Volatile
74fd4e5da5Sopenharmony_ciOpDecorate %var BuiltIn )") + built_in + std::string(R"(
75fd4e5da5Sopenharmony_ci%void = OpTypeVoid
76fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
77fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
78fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
79fd4e5da5Sopenharmony_ci%StorageBuffer = OpTypeStruct %uint %float
80fd4e5da5Sopenharmony_ci%_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
81fd4e5da5Sopenharmony_ci%sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
82fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
83fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
84fd4e5da5Sopenharmony_ci%13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
85fd4e5da5Sopenharmony_ci%_runtimearr_13 = OpTypeRuntimeArray %13
86fd4e5da5Sopenharmony_ci%_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
87fd4e5da5Sopenharmony_ci%images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
88fd4e5da5Sopenharmony_ci%_ptr_Input_uint = OpTypePointer Input %uint
89fd4e5da5Sopenharmony_ci%v4uint = OpTypeVector %uint 4
90fd4e5da5Sopenharmony_ci%_ptr_Input_v4uint = OpTypePointer Input %v4uint
91fd4e5da5Sopenharmony_ci%var = OpVariable )") +
92fd4e5da5Sopenharmony_ci      var_type + std::string(R"( Input
93fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
94fd4e5da5Sopenharmony_ci%_ptr_Uniform_uint = OpTypePointer Uniform %uint
95fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
96fd4e5da5Sopenharmony_ci%v2int = OpTypeVector %int 2
97fd4e5da5Sopenharmony_ci%25 = OpConstantComposite %v2int %int_0 %int_0
98fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
99fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
100fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float
101fd4e5da5Sopenharmony_ci%main = OpFunction %void None %3
102fd4e5da5Sopenharmony_ci%5 = OpLabel
103fd4e5da5Sopenharmony_ci%19 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
104fd4e5da5Sopenharmony_ci%20 = OpLoad %uint %19
105fd4e5da5Sopenharmony_ci%load = OpLoad )") + var_load_type + std::string(R"( %var
106fd4e5da5Sopenharmony_ci%22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
107fd4e5da5Sopenharmony_ci%23 = OpLoad %13 %22
108fd4e5da5Sopenharmony_ci%27 = OpImageRead %v4float %23 %25
109fd4e5da5Sopenharmony_ci%29 = OpCompositeExtract %float %27 0
110fd4e5da5Sopenharmony_ci%31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
111fd4e5da5Sopenharmony_ciOpStore %31 %29
112fd4e5da5Sopenharmony_ci%32 = OpFunctionCall %void %fn
113fd4e5da5Sopenharmony_ciOpReturn
114fd4e5da5Sopenharmony_ciOpFunctionEnd
115fd4e5da5Sopenharmony_ci%fn = OpFunction %void None %3
116fd4e5da5Sopenharmony_ci%33 = OpLabel
117fd4e5da5Sopenharmony_ciOpReturn
118fd4e5da5Sopenharmony_ciOpFunctionEnd
119fd4e5da5Sopenharmony_ci)");
120fd4e5da5Sopenharmony_ci
121fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<SpreadVolatileSemantics>(text, true);
122fd4e5da5Sopenharmony_ci}
123fd4e5da5Sopenharmony_ci
124fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(
125fd4e5da5Sopenharmony_ci    AddVolatileDecoration, AddVolatileDecorationTest,
126fd4e5da5Sopenharmony_ci    ::testing::ValuesIn(std::vector<ExecutionModelAndBuiltIn>{
127fd4e5da5Sopenharmony_ci        {"RayGenerationKHR", "SubgroupSize", false},
128fd4e5da5Sopenharmony_ci        {"RayGenerationKHR", "SubgroupLocalInvocationId", false},
129fd4e5da5Sopenharmony_ci        {"RayGenerationKHR", "SubgroupEqMask", true},
130fd4e5da5Sopenharmony_ci        {"ClosestHitKHR", "SubgroupLocalInvocationId", true},
131fd4e5da5Sopenharmony_ci        {"IntersectionKHR", "SubgroupEqMask", true},
132fd4e5da5Sopenharmony_ci        {"MissKHR", "SubgroupGeMask", true},
133fd4e5da5Sopenharmony_ci        {"CallableKHR", "SubgroupGtMask", true},
134fd4e5da5Sopenharmony_ci        {"RayGenerationKHR", "SubgroupLeMask", true},
135fd4e5da5Sopenharmony_ci    }));
136fd4e5da5Sopenharmony_ci
137fd4e5da5Sopenharmony_ciusing SetLoadVolatileTest =
138fd4e5da5Sopenharmony_ci    PassTest<::testing::TestWithParam<ExecutionModelAndBuiltIn>>;
139fd4e5da5Sopenharmony_ci
140fd4e5da5Sopenharmony_ciTEST_P(SetLoadVolatileTest, InMain) {
141fd4e5da5Sopenharmony_ci  const auto& tc = GetParam();
142fd4e5da5Sopenharmony_ci  const std::string execution_model(tc.execution_model);
143fd4e5da5Sopenharmony_ci  const std::string built_in(tc.built_in);
144fd4e5da5Sopenharmony_ci
145fd4e5da5Sopenharmony_ci  const std::string var_type =
146fd4e5da5Sopenharmony_ci      tc.use_v4uint ? "%_ptr_Input_v4uint" : "%_ptr_Input_uint";
147fd4e5da5Sopenharmony_ci  const std::string var_value = tc.use_v4uint ? std::string(R"(
148fd4e5da5Sopenharmony_ci; CHECK: [[ptr:%\w+]] = OpAccessChain %_ptr_Input_uint [[var]] %int_0
149fd4e5da5Sopenharmony_ci; CHECK: OpLoad {{%\w+}} [[ptr]] Volatile
150fd4e5da5Sopenharmony_ci%ptr = OpAccessChain %_ptr_Input_uint %var %int_0
151fd4e5da5Sopenharmony_ci%var_value = OpLoad %uint %ptr)")
152fd4e5da5Sopenharmony_ci                                              : std::string(R"(
153fd4e5da5Sopenharmony_ci; CHECK: OpLoad {{%\w+}} [[var]] Volatile
154fd4e5da5Sopenharmony_ci%var_value = OpLoad %uint %var)");
155fd4e5da5Sopenharmony_ci
156fd4e5da5Sopenharmony_ci  const std::string text = std::string(R"(OpCapability RuntimeDescriptorArray
157fd4e5da5Sopenharmony_ciOpCapability RayTracingKHR
158fd4e5da5Sopenharmony_ciOpCapability SubgroupBallotKHR
159fd4e5da5Sopenharmony_ciOpCapability VulkanMemoryModel
160fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_vulkan_memory_model"
161fd4e5da5Sopenharmony_ciOpExtension "SPV_EXT_descriptor_indexing"
162fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_ray_tracing"
163fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_shader_ballot"
164fd4e5da5Sopenharmony_ciOpMemoryModel Logical Vulkan
165fd4e5da5Sopenharmony_ciOpEntryPoint )") + execution_model +
166fd4e5da5Sopenharmony_ci                           std::string(R"( %main "main" %var
167fd4e5da5Sopenharmony_ciOpName %main "main"
168fd4e5da5Sopenharmony_ciOpName %StorageBuffer "StorageBuffer"
169fd4e5da5Sopenharmony_ciOpMemberName %StorageBuffer 0 "index"
170fd4e5da5Sopenharmony_ciOpMemberName %StorageBuffer 1 "red"
171fd4e5da5Sopenharmony_ciOpName %sbo "sbo"
172fd4e5da5Sopenharmony_ciOpName %images "images"
173fd4e5da5Sopenharmony_ciOpMemberDecorate %StorageBuffer 0 Offset 0
174fd4e5da5Sopenharmony_ciOpMemberDecorate %StorageBuffer 1 Offset 4
175fd4e5da5Sopenharmony_ciOpDecorate %StorageBuffer BufferBlock
176fd4e5da5Sopenharmony_ciOpDecorate %sbo DescriptorSet 0
177fd4e5da5Sopenharmony_ciOpDecorate %sbo Binding 0
178fd4e5da5Sopenharmony_ciOpDecorate %images DescriptorSet 0
179fd4e5da5Sopenharmony_ciOpDecorate %images Binding 1
180fd4e5da5Sopenharmony_ciOpDecorate %images NonWritable
181fd4e5da5Sopenharmony_ci)") + std::string(R"(
182fd4e5da5Sopenharmony_ci; CHECK: OpDecorate [[var:%\w+]] BuiltIn )") +
183fd4e5da5Sopenharmony_ci                           built_in + std::string(R"(
184fd4e5da5Sopenharmony_ciOpDecorate %var BuiltIn )") + built_in +
185fd4e5da5Sopenharmony_ci                           std::string(R"(
186fd4e5da5Sopenharmony_ci%void = OpTypeVoid
187fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
188fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
189fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
190fd4e5da5Sopenharmony_ci%StorageBuffer = OpTypeStruct %uint %float
191fd4e5da5Sopenharmony_ci%_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
192fd4e5da5Sopenharmony_ci%sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
193fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
194fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
195fd4e5da5Sopenharmony_ci%13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
196fd4e5da5Sopenharmony_ci%_runtimearr_13 = OpTypeRuntimeArray %13
197fd4e5da5Sopenharmony_ci%_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
198fd4e5da5Sopenharmony_ci%images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
199fd4e5da5Sopenharmony_ci%_ptr_Input_uint = OpTypePointer Input %uint
200fd4e5da5Sopenharmony_ci%v4uint = OpTypeVector %uint 4
201fd4e5da5Sopenharmony_ci%_ptr_Input_v4uint = OpTypePointer Input %v4uint
202fd4e5da5Sopenharmony_ci%var = OpVariable )") + var_type +
203fd4e5da5Sopenharmony_ci                           std::string(R"( Input
204fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
205fd4e5da5Sopenharmony_ci%_ptr_Uniform_uint = OpTypePointer Uniform %uint
206fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
207fd4e5da5Sopenharmony_ci%v2int = OpTypeVector %int 2
208fd4e5da5Sopenharmony_ci%25 = OpConstantComposite %v2int %int_0 %int_0
209fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
210fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
211fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float
212fd4e5da5Sopenharmony_ci%main = OpFunction %void None %3
213fd4e5da5Sopenharmony_ci%5 = OpLabel
214fd4e5da5Sopenharmony_ci%19 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
215fd4e5da5Sopenharmony_ci%20 = OpLoad %uint %19
216fd4e5da5Sopenharmony_ci)") + var_value + std::string(R"(
217fd4e5da5Sopenharmony_ci%test = OpIAdd %uint %var_value %20
218fd4e5da5Sopenharmony_ci%22 = OpAccessChain %_ptr_UniformConstant_13 %images %test
219fd4e5da5Sopenharmony_ci%23 = OpLoad %13 %22
220fd4e5da5Sopenharmony_ci%27 = OpImageRead %v4float %23 %25
221fd4e5da5Sopenharmony_ci%29 = OpCompositeExtract %float %27 0
222fd4e5da5Sopenharmony_ci%31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
223fd4e5da5Sopenharmony_ciOpStore %31 %29
224fd4e5da5Sopenharmony_ciOpReturn
225fd4e5da5Sopenharmony_ciOpFunctionEnd
226fd4e5da5Sopenharmony_ci)");
227fd4e5da5Sopenharmony_ci
228fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<SpreadVolatileSemantics>(text, true);
229fd4e5da5Sopenharmony_ci}
230fd4e5da5Sopenharmony_ci
231fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(
232fd4e5da5Sopenharmony_ci    SetLoadVolatile, SetLoadVolatileTest,
233fd4e5da5Sopenharmony_ci    ::testing::ValuesIn(std::vector<ExecutionModelAndBuiltIn>{
234fd4e5da5Sopenharmony_ci        {"RayGenerationKHR", "SubgroupSize", false},
235fd4e5da5Sopenharmony_ci        {"RayGenerationKHR", "SubgroupLocalInvocationId", false},
236fd4e5da5Sopenharmony_ci        {"RayGenerationKHR", "SubgroupEqMask", true},
237fd4e5da5Sopenharmony_ci        {"ClosestHitKHR", "SubgroupLocalInvocationId", true},
238fd4e5da5Sopenharmony_ci        {"IntersectionKHR", "SubgroupEqMask", true},
239fd4e5da5Sopenharmony_ci        {"MissKHR", "SubgroupGeMask", true},
240fd4e5da5Sopenharmony_ci        {"CallableKHR", "SubgroupGtMask", true},
241fd4e5da5Sopenharmony_ci        {"RayGenerationKHR", "SubgroupLeMask", true},
242fd4e5da5Sopenharmony_ci    }));
243fd4e5da5Sopenharmony_ci
244fd4e5da5Sopenharmony_ciusing VolatileSpreadTest = PassTest<::testing::Test>;
245fd4e5da5Sopenharmony_ci
246fd4e5da5Sopenharmony_ciTEST_F(VolatileSpreadTest, SpreadVolatileForHelperInvocation) {
247fd4e5da5Sopenharmony_ci  const std::string text =
248fd4e5da5Sopenharmony_ci      R"(
249fd4e5da5Sopenharmony_ciOpCapability Shader
250fd4e5da5Sopenharmony_ciOpCapability DemoteToHelperInvocation
251fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
252fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %var
253fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
254fd4e5da5Sopenharmony_ci
255fd4e5da5Sopenharmony_ci; CHECK: OpDecorate [[var:%\w+]] BuiltIn HelperInvocation
256fd4e5da5Sopenharmony_ci; CHECK: OpDecorate [[var]] Volatile
257fd4e5da5Sopenharmony_ciOpDecorate %var BuiltIn HelperInvocation
258fd4e5da5Sopenharmony_ci
259fd4e5da5Sopenharmony_ci%bool = OpTypeBool
260fd4e5da5Sopenharmony_ci%void = OpTypeVoid
261fd4e5da5Sopenharmony_ci%void_fn = OpTypeFunction %void
262fd4e5da5Sopenharmony_ci%_ptr_Input_bool = OpTypePointer Input %bool
263fd4e5da5Sopenharmony_ci%var = OpVariable %_ptr_Input_bool Input
264fd4e5da5Sopenharmony_ci%main = OpFunction %void None %void_fn
265fd4e5da5Sopenharmony_ci%entry = OpLabel
266fd4e5da5Sopenharmony_ci%load = OpLoad %bool %var
267fd4e5da5Sopenharmony_ciOpDemoteToHelperInvocation
268fd4e5da5Sopenharmony_ciOpReturn
269fd4e5da5Sopenharmony_ciOpFunctionEnd
270fd4e5da5Sopenharmony_ci)";
271fd4e5da5Sopenharmony_ci
272fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_UNIVERSAL_1_6);
273fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<SpreadVolatileSemantics>(text, true);
274fd4e5da5Sopenharmony_ci}
275fd4e5da5Sopenharmony_ci
276fd4e5da5Sopenharmony_ciTEST_F(VolatileSpreadTest, MultipleExecutionModel) {
277fd4e5da5Sopenharmony_ci  const std::string text =
278fd4e5da5Sopenharmony_ci      R"(
279fd4e5da5Sopenharmony_ciOpCapability RuntimeDescriptorArray
280fd4e5da5Sopenharmony_ciOpCapability RayTracingKHR
281fd4e5da5Sopenharmony_ciOpCapability SubgroupBallotKHR
282fd4e5da5Sopenharmony_ciOpExtension "SPV_EXT_descriptor_indexing"
283fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_ray_tracing"
284fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_shader_ballot"
285fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
286fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
287fd4e5da5Sopenharmony_ciOpEntryPoint RayGenerationKHR %RayGeneration "RayGeneration" %var
288fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %compute "Compute" %gl_LocalInvocationIndex
289fd4e5da5Sopenharmony_ciOpExecutionMode %compute LocalSize 16 16 1
290fd4e5da5Sopenharmony_ciOpSource GLSL 460
291fd4e5da5Sopenharmony_ciOpSourceExtension "GL_EXT_nonuniform_qualifier"
292fd4e5da5Sopenharmony_ciOpSourceExtension "GL_KHR_ray_tracing"
293fd4e5da5Sopenharmony_ciOpName %RayGeneration "RayGeneration"
294fd4e5da5Sopenharmony_ciOpName %StorageBuffer "StorageBuffer"
295fd4e5da5Sopenharmony_ciOpMemberName %StorageBuffer 0 "index"
296fd4e5da5Sopenharmony_ciOpMemberName %StorageBuffer 1 "red"
297fd4e5da5Sopenharmony_ciOpName %sbo "sbo"
298fd4e5da5Sopenharmony_ciOpName %images "images"
299fd4e5da5Sopenharmony_ciOpMemberDecorate %StorageBuffer 0 Offset 0
300fd4e5da5Sopenharmony_ciOpMemberDecorate %StorageBuffer 1 Offset 4
301fd4e5da5Sopenharmony_ciOpDecorate %gl_LocalInvocationIndex BuiltIn LocalInvocationIndex
302fd4e5da5Sopenharmony_ciOpDecorate %StorageBuffer BufferBlock
303fd4e5da5Sopenharmony_ciOpDecorate %sbo DescriptorSet 0
304fd4e5da5Sopenharmony_ciOpDecorate %sbo Binding 0
305fd4e5da5Sopenharmony_ciOpDecorate %images DescriptorSet 0
306fd4e5da5Sopenharmony_ciOpDecorate %images Binding 1
307fd4e5da5Sopenharmony_ciOpDecorate %images NonWritable
308fd4e5da5Sopenharmony_ci
309fd4e5da5Sopenharmony_ci; CHECK:     OpEntryPoint RayGenerationNV {{%\w+}} "RayGeneration" [[var:%\w+]]
310fd4e5da5Sopenharmony_ci; CHECK:     OpDecorate [[var]] BuiltIn SubgroupSize
311fd4e5da5Sopenharmony_ci; CHECK:     OpDecorate [[var]] Volatile
312fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate {{%\w+}} Volatile
313fd4e5da5Sopenharmony_ciOpDecorate %var BuiltIn SubgroupSize
314fd4e5da5Sopenharmony_ci
315fd4e5da5Sopenharmony_ci%void = OpTypeVoid
316fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
317fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
318fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
319fd4e5da5Sopenharmony_ci%StorageBuffer = OpTypeStruct %uint %float
320fd4e5da5Sopenharmony_ci%_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
321fd4e5da5Sopenharmony_ci%sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
322fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
323fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
324fd4e5da5Sopenharmony_ci%13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
325fd4e5da5Sopenharmony_ci%_runtimearr_13 = OpTypeRuntimeArray %13
326fd4e5da5Sopenharmony_ci%_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
327fd4e5da5Sopenharmony_ci%images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
328fd4e5da5Sopenharmony_ci%_ptr_Input_uint = OpTypePointer Input %uint
329fd4e5da5Sopenharmony_ci%var = OpVariable %_ptr_Input_uint Input
330fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
331fd4e5da5Sopenharmony_ci%_ptr_Uniform_uint = OpTypePointer Uniform %uint
332fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
333fd4e5da5Sopenharmony_ci%v2int = OpTypeVector %int 2
334fd4e5da5Sopenharmony_ci%25 = OpConstantComposite %v2int %int_0 %int_0
335fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
336fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
337fd4e5da5Sopenharmony_ci%uint_1 = OpConstant %uint 1
338fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float
339fd4e5da5Sopenharmony_ci%gl_LocalInvocationIndex = OpVariable %_ptr_Input_uint Input
340fd4e5da5Sopenharmony_ci%_ptr_Workgroup_uint = OpTypePointer Workgroup %uint
341fd4e5da5Sopenharmony_ci%shared = OpVariable %_ptr_Workgroup_uint Workgroup
342fd4e5da5Sopenharmony_ci
343fd4e5da5Sopenharmony_ci%RayGeneration = OpFunction %void None %3
344fd4e5da5Sopenharmony_ci%5 = OpLabel
345fd4e5da5Sopenharmony_ci%19 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
346fd4e5da5Sopenharmony_ci%20 = OpLoad %uint %var
347fd4e5da5Sopenharmony_ci%22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
348fd4e5da5Sopenharmony_ci%23 = OpLoad %13 %22
349fd4e5da5Sopenharmony_ci%27 = OpImageRead %v4float %23 %25
350fd4e5da5Sopenharmony_ci%29 = OpCompositeExtract %float %27 0
351fd4e5da5Sopenharmony_ci%31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
352fd4e5da5Sopenharmony_ciOpStore %31 %29
353fd4e5da5Sopenharmony_ciOpReturn
354fd4e5da5Sopenharmony_ciOpFunctionEnd
355fd4e5da5Sopenharmony_ci
356fd4e5da5Sopenharmony_ci%compute = OpFunction %void None %3
357fd4e5da5Sopenharmony_ci%66 = OpLabel
358fd4e5da5Sopenharmony_ci%62 = OpLoad %uint %gl_LocalInvocationIndex
359fd4e5da5Sopenharmony_ci%61 = OpAtomicIAdd %uint %shared %uint_1 %uint_0 %62
360fd4e5da5Sopenharmony_ciOpReturn
361fd4e5da5Sopenharmony_ciOpFunctionEnd
362fd4e5da5Sopenharmony_ci)";
363fd4e5da5Sopenharmony_ci
364fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<SpreadVolatileSemantics>(text, true);
365fd4e5da5Sopenharmony_ci}
366fd4e5da5Sopenharmony_ci
367fd4e5da5Sopenharmony_ciTEST_F(VolatileSpreadTest, VarUsedInMultipleEntryPoints) {
368fd4e5da5Sopenharmony_ci  const std::string text =
369fd4e5da5Sopenharmony_ci      R"(
370fd4e5da5Sopenharmony_ciOpCapability RuntimeDescriptorArray
371fd4e5da5Sopenharmony_ciOpCapability RayTracingKHR
372fd4e5da5Sopenharmony_ciOpCapability SubgroupBallotKHR
373fd4e5da5Sopenharmony_ciOpExtension "SPV_EXT_descriptor_indexing"
374fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_ray_tracing"
375fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_shader_ballot"
376fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
377fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
378fd4e5da5Sopenharmony_ciOpEntryPoint RayGenerationKHR %RayGeneration "RayGeneration" %var
379fd4e5da5Sopenharmony_ciOpEntryPoint ClosestHitKHR %ClosestHit "ClosestHit" %var
380fd4e5da5Sopenharmony_ciOpSource GLSL 460
381fd4e5da5Sopenharmony_ciOpSourceExtension "GL_EXT_nonuniform_qualifier"
382fd4e5da5Sopenharmony_ciOpSourceExtension "GL_KHR_ray_tracing"
383fd4e5da5Sopenharmony_ciOpName %RayGeneration "RayGeneration"
384fd4e5da5Sopenharmony_ciOpName %ClosestHit "ClosestHit"
385fd4e5da5Sopenharmony_ciOpName %StorageBuffer "StorageBuffer"
386fd4e5da5Sopenharmony_ciOpMemberName %StorageBuffer 0 "index"
387fd4e5da5Sopenharmony_ciOpMemberName %StorageBuffer 1 "red"
388fd4e5da5Sopenharmony_ciOpName %sbo "sbo"
389fd4e5da5Sopenharmony_ciOpName %images "images"
390fd4e5da5Sopenharmony_ciOpMemberDecorate %StorageBuffer 0 Offset 0
391fd4e5da5Sopenharmony_ciOpMemberDecorate %StorageBuffer 1 Offset 4
392fd4e5da5Sopenharmony_ciOpDecorate %gl_LocalInvocationIndex BuiltIn LocalInvocationIndex
393fd4e5da5Sopenharmony_ciOpDecorate %StorageBuffer BufferBlock
394fd4e5da5Sopenharmony_ciOpDecorate %sbo DescriptorSet 0
395fd4e5da5Sopenharmony_ciOpDecorate %sbo Binding 0
396fd4e5da5Sopenharmony_ciOpDecorate %images DescriptorSet 0
397fd4e5da5Sopenharmony_ciOpDecorate %images Binding 1
398fd4e5da5Sopenharmony_ciOpDecorate %images NonWritable
399fd4e5da5Sopenharmony_ci
400fd4e5da5Sopenharmony_ci; CHECK:     OpEntryPoint RayGenerationNV {{%\w+}} "RayGeneration" [[var:%\w+]]
401fd4e5da5Sopenharmony_ci; CHECK:     OpEntryPoint ClosestHitNV {{%\w+}} "ClosestHit" [[var]]
402fd4e5da5Sopenharmony_ci; CHECK:     OpDecorate [[var]] BuiltIn SubgroupSize
403fd4e5da5Sopenharmony_ci; CHECK:     OpDecorate [[var]] Volatile
404fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate {{%\w+}} Volatile
405fd4e5da5Sopenharmony_ciOpDecorate %var BuiltIn SubgroupSize
406fd4e5da5Sopenharmony_ci
407fd4e5da5Sopenharmony_ci%void = OpTypeVoid
408fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
409fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
410fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
411fd4e5da5Sopenharmony_ci%StorageBuffer = OpTypeStruct %uint %float
412fd4e5da5Sopenharmony_ci%_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
413fd4e5da5Sopenharmony_ci%sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
414fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
415fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
416fd4e5da5Sopenharmony_ci%13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
417fd4e5da5Sopenharmony_ci%_runtimearr_13 = OpTypeRuntimeArray %13
418fd4e5da5Sopenharmony_ci%_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
419fd4e5da5Sopenharmony_ci%images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
420fd4e5da5Sopenharmony_ci%_ptr_Input_uint = OpTypePointer Input %uint
421fd4e5da5Sopenharmony_ci%var = OpVariable %_ptr_Input_uint Input
422fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
423fd4e5da5Sopenharmony_ci%_ptr_Uniform_uint = OpTypePointer Uniform %uint
424fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
425fd4e5da5Sopenharmony_ci%v2int = OpTypeVector %int 2
426fd4e5da5Sopenharmony_ci%25 = OpConstantComposite %v2int %int_0 %int_0
427fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
428fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
429fd4e5da5Sopenharmony_ci%uint_1 = OpConstant %uint 1
430fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float
431fd4e5da5Sopenharmony_ci%gl_LocalInvocationIndex = OpVariable %_ptr_Input_uint Input
432fd4e5da5Sopenharmony_ci%_ptr_Workgroup_uint = OpTypePointer Workgroup %uint
433fd4e5da5Sopenharmony_ci%shared = OpVariable %_ptr_Workgroup_uint Workgroup
434fd4e5da5Sopenharmony_ci
435fd4e5da5Sopenharmony_ci%RayGeneration = OpFunction %void None %3
436fd4e5da5Sopenharmony_ci%5 = OpLabel
437fd4e5da5Sopenharmony_ci%19 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
438fd4e5da5Sopenharmony_ci%20 = OpLoad %uint %var
439fd4e5da5Sopenharmony_ci%22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
440fd4e5da5Sopenharmony_ci%23 = OpLoad %13 %22
441fd4e5da5Sopenharmony_ci%27 = OpImageRead %v4float %23 %25
442fd4e5da5Sopenharmony_ci%29 = OpCompositeExtract %float %27 0
443fd4e5da5Sopenharmony_ci%31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
444fd4e5da5Sopenharmony_ciOpStore %31 %29
445fd4e5da5Sopenharmony_ciOpReturn
446fd4e5da5Sopenharmony_ciOpFunctionEnd
447fd4e5da5Sopenharmony_ci
448fd4e5da5Sopenharmony_ci%ClosestHit = OpFunction %void None %3
449fd4e5da5Sopenharmony_ci%45 = OpLabel
450fd4e5da5Sopenharmony_ci%49 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
451fd4e5da5Sopenharmony_ci%40 = OpLoad %uint %var
452fd4e5da5Sopenharmony_ci%42 = OpAccessChain %_ptr_UniformConstant_13 %images %40
453fd4e5da5Sopenharmony_ci%43 = OpLoad %13 %42
454fd4e5da5Sopenharmony_ci%47 = OpImageRead %v4float %43 %25
455fd4e5da5Sopenharmony_ci%59 = OpCompositeExtract %float %47 0
456fd4e5da5Sopenharmony_ci%51 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
457fd4e5da5Sopenharmony_ciOpStore %51 %59
458fd4e5da5Sopenharmony_ciOpReturn
459fd4e5da5Sopenharmony_ciOpFunctionEnd
460fd4e5da5Sopenharmony_ci)";
461fd4e5da5Sopenharmony_ci
462fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<SpreadVolatileSemantics>(text, true);
463fd4e5da5Sopenharmony_ci}
464fd4e5da5Sopenharmony_ci
465fd4e5da5Sopenharmony_ciclass VolatileSpreadErrorTest : public PassTest<::testing::Test> {
466fd4e5da5Sopenharmony_ci public:
467fd4e5da5Sopenharmony_ci  VolatileSpreadErrorTest()
468fd4e5da5Sopenharmony_ci      : consumer_([this](spv_message_level_t level, const char*,
469fd4e5da5Sopenharmony_ci                         const spv_position_t& position, const char* message) {
470fd4e5da5Sopenharmony_ci          if (!error_message_.empty()) error_message_ += "\n";
471fd4e5da5Sopenharmony_ci          switch (level) {
472fd4e5da5Sopenharmony_ci            case SPV_MSG_FATAL:
473fd4e5da5Sopenharmony_ci            case SPV_MSG_INTERNAL_ERROR:
474fd4e5da5Sopenharmony_ci            case SPV_MSG_ERROR:
475fd4e5da5Sopenharmony_ci              error_message_ += "ERROR";
476fd4e5da5Sopenharmony_ci              break;
477fd4e5da5Sopenharmony_ci            case SPV_MSG_WARNING:
478fd4e5da5Sopenharmony_ci              error_message_ += "WARNING";
479fd4e5da5Sopenharmony_ci              break;
480fd4e5da5Sopenharmony_ci            case SPV_MSG_INFO:
481fd4e5da5Sopenharmony_ci              error_message_ += "INFO";
482fd4e5da5Sopenharmony_ci              break;
483fd4e5da5Sopenharmony_ci            case SPV_MSG_DEBUG:
484fd4e5da5Sopenharmony_ci              error_message_ += "DEBUG";
485fd4e5da5Sopenharmony_ci              break;
486fd4e5da5Sopenharmony_ci          }
487fd4e5da5Sopenharmony_ci          error_message_ +=
488fd4e5da5Sopenharmony_ci              ": " + std::to_string(position.index) + ": " + message;
489fd4e5da5Sopenharmony_ci        }) {}
490fd4e5da5Sopenharmony_ci
491fd4e5da5Sopenharmony_ci  Pass::Status RunPass(const std::string& text) {
492fd4e5da5Sopenharmony_ci    std::unique_ptr<IRContext> context_ =
493fd4e5da5Sopenharmony_ci        spvtools::BuildModule(SPV_ENV_UNIVERSAL_1_2, consumer_, text);
494fd4e5da5Sopenharmony_ci    if (!context_.get()) return Pass::Status::Failure;
495fd4e5da5Sopenharmony_ci
496fd4e5da5Sopenharmony_ci    PassManager manager;
497fd4e5da5Sopenharmony_ci    manager.SetMessageConsumer(consumer_);
498fd4e5da5Sopenharmony_ci    manager.AddPass<SpreadVolatileSemantics>();
499fd4e5da5Sopenharmony_ci
500fd4e5da5Sopenharmony_ci    return manager.Run(context_.get());
501fd4e5da5Sopenharmony_ci  }
502fd4e5da5Sopenharmony_ci
503fd4e5da5Sopenharmony_ci  std::string GetErrorMessage() const { return error_message_; }
504fd4e5da5Sopenharmony_ci
505fd4e5da5Sopenharmony_ci  void TearDown() override { error_message_.clear(); }
506fd4e5da5Sopenharmony_ci
507fd4e5da5Sopenharmony_ci private:
508fd4e5da5Sopenharmony_ci  spvtools::MessageConsumer consumer_;
509fd4e5da5Sopenharmony_ci  std::string error_message_;
510fd4e5da5Sopenharmony_ci};
511fd4e5da5Sopenharmony_ci
512fd4e5da5Sopenharmony_ciTEST_F(VolatileSpreadErrorTest, VarUsedInMultipleExecutionModelError) {
513fd4e5da5Sopenharmony_ci  const std::string text =
514fd4e5da5Sopenharmony_ci      R"(
515fd4e5da5Sopenharmony_ciOpCapability RuntimeDescriptorArray
516fd4e5da5Sopenharmony_ciOpCapability RayTracingKHR
517fd4e5da5Sopenharmony_ciOpCapability SubgroupBallotKHR
518fd4e5da5Sopenharmony_ciOpExtension "SPV_EXT_descriptor_indexing"
519fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_ray_tracing"
520fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_shader_ballot"
521fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
522fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
523fd4e5da5Sopenharmony_ciOpEntryPoint RayGenerationKHR %RayGeneration "RayGeneration" %var
524fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %compute "Compute" %gl_LocalInvocationIndex %var
525fd4e5da5Sopenharmony_ciOpExecutionMode %compute LocalSize 16 16 1
526fd4e5da5Sopenharmony_ciOpSource GLSL 460
527fd4e5da5Sopenharmony_ciOpSourceExtension "GL_EXT_nonuniform_qualifier"
528fd4e5da5Sopenharmony_ciOpSourceExtension "GL_KHR_ray_tracing"
529fd4e5da5Sopenharmony_ciOpName %RayGeneration "RayGeneration"
530fd4e5da5Sopenharmony_ciOpName %StorageBuffer "StorageBuffer"
531fd4e5da5Sopenharmony_ciOpMemberName %StorageBuffer 0 "index"
532fd4e5da5Sopenharmony_ciOpMemberName %StorageBuffer 1 "red"
533fd4e5da5Sopenharmony_ciOpName %sbo "sbo"
534fd4e5da5Sopenharmony_ciOpName %images "images"
535fd4e5da5Sopenharmony_ciOpMemberDecorate %StorageBuffer 0 Offset 0
536fd4e5da5Sopenharmony_ciOpMemberDecorate %StorageBuffer 1 Offset 4
537fd4e5da5Sopenharmony_ciOpDecorate %gl_LocalInvocationIndex BuiltIn LocalInvocationIndex
538fd4e5da5Sopenharmony_ciOpDecorate %StorageBuffer BufferBlock
539fd4e5da5Sopenharmony_ciOpDecorate %sbo DescriptorSet 0
540fd4e5da5Sopenharmony_ciOpDecorate %sbo Binding 0
541fd4e5da5Sopenharmony_ciOpDecorate %images DescriptorSet 0
542fd4e5da5Sopenharmony_ciOpDecorate %images Binding 1
543fd4e5da5Sopenharmony_ciOpDecorate %images NonWritable
544fd4e5da5Sopenharmony_ciOpDecorate %var BuiltIn SubgroupSize
545fd4e5da5Sopenharmony_ci%void = OpTypeVoid
546fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
547fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
548fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
549fd4e5da5Sopenharmony_ci%StorageBuffer = OpTypeStruct %uint %float
550fd4e5da5Sopenharmony_ci%_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
551fd4e5da5Sopenharmony_ci%sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
552fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
553fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
554fd4e5da5Sopenharmony_ci%13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
555fd4e5da5Sopenharmony_ci%_runtimearr_13 = OpTypeRuntimeArray %13
556fd4e5da5Sopenharmony_ci%_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
557fd4e5da5Sopenharmony_ci%images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
558fd4e5da5Sopenharmony_ci%_ptr_Input_uint = OpTypePointer Input %uint
559fd4e5da5Sopenharmony_ci%var = OpVariable %_ptr_Input_uint Input
560fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
561fd4e5da5Sopenharmony_ci%_ptr_Uniform_uint = OpTypePointer Uniform %uint
562fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
563fd4e5da5Sopenharmony_ci%v2int = OpTypeVector %int 2
564fd4e5da5Sopenharmony_ci%25 = OpConstantComposite %v2int %int_0 %int_0
565fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
566fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
567fd4e5da5Sopenharmony_ci%uint_1 = OpConstant %uint 1
568fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float
569fd4e5da5Sopenharmony_ci%gl_LocalInvocationIndex = OpVariable %_ptr_Input_uint Input
570fd4e5da5Sopenharmony_ci%_ptr_Workgroup_uint = OpTypePointer Workgroup %uint
571fd4e5da5Sopenharmony_ci%shared = OpVariable %_ptr_Workgroup_uint Workgroup
572fd4e5da5Sopenharmony_ci
573fd4e5da5Sopenharmony_ci%RayGeneration = OpFunction %void None %3
574fd4e5da5Sopenharmony_ci%5 = OpLabel
575fd4e5da5Sopenharmony_ci%19 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
576fd4e5da5Sopenharmony_ci%20 = OpLoad %uint %var
577fd4e5da5Sopenharmony_ci%22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
578fd4e5da5Sopenharmony_ci%23 = OpLoad %13 %22
579fd4e5da5Sopenharmony_ci%27 = OpImageRead %v4float %23 %25
580fd4e5da5Sopenharmony_ci%29 = OpCompositeExtract %float %27 0
581fd4e5da5Sopenharmony_ci%31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
582fd4e5da5Sopenharmony_ciOpStore %31 %29
583fd4e5da5Sopenharmony_ciOpReturn
584fd4e5da5Sopenharmony_ciOpFunctionEnd
585fd4e5da5Sopenharmony_ci
586fd4e5da5Sopenharmony_ci%compute = OpFunction %void None %3
587fd4e5da5Sopenharmony_ci%66 = OpLabel
588fd4e5da5Sopenharmony_ci%62 = OpLoad %uint %gl_LocalInvocationIndex
589fd4e5da5Sopenharmony_ci%63 = OpLoad %uint %var
590fd4e5da5Sopenharmony_ci%64 = OpIAdd %uint %62 %63
591fd4e5da5Sopenharmony_ci%61 = OpAtomicIAdd %uint %shared %uint_1 %uint_0 %64
592fd4e5da5Sopenharmony_ciOpReturn
593fd4e5da5Sopenharmony_ciOpFunctionEnd
594fd4e5da5Sopenharmony_ci)";
595fd4e5da5Sopenharmony_ci
596fd4e5da5Sopenharmony_ci  EXPECT_EQ(RunPass(text), Pass::Status::Failure);
597fd4e5da5Sopenharmony_ci  const char expected_error[] =
598fd4e5da5Sopenharmony_ci      "ERROR: 0: Variable is a target for Volatile semantics for an entry "
599fd4e5da5Sopenharmony_ci      "point, but it is not for another entry point";
600fd4e5da5Sopenharmony_ci  EXPECT_STREQ(GetErrorMessage().substr(0, sizeof(expected_error) - 1).c_str(),
601fd4e5da5Sopenharmony_ci               expected_error);
602fd4e5da5Sopenharmony_ci}
603fd4e5da5Sopenharmony_ci
604fd4e5da5Sopenharmony_ciTEST_F(VolatileSpreadErrorTest,
605fd4e5da5Sopenharmony_ci       VarUsedInMultipleReverseOrderExecutionModelError) {
606fd4e5da5Sopenharmony_ci  const std::string text =
607fd4e5da5Sopenharmony_ci      R"(
608fd4e5da5Sopenharmony_ciOpCapability RuntimeDescriptorArray
609fd4e5da5Sopenharmony_ciOpCapability RayTracingKHR
610fd4e5da5Sopenharmony_ciOpCapability SubgroupBallotKHR
611fd4e5da5Sopenharmony_ciOpExtension "SPV_EXT_descriptor_indexing"
612fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_ray_tracing"
613fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_shader_ballot"
614fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
615fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
616fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %compute "Compute" %gl_LocalInvocationIndex %var
617fd4e5da5Sopenharmony_ciOpEntryPoint RayGenerationKHR %RayGeneration "RayGeneration" %var
618fd4e5da5Sopenharmony_ciOpExecutionMode %compute LocalSize 16 16 1
619fd4e5da5Sopenharmony_ciOpSource GLSL 460
620fd4e5da5Sopenharmony_ciOpSourceExtension "GL_EXT_nonuniform_qualifier"
621fd4e5da5Sopenharmony_ciOpSourceExtension "GL_KHR_ray_tracing"
622fd4e5da5Sopenharmony_ciOpName %RayGeneration "RayGeneration"
623fd4e5da5Sopenharmony_ciOpName %StorageBuffer "StorageBuffer"
624fd4e5da5Sopenharmony_ciOpMemberName %StorageBuffer 0 "index"
625fd4e5da5Sopenharmony_ciOpMemberName %StorageBuffer 1 "red"
626fd4e5da5Sopenharmony_ciOpName %sbo "sbo"
627fd4e5da5Sopenharmony_ciOpName %images "images"
628fd4e5da5Sopenharmony_ciOpMemberDecorate %StorageBuffer 0 Offset 0
629fd4e5da5Sopenharmony_ciOpMemberDecorate %StorageBuffer 1 Offset 4
630fd4e5da5Sopenharmony_ciOpDecorate %gl_LocalInvocationIndex BuiltIn LocalInvocationIndex
631fd4e5da5Sopenharmony_ciOpDecorate %StorageBuffer BufferBlock
632fd4e5da5Sopenharmony_ciOpDecorate %sbo DescriptorSet 0
633fd4e5da5Sopenharmony_ciOpDecorate %sbo Binding 0
634fd4e5da5Sopenharmony_ciOpDecorate %images DescriptorSet 0
635fd4e5da5Sopenharmony_ciOpDecorate %images Binding 1
636fd4e5da5Sopenharmony_ciOpDecorate %images NonWritable
637fd4e5da5Sopenharmony_ciOpDecorate %var BuiltIn SubgroupSize
638fd4e5da5Sopenharmony_ci%void = OpTypeVoid
639fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
640fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
641fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
642fd4e5da5Sopenharmony_ci%StorageBuffer = OpTypeStruct %uint %float
643fd4e5da5Sopenharmony_ci%_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
644fd4e5da5Sopenharmony_ci%sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
645fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
646fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
647fd4e5da5Sopenharmony_ci%13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
648fd4e5da5Sopenharmony_ci%_runtimearr_13 = OpTypeRuntimeArray %13
649fd4e5da5Sopenharmony_ci%_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
650fd4e5da5Sopenharmony_ci%images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
651fd4e5da5Sopenharmony_ci%_ptr_Input_uint = OpTypePointer Input %uint
652fd4e5da5Sopenharmony_ci%var = OpVariable %_ptr_Input_uint Input
653fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
654fd4e5da5Sopenharmony_ci%_ptr_Uniform_uint = OpTypePointer Uniform %uint
655fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
656fd4e5da5Sopenharmony_ci%v2int = OpTypeVector %int 2
657fd4e5da5Sopenharmony_ci%25 = OpConstantComposite %v2int %int_0 %int_0
658fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
659fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
660fd4e5da5Sopenharmony_ci%uint_1 = OpConstant %uint 1
661fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float
662fd4e5da5Sopenharmony_ci%gl_LocalInvocationIndex = OpVariable %_ptr_Input_uint Input
663fd4e5da5Sopenharmony_ci%_ptr_Workgroup_uint = OpTypePointer Workgroup %uint
664fd4e5da5Sopenharmony_ci%shared = OpVariable %_ptr_Workgroup_uint Workgroup
665fd4e5da5Sopenharmony_ci
666fd4e5da5Sopenharmony_ci%RayGeneration = OpFunction %void None %3
667fd4e5da5Sopenharmony_ci%5 = OpLabel
668fd4e5da5Sopenharmony_ci%19 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
669fd4e5da5Sopenharmony_ci%20 = OpLoad %uint %var
670fd4e5da5Sopenharmony_ci%22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
671fd4e5da5Sopenharmony_ci%23 = OpLoad %13 %22
672fd4e5da5Sopenharmony_ci%27 = OpImageRead %v4float %23 %25
673fd4e5da5Sopenharmony_ci%29 = OpCompositeExtract %float %27 0
674fd4e5da5Sopenharmony_ci%31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
675fd4e5da5Sopenharmony_ciOpStore %31 %29
676fd4e5da5Sopenharmony_ciOpReturn
677fd4e5da5Sopenharmony_ciOpFunctionEnd
678fd4e5da5Sopenharmony_ci
679fd4e5da5Sopenharmony_ci%compute = OpFunction %void None %3
680fd4e5da5Sopenharmony_ci%66 = OpLabel
681fd4e5da5Sopenharmony_ci%62 = OpLoad %uint %gl_LocalInvocationIndex
682fd4e5da5Sopenharmony_ci%63 = OpLoad %uint %var
683fd4e5da5Sopenharmony_ci%64 = OpIAdd %uint %62 %63
684fd4e5da5Sopenharmony_ci%61 = OpAtomicIAdd %uint %shared %uint_1 %uint_0 %64
685fd4e5da5Sopenharmony_ciOpReturn
686fd4e5da5Sopenharmony_ciOpFunctionEnd
687fd4e5da5Sopenharmony_ci)";
688fd4e5da5Sopenharmony_ci
689fd4e5da5Sopenharmony_ci  EXPECT_EQ(RunPass(text), Pass::Status::Failure);
690fd4e5da5Sopenharmony_ci  const char expected_error[] =
691fd4e5da5Sopenharmony_ci      "ERROR: 0: Variable is a target for Volatile semantics for an entry "
692fd4e5da5Sopenharmony_ci      "point, but it is not for another entry point";
693fd4e5da5Sopenharmony_ci  EXPECT_STREQ(GetErrorMessage().substr(0, sizeof(expected_error) - 1).c_str(),
694fd4e5da5Sopenharmony_ci               expected_error);
695fd4e5da5Sopenharmony_ci}
696fd4e5da5Sopenharmony_ci
697fd4e5da5Sopenharmony_ciTEST_F(VolatileSpreadErrorTest, FunctionNotInlined) {
698fd4e5da5Sopenharmony_ci  const std::string text =
699fd4e5da5Sopenharmony_ci      R"(
700fd4e5da5Sopenharmony_ciOpCapability RuntimeDescriptorArray
701fd4e5da5Sopenharmony_ciOpCapability RayTracingKHR
702fd4e5da5Sopenharmony_ciOpCapability SubgroupBallotKHR
703fd4e5da5Sopenharmony_ciOpExtension "SPV_EXT_descriptor_indexing"
704fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_ray_tracing"
705fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_shader_ballot"
706fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
707fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
708fd4e5da5Sopenharmony_ciOpEntryPoint RayGenerationKHR %RayGeneration "RayGeneration" %var
709fd4e5da5Sopenharmony_ciOpEntryPoint ClosestHitKHR %ClosestHit "ClosestHit" %var
710fd4e5da5Sopenharmony_ciOpSource GLSL 460
711fd4e5da5Sopenharmony_ciOpSourceExtension "GL_EXT_nonuniform_qualifier"
712fd4e5da5Sopenharmony_ciOpSourceExtension "GL_KHR_ray_tracing"
713fd4e5da5Sopenharmony_ciOpName %RayGeneration "RayGeneration"
714fd4e5da5Sopenharmony_ciOpName %ClosestHit "ClosestHit"
715fd4e5da5Sopenharmony_ciOpName %StorageBuffer "StorageBuffer"
716fd4e5da5Sopenharmony_ciOpMemberName %StorageBuffer 0 "index"
717fd4e5da5Sopenharmony_ciOpMemberName %StorageBuffer 1 "red"
718fd4e5da5Sopenharmony_ciOpName %sbo "sbo"
719fd4e5da5Sopenharmony_ciOpName %images "images"
720fd4e5da5Sopenharmony_ciOpMemberDecorate %StorageBuffer 0 Offset 0
721fd4e5da5Sopenharmony_ciOpMemberDecorate %StorageBuffer 1 Offset 4
722fd4e5da5Sopenharmony_ciOpDecorate %gl_LocalInvocationIndex BuiltIn LocalInvocationIndex
723fd4e5da5Sopenharmony_ciOpDecorate %StorageBuffer BufferBlock
724fd4e5da5Sopenharmony_ciOpDecorate %sbo DescriptorSet 0
725fd4e5da5Sopenharmony_ciOpDecorate %sbo Binding 0
726fd4e5da5Sopenharmony_ciOpDecorate %images DescriptorSet 0
727fd4e5da5Sopenharmony_ciOpDecorate %images Binding 1
728fd4e5da5Sopenharmony_ciOpDecorate %images NonWritable
729fd4e5da5Sopenharmony_ciOpDecorate %var BuiltIn SubgroupSize
730fd4e5da5Sopenharmony_ci%void = OpTypeVoid
731fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
732fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
733fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
734fd4e5da5Sopenharmony_ci%StorageBuffer = OpTypeStruct %uint %float
735fd4e5da5Sopenharmony_ci%_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
736fd4e5da5Sopenharmony_ci%sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
737fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
738fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
739fd4e5da5Sopenharmony_ci%13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
740fd4e5da5Sopenharmony_ci%_runtimearr_13 = OpTypeRuntimeArray %13
741fd4e5da5Sopenharmony_ci%_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
742fd4e5da5Sopenharmony_ci%images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
743fd4e5da5Sopenharmony_ci%_ptr_Input_uint = OpTypePointer Input %uint
744fd4e5da5Sopenharmony_ci%var = OpVariable %_ptr_Input_uint Input
745fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
746fd4e5da5Sopenharmony_ci%_ptr_Uniform_uint = OpTypePointer Uniform %uint
747fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
748fd4e5da5Sopenharmony_ci%v2int = OpTypeVector %int 2
749fd4e5da5Sopenharmony_ci%25 = OpConstantComposite %v2int %int_0 %int_0
750fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
751fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
752fd4e5da5Sopenharmony_ci%uint_1 = OpConstant %uint 1
753fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float
754fd4e5da5Sopenharmony_ci%gl_LocalInvocationIndex = OpVariable %_ptr_Input_uint Input
755fd4e5da5Sopenharmony_ci%_ptr_Workgroup_uint = OpTypePointer Workgroup %uint
756fd4e5da5Sopenharmony_ci%shared = OpVariable %_ptr_Workgroup_uint Workgroup
757fd4e5da5Sopenharmony_ci
758fd4e5da5Sopenharmony_ci%RayGeneration = OpFunction %void None %3
759fd4e5da5Sopenharmony_ci%5 = OpLabel
760fd4e5da5Sopenharmony_ci%19 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
761fd4e5da5Sopenharmony_ci%20 = OpLoad %uint %19
762fd4e5da5Sopenharmony_ci%22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
763fd4e5da5Sopenharmony_ci%23 = OpLoad %13 %22
764fd4e5da5Sopenharmony_ci%27 = OpImageRead %v4float %23 %25
765fd4e5da5Sopenharmony_ci%29 = OpCompositeExtract %float %27 0
766fd4e5da5Sopenharmony_ci%31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
767fd4e5da5Sopenharmony_ciOpStore %31 %29
768fd4e5da5Sopenharmony_ciOpReturn
769fd4e5da5Sopenharmony_ciOpFunctionEnd
770fd4e5da5Sopenharmony_ci
771fd4e5da5Sopenharmony_ci%NotInlined = OpFunction %void None %3
772fd4e5da5Sopenharmony_ci%32 = OpLabel
773fd4e5da5Sopenharmony_ciOpReturn
774fd4e5da5Sopenharmony_ciOpFunctionEnd
775fd4e5da5Sopenharmony_ci
776fd4e5da5Sopenharmony_ci%ClosestHit = OpFunction %void None %3
777fd4e5da5Sopenharmony_ci%45 = OpLabel
778fd4e5da5Sopenharmony_ci%49 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
779fd4e5da5Sopenharmony_ci%40 = OpLoad %uint %49
780fd4e5da5Sopenharmony_ci%42 = OpAccessChain %_ptr_UniformConstant_13 %images %40
781fd4e5da5Sopenharmony_ci%43 = OpLoad %13 %42
782fd4e5da5Sopenharmony_ci%47 = OpImageRead %v4float %43 %25
783fd4e5da5Sopenharmony_ci%59 = OpCompositeExtract %float %47 0
784fd4e5da5Sopenharmony_ci%51 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
785fd4e5da5Sopenharmony_ciOpStore %51 %59
786fd4e5da5Sopenharmony_ciOpReturn
787fd4e5da5Sopenharmony_ciOpFunctionEnd
788fd4e5da5Sopenharmony_ci)";
789fd4e5da5Sopenharmony_ci
790fd4e5da5Sopenharmony_ci  EXPECT_EQ(RunPass(text), Pass::Status::SuccessWithoutChange);
791fd4e5da5Sopenharmony_ci}
792fd4e5da5Sopenharmony_ci
793fd4e5da5Sopenharmony_ciTEST_F(VolatileSpreadErrorTest, VarNotUsedInEntryPointForVolatile) {
794fd4e5da5Sopenharmony_ci  const std::string text =
795fd4e5da5Sopenharmony_ci      R"(
796fd4e5da5Sopenharmony_ciOpCapability RuntimeDescriptorArray
797fd4e5da5Sopenharmony_ciOpCapability RayTracingKHR
798fd4e5da5Sopenharmony_ciOpCapability SubgroupBallotKHR
799fd4e5da5Sopenharmony_ciOpExtension "SPV_EXT_descriptor_indexing"
800fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_ray_tracing"
801fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_shader_ballot"
802fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
803fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
804fd4e5da5Sopenharmony_ciOpEntryPoint RayGenerationKHR %RayGeneration "RayGeneration" %var
805fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %compute "Compute" %gl_LocalInvocationIndex %var
806fd4e5da5Sopenharmony_ciOpExecutionMode %compute LocalSize 16 16 1
807fd4e5da5Sopenharmony_ciOpSource GLSL 460
808fd4e5da5Sopenharmony_ciOpSourceExtension "GL_EXT_nonuniform_qualifier"
809fd4e5da5Sopenharmony_ciOpSourceExtension "GL_KHR_ray_tracing"
810fd4e5da5Sopenharmony_ciOpName %RayGeneration "RayGeneration"
811fd4e5da5Sopenharmony_ciOpName %StorageBuffer "StorageBuffer"
812fd4e5da5Sopenharmony_ciOpMemberName %StorageBuffer 0 "index"
813fd4e5da5Sopenharmony_ciOpMemberName %StorageBuffer 1 "red"
814fd4e5da5Sopenharmony_ciOpName %sbo "sbo"
815fd4e5da5Sopenharmony_ciOpName %images "images"
816fd4e5da5Sopenharmony_ciOpMemberDecorate %StorageBuffer 0 Offset 0
817fd4e5da5Sopenharmony_ciOpMemberDecorate %StorageBuffer 1 Offset 4
818fd4e5da5Sopenharmony_ciOpDecorate %gl_LocalInvocationIndex BuiltIn LocalInvocationIndex
819fd4e5da5Sopenharmony_ciOpDecorate %StorageBuffer BufferBlock
820fd4e5da5Sopenharmony_ciOpDecorate %sbo DescriptorSet 0
821fd4e5da5Sopenharmony_ciOpDecorate %sbo Binding 0
822fd4e5da5Sopenharmony_ciOpDecorate %images DescriptorSet 0
823fd4e5da5Sopenharmony_ciOpDecorate %images Binding 1
824fd4e5da5Sopenharmony_ciOpDecorate %images NonWritable
825fd4e5da5Sopenharmony_ci
826fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate {{%\w+}} Volatile
827fd4e5da5Sopenharmony_ci
828fd4e5da5Sopenharmony_ciOpDecorate %var BuiltIn SubgroupSize
829fd4e5da5Sopenharmony_ci%void = OpTypeVoid
830fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
831fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
832fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
833fd4e5da5Sopenharmony_ci%StorageBuffer = OpTypeStruct %uint %float
834fd4e5da5Sopenharmony_ci%_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
835fd4e5da5Sopenharmony_ci%sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
836fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
837fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
838fd4e5da5Sopenharmony_ci%13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
839fd4e5da5Sopenharmony_ci%_runtimearr_13 = OpTypeRuntimeArray %13
840fd4e5da5Sopenharmony_ci%_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
841fd4e5da5Sopenharmony_ci%images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
842fd4e5da5Sopenharmony_ci%_ptr_Input_uint = OpTypePointer Input %uint
843fd4e5da5Sopenharmony_ci%var = OpVariable %_ptr_Input_uint Input
844fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
845fd4e5da5Sopenharmony_ci%_ptr_Uniform_uint = OpTypePointer Uniform %uint
846fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
847fd4e5da5Sopenharmony_ci%v2int = OpTypeVector %int 2
848fd4e5da5Sopenharmony_ci%25 = OpConstantComposite %v2int %int_0 %int_0
849fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
850fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
851fd4e5da5Sopenharmony_ci%uint_1 = OpConstant %uint 1
852fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float
853fd4e5da5Sopenharmony_ci%gl_LocalInvocationIndex = OpVariable %_ptr_Input_uint Input
854fd4e5da5Sopenharmony_ci%_ptr_Workgroup_uint = OpTypePointer Workgroup %uint
855fd4e5da5Sopenharmony_ci%shared = OpVariable %_ptr_Workgroup_uint Workgroup
856fd4e5da5Sopenharmony_ci
857fd4e5da5Sopenharmony_ci%RayGeneration = OpFunction %void None %3
858fd4e5da5Sopenharmony_ci%5 = OpLabel
859fd4e5da5Sopenharmony_ci%19 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
860fd4e5da5Sopenharmony_ci%20 = OpLoad %uint %19
861fd4e5da5Sopenharmony_ci%22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
862fd4e5da5Sopenharmony_ci%23 = OpLoad %13 %22
863fd4e5da5Sopenharmony_ci%27 = OpImageRead %v4float %23 %25
864fd4e5da5Sopenharmony_ci%29 = OpCompositeExtract %float %27 0
865fd4e5da5Sopenharmony_ci%31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
866fd4e5da5Sopenharmony_ciOpStore %31 %29
867fd4e5da5Sopenharmony_ciOpReturn
868fd4e5da5Sopenharmony_ciOpFunctionEnd
869fd4e5da5Sopenharmony_ci
870fd4e5da5Sopenharmony_ci%compute = OpFunction %void None %3
871fd4e5da5Sopenharmony_ci%66 = OpLabel
872fd4e5da5Sopenharmony_ci%62 = OpLoad %uint %gl_LocalInvocationIndex
873fd4e5da5Sopenharmony_ci%63 = OpLoad %uint %var
874fd4e5da5Sopenharmony_ci%64 = OpIAdd %uint %62 %63
875fd4e5da5Sopenharmony_ci%61 = OpAtomicIAdd %uint %shared %uint_1 %uint_0 %64
876fd4e5da5Sopenharmony_ciOpReturn
877fd4e5da5Sopenharmony_ciOpFunctionEnd
878fd4e5da5Sopenharmony_ci)";
879fd4e5da5Sopenharmony_ci
880fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<SpreadVolatileSemantics>(text, true);
881fd4e5da5Sopenharmony_ci}
882fd4e5da5Sopenharmony_ci
883fd4e5da5Sopenharmony_ciTEST_F(VolatileSpreadTest, RecursivelySpreadVolatile) {
884fd4e5da5Sopenharmony_ci  const std::string text =
885fd4e5da5Sopenharmony_ci      R"(
886fd4e5da5Sopenharmony_ciOpCapability RuntimeDescriptorArray
887fd4e5da5Sopenharmony_ciOpCapability RayTracingKHR
888fd4e5da5Sopenharmony_ciOpCapability SubgroupBallotKHR
889fd4e5da5Sopenharmony_ciOpCapability VulkanMemoryModel
890fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_vulkan_memory_model"
891fd4e5da5Sopenharmony_ciOpExtension "SPV_EXT_descriptor_indexing"
892fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_ray_tracing"
893fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_shader_ballot"
894fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
895fd4e5da5Sopenharmony_ciOpMemoryModel Logical Vulkan
896fd4e5da5Sopenharmony_ciOpEntryPoint RayGenerationKHR %RayGeneration "RayGeneration" %var0 %var1
897fd4e5da5Sopenharmony_ciOpSource GLSL 460
898fd4e5da5Sopenharmony_ciOpSourceExtension "GL_EXT_nonuniform_qualifier"
899fd4e5da5Sopenharmony_ciOpSourceExtension "GL_KHR_ray_tracing"
900fd4e5da5Sopenharmony_ciOpName %RayGeneration "RayGeneration"
901fd4e5da5Sopenharmony_ciOpName %StorageBuffer "StorageBuffer"
902fd4e5da5Sopenharmony_ciOpMemberName %StorageBuffer 0 "index"
903fd4e5da5Sopenharmony_ciOpMemberName %StorageBuffer 1 "red"
904fd4e5da5Sopenharmony_ciOpName %sbo "sbo"
905fd4e5da5Sopenharmony_ciOpName %images "images"
906fd4e5da5Sopenharmony_ciOpMemberDecorate %StorageBuffer 0 Offset 0
907fd4e5da5Sopenharmony_ciOpMemberDecorate %StorageBuffer 1 Offset 4
908fd4e5da5Sopenharmony_ciOpDecorate %StorageBuffer BufferBlock
909fd4e5da5Sopenharmony_ciOpDecorate %sbo DescriptorSet 0
910fd4e5da5Sopenharmony_ciOpDecorate %sbo Binding 0
911fd4e5da5Sopenharmony_ciOpDecorate %images DescriptorSet 0
912fd4e5da5Sopenharmony_ciOpDecorate %images Binding 1
913fd4e5da5Sopenharmony_ciOpDecorate %images NonWritable
914fd4e5da5Sopenharmony_ci
915fd4e5da5Sopenharmony_ci; CHECK: OpDecorate [[var0:%\w+]] BuiltIn SubgroupEqMask
916fd4e5da5Sopenharmony_ci; CHECK: OpDecorate [[var1:%\w+]] BuiltIn SubgroupGeMask
917fd4e5da5Sopenharmony_ciOpDecorate %var0 BuiltIn SubgroupEqMask
918fd4e5da5Sopenharmony_ciOpDecorate %var1 BuiltIn SubgroupGeMask
919fd4e5da5Sopenharmony_ci
920fd4e5da5Sopenharmony_ci%void = OpTypeVoid
921fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
922fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
923fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
924fd4e5da5Sopenharmony_ci%StorageBuffer = OpTypeStruct %uint %float
925fd4e5da5Sopenharmony_ci%_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
926fd4e5da5Sopenharmony_ci%sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
927fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
928fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
929fd4e5da5Sopenharmony_ci%13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
930fd4e5da5Sopenharmony_ci%_runtimearr_13 = OpTypeRuntimeArray %13
931fd4e5da5Sopenharmony_ci%_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
932fd4e5da5Sopenharmony_ci%images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
933fd4e5da5Sopenharmony_ci%v4uint = OpTypeVector %uint 4
934fd4e5da5Sopenharmony_ci%_ptr_Input_v4uint = OpTypePointer Input %v4uint
935fd4e5da5Sopenharmony_ci%_ptr_Input_uint = OpTypePointer Input %uint
936fd4e5da5Sopenharmony_ci%var0 = OpVariable %_ptr_Input_v4uint Input
937fd4e5da5Sopenharmony_ci%var1 = OpVariable %_ptr_Input_v4uint Input
938fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
939fd4e5da5Sopenharmony_ci%_ptr_Uniform_uint = OpTypePointer Uniform %uint
940fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
941fd4e5da5Sopenharmony_ci%v2int = OpTypeVector %int 2
942fd4e5da5Sopenharmony_ci%25 = OpConstantComposite %v2int %int_0 %int_0
943fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
944fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
945fd4e5da5Sopenharmony_ci%uint_1 = OpConstant %uint 1
946fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float
947fd4e5da5Sopenharmony_ci
948fd4e5da5Sopenharmony_ci%RayGeneration = OpFunction %void None %3
949fd4e5da5Sopenharmony_ci%5 = OpLabel
950fd4e5da5Sopenharmony_ci
951fd4e5da5Sopenharmony_ci; CHECK: [[ptr0:%\w+]] = OpAccessChain %_ptr_Input_uint [[var0]] %int_0
952fd4e5da5Sopenharmony_ci; CHECK: OpLoad {{%\w+}} [[ptr0]] Volatile
953fd4e5da5Sopenharmony_ci%19 = OpAccessChain %_ptr_Input_uint %var0 %int_0
954fd4e5da5Sopenharmony_ci%20 = OpLoad %uint %19
955fd4e5da5Sopenharmony_ci
956fd4e5da5Sopenharmony_ci%22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
957fd4e5da5Sopenharmony_ci%23 = OpLoad %13 %22
958fd4e5da5Sopenharmony_ci%27 = OpImageRead %v4float %23 %25
959fd4e5da5Sopenharmony_ci%29 = OpCompositeExtract %float %27 0
960fd4e5da5Sopenharmony_ci%31 = OpAccessChain %_ptr_Uniform_float %sbo %uint_1
961fd4e5da5Sopenharmony_ci
962fd4e5da5Sopenharmony_ci; CHECK: OpLoad {{%\w+}} [[ptr0]] Volatile
963fd4e5da5Sopenharmony_ci%24 = OpLoad %uint %19
964fd4e5da5Sopenharmony_ci
965fd4e5da5Sopenharmony_ci; CHECK: [[var2:%\w+]] = OpCopyObject %_ptr_Input_v4uint [[var0]]
966fd4e5da5Sopenharmony_ci; CHECK: [[ptr2:%\w+]] = OpAccessChain %_ptr_Input_uint [[var2]] %int_1
967fd4e5da5Sopenharmony_ci; CHECK: OpLoad {{%\w+}} [[ptr2]] Volatile
968fd4e5da5Sopenharmony_ci%18 = OpCopyObject %_ptr_Input_v4uint %var0
969fd4e5da5Sopenharmony_ci%21 = OpAccessChain %_ptr_Input_uint %18 %int_1
970fd4e5da5Sopenharmony_ci%26 = OpLoad %uint %21
971fd4e5da5Sopenharmony_ci
972fd4e5da5Sopenharmony_ci%28 = OpIAdd %uint %24 %26
973fd4e5da5Sopenharmony_ci%30 = OpConvertUToF %float %28
974fd4e5da5Sopenharmony_ci
975fd4e5da5Sopenharmony_ci; CHECK: [[ptr1:%\w+]] = OpAccessChain %_ptr_Input_uint [[var1]] %int_1
976fd4e5da5Sopenharmony_ci; CHECK: OpLoad {{%\w+}} [[ptr1]] Volatile
977fd4e5da5Sopenharmony_ci%32 = OpAccessChain %_ptr_Input_uint %var1 %int_1
978fd4e5da5Sopenharmony_ci%33 = OpLoad %uint %32
979fd4e5da5Sopenharmony_ci
980fd4e5da5Sopenharmony_ci%34 = OpConvertUToF %float %33
981fd4e5da5Sopenharmony_ci%35 = OpFAdd %float %34 %30
982fd4e5da5Sopenharmony_ci%36 = OpFAdd %float %35 %29
983fd4e5da5Sopenharmony_ciOpStore %31 %36
984fd4e5da5Sopenharmony_ciOpReturn
985fd4e5da5Sopenharmony_ciOpFunctionEnd
986fd4e5da5Sopenharmony_ci)";
987fd4e5da5Sopenharmony_ci
988fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<SpreadVolatileSemantics>(text, true);
989fd4e5da5Sopenharmony_ci}
990fd4e5da5Sopenharmony_ci
991fd4e5da5Sopenharmony_ciTEST_F(VolatileSpreadTest, SpreadVolatileOnlyForTargetEntryPoints) {
992fd4e5da5Sopenharmony_ci  const std::string text =
993fd4e5da5Sopenharmony_ci      R"(
994fd4e5da5Sopenharmony_ciOpCapability RuntimeDescriptorArray
995fd4e5da5Sopenharmony_ciOpCapability RayTracingKHR
996fd4e5da5Sopenharmony_ciOpCapability SubgroupBallotKHR
997fd4e5da5Sopenharmony_ciOpCapability VulkanMemoryModel
998fd4e5da5Sopenharmony_ciOpCapability VulkanMemoryModelDeviceScopeKHR
999fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_vulkan_memory_model"
1000fd4e5da5Sopenharmony_ciOpExtension "SPV_EXT_descriptor_indexing"
1001fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_ray_tracing"
1002fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_shader_ballot"
1003fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
1004fd4e5da5Sopenharmony_ciOpMemoryModel Logical Vulkan
1005fd4e5da5Sopenharmony_ciOpEntryPoint RayGenerationKHR %RayGeneration "RayGeneration" %var0 %var1
1006fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %compute "Compute" %var0 %var1
1007fd4e5da5Sopenharmony_ciOpExecutionMode %compute LocalSize 16 16 1
1008fd4e5da5Sopenharmony_ciOpSource GLSL 460
1009fd4e5da5Sopenharmony_ciOpSourceExtension "GL_EXT_nonuniform_qualifier"
1010fd4e5da5Sopenharmony_ciOpSourceExtension "GL_KHR_ray_tracing"
1011fd4e5da5Sopenharmony_ciOpName %RayGeneration "RayGeneration"
1012fd4e5da5Sopenharmony_ciOpName %StorageBuffer "StorageBuffer"
1013fd4e5da5Sopenharmony_ciOpMemberName %StorageBuffer 0 "index"
1014fd4e5da5Sopenharmony_ciOpMemberName %StorageBuffer 1 "red"
1015fd4e5da5Sopenharmony_ciOpName %sbo "sbo"
1016fd4e5da5Sopenharmony_ciOpName %images "images"
1017fd4e5da5Sopenharmony_ciOpMemberDecorate %StorageBuffer 0 Offset 0
1018fd4e5da5Sopenharmony_ciOpMemberDecorate %StorageBuffer 1 Offset 4
1019fd4e5da5Sopenharmony_ciOpDecorate %StorageBuffer BufferBlock
1020fd4e5da5Sopenharmony_ciOpDecorate %sbo DescriptorSet 0
1021fd4e5da5Sopenharmony_ciOpDecorate %sbo Binding 0
1022fd4e5da5Sopenharmony_ciOpDecorate %images DescriptorSet 0
1023fd4e5da5Sopenharmony_ciOpDecorate %images Binding 1
1024fd4e5da5Sopenharmony_ciOpDecorate %images NonWritable
1025fd4e5da5Sopenharmony_ci
1026fd4e5da5Sopenharmony_ci; CHECK: OpDecorate [[var0:%\w+]] BuiltIn SubgroupEqMask
1027fd4e5da5Sopenharmony_ci; CHECK: OpDecorate [[var1:%\w+]] BuiltIn SubgroupGeMask
1028fd4e5da5Sopenharmony_ciOpDecorate %var0 BuiltIn SubgroupEqMask
1029fd4e5da5Sopenharmony_ciOpDecorate %var1 BuiltIn SubgroupGeMask
1030fd4e5da5Sopenharmony_ci
1031fd4e5da5Sopenharmony_ci%void = OpTypeVoid
1032fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
1033fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
1034fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
1035fd4e5da5Sopenharmony_ci%StorageBuffer = OpTypeStruct %uint %float
1036fd4e5da5Sopenharmony_ci%_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
1037fd4e5da5Sopenharmony_ci%sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
1038fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
1039fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
1040fd4e5da5Sopenharmony_ci%13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
1041fd4e5da5Sopenharmony_ci%_runtimearr_13 = OpTypeRuntimeArray %13
1042fd4e5da5Sopenharmony_ci%_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
1043fd4e5da5Sopenharmony_ci%images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
1044fd4e5da5Sopenharmony_ci%v4uint = OpTypeVector %uint 4
1045fd4e5da5Sopenharmony_ci%_ptr_Input_v4uint = OpTypePointer Input %v4uint
1046fd4e5da5Sopenharmony_ci%_ptr_Input_uint = OpTypePointer Input %uint
1047fd4e5da5Sopenharmony_ci%var0 = OpVariable %_ptr_Input_v4uint Input
1048fd4e5da5Sopenharmony_ci%var1 = OpVariable %_ptr_Input_v4uint Input
1049fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
1050fd4e5da5Sopenharmony_ci%_ptr_Uniform_uint = OpTypePointer Uniform %uint
1051fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
1052fd4e5da5Sopenharmony_ci%v2int = OpTypeVector %int 2
1053fd4e5da5Sopenharmony_ci%25 = OpConstantComposite %v2int %int_0 %int_0
1054fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
1055fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
1056fd4e5da5Sopenharmony_ci%uint_1 = OpConstant %uint 1
1057fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float
1058fd4e5da5Sopenharmony_ci%_ptr_Workgroup_uint = OpTypePointer Workgroup %uint
1059fd4e5da5Sopenharmony_ci%shared = OpVariable %_ptr_Workgroup_uint Workgroup
1060fd4e5da5Sopenharmony_ci
1061fd4e5da5Sopenharmony_ci%RayGeneration = OpFunction %void None %3
1062fd4e5da5Sopenharmony_ci%5 = OpLabel
1063fd4e5da5Sopenharmony_ci
1064fd4e5da5Sopenharmony_ci; CHECK: [[ptr0:%\w+]] = OpAccessChain %_ptr_Input_uint [[var0]] %int_0
1065fd4e5da5Sopenharmony_ci; CHECK: OpLoad {{%\w+}} [[ptr0]] Volatile
1066fd4e5da5Sopenharmony_ci%19 = OpAccessChain %_ptr_Input_uint %var0 %int_0
1067fd4e5da5Sopenharmony_ci%20 = OpLoad %uint %19
1068fd4e5da5Sopenharmony_ci
1069fd4e5da5Sopenharmony_ci%22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
1070fd4e5da5Sopenharmony_ci%23 = OpLoad %13 %22
1071fd4e5da5Sopenharmony_ci%27 = OpImageRead %v4float %23 %25
1072fd4e5da5Sopenharmony_ci%29 = OpCompositeExtract %float %27 0
1073fd4e5da5Sopenharmony_ci%31 = OpAccessChain %_ptr_Uniform_float %sbo %uint_1
1074fd4e5da5Sopenharmony_ci
1075fd4e5da5Sopenharmony_ci; CHECK: OpLoad {{%\w+}} [[ptr0]] Volatile
1076fd4e5da5Sopenharmony_ci%24 = OpLoad %uint %19
1077fd4e5da5Sopenharmony_ci
1078fd4e5da5Sopenharmony_ci; CHECK: [[var2:%\w+]] = OpCopyObject %_ptr_Input_v4uint [[var0]]
1079fd4e5da5Sopenharmony_ci; CHECK: [[ptr2:%\w+]] = OpAccessChain %_ptr_Input_uint [[var2]] %int_1
1080fd4e5da5Sopenharmony_ci; CHECK: OpLoad {{%\w+}} [[ptr2]] Volatile
1081fd4e5da5Sopenharmony_ci%18 = OpCopyObject %_ptr_Input_v4uint %var0
1082fd4e5da5Sopenharmony_ci%21 = OpAccessChain %_ptr_Input_uint %18 %int_1
1083fd4e5da5Sopenharmony_ci%26 = OpLoad %uint %21
1084fd4e5da5Sopenharmony_ci
1085fd4e5da5Sopenharmony_ci%28 = OpIAdd %uint %24 %26
1086fd4e5da5Sopenharmony_ci%30 = OpConvertUToF %float %28
1087fd4e5da5Sopenharmony_ci
1088fd4e5da5Sopenharmony_ci; CHECK: [[ptr1:%\w+]] = OpAccessChain %_ptr_Input_uint [[var1]] %int_1
1089fd4e5da5Sopenharmony_ci; CHECK: OpLoad {{%\w+}} [[ptr1]] Volatile
1090fd4e5da5Sopenharmony_ci%32 = OpAccessChain %_ptr_Input_uint %var1 %int_1
1091fd4e5da5Sopenharmony_ci%33 = OpLoad %uint %32
1092fd4e5da5Sopenharmony_ci
1093fd4e5da5Sopenharmony_ci%34 = OpConvertUToF %float %33
1094fd4e5da5Sopenharmony_ci%35 = OpFAdd %float %34 %30
1095fd4e5da5Sopenharmony_ci%36 = OpFAdd %float %35 %29
1096fd4e5da5Sopenharmony_ciOpStore %31 %36
1097fd4e5da5Sopenharmony_ciOpReturn
1098fd4e5da5Sopenharmony_ciOpFunctionEnd
1099fd4e5da5Sopenharmony_ci
1100fd4e5da5Sopenharmony_ci%compute = OpFunction %void None %3
1101fd4e5da5Sopenharmony_ci%66 = OpLabel
1102fd4e5da5Sopenharmony_ci
1103fd4e5da5Sopenharmony_ci; CHECK-NOT: OpLoad {{%\w+}} {{%\w+}} Volatile
1104fd4e5da5Sopenharmony_ci%62 = OpLoad %v4uint %var0
1105fd4e5da5Sopenharmony_ci%63 = OpLoad %v4uint %var1
1106fd4e5da5Sopenharmony_ci%64 = OpIAdd %v4uint %62 %63
1107fd4e5da5Sopenharmony_ci%65 = OpCompositeExtract %uint %64 0
1108fd4e5da5Sopenharmony_ci%61 = OpAtomicIAdd %uint %shared %uint_1 %uint_0 %65
1109fd4e5da5Sopenharmony_ciOpReturn
1110fd4e5da5Sopenharmony_ciOpFunctionEnd
1111fd4e5da5Sopenharmony_ci)";
1112fd4e5da5Sopenharmony_ci
1113fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<SpreadVolatileSemantics>(text, true);
1114fd4e5da5Sopenharmony_ci}
1115fd4e5da5Sopenharmony_ci
1116fd4e5da5Sopenharmony_ciTEST_F(VolatileSpreadTest, SkipIfItHasNoExecutionModel) {
1117fd4e5da5Sopenharmony_ci  const std::string text = R"(
1118fd4e5da5Sopenharmony_ciOpCapability Shader
1119fd4e5da5Sopenharmony_ciOpCapability Linkage
1120fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
1121fd4e5da5Sopenharmony_ci%2 = OpTypeVoid
1122fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %2
1123fd4e5da5Sopenharmony_ci%4 = OpFunction %2 None %3
1124fd4e5da5Sopenharmony_ci%5 = OpLabel
1125fd4e5da5Sopenharmony_ciOpReturn
1126fd4e5da5Sopenharmony_ciOpFunctionEnd
1127fd4e5da5Sopenharmony_ci)";
1128fd4e5da5Sopenharmony_ci
1129fd4e5da5Sopenharmony_ci  Pass::Status status;
1130fd4e5da5Sopenharmony_ci  std::tie(std::ignore, status) =
1131fd4e5da5Sopenharmony_ci      SinglePassRunToBinary<SpreadVolatileSemantics>(text,
1132fd4e5da5Sopenharmony_ci                                                     /* skip_nop = */ false);
1133fd4e5da5Sopenharmony_ci  EXPECT_EQ(status, Pass::Status::SuccessWithoutChange);
1134fd4e5da5Sopenharmony_ci}
1135fd4e5da5Sopenharmony_ci
1136fd4e5da5Sopenharmony_ciTEST_F(VolatileSpreadTest, NoInlinedfuncCalls) {
1137fd4e5da5Sopenharmony_ci  const std::string text = R"(
1138fd4e5da5Sopenharmony_ciOpCapability RayTracingNV
1139fd4e5da5Sopenharmony_ciOpCapability VulkanMemoryModel
1140fd4e5da5Sopenharmony_ciOpCapability GroupNonUniform
1141fd4e5da5Sopenharmony_ciOpExtension "SPV_NV_ray_tracing"
1142fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_vulkan_memory_model"
1143fd4e5da5Sopenharmony_ciOpMemoryModel Logical Vulkan
1144fd4e5da5Sopenharmony_ciOpEntryPoint RayGenerationNV %main "main" %SubgroupSize
1145fd4e5da5Sopenharmony_ciOpSource HLSL 630
1146fd4e5da5Sopenharmony_ciOpName %main "main"
1147fd4e5da5Sopenharmony_ciOpName %src_main "src.main"
1148fd4e5da5Sopenharmony_ciOpName %bb_entry "bb.entry"
1149fd4e5da5Sopenharmony_ciOpName %func0 "func0"
1150fd4e5da5Sopenharmony_ciOpName %bb_entry_0 "bb.entry"
1151fd4e5da5Sopenharmony_ciOpName %func2 "func2"
1152fd4e5da5Sopenharmony_ciOpName %bb_entry_1 "bb.entry"
1153fd4e5da5Sopenharmony_ciOpName %param_var_count "param.var.count"
1154fd4e5da5Sopenharmony_ciOpName %func1 "func1"
1155fd4e5da5Sopenharmony_ciOpName %bb_entry_2 "bb.entry"
1156fd4e5da5Sopenharmony_ciOpName %func3 "func3"
1157fd4e5da5Sopenharmony_ciOpName %count "count"
1158fd4e5da5Sopenharmony_ciOpName %bb_entry_3 "bb.entry"
1159fd4e5da5Sopenharmony_ciOpDecorate %SubgroupSize BuiltIn SubgroupSize
1160fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
1161fd4e5da5Sopenharmony_ci%_ptr_Input_uint = OpTypePointer Input %uint
1162fd4e5da5Sopenharmony_ci%void = OpTypeVoid
1163fd4e5da5Sopenharmony_ci%6 = OpTypeFunction %void
1164fd4e5da5Sopenharmony_ci%_ptr_Function_uint = OpTypePointer Function %uint
1165fd4e5da5Sopenharmony_ci%25 = OpTypeFunction %void %_ptr_Function_uint
1166fd4e5da5Sopenharmony_ci%SubgroupSize = OpVariable %_ptr_Input_uint Input
1167fd4e5da5Sopenharmony_ci%main = OpFunction %void None %6
1168fd4e5da5Sopenharmony_ci%7 = OpLabel
1169fd4e5da5Sopenharmony_ci%8 = OpFunctionCall %void %src_main
1170fd4e5da5Sopenharmony_ciOpReturn
1171fd4e5da5Sopenharmony_ciOpFunctionEnd
1172fd4e5da5Sopenharmony_ci%src_main = OpFunction %void None %6
1173fd4e5da5Sopenharmony_ci%bb_entry = OpLabel
1174fd4e5da5Sopenharmony_ci%11 = OpFunctionCall %void %func0
1175fd4e5da5Sopenharmony_ciOpReturn
1176fd4e5da5Sopenharmony_ciOpFunctionEnd
1177fd4e5da5Sopenharmony_ci%func0 = OpFunction %void DontInline %6
1178fd4e5da5Sopenharmony_ci%bb_entry_0 = OpLabel
1179fd4e5da5Sopenharmony_ci%14 = OpFunctionCall %void %func2
1180fd4e5da5Sopenharmony_ci%16 = OpFunctionCall %void %func1
1181fd4e5da5Sopenharmony_ciOpReturn
1182fd4e5da5Sopenharmony_ciOpFunctionEnd
1183fd4e5da5Sopenharmony_ci%func2 = OpFunction %void DontInline %6
1184fd4e5da5Sopenharmony_ci%bb_entry_1 = OpLabel
1185fd4e5da5Sopenharmony_ci%param_var_count = OpVariable %_ptr_Function_uint Function
1186fd4e5da5Sopenharmony_ci; CHECK: {{%\w+}} = OpLoad %uint %SubgroupSize Volatile
1187fd4e5da5Sopenharmony_ci%21 = OpLoad %uint %SubgroupSize
1188fd4e5da5Sopenharmony_ciOpStore %param_var_count %21
1189fd4e5da5Sopenharmony_ci%22 = OpFunctionCall %void %func3 %param_var_count
1190fd4e5da5Sopenharmony_ciOpReturn
1191fd4e5da5Sopenharmony_ciOpFunctionEnd
1192fd4e5da5Sopenharmony_ci%func1 = OpFunction %void DontInline %6
1193fd4e5da5Sopenharmony_ci%bb_entry_2 = OpLabel
1194fd4e5da5Sopenharmony_ciOpReturn
1195fd4e5da5Sopenharmony_ciOpFunctionEnd
1196fd4e5da5Sopenharmony_ci%func3 = OpFunction %void DontInline %25
1197fd4e5da5Sopenharmony_ci%count = OpFunctionParameter %_ptr_Function_uint
1198fd4e5da5Sopenharmony_ci%bb_entry_3 = OpLabel
1199fd4e5da5Sopenharmony_ciOpReturn
1200fd4e5da5Sopenharmony_ciOpFunctionEnd
1201fd4e5da5Sopenharmony_ci)";
1202fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<SpreadVolatileSemantics>(text, true);
1203fd4e5da5Sopenharmony_ci}
1204fd4e5da5Sopenharmony_ci
1205fd4e5da5Sopenharmony_ciTEST_F(VolatileSpreadErrorTest, NoInlinedMultiEntryfuncCalls) {
1206fd4e5da5Sopenharmony_ci  const std::string text = R"(
1207fd4e5da5Sopenharmony_ciOpCapability RayTracingNV
1208fd4e5da5Sopenharmony_ciOpCapability SubgroupBallotKHR
1209fd4e5da5Sopenharmony_ciOpExtension "SPV_NV_ray_tracing"
1210fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_shader_ballot"
1211fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
1212fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
1213fd4e5da5Sopenharmony_ciOpEntryPoint RayGenerationNV %main "main" %SubgroupSize
1214fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %main2 "main2" %gl_LocalInvocationIndex %SubgroupSize
1215fd4e5da5Sopenharmony_ciOpSource HLSL 630
1216fd4e5da5Sopenharmony_ciOpName %main "main"
1217fd4e5da5Sopenharmony_ciOpName %bb_entry "bb.entry"
1218fd4e5da5Sopenharmony_ciOpName %main2 "main2"
1219fd4e5da5Sopenharmony_ciOpName %bb_entry_0 "bb.entry"
1220fd4e5da5Sopenharmony_ciOpName %func "func"
1221fd4e5da5Sopenharmony_ciOpName %count "count"
1222fd4e5da5Sopenharmony_ciOpName %bb_entry_1 "bb.entry"
1223fd4e5da5Sopenharmony_ciOpDecorate %gl_LocalInvocationIndex BuiltIn LocalInvocationIndex
1224fd4e5da5Sopenharmony_ciOpDecorate %SubgroupSize BuiltIn SubgroupSize
1225fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
1226fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
1227fd4e5da5Sopenharmony_ci%_ptr_Input_uint = OpTypePointer Input %uint
1228fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
1229fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
1230fd4e5da5Sopenharmony_ci%void = OpTypeVoid
1231fd4e5da5Sopenharmony_ci%12 = OpTypeFunction %void
1232fd4e5da5Sopenharmony_ci%_ptr_Function_uint = OpTypePointer Function %uint
1233fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
1234fd4e5da5Sopenharmony_ci%29 = OpTypeFunction %void %_ptr_Function_v4float
1235fd4e5da5Sopenharmony_ci%34 = OpTypeFunction %void %_ptr_Function_uint
1236fd4e5da5Sopenharmony_ci%SubgroupSize = OpVariable %_ptr_Input_uint Input
1237fd4e5da5Sopenharmony_ci%gl_LocalInvocationIndex = OpVariable %_ptr_Input_uint Input
1238fd4e5da5Sopenharmony_ci%main = OpFunction %void None %12
1239fd4e5da5Sopenharmony_ci%bb_entry = OpLabel
1240fd4e5da5Sopenharmony_ci%20 = OpFunctionCall %void %func
1241fd4e5da5Sopenharmony_ciOpReturn
1242fd4e5da5Sopenharmony_ciOpFunctionEnd
1243fd4e5da5Sopenharmony_ci%main2 = OpFunction %void None %12
1244fd4e5da5Sopenharmony_ci%bb_entry_0 = OpLabel
1245fd4e5da5Sopenharmony_ci%33 = OpFunctionCall %void %func
1246fd4e5da5Sopenharmony_ciOpReturn
1247fd4e5da5Sopenharmony_ciOpFunctionEnd
1248fd4e5da5Sopenharmony_ci%func = OpFunction %void DontInline %12
1249fd4e5da5Sopenharmony_ci%bb_entry_1 = OpLabel
1250fd4e5da5Sopenharmony_ci%count = OpVariable %_ptr_Function_uint Function
1251fd4e5da5Sopenharmony_ci%35 = OpLoad %uint %SubgroupSize
1252fd4e5da5Sopenharmony_ciOpStore %count %35
1253fd4e5da5Sopenharmony_ciOpReturn
1254fd4e5da5Sopenharmony_ciOpFunctionEnd
1255fd4e5da5Sopenharmony_ci)";
1256fd4e5da5Sopenharmony_ci  EXPECT_EQ(RunPass(text), Pass::Status::Failure);
1257fd4e5da5Sopenharmony_ci  const char expected_error[] =
1258fd4e5da5Sopenharmony_ci      "ERROR: 0: Variable is a target for Volatile semantics for an entry "
1259fd4e5da5Sopenharmony_ci      "point, but it is not for another entry point";
1260fd4e5da5Sopenharmony_ci  EXPECT_STREQ(GetErrorMessage().substr(0, sizeof(expected_error) - 1).c_str(),
1261fd4e5da5Sopenharmony_ci               expected_error);
1262fd4e5da5Sopenharmony_ci}
1263fd4e5da5Sopenharmony_ci
1264fd4e5da5Sopenharmony_ci}  // namespace
1265fd4e5da5Sopenharmony_ci}  // namespace opt
1266fd4e5da5Sopenharmony_ci}  // namespace spvtools
1267