-
Notifications
You must be signed in to change notification settings - Fork 250
Blocks (StorageBuffer and PushConstant) #289
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
Changes from all commits
cc8c2eb
3574288
4eb623a
7b3020e
0d3ec6d
127200f
780b319
512a2cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,54 @@ macro_rules! storage_class { | |
} | ||
}; | ||
|
||
// Interior Block | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While the (Do keep in mind that this is intended to be a quick hack fix before we're able to fully implement the bindings RFC, as that will replace this whole system with something much more elegant) |
||
($(#[$($meta:meta)+])* block $block:ident storage_class $name:ident ; $($tt:tt)*) => { | ||
|
||
#[spirv(block)] | ||
#[allow(unused_attributes)] | ||
pub struct $block <T> { | ||
value: T | ||
} | ||
|
||
$(#[$($meta)+])* | ||
#[allow(unused_attributes)] | ||
pub struct $name<'block, T> { | ||
block: &'block mut $block <T>, | ||
} | ||
|
||
impl<T: Copy> $name<'_, T> { | ||
/// Load the value into memory. | ||
#[inline] | ||
#[allow(unused_attributes)] | ||
#[spirv(really_unsafe_ignore_bitcasts)] | ||
pub fn load(&self) -> T { | ||
self.block.value | ||
} | ||
} | ||
|
||
storage_class!($($tt)*); | ||
}; | ||
|
||
// Methods available on writeable storage classes. | ||
($(#[$($meta:meta)+])* writeable block $block:ident storage_class $name:ident $($tt:tt)+) => { | ||
storage_class!($(#[$($meta)+])* block $block storage_class $name $($tt)+); | ||
|
||
impl <T: Copy> $name<'_, T> { | ||
/// Store the value in storage. | ||
#[inline] | ||
#[allow(unused_attributes)] | ||
#[spirv(really_unsafe_ignore_bitcasts)] | ||
pub fn store(&mut self, v: T) { | ||
self.block.value = v; | ||
} | ||
|
||
/// A convenience function to load a value into memory and store it. | ||
pub fn then(&mut self, then: impl FnOnce(T) -> T) { | ||
self.store((then)(self.load())); | ||
} | ||
} | ||
}; | ||
|
||
(;) => {}; | ||
() => {}; | ||
} | ||
|
@@ -112,7 +160,7 @@ storage_class! { | |
/// Intended to contain a small bank of values pushed from the client API. | ||
/// Variables declared with this storage class are read-only, and must not | ||
/// have initializers. | ||
#[spirv(push_constant)] storage_class PushConstant; | ||
#[spirv(push_constant)] block PushConstantBlock storage_class PushConstant; | ||
|
||
/// Atomic counter-specific memory. | ||
/// | ||
|
@@ -131,7 +179,7 @@ storage_class! { | |
/// | ||
/// Shared externally, readable and writable, visible across all functions | ||
/// in all invocations in all work groups. | ||
#[spirv(storage_buffer)] writeable storage_class StorageBuffer; | ||
#[spirv(storage_buffer)] writeable block StorageBufferBlock storage_class StorageBuffer; | ||
|
||
/// Used for storing arbitrary data associated with a ray to pass | ||
/// to callables. (Requires `SPV_KHR_ray_tracing` extension) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment isn't correct, right? It's the opposite of what's actually happening, it's only called in the ADT translation code. I believe this should be called at the entrypoint of
trans_type_impl
, in the same for loop thattrans_image
is called, and error when applied to a struct that results in a scalar or otherwise non-struct representation.