Skip to content

feat: Buffer views - #3271

Open
reczkok wants to merge 10 commits into
mainfrom
feat/wgsl-buffer-view
Open

reczkok wants to merge 10 commits into
mainfrom
feat/wgsl-buffer-view

Conversation

@reczkok

@reczkok reczkok commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Oct 24, 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@318d02a90cefb3f00f113aef9a157e4f1a9b235c
https://pkg.pr.new/software-mansion/TypeGPU/typegpu@318d02a90cefb3f00f113aef9a157e4f1a9b235c
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/cli@318d02a90cefb3f00f113aef9a157e4f1a9b235c
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/gl@318d02a90cefb3f00f113aef9a157e4f1a9b235c

benchmark
view benchmark

commit
view commit

@github-actions

github-actions Bot commented Oct 24, 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.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]
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.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]
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.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]
Loading

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

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

🟢 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 ($${\color{red}+13.0\%}$$)
d_struct.ts 4.06 kB ($${\color{red}+4.6\%}$$)
STATIC_allImports.ts 320.23 kB ($${\color{red}+1.5\%}$$)
STATIC_d.ts 72.35 kB ($${\color{red}+1.3\%}$$)
d_arrayOf.ts 33.95 kB ($${\color{red}+1.2\%}$$)
d_builtin.ts 36.48 kB ($${\color{red}+1.2\%}$$)
d_deepEqual.ts 23.01 kB ($${\color{red}+1.1\%}$$)
d_schemasEqualNominally.ts 23.01 kB ($${\color{red}+1.1\%}$$)
d_schemasEqualStructurally.ts 23.01 kB ($${\color{red}+1.1\%}$$)
d_bool.ts 20.25 kB ($${\color{red}+1.1\%}$$)
d_f16.ts 20.25 kB ($${\color{red}+1.1\%}$$)
d_f32.ts 20.25 kB ($${\color{red}+1.1\%}$$)
d_i32.ts 20.25 kB ($${\color{red}+1.1\%}$$)
d_u32.ts 20.25 kB ($${\color{red}+1.1\%}$$)
d_ref.ts 20.26 kB ($${\color{red}+1.1\%}$$)
d_u16.ts 20.27 kB ($${\color{red}+1.1\%}$$)
d_abstractInt.ts 20.33 kB ($${\color{red}+1.1\%}$$)
d_abstractFloat.ts 20.33 kB ($${\color{red}+1.1\%}$$)
tgpu_resolveWithContext.ts 162.09 kB ($${\color{red}+1.1\%}$$)
tgpu_resolve.ts 162.16 kB ($${\color{red}+1.1\%}$$)
d_textureDepth2d.ts 20.69 kB ($${\color{red}+1.0\%}$$)
d_textureDepthCube.ts 20.70 kB ($${\color{red}+1.0\%}$$)
d_texture1d.ts 20.71 kB ($${\color{red}+1.0\%}$$)
d_texture2d.ts 20.71 kB ($${\color{red}+1.0\%}$$)
d_texture3d.ts 20.71 kB ($${\color{red}+1.0\%}$$)
d_textureCube.ts 20.71 kB ($${\color{red}+1.0\%}$$)
d_textureDepth2dArray.ts 20.71 kB ($${\color{red}+1.0\%}$$)
d_textureDepthCubeArray.ts 20.72 kB ($${\color{red}+1.0\%}$$)
d_textureDepthMultisampled2d.ts 20.72 kB ($${\color{red}+1.0\%}$$)
d_texture2dArray.ts 20.72 kB ($${\color{red}+1.0\%}$$)
d_textureCubeArray.ts 20.73 kB ($${\color{red}+1.0\%}$$)
d_textureMultisampled2d.ts 20.73 kB ($${\color{red}+1.0\%}$$)
std_isKnownAtComptime.ts 20.87 kB ($${\color{red}+1.0\%}$$)
std_subgroupElect.ts 21.44 kB ($${\color{red}+1.0\%}$$)
std_subgroupAll.ts 21.45 kB ($${\color{red}+1.0\%}$$)
std_subgroupAny.ts 21.45 kB ($${\color{red}+1.0\%}$$)
std_quadSwapX.ts 21.45 kB ($${\color{red}+1.0\%}$$)
std_quadSwapY.ts 21.45 kB ($${\color{red}+1.0\%}$$)
std_subgroupOr.ts 21.45 kB ($${\color{red}+1.0\%}$$)
std_subgroupAdd.ts 21.45 kB ($${\color{red}+1.0\%}$$)
std_subgroupAnd.ts 21.45 kB ($${\color{red}+1.0\%}$$)
std_subgroupMax.ts 21.45 kB ($${\color{red}+1.0\%}$$)
std_subgroupMin.ts 21.45 kB ($${\color{red}+1.0\%}$$)
std_subgroupMul.ts 21.45 kB ($${\color{red}+1.0\%}$$)
std_subgroupXor.ts 21.45 kB ($${\color{red}+1.0\%}$$)
std_quadSwapDiagonal.ts 21.46 kB ($${\color{red}+1.0\%}$$)
std_subgroupExclusiveAdd.ts 21.47 kB ($${\color{red}+1.0\%}$$)
std_subgroupExclusiveMul.ts 21.47 kB ($${\color{red}+1.0\%}$$)
std_subgroupInclusiveAdd.ts 21.47 kB ($${\color{red}+1.0\%}$$)
std_subgroupInclusiveMul.ts 21.47 kB ($${\color{red}+1.0\%}$$)
std_subgroupBroadcastFirst.ts 21.47 kB ($${\color{red}+1.0\%}$$)
std_storageBarrier.ts 21.49 kB ($${\color{red}+1.0\%}$$)
std_textureBarrier.ts 21.49 kB ($${\color{red}+1.0\%}$$)
std_workgroupBarrier.ts 21.50 kB ($${\color{red}+1.0\%}$$)
std_discard.ts 21.50 kB ($${\color{red}+1.0\%}$$)
std_textureNumLayers.ts 21.52 kB ($${\color{red}+1.0\%}$$)
std_textureNumLevels.ts 21.52 kB ($${\color{red}+1.0\%}$$)
std_textureNumSamples.ts 21.53 kB ($${\color{red}+1.0\%}$$)
std_typeOf.ts 22.25 kB ($${\color{red}+1.0\%}$$)
std_textureSampleCompare.ts 21.55 kB ($${\color{red}+1.0\%}$$)
std_textureSampleCompareLevel.ts 21.57 kB ($${\color{red}+1.0\%}$$)
std_textureStore.ts 21.57 kB ($${\color{red}+1.0\%}$$)
std_workgroupUniformLoad.ts 21.59 kB ($${\color{red}+1.0\%}$$)
tgpu_comptime.ts 21.60 kB ($${\color{red}+1.0\%}$$)
std_atomicLoad.ts 21.63 kB ($${\color{red}+1.0\%}$$)
std_atomicOr.ts 21.67 kB ($${\color{red}+1.0\%}$$)
std_atomicAdd.ts 21.67 kB ($${\color{red}+1.0\%}$$)
std_atomicAnd.ts 21.67 kB ($${\color{red}+1.0\%}$$)
std_atomicMax.ts 21.67 kB ($${\color{red}+1.0\%}$$)
std_atomicMin.ts 21.67 kB ($${\color{red}+1.0\%}$$)
std_atomicSub.ts 21.67 kB ($${\color{red}+1.0\%}$$)
std_atomicXor.ts 21.67 kB ($${\color{red}+1.0\%}$$)
std_atomicExchange.ts 21.68 kB ($${\color{red}+1.0\%}$$)
std_atomicStore.ts 21.71 kB ($${\color{red}+1.0\%}$$)
std_quadBroadcast.ts 21.72 kB ($${\color{red}+1.0\%}$$)
std_arrayLength.ts 21.72 kB ($${\color{red}+1.0\%}$$)
std_subgroupShuffleUp.ts 21.72 kB ($${\color{red}+1.0\%}$$)
std_subgroupShuffle.ts 21.72 kB ($${\color{red}+1.0\%}$$)
std_subgroupShuffleXor.ts 21.72 kB ($${\color{red}+1.0\%}$$)
std_subgroupShuffleDown.ts 21.73 kB ($${\color{red}+1.0\%}$$)
std_subgroupBroadcast.ts 21.73 kB ($${\color{red}+1.0\%}$$)
d_sizeOf.ts 32.97 kB ($${\color{red}+1.0\%}$$)
std_copy.ts 21.75 kB ($${\color{red}+1.0\%}$$)
d_isContiguous.ts 32.98 kB ($${\color{red}+1.0\%}$$)
d_getLongestContiguousPrefix.ts 32.99 kB ($${\color{red}+1.0\%}$$)
d_isBuiltin.ts 33.07 kB ($${\color{red}+1.0\%}$$)
std_extensionEnabled.ts 21.82 kB ($${\color{red}+1.0\%}$$)
std_range.ts 22.09 kB ($${\color{red}+1.0\%}$$)
std_isBeingTranspiled.ts 22.13 kB ($${\color{red}+1.0\%}$$)
std_getShaderStage.ts 22.19 kB ($${\color{red}+1.0\%}$$)
std_getTargetShaderLanguage.ts 22.20 kB ($${\color{red}+1.0\%}$$)
d_disarrayOf.ts 22.31 kB ($${\color{red}+1.0\%}$$)
d_size.ts 34.74 kB ($${\color{red}+1.0\%}$$)
d_align.ts 34.74 kB ($${\color{red}+1.0\%}$$)
d_location.ts 34.74 kB ($${\color{red}+1.0\%}$$)
d_interpolate.ts 34.74 kB ($${\color{red}+1.0\%}$$)
d_invariant.ts 35.11 kB ($${\color{red}+0.9\%}$$)
tgpu_vertexLayout.ts 35.00 kB ($${\color{red}+0.9\%}$$)
common_writeSoA.ts 35.59 kB ($${\color{red}+0.9\%}$$)
d_memoryLayoutOf.ts 36.56 kB ($${\color{red}+0.9\%}$$)
std_atomicCompareExchangeWeak.ts 24.27 kB ($${\color{red}+0.9\%}$$)
common_fullScreenTriangle.ts 49.15 kB ($${\color{red}+0.9\%}$$)
tgpu_initFromDevice.ts 257.29 kB ($${\color{red}+0.8\%}$$)
tgpu_init.ts 257.83 kB ($${\color{red}+0.8\%}$$)
tgpu_fn.ts 47.40 kB ($${\color{red}+0.8\%}$$)
STATIC_tgpu.ts 269.06 kB ($${\color{red}+0.8\%}$$)
std_subgroupBallot.ts 27.92 kB ($${\color{red}+0.8\%}$$)
std_textureSampleBaseClampToEdge.ts 28.00 kB ($${\color{red}+0.8\%}$$)
std_textureSampleGrad.ts 28.01 kB ($${\color{red}+0.8\%}$$)
std_textureSampleBias.ts 28.07 kB ($${\color{red}+0.8\%}$$)
d_uint8.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_float16.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_float16x2.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_float16x4.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_float32.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_float32x2.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_float32x3.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_float32x4.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_sint16.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_sint16x2.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_sint16x4.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_sint32.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_sint32x2.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_sint32x3.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_sint32x4.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_sint8.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_sint8x2.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_sint8x4.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_snorm16.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_snorm16x2.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_snorm16x4.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_snorm8.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_snorm8x2.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_snorm8x4.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_uint16.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_uint16x2.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_uint16x4.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_uint32.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_uint32x2.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_uint32x3.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_uint32x4.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_uint8x2.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_uint8x4.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_unorm10_10_10_2.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_unorm16.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_unorm16x2.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_unorm16x4.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_unorm8.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_unorm8x2.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_unorm8x4.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_unorm8x4_bgra.ts 28.21 kB ($${\color{red}+0.8\%}$$)
std_textureSample.ts 28.09 kB ($${\color{red}+0.8\%}$$)
std_textureSampleLevel.ts 28.10 kB ($${\color{red}+0.8\%}$$)
std_textureGatherCompare.ts 28.13 kB ($${\color{red}+0.8\%}$$)
std_textureDimensions.ts 28.16 kB ($${\color{red}+0.8\%}$$)
d_formatToWGSLType.ts 28.21 kB ($${\color{red}+0.8\%}$$)
d_packedFormats.ts 28.23 kB ($${\color{red}+0.8\%}$$)
d_isPackedData.ts 28.28 kB ($${\color{red}+0.8\%}$$)
std_textureGather.ts 28.33 kB ($${\color{red}+0.8\%}$$)
STATIC_common.ts 56.70 kB ($${\color{red}+0.7\%}$$)
d_alignmentOf.ts 30.08 kB ($${\color{red}+0.7\%}$$)
tgpu_computeFn.ts 46.50 kB ($${\color{red}+0.7\%}$$)
std_textureLoad.ts 29.95 kB ($${\color{red}+0.7\%}$$)
tgpu_vertexFn.ts 47.05 kB ($${\color{red}+0.7\%}$$)
tgpu_fragmentFn.ts 47.24 kB ($${\color{red}+0.7\%}$$)
std_bitcast.ts 30.73 kB ($${\color{red}+0.7\%}$$)
tgpu_accessor.ts 68.39 kB ($${\color{red}+0.7\%}$$)
tgpu_mutableAccessor.ts 68.40 kB ($${\color{red}+0.7\%}$$)
std_pack2x16float.ts 31.74 kB ($${\color{red}+0.7\%}$$)
std_unpack2x16unorm.ts 31.74 kB ($${\color{red}+0.7\%}$$)
std_unpack2x16float.ts 31.75 kB ($${\color{red}+0.7\%}$$)
std_pack4xI8.ts 31.76 kB ($${\color{red}+0.7\%}$$)
std_unpack4xI8.ts 31.76 kB ($${\color{red}+0.7\%}$$)
std_pack4xU8.ts 31.76 kB ($${\color{red}+0.7\%}$$)
std_unpack4xU8.ts 31.76 kB ($${\color{red}+0.7\%}$$)
std_unpack2x16snorm.ts 31.76 kB ($${\color{red}+0.7\%}$$)
std_unpack4x8unorm.ts 31.78 kB ($${\color{red}+0.7\%}$$)
std_unpack4x8snorm.ts 31.83 kB ($${\color{red}+0.7\%}$$)
std_pack2x16snorm.ts 31.92 kB ($${\color{red}+0.7\%}$$)
std_pack2x16unorm.ts 31.92 kB ($${\color{red}+0.7\%}$$)
std_pack4xU8Clamp.ts 31.93 kB ($${\color{red}+0.7\%}$$)
std_pack4xI8Clamp.ts 31.94 kB ($${\color{red}+0.7\%}$$)
std_pack4x8snorm.ts 32.00 kB ($${\color{red}+0.7\%}$$)
std_pack4x8unorm.ts 32.00 kB ($${\color{red}+0.7\%}$$)
std_identity2.ts 34.42 kB ($${\color{red}+0.6\%}$$)
std_identity3.ts 34.42 kB ($${\color{red}+0.6\%}$$)
std_identity4.ts 34.42 kB ($${\color{red}+0.6\%}$$)
std_rotationX4.ts 34.42 kB ($${\color{red}+0.6\%}$$)
std_rotationY4.ts 34.42 kB ($${\color{red}+0.6\%}$$)
std_rotationZ4.ts 34.42 kB ($${\color{red}+0.6\%}$$)
std_scaling4.ts 34.42 kB ($${\color{red}+0.6\%}$$)
std_translation4.ts 34.42 kB ($${\color{red}+0.6\%}$$)
d_matToArray.ts 34.55 kB ($${\color{red}+0.6\%}$$)
std_dot4I8Packed.ts 35.80 kB ($${\color{red}+0.6\%}$$)
std_dot4U8Packed.ts 35.80 kB ($${\color{red}+0.6\%}$$)
std_firstLeadingBit.ts 35.81 kB ($${\color{red}+0.6\%}$$)
std_determinant.ts 35.89 kB ($${\color{red}+0.6\%}$$)
std_dpdxFine.ts 35.89 kB ($${\color{red}+0.6\%}$$)
std_dpdyFine.ts 35.89 kB ($${\color{red}+0.6\%}$$)
std_dpdxCoarse.ts 35.90 kB ($${\color{red}+0.6\%}$$)
std_dpdyCoarse.ts 35.90 kB ($${\color{red}+0.6\%}$$)
std_fwidthFine.ts 35.90 kB ($${\color{red}+0.6\%}$$)
std_dpdx.ts 35.90 kB ($${\color{red}+0.6\%}$$)
std_dpdy.ts 35.90 kB ($${\color{red}+0.6\%}$$)
std_fwidthCoarse.ts 35.90 kB ($${\color{red}+0.6\%}$$)
std_fwidth.ts 35.91 kB ($${\color{red}+0.6\%}$$)
std_refract.ts 35.91 kB ($${\color{red}+0.6\%}$$)
std_trunc.ts 35.96 kB ($${\color{red}+0.6\%}$$)
std_reverseBits.ts 35.97 kB ($${\color{red}+0.6\%}$$)
std_quantizeToF16.ts 35.97 kB ($${\color{red}+0.6\%}$$)
std_countOneBits.ts 35.97 kB ($${\color{red}+0.6\%}$$)
std_extractBits.ts 35.98 kB ($${\color{red}+0.6\%}$$)
std_firstTrailingBit.ts 35.98 kB ($${\color{red}+0.6\%}$$)
std_countLeadingZeros.ts 35.99 kB ($${\color{red}+0.6\%}$$)
std_countTrailingZeros.ts 35.99 kB ($${\color{red}+0.6\%}$$)
std_insertBits.ts 35.99 kB ($${\color{red}+0.6\%}$$)
std_faceForward.ts 35.99 kB ($${\color{red}+0.6\%}$$)
std_intdiv.ts 36.00 kB ($${\color{red}+0.6\%}$$)
std_tan.ts 36.04 kB ($${\color{red}+0.6\%}$$)
std_degrees.ts 36.05 kB ($${\color{red}+0.6\%}$$)
std_radians.ts 36.05 kB ($${\color{red}+0.6\%}$$)
std_inverseSqrt.ts 36.08 kB ($${\color{red}+0.6\%}$$)
std_round.ts 36.09 kB ($${\color{red}+0.6\%}$$)
std_step.ts 36.22 kB ($${\color{red}+0.6\%}$$)
std_ldexp.ts 36.22 kB ($${\color{red}+0.6\%}$$)
std_fma.ts 36.22 kB ($${\color{red}+0.6\%}$$)
std_transpose.ts 36.29 kB ($${\color{red}+0.6\%}$$)
std_not.ts 36.45 kB ($${\color{red}+0.6\%}$$)
std_abs.ts 36.46 kB ($${\color{red}+0.6\%}$$)
std_gt.ts 36.83 kB ($${\color{red}+0.6\%}$$)
std_neg.ts 36.51 kB ($${\color{red}+0.6\%}$$)
std_or.ts 36.52 kB ($${\color{red}+0.6\%}$$)
std_and.ts 36.60 kB ($${\color{red}+0.6\%}$$)
std_lt.ts 36.60 kB ($${\color{red}+0.6\%}$$)
std_eq.ts 36.61 kB ($${\color{red}+0.6\%}$$)
std_cos.ts 36.63 kB ($${\color{red}+0.6\%}$$)
std_exp.ts 36.63 kB ($${\color{red}+0.6\%}$$)
std_log.ts 36.63 kB ($${\color{red}+0.6\%}$$)
std_sin.ts 36.63 kB ($${\color{red}+0.6\%}$$)
std_exp2.ts 36.63 kB ($${\color{red}+0.6\%}$$)
std_sign.ts 36.63 kB ($${\color{red}+0.6\%}$$)
std_acos.ts 36.63 kB ($${\color{red}+0.6\%}$$)
std_asin.ts 36.63 kB ($${\color{red}+0.6\%}$$)
std_atan.ts 36.63 kB ($${\color{red}+0.6\%}$$)
std_ceil.ts 36.63 kB ($${\color{red}+0.6\%}$$)
std_cosh.ts 36.63 kB ($${\color{red}+0.6\%}$$)
std_log2.ts 36.63 kB ($${\color{red}+0.6\%}$$)
std_sinh.ts 36.63 kB ($${\color{red}+0.6\%}$$)
std_sqrt.ts 36.63 kB ($${\color{red}+0.6\%}$$)
std_tanh.ts 36.63 kB ($${\color{red}+0.6\%}$$)
std_acosh.ts 36.63 kB ($${\color{red}+0.6\%}$$)
std_asinh.ts 36.63 kB ($${\color{red}+0.6\%}$$)
std_atanh.ts 36.63 kB ($${\color{red}+0.6\%}$$)
std_floor.ts 36.63 kB ($${\color{red}+0.6\%}$$)
std_fract.ts 36.64 kB ($${\color{red}+0.6\%}$$)
std_ge.ts 36.67 kB ($${\color{red}+0.6\%}$$)
std_ne.ts 36.68 kB ($${\color{red}+0.6\%}$$)
std_le.ts 36.75 kB ($${\color{red}+0.6\%}$$)
std_saturate.ts 36.78 kB ($${\color{red}+0.6\%}$$)
std_pow.ts 36.81 kB ($${\color{red}+0.6\%}$$)
std_atan2.ts 36.82 kB ($${\color{red}+0.6\%}$$)
std_mix.ts 37.18 kB ($${\color{red}+0.6\%}$$)
std_clamp.ts 36.91 kB ($${\color{red}+0.6\%}$$)
std_max.ts 36.93 kB ($${\color{red}+0.6\%}$$)
std_min.ts 36.93 kB ($${\color{red}+0.6\%}$$)
std_smoothstep.ts 37.03 kB ($${\color{red}+0.6\%}$$)
std_select.ts 37.43 kB ($${\color{red}+0.6\%}$$)
std_mod.ts 37.46 kB ($${\color{red}+0.6\%}$$)
std_div.ts 37.50 kB ($${\color{red}+0.6\%}$$)
std_add.ts 37.58 kB ($${\color{red}+0.6\%}$$)
std_frexp.ts 38.54 kB ($${\color{red}+0.6\%}$$)
std_modf.ts 38.67 kB ($${\color{red}+0.6\%}$$)
std_all.ts 39.78 kB ($${\color{red}+0.5\%}$$)
std_bitShiftLeft.ts 39.76 kB ($${\color{red}+0.5\%}$$)
std_bitShiftRight.ts 39.77 kB ($${\color{red}+0.5\%}$$)
std_dot.ts 40.06 kB ($${\color{red}+0.5\%}$$)
std_length.ts 40.16 kB ($${\color{red}+0.5\%}$$)
std_any.ts 40.60 kB ($${\color{red}+0.5\%}$$)
std_cross.ts 40.27 kB ($${\color{red}+0.5\%}$$)
std_allEq.ts 40.81 kB ($${\color{red}+0.5\%}$$)
tgpu_lazy.ts 62.91 kB ($${\color{red}+0.5\%}$$)
tgpu_const.ts 63.11 kB ($${\color{red}+0.5\%}$$)
std_isCloseTo.ts 41.09 kB ($${\color{red}+0.5\%}$$)
tgpu_workgroupVar.ts 63.69 kB ($${\color{red}+0.5\%}$$)
tgpu_privateVar.ts 63.69 kB ($${\color{red}+0.5\%}$$)
std_normalize.ts 41.18 kB ($${\color{red}+0.5\%}$$)
std_bitcastF32toU32.ts 41.97 kB ($${\color{red}+0.5\%}$$)
std_bitcastU32toF32.ts 41.97 kB ($${\color{red}+0.5\%}$$)
std_bitcastU32toI32.ts 41.97 kB ($${\color{red}+0.5\%}$$)
std_mul.ts 42.20 kB ($${\color{red}+0.5\%}$$)
std_rotateZ4.ts 42.46 kB ($${\color{red}+0.5\%}$$)
std_translate4.ts 42.46 kB ($${\color{red}+0.5\%}$$)
std_scale4.ts 42.46 kB ($${\color{red}+0.5\%}$$)
std_rotateX4.ts 42.46 kB ($${\color{red}+0.5\%}$$)
std_rotateY4.ts 42.46 kB ($${\color{red}+0.5\%}$$)
std_sub.ts 42.58 kB ($${\color{red}+0.5\%}$$)
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.

@reczkok

reczkok commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

@pullfrog do a preliminary review

@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 critical issues — one minor validation gap worth a look.

Reviewed changes

  • d.bytes(n) schema (data/bytes.ts) — new WgslBuffer schema resolving to WGSL buffer<n> (or runtime-sized buffer for 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, plus std exports.
  • buffer_view language-feature plumbing (resolutionCtx.ts, wgslExtensions.ts, resolveData.ts, types.ts) — requireLanguageFeature and a requires buffer_view; directive emitted ahead of the module.
  • For-of over pointer iterables (tgsl/forOfUtils.ts) — getRangeSnippets now unwraps pointer data types (enables iterating a bufferView-returned array).
  • Docs + example + tests — new buffer-views.mdx, the shape-stream example, and bytes/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.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

Comment thread packages/typegpu/src/data/bytes.ts Outdated
@reczkok
reczkok force-pushed the feat/wgsl-buffer-view branch from 79f03d5 to 45d9dd2 Compare October 24, 2026 18:45
@reczkok
reczkok added this pull request to stack #3273 October 24, 2026 18:46
@reczkok
reczkok force-pushed the feat/wgsl-buffer-view branch from 45d9dd2 to 325e990 Compare October 26, 2026 13:02
@reczkok
reczkok removed this pull request from stack #3273 October 26, 2026 13:03
@reczkok
reczkok changed the base branch from main to feat/comptime-sizeof October 26, 2026 13:03
@reczkok
reczkok added this pull request to stack #3281 October 26, 2026 13:03
@reczkok
reczkok force-pushed the feat/wgsl-buffer-view branch 3 times, most recently from ab86c1d to a1c5a32 Compare October 27, 2026 12:14
Base automatically changed from feat/comptime-sizeof to main October 27, 2026 12:22
@iwoplaza
iwoplaza force-pushed the feat/wgsl-buffer-view branch from a1c5a32 to 2214ecc Compare October 27, 2026 12:22
@reczkok
reczkok force-pushed the feat/wgsl-buffer-view branch 5 times, most recently from 3ec897f to bab7afe Compare October 27, 2026 15:48
@reczkok
reczkok marked this pull request as ready for review October 27, 2026 15:58
Copilot AI balanced review requested due to automatic review settings October 27, 2026 15:58

Copilot AI 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.

🟡 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

Comment thread packages/typegpu/src/data/array.ts
Comment thread packages/typegpu/src/data/struct.ts
Comment thread packages/typegpu/src/tgsl/conversion.ts
Comment thread packages/typegpu/src/tgsl/wgslGenerator.ts

@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 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.buffer schema — new WgslBuffer type in data/buffer.ts (byteSize, 0 = runtime-sized) with size-multiple-of-4 validation and $validStorageSchema/$validUniformSchema tokens; threaded through resolveData, sizeOf/alignmentOf, schemasEqual, serial/schema, partialIO, and dataIO, and rejected as a struct property or array element.
  • std.bufferView family — std/bufferView.ts emits the WGSL builtins, checks schema host-shareability and comptime alignment/fit, and preserves read-only/mutable view semantics.
  • requires directives — resolutionCtx.ts/wgslExtensions.ts add requireLanguageFeature and requiredLanguageFeatures, emitted next to enable directives; resolution throws when root.enabledWgslLanguageFeatures lacks buffer_view.
  • Type-level plumbing — ptr.ts accepts d.buffer in pointer constructors, tgsl/conversion.ts adds size-subtyping (fitsBufferParameter), tgpuBindGroupLayout.ts widens BoundSchema for d.buffer entries, and Ptr gains $gpuRepr.
  • for...of over pointers — tgsl/forOfUtils.ts unwraps pointer iterables so buffer-view results iterate.
  • Tests / docs / example — new tests/std/bufferView.test.ts and tests/wgslBuffer.test.ts, a buffer-views docs page, and the packed-shapes example.

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).

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

Comment thread packages/typegpu/src/std/bufferView.ts
Comment thread apps/typegpu-docs/src/content/docs/apis/buffer-views.mdx Outdated
@reczkok
reczkok force-pushed the feat/wgsl-buffer-view branch from bab7afe to 318d02a Compare October 27, 2026 16:18

@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 — 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-shapes example to animate on the GPU — shape motion moved into a Motion struct with a time uniform and a toLocal helper, replacing the previous per-frame CPU buffer rewrites; shape colors are now u32 palette indices resolved against a tgpu.const palette in the shader, and the CPU side only writes once per scene.
  • Clarified bufferArrayView length in the docs — buffer-views.mdx now states the length is byteSize divided by the array stride (the element size rounded up to its alignment), matching WGSL StrideOf.

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.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

This branch has not been deployed

No deployments
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.

2 participants