Add hot-reloading for development#4
Open
tspython wants to merge 3 commits into
Open
Conversation
Use the `notify` crate to watch the repository working directory for file changes. When modifications are detected, the app automatically refreshes the git status and redraws — no manual Ctrl+R needed. Key design decisions: - Uses winit's user-event mechanism (EventLoopProxy) for thread-safe event delivery from the watcher thread to the main event loop - 500ms debounce to avoid excessive refreshes during rapid edits - Ignores pure access events to reduce noise - Watcher automatically restarts when switching repositories - Gracefully degrades (logs warning) if watcher setup fails https://claude.ai/code/session_01MqAAWLk3jPZp2etNAfhgVZ
This reverts commit 8eaaf0c.
Two forms of hot-reloading for development: 1. **Shader hot-reload (runtime, no restart):** The app watches .wgsl files via `notify` and recreates GPU pipelines when they change. Edit text.wgsl or rect.wgsl and see rendering changes instantly while the app is running. Uses winit user events for thread-safe delivery with 300ms debounce. 2. **Code hot-reload (auto-rebuild):** `cargo dev` alias uses cargo-watch to rebuild and restart the app when Rust source files change. Install with `cargo install cargo-watch`. Shaders are now loaded from disk at runtime (with compiled-in fallback), pipeline layouts are stored for recreation, and the shader directory is auto-detected relative to the source tree. https://claude.ai/code/session_01MqAAWLk3jPZp2etNAfhgVZ
| rect_pl: &wgpu::PipelineLayout, | ||
| target_format: wgpu::TextureFormat, | ||
| shader_dir: &std::path::Path, | ||
| ) -> anyhow::Result<(wgpu::RenderPipeline, wgpu::RenderPipeline)> { |
There was a problem hiding this comment.
[🟡 Medium]
reload_shaders() is written to surface errors to the UI, but create_pipelines() cannot return an error, so the failure branch in user_event is unreachable and invalid shader edits cannot be reported as Shader reload failed as intended. This breaks the documented behavior for bad .wgsl edits and can leave the app reporting success after a failed reload attempt; make shader parsing/compilation failures explicit by validating WGSL and returning Err before replacing pipelines. ```rust
// src/app.rs
fn create_pipelines(...) -> anyhow::Result<(wgpu::RenderPipeline, wgpu::RenderPipeline)> {
...
Ok((text_pipeline, rect_pipeline))
}
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.
Summary
Two forms of hot-reloading for faster development iteration:
.wgslfiles vianotifyand recreates GPU pipelines instantly when they change. Edittext.wgslorrect.wgsland see rendering changes live while the app is running. Uses winit user events with 300ms debounce.cargo devalias (via.cargo/config.toml) usescargo-watchto automatically rebuild and restart the app when Rust source files change. Install withcargo install cargo-watch.Test plan
src/rect.wgsl(e.g. change a color), verify the UI updates instantly without restartsrc/text.wgsl, verify text rendering updates instantly.wgslfile — verify the status bar shows "Shader reload failed" and the app keeps running with the previous shaderscargo dev, edit a.rsfile — verify the app rebuilds and restarts automaticallyhttps://claude.ai/code/session_01MqAAWLk3jPZp2etNAfhgVZ