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 =
2424 builtin.zig_backend == .stage2_aarch64 or
2525 builtin.zig_backend == .stage2_arm or
2626 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
2931comptime {
3032 // No matter what, we import the root file, so that any export, test, comptime
......@@ -43,6 +45,9 @@ comptime {
4345 }
4446 } else if (builtin.os.tag == .wasi and @hasDecl(root, "main")) {
4547 @export(wasiMain2, .{ .name = "_start" });
48 } else if (builtin.os.tag == .opencl) {
49 if (@hasDecl(root, "main"))
50 @export(spirvMain2, .{ .name = "main" });
4651 } else {
4752 if (!@hasDecl(root, "_start")) {
4853 @export(_start2, .{ .name = "_start" });
......@@ -127,6 +132,10 @@ fn wasiMain2() callconv(.C) noreturn {
127132 }
128133}
129134
135fn spirvMain2() callconv(.Kernel) void {
136 root.main();
137}
138
130139fn wWinMainCRTStartup2() callconv(.C) noreturn {
131140 root.main();
132141 exit2(0);