authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-04-08 15:03:05+02:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-04-09 01:51:54+02:00
log1de2d2ee1c70dfd01dc8b161af53ce188e84b1d0
tree60579b813e20e274991502b9672a51b55b5ecb0b
parente389f524c9a09719ea2f6b684c0bf6f3fe4c3c9b
signaturelock-open Commit is signed but in an unrecognized format.

spirv: deny OpEntryPoint in asm

Kernels should be exported by marking the kernel using callconv(.Kernel) and exporting it as a regular function.

1 files changed, 12 insertions(+), 8 deletions(-)

src/codegen/spirv/Assembler.zig+12-8
......@@ -239,12 +239,17 @@ fn todo(self: *Assembler, comptime fmt: []const u8, args: anytype) Error {
239239/// If this function returns `error.AssembleFail`, an explanatory
240240/// error message has already been emitted into `self.errors`.
241241fn processInstruction(self: *Assembler) !void {
242 const result = switch (self.inst.opcode.class()) {
243 .TypeDeclaration => try self.processTypeInstruction(),
244 else => if (try self.processGenericInstruction()) |result|
245 result
246 else
247 return,
242 const result = switch (self.inst.opcode) {
243 .OpEntryPoint => {
244 return self.fail(0, "cannot export entry points via OpEntryPoint, export the kernel using callconv(.Kernel)", .{});
245 },
246 else => switch (self.inst.opcode.class()) {
247 .TypeDeclaration => try self.processTypeInstruction(),
248 else => if (try self.processGenericInstruction()) |result|
249 result
250 else
251 return,
252 },
248253 };
249254
250255 const result_ref = self.inst.result().?;
......@@ -435,8 +440,7 @@ fn processGenericInstruction(self: *Assembler) !?AsmValue {
435440 .Annotation => &self.spv.sections.annotations,
436441 .TypeDeclaration => unreachable, // Handled elsewhere.
437442 else => switch (self.inst.opcode) {
438 // TODO: This should emit a proper entry point.
439 .OpEntryPoint => unreachable, // &self.spv.sections.entry_points,
443 .OpEntryPoint => unreachable,
440444 .OpExecutionMode, .OpExecutionModeId => &self.spv.sections.execution_modes,
441445 .OpVariable => switch (@intToEnum(spec.StorageClass, operands[2].value)) {
442446 .Function => &self.func.prologue,