Merge pull request #87 from Avokadoen/store-hash

Expose shader hash
This commit is contained in:
Robin Voetter
2023-05-23 23:33:34 +02:00
committed by GitHub
2 changed files with 9 additions and 4 deletions

View File

@@ -52,6 +52,9 @@ pub const ShaderCompileStep = struct {
/// The path to the shader, relative to the current build root. /// The path to the shader, relative to the current build root.
source_path: []const u8, source_path: []const u8,
/// The final hash of the shader
hash: [64]u8,
/// Miscellaneous options to pass when compiling the shader. /// Miscellaneous options to pass when compiling the shader.
options: ShaderOptions, options: ShaderOptions,
}; };
@@ -115,6 +118,7 @@ pub const ShaderCompileStep = struct {
self.shaders.append(.{ self.shaders.append(.{
.name = name, .name = name,
.source_path = full_source_path, .source_path = full_source_path,
.hash = undefined,
.options = options, .options = options,
}) catch unreachable; }) catch unreachable;
} }
@@ -180,17 +184,17 @@ pub const ShaderCompileStep = struct {
); );
try cwd.makePath(shaders_dir); try cwd.makePath(shaders_dir);
for (self.shaders.items) |shader| { for (self.shaders.items) |*shader| {
const shader_basename = try self.hashShaderToFileName(shader); shader.hash = try self.hashShaderToFileName(shader.*);
const shader_out_path = try std.fs.path.join(b.allocator, &.{ const shader_out_path = try std.fs.path.join(b.allocator, &.{
shaders_dir, shaders_dir,
&shader_basename, &shader.hash,
}); });
// This path must be relative to the shaders zig file - which is in the same directory // 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", .{ try shaders_out.print("pub const {s} align(@alignOf(u32)) = @embedFile(\"{s}\").*;\n", .{
shader.name, shader.name,
&shader_basename, &shader.hash,
}); });
// If we have a cache hit, we can save some compile time by not invoking the compile command. // If we have a cache hit, we can save some compile time by not invoking the compile command.

View File

@@ -72,6 +72,7 @@ pub const GenerateStep = struct {
/// by parsing it and rendering with `std.zig.parse` and `std.zig.render` respectively. /// by parsing it and rendering with `std.zig.parse` and `std.zig.render` respectively.
fn make(step: *Build.Step, progress: *std.Progress.Node) !void { fn make(step: *Build.Step, progress: *std.Progress.Node) !void {
_ = progress; _ = progress;
const b = step.owner; const b = step.owner;
const self = @fieldParentPtr(GenerateStep, "step", step); const self = @fieldParentPtr(GenerateStep, "step", step);
const cwd = std.fs.cwd(); const cwd = std.fs.cwd();