From e2268a7eb4a72f8097dcdb2b185f8ebc2cfc8974 Mon Sep 17 00:00:00 2001 From: ashpil Date: Wed, 29 Dec 2021 21:45:12 +0300 Subject: [PATCH 1/2] makes shader build comment output directory user-specifiable --- build.zig | 2 +- generator/build_integration.zig | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/build.zig b/build.zig index b8ad6db..7823249 100644 --- a/build.zig +++ b/build.zig @@ -21,7 +21,7 @@ pub const ResourceGenStep = struct { self.* = .{ .step = Step.init(.custom, "resources", builder.allocator, make), - .shader_step = vkgen.ShaderCompileStep.init(builder, &[_][]const u8{ "glslc", "--target-env=vulkan1.2" }), + .shader_step = vkgen.ShaderCompileStep.init(builder, &[_][]const u8{ "glslc", "--target-env=vulkan1.2" }, "shaders"), .builder = builder, .package = .{ .name = "resources", diff --git a/generator/build_integration.zig b/generator/build_integration.zig index 8423709..1220a95 100644 --- a/generator/build_integration.zig +++ b/generator/build_integration.zig @@ -22,16 +22,20 @@ pub const ShaderCompileStep = struct { /// The command and optional arguments used to invoke the shader compiler. glslc_cmd: []const []const u8, + /// The directory within `zig-cache/` that the compiled shaders are placed in. + output_dir: []const u8, + /// List of shaders that are to be compiled. shaders: std.ArrayList(Shader), /// Create a ShaderCompilerStep for `builder`. When this step is invoked by the build /// system, ` -o ` is invoked for each shader. - pub fn init(builder: *Builder, glslc_cmd: []const []const u8) *ShaderCompileStep { + pub fn init(builder: *Builder, glslc_cmd: []const []const u8, output_dir: []const u8) *ShaderCompileStep { const self = builder.allocator.create(ShaderCompileStep) catch unreachable; self.* = .{ .step = Step.init(.custom, "shader-compile", builder.allocator, make), .builder = builder, + .output_dir = output_dir, .glslc_cmd = builder.dupeStrings(glslc_cmd), .shaders = std.ArrayList(Shader).init(builder.allocator), }; @@ -46,7 +50,7 @@ pub const ShaderCompileStep = struct { const full_out_path = path.join(self.builder.allocator, &[_][]const u8{ self.builder.build_root, self.builder.cache_root, - "shaders", + self.output_dir, src, }) catch unreachable; self.shaders.append(.{ .source_path = src, .full_out_path = full_out_path }) catch unreachable; From 809537f53637443102507b651ddf9079d1adb44a Mon Sep 17 00:00:00 2001 From: ashpil Date: Wed, 29 Dec 2021 21:49:52 +0300 Subject: [PATCH 2/2] appends .spv to glslc compiled filename --- generator/build_integration.zig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/generator/build_integration.zig b/generator/build_integration.zig index 1220a95..f6038c9 100644 --- a/generator/build_integration.zig +++ b/generator/build_integration.zig @@ -47,11 +47,12 @@ pub const ShaderCompileStep = struct { /// This path can then be used to include the binary into an executable, for example by passing it /// to @embedFile via an additional generated file. pub fn add(self: *ShaderCompileStep, src: []const u8) []const u8 { + const output_filename = std.fmt.allocPrint(self.builder.allocator, "{s}.spv", .{ src }) catch unreachable; const full_out_path = path.join(self.builder.allocator, &[_][]const u8{ self.builder.build_root, self.builder.cache_root, self.output_dir, - src, + output_filename, }) catch unreachable; self.shaders.append(.{ .source_path = src, .full_out_path = full_out_path }) catch unreachable; return full_out_path;