aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/spirv/Module.zig
diff options
context:
space:
mode:
authorAli Chraghi <alichraghi@proton.me>2024-02-15 17:28:15 +0330
committerAli Chraghi <alichraghi@proton.me>2024-02-15 17:28:15 +0330
commit23b707565676fd650299e9808c1acf2bbb4d46f2 (patch)
treeec2a00f8381784c7a8ad69f0f9c80d86669c5a7a /src/codegen/spirv/Module.zig
parent44c31194e3d192d0991866c91c5b44a54ebf8fb1 (diff)
downloadzig-23b707565676fd650299e9808c1acf2bbb4d46f2.tar.gz
zig-23b707565676fd650299e9808c1acf2bbb4d46f2.zip
spirv: add capability to compile with x86_64 backend
Diffstat (limited to 'src/codegen/spirv/Module.zig')
-rw-r--r--src/codegen/spirv/Module.zig32
1 files changed, 20 insertions, 12 deletions
diff --git a/src/codegen/spirv/Module.zig b/src/codegen/spirv/Module.zig
index a1d1f13a6e..61ef36162f 100644
--- a/src/codegen/spirv/Module.zig
+++ b/src/codegen/spirv/Module.zig
@@ -8,6 +8,7 @@
const Module = @This();
const std = @import("std");
+const builtin = @import("builtin");
const Allocator = std.mem.Allocator;
const assert = std.debug.assert;
@@ -471,19 +472,26 @@ pub fn flush(self: *Module, file: std.fs.File, target: std.Target) !void {
self.sections.functions.toWords(),
};
- var iovc_buffers: [buffers.len]std.os.iovec_const = undefined;
- var file_size: u64 = 0;
- for (&iovc_buffers, 0..) |*iovc, i| {
- // Note, since spir-v supports both little and big endian we can ignore byte order here and
- // just treat the words as a sequence of bytes.
- const bytes = std.mem.sliceAsBytes(buffers[i]);
- iovc.* = .{ .iov_base = bytes.ptr, .iov_len = bytes.len };
- file_size += bytes.len;
- }
+ if (builtin.zig_backend == .stage2_x86_64) {
+ for (buffers) |buf| {
+ try file.writeAll(std.mem.sliceAsBytes(buf));
+ }
+ } else {
+ // miscompiles with x86_64 backend
+ var iovc_buffers: [buffers.len]std.os.iovec_const = undefined;
+ var file_size: u64 = 0;
+ for (&iovc_buffers, 0..) |*iovc, i| {
+ // Note, since spir-v supports both little and big endian we can ignore byte order here and
+ // just treat the words as a sequence of bytes.
+ const bytes = std.mem.sliceAsBytes(buffers[i]);
+ iovc.* = .{ .iov_base = bytes.ptr, .iov_len = bytes.len };
+ file_size += bytes.len;
+ }
- try file.seekTo(0);
- try file.setEndPos(file_size);
- try file.pwritevAll(&iovc_buffers, 0);
+ try file.seekTo(0);
+ try file.setEndPos(file_size);
+ try file.pwritevAll(&iovc_buffers, 0);
+ }
}
/// Merge the sections making up a function declaration into this module.