Skip to content

Best practice for per-draw uniform data #733

Closed
@math4tots

Description

@math4tots

I'm afraid this may be a noobie question given how common this use case must be, but for the same reason I figured it would be an easy question for some wgpu gurus.

What's the best practice for updating per-draw uniform data? In particular, I really just want to pass a 4x4 transformation matrix for each draw call.

Some possibilities:

  1. Tutorial here suggests that using a staging buffer is the way to go, but this path involves creating a new staging buffer for each draw, which seems kind of expensive. But if a second person were to tell me that this is the way to go, I'd be happy to accept this for the time being.
  2. Push constants: I think this would be exactly what I'd want if it were available, but thread here seems to suggest it might not be available anytime soon...
  3. The same thread above suggests dynamic offsets as a workaround. I might not be understanding this correctly, but it's not clear to me how changing offsets into the buffer will allow me to pass in arbitrary 4x4 matrices to my shaders.
  4. I've also come across this which compares push-constants with mapped buffers. I would guess that this would be like using the Buffer::map_read/map_write methods? I was kind of hoping to avoid them if I could for now, because of the situation with event loops described in the docs, but if someone tells me that that's the recommended way to do this, I might try it anyway.

Are any of the above possibilities the recommended way to update per-draw data with wgpu today?

Are there other better ways to update per-draw uniform data?

Metadata

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