adding base extension support
All checks were successful
Build / build (push) Successful in 2m8s
Test / build (push) Successful in 7m17s

This commit is contained in:
2026-01-23 03:23:44 +01:00
parent 27172539e5
commit 37da19ed43
9 changed files with 112 additions and 81 deletions

View File

@@ -41,6 +41,7 @@ const ModuleError = error{
InvalidSpirV,
InvalidMagic,
UnsupportedEndianness,
UnsupportedExtension,
OutOfMemory,
};

View File

@@ -1,5 +1,6 @@
const std = @import("std");
const spv = @import("spv.zig");
const op = @import("opcodes.zig");
const RuntimeError = @import("Runtime.zig").RuntimeError;
@@ -228,7 +229,10 @@ pub const Value = union(Type) {
pub const VariantData = union(Variant) {
String: []const u8,
Extension: struct {},
Extension: struct {
/// Should not be allocated but rather a pointer to a static array
dispatcher: []op.OpCodeExtFunc,
},
Type: union(Type) {
Void: struct {},
Bool: struct {},

View File

@@ -26,6 +26,7 @@ pub const RuntimeError = error{
ToDo,
Unreachable,
UnsupportedSpirV,
UnsupportedExtension,
};
pub const Function = struct {

0
src/ext/GLSL_std_450.zig git.filemode.normal_file
View File

View File

@@ -13,7 +13,6 @@ const SpvByte = spv.SpvByte;
const SpvWord = spv.SpvWord;
const SpvBool = spv.SpvBool;
// OpExtInstImport
// OpExtInst Sin
// OpExtInst Cos
// OpExtInst Length
@@ -71,6 +70,7 @@ const BitOp = enum {
};
pub const OpCodeFunc = *const fn (std.mem.Allocator, SpvWord, *Runtime) RuntimeError!void;
pub const OpCodeExtFunc = *const fn (std.mem.Allocator, SpvWord, SpvWord, SpvWord, *Runtime) RuntimeError!void;
pub const SetupDispatcher = block: {
@setEvalBranchQuota(65535);
@@ -174,6 +174,8 @@ pub const SetupDispatcher = block: {
.Variable = opVariable,
.VectorTimesMatrix = autoSetupConstant,
.VectorTimesScalar = autoSetupConstant,
.ExtInst = autoSetupConstant,
.ExtInstImport = opExtInstImport,
});
};
@@ -1104,6 +1106,30 @@ fn opExecutionMode(_: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeError!
}
}
fn opExtInst(allocator: std.mem.Allocator, word_count: SpvWord, rt: *Runtime) RuntimeError!void {
const target_type = try rt.it.next();
const id = try rt.it.next();
const set = try rt.it.next();
const inst = try rt.it.next();
switch (try rt.results[set].getVariant()) {
.Extension => |ext| if (ext.dispatcher[inst]) |pfn| {
try pfn(allocator, target_type, id, word_count, rt);
},
else => return RuntimeError.InvalidSpirV,
}
}
fn opExtInstImport(allocator: std.mem.Allocator, word_count: SpvWord, rt: *Runtime) RuntimeError!void {
const id = try rt.it.next();
rt.mod.results[id].name = try readStringN(allocator, &rt.it, word_count - 1);
rt.mod.results[id].variant = .{
.Extension = .{
.dispatcher = undefined,
},
};
}
fn opFunction(allocator: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeError!void {
const return_type = try rt.it.next();
const id = try rt.it.next();