software-mansion / software-mansion/TypeGPU

feat: Second argument to `.as` for reinterpretation

Open
#2,413 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
3.2k
Forks
122
Avg merge
3d 5h
Merged PRs (30d)
34

Description

This is equivalent in function to creating a new typed buffer and plugging in an existing GPUBuffer, but we can validate that the size of the schemas matches. Also, it's pretty cool.

const size = 4;

const array2d = <T extends AnyWgslData>(element: T, w: number, h: number) =>
  d.arrayOf(d.arrayOf(d.vec2h, w), h);

const displacementBuffer = root.createBuffer(array2d(d.vec2h, size, size)).$usage('storage');

const regularView = noiseBuffer.as('mutable');
const packedView = noiseBuffer.as('mutable', array2d(d.u32, size, size));

We could also go for a .reinterpret API, which would nicely extend to fixed usages:

const size = 4;

const array2d = <T extends AnyWgslData>(element: T, w: number, h: number) =>
  d.arrayOf(d.arrayOf(d.vec2h, w), h);

const displacementMutable = root.createMutable(array2d(d.vec2h, size, size));
const displacementPackedMutable = displacementMutable.reinterpret(array2d(d.u32, size, size));

To be discussed before attempting to implement

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No files or tests are named. Start by reviewing the existing .as and createBuffer entry points, then compare the proposed second argument with the alternative .reinterpret API; first resolve the API choice and schema-size validation behavior before attempting implementation.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, computer-graphics
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.