// SPDX-License-Identifier: LGPL-3.0-only // SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts® export module Crafter.Build:Shader; import std; namespace fs = std::filesystem; namespace Crafter { export enum class ShaderType { Vertex, TessControl, TessEvaluation, Geometry, Fragment, Compute, RayGen, Intersect, AnyHit, ClosestHit, Miss, Callable, Task, Mesh, }; export class Shader { public: fs::path path; std::string entrypoint; ShaderType type; // Preprocessor macros for this compile, spelled like the compiler's -D: // "NAME" (defined to 1) or "NAME=VALUE". They are placed ahead of the // source, so one file can be registered more than once and take a // different #ifdef branch each time. Note the spelling differs from // Configuration::defines, which is a list of {name, value} pairs. std::vector defines; // Names the output when one source is compiled more than once: empty // gives ".spv", "sets" gives ".sets.spv". One file-name // component: no path separators. Every entry of a configuration must // end up with its own OutputName(); Build() fails if two collide, so // each extra compile of a source needs its own variant. std::string variant; Shader(fs::path&& path, std::string&& entrypoint, ShaderType type); // File name of the compiled SPIR-V, relative to the output directory. // The single source of truth for it: Check, Compile and the artifact // forwarding in Build() all go through here. fs::path OutputName() const; // Whether the output in `outputDir` is up to date: newer than the // source and than every file the source #included, and compiled with // this entry's stage, entry point and defines, searching // `includeDirs`. Compile records the last two in `buildDir`; without // its record an output is stale. bool Check(const fs::path& outputDir, const fs::path& buildDir, std::span includeDirs) const; // Compiles into `outputDir`, searching `includeDirs` for #include, and // records what Check needs in `buildDir`: a depfile naming the source // and every file it included, and the settings it was compiled with. // Returns an error message, empty on success. std::string Compile(const fs::path& outputDir, const fs::path& buildDir, std::span includeDirs) const; }; }