Skip to content
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

[Discussion] A slimmer API for allowing buffer usages. #260

Open
iwoplaza opened this issue Sep 4, 2024 · 2 comments
Open

[Discussion] A slimmer API for allowing buffer usages. #260

iwoplaza opened this issue Sep 4, 2024 · 2 comments
Labels
discussion Dedicated for discussion about a certain topic.

Comments

@iwoplaza
Copy link
Collaborator

iwoplaza commented Sep 4, 2024

Motivation

  • Becomes hard to read with multiple allowed usages.
  • Not possible to use the same buffer with different strides ('instance'/'vertex').
  • $allowReadonly() and $allowMutable() add the same flags.

Before

// TgpuBuffer<typeof Grid> & AllowReadonly & AllowMutable & AllowVertex & Unmanaged
const fooBuffer = tgpu
  .createBuffer(Grid, initialGrid)
  .$allowReadonly()
  .$allowMutable()
  .$allowVertex('instance')
  .$device(device);

const fooReadonly = asReadonly(fooBuffer);
const fooMutable = asMutable(fooBuffer);
const fooVertex = asVertex(fooBuffer);

After

// TgpuBuffer<typeof Grid> & Storage & Vertex & Unmanaged
const fooBuffer = tgpu
  .createBuffer(Grid, initialGrid)
  .$usage(tgpu.Storage, tgpu.Vertex)
  .$device(device);

const fooReadonly = asReadonly(fooBuffer);
const fooMutable = asMutable(fooBuffer);
const fooVertex = asVertex(fooBuffer, 'instance');
@iwoplaza
Copy link
Collaborator Author

iwoplaza commented Sep 5, 2024

@reczkok @mhawryluk Thoughts? 🤔

@mhawryluk
Copy link
Collaborator

looks good 👍

@iwoplaza iwoplaza added the discussion Dedicated for discussion about a certain topic. label Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Dedicated for discussion about a certain topic.
Projects
None yet
Development

No branches or pull requests

2 participants