diff --git a/crates/bevy_render/Cargo.toml b/crates/bevy_render/Cargo.toml index 448c11f204..7730cf4217 100644 --- a/crates/bevy_render/Cargo.toml +++ b/crates/bevy_render/Cargo.toml @@ -9,6 +9,18 @@ license = "MIT OR Apache-2.0" keywords = ["bevy"] [features] +# Bevy users should _never_ turn this feature on. +# +# Bevy/wgpu developers can turn this feature on to test a newer version of wgpu without needing to also update naga_oil. +# +# When turning this feature on, you can add the following to bevy/Cargo.toml (not this file), and then run `cargo update`: +# [patch.crates-io] +# wgpu = { git = "https://github.com/gfx-rs/wgpu", rev = "..." } +# wgpu-core = { git = "https://github.com/gfx-rs/wgpu", rev = "..." } +# wgpu-hal = { git = "https://github.com/gfx-rs/wgpu", rev = "..." } +# wgpu-types = { git = "https://github.com/gfx-rs/wgpu", rev = "..." } +decoupled_naga = [] + # Texture formats (require more than just image support) basis-universal = ["bevy_image/basis-universal"] dds = ["bevy_image/dds"] diff --git a/crates/bevy_render/src/render_resource/pipeline_cache.rs b/crates/bevy_render/src/render_resource/pipeline_cache.rs index 4f9fc5ce26..70086cb6b2 100644 --- a/crates/bevy_render/src/render_resource/pipeline_cache.rs +++ b/crates/bevy_render/src/render_resource/pipeline_cache.rs @@ -349,7 +349,28 @@ impl ShaderCache { }, )?; - ShaderSource::Naga(Cow::Owned(naga)) + #[cfg(not(feature = "decoupled_naga"))] + { + ShaderSource::Naga(Cow::Owned(naga)) + } + + #[cfg(feature = "decoupled_naga")] + { + let mut validator = naga::valid::Validator::new( + naga::valid::ValidationFlags::all(), + self.composer.capabilities, + ); + let module_info = validator.validate(&naga).unwrap(); + let wgsl = Cow::Owned( + naga::back::wgsl::write_string( + &naga, + &module_info, + naga::back::wgsl::WriterFlags::empty(), + ) + .unwrap(), + ); + ShaderSource::Wgsl(wgsl) + } } };