Skip to content

Conversation

@beholdnec
Copy link
Contributor

CAUTION!
This is a draft PR. It has not been fully tested. This code is awaiting review before it can be merged.

Connections
Addresses #6779. Some developers would like for wgpu not to panic when 0-length buffer slices exist.

Description
wgpu currently panics if an empty buffer slice (length 0) is created. The code currently has contradictory comments about whether empty buffer slices are allowed to exist or not. This PR makes it so empty buffer slices can be created, but not mapped or referenced by set_index_buffer or set_vertex_buffer.

Testing
Tests in buffer.rs have been modified to accept zero-length buffer slices. All tests pass.

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy --tests. If applicable, add:
    • --target wasm32-unknown-unknown
  • Run cargo xtask test to run tests.
  • If this contains user-facing changes, add a CHANGELOG.md entry.

@beholdnec
Copy link
Contributor Author

Open questions:

  • should we silently accept empty slices instead of panicking? If so, which methods should accept empty slices?
  • an empty buffer slice could be a logic error, and this PR can potentially make such errors less detectable. Is this still desirable for developers?

@beholdnec beholdnec marked this pull request as ready for review November 12, 2025 21:54
@andyleiserson
Copy link
Contributor

Related: #3170

The WebGPU spec allows zero-size bindings in places where we currently don't. I think that answers the question of whether we should accept them, but we need to figure out how to handle them internally when the backend does not support them.

@beholdnec beholdnec marked this pull request as draft November 19, 2025 23:49
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