Skip to content

fix: Matrix writers - #3178

Open
aleksanderkatan wants to merge 7 commits into
fix/matrix-infer-inputfrom
fix/matrix-fallback-writer
Open

aleksanderkatan wants to merge 7 commits into
fix/matrix-infer-inputfrom
fix/matrix-fallback-writer

Conversation

@aleksanderkatan

@aleksanderkatan aleksanderkatan commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Compiled writer didn't fill padding with zeroes, and fallback writer didn't handle JS arrays separately

@github-actions

github-actions Bot commented Oct 9, 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@33c6b9f14583f6213e78e7096b2c3c63a229e5fb

benchmark
view benchmark

commit
view commit

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

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

🟢 Decreased (max -0.20%) ➖ Unchanged 🔴 Increased ❔ Unknown
6 343 0 0

No notable changes.

If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu.

@github-actions

github-actions Bot commented Oct 9, 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.98, 2.06, 4.64, 7.21, 7.70, 12.38, 24.64, 27.69]
  line [1.05, 2.04, 4.18, 6.82, 7.67, 12.72, 25.98, 24.41]
  line [0.98, 1.91, 4.04, 6.83, 9.06, 11.40, 25.58, 25.85]
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.31, 0.53, 0.74, 0.89, 1.13, 1.18, 1.45, 1.60]
  line [0.35, 0.55, 0.73, 0.82, 1.11, 1.21, 1.47, 1.60]
  line [0.30, 0.50, 0.68, 0.86, 1.13, 1.21, 1.44, 1.67]
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 [1.00, 2.67, 4.53, 8.52, 13.33, 26.43, 55.80, 115.93]
  line [0.91, 2.31, 3.62, 7.31, 12.84, 26.81, 57.34, 112.01]
  line [0.90, 2.34, 4.00, 7.10, 12.59, 26.38, 55.27, 113.19]
Loading

@aleksanderkatan
aleksanderkatan added this pull request to stack #3179 October 9, 2026 11:01
@aleksanderkatan

Copy link
Copy Markdown
Member Author

@pullfrog review

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

Reviewed changes

  • mat3x3f fallback padding — the fallback writer (dataIO.ts) now distinguishes already-padded inputs (Float32Array / matrix instances) from compact JS arrays and, for the latter, inserts a per-column 0 so the on-wire layout matches the compiled writer's strided layout.
  • Write-side InferInput typing — DataWriter, writeData, and writeToArrayBuffer now accept InferInput<T> instead of Infer<T>; writer methods drop their explicit parameter annotations, and wgslTypes is imported as a value (rather than import type) so isMatInstance can run at runtime.
  • New noEval test file — tests/internal/arrayBufferIO.noEval.test.ts mocks the compiled writer out and mirrors the public arrayBufferIO.test.ts, adding mat3x3f array / matrix-instance / typed-array cases.

Verified locally: tests/internal + tests/arrayBufferIO.test.ts + tests/buffer.test.ts pass (558 tests), and pnpm --filter typegpu test:types is clean.

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

Comment thread packages/typegpu/src/data/dataIO.ts
@aleksanderkatan aleksanderkatan changed the title fix: Matrix fallback writer fix: Matrix writers Oct 9, 2026
@aleksanderkatan
aleksanderkatan marked this pull request as ready for review October 9, 2026 12:59
Copilot AI balanced review requested due to automatic review settings October 9, 2026 12:59

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 reached their quota limit.

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

( ◦°^°◦) 🏴☠️ Ahoy, matey! I read the whole diff o' the matrix writers end to end, ran the two test files (26 tests, all pass), typechecked the core package, an' sent a probe to be sure the no-eval mock truly forces the fallback writer. The compiled writer now zeroes mat3x3f column padding, an' the fallback writer pads packed JS arrays — the hull be sound. Previous findin' be addressed; ship it!

Reviewed changes

  • Compiled writer zeroes mat3x3f padding — buildWriter's matrix branch now iterates matSize * wgslElementStride (12 for mat3x3f) and emits writeFloat32(..., 0) for the three column-padding floats (row >= matSize), which were previously left untouched. Index math for non-padding elements is unchanged. This closes the earlier review finding (divergence between compiled and fallback writers on reused buffers).
  • Fallback writer handles JS arrays — dataWriters.mat3x3f now distinguishes Float32Array/matrix instances (already padded, iterate as-is) from packed JS arrays (emit 3 floats per column plus a 0 padding float).
  • dataIO type cleanup — writeData/writeToArrayBuffer value params narrowed to InferInput, wgsl switched to a runtime namespace import, and a cast dropped in writeToArrayBuffer.
  • Test coverage for both paths — arrayBufferIO.test.ts gains mat3x3f override/padding assertions (compiled path), and a new tests/internal/arrayBufferIO.noEval.test.ts mocks getCompiledWriter to exercise the fallback writer across vec/array/struct/mat/typed-array inputs.

Verified: npx vitest run tests/arrayBufferIO.test.ts tests/internal/arrayBufferIO.noEval.test.ts → 26 passing; npx tsc --noEmit in packages/typegpu → clean; a probe confirmed the vi.mock('../../src/data/compiledIO.ts') genuinely intercepts getCompiledWriter, so the no-eval suite really covers the fallback. Since only f32 matrices exist, the hardcoded 4-byte element stride is safe, and wgslTypes.ts has no import back into dataIO, so the new runtime namespace import introduces no cycle.

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.

2 participants