From 0552e504d061c428655536b82db3bda21d97ef3c Mon Sep 17 00:00:00 2001 From: Robin Voetter Date: Sun, 15 Oct 2023 16:47:48 +0200 Subject: [PATCH] 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 --- src/codegen/spirv/Module.zig | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/codegen/spirv/Module.zig b/src/codegen/spirv/Module.zig index c16e1a6d72..1936b78826 100644 --- a/src/codegen/spirv/Module.zig +++ b/src/codegen/spirv/Module.zig @@ -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.*;