Skip to content

impr: More capable and performant write API#2279

Open
reczkok wants to merge 16 commits intomainfrom
impr/allow-buffer-write-encoder
Open

impr: More capable and performant write API#2279
reczkok wants to merge 16 commits intomainfrom
impr/allow-buffer-write-encoder

Conversation

@reczkok
Copy link
Contributor

@reczkok reczkok commented Mar 11, 2026

Introduce InferInput and $inRepr to accept plain arrays and TypedArrays for vector/array write-side representations. Add BufferWriteOptions (startOffset/endOffset) and improve memoryLayoutOf accessor errors. Update compiled/data writers to index into array-like vector inputs and adjust tests and docs accordingly

@reczkok reczkok requested a review from Copilot March 11, 2026 17:39
@github-actions
Copy link

github-actions bot commented Mar 11, 2026

pkg.pr.new

packages
Ready to be installed by your favorite package manager ⬇️

https://pkg.pr.new/software-mansion/TypeGPU/typegpu@e51409a9f4f14e16664240328b88e1034e412872
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/noise@e51409a9f4f14e16664240328b88e1034e412872
https://pkg.pr.new/software-mansion/TypeGPU/unplugin-typegpu@e51409a9f4f14e16664240328b88e1034e412872

benchmark
view benchmark

commit
view commit

@github-actions
Copy link

github-actions bot commented Mar 11, 2026

📊 Bundle Size Comparison

🟢 Decreased ➖ Unchanged 🔴 Increased ❔ Unknown
2 15 332 0

👀 Notable results

Static test results:

Test tsdown
tgpuImportEverything.ts 246.17 kB ($${\color{red}+0.7\%}$$)
tgpuImportOne.ts 246.18 kB ($${\color{red}+0.7\%}$$)
importEntireLibrary.ts 273.00 kB ($${\color{red}+0.6\%}$$)

Dynamic test results:

‼️ Click to reveal the results table (64 entries).
Test tsdown
Void from typegpudata.ts 700 B ($${\color{red}+4.6\%}$$)
sampler from typegpudata.ts 708 B ($${\color{red}+4.6\%}$$)
isPtr from typegpudata.ts 718 B ($${\color{red}+4.5\%}$$)
comparisonSampler from typegpudata.ts 719 B ($${\color{red}+4.5\%}$$)
isSizeAttrib from typegpudata.ts 720 B ($${\color{red}+4.5\%}$$)
isWgslArray from typegpudata.ts 720 B ($${\color{red}+4.5\%}$$)
isAlignAttrib from typegpudata.ts 721 B ($${\color{red}+4.5\%}$$)
isAtomic from typegpudata.ts 721 B ($${\color{red}+4.5\%}$$)
isWgslStruct from typegpudata.ts 721 B ($${\color{red}+4.5\%}$$)
isBuiltinAttrib from typegpudata.ts 723 B ($${\color{red}+4.5\%}$$)
isDecorated from typegpudata.ts 724 B ($${\color{red}+4.5\%}$$)
isLocationAttrib from typegpudata.ts 724 B ($${\color{red}+4.5\%}$$)
isInterpolateAttrib from typegpudata.ts 727 B ($${\color{red}+4.5\%}$$)
isTgpuFn from typegpu.ts 731 B ($${\color{red}+4.4\%}$$)
atomic from typegpudata.ts 739 B ($${\color{red}+4.4\%}$$)
ptrHandle from typegpudata.ts 817 B ($${\color{red}+3.9\%}$$)
ptrUniform from typegpudata.ts 818 B ($${\color{red}+3.9\%}$$)
ptrStorage from typegpudata.ts 822 B ($${\color{red}+3.9\%}$$)
ptrPrivate from typegpudata.ts 824 B ($${\color{red}+3.9\%}$$)
ptrFn from typegpudata.ts 825 B ($${\color{red}+3.9\%}$$)
ptrWorkgroup from typegpudata.ts 826 B ($${\color{red}+3.9\%}$$)
textureExternal from typegpudata.ts 839 B ($${\color{red}+3.8\%}$$)
isUsableAsVertex from typegpu.ts 84.93 kB ($${\color{green}-3.7\%}$$)
isBuffer from typegpu.ts 84.93 kB ($${\color{green}-3.7\%}$$)
textureStorage1d from typegpudata.ts 1003 B ($${\color{red}+3.2\%}$$)
textureStorage2d from typegpudata.ts 1003 B ($${\color{red}+3.2\%}$$)
textureStorage3d from typegpudata.ts 1003 B ($${\color{red}+3.2\%}$$)
textureStorage2dArray from typegpudata.ts 1021 B ($${\color{red}+3.1\%}$$)
NotUniformError from typegpu.ts 1.27 kB ($${\color{red}+2.4\%}$$)
isWgslData from typegpudata.ts 1.28 kB ($${\color{red}+2.4\%}$$)
MissingBindGroupsError from typegpu.ts 1.31 kB ($${\color{red}+2.4\%}$$)
MissingVertexBuffersError from typegpu.ts 1.32 kB ($${\color{red}+2.4\%}$$)
ResolutionError from typegpu.ts 1.51 kB ($${\color{red}+2.0\%}$$)
isBufferShorthand from typegpu.ts 1.73 kB ($${\color{red}+2.0\%}$$)
unstruct from typegpudata.ts 1.61 kB ($${\color{red}+1.9\%}$$)
isDisarray from typegpudata.ts 1.66 kB ($${\color{red}+1.9\%}$$)
isUnstruct from typegpudata.ts 1.66 kB ($${\color{red}+1.9\%}$$)
isLooseDecorated from typegpudata.ts 1.67 kB ($${\color{red}+1.9\%}$$)
isLooseData from typegpudata.ts 1.70 kB ($${\color{red}+1.8\%}$$)
ShaderGenerator from typegpu.ts 1.80 kB ($${\color{red}+1.7\%}$$)
isData from typegpudata.ts 2.35 kB ($${\color{red}+1.3\%}$$)
deepEqual from typegpudata.ts 2.74 kB ($${\color{red}+1.1\%}$$)
struct from typegpudata.ts 3.34 kB ($${\color{red}+0.9\%}$$)
ref from typegpudata.ts 4.12 kB ($${\color{red}+0.7\%}$$)
tgpu from typegpu.ts 246.17 kB ($${\color{red}+0.7\%}$$)
tgpu.fn from typegpu.ts 246.17 kB ($${\color{red}+0.7\%}$$)
tgpu.init from typegpu.ts 246.17 kB ($${\color{red}+0.7\%}$$)
tgpu.lazy from typegpu.ts 246.17 kB ($${\color{red}+0.7\%}$$)
tgpu.slot from typegpu.ts 246.17 kB ($${\color{red}+0.7\%}$$)
tgpu.const from typegpu.ts 246.17 kB ($${\color{red}+0.7\%}$$)
tgpu.unroll from typegpu.ts 246.17 kB ($${\color{red}+0.7\%}$$)
tgpu.resolve from typegpu.ts 246.18 kB ($${\color{red}+0.7\%}$$)
tgpu.accessor from typegpu.ts 246.18 kB ($${\color{red}+0.7\%}$$)
tgpu.comptime from typegpu.ts 246.18 kB ($${\color{red}+0.7\%}$$)
tgpu.vertexFn from typegpu.ts 246.18 kB ($${\color{red}+0.7\%}$$)
tgpu.computeFn from typegpu.ts 246.18 kB ($${\color{red}+0.7\%}$$)
tgpu.fragmentFn from typegpu.ts 246.18 kB ($${\color{red}+0.7\%}$$)
tgpu.privateVar from typegpu.ts 246.18 kB ($${\color{red}+0.7\%}$$)
tgpu.vertexLayout from typegpu.ts 246.18 kB ($${\color{red}+0.7\%}$$)
tgpu.workgroupVar from typegpu.ts 246.18 kB ($${\color{red}+0.7\%}$$)
tgpu.initFromDevice from typegpu.ts 246.18 kB ($${\color{red}+0.7\%}$$)
tgpu.bindGroupLayout from typegpu.ts 246.18 kB ($${\color{red}+0.7\%}$$)
tgpu.mutableAccessor from typegpu.ts 246.18 kB ($${\color{red}+0.7\%}$$)
tgpu.resolveWithContext from typegpu.ts 246.19 kB ($${\color{red}+0.7\%}$$)

📋 All results

Click to reveal the results table (348 entries).
Test tsdown
Void from typegpudata.ts 700 B ($${\color{red}+4.6\%}$$)
sampler from typegpudata.ts 708 B ($${\color{red}+4.6\%}$$)
isPtr from typegpudata.ts 718 B ($${\color{red}+4.5\%}$$)
comparisonSampler from typegpudata.ts 719 B ($${\color{red}+4.5\%}$$)
isSizeAttrib from typegpudata.ts 720 B ($${\color{red}+4.5\%}$$)
isWgslArray from typegpudata.ts 720 B ($${\color{red}+4.5\%}$$)
isAlignAttrib from typegpudata.ts 721 B ($${\color{red}+4.5\%}$$)
isAtomic from typegpudata.ts 721 B ($${\color{red}+4.5\%}$$)
isWgslStruct from typegpudata.ts 721 B ($${\color{red}+4.5\%}$$)
isBuiltinAttrib from typegpudata.ts 723 B ($${\color{red}+4.5\%}$$)
isDecorated from typegpudata.ts 724 B ($${\color{red}+4.5\%}$$)
isLocationAttrib from typegpudata.ts 724 B ($${\color{red}+4.5\%}$$)
isInterpolateAttrib from typegpudata.ts 727 B ($${\color{red}+4.5\%}$$)
isTgpuFn from typegpu.ts 731 B ($${\color{red}+4.4\%}$$)
atomic from typegpudata.ts 739 B ($${\color{red}+4.4\%}$$)
ptrHandle from typegpudata.ts 817 B ($${\color{red}+3.9\%}$$)
ptrUniform from typegpudata.ts 818 B ($${\color{red}+3.9\%}$$)
ptrStorage from typegpudata.ts 822 B ($${\color{red}+3.9\%}$$)
ptrPrivate from typegpudata.ts 824 B ($${\color{red}+3.9\%}$$)
ptrFn from typegpudata.ts 825 B ($${\color{red}+3.9\%}$$)
ptrWorkgroup from typegpudata.ts 826 B ($${\color{red}+3.9\%}$$)
textureExternal from typegpudata.ts 839 B ($${\color{red}+3.8\%}$$)
isUsableAsVertex from typegpu.ts 84.93 kB ($${\color{green}-3.7\%}$$)
isBuffer from typegpu.ts 84.93 kB ($${\color{green}-3.7\%}$$)
textureStorage1d from typegpudata.ts 1003 B ($${\color{red}+3.2\%}$$)
textureStorage2d from typegpudata.ts 1003 B ($${\color{red}+3.2\%}$$)
textureStorage3d from typegpudata.ts 1003 B ($${\color{red}+3.2\%}$$)
textureStorage2dArray from typegpudata.ts 1021 B ($${\color{red}+3.1\%}$$)
NotUniformError from typegpu.ts 1.27 kB ($${\color{red}+2.4\%}$$)
isWgslData from typegpudata.ts 1.28 kB ($${\color{red}+2.4\%}$$)
MissingBindGroupsError from typegpu.ts 1.31 kB ($${\color{red}+2.4\%}$$)
MissingVertexBuffersError from typegpu.ts 1.32 kB ($${\color{red}+2.4\%}$$)
ResolutionError from typegpu.ts 1.51 kB ($${\color{red}+2.0\%}$$)
isBufferShorthand from typegpu.ts 1.73 kB ($${\color{red}+2.0\%}$$)
unstruct from typegpudata.ts 1.61 kB ($${\color{red}+1.9\%}$$)
isDisarray from typegpudata.ts 1.66 kB ($${\color{red}+1.9\%}$$)
isUnstruct from typegpudata.ts 1.66 kB ($${\color{red}+1.9\%}$$)
isLooseDecorated from typegpudata.ts 1.67 kB ($${\color{red}+1.9\%}$$)
isLooseData from typegpudata.ts 1.70 kB ($${\color{red}+1.8\%}$$)
ShaderGenerator from typegpu.ts 1.80 kB ($${\color{red}+1.7\%}$$)
isData from typegpudata.ts 2.35 kB ($${\color{red}+1.3\%}$$)
deepEqual from typegpudata.ts 2.74 kB ($${\color{red}+1.1\%}$$)
struct from typegpudata.ts 3.34 kB ($${\color{red}+0.9\%}$$)
ref from typegpudata.ts 4.12 kB ($${\color{red}+0.7\%}$$)
tgpuImportEverything.ts 246.17 kB ($${\color{red}+0.7\%}$$)
tgpu from typegpu.ts 246.17 kB ($${\color{red}+0.7\%}$$)
tgpu.fn from typegpu.ts 246.17 kB ($${\color{red}+0.7\%}$$)
tgpu.init from typegpu.ts 246.17 kB ($${\color{red}+0.7\%}$$)
tgpu.lazy from typegpu.ts 246.17 kB ($${\color{red}+0.7\%}$$)
tgpu.slot from typegpu.ts 246.17 kB ($${\color{red}+0.7\%}$$)
tgpu.const from typegpu.ts 246.17 kB ($${\color{red}+0.7\%}$$)
tgpu.unroll from typegpu.ts 246.17 kB ($${\color{red}+0.7\%}$$)
tgpu.resolve from typegpu.ts 246.18 kB ($${\color{red}+0.7\%}$$)
tgpu.accessor from typegpu.ts 246.18 kB ($${\color{red}+0.7\%}$$)
tgpu.comptime from typegpu.ts 246.18 kB ($${\color{red}+0.7\%}$$)
tgpu.vertexFn from typegpu.ts 246.18 kB ($${\color{red}+0.7\%}$$)
tgpu.computeFn from typegpu.ts 246.18 kB ($${\color{red}+0.7\%}$$)
tgpu.fragmentFn from typegpu.ts 246.18 kB ($${\color{red}+0.7\%}$$)
tgpu.privateVar from typegpu.ts 246.18 kB ($${\color{red}+0.7\%}$$)
tgpuImportOne.ts 246.18 kB ($${\color{red}+0.7\%}$$)
tgpu.vertexLayout from typegpu.ts 246.18 kB ($${\color{red}+0.7\%}$$)
tgpu.workgroupVar from typegpu.ts 246.18 kB ($${\color{red}+0.7\%}$$)
tgpu.initFromDevice from typegpu.ts 246.18 kB ($${\color{red}+0.7\%}$$)
tgpu.bindGroupLayout from typegpu.ts 246.18 kB ($${\color{red}+0.7\%}$$)
tgpu.mutableAccessor from typegpu.ts 246.18 kB ($${\color{red}+0.7\%}$$)
tgpu.resolveWithContext from typegpu.ts 246.19 kB ($${\color{red}+0.7\%}$$)
importEntireLibrary.ts 273.00 kB ($${\color{red}+0.6\%}$$)
memoryLayoutOf from typegpudata.ts 39.56 kB ($${\color{red}+0.3\%}$$)
bool from typegpudata.ts 10.57 kB ($${\color{red}+0.3\%}$$)
f16 from typegpudata.ts 10.57 kB ($${\color{red}+0.3\%}$$)
f32 from typegpudata.ts 10.57 kB ($${\color{red}+0.3\%}$$)
i32 from typegpudata.ts 10.57 kB ($${\color{red}+0.3\%}$$)
u32 from typegpudata.ts 10.57 kB ($${\color{red}+0.3\%}$$)
u16 from typegpudata.ts 10.59 kB ($${\color{red}+0.3\%}$$)
textureDepth2d from typegpudata.ts 11.01 kB ($${\color{red}+0.3\%}$$)
textureDepthCube from typegpudata.ts 11.02 kB ($${\color{red}+0.3\%}$$)
texture1d from typegpudata.ts 11.03 kB ($${\color{red}+0.3\%}$$)
texture2d from typegpudata.ts 11.03 kB ($${\color{red}+0.3\%}$$)
texture3d from typegpudata.ts 11.03 kB ($${\color{red}+0.3\%}$$)
textureCube from typegpudata.ts 11.03 kB ($${\color{red}+0.3\%}$$)
textureDepth2dArray from typegpudata.ts 11.03 kB ($${\color{red}+0.3\%}$$)
textureDepthCubeArray from typegpudata.ts 11.04 kB ($${\color{red}+0.3\%}$$)
textureDepthMultisampled2d from typegpudata.ts 11.04 kB ($${\color{red}+0.3\%}$$)
texture2dArray from typegpudata.ts 11.04 kB ($${\color{red}+0.3\%}$$)
textureCubeArray from typegpudata.ts 11.05 kB ($${\color{red}+0.3\%}$$)
textureMultisampled2d from typegpudata.ts 11.05 kB ($${\color{red}+0.3\%}$$)
discard from typegpustd.ts 11.78 kB ($${\color{red}+0.3\%}$$)
arrayLength from typegpustd.ts 12.01 kB ($${\color{red}+0.3\%}$$)
extensionEnabled from typegpustd.ts 12.09 kB ($${\color{red}+0.3\%}$$)
disarrayOf from typegpudata.ts 12.53 kB ($${\color{red}+0.2\%}$$)
dpdx from typegpustd.ts 12.62 kB ($${\color{red}+0.2\%}$$)
dpdxCoarse from typegpustd.ts 12.63 kB ($${\color{red}+0.2\%}$$)
dpdxFine from typegpustd.ts 12.63 kB ($${\color{red}+0.2\%}$$)
dpdyCoarse from typegpustd.ts 12.63 kB ($${\color{red}+0.2\%}$$)
dpdyFine from typegpustd.ts 12.63 kB ($${\color{red}+0.2\%}$$)
dpdy from typegpustd.ts 12.63 kB ($${\color{red}+0.2\%}$$)
fwidthCoarse from typegpustd.ts 12.63 kB ($${\color{red}+0.2\%}$$)
fwidthFine from typegpustd.ts 12.63 kB ($${\color{red}+0.2\%}$$)
fwidth from typegpustd.ts 12.63 kB ($${\color{red}+0.2\%}$$)
atomicLoad from typegpustd.ts 13.38 kB ($${\color{red}+0.2\%}$$)
atomicStore from typegpustd.ts 13.38 kB ($${\color{red}+0.2\%}$$)
textureBarrier from typegpustd.ts 13.38 kB ($${\color{red}+0.2\%}$$)
atomicAdd from typegpustd.ts 13.39 kB ($${\color{red}+0.2\%}$$)
atomicAnd from typegpustd.ts 13.39 kB ($${\color{red}+0.2\%}$$)
atomicMax from typegpustd.ts 13.39 kB ($${\color{red}+0.2\%}$$)
atomicMin from typegpustd.ts 13.39 kB ($${\color{red}+0.2\%}$$)
atomicOr from typegpustd.ts 13.39 kB ($${\color{red}+0.2\%}$$)
atomicSub from typegpustd.ts 13.39 kB ($${\color{red}+0.2\%}$$)
atomicXor from typegpustd.ts 13.39 kB ($${\color{red}+0.2\%}$$)
storageBarrier from typegpustd.ts 13.39 kB ($${\color{red}+0.2\%}$$)
workgroupBarrier from typegpustd.ts 13.39 kB ($${\color{red}+0.2\%}$$)
vec2b from typegpudata.ts 16.96 kB ($${\color{red}+0.2\%}$$)
vec2f from typegpudata.ts 16.96 kB ($${\color{red}+0.2\%}$$)
vec2h from typegpudata.ts 16.96 kB ($${\color{red}+0.2\%}$$)
vec2i from typegpudata.ts 16.96 kB ($${\color{red}+0.2\%}$$)
vec2u from typegpudata.ts 16.96 kB ($${\color{red}+0.2\%}$$)
vec3b from typegpudata.ts 16.96 kB ($${\color{red}+0.2\%}$$)
vec3f from typegpudata.ts 16.96 kB ($${\color{red}+0.2\%}$$)
vec3h from typegpudata.ts 16.96 kB ($${\color{red}+0.2\%}$$)
vec3i from typegpudata.ts 16.96 kB ($${\color{red}+0.2\%}$$)
vec3u from typegpudata.ts 16.96 kB ($${\color{red}+0.2\%}$$)
vec4b from typegpudata.ts 16.96 kB ($${\color{red}+0.2\%}$$)
vec4f from typegpudata.ts 16.96 kB ($${\color{red}+0.2\%}$$)
vec4h from typegpudata.ts 16.96 kB ($${\color{red}+0.2\%}$$)
vec4i from typegpudata.ts 16.96 kB ($${\color{red}+0.2\%}$$)
vec4u from typegpudata.ts 16.96 kB ($${\color{red}+0.2\%}$$)
formatToWGSLType from typegpudata.ts 18.44 kB ($${\color{red}+0.2\%}$$)
uint8 from typegpudata.ts 18.44 kB ($${\color{red}+0.2\%}$$)
float16 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
float16x2 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
float16x4 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
float32 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
float32x2 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
float32x3 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
float32x4 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
sint16 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
sint16x2 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
sint16x4 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
sint32 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
sint32x2 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
sint32x3 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
sint32x4 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
sint8 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
sint8x2 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
sint8x4 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
snorm16 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
snorm16x2 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
snorm16x4 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
snorm8 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
snorm8x2 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
snorm8x4 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
uint16 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
uint16x2 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
uint16x4 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
uint32 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
uint32x2 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
uint32x3 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
uint32x4 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
uint8x2 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
uint8x4 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
unorm10 10 10 2 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
unorm16 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
unorm16x2 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
unorm16x4 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
unorm8 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
unorm8x2 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
unorm8x4 bgra from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
unorm8x4 from typegpudata.ts 18.45 kB ($${\color{red}+0.2\%}$$)
packedFormats from typegpudata.ts 18.47 kB ($${\color{red}+0.2\%}$$)
isPackedData from typegpudata.ts 18.51 kB ($${\color{red}+0.2\%}$$)
alignmentOf from typegpudata.ts 19.49 kB ($${\color{red}+0.2\%}$$)
d from typegpu.ts 84.39 kB ($${\color{red}+0.1\%}$$)
subgroupAdd from typegpustd.ts 21.52 kB ($${\color{red}+0.1\%}$$)
subgroupAll from typegpustd.ts 21.53 kB ($${\color{red}+0.1\%}$$)
subgroupAnd from typegpustd.ts 21.53 kB ($${\color{red}+0.1\%}$$)
subgroupAny from typegpustd.ts 21.53 kB ($${\color{red}+0.1\%}$$)
subgroupBallot from typegpustd.ts 21.53 kB ($${\color{red}+0.1\%}$$)
subgroupBroadcastFirst from typegpustd.ts 21.53 kB ($${\color{red}+0.1\%}$$)
subgroupBroadcast from typegpustd.ts 21.53 kB ($${\color{red}+0.1\%}$$)
subgroupElect from typegpustd.ts 21.53 kB ($${\color{red}+0.1\%}$$)
subgroupExclusiveAdd from typegpustd.ts 21.53 kB ($${\color{red}+0.1\%}$$)
subgroupExclusiveMul from typegpustd.ts 21.53 kB ($${\color{red}+0.1\%}$$)
subgroupInclusiveAdd from typegpustd.ts 21.53 kB ($${\color{red}+0.1\%}$$)
subgroupInclusiveMul from typegpustd.ts 21.53 kB ($${\color{red}+0.1\%}$$)
subgroupMax from typegpustd.ts 21.53 kB ($${\color{red}+0.1\%}$$)
subgroupMin from typegpustd.ts 21.53 kB ($${\color{red}+0.1\%}$$)
subgroupMul from typegpustd.ts 21.53 kB ($${\color{red}+0.1\%}$$)
subgroupOr from typegpustd.ts 21.53 kB ($${\color{red}+0.1\%}$$)
subgroupShuffleDown from typegpustd.ts 21.53 kB ($${\color{red}+0.1\%}$$)
subgroupShuffleUp from typegpustd.ts 21.53 kB ($${\color{red}+0.1\%}$$)
subgroupShuffleXor from typegpustd.ts 21.53 kB ($${\color{red}+0.1\%}$$)
subgroupShuffle from typegpustd.ts 21.53 kB ($${\color{red}+0.1\%}$$)
subgroupXor from typegpustd.ts 21.53 kB ($${\color{red}+0.1\%}$$)
dataImportEverything.ts 86.70 kB ($${\color{red}+0.1\%}$$)
isBuiltin from typegpudata.ts 22.21 kB ($${\color{red}+0.1\%}$$)
dataImportOneDirect.ts 22.26 kB ($${\color{red}+0.1\%}$$)
dataImportOneStar.ts 22.26 kB ($${\color{red}+0.1\%}$$)
sizeOf from typegpudata.ts 22.26 kB ($${\color{red}+0.1\%}$$)
isContiguous from typegpudata.ts 22.27 kB ($${\color{red}+0.1\%}$$)
getLongestContiguousPrefix from typegpudata.ts 22.28 kB ($${\color{red}+0.1\%}$$)
textureDimensions from typegpustd.ts 23.01 kB ($${\color{red}+0.1\%}$$)
textureGather from typegpustd.ts 23.01 kB ($${\color{red}+0.1\%}$$)
textureLoad from typegpustd.ts 23.01 kB ($${\color{red}+0.1\%}$$)
textureSampleBaseClampToEdge from typegpustd.ts 23.01 kB ($${\color{red}+0.1\%}$$)
textureSampleBias from typegpustd.ts 23.01 kB ($${\color{red}+0.1\%}$$)
textureSampleCompareLevel from typegpustd.ts 23.01 kB ($${\color{red}+0.1\%}$$)
textureSampleCompare from typegpustd.ts 23.01 kB ($${\color{red}+0.1\%}$$)
textureSampleLevel from typegpustd.ts 23.01 kB ($${\color{red}+0.1\%}$$)
textureSample from typegpustd.ts 23.01 kB ($${\color{red}+0.1\%}$$)
textureStore from typegpustd.ts 23.01 kB ($${\color{red}+0.1\%}$$)
arrayOf from typegpudata.ts 23.75 kB ($${\color{red}+0.1\%}$$)
size from typegpudata.ts 23.94 kB ($${\color{red}+0.1\%}$$)
align from typegpudata.ts 23.94 kB ($${\color{red}+0.1\%}$$)
location from typegpudata.ts 23.94 kB ($${\color{red}+0.1\%}$$)
interpolate from typegpudata.ts 23.94 kB ($${\color{red}+0.1\%}$$)
invariant from typegpudata.ts 24.31 kB ($${\color{red}+0.1\%}$$)
mat4x4f from typegpudata.ts 24.48 kB ($${\color{red}+0.1\%}$$)
identity2 from typegpustd.ts 24.48 kB ($${\color{red}+0.1\%}$$)
identity3 from typegpustd.ts 24.48 kB ($${\color{red}+0.1\%}$$)
identity4 from typegpustd.ts 24.48 kB ($${\color{red}+0.1\%}$$)
mat2x2f from typegpudata.ts 24.48 kB ($${\color{red}+0.1\%}$$)
mat3x3f from typegpudata.ts 24.48 kB ($${\color{red}+0.1\%}$$)
rotationX4 from typegpustd.ts 24.48 kB ($${\color{red}+0.1\%}$$)
rotationY4 from typegpustd.ts 24.48 kB ($${\color{red}+0.1\%}$$)
rotationZ4 from typegpustd.ts 24.48 kB ($${\color{red}+0.1\%}$$)
scaling4 from typegpustd.ts 24.48 kB ($${\color{red}+0.1\%}$$)
translation4 from typegpustd.ts 24.48 kB ($${\color{red}+0.1\%}$$)
matToArray from typegpudata.ts 24.61 kB ($${\color{red}+0.1\%}$$)
builtin from typegpudata.ts 26.11 kB ($${\color{red}+0.1\%}$$)
pack2x16float from typegpustd.ts 33.47 kB ($${\color{red}+0.1\%}$$)
pack4x8unorm from typegpustd.ts 33.47 kB ($${\color{red}+0.1\%}$$)
unpack2x16float from typegpustd.ts 33.47 kB ($${\color{red}+0.1\%}$$)
unpack4x8unorm from typegpustd.ts 33.47 kB ($${\color{red}+0.1\%}$$)
common from typegpu.ts 36.15 kB ($${\color{red}+0.1\%}$$)
bitcastU32toF32 from typegpustd.ts 41.67 kB ($${\color{red}+0.1\%}$$)
bitcastU32toI32 from typegpustd.ts 41.68 kB ($${\color{red}+0.1\%}$$)
neg from typegpustd.ts 45.84 kB ($${\color{red}+0.1\%}$$)
add from typegpustd.ts 45.85 kB ($${\color{red}+0.1\%}$$)
bitShiftLeft from typegpustd.ts 45.85 kB ($${\color{red}+0.1\%}$$)
bitShiftRight from typegpustd.ts 45.85 kB ($${\color{red}+0.1\%}$$)
div from typegpustd.ts 45.85 kB ($${\color{red}+0.1\%}$$)
mod from typegpustd.ts 45.85 kB ($${\color{red}+0.1\%}$$)
mul from typegpustd.ts 45.85 kB ($${\color{red}+0.1\%}$$)
sub from typegpustd.ts 45.85 kB ($${\color{red}+0.1\%}$$)
stdImportOneDirect.ts 45.85 kB ($${\color{red}+0.1\%}$$)
stdImportOneStar.ts 45.85 kB ($${\color{red}+0.1\%}$$)
rotateX4 from typegpustd.ts 46.61 kB ($${\color{red}+0.1\%}$$)
scale4 from typegpustd.ts 46.61 kB ($${\color{red}+0.1\%}$$)
translate4 from typegpustd.ts 46.61 kB ($${\color{red}+0.1\%}$$)
rotateY4 from typegpustd.ts 46.61 kB ($${\color{red}+0.1\%}$$)
rotateZ4 from typegpustd.ts 46.61 kB ($${\color{red}+0.1\%}$$)
and from typegpustd.ts 48.37 kB ($${\color{red}+0.1\%}$$)
not from typegpustd.ts 48.37 kB ($${\color{red}+0.1\%}$$)
or from typegpustd.ts 48.37 kB ($${\color{red}+0.1\%}$$)
allEq from typegpustd.ts 48.37 kB ($${\color{red}+0.1\%}$$)
all from typegpustd.ts 48.37 kB ($${\color{red}+0.1\%}$$)
eq from typegpustd.ts 48.37 kB ($${\color{red}+0.1\%}$$)
ge from typegpustd.ts 48.37 kB ($${\color{red}+0.1\%}$$)
lt from typegpustd.ts 48.37 kB ($${\color{red}+0.1\%}$$)
ne from typegpustd.ts 48.37 kB ($${\color{red}+0.1\%}$$)
any from typegpustd.ts 48.38 kB ($${\color{red}+0.1\%}$$)
gt from typegpustd.ts 48.38 kB ($${\color{red}+0.1\%}$$)
isCloseTo from typegpustd.ts 48.38 kB ($${\color{red}+0.1\%}$$)
le from typegpustd.ts 48.38 kB ($${\color{red}+0.1\%}$$)
select from typegpustd.ts 48.38 kB ($${\color{red}+0.1\%}$$)
isUsableAsUniform from typegpu.ts 59.64 kB ($${\color{red}+0.1\%}$$)
isTexture from typegpu.ts 59.65 kB ($${\color{red}+0.1\%}$$)
isSampler from typegpu.ts 59.66 kB ($${\color{red}+0.1\%}$$)
isComparisonSampler from typegpu.ts 59.67 kB ($${\color{red}+0.1\%}$$)
isVariable from typegpu.ts 61.44 kB ($${\color{red}+0.0\%}$$)
dot from typegpustd.ts 63.15 kB ($${\color{red}+0.0\%}$$)
length from typegpustd.ts 63.15 kB ($${\color{red}+0.0\%}$$)
distance from typegpustd.ts 63.15 kB ($${\color{red}+0.0\%}$$)
dot4U8Packed from typegpustd.ts 63.15 kB ($${\color{red}+0.0\%}$$)
fract from typegpustd.ts 63.15 kB ($${\color{red}+0.0\%}$$)
frexp from typegpustd.ts 63.15 kB ($${\color{red}+0.0\%}$$)
mix from typegpustd.ts 63.15 kB ($${\color{red}+0.0\%}$$)
modf from typegpustd.ts 63.15 kB ($${\color{red}+0.0\%}$$)
abs from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
acos from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
acosh from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
asin from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
asinh from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
atan2 from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
atan from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
atanh from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
ceil from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
clamp from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
cos from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
cosh from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
countLeadingZeros from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
countOneBits from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
countTrailingZeros from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
cross from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
degrees from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
determinant from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
dot4I8Packed from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
exp2 from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
exp from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
extractBits from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
faceForward from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
firstLeadingBit from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
firstTrailingBit from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
floor from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
fma from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
insertBits from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
inverseSqrt from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
ldexp from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
log2 from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
log from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
max from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
min from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
normalize from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
pow from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
quantizeToF16 from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
radians from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
reflect from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
refract from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
reverseBits from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
round from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
saturate from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
sign from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
sin from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
sinh from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
smoothstep from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
sqrt from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
step from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
tan from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
tanh from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
transpose from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
trunc from typegpustd.ts 63.16 kB ($${\color{red}+0.0\%}$$)
std from typegpu.ts 98.13 kB ($${\color{red}+0.0\%}$$)
WgslGenerator from typegpu.ts 98.93 kB ($${\color{red}+0.0\%}$$)
stdImportEverything.ts 100.84 kB ($${\color{red}+0.0\%}$$)
functionWithUseGpu.ts 282 B (➖)
functionWithoutUseGpu.ts 24 B (➖)
MissingLinksError from typegpu.ts 201 B (➖)
MissingSlotValueError from typegpu.ts 146 B (➖)
isAccessor from typegpu.ts 65 B (➖)
isLazy from typegpu.ts 61 B (➖)
isMutableAccessor from typegpu.ts 73 B (➖)
isSlot from typegpu.ts 61 B (➖)
isTgpuComputeFn from typegpu.ts 69 B (➖)
isTgpuFragmentFn from typegpu.ts 70 B (➖)
isTgpuVertexFn from typegpu.ts 68 B (➖)
isUsableAsRender from typegpu.ts 55 B (➖)
isUsableAsSampled from typegpu.ts 56 B (➖)
isUsableAsStorage from typegpu.ts 56 B (➖)

If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu.

This comment was marked as outdated.

@reczkok reczkok marked this pull request as ready for review March 13, 2026 17:01
@reczkok reczkok force-pushed the impr/allow-buffer-write-encoder branch from 3941b59 to a75db15 Compare March 17, 2026 16:18
@reczkok reczkok requested a review from Copilot March 17, 2026 16:30

This comment was marked as outdated.

@reczkok reczkok marked this pull request as draft March 18, 2026 11:11
@reczkok reczkok changed the title impr: More permissive options for buffer writes along with sliced writes impr: More capable and performant write API Mar 18, 2026
reczkok added 16 commits March 18, 2026 16:13
Introduce InferInput and $inRepr to accept plain arrays and TypedArrays
for vector/array write-side representations. Add BufferWriteOptions
(startOffset/endOffset) and improve memoryLayoutOf accessor errors.
Update compiled/data writers to index into array-like vector inputs and
adjust tests and docs accordingly
Add runtime validation for write offsets in TgpuBuffer.write:
startOffset must be a non-negative integer; endOffset must be
>= startOffset and <= buffer size. Forward BufferWriteOptions through
 the buffer shorthand write API and add unit tests for the new checks.
 Clarify docs about TypeGPU wrapper allocation and byte-based endOffset
 behavior (partial-element writes).
Use actual primitive/component size when generating compiled writers
instead of assuming 4-byte components. Add a runtime guard in the
buffer implementation to reject flat TypedArray inputs for arrays of
vectors when the compiled writer is unavailable (e.g. no-eval
environments), and add tests covering float16 vec writers and array
stride/offset behavior.
@reczkok reczkok force-pushed the impr/allow-buffer-write-encoder branch from 7aea73d to e51409a Compare March 18, 2026 15:13
@reczkok reczkok marked this pull request as ready for review March 18, 2026 15:14
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 20 out of 20 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 350 to +367
const gpuBuffer = this.buffer;
const bufferSize = sizeOf(this.dataType);
const startOffset = options?.startOffset ?? 0;
const endOffset = options?.endOffset ?? bufferSize;
const size = endOffset - startOffset;

if (gpuBuffer.mapState === 'mapped') {
const mapped = gpuBuffer.getMappedRange();
this._writeToTarget(mapped, data);
this._writeToTarget(mapped, data, options);
return;
}

const size = sizeOf(this.dataType);
if (!this._hostBuffer) {
this._hostBuffer = new ArrayBuffer(size);
this._hostBuffer = new ArrayBuffer(sizeOf(this.dataType));
}

this._writeToTarget(this._hostBuffer, data);
this.#device.queue.writeBuffer(gpuBuffer, 0, this._hostBuffer, 0, size);
this._writeToTarget(this._hostBuffer, data, options);
this.#device.queue.writeBuffer(gpuBuffer, startOffset, this._hostBuffer, startOffset, size);
? Int32Array
: T extends Vec2u | Vec3u | Vec4u | U32
? Uint32Array
: never;
Combined with `startOffset` and `d.memoryLayoutOf`, this lets you write to a precise region of the buffer.

:::note
Both offsets are **byte-based**. Any component whose byte position falls at or beyond `endOffset` is not written, which means offsets that do not align to schema element boundaries can result in partial elements being written. Use `d.memoryLayoutOf` to target whole elements safely.
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