-
-
Notifications
You must be signed in to change notification settings - Fork 43
fix: Pointers for reference types #1591
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
Merged
Merged
Changes from 18 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
0400f93
Add TGSL parsing test
19d6ae6
Add `INTERNAL_createPtr`
3470135
Merge remote-tracking branch 'origin/main' into fix/pointers-for-refe…
924a4d1
Change pointer inner type to StorableData
6400895
Remove circular dep, add test, lint
5291a0c
Update packages/typegpu/src/std/array.ts
aleksanderkatan 9d7a087
Lint
8d83ad0
Some docs
5dff422
Lint
fa666cc
Review fixes
f602a68
Add private pointers to tgsl-pasing-test
b98cf02
Merge remote-tracking branch 'origin/main' into fix/pointers-for-refe…
071acf3
Merge fixes
bd56f2d
Add a tip about atomic std functions
75292c5
Change pointer schemas to camel case
e631d4f
Modify dereference message, lint
ce93828
Merge remote-tracking branch 'origin/main' into fix/pointers-for-refe…
1bd6404
Merge branch 'main' into fix/pointers-for-reference-types
aleksanderkatan 97eb673
Merge remote-tracking branch 'origin/main' into fix/pointers-for-refe…
68e3624
Merge fixes
106d411
Update apps/typegpu-docs/src/content/docs/fundamentals/tgsl.mdx
aleksanderkatan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
apps/typegpu-docs/src/content/examples/tests/tgsl-parsing-test/pointers.ts
aleksanderkatan marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import tgpu from 'typegpu'; | ||
| import * as d from 'typegpu/data'; | ||
| import * as std from 'typegpu/std'; | ||
|
|
||
| const SimpleStruct = d.struct({ vec: d.vec2f }); | ||
|
|
||
| const modifyNumFn = tgpu.fn([d.ptrFn(d.u32)])((ptr) => { | ||
| // biome-ignore lint/style/noParameterAssign: it's just a test | ||
| ptr += 1; | ||
aleksanderkatan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| const modifyVecFn = tgpu.fn([d.ptrFn(d.vec2f)])((ptr) => { | ||
| ptr.x += 1; | ||
| }); | ||
|
|
||
| const modifyStructFn = tgpu.fn([d.ptrFn(SimpleStruct)])((ptr) => { | ||
| ptr.vec.x += 1; | ||
| }); | ||
|
|
||
| const privateNum = tgpu['~unstable'].privateVar(d.u32); | ||
| const modifyNumPrivate = tgpu.fn([d.ptrPrivate(d.u32)])((ptr) => { | ||
| // biome-ignore lint/style/noParameterAssign: it's just a test | ||
| ptr += 1; | ||
| }); | ||
|
|
||
| const privateVec = tgpu['~unstable'].privateVar(d.vec2f); | ||
| const modifyVecPrivate = tgpu.fn([d.ptrPrivate(d.vec2f)])((ptr) => { | ||
| ptr.x += 1; | ||
| }); | ||
|
|
||
| const privateStruct = tgpu['~unstable'].privateVar(SimpleStruct); | ||
| const modifyStructPrivate = tgpu.fn([d.ptrPrivate(SimpleStruct)])((ptr) => { | ||
| ptr.vec.x += 1; | ||
| }); | ||
|
|
||
| // TODO: replace `s = s &&` with `s &&=` when implemented | ||
| export const pointersTest = tgpu.fn([], d.bool)(() => { | ||
| let s = true; | ||
|
|
||
| // function pointers | ||
| const num = d.u32(); | ||
| modifyNumFn(num); | ||
| s = s && (num === 1); | ||
|
|
||
| const vec = d.vec2f(); | ||
| modifyVecFn(vec); | ||
| s = s && std.allEq(vec, d.vec2f(1, 0)); | ||
|
|
||
| const myStruct = SimpleStruct(); | ||
| modifyStructFn(myStruct); | ||
| s = s && std.allEq(myStruct.vec, d.vec2f(1, 0)); | ||
|
|
||
| // private pointers | ||
| modifyNumPrivate(privateNum.$); | ||
| s = s && (privateNum.$ === 1); | ||
|
|
||
| modifyVecPrivate(privateVec.$); | ||
| s = s && std.allEq(privateVec.$, d.vec2f(1, 0)); | ||
|
|
||
| modifyStructPrivate(privateStruct.$); | ||
| s = s && std.allEq(privateStruct.$.vec, d.vec2f(1, 0)); | ||
|
|
||
| return s; | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,6 +73,7 @@ export type { | |
| Mat4x4f, | ||
| Ptr, | ||
| Size, | ||
| StorableData, | ||
| U16, | ||
| U32, | ||
| v2b, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,76 +1,57 @@ | ||
| import { $internal } from '../shared/symbols.ts'; | ||
| import type { AnyData } from './dataTypes.ts'; | ||
| import type { Ptr } from './wgslTypes.ts'; | ||
| import type { Access, AddressSpace, Ptr, StorableData } from './wgslTypes.ts'; | ||
|
|
||
| export function ptrFn<T extends AnyData>( | ||
| export function ptrFn<T extends StorableData>( | ||
| inner: T, | ||
| ): Ptr<'function', T, 'read-write'> { | ||
| return { | ||
| [$internal]: true, | ||
| type: 'ptr', | ||
| inner, | ||
| addressSpace: 'function', | ||
| access: 'read-write', | ||
| } as Ptr<'function', T, 'read-write'>; | ||
| return INTERNAL_createPtr('function', inner, 'read-write'); | ||
| } | ||
|
|
||
| export function ptrPrivate<T extends AnyData>( | ||
| export function ptrPrivate<T extends StorableData>( | ||
| inner: T, | ||
| ): Ptr<'private', T, 'read-write'> { | ||
| return { | ||
| [$internal]: true, | ||
| type: 'ptr', | ||
| inner, | ||
| addressSpace: 'private', | ||
| access: 'read-write', | ||
| } as Ptr<'private', T, 'read-write'>; | ||
| return INTERNAL_createPtr('private', inner, 'read-write'); | ||
| } | ||
|
|
||
| export function ptrWorkgroup<T extends AnyData>( | ||
| export function ptrWorkgroup<T extends StorableData>( | ||
| inner: T, | ||
| ): Ptr<'workgroup', T, 'read-write'> { | ||
| return { | ||
| [$internal]: true, | ||
| type: 'ptr', | ||
| inner, | ||
| addressSpace: 'workgroup', | ||
| access: 'read-write', | ||
| } as Ptr<'workgroup', T, 'read-write'>; | ||
| return INTERNAL_createPtr('workgroup', inner, 'read-write'); | ||
| } | ||
|
|
||
| export function ptrStorage< | ||
| T extends AnyData, | ||
| T extends StorableData, | ||
| TAccess extends 'read' | 'read-write' = 'read', | ||
| >(inner: T, access: TAccess = 'read' as TAccess): Ptr<'storage', T, TAccess> { | ||
| return { | ||
| [$internal]: true, | ||
| type: 'ptr', | ||
| inner, | ||
| addressSpace: 'storage', | ||
| access, | ||
| } as Ptr<'storage', T, TAccess>; | ||
| return INTERNAL_createPtr('storage', inner, access); | ||
| } | ||
|
|
||
| export function ptrUniform<T extends AnyData>( | ||
| export function ptrUniform<T extends StorableData>( | ||
| inner: T, | ||
| ): Ptr<'uniform', T, 'read'> { | ||
| return { | ||
| [$internal]: true, | ||
| type: 'ptr', | ||
| inner, | ||
| addressSpace: 'uniform', | ||
| access: 'read', | ||
| } as Ptr<'uniform', T, 'read'>; | ||
| return INTERNAL_createPtr('uniform', inner, 'read'); | ||
| } | ||
|
|
||
| export function ptrHandle<T extends AnyData>( | ||
| export function ptrHandle<T extends StorableData>( | ||
| inner: T, | ||
| ): Ptr<'handle', T, 'read'> { | ||
| return INTERNAL_createPtr('handle', inner, 'read'); | ||
| } | ||
|
|
||
| function INTERNAL_createPtr< | ||
| TAddressSpace extends AddressSpace, | ||
| TInner extends StorableData, | ||
| TAccess extends Access, | ||
| >( | ||
| addressSpace: TAddressSpace, | ||
| inner: TInner, | ||
| access: TAccess, | ||
| ): Ptr<TAddressSpace, TInner, TAccess> { | ||
| return { | ||
| [$internal]: true, | ||
| type: 'ptr', | ||
| addressSpace, | ||
| inner, | ||
| addressSpace: 'handle', | ||
| access: 'read', | ||
| } as Ptr<'handle', T, 'read'>; | ||
| access, | ||
| } as Ptr<TAddressSpace, TInner, TAccess>; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.