feat: accept buffer shorthands directly in createBindGroup#2639
feat: accept buffer shorthands directly in createBindGroup#2639mvanhorn wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves createBindGroup(...) ergonomics by allowing TypeGPU buffer shorthands (root.createUniform, root.createMutable, root.createReadonly) to be provided directly as bind-group entry values, while keeping the underlying bind-group resolution logic unchanged by unwrapping shorthands to their .buffer at unwrap-time.
Changes:
- Extends
LayoutEntryToInputto acceptTgpuUniformfor uniform bindings andTgpuMutable/TgpuReadonlyfor storage bindings (andTgpuBufferShorthandin the widest branch). - Updates
TgpuBindGroupImpl.unwrapto detect buffer shorthands viaisBufferShorthandand resolve them to their underlying.buffer. - Adds unit tests verifying uniform and storage entries accept shorthands and produce the expected resolved
device.createBindGroup(...)call.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/typegpu/src/tgpuBindGroupLayout.ts | Expands bind-group input typing to include shorthands and unwraps shorthand values to their underlying buffers during bind group creation. |
| packages/typegpu/tests/bindGroupLayout.test.ts | Adds runtime tests covering shorthand acceptance for uniform and storage bind-group entries. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — accepts buffer shorthands (createUniform / createMutable / createReadonly) directly as entries in createBindGroup, removing the friction of manually unwrapping to .buffer.
- Widen
LayoutEntryToInput— addsTgpuUniformfor uniform entries,TgpuMutable | TgpuReadonlyfor storage entries, andTgpuBufferShorthand<AnyWgslData>in the widest-type branch. Purely additive, reusing the existingMemIdentity/UnwrapRuntimeConstructormachinery. - Unwrap shorthands in
TgpuBindGroupImpl.unwrap— a singleisBufferShorthandguard resolves the shorthand to its underlying.bufferbefore the existing validation and layout pipeline. The rest of the bind-group machinery is unchanged. - Tests — three new test cases covering uniform, mutable, and readonly shorthands passed directly to
createBindGroup, verifying the resolvedGPUBindGroupmatches the unwrapped-buffer equivalent.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

Summary
Lets buffer shorthands (
root.createUniform/root.createMutable/root.createReadonly) be passed directly as entries toroot.createBindGroup(...), without first unwrapping them back to the underlying buffer usage.Changes are purely additive on the input side:
LayoutEntryToInputnow acceptsTgpuUniformfor uniform entries andTgpuMutable/TgpuReadonlyfor storage entries (andTgpuBufferShorthandin the widest-type branch), reusing the existingMemIdentity/UnwrapRuntimeConstructormachinery so the same type guarantees apply.TgpuBindGroupImpl.unwrapdetects shorthands via the existingisBufferShorthandguard and resolves them to their underlyingbuffer, so the rest of the bind-group machinery is unchanged.All previously accepted entry types (raw buffer usages,
GPUBuffer, textures, samplers) continue to work unchanged. This covers the direct bind-group acceptance path only and does not depend on #2454.Why this matters
Closes #2477. The shorthands were introduced to make buffers easier to use, but bind groups still required unwrapping them by hand, which was an inconsistency the issue (and the maintainer discussion) flagged. Accepting them directly removes that friction and matches the ergonomics shorthands were meant to provide.
Testing
Added unit tests in
bindGroupLayout.test.tscovering:createUniformshorthand passed directly for a uniform entry, producing the same resolved bind group as the unwrapped buffercreateMutableandcreateReadonlyshorthands accepted for storage entriesVerified locally (in
packages/typegpu):pnpm run test:types— passespnpm exec vitest run --project=!browser bindGroupLayout— 36/36 passoxlint --type-aware+oxfmt --checkon the touched files — cleanFixes #2477