1fd4e5da5Sopenharmony_ci// Copyright (c) 2017 Google Inc.
2fd4e5da5Sopenharmony_ci//
3fd4e5da5Sopenharmony_ci// Licensed under the Apache License, Version 2.0 (the "License");
4fd4e5da5Sopenharmony_ci// you may not use this file except in compliance with the License.
5fd4e5da5Sopenharmony_ci// You may obtain a copy of the License at
6fd4e5da5Sopenharmony_ci//
7fd4e5da5Sopenharmony_ci//     http://www.apache.org/licenses/LICENSE-2.0
8fd4e5da5Sopenharmony_ci//
9fd4e5da5Sopenharmony_ci// Unless required by applicable law or agreed to in writing, software
10fd4e5da5Sopenharmony_ci// distributed under the License is distributed on an "AS IS" BASIS,
11fd4e5da5Sopenharmony_ci// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12fd4e5da5Sopenharmony_ci// See the License for the specific language governing permissions and
13fd4e5da5Sopenharmony_ci// limitations under the License.
14fd4e5da5Sopenharmony_ci
15fd4e5da5Sopenharmony_ci// Tests validation rules of GLSL.450.std and OpenCL.std extended instructions.
16fd4e5da5Sopenharmony_ci// Doesn't test OpenCL.std vector size 2, 3, 4, 8 or 16 rules (not supported
17fd4e5da5Sopenharmony_ci// by standard SPIR-V).
18fd4e5da5Sopenharmony_ci
19fd4e5da5Sopenharmony_ci#include <sstream>
20fd4e5da5Sopenharmony_ci#include <string>
21fd4e5da5Sopenharmony_ci#include <vector>
22fd4e5da5Sopenharmony_ci
23fd4e5da5Sopenharmony_ci#include "gmock/gmock.h"
24fd4e5da5Sopenharmony_ci#include "test/unit_spirv.h"
25fd4e5da5Sopenharmony_ci#include "test/val/val_fixtures.h"
26fd4e5da5Sopenharmony_ci
27fd4e5da5Sopenharmony_cinamespace spvtools {
28fd4e5da5Sopenharmony_cinamespace val {
29fd4e5da5Sopenharmony_cinamespace {
30fd4e5da5Sopenharmony_ci
31fd4e5da5Sopenharmony_ciusing ::testing::Eq;
32fd4e5da5Sopenharmony_ciusing ::testing::HasSubstr;
33fd4e5da5Sopenharmony_ciusing ::testing::Not;
34fd4e5da5Sopenharmony_ci
35fd4e5da5Sopenharmony_ciusing ValidateOldDebugInfo = spvtest::ValidateBase<std::string>;
36fd4e5da5Sopenharmony_ciusing ValidateOpenCL100DebugInfo = spvtest::ValidateBase<std::string>;
37fd4e5da5Sopenharmony_ciusing ValidateXDebugInfo = spvtest::ValidateBase<std::string>;
38fd4e5da5Sopenharmony_ciusing ValidateLocalDebugInfoOutOfFunction = spvtest::ValidateBase<std::string>;
39fd4e5da5Sopenharmony_ciusing ValidateOpenCL100DebugInfoDebugTypedef =
40fd4e5da5Sopenharmony_ci    spvtest::ValidateBase<std::pair<std::string, std::string>>;
41fd4e5da5Sopenharmony_ciusing ValidateVulkan100DebugInfoDebugTypedef =
42fd4e5da5Sopenharmony_ci    spvtest::ValidateBase<std::pair<std::string, std::string>>;
43fd4e5da5Sopenharmony_ciusing ValidateOpenCL100DebugInfoDebugTypeEnum =
44fd4e5da5Sopenharmony_ci    spvtest::ValidateBase<std::pair<std::string, std::string>>;
45fd4e5da5Sopenharmony_ciusing ValidateVulkan100DebugInfoDebugTypeEnum =
46fd4e5da5Sopenharmony_ci    spvtest::ValidateBase<std::pair<std::string, std::string>>;
47fd4e5da5Sopenharmony_ciusing ValidateOpenCL100DebugInfoDebugTypeComposite =
48fd4e5da5Sopenharmony_ci    spvtest::ValidateBase<std::pair<std::string, std::string>>;
49fd4e5da5Sopenharmony_ciusing ValidateVulkan100DebugInfoDebugTypeComposite =
50fd4e5da5Sopenharmony_ci    spvtest::ValidateBase<std::pair<std::string, std::string>>;
51fd4e5da5Sopenharmony_ciusing ValidateOpenCL100DebugInfoDebugTypeMember =
52fd4e5da5Sopenharmony_ci    spvtest::ValidateBase<std::pair<std::string, std::string>>;
53fd4e5da5Sopenharmony_ciusing ValidateVulkan100DebugInfoDebugTypeMember =
54fd4e5da5Sopenharmony_ci    spvtest::ValidateBase<std::pair<std::string, std::string>>;
55fd4e5da5Sopenharmony_ciusing ValidateOpenCL100DebugInfoDebugTypeInheritance =
56fd4e5da5Sopenharmony_ci    spvtest::ValidateBase<std::pair<std::string, std::string>>;
57fd4e5da5Sopenharmony_ciusing ValidateOpenCL100DebugInfoDebugFunction =
58fd4e5da5Sopenharmony_ci    spvtest::ValidateBase<std::pair<std::string, std::string>>;
59fd4e5da5Sopenharmony_ciusing ValidateVulkan100DebugInfoDebugFunction =
60fd4e5da5Sopenharmony_ci    spvtest::ValidateBase<std::pair<std::string, std::string>>;
61fd4e5da5Sopenharmony_ciusing ValidateOpenCL100DebugInfoDebugFunctionDeclaration =
62fd4e5da5Sopenharmony_ci    spvtest::ValidateBase<std::pair<std::string, std::string>>;
63fd4e5da5Sopenharmony_ciusing ValidateVulkan100DebugInfoDebugFunctionDeclaration =
64fd4e5da5Sopenharmony_ci    spvtest::ValidateBase<std::pair<std::string, std::string>>;
65fd4e5da5Sopenharmony_ciusing ValidateOpenCL100DebugInfoDebugLexicalBlock =
66fd4e5da5Sopenharmony_ci    spvtest::ValidateBase<std::pair<std::string, std::string>>;
67fd4e5da5Sopenharmony_ciusing ValidateVulkan100DebugInfoDebugLexicalBlock =
68fd4e5da5Sopenharmony_ci    spvtest::ValidateBase<std::pair<std::string, std::string>>;
69fd4e5da5Sopenharmony_ciusing ValidateOpenCL100DebugInfoDebugLocalVariable =
70fd4e5da5Sopenharmony_ci    spvtest::ValidateBase<std::pair<std::string, std::string>>;
71fd4e5da5Sopenharmony_ciusing ValidateVulkan100DebugInfoDebugLocalVariable =
72fd4e5da5Sopenharmony_ci    spvtest::ValidateBase<std::pair<std::string, std::string>>;
73fd4e5da5Sopenharmony_ciusing ValidateOpenCL100DebugInfoDebugGlobalVariable =
74fd4e5da5Sopenharmony_ci    spvtest::ValidateBase<std::pair<std::string, std::string>>;
75fd4e5da5Sopenharmony_ciusing ValidateVulkan100DebugInfoDebugGlobalVariable =
76fd4e5da5Sopenharmony_ci    spvtest::ValidateBase<std::pair<std::string, std::string>>;
77fd4e5da5Sopenharmony_ciusing ValidateOpenCL100DebugInfoDebugDeclare =
78fd4e5da5Sopenharmony_ci    spvtest::ValidateBase<std::pair<std::string, std::string>>;
79fd4e5da5Sopenharmony_ciusing ValidateVulkan100DebugInfoDebugDeclare =
80fd4e5da5Sopenharmony_ci    spvtest::ValidateBase<std::pair<std::string, std::string>>;
81fd4e5da5Sopenharmony_ciusing ValidateOpenCL100DebugInfoDebugValue =
82fd4e5da5Sopenharmony_ci    spvtest::ValidateBase<std::pair<std::string, std::string>>;
83fd4e5da5Sopenharmony_ciusing ValidateVulkan100DebugInfoDebugValue =
84fd4e5da5Sopenharmony_ci    spvtest::ValidateBase<std::pair<std::string, std::string>>;
85fd4e5da5Sopenharmony_ciusing ValidateVulkan100DebugInfo = spvtest::ValidateBase<std::string>;
86fd4e5da5Sopenharmony_ci
87fd4e5da5Sopenharmony_cistd::string GenerateShaderCodeForDebugInfo(
88fd4e5da5Sopenharmony_ci    const std::string& op_string_instructions,
89fd4e5da5Sopenharmony_ci    const std::string& op_const_instructions,
90fd4e5da5Sopenharmony_ci    const std::string& debug_instructions_before_main, const std::string& body,
91fd4e5da5Sopenharmony_ci    const std::string& capabilities_and_extensions = "",
92fd4e5da5Sopenharmony_ci    const std::string& execution_model = "Fragment") {
93fd4e5da5Sopenharmony_ci  std::ostringstream ss;
94fd4e5da5Sopenharmony_ci  ss << R"(
95fd4e5da5Sopenharmony_ciOpCapability Shader
96fd4e5da5Sopenharmony_ciOpCapability Float16
97fd4e5da5Sopenharmony_ciOpCapability Float64
98fd4e5da5Sopenharmony_ciOpCapability Int16
99fd4e5da5Sopenharmony_ciOpCapability Int64
100fd4e5da5Sopenharmony_ci)";
101fd4e5da5Sopenharmony_ci
102fd4e5da5Sopenharmony_ci  ss << capabilities_and_extensions;
103fd4e5da5Sopenharmony_ci  ss << "%extinst = OpExtInstImport \"GLSL.std.450\"\n";
104fd4e5da5Sopenharmony_ci  ss << "OpMemoryModel Logical GLSL450\n";
105fd4e5da5Sopenharmony_ci  ss << "OpEntryPoint " << execution_model << " %main \"main\""
106fd4e5da5Sopenharmony_ci     << " %f32_output"
107fd4e5da5Sopenharmony_ci     << " %f32vec2_output"
108fd4e5da5Sopenharmony_ci     << " %u32_output"
109fd4e5da5Sopenharmony_ci     << " %u32vec2_output"
110fd4e5da5Sopenharmony_ci     << " %u64_output"
111fd4e5da5Sopenharmony_ci     << " %f32_input"
112fd4e5da5Sopenharmony_ci     << " %f32vec2_input"
113fd4e5da5Sopenharmony_ci     << " %u32_input"
114fd4e5da5Sopenharmony_ci     << " %u32vec2_input"
115fd4e5da5Sopenharmony_ci     << " %u64_input"
116fd4e5da5Sopenharmony_ci     << "\n";
117fd4e5da5Sopenharmony_ci  if (execution_model == "Fragment") {
118fd4e5da5Sopenharmony_ci    ss << "OpExecutionMode %main OriginUpperLeft\n";
119fd4e5da5Sopenharmony_ci  }
120fd4e5da5Sopenharmony_ci
121fd4e5da5Sopenharmony_ci  ss << op_string_instructions;
122fd4e5da5Sopenharmony_ci
123fd4e5da5Sopenharmony_ci  ss << R"(
124fd4e5da5Sopenharmony_ci%void = OpTypeVoid
125fd4e5da5Sopenharmony_ci%func = OpTypeFunction %void
126fd4e5da5Sopenharmony_ci%bool = OpTypeBool
127fd4e5da5Sopenharmony_ci%f16 = OpTypeFloat 16
128fd4e5da5Sopenharmony_ci%f32 = OpTypeFloat 32
129fd4e5da5Sopenharmony_ci%f64 = OpTypeFloat 64
130fd4e5da5Sopenharmony_ci%u32 = OpTypeInt 32 0
131fd4e5da5Sopenharmony_ci%s32 = OpTypeInt 32 1
132fd4e5da5Sopenharmony_ci%u64 = OpTypeInt 64 0
133fd4e5da5Sopenharmony_ci%s64 = OpTypeInt 64 1
134fd4e5da5Sopenharmony_ci%u16 = OpTypeInt 16 0
135fd4e5da5Sopenharmony_ci%s16 = OpTypeInt 16 1
136fd4e5da5Sopenharmony_ci%f32vec2 = OpTypeVector %f32 2
137fd4e5da5Sopenharmony_ci%f32vec3 = OpTypeVector %f32 3
138fd4e5da5Sopenharmony_ci%f32vec4 = OpTypeVector %f32 4
139fd4e5da5Sopenharmony_ci%f64vec2 = OpTypeVector %f64 2
140fd4e5da5Sopenharmony_ci%f64vec3 = OpTypeVector %f64 3
141fd4e5da5Sopenharmony_ci%f64vec4 = OpTypeVector %f64 4
142fd4e5da5Sopenharmony_ci%u32vec2 = OpTypeVector %u32 2
143fd4e5da5Sopenharmony_ci%u32vec3 = OpTypeVector %u32 3
144fd4e5da5Sopenharmony_ci%s32vec2 = OpTypeVector %s32 2
145fd4e5da5Sopenharmony_ci%u32vec4 = OpTypeVector %u32 4
146fd4e5da5Sopenharmony_ci%s32vec4 = OpTypeVector %s32 4
147fd4e5da5Sopenharmony_ci%u64vec2 = OpTypeVector %u64 2
148fd4e5da5Sopenharmony_ci%s64vec2 = OpTypeVector %s64 2
149fd4e5da5Sopenharmony_ci%f64mat22 = OpTypeMatrix %f64vec2 2
150fd4e5da5Sopenharmony_ci%f32mat22 = OpTypeMatrix %f32vec2 2
151fd4e5da5Sopenharmony_ci%f32mat23 = OpTypeMatrix %f32vec2 3
152fd4e5da5Sopenharmony_ci%f32mat32 = OpTypeMatrix %f32vec3 2
153fd4e5da5Sopenharmony_ci%f32mat33 = OpTypeMatrix %f32vec3 3
154fd4e5da5Sopenharmony_ci
155fd4e5da5Sopenharmony_ci%f32_0 = OpConstant %f32 0
156fd4e5da5Sopenharmony_ci%f32_1 = OpConstant %f32 1
157fd4e5da5Sopenharmony_ci%f32_2 = OpConstant %f32 2
158fd4e5da5Sopenharmony_ci%f32_3 = OpConstant %f32 3
159fd4e5da5Sopenharmony_ci%f32_4 = OpConstant %f32 4
160fd4e5da5Sopenharmony_ci%f32_h = OpConstant %f32 0.5
161fd4e5da5Sopenharmony_ci%f32vec2_01 = OpConstantComposite %f32vec2 %f32_0 %f32_1
162fd4e5da5Sopenharmony_ci%f32vec2_12 = OpConstantComposite %f32vec2 %f32_1 %f32_2
163fd4e5da5Sopenharmony_ci%f32vec3_012 = OpConstantComposite %f32vec3 %f32_0 %f32_1 %f32_2
164fd4e5da5Sopenharmony_ci%f32vec3_123 = OpConstantComposite %f32vec3 %f32_1 %f32_2 %f32_3
165fd4e5da5Sopenharmony_ci%f32vec4_0123 = OpConstantComposite %f32vec4 %f32_0 %f32_1 %f32_2 %f32_3
166fd4e5da5Sopenharmony_ci%f32vec4_1234 = OpConstantComposite %f32vec4 %f32_1 %f32_2 %f32_3 %f32_4
167fd4e5da5Sopenharmony_ci
168fd4e5da5Sopenharmony_ci%f64_0 = OpConstant %f64 0
169fd4e5da5Sopenharmony_ci%f64_1 = OpConstant %f64 1
170fd4e5da5Sopenharmony_ci%f64_2 = OpConstant %f64 2
171fd4e5da5Sopenharmony_ci%f64_3 = OpConstant %f64 3
172fd4e5da5Sopenharmony_ci%f64vec2_01 = OpConstantComposite %f64vec2 %f64_0 %f64_1
173fd4e5da5Sopenharmony_ci%f64vec3_012 = OpConstantComposite %f64vec3 %f64_0 %f64_1 %f64_2
174fd4e5da5Sopenharmony_ci%f64vec4_0123 = OpConstantComposite %f64vec4 %f64_0 %f64_1 %f64_2 %f64_3
175fd4e5da5Sopenharmony_ci
176fd4e5da5Sopenharmony_ci%f16_0 = OpConstant %f16 0
177fd4e5da5Sopenharmony_ci%f16_1 = OpConstant %f16 1
178fd4e5da5Sopenharmony_ci%f16_h = OpConstant %f16 0.5
179fd4e5da5Sopenharmony_ci
180fd4e5da5Sopenharmony_ci%u32_0 = OpConstant %u32 0
181fd4e5da5Sopenharmony_ci%u32_1 = OpConstant %u32 1
182fd4e5da5Sopenharmony_ci%u32_2 = OpConstant %u32 2
183fd4e5da5Sopenharmony_ci%u32_3 = OpConstant %u32 3
184fd4e5da5Sopenharmony_ci
185fd4e5da5Sopenharmony_ci%s32_0 = OpConstant %s32 0
186fd4e5da5Sopenharmony_ci%s32_1 = OpConstant %s32 1
187fd4e5da5Sopenharmony_ci%s32_2 = OpConstant %s32 2
188fd4e5da5Sopenharmony_ci%s32_3 = OpConstant %s32 3
189fd4e5da5Sopenharmony_ci
190fd4e5da5Sopenharmony_ci%u64_0 = OpConstant %u64 0
191fd4e5da5Sopenharmony_ci%u64_1 = OpConstant %u64 1
192fd4e5da5Sopenharmony_ci%u64_2 = OpConstant %u64 2
193fd4e5da5Sopenharmony_ci%u64_3 = OpConstant %u64 3
194fd4e5da5Sopenharmony_ci
195fd4e5da5Sopenharmony_ci%s64_0 = OpConstant %s64 0
196fd4e5da5Sopenharmony_ci%s64_1 = OpConstant %s64 1
197fd4e5da5Sopenharmony_ci%s64_2 = OpConstant %s64 2
198fd4e5da5Sopenharmony_ci%s64_3 = OpConstant %s64 3
199fd4e5da5Sopenharmony_ci)";
200fd4e5da5Sopenharmony_ci
201fd4e5da5Sopenharmony_ci  ss << op_const_instructions;
202fd4e5da5Sopenharmony_ci
203fd4e5da5Sopenharmony_ci  ss << R"(
204fd4e5da5Sopenharmony_ci%s32vec2_01 = OpConstantComposite %s32vec2 %s32_0 %s32_1
205fd4e5da5Sopenharmony_ci%u32vec2_01 = OpConstantComposite %u32vec2 %u32_0 %u32_1
206fd4e5da5Sopenharmony_ci
207fd4e5da5Sopenharmony_ci%s32vec2_12 = OpConstantComposite %s32vec2 %s32_1 %s32_2
208fd4e5da5Sopenharmony_ci%u32vec2_12 = OpConstantComposite %u32vec2 %u32_1 %u32_2
209fd4e5da5Sopenharmony_ci
210fd4e5da5Sopenharmony_ci%s32vec4_0123 = OpConstantComposite %s32vec4 %s32_0 %s32_1 %s32_2 %s32_3
211fd4e5da5Sopenharmony_ci%u32vec4_0123 = OpConstantComposite %u32vec4 %u32_0 %u32_1 %u32_2 %u32_3
212fd4e5da5Sopenharmony_ci
213fd4e5da5Sopenharmony_ci%s64vec2_01 = OpConstantComposite %s64vec2 %s64_0 %s64_1
214fd4e5da5Sopenharmony_ci%u64vec2_01 = OpConstantComposite %u64vec2 %u64_0 %u64_1
215fd4e5da5Sopenharmony_ci
216fd4e5da5Sopenharmony_ci%f32mat22_1212 = OpConstantComposite %f32mat22 %f32vec2_12 %f32vec2_12
217fd4e5da5Sopenharmony_ci%f32mat23_121212 = OpConstantComposite %f32mat23 %f32vec2_12 %f32vec2_12 %f32vec2_12
218fd4e5da5Sopenharmony_ci
219fd4e5da5Sopenharmony_ci%f32_ptr_output = OpTypePointer Output %f32
220fd4e5da5Sopenharmony_ci%f32vec2_ptr_output = OpTypePointer Output %f32vec2
221fd4e5da5Sopenharmony_ci
222fd4e5da5Sopenharmony_ci%u32_ptr_output = OpTypePointer Output %u32
223fd4e5da5Sopenharmony_ci%u32vec2_ptr_output = OpTypePointer Output %u32vec2
224fd4e5da5Sopenharmony_ci
225fd4e5da5Sopenharmony_ci%u64_ptr_output = OpTypePointer Output %u64
226fd4e5da5Sopenharmony_ci
227fd4e5da5Sopenharmony_ci%f32_output = OpVariable %f32_ptr_output Output
228fd4e5da5Sopenharmony_ci%f32vec2_output = OpVariable %f32vec2_ptr_output Output
229fd4e5da5Sopenharmony_ci
230fd4e5da5Sopenharmony_ci%u32_output = OpVariable %u32_ptr_output Output
231fd4e5da5Sopenharmony_ci%u32vec2_output = OpVariable %u32vec2_ptr_output Output
232fd4e5da5Sopenharmony_ci
233fd4e5da5Sopenharmony_ci%u64_output = OpVariable %u64_ptr_output Output
234fd4e5da5Sopenharmony_ci
235fd4e5da5Sopenharmony_ci%f32_ptr_input = OpTypePointer Input %f32
236fd4e5da5Sopenharmony_ci%f32vec2_ptr_input = OpTypePointer Input %f32vec2
237fd4e5da5Sopenharmony_ci
238fd4e5da5Sopenharmony_ci%u32_ptr_input = OpTypePointer Input %u32
239fd4e5da5Sopenharmony_ci%u32vec2_ptr_input = OpTypePointer Input %u32vec2
240fd4e5da5Sopenharmony_ci
241fd4e5da5Sopenharmony_ci%u64_ptr_input = OpTypePointer Input %u64
242fd4e5da5Sopenharmony_ci
243fd4e5da5Sopenharmony_ci%f32_ptr_function = OpTypePointer Function %f32
244fd4e5da5Sopenharmony_ci
245fd4e5da5Sopenharmony_ci%f32_input = OpVariable %f32_ptr_input Input
246fd4e5da5Sopenharmony_ci%f32vec2_input = OpVariable %f32vec2_ptr_input Input
247fd4e5da5Sopenharmony_ci
248fd4e5da5Sopenharmony_ci%u32_input = OpVariable %u32_ptr_input Input
249fd4e5da5Sopenharmony_ci%u32vec2_input = OpVariable %u32vec2_ptr_input Input
250fd4e5da5Sopenharmony_ci
251fd4e5da5Sopenharmony_ci%u64_input = OpVariable %u64_ptr_input Input
252fd4e5da5Sopenharmony_ci
253fd4e5da5Sopenharmony_ci%u32_ptr_function = OpTypePointer Function %u32
254fd4e5da5Sopenharmony_ci
255fd4e5da5Sopenharmony_ci%struct_f16_u16 = OpTypeStruct %f16 %u16
256fd4e5da5Sopenharmony_ci%struct_f32_f32 = OpTypeStruct %f32 %f32
257fd4e5da5Sopenharmony_ci%struct_f32_f32_f32 = OpTypeStruct %f32 %f32 %f32
258fd4e5da5Sopenharmony_ci%struct_f32_u32 = OpTypeStruct %f32 %u32
259fd4e5da5Sopenharmony_ci%struct_f32_u32_f32 = OpTypeStruct %f32 %u32 %f32
260fd4e5da5Sopenharmony_ci%struct_u32_f32 = OpTypeStruct %u32 %f32
261fd4e5da5Sopenharmony_ci%struct_u32_u32 = OpTypeStruct %u32 %u32
262fd4e5da5Sopenharmony_ci%struct_f32_f64 = OpTypeStruct %f32 %f64
263fd4e5da5Sopenharmony_ci%struct_f32vec2_f32vec2 = OpTypeStruct %f32vec2 %f32vec2
264fd4e5da5Sopenharmony_ci%struct_f32vec2_u32vec2 = OpTypeStruct %f32vec2 %u32vec2
265fd4e5da5Sopenharmony_ci)";
266fd4e5da5Sopenharmony_ci
267fd4e5da5Sopenharmony_ci  ss << debug_instructions_before_main;
268fd4e5da5Sopenharmony_ci
269fd4e5da5Sopenharmony_ci  ss << R"(
270fd4e5da5Sopenharmony_ci%main = OpFunction %void None %func
271fd4e5da5Sopenharmony_ci%main_entry = OpLabel
272fd4e5da5Sopenharmony_ci)";
273fd4e5da5Sopenharmony_ci
274fd4e5da5Sopenharmony_ci  ss << body;
275fd4e5da5Sopenharmony_ci
276fd4e5da5Sopenharmony_ci  ss << R"(
277fd4e5da5Sopenharmony_ciOpReturn
278fd4e5da5Sopenharmony_ciOpFunctionEnd)";
279fd4e5da5Sopenharmony_ci
280fd4e5da5Sopenharmony_ci  return ss.str();
281fd4e5da5Sopenharmony_ci}
282fd4e5da5Sopenharmony_ci
283fd4e5da5Sopenharmony_ciTEST_F(ValidateOldDebugInfo, UseDebugInstructionOutOfFunction) {
284fd4e5da5Sopenharmony_ci  const std::string src = R"(
285fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
286fd4e5da5Sopenharmony_ci)";
287fd4e5da5Sopenharmony_ci
288fd4e5da5Sopenharmony_ci  const std::string dbg_inst = R"(
289fd4e5da5Sopenharmony_ci%cu = OpExtInst %void %DbgExt DebugCompilationUnit %code 1 1
290fd4e5da5Sopenharmony_ci)";
291fd4e5da5Sopenharmony_ci
292fd4e5da5Sopenharmony_ci  const std::string extension = R"(
293fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "DebugInfo"
294fd4e5da5Sopenharmony_ci)";
295fd4e5da5Sopenharmony_ci
296fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", dbg_inst, "",
297fd4e5da5Sopenharmony_ci                                                     extension, "Vertex"));
298fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
299fd4e5da5Sopenharmony_ci}
300fd4e5da5Sopenharmony_ci
301fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, UseDebugInstructionOutOfFunction) {
302fd4e5da5Sopenharmony_ci  const std::string src = R"(
303fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
304fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
305fd4e5da5Sopenharmony_ci)";
306fd4e5da5Sopenharmony_ci
307fd4e5da5Sopenharmony_ci  const std::string dbg_inst = R"(
308fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
309fd4e5da5Sopenharmony_ci)";
310fd4e5da5Sopenharmony_ci
311fd4e5da5Sopenharmony_ci  const std::string extension = R"(
312fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
313fd4e5da5Sopenharmony_ci)";
314fd4e5da5Sopenharmony_ci
315fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", dbg_inst, "",
316fd4e5da5Sopenharmony_ci                                                     extension, "Vertex"));
317fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
318fd4e5da5Sopenharmony_ci}
319fd4e5da5Sopenharmony_ci
320fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugSourceInFunction) {
321fd4e5da5Sopenharmony_ci  const std::string src = R"(
322fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
323fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
324fd4e5da5Sopenharmony_ci)";
325fd4e5da5Sopenharmony_ci
326fd4e5da5Sopenharmony_ci  const std::string dbg_inst = R"(
327fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
328fd4e5da5Sopenharmony_ci)";
329fd4e5da5Sopenharmony_ci
330fd4e5da5Sopenharmony_ci  const std::string extension = R"(
331fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
332fd4e5da5Sopenharmony_ci)";
333fd4e5da5Sopenharmony_ci
334fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", "", dbg_inst,
335fd4e5da5Sopenharmony_ci                                                     extension, "Vertex"));
336fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_LAYOUT, ValidateInstructions());
337fd4e5da5Sopenharmony_ci  EXPECT_THAT(
338fd4e5da5Sopenharmony_ci      getDiagnosticString(),
339fd4e5da5Sopenharmony_ci      HasSubstr("Debug info extension instructions other than DebugScope, "
340fd4e5da5Sopenharmony_ci                "DebugNoScope, DebugDeclare, DebugValue must appear between "
341fd4e5da5Sopenharmony_ci                "section 9 (types, constants, global variables) and section 10 "
342fd4e5da5Sopenharmony_ci                "(function declarations)"));
343fd4e5da5Sopenharmony_ci}
344fd4e5da5Sopenharmony_ci
345fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugSourceInFunction) {
346fd4e5da5Sopenharmony_ci  const std::string src = R"(
347fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
348fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
349fd4e5da5Sopenharmony_ci)";
350fd4e5da5Sopenharmony_ci
351fd4e5da5Sopenharmony_ci  const std::string dbg_inst = R"(
352fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
353fd4e5da5Sopenharmony_ci)";
354fd4e5da5Sopenharmony_ci
355fd4e5da5Sopenharmony_ci  const std::string extension = R"(
356fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
357fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
358fd4e5da5Sopenharmony_ci)";
359fd4e5da5Sopenharmony_ci
360fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", "", dbg_inst,
361fd4e5da5Sopenharmony_ci                                                     extension, "Vertex"));
362fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_LAYOUT, ValidateInstructions());
363fd4e5da5Sopenharmony_ci  EXPECT_THAT(
364fd4e5da5Sopenharmony_ci      getDiagnosticString(),
365fd4e5da5Sopenharmony_ci      HasSubstr("Debug info extension instructions other than DebugScope, "
366fd4e5da5Sopenharmony_ci                "DebugNoScope, DebugDeclare, DebugValue must appear between "
367fd4e5da5Sopenharmony_ci                "section 9 (types, constants, global variables) and section 10 "
368fd4e5da5Sopenharmony_ci                "(function declarations)"));
369fd4e5da5Sopenharmony_ci}
370fd4e5da5Sopenharmony_ci
371fd4e5da5Sopenharmony_ciTEST_P(ValidateLocalDebugInfoOutOfFunction, OpenCLDebugInfo100DebugScope) {
372fd4e5da5Sopenharmony_ci  const std::string src = R"(
373fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
374fd4e5da5Sopenharmony_ci%code = OpString "void main() {}"
375fd4e5da5Sopenharmony_ci%void_name = OpString "void"
376fd4e5da5Sopenharmony_ci%main_name = OpString "main"
377fd4e5da5Sopenharmony_ci%main_linkage_name = OpString "v_main"
378fd4e5da5Sopenharmony_ci%int_name = OpString "int"
379fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
380fd4e5da5Sopenharmony_ci)";
381fd4e5da5Sopenharmony_ci
382fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
383fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
384fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
385fd4e5da5Sopenharmony_ci%int_info = OpExtInst %void %DbgExt DebugTypeBasic %int_name %u32_0 Signed
386fd4e5da5Sopenharmony_ci%main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void
387fd4e5da5Sopenharmony_ci%main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 1 1 %comp_unit %main_linkage_name FlagIsPublic 1 %main
388fd4e5da5Sopenharmony_ci%foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %int_info %dbg_src 1 1 %main_info FlagIsLocal
389fd4e5da5Sopenharmony_ci%expr = OpExtInst %void %DbgExt DebugExpression
390fd4e5da5Sopenharmony_ci)";
391fd4e5da5Sopenharmony_ci
392fd4e5da5Sopenharmony_ci  const std::string body = R"(
393fd4e5da5Sopenharmony_ci%foo = OpVariable %u32_ptr_function Function
394fd4e5da5Sopenharmony_ci%foo_val = OpLoad %u32 %foo
395fd4e5da5Sopenharmony_ci)";
396fd4e5da5Sopenharmony_ci
397fd4e5da5Sopenharmony_ci  const std::string extension = R"(
398fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
399fd4e5da5Sopenharmony_ci)";
400fd4e5da5Sopenharmony_ci
401fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
402fd4e5da5Sopenharmony_ci      src, "", dbg_inst_header + GetParam(), body, extension, "Vertex"));
403fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_LAYOUT, ValidateInstructions());
404fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
405fd4e5da5Sopenharmony_ci              HasSubstr("DebugScope, DebugNoScope, DebugDeclare, DebugValue "
406fd4e5da5Sopenharmony_ci                        "of debug info extension must appear in a function "
407fd4e5da5Sopenharmony_ci                        "body"));
408fd4e5da5Sopenharmony_ci}
409fd4e5da5Sopenharmony_ci
410fd4e5da5Sopenharmony_ciTEST_P(ValidateLocalDebugInfoOutOfFunction, VulkanDebugInfo100DebugScope) {
411fd4e5da5Sopenharmony_ci  const std::string src = R"(
412fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
413fd4e5da5Sopenharmony_ci%code = OpString "void main() {}"
414fd4e5da5Sopenharmony_ci%void_name = OpString "void"
415fd4e5da5Sopenharmony_ci%main_name = OpString "main"
416fd4e5da5Sopenharmony_ci%main_linkage_name = OpString "v_main"
417fd4e5da5Sopenharmony_ci%int_name = OpString "int"
418fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
419fd4e5da5Sopenharmony_ci)";
420fd4e5da5Sopenharmony_ci
421fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
422fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
423fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
424fd4e5da5Sopenharmony_ci%int_info = OpExtInst %void %DbgExt DebugTypeBasic %int_name %u32_0 %u32_1 %u32_0
425fd4e5da5Sopenharmony_ci%main_type_info = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %void
426fd4e5da5Sopenharmony_ci%main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src %u32_1 %u32_1 %comp_unit %main_linkage_name %u32_3 %u32_1
427fd4e5da5Sopenharmony_ci%foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %int_info %dbg_src %u32_1 %u32_1 %main_info %u32_4
428fd4e5da5Sopenharmony_ci%expr = OpExtInst %void %DbgExt DebugExpression
429fd4e5da5Sopenharmony_ci)";
430fd4e5da5Sopenharmony_ci
431fd4e5da5Sopenharmony_ci  const std::string body = R"(
432fd4e5da5Sopenharmony_ci%foo = OpVariable %u32_ptr_function Function
433fd4e5da5Sopenharmony_ci%main_def = OpExtInst %void %DbgExt DebugFunctionDefinition %main_info %main
434fd4e5da5Sopenharmony_ci%foo_val = OpLoad %u32 %foo
435fd4e5da5Sopenharmony_ci)";
436fd4e5da5Sopenharmony_ci
437fd4e5da5Sopenharmony_ci  const std::string extension = R"(
438fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
439fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
440fd4e5da5Sopenharmony_ci)";
441fd4e5da5Sopenharmony_ci
442fd4e5da5Sopenharmony_ci  const std::string constants = R"(
443fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
444fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
445fd4e5da5Sopenharmony_ci)";
446fd4e5da5Sopenharmony_ci
447fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
448fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header + GetParam(), body, extension, "Vertex"));
449fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_LAYOUT, ValidateInstructions());
450fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
451fd4e5da5Sopenharmony_ci              HasSubstr("DebugScope, DebugNoScope, DebugDeclare, DebugValue "
452fd4e5da5Sopenharmony_ci                        "of debug info extension must appear in a function "
453fd4e5da5Sopenharmony_ci                        "body"));
454fd4e5da5Sopenharmony_ci}
455fd4e5da5Sopenharmony_ci
456fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(
457fd4e5da5Sopenharmony_ci    AllLocalDebugInfo, ValidateLocalDebugInfoOutOfFunction,
458fd4e5da5Sopenharmony_ci    ::testing::ValuesIn(std::vector<std::string>{
459fd4e5da5Sopenharmony_ci        "%main_scope = OpExtInst %void %DbgExt DebugScope %main_info",
460fd4e5da5Sopenharmony_ci        "%no_scope = OpExtInst %void %DbgExt DebugNoScope",
461fd4e5da5Sopenharmony_ci    }));
462fd4e5da5Sopenharmony_ci
463fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugFunctionForwardReference) {
464fd4e5da5Sopenharmony_ci  const std::string src = R"(
465fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
466fd4e5da5Sopenharmony_ci%code = OpString "void main() {}"
467fd4e5da5Sopenharmony_ci%void_name = OpString "void"
468fd4e5da5Sopenharmony_ci%main_name = OpString "main"
469fd4e5da5Sopenharmony_ci%main_linkage_name = OpString "v_main"
470fd4e5da5Sopenharmony_ci)";
471fd4e5da5Sopenharmony_ci
472fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
473fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
474fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
475fd4e5da5Sopenharmony_ci%main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void
476fd4e5da5Sopenharmony_ci%main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 1 1 %comp_unit %main_linkage_name FlagIsPublic 1 %main
477fd4e5da5Sopenharmony_ci)";
478fd4e5da5Sopenharmony_ci
479fd4e5da5Sopenharmony_ci  const std::string body = R"(
480fd4e5da5Sopenharmony_ci%main_scope = OpExtInst %void %DbgExt DebugScope %main_info
481fd4e5da5Sopenharmony_ci)";
482fd4e5da5Sopenharmony_ci
483fd4e5da5Sopenharmony_ci  const std::string extension = R"(
484fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
485fd4e5da5Sopenharmony_ci)";
486fd4e5da5Sopenharmony_ci
487fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
488fd4e5da5Sopenharmony_ci      src, "", dbg_inst_header, body, extension, "Vertex"));
489fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
490fd4e5da5Sopenharmony_ci}
491fd4e5da5Sopenharmony_ci
492fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugFunctionMissingOpFunction) {
493fd4e5da5Sopenharmony_ci  const std::string src = R"(
494fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
495fd4e5da5Sopenharmony_ci%code = OpString "void main() {}"
496fd4e5da5Sopenharmony_ci%void_name = OpString "void"
497fd4e5da5Sopenharmony_ci%main_name = OpString "main"
498fd4e5da5Sopenharmony_ci%main_linkage_name = OpString "v_main"
499fd4e5da5Sopenharmony_ci)";
500fd4e5da5Sopenharmony_ci
501fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
502fd4e5da5Sopenharmony_ci%dbgNone = OpExtInst %void %DbgExt DebugInfoNone
503fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
504fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
505fd4e5da5Sopenharmony_ci%main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void
506fd4e5da5Sopenharmony_ci%main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 1 1 %comp_unit %main_linkage_name FlagIsPublic 1 %dbgNone
507fd4e5da5Sopenharmony_ci)";
508fd4e5da5Sopenharmony_ci
509fd4e5da5Sopenharmony_ci  const std::string body = R"(
510fd4e5da5Sopenharmony_ci%main_scope = OpExtInst %void %DbgExt DebugScope %main_info
511fd4e5da5Sopenharmony_ci)";
512fd4e5da5Sopenharmony_ci
513fd4e5da5Sopenharmony_ci  const std::string extension = R"(
514fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
515fd4e5da5Sopenharmony_ci)";
516fd4e5da5Sopenharmony_ci
517fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
518fd4e5da5Sopenharmony_ci      src, "", dbg_inst_header, body, extension, "Vertex"));
519fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
520fd4e5da5Sopenharmony_ci}
521fd4e5da5Sopenharmony_ci
522fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugScopeBeforeOpVariableInFunction) {
523fd4e5da5Sopenharmony_ci  const std::string src = R"(
524fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
525fd4e5da5Sopenharmony_ci%code = OpString "float4 main(float arg) {
526fd4e5da5Sopenharmony_ci  float foo;
527fd4e5da5Sopenharmony_ci  return float4(0, 0, 0, 0);
528fd4e5da5Sopenharmony_ci}
529fd4e5da5Sopenharmony_ci"
530fd4e5da5Sopenharmony_ci%float_name = OpString "float"
531fd4e5da5Sopenharmony_ci%main_name = OpString "main"
532fd4e5da5Sopenharmony_ci%main_linkage_name = OpString "v4f_main_f"
533fd4e5da5Sopenharmony_ci)";
534fd4e5da5Sopenharmony_ci
535fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
536fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
537fd4e5da5Sopenharmony_ci)";
538fd4e5da5Sopenharmony_ci
539fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
540fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
541fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
542fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
543fd4e5da5Sopenharmony_ci%v4float_info = OpExtInst %void %DbgExt DebugTypeVector %float_info 4
544fd4e5da5Sopenharmony_ci%main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %v4float_info %float_info
545fd4e5da5Sopenharmony_ci%main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 12 1 %comp_unit %main_linkage_name FlagIsPublic 13 %main
546fd4e5da5Sopenharmony_ci)";
547fd4e5da5Sopenharmony_ci
548fd4e5da5Sopenharmony_ci  const std::string body = R"(
549fd4e5da5Sopenharmony_ci%main_scope = OpExtInst %void %DbgExt DebugScope %main_info
550fd4e5da5Sopenharmony_ci%foo = OpVariable %f32_ptr_function Function
551fd4e5da5Sopenharmony_ci)";
552fd4e5da5Sopenharmony_ci
553fd4e5da5Sopenharmony_ci  const std::string extension = R"(
554fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
555fd4e5da5Sopenharmony_ci)";
556fd4e5da5Sopenharmony_ci
557fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
558fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, body, extension, "Vertex"));
559fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
560fd4e5da5Sopenharmony_ci}
561fd4e5da5Sopenharmony_ci
562fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugTypeCompositeSizeDebugInfoNone) {
563fd4e5da5Sopenharmony_ci  const std::string src = R"(
564fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
565fd4e5da5Sopenharmony_ci%code = OpString "OpaqueType foo;
566fd4e5da5Sopenharmony_cimain() {}
567fd4e5da5Sopenharmony_ci"
568fd4e5da5Sopenharmony_ci%ty_name = OpString "struct VS_OUTPUT"
569fd4e5da5Sopenharmony_ci)";
570fd4e5da5Sopenharmony_ci
571fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
572fd4e5da5Sopenharmony_ci%dbg_none = OpExtInst %void %DbgExt DebugInfoNone
573fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
574fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
575fd4e5da5Sopenharmony_ci%opaque = OpExtInst %void %DbgExt DebugTypeComposite %ty_name Class %dbg_src 1 1 %comp_unit %ty_name %dbg_none FlagIsPublic
576fd4e5da5Sopenharmony_ci)";
577fd4e5da5Sopenharmony_ci
578fd4e5da5Sopenharmony_ci  const std::string extension = R"(
579fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
580fd4e5da5Sopenharmony_ci)";
581fd4e5da5Sopenharmony_ci
582fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", dbg_inst_header,
583fd4e5da5Sopenharmony_ci                                                     "", extension, "Vertex"));
584fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
585fd4e5da5Sopenharmony_ci}
586fd4e5da5Sopenharmony_ci
587fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugTypeCompositeForwardReference) {
588fd4e5da5Sopenharmony_ci  const std::string src = R"(
589fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
590fd4e5da5Sopenharmony_ci%code = OpString "struct VS_OUTPUT {
591fd4e5da5Sopenharmony_ci  float4 pos : SV_POSITION;
592fd4e5da5Sopenharmony_ci  float4 color : COLOR;
593fd4e5da5Sopenharmony_ci};
594fd4e5da5Sopenharmony_cimain() {}
595fd4e5da5Sopenharmony_ci"
596fd4e5da5Sopenharmony_ci%VS_OUTPUT_name = OpString "struct VS_OUTPUT"
597fd4e5da5Sopenharmony_ci%float_name = OpString "float"
598fd4e5da5Sopenharmony_ci%VS_OUTPUT_pos_name = OpString "pos : SV_POSITION"
599fd4e5da5Sopenharmony_ci%VS_OUTPUT_color_name = OpString "color : COLOR"
600fd4e5da5Sopenharmony_ci%VS_OUTPUT_linkage_name = OpString "VS_OUTPUT"
601fd4e5da5Sopenharmony_ci)";
602fd4e5da5Sopenharmony_ci
603fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
604fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
605fd4e5da5Sopenharmony_ci%int_128 = OpConstant %u32 128
606fd4e5da5Sopenharmony_ci)";
607fd4e5da5Sopenharmony_ci
608fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
609fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
610fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
611fd4e5da5Sopenharmony_ci%VS_OUTPUT_info = OpExtInst %void %DbgExt DebugTypeComposite %VS_OUTPUT_name Structure %dbg_src 1 1 %comp_unit %VS_OUTPUT_linkage_name %int_128 FlagIsPublic %VS_OUTPUT_pos_info %VS_OUTPUT_color_info
612fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
613fd4e5da5Sopenharmony_ci%v4float_info = OpExtInst %void %DbgExt DebugTypeVector %float_info 4
614fd4e5da5Sopenharmony_ci%VS_OUTPUT_pos_info = OpExtInst %void %DbgExt DebugTypeMember %VS_OUTPUT_pos_name %v4float_info %dbg_src 2 3 %VS_OUTPUT_info %u32_0 %int_128 FlagIsPublic
615fd4e5da5Sopenharmony_ci%VS_OUTPUT_color_info = OpExtInst %void %DbgExt DebugTypeMember %VS_OUTPUT_color_name %v4float_info %dbg_src 3 3 %VS_OUTPUT_info %int_128 %int_128 FlagIsPublic
616fd4e5da5Sopenharmony_ci)";
617fd4e5da5Sopenharmony_ci
618fd4e5da5Sopenharmony_ci  const std::string extension = R"(
619fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
620fd4e5da5Sopenharmony_ci)";
621fd4e5da5Sopenharmony_ci
622fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
623fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, "", extension, "Vertex"));
624fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
625fd4e5da5Sopenharmony_ci}
626fd4e5da5Sopenharmony_ci
627fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugTypeCompositeMissingReference) {
628fd4e5da5Sopenharmony_ci  const std::string src = R"(
629fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
630fd4e5da5Sopenharmony_ci%code = OpString "struct VS_OUTPUT {
631fd4e5da5Sopenharmony_ci  float4 pos : SV_POSITION;
632fd4e5da5Sopenharmony_ci  float4 color : COLOR;
633fd4e5da5Sopenharmony_ci};
634fd4e5da5Sopenharmony_cimain() {}
635fd4e5da5Sopenharmony_ci"
636fd4e5da5Sopenharmony_ci%VS_OUTPUT_name = OpString "struct VS_OUTPUT"
637fd4e5da5Sopenharmony_ci%float_name = OpString "float"
638fd4e5da5Sopenharmony_ci%VS_OUTPUT_pos_name = OpString "pos : SV_POSITION"
639fd4e5da5Sopenharmony_ci%VS_OUTPUT_color_name = OpString "color : COLOR"
640fd4e5da5Sopenharmony_ci%VS_OUTPUT_linkage_name = OpString "VS_OUTPUT"
641fd4e5da5Sopenharmony_ci)";
642fd4e5da5Sopenharmony_ci
643fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
644fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
645fd4e5da5Sopenharmony_ci%int_128 = OpConstant %u32 128
646fd4e5da5Sopenharmony_ci)";
647fd4e5da5Sopenharmony_ci
648fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
649fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
650fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
651fd4e5da5Sopenharmony_ci%VS_OUTPUT_info = OpExtInst %void %DbgExt DebugTypeComposite %VS_OUTPUT_name Structure %dbg_src 1 1 %comp_unit %VS_OUTPUT_linkage_name %int_128 FlagIsPublic %VS_OUTPUT_pos_info %VS_OUTPUT_color_info
652fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
653fd4e5da5Sopenharmony_ci%v4float_info = OpExtInst %void %DbgExt DebugTypeVector %float_info 4
654fd4e5da5Sopenharmony_ci%VS_OUTPUT_pos_info = OpExtInst %void %DbgExt DebugTypeMember %VS_OUTPUT_pos_name %v4float_info %dbg_src 2 3 %VS_OUTPUT_info %u32_0 %int_128 FlagIsPublic
655fd4e5da5Sopenharmony_ci)";
656fd4e5da5Sopenharmony_ci
657fd4e5da5Sopenharmony_ci  const std::string extension = R"(
658fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
659fd4e5da5Sopenharmony_ci)";
660fd4e5da5Sopenharmony_ci
661fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
662fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, "", extension, "Vertex"));
663fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
664fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
665fd4e5da5Sopenharmony_ci              HasSubstr("forward referenced IDs have not been defined"));
666fd4e5da5Sopenharmony_ci}
667fd4e5da5Sopenharmony_ci
668fd4e5da5Sopenharmony_ciTEST_P(ValidateXDebugInfo, DebugSourceWrongResultType) {
669fd4e5da5Sopenharmony_ci  const std::string src = R"(
670fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
671fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
672fd4e5da5Sopenharmony_ci)";
673fd4e5da5Sopenharmony_ci
674fd4e5da5Sopenharmony_ci  const std::string dbg_inst = R"(
675fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %bool %DbgExt DebugSource %src %code
676fd4e5da5Sopenharmony_ci)";
677fd4e5da5Sopenharmony_ci
678fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", dbg_inst, "",
679fd4e5da5Sopenharmony_ci                                                     GetParam(), "Vertex"));
680fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
681fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
682fd4e5da5Sopenharmony_ci              HasSubstr("expected result type must be a result id of "
683fd4e5da5Sopenharmony_ci                        "OpTypeVoid"));
684fd4e5da5Sopenharmony_ci}
685fd4e5da5Sopenharmony_ci
686fd4e5da5Sopenharmony_ciTEST_P(ValidateXDebugInfo, DebugSourceFailFile) {
687fd4e5da5Sopenharmony_ci  const std::string src = R"(
688fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
689fd4e5da5Sopenharmony_ci)";
690fd4e5da5Sopenharmony_ci
691fd4e5da5Sopenharmony_ci  const std::string dbg_inst = R"(
692fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %DbgExt %code
693fd4e5da5Sopenharmony_ci)";
694fd4e5da5Sopenharmony_ci
695fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", dbg_inst, "",
696fd4e5da5Sopenharmony_ci                                                     GetParam(), "Vertex"));
697fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
698fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
699fd4e5da5Sopenharmony_ci              HasSubstr("expected operand File must be a result id of "
700fd4e5da5Sopenharmony_ci                        "OpString"));
701fd4e5da5Sopenharmony_ci}
702fd4e5da5Sopenharmony_ci
703fd4e5da5Sopenharmony_ciTEST_P(ValidateXDebugInfo, DebugSourceFailSource) {
704fd4e5da5Sopenharmony_ci  const std::string src = R"(
705fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
706fd4e5da5Sopenharmony_ci)";
707fd4e5da5Sopenharmony_ci
708fd4e5da5Sopenharmony_ci  const std::string dbg_inst = R"(
709fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %DbgExt
710fd4e5da5Sopenharmony_ci)";
711fd4e5da5Sopenharmony_ci
712fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", dbg_inst, "",
713fd4e5da5Sopenharmony_ci                                                     GetParam(), "Vertex"));
714fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
715fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
716fd4e5da5Sopenharmony_ci              HasSubstr("expected operand Text must be a result id of "
717fd4e5da5Sopenharmony_ci                        "OpString"));
718fd4e5da5Sopenharmony_ci}
719fd4e5da5Sopenharmony_ci
720fd4e5da5Sopenharmony_ciTEST_P(ValidateXDebugInfo, DebugSourceNoText) {
721fd4e5da5Sopenharmony_ci  const std::string src = R"(
722fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
723fd4e5da5Sopenharmony_ci)";
724fd4e5da5Sopenharmony_ci
725fd4e5da5Sopenharmony_ci  const std::string dbg_inst = R"(
726fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src
727fd4e5da5Sopenharmony_ci)";
728fd4e5da5Sopenharmony_ci
729fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", dbg_inst, "",
730fd4e5da5Sopenharmony_ci                                                     GetParam(), "Vertex"));
731fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
732fd4e5da5Sopenharmony_ci}
733fd4e5da5Sopenharmony_ci
734fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(OpenCLAndVkDebugInfo100, ValidateXDebugInfo,
735fd4e5da5Sopenharmony_ci                         ::testing::ValuesIn(std::vector<std::string>{
736fd4e5da5Sopenharmony_ci                             R"(
737fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
738fd4e5da5Sopenharmony_ci)",
739fd4e5da5Sopenharmony_ci                             R"(
740fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
741fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
742fd4e5da5Sopenharmony_ci)",
743fd4e5da5Sopenharmony_ci                         }));
744fd4e5da5Sopenharmony_ci
745fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugCompilationUnit) {
746fd4e5da5Sopenharmony_ci  const std::string src = R"(
747fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
748fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
749fd4e5da5Sopenharmony_ci)";
750fd4e5da5Sopenharmony_ci
751fd4e5da5Sopenharmony_ci  const std::string dbg_inst = R"(
752fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
753fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
754fd4e5da5Sopenharmony_ci)";
755fd4e5da5Sopenharmony_ci
756fd4e5da5Sopenharmony_ci  const std::string extension = R"(
757fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
758fd4e5da5Sopenharmony_ci)";
759fd4e5da5Sopenharmony_ci
760fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", dbg_inst, "",
761fd4e5da5Sopenharmony_ci                                                     extension, "Vertex"));
762fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
763fd4e5da5Sopenharmony_ci}
764fd4e5da5Sopenharmony_ci
765fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugCompilationUnitFail) {
766fd4e5da5Sopenharmony_ci  const std::string src = R"(
767fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
768fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
769fd4e5da5Sopenharmony_ci)";
770fd4e5da5Sopenharmony_ci
771fd4e5da5Sopenharmony_ci  const std::string dbg_inst = R"(
772fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
773fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %src HLSL
774fd4e5da5Sopenharmony_ci)";
775fd4e5da5Sopenharmony_ci
776fd4e5da5Sopenharmony_ci  const std::string extension = R"(
777fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
778fd4e5da5Sopenharmony_ci)";
779fd4e5da5Sopenharmony_ci
780fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", dbg_inst, "",
781fd4e5da5Sopenharmony_ci                                                     extension, "Vertex"));
782fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
783fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
784fd4e5da5Sopenharmony_ci              HasSubstr("expected operand Source must be a result id of "
785fd4e5da5Sopenharmony_ci                        "DebugSource"));
786fd4e5da5Sopenharmony_ci}
787fd4e5da5Sopenharmony_ci
788fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugCompilationUnitFail) {
789fd4e5da5Sopenharmony_ci  const std::string src = R"(
790fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
791fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
792fd4e5da5Sopenharmony_ci)";
793fd4e5da5Sopenharmony_ci
794fd4e5da5Sopenharmony_ci  const std::string dbg_inst = R"(
795fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
796fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %src %u32_5
797fd4e5da5Sopenharmony_ci)";
798fd4e5da5Sopenharmony_ci
799fd4e5da5Sopenharmony_ci  const std::string extension = R"(
800fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
801fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
802fd4e5da5Sopenharmony_ci)";
803fd4e5da5Sopenharmony_ci
804fd4e5da5Sopenharmony_ci  const std::string constants = R"(
805fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
806fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
807fd4e5da5Sopenharmony_ci)";
808fd4e5da5Sopenharmony_ci
809fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, constants, dbg_inst,
810fd4e5da5Sopenharmony_ci                                                     "", extension, "Vertex"));
811fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
812fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
813fd4e5da5Sopenharmony_ci              HasSubstr("expected operand Source must be a result id of "
814fd4e5da5Sopenharmony_ci                        "DebugSource"));
815fd4e5da5Sopenharmony_ci}
816fd4e5da5Sopenharmony_ci
817fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugTypeBasicFailName) {
818fd4e5da5Sopenharmony_ci  const std::string src = R"(
819fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
820fd4e5da5Sopenharmony_ci%code = OpString "float4 main(float arg) {
821fd4e5da5Sopenharmony_ci  float foo;
822fd4e5da5Sopenharmony_ci  return float4(0, 0, 0, 0);
823fd4e5da5Sopenharmony_ci}
824fd4e5da5Sopenharmony_ci"
825fd4e5da5Sopenharmony_ci%float_name = OpString "float"
826fd4e5da5Sopenharmony_ci)";
827fd4e5da5Sopenharmony_ci
828fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
829fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
830fd4e5da5Sopenharmony_ci)";
831fd4e5da5Sopenharmony_ci
832fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
833fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
834fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
835fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %int_32 %int_32 Float
836fd4e5da5Sopenharmony_ci)";
837fd4e5da5Sopenharmony_ci
838fd4e5da5Sopenharmony_ci  const std::string extension = R"(
839fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
840fd4e5da5Sopenharmony_ci)";
841fd4e5da5Sopenharmony_ci
842fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
843fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, "", extension, "Vertex"));
844fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
845fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
846fd4e5da5Sopenharmony_ci              HasSubstr("expected operand Name must be a result id of "
847fd4e5da5Sopenharmony_ci                        "OpString"));
848fd4e5da5Sopenharmony_ci}
849fd4e5da5Sopenharmony_ci
850fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugTypeBasicFailName) {
851fd4e5da5Sopenharmony_ci  const std::string src = R"(
852fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
853fd4e5da5Sopenharmony_ci%code = OpString "float4 main(float arg) {
854fd4e5da5Sopenharmony_ci  float foo;
855fd4e5da5Sopenharmony_ci  return float4(0, 0, 0, 0);
856fd4e5da5Sopenharmony_ci}
857fd4e5da5Sopenharmony_ci"
858fd4e5da5Sopenharmony_ci%float_name = OpString "float"
859fd4e5da5Sopenharmony_ci)";
860fd4e5da5Sopenharmony_ci
861fd4e5da5Sopenharmony_ci  const std::string constants = R"(
862fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
863fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
864fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
865fd4e5da5Sopenharmony_ci)";
866fd4e5da5Sopenharmony_ci
867fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
868fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
869fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
870fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %u32_32 %u32_32 %u32_3 %u32_0
871fd4e5da5Sopenharmony_ci)";
872fd4e5da5Sopenharmony_ci
873fd4e5da5Sopenharmony_ci  const std::string extension = R"(
874fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
875fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
876fd4e5da5Sopenharmony_ci)";
877fd4e5da5Sopenharmony_ci
878fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
879fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
880fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
881fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
882fd4e5da5Sopenharmony_ci              HasSubstr("expected operand Name must be a result id of "
883fd4e5da5Sopenharmony_ci                        "OpString"));
884fd4e5da5Sopenharmony_ci}
885fd4e5da5Sopenharmony_ci
886fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugTypeBasicFailSize) {
887fd4e5da5Sopenharmony_ci  const std::string src = R"(
888fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
889fd4e5da5Sopenharmony_ci%code = OpString "float4 main(float arg) {
890fd4e5da5Sopenharmony_ci  float foo;
891fd4e5da5Sopenharmony_ci  return float4(0, 0, 0, 0);
892fd4e5da5Sopenharmony_ci}
893fd4e5da5Sopenharmony_ci"
894fd4e5da5Sopenharmony_ci%float_name = OpString "float"
895fd4e5da5Sopenharmony_ci)";
896fd4e5da5Sopenharmony_ci
897fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
898fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
899fd4e5da5Sopenharmony_ci)";
900fd4e5da5Sopenharmony_ci
901fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
902fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
903fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
904fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %float_name Float
905fd4e5da5Sopenharmony_ci)";
906fd4e5da5Sopenharmony_ci
907fd4e5da5Sopenharmony_ci  const std::string extension = R"(
908fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
909fd4e5da5Sopenharmony_ci)";
910fd4e5da5Sopenharmony_ci
911fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
912fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, "", extension, "Vertex"));
913fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
914fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
915fd4e5da5Sopenharmony_ci              HasSubstr("expected operand Size must be a result id of "
916fd4e5da5Sopenharmony_ci                        "OpConstant"));
917fd4e5da5Sopenharmony_ci}
918fd4e5da5Sopenharmony_ci
919fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugTypeBasicFailSize) {
920fd4e5da5Sopenharmony_ci  const std::string src = R"(
921fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
922fd4e5da5Sopenharmony_ci%code = OpString "float4 main(float arg) {
923fd4e5da5Sopenharmony_ci  float foo;
924fd4e5da5Sopenharmony_ci  return float4(0, 0, 0, 0);
925fd4e5da5Sopenharmony_ci}
926fd4e5da5Sopenharmony_ci"
927fd4e5da5Sopenharmony_ci%float_name = OpString "float"
928fd4e5da5Sopenharmony_ci)";
929fd4e5da5Sopenharmony_ci
930fd4e5da5Sopenharmony_ci  const std::string constants = R"(
931fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
932fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
933fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
934fd4e5da5Sopenharmony_ci)";
935fd4e5da5Sopenharmony_ci
936fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
937fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
938fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
939fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %float_name %u32_3 %u32_0
940fd4e5da5Sopenharmony_ci)";
941fd4e5da5Sopenharmony_ci
942fd4e5da5Sopenharmony_ci  const std::string extension = R"(
943fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
944fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
945fd4e5da5Sopenharmony_ci)";
946fd4e5da5Sopenharmony_ci
947fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
948fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
949fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
950fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
951fd4e5da5Sopenharmony_ci              HasSubstr("expected operand Size must be a result id of "
952fd4e5da5Sopenharmony_ci                        "OpConstant"));
953fd4e5da5Sopenharmony_ci}
954fd4e5da5Sopenharmony_ci
955fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugTypePointer) {
956fd4e5da5Sopenharmony_ci  const std::string src = R"(
957fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
958fd4e5da5Sopenharmony_ci%code = OpString "float4 main(float arg) {
959fd4e5da5Sopenharmony_ci  float foo;
960fd4e5da5Sopenharmony_ci  return float4(0, 0, 0, 0);
961fd4e5da5Sopenharmony_ci}
962fd4e5da5Sopenharmony_ci"
963fd4e5da5Sopenharmony_ci%float_name = OpString "float"
964fd4e5da5Sopenharmony_ci)";
965fd4e5da5Sopenharmony_ci
966fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
967fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
968fd4e5da5Sopenharmony_ci)";
969fd4e5da5Sopenharmony_ci
970fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
971fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
972fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
973fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
974fd4e5da5Sopenharmony_ci%pfloat_info = OpExtInst %void %DbgExt DebugTypePointer %float_info Function FlagIsLocal
975fd4e5da5Sopenharmony_ci)";
976fd4e5da5Sopenharmony_ci
977fd4e5da5Sopenharmony_ci  const std::string extension = R"(
978fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
979fd4e5da5Sopenharmony_ci)";
980fd4e5da5Sopenharmony_ci
981fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
982fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, "", extension, "Vertex"));
983fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
984fd4e5da5Sopenharmony_ci}
985fd4e5da5Sopenharmony_ci
986fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugTypePointerFail) {
987fd4e5da5Sopenharmony_ci  const std::string src = R"(
988fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
989fd4e5da5Sopenharmony_ci%code = OpString "float4 main(float arg) {
990fd4e5da5Sopenharmony_ci  float foo;
991fd4e5da5Sopenharmony_ci  return float4(0, 0, 0, 0);
992fd4e5da5Sopenharmony_ci}
993fd4e5da5Sopenharmony_ci"
994fd4e5da5Sopenharmony_ci%float_name = OpString "float"
995fd4e5da5Sopenharmony_ci)";
996fd4e5da5Sopenharmony_ci
997fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
998fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
999fd4e5da5Sopenharmony_ci)";
1000fd4e5da5Sopenharmony_ci
1001fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
1002fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
1003fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
1004fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
1005fd4e5da5Sopenharmony_ci%pfloat_info = OpExtInst %void %DbgExt DebugTypePointer %dbg_src Function FlagIsLocal
1006fd4e5da5Sopenharmony_ci)";
1007fd4e5da5Sopenharmony_ci
1008fd4e5da5Sopenharmony_ci  const std::string extension = R"(
1009fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
1010fd4e5da5Sopenharmony_ci)";
1011fd4e5da5Sopenharmony_ci
1012fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
1013fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, "", extension, "Vertex"));
1014fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1015fd4e5da5Sopenharmony_ci  EXPECT_THAT(
1016fd4e5da5Sopenharmony_ci      getDiagnosticString(),
1017fd4e5da5Sopenharmony_ci      HasSubstr("expected operand Base Type is not a valid debug type"));
1018fd4e5da5Sopenharmony_ci}
1019fd4e5da5Sopenharmony_ci
1020fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugTypeQualifier) {
1021fd4e5da5Sopenharmony_ci  const std::string src = R"(
1022fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
1023fd4e5da5Sopenharmony_ci%code = OpString "float4 main(float arg) {
1024fd4e5da5Sopenharmony_ci  float foo;
1025fd4e5da5Sopenharmony_ci  return float4(0, 0, 0, 0);
1026fd4e5da5Sopenharmony_ci}
1027fd4e5da5Sopenharmony_ci"
1028fd4e5da5Sopenharmony_ci%float_name = OpString "float"
1029fd4e5da5Sopenharmony_ci)";
1030fd4e5da5Sopenharmony_ci
1031fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
1032fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
1033fd4e5da5Sopenharmony_ci)";
1034fd4e5da5Sopenharmony_ci
1035fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
1036fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
1037fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
1038fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
1039fd4e5da5Sopenharmony_ci%cfloat_info = OpExtInst %void %DbgExt DebugTypeQualifier %float_info ConstType
1040fd4e5da5Sopenharmony_ci)";
1041fd4e5da5Sopenharmony_ci
1042fd4e5da5Sopenharmony_ci  const std::string extension = R"(
1043fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
1044fd4e5da5Sopenharmony_ci)";
1045fd4e5da5Sopenharmony_ci
1046fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
1047fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, "", extension, "Vertex"));
1048fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1049fd4e5da5Sopenharmony_ci}
1050fd4e5da5Sopenharmony_ci
1051fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugTypeQualifierFail) {
1052fd4e5da5Sopenharmony_ci  const std::string src = R"(
1053fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
1054fd4e5da5Sopenharmony_ci%code = OpString "float4 main(float arg) {
1055fd4e5da5Sopenharmony_ci  float foo;
1056fd4e5da5Sopenharmony_ci  return float4(0, 0, 0, 0);
1057fd4e5da5Sopenharmony_ci}
1058fd4e5da5Sopenharmony_ci"
1059fd4e5da5Sopenharmony_ci%float_name = OpString "float"
1060fd4e5da5Sopenharmony_ci)";
1061fd4e5da5Sopenharmony_ci
1062fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
1063fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
1064fd4e5da5Sopenharmony_ci)";
1065fd4e5da5Sopenharmony_ci
1066fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
1067fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
1068fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
1069fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
1070fd4e5da5Sopenharmony_ci%cfloat_info = OpExtInst %void %DbgExt DebugTypeQualifier %comp_unit ConstType
1071fd4e5da5Sopenharmony_ci)";
1072fd4e5da5Sopenharmony_ci
1073fd4e5da5Sopenharmony_ci  const std::string extension = R"(
1074fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
1075fd4e5da5Sopenharmony_ci)";
1076fd4e5da5Sopenharmony_ci
1077fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
1078fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, "", extension, "Vertex"));
1079fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1080fd4e5da5Sopenharmony_ci  EXPECT_THAT(
1081fd4e5da5Sopenharmony_ci      getDiagnosticString(),
1082fd4e5da5Sopenharmony_ci      HasSubstr("expected operand Base Type is not a valid debug type"));
1083fd4e5da5Sopenharmony_ci}
1084fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugTypeQualifier) {
1085fd4e5da5Sopenharmony_ci  const std::string src = R"(
1086fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
1087fd4e5da5Sopenharmony_ci%code = OpString "float4 main(float arg) {
1088fd4e5da5Sopenharmony_ci  float foo;
1089fd4e5da5Sopenharmony_ci  return float4(0, 0, 0, 0);
1090fd4e5da5Sopenharmony_ci}
1091fd4e5da5Sopenharmony_ci"
1092fd4e5da5Sopenharmony_ci%float_name = OpString "float"
1093fd4e5da5Sopenharmony_ci)";
1094fd4e5da5Sopenharmony_ci
1095fd4e5da5Sopenharmony_ci  const std::string constants = R"(
1096fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
1097fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
1098fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
1099fd4e5da5Sopenharmony_ci)";
1100fd4e5da5Sopenharmony_ci
1101fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
1102fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
1103fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
1104fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
1105fd4e5da5Sopenharmony_ci%cfloat_info = OpExtInst %void %DbgExt DebugTypeQualifier %float_info %u32_0
1106fd4e5da5Sopenharmony_ci)";
1107fd4e5da5Sopenharmony_ci
1108fd4e5da5Sopenharmony_ci  const std::string extension = R"(
1109fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
1110fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
1111fd4e5da5Sopenharmony_ci)";
1112fd4e5da5Sopenharmony_ci
1113fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
1114fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
1115fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1116fd4e5da5Sopenharmony_ci}
1117fd4e5da5Sopenharmony_ci
1118fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugTypeQualifierFail) {
1119fd4e5da5Sopenharmony_ci  const std::string src = R"(
1120fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
1121fd4e5da5Sopenharmony_ci%code = OpString "float4 main(float arg) {
1122fd4e5da5Sopenharmony_ci  float foo;
1123fd4e5da5Sopenharmony_ci  return float4(0, 0, 0, 0);
1124fd4e5da5Sopenharmony_ci}
1125fd4e5da5Sopenharmony_ci"
1126fd4e5da5Sopenharmony_ci%float_name = OpString "float"
1127fd4e5da5Sopenharmony_ci)";
1128fd4e5da5Sopenharmony_ci
1129fd4e5da5Sopenharmony_ci  const std::string constants = R"(
1130fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
1131fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
1132fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
1133fd4e5da5Sopenharmony_ci)";
1134fd4e5da5Sopenharmony_ci
1135fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
1136fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
1137fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
1138fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
1139fd4e5da5Sopenharmony_ci%cfloat_info = OpExtInst %void %DbgExt DebugTypeQualifier %comp_unit %u32_0
1140fd4e5da5Sopenharmony_ci)";
1141fd4e5da5Sopenharmony_ci
1142fd4e5da5Sopenharmony_ci  const std::string extension = R"(
1143fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
1144fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
1145fd4e5da5Sopenharmony_ci)";
1146fd4e5da5Sopenharmony_ci
1147fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
1148fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
1149fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1150fd4e5da5Sopenharmony_ci  EXPECT_THAT(
1151fd4e5da5Sopenharmony_ci      getDiagnosticString(),
1152fd4e5da5Sopenharmony_ci      HasSubstr("expected operand Base Type is not a valid debug type"));
1153fd4e5da5Sopenharmony_ci}
1154fd4e5da5Sopenharmony_ci
1155fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugTypeArray) {
1156fd4e5da5Sopenharmony_ci  const std::string src = R"(
1157fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
1158fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
1159fd4e5da5Sopenharmony_ci%float_name = OpString "float"
1160fd4e5da5Sopenharmony_ci)";
1161fd4e5da5Sopenharmony_ci
1162fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
1163fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
1164fd4e5da5Sopenharmony_ci)";
1165fd4e5da5Sopenharmony_ci
1166fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
1167fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
1168fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
1169fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
1170fd4e5da5Sopenharmony_ci%float_arr_info = OpExtInst %void %DbgExt DebugTypeArray %float_info %int_32
1171fd4e5da5Sopenharmony_ci)";
1172fd4e5da5Sopenharmony_ci
1173fd4e5da5Sopenharmony_ci  const std::string extension = R"(
1174fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
1175fd4e5da5Sopenharmony_ci)";
1176fd4e5da5Sopenharmony_ci
1177fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
1178fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, "", extension, "Vertex"));
1179fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1180fd4e5da5Sopenharmony_ci}
1181fd4e5da5Sopenharmony_ci
1182fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugTypeArrayWithVariableSize) {
1183fd4e5da5Sopenharmony_ci  const std::string src = R"(
1184fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
1185fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
1186fd4e5da5Sopenharmony_ci%float_name = OpString "float"
1187fd4e5da5Sopenharmony_ci%int_name = OpString "int"
1188fd4e5da5Sopenharmony_ci%main_name = OpString "main"
1189fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
1190fd4e5da5Sopenharmony_ci)";
1191fd4e5da5Sopenharmony_ci
1192fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
1193fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
1194fd4e5da5Sopenharmony_ci)";
1195fd4e5da5Sopenharmony_ci
1196fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
1197fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
1198fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
1199fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
1200fd4e5da5Sopenharmony_ci%uint_info = OpExtInst %void %DbgExt DebugTypeBasic %int_name %int_32 Unsigned
1201fd4e5da5Sopenharmony_ci%main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void
1202fd4e5da5Sopenharmony_ci%main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 1 1 %comp_unit %main_name FlagIsPublic 1 %main
1203fd4e5da5Sopenharmony_ci%foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %uint_info %dbg_src 1 1 %main_info FlagIsLocal
1204fd4e5da5Sopenharmony_ci%float_arr_info = OpExtInst %void %DbgExt DebugTypeArray %float_info %foo_info
1205fd4e5da5Sopenharmony_ci)";
1206fd4e5da5Sopenharmony_ci
1207fd4e5da5Sopenharmony_ci  const std::string extension = R"(
1208fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
1209fd4e5da5Sopenharmony_ci)";
1210fd4e5da5Sopenharmony_ci
1211fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
1212fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, "", extension, "Vertex"));
1213fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1214fd4e5da5Sopenharmony_ci}
1215fd4e5da5Sopenharmony_ci
1216fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugTypeArrayFailBaseType) {
1217fd4e5da5Sopenharmony_ci  const std::string src = R"(
1218fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
1219fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
1220fd4e5da5Sopenharmony_ci%float_name = OpString "float"
1221fd4e5da5Sopenharmony_ci)";
1222fd4e5da5Sopenharmony_ci
1223fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
1224fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
1225fd4e5da5Sopenharmony_ci)";
1226fd4e5da5Sopenharmony_ci
1227fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
1228fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
1229fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
1230fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
1231fd4e5da5Sopenharmony_ci%float_arr_info = OpExtInst %void %DbgExt DebugTypeArray %comp_unit %int_32
1232fd4e5da5Sopenharmony_ci)";
1233fd4e5da5Sopenharmony_ci
1234fd4e5da5Sopenharmony_ci  const std::string extension = R"(
1235fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
1236fd4e5da5Sopenharmony_ci)";
1237fd4e5da5Sopenharmony_ci
1238fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
1239fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, "", extension, "Vertex"));
1240fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1241fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
1242fd4e5da5Sopenharmony_ci              HasSubstr("expected operand Base Type is not a valid debug "
1243fd4e5da5Sopenharmony_ci                        "type"));
1244fd4e5da5Sopenharmony_ci}
1245fd4e5da5Sopenharmony_ci
1246fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugTypeArrayFailComponentCount) {
1247fd4e5da5Sopenharmony_ci  const std::string src = R"(
1248fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
1249fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
1250fd4e5da5Sopenharmony_ci%float_name = OpString "float"
1251fd4e5da5Sopenharmony_ci)";
1252fd4e5da5Sopenharmony_ci
1253fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
1254fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
1255fd4e5da5Sopenharmony_ci)";
1256fd4e5da5Sopenharmony_ci
1257fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
1258fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
1259fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
1260fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
1261fd4e5da5Sopenharmony_ci%float_arr_info = OpExtInst %void %DbgExt DebugTypeArray %float_info %float_info
1262fd4e5da5Sopenharmony_ci)";
1263fd4e5da5Sopenharmony_ci
1264fd4e5da5Sopenharmony_ci  const std::string extension = R"(
1265fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
1266fd4e5da5Sopenharmony_ci)";
1267fd4e5da5Sopenharmony_ci
1268fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
1269fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, "", extension, "Vertex"));
1270fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1271fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
1272fd4e5da5Sopenharmony_ci              HasSubstr("Component Count must be OpConstant with a 32- or "
1273fd4e5da5Sopenharmony_ci                        "64-bits integer scalar type or DebugGlobalVariable or "
1274fd4e5da5Sopenharmony_ci                        "DebugLocalVariable with a 32- or 64-bits unsigned "
1275fd4e5da5Sopenharmony_ci                        "integer scalar type"));
1276fd4e5da5Sopenharmony_ci}
1277fd4e5da5Sopenharmony_ci
1278fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugTypeArrayFailComponentCountFloat) {
1279fd4e5da5Sopenharmony_ci  const std::string src = R"(
1280fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
1281fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
1282fd4e5da5Sopenharmony_ci%float_name = OpString "float"
1283fd4e5da5Sopenharmony_ci)";
1284fd4e5da5Sopenharmony_ci
1285fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
1286fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
1287fd4e5da5Sopenharmony_ci)";
1288fd4e5da5Sopenharmony_ci
1289fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
1290fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
1291fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
1292fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
1293fd4e5da5Sopenharmony_ci%float_arr_info = OpExtInst %void %DbgExt DebugTypeArray %float_info %f32_4
1294fd4e5da5Sopenharmony_ci)";
1295fd4e5da5Sopenharmony_ci
1296fd4e5da5Sopenharmony_ci  const std::string extension = R"(
1297fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
1298fd4e5da5Sopenharmony_ci)";
1299fd4e5da5Sopenharmony_ci
1300fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
1301fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, "", extension, "Vertex"));
1302fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1303fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
1304fd4e5da5Sopenharmony_ci              HasSubstr("Component Count must be OpConstant with a 32- or "
1305fd4e5da5Sopenharmony_ci                        "64-bits integer scalar type or DebugGlobalVariable or "
1306fd4e5da5Sopenharmony_ci                        "DebugLocalVariable with a 32- or 64-bits unsigned "
1307fd4e5da5Sopenharmony_ci                        "integer scalar type"));
1308fd4e5da5Sopenharmony_ci}
1309fd4e5da5Sopenharmony_ci
1310fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugTypeArrayFailComponentCountZero) {
1311fd4e5da5Sopenharmony_ci  const std::string src = R"(
1312fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
1313fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
1314fd4e5da5Sopenharmony_ci%float_name = OpString "float"
1315fd4e5da5Sopenharmony_ci)";
1316fd4e5da5Sopenharmony_ci
1317fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
1318fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
1319fd4e5da5Sopenharmony_ci)";
1320fd4e5da5Sopenharmony_ci
1321fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
1322fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
1323fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
1324fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
1325fd4e5da5Sopenharmony_ci%float_arr_info = OpExtInst %void %DbgExt DebugTypeArray %float_info %u32_0
1326fd4e5da5Sopenharmony_ci)";
1327fd4e5da5Sopenharmony_ci
1328fd4e5da5Sopenharmony_ci  const std::string extension = R"(
1329fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
1330fd4e5da5Sopenharmony_ci)";
1331fd4e5da5Sopenharmony_ci
1332fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
1333fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, "", extension, "Vertex"));
1334fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1335fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
1336fd4e5da5Sopenharmony_ci              HasSubstr("Component Count must be OpConstant with a 32- or "
1337fd4e5da5Sopenharmony_ci                        "64-bits integer scalar type or DebugGlobalVariable or "
1338fd4e5da5Sopenharmony_ci                        "DebugLocalVariable with a 32- or 64-bits unsigned "
1339fd4e5da5Sopenharmony_ci                        "integer scalar type"));
1340fd4e5da5Sopenharmony_ci}
1341fd4e5da5Sopenharmony_ci
1342fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugTypeArrayFailVariableSizeTypeFloat) {
1343fd4e5da5Sopenharmony_ci  const std::string src = R"(
1344fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
1345fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
1346fd4e5da5Sopenharmony_ci%float_name = OpString "float"
1347fd4e5da5Sopenharmony_ci%main_name = OpString "main"
1348fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
1349fd4e5da5Sopenharmony_ci)";
1350fd4e5da5Sopenharmony_ci
1351fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
1352fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
1353fd4e5da5Sopenharmony_ci)";
1354fd4e5da5Sopenharmony_ci
1355fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
1356fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
1357fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
1358fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
1359fd4e5da5Sopenharmony_ci%main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void
1360fd4e5da5Sopenharmony_ci%main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 1 1 %comp_unit %main_name FlagIsPublic 1 %main
1361fd4e5da5Sopenharmony_ci%foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %float_info %dbg_src 1 1 %main_info FlagIsLocal
1362fd4e5da5Sopenharmony_ci%float_arr_info = OpExtInst %void %DbgExt DebugTypeArray %float_info %foo_info
1363fd4e5da5Sopenharmony_ci)";
1364fd4e5da5Sopenharmony_ci
1365fd4e5da5Sopenharmony_ci  const std::string extension = R"(
1366fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
1367fd4e5da5Sopenharmony_ci)";
1368fd4e5da5Sopenharmony_ci
1369fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
1370fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, "", extension, "Vertex"));
1371fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1372fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
1373fd4e5da5Sopenharmony_ci              HasSubstr("Component Count must be OpConstant with a 32- or "
1374fd4e5da5Sopenharmony_ci                        "64-bits integer scalar type or DebugGlobalVariable or "
1375fd4e5da5Sopenharmony_ci                        "DebugLocalVariable with a 32- or 64-bits unsigned "
1376fd4e5da5Sopenharmony_ci                        "integer scalar type"));
1377fd4e5da5Sopenharmony_ci}
1378fd4e5da5Sopenharmony_ci
1379fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugTypeArray) {
1380fd4e5da5Sopenharmony_ci  const std::string src = R"(
1381fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
1382fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
1383fd4e5da5Sopenharmony_ci%float_name = OpString "float"
1384fd4e5da5Sopenharmony_ci)";
1385fd4e5da5Sopenharmony_ci
1386fd4e5da5Sopenharmony_ci  const std::string constants = R"(
1387fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
1388fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
1389fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
1390fd4e5da5Sopenharmony_ci)";
1391fd4e5da5Sopenharmony_ci
1392fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
1393fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
1394fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
1395fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
1396fd4e5da5Sopenharmony_ci%float_arr_info = OpExtInst %void %DbgExt DebugTypeArray %float_info %u32_32
1397fd4e5da5Sopenharmony_ci)";
1398fd4e5da5Sopenharmony_ci
1399fd4e5da5Sopenharmony_ci  const std::string extension = R"(
1400fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
1401fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
1402fd4e5da5Sopenharmony_ci)";
1403fd4e5da5Sopenharmony_ci
1404fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
1405fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
1406fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1407fd4e5da5Sopenharmony_ci}
1408fd4e5da5Sopenharmony_ci
1409fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugTypeArrayWithVariableSize) {
1410fd4e5da5Sopenharmony_ci  const std::string src = R"(
1411fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
1412fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
1413fd4e5da5Sopenharmony_ci%float_name = OpString "float"
1414fd4e5da5Sopenharmony_ci%uint_name = OpString "uint"
1415fd4e5da5Sopenharmony_ci%main_name = OpString "main"
1416fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
1417fd4e5da5Sopenharmony_ci)";
1418fd4e5da5Sopenharmony_ci
1419fd4e5da5Sopenharmony_ci  const std::string constants = R"(
1420fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
1421fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
1422fd4e5da5Sopenharmony_ci%u32_6 = OpConstant %u32 6
1423fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
1424fd4e5da5Sopenharmony_ci)";
1425fd4e5da5Sopenharmony_ci
1426fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
1427fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
1428fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
1429fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
1430fd4e5da5Sopenharmony_ci%uint_info = OpExtInst %void %DbgExt DebugTypeBasic %uint_name %u32_32 %u32_6 %u32_0
1431fd4e5da5Sopenharmony_ci%main_type_info = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %void
1432fd4e5da5Sopenharmony_ci%main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src %u32_1 %u32_1 %comp_unit %main_name %u32_3 %u32_1
1433fd4e5da5Sopenharmony_ci%foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %uint_info %dbg_src %u32_1 %u32_1 %main_info %u32_4
1434fd4e5da5Sopenharmony_ci%float_arr_info = OpExtInst %void %DbgExt DebugTypeArray %float_info %foo_info
1435fd4e5da5Sopenharmony_ci)";
1436fd4e5da5Sopenharmony_ci
1437fd4e5da5Sopenharmony_ci  const std::string extension = R"(
1438fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
1439fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
1440fd4e5da5Sopenharmony_ci)";
1441fd4e5da5Sopenharmony_ci
1442fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
1443fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
1444fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1445fd4e5da5Sopenharmony_ci}
1446fd4e5da5Sopenharmony_ci
1447fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugTypeArrayFailBaseType) {
1448fd4e5da5Sopenharmony_ci  const std::string src = R"(
1449fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
1450fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
1451fd4e5da5Sopenharmony_ci%float_name = OpString "float"
1452fd4e5da5Sopenharmony_ci)";
1453fd4e5da5Sopenharmony_ci
1454fd4e5da5Sopenharmony_ci  const std::string constants = R"(
1455fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
1456fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
1457fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
1458fd4e5da5Sopenharmony_ci)";
1459fd4e5da5Sopenharmony_ci
1460fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
1461fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
1462fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
1463fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
1464fd4e5da5Sopenharmony_ci%float_arr_info = OpExtInst %void %DbgExt DebugTypeArray %comp_unit %u32_32
1465fd4e5da5Sopenharmony_ci)";
1466fd4e5da5Sopenharmony_ci
1467fd4e5da5Sopenharmony_ci  const std::string extension = R"(
1468fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
1469fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
1470fd4e5da5Sopenharmony_ci)";
1471fd4e5da5Sopenharmony_ci
1472fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
1473fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
1474fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1475fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
1476fd4e5da5Sopenharmony_ci              HasSubstr("expected operand Base Type is not a valid debug "
1477fd4e5da5Sopenharmony_ci                        "type"));
1478fd4e5da5Sopenharmony_ci}
1479fd4e5da5Sopenharmony_ci
1480fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugTypeArrayFailComponentCount) {
1481fd4e5da5Sopenharmony_ci  const std::string src = R"(
1482fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
1483fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
1484fd4e5da5Sopenharmony_ci%float_name = OpString "float"
1485fd4e5da5Sopenharmony_ci)";
1486fd4e5da5Sopenharmony_ci
1487fd4e5da5Sopenharmony_ci  const std::string constants = R"(
1488fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
1489fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
1490fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
1491fd4e5da5Sopenharmony_ci)";
1492fd4e5da5Sopenharmony_ci
1493fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
1494fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
1495fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
1496fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
1497fd4e5da5Sopenharmony_ci%float_arr_info = OpExtInst %void %DbgExt DebugTypeArray %float_info %float_info
1498fd4e5da5Sopenharmony_ci)";
1499fd4e5da5Sopenharmony_ci
1500fd4e5da5Sopenharmony_ci  const std::string extension = R"(
1501fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
1502fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
1503fd4e5da5Sopenharmony_ci)";
1504fd4e5da5Sopenharmony_ci
1505fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
1506fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
1507fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1508fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
1509fd4e5da5Sopenharmony_ci              HasSubstr("Component Count must be OpConstant with a 32- or "
1510fd4e5da5Sopenharmony_ci                        "64-bits integer scalar type or DebugGlobalVariable or "
1511fd4e5da5Sopenharmony_ci                        "DebugLocalVariable with a 32- or 64-bits unsigned "
1512fd4e5da5Sopenharmony_ci                        "integer scalar type"));
1513fd4e5da5Sopenharmony_ci}
1514fd4e5da5Sopenharmony_ci
1515fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugTypeArrayFailComponentCountFloat) {
1516fd4e5da5Sopenharmony_ci  const std::string src = R"(
1517fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
1518fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
1519fd4e5da5Sopenharmony_ci%float_name = OpString "float"
1520fd4e5da5Sopenharmony_ci)";
1521fd4e5da5Sopenharmony_ci
1522fd4e5da5Sopenharmony_ci  const std::string constants = R"(
1523fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
1524fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
1525fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
1526fd4e5da5Sopenharmony_ci)";
1527fd4e5da5Sopenharmony_ci
1528fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
1529fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
1530fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
1531fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
1532fd4e5da5Sopenharmony_ci%float_arr_info = OpExtInst %void %DbgExt DebugTypeArray %float_info %f32_4
1533fd4e5da5Sopenharmony_ci)";
1534fd4e5da5Sopenharmony_ci
1535fd4e5da5Sopenharmony_ci  const std::string extension = R"(
1536fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
1537fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
1538fd4e5da5Sopenharmony_ci)";
1539fd4e5da5Sopenharmony_ci
1540fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
1541fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
1542fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1543fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
1544fd4e5da5Sopenharmony_ci              HasSubstr("Component Count must be OpConstant with a 32- or "
1545fd4e5da5Sopenharmony_ci                        "64-bits integer scalar type or DebugGlobalVariable or "
1546fd4e5da5Sopenharmony_ci                        "DebugLocalVariable with a 32- or 64-bits unsigned "
1547fd4e5da5Sopenharmony_ci                        "integer scalar type"));
1548fd4e5da5Sopenharmony_ci}
1549fd4e5da5Sopenharmony_ci
1550fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugTypeArrayComponentCountZero) {
1551fd4e5da5Sopenharmony_ci  const std::string src = R"(
1552fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
1553fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
1554fd4e5da5Sopenharmony_ci%float_name = OpString "float"
1555fd4e5da5Sopenharmony_ci)";
1556fd4e5da5Sopenharmony_ci
1557fd4e5da5Sopenharmony_ci  const std::string constants = R"(
1558fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
1559fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
1560fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
1561fd4e5da5Sopenharmony_ci)";
1562fd4e5da5Sopenharmony_ci
1563fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
1564fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
1565fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
1566fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
1567fd4e5da5Sopenharmony_ci%float_arr_info = OpExtInst %void %DbgExt DebugTypeArray %float_info %u32_0
1568fd4e5da5Sopenharmony_ci)";
1569fd4e5da5Sopenharmony_ci
1570fd4e5da5Sopenharmony_ci  const std::string extension = R"(
1571fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
1572fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
1573fd4e5da5Sopenharmony_ci)";
1574fd4e5da5Sopenharmony_ci
1575fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
1576fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
1577fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1578fd4e5da5Sopenharmony_ci}
1579fd4e5da5Sopenharmony_ci
1580fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugTypeArrayFailVariableSizeTypeFloat) {
1581fd4e5da5Sopenharmony_ci  const std::string src = R"(
1582fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
1583fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
1584fd4e5da5Sopenharmony_ci%float_name = OpString "float"
1585fd4e5da5Sopenharmony_ci%main_name = OpString "main"
1586fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
1587fd4e5da5Sopenharmony_ci)";
1588fd4e5da5Sopenharmony_ci
1589fd4e5da5Sopenharmony_ci  const std::string constants = R"(
1590fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
1591fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
1592fd4e5da5Sopenharmony_ci%u32_6 = OpConstant %u32 6
1593fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
1594fd4e5da5Sopenharmony_ci)";
1595fd4e5da5Sopenharmony_ci
1596fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
1597fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
1598fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
1599fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
1600fd4e5da5Sopenharmony_ci%main_type_info = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %void
1601fd4e5da5Sopenharmony_ci%main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src %u32_1 %u32_1 %comp_unit %main_name %u32_3 %u32_1
1602fd4e5da5Sopenharmony_ci%foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %float_info %dbg_src %u32_1 %u32_1 %main_info %u32_4
1603fd4e5da5Sopenharmony_ci%float_arr_info = OpExtInst %void %DbgExt DebugTypeArray %float_info %foo_info
1604fd4e5da5Sopenharmony_ci)";
1605fd4e5da5Sopenharmony_ci
1606fd4e5da5Sopenharmony_ci  const std::string extension = R"(
1607fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
1608fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
1609fd4e5da5Sopenharmony_ci)";
1610fd4e5da5Sopenharmony_ci
1611fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
1612fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
1613fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1614fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
1615fd4e5da5Sopenharmony_ci              HasSubstr("Component Count must be OpConstant with a 32- or "
1616fd4e5da5Sopenharmony_ci                        "64-bits integer scalar type or DebugGlobalVariable or "
1617fd4e5da5Sopenharmony_ci                        "DebugLocalVariable with a 32- or 64-bits unsigned "
1618fd4e5da5Sopenharmony_ci                        "integer scalar type"));
1619fd4e5da5Sopenharmony_ci}
1620fd4e5da5Sopenharmony_ci
1621fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugTypeVector) {
1622fd4e5da5Sopenharmony_ci  const std::string src = R"(
1623fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
1624fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
1625fd4e5da5Sopenharmony_ci%float_name = OpString "float"
1626fd4e5da5Sopenharmony_ci)";
1627fd4e5da5Sopenharmony_ci
1628fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
1629fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
1630fd4e5da5Sopenharmony_ci)";
1631fd4e5da5Sopenharmony_ci
1632fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
1633fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
1634fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
1635fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
1636fd4e5da5Sopenharmony_ci%vfloat_info = OpExtInst %void %DbgExt DebugTypeVector %float_info 4
1637fd4e5da5Sopenharmony_ci)";
1638fd4e5da5Sopenharmony_ci
1639fd4e5da5Sopenharmony_ci  const std::string extension = R"(
1640fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
1641fd4e5da5Sopenharmony_ci)";
1642fd4e5da5Sopenharmony_ci
1643fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
1644fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, "", extension, "Vertex"));
1645fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1646fd4e5da5Sopenharmony_ci}
1647fd4e5da5Sopenharmony_ci
1648fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugTypeVectorFail) {
1649fd4e5da5Sopenharmony_ci  const std::string src = R"(
1650fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
1651fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
1652fd4e5da5Sopenharmony_ci%float_name = OpString "float"
1653fd4e5da5Sopenharmony_ci)";
1654fd4e5da5Sopenharmony_ci
1655fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
1656fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
1657fd4e5da5Sopenharmony_ci)";
1658fd4e5da5Sopenharmony_ci
1659fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
1660fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
1661fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
1662fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
1663fd4e5da5Sopenharmony_ci%vfloat_info = OpExtInst %void %DbgExt DebugTypeVector %dbg_src 4
1664fd4e5da5Sopenharmony_ci)";
1665fd4e5da5Sopenharmony_ci
1666fd4e5da5Sopenharmony_ci  const std::string extension = R"(
1667fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
1668fd4e5da5Sopenharmony_ci)";
1669fd4e5da5Sopenharmony_ci
1670fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
1671fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, "", extension, "Vertex"));
1672fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1673fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
1674fd4e5da5Sopenharmony_ci              HasSubstr("expected operand Base Type must be a result id of "
1675fd4e5da5Sopenharmony_ci                        "DebugTypeBasic"));
1676fd4e5da5Sopenharmony_ci}
1677fd4e5da5Sopenharmony_ci
1678fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugTypeVectorFailComponentZero) {
1679fd4e5da5Sopenharmony_ci  const std::string src = R"(
1680fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
1681fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
1682fd4e5da5Sopenharmony_ci%float_name = OpString "float"
1683fd4e5da5Sopenharmony_ci)";
1684fd4e5da5Sopenharmony_ci
1685fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
1686fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
1687fd4e5da5Sopenharmony_ci)";
1688fd4e5da5Sopenharmony_ci
1689fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
1690fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
1691fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
1692fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
1693fd4e5da5Sopenharmony_ci%vfloat_info = OpExtInst %void %DbgExt DebugTypeVector %dbg_src 0
1694fd4e5da5Sopenharmony_ci)";
1695fd4e5da5Sopenharmony_ci
1696fd4e5da5Sopenharmony_ci  const std::string extension = R"(
1697fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
1698fd4e5da5Sopenharmony_ci)";
1699fd4e5da5Sopenharmony_ci
1700fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
1701fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, "", extension, "Vertex"));
1702fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1703fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
1704fd4e5da5Sopenharmony_ci              HasSubstr("expected operand Base Type must be a result id of "
1705fd4e5da5Sopenharmony_ci                        "DebugTypeBasic"));
1706fd4e5da5Sopenharmony_ci}
1707fd4e5da5Sopenharmony_ci
1708fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugTypeVectorFailComponentFive) {
1709fd4e5da5Sopenharmony_ci  const std::string src = R"(
1710fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
1711fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
1712fd4e5da5Sopenharmony_ci%float_name = OpString "float"
1713fd4e5da5Sopenharmony_ci)";
1714fd4e5da5Sopenharmony_ci
1715fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
1716fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
1717fd4e5da5Sopenharmony_ci)";
1718fd4e5da5Sopenharmony_ci
1719fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
1720fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
1721fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
1722fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
1723fd4e5da5Sopenharmony_ci%vfloat_info = OpExtInst %void %DbgExt DebugTypeVector %dbg_src 5
1724fd4e5da5Sopenharmony_ci)";
1725fd4e5da5Sopenharmony_ci
1726fd4e5da5Sopenharmony_ci  const std::string extension = R"(
1727fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
1728fd4e5da5Sopenharmony_ci)";
1729fd4e5da5Sopenharmony_ci
1730fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
1731fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, "", extension, "Vertex"));
1732fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1733fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
1734fd4e5da5Sopenharmony_ci              HasSubstr("expected operand Base Type must be a result id of "
1735fd4e5da5Sopenharmony_ci                        "DebugTypeBasic"));
1736fd4e5da5Sopenharmony_ci}
1737fd4e5da5Sopenharmony_ci
1738fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugTypeVector) {
1739fd4e5da5Sopenharmony_ci  const std::string src = R"(
1740fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
1741fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
1742fd4e5da5Sopenharmony_ci%float_name = OpString "float"
1743fd4e5da5Sopenharmony_ci)";
1744fd4e5da5Sopenharmony_ci
1745fd4e5da5Sopenharmony_ci  const std::string constants = R"(
1746fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
1747fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
1748fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
1749fd4e5da5Sopenharmony_ci)";
1750fd4e5da5Sopenharmony_ci
1751fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
1752fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
1753fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
1754fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
1755fd4e5da5Sopenharmony_ci%vfloat_info = OpExtInst %void %DbgExt DebugTypeVector %float_info %u32_4
1756fd4e5da5Sopenharmony_ci)";
1757fd4e5da5Sopenharmony_ci
1758fd4e5da5Sopenharmony_ci  const std::string extension = R"(
1759fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
1760fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
1761fd4e5da5Sopenharmony_ci)";
1762fd4e5da5Sopenharmony_ci
1763fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
1764fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
1765fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1766fd4e5da5Sopenharmony_ci}
1767fd4e5da5Sopenharmony_ci
1768fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugTypeVectorFail) {
1769fd4e5da5Sopenharmony_ci  const std::string src = R"(
1770fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
1771fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
1772fd4e5da5Sopenharmony_ci%float_name = OpString "float"
1773fd4e5da5Sopenharmony_ci)";
1774fd4e5da5Sopenharmony_ci
1775fd4e5da5Sopenharmony_ci  const std::string constants = R"(
1776fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
1777fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
1778fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
1779fd4e5da5Sopenharmony_ci)";
1780fd4e5da5Sopenharmony_ci
1781fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
1782fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
1783fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
1784fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
1785fd4e5da5Sopenharmony_ci%vfloat_info = OpExtInst %void %DbgExt DebugTypeVector %dbg_src %u32_4
1786fd4e5da5Sopenharmony_ci)";
1787fd4e5da5Sopenharmony_ci
1788fd4e5da5Sopenharmony_ci  const std::string extension = R"(
1789fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
1790fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
1791fd4e5da5Sopenharmony_ci)";
1792fd4e5da5Sopenharmony_ci
1793fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
1794fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
1795fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1796fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
1797fd4e5da5Sopenharmony_ci              HasSubstr("expected operand Base Type must be a result id of "
1798fd4e5da5Sopenharmony_ci                        "DebugTypeBasic"));
1799fd4e5da5Sopenharmony_ci}
1800fd4e5da5Sopenharmony_ci
1801fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugTypeVectorFailComponentZero) {
1802fd4e5da5Sopenharmony_ci  const std::string src = R"(
1803fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
1804fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
1805fd4e5da5Sopenharmony_ci%float_name = OpString "float"
1806fd4e5da5Sopenharmony_ci)";
1807fd4e5da5Sopenharmony_ci
1808fd4e5da5Sopenharmony_ci  const std::string constants = R"(
1809fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
1810fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
1811fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
1812fd4e5da5Sopenharmony_ci)";
1813fd4e5da5Sopenharmony_ci
1814fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
1815fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
1816fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
1817fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
1818fd4e5da5Sopenharmony_ci%vfloat_info = OpExtInst %void %DbgExt DebugTypeVector %float_info %u32_0
1819fd4e5da5Sopenharmony_ci)";
1820fd4e5da5Sopenharmony_ci
1821fd4e5da5Sopenharmony_ci  const std::string extension = R"(
1822fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
1823fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
1824fd4e5da5Sopenharmony_ci)";
1825fd4e5da5Sopenharmony_ci
1826fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
1827fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
1828fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1829fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
1830fd4e5da5Sopenharmony_ci              HasSubstr("Component Count must be positive "
1831fd4e5da5Sopenharmony_ci                        "integer less than or equal to 4"));
1832fd4e5da5Sopenharmony_ci}
1833fd4e5da5Sopenharmony_ci
1834fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugTypeVectorFailComponentFive) {
1835fd4e5da5Sopenharmony_ci  const std::string src = R"(
1836fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
1837fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
1838fd4e5da5Sopenharmony_ci%float_name = OpString "float"
1839fd4e5da5Sopenharmony_ci)";
1840fd4e5da5Sopenharmony_ci
1841fd4e5da5Sopenharmony_ci  const std::string constants = R"(
1842fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
1843fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
1844fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
1845fd4e5da5Sopenharmony_ci)";
1846fd4e5da5Sopenharmony_ci
1847fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
1848fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
1849fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
1850fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
1851fd4e5da5Sopenharmony_ci%vfloat_info = OpExtInst %void %DbgExt DebugTypeVector %float_info %u32_5
1852fd4e5da5Sopenharmony_ci)";
1853fd4e5da5Sopenharmony_ci
1854fd4e5da5Sopenharmony_ci  const std::string extension = R"(
1855fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
1856fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
1857fd4e5da5Sopenharmony_ci)";
1858fd4e5da5Sopenharmony_ci
1859fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
1860fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
1861fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1862fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
1863fd4e5da5Sopenharmony_ci              HasSubstr("Component Count must be positive "
1864fd4e5da5Sopenharmony_ci                        "integer less than or equal to 4"));
1865fd4e5da5Sopenharmony_ci}
1866fd4e5da5Sopenharmony_ci
1867fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugTypeMatrix) {
1868fd4e5da5Sopenharmony_ci  const std::string src = R"(
1869fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
1870fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
1871fd4e5da5Sopenharmony_ci%float_name = OpString "float"
1872fd4e5da5Sopenharmony_ci)";
1873fd4e5da5Sopenharmony_ci
1874fd4e5da5Sopenharmony_ci  const std::string constants = R"(
1875fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
1876fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
1877fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
1878fd4e5da5Sopenharmony_ci%true = OpConstantTrue %bool
1879fd4e5da5Sopenharmony_ci)";
1880fd4e5da5Sopenharmony_ci
1881fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
1882fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
1883fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
1884fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
1885fd4e5da5Sopenharmony_ci%vfloat_info = OpExtInst %void %DbgExt DebugTypeVector %float_info %u32_4
1886fd4e5da5Sopenharmony_ci%mfloat_info = OpExtInst %void %DbgExt DebugTypeMatrix %vfloat_info %u32_4 %true
1887fd4e5da5Sopenharmony_ci)";
1888fd4e5da5Sopenharmony_ci
1889fd4e5da5Sopenharmony_ci  const std::string extension = R"(
1890fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
1891fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
1892fd4e5da5Sopenharmony_ci)";
1893fd4e5da5Sopenharmony_ci
1894fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
1895fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
1896fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1897fd4e5da5Sopenharmony_ci}
1898fd4e5da5Sopenharmony_ci
1899fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugTypeMatrixFailVectorTypeType) {
1900fd4e5da5Sopenharmony_ci  const std::string src = R"(
1901fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
1902fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
1903fd4e5da5Sopenharmony_ci%float_name = OpString "float"
1904fd4e5da5Sopenharmony_ci)";
1905fd4e5da5Sopenharmony_ci
1906fd4e5da5Sopenharmony_ci  const std::string constants = R"(
1907fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
1908fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
1909fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
1910fd4e5da5Sopenharmony_ci%true = OpConstantTrue %bool
1911fd4e5da5Sopenharmony_ci)";
1912fd4e5da5Sopenharmony_ci
1913fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
1914fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
1915fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
1916fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
1917fd4e5da5Sopenharmony_ci%vfloat_info = OpExtInst %void %DbgExt DebugTypeVector %float_info %u32_4
1918fd4e5da5Sopenharmony_ci%mfloat_info = OpExtInst %void %DbgExt DebugTypeMatrix %dbg_src %u32_4 %true
1919fd4e5da5Sopenharmony_ci)";
1920fd4e5da5Sopenharmony_ci
1921fd4e5da5Sopenharmony_ci  const std::string extension = R"(
1922fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
1923fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
1924fd4e5da5Sopenharmony_ci)";
1925fd4e5da5Sopenharmony_ci
1926fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
1927fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
1928fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1929fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
1930fd4e5da5Sopenharmony_ci              HasSubstr("expected operand Vector Type must be a result id of "
1931fd4e5da5Sopenharmony_ci                        "DebugTypeVector"));
1932fd4e5da5Sopenharmony_ci}
1933fd4e5da5Sopenharmony_ci
1934fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugTypeMatrixFailVectorCountType) {
1935fd4e5da5Sopenharmony_ci  const std::string src = R"(
1936fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
1937fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
1938fd4e5da5Sopenharmony_ci%float_name = OpString "float"
1939fd4e5da5Sopenharmony_ci)";
1940fd4e5da5Sopenharmony_ci
1941fd4e5da5Sopenharmony_ci  const std::string constants = R"(
1942fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
1943fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
1944fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
1945fd4e5da5Sopenharmony_ci%true = OpConstantTrue %bool
1946fd4e5da5Sopenharmony_ci)";
1947fd4e5da5Sopenharmony_ci
1948fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
1949fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
1950fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
1951fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
1952fd4e5da5Sopenharmony_ci%vfloat_info = OpExtInst %void %DbgExt DebugTypeVector %float_info %u32_4
1953fd4e5da5Sopenharmony_ci%mfloat_info = OpExtInst %void %DbgExt DebugTypeMatrix %vfloat_info %dbg_src %true
1954fd4e5da5Sopenharmony_ci)";
1955fd4e5da5Sopenharmony_ci
1956fd4e5da5Sopenharmony_ci  const std::string extension = R"(
1957fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
1958fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
1959fd4e5da5Sopenharmony_ci)";
1960fd4e5da5Sopenharmony_ci
1961fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
1962fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
1963fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1964fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
1965fd4e5da5Sopenharmony_ci              HasSubstr("expected operand Vector Count must be a result id of "
1966fd4e5da5Sopenharmony_ci                        "32-bit unsigned OpConstant"));
1967fd4e5da5Sopenharmony_ci}
1968fd4e5da5Sopenharmony_ci
1969fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugTypeMatrixFailVectorCountZero) {
1970fd4e5da5Sopenharmony_ci  const std::string src = R"(
1971fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
1972fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
1973fd4e5da5Sopenharmony_ci%float_name = OpString "float"
1974fd4e5da5Sopenharmony_ci)";
1975fd4e5da5Sopenharmony_ci
1976fd4e5da5Sopenharmony_ci  const std::string constants = R"(
1977fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
1978fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
1979fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
1980fd4e5da5Sopenharmony_ci%true = OpConstantTrue %bool
1981fd4e5da5Sopenharmony_ci)";
1982fd4e5da5Sopenharmony_ci
1983fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
1984fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
1985fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
1986fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
1987fd4e5da5Sopenharmony_ci%vfloat_info = OpExtInst %void %DbgExt DebugTypeVector %float_info %u32_4
1988fd4e5da5Sopenharmony_ci%mfloat_info = OpExtInst %void %DbgExt DebugTypeMatrix %vfloat_info %u32_0 %true
1989fd4e5da5Sopenharmony_ci)";
1990fd4e5da5Sopenharmony_ci
1991fd4e5da5Sopenharmony_ci  const std::string extension = R"(
1992fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
1993fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
1994fd4e5da5Sopenharmony_ci)";
1995fd4e5da5Sopenharmony_ci
1996fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
1997fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
1998fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1999fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
2000fd4e5da5Sopenharmony_ci              HasSubstr("Vector Count must be positive "
2001fd4e5da5Sopenharmony_ci                        "integer less than or equal to 4"));
2002fd4e5da5Sopenharmony_ci}
2003fd4e5da5Sopenharmony_ci
2004fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugTypeMatrixFailVectorCountFive) {
2005fd4e5da5Sopenharmony_ci  const std::string src = R"(
2006fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
2007fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
2008fd4e5da5Sopenharmony_ci%float_name = OpString "float"
2009fd4e5da5Sopenharmony_ci)";
2010fd4e5da5Sopenharmony_ci
2011fd4e5da5Sopenharmony_ci  const std::string constants = R"(
2012fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
2013fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
2014fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
2015fd4e5da5Sopenharmony_ci%true = OpConstantTrue %bool
2016fd4e5da5Sopenharmony_ci)";
2017fd4e5da5Sopenharmony_ci
2018fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
2019fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
2020fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
2021fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
2022fd4e5da5Sopenharmony_ci%vfloat_info = OpExtInst %void %DbgExt DebugTypeVector %float_info %u32_4
2023fd4e5da5Sopenharmony_ci%mfloat_info = OpExtInst %void %DbgExt DebugTypeMatrix %vfloat_info %u32_5 %true
2024fd4e5da5Sopenharmony_ci)";
2025fd4e5da5Sopenharmony_ci
2026fd4e5da5Sopenharmony_ci  const std::string extension = R"(
2027fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
2028fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
2029fd4e5da5Sopenharmony_ci)";
2030fd4e5da5Sopenharmony_ci
2031fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
2032fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
2033fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2034fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
2035fd4e5da5Sopenharmony_ci              HasSubstr("Vector Count must be positive "
2036fd4e5da5Sopenharmony_ci                        "integer less than or equal to 4"));
2037fd4e5da5Sopenharmony_ci}
2038fd4e5da5Sopenharmony_ci
2039fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugTypedef) {
2040fd4e5da5Sopenharmony_ci  const std::string src = R"(
2041fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
2042fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
2043fd4e5da5Sopenharmony_ci%float_name = OpString "float"
2044fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
2045fd4e5da5Sopenharmony_ci)";
2046fd4e5da5Sopenharmony_ci
2047fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
2048fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
2049fd4e5da5Sopenharmony_ci)";
2050fd4e5da5Sopenharmony_ci
2051fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
2052fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
2053fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
2054fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
2055fd4e5da5Sopenharmony_ci%foo_info = OpExtInst %void %DbgExt DebugTypedef %foo_name %float_info %dbg_src 1 1 %comp_unit
2056fd4e5da5Sopenharmony_ci)";
2057fd4e5da5Sopenharmony_ci
2058fd4e5da5Sopenharmony_ci  const std::string extension = R"(
2059fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
2060fd4e5da5Sopenharmony_ci)";
2061fd4e5da5Sopenharmony_ci
2062fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
2063fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, "", extension, "Vertex"));
2064fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
2065fd4e5da5Sopenharmony_ci}
2066fd4e5da5Sopenharmony_ci
2067fd4e5da5Sopenharmony_ciTEST_P(ValidateOpenCL100DebugInfoDebugTypedef, Fail) {
2068fd4e5da5Sopenharmony_ci  const std::string src = R"(
2069fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
2070fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
2071fd4e5da5Sopenharmony_ci%float_name = OpString "float"
2072fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
2073fd4e5da5Sopenharmony_ci)";
2074fd4e5da5Sopenharmony_ci
2075fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
2076fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
2077fd4e5da5Sopenharmony_ci)";
2078fd4e5da5Sopenharmony_ci
2079fd4e5da5Sopenharmony_ci  const auto& param = GetParam();
2080fd4e5da5Sopenharmony_ci
2081fd4e5da5Sopenharmony_ci  std::ostringstream ss;
2082fd4e5da5Sopenharmony_ci  ss << R"(
2083fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
2084fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
2085fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
2086fd4e5da5Sopenharmony_ci%foo_info = OpExtInst %void %DbgExt DebugTypedef )";
2087fd4e5da5Sopenharmony_ci  ss << param.first;
2088fd4e5da5Sopenharmony_ci
2089fd4e5da5Sopenharmony_ci  const std::string extension = R"(
2090fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
2091fd4e5da5Sopenharmony_ci)";
2092fd4e5da5Sopenharmony_ci
2093fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, size_const, ss.str(),
2094fd4e5da5Sopenharmony_ci                                                     "", extension, "Vertex"));
2095fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2096fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
2097fd4e5da5Sopenharmony_ci              HasSubstr("expected operand " + param.second +
2098fd4e5da5Sopenharmony_ci                        " must be a result id of "));
2099fd4e5da5Sopenharmony_ci}
2100fd4e5da5Sopenharmony_ci
2101fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(
2102fd4e5da5Sopenharmony_ci    AllOpenCL100DebugInfoFail, ValidateOpenCL100DebugInfoDebugTypedef,
2103fd4e5da5Sopenharmony_ci    ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
2104fd4e5da5Sopenharmony_ci        std::make_pair(R"(%dbg_src %float_info %dbg_src 1 1 %comp_unit)",
2105fd4e5da5Sopenharmony_ci                       "Name"),
2106fd4e5da5Sopenharmony_ci        std::make_pair(R"(%foo_name %dbg_src %dbg_src 1 1 %comp_unit)",
2107fd4e5da5Sopenharmony_ci                       "Base Type"),
2108fd4e5da5Sopenharmony_ci        std::make_pair(R"(%foo_name %float_info %comp_unit 1 1 %comp_unit)",
2109fd4e5da5Sopenharmony_ci                       "Source"),
2110fd4e5da5Sopenharmony_ci        std::make_pair(R"(%foo_name %float_info %dbg_src 1 1 %dbg_src)",
2111fd4e5da5Sopenharmony_ci                       "Parent"),
2112fd4e5da5Sopenharmony_ci    }));
2113fd4e5da5Sopenharmony_ci
2114fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugTypedef) {
2115fd4e5da5Sopenharmony_ci  const std::string src = R"(
2116fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
2117fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
2118fd4e5da5Sopenharmony_ci%float_name = OpString "float"
2119fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
2120fd4e5da5Sopenharmony_ci)";
2121fd4e5da5Sopenharmony_ci
2122fd4e5da5Sopenharmony_ci  const std::string constants = R"(
2123fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
2124fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
2125fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
2126fd4e5da5Sopenharmony_ci)";
2127fd4e5da5Sopenharmony_ci
2128fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
2129fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
2130fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
2131fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
2132fd4e5da5Sopenharmony_ci%foo_info = OpExtInst %void %DbgExt DebugTypedef %foo_name %float_info %dbg_src %u32_1 %u32_1 %comp_unit
2133fd4e5da5Sopenharmony_ci)";
2134fd4e5da5Sopenharmony_ci
2135fd4e5da5Sopenharmony_ci  const std::string extension = R"(
2136fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
2137fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
2138fd4e5da5Sopenharmony_ci)";
2139fd4e5da5Sopenharmony_ci
2140fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
2141fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
2142fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
2143fd4e5da5Sopenharmony_ci}
2144fd4e5da5Sopenharmony_ci
2145fd4e5da5Sopenharmony_ciTEST_P(ValidateVulkan100DebugInfoDebugTypedef, Fail) {
2146fd4e5da5Sopenharmony_ci  const std::string src = R"(
2147fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
2148fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
2149fd4e5da5Sopenharmony_ci%float_name = OpString "float"
2150fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
2151fd4e5da5Sopenharmony_ci)";
2152fd4e5da5Sopenharmony_ci
2153fd4e5da5Sopenharmony_ci  const std::string constants = R"(
2154fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
2155fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
2156fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
2157fd4e5da5Sopenharmony_ci)";
2158fd4e5da5Sopenharmony_ci
2159fd4e5da5Sopenharmony_ci  const auto& param = GetParam();
2160fd4e5da5Sopenharmony_ci
2161fd4e5da5Sopenharmony_ci  std::ostringstream ss;
2162fd4e5da5Sopenharmony_ci  ss << R"(
2163fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
2164fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
2165fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
2166fd4e5da5Sopenharmony_ci%foo_info = OpExtInst %void %DbgExt DebugTypedef )";
2167fd4e5da5Sopenharmony_ci  ss << param.first;
2168fd4e5da5Sopenharmony_ci
2169fd4e5da5Sopenharmony_ci  const std::string extension = R"(
2170fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
2171fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
2172fd4e5da5Sopenharmony_ci)";
2173fd4e5da5Sopenharmony_ci
2174fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, constants, ss.str(),
2175fd4e5da5Sopenharmony_ci                                                     "", extension, "Vertex"));
2176fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2177fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
2178fd4e5da5Sopenharmony_ci              HasSubstr("expected operand " + param.second +
2179fd4e5da5Sopenharmony_ci                        " must be a result id of "));
2180fd4e5da5Sopenharmony_ci}
2181fd4e5da5Sopenharmony_ci
2182fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(
2183fd4e5da5Sopenharmony_ci    AllVulkan100DebugInfoFail, ValidateVulkan100DebugInfoDebugTypedef,
2184fd4e5da5Sopenharmony_ci    ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
2185fd4e5da5Sopenharmony_ci        std::make_pair(
2186fd4e5da5Sopenharmony_ci            R"(%dbg_src %float_info %dbg_src %u32_1 %u32_1 %comp_unit)",
2187fd4e5da5Sopenharmony_ci            "Name"),
2188fd4e5da5Sopenharmony_ci        std::make_pair(
2189fd4e5da5Sopenharmony_ci            R"(%foo_name %dbg_src %dbg_src %u32_1 %u32_1 %comp_unit)",
2190fd4e5da5Sopenharmony_ci            "Base Type"),
2191fd4e5da5Sopenharmony_ci        std::make_pair(
2192fd4e5da5Sopenharmony_ci            R"(%foo_name %float_info %comp_unit %u32_1 %u32_1 %comp_unit)",
2193fd4e5da5Sopenharmony_ci            "Source"),
2194fd4e5da5Sopenharmony_ci        std::make_pair(
2195fd4e5da5Sopenharmony_ci            R"(%foo_name %float_info %dbg_src %u32_1 %u32_1 %dbg_src)",
2196fd4e5da5Sopenharmony_ci            "Parent"),
2197fd4e5da5Sopenharmony_ci    }));
2198fd4e5da5Sopenharmony_ci
2199fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugTypeFunction) {
2200fd4e5da5Sopenharmony_ci  const std::string src = R"(
2201fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
2202fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
2203fd4e5da5Sopenharmony_ci%main_name = OpString "main"
2204fd4e5da5Sopenharmony_ci%main_linkage_name = OpString "v_main"
2205fd4e5da5Sopenharmony_ci%float_name = OpString "float"
2206fd4e5da5Sopenharmony_ci)";
2207fd4e5da5Sopenharmony_ci
2208fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
2209fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
2210fd4e5da5Sopenharmony_ci)";
2211fd4e5da5Sopenharmony_ci
2212fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
2213fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
2214fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
2215fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
2216fd4e5da5Sopenharmony_ci%main_type_info1 = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void
2217fd4e5da5Sopenharmony_ci%main_type_info2 = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %float_info
2218fd4e5da5Sopenharmony_ci%main_type_info3 = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %float_info %float_info
2219fd4e5da5Sopenharmony_ci%main_type_info4 = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void %float_info %float_info
2220fd4e5da5Sopenharmony_ci)";
2221fd4e5da5Sopenharmony_ci
2222fd4e5da5Sopenharmony_ci  const std::string extension = R"(
2223fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
2224fd4e5da5Sopenharmony_ci)";
2225fd4e5da5Sopenharmony_ci
2226fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
2227fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, "", extension, "Vertex"));
2228fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
2229fd4e5da5Sopenharmony_ci}
2230fd4e5da5Sopenharmony_ci
2231fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugTypeFunctionFailReturn) {
2232fd4e5da5Sopenharmony_ci  const std::string src = R"(
2233fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
2234fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
2235fd4e5da5Sopenharmony_ci%main_name = OpString "main"
2236fd4e5da5Sopenharmony_ci%main_linkage_name = OpString "v_main"
2237fd4e5da5Sopenharmony_ci%float_name = OpString "float"
2238fd4e5da5Sopenharmony_ci)";
2239fd4e5da5Sopenharmony_ci
2240fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
2241fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
2242fd4e5da5Sopenharmony_ci)";
2243fd4e5da5Sopenharmony_ci
2244fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
2245fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
2246fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
2247fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
2248fd4e5da5Sopenharmony_ci%main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %dbg_src %float_info
2249fd4e5da5Sopenharmony_ci)";
2250fd4e5da5Sopenharmony_ci
2251fd4e5da5Sopenharmony_ci  const std::string extension = R"(
2252fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
2253fd4e5da5Sopenharmony_ci)";
2254fd4e5da5Sopenharmony_ci
2255fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
2256fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, "", extension, "Vertex"));
2257fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2258fd4e5da5Sopenharmony_ci  EXPECT_THAT(
2259fd4e5da5Sopenharmony_ci      getDiagnosticString(),
2260fd4e5da5Sopenharmony_ci      HasSubstr("expected operand Return Type is not a valid debug type"));
2261fd4e5da5Sopenharmony_ci}
2262fd4e5da5Sopenharmony_ci
2263fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugTypeFunctionFailParam) {
2264fd4e5da5Sopenharmony_ci  const std::string src = R"(
2265fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
2266fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
2267fd4e5da5Sopenharmony_ci%main_name = OpString "main"
2268fd4e5da5Sopenharmony_ci%main_linkage_name = OpString "v_main"
2269fd4e5da5Sopenharmony_ci%float_name = OpString "float"
2270fd4e5da5Sopenharmony_ci)";
2271fd4e5da5Sopenharmony_ci
2272fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
2273fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
2274fd4e5da5Sopenharmony_ci)";
2275fd4e5da5Sopenharmony_ci
2276fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
2277fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
2278fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
2279fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
2280fd4e5da5Sopenharmony_ci%main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %float_info %void
2281fd4e5da5Sopenharmony_ci)";
2282fd4e5da5Sopenharmony_ci
2283fd4e5da5Sopenharmony_ci  const std::string extension = R"(
2284fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
2285fd4e5da5Sopenharmony_ci)";
2286fd4e5da5Sopenharmony_ci
2287fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
2288fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, "", extension, "Vertex"));
2289fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2290fd4e5da5Sopenharmony_ci  EXPECT_THAT(
2291fd4e5da5Sopenharmony_ci      getDiagnosticString(),
2292fd4e5da5Sopenharmony_ci      HasSubstr("expected operand Parameter Types is not a valid debug type"));
2293fd4e5da5Sopenharmony_ci}
2294fd4e5da5Sopenharmony_ci
2295fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugTypeFunctionAndParams) {
2296fd4e5da5Sopenharmony_ci  const std::string src = R"(
2297fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
2298fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
2299fd4e5da5Sopenharmony_ci%main_name = OpString "main"
2300fd4e5da5Sopenharmony_ci%main_linkage_name = OpString "v_main"
2301fd4e5da5Sopenharmony_ci%float_name = OpString "float"
2302fd4e5da5Sopenharmony_ci)";
2303fd4e5da5Sopenharmony_ci
2304fd4e5da5Sopenharmony_ci  const std::string constants = R"(
2305fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
2306fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
2307fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
2308fd4e5da5Sopenharmony_ci)";
2309fd4e5da5Sopenharmony_ci
2310fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
2311fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
2312fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
2313fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
2314fd4e5da5Sopenharmony_ci%main_type_info1 = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %void
2315fd4e5da5Sopenharmony_ci%main_type_info2 = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %float_info
2316fd4e5da5Sopenharmony_ci%main_type_info3 = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %float_info %float_info
2317fd4e5da5Sopenharmony_ci%main_type_info4 = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %void %float_info %float_info
2318fd4e5da5Sopenharmony_ci)";
2319fd4e5da5Sopenharmony_ci
2320fd4e5da5Sopenharmony_ci  const std::string extension = R"(
2321fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
2322fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
2323fd4e5da5Sopenharmony_ci)";
2324fd4e5da5Sopenharmony_ci
2325fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
2326fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
2327fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
2328fd4e5da5Sopenharmony_ci}
2329fd4e5da5Sopenharmony_ci
2330fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugTypeFunctionFailReturn) {
2331fd4e5da5Sopenharmony_ci  const std::string src = R"(
2332fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
2333fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
2334fd4e5da5Sopenharmony_ci%main_name = OpString "main"
2335fd4e5da5Sopenharmony_ci%main_linkage_name = OpString "v_main"
2336fd4e5da5Sopenharmony_ci%float_name = OpString "float"
2337fd4e5da5Sopenharmony_ci)";
2338fd4e5da5Sopenharmony_ci
2339fd4e5da5Sopenharmony_ci  const std::string constants = R"(
2340fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
2341fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
2342fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
2343fd4e5da5Sopenharmony_ci)";
2344fd4e5da5Sopenharmony_ci
2345fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
2346fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
2347fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
2348fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
2349fd4e5da5Sopenharmony_ci%main_type_info = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %dbg_src %float_info
2350fd4e5da5Sopenharmony_ci)";
2351fd4e5da5Sopenharmony_ci
2352fd4e5da5Sopenharmony_ci  const std::string extension = R"(
2353fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
2354fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
2355fd4e5da5Sopenharmony_ci)";
2356fd4e5da5Sopenharmony_ci
2357fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
2358fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
2359fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2360fd4e5da5Sopenharmony_ci  EXPECT_THAT(
2361fd4e5da5Sopenharmony_ci      getDiagnosticString(),
2362fd4e5da5Sopenharmony_ci      HasSubstr("expected operand Return Type is not a valid debug type"));
2363fd4e5da5Sopenharmony_ci}
2364fd4e5da5Sopenharmony_ci
2365fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugTypeFunctionFailParam) {
2366fd4e5da5Sopenharmony_ci  const std::string src = R"(
2367fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
2368fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
2369fd4e5da5Sopenharmony_ci%main_name = OpString "main"
2370fd4e5da5Sopenharmony_ci%main_linkage_name = OpString "v_main"
2371fd4e5da5Sopenharmony_ci%float_name = OpString "float"
2372fd4e5da5Sopenharmony_ci)";
2373fd4e5da5Sopenharmony_ci
2374fd4e5da5Sopenharmony_ci  const std::string constants = R"(
2375fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
2376fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
2377fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
2378fd4e5da5Sopenharmony_ci)";
2379fd4e5da5Sopenharmony_ci
2380fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
2381fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
2382fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
2383fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
2384fd4e5da5Sopenharmony_ci%main_type_info = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %float_info %void
2385fd4e5da5Sopenharmony_ci)";
2386fd4e5da5Sopenharmony_ci
2387fd4e5da5Sopenharmony_ci  const std::string extension = R"(
2388fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
2389fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
2390fd4e5da5Sopenharmony_ci)";
2391fd4e5da5Sopenharmony_ci
2392fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
2393fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
2394fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2395fd4e5da5Sopenharmony_ci  EXPECT_THAT(
2396fd4e5da5Sopenharmony_ci      getDiagnosticString(),
2397fd4e5da5Sopenharmony_ci      HasSubstr("expected operand Parameter Types is not a valid debug type"));
2398fd4e5da5Sopenharmony_ci}
2399fd4e5da5Sopenharmony_ci
2400fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugTypeEnum) {
2401fd4e5da5Sopenharmony_ci  const std::string src = R"(
2402fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
2403fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
2404fd4e5da5Sopenharmony_ci%float_name = OpString "float"
2405fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
2406fd4e5da5Sopenharmony_ci)";
2407fd4e5da5Sopenharmony_ci
2408fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
2409fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
2410fd4e5da5Sopenharmony_ci)";
2411fd4e5da5Sopenharmony_ci
2412fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
2413fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
2414fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
2415fd4e5da5Sopenharmony_ci%none = OpExtInst %void %DbgExt DebugInfoNone
2416fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
2417fd4e5da5Sopenharmony_ci%foo_info1 = OpExtInst %void %DbgExt DebugTypeEnum %foo_name %float_info %dbg_src 1 1 %comp_unit %int_32 FlagIsPublic %u32_0 %foo_name %u32_1 %foo_name
2418fd4e5da5Sopenharmony_ci%foo_info2 = OpExtInst %void %DbgExt DebugTypeEnum %foo_name %none %dbg_src 1 1 %comp_unit %int_32 FlagIsPublic %u32_0 %foo_name %u32_1 %foo_name
2419fd4e5da5Sopenharmony_ci%foo_info3 = OpExtInst %void %DbgExt DebugTypeEnum %foo_name %none %dbg_src 1 1 %comp_unit %int_32 FlagIsPublic
2420fd4e5da5Sopenharmony_ci)";
2421fd4e5da5Sopenharmony_ci
2422fd4e5da5Sopenharmony_ci  const std::string extension = R"(
2423fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
2424fd4e5da5Sopenharmony_ci)";
2425fd4e5da5Sopenharmony_ci
2426fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
2427fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, "", extension, "Vertex"));
2428fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
2429fd4e5da5Sopenharmony_ci}
2430fd4e5da5Sopenharmony_ci
2431fd4e5da5Sopenharmony_ciTEST_P(ValidateOpenCL100DebugInfoDebugTypeEnum, Fail) {
2432fd4e5da5Sopenharmony_ci  const std::string src = R"(
2433fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
2434fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
2435fd4e5da5Sopenharmony_ci%float_name = OpString "float"
2436fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
2437fd4e5da5Sopenharmony_ci)";
2438fd4e5da5Sopenharmony_ci
2439fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
2440fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
2441fd4e5da5Sopenharmony_ci)";
2442fd4e5da5Sopenharmony_ci
2443fd4e5da5Sopenharmony_ci  const auto& param = GetParam();
2444fd4e5da5Sopenharmony_ci
2445fd4e5da5Sopenharmony_ci  std::ostringstream ss;
2446fd4e5da5Sopenharmony_ci  ss << R"(
2447fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
2448fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
2449fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
2450fd4e5da5Sopenharmony_ci%foo_info = OpExtInst %void %DbgExt DebugTypeEnum )";
2451fd4e5da5Sopenharmony_ci  ss << param.first;
2452fd4e5da5Sopenharmony_ci
2453fd4e5da5Sopenharmony_ci  const std::string extension = R"(
2454fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
2455fd4e5da5Sopenharmony_ci)";
2456fd4e5da5Sopenharmony_ci
2457fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, size_const, ss.str(),
2458fd4e5da5Sopenharmony_ci                                                     "", extension, "Vertex"));
2459fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2460fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
2461fd4e5da5Sopenharmony_ci              HasSubstr("expected operand " + param.second));
2462fd4e5da5Sopenharmony_ci}
2463fd4e5da5Sopenharmony_ci
2464fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(
2465fd4e5da5Sopenharmony_ci    AllOpenCL100DebugInfoFail, ValidateOpenCL100DebugInfoDebugTypeEnum,
2466fd4e5da5Sopenharmony_ci    ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
2467fd4e5da5Sopenharmony_ci        std::make_pair(
2468fd4e5da5Sopenharmony_ci            R"(%dbg_src %float_info %dbg_src 1 1 %comp_unit %int_32 FlagIsPublic %u32_0 %foo_name)",
2469fd4e5da5Sopenharmony_ci            "Name"),
2470fd4e5da5Sopenharmony_ci        std::make_pair(
2471fd4e5da5Sopenharmony_ci            R"(%foo_name %dbg_src %dbg_src 1 1 %comp_unit %int_32 FlagIsPublic %u32_0 %foo_name)",
2472fd4e5da5Sopenharmony_ci            "Underlying Types"),
2473fd4e5da5Sopenharmony_ci        std::make_pair(
2474fd4e5da5Sopenharmony_ci            R"(%foo_name %float_info %comp_unit 1 1 %comp_unit %int_32 FlagIsPublic %u32_0 %foo_name)",
2475fd4e5da5Sopenharmony_ci            "Source"),
2476fd4e5da5Sopenharmony_ci        std::make_pair(
2477fd4e5da5Sopenharmony_ci            R"(%foo_name %float_info %dbg_src 1 1 %dbg_src %int_32 FlagIsPublic %u32_0 %foo_name)",
2478fd4e5da5Sopenharmony_ci            "Parent"),
2479fd4e5da5Sopenharmony_ci        std::make_pair(
2480fd4e5da5Sopenharmony_ci            R"(%foo_name %float_info %dbg_src 1 1 %comp_unit %void FlagIsPublic %u32_0 %foo_name)",
2481fd4e5da5Sopenharmony_ci            "Size"),
2482fd4e5da5Sopenharmony_ci        std::make_pair(
2483fd4e5da5Sopenharmony_ci            R"(%foo_name %float_info %dbg_src 1 1 %comp_unit %u32_0 FlagIsPublic %u32_0 %foo_name)",
2484fd4e5da5Sopenharmony_ci            "Size"),
2485fd4e5da5Sopenharmony_ci        std::make_pair(
2486fd4e5da5Sopenharmony_ci            R"(%foo_name %float_info %dbg_src 1 1 %comp_unit %int_32 FlagIsPublic %foo_name %foo_name)",
2487fd4e5da5Sopenharmony_ci            "Value"),
2488fd4e5da5Sopenharmony_ci        std::make_pair(
2489fd4e5da5Sopenharmony_ci            R"(%foo_name %float_info %dbg_src 1 1 %comp_unit %int_32 FlagIsPublic %u32_0 %u32_1)",
2490fd4e5da5Sopenharmony_ci            "Name"),
2491fd4e5da5Sopenharmony_ci    }));
2492fd4e5da5Sopenharmony_ci
2493fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugTypeEnum) {
2494fd4e5da5Sopenharmony_ci  const std::string src = R"(
2495fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
2496fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
2497fd4e5da5Sopenharmony_ci%float_name = OpString "float"
2498fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
2499fd4e5da5Sopenharmony_ci)";
2500fd4e5da5Sopenharmony_ci
2501fd4e5da5Sopenharmony_ci  const std::string constants = R"(
2502fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
2503fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
2504fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
2505fd4e5da5Sopenharmony_ci)";
2506fd4e5da5Sopenharmony_ci
2507fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
2508fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
2509fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
2510fd4e5da5Sopenharmony_ci%none = OpExtInst %void %DbgExt DebugInfoNone
2511fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
2512fd4e5da5Sopenharmony_ci%foo_info1 = OpExtInst %void %DbgExt DebugTypeEnum %foo_name %float_info %dbg_src %u32_1 %u32_1 %comp_unit %u32_32 %u32_3 %u32_0 %foo_name %u32_1 %foo_name
2513fd4e5da5Sopenharmony_ci%foo_info2 = OpExtInst %void %DbgExt DebugTypeEnum %foo_name %none %dbg_src %u32_1 %u32_1 %comp_unit %u32_32 %u32_3 %u32_0 %foo_name %u32_1 %foo_name
2514fd4e5da5Sopenharmony_ci%foo_info3 = OpExtInst %void %DbgExt DebugTypeEnum %foo_name %none %dbg_src %u32_1 %u32_1 %comp_unit %u32_32 %u32_3
2515fd4e5da5Sopenharmony_ci)";
2516fd4e5da5Sopenharmony_ci
2517fd4e5da5Sopenharmony_ci  const std::string extension = R"(
2518fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
2519fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
2520fd4e5da5Sopenharmony_ci)";
2521fd4e5da5Sopenharmony_ci
2522fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
2523fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
2524fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
2525fd4e5da5Sopenharmony_ci}
2526fd4e5da5Sopenharmony_ci
2527fd4e5da5Sopenharmony_ciTEST_P(ValidateVulkan100DebugInfoDebugTypeEnum, Fail) {
2528fd4e5da5Sopenharmony_ci  const std::string src = R"(
2529fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
2530fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
2531fd4e5da5Sopenharmony_ci%float_name = OpString "float"
2532fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
2533fd4e5da5Sopenharmony_ci)";
2534fd4e5da5Sopenharmony_ci
2535fd4e5da5Sopenharmony_ci  const std::string constants = R"(
2536fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
2537fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
2538fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
2539fd4e5da5Sopenharmony_ci)";
2540fd4e5da5Sopenharmony_ci
2541fd4e5da5Sopenharmony_ci  const auto& param = GetParam();
2542fd4e5da5Sopenharmony_ci
2543fd4e5da5Sopenharmony_ci  std::ostringstream ss;
2544fd4e5da5Sopenharmony_ci  ss << R"(
2545fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
2546fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
2547fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
2548fd4e5da5Sopenharmony_ci%foo_info = OpExtInst %void %DbgExt DebugTypeEnum )";
2549fd4e5da5Sopenharmony_ci  ss << param.first;
2550fd4e5da5Sopenharmony_ci
2551fd4e5da5Sopenharmony_ci  const std::string extension = R"(
2552fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
2553fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
2554fd4e5da5Sopenharmony_ci)";
2555fd4e5da5Sopenharmony_ci
2556fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, constants, ss.str(),
2557fd4e5da5Sopenharmony_ci                                                     "", extension, "Vertex"));
2558fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2559fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
2560fd4e5da5Sopenharmony_ci              HasSubstr("expected operand " + param.second));
2561fd4e5da5Sopenharmony_ci}
2562fd4e5da5Sopenharmony_ci
2563fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(
2564fd4e5da5Sopenharmony_ci    AllVulkan100DebugInfoFail, ValidateVulkan100DebugInfoDebugTypeEnum,
2565fd4e5da5Sopenharmony_ci    ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
2566fd4e5da5Sopenharmony_ci        std::make_pair(
2567fd4e5da5Sopenharmony_ci            R"(%dbg_src %float_info %dbg_src %u32_1 %u32_1 %comp_unit %u32_32 %u32_3 %u32_0 %foo_name)",
2568fd4e5da5Sopenharmony_ci            "Name"),
2569fd4e5da5Sopenharmony_ci        std::make_pair(
2570fd4e5da5Sopenharmony_ci            R"(%foo_name %dbg_src %dbg_src %u32_1 %u32_1 %comp_unit %u32_32 %u32_3 %u32_0 %foo_name)",
2571fd4e5da5Sopenharmony_ci            "Underlying Types"),
2572fd4e5da5Sopenharmony_ci        std::make_pair(
2573fd4e5da5Sopenharmony_ci            R"(%foo_name %float_info %comp_unit %u32_1 %u32_1 %comp_unit %u32_32 %u32_3 %u32_0 %foo_name)",
2574fd4e5da5Sopenharmony_ci            "Source"),
2575fd4e5da5Sopenharmony_ci        std::make_pair(
2576fd4e5da5Sopenharmony_ci            R"(%foo_name %float_info %dbg_src %u32_1 %u32_1 %dbg_src %u32_32 %u32_3 %u32_0 %foo_name)",
2577fd4e5da5Sopenharmony_ci            "Parent"),
2578fd4e5da5Sopenharmony_ci        std::make_pair(
2579fd4e5da5Sopenharmony_ci            R"(%foo_name %float_info %dbg_src %u32_1 %u32_1 %comp_unit %void %u32_3 %u32_0 %foo_name)",
2580fd4e5da5Sopenharmony_ci            "Size"),
2581fd4e5da5Sopenharmony_ci        std::make_pair(
2582fd4e5da5Sopenharmony_ci            R"(%foo_name %float_info %dbg_src %u32_1 %u32_1 %comp_unit %u32_0 %u32_3 %u32_0 %foo_name)",
2583fd4e5da5Sopenharmony_ci            "Size"),
2584fd4e5da5Sopenharmony_ci        std::make_pair(
2585fd4e5da5Sopenharmony_ci            R"(%foo_name %float_info %dbg_src %u32_1 %u32_1 %comp_unit %u32_32 %u32_3 %foo_name %foo_name)",
2586fd4e5da5Sopenharmony_ci            "Value"),
2587fd4e5da5Sopenharmony_ci        std::make_pair(
2588fd4e5da5Sopenharmony_ci            R"(%foo_name %float_info %dbg_src %u32_1 %u32_1 %comp_unit %u32_32 %u32_3 %u32_0 %u32_1)",
2589fd4e5da5Sopenharmony_ci            "Name"),
2590fd4e5da5Sopenharmony_ci    }));
2591fd4e5da5Sopenharmony_ci
2592fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugTypeCompositeFunctionAndInheritance) {
2593fd4e5da5Sopenharmony_ci  const std::string src = R"(
2594fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
2595fd4e5da5Sopenharmony_ci%code = OpString "struct VS_OUTPUT {
2596fd4e5da5Sopenharmony_ci  float4 pos : SV_POSITION;
2597fd4e5da5Sopenharmony_ci};
2598fd4e5da5Sopenharmony_cistruct foo : VS_OUTPUT {
2599fd4e5da5Sopenharmony_ci};
2600fd4e5da5Sopenharmony_cimain() {}
2601fd4e5da5Sopenharmony_ci"
2602fd4e5da5Sopenharmony_ci%VS_OUTPUT_name = OpString "struct VS_OUTPUT"
2603fd4e5da5Sopenharmony_ci%float_name = OpString "float"
2604fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
2605fd4e5da5Sopenharmony_ci%VS_OUTPUT_pos_name = OpString "pos : SV_POSITION"
2606fd4e5da5Sopenharmony_ci%VS_OUTPUT_linkage_name = OpString "VS_OUTPUT"
2607fd4e5da5Sopenharmony_ci%main_name = OpString "main"
2608fd4e5da5Sopenharmony_ci%main_linkage_name = OpString "v4f_main_f"
2609fd4e5da5Sopenharmony_ci)";
2610fd4e5da5Sopenharmony_ci
2611fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
2612fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
2613fd4e5da5Sopenharmony_ci%int_128 = OpConstant %u32 128
2614fd4e5da5Sopenharmony_ci)";
2615fd4e5da5Sopenharmony_ci
2616fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
2617fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
2618fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
2619fd4e5da5Sopenharmony_ci%VS_OUTPUT_info = OpExtInst %void %DbgExt DebugTypeComposite %VS_OUTPUT_name Structure %dbg_src 1 1 %comp_unit %VS_OUTPUT_linkage_name %int_128 FlagIsPublic %VS_OUTPUT_pos_info %main_info %child
2620fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
2621fd4e5da5Sopenharmony_ci%v4float_info = OpExtInst %void %DbgExt DebugTypeVector %float_info 4
2622fd4e5da5Sopenharmony_ci%VS_OUTPUT_pos_info = OpExtInst %void %DbgExt DebugTypeMember %VS_OUTPUT_pos_name %v4float_info %dbg_src 2 3 %VS_OUTPUT_info %u32_0 %int_128 FlagIsPublic
2623fd4e5da5Sopenharmony_ci%main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %v4float_info %float_info
2624fd4e5da5Sopenharmony_ci%main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 12 1 %comp_unit %main_linkage_name FlagIsPublic 13 %main
2625fd4e5da5Sopenharmony_ci%foo_info = OpExtInst %void %DbgExt DebugTypeComposite %foo_name Structure %dbg_src 1 1 %comp_unit %foo_name %u32_0 FlagIsPublic
2626fd4e5da5Sopenharmony_ci%child = OpExtInst %void %DbgExt DebugTypeInheritance %foo_info %VS_OUTPUT_info %int_128 %int_128 FlagIsPublic
2627fd4e5da5Sopenharmony_ci)";
2628fd4e5da5Sopenharmony_ci
2629fd4e5da5Sopenharmony_ci  const std::string extension = R"(
2630fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
2631fd4e5da5Sopenharmony_ci)";
2632fd4e5da5Sopenharmony_ci
2633fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
2634fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, "", extension, "Vertex"));
2635fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
2636fd4e5da5Sopenharmony_ci}
2637fd4e5da5Sopenharmony_ci
2638fd4e5da5Sopenharmony_ciTEST_P(ValidateOpenCL100DebugInfoDebugTypeComposite, Fail) {
2639fd4e5da5Sopenharmony_ci  const std::string src = R"(
2640fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
2641fd4e5da5Sopenharmony_ci%code = OpString "struct VS_OUTPUT {
2642fd4e5da5Sopenharmony_ci  float4 pos : SV_POSITION;
2643fd4e5da5Sopenharmony_ci};
2644fd4e5da5Sopenharmony_cistruct foo : VS_OUTPUT {
2645fd4e5da5Sopenharmony_ci};
2646fd4e5da5Sopenharmony_cimain() {}
2647fd4e5da5Sopenharmony_ci"
2648fd4e5da5Sopenharmony_ci%VS_OUTPUT_name = OpString "struct VS_OUTPUT"
2649fd4e5da5Sopenharmony_ci%float_name = OpString "float"
2650fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
2651fd4e5da5Sopenharmony_ci%VS_OUTPUT_pos_name = OpString "pos : SV_POSITION"
2652fd4e5da5Sopenharmony_ci%VS_OUTPUT_linkage_name = OpString "VS_OUTPUT"
2653fd4e5da5Sopenharmony_ci%main_name = OpString "main"
2654fd4e5da5Sopenharmony_ci%main_linkage_name = OpString "v4f_main_f"
2655fd4e5da5Sopenharmony_ci)";
2656fd4e5da5Sopenharmony_ci
2657fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
2658fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
2659fd4e5da5Sopenharmony_ci%int_128 = OpConstant %u32 128
2660fd4e5da5Sopenharmony_ci)";
2661fd4e5da5Sopenharmony_ci
2662fd4e5da5Sopenharmony_ci  const auto& param = GetParam();
2663fd4e5da5Sopenharmony_ci
2664fd4e5da5Sopenharmony_ci  std::ostringstream ss;
2665fd4e5da5Sopenharmony_ci  ss << R"(
2666fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
2667fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
2668fd4e5da5Sopenharmony_ci%VS_OUTPUT_info = OpExtInst %void %DbgExt DebugTypeComposite )";
2669fd4e5da5Sopenharmony_ci  ss << param.first;
2670fd4e5da5Sopenharmony_ci  ss << R"(
2671fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
2672fd4e5da5Sopenharmony_ci%v4float_info = OpExtInst %void %DbgExt DebugTypeVector %float_info 4
2673fd4e5da5Sopenharmony_ci%VS_OUTPUT_pos_info = OpExtInst %void %DbgExt DebugTypeMember %VS_OUTPUT_pos_name %v4float_info %dbg_src 2 3 %VS_OUTPUT_info %u32_0 %int_128 FlagIsPublic
2674fd4e5da5Sopenharmony_ci%main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %v4float_info %float_info
2675fd4e5da5Sopenharmony_ci%main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 12 1 %comp_unit %main_linkage_name FlagIsPublic 13 %main
2676fd4e5da5Sopenharmony_ci%foo_info = OpExtInst %void %DbgExt DebugTypeComposite %foo_name Structure %dbg_src 1 1 %comp_unit %foo_name %u32_0 FlagIsPublic
2677fd4e5da5Sopenharmony_ci%child = OpExtInst %void %DbgExt DebugTypeInheritance %foo_info %VS_OUTPUT_info %int_128 %int_128 FlagIsPublic
2678fd4e5da5Sopenharmony_ci)";
2679fd4e5da5Sopenharmony_ci
2680fd4e5da5Sopenharmony_ci  const std::string extension = R"(
2681fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
2682fd4e5da5Sopenharmony_ci)";
2683fd4e5da5Sopenharmony_ci
2684fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, size_const, ss.str(),
2685fd4e5da5Sopenharmony_ci                                                     "", extension, "Vertex"));
2686fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2687fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
2688fd4e5da5Sopenharmony_ci              HasSubstr("expected operand " + param.second + " must be "));
2689fd4e5da5Sopenharmony_ci}
2690fd4e5da5Sopenharmony_ci
2691fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(
2692fd4e5da5Sopenharmony_ci    AllOpenCL100DebugInfoFail, ValidateOpenCL100DebugInfoDebugTypeComposite,
2693fd4e5da5Sopenharmony_ci    ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
2694fd4e5da5Sopenharmony_ci        std::make_pair(
2695fd4e5da5Sopenharmony_ci            R"(%dbg_src Structure %dbg_src 1 1 %comp_unit %VS_OUTPUT_linkage_name %int_128 FlagIsPublic %VS_OUTPUT_pos_info %main_info %child)",
2696fd4e5da5Sopenharmony_ci            "Name"),
2697fd4e5da5Sopenharmony_ci        std::make_pair(
2698fd4e5da5Sopenharmony_ci            R"(%VS_OUTPUT_name Structure %comp_unit 1 1 %comp_unit %VS_OUTPUT_linkage_name %int_128 FlagIsPublic %VS_OUTPUT_pos_info %main_info %child)",
2699fd4e5da5Sopenharmony_ci            "Source"),
2700fd4e5da5Sopenharmony_ci        std::make_pair(
2701fd4e5da5Sopenharmony_ci            R"(%VS_OUTPUT_name Structure %dbg_src 1 1 %dbg_src %VS_OUTPUT_linkage_name %int_128 FlagIsPublic %VS_OUTPUT_pos_info %main_info %child)",
2702fd4e5da5Sopenharmony_ci            "Parent"),
2703fd4e5da5Sopenharmony_ci        std::make_pair(
2704fd4e5da5Sopenharmony_ci            R"(%VS_OUTPUT_name Structure %dbg_src 1 1 %comp_unit %int_128 %int_128 FlagIsPublic %VS_OUTPUT_pos_info %main_info %child)",
2705fd4e5da5Sopenharmony_ci            "Linkage Name"),
2706fd4e5da5Sopenharmony_ci        std::make_pair(
2707fd4e5da5Sopenharmony_ci            R"(%VS_OUTPUT_name Structure %dbg_src 1 1 %comp_unit %VS_OUTPUT_linkage_name %dbg_src FlagIsPublic %VS_OUTPUT_pos_info %main_info %child)",
2708fd4e5da5Sopenharmony_ci            "Size"),
2709fd4e5da5Sopenharmony_ci        std::make_pair(
2710fd4e5da5Sopenharmony_ci            R"(%VS_OUTPUT_name Structure %dbg_src 1 1 %comp_unit %VS_OUTPUT_linkage_name %int_128 FlagIsPublic %dbg_src %main_info %child)",
2711fd4e5da5Sopenharmony_ci            "Members"),
2712fd4e5da5Sopenharmony_ci        std::make_pair(
2713fd4e5da5Sopenharmony_ci            R"(%VS_OUTPUT_name Structure %dbg_src 1 1 %comp_unit %VS_OUTPUT_linkage_name %int_128 FlagIsPublic %VS_OUTPUT_pos_info %dbg_src %child)",
2714fd4e5da5Sopenharmony_ci            "Members"),
2715fd4e5da5Sopenharmony_ci        std::make_pair(
2716fd4e5da5Sopenharmony_ci            R"(%VS_OUTPUT_name Structure %dbg_src 1 1 %comp_unit %VS_OUTPUT_linkage_name %int_128 FlagIsPublic %VS_OUTPUT_pos_info %main_info %dbg_src)",
2717fd4e5da5Sopenharmony_ci            "Members"),
2718fd4e5da5Sopenharmony_ci    }));
2719fd4e5da5Sopenharmony_ci
2720fd4e5da5Sopenharmony_ciTEST_P(ValidateOpenCL100DebugInfoDebugTypeMember, Fail) {
2721fd4e5da5Sopenharmony_ci  const std::string src = R"(
2722fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
2723fd4e5da5Sopenharmony_ci%code = OpString "struct VS_OUTPUT {
2724fd4e5da5Sopenharmony_ci  float pos : SV_POSITION;
2725fd4e5da5Sopenharmony_ci};
2726fd4e5da5Sopenharmony_cimain() {}
2727fd4e5da5Sopenharmony_ci"
2728fd4e5da5Sopenharmony_ci%VS_OUTPUT_name = OpString "struct VS_OUTPUT"
2729fd4e5da5Sopenharmony_ci%float_name = OpString "float"
2730fd4e5da5Sopenharmony_ci%VS_OUTPUT_pos_name = OpString "pos : SV_POSITION"
2731fd4e5da5Sopenharmony_ci%VS_OUTPUT_linkage_name = OpString "VS_OUTPUT"
2732fd4e5da5Sopenharmony_ci)";
2733fd4e5da5Sopenharmony_ci
2734fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
2735fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
2736fd4e5da5Sopenharmony_ci)";
2737fd4e5da5Sopenharmony_ci
2738fd4e5da5Sopenharmony_ci  const auto& param = GetParam();
2739fd4e5da5Sopenharmony_ci
2740fd4e5da5Sopenharmony_ci  std::ostringstream ss;
2741fd4e5da5Sopenharmony_ci  ss << R"(
2742fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
2743fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
2744fd4e5da5Sopenharmony_ci%VS_OUTPUT_info = OpExtInst %void %DbgExt DebugTypeComposite %VS_OUTPUT_name Structure %dbg_src 1 1 %comp_unit %VS_OUTPUT_linkage_name %int_32 FlagIsPublic %VS_OUTPUT_pos_info
2745fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
2746fd4e5da5Sopenharmony_ci%VS_OUTPUT_pos_info = OpExtInst %void %DbgExt DebugTypeMember )";
2747fd4e5da5Sopenharmony_ci  ss << param.first;
2748fd4e5da5Sopenharmony_ci
2749fd4e5da5Sopenharmony_ci  const std::string extension = R"(
2750fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
2751fd4e5da5Sopenharmony_ci)";
2752fd4e5da5Sopenharmony_ci
2753fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, size_const, ss.str(),
2754fd4e5da5Sopenharmony_ci                                                     "", extension, "Vertex"));
2755fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2756fd4e5da5Sopenharmony_ci  if (!param.second.empty()) {
2757fd4e5da5Sopenharmony_ci    EXPECT_THAT(getDiagnosticString(),
2758fd4e5da5Sopenharmony_ci                HasSubstr("expected operand " + param.second +
2759fd4e5da5Sopenharmony_ci                          " must be a result id of "));
2760fd4e5da5Sopenharmony_ci  }
2761fd4e5da5Sopenharmony_ci}
2762fd4e5da5Sopenharmony_ci
2763fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(
2764fd4e5da5Sopenharmony_ci    AllOpenCL100DebugInfoFail, ValidateOpenCL100DebugInfoDebugTypeMember,
2765fd4e5da5Sopenharmony_ci    ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
2766fd4e5da5Sopenharmony_ci        std::make_pair(
2767fd4e5da5Sopenharmony_ci            R"(%dbg_src %float_info %dbg_src 2 3 %VS_OUTPUT_info %u32_0 %int_32 FlagIsPublic)",
2768fd4e5da5Sopenharmony_ci            "Name"),
2769fd4e5da5Sopenharmony_ci        std::make_pair(
2770fd4e5da5Sopenharmony_ci            R"(%VS_OUTPUT_pos_name %dbg_src %dbg_src 2 3 %VS_OUTPUT_info %u32_0 %int_32 FlagIsPublic)",
2771fd4e5da5Sopenharmony_ci            ""),
2772fd4e5da5Sopenharmony_ci        std::make_pair(
2773fd4e5da5Sopenharmony_ci            R"(%VS_OUTPUT_pos_name %float_info %float_info 2 3 %VS_OUTPUT_info %u32_0 %int_32 FlagIsPublic)",
2774fd4e5da5Sopenharmony_ci            "Source"),
2775fd4e5da5Sopenharmony_ci        std::make_pair(
2776fd4e5da5Sopenharmony_ci            R"(%VS_OUTPUT_pos_name %float_info %dbg_src 2 3 %float_info %u32_0 %int_32 FlagIsPublic)",
2777fd4e5da5Sopenharmony_ci            "Parent"),
2778fd4e5da5Sopenharmony_ci        std::make_pair(
2779fd4e5da5Sopenharmony_ci            R"(%VS_OUTPUT_pos_name %float_info %dbg_src 2 3 %VS_OUTPUT_info %void %int_32 FlagIsPublic)",
2780fd4e5da5Sopenharmony_ci            "Offset"),
2781fd4e5da5Sopenharmony_ci        std::make_pair(
2782fd4e5da5Sopenharmony_ci            R"(%VS_OUTPUT_pos_name %float_info %dbg_src 2 3 %VS_OUTPUT_info %u32_0 %void FlagIsPublic)",
2783fd4e5da5Sopenharmony_ci            "Size"),
2784fd4e5da5Sopenharmony_ci    }));
2785fd4e5da5Sopenharmony_ci
2786fd4e5da5Sopenharmony_ciTEST_P(ValidateOpenCL100DebugInfoDebugTypeInheritance, Fail) {
2787fd4e5da5Sopenharmony_ci  const std::string src = R"(
2788fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
2789fd4e5da5Sopenharmony_ci%code = OpString "struct VS_OUTPUT {};
2790fd4e5da5Sopenharmony_cistruct foo : VS_OUTPUT {};
2791fd4e5da5Sopenharmony_ci"
2792fd4e5da5Sopenharmony_ci%VS_OUTPUT_name = OpString "struct VS_OUTPUT"
2793fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
2794fd4e5da5Sopenharmony_ci)";
2795fd4e5da5Sopenharmony_ci
2796fd4e5da5Sopenharmony_ci  const auto& param = GetParam();
2797fd4e5da5Sopenharmony_ci
2798fd4e5da5Sopenharmony_ci  std::ostringstream ss;
2799fd4e5da5Sopenharmony_ci  ss << R"(
2800fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
2801fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
2802fd4e5da5Sopenharmony_ci%VS_OUTPUT_info = OpExtInst %void %DbgExt DebugTypeComposite %VS_OUTPUT_name Structure %dbg_src 1 1 %comp_unit %VS_OUTPUT_name %u32_0 FlagIsPublic %child
2803fd4e5da5Sopenharmony_ci%foo_info = OpExtInst %void %DbgExt DebugTypeComposite %foo_name Structure %dbg_src 1 1 %comp_unit %foo_name %u32_0 FlagIsPublic
2804fd4e5da5Sopenharmony_ci%bar_info = OpExtInst %void %DbgExt DebugTypeComposite %foo_name Union %dbg_src 1 1 %comp_unit %foo_name %u32_0 FlagIsPublic
2805fd4e5da5Sopenharmony_ci%child = OpExtInst %void %DbgExt DebugTypeInheritance )"
2806fd4e5da5Sopenharmony_ci     << param.first;
2807fd4e5da5Sopenharmony_ci
2808fd4e5da5Sopenharmony_ci  const std::string extension = R"(
2809fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
2810fd4e5da5Sopenharmony_ci)";
2811fd4e5da5Sopenharmony_ci
2812fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", ss.str(), "",
2813fd4e5da5Sopenharmony_ci                                                     extension, "Vertex"));
2814fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2815fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
2816fd4e5da5Sopenharmony_ci              HasSubstr("expected operand " + param.second));
2817fd4e5da5Sopenharmony_ci}
2818fd4e5da5Sopenharmony_ci
2819fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(
2820fd4e5da5Sopenharmony_ci    AllOpenCL100DebugInfoFail, ValidateOpenCL100DebugInfoDebugTypeInheritance,
2821fd4e5da5Sopenharmony_ci    ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
2822fd4e5da5Sopenharmony_ci        std::make_pair(R"(%dbg_src %VS_OUTPUT_info %u32_0 %u32_0 FlagIsPublic)",
2823fd4e5da5Sopenharmony_ci                       "Child must be a result id of"),
2824fd4e5da5Sopenharmony_ci        std::make_pair(R"(%foo_info %dbg_src %u32_0 %u32_0 FlagIsPublic)",
2825fd4e5da5Sopenharmony_ci                       "Parent must be a result id of"),
2826fd4e5da5Sopenharmony_ci        std::make_pair(
2827fd4e5da5Sopenharmony_ci            R"(%bar_info %VS_OUTPUT_info %u32_0 %u32_0 FlagIsPublic)",
2828fd4e5da5Sopenharmony_ci            "Child must be class or struct debug type"),
2829fd4e5da5Sopenharmony_ci        std::make_pair(R"(%foo_info %bar_info %u32_0 %u32_0 FlagIsPublic)",
2830fd4e5da5Sopenharmony_ci                       "Parent must be class or struct debug type"),
2831fd4e5da5Sopenharmony_ci        std::make_pair(R"(%foo_info %VS_OUTPUT_info %void %u32_0 FlagIsPublic)",
2832fd4e5da5Sopenharmony_ci                       "Offset"),
2833fd4e5da5Sopenharmony_ci        std::make_pair(R"(%foo_info %VS_OUTPUT_info %u32_0 %void FlagIsPublic)",
2834fd4e5da5Sopenharmony_ci                       "Size"),
2835fd4e5da5Sopenharmony_ci    }));
2836fd4e5da5Sopenharmony_ci
2837fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugTypeComposite) {
2838fd4e5da5Sopenharmony_ci  const std::string src = R"(
2839fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
2840fd4e5da5Sopenharmony_ci%code = OpString "struct VS_OUTPUT {
2841fd4e5da5Sopenharmony_ci  float4 pos : SV_POSITION;
2842fd4e5da5Sopenharmony_ci};
2843fd4e5da5Sopenharmony_cistruct foo : VS_OUTPUT {
2844fd4e5da5Sopenharmony_ci};
2845fd4e5da5Sopenharmony_cimain() {}
2846fd4e5da5Sopenharmony_ci"
2847fd4e5da5Sopenharmony_ci%VS_OUTPUT_name = OpString "struct VS_OUTPUT"
2848fd4e5da5Sopenharmony_ci%float_name = OpString "float"
2849fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
2850fd4e5da5Sopenharmony_ci%VS_OUTPUT_pos_name = OpString "pos : SV_POSITION"
2851fd4e5da5Sopenharmony_ci%VS_OUTPUT_linkage_name = OpString "VS_OUTPUT"
2852fd4e5da5Sopenharmony_ci%main_name = OpString "main"
2853fd4e5da5Sopenharmony_ci%main_linkage_name = OpString "v4f_main_f"
2854fd4e5da5Sopenharmony_ci)";
2855fd4e5da5Sopenharmony_ci
2856fd4e5da5Sopenharmony_ci  const std::string constants = R"(
2857fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
2858fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
2859fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
2860fd4e5da5Sopenharmony_ci%u32_128 = OpConstant %u32 128
2861fd4e5da5Sopenharmony_ci)";
2862fd4e5da5Sopenharmony_ci
2863fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
2864fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
2865fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
2866fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
2867fd4e5da5Sopenharmony_ci%v4float_info = OpExtInst %void %DbgExt DebugTypeVector %float_info %u32_4
2868fd4e5da5Sopenharmony_ci%VS_OUTPUT_pos_info = OpExtInst %void %DbgExt DebugTypeMember %VS_OUTPUT_pos_name %v4float_info %dbg_src %u32_2 %u32_3 %u32_0 %u32_128 %u32_3
2869fd4e5da5Sopenharmony_ci%VS_OUTPUT_info = OpExtInst %void %DbgExt DebugTypeComposite %VS_OUTPUT_name %u32_1 %dbg_src %u32_1 %u32_1 %comp_unit %VS_OUTPUT_linkage_name %u32_128 %u32_3 %VS_OUTPUT_pos_info
2870fd4e5da5Sopenharmony_ci%foo_info = OpExtInst %void %DbgExt DebugTypeComposite %foo_name %u32_1 %dbg_src %u32_1 %u32_1 %comp_unit %foo_name %u32_0 %u32_3
2871fd4e5da5Sopenharmony_ci)";
2872fd4e5da5Sopenharmony_ci
2873fd4e5da5Sopenharmony_ci  const std::string extension = R"(
2874fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
2875fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
2876fd4e5da5Sopenharmony_ci)";
2877fd4e5da5Sopenharmony_ci
2878fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
2879fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
2880fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
2881fd4e5da5Sopenharmony_ci}
2882fd4e5da5Sopenharmony_ci
2883fd4e5da5Sopenharmony_ciTEST_P(ValidateVulkan100DebugInfoDebugTypeComposite, Fail) {
2884fd4e5da5Sopenharmony_ci  const std::string src = R"(
2885fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
2886fd4e5da5Sopenharmony_ci%code = OpString "struct VS_OUTPUT {
2887fd4e5da5Sopenharmony_ci  float4 pos : SV_POSITION;
2888fd4e5da5Sopenharmony_ci};
2889fd4e5da5Sopenharmony_cistruct foo : VS_OUTPUT {
2890fd4e5da5Sopenharmony_ci};
2891fd4e5da5Sopenharmony_cimain() {}
2892fd4e5da5Sopenharmony_ci"
2893fd4e5da5Sopenharmony_ci%VS_OUTPUT_name = OpString "struct VS_OUTPUT"
2894fd4e5da5Sopenharmony_ci%float_name = OpString "float"
2895fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
2896fd4e5da5Sopenharmony_ci%VS_OUTPUT_pos_name = OpString "pos : SV_POSITION"
2897fd4e5da5Sopenharmony_ci%VS_OUTPUT_linkage_name = OpString "VS_OUTPUT"
2898fd4e5da5Sopenharmony_ci%main_name = OpString "main"
2899fd4e5da5Sopenharmony_ci%main_linkage_name = OpString "v4f_main_f"
2900fd4e5da5Sopenharmony_ci)";
2901fd4e5da5Sopenharmony_ci
2902fd4e5da5Sopenharmony_ci  const std::string constants = R"(
2903fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
2904fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
2905fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
2906fd4e5da5Sopenharmony_ci%u32_128 = OpConstant %u32 128
2907fd4e5da5Sopenharmony_ci)";
2908fd4e5da5Sopenharmony_ci
2909fd4e5da5Sopenharmony_ci  const auto& param = GetParam();
2910fd4e5da5Sopenharmony_ci
2911fd4e5da5Sopenharmony_ci  std::ostringstream ss;
2912fd4e5da5Sopenharmony_ci  ss << R"(
2913fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
2914fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
2915fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
2916fd4e5da5Sopenharmony_ci%v4float_info = OpExtInst %void %DbgExt DebugTypeVector %float_info %u32_4
2917fd4e5da5Sopenharmony_ci%VS_OUTPUT_pos_info = OpExtInst %void %DbgExt DebugTypeMember %VS_OUTPUT_pos_name %v4float_info %dbg_src %u32_2 %u32_3 %u32_0 %u32_128 %u32_3
2918fd4e5da5Sopenharmony_ci%VS_OUTPUT_info = OpExtInst %void %DbgExt DebugTypeComposite )";
2919fd4e5da5Sopenharmony_ci  ss << param.first;
2920fd4e5da5Sopenharmony_ci
2921fd4e5da5Sopenharmony_ci  const std::string extension = R"(
2922fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
2923fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
2924fd4e5da5Sopenharmony_ci)";
2925fd4e5da5Sopenharmony_ci
2926fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, constants, ss.str(),
2927fd4e5da5Sopenharmony_ci                                                     "", extension, "Vertex"));
2928fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2929fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
2930fd4e5da5Sopenharmony_ci              HasSubstr("expected operand " + param.second + " must be "));
2931fd4e5da5Sopenharmony_ci}
2932fd4e5da5Sopenharmony_ci
2933fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(
2934fd4e5da5Sopenharmony_ci    AllVulkan100DebugInfoFail, ValidateVulkan100DebugInfoDebugTypeComposite,
2935fd4e5da5Sopenharmony_ci    ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
2936fd4e5da5Sopenharmony_ci        std::make_pair(
2937fd4e5da5Sopenharmony_ci            R"(%dbg_src %u32_1 %dbg_src %u32_1 %u32_1 %comp_unit %VS_OUTPUT_linkage_name %u32_128 %u32_3 %VS_OUTPUT_pos_info)",
2938fd4e5da5Sopenharmony_ci            "Name"),
2939fd4e5da5Sopenharmony_ci        std::make_pair(
2940fd4e5da5Sopenharmony_ci            R"(%VS_OUTPUT_name %u32_1 %comp_unit %u32_1 %u32_1 %comp_unit %VS_OUTPUT_linkage_name %u32_128 %u32_3 %VS_OUTPUT_pos_info)",
2941fd4e5da5Sopenharmony_ci            "Source"),
2942fd4e5da5Sopenharmony_ci        std::make_pair(
2943fd4e5da5Sopenharmony_ci            R"(%VS_OUTPUT_name %u32_1 %dbg_src %u32_1 %u32_1 %dbg_src %VS_OUTPUT_linkage_name %u32_128 %u32_3 %VS_OUTPUT_pos_info)",
2944fd4e5da5Sopenharmony_ci            "Parent"),
2945fd4e5da5Sopenharmony_ci        std::make_pair(
2946fd4e5da5Sopenharmony_ci            R"(%VS_OUTPUT_name %u32_1 %dbg_src %u32_1 %u32_1 %comp_unit %u32_128 %u32_128 %u32_3 %VS_OUTPUT_pos_info)",
2947fd4e5da5Sopenharmony_ci            "Linkage Name"),
2948fd4e5da5Sopenharmony_ci        std::make_pair(
2949fd4e5da5Sopenharmony_ci            R"(%VS_OUTPUT_name %u32_1 %dbg_src %u32_1 %u32_1 %comp_unit %VS_OUTPUT_linkage_name %dbg_src %u32_3 %VS_OUTPUT_pos_info)",
2950fd4e5da5Sopenharmony_ci            "Size"),
2951fd4e5da5Sopenharmony_ci        std::make_pair(
2952fd4e5da5Sopenharmony_ci            R"(%VS_OUTPUT_name %u32_1 %dbg_src %u32_1 %u32_1 %comp_unit %VS_OUTPUT_linkage_name %u32_128 %dbg_src %VS_OUTPUT_pos_info)",
2953fd4e5da5Sopenharmony_ci            "Flags"),
2954fd4e5da5Sopenharmony_ci        std::make_pair(
2955fd4e5da5Sopenharmony_ci            R"(%VS_OUTPUT_name %u32_1 %dbg_src %u32_1 %u32_1 %comp_unit %VS_OUTPUT_linkage_name %u32_128 %u32_3 %dbg_src)",
2956fd4e5da5Sopenharmony_ci            "Members"),
2957fd4e5da5Sopenharmony_ci    }));
2958fd4e5da5Sopenharmony_ci
2959fd4e5da5Sopenharmony_ciTEST_P(ValidateVulkan100DebugInfoDebugTypeMember, Fail) {
2960fd4e5da5Sopenharmony_ci  const std::string src = R"(
2961fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
2962fd4e5da5Sopenharmony_ci%code = OpString "struct VS_OUTPUT {
2963fd4e5da5Sopenharmony_ci  float pos : SV_POSITION;
2964fd4e5da5Sopenharmony_ci};
2965fd4e5da5Sopenharmony_cimain() {}
2966fd4e5da5Sopenharmony_ci"
2967fd4e5da5Sopenharmony_ci%VS_OUTPUT_name = OpString "struct VS_OUTPUT"
2968fd4e5da5Sopenharmony_ci%float_name = OpString "float"
2969fd4e5da5Sopenharmony_ci%VS_OUTPUT_pos_name = OpString "pos : SV_POSITION"
2970fd4e5da5Sopenharmony_ci%VS_OUTPUT_linkage_name = OpString "VS_OUTPUT"
2971fd4e5da5Sopenharmony_ci)";
2972fd4e5da5Sopenharmony_ci
2973fd4e5da5Sopenharmony_ci  const std::string constants = R"(
2974fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
2975fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
2976fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
2977fd4e5da5Sopenharmony_ci%u32_128 = OpConstant %u32 128
2978fd4e5da5Sopenharmony_ci)";
2979fd4e5da5Sopenharmony_ci
2980fd4e5da5Sopenharmony_ci  const auto& param = GetParam();
2981fd4e5da5Sopenharmony_ci
2982fd4e5da5Sopenharmony_ci  std::ostringstream ss;
2983fd4e5da5Sopenharmony_ci  ss << R"(
2984fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
2985fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
2986fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
2987fd4e5da5Sopenharmony_ci%VS_OUTPUT_pos_info = OpExtInst %void %DbgExt DebugTypeMember )";
2988fd4e5da5Sopenharmony_ci  ss << param.first;
2989fd4e5da5Sopenharmony_ci
2990fd4e5da5Sopenharmony_ci  const std::string extension = R"(
2991fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
2992fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
2993fd4e5da5Sopenharmony_ci)";
2994fd4e5da5Sopenharmony_ci
2995fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, constants, ss.str(),
2996fd4e5da5Sopenharmony_ci                                                     "", extension, "Vertex"));
2997fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2998fd4e5da5Sopenharmony_ci  if (!param.second.empty()) {
2999fd4e5da5Sopenharmony_ci    EXPECT_THAT(getDiagnosticString(),
3000fd4e5da5Sopenharmony_ci                HasSubstr("expected operand " + param.second +
3001fd4e5da5Sopenharmony_ci                          " must be a result id of "));
3002fd4e5da5Sopenharmony_ci  }
3003fd4e5da5Sopenharmony_ci}
3004fd4e5da5Sopenharmony_ci
3005fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(
3006fd4e5da5Sopenharmony_ci    AllVulkan100DebugInfoFail, ValidateVulkan100DebugInfoDebugTypeMember,
3007fd4e5da5Sopenharmony_ci    ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
3008fd4e5da5Sopenharmony_ci        std::make_pair(
3009fd4e5da5Sopenharmony_ci            R"(%dbg_src %float_info %dbg_src %u32_2 %u32_3 %u32_0 %u32_32 %u32_3)",
3010fd4e5da5Sopenharmony_ci            "Name"),
3011fd4e5da5Sopenharmony_ci        std::make_pair(
3012fd4e5da5Sopenharmony_ci            R"(%VS_OUTPUT_pos_name %dbg_src %dbg_src %u32_2 %u32_3 %u32_0 %u32_32 %u32_3)",
3013fd4e5da5Sopenharmony_ci            ""),
3014fd4e5da5Sopenharmony_ci        std::make_pair(
3015fd4e5da5Sopenharmony_ci            R"(%VS_OUTPUT_pos_name %float_info %float_info %u32_2 %u32_3 %u32_0 %u32_32 %u32_3)",
3016fd4e5da5Sopenharmony_ci            "Source"),
3017fd4e5da5Sopenharmony_ci        std::make_pair(
3018fd4e5da5Sopenharmony_ci            R"(%VS_OUTPUT_pos_name %float_info %dbg_src %u32_2 %u32_3 %void %u32_32 %u32_3)",
3019fd4e5da5Sopenharmony_ci            "Offset"),
3020fd4e5da5Sopenharmony_ci        std::make_pair(
3021fd4e5da5Sopenharmony_ci            R"(%VS_OUTPUT_pos_name %float_info %dbg_src %u32_2 %u32_3 %u32_0 %void %u32_3)",
3022fd4e5da5Sopenharmony_ci            "Size"),
3023fd4e5da5Sopenharmony_ci        std::make_pair(
3024fd4e5da5Sopenharmony_ci            R"(%VS_OUTPUT_pos_name %float_info %dbg_src %u32_2 %u32_3 %u32_0 %u32_32 %void)",
3025fd4e5da5Sopenharmony_ci            "Flags"),
3026fd4e5da5Sopenharmony_ci    }));
3027fd4e5da5Sopenharmony_ci
3028fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugFunctionDeclaration) {
3029fd4e5da5Sopenharmony_ci  const std::string src = R"(
3030fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
3031fd4e5da5Sopenharmony_ci%code = OpString "struct VS_OUTPUT {
3032fd4e5da5Sopenharmony_ci  float4 pos : SV_POSITION;
3033fd4e5da5Sopenharmony_ci};
3034fd4e5da5Sopenharmony_cimain() {}
3035fd4e5da5Sopenharmony_ci"
3036fd4e5da5Sopenharmony_ci%main_name = OpString "main"
3037fd4e5da5Sopenharmony_ci%main_linkage_name = OpString "v4f_main_f"
3038fd4e5da5Sopenharmony_ci)";
3039fd4e5da5Sopenharmony_ci
3040fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
3041fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
3042fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
3043fd4e5da5Sopenharmony_ci%main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void
3044fd4e5da5Sopenharmony_ci%main_decl = OpExtInst %void %DbgExt DebugFunctionDeclaration %main_name %main_type_info %dbg_src 12 1 %comp_unit %main_linkage_name FlagIsPublic
3045fd4e5da5Sopenharmony_ci%main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 12 1 %comp_unit %main_linkage_name FlagIsPublic 13 %main)";
3046fd4e5da5Sopenharmony_ci
3047fd4e5da5Sopenharmony_ci  const std::string extension = R"(
3048fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
3049fd4e5da5Sopenharmony_ci)";
3050fd4e5da5Sopenharmony_ci
3051fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", dbg_inst_header,
3052fd4e5da5Sopenharmony_ci                                                     "", extension, "Vertex"));
3053fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
3054fd4e5da5Sopenharmony_ci}
3055fd4e5da5Sopenharmony_ci
3056fd4e5da5Sopenharmony_ciTEST_P(ValidateOpenCL100DebugInfoDebugFunction, Fail) {
3057fd4e5da5Sopenharmony_ci  const std::string src = R"(
3058fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
3059fd4e5da5Sopenharmony_ci%code = OpString "struct VS_OUTPUT {
3060fd4e5da5Sopenharmony_ci  float4 pos : SV_POSITION;
3061fd4e5da5Sopenharmony_ci};
3062fd4e5da5Sopenharmony_cimain() {}
3063fd4e5da5Sopenharmony_ci"
3064fd4e5da5Sopenharmony_ci%main_name = OpString "main"
3065fd4e5da5Sopenharmony_ci%main_linkage_name = OpString "v4f_main_f"
3066fd4e5da5Sopenharmony_ci)";
3067fd4e5da5Sopenharmony_ci
3068fd4e5da5Sopenharmony_ci  const auto& param = GetParam();
3069fd4e5da5Sopenharmony_ci
3070fd4e5da5Sopenharmony_ci  std::ostringstream ss;
3071fd4e5da5Sopenharmony_ci  ss << R"(
3072fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
3073fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
3074fd4e5da5Sopenharmony_ci%main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void
3075fd4e5da5Sopenharmony_ci%main_decl = OpExtInst %void %DbgExt DebugFunctionDeclaration %main_name %main_type_info %dbg_src 12 1 %comp_unit %main_linkage_name FlagIsPublic
3076fd4e5da5Sopenharmony_ci%main_info = OpExtInst %void %DbgExt DebugFunction )"
3077fd4e5da5Sopenharmony_ci     << param.first;
3078fd4e5da5Sopenharmony_ci
3079fd4e5da5Sopenharmony_ci  const std::string extension = R"(
3080fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
3081fd4e5da5Sopenharmony_ci)";
3082fd4e5da5Sopenharmony_ci
3083fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", ss.str(), "",
3084fd4e5da5Sopenharmony_ci                                                     extension, "Vertex"));
3085fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3086fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
3087fd4e5da5Sopenharmony_ci              HasSubstr("expected operand " + param.second));
3088fd4e5da5Sopenharmony_ci}
3089fd4e5da5Sopenharmony_ci
3090fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(
3091fd4e5da5Sopenharmony_ci    AllOpenCL100DebugInfoFail, ValidateOpenCL100DebugInfoDebugFunction,
3092fd4e5da5Sopenharmony_ci    ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
3093fd4e5da5Sopenharmony_ci        std::make_pair(
3094fd4e5da5Sopenharmony_ci            R"(%u32_0 %main_type_info %dbg_src 12 1 %comp_unit %main_linkage_name FlagIsPublic 13 %main)",
3095fd4e5da5Sopenharmony_ci            "Name"),
3096fd4e5da5Sopenharmony_ci        std::make_pair(
3097fd4e5da5Sopenharmony_ci            R"(%main_name %dbg_src %dbg_src 12 1 %comp_unit %main_linkage_name FlagIsPublic 13 %main)",
3098fd4e5da5Sopenharmony_ci            "Type"),
3099fd4e5da5Sopenharmony_ci        std::make_pair(
3100fd4e5da5Sopenharmony_ci            R"(%main_name %main_type_info %comp_unit 12 1 %comp_unit %main_linkage_name FlagIsPublic 13 %main)",
3101fd4e5da5Sopenharmony_ci            "Source"),
3102fd4e5da5Sopenharmony_ci        std::make_pair(
3103fd4e5da5Sopenharmony_ci            R"(%main_name %main_type_info %dbg_src 12 1 %dbg_src %main_linkage_name FlagIsPublic 13 %main)",
3104fd4e5da5Sopenharmony_ci            "Parent"),
3105fd4e5da5Sopenharmony_ci        std::make_pair(
3106fd4e5da5Sopenharmony_ci            R"(%main_name %main_type_info %dbg_src 12 1 %comp_unit %void FlagIsPublic 13 %main)",
3107fd4e5da5Sopenharmony_ci            "Linkage Name"),
3108fd4e5da5Sopenharmony_ci        std::make_pair(
3109fd4e5da5Sopenharmony_ci            R"(%main_name %main_type_info %dbg_src 12 1 %comp_unit %main_linkage_name FlagIsPublic 13 %void)",
3110fd4e5da5Sopenharmony_ci            "Function"),
3111fd4e5da5Sopenharmony_ci        std::make_pair(
3112fd4e5da5Sopenharmony_ci            R"(%main_name %main_type_info %dbg_src 12 1 %comp_unit %main_linkage_name FlagIsPublic 13 %main %dbg_src)",
3113fd4e5da5Sopenharmony_ci            "Declaration"),
3114fd4e5da5Sopenharmony_ci    }));
3115fd4e5da5Sopenharmony_ci
3116fd4e5da5Sopenharmony_ciTEST_P(ValidateOpenCL100DebugInfoDebugFunctionDeclaration, Fail) {
3117fd4e5da5Sopenharmony_ci  const std::string src = R"(
3118fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
3119fd4e5da5Sopenharmony_ci%code = OpString "struct VS_OUTPUT {
3120fd4e5da5Sopenharmony_ci  float4 pos : SV_POSITION;
3121fd4e5da5Sopenharmony_ci};
3122fd4e5da5Sopenharmony_cimain() {}
3123fd4e5da5Sopenharmony_ci"
3124fd4e5da5Sopenharmony_ci%main_name = OpString "main"
3125fd4e5da5Sopenharmony_ci%main_linkage_name = OpString "v4f_main_f"
3126fd4e5da5Sopenharmony_ci)";
3127fd4e5da5Sopenharmony_ci
3128fd4e5da5Sopenharmony_ci  const auto& param = GetParam();
3129fd4e5da5Sopenharmony_ci
3130fd4e5da5Sopenharmony_ci  std::ostringstream ss;
3131fd4e5da5Sopenharmony_ci  ss << R"(
3132fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
3133fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
3134fd4e5da5Sopenharmony_ci%main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void
3135fd4e5da5Sopenharmony_ci%main_decl = OpExtInst %void %DbgExt DebugFunctionDeclaration )"
3136fd4e5da5Sopenharmony_ci     << param.first;
3137fd4e5da5Sopenharmony_ci
3138fd4e5da5Sopenharmony_ci  const std::string extension = R"(
3139fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
3140fd4e5da5Sopenharmony_ci)";
3141fd4e5da5Sopenharmony_ci
3142fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", ss.str(), "",
3143fd4e5da5Sopenharmony_ci                                                     extension, "Vertex"));
3144fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3145fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
3146fd4e5da5Sopenharmony_ci              HasSubstr("expected operand " + param.second));
3147fd4e5da5Sopenharmony_ci}
3148fd4e5da5Sopenharmony_ci
3149fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(
3150fd4e5da5Sopenharmony_ci    AllOpenCL100DebugInfoFail,
3151fd4e5da5Sopenharmony_ci    ValidateOpenCL100DebugInfoDebugFunctionDeclaration,
3152fd4e5da5Sopenharmony_ci    ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
3153fd4e5da5Sopenharmony_ci        std::make_pair(
3154fd4e5da5Sopenharmony_ci            R"(%u32_0 %main_type_info %dbg_src 12 1 %comp_unit %main_linkage_name FlagIsPublic)",
3155fd4e5da5Sopenharmony_ci            "Name"),
3156fd4e5da5Sopenharmony_ci        std::make_pair(
3157fd4e5da5Sopenharmony_ci            R"(%main_name %dbg_src %dbg_src 12 1 %comp_unit %main_linkage_name FlagIsPublic)",
3158fd4e5da5Sopenharmony_ci            "Type"),
3159fd4e5da5Sopenharmony_ci        std::make_pair(
3160fd4e5da5Sopenharmony_ci            R"(%main_name %main_type_info %comp_unit 12 1 %comp_unit %main_linkage_name FlagIsPublic)",
3161fd4e5da5Sopenharmony_ci            "Source"),
3162fd4e5da5Sopenharmony_ci        std::make_pair(
3163fd4e5da5Sopenharmony_ci            R"(%main_name %main_type_info %dbg_src 12 1 %dbg_src %main_linkage_name FlagIsPublic)",
3164fd4e5da5Sopenharmony_ci            "Parent"),
3165fd4e5da5Sopenharmony_ci        std::make_pair(
3166fd4e5da5Sopenharmony_ci            R"(%main_name %main_type_info %dbg_src 12 1 %comp_unit %void FlagIsPublic)",
3167fd4e5da5Sopenharmony_ci            "Linkage Name"),
3168fd4e5da5Sopenharmony_ci    }));
3169fd4e5da5Sopenharmony_ci
3170fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugFunctionDeclaration) {
3171fd4e5da5Sopenharmony_ci  const std::string src = R"(
3172fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
3173fd4e5da5Sopenharmony_ci%code = OpString "struct VS_OUTPUT {
3174fd4e5da5Sopenharmony_ci  float4 pos : SV_POSITION;
3175fd4e5da5Sopenharmony_ci};
3176fd4e5da5Sopenharmony_cimain() {}
3177fd4e5da5Sopenharmony_ci"
3178fd4e5da5Sopenharmony_ci%main_name = OpString "main"
3179fd4e5da5Sopenharmony_ci%main_linkage_name = OpString "v4f_main_f"
3180fd4e5da5Sopenharmony_ci)";
3181fd4e5da5Sopenharmony_ci
3182fd4e5da5Sopenharmony_ci  const std::string constants = R"(
3183fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
3184fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
3185fd4e5da5Sopenharmony_ci%u32_12 = OpConstant %u32 12
3186fd4e5da5Sopenharmony_ci%u32_13 = OpConstant %u32 13
3187fd4e5da5Sopenharmony_ci)";
3188fd4e5da5Sopenharmony_ci
3189fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
3190fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
3191fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
3192fd4e5da5Sopenharmony_ci%main_type_info = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %void
3193fd4e5da5Sopenharmony_ci%main_decl = OpExtInst %void %DbgExt DebugFunctionDeclaration %main_name %main_type_info %dbg_src %u32_12 %u32_1 %comp_unit %main_linkage_name %u32_3
3194fd4e5da5Sopenharmony_ci%main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src %u32_12 %u32_1 %comp_unit %main_linkage_name %u32_3 %u32_13
3195fd4e5da5Sopenharmony_ci)";
3196fd4e5da5Sopenharmony_ci
3197fd4e5da5Sopenharmony_ci  const std::string extension = R"(
3198fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
3199fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
3200fd4e5da5Sopenharmony_ci)";
3201fd4e5da5Sopenharmony_ci
3202fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
3203fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
3204fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
3205fd4e5da5Sopenharmony_ci}
3206fd4e5da5Sopenharmony_ci
3207fd4e5da5Sopenharmony_ciTEST_P(ValidateVulkan100DebugInfoDebugFunction, Fail) {
3208fd4e5da5Sopenharmony_ci  const std::string src = R"(
3209fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
3210fd4e5da5Sopenharmony_ci%code = OpString "struct VS_OUTPUT {
3211fd4e5da5Sopenharmony_ci  float4 pos : SV_POSITION;
3212fd4e5da5Sopenharmony_ci};
3213fd4e5da5Sopenharmony_cimain() {}
3214fd4e5da5Sopenharmony_ci"
3215fd4e5da5Sopenharmony_ci%main_name = OpString "main"
3216fd4e5da5Sopenharmony_ci%main_linkage_name = OpString "v4f_main_f"
3217fd4e5da5Sopenharmony_ci)";
3218fd4e5da5Sopenharmony_ci
3219fd4e5da5Sopenharmony_ci  const std::string constants = R"(
3220fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
3221fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
3222fd4e5da5Sopenharmony_ci%u32_12 = OpConstant %u32 12
3223fd4e5da5Sopenharmony_ci%u32_13 = OpConstant %u32 13
3224fd4e5da5Sopenharmony_ci)";
3225fd4e5da5Sopenharmony_ci
3226fd4e5da5Sopenharmony_ci  const auto& param = GetParam();
3227fd4e5da5Sopenharmony_ci
3228fd4e5da5Sopenharmony_ci  std::ostringstream ss;
3229fd4e5da5Sopenharmony_ci  ss << R"(
3230fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
3231fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
3232fd4e5da5Sopenharmony_ci%main_type_info = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %void
3233fd4e5da5Sopenharmony_ci%main_decl = OpExtInst %void %DbgExt DebugFunctionDeclaration %main_name %main_type_info %dbg_src %u32_12 %u32_1 %comp_unit %main_linkage_name %u32_3
3234fd4e5da5Sopenharmony_ci%main_info = OpExtInst %void %DbgExt DebugFunction )"
3235fd4e5da5Sopenharmony_ci     << param.first;
3236fd4e5da5Sopenharmony_ci
3237fd4e5da5Sopenharmony_ci  const std::string extension = R"(
3238fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
3239fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
3240fd4e5da5Sopenharmony_ci)";
3241fd4e5da5Sopenharmony_ci
3242fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, constants, ss.str(),
3243fd4e5da5Sopenharmony_ci                                                     "", extension, "Vertex"));
3244fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3245fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
3246fd4e5da5Sopenharmony_ci              HasSubstr("expected operand " + param.second));
3247fd4e5da5Sopenharmony_ci}
3248fd4e5da5Sopenharmony_ci
3249fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(
3250fd4e5da5Sopenharmony_ci    AllVulkan100DebugInfoFail, ValidateVulkan100DebugInfoDebugFunction,
3251fd4e5da5Sopenharmony_ci    ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
3252fd4e5da5Sopenharmony_ci        std::make_pair(
3253fd4e5da5Sopenharmony_ci            R"(%u32_0 %main_type_info %dbg_src %u32_12 %u32_1 %comp_unit %main_linkage_name %u32_3 %u32_13)",
3254fd4e5da5Sopenharmony_ci            "Name"),
3255fd4e5da5Sopenharmony_ci        std::make_pair(
3256fd4e5da5Sopenharmony_ci            R"(%main_name %dbg_src %dbg_src %u32_12 %u32_1 %comp_unit %main_linkage_name %u32_3 %u32_13)",
3257fd4e5da5Sopenharmony_ci            "Type"),
3258fd4e5da5Sopenharmony_ci        std::make_pair(
3259fd4e5da5Sopenharmony_ci            R"(%main_name %main_type_info %comp_unit %u32_12 %u32_1 %comp_unit %main_linkage_name %u32_3 %u32_13)",
3260fd4e5da5Sopenharmony_ci            "Source"),
3261fd4e5da5Sopenharmony_ci        std::make_pair(
3262fd4e5da5Sopenharmony_ci            R"(%main_name %main_type_info %dbg_src %u32_12 %u32_1 %dbg_src %main_linkage_name %u32_3 %u32_13)",
3263fd4e5da5Sopenharmony_ci            "Parent"),
3264fd4e5da5Sopenharmony_ci        std::make_pair(
3265fd4e5da5Sopenharmony_ci            R"(%main_name %main_type_info %dbg_src %u32_12 %u32_1 %comp_unit %void %u32_3 %u32_13)",
3266fd4e5da5Sopenharmony_ci            "Linkage Name"),
3267fd4e5da5Sopenharmony_ci        std::make_pair(
3268fd4e5da5Sopenharmony_ci            R"(%main_name %main_type_info %dbg_src %u32_12 %u32_1 %comp_unit %main_linkage_name %u32_3 %u32_13 %dbg_src)",
3269fd4e5da5Sopenharmony_ci            "Declaration"),
3270fd4e5da5Sopenharmony_ci    }));
3271fd4e5da5Sopenharmony_ci
3272fd4e5da5Sopenharmony_ciTEST_P(ValidateVulkan100DebugInfoDebugFunctionDeclaration, Fail) {
3273fd4e5da5Sopenharmony_ci  const std::string src = R"(
3274fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
3275fd4e5da5Sopenharmony_ci%code = OpString "struct VS_OUTPUT {
3276fd4e5da5Sopenharmony_ci  float4 pos : SV_POSITION;
3277fd4e5da5Sopenharmony_ci};
3278fd4e5da5Sopenharmony_cimain() {}
3279fd4e5da5Sopenharmony_ci"
3280fd4e5da5Sopenharmony_ci%main_name = OpString "main"
3281fd4e5da5Sopenharmony_ci%main_linkage_name = OpString "v4f_main_f"
3282fd4e5da5Sopenharmony_ci)";
3283fd4e5da5Sopenharmony_ci
3284fd4e5da5Sopenharmony_ci  const std::string constants = R"(
3285fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
3286fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
3287fd4e5da5Sopenharmony_ci%u32_12 = OpConstant %u32 12
3288fd4e5da5Sopenharmony_ci%u32_13 = OpConstant %u32 13
3289fd4e5da5Sopenharmony_ci)";
3290fd4e5da5Sopenharmony_ci
3291fd4e5da5Sopenharmony_ci  const auto& param = GetParam();
3292fd4e5da5Sopenharmony_ci
3293fd4e5da5Sopenharmony_ci  std::ostringstream ss;
3294fd4e5da5Sopenharmony_ci  ss << R"(
3295fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
3296fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
3297fd4e5da5Sopenharmony_ci%main_type_info = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %void
3298fd4e5da5Sopenharmony_ci%main_decl = OpExtInst %void %DbgExt DebugFunctionDeclaration )"
3299fd4e5da5Sopenharmony_ci     << param.first;
3300fd4e5da5Sopenharmony_ci
3301fd4e5da5Sopenharmony_ci  const std::string extension = R"(
3302fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
3303fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
3304fd4e5da5Sopenharmony_ci)";
3305fd4e5da5Sopenharmony_ci
3306fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, constants, ss.str(),
3307fd4e5da5Sopenharmony_ci                                                     "", extension, "Vertex"));
3308fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3309fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
3310fd4e5da5Sopenharmony_ci              HasSubstr("expected operand " + param.second));
3311fd4e5da5Sopenharmony_ci}
3312fd4e5da5Sopenharmony_ci
3313fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(
3314fd4e5da5Sopenharmony_ci    AllVulkan100DebugInfoFail,
3315fd4e5da5Sopenharmony_ci    ValidateVulkan100DebugInfoDebugFunctionDeclaration,
3316fd4e5da5Sopenharmony_ci    ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
3317fd4e5da5Sopenharmony_ci        std::make_pair(
3318fd4e5da5Sopenharmony_ci            R"(%u32_0 %main_type_info %dbg_src %u32_12 %u32_1 %comp_unit %main_linkage_name %u32_3)",
3319fd4e5da5Sopenharmony_ci            "Name"),
3320fd4e5da5Sopenharmony_ci        std::make_pair(
3321fd4e5da5Sopenharmony_ci            R"(%main_name %dbg_src %dbg_src %u32_12 %u32_1 %comp_unit %main_linkage_name %u32_3)",
3322fd4e5da5Sopenharmony_ci            "Type"),
3323fd4e5da5Sopenharmony_ci        std::make_pair(
3324fd4e5da5Sopenharmony_ci            R"(%main_name %main_type_info %comp_unit %u32_12 %u32_1 %comp_unit %main_linkage_name %u32_3)",
3325fd4e5da5Sopenharmony_ci            "Source"),
3326fd4e5da5Sopenharmony_ci        std::make_pair(
3327fd4e5da5Sopenharmony_ci            R"(%main_name %main_type_info %dbg_src %u32_12 %u32_1 %dbg_src %main_linkage_name %u32_3)",
3328fd4e5da5Sopenharmony_ci            "Parent"),
3329fd4e5da5Sopenharmony_ci        std::make_pair(
3330fd4e5da5Sopenharmony_ci            R"(%main_name %main_type_info %dbg_src %u32_12 %u32_1 %comp_unit %void %u32_3)",
3331fd4e5da5Sopenharmony_ci            "Linkage Name"),
3332fd4e5da5Sopenharmony_ci    }));
3333fd4e5da5Sopenharmony_ci
3334fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugLexicalBlock) {
3335fd4e5da5Sopenharmony_ci  const std::string src = R"(
3336fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
3337fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
3338fd4e5da5Sopenharmony_ci%main_name = OpString "main"
3339fd4e5da5Sopenharmony_ci)";
3340fd4e5da5Sopenharmony_ci
3341fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
3342fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
3343fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
3344fd4e5da5Sopenharmony_ci%main_block = OpExtInst %void %DbgExt DebugLexicalBlock %dbg_src 1 1 %comp_unit %main_name)";
3345fd4e5da5Sopenharmony_ci
3346fd4e5da5Sopenharmony_ci  const std::string extension = R"(
3347fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
3348fd4e5da5Sopenharmony_ci)";
3349fd4e5da5Sopenharmony_ci
3350fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", dbg_inst_header,
3351fd4e5da5Sopenharmony_ci                                                     "", extension, "Vertex"));
3352fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
3353fd4e5da5Sopenharmony_ci}
3354fd4e5da5Sopenharmony_ci
3355fd4e5da5Sopenharmony_ciTEST_P(ValidateOpenCL100DebugInfoDebugLexicalBlock, Fail) {
3356fd4e5da5Sopenharmony_ci  const std::string src = R"(
3357fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
3358fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
3359fd4e5da5Sopenharmony_ci%main_name = OpString "main"
3360fd4e5da5Sopenharmony_ci)";
3361fd4e5da5Sopenharmony_ci
3362fd4e5da5Sopenharmony_ci  const auto& param = GetParam();
3363fd4e5da5Sopenharmony_ci
3364fd4e5da5Sopenharmony_ci  std::ostringstream ss;
3365fd4e5da5Sopenharmony_ci  ss << R"(
3366fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
3367fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
3368fd4e5da5Sopenharmony_ci%main_block = OpExtInst %void %DbgExt DebugLexicalBlock )"
3369fd4e5da5Sopenharmony_ci     << param.first;
3370fd4e5da5Sopenharmony_ci
3371fd4e5da5Sopenharmony_ci  const std::string extension = R"(
3372fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
3373fd4e5da5Sopenharmony_ci)";
3374fd4e5da5Sopenharmony_ci
3375fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", ss.str(), "",
3376fd4e5da5Sopenharmony_ci                                                     extension, "Vertex"));
3377fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3378fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
3379fd4e5da5Sopenharmony_ci              HasSubstr("expected operand " + param.second));
3380fd4e5da5Sopenharmony_ci}
3381fd4e5da5Sopenharmony_ci
3382fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(
3383fd4e5da5Sopenharmony_ci    AllOpenCL100DebugInfoFail, ValidateOpenCL100DebugInfoDebugLexicalBlock,
3384fd4e5da5Sopenharmony_ci    ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
3385fd4e5da5Sopenharmony_ci        std::make_pair(R"(%comp_unit 1 1 %comp_unit %main_name)", "Source"),
3386fd4e5da5Sopenharmony_ci        std::make_pair(R"(%dbg_src 1 1 %dbg_src %main_name)", "Parent"),
3387fd4e5da5Sopenharmony_ci        std::make_pair(R"(%dbg_src 1 1 %comp_unit %void)", "Name"),
3388fd4e5da5Sopenharmony_ci    }));
3389fd4e5da5Sopenharmony_ci
3390fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugScopeFailScope) {
3391fd4e5da5Sopenharmony_ci  const std::string src = R"(
3392fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
3393fd4e5da5Sopenharmony_ci%code = OpString "void main() {}"
3394fd4e5da5Sopenharmony_ci)";
3395fd4e5da5Sopenharmony_ci
3396fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
3397fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
3398fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
3399fd4e5da5Sopenharmony_ci)";
3400fd4e5da5Sopenharmony_ci
3401fd4e5da5Sopenharmony_ci  const std::string body = R"(
3402fd4e5da5Sopenharmony_ci%main_scope = OpExtInst %void %DbgExt DebugScope %dbg_src
3403fd4e5da5Sopenharmony_ci)";
3404fd4e5da5Sopenharmony_ci
3405fd4e5da5Sopenharmony_ci  const std::string extension = R"(
3406fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
3407fd4e5da5Sopenharmony_ci)";
3408fd4e5da5Sopenharmony_ci
3409fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
3410fd4e5da5Sopenharmony_ci      src, "", dbg_inst_header, body, extension, "Vertex"));
3411fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3412fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(), HasSubstr("expected operand Scope"));
3413fd4e5da5Sopenharmony_ci}
3414fd4e5da5Sopenharmony_ci
3415fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugScopeFailInlinedAt) {
3416fd4e5da5Sopenharmony_ci  const std::string src = R"(
3417fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
3418fd4e5da5Sopenharmony_ci%code = OpString "void main() {}"
3419fd4e5da5Sopenharmony_ci)";
3420fd4e5da5Sopenharmony_ci
3421fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
3422fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
3423fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
3424fd4e5da5Sopenharmony_ci)";
3425fd4e5da5Sopenharmony_ci
3426fd4e5da5Sopenharmony_ci  const std::string body = R"(
3427fd4e5da5Sopenharmony_ci%main_scope = OpExtInst %void %DbgExt DebugScope %comp_unit %dbg_src
3428fd4e5da5Sopenharmony_ci)";
3429fd4e5da5Sopenharmony_ci
3430fd4e5da5Sopenharmony_ci  const std::string extension = R"(
3431fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
3432fd4e5da5Sopenharmony_ci)";
3433fd4e5da5Sopenharmony_ci
3434fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
3435fd4e5da5Sopenharmony_ci      src, "", dbg_inst_header, body, extension, "Vertex"));
3436fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3437fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(), HasSubstr("expected operand Inlined At"));
3438fd4e5da5Sopenharmony_ci}
3439fd4e5da5Sopenharmony_ci
3440fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugLexicalBlock) {
3441fd4e5da5Sopenharmony_ci  const std::string src = R"(
3442fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
3443fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
3444fd4e5da5Sopenharmony_ci%main_name = OpString "main"
3445fd4e5da5Sopenharmony_ci)";
3446fd4e5da5Sopenharmony_ci
3447fd4e5da5Sopenharmony_ci  const std::string constants = R"(
3448fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
3449fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
3450fd4e5da5Sopenharmony_ci)";
3451fd4e5da5Sopenharmony_ci
3452fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
3453fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
3454fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
3455fd4e5da5Sopenharmony_ci%main_block = OpExtInst %void %DbgExt DebugLexicalBlock %dbg_src %u32_1 %u32_1 %comp_unit %main_name
3456fd4e5da5Sopenharmony_ci)";
3457fd4e5da5Sopenharmony_ci
3458fd4e5da5Sopenharmony_ci  const std::string extension = R"(
3459fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
3460fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
3461fd4e5da5Sopenharmony_ci)";
3462fd4e5da5Sopenharmony_ci
3463fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
3464fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
3465fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
3466fd4e5da5Sopenharmony_ci}
3467fd4e5da5Sopenharmony_ci
3468fd4e5da5Sopenharmony_ciTEST_P(ValidateVulkan100DebugInfoDebugLexicalBlock, Fail) {
3469fd4e5da5Sopenharmony_ci  const std::string src = R"(
3470fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
3471fd4e5da5Sopenharmony_ci%code = OpString "main() {}"
3472fd4e5da5Sopenharmony_ci%main_name = OpString "main"
3473fd4e5da5Sopenharmony_ci)";
3474fd4e5da5Sopenharmony_ci
3475fd4e5da5Sopenharmony_ci  const std::string constants = R"(
3476fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
3477fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
3478fd4e5da5Sopenharmony_ci)";
3479fd4e5da5Sopenharmony_ci
3480fd4e5da5Sopenharmony_ci  const auto& param = GetParam();
3481fd4e5da5Sopenharmony_ci
3482fd4e5da5Sopenharmony_ci  std::ostringstream ss;
3483fd4e5da5Sopenharmony_ci  ss << R"(
3484fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
3485fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
3486fd4e5da5Sopenharmony_ci%main_block = OpExtInst %void %DbgExt DebugLexicalBlock )"
3487fd4e5da5Sopenharmony_ci     << param.first;
3488fd4e5da5Sopenharmony_ci
3489fd4e5da5Sopenharmony_ci  const std::string extension = R"(
3490fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
3491fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
3492fd4e5da5Sopenharmony_ci)";
3493fd4e5da5Sopenharmony_ci
3494fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, constants, ss.str(),
3495fd4e5da5Sopenharmony_ci                                                     "", extension, "Vertex"));
3496fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3497fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
3498fd4e5da5Sopenharmony_ci              HasSubstr("expected operand " + param.second));
3499fd4e5da5Sopenharmony_ci}
3500fd4e5da5Sopenharmony_ci
3501fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(
3502fd4e5da5Sopenharmony_ci    AllVulkan100DebugInfoFail, ValidateVulkan100DebugInfoDebugLexicalBlock,
3503fd4e5da5Sopenharmony_ci    ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
3504fd4e5da5Sopenharmony_ci        std::make_pair(R"(%comp_unit %u32_1 %u32_1 %comp_unit %main_name)",
3505fd4e5da5Sopenharmony_ci                       "Source"),
3506fd4e5da5Sopenharmony_ci        std::make_pair(R"(%dbg_src %u32_1 %u32_1 %dbg_src %main_name)",
3507fd4e5da5Sopenharmony_ci                       "Parent"),
3508fd4e5da5Sopenharmony_ci        std::make_pair(R"(%dbg_src %u32_1 %u32_1 %comp_unit %void)", "Name"),
3509fd4e5da5Sopenharmony_ci    }));
3510fd4e5da5Sopenharmony_ci
3511fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugScopeFailScope) {
3512fd4e5da5Sopenharmony_ci  const std::string src = R"(
3513fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
3514fd4e5da5Sopenharmony_ci%code = OpString "void main() {}"
3515fd4e5da5Sopenharmony_ci)";
3516fd4e5da5Sopenharmony_ci
3517fd4e5da5Sopenharmony_ci  const std::string constants = R"(
3518fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
3519fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
3520fd4e5da5Sopenharmony_ci)";
3521fd4e5da5Sopenharmony_ci
3522fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
3523fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
3524fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
3525fd4e5da5Sopenharmony_ci)";
3526fd4e5da5Sopenharmony_ci
3527fd4e5da5Sopenharmony_ci  const std::string body = R"(
3528fd4e5da5Sopenharmony_ci%main_scope = OpExtInst %void %DbgExt DebugScope %dbg_src
3529fd4e5da5Sopenharmony_ci)";
3530fd4e5da5Sopenharmony_ci
3531fd4e5da5Sopenharmony_ci  const std::string extension = R"(
3532fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
3533fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
3534fd4e5da5Sopenharmony_ci)";
3535fd4e5da5Sopenharmony_ci
3536fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
3537fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, body, extension, "Vertex"));
3538fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3539fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(), HasSubstr("expected operand Scope"));
3540fd4e5da5Sopenharmony_ci}
3541fd4e5da5Sopenharmony_ci
3542fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugScopeFailInlinedAt) {
3543fd4e5da5Sopenharmony_ci  const std::string src = R"(
3544fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
3545fd4e5da5Sopenharmony_ci%code = OpString "void main() {}"
3546fd4e5da5Sopenharmony_ci)";
3547fd4e5da5Sopenharmony_ci
3548fd4e5da5Sopenharmony_ci  const std::string constants = R"(
3549fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
3550fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
3551fd4e5da5Sopenharmony_ci)";
3552fd4e5da5Sopenharmony_ci
3553fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
3554fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
3555fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
3556fd4e5da5Sopenharmony_ci)";
3557fd4e5da5Sopenharmony_ci
3558fd4e5da5Sopenharmony_ci  const std::string body = R"(
3559fd4e5da5Sopenharmony_ci%main_scope = OpExtInst %void %DbgExt DebugScope %comp_unit %dbg_src
3560fd4e5da5Sopenharmony_ci)";
3561fd4e5da5Sopenharmony_ci
3562fd4e5da5Sopenharmony_ci  const std::string extension = R"(
3563fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
3564fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
3565fd4e5da5Sopenharmony_ci)";
3566fd4e5da5Sopenharmony_ci
3567fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
3568fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, body, extension, "Vertex"));
3569fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3570fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(), HasSubstr("expected operand Inlined At"));
3571fd4e5da5Sopenharmony_ci}
3572fd4e5da5Sopenharmony_ci
3573fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugLocalVariable) {
3574fd4e5da5Sopenharmony_ci  const std::string src = R"(
3575fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
3576fd4e5da5Sopenharmony_ci%code = OpString "void main() { float foo; }"
3577fd4e5da5Sopenharmony_ci%float_name = OpString "float"
3578fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
3579fd4e5da5Sopenharmony_ci)";
3580fd4e5da5Sopenharmony_ci
3581fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
3582fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
3583fd4e5da5Sopenharmony_ci)";
3584fd4e5da5Sopenharmony_ci
3585fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
3586fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
3587fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
3588fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
3589fd4e5da5Sopenharmony_ci%foo = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %float_info %dbg_src 1 10 %comp_unit FlagIsLocal 0
3590fd4e5da5Sopenharmony_ci)";
3591fd4e5da5Sopenharmony_ci
3592fd4e5da5Sopenharmony_ci  const std::string extension = R"(
3593fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
3594fd4e5da5Sopenharmony_ci)";
3595fd4e5da5Sopenharmony_ci
3596fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
3597fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, "", extension, "Vertex"));
3598fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
3599fd4e5da5Sopenharmony_ci}
3600fd4e5da5Sopenharmony_ci
3601fd4e5da5Sopenharmony_ciTEST_P(ValidateOpenCL100DebugInfoDebugLocalVariable, Fail) {
3602fd4e5da5Sopenharmony_ci  const std::string src = R"(
3603fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
3604fd4e5da5Sopenharmony_ci%code = OpString "void main() { float foo; }"
3605fd4e5da5Sopenharmony_ci%float_name = OpString "float"
3606fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
3607fd4e5da5Sopenharmony_ci)";
3608fd4e5da5Sopenharmony_ci
3609fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
3610fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
3611fd4e5da5Sopenharmony_ci)";
3612fd4e5da5Sopenharmony_ci
3613fd4e5da5Sopenharmony_ci  const auto& param = GetParam();
3614fd4e5da5Sopenharmony_ci
3615fd4e5da5Sopenharmony_ci  std::ostringstream ss;
3616fd4e5da5Sopenharmony_ci  ss << R"(
3617fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
3618fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
3619fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
3620fd4e5da5Sopenharmony_ci%foo = OpExtInst %void %DbgExt DebugLocalVariable )"
3621fd4e5da5Sopenharmony_ci     << param.first;
3622fd4e5da5Sopenharmony_ci
3623fd4e5da5Sopenharmony_ci  const std::string extension = R"(
3624fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
3625fd4e5da5Sopenharmony_ci)";
3626fd4e5da5Sopenharmony_ci
3627fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, size_const, ss.str(),
3628fd4e5da5Sopenharmony_ci                                                     "", extension, "Vertex"));
3629fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3630fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
3631fd4e5da5Sopenharmony_ci              HasSubstr("expected operand " + param.second));
3632fd4e5da5Sopenharmony_ci}
3633fd4e5da5Sopenharmony_ci
3634fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(
3635fd4e5da5Sopenharmony_ci    AllOpenCL100DebugInfoFail, ValidateOpenCL100DebugInfoDebugLocalVariable,
3636fd4e5da5Sopenharmony_ci    ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
3637fd4e5da5Sopenharmony_ci        std::make_pair(
3638fd4e5da5Sopenharmony_ci            R"(%void %float_info %dbg_src 1 10 %comp_unit FlagIsLocal 0)",
3639fd4e5da5Sopenharmony_ci            "Name"),
3640fd4e5da5Sopenharmony_ci        std::make_pair(
3641fd4e5da5Sopenharmony_ci            R"(%foo_name %dbg_src %dbg_src 1 10 %comp_unit FlagIsLocal 0)",
3642fd4e5da5Sopenharmony_ci            "Type"),
3643fd4e5da5Sopenharmony_ci        std::make_pair(
3644fd4e5da5Sopenharmony_ci            R"(%foo_name %float_info %comp_unit 1 10 %comp_unit FlagIsLocal 0)",
3645fd4e5da5Sopenharmony_ci            "Source"),
3646fd4e5da5Sopenharmony_ci        std::make_pair(
3647fd4e5da5Sopenharmony_ci            R"(%foo_name %float_info %dbg_src 1 10 %dbg_src FlagIsLocal 0)",
3648fd4e5da5Sopenharmony_ci            "Parent"),
3649fd4e5da5Sopenharmony_ci    }));
3650fd4e5da5Sopenharmony_ci
3651fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugLocalVariable) {
3652fd4e5da5Sopenharmony_ci  const std::string src = R"(
3653fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
3654fd4e5da5Sopenharmony_ci%code = OpString "void main() { float foo; }"
3655fd4e5da5Sopenharmony_ci%float_name = OpString "float"
3656fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
3657fd4e5da5Sopenharmony_ci)";
3658fd4e5da5Sopenharmony_ci
3659fd4e5da5Sopenharmony_ci  const std::string constants = R"(
3660fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
3661fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
3662fd4e5da5Sopenharmony_ci%u32_10 = OpConstant %u32 10
3663fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
3664fd4e5da5Sopenharmony_ci)";
3665fd4e5da5Sopenharmony_ci
3666fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
3667fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
3668fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
3669fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
3670fd4e5da5Sopenharmony_ci%foo = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %float_info %dbg_src %u32_1 %u32_10 %comp_unit %u32_4
3671fd4e5da5Sopenharmony_ci)";
3672fd4e5da5Sopenharmony_ci
3673fd4e5da5Sopenharmony_ci  const std::string extension = R"(
3674fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
3675fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
3676fd4e5da5Sopenharmony_ci)";
3677fd4e5da5Sopenharmony_ci
3678fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
3679fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
3680fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
3681fd4e5da5Sopenharmony_ci}
3682fd4e5da5Sopenharmony_ci
3683fd4e5da5Sopenharmony_ciTEST_P(ValidateVulkan100DebugInfoDebugLocalVariable, Fail) {
3684fd4e5da5Sopenharmony_ci  const std::string src = R"(
3685fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
3686fd4e5da5Sopenharmony_ci%code = OpString "void main() { float foo; }"
3687fd4e5da5Sopenharmony_ci%float_name = OpString "float"
3688fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
3689fd4e5da5Sopenharmony_ci)";
3690fd4e5da5Sopenharmony_ci
3691fd4e5da5Sopenharmony_ci  const std::string constants = R"(
3692fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
3693fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
3694fd4e5da5Sopenharmony_ci%u32_10 = OpConstant %u32 10
3695fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
3696fd4e5da5Sopenharmony_ci)";
3697fd4e5da5Sopenharmony_ci
3698fd4e5da5Sopenharmony_ci  const auto& param = GetParam();
3699fd4e5da5Sopenharmony_ci
3700fd4e5da5Sopenharmony_ci  std::ostringstream ss;
3701fd4e5da5Sopenharmony_ci  ss << R"(
3702fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
3703fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
3704fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
3705fd4e5da5Sopenharmony_ci%foo = OpExtInst %void %DbgExt DebugLocalVariable )"
3706fd4e5da5Sopenharmony_ci     << param.first;
3707fd4e5da5Sopenharmony_ci
3708fd4e5da5Sopenharmony_ci  const std::string extension = R"(
3709fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
3710fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
3711fd4e5da5Sopenharmony_ci)";
3712fd4e5da5Sopenharmony_ci
3713fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, constants, ss.str(),
3714fd4e5da5Sopenharmony_ci                                                     "", extension, "Vertex"));
3715fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3716fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
3717fd4e5da5Sopenharmony_ci              HasSubstr("expected operand " + param.second));
3718fd4e5da5Sopenharmony_ci}
3719fd4e5da5Sopenharmony_ci
3720fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(
3721fd4e5da5Sopenharmony_ci    AllVulkan100DebugInfoFail, ValidateVulkan100DebugInfoDebugLocalVariable,
3722fd4e5da5Sopenharmony_ci    ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
3723fd4e5da5Sopenharmony_ci        std::make_pair(
3724fd4e5da5Sopenharmony_ci            R"(%void %float_info %dbg_src %u32_1 %u32_10 %comp_unit %u32_3 %u32_0)",
3725fd4e5da5Sopenharmony_ci            "Name"),
3726fd4e5da5Sopenharmony_ci        std::make_pair(
3727fd4e5da5Sopenharmony_ci            R"(%foo_name %dbg_src %dbg_src %u32_1 %u32_10 %comp_unit %u32_3 %u32_0)",
3728fd4e5da5Sopenharmony_ci            "Type"),
3729fd4e5da5Sopenharmony_ci        std::make_pair(
3730fd4e5da5Sopenharmony_ci            R"(%foo_name %float_info %comp_unit %u32_1 %u32_10 %comp_unit %u32_3 %u32_0)",
3731fd4e5da5Sopenharmony_ci            "Source"),
3732fd4e5da5Sopenharmony_ci        std::make_pair(
3733fd4e5da5Sopenharmony_ci            R"(%foo_name %float_info %dbg_src %u32_1 %u32_10 %dbg_src %u32_3 %u32_0)",
3734fd4e5da5Sopenharmony_ci            "Parent"),
3735fd4e5da5Sopenharmony_ci    }));
3736fd4e5da5Sopenharmony_ci
3737fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugDeclare) {
3738fd4e5da5Sopenharmony_ci  const std::string src = R"(
3739fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
3740fd4e5da5Sopenharmony_ci%code = OpString "void main() { float foo; }"
3741fd4e5da5Sopenharmony_ci%float_name = OpString "float"
3742fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
3743fd4e5da5Sopenharmony_ci)";
3744fd4e5da5Sopenharmony_ci
3745fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
3746fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
3747fd4e5da5Sopenharmony_ci)";
3748fd4e5da5Sopenharmony_ci
3749fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
3750fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
3751fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
3752fd4e5da5Sopenharmony_ci%null_expr = OpExtInst %void %DbgExt DebugExpression
3753fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
3754fd4e5da5Sopenharmony_ci%foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %float_info %dbg_src 1 10 %comp_unit FlagIsLocal 0
3755fd4e5da5Sopenharmony_ci)";
3756fd4e5da5Sopenharmony_ci
3757fd4e5da5Sopenharmony_ci  const std::string body = R"(
3758fd4e5da5Sopenharmony_ci%foo = OpVariable %f32_ptr_function Function
3759fd4e5da5Sopenharmony_ci%decl = OpExtInst %void %DbgExt DebugDeclare %foo_info %foo %null_expr
3760fd4e5da5Sopenharmony_ci)";
3761fd4e5da5Sopenharmony_ci
3762fd4e5da5Sopenharmony_ci  const std::string extension = R"(
3763fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
3764fd4e5da5Sopenharmony_ci)";
3765fd4e5da5Sopenharmony_ci
3766fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
3767fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, body, extension, "Vertex"));
3768fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
3769fd4e5da5Sopenharmony_ci}
3770fd4e5da5Sopenharmony_ci
3771fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugDeclareParam) {
3772fd4e5da5Sopenharmony_ci  CompileSuccessfully(R"(
3773fd4e5da5Sopenharmony_ci               OpCapability Shader
3774fd4e5da5Sopenharmony_ci          %1 = OpExtInstImport "OpenCL.DebugInfo.100"
3775fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
3776fd4e5da5Sopenharmony_ci               OpEntryPoint Vertex %main "main" %in_var_COLOR
3777fd4e5da5Sopenharmony_ci          %4 = OpString "test.hlsl"
3778fd4e5da5Sopenharmony_ci               OpSource HLSL 620 %4 "#line 1 \"test.hlsl\"
3779fd4e5da5Sopenharmony_civoid main(float foo:COLOR) {}
3780fd4e5da5Sopenharmony_ci"
3781fd4e5da5Sopenharmony_ci         %11 = OpString "#line 1 \"test.hlsl\"
3782fd4e5da5Sopenharmony_civoid main(float foo:COLOR) {}
3783fd4e5da5Sopenharmony_ci"
3784fd4e5da5Sopenharmony_ci         %14 = OpString "float"
3785fd4e5da5Sopenharmony_ci         %17 = OpString "src.main"
3786fd4e5da5Sopenharmony_ci         %20 = OpString "foo"
3787fd4e5da5Sopenharmony_ci               OpName %in_var_COLOR "in.var.COLOR"
3788fd4e5da5Sopenharmony_ci               OpName %main "main"
3789fd4e5da5Sopenharmony_ci               OpName %param_var_foo "param.var.foo"
3790fd4e5da5Sopenharmony_ci               OpName %src_main "src.main"
3791fd4e5da5Sopenharmony_ci               OpName %foo "foo"
3792fd4e5da5Sopenharmony_ci               OpName %bb_entry "bb.entry"
3793fd4e5da5Sopenharmony_ci               OpDecorate %in_var_COLOR Location 0
3794fd4e5da5Sopenharmony_ci       %uint = OpTypeInt 32 0
3795fd4e5da5Sopenharmony_ci    %uint_32 = OpConstant %uint 32
3796fd4e5da5Sopenharmony_ci      %float = OpTypeFloat 32
3797fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
3798fd4e5da5Sopenharmony_ci       %void = OpTypeVoid
3799fd4e5da5Sopenharmony_ci         %23 = OpTypeFunction %void
3800fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
3801fd4e5da5Sopenharmony_ci         %29 = OpTypeFunction %void %_ptr_Function_float
3802fd4e5da5Sopenharmony_ci               OpLine %4 1 21
3803fd4e5da5Sopenharmony_ci%in_var_COLOR = OpVariable %_ptr_Input_float Input
3804fd4e5da5Sopenharmony_ci         %10 = OpExtInst %void %1 DebugExpression
3805fd4e5da5Sopenharmony_ci         %12 = OpExtInst %void %1 DebugSource %4 %11
3806fd4e5da5Sopenharmony_ci         %13 = OpExtInst %void %1 DebugCompilationUnit 1 4 %12 HLSL
3807fd4e5da5Sopenharmony_ci         %15 = OpExtInst %void %1 DebugTypeBasic %14 %uint_32 Float
3808fd4e5da5Sopenharmony_ci         %16 = OpExtInst %void %1 DebugTypeFunction FlagIsProtected|FlagIsPrivate %void %15
3809fd4e5da5Sopenharmony_ci         %18 = OpExtInst %void %1 DebugFunction %17 %16 %12 1 1 %13 %17 FlagIsProtected|FlagIsPrivate 1 %src_main
3810fd4e5da5Sopenharmony_ci         %21 = OpExtInst %void %1 DebugLocalVariable %20 %15 %12 1 17 %18 FlagIsLocal 0
3811fd4e5da5Sopenharmony_ci         %22 = OpExtInst %void %1 DebugLexicalBlock %12 1 28 %18
3812fd4e5da5Sopenharmony_ci               OpLine %4 1 1
3813fd4e5da5Sopenharmony_ci       %main = OpFunction %void None %23
3814fd4e5da5Sopenharmony_ci         %24 = OpLabel
3815fd4e5da5Sopenharmony_ci               OpLine %4 1 17
3816fd4e5da5Sopenharmony_ci%param_var_foo = OpVariable %_ptr_Function_float Function
3817fd4e5da5Sopenharmony_ci         %27 = OpLoad %float %in_var_COLOR
3818fd4e5da5Sopenharmony_ci               OpLine %4 1 1
3819fd4e5da5Sopenharmony_ci         %28 = OpFunctionCall %void %src_main %param_var_foo
3820fd4e5da5Sopenharmony_ci               OpReturn
3821fd4e5da5Sopenharmony_ci               OpFunctionEnd
3822fd4e5da5Sopenharmony_ci   %src_main = OpFunction %void None %29
3823fd4e5da5Sopenharmony_ci               OpLine %4 1 17
3824fd4e5da5Sopenharmony_ci        %foo = OpFunctionParameter %_ptr_Function_float
3825fd4e5da5Sopenharmony_ci         %31 = OpExtInst %void %1 DebugDeclare %21 %foo %10
3826fd4e5da5Sopenharmony_ci   %bb_entry = OpLabel
3827fd4e5da5Sopenharmony_ci               OpLine %4 1 29
3828fd4e5da5Sopenharmony_ci               OpReturn
3829fd4e5da5Sopenharmony_ci               OpFunctionEnd
3830fd4e5da5Sopenharmony_ci)");
3831fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
3832fd4e5da5Sopenharmony_ci}
3833fd4e5da5Sopenharmony_ci
3834fd4e5da5Sopenharmony_ciTEST_P(ValidateOpenCL100DebugInfoDebugDeclare, Fail) {
3835fd4e5da5Sopenharmony_ci  const std::string src = R"(
3836fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
3837fd4e5da5Sopenharmony_ci%code = OpString "void main() { float foo; }"
3838fd4e5da5Sopenharmony_ci%float_name = OpString "float"
3839fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
3840fd4e5da5Sopenharmony_ci)";
3841fd4e5da5Sopenharmony_ci
3842fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
3843fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
3844fd4e5da5Sopenharmony_ci)";
3845fd4e5da5Sopenharmony_ci
3846fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
3847fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
3848fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
3849fd4e5da5Sopenharmony_ci%null_expr = OpExtInst %void %DbgExt DebugExpression
3850fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
3851fd4e5da5Sopenharmony_ci%foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %float_info %dbg_src 1 10 %comp_unit FlagIsLocal 0
3852fd4e5da5Sopenharmony_ci)";
3853fd4e5da5Sopenharmony_ci
3854fd4e5da5Sopenharmony_ci  const auto& param = GetParam();
3855fd4e5da5Sopenharmony_ci
3856fd4e5da5Sopenharmony_ci  std::ostringstream ss;
3857fd4e5da5Sopenharmony_ci  ss << R"(
3858fd4e5da5Sopenharmony_ci%foo = OpVariable %f32_ptr_function Function
3859fd4e5da5Sopenharmony_ci%decl = OpExtInst %void %DbgExt DebugDeclare )"
3860fd4e5da5Sopenharmony_ci     << param.first;
3861fd4e5da5Sopenharmony_ci
3862fd4e5da5Sopenharmony_ci  const std::string extension = R"(
3863fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
3864fd4e5da5Sopenharmony_ci)";
3865fd4e5da5Sopenharmony_ci
3866fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
3867fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, ss.str(), extension, "Vertex"));
3868fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3869fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
3870fd4e5da5Sopenharmony_ci              HasSubstr("expected operand " + param.second));
3871fd4e5da5Sopenharmony_ci}
3872fd4e5da5Sopenharmony_ci
3873fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(
3874fd4e5da5Sopenharmony_ci    AllOpenCL100DebugInfoFail, ValidateOpenCL100DebugInfoDebugDeclare,
3875fd4e5da5Sopenharmony_ci    ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
3876fd4e5da5Sopenharmony_ci        std::make_pair(R"(%dbg_src %foo %null_expr)", "Local Variable"),
3877fd4e5da5Sopenharmony_ci        std::make_pair(R"(%foo_info %void %null_expr)", "Variable"),
3878fd4e5da5Sopenharmony_ci        std::make_pair(R"(%foo_info %foo %dbg_src)", "Expression"),
3879fd4e5da5Sopenharmony_ci    }));
3880fd4e5da5Sopenharmony_ci
3881fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugDeclare) {
3882fd4e5da5Sopenharmony_ci  const std::string src = R"(
3883fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
3884fd4e5da5Sopenharmony_ci%code = OpString "void main() { float foo; }"
3885fd4e5da5Sopenharmony_ci%float_name = OpString "float"
3886fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
3887fd4e5da5Sopenharmony_ci)";
3888fd4e5da5Sopenharmony_ci
3889fd4e5da5Sopenharmony_ci  const std::string constants = R"(
3890fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
3891fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
3892fd4e5da5Sopenharmony_ci%u32_10 = OpConstant %u32 10
3893fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
3894fd4e5da5Sopenharmony_ci)";
3895fd4e5da5Sopenharmony_ci
3896fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
3897fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
3898fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
3899fd4e5da5Sopenharmony_ci%null_expr = OpExtInst %void %DbgExt DebugExpression
3900fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
3901fd4e5da5Sopenharmony_ci%foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %float_info %dbg_src %u32_1 %u32_10 %comp_unit %u32_4
3902fd4e5da5Sopenharmony_ci)";
3903fd4e5da5Sopenharmony_ci
3904fd4e5da5Sopenharmony_ci  const std::string extension = R"(
3905fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
3906fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
3907fd4e5da5Sopenharmony_ci)";
3908fd4e5da5Sopenharmony_ci
3909fd4e5da5Sopenharmony_ci  const std::string body = R"(
3910fd4e5da5Sopenharmony_ci%foo = OpVariable %f32_ptr_function Function
3911fd4e5da5Sopenharmony_ci%decl = OpExtInst %void %DbgExt DebugDeclare %foo_info %foo %null_expr
3912fd4e5da5Sopenharmony_ci)";
3913fd4e5da5Sopenharmony_ci
3914fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
3915fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, body, extension, "Vertex"));
3916fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
3917fd4e5da5Sopenharmony_ci}
3918fd4e5da5Sopenharmony_ci
3919fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugDeclareParam) {
3920fd4e5da5Sopenharmony_ci  CompileSuccessfully(R"(
3921fd4e5da5Sopenharmony_ci               OpCapability Shader
3922fd4e5da5Sopenharmony_ci               OpExtension "SPV_KHR_non_semantic_info"
3923fd4e5da5Sopenharmony_ci          %1 = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
3924fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
3925fd4e5da5Sopenharmony_ci               OpEntryPoint Vertex %main "main" %in_var_COLOR
3926fd4e5da5Sopenharmony_ci          %4 = OpString "test.hlsl"
3927fd4e5da5Sopenharmony_ci               OpSource HLSL 620 %4 "#line 1 \"test.hlsl\"
3928fd4e5da5Sopenharmony_civoid main(float foo:COLOR) {}
3929fd4e5da5Sopenharmony_ci"
3930fd4e5da5Sopenharmony_ci         %11 = OpString "#line 1 \"test.hlsl\"
3931fd4e5da5Sopenharmony_civoid main(float foo:COLOR) {}
3932fd4e5da5Sopenharmony_ci"
3933fd4e5da5Sopenharmony_ci         %14 = OpString "float"
3934fd4e5da5Sopenharmony_ci         %17 = OpString "src.main"
3935fd4e5da5Sopenharmony_ci         %20 = OpString "foo"
3936fd4e5da5Sopenharmony_ci               OpName %in_var_COLOR "in.var.COLOR"
3937fd4e5da5Sopenharmony_ci               OpName %main "main"
3938fd4e5da5Sopenharmony_ci               OpName %param_var_foo "param.var.foo"
3939fd4e5da5Sopenharmony_ci               OpName %src_main "src.main"
3940fd4e5da5Sopenharmony_ci               OpName %foo "foo"
3941fd4e5da5Sopenharmony_ci               OpName %bb_entry "bb.entry"
3942fd4e5da5Sopenharmony_ci               OpDecorate %in_var_COLOR Location 0
3943fd4e5da5Sopenharmony_ci       %uint = OpTypeInt 32 0
3944fd4e5da5Sopenharmony_ci      %u32_0 = OpConstant %uint 0
3945fd4e5da5Sopenharmony_ci      %u32_1 = OpConstant %uint 1
3946fd4e5da5Sopenharmony_ci      %u32_2 = OpConstant %uint 2
3947fd4e5da5Sopenharmony_ci      %u32_3 = OpConstant %uint 3
3948fd4e5da5Sopenharmony_ci      %u32_4 = OpConstant %uint 4
3949fd4e5da5Sopenharmony_ci      %u32_5 = OpConstant %uint 5
3950fd4e5da5Sopenharmony_ci     %u32_10 = OpConstant %uint 10
3951fd4e5da5Sopenharmony_ci     %u32_17 = OpConstant %uint 17
3952fd4e5da5Sopenharmony_ci     %u32_28 = OpConstant %uint 28
3953fd4e5da5Sopenharmony_ci     %u32_32 = OpConstant %uint 32
3954fd4e5da5Sopenharmony_ci    %uint_32 = OpConstant %uint 32
3955fd4e5da5Sopenharmony_ci      %float = OpTypeFloat 32
3956fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
3957fd4e5da5Sopenharmony_ci       %void = OpTypeVoid
3958fd4e5da5Sopenharmony_ci         %23 = OpTypeFunction %void
3959fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
3960fd4e5da5Sopenharmony_ci         %29 = OpTypeFunction %void %_ptr_Function_float
3961fd4e5da5Sopenharmony_ci               OpLine %4 1 21
3962fd4e5da5Sopenharmony_ci%in_var_COLOR = OpVariable %_ptr_Input_float Input
3963fd4e5da5Sopenharmony_ci         %10 = OpExtInst %void %1 DebugExpression
3964fd4e5da5Sopenharmony_ci         %12 = OpExtInst %void %1 DebugSource %4 %11
3965fd4e5da5Sopenharmony_ci         %13 = OpExtInst %void %1 DebugCompilationUnit %u32_1 %u32_4 %12 %u32_5
3966fd4e5da5Sopenharmony_ci         %15 = OpExtInst %void %1 DebugTypeBasic %14 %uint_32 %u32_3 %u32_0
3967fd4e5da5Sopenharmony_ci         %16 = OpExtInst %void %1 DebugTypeFunction %u32_3 %void %15
3968fd4e5da5Sopenharmony_ci         %18 = OpExtInst %void %1 DebugFunction %17 %16 %12 %u32_1 %u32_1 %13 %17 %u32_3 %u32_1
3969fd4e5da5Sopenharmony_ci         %21 = OpExtInst %void %1 DebugLocalVariable %20 %15 %12 %u32_1 %u32_17 %18 %u32_4 %u32_0
3970fd4e5da5Sopenharmony_ci         %22 = OpExtInst %void %1 DebugLexicalBlock %12 %u32_1 %u32_28 %18
3971fd4e5da5Sopenharmony_ci       %main = OpFunction %void None %23
3972fd4e5da5Sopenharmony_ci         %24 = OpLabel
3973fd4e5da5Sopenharmony_ci%param_var_foo = OpVariable %_ptr_Function_float Function
3974fd4e5da5Sopenharmony_ci         %27 = OpLoad %float %in_var_COLOR
3975fd4e5da5Sopenharmony_ci         %28 = OpFunctionCall %void %src_main %param_var_foo
3976fd4e5da5Sopenharmony_ci               OpReturn
3977fd4e5da5Sopenharmony_ci               OpFunctionEnd
3978fd4e5da5Sopenharmony_ci   %src_main = OpFunction %void None %29
3979fd4e5da5Sopenharmony_ci        %foo = OpFunctionParameter %_ptr_Function_float
3980fd4e5da5Sopenharmony_ci         %31 = OpExtInst %void %1 DebugDeclare %21 %foo %10
3981fd4e5da5Sopenharmony_ci   %bb_entry = OpLabel
3982fd4e5da5Sopenharmony_ci               OpReturn
3983fd4e5da5Sopenharmony_ci               OpFunctionEnd
3984fd4e5da5Sopenharmony_ci)");
3985fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
3986fd4e5da5Sopenharmony_ci}
3987fd4e5da5Sopenharmony_ci
3988fd4e5da5Sopenharmony_ciTEST_P(ValidateVulkan100DebugInfoDebugDeclare, Fail) {
3989fd4e5da5Sopenharmony_ci  const std::string src = R"(
3990fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
3991fd4e5da5Sopenharmony_ci%code = OpString "void main() { float foo; }"
3992fd4e5da5Sopenharmony_ci%float_name = OpString "float"
3993fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
3994fd4e5da5Sopenharmony_ci)";
3995fd4e5da5Sopenharmony_ci
3996fd4e5da5Sopenharmony_ci  const std::string constants = R"(
3997fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
3998fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
3999fd4e5da5Sopenharmony_ci%u32_10 = OpConstant %u32 10
4000fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
4001fd4e5da5Sopenharmony_ci)";
4002fd4e5da5Sopenharmony_ci
4003fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
4004fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
4005fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
4006fd4e5da5Sopenharmony_ci%null_expr = OpExtInst %void %DbgExt DebugExpression
4007fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
4008fd4e5da5Sopenharmony_ci%foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %float_info %dbg_src %u32_1 %u32_10 %comp_unit %u32_4
4009fd4e5da5Sopenharmony_ci)";
4010fd4e5da5Sopenharmony_ci
4011fd4e5da5Sopenharmony_ci  const std::string extension = R"(
4012fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
4013fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
4014fd4e5da5Sopenharmony_ci)";
4015fd4e5da5Sopenharmony_ci
4016fd4e5da5Sopenharmony_ci  const auto& param = GetParam();
4017fd4e5da5Sopenharmony_ci
4018fd4e5da5Sopenharmony_ci  std::ostringstream ss;
4019fd4e5da5Sopenharmony_ci  ss << R"(
4020fd4e5da5Sopenharmony_ci%foo = OpVariable %f32_ptr_function Function
4021fd4e5da5Sopenharmony_ci%decl = OpExtInst %void %DbgExt DebugDeclare )"
4022fd4e5da5Sopenharmony_ci     << param.first;
4023fd4e5da5Sopenharmony_ci
4024fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
4025fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, ss.str(), extension, "Vertex"));
4026fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4027fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
4028fd4e5da5Sopenharmony_ci              HasSubstr("expected operand " + param.second));
4029fd4e5da5Sopenharmony_ci}
4030fd4e5da5Sopenharmony_ci
4031fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(
4032fd4e5da5Sopenharmony_ci    AllVulkan100DebugInfoFail, ValidateVulkan100DebugInfoDebugDeclare,
4033fd4e5da5Sopenharmony_ci    ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
4034fd4e5da5Sopenharmony_ci        std::make_pair(R"(%dbg_src %foo %null_expr)", "Local Variable"),
4035fd4e5da5Sopenharmony_ci        std::make_pair(R"(%foo_info %void %null_expr)", "Variable"),
4036fd4e5da5Sopenharmony_ci        std::make_pair(R"(%foo_info %foo %dbg_src)", "Expression"),
4037fd4e5da5Sopenharmony_ci    }));
4038fd4e5da5Sopenharmony_ci
4039fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugExpression) {
4040fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
4041fd4e5da5Sopenharmony_ci%op0 = OpExtInst %void %DbgExt DebugOperation Deref
4042fd4e5da5Sopenharmony_ci%op1 = OpExtInst %void %DbgExt DebugOperation Plus
4043fd4e5da5Sopenharmony_ci%null_expr = OpExtInst %void %DbgExt DebugExpression %op0 %op1
4044fd4e5da5Sopenharmony_ci)";
4045fd4e5da5Sopenharmony_ci
4046fd4e5da5Sopenharmony_ci  const std::string extension = R"(
4047fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
4048fd4e5da5Sopenharmony_ci)";
4049fd4e5da5Sopenharmony_ci
4050fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo("", "", dbg_inst_header,
4051fd4e5da5Sopenharmony_ci                                                     "", extension, "Vertex"));
4052fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4053fd4e5da5Sopenharmony_ci}
4054fd4e5da5Sopenharmony_ci
4055fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugExpressionFail) {
4056fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
4057fd4e5da5Sopenharmony_ci%op = OpExtInst %void %DbgExt DebugOperation Deref
4058fd4e5da5Sopenharmony_ci%null_expr = OpExtInst %void %DbgExt DebugExpression %op %void
4059fd4e5da5Sopenharmony_ci)";
4060fd4e5da5Sopenharmony_ci
4061fd4e5da5Sopenharmony_ci  const std::string extension = R"(
4062fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
4063fd4e5da5Sopenharmony_ci)";
4064fd4e5da5Sopenharmony_ci
4065fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo("", "", dbg_inst_header,
4066fd4e5da5Sopenharmony_ci                                                     "", extension, "Vertex"));
4067fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4068fd4e5da5Sopenharmony_ci  EXPECT_THAT(
4069fd4e5da5Sopenharmony_ci      getDiagnosticString(),
4070fd4e5da5Sopenharmony_ci      HasSubstr(
4071fd4e5da5Sopenharmony_ci          "expected operand Operation must be a result id of DebugOperation"));
4072fd4e5da5Sopenharmony_ci}
4073fd4e5da5Sopenharmony_ci
4074fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugExpression) {
4075fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
4076fd4e5da5Sopenharmony_ci%op0 = OpExtInst %void %DbgExt DebugOperation %u32_0
4077fd4e5da5Sopenharmony_ci%op1 = OpExtInst %void %DbgExt DebugOperation %u32_1
4078fd4e5da5Sopenharmony_ci%null_expr = OpExtInst %void %DbgExt DebugExpression %op0 %op1
4079fd4e5da5Sopenharmony_ci)";
4080fd4e5da5Sopenharmony_ci
4081fd4e5da5Sopenharmony_ci  const std::string extension = R"(
4082fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
4083fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
4084fd4e5da5Sopenharmony_ci)";
4085fd4e5da5Sopenharmony_ci
4086fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo("", "", dbg_inst_header,
4087fd4e5da5Sopenharmony_ci                                                     "", extension, "Vertex"));
4088fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4089fd4e5da5Sopenharmony_ci}
4090fd4e5da5Sopenharmony_ci
4091fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugExpressionFail) {
4092fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
4093fd4e5da5Sopenharmony_ci%op = OpExtInst %void %DbgExt DebugOperation %u32_0
4094fd4e5da5Sopenharmony_ci%null_expr = OpExtInst %void %DbgExt DebugExpression %op %void
4095fd4e5da5Sopenharmony_ci)";
4096fd4e5da5Sopenharmony_ci
4097fd4e5da5Sopenharmony_ci  const std::string extension = R"(
4098fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
4099fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
4100fd4e5da5Sopenharmony_ci)";
4101fd4e5da5Sopenharmony_ci
4102fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo("", "", dbg_inst_header,
4103fd4e5da5Sopenharmony_ci                                                     "", extension, "Vertex"));
4104fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4105fd4e5da5Sopenharmony_ci  EXPECT_THAT(
4106fd4e5da5Sopenharmony_ci      getDiagnosticString(),
4107fd4e5da5Sopenharmony_ci      HasSubstr(
4108fd4e5da5Sopenharmony_ci          "expected operand Operation must be a result id of DebugOperation"));
4109fd4e5da5Sopenharmony_ci}
4110fd4e5da5Sopenharmony_ci
4111fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugTypeTemplate) {
4112fd4e5da5Sopenharmony_ci  const std::string src = R"(
4113fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
4114fd4e5da5Sopenharmony_ci%code = OpString "OpaqueType foo;
4115fd4e5da5Sopenharmony_cimain() {}
4116fd4e5da5Sopenharmony_ci"
4117fd4e5da5Sopenharmony_ci%float_name = OpString "float"
4118fd4e5da5Sopenharmony_ci%ty_name = OpString "Texture"
4119fd4e5da5Sopenharmony_ci%t_name = OpString "T"
4120fd4e5da5Sopenharmony_ci)";
4121fd4e5da5Sopenharmony_ci
4122fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
4123fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
4124fd4e5da5Sopenharmony_ci%int_128 = OpConstant %u32 128
4125fd4e5da5Sopenharmony_ci)";
4126fd4e5da5Sopenharmony_ci
4127fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
4128fd4e5da5Sopenharmony_ci%dbg_none = OpExtInst %void %DbgExt DebugInfoNone
4129fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
4130fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
4131fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
4132fd4e5da5Sopenharmony_ci%opaque = OpExtInst %void %DbgExt DebugTypeComposite %ty_name Class %dbg_src 1 1 %comp_unit %ty_name %dbg_none FlagIsPublic
4133fd4e5da5Sopenharmony_ci%param = OpExtInst %void %DbgExt DebugTypeTemplateParameter %t_name %float_info %dbg_none %dbg_src 0 0
4134fd4e5da5Sopenharmony_ci%temp = OpExtInst %void %DbgExt DebugTypeTemplate %opaque %param
4135fd4e5da5Sopenharmony_ci)";
4136fd4e5da5Sopenharmony_ci
4137fd4e5da5Sopenharmony_ci  const std::string extension = R"(
4138fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
4139fd4e5da5Sopenharmony_ci)";
4140fd4e5da5Sopenharmony_ci
4141fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
4142fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, "", extension, "Vertex"));
4143fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4144fd4e5da5Sopenharmony_ci}
4145fd4e5da5Sopenharmony_ci
4146fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugTypeTemplateUsedForVariableType) {
4147fd4e5da5Sopenharmony_ci  const std::string src = R"(
4148fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
4149fd4e5da5Sopenharmony_ci%code = OpString "OpaqueType foo;
4150fd4e5da5Sopenharmony_cimain() {}
4151fd4e5da5Sopenharmony_ci"
4152fd4e5da5Sopenharmony_ci%float_name = OpString "float"
4153fd4e5da5Sopenharmony_ci%ty_name = OpString "Texture"
4154fd4e5da5Sopenharmony_ci%t_name = OpString "T"
4155fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
4156fd4e5da5Sopenharmony_ci)";
4157fd4e5da5Sopenharmony_ci
4158fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
4159fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
4160fd4e5da5Sopenharmony_ci%int_128 = OpConstant %u32 128
4161fd4e5da5Sopenharmony_ci)";
4162fd4e5da5Sopenharmony_ci
4163fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
4164fd4e5da5Sopenharmony_ci%dbg_none = OpExtInst %void %DbgExt DebugInfoNone
4165fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
4166fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
4167fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
4168fd4e5da5Sopenharmony_ci%opaque = OpExtInst %void %DbgExt DebugTypeComposite %ty_name Class %dbg_src 1 1 %comp_unit %ty_name %dbg_none FlagIsPublic
4169fd4e5da5Sopenharmony_ci%param = OpExtInst %void %DbgExt DebugTypeTemplateParameter %t_name %float_info %dbg_none %dbg_src 0 0
4170fd4e5da5Sopenharmony_ci%temp = OpExtInst %void %DbgExt DebugTypeTemplate %opaque %param
4171fd4e5da5Sopenharmony_ci%foo = OpExtInst %void %DbgExt DebugGlobalVariable %foo_name %temp %dbg_src 0 0 %comp_unit %foo_name %f32_input FlagIsProtected|FlagIsPrivate
4172fd4e5da5Sopenharmony_ci)";
4173fd4e5da5Sopenharmony_ci
4174fd4e5da5Sopenharmony_ci  const std::string extension = R"(
4175fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
4176fd4e5da5Sopenharmony_ci)";
4177fd4e5da5Sopenharmony_ci
4178fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
4179fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, "", extension, "Vertex"));
4180fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4181fd4e5da5Sopenharmony_ci}
4182fd4e5da5Sopenharmony_ci
4183fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugTypeTemplateFunction) {
4184fd4e5da5Sopenharmony_ci  const std::string src = R"(
4185fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
4186fd4e5da5Sopenharmony_ci%code = OpString "OpaqueType foo;
4187fd4e5da5Sopenharmony_cimain() {}
4188fd4e5da5Sopenharmony_ci"
4189fd4e5da5Sopenharmony_ci%float_name = OpString "float"
4190fd4e5da5Sopenharmony_ci%ty_name = OpString "Texture"
4191fd4e5da5Sopenharmony_ci%t_name = OpString "T"
4192fd4e5da5Sopenharmony_ci%main_name = OpString "main"
4193fd4e5da5Sopenharmony_ci)";
4194fd4e5da5Sopenharmony_ci
4195fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
4196fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
4197fd4e5da5Sopenharmony_ci%int_128 = OpConstant %u32 128
4198fd4e5da5Sopenharmony_ci)";
4199fd4e5da5Sopenharmony_ci
4200fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
4201fd4e5da5Sopenharmony_ci%dbg_none = OpExtInst %void %DbgExt DebugInfoNone
4202fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
4203fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
4204fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
4205fd4e5da5Sopenharmony_ci%param = OpExtInst %void %DbgExt DebugTypeTemplateParameter %t_name %float_info %dbg_none %dbg_src 0 0
4206fd4e5da5Sopenharmony_ci%main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %param %param
4207fd4e5da5Sopenharmony_ci%main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 1 1 %comp_unit %main_name FlagIsPublic 1 %main
4208fd4e5da5Sopenharmony_ci%temp = OpExtInst %void %DbgExt DebugTypeTemplate %main_info %param
4209fd4e5da5Sopenharmony_ci)";
4210fd4e5da5Sopenharmony_ci
4211fd4e5da5Sopenharmony_ci  const std::string extension = R"(
4212fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
4213fd4e5da5Sopenharmony_ci)";
4214fd4e5da5Sopenharmony_ci
4215fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
4216fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, "", extension, "Vertex"));
4217fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4218fd4e5da5Sopenharmony_ci}
4219fd4e5da5Sopenharmony_ci
4220fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugTypeTemplateFailTarget) {
4221fd4e5da5Sopenharmony_ci  const std::string src = R"(
4222fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
4223fd4e5da5Sopenharmony_ci%code = OpString "OpaqueType foo;
4224fd4e5da5Sopenharmony_cimain() {}
4225fd4e5da5Sopenharmony_ci"
4226fd4e5da5Sopenharmony_ci%float_name = OpString "float"
4227fd4e5da5Sopenharmony_ci%ty_name = OpString "Texture"
4228fd4e5da5Sopenharmony_ci%t_name = OpString "T"
4229fd4e5da5Sopenharmony_ci%main_name = OpString "main"
4230fd4e5da5Sopenharmony_ci)";
4231fd4e5da5Sopenharmony_ci
4232fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
4233fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
4234fd4e5da5Sopenharmony_ci%int_128 = OpConstant %u32 128
4235fd4e5da5Sopenharmony_ci)";
4236fd4e5da5Sopenharmony_ci
4237fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
4238fd4e5da5Sopenharmony_ci%dbg_none = OpExtInst %void %DbgExt DebugInfoNone
4239fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
4240fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
4241fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
4242fd4e5da5Sopenharmony_ci%param = OpExtInst %void %DbgExt DebugTypeTemplateParameter %t_name %float_info %dbg_none %dbg_src 0 0
4243fd4e5da5Sopenharmony_ci%temp = OpExtInst %void %DbgExt DebugTypeTemplate %float_info %param
4244fd4e5da5Sopenharmony_ci)";
4245fd4e5da5Sopenharmony_ci
4246fd4e5da5Sopenharmony_ci  const std::string extension = R"(
4247fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
4248fd4e5da5Sopenharmony_ci)";
4249fd4e5da5Sopenharmony_ci
4250fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
4251fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, "", extension, "Vertex"));
4252fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4253fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
4254fd4e5da5Sopenharmony_ci              HasSubstr("expected operand Target must be DebugTypeComposite or "
4255fd4e5da5Sopenharmony_ci                        "DebugFunction"));
4256fd4e5da5Sopenharmony_ci}
4257fd4e5da5Sopenharmony_ci
4258fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugTypeTemplateFailParam) {
4259fd4e5da5Sopenharmony_ci  const std::string src = R"(
4260fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
4261fd4e5da5Sopenharmony_ci%code = OpString "OpaqueType foo;
4262fd4e5da5Sopenharmony_cimain() {}
4263fd4e5da5Sopenharmony_ci"
4264fd4e5da5Sopenharmony_ci%float_name = OpString "float"
4265fd4e5da5Sopenharmony_ci%ty_name = OpString "Texture"
4266fd4e5da5Sopenharmony_ci%t_name = OpString "T"
4267fd4e5da5Sopenharmony_ci%main_name = OpString "main"
4268fd4e5da5Sopenharmony_ci)";
4269fd4e5da5Sopenharmony_ci
4270fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
4271fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
4272fd4e5da5Sopenharmony_ci%int_128 = OpConstant %u32 128
4273fd4e5da5Sopenharmony_ci)";
4274fd4e5da5Sopenharmony_ci
4275fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
4276fd4e5da5Sopenharmony_ci%dbg_none = OpExtInst %void %DbgExt DebugInfoNone
4277fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
4278fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
4279fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
4280fd4e5da5Sopenharmony_ci%param = OpExtInst %void %DbgExt DebugTypeTemplateParameter %t_name %float_info %dbg_none %dbg_src 0 0
4281fd4e5da5Sopenharmony_ci%main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %param %param
4282fd4e5da5Sopenharmony_ci%main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 1 1 %comp_unit %main_name FlagIsPublic 1 %main
4283fd4e5da5Sopenharmony_ci%temp = OpExtInst %void %DbgExt DebugTypeTemplate %main_info %float_info
4284fd4e5da5Sopenharmony_ci)";
4285fd4e5da5Sopenharmony_ci
4286fd4e5da5Sopenharmony_ci  const std::string extension = R"(
4287fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
4288fd4e5da5Sopenharmony_ci)";
4289fd4e5da5Sopenharmony_ci
4290fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
4291fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, "", extension, "Vertex"));
4292fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4293fd4e5da5Sopenharmony_ci  EXPECT_THAT(
4294fd4e5da5Sopenharmony_ci      getDiagnosticString(),
4295fd4e5da5Sopenharmony_ci      HasSubstr(
4296fd4e5da5Sopenharmony_ci          "expected operand Parameters must be DebugTypeTemplateParameter or "
4297fd4e5da5Sopenharmony_ci          "DebugTypeTemplateTemplateParameter"));
4298fd4e5da5Sopenharmony_ci}
4299fd4e5da5Sopenharmony_ci
4300fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugTypeTemplate) {
4301fd4e5da5Sopenharmony_ci  const std::string src = R"(
4302fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
4303fd4e5da5Sopenharmony_ci%code = OpString "OpaqueType foo;
4304fd4e5da5Sopenharmony_cimain() {}
4305fd4e5da5Sopenharmony_ci"
4306fd4e5da5Sopenharmony_ci%float_name = OpString "float"
4307fd4e5da5Sopenharmony_ci%ty_name = OpString "Texture"
4308fd4e5da5Sopenharmony_ci%t_name = OpString "T"
4309fd4e5da5Sopenharmony_ci)";
4310fd4e5da5Sopenharmony_ci
4311fd4e5da5Sopenharmony_ci  const std::string constants = R"(
4312fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
4313fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
4314fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
4315fd4e5da5Sopenharmony_ci)";
4316fd4e5da5Sopenharmony_ci
4317fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
4318fd4e5da5Sopenharmony_ci%dbg_none = OpExtInst %void %DbgExt DebugInfoNone
4319fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
4320fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
4321fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
4322fd4e5da5Sopenharmony_ci%opaque = OpExtInst %void %DbgExt DebugTypeComposite %ty_name %u32_1 %dbg_src %u32_1 %u32_1 %comp_unit %ty_name %dbg_none %u32_3
4323fd4e5da5Sopenharmony_ci%param = OpExtInst %void %DbgExt DebugTypeTemplateParameter %t_name %float_info %dbg_none %dbg_src %u32_0 %u32_0
4324fd4e5da5Sopenharmony_ci%temp = OpExtInst %void %DbgExt DebugTypeTemplate %opaque %param
4325fd4e5da5Sopenharmony_ci)";
4326fd4e5da5Sopenharmony_ci
4327fd4e5da5Sopenharmony_ci  const std::string extension = R"(
4328fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
4329fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
4330fd4e5da5Sopenharmony_ci)";
4331fd4e5da5Sopenharmony_ci
4332fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
4333fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
4334fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4335fd4e5da5Sopenharmony_ci}
4336fd4e5da5Sopenharmony_ci
4337fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugTypeTemplateUsedForVariableType) {
4338fd4e5da5Sopenharmony_ci  const std::string src = R"(
4339fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
4340fd4e5da5Sopenharmony_ci%code = OpString "OpaqueType foo;
4341fd4e5da5Sopenharmony_cimain() {}
4342fd4e5da5Sopenharmony_ci"
4343fd4e5da5Sopenharmony_ci%float_name = OpString "float"
4344fd4e5da5Sopenharmony_ci%ty_name = OpString "Texture"
4345fd4e5da5Sopenharmony_ci%t_name = OpString "T"
4346fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
4347fd4e5da5Sopenharmony_ci)";
4348fd4e5da5Sopenharmony_ci
4349fd4e5da5Sopenharmony_ci  const std::string constants = R"(
4350fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
4351fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
4352fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
4353fd4e5da5Sopenharmony_ci)";
4354fd4e5da5Sopenharmony_ci
4355fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
4356fd4e5da5Sopenharmony_ci%dbg_none = OpExtInst %void %DbgExt DebugInfoNone
4357fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
4358fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
4359fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
4360fd4e5da5Sopenharmony_ci%opaque = OpExtInst %void %DbgExt DebugTypeComposite %ty_name %u32_1 %dbg_src %u32_1 %u32_1 %comp_unit %ty_name %dbg_none %u32_3
4361fd4e5da5Sopenharmony_ci%param = OpExtInst %void %DbgExt DebugTypeTemplateParameter %t_name %float_info %dbg_none %dbg_src %u32_0 %u32_0
4362fd4e5da5Sopenharmony_ci%temp = OpExtInst %void %DbgExt DebugTypeTemplate %opaque %param
4363fd4e5da5Sopenharmony_ci%foo = OpExtInst %void %DbgExt DebugGlobalVariable %foo_name %temp %dbg_src %u32_0 %u32_0 %comp_unit %foo_name %f32_input %u32_3
4364fd4e5da5Sopenharmony_ci)";
4365fd4e5da5Sopenharmony_ci
4366fd4e5da5Sopenharmony_ci  const std::string extension = R"(
4367fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
4368fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
4369fd4e5da5Sopenharmony_ci)";
4370fd4e5da5Sopenharmony_ci
4371fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
4372fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
4373fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4374fd4e5da5Sopenharmony_ci}
4375fd4e5da5Sopenharmony_ci
4376fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugTypeTemplateFunction) {
4377fd4e5da5Sopenharmony_ci  const std::string src = R"(
4378fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
4379fd4e5da5Sopenharmony_ci%code = OpString "OpaqueType foo;
4380fd4e5da5Sopenharmony_cimain() {}
4381fd4e5da5Sopenharmony_ci"
4382fd4e5da5Sopenharmony_ci%float_name = OpString "float"
4383fd4e5da5Sopenharmony_ci%ty_name = OpString "Texture"
4384fd4e5da5Sopenharmony_ci%t_name = OpString "T"
4385fd4e5da5Sopenharmony_ci%main_name = OpString "main"
4386fd4e5da5Sopenharmony_ci)";
4387fd4e5da5Sopenharmony_ci
4388fd4e5da5Sopenharmony_ci  const std::string constants = R"(
4389fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
4390fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
4391fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
4392fd4e5da5Sopenharmony_ci)";
4393fd4e5da5Sopenharmony_ci
4394fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
4395fd4e5da5Sopenharmony_ci%dbg_none = OpExtInst %void %DbgExt DebugInfoNone
4396fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
4397fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
4398fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
4399fd4e5da5Sopenharmony_ci%param = OpExtInst %void %DbgExt DebugTypeTemplateParameter %t_name %float_info %dbg_none %dbg_src %u32_0 %u32_0
4400fd4e5da5Sopenharmony_ci%main_type_info = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %param %param
4401fd4e5da5Sopenharmony_ci%main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src %u32_1 %u32_1 %comp_unit %main_name %u32_3 %u32_1
4402fd4e5da5Sopenharmony_ci%temp = OpExtInst %void %DbgExt DebugTypeTemplate %main_info %param
4403fd4e5da5Sopenharmony_ci)";
4404fd4e5da5Sopenharmony_ci
4405fd4e5da5Sopenharmony_ci  const std::string extension = R"(
4406fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
4407fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
4408fd4e5da5Sopenharmony_ci)";
4409fd4e5da5Sopenharmony_ci
4410fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
4411fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
4412fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4413fd4e5da5Sopenharmony_ci}
4414fd4e5da5Sopenharmony_ci
4415fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugTypeTemplateFailTarget) {
4416fd4e5da5Sopenharmony_ci  const std::string src = R"(
4417fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
4418fd4e5da5Sopenharmony_ci%code = OpString "OpaqueType foo;
4419fd4e5da5Sopenharmony_cimain() {}
4420fd4e5da5Sopenharmony_ci"
4421fd4e5da5Sopenharmony_ci%float_name = OpString "float"
4422fd4e5da5Sopenharmony_ci%ty_name = OpString "Texture"
4423fd4e5da5Sopenharmony_ci%t_name = OpString "T"
4424fd4e5da5Sopenharmony_ci%main_name = OpString "main"
4425fd4e5da5Sopenharmony_ci)";
4426fd4e5da5Sopenharmony_ci
4427fd4e5da5Sopenharmony_ci  const std::string constants = R"(
4428fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
4429fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
4430fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
4431fd4e5da5Sopenharmony_ci)";
4432fd4e5da5Sopenharmony_ci
4433fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
4434fd4e5da5Sopenharmony_ci%dbg_none = OpExtInst %void %DbgExt DebugInfoNone
4435fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
4436fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
4437fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
4438fd4e5da5Sopenharmony_ci%param = OpExtInst %void %DbgExt DebugTypeTemplateParameter %t_name %float_info %dbg_none %dbg_src %u32_0 %u32_0
4439fd4e5da5Sopenharmony_ci%temp = OpExtInst %void %DbgExt DebugTypeTemplate %float_info %param
4440fd4e5da5Sopenharmony_ci)";
4441fd4e5da5Sopenharmony_ci
4442fd4e5da5Sopenharmony_ci  const std::string extension = R"(
4443fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
4444fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
4445fd4e5da5Sopenharmony_ci)";
4446fd4e5da5Sopenharmony_ci
4447fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
4448fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
4449fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4450fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
4451fd4e5da5Sopenharmony_ci              HasSubstr("expected operand Target must be DebugTypeComposite or "
4452fd4e5da5Sopenharmony_ci                        "DebugFunction"));
4453fd4e5da5Sopenharmony_ci}
4454fd4e5da5Sopenharmony_ci
4455fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugTypeTemplateFailParam) {
4456fd4e5da5Sopenharmony_ci  const std::string src = R"(
4457fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
4458fd4e5da5Sopenharmony_ci%code = OpString "OpaqueType foo;
4459fd4e5da5Sopenharmony_cimain() {}
4460fd4e5da5Sopenharmony_ci"
4461fd4e5da5Sopenharmony_ci%float_name = OpString "float"
4462fd4e5da5Sopenharmony_ci%ty_name = OpString "Texture"
4463fd4e5da5Sopenharmony_ci%t_name = OpString "T"
4464fd4e5da5Sopenharmony_ci%main_name = OpString "main"
4465fd4e5da5Sopenharmony_ci)";
4466fd4e5da5Sopenharmony_ci
4467fd4e5da5Sopenharmony_ci  const std::string constants = R"(
4468fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
4469fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
4470fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
4471fd4e5da5Sopenharmony_ci)";
4472fd4e5da5Sopenharmony_ci
4473fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
4474fd4e5da5Sopenharmony_ci%dbg_none = OpExtInst %void %DbgExt DebugInfoNone
4475fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
4476fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
4477fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
4478fd4e5da5Sopenharmony_ci%opaque = OpExtInst %void %DbgExt DebugTypeComposite %ty_name %u32_1 %dbg_src %u32_1 %u32_1 %comp_unit %ty_name %dbg_none %u32_3
4479fd4e5da5Sopenharmony_ci%param = OpExtInst %void %DbgExt DebugTypeTemplateParameter %t_name %float_info %dbg_none %dbg_src %u32_0 %u32_0
4480fd4e5da5Sopenharmony_ci%temp = OpExtInst %void %DbgExt DebugTypeTemplate %opaque %float_info
4481fd4e5da5Sopenharmony_ci)";
4482fd4e5da5Sopenharmony_ci
4483fd4e5da5Sopenharmony_ci  const std::string extension = R"(
4484fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
4485fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
4486fd4e5da5Sopenharmony_ci)";
4487fd4e5da5Sopenharmony_ci
4488fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
4489fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
4490fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4491fd4e5da5Sopenharmony_ci  EXPECT_THAT(
4492fd4e5da5Sopenharmony_ci      getDiagnosticString(),
4493fd4e5da5Sopenharmony_ci      HasSubstr(
4494fd4e5da5Sopenharmony_ci          "expected operand Parameters must be DebugTypeTemplateParameter or "
4495fd4e5da5Sopenharmony_ci          "DebugTypeTemplateTemplateParameter"));
4496fd4e5da5Sopenharmony_ci}
4497fd4e5da5Sopenharmony_ci
4498fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugGlobalVariable) {
4499fd4e5da5Sopenharmony_ci  const std::string src = R"(
4500fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
4501fd4e5da5Sopenharmony_ci%code = OpString "float foo; void main() {}"
4502fd4e5da5Sopenharmony_ci%float_name = OpString "float"
4503fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
4504fd4e5da5Sopenharmony_ci)";
4505fd4e5da5Sopenharmony_ci
4506fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
4507fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
4508fd4e5da5Sopenharmony_ci)";
4509fd4e5da5Sopenharmony_ci
4510fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
4511fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
4512fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
4513fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
4514fd4e5da5Sopenharmony_ci%foo = OpExtInst %void %DbgExt DebugGlobalVariable %foo_name %float_info %dbg_src 0 0 %comp_unit %foo_name %f32_input FlagIsProtected|FlagIsPrivate
4515fd4e5da5Sopenharmony_ci)";
4516fd4e5da5Sopenharmony_ci
4517fd4e5da5Sopenharmony_ci  const std::string extension = R"(
4518fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
4519fd4e5da5Sopenharmony_ci)";
4520fd4e5da5Sopenharmony_ci
4521fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
4522fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, "", extension, "Vertex"));
4523fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4524fd4e5da5Sopenharmony_ci}
4525fd4e5da5Sopenharmony_ci
4526fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugGlobalVariableStaticMember) {
4527fd4e5da5Sopenharmony_ci  const std::string src = R"(
4528fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
4529fd4e5da5Sopenharmony_ci%code = OpString "float foo; void main() {}"
4530fd4e5da5Sopenharmony_ci%float_name = OpString "float"
4531fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
4532fd4e5da5Sopenharmony_ci)";
4533fd4e5da5Sopenharmony_ci
4534fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
4535fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
4536fd4e5da5Sopenharmony_ci)";
4537fd4e5da5Sopenharmony_ci
4538fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
4539fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
4540fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
4541fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
4542fd4e5da5Sopenharmony_ci%t = OpExtInst %void %DbgExt DebugTypeComposite %foo_name Class %dbg_src 0 0 %comp_unit %foo_name %int_32 FlagIsPublic %a
4543fd4e5da5Sopenharmony_ci%a = OpExtInst %void %DbgExt DebugTypeMember %foo_name %float_info %dbg_src 0 0 %t %u32_0 %int_32 FlagIsPublic
4544fd4e5da5Sopenharmony_ci%foo = OpExtInst %void %DbgExt DebugGlobalVariable %foo_name %float_info %dbg_src 0 0 %comp_unit %foo_name %f32_input FlagIsProtected|FlagIsPrivate %a
4545fd4e5da5Sopenharmony_ci)";
4546fd4e5da5Sopenharmony_ci
4547fd4e5da5Sopenharmony_ci  const std::string extension = R"(
4548fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
4549fd4e5da5Sopenharmony_ci)";
4550fd4e5da5Sopenharmony_ci
4551fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
4552fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, "", extension, "Vertex"));
4553fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4554fd4e5da5Sopenharmony_ci}
4555fd4e5da5Sopenharmony_ci
4556fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugGlobalVariableDebugInfoNone) {
4557fd4e5da5Sopenharmony_ci  const std::string src = R"(
4558fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
4559fd4e5da5Sopenharmony_ci%code = OpString "float foo; void main() {}"
4560fd4e5da5Sopenharmony_ci%float_name = OpString "float"
4561fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
4562fd4e5da5Sopenharmony_ci)";
4563fd4e5da5Sopenharmony_ci
4564fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
4565fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
4566fd4e5da5Sopenharmony_ci)";
4567fd4e5da5Sopenharmony_ci
4568fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
4569fd4e5da5Sopenharmony_ci%dbgNone = OpExtInst %void %DbgExt DebugInfoNone
4570fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
4571fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
4572fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
4573fd4e5da5Sopenharmony_ci%foo = OpExtInst %void %DbgExt DebugGlobalVariable %foo_name %float_info %dbg_src 0 0 %comp_unit %foo_name %dbgNone FlagIsProtected|FlagIsPrivate
4574fd4e5da5Sopenharmony_ci)";
4575fd4e5da5Sopenharmony_ci
4576fd4e5da5Sopenharmony_ci  const std::string extension = R"(
4577fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
4578fd4e5da5Sopenharmony_ci)";
4579fd4e5da5Sopenharmony_ci
4580fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
4581fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, "", extension, "Vertex"));
4582fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4583fd4e5da5Sopenharmony_ci}
4584fd4e5da5Sopenharmony_ci
4585fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugGlobalVariableConst) {
4586fd4e5da5Sopenharmony_ci  const std::string src = R"(
4587fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
4588fd4e5da5Sopenharmony_ci%code = OpString "float foo; void main() {}"
4589fd4e5da5Sopenharmony_ci%float_name = OpString "float"
4590fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
4591fd4e5da5Sopenharmony_ci)";
4592fd4e5da5Sopenharmony_ci
4593fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
4594fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
4595fd4e5da5Sopenharmony_ci)";
4596fd4e5da5Sopenharmony_ci
4597fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
4598fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
4599fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
4600fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
4601fd4e5da5Sopenharmony_ci%foo = OpExtInst %void %DbgExt DebugGlobalVariable %foo_name %float_info %dbg_src 0 0 %comp_unit %foo_name %int_32 FlagIsProtected|FlagIsPrivate
4602fd4e5da5Sopenharmony_ci)";
4603fd4e5da5Sopenharmony_ci
4604fd4e5da5Sopenharmony_ci  const std::string extension = R"(
4605fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
4606fd4e5da5Sopenharmony_ci)";
4607fd4e5da5Sopenharmony_ci
4608fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
4609fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, "", extension, "Vertex"));
4610fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4611fd4e5da5Sopenharmony_ci}
4612fd4e5da5Sopenharmony_ci
4613fd4e5da5Sopenharmony_ciTEST_P(ValidateOpenCL100DebugInfoDebugGlobalVariable, Fail) {
4614fd4e5da5Sopenharmony_ci  const std::string src = R"(
4615fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
4616fd4e5da5Sopenharmony_ci%code = OpString "float foo; void main() {}"
4617fd4e5da5Sopenharmony_ci%float_name = OpString "float"
4618fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
4619fd4e5da5Sopenharmony_ci)";
4620fd4e5da5Sopenharmony_ci
4621fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
4622fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
4623fd4e5da5Sopenharmony_ci)";
4624fd4e5da5Sopenharmony_ci
4625fd4e5da5Sopenharmony_ci  const auto& param = GetParam();
4626fd4e5da5Sopenharmony_ci
4627fd4e5da5Sopenharmony_ci  std::ostringstream ss;
4628fd4e5da5Sopenharmony_ci  ss << R"(
4629fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
4630fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
4631fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
4632fd4e5da5Sopenharmony_ci%foo = OpExtInst %void %DbgExt DebugGlobalVariable )"
4633fd4e5da5Sopenharmony_ci     << param.first;
4634fd4e5da5Sopenharmony_ci
4635fd4e5da5Sopenharmony_ci  const std::string extension = R"(
4636fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
4637fd4e5da5Sopenharmony_ci)";
4638fd4e5da5Sopenharmony_ci
4639fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, size_const, ss.str(),
4640fd4e5da5Sopenharmony_ci                                                     "", extension, "Vertex"));
4641fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4642fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
4643fd4e5da5Sopenharmony_ci              HasSubstr("expected operand " + param.second));
4644fd4e5da5Sopenharmony_ci}
4645fd4e5da5Sopenharmony_ci
4646fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(
4647fd4e5da5Sopenharmony_ci    AllOpenCL100DebugInfoFail, ValidateOpenCL100DebugInfoDebugGlobalVariable,
4648fd4e5da5Sopenharmony_ci    ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
4649fd4e5da5Sopenharmony_ci        std::make_pair(
4650fd4e5da5Sopenharmony_ci            R"(%void %float_info %dbg_src 0 0 %comp_unit %foo_name %f32_input FlagIsProtected|FlagIsPrivate)",
4651fd4e5da5Sopenharmony_ci            "Name"),
4652fd4e5da5Sopenharmony_ci        std::make_pair(
4653fd4e5da5Sopenharmony_ci            R"(%foo_name %dbg_src %dbg_src 0 0 %comp_unit %foo_name %f32_input FlagIsProtected|FlagIsPrivate)",
4654fd4e5da5Sopenharmony_ci            "Type"),
4655fd4e5da5Sopenharmony_ci        std::make_pair(
4656fd4e5da5Sopenharmony_ci            R"(%foo_name %float_info %comp_unit 0 0 %comp_unit %foo_name %f32_input FlagIsProtected|FlagIsPrivate)",
4657fd4e5da5Sopenharmony_ci            "Source"),
4658fd4e5da5Sopenharmony_ci        std::make_pair(
4659fd4e5da5Sopenharmony_ci            R"(%foo_name %float_info %dbg_src 0 0 %dbg_src %foo_name %f32_input FlagIsProtected|FlagIsPrivate)",
4660fd4e5da5Sopenharmony_ci            "Scope"),
4661fd4e5da5Sopenharmony_ci        std::make_pair(
4662fd4e5da5Sopenharmony_ci            R"(%foo_name %float_info %dbg_src 0 0 %comp_unit %void %f32_input FlagIsProtected|FlagIsPrivate)",
4663fd4e5da5Sopenharmony_ci            "Linkage Name"),
4664fd4e5da5Sopenharmony_ci        std::make_pair(
4665fd4e5da5Sopenharmony_ci            R"(%foo_name %float_info %dbg_src 0 0 %comp_unit %foo_name %void FlagIsProtected|FlagIsPrivate)",
4666fd4e5da5Sopenharmony_ci            "Variable"),
4667fd4e5da5Sopenharmony_ci    }));
4668fd4e5da5Sopenharmony_ci
4669fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugGlobalVariable) {
4670fd4e5da5Sopenharmony_ci  const std::string src = R"(
4671fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
4672fd4e5da5Sopenharmony_ci%code = OpString "float foo; void main() {}"
4673fd4e5da5Sopenharmony_ci%float_name = OpString "float"
4674fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
4675fd4e5da5Sopenharmony_ci)";
4676fd4e5da5Sopenharmony_ci
4677fd4e5da5Sopenharmony_ci  const std::string constants = R"(
4678fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
4679fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
4680fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
4681fd4e5da5Sopenharmony_ci)";
4682fd4e5da5Sopenharmony_ci
4683fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
4684fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
4685fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
4686fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
4687fd4e5da5Sopenharmony_ci%foo = OpExtInst %void %DbgExt DebugGlobalVariable %foo_name %float_info %dbg_src %u32_0 %u32_0 %comp_unit %foo_name %f32_input %u32_3
4688fd4e5da5Sopenharmony_ci)";
4689fd4e5da5Sopenharmony_ci
4690fd4e5da5Sopenharmony_ci  const std::string extension = R"(
4691fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
4692fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
4693fd4e5da5Sopenharmony_ci)";
4694fd4e5da5Sopenharmony_ci
4695fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
4696fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
4697fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4698fd4e5da5Sopenharmony_ci}
4699fd4e5da5Sopenharmony_ci
4700fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugGlobalVariableStaticMember) {
4701fd4e5da5Sopenharmony_ci  const std::string src = R"(
4702fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
4703fd4e5da5Sopenharmony_ci%code = OpString "float foo; void main() {}"
4704fd4e5da5Sopenharmony_ci%float_name = OpString "float"
4705fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
4706fd4e5da5Sopenharmony_ci)";
4707fd4e5da5Sopenharmony_ci
4708fd4e5da5Sopenharmony_ci  const std::string constants = R"(
4709fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
4710fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
4711fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
4712fd4e5da5Sopenharmony_ci)";
4713fd4e5da5Sopenharmony_ci
4714fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
4715fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
4716fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
4717fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
4718fd4e5da5Sopenharmony_ci%a = OpExtInst %void %DbgExt DebugTypeMember %foo_name %float_info %dbg_src %u32_0 %u32_0 %u32_0 %u32_32 %u32_3
4719fd4e5da5Sopenharmony_ci%t = OpExtInst %void %DbgExt DebugTypeComposite %foo_name %u32_1 %dbg_src %u32_0 %u32_0 %comp_unit %foo_name %u32_32 %u32_3 %a
4720fd4e5da5Sopenharmony_ci%foo = OpExtInst %void %DbgExt DebugGlobalVariable %foo_name %t %dbg_src %u32_0 %u32_0 %comp_unit %foo_name %f32_input %u32_3
4721fd4e5da5Sopenharmony_ci)";
4722fd4e5da5Sopenharmony_ci
4723fd4e5da5Sopenharmony_ci  const std::string extension = R"(
4724fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
4725fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
4726fd4e5da5Sopenharmony_ci)";
4727fd4e5da5Sopenharmony_ci
4728fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
4729fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
4730fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4731fd4e5da5Sopenharmony_ci}
4732fd4e5da5Sopenharmony_ci
4733fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugGlobalVariableDebugInfoNone) {
4734fd4e5da5Sopenharmony_ci  const std::string src = R"(
4735fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
4736fd4e5da5Sopenharmony_ci%code = OpString "float foo; void main() {}"
4737fd4e5da5Sopenharmony_ci%float_name = OpString "float"
4738fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
4739fd4e5da5Sopenharmony_ci)";
4740fd4e5da5Sopenharmony_ci
4741fd4e5da5Sopenharmony_ci  const std::string constants = R"(
4742fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
4743fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
4744fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
4745fd4e5da5Sopenharmony_ci)";
4746fd4e5da5Sopenharmony_ci
4747fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
4748fd4e5da5Sopenharmony_ci%dbgNone = OpExtInst %void %DbgExt DebugInfoNone
4749fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
4750fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
4751fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
4752fd4e5da5Sopenharmony_ci%foo = OpExtInst %void %DbgExt DebugGlobalVariable %foo_name %float_info %dbg_src %u32_0 %u32_0 %comp_unit %foo_name %dbgNone %u32_3
4753fd4e5da5Sopenharmony_ci)";
4754fd4e5da5Sopenharmony_ci
4755fd4e5da5Sopenharmony_ci  const std::string extension = R"(
4756fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
4757fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
4758fd4e5da5Sopenharmony_ci)";
4759fd4e5da5Sopenharmony_ci
4760fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
4761fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
4762fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4763fd4e5da5Sopenharmony_ci}
4764fd4e5da5Sopenharmony_ci
4765fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugGlobalVariableConst) {
4766fd4e5da5Sopenharmony_ci  const std::string src = R"(
4767fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
4768fd4e5da5Sopenharmony_ci%code = OpString "float foo; void main() {}"
4769fd4e5da5Sopenharmony_ci%float_name = OpString "float"
4770fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
4771fd4e5da5Sopenharmony_ci)";
4772fd4e5da5Sopenharmony_ci
4773fd4e5da5Sopenharmony_ci  const std::string constants = R"(
4774fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
4775fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
4776fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
4777fd4e5da5Sopenharmony_ci)";
4778fd4e5da5Sopenharmony_ci
4779fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
4780fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
4781fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
4782fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
4783fd4e5da5Sopenharmony_ci%foo = OpExtInst %void %DbgExt DebugGlobalVariable %foo_name %float_info %dbg_src %u32_0 %u32_0 %comp_unit %foo_name %u32_32 %u32_3
4784fd4e5da5Sopenharmony_ci)";
4785fd4e5da5Sopenharmony_ci
4786fd4e5da5Sopenharmony_ci  const std::string extension = R"(
4787fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
4788fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
4789fd4e5da5Sopenharmony_ci)";
4790fd4e5da5Sopenharmony_ci
4791fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
4792fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, "", extension, "Vertex"));
4793fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4794fd4e5da5Sopenharmony_ci}
4795fd4e5da5Sopenharmony_ci
4796fd4e5da5Sopenharmony_ciTEST_P(ValidateVulkan100DebugInfoDebugGlobalVariable, Fail) {
4797fd4e5da5Sopenharmony_ci  const std::string src = R"(
4798fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
4799fd4e5da5Sopenharmony_ci%code = OpString "float foo; void main() {}"
4800fd4e5da5Sopenharmony_ci%float_name = OpString "float"
4801fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
4802fd4e5da5Sopenharmony_ci)";
4803fd4e5da5Sopenharmony_ci
4804fd4e5da5Sopenharmony_ci  const std::string constants = R"(
4805fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
4806fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
4807fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
4808fd4e5da5Sopenharmony_ci)";
4809fd4e5da5Sopenharmony_ci
4810fd4e5da5Sopenharmony_ci  const auto& param = GetParam();
4811fd4e5da5Sopenharmony_ci
4812fd4e5da5Sopenharmony_ci  std::ostringstream ss;
4813fd4e5da5Sopenharmony_ci  ss << R"(
4814fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
4815fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
4816fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
4817fd4e5da5Sopenharmony_ci%foo = OpExtInst %void %DbgExt DebugGlobalVariable )"
4818fd4e5da5Sopenharmony_ci     << param.first;
4819fd4e5da5Sopenharmony_ci
4820fd4e5da5Sopenharmony_ci  const std::string extension = R"(
4821fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
4822fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
4823fd4e5da5Sopenharmony_ci)";
4824fd4e5da5Sopenharmony_ci
4825fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, constants, ss.str(),
4826fd4e5da5Sopenharmony_ci                                                     "", extension, "Vertex"));
4827fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4828fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
4829fd4e5da5Sopenharmony_ci              HasSubstr("expected operand " + param.second));
4830fd4e5da5Sopenharmony_ci}
4831fd4e5da5Sopenharmony_ci
4832fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(
4833fd4e5da5Sopenharmony_ci    AllOpenCL100DebugInfoFail, ValidateVulkan100DebugInfoDebugGlobalVariable,
4834fd4e5da5Sopenharmony_ci    ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
4835fd4e5da5Sopenharmony_ci        std::make_pair(
4836fd4e5da5Sopenharmony_ci            R"(%void %float_info %dbg_src %u32_0 %u32_0 %comp_unit %foo_name %f32_input %u32_3)",
4837fd4e5da5Sopenharmony_ci            "Name"),
4838fd4e5da5Sopenharmony_ci        std::make_pair(
4839fd4e5da5Sopenharmony_ci            R"(%foo_name %dbg_src %dbg_src %u32_0 %u32_0 %comp_unit %foo_name %f32_input %u32_3)",
4840fd4e5da5Sopenharmony_ci            "Type"),
4841fd4e5da5Sopenharmony_ci        std::make_pair(
4842fd4e5da5Sopenharmony_ci            R"(%foo_name %float_info %comp_unit %u32_0 %u32_0 %comp_unit %foo_name %f32_input %u32_3)",
4843fd4e5da5Sopenharmony_ci            "Source"),
4844fd4e5da5Sopenharmony_ci        std::make_pair(
4845fd4e5da5Sopenharmony_ci            R"(%foo_name %float_info %dbg_src %u32_0 %u32_0 %dbg_src %foo_name %f32_input %u32_3)",
4846fd4e5da5Sopenharmony_ci            "Scope"),
4847fd4e5da5Sopenharmony_ci        std::make_pair(
4848fd4e5da5Sopenharmony_ci            R"(%foo_name %float_info %dbg_src %u32_0 %u32_0 %comp_unit %void %f32_input %u32_3)",
4849fd4e5da5Sopenharmony_ci            "Linkage Name"),
4850fd4e5da5Sopenharmony_ci        std::make_pair(
4851fd4e5da5Sopenharmony_ci            R"(%foo_name %float_info %dbg_src %u32_0 %u32_0 %comp_unit %foo_name %void %u32_3)",
4852fd4e5da5Sopenharmony_ci            "Variable"),
4853fd4e5da5Sopenharmony_ci    }));
4854fd4e5da5Sopenharmony_ci
4855fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugInlinedAt) {
4856fd4e5da5Sopenharmony_ci  const std::string src = R"(
4857fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
4858fd4e5da5Sopenharmony_ci%code = OpString "void main() {}"
4859fd4e5da5Sopenharmony_ci%void_name = OpString "void"
4860fd4e5da5Sopenharmony_ci%main_name = OpString "main"
4861fd4e5da5Sopenharmony_ci%main_linkage_name = OpString "v_main"
4862fd4e5da5Sopenharmony_ci)";
4863fd4e5da5Sopenharmony_ci
4864fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
4865fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
4866fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
4867fd4e5da5Sopenharmony_ci%main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void
4868fd4e5da5Sopenharmony_ci%main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 1 1 %comp_unit %main_linkage_name FlagIsPublic 1 %main
4869fd4e5da5Sopenharmony_ci%inlined_at = OpExtInst %void %DbgExt DebugInlinedAt 0 %main_info
4870fd4e5da5Sopenharmony_ci%inlined_at_recursive = OpExtInst %void %DbgExt DebugInlinedAt 0 %main_info %inlined_at
4871fd4e5da5Sopenharmony_ci)";
4872fd4e5da5Sopenharmony_ci
4873fd4e5da5Sopenharmony_ci  const std::string body = R"(
4874fd4e5da5Sopenharmony_ci%main_scope = OpExtInst %void %DbgExt DebugScope %main_info %inlined_at
4875fd4e5da5Sopenharmony_ci)";
4876fd4e5da5Sopenharmony_ci
4877fd4e5da5Sopenharmony_ci  const std::string extension = R"(
4878fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
4879fd4e5da5Sopenharmony_ci)";
4880fd4e5da5Sopenharmony_ci
4881fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
4882fd4e5da5Sopenharmony_ci      src, "", dbg_inst_header, body, extension, "Vertex"));
4883fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4884fd4e5da5Sopenharmony_ci}
4885fd4e5da5Sopenharmony_ci
4886fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugInlinedAtFail) {
4887fd4e5da5Sopenharmony_ci  const std::string src = R"(
4888fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
4889fd4e5da5Sopenharmony_ci%code = OpString "void main() {}"
4890fd4e5da5Sopenharmony_ci%void_name = OpString "void"
4891fd4e5da5Sopenharmony_ci%main_name = OpString "main"
4892fd4e5da5Sopenharmony_ci%main_linkage_name = OpString "v_main"
4893fd4e5da5Sopenharmony_ci)";
4894fd4e5da5Sopenharmony_ci
4895fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
4896fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
4897fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
4898fd4e5da5Sopenharmony_ci%main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void
4899fd4e5da5Sopenharmony_ci%main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 1 1 %comp_unit %main_linkage_name FlagIsPublic 1 %main
4900fd4e5da5Sopenharmony_ci%inlined_at = OpExtInst %void %DbgExt DebugInlinedAt 0 %main_info
4901fd4e5da5Sopenharmony_ci%inlined_at_recursive = OpExtInst %void %DbgExt DebugInlinedAt 0 %inlined_at
4902fd4e5da5Sopenharmony_ci)";
4903fd4e5da5Sopenharmony_ci
4904fd4e5da5Sopenharmony_ci  const std::string body = R"(
4905fd4e5da5Sopenharmony_ci%main_scope = OpExtInst %void %DbgExt DebugScope %main_info %inlined_at
4906fd4e5da5Sopenharmony_ci)";
4907fd4e5da5Sopenharmony_ci
4908fd4e5da5Sopenharmony_ci  const std::string extension = R"(
4909fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
4910fd4e5da5Sopenharmony_ci)";
4911fd4e5da5Sopenharmony_ci
4912fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
4913fd4e5da5Sopenharmony_ci      src, "", dbg_inst_header, body, extension, "Vertex"));
4914fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4915fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(), HasSubstr("expected operand Scope"));
4916fd4e5da5Sopenharmony_ci}
4917fd4e5da5Sopenharmony_ci
4918fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugInlinedAtFail2) {
4919fd4e5da5Sopenharmony_ci  const std::string src = R"(
4920fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
4921fd4e5da5Sopenharmony_ci%code = OpString "void main() {}"
4922fd4e5da5Sopenharmony_ci%void_name = OpString "void"
4923fd4e5da5Sopenharmony_ci%main_name = OpString "main"
4924fd4e5da5Sopenharmony_ci%main_linkage_name = OpString "v_main"
4925fd4e5da5Sopenharmony_ci)";
4926fd4e5da5Sopenharmony_ci
4927fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
4928fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
4929fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
4930fd4e5da5Sopenharmony_ci%main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void
4931fd4e5da5Sopenharmony_ci%main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 1 1 %comp_unit %main_linkage_name FlagIsPublic 1 %main
4932fd4e5da5Sopenharmony_ci%inlined_at = OpExtInst %void %DbgExt DebugInlinedAt 0 %main_info
4933fd4e5da5Sopenharmony_ci%inlined_at_recursive = OpExtInst %void %DbgExt DebugInlinedAt 0 %main_info %main_info
4934fd4e5da5Sopenharmony_ci)";
4935fd4e5da5Sopenharmony_ci
4936fd4e5da5Sopenharmony_ci  const std::string body = R"(
4937fd4e5da5Sopenharmony_ci%main_scope = OpExtInst %void %DbgExt DebugScope %main_info %inlined_at
4938fd4e5da5Sopenharmony_ci)";
4939fd4e5da5Sopenharmony_ci
4940fd4e5da5Sopenharmony_ci  const std::string extension = R"(
4941fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
4942fd4e5da5Sopenharmony_ci)";
4943fd4e5da5Sopenharmony_ci
4944fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
4945fd4e5da5Sopenharmony_ci      src, "", dbg_inst_header, body, extension, "Vertex"));
4946fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4947fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(), HasSubstr("expected operand Inlined"));
4948fd4e5da5Sopenharmony_ci}
4949fd4e5da5Sopenharmony_ci
4950fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugInlinedAt) {
4951fd4e5da5Sopenharmony_ci  const std::string src = R"(
4952fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
4953fd4e5da5Sopenharmony_ci%code = OpString "void main() {}"
4954fd4e5da5Sopenharmony_ci%void_name = OpString "void"
4955fd4e5da5Sopenharmony_ci%main_name = OpString "main"
4956fd4e5da5Sopenharmony_ci%main_linkage_name = OpString "v_main"
4957fd4e5da5Sopenharmony_ci)";
4958fd4e5da5Sopenharmony_ci
4959fd4e5da5Sopenharmony_ci  const std::string constants = R"(
4960fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
4961fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
4962fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
4963fd4e5da5Sopenharmony_ci)";
4964fd4e5da5Sopenharmony_ci
4965fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
4966fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
4967fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
4968fd4e5da5Sopenharmony_ci%main_type_info = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %void
4969fd4e5da5Sopenharmony_ci%main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src %u32_1 %u32_1 %comp_unit %main_name %u32_3 %u32_1
4970fd4e5da5Sopenharmony_ci%inlined_at = OpExtInst %void %DbgExt DebugInlinedAt %u32_0 %main_info
4971fd4e5da5Sopenharmony_ci%inlined_at_recursive = OpExtInst %void %DbgExt DebugInlinedAt %u32_0 %main_info %inlined_at
4972fd4e5da5Sopenharmony_ci)";
4973fd4e5da5Sopenharmony_ci
4974fd4e5da5Sopenharmony_ci  const std::string extension = R"(
4975fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
4976fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
4977fd4e5da5Sopenharmony_ci)";
4978fd4e5da5Sopenharmony_ci
4979fd4e5da5Sopenharmony_ci  const std::string body = R"(
4980fd4e5da5Sopenharmony_ci%main_scope = OpExtInst %void %DbgExt DebugScope %main_info %inlined_at
4981fd4e5da5Sopenharmony_ci)";
4982fd4e5da5Sopenharmony_ci
4983fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
4984fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, body, extension, "Vertex"));
4985fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4986fd4e5da5Sopenharmony_ci}
4987fd4e5da5Sopenharmony_ci
4988fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugInlinedAtFail) {
4989fd4e5da5Sopenharmony_ci  const std::string src = R"(
4990fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
4991fd4e5da5Sopenharmony_ci%code = OpString "void main() {}"
4992fd4e5da5Sopenharmony_ci%void_name = OpString "void"
4993fd4e5da5Sopenharmony_ci%main_name = OpString "main"
4994fd4e5da5Sopenharmony_ci%main_linkage_name = OpString "v_main"
4995fd4e5da5Sopenharmony_ci)";
4996fd4e5da5Sopenharmony_ci
4997fd4e5da5Sopenharmony_ci  const std::string constants = R"(
4998fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
4999fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
5000fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
5001fd4e5da5Sopenharmony_ci)";
5002fd4e5da5Sopenharmony_ci
5003fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
5004fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
5005fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
5006fd4e5da5Sopenharmony_ci%main_type_info = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %void
5007fd4e5da5Sopenharmony_ci%main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src %u32_1 %u32_1 %comp_unit %main_name %u32_3 %u32_1
5008fd4e5da5Sopenharmony_ci%inlined_at = OpExtInst %void %DbgExt DebugInlinedAt %u32_0 %main_info
5009fd4e5da5Sopenharmony_ci%inlined_at_recursive = OpExtInst %void %DbgExt DebugInlinedAt %u32_0 %inlined_at %inlined_at
5010fd4e5da5Sopenharmony_ci)";
5011fd4e5da5Sopenharmony_ci
5012fd4e5da5Sopenharmony_ci  const std::string extension = R"(
5013fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
5014fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
5015fd4e5da5Sopenharmony_ci)";
5016fd4e5da5Sopenharmony_ci
5017fd4e5da5Sopenharmony_ci  const std::string body = R"(
5018fd4e5da5Sopenharmony_ci%main_scope = OpExtInst %void %DbgExt DebugScope %main_info %inlined_at
5019fd4e5da5Sopenharmony_ci)";
5020fd4e5da5Sopenharmony_ci
5021fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
5022fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, body, extension, "Vertex"));
5023fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5024fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(), HasSubstr("expected operand Scope"));
5025fd4e5da5Sopenharmony_ci}
5026fd4e5da5Sopenharmony_ci
5027fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugInlinedAtFail2) {
5028fd4e5da5Sopenharmony_ci  const std::string src = R"(
5029fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
5030fd4e5da5Sopenharmony_ci%code = OpString "void main() {}"
5031fd4e5da5Sopenharmony_ci%void_name = OpString "void"
5032fd4e5da5Sopenharmony_ci%main_name = OpString "main"
5033fd4e5da5Sopenharmony_ci%main_linkage_name = OpString "v_main"
5034fd4e5da5Sopenharmony_ci)";
5035fd4e5da5Sopenharmony_ci
5036fd4e5da5Sopenharmony_ci  const std::string constants = R"(
5037fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
5038fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
5039fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
5040fd4e5da5Sopenharmony_ci)";
5041fd4e5da5Sopenharmony_ci
5042fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
5043fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
5044fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
5045fd4e5da5Sopenharmony_ci%main_type_info = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %void
5046fd4e5da5Sopenharmony_ci%main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src %u32_1 %u32_1 %comp_unit %main_name %u32_3 %u32_1
5047fd4e5da5Sopenharmony_ci%inlined_at = OpExtInst %void %DbgExt DebugInlinedAt %u32_0 %main_info
5048fd4e5da5Sopenharmony_ci%inlined_at_recursive = OpExtInst %void %DbgExt DebugInlinedAt %u32_0 %main_info %main_info
5049fd4e5da5Sopenharmony_ci)";
5050fd4e5da5Sopenharmony_ci
5051fd4e5da5Sopenharmony_ci  const std::string extension = R"(
5052fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
5053fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
5054fd4e5da5Sopenharmony_ci)";
5055fd4e5da5Sopenharmony_ci
5056fd4e5da5Sopenharmony_ci  const std::string body = R"(
5057fd4e5da5Sopenharmony_ci%main_scope = OpExtInst %void %DbgExt DebugScope %main_info %inlined_at
5058fd4e5da5Sopenharmony_ci)";
5059fd4e5da5Sopenharmony_ci
5060fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
5061fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, body, extension, "Vertex"));
5062fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5063fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(), HasSubstr("expected operand Inlined"));
5064fd4e5da5Sopenharmony_ci}
5065fd4e5da5Sopenharmony_ci
5066fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugValue) {
5067fd4e5da5Sopenharmony_ci  const std::string src = R"(
5068fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
5069fd4e5da5Sopenharmony_ci%code = OpString "void main() { float foo; }"
5070fd4e5da5Sopenharmony_ci%float_name = OpString "float"
5071fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
5072fd4e5da5Sopenharmony_ci)";
5073fd4e5da5Sopenharmony_ci
5074fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
5075fd4e5da5Sopenharmony_ci%int_3 = OpConstant %u32 3
5076fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
5077fd4e5da5Sopenharmony_ci)";
5078fd4e5da5Sopenharmony_ci
5079fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
5080fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
5081fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
5082fd4e5da5Sopenharmony_ci%null_expr = OpExtInst %void %DbgExt DebugExpression
5083fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
5084fd4e5da5Sopenharmony_ci%v4float_info = OpExtInst %void %DbgExt DebugTypeVector %float_info 4
5085fd4e5da5Sopenharmony_ci%foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %v4float_info %dbg_src 1 10 %comp_unit FlagIsLocal 0
5086fd4e5da5Sopenharmony_ci)";
5087fd4e5da5Sopenharmony_ci
5088fd4e5da5Sopenharmony_ci  const std::string body = R"(
5089fd4e5da5Sopenharmony_ci%value = OpExtInst %void %DbgExt DebugValue %foo_info %int_32 %null_expr %int_3
5090fd4e5da5Sopenharmony_ci)";
5091fd4e5da5Sopenharmony_ci
5092fd4e5da5Sopenharmony_ci  const std::string extension = R"(
5093fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
5094fd4e5da5Sopenharmony_ci)";
5095fd4e5da5Sopenharmony_ci
5096fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
5097fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, body, extension, "Vertex"));
5098fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
5099fd4e5da5Sopenharmony_ci}
5100fd4e5da5Sopenharmony_ci
5101fd4e5da5Sopenharmony_ciTEST_F(ValidateOpenCL100DebugInfo, DebugValueWithVariableIndex) {
5102fd4e5da5Sopenharmony_ci  const std::string src = R"(
5103fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
5104fd4e5da5Sopenharmony_ci%code = OpString "void main() { float foo; }"
5105fd4e5da5Sopenharmony_ci%float_name = OpString "float"
5106fd4e5da5Sopenharmony_ci%int_name = OpString "int"
5107fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
5108fd4e5da5Sopenharmony_ci%len_name = OpString "length"
5109fd4e5da5Sopenharmony_ci)";
5110fd4e5da5Sopenharmony_ci
5111fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
5112fd4e5da5Sopenharmony_ci%int_3 = OpConstant %u32 3
5113fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
5114fd4e5da5Sopenharmony_ci)";
5115fd4e5da5Sopenharmony_ci
5116fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
5117fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
5118fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
5119fd4e5da5Sopenharmony_ci%null_expr = OpExtInst %void %DbgExt DebugExpression
5120fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
5121fd4e5da5Sopenharmony_ci%int_info = OpExtInst %void %DbgExt DebugTypeBasic %int_name %int_32 Signed
5122fd4e5da5Sopenharmony_ci%v4float_info = OpExtInst %void %DbgExt DebugTypeVector %float_info 4
5123fd4e5da5Sopenharmony_ci%foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %v4float_info %dbg_src 1 10 %comp_unit FlagIsLocal
5124fd4e5da5Sopenharmony_ci%len_info = OpExtInst %void %DbgExt DebugLocalVariable %len_name %int_info %dbg_src 0 0 %comp_unit FlagIsLocal
5125fd4e5da5Sopenharmony_ci)";
5126fd4e5da5Sopenharmony_ci
5127fd4e5da5Sopenharmony_ci  const std::string body = R"(
5128fd4e5da5Sopenharmony_ci%value = OpExtInst %void %DbgExt DebugValue %foo_info %int_32 %null_expr %len_info
5129fd4e5da5Sopenharmony_ci)";
5130fd4e5da5Sopenharmony_ci
5131fd4e5da5Sopenharmony_ci  const std::string extension = R"(
5132fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
5133fd4e5da5Sopenharmony_ci)";
5134fd4e5da5Sopenharmony_ci
5135fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
5136fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, body, extension, "Vertex"));
5137fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
5138fd4e5da5Sopenharmony_ci}
5139fd4e5da5Sopenharmony_ci
5140fd4e5da5Sopenharmony_ciTEST_P(ValidateOpenCL100DebugInfoDebugValue, Fail) {
5141fd4e5da5Sopenharmony_ci  const std::string src = R"(
5142fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
5143fd4e5da5Sopenharmony_ci%code = OpString "void main() { float foo; }"
5144fd4e5da5Sopenharmony_ci%float_name = OpString "float"
5145fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
5146fd4e5da5Sopenharmony_ci)";
5147fd4e5da5Sopenharmony_ci
5148fd4e5da5Sopenharmony_ci  const std::string size_const = R"(
5149fd4e5da5Sopenharmony_ci%int_32 = OpConstant %u32 32
5150fd4e5da5Sopenharmony_ci)";
5151fd4e5da5Sopenharmony_ci
5152fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
5153fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
5154fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
5155fd4e5da5Sopenharmony_ci%null_expr = OpExtInst %void %DbgExt DebugExpression
5156fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
5157fd4e5da5Sopenharmony_ci%foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %float_info %dbg_src 1 10 %comp_unit FlagIsLocal 0
5158fd4e5da5Sopenharmony_ci)";
5159fd4e5da5Sopenharmony_ci
5160fd4e5da5Sopenharmony_ci  const auto& param = GetParam();
5161fd4e5da5Sopenharmony_ci
5162fd4e5da5Sopenharmony_ci  std::ostringstream ss;
5163fd4e5da5Sopenharmony_ci  ss << R"(
5164fd4e5da5Sopenharmony_ci%decl = OpExtInst %void %DbgExt DebugValue )"
5165fd4e5da5Sopenharmony_ci     << param.first;
5166fd4e5da5Sopenharmony_ci
5167fd4e5da5Sopenharmony_ci  const std::string extension = R"(
5168fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
5169fd4e5da5Sopenharmony_ci)";
5170fd4e5da5Sopenharmony_ci
5171fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
5172fd4e5da5Sopenharmony_ci      src, size_const, dbg_inst_header, ss.str(), extension, "Vertex"));
5173fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5174fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
5175fd4e5da5Sopenharmony_ci              HasSubstr("expected operand " + param.second));
5176fd4e5da5Sopenharmony_ci}
5177fd4e5da5Sopenharmony_ci
5178fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(
5179fd4e5da5Sopenharmony_ci    AllOpenCL100DebugInfoFail, ValidateOpenCL100DebugInfoDebugValue,
5180fd4e5da5Sopenharmony_ci    ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
5181fd4e5da5Sopenharmony_ci        std::make_pair(R"(%dbg_src %int_32 %null_expr)", "Local Variable"),
5182fd4e5da5Sopenharmony_ci        std::make_pair(R"(%foo_info %int_32 %dbg_src)", "Expression"),
5183fd4e5da5Sopenharmony_ci        std::make_pair(R"(%foo_info %int_32 %null_expr %dbg_src)", "Indexes"),
5184fd4e5da5Sopenharmony_ci    }));
5185fd4e5da5Sopenharmony_ci
5186fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugValue) {
5187fd4e5da5Sopenharmony_ci  const std::string src = R"(
5188fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
5189fd4e5da5Sopenharmony_ci%code = OpString "void main() { float foo; }"
5190fd4e5da5Sopenharmony_ci%float_name = OpString "float"
5191fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
5192fd4e5da5Sopenharmony_ci)";
5193fd4e5da5Sopenharmony_ci
5194fd4e5da5Sopenharmony_ci  const std::string constants = R"(
5195fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
5196fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
5197fd4e5da5Sopenharmony_ci%u32_10 = OpConstant %u32 10
5198fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
5199fd4e5da5Sopenharmony_ci)";
5200fd4e5da5Sopenharmony_ci
5201fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
5202fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
5203fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
5204fd4e5da5Sopenharmony_ci%null_expr = OpExtInst %void %DbgExt DebugExpression
5205fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
5206fd4e5da5Sopenharmony_ci%v4float_info = OpExtInst %void %DbgExt DebugTypeVector %float_info %u32_4
5207fd4e5da5Sopenharmony_ci%foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %v4float_info %dbg_src %u32_1 %u32_10 %comp_unit %u32_4
5208fd4e5da5Sopenharmony_ci)";
5209fd4e5da5Sopenharmony_ci
5210fd4e5da5Sopenharmony_ci  const std::string extension = R"(
5211fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
5212fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
5213fd4e5da5Sopenharmony_ci)";
5214fd4e5da5Sopenharmony_ci
5215fd4e5da5Sopenharmony_ci  const std::string body = R"(
5216fd4e5da5Sopenharmony_ci%value = OpExtInst %void %DbgExt DebugValue %foo_info %u32_32 %null_expr %u32_3
5217fd4e5da5Sopenharmony_ci)";
5218fd4e5da5Sopenharmony_ci
5219fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
5220fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, body, extension, "Vertex"));
5221fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
5222fd4e5da5Sopenharmony_ci}
5223fd4e5da5Sopenharmony_ci
5224fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, DebugValueWithVariableIndex) {
5225fd4e5da5Sopenharmony_ci  const std::string src = R"(
5226fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
5227fd4e5da5Sopenharmony_ci%code = OpString "void main() { float foo; }"
5228fd4e5da5Sopenharmony_ci%float_name = OpString "float"
5229fd4e5da5Sopenharmony_ci%int_name = OpString "int"
5230fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
5231fd4e5da5Sopenharmony_ci%len_name = OpString "length"
5232fd4e5da5Sopenharmony_ci)";
5233fd4e5da5Sopenharmony_ci
5234fd4e5da5Sopenharmony_ci  const std::string constants = R"(
5235fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
5236fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
5237fd4e5da5Sopenharmony_ci%u32_10 = OpConstant %u32 10
5238fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
5239fd4e5da5Sopenharmony_ci)";
5240fd4e5da5Sopenharmony_ci
5241fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
5242fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
5243fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
5244fd4e5da5Sopenharmony_ci%null_expr = OpExtInst %void %DbgExt DebugExpression
5245fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
5246fd4e5da5Sopenharmony_ci%int_info = OpExtInst %void %DbgExt DebugTypeBasic %int_name %u32_32 %u32_4 %u32_0
5247fd4e5da5Sopenharmony_ci%v4float_info = OpExtInst %void %DbgExt DebugTypeVector %float_info %u32_4
5248fd4e5da5Sopenharmony_ci%foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %v4float_info %dbg_src %u32_1 %u32_10 %comp_unit %u32_4 %u32_0
5249fd4e5da5Sopenharmony_ci%len_info = OpExtInst %void %DbgExt DebugLocalVariable %len_name %int_info %dbg_src %u32_0 %u32_0 %comp_unit %u32_4
5250fd4e5da5Sopenharmony_ci)";
5251fd4e5da5Sopenharmony_ci
5252fd4e5da5Sopenharmony_ci  const std::string extension = R"(
5253fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
5254fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
5255fd4e5da5Sopenharmony_ci)";
5256fd4e5da5Sopenharmony_ci
5257fd4e5da5Sopenharmony_ci  const std::string body = R"(
5258fd4e5da5Sopenharmony_ci%value = OpExtInst %void %DbgExt DebugValue %foo_info %u32_32 %null_expr %len_info
5259fd4e5da5Sopenharmony_ci)";
5260fd4e5da5Sopenharmony_ci
5261fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
5262fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, body, extension, "Vertex"));
5263fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
5264fd4e5da5Sopenharmony_ci}
5265fd4e5da5Sopenharmony_ci
5266fd4e5da5Sopenharmony_ciTEST_P(ValidateVulkan100DebugInfoDebugValue, Fail) {
5267fd4e5da5Sopenharmony_ci  const std::string src = R"(
5268fd4e5da5Sopenharmony_ci%src = OpString "simple.hlsl"
5269fd4e5da5Sopenharmony_ci%code = OpString "void main() { float foo; }"
5270fd4e5da5Sopenharmony_ci%float_name = OpString "float"
5271fd4e5da5Sopenharmony_ci%foo_name = OpString "foo"
5272fd4e5da5Sopenharmony_ci)";
5273fd4e5da5Sopenharmony_ci
5274fd4e5da5Sopenharmony_ci  const std::string constants = R"(
5275fd4e5da5Sopenharmony_ci%u32_4 = OpConstant %u32 4
5276fd4e5da5Sopenharmony_ci%u32_5 = OpConstant %u32 5
5277fd4e5da5Sopenharmony_ci%u32_10 = OpConstant %u32 10
5278fd4e5da5Sopenharmony_ci%u32_32 = OpConstant %u32 32
5279fd4e5da5Sopenharmony_ci)";
5280fd4e5da5Sopenharmony_ci
5281fd4e5da5Sopenharmony_ci  const std::string dbg_inst_header = R"(
5282fd4e5da5Sopenharmony_ci%dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
5283fd4e5da5Sopenharmony_ci%comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
5284fd4e5da5Sopenharmony_ci%null_expr = OpExtInst %void %DbgExt DebugExpression
5285fd4e5da5Sopenharmony_ci%float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
5286fd4e5da5Sopenharmony_ci%v4float_info = OpExtInst %void %DbgExt DebugTypeVector %float_info %u32_4
5287fd4e5da5Sopenharmony_ci%foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %v4float_info %dbg_src %u32_1 %u32_10 %comp_unit %u32_4 %u32_0
5288fd4e5da5Sopenharmony_ci)";
5289fd4e5da5Sopenharmony_ci
5290fd4e5da5Sopenharmony_ci  const std::string extension = R"(
5291fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
5292fd4e5da5Sopenharmony_ci%DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
5293fd4e5da5Sopenharmony_ci)";
5294fd4e5da5Sopenharmony_ci
5295fd4e5da5Sopenharmony_ci  const auto& param = GetParam();
5296fd4e5da5Sopenharmony_ci
5297fd4e5da5Sopenharmony_ci  std::ostringstream ss;
5298fd4e5da5Sopenharmony_ci  ss << R"(
5299fd4e5da5Sopenharmony_ci%decl = OpExtInst %void %DbgExt DebugValue )"
5300fd4e5da5Sopenharmony_ci     << param.first;
5301fd4e5da5Sopenharmony_ci
5302fd4e5da5Sopenharmony_ci  CompileSuccessfully(GenerateShaderCodeForDebugInfo(
5303fd4e5da5Sopenharmony_ci      src, constants, dbg_inst_header, ss.str(), extension, "Vertex"));
5304fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5305fd4e5da5Sopenharmony_ci  EXPECT_THAT(getDiagnosticString(),
5306fd4e5da5Sopenharmony_ci              HasSubstr("expected operand " + param.second));
5307fd4e5da5Sopenharmony_ci}
5308fd4e5da5Sopenharmony_ci
5309fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(
5310fd4e5da5Sopenharmony_ci    AllOpenCL100DebugInfoFail, ValidateVulkan100DebugInfoDebugValue,
5311fd4e5da5Sopenharmony_ci    ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
5312fd4e5da5Sopenharmony_ci        std::make_pair(R"(%dbg_src %u32_32 %null_expr %u32_3)",
5313fd4e5da5Sopenharmony_ci                       "Local Variable"),
5314fd4e5da5Sopenharmony_ci        std::make_pair(R"(%foo_info %u32_32 %dbg_src %u32_3)", "Expression"),
5315fd4e5da5Sopenharmony_ci        std::make_pair(R"(%foo_info %u32_32 %null_expr %dbg_src)", "Indexes"),
5316fd4e5da5Sopenharmony_ci    }));
5317fd4e5da5Sopenharmony_ci
5318fd4e5da5Sopenharmony_ciTEST_F(ValidateVulkan100DebugInfo, VulkanDebugInfoSample) {
5319fd4e5da5Sopenharmony_ci  std::ostringstream ss;
5320fd4e5da5Sopenharmony_ci  ss << R"(
5321fd4e5da5Sopenharmony_ci               OpCapability Shader
5322fd4e5da5Sopenharmony_ci               OpExtension "SPV_KHR_non_semantic_info"
5323fd4e5da5Sopenharmony_ci          %id_1 = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
5324fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
5325fd4e5da5Sopenharmony_ci               OpEntryPoint Fragment %id_MainPs "MainPs" %id_in_var_TEXCOORD2 %id_out_var_SV_Target0
5326fd4e5da5Sopenharmony_ci               OpExecutionMode %id_MainPs OriginUpperLeft
5327fd4e5da5Sopenharmony_ci          %id_7 = OpString "foo.frag"
5328fd4e5da5Sopenharmony_ci         %id_27 = OpString "float"
5329fd4e5da5Sopenharmony_ci         %id_32 = OpString "vColor"
5330fd4e5da5Sopenharmony_ci         %id_36 = OpString "PS_OUTPUT"
5331fd4e5da5Sopenharmony_ci         %id_42 = OpString "vTextureCoords"
5332fd4e5da5Sopenharmony_ci         %id_46 = OpString "PS_INPUT"
5333fd4e5da5Sopenharmony_ci         %id_49 = OpString "MainPs"
5334fd4e5da5Sopenharmony_ci         %id_50 = OpString ""
5335fd4e5da5Sopenharmony_ci         %id_55 = OpString "ps_output"
5336fd4e5da5Sopenharmony_ci         %id_59 = OpString "i"
5337fd4e5da5Sopenharmony_ci         %id_63 = OpString "@type.sampler"
5338fd4e5da5Sopenharmony_ci         %id_64 = OpString "type.sampler"
5339fd4e5da5Sopenharmony_ci         %id_66 = OpString "g_sAniso"
5340fd4e5da5Sopenharmony_ci         %id_69 = OpString "@type.2d.image"
5341fd4e5da5Sopenharmony_ci         %id_70 = OpString "type.2d.image"
5342fd4e5da5Sopenharmony_ci         %id_72 = OpString "TemplateParam"
5343fd4e5da5Sopenharmony_ci         %id_75 = OpString "g_tColor"
5344fd4e5da5Sopenharmony_ci               OpName %id_type_2d_image "type.2d.image"
5345fd4e5da5Sopenharmony_ci               OpName %id_g_tColor "g_tColor"
5346fd4e5da5Sopenharmony_ci               OpName %id_type_sampler "type.sampler"
5347fd4e5da5Sopenharmony_ci               OpName %id_g_sAniso "g_sAniso"
5348fd4e5da5Sopenharmony_ci               OpName %id_in_var_TEXCOORD2 "in.var.TEXCOORD2"
5349fd4e5da5Sopenharmony_ci               OpName %id_out_var_SV_Target0 "out.var.SV_Target0"
5350fd4e5da5Sopenharmony_ci               OpName %id_MainPs "MainPs"
5351fd4e5da5Sopenharmony_ci               OpName %id_PS_INPUT "PS_INPUT"
5352fd4e5da5Sopenharmony_ci               OpMemberName %id_PS_INPUT 0 "vTextureCoords"
5353fd4e5da5Sopenharmony_ci               OpName %id_param_var_i "param.var.i"
5354fd4e5da5Sopenharmony_ci               OpName %id_PS_OUTPUT "PS_OUTPUT"
5355fd4e5da5Sopenharmony_ci               OpMemberName %id_PS_OUTPUT 0 "vColor"
5356fd4e5da5Sopenharmony_ci               OpName %id_src_MainPs "src.MainPs"
5357fd4e5da5Sopenharmony_ci               OpName %id_i "i"
5358fd4e5da5Sopenharmony_ci               OpName %id_bb_entry "bb.entry"
5359fd4e5da5Sopenharmony_ci               OpName %id_ps_output "ps_output"
5360fd4e5da5Sopenharmony_ci               OpName %id_type_sampled_image "type.sampled.image"
5361fd4e5da5Sopenharmony_ci               OpDecorate %id_in_var_TEXCOORD2 Location 0
5362fd4e5da5Sopenharmony_ci               OpDecorate %id_out_var_SV_Target0 Location 0
5363fd4e5da5Sopenharmony_ci               OpDecorate %id_g_tColor DescriptorSet 0
5364fd4e5da5Sopenharmony_ci               OpDecorate %id_g_tColor Binding 0
5365fd4e5da5Sopenharmony_ci               OpDecorate %id_g_sAniso DescriptorSet 0
5366fd4e5da5Sopenharmony_ci               OpDecorate %id_g_sAniso Binding 1
5367fd4e5da5Sopenharmony_ci        %id_int = OpTypeInt 32 1
5368fd4e5da5Sopenharmony_ci      %id_int_0 = OpConstant %id_int 0
5369fd4e5da5Sopenharmony_ci       %id_uint = OpTypeInt 32 0
5370fd4e5da5Sopenharmony_ci    %id_uint_32 = OpConstant %id_uint 32
5371fd4e5da5Sopenharmony_ci      %id_float = OpTypeFloat 32
5372fd4e5da5Sopenharmony_ci%id_type_2d_image = OpTypeImage %id_float 2D 2 0 0 1 Unknown
5373fd4e5da5Sopenharmony_ci%id__ptr_UniformConstant_type_2d_image = OpTypePointer UniformConstant %id_type_2d_image
5374fd4e5da5Sopenharmony_ci%id_type_sampler = OpTypeSampler
5375fd4e5da5Sopenharmony_ci%id__ptr_UniformConstant_type_sampler = OpTypePointer UniformConstant %id_type_sampler
5376fd4e5da5Sopenharmony_ci    %id_v2float = OpTypeVector %id_float 2
5377fd4e5da5Sopenharmony_ci%id__ptr_Input_v2float = OpTypePointer Input %id_v2float
5378fd4e5da5Sopenharmony_ci    %id_v4float = OpTypeVector %id_float 4
5379fd4e5da5Sopenharmony_ci%id__ptr_Output_v4float = OpTypePointer Output %id_v4float
5380fd4e5da5Sopenharmony_ci       %id_void = OpTypeVoid
5381fd4e5da5Sopenharmony_ci     %id_uint_1 = OpConstant %id_uint 1
5382fd4e5da5Sopenharmony_ci     %id_uint_4 = OpConstant %id_uint 4
5383fd4e5da5Sopenharmony_ci     %id_uint_5 = OpConstant %id_uint 5
5384fd4e5da5Sopenharmony_ci     %id_uint_3 = OpConstant %id_uint 3
5385fd4e5da5Sopenharmony_ci     %id_uint_0 = OpConstant %id_uint 0
5386fd4e5da5Sopenharmony_ci   %id_uint_128 = OpConstant %id_uint 128
5387fd4e5da5Sopenharmony_ci    %id_uint_12 = OpConstant %id_uint 12
5388fd4e5da5Sopenharmony_ci    %id_uint_10 = OpConstant %id_uint 10
5389fd4e5da5Sopenharmony_ci     %id_uint_8 = OpConstant %id_uint 8
5390fd4e5da5Sopenharmony_ci     %id_uint_2 = OpConstant %id_uint 2
5391fd4e5da5Sopenharmony_ci    %id_uint_64 = OpConstant %id_uint 64
5392fd4e5da5Sopenharmony_ci     %id_uint_7 = OpConstant %id_uint 7
5393fd4e5da5Sopenharmony_ci    %id_uint_15 = OpConstant %id_uint 15
5394fd4e5da5Sopenharmony_ci    %id_uint_16 = OpConstant %id_uint 16
5395fd4e5da5Sopenharmony_ci    %id_uint_17 = OpConstant %id_uint 17
5396fd4e5da5Sopenharmony_ci    %id_uint_29 = OpConstant %id_uint 29
5397fd4e5da5Sopenharmony_ci    %id_uint_14 = OpConstant %id_uint 14
5398fd4e5da5Sopenharmony_ci    %id_uint_11 = OpConstant %id_uint 11
5399fd4e5da5Sopenharmony_ci         %id_78 = OpTypeFunction %id_void
5400fd4e5da5Sopenharmony_ci   %id_PS_INPUT = OpTypeStruct %id_v2float
5401fd4e5da5Sopenharmony_ci%id__ptr_Function_PS_INPUT = OpTypePointer Function %id_PS_INPUT
5402fd4e5da5Sopenharmony_ci  %id_PS_OUTPUT = OpTypeStruct %id_v4float
5403fd4e5da5Sopenharmony_ci         %id_89 = OpTypeFunction %id_PS_OUTPUT %id__ptr_Function_PS_INPUT
5404fd4e5da5Sopenharmony_ci%id__ptr_Function_PS_OUTPUT = OpTypePointer Function %id_PS_OUTPUT
5405fd4e5da5Sopenharmony_ci    %id_uint_20 = OpConstant %id_uint 20
5406fd4e5da5Sopenharmony_ci    %id_uint_19 = OpConstant %id_uint 19
5407fd4e5da5Sopenharmony_ci    %id_uint_26 = OpConstant %id_uint 26
5408fd4e5da5Sopenharmony_ci    %id_uint_46 = OpConstant %id_uint 46
5409fd4e5da5Sopenharmony_ci%id__ptr_Function_v2float = OpTypePointer Function %id_v2float
5410fd4e5da5Sopenharmony_ci    %id_uint_57 = OpConstant %id_uint 57
5411fd4e5da5Sopenharmony_ci    %id_uint_78 = OpConstant %id_uint 78
5412fd4e5da5Sopenharmony_ci%id_type_sampled_image = OpTypeSampledImage %id_type_2d_image
5413fd4e5da5Sopenharmony_ci    %id_uint_81 = OpConstant %id_uint 81
5414fd4e5da5Sopenharmony_ci%id__ptr_Function_v4float = OpTypePointer Function %id_v4float
5415fd4e5da5Sopenharmony_ci   %id_g_tColor = OpVariable %id__ptr_UniformConstant_type_2d_image UniformConstant
5416fd4e5da5Sopenharmony_ci   %id_g_sAniso = OpVariable %id__ptr_UniformConstant_type_sampler UniformConstant
5417fd4e5da5Sopenharmony_ci%id_in_var_TEXCOORD2 = OpVariable %id__ptr_Input_v2float Input
5418fd4e5da5Sopenharmony_ci%id_out_var_SV_Target0 = OpVariable %id__ptr_Output_v4float Output
5419fd4e5da5Sopenharmony_ci         %id_22 = OpExtInst %id_void %id_1 DebugSource %id_7
5420fd4e5da5Sopenharmony_ci         %id_23 = OpExtInst %id_void %id_1 DebugCompilationUnit %id_uint_1 %id_uint_4 %id_22 %id_uint_5
5421fd4e5da5Sopenharmony_ci         %id_28 = OpExtInst %id_void %id_1 DebugTypeBasic %id_27 %id_uint_32 %id_uint_3 %id_uint_0
5422fd4e5da5Sopenharmony_ci         %id_31 = OpExtInst %id_void %id_1 DebugTypeVector %id_28 %id_uint_4
5423fd4e5da5Sopenharmony_ci         %id_34 = OpExtInst %id_void %id_1 DebugTypeMember %id_32 %id_31 %id_22 %id_uint_12 %id_uint_12 %id_uint_0 %id_uint_128 %id_uint_3
5424fd4e5da5Sopenharmony_ci         %id_37 = OpExtInst %id_void %id_1 DebugTypeComposite %id_36 %id_uint_1 %id_22 %id_uint_10 %id_uint_8 %id_23 %id_36 %id_uint_128 %id_uint_3 %id_34
5425fd4e5da5Sopenharmony_ci         %id_40 = OpExtInst %id_void %id_1 DebugTypeVector %id_28 %id_uint_2
5426fd4e5da5Sopenharmony_ci         %id_44 = OpExtInst %id_void %id_1 DebugTypeMember %id_42 %id_40 %id_22 %id_uint_7 %id_uint_12 %id_uint_0 %id_uint_64 %id_uint_3
5427fd4e5da5Sopenharmony_ci         %id_47 = OpExtInst %id_void %id_1 DebugTypeComposite %id_46 %id_uint_1 %id_22 %id_uint_5 %id_uint_8 %id_23 %id_46 %id_uint_64 %id_uint_3 %id_44
5428fd4e5da5Sopenharmony_ci         %id_48 = OpExtInst %id_void %id_1 DebugTypeFunction %id_uint_3 %id_37 %id_47
5429fd4e5da5Sopenharmony_ci         %id_51 = OpExtInst %id_void %id_1 DebugFunction %id_49 %id_48 %id_22 %id_uint_15 %id_uint_1 %id_23 %id_50 %id_uint_3 %id_uint_16
5430fd4e5da5Sopenharmony_ci         %id_54 = OpExtInst %id_void %id_1 DebugLexicalBlock %id_22 %id_uint_16 %id_uint_1 %id_51
5431fd4e5da5Sopenharmony_ci         %id_56 = OpExtInst %id_void %id_1 DebugLocalVariable %id_55 %id_37 %id_22 %id_uint_17 %id_uint_15 %id_54 %id_uint_4
5432fd4e5da5Sopenharmony_ci         %id_58 = OpExtInst %id_void %id_1 DebugExpression
5433fd4e5da5Sopenharmony_ci         %id_60 = OpExtInst %id_void %id_1 DebugLocalVariable %id_59 %id_47 %id_22 %id_uint_15 %id_uint_29 %id_51 %id_uint_4 %id_uint_1
5434fd4e5da5Sopenharmony_ci         %id_62 = OpExtInst %id_void %id_1 DebugInfoNone
5435fd4e5da5Sopenharmony_ci         %id_65 = OpExtInst %id_void %id_1 DebugTypeComposite %id_63 %id_uint_1 %id_22 %id_uint_0 %id_uint_0 %id_23 %id_64 %id_62 %id_uint_3
5436fd4e5da5Sopenharmony_ci         %id_67 = OpExtInst %id_void %id_1 DebugGlobalVariable %id_66 %id_65 %id_22 %id_uint_3 %id_uint_14 %id_23 %id_66 %id_g_sAniso %id_uint_8
5437fd4e5da5Sopenharmony_ci         %id_71 = OpExtInst %id_void %id_1 DebugTypeComposite %id_69 %id_uint_0 %id_22 %id_uint_0 %id_uint_0 %id_23 %id_70 %id_62 %id_uint_3
5438fd4e5da5Sopenharmony_ci         %id_73 = OpExtInst %id_void %id_1 DebugTypeTemplateParameter %id_72 %id_31 %id_62 %id_22 %id_uint_0 %id_uint_0
5439fd4e5da5Sopenharmony_ci         %id_74 = OpExtInst %id_void %id_1 DebugTypeTemplate %id_71 %id_73
5440fd4e5da5Sopenharmony_ci         %id_76 = OpExtInst %id_void %id_1 DebugGlobalVariable %id_75 %id_74 %id_22 %id_uint_1 %id_uint_11 %id_23 %id_75 %id_g_tColor %id_uint_8
5441fd4e5da5Sopenharmony_ci     %id_MainPs = OpFunction %id_void None %id_78
5442fd4e5da5Sopenharmony_ci         %id_79 = OpLabel
5443fd4e5da5Sopenharmony_ci%id_param_var_i = OpVariable %id__ptr_Function_PS_INPUT Function
5444fd4e5da5Sopenharmony_ci         %id_83 = OpLoad %id_v2float %id_in_var_TEXCOORD2
5445fd4e5da5Sopenharmony_ci         %id_84 = OpCompositeConstruct %id_PS_INPUT %id_83
5446fd4e5da5Sopenharmony_ci               OpStore %id_param_var_i %id_84
5447fd4e5da5Sopenharmony_ci         %id_86 = OpFunctionCall %id_PS_OUTPUT %id_src_MainPs %id_param_var_i
5448fd4e5da5Sopenharmony_ci         %id_88 = OpCompositeExtract %id_v4float %id_86 0
5449fd4e5da5Sopenharmony_ci               OpStore %id_out_var_SV_Target0 %id_88
5450fd4e5da5Sopenharmony_ci               OpReturn
5451fd4e5da5Sopenharmony_ci               OpFunctionEnd
5452fd4e5da5Sopenharmony_ci %id_src_MainPs = OpFunction %id_PS_OUTPUT None %id_89
5453fd4e5da5Sopenharmony_ci          %id_i = OpFunctionParameter %id__ptr_Function_PS_INPUT
5454fd4e5da5Sopenharmony_ci   %id_bb_entry = OpLabel
5455fd4e5da5Sopenharmony_ci  %id_ps_output = OpVariable %id__ptr_Function_PS_OUTPUT Function
5456fd4e5da5Sopenharmony_ci         %id_94 = OpExtInst %id_void %id_1 DebugScope %id_51
5457fd4e5da5Sopenharmony_ci         %id_97 = OpExtInst %id_void %id_1 DebugDeclare %id_60 %id_i %id_58
5458fd4e5da5Sopenharmony_ci         %id_99 = OpExtInst %id_void %id_1 DebugFunctionDefinition %id_51 %id_src_MainPs
5459fd4e5da5Sopenharmony_ci        %id_100 = OpExtInst %id_void %id_1 DebugScope %id_54
5460fd4e5da5Sopenharmony_ci        %id_102 = OpExtInst %id_void %id_1 DebugDeclare %id_56 %id_ps_output %id_58
5461fd4e5da5Sopenharmony_ci        %id_106 = OpLoad %id_type_2d_image %id_g_tColor
5462fd4e5da5Sopenharmony_ci        %id_109 = OpLoad %id_type_sampler %id_g_sAniso
5463fd4e5da5Sopenharmony_ci        %id_114 = OpAccessChain %id__ptr_Function_v2float %id_i %id_int_0
5464fd4e5da5Sopenharmony_ci        %id_115 = OpLoad %id_v2float %id_114
5465fd4e5da5Sopenharmony_ci        %id_119 = OpSampledImage %id_type_sampled_image %id_106 %id_109
5466fd4e5da5Sopenharmony_ci        %id_120 = OpImageSampleImplicitLod %id_v4float %id_119 %id_115 None
5467fd4e5da5Sopenharmony_ci        %id_123 = OpAccessChain %id__ptr_Function_v4float %id_ps_output %id_int_0
5468fd4e5da5Sopenharmony_ci               OpStore %id_123 %id_120
5469fd4e5da5Sopenharmony_ci        %id_125 = OpLoad %id_PS_OUTPUT %id_ps_output
5470fd4e5da5Sopenharmony_ci               OpReturnValue %id_125
5471fd4e5da5Sopenharmony_ci               OpFunctionEnd
5472fd4e5da5Sopenharmony_ci)";
5473fd4e5da5Sopenharmony_ci
5474fd4e5da5Sopenharmony_ci  CompileSuccessfully(ss.str());
5475fd4e5da5Sopenharmony_ci  ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
5476fd4e5da5Sopenharmony_ci}
5477fd4e5da5Sopenharmony_ci
5478fd4e5da5Sopenharmony_ci}  // namespace
5479fd4e5da5Sopenharmony_ci}  // namespace val
5480fd4e5da5Sopenharmony_ci}  // namespace spvtools
5481