feat: Add buffer type aliases - #2787
Conversation
|
pkg.pr.new packages benchmark commit |
There was a problem hiding this comment.
Pull request overview
Adds explicit buffer type aliases that capture common usage-flag intersections, making user type annotations and API surface clearer while keeping the underlying TgpuBuffer behavior unchanged.
Changes:
- Introduces
TgpuUniformBuffer,TgpuStorageBuffer,TgpuVertexBuffer, andTgpuIndexBufferas named aliases forTgpuBuffer<T> & <UsageFlag>. - Exports
TgpuBufferBindingalongside existing buffer binding types. - Updates docs and adds a type-level test to ensure
.$usage(...)results are compatible with the new aliases; ignores local.pnpm-store.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/typegpu/src/core/buffer/buffer.ts | Adds the new Tgpu*Buffer type aliases. |
| packages/typegpu/src/indexNamedExports.ts | Re-exports the new aliases and TgpuBufferBinding from the public entry points. |
| packages/typegpu/tests/buffer.test.ts | Adds a type-level regression test asserting .$usage(...) buffers extend the new aliases. |
| apps/typegpu-docs/src/content/docs/apis/buffers.mdx | Documents the new aliases with a concrete annotation example. |
| .gitignore | Ignores .pnpm-store created by local tooling. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Bundle size comparison (
|
| 🟢 Decreased | ➖ Unchanged | 🔴 Increased | ❔ Unknown |
|---|---|---|---|
| 0 | 322 | 0 | 0 |
import { ... } in PR vs import * as ... in PR (is the library tree-Shakeable?):
| Test | tsdown |
|---|---|
| tgpu_init.ts | 260.04 kB ( |
| tgpu_initFromDevice.ts | 259.51 kB ( |
| tgpu_resolve.ts | 165.41 kB ( |
| tgpu_resolveWithContext.ts | 165.35 kB ( |
| tgpu_bindGroupLayout.ts | 69.27 kB ( |
| tgpu_mutableAccessor.ts | 66.27 kB ( |
| tgpu_accessor.ts | 66.26 kB ( |
| tgpu_privateVar.ts | 65.61 kB ( |
| tgpu_workgroupVar.ts | 65.60 kB ( |
| tgpu_const.ts | 64.85 kB ( |
| tgpu_fn.ts | 38.45 kB ( |
| tgpu_fragmentFn.ts | 38.45 kB ( |
| tgpu_vertexFn.ts | 38.27 kB ( |
| tgpu_computeFn.ts | 37.97 kB ( |
| tgpu_vertexLayout.ts | 27.08 kB ( |
| tgpu_comptime.ts | 14.77 kB ( |
| tgpu_unroll.ts | 1.66 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.
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.91, 1.77, 4.26, 6.54, 7.40, 10.94, 22.40, 24.65]
line [0.88, 1.87, 3.75, 6.72, 7.26, 11.26, 21.30, 22.58]
line [0.89, 1.86, 4.15, 6.47, 8.29, 11.14, 21.41, 25.42]
---
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.32, 0.51, 0.67, 0.79, 1.06, 1.15, 1.35, 1.51]
line [0.28, 0.45, 0.64, 0.77, 1.02, 1.11, 1.26, 1.45]
line [0.34, 0.49, 0.67, 0.80, 1.06, 1.14, 1.40, 1.52]
---
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.84, 1.96, 3.55, 6.80, 12.80, 25.73, 53.91, 108.42]
line [0.96, 2.05, 3.98, 7.07, 12.46, 25.86, 54.74, 108.75]
line [0.86, 2.07, 4.06, 6.32, 12.85, 26.13, 55.47, 111.45]
|
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed PR #2787 "feat: Add buffer type aliases" at d4591b0.
- Added four named public type aliases for usage-flagged buffers in
packages/typegpu/src/core/buffer/buffer.ts. - Exported the new aliases and
TgpuBufferBindingfrompackages/typegpu/src/indexNamedExports.ts. - Added a type-level test asserting
.$usage(...)results are assignable to the corresponding aliases. - Documented the aliases in the buffers API docs.
- Added
.pnpm-storeto.gitignore.
The new aliases correctly mirror the existing TgpuBuffer<T> & UsageFlag patterns used throughout the codebase, the tests would fail if the aliases drifted from the actual $usage return types, and the public exports are wired through the named-export barrel. No runtime behavior changes.
Kimi K2 (free via Pullfrog for OSS) | 𝕏

Closes #2689
TgpuUniformBuffer,TgpuStorageBuffer,TgpuVertexBuffer, andTgpuIndexBufferas named aliases forTgpuBufferintersected with usage flagsTgpuBufferBindingalongside existing buffer binding types.pnpm-storeregularly created by the Cursor sandbox