Skip to content

Commit

Permalink
detect if functions are public for fragment shaders
Browse files Browse the repository at this point in the history
  • Loading branch information
zanciks committed Nov 27, 2024
1 parent d3f9af7 commit f192cc4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion crates/spirv-std/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ mod image;
use proc_macro::TokenStream;
use proc_macro2::{Delimiter, Group, Ident, Span, TokenTree};

use syn::{punctuated::Punctuated, spanned::Spanned, visit_mut::VisitMut, ItemFn, Token};
use syn::{punctuated::Punctuated, spanned::Spanned, visit_mut::VisitMut, ItemFn, Token, Visibility};

use quote::{quote, ToTokens};
use std::fmt::Write;
Expand Down Expand Up @@ -149,6 +149,14 @@ pub fn spirv(attr: TokenStream, item: TokenStream) -> TokenStream {
let attr: proc_macro2::TokenStream = attr.into();
tokens.extend(quote! { #[cfg_attr(target_arch="spirv", rust_gpu::spirv(#attr))] });

if attr.to_string().trim() == "fragment" {
let item_clone = item.clone();
let input = syn::parse_macro_input!(item_clone as ItemFn);
if !matches!(input.vis, Visibility::Public(_)) {
panic!("The `spirv` macro can only be applied to public functions.");
}
}

let item: proc_macro2::TokenStream = item.into();
for tt in item {
match tt {
Expand Down

0 comments on commit f192cc4

Please sign in to comment.