Skip to content

feat: accept buffer shorthands directly in createBindGroup#2639

Open
mvanhorn wants to merge 1 commit into
software-mansion:mainfrom
mvanhorn:feat/2477-buffer-shorthands-bind-groups
Open

feat: accept buffer shorthands directly in createBindGroup#2639
mvanhorn wants to merge 1 commit into
software-mansion:mainfrom
mvanhorn:feat/2477-buffer-shorthands-bind-groups

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

Summary

Lets buffer shorthands (root.createUniform / root.createMutable / root.createReadonly) be passed directly as entries to root.createBindGroup(...), without first unwrapping them back to the underlying buffer usage.

const uniform = root.createUniform(d.vec3f);

// before: had to unwrap to the buffer/usage
root.createBindGroup(layout, { foo: uniform.buffer });

// now: the shorthand is accepted directly
root.createBindGroup(layout, { foo: uniform });

Changes are purely additive on the input side:

  • LayoutEntryToInput now accepts TgpuUniform for uniform entries and TgpuMutable/TgpuReadonly for storage entries (and TgpuBufferShorthand in the widest-type branch), reusing the existing MemIdentity/UnwrapRuntimeConstructor machinery so the same type guarantees apply.
  • TgpuBindGroupImpl.unwrap detects shorthands via the existing isBufferShorthand guard and resolves them to their underlying buffer, 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.ts covering:

  • a createUniform shorthand passed directly for a uniform entry, producing the same resolved bind group as the unwrapped buffer
  • createMutable and createReadonly shorthands accepted for storage entries

Verified locally (in packages/typegpu):

  • pnpm run test:types — passes
  • pnpm exec vitest run --project=!browser bindGroupLayout — 36/36 pass
  • oxlint --type-aware + oxfmt --check on the touched files — clean

Fixes #2477

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 LayoutEntryToInput to accept TgpuUniform for uniform bindings and TgpuMutable/TgpuReadonly for storage bindings (and TgpuBufferShorthand in the widest branch).
  • Updates TgpuBindGroupImpl.unwrap to detect buffer shorthands via isBufferShorthand and 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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 — adds TgpuUniform for uniform entries, TgpuMutable | TgpuReadonly for storage entries, and TgpuBufferShorthand<AnyWgslData> in the widest-type branch. Purely additive, reusing the existing MemIdentity/UnwrapRuntimeConstructor machinery.
  • Unwrap shorthands in TgpuBindGroupImpl.unwrap — a single isBufferShorthand guard resolves the shorthand to its underlying .buffer before 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 resolved GPUBindGroup matches the unwrapped-buffer equivalent.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

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.

feat: Allow buffer shorthands (usages) directly in bind groups

2 participants