Skip to content

docs: Use immediates in point-light shadow example - #3034

Open
reczkok wants to merge 2 commits into
feat/immediate-pipelinesfrom
feat/tgpu-immediates-examples
Open

reczkok wants to merge 2 commits into
feat/immediate-pipelinesfrom
feat/tgpu-immediates-examples

Conversation

@reczkok

@reczkok reczkok commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Stacked on #3032.

The shadow-face view-projection matrix is delivered through an immediate when immediate_address_space is available, with the existing uniform as fallback via an accessor.

@reczkok
reczkok added this pull request to stack #3033 September 16, 2026 17:20
@github-actions

github-actions Bot commented Sep 16, 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@5d90be5f1f0c0cb747a52ba2dfe0fde2b2b4c4a0
https://pkg.pr.new/software-mansion/TypeGPU/tinyest@5d90be5f1f0c0cb747a52ba2dfe0fde2b2b4c4a0
https://pkg.pr.new/software-mansion/TypeGPU/tinyest-for-wgsl@5d90be5f1f0c0cb747a52ba2dfe0fde2b2b4c4a0
https://pkg.pr.new/software-mansion/TypeGPU/typegpu@5d90be5f1f0c0cb747a52ba2dfe0fde2b2b4c4a0
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/gl@5d90be5f1f0c0cb747a52ba2dfe0fde2b2b4c4a0
https://pkg.pr.new/software-mansion/TypeGPU/unplugin-typegpu@5d90be5f1f0c0cb747a52ba2dfe0fde2b2b4c4a0

benchmark
view benchmark

commit
view commit

@github-actions

github-actions Bot commented Sep 16, 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.99, 1.96, 4.42, 6.30, 7.30, 12.59, 23.76, 25.87]
  line [1.00, 2.09, 4.45, 6.81, 8.28, 11.83, 24.50, 25.07]
  line [1.00, 1.99, 4.44, 6.89, 8.66, 12.83, 24.48, 27.46]
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.30, 0.53, 0.72, 0.90, 1.16, 1.23, 1.44, 1.61]
  line [0.30, 0.57, 0.72, 0.87, 1.12, 1.22, 1.48, 1.65]
  line [0.30, 0.51, 0.67, 0.82, 1.09, 1.18, 1.39, 1.59]
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.82, 2.23, 4.44, 7.19, 13.01, 28.39, 56.85, 114.61]
  line [0.92, 2.19, 3.90, 8.09, 12.72, 27.16, 56.78, 115.09]
  line [0.93, 2.20, 4.04, 7.12, 12.60, 26.72, 58.59, 115.22]
Loading

@github-actions

github-actions Bot commented Sep 16, 2026

Copy link
Copy Markdown

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

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

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

Test tsdown
STATIC_tgpu.ts 279.10 kB ($${\color{red}+1.5\%}$$)
STATIC_allImports.ts 305.16 kB ($${\color{red}+1.3\%}$$)
tgpu_initFromDevice.ts 268.47 kB ($${\color{red}+1.3\%}$$)
tgpu_init.ts 269.02 kB ($${\color{red}+1.3\%}$$)
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.

@reczkok
reczkok force-pushed the feat/tgpu-immediates-examples branch from 4f4b2f6 to 4cc1acd Compare September 16, 2026 17:29
@reczkok
reczkok marked this pull request as ready for review September 16, 2026 20:17
Copilot AI lite review requested due to automatic review settings September 16, 2026 20:17

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.

🟡 Changes recommended

The advertised uniform fallback is not covered by the current tests.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Updates the point-light shadow example to use WGSL immediates when available while retaining a uniform-backed fallback.

Changes:

  • Adds per-face view-projection immediate handling.
  • Provides an accessor-based uniform fallback.
  • Exposes camera view-projection matrices.
  • Updates shader snapshot expectations.
File summaries
File Summary
apps/typegpu-docs/tests/individual-example-tests/point-light-shadow.test.ts Updates shader snapshots; moderate issue (2 votes): add coverage for the feature-disabled fallback path.
apps/typegpu-docs/src/examples/rendering/point-light-shadow/point-light.ts Creates and supplies the optional immediate matrix; moderate issue (1 vote): ensure the uniform-backed fallback is exercised.
apps/typegpu-docs/src/examples/rendering/point-light-shadow/index.ts Routes the depth shader through the immediate or uniform-backed accessor.
apps/typegpu-docs/src/examples/rendering/point-light-shadow/camera.ts Exposes and maintains the view-projection matrix.
Review details

Suppressed comments (1)

apps/typegpu-docs/src/examples/rendering/point-light-shadow/point-light.ts:49

  • The example test runs with the test utility's default wgslLanguageFeatures, which includes immediate_address_space, and its snapshot only asserts the immediate shader. The undefined branch that supplies the uniform-backed accessor at index.ts:288 is therefore never exercised, so a regression in the advertised fallback would pass; add a fallback run with the feature removed before importing the example and assert the depth shader uses camera.viewProjectionMatrix.
    this.faceImmediate = root.enabledWgslLanguageFeatures.has('immediate_address_space')
  • Files reviewed: 4/4 changed files
  • Comments generated: 1
  • Review effort level: Lite

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

Comment on lines +25 to +35
@@ -37,7 +32,7 @@ describe('point light shadow example', () => {
@vertex fn vertexDepth(@location(0) position: vec3f, @location(3) column1: vec4f, @location(4) column2: vec4f, @location(5) column3: vec4f, @location(6) column4: vec4f) -> vertexDepth_Output {
let modelMatrix = mat4x4f(column1, column2, column3, column4);
let worldPos = (modelMatrix * vec4f(position, 1f)).xyz;
let pos = (camera.viewProjectionMatrix * vec4f(worldPos, 1f));
let pos = (item * vec4f(worldPos, 1f));

@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 coverage observation below.

Reviewed changes

  • Depth pass delivers the face view-projection through an immediatefaceViewProj = tgpu.accessor(d.mat4x4f) is bound to pointLight.faceImmediate when immediate_address_space is available, otherwise to () => renderLayout.$.camera.viewProjectionMatrix.
  • PointLight creates a conditional immediate var and sets it per facerenderShadowMaps calls pipeline.with(faceImmediate, camera.viewProjectionMatrix) for each of the six faces; the fallback path reuses the per-camera uniform bind group.
  • Camera stores and exposes viewProjectionMatrix — the old #computeData splits into #computeViewProjection() and #cameraData(), giving the CPU side access to the matrix the immediate needs.
  • Snapshot regenerated for the immediate branchvar<immediate> item: mat4x4f and item * vec4f(...) replace the camera uniform in the depth module.

ℹ️ Fallback branch is no longer pinned by any test

The example test harness unconditionally advertises immediate_address_space (packages/typegpu-testing-utility/src/extendedIt.ts:224), so the regenerated snapshot only pins the immediate branch. The fallback branch — which is what runs on browsers without the extension today, i.e. most of them — is no longer asserted anywhere, so a regression in the accessor fallback would pass CI. I confirmed it currently resolves correctly, so this is a coverage note rather than a bug.

Technical details
# Fallback-path coverage gap

## Affected sites
- `apps/typegpu-docs/tests/individual-example-tests/point-light-shadow.test.ts` — the inline snapshot now pins only the `var<immediate> item` shader; the `camera.viewProjectionMatrix` variant is unasserted.
- `packages/typegpu-testing-utility/src/extendedIt.ts:224` — the mocked `navigator` unconditionally advertises `immediate_address_space`.

## Required outcome
- Restore coverage of the fallback branch that non-immediate hardware takes.

## Suggested approach (optional)
- Add a sibling test (separate file, since the example module is imported once per file) that clears `navigator.gpu.wgslLanguageFeatures` before `runExampleTest`, mirroring `point-light-shadow.test.ts`. Verified locally: the depth shader then emits `camera.viewProjectionMatrix` with no `var<immediate>`.

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

@cieplypolar cieplypolar left a comment

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.

Cool! Left 1 nit.

Comment thread apps/typegpu-docs/src/examples/rendering/point-light-shadow/point-light.ts Outdated
@reczkok
reczkok force-pushed the feat/tgpu-immediates-examples branch from 4cc1acd to 5d90be5 Compare September 18, 2026 09:19

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

Reviewed changes

  • Named the face immediatepointLight.faceImmediate now calls .$name('viewProjectionMatrix'), so the depth module emits var<immediate> viewProjectionMatrix: mat4x4f; and viewProjectionMatrix * vec4f(...); the inline snapshot was regenerated to match. This implements the human reviewer nit on point-light.ts:50.

Pullfrog  | View workflow run | Using DeepSeek Flash (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.

3 participants