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