mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-24 08:21:25 +01:00
[BREAKING] Wrap ShaderSource::Naga in Cow<'static> (#2903)
This commit is contained in:
1 parent
41006d7a88
commit
95408cd48b
10 files changed
+23
-10
No files matched your search
@@ -109,6 +109,7 @@ SurfaceConfiguration {
|
||||
- Update Winit to version 0.27 and raw-window-handle to 0.5 by @wyatt-herkamp in [#2918](https://github.com/gfx-rs/wgpu/pull/2918)
|
||||
- Address Clippy 0.1.63 complaints. By @jimblandy in [#2977](https://github.com/gfx-rs/wgpu/pull/2977)
|
||||
- Don't use `PhantomData` for `IdentityManager`'s `Input` type. By @jimblandy in [#2972](https://github.com/gfx-rs/wgpu/pull/2972)
|
||||
- Changed Naga variant in ShaderSource to `Cow<'static, Module>`, to allow loading global variables by @daxpedda in [#2903](https://github.com/gfx-rs/wgpu/pull/2903)
|
||||
|
||||
#### Metal
|
||||
- Extract the generic code into `get_metal_layer` by @jinleili in [#2826](https://github.com/gfx-rs/wgpu/pull/2826)
|
||||
|
||||
@@ -47,7 +47,7 @@ thiserror = "1"
|
||||
git = "https://github.com/gfx-rs/naga"
|
||||
rev = "b209d911"
|
||||
version = "0.9"
|
||||
features = ["span", "validate", "wgsl-in"]
|
||||
features = ["clone", "span", "validate", "wgsl-in"]
|
||||
|
||||
[dependencies.wgt]
|
||||
path = "../wgpu-types"
|
||||
|
||||
@@ -1216,7 +1216,7 @@ impl<A: HalApi> Device<A> {
|
||||
inner,
|
||||
})
|
||||
})?;
|
||||
(module, code.into_owned())
|
||||
(Cow::Owned(module), code.into_owned())
|
||||
}
|
||||
pipeline::ShaderModuleSource::Naga(module) => (module, String::new()),
|
||||
};
|
||||
|
||||
@@ -21,7 +21,7 @@ pub(crate) struct LateSizedBufferGroup {
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
pub enum ShaderModuleSource<'a> {
|
||||
Wgsl(Cow<'a, str>),
|
||||
Naga(naga::Module),
|
||||
Naga(Cow<'static, naga::Module>),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
||||
@@ -98,6 +98,7 @@ android_system_properties = "0.1.1"
|
||||
git = "https://github.com/gfx-rs/naga"
|
||||
rev = "b209d911"
|
||||
version = "0.9"
|
||||
features = ["clone"]
|
||||
|
||||
# DEV dependencies
|
||||
|
||||
|
||||
@@ -7,7 +7,13 @@ use hal::{
|
||||
};
|
||||
use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle};
|
||||
|
||||
use std::{borrow::Borrow, iter, mem, num::NonZeroU32, ptr, time::Instant};
|
||||
use std::{
|
||||
borrow::{Borrow, Cow},
|
||||
iter, mem,
|
||||
num::NonZeroU32,
|
||||
ptr,
|
||||
time::Instant,
|
||||
};
|
||||
|
||||
const MAX_BUNNIES: usize = 1 << 20;
|
||||
const BUNNY_SIZE: f32 = 0.15 * 256.0;
|
||||
@@ -148,7 +154,10 @@ impl<A: hal::Api> Example<A> {
|
||||
)
|
||||
.validate(&module)
|
||||
.unwrap();
|
||||
hal::NagaShader { module, info }
|
||||
hal::NagaShader {
|
||||
module: Cow::Owned(module),
|
||||
info,
|
||||
}
|
||||
};
|
||||
let shader_desc = hal::ShaderModuleDescriptor {
|
||||
label: None,
|
||||
|
||||
+2
-2
@@ -83,7 +83,7 @@ pub mod api {
|
||||
pub use vulkan::UpdateAfterBindTypes;
|
||||
|
||||
use std::{
|
||||
borrow::Borrow,
|
||||
borrow::{Borrow, Cow},
|
||||
fmt,
|
||||
num::{NonZeroU32, NonZeroU8},
|
||||
ops::{Range, RangeInclusive},
|
||||
@@ -940,7 +940,7 @@ pub struct CommandEncoderDescriptor<'a, A: Api> {
|
||||
/// Naga shader module.
|
||||
pub struct NagaShader {
|
||||
/// Shader module IR.
|
||||
pub module: naga::Module,
|
||||
pub module: Cow<'static, naga::Module>,
|
||||
/// Analysis information of the module.
|
||||
pub info: naga::valid::ModuleInfo,
|
||||
}
|
||||
|
||||
@@ -143,6 +143,7 @@ env_logger = "0.9"
|
||||
git = "https://github.com/gfx-rs/naga"
|
||||
rev = "b209d911"
|
||||
version = "0.9"
|
||||
features = ["clone"]
|
||||
optional = true
|
||||
|
||||
# used to test all the example shaders
|
||||
|
||||
@@ -1116,7 +1116,7 @@ impl crate::Context for Context {
|
||||
};
|
||||
let parser = naga::front::spv::Parser::new(spv.iter().cloned(), &options);
|
||||
let module = parser.parse().unwrap();
|
||||
wgc::pipeline::ShaderModuleSource::Naga(module)
|
||||
wgc::pipeline::ShaderModuleSource::Naga(std::borrow::Cow::Owned(module))
|
||||
}
|
||||
#[cfg(feature = "glsl")]
|
||||
ShaderSource::Glsl {
|
||||
@@ -1132,7 +1132,7 @@ impl crate::Context for Context {
|
||||
let mut parser = naga::front::glsl::Parser::default();
|
||||
let module = parser.parse(&options, shader).unwrap();
|
||||
|
||||
wgc::pipeline::ShaderModuleSource::Naga(module)
|
||||
wgc::pipeline::ShaderModuleSource::Naga(std::borrow::Cow::Owned(module))
|
||||
}
|
||||
ShaderSource::Wgsl(ref code) => wgc::pipeline::ShaderModuleSource::Wgsl(Borrowed(code)),
|
||||
#[cfg(feature = "naga")]
|
||||
|
||||
+2
-1
@@ -835,6 +835,7 @@ impl Drop for ShaderModule {
|
||||
///
|
||||
/// Any necessary shader translation (e.g. from WGSL to SPIR-V or vice versa)
|
||||
/// will be done internally by wgpu.
|
||||
#[cfg_attr(feature = "naga", allow(clippy::large_enum_variant))]
|
||||
#[non_exhaustive]
|
||||
pub enum ShaderSource<'a> {
|
||||
/// SPIR-V module represented as a slice of words.
|
||||
@@ -861,7 +862,7 @@ pub enum ShaderSource<'a> {
|
||||
/// Naga module.
|
||||
#[cfg(feature = "naga")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "naga")))]
|
||||
Naga(naga::Module),
|
||||
Naga(Cow<'static, naga::Module>),
|
||||
}
|
||||
static_assertions::assert_impl_all!(ShaderSource: Send, Sync);
|
||||
|
||||
|
||||
Reference in new issue
Block a user