Skip to main content

Module slang_source

Module slang_source 

Source
Expand description

Source assembly for the single-source .slang engine shaders.

Every consumer that compiles one of src/shaders/*.slang assembles the same text the same way: the file’s body, its {...} fragment markers replaced, and the program’s variant defines injected ahead of it. Both the fragments and the defines ride the text rather than an include path or a command line, so the backends’ content-addressed shader cache keys them – which is what keeps two pool sizes, two Hi-Z variants, or two revisions of a shared helper from ever sharing an artifact.

It lives here, below the device backends, because the assembly is what they and the build script have to agree on: a build script’s precompile and a renderer’s runtime compile must produce byte-identical source for the content-addressed cache to be sound across them. Keeping one implementation is what makes that true by construction rather than by review.

Reading a shader off disk is not part of it. Hot-reload wants the checkout’s copy to win over the embedded one, and that is a std filesystem concern in a no_std crate – so assemble_with takes a resolver and the device crate supplies the one that reads disk first.

Constants§

FRAGMENTS
The shared fragments, as (marker, file). A shader carrying a marker has the named file’s text spliced in at that point.

Functions§

assemble
The exact source text a program compiles, from the embedded shaders alone. file names the .slang under src/shaders/.
assemble_with
The same assembly against a caller-supplied resolver, which is how the device crate lets a hot-reload build prefer the checkout’s copy of a shader (and of every fragment it splices) over the embedded one. A resolver that returns None falls back to the embedded text, so a missing file loses the edit rather than the shader.
inject_defines
Prepend a #define line per (name, value) pair. The defines become part of the source text on purpose: the shader cache keys on the assembled source, so two pool sizes can never share an artifact.
source_digest
Digest of one assembled source text, identifying the artifact a build script compiled from it.