Repository navigation
Shader hot reload for debug builds - #224
Merged
Merged
Conversation
2 of 8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
In Debug builds, saving a shader while the game runs recompiles it and swaps it into the running renderer, on all four backends. Release builds compile none of it.
Core/FileWatcher(public): a generic, non-blocking watcher (inotify on Linux,ReadDirectoryChangesWon Windows). It only reports saved files, so later reloads (the Rust gameplay library, assets) can reuse it.Debug/ShaderHotReload(public): watches registered shader folders and waits 150 ms after the last change so editors finish writing. It compiles changed GLSL with glslc (temp file, then an atomic rename, so the old.spvsurvives a failed compile) and copies the result intoassets/shaders. Then it calls the newRenderer::ReloadShaders(stems). Folders registered later override earlier ones, matching how the build copies assets. It warns about an edit that will have no effect: a file overridden by a later folder, or a variant for another backend.OpenGLShader::compile(), which leaked the previous program and set it to 0 when linking failed..hlsland rebuilds its input layout. Shaders compiled from the same files compile once and share the result. If either stage or the layout fails, the old ones stay. It also reloads the tonemap shaders, and fixes two leaks inCreateShader: the shader object when compiling fails, and an extra input-layout reference for every shader after the first._dx12.hlsl, and swaps each one's bytecode and PSO only once the new PSO exists. It also rebuilds the shadow, skybox and debug-line PSOs, and refreshes the default PSO. Replaced PSOs that nothing uses any more are removed from the pipeline cache, so it doesn't grow on every save.Why
Iterating on shaders meant a rebuild and restart for every change. This is step one of the hot reload plan; the Rust gameplay library reload builds on the same watcher.
Follow-ups: #218, #219, #220, #221, #222, #223.
How it was verified
SLEAK_HOT_RELOADundefined, which is what Release compiles)SLEAK_HOT_RELOADboth on and off, and the Windows CI jobs here are the first real MSVC build. DX11/DX12 reload and the Windows file watcher still need a manual test on Windows.--validate: a normal edit, a syntax error (logged, old shader kept), the fix, engine and game shaders, an overridden file, and two passes at once all behaved as expected with zero validation errorsChecklist
///commentssrc/orinclude/private/in public headers