Skip to content

Conversation

@aleksanderkatan
Copy link
Contributor

@aleksanderkatan aleksanderkatan commented Aug 7, 2025

Changes:

  • merge schemaDefaultWrapper and schemaCloneWrapper into schemaCallWrapper that also handles vertex formats,
  • add copy semantics to unstruct call,
  • implement disarray call.

The wgslGenerator is left as is.

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

github-actions bot commented Aug 7, 2025

pkg.pr.new

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

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

benchmark
view benchmark

commit
view commit

Comment on lines +16 to +18
if (item === undefined) {
return callSchema();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This if is necessary because vector constructors actually distinguish between vec2f() and vec2f(undefined) (the second throws an error, I'm not sure, do we consider this an issue?)

Copy link
Contributor

Choose a reason for hiding this comment

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

I would say the error is correct. Calling vec2f(undefined) is not valid imo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's just that in most cases, f() is equivalent to f(undefined).
image
Though, now that I researched some more, I see that there are more exceptions to this, like destructuring a default parameter, so I guess we may just conclude vec2f(undefined) as invalid.

@aleksanderkatan aleksanderkatan marked this pull request as ready for review August 7, 2025 14:46
@cieplypolar cieplypolar requested a review from Copilot August 7, 2025 15:13
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 implements callable functionality for unstruct and disarray schemas, consolidating schema wrapper utilities and adding copy semantics. The changes enable schemas to be called as functions to create instances with proper deep copying behavior.

Key Changes

  • Merged schemaDefaultWrapper and schemaCloneWrapper into unified schemaCallWrapper that handles vertex formats
  • Added callable functionality to unstruct and disarray schemas with copy semantics
  • Updated error messages for consistency across array and disarray types

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/src/data/utils.ts Consolidates wrapper functions into schemaCallWrapper with vertex format support
packages/typegpu/src/data/unstruct.ts Implements callable unstruct with deep copy semantics
packages/typegpu/src/data/disarray.ts Implements callable disarray with validation and deep copy
packages/typegpu/src/data/dataTypes.ts Adds callable type signatures to Disarray and Unstruct interfaces
packages/typegpu/tests/unstruct.test.ts Adds comprehensive tests for callable unstruct functionality
packages/typegpu/tests/disarray.test.ts Adds comprehensive tests for callable disarray functionality
packages/typegpu/tests/data/utils.test.ts Tests for the new unified schema wrapper function
packages/typegpu/src/data/struct.ts Updates to use new unified wrapper function
packages/typegpu/src/data/array.ts Updates to use new wrapper and consistent error messages
packages/typegpu/src/core/function/tgpuFn.ts Updates import and usage of wrapper function
packages/typegpu/src/core/buffer/bufferUsage.ts Updates to use new unified wrapper function

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.

Merge! Merge! Merge! (after nit fix)

@aleksanderkatan aleksanderkatan merged commit d80eaa4 into main Aug 8, 2025
6 checks passed
@aleksanderkatan aleksanderkatan deleted the feat/callable-unstructs-and-disarrays branch August 14, 2025 11:28
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: Callable unstructs and disarrays

4 participants