Repository navigation
fix(rendering): key the shader cache per adapter - #4496
Conversation
Key the wgpu pipeline cache by adapter and drop a blob this device rejects, so a cache written by another GPU cannot invalidate the composite pipeline.
|
@kyzer1023 is attempting to deploy a commit to the Cap Software Inc Team on Vercel. A member of the Team first needs to authorize it. |
| let stored = std::fs::read(&path).unwrap_or_default(); | ||
| assert_ne!(stored, foreign_header()); |
There was a problem hiding this comment.
Missing cache files pass tests
The recovery test passes even if save_pipeline_cache never writes anything. Once the foreign cache is removed, unwrap_or_default() turns the missing file into empty bytes, which passes assert_ne!. The corrupt-cache case only checks drawing. Require the file to exist after both cases, then reload its contents to check that recovery saved a usable cache. This would catch changes that silently stop cache reuse.
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/rendering/src/composite_frame.rs
Line: 382-383
Comment:
**Missing cache files pass tests**
The recovery test passes even if `save_pipeline_cache` never writes anything. Once the foreign cache is removed, `unwrap_or_default()` turns the missing file into empty bytes, which passes `assert_ne!`. The corrupt-cache case only checks drawing. Require the file to exist after both cases, then reload its contents to check that recovery saved a usable cache. This would catch changes that silently stop cache reuse.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Fixed in ee1b2b9a. Both recovery cases now assert std::fs::read succeeds with non-empty bytes that differ from the rejected foreign/corrupt blob, then reload that saved file through CompositeVideoFramePipeline::new, draw a frame, and check that reload logs neither a cache rejection nor an uncaptured wgpu error while keeping the cache file on disk (when the adapter exposes Features::PIPELINE_CACHE).
The recovery test now reads the cache file after a foreign blob and a corrupt blob, then loads those bytes again and draws.
|
@greptileai review |
Why
CompositeVideoFramePipelinestored one sharedshader_cache.binfor every GPU adapter. On a dual-GPU system (for example a laptop switching between NVIDIA and Intel Vulkan ICDs), wgpu rejects a cache blob created for another device, andfallback: truedoes not cover that mismatch—leaving the composite pipeline invalid with"Pipeline cache validation failed: The cache data was created for a different device"and subsequentDevice::pollpanics.What changed
crates/rendering/src/composite_frame.rsonly.wgpu::util::pipeline_cache_keywith vendor and device IDs read from the live Vulkan physical device (wgpu_pipeline_cache_vulkan_<vendor>_<device>.bin).shader_cache.binunread so existing poisoned installs start clean. Metal and DX12 do not enablePIPELINE_CACHEin this repo and continue to skip caching.shader_cache_testsincrates/rendering/src/composite_frame.rscovering foreign-header and corrupt-blob recovery.Verification
cargo test -p cap-rendering --lib shader_cache_tests -- --test-threads=1passed (2/2). Before the fix, a foreign header rendered clear color[0, 0, 0, 0]with the device-mismatch error; after the fix, both foreign-header and corrupt-blob tests render[255, 0, 0, 255], replace the bad file, and log zero uncaptured wgpu errors.0x10de/0x1d10+ Intel UHD Graphics 6200x8086/0x5917, opening a 15 s 1920×1080.capin the GPUI editor):60.0 fps,total_skipped=0); createdwgpu_pipeline_cache_vulkan_4318_7440.bin(61,566 bytes); legacyshader_cache.binuntouched; zero wgpu/poll errors.shader_cache.binpresent): Rendered 537 frames (59.8 fps,total_skipped=0); createdwgpu_pipeline_cache_vulkan_32902_22807.bin(185,856 bytes) alongside unchanged MX150 cache; legacyshader_cache.binignored; zeroDevice::pollpanics or uncaptured wgpu errors.wgpu_pipeline_cache_vulkan_32902_22807.bindirectly with the MX150 blob and reopened the editor on Intel UHD 620 -> loggedWARN shader cache rejected for this adapter; starting a new one, rendered 538 frames (59.9 fps,total_skipped=0), zeroDevice::pollpanics or uncaptured errors, and replaced the file with a fresh valid Intel cache (55,536 bytes).

Confidence Score: 5/5
The PR appears safe to merge; no blocking issues were found.Summary
Keys the shader cache by the active Vulkan adapter and retries with an empty cache when saved bytes are rejected.
The previous test finding is fixed. No new actionable issues were found.
Reviews (3) · Last reviewed commit: "Merge branch 'main' into fix/shader-cach..." · Reviewed by Greptile