Skip to content

Add hot-reloading for development#4

Open
tspython wants to merge 3 commits into
masterfrom
claude/implement-hot-reloading-kWNEA
Open

Add hot-reloading for development#4
tspython wants to merge 3 commits into
masterfrom
claude/implement-hot-reloading-kWNEA

Conversation

@tspython
Copy link
Copy Markdown
Owner

@tspython tspython commented Mar 25, 2026

Summary

Two forms of hot-reloading for faster development iteration:

  • Shader hot-reload (runtime, no restart): The app watches .wgsl files via notify and recreates GPU pipelines instantly when they change. Edit text.wgsl or rect.wgsl and see rendering changes live while the app is running. Uses winit user events with 300ms debounce.
  • Code hot-reload (auto-rebuild): cargo dev alias (via .cargo/config.toml) uses cargo-watch to automatically 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 for release builds), pipeline layouts are stored for recreation, and the shader directory is auto-detected relative to the source tree.

Test plan

  • All 26 existing tests pass
  • Run the app, edit src/rect.wgsl (e.g. change a color), verify the UI updates instantly without restart
  • Run the app, edit src/text.wgsl, verify text rendering updates instantly
  • Save an invalid .wgsl file — verify the status bar shows "Shader reload failed" and the app keeps running with the previous shaders
  • Run cargo dev, edit a .rs file — verify the app rebuilds and restarts automatically
  • Build a release binary and run it outside the source tree — verify it still works using compiled-in shader fallback

https://claude.ai/code/session_01MqAAWLk3jPZp2etNAfhgVZ

claude added 3 commits March 25, 2026 03:12
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
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
@tspython tspython changed the title Add hot reloading via file system watching Add hot-reloading for development Mar 25, 2026
Copy link
Copy Markdown

@capy-ai capy-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added 1 comment

Comment thread src/app.rs
rect_pl: &wgpu::PipelineLayout,
target_format: wgpu::TextureFormat,
shader_dir: &std::path::Path,
) -> anyhow::Result<(wgpu::RenderPipeline, wgpu::RenderPipeline)> {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[🟡 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))
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants