Repository navigation
feat: Buffer views - #3271
feat: Buffer views#3271reczkok wants to merge 10 commits into
Conversation
|
pkg.pr.new packages benchmark commit |
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.77, 1.55, 3.52, 5.21, 5.96, 9.35, 20.03, 22.35]
line [0.72, 1.53, 3.35, 5.06, 5.85, 9.26, 18.22, 21.47]
line [0.73, 1.48, 3.26, 5.30, 6.18, 10.70, 20.90, 21.50]
---
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.27, 0.43, 0.57, 0.68, 0.91, 0.97, 1.18, 1.25]
line [0.28, 0.45, 0.58, 0.68, 0.93, 1.00, 1.17, 1.20]
line [0.27, 0.40, 0.55, 0.65, 0.83, 0.88, 1.10, 1.19]
---
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.73, 1.80, 3.03, 5.19, 9.82, 21.31, 46.07, 91.60]
line [0.74, 1.78, 2.84, 5.48, 11.21, 20.88, 43.45, 89.11]
line [0.70, 1.70, 2.70, 5.69, 10.58, 20.83, 45.66, 91.49]
|
Bundle size comparison (
|
| 🟢 Decreased | ➖ Unchanged | 🔴 Increased (max 13.02%) | ❔ Unknown |
|---|---|---|---|
| 0 | 36 | 319 | 4 |
import * as ... in PR vs import * as ... in target (did bundle size increase?):
Click to reveal the results table (300 entries).
| Test | tsdown |
|---|---|
| STATIC_std.ts | 114.82 kB ( |
| d_struct.ts | 4.06 kB ( |
| STATIC_allImports.ts | 320.23 kB ( |
| STATIC_d.ts | 72.35 kB ( |
| d_arrayOf.ts | 33.95 kB ( |
| d_builtin.ts | 36.48 kB ( |
| d_deepEqual.ts | 23.01 kB ( |
| d_schemasEqualNominally.ts | 23.01 kB ( |
| d_schemasEqualStructurally.ts | 23.01 kB ( |
| d_bool.ts | 20.25 kB ( |
| d_f16.ts | 20.25 kB ( |
| d_f32.ts | 20.25 kB ( |
| d_i32.ts | 20.25 kB ( |
| d_u32.ts | 20.25 kB ( |
| d_ref.ts | 20.26 kB ( |
| d_u16.ts | 20.27 kB ( |
| d_abstractInt.ts | 20.33 kB ( |
| d_abstractFloat.ts | 20.33 kB ( |
| tgpu_resolveWithContext.ts | 162.09 kB ( |
| tgpu_resolve.ts | 162.16 kB ( |
| d_textureDepth2d.ts | 20.69 kB ( |
| d_textureDepthCube.ts | 20.70 kB ( |
| d_texture1d.ts | 20.71 kB ( |
| d_texture2d.ts | 20.71 kB ( |
| d_texture3d.ts | 20.71 kB ( |
| d_textureCube.ts | 20.71 kB ( |
| d_textureDepth2dArray.ts | 20.71 kB ( |
| d_textureDepthCubeArray.ts | 20.72 kB ( |
| d_textureDepthMultisampled2d.ts | 20.72 kB ( |
| d_texture2dArray.ts | 20.72 kB ( |
| d_textureCubeArray.ts | 20.73 kB ( |
| d_textureMultisampled2d.ts | 20.73 kB ( |
| std_isKnownAtComptime.ts | 20.87 kB ( |
| std_subgroupElect.ts | 21.44 kB ( |
| std_subgroupAll.ts | 21.45 kB ( |
| std_subgroupAny.ts | 21.45 kB ( |
| std_quadSwapX.ts | 21.45 kB ( |
| std_quadSwapY.ts | 21.45 kB ( |
| std_subgroupOr.ts | 21.45 kB ( |
| std_subgroupAdd.ts | 21.45 kB ( |
| std_subgroupAnd.ts | 21.45 kB ( |
| std_subgroupMax.ts | 21.45 kB ( |
| std_subgroupMin.ts | 21.45 kB ( |
| std_subgroupMul.ts | 21.45 kB ( |
| std_subgroupXor.ts | 21.45 kB ( |
| std_quadSwapDiagonal.ts | 21.46 kB ( |
| std_subgroupExclusiveAdd.ts | 21.47 kB ( |
| std_subgroupExclusiveMul.ts | 21.47 kB ( |
| std_subgroupInclusiveAdd.ts | 21.47 kB ( |
| std_subgroupInclusiveMul.ts | 21.47 kB ( |
| std_subgroupBroadcastFirst.ts | 21.47 kB ( |
| std_storageBarrier.ts | 21.49 kB ( |
| std_textureBarrier.ts | 21.49 kB ( |
| std_workgroupBarrier.ts | 21.50 kB ( |
| std_discard.ts | 21.50 kB ( |
| std_textureNumLayers.ts | 21.52 kB ( |
| std_textureNumLevels.ts | 21.52 kB ( |
| std_textureNumSamples.ts | 21.53 kB ( |
| std_typeOf.ts | 22.25 kB ( |
| std_textureSampleCompare.ts | 21.55 kB ( |
| std_textureSampleCompareLevel.ts | 21.57 kB ( |
| std_textureStore.ts | 21.57 kB ( |
| std_workgroupUniformLoad.ts | 21.59 kB ( |
| tgpu_comptime.ts | 21.60 kB ( |
| std_atomicLoad.ts | 21.63 kB ( |
| std_atomicOr.ts | 21.67 kB ( |
| std_atomicAdd.ts | 21.67 kB ( |
| std_atomicAnd.ts | 21.67 kB ( |
| std_atomicMax.ts | 21.67 kB ( |
| std_atomicMin.ts | 21.67 kB ( |
| std_atomicSub.ts | 21.67 kB ( |
| std_atomicXor.ts | 21.67 kB ( |
| std_atomicExchange.ts | 21.68 kB ( |
| std_atomicStore.ts | 21.71 kB ( |
| std_quadBroadcast.ts | 21.72 kB ( |
| std_arrayLength.ts | 21.72 kB ( |
| std_subgroupShuffleUp.ts | 21.72 kB ( |
| std_subgroupShuffle.ts | 21.72 kB ( |
| std_subgroupShuffleXor.ts | 21.72 kB ( |
| std_subgroupShuffleDown.ts | 21.73 kB ( |
| std_subgroupBroadcast.ts | 21.73 kB ( |
| d_sizeOf.ts | 32.97 kB ( |
| std_copy.ts | 21.75 kB ( |
| d_isContiguous.ts | 32.98 kB ( |
| d_getLongestContiguousPrefix.ts | 32.99 kB ( |
| d_isBuiltin.ts | 33.07 kB ( |
| std_extensionEnabled.ts | 21.82 kB ( |
| std_range.ts | 22.09 kB ( |
| std_isBeingTranspiled.ts | 22.13 kB ( |
| std_getShaderStage.ts | 22.19 kB ( |
| std_getTargetShaderLanguage.ts | 22.20 kB ( |
| d_disarrayOf.ts | 22.31 kB ( |
| d_size.ts | 34.74 kB ( |
| d_align.ts | 34.74 kB ( |
| d_location.ts | 34.74 kB ( |
| d_interpolate.ts | 34.74 kB ( |
| d_invariant.ts | 35.11 kB ( |
| tgpu_vertexLayout.ts | 35.00 kB ( |
| common_writeSoA.ts | 35.59 kB ( |
| d_memoryLayoutOf.ts | 36.56 kB ( |
| std_atomicCompareExchangeWeak.ts | 24.27 kB ( |
| common_fullScreenTriangle.ts | 49.15 kB ( |
| tgpu_initFromDevice.ts | 257.29 kB ( |
| tgpu_init.ts | 257.83 kB ( |
| tgpu_fn.ts | 47.40 kB ( |
| STATIC_tgpu.ts | 269.06 kB ( |
| std_subgroupBallot.ts | 27.92 kB ( |
| std_textureSampleBaseClampToEdge.ts | 28.00 kB ( |
| std_textureSampleGrad.ts | 28.01 kB ( |
| std_textureSampleBias.ts | 28.07 kB ( |
| d_uint8.ts | 28.21 kB ( |
| d_float16.ts | 28.21 kB ( |
| d_float16x2.ts | 28.21 kB ( |
| d_float16x4.ts | 28.21 kB ( |
| d_float32.ts | 28.21 kB ( |
| d_float32x2.ts | 28.21 kB ( |
| d_float32x3.ts | 28.21 kB ( |
| d_float32x4.ts | 28.21 kB ( |
| d_sint16.ts | 28.21 kB ( |
| d_sint16x2.ts | 28.21 kB ( |
| d_sint16x4.ts | 28.21 kB ( |
| d_sint32.ts | 28.21 kB ( |
| d_sint32x2.ts | 28.21 kB ( |
| d_sint32x3.ts | 28.21 kB ( |
| d_sint32x4.ts | 28.21 kB ( |
| d_sint8.ts | 28.21 kB ( |
| d_sint8x2.ts | 28.21 kB ( |
| d_sint8x4.ts | 28.21 kB ( |
| d_snorm16.ts | 28.21 kB ( |
| d_snorm16x2.ts | 28.21 kB ( |
| d_snorm16x4.ts | 28.21 kB ( |
| d_snorm8.ts | 28.21 kB ( |
| d_snorm8x2.ts | 28.21 kB ( |
| d_snorm8x4.ts | 28.21 kB ( |
| d_uint16.ts | 28.21 kB ( |
| d_uint16x2.ts | 28.21 kB ( |
| d_uint16x4.ts | 28.21 kB ( |
| d_uint32.ts | 28.21 kB ( |
| d_uint32x2.ts | 28.21 kB ( |
| d_uint32x3.ts | 28.21 kB ( |
| d_uint32x4.ts | 28.21 kB ( |
| d_uint8x2.ts | 28.21 kB ( |
| d_uint8x4.ts | 28.21 kB ( |
| d_unorm10_10_10_2.ts | 28.21 kB ( |
| d_unorm16.ts | 28.21 kB ( |
| d_unorm16x2.ts | 28.21 kB ( |
| d_unorm16x4.ts | 28.21 kB ( |
| d_unorm8.ts | 28.21 kB ( |
| d_unorm8x2.ts | 28.21 kB ( |
| d_unorm8x4.ts | 28.21 kB ( |
| d_unorm8x4_bgra.ts | 28.21 kB ( |
| std_textureSample.ts | 28.09 kB ( |
| std_textureSampleLevel.ts | 28.10 kB ( |
| std_textureGatherCompare.ts | 28.13 kB ( |
| std_textureDimensions.ts | 28.16 kB ( |
| d_formatToWGSLType.ts | 28.21 kB ( |
| d_packedFormats.ts | 28.23 kB ( |
| d_isPackedData.ts | 28.28 kB ( |
| std_textureGather.ts | 28.33 kB ( |
| STATIC_common.ts | 56.70 kB ( |
| d_alignmentOf.ts | 30.08 kB ( |
| tgpu_computeFn.ts | 46.50 kB ( |
| std_textureLoad.ts | 29.95 kB ( |
| tgpu_vertexFn.ts | 47.05 kB ( |
| tgpu_fragmentFn.ts | 47.24 kB ( |
| std_bitcast.ts | 30.73 kB ( |
| tgpu_accessor.ts | 68.39 kB ( |
| tgpu_mutableAccessor.ts | 68.40 kB ( |
| std_pack2x16float.ts | 31.74 kB ( |
| std_unpack2x16unorm.ts | 31.74 kB ( |
| std_unpack2x16float.ts | 31.75 kB ( |
| std_pack4xI8.ts | 31.76 kB ( |
| std_unpack4xI8.ts | 31.76 kB ( |
| std_pack4xU8.ts | 31.76 kB ( |
| std_unpack4xU8.ts | 31.76 kB ( |
| std_unpack2x16snorm.ts | 31.76 kB ( |
| std_unpack4x8unorm.ts | 31.78 kB ( |
| std_unpack4x8snorm.ts | 31.83 kB ( |
| std_pack2x16snorm.ts | 31.92 kB ( |
| std_pack2x16unorm.ts | 31.92 kB ( |
| std_pack4xU8Clamp.ts | 31.93 kB ( |
| std_pack4xI8Clamp.ts | 31.94 kB ( |
| std_pack4x8snorm.ts | 32.00 kB ( |
| std_pack4x8unorm.ts | 32.00 kB ( |
| std_identity2.ts | 34.42 kB ( |
| std_identity3.ts | 34.42 kB ( |
| std_identity4.ts | 34.42 kB ( |
| std_rotationX4.ts | 34.42 kB ( |
| std_rotationY4.ts | 34.42 kB ( |
| std_rotationZ4.ts | 34.42 kB ( |
| std_scaling4.ts | 34.42 kB ( |
| std_translation4.ts | 34.42 kB ( |
| d_matToArray.ts | 34.55 kB ( |
| std_dot4I8Packed.ts | 35.80 kB ( |
| std_dot4U8Packed.ts | 35.80 kB ( |
| std_firstLeadingBit.ts | 35.81 kB ( |
| std_determinant.ts | 35.89 kB ( |
| std_dpdxFine.ts | 35.89 kB ( |
| std_dpdyFine.ts | 35.89 kB ( |
| std_dpdxCoarse.ts | 35.90 kB ( |
| std_dpdyCoarse.ts | 35.90 kB ( |
| std_fwidthFine.ts | 35.90 kB ( |
| std_dpdx.ts | 35.90 kB ( |
| std_dpdy.ts | 35.90 kB ( |
| std_fwidthCoarse.ts | 35.90 kB ( |
| std_fwidth.ts | 35.91 kB ( |
| std_refract.ts | 35.91 kB ( |
| std_trunc.ts | 35.96 kB ( |
| std_reverseBits.ts | 35.97 kB ( |
| std_quantizeToF16.ts | 35.97 kB ( |
| std_countOneBits.ts | 35.97 kB ( |
| std_extractBits.ts | 35.98 kB ( |
| std_firstTrailingBit.ts | 35.98 kB ( |
| std_countLeadingZeros.ts | 35.99 kB ( |
| std_countTrailingZeros.ts | 35.99 kB ( |
| std_insertBits.ts | 35.99 kB ( |
| std_faceForward.ts | 35.99 kB ( |
| std_intdiv.ts | 36.00 kB ( |
| std_tan.ts | 36.04 kB ( |
| std_degrees.ts | 36.05 kB ( |
| std_radians.ts | 36.05 kB ( |
| std_inverseSqrt.ts | 36.08 kB ( |
| std_round.ts | 36.09 kB ( |
| std_step.ts | 36.22 kB ( |
| std_ldexp.ts | 36.22 kB ( |
| std_fma.ts | 36.22 kB ( |
| std_transpose.ts | 36.29 kB ( |
| std_not.ts | 36.45 kB ( |
| std_abs.ts | 36.46 kB ( |
| std_gt.ts | 36.83 kB ( |
| std_neg.ts | 36.51 kB ( |
| std_or.ts | 36.52 kB ( |
| std_and.ts | 36.60 kB ( |
| std_lt.ts | 36.60 kB ( |
| std_eq.ts | 36.61 kB ( |
| std_cos.ts | 36.63 kB ( |
| std_exp.ts | 36.63 kB ( |
| std_log.ts | 36.63 kB ( |
| std_sin.ts | 36.63 kB ( |
| std_exp2.ts | 36.63 kB ( |
| std_sign.ts | 36.63 kB ( |
| std_acos.ts | 36.63 kB ( |
| std_asin.ts | 36.63 kB ( |
| std_atan.ts | 36.63 kB ( |
| std_ceil.ts | 36.63 kB ( |
| std_cosh.ts | 36.63 kB ( |
| std_log2.ts | 36.63 kB ( |
| std_sinh.ts | 36.63 kB ( |
| std_sqrt.ts | 36.63 kB ( |
| std_tanh.ts | 36.63 kB ( |
| std_acosh.ts | 36.63 kB ( |
| std_asinh.ts | 36.63 kB ( |
| std_atanh.ts | 36.63 kB ( |
| std_floor.ts | 36.63 kB ( |
| std_fract.ts | 36.64 kB ( |
| std_ge.ts | 36.67 kB ( |
| std_ne.ts | 36.68 kB ( |
| std_le.ts | 36.75 kB ( |
| std_saturate.ts | 36.78 kB ( |
| std_pow.ts | 36.81 kB ( |
| std_atan2.ts | 36.82 kB ( |
| std_mix.ts | 37.18 kB ( |
| std_clamp.ts | 36.91 kB ( |
| std_max.ts | 36.93 kB ( |
| std_min.ts | 36.93 kB ( |
| std_smoothstep.ts | 37.03 kB ( |
| std_select.ts | 37.43 kB ( |
| std_mod.ts | 37.46 kB ( |
| std_div.ts | 37.50 kB ( |
| std_add.ts | 37.58 kB ( |
| std_frexp.ts | 38.54 kB ( |
| std_modf.ts | 38.67 kB ( |
| std_all.ts | 39.78 kB ( |
| std_bitShiftLeft.ts | 39.76 kB ( |
| std_bitShiftRight.ts | 39.77 kB ( |
| std_dot.ts | 40.06 kB ( |
| std_length.ts | 40.16 kB ( |
| std_any.ts | 40.60 kB ( |
| std_cross.ts | 40.27 kB ( |
| std_allEq.ts | 40.81 kB ( |
| tgpu_lazy.ts | 62.91 kB ( |
| tgpu_const.ts | 63.11 kB ( |
| std_isCloseTo.ts | 41.09 kB ( |
| tgpu_workgroupVar.ts | 63.69 kB ( |
| tgpu_privateVar.ts | 63.69 kB ( |
| std_normalize.ts | 41.18 kB ( |
| std_bitcastF32toU32.ts | 41.97 kB ( |
| std_bitcastU32toF32.ts | 41.97 kB ( |
| std_bitcastU32toI32.ts | 41.97 kB ( |
| std_mul.ts | 42.20 kB ( |
| std_rotateZ4.ts | 42.46 kB ( |
| std_translate4.ts | 42.46 kB ( |
| std_scale4.ts | 42.46 kB ( |
| std_rotateX4.ts | 42.46 kB ( |
| std_rotateY4.ts | 42.46 kB ( |
| std_sub.ts | 42.58 kB ( |
| d_buffer.ts | 1.03 kB |
| std_bufferArrayView.ts | 41.26 kB |
| std_bufferLength.ts | 42.40 kB |
| std_bufferView.ts | 41.26 kB |
If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu.
|
@pullfrog do a preliminary review |
There was a problem hiding this comment.
ℹ️ No critical issues — one minor validation gap worth a look.
Reviewed changes
d.bytes(n)schema (data/bytes.ts) — newWgslBufferschema resolving to WGSLbuffer<n>(or runtime-sizedbufferfor 0), with size/alignment/equality/layout/serialization wiring and struct/array/address-space guards.std.bufferView/std.bufferArrayView/std.bufferLength(std/bufferView.ts) — codegen-only builtins that reinterpret buffer bytes as host-shareable types, with alignment, fit, atomic, host-shareable and scope validation, plusstdexports.buffer_viewlanguage-feature plumbing (resolutionCtx.ts,wgslExtensions.ts,resolveData.ts,types.ts) —requireLanguageFeatureand arequires buffer_view;directive emitted ahead of the module.- For-of over pointer iterables (
tgsl/forOfUtils.ts) —getRangeSnippetsnow unwraps pointer data types (enables iterating abufferView-returned array). - Docs + example + tests — new
buffer-views.mdx, theshape-streamexample, andbytes/bufferView/serialization/generator tests.
I read the full diff, verified the relevant source paths (dualImpl, pinEref, ptr, array, resolveData, forOfUtils, dataIO, compiledIO, schemaMemoryLayout, schemasEqual), ran the new tests (bytes, std/bufferView, serializeDataSchema), the tgsl suite, and tsc --noEmit — all pass. I also checked the claims against the WGSL spec: the requires buffer_view; directive/feature name is correct, directive ordering relative to enable is unconstrained, and the alignment/MinTypeSize/invalid-pointer semantics line up with assertViewFits/minSizeOf.
The buffer<N> size rule is the one gap I found; detail inline.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
79f03d5 to
45d9dd2
Compare
45d9dd2 to
325e990
Compare
ab86c1d to
a1c5a32
Compare
a1c5a32 to
2214ecc
Compare
3ec897f to
bab7afe
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Pointer compatibility and decorated-schema validation gaps allow invalid WGSL to be generated.
4 open issues
What changed in this PR
Adds WGSL buffer views to TypeGPU, allowing shaders to interpret raw buffer bytes as typed data at runtime offsets.
Changes:
- Introduces
d.buffer, buffer-view built-ins, and language-feature checks. - Integrates raw buffers with bindings, memory layout, serialization, and CPU reads and writes.
- Adds tests, API documentation, and a packed-shapes example.
| File | Description |
|---|---|
| packages/typegpu/tests/wgslBuffer.test.ts | Tests buffer schemas, restrictions, and raw-byte operations. |
| packages/typegpu/tests/tgsl/wgslGenerator.test.ts | Tests iteration through array pointers. |
| packages/typegpu/tests/std/bufferView.test.ts | Tests view generation, validation, and mutability. |
| packages/typegpu/tests/serializeDataSchema.test.ts | Adds buffer-schema serialization coverage. |
| packages/typegpu/tests/bufferBindings.test.ts | Updates snapshots for reserved buffer names. |
| packages/typegpu/src/wgslExtensions.ts | Defines the buffer-view language feature. |
| packages/typegpu/src/types.ts | Adds language-feature requirements to resolution. |
| packages/typegpu/src/tgsl/wgslGenerator.ts | Validates buffer variable address spaces. |
| packages/typegpu/src/tgsl/forOfUtils.ts | Supports pointer-backed iteration ranges. |
| packages/typegpu/src/tgsl/conversion.ts | Adds size-based buffer-pointer compatibility. |
| packages/typegpu/src/tgpuBindGroupLayout.ts | Allows typed buffers in raw-buffer bindings. |
| packages/typegpu/src/std/index.ts | Exports buffer-view built-ins. |
| packages/typegpu/src/std/bufferView.ts | Implements views, length queries, and validation. |
| packages/typegpu/src/serial/schema.ts | Serializes and restores buffer schemas. |
| packages/typegpu/src/resolutionCtx.ts | Checks features and emits requires directives. |
| packages/typegpu/src/nameUtils.ts | Reserves buffer-view built-in names. |
| packages/typegpu/src/data/wgslTypes.ts | Adds buffer types and GPU pointer representations. |
| packages/typegpu/src/data/struct.ts | Rejects buffer-typed struct members. |
| packages/typegpu/src/data/schemasEqual.ts | Compares buffer schema sizes. |
| packages/typegpu/src/data/schemaMemoryLayout.ts | Defines raw-buffer memory layouts. |
| packages/typegpu/src/data/ptr.ts | Allows buffer schemas in supported pointer types. |
| packages/typegpu/src/data/partialIO.ts | Supports raw-byte patches. |
| packages/typegpu/src/data/index.ts | Exports buffer schemas. |
| packages/typegpu/src/data/dataIO.ts | Reads and writes raw buffer bytes. |
| packages/typegpu/src/data/buffer.ts | Defines sized and runtime-sized buffer schemas. |
| packages/typegpu/src/data/array.ts | Rejects buffer-typed array elements. |
| packages/typegpu/src/data/alignmentOf.ts | Defines buffer alignment. |
| packages/typegpu/src/core/variable/tgpuVariable.ts | Requires sizes for workgroup buffers. |
| packages/typegpu/src/core/resolve/resolveData.ts | Resolves buffer schemas to WGSL. |
| packages/typegpu-testing-utility/src/extendedIt.ts | Enables buffer views in mocked environments. |
| apps/typegpu-docs/tests/individual-example-tests/dispatch.test.ts | Updates reserved-name snapshots. |
| apps/typegpu-docs/src/examples/simple/packed-shapes/meta.json | Describes the packed-shapes example. |
| apps/typegpu-docs/src/examples/simple/packed-shapes/index.ts | Demonstrates runtime views over packed shapes. |
| apps/typegpu-docs/src/examples/simple/packed-shapes/index.html | Adds an unsupported-feature notice. |
| apps/typegpu-docs/src/content/docs/apis/buffer-views.mdx | Documents buffer-view APIs and usage. |
| apps/typegpu-docs/astro.config.mjs | Adds buffer views to documentation navigation. |
Review effort: Balanced
There was a problem hiding this comment.
ℹ️ No critical issues — two rough edges worth a look.
Reviewed changes — the complete diff of this PR (9 commits, 37 files), which adds WGSL buffer<N>/buffer schemas (d.buffer), the std.bufferView / std.bufferArrayView / std.bufferLength builtins, requires buffer_view; emission, host-side buffer I/O, docs, and a packed-shapes example.
d.bufferschema — newWgslBuffertype indata/buffer.ts(byteSize,0= runtime-sized) with size-multiple-of-4 validation and$validStorageSchema/$validUniformSchematokens; threaded throughresolveData,sizeOf/alignmentOf,schemasEqual,serial/schema,partialIO, anddataIO, and rejected as a struct property or array element.std.bufferViewfamily —std/bufferView.tsemits the WGSL builtins, checks schema host-shareability and comptime alignment/fit, and preserves read-only/mutable view semantics.requiresdirectives —resolutionCtx.ts/wgslExtensions.tsaddrequireLanguageFeatureandrequiredLanguageFeatures, emitted next toenabledirectives; resolution throws whenroot.enabledWgslLanguageFeatureslacksbuffer_view.- Type-level plumbing —
ptr.tsacceptsd.bufferin pointer constructors,tgsl/conversion.tsadds size-subtyping (fitsBufferParameter),tgpuBindGroupLayout.tswidensBoundSchemaford.bufferentries, andPtrgains$gpuRepr. for...ofover pointers —tgsl/forOfUtils.tsunwraps pointer iterables so buffer-view results iterate.- Tests / docs / example — new
tests/std/bufferView.test.tsandtests/wgslBuffer.test.ts, abuffer-viewsdocs page, and thepacked-shapesexample.
I verified the emitted WGSL against W3C WGSL §6.3/§17.14/§4.1.2: the bufferView<T>(&buf, offset), bufferArrayView<T>(&buf, offset, size), and bufferLength(&buf) call shapes, the requires buffer_view; syntax/placement, and the buffer/buffer<N> types all conform. Host-side read/write paths are byte-correct (no endianness swap, exact region, partial-write semantics match the tests).
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
bab7afe to
318d02a
Compare
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — the delta since the prior Pullfrog review (bab7afe → 318d02a). The branch was rebased, so the only net content change is the animate on gpu commit; every other file was already present at bab7afe.
- Reworked the
packed-shapesexample to animate on the GPU — shape motion moved into aMotionstruct with atimeuniform and atoLocalhelper, replacing the previous per-frame CPU buffer rewrites; shape colors are nowu32palette indices resolved against atgpu.constpalette in the shader, and the CPU side only writes once per scene. - Clarified
bufferArrayViewlength in the docs —buffer-views.mdxnow states the length isbyteSizedivided by the array stride (the element size rounded up to its alignment), matching WGSLStrideOf.
The example's manual offsets stay consistent with the CPU Scene struct layout: d.sizeOf(Circle)/d.sizeOf(Box) equal the corresponding array strides, and bufferArrayView sizes are exact stride multiples.
( ◦°^°◦) 🏴☠️
Ahoy, matey! I inspected the fresh commit — the shapes now dance on the GPU, and the view-length line in the docs be truthful. No leaks below the waterline, so I be givin' me approval.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏


(FYI this is not the feature discussed in #2816 proposal, this is the actual WebGPU feature)
d.buffer(n)resolves to the WGSLbuffer<n>type, andstd.bufferView,std.bufferArrayViewandstd.bufferLengthread and write its bytes as any host-shareable type at runtime offsets