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
This commit is contained in:
Robin Voetter 2023-10-15 16:47:48 +02:00
parent 45a1945dc4
commit 0552e504d0
No known key found for this signature in database

View File

@ -415,6 +415,18 @@ pub fn flush(self: *Module, file: std.fs.File) !void {
0, // Schema (currently reserved for future use)
};
var source = Section{};
defer source.deinit(self.gpa);
try self.sections.debug_strings.emit(self.gpa, .OpSource, .{
.source_language = .Unknown,
.version = 0,
// We cannot emit these because the Khronos translator does not parse this instruction
// correctly.
// See https://github.com/KhronosGroup/SPIRV-LLVM-Translator/issues/2188
.file = null,
.source = null,
});
// Note: needs to be kept in order according to section 2.3!
const buffers = &[_][]const Word{
&header,
@ -422,6 +434,7 @@ pub fn flush(self: *Module, file: std.fs.File) !void {
self.sections.extensions.toWords(),
entry_points.toWords(),
self.sections.execution_modes.toWords(),
source.toWords(),
self.sections.debug_strings.toWords(),
self.sections.debug_names.toWords(),
self.sections.annotations.toWords(),
@ -467,13 +480,6 @@ pub fn resolveSourceFileName(self: *Module, path: []const u8) !IdRef {
.id_result = file_result_id,
.string = path,
});
try self.sections.debug_strings.emit(self.gpa, .OpSource, .{
.source_language = .Unknown, // TODO: Register Zig source language.
.version = 0, // TODO: Zig version as u32?
.file = file_result_id,
.source = null, // TODO: Store actual source also?
});
}
return result.value_ptr.*;