impr: Unify bufferShorthand and bufferUsage#2665
Conversation
|
pkg.pr.new packages benchmark commit |
Bundle size comparison (
|
| 🟢 Decreased (max -0.13%) | ➖ Unchanged | 🔴 Increased | ❔ Unknown |
|---|---|---|---|
| 21 | 299 | 0 | 0 |
import { ... } in PR vs import * as ... in PR (is the library tree-Shakeable?):
Click to reveal the results table (297 entries).
| Test | tsdown |
|---|---|
| d_Void.ts | 87.65 kB ( |
| d_sampler.ts | 87.66 kB ( |
| d_isPtr.ts | 87.65 kB ( |
| d_comparisonSampler.ts | 87.67 kB ( |
| d_isSizeAttrib.ts | 87.66 kB ( |
| d_isWgslArray.ts | 87.66 kB ( |
| d_isAlignAttrib.ts | 87.66 kB ( |
| d_isWgslStruct.ts | 87.66 kB ( |
| d_isAtomic.ts | 87.66 kB ( |
| d_isBuiltinAttrib.ts | 87.66 kB ( |
| d_isLocationAttrib.ts | 87.67 kB ( |
| d_isDecorated.ts | 87.66 kB ( |
| d_isInterpolateAttrib.ts | 87.67 kB ( |
| d_atomic.ts | 87.66 kB ( |
| d_ptrHandle.ts | 87.66 kB ( |
| d_ptrUniform.ts | 87.66 kB ( |
| d_ptrStorage.ts | 87.66 kB ( |
| d_ptrPrivate.ts | 87.66 kB ( |
| d_ptrFn.ts | 87.65 kB ( |
| d_ptrWorkgroup.ts | 87.66 kB ( |
| d_textureExternal.ts | 87.66 kB ( |
| d_textureStorage1d.ts | 87.67 kB ( |
| d_textureStorage2d.ts | 87.67 kB ( |
| d_textureStorage3d.ts | 87.67 kB ( |
| d_textureStorage2dArray.ts | 87.67 kB ( |
| d_isDisarray.ts | 87.66 kB ( |
| d_isUnstruct.ts | 87.66 kB ( |
| d_isLooseDecorated.ts | 87.67 kB ( |
| d_isLooseData.ts | 87.66 kB ( |
| d_isWgslData.ts | 87.66 kB ( |
| d_unstruct.ts | 87.66 kB ( |
| d_isData.ts | 87.66 kB ( |
| d_deepEqual.ts | 87.66 kB ( |
| d_struct.ts | 87.66 kB ( |
| d_ref.ts | 87.65 kB ( |
| std_discard.ts | 105.47 kB ( |
| std_isBeingTranspiled.ts | 105.48 kB ( |
| std_copy.ts | 105.47 kB ( |
| std_arrayLength.ts | 105.48 kB ( |
| std_getTargetShaderLanguage.ts | 105.49 kB ( |
| std_extensionEnabled.ts | 105.48 kB ( |
| std_range.ts | 105.47 kB ( |
| std_dpdx.ts | 105.47 kB ( |
| std_fwidthCoarse.ts | 105.48 kB ( |
| std_dpdxCoarse.ts | 105.47 kB ( |
| std_dpdyCoarse.ts | 105.47 kB ( |
| std_fwidthFine.ts | 105.47 kB ( |
| std_dpdxFine.ts | 105.47 kB ( |
| std_dpdyFine.ts | 105.47 kB ( |
| std_fwidth.ts | 105.47 kB ( |
| std_dpdy.ts | 105.47 kB ( |
| d_bool.ts | 87.65 kB ( |
| d_f16.ts | 87.65 kB ( |
| d_f32.ts | 87.65 kB ( |
| d_i32.ts | 87.65 kB ( |
| d_u32.ts | 87.65 kB ( |
| d_u16.ts | 87.65 kB ( |
| std_atomicLoad.ts | 105.47 kB ( |
| std_textureBarrier.ts | 105.48 kB ( |
| std_atomicStore.ts | 105.48 kB ( |
| std_workgroupBarrier.ts | 105.48 kB ( |
| std_storageBarrier.ts | 105.48 kB ( |
| std_atomicAdd.ts | 105.47 kB ( |
| std_atomicAnd.ts | 105.47 kB ( |
| std_atomicMax.ts | 105.47 kB ( |
| std_atomicMin.ts | 105.47 kB ( |
| std_atomicSub.ts | 105.47 kB ( |
| std_atomicXor.ts | 105.47 kB ( |
| std_atomicOr.ts | 105.47 kB ( |
| d_textureDepth2d.ts | 87.66 kB ( |
| d_textureDepthCube.ts | 87.67 kB ( |
| d_texture1d.ts | 87.66 kB ( |
| d_texture2d.ts | 87.66 kB ( |
| d_texture3d.ts | 87.66 kB ( |
| d_textureDepth2dArray.ts | 87.67 kB ( |
| d_textureCube.ts | 87.66 kB ( |
| d_textureDepthCubeArray.ts | 87.67 kB ( |
| d_textureDepthMultisampled2d.ts | 87.67 kB ( |
| d_texture2dArray.ts | 87.66 kB ( |
| d_textureCubeArray.ts | 87.67 kB ( |
| d_textureMultisampled2d.ts | 87.67 kB ( |
| d_disarrayOf.ts | 87.66 kB ( |
| d_vec2b.ts | 87.65 kB ( |
| d_vec2f.ts | 87.65 kB ( |
| d_vec2h.ts | 87.65 kB ( |
| d_vec2i.ts | 87.65 kB ( |
| d_vec2u.ts | 87.65 kB ( |
| d_vec3b.ts | 87.65 kB ( |
| d_vec3f.ts | 87.65 kB ( |
| d_vec3h.ts | 87.65 kB ( |
| d_vec3i.ts | 87.65 kB ( |
| d_vec3u.ts | 87.65 kB ( |
| d_vec4b.ts | 87.65 kB ( |
| d_vec4f.ts | 87.65 kB ( |
| d_vec4h.ts | 87.65 kB ( |
| d_vec4i.ts | 87.65 kB ( |
| d_vec4u.ts | 87.65 kB ( |
| std_subgroupAdd.ts | 105.48 kB ( |
| std_subgroupBroadcastFirst.ts | 105.49 kB ( |
| std_subgroupExclusiveAdd.ts | 105.48 kB ( |
| std_subgroupExclusiveMul.ts | 105.48 kB ( |
| std_subgroupInclusiveAdd.ts | 105.48 kB ( |
| std_subgroupInclusiveMul.ts | 105.48 kB ( |
| std_subgroupShuffleDown.ts | 105.48 kB ( |
| std_subgroupShuffleXor.ts | 105.48 kB ( |
| std_subgroupBroadcast.ts | 105.48 kB ( |
| std_subgroupShuffleUp.ts | 105.48 kB ( |
| std_subgroupShuffle.ts | 105.48 kB ( |
| std_subgroupBallot.ts | 105.48 kB ( |
| std_subgroupElect.ts | 105.48 kB ( |
| std_subgroupAll.ts | 105.48 kB ( |
| std_subgroupAnd.ts | 105.48 kB ( |
| std_subgroupAny.ts | 105.48 kB ( |
| std_subgroupMax.ts | 105.48 kB ( |
| std_subgroupMin.ts | 105.48 kB ( |
| std_subgroupMul.ts | 105.48 kB ( |
| std_subgroupXor.ts | 105.48 kB ( |
| std_subgroupOr.ts | 105.47 kB ( |
| d_formatToWGSLType.ts | 87.67 kB ( |
| d_uint8.ts | 87.65 kB ( |
| d_unorm10_10_10_2.ts | 87.66 kB ( |
| d_unorm8x4_bgra.ts | 87.66 kB ( |
| d_float16x2.ts | 87.66 kB ( |
| d_float16x4.ts | 87.66 kB ( |
| d_float32x2.ts | 87.66 kB ( |
| d_float32x3.ts | 87.66 kB ( |
| d_float32x4.ts | 87.66 kB ( |
| d_snorm16x2.ts | 87.66 kB ( |
| d_snorm16x4.ts | 87.66 kB ( |
| d_unorm16x2.ts | 87.66 kB ( |
| d_unorm16x4.ts | 87.66 kB ( |
| d_sint16x2.ts | 87.66 kB ( |
| d_sint16x4.ts | 87.66 kB ( |
| d_sint32x2.ts | 87.66 kB ( |
| d_sint32x3.ts | 87.66 kB ( |
| d_sint32x4.ts | 87.66 kB ( |
| d_snorm8x2.ts | 87.66 kB ( |
| d_snorm8x4.ts | 87.66 kB ( |
| d_uint16x2.ts | 87.66 kB ( |
| d_uint16x4.ts | 87.66 kB ( |
| d_uint32x2.ts | 87.66 kB ( |
| d_uint32x3.ts | 87.66 kB ( |
| d_uint32x4.ts | 87.66 kB ( |
| d_unorm8x2.ts | 87.66 kB ( |
| d_unorm8x4.ts | 87.66 kB ( |
| d_float16.ts | 87.66 kB ( |
| d_float32.ts | 87.66 kB ( |
| d_sint8x2.ts | 87.66 kB ( |
| d_sint8x4.ts | 87.66 kB ( |
| d_snorm16.ts | 87.66 kB ( |
| d_uint8x2.ts | 87.66 kB ( |
| d_uint8x4.ts | 87.66 kB ( |
| d_unorm16.ts | 87.66 kB ( |
| d_sint16.ts | 87.66 kB ( |
| d_sint32.ts | 87.66 kB ( |
| d_snorm8.ts | 87.66 kB ( |
| d_uint16.ts | 87.66 kB ( |
| d_uint32.ts | 87.66 kB ( |
| d_unorm8.ts | 87.66 kB ( |
| d_sint8.ts | 87.65 kB ( |
| d_packedFormats.ts | 87.66 kB ( |
| d_isPackedData.ts | 87.66 kB ( |
| std_textureDimensions.ts | 105.48 kB ( |
| std_textureGather.ts | 105.48 kB ( |
| std_textureSampleBaseClampToEdge.ts | 105.49 kB ( |
| std_textureSampleCompareLevel.ts | 105.49 kB ( |
| std_textureSampleCompare.ts | 105.48 kB ( |
| std_textureSampleLevel.ts | 105.48 kB ( |
| std_textureSampleBias.ts | 105.48 kB ( |
| std_textureSampleGrad.ts | 105.48 kB ( |
| std_textureSample.ts | 105.48 kB ( |
| std_textureStore.ts | 105.48 kB ( |
| std_textureLoad.ts | 105.48 kB ( |
| d_alignmentOf.ts | 87.66 kB ( |
| std_translation4.ts | 105.48 kB ( |
| std_rotationX4.ts | 105.47 kB ( |
| std_rotationY4.ts | 105.47 kB ( |
| std_rotationZ4.ts | 105.47 kB ( |
| std_identity2.ts | 105.47 kB ( |
| std_identity3.ts | 105.47 kB ( |
| std_identity4.ts | 105.47 kB ( |
| std_scaling4.ts | 105.47 kB ( |
| d_isBuiltin.ts | 87.66 kB ( |
| d_sizeOf.ts | 87.66 kB ( |
| d_isContiguous.ts | 87.66 kB ( |
| d_getLongestContiguousPrefix.ts | 87.67 kB ( |
| d_arrayOf.ts | 87.66 kB ( |
| d_size.ts | 87.65 kB ( |
| d_align.ts | 87.65 kB ( |
| d_location.ts | 87.66 kB ( |
| d_interpolate.ts | 87.66 kB ( |
| d_invariant.ts | 87.66 kB ( |
| d_mat4x4f.ts | 87.66 kB ( |
| d_mat2x2f.ts | 87.66 kB ( |
| d_mat3x3f.ts | 87.66 kB ( |
| d_matToArray.ts | 87.66 kB ( |
| d_builtin.ts | 87.66 kB ( |
| std_unpack2x16float.ts | 105.48 kB ( |
| std_unpack4x8unorm.ts | 105.48 kB ( |
| std_pack2x16float.ts | 105.48 kB ( |
| std_pack4x8unorm.ts | 105.48 kB ( |
| std_bitcastU32toF32.ts | 105.48 kB ( |
| std_bitcastU32toI32.ts | 105.48 kB ( |
| std_neg.ts | 105.47 kB ( |
| std_bitShiftRight.ts | 105.48 kB ( |
| std_bitShiftLeft.ts | 105.48 kB ( |
| std_add.ts | 105.47 kB ( |
| std_div.ts | 105.47 kB ( |
| std_mod.ts | 105.47 kB ( |
| std_mul.ts | 105.47 kB ( |
| std_sub.ts | 105.47 kB ( |
| std_translate4.ts | 105.47 kB ( |
| std_rotateX4.ts | 105.47 kB ( |
| std_scale4.ts | 105.47 kB ( |
| std_rotateY4.ts | 105.47 kB ( |
| std_rotateZ4.ts | 105.47 kB ( |
| d_memoryLayoutOf.ts | 87.66 kB ( |
| std_and.ts | 105.47 kB ( |
| std_or.ts | 105.47 kB ( |
| std_select.ts | 105.47 kB ( |
| std_allEq.ts | 105.47 kB ( |
| std_all.ts | 105.47 kB ( |
| std_not.ts | 105.47 kB ( |
| std_eq.ts | 105.47 kB ( |
| std_lt.ts | 105.47 kB ( |
| std_ne.ts | 105.47 kB ( |
| std_isCloseTo.ts | 105.47 kB ( |
| std_any.ts | 105.47 kB ( |
| std_ge.ts | 105.47 kB ( |
| std_gt.ts | 105.47 kB ( |
| std_le.ts | 105.47 kB ( |
| std_dot4U8Packed.ts | 105.48 kB ( |
| std_length.ts | 105.47 kB ( |
| std_countTrailingZeros.ts | 105.48 kB ( |
| std_distance.ts | 105.47 kB ( |
| std_dot.ts | 105.47 kB ( |
| std_countLeadingZeros.ts | 105.48 kB ( |
| std_firstTrailingBit.ts | 105.48 kB ( |
| std_firstLeadingBit.ts | 105.48 kB ( |
| std_fract.ts | 105.47 kB ( |
| std_frexp.ts | 105.47 kB ( |
| std_modf.ts | 105.47 kB ( |
| std_quantizeToF16.ts | 105.48 kB ( |
| std_mix.ts | 105.47 kB ( |
| std_countOneBits.ts | 105.48 kB ( |
| std_dot4I8Packed.ts | 105.48 kB ( |
| std_determinant.ts | 105.48 kB ( |
| std_extractBits.ts | 105.48 kB ( |
| std_faceForward.ts | 105.48 kB ( |
| std_inverseSqrt.ts | 105.48 kB ( |
| std_reverseBits.ts | 105.48 kB ( |
| std_insertBits.ts | 105.47 kB ( |
| std_smoothstep.ts | 105.47 kB ( |
| std_normalize.ts | 105.47 kB ( |
| std_transpose.ts | 105.47 kB ( |
| std_saturate.ts | 105.47 kB ( |
| std_degrees.ts | 105.47 kB ( |
| std_radians.ts | 105.47 kB ( |
| std_reflect.ts | 105.47 kB ( |
| std_refract.ts | 105.47 kB ( |
| std_acosh.ts | 105.47 kB ( |
| std_asinh.ts | 105.47 kB ( |
| std_atan2.ts | 105.47 kB ( |
| std_atanh.ts | 105.47 kB ( |
| std_clamp.ts | 105.47 kB ( |
| std_cross.ts | 105.47 kB ( |
| std_floor.ts | 105.47 kB ( |
| std_ldexp.ts | 105.47 kB ( |
| std_round.ts | 105.47 kB ( |
| std_trunc.ts | 105.47 kB ( |
| std_acos.ts | 105.47 kB ( |
| std_asin.ts | 105.47 kB ( |
| std_atan.ts | 105.47 kB ( |
| std_ceil.ts | 105.47 kB ( |
| std_cosh.ts | 105.47 kB ( |
| std_exp2.ts | 105.47 kB ( |
| std_log2.ts | 105.47 kB ( |
| std_sign.ts | 105.47 kB ( |
| std_sinh.ts | 105.47 kB ( |
| std_sqrt.ts | 105.47 kB ( |
| std_step.ts | 105.47 kB ( |
| std_tanh.ts | 105.47 kB ( |
| std_abs.ts | 105.47 kB ( |
| std_cos.ts | 105.47 kB ( |
| std_exp.ts | 105.47 kB ( |
| std_fma.ts | 105.47 kB ( |
| std_log.ts | 105.47 kB ( |
| std_max.ts | 105.47 kB ( |
| std_min.ts | 105.47 kB ( |
| std_pow.ts | 105.47 kB ( |
| std_sin.ts | 105.47 kB ( |
| std_tan.ts | 105.47 kB ( |
| common_fullScreenTriangle.ts | 57.18 kB ( |
| common_writeSoA.ts | 57.17 kB ( |
| STATIC_allImports.ts | 289.06 kB ( |
| STATIC_d.ts | 87.65 kB ( |
| STATIC_std.ts | 105.46 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.97, 1.99, 4.26, 6.97, 7.77, 12.03, 23.53, 23.08]
line [0.91, 2.02, 4.23, 6.79, 7.91, 10.31, 21.70, 24.41]
line [0.95, 1.96, 4.37, 6.41, 7.56, 11.58, 22.50, 24.33]
---
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.31, 0.55, 0.72, 0.87, 1.22, 1.19, 1.53, 1.62]
line [0.35, 0.58, 0.74, 0.83, 1.15, 1.27, 1.49, 1.62]
line [0.32, 0.52, 0.71, 0.86, 1.14, 1.22, 1.49, 1.62]
---
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.99, 3.85, 6.45, 12.92, 27.03, 56.67, 116.13]
line [0.81, 2.13, 4.04, 6.40, 12.49, 26.29, 58.32, 116.84]
line [0.81, 2.11, 3.96, 6.46, 12.26, 26.35, 56.57, 116.30]
|
|
@pullfrog review |
There was a problem hiding this comment.
Important
Two regressions slipped into the buffer-usage/shorthand unification: the standalone uniform() constructor loses its generic type parameter, and the deprecated isBufferUsage() predicate is now permanently false because no runtime object reports resourceType === \'buffer-usage\'.
Reviewed changes — unified TgpuBufferShorthand with the old fixed buffer-usage implementation, deprecated the TgpuBufferUsage types, moved TgpuLaidOutBufferImpl to a new file, and updated buffer.as(...) + tests/examples to use the new TgpuMutable/TgpuReadonly/TgpuUniform names.
- Merged
TgpuFixedBufferUsageintoTgpuBufferShorthandinpackages/typegpu/src/core/buffer/bufferShorthand.ts;buffer.as(...)now returns a shorthand instance directly. - Deprecated
TgpuBufferUsagetypes inpackages/typegpu/src/core/buffer/bufferUsage.ts, keepingTgpuBufferUniform/TgpuBufferReadonly/TgpuBufferMutableas aliases with a TODO to remove in #2666. - Moved
TgpuLaidOutBufferImpltopackages/typegpu/src/core/buffer/laidOutBuffer.tsand changed itsresourceTypeto\'laid-out-buffer\'. - Updated tests/examples from
TgpuBufferMutable/TgpuBufferReadonlytoTgpuMutable/TgpuReadonly.
Kimi K2 (free via Pullfrog for OSS) | 𝕏
|
@pullfrog review |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — the unification of bufferShorthand and bufferUsage: TgpuFixedBufferUsage is merged into TgpuBufferShorthandImpl, constructors moved, old TgpuBuffer* types deprecated and left in bufferUsage.ts, TgpuLaidOutBufferImpl extracted into its own file, and the isUsableAs* runtime guards centralized in types.ts.
- Merges
TgpuFixedBufferUsageintoTgpuBufferShorthandImplinpackages/typegpu/src/core/buffer/bufferShorthand.ts. - Moves
mutable,readonly,uniformconstructors frombufferUsage.tstobufferShorthand.ts, sobuffer.as(...)now returns shorthand types (TgpuMutable,TgpuReadonly,TgpuUniform). - Deprecates
TgpuBufferUniform,TgpuBufferReadonly,TgpuBufferMutablewhile keeping them inbufferUsage.tsfor backward compatibility. - Moves
TgpuLaidOutBufferImpltopackages/typegpu/src/core/buffer/laidOutBuffer.tsand centralizesisUsableAs*guards inpackages/typegpu/src/types.ts. - Moves tests from
bufferUsage.test.tsintobufferShorthands.test.tsand updates thefluid-double-bufferingdocs example to the new type names.
Kimi K2 (free via Pullfrog for OSS) | 𝕏
| declare readonly [$repr]: Infer<TData>; | ||
|
|
||
| readonly [$internal]: { readonly dataType: TData }; | ||
| readonly resourceType = 'laid-out-buffer' as const; |
There was a problem hiding this comment.
ℹ️ The resourceType token changed from 'buffer-usage' to 'laid-out-buffer'. That's consistent with the file split and no internal code branches on it, but it's a public-facing breaking change worth calling out in the changelog/notes since any user code inspecting resourceType will observe the difference.
There was a problem hiding this comment.
Important
This PR introduces a type regression: the new TgpuMutable/TgpuReadonly/TgpuUniform shorthand types are no longer assignable to ResolvableObject, so tgpu.resolve([buffer.as('mutable')]) no longer type-checks. The deprecated TgpuBuffer* aliases also describe runtime values that no longer exist. Both should be fixed before merging.
Reviewed changes — unify bufferShorthand and bufferUsage by moving the usage implementation into TgpuBufferShorthandImpl, relocating TgpuLaidOutBufferImpl, deprecating the old TgpuBuffer* interfaces, and moving isUsableAs* guards to types.ts.
- Move usage behavior into
TgpuBufferShorthandImpl—buffer.$usage(...).as(...)now returns aTgpuBufferShorthand(e.g.TgpuMutable) instead of a separateTgpuBufferUsage. - Relocate
TgpuLaidOutBufferImpltopackages/typegpu/src/core/buffer/laidOutBuffer.ts. - Deprecate old buffer-usage interfaces —
TgpuBufferUniform,TgpuBufferReadonly,TgpuBufferMutableare kept as deprecated aliases. - Move type guards —
isBuffer,isUsableAs*,isGPUBufferare centralized intypes.ts. - Update tests and one example — usage tests moved into
bufferShorthands.test.tsandfluid-double-bufferingupdated toTgpuReadonly/TgpuMutable.
ℹ️ Stale tutorial code still uses deprecated TgpuBuffer* types
The triangle-to-boids tutorial source and code snippets still import and use TgpuBufferReadonly and TgpuBufferMutable. Since the PR already migrated fluid-double-buffering to TgpuReadonly/TgpuMutable, the tutorial should be updated for consistency.
apps/typegpu-docs/src/content/docs/tutorials/triangle-to-boids/index.mdx:1007-1008apps/typegpu-docs/src/content/docs/tutorials/triangle-to-boids/code/step7-typegpu.ts:8-9,51-52apps/typegpu-docs/src/content/docs/tutorials/triangle-to-boids/code/step8-typegpu.ts:8-9,50-51apps/typegpu-docs/src/content/docs/tutorials/triangle-to-boids/code/step9-typegpu.ts:13-14,76-77
Note: 1 inline comment(s) dropped because they did not anchor to lines inside the PR diff:
packages/typegpu/src/core/buffer/bufferShorthand.ts:27(RIGHT) — line 27 (RIGHT) is not inside a diff hunk
Kimi K2 (free via Pullfrog for OSS) | 𝕏
| /** | ||
| * @deprecated use TgpuUniform instead. | ||
| */ | ||
| export interface TgpuBufferUniform<TData extends BaseData> extends TgpuBufferUsage< |
There was a problem hiding this comment.
TgpuBufferUniform/Readonly/Mutable interfaces describe values that no longer exist at runtime. They declare resourceType: 'buffer-usage', a .usage property, and [$internal]: { dataType }, but buffer.as(...)/root.create*(...) now return TgpuBufferShorthandImpl objects with resourceType set to the usage name, no .usage, and [$internal] = true.
Technical details
# Deprecated buffer-usage aliases are structurally inconsistent
## Affected sites
- `packages/typegpu/src/core/buffer/bufferUsage.ts:12-30` — `TgpuBufferUsage` interface describes a non-existent runtime shape.
- `packages/typegpu/src/core/buffer/bufferUsage.ts:35-66` — deprecated aliases extend the inconsistent interface.
- `packages/typegpu/src/indexNamedExports.ts:75-79` — aliases are still publicly exported.
## Required outcome
Either the deprecated aliases must be type-compatible with the values actually returned by the API, or they must be removed entirely.
## Suggested approach
Redefine the deprecated types as direct aliases:
```ts
/** @deprecated use TgpuReadonly instead. */
export type TgpuBufferReadonly<TData extends BaseData> = TgpuReadonly<TData>;
```
If the follow-up (#2666) removes this file anyway, deleting them now is also acceptable given the breaking-change label.There was a problem hiding this comment.
I agree with Froggy here. I think we can both deprecate this type while still supporting existing code that supports it by just letting TgpuBufferUniform be an alias for TgpuUniform and so on.
There was a problem hiding this comment.
Important
This PR introduces a type regression: the new TgpuMutable/TgpuReadonly/TgpuUniform shorthand types are no longer assignable to ResolvableObject, so tgpu.resolve([buffer.as('mutable')]) no longer type-checks. The deprecated TgpuBuffer* aliases also describe runtime values that no longer exist. Both should be fixed before merging.
Reviewed changes — unify bufferShorthand and bufferUsage by moving the usage implementation into TgpuBufferShorthandImpl, relocating TgpuLaidOutBufferImpl, deprecating the old TgpuBuffer* interfaces, and moving isUsableAs* guards to types.ts.
- Move usage behavior into
TgpuBufferShorthandImpl—buffer.$usage(...).as(...)now returns aTgpuBufferShorthand(e.g.TgpuMutable) instead of a separateTgpuBufferUsage. - Relocate
TgpuLaidOutBufferImpltopackages/typegpu/src/core/buffer/laidOutBuffer.ts. - Deprecate old buffer-usage interfaces —
TgpuBufferUniform,TgpuBufferReadonly,TgpuBufferMutableare kept as deprecated aliases. - Move type guards —
isBuffer,isUsableAs*,isGPUBufferare centralized intypes.ts. - Update tests and one example — usage tests moved into
bufferShorthands.test.tsandfluid-double-bufferingupdated toTgpuReadonly/TgpuMutable.
ℹ️ Stale tutorial code still uses deprecated TgpuBuffer* types
The triangle-to-boids tutorial source and code snippets still import and use TgpuBufferReadonly and TgpuBufferMutable. Since the PR already migrated fluid-double-buffering to TgpuReadonly/TgpuMutable, the tutorial should be updated for consistency.
apps/typegpu-docs/src/content/docs/tutorials/triangle-to-boids/index.mdx:1007-1008apps/typegpu-docs/src/content/docs/tutorials/triangle-to-boids/code/step7-typegpu.ts:8-9,51-52apps/typegpu-docs/src/content/docs/tutorials/triangle-to-boids/code/step8-typegpu.ts:8-9,50-51apps/typegpu-docs/src/content/docs/tutorials/triangle-to-boids/code/step9-typegpu.ts:13-14,76-77
Kimi K2 (free via Pullfrog for OSS) | 𝕏
cieplypolar
left a comment
There was a problem hiding this comment.
I left some comments to address before merging.
There was a problem hiding this comment.
Important
The new commits fix the shorthand resolvability regression raised in the prior review, but the outstanding concern that deprecated TgpuBuffer* aliases no longer match runtime values remains unaddressed.
Reviewed changes — the two commits since the prior review fixed the shorthand resolvability regression and tightened test assertions.
- Made shorthand types resolvable by adding
TgpuBufferShorthand<BaseData>toResolvableObjectinpackages/typegpu/src/types.ts. - Added resolve coverage for
buffer.as('mutable'),buffer.as('readonly'), andbuffer.as('uniform')inpackages/typegpu/tests/bufferShorthands.test.ts. - Replaced generic
toThrow()assertions with inline snapshots of the expected error messages.
⚠️ Deprecated TgpuBuffer* aliases still don't match runtime values
The deprecated interfaces in packages/typegpu/src/core/buffer/bufferUsage.ts describe a resourceType: 'buffer-usage' runtime shape with a .usage property, but buffer.as(...) and root.create*(...) now return TgpuBufferShorthandImpl values whose resourceType is 'mutable', 'readonly', or 'uniform'. They therefore cannot be safely used as the deprecated types. This concern was raised in the prior Pullfrog review and has not changed with the new commits.
Technical details
# Deprecated `TgpuBuffer*` aliases are structurally inconsistent
## Affected sites
- `packages/typegpu/src/core/buffer/bufferUsage.ts:12-30` — `TgpuBufferUsage` interface describes a non-existent runtime shape.
- `packages/typegpu/src/core/buffer/bufferUsage.ts:35-66` — deprecated aliases extend the inconsistent interface.
- `packages/typegpu/src/indexNamedExports.ts:75-79` — aliases are still publicly exported.
## Required outcome
Either the deprecated aliases must be type-compatible with the values actually returned by the API, or they must be removed entirely.
## Open questions for the human
- Given the breaking-change label and the planned removal of this file in #2666, is keeping the aliases as migration guidance an acceptable trade-off?
- Should the follow-up issue explicitly delete these interfaces rather than maintaining them as structural dead-ends?Kimi K2 (free via Pullfrog for OSS) | 𝕏
@aleksanderkatan I agree. From what I understand, after |
I don't really get the type name |
@aleksanderkatan I can see that. Would |
|
Edit: #2693 |
There was a problem hiding this comment.
ℹ️ No critical issues — one minor import-consolidation nit inline.
Reviewed changes — this run checked the merge from origin/main and the small adaptations it required.
- Integrated upstream side-effect detection by passing
possibleSideEffects: falsetosnip(...)forTgpuBufferShorthandImpl.$gpuValueOfandTgpuLaidOutBufferImpl.$gpuValueOf. - Updated
tgpuBindGroupLayout.tsimports after the removal of deprecated pipeline/texture layout APIs, movingisBuffer,isUsableAsStorage, andisUsableAsUniformto./types.tsand importingTgpuLaidOutBufferImplfrom its new file.
Kimi K2 (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
ℹ️ No new issues in this commit.
Reviewed changes — the latest commit cleaned up the deprecated TgpuBuffer* aliases.
- Replaced deprecated
TgpuBuffer*interfaces inpackages/typegpu/src/core/buffer/bufferUsage.tswith direct type aliases toTgpuMutable/TgpuReadonly/TgpuUniform, so they now match the runtime values returned by the API.
Note: the import-consolidation nit from the previous incremental review and the informational resourceType breaking-change note remain open; they do not block this cleanup.
Kimi K2 (free via Pullfrog for OSS) | 𝕏
Co-authored-by: pullfrog[bot] <226033991+pullfrog[bot]@users.noreply.github.com>
|
Run failed. View the logs →
|

bufferUsage.tsfunctionality was moved.TgpuFixedBufferUsagewas merged intoTgpuBufferShorthand,TgpuLaidOutBufferImplwas moved to another file,I also moved
isUsableAs*guards totypes.ts.Buffer usages were not usable in bind group layouts, and so are shorthands (ATM), so there is no issue there.
buffer.$usage(...).as(...)now returns abufferShorthand. I think we should renameBufferShorthand, for example toFixedBuffer(in another PR so that this one is easier to review), what do you think?