Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 117
Add naga-wgsl target v2#493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| use crate::codegen_cx::CodegenArgs; | ||
| use crate::target::{NagaTarget, SpirvTarget}; | ||
| use rustc_session::Session; | ||
| use rustc_span::ErrorGuaranteed; | ||
| use std::path::Path; | ||
| pub type NagaTranspile = fn( | ||
| sess: &Session, | ||
| cg_args: &CodegenArgs, | ||
| spv_binary: &[u32], | ||
| out_filename: &Path, | ||
| ) -> Result<(), ErrorGuaranteed>; | ||
| pub fn should_transpile(sess: &Session) -> Result<Option<NagaTranspile>, ErrorGuaranteed> { | ||
| let target = SpirvTarget::parse_target(sess.opts.target_triple.tuple()) | ||
| .expect("parsing should fail earlier"); | ||
| let result: Result<Option<NagaTranspile>, ()> = match target { | ||
| #[cfg(feature = "naga")] | ||
| SpirvTarget::Naga(NagaTarget::NAGA_WGSL) => Ok(Some(transpile::wgsl_transpile)), | ||
| #[cfg(not(feature = "naga"))] | ||
| SpirvTarget::Naga(NagaTarget::NAGA_WGSL) => Err(()), | ||
| _ => Ok(None), | ||
| }; | ||
| result.map_err(|_e| { | ||
| sess.dcx().err(format!( | ||
| "Target `{}` requires feature \"naga\" on rustc_codegen_spirv", | ||
| target.target() | ||
| )) | ||
| }) | ||
| } | ||
| #[cfg(feature = "naga")] | ||
| mod transpile { | ||
| use crate::codegen_cx::CodegenArgs; | ||
| use naga::error::ShaderError; | ||
| use naga::valid::Capabilities; | ||
| use rustc_session::Session; | ||
| use rustc_span::ErrorGuaranteed; | ||
| use std::path::Path; | ||
| pub fn wgsl_transpile( | ||
| sess: &Session, | ||
| _cg_args: &CodegenArgs, | ||
| spv_binary: &[u32], | ||
| out_filename: &Path, | ||
| ) -> Result<(), ErrorGuaranteed> { | ||
| // these should be params via spirv-builder | ||
| let opts = naga::front::spv::Options::default(); | ||
| let capabilities = Capabilities::all(); | ||
| let writer_flags = naga::back::wgsl::WriterFlags::empty(); | ||
| let module = naga::front::spv::parse_u8_slice(bytemuck::cast_slice(spv_binary), &opts) | ||
| .map_err(|err| { | ||
| sess.dcx().err(format!( | ||
| "Naga failed to parse spv: \n{}", | ||
| ShaderError { | ||
| source: String::new(), | ||
| label: None, | ||
| inner: Box::new(err), | ||
| } | ||
| )) | ||
| })?; | ||
| let mut validator = | ||
| naga::valid::Validator::new(naga::valid::ValidationFlags::default(), capabilities); | ||
| let info = validator.validate(&module).map_err(|err| { | ||
| sess.dcx().err(format!( | ||
| "Naga validation failed: \n{}", | ||
| ShaderError { | ||
| source: String::new(), | ||
| label: None, | ||
| inner: Box::new(err), | ||
| } | ||
| )) | ||
| })?; | ||
| let wgsl_dst = out_filename.with_extension("wgsl"); | ||
| let wgsl = naga::back::wgsl::write_string(&module, &info, writer_flags).map_err(|err| { | ||
| sess.dcx() | ||
| .err(format!("Naga failed to write wgsl : \n{err}")) | ||
| })?; | ||
| std::fs::write(&wgsl_dst, wgsl).map_err(|err| { | ||
| sess.dcx() | ||
| .err(format!("failed to write wgsl to file: {err}")) | ||
| })?; | ||
| Ok(()) | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, this effectively makes
naganon-optional if I'm reading it correctly. Is it intentional?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's from the old PR, added with comment
So this was more a hack than anything else. I'll have a look what the compile time impact is, and if it's actually significant (which next to
spirv-tools-sysmay not be), look into making it optional and supported by cargo-gpu.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if
nagashould really be a dependency of either of those two features. Why not let user specify it explicitly instead?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we'd need to build the infra in cargo-gpu first