Skip to content

Create a BufferBinding from a BufferSlice #6309

Open
@DCNick3

Description

TL;DR: I pass a BufferSlice in a bunch of places, but I can't use it to bind a buffer, since BufferBinding needs a Buffer reference.

Is your feature request related to a problem? Please describe.
While implementing a more opinionated graphics API wrapper around wgpu for my game engine, I've started using wgpu's BufferSlice to pass different buffers without giving up the ownership in a generic way.

It works fine for passing vertex and index buffers, but a problem occurred when I tried to use it to pass uniform buffers: AFAIU,
the only way to bind a uniform buffer is to construct a BufferBinding struct and pass it to the bind group descriptor.

BufferBinding, however, wants a reference to a Buffer, not BufferSlice. With BufferSlice not providing an API to get to its internally stored buffer reference, offset and size (the exact three things BufferBinding wants!), I have no good option to do it this way.

Implementation-wise they seem to be exactly the same: they store a reference to a buffer, start offset and an optional size. They just provide different APIs to use them with.

Describe the solution you'd like
I'd like any solution allowing me use BufferSlice to bind a uniform buffer without me having to refer back to the Buffer it originated from.

The easiest & non-backcompat breaking solution would be to expose the innards of the BufferSlice, allowing to construct a BufferBinding from them. Not sure it the best design, though.

An IMO better solution is replacing the usage of BufferBinding with BufferSlice. This would be a breaking change, but the expressiveness of API wouldn't be changed (instead of providing the offset and size directly, you would have to slice the buffer before passing it to the descriptor). If BufferBinding is to be removed, there will be no rust equivalent to WebGPU's GPUBufferBinding, so not sure if it will work for you.

Describe alternatives you've considered
Implementing a BufferSlice myself and adding conversion operations to wgpu BufferSlice and BufferBinding where needed.

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions