-
-
Notifications
You must be signed in to change notification settings - Fork 43
feat: Support structs and arrays in console.log
#1732
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Support structs and arrays in console.log
#1732
Conversation
|
pkg.pr.new packages benchmark commit |
There was a problem hiding this 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.
…and-arrays-in-consolelog
iwoplaza
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UUuuuuugee! 👏
…and-arrays-in-consolelog
29d9aa7 to
ac6e2c1
Compare
1600 lines changed are just tests!
Changes:
number[]toUint32Arrayin deserialization (JS side) so that the deserialization takes O(n) time,console.log,safeStringify.ts->stringify.ts).