Skip to content

impr: Use Immediates in examples - #2813

Closed
reczkok wants to merge 28 commits into
feat/tgpu-immediatesfrom
feat/tgpu-immediates-examples
Closed

reczkok wants to merge 28 commits into
feat/tgpu-immediatesfrom
feat/tgpu-immediates-examples

Conversation

@reczkok

@reczkok reczkok commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@reczkok
reczkok marked this pull request as draft August 8, 2026 13:58
@github-actions

github-actions Bot commented Aug 8, 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/typegpu@5aa6bea72181c40591725c5f3565920dca10aeee
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/gl@5aa6bea72181c40591725c5f3565920dca10aeee

benchmark
view benchmark

commit
view commit

@github-actions

github-actions Bot commented Aug 8, 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 [1.01, 1.98, 4.61, 6.22, 7.25, 11.50, 22.76, 25.30]
  line [0.95, 1.94, 4.32, 7.06, 7.69, 11.72, 23.52, 26.69]
  line [1.02, 1.94, 4.60, 6.69, 7.27, 10.64, 23.72, 22.93]
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.35, 0.55, 0.70, 0.81, 1.05, 1.16, 1.37, 1.55]
  line [0.29, 0.48, 0.63, 0.77, 1.03, 1.13, 1.35, 1.49]
  line [0.33, 0.55, 0.68, 0.83, 1.09, 1.16, 1.32, 1.52]
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.86, 2.41, 3.51, 7.23, 12.27, 26.36, 55.16, 111.20]
  line [0.83, 2.28, 3.98, 7.03, 12.60, 26.59, 55.56, 112.12]
  line [0.89, 2.05, 3.43, 7.29, 12.43, 26.40, 54.39, 110.90]
Loading

@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown

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

🟢 Decreased ➖ Unchanged 🔴 Increased (max 1.77%) ❔ Unknown
0 39 286 0

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

Test tsdown
STATIC_tgpu.ts 277.66 kB ($${\color{red}+1.8\%}$$)
tgpu_initFromDevice.ts 267.04 kB ($${\color{red}+1.6\%}$$)
tgpu_init.ts 267.58 kB ($${\color{red}+1.6\%}$$)
STATIC_allImports.ts 303.91 kB ($${\color{red}+1.6\%}$$)
d_ref.ts 5.03 kB ($${\color{red}+0.9\%}$$)

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

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ No critical issues — one minor suggestion inline.

Reviewed changes

  • Lighting shaders — replaced DSL chains (.mul/.sub/.div) and tgpu.fn with 'use gpu' bodies using infix operators and direct accessor reads; depthToColor is now a plain TS 'use gpu' fn.
  • PointLight immediates — dropped the six shadow Cameras in favor of a tgpu.accessor(d.mat4x4f) fed by immediateVar + pass.setImmediates, with a per-face uniform-bind-group fallback when immediate_address_space is unsupported.
  • Render loop — moved to an explicit root['~unstable'].createCommandEncoder() with hand-rolled passes; destroyed depthTexture/msaaTexture on resize; scene._instanceBuffer now destroyed before rebuild.
  • Camera / typesCameraData struct replaced by a single d.mat4x4f viewProj uniform (dropped unused inverseViewProjectionMatrix).
  • box-geometry — model matrix built with wgpu-matrix (quat.fromEuler(…, 'zyx') + mat4.fromQuat/setTranslation/scale); verified equivalent to the old T*Rz*Ry*Rx*S chain.
  • Snapshot test — updated WGSL inline snapshot (immediate path).

I verified the two things that looked risky: pointLight.positionUniform.$ needs no explicit bind group (TypeGPU's auto-generated catch-all bind group covers it, see resolutionCtx.ts), and the wgpu-matrix fromEuler('zyx') quaternion is exactly qz⊗qy⊗qx, i.e. the same rotation the old rotationZ().mul(rotationY()).mul(rotationX()) chain produced.

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

Comment thread apps/typegpu-docs/src/examples/rendering/point-light-shadow/point-light.ts Outdated
@reczkok
reczkok force-pushed the feat/tgpu-immediates branch 2 times, most recently from e991685 to 3ed038b Compare September 1, 2026 23:56
@reczkok
reczkok force-pushed the feat/tgpu-immediates-examples branch from 85378ac to 5aa6bea Compare September 1, 2026 23:57
@reczkok
reczkok marked this pull request as ready for review September 1, 2026 23:58
Copilot AI lite review requested due to automatic review settings September 1, 2026 23:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The changes consistently update the example code, shader bindings, and tests to the new immediates/encoder-based approach without introducing any confirmed correctness issues.

Pull request overview

Updates the point-light-shadow docs example to use TypeGPU “Immediates” (with a uniform fallback) and the newer command-encoder/pass-style rendering flow, simplifying several data structures along the way.

Changes:

  • Switch shadow-face view-projection data to an accessor backed by an immediate var when supported, with a per-face uniform/bind-group fallback otherwise.
  • Simplify camera/view-projection handling (remove CameraData struct usage) and update shaders + bindings accordingly.
  • Move rendering to explicit CommandEncoder render passes; add explicit destruction for rebuilt buffers and resized textures.
File summaries
File Description
apps/typegpu-docs/tests/individual-example-tests/point-light-shadow.test.ts Updates the WGSL snapshot to reflect immediate-backed view-projection and new binding names.
apps/typegpu-docs/src/examples/rendering/point-light-shadow/types.ts Removes CameraData from the example’s shared types.
apps/typegpu-docs/src/examples/rendering/point-light-shadow/scene.ts Destroys/recreates the instance buffer when rebuilding the instance array.
apps/typegpu-docs/src/examples/rendering/point-light-shadow/point-light.ts Implements per-face shadow rendering using immediates (or per-face uniform fallback) and encoder-based passes.
apps/typegpu-docs/src/examples/rendering/point-light-shadow/index.ts Refactors the example to use encoder passes, binds the new view-projection inputs, and wires up shadow rendering accordingly.
apps/typegpu-docs/src/examples/rendering/point-light-shadow/camera.ts Uses a single mat4x4f uniform for view-projection (no inverse matrix).
apps/typegpu-docs/src/examples/rendering/point-light-shadow/box-geometry.ts Changes model-matrix construction to use wgpu-matrix quaternion/Euler utilities.
Review details
  • Files reviewed: 7/7 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ No critical issues — one minor suggestion inline.

Reviewed changes

  • Lighting shaders — replaced .mul/.sub/.div DSL chains and tgpu.fn with 'use gpu' bodies using infix operators and direct accessor reads; depthToColor is now a plain TS 'use gpu' arrow fn inlined into two fragment bodies.
  • PointLight immediates — dropped the six shadow Cameras for a tgpu.accessor(d.mat4x4f) fed by immediateVar + pass.setImmediates, with a per-face uniform bind-group (faceLayout) fallback when immediate_address_space is unsupported.
  • Render loop — explicit root['~unstable'].createCommandEncoder() with hand-rolled passes; depthTexture/msaaTexture destroyed on resize; scene.#instanceBuffer destroyed before rebuild.
  • Camera / typesCameraData struct replaced by a single d.mat4x4f viewProj uniform (dropped the unused inverseViewProjectionMatrix).
  • box-geometry — model matrix built with wgpu-matrix (quat.fromEuler(…, 'zyx') + mat4.fromQuat/setTranslation/scale).
  • Snapshot test — WGSL inline snapshot updated (immediate path).

I re-verified the previously-reviewed surface against the current head (5aa6bea): the wgpu-matrix fromEuler('zyx') rotation is numerically equivalent to the old T*Rz*Ry*Rx*S chain (max diff ~1e-7, float rounding only); the new pass API defaults depthLoadOp: 'clear' / depthClearValue: 1 for depth attachments, matching the old explicit values; and the non-immediate fallback compiles to valid WGSL (verified with a scratch test that removes immediate_address_space from the mock device's feature set).

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

pass.setVertexBuffer(instanceLayout, scene.instanceBuffer);
pass.setIndexBuffer(BoxGeometry.indexBuffer, 'uint16');
pass.setPipeline(pipeline);
if (this.#faceImmediate) {

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.

The uniform fallback branch (#faceUniforms/#faceBindGroups) is only exercised when immediate_address_space isn't supported, but the committed snapshot test always runs with the mock device's feature set containing it, so only the immediate path is covered. I confirmed the fallback compiles to valid WGSL (removing the feature yields @group(1) @binding(0) var<uniform> viewProj in the depth shader, no var<immediate> item) — but since this is the only code path on devices without the extension, a test variant that disables the feature would pin it against regressions.

cieplypolar and others added 11 commits September 9, 2026 09:58
* new transpilers

* external chain

* function parts

* simplify

* transpilation options

* more simplification

* working version

* fix types

* polish

* unplugin update

* review fixes

* consistent comments

* unnecessary import

* cleanup

* legacy

* review fixes
* update unsupported syntax in plugin

* tinyest + tinyest for wgsl

fix 1 test format

* obfuscation + tseynit

* wgslgenerator

* glslgenerator

* fix fields order in examples

* better error in glsl (tseynit)

* legacy transpilers support computed properties

* align with new api

* review fixes

- 0 new nodes

* rename parse -> transpile
@reczkok
reczkok force-pushed the feat/tgpu-immediates-examples branch from 5aa6bea to 4f4b2f6 Compare September 16, 2026 17:19
@reczkok
reczkok removed this pull request from stack #2814 September 16, 2026 17:20
@reczkok

reczkok commented Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

Moved to #3034, stacked on #3032.

@reczkok reczkok closed this Sep 16, 2026
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.

7 participants