diff --git a/Cargo.lock b/Cargo.lock index 074ef692b2..6bfad708a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -295,15 +295,6 @@ version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac07cdecf99051d9a5238b80f35af32cdeba5b336e55d957b318b50137e18da5" -[[package]] -name = "bit-set" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34ddef2995421ab6a5c779542c81ee77c115206f4ad9d5a8e05f4ff49716a3dd" -dependencies = [ - "bit-vec", -] - [[package]] name = "bit-set" version = "0.10.0" @@ -1541,7 +1532,7 @@ dependencies = [ "futures", "shared", "spirv-builder", - "strum 0.28.0", + "strum", "wasm-bindgen-futures", "web-sys", "web-time", @@ -3881,31 +3872,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "743fb55ba31b18fb1ecef6bdc9aa2743314978ac084044301a7eee33fb99a20d" -[[package]] -name = "naga" -version = "29.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2bf919621e7975acb27d881bae2fb993e0d45c8e0446e85e6272971e00dc8df" -dependencies = [ - "arrayvec", - "bit-set 0.9.1", - "bitflags 2.13.2", - "cfg-if", - "cfg_aliases", - "codespan-reporting", - "half", - "hashbrown 0.16.1", - "indexmap", - "libm", - "log", - "num-traits", - "once_cell", - "petgraph", - "rustc-hash 1.1.0", - "spirv", - "thiserror 2.0.21", -] - [[package]] name = "naga" version = "30.0.1" @@ -3913,7 +3879,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a616d2fb8c89516ac2723a581f69d6c18576046bed761bd6b305e5618e6ae130" dependencies = [ "arrayvec", - "bit-set 0.10.0", + "bit-set", "bitflags 2.13.2", "cfg-if", "cfg_aliases", @@ -5257,7 +5223,7 @@ dependencies = [ "lazy_static", "libc", "log", - "naga 29.0.4", + "naga", "object 0.37.3", "pretty_assertions", "regex", @@ -5271,7 +5237,7 @@ dependencies = [ "spirt", "spirv-std-types", "spirv-tools", - "strum 0.27.2", + "strum", "termcolor", "thorin-dwp", "tracing", @@ -5940,34 +5906,13 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" -[[package]] -name = "strum" -version = "0.27.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af23d6f6c1a224baef9d3f61e287d2761385a5b88fdab4eb4c6f11aeb54c4bcf" -dependencies = [ - "strum_macros 0.27.2", -] - [[package]] name = "strum" version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9628de9b8791db39ceda2b119bbe13134770b56c138ec1d3af810d045c04f9bd" dependencies = [ - "strum_macros 0.28.0", -] - -[[package]] -name = "strum_macros" -version = "0.27.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7695ce3845ea4b33927c055a39dc438a45b059f7c1b3d91d38d10355fb8cbca7" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn 2.0.119", + "strum_macros", ] [[package]] @@ -7149,7 +7094,7 @@ dependencies = [ "hashbrown 0.17.1", "js-sys", "log", - "naga 30.0.1", + "naga", "parking_lot", "portable-atomic", "profiling", @@ -7171,7 +7116,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c018fce9b6270aa203c2fdd56f3cce996713534bd757e4ea58c8560b121f14" dependencies = [ "arrayvec", - "bit-set 0.10.0", + "bit-set", "bit-vec", "bitflags 2.13.2", "bytemuck", @@ -7180,7 +7125,7 @@ dependencies = [ "hashbrown 0.17.1", "indexmap", "log", - "naga 30.0.1", + "naga", "naga-types", "once_cell", "parking_lot", @@ -7234,7 +7179,7 @@ dependencies = [ "android_system_properties", "arrayvec", "ash", - "bit-set 0.10.0", + "bit-set", "bitflags 2.13.2", "block2 0.6.2", "bytemuck", @@ -7249,7 +7194,7 @@ dependencies = [ "libc", "libloading", "log", - "naga 30.0.1", + "naga", "naga-types", "ndk-sys", "objc2 0.6.4", @@ -7287,7 +7232,7 @@ version = "30.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2f62e73117bb7a62bfd9c5a5841438a823f6566c6442a808ee269d2d055c081" dependencies = [ - "naga 30.0.1", + "naga", "wgpu-types", ] diff --git a/crates/rustc_codegen_spirv/Cargo.toml b/crates/rustc_codegen_spirv/Cargo.toml index 91d9cdadb9..3d430ac603 100644 --- a/crates/rustc_codegen_spirv/Cargo.toml +++ b/crates/rustc_codegen_spirv/Cargo.toml @@ -62,8 +62,8 @@ itertools = "0.14.0" tracing.workspace = true tracing-subscriber.workspace = true tracing-tree = "0.4.0" -naga = { version = "29.0.1", features = ["spv-in", "wgsl-out"], optional = true } -strum = { version = "0.27.2", features = ["derive"] } +naga = { version = "30.0.1", features = ["spv-in", "wgsl-out"], optional = true } +strum = { version = "0.28.0", features = ["derive"] } rspirv2.workspace = true [dev-dependencies] diff --git a/crates/rustc_codegen_spirv/src/link.rs b/crates/rustc_codegen_spirv/src/link.rs index ea5ebadce5..057f714f84 100644 --- a/crates/rustc_codegen_spirv/src/link.rs +++ b/crates/rustc_codegen_spirv/src/link.rs @@ -3,7 +3,7 @@ use crate::maybe_pqp_cg_ssa as rustc_codegen_ssa; use crate::codegen_cx::{CodegenArgs, SpirvMetadata}; use crate::linker; -use crate::naga_transpile::should_transpile; +use crate::naga_transpile::transpile; use crate::target::{SpirvTarget, SpirvTargetVariant}; use ar::{Archive, GnuBuilder, Header}; use rspirv::binary::Assemble; @@ -302,10 +302,17 @@ fn post_link_single_module( do_spirv_val(sess, &spv_binary, out_filename, val_options); } + let binary = { + let _transpile_timer = sess.timer("link_transpile"); + match transpile(sess, cg_args, &spv_binary) { + Ok(e) => e, + Err(_) => return, + } + }; + { let save_modules_timer = sess.timer("link_save_modules"); - if let Err(e) = std::fs::write(out_filename, spirv_tools::binary::from_binary(&spv_binary)) - { + if let Err(e) = std::fs::write(out_filename, binary) { let mut err = sess .dcx() .struct_err("failed to serialize spirv-binary to disk"); @@ -316,10 +323,6 @@ fn post_link_single_module( drop(save_modules_timer); } - - if let Ok(Some(transpile)) = should_transpile(sess) { - transpile(sess, cg_args, &spv_binary, out_filename).ok(); - } } fn do_spirv_opt( diff --git a/crates/rustc_codegen_spirv/src/naga_transpile.rs b/crates/rustc_codegen_spirv/src/naga_transpile.rs index 6f6b813110..3d9df3cd20 100644 --- a/crates/rustc_codegen_spirv/src/naga_transpile.rs +++ b/crates/rustc_codegen_spirv/src/naga_transpile.rs @@ -2,31 +2,26 @@ 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( +pub fn transpile( sess: &Session, cg_args: &CodegenArgs, spv_binary: &[u32], - out_filename: &Path, -) -> Result<(), ErrorGuaranteed>; - -pub fn should_transpile(sess: &Session) -> Result, ErrorGuaranteed> { +) -> Result, ErrorGuaranteed> { let target = SpirvTarget::parse_target(sess.opts.target_triple.tuple()) .expect("parsing should fail earlier"); - let result: Result, ()> = match target { + match target { #[cfg(feature = "naga")] - SpirvTarget::Naga(NagaTarget::NAGA_WGSL) => Ok(Some(transpile::wgsl_transpile)), + SpirvTarget::Naga(NagaTarget::NAGA_WGSL) => { + transpile::wgsl_transpile(sess, cg_args, spv_binary) + } #[cfg(not(feature = "naga"))] - SpirvTarget::Naga(NagaTarget::NAGA_WGSL) => Err(()), - _ => Ok(None), - }; - result.map_err(|_e| { - sess.dcx().err(format!( + SpirvTarget::Naga(_) => Err(sess.dcx().err(format!( "Target `{}` requires feature \"naga\" on rustc_codegen_spirv", target.target() - )) - }) + ))), + _ => Ok(bytemuck::cast_slice::<_, u8>(spv_binary).to_vec()), + } } #[cfg(feature = "naga")] @@ -36,16 +31,18 @@ mod transpile { 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> { + ) -> Result, ErrorGuaranteed> { // these should be params via spirv-builder - let opts = naga::front::spv::Options::default(); + let opts = naga::front::spv::Options { + adjust_coordinate_space: false, + strict_capabilities: false, + ..Default::default() + }; let capabilities = Capabilities::all(); let writer_flags = naga::back::wgsl::WriterFlags::empty(); @@ -73,17 +70,10 @@ mod transpile { )) })?; - 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(()) + Ok(wgsl.into_bytes()) } } diff --git a/tests/difftests/tests/Cargo.lock b/tests/difftests/tests/Cargo.lock index 02a41bf894..fbca9d9ace 100644 --- a/tests/difftests/tests/Cargo.lock +++ b/tests/difftests/tests/Cargo.lock @@ -168,15 +168,6 @@ version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" -[[package]] -name = "bit-set" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34ddef2995421ab6a5c779542c81ee77c115206f4ad9d5a8e05f4ff49716a3dd" -dependencies = [ - "bit-vec", -] - [[package]] name = "bit-set" version = "0.10.0" @@ -1128,31 +1119,6 @@ dependencies = [ "simd-adler32", ] -[[package]] -name = "naga" -version = "29.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2bf919621e7975acb27d881bae2fb993e0d45c8e0446e85e6272971e00dc8df" -dependencies = [ - "arrayvec", - "bit-set 0.9.1", - "bitflags", - "cfg-if", - "cfg_aliases", - "codespan-reporting", - "half", - "hashbrown 0.16.1", - "indexmap", - "libm", - "log", - "num-traits", - "once_cell", - "petgraph", - "rustc-hash 1.1.0", - "spirv", - "thiserror", -] - [[package]] name = "naga" version = "30.0.1" @@ -1160,7 +1126,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a616d2fb8c89516ac2723a581f69d6c18576046bed761bd6b305e5618e6ae130" dependencies = [ "arrayvec", - "bit-set 0.10.0", + "bit-set", "bitflags", "cfg-if", "cfg_aliases", @@ -1647,7 +1613,7 @@ dependencies = [ "lazy_static", "libc", "log", - "naga 29.0.4", + "naga", "object 0.37.3", "regex", "rspirv", @@ -1973,18 +1939,18 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "strum" -version = "0.27.2" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af23d6f6c1a224baef9d3f61e287d2761385a5b88fdab4eb4c6f11aeb54c4bcf" +checksum = "9628de9b8791db39ceda2b119bbe13134770b56c138ec1d3af810d045c04f9bd" dependencies = [ "strum_macros", ] [[package]] name = "strum_macros" -version = "0.27.2" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7695ce3845ea4b33927c055a39dc438a45b059f7c1b3d91d38d10355fb8cbca7" +checksum = "ab85eea0270ee17587ed4156089e10b9e6880ee688791d45a905f5b1ca36f664" dependencies = [ "heck", "proc-macro2", @@ -2476,7 +2442,7 @@ dependencies = [ "hashbrown 0.17.1", "js-sys", "log", - "naga 30.0.1", + "naga", "parking_lot", "portable-atomic", "profiling", @@ -2498,7 +2464,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c018fce9b6270aa203c2fdd56f3cce996713534bd757e4ea58c8560b121f14" dependencies = [ "arrayvec", - "bit-set 0.10.0", + "bit-set", "bit-vec", "bitflags", "bytemuck", @@ -2507,7 +2473,7 @@ dependencies = [ "hashbrown 0.17.1", "indexmap", "log", - "naga 30.0.1", + "naga", "naga-types", "once_cell", "parking_lot", @@ -2561,7 +2527,7 @@ dependencies = [ "libc", "libloading", "log", - "naga 30.0.1", + "naga", "naga-types", "objc2", "objc2-core-foundation", @@ -2591,7 +2557,7 @@ version = "30.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2f62e73117bb7a62bfd9c5a5841438a823f6566c6442a808ee269d2d055c081" dependencies = [ - "naga 30.0.1", + "naga", "wgpu-types", ]