-
Notifications
You must be signed in to change notification settings - Fork 187
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
Helper macro for including precompiled SPIR-V #245
base: master
Are you sure you want to change the base?
Conversation
7458b50
to
ae873e4
Compare
7b4736d
to
0b55642
Compare
Should help suppress the temptation to court UB via naive include_bytes. Implementation placed in the root because macros are always imported via the root and it'd be weird for the returned type to not be beside it.
I don't fully understand the purpose of this. We can already use |
This can be used in a |
Then it will do the stack allocation in a const context, which is probably also not what you want.
I think we should rather improve the API of rust also really should have a |
If you don't believe that will optimize it, you can use it to initialize a static and get a hard guarantee.
The API of that function is correct for what it's meant for, which is not fixing up
People keep doing this and getting it wrong, and if the allocation doesn't matter then I'm not sure what the problem with the macro is. Some SPIR-V won't blow your stack, in the unlikely event that it ends up there to begin with.
We've herein implemented this in a declarative macro, which has the substantial advantage of not requiring you to compile syn. Additionally, proc macros cannot yet provide equivalent path semantics as they don't know what file they've been invoked in. |
I think this #[macro_export]
macro_rules! include_spv {
($path:expr) => {{
static ALIGNED: &'static $crate::util::Align4<[u8]> = &$crate::util::Align4(*include_bytes!($path));
ALIGNED
}};
} And the example would be: let vertex_code: &Spirv = include_spv!("../../shader/triangle/vert.spv");
let vertex_shader_info = vk::ShaderModuleCreateInfo::builder().code(vertex_code); EDIT I stand corrected. @Ralith is right, this won't work in a const context. |
It doesn't, which is exactly why you needed to replace |
Should help suppress the temptation to court UB via naive include_bytes. Implementation placed in the root because macros are always imported via the root and it'd be weird for the returned type
to not be beside it.