Static utility for GLSL → SPIR-V compilation with include resolution and caching.
More...
|
| static Result | compile (const QByteArray &source, QShader::Stage stage) |
| | Compile GLSL source to QShader (SPIR-V 1.0 + GLSL 330 + ES 300/310/320).
|
| static Result | compileFromFile (const QString &path, const QStringList &includePaths) |
| | Load shader from file, expand #include directives, then compile.
|
| static QString | loadAndExpand (const QString &path, const QStringList &includePaths, QString *outError=nullptr, QStringList *outIncludedPaths=nullptr) |
| | Load a shader file and expand #include directives without compiling.
|
| static QString | expandSource (const QString &source, const QString ¤tFileDir, const QStringList &includePaths, QString *outError=nullptr, QStringList *outIncludedPaths=nullptr) |
| | Expand #include directives in already-read source, without touching the filesystem for the top-level text.
|
| static void | clearCache () |
| | Clear the in-memory compilation cache (e.g.
|
| static const QList< QShaderBaker::GeneratedShader > & | bakeTargets () |
| | Bake target list: SPIR-V 1.0, GLSL 330, GLSL ES 300/310/320.
|
Static utility for GLSL → SPIR-V compilation with include resolution and caching.
Compilation results are cached by source hash to avoid redundant QShaderBaker invocations. Those two caches (source-hash and filename+mtime) are in-memory, but they sit in front of a content-addressed ON-DISK cache of serialized QShaders under GenericCacheLocation, keyed by Qt version, which the disk read consults BEFORE taking the bake lock. So a compile result normally survives a process restart. The disk cache is pruned once per process, on the first write, when it exceeds 512 entries and then down to about 90% of that, so a long-lived daemon is not capped within its own lifetime. Set PHOSPHOR_DISABLE_SHADER_DISK_CACHE to opt out.
- Thread-safety
- All methods are safe to call from any thread. An in-memory cache read takes only a short cache mutex, never the bake mutex; the disk read takes neither. Cache misses serialize on an internal bake mutex — QShaderBaker (glslang) is not reentrant, and concurrent bake() calls crash inside QSpirvCompiler::compileToSpirv(), so the mutex is load-bearing and must not be removed. loadAndExpand() is pure I/O and runs concurrently.
| QString PhosphorRendering::ShaderCompiler::expandSource |
( |
const QString & | source, |
|
|
const QString & | currentFileDir, |
|
|
const QStringList & | includePaths, |
|
|
QString * | outError = nullptr, |
|
|
QStringList * | outIncludedPaths = nullptr ) |
|
static |
Expand #include directives in already-read source, without touching the filesystem for the top-level text.
Shares its search-path policy with loadAndExpand (currentFileDir searched first, then includePaths), so a caller that must transform the raw source before expansion — e.g. the T1.4 entry-point harness, which prepends a #version/include scaffold to an entry-only pack — gets byte-identical expansion to the load-from-path path.
- Parameters
-
| source | Raw (already-read) GLSL, possibly harness-assembled |
| currentFileDir | Directory of the top-level shader, searched first |
| includePaths | Additional #include search directories |
| outError | If non-null, set on error |
| outIncludedPaths | If non-null, appended with each included header's canonical path (same fingerprint contract as loadAndExpand) |
- Returns
- Expanded GLSL source, or empty string on error