Skip to content

feat: Use @typegpu/gl as a fallback when @typegpu/three is made to generate GLSL - #2794

Open
iwoplaza wants to merge 1 commit into
feat/make-triangle-work-with-gl-fallbackfrom
feat/typegpu-three-gl-fallback
Open

feat: Use @typegpu/gl as a fallback when @typegpu/three is made to generate GLSL#2794
iwoplaza wants to merge 1 commit into
feat/make-triangle-work-with-gl-fallbackfrom
feat/typegpu-three-gl-fallback

Conversation

@iwoplaza

@iwoplaza iwoplaza commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings August 5, 2026 22:44
@github-actions

github-actions Bot commented Aug 5, 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/eslint-plugin-typegpu@24d8fe31067d0851b8a3d47684cdb2e9afa0e70f
https://pkg.pr.new/software-mansion/TypeGPU/tgpu-gen@24d8fe31067d0851b8a3d47684cdb2e9afa0e70f
https://pkg.pr.new/software-mansion/TypeGPU/tinyest-for-wgsl@24d8fe31067d0851b8a3d47684cdb2e9afa0e70f
https://pkg.pr.new/software-mansion/TypeGPU/typegpu@24d8fe31067d0851b8a3d47684cdb2e9afa0e70f
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/cli@24d8fe31067d0851b8a3d47684cdb2e9afa0e70f
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/color@24d8fe31067d0851b8a3d47684cdb2e9afa0e70f
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/gl@24d8fe31067d0851b8a3d47684cdb2e9afa0e70f
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/noise@24d8fe31067d0851b8a3d47684cdb2e9afa0e70f
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/radiance-cascades@24d8fe31067d0851b8a3d47684cdb2e9afa0e70f
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/react@24d8fe31067d0851b8a3d47684cdb2e9afa0e70f
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/sdf@24d8fe31067d0851b8a3d47684cdb2e9afa0e70f
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/three@24d8fe31067d0851b8a3d47684cdb2e9afa0e70f
https://pkg.pr.new/software-mansion/TypeGPU/unplugin-typegpu@24d8fe31067d0851b8a3d47684cdb2e9afa0e70f

benchmark
view benchmark

commit
view commit

@github-actions

github-actions Bot commented Aug 5, 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.42, 0.89, 1.98, 2.77, 3.18, 5.61, 10.43, 11.50]
  line [0.44, 0.83, 1.93, 2.76, 3.53, 5.58, 10.79, 12.72]
  line [0.45, 0.86, 1.81, 3.33, 3.57, 5.29, 10.51, 12.05]
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.17, 0.27, 0.38, 0.41, 0.53, 0.53, 0.62, 0.70]
  line [0.12, 0.23, 0.31, 0.41, 0.53, 0.56, 0.60, 0.72]
  line [0.17, 0.27, 0.36, 0.42, 0.56, 0.50, 0.69, 0.74]
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.48, 1.06, 2.18, 3.94, 5.82, 11.83, 24.66, 51.61]
  line [0.47, 1.08, 2.17, 3.19, 5.65, 12.47, 25.49, 51.84]
  line [0.51, 1.10, 2.01, 2.98, 5.95, 12.99, 26.04, 54.06]
Loading

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

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

🟢 Decreased (max -1.32%) ➖ Unchanged 🔴 Increased ❔ Unknown
285 37 0 0

import * as ... in PR vs import * as ... in target (did bundle size increase?):

Click to reveal the results table (187 entries).
Test tsdown
d_builtin.ts 29.19 kB ($${\color{green}-0.6\%}$$)
d_matToArray.ts 27.82 kB ($${\color{green}-0.6\%}$$)
d_mat2x2f.ts 27.69 kB ($${\color{green}-0.6\%}$$)
d_mat3x3f.ts 27.69 kB ($${\color{green}-0.6\%}$$)
d_mat4x4f.ts 27.69 kB ($${\color{green}-0.6\%}$$)
std_identity4.ts 27.69 kB ($${\color{green}-0.6\%}$$)
std_identity2.ts 27.68 kB ($${\color{green}-0.6\%}$$)
std_identity3.ts 27.68 kB ($${\color{green}-0.6\%}$$)
std_rotationX4.ts 27.68 kB ($${\color{green}-0.6\%}$$)
std_rotationY4.ts 27.68 kB ($${\color{green}-0.6\%}$$)
std_rotationZ4.ts 27.68 kB ($${\color{green}-0.6\%}$$)
std_scaling4.ts 27.68 kB ($${\color{green}-0.6\%}$$)
std_translation4.ts 27.68 kB ($${\color{green}-0.6\%}$$)
std_textureLoad.ts 26.64 kB ($${\color{green}-0.6\%}$$)
std_textureSample.ts 26.64 kB ($${\color{green}-0.6\%}$$)
std_textureSampleBaseClampToEdge.ts 26.64 kB ($${\color{green}-0.6\%}$$)
std_textureSampleBias.ts 26.64 kB ($${\color{green}-0.6\%}$$)
std_textureSampleCompare.ts 26.64 kB ($${\color{green}-0.6\%}$$)
std_textureSampleCompareLevel.ts 26.64 kB ($${\color{green}-0.6\%}$$)
std_textureSampleGrad.ts 26.64 kB ($${\color{green}-0.6\%}$$)
std_textureSampleLevel.ts 26.64 kB ($${\color{green}-0.6\%}$$)
std_textureStore.ts 26.64 kB ($${\color{green}-0.6\%}$$)
std_textureDimensions.ts 26.63 kB ($${\color{green}-0.6\%}$$)
std_textureGather.ts 26.63 kB ($${\color{green}-0.6\%}$$)
d_invariant.ts 27.36 kB ($${\color{green}-0.6\%}$$)
d_interpolate.ts 26.99 kB ($${\color{green}-0.6\%}$$)
d_location.ts 26.98 kB ($${\color{green}-0.6\%}$$)
d_align.ts 26.98 kB ($${\color{green}-0.6\%}$$)
d_size.ts 26.98 kB ($${\color{green}-0.6\%}$$)
d_arrayOf.ts 26.73 kB ($${\color{green}-0.6\%}$$)
std_bitcast.ts 47.62 kB ($${\color{green}-0.6\%}$$)
std_bitcastU32toF32.ts 47.61 kB ($${\color{green}-0.6\%}$$)
std_bitcastU32toI32.ts 47.61 kB ($${\color{green}-0.6\%}$$)
std_bitcastF32toU32.ts 47.61 kB ($${\color{green}-0.6\%}$$)
std_subgroupAll.ts 25.03 kB ($${\color{green}-0.6\%}$$)
std_subgroupAnd.ts 25.03 kB ($${\color{green}-0.6\%}$$)
std_subgroupAny.ts 25.03 kB ($${\color{green}-0.6\%}$$)
std_subgroupBallot.ts 25.03 kB ($${\color{green}-0.6\%}$$)
std_subgroupBroadcast.ts 25.03 kB ($${\color{green}-0.6\%}$$)
std_subgroupBroadcastFirst.ts 25.03 kB ($${\color{green}-0.6\%}$$)
std_subgroupElect.ts 25.03 kB ($${\color{green}-0.6\%}$$)
std_subgroupExclusiveAdd.ts 25.03 kB ($${\color{green}-0.6\%}$$)
std_subgroupExclusiveMul.ts 25.03 kB ($${\color{green}-0.6\%}$$)
std_subgroupInclusiveAdd.ts 25.03 kB ($${\color{green}-0.6\%}$$)
std_subgroupInclusiveMul.ts 25.03 kB ($${\color{green}-0.6\%}$$)
std_subgroupMax.ts 25.03 kB ($${\color{green}-0.6\%}$$)
std_subgroupMin.ts 25.03 kB ($${\color{green}-0.6\%}$$)
std_subgroupMul.ts 25.03 kB ($${\color{green}-0.6\%}$$)
std_subgroupOr.ts 25.03 kB ($${\color{green}-0.6\%}$$)
std_subgroupShuffle.ts 25.03 kB ($${\color{green}-0.6\%}$$)
std_subgroupShuffleDown.ts 25.03 kB ($${\color{green}-0.6\%}$$)
std_subgroupShuffleUp.ts 25.03 kB ($${\color{green}-0.6\%}$$)
std_subgroupShuffleXor.ts 25.03 kB ($${\color{green}-0.6\%}$$)
std_subgroupXor.ts 25.03 kB ($${\color{green}-0.6\%}$$)
std_subgroupAdd.ts 25.02 kB ($${\color{green}-0.6\%}$$)
d_getLongestContiguousPrefix.ts 25.31 kB ($${\color{green}-0.7\%}$$)
d_isContiguous.ts 25.30 kB ($${\color{green}-0.7\%}$$)
d_sizeOf.ts 25.29 kB ($${\color{green}-0.7\%}$$)
d_isBuiltin.ts 25.24 kB ($${\color{green}-0.7\%}$$)
d_alignmentOf.ts 22.51 kB ($${\color{green}-0.7\%}$$)
d_isPackedData.ts 21.63 kB ($${\color{green}-0.8\%}$$)
d_packedFormats.ts 21.59 kB ($${\color{green}-0.8\%}$$)
d_float16.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_float16x2.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_float16x4.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_float32.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_float32x2.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_float32x3.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_float32x4.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_sint16.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_sint16x2.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_sint16x4.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_sint32.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_sint32x2.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_sint32x3.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_sint32x4.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_sint8.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_sint8x2.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_sint8x4.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_snorm16.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_snorm16x2.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_snorm16x4.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_snorm8.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_snorm8x2.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_snorm8x4.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_uint16.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_uint16x2.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_uint16x4.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_uint32.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_uint32x2.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_uint32x3.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_uint32x4.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_uint8x2.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_uint8x4.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_unorm10_10_10_2.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_unorm16.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_unorm16x2.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_unorm16x4.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_unorm8.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_unorm8x2.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_unorm8x4.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_unorm8x4_bgra.ts 21.57 kB ($${\color{green}-0.8\%}$$)
d_uint8.ts 21.56 kB ($${\color{green}-0.8\%}$$)
d_formatToWGSLType.ts 21.56 kB ($${\color{green}-0.8\%}$$)
d_vec2b.ts 20.07 kB ($${\color{green}-0.8\%}$$)
d_vec2f.ts 20.07 kB ($${\color{green}-0.8\%}$$)
d_vec2h.ts 20.07 kB ($${\color{green}-0.8\%}$$)
d_vec2i.ts 20.07 kB ($${\color{green}-0.8\%}$$)
d_vec2u.ts 20.07 kB ($${\color{green}-0.8\%}$$)
d_vec3b.ts 20.07 kB ($${\color{green}-0.8\%}$$)
d_vec3f.ts 20.07 kB ($${\color{green}-0.8\%}$$)
d_vec3h.ts 20.07 kB ($${\color{green}-0.8\%}$$)
d_vec3i.ts 20.07 kB ($${\color{green}-0.8\%}$$)
d_vec3u.ts 20.07 kB ($${\color{green}-0.8\%}$$)
d_vec4b.ts 20.07 kB ($${\color{green}-0.8\%}$$)
d_vec4f.ts 20.07 kB ($${\color{green}-0.8\%}$$)
d_vec4h.ts 20.07 kB ($${\color{green}-0.8\%}$$)
d_vec4i.ts 20.07 kB ($${\color{green}-0.8\%}$$)
d_vec4u.ts 20.07 kB ($${\color{green}-0.8\%}$$)
std_atomicAdd.ts 16.69 kB ($${\color{green}-1.0\%}$$)
std_atomicAnd.ts 16.69 kB ($${\color{green}-1.0\%}$$)
std_atomicMax.ts 16.69 kB ($${\color{green}-1.0\%}$$)
std_atomicMin.ts 16.69 kB ($${\color{green}-1.0\%}$$)
std_atomicOr.ts 16.69 kB ($${\color{green}-1.0\%}$$)
std_atomicSub.ts 16.69 kB ($${\color{green}-1.0\%}$$)
std_atomicXor.ts 16.69 kB ($${\color{green}-1.0\%}$$)
std_storageBarrier.ts 16.69 kB ($${\color{green}-1.0\%}$$)
std_workgroupBarrier.ts 16.69 kB ($${\color{green}-1.0\%}$$)
std_atomicStore.ts 16.69 kB ($${\color{green}-1.0\%}$$)
std_textureBarrier.ts 16.69 kB ($${\color{green}-1.0\%}$$)
std_atomicLoad.ts 16.68 kB ($${\color{green}-1.0\%}$$)
std_arrayLength.ts 15.18 kB ($${\color{green}-1.0\%}$$)
std_dpdxCoarse.ts 15.89 kB ($${\color{green}-1.0\%}$$)
std_dpdxFine.ts 15.89 kB ($${\color{green}-1.0\%}$$)
std_dpdy.ts 15.89 kB ($${\color{green}-1.0\%}$$)
std_dpdyCoarse.ts 15.89 kB ($${\color{green}-1.0\%}$$)
std_dpdyFine.ts 15.89 kB ($${\color{green}-1.0\%}$$)
std_fwidth.ts 15.89 kB ($${\color{green}-1.0\%}$$)
std_fwidthCoarse.ts 15.89 kB ($${\color{green}-1.0\%}$$)
std_fwidthFine.ts 15.89 kB ($${\color{green}-1.0\%}$$)
std_dpdx.ts 15.88 kB ($${\color{green}-1.0\%}$$)
std_copy.ts 15.16 kB ($${\color{green}-1.1\%}$$)
d_disarrayOf.ts 15.57 kB ($${\color{green}-1.1\%}$$)
std_discard.ts 14.92 kB ($${\color{green}-1.1\%}$$)
std_range.ts 15.40 kB ($${\color{green}-1.1\%}$$)
std_extensionEnabled.ts 15.13 kB ($${\color{green}-1.1\%}$$)
std_getTargetShaderLanguage.ts 15.08 kB ($${\color{green}-1.1\%}$$)
std_isBeingTranspiled.ts 15.01 kB ($${\color{green}-1.1\%}$$)
d_textureMultisampled2d.ts 14.10 kB ($${\color{green}-1.2\%}$$)
d_textureCubeArray.ts 14.10 kB ($${\color{green}-1.2\%}$$)
d_texture2dArray.ts 14.09 kB ($${\color{green}-1.2\%}$$)
d_textureDepthMultisampled2d.ts 14.09 kB ($${\color{green}-1.2\%}$$)
d_textureDepthCubeArray.ts 14.09 kB ($${\color{green}-1.2\%}$$)
d_textureDepth2dArray.ts 14.08 kB ($${\color{green}-1.2\%}$$)
d_textureCube.ts 14.08 kB ($${\color{green}-1.2\%}$$)
d_texture1d.ts 14.08 kB ($${\color{green}-1.2\%}$$)
d_texture2d.ts 14.08 kB ($${\color{green}-1.2\%}$$)
d_texture3d.ts 14.08 kB ($${\color{green}-1.2\%}$$)
d_textureDepthCube.ts 14.07 kB ($${\color{green}-1.2\%}$$)
d_textureDepth2d.ts 14.06 kB ($${\color{green}-1.2\%}$$)
STATIC_allImports.ts 295.42 kB ($${\color{green}-1.2\%}$$)
d_u16.ts 13.64 kB ($${\color{green}-1.2\%}$$)
d_bool.ts 13.62 kB ($${\color{green}-1.2\%}$$)
d_f16.ts 13.62 kB ($${\color{green}-1.2\%}$$)
d_f32.ts 13.62 kB ($${\color{green}-1.2\%}$$)
d_i32.ts 13.62 kB ($${\color{green}-1.2\%}$$)
d_u32.ts 13.62 kB ($${\color{green}-1.2\%}$$)
tgpu_resolveWithContext.ts 269.65 kB ($${\color{green}-1.3\%}$$)
tgpu_bindGroupLayout.ts 269.65 kB ($${\color{green}-1.3\%}$$)
tgpu_mutableAccessor.ts 269.65 kB ($${\color{green}-1.3\%}$$)
tgpu_initFromDevice.ts 269.65 kB ($${\color{green}-1.3\%}$$)
tgpu_vertexLayout.ts 269.65 kB ($${\color{green}-1.3\%}$$)
tgpu_workgroupVar.ts 269.65 kB ($${\color{green}-1.3\%}$$)
tgpu_fragmentFn.ts 269.65 kB ($${\color{green}-1.3\%}$$)
tgpu_privateVar.ts 269.65 kB ($${\color{green}-1.3\%}$$)
tgpu_computeFn.ts 269.64 kB ($${\color{green}-1.3\%}$$)
tgpu_accessor.ts 269.64 kB ($${\color{green}-1.3\%}$$)
tgpu_comptime.ts 269.64 kB ($${\color{green}-1.3\%}$$)
tgpu_vertexFn.ts 269.64 kB ($${\color{green}-1.3\%}$$)
tgpu_resolve.ts 269.64 kB ($${\color{green}-1.3\%}$$)
tgpu_unroll.ts 269.64 kB ($${\color{green}-1.3\%}$$)
tgpu_const.ts 269.64 kB ($${\color{green}-1.3\%}$$)
tgpu_init.ts 269.64 kB ($${\color{green}-1.3\%}$$)
tgpu_lazy.ts 269.64 kB ($${\color{green}-1.3\%}$$)
tgpu_slot.ts 269.64 kB ($${\color{green}-1.3\%}$$)
tgpu_fn.ts 269.64 kB ($${\color{green}-1.3\%}$$)
STATIC_tgpu.ts 269.63 kB ($${\color{green}-1.3\%}$$)

import { ... } in PR vs import * as ... in PR (is the library tree-Shakeable?):

Test tsdown
tgpu_init.ts 260.88 kB ($${\color{green}-3.2\%}$$)
tgpu_initFromDevice.ts 260.35 kB ($${\color{green}-3.4\%}$$)
tgpu_resolve.ts 167.50 kB ($${\color{green}-37.9\%}$$)
tgpu_resolveWithContext.ts 167.44 kB ($${\color{green}-37.9\%}$$)
tgpu_bindGroupLayout.ts 71.67 kB ($${\color{green}-73.4\%}$$)
tgpu_mutableAccessor.ts 68.06 kB ($${\color{green}-74.8\%}$$)
tgpu_accessor.ts 68.05 kB ($${\color{green}-74.8\%}$$)
tgpu_privateVar.ts 66.80 kB ($${\color{green}-75.2\%}$$)
tgpu_workgroupVar.ts 66.79 kB ($${\color{green}-75.2\%}$$)
tgpu_const.ts 66.28 kB ($${\color{green}-75.4\%}$$)
tgpu_lazy.ts 66.15 kB ($${\color{green}-75.5\%}$$)
tgpu_fn.ts 38.59 kB ($${\color{green}-85.7\%}$$)
tgpu_fragmentFn.ts 38.58 kB ($${\color{green}-85.7\%}$$)
tgpu_vertexFn.ts 38.40 kB ($${\color{green}-85.8\%}$$)
tgpu_computeFn.ts 38.10 kB ($${\color{green}-85.9\%}$$)
tgpu_vertexLayout.ts 27.22 kB ($${\color{green}-89.9\%}$$)
tgpu_comptime.ts 14.91 kB ($${\color{green}-94.5\%}$$)
tgpu_unroll.ts 1.66 kB ($${\color{green}-99.4\%}$$)
tgpu_slot.ts 1.54 kB ($${\color{green}-99.4\%}$$)

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates @typegpu/three to support Three.js’s WebGL backend path by switching TypeGPU shader generation to GLSL via @typegpu/gl when WebGL is detected.

Changes:

  • Add @typegpu/gl as a peer dependency and wire it into the workspace lockfile.
  • Detect WebGL backend in the node builder and apply glOptions({ shaderStage: 'none' }) to tgpu.resolve(...) calls.
  • Adjust function-start detection to handle GLSL-style function declarations.

Reviewed changes

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

File Description
pnpm-lock.yaml Adds @typegpu/gl to the workspace install graph for packages/typegpu-three.
packages/typegpu-three/src/typegpu-node.ts Adds WebGL detection + GLSL generation options via glOptions, and updates function-start detection.
packages/typegpu-three/package.json Declares @typegpu/gl as a peer dependency for @typegpu/three.
Files not reviewed (1)
  • pnpm-lock.yaml: Generated file

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

Comment on lines +100 to +102
function isWebGL(builder: THREE.NodeBuilder): boolean {
return 'isWebGLBackend' in builder.renderer.backend && !!builder.renderer.backend.isWebGLBackend;
}
Comment on lines +184 to 188
const lastFnStart = findFunctionStart(stageData.codeGeneratedThusFar, functionId, webgl);

// Extracting the function code
const fnCode = stageData.codeGeneratedThusFar.slice(lastFnStart).trim();

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

Caution

The WebGL fallback path now generates GLSL, but forceExplicitVoidReturn is WGSL-only: it appends -> void after the first ), corrupting every GLSL function signature. This prevents the fallback from working. See the inline comment on packages/typegpu-three/src/typegpu-node.ts:193.

Reviewed changes

  • Declared @typegpu/gl as a peer dependency and wired glOptions({ shaderStage: 'none' }) into the three tgpu.resolve calls when the Three.js builder targets WebGL.
  • Added isWebGL() backend detection and findFunctionStart() to handle both WGSL (fn name) and GLSL (type name() function declaration syntax.
  • Refactored the dependency-assignment resolution in generate() into a local code variable.
  • Updated pnpm-lock.yaml to link the new peer dependency.

ℹ️ Docs will need updating once WebGL works

The @typegpu/three docs currently include a caution block stating that the WebGL fallback does not work. Once this feature branch makes it work, that block and the install instructions should be updated.

Pullfrog  | Fix it ➔View workflow run | Using Kimi K2 (free via Pullfrog for OSS) | 𝕏

@iwoplaza
iwoplaza force-pushed the feat/typegpu-three-gl-fallback branch from da61438 to a010b4f Compare August 5, 2026 23:05
@pullfrog

pullfrog Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Follow-up to the review above with line-specific notes:

  • packages/typegpu-three/src/typegpu-node.ts:193forceExplicitVoidReturn(fnCode) is WGSL-specific. When webgl is true, fnCode is GLSL (e.g. float foo() { ... } or void main() { ... }), so inserting -> void after the first ) corrupts the signature. This needs to be skipped for GLSL.

  • packages/typegpu-three/src/typegpu-node.ts:108functionId should be escaped before it is interpolated into the RegExp (\w+\s+${functionId}\s*\(). Generated IDs are usually safe, but a user-defined function name with regex metacharacters would mis-match or throw.

  • packages/typegpu-three/src/typegpu-node.ts:109 — If code.match(regexp) returns null, code.indexOf(undefined) searches for the literal substring "undefined". Check for a match explicitly and fall back to 0 instead.

  • packages/typegpu-three/package.json:49@typegpu/gl is imported unconditionally at the top of typegpu-node.ts, yet it is declared as a peer dependency. Consumers using only the WebGPU path still need it installed or the module fails to load. Consider a regular dependency or an optional peer dependency.

Pullfrog  | View workflow run | via Pullfrog | Using Kimi K2 (free via Pullfrog for OSS) | 𝕏

@iwoplaza
iwoplaza force-pushed the feat/typegpu-three-gl-fallback branch from a010b4f to 2cc2d21 Compare August 5, 2026 23:35

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

Important

The @typegpu/gl delta improves GLSL emission, but the WebGL fallback path is still blocked because forceExplicitVoidReturn corrupts GLSL signatures.

Reviewed changes

Reviewed the delta that removed the WORKAROUND_wgslToGlslFixups post-processor from @typegpu/gl and replaced it with native GLSL generation.

  • Removed WORKAROUND_wgslToGlslFixups from packages/typegpu-gl/src/tgpuRootWebGL.ts and its export in packages/typegpu-gl/src/index.ts.
  • Added native array support in packages/typegpu-gl/src/glslGenerator.ts: resolveArraySizeSuffix, array-aware declareGlobalConst, declareGlobalVar, typeAnnotation, typeInstantiation, and _emitVarDecl now emit GLSL type name[N] declarations and type[N](...) constructors.
  • Added a numericLiteral override that emits GLSL literals without WGSL f/h suffixes, keeps u for u32, and chooses decimal or exponential form for floats.
  • Updated @typegpu/gl test snapshots; all 35 @typegpu/gl tests pass.

⚠️ WebGL fallback remains broken for GLSL signatures

packages/typegpu-three/src/typegpu-node.ts:193 still applies forceExplicitVoidReturn(fnCode) unconditionally. The helper inserts -> void after the first ), which corrupts GLSL function signatures such as float foo() into float foo()-> void. This prevents the WebGL fallback from working even though @typegpu/gl now emits valid GLSL.

Technical details
# forceExplicitVoidReturn corrupts GLSL signatures

## Affected sites
- packages/typegpu-three/src/typegpu-node.ts:193 — `forceExplicitVoidReturn(fnCode)` is applied to GLSL code

## Required outcome
- GLSL function code must not be passed through the WGSL-specific `forceExplicitVoidReturn` helper.

## Suggested approach
Skip `forceExplicitVoidReturn` when `webgl` is true, or detect whether the resolved code already has a return type in a language-agnostic way.

Pullfrog  | Fix it ➔View workflow run | Using Kimi K2 (free via Pullfrog for OSS) | 𝕏

@iwoplaza
iwoplaza force-pushed the feat/typegpu-three-gl-fallback branch from 2cc2d21 to 7b889ba Compare August 6, 2026 08:11
@iwoplaza
iwoplaza force-pushed the feat/typegpu-three-gl-fallback branch from 7b889ba to 961d532 Compare August 6, 2026 13:58
@iwoplaza
iwoplaza force-pushed the feat/typegpu-three-gl-fallback branch from 961d532 to 6b3dea9 Compare August 6, 2026 14:03
@iwoplaza
iwoplaza force-pushed the feat/typegpu-three-gl-fallback branch from 6b3dea9 to 24d8fe3 Compare August 6, 2026 14:48
@iwoplaza
iwoplaza force-pushed the feat/typegpu-three-gl-fallback branch from 24d8fe3 to 75504e6 Compare August 6, 2026 14:49

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

Caution

The upstream @typegpu/gl fixes in this rebase are correct, but the PR's own @typegpu/three integration still applies a WGSL-only helper to GLSL code. The WebGL fallback therefore remains broken.

Reviewed changes

Reviewed the delta from the previous pullfrog review head (6b3dea9) to the current head (75504e6). The @typegpu/three changes are byte-for-byte identical to the previous iteration; the new commits come from the upstream feat/make-triangle-work-with-gl-fallback feature branch.

  • Eagerly reserved gl_Position and sample in packages/typegpu-gl/src/glslGenerator.ts on the first functionDefinition call, so the shaderStage: 'none' path used by @typegpu/three cannot accidentally use these GLSL keywords as identifiers.
  • Updated @typegpu/gl inline snapshots to match improved numeric-literal and zero-constructor emission (1i1, 0i0, 1.5f1.5, vec3()vec3(0)).
  • The @typegpu/three files are unchanged from the previous iteration.

🚨 WebGL fallback still blocked by forceExplicitVoidReturn

packages/typegpu-three/src/typegpu-node.ts:193 still passes the resolved function code through forceExplicitVoidReturn. That helper assumes WGSL syntax: it looks for -> to detect an explicit return type and otherwise appends -> void after the first ). GLSL function declarations do not contain ->, so a signature such as float foo() is corrupted into float foo()-> void, which is invalid GLSL. This was raised in the previous pullfrog review and has not been addressed in this rebase.

Technical details
# forceExplicitVoidReturn corrupts GLSL signatures

## Affected sites
- packages/typegpu-three/src/typegpu-node.ts:193 — `forceExplicitVoidReturn(fnCode)` is applied to GLSL code

## Required outcome
- GLSL function code must not be passed through the WGSL-specific `forceExplicitVoidReturn` helper.

## Suggested approach
Skip `forceExplicitVoidReturn` when `webgl` is true, or detect whether the resolved code already has a return type in a language-agnostic way.

Pullfrog  | Fix it ➔View workflow run | Using Kimi K2 (free via Pullfrog for OSS) | 𝕏

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