Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more support for cgmath and nalgebra types #2107

Merged
merged 1 commit into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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