mirror of
https://github.com/vulkano-rs/vulkano.git
synced 2024-11-21 22:34:43 +00:00
Use include_bytes! in shader! for automatic recompilation (#1523)
This commit is contained in:
parent
eb21fea03b
commit
fc2e470d14
@ -191,6 +191,7 @@ pub(super) fn reflect(
|
||||
name: &str,
|
||||
spirv: &[u32],
|
||||
types_meta: TypesMeta,
|
||||
full_path: Option<&str>,
|
||||
dump: bool,
|
||||
) -> Result<TokenStream, Error> {
|
||||
let struct_name = Ident::new(&name, Span::call_site());
|
||||
@ -255,6 +256,12 @@ pub(super) fn reflect(
|
||||
}
|
||||
}
|
||||
|
||||
let include_bytes = full_path.map(|s| quote! {
|
||||
// using include_bytes here ensures that changing the shader will force recompilation.
|
||||
// The bytes themselves can be optimized out by the compiler as they are unused.
|
||||
let _bytes = ::std::include_bytes!( #s );
|
||||
}).unwrap_or(TokenStream::new());
|
||||
|
||||
let structs = structs::write_structs(&doc, &types_meta);
|
||||
let specialization_constants = spec_consts::write_specialization_constants(&doc, &types_meta);
|
||||
let uses = &types_meta.uses;
|
||||
@ -308,6 +315,8 @@ pub(super) fn reflect(
|
||||
pub fn load(device: ::std::sync::Arc<::vulkano::device::Device>)
|
||||
-> Result<#struct_name, ::vulkano::OomError>
|
||||
{
|
||||
#include_bytes
|
||||
|
||||
#( #cap_checks )*
|
||||
static WORDS: &[u32] = &[ #( #spirv ),* ];
|
||||
|
||||
|
@ -574,23 +574,27 @@ pub fn shader(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||
"Shader",
|
||||
unsafe { from_raw_parts(bytes.as_slice().as_ptr() as *const u32, bytes.len() / 4) },
|
||||
input.types_meta,
|
||||
None,
|
||||
input.dump,
|
||||
)
|
||||
.unwrap()
|
||||
.into()
|
||||
} else {
|
||||
let (path, source_code) = match input.source_kind {
|
||||
SourceKind::Src(source) => (None, source),
|
||||
SourceKind::Path(path) => (Some(path.clone()), {
|
||||
let (path, full_path, source_code) = match input.source_kind {
|
||||
SourceKind::Src(source) => (None, None, source),
|
||||
SourceKind::Path(path) => {
|
||||
let full_path = root_path.join(&path);
|
||||
|
||||
if full_path.is_file() {
|
||||
(Some(path.clone()),
|
||||
Some(full_path.to_str()
|
||||
.expect("Path {:?} could not be converted to UTF-8").to_owned()),
|
||||
read_file_to_string(&full_path)
|
||||
.expect(&format!("Error reading source from {:?}", path))
|
||||
.expect(&format!("Error reading source from {:?}", path)))
|
||||
} else {
|
||||
panic!("File {:?} was not found ; note that the path must be relative to your Cargo.toml", path);
|
||||
}
|
||||
}),
|
||||
}
|
||||
SourceKind::Bytes(_) => unreachable!(),
|
||||
};
|
||||
|
||||
@ -617,7 +621,7 @@ pub fn shader(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||
Err(e) => panic!("{}", e.replace("(s): ", "(s):\n")),
|
||||
};
|
||||
|
||||
codegen::reflect("Shader", content.as_binary(), input.types_meta, input.dump)
|
||||
codegen::reflect("Shader", content.as_binary(), input.types_meta, full_path.as_deref(), input.dump)
|
||||
.unwrap()
|
||||
.into()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user