feat: Allow buffer bindings in bind groups#2727
Conversation
|
pkg.pr.new packages benchmark commit |
Bundle size comparison (
|
| 🟢 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 ( |
| tgpu_initFromDevice.ts | 256.02 kB ( |
| tgpu_resolve.ts | 163.90 kB ( |
| tgpu_resolveWithContext.ts | 163.83 kB ( |
| tgpu_bindGroupLayout.ts | 68.88 kB ( |
| tgpu_mutableAccessor.ts | 65.83 kB ( |
| tgpu_accessor.ts | 65.81 kB ( |
| tgpu_privateVar.ts | 65.23 kB ( |
| tgpu_workgroupVar.ts | 65.23 kB ( |
| tgpu_const.ts | 64.48 kB ( |
| tgpu_fn.ts | 38.07 kB ( |
| tgpu_fragmentFn.ts | 37.97 kB ( |
| tgpu_vertexFn.ts | 37.78 kB ( |
| tgpu_computeFn.ts | 37.49 kB ( |
| tgpu_vertexLayout.ts | 26.62 kB ( |
| tgpu_comptime.ts | 14.42 kB ( |
| tgpu_unroll.ts | 2.59 kB ( |
| tgpu_slot.ts | 1.54 kB ( |
| tgpu_lazy.ts | 1.19 kB ( |
If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu.
|
@pullfrog review |
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]
---
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]
---
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]
|
There was a problem hiding this comment.
✅ 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, andisReadonlyBindingtype guards inbufferBinding.tsand export them fromindexNamedExports.ts. - Make buffer bindings unwrappable by adding
TgpuBufferBindingoverloads toUnwrapperandTgpuRootImpl.unwrap, returning the wrapped buffer'sGPUBuffer. - Allow bindings in bind groups by widening
LayoutEntryToInputand handlingTgpuUniform/TgpuMutable/TgpuReadonlyinTgpuBindGroupImpl.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-errormismatches.
Kimi K2 (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ 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, andisReadonlyBindinginbufferBinding.tsand exported them publicly. - Made bindings unwrappable by extending the
Unwrapperinterface andTgpuRoot.unwrapimplementation. - Updated
LayoutEntryToInputso bind group layouts accept the matching binding type, and updatedTgpuBindGroupImpl.unwrapto unwrap binding resources while asserting storage access compatibility. - Added unit and type-level tests for unwrapping and bind group compatibility for each binding flavor.
Kimi K2 (free via Pullfrog for OSS) | 𝕏

Changes: