From efb6dcdc2f554abbb35868430adbb8a3c4c93d02 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Mon, 2 May 2016 11:18:26 +0200 Subject: [PATCH] Add buffer_slice_field! macro --- TROUBLES.md | 6 ------ vulkano/src/buffer/mod.rs | 10 ++++++++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/TROUBLES.md b/TROUBLES.md index 1e70caa1..5b3e60fb 100644 --- a/TROUBLES.md +++ b/TROUBLES.md @@ -2,12 +2,6 @@ - No way to store an object and its borrowing in the same struct. This is the reason why the whole API uses `Arc`s. -- No pointer-to-struct-member. When you request the GPU to perform an operation on some data, you have to give a pointer to the data that - must be manipulated. However regular Rust pointers can't be used, as the buffers are not necessarily in the memory accessible from your - program. Instead vulkano provides its own pointer-like struct named `BufferSlice`. The problem is that there is no way to safely convert - a `BufferSlice` (equivalent of a virtual `&Foo`), where `struct Foo { a: i32 }`, into a `BufferSlice` (equivalent of a virtual - `&i32`) pointing to the `a` member. - - Lack of plugins means that you have to use a build script to compile your shaders instead of inlining them directly where they are used. In addition to this, lots of existing macros would be much simpler to implement with plugins. The code generated by macros is currently inefficient because using the efficient way would make the code very difficult to read. diff --git a/vulkano/src/buffer/mod.rs b/vulkano/src/buffer/mod.rs index 3ece6238..689265a4 100644 --- a/vulkano/src/buffer/mod.rs +++ b/vulkano/src/buffer/mod.rs @@ -232,6 +232,16 @@ impl<'a, T, B: 'a> From> for BufferSlice<'a, [T], B> } } +/// Takes a `BufferSlice` that points to a struct, and returns a `BufferSlice` that points to +/// a specific field of that struct. +#[macro_export] +macro_rules! buffer_slice_field { + ($slice:expr, $field:ident) => ( + // TODO: add #[allow(unsafe_code)] when that's allowed + unsafe { $slice.slice_custom(|s| &s.$field) } + ) +} + #[cfg(test)] mod tests { // TODO: restore these tests