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

Closed
wants to merge 25 commits into 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)

@eddyb eddyb force-pushed the buffer-interface-block branch from fa61f1e to 8f10f2a Compare March 21, 2023 05:27
@eddyb eddyb mentioned this pull request Mar 22, 2023
@eddyb eddyb force-pushed the buffer-interface-block branch from 8f10f2a to d78df7e Compare June 4, 2023 15:14
@eddyb eddyb force-pushed the buffer-interface-block branch from d78df7e to e7be758 Compare November 10, 2023 05:41
@eddyb eddyb force-pushed the buffer-interface-block branch from e7be758 to 225f773 Compare November 25, 2023 09:48
@eddyb eddyb force-pushed the buffer-interface-block branch 4 times, most recently from 52445ce to e28b47f Compare August 4, 2024 15:17
@eddyb eddyb force-pushed the buffer-interface-block branch from e28b47f to 8ee360c Compare August 6, 2024 13:19
@eddyb eddyb force-pushed the buffer-interface-block branch from 8ee360c to 9d6b34f Compare August 9, 2024 01:03
@LykenSol LykenSol closed this by deleting the head repository Nov 7, 2024
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.

3 participants