You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ShaderCacheImpl's key describes the shader source, but the value it stores depends on the toolchain that compiled it. Nothing ties the two together, so a change that alters compiler output for unchanged GLSL silently keeps serving stale entries.
CACHE_VERSION exists to cover this, but it is hand-maintained and has been bumped twice in the cache's lifetime, both times for a format change rather than a content change:
What can change the output without changing the source
BabylonNative's own ShaderCompiler.ShaderCompiler: preserve original sampler names colliding with HLSL/MSL keywords #1796 changes the sampler name written into the bgfx blob and the UniformStages key. Because Program.cpp resolves uniforms by name (uniformStages.find(info.name) and uniformNameToIndex[info.name]), a stale entry reproduces the exact bug that PR fixes: the sampler never binds.
glslang (284e4301e5a6b44b279635276588db7cdd942624) — GLSL to SPIR-V.
bgfx, via bgfx.cmake (6c5515826c428337b7cbc0a5a7cc6d12325ce72b) — blob layout and uniform table.
That last one is not hypothetical: #1795 moved the bgfx.cmake pin and merged without touching CACHE_VERSION.
Suggested direction
Derive the version instead of hand-maintaining it. CMake already holds every dependency SHA above, so at configure time it can digest them together with a content hash of Plugins/ShaderCompiler/Source/* and the selected GRAPHICS_API, and configure_file the result into a generated header:
CACHE_VERSION then becomes that constant. Both PRs above would have invalidated automatically, with no author having to notice.
Keeping this as the whole-file version check rather than folding the digest into Hash() is deliberate: Load already discards the file cleanly on mismatch, whereas a key-based scheme leaves superseded entries in the file forever as unreachable garbage.
Tradeoffs
Over-invalidates: a comment-only edit under Plugins/ShaderCompiler/Source/ costs one full recompile. That is strictly safer than today's under-invalidation and is a one-time startup cost.
Hash file contents rather than a git SHA, so dirty working trees are covered and configure does not need git.
[Filed by Copilot on behalf of @bghgary]
Summary
ShaderCacheImpl's key describes the shader source, but the value it stores depends on the toolchain that compiled it. Nothing ties the two together, so a change that alters compiler output for unchanged GLSL silently keeps serving stale entries.CACHE_VERSIONexists to cover this, but it is hand-maintained and has been bumped twice in the cache's lifetime, both times for a format change rather than a content change:dd56a4d0(#1402)CACHE_VERSION = 1ec95b268(#1598)1 -> 2, precompiled shader supportWhat can change the output without changing the source
ShaderCompiler. ShaderCompiler: preserve original sampler names colliding with HLSL/MSL keywords #1796 changes the sampler name written into the bgfx blob and theUniformStageskey. BecauseProgram.cppresolves uniforms by name (uniformStages.find(info.name)anduniformNameToIndex[info.name]), a stale entry reproduces the exact bug that PR fixes: the sampler never binds.a512817ddbcd879a3929aef7d1d762871bdf8635) — the reserved-keyword renaming behind ShaderCompiler: preserve original sampler names colliding with HLSL/MSL keywords #1796 lives here.284e4301e5a6b44b279635276588db7cdd942624) — GLSL to SPIR-V.6c5515826c428337b7cbc0a5a7cc6d12325ce72b) — blob layout and uniform table.That last one is not hypothetical: #1795 moved the bgfx.cmake pin and merged without touching
CACHE_VERSION.Suggested direction
Derive the version instead of hand-maintaining it. CMake already holds every dependency SHA above, so at configure time it can digest them together with a content hash of
Plugins/ShaderCompiler/Source/*and the selectedGRAPHICS_API, andconfigure_filethe result into a generated header:CACHE_VERSIONthen becomes that constant. Both PRs above would have invalidated automatically, with no author having to notice.Keeping this as the whole-file version check rather than folding the digest into
Hash()is deliberate:Loadalready discards the file cleanly on mismatch, whereas a key-based scheme leaves superseded entries in the file forever as unreachable garbage.Tradeoffs
Plugins/ShaderCompiler/Source/costs one full recompile. That is strictly safer than today's under-invalidation and is a one-time startup cost.Note
#1796 should still bump
CACHE_VERSIONby hand; this issue is the follow-up so the next change does not depend on someone noticing.