feat: Allow shader generators to report different language keys - #2792
feat: Allow shader generators to report different language keys#2792iwoplaza wants to merge 1 commit into
Conversation
|
Run failed. View the logs →
|
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.68, 1.30, 2.96, 4.65, 5.56, 8.57, 17.01, 17.09]
line [0.63, 1.24, 2.65, 4.57, 4.95, 8.14, 15.76, 17.22]
line [0.65, 1.27, 2.77, 4.26, 5.05, 8.03, 16.28, 16.17]
---
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.42, 0.38, 0.83, 0.57, 0.78, 0.83, 0.98, 1.09]
line [0.20, 0.38, 0.52, 0.62, 0.81, 0.86, 1.01, 1.11]
line [0.25, 0.39, 0.54, 0.61, 0.86, 0.93, 1.07, 1.17]
---
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.62, 2.92, 5.01, 8.59, 17.26, 37.66, 77.18]
line [0.56, 1.47, 2.59, 4.53, 8.51, 17.41, 37.94, 77.40]
line [0.63, 1.55, 2.85, 4.35, 8.65, 17.97, 39.61, 80.35]
|
Bundle size comparison (
|
| 🟢 Decreased | ➖ Unchanged | 🔴 Increased (max 0.02%) | ❔ Unknown |
|---|---|---|---|
| 0 | 301 | 21 | 0 |
import { ... } in PR vs import * as ... in PR (is the library tree-Shakeable?):
| Test | tsdown |
|---|---|
| tgpu_init.ts | 260.83 kB ( |
| tgpu_initFromDevice.ts | 260.30 kB ( |
| tgpu_resolve.ts | 167.31 kB ( |
| tgpu_resolveWithContext.ts | 167.24 kB ( |
| tgpu_bindGroupLayout.ts | 71.66 kB ( |
| tgpu_mutableAccessor.ts | 68.05 kB ( |
| tgpu_accessor.ts | 68.05 kB ( |
| tgpu_privateVar.ts | 66.79 kB ( |
| tgpu_workgroupVar.ts | 66.79 kB ( |
| tgpu_const.ts | 66.27 kB ( |
| tgpu_lazy.ts | 66.15 kB ( |
| tgpu_fn.ts | 38.59 kB ( |
| tgpu_fragmentFn.ts | 38.58 kB ( |
| tgpu_vertexFn.ts | 38.40 kB ( |
| tgpu_computeFn.ts | 38.10 kB ( |
| tgpu_vertexLayout.ts | 27.22 kB ( |
| tgpu_comptime.ts | 14.91 kB ( |
| tgpu_unroll.ts | 1.66 kB ( |
| tgpu_slot.ts | 1.54 kB ( |
If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu.
There was a problem hiding this comment.
Pull request overview
This PR adds a standardized way for shader generators to report which target shading language they are generating, and wires that through to std.getTargetShaderLanguage() so it can reflect non-WGSL targets (e.g. GLSL).
Changes:
- Add
languageKeyto theShaderGeneratorinterface as a required, read-only identifier for the target language. - Define
languageKeyonWgslGenerator(wgsl) and override it inGlslGenerator(glsl). - Update
std.getTargetShaderLanguage()to returnctx.gen.languageKey(and add a GLSL-focused test).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/typegpu/src/tgsl/wgslGenerator.ts | Adds a prototype languageKey default (wgsl) to the base generator implementation. |
| packages/typegpu/src/tgsl/shaderGenerator.ts | Extends the generator contract with a required languageKey. |
| packages/typegpu/src/std/environment.ts | Switches getTargetShaderLanguage() to use the generator-provided languageKey. |
| packages/typegpu-gl/src/glslGenerator.ts | Sets the GLSL generator’s languageKey to glsl. |
| packages/typegpu-gl/tests/glslGenerator.test.ts | Adds coverage asserting GLSL resolution reports glsl via std.getTargetShaderLanguage(). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
pkg.pr.new packages benchmark commit |
ffacd45 to
af40c03
Compare
There was a problem hiding this comment.
Important
The public API docs for std.getTargetShaderLanguage() still describe the return value as only ever being 'wgsl' or undefined, but GLSL resolution now returns 'glsl'.
Reviewed changes
The latest commit revises the JSDoc for std.getTargetShaderLanguage() so it no longer hardcodes 'wgsl'.
- Updated
packages/typegpu/src/std/environment.tsJSDoc to say the function returns the shader language ultimately being generated (usuallywgsl) rather than always'wgsl'.
⚠️ Public docs are stale
apps/typegpu-docs/src/content/docs/apis/utils.mdx still states that std.getTargetShaderLanguage() returns 'wgsl' during WGSL resolution and undefined otherwise, and its behavior table still lists 'wgsl' for direct 'use gpu' callees, tgpu.comptime, and tgpu.lazy. Since GLSL resolution now returns 'glsl', this documentation is misleading and should be updated alongside the code change.
Technical details
# Stale public docs for `getTargetShaderLanguage`
## Affected sites
- `apps/typegpu-docs/src/content/docs/apis/utils.mdx:114` — summary claims the function returns `'wgsl'` during WGSL resolution
- `apps/typegpu-docs/src/content/docs/apis/utils.mdx:133-135` — behavior table lists `'wgsl'` for transpiled, comptime, and lazy environments
## Required outcome
- Update the docs to state that `std.getTargetShaderLanguage()` returns the active shader generator's language key (e.g. `'wgsl'`, `'glsl'`) during resolution and `undefined` otherwise.
- Update the behavior table to reflect that the returned key depends on the shader generator being used.
## Suggested approach (optional)
Mirror the revised JSDoc phrasing: "the shader language that is ultimately being generated (usually `wgsl`)".Kimi K2 (free via Pullfrog for OSS) | 𝕏
af40c03 to
d65d26c
Compare
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
The latest commit updates the public API docs for std.getTargetShaderLanguage() to reflect that the function now returns the active shader generator's language key rather than only 'wgsl'.
- Updated
apps/typegpu-docs/src/content/docs/apis/utils.mdxsummary and behavior table to describegetTargetShaderLanguage()as returning the name of the shader language being generated (usually'wgsl').
Kimi K2 (free via Pullfrog for OSS) | 𝕏
| #functionType: TgpuShaderStage | 'normal' | undefined; | ||
| #entryFnState: EntryFnState | undefined; | ||
|
|
||
| static { |
There was a problem hiding this comment.
is there a reason why declare is omitted in glsl generator?
// prototype properties
declare languageKey: string;The above code snippet comes from wgsl generator.
There was a problem hiding this comment.
Because it inherits that property from the WgslGenerator class

No description provided.