big rework towards Zig 0.15

This commit is contained in:
Kbz-8
2025-10-24 17:31:36 +02:00
parent dcc40e46b9
commit f52052da90
15 changed files with 439 additions and 443 deletions

4
.gitignore vendored
View File

@@ -1,4 +1,2 @@
.zig-cache/
.idea/
zig-cache/
zig-out/ zig-out/

188
build.zig
View File

@@ -3,10 +3,7 @@ const std = @import("std");
const Build = std.Build; const Build = std.Build;
const Step = std.Build.Step; const Step = std.Build.Step;
pub const Libsource = enum { pub const Libsource = enum { source, prebuild };
source,
prebuild
};
// based on ziglua's build.zig // based on ziglua's build.zig
@@ -28,24 +25,25 @@ pub fn build(b: *Build) void {
} }
// Zig module // Zig module
const nzslzig = b.addModule("nzslzig", .{ const nzigsl = b.addModule("nzigsl", .{
.root_source_file = .{ .path = "src/lib.zig" },
});
const docs = b.addStaticLibrary(.{
.name = "nzslzig",
.root_source_file = .{ .path = "src/lib.zig" },
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
.root_source_file = b.path("src/lib.zig"),
}); });
// Expose build configuration to the nzslzig module const docs = b.addLibrary(.{
.name = "nzigsl",
.root_module = nzigsl,
.linkage = .static,
});
// Expose build configuration to the nzigsl module
const config = b.addOptions(); const config = b.addOptions();
config.addOption(Libsource, "libsource", libsource); config.addOption(Libsource, "libsource", libsource);
nzslzig.addOptions("config", config); nzigsl.addOptions("config", config);
nzsldep: { nzsldep: {
const upstream = b.lazyDependency(if (libsource == .source) "nzsl_source" else break :nzsldep , .{}) orelse break :nzsldep; const upstream = b.lazyDependency(if (libsource == .source) "nzsl" else break :nzsldep, .{}) orelse break :nzsldep;
const nazaraUtils = b.lazyDependency("NazaraUtils", .{}) orelse break :nzsldep; const nazaraUtils = b.lazyDependency("NazaraUtils", .{}) orelse break :nzsldep;
const frozen = b.lazyDependency("frozen", .{}) orelse break :nzsldep; const frozen = b.lazyDependency("frozen", .{}) orelse break :nzsldep;
const fmt = b.lazyDependency("fmt", .{}) orelse break :nzsldep; const fmt = b.lazyDependency("fmt", .{}) orelse break :nzsldep;
@@ -53,16 +51,16 @@ pub fn build(b: *Build) void {
const fast_float = b.lazyDependency("fast_float", .{}) orelse break :nzsldep; const fast_float = b.lazyDependency("fast_float", .{}) orelse break :nzsldep;
const lib = switch (libsource) { const lib = switch (libsource) {
.source => buildNzsl(b, target, optimize, upstream, nazaraUtils, frozen, fmt, ordered_map, fast_float, shared), .source => buildNzsl(b, target, optimize, upstream, nazaraUtils, frozen, fmt, ordered_map, fast_float, shared),
else => unreachable, else => unreachable,
}; };
// Expose the Nzsl artifact // Expose the Nzsl artifact
b.installArtifact(lib); b.installArtifact(lib);
//nzslzig.addSystemIncludePath(upstream.path("include")); //nzigsl.addSystemIncludePath(upstream.path("include"));
nzslzig.linkLibrary(lib); nzigsl.linkLibrary(lib);
docs.linkLibrary(lib); docs.linkLibrary(lib);
} }
@@ -74,11 +72,13 @@ pub fn build(b: *Build) void {
for (examples) |example| { for (examples) |example| {
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = example[0], .name = example[0],
.root_source_file = .{ .path = example[1] }, .root_module = b.createModule(.{
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
.root_source_file = b.path(example[1]),
}),
}); });
exe.root_module.addImport("nzslzig", nzslzig); exe.root_module.addImport("nzigsl", nzigsl);
const artifact = b.addInstallArtifact(exe, .{}); const artifact = b.addInstallArtifact(exe, .{});
const exe_step = b.step(b.fmt("install-example-{s}", .{example[0]}), b.fmt("Install {s} example", .{example[0]})); const exe_step = b.step(b.fmt("install-example-{s}", .{example[0]}), b.fmt("Install {s} example", .{example[0]}));
@@ -93,7 +93,7 @@ pub fn build(b: *Build) void {
} }
docs.root_module.addOptions("config", config); docs.root_module.addOptions("config", config);
docs.root_module.addImport("nzslzig", nzslzig); docs.root_module.addImport("nzigsl", nzigsl);
const install_docs = b.addInstallDirectory(.{ const install_docs = b.addInstallDirectory(.{
.source_dir = docs.getEmittedDocs(), .source_dir = docs.getEmittedDocs(),
@@ -106,16 +106,14 @@ pub fn build(b: *Build) void {
} }
fn buildNzsl(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, upstream: *Build.Dependency, nazaraUtils: *Build.Dependency, frozen: *Build.Dependency, ordered_map: *Build.Dependency, fast_float: *Build.Dependency, fmt: *Build.Dependency, shared: bool) *Step.Compile { fn buildNzsl(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, upstream: *Build.Dependency, nazaraUtils: *Build.Dependency, frozen: *Build.Dependency, ordered_map: *Build.Dependency, fast_float: *Build.Dependency, fmt: *Build.Dependency, shared: bool) *Step.Compile {
const lib = b.addLibrary(.{
const lib_opts = .{
.name = "nzsl", .name = "nzsl",
.target = target, .root_module = b.createModule(.{
.optimize = optimize, .target = target,
}; .optimize = optimize,
const lib = if (shared) }),
b.addSharedLibrary(lib_opts) .linkage = if (shared) .dynamic else .static,
else });
b.addStaticLibrary(lib_opts);
lib.addSystemIncludePath(upstream.path("include")); lib.addSystemIncludePath(upstream.path("include"));
lib.addSystemIncludePath(upstream.path("src")); lib.addSystemIncludePath(upstream.path("src"));
@@ -128,7 +126,9 @@ fn buildNzsl(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.Opti
const flags = [_][]const u8{ const flags = [_][]const u8{
if (shared) if (shared)
"-DCNZSL_DYNAMIC" else "-DCNZSL_STATIC", "-DCNZSL_DYNAMIC"
else
"-DCNZSL_STATIC",
if (shared) "-DNZSL_DYNAMIC" else "-DNZSL_STATIC", if (shared) "-DNZSL_DYNAMIC" else "-DNZSL_STATIC",
"-DCNZSL_BUILD", "-DCNZSL_BUILD",
"-DNZSL_BUILD", "-DNZSL_BUILD",
@@ -159,63 +159,83 @@ fn buildNzsl(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.Opti
lib.linkLibCpp(); lib.linkLibCpp();
lib.installHeader(upstream.path("include/CNZSL/CNZSL.h"), "CNZSL/CNZSL.h");
lib.installHeader(upstream.path("include/CNZSL/Config.h"), "CNZSL/Config.h");
lib.installHeader(upstream.path("include/CNZSL/DebugLevel.h"), "CNZSL/DebugLevel.h");
lib.installHeader(upstream.path("include/CNZSL/GlslWriter.h"), "CNZSL/GlslWriter.h");
lib.installHeader(upstream.path("include/CNZSL/LangWriter.h"), "CNZSL/LangWriter.h");
lib.installHeader(upstream.path("include/CNZSL/Module.h"), "CNZSL/Module.h");
lib.installHeader(upstream.path("include/CNZSL/Parser.h"), "CNZSL/Parser.h");
lib.installHeader(upstream.path("include/CNZSL/ShaderStageType.h"), "CNZSL/ShaderStageType.h");
lib.installHeader(upstream.path("include/CNZSL/SpirvWriter.h"), "CNZSL/SpirvWriter.h"); lib.installHeader(upstream.path("include/CNZSL/SpirvWriter.h"), "CNZSL/SpirvWriter.h");
lib.installHeader(upstream.path("include/CNZSL/WriterStates.h"), "CNZSL/WriterStates.h"); lib.installHeader(upstream.path("include/CNZSL/ShaderStageType.h"), "CNZSL/ShaderStageType.h");
lib.installHeader(upstream.path("include/CNZSL/Serializer.h"), "CNZSL/Serializer.h");
lib.installHeader(upstream.path("include/CNZSL/Parser.h"), "CNZSL/Parser.h");
lib.installHeader(upstream.path("include/CNZSL/Module.h"), "CNZSL/Module.h");
lib.installHeader(upstream.path("include/CNZSL/LangWriter.h"), "CNZSL/LangWriter.h");
lib.installHeader(upstream.path("include/CNZSL/GlslWriter.h"), "CNZSL/GlslWriter.h");
lib.installHeader(upstream.path("include/CNZSL/DebugLevel.h"), "CNZSL/DebugLevel.h");
lib.installHeader(upstream.path("include/CNZSL/Config.h"), "CNZSL/Config.h");
lib.installHeader(upstream.path("include/CNZSL/CNZSL.h"), "CNZSL/CNZSL.h");
lib.installHeader(upstream.path("include/CNZSL/BackendParameters.h"), "CNZSL/BackendParameters.h");
lib.installHeader(upstream.path("include/CNZSL/FilesystemModuleResolver.h"), "CNZSL/FilesystemModuleResolver.h");
return lib; return lib;
} }
const nzsl_source_files_list = [_][]const u8{ const nzsl_source_files_list = [_][]const u8{
"src/NZSL/Ast/AstSerializer.cpp",
"src/NZSL/Ast/Cloner.cpp",
"src/NZSL/Ast/ConstantPropagationVisitor.cpp",
"src/NZSL/Ast/ConstantPropagationVisitor_BinaryArithmetics.cpp",
"src/NZSL/Ast/ConstantPropagationVisitor_BinaryComparison.cpp",
"src/NZSL/Ast/ConstantValue.cpp",
"src/NZSL/Ast/DependencyCheckerVisitor.cpp",
"src/NZSL/Ast/EliminateUnusedPassVisitor.cpp",
"src/NZSL/Ast/ExportVisitor.cpp",
"src/NZSL/Ast/ExpressionType.cpp",
"src/NZSL/Ast/ExpressionVisitor.cpp",
"src/NZSL/Ast/ExpressionVisitorExcept.cpp",
"src/NZSL/Ast/IndexRemapperVisitor.cpp",
"src/NZSL/Ast/Nodes.cpp",
"src/NZSL/Ast/RecursiveVisitor.cpp",
"src/NZSL/Ast/ReflectVisitor.cpp",
"src/NZSL/Ast/SanitizeVisitor.cpp",
"src/NZSL/Ast/StatementVisitor.cpp",
"src/NZSL/Ast/StatementVisitorExcept.cpp",
"src/NZSL/Ast/Utils.cpp",
"src/NZSL/FilesystemModuleResolver.cpp",
"src/NZSL/GlslWriter.cpp",
"src/NZSL/Lang/Errors.cpp",
"src/NZSL/LangWriter.cpp",
"src/NZSL/Lexer.cpp",
"src/NZSL/ModuleResolver.cpp",
"src/NZSL/Parser.cpp",
"src/NZSL/Serializer.cpp",
"src/NZSL/ShaderWriter.cpp",
"src/NZSL/SpirV/SpirvAstVisitor.cpp",
"src/NZSL/SpirV/SpirvConstantCache.cpp",
"src/NZSL/SpirV/SpirvData.cpp",
"src/NZSL/SpirV/SpirvDecoder.cpp",
"src/NZSL/SpirV/SpirvExpressionLoad.cpp",
"src/NZSL/SpirV/SpirvExpressionStore.cpp",
"src/NZSL/SpirV/SpirvPrinter.cpp",
"src/NZSL/SpirV/SpirvSectionBase.cpp",
"src/NZSL/SpirvWriter.cpp", "src/NZSL/SpirvWriter.cpp",
"src/CNZSL/GlslWriter.cpp", "src/NZSL/SpirV/SpirvSectionBase.cpp",
"src/CNZSL/LangWriter.cpp", "src/NZSL/SpirV/SpirvPrinter.cpp",
"src/CNZSL/Module.cpp", "src/NZSL/SpirV/SpirvExpressionStore.cpp",
"src/CNZSL/Parser.cpp", "src/NZSL/SpirV/SpirvExpressionLoad.cpp",
"src/NZSL/SpirV/SpirvDecoder.cpp",
"src/NZSL/SpirV/SpirvData.cpp",
"src/NZSL/SpirV/SpirvConstantCache.cpp",
"src/NZSL/SpirV/SpirvAstVisitor.cpp",
"src/NZSL/Serializer.cpp",
"src/NZSL/Parser.cpp",
"src/NZSL/ModuleResolver.cpp",
"src/NZSL/Lexer.cpp",
"src/NZSL/LangWriter.cpp",
"src/NZSL/Lang/Version.cpp",
"src/NZSL/Lang/Errors.cpp",
"src/NZSL/GlslWriter.cpp",
"src/NZSL/FilesystemModuleResolver.cpp",
"src/NZSL/Ast/Utils.cpp",
"src/NZSL/Ast/Transformations/ValidationTransformer.cpp",
"src/NZSL/Ast/Transformations/TransformerContext.cpp",
"src/NZSL/Ast/Transformations/Transformer.cpp",
"src/NZSL/Ast/Transformations/SwizzleTransformer.cpp",
"src/NZSL/Ast/Transformations/StructAssignmentTransformer.cpp",
"src/NZSL/Ast/Transformations/ResolveTransformer.cpp",
"src/NZSL/Ast/Transformations/MatrixTransformer.cpp",
"src/NZSL/Ast/Transformations/LoopUnrollTransformer.cpp",
"src/NZSL/Ast/Transformations/LiteralTransformer.cpp",
"src/NZSL/Ast/Transformations/IndexRemapperTransformer.cpp",
"src/NZSL/Ast/Transformations/IdentifierTransformer.cpp",
"src/NZSL/Ast/Transformations/ForToWhileTransformer.cpp",
"src/NZSL/Ast/Transformations/EliminateUnusedTransformer.cpp",
"src/NZSL/Ast/Transformations/ConstantRemovalTransformer.cpp",
"src/NZSL/Ast/Transformations/ConstantPropagationTransformer_Binary.cpp",
"src/NZSL/Ast/Transformations/ConstantPropagationTransformer.cpp",
"src/NZSL/Ast/Transformations/CompoundAssignmentTransformer.cpp",
"src/NZSL/Ast/Transformations/BranchSplitterTransformer.cpp",
"src/NZSL/Ast/Transformations/BindingResolverTransformer.cpp",
"src/NZSL/Ast/Transformations/AliasTransformer.cpp",
"src/NZSL/Ast/StatementVisitorExcept.cpp",
"src/NZSL/Ast/StatementVisitor.cpp",
"src/NZSL/Ast/ReflectVisitor.cpp",
"src/NZSL/Ast/RecursiveVisitor.cpp",
"src/NZSL/Ast/Nodes.cpp",
"src/NZSL/Ast/IdentifierList.cpp",
"src/NZSL/Ast/ExpressionVisitorExcept.cpp",
"src/NZSL/Ast/ExpressionVisitor.cpp",
"src/NZSL/Ast/ExpressionType.cpp",
"src/NZSL/Ast/ExportVisitor.cpp",
"src/NZSL/Ast/DependencyCheckerVisitor.cpp",
"src/NZSL/Ast/ConstantValue.cpp",
"src/NZSL/Ast/Cloner.cpp",
"src/NZSL/Ast/AstSerializer.cpp",
"src/NZSL/Archive.cpp",
"src/CNZSL/SpirvWriter.cpp", "src/CNZSL/SpirvWriter.cpp",
"src/CNZSL/WriterStates.cpp", "src/CNZSL/Serializer.cpp",
"src/CNZSL/Parser.cpp",
"src/CNZSL/Module.cpp",
"src/CNZSL/LangWriter.cpp",
"src/CNZSL/GlslWriter.cpp",
"src/CNZSL/FilesystemModuleResolver.cpp",
"src/CNZSL/BackendParameters.cpp",
}; };

View File

@@ -1,62 +1,42 @@
.{ .{
.name = .NZSL, .name = .NZSL,
// This is a [Semantic Version](https://semver.org/). .version = "1.1.1",
// In a future version of Zig it will be used for package deduplication. .fingerprint = 0xd558585854524c37,
.version = "0.0.0",
// This field is optional.
// This is currently advisory only; Zig does not yet do anything
// with this value.
//.minimum_zig_version = "0.11.0",
// This field is optional.
// Each dependency must either provide a `url` and `hash`, or a `path`.
// `zig build --fetch` can be used to fetch all dependencies of a package, recursively.
// Once all dependencies are fetched, `zig build` no longer requires
// internet connectivity.
.dependencies = .{ .dependencies = .{
.nzsl_source = .{ .nzsl = .{
.url = "https://github.com/NazaraEngine/ShaderLang/archive/97dfc07923572cb26aa2db485df6bd837dea79bb.tar.gz", .url = "git+https://github.com/NazaraEngine/ShaderLang?ref=v1.1.1#6d06572eaa664b1655f57522edf1e8c88292be0a",
.hash = "12203c913b5cbccbb4b6b11d7e5730f81ed0737553fe3fc30995d059bf859101933f", .hash = "N-V-__8AAPOQIwAwA5SQCrbVxrBp5Q7YX--899XJIjFv6rZn",
.lazy = true,
.lazy = true, .lazy = true,
}, },
.NazaraUtils = .{ .NazaraUtils = .{
.url = "https://github.com/NazaraEngine/NazaraUtils/archive/cbdb331a9610fa52f51e7c86576cc9e2e7235691.tar.gz", .url = "git+https://github.com/NazaraEngine/NazaraUtils?ref=v1.0.0#d2f5d902ed9ac2bc8e26a015b1ff02edc5e3b550",
.hash = "1220a6576ccd4e2c0cf5ab804ef680c4d1834859d1f7a7e3228fef73f8dce8c0e826", .hash = "N-V-__8AAJuBBgAWrip3l4mh6_ZGHqqhMM71rYLtPorOOwyf",
.lazy = true, .lazy = true,
}, },
.frozen = .{ .frozen = .{
.url = "https://github.com/serge-sans-paille/frozen/archive/292a8110466ae964c8fde9d0e0371e5ac21bfa60.tar.gz", .url = "git+https://github.com/serge-sans-paille/frozen?ref=1.2.0#06bee5321cecd9a9ffaceb164b5adb2ffafae781",
.hash = "122039e95c3739bd73b8413d3448395b1e7b17953e342e4c3c07de848d406a28733c", .hash = "N-V-__8AAKBODwDkFCWVcsOuoC6UVtDAF1UXmqRUcTQ3nAei",
.lazy = true, .lazy = true,
}, },
.fmt = .{ .fmt = .{
.url = "https://github.com/fmtlib/fmt/archive/e69e5f977d458f2650bb346dadf2ad30c5320281.tar.gz", .url = "git+https://github.com/fmtlib/fmt?ref=12.0.0#e424e3f2e607da02742f73db84873b8084fc714c",
.hash = "12202f41bb1cbca6f555a37883ce510374b9ca577ed5cd117d71c7bdc2c87380e14d", .hash = "N-V-__8AAPoaLgBRjRikFTr6HpPPxdavmJAPy_SOYbgt3cIM",
.lazy = true, .lazy = true,
}, },
.ordered_map = .{ .ordered_map = .{
.url = "https://github.com/Tessil/ordered-map/archive/bd8d5ef4149cd40783a486011778a2e7eedde441.tar.gz", .url = "git+https://github.com/Tessil/ordered-map?ref=v1.1.0#eba0b81b89c42232e8a937389be303a33f34a527",
.hash = "122079b9af72c89c53a2fae29968665d7c8c5c9c466764019b7bf81f605072bd087f", .hash = "N-V-__8AACcGBQD8RCQaOW9wvl9QUSQ3BoWjFhFdZjAySrEw",
.lazy = true, .lazy = true,
}, },
.fast_float = .{ .fast_float = .{
.url = "https://github.com/fastfloat/fast_float/archive/1fc3ac3932220b5effaca7203bb1bb771528d256.tar.gz", .url = "git+https://github.com/fastfloat/fast_float?ref=v8.1.0#88b1e5321c6918cbe091afd76728296290668403",
.hash = "12201d7ec3e6bd8e0e90d5792a66fd4ccc670f337ee8818f8d830c1f4bd7e2fe2f3b", .hash = "N-V-__8AABEwCAAXomDLtLslEEK5zzy4Yy0b2RC-WS-DgdnU",
.lazy = true, .lazy = true,
}, },
}, },
.paths = .{ .paths = .{
// This makes *all* files, recursively, included in this package. It is generally
// better to explicitly list the files and directories instead, to insure that
// fetching from tarballs, file system paths, and version control all result
// in the same contents hash.
"", "",
// For example...
//"build.zig",
//"build.zig.zon",
//"src",
//"LICENSE",
//"README.md",
}, },
} }

View File

@@ -1,4 +1,4 @@
[nzsl_version("1.0")] [nzsl_version("1.1")]
[desc("Mandelbrot shader from http://nuclear.mutantstargoat.com/articles/sdr_fract")] [desc("Mandelbrot shader from http://nuclear.mutantstargoat.com/articles/sdr_fract")]
[feature(primitive_externals)] //< Required since SFML doesn't use UBO [feature(primitive_externals)] //< Required since SFML doesn't use UBO
module; module;
@@ -53,8 +53,8 @@ fn main(input: Input) -> Output
else else
u = 0.0; u = 0.0;
let out: Output; let output: Output;
out.color = palette.Sample(vec2[f32](u, 0.0)); output.color = palette.Sample(vec2[f32](u, 0.0));
return out; return output;
} }

View File

@@ -1,24 +1,22 @@
const std= @import("std"); const std = @import("std");
const nzsl = @import("nzslzig"); const nzsl = @import("nzigsl");
pub fn main() !void { pub fn main() !void {
const mandelbrotModule = try nzsl.parseFromFile("examples/mandelbrot.nzsl"); const module = try nzsl.parser.parseFromFile("examples/mandelbrot.nzsl");
defer mandelbrotModule.release(); defer module.deinit();
const glslWriter = nzsl.GlslWriter.create(); const params = try nzsl.BackendParameters.init();
defer glslWriter.release(); defer params.deinit();
params.setDebugLevel(.full);
const state = nzsl.WriterStates.create(); const writer = try nzsl.GlslWriter.init();
defer state.release(); defer writer.deinit();
state.setDebugLevel(.full); const writer_params = try nzsl.GlslWriter.Parameters.init();
defer writer_params.deinit();
const mappings = nzsl.GlslBindingMapping.create(); const output = try writer.generate(module, params, writer_params);
defer mappings.release(); defer output.deinit();
const output = try glslWriter.generate(mandelbrotModule, mappings, state);
defer output.release();
std.log.debug("Generated code: \n{s}", .{ output.getCode() });
std.log.debug("Generated code: \n{s}", .{output.getCode()});
} }

81
src/BackendParameters.zig git.filemode.normal_file
View File

@@ -0,0 +1,81 @@
const std = @import("std");
const DebugLevel = @import("lib.zig").DebugLevel;
const OptionHash = @import("lib.zig").OptionHash;
const cnzsl = @cImport({
@cInclude("CNZSL/CNZSL.h");
});
const Self = @This();
instance: *cnzsl.nzslBackendParameters,
pub fn init() !Self {
const cparameters = cnzsl.nzslBackendParametersCreate() orelse return error.NullPointer;
return .{
.instance = cparameters,
};
}
pub fn deinit(self: Self) void {
cnzsl.nzslBackendParametersDestroy(self.instance);
}
pub fn enableDeadCodeRemoval(self: Self, enable: bool) void {
cnzsl.nzslBackendParametersEnableDeadCodeRemoval(self.instance, enable);
}
pub fn enableOptimization(self: Self, enable: bool) void {
cnzsl.nzslBackendParametersEnableOptimization(self.instance, enable);
}
pub fn enableResolving(self: Self, enable: bool) void {
cnzsl.nzslBackendParametersEnableResolving(self.instance, enable);
}
pub fn enableTargetRequired(self: Self, enable: bool) void {
cnzsl.nzslBackendParametersEnableTargetRequired(self.instance, enable);
}
pub fn enableValidation(self: Self, enable: bool) void {
cnzsl.nzslBackendParametersEnableValidation(self.instance, enable);
}
pub fn setDebugLevel(self: Self, debug_level: DebugLevel) void {
cnzsl.nzslBackendParametersSetDebugLevel(self.instance, @intFromEnum(debug_level));
}
//pub fn SetModuleResolver_Filesystem(self: Self, const nzslFilesystemModuleResolver* resolverPtr) void {
//}
pub fn setOption(self: Self, hash: OptionHash, value: anytype) void {
const T = @TypeOf(value);
switch (@typeInfo(T)) {
.vector => |v| self.setOption(hash, @as([v.len]v.child, value)),
.float, .int, .comptime_float, .comptime_int, .bool => self.setOption(hash, [1]T{value}),
.array => |a| {
const sanitized_value, const sanitized_primitive_name = switch (@typeInfo(a.child)) {
.bool => blk: {
var new_array: [a.len]c_int = undefined;
for (value, 0..a.len) |v, i| {
new_array[i] = @intFromBool(v);
}
break :blk .{ new_array, "bool" };
},
.float => |f| if (f.bits != 32) @compileError("Unhandled float size (not 32 bits)") else .{ value, @typeName(a.child) },
.int => |i| if (i.bits != 32) @compileError("Unhandled integer size (not 32 bits)") else .{ value, @typeName(a.child) },
.comptime_float => .{ value, "f32" },
.comptime_int => .{ value, "i32" },
else => @compileError("Unhandled type"),
};
const type_name, const c_value = switch (a.len) {
1 => .{ "" ++ sanitized_primitive_name, sanitized_value[0] },
2...4 => .{ "vec" ++ [_]u8{'0' + a.len} ++ sanitized_primitive_name, @as([*c]const a.child, @ptrCast(&sanitized_value)) },
else => @compileError("Unhandled array or vector size"),
};
@call(.auto, @field(cnzsl, "nzslBackendParametersSetOption_" ++ type_name), .{ self.instance, hash, c_value });
},
else => @compileError("Unhandled type"),
}
}

View File

@@ -1,107 +1,104 @@
const cnzsl = @import("nzsl-c.zig");
const nzsl = @import("lib.zig");
const std = @import("std"); const std = @import("std");
const Module = @import("Module.zig");
const BackendParameters = @import("BackendParameters.zig");
const ShaderStageType = @import("lib.zig").ShaderStageType;
const cnzsl = @cImport({
@cInclude("CNZSL/CNZSL.h");
});
pub const ShaderStageType = enum(cnzsl.nzslShaderStageType) { const Self = @This();
compute = cnzsl.NZSL_STAGE_COMPUTE,
fragment = cnzsl.NZSL_STAGE_FRAGMENT,
vertex = cnzsl.NZSL_STAGE_VERTEX,
};
pub const GlslWriter = struct { instance: *cnzsl.nzslGlslWriter,
instance: *cnzsl.nzslGlslWriter,
pub fn create() GlslWriter { pub fn init() !Self {
return .{.instance = cnzsl.nzslGlslWriterCreate() orelse unreachable}; const cwriter = cnzsl.nzslGlslWriterCreate() orelse return error.NullPointer;
return .{
.instance = cwriter,
};
}
pub fn deinit(self: Self) void {
cnzsl.nzslGlslWriterDestroy(self.instance);
}
pub fn generate(self: Self, module: Module, backend_parameters: BackendParameters, parameters: Parameters) !Output {
const output = cnzsl.nzslGlslWriterGenerate(self.instance, @ptrCast(module.instance), @ptrCast(backend_parameters.instance), @ptrCast(parameters.instance)) orelse return error.FailedToGenerateGlsl;
return .{
.instance = output,
};
}
pub fn generateStage(self: Self, stage: ShaderStageType, module: Module, backend_parameters: BackendParameters, parameters: Parameters) !Output {
const output = cnzsl.nzslGlslWriterGenerateStage(self.instance, @intFromEnum(stage), @ptrCast(module.instance), @ptrCast(backend_parameters.instance), @ptrCast(parameters.instance)) orelse return error.FailedToGenerateGlsl;
return .{
.instance = output,
};
}
pub fn getLastError(self: Self) ![]const u8 {
const err = cnzsl.nzslGlslWriterGetLastError(self.instance) orelse return error.NullPointer;
return std.mem.span(err);
}
pub const Parameters = struct {
const InnerSelf = @This();
instance: *cnzsl.nzslGlslWriterParameters,
pub fn init() !InnerSelf {
const cparameters = cnzsl.nzslGlslWriterParametersCreate() orelse return error.NullPointer;
return .{
.instance = cparameters,
};
} }
pub fn release(self: GlslWriter) void { pub fn deinit(self: InnerSelf) void {
cnzsl.nzslGlslWriterDestroy(self.instance); cnzsl.nzslGlslWriterParametersDestroy(self.instance);
} }
pub fn generate(self: GlslWriter, module: nzsl.Module, bindingMapping: GlslBindingMapping, states: nzsl.WriterStates) !GlslOutput { pub fn setBindingMapping(self: InnerSelf, set_index: u32, binding_index: u32, gl_binding: u32) void {
var output: ?*cnzsl.nzslGlslOutput = null; cnzsl.nzslGlslWriterParametersSetBindingMapping(self.instance, set_index, binding_index, @intCast(gl_binding));
output = cnzsl.nzslGlslWriterGenerate(self.instance, module.instance, bindingMapping.instance, states.instance);
if(output == null) {
std.log.err("Failed to generate glsl output: {s}", .{ self.getLastError() });
return error.FailedToGenerateGlsl;
}
return .{.instance = output orelse unreachable};
} }
pub fn generateStage(self: GlslWriter, stage: ShaderStageType, module: nzsl.Module, bindingMapping: GlslBindingMapping, states: nzsl.WriterStates) !GlslOutput { pub fn setPushConstantBinding(self: InnerSelf, gl_binding: u32) void {
var output: ?*cnzsl.nzslGlslOutput = null; cnzsl.nzslGlslWriterParametersSetPushConstantBinding(self.instance, @intCast(gl_binding));
output = cnzsl.nzslGlslWriterGenerateStage(@intFromEnum(stage), self.instance, module.instance, bindingMapping.instance, states.instance);
if(output == null) {
std.log.err("Failed to generate glsl output: {s}", .{ self.getLastError() });
return error.FailedToGenerateGlsl;
}
return .{.instance = output orelse unreachable};
}
pub fn getLastError(self: GlslWriter) [*c]const u8 {
return cnzsl.nzslGlslWriterGetLastError(self.instance);
} }
}; };
pub const GlslBindingMapping = struct { pub const Output = struct {
instance: *cnzsl.nzslGlslBindingMapping, const InnerSelf = @This();
pub fn create() GlslBindingMapping {
return .{.instance = cnzsl.nzslGlslBindingMappingCreate() orelse unreachable};
}
pub fn release(self: GlslBindingMapping) void {
cnzsl.nzslGlslBindingMappingDestroy(self.instance);
}
pub fn setBinding(self: GlslBindingMapping, setIndex: u32, bindingIndex: u32, glBinding: c_uint) void {
cnzsl.nzslGlslBindingMappingSetBinding(self.instance, setIndex, bindingIndex, glBinding);
}
};
pub const GlslOutput = struct {
instance: *cnzsl.nzslGlslOutput, instance: *cnzsl.nzslGlslOutput,
pub fn release(self: GlslOutput) void { pub fn deinit(self: InnerSelf) void {
cnzsl.nzslGlslOutputDestroy(self.instance); cnzsl.nzslGlslOutputDestroy(self.instance);
} }
pub fn getCode(self: GlslOutput) []const u8 { pub fn getCode(self: InnerSelf) []const u8 {
var size: usize = undefined; var size: usize = undefined;
const code = cnzsl.nzslGlslOutputGetCode(self.instance, &size); const code = cnzsl.nzslGlslOutputGetCode(self.instance, &size);
return code[0..size]; return code[0..size];
} }
/// Return texture binding in output or -1 if binding doesn't exists pub fn getExplicitTextureBinding(self: InnerSelf, binding_name: [:0]const u8) i32 {
pub fn getExplicitTextureBinding(self: GlslOutput, bindingName: [*c]const u8) c_int { const res = cnzsl.nzslGlslOutputGetExplicitTextureBinding(self.instance, binding_name);
return cnzsl.nzslGlslOutputGetExplicitTextureBinding(self.instance, bindingName); return if (res != -1) res else error.BindingNameNotFound;
} }
/// Return uniform binding in output or -1 if binding doesn't exists pub fn getExplicitUniformBlockBinding(self: InnerSelf, binding_name: [:0]const u8) i32 {
pub fn getExplicitUniformBlockBinding(self: GlslOutput, bindingName: [*c]const u8) c_int { const res = cnzsl.nzslGlslOutputGetExplicitUniformBlockBinding(self.instance, binding_name);
return cnzsl.nzslGlslOutputGetExplicitUniformBlockBinding(self.instance, bindingName); return if (res != -1) res else error.BindingNameNotFound;
} }
pub fn getUsesDrawParameterBaseInstanceUniform(self: GlslOutput) c_int { pub fn usesDrawParameterBaseInstanceUniform(self: InnerSelf) bool {
return cnzsl.nzslGlslOutputGetUsesDrawParameterBaseInstanceUniform(self.instance); return cnzsl.nzslGlslOutputGetUsesDrawParameterBaseInstanceUniform(self.instance);
} }
pub fn getUsesDrawParameterBaseVertexUniform(self: GlslOutput) c_int { pub fn usesDrawParameterBaseVertexUniform(self: InnerSelf) bool {
return cnzsl.nzslGlslOutputGetUsesDrawParameterBaseVertexUniform(self.instance); return cnzsl.nzslGlslOutputGetUsesDrawParameterBaseVertexUniform(self.instance);
} }
pub fn getUsesDrawParameterDrawIndexUniform(self: GlslOutput) c_int { pub fn usesDrawParameterDrawIndexUniform(self: InnerSelf) bool {
return cnzsl.nzslGlslOutputGetUsesDrawParameterDrawIndexUniform(self.instance); return cnzsl.nzslGlslOutputGetUsesDrawParameterDrawIndexUniform(self.instance);
} }
}; };

View File

@@ -1,49 +1,48 @@
const cnzsl = @import("nzsl-c.zig");
const nzsl = @import("lib.zig");
const std = @import("std"); const std = @import("std");
const Module = @import("Module.zig");
const cnzsl = @cImport({
@cInclude("CNZSL/CNZSL.h");
});
pub const LangWriter = struct { const Self = @This();
instance: *cnzsl.nzslLangWriter,
pub fn create() LangWriter { instance: *cnzsl.nzslLangWriter,
return .{.instance = cnzsl.nzslLangWriterCreate() orelse unreachable};
}
pub fn release(self: LangWriter) void { pub fn init() !Self {
cnzsl.nzslLangWriterDestroy(self.instance); const cwriter = cnzsl.nzslLangWriterCreate() orelse return error.NullPointer;
} return .{
.instance = cwriter,
};
}
pub fn getLastError(self: LangWriter) [*c]const u8 { pub fn deinit(self: Self) void {
return cnzsl.nzslLangWriterGetLastError(self.instance); cnzsl.nzslLangWriterDestroy(self.instance);
} }
pub fn generate(self: LangWriter, module: nzsl.Module, states: nzsl.WriterStates) LangOutput { pub fn getLastError(self: Self) ![]const u8 {
var output: ?*cnzsl.nzslLangOutput = null; const err = cnzsl.nzslLangWriterGetLastError(self.instance) orelse return error.NullPointer;
return std.mem.span(err);
}
output = cnzsl.nzslLangWriterGenerate(self.instance, module.instance, states.instance); pub fn generate(self: Self, module: Module) !Output {
const output = cnzsl.nzslLangWriterGenerate(self.instance, @ptrCast(module.instance)) orelse return error.FailedToGenerateLang;
return .{
.instance = output,
};
}
if(output == null) { pub const Output = struct {
std.log.err("Failed to generate lang output: {s}", .{ self.getLastError() }); const InnerSelf = @This();
return error.FailedToGenerateLang;
}
return .{.instance = output orelse unreachable};
}
};
pub const LangOutput = struct {
instance: *cnzsl.nzslLangOutput, instance: *cnzsl.nzslLangOutput,
pub fn release(self: LangOutput) void { pub fn deinit(self: InnerSelf) void {
cnzsl.nzslLangOutputDestroy(self.instance); cnzsl.nzslLangOutputDestroy(self.instance);
} }
pub fn getCode(self: LangOutput) []const u8 { pub fn getCode(self: InnerSelf) []const u8 {
var size: usize = undefined; var size: usize = undefined;
const code = cnzsl.nzslLangOutputGetCode(self.instance, &size); const code = cnzsl.nzslLangOutputGetCode(self.instance, &size);
return code[0..size]; return code[0..size];
} }
}; };

View File

@@ -1,17 +1,24 @@
const cnzsl = @import("nzsl-c.zig"); const std = @import("std");
const cnzsl = @cImport({
@cInclude("CNZSL/CNZSL.h");
});
pub const Module = struct { const Self = @This();
instance: *cnzsl.nzslModule,
pub fn create() Module { instance: *cnzsl.nzslModule,
return .{.instance = cnzsl.nzslModuleCreate() orelse unreachable};
}
pub fn release(self: Module) void { pub fn init() !Self {
cnzsl.nzslModuleDestroy(self.instance); const cmodule = cnzsl.nzslModuleCreate() orelse return error.NullPointer;
} return .{
.instance = cmodule,
};
}
pub fn getLastError(self: Module) [*c]const u8 { pub fn deinit(self: Self) void {
return cnzsl.nzslModuleGetLastError(self.instance); cnzsl.nzslModuleDestroy(@ptrCast(self.instance));
} }
};
pub fn getLastError(self: Self) ![]const u8 {
const err = cnzsl.nzslModuleGetLastError(@ptrCast(self.instance)) orelse return error.NullPointer;
return std.mem.span(err);
}

View File

@@ -1,44 +0,0 @@
const cnzsl = @import("nzsl-c.zig");
const nzsl = @import("lib.zig");
const std = @import("std");
pub fn parseSource(source: []const u8) !nzsl.Module {
return parseSourceWithFilePath(source, "");
}
/// Parse a NZSL source code and stores it inside a nzslModule
/// In case of failure, a negative value is returned and an error code is set
///
/// @param module pointer to a
/// @param source pointer to NZSL source
/// @param sourceLen length of source in characters
/// @param filePath used when reporting errors
/// @param filePathLen length of filePath in characters
/// @return 0 if parsing succeeded and a negative value in case of failure
///
/// @see nzslModuleGetLastError
pub fn parseSourceWithFilePath(source: []const u8, filePath: []const u8) !nzsl.Module {
const module = nzsl.Module.create();
if(cnzsl.nzslParserParseSourceWithFilePath(module.instance, source.ptr, source.len, filePath.ptr, filePath.len) != 0) {
defer module.release();
std.log.err("Error while parsing source({s}): {s}", .{ filePath, module.getLastError() });
return error.FailedToParse;
}
return module;
}
pub fn parseFromFile(filePath: []const u8) !nzsl.Module {
const module = nzsl.Module.create();
if(cnzsl.nzslParserParseFromFile(module.instance, filePath.ptr, filePath.len) != 0) {
defer module.release();
std.log.err("Error while parsing source: {s}", .{ module.getLastError() });
return error.FailedToParse;
}
return module;
}

View File

@@ -1,55 +1,65 @@
const cnzsl = @import("nzsl-c.zig");
const nzsl = @import("lib.zig");
const std = @import("std"); const std = @import("std");
const Module = @import("Module.zig");
const BackendParameters = @import("BackendParameters.zig");
const cnzsl = @cImport({
@cInclude("CNZSL/CNZSL.h");
});
pub const SpirvWriterEnvironment = cnzsl.nzslSpirvWriterEnvironment; const Self = @This();
pub const SpirvWriter = struct { instance: *cnzsl.nzslSpirvWriter,
instance: *cnzsl.nzslSpirvWriter,
pub fn create() SpirvWriter { pub fn init() !Self {
return .{.instance = cnzsl.nzslSpirvWriterCreate() orelse unreachable}; const cwriter = cnzsl.nzslSpirvWriterCreate() orelse return error.NullPointer;
} return .{
.instance = cwriter,
};
}
pub fn release(self: SpirvWriter) void { pub fn deinit(self: Self) void {
cnzsl.nzslSpirvWriterDestroy(self.instance); cnzsl.nzslSpirvWriterDestroy(self.instance);
} }
pub fn getLastError(self: SpirvWriter) [*c]const u8 { pub fn getLastError(self: Self) ![]const u8 {
return cnzsl.nzslSpirvWriterGetLastError(self.instance); const err = cnzsl.nzslSpirvWriterGetLastError(self.instance) orelse return error.NullPointer;
} return std.mem.span(err);
}
pub fn setEnv(self: SpirvWriter, env: SpirvWriterEnvironment) void { pub fn setEnv(self: Self, env: Environment) void {
return cnzsl.nzslSpirvWriterSetEnv(self.instance, env); const SpirvEnv = extern struct {
} spv_major_version: u32,
spv_minor_version: u32,
};
const cenv: SpirvEnv = .{
.spv_major_version = @intCast(env.spv_version.major),
.spv_minor_version = @intCast(env.spv_version.minor),
};
return cnzsl.nzslSpirvWriterSetEnv(self.instance, @ptrCast(&cenv));
}
pub fn generate(self: SpirvWriter, module: nzsl.Module, states: nzsl.WriterStates) SpirvOutput { pub fn generate(self: Self, module: Module, backend_parameters: BackendParameters) !Output {
var output: ?*cnzsl.nzslSpirvOutput = null; const output = cnzsl.nzslSpirvWriterGenerate(self.instance, @ptrCast(module.instance), @ptrCast(backend_parameters.instance)) orelse return error.FailedToGenerateSpirv;
return .{
output = cnzsl.nzslSpirvWriterGenerate(self.instance, module.instance, states.instance); .instance = output,
};
if(output == null) { }
std.log.err("Failed to generate spirv output: {s}", .{ self.getLastError() });
return error.FailedToGenerateSpirv;
}
return .{.instance = output orelse unreachable};
}
pub const Environment = struct {
spv_version: std.SemanticVersion,
}; };
pub const SpirvOutput = struct { pub const Output = struct {
const InnerSelf = @This();
instance: *cnzsl.nzslSpirvOutput, instance: *cnzsl.nzslSpirvOutput,
pub fn release(self: SpirvOutput) void { pub fn deinit(self: InnerSelf) void {
cnzsl.nzslSpirvOutputDestroy(self.instance); cnzsl.nzslSpirvOutputDestroy(self.instance);
} }
pub fn getCode(self: SpirvOutput) []const u32 { pub fn getCode(self: InnerSelf) []const u32 {
var size: usize = undefined; var size: usize = undefined;
const code = cnzsl.nzslSpirvOutputGetSpirv(self.instance, &size); const code = cnzsl.nzslSpirvOutputGetSpirv(self.instance, &size);
return code[0..size]; return code[0..size];
} }
}; };

View File

@@ -1,93 +0,0 @@
const cnzsl = @import("nzsl-c.zig");
const nzsl = @import("lib.zig");
const std = @import("std");
pub fn vec(comptime T: type, comptime dim: usize) type {
return [dim]T;
}
pub const vec2bool = vec(bool, 2);
pub const vec2nzslBool = vec(cnzsl.nzslBool, 2);
pub const vec3bool = vec(bool, 3);
pub const vec3nzslBool = vec(cnzsl.nzslBool, 3);
pub const vec4bool = vec(bool, 4);
pub const vec4nzslBool = vec(cnzsl.nzslBool, 4);
pub const vec2f32 = vec(f32, 2);
pub const vec3f32 = vec(f32, 3);
pub const vec4f32 = vec(f32, 4);
pub const vec2u32 = vec(u32, 2);
pub const vec3u32 = vec(u32, 3);
pub const vec4u32 = vec(u32, 4);
pub const vec2i32 = vec(i32, 2);
pub const vec3i32 = vec(i32, 3);
pub const vec4i32 = vec(i32, 4);
pub const DebugLevel = enum(cnzsl.nzslDebugLevel) {
none = cnzsl.NZSL_DEBUG_NONE,
full = cnzsl.NZSL_DEBUG_FULL,
minimal = cnzsl.NZSL_DEBUG_MINIMAL,
regular = cnzsl.NZSL_DEBUG_REGULAR,
};
pub const OptionHash = cnzsl.nzslOptionHash;
pub fn hashOption(str: [*c]const u8) OptionHash {
return cnzsl.nzslHashOption(str);
}
pub const WriterStates = struct {
instance: *cnzsl.nzslWriterStates,
pub fn create() WriterStates {
return .{.instance = cnzsl.nzslWriterStatesCreate() orelse unreachable};
}
pub fn enableOptimization(self: WriterStates, enable: bool) void {
cnzsl.nzslWriterStatesEnableOptimization(self.instance, enable);
}
pub fn enableSanitization(self: WriterStates, enable: bool) void {
cnzsl.nzslWriterStatesEnableSanitization(self.instance, enable);
}
pub fn setDebugLevel(self: WriterStates, debugLevel: DebugLevel) void {
cnzsl.nzslWriterStatesSetDebugLevel(self.instance, @intFromEnum(debugLevel));
}
pub fn setOption(self: WriterStates, optionHash: OptionHash, value: anytype) void {
switch (@TypeOf(value)) {
inline bool => cnzsl.nzslWriterStatesSetOption_bool(self.instance, optionHash, @intFromBool(value)),
inline cnzsl.nzslBool => cnzsl.nzslWriterStatesSetOption_bool(self.instance, optionHash, value),
inline vec2bool => {
self.setOption(optionHash, vec2nzslBool{@intFromBool(value[0]), @intFromBool(value[1])});
},
inline vec2nzslBool => cnzsl.nzslWriterStatesSetOption_vec2bool(self.instance, optionHash, &value),
inline vec3bool => {
self.setOption(optionHash, vec3nzslBool{@intFromBool(value[0]), @intFromBool(value[1]), @intFromBool(value[2])});
},
inline vec3nzslBool => cnzsl.nzslWriterStatesSetOption_vec3bool(self.instance, optionHash, &value),
inline vec4bool => {
self.setOption(optionHash, vec4nzslBool{@intFromBool(value[0]), @intFromBool(value[1]), @intFromBool(value[2]), @intFromBool(value[3])});
},
inline vec4nzslBool => cnzsl.nzslWriterStatesSetOption_vec4bool(self.instance, optionHash, &value),
inline comptime_float, f32 => cnzsl.nzslWriterStatesSetOption_f32(self.instance, optionHash, value),
inline vec2f32 => cnzsl.nzslWriterStatesSetOption_vec2f32(self.instance, optionHash, &value),
inline vec3f32 => cnzsl.nzslWriterStatesSetOption_vec3f32(self.instance, optionHash, &value),
inline vec4f32 => cnzsl.nzslWriterStatesSetOption_vec4f32(self.instance, optionHash, &value),
inline i32 => cnzsl.nzslWriterStatesSetOption_i32(self.instance, optionHash, value),
inline comptime_int => {
std.log.debug("/!\\ setOption with comptime_int defaults to i32 with value {} ", .{ value });
cnzsl.nzslWriterStatesSetOption_i32(self.instance, optionHash, value);
},
inline vec2i32 => cnzsl.nzslWriterStatesSetOption_vec2i32(self.instance, optionHash, &value),
inline vec3i32 => cnzsl.nzslWriterStatesSetOption_vec3i32(self.instance, optionHash, &value),
inline vec4i32 => cnzsl.nzslWriterStatesSetOption_vec4i32(self.instance, optionHash, &value),
inline u32 => cnzsl.nzslWriterStatesSetOption_u32(self.instance, optionHash, value),
inline vec2u32 => cnzsl.nzslWriterStatesSetOption_vec2u32(self.instance, optionHash, &value),
inline vec3u32 => cnzsl.nzslWriterStatesSetOption_vec3u32(self.instance, optionHash, &value),
inline vec4u32 => cnzsl.nzslWriterStatesSetOption_vec4u32(self.instance, optionHash, &value),
else => std.debug.panic("Unsupported type {}", .{@TypeOf(value)})
}
}
pub fn release(self: WriterStates) void {
cnzsl.nzslWriterStatesDestroy(self.instance);
}
};

View File

@@ -1,11 +1,30 @@
// const cnzsl = @cImport({
// @cInclude("CNZSL/CNZSL.h");
// });
const std = @import("std"); const std = @import("std");
const cnzsl = @import("nzsl-c.zig"); const cnzsl = @cImport({
@cInclude("CNZSL/CNZSL.h");
});
pub usingnamespace @import("WriterStates.zig"); pub const ShaderStageType = enum(cnzsl.nzslShaderStageType) {
pub usingnamespace @import("GlslWriter.zig"); compute = cnzsl.NZSL_STAGE_COMPUTE,
pub usingnamespace @import("SpirvWriter.zig"); fragment = cnzsl.NZSL_STAGE_FRAGMENT,
pub usingnamespace @import("Module.zig"); vertex = cnzsl.NZSL_STAGE_VERTEX,
pub usingnamespace @import("Parser.zig"); };
pub const DebugLevel = enum(cnzsl.nzslDebugLevel) {
none = cnzsl.NZSL_DEBUG_NONE,
full = cnzsl.NZSL_DEBUG_FULL,
minimal = cnzsl.NZSL_DEBUG_MINIMAL,
regular = cnzsl.NZSL_DEBUG_REGULAR,
};
pub const OptionHash = u32;
pub fn hashOption(str: [:0]const u8) !OptionHash {
return cnzsl.nzslHashOption(str);
}
pub const BackendParameters = @import("BackendParameters.zig");
pub const GlslWriter = @import("GlslWriter.zig");
pub const LangWriter = @import("LangWriter.zig");
pub const Module = @import("Module.zig");
pub const parser = @import("parser.zig");
pub const SpirvWriter = @import("SpirvWriter.zig");

View File

@@ -1,3 +0,0 @@
pub usingnamespace @cImport({
@cInclude("CNZSL/CNZSL.h");
});

27
src/parser.zig git.filemode.normal_file
View File

@@ -0,0 +1,27 @@
const std = @import("std");
const cnzsl = @cImport({
@cInclude("CNZSL/CNZSL.h");
});
const Module = @import("Module.zig");
pub fn parseSource(source: []const u8) !Module {
return parseSourceWithFilePath(source, "");
}
pub fn parseSourceWithFilePath(source: []const u8, filePath: []const u8) !Module {
const module = try Module.init();
errdefer module.deinit();
if (cnzsl.nzslParserParseSourceWithFilePath(@ptrCast(module.instance), source.ptr, source.len, filePath.ptr, filePath.len) != 0) {
return error.FailedToParse;
}
return module;
}
pub fn parseFromFile(filePath: []const u8) !Module {
const module = try Module.init();
errdefer module.deinit();
if (cnzsl.nzslParserParseFromFile(@ptrCast(module.instance), filePath.ptr, filePath.len) != 0) {
return error.FailedToParse;
}
return module;
}