Migrate GLSL to Slang, text shader
This commit is contained in:
40
build.zig
40
build.zig
@@ -73,30 +73,36 @@ pub fn build(b: *std.Build) !void {
|
||||
run_step.dependOn(&run_cmd.step);
|
||||
}
|
||||
|
||||
fn isShaderExtension(extension: []const u8) bool {
|
||||
return std.mem.eql(u8, extension, ".vert") or
|
||||
std.mem.eql(u8, extension, ".frag") or
|
||||
std.mem.eql(u8, extension, ".comp");
|
||||
}
|
||||
|
||||
fn addShaders(b: *std.Build, exe_mod: *std.Build.Module) !void {
|
||||
var dir = try b.build_root.handle.openDir(b.graph.io, "assets/shaders", .{ .iterate = true });
|
||||
defer dir.close(b.graph.io);
|
||||
|
||||
var walker = try dir.walk(b.allocator);
|
||||
defer walker.deinit();
|
||||
var it = dir.iterateAssumeFirstIteration();
|
||||
|
||||
while (try walker.next(b.graph.io)) |entry| {
|
||||
while (try it.next(b.graph.io)) |entry| {
|
||||
if (entry.kind != .file) continue;
|
||||
if (!isShaderExtension(std.fs.path.extension(entry.path))) continue;
|
||||
|
||||
const glslc = b.addSystemCommand(&.{ "glslc", "-g", "--target-env=vulkan1.2" });
|
||||
glslc.addFileArg(b.path(b.pathJoin(&.{ "assets/shaders", entry.path })));
|
||||
glslc.addArg("-o");
|
||||
const spv = glslc.addOutputFileArg(b.fmt("{s}.spv", .{entry.basename}));
|
||||
glslc.addArgs(&.{ "-MD", "-MF" });
|
||||
_ = glslc.addDepFileOutputArg(b.fmt("{s}.d", .{entry.basename}));
|
||||
const stem = std.fs.path.stem(entry.name);
|
||||
const extension = std.fs.path.extension(entry.name);
|
||||
if (!std.mem.eql(u8, extension, ".slang")) continue;
|
||||
|
||||
exe_mod.addAnonymousImport(b.fmt("shaders/{s}", .{entry.path}), .{ .root_source_file = spv });
|
||||
const slangc = b.addSystemCommand(&.{
|
||||
"slangc",
|
||||
"-g",
|
||||
"-target",
|
||||
"spirv",
|
||||
"-fvk-use-scalar-layout",
|
||||
"-matrix-layout-column-major",
|
||||
});
|
||||
|
||||
slangc.addArg("-o");
|
||||
const spv = slangc.addOutputFileArg(b.fmt("{s}.spv", .{stem}));
|
||||
|
||||
slangc.addArg("-depfile");
|
||||
_ = slangc.addDepFileOutputArg(b.fmt("{s}.d", .{stem}));
|
||||
|
||||
slangc.addFileArg(b.path(b.pathJoin(&.{ "assets/shaders", entry.name })));
|
||||
|
||||
exe_mod.addAnonymousImport(b.fmt("shaders/{s}", .{stem}), .{ .root_source_file = spv });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user