mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-28 00:59:12 +01:00
Add Naga variant to ShaderSource
This commit is contained in:
1 parent
36ae2ceda3
commit
064f3f1db4
3 files changed
+21
No files matched your search
@@ -1108,6 +1108,8 @@ impl crate::Context for Context {
|
||||
wgc::pipeline::ShaderModuleSource::Naga(module)
|
||||
}
|
||||
ShaderSource::Wgsl(ref code) => wgc::pipeline::ShaderModuleSource::Wgsl(Borrowed(code)),
|
||||
#[cfg(feature = "naga")]
|
||||
ShaderSource::Naga(module) => wgc::pipeline::ShaderModuleSource::Naga(module),
|
||||
};
|
||||
let (id, error) = wgc::gfx_select!(
|
||||
device.id => global.device_create_shader_module(device.id, &descriptor, source, PhantomData)
|
||||
|
||||
@@ -1307,6 +1307,21 @@ impl crate::Context for Context {
|
||||
web_sys::GpuShaderModuleDescriptor::new(wgsl_text.as_str())
|
||||
}
|
||||
crate::ShaderSource::Wgsl(ref code) => web_sys::GpuShaderModuleDescriptor::new(code),
|
||||
#[cfg(feature = "naga")]
|
||||
crate::ShaderSource::Naga(module) => {
|
||||
use naga::{back, valid};
|
||||
|
||||
let mut validator = valid::Validator::new(
|
||||
valid::ValidationFlags::all(),
|
||||
valid::Capabilities::all(),
|
||||
);
|
||||
let module_info = validator.validate(&module).unwrap();
|
||||
|
||||
let writer_flags = naga::back::wgsl::WriterFlags::empty();
|
||||
let wgsl_text =
|
||||
back::wgsl::write_string(&module, &module_info, writer_flags).unwrap();
|
||||
web_sys::GpuShaderModuleDescriptor::new(wgsl_text.as_str())
|
||||
}
|
||||
};
|
||||
if let Some(label) = desc.label {
|
||||
descriptor.label(label);
|
||||
|
||||
@@ -813,6 +813,10 @@ pub enum ShaderSource<'a> {
|
||||
},
|
||||
/// WGSL module as a string slice.
|
||||
Wgsl(Cow<'a, str>),
|
||||
/// Naga module.
|
||||
#[cfg(feature = "naga")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "naga")))]
|
||||
Naga(naga::Module),
|
||||
}
|
||||
|
||||
/// Descriptor for use with [`Device::create_shader_module`].
|
||||
|
||||
Reference in new issue
Block a user