Skip to content

fix(tgpu-gen): Generate matrix and f16 vector schemas for templated WGSL types - #3275

Open
RaphaelFakhri wants to merge 2 commits into
software-mansion:mainfrom
RaphaelFakhri:fix/tgpu-gen-mat-f16-aliases
Open

RaphaelFakhri wants to merge 2 commits into
software-mansion:mainfrom
RaphaelFakhri:fix/tgpu-gen-mat-f16-aliases

Conversation

@RaphaelFakhri

@RaphaelFakhri RaphaelFakhri commented Oct 25, 2026 •

Copy link
Copy Markdown

tgpu-gen converts templated WGSL types to TypeGPU schemas in typeToAlias, which only handles vec2/vec3/vec4 with i32, u32 or f32. For any other templated type it returns undefined, so these members become d.undefined in the generated code:

  • mat2x2<f32>, mat3x3<f32>, mat4x4<f32>
  • vec2<f16>, vec3<f16>, vec4<f16>
  • vec2<bool>, vec3<bool>, vec4<bool>

The shorthand forms (mat4x4f, vec3h) already work because they skip that function.

Changes

  • typeToAlias maps vecN<f16> to vecNh, vecN<bool> to vecNb and the square matNxN<f32> types to matNxNf, matching the schemas exported from typegpu/data.
  • Adds structs generator tests that cover these types.

Testing

The packages/tgpu-gen tests pass: 32 tests. Without the gen.mjs changes, the new tests fail because the output contains d.undefined.

Fixes #3274

Copilot AI balanced review requested due to automatic review settings October 25, 2026 00:43

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@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 optional suggestion inline.

Reviewed changes

  • typeToAlias mappings (packages/tgpu-gen/gen.mjs) — adds vecN<f16> → vecNh and square matNxN<f32> → matNxNf, so those templated members no longer emit d.undefined. Correct: both map to schemas that typegpu/data actually exports (d.vec2h/3h/4h, d.mat2x2f/3x3f/4x4f).
  • structs generator test (packages/tgpu-gen/tests/structs.test.ts) — new case asserting the f16 vector and square-matrix member mappings. Verified locally: npx vitest run --project=!browser packages/tgpu-gen reports 31 passing tests, and the new case fails without the gen.mjs change.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

Comment thread packages/tgpu-gen/gen.mjs
Map vec2<bool>, vec3<bool> and vec4<bool> to d.vec2b, d.vec3b and d.vec4b instead of d.undefined.
@RaphaelFakhri

Copy link
Copy Markdown
Author

Thanks for the suggestion. typegpu/data exports vec2b, vec3b and vec4b (packages/typegpu/src/data/index.ts), so commit e1f0779 maps vec2<bool>, vec3<bool> and vec4<bool> to d.vec2b, d.vec3b and d.vec4b in typeToAlias. A new structs test covers the three types. It fails without the gen.mjs change (1 failed, 31 passed) and passes with it (32 passed).

@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

  • vecN<bool> alias mapping (packages/tgpu-gen/gen.mjs) — adds a bool branch returning vec2b/vec3b/vec4b, closing the d.undefined hole the prior review flagged. Verified d.vec2b/3b/4b are exported from typegpu/data.
  • bool vector test (packages/tgpu-gen/tests/structs.test.ts) — new case asserting the bool member mappings.

Confirmed npx vitest run --project=!browser packages/tgpu-gen reports 32 passing tests. The prior review's suggestion was addressed and its thread resolved.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

This branch has not been deployed

No deployments
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.

tgpu-gen: templated matrix and f16 vector types generate d.undefined

2 participants