Skip to content

fix(@typegpu/gl): Reserve all keywords defined in the GLSL ES 3.0 spec - #2905

Open
iwoplaza wants to merge 1 commit into
mainfrom
fix/glsl-reserved-keywords
Open

fix(@typegpu/gl): Reserve all keywords defined in the GLSL ES 3.0 spec#2905
iwoplaza wants to merge 1 commit into
mainfrom
fix/glsl-reserved-keywords

Conversation

@iwoplaza

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI lite review requested due to automatic review settings August 23, 2026 08:44
@github-actions

github-actions Bot commented Aug 23, 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/gl@d151ba82edee343f21aa453971fb162d3c0717e8

benchmark
view benchmark

commit
view commit

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.

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 reservedKeywords list (GLSL ES 3.0 keywords + built-in globals) in glslGenerator.ts.
  • Updated GlslGenerator.initGenerator() to reserve all entries from that list via ctx.reserveIdentifier(...).

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

Comment thread packages/typegpu-gl/src/glslGenerator.ts Outdated
Comment thread packages/typegpu-gl/src/glslGenerator.ts

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

ℹ️ В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-level reservedKeywords array 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).

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

Comment thread packages/typegpu-gl/src/glslGenerator.ts Outdated
@github-actions

github-actions Bot commented Aug 23, 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.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]
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.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]
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.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]
Loading

@github-actions

Copy link
Copy Markdown

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

🟢 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 ($${\color{green}-3.5\%}$$)
tgpu_initFromDevice.ts 262.56 kB ($${\color{green}-3.7\%}$$)
tgpu_resolve.ts 161.75 kB ($${\color{green}-40.7\%}$$)
tgpu_resolveWithContext.ts 161.68 kB ($${\color{green}-40.7\%}$$)
tgpu_bindGroupLayout.ts 62.32 kB ($${\color{green}-77.1\%}$$)
tgpu_mutableAccessor.ts 57.04 kB ($${\color{green}-79.1\%}$$)
tgpu_accessor.ts 57.04 kB ($${\color{green}-79.1\%}$$)
tgpu_privateVar.ts 55.73 kB ($${\color{green}-79.6\%}$$)
tgpu_workgroupVar.ts 55.73 kB ($${\color{green}-79.6\%}$$)
tgpu_const.ts 55.15 kB ($${\color{green}-79.8\%}$$)
tgpu_lazy.ts 54.95 kB ($${\color{green}-79.8\%}$$)
tgpu_fragmentFn.ts 39.68 kB ($${\color{green}-85.4\%}$$)
tgpu_fn.ts 39.62 kB ($${\color{green}-85.5\%}$$)
tgpu_vertexFn.ts 39.50 kB ($${\color{green}-85.5\%}$$)
tgpu_computeFn.ts 39.20 kB ($${\color{green}-85.6\%}$$)
tgpu_vertexLayout.ts 28.33 kB ($${\color{green}-89.6\%}$$)
tgpu_comptime.ts 15.93 kB ($${\color{green}-94.2\%}$$)
tgpu_unroll.ts 1.75 kB ($${\color{green}-99.4\%}$$)
tgpu_slot.ts 1.70 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.

@iwoplaza
iwoplaza force-pushed the fix/glsl-reserved-keywords branch from 47dbd0f to 22ac1a8 Compare August 23, 2026 09:12
@iwoplaza
iwoplaza force-pushed the fix/glsl-reserved-keywords branch from 22ac1a8 to d151ba8 Compare August 23, 2026 09:13

@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. Prior feedback addressed in d151ba82.

Reviewed changes

  • Fixed the pler2DMSArray typo to sampler2DMSArray, restoring reservation of the real GLSL ES keyword (it now matches its isampler2DMSArray / usampler2DMSArray siblings).
  • Removed the duplicate volatile entry.

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.

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

@aleksanderkatan aleksanderkatan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🔑L

Comment on lines +31 to +38
'gl_VertexID',
'gl_InstanceID',
'gl_Position',
'gl_PointSize',
'gl_FragCoord',
'gl_FrontFacing',
'gl_FragDepth',
'gl_PointCoord',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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);
      }"
    `);
  });

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.

4 participants