diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index bd55654183..c4c48ac2aa 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -135,7 +135,14 @@ jobs:
fail-fast: false
matrix:
os: [ ubuntu-24.04, windows-2022, macOS-latest ]
+ target_env: [ "vulkan1.1,vulkan1.2,vulkan1.3,vulkan1.4,spv1.3,spv1.4" ]
+ experimental: [ false ]
+ include:
+ - os: ubuntu-24.04
+ target_env: naga-wgsl
+ experimental: true
runs-on: ${{ matrix.os }}
+ continue-on-error: ${{ matrix.experimental }}
steps:
- uses: actions/checkout@v4
- name: Install Vulkan SDK
@@ -154,7 +161,7 @@ jobs:
- name: cargo fetch --locked
run: cargo fetch --locked --target $TARGET
- name: compiletest
- run: cargo run -p compiletests --release --no-default-features --features "use-installed-tools" -- --target-env vulkan1.1,vulkan1.2,vulkan1.3,vulkan1.4,spv1.3,spv1.4
+ run: cargo run -p compiletests --release --no-default-features --features "use-installed-tools" -- --target-env ${{ matrix.target_env }}
difftest:
name: Difftest
diff --git a/Cargo.lock b/Cargo.lock
index 6d0220a41e..b9bb382da3 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1027,6 +1027,12 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
+[[package]]
+name = "foldhash"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb"
+
[[package]]
name = "foreign-types"
version = "0.5.0"
@@ -1353,7 +1359,16 @@ checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"
dependencies = [
"allocator-api2",
"equivalent",
- "foldhash",
+ "foldhash 0.1.5",
+]
+
+[[package]]
+name = "hashbrown"
+version = "0.16.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100"
+dependencies = [
+ "foldhash 0.2.0",
]
[[package]]
@@ -1931,6 +1946,31 @@ dependencies = [
"unicode-ident",
]
+[[package]]
+name = "naga"
+version = "27.0.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "066cf25f0e8b11ee0df221219010f213ad429855f57c494f995590c861a9a7d8"
+dependencies = [
+ "arrayvec",
+ "bit-set",
+ "bitflags 2.9.4",
+ "cfg-if",
+ "cfg_aliases",
+ "codespan-reporting",
+ "half",
+ "hashbrown 0.16.1",
+ "indexmap 2.11.0",
+ "libm",
+ "log",
+ "num-traits",
+ "once_cell",
+ "petgraph",
+ "rustc-hash",
+ "spirv",
+ "thiserror 2.0.16",
+]
+
[[package]]
name = "ndk"
version = "0.9.0"
@@ -2711,6 +2751,7 @@ dependencies = [
"lazy_static",
"libc",
"log",
+ "naga 27.0.3",
"object 0.37.3",
"pretty_assertions",
"regex",
@@ -2723,6 +2764,7 @@ dependencies = [
"spirt",
"spirv-std-types",
"spirv-tools",
+ "strum",
"thorin-dwp",
"tracing",
"tracing-subscriber",
@@ -4016,7 +4058,7 @@ dependencies = [
"hashbrown 0.15.5",
"js-sys",
"log",
- "naga",
+ "naga 26.0.0",
"parking_lot",
"portable-atomic",
"profiling",
@@ -4047,7 +4089,7 @@ dependencies = [
"hashbrown 0.15.5",
"indexmap 2.11.0",
"log",
- "naga",
+ "naga 26.0.0",
"once_cell",
"parking_lot",
"portable-atomic",
@@ -4118,7 +4160,7 @@ dependencies = [
"libloading",
"log",
"metal",
- "naga",
+ "naga 26.0.0",
"ndk-sys",
"objc",
"ordered-float 5.0.0",
diff --git a/crates/rustc_codegen_spirv/Cargo.toml b/crates/rustc_codegen_spirv/Cargo.toml
index 2357ae1f7f..c0f98b7170 100644
--- a/crates/rustc_codegen_spirv/Cargo.toml
+++ b/crates/rustc_codegen_spirv/Cargo.toml
@@ -20,15 +20,16 @@ crate-type = ["dylib"]
default = ["use-compiled-tools"]
# If enabled, uses spirv-tools binaries installed in PATH, instead of
# compiling and linking the spirv-tools C++ code
-use-installed-tools = ["spirv-tools/use-installed-tools"]
+use-installed-tools = ["spirv-tools/use-installed-tools", "naga"]
# If enabled will compile and link the C++ code for the spirv tools, the compiled
# version is preferred if both this and `use-installed-tools` are enabled
-use-compiled-tools = ["spirv-tools/use-compiled-tools"]
+use-compiled-tools = ["spirv-tools/use-compiled-tools", "naga"]
# If enabled, this will not check whether the current rustc version is set to the
# appropriate channel. rustc_cogeden_spirv requires a specific nightly version,
# and will likely produce compile errors when built against a different toolchain.
# Enable this feature to be able to experiment with other versions.
skip-toolchain-check = []
+naga = ["dep:naga"]
[dependencies]
# HACK(eddyb) these only exist to unify features across dependency trees,
@@ -61,6 +62,8 @@ itertools = "0.14.0"
tracing.workspace = true
tracing-subscriber.workspace = true
tracing-tree = "0.4.0"
+naga = { version = "27.0.3", features = ["spv-in", "wgsl-out"], optional = true }
+strum = { version = "0.27.2", features = ["derive"] }
[dev-dependencies]
pretty_assertions = "1.0"
diff --git a/crates/rustc_codegen_spirv/src/lib.rs b/crates/rustc_codegen_spirv/src/lib.rs
index be6b291e25..7274635c64 100644
--- a/crates/rustc_codegen_spirv/src/lib.rs
+++ b/crates/rustc_codegen_spirv/src/lib.rs
@@ -133,6 +133,7 @@ mod custom_decorations;
mod custom_insts;
mod link;
mod linker;
+mod naga_transpile;
mod spirv_type;
mod spirv_type_constraints;
mod symbols;
diff --git a/crates/rustc_codegen_spirv/src/link.rs b/crates/rustc_codegen_spirv/src/link.rs
index 6f80acaf5f..18b36c5c03 100644
--- a/crates/rustc_codegen_spirv/src/link.rs
+++ b/crates/rustc_codegen_spirv/src/link.rs
@@ -2,6 +2,7 @@
use crate::maybe_pqp_cg_ssa as rustc_codegen_ssa;
use crate::codegen_cx::{CodegenArgs, SpirvMetadata};
+use crate::naga_transpile::should_transpile;
use crate::target::{SpirvTarget, SpirvTargetVariant};
use crate::{SpirvCodegenBackend, SpirvModuleBuffer, linker};
use ar::{Archive, GnuBuilder, Header};
@@ -323,6 +324,10 @@ 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
new file mode 100644
index 0000000000..0f2235cb45
--- /dev/null
+++ b/crates/rustc_codegen_spirv/src/naga_transpile.rs
@@ -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