From 9bb8e7b1f7098d8efb62b3390aa027dd211eb225 Mon Sep 17 00:00:00 2001 From: avokadoen Date: Tue, 23 May 2023 21:12:21 +0200 Subject: [PATCH] expose shader hash in Shader struct --- generator/build_integration.zig | 12 ++++++++---- generator/vulkan/build_integration.zig | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/generator/build_integration.zig b/generator/build_integration.zig index 382a6c8..b796f37 100644 --- a/generator/build_integration.zig +++ b/generator/build_integration.zig @@ -52,6 +52,9 @@ pub const ShaderCompileStep = struct { /// The path to the shader, relative to the current build root. source_path: []const u8, + /// The final hash of the shader + hash: [64]u8, + /// Miscellaneous options to pass when compiling the shader. options: ShaderOptions, }; @@ -115,6 +118,7 @@ pub const ShaderCompileStep = struct { self.shaders.append(.{ .name = name, .source_path = full_source_path, + .hash = undefined, .options = options, }) catch unreachable; } @@ -180,17 +184,17 @@ pub const ShaderCompileStep = struct { ); try cwd.makePath(shaders_dir); - for (self.shaders.items) |shader| { - const shader_basename = try self.hashShaderToFileName(shader); + for (self.shaders.items) |*shader| { + shader.hash = try self.hashShaderToFileName(shader.*); const shader_out_path = try std.fs.path.join(b.allocator, &.{ shaders_dir, - &shader_basename, + &shader.hash, }); // This path must be relative to the shaders zig file - which is in the same directory try shaders_out.print("pub const {s} align(@alignOf(u32)) = @embedFile(\"{s}\").*;\n", .{ shader.name, - &shader_basename, + &shader.hash, }); // If we have a cache hit, we can save some compile time by not invoking the compile command. diff --git a/generator/vulkan/build_integration.zig b/generator/vulkan/build_integration.zig index 74eb754..61b0d1a 100644 --- a/generator/vulkan/build_integration.zig +++ b/generator/vulkan/build_integration.zig @@ -72,6 +72,7 @@ pub const GenerateStep = struct { /// by parsing it and rendering with `std.zig.parse` and `std.zig.render` respectively. fn make(step: *Build.Step, progress: *std.Progress.Node) !void { _ = progress; + const b = step.owner; const self = @fieldParentPtr(GenerateStep, "step", step); const cwd = std.fs.cwd();