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