feat: Asynchronous pipeline creation#2604
Conversation
|
pkg.pr.new packages benchmark commit |
Bundle size comparison (
|
| 🟢 Decreased | ➖ Unchanged | 🔴 Increased | ❔ Unknown |
|---|---|---|---|
| 0 | 299 | 21 | 0 |
import * as ... in PR vs import * as ... in target (did bundle size increase?):
| Test | tsdown |
|---|---|
| STATIC_tgpu.ts | 263.15 kB ( |
| tgpu_fn.ts | 263.15 kB ( |
| tgpu_init.ts | 263.15 kB ( |
| tgpu_lazy.ts | 263.15 kB ( |
| tgpu_slot.ts | 263.15 kB ( |
| tgpu_const.ts | 263.15 kB ( |
| tgpu_unroll.ts | 263.15 kB ( |
| tgpu_resolve.ts | 263.16 kB ( |
| tgpu_accessor.ts | 263.16 kB ( |
| tgpu_comptime.ts | 263.16 kB ( |
| tgpu_vertexFn.ts | 263.16 kB ( |
| tgpu_computeFn.ts | 263.16 kB ( |
| tgpu_fragmentFn.ts | 263.16 kB ( |
| tgpu_privateVar.ts | 263.16 kB ( |
| tgpu_vertexLayout.ts | 263.16 kB ( |
| tgpu_workgroupVar.ts | 263.16 kB ( |
| tgpu_initFromDevice.ts | 263.16 kB ( |
| tgpu_bindGroupLayout.ts | 263.16 kB ( |
| tgpu_mutableAccessor.ts | 263.16 kB ( |
| tgpu_resolveWithContext.ts | 263.17 kB ( |
| STATIC_allImports.ts | 293.02 kB ( |
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.36 kB ( |
| d_sampler.ts | 87.36 kB ( |
| d_isPtr.ts | 87.36 kB ( |
| d_comparisonSampler.ts | 87.37 kB ( |
| d_isSizeAttrib.ts | 87.37 kB ( |
| d_isWgslArray.ts | 87.37 kB ( |
| d_isAlignAttrib.ts | 87.37 kB ( |
| d_isWgslStruct.ts | 87.37 kB ( |
| d_isAtomic.ts | 87.36 kB ( |
| d_isBuiltinAttrib.ts | 87.37 kB ( |
| d_isLocationAttrib.ts | 87.37 kB ( |
| d_isDecorated.ts | 87.37 kB ( |
| d_isInterpolateAttrib.ts | 87.38 kB ( |
| d_atomic.ts | 87.36 kB ( |
| d_ptrHandle.ts | 87.37 kB ( |
| d_ptrUniform.ts | 87.37 kB ( |
| d_ptrStorage.ts | 87.37 kB ( |
| d_ptrPrivate.ts | 87.37 kB ( |
| d_ptrFn.ts | 87.36 kB ( |
| d_ptrWorkgroup.ts | 87.37 kB ( |
| d_textureExternal.ts | 87.37 kB ( |
| d_textureStorage1d.ts | 87.37 kB ( |
| d_textureStorage2d.ts | 87.37 kB ( |
| d_textureStorage3d.ts | 87.37 kB ( |
| d_textureStorage2dArray.ts | 87.38 kB ( |
| d_isDisarray.ts | 87.37 kB ( |
| d_isUnstruct.ts | 87.37 kB ( |
| d_isLooseDecorated.ts | 87.37 kB ( |
| d_isLooseData.ts | 87.37 kB ( |
| d_isWgslData.ts | 87.37 kB ( |
| d_unstruct.ts | 87.36 kB ( |
| d_isData.ts | 87.36 kB ( |
| d_deepEqual.ts | 87.37 kB ( |
| d_struct.ts | 87.36 kB ( |
| d_ref.ts | 87.36 kB ( |
| std_discard.ts | 103.09 kB ( |
| std_copy.ts | 103.09 kB ( |
| std_arrayLength.ts | 103.10 kB ( |
| std_isBeingTranspiled.ts | 103.10 kB ( |
| std_getTargetShaderLanguage.ts | 103.11 kB ( |
| std_extensionEnabled.ts | 103.10 kB ( |
| std_range.ts | 103.09 kB ( |
| std_dpdx.ts | 103.09 kB ( |
| std_fwidthCoarse.ts | 103.10 kB ( |
| std_dpdxCoarse.ts | 103.10 kB ( |
| std_dpdyCoarse.ts | 103.10 kB ( |
| std_fwidthFine.ts | 103.10 kB ( |
| std_dpdxFine.ts | 103.09 kB ( |
| std_dpdyFine.ts | 103.09 kB ( |
| std_fwidth.ts | 103.09 kB ( |
| std_dpdy.ts | 103.09 kB ( |
| d_bool.ts | 87.36 kB ( |
| d_f16.ts | 87.36 kB ( |
| d_f32.ts | 87.36 kB ( |
| d_i32.ts | 87.36 kB ( |
| d_u32.ts | 87.36 kB ( |
| d_u16.ts | 87.36 kB ( |
| std_atomicLoad.ts | 103.10 kB ( |
| std_textureBarrier.ts | 103.10 kB ( |
| std_atomicStore.ts | 103.10 kB ( |
| std_workgroupBarrier.ts | 103.10 kB ( |
| std_storageBarrier.ts | 103.10 kB ( |
| std_atomicAdd.ts | 103.09 kB ( |
| std_atomicAnd.ts | 103.09 kB ( |
| std_atomicMax.ts | 103.09 kB ( |
| std_atomicMin.ts | 103.09 kB ( |
| std_atomicSub.ts | 103.09 kB ( |
| std_atomicXor.ts | 103.09 kB ( |
| std_atomicOr.ts | 103.09 kB ( |
| d_textureDepth2d.ts | 87.37 kB ( |
| d_textureDepthCube.ts | 87.37 kB ( |
| d_texture1d.ts | 87.37 kB ( |
| d_texture2d.ts | 87.37 kB ( |
| d_texture3d.ts | 87.37 kB ( |
| d_textureDepth2dArray.ts | 87.38 kB ( |
| d_textureCube.ts | 87.37 kB ( |
| d_textureDepthCubeArray.ts | 87.38 kB ( |
| d_textureDepthMultisampled2d.ts | 87.38 kB ( |
| d_texture2dArray.ts | 87.37 kB ( |
| d_textureCubeArray.ts | 87.37 kB ( |
| d_textureMultisampled2d.ts | 87.38 kB ( |
| d_disarrayOf.ts | 87.37 kB ( |
| d_vec2b.ts | 87.36 kB ( |
| d_vec2f.ts | 87.36 kB ( |
| d_vec2h.ts | 87.36 kB ( |
| d_vec2i.ts | 87.36 kB ( |
| d_vec2u.ts | 87.36 kB ( |
| d_vec3b.ts | 87.36 kB ( |
| d_vec3f.ts | 87.36 kB ( |
| d_vec3h.ts | 87.36 kB ( |
| d_vec3i.ts | 87.36 kB ( |
| d_vec3u.ts | 87.36 kB ( |
| d_vec4b.ts | 87.36 kB ( |
| d_vec4f.ts | 87.36 kB ( |
| d_vec4h.ts | 87.36 kB ( |
| d_vec4i.ts | 87.36 kB ( |
| d_vec4u.ts | 87.36 kB ( |
| std_subgroupAdd.ts | 103.10 kB ( |
| std_subgroupBroadcastFirst.ts | 103.11 kB ( |
| std_subgroupExclusiveAdd.ts | 103.11 kB ( |
| std_subgroupExclusiveMul.ts | 103.11 kB ( |
| std_subgroupInclusiveAdd.ts | 103.11 kB ( |
| std_subgroupInclusiveMul.ts | 103.11 kB ( |
| std_subgroupShuffleDown.ts | 103.10 kB ( |
| std_subgroupShuffleXor.ts | 103.10 kB ( |
| std_subgroupBroadcast.ts | 103.10 kB ( |
| std_subgroupShuffleUp.ts | 103.10 kB ( |
| std_subgroupShuffle.ts | 103.10 kB ( |
| std_subgroupBallot.ts | 103.10 kB ( |
| std_subgroupElect.ts | 103.10 kB ( |
| std_subgroupAll.ts | 103.10 kB ( |
| std_subgroupAnd.ts | 103.10 kB ( |
| std_subgroupAny.ts | 103.10 kB ( |
| std_subgroupMax.ts | 103.10 kB ( |
| std_subgroupMin.ts | 103.10 kB ( |
| std_subgroupMul.ts | 103.10 kB ( |
| std_subgroupXor.ts | 103.10 kB ( |
| std_subgroupOr.ts | 103.10 kB ( |
| d_formatToWGSLType.ts | 87.37 kB ( |
| d_uint8.ts | 87.36 kB ( |
| d_unorm10_10_10_2.ts | 87.37 kB ( |
| d_unorm8x4_bgra.ts | 87.37 kB ( |
| d_float16x2.ts | 87.37 kB ( |
| d_float16x4.ts | 87.37 kB ( |
| d_float32x2.ts | 87.37 kB ( |
| d_float32x3.ts | 87.37 kB ( |
| d_float32x4.ts | 87.37 kB ( |
| d_snorm16x2.ts | 87.37 kB ( |
| d_snorm16x4.ts | 87.37 kB ( |
| d_unorm16x2.ts | 87.37 kB ( |
| d_unorm16x4.ts | 87.37 kB ( |
| d_sint16x2.ts | 87.36 kB ( |
| d_sint16x4.ts | 87.36 kB ( |
| d_sint32x2.ts | 87.36 kB ( |
| d_sint32x3.ts | 87.36 kB ( |
| d_sint32x4.ts | 87.36 kB ( |
| d_snorm8x2.ts | 87.36 kB ( |
| d_snorm8x4.ts | 87.36 kB ( |
| d_uint16x2.ts | 87.36 kB ( |
| d_uint16x4.ts | 87.36 kB ( |
| d_uint32x2.ts | 87.36 kB ( |
| d_uint32x3.ts | 87.36 kB ( |
| d_uint32x4.ts | 87.36 kB ( |
| d_unorm8x2.ts | 87.36 kB ( |
| d_unorm8x4.ts | 87.36 kB ( |
| d_float16.ts | 87.36 kB ( |
| d_float32.ts | 87.36 kB ( |
| d_sint8x2.ts | 87.36 kB ( |
| d_sint8x4.ts | 87.36 kB ( |
| d_snorm16.ts | 87.36 kB ( |
| d_uint8x2.ts | 87.36 kB ( |
| d_uint8x4.ts | 87.36 kB ( |
| d_unorm16.ts | 87.36 kB ( |
| d_sint16.ts | 87.36 kB ( |
| d_sint32.ts | 87.36 kB ( |
| d_snorm8.ts | 87.36 kB ( |
| d_uint16.ts | 87.36 kB ( |
| d_uint32.ts | 87.36 kB ( |
| d_unorm8.ts | 87.36 kB ( |
| d_sint8.ts | 87.36 kB ( |
| d_packedFormats.ts | 87.37 kB ( |
| d_isPackedData.ts | 87.37 kB ( |
| std_textureDimensions.ts | 103.10 kB ( |
| std_textureGather.ts | 103.10 kB ( |
| std_textureSampleBaseClampToEdge.ts | 103.11 kB ( |
| std_textureSampleCompareLevel.ts | 103.11 kB ( |
| std_textureSampleCompare.ts | 103.11 kB ( |
| std_textureSampleLevel.ts | 103.10 kB ( |
| std_textureSampleBias.ts | 103.10 kB ( |
| std_textureSampleGrad.ts | 103.10 kB ( |
| std_textureSample.ts | 103.10 kB ( |
| std_textureStore.ts | 103.10 kB ( |
| std_textureLoad.ts | 103.10 kB ( |
| d_alignmentOf.ts | 87.37 kB ( |
| std_translation4.ts | 103.10 kB ( |
| std_rotationX4.ts | 103.10 kB ( |
| std_rotationY4.ts | 103.10 kB ( |
| std_rotationZ4.ts | 103.10 kB ( |
| std_identity2.ts | 103.09 kB ( |
| std_identity3.ts | 103.09 kB ( |
| std_identity4.ts | 103.09 kB ( |
| std_scaling4.ts | 103.09 kB ( |
| d_isBuiltin.ts | 87.37 kB ( |
| d_sizeOf.ts | 87.36 kB ( |
| d_isContiguous.ts | 87.37 kB ( |
| d_getLongestContiguousPrefix.ts | 87.38 kB ( |
| d_arrayOf.ts | 87.36 kB ( |
| d_size.ts | 87.36 kB ( |
| d_align.ts | 87.36 kB ( |
| d_location.ts | 87.36 kB ( |
| d_interpolate.ts | 87.37 kB ( |
| d_invariant.ts | 87.37 kB ( |
| d_mat4x4f.ts | 87.36 kB ( |
| d_mat2x2f.ts | 87.36 kB ( |
| d_mat3x3f.ts | 87.36 kB ( |
| d_matToArray.ts | 87.37 kB ( |
| d_builtin.ts | 87.36 kB ( |
| std_unpack2x16float.ts | 103.10 kB ( |
| std_unpack4x8unorm.ts | 103.10 kB ( |
| std_pack2x16float.ts | 103.10 kB ( |
| std_pack4x8unorm.ts | 103.10 kB ( |
| std_bitcastU32toF32.ts | 103.10 kB ( |
| std_bitcastU32toI32.ts | 103.10 kB ( |
| std_neg.ts | 103.09 kB ( |
| std_bitShiftRight.ts | 103.10 kB ( |
| std_bitShiftLeft.ts | 103.10 kB ( |
| std_add.ts | 103.09 kB ( |
| std_div.ts | 103.09 kB ( |
| std_mod.ts | 103.09 kB ( |
| std_mul.ts | 103.09 kB ( |
| std_sub.ts | 103.09 kB ( |
| std_translate4.ts | 103.10 kB ( |
| std_rotateX4.ts | 103.09 kB ( |
| std_scale4.ts | 103.09 kB ( |
| std_rotateY4.ts | 103.09 kB ( |
| std_rotateZ4.ts | 103.09 kB ( |
| d_memoryLayoutOf.ts | 87.37 kB ( |
| std_and.ts | 103.09 kB ( |
| std_or.ts | 103.09 kB ( |
| std_select.ts | 103.09 kB ( |
| std_allEq.ts | 103.09 kB ( |
| std_all.ts | 103.09 kB ( |
| std_not.ts | 103.09 kB ( |
| std_eq.ts | 103.09 kB ( |
| std_lt.ts | 103.09 kB ( |
| std_ne.ts | 103.09 kB ( |
| std_isCloseTo.ts | 103.09 kB ( |
| std_any.ts | 103.09 kB ( |
| std_ge.ts | 103.09 kB ( |
| std_gt.ts | 103.09 kB ( |
| std_le.ts | 103.09 kB ( |
| std_dot4U8Packed.ts | 103.10 kB ( |
| std_length.ts | 103.09 kB ( |
| std_countTrailingZeros.ts | 103.10 kB ( |
| std_distance.ts | 103.09 kB ( |
| std_dot.ts | 103.09 kB ( |
| std_countLeadingZeros.ts | 103.10 kB ( |
| std_firstTrailingBit.ts | 103.10 kB ( |
| std_firstLeadingBit.ts | 103.10 kB ( |
| std_fract.ts | 103.09 kB ( |
| std_frexp.ts | 103.09 kB ( |
| std_modf.ts | 103.09 kB ( |
| std_quantizeToF16.ts | 103.10 kB ( |
| std_mix.ts | 103.09 kB ( |
| std_countOneBits.ts | 103.10 kB ( |
| std_dot4I8Packed.ts | 103.10 kB ( |
| std_determinant.ts | 103.10 kB ( |
| std_extractBits.ts | 103.10 kB ( |
| std_faceForward.ts | 103.10 kB ( |
| std_inverseSqrt.ts | 103.10 kB ( |
| std_reverseBits.ts | 103.10 kB ( |
| std_insertBits.ts | 103.10 kB ( |
| std_smoothstep.ts | 103.10 kB ( |
| std_normalize.ts | 103.09 kB ( |
| std_transpose.ts | 103.09 kB ( |
| std_saturate.ts | 103.09 kB ( |
| std_degrees.ts | 103.09 kB ( |
| std_radians.ts | 103.09 kB ( |
| std_reflect.ts | 103.09 kB ( |
| std_refract.ts | 103.09 kB ( |
| std_acosh.ts | 103.09 kB ( |
| std_asinh.ts | 103.09 kB ( |
| std_atan2.ts | 103.09 kB ( |
| std_atanh.ts | 103.09 kB ( |
| std_clamp.ts | 103.09 kB ( |
| std_cross.ts | 103.09 kB ( |
| std_floor.ts | 103.09 kB ( |
| std_ldexp.ts | 103.09 kB ( |
| std_round.ts | 103.09 kB ( |
| std_trunc.ts | 103.09 kB ( |
| std_acos.ts | 103.09 kB ( |
| std_asin.ts | 103.09 kB ( |
| std_atan.ts | 103.09 kB ( |
| std_ceil.ts | 103.09 kB ( |
| std_cosh.ts | 103.09 kB ( |
| std_exp2.ts | 103.09 kB ( |
| std_log2.ts | 103.09 kB ( |
| std_sign.ts | 103.09 kB ( |
| std_sinh.ts | 103.09 kB ( |
| std_sqrt.ts | 103.09 kB ( |
| std_step.ts | 103.09 kB ( |
| std_tanh.ts | 103.09 kB ( |
| std_abs.ts | 103.09 kB ( |
| std_cos.ts | 103.09 kB ( |
| std_exp.ts | 103.09 kB ( |
| std_fma.ts | 103.09 kB ( |
| std_log.ts | 103.09 kB ( |
| std_max.ts | 103.09 kB ( |
| std_min.ts | 103.09 kB ( |
| std_pow.ts | 103.09 kB ( |
| std_sin.ts | 103.09 kB ( |
| std_tan.ts | 103.09 kB ( |
| common_fullScreenTriangle.ts | 56.66 kB ( |
| common_writeSoA.ts | 56.65 kB ( |
| STATIC_allImports.ts | 288.00 kB ( |
| STATIC_d.ts | 87.36 kB ( |
| STATIC_std.ts | 103.08 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.95, 2.04, 4.81, 6.83, 8.07, 11.46, 23.36, 23.34]
line [1.02, 2.03, 4.23, 6.46, 8.39, 11.59, 23.16, 25.90]
line [0.91, 1.86, 4.31, 6.60, 7.47, 10.76, 22.08, 24.70]
---
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.34, 0.52, 0.72, 0.83, 1.16, 1.27, 1.52, 1.63]
line [0.28, 0.54, 0.73, 0.91, 1.22, 1.31, 1.57, 1.69]
line [0.27, 0.52, 0.70, 0.82, 1.18, 1.21, 1.44, 1.53]
---
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.90, 2.01, 4.68, 6.38, 12.65, 26.64, 57.38, 112.97]
line [1.01, 2.01, 4.20, 6.49, 12.54, 26.82, 58.05, 118.37]
line [0.84, 2.09, 4.22, 6.35, 12.65, 25.27, 54.47, 113.92]
|
9fe9b72 to
de777f1
Compare
There was a problem hiding this comment.
Pull request overview
This PR introduces explicit pipeline initialization APIs for compute pipelines, enabling asynchronous compilation to reduce first-dispatch stalls, and updates docs/examples/tests to exercise the new behavior.
Changes:
- Refactors
ComputePipelineCoreand addsinitAsync()/initSync()to compute pipelines. - Updates multiple docs examples to eagerly initialize compute pipelines (primarily via
initAsync()). - Adds unit tests and updates docs/example snapshots to reflect the new initialization flow.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/typegpu/src/core/pipeline/computePipeline.ts | Adds initAsync/initSync, refactors memoization/initialization flow, and moves perf tracking into a helper. |
| packages/typegpu/tests/pipelineInit.test.ts | Adds tests covering sync/async initialization, caching, and unwrap behavior during async init. |
| packages/typegpu-testing-utility/src/extendedIt.ts | Extends the GPU device mock with createComputePipelineAsync for new tests. |
| apps/typegpu-docs/src/examples/simulation/stable-fluid/index.ts | Eagerly initializes all compute pipelines with initAsync() to avoid first-frame stalls. |
| apps/typegpu-docs/src/examples/simulation/gravity/index.ts | Eagerly initializes compute pipelines with initAsync(). |
| apps/typegpu-docs/src/examples/rendering/function-visualizer/index.ts | Eagerly initializes dynamically-created guarded compute pipelines with initAsync(). |
| apps/typegpu-docs/src/examples/image-processing/background-segmentation/index.ts | Eagerly initializes guarded compute pipelines via initSync() before use. |
| apps/typegpu-docs/src/examples/algorithms/mnist-inference/index.ts | Eagerly initializes compute pipelines via initAsync() (including optional subgroup pipeline). |
| apps/typegpu-docs/src/examples/algorithms/matrix-next/index.ts | Eagerly initializes both compute strategies via initAsync(). |
| apps/typegpu-docs/tests/individual-example-tests/stable-fluid.test.ts | Updates expected shader-module call count and snapshot output. |
| apps/typegpu-docs/tests/individual-example-tests/mnist-inference.test.ts | Updates shader snapshot output ordering/content. |
| apps/typegpu-docs/tests/individual-example-tests/matrix-next.test.ts | Updates expected shader-module call count and snapshot output. |
| apps/typegpu-docs/src/content/docs/apis/pipelines.mdx | Documents pipeline initialization and shows initSync/initAsync usage. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Pipeline initialization involves resolving the pipeline code, creating the shader module, and creating the underlying WebGPU pipeline. | ||
| This happens automatically the first time the pipeline is executed via `.draw`, `.dispatchWorkgroups`, or a similar method. | ||
| The `initSync` and `initAsync` methods let you perform this work ahead of time, avoiding a stall on first execution. |
There was a problem hiding this comment.
I'm missing the explanation of when one should use initSync as opposed to initAsync and vice versa. On the other hand, it's non-trivial to explain it briefly 🤔
Maybe:
| Pipeline initialization involves resolving the pipeline code, creating the shader module, and creating the underlying WebGPU pipeline. | |
| This happens automatically the first time the pipeline is executed via `.draw`, `.dispatchWorkgroups`, or a similar method. | |
| The `initSync` and `initAsync` methods let you perform this work ahead of time, avoiding a stall on first execution. | |
| Pipeline initialization involves resolving the pipeline code, creating the shader module, and creating the underlying WebGPU pipeline. | |
| This happens automatically the first time the pipeline is executed via `.draw`, `.dispatchWorkgroups`, or a similar method. | |
| The `initSync` function lets you jump-start that initialization on the WebGPU process early. To await until the initialization actually finishes and avoid a stall on first execution, you can use the `initAsync` function instead. |
There was a problem hiding this comment.
I updated this paragraph and added commented snippets, tell me what you think
| }, | ||
| }); | ||
|
|
||
| await Promise.all([computeCollisionsPipeline.initAsync(), computeGravityPipeline.initAsync()]); |
There was a problem hiding this comment.
I'd prewarm these promises early:
| await Promise.all([computeCollisionsPipeline.initAsync(), computeGravityPipeline.initAsync()]); | |
| // Initializing all used pipelines | |
| const pipelinePromises = [ | |
| computeCollisionsPipeline.initAsync(), | |
| computeGravityPipeline.initAsync(), | |
| skyBoxPipeline.initAsync(), | |
| renderPipeline.initAsync(), | |
| ]; |
And await them right before requesting the first frame:
// Only requesting the first frame after all pipelines have been initialized
await Promise.all(pipelinePromises);
requestAnimationFrame(frame);On another note, why aren't we preinitializing the render pipelines?
There was a problem hiding this comment.
we aren't because they do not yethave initAsync/initSync methods - as I mentioned, I wanted to wait with them for an initial review so as not to do the same fixes twice
reczkok
left a comment
There was a problem hiding this comment.
Looks nice, I like the performance tracking approach
| ## Initialization | ||
|
|
||
| Pipeline initialization involves resolving the pipeline code, creating the shader module, and creating the underlying WebGPU pipeline. | ||
| This happens automatically the first time the pipeline is executed via `.draw`, `.dispatchWorkgroups`, or a similar method. | ||
| The `initSync` method lets you start the initialization early. | ||
| To wait until initialization actually finishes on the device (fully avoiding a stall on first execution), use `initAsync` instead. |
There was a problem hiding this comment.
I would stress here (and especially in the AI Skill) that this is not that important for small/mid sized shaders - only makes sense when you have a bigger application or shaders that are very big or have very many of them) - AI is prone to overusing solutions like those.
There was a problem hiding this comment.
Wouldn't it be better to just not mention it in the skill at all? Can we discuss it in #2650 ?
|
@pullfrog review |
There was a problem hiding this comment.
ℹ️ No critical issues — one docstring typo inline.
Reviewed changes — added explicit initAsync/initSync pipeline initialization for compute and render pipelines, extracted a PerformanceTracker, updated docs/examples, and realigned test snapshots and expected call counts.
- Added
initAsync()andinitSync()toTgpuComputePipeline,TgpuRenderPipeline, andTgpuGuardedComputePipeline. - Refactored
ComputePipelineCoreandRenderPipelineCoreto share async-init logic throughresolveAndCreateShaderModule()andPerformanceTracker. - Updated the pipelines docs page and example code to pre-initialize pipelines.
- Added
packages/typegpu/tests/pipelineInit.test.tsand updated example test snapshots/call counts.
Kimi K2 (free via Pullfrog for OSS) | 𝕏

Changes:
ComputePipelineCore,initAsyncandinitSync,initAsync,The PERF is set to true only in browser tests, which currently do not work.
Also, I think that the measurements are just incorrect.
Still, I opted to leave them as is in a separate class. I tested manually the results before and after on Stable Fluids (7 resolves), and they were similar, so I don't think any logic changed.