adding serializer
This commit is contained in:
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2024 REMqb
|
Copyright (c) 2025 kbz_8
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
32
src/Deserializer.zig
git.filemode.normal_file
32
src/Deserializer.zig
git.filemode.normal_file
@@ -0,0 +1,32 @@
|
|||||||
|
const std = @import("std");
|
||||||
|
const Module = @import("Module.zig");
|
||||||
|
const cnzsl = @cImport({
|
||||||
|
@cInclude("CNZSL/CNZSL.h");
|
||||||
|
});
|
||||||
|
|
||||||
|
const Self = @This();
|
||||||
|
|
||||||
|
instance: *cnzsl.nzslDeserializer,
|
||||||
|
|
||||||
|
pub fn init(data: []const u8) !Self {
|
||||||
|
const cdeserializer = cnzsl.nzslDeserializerCreate(@ptrCast(data), data.len) orelse return error.NullPointer;
|
||||||
|
return .{
|
||||||
|
.instance = cdeserializer,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn deinit(self: Self) void {
|
||||||
|
cnzsl.nzslDeserializerDestroy(@ptrCast(self.instance));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn deserializeShader(self: Self) !Module {
|
||||||
|
const cmodule = cnzsl.nzslDeserializeShader(@ptrCast(self.instance)) orelse return error.NullPointer;
|
||||||
|
return .{
|
||||||
|
.instance = @ptrCast(cmodule),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn getLastError(self: Self) ![]const u8 {
|
||||||
|
const err = cnzsl.nzslDeserializerGetLastError(@ptrCast(self.instance)) orelse return error.NullPointer;
|
||||||
|
return std.mem.span(err);
|
||||||
|
}
|
||||||
20
src/FilesystemModuleResolver.zig
git.filemode.normal_file
20
src/FilesystemModuleResolver.zig
git.filemode.normal_file
@@ -0,0 +1,20 @@
|
|||||||
|
const std = @import("std");
|
||||||
|
const Module = @import("Module.zig");
|
||||||
|
const cnzsl = @cImport({
|
||||||
|
@cInclude("CNZSL/CNZSL.h");
|
||||||
|
});
|
||||||
|
|
||||||
|
const Self = @This();
|
||||||
|
|
||||||
|
instance: *cnzsl.nzslFilesystemModuleResolver,
|
||||||
|
|
||||||
|
pub fn init() !Self {
|
||||||
|
const cfmr = cnzsl.nzslFilesystemModuleResolverCreate() orelse error.NullPointer;
|
||||||
|
return .{
|
||||||
|
.instance = cfmr,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn deinit(self: Self) void {
|
||||||
|
cnzsl.nzslFilesystemModuleResolverDestroy(@ptrCast(self.instance));
|
||||||
|
}
|
||||||
37
src/Serializer.zig
git.filemode.normal_file
37
src/Serializer.zig
git.filemode.normal_file
@@ -0,0 +1,37 @@
|
|||||||
|
const std = @import("std");
|
||||||
|
const Module = @import("Module.zig");
|
||||||
|
const cnzsl = @cImport({
|
||||||
|
@cInclude("CNZSL/CNZSL.h");
|
||||||
|
});
|
||||||
|
|
||||||
|
const Self = @This();
|
||||||
|
|
||||||
|
instance: *cnzsl.nzslSerializer,
|
||||||
|
|
||||||
|
pub fn init() !Self {
|
||||||
|
const cserializer = cnzsl.nzslSerializerCreate() orelse return error.NullPointer;
|
||||||
|
return .{
|
||||||
|
.instance = cserializer,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn deinit(self: Self) void {
|
||||||
|
cnzsl.nzslSerializerDestroy(self.instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn serializeShader(self: Self, module: Module) !void {
|
||||||
|
if (cnzsl.nzslSerializeShader(self.instance, @ptrCast(module.instance)) == 0) {
|
||||||
|
return error.FailedToSerializeShader;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn getData(self: Self) []const u8 {
|
||||||
|
var size: usize = undefined;
|
||||||
|
const code: [*c]const u8 = @ptrCast(cnzsl.nzslSerializerGetData(self.instance, &size));
|
||||||
|
return code[0..size];
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn getLastError(self: Self) ![]const u8 {
|
||||||
|
const err = cnzsl.nzslSerializerGetLastError(@ptrCast(self.instance)) orelse return error.NullPointer;
|
||||||
|
return std.mem.span(err);
|
||||||
|
}
|
||||||
@@ -23,8 +23,11 @@ pub fn hashOption(str: [:0]const u8) !OptionHash {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub const BackendParameters = @import("BackendParameters.zig");
|
pub const BackendParameters = @import("BackendParameters.zig");
|
||||||
|
pub const Deserializer = @import("Deserializer.zig");
|
||||||
|
pub const FilesystemModuleResolver = @import("FilesystemModuleResolver.zig");
|
||||||
pub const GlslWriter = @import("GlslWriter.zig");
|
pub const GlslWriter = @import("GlslWriter.zig");
|
||||||
pub const LangWriter = @import("LangWriter.zig");
|
pub const LangWriter = @import("LangWriter.zig");
|
||||||
pub const Module = @import("Module.zig");
|
pub const Module = @import("Module.zig");
|
||||||
pub const parser = @import("parser.zig");
|
pub const parser = @import("parser.zig");
|
||||||
|
pub const Serializer = @import("Serializer.zig");
|
||||||
pub const SpirvWriter = @import("SpirvWriter.zig");
|
pub const SpirvWriter = @import("SpirvWriter.zig");
|
||||||
|
|||||||
Reference in New Issue
Block a user