-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
Make unstruct resolvable and introduce root.unwrap(TgpuVertexLayout)
#781
base: main
Are you sure you want to change the base?
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
I experimented with this: export type HasAllPropsWithLocations<T> = T extends TgpuVertexLayout<infer U>
? HasAllPropsWithLocations<U>
: T extends WgslStruct | Unstruct
? {
[K in keyof T['propTypes']]: HasAllPropsWithLocations<
T['propTypes'][K]
>;
}[keyof T['propTypes']] extends false
? false
: true
: T extends { elementType: unknown }
? HasAllPropsWithLocations<T['elementType']>
: HasCustomLocation<T> extends false
? false
: true; but keep running into |
apps/typegpu-docs/src/content/docs/fundamentals/vertex-layouts.mdx
Outdated
Show resolved
Hide resolved
apps/typegpu-docs/src/content/docs/fundamentals/vertex-layouts.mdx
Outdated
Show resolved
Hide resolved
apps/typegpu-docs/src/content/examples/simulation/boids/index.ts
Outdated
Show resolved
Hide resolved
trianglePos: { uniform: d.arrayOf(TriangleInfoStruct, triangleAmount) }, | ||
colorPalette: { uniform: d.vec3f }, | ||
}); | ||
const vertexLayout = tgpu['~unstable'].vertexLayout((n) => |
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.
what do we do about [~unstable]
in published examples. I'd say we either
- make vertexLayout stable, docs public and release 0.3.3 right after merging this PR
- make boids experimental
- do nothing
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.
I'm kinda a fan of option 1
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.
Let's do option 1 🚀
I have changed the target to a next
branch, which we will accumulate any new features and docs about them until 0.4.0
apps/typegpu-docs/src/content/examples/simulation/game-of-life/index.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: Marcin Hawryluk <[email protected]>
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.
Great!
Co-authored-by: Iwo Plaza <[email protected]>
apps/typegpu-docs/src/content/docs/fundamentals/vertex-layouts.mdx
Outdated
Show resolved
Hide resolved
apps/typegpu-docs/src/content/docs/fundamentals/vertex-layouts.mdx
Outdated
Show resolved
Hide resolved
apps/typegpu-docs/src/content/docs/fundamentals/vertex-layouts.mdx
Outdated
Show resolved
Hide resolved
apps/typegpu-docs/src/content/docs/fundamentals/vertex-layouts.mdx
Outdated
Show resolved
Hide resolved
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.
This is a really nice addition, awesome!! 🚀
The above example is great if the vertex buffer will also be used as a storage or uniform buffer. However, if you're only interested in the vertex data, you can use a loose schema instead. | ||
It is not restricted by alignment rules and can utilize many useful [vertex formats](https://www.w3.org/TR/webgpu/#vertex-formats). To create loose schemas, use `d.unstruct` instead of `d.struct` and `d.disarrayOf` instead of `d.arrayOf`. | ||
Inside of loose schemas you can use vertex formats as well as the usual data types. |
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.
Thank you ChatGPU 🫡
The above example is great if the vertex buffer will also be used as a storage or uniform buffer. However, if you're only interested in the vertex data, you can use a loose schema instead. | |
It is not restricted by alignment rules and can utilize many useful [vertex formats](https://www.w3.org/TR/webgpu/#vertex-formats). To create loose schemas, use `d.unstruct` instead of `d.struct` and `d.disarrayOf` instead of `d.arrayOf`. | |
Inside of loose schemas you can use vertex formats as well as the usual data types. | |
If the vertex buffer is not required to function as a storage or uniform buffer, a *loose schema* may be used to define the vertex data layout. Loose schemas are not subject to alignment restrictions and allow the use of various [vertex formats](https://www.w3.org/TR/webgpu/#vertex-formats). | |
To define a loose schema: | |
- Use `d.unstruct` instead of `d.struct`. | |
- Use `d.disarrayOf` instead of `d.arrayOf`. | |
Within a loose schema, both standard data types and vertex formats can be utilized. |
const LooseParticleGeometry = d.unstruct({ | ||
tilt: d.f32, | ||
angle: d.f32, | ||
color: d.unorm8x4, // 4x8-bit unsigned normalized |
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.
color: d.unorm8x4, // 4x8-bit unsigned normalized | |
// four 8-bit values, unsigned & normalized | |
// i.e., four integers in (0, 255) represent four floats in the range of (0.0, 1.0) | |
color: d.unorm8x4, |
}); | ||
``` | ||
|
||
If you are using a loose schema, you can now resolve it to get its WGSL representation. |
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.
If you are using a loose schema, you can now resolve it to get its WGSL representation. | |
Loose schemas can be interpreted in multiple ways within a shader. However, for convenience, they can be resolved to their default WGSL representation. |
closes #747