-
-
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
reczkok
commented
Jan 14, 2025
•
edited
Loading
edited
- Tests for unstruct resolution
- Tests for TgpuVertexLayout unwrapping
- Update docs
- Check if feasible to type check if every attribute has a location
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
apps/typegpu-docs/src/content/examples/simulation/game-of-life/index.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: Marcin Hawryluk <70582973+mhawryluk@users.noreply.github.com>
{/* | `root.unwrap(resource: TgpuTexture)` | Returns a `GPUTexture`. | */} | ||
{/* | `root.unwrap(resource: TgpuReadonlyTexture \| TgpuWriteonlyTexture \| TgpuMutableTexture \| TgpuSampledTexture)` | Returns a `GPUTextureView`. | */} | ||
|
||
:::note | ||
To unwrap a `TgpuVertexLayout` make sure that all its attributes are marked with the appropriate location. |
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.
A suggestion, this wording might suggest more that:
- It's something the dev has to do manually,
- This usually happens automatically, but it's a requirement when trying to unwrap
To unwrap a `TgpuVertexLayout` make sure that all its attributes are marked with the appropriate location. | |
To unwrap a `TgpuVertexLayout` make sure to explicitly mark each of its attributes with the appropriate location using `d.location(...)`. |
@@ -176,6 +176,108 @@ describe('tgpu resolve', () => { | |||
); | |||
}); | |||
|
|||
it('should resolve an unstruct to its corresponding struct', () => { | |||
const vertexInfo = d.unstruct({ |
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 stick to PascalCase for structs.
const vertexInfo = d.unstruct({ | |
const VertexInfo = d.unstruct({ |