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

Clearer error messages for private functions with #[spirv(fragment)] attribute #161

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
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,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;
Expand Down Expand Up @@ -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::<ItemFn>(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 {
Expand Down
4 changes: 2 additions & 2 deletions crates/spirv-std/src/byte_addressable_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(
pub unsafe fn buffer_load_intrinsic<T>(
buffer: &[u32],
// FIXME(eddyb) should be `usize`.
offset: u32,
Expand All @@ -26,7 +26,7 @@ unsafe fn buffer_load_intrinsic<T>(
// HACK(eddyb) try to prevent MIR inlining from breaking our intrinsics.
#[inline(never)]
#[spirv_std_macros::gpu_only]
unsafe fn buffer_store_intrinsic<T>(
pub unsafe fn buffer_store_intrinsic<T>(
buffer: &mut [u32],
// FIXME(eddyb) should be `usize`.
offset: u32,
Expand Down
Loading