authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-04-08 19:02:31+02:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-04-09 01:51:55+02:00
loga7563e453dce0cc256a0c40af434731f2cf7dcaf
treea0483d968b31c6d5a90bb32312bf13af62c0b79d
parent45b5f467709e3df01aafc37c25070bbbebd43e1e
signaturelock-open Commit is signed but in an unrecognized format.

spirv: minimal start code

For SPIR-V, only export the main function if it is actually declared. Kernel entry points will often have parameters and more than one kernel declared. In general, SPIR-V binaries should mostly be compiled as libraries and not as executables. However, this start code is required so that we can build test executables. Note that a call to isSpirV() would emit the code for that function, even though the call is at comptime. To save that function from being emitted the checks are just inlined manually.

1 files changed, 10 insertions(+), 1 deletions(-)

lib/std/start.zig+10-1
...@@ -24,7 +24,9 @@ pub const simplified_logic =...@@ -24,7 +24,9 @@ pub const simplified_logic =
24 builtin.zig_backend == .stage2_aarch64 or24 builtin.zig_backend == .stage2_aarch64 or
25 builtin.zig_backend == .stage2_arm or25 builtin.zig_backend == .stage2_arm or
26 builtin.zig_backend == .stage2_riscv64 or26 builtin.zig_backend == .stage2_riscv64 or
27 builtin.zig_backend == .stage2_sparc64;27 builtin.zig_backend == .stage2_sparc64 or
28 builtin.cpu.arch == .spirv32 or
29 builtin.cpu.arch == .spirv64;
2830
29comptime {31comptime {
30 // No matter what, we import the root file, so that any export, test, comptime32 // No matter what, we import the root file, so that any export, test, comptime
...@@ -43,6 +45,9 @@ comptime {...@@ -43,6 +45,9 @@ comptime {
43 }45 }
44 } else if (builtin.os.tag == .wasi and @hasDecl(root, "main")) {46 } else if (builtin.os.tag == .wasi and @hasDecl(root, "main")) {
45 @export(wasiMain2, .{ .name = "_start" });47 @export(wasiMain2, .{ .name = "_start" });
48 } else if (builtin.os.tag == .opencl) {
49 if (@hasDecl(root, "main"))
50 @export(spirvMain2, .{ .name = "main" });
46 } else {51 } else {
47 if (!@hasDecl(root, "_start")) {52 if (!@hasDecl(root, "_start")) {
48 @export(_start2, .{ .name = "_start" });53 @export(_start2, .{ .name = "_start" });
...@@ -127,6 +132,10 @@ fn wasiMain2() callconv(.C) noreturn {...@@ -127,6 +132,10 @@ fn wasiMain2() callconv(.C) noreturn {
127 }132 }
128}133}
129134
135fn spirvMain2() callconv(.Kernel) void {
136 root.main();
137}
138
130fn wWinMainCRTStartup2() callconv(.C) noreturn {139fn wWinMainCRTStartup2() callconv(.C) noreturn {
131 root.main();140 root.main();
132 exit2(0);141 exit2(0);