Skip to content

Conversation

@aleksanderkatan
Copy link
Contributor

@aleksanderkatan aleksanderkatan commented Sep 19, 2025

1600 lines changed are just tests!

Changes:

  • revamp serialization (WGSL side) so that it is no longer stateless but it is simpler to use (it still is O(n^2) due to arguments being copied),
  • change number[] to Uint32Array in deserialization (JS side) so that the deserialization takes O(n) time,
  • support structs and arrays in GPU console.log,
  • slight refactor (safeStringify.ts->stringify.ts).

@aleksanderkatan aleksanderkatan linked an issue Sep 19, 2025 that may be closed by this pull request
@github-actions
Copy link

github-actions bot commented Sep 19, 2025

pkg.pr.new

packages
Ready to be installed by your favorite package manager ⬇️

https://pkg.pr.new/software-mansion/TypeGPU/typegpu@19c013d1689f1eb74df9eac8fe13063e8fc60f4b
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/noise@19c013d1689f1eb74df9eac8fe13063e8fc60f4b
https://pkg.pr.new/software-mansion/TypeGPU/unplugin-typegpu@19c013d1689f1eb74df9eac8fe13063e8fc60f4b

benchmark
view benchmark

commit
view commit

Copy link

Copilot AI left a comment

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 revamps the serialization system for GPU console.log to support structs and arrays. The serialization is now stateful instead of stateless, using private variables to track data positions, which simplifies usage while still being O(n²) due to argument copying. The deserialization was optimized by changing from number[] to Uint32Array for O(n) performance.

  • Revamped WGSL-side serialization to use stateful approach with private variables
  • Added support for structs and arrays in GPU console.log functionality
  • Optimized JavaScript-side deserialization with Uint32Array instead of number[]

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/typegpu/tests/tgsl/consoleLog.test.ts Updated test snapshots to reflect new serialization approach with stateful variables and added tests for nested arrays/structs
packages/typegpu/tests/examples/individual/log-test.test.ts Updated test snapshots showing new serialization code generation and added compound types test case
packages/typegpu/src/tgsl/wgslGenerator.ts Updated import path from safeStringify to stringify
packages/typegpu/src/tgsl/consoleLog/serializers.ts Major refactor: changed from stateless to stateful serialization using private variables, added support for structs and arrays
packages/typegpu/src/tgsl/consoleLog/deserializers.ts Updated to use Uint32Array instead of number[], added struct and array deserialization support
packages/typegpu/src/tgpuBindGroupLayout.ts Updated import path from safeStringify to stringify
packages/typegpu/src/std/atomic.ts Reordered imports and updated safeStringify import path
packages/typegpu/src/shared/stringify.ts New file containing safeStringify and niceStringify functions for better console output formatting
packages/typegpu/src/shared/safeStringify.ts File deleted - functionality moved to stringify.ts
packages/typegpu/src/resolutionCtx.ts Updated import paths to reflect file reorganization
packages/typegpu/src/data/alignmentOf.ts Added missing alignment entries for bool and vector bool types
apps/typegpu-docs/src/examples/tests/log-test/index.ts Added compound types test case and simplified some logging calls
apps/typegpu-docs/src/content/docs/fundamentals/utils.mdx Updated documentation to reflect new struct and array support
Comments suppressed due to low confidence (1)

packages/typegpu/src/tgsl/consoleLog/deserializers.ts:1

  • [nitpick] The function signature suggests that the entire Uint32Array is passed to each deserializer, but only a slice is needed. Consider updating the signature to accept the specific slice to avoid potential confusion and improve clarity.
import { mat2x2f, mat3x3f, mat4x4f } from '../../data/matrix.ts';

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@aleksanderkatan aleksanderkatan marked this pull request as ready for review September 22, 2025 15:55
Copy link
Collaborator

@iwoplaza iwoplaza left a comment

Choose a reason for hiding this comment

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

UUuuuuugee! 👏

@aleksanderkatan aleksanderkatan force-pushed the feat/support-structs-and-arrays-in-consolelog branch from 29d9aa7 to ac6e2c1 Compare September 26, 2025 13:58
@aleksanderkatan aleksanderkatan merged commit 68e5f20 into main Sep 26, 2025
5 checks passed
@aleksanderkatan aleksanderkatan deleted the feat/support-structs-and-arrays-in-consolelog branch October 10, 2025 15:45
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.

feat: Support structs and arrays in console.log

3 participants