diff --git a/crates/spirv-std/macros/src/lib.rs b/crates/spirv-std/macros/src/lib.rs index 9ecc7aef8b..c5e7a0f3b6 100644 --- a/crates/spirv-std/macros/src/lib.rs +++ b/crates/spirv-std/macros/src/lib.rs @@ -76,7 +76,9 @@ 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; @@ -149,6 +151,12 @@ 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 let Ok(item_fn) = syn::parse::(item.clone()) { + if !matches!(item_fn.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 { diff --git a/crates/spirv-std/src/byte_addressable_buffer.rs b/crates/spirv-std/src/byte_addressable_buffer.rs index 0640e54bda..aefccfbcb2 100644 --- a/crates/spirv-std/src/byte_addressable_buffer.rs +++ b/crates/spirv-std/src/byte_addressable_buffer.rs @@ -6,7 +6,7 @@ use core::mem; // HACK(eddyb) try to prevent MIR inlining from breaking our intrinsics. #[inline(never)] #[spirv_std_macros::gpu_only] -unsafe fn buffer_load_intrinsic( +pub unsafe fn buffer_load_intrinsic( buffer: &[u32], // FIXME(eddyb) should be `usize`. offset: u32, @@ -26,7 +26,7 @@ unsafe fn buffer_load_intrinsic( // HACK(eddyb) try to prevent MIR inlining from breaking our intrinsics. #[inline(never)] #[spirv_std_macros::gpu_only] -unsafe fn buffer_store_intrinsic( +pub unsafe fn buffer_store_intrinsic( buffer: &mut [u32], // FIXME(eddyb) should be `usize`. offset: u32,