Skip to content

feat: Allow buffer bindings in bind groups#2727

Open
aleksanderkatan wants to merge 7 commits into
mainfrom
feat/allow-buffer-bindings-in-bind-groups
Open

feat: Allow buffer bindings in bind groups#2727
aleksanderkatan wants to merge 7 commits into
mainfrom
feat/allow-buffer-bindings-in-bind-groups

Conversation

@aleksanderkatan

Copy link
Copy Markdown
Contributor

Changes:

  • add 3 bindings type guards,
  • make bindings unwrappable,
  • allow bindings in bind groups.

@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown

pkg.pr.new

packages
Ready to be installed by your favorite package manager ⬇️

https://pkg.pr.new/software-mansion/TypeGPU/tgpu-gen@03ccafb1546f62c30015c79ae0fc20c47dbd74bd
https://pkg.pr.new/software-mansion/TypeGPU/tinyest-for-wgsl@03ccafb1546f62c30015c79ae0fc20c47dbd74bd
https://pkg.pr.new/software-mansion/TypeGPU/typegpu@03ccafb1546f62c30015c79ae0fc20c47dbd74bd
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/cli@03ccafb1546f62c30015c79ae0fc20c47dbd74bd
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/color@03ccafb1546f62c30015c79ae0fc20c47dbd74bd
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/gl@03ccafb1546f62c30015c79ae0fc20c47dbd74bd
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/noise@03ccafb1546f62c30015c79ae0fc20c47dbd74bd
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/radiance-cascades@03ccafb1546f62c30015c79ae0fc20c47dbd74bd
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/react@03ccafb1546f62c30015c79ae0fc20c47dbd74bd
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/sdf@03ccafb1546f62c30015c79ae0fc20c47dbd74bd
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/three@03ccafb1546f62c30015c79ae0fc20c47dbd74bd
https://pkg.pr.new/software-mansion/TypeGPU/unplugin-typegpu@03ccafb1546f62c30015c79ae0fc20c47dbd74bd

benchmark
view benchmark

commit
view commit

@github-actions

Copy link
Copy Markdown

Bundle size comparison (import * as ... in PR vs import * as ... in target):

🟢 Decreased ➖ Unchanged 🔴 Increased (max 0.15%) ❔ Unknown
0 300 21 0

import { ... } in PR vs import * as ... in PR (is the library tree-Shakeable?):

Test tsdown
tgpu_init.ts 256.53 kB ($${\color{green}-3.1\%}$$)
tgpu_initFromDevice.ts 256.02 kB ($${\color{green}-3.3\%}$$)
tgpu_resolve.ts 163.90 kB ($${\color{green}-38.1\%}$$)
tgpu_resolveWithContext.ts 163.83 kB ($${\color{green}-38.1\%}$$)
tgpu_bindGroupLayout.ts 68.88 kB ($${\color{green}-74.0\%}$$)
tgpu_mutableAccessor.ts 65.83 kB ($${\color{green}-75.1\%}$$)
tgpu_accessor.ts 65.81 kB ($${\color{green}-75.2\%}$$)
tgpu_privateVar.ts 65.23 kB ($${\color{green}-75.4\%}$$)
tgpu_workgroupVar.ts 65.23 kB ($${\color{green}-75.4\%}$$)
tgpu_const.ts 64.48 kB ($${\color{green}-75.7\%}$$)
tgpu_fn.ts 38.07 kB ($${\color{green}-85.6\%}$$)
tgpu_fragmentFn.ts 37.97 kB ($${\color{green}-85.7\%}$$)
tgpu_vertexFn.ts 37.78 kB ($${\color{green}-85.7\%}$$)
tgpu_computeFn.ts 37.49 kB ($${\color{green}-85.8\%}$$)
tgpu_vertexLayout.ts 26.62 kB ($${\color{green}-90.0\%}$$)
tgpu_comptime.ts 14.42 kB ($${\color{green}-94.6\%}$$)
tgpu_unroll.ts 2.59 kB ($${\color{green}-99.0\%}$$)
tgpu_slot.ts 1.54 kB ($${\color{green}-99.4\%}$$)
tgpu_lazy.ts 1.19 kB ($${\color{green}-99.6\%}$$)

If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu.

@aleksanderkatan

Copy link
Copy Markdown
Contributor Author

@pullfrog review

@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown

Resolution Time Benchmark

---
config:
  themeVariables:
    xyChart:
      plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
  title "Random Branching (🔴 PR | 🔵 main | 🟢 release)"
  x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
  y-axis "time (ms)"
  line [0.86, 1.70, 3.63, 5.56, 6.36, 12.22, 21.38, 22.09]
  line [0.80, 1.69, 3.80, 6.12, 6.40, 11.39, 19.89, 22.26]
  line [0.83, 1.69, 3.69, 6.17, 7.51, 11.38, 20.58, 23.65]
Loading
---
config:
  themeVariables:
    xyChart:
      plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
  title "Linear Recursion (🔴 PR | 🔵 main | 🟢 release)"
  x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
  y-axis "time (ms)"
  line [0.30, 0.49, 0.70, 0.81, 1.03, 1.08, 1.27, 1.41]
  line [0.29, 0.51, 0.67, 0.75, 1.03, 1.09, 1.26, 1.33]
  line [0.29, 0.53, 0.68, 0.77, 1.02, 1.12, 1.34, 1.44]
Loading
---
config:
  themeVariables:
    xyChart:
      plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
  title "Full Tree (🔴 PR | 🔵 main | 🟢 release)"
  x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
  y-axis "time (ms)"
  line [0.78, 1.91, 3.37, 5.75, 11.67, 23.28, 50.25, 101.70]
  line [0.68, 1.96, 3.49, 5.77, 11.66, 24.39, 48.83, 102.34]
  line [0.86, 1.96, 3.60, 5.86, 11.17, 23.64, 50.90, 104.59]
Loading

@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 — allow TgpuMutable, TgpuReadonly, and TgpuUniform buffer bindings to be passed directly into bind group entries and unwrapped to their underlying GPUBuffer.

  • Add isUniformBinding, isMutableBinding, and isReadonlyBinding type guards in bufferBinding.ts and export them from indexNamedExports.ts.
  • Make buffer bindings unwrappable by adding TgpuBufferBinding overloads to Unwrapper and TgpuRootImpl.unwrap, returning the wrapped buffer's GPUBuffer.
  • Allow bindings in bind groups by widening LayoutEntryToInput and handling TgpuUniform / TgpuMutable / TgpuReadonly in TgpuBindGroupImpl.unwrap, with a runtime invariant that matches the storage access mode.
  • Add unit and type tests covering unwrap, allowed bind group use, and @ts-expect-error mismatches.

Pullfrog  | View workflow run | Using Kimi K2 (free via Pullfrog for OSS) | 𝕏

@aleksanderkatan aleksanderkatan marked this pull request as ready for review July 14, 2026 16:16
Copilot AI review requested due to automatic review settings July 14, 2026 16:16

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@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 — this PR lets buffer bindings (TgpuUniform, TgpuMutable, TgpuReadonly) be used directly as bind group entries instead of only raw buffers.

  • Added runtime type guards isUniformBinding, isMutableBinding, and isReadonlyBinding in bufferBinding.ts and exported them publicly.
  • Made bindings unwrappable by extending the Unwrapper interface and TgpuRoot.unwrap implementation.
  • Updated LayoutEntryToInput so bind group layouts accept the matching binding type, and updated TgpuBindGroupImpl.unwrap to unwrap binding resources while asserting storage access compatibility.
  • Added unit and type-level tests for unwrapping and bind group compatibility for each binding flavor.

Pullfrog  | View workflow run | Using Kimi K2 (free via Pullfrog for OSS) | 𝕏

@iwoplaza iwoplaza left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

:shipit:

@cieplypolar cieplypolar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

:shipit:

@reczkok reczkok 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.

:shipit:

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

5 participants