diff --git a/Cargo.lock b/Cargo.lock index 9b68563..5b0849f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -465,6 +465,15 @@ dependencies = [ "wasi", ] +[[package]] +name = "glam" +version = "0.30.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2d1aab06663bdce00d6ca5e5ed586ec8d18033a771906c993a1e3755b368d85" +dependencies = [ + "libm", +] + [[package]] name = "hashbrown" version = "0.15.2" @@ -688,6 +697,12 @@ version = "0.2.172" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" +[[package]] +name = "libm" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" + [[package]] name = "libredox" version = "0.1.3" @@ -800,6 +815,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", + "libm", ] [[package]] @@ -1251,6 +1267,35 @@ dependencies = [ "thiserror", ] +[[package]] +name = "spirv-std" +version = "0.9.0" +source = "git+https://github.com/Rust-GPU/rust-gpu?rev=de03e8d8c997c68aed1a950863c0d79ba9bd8c72#de03e8d8c997c68aed1a950863c0d79ba9bd8c72" +dependencies = [ + "bitflags 1.3.2", + "glam", + "libm", + "num-traits", + "spirv-std-macros", + "spirv-std-types", +] + +[[package]] +name = "spirv-std-macros" +version = "0.9.0" +source = "git+https://github.com/Rust-GPU/rust-gpu?rev=de03e8d8c997c68aed1a950863c0d79ba9bd8c72#de03e8d8c997c68aed1a950863c0d79ba9bd8c72" +dependencies = [ + "proc-macro2", + "quote", + "spirv-std-types", + "syn", +] + +[[package]] +name = "spirv-std-types" +version = "0.9.0" +source = "git+https://github.com/Rust-GPU/rust-gpu?rev=de03e8d8c997c68aed1a950863c0d79ba9bd8c72#de03e8d8c997c68aed1a950863c0d79ba9bd8c72" + [[package]] name = "stable_deref_trait" version = "1.2.0" @@ -1317,6 +1362,13 @@ dependencies = [ "syn", ] +[[package]] +name = "test-shaders" +version = "0.1.0" +dependencies = [ + "spirv-std", +] + [[package]] name = "thiserror" version = "2.0.12" diff --git a/Cargo.toml b/Cargo.toml index 75d6799..64be376 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,7 @@ [workspace] members = [ "crates/cargo-gpu", + "crates/test-shaders", "crates/xtask", ] diff --git a/crates/cargo-gpu/src/build.rs b/crates/cargo-gpu/src/build.rs index 1bb5078..bcd8e01 100644 --- a/crates/cargo-gpu/src/build.rs +++ b/crates/cargo-gpu/src/build.rs @@ -116,6 +116,7 @@ impl Build { fn parse_compilation_result(&self, result: &CompileResult) -> anyhow::Result<()> { let shaders = match &result.module { ModuleResult::MultiModule(modules) => { + log::debug!("modules: {modules:#?}"); anyhow::ensure!(!modules.is_empty(), "No shader modules were compiled"); modules.iter().collect::>() } @@ -128,6 +129,7 @@ impl Build { let mut linkage: Vec = shaders .into_iter() .map(|(entry, filepath)| -> anyhow::Result { + log::debug!("Compiled {entry} to {filepath:?}"); use relative_path::PathExt as _; let path = self.build.output_dir.join( filepath diff --git a/crates/test-shaders/Cargo.toml b/crates/test-shaders/Cargo.toml new file mode 100644 index 0000000..00112cb --- /dev/null +++ b/crates/test-shaders/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "test-shaders" +version = "0.1.0" +edition = "2024" + +[lib] +crate-type = ["rlib", "cdylib"] + +[dependencies] +spirv-std = { git = "https://github.com/Rust-GPU/rust-gpu", rev = "de03e8d8c997c68aed1a950863c0d79ba9bd8c72" } + diff --git a/crates/test-shaders/src/lib.rs b/crates/test-shaders/src/lib.rs new file mode 100644 index 0000000..fde167d --- /dev/null +++ b/crates/test-shaders/src/lib.rs @@ -0,0 +1,32 @@ +//! Test shaders. +//! +//! Here we have some shaders that have been problematic in the past. +#![no_std] +#![expect( + unexpected_cfgs, + reason = "rust-gpu uses the spirv attribute macro heavily" +)] +use spirv_std::{glam::Vec4, spirv}; + +/// This shader has the same name as the vertex shader below it. +/// It should be compiled and then named something so that the two +/// don't clobber each other. +/// See +#[inline(never)] +#[spirv(fragment(entry_point_name = "duplicate_main"))] +pub const fn dupe_frag(in_color: Vec4, output: &mut Vec4) { + *output = in_color; +} + +/// This shader has the same name as the fragment shader above it. +/// It should be compiled and then named something so that the two +/// don't clobber each other. +/// See +#[spirv(vertex(entry_point_name = "duplicate_main"))] +pub const fn implicit_isosceles_vertex( + // Which vertex within the render unit are we rendering + #[spirv(vertex_index)] vertex_index: u32, + #[spirv(position)] clip_pos: &mut Vec4, +) { + *clip_pos = Vec4::splat(vertex_index as f32); +} diff --git a/output/duplicate_main.1.spv b/output/duplicate_main.1.spv new file mode 100644 index 0000000..c7b0fce Binary files /dev/null and b/output/duplicate_main.1.spv differ diff --git a/output/manifest.json b/output/manifest.json new file mode 100644 index 0000000..67faf23 --- /dev/null +++ b/output/manifest.json @@ -0,0 +1,7 @@ +[ + { + "source_path": "../../output/duplicate_main.1.spv", + "entry_point": "duplicate_main", + "wgsl_entry_point": "duplicate_main" + } +] \ No newline at end of file