Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions _release-content/migration-guides/async_shader_loading.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
title: "Asynchronous `ShaderModule` loading"
pull_requests: [25352]
---

Because getting shader compilation info needs to be asynchronous on wasm and can't be blocking,
`ShaderCache` no longer loads and stores `wgpu::ShaderModule` now, which is moved to inside `PipelineCache`.

Changes:

- `PipelineCache::block_on_render_pipeline` is not available on `wasm32` now.
- `ShaderCache` no longer has `ShaderModule` and `RenderDevice` generic parameters.
- `ShaderCache::get` is changed to return processed shader source code instead of `wgpu::ShaderModule`.
5 changes: 5 additions & 0 deletions crates/bevy_core_pipeline/src/upscaling/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ fn clear_view_upscaling_pipelines(

fn prepare_view_upscaling_pipelines(
mut commands: Commands,
#[cfg_attr(
target_arch = "wasm32",
expect(unused_mut, reason = "`block_on_render_pipeline` is unused on wasm32")
)]
mut pipeline_cache: ResMut<PipelineCache>,
mut pipelines: ResMut<SpecializedRenderPipelines<BlitPipeline>>,
blit_pipeline: Res<BlitPipeline>,
Expand Down Expand Up @@ -98,6 +102,7 @@ fn prepare_view_upscaling_pipelines(

// Ensure the pipeline is loaded before continuing the frame to prevent frames without
// any GPU work submitted
#[cfg(not(target_arch = "wasm32"))]
pipeline_cache.block_on_render_pipeline(pipeline);

commands
Expand Down
7 changes: 7 additions & 0 deletions crates/bevy_render/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ image = { version = "0.25.2", default-features = false }
# When the 'atomics' feature is enabled `fragile-send-sync-non-atomic` does nothing
# and Bevy instead wraps `wgpu` types to verify they are not used off their origin thread.
wgpu = { version = "30", default-features = false, features = [
# `std` is required: wgpu's error scopes are tracked per-thread via
# `std::thread::ThreadId`. Without this feature wgpu falls back to a no_std
# stub where all threads share a single (global) error-scope stack, which
# panics with "Mismatched pop_error_scope call" when pipelines are compiled
# concurrently on multiple threads (async pipeline compilation).
"std",
"wgsl",
"dx12",
"metal",
Expand Down Expand Up @@ -116,6 +122,7 @@ bitflags = "2"
itertools = "0.14"
weak-table = "0.3"
tracing = "0.1"
async-lock = { version = "3.0", default-features = false }

[dev-dependencies]
proptest = "1"
Expand Down
Loading