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

Added NonWritable + NonReadable Decorations. Fixes #689 #692

Closed

Conversation

charles-r-earp
Copy link
Contributor

Fixes #689.

This PR allows adding NonWritable and NonReadable decorations to StorageBuffers. This can be added to other types, Images for example. This is an opt in via attributes #[spirv(non_writable)] and #[spirv(non_readable)], and does not do any validation. Probably non_writable can be inferred from the function declaration but that can be addressed later.

It looks like this:

#![cfg_attr(
    target_arch = "spirv",
    no_std,
    feature(register_attr),
    register_attr(spirv)
)]
#![deny(warnings)]

use spirv_std::glam::UVec3;

#[repr(C)]
pub struct PushConsts {
    n: u32,
}

#[allow(unused)]
#[spirv(compute(threads(64)))]
pub fn add(
    #[spirv(global_invocation_id)] global_id: UVec3,
    #[spirv(storage_buffer, descriptor_set = 0, binding = 0, non_writable)] a: &[u32],
    #[spirv(storage_buffer, descriptor_set = 0, binding = 1, non_writable)] b: &[u32],
    #[spirv(storage_buffer, descriptor_set = 0, binding = 2, non_readable)] y: &mut [u32],
    #[spirv(push_constant)] push_consts: &PushConsts,
) {
    let gid = global_id.x as usize;
    if global_id.x < push_consts.n {
        y[gid] = a[gid] + b[gid];
    }
}

As far as validation, this could be done in the validation pass or through the type system, by adding a trait bound to the argument. But the former is probably the most robust way, but it has to do a recursive check against all the access chains as well. It would be nice if immutable arguments were declared non_writable automatically for known types at the very least. For example, &[T] where T: Copy should be able to be marked non_writable.

@khyperia
Copy link
Contributor

khyperia commented Aug 3, 2021

Unfortunately, as stated in the readme, we're not able to accept major feature contributions right now :( - hopefully we can reopen this later when we're a little more stable!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for NonReadable, NonWritable
2 participants