Resolves #include directives in GLSL shader source. More...
#include <PhosphorShaders/ShaderIncludeResolver.h>
Static Public Member Functions | |
| static QString | expandIncludes (const QString &source, const QString ¤tFileDir, const QStringList &includePaths, QString *outError=nullptr, QStringList *outIncludedPaths=nullptr, QStringList *outSourcePaths=nullptr) |
Expand #include directives in source. | |
Static Public Attributes | |
| static constexpr int | MaxIncludeDepth = 10 |
| static constexpr qint64 | MaxIncludeBytes = 1 << 20 |
| Largest include file, in bytes. | |
| static constexpr qsizetype | MaxExpandedSize = 16 << 20 |
| Largest expanded source, in UTF-16 code units. | |
| static constexpr const char * | GeneratedPreambleInclude = "p_generated.glsl" |
| Reserved include name for the generated p_<id> autocomplete sidecar (plasmazones-shader-validate --emit-preamble). | |
Resolves #include directives in GLSL shader source.
Supports:
An include name is always relative to a search directory: an absolute name is an error. Shader packs can come from third parties, and an absolute name would let one inline any readable file on the system.
|
static |
Expand #include directives in source.
Each inlined include is bracketed by PhosphorShaders::lineDirective re-anchors. A re-anchor of that shape that source already carries for its own source string, such as the one assembleEntryPoint emits after a family prologue, is honoured: the parent's re-anchor after a later include counts from it rather than from the top of the text.
| source | Raw shader source (may contain #include "..." or #include <...>) |
| currentFileDir | Directory of the file that contains source |
| includePaths | Directories to search for includes |
| outError | If non-null, set on error (file not found, absolute name, depth or size exceeded) |
| outIncludedPaths | If non-null, appended with the canonical absolute path of every successfully-resolved include file. Lets callers fingerprint transitively-included headers (e.g. for cache invalidation) — without this, a cache keyed only on the top-level shader's mtime serves stale baked SPIR-V when an included header changes. |
| outSourcePaths | If non-null, populated as a GLSL source-string legend: element i is the path of source-string number i as referenced by the #line <n> <i> directives this resolver emits around each inlined include. Index 0 is the top-level source — left empty because the resolver is handed only the source text and its directory, not the top-level file's path, so the caller (which knows which file it asked to expand) fills index 0. Consumers map a glslang / driver diagnostic of the form <i>:<line> back to <path>:<line>. |
|
staticconstexpr |
Reserved include name for the generated p_<id> autocomplete sidecar (plasmazones-shader-validate --emit-preamble).
An #include of a file with this basename is skipped (treated as a no-op) during expansion: the real param preamble is spliced at load, so the sidecar is an editor-only aid that must neither resolve nor error at runtime. Lets an author keep #include "p_generated.glsl" in the frag for glslls autocomplete while shipping it unchanged, with or without the sidecar present.
|
staticconstexpr |
Largest expanded source, in UTF-16 code units.
One file may include another several times at each of the MaxIncludeDepth levels, so the depth and the per-file limit alone do not bound the output.
|
staticconstexpr |
Largest include file, in bytes.
A bigger file is an error, not a truncated read.
|
staticconstexpr |