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/route-bin-ops-through-generatorfrom
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/route-bin-ops-through-generatorfrom
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@7a5292064831ffe1bcbae4461039563211c1dabd
https://pkg.pr.new/software-mansion/TypeGPU/tgpu-gen@7a5292064831ffe1bcbae4461039563211c1dabd
https://pkg.pr.new/software-mansion/TypeGPU/tinyest-for-wgsl@7a5292064831ffe1bcbae4461039563211c1dabd
https://pkg.pr.new/software-mansion/TypeGPU/typegpu@7a5292064831ffe1bcbae4461039563211c1dabd
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/cli@7a5292064831ffe1bcbae4461039563211c1dabd
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/color@7a5292064831ffe1bcbae4461039563211c1dabd
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/gl@7a5292064831ffe1bcbae4461039563211c1dabd
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/noise@7a5292064831ffe1bcbae4461039563211c1dabd
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/radiance-cascades@7a5292064831ffe1bcbae4461039563211c1dabd
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/react@7a5292064831ffe1bcbae4461039563211c1dabd
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/sdf@7a5292064831ffe1bcbae4461039563211c1dabd
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/three@7a5292064831ffe1bcbae4461039563211c1dabd
https://pkg.pr.new/software-mansion/TypeGPU/unplugin-typegpu@7a5292064831ffe1bcbae4461039563211c1dabd

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.64, 1.32, 2.65, 4.39, 4.92, 8.43, 13.80, 18.56]
  line [0.68, 1.39, 2.82, 4.29, 5.12, 8.72, 16.14, 16.09]
  line [0.65, 1.35, 2.85, 4.72, 5.36, 8.69, 16.67, 18.75]
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.26, 0.34, 0.45, 0.51, 0.70, 0.80, 0.93, 1.01]
  line [0.22, 0.37, 0.50, 0.58, 0.80, 0.88, 1.04, 1.09]
  line [0.22, 0.37, 0.54, 0.64, 0.87, 0.79, 1.00, 1.11]
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.65, 1.41, 2.54, 4.47, 8.47, 17.90, 36.50, 76.07]
  line [0.58, 1.43, 2.96, 5.15, 8.75, 17.88, 37.79, 75.85]
  line [0.69, 1.45, 2.73, 4.41, 8.73, 18.58, 38.52, 78.52]
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 -0.25%) ➖ Unchanged 🔴 Increased (max 2.79%) ❔ Unknown
6 129 187 1

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

Test tsdown
std_isBeingTranspiled.ts 15.71 kB ($${\color{red}+2.8\%}$$)
std_getTargetShaderLanguage.ts 15.77 kB ($${\color{red}+2.8\%}$$)
STATIC_std.ts 110.08 kB ($${\color{red}+0.5\%}$$)
std_getShaderStage.ts 15.76 kB

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

Test tsdown
tgpu_init.ts 268.26 kB ($${\color{green}-3.3\%}$$)
tgpu_initFromDevice.ts 267.73 kB ($${\color{green}-3.5\%}$$)
tgpu_resolve.ts 168.97 kB ($${\color{green}-39.1\%}$$)
tgpu_resolveWithContext.ts 168.90 kB ($${\color{green}-39.1\%}$$)
tgpu_bindGroupLayout.ts 73.91 kB ($${\color{green}-73.4\%}$$)
tgpu_mutableAccessor.ts 68.64 kB ($${\color{green}-75.3\%}$$)
tgpu_accessor.ts 68.63 kB ($${\color{green}-75.3\%}$$)
tgpu_privateVar.ts 67.33 kB ($${\color{green}-75.7\%}$$)
tgpu_workgroupVar.ts 67.32 kB ($${\color{green}-75.7\%}$$)
tgpu_const.ts 66.74 kB ($${\color{green}-75.9\%}$$)
tgpu_lazy.ts 66.54 kB ($${\color{green}-76.0\%}$$)
tgpu_fragmentFn.ts 38.92 kB ($${\color{green}-86.0\%}$$)
tgpu_fn.ts 38.86 kB ($${\color{green}-86.0\%}$$)
tgpu_vertexFn.ts 38.73 kB ($${\color{green}-86.0\%}$$)
tgpu_computeFn.ts 38.44 kB ($${\color{green}-86.1\%}$$)
tgpu_vertexLayout.ts 27.57 kB ($${\color{green}-90.1\%}$$)
tgpu_comptime.ts 15.18 kB ($${\color{green}-94.5\%}$$)
tgpu_unroll.ts 1.75 kB ($${\color{green}-99.4\%}$$)
tgpu_slot.ts 1.70 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 thread packages/typegpu-three/src/typegpu-node.ts
Comment thread packages/typegpu-three/src/typegpu-node.ts Outdated

@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) | 𝕏

@iwoplaza
iwoplaza force-pushed the feat/typegpu-three-gl-fallback branch 2 times, most recently from b4129ca to fb2b7ae Compare August 6, 2026 21:54

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

The prior forceExplicitVoidReturn concern is fixed, and the new GLSL implicit-pointer support is well covered by tests.

Reviewed changes

Reviewed the delta since the prior pullfrog review (75504e6). The latest commits add native GLSL handling for implicit const pointers and fix the WGSL-only return-type helper that was blocking the WebGL fallback.

  • Fixed forceExplicitVoidReturn corrupting GLSL signatures. packages/typegpu-three/src/typegpu-node.ts now skips the WGSL-specific helper when the Three.js builder targets WebGL, so GLSL functions no longer get -> void appended.
  • Refactored implicit-pointer const emission. packages/typegpu/src/tgsl/wgslGenerator.ts extracted the alias logic into a protected _aliasConstStatement method so language-specific generators can override it.
  • Added GLSL implicit-pointer support. packages/typegpu-gl/src/glslGenerator.ts overrides _aliasConstStatement: immutable memory is copied, mutable memory is aliased by inlining the original expression, and runtime index expressions are hoisted into let variables to guarantee single evaluation.
  • Added test coverage. packages/typegpu-gl/tests/implicitPointer.test.ts covers immutable copies, mutable aliases, nested member/index accesses, aliases of aliases, and local-variable aliases.

All @typegpu/gl and packages/typegpu tests pass.

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

@iwoplaza
iwoplaza force-pushed the feat/typegpu-three-gl-fallback branch from 5e1ad8a to c98cc33 Compare August 9, 2026 20:42
@iwoplaza
iwoplaza changed the base branch from feat/make-triangle-work-with-gl-fallback to feat/glsl-implicit-pointer-definitions August 9, 2026 20:44
@iwoplaza
iwoplaza force-pushed the feat/typegpu-three-gl-fallback branch from c98cc33 to c4ac089 Compare August 9, 2026 20:51

@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 new isWebGL helper dereferences builder.renderer without a null check, which crashes with TypeError: Cannot read properties of undefined (reading 'backend') whenever a TgpuFnNode is built against a renderer-less NodeBuilder. This breaks the base branch's own @typegpu/three test suite (packages/typegpu-three/tests/typegpu-node.test.ts, 3 failures) — those tests construct new WGSLNodeBuilder() without a renderer and pass on the base branch, so this is a regression introduced by this PR.

Reviewed changes

Reviewed the PR head c98cc339 against base ce1619a9. The branch was force-pushed/rebuilt since the prior pullfrog review (fb2b7ae9, unreachable), so this compares the current iteration against the advanced base.

  • Adapted the WebGL fallback to the new base APIs. typegpu-node.ts now uses a fresh glOptions() (no shaderStage arg) in #getNodeFunction, #analyzeFunction and generate, matches crossShaderStage state semantics, and resolves the function declaration from resolveWithContext's declarations via existingDeclarations.
  • Added isWebGL backend detection and preserved the webgl ? fnDeclaration : forceExplicitVoidReturn(fnDeclaration) guard.
  • GLSL implicit-pointer support (_aliasConstStatement override, immutable-copy / mutable-alias semantics, #hoistIndexAccesses) carried over to the new base; wgslGenerator.ts retainsthe extracted _aliasConstStatement hook.
  • @typegpu/gl peer dependency wiring and lockfile unchanged in substance.

Verified: packages/typegpu-gl suite fully passes (46 passed, 2 skipped, incl. implicitPointer.test.ts 6/6). packages/typegpu-three fails only on the isWebGL null-renderer path.

Pullfrog  | Fix all ➔Fix 👍s ➔View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment thread packages/typegpu-three/src/typegpu-node.ts Outdated

@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 renderer-less crash fix is a test-only patch. isWebGL still dereferences builder.renderer.backend unguarded, and it now trips the production fromTSL path: fromTSL(toTSL(...), type) resolves through the module-level renderer-less sharedBuilder = new WGSLNodeBuilder(), so isWebGL throws, the try/catch swallows it, and TypeGPU silently skips its TSL-vs-TypeGPU type comparison — while emitting two fromTSL: failed to infer node type via getNodeType; skipping type comparison. warnings in the PR's own test run (base emits zero). Guarding the access (e.g. !!builder.renderer &&) removes both warnings and also fixes the 3 test failures without needing the renderer mock.

Reviewed changes

Reviewed the single new commit c4ac0890 (head changed from c98cc339). The PR was also restructured: the implicit-pointer GLSL work now lives on the base branch feat/glsl-implicit-pointer-definitions, so this PR's own surface shrank to the @typegpu/three integration plus the test fix.

  • Added renderer/backend mocks to typegpu-node.test.ts and assigned builder.renderer in builderFor, fixing the renderer-less WGSLNodeBuilder crash that previously broke the 3 base tests.
  • isWebGL + glOptions() wiring unchanged from the prior iteration; forceExplicitVoidReturn skip for WebGL preserved.
  • @typegpu/gl peer dependency wiring unchanged in substance.

Verified: packages/typegpu-gl suite still fully green (46 passed, 2 skipped). packages/typegpu-three tests now pass, but emit two fromTSL: failed to infer node type warnings that a guarded isWebGL eliminates.

Technical details
# isWebGL unguarded deref degrades fromTSL type comparison

## Affected sites
- packages/typegpu-three/src/typegpu-node.ts:113-115 — `isWebGL` reads `builder.renderer.backend`
- packages/typegpu-three/src/typegpu-node.ts:394-395 — `fromTSL` caches a renderer-less `new WGSLNodeBuilder()` as `sharedBuilder`, then calls `node.getNodeType(sharedBuilder)` in try/catch (lines 398-403)

## Required outcome
- `isWebGL` must not throw on builders without a `renderer` (both the tests' bare builders and `fromTSL`'s `sharedBuilder`).

## Suggested approach
- Guard the access: `return !!builder.renderer && 'isWebGLBackend' in builder.renderer.backend && !!builder.renderer.backend.isWebGLBackend;`
- Verified: with that one-line guard, `packages/typegpu-three/tests/typegpu-node.test.ts` passes with zero `fromTSL` warnings.

## Open questions for the human
- Keep the renderer mock in the test (it makes the setup more faithful) while adding the guard, or replace the mock with the guard alone?

Pullfrog  | Fix all ➔Fix 👍s ➔View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment thread packages/typegpu-three/src/typegpu-node.ts Outdated
@iwoplaza
iwoplaza force-pushed the feat/typegpu-three-gl-fallback branch from c4ac089 to aee322e Compare August 10, 2026 10:04
@iwoplaza
iwoplaza changed the base branch from feat/glsl-implicit-pointer-definitions to feat/route-bin-ops-through-generator August 10, 2026 10:05
@iwoplaza
iwoplaza force-pushed the feat/typegpu-three-gl-fallback branch from aee322e to 6e3e8c2 Compare August 10, 2026 10:06
@iwoplaza
iwoplaza force-pushed the feat/typegpu-three-gl-fallback branch from 6e3e8c2 to cc1f6fb Compare August 10, 2026 10:17
@iwoplaza
iwoplaza force-pushed the feat/typegpu-three-gl-fallback branch 2 times, most recently from 2e4aefa to 0bf429b Compare August 11, 2026 09:15
@iwoplaza
iwoplaza force-pushed the feat/typegpu-three-gl-fallback branch from 0bf429b to 5fa70c0 Compare August 11, 2026 09:21
@iwoplaza
iwoplaza force-pushed the feat/typegpu-three-gl-fallback branch from 5fa70c0 to 96e6104 Compare August 11, 2026 09:25

@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

A new test in this delta fails: WebGL storage arrays > lowers array reads through a typed TSL helper and writes to the current element. The generated compute code is direct GLSL subscripting (void item() { vec3 value = storageValue[2]; storageValue[2] = value; }), which never contains the asserted typegpuReadStorage marker. That identifier does not exist anywhere in the codebase — it's referenced only by the test itself — so the assertion cannot pass as written. This blocks the merge until either the typed-helper lowering (or whatever the test is meant to pin) is implemented, or the expectation is corrected to match actual codegen.

Reviewed changes

Reviewed the delta since the prior pullfrog review (c4ac0890):

  • Guarded isWebGL against renderer-less builders. packages/typegpu-three/src/typegpu-node.ts:128 now reads builder.renderer?.backend and returns false when there is no renderer, fixing the open unguarded-deref concern. The new uses the active WebGL builder to infer nested toTSL return types test pins the fix (passes with zero console.warn calls).
  • Added a WebGL storage-array test that builds a fake storage node through setup/analyze/generate and asserts GLSL codegen — this test currently fails.
  • Added SetupStageData / getSetupStageData plumbing to the builder data so WebGL builders can be exercised through the setup build stage.

⚠️ New WebGL storage-array test fails

packages/typegpu-three/tests/typegpu-node.test.ts:169 asserts the generated compute code contains typegpuReadStorage, but the generator emits plain array indexing instead. Since typegpuReadStorage is defined nowhere in the repo, this test is red on a clean run (verified locally: 4/5 pass, this one fails). Either the storage-array lowering through the typed helper is intended-but-not-implemented (then it needs implementing), or the assertion is stale and should match the real storageValue[2] codegen.

Technical details
# New WebGL storage-array test fails

## Affected sites
- packages/typegpu-three/tests/typegpu-node.test.ts:169 — expects `typegpuReadStorage` in `builder.getCodes('compute')`
- packages/typegpu-three/tests/typegpu-node.test.ts:153-171 — the failing test itself

## Required outcome
- The test must pass on a clean run. Either implement the typed-helper lowering it describes (or confirm it isn't needed and drop the marker assertion), or fix the expectation to the actual generated code.

## Suggested approach
- Run `pnpm vitest run --project=!browser packages/typegpu-three/tests/typegpu-node.test.ts` to reproduce the failure, then decide whether the feature or the assertion is in error.

ℹ️ Nitpicks

  • packages/typegpu-three/src/typegpu-node.ts:84-91getSetupStageData/SetupStageData/setupStageDataMap are added but never called anywhere (only getGenerateStageData/getAnalyzeStageData have call sites). If the setup build stage doesn't need its own stage data yet, this is dead code added by the delta.

Pullfrog  | Fix all ➔Fix 👍s ➔View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

builder.setBuildStage('generate');

expect(() => fn.build(builder)).not.toThrow();
expect(builder.getCodes('compute')).toContain('typegpuReadStorage');

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.

This test fails on a clean run: getCodes('compute') returns direct GLSL indexing (vec3 value = storageValue[2]; storageValue[2] = value;) and never contains typegpuReadStorage, which is defined nowhere in the repo. Either the typed-helper lowering this pins is missing (implement it) or the expectation is stale (match the actual codegen). Reproduce with pnpm vitest run --project=!browser packages/typegpu-three/tests/typegpu-node.test.ts.

@iwoplaza
iwoplaza force-pushed the feat/typegpu-three-gl-fallback branch from 96e6104 to f33e6db Compare August 11, 2026 13:37
@iwoplaza
iwoplaza force-pushed the feat/typegpu-three-gl-fallback branch from f33e6db to 68c6f79 Compare August 11, 2026 14:44
@iwoplaza
iwoplaza force-pushed the feat/typegpu-three-gl-fallback branch from 68c6f79 to f1a4dba Compare August 11, 2026 14:50
@iwoplaza
iwoplaza force-pushed the feat/typegpu-three-gl-fallback branch from f1a4dba to 7a52920 Compare August 11, 2026 15:02

function isWebGL(builder: THREE.NodeBuilder): boolean {
const backend = builder.renderer?.backend;
return !!backend && 'isWebGLBackend' in backend && !!backend.isWebGLBackend;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return !!backend && 'isWebGLBackend' in backend && !!backend.isWebGLBackend;
return !!backend && (backend as unknown as { isWebGLBackend}).isWebGLBackend === true;

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.

3 participants