authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-04-08 14:55:39+02:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-04-09 01:51:54+02:00
loge389f524c9a09719ea2f6b684c0bf6f3fe4c3c9b
tree8cde9fe9ea079375e1beb32542cd29a7124eabd6
parentf12beb857ad7868396a4246b8f62f83f625c0978
signaturelock-open Commit is signed but in an unrecognized format.

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.

2 files changed, 16 insertions(+), 4 deletions(-)

src/codegen/spirv.zig+1
......@@ -1456,6 +1456,7 @@ pub const DeclGen = struct {
14561456 .name = fqn,
14571457 });
14581458
1459 // Temporarily generate a test kernel declaration if this is a test function.
14591460 if (self.module.test_functions.contains(self.decl_index)) {
14601461 try self.generateTestEntryPoint(fqn, spv_decl_index);
14611462 }
src/link/SpirV.zig+15-4
......@@ -135,10 +135,21 @@ pub fn updateDeclExports(
135135 decl_index: Module.Decl.Index,
136136 exports: []const *Module.Export,
137137) !void {
138 _ = self;
139 _ = module;
140 _ = decl_index;
141 _ = exports;
138 const decl = module.declPtr(decl_index);
139 if (decl.val.tag() == .function and decl.ty.fnCallingConvention() == .Kernel) {
140 // TODO: Unify with resolveDecl in spirv.zig.
141 const entry = try self.decl_link.getOrPut(decl_index);
142 if (!entry.found_existing) {
143 entry.value_ptr.* = try self.spv.allocDecl(.func);
144 }
145 const spv_decl_index = entry.value_ptr.*;
146
147 for (exports) |exp| {
148 try self.spv.declareEntryPoint(spv_decl_index, exp.options.name);
149 }
150 }
151
152 // TODO: Export regular functions, variables, etc using Linkage attributes.
142153}
143154
144155pub fn freeDecl(self: *SpirV, decl_index: Module.Decl.Index) void {