authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-10-15 16:47:48+02:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-10-15 17:07:39+02:00
log0552e504d061c428655536b82db3bda21d97ef3c
tree6115fc20146bb97cbe6e0ab5badc05d1a92015f3
parent45a1945dc4a77fb757725d977a6e385a21793a98
signature Signed by SSH key SHA256:CQ99aPxq+RueiL9u7z0FEki5Fm7V6T8q4PrEGmINrA4

spirv: work around OpSource parsing issue in llvm-spirv

The Khronos SPIRV-LLVM translator does not parse OpSource correctly. This was causing tests to fail and other mysterious issues. These are resolved by only generating a single OpSource instruction for now, which does not have the source file locations also. See https://github.com/KhronosGroup/SPIRV-LLVM-Translator/issues/2188

1 files changed, 13 insertions(+), 7 deletions(-)

src/codegen/spirv/Module.zig+13-7
...@@ -415,6 +415,18 @@ pub fn flush(self: *Module, file: std.fs.File) !void {...@@ -415,6 +415,18 @@ pub fn flush(self: *Module, file: std.fs.File) !void {
415 0, // Schema (currently reserved for future use)415 0, // Schema (currently reserved for future use)
416 };416 };
417417
418 var source = Section{};
419 defer source.deinit(self.gpa);
420 try self.sections.debug_strings.emit(self.gpa, .OpSource, .{
421 .source_language = .Unknown,
422 .version = 0,
423 // We cannot emit these because the Khronos translator does not parse this instruction
424 // correctly.
425 // See https://github.com/KhronosGroup/SPIRV-LLVM-Translator/issues/2188
426 .file = null,
427 .source = null,
428 });
429
418 // Note: needs to be kept in order according to section 2.3!430 // Note: needs to be kept in order according to section 2.3!
419 const buffers = &[_][]const Word{431 const buffers = &[_][]const Word{
420 &header,432 &header,
...@@ -422,6 +434,7 @@ pub fn flush(self: *Module, file: std.fs.File) !void {...@@ -422,6 +434,7 @@ pub fn flush(self: *Module, file: std.fs.File) !void {
422 self.sections.extensions.toWords(),434 self.sections.extensions.toWords(),
423 entry_points.toWords(),435 entry_points.toWords(),
424 self.sections.execution_modes.toWords(),436 self.sections.execution_modes.toWords(),
437 source.toWords(),
425 self.sections.debug_strings.toWords(),438 self.sections.debug_strings.toWords(),
426 self.sections.debug_names.toWords(),439 self.sections.debug_names.toWords(),
427 self.sections.annotations.toWords(),440 self.sections.annotations.toWords(),
...@@ -467,13 +480,6 @@ pub fn resolveSourceFileName(self: *Module, path: []const u8) !IdRef {...@@ -467,13 +480,6 @@ pub fn resolveSourceFileName(self: *Module, path: []const u8) !IdRef {
467 .id_result = file_result_id,480 .id_result = file_result_id,
468 .string = path,481 .string = path,
469 });482 });
470
471 try self.sections.debug_strings.emit(self.gpa, .OpSource, .{
472 .source_language = .Unknown, // TODO: Register Zig source language.
473 .version = 0, // TODO: Zig version as u32?
474 .file = file_result_id,
475 .source = null, // TODO: Store actual source also?
476 });
477 }483 }
478484
479 return result.value_ptr.*;485 return result.value_ptr.*;