Skip to content

Commit

Permalink
Add more support for cgmath and nalgebra types (vulkano-rs#2107)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rua authored and hakolao committed Feb 20, 2024
1 parent e35dc1b commit 78752a7
Show file tree
Hide file tree
Showing 7 changed files with 493 additions and 175 deletions.
2 changes: 2 additions & 0 deletions vulkano-shaders/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@ syn = { version = "1.0", features = ["full", "extra-traits"] }
vulkano = { version = "0.32.0", path = "../vulkano" }

[features]
cgmath = []
nalgebra = []
shaderc-build-from-source = ["shaderc/build-from-source"]
shaderc-debug = []
37 changes: 28 additions & 9 deletions vulkano-shaders/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// notice may not be copied, modified, or distributed except
// according to those terms.

use crate::{entry_point, read_file_to_string, structs, RegisteredType, TypesMeta};
use crate::{entry_point, read_file_to_string, structs, LinAlgType, RegisteredType, TypesMeta};
use ahash::HashMap;
use proc_macro2::TokenStream;
pub use shaderc::{CompilationArtifact, IncludeType, ResolvedInclude, ShaderKind};
Expand Down Expand Up @@ -205,7 +205,7 @@ pub fn compile(
Ok((content, includes))
}

pub(super) fn reflect<'a>(
pub(super) fn reflect<'a, L: LinAlgType>(
prefix: &'a str,
words: &[u32],
types_meta: &TypesMeta,
Expand Down Expand Up @@ -243,8 +243,12 @@ pub(super) fn reflect<'a>(
let entry_points = reflect::entry_points(&spirv)
.map(|(name, model, info)| entry_point::write_entry_point(&name, model, &info));

let specialization_constants =
structs::write_specialization_constants(prefix, &spirv, shared_constants, types_registry);
let specialization_constants = structs::write_specialization_constants::<L>(
prefix,
&spirv,
shared_constants,
types_registry,
);

let load_name = if prefix.is_empty() {
format_ident!("load")
Expand Down Expand Up @@ -278,7 +282,7 @@ pub(super) fn reflect<'a>(
#specialization_constants
};

let structs = structs::write_structs(prefix, &spirv, types_meta, types_registry);
let structs = structs::write_structs::<L>(prefix, &spirv, types_meta, types_registry);

Ok((shader_code, structs))
}
Expand All @@ -304,7 +308,7 @@ impl From<SpirvError> for Error {
#[cfg(test)]
mod tests {
use super::*;
use crate::codegen::compile;
use crate::{codegen::compile, StdArray};
use shaderc::ShaderKind;
use std::path::{Path, PathBuf};
use vulkano::shader::{reflect, spirv::Spirv};
Expand Down Expand Up @@ -371,7 +375,12 @@ mod tests {
.unwrap();
let spirv = Spirv::new(comp.as_binary()).unwrap();
let res = std::panic::catch_unwind(|| {
structs::write_structs("", &spirv, &TypesMeta::default(), &mut HashMap::default())
structs::write_structs::<StdArray>(
"",
&spirv,
&TypesMeta::default(),
&mut HashMap::default(),
)
});
assert!(res.is_err());
}
Expand Down Expand Up @@ -400,7 +409,12 @@ mod tests {
)
.unwrap();
let spirv = Spirv::new(comp.as_binary()).unwrap();
structs::write_structs("", &spirv, &TypesMeta::default(), &mut HashMap::default());
structs::write_structs::<StdArray>(
"",
&spirv,
&TypesMeta::default(),
&mut HashMap::default(),
);
}
#[test]
fn test_wrap_alignment() {
Expand Down Expand Up @@ -432,7 +446,12 @@ mod tests {
)
.unwrap();
let spirv = Spirv::new(comp.as_binary()).unwrap();
structs::write_structs("", &spirv, &TypesMeta::default(), &mut HashMap::default());
structs::write_structs::<StdArray>(
"",
&spirv,
&TypesMeta::default(),
&mut HashMap::default(),
);
}

#[test]
Expand Down
Loading

0 comments on commit 78752a7

Please sign in to comment.