A depfile lists the HLSL files your build should watch for changes, including nested headers.
dotnet tool install -g RecursiveAI.OneShader.ToolRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
oneshader -T cs_6_0 -I include fill.hlsl \ -Fo fill.spv --depfile fill.d
Unzip the example, then dotnet run.
Run the command with fill.hlsl and the include/ directory shown below and supplied in the zip. It writes fill.spv and a Make-style rule in fill.d without printing anything on success. The rule lists the input files by their full paths.
fill.hlsl
#include <value.hlsli> RWStructuredBuffer<uint> Output : register(u0); [numthreads(1, 1, 1)] void main() { Output[0] = VALUE; }
include/value.hlsli
#include "base.hlsli" #define VALUE (BASE_VALUE + 1u)
include/base.hlsli
#define BASE_VALUE 41uThe full program
The zip restores the tool version in its manifest and invokes the same CLI. It strips the current directory prefix only when printing the rule; the depfile on disk keeps the compiler’s paths. You don’t need the global install for the zip.
using System.Diagnostics; RunDotnet("tool", "restore"); RunDotnet("oneshader", "-T", "cs_6_0", "-I", "include", "fill.hlsl", "-Fo", "fill.spv", "--depfile", "fill.d"); // Shorten local paths for display only; leave the depfile intact for Make. string prefix = Path.GetFullPath(".").Replace('\\', '/') + "/"; string rule = File.ReadAllText("fill.d"); Console.Write(rule.Replace(prefix.Replace("$", "$$").Replace("#", "\\#") .Replace(" ", "\\ "), "", StringComparison.Ordinal)); static void RunDotnet(params string[] args) { var command = new ProcessStartInfo("dotnet"); foreach (string arg in args) command.ArgumentList.Add(arg); using var process = Process.Start(command)!; process.WaitForExit(); if (process.ExitCode != 0) throw new InvalidOperationException($"dotnet {args[0]} exited with {process.ExitCode}."); }
After the tool restore messages, it prints:
fill.spv: fill.hlsl include/base.hlsli include/value.hlsliIf an included file can’t be found, the compile fails and no new depfile is written; don’t reuse an old one as if the compile succeeded.
Variations
Use a space in the output filename. Quote the path at the shell; the compiler escapes the space for Make.
oneshader -T cs_6_0 -I include fill.hlsl \ -Fo "fill test.spv" --depfile "fill test.d"
The new rule starts with fill\ test.spv:.
Related recipes
The short answer
Pass --depfile fill.d on the same command that compiles fill.hlsl. The compiler writes a rule with the compiled output on the left and the files it read on the right. Give that rule to your build system so it can recompile just the shaders that depend on an edited header.
Does the depfile include nested headers?
#include inserts the contents of another file into the shader source. In this example, -I include tells OneShader where to look for value.hlsli. That file includes base.hlsli, so an edit to the base file can change the shader even when fill.hlsl hasn’t changed. The generated rule includes both headers; it doesn’t stop at the first level. The command-line documentation also notes that the depfile escapes spaces, #, and $ for Make.
How do you make a shader recompile when an included file changes?
Include the generated file in your Makefile. With GNU Make 4.3 or newer, use &: to tell Make that one command creates both outputs. Start with dotnet tool restore in the unzipped folder to make the local dotnet oneshader command available. Keep the tab before the recipe command.
.DEFAULT_GOAL := fill.spv -include fill.d fill.spv fill.d &: fill.hlsl dotnet oneshader -T cs_6_0 -I include fill.hlsl \ -Fo fill.spv --depfile fill.d
Run make once to create both files. A second run without edits leaves the shader up to date. Edit include/base.hlsli and Make runs the compile again, even though fill.hlsl hasn’t changed. Keep fill.hlsl in the explicit rule so the first build works before the generated rule exists. If you change compiler flags in the Makefile, add the Makefile as a prerequisite too: the depfile only lists files the shader compiler read.