[BREAKING] Wrap `ShaderSource::Naga` in `Cow<'static>`
Checklist
- [x] Run
cargo clippy. - [x] Run
RUSTFLAGS=--cfg=web_sys_unstable_apis cargo clippy --target wasm32-unknown-unknownif applicable. - [ ] Add change to CHANGELOG.md. See simple instructions inside file.
Connections Depends on https://github.com/gfx-rs/naga/pull/2013.
Description
I'm currently pre-compiling shaders and storing them as const, but ShaderSource::Naga wants to own naga::Modules, as far as I understand, for good reasons, because it stores them, so not owning them would be problematic. Using Cow<'static, Module>, solves this, even if it looks strange.
Testing None.
Could you provide an example that this change fixes? Is there another way to handle it without changing this type?
// I'm hiding some stuff here, but I've done this with a proc-macro
// and using `serde` to deserialize the `Module` in a `Lazy`.
const MODULE: &'static Module = ...;
// With the PR.
let source = ShaderModuleDescriptor {
label: None,
source: ShaderSource::Naga(Cow::Borrowed(MODULE)),
};
// Without the PR.
let source = ShaderModuleDescriptor {
label: None,
source: ShaderSource::Naga(MODULE.clone()),
};
// With the PR, I can now keep re-using the `Module` without having to clone it unnecessarily.
device.create_shader_module(source);
I hope this explains it.
~~On a side note, this change would also solve the lifetime issue in #2890.~~ (it wouldn't, because it's 'static)
Is there another way to handle it without changing this type?
Not that I'm aware of, unless we want to carry around a lifetime I guess.
Probably related: #2801.
Now that https://github.com/gfx-rs/naga/pull/2013 was merged, I updated the relevant parts to depend on it.
I think CI isn't failing because of this PR, it fails with the same errors in the latest commit on master too.
Added CHANGELOG entry and rebased, not sure why CI fails now, but it doesn't look like it's because of this PR.
Rebased after #3008.