-
Notifications
You must be signed in to change notification settings - Fork 85
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
Draft
Firestar99
wants to merge
5
commits into
target-decl
Choose a base branch
from
naga-wgsl-v2
base: target-decl
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7b295b6
wgsl: add `spirv-unknown-naga-wgsl` target, transpiling with naga 27
Firestar99 47eb352
wgsl: hide naga behind feature
Firestar99 8467a5b
wgsl: enable naga feature by default, cargo-gpu can't handle it
Firestar99 0ca7c46
wgsl: ignore naga targets in compile tests with unsupported extension…
Firestar99 231bcb7
wgsl ci: add experimental wgsl compiletest to ci
Firestar99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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::default(); | ||
| 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(()) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
tests/compiletests/ui/arch/convert_u_to_acceleration_structure_khr.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| // build-pass | ||
| // compile-flags: -C target-feature=+Int64,+GeometryStreams | ||
| // ignore-naga | ||
|
|
||
| use spirv_std::spirv; | ||
|
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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