1fd4e5da5Sopenharmony_ci// Copyright (c) 2017-2022 Valve Corporation
2fd4e5da5Sopenharmony_ci// Copyright (c) 2017-2022 LunarG Inc.
3fd4e5da5Sopenharmony_ci//
4fd4e5da5Sopenharmony_ci// Licensed under the Apache License, Version 2.0 (the "License");
5fd4e5da5Sopenharmony_ci// you may not use this file except in compliance with the License.
6fd4e5da5Sopenharmony_ci// You may obtain a copy of the License at
7fd4e5da5Sopenharmony_ci//
8fd4e5da5Sopenharmony_ci//     http://www.apache.org/licenses/LICENSE-2.0
9fd4e5da5Sopenharmony_ci//
10fd4e5da5Sopenharmony_ci// Unless required by applicable law or agreed to in writing, software
11fd4e5da5Sopenharmony_ci// distributed under the License is distributed on an "AS IS" BASIS,
12fd4e5da5Sopenharmony_ci// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13fd4e5da5Sopenharmony_ci// See the License for the specific language governing permissions and
14fd4e5da5Sopenharmony_ci// limitations under the License.
15fd4e5da5Sopenharmony_ci
16fd4e5da5Sopenharmony_ci// Bindless Check Instrumentation Tests.
17fd4e5da5Sopenharmony_ci
18fd4e5da5Sopenharmony_ci#include <string>
19fd4e5da5Sopenharmony_ci#include <vector>
20fd4e5da5Sopenharmony_ci
21fd4e5da5Sopenharmony_ci#include "test/opt/pass_fixture.h"
22fd4e5da5Sopenharmony_ci#include "test/opt/pass_utils.h"
23fd4e5da5Sopenharmony_ci
24fd4e5da5Sopenharmony_cinamespace spvtools {
25fd4e5da5Sopenharmony_cinamespace opt {
26fd4e5da5Sopenharmony_cinamespace {
27fd4e5da5Sopenharmony_ci
28fd4e5da5Sopenharmony_ciusing InstBindlessTest = PassTest<::testing::Test>;
29fd4e5da5Sopenharmony_ci
30fd4e5da5Sopenharmony_cistatic const std::string kFuncName = "inst_bindless_check_desc";
31fd4e5da5Sopenharmony_ci
32fd4e5da5Sopenharmony_cistatic const std::string kImportDeco = R"(
33fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %)" + kFuncName + R"( LinkageAttributes ")" +
34fd4e5da5Sopenharmony_ci                                       kFuncName + R"(" Import
35fd4e5da5Sopenharmony_ci)";
36fd4e5da5Sopenharmony_ci
37fd4e5da5Sopenharmony_cistatic const std::string kImportStub = R"(
38fd4e5da5Sopenharmony_ci;CHECK: %)" + kFuncName + R"( = OpFunction %bool None {{%\w+}}
39fd4e5da5Sopenharmony_ci;CHECK: OpFunctionEnd
40fd4e5da5Sopenharmony_ci)";
41fd4e5da5Sopenharmony_ci
42fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest, Simple) {
43fd4e5da5Sopenharmony_ci  // Texture2D g_tColor[128];
44fd4e5da5Sopenharmony_ci  //
45fd4e5da5Sopenharmony_ci  // layout(push_constant) cbuffer PerViewConstantBuffer_t
46fd4e5da5Sopenharmony_ci  // {
47fd4e5da5Sopenharmony_ci  //   uint g_nDataIdx;
48fd4e5da5Sopenharmony_ci  // };
49fd4e5da5Sopenharmony_ci  //
50fd4e5da5Sopenharmony_ci  // SamplerState g_sAniso;
51fd4e5da5Sopenharmony_ci  //
52fd4e5da5Sopenharmony_ci  // struct PS_INPUT
53fd4e5da5Sopenharmony_ci  // {
54fd4e5da5Sopenharmony_ci  //   float2 vTextureCoords : TEXCOORD2;
55fd4e5da5Sopenharmony_ci  // };
56fd4e5da5Sopenharmony_ci  //
57fd4e5da5Sopenharmony_ci  // struct PS_OUTPUT
58fd4e5da5Sopenharmony_ci  // {
59fd4e5da5Sopenharmony_ci  //   float4 vColor : SV_Target0;
60fd4e5da5Sopenharmony_ci  // };
61fd4e5da5Sopenharmony_ci  //
62fd4e5da5Sopenharmony_ci  // PS_OUTPUT MainPs(PS_INPUT i)
63fd4e5da5Sopenharmony_ci  // {
64fd4e5da5Sopenharmony_ci  //   PS_OUTPUT ps_output;
65fd4e5da5Sopenharmony_ci  //   ps_output.vColor =
66fd4e5da5Sopenharmony_ci  //       g_tColor[ g_nDataIdx ].Sample(g_sAniso, i.vTextureCoords.xy);
67fd4e5da5Sopenharmony_ci  //   return ps_output;
68fd4e5da5Sopenharmony_ci  // }
69fd4e5da5Sopenharmony_ci
70fd4e5da5Sopenharmony_ci  const std::string entry = R"(
71fd4e5da5Sopenharmony_ciOpCapability Shader
72fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
73fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
74fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
75fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
76fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
77fd4e5da5Sopenharmony_ciOpExecutionMode %MainPs OriginUpperLeft
78fd4e5da5Sopenharmony_ciOpSource HLSL 500
79fd4e5da5Sopenharmony_ci)";
80fd4e5da5Sopenharmony_ci
81fd4e5da5Sopenharmony_ci  // clang-format off
82fd4e5da5Sopenharmony_ci  const std::string names_annots = R"(
83fd4e5da5Sopenharmony_ciOpName %MainPs "MainPs"
84fd4e5da5Sopenharmony_ciOpName %g_tColor "g_tColor"
85fd4e5da5Sopenharmony_ciOpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
86fd4e5da5Sopenharmony_ciOpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
87fd4e5da5Sopenharmony_ciOpName %_ ""
88fd4e5da5Sopenharmony_ciOpName %g_sAniso "g_sAniso"
89fd4e5da5Sopenharmony_ciOpName %i_vTextureCoords "i.vTextureCoords"
90fd4e5da5Sopenharmony_ciOpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
91fd4e5da5Sopenharmony_ciOpDecorate %g_tColor DescriptorSet 3
92fd4e5da5Sopenharmony_ciOpDecorate %g_tColor Binding 0
93fd4e5da5Sopenharmony_ciOpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
94fd4e5da5Sopenharmony_ciOpDecorate %PerViewConstantBuffer_t Block
95fd4e5da5Sopenharmony_ciOpDecorate %g_sAniso DescriptorSet 0
96fd4e5da5Sopenharmony_ciOpDecorate %i_vTextureCoords Location 0
97fd4e5da5Sopenharmony_ciOpDecorate %_entryPointOutput_vColor Location 0)"
98fd4e5da5Sopenharmony_ci+ kImportDeco +
99fd4e5da5Sopenharmony_ciR"(
100fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
101fd4e5da5Sopenharmony_ci)";
102fd4e5da5Sopenharmony_ci
103fd4e5da5Sopenharmony_ci  const std::string consts_types_vars = R"(
104fd4e5da5Sopenharmony_ci%void = OpTypeVoid
105fd4e5da5Sopenharmony_ci%10 = OpTypeFunction %void
106fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
107fd4e5da5Sopenharmony_ci%v2float = OpTypeVector %float 2
108fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
109fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
110fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
111fd4e5da5Sopenharmony_ci%16 = OpTypeImage %float 2D 0 0 0 1 Unknown
112fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
113fd4e5da5Sopenharmony_ci%uint_128 = OpConstant %uint 128
114fd4e5da5Sopenharmony_ci%_arr_16_uint_128 = OpTypeArray %16 %uint_128
115fd4e5da5Sopenharmony_ci%_ptr_UniformConstant__arr_16_uint_128 = OpTypePointer UniformConstant %_arr_16_uint_128
116fd4e5da5Sopenharmony_ci%g_tColor = OpVariable %_ptr_UniformConstant__arr_16_uint_128 UniformConstant
117fd4e5da5Sopenharmony_ci%PerViewConstantBuffer_t = OpTypeStruct %uint
118fd4e5da5Sopenharmony_ci%_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
119fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
120fd4e5da5Sopenharmony_ci%_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
121fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_16 = OpTypePointer UniformConstant %16
122fd4e5da5Sopenharmony_ci%24 = OpTypeSampler
123fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_24 = OpTypePointer UniformConstant %24
124fd4e5da5Sopenharmony_ci%g_sAniso = OpVariable %_ptr_UniformConstant_24 UniformConstant
125fd4e5da5Sopenharmony_ci%26 = OpTypeSampledImage %16
126fd4e5da5Sopenharmony_ci%_ptr_Input_v2float = OpTypePointer Input %v2float
127fd4e5da5Sopenharmony_ci%i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
128fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
129fd4e5da5Sopenharmony_ci%_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
130fd4e5da5Sopenharmony_ci;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
131fd4e5da5Sopenharmony_ci;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
132fd4e5da5Sopenharmony_ci;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
133fd4e5da5Sopenharmony_ci)";
134fd4e5da5Sopenharmony_ci
135fd4e5da5Sopenharmony_ci  const std::string main_func = R"(
136fd4e5da5Sopenharmony_ci%MainPs = OpFunction %void None %10
137fd4e5da5Sopenharmony_ci%29 = OpLabel
138fd4e5da5Sopenharmony_ci%30 = OpLoad %v2float %i_vTextureCoords
139fd4e5da5Sopenharmony_ci%31 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
140fd4e5da5Sopenharmony_ci%32 = OpLoad %uint %31
141fd4e5da5Sopenharmony_ci%33 = OpAccessChain %_ptr_UniformConstant_16 %g_tColor %32
142fd4e5da5Sopenharmony_ci%34 = OpLoad %16 %33
143fd4e5da5Sopenharmony_ci%35 = OpLoad %24 %g_sAniso
144fd4e5da5Sopenharmony_ci%36 = OpSampledImage %26 %34 %35
145fd4e5da5Sopenharmony_ci%37 = OpImageSampleImplicitLod %v4float %36 %30
146fd4e5da5Sopenharmony_ciOpStore %_entryPointOutput_vColor %37
147fd4e5da5Sopenharmony_ci;CHECK-NOT: %37 = OpImageSampleImplicitLod %v4float %36 %30
148fd4e5da5Sopenharmony_ci;CHECK-NOT: OpStore %_entryPointOutput_vColor %37
149fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_57 {{%\w+}} %uint_3 %uint_0 %32 %uint_0
150fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
151fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
152fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
153fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %16 %33
154fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpSampledImage %26 {{%\w+}} %35
155fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpImageSampleImplicitLod %v4float {{%\w+}} %30
156fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
157fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
158fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
159fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
160fd4e5da5Sopenharmony_ci;CHECK: [[phi_result:%\w+]] = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}}
161fd4e5da5Sopenharmony_ci;CHECK: OpStore %_entryPointOutput_vColor [[phi_result]]
162fd4e5da5Sopenharmony_ciOpReturn
163fd4e5da5Sopenharmony_ciOpFunctionEnd
164fd4e5da5Sopenharmony_ci)";
165fd4e5da5Sopenharmony_ci  // clang-format on
166fd4e5da5Sopenharmony_ci
167fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
168fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(
169fd4e5da5Sopenharmony_ci      entry + names_annots + consts_types_vars + kImportStub + main_func, true,
170fd4e5da5Sopenharmony_ci      23u);
171fd4e5da5Sopenharmony_ci}
172fd4e5da5Sopenharmony_ci
173fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest, InstrumentMultipleInstructions) {
174fd4e5da5Sopenharmony_ci  // Texture2D g_tColor[128];
175fd4e5da5Sopenharmony_ci  //
176fd4e5da5Sopenharmony_ci  // layout(push_constant) cbuffer PerViewConstantBuffer_t
177fd4e5da5Sopenharmony_ci  // {
178fd4e5da5Sopenharmony_ci  //   uint g_nDataIdx;
179fd4e5da5Sopenharmony_ci  //   uint g_nDataIdx2;
180fd4e5da5Sopenharmony_ci  // };
181fd4e5da5Sopenharmony_ci  //
182fd4e5da5Sopenharmony_ci  // SamplerState g_sAniso;
183fd4e5da5Sopenharmony_ci  //
184fd4e5da5Sopenharmony_ci  // struct PS_INPUT
185fd4e5da5Sopenharmony_ci  // {
186fd4e5da5Sopenharmony_ci  //   float2 vTextureCoords : TEXCOORD2;
187fd4e5da5Sopenharmony_ci  // };
188fd4e5da5Sopenharmony_ci  //
189fd4e5da5Sopenharmony_ci  // struct PS_OUTPUT
190fd4e5da5Sopenharmony_ci  // {
191fd4e5da5Sopenharmony_ci  //   float4 vColor : SV_Target0;
192fd4e5da5Sopenharmony_ci  // };
193fd4e5da5Sopenharmony_ci  //
194fd4e5da5Sopenharmony_ci  // PS_OUTPUT MainPs(PS_INPUT i)
195fd4e5da5Sopenharmony_ci  // {
196fd4e5da5Sopenharmony_ci  //   PS_OUTPUT ps_output;
197fd4e5da5Sopenharmony_ci  //
198fd4e5da5Sopenharmony_ci  //   float t  = g_tColor[g_nDataIdx ].Sample(g_sAniso, i.vTextureCoords.xy);
199fd4e5da5Sopenharmony_ci  //   float t2 = g_tColor[g_nDataIdx2].Sample(g_sAniso, i.vTextureCoords.xy);
200fd4e5da5Sopenharmony_ci  //   ps_output.vColor = t + t2;
201fd4e5da5Sopenharmony_ci  //   return ps_output;
202fd4e5da5Sopenharmony_ci  // }
203fd4e5da5Sopenharmony_ci
204fd4e5da5Sopenharmony_ci  // clang-format off
205fd4e5da5Sopenharmony_ci  const std::string defs = R"(
206fd4e5da5Sopenharmony_ciOpCapability Shader
207fd4e5da5Sopenharmony_ciOpCapability Linkage
208fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
209fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
210fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
211fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
212fd4e5da5Sopenharmony_ciOpExecutionMode %MainPs OriginUpperLeft
213fd4e5da5Sopenharmony_ciOpSource HLSL 500
214fd4e5da5Sopenharmony_ciOpName %MainPs "MainPs"
215fd4e5da5Sopenharmony_ciOpName %g_tColor "g_tColor"
216fd4e5da5Sopenharmony_ciOpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
217fd4e5da5Sopenharmony_ciOpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
218fd4e5da5Sopenharmony_ciOpName %_ ""
219fd4e5da5Sopenharmony_ciOpName %g_sAniso "g_sAniso"
220fd4e5da5Sopenharmony_ciOpName %i_vTextureCoords "i.vTextureCoords"
221fd4e5da5Sopenharmony_ciOpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
222fd4e5da5Sopenharmony_ciOpDecorate %g_tColor DescriptorSet 3
223fd4e5da5Sopenharmony_ciOpDecorate %g_tColor Binding 4
224fd4e5da5Sopenharmony_ciOpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
225fd4e5da5Sopenharmony_ciOpMemberDecorate %PerViewConstantBuffer_t 1 Offset 4
226fd4e5da5Sopenharmony_ciOpDecorate %PerViewConstantBuffer_t Block
227fd4e5da5Sopenharmony_ciOpDecorate %g_sAniso DescriptorSet 3
228fd4e5da5Sopenharmony_ciOpDecorate %i_vTextureCoords Location 0
229fd4e5da5Sopenharmony_ciOpDecorate %_entryPointOutput_vColor Location 0
230fd4e5da5Sopenharmony_ci)" + kImportDeco + R"(
231fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
232fd4e5da5Sopenharmony_ci%void = OpTypeVoid
233fd4e5da5Sopenharmony_ci%10 = OpTypeFunction %void
234fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
235fd4e5da5Sopenharmony_ci%v2float = OpTypeVector %float 2
236fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
237fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
238fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
239fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
240fd4e5da5Sopenharmony_ci%17 = OpTypeImage %float 2D 0 0 0 1 Unknown
241fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
242fd4e5da5Sopenharmony_ci%uint_128 = OpConstant %uint 128
243fd4e5da5Sopenharmony_ci%_arr_17_uint_128 = OpTypeArray %17 %uint_128
244fd4e5da5Sopenharmony_ci%_ptr_UniformConstant__arr_17_uint_128 = OpTypePointer UniformConstant %_arr_17_uint_128
245fd4e5da5Sopenharmony_ci%g_tColor = OpVariable %_ptr_UniformConstant__arr_17_uint_128 UniformConstant
246fd4e5da5Sopenharmony_ci%PerViewConstantBuffer_t = OpTypeStruct %uint %uint
247fd4e5da5Sopenharmony_ci%_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
248fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
249fd4e5da5Sopenharmony_ci%_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
250fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_17 = OpTypePointer UniformConstant %17
251fd4e5da5Sopenharmony_ci%25 = OpTypeSampler
252fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_25 = OpTypePointer UniformConstant %25
253fd4e5da5Sopenharmony_ci%g_sAniso = OpVariable %_ptr_UniformConstant_25 UniformConstant
254fd4e5da5Sopenharmony_ci%27 = OpTypeSampledImage %17
255fd4e5da5Sopenharmony_ci%_ptr_Input_v2float = OpTypePointer Input %v2float
256fd4e5da5Sopenharmony_ci%i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
257fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
258fd4e5da5Sopenharmony_ci%_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
259fd4e5da5Sopenharmony_ci;CHECK: %v4uint = OpTypeVector %uint 4
260fd4e5da5Sopenharmony_ci;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
261fd4e5da5Sopenharmony_ci;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
262fd4e5da5Sopenharmony_ci;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
263fd4e5da5Sopenharmony_ci)";
264fd4e5da5Sopenharmony_ci
265fd4e5da5Sopenharmony_ci  const std::string main_func = R"(
266fd4e5da5Sopenharmony_ci%MainPs = OpFunction %void None %10
267fd4e5da5Sopenharmony_ci%30 = OpLabel
268fd4e5da5Sopenharmony_ci%31 = OpLoad %v2float %i_vTextureCoords
269fd4e5da5Sopenharmony_ci%32 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
270fd4e5da5Sopenharmony_ci%33 = OpLoad %uint %32
271fd4e5da5Sopenharmony_ci%34 = OpAccessChain %_ptr_UniformConstant_17 %g_tColor %33
272fd4e5da5Sopenharmony_ci%35 = OpLoad %17 %34
273fd4e5da5Sopenharmony_ci%36 = OpLoad %25 %g_sAniso
274fd4e5da5Sopenharmony_ci%37 = OpSampledImage %27 %35 %36
275fd4e5da5Sopenharmony_ci%38 = OpImageSampleImplicitLod %v4float %37 %31
276fd4e5da5Sopenharmony_ci;CHECK-NOT: %38 = OpImageSampleImplicitLod %v4float %37 %31
277fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord
278fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}}
279fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
280fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
281fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0
282fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_60 {{%\w+}} %uint_3 %uint_4 %33 %uint_0
283fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
284fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
285fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
286fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %17 %34
287fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpSampledImage %27 {{%\w+}} %36
288fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpImageSampleImplicitLod %v4float {{%\w+}} %31
289fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
290fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
291fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
292fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
293fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}}
294fd4e5da5Sopenharmony_ci%39 = OpAccessChain %_ptr_PushConstant_uint %_ %int_1
295fd4e5da5Sopenharmony_ci%40 = OpLoad %uint %39
296fd4e5da5Sopenharmony_ci%41 = OpAccessChain %_ptr_UniformConstant_17 %g_tColor %40
297fd4e5da5Sopenharmony_ci%42 = OpLoad %17 %41
298fd4e5da5Sopenharmony_ci%43 = OpSampledImage %27 %42 %36
299fd4e5da5Sopenharmony_ci%44 = OpImageSampleImplicitLod %v4float %43 %31
300fd4e5da5Sopenharmony_ci%45 = OpFAdd %v4float %38 %44
301fd4e5da5Sopenharmony_ci;CHECK-NOT: %44 = OpImageSampleImplicitLod %v4float %43 %31
302fd4e5da5Sopenharmony_ci;CHECK-NOT: %45 = OpFAdd %v4float %38 %44
303fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord
304fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}}
305fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
306fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
307fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0
308fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_66 {{%\w+}} %uint_3 %uint_4 %40 %uint_0
309fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
310fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
311fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
312fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %17 %41
313fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpSampledImage %27 {{%\w+}} %36
314fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpImageSampleImplicitLod %v4float {{%\w+}} %31
315fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
316fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
317fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
318fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
319fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}}
320fd4e5da5Sopenharmony_ci;CHECK: %45 = OpFAdd %v4float {{%\w+}} {{%\w+}}
321fd4e5da5Sopenharmony_ciOpStore %_entryPointOutput_vColor %45
322fd4e5da5Sopenharmony_ciOpReturn
323fd4e5da5Sopenharmony_ciOpFunctionEnd
324fd4e5da5Sopenharmony_ci)";
325fd4e5da5Sopenharmony_ci  // clang-format on
326fd4e5da5Sopenharmony_ci
327fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
328fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(defs + kImportStub + main_func,
329fd4e5da5Sopenharmony_ci                                               true, 23u);
330fd4e5da5Sopenharmony_ci}
331fd4e5da5Sopenharmony_ci
332fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest, InstrumentOpImage) {
333fd4e5da5Sopenharmony_ci  // This test verifies that the pass will correctly instrument shader
334fd4e5da5Sopenharmony_ci  // using OpImage. This test was created by editing the SPIR-V
335fd4e5da5Sopenharmony_ci  // from the Simple test.
336fd4e5da5Sopenharmony_ci
337fd4e5da5Sopenharmony_ci  // clang-format off
338fd4e5da5Sopenharmony_ci  const std::string defs = R"(
339fd4e5da5Sopenharmony_ciOpCapability Shader
340fd4e5da5Sopenharmony_ciOpCapability StorageImageReadWithoutFormat
341fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
342fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
343fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
344fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
345fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
346fd4e5da5Sopenharmony_ciOpExecutionMode %MainPs OriginUpperLeft
347fd4e5da5Sopenharmony_ciOpSource HLSL 500
348fd4e5da5Sopenharmony_ciOpName %MainPs "MainPs"
349fd4e5da5Sopenharmony_ciOpName %g_tColor "g_tColor"
350fd4e5da5Sopenharmony_ciOpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
351fd4e5da5Sopenharmony_ciOpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
352fd4e5da5Sopenharmony_ciOpName %_ ""
353fd4e5da5Sopenharmony_ciOpName %i_vTextureCoords "i.vTextureCoords"
354fd4e5da5Sopenharmony_ciOpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
355fd4e5da5Sopenharmony_ciOpDecorate %g_tColor DescriptorSet 3
356fd4e5da5Sopenharmony_ciOpDecorate %g_tColor Binding 9
357fd4e5da5Sopenharmony_ciOpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
358fd4e5da5Sopenharmony_ciOpDecorate %PerViewConstantBuffer_t Block
359fd4e5da5Sopenharmony_ciOpDecorate %i_vTextureCoords Location 0
360fd4e5da5Sopenharmony_ciOpDecorate %_entryPointOutput_vColor Location 0
361fd4e5da5Sopenharmony_ci)" + kImportDeco + R"(
362fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
363fd4e5da5Sopenharmony_ci%void = OpTypeVoid
364fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
365fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
366fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
367fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
368fd4e5da5Sopenharmony_ci%v2int = OpTypeVector %int 2
369fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
370fd4e5da5Sopenharmony_ci%20 = OpTypeImage %float 2D 0 0 0 0 Unknown
371fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
372fd4e5da5Sopenharmony_ci%uint_128 = OpConstant %uint 128
373fd4e5da5Sopenharmony_ci%39 = OpTypeSampledImage %20
374fd4e5da5Sopenharmony_ci%_arr_39_uint_128 = OpTypeArray %39 %uint_128
375fd4e5da5Sopenharmony_ci%_ptr_UniformConstant__arr_39_uint_128 = OpTypePointer UniformConstant %_arr_39_uint_128
376fd4e5da5Sopenharmony_ci%g_tColor = OpVariable %_ptr_UniformConstant__arr_39_uint_128 UniformConstant
377fd4e5da5Sopenharmony_ci%PerViewConstantBuffer_t = OpTypeStruct %uint
378fd4e5da5Sopenharmony_ci%_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
379fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
380fd4e5da5Sopenharmony_ci%_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
381fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_39 = OpTypePointer UniformConstant %39
382fd4e5da5Sopenharmony_ci%_ptr_Input_v2int = OpTypePointer Input %v2int
383fd4e5da5Sopenharmony_ci%i_vTextureCoords = OpVariable %_ptr_Input_v2int Input
384fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
385fd4e5da5Sopenharmony_ci%_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
386fd4e5da5Sopenharmony_ci;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
387fd4e5da5Sopenharmony_ci;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
388fd4e5da5Sopenharmony_ci;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
389fd4e5da5Sopenharmony_ci)";
390fd4e5da5Sopenharmony_ci
391fd4e5da5Sopenharmony_ci  const std::string main_func = R"(
392fd4e5da5Sopenharmony_ci%MainPs = OpFunction %void None %3
393fd4e5da5Sopenharmony_ci%5 = OpLabel
394fd4e5da5Sopenharmony_ci%53 = OpLoad %v2int %i_vTextureCoords
395fd4e5da5Sopenharmony_ci%63 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
396fd4e5da5Sopenharmony_ci%64 = OpLoad %uint %63
397fd4e5da5Sopenharmony_ci%65 = OpAccessChain %_ptr_UniformConstant_39 %g_tColor %64
398fd4e5da5Sopenharmony_ci%66 = OpLoad %39 %65
399fd4e5da5Sopenharmony_ci%75 = OpImage %20 %66
400fd4e5da5Sopenharmony_ci%71 = OpImageRead %v4float %75 %53
401fd4e5da5Sopenharmony_ciOpStore %_entryPointOutput_vColor %71
402fd4e5da5Sopenharmony_ci;CHECK-NOT: %71 = OpImageRead %v4float %75 %53
403fd4e5da5Sopenharmony_ci;CHECK-NOT: OpStore %_entryPointOutput_vColor %71
404fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord
405fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}}
406fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
407fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
408fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0
409fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_52 {{%\w+}} %uint_3 %uint_9 %64 %uint_0
410fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
411fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
412fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
413fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %39 %65
414fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpImage %20 {{%\w+}}
415fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpImageRead %v4float {{%\w+}} %53
416fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
417fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
418fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
419fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
420fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}}
421fd4e5da5Sopenharmony_ci;CHECK: OpStore %_entryPointOutput_vColor {{%\w+}}
422fd4e5da5Sopenharmony_ciOpReturn
423fd4e5da5Sopenharmony_ciOpFunctionEnd
424fd4e5da5Sopenharmony_ci)";
425fd4e5da5Sopenharmony_ci  // clang-format on
426fd4e5da5Sopenharmony_ci
427fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
428fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(defs + kImportStub + main_func,
429fd4e5da5Sopenharmony_ci                                               true, 23u);
430fd4e5da5Sopenharmony_ci}
431fd4e5da5Sopenharmony_ci
432fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest, InstrumentSampledImage) {
433fd4e5da5Sopenharmony_ci  // This test verifies that the pass will correctly instrument shader
434fd4e5da5Sopenharmony_ci  // using sampled image. This test was created by editing the SPIR-V
435fd4e5da5Sopenharmony_ci  // from the Simple test.
436fd4e5da5Sopenharmony_ci
437fd4e5da5Sopenharmony_ci  // clang-format off
438fd4e5da5Sopenharmony_ci  const std::string defs = R"(
439fd4e5da5Sopenharmony_ciOpCapability Shader
440fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
441fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
442fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
443fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
444fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
445fd4e5da5Sopenharmony_ciOpExecutionMode %MainPs OriginUpperLeft
446fd4e5da5Sopenharmony_ciOpSource HLSL 500
447fd4e5da5Sopenharmony_ciOpName %MainPs "MainPs"
448fd4e5da5Sopenharmony_ciOpName %g_tColor "g_tColor"
449fd4e5da5Sopenharmony_ciOpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
450fd4e5da5Sopenharmony_ciOpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
451fd4e5da5Sopenharmony_ciOpName %_ ""
452fd4e5da5Sopenharmony_ciOpName %i_vTextureCoords "i.vTextureCoords"
453fd4e5da5Sopenharmony_ciOpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
454fd4e5da5Sopenharmony_ciOpDecorate %g_tColor DescriptorSet 4
455fd4e5da5Sopenharmony_ciOpDecorate %g_tColor Binding 11
456fd4e5da5Sopenharmony_ciOpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
457fd4e5da5Sopenharmony_ciOpDecorate %PerViewConstantBuffer_t Block
458fd4e5da5Sopenharmony_ciOpDecorate %i_vTextureCoords Location 0
459fd4e5da5Sopenharmony_ciOpDecorate %_entryPointOutput_vColor Location 0
460fd4e5da5Sopenharmony_ci)" + kImportDeco + R"(
461fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
462fd4e5da5Sopenharmony_ci%void = OpTypeVoid
463fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
464fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
465fd4e5da5Sopenharmony_ci%v2float = OpTypeVector %float 2
466fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
467fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
468fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
469fd4e5da5Sopenharmony_ci%20 = OpTypeImage %float 2D 0 0 0 1 Unknown
470fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
471fd4e5da5Sopenharmony_ci%uint_128 = OpConstant %uint 128
472fd4e5da5Sopenharmony_ci%39 = OpTypeSampledImage %20
473fd4e5da5Sopenharmony_ci%_arr_39_uint_128 = OpTypeArray %39 %uint_128
474fd4e5da5Sopenharmony_ci%_ptr_UniformConstant__arr_39_uint_128 = OpTypePointer UniformConstant %_arr_39_uint_128
475fd4e5da5Sopenharmony_ci%g_tColor = OpVariable %_ptr_UniformConstant__arr_39_uint_128 UniformConstant
476fd4e5da5Sopenharmony_ci%PerViewConstantBuffer_t = OpTypeStruct %uint
477fd4e5da5Sopenharmony_ci%_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
478fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
479fd4e5da5Sopenharmony_ci%_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
480fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_39 = OpTypePointer UniformConstant %39
481fd4e5da5Sopenharmony_ci%_ptr_Input_v2float = OpTypePointer Input %v2float
482fd4e5da5Sopenharmony_ci%i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
483fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
484fd4e5da5Sopenharmony_ci%_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
485fd4e5da5Sopenharmony_ci;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
486fd4e5da5Sopenharmony_ci;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
487fd4e5da5Sopenharmony_ci;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
488fd4e5da5Sopenharmony_ci)";
489fd4e5da5Sopenharmony_ci
490fd4e5da5Sopenharmony_ci  const std::string main_func = R"(
491fd4e5da5Sopenharmony_ci%MainPs = OpFunction %void None %3
492fd4e5da5Sopenharmony_ci%5 = OpLabel
493fd4e5da5Sopenharmony_ci%53 = OpLoad %v2float %i_vTextureCoords
494fd4e5da5Sopenharmony_ci%63 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
495fd4e5da5Sopenharmony_ci%64 = OpLoad %uint %63
496fd4e5da5Sopenharmony_ci%65 = OpAccessChain %_ptr_UniformConstant_39 %g_tColor %64
497fd4e5da5Sopenharmony_ci%66 = OpLoad %39 %65
498fd4e5da5Sopenharmony_ci%71 = OpImageSampleImplicitLod %v4float %66 %53
499fd4e5da5Sopenharmony_ciOpStore %_entryPointOutput_vColor %71
500fd4e5da5Sopenharmony_ci;CHECK-NOT: %71 = OpImageSampleImplicitLod %v4float %66 %53
501fd4e5da5Sopenharmony_ci;CHECK-NOT: OpStore %_entryPointOutput_vColor %71
502fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord
503fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}}
504fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
505fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
506fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0
507fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_50 {{%\w+}} %uint_4 %uint_11 %64 %uint_0
508fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
509fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
510fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
511fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %39 %65
512fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpImageSampleImplicitLod %v4float {{%\w+}} %53
513fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
514fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
515fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
516fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
517fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}}
518fd4e5da5Sopenharmony_ci;CHECK: OpStore %_entryPointOutput_vColor {{%\w+}}
519fd4e5da5Sopenharmony_ciOpReturn
520fd4e5da5Sopenharmony_ciOpFunctionEnd
521fd4e5da5Sopenharmony_ci)";
522fd4e5da5Sopenharmony_ci  // clang-format on
523fd4e5da5Sopenharmony_ci
524fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
525fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(defs + kImportStub + main_func,
526fd4e5da5Sopenharmony_ci                                               true, 23u);
527fd4e5da5Sopenharmony_ci}
528fd4e5da5Sopenharmony_ci
529fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest, InstrumentImageWrite) {
530fd4e5da5Sopenharmony_ci  // This test verifies that the pass will correctly instrument shader
531fd4e5da5Sopenharmony_ci  // doing bindless image write. This test was created by editing the SPIR-V
532fd4e5da5Sopenharmony_ci  // from the Simple test.
533fd4e5da5Sopenharmony_ci
534fd4e5da5Sopenharmony_ci  // clang-format off
535fd4e5da5Sopenharmony_ci  const std::string defs = R"(
536fd4e5da5Sopenharmony_ciOpCapability Shader
537fd4e5da5Sopenharmony_ciOpCapability StorageImageWriteWithoutFormat
538fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
539fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
540fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
541fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
542fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
543fd4e5da5Sopenharmony_ciOpExecutionMode %MainPs OriginUpperLeft
544fd4e5da5Sopenharmony_ciOpSource HLSL 500
545fd4e5da5Sopenharmony_ciOpName %MainPs "MainPs"
546fd4e5da5Sopenharmony_ciOpName %g_tColor "g_tColor"
547fd4e5da5Sopenharmony_ciOpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
548fd4e5da5Sopenharmony_ciOpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
549fd4e5da5Sopenharmony_ciOpName %_ ""
550fd4e5da5Sopenharmony_ciOpName %i_vTextureCoords "i.vTextureCoords"
551fd4e5da5Sopenharmony_ciOpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
552fd4e5da5Sopenharmony_ciOpDecorate %g_tColor DescriptorSet 30
553fd4e5da5Sopenharmony_ciOpDecorate %g_tColor Binding 2
554fd4e5da5Sopenharmony_ciOpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
555fd4e5da5Sopenharmony_ciOpDecorate %PerViewConstantBuffer_t Block
556fd4e5da5Sopenharmony_ciOpDecorate %i_vTextureCoords Location 0
557fd4e5da5Sopenharmony_ciOpDecorate %_entryPointOutput_vColor Location 0
558fd4e5da5Sopenharmony_ci)" + kImportDeco + R"(
559fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
560fd4e5da5Sopenharmony_ci%void = OpTypeVoid
561fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
562fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
563fd4e5da5Sopenharmony_ci%v2float = OpTypeVector %float 2
564fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
565fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
566fd4e5da5Sopenharmony_ci%v2int = OpTypeVector %int 2
567fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
568fd4e5da5Sopenharmony_ci%20 = OpTypeImage %float 2D 0 0 0 0 Unknown
569fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
570fd4e5da5Sopenharmony_ci%uint_128 = OpConstant %uint 128
571fd4e5da5Sopenharmony_ci%80 = OpConstantNull %v4float
572fd4e5da5Sopenharmony_ci%_arr_20_uint_128 = OpTypeArray %20 %uint_128
573fd4e5da5Sopenharmony_ci%_ptr_UniformConstant__arr_20_uint_128 = OpTypePointer UniformConstant %_arr_20_uint_128
574fd4e5da5Sopenharmony_ci%g_tColor = OpVariable %_ptr_UniformConstant__arr_20_uint_128 UniformConstant
575fd4e5da5Sopenharmony_ci%PerViewConstantBuffer_t = OpTypeStruct %uint
576fd4e5da5Sopenharmony_ci%_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
577fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
578fd4e5da5Sopenharmony_ci%_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
579fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_20 = OpTypePointer UniformConstant %20
580fd4e5da5Sopenharmony_ci%_ptr_Input_v2int = OpTypePointer Input %v2int
581fd4e5da5Sopenharmony_ci%i_vTextureCoords = OpVariable %_ptr_Input_v2int Input
582fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
583fd4e5da5Sopenharmony_ci%_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
584fd4e5da5Sopenharmony_ci;CHECK: %v4uint = OpTypeVector %uint 4
585fd4e5da5Sopenharmony_ci;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
586fd4e5da5Sopenharmony_ci;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
587fd4e5da5Sopenharmony_ci)";
588fd4e5da5Sopenharmony_ci
589fd4e5da5Sopenharmony_ci  const std::string main_func = R"(
590fd4e5da5Sopenharmony_ci%MainPs = OpFunction %void None %3
591fd4e5da5Sopenharmony_ci%5 = OpLabel
592fd4e5da5Sopenharmony_ci%53 = OpLoad %v2int %i_vTextureCoords
593fd4e5da5Sopenharmony_ci%63 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
594fd4e5da5Sopenharmony_ci%64 = OpLoad %uint %63
595fd4e5da5Sopenharmony_ci%65 = OpAccessChain %_ptr_UniformConstant_20 %g_tColor %64
596fd4e5da5Sopenharmony_ci%66 = OpLoad %20 %65
597fd4e5da5Sopenharmony_ciOpImageWrite %66 %53 %80
598fd4e5da5Sopenharmony_ciOpStore %_entryPointOutput_vColor %80
599fd4e5da5Sopenharmony_ci;CHECK-NOT: OpImageWrite %66 %53 %80
600fd4e5da5Sopenharmony_ci;CHECK-NOT: OpStore %_entryPointOutput_vColor %80
601fd4e5da5Sopenharmony_ci;CHECK: %32 = OpLoad %16 %31
602fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord
603fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}}
604fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
605fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
606fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0
607fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_52 {{%\w+}} %uint_30 %uint_2 %30 %uint_0
608fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
609fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
610fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
611fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %16 %31
612fd4e5da5Sopenharmony_ci;CHECK: OpImageWrite {{%\w+}} %28 %19
613fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
614fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
615fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
616fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
617fd4e5da5Sopenharmony_ci;CHECK: OpStore %_entryPointOutput_vColor %19
618fd4e5da5Sopenharmony_ciOpReturn
619fd4e5da5Sopenharmony_ciOpFunctionEnd
620fd4e5da5Sopenharmony_ci)";
621fd4e5da5Sopenharmony_ci  // clang-format on
622fd4e5da5Sopenharmony_ci
623fd4e5da5Sopenharmony_ci  // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
624fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(defs + kImportStub + main_func,
625fd4e5da5Sopenharmony_ci                                               true, 23u);
626fd4e5da5Sopenharmony_ci}
627fd4e5da5Sopenharmony_ci
628fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest, InstrumentVertexSimple) {
629fd4e5da5Sopenharmony_ci  // This test verifies that the pass will correctly instrument shader
630fd4e5da5Sopenharmony_ci  // doing bindless image write. This test was created by editing the SPIR-V
631fd4e5da5Sopenharmony_ci  // from the Simple test.
632fd4e5da5Sopenharmony_ci
633fd4e5da5Sopenharmony_ci  // clang-format off
634fd4e5da5Sopenharmony_ci  const std::string defs = R"(
635fd4e5da5Sopenharmony_ciOpCapability Shader
636fd4e5da5Sopenharmony_ciOpCapability Sampled1D
637fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
638fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
639fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
640fd4e5da5Sopenharmony_ciOpEntryPoint Vertex %main "main" %_ %coords2D
641fd4e5da5Sopenharmony_ciOpSource GLSL 450
642fd4e5da5Sopenharmony_ciOpName %main "main"
643fd4e5da5Sopenharmony_ciOpName %lod "lod"
644fd4e5da5Sopenharmony_ciOpName %coords1D "coords1D"
645fd4e5da5Sopenharmony_ciOpName %gl_PerVertex "gl_PerVertex"
646fd4e5da5Sopenharmony_ciOpMemberName %gl_PerVertex 0 "gl_Position"
647fd4e5da5Sopenharmony_ciOpMemberName %gl_PerVertex 1 "gl_PointSize"
648fd4e5da5Sopenharmony_ciOpMemberName %gl_PerVertex 2 "gl_ClipDistance"
649fd4e5da5Sopenharmony_ciOpMemberName %gl_PerVertex 3 "gl_CullDistance"
650fd4e5da5Sopenharmony_ciOpName %_ ""
651fd4e5da5Sopenharmony_ciOpName %texSampler1D "texSampler1D"
652fd4e5da5Sopenharmony_ciOpName %foo "foo"
653fd4e5da5Sopenharmony_ciOpMemberName %foo 0 "g_idx"
654fd4e5da5Sopenharmony_ciOpName %__0 ""
655fd4e5da5Sopenharmony_ciOpName %coords2D "coords2D"
656fd4e5da5Sopenharmony_ci)" + kImportDeco + R"(
657fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %gl_VertexIndex BuiltIn VertexIndex
658fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %gl_InstanceIndex BuiltIn InstanceIndex
659fd4e5da5Sopenharmony_ciOpMemberDecorate %gl_PerVertex 0 BuiltIn Position
660fd4e5da5Sopenharmony_ciOpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
661fd4e5da5Sopenharmony_ciOpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
662fd4e5da5Sopenharmony_ciOpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
663fd4e5da5Sopenharmony_ciOpDecorate %gl_PerVertex Block
664fd4e5da5Sopenharmony_ciOpDecorate %texSampler1D DescriptorSet 2
665fd4e5da5Sopenharmony_ciOpDecorate %texSampler1D Binding 13
666fd4e5da5Sopenharmony_ciOpMemberDecorate %foo 0 Offset 0
667fd4e5da5Sopenharmony_ciOpDecorate %foo Block
668fd4e5da5Sopenharmony_ciOpDecorate %__0 DescriptorSet 7
669fd4e5da5Sopenharmony_ciOpDecorate %__0 Binding 5
670fd4e5da5Sopenharmony_ciOpDecorate %coords2D Location 0
671fd4e5da5Sopenharmony_ci%void = OpTypeVoid
672fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
673fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
674fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
675fd4e5da5Sopenharmony_ci%float_3 = OpConstant %float 3
676fd4e5da5Sopenharmony_ci%float_1_78900003 = OpConstant %float 1.78900003
677fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
678fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
679fd4e5da5Sopenharmony_ci%uint_1 = OpConstant %uint 1
680fd4e5da5Sopenharmony_ci%_arr_float_uint_1 = OpTypeArray %float %uint_1
681fd4e5da5Sopenharmony_ci%gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
682fd4e5da5Sopenharmony_ci%_ptr_Output_gl_PerVertex = OpTypePointer Output %gl_PerVertex
683fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_Output_gl_PerVertex Output
684fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
685fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
686fd4e5da5Sopenharmony_ci%21 = OpTypeImage %float 1D 0 0 0 1 Unknown
687fd4e5da5Sopenharmony_ci%22 = OpTypeSampledImage %21
688fd4e5da5Sopenharmony_ci%uint_128 = OpConstant %uint 128
689fd4e5da5Sopenharmony_ci%_arr_22_uint_128 = OpTypeArray %22 %uint_128
690fd4e5da5Sopenharmony_ci%_ptr_UniformConstant__arr_22_uint_128 = OpTypePointer UniformConstant %_arr_22_uint_128
691fd4e5da5Sopenharmony_ci%texSampler1D = OpVariable %_ptr_UniformConstant__arr_22_uint_128 UniformConstant
692fd4e5da5Sopenharmony_ci%foo = OpTypeStruct %int
693fd4e5da5Sopenharmony_ci%_ptr_Uniform_foo = OpTypePointer Uniform %foo
694fd4e5da5Sopenharmony_ci%__0 = OpVariable %_ptr_Uniform_foo Uniform
695fd4e5da5Sopenharmony_ci%_ptr_Uniform_int = OpTypePointer Uniform %int
696fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_22 = OpTypePointer UniformConstant %22
697fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
698fd4e5da5Sopenharmony_ci%v2float = OpTypeVector %float 2
699fd4e5da5Sopenharmony_ci%_ptr_Input_v2float = OpTypePointer Input %v2float
700fd4e5da5Sopenharmony_ci%coords2D = OpVariable %_ptr_Input_v2float Input
701fd4e5da5Sopenharmony_ci;CHECK: %_ptr_Input_uint = OpTypePointer Input %uint
702fd4e5da5Sopenharmony_ci;CHECK: %gl_VertexIndex = OpVariable %_ptr_Input_uint Input
703fd4e5da5Sopenharmony_ci;CHECK: %gl_InstanceIndex = OpVariable %_ptr_Input_uint Input
704fd4e5da5Sopenharmony_ci;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
705fd4e5da5Sopenharmony_ci)";
706fd4e5da5Sopenharmony_ci
707fd4e5da5Sopenharmony_ci  const std::string main_func = R"(
708fd4e5da5Sopenharmony_ci%main = OpFunction %void None %3
709fd4e5da5Sopenharmony_ci%5 = OpLabel
710fd4e5da5Sopenharmony_ci%lod = OpVariable %_ptr_Function_float Function
711fd4e5da5Sopenharmony_ci%coords1D = OpVariable %_ptr_Function_float Function
712fd4e5da5Sopenharmony_ciOpStore %lod %float_3
713fd4e5da5Sopenharmony_ciOpStore %coords1D %float_1_78900003
714fd4e5da5Sopenharmony_ci%31 = OpAccessChain %_ptr_Uniform_int %__0 %int_0
715fd4e5da5Sopenharmony_ci%32 = OpLoad %int %31
716fd4e5da5Sopenharmony_ci%34 = OpAccessChain %_ptr_UniformConstant_22 %texSampler1D %32
717fd4e5da5Sopenharmony_ci%35 = OpLoad %22 %34
718fd4e5da5Sopenharmony_ci%36 = OpLoad %float %coords1D
719fd4e5da5Sopenharmony_ci%37 = OpLoad %float %lod
720fd4e5da5Sopenharmony_ci%38 = OpImageSampleExplicitLod %v4float %35 %36 Lod %37
721fd4e5da5Sopenharmony_ci%40 = OpAccessChain %_ptr_Output_v4float %_ %int_0
722fd4e5da5Sopenharmony_ciOpStore %40 %38
723fd4e5da5Sopenharmony_ci;CHECK-NOT: %38 = OpImageSampleExplicitLod %v4float %35 %36 Lod %37
724fd4e5da5Sopenharmony_ci;CHECK-NOT: %40 = OpAccessChain %_ptr_Output_v4float %_ %int_0
725fd4e5da5Sopenharmony_ci;CHECK-NOT: OpStore %40 %38
726fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %uint %gl_VertexIndex
727fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %uint %gl_InstanceIndex
728fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_0 {{%\w+}} {{%\w+}} %uint_0
729fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_70 {{%\w+}} %uint_7 %uint_5 %uint_0 {{%\w+}}
730fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
731fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
732fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
733fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %int {{%\w+}}
734fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
735fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
736fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
737fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
738fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpPhi %int {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}}
739fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpAccessChain %_ptr_UniformConstant_25 %texSampler1D {{%\w+}}
740fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad {{%\w+}} {{%\w+}}
741fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %float %coords1D
742fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %float %lod
743fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %uint %gl_VertexIndex
744fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %uint %gl_InstanceIndex
745fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_0 {{%\w+}} {{%\w+}} %uint_0
746fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %uint {{%\w+}}
747fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_75 {{%\w+}} %uint_2 %uint_13 {{%\w+}} %uint_0
748fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
749fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
750fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
751fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %25 %38
752fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpImageSampleExplicitLod %v4float {{%\w+}} %40 Lod %41
753fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
754fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
755fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
756fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
757fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}}
758fd4e5da5Sopenharmony_ci;CHECK: %43 = OpAccessChain %_ptr_Output_v4float %_ %int_0
759fd4e5da5Sopenharmony_ci;CHECK: OpStore %43 {{%\w+}}
760fd4e5da5Sopenharmony_ciOpReturn
761fd4e5da5Sopenharmony_ciOpFunctionEnd
762fd4e5da5Sopenharmony_ci)";
763fd4e5da5Sopenharmony_ci  // clang-format on
764fd4e5da5Sopenharmony_ci
765fd4e5da5Sopenharmony_ci  // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
766fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(defs + kImportStub + main_func,
767fd4e5da5Sopenharmony_ci                                               true, 23u);
768fd4e5da5Sopenharmony_ci}
769fd4e5da5Sopenharmony_ci
770fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest, InstrumentTeseSimple) {
771fd4e5da5Sopenharmony_ci  // This test verifies that the pass will correctly instrument tessellation
772fd4e5da5Sopenharmony_ci  // evaluation shader doing bindless buffer load.
773fd4e5da5Sopenharmony_ci  //
774fd4e5da5Sopenharmony_ci  // clang-format off
775fd4e5da5Sopenharmony_ci  //
776fd4e5da5Sopenharmony_ci  // #version 450
777fd4e5da5Sopenharmony_ci  // #extension GL_EXT_nonuniform_qualifier : enable
778fd4e5da5Sopenharmony_ci  //
779fd4e5da5Sopenharmony_ci  // layout(std140, set = 9, binding = 1) uniform ufoo { uint index; } uniform_index_buffer;
780fd4e5da5Sopenharmony_ci  //
781fd4e5da5Sopenharmony_ci  // layout(set = 9, binding = 2) buffer bfoo { vec4 val; } adds[11];
782fd4e5da5Sopenharmony_ci  //
783fd4e5da5Sopenharmony_ci  // layout(triangles, equal_spacing, cw) in;
784fd4e5da5Sopenharmony_ci  //
785fd4e5da5Sopenharmony_ci  // void main() {
786fd4e5da5Sopenharmony_ci  //   gl_Position = adds[uniform_index_buffer.index].val;
787fd4e5da5Sopenharmony_ci  // }
788fd4e5da5Sopenharmony_ci  //
789fd4e5da5Sopenharmony_ci
790fd4e5da5Sopenharmony_ci  const std::string defs = R"(
791fd4e5da5Sopenharmony_ciOpCapability Tessellation
792fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
793fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
794fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
795fd4e5da5Sopenharmony_ciOpEntryPoint TessellationEvaluation %main "main" %_
796fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint TessellationEvaluation %main "main" %_ %gl_PrimitiveID %gl_TessCoord
797fd4e5da5Sopenharmony_ciOpExecutionMode %main Triangles
798fd4e5da5Sopenharmony_ciOpExecutionMode %main SpacingEqual
799fd4e5da5Sopenharmony_ciOpExecutionMode %main VertexOrderCw
800fd4e5da5Sopenharmony_ciOpSource GLSL 450
801fd4e5da5Sopenharmony_ciOpSourceExtension "GL_EXT_nonuniform_qualifier"
802fd4e5da5Sopenharmony_ciOpName %main "main"
803fd4e5da5Sopenharmony_ciOpName %gl_PerVertex "gl_PerVertex"
804fd4e5da5Sopenharmony_ciOpMemberName %gl_PerVertex 0 "gl_Position"
805fd4e5da5Sopenharmony_ciOpMemberName %gl_PerVertex 1 "gl_PointSize"
806fd4e5da5Sopenharmony_ciOpMemberName %gl_PerVertex 2 "gl_ClipDistance"
807fd4e5da5Sopenharmony_ciOpMemberName %gl_PerVertex 3 "gl_CullDistance"
808fd4e5da5Sopenharmony_ciOpName %_ ""
809fd4e5da5Sopenharmony_ciOpName %bfoo "bfoo"
810fd4e5da5Sopenharmony_ciOpMemberName %bfoo 0 "val"
811fd4e5da5Sopenharmony_ciOpName %adds "adds"
812fd4e5da5Sopenharmony_ciOpName %ufoo "ufoo"
813fd4e5da5Sopenharmony_ciOpMemberName %ufoo 0 "index"
814fd4e5da5Sopenharmony_ciOpName %uniform_index_buffer "uniform_index_buffer"
815fd4e5da5Sopenharmony_ciOpMemberDecorate %gl_PerVertex 0 BuiltIn Position
816fd4e5da5Sopenharmony_ciOpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
817fd4e5da5Sopenharmony_ciOpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
818fd4e5da5Sopenharmony_ciOpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
819fd4e5da5Sopenharmony_ciOpDecorate %gl_PerVertex Block
820fd4e5da5Sopenharmony_ciOpMemberDecorate %bfoo 0 Offset 0
821fd4e5da5Sopenharmony_ciOpDecorate %bfoo Block
822fd4e5da5Sopenharmony_ciOpDecorate %adds DescriptorSet 9
823fd4e5da5Sopenharmony_ciOpDecorate %adds Binding 1
824fd4e5da5Sopenharmony_ciOpMemberDecorate %ufoo 0 Offset 0
825fd4e5da5Sopenharmony_ciOpDecorate %ufoo Block
826fd4e5da5Sopenharmony_ciOpDecorate %uniform_index_buffer DescriptorSet 9
827fd4e5da5Sopenharmony_ciOpDecorate %uniform_index_buffer Binding 2
828fd4e5da5Sopenharmony_ci)" + kImportDeco + R"(
829fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %gl_PrimitiveID BuiltIn PrimitiveId
830fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %gl_TessCoord BuiltIn TessCoord
831fd4e5da5Sopenharmony_ci%void = OpTypeVoid
832fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
833fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
834fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
835fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
836fd4e5da5Sopenharmony_ci%uint_1 = OpConstant %uint 1
837fd4e5da5Sopenharmony_ci%_arr_float_uint_1 = OpTypeArray %float %uint_1
838fd4e5da5Sopenharmony_ci%gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
839fd4e5da5Sopenharmony_ci%_ptr_Output_gl_PerVertex = OpTypePointer Output %gl_PerVertex
840fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_Output_gl_PerVertex Output
841fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
842fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
843fd4e5da5Sopenharmony_ci%bfoo = OpTypeStruct %v4float
844fd4e5da5Sopenharmony_ci%uint_11 = OpConstant %uint 11
845fd4e5da5Sopenharmony_ci%_arr_bfoo_uint_11 = OpTypeArray %bfoo %uint_11
846fd4e5da5Sopenharmony_ci%_ptr_StorageBuffer__arr_bfoo_uint_11 = OpTypePointer StorageBuffer %_arr_bfoo_uint_11
847fd4e5da5Sopenharmony_ci%adds = OpVariable %_ptr_StorageBuffer__arr_bfoo_uint_11 StorageBuffer
848fd4e5da5Sopenharmony_ci%ufoo = OpTypeStruct %uint
849fd4e5da5Sopenharmony_ci%_ptr_Uniform_ufoo = OpTypePointer Uniform %ufoo
850fd4e5da5Sopenharmony_ci%uniform_index_buffer = OpVariable %_ptr_Uniform_ufoo Uniform
851fd4e5da5Sopenharmony_ci%_ptr_Uniform_uint = OpTypePointer Uniform %uint
852fd4e5da5Sopenharmony_ci%_ptr_StorageBuffer_v4float = OpTypePointer StorageBuffer %v4float
853fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
854fd4e5da5Sopenharmony_ci;CHECK: %_ptr_Input_uint = OpTypePointer Input %uint
855fd4e5da5Sopenharmony_ci;CHECK: %gl_PrimitiveID = OpVariable %_ptr_Input_uint Input
856fd4e5da5Sopenharmony_ci;CHECK: %v3float = OpTypeVector %float 3
857fd4e5da5Sopenharmony_ci;CHECK: %_ptr_Input_v3float = OpTypePointer Input %v3float
858fd4e5da5Sopenharmony_ci;CHECK: %gl_TessCoord = OpVariable %_ptr_Input_v3float Input
859fd4e5da5Sopenharmony_ci;CHECK: %v3uint = OpTypeVector %uint 3
860fd4e5da5Sopenharmony_ci;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
861fd4e5da5Sopenharmony_ci)";
862fd4e5da5Sopenharmony_ci
863fd4e5da5Sopenharmony_ci  const std::string main_func =
864fd4e5da5Sopenharmony_ci      R"(
865fd4e5da5Sopenharmony_ci%main = OpFunction %void None %3
866fd4e5da5Sopenharmony_ci%5 = OpLabel
867fd4e5da5Sopenharmony_ci%25 = OpAccessChain %_ptr_Uniform_uint %uniform_index_buffer %int_0
868fd4e5da5Sopenharmony_ci%26 = OpLoad %uint %25
869fd4e5da5Sopenharmony_ci%28 = OpAccessChain %_ptr_StorageBuffer_v4float %adds %26 %int_0
870fd4e5da5Sopenharmony_ci%29 = OpLoad %v4float %28
871fd4e5da5Sopenharmony_ci;CHECK-NOT: %29 = OpLoad %v4float %28
872fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %uint %gl_PrimitiveID
873fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v3float %gl_TessCoord
874fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %v3uint {{%\w+}}
875fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
876fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
877fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_2 {{%\w+}} {{%\w+}} {{%\w+}}
878fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_62 {{%\w+}} %uint_9 %uint_2 %uint_0 {{%\w+}}
879fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
880fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
881fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
882fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %uint %27
883fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
884fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
885fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
886fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
887fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpPhi %uint {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}}
888fd4e5da5Sopenharmony_ci%31 = OpAccessChain %_ptr_Output_v4float %_ %int_0
889fd4e5da5Sopenharmony_ciOpStore %31 %29
890fd4e5da5Sopenharmony_ci;CHECK-NOT: OpStore %31 %29
891fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %uint %gl_PrimitiveID
892fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v3float %gl_TessCoord
893fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %v3uint {{%\w+}}
894fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
895fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
896fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_2 {{%\w+}} {{%\w+}} {{%\w+}}
897fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_64 {{%\w+}} %uint_9 %uint_1 {{%\w+}} {{%\w+}}
898fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
899fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
900fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
901fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v4float %29
902fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
903fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
904fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
905fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
906fd4e5da5Sopenharmony_ci;CHECK: [[phi_result:%\w+]] = OpPhi {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}}
907fd4e5da5Sopenharmony_ci;CHECK: %31 = OpAccessChain %_ptr_Output_v4float %_ %int_0
908fd4e5da5Sopenharmony_ci;CHECK: OpStore %31 [[phi_result]]
909fd4e5da5Sopenharmony_ciOpReturn
910fd4e5da5Sopenharmony_ciOpFunctionEnd
911fd4e5da5Sopenharmony_ci)";
912fd4e5da5Sopenharmony_ci  // clang-format on
913fd4e5da5Sopenharmony_ci
914fd4e5da5Sopenharmony_ci  // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
915fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(defs + kImportStub + main_func,
916fd4e5da5Sopenharmony_ci                                               true, 23u);
917fd4e5da5Sopenharmony_ci}
918fd4e5da5Sopenharmony_ci
919fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest, InstrumentTesc) {
920fd4e5da5Sopenharmony_ci  // This test verifies that the pass will correctly instrument tessellation
921fd4e5da5Sopenharmony_ci  // control shader
922fd4e5da5Sopenharmony_ci  //
923fd4e5da5Sopenharmony_ci  // clang-format off
924fd4e5da5Sopenharmony_ci  //
925fd4e5da5Sopenharmony_ci  // #version 450
926fd4e5da5Sopenharmony_ci  // layout(vertices = 3) out;
927fd4e5da5Sopenharmony_ci  // layout(set = 0, binding = 0) uniform texture1D _77;
928fd4e5da5Sopenharmony_ci  // layout(set = 0, binding = 1) uniform sampler _78;
929fd4e5da5Sopenharmony_ci
930fd4e5da5Sopenharmony_ci  // layout(location = 1) flat in int _3[];
931fd4e5da5Sopenharmony_ci  // layout(location = 0) out vec4 _5[3];
932fd4e5da5Sopenharmony_ci
933fd4e5da5Sopenharmony_ci  // void main()
934fd4e5da5Sopenharmony_ci  // {
935fd4e5da5Sopenharmony_ci  //     float param;
936fd4e5da5Sopenharmony_ci  //     if (_3[gl_InvocationID] == 0)
937fd4e5da5Sopenharmony_ci  //     {
938fd4e5da5Sopenharmony_ci  //         param = 0.0234375;
939fd4e5da5Sopenharmony_ci  //     }
940fd4e5da5Sopenharmony_ci  //     else
941fd4e5da5Sopenharmony_ci  //     {
942fd4e5da5Sopenharmony_ci  //         param = 1.0156199932098388671875;
943fd4e5da5Sopenharmony_ci  //     }
944fd4e5da5Sopenharmony_ci  //     _5[gl_InvocationID] = textureLod(sampler1D(_77, _78), param, 0.0);
945fd4e5da5Sopenharmony_ci  //     vec4 _203;
946fd4e5da5Sopenharmony_ci  //     if (gl_InvocationID == 0)
947fd4e5da5Sopenharmony_ci  //     {
948fd4e5da5Sopenharmony_ci  //         _203 = gl_in[0].gl_Position;
949fd4e5da5Sopenharmony_ci  //     }
950fd4e5da5Sopenharmony_ci  //     else
951fd4e5da5Sopenharmony_ci  //     {
952fd4e5da5Sopenharmony_ci  //         _203 = gl_in[2].gl_Position;
953fd4e5da5Sopenharmony_ci  //     }
954fd4e5da5Sopenharmony_ci  //     gl_out[gl_InvocationID].gl_Position = _203;
955fd4e5da5Sopenharmony_ci  //     gl_TessLevelInner[0] = 2.7999999523162841796875;
956fd4e5da5Sopenharmony_ci  //     gl_TessLevelInner[1] = 2.7999999523162841796875;
957fd4e5da5Sopenharmony_ci  //     gl_TessLevelOuter[0] = 2.7999999523162841796875;
958fd4e5da5Sopenharmony_ci  //     gl_TessLevelOuter[1] = 2.7999999523162841796875;
959fd4e5da5Sopenharmony_ci  //     gl_TessLevelOuter[2] = 2.7999999523162841796875;
960fd4e5da5Sopenharmony_ci  //     gl_TessLevelOuter[3] = 2.7999999523162841796875;
961fd4e5da5Sopenharmony_ci  // }
962fd4e5da5Sopenharmony_ci  //
963fd4e5da5Sopenharmony_ci  // clang-format on
964fd4e5da5Sopenharmony_ci  //
965fd4e5da5Sopenharmony_ci  //
966fd4e5da5Sopenharmony_ci
967fd4e5da5Sopenharmony_ci  // clang-format off
968fd4e5da5Sopenharmony_ci  const std::string defs = R"(
969fd4e5da5Sopenharmony_ciOpCapability Tessellation
970fd4e5da5Sopenharmony_ciOpCapability Sampled1D
971fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
972fd4e5da5Sopenharmony_ci;CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
973fd4e5da5Sopenharmony_ci;CHECK: OpExtension "SPV_KHR_physical_storage_buffer"
974fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
975fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
976fd4e5da5Sopenharmony_ci;CHECK: OpMemoryModel PhysicalStorageBuffer64 GLSL450
977fd4e5da5Sopenharmony_ciOpEntryPoint TessellationControl %main "main" %_3 %gl_InvocationID %_5 %gl_in %gl_out %gl_TessLevelInner %gl_TessLevelOuter
978fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint TessellationControl %main "main" %_3 %gl_InvocationID %_5 %gl_in %gl_out %gl_TessLevelInner %gl_TessLevelOuter %gl_PrimitiveID
979fd4e5da5Sopenharmony_ciOpExecutionMode %main OutputVertices 3
980fd4e5da5Sopenharmony_ciOpSource GLSL 450
981fd4e5da5Sopenharmony_ciOpName %main "main"
982fd4e5da5Sopenharmony_ciOpName %_3 "_3"
983fd4e5da5Sopenharmony_ciOpName %gl_InvocationID "gl_InvocationID"
984fd4e5da5Sopenharmony_ciOpName %param "param"
985fd4e5da5Sopenharmony_ciOpName %_5 "_5"
986fd4e5da5Sopenharmony_ciOpName %_77 "_77"
987fd4e5da5Sopenharmony_ciOpName %_78 "_78"
988fd4e5da5Sopenharmony_ciOpName %_203 "_203"
989fd4e5da5Sopenharmony_ciOpName %gl_PerVertex "gl_PerVertex"
990fd4e5da5Sopenharmony_ciOpMemberName %gl_PerVertex 0 "gl_Position"
991fd4e5da5Sopenharmony_ciOpMemberName %gl_PerVertex 1 "gl_PointSize"
992fd4e5da5Sopenharmony_ciOpMemberName %gl_PerVertex 2 "gl_ClipDistance"
993fd4e5da5Sopenharmony_ciOpMemberName %gl_PerVertex 3 "gl_CullDistance"
994fd4e5da5Sopenharmony_ciOpName %gl_in "gl_in"
995fd4e5da5Sopenharmony_ciOpName %gl_PerVertex_0 "gl_PerVertex"
996fd4e5da5Sopenharmony_ciOpMemberName %gl_PerVertex_0 0 "gl_Position"
997fd4e5da5Sopenharmony_ciOpMemberName %gl_PerVertex_0 1 "gl_PointSize"
998fd4e5da5Sopenharmony_ciOpMemberName %gl_PerVertex_0 2 "gl_ClipDistance"
999fd4e5da5Sopenharmony_ciOpMemberName %gl_PerVertex_0 3 "gl_CullDistance"
1000fd4e5da5Sopenharmony_ciOpName %gl_out "gl_out"
1001fd4e5da5Sopenharmony_ciOpName %gl_TessLevelInner "gl_TessLevelInner"
1002fd4e5da5Sopenharmony_ciOpName %gl_TessLevelOuter "gl_TessLevelOuter"
1003fd4e5da5Sopenharmony_ciOpDecorate %_3 Flat
1004fd4e5da5Sopenharmony_ciOpDecorate %_3 Location 1
1005fd4e5da5Sopenharmony_ciOpDecorate %gl_InvocationID BuiltIn InvocationId
1006fd4e5da5Sopenharmony_ciOpDecorate %_5 Location 0
1007fd4e5da5Sopenharmony_ciOpDecorate %_77 DescriptorSet 0
1008fd4e5da5Sopenharmony_ciOpDecorate %_77 Binding 0
1009fd4e5da5Sopenharmony_ciOpDecorate %_78 DescriptorSet 0
1010fd4e5da5Sopenharmony_ciOpDecorate %_78 Binding 1
1011fd4e5da5Sopenharmony_ciOpMemberDecorate %gl_PerVertex 0 BuiltIn Position
1012fd4e5da5Sopenharmony_ciOpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
1013fd4e5da5Sopenharmony_ciOpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
1014fd4e5da5Sopenharmony_ciOpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
1015fd4e5da5Sopenharmony_ciOpDecorate %gl_PerVertex Block
1016fd4e5da5Sopenharmony_ciOpMemberDecorate %gl_PerVertex_0 0 BuiltIn Position
1017fd4e5da5Sopenharmony_ciOpMemberDecorate %gl_PerVertex_0 1 BuiltIn PointSize
1018fd4e5da5Sopenharmony_ciOpMemberDecorate %gl_PerVertex_0 2 BuiltIn ClipDistance
1019fd4e5da5Sopenharmony_ciOpMemberDecorate %gl_PerVertex_0 3 BuiltIn CullDistance
1020fd4e5da5Sopenharmony_ciOpDecorate %gl_PerVertex_0 Block
1021fd4e5da5Sopenharmony_ciOpDecorate %gl_TessLevelInner Patch
1022fd4e5da5Sopenharmony_ciOpDecorate %gl_TessLevelInner BuiltIn TessLevelInner
1023fd4e5da5Sopenharmony_ciOpDecorate %gl_TessLevelOuter Patch
1024fd4e5da5Sopenharmony_ciOpDecorate %gl_TessLevelOuter BuiltIn TessLevelOuter
1025fd4e5da5Sopenharmony_ci%void = OpTypeVoid
1026fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
1027fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
1028fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
1029fd4e5da5Sopenharmony_ci%uint_32 = OpConstant %uint 32
1030fd4e5da5Sopenharmony_ci%_arr_int_uint_32 = OpTypeArray %int %uint_32
1031fd4e5da5Sopenharmony_ci%_ptr_Input__arr_int_uint_32 = OpTypePointer Input %_arr_int_uint_32
1032fd4e5da5Sopenharmony_ci%_3 = OpVariable %_ptr_Input__arr_int_uint_32 Input
1033fd4e5da5Sopenharmony_ci%_ptr_Input_int = OpTypePointer Input %int
1034fd4e5da5Sopenharmony_ci%gl_InvocationID = OpVariable %_ptr_Input_int Input
1035fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
1036fd4e5da5Sopenharmony_ci%bool = OpTypeBool
1037fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
1038fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
1039fd4e5da5Sopenharmony_ci%float_0_0234375 = OpConstant %float 0.0234375
1040fd4e5da5Sopenharmony_ci%float_1_01561999 = OpConstant %float 1.01561999
1041fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
1042fd4e5da5Sopenharmony_ci%uint_3 = OpConstant %uint 3
1043fd4e5da5Sopenharmony_ci%_arr_v4float_uint_3 = OpTypeArray %v4float %uint_3
1044fd4e5da5Sopenharmony_ci%_ptr_Output__arr_v4float_uint_3 = OpTypePointer Output %_arr_v4float_uint_3
1045fd4e5da5Sopenharmony_ci%_5 = OpVariable %_ptr_Output__arr_v4float_uint_3 Output
1046fd4e5da5Sopenharmony_ci%34 = OpTypeImage %float 1D 0 0 0 1 Unknown
1047fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_34 = OpTypePointer UniformConstant %34
1048fd4e5da5Sopenharmony_ci%_77 = OpVariable %_ptr_UniformConstant_34 UniformConstant
1049fd4e5da5Sopenharmony_ci%38 = OpTypeSampler
1050fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_38 = OpTypePointer UniformConstant %38
1051fd4e5da5Sopenharmony_ci%_78 = OpVariable %_ptr_UniformConstant_38 UniformConstant
1052fd4e5da5Sopenharmony_ci%42 = OpTypeSampledImage %34
1053fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
1054fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
1055fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
1056fd4e5da5Sopenharmony_ci%uint_1 = OpConstant %uint 1
1057fd4e5da5Sopenharmony_ci%_arr_float_uint_1 = OpTypeArray %float %uint_1
1058fd4e5da5Sopenharmony_ci%gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
1059fd4e5da5Sopenharmony_ci%_arr_gl_PerVertex_uint_32 = OpTypeArray %gl_PerVertex %uint_32
1060fd4e5da5Sopenharmony_ci%_ptr_Input__arr_gl_PerVertex_uint_32 = OpTypePointer Input %_arr_gl_PerVertex_uint_32
1061fd4e5da5Sopenharmony_ci%gl_in = OpVariable %_ptr_Input__arr_gl_PerVertex_uint_32 Input
1062fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
1063fd4e5da5Sopenharmony_ci%int_2 = OpConstant %int 2
1064fd4e5da5Sopenharmony_ci%gl_PerVertex_0 = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
1065fd4e5da5Sopenharmony_ci%_arr_gl_PerVertex_0_uint_3 = OpTypeArray %gl_PerVertex_0 %uint_3
1066fd4e5da5Sopenharmony_ci%_ptr_Output__arr_gl_PerVertex_0_uint_3 = OpTypePointer Output %_arr_gl_PerVertex_0_uint_3
1067fd4e5da5Sopenharmony_ci%gl_out = OpVariable %_ptr_Output__arr_gl_PerVertex_0_uint_3 Output
1068fd4e5da5Sopenharmony_ci%uint_2 = OpConstant %uint 2
1069fd4e5da5Sopenharmony_ci%_arr_float_uint_2 = OpTypeArray %float %uint_2
1070fd4e5da5Sopenharmony_ci%_ptr_Output__arr_float_uint_2 = OpTypePointer Output %_arr_float_uint_2
1071fd4e5da5Sopenharmony_ci%gl_TessLevelInner = OpVariable %_ptr_Output__arr_float_uint_2 Output
1072fd4e5da5Sopenharmony_ci%float_2_79999995 = OpConstant %float 2.79999995
1073fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
1074fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
1075fd4e5da5Sopenharmony_ci%uint_4 = OpConstant %uint 4
1076fd4e5da5Sopenharmony_ci%_arr_float_uint_4 = OpTypeArray %float %uint_4
1077fd4e5da5Sopenharmony_ci%_ptr_Output__arr_float_uint_4 = OpTypePointer Output %_arr_float_uint_4
1078fd4e5da5Sopenharmony_ci%gl_TessLevelOuter = OpVariable %_ptr_Output__arr_float_uint_4 Output
1079fd4e5da5Sopenharmony_ci%int_3 = OpConstant %int 3
1080fd4e5da5Sopenharmony_ci)";
1081fd4e5da5Sopenharmony_ci
1082fd4e5da5Sopenharmony_ci  const std::string main_func =
1083fd4e5da5Sopenharmony_ci      R"(
1084fd4e5da5Sopenharmony_ci%main = OpFunction %void None %3
1085fd4e5da5Sopenharmony_ci%5 = OpLabel
1086fd4e5da5Sopenharmony_ci%param = OpVariable %_ptr_Function_float Function
1087fd4e5da5Sopenharmony_ci%_203 = OpVariable %_ptr_Function_v4float Function
1088fd4e5da5Sopenharmony_ci%14 = OpLoad %int %gl_InvocationID
1089fd4e5da5Sopenharmony_ci%15 = OpAccessChain %_ptr_Input_int %_3 %14
1090fd4e5da5Sopenharmony_ci%16 = OpLoad %int %15
1091fd4e5da5Sopenharmony_ci%19 = OpIEqual %bool %16 %int_0
1092fd4e5da5Sopenharmony_ciOpSelectionMerge %21 None
1093fd4e5da5Sopenharmony_ciOpBranchConditional %19 %20 %26
1094fd4e5da5Sopenharmony_ci%20 = OpLabel
1095fd4e5da5Sopenharmony_ci;CHECK-NOT: %15 = OpAccessChain %_ptr_Input_int %_3 %14
1096fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
1097fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
1098fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %int %gl_InvocationID
1099fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpAccessChain %_ptr_Input_int %_3 {{%\w+}}
1100fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %int {{%\w+}}
1101fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpIEqual %bool {{%\w+}} %int_0
1102fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
1103fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
1104fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
1105fd4e5da5Sopenharmony_ciOpStore %param %float_0_0234375
1106fd4e5da5Sopenharmony_ciOpBranch %21
1107fd4e5da5Sopenharmony_ci%26 = OpLabel
1108fd4e5da5Sopenharmony_ciOpStore %param %float_1_01561999
1109fd4e5da5Sopenharmony_ciOpBranch %21
1110fd4e5da5Sopenharmony_ci%21 = OpLabel
1111fd4e5da5Sopenharmony_ci%33 = OpLoad %int %gl_InvocationID
1112fd4e5da5Sopenharmony_ci%37 = OpLoad %34 %_77
1113fd4e5da5Sopenharmony_ci%41 = OpLoad %38 %_78
1114fd4e5da5Sopenharmony_ci%43 = OpSampledImage %42 %37 %41
1115fd4e5da5Sopenharmony_ci%44 = OpLoad %float %param
1116fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %int %gl_InvocationID
1117fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %uint {{%\w+}}
1118fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %uint %gl_PrimitiveID
1119fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_1 {{%\w+}} {{%\w+}} %uint_0
1120fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %inst_bindless_check_desc %uint_23 %uint_129 {{%\w+}} %uint_0 %uint_0 %uint_0 %uint_0
1121fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
1122fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
1123fd4e5da5Sopenharmony_ci%46 = OpImageSampleExplicitLod %v4float %43 %44 Lod %float_0
1124fd4e5da5Sopenharmony_ci%48 = OpAccessChain %_ptr_Output_v4float %_5 %33
1125fd4e5da5Sopenharmony_ciOpStore %48 %46
1126fd4e5da5Sopenharmony_ci;CHECK-NOT: %48 = OpAccessChain %_ptr_Output_v4float %_5 %33
1127fd4e5da5Sopenharmony_ci;CHECK-NOT: OpStore %48 %46
1128fd4e5da5Sopenharmony_ci;CHECK: [[phi_result:%\w+]] = OpPhi %v4float {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}}
1129fd4e5da5Sopenharmony_ci;CHECK: [[access_chain:%\w+]] = OpAccessChain %_ptr_Output_v4float %_5 {{%\w+}}
1130fd4e5da5Sopenharmony_ci;CHECK: OpStore [[access_chain]] [[phi_result]]
1131fd4e5da5Sopenharmony_ci%49 = OpLoad %int %gl_InvocationID
1132fd4e5da5Sopenharmony_ci%50 = OpIEqual %bool %49 %int_0
1133fd4e5da5Sopenharmony_ciOpSelectionMerge %52 None
1134fd4e5da5Sopenharmony_ciOpBranchConditional %50 %51 %64
1135fd4e5da5Sopenharmony_ci%51 = OpLabel
1136fd4e5da5Sopenharmony_ci%62 = OpAccessChain %_ptr_Input_v4float %gl_in %int_0 %int_0
1137fd4e5da5Sopenharmony_ci%63 = OpLoad %v4float %62
1138fd4e5da5Sopenharmony_ciOpStore %_203 %63
1139fd4e5da5Sopenharmony_ciOpBranch %52
1140fd4e5da5Sopenharmony_ci%64 = OpLabel
1141fd4e5da5Sopenharmony_ci%66 = OpAccessChain %_ptr_Input_v4float %gl_in %int_2 %int_0
1142fd4e5da5Sopenharmony_ci%67 = OpLoad %v4float %66
1143fd4e5da5Sopenharmony_ciOpStore %_203 %67
1144fd4e5da5Sopenharmony_ciOpBranch %52
1145fd4e5da5Sopenharmony_ci%52 = OpLabel
1146fd4e5da5Sopenharmony_ci%72 = OpLoad %int %gl_InvocationID
1147fd4e5da5Sopenharmony_ci%73 = OpLoad %v4float %_203
1148fd4e5da5Sopenharmony_ci%74 = OpAccessChain %_ptr_Output_v4float %gl_out %72 %int_0
1149fd4e5da5Sopenharmony_ciOpStore %74 %73
1150fd4e5da5Sopenharmony_ci%81 = OpAccessChain %_ptr_Output_float %gl_TessLevelInner %int_0
1151fd4e5da5Sopenharmony_ciOpStore %81 %float_2_79999995
1152fd4e5da5Sopenharmony_ci%83 = OpAccessChain %_ptr_Output_float %gl_TessLevelInner %int_1
1153fd4e5da5Sopenharmony_ciOpStore %83 %float_2_79999995
1154fd4e5da5Sopenharmony_ci%88 = OpAccessChain %_ptr_Output_float %gl_TessLevelOuter %int_0
1155fd4e5da5Sopenharmony_ciOpStore %88 %float_2_79999995
1156fd4e5da5Sopenharmony_ci%89 = OpAccessChain %_ptr_Output_float %gl_TessLevelOuter %int_1
1157fd4e5da5Sopenharmony_ciOpStore %89 %float_2_79999995
1158fd4e5da5Sopenharmony_ci%90 = OpAccessChain %_ptr_Output_float %gl_TessLevelOuter %int_2
1159fd4e5da5Sopenharmony_ciOpStore %90 %float_2_79999995
1160fd4e5da5Sopenharmony_ci%92 = OpAccessChain %_ptr_Output_float %gl_TessLevelOuter %int_3
1161fd4e5da5Sopenharmony_ciOpStore %92 %float_2_79999995
1162fd4e5da5Sopenharmony_ciOpReturn
1163fd4e5da5Sopenharmony_ciOpFunctionEnd
1164fd4e5da5Sopenharmony_ci)";
1165fd4e5da5Sopenharmony_ci  // clang-format on
1166fd4e5da5Sopenharmony_ci
1167fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
1168fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(defs + kImportStub + main_func,
1169fd4e5da5Sopenharmony_ci                                               true, 23u);
1170fd4e5da5Sopenharmony_ci}
1171fd4e5da5Sopenharmony_ci
1172fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest, MultipleDebugFunctions) {
1173fd4e5da5Sopenharmony_ci  // Same source as Simple, but compiled -g and not optimized, especially not
1174fd4e5da5Sopenharmony_ci  // inlined. The OpSource has had the source extracted for the sake of brevity.
1175fd4e5da5Sopenharmony_ci
1176fd4e5da5Sopenharmony_ci  // clang-format off
1177fd4e5da5Sopenharmony_ci  const std::string defs = R"(
1178fd4e5da5Sopenharmony_ciOpCapability Shader
1179fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
1180fd4e5da5Sopenharmony_ci%2 = OpExtInstImport "GLSL.std.450"
1181fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
1182fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
1183fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
1184fd4e5da5Sopenharmony_ciOpExecutionMode %MainPs OriginUpperLeft
1185fd4e5da5Sopenharmony_ci%1 = OpString "foo5.frag"
1186fd4e5da5Sopenharmony_ciOpSource HLSL 500 %1
1187fd4e5da5Sopenharmony_ciOpName %MainPs "MainPs"
1188fd4e5da5Sopenharmony_ciOpName %PS_INPUT "PS_INPUT"
1189fd4e5da5Sopenharmony_ciOpMemberName %PS_INPUT 0 "vTextureCoords"
1190fd4e5da5Sopenharmony_ciOpName %PS_OUTPUT "PS_OUTPUT"
1191fd4e5da5Sopenharmony_ciOpMemberName %PS_OUTPUT 0 "vColor"
1192fd4e5da5Sopenharmony_ciOpName %_MainPs_struct_PS_INPUT_vf21_ "@MainPs(struct-PS_INPUT-vf21;"
1193fd4e5da5Sopenharmony_ciOpName %i "i"
1194fd4e5da5Sopenharmony_ciOpName %ps_output "ps_output"
1195fd4e5da5Sopenharmony_ciOpName %g_tColor "g_tColor"
1196fd4e5da5Sopenharmony_ciOpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
1197fd4e5da5Sopenharmony_ciOpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
1198fd4e5da5Sopenharmony_ciOpName %_ ""
1199fd4e5da5Sopenharmony_ciOpName %g_sAniso "g_sAniso"
1200fd4e5da5Sopenharmony_ciOpName %i_0 "i"
1201fd4e5da5Sopenharmony_ciOpName %i_vTextureCoords "i.vTextureCoords"
1202fd4e5da5Sopenharmony_ciOpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
1203fd4e5da5Sopenharmony_ciOpName %param "param"
1204fd4e5da5Sopenharmony_ciOpDecorate %g_tColor DescriptorSet 1
1205fd4e5da5Sopenharmony_ciOpDecorate %g_tColor Binding 2
1206fd4e5da5Sopenharmony_ciOpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
1207fd4e5da5Sopenharmony_ciOpDecorate %PerViewConstantBuffer_t Block
1208fd4e5da5Sopenharmony_ciOpDecorate %g_sAniso DescriptorSet 1
1209fd4e5da5Sopenharmony_ciOpDecorate %g_sAniso Binding 3
1210fd4e5da5Sopenharmony_ciOpDecorate %i_vTextureCoords Location 0
1211fd4e5da5Sopenharmony_ciOpDecorate %_entryPointOutput_vColor Location 0
1212fd4e5da5Sopenharmony_ci)" + kImportDeco + R"(
1213fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
1214fd4e5da5Sopenharmony_ci%void = OpTypeVoid
1215fd4e5da5Sopenharmony_ci%4 = OpTypeFunction %void
1216fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
1217fd4e5da5Sopenharmony_ci%v2float = OpTypeVector %float 2
1218fd4e5da5Sopenharmony_ci%PS_INPUT = OpTypeStruct %v2float
1219fd4e5da5Sopenharmony_ci%_ptr_Function_PS_INPUT = OpTypePointer Function %PS_INPUT
1220fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
1221fd4e5da5Sopenharmony_ci%PS_OUTPUT = OpTypeStruct %v4float
1222fd4e5da5Sopenharmony_ci%13 = OpTypeFunction %PS_OUTPUT %_ptr_Function_PS_INPUT
1223fd4e5da5Sopenharmony_ci%_ptr_Function_PS_OUTPUT = OpTypePointer Function %PS_OUTPUT
1224fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
1225fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
1226fd4e5da5Sopenharmony_ci%21 = OpTypeImage %float 2D 0 0 0 1 Unknown
1227fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
1228fd4e5da5Sopenharmony_ci%uint_128 = OpConstant %uint 128
1229fd4e5da5Sopenharmony_ci%_arr_21_uint_128 = OpTypeArray %21 %uint_128
1230fd4e5da5Sopenharmony_ci%_ptr_UniformConstant__arr_21_uint_128 = OpTypePointer UniformConstant %_arr_21_uint_128
1231fd4e5da5Sopenharmony_ci%g_tColor = OpVariable %_ptr_UniformConstant__arr_21_uint_128 UniformConstant
1232fd4e5da5Sopenharmony_ci%PerViewConstantBuffer_t = OpTypeStruct %uint
1233fd4e5da5Sopenharmony_ci%_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
1234fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
1235fd4e5da5Sopenharmony_ci%_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
1236fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_21 = OpTypePointer UniformConstant %21
1237fd4e5da5Sopenharmony_ci%36 = OpTypeSampler
1238fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_36 = OpTypePointer UniformConstant %36
1239fd4e5da5Sopenharmony_ci%g_sAniso = OpVariable %_ptr_UniformConstant_36 UniformConstant
1240fd4e5da5Sopenharmony_ci%40 = OpTypeSampledImage %21
1241fd4e5da5Sopenharmony_ci%_ptr_Function_v2float = OpTypePointer Function %v2float
1242fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
1243fd4e5da5Sopenharmony_ci%_ptr_Input_v2float = OpTypePointer Input %v2float
1244fd4e5da5Sopenharmony_ci%i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
1245fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
1246fd4e5da5Sopenharmony_ci%_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
1247fd4e5da5Sopenharmony_ci;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
1248fd4e5da5Sopenharmony_ci;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
1249fd4e5da5Sopenharmony_ci;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
1250fd4e5da5Sopenharmony_ci)";
1251fd4e5da5Sopenharmony_ci
1252fd4e5da5Sopenharmony_ci  const std::string func1 = R"(
1253fd4e5da5Sopenharmony_ci%MainPs = OpFunction %void None %4
1254fd4e5da5Sopenharmony_ci%6 = OpLabel
1255fd4e5da5Sopenharmony_ci%i_0 = OpVariable %_ptr_Function_PS_INPUT Function
1256fd4e5da5Sopenharmony_ci%param = OpVariable %_ptr_Function_PS_INPUT Function
1257fd4e5da5Sopenharmony_ciOpLine %1 21 0
1258fd4e5da5Sopenharmony_ci%54 = OpLoad %v2float %i_vTextureCoords
1259fd4e5da5Sopenharmony_ci%55 = OpAccessChain %_ptr_Function_v2float %i_0 %int_0
1260fd4e5da5Sopenharmony_ciOpStore %55 %54
1261fd4e5da5Sopenharmony_ci%59 = OpLoad %PS_INPUT %i_0
1262fd4e5da5Sopenharmony_ciOpStore %param %59
1263fd4e5da5Sopenharmony_ci%60 = OpFunctionCall %PS_OUTPUT %_MainPs_struct_PS_INPUT_vf21_ %param
1264fd4e5da5Sopenharmony_ci%61 = OpCompositeExtract %v4float %60 0
1265fd4e5da5Sopenharmony_ciOpStore %_entryPointOutput_vColor %61
1266fd4e5da5Sopenharmony_ciOpReturn
1267fd4e5da5Sopenharmony_ciOpFunctionEnd
1268fd4e5da5Sopenharmony_ci)";
1269fd4e5da5Sopenharmony_ci
1270fd4e5da5Sopenharmony_ci  const std::string func2 = R"(
1271fd4e5da5Sopenharmony_ci%_MainPs_struct_PS_INPUT_vf21_ = OpFunction %PS_OUTPUT None %13
1272fd4e5da5Sopenharmony_ci%i = OpFunctionParameter %_ptr_Function_PS_INPUT
1273fd4e5da5Sopenharmony_ci%16 = OpLabel
1274fd4e5da5Sopenharmony_ci%ps_output = OpVariable %_ptr_Function_PS_OUTPUT Function
1275fd4e5da5Sopenharmony_ciOpLine %1 24 0
1276fd4e5da5Sopenharmony_ci%31 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
1277fd4e5da5Sopenharmony_ci%32 = OpLoad %uint %31
1278fd4e5da5Sopenharmony_ci%34 = OpAccessChain %_ptr_UniformConstant_21 %g_tColor %32
1279fd4e5da5Sopenharmony_ci%35 = OpLoad %21 %34
1280fd4e5da5Sopenharmony_ci%39 = OpLoad %36 %g_sAniso
1281fd4e5da5Sopenharmony_ci%41 = OpSampledImage %40 %35 %39
1282fd4e5da5Sopenharmony_ci%43 = OpAccessChain %_ptr_Function_v2float %i %int_0
1283fd4e5da5Sopenharmony_ci%44 = OpLoad %v2float %43
1284fd4e5da5Sopenharmony_ci%45 = OpImageSampleImplicitLod %v4float %41 %44
1285fd4e5da5Sopenharmony_ci;CHECK-NOT: %45 = OpImageSampleImplicitLod %v4float %41 %44
1286fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v2float {{%\w+}}
1287fd4e5da5Sopenharmony_ci;CHECK: OpNoLine
1288fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord
1289fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}}
1290fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
1291fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
1292fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0
1293fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_128 {{%\w+}} %uint_1 %uint_2 {{%\w+}} %uint_0
1294fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
1295fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
1296fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
1297fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %27 {{%\w+}}
1298fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpSampledImage %37 {{%\w+}} {{%\w+}}
1299fd4e5da5Sopenharmony_ci;CHECK: OpLine %5 24 0
1300fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpImageSampleImplicitLod %v4float {{%\w+}} {{%\w+}}
1301fd4e5da5Sopenharmony_ci;CHECK: OpNoLine
1302fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
1303fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
1304fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
1305fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
1306fd4e5da5Sopenharmony_ci;CHECK: [[phi_result:%\w+]] = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}}
1307fd4e5da5Sopenharmony_ci%47 = OpAccessChain %_ptr_Function_v4float %ps_output %int_0
1308fd4e5da5Sopenharmony_ciOpStore %47 %45
1309fd4e5da5Sopenharmony_ci;CHECK-NOT: OpStore %47 %45
1310fd4e5da5Sopenharmony_ci;CHECK: [[store_loc:%\w+]] = OpAccessChain %_ptr_Function_v4float %ps_output %int_0
1311fd4e5da5Sopenharmony_ci;CHECK: OpStore [[store_loc]] [[phi_result]]
1312fd4e5da5Sopenharmony_ciOpLine %1 25 0
1313fd4e5da5Sopenharmony_ci%48 = OpLoad %PS_OUTPUT %ps_output
1314fd4e5da5Sopenharmony_ciOpReturnValue %48
1315fd4e5da5Sopenharmony_ciOpFunctionEnd
1316fd4e5da5Sopenharmony_ci)";
1317fd4e5da5Sopenharmony_ci  // clang-format on
1318fd4e5da5Sopenharmony_ci
1319fd4e5da5Sopenharmony_ci  // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
1320fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(
1321fd4e5da5Sopenharmony_ci      defs + kImportStub + func1 + func2, true, 23u);
1322fd4e5da5Sopenharmony_ci}
1323fd4e5da5Sopenharmony_ci
1324fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest, RuntimeArray) {
1325fd4e5da5Sopenharmony_ci  // This test verifies that the pass will correctly instrument shader
1326fd4e5da5Sopenharmony_ci  // with runtime descriptor array. This test was created by editing the
1327fd4e5da5Sopenharmony_ci  // SPIR-V from the Simple test.
1328fd4e5da5Sopenharmony_ci
1329fd4e5da5Sopenharmony_ci  // clang-format off
1330fd4e5da5Sopenharmony_ci  const std::string defs = R"(
1331fd4e5da5Sopenharmony_ciOpCapability Shader
1332fd4e5da5Sopenharmony_ciOpCapability RuntimeDescriptorArray
1333fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
1334fd4e5da5Sopenharmony_ciOpExtension "SPV_EXT_descriptor_indexing"
1335fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
1336fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
1337fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
1338fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
1339fd4e5da5Sopenharmony_ciOpExecutionMode %MainPs OriginUpperLeft
1340fd4e5da5Sopenharmony_ciOpSource HLSL 500
1341fd4e5da5Sopenharmony_ciOpName %MainPs "MainPs"
1342fd4e5da5Sopenharmony_ciOpName %g_tColor "g_tColor"
1343fd4e5da5Sopenharmony_ciOpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
1344fd4e5da5Sopenharmony_ciOpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
1345fd4e5da5Sopenharmony_ciOpName %_ ""
1346fd4e5da5Sopenharmony_ciOpName %g_sAniso "g_sAniso"
1347fd4e5da5Sopenharmony_ciOpName %i_vTextureCoords "i.vTextureCoords"
1348fd4e5da5Sopenharmony_ciOpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
1349fd4e5da5Sopenharmony_ciOpDecorate %g_tColor DescriptorSet 1
1350fd4e5da5Sopenharmony_ciOpDecorate %g_tColor Binding 2
1351fd4e5da5Sopenharmony_ciOpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
1352fd4e5da5Sopenharmony_ciOpDecorate %PerViewConstantBuffer_t Block
1353fd4e5da5Sopenharmony_ciOpDecorate %g_sAniso DescriptorSet 1
1354fd4e5da5Sopenharmony_ciOpDecorate %g_sAniso Binding 3
1355fd4e5da5Sopenharmony_ciOpDecorate %i_vTextureCoords Location 0
1356fd4e5da5Sopenharmony_ciOpDecorate %_entryPointOutput_vColor Location 0
1357fd4e5da5Sopenharmony_ci)" + kImportDeco + R"(
1358fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
1359fd4e5da5Sopenharmony_ci%void = OpTypeVoid
1360fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
1361fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
1362fd4e5da5Sopenharmony_ci%v2float = OpTypeVector %float 2
1363fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
1364fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
1365fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
1366fd4e5da5Sopenharmony_ci%20 = OpTypeImage %float 2D 0 0 0 1 Unknown
1367fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
1368fd4e5da5Sopenharmony_ci%uint_1 = OpConstant %uint 1
1369fd4e5da5Sopenharmony_ci%_rarr_20 = OpTypeRuntimeArray %20
1370fd4e5da5Sopenharmony_ci%_ptr_UniformConstant__arr_20 = OpTypePointer UniformConstant %_rarr_20
1371fd4e5da5Sopenharmony_ci%g_tColor = OpVariable %_ptr_UniformConstant__arr_20 UniformConstant
1372fd4e5da5Sopenharmony_ci%PerViewConstantBuffer_t = OpTypeStruct %uint
1373fd4e5da5Sopenharmony_ci%_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
1374fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
1375fd4e5da5Sopenharmony_ci%_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
1376fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_20 = OpTypePointer UniformConstant %20
1377fd4e5da5Sopenharmony_ci%35 = OpTypeSampler
1378fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_35 = OpTypePointer UniformConstant %35
1379fd4e5da5Sopenharmony_ci%g_sAniso = OpVariable %_ptr_UniformConstant_35 UniformConstant
1380fd4e5da5Sopenharmony_ci%39 = OpTypeSampledImage %20
1381fd4e5da5Sopenharmony_ci%_ptr_Input_v2float = OpTypePointer Input %v2float
1382fd4e5da5Sopenharmony_ci%i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
1383fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
1384fd4e5da5Sopenharmony_ci%_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
1385fd4e5da5Sopenharmony_ci;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
1386fd4e5da5Sopenharmony_ci;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
1387fd4e5da5Sopenharmony_ci;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
1388fd4e5da5Sopenharmony_ci)";
1389fd4e5da5Sopenharmony_ci
1390fd4e5da5Sopenharmony_ci  const std::string main_func = R"(
1391fd4e5da5Sopenharmony_ci%MainPs = OpFunction %void None %3
1392fd4e5da5Sopenharmony_ci%5 = OpLabel
1393fd4e5da5Sopenharmony_ci%53 = OpLoad %v2float %i_vTextureCoords
1394fd4e5da5Sopenharmony_ci%63 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
1395fd4e5da5Sopenharmony_ci%64 = OpLoad %uint %63
1396fd4e5da5Sopenharmony_ci%65 = OpAccessChain %_ptr_UniformConstant_20 %g_tColor %64
1397fd4e5da5Sopenharmony_ci%66 = OpLoad %20 %65
1398fd4e5da5Sopenharmony_ci%67 = OpLoad %35 %g_sAniso
1399fd4e5da5Sopenharmony_ci%68 = OpSampledImage %39 %66 %67
1400fd4e5da5Sopenharmony_ci%71 = OpImageSampleImplicitLod %v4float %68 %53
1401fd4e5da5Sopenharmony_ciOpStore %_entryPointOutput_vColor %71
1402fd4e5da5Sopenharmony_ci;CHECK-NOT: %71 = OpImageSampleImplicitLod %v4float %68 %53
1403fd4e5da5Sopenharmony_ci;CHECK-NOT: OpStore %_entryPointOutput_vColor %71
1404fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord
1405fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}}
1406fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
1407fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
1408fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0
1409fd4e5da5Sopenharmony_ci;CHECK: [[check_result:%\w+]] = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_60 {{%\w+}} %uint_1 %uint_2 %32 %uint_0
1410fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
1411fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
1412fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
1413fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %16 %33
1414fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpSampledImage %26 {{%\w+}} %35
1415fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpImageSampleImplicitLod %v4float {{%\w+}} %30
1416fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
1417fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
1418fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
1419fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
1420fd4e5da5Sopenharmony_ci;CHECK: [[phi_result_1:%\w+]] = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}}
1421fd4e5da5Sopenharmony_ci;CHECK: OpStore %_entryPointOutput_vColor [[phi_result_1]]
1422fd4e5da5Sopenharmony_ciOpReturn
1423fd4e5da5Sopenharmony_ciOpFunctionEnd
1424fd4e5da5Sopenharmony_ci)";
1425fd4e5da5Sopenharmony_ci  // clang-format on
1426fd4e5da5Sopenharmony_ci
1427fd4e5da5Sopenharmony_ci  // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
1428fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(defs + kImportStub + main_func,
1429fd4e5da5Sopenharmony_ci                                               true, 23u);
1430fd4e5da5Sopenharmony_ci}
1431fd4e5da5Sopenharmony_ci
1432fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest, InstrumentInitCheckOnScalarDescriptor) {
1433fd4e5da5Sopenharmony_ci  // This test verifies that the pass will correctly instrument vanilla
1434fd4e5da5Sopenharmony_ci  // texture sample on a scalar descriptor with an initialization check if the
1435fd4e5da5Sopenharmony_ci  // input_init_enable argument is set to true. This can happen when the
1436fd4e5da5Sopenharmony_ci  // descriptor indexing extension is enabled in the API but the SPIR-V
1437fd4e5da5Sopenharmony_ci  // does not have the extension enabled because it does not contain a
1438fd4e5da5Sopenharmony_ci  // runtime array. This is the same shader as NoInstrumentNonBindless.
1439fd4e5da5Sopenharmony_ci
1440fd4e5da5Sopenharmony_ci  // clang-format off
1441fd4e5da5Sopenharmony_ci  const std::string defs = R"(
1442fd4e5da5Sopenharmony_ciOpCapability Shader
1443fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
1444fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
1445fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
1446fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
1447fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
1448fd4e5da5Sopenharmony_ciOpExecutionMode %MainPs OriginUpperLeft
1449fd4e5da5Sopenharmony_ciOpSource HLSL 500
1450fd4e5da5Sopenharmony_ciOpName %MainPs "MainPs"
1451fd4e5da5Sopenharmony_ciOpName %g_tColor "g_tColor"
1452fd4e5da5Sopenharmony_ciOpName %g_sAniso "g_sAniso"
1453fd4e5da5Sopenharmony_ciOpName %i_vTextureCoords "i.vTextureCoords"
1454fd4e5da5Sopenharmony_ciOpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
1455fd4e5da5Sopenharmony_ciOpDecorate %g_tColor DescriptorSet 1
1456fd4e5da5Sopenharmony_ciOpDecorate %g_tColor Binding 2
1457fd4e5da5Sopenharmony_ciOpDecorate %g_sAniso DescriptorSet 1
1458fd4e5da5Sopenharmony_ciOpDecorate %g_sAniso Binding 2
1459fd4e5da5Sopenharmony_ciOpDecorate %i_vTextureCoords Location 0
1460fd4e5da5Sopenharmony_ciOpDecorate %_entryPointOutput_vColor Location 0
1461fd4e5da5Sopenharmony_ci)" + kImportDeco + R"(
1462fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
1463fd4e5da5Sopenharmony_ci%void = OpTypeVoid
1464fd4e5da5Sopenharmony_ci%8 = OpTypeFunction %void
1465fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
1466fd4e5da5Sopenharmony_ci%v2float = OpTypeVector %float 2
1467fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
1468fd4e5da5Sopenharmony_ci%12 = OpTypeImage %float 2D 0 0 0 1 Unknown
1469fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_12 = OpTypePointer UniformConstant %12
1470fd4e5da5Sopenharmony_ci%g_tColor = OpVariable %_ptr_UniformConstant_12 UniformConstant
1471fd4e5da5Sopenharmony_ci%14 = OpTypeSampler
1472fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_14 = OpTypePointer UniformConstant %14
1473fd4e5da5Sopenharmony_ci%g_sAniso = OpVariable %_ptr_UniformConstant_14 UniformConstant
1474fd4e5da5Sopenharmony_ci%16 = OpTypeSampledImage %12
1475fd4e5da5Sopenharmony_ci%_ptr_Input_v2float = OpTypePointer Input %v2float
1476fd4e5da5Sopenharmony_ci%i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
1477fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
1478fd4e5da5Sopenharmony_ci%_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
1479fd4e5da5Sopenharmony_ci;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
1480fd4e5da5Sopenharmony_ci)";
1481fd4e5da5Sopenharmony_ci
1482fd4e5da5Sopenharmony_ci  const std::string main_func = R"(
1483fd4e5da5Sopenharmony_ci%MainPs = OpFunction %void None %8
1484fd4e5da5Sopenharmony_ci%19 = OpLabel
1485fd4e5da5Sopenharmony_ci%20 = OpLoad %v2float %i_vTextureCoords
1486fd4e5da5Sopenharmony_ci%21 = OpLoad %12 %g_tColor
1487fd4e5da5Sopenharmony_ci%22 = OpLoad %14 %g_sAniso
1488fd4e5da5Sopenharmony_ci%23 = OpSampledImage %16 %21 %22
1489fd4e5da5Sopenharmony_ci%24 = OpImageSampleImplicitLod %v4float %23 %20
1490fd4e5da5Sopenharmony_ciOpStore %_entryPointOutput_vColor %24
1491fd4e5da5Sopenharmony_ci;CHECK-NOT: %24 = OpImageSampleImplicitLod %v4float %23 %20
1492fd4e5da5Sopenharmony_ci;CHECK-NOT: OpStore %_entryPointOutput_vColor %24
1493fd4e5da5Sopenharmony_ci;CHECK: [[check_result:%\w+]] = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_40 {{%\w+}} %uint_1 %uint_2 %uint_0 %uint_0
1494fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
1495fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional [[check_result]] {{%\w+}} {{%\w+}}
1496fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
1497fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %12 %g_tColor
1498fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpSampledImage %16 {{%\w+}} %22
1499fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpImageSampleImplicitLod %v4float {{%\w+}} %20
1500fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
1501fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
1502fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
1503fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
1504fd4e5da5Sopenharmony_ci;CHECK: [[phi_result:%\w+]] = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}}
1505fd4e5da5Sopenharmony_ci;CHECK: OpStore %_entryPointOutput_vColor [[phi_result]]
1506fd4e5da5Sopenharmony_ciOpReturn
1507fd4e5da5Sopenharmony_ciOpFunctionEnd
1508fd4e5da5Sopenharmony_ci)";
1509fd4e5da5Sopenharmony_ci  // clang-format on
1510fd4e5da5Sopenharmony_ci
1511fd4e5da5Sopenharmony_ci  // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
1512fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(defs + kImportStub + main_func,
1513fd4e5da5Sopenharmony_ci                                               true, 23u);
1514fd4e5da5Sopenharmony_ci}
1515fd4e5da5Sopenharmony_ci
1516fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest, SPV14AddToEntryPoint) {
1517fd4e5da5Sopenharmony_ci  const std::string text = R"(
1518fd4e5da5Sopenharmony_ciOpCapability Shader
1519fd4e5da5Sopenharmony_ciOpExtension "SPV_EXT_descriptor_indexing"
1520fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
1521fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %foo "foo" %gid %image_var %sampler_var
1522fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint Fragment {{%\w+}} "foo" {{%\w+}} {{%\w+}} {{%\w+}} %gl_FragCoord
1523fd4e5da5Sopenharmony_ciOpExecutionMode %foo OriginUpperLeft
1524fd4e5da5Sopenharmony_ciOpDecorate %image_var DescriptorSet 4
1525fd4e5da5Sopenharmony_ciOpDecorate %image_var Binding 1
1526fd4e5da5Sopenharmony_ciOpDecorate %sampler_var DescriptorSet 4
1527fd4e5da5Sopenharmony_ciOpDecorate %sampler_var Binding 2
1528fd4e5da5Sopenharmony_ciOpDecorate %gid DescriptorSet 0
1529fd4e5da5Sopenharmony_ciOpDecorate %gid Binding 2
1530fd4e5da5Sopenharmony_ciOpDecorate %struct Block
1531fd4e5da5Sopenharmony_ciOpMemberDecorate %struct 0 Offset 0
1532fd4e5da5Sopenharmony_ci%void = OpTypeVoid
1533fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0
1534fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
1535fd4e5da5Sopenharmony_ci%v3int = OpTypeVector %int 3
1536fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
1537fd4e5da5Sopenharmony_ci%v3float = OpTypeVector %float 3
1538fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
1539fd4e5da5Sopenharmony_ci%struct = OpTypeStruct %v3int
1540fd4e5da5Sopenharmony_ci%ptr_ssbo_struct = OpTypePointer StorageBuffer %struct
1541fd4e5da5Sopenharmony_ci%ptr_ssbo_v3int = OpTypePointer StorageBuffer %v3int
1542fd4e5da5Sopenharmony_ci%gid = OpVariable %ptr_ssbo_struct StorageBuffer
1543fd4e5da5Sopenharmony_ci%image = OpTypeImage %float 3D 0 0 0 1 Unknown
1544fd4e5da5Sopenharmony_ci%ptr_uc_image = OpTypePointer UniformConstant %image
1545fd4e5da5Sopenharmony_ci%sampler = OpTypeSampler
1546fd4e5da5Sopenharmony_ci%ptr_uc_sampler = OpTypePointer UniformConstant %sampler
1547fd4e5da5Sopenharmony_ci%image_var = OpVariable %ptr_uc_image UniformConstant
1548fd4e5da5Sopenharmony_ci%sampler_var = OpVariable %ptr_uc_sampler UniformConstant
1549fd4e5da5Sopenharmony_ci%sampled = OpTypeSampledImage %image
1550fd4e5da5Sopenharmony_ci%void_fn = OpTypeFunction %void
1551fd4e5da5Sopenharmony_ci%foo = OpFunction %void None %void_fn
1552fd4e5da5Sopenharmony_ci%entry = OpLabel
1553fd4e5da5Sopenharmony_ci%ld_image = OpLoad %image %image_var
1554fd4e5da5Sopenharmony_ci%ld_sampler = OpLoad %sampler %sampler_var
1555fd4e5da5Sopenharmony_ci%gep = OpAccessChain %ptr_ssbo_v3int %gid %int_0
1556fd4e5da5Sopenharmony_ci%ld_gid = OpLoad %v3int %gep
1557fd4e5da5Sopenharmony_ci%convert = OpConvertUToF %v3float %ld_gid
1558fd4e5da5Sopenharmony_ci%sampled_image = OpSampledImage %sampled %ld_image %ld_sampler
1559fd4e5da5Sopenharmony_ci%sample = OpImageSampleImplicitLod %v4float %sampled_image %convert
1560fd4e5da5Sopenharmony_ciOpReturn
1561fd4e5da5Sopenharmony_ciOpFunctionEnd
1562fd4e5da5Sopenharmony_ci)";
1563fd4e5da5Sopenharmony_ci
1564fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_VULKAN_1_1_SPIRV_1_4);
1565fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 23u);
1566fd4e5da5Sopenharmony_ci}
1567fd4e5da5Sopenharmony_ci
1568fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest, SPV14AddToEntryPoints) {
1569fd4e5da5Sopenharmony_ci  const std::string text = R"(
1570fd4e5da5Sopenharmony_ciOpCapability Shader
1571fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
1572fd4e5da5Sopenharmony_ciOpExtension "SPV_EXT_descriptor_indexing"
1573fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
1574fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %foo "foo" %gid %image_var %sampler_var
1575fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint Fragment {{%\w+}} "foo" {{%\w+}} {{%\w+}} {{%\w+}} %gl_FragCoord
1576fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %foo "bar" %gid %image_var %sampler_var
1577fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint Fragment {{%\w+}} "bar" {{%\w+}} {{%\w+}} {{%\w+}} %gl_FragCoord
1578fd4e5da5Sopenharmony_ciOpExecutionMode %foo OriginUpperLeft
1579fd4e5da5Sopenharmony_ciOpDecorate %image_var DescriptorSet 3
1580fd4e5da5Sopenharmony_ciOpDecorate %image_var Binding 2
1581fd4e5da5Sopenharmony_ciOpDecorate %sampler_var DescriptorSet 3
1582fd4e5da5Sopenharmony_ciOpDecorate %sampler_var Binding 3
1583fd4e5da5Sopenharmony_ciOpDecorate %gid DescriptorSet 3
1584fd4e5da5Sopenharmony_ciOpDecorate %gid Binding 4
1585fd4e5da5Sopenharmony_ciOpDecorate %struct Block
1586fd4e5da5Sopenharmony_ciOpMemberDecorate %struct 0 Offset 0
1587fd4e5da5Sopenharmony_ci%void = OpTypeVoid
1588fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0
1589fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
1590fd4e5da5Sopenharmony_ci%v3int = OpTypeVector %int 3
1591fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
1592fd4e5da5Sopenharmony_ci%v3float = OpTypeVector %float 3
1593fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
1594fd4e5da5Sopenharmony_ci%struct = OpTypeStruct %v3int
1595fd4e5da5Sopenharmony_ci%ptr_ssbo_struct = OpTypePointer StorageBuffer %struct
1596fd4e5da5Sopenharmony_ci%ptr_ssbo_v3int = OpTypePointer StorageBuffer %v3int
1597fd4e5da5Sopenharmony_ci%gid = OpVariable %ptr_ssbo_struct StorageBuffer
1598fd4e5da5Sopenharmony_ci%image = OpTypeImage %float 3D 0 0 0 1 Unknown
1599fd4e5da5Sopenharmony_ci%ptr_uc_image = OpTypePointer UniformConstant %image
1600fd4e5da5Sopenharmony_ci%sampler = OpTypeSampler
1601fd4e5da5Sopenharmony_ci%ptr_uc_sampler = OpTypePointer UniformConstant %sampler
1602fd4e5da5Sopenharmony_ci%image_var = OpVariable %ptr_uc_image UniformConstant
1603fd4e5da5Sopenharmony_ci%sampler_var = OpVariable %ptr_uc_sampler UniformConstant
1604fd4e5da5Sopenharmony_ci%sampled = OpTypeSampledImage %image
1605fd4e5da5Sopenharmony_ci%void_fn = OpTypeFunction %void
1606fd4e5da5Sopenharmony_ci%foo = OpFunction %void None %void_fn
1607fd4e5da5Sopenharmony_ci%entry = OpLabel
1608fd4e5da5Sopenharmony_ci%ld_image = OpLoad %image %image_var
1609fd4e5da5Sopenharmony_ci%ld_sampler = OpLoad %sampler %sampler_var
1610fd4e5da5Sopenharmony_ci%gep = OpAccessChain %ptr_ssbo_v3int %gid %int_0
1611fd4e5da5Sopenharmony_ci%ld_gid = OpLoad %v3int %gep
1612fd4e5da5Sopenharmony_ci%convert = OpConvertUToF %v3float %ld_gid
1613fd4e5da5Sopenharmony_ci%sampled_image = OpSampledImage %sampled %ld_image %ld_sampler
1614fd4e5da5Sopenharmony_ci%sample = OpImageSampleImplicitLod %v4float %sampled_image %convert
1615fd4e5da5Sopenharmony_ciOpReturn
1616fd4e5da5Sopenharmony_ciOpFunctionEnd
1617fd4e5da5Sopenharmony_ci)";
1618fd4e5da5Sopenharmony_ci
1619fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_VULKAN_1_1_SPIRV_1_4);
1620fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 23u);
1621fd4e5da5Sopenharmony_ci}
1622fd4e5da5Sopenharmony_ci
1623fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest, InstBoundsAndInitLoadUnsizedUBOArray) {
1624fd4e5da5Sopenharmony_ci  // #version 450
1625fd4e5da5Sopenharmony_ci  // #extension GL_EXT_nonuniform_qualifier : enable
1626fd4e5da5Sopenharmony_ci  //
1627fd4e5da5Sopenharmony_ci  // layout(location=0) in nonuniformEXT flat int nu_ii;
1628fd4e5da5Sopenharmony_ci  // layout(location=0) out float b;
1629fd4e5da5Sopenharmony_ci  //
1630fd4e5da5Sopenharmony_ci  // layout(set = 6, binding=3)  uniform uname { float a; }  uniformBuffer[];
1631fd4e5da5Sopenharmony_ci  //
1632fd4e5da5Sopenharmony_ci  // void main()
1633fd4e5da5Sopenharmony_ci  // {
1634fd4e5da5Sopenharmony_ci  //     b = uniformBuffer[nu_ii].a;
1635fd4e5da5Sopenharmony_ci  // }
1636fd4e5da5Sopenharmony_ci
1637fd4e5da5Sopenharmony_ci  // clang-format off
1638fd4e5da5Sopenharmony_ci  const std::string defs = R"(
1639fd4e5da5Sopenharmony_ciOpCapability Shader
1640fd4e5da5Sopenharmony_ciOpCapability ShaderNonUniform
1641fd4e5da5Sopenharmony_ciOpCapability RuntimeDescriptorArray
1642fd4e5da5Sopenharmony_ciOpCapability UniformBufferArrayNonUniformIndexing
1643fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
1644fd4e5da5Sopenharmony_ciOpExtension "SPV_EXT_descriptor_indexing"
1645fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
1646fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
1647fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %b %nu_ii
1648fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint Fragment %main "main" %b %nu_ii %gl_FragCoord
1649fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
1650fd4e5da5Sopenharmony_ciOpSource GLSL 450
1651fd4e5da5Sopenharmony_ciOpSourceExtension "GL_EXT_nonuniform_qualifier"
1652fd4e5da5Sopenharmony_ciOpName %main "main"
1653fd4e5da5Sopenharmony_ciOpName %b "b"
1654fd4e5da5Sopenharmony_ciOpName %uname "uname"
1655fd4e5da5Sopenharmony_ciOpMemberName %uname 0 "a"
1656fd4e5da5Sopenharmony_ciOpName %uniformBuffer "uniformBuffer"
1657fd4e5da5Sopenharmony_ciOpName %nu_ii "nu_ii"
1658fd4e5da5Sopenharmony_ciOpDecorate %b Location 0
1659fd4e5da5Sopenharmony_ciOpMemberDecorate %uname 0 Offset 0
1660fd4e5da5Sopenharmony_ciOpDecorate %uname Block
1661fd4e5da5Sopenharmony_ciOpDecorate %uniformBuffer DescriptorSet 6
1662fd4e5da5Sopenharmony_ciOpDecorate %uniformBuffer Binding 3
1663fd4e5da5Sopenharmony_ciOpDecorate %nu_ii Flat
1664fd4e5da5Sopenharmony_ciOpDecorate %nu_ii Location 0
1665fd4e5da5Sopenharmony_ciOpDecorate %nu_ii NonUniform
1666fd4e5da5Sopenharmony_ciOpDecorate %16 NonUniform
1667fd4e5da5Sopenharmony_ciOpDecorate %20 NonUniform
1668fd4e5da5Sopenharmony_ci;CHECK: OpDecorate {{%\w+}} NonUniform
1669fd4e5da5Sopenharmony_ci)" + kImportDeco + R"(
1670fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
1671fd4e5da5Sopenharmony_ci;CHECK: OpDecorate {{%\w+}} NonUniform
1672fd4e5da5Sopenharmony_ci%void = OpTypeVoid
1673fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
1674fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
1675fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
1676fd4e5da5Sopenharmony_ci%b = OpVariable %_ptr_Output_float Output
1677fd4e5da5Sopenharmony_ci%uname = OpTypeStruct %float
1678fd4e5da5Sopenharmony_ci%_runtimearr_uname = OpTypeRuntimeArray %uname
1679fd4e5da5Sopenharmony_ci%_ptr_Uniform__runtimearr_uname = OpTypePointer Uniform %_runtimearr_uname
1680fd4e5da5Sopenharmony_ci%uniformBuffer = OpVariable %_ptr_Uniform__runtimearr_uname Uniform
1681fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
1682fd4e5da5Sopenharmony_ci%_ptr_Input_int = OpTypePointer Input %int
1683fd4e5da5Sopenharmony_ci%nu_ii = OpVariable %_ptr_Input_int Input
1684fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
1685fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float
1686fd4e5da5Sopenharmony_ci;CHECK: %v4uint = OpTypeVector %uint 4
1687fd4e5da5Sopenharmony_ci;CHECK: %v4float = OpTypeVector %float 4
1688fd4e5da5Sopenharmony_ci;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
1689fd4e5da5Sopenharmony_ci;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
1690fd4e5da5Sopenharmony_ci;CHECK: [[null_float:%\w+]] = OpConstantNull %float
1691fd4e5da5Sopenharmony_ci)";
1692fd4e5da5Sopenharmony_ci
1693fd4e5da5Sopenharmony_ci  const std::string main_func = R"(
1694fd4e5da5Sopenharmony_ci%main = OpFunction %void None %3
1695fd4e5da5Sopenharmony_ci%5 = OpLabel
1696fd4e5da5Sopenharmony_ci%16 = OpLoad %int %nu_ii
1697fd4e5da5Sopenharmony_ci%19 = OpAccessChain %_ptr_Uniform_float %uniformBuffer %16 %int_0
1698fd4e5da5Sopenharmony_ci%20 = OpLoad %float %19
1699fd4e5da5Sopenharmony_ciOpStore %b %20
1700fd4e5da5Sopenharmony_ci;CHECK-NOT: %20 = OpLoad %float %19
1701fd4e5da5Sopenharmony_ci;CHECK-NOT: OpStore %b %20
1702fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord
1703fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}}
1704fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
1705fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
1706fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0
1707fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %uint %7
1708fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_46 {{%\w+}} %uint_6 %uint_3 {{%\w+}} {{%\w+}}
1709fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
1710fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
1711fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
1712fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %float %20
1713fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
1714fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
1715fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
1716fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
1717fd4e5da5Sopenharmony_ci;CHECK: [[phi_result:%\w+]] = OpPhi %float {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}}
1718fd4e5da5Sopenharmony_ci;CHECK: OpStore %b [[phi_result]]
1719fd4e5da5Sopenharmony_ciOpReturn
1720fd4e5da5Sopenharmony_ciOpFunctionEnd
1721fd4e5da5Sopenharmony_ci)";
1722fd4e5da5Sopenharmony_ci  // clang-format on
1723fd4e5da5Sopenharmony_ci
1724fd4e5da5Sopenharmony_ci  // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
1725fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(defs + kImportStub + main_func,
1726fd4e5da5Sopenharmony_ci                                               true, 23u);
1727fd4e5da5Sopenharmony_ci}
1728fd4e5da5Sopenharmony_ci
1729fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest, InstBoundsAndInitLoadUnsizedSSBOArrayDeprecated) {
1730fd4e5da5Sopenharmony_ci  // #version 450
1731fd4e5da5Sopenharmony_ci  // #extension GL_EXT_nonuniform_qualifier : enable
1732fd4e5da5Sopenharmony_ci  //
1733fd4e5da5Sopenharmony_ci  // layout(location=0) in nonuniformEXT flat int nu_ii;
1734fd4e5da5Sopenharmony_ci  // layout(location=0) out float b;
1735fd4e5da5Sopenharmony_ci  //
1736fd4e5da5Sopenharmony_ci  // layout(set = 7, binding=3)  buffer bname { float b; }  storageBuffer[];
1737fd4e5da5Sopenharmony_ci  //
1738fd4e5da5Sopenharmony_ci  // void main()
1739fd4e5da5Sopenharmony_ci  // {
1740fd4e5da5Sopenharmony_ci  //     b = storageBuffer[nu_ii].b;
1741fd4e5da5Sopenharmony_ci  // }
1742fd4e5da5Sopenharmony_ci
1743fd4e5da5Sopenharmony_ci  // clang-format off
1744fd4e5da5Sopenharmony_ci  const std::string defs = R"(
1745fd4e5da5Sopenharmony_ciOpCapability Shader
1746fd4e5da5Sopenharmony_ciOpCapability ShaderNonUniform
1747fd4e5da5Sopenharmony_ciOpCapability RuntimeDescriptorArray
1748fd4e5da5Sopenharmony_ciOpCapability StorageBufferArrayNonUniformIndexing
1749fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
1750fd4e5da5Sopenharmony_ciOpExtension "SPV_EXT_descriptor_indexing"
1751fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
1752fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
1753fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %b %nu_ii
1754fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint Fragment %main "main" %b %nu_ii %gl_FragCoord
1755fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
1756fd4e5da5Sopenharmony_ciOpSource GLSL 450
1757fd4e5da5Sopenharmony_ciOpSourceExtension "GL_EXT_nonuniform_qualifier"
1758fd4e5da5Sopenharmony_ciOpName %main "main"
1759fd4e5da5Sopenharmony_ciOpName %b "b"
1760fd4e5da5Sopenharmony_ciOpName %bname "bname"
1761fd4e5da5Sopenharmony_ciOpMemberName %bname 0 "a"
1762fd4e5da5Sopenharmony_ciOpName %storageBuffer "storageBuffer"
1763fd4e5da5Sopenharmony_ciOpName %nu_ii "nu_ii"
1764fd4e5da5Sopenharmony_ciOpDecorate %b Location 0
1765fd4e5da5Sopenharmony_ciOpMemberDecorate %bname 0 Offset 0
1766fd4e5da5Sopenharmony_ciOpDecorate %bname Block
1767fd4e5da5Sopenharmony_ciOpDecorate %storageBuffer DescriptorSet 7
1768fd4e5da5Sopenharmony_ciOpDecorate %storageBuffer Binding 3
1769fd4e5da5Sopenharmony_ciOpDecorate %nu_ii Flat
1770fd4e5da5Sopenharmony_ciOpDecorate %nu_ii Location 0
1771fd4e5da5Sopenharmony_ciOpDecorate %nu_ii NonUniform
1772fd4e5da5Sopenharmony_ciOpDecorate %16 NonUniform
1773fd4e5da5Sopenharmony_ciOpDecorate %20 NonUniform
1774fd4e5da5Sopenharmony_ci)" + kImportDeco + R"(
1775fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
1776fd4e5da5Sopenharmony_ci%void = OpTypeVoid
1777fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
1778fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
1779fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
1780fd4e5da5Sopenharmony_ci%b = OpVariable %_ptr_Output_float Output
1781fd4e5da5Sopenharmony_ci%bname = OpTypeStruct %float
1782fd4e5da5Sopenharmony_ci%_runtimearr_bname = OpTypeRuntimeArray %bname
1783fd4e5da5Sopenharmony_ci%_ptr_StorageBuffer__runtimearr_bname = OpTypePointer StorageBuffer %_runtimearr_bname
1784fd4e5da5Sopenharmony_ci%storageBuffer = OpVariable %_ptr_StorageBuffer__runtimearr_bname StorageBuffer
1785fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
1786fd4e5da5Sopenharmony_ci%_ptr_Input_int = OpTypePointer Input %int
1787fd4e5da5Sopenharmony_ci%nu_ii = OpVariable %_ptr_Input_int Input
1788fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
1789fd4e5da5Sopenharmony_ci%_ptr_StorageBuffer_float = OpTypePointer StorageBuffer %float
1790fd4e5da5Sopenharmony_ci;CHECK: %uint = OpTypeInt 32 0
1791fd4e5da5Sopenharmony_ci;CHECK: %v4uint = OpTypeVector %uint 4
1792fd4e5da5Sopenharmony_ci;CHECK: %v4float = OpTypeVector %float 4
1793fd4e5da5Sopenharmony_ci;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
1794fd4e5da5Sopenharmony_ci;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
1795fd4e5da5Sopenharmony_ci;CHECK: [[null_float:%\w+]] = OpConstantNull %float
1796fd4e5da5Sopenharmony_ci)";
1797fd4e5da5Sopenharmony_ci
1798fd4e5da5Sopenharmony_ci  const std::string main_func = R"(
1799fd4e5da5Sopenharmony_ci%main = OpFunction %void None %3
1800fd4e5da5Sopenharmony_ci%5 = OpLabel
1801fd4e5da5Sopenharmony_ci%16 = OpLoad %int %nu_ii
1802fd4e5da5Sopenharmony_ci%19 = OpAccessChain %_ptr_StorageBuffer_float %storageBuffer %16 %int_0
1803fd4e5da5Sopenharmony_ci%20 = OpLoad %float %19
1804fd4e5da5Sopenharmony_ciOpStore %b %20
1805fd4e5da5Sopenharmony_ci;CHECK-NOT: %20 = OpLoad %float %19
1806fd4e5da5Sopenharmony_ci;CHECK-NOT: OpStore %b %20
1807fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord
1808fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}}
1809fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
1810fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
1811fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0
1812fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %uint %7
1813fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_46 {{%\w+}} %uint_7 %uint_3 {{%\w+}} {{%\w+}}
1814fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
1815fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
1816fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
1817fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %float %20
1818fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
1819fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
1820fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
1821fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
1822fd4e5da5Sopenharmony_ci;CHECK: [[phi_result:%\w+]] = OpPhi %float {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}}
1823fd4e5da5Sopenharmony_ci;CHECK: OpStore %b [[phi_result]]
1824fd4e5da5Sopenharmony_ciOpReturn
1825fd4e5da5Sopenharmony_ciOpFunctionEnd
1826fd4e5da5Sopenharmony_ci)";
1827fd4e5da5Sopenharmony_ci  // clang-format on
1828fd4e5da5Sopenharmony_ci
1829fd4e5da5Sopenharmony_ci  // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
1830fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(defs + kImportStub + main_func,
1831fd4e5da5Sopenharmony_ci                                               true, 23u);
1832fd4e5da5Sopenharmony_ci}
1833fd4e5da5Sopenharmony_ci
1834fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest, InstBoundsAndInitLoadUnsizedSSBOArray) {
1835fd4e5da5Sopenharmony_ci  // Same as Deprecated but declaring as StorageBuffer Block
1836fd4e5da5Sopenharmony_ci
1837fd4e5da5Sopenharmony_ci  // clang-format off
1838fd4e5da5Sopenharmony_ci  const std::string defs = R"(
1839fd4e5da5Sopenharmony_ciOpCapability Shader
1840fd4e5da5Sopenharmony_ciOpCapability ShaderNonUniform
1841fd4e5da5Sopenharmony_ciOpCapability RuntimeDescriptorArray
1842fd4e5da5Sopenharmony_ciOpCapability StorageBufferArrayNonUniformIndexing
1843fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
1844fd4e5da5Sopenharmony_ciOpExtension "SPV_EXT_descriptor_indexing"
1845fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
1846fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
1847fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %b %nu_ii
1848fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint Fragment %main "main" %b %nu_ii %gl_FragCoord
1849fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
1850fd4e5da5Sopenharmony_ciOpSource GLSL 450
1851fd4e5da5Sopenharmony_ciOpSourceExtension "GL_EXT_nonuniform_qualifier"
1852fd4e5da5Sopenharmony_ciOpName %main "main"
1853fd4e5da5Sopenharmony_ciOpName %b "b"
1854fd4e5da5Sopenharmony_ciOpName %bname "bname"
1855fd4e5da5Sopenharmony_ciOpMemberName %bname 0 "a"
1856fd4e5da5Sopenharmony_ciOpName %storageBuffer "storageBuffer"
1857fd4e5da5Sopenharmony_ciOpName %nu_ii "nu_ii"
1858fd4e5da5Sopenharmony_ciOpDecorate %b Location 0
1859fd4e5da5Sopenharmony_ciOpMemberDecorate %bname 0 Offset 0
1860fd4e5da5Sopenharmony_ciOpDecorate %bname Block
1861fd4e5da5Sopenharmony_ciOpDecorate %storageBuffer DescriptorSet 0
1862fd4e5da5Sopenharmony_ciOpDecorate %storageBuffer Binding 3
1863fd4e5da5Sopenharmony_ciOpDecorate %nu_ii Flat
1864fd4e5da5Sopenharmony_ciOpDecorate %nu_ii Location 0
1865fd4e5da5Sopenharmony_ciOpDecorate %nu_ii NonUniform
1866fd4e5da5Sopenharmony_ciOpDecorate %16 NonUniform
1867fd4e5da5Sopenharmony_ciOpDecorate %20 NonUniform
1868fd4e5da5Sopenharmony_ci;CHECK: OpDecorate {{%\w+}} NonUniform
1869fd4e5da5Sopenharmony_ci)" + kImportDeco + R"(
1870fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
1871fd4e5da5Sopenharmony_ci;CHECK: OpDecorate {{%\w+}} NonUniform
1872fd4e5da5Sopenharmony_ci%void = OpTypeVoid
1873fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
1874fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
1875fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
1876fd4e5da5Sopenharmony_ci%b = OpVariable %_ptr_Output_float Output
1877fd4e5da5Sopenharmony_ci%bname = OpTypeStruct %float
1878fd4e5da5Sopenharmony_ci%_runtimearr_bname = OpTypeRuntimeArray %bname
1879fd4e5da5Sopenharmony_ci%_ptr_StorageBuffer__runtimearr_bname = OpTypePointer StorageBuffer %_runtimearr_bname
1880fd4e5da5Sopenharmony_ci%storageBuffer = OpVariable %_ptr_StorageBuffer__runtimearr_bname StorageBuffer
1881fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
1882fd4e5da5Sopenharmony_ci%_ptr_Input_int = OpTypePointer Input %int
1883fd4e5da5Sopenharmony_ci%nu_ii = OpVariable %_ptr_Input_int Input
1884fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
1885fd4e5da5Sopenharmony_ci%_ptr_StorageBuffer_float = OpTypePointer StorageBuffer %float
1886fd4e5da5Sopenharmony_ci;CHECK: %v4uint = OpTypeVector %uint 4
1887fd4e5da5Sopenharmony_ci;CHECK: %v4float = OpTypeVector %float 4
1888fd4e5da5Sopenharmony_ci;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
1889fd4e5da5Sopenharmony_ci;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
1890fd4e5da5Sopenharmony_ci;CHECK: [[null_float:%\w+]] = OpConstantNull %float
1891fd4e5da5Sopenharmony_ci)";
1892fd4e5da5Sopenharmony_ci
1893fd4e5da5Sopenharmony_ci  const std::string main_func = R"(
1894fd4e5da5Sopenharmony_ci%main = OpFunction %void None %3
1895fd4e5da5Sopenharmony_ci%5 = OpLabel
1896fd4e5da5Sopenharmony_ci%16 = OpLoad %int %nu_ii
1897fd4e5da5Sopenharmony_ci%19 = OpAccessChain %_ptr_StorageBuffer_float %storageBuffer %16 %int_0
1898fd4e5da5Sopenharmony_ci%20 = OpLoad %float %19
1899fd4e5da5Sopenharmony_ciOpStore %b %20
1900fd4e5da5Sopenharmony_ci;CHECK-NOT: %20 = OpLoad %float %19
1901fd4e5da5Sopenharmony_ci;CHECK-NOT: OpStore %b %20
1902fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord
1903fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}}
1904fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
1905fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
1906fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0
1907fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %uint %7
1908fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_46 {{%\w+}} %uint_0 %uint_3 {{%\w+}} {{%\w+}}
1909fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
1910fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
1911fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
1912fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %float %20
1913fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
1914fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
1915fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
1916fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
1917fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpPhi %float {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}}
1918fd4e5da5Sopenharmony_ci;CHECK: OpStore %b {{%\w+}}
1919fd4e5da5Sopenharmony_ciOpReturn
1920fd4e5da5Sopenharmony_ciOpFunctionEnd
1921fd4e5da5Sopenharmony_ci)";
1922fd4e5da5Sopenharmony_ci  // clang-format on
1923fd4e5da5Sopenharmony_ci
1924fd4e5da5Sopenharmony_ci  // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
1925fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(defs + kImportStub + main_func,
1926fd4e5da5Sopenharmony_ci                                               true, 23u);
1927fd4e5da5Sopenharmony_ci}
1928fd4e5da5Sopenharmony_ci
1929fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest, InstInitLoadUBOScalar) {
1930fd4e5da5Sopenharmony_ci  // #version 450
1931fd4e5da5Sopenharmony_ci  // #extension GL_EXT_nonuniform_qualifier : enable
1932fd4e5da5Sopenharmony_ci  //
1933fd4e5da5Sopenharmony_ci  // layout(location=0) out float b;
1934fd4e5da5Sopenharmony_ci  // layout(set=7, binding=3)  uniform uname { float a; }  uniformBuffer;
1935fd4e5da5Sopenharmony_ci  //
1936fd4e5da5Sopenharmony_ci  // void main()
1937fd4e5da5Sopenharmony_ci  // {
1938fd4e5da5Sopenharmony_ci  //     b = uniformBuffer.a;
1939fd4e5da5Sopenharmony_ci  // }
1940fd4e5da5Sopenharmony_ci
1941fd4e5da5Sopenharmony_ci  // clang-format off
1942fd4e5da5Sopenharmony_ci  const std::string defs = R"(
1943fd4e5da5Sopenharmony_ciOpCapability Shader
1944fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
1945fd4e5da5Sopenharmony_ciOpExtension "SPV_EXT_descriptor_indexing"
1946fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
1947fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
1948fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %b
1949fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint Fragment %main "main" %b %gl_FragCoord
1950fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
1951fd4e5da5Sopenharmony_ciOpSource GLSL 450
1952fd4e5da5Sopenharmony_ciOpSourceExtension "GL_EXT_nonuniform_qualifier"
1953fd4e5da5Sopenharmony_ciOpName %main "main"
1954fd4e5da5Sopenharmony_ciOpName %b "b"
1955fd4e5da5Sopenharmony_ciOpName %uname "uname"
1956fd4e5da5Sopenharmony_ciOpMemberName %uname 0 "a"
1957fd4e5da5Sopenharmony_ciOpName %uniformBuffer "uniformBuffer"
1958fd4e5da5Sopenharmony_ciOpDecorate %b Location 0
1959fd4e5da5Sopenharmony_ciOpMemberDecorate %uname 0 Offset 0
1960fd4e5da5Sopenharmony_ciOpDecorate %uname Block
1961fd4e5da5Sopenharmony_ciOpDecorate %uniformBuffer DescriptorSet 7
1962fd4e5da5Sopenharmony_ciOpDecorate %uniformBuffer Binding 3
1963fd4e5da5Sopenharmony_ci)" + kImportDeco + R"(
1964fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
1965fd4e5da5Sopenharmony_ci%void = OpTypeVoid
1966fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
1967fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
1968fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
1969fd4e5da5Sopenharmony_ci%b = OpVariable %_ptr_Output_float Output
1970fd4e5da5Sopenharmony_ci%uname = OpTypeStruct %float
1971fd4e5da5Sopenharmony_ci%_ptr_Uniform_uname = OpTypePointer Uniform %uname
1972fd4e5da5Sopenharmony_ci%uniformBuffer = OpVariable %_ptr_Uniform_uname Uniform
1973fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
1974fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
1975fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float
1976fd4e5da5Sopenharmony_ci;CHECK: %int = OpTypeInt 32 1
1977fd4e5da5Sopenharmony_ci;CHECK: %_ptr_Uniform_float = OpTypePointer Uniform %float
1978fd4e5da5Sopenharmony_ci;CHECK: %uint = OpTypeInt 32 0
1979fd4e5da5Sopenharmony_ci;CHECK: %v4uint = OpTypeVector %uint 4
1980fd4e5da5Sopenharmony_ci;CHECK: %v4float = OpTypeVector %float 4
1981fd4e5da5Sopenharmony_ci;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
1982fd4e5da5Sopenharmony_ci;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
1983fd4e5da5Sopenharmony_ci;CHECK: [[null_float:%\w+]] = OpConstantNull %float
1984fd4e5da5Sopenharmony_ci)";
1985fd4e5da5Sopenharmony_ci
1986fd4e5da5Sopenharmony_ci  const std::string main_func = R"(
1987fd4e5da5Sopenharmony_ci%main = OpFunction %void None %3
1988fd4e5da5Sopenharmony_ci%5 = OpLabel
1989fd4e5da5Sopenharmony_ci%15 = OpAccessChain %_ptr_Uniform_float %uniformBuffer %int_0
1990fd4e5da5Sopenharmony_ci%16 = OpLoad %float %15
1991fd4e5da5Sopenharmony_ciOpStore %b %16
1992fd4e5da5Sopenharmony_ci;CHECK-NOT: %16 = OpLoad %float %15
1993fd4e5da5Sopenharmony_ci;CHECK-NOT: OpStore %b %16
1994fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord
1995fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}}
1996fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
1997fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
1998fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0
1999fd4e5da5Sopenharmony_ci;CHECK: [[check_result:%\w+]] = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_33 {{%\w+}} %uint_7 %uint_3 %uint_0 {{%\w+}}
2000fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
2001fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional [[check_result]] {{%\w+}} {{%\w+}}
2002fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2003fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %float %15
2004fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
2005fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2006fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
2007fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2008fd4e5da5Sopenharmony_ci;CHECK: [[phi_result:%\w+]] = OpPhi %float {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}}
2009fd4e5da5Sopenharmony_ci;CHECK: OpStore %b [[phi_result]]
2010fd4e5da5Sopenharmony_ciOpReturn
2011fd4e5da5Sopenharmony_ciOpFunctionEnd
2012fd4e5da5Sopenharmony_ci)";
2013fd4e5da5Sopenharmony_ci  // clang-format on
2014fd4e5da5Sopenharmony_ci
2015fd4e5da5Sopenharmony_ci  // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
2016fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(defs + kImportStub + main_func,
2017fd4e5da5Sopenharmony_ci                                               true, 23u);
2018fd4e5da5Sopenharmony_ci}
2019fd4e5da5Sopenharmony_ci
2020fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest, InstBoundsInitStoreUnsizedSSBOArray) {
2021fd4e5da5Sopenharmony_ci  // #version 450
2022fd4e5da5Sopenharmony_ci  // #extension GL_EXT_nonuniform_qualifier : enable
2023fd4e5da5Sopenharmony_ci  //
2024fd4e5da5Sopenharmony_ci  // layout(location=0) in nonuniformEXT flat int nu_ii;
2025fd4e5da5Sopenharmony_ci  // layout(location=1) in float b;
2026fd4e5da5Sopenharmony_ci  //
2027fd4e5da5Sopenharmony_ci  // layout(set=5, binding=4)  buffer bname { float b; }  storageBuffer[];
2028fd4e5da5Sopenharmony_ci  //
2029fd4e5da5Sopenharmony_ci  // void main()
2030fd4e5da5Sopenharmony_ci  // {
2031fd4e5da5Sopenharmony_ci  //     storageBuffer[nu_ii].b = b;
2032fd4e5da5Sopenharmony_ci  // }
2033fd4e5da5Sopenharmony_ci
2034fd4e5da5Sopenharmony_ci  // clang-format off
2035fd4e5da5Sopenharmony_ci  const std::string defs = R"(OpCapability Shader
2036fd4e5da5Sopenharmony_ciOpCapability ShaderNonUniform
2037fd4e5da5Sopenharmony_ciOpCapability RuntimeDescriptorArray
2038fd4e5da5Sopenharmony_ciOpCapability StorageBufferArrayNonUniformIndexing
2039fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
2040fd4e5da5Sopenharmony_ciOpExtension "SPV_EXT_descriptor_indexing"
2041fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
2042fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
2043fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %nu_ii %b
2044fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint Fragment %main "main" %nu_ii %b %gl_FragCoord
2045fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
2046fd4e5da5Sopenharmony_ciOpSource GLSL 450
2047fd4e5da5Sopenharmony_ciOpSourceExtension "GL_EXT_nonuniform_qualifier"
2048fd4e5da5Sopenharmony_ciOpName %main "main"
2049fd4e5da5Sopenharmony_ciOpName %bname "bname"
2050fd4e5da5Sopenharmony_ciOpMemberName %bname 0 "b"
2051fd4e5da5Sopenharmony_ciOpName %storageBuffer "storageBuffer"
2052fd4e5da5Sopenharmony_ciOpName %nu_ii "nu_ii"
2053fd4e5da5Sopenharmony_ciOpName %b "b"
2054fd4e5da5Sopenharmony_ciOpMemberDecorate %bname 0 Offset 0
2055fd4e5da5Sopenharmony_ciOpDecorate %bname BufferBlock
2056fd4e5da5Sopenharmony_ciOpDecorate %storageBuffer DescriptorSet 5
2057fd4e5da5Sopenharmony_ciOpDecorate %storageBuffer Binding 4
2058fd4e5da5Sopenharmony_ciOpDecorate %nu_ii Flat
2059fd4e5da5Sopenharmony_ciOpDecorate %nu_ii Location 0
2060fd4e5da5Sopenharmony_ciOpDecorate %nu_ii NonUniform
2061fd4e5da5Sopenharmony_ciOpDecorate %14 NonUniform
2062fd4e5da5Sopenharmony_ciOpDecorate %b Location 1
2063fd4e5da5Sopenharmony_ci)" + kImportDeco + R"(
2064fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
2065fd4e5da5Sopenharmony_ci%void = OpTypeVoid
2066fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
2067fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
2068fd4e5da5Sopenharmony_ci%bname = OpTypeStruct %float
2069fd4e5da5Sopenharmony_ci%_runtimearr_bname = OpTypeRuntimeArray %bname
2070fd4e5da5Sopenharmony_ci%_ptr_Uniform__runtimearr_bname = OpTypePointer Uniform %_runtimearr_bname
2071fd4e5da5Sopenharmony_ci%storageBuffer = OpVariable %_ptr_Uniform__runtimearr_bname Uniform
2072fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
2073fd4e5da5Sopenharmony_ci%_ptr_Input_int = OpTypePointer Input %int
2074fd4e5da5Sopenharmony_ci%nu_ii = OpVariable %_ptr_Input_int Input
2075fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
2076fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
2077fd4e5da5Sopenharmony_ci%b = OpVariable %_ptr_Input_float Input
2078fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float
2079fd4e5da5Sopenharmony_ci;CHECK: %v4uint = OpTypeVector %uint 4
2080fd4e5da5Sopenharmony_ci;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
2081fd4e5da5Sopenharmony_ci)";
2082fd4e5da5Sopenharmony_ci
2083fd4e5da5Sopenharmony_ci  const std::string main_func = R"(
2084fd4e5da5Sopenharmony_ci%main = OpFunction %void None %3
2085fd4e5da5Sopenharmony_ci%5 = OpLabel
2086fd4e5da5Sopenharmony_ci%14 = OpLoad %int %nu_ii
2087fd4e5da5Sopenharmony_ci%18 = OpLoad %float %b
2088fd4e5da5Sopenharmony_ci%20 = OpAccessChain %_ptr_Uniform_float %storageBuffer %14 %int_0
2089fd4e5da5Sopenharmony_ciOpStore %20 %18
2090fd4e5da5Sopenharmony_ci;CHECK-NOT: OpStore %20 %18
2091fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord
2092fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}}
2093fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
2094fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
2095fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0
2096fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %uint %7
2097fd4e5da5Sopenharmony_ci;CHECK: [[check_result:%\w+]] = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_46 {{%\w+}} %uint_5 %uint_4 {{%\w+}} {{%\w+}}
2098fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
2099fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional [[check_result]] {{%\w+}} {{%\w+}}
2100fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2101fd4e5da5Sopenharmony_ci;CHECK: OpStore %20 %19
2102fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
2103fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2104fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
2105fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2106fd4e5da5Sopenharmony_ciOpReturn
2107fd4e5da5Sopenharmony_ciOpFunctionEnd
2108fd4e5da5Sopenharmony_ci)";
2109fd4e5da5Sopenharmony_ci  // clang-format on
2110fd4e5da5Sopenharmony_ci
2111fd4e5da5Sopenharmony_ci  // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
2112fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(defs + kImportStub + main_func,
2113fd4e5da5Sopenharmony_ci                                               true, 23u);
2114fd4e5da5Sopenharmony_ci}
2115fd4e5da5Sopenharmony_ci
2116fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest, InstBoundsInitLoadSizedUBOArray) {
2117fd4e5da5Sopenharmony_ci  // #version 450
2118fd4e5da5Sopenharmony_ci  // #extension GL_EXT_nonuniform_qualifier : enable
2119fd4e5da5Sopenharmony_ci  //
2120fd4e5da5Sopenharmony_ci  // layout(location=0) in nonuniformEXT flat int nu_ii;
2121fd4e5da5Sopenharmony_ci  // layout(location=0) out float b;
2122fd4e5da5Sopenharmony_ci  //
2123fd4e5da5Sopenharmony_ci  // layout(set=1, binding=3)  uniform uname { float a; }  uniformBuffer[128];
2124fd4e5da5Sopenharmony_ci  //
2125fd4e5da5Sopenharmony_ci  // void main()
2126fd4e5da5Sopenharmony_ci  // {
2127fd4e5da5Sopenharmony_ci  //     b = uniformBuffer[nu_ii].a;
2128fd4e5da5Sopenharmony_ci  // }
2129fd4e5da5Sopenharmony_ci
2130fd4e5da5Sopenharmony_ci  // clang-format off
2131fd4e5da5Sopenharmony_ci  const std::string defs = R"(
2132fd4e5da5Sopenharmony_ciOpCapability Shader
2133fd4e5da5Sopenharmony_ciOpCapability ShaderNonUniform
2134fd4e5da5Sopenharmony_ciOpCapability UniformBufferArrayNonUniformIndexing
2135fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
2136fd4e5da5Sopenharmony_ciOpExtension "SPV_EXT_descriptor_indexing"
2137fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
2138fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
2139fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %b %nu_ii
2140fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint Fragment %main "main" %b %nu_ii %gl_FragCoord
2141fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
2142fd4e5da5Sopenharmony_ciOpSource GLSL 450
2143fd4e5da5Sopenharmony_ciOpSourceExtension "GL_EXT_nonuniform_qualifier"
2144fd4e5da5Sopenharmony_ciOpName %main "main"
2145fd4e5da5Sopenharmony_ciOpName %b "b"
2146fd4e5da5Sopenharmony_ciOpName %uname "uname"
2147fd4e5da5Sopenharmony_ciOpMemberName %uname 0 "a"
2148fd4e5da5Sopenharmony_ciOpName %uniformBuffer "uniformBuffer"
2149fd4e5da5Sopenharmony_ciOpName %nu_ii "nu_ii"
2150fd4e5da5Sopenharmony_ciOpDecorate %b Location 0
2151fd4e5da5Sopenharmony_ciOpMemberDecorate %uname 0 Offset 0
2152fd4e5da5Sopenharmony_ciOpDecorate %uname Block
2153fd4e5da5Sopenharmony_ciOpDecorate %uniformBuffer DescriptorSet 1
2154fd4e5da5Sopenharmony_ciOpDecorate %uniformBuffer Binding 3
2155fd4e5da5Sopenharmony_ciOpDecorate %nu_ii Flat
2156fd4e5da5Sopenharmony_ciOpDecorate %nu_ii Location 0
2157fd4e5da5Sopenharmony_ciOpDecorate %nu_ii NonUniform
2158fd4e5da5Sopenharmony_ciOpDecorate %18 NonUniform
2159fd4e5da5Sopenharmony_ciOpDecorate %22 NonUniform
2160fd4e5da5Sopenharmony_ci)" + kImportDeco + R"(
2161fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
2162fd4e5da5Sopenharmony_ci;CHECK: OpDecorate [[load_result:%\w+]] NonUniform
2163fd4e5da5Sopenharmony_ci%void = OpTypeVoid
2164fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
2165fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
2166fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
2167fd4e5da5Sopenharmony_ci%b = OpVariable %_ptr_Output_float Output
2168fd4e5da5Sopenharmony_ci%uname = OpTypeStruct %float
2169fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
2170fd4e5da5Sopenharmony_ci%uint_128 = OpConstant %uint 128
2171fd4e5da5Sopenharmony_ci%_arr_uname_uint_128 = OpTypeArray %uname %uint_128
2172fd4e5da5Sopenharmony_ci%_ptr_Uniform__arr_uname_uint_128 = OpTypePointer Uniform %_arr_uname_uint_128
2173fd4e5da5Sopenharmony_ci%uniformBuffer = OpVariable %_ptr_Uniform__arr_uname_uint_128 Uniform
2174fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
2175fd4e5da5Sopenharmony_ci%_ptr_Input_int = OpTypePointer Input %int
2176fd4e5da5Sopenharmony_ci%nu_ii = OpVariable %_ptr_Input_int Input
2177fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
2178fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float
2179fd4e5da5Sopenharmony_ci;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
2180fd4e5da5Sopenharmony_ci;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
2181fd4e5da5Sopenharmony_ci;CHECK: [[null_float:%\w+]] = OpConstantNull %float
2182fd4e5da5Sopenharmony_ci)";
2183fd4e5da5Sopenharmony_ci
2184fd4e5da5Sopenharmony_ci  const std::string main_func = R"(
2185fd4e5da5Sopenharmony_ci%main = OpFunction %void None %3
2186fd4e5da5Sopenharmony_ci%5 = OpLabel
2187fd4e5da5Sopenharmony_ci%18 = OpLoad %int %nu_ii
2188fd4e5da5Sopenharmony_ci%21 = OpAccessChain %_ptr_Uniform_float %uniformBuffer %18 %int_0
2189fd4e5da5Sopenharmony_ci%22 = OpLoad %float %21
2190fd4e5da5Sopenharmony_ciOpStore %b %22
2191fd4e5da5Sopenharmony_ci;CHECK-NOT: %22 = OpLoad %float %21
2192fd4e5da5Sopenharmony_ci;CHECK-NOT: OpStore %b %22
2193fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord
2194fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}}
2195fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
2196fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
2197fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0
2198fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %uint %7
2199fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_47 {{%\w+}} %uint_1 %uint_3 {{%\w+}} {{%\w+}}
2200fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
2201fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
2202fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2203fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %float %22
2204fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
2205fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2206fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
2207fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2208fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpPhi %float {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}}
2209fd4e5da5Sopenharmony_ci;CHECK: OpStore %b {{%\w+}}
2210fd4e5da5Sopenharmony_ciOpReturn
2211fd4e5da5Sopenharmony_ciOpFunctionEnd
2212fd4e5da5Sopenharmony_ci)";
2213fd4e5da5Sopenharmony_ci  // clang-format on
2214fd4e5da5Sopenharmony_ci
2215fd4e5da5Sopenharmony_ci  // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
2216fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(defs + kImportStub + main_func,
2217fd4e5da5Sopenharmony_ci                                               true, 23u);
2218fd4e5da5Sopenharmony_ci}
2219fd4e5da5Sopenharmony_ci
2220fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest,
2221fd4e5da5Sopenharmony_ci       InstBoundsComputeShaderInitLoadVariableSizedSampledImagesArray) {
2222fd4e5da5Sopenharmony_ci  // #version 450
2223fd4e5da5Sopenharmony_ci  // #extension GL_EXT_nonuniform_qualifier : enable
2224fd4e5da5Sopenharmony_ci  //
2225fd4e5da5Sopenharmony_ci  // layout (local_size_x = 1, local_size_y = 1) in;
2226fd4e5da5Sopenharmony_ci  //
2227fd4e5da5Sopenharmony_ci  // layout(set = 2, binding = 0, std140) buffer Input {
2228fd4e5da5Sopenharmony_ci  //   uint index;
2229fd4e5da5Sopenharmony_ci  //   float red;
2230fd4e5da5Sopenharmony_ci  // } sbo;
2231fd4e5da5Sopenharmony_ci  //
2232fd4e5da5Sopenharmony_ci  // layout(set = 2, binding = 1, rgba32f) readonly uniform image2D images[];
2233fd4e5da5Sopenharmony_ci  //
2234fd4e5da5Sopenharmony_ci  // void main()
2235fd4e5da5Sopenharmony_ci  // {
2236fd4e5da5Sopenharmony_ci  //    sbo.red = imageLoad(images[sbo.index], ivec2(0, 0)).r;
2237fd4e5da5Sopenharmony_ci  // }
2238fd4e5da5Sopenharmony_ci
2239fd4e5da5Sopenharmony_ci  // clang-format off
2240fd4e5da5Sopenharmony_ci  const std::string defs = R"(
2241fd4e5da5Sopenharmony_ciOpCapability Shader
2242fd4e5da5Sopenharmony_ciOpCapability RuntimeDescriptorArray
2243fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
2244fd4e5da5Sopenharmony_ciOpExtension "SPV_EXT_descriptor_indexing"
2245fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
2246fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
2247fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %main "main"
2248fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint GLCompute %main "main" %gl_GlobalInvocationID
2249fd4e5da5Sopenharmony_ciOpExecutionMode %main LocalSize 1 1 1
2250fd4e5da5Sopenharmony_ciOpSource GLSL 450
2251fd4e5da5Sopenharmony_ciOpSourceExtension "GL_EXT_nonuniform_qualifier"
2252fd4e5da5Sopenharmony_ciOpName %main "main"
2253fd4e5da5Sopenharmony_ciOpName %Input "Input"
2254fd4e5da5Sopenharmony_ciOpMemberName %Input 0 "index"
2255fd4e5da5Sopenharmony_ciOpMemberName %Input 1 "red"
2256fd4e5da5Sopenharmony_ciOpName %sbo "sbo"
2257fd4e5da5Sopenharmony_ciOpName %images "images"
2258fd4e5da5Sopenharmony_ciOpMemberDecorate %Input 0 Offset 0
2259fd4e5da5Sopenharmony_ciOpMemberDecorate %Input 1 Offset 4
2260fd4e5da5Sopenharmony_ciOpDecorate %Input BufferBlock
2261fd4e5da5Sopenharmony_ciOpDecorate %sbo DescriptorSet 2
2262fd4e5da5Sopenharmony_ciOpDecorate %sbo Binding 0
2263fd4e5da5Sopenharmony_ciOpDecorate %images DescriptorSet 2
2264fd4e5da5Sopenharmony_ciOpDecorate %images Binding 1
2265fd4e5da5Sopenharmony_ciOpDecorate %images NonWritable
2266fd4e5da5Sopenharmony_ci)" + kImportDeco + R"(
2267fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId
2268fd4e5da5Sopenharmony_ci%void = OpTypeVoid
2269fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
2270fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
2271fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
2272fd4e5da5Sopenharmony_ci%Input = OpTypeStruct %uint %float
2273fd4e5da5Sopenharmony_ci%_ptr_Uniform_Input = OpTypePointer Uniform %Input
2274fd4e5da5Sopenharmony_ci%sbo = OpVariable %_ptr_Uniform_Input Uniform
2275fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
2276fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
2277fd4e5da5Sopenharmony_ci%13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
2278fd4e5da5Sopenharmony_ci%_runtimearr_13 = OpTypeRuntimeArray %13
2279fd4e5da5Sopenharmony_ci%_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
2280fd4e5da5Sopenharmony_ci%images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
2281fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
2282fd4e5da5Sopenharmony_ci%_ptr_Uniform_uint = OpTypePointer Uniform %uint
2283fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
2284fd4e5da5Sopenharmony_ci%v2int = OpTypeVector %int 2
2285fd4e5da5Sopenharmony_ci%25 = OpConstantComposite %v2int %int_0 %int_0
2286fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
2287fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
2288fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float
2289fd4e5da5Sopenharmony_ci;CHECK: %v3uint = OpTypeVector %uint 3
2290fd4e5da5Sopenharmony_ci;CHECK: %_ptr_Input_v3uint = OpTypePointer Input %v3uint
2291fd4e5da5Sopenharmony_ci;CHECK: %gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input
2292fd4e5da5Sopenharmony_ci;CHECK: [[null_uint:%\w+]] = OpConstantNull %uint
2293fd4e5da5Sopenharmony_ci;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
2294fd4e5da5Sopenharmony_ci)";
2295fd4e5da5Sopenharmony_ci
2296fd4e5da5Sopenharmony_ci  const std::string main_func = R"(
2297fd4e5da5Sopenharmony_ci%main = OpFunction %void None %3
2298fd4e5da5Sopenharmony_ci%5 = OpLabel
2299fd4e5da5Sopenharmony_ci%19 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
2300fd4e5da5Sopenharmony_ci%20 = OpLoad %uint %19
2301fd4e5da5Sopenharmony_ci%22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
2302fd4e5da5Sopenharmony_ci%23 = OpLoad %13 %22
2303fd4e5da5Sopenharmony_ci%27 = OpImageRead %v4float %23 %25
2304fd4e5da5Sopenharmony_ci%29 = OpCompositeExtract %float %27 0
2305fd4e5da5Sopenharmony_ci%31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
2306fd4e5da5Sopenharmony_ciOpStore %31 %29
2307fd4e5da5Sopenharmony_ci;CHECK-NOT: OpStore %31 %29
2308fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v3uint %gl_GlobalInvocationID
2309fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
2310fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
2311fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2
2312fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5 {{%\w+}} {{%\w+}} {{%\w+}}
2313fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_48 {{%\w+}} %uint_2 %uint_0 %uint_0 {{%\w+}}
2314fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
2315fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
2316fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2317fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %uint %25
2318fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
2319fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2320fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
2321fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2322fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpPhi %uint {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}}
2323fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpAccessChain %_ptr_UniformConstant_13 %images {{%\w+}}
2324fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %13 {{%\w+}}
2325fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v3uint %gl_GlobalInvocationID
2326fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
2327fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
2328fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2
2329fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5 {{%\w+}} {{%\w+}} {{%\w+}}
2330fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_51 {{%\w+}} %uint_2 %uint_1 {{%\w+}} %uint_0
2331fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
2332fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
2333fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2334fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %13 {{%\w+}}
2335fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpImageRead %v4float {{%\w+}} %20
2336fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
2337fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2338fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
2339fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2340fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}}
2341fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %float {{%\w+}} 0
2342fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpAccessChain %_ptr_Uniform_float %sbo %int_1
2343fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v3uint %gl_GlobalInvocationID
2344fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
2345fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
2346fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2
2347fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5 {{%\w+}} {{%\w+}} {{%\w+}}
2348fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_54 {{%\w+}} %uint_2 %uint_0 %uint_0 {{%\w+}}
2349fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
2350fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
2351fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2352fd4e5da5Sopenharmony_ci;CHECK: OpStore %31 {{%\w+}}
2353fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
2354fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2355fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
2356fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2357fd4e5da5Sopenharmony_ciOpReturn
2358fd4e5da5Sopenharmony_ciOpFunctionEnd
2359fd4e5da5Sopenharmony_ci)";
2360fd4e5da5Sopenharmony_ci  // clang-format on
2361fd4e5da5Sopenharmony_ci
2362fd4e5da5Sopenharmony_ci  // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
2363fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(defs + kImportStub + main_func,
2364fd4e5da5Sopenharmony_ci                                               true, 23u);
2365fd4e5da5Sopenharmony_ci}
2366fd4e5da5Sopenharmony_ci
2367fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest,
2368fd4e5da5Sopenharmony_ci       InstBoundsRayGenerationInitLoadVariableSizedSampledImagesArray) {
2369fd4e5da5Sopenharmony_ci  // #version 460
2370fd4e5da5Sopenharmony_ci  // #extension GL_EXT_nonuniform_qualifier : require
2371fd4e5da5Sopenharmony_ci  // #extension GL_NV_ray_tracing : require
2372fd4e5da5Sopenharmony_ci  //
2373fd4e5da5Sopenharmony_ci  // layout(set = 3, binding = 1, std140) buffer StorageBuffer {
2374fd4e5da5Sopenharmony_ci  //   uint index;
2375fd4e5da5Sopenharmony_ci  //   float red;
2376fd4e5da5Sopenharmony_ci  // } sbo;
2377fd4e5da5Sopenharmony_ci  //
2378fd4e5da5Sopenharmony_ci  // layout(set = 3, binding = 5, rgba32f) readonly uniform image2D images[];
2379fd4e5da5Sopenharmony_ci  //
2380fd4e5da5Sopenharmony_ci  // void main()
2381fd4e5da5Sopenharmony_ci  // {
2382fd4e5da5Sopenharmony_ci  //    sbo.red = imageLoad(images[sbo.index], ivec2(0, 0)).r;
2383fd4e5da5Sopenharmony_ci  // }
2384fd4e5da5Sopenharmony_ci
2385fd4e5da5Sopenharmony_ci  // clang-format off
2386fd4e5da5Sopenharmony_ci  const std::string defs = R"(
2387fd4e5da5Sopenharmony_ciOpCapability RuntimeDescriptorArray
2388fd4e5da5Sopenharmony_ciOpCapability RayTracingNV
2389fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
2390fd4e5da5Sopenharmony_ciOpExtension "SPV_EXT_descriptor_indexing"
2391fd4e5da5Sopenharmony_ciOpExtension "SPV_NV_ray_tracing"
2392fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
2393fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
2394fd4e5da5Sopenharmony_ciOpEntryPoint RayGenerationNV %main "main"
2395fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint RayGenerationNV %main "main" [[launch_id:%\w+]]
2396fd4e5da5Sopenharmony_ciOpSource GLSL 460
2397fd4e5da5Sopenharmony_ciOpSourceExtension "GL_EXT_nonuniform_qualifier"
2398fd4e5da5Sopenharmony_ciOpSourceExtension "GL_NV_ray_tracing"
2399fd4e5da5Sopenharmony_ciOpName %main "main"
2400fd4e5da5Sopenharmony_ciOpName %StorageBuffer "StorageBuffer"
2401fd4e5da5Sopenharmony_ciOpMemberName %StorageBuffer 0 "index"
2402fd4e5da5Sopenharmony_ciOpMemberName %StorageBuffer 1 "red"
2403fd4e5da5Sopenharmony_ciOpName %sbo "sbo"
2404fd4e5da5Sopenharmony_ciOpName %images "images"
2405fd4e5da5Sopenharmony_ciOpMemberDecorate %StorageBuffer 0 Offset 0
2406fd4e5da5Sopenharmony_ciOpMemberDecorate %StorageBuffer 1 Offset 4
2407fd4e5da5Sopenharmony_ciOpDecorate %StorageBuffer BufferBlock
2408fd4e5da5Sopenharmony_ciOpDecorate %sbo DescriptorSet 3
2409fd4e5da5Sopenharmony_ciOpDecorate %sbo Binding 1
2410fd4e5da5Sopenharmony_ciOpDecorate %images DescriptorSet 3
2411fd4e5da5Sopenharmony_ciOpDecorate %images Binding 5
2412fd4e5da5Sopenharmony_ciOpDecorate %images NonWritable
2413fd4e5da5Sopenharmony_ci)" + kImportDeco + R"(
2414fd4e5da5Sopenharmony_ci;CHECK: OpDecorate [[launch_id]] BuiltIn LaunchIdNV
2415fd4e5da5Sopenharmony_ci%void = OpTypeVoid
2416fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
2417fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
2418fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
2419fd4e5da5Sopenharmony_ci%StorageBuffer = OpTypeStruct %uint %float
2420fd4e5da5Sopenharmony_ci%_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
2421fd4e5da5Sopenharmony_ci%sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
2422fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
2423fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
2424fd4e5da5Sopenharmony_ci%13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
2425fd4e5da5Sopenharmony_ci%_runtimearr_13 = OpTypeRuntimeArray %13
2426fd4e5da5Sopenharmony_ci%_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
2427fd4e5da5Sopenharmony_ci%images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
2428fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
2429fd4e5da5Sopenharmony_ci%_ptr_Uniform_uint = OpTypePointer Uniform %uint
2430fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
2431fd4e5da5Sopenharmony_ci%v2int = OpTypeVector %int 2
2432fd4e5da5Sopenharmony_ci%25 = OpConstantComposite %v2int %int_0 %int_0
2433fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
2434fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
2435fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float
2436fd4e5da5Sopenharmony_ci;CHECK: [[null_uint:%\w+]] = OpConstantNull %uint
2437fd4e5da5Sopenharmony_ci;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
2438fd4e5da5Sopenharmony_ci)";
2439fd4e5da5Sopenharmony_ci
2440fd4e5da5Sopenharmony_ci  const std::string main_func = R"(
2441fd4e5da5Sopenharmony_ci%main = OpFunction %void None %3
2442fd4e5da5Sopenharmony_ci%5 = OpLabel
2443fd4e5da5Sopenharmony_ci%19 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
2444fd4e5da5Sopenharmony_ci%20 = OpLoad %uint %19
2445fd4e5da5Sopenharmony_ci%22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
2446fd4e5da5Sopenharmony_ci%23 = OpLoad %13 %22
2447fd4e5da5Sopenharmony_ci%27 = OpImageRead %v4float %23 %25
2448fd4e5da5Sopenharmony_ci%29 = OpCompositeExtract %float %27 0
2449fd4e5da5Sopenharmony_ci%31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
2450fd4e5da5Sopenharmony_ciOpStore %31 %29
2451fd4e5da5Sopenharmony_ci;CHECK-NOT: OpStore %31 %29
2452fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}}
2453fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
2454fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
2455fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2
2456fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5313 {{%\w+}} {{%\w+}} {{%\w+}}
2457fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_49 {{%\w+}} %uint_3 %uint_1 %uint_0 {{%\w+}}
2458fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
2459fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
2460fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2461fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %uint %25
2462fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
2463fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2464fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
2465fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2466fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpPhi %uint {{%\w+}} {{%\w+}} [[null_uint]] {{%\w+}}
2467fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpAccessChain %_ptr_UniformConstant_13 %images {{%\w+}}
2468fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %13 {{%\w+}}
2469fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}}
2470fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
2471fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
2472fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2
2473fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5313 {{%\w+}} {{%\w+}} {{%\w+}}
2474fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_52 {{%\w+}} %uint_3 %uint_5 {{%\w+}} %uint_0
2475fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
2476fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
2477fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2478fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %13 {{%\w+}}
2479fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpImageRead %v4float {{%\w+}} %20
2480fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
2481fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2482fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
2483fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2484fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}}
2485fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %float {{%\w+}} 0
2486fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpAccessChain %_ptr_Uniform_float %sbo %int_1
2487fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}}
2488fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
2489fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
2490fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2
2491fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5313 {{%\w+}} {{%\w+}} {{%\w+}}
2492fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_55 {{%\w+}} %uint_3 %uint_1 %uint_0 {{%\w+}}
2493fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
2494fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
2495fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2496fd4e5da5Sopenharmony_ci;CHECK: OpStore {{%\w+}} {{%\w+}}
2497fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
2498fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2499fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
2500fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2501fd4e5da5Sopenharmony_ciOpReturn
2502fd4e5da5Sopenharmony_ciOpFunctionEnd
2503fd4e5da5Sopenharmony_ci)";
2504fd4e5da5Sopenharmony_ci  // clang-format on
2505fd4e5da5Sopenharmony_ci
2506fd4e5da5Sopenharmony_ci  // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
2507fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(defs + kImportStub + main_func,
2508fd4e5da5Sopenharmony_ci                                               true, 23u);
2509fd4e5da5Sopenharmony_ci}
2510fd4e5da5Sopenharmony_ci
2511fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest,
2512fd4e5da5Sopenharmony_ci       InstBoundsIntersectionInitLoadVariableSizedSampledImagesArray) {
2513fd4e5da5Sopenharmony_ci  // #version 460
2514fd4e5da5Sopenharmony_ci  // #extension GL_EXT_nonuniform_qualifier : require
2515fd4e5da5Sopenharmony_ci  // #extension GL_NV_ray_tracing : require
2516fd4e5da5Sopenharmony_ci  //
2517fd4e5da5Sopenharmony_ci  // layout(set = 5, binding = 1, std140) buffer StorageBuffer {
2518fd4e5da5Sopenharmony_ci  //   uint index;
2519fd4e5da5Sopenharmony_ci  //   float red;
2520fd4e5da5Sopenharmony_ci  // } sbo;
2521fd4e5da5Sopenharmony_ci  //
2522fd4e5da5Sopenharmony_ci  // layout(set = 5, binding = 3, rgba32f) readonly uniform image2D images[];
2523fd4e5da5Sopenharmony_ci  //
2524fd4e5da5Sopenharmony_ci  // void main()
2525fd4e5da5Sopenharmony_ci  // {
2526fd4e5da5Sopenharmony_ci  //    sbo.red = imageLoad(images[sbo.index], ivec2(0, 0)).r;
2527fd4e5da5Sopenharmony_ci  // }
2528fd4e5da5Sopenharmony_ci
2529fd4e5da5Sopenharmony_ci  // clang-format off
2530fd4e5da5Sopenharmony_ci  const std::string defs = R"(
2531fd4e5da5Sopenharmony_ciOpCapability RuntimeDescriptorArray
2532fd4e5da5Sopenharmony_ciOpCapability RayTracingNV
2533fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
2534fd4e5da5Sopenharmony_ciOpExtension "SPV_EXT_descriptor_indexing"
2535fd4e5da5Sopenharmony_ciOpExtension "SPV_NV_ray_tracing"
2536fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
2537fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
2538fd4e5da5Sopenharmony_ciOpEntryPoint IntersectionNV %main "main"
2539fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint IntersectionNV %main "main" [[launch_id:%\w+]]
2540fd4e5da5Sopenharmony_ciOpSource GLSL 460
2541fd4e5da5Sopenharmony_ciOpSourceExtension "GL_EXT_nonuniform_qualifier"
2542fd4e5da5Sopenharmony_ciOpSourceExtension "GL_NV_ray_tracing"
2543fd4e5da5Sopenharmony_ciOpName %main "main"
2544fd4e5da5Sopenharmony_ciOpName %StorageBuffer "StorageBuffer"
2545fd4e5da5Sopenharmony_ciOpMemberName %StorageBuffer 0 "index"
2546fd4e5da5Sopenharmony_ciOpMemberName %StorageBuffer 1 "red"
2547fd4e5da5Sopenharmony_ciOpName %sbo "sbo"
2548fd4e5da5Sopenharmony_ciOpName %images "images"
2549fd4e5da5Sopenharmony_ciOpMemberDecorate %StorageBuffer 0 Offset 0
2550fd4e5da5Sopenharmony_ciOpMemberDecorate %StorageBuffer 1 Offset 4
2551fd4e5da5Sopenharmony_ciOpDecorate %StorageBuffer BufferBlock
2552fd4e5da5Sopenharmony_ciOpDecorate %sbo DescriptorSet 5
2553fd4e5da5Sopenharmony_ciOpDecorate %sbo Binding 1
2554fd4e5da5Sopenharmony_ciOpDecorate %images DescriptorSet 5
2555fd4e5da5Sopenharmony_ciOpDecorate %images Binding 3
2556fd4e5da5Sopenharmony_ciOpDecorate %images NonWritable
2557fd4e5da5Sopenharmony_ci)" + kImportDeco + R"(
2558fd4e5da5Sopenharmony_ci;CHECK: OpDecorate [[launch_id]] BuiltIn LaunchIdNV
2559fd4e5da5Sopenharmony_ci%void = OpTypeVoid
2560fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
2561fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
2562fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
2563fd4e5da5Sopenharmony_ci%StorageBuffer = OpTypeStruct %uint %float
2564fd4e5da5Sopenharmony_ci%_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
2565fd4e5da5Sopenharmony_ci%sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
2566fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
2567fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
2568fd4e5da5Sopenharmony_ci%13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
2569fd4e5da5Sopenharmony_ci%_runtimearr_13 = OpTypeRuntimeArray %13
2570fd4e5da5Sopenharmony_ci%_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
2571fd4e5da5Sopenharmony_ci%images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
2572fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
2573fd4e5da5Sopenharmony_ci%_ptr_Uniform_uint = OpTypePointer Uniform %uint
2574fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
2575fd4e5da5Sopenharmony_ci%v2int = OpTypeVector %int 2
2576fd4e5da5Sopenharmony_ci%25 = OpConstantComposite %v2int %int_0 %int_0
2577fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
2578fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
2579fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float
2580fd4e5da5Sopenharmony_ci;CHECK: [[launch_id]] = OpVariable %_ptr_Input_v3uint Input
2581fd4e5da5Sopenharmony_ci;CHECK: [[null_uint:%\w+]] = OpConstantNull %uint
2582fd4e5da5Sopenharmony_ci;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
2583fd4e5da5Sopenharmony_ci)";
2584fd4e5da5Sopenharmony_ci
2585fd4e5da5Sopenharmony_ci  const std::string main_func = R"(
2586fd4e5da5Sopenharmony_ci%main = OpFunction %void None %3
2587fd4e5da5Sopenharmony_ci%5 = OpLabel
2588fd4e5da5Sopenharmony_ci%19 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
2589fd4e5da5Sopenharmony_ci%20 = OpLoad %uint %19
2590fd4e5da5Sopenharmony_ci%22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
2591fd4e5da5Sopenharmony_ci%23 = OpLoad %13 %22
2592fd4e5da5Sopenharmony_ci%27 = OpImageRead %v4float %23 %25
2593fd4e5da5Sopenharmony_ci%29 = OpCompositeExtract %float %27 0
2594fd4e5da5Sopenharmony_ci%31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
2595fd4e5da5Sopenharmony_ciOpStore %31 %29
2596fd4e5da5Sopenharmony_ci;CHECK-NOT: OpStore %31 %29
2597fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}}
2598fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
2599fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
2600fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2
2601fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5314 {{%\w+}} {{%\w+}} {{%\w+}}
2602fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_49 {{%\w+}} %uint_5 %uint_1 %uint_0 {{%\w+}}
2603fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
2604fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
2605fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2606fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %uint %25
2607fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
2608fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2609fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
2610fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2611fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpPhi %uint {{%\w+}} {{%\w+}} [[null_uint]] {{%\w+}}
2612fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpAccessChain %_ptr_UniformConstant_13 %images {{%\w+}}
2613fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %13 {{%\w+}}
2614fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}}
2615fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
2616fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
2617fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2
2618fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5314 {{%\w+}} {{%\w+}} {{%\w+}}
2619fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_52 {{%\w+}} %uint_5 %uint_3 {{%\w+}} %uint_0
2620fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
2621fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
2622fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2623fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %13 {{%\w+}}
2624fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpImageRead %v4float {{%\w+}} %20
2625fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
2626fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2627fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
2628fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2629fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}}
2630fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %float {{%\w+}} 0
2631fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpAccessChain %_ptr_Uniform_float %sbo %int_1
2632fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}}
2633fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
2634fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
2635fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2
2636fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5314 {{%\w+}} {{%\w+}} {{%\w+}}
2637fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_55 {{%\w+}} %uint_5 %uint_1 %uint_0 {{%\w+}}
2638fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
2639fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
2640fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2641fd4e5da5Sopenharmony_ci;CHECK: OpStore %31 {{%\w+}}
2642fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
2643fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2644fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
2645fd4e5da5Sopenharmony_ciOpReturn
2646fd4e5da5Sopenharmony_ciOpFunctionEnd
2647fd4e5da5Sopenharmony_ci)";
2648fd4e5da5Sopenharmony_ci  // clang-format on
2649fd4e5da5Sopenharmony_ci
2650fd4e5da5Sopenharmony_ci  // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
2651fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(defs + kImportStub + main_func,
2652fd4e5da5Sopenharmony_ci                                               true, 23u);
2653fd4e5da5Sopenharmony_ci}
2654fd4e5da5Sopenharmony_ci
2655fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest,
2656fd4e5da5Sopenharmony_ci       InstBoundsAnyHitInitLoadVariableSizedSampledImagesArray) {
2657fd4e5da5Sopenharmony_ci  // #version 460
2658fd4e5da5Sopenharmony_ci  // #extension GL_EXT_nonuniform_qualifier : require
2659fd4e5da5Sopenharmony_ci  // #extension GL_NV_ray_tracing : require
2660fd4e5da5Sopenharmony_ci  //
2661fd4e5da5Sopenharmony_ci  // layout(set = 2, binding = 1, std140) buffer StorageBuffer {
2662fd4e5da5Sopenharmony_ci  //   uint index;
2663fd4e5da5Sopenharmony_ci  //   float red;
2664fd4e5da5Sopenharmony_ci  // } sbo;
2665fd4e5da5Sopenharmony_ci  //
2666fd4e5da5Sopenharmony_ci  // layout(set = 2, binding = 3, rgba32f) readonly uniform image2D images[];
2667fd4e5da5Sopenharmony_ci  //
2668fd4e5da5Sopenharmony_ci  // void main()
2669fd4e5da5Sopenharmony_ci  // {
2670fd4e5da5Sopenharmony_ci  //    sbo.red = imageLoad(images[sbo.index], ivec2(0, 0)).r;
2671fd4e5da5Sopenharmony_ci  // }
2672fd4e5da5Sopenharmony_ci
2673fd4e5da5Sopenharmony_ci  // clang-format off
2674fd4e5da5Sopenharmony_ci  const std::string defs = R"(
2675fd4e5da5Sopenharmony_ciOpCapability RuntimeDescriptorArray
2676fd4e5da5Sopenharmony_ciOpCapability RayTracingNV
2677fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
2678fd4e5da5Sopenharmony_ciOpExtension "SPV_EXT_descriptor_indexing"
2679fd4e5da5Sopenharmony_ciOpExtension "SPV_NV_ray_tracing"
2680fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
2681fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
2682fd4e5da5Sopenharmony_ciOpEntryPoint AnyHitNV %main "main"
2683fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint AnyHitNV %main "main" [[launch_id:%\w+]]
2684fd4e5da5Sopenharmony_ciOpSource GLSL 460
2685fd4e5da5Sopenharmony_ciOpSourceExtension "GL_EXT_nonuniform_qualifier"
2686fd4e5da5Sopenharmony_ciOpSourceExtension "GL_NV_ray_tracing"
2687fd4e5da5Sopenharmony_ciOpName %main "main"
2688fd4e5da5Sopenharmony_ciOpName %StorageBuffer "StorageBuffer"
2689fd4e5da5Sopenharmony_ciOpMemberName %StorageBuffer 0 "index"
2690fd4e5da5Sopenharmony_ciOpMemberName %StorageBuffer 1 "red"
2691fd4e5da5Sopenharmony_ciOpName %sbo "sbo"
2692fd4e5da5Sopenharmony_ciOpName %images "images"
2693fd4e5da5Sopenharmony_ciOpMemberDecorate %StorageBuffer 0 Offset 0
2694fd4e5da5Sopenharmony_ciOpMemberDecorate %StorageBuffer 1 Offset 4
2695fd4e5da5Sopenharmony_ciOpDecorate %StorageBuffer BufferBlock
2696fd4e5da5Sopenharmony_ciOpDecorate %sbo DescriptorSet 2
2697fd4e5da5Sopenharmony_ciOpDecorate %sbo Binding 1
2698fd4e5da5Sopenharmony_ciOpDecorate %images DescriptorSet 2
2699fd4e5da5Sopenharmony_ciOpDecorate %images Binding 3
2700fd4e5da5Sopenharmony_ciOpDecorate %images NonWritable
2701fd4e5da5Sopenharmony_ci)" + kImportDeco + R"(
2702fd4e5da5Sopenharmony_ci;CHECK: OpDecorate [[launch_id]] BuiltIn LaunchIdNV
2703fd4e5da5Sopenharmony_ci%void = OpTypeVoid
2704fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
2705fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
2706fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
2707fd4e5da5Sopenharmony_ci%StorageBuffer = OpTypeStruct %uint %float
2708fd4e5da5Sopenharmony_ci%_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
2709fd4e5da5Sopenharmony_ci%sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
2710fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
2711fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
2712fd4e5da5Sopenharmony_ci%13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
2713fd4e5da5Sopenharmony_ci%_runtimearr_13 = OpTypeRuntimeArray %13
2714fd4e5da5Sopenharmony_ci%_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
2715fd4e5da5Sopenharmony_ci%images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
2716fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
2717fd4e5da5Sopenharmony_ci%_ptr_Uniform_uint = OpTypePointer Uniform %uint
2718fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
2719fd4e5da5Sopenharmony_ci%v2int = OpTypeVector %int 2
2720fd4e5da5Sopenharmony_ci%25 = OpConstantComposite %v2int %int_0 %int_0
2721fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
2722fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
2723fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float
2724fd4e5da5Sopenharmony_ci;CHECK: [[launch_id]] = OpVariable %_ptr_Input_v3uint Input
2725fd4e5da5Sopenharmony_ci;CHECK: [[null_uint:%\w+]] = OpConstantNull %uint
2726fd4e5da5Sopenharmony_ci;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
2727fd4e5da5Sopenharmony_ci)";
2728fd4e5da5Sopenharmony_ci
2729fd4e5da5Sopenharmony_ci  const std::string main_func = R"(
2730fd4e5da5Sopenharmony_ci%main = OpFunction %void None %3
2731fd4e5da5Sopenharmony_ci%5 = OpLabel
2732fd4e5da5Sopenharmony_ci%19 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
2733fd4e5da5Sopenharmony_ci%20 = OpLoad %uint %19
2734fd4e5da5Sopenharmony_ci%22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
2735fd4e5da5Sopenharmony_ci%23 = OpLoad %13 %22
2736fd4e5da5Sopenharmony_ci%27 = OpImageRead %v4float %23 %25
2737fd4e5da5Sopenharmony_ci%29 = OpCompositeExtract %float %27 0
2738fd4e5da5Sopenharmony_ci%31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
2739fd4e5da5Sopenharmony_ciOpStore %31 %29
2740fd4e5da5Sopenharmony_ci;CHECK-NOT: %20 = OpLoad %uint %19
2741fd4e5da5Sopenharmony_ci;CHECK-NOT: %22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
2742fd4e5da5Sopenharmony_ci;CHECK-NOT: %23 = OpLoad %13 %22
2743fd4e5da5Sopenharmony_ci;CHECK-NOT: %27 = OpImageRead %v4float %23 %25
2744fd4e5da5Sopenharmony_ci;CHECK-NOT: %29 = OpCompositeExtract %float %27 0
2745fd4e5da5Sopenharmony_ci;CHECK-NOT: %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
2746fd4e5da5Sopenharmony_ci;CHECK-NOT: OpStore %31 %29
2747fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}}
2748fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
2749fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
2750fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2
2751fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5315 {{%\w+}} {{%\w+}} {{%\w+}}
2752fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_49 {{%\w+}} %uint_2 %uint_1 %uint_0 {{%\w+}}
2753fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
2754fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
2755fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2756fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %uint %25
2757fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
2758fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2759fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
2760fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2761fd4e5da5Sopenharmony_ci;CHECK: [[phi_result:%\w+]] = OpPhi %uint {{%\w+}} {{%\w+}} [[null_uint]] {{%\w+}}
2762fd4e5da5Sopenharmony_ci;CHECK: %27 = OpAccessChain %_ptr_UniformConstant_13 %images [[phi_result]]
2763fd4e5da5Sopenharmony_ci;CHECK: %28 = OpLoad %13 %27
2764fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}}
2765fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
2766fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
2767fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2
2768fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5315 {{%\w+}} {{%\w+}} {{%\w+}}
2769fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_52 {{%\w+}} %uint_2 %uint_3 {{%\w+}} %uint_0
2770fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
2771fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
2772fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2773fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %13 %27
2774fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpImageRead %v4float {{%\w+}} %20
2775fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
2776fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2777fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
2778fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2779fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}}
2780fd4e5da5Sopenharmony_ci;CHECK: %30 = OpCompositeExtract %float {{%\w+}} 0
2781fd4e5da5Sopenharmony_ci;CHECK: %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
2782fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}}
2783fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
2784fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
2785fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2
2786fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5315 {{%\w+}} {{%\w+}} {{%\w+}}
2787fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_55 {{%\w+}} %uint_2 %uint_1 %uint_0 {{%\w+}}
2788fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
2789fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
2790fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2791fd4e5da5Sopenharmony_ci;CHECK: OpStore %31 %30
2792fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
2793fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2794fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
2795fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2796fd4e5da5Sopenharmony_ciOpReturn
2797fd4e5da5Sopenharmony_ciOpFunctionEnd
2798fd4e5da5Sopenharmony_ci)";
2799fd4e5da5Sopenharmony_ci  // clang-format on
2800fd4e5da5Sopenharmony_ci
2801fd4e5da5Sopenharmony_ci  // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
2802fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(defs + kImportStub + main_func,
2803fd4e5da5Sopenharmony_ci                                               true, 23u);
2804fd4e5da5Sopenharmony_ci}
2805fd4e5da5Sopenharmony_ci
2806fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest,
2807fd4e5da5Sopenharmony_ci       InstBoundsClosestHitInitLoadVariableSizedSampledImagesArray) {
2808fd4e5da5Sopenharmony_ci  // #version 460
2809fd4e5da5Sopenharmony_ci  // #extension GL_EXT_nonuniform_qualifier : require
2810fd4e5da5Sopenharmony_ci  // #extension GL_NV_ray_tracing : require
2811fd4e5da5Sopenharmony_ci  //
2812fd4e5da5Sopenharmony_ci  // layout(set = 1, binding = 2, std140) buffer StorageBuffer {
2813fd4e5da5Sopenharmony_ci  //   uint index;
2814fd4e5da5Sopenharmony_ci  //   float red;
2815fd4e5da5Sopenharmony_ci  // } sbo;
2816fd4e5da5Sopenharmony_ci  //
2817fd4e5da5Sopenharmony_ci  // layout(set = 1, binding = 3, rgba32f) readonly uniform image2D images[];
2818fd4e5da5Sopenharmony_ci  //
2819fd4e5da5Sopenharmony_ci  // void main()
2820fd4e5da5Sopenharmony_ci  // {
2821fd4e5da5Sopenharmony_ci  //    sbo.red = imageLoad(images[sbo.index], ivec2(0, 0)).r;
2822fd4e5da5Sopenharmony_ci  // }
2823fd4e5da5Sopenharmony_ci
2824fd4e5da5Sopenharmony_ci  // clang-format off
2825fd4e5da5Sopenharmony_ci  const std::string defs = R"(
2826fd4e5da5Sopenharmony_ciOpCapability RuntimeDescriptorArray
2827fd4e5da5Sopenharmony_ciOpCapability RayTracingNV
2828fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
2829fd4e5da5Sopenharmony_ciOpExtension "SPV_EXT_descriptor_indexing"
2830fd4e5da5Sopenharmony_ciOpExtension "SPV_NV_ray_tracing"
2831fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
2832fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
2833fd4e5da5Sopenharmony_ciOpEntryPoint ClosestHitNV %main "main"
2834fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint ClosestHitNV %main "main" [[launch_id:%\w+]]
2835fd4e5da5Sopenharmony_ciOpSource GLSL 460
2836fd4e5da5Sopenharmony_ciOpSourceExtension "GL_EXT_nonuniform_qualifier"
2837fd4e5da5Sopenharmony_ciOpSourceExtension "GL_NV_ray_tracing"
2838fd4e5da5Sopenharmony_ciOpName %main "main"
2839fd4e5da5Sopenharmony_ciOpName %StorageBuffer "StorageBuffer"
2840fd4e5da5Sopenharmony_ciOpMemberName %StorageBuffer 0 "index"
2841fd4e5da5Sopenharmony_ciOpMemberName %StorageBuffer 1 "red"
2842fd4e5da5Sopenharmony_ciOpName %sbo "sbo"
2843fd4e5da5Sopenharmony_ciOpName %images "images"
2844fd4e5da5Sopenharmony_ciOpMemberDecorate %StorageBuffer 0 Offset 0
2845fd4e5da5Sopenharmony_ciOpMemberDecorate %StorageBuffer 1 Offset 4
2846fd4e5da5Sopenharmony_ciOpDecorate %StorageBuffer BufferBlock
2847fd4e5da5Sopenharmony_ciOpDecorate %sbo DescriptorSet 1
2848fd4e5da5Sopenharmony_ciOpDecorate %sbo Binding 2
2849fd4e5da5Sopenharmony_ciOpDecorate %images DescriptorSet 1
2850fd4e5da5Sopenharmony_ciOpDecorate %images Binding 3
2851fd4e5da5Sopenharmony_ciOpDecorate %images NonWritable
2852fd4e5da5Sopenharmony_ci)" + kImportDeco + R"(
2853fd4e5da5Sopenharmony_ci;CHECK: OpDecorate [[launch_id]] BuiltIn LaunchIdNV
2854fd4e5da5Sopenharmony_ci%void = OpTypeVoid
2855fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
2856fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
2857fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
2858fd4e5da5Sopenharmony_ci%StorageBuffer = OpTypeStruct %uint %float
2859fd4e5da5Sopenharmony_ci%_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
2860fd4e5da5Sopenharmony_ci%sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
2861fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
2862fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
2863fd4e5da5Sopenharmony_ci%13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
2864fd4e5da5Sopenharmony_ci%_runtimearr_13 = OpTypeRuntimeArray %13
2865fd4e5da5Sopenharmony_ci%_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
2866fd4e5da5Sopenharmony_ci%images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
2867fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
2868fd4e5da5Sopenharmony_ci%_ptr_Uniform_uint = OpTypePointer Uniform %uint
2869fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
2870fd4e5da5Sopenharmony_ci%v2int = OpTypeVector %int 2
2871fd4e5da5Sopenharmony_ci%25 = OpConstantComposite %v2int %int_0 %int_0
2872fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
2873fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
2874fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float
2875fd4e5da5Sopenharmony_ci;CHECK: [[launch_id]] = OpVariable %_ptr_Input_v3uint Input
2876fd4e5da5Sopenharmony_ci;CHECK: [[null_uint:%\w+]] = OpConstantNull %uint
2877fd4e5da5Sopenharmony_ci;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
2878fd4e5da5Sopenharmony_ci)";
2879fd4e5da5Sopenharmony_ci
2880fd4e5da5Sopenharmony_ci  const std::string main_func = R"(
2881fd4e5da5Sopenharmony_ci%main = OpFunction %void None %3
2882fd4e5da5Sopenharmony_ci%5 = OpLabel
2883fd4e5da5Sopenharmony_ci%19 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
2884fd4e5da5Sopenharmony_ci%20 = OpLoad %uint %19
2885fd4e5da5Sopenharmony_ci%22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
2886fd4e5da5Sopenharmony_ci%23 = OpLoad %13 %22
2887fd4e5da5Sopenharmony_ci%27 = OpImageRead %v4float %23 %25
2888fd4e5da5Sopenharmony_ci%29 = OpCompositeExtract %float %27 0
2889fd4e5da5Sopenharmony_ci%31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
2890fd4e5da5Sopenharmony_ciOpStore %31 %29
2891fd4e5da5Sopenharmony_ci;CHECK-NOT: %20 = OpLoad %uint %19
2892fd4e5da5Sopenharmony_ci;CHECK-NOT: %22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
2893fd4e5da5Sopenharmony_ci;CHECK-NOT: %23 = OpLoad %13 %22
2894fd4e5da5Sopenharmony_ci;CHECK-NOT: %27 = OpImageRead %v4float %23 %25
2895fd4e5da5Sopenharmony_ci;CHECK-NOT: %29 = OpCompositeExtract %float %27 0
2896fd4e5da5Sopenharmony_ci;CHECK-NOT: %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
2897fd4e5da5Sopenharmony_ci;CHECK-NOT: OpStore %31 %29
2898fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}}
2899fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
2900fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
2901fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2
2902fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5316 {{%\w+}} {{%\w+}} {{%\w+}}
2903fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_49 {{%\w+}} %uint_1 %uint_2 %uint_0 {{%\w+}}
2904fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
2905fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
2906fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2907fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %uint %25
2908fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
2909fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2910fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
2911fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2912fd4e5da5Sopenharmony_ci;CHECK: [[phi_result:%\w+]] = OpPhi %uint {{%\w+}} {{%\w+}} [[null_uint]] {{%\w+}}
2913fd4e5da5Sopenharmony_ci;CHECK: %27 = OpAccessChain %_ptr_UniformConstant_13 %images [[phi_result]]
2914fd4e5da5Sopenharmony_ci;CHECK: %28 = OpLoad %13 %27
2915fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}}
2916fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
2917fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
2918fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2
2919fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5316 {{%\w+}} {{%\w+}} {{%\w+}}
2920fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_52 {{%\w+}} %uint_1 %uint_3 {{%\w+}} %uint_0
2921fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
2922fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
2923fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2924fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %13 %27
2925fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpImageRead %v4float {{%\w+}} %20
2926fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
2927fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2928fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
2929fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2930fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}}
2931fd4e5da5Sopenharmony_ci;CHECK: %30 = OpCompositeExtract %float {{%\w+}} 0
2932fd4e5da5Sopenharmony_ci;CHECK: %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
2933fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}}
2934fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
2935fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
2936fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2
2937fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5316 {{%\w+}} {{%\w+}} {{%\w+}}
2938fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_55 {{%\w+}} %uint_1 %uint_2 %uint_0 {{%\w+}}
2939fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
2940fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
2941fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2942fd4e5da5Sopenharmony_ci;CHECK: OpStore %31 %30
2943fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
2944fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2945fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
2946fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
2947fd4e5da5Sopenharmony_ciOpReturn
2948fd4e5da5Sopenharmony_ciOpFunctionEnd
2949fd4e5da5Sopenharmony_ci)";
2950fd4e5da5Sopenharmony_ci  // clang-format on
2951fd4e5da5Sopenharmony_ci
2952fd4e5da5Sopenharmony_ci  // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
2953fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(defs + kImportStub + main_func,
2954fd4e5da5Sopenharmony_ci                                               true, 23u);
2955fd4e5da5Sopenharmony_ci}
2956fd4e5da5Sopenharmony_ci
2957fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest,
2958fd4e5da5Sopenharmony_ci       InstBoundsMissInitLoadVariableSizedSampledImagesArray) {
2959fd4e5da5Sopenharmony_ci  // #version 460
2960fd4e5da5Sopenharmony_ci  // #extension GL_EXT_nonuniform_qualifier : require
2961fd4e5da5Sopenharmony_ci  // #extension GL_NV_ray_tracing : require
2962fd4e5da5Sopenharmony_ci  //
2963fd4e5da5Sopenharmony_ci  // layout(set = 1, binding = 2, std140) buffer StorageBuffer {
2964fd4e5da5Sopenharmony_ci  //   uint index;
2965fd4e5da5Sopenharmony_ci  //   float red;
2966fd4e5da5Sopenharmony_ci  // } sbo;
2967fd4e5da5Sopenharmony_ci  //
2968fd4e5da5Sopenharmony_ci  // layout(set = 1, binding = 3, rgba32f) readonly uniform image2D images[];
2969fd4e5da5Sopenharmony_ci  //
2970fd4e5da5Sopenharmony_ci  // void main()
2971fd4e5da5Sopenharmony_ci  // {
2972fd4e5da5Sopenharmony_ci  //    sbo.red = imageLoad(images[sbo.index], ivec2(0, 0)).r;
2973fd4e5da5Sopenharmony_ci  // }
2974fd4e5da5Sopenharmony_ci
2975fd4e5da5Sopenharmony_ci  // clang-format off
2976fd4e5da5Sopenharmony_ci  const std::string defs = R"(
2977fd4e5da5Sopenharmony_ciOpCapability RuntimeDescriptorArray
2978fd4e5da5Sopenharmony_ciOpCapability RayTracingNV
2979fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
2980fd4e5da5Sopenharmony_ciOpExtension "SPV_EXT_descriptor_indexing"
2981fd4e5da5Sopenharmony_ciOpExtension "SPV_NV_ray_tracing"
2982fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
2983fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
2984fd4e5da5Sopenharmony_ciOpEntryPoint MissNV %main "main"
2985fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint MissNV %main "main" [[launch_id:%\w+]]
2986fd4e5da5Sopenharmony_ciOpSource GLSL 460
2987fd4e5da5Sopenharmony_ciOpSourceExtension "GL_EXT_nonuniform_qualifier"
2988fd4e5da5Sopenharmony_ciOpSourceExtension "GL_NV_ray_tracing"
2989fd4e5da5Sopenharmony_ciOpName %main "main"
2990fd4e5da5Sopenharmony_ciOpName %StorageBuffer "StorageBuffer"
2991fd4e5da5Sopenharmony_ciOpMemberName %StorageBuffer 0 "index"
2992fd4e5da5Sopenharmony_ciOpMemberName %StorageBuffer 1 "red"
2993fd4e5da5Sopenharmony_ciOpName %sbo "sbo"
2994fd4e5da5Sopenharmony_ciOpName %images "images"
2995fd4e5da5Sopenharmony_ciOpMemberDecorate %StorageBuffer 0 Offset 0
2996fd4e5da5Sopenharmony_ciOpMemberDecorate %StorageBuffer 1 Offset 4
2997fd4e5da5Sopenharmony_ciOpDecorate %StorageBuffer BufferBlock
2998fd4e5da5Sopenharmony_ciOpDecorate %sbo DescriptorSet 1
2999fd4e5da5Sopenharmony_ciOpDecorate %sbo Binding 2
3000fd4e5da5Sopenharmony_ciOpDecorate %images DescriptorSet 1
3001fd4e5da5Sopenharmony_ciOpDecorate %images Binding 3
3002fd4e5da5Sopenharmony_ciOpDecorate %images NonWritable
3003fd4e5da5Sopenharmony_ci)" + kImportDeco + R"(
3004fd4e5da5Sopenharmony_ci;CHECK: OpDecorate [[launch_id]] BuiltIn LaunchIdNV
3005fd4e5da5Sopenharmony_ci%void = OpTypeVoid
3006fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
3007fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
3008fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
3009fd4e5da5Sopenharmony_ci%StorageBuffer = OpTypeStruct %uint %float
3010fd4e5da5Sopenharmony_ci%_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
3011fd4e5da5Sopenharmony_ci%sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
3012fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
3013fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
3014fd4e5da5Sopenharmony_ci%13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
3015fd4e5da5Sopenharmony_ci%_runtimearr_13 = OpTypeRuntimeArray %13
3016fd4e5da5Sopenharmony_ci%_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
3017fd4e5da5Sopenharmony_ci%images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
3018fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
3019fd4e5da5Sopenharmony_ci%_ptr_Uniform_uint = OpTypePointer Uniform %uint
3020fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
3021fd4e5da5Sopenharmony_ci%v2int = OpTypeVector %int 2
3022fd4e5da5Sopenharmony_ci%25 = OpConstantComposite %v2int %int_0 %int_0
3023fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
3024fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
3025fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float
3026fd4e5da5Sopenharmony_ci;CHECK: [[launch_id]] = OpVariable %_ptr_Input_v3uint Input
3027fd4e5da5Sopenharmony_ci;CHECK: [[null_uint:%\w+]] = OpConstantNull %uint
3028fd4e5da5Sopenharmony_ci;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
3029fd4e5da5Sopenharmony_ci)";
3030fd4e5da5Sopenharmony_ci
3031fd4e5da5Sopenharmony_ci  const std::string main_func = R"(
3032fd4e5da5Sopenharmony_ci%main = OpFunction %void None %3
3033fd4e5da5Sopenharmony_ci%5 = OpLabel
3034fd4e5da5Sopenharmony_ci%19 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
3035fd4e5da5Sopenharmony_ci%20 = OpLoad %uint %19
3036fd4e5da5Sopenharmony_ci%22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
3037fd4e5da5Sopenharmony_ci%23 = OpLoad %13 %22
3038fd4e5da5Sopenharmony_ci%27 = OpImageRead %v4float %23 %25
3039fd4e5da5Sopenharmony_ci%29 = OpCompositeExtract %float %27 0
3040fd4e5da5Sopenharmony_ci%31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
3041fd4e5da5Sopenharmony_ciOpStore %31 %29
3042fd4e5da5Sopenharmony_ci;CHECK-NOT: %20 = OpLoad %uint %19
3043fd4e5da5Sopenharmony_ci;CHECK-NOT: %22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
3044fd4e5da5Sopenharmony_ci;CHECK-NOT: %27 = OpImageRead %v4float %23 %25
3045fd4e5da5Sopenharmony_ci;CHECK-NOT: %29 = OpCompositeExtract %float %27 0
3046fd4e5da5Sopenharmony_ci;CHECK-NOT OpStore %31 %29
3047fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}}
3048fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
3049fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
3050fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2
3051fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5317 {{%\w+}} {{%\w+}} {{%\w+}}
3052fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_49 {{%\w+}} %uint_1 %uint_2 %uint_0 {{%\w+}}
3053fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
3054fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
3055fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3056fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %uint %25
3057fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
3058fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3059fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
3060fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3061fd4e5da5Sopenharmony_ci;CHECK: [[phi_result:%\w+]] = OpPhi %uint {{%\w+}} {{%\w+}} [[null_uint]] {{%\w+}}
3062fd4e5da5Sopenharmony_ci;CHECK: %27 = OpAccessChain %_ptr_UniformConstant_13 %images [[phi_result]]
3063fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}}
3064fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
3065fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
3066fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2
3067fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5317 {{%\w+}} {{%\w+}} {{%\w+}}
3068fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_52 {{%\w+}} %uint_1 %uint_3 {{%\w+}} %uint_0
3069fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
3070fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
3071fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3072fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %13 %27
3073fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpImageRead %v4float {{%\w+}} %20
3074fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
3075fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3076fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
3077fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3078fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}}
3079fd4e5da5Sopenharmony_ci;CHECK: %30 = OpCompositeExtract %float {{%\w+}} 0
3080fd4e5da5Sopenharmony_ci;CHECK: %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
3081fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}}
3082fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
3083fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
3084fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2
3085fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5317 {{%\w+}} {{%\w+}} {{%\w+}}
3086fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_55 {{%\w+}} %uint_1 %uint_2 %uint_0 {{%\w+}}
3087fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
3088fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
3089fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3090fd4e5da5Sopenharmony_ci;CHECK: OpStore %31 %30
3091fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
3092fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3093fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
3094fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3095fd4e5da5Sopenharmony_ciOpReturn
3096fd4e5da5Sopenharmony_ciOpFunctionEnd
3097fd4e5da5Sopenharmony_ci)";
3098fd4e5da5Sopenharmony_ci  // clang-format on
3099fd4e5da5Sopenharmony_ci
3100fd4e5da5Sopenharmony_ci  // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
3101fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(defs + kImportStub + main_func,
3102fd4e5da5Sopenharmony_ci                                               true, 23u);
3103fd4e5da5Sopenharmony_ci}
3104fd4e5da5Sopenharmony_ci
3105fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest,
3106fd4e5da5Sopenharmony_ci       InstBoundsCallableInitLoadVariableSizedSampledImagesArray) {
3107fd4e5da5Sopenharmony_ci  // #version 460
3108fd4e5da5Sopenharmony_ci  // #extension GL_EXT_nonuniform_qualifier : require
3109fd4e5da5Sopenharmony_ci  // #extension GL_NV_ray_tracing : require
3110fd4e5da5Sopenharmony_ci  //
3111fd4e5da5Sopenharmony_ci  // layout(set = 1, binding = 2, std140) buffer StorageBuffer {
3112fd4e5da5Sopenharmony_ci  //   uint index;
3113fd4e5da5Sopenharmony_ci  //   float red;
3114fd4e5da5Sopenharmony_ci  // } sbo;
3115fd4e5da5Sopenharmony_ci  //
3116fd4e5da5Sopenharmony_ci  // layout(set = 1, binding = 3, rgba32f) readonly uniform image2D images[];
3117fd4e5da5Sopenharmony_ci  //
3118fd4e5da5Sopenharmony_ci  // void main()
3119fd4e5da5Sopenharmony_ci  // {
3120fd4e5da5Sopenharmony_ci  //    sbo.red = imageLoad(images[sbo.index], ivec2(0, 0)).r;
3121fd4e5da5Sopenharmony_ci  // }
3122fd4e5da5Sopenharmony_ci
3123fd4e5da5Sopenharmony_ci  // clang-format off
3124fd4e5da5Sopenharmony_ci  const std::string defs = R"(
3125fd4e5da5Sopenharmony_ciOpCapability RuntimeDescriptorArray
3126fd4e5da5Sopenharmony_ciOpCapability RayTracingNV
3127fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
3128fd4e5da5Sopenharmony_ciOpExtension "SPV_EXT_descriptor_indexing"
3129fd4e5da5Sopenharmony_ciOpExtension "SPV_NV_ray_tracing"
3130fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
3131fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
3132fd4e5da5Sopenharmony_ciOpEntryPoint CallableNV %main "main"
3133fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint CallableNV %main "main" [[launch_id:%\w+]]
3134fd4e5da5Sopenharmony_ciOpSource GLSL 460
3135fd4e5da5Sopenharmony_ciOpSourceExtension "GL_EXT_nonuniform_qualifier"
3136fd4e5da5Sopenharmony_ciOpSourceExtension "GL_NV_ray_tracing"
3137fd4e5da5Sopenharmony_ciOpName %main "main"
3138fd4e5da5Sopenharmony_ciOpName %StorageBuffer "StorageBuffer"
3139fd4e5da5Sopenharmony_ciOpMemberName %StorageBuffer 0 "index"
3140fd4e5da5Sopenharmony_ciOpMemberName %StorageBuffer 1 "red"
3141fd4e5da5Sopenharmony_ciOpName %sbo "sbo"
3142fd4e5da5Sopenharmony_ciOpName %images "images"
3143fd4e5da5Sopenharmony_ciOpMemberDecorate %StorageBuffer 0 Offset 0
3144fd4e5da5Sopenharmony_ciOpMemberDecorate %StorageBuffer 1 Offset 4
3145fd4e5da5Sopenharmony_ciOpDecorate %StorageBuffer BufferBlock
3146fd4e5da5Sopenharmony_ciOpDecorate %sbo DescriptorSet 1
3147fd4e5da5Sopenharmony_ciOpDecorate %sbo Binding 2
3148fd4e5da5Sopenharmony_ciOpDecorate %images DescriptorSet 1
3149fd4e5da5Sopenharmony_ciOpDecorate %images Binding 3
3150fd4e5da5Sopenharmony_ciOpDecorate %images NonWritable
3151fd4e5da5Sopenharmony_ci)" + kImportDeco + R"(
3152fd4e5da5Sopenharmony_ci;CHECK: OpDecorate [[launch_id]] BuiltIn LaunchIdNV
3153fd4e5da5Sopenharmony_ci%void = OpTypeVoid
3154fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
3155fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
3156fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
3157fd4e5da5Sopenharmony_ci%StorageBuffer = OpTypeStruct %uint %float
3158fd4e5da5Sopenharmony_ci%_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
3159fd4e5da5Sopenharmony_ci%sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
3160fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
3161fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
3162fd4e5da5Sopenharmony_ci%13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
3163fd4e5da5Sopenharmony_ci%_runtimearr_13 = OpTypeRuntimeArray %13
3164fd4e5da5Sopenharmony_ci%_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
3165fd4e5da5Sopenharmony_ci%images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
3166fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
3167fd4e5da5Sopenharmony_ci%_ptr_Uniform_uint = OpTypePointer Uniform %uint
3168fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
3169fd4e5da5Sopenharmony_ci%v2int = OpTypeVector %int 2
3170fd4e5da5Sopenharmony_ci%25 = OpConstantComposite %v2int %int_0 %int_0
3171fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
3172fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
3173fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float
3174fd4e5da5Sopenharmony_ci;CHECK: [[null_uint:%\w+]] = OpConstantNull %uint
3175fd4e5da5Sopenharmony_ci;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
3176fd4e5da5Sopenharmony_ci)";
3177fd4e5da5Sopenharmony_ci
3178fd4e5da5Sopenharmony_ci  const std::string main_func = R"(
3179fd4e5da5Sopenharmony_ci%main = OpFunction %void None %3
3180fd4e5da5Sopenharmony_ci%5 = OpLabel
3181fd4e5da5Sopenharmony_ci%19 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
3182fd4e5da5Sopenharmony_ci%20 = OpLoad %uint %19
3183fd4e5da5Sopenharmony_ci%22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
3184fd4e5da5Sopenharmony_ci%23 = OpLoad %13 %22
3185fd4e5da5Sopenharmony_ci%27 = OpImageRead %v4float %23 %25
3186fd4e5da5Sopenharmony_ci%29 = OpCompositeExtract %float %27 0
3187fd4e5da5Sopenharmony_ci;CHECK-NOT: %20 = OpLoad %uint %19
3188fd4e5da5Sopenharmony_ci;CHECK-NOT: %22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
3189fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}}
3190fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
3191fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
3192fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2
3193fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5318 {{%\w+}} {{%\w+}} {{%\w+}}
3194fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_49 {{%\w+}} %uint_1 %uint_2 %uint_0 {{%\w+}}
3195fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
3196fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
3197fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3198fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %uint %25
3199fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
3200fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3201fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
3202fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3203fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpPhi %uint {{%\w+}} {{%\w+}} [[null_uint]] {{%\w+}}
3204fd4e5da5Sopenharmony_ci;CHECK: %27 = OpAccessChain %_ptr_UniformConstant_13 %images {{%\w+}}
3205fd4e5da5Sopenharmony_ci;CHECK-NOT: %23 = OpLoad %13 %22
3206fd4e5da5Sopenharmony_ci;CHECK-NOT: %27 = OpImageRead %v4float %23 %25
3207fd4e5da5Sopenharmony_ci;CHECK-NOT: %29 = OpCompositeExtract %float %27 0
3208fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}}
3209fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
3210fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
3211fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2
3212fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5318 {{%\w+}} {{%\w+}} {{%\w+}}
3213fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_52 {{%\w+}} %uint_1 %uint_3 {{%\w+}} %uint_0
3214fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
3215fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
3216fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3217fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %13 %27
3218fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpImageRead %v4float {{%\w+}} %20
3219fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
3220fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3221fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
3222fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3223fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}}
3224fd4e5da5Sopenharmony_ci;CHECK: %30 = OpCompositeExtract %float {{%\w+}} 0
3225fd4e5da5Sopenharmony_ci;CHECK: %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
3226fd4e5da5Sopenharmony_ci%31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
3227fd4e5da5Sopenharmony_ciOpStore %31 %29
3228fd4e5da5Sopenharmony_ci;CHECK-NOT: %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
3229fd4e5da5Sopenharmony_ci;CHECK-NOT: OpStore %31 %29
3230fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}}
3231fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
3232fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
3233fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2
3234fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_5318 {{%\w+}} {{%\w+}} {{%\w+}}
3235fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_55 {{%\w+}} %uint_1 %uint_2 %uint_0 {{%\w+}}
3236fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
3237fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
3238fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3239fd4e5da5Sopenharmony_ci;CHECK: OpStore %31 %30
3240fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
3241fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3242fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
3243fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3244fd4e5da5Sopenharmony_ciOpReturn
3245fd4e5da5Sopenharmony_ciOpFunctionEnd
3246fd4e5da5Sopenharmony_ci)";
3247fd4e5da5Sopenharmony_ci  // clang-format on
3248fd4e5da5Sopenharmony_ci
3249fd4e5da5Sopenharmony_ci  // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
3250fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(defs + kImportStub + main_func,
3251fd4e5da5Sopenharmony_ci                                               true, 23u);
3252fd4e5da5Sopenharmony_ci}
3253fd4e5da5Sopenharmony_ci
3254fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest, InstBoundsInitSameBlockOpReplication) {
3255fd4e5da5Sopenharmony_ci  // Test that same block ops like OpSampledImage are replicated properly
3256fd4e5da5Sopenharmony_ci  // where needed.
3257fd4e5da5Sopenharmony_ci  //
3258fd4e5da5Sopenharmony_ci  // clang-format off
3259fd4e5da5Sopenharmony_ci  //
3260fd4e5da5Sopenharmony_ci  // #version 450 core
3261fd4e5da5Sopenharmony_ci  // #extension GL_EXT_nonuniform_qualifier : enable
3262fd4e5da5Sopenharmony_ci  //
3263fd4e5da5Sopenharmony_ci  // layout(location = 0) in vec2 inTexcoord;
3264fd4e5da5Sopenharmony_ci  // layout(location = 0) out vec4 outColor;
3265fd4e5da5Sopenharmony_ci  //
3266fd4e5da5Sopenharmony_ci  // layout(set = 1, binding = 0) uniform Uniforms {
3267fd4e5da5Sopenharmony_ci  //   vec2 var0;
3268fd4e5da5Sopenharmony_ci  // } uniforms;
3269fd4e5da5Sopenharmony_ci  //
3270fd4e5da5Sopenharmony_ci  // layout(set = 1, binding = 1) uniform sampler uniformSampler;
3271fd4e5da5Sopenharmony_ci  // layout(set = 1, binding = 2) uniform texture2D uniformTex;
3272fd4e5da5Sopenharmony_ci  // layout(set = 1, binding = 3) uniform texture2D uniformTexArr[8];
3273fd4e5da5Sopenharmony_ci  //
3274fd4e5da5Sopenharmony_ci  // void main() {
3275fd4e5da5Sopenharmony_ci  //   int index = 0;
3276fd4e5da5Sopenharmony_ci  //   float x = texture(sampler2D(uniformTexArr[nonuniformEXT(index)], uniformSampler), inTexcoord.xy).x;
3277fd4e5da5Sopenharmony_ci  //   float y = texture(sampler2D(uniformTex, uniformSampler), inTexcoord.xy * uniforms.var0.xy).x;
3278fd4e5da5Sopenharmony_ci  //   outColor = vec4(x, y, 0.0, 0.0);
3279fd4e5da5Sopenharmony_ci  // }
3280fd4e5da5Sopenharmony_ci  //
3281fd4e5da5Sopenharmony_ci
3282fd4e5da5Sopenharmony_ci  const std::string defs = R"(
3283fd4e5da5Sopenharmony_ciOpCapability Shader
3284fd4e5da5Sopenharmony_ciOpCapability ShaderNonUniformEXT
3285fd4e5da5Sopenharmony_ciOpCapability SampledImageArrayNonUniformIndexingEXT
3286fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
3287fd4e5da5Sopenharmony_ciOpExtension "SPV_EXT_descriptor_indexing"
3288fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
3289fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
3290fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %inTexcoord %outColor
3291fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint Fragment %main "main" %inTexcoord %outColor %gl_FragCoord
3292fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
3293fd4e5da5Sopenharmony_ciOpSource GLSL 450
3294fd4e5da5Sopenharmony_ciOpSourceExtension "GL_EXT_nonuniform_qualifier"
3295fd4e5da5Sopenharmony_ciOpName %main "main"
3296fd4e5da5Sopenharmony_ciOpName %index "index"
3297fd4e5da5Sopenharmony_ciOpName %x "x"
3298fd4e5da5Sopenharmony_ciOpName %uniformTexArr "uniformTexArr"
3299fd4e5da5Sopenharmony_ciOpName %uniformSampler "uniformSampler"
3300fd4e5da5Sopenharmony_ciOpName %inTexcoord "inTexcoord"
3301fd4e5da5Sopenharmony_ciOpName %y "y"
3302fd4e5da5Sopenharmony_ciOpName %uniformTex "uniformTex"
3303fd4e5da5Sopenharmony_ciOpName %Uniforms "Uniforms"
3304fd4e5da5Sopenharmony_ciOpMemberName %Uniforms 0 "var0"
3305fd4e5da5Sopenharmony_ciOpName %uniforms "uniforms"
3306fd4e5da5Sopenharmony_ciOpName %outColor "outColor"
3307fd4e5da5Sopenharmony_ciOpDecorate %uniformTexArr DescriptorSet 1
3308fd4e5da5Sopenharmony_ciOpDecorate %uniformTexArr Binding 3
3309fd4e5da5Sopenharmony_ciOpDecorate %19 NonUniformEXT
3310fd4e5da5Sopenharmony_ciOpDecorate %22 NonUniformEXT
3311fd4e5da5Sopenharmony_ciOpDecorate %uniformSampler DescriptorSet 1
3312fd4e5da5Sopenharmony_ciOpDecorate %uniformSampler Binding 1
3313fd4e5da5Sopenharmony_ciOpDecorate %inTexcoord Location 0
3314fd4e5da5Sopenharmony_ciOpDecorate %uniformTex DescriptorSet 1
3315fd4e5da5Sopenharmony_ciOpDecorate %uniformTex Binding 2
3316fd4e5da5Sopenharmony_ciOpMemberDecorate %Uniforms 0 Offset 0
3317fd4e5da5Sopenharmony_ciOpDecorate %Uniforms Block
3318fd4e5da5Sopenharmony_ciOpDecorate %uniforms DescriptorSet 1
3319fd4e5da5Sopenharmony_ciOpDecorate %uniforms Binding 0
3320fd4e5da5Sopenharmony_ciOpDecorate %outColor Location 0
3321fd4e5da5Sopenharmony_ci;CHECK: OpDecorate {{%\w+}} NonUniform
3322fd4e5da5Sopenharmony_ci;CHECK: OpDecorate {{%\w+}} NonUniform
3323fd4e5da5Sopenharmony_ci)" + kImportDeco + R"(
3324fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
3325fd4e5da5Sopenharmony_ci;CHECK: OpDecorate [[desc_state_result:%\w+]] NonUniform
3326fd4e5da5Sopenharmony_ci%void = OpTypeVoid
3327fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
3328fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
3329fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
3330fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
3331fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
3332fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
3333fd4e5da5Sopenharmony_ci%13 = OpTypeImage %float 2D 0 0 0 1 Unknown
3334fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
3335fd4e5da5Sopenharmony_ci%uint_8 = OpConstant %uint 8
3336fd4e5da5Sopenharmony_ci%_arr_13_uint_8 = OpTypeArray %13 %uint_8
3337fd4e5da5Sopenharmony_ci%_ptr_UniformConstant__arr_13_uint_8 = OpTypePointer UniformConstant %_arr_13_uint_8
3338fd4e5da5Sopenharmony_ci%uniformTexArr = OpVariable %_ptr_UniformConstant__arr_13_uint_8 UniformConstant
3339fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
3340fd4e5da5Sopenharmony_ci%23 = OpTypeSampler
3341fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_23 = OpTypePointer UniformConstant %23
3342fd4e5da5Sopenharmony_ci%uniformSampler = OpVariable %_ptr_UniformConstant_23 UniformConstant
3343fd4e5da5Sopenharmony_ci%27 = OpTypeSampledImage %13
3344fd4e5da5Sopenharmony_ci%v2float = OpTypeVector %float 2
3345fd4e5da5Sopenharmony_ci%_ptr_Input_v2float = OpTypePointer Input %v2float
3346fd4e5da5Sopenharmony_ci%inTexcoord = OpVariable %_ptr_Input_v2float Input
3347fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
3348fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
3349fd4e5da5Sopenharmony_ci%uniformTex = OpVariable %_ptr_UniformConstant_13 UniformConstant
3350fd4e5da5Sopenharmony_ci%Uniforms = OpTypeStruct %v2float
3351fd4e5da5Sopenharmony_ci%_ptr_Uniform_Uniforms = OpTypePointer Uniform %Uniforms
3352fd4e5da5Sopenharmony_ci%uniforms = OpVariable %_ptr_Uniform_Uniforms Uniform
3353fd4e5da5Sopenharmony_ci%_ptr_Uniform_v2float = OpTypePointer Uniform %v2float
3354fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
3355fd4e5da5Sopenharmony_ci%outColor = OpVariable %_ptr_Output_v4float Output
3356fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
3357fd4e5da5Sopenharmony_ci;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
3358fd4e5da5Sopenharmony_ci;CHECK: [[null_v2float:%\w+]] = OpConstantNull %v2float
3359fd4e5da5Sopenharmony_ci)";
3360fd4e5da5Sopenharmony_ci
3361fd4e5da5Sopenharmony_ci  const std::string main_func = R"(
3362fd4e5da5Sopenharmony_ci%main = OpFunction %void None %3
3363fd4e5da5Sopenharmony_ci%5 = OpLabel
3364fd4e5da5Sopenharmony_ci%index = OpVariable %_ptr_Function_int Function
3365fd4e5da5Sopenharmony_ci%x = OpVariable %_ptr_Function_float Function
3366fd4e5da5Sopenharmony_ci%y = OpVariable %_ptr_Function_float Function
3367fd4e5da5Sopenharmony_ciOpStore %index %int_0
3368fd4e5da5Sopenharmony_ci%19 = OpLoad %int %index
3369fd4e5da5Sopenharmony_ci%21 = OpAccessChain %_ptr_UniformConstant_13 %uniformTexArr %19
3370fd4e5da5Sopenharmony_ci%22 = OpLoad %13 %21
3371fd4e5da5Sopenharmony_ci%26 = OpLoad %23 %uniformSampler
3372fd4e5da5Sopenharmony_ci%28 = OpSampledImage %27 %22 %26
3373fd4e5da5Sopenharmony_ci%32 = OpLoad %v2float %inTexcoord
3374fd4e5da5Sopenharmony_ci%34 = OpImageSampleImplicitLod %v4float %28 %32
3375fd4e5da5Sopenharmony_ci%36 = OpCompositeExtract %float %34 0
3376fd4e5da5Sopenharmony_ci;CHECK-NOT: %34 = OpImageSampleImplicitLod %v4float %28 %32
3377fd4e5da5Sopenharmony_ci;CHECK-NOT: %36 = OpCompositeExtract %float %34 0
3378fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord
3379fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}}
3380fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
3381fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
3382fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0
3383fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %uint %19
3384fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_80 {{%\w+}} %uint_1 %uint_3 {{%\w+}} %uint_0
3385fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
3386fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
3387fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3388fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %13 %21
3389fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpSampledImage %27 {{%\w+}} %26
3390fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpImageSampleImplicitLod %v4float {{%\w+}} %32
3391fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
3392fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3393fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
3394fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3395fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}}
3396fd4e5da5Sopenharmony_ciOpStore %x %36
3397fd4e5da5Sopenharmony_ci%39 = OpLoad %13 %uniformTex
3398fd4e5da5Sopenharmony_ci%40 = OpLoad %23 %uniformSampler
3399fd4e5da5Sopenharmony_ci%41 = OpSampledImage %27 %39 %40
3400fd4e5da5Sopenharmony_ci%42 = OpLoad %v2float %inTexcoord
3401fd4e5da5Sopenharmony_ci%47 = OpAccessChain %_ptr_Uniform_v2float %uniforms %int_0
3402fd4e5da5Sopenharmony_ci%48 = OpLoad %v2float %47
3403fd4e5da5Sopenharmony_ci%49 = OpFMul %v2float %42 %48
3404fd4e5da5Sopenharmony_ci;CHECK-NOT: %48 = OpLoad %v2float %47
3405fd4e5da5Sopenharmony_ci;CHECK-NOT: %49 = OpFMul %v2float %42 %48
3406fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord
3407fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}}
3408fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
3409fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
3410fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0
3411fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_88 {{%\w+}} %uint_1 %uint_0 %uint_0 {{%\w+}}
3412fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
3413fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
3414fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3415fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v2float %47
3416fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
3417fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3418fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
3419fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3420fd4e5da5Sopenharmony_ci;CHECK: [[phi_result:%\w+]] = OpPhi %v2float {{%\w+}} {{%\w+}} [[null_v2float]] {{%\w+}}
3421fd4e5da5Sopenharmony_ci;CHECK: %49 = OpFMul %v2float %42 [[phi_result]]
3422fd4e5da5Sopenharmony_ci%50 = OpImageSampleImplicitLod %v4float %41 %49
3423fd4e5da5Sopenharmony_ci%51 = OpCompositeExtract %float %50 0
3424fd4e5da5Sopenharmony_ciOpStore %y %51
3425fd4e5da5Sopenharmony_ci;CHECK-NOT: %50 = OpImageSampleImplicitLod %v4float %41 %49
3426fd4e5da5Sopenharmony_ci;CHECK-NOT: %51 = OpCompositeExtract %float %50 0
3427fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpSampledImage %27 %39 %40
3428fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord
3429fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}}
3430fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
3431fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
3432fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0
3433fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_90 {{%\w+}} %uint_1 %uint_2 %uint_0 %uint_0
3434fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
3435fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
3436fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3437fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %13 %uniformTex
3438fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpSampledImage %27 {{%\w+}} %40
3439fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpImageSampleImplicitLod %v4float {{%\w+}} %49
3440fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
3441fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3442fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
3443fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3444fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}}
3445fd4e5da5Sopenharmony_ci;CHECK: %51 = OpCompositeExtract %float {{%\w+}} 0
3446fd4e5da5Sopenharmony_ciOpStore %y %51
3447fd4e5da5Sopenharmony_ci%54 = OpLoad %float %x
3448fd4e5da5Sopenharmony_ci%55 = OpLoad %float %y
3449fd4e5da5Sopenharmony_ci%57 = OpCompositeConstruct %v4float %54 %55 %float_0 %float_0
3450fd4e5da5Sopenharmony_ciOpStore %outColor %57
3451fd4e5da5Sopenharmony_ciOpReturn
3452fd4e5da5Sopenharmony_ciOpFunctionEnd
3453fd4e5da5Sopenharmony_ci)";
3454fd4e5da5Sopenharmony_ci  // clang-format on
3455fd4e5da5Sopenharmony_ci
3456fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
3457fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(defs + kImportStub + main_func,
3458fd4e5da5Sopenharmony_ci                                               true, 23u);
3459fd4e5da5Sopenharmony_ci}
3460fd4e5da5Sopenharmony_ci
3461fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest, MultipleUniformNonAggregateRefsNoDescInit) {
3462fd4e5da5Sopenharmony_ci  // Check that uniform refs do not go out-of-bounds. All checks use same input
3463fd4e5da5Sopenharmony_ci  // buffer read function call result at top of function for uniform buffer
3464fd4e5da5Sopenharmony_ci  // length. Because descriptor indexing is not being checked, we can avoid one
3465fd4e5da5Sopenharmony_ci  // buffer load.
3466fd4e5da5Sopenharmony_ci  //
3467fd4e5da5Sopenharmony_ci  // Texture2D g_tColor;
3468fd4e5da5Sopenharmony_ci  // SamplerState g_sAniso;
3469fd4e5da5Sopenharmony_ci  //
3470fd4e5da5Sopenharmony_ci  // layout(push_constant) cbuffer PerViewPushConst_t { bool g_B; };
3471fd4e5da5Sopenharmony_ci  //
3472fd4e5da5Sopenharmony_ci  // cbuffer PerViewConstantBuffer_t {
3473fd4e5da5Sopenharmony_ci  //   float2 g_TexOff0;
3474fd4e5da5Sopenharmony_ci  //   float2 g_TexOff1;
3475fd4e5da5Sopenharmony_ci  // };
3476fd4e5da5Sopenharmony_ci  //
3477fd4e5da5Sopenharmony_ci  // struct PS_INPUT {
3478fd4e5da5Sopenharmony_ci  //   float2 vTextureCoords : TEXCOORD2;
3479fd4e5da5Sopenharmony_ci  // };
3480fd4e5da5Sopenharmony_ci  //
3481fd4e5da5Sopenharmony_ci  // struct PS_OUTPUT {
3482fd4e5da5Sopenharmony_ci  //   float4 vColor : SV_Target0;
3483fd4e5da5Sopenharmony_ci  // };
3484fd4e5da5Sopenharmony_ci  //
3485fd4e5da5Sopenharmony_ci  // PS_OUTPUT MainPs(PS_INPUT i) {
3486fd4e5da5Sopenharmony_ci  //   PS_OUTPUT ps_output;
3487fd4e5da5Sopenharmony_ci  //   float2 off;
3488fd4e5da5Sopenharmony_ci  //   float2 vtc;
3489fd4e5da5Sopenharmony_ci  //   if (g_B)
3490fd4e5da5Sopenharmony_ci  //     off = g_TexOff0;
3491fd4e5da5Sopenharmony_ci  //   else
3492fd4e5da5Sopenharmony_ci  //     off = g_TexOff1;
3493fd4e5da5Sopenharmony_ci  //   vtc = i.vTextureCoords.xy + off;
3494fd4e5da5Sopenharmony_ci  //   ps_output.vColor = g_tColor.Sample(g_sAniso, vtc);
3495fd4e5da5Sopenharmony_ci  //   return ps_output;
3496fd4e5da5Sopenharmony_ci  // }
3497fd4e5da5Sopenharmony_ci
3498fd4e5da5Sopenharmony_ci  // clang-format off
3499fd4e5da5Sopenharmony_ci  const std::string text = R"(
3500fd4e5da5Sopenharmony_ciOpCapability Shader
3501fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
3502fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
3503fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
3504fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %MainPs "MainPs" %_ %__0 %g_tColor %g_sAniso %i_vTextureCoords %_entryPointOutput_vColor
3505fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint Fragment %MainPs "MainPs" %_ %__0 %g_tColor %g_sAniso %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
3506fd4e5da5Sopenharmony_ciOpExecutionMode %MainPs OriginUpperLeft
3507fd4e5da5Sopenharmony_ciOpSource HLSL 500
3508fd4e5da5Sopenharmony_ciOpName %MainPs "MainPs"
3509fd4e5da5Sopenharmony_ciOpName %PerViewPushConst_t "PerViewPushConst_t"
3510fd4e5da5Sopenharmony_ciOpMemberName %PerViewPushConst_t 0 "g_B"
3511fd4e5da5Sopenharmony_ciOpName %_ ""
3512fd4e5da5Sopenharmony_ciOpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
3513fd4e5da5Sopenharmony_ciOpMemberName %PerViewConstantBuffer_t 0 "g_TexOff0"
3514fd4e5da5Sopenharmony_ciOpMemberName %PerViewConstantBuffer_t 1 "g_TexOff1"
3515fd4e5da5Sopenharmony_ciOpName %__0 ""
3516fd4e5da5Sopenharmony_ciOpName %g_tColor "g_tColor"
3517fd4e5da5Sopenharmony_ciOpName %g_sAniso "g_sAniso"
3518fd4e5da5Sopenharmony_ciOpName %i_vTextureCoords "i.vTextureCoords"
3519fd4e5da5Sopenharmony_ciOpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
3520fd4e5da5Sopenharmony_ciOpMemberDecorate %PerViewPushConst_t 0 Offset 0
3521fd4e5da5Sopenharmony_ciOpDecorate %PerViewPushConst_t Block
3522fd4e5da5Sopenharmony_ciOpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
3523fd4e5da5Sopenharmony_ciOpMemberDecorate %PerViewConstantBuffer_t 1 Offset 8
3524fd4e5da5Sopenharmony_ciOpDecorate %PerViewConstantBuffer_t Block
3525fd4e5da5Sopenharmony_ciOpDecorate %__0 DescriptorSet 0
3526fd4e5da5Sopenharmony_ciOpDecorate %__0 Binding 1
3527fd4e5da5Sopenharmony_ciOpDecorate %g_tColor DescriptorSet 0
3528fd4e5da5Sopenharmony_ciOpDecorate %g_tColor Binding 0
3529fd4e5da5Sopenharmony_ciOpDecorate %g_sAniso DescriptorSet 0
3530fd4e5da5Sopenharmony_ciOpDecorate %g_sAniso Binding 2
3531fd4e5da5Sopenharmony_ciOpDecorate %i_vTextureCoords Location 0
3532fd4e5da5Sopenharmony_ciOpDecorate %_entryPointOutput_vColor Location 0
3533fd4e5da5Sopenharmony_ci)" + kImportDeco + R"(
3534fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
3535fd4e5da5Sopenharmony_ci%void = OpTypeVoid
3536fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
3537fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
3538fd4e5da5Sopenharmony_ci%v2float = OpTypeVector %float 2
3539fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
3540fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
3541fd4e5da5Sopenharmony_ci%PerViewPushConst_t = OpTypeStruct %uint
3542fd4e5da5Sopenharmony_ci%_ptr_PushConstant_PerViewPushConst_t = OpTypePointer PushConstant %PerViewPushConst_t
3543fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_PushConstant_PerViewPushConst_t PushConstant
3544fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
3545fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
3546fd4e5da5Sopenharmony_ci%_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
3547fd4e5da5Sopenharmony_ci%bool = OpTypeBool
3548fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
3549fd4e5da5Sopenharmony_ci%PerViewConstantBuffer_t = OpTypeStruct %v2float %v2float
3550fd4e5da5Sopenharmony_ci%_ptr_Uniform_PerViewConstantBuffer_t = OpTypePointer Uniform %PerViewConstantBuffer_t
3551fd4e5da5Sopenharmony_ci%__0 = OpVariable %_ptr_Uniform_PerViewConstantBuffer_t Uniform
3552fd4e5da5Sopenharmony_ci%_ptr_Uniform_v2float = OpTypePointer Uniform %v2float
3553fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
3554fd4e5da5Sopenharmony_ci%49 = OpTypeImage %float 2D 0 0 0 1 Unknown
3555fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_49 = OpTypePointer UniformConstant %49
3556fd4e5da5Sopenharmony_ci%g_tColor = OpVariable %_ptr_UniformConstant_49 UniformConstant
3557fd4e5da5Sopenharmony_ci%53 = OpTypeSampler
3558fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_53 = OpTypePointer UniformConstant %53
3559fd4e5da5Sopenharmony_ci%g_sAniso = OpVariable %_ptr_UniformConstant_53 UniformConstant
3560fd4e5da5Sopenharmony_ci%57 = OpTypeSampledImage %49
3561fd4e5da5Sopenharmony_ci%_ptr_Input_v2float = OpTypePointer Input %v2float
3562fd4e5da5Sopenharmony_ci%i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
3563fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
3564fd4e5da5Sopenharmony_ci%_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
3565fd4e5da5Sopenharmony_ci;CHECK: %v4uint = OpTypeVector %uint 4
3566fd4e5da5Sopenharmony_ci;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
3567fd4e5da5Sopenharmony_ci;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
3568fd4e5da5Sopenharmony_ci;CHECK: [[null_v2float:%\w+]] = OpConstantNull %v2float
3569fd4e5da5Sopenharmony_ci )" + kImportStub + R"(
3570fd4e5da5Sopenharmony_ci%MainPs = OpFunction %void None %3
3571fd4e5da5Sopenharmony_ci%5 = OpLabel
3572fd4e5da5Sopenharmony_ci%69 = OpLoad %v2float %i_vTextureCoords
3573fd4e5da5Sopenharmony_ci%82 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
3574fd4e5da5Sopenharmony_ci%83 = OpLoad %uint %82
3575fd4e5da5Sopenharmony_ci%84 = OpINotEqual %bool %83 %uint_0
3576fd4e5da5Sopenharmony_ciOpSelectionMerge %91 None
3577fd4e5da5Sopenharmony_ciOpBranchConditional %84 %85 %88
3578fd4e5da5Sopenharmony_ci%85 = OpLabel
3579fd4e5da5Sopenharmony_ci%86 = OpAccessChain %_ptr_Uniform_v2float %__0 %int_0
3580fd4e5da5Sopenharmony_ci%87 = OpLoad %v2float %86
3581fd4e5da5Sopenharmony_ci;CHECK-NOT:     %87 = OpLoad %v2float %86
3582fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3583fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpIAdd %uint %uint_0 %uint_7
3584fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord
3585fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}}
3586fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
3587fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
3588fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0
3589fd4e5da5Sopenharmony_ci;CHECK: [[desc_state_result:%\w+]] = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_72 {{%\w+}} %uint_0 %uint_1 %uint_0 {{%\w+}}
3590fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
3591fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional [[desc_state_result]] {{%\w+}} {{%\w+}}
3592fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3593fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v2float %86
3594fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
3595fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3596fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
3597fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3598fd4e5da5Sopenharmony_ci ;CHECK: {{%\w+}} = OpPhi %v2float {{%\w+}} {{%\w+}} [[null_v2float]] {{%\w+}}
3599fd4e5da5Sopenharmony_ciOpBranch %91
3600fd4e5da5Sopenharmony_ci%88 = OpLabel
3601fd4e5da5Sopenharmony_ci%89 = OpAccessChain %_ptr_Uniform_v2float %__0 %int_1
3602fd4e5da5Sopenharmony_ci%90 = OpLoad %v2float %89
3603fd4e5da5Sopenharmony_ci;CHECK-NOT:     %90 = OpLoad %v2float %89
3604fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpIAdd %uint %uint_8 %uint_7
3605fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord
3606fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}}
3607fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
3608fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
3609fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0
3610fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_76 {{%\w+}} %uint_0 %uint_1 %uint_0 {{%\w+}}
3611fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
3612fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
3613fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3614fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v2float %89
3615fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
3616fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3617fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
3618fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3619fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpPhi %v2float {{%\w+}} {{%\w+}} [[null_v2float]] {{%\w+}}
3620fd4e5da5Sopenharmony_ciOpBranch %91
3621fd4e5da5Sopenharmony_ci%91 = OpLabel
3622fd4e5da5Sopenharmony_ci%115 = OpPhi %v2float %87 %85 %90 %88
3623fd4e5da5Sopenharmony_ci;CHECK-NOT:       %115 = OpPhi %v2float %87 %85 %90 %88
3624fd4e5da5Sopenharmony_ci;CHECK: %115 = OpPhi %v2float {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}}
3625fd4e5da5Sopenharmony_ci%95 = OpFAdd %v2float %69 %115
3626fd4e5da5Sopenharmony_ci%96 = OpLoad %49 %g_tColor
3627fd4e5da5Sopenharmony_ci%97 = OpLoad %53 %g_sAniso
3628fd4e5da5Sopenharmony_ci%98 = OpSampledImage %57 %96 %97
3629fd4e5da5Sopenharmony_ci%100 = OpImageSampleImplicitLod %v4float %98 %95
3630fd4e5da5Sopenharmony_ciOpStore %_entryPointOutput_vColor %100
3631fd4e5da5Sopenharmony_ciOpReturn
3632fd4e5da5Sopenharmony_ciOpFunctionEnd
3633fd4e5da5Sopenharmony_ci)";
3634fd4e5da5Sopenharmony_ci  // clang-format on
3635fd4e5da5Sopenharmony_ci
3636fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
3637fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
3638fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 23u);
3639fd4e5da5Sopenharmony_ci}
3640fd4e5da5Sopenharmony_ci
3641fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest, UniformArrayRefNoDescInit) {
3642fd4e5da5Sopenharmony_ci  // Check that uniform array ref does not go out-of-bounds.
3643fd4e5da5Sopenharmony_ci  //
3644fd4e5da5Sopenharmony_ci  // Texture2D g_tColor;
3645fd4e5da5Sopenharmony_ci  // SamplerState g_sAniso;
3646fd4e5da5Sopenharmony_ci  //
3647fd4e5da5Sopenharmony_ci  // layout(push_constant) cbuffer PerViewPushConst_t { uint g_c; };
3648fd4e5da5Sopenharmony_ci  //
3649fd4e5da5Sopenharmony_ci  // struct PerBatchEnvMapConstantBuffer_t {
3650fd4e5da5Sopenharmony_ci  //   float4x3 g_matEnvMapWorldToLocal;
3651fd4e5da5Sopenharmony_ci  //   float4 g_vEnvironmentMapBoxMins;
3652fd4e5da5Sopenharmony_ci  //   float2 g_TexOff;
3653fd4e5da5Sopenharmony_ci  // };
3654fd4e5da5Sopenharmony_ci  //
3655fd4e5da5Sopenharmony_ci  // cbuffer _BindlessFastEnvMapCB_PS_t {
3656fd4e5da5Sopenharmony_ci  //   PerBatchEnvMapConstantBuffer_t g_envMapConstants[128];
3657fd4e5da5Sopenharmony_ci  // };
3658fd4e5da5Sopenharmony_ci  //
3659fd4e5da5Sopenharmony_ci  // struct PS_INPUT {
3660fd4e5da5Sopenharmony_ci  //   float2 vTextureCoords : TEXCOORD2;
3661fd4e5da5Sopenharmony_ci  // };
3662fd4e5da5Sopenharmony_ci  //
3663fd4e5da5Sopenharmony_ci  // struct PS_OUTPUT {
3664fd4e5da5Sopenharmony_ci  //   float4 vColor : SV_Target0;
3665fd4e5da5Sopenharmony_ci  // };
3666fd4e5da5Sopenharmony_ci  //
3667fd4e5da5Sopenharmony_ci  // PS_OUTPUT MainPs(PS_INPUT i) {
3668fd4e5da5Sopenharmony_ci  //   PS_OUTPUT ps_output;
3669fd4e5da5Sopenharmony_ci  //   float2 off;
3670fd4e5da5Sopenharmony_ci  //   float2 vtc;
3671fd4e5da5Sopenharmony_ci  //   off = g_envMapConstants[g_c].g_TexOff;
3672fd4e5da5Sopenharmony_ci  //   vtc = i.vTextureCoords.xy + off;
3673fd4e5da5Sopenharmony_ci  //   ps_output.vColor = g_tColor.Sample(g_sAniso, vtc);
3674fd4e5da5Sopenharmony_ci  //   return ps_output;
3675fd4e5da5Sopenharmony_ci  // }
3676fd4e5da5Sopenharmony_ci
3677fd4e5da5Sopenharmony_ci  // clang-format off
3678fd4e5da5Sopenharmony_ci  const std::string text = R"(
3679fd4e5da5Sopenharmony_ciOpCapability Shader
3680fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
3681fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
3682fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
3683fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %MainPs "MainPs" %_ %__0 %g_tColor %g_sAniso %i_vTextureCoords %_entryPointOutput_vColor
3684fd4e5da5Sopenharmony_ciOpExecutionMode %MainPs OriginUpperLeft
3685fd4e5da5Sopenharmony_ciOpSource HLSL 500
3686fd4e5da5Sopenharmony_ciOpName %MainPs "MainPs"
3687fd4e5da5Sopenharmony_ciOpName %PerBatchEnvMapConstantBuffer_t "PerBatchEnvMapConstantBuffer_t"
3688fd4e5da5Sopenharmony_ciOpMemberName %PerBatchEnvMapConstantBuffer_t 0 "g_matEnvMapWorldToLocal"
3689fd4e5da5Sopenharmony_ciOpMemberName %PerBatchEnvMapConstantBuffer_t 1 "g_vEnvironmentMapBoxMins"
3690fd4e5da5Sopenharmony_ciOpMemberName %PerBatchEnvMapConstantBuffer_t 2 "g_TexOff"
3691fd4e5da5Sopenharmony_ciOpName %_BindlessFastEnvMapCB_PS_t "_BindlessFastEnvMapCB_PS_t"
3692fd4e5da5Sopenharmony_ciOpMemberName %_BindlessFastEnvMapCB_PS_t 0 "g_envMapConstants"
3693fd4e5da5Sopenharmony_ciOpName %_ ""
3694fd4e5da5Sopenharmony_ciOpName %PerViewPushConst_t "PerViewPushConst_t"
3695fd4e5da5Sopenharmony_ciOpMemberName %PerViewPushConst_t 0 "g_c"
3696fd4e5da5Sopenharmony_ciOpName %__0 ""
3697fd4e5da5Sopenharmony_ciOpName %g_tColor "g_tColor"
3698fd4e5da5Sopenharmony_ciOpName %g_sAniso "g_sAniso"
3699fd4e5da5Sopenharmony_ciOpName %i_vTextureCoords "i.vTextureCoords"
3700fd4e5da5Sopenharmony_ciOpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
3701fd4e5da5Sopenharmony_ciOpMemberDecorate %PerBatchEnvMapConstantBuffer_t 0 RowMajor
3702fd4e5da5Sopenharmony_ciOpMemberDecorate %PerBatchEnvMapConstantBuffer_t 0 Offset 0
3703fd4e5da5Sopenharmony_ciOpMemberDecorate %PerBatchEnvMapConstantBuffer_t 0 MatrixStride 16
3704fd4e5da5Sopenharmony_ciOpMemberDecorate %PerBatchEnvMapConstantBuffer_t 1 Offset 48
3705fd4e5da5Sopenharmony_ciOpMemberDecorate %PerBatchEnvMapConstantBuffer_t 2 Offset 64
3706fd4e5da5Sopenharmony_ciOpDecorate %_arr_PerBatchEnvMapConstantBuffer_t_uint_128 ArrayStride 80
3707fd4e5da5Sopenharmony_ciOpMemberDecorate %_BindlessFastEnvMapCB_PS_t 0 Offset 0
3708fd4e5da5Sopenharmony_ciOpDecorate %_BindlessFastEnvMapCB_PS_t Block
3709fd4e5da5Sopenharmony_ciOpDecorate %_ DescriptorSet 0
3710fd4e5da5Sopenharmony_ciOpDecorate %_ Binding 2
3711fd4e5da5Sopenharmony_ciOpMemberDecorate %PerViewPushConst_t 0 Offset 0
3712fd4e5da5Sopenharmony_ciOpDecorate %PerViewPushConst_t Block
3713fd4e5da5Sopenharmony_ciOpDecorate %g_tColor DescriptorSet 0
3714fd4e5da5Sopenharmony_ciOpDecorate %g_tColor Binding 0
3715fd4e5da5Sopenharmony_ciOpDecorate %g_sAniso DescriptorSet 0
3716fd4e5da5Sopenharmony_ciOpDecorate %g_sAniso Binding 1
3717fd4e5da5Sopenharmony_ciOpDecorate %i_vTextureCoords Location 0
3718fd4e5da5Sopenharmony_ciOpDecorate %_entryPointOutput_vColor Location 0
3719fd4e5da5Sopenharmony_ci)" + kImportDeco + R"(
3720fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
3721fd4e5da5Sopenharmony_ci%void = OpTypeVoid
3722fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
3723fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
3724fd4e5da5Sopenharmony_ci%v2float = OpTypeVector %float 2
3725fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
3726fd4e5da5Sopenharmony_ci%v3float = OpTypeVector %float 3
3727fd4e5da5Sopenharmony_ci%mat4v3float = OpTypeMatrix %v3float 4
3728fd4e5da5Sopenharmony_ci%PerBatchEnvMapConstantBuffer_t = OpTypeStruct %mat4v3float %v4float %v2float
3729fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
3730fd4e5da5Sopenharmony_ci%uint_128 = OpConstant %uint 128
3731fd4e5da5Sopenharmony_ci%_arr_PerBatchEnvMapConstantBuffer_t_uint_128 = OpTypeArray %PerBatchEnvMapConstantBuffer_t %uint_128
3732fd4e5da5Sopenharmony_ci%_BindlessFastEnvMapCB_PS_t = OpTypeStruct %_arr_PerBatchEnvMapConstantBuffer_t_uint_128
3733fd4e5da5Sopenharmony_ci%_ptr_Uniform__BindlessFastEnvMapCB_PS_t = OpTypePointer Uniform %_BindlessFastEnvMapCB_PS_t
3734fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_Uniform__BindlessFastEnvMapCB_PS_t Uniform
3735fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
3736fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
3737fd4e5da5Sopenharmony_ci%PerViewPushConst_t = OpTypeStruct %uint
3738fd4e5da5Sopenharmony_ci%_ptr_PushConstant_PerViewPushConst_t = OpTypePointer PushConstant %PerViewPushConst_t
3739fd4e5da5Sopenharmony_ci%__0 = OpVariable %_ptr_PushConstant_PerViewPushConst_t PushConstant
3740fd4e5da5Sopenharmony_ci%_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
3741fd4e5da5Sopenharmony_ci%int_2 = OpConstant %int 2
3742fd4e5da5Sopenharmony_ci%_ptr_Uniform_v2float = OpTypePointer Uniform %v2float
3743fd4e5da5Sopenharmony_ci%46 = OpTypeImage %float 2D 0 0 0 1 Unknown
3744fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_46 = OpTypePointer UniformConstant %46
3745fd4e5da5Sopenharmony_ci%g_tColor = OpVariable %_ptr_UniformConstant_46 UniformConstant
3746fd4e5da5Sopenharmony_ci%50 = OpTypeSampler
3747fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_50 = OpTypePointer UniformConstant %50
3748fd4e5da5Sopenharmony_ci%g_sAniso = OpVariable %_ptr_UniformConstant_50 UniformConstant
3749fd4e5da5Sopenharmony_ci%54 = OpTypeSampledImage %46
3750fd4e5da5Sopenharmony_ci%_ptr_Input_v2float = OpTypePointer Input %v2float
3751fd4e5da5Sopenharmony_ci%i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
3752fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
3753fd4e5da5Sopenharmony_ci%_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
3754fd4e5da5Sopenharmony_ci;CHECK: %v4uint = OpTypeVector %uint 4
3755fd4e5da5Sopenharmony_ci;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
3756fd4e5da5Sopenharmony_ci;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
3757fd4e5da5Sopenharmony_ci;CHECK: [[null_v2float:%\w+]] = OpConstantNull %v2float
3758fd4e5da5Sopenharmony_ci)" + kImportStub + R"(
3759fd4e5da5Sopenharmony_ci%MainPs = OpFunction %void None %3
3760fd4e5da5Sopenharmony_ci%5 = OpLabel
3761fd4e5da5Sopenharmony_ci%66 = OpLoad %v2float %i_vTextureCoords
3762fd4e5da5Sopenharmony_ci%79 = OpAccessChain %_ptr_PushConstant_uint %__0 %int_0
3763fd4e5da5Sopenharmony_ci%80 = OpLoad %uint %79
3764fd4e5da5Sopenharmony_ci%81 = OpAccessChain %_ptr_Uniform_v2float %_ %int_0 %80 %int_2
3765fd4e5da5Sopenharmony_ci%82 = OpLoad %v2float %81
3766fd4e5da5Sopenharmony_ci;CHECK-NOT: %82 = OpLoad %v2float %81
3767fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpIMul %uint %uint_80 %80
3768fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpIAdd %uint %uint_0 {{%\w+}}
3769fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_64
3770fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_7
3771fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord
3772fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}}
3773fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
3774fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
3775fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0
3776fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_79 {{%\w+}} %uint_0 %uint_2 %uint_0 {{%\w+}}
3777fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
3778fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
3779fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3780fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v2float %81
3781fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
3782fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3783fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
3784fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3785fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpPhi %v2float {{%\w+}} {{%\w+}} [[null_v2float]] {{%\w+}}
3786fd4e5da5Sopenharmony_ci%86 = OpFAdd %v2float %66 %82
3787fd4e5da5Sopenharmony_ci;CHECK-NOT: %86 = OpFAdd %v2float %66 %82
3788fd4e5da5Sopenharmony_ci;CHECK: %86 = OpFAdd %v2float %66 {{%\w+}}
3789fd4e5da5Sopenharmony_ci%87 = OpLoad %46 %g_tColor
3790fd4e5da5Sopenharmony_ci%88 = OpLoad %50 %g_sAniso
3791fd4e5da5Sopenharmony_ci%89 = OpSampledImage %54 %87 %88
3792fd4e5da5Sopenharmony_ci%91 = OpImageSampleImplicitLod %v4float %89 %86
3793fd4e5da5Sopenharmony_ciOpStore %_entryPointOutput_vColor %91
3794fd4e5da5Sopenharmony_ciOpReturn
3795fd4e5da5Sopenharmony_ciOpFunctionEnd
3796fd4e5da5Sopenharmony_ci)";
3797fd4e5da5Sopenharmony_ci  // clang-format on
3798fd4e5da5Sopenharmony_ci
3799fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
3800fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
3801fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 23u);
3802fd4e5da5Sopenharmony_ci}
3803fd4e5da5Sopenharmony_ci
3804fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest, UniformArrayRefWithDescInit) {
3805fd4e5da5Sopenharmony_ci  // The buffer-oob and desc-init checks should use the same debug
3806fd4e5da5Sopenharmony_ci  // output buffer write function.
3807fd4e5da5Sopenharmony_ci  //
3808fd4e5da5Sopenharmony_ci  // Same source as UniformArrayRefNoDescInit
3809fd4e5da5Sopenharmony_ci
3810fd4e5da5Sopenharmony_ci  // clang-format off
3811fd4e5da5Sopenharmony_ci  const std::string text = R"(
3812fd4e5da5Sopenharmony_ciOpCapability Shader
3813fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
3814fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
3815fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
3816fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %MainPs "MainPs" %_ %__0 %g_tColor %g_sAniso %i_vTextureCoords %_entryPointOutput_vColor
3817fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint Fragment %MainPs "MainPs" %_ %__0 %g_tColor %g_sAniso %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
3818fd4e5da5Sopenharmony_ciOpExecutionMode %MainPs OriginUpperLeft
3819fd4e5da5Sopenharmony_ciOpSource HLSL 500
3820fd4e5da5Sopenharmony_ciOpName %MainPs "MainPs"
3821fd4e5da5Sopenharmony_ciOpName %PerBatchEnvMapConstantBuffer_t "PerBatchEnvMapConstantBuffer_t"
3822fd4e5da5Sopenharmony_ciOpMemberName %PerBatchEnvMapConstantBuffer_t 0 "g_matEnvMapWorldToLocal"
3823fd4e5da5Sopenharmony_ciOpMemberName %PerBatchEnvMapConstantBuffer_t 1 "g_vEnvironmentMapBoxMins"
3824fd4e5da5Sopenharmony_ciOpMemberName %PerBatchEnvMapConstantBuffer_t 2 "g_TexOff"
3825fd4e5da5Sopenharmony_ciOpName %_BindlessFastEnvMapCB_PS_t "_BindlessFastEnvMapCB_PS_t"
3826fd4e5da5Sopenharmony_ciOpMemberName %_BindlessFastEnvMapCB_PS_t 0 "g_envMapConstants"
3827fd4e5da5Sopenharmony_ciOpName %_ ""
3828fd4e5da5Sopenharmony_ciOpName %PerViewPushConst_t "PerViewPushConst_t"
3829fd4e5da5Sopenharmony_ciOpMemberName %PerViewPushConst_t 0 "g_c"
3830fd4e5da5Sopenharmony_ciOpName %__0 ""
3831fd4e5da5Sopenharmony_ciOpName %g_tColor "g_tColor"
3832fd4e5da5Sopenharmony_ciOpName %g_sAniso "g_sAniso"
3833fd4e5da5Sopenharmony_ciOpName %i_vTextureCoords "i.vTextureCoords"
3834fd4e5da5Sopenharmony_ciOpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
3835fd4e5da5Sopenharmony_ciOpMemberDecorate %PerBatchEnvMapConstantBuffer_t 0 RowMajor
3836fd4e5da5Sopenharmony_ciOpMemberDecorate %PerBatchEnvMapConstantBuffer_t 0 Offset 0
3837fd4e5da5Sopenharmony_ciOpMemberDecorate %PerBatchEnvMapConstantBuffer_t 0 MatrixStride 16
3838fd4e5da5Sopenharmony_ciOpMemberDecorate %PerBatchEnvMapConstantBuffer_t 1 Offset 48
3839fd4e5da5Sopenharmony_ciOpMemberDecorate %PerBatchEnvMapConstantBuffer_t 2 Offset 64
3840fd4e5da5Sopenharmony_ciOpDecorate %_arr_PerBatchEnvMapConstantBuffer_t_uint_128 ArrayStride 80
3841fd4e5da5Sopenharmony_ciOpMemberDecorate %_BindlessFastEnvMapCB_PS_t 0 Offset 0
3842fd4e5da5Sopenharmony_ciOpDecorate %_BindlessFastEnvMapCB_PS_t Block
3843fd4e5da5Sopenharmony_ciOpDecorate %_ DescriptorSet 0
3844fd4e5da5Sopenharmony_ciOpDecorate %_ Binding 2
3845fd4e5da5Sopenharmony_ciOpMemberDecorate %PerViewPushConst_t 0 Offset 0
3846fd4e5da5Sopenharmony_ciOpDecorate %PerViewPushConst_t Block
3847fd4e5da5Sopenharmony_ciOpDecorate %g_tColor DescriptorSet 0
3848fd4e5da5Sopenharmony_ciOpDecorate %g_tColor Binding 0
3849fd4e5da5Sopenharmony_ciOpDecorate %g_sAniso DescriptorSet 0
3850fd4e5da5Sopenharmony_ciOpDecorate %g_sAniso Binding 1
3851fd4e5da5Sopenharmony_ciOpDecorate %i_vTextureCoords Location 0
3852fd4e5da5Sopenharmony_ciOpDecorate %_entryPointOutput_vColor Location 0
3853fd4e5da5Sopenharmony_ci)" + kImportDeco + R"(
3854fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
3855fd4e5da5Sopenharmony_ci%void = OpTypeVoid
3856fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
3857fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
3858fd4e5da5Sopenharmony_ci%v2float = OpTypeVector %float 2
3859fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
3860fd4e5da5Sopenharmony_ci%v3float = OpTypeVector %float 3
3861fd4e5da5Sopenharmony_ci%mat4v3float = OpTypeMatrix %v3float 4
3862fd4e5da5Sopenharmony_ci%PerBatchEnvMapConstantBuffer_t = OpTypeStruct %mat4v3float %v4float %v2float
3863fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
3864fd4e5da5Sopenharmony_ci%uint_128 = OpConstant %uint 128
3865fd4e5da5Sopenharmony_ci%_arr_PerBatchEnvMapConstantBuffer_t_uint_128 = OpTypeArray %PerBatchEnvMapConstantBuffer_t %uint_128
3866fd4e5da5Sopenharmony_ci%_BindlessFastEnvMapCB_PS_t = OpTypeStruct %_arr_PerBatchEnvMapConstantBuffer_t_uint_128
3867fd4e5da5Sopenharmony_ci%_ptr_Uniform__BindlessFastEnvMapCB_PS_t = OpTypePointer Uniform %_BindlessFastEnvMapCB_PS_t
3868fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_Uniform__BindlessFastEnvMapCB_PS_t Uniform
3869fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
3870fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
3871fd4e5da5Sopenharmony_ci%PerViewPushConst_t = OpTypeStruct %uint
3872fd4e5da5Sopenharmony_ci%_ptr_PushConstant_PerViewPushConst_t = OpTypePointer PushConstant %PerViewPushConst_t
3873fd4e5da5Sopenharmony_ci%__0 = OpVariable %_ptr_PushConstant_PerViewPushConst_t PushConstant
3874fd4e5da5Sopenharmony_ci%_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
3875fd4e5da5Sopenharmony_ci%int_2 = OpConstant %int 2
3876fd4e5da5Sopenharmony_ci%_ptr_Uniform_v2float = OpTypePointer Uniform %v2float
3877fd4e5da5Sopenharmony_ci%46 = OpTypeImage %float 2D 0 0 0 1 Unknown
3878fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_46 = OpTypePointer UniformConstant %46
3879fd4e5da5Sopenharmony_ci%g_tColor = OpVariable %_ptr_UniformConstant_46 UniformConstant
3880fd4e5da5Sopenharmony_ci%50 = OpTypeSampler
3881fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_50 = OpTypePointer UniformConstant %50
3882fd4e5da5Sopenharmony_ci%g_sAniso = OpVariable %_ptr_UniformConstant_50 UniformConstant
3883fd4e5da5Sopenharmony_ci%54 = OpTypeSampledImage %46
3884fd4e5da5Sopenharmony_ci%_ptr_Input_v2float = OpTypePointer Input %v2float
3885fd4e5da5Sopenharmony_ci%i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
3886fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
3887fd4e5da5Sopenharmony_ci%_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
3888fd4e5da5Sopenharmony_ci;CHECK: %v4uint = OpTypeVector %uint 4
3889fd4e5da5Sopenharmony_ci;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
3890fd4e5da5Sopenharmony_ci;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
3891fd4e5da5Sopenharmony_ci;CHECK: [[null_v2float:%\w+]] = OpConstantNull %v2float
3892fd4e5da5Sopenharmony_ci;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
3893fd4e5da5Sopenharmony_ci)" + kImportStub + R"(
3894fd4e5da5Sopenharmony_ci%MainPs = OpFunction %void None %3
3895fd4e5da5Sopenharmony_ci%5 = OpLabel
3896fd4e5da5Sopenharmony_ci%66 = OpLoad %v2float %i_vTextureCoords
3897fd4e5da5Sopenharmony_ci%79 = OpAccessChain %_ptr_PushConstant_uint %__0 %int_0
3898fd4e5da5Sopenharmony_ci%80 = OpLoad %uint %79
3899fd4e5da5Sopenharmony_ci%81 = OpAccessChain %_ptr_Uniform_v2float %_ %int_0 %80 %int_2
3900fd4e5da5Sopenharmony_ci%82 = OpLoad %v2float %81
3901fd4e5da5Sopenharmony_ci%86 = OpFAdd %v2float %66 %82
3902fd4e5da5Sopenharmony_ci;CHECK-NOT: %82 = OpLoad %v2float %81
3903fd4e5da5Sopenharmony_ci;CHECK-NOT: %86 = OpFAdd %v2float %66 %82
3904fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpIMul %uint %uint_80 %80
3905fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpIAdd %uint %uint_0 {{%\w+}}
3906fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_64
3907fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_7
3908fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord
3909fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}}
3910fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
3911fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
3912fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0
3913fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_79 {{%\w+}} %uint_0 %uint_2 %uint_0 {{%\w+}}
3914fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
3915fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
3916fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3917fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v2float %81
3918fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
3919fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3920fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
3921fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3922fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpPhi %v2float {{%\w+}} {{%\w+}} [[null_v2float]] {{%\w+}}
3923fd4e5da5Sopenharmony_ci;CHECK: %86 = OpFAdd %v2float %66 {{%\w+}}
3924fd4e5da5Sopenharmony_ci%87 = OpLoad %46 %g_tColor
3925fd4e5da5Sopenharmony_ci%88 = OpLoad %50 %g_sAniso
3926fd4e5da5Sopenharmony_ci%89 = OpSampledImage %54 %87 %88
3927fd4e5da5Sopenharmony_ci%91 = OpImageSampleImplicitLod %v4float %89 %86
3928fd4e5da5Sopenharmony_ciOpStore %_entryPointOutput_vColor %91
3929fd4e5da5Sopenharmony_ci;CHECK-NOT: %91 = OpImageSampleImplicitLod %v4float %89 %86
3930fd4e5da5Sopenharmony_ci;CHECK-NOT:       OpStore %_entryPointOutput_vColor %91
3931fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord
3932fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}}
3933fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
3934fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
3935fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0
3936fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_84 {{%\w+}} %uint_0 %uint_0 %uint_0 %uint_0
3937fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
3938fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
3939fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3940fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %46 %g_tColor
3941fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpSampledImage %54 {{%\w+}} %88
3942fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpImageSampleImplicitLod %v4float {{%\w+}} %86
3943fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
3944fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3945fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
3946fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
3947fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}}
3948fd4e5da5Sopenharmony_ci;CHECK: OpStore %_entryPointOutput_vColor {{%\w+}}
3949fd4e5da5Sopenharmony_ciOpReturn
3950fd4e5da5Sopenharmony_ciOpFunctionEnd
3951fd4e5da5Sopenharmony_ci)";
3952fd4e5da5Sopenharmony_ci  // clang-format on
3953fd4e5da5Sopenharmony_ci
3954fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
3955fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
3956fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 23u);
3957fd4e5da5Sopenharmony_ci}
3958fd4e5da5Sopenharmony_ci
3959fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest, Descriptor16BitIdxRef) {
3960fd4e5da5Sopenharmony_ci  // Check that descriptor indexed with 16bit index is inbounds and
3961fd4e5da5Sopenharmony_ci  // initialized
3962fd4e5da5Sopenharmony_ci  //
3963fd4e5da5Sopenharmony_ci  // Use Simple source with min16uint g_nDataIdx
3964fd4e5da5Sopenharmony_ci
3965fd4e5da5Sopenharmony_ci  // clang-format off
3966fd4e5da5Sopenharmony_ci  const std::string text = R"(
3967fd4e5da5Sopenharmony_ciOpCapability Shader
3968fd4e5da5Sopenharmony_ciOpCapability Int16
3969fd4e5da5Sopenharmony_ciOpCapability StoragePushConstant16
3970fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
3971fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
3972fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
3973fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %MainPs "MainPs" %g_tColor %_ %g_sAniso %i_vTextureCoords %_entryPointOutput_vColor
3974fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint Fragment %MainPs "MainPs" %g_tColor %_ %g_sAniso %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
3975fd4e5da5Sopenharmony_ciOpExecutionMode %MainPs OriginUpperLeft
3976fd4e5da5Sopenharmony_ciOpSource HLSL 500
3977fd4e5da5Sopenharmony_ciOpName %MainPs "MainPs"
3978fd4e5da5Sopenharmony_ciOpName %g_tColor "g_tColor"
3979fd4e5da5Sopenharmony_ciOpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
3980fd4e5da5Sopenharmony_ciOpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
3981fd4e5da5Sopenharmony_ciOpName %_ ""
3982fd4e5da5Sopenharmony_ciOpName %g_sAniso "g_sAniso"
3983fd4e5da5Sopenharmony_ciOpName %i_vTextureCoords "i.vTextureCoords"
3984fd4e5da5Sopenharmony_ciOpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
3985fd4e5da5Sopenharmony_ciOpDecorate %g_tColor DescriptorSet 1
3986fd4e5da5Sopenharmony_ciOpDecorate %g_tColor Binding 2
3987fd4e5da5Sopenharmony_ciOpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
3988fd4e5da5Sopenharmony_ciOpDecorate %PerViewConstantBuffer_t Block
3989fd4e5da5Sopenharmony_ciOpDecorate %g_sAniso DescriptorSet 1
3990fd4e5da5Sopenharmony_ciOpDecorate %g_sAniso Binding 2
3991fd4e5da5Sopenharmony_ciOpDecorate %i_vTextureCoords Location 0
3992fd4e5da5Sopenharmony_ciOpDecorate %_entryPointOutput_vColor Location 0
3993fd4e5da5Sopenharmony_ci)" + kImportDeco + R"(
3994fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
3995fd4e5da5Sopenharmony_ci%void = OpTypeVoid
3996fd4e5da5Sopenharmony_ci%10 = OpTypeFunction %void
3997fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
3998fd4e5da5Sopenharmony_ci%v2float = OpTypeVector %float 2
3999fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
4000fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
4001fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
4002fd4e5da5Sopenharmony_ci%16 = OpTypeImage %float 2D 0 0 0 1 Unknown
4003fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
4004fd4e5da5Sopenharmony_ci%uint_128 = OpConstant %uint 128
4005fd4e5da5Sopenharmony_ci%_arr_16_uint_128 = OpTypeArray %16 %uint_128
4006fd4e5da5Sopenharmony_ci%_ptr_UniformConstant__arr_16_uint_128 = OpTypePointer UniformConstant %_arr_16_uint_128
4007fd4e5da5Sopenharmony_ci%g_tColor = OpVariable %_ptr_UniformConstant__arr_16_uint_128 UniformConstant
4008fd4e5da5Sopenharmony_ci%ushort = OpTypeInt 16 0
4009fd4e5da5Sopenharmony_ci%PerViewConstantBuffer_t = OpTypeStruct %ushort
4010fd4e5da5Sopenharmony_ci%_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
4011fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
4012fd4e5da5Sopenharmony_ci%_ptr_PushConstant_ushort = OpTypePointer PushConstant %ushort
4013fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_16 = OpTypePointer UniformConstant %16
4014fd4e5da5Sopenharmony_ci%25 = OpTypeSampler
4015fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_25 = OpTypePointer UniformConstant %25
4016fd4e5da5Sopenharmony_ci%g_sAniso = OpVariable %_ptr_UniformConstant_25 UniformConstant
4017fd4e5da5Sopenharmony_ci%27 = OpTypeSampledImage %16
4018fd4e5da5Sopenharmony_ci%_ptr_Input_v2float = OpTypePointer Input %v2float
4019fd4e5da5Sopenharmony_ci%i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
4020fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
4021fd4e5da5Sopenharmony_ci%_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
4022fd4e5da5Sopenharmony_ci;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
4023fd4e5da5Sopenharmony_ci;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
4024fd4e5da5Sopenharmony_ci;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
4025fd4e5da5Sopenharmony_ci)" + kImportStub + R"(
4026fd4e5da5Sopenharmony_ci%MainPs = OpFunction %void None %10
4027fd4e5da5Sopenharmony_ci%30 = OpLabel
4028fd4e5da5Sopenharmony_ci;CHECK:  OpBranch %39
4029fd4e5da5Sopenharmony_ci;CHECK:  %39 = OpLabel
4030fd4e5da5Sopenharmony_ci%31 = OpLoad %v2float %i_vTextureCoords
4031fd4e5da5Sopenharmony_ci%32 = OpAccessChain %_ptr_PushConstant_ushort %_ %int_0
4032fd4e5da5Sopenharmony_ci%33 = OpLoad %ushort %32
4033fd4e5da5Sopenharmony_ci%34 = OpAccessChain %_ptr_UniformConstant_16 %g_tColor %33
4034fd4e5da5Sopenharmony_ci%35 = OpLoad %16 %34
4035fd4e5da5Sopenharmony_ci%36 = OpLoad %25 %g_sAniso
4036fd4e5da5Sopenharmony_ci%37 = OpSampledImage %27 %35 %36
4037fd4e5da5Sopenharmony_ci%38 = OpImageSampleImplicitLod %v4float %37 %31
4038fd4e5da5Sopenharmony_ciOpStore %_entryPointOutput_vColor %38
4039fd4e5da5Sopenharmony_ci;CHECK-NOT: %38 = OpImageSampleImplicitLod %v4float %37 %31
4040fd4e5da5Sopenharmony_ci;CHECK-NOT: OpStore %_entryPointOutput_vColor %38
4041fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord
4042fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}}
4043fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
4044fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
4045fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0
4046fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpUConvert %uint %33
4047fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_61 {{%\w+}} %uint_1 %uint_2 {{%\w+}} %uint_0
4048fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
4049fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
4050fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
4051fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %16 %34
4052fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpSampledImage %27 {{%\w+}} %36
4053fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpImageSampleImplicitLod %v4float {{%\w+}} %31
4054fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
4055fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
4056fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
4057fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
4058fd4e5da5Sopenharmony_ci;CHECK: [[phi_result:%\w+]] = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}}
4059fd4e5da5Sopenharmony_ci;CHECK: OpStore %_entryPointOutput_vColor [[phi_result]]
4060fd4e5da5Sopenharmony_ciOpReturn
4061fd4e5da5Sopenharmony_ciOpFunctionEnd
4062fd4e5da5Sopenharmony_ci)";
4063fd4e5da5Sopenharmony_ci  // clang-format on
4064fd4e5da5Sopenharmony_ci
4065fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
4066fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
4067fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 23u);
4068fd4e5da5Sopenharmony_ci}
4069fd4e5da5Sopenharmony_ci
4070fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest, UniformArray16bitIdxRef) {
4071fd4e5da5Sopenharmony_ci  // Check that uniform array ref with 16bit index does not go out-of-bounds.
4072fd4e5da5Sopenharmony_ci  //
4073fd4e5da5Sopenharmony_ci  // Texture2D g_tColor;
4074fd4e5da5Sopenharmony_ci  // SamplerState g_sAniso;
4075fd4e5da5Sopenharmony_ci  //
4076fd4e5da5Sopenharmony_ci  // layout(push_constant) cbuffer PerViewPushConst_t { min16uint g_c; };
4077fd4e5da5Sopenharmony_ci  //
4078fd4e5da5Sopenharmony_ci  // struct PerBatchEnvMapConstantBuffer_t {
4079fd4e5da5Sopenharmony_ci  //   float4x3 g_matEnvMapWorldToLocal;
4080fd4e5da5Sopenharmony_ci  //   float4 g_vEnvironmentMapBoxMins;
4081fd4e5da5Sopenharmony_ci  //   float2 g_TexOff;
4082fd4e5da5Sopenharmony_ci  // };
4083fd4e5da5Sopenharmony_ci  //
4084fd4e5da5Sopenharmony_ci  // cbuffer _BindlessFastEnvMapCB_PS_t {
4085fd4e5da5Sopenharmony_ci  //   PerBatchEnvMapConstantBuffer_t g_envMapConstants[128];
4086fd4e5da5Sopenharmony_ci  // };
4087fd4e5da5Sopenharmony_ci  //
4088fd4e5da5Sopenharmony_ci  // struct PS_INPUT {
4089fd4e5da5Sopenharmony_ci  //   float2 vTextureCoords : TEXCOORD2;
4090fd4e5da5Sopenharmony_ci  // };
4091fd4e5da5Sopenharmony_ci  //
4092fd4e5da5Sopenharmony_ci  // struct PS_OUTPUT {
4093fd4e5da5Sopenharmony_ci  //   float4 vColor : SV_Target0;
4094fd4e5da5Sopenharmony_ci  // };
4095fd4e5da5Sopenharmony_ci  //
4096fd4e5da5Sopenharmony_ci  // PS_OUTPUT MainPs(PS_INPUT i) {
4097fd4e5da5Sopenharmony_ci  //   PS_OUTPUT ps_output;
4098fd4e5da5Sopenharmony_ci  //   float2 off;
4099fd4e5da5Sopenharmony_ci  //   float2 vtc;
4100fd4e5da5Sopenharmony_ci  //   off = g_envMapConstants[g_c].g_TexOff;
4101fd4e5da5Sopenharmony_ci  //   vtc = i.vTextureCoords.xy + off;
4102fd4e5da5Sopenharmony_ci  //   ps_output.vColor = g_tColor.Sample(g_sAniso, vtc);
4103fd4e5da5Sopenharmony_ci  //   return ps_output;
4104fd4e5da5Sopenharmony_ci  // }
4105fd4e5da5Sopenharmony_ci
4106fd4e5da5Sopenharmony_ci  // clang-format off
4107fd4e5da5Sopenharmony_ci  const std::string text = R"(
4108fd4e5da5Sopenharmony_ciOpCapability Shader
4109fd4e5da5Sopenharmony_ciOpCapability Int16
4110fd4e5da5Sopenharmony_ciOpCapability StoragePushConstant16
4111fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
4112fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
4113fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
4114fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %MainPs "MainPs" %_ %__0 %g_tColor %g_sAniso %i_vTextureCoords %_entryPointOutput_vColor
4115fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint Fragment %MainPs "MainPs" %_ %__0 %g_tColor %g_sAniso %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
4116fd4e5da5Sopenharmony_ciOpExecutionMode %MainPs OriginUpperLeft
4117fd4e5da5Sopenharmony_ciOpSource HLSL 500
4118fd4e5da5Sopenharmony_ciOpName %MainPs "MainPs"
4119fd4e5da5Sopenharmony_ciOpName %PerBatchEnvMapConstantBuffer_t "PerBatchEnvMapConstantBuffer_t"
4120fd4e5da5Sopenharmony_ciOpMemberName %PerBatchEnvMapConstantBuffer_t 0 "g_matEnvMapWorldToLocal"
4121fd4e5da5Sopenharmony_ciOpMemberName %PerBatchEnvMapConstantBuffer_t 1 "g_vEnvironmentMapBoxMins"
4122fd4e5da5Sopenharmony_ciOpMemberName %PerBatchEnvMapConstantBuffer_t 2 "g_TexOff"
4123fd4e5da5Sopenharmony_ciOpName %_BindlessFastEnvMapCB_PS_t "_BindlessFastEnvMapCB_PS_t"
4124fd4e5da5Sopenharmony_ciOpMemberName %_BindlessFastEnvMapCB_PS_t 0 "g_envMapConstants"
4125fd4e5da5Sopenharmony_ciOpName %_ ""
4126fd4e5da5Sopenharmony_ciOpName %PerViewPushConst_t "PerViewPushConst_t"
4127fd4e5da5Sopenharmony_ciOpMemberName %PerViewPushConst_t 0 "g_c"
4128fd4e5da5Sopenharmony_ciOpName %__0 ""
4129fd4e5da5Sopenharmony_ciOpName %g_tColor "g_tColor"
4130fd4e5da5Sopenharmony_ciOpName %g_sAniso "g_sAniso"
4131fd4e5da5Sopenharmony_ciOpName %i_vTextureCoords "i.vTextureCoords"
4132fd4e5da5Sopenharmony_ciOpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
4133fd4e5da5Sopenharmony_ciOpMemberDecorate %PerBatchEnvMapConstantBuffer_t 0 RowMajor
4134fd4e5da5Sopenharmony_ciOpMemberDecorate %PerBatchEnvMapConstantBuffer_t 0 Offset 0
4135fd4e5da5Sopenharmony_ciOpMemberDecorate %PerBatchEnvMapConstantBuffer_t 0 MatrixStride 16
4136fd4e5da5Sopenharmony_ciOpMemberDecorate %PerBatchEnvMapConstantBuffer_t 1 Offset 48
4137fd4e5da5Sopenharmony_ciOpMemberDecorate %PerBatchEnvMapConstantBuffer_t 2 Offset 64
4138fd4e5da5Sopenharmony_ciOpDecorate %_arr_PerBatchEnvMapConstantBuffer_t_uint_128 ArrayStride 80
4139fd4e5da5Sopenharmony_ciOpMemberDecorate %_BindlessFastEnvMapCB_PS_t 0 Offset 0
4140fd4e5da5Sopenharmony_ciOpDecorate %_BindlessFastEnvMapCB_PS_t Block
4141fd4e5da5Sopenharmony_ciOpDecorate %_ DescriptorSet 0
4142fd4e5da5Sopenharmony_ciOpDecorate %_ Binding 0
4143fd4e5da5Sopenharmony_ciOpMemberDecorate %PerViewPushConst_t 0 Offset 0
4144fd4e5da5Sopenharmony_ciOpDecorate %PerViewPushConst_t Block
4145fd4e5da5Sopenharmony_ciOpDecorate %g_tColor DescriptorSet 0
4146fd4e5da5Sopenharmony_ciOpDecorate %g_tColor Binding 0
4147fd4e5da5Sopenharmony_ciOpDecorate %g_sAniso DescriptorSet 0
4148fd4e5da5Sopenharmony_ciOpDecorate %g_sAniso Binding 0
4149fd4e5da5Sopenharmony_ciOpDecorate %i_vTextureCoords Location 0
4150fd4e5da5Sopenharmony_ciOpDecorate %_entryPointOutput_vColor Location 0
4151fd4e5da5Sopenharmony_ci)" + kImportDeco + R"(
4152fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
4153fd4e5da5Sopenharmony_ci%void = OpTypeVoid
4154fd4e5da5Sopenharmony_ci%14 = OpTypeFunction %void
4155fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
4156fd4e5da5Sopenharmony_ci%v2float = OpTypeVector %float 2
4157fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
4158fd4e5da5Sopenharmony_ci%v3float = OpTypeVector %float 3
4159fd4e5da5Sopenharmony_ci%mat4v3float = OpTypeMatrix %v3float 4
4160fd4e5da5Sopenharmony_ci%PerBatchEnvMapConstantBuffer_t = OpTypeStruct %mat4v3float %v4float %v2float
4161fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
4162fd4e5da5Sopenharmony_ci%uint_128 = OpConstant %uint 128
4163fd4e5da5Sopenharmony_ci%_arr_PerBatchEnvMapConstantBuffer_t_uint_128 = OpTypeArray %PerBatchEnvMapConstantBuffer_t %uint_128
4164fd4e5da5Sopenharmony_ci%_BindlessFastEnvMapCB_PS_t = OpTypeStruct %_arr_PerBatchEnvMapConstantBuffer_t_uint_128
4165fd4e5da5Sopenharmony_ci%_ptr_Uniform__BindlessFastEnvMapCB_PS_t = OpTypePointer Uniform %_BindlessFastEnvMapCB_PS_t
4166fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_Uniform__BindlessFastEnvMapCB_PS_t Uniform
4167fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
4168fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
4169fd4e5da5Sopenharmony_ci%ushort = OpTypeInt 16 0
4170fd4e5da5Sopenharmony_ci%PerViewPushConst_t = OpTypeStruct %ushort
4171fd4e5da5Sopenharmony_ci%_ptr_PushConstant_PerViewPushConst_t = OpTypePointer PushConstant %PerViewPushConst_t
4172fd4e5da5Sopenharmony_ci%__0 = OpVariable %_ptr_PushConstant_PerViewPushConst_t PushConstant
4173fd4e5da5Sopenharmony_ci%_ptr_PushConstant_ushort = OpTypePointer PushConstant %ushort
4174fd4e5da5Sopenharmony_ci%int_2 = OpConstant %int 2
4175fd4e5da5Sopenharmony_ci%_ptr_Uniform_v2float = OpTypePointer Uniform %v2float
4176fd4e5da5Sopenharmony_ci%30 = OpTypeImage %float 2D 0 0 0 1 Unknown
4177fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_30 = OpTypePointer UniformConstant %30
4178fd4e5da5Sopenharmony_ci%g_tColor = OpVariable %_ptr_UniformConstant_30 UniformConstant
4179fd4e5da5Sopenharmony_ci%32 = OpTypeSampler
4180fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_32 = OpTypePointer UniformConstant %32
4181fd4e5da5Sopenharmony_ci%g_sAniso = OpVariable %_ptr_UniformConstant_32 UniformConstant
4182fd4e5da5Sopenharmony_ci%34 = OpTypeSampledImage %30
4183fd4e5da5Sopenharmony_ci%_ptr_Input_v2float = OpTypePointer Input %v2float
4184fd4e5da5Sopenharmony_ci%i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
4185fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
4186fd4e5da5Sopenharmony_ci%_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
4187fd4e5da5Sopenharmony_ci;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
4188fd4e5da5Sopenharmony_ci;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
4189fd4e5da5Sopenharmony_ci;CHECK: [[null_v2float:%\w+]] = OpConstantNull %v2float
4190fd4e5da5Sopenharmony_ci)" + kImportStub + R"(
4191fd4e5da5Sopenharmony_ci%MainPs = OpFunction %void None %14
4192fd4e5da5Sopenharmony_ci%37 = OpLabel
4193fd4e5da5Sopenharmony_ci%38 = OpLoad %v2float %i_vTextureCoords
4194fd4e5da5Sopenharmony_ci%39 = OpAccessChain %_ptr_PushConstant_ushort %__0 %int_0
4195fd4e5da5Sopenharmony_ci%40 = OpLoad %ushort %39
4196fd4e5da5Sopenharmony_ci%41 = OpAccessChain %_ptr_Uniform_v2float %_ %int_0 %40 %int_2
4197fd4e5da5Sopenharmony_ci%42 = OpLoad %v2float %41
4198fd4e5da5Sopenharmony_ci%43 = OpFAdd %v2float %38 %42
4199fd4e5da5Sopenharmony_ci;CHECK-NOT: %42 = OpLoad %v2float %41
4200fd4e5da5Sopenharmony_ci;CHECK-NOT: %43 = OpFAdd %v2float %38 %42
4201fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpUConvert %uint %40
4202fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpIMul %uint %uint_80 {{%\w+}}
4203fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpIAdd %uint %uint_0 {{%\w+}}
4204fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_64
4205fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_7
4206fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord
4207fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}}
4208fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
4209fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
4210fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0
4211fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_82 {{%\w+}} %uint_0 %uint_0 %uint_0 {{%\w+}}
4212fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
4213fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
4214fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
4215fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v2float %41
4216fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
4217fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
4218fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
4219fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
4220fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpPhi %v2float {{%\w+}} {{%\w+}} [[null_v2float]] {{%\w+}}
4221fd4e5da5Sopenharmony_ci;CHECK: %43 = OpFAdd %v2float %38 {{%\w+}}
4222fd4e5da5Sopenharmony_ci%44 = OpLoad %30 %g_tColor
4223fd4e5da5Sopenharmony_ci%45 = OpLoad %32 %g_sAniso
4224fd4e5da5Sopenharmony_ci%46 = OpSampledImage %34 %44 %45
4225fd4e5da5Sopenharmony_ci%47 = OpImageSampleImplicitLod %v4float %46 %43
4226fd4e5da5Sopenharmony_ciOpStore %_entryPointOutput_vColor %47
4227fd4e5da5Sopenharmony_ciOpReturn
4228fd4e5da5Sopenharmony_ciOpFunctionEnd
4229fd4e5da5Sopenharmony_ci)";
4230fd4e5da5Sopenharmony_ci  // clang-format on
4231fd4e5da5Sopenharmony_ci
4232fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
4233fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
4234fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 23u);
4235fd4e5da5Sopenharmony_ci}
4236fd4e5da5Sopenharmony_ci
4237fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest, UniformMatrixRefRowMajor) {
4238fd4e5da5Sopenharmony_ci  // The buffer-oob row major matrix check
4239fd4e5da5Sopenharmony_ci  //
4240fd4e5da5Sopenharmony_ci  // #version 450
4241fd4e5da5Sopenharmony_ci  // #extension GL_EXT_scalar_block_layout : enable
4242fd4e5da5Sopenharmony_ci  //
4243fd4e5da5Sopenharmony_ci  // layout(location = 0) in highp vec4 a_position;
4244fd4e5da5Sopenharmony_ci  // layout(location = 0) out mediump float v_vtxResult;
4245fd4e5da5Sopenharmony_ci  //
4246fd4e5da5Sopenharmony_ci  // layout(set = 0, binding = 0, std430, row_major) uniform Block
4247fd4e5da5Sopenharmony_ci  // {
4248fd4e5da5Sopenharmony_ci  //    lowp mat4x2 var;
4249fd4e5da5Sopenharmony_ci  // };
4250fd4e5da5Sopenharmony_ci  //
4251fd4e5da5Sopenharmony_ci  // void main (void)
4252fd4e5da5Sopenharmony_ci  // {
4253fd4e5da5Sopenharmony_ci  //    v_vtxResult = var[2][1];
4254fd4e5da5Sopenharmony_ci  // }
4255fd4e5da5Sopenharmony_ci
4256fd4e5da5Sopenharmony_ci  // clang-format off
4257fd4e5da5Sopenharmony_ci  std::string text = R"(
4258fd4e5da5Sopenharmony_ciOpCapability Shader
4259fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
4260fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
4261fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
4262fd4e5da5Sopenharmony_ciOpEntryPoint Vertex %main "main" %v_vtxResult %_ %a_position
4263fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint Vertex %main "main" %v_vtxResult %_ %a_position %gl_VertexIndex %gl_InstanceIndex
4264fd4e5da5Sopenharmony_ciOpSource GLSL 450
4265fd4e5da5Sopenharmony_ciOpSourceExtension "GL_EXT_scalar_block_layout"
4266fd4e5da5Sopenharmony_ciOpName %main "main"
4267fd4e5da5Sopenharmony_ciOpName %v_vtxResult "v_vtxResult"
4268fd4e5da5Sopenharmony_ciOpName %Block "Block"
4269fd4e5da5Sopenharmony_ciOpMemberName %Block 0 "var"
4270fd4e5da5Sopenharmony_ciOpName %_ ""
4271fd4e5da5Sopenharmony_ciOpName %a_position "a_position"
4272fd4e5da5Sopenharmony_ciOpDecorate %v_vtxResult RelaxedPrecision
4273fd4e5da5Sopenharmony_ciOpDecorate %v_vtxResult Location 0
4274fd4e5da5Sopenharmony_ciOpMemberDecorate %Block 0 RowMajor
4275fd4e5da5Sopenharmony_ciOpMemberDecorate %Block 0 RelaxedPrecision
4276fd4e5da5Sopenharmony_ciOpMemberDecorate %Block 0 Offset 0
4277fd4e5da5Sopenharmony_ciOpMemberDecorate %Block 0 MatrixStride 16
4278fd4e5da5Sopenharmony_ciOpDecorate %Block Block
4279fd4e5da5Sopenharmony_ciOpDecorate %_ DescriptorSet 0
4280fd4e5da5Sopenharmony_ciOpDecorate %_ Binding 0
4281fd4e5da5Sopenharmony_ciOpDecorate %21 RelaxedPrecision
4282fd4e5da5Sopenharmony_ci;CHECK-NOT: OpDecorate %21 RelaxedPrecision
4283fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %v_vtxResult RelaxedPrecision
4284fd4e5da5Sopenharmony_ci;CHECK: OpDecorate [[phi_result:%\w+]] RelaxedPrecision
4285fd4e5da5Sopenharmony_ciOpDecorate %a_position Location 0
4286fd4e5da5Sopenharmony_ci)" + kImportDeco + R"(
4287fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %gl_VertexIndex BuiltIn VertexIndex
4288fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %gl_InstanceIndex BuiltIn InstanceIndex
4289fd4e5da5Sopenharmony_ci;CHECK: OpDecorate [[load_result:%\w+]] RelaxedPrecision
4290fd4e5da5Sopenharmony_ci%void = OpTypeVoid
4291fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
4292fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
4293fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
4294fd4e5da5Sopenharmony_ci%v_vtxResult = OpVariable %_ptr_Output_float Output
4295fd4e5da5Sopenharmony_ci%v2float = OpTypeVector %float 2
4296fd4e5da5Sopenharmony_ci%mat4v2float = OpTypeMatrix %v2float 4
4297fd4e5da5Sopenharmony_ci%Block = OpTypeStruct %mat4v2float
4298fd4e5da5Sopenharmony_ci%_ptr_Uniform_Block = OpTypePointer Uniform %Block
4299fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_Uniform_Block Uniform
4300fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
4301fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
4302fd4e5da5Sopenharmony_ci%int_2 = OpConstant %int 2
4303fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
4304fd4e5da5Sopenharmony_ci%uint_1 = OpConstant %uint 1
4305fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float
4306fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
4307fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
4308fd4e5da5Sopenharmony_ci%a_position = OpVariable %_ptr_Input_v4float Input
4309fd4e5da5Sopenharmony_ci;CHECK: %_ptr_Input_uint = OpTypePointer Input %uint
4310fd4e5da5Sopenharmony_ci;CHECK: %gl_VertexIndex = OpVariable %_ptr_Input_uint Input
4311fd4e5da5Sopenharmony_ci;CHECK: %gl_InstanceIndex = OpVariable %_ptr_Input_uint Input
4312fd4e5da5Sopenharmony_ci;CHECK: [[null_float:%\w+]] = OpConstantNull %float
4313fd4e5da5Sopenharmony_ci)" + kImportStub + R"(
4314fd4e5da5Sopenharmony_ci%main = OpFunction %void None %3
4315fd4e5da5Sopenharmony_ci%5 = OpLabel
4316fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
4317fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
4318fd4e5da5Sopenharmony_ci%20 = OpAccessChain %_ptr_Uniform_float %_ %int_0 %int_2 %uint_1
4319fd4e5da5Sopenharmony_ci%21 = OpLoad %float %20
4320fd4e5da5Sopenharmony_ci;CHECK-NOT: %21 = OpLoad %float %20
4321fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpIMul %uint %uint_4 %int_2
4322fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpIAdd %uint %uint_0 {{%\w+}}
4323fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpIMul %uint %uint_16 %uint_1
4324fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} {{%\w+}}
4325fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_3
4326fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %uint %gl_VertexIndex
4327fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %uint %gl_InstanceIndex
4328fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_0 {{%\w+}} {{%\w+}} %uint_0
4329fd4e5da5Sopenharmony_ci;CHECK: [[desc_state:%\w+]] = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_46 {{%\w+}} %uint_0 %uint_0 %uint_0 {{%\w+}}
4330fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
4331fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional [[desc_state]] {{%\w+}} {{%\w+}}
4332fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
4333fd4e5da5Sopenharmony_ci;CHECK: [[load_result]] = OpLoad %float %20
4334fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
4335fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
4336fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
4337fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
4338fd4e5da5Sopenharmony_ci;CHECK: [[phi_result]] = OpPhi %float [[load_result]] {{%\w+}} [[null_float]] {{%\w+}}
4339fd4e5da5Sopenharmony_ciOpStore %v_vtxResult %21
4340fd4e5da5Sopenharmony_ci;CHECK-NOT: OpStore %v_vtxResult %21$
4341fd4e5da5Sopenharmony_ci;CHECK: OpStore %v_vtxResult [[phi_result]]
4342fd4e5da5Sopenharmony_ciOpReturn
4343fd4e5da5Sopenharmony_ciOpFunctionEnd
4344fd4e5da5Sopenharmony_ci)";
4345fd4e5da5Sopenharmony_ci  // clang-format on
4346fd4e5da5Sopenharmony_ci
4347fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
4348fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
4349fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 23u);
4350fd4e5da5Sopenharmony_ci}
4351fd4e5da5Sopenharmony_ci
4352fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest, UniformMatrixRefColumnMajor) {
4353fd4e5da5Sopenharmony_ci  // The buffer-oob column major matrix check
4354fd4e5da5Sopenharmony_ci  //
4355fd4e5da5Sopenharmony_ci  // #version 450
4356fd4e5da5Sopenharmony_ci  // #extension GL_EXT_scalar_block_layout : enable
4357fd4e5da5Sopenharmony_ci  //
4358fd4e5da5Sopenharmony_ci  // layout(location = 0) in highp vec4 a_position;
4359fd4e5da5Sopenharmony_ci  // layout(location = 0) out mediump float v_vtxResult;
4360fd4e5da5Sopenharmony_ci  //
4361fd4e5da5Sopenharmony_ci  // layout(set = 0, binding = 0, std430, column_major) uniform Block
4362fd4e5da5Sopenharmony_ci  // {
4363fd4e5da5Sopenharmony_ci  //    lowp mat4x2 var;
4364fd4e5da5Sopenharmony_ci  // };
4365fd4e5da5Sopenharmony_ci  //
4366fd4e5da5Sopenharmony_ci  // void main (void)
4367fd4e5da5Sopenharmony_ci  // {
4368fd4e5da5Sopenharmony_ci  //    v_vtxResult = var[2][1];
4369fd4e5da5Sopenharmony_ci  // }
4370fd4e5da5Sopenharmony_ci
4371fd4e5da5Sopenharmony_ci  // clang-format off
4372fd4e5da5Sopenharmony_ci  const std::string text = R"(
4373fd4e5da5Sopenharmony_ciOpCapability Shader
4374fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
4375fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
4376fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
4377fd4e5da5Sopenharmony_ciOpEntryPoint Vertex %main "main" %v_vtxResult %_ %a_position
4378fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint Vertex %main "main" %v_vtxResult %_ %a_position %gl_VertexIndex %gl_InstanceIndex
4379fd4e5da5Sopenharmony_ciOpSource GLSL 450
4380fd4e5da5Sopenharmony_ciOpSourceExtension "GL_EXT_scalar_block_layout"
4381fd4e5da5Sopenharmony_ciOpName %main "main"
4382fd4e5da5Sopenharmony_ciOpName %v_vtxResult "v_vtxResult"
4383fd4e5da5Sopenharmony_ciOpName %Block "Block"
4384fd4e5da5Sopenharmony_ciOpMemberName %Block 0 "var"
4385fd4e5da5Sopenharmony_ciOpName %_ ""
4386fd4e5da5Sopenharmony_ciOpName %a_position "a_position"
4387fd4e5da5Sopenharmony_ciOpDecorate %v_vtxResult RelaxedPrecision
4388fd4e5da5Sopenharmony_ciOpDecorate %v_vtxResult Location 0
4389fd4e5da5Sopenharmony_ciOpMemberDecorate %Block 0 ColMajor
4390fd4e5da5Sopenharmony_ciOpMemberDecorate %Block 0 RelaxedPrecision
4391fd4e5da5Sopenharmony_ciOpMemberDecorate %Block 0 Offset 0
4392fd4e5da5Sopenharmony_ciOpMemberDecorate %Block 0 MatrixStride 8
4393fd4e5da5Sopenharmony_ciOpDecorate %Block Block
4394fd4e5da5Sopenharmony_ciOpDecorate %_ DescriptorSet 0
4395fd4e5da5Sopenharmony_ciOpDecorate %_ Binding 0
4396fd4e5da5Sopenharmony_ciOpDecorate %21 RelaxedPrecision
4397fd4e5da5Sopenharmony_ci;CHECK-NOT: OpDecorate %21 RelaxedPrecision
4398fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %v_vtxResult RelaxedPrecision
4399fd4e5da5Sopenharmony_ci;CHECK: OpDecorate [[phi_result:%\w+]] RelaxedPrecision
4400fd4e5da5Sopenharmony_ciOpDecorate %a_position Location 0
4401fd4e5da5Sopenharmony_ci)" + kImportDeco + R"(
4402fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %gl_VertexIndex BuiltIn VertexIndex
4403fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %gl_InstanceIndex BuiltIn InstanceIndex
4404fd4e5da5Sopenharmony_ci;CHECK: OpDecorate [[load_result:%\w+]] RelaxedPrecision
4405fd4e5da5Sopenharmony_ci%void = OpTypeVoid
4406fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
4407fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
4408fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
4409fd4e5da5Sopenharmony_ci%v_vtxResult = OpVariable %_ptr_Output_float Output
4410fd4e5da5Sopenharmony_ci%v2float = OpTypeVector %float 2
4411fd4e5da5Sopenharmony_ci%mat4v2float = OpTypeMatrix %v2float 4
4412fd4e5da5Sopenharmony_ci%Block = OpTypeStruct %mat4v2float
4413fd4e5da5Sopenharmony_ci%_ptr_Uniform_Block = OpTypePointer Uniform %Block
4414fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_Uniform_Block Uniform
4415fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
4416fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
4417fd4e5da5Sopenharmony_ci%int_2 = OpConstant %int 2
4418fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
4419fd4e5da5Sopenharmony_ci%uint_1 = OpConstant %uint 1
4420fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float
4421fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
4422fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
4423fd4e5da5Sopenharmony_ci%a_position = OpVariable %_ptr_Input_v4float Input
4424fd4e5da5Sopenharmony_ci;CHECK: %_ptr_Input_uint = OpTypePointer Input %uint
4425fd4e5da5Sopenharmony_ci;CHECK: %gl_VertexIndex = OpVariable %_ptr_Input_uint Input
4426fd4e5da5Sopenharmony_ci;CHECK: %gl_InstanceIndex = OpVariable %_ptr_Input_uint Input
4427fd4e5da5Sopenharmony_ci;CHECK: [[null_float:%\w+]] = OpConstantNull %float
4428fd4e5da5Sopenharmony_ci)" + kImportStub + R"(
4429fd4e5da5Sopenharmony_ci%main = OpFunction %void None %3
4430fd4e5da5Sopenharmony_ci%5 = OpLabel
4431fd4e5da5Sopenharmony_ci%20 = OpAccessChain %_ptr_Uniform_float %_ %int_0 %int_2 %uint_1
4432fd4e5da5Sopenharmony_ci%21 = OpLoad %float %20
4433fd4e5da5Sopenharmony_ci;CHECK-NOT: %21 = OpLoad %float %20
4434fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
4435fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
4436fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpIMul %uint %uint_8 %int_2
4437fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpIAdd %uint %uint_0 {{%\w+}}
4438fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpIMul %uint %uint_4 %uint_1
4439fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} {{%\w+}}
4440fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_3
4441fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %uint %gl_VertexIndex
4442fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %uint %gl_InstanceIndex
4443fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_0 {{%\w+}} {{%\w+}} %uint_0
4444fd4e5da5Sopenharmony_ci;CHECK: [[desc_state:%\w+]] = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_46 {{%\w+}} %uint_0 %uint_0 %uint_0 {{%\w+}}
4445fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
4446fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional [[desc_state]] {{%\w+}} {{%\w+}}
4447fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
4448fd4e5da5Sopenharmony_ci;CHECK:[[load_result]] = OpLoad %float %20
4449fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
4450fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
4451fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
4452fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
4453fd4e5da5Sopenharmony_ci;CHECK: [[phi_result]] = OpPhi %float [[load_result]] {{%\w+}} [[null_float]] {{%\w+}}
4454fd4e5da5Sopenharmony_ciOpStore %v_vtxResult %21
4455fd4e5da5Sopenharmony_ci;CHECK-NOT: OpStore %v_vtxResult %21$
4456fd4e5da5Sopenharmony_ci;CHECK: OpStore %v_vtxResult [[phi_result]]
4457fd4e5da5Sopenharmony_ciOpReturn
4458fd4e5da5Sopenharmony_ciOpFunctionEnd
4459fd4e5da5Sopenharmony_ci)";
4460fd4e5da5Sopenharmony_ci  // clang-format on
4461fd4e5da5Sopenharmony_ci
4462fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
4463fd4e5da5Sopenharmony_ci  ValidatorOptions()->uniform_buffer_standard_layout = true;
4464fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
4465fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 23u);
4466fd4e5da5Sopenharmony_ci}
4467fd4e5da5Sopenharmony_ci
4468fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest, UniformMatrixVecRefRowMajor) {
4469fd4e5da5Sopenharmony_ci  // The buffer-oob row major matrix vector ref check
4470fd4e5da5Sopenharmony_ci  //
4471fd4e5da5Sopenharmony_ci  // #version 450
4472fd4e5da5Sopenharmony_ci  // #extension GL_EXT_scalar_block_layout : enable
4473fd4e5da5Sopenharmony_ci  //
4474fd4e5da5Sopenharmony_ci  // layout(location = 0) in highp vec4 a_position;
4475fd4e5da5Sopenharmony_ci  // layout(location = 0) out highp vec2 v_vtxResult;
4476fd4e5da5Sopenharmony_ci  //
4477fd4e5da5Sopenharmony_ci  // layout(set = 3, binding = 7, std430, row_major) uniform Block
4478fd4e5da5Sopenharmony_ci  // {
4479fd4e5da5Sopenharmony_ci  //    lowp mat2 var[3][4];
4480fd4e5da5Sopenharmony_ci  // };
4481fd4e5da5Sopenharmony_ci  //
4482fd4e5da5Sopenharmony_ci  // void main (void)
4483fd4e5da5Sopenharmony_ci  // {
4484fd4e5da5Sopenharmony_ci  //    v_vtxResult = var[2][3][1];
4485fd4e5da5Sopenharmony_ci  // }
4486fd4e5da5Sopenharmony_ci
4487fd4e5da5Sopenharmony_ci  // clang-format off
4488fd4e5da5Sopenharmony_ci  const std::string text = R"(
4489fd4e5da5Sopenharmony_ciOpCapability Shader
4490fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
4491fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
4492fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
4493fd4e5da5Sopenharmony_ciOpEntryPoint Vertex %main "main" %v_vtxResult %_ %a_position
4494fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint Vertex %main "main" %v_vtxResult %_ %a_position %gl_VertexIndex %gl_InstanceIndex
4495fd4e5da5Sopenharmony_ciOpSource GLSL 450
4496fd4e5da5Sopenharmony_ciOpSourceExtension "GL_EXT_scalar_block_layout"
4497fd4e5da5Sopenharmony_ciOpName %main "main"
4498fd4e5da5Sopenharmony_ciOpName %v_vtxResult "v_vtxResult"
4499fd4e5da5Sopenharmony_ciOpName %Block "Block"
4500fd4e5da5Sopenharmony_ciOpMemberName %Block 0 "var"
4501fd4e5da5Sopenharmony_ciOpName %_ ""
4502fd4e5da5Sopenharmony_ciOpName %a_position "a_position"
4503fd4e5da5Sopenharmony_ciOpDecorate %v_vtxResult Location 0
4504fd4e5da5Sopenharmony_ciOpDecorate %_arr_mat2v2float_uint_4 ArrayStride 32
4505fd4e5da5Sopenharmony_ciOpDecorate %_arr__arr_mat2v2float_uint_4_uint_3 ArrayStride 128
4506fd4e5da5Sopenharmony_ciOpMemberDecorate %Block 0 RowMajor
4507fd4e5da5Sopenharmony_ciOpMemberDecorate %Block 0 RelaxedPrecision
4508fd4e5da5Sopenharmony_ciOpMemberDecorate %Block 0 Offset 0
4509fd4e5da5Sopenharmony_ciOpMemberDecorate %Block 0 MatrixStride 16
4510fd4e5da5Sopenharmony_ciOpDecorate %Block Block
4511fd4e5da5Sopenharmony_ciOpDecorate %_ DescriptorSet 3
4512fd4e5da5Sopenharmony_ciOpDecorate %_ Binding 7
4513fd4e5da5Sopenharmony_ciOpDecorate %26 RelaxedPrecision
4514fd4e5da5Sopenharmony_ci;CHECK-NOT: OpDecorate %26 RelaxedPrecision
4515fd4e5da5Sopenharmony_ci;CHECK: OpDecorate [[phi_result:%\w+]] RelaxedPrecision
4516fd4e5da5Sopenharmony_ciOpDecorate %a_position Location 0
4517fd4e5da5Sopenharmony_ci)" + kImportDeco + R"(
4518fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %gl_VertexIndex BuiltIn VertexIndex
4519fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %gl_InstanceIndex BuiltIn InstanceIndex
4520fd4e5da5Sopenharmony_ci;CHECK: OpDecorate [[load_result:%\w+]] RelaxedPrecision
4521fd4e5da5Sopenharmony_ci%void = OpTypeVoid
4522fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
4523fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
4524fd4e5da5Sopenharmony_ci%v2float = OpTypeVector %float 2
4525fd4e5da5Sopenharmony_ci%_ptr_Output_v2float = OpTypePointer Output %v2float
4526fd4e5da5Sopenharmony_ci%v_vtxResult = OpVariable %_ptr_Output_v2float Output
4527fd4e5da5Sopenharmony_ci%mat2v2float = OpTypeMatrix %v2float 2
4528fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
4529fd4e5da5Sopenharmony_ci%uint_4 = OpConstant %uint 4
4530fd4e5da5Sopenharmony_ci%_arr_mat2v2float_uint_4 = OpTypeArray %mat2v2float %uint_4
4531fd4e5da5Sopenharmony_ci%uint_3 = OpConstant %uint 3
4532fd4e5da5Sopenharmony_ci%_arr__arr_mat2v2float_uint_4_uint_3 = OpTypeArray %_arr_mat2v2float_uint_4 %uint_3
4533fd4e5da5Sopenharmony_ci%Block = OpTypeStruct %_arr__arr_mat2v2float_uint_4_uint_3
4534fd4e5da5Sopenharmony_ci%_ptr_Uniform_Block = OpTypePointer Uniform %Block
4535fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_Uniform_Block Uniform
4536fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
4537fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
4538fd4e5da5Sopenharmony_ci%int_2 = OpConstant %int 2
4539fd4e5da5Sopenharmony_ci%int_3 = OpConstant %int 3
4540fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
4541fd4e5da5Sopenharmony_ci%_ptr_Uniform_v2float = OpTypePointer Uniform %v2float
4542fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
4543fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
4544fd4e5da5Sopenharmony_ci%a_position = OpVariable %_ptr_Input_v4float Input
4545fd4e5da5Sopenharmony_ci;CHECK: %_ptr_Input_uint = OpTypePointer Input %uint
4546fd4e5da5Sopenharmony_ci;CHECK: %gl_VertexIndex = OpVariable %_ptr_Input_uint Input
4547fd4e5da5Sopenharmony_ci;CHECK: %gl_InstanceIndex = OpVariable %_ptr_Input_uint Input
4548fd4e5da5Sopenharmony_ci;CHECK: [[null_v2float:%\w+]] = OpConstantNull %v2float
4549fd4e5da5Sopenharmony_ci)" + kImportStub + R"(
4550fd4e5da5Sopenharmony_ci%main = OpFunction %void None %3
4551fd4e5da5Sopenharmony_ci%5 = OpLabel
4552fd4e5da5Sopenharmony_ci%25 = OpAccessChain %_ptr_Uniform_v2float %_ %int_0 %int_2 %int_3 %int_1
4553fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpIMul %uint %uint_128 %int_2
4554fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpIAdd %uint %uint_0 {{%\w+}}
4555fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpIMul %uint %uint_32 %int_3
4556fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} {{%\w+}}
4557fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpIMul %uint %uint_4 %int_1
4558fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} {{%\w+}}
4559fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_19
4560fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %uint %gl_VertexIndex
4561fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %uint %gl_InstanceIndex
4562fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_0 {{%\w+}} {{%\w+}} %uint_0
4563fd4e5da5Sopenharmony_ci;CHECK: [[desc_state:%\w+]] = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_52 {{%\w+}} %uint_3 %uint_7 %uint_0 {{%\w+}}
4564fd4e5da5Sopenharmony_ci%26 = OpLoad %v2float %25
4565fd4e5da5Sopenharmony_ciOpStore %v_vtxResult %26
4566fd4e5da5Sopenharmony_ci;CHECK-NOT: %26 = OpLoad %v2float %25
4567fd4e5da5Sopenharmony_ci;CHECK-NOT: OpStore %v_vtxResult %26
4568fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
4569fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional [[desc_state]] {{%\w+}} {{%\w+}}
4570fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
4571fd4e5da5Sopenharmony_ci;CHECK: [[load_result]] = OpLoad %v2float %25
4572fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
4573fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
4574fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
4575fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
4576fd4e5da5Sopenharmony_ci;CHECK: [[phi_result]] = OpPhi %v2float [[load_result]] {{%\w+}} [[null_v2float]] {{%\w+}}
4577fd4e5da5Sopenharmony_ci;CHECK: OpStore %v_vtxResult [[phi_result]]
4578fd4e5da5Sopenharmony_ciOpReturn
4579fd4e5da5Sopenharmony_ciOpFunctionEnd
4580fd4e5da5Sopenharmony_ci)";
4581fd4e5da5Sopenharmony_ci  // clang-format on
4582fd4e5da5Sopenharmony_ci
4583fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
4584fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
4585fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 23u);
4586fd4e5da5Sopenharmony_ci}
4587fd4e5da5Sopenharmony_ci
4588fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest, ImageBufferOOBRead) {
4589fd4e5da5Sopenharmony_ci  // Texel buffer (imagebuffer) oob check for ImageRead
4590fd4e5da5Sopenharmony_ci  //
4591fd4e5da5Sopenharmony_ci  // #version 450
4592fd4e5da5Sopenharmony_ci  // layout(set=3, binding=7, r32f) uniform readonly imageBuffer s;
4593fd4e5da5Sopenharmony_ci  // layout(location=11) out vec4 x;
4594fd4e5da5Sopenharmony_ci  // layout(location=13) in flat int ii;
4595fd4e5da5Sopenharmony_ci  //
4596fd4e5da5Sopenharmony_ci  // void main(){
4597fd4e5da5Sopenharmony_ci  //    x = imageLoad(s, ii);
4598fd4e5da5Sopenharmony_ci  // }
4599fd4e5da5Sopenharmony_ci
4600fd4e5da5Sopenharmony_ci  // clang-format off
4601fd4e5da5Sopenharmony_ci  const std::string text = R"(
4602fd4e5da5Sopenharmony_ciOpCapability Shader
4603fd4e5da5Sopenharmony_ciOpCapability ImageBuffer
4604fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
4605fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
4606fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
4607fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %x %s %ii
4608fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
4609fd4e5da5Sopenharmony_ciOpSource GLSL 450
4610fd4e5da5Sopenharmony_ciOpName %main "main"
4611fd4e5da5Sopenharmony_ciOpName %x "x"
4612fd4e5da5Sopenharmony_ciOpName %s "s"
4613fd4e5da5Sopenharmony_ciOpName %ii "ii"
4614fd4e5da5Sopenharmony_ciOpDecorate %x Location 11
4615fd4e5da5Sopenharmony_ciOpDecorate %s DescriptorSet 3
4616fd4e5da5Sopenharmony_ciOpDecorate %s Binding 7
4617fd4e5da5Sopenharmony_ciOpDecorate %s NonWritable
4618fd4e5da5Sopenharmony_ciOpDecorate %ii Flat
4619fd4e5da5Sopenharmony_ciOpDecorate %ii Location 13
4620fd4e5da5Sopenharmony_ci)" + kImportDeco + R"(
4621fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
4622fd4e5da5Sopenharmony_ci%void = OpTypeVoid
4623fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
4624fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
4625fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
4626fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
4627fd4e5da5Sopenharmony_ci%x = OpVariable %_ptr_Output_v4float Output
4628fd4e5da5Sopenharmony_ci%10 = OpTypeImage %float Buffer 0 0 0 2 R32f
4629fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_10 = OpTypePointer UniformConstant %10
4630fd4e5da5Sopenharmony_ci%s = OpVariable %_ptr_UniformConstant_10 UniformConstant
4631fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
4632fd4e5da5Sopenharmony_ci%_ptr_Input_int = OpTypePointer Input %int
4633fd4e5da5Sopenharmony_ci%ii = OpVariable %_ptr_Input_int Input
4634fd4e5da5Sopenharmony_ci;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
4635fd4e5da5Sopenharmony_ci;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
4636fd4e5da5Sopenharmony_ci;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
4637fd4e5da5Sopenharmony_ci%main = OpFunction %void None %3
4638fd4e5da5Sopenharmony_ci%5 = OpLabel
4639fd4e5da5Sopenharmony_ci;CHECK: OpBranch %19
4640fd4e5da5Sopenharmony_ci;CHECK: %19 = OpLabel
4641fd4e5da5Sopenharmony_ci%13 = OpLoad %10 %s
4642fd4e5da5Sopenharmony_ci%17 = OpLoad %int %ii
4643fd4e5da5Sopenharmony_ci%18 = OpImageRead %v4float %13 %17
4644fd4e5da5Sopenharmony_ciOpStore %x %18
4645fd4e5da5Sopenharmony_ci;CHECK-NOT: %18 = OpImageRead %v4float %13 %17
4646fd4e5da5Sopenharmony_ci;CHECK-NOT: OpStore %x %18
4647fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord
4648fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}}
4649fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
4650fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
4651fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0
4652fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_34 {{%\w+}} %uint_3 %uint_7 %uint_0 %22
4653fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
4654fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
4655fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
4656fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %10 %s
4657fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpImageRead %v4float {{%\w+}} %17
4658fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
4659fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
4660fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
4661fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
4662fd4e5da5Sopenharmony_ci;CHECK: [[phi_result:%\w+]] = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}}
4663fd4e5da5Sopenharmony_ci;CHECK: OpStore %x [[phi_result]]
4664fd4e5da5Sopenharmony_ciOpReturn
4665fd4e5da5Sopenharmony_ciOpFunctionEnd
4666fd4e5da5Sopenharmony_ci)";
4667fd4e5da5Sopenharmony_ci  // clang-format on
4668fd4e5da5Sopenharmony_ci
4669fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
4670fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
4671fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 23u);
4672fd4e5da5Sopenharmony_ci}
4673fd4e5da5Sopenharmony_ci
4674fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest, ImageBufferOOBWrite) {
4675fd4e5da5Sopenharmony_ci  // Texel buffer (imagebuffer) oob check for ImageWrite
4676fd4e5da5Sopenharmony_ci  //
4677fd4e5da5Sopenharmony_ci  // #version 450
4678fd4e5da5Sopenharmony_ci  // layout(set=3, binding=7, r32f) uniform readonly imageBuffer s;
4679fd4e5da5Sopenharmony_ci  // layout(location=11) out vec4 x;
4680fd4e5da5Sopenharmony_ci  // layout(location=13) in flat int ii;
4681fd4e5da5Sopenharmony_ci  //
4682fd4e5da5Sopenharmony_ci  // void main(){
4683fd4e5da5Sopenharmony_ci  //    imageStore(s, ii, x);
4684fd4e5da5Sopenharmony_ci  // }
4685fd4e5da5Sopenharmony_ci
4686fd4e5da5Sopenharmony_ci  // clang-format off
4687fd4e5da5Sopenharmony_ci  const std::string text = R"(
4688fd4e5da5Sopenharmony_ciOpCapability Shader
4689fd4e5da5Sopenharmony_ciOpCapability ImageBuffer
4690fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
4691fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
4692fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
4693fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %s %ii %x
4694fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint Fragment %main "main" %s %ii %x %gl_FragCoord
4695fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
4696fd4e5da5Sopenharmony_ciOpSource GLSL 450
4697fd4e5da5Sopenharmony_ciOpName %main "main"
4698fd4e5da5Sopenharmony_ciOpName %s "s"
4699fd4e5da5Sopenharmony_ciOpName %ii "ii"
4700fd4e5da5Sopenharmony_ciOpName %x "x"
4701fd4e5da5Sopenharmony_ciOpDecorate %s DescriptorSet 3
4702fd4e5da5Sopenharmony_ciOpDecorate %s Binding 7
4703fd4e5da5Sopenharmony_ciOpDecorate %s NonReadable
4704fd4e5da5Sopenharmony_ciOpDecorate %ii Flat
4705fd4e5da5Sopenharmony_ciOpDecorate %ii Location 13
4706fd4e5da5Sopenharmony_ciOpDecorate %x Location 11
4707fd4e5da5Sopenharmony_ci)" + kImportDeco + R"(
4708fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
4709fd4e5da5Sopenharmony_ci%void = OpTypeVoid
4710fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
4711fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
4712fd4e5da5Sopenharmony_ci%7 = OpTypeImage %float Buffer 0 0 0 2 R32f
4713fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_7 = OpTypePointer UniformConstant %7
4714fd4e5da5Sopenharmony_ci%s = OpVariable %_ptr_UniformConstant_7 UniformConstant
4715fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
4716fd4e5da5Sopenharmony_ci%_ptr_Input_int = OpTypePointer Input %int
4717fd4e5da5Sopenharmony_ci%ii = OpVariable %_ptr_Input_int Input
4718fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
4719fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
4720fd4e5da5Sopenharmony_ci%x = OpVariable %_ptr_Output_v4float Output
4721fd4e5da5Sopenharmony_ci;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
4722fd4e5da5Sopenharmony_ci;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
4723fd4e5da5Sopenharmony_ci)" + kImportStub + R"(
4724fd4e5da5Sopenharmony_ci%main = OpFunction %void None %3
4725fd4e5da5Sopenharmony_ci%5 = OpLabel
4726fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
4727fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
4728fd4e5da5Sopenharmony_ci;CHECK: %19 = OpLabel
4729fd4e5da5Sopenharmony_ci%10 = OpLoad %7 %s
4730fd4e5da5Sopenharmony_ci%14 = OpLoad %int %ii
4731fd4e5da5Sopenharmony_ci%18 = OpLoad %v4float %x
4732fd4e5da5Sopenharmony_ciOpImageWrite %10 %14 %18
4733fd4e5da5Sopenharmony_ci;CHECK-NOT: OpImageWrite %10 %14 %18
4734fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord
4735fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}}
4736fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
4737fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
4738fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0
4739fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_35 {{%\w+}} %uint_3 %uint_7 %uint_0 {{%\w+}}
4740fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
4741fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
4742fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
4743fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %7 %s
4744fd4e5da5Sopenharmony_ci;CHECK: OpImageWrite {{%\w+}} %14 %18
4745fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
4746fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
4747fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
4748fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
4749fd4e5da5Sopenharmony_ciOpReturn
4750fd4e5da5Sopenharmony_ciOpFunctionEnd
4751fd4e5da5Sopenharmony_ci)";
4752fd4e5da5Sopenharmony_ci  // clang-format on
4753fd4e5da5Sopenharmony_ci
4754fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
4755fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
4756fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 23u);
4757fd4e5da5Sopenharmony_ci}
4758fd4e5da5Sopenharmony_ci
4759fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest, TextureBufferOOBFetch) {
4760fd4e5da5Sopenharmony_ci  // Texel buffer (texturebuffer) oob check for ImageFetch
4761fd4e5da5Sopenharmony_ci  //
4762fd4e5da5Sopenharmony_ci  // #version 450
4763fd4e5da5Sopenharmony_ci  // layout(set=3, binding=7) uniform textureBuffer s;
4764fd4e5da5Sopenharmony_ci  // layout(location=11) out vec4 x;
4765fd4e5da5Sopenharmony_ci  // layout(location=13) in flat int ii;
4766fd4e5da5Sopenharmony_ci  //
4767fd4e5da5Sopenharmony_ci  // void main(){
4768fd4e5da5Sopenharmony_ci  //    x = texelFetch(s, ii);
4769fd4e5da5Sopenharmony_ci  // }
4770fd4e5da5Sopenharmony_ci
4771fd4e5da5Sopenharmony_ci  // clang-format off
4772fd4e5da5Sopenharmony_ci  const std::string text = R"(
4773fd4e5da5Sopenharmony_ciOpCapability Shader
4774fd4e5da5Sopenharmony_ciOpCapability SampledBuffer
4775fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
4776fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
4777fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
4778fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %x %s %ii
4779fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint Fragment %main "main" %x %s %ii %gl_FragCoord
4780fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
4781fd4e5da5Sopenharmony_ciOpSource GLSL 450
4782fd4e5da5Sopenharmony_ciOpName %main "main"
4783fd4e5da5Sopenharmony_ciOpName %x "x"
4784fd4e5da5Sopenharmony_ciOpName %s "s"
4785fd4e5da5Sopenharmony_ciOpName %ii "ii"
4786fd4e5da5Sopenharmony_ciOpDecorate %x Location 11
4787fd4e5da5Sopenharmony_ciOpDecorate %s DescriptorSet 3
4788fd4e5da5Sopenharmony_ciOpDecorate %s Binding 7
4789fd4e5da5Sopenharmony_ciOpDecorate %ii Flat
4790fd4e5da5Sopenharmony_ciOpDecorate %ii Location 13
4791fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
4792fd4e5da5Sopenharmony_ci%void = OpTypeVoid
4793fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
4794fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
4795fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
4796fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
4797fd4e5da5Sopenharmony_ci%x = OpVariable %_ptr_Output_v4float Output
4798fd4e5da5Sopenharmony_ci%10 = OpTypeImage %float Buffer 0 0 0 1 Unknown
4799fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_10 = OpTypePointer UniformConstant %10
4800fd4e5da5Sopenharmony_ci%s = OpVariable %_ptr_UniformConstant_10 UniformConstant
4801fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
4802fd4e5da5Sopenharmony_ci%_ptr_Input_int = OpTypePointer Input %int
4803fd4e5da5Sopenharmony_ci%ii = OpVariable %_ptr_Input_int Input
4804fd4e5da5Sopenharmony_ci;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
4805fd4e5da5Sopenharmony_ci;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
4806fd4e5da5Sopenharmony_ci;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
4807fd4e5da5Sopenharmony_ci%main = OpFunction %void None %3
4808fd4e5da5Sopenharmony_ci%5 = OpLabel
4809fd4e5da5Sopenharmony_ci;CHECK: OpBranch %19
4810fd4e5da5Sopenharmony_ci;CHECK: %19 = OpLabel
4811fd4e5da5Sopenharmony_ci%13 = OpLoad %10 %s
4812fd4e5da5Sopenharmony_ci%17 = OpLoad %int %ii
4813fd4e5da5Sopenharmony_ci%18 = OpImageFetch %v4float %13 %17
4814fd4e5da5Sopenharmony_ciOpStore %x %18
4815fd4e5da5Sopenharmony_ci;CHECK-NOT: %18 = OpImageFetch %v4float %13 %17
4816fd4e5da5Sopenharmony_ci;CHECK-NOT: OpStore %x %18
4817fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord
4818fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}}
4819fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
4820fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
4821fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0
4822fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_33 {{%\w+}} %uint_3 %uint_7 %uint_0 {{%\w+}}
4823fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
4824fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
4825fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
4826fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %10 %s
4827fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpImageFetch %v4float {{%\w+}} %17
4828fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
4829fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
4830fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
4831fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
4832fd4e5da5Sopenharmony_ci;CHECK: [[phi_result:%\w+]] = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}}
4833fd4e5da5Sopenharmony_ci;CHECK: OpStore %x [[phi_result]]
4834fd4e5da5Sopenharmony_ciOpReturn
4835fd4e5da5Sopenharmony_ciOpFunctionEnd
4836fd4e5da5Sopenharmony_ci)";
4837fd4e5da5Sopenharmony_ci  // clang-format on
4838fd4e5da5Sopenharmony_ci
4839fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
4840fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
4841fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 23u);
4842fd4e5da5Sopenharmony_ci}
4843fd4e5da5Sopenharmony_ci
4844fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest, SamplerBufferOOBFetch) {
4845fd4e5da5Sopenharmony_ci  // Texel buffer (samplerbuffer) oob check for ImageFetch
4846fd4e5da5Sopenharmony_ci  //
4847fd4e5da5Sopenharmony_ci  // #version 450
4848fd4e5da5Sopenharmony_ci  // layout(set=3, binding=7) uniform samplerBuffer s;
4849fd4e5da5Sopenharmony_ci  // layout(location=11) out vec4 x;
4850fd4e5da5Sopenharmony_ci  // layout(location=13) in flat int ii;
4851fd4e5da5Sopenharmony_ci  //
4852fd4e5da5Sopenharmony_ci  // void main(){
4853fd4e5da5Sopenharmony_ci  //    x = texelFetch(s, ii);
4854fd4e5da5Sopenharmony_ci  // }
4855fd4e5da5Sopenharmony_ci
4856fd4e5da5Sopenharmony_ci  // clang-format off
4857fd4e5da5Sopenharmony_ci  const std::string text = R"(
4858fd4e5da5Sopenharmony_ciOpCapability Shader
4859fd4e5da5Sopenharmony_ciOpCapability SampledBuffer
4860fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
4861fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
4862fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
4863fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %x %s %ii
4864fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint Fragment %main "main" %x %s %ii %gl_FragCoord
4865fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
4866fd4e5da5Sopenharmony_ciOpSource GLSL 450
4867fd4e5da5Sopenharmony_ciOpName %main "main"
4868fd4e5da5Sopenharmony_ciOpName %x "x"
4869fd4e5da5Sopenharmony_ciOpName %s "s"
4870fd4e5da5Sopenharmony_ciOpName %ii "ii"
4871fd4e5da5Sopenharmony_ciOpDecorate %x Location 11
4872fd4e5da5Sopenharmony_ciOpDecorate %s DescriptorSet 3
4873fd4e5da5Sopenharmony_ciOpDecorate %s Binding 7
4874fd4e5da5Sopenharmony_ciOpDecorate %ii Flat
4875fd4e5da5Sopenharmony_ciOpDecorate %ii Location 13
4876fd4e5da5Sopenharmony_ci)" + kImportDeco + R"(
4877fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
4878fd4e5da5Sopenharmony_ci%void = OpTypeVoid
4879fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
4880fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
4881fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
4882fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
4883fd4e5da5Sopenharmony_ci%x = OpVariable %_ptr_Output_v4float Output
4884fd4e5da5Sopenharmony_ci%10 = OpTypeImage %float Buffer 0 0 0 1 Unknown
4885fd4e5da5Sopenharmony_ci%11 = OpTypeSampledImage %10
4886fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_11 = OpTypePointer UniformConstant %11
4887fd4e5da5Sopenharmony_ci%s = OpVariable %_ptr_UniformConstant_11 UniformConstant
4888fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
4889fd4e5da5Sopenharmony_ci%_ptr_Input_int = OpTypePointer Input %int
4890fd4e5da5Sopenharmony_ci%ii = OpVariable %_ptr_Input_int Input
4891fd4e5da5Sopenharmony_ci;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
4892fd4e5da5Sopenharmony_ci;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
4893fd4e5da5Sopenharmony_ci;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
4894fd4e5da5Sopenharmony_ci)" + kImportStub + R"(
4895fd4e5da5Sopenharmony_ci%main = OpFunction %void None %3
4896fd4e5da5Sopenharmony_ci%5 = OpLabel
4897fd4e5da5Sopenharmony_ci;CHECK: OpBranch %21
4898fd4e5da5Sopenharmony_ci;CHECK: %21 = OpLabel
4899fd4e5da5Sopenharmony_ci%14 = OpLoad %11 %s
4900fd4e5da5Sopenharmony_ci%18 = OpLoad %int %ii
4901fd4e5da5Sopenharmony_ci%19 = OpImage %10 %14
4902fd4e5da5Sopenharmony_ci%20 = OpImageFetch %v4float %19 %18
4903fd4e5da5Sopenharmony_ciOpStore %x %20
4904fd4e5da5Sopenharmony_ci;CHECK-NOT: %20 = OpImageFetch %v4float %19 %18
4905fd4e5da5Sopenharmony_ci;CHECK-NOT: OpStore %x %20
4906fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord
4907fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}}
4908fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
4909fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
4910fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0
4911fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_35 {{%\w+}} %uint_3 %uint_7 %uint_0 {{%\w+}}
4912fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
4913fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
4914fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
4915fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %11 %s
4916fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpImage %10 {{%\w+}}
4917fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpImageFetch %v4float {{%\w+}} {{%\w+}}
4918fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
4919fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
4920fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
4921fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
4922fd4e5da5Sopenharmony_ci;CHECK: [[phi_result:%\w+]] = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}}
4923fd4e5da5Sopenharmony_ci;CHECK: OpStore %x [[phi_result]]
4924fd4e5da5Sopenharmony_ciOpReturn
4925fd4e5da5Sopenharmony_ciOpFunctionEnd
4926fd4e5da5Sopenharmony_ci)";
4927fd4e5da5Sopenharmony_ci  // clang-format on
4928fd4e5da5Sopenharmony_ci
4929fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
4930fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
4931fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 23u);
4932fd4e5da5Sopenharmony_ci}
4933fd4e5da5Sopenharmony_ci
4934fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest, SamplerBufferConstructorOOBFetch) {
4935fd4e5da5Sopenharmony_ci  // Texel buffer (samplerbuffer constructor) oob check for ImageFetch
4936fd4e5da5Sopenharmony_ci  //
4937fd4e5da5Sopenharmony_ci  // #version 450
4938fd4e5da5Sopenharmony_ci  // layout(set=3, binding=7) uniform textureBuffer tBuf;
4939fd4e5da5Sopenharmony_ci  // layout(set=3, binding=8) uniform sampler s;
4940fd4e5da5Sopenharmony_ci  // layout(location=11) out vec4 x;
4941fd4e5da5Sopenharmony_ci  // layout(location=13) in flat int ii;
4942fd4e5da5Sopenharmony_ci  //
4943fd4e5da5Sopenharmony_ci  // void main(){
4944fd4e5da5Sopenharmony_ci  //    x = texelFetch(samplerBuffer(tBuf, s), ii);
4945fd4e5da5Sopenharmony_ci  // }
4946fd4e5da5Sopenharmony_ci
4947fd4e5da5Sopenharmony_ci  // clang-format off
4948fd4e5da5Sopenharmony_ci  const std::string text = R"(
4949fd4e5da5Sopenharmony_ciOpCapability Shader
4950fd4e5da5Sopenharmony_ciOpCapability SampledBuffer
4951fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
4952fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
4953fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
4954fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %x %tBuf %s %ii
4955fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint Fragment %main "main" %x %tBuf %s %ii %gl_FragCoord
4956fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
4957fd4e5da5Sopenharmony_ciOpSource GLSL 450
4958fd4e5da5Sopenharmony_ciOpName %main "main"
4959fd4e5da5Sopenharmony_ciOpName %x "x"
4960fd4e5da5Sopenharmony_ciOpName %tBuf "tBuf"
4961fd4e5da5Sopenharmony_ciOpName %s "s"
4962fd4e5da5Sopenharmony_ciOpName %ii "ii"
4963fd4e5da5Sopenharmony_ciOpDecorate %x Location 11
4964fd4e5da5Sopenharmony_ciOpDecorate %tBuf DescriptorSet 3
4965fd4e5da5Sopenharmony_ciOpDecorate %tBuf Binding 7
4966fd4e5da5Sopenharmony_ciOpDecorate %s DescriptorSet 3
4967fd4e5da5Sopenharmony_ciOpDecorate %s Binding 8
4968fd4e5da5Sopenharmony_ciOpDecorate %ii Flat
4969fd4e5da5Sopenharmony_ciOpDecorate %ii Location 13
4970fd4e5da5Sopenharmony_ci)" + kImportDeco + R"(
4971fd4e5da5Sopenharmony_ci;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
4972fd4e5da5Sopenharmony_ci%void = OpTypeVoid
4973fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
4974fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
4975fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
4976fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
4977fd4e5da5Sopenharmony_ci%x = OpVariable %_ptr_Output_v4float Output
4978fd4e5da5Sopenharmony_ci%10 = OpTypeImage %float Buffer 0 0 0 1 Unknown
4979fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_10 = OpTypePointer UniformConstant %10
4980fd4e5da5Sopenharmony_ci%tBuf = OpVariable %_ptr_UniformConstant_10 UniformConstant
4981fd4e5da5Sopenharmony_ci%14 = OpTypeSampler
4982fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_14 = OpTypePointer UniformConstant %14
4983fd4e5da5Sopenharmony_ci%s = OpVariable %_ptr_UniformConstant_14 UniformConstant
4984fd4e5da5Sopenharmony_ci%18 = OpTypeSampledImage %10
4985fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
4986fd4e5da5Sopenharmony_ci%_ptr_Input_int = OpTypePointer Input %int
4987fd4e5da5Sopenharmony_ci%ii = OpVariable %_ptr_Input_int Input
4988fd4e5da5Sopenharmony_ci;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
4989fd4e5da5Sopenharmony_ci;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
4990fd4e5da5Sopenharmony_ci;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
4991fd4e5da5Sopenharmony_ci%main = OpFunction %void None %3
4992fd4e5da5Sopenharmony_ci%5 = OpLabel
4993fd4e5da5Sopenharmony_ci%13 = OpLoad %10 %tBuf
4994fd4e5da5Sopenharmony_ci%17 = OpLoad %14 %s
4995fd4e5da5Sopenharmony_ci%19 = OpSampledImage %18 %13 %17
4996fd4e5da5Sopenharmony_ci%23 = OpLoad %int %ii
4997fd4e5da5Sopenharmony_ci%24 = OpImage %10 %19
4998fd4e5da5Sopenharmony_ci%25 = OpImageFetch %v4float %24 %23
4999fd4e5da5Sopenharmony_ciOpStore %x %25
5000fd4e5da5Sopenharmony_ci;CHECK-NOT: %25 = OpImageFetch %v4float %24 %23
5001fd4e5da5Sopenharmony_ci;CHECK-NOT: OpStore %x %25
5002fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord
5003fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}}
5004fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
5005fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
5006fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_4 {{%\w+}} {{%\w+}} %uint_0
5007fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_43 {{%\w+}} %uint_3 %uint_7 %uint_0 {{%\w+}}
5008fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
5009fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
5010fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
5011fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %10 %tBuf
5012fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpSampledImage %18 {{%\w+}} %17
5013fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpImage %10 {{%\w+}}
5014fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpImageFetch %v4float {{%\w+}} %23
5015fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
5016fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
5017fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
5018fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
5019fd4e5da5Sopenharmony_ci;CHECK: [[phi_result:%\w+]] = OpPhi %v4float {{%\w+}} {{%\w+}} [[null_v4float]] {{%\w+}}
5020fd4e5da5Sopenharmony_ci;CHECK: OpStore %x [[phi_result]]
5021fd4e5da5Sopenharmony_ciOpReturn
5022fd4e5da5Sopenharmony_ciOpFunctionEnd
5023fd4e5da5Sopenharmony_ci)";
5024fd4e5da5Sopenharmony_ci  // clang-format on
5025fd4e5da5Sopenharmony_ci
5026fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
5027fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
5028fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 23u);
5029fd4e5da5Sopenharmony_ci}
5030fd4e5da5Sopenharmony_ci
5031fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest, DeviceBufferAddressOOB) {
5032fd4e5da5Sopenharmony_ci  // #version 450
5033fd4e5da5Sopenharmony_ci  // #extension GL_EXT_buffer_reference : enable
5034fd4e5da5Sopenharmony_ci  //  layout(buffer_reference, buffer_reference_align = 16) buffer bufStruct;
5035fd4e5da5Sopenharmony_ci  // layout(set = 0, binding = 0) uniform ufoo {
5036fd4e5da5Sopenharmony_ci  //     bufStruct data;
5037fd4e5da5Sopenharmony_ci  //     int nWrites;
5038fd4e5da5Sopenharmony_ci  // } u_info;
5039fd4e5da5Sopenharmony_ci  // layout(buffer_reference, std140) buffer bufStruct {
5040fd4e5da5Sopenharmony_ci  //     int a[4];
5041fd4e5da5Sopenharmony_ci  // };
5042fd4e5da5Sopenharmony_ci  // void main() {
5043fd4e5da5Sopenharmony_ci  //     for (int i=0; i < u_info.nWrites; ++i) {
5044fd4e5da5Sopenharmony_ci  //         u_info.data.a[i] = 0xdeadca71;
5045fd4e5da5Sopenharmony_ci  //     }
5046fd4e5da5Sopenharmony_ci  // }
5047fd4e5da5Sopenharmony_ci
5048fd4e5da5Sopenharmony_ci  // clang-format off
5049fd4e5da5Sopenharmony_ci  const std::string text = R"(
5050fd4e5da5Sopenharmony_ciOpCapability Shader
5051fd4e5da5Sopenharmony_ciOpCapability PhysicalStorageBufferAddresses
5052fd4e5da5Sopenharmony_ci;CHECK: OpCapability Linkage
5053fd4e5da5Sopenharmony_ci;CHECK: OpCapability Int64
5054fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_physical_storage_buffer"
5055fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
5056fd4e5da5Sopenharmony_ciOpMemoryModel PhysicalStorageBuffer64 GLSL450
5057fd4e5da5Sopenharmony_ciOpEntryPoint Vertex %main "main" %u_info
5058fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint Vertex %main "main" %u_info %gl_VertexIndex %gl_InstanceIndex
5059fd4e5da5Sopenharmony_ciOpSource GLSL 450
5060fd4e5da5Sopenharmony_ciOpSourceExtension "GL_EXT_buffer_reference"
5061fd4e5da5Sopenharmony_ciOpName %main "main"
5062fd4e5da5Sopenharmony_ciOpName %i "i"
5063fd4e5da5Sopenharmony_ciOpName %ufoo "ufoo"
5064fd4e5da5Sopenharmony_ciOpMemberName %ufoo 0 "data"
5065fd4e5da5Sopenharmony_ciOpMemberName %ufoo 1 "nWrites"
5066fd4e5da5Sopenharmony_ciOpName %bufStruct "bufStruct"
5067fd4e5da5Sopenharmony_ciOpMemberName %bufStruct 0 "a"
5068fd4e5da5Sopenharmony_ciOpName %u_info "u_info"
5069fd4e5da5Sopenharmony_ciOpMemberDecorate %ufoo 0 Offset 0
5070fd4e5da5Sopenharmony_ciOpMemberDecorate %ufoo 1 Offset 8
5071fd4e5da5Sopenharmony_ciOpDecorate %ufoo Block
5072fd4e5da5Sopenharmony_ciOpDecorate %_arr_int_uint_4 ArrayStride 16
5073fd4e5da5Sopenharmony_ciOpMemberDecorate %bufStruct 0 Offset 0
5074fd4e5da5Sopenharmony_ciOpDecorate %bufStruct Block
5075fd4e5da5Sopenharmony_ciOpDecorate %u_info DescriptorSet 0
5076fd4e5da5Sopenharmony_ciOpDecorate %u_info Binding 0
5077fd4e5da5Sopenharmony_ci%void = OpTypeVoid
5078fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
5079fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
5080fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
5081fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
5082fd4e5da5Sopenharmony_ciOpTypeForwardPointer %_ptr_PhysicalStorageBuffer_bufStruct PhysicalStorageBuffer
5083fd4e5da5Sopenharmony_ci%ufoo = OpTypeStruct %_ptr_PhysicalStorageBuffer_bufStruct %int
5084fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
5085fd4e5da5Sopenharmony_ci%uint_4 = OpConstant %uint 4
5086fd4e5da5Sopenharmony_ci%_arr_int_uint_4 = OpTypeArray %int %uint_4
5087fd4e5da5Sopenharmony_ci%bufStruct = OpTypeStruct %_arr_int_uint_4
5088fd4e5da5Sopenharmony_ci%_ptr_PhysicalStorageBuffer_bufStruct = OpTypePointer PhysicalStorageBuffer %bufStruct
5089fd4e5da5Sopenharmony_ci%_ptr_Uniform_ufoo = OpTypePointer Uniform %ufoo
5090fd4e5da5Sopenharmony_ci%u_info = OpVariable %_ptr_Uniform_ufoo Uniform
5091fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
5092fd4e5da5Sopenharmony_ci%_ptr_Uniform_int = OpTypePointer Uniform %int
5093fd4e5da5Sopenharmony_ci%bool = OpTypeBool
5094fd4e5da5Sopenharmony_ci%_ptr_Uniform__ptr_PhysicalStorageBuffer_bufStruct = OpTypePointer Uniform %_ptr_PhysicalStorageBuffer_bufStruct
5095fd4e5da5Sopenharmony_ci%int_n559035791 = OpConstant %int -559035791
5096fd4e5da5Sopenharmony_ci%_ptr_PhysicalStorageBuffer_int = OpTypePointer PhysicalStorageBuffer %int
5097fd4e5da5Sopenharmony_ci)" + kImportStub + R"(
5098fd4e5da5Sopenharmony_ci%main = OpFunction %void None %3
5099fd4e5da5Sopenharmony_ci%5 = OpLabel
5100fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
5101fd4e5da5Sopenharmony_ciOpStore %i %int_0
5102fd4e5da5Sopenharmony_ciOpBranch %10
5103fd4e5da5Sopenharmony_ci%10 = OpLabel
5104fd4e5da5Sopenharmony_ciOpLoopMerge %12 %13 None
5105fd4e5da5Sopenharmony_ciOpBranch %14
5106fd4e5da5Sopenharmony_ci%14 = OpLabel
5107fd4e5da5Sopenharmony_ci%15 = OpLoad %int %i
5108fd4e5da5Sopenharmony_ci%26 = OpAccessChain %_ptr_Uniform_int %u_info %int_1
5109fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpIAdd %uint %uint_8 %uint_3
5110fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %uint %gl_VertexIndex
5111fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %uint %gl_InstanceIndex
5112fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_0 {{%\w+}} {{%\w+}} %uint_0
5113fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_56 {{%\w+}} %uint_0 %uint_0 %uint_0 {{%\w+}}
5114fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
5115fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
5116fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
5117fd4e5da5Sopenharmony_ci;CHECK: [[load_result:%\w+]] = OpLoad %int %26
5118fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
5119fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
5120fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
5121fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
5122fd4e5da5Sopenharmony_ci;CHECK: [[phi_result:%\w+]] = OpPhi %int [[load_result]] {{%\w+}} {{%\w+}} {{%\w+}}
5123fd4e5da5Sopenharmony_ci%27 = OpLoad %int %26
5124fd4e5da5Sopenharmony_ci%29 = OpSLessThan %bool %15 %27
5125fd4e5da5Sopenharmony_ci;CHECK-NOT: %27 = OpLoad %int %26
5126fd4e5da5Sopenharmony_ci;CHECK-NOT: %29 = OpSLessThan %bool %15 %27
5127fd4e5da5Sopenharmony_ci;CHECK: %29 = OpSLessThan %bool %15 [[phi_result]]
5128fd4e5da5Sopenharmony_ciOpBranchConditional %29 %11 %12
5129fd4e5da5Sopenharmony_ci%11 = OpLabel
5130fd4e5da5Sopenharmony_ci%31 = OpAccessChain %_ptr_Uniform__ptr_PhysicalStorageBuffer_bufStruct %u_info %int_0
5131fd4e5da5Sopenharmony_ci%32 = OpLoad %_ptr_PhysicalStorageBuffer_bufStruct %31
5132fd4e5da5Sopenharmony_ci;CHECK-NOT: %32 = OpLoad %_ptr_PhysicalStorageBuffer_bufStruct %31
5133fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpIAdd %uint %uint_0 %uint_7
5134fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %uint %gl_VertexIndex
5135fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %uint %gl_InstanceIndex
5136fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_0 {{%\w+}} {{%\w+}} %uint_0
5137fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_61 {{%\w+}} %uint_0 %uint_0 %uint_0 {{%\w+}}
5138fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
5139fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
5140fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
5141fd4e5da5Sopenharmony_ci;CHECK: [[load_result_2:%\w+]] = OpLoad %_ptr_PhysicalStorageBuffer_bufStruct %31
5142fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
5143fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
5144fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpConvertUToPtr %_ptr_PhysicalStorageBuffer_bufStruct {{%\w+}}
5145fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
5146fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
5147fd4e5da5Sopenharmony_ci;CHECK: [[phi_result_2:%\w+]] = OpPhi %_ptr_PhysicalStorageBuffer_bufStruct [[load_result_2]] {{%\w+}} {{%\w+}} {{%\w+}}
5148fd4e5da5Sopenharmony_ci%33 = OpLoad %int %i
5149fd4e5da5Sopenharmony_ci%36 = OpAccessChain %_ptr_PhysicalStorageBuffer_int %32 %int_0 %33
5150fd4e5da5Sopenharmony_ci;CHECK-NOT: %36 = OpAccessChain %_ptr_PhysicalStorageBuffer_int %32 %int_0 %33
5151fd4e5da5Sopenharmony_ci;CHECK: %36 = OpAccessChain %_ptr_PhysicalStorageBuffer_int [[phi_result_2]] %int_0 %33
5152fd4e5da5Sopenharmony_ciOpStore %36 %int_n559035791 Aligned 16
5153fd4e5da5Sopenharmony_ciOpBranch %13
5154fd4e5da5Sopenharmony_ci%13 = OpLabel
5155fd4e5da5Sopenharmony_ci%37 = OpLoad %int %i
5156fd4e5da5Sopenharmony_ci%38 = OpIAdd %int %37 %int_1
5157fd4e5da5Sopenharmony_ciOpStore %i %38
5158fd4e5da5Sopenharmony_ciOpBranch %10
5159fd4e5da5Sopenharmony_ci%12 = OpLabel
5160fd4e5da5Sopenharmony_ciOpReturn
5161fd4e5da5Sopenharmony_ciOpFunctionEnd)";
5162fd4e5da5Sopenharmony_ci  // clang-format on
5163fd4e5da5Sopenharmony_ci
5164fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
5165fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
5166fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 23u);
5167fd4e5da5Sopenharmony_ci}
5168fd4e5da5Sopenharmony_ci
5169fd4e5da5Sopenharmony_ciTEST_F(InstBindlessTest, VertexIndexOOB) {
5170fd4e5da5Sopenharmony_ci  // #version 450
5171fd4e5da5Sopenharmony_ci  // layout(std140, binding = 0) uniform foo { uint tex_index[1]; }
5172fd4e5da5Sopenharmony_ci  // uniform_index_buffer; layout(location = 0) out flat uint index; vec2
5173fd4e5da5Sopenharmony_ci  // vertices[3]; void main() {
5174fd4e5da5Sopenharmony_ci  //     vertices[0] = vec2(-1.0, -1.0);
5175fd4e5da5Sopenharmony_ci  //     vertices[1] = vec2( 1.0, -1.0);
5176fd4e5da5Sopenharmony_ci  //     vertices[2] = vec2( 0.0,  1.0);
5177fd4e5da5Sopenharmony_ci  //     gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);
5178fd4e5da5Sopenharmony_ci  //     index = uniform_index_buffer.tex_index[0];
5179fd4e5da5Sopenharmony_ci  // }
5180fd4e5da5Sopenharmony_ci  // clang-format off
5181fd4e5da5Sopenharmony_ci  const std::string text = R"(
5182fd4e5da5Sopenharmony_ciOpCapability Shader
5183fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
5184fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
5185fd4e5da5Sopenharmony_ciOpEntryPoint Vertex %main "main" %vertices %_ %gl_VertexIndex %index %uniform_index_buffer
5186fd4e5da5Sopenharmony_ciOpSource GLSL 450
5187fd4e5da5Sopenharmony_ciOpName %main "main"
5188fd4e5da5Sopenharmony_ciOpName %vertices "vertices"
5189fd4e5da5Sopenharmony_ciOpName %gl_PerVertex "gl_PerVertex"
5190fd4e5da5Sopenharmony_ciOpMemberName %gl_PerVertex 0 "gl_Position"
5191fd4e5da5Sopenharmony_ciOpMemberName %gl_PerVertex 1 "gl_PointSize"
5192fd4e5da5Sopenharmony_ciOpMemberName %gl_PerVertex 2 "gl_ClipDistance"
5193fd4e5da5Sopenharmony_ciOpMemberName %gl_PerVertex 3 "gl_CullDistance"
5194fd4e5da5Sopenharmony_ciOpName %_ ""
5195fd4e5da5Sopenharmony_ciOpName %gl_VertexIndex "gl_VertexIndex"
5196fd4e5da5Sopenharmony_ciOpName %index "index"
5197fd4e5da5Sopenharmony_ciOpName %foo "foo"
5198fd4e5da5Sopenharmony_ciOpMemberName %foo 0 "tex_index"
5199fd4e5da5Sopenharmony_ciOpName %uniform_index_buffer "uniform_index_buffer"
5200fd4e5da5Sopenharmony_ciOpMemberDecorate %gl_PerVertex 0 BuiltIn Position
5201fd4e5da5Sopenharmony_ciOpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
5202fd4e5da5Sopenharmony_ciOpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
5203fd4e5da5Sopenharmony_ciOpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
5204fd4e5da5Sopenharmony_ciOpDecorate %gl_PerVertex Block
5205fd4e5da5Sopenharmony_ciOpDecorate %gl_VertexIndex BuiltIn VertexIndex
5206fd4e5da5Sopenharmony_ciOpDecorate %index Flat
5207fd4e5da5Sopenharmony_ciOpDecorate %index Location 0
5208fd4e5da5Sopenharmony_ciOpDecorate %_arr_uint_uint_1 ArrayStride 16
5209fd4e5da5Sopenharmony_ciOpMemberDecorate %foo 0 Offset 0
5210fd4e5da5Sopenharmony_ciOpDecorate %foo Block
5211fd4e5da5Sopenharmony_ciOpDecorate %uniform_index_buffer DescriptorSet 0
5212fd4e5da5Sopenharmony_ciOpDecorate %uniform_index_buffer Binding 0
5213fd4e5da5Sopenharmony_ci%void = OpTypeVoid
5214fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
5215fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
5216fd4e5da5Sopenharmony_ci%v2float = OpTypeVector %float 2
5217fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
5218fd4e5da5Sopenharmony_ci%uint_3 = OpConstant %uint 3
5219fd4e5da5Sopenharmony_ci%_arr_v2float_uint_3 = OpTypeArray %v2float %uint_3
5220fd4e5da5Sopenharmony_ci%_ptr_Private__arr_v2float_uint_3 = OpTypePointer Private %_arr_v2float_uint_3
5221fd4e5da5Sopenharmony_ci%vertices = OpVariable %_ptr_Private__arr_v2float_uint_3 Private
5222fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
5223fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
5224fd4e5da5Sopenharmony_ci%float_n1 = OpConstant %float -1
5225fd4e5da5Sopenharmony_ci%16 = OpConstantComposite %v2float %float_n1 %float_n1
5226fd4e5da5Sopenharmony_ci%_ptr_Private_v2float = OpTypePointer Private %v2float
5227fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
5228fd4e5da5Sopenharmony_ci%float_1 = OpConstant %float 1
5229fd4e5da5Sopenharmony_ci%21 = OpConstantComposite %v2float %float_1 %float_n1
5230fd4e5da5Sopenharmony_ci%int_2 = OpConstant %int 2
5231fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
5232fd4e5da5Sopenharmony_ci%25 = OpConstantComposite %v2float %float_0 %float_1
5233fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
5234fd4e5da5Sopenharmony_ci%uint_1 = OpConstant %uint 1
5235fd4e5da5Sopenharmony_ci%_arr_float_uint_1 = OpTypeArray %float %uint_1
5236fd4e5da5Sopenharmony_ci%gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
5237fd4e5da5Sopenharmony_ci%_ptr_Output_gl_PerVertex = OpTypePointer Output %gl_PerVertex
5238fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_Output_gl_PerVertex Output
5239fd4e5da5Sopenharmony_ci%_ptr_Input_int = OpTypePointer Input %int
5240fd4e5da5Sopenharmony_ci%gl_VertexIndex = OpVariable %_ptr_Input_int Input
5241fd4e5da5Sopenharmony_ci%int_3 = OpConstant %int 3
5242fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
5243fd4e5da5Sopenharmony_ci%_ptr_Output_uint = OpTypePointer Output %uint
5244fd4e5da5Sopenharmony_ci%index = OpVariable %_ptr_Output_uint Output
5245fd4e5da5Sopenharmony_ci%_arr_uint_uint_1 = OpTypeArray %uint %uint_1
5246fd4e5da5Sopenharmony_ci%foo = OpTypeStruct %_arr_uint_uint_1
5247fd4e5da5Sopenharmony_ci%_ptr_Uniform_foo = OpTypePointer Uniform %foo
5248fd4e5da5Sopenharmony_ci%uniform_index_buffer = OpVariable %_ptr_Uniform_foo Uniform
5249fd4e5da5Sopenharmony_ci%_ptr_Uniform_uint = OpTypePointer Uniform %uint
5250fd4e5da5Sopenharmony_ci)" + kImportStub + R"(
5251fd4e5da5Sopenharmony_ci%main = OpFunction %void None %3
5252fd4e5da5Sopenharmony_ci%5 = OpLabel
5253fd4e5da5Sopenharmony_ci%18 = OpAccessChain %_ptr_Private_v2float %vertices %int_0
5254fd4e5da5Sopenharmony_ciOpStore %18 %16
5255fd4e5da5Sopenharmony_ci%22 = OpAccessChain %_ptr_Private_v2float %vertices %int_1
5256fd4e5da5Sopenharmony_ciOpStore %22 %21
5257fd4e5da5Sopenharmony_ci%26 = OpAccessChain %_ptr_Private_v2float %vertices %int_2
5258fd4e5da5Sopenharmony_ciOpStore %26 %25
5259fd4e5da5Sopenharmony_ci%35 = OpLoad %int %gl_VertexIndex
5260fd4e5da5Sopenharmony_ci%37 = OpSMod %int %35 %int_3
5261fd4e5da5Sopenharmony_ci%38 = OpAccessChain %_ptr_Private_v2float %vertices %37
5262fd4e5da5Sopenharmony_ci%39 = OpLoad %v2float %38
5263fd4e5da5Sopenharmony_ci%40 = OpCompositeExtract %float %39 0
5264fd4e5da5Sopenharmony_ci%41 = OpCompositeExtract %float %39 1
5265fd4e5da5Sopenharmony_ci%42 = OpCompositeConstruct %v4float %40 %41 %float_0 %float_1
5266fd4e5da5Sopenharmony_ci%44 = OpAccessChain %_ptr_Output_v4float %_ %int_0
5267fd4e5da5Sopenharmony_ciOpStore %44 %42
5268fd4e5da5Sopenharmony_ci%52 = OpAccessChain %_ptr_Uniform_uint %uniform_index_buffer %int_0 %int_0
5269fd4e5da5Sopenharmony_ci%53 = OpLoad %uint %52
5270fd4e5da5Sopenharmony_ci;CHECK-NOT: %53 = OpLoad %uint %52
5271fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpIMul %uint %uint_16 %int_0
5272fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpIAdd %uint %uint_0 {{%\w+}}
5273fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_3
5274fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %int %gl_VertexIndex
5275fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpBitcast %uint {{%\w+}}
5276fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %uint %gl_InstanceIndex
5277fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpCompositeConstruct %v4uint %uint_0 {{%\w+}} {{%\w+}} %uint_0
5278fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpFunctionCall %bool %)" + kFuncName + R"( %uint_23 %uint_87 {{%\w+}} %uint_0 %uint_0 %uint_0 {{%\w+}}
5279fd4e5da5Sopenharmony_ci;CHECK: OpSelectionMerge {{%\w+}} None
5280fd4e5da5Sopenharmony_ci;CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
5281fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
5282fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLoad %uint %52
5283fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
5284fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
5285fd4e5da5Sopenharmony_ci;CHECK: OpBranch {{%\w+}}
5286fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpLabel
5287fd4e5da5Sopenharmony_ci;CHECK: [[phi_result:%\w+]] = OpPhi %uint {{%\w+}} {{%\w+}} {{%\w+}} {{%\w+}}
5288fd4e5da5Sopenharmony_ci;CHECK: OpStore %index [[phi_result]]
5289fd4e5da5Sopenharmony_ciOpStore %index %53
5290fd4e5da5Sopenharmony_ci;CHECK-NOT: OpStore %index %53
5291fd4e5da5Sopenharmony_ciOpReturn
5292fd4e5da5Sopenharmony_ci;CHECK: OpReturn
5293fd4e5da5Sopenharmony_ciOpFunctionEnd)";
5294fd4e5da5Sopenharmony_ci  // clang-format on
5295fd4e5da5Sopenharmony_ci
5296fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
5297fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
5298fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 23u);
5299fd4e5da5Sopenharmony_ci}
5300fd4e5da5Sopenharmony_ci
5301fd4e5da5Sopenharmony_ci// TODO(greg-lunarg): Add tests to verify handling of these cases:
5302fd4e5da5Sopenharmony_ci//
5303fd4e5da5Sopenharmony_ci//   Compute shader
5304fd4e5da5Sopenharmony_ci//   Geometry shader
5305fd4e5da5Sopenharmony_ci//   Tessellation control shader
5306fd4e5da5Sopenharmony_ci//   Tessellation eval shader
5307fd4e5da5Sopenharmony_ci//   OpImage
5308fd4e5da5Sopenharmony_ci//   SampledImage variable
5309fd4e5da5Sopenharmony_ci
5310fd4e5da5Sopenharmony_ci}  // namespace
5311fd4e5da5Sopenharmony_ci}  // namespace opt
5312fd4e5da5Sopenharmony_ci}  // namespace spvtools
5313