Skip to content

feat: Allow shader generators to report different language keys - #2792

Open
iwoplaza wants to merge 1 commit into
mainfrom
feat/custom-language-key-in-shader-generator
Open

feat: Allow shader generators to report different language keys#2792
iwoplaza wants to merge 1 commit into
mainfrom
feat/custom-language-key-in-shader-generator

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:07
@pullfrog

pullfrog Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Run failed. View the logs →

Pullfrog  | Rerun failed job ➔View workflow run | via Pullfrog | Using Kimi K2 (free via Pullfrog for OSS) | 𝕏

@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.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]
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.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]
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.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]
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 ➖ 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 264.53 kB ($${\color{green}-3.2\%}$$)
tgpu_initFromDevice.ts 264.00 kB ($${\color{green}-3.4\%}$$)
tgpu_resolve.ts 167.60 kB ($${\color{green}-38.7\%}$$)
tgpu_resolveWithContext.ts 167.53 kB ($${\color{green}-38.7\%}$$)
tgpu_bindGroupLayout.ts 71.83 kB ($${\color{green}-73.7\%}$$)
tgpu_mutableAccessor.ts 68.22 kB ($${\color{green}-75.0\%}$$)
tgpu_accessor.ts 68.22 kB ($${\color{green}-75.0\%}$$)
tgpu_privateVar.ts 66.96 kB ($${\color{green}-75.5\%}$$)
tgpu_workgroupVar.ts 66.96 kB ($${\color{green}-75.5\%}$$)
tgpu_const.ts 66.44 kB ($${\color{green}-75.7\%}$$)
tgpu_lazy.ts 66.32 kB ($${\color{green}-75.7\%}$$)
tgpu_fn.ts 38.75 kB ($${\color{green}-85.8\%}$$)
tgpu_fragmentFn.ts 38.75 kB ($${\color{green}-85.8\%}$$)
tgpu_vertexFn.ts 38.57 kB ($${\color{green}-85.9\%}$$)
tgpu_computeFn.ts 38.27 kB ($${\color{green}-86.0\%}$$)
tgpu_vertexLayout.ts 27.39 kB ($${\color{green}-90.0\%}$$)
tgpu_comptime.ts 15.07 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 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 languageKey to the ShaderGenerator interface as a required, read-only identifier for the target language.
  • Define languageKey on WgslGenerator (wgsl) and override it in GlslGenerator (glsl).
  • Update std.getTargetShaderLanguage() to return ctx.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.

Comment thread packages/typegpu/src/std/environment.ts Outdated
@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@d65d26ccd88557d7463847b4f29d0147c4e31ff0
https://pkg.pr.new/software-mansion/TypeGPU/tgpu-gen@d65d26ccd88557d7463847b4f29d0147c4e31ff0
https://pkg.pr.new/software-mansion/TypeGPU/tinyest-for-wgsl@d65d26ccd88557d7463847b4f29d0147c4e31ff0
https://pkg.pr.new/software-mansion/TypeGPU/typegpu@d65d26ccd88557d7463847b4f29d0147c4e31ff0
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/cli@d65d26ccd88557d7463847b4f29d0147c4e31ff0
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/color@d65d26ccd88557d7463847b4f29d0147c4e31ff0
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/gl@d65d26ccd88557d7463847b4f29d0147c4e31ff0
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/noise@d65d26ccd88557d7463847b4f29d0147c4e31ff0
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/radiance-cascades@d65d26ccd88557d7463847b4f29d0147c4e31ff0
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/react@d65d26ccd88557d7463847b4f29d0147c4e31ff0
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/sdf@d65d26ccd88557d7463847b4f29d0147c4e31ff0
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/three@d65d26ccd88557d7463847b4f29d0147c4e31ff0
https://pkg.pr.new/software-mansion/TypeGPU/unplugin-typegpu@d65d26ccd88557d7463847b4f29d0147c4e31ff0

benchmark
view benchmark

commit
view commit

@iwoplaza
iwoplaza force-pushed the feat/custom-language-key-in-shader-generator branch from ffacd45 to af40c03 Compare August 6, 2026 08:11

@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 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.ts JSDoc to say the function returns the shader language ultimately being generated (usually wgsl) 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`)".

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

@iwoplaza
iwoplaza force-pushed the feat/custom-language-key-in-shader-generator branch from af40c03 to d65d26c Compare August 6, 2026 09:26

@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
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.mdx summary and behavior table to describe getTargetShaderLanguage() as returning the name of the shader language being generated (usually 'wgsl').

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

#functionType: TgpuShaderStage | 'normal' | undefined;
#entryFnState: EntryFnState | undefined;

static {

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.

is there a reason why declare is omitted in glsl generator?

// prototype properties
declare languageKey: string;

The above code snippet comes from wgsl generator.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Because it inherits that property from the WgslGenerator class

@iwoplaza
iwoplaza force-pushed the feat/custom-language-key-in-shader-generator branch from d65d26c to 6f19b94 Compare August 6, 2026 17:00
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