Decoupled naga for wgpu testing (#18099)
# Objective - Allow bevy and wgpu developers to test newer versions of wgpu without having to update naga_oil. ## Solution - Currently bevy feeds wgsl through naga_oil to get a naga::Module that it passes to wgpu. - Added a way to pass wgsl through naga_oil, and then serialize the naga::Module back into a wgsl string to feed to wgpu, allowing wgpu to parse it using it's internal version of naga (and not the version of naga bevy_render/naga_oil is using). ## Testing 1. Run 3d_scene (it works) 2. Run 3d_scene with `--features bevy_render/decoupled_naga` (it still works) 3. Add the following patch to bevy/Cargo.toml, run cargo update, and compile again (it will fail) ```toml [patch.crates-io] wgpu = { git = "https://github.com/gfx-rs/wgpu", rev = "2764e7a39920e23928d300e8856a672f1952da63" } wgpu-core = { git = "https://github.com/gfx-rs/wgpu", rev = "2764e7a39920e23928d300e8856a672f1952da63" } wgpu-hal = { git = "https://github.com/gfx-rs/wgpu", rev = "2764e7a39920e23928d300e8856a672f1952da63" } wgpu-types = { git = "https://github.com/gfx-rs/wgpu", rev = "2764e7a39920e23928d300e8856a672f1952da63" } ``` 4. Fix errors and compile again (it will work, and you didn't have to touch naga_oil)
This commit is contained in:
parent
4cd014384f
commit
bb1616a212
@ -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"]
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user