Skip to content

Commit 4904216

Browse files
committed
integrated naga transpiling to wgsl
1 parent c60cc12 commit 4904216

File tree

6 files changed

+250
-1
lines changed

6 files changed

+250
-1
lines changed

Cargo.lock

Lines changed: 136 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ tempdir = "0.3.7"
2828
test-log = "0.2.16"
2929
cargo_metadata = "0.19.2"
3030
semver = "1.0.26"
31+
naga = "25.0.1"
3132

3233
# This crate MUST NEVER be upgraded, we need this particular "first" version to support old rust-gpu builds
3334
legacy_target_specs = { package = "rustc_codegen_spirv-target-specs", version = "0.9.0", features = ["include_str"] }

crates/cargo-gpu/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ build = "build.rs"
1010
default-run = "cargo-gpu"
1111
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1212

13+
[features]
14+
# Enable naga support to convert spirv to wgsl
15+
naga = ["dep:naga"]
16+
1317
[dependencies]
1418
cargo_metadata.workspace = true
1519
anyhow.workspace = true
@@ -24,6 +28,7 @@ serde.workspace = true
2428
serde_json.workspace = true
2529
crossterm.workspace = true
2630
semver.workspace = true
31+
naga = { workspace = true, optional = true, features = ["spv-in", "wgsl-out"] }
2732

2833
[dev-dependencies]
2934
test-log.workspace = true

crates/cargo-gpu/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,15 @@ mod legacy_target_specs;
6565
mod linkage;
6666
mod lockfile;
6767
mod metadata;
68+
#[cfg(feature = "naga")]
69+
mod naga;
6870
mod show;
6971
mod spirv_source;
7072
mod test;
7173

7274
pub use install::*;
75+
#[cfg(feature = "naga")]
76+
pub use naga::*;
7377
pub use spirv_builder;
7478

7579
/// Central function to write to the user.

crates/cargo-gpu/src/linkage.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,13 @@ impl Linkage {
2323
.map(|comp| comp.as_os_str().to_string_lossy())
2424
.collect::<Vec<_>>()
2525
.join("/"),
26-
wgsl_entry_point: entry_point.as_ref().replace("::", ""),
26+
wgsl_entry_point: spv_entry_point_to_wgsl(entry_point.as_ref()),
2727
entry_point: entry_point.as_ref().to_owned(),
2828
}
2929
}
3030
}
31+
32+
/// Convert a spirv entry point to a valid wgsl entry point
33+
pub fn spv_entry_point_to_wgsl(entry_point: &str) -> String {
34+
entry_point.replace("::", "")
35+
}

0 commit comments

Comments
 (0)