fix(@typegpu/gl): Reserve all keywords defined in the GLSL ES 3.0 spec - #2905
fix(@typegpu/gl): Reserve all keywords defined in the GLSL ES 3.0 spec#2905iwoplaza wants to merge 1 commit into
Conversation
|
pkg.pr.new packages benchmark commit |
There was a problem hiding this comment.
Pull request overview
This PR expands @typegpu/gl’s GLSL generator identifier reservation to cover the full set of keywords (and built-in globals) from the GLSL ES 3.0 specification, preventing generated names from colliding with reserved tokens in emitted GLSL.
Changes:
- Added a
reservedKeywordslist (GLSL ES 3.0 keywords + built-in globals) inglslGenerator.ts. - Updated
GlslGenerator.initGenerator()to reserve all entries from that list viactx.reserveIdentifier(...).
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
ℹ️ ВAppпру two typos inline — both inside the new keyword list.
Reviewed changes
- Replaced the one-off
reserveIdentifier('gl_Position', 'global')/reserveIdentifier('sample', 'global')calls with a module-levelreservedKeywordsarray enumerating the globals, defined keywords, and future-reserved type/qualifier words from GLSL ES 3.0, reserved in a loop inside the generator constructor.
The list goes one word too far in a couple of places (see the inline comment and nitpick).
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
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.93, 4.38, 6.55, 7.20, 10.98, 25.09, 23.63]
line [0.93, 1.86, 4.27, 6.53, 7.90, 12.47, 23.31, 23.28]
line [0.95, 1.92, 4.16, 6.70, 7.96, 12.49, 23.35, 24.58]
---
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.34, 0.54, 0.71, 0.76, 1.03, 1.14, 1.33, 1.59]
line [0.28, 0.45, 0.68, 0.76, 1.04, 1.11, 1.30, 1.50]
line [0.31, 0.53, 0.67, 0.82, 1.03, 1.15, 1.38, 1.49]
---
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.87, 2.17, 3.42, 7.18, 12.24, 25.75, 54.47, 110.95]
line [0.87, 2.05, 3.50, 7.25, 12.67, 26.88, 55.09, 111.32]
line [0.85, 2.15, 3.37, 7.15, 12.81, 26.36, 55.32, 111.50]
|
Bundle size comparison (
|
| 🟢 Decreased | ➖ Unchanged | 🔴 Increased | ❔ Unknown |
|---|---|---|---|
| 0 | 325 | 0 | 0 |
import { ... } in PR vs import * as ... in PR (is the library tree-Shakeable?):
| Test | tsdown |
|---|---|
| tgpu_init.ts | 263.10 kB ( |
| tgpu_initFromDevice.ts | 262.56 kB ( |
| tgpu_resolve.ts | 161.75 kB ( |
| tgpu_resolveWithContext.ts | 161.68 kB ( |
| tgpu_bindGroupLayout.ts | 62.32 kB ( |
| tgpu_mutableAccessor.ts | 57.04 kB ( |
| tgpu_accessor.ts | 57.04 kB ( |
| tgpu_privateVar.ts | 55.73 kB ( |
| tgpu_workgroupVar.ts | 55.73 kB ( |
| tgpu_const.ts | 55.15 kB ( |
| tgpu_lazy.ts | 54.95 kB ( |
| tgpu_fragmentFn.ts | 39.68 kB ( |
| tgpu_fn.ts | 39.62 kB ( |
| tgpu_vertexFn.ts | 39.50 kB ( |
| tgpu_computeFn.ts | 39.20 kB ( |
| tgpu_vertexLayout.ts | 28.33 kB ( |
| tgpu_comptime.ts | 15.93 kB ( |
| tgpu_unroll.ts | 1.75 kB ( |
| tgpu_slot.ts | 1.70 kB ( |
If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu.
47dbd0f to
22ac1a8
Compare
22ac1a8 to
d151ba8
Compare
There was a problem hiding this comment.
✅ No new issues found. Prior feedback addressed in
d151ba82.
Reviewed changes
- Fixed the
pler2DMSArraytypo tosampler2DMSArray, restoring reservation of the real GLSL ES keyword (it now matches itsisampler2DMSArray/usampler2DMSArraysiblings). - Removed the duplicate
volatileentry.
Both items raised in the previous review are cleanly resolved; the keyword list now has each real GLSL ES 3.0 word once and correctly spelled.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| 'gl_VertexID', | ||
| 'gl_InstanceID', | ||
| 'gl_Position', | ||
| 'gl_PointSize', | ||
| 'gl_FragCoord', | ||
| 'gl_FrontFacing', | ||
| 'gl_FragDepth', | ||
| 'gl_PointCoord', |
There was a problem hiding this comment.
Function names and variable names already cannot start with gl_ (though we don't enforce this yet):
Identifiers starting with “gl_” are reserved for use by OpenGL ES, and may not be declared in a shader as either a variable or a function.
it('...', () => {
const gl_fn = () => {
'use gpu';
const gl_color = d.vec4f(1, 0, 0, 1);
return gl_color;
};
const result = tgpu.resolveWithContext([gl_fn], glOptions());
expect(result.code).toMatchInlineSnapshot(`
"vec4 gl_fn() {
vec4 gl_color = vec4(1, 0, 0, 1);
return gl_color;
}"
`);
});Do we plan on banning them in the future?
| ctx.reserveIdentifier('gl_Position', 'global'); | ||
| ctx.reserveIdentifier('sample', 'global'); // `sample` is a reserved word in GLSL ES (for multisample interpolation qualifiers), | ||
| for (const keyword of reservedKeywords) { | ||
| ctx.reserveIdentifier(keyword, 'global'); |
There was a problem hiding this comment.
Please add at least one test
it('renames invalid glsl identifiers', () => {
const gl_InstanceID = () => {
'use gpu';
const gl_VertexID = 1;
const iimage2D = 2;
return gl_VertexID + iimage2D;
};
expect(tgpu.resolve([gl_InstanceID], glOptions())).toMatchInlineSnapshot(`
"int gl_InstanceID_1() {
int gl_VertexID_1 = 1;
int iimage2D_1 = 2;
return (gl_VertexID_1 + iimage2D_1);
}"
`);
});
No description provided.