Skip to content

Support zero-length vertex/index buffers #3170

@jimblandy

Description

@jimblandy

The WebGPU specification says that setVertexBuffer and setIndexBuffer may be passed a size of zero, but the wgpu Rust API doesn't support this: the set_index_buffer and set_vertex_buffer methods take BufferSlice values, which are not allowed to be empty.

The wgpu-core APIs (used by Firefox and Deno) allow zero-size vertex/index buffers and bindings.

As explained in the documentation for hal::BufferBinding, some backends do not support zero-size bindings. Previously, this documentation stated that a zero-size hal::BufferBinding was not permitted, but this restriction was not honored elsewhere in the code. To handle zero-size bindings propertly, they need to be quashed or remapped to a non-zero size, either universally in wgpu-core, or in the specific backends that do not support them.

An incomplete attempt to clean up the handling of zero-length buffers was made in #7875 (later reverted in #7905) and #7911. The relevant code (in particular, the ShouldBeNonZeroExt trait and the type of the size member of hal::BufferBinding) should be cleaned up when this issue is addressed.

Note that although WebGPU allows zero-size vertex and index buffers, it does not allow zero-size buffer bindings in a bind group:

The bound part designated by bufferBinding.offset and bufferBinding.size resides inside the buffer and has non-zero size.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: apiIssues related to API surfacearea: correctnessWe're behaving incorrectlytype: bugSomething isn't working

    Type

    No type

    Projects

    Status

    Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions