authorgravatar for alichraghi@proton.meAli Chraghi <alichraghi@proton.me> 2024-02-15 17:28:15+03:30
committergravatar for alichraghi@proton.meAli Chraghi <alichraghi@proton.me> 2024-02-15 17:28:15+03:30
log23b707565676fd650299e9808c1acf2bbb4d46f2
treeec2a00f8381784c7a8ad69f0f9c80d86669c5a7a
parent44c31194e3d192d0991866c91c5b44a54ebf8fb1

spirv: add capability to compile with x86_64 backend


1 files changed, 20 insertions(+), 12 deletions(-)

src/codegen/spirv/Module.zig+20-12
...@@ -8,6 +8,7 @@...@@ -8,6 +8,7 @@
8const Module = @This();8const Module = @This();
99
10const std = @import("std");10const std = @import("std");
11const builtin = @import("builtin");
11const Allocator = std.mem.Allocator;12const Allocator = std.mem.Allocator;
12const assert = std.debug.assert;13const assert = std.debug.assert;
1314
...@@ -471,19 +472,26 @@ pub fn flush(self: *Module, file: std.fs.File, target: std.Target) !void {...@@ -471,19 +472,26 @@ pub fn flush(self: *Module, file: std.fs.File, target: std.Target) !void {
471 self.sections.functions.toWords(),472 self.sections.functions.toWords(),
472 };473 };
473474
474 var iovc_buffers: [buffers.len]std.os.iovec_const = undefined;475 if (builtin.zig_backend == .stage2_x86_64) {
475 var file_size: u64 = 0;476 for (buffers) |buf| {
476 for (&iovc_buffers, 0..) |*iovc, i| {477 try file.writeAll(std.mem.sliceAsBytes(buf));
477 // Note, since spir-v supports both little and big endian we can ignore byte order here and478 }
478 // just treat the words as a sequence of bytes.479 } else {
479 const bytes = std.mem.sliceAsBytes(buffers[i]);480 // miscompiles with x86_64 backend
480 iovc.* = .{ .iov_base = bytes.ptr, .iov_len = bytes.len };481 var iovc_buffers: [buffers.len]std.os.iovec_const = undefined;
481 file_size += bytes.len;482 var file_size: u64 = 0;
482 }483 for (&iovc_buffers, 0..) |*iovc, i| {
484 // Note, since spir-v supports both little and big endian we can ignore byte order here and
485 // just treat the words as a sequence of bytes.
486 const bytes = std.mem.sliceAsBytes(buffers[i]);
487 iovc.* = .{ .iov_base = bytes.ptr, .iov_len = bytes.len };
488 file_size += bytes.len;
489 }
483490
484 try file.seekTo(0);491 try file.seekTo(0);
485 try file.setEndPos(file_size);492 try file.setEndPos(file_size);
486 try file.pwritevAll(&iovc_buffers, 0);493 try file.pwritevAll(&iovc_buffers, 0);
494 }
487}495}
488496
489/// Merge the sections making up a function declaration into this module.497/// Merge the sections making up a function declaration into this module.