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

[WIP] add #[spirv(typed_buffer)] for explicit SpirvType::InterfaceBlocks. #1014

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from

Conversation

eddyb
Copy link
Contributor

@eddyb eddyb commented Mar 21, 2023

Opened as draft because it's somewhat incomplete, but I want it out of the way for now.

This PR adds a TypedBuffer<T> "handle" type to spirv-std (comparable to Image types in some respects).
While not a perfect representation of the Vulkan/SPIR-V buffer model, we can't do much better for now.

With TypedBuffer<T>, we can now redefine the existing usage patterns:

#[spirv(fragment)]
fn main_fs(
    #[spirv(uniform,        descriptor_set = 0, binding = 0)]
    uniform_buffer: &MyConstData,
    #[spirv(storage_buffer, descriptor_set = 0, binding = 1)]
    storage_buffer: &mut [u32],
) {...}

as sugar1 for:
1 (which we will continue to support for the foreseeable future, presumably)

#[spirv(fragment)]
fn main_fs(
    #[spirv(uniform,        descriptor_set = 0, binding = 0)]
    uniform_buffer: &TypedBuffer<MyConstData>,
    #[spirv(storage_buffer, descriptor_set = 0, binding = 1)]
    storage_buffer: &mut TypedBuffer<[u32]>,
) {...}

(comparable to buffer { uint data[]; } storage_buffer; in GLSL)

That is, plain Rust references are used to describe a single buffer, with the Rust type (MyConstData or [u32]) being for the buffer contents, used to interpret the raw bytes (provided to the host, e.g. Vulkan, API).

Because the "buffer handle" is made explicit, specifying multiple buffers is unambiguous:

#[spirv(fragment)]
fn main_fs(
    #[spirv(uniform,        descriptor_set = 0, binding = 0)]
    uniform_buffers: &RuntimeArray<TypedBuffer<MyConstData>>,
    #[spirv(storage_buffer, descriptor_set = 0, binding = 1)]
    storage_buffers: &mut RuntimeArray<TypedBuffer<[u32]>>,
) {...}

(comparable to buffer { uint data[]; } storage_buffers[]; in GLSL)

In other words, each TypedBuffer Rust value corresponds exactly to one buffer descriptor (e.g. VkBuffer).


TODO(@eddyb): add changelog, tests, discuss UntypedBuffer (TypedBuffer<[u32]> wrapper), maybe deprecate ByteAddressibleBuffer (to rename it to ByteAddressibleView or something? unsure what's best here)

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.

2 participants