-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d1e45cd
commit 9c2bc09
Showing
13 changed files
with
91 additions
and
153 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,46 @@ | ||
use proc_macro; | ||
use proc_macro::*; | ||
use quote::quote; | ||
|
||
#[proc_macro] | ||
pub fn shader(name: TokenStream) -> TokenStream { | ||
let const_case = name.to_string() | ||
.replace([' ', '-'], "_") | ||
.to_uppercase(); | ||
let snake_case = const_case.to_lowercase(); | ||
let _pascal_case = snake_case | ||
.split('_') | ||
.map(|s| { | ||
let mut c = s.chars(); | ||
match c.next() { | ||
None => String::new(), | ||
Some(f) => f.to_uppercase().collect::<String>() + c.as_str(), | ||
} | ||
}) | ||
.collect::<String>(); | ||
let function = proc_macro2::Ident::new(&snake_case, proc_macro2::Span::call_site()); | ||
let module = proc_macro2::Ident::new(&snake_case, proc_macro2::Span::call_site()); | ||
let constant = proc_macro2::Ident::new(&const_case, proc_macro2::Span::call_site()); | ||
let code = quote! { | ||
mod #module; | ||
|
||
#[spirv(fragment)] | ||
pub fn #function( | ||
#[spirv(frag_coord)] in_frag_coord: Vec4, | ||
#[spirv(push_constant)] constants: &Constants, | ||
output: &mut Vec4, | ||
) { | ||
let frag_coord = vec2(in_frag_coord.x, in_frag_coord.y); | ||
*output = #module::#function(constants, frag_coord); | ||
} | ||
|
||
#[cfg(not(target_arch = "spirv"))] | ||
#[allow(dead_code)] | ||
pub const #constant: &RawShader = &RawShader { | ||
shader_type: ShaderType::Pixel, | ||
crate_name: env!("CARGO_CRATE_NAME"), | ||
entry_point: stringify!(#function), | ||
}; | ||
}; | ||
|
||
code.into() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters