simvx.graphics.materials.shader_compiler

GLSL to SPIR-V compilation via glslc, with include resolution and optional reflection.

Module Contents

Functions

resolve_includes

Recursively resolve #include "file.glsl" directives in GLSL source.

compile_shader

Compile a GLSL file to SPIR-V using glslc. Returns the output path.

Data

API

simvx.graphics.materials.shader_compiler.__all__

[‘compile_shader’, ‘resolve_includes’]

simvx.graphics.materials.shader_compiler.log

‘getLogger(…)’

simvx.graphics.materials.shader_compiler.resolve_includes(source: str, base_dir: pathlib.Path, _seen: set[str] | None = None) str[source]

Recursively resolve #include "file.glsl" directives in GLSL source.

Args: source: GLSL source text. base_dir: Directory to resolve relative include paths against. _seen: Internal set tracking already-included files to prevent cycles.

Returns: Processed GLSL source with all includes inlined.

Raises: FileNotFoundError: If an included file does not exist. RuntimeError: If a circular include is detected.

simvx.graphics.materials.shader_compiler.compile_shader(src: pathlib.Path, out: pathlib.Path | None = None, *, force: bool = False, defines: tuple[str, ...] = ()) pathlib.Path[source]

Compile a GLSL file to SPIR-V using glslc. Returns the output path.

Skips recompilation when the cached .spv is newer than the source and all its #include dependencies. Pass force=True to always recompile.

Args: src: Path to the GLSL source file. out: Optional output path for the SPIR-V binary. Defaults to src.spv (or src.<define>.spv when defines is non-empty, so a macro variant never clobbers the base permutation’s cache). Valued defines keep their value in the suffix (NAME=4.NAME_4.spv) so two values of one macro never alias. force: Always recompile, ignoring the cache. defines: Preprocessor macros (NAME or NAME=VALUE) passed to glslc as -D flags. Used for compile-time shader permutations (e.g. the thin G-buffer GBUFFER variant of the uber fragment shader).

Returns: Path to the compiled SPIR-V file.

Raises: RuntimeError: If glslc compilation fails, with annotated error details.