From e389f524c9a09719ea2f6b684c0bf6f3fe4c3c9b Mon Sep 17 00:00:00 2001 From: Robin Voetter Date: Sat, 8 Apr 2023 14:55:39 +0200 Subject: [PATCH] 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. --- src/codegen/spirv.zig | 1 + src/link/SpirV.zig | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/codegen/spirv.zig b/src/codegen/spirv.zig index f813c393cd73a3198b7f315413deb3b119ff2d2e..aebe16a10a11d999bc2638a7272bf527d26d8402 100644 --- 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 index 7ec4c2cac6f6a3855b1a6f515a0d3785a6b67f2c..3eed36993344f4284121cee4376dfb958580f021 100644 --- 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 { -- 2.54.0