zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit e389f524c9a09719ea2f6b684c0bf6f3fe4c3c9b (tree)
parent f12beb857ad7868396a4246b8f62f83f625c0978
Author: Robin Voetter <robin@voetter.nl>
Date:   Sat,  8 Apr 2023 14:55:39 +0200

spirv: export functions with .Kernel callconv as entry point

Exported functions which have the .Kernel calling convention are now exported
as entry point. This also works with @export.

Diffstat:
Msrc/codegen/spirv.zig | 1+
Msrc/link/SpirV.zig | 19+++++++++++++++----
2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/codegen/spirv.zig b/src/codegen/spirv.zig @@ -1456,6 +1456,7 @@ pub const DeclGen = struct { .name = fqn, }); + // Temporarily generate a test kernel declaration if this is a test function. if (self.module.test_functions.contains(self.decl_index)) { try self.generateTestEntryPoint(fqn, spv_decl_index); } diff --git a/src/link/SpirV.zig b/src/link/SpirV.zig @@ -135,10 +135,21 @@ pub fn updateDeclExports( decl_index: Module.Decl.Index, exports: []const *Module.Export, ) !void { - _ = self; - _ = module; - _ = decl_index; - _ = exports; + const decl = module.declPtr(decl_index); + if (decl.val.tag() == .function and decl.ty.fnCallingConvention() == .Kernel) { + // TODO: Unify with resolveDecl in spirv.zig. + const entry = try self.decl_link.getOrPut(decl_index); + if (!entry.found_existing) { + entry.value_ptr.* = try self.spv.allocDecl(.func); + } + const spv_decl_index = entry.value_ptr.*; + + for (exports) |exp| { + try self.spv.declareEntryPoint(spv_decl_index, exp.options.name); + } + } + + // TODO: Export regular functions, variables, etc using Linkage attributes. } pub fn freeDecl(self: *SpirV, decl_index: Module.Decl.Index) void {