-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Compute shaders can read / write index and vertex buffers #6226
Conversation
*/ | ||
constructor(graphicsDevice, format, numVertices, usage = BUFFER_STATIC, initialData) { | ||
constructor(graphicsDevice, format, numVertices, usage = BUFFER_STATIC, initialData, options) { |
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.
Hmm. This constructor signature is getting a bit messy. If you pass options, you need to set a value of initialData
. which a lot of devs never pass. Feels like if this was written from scratch, usage
and initialData
would be in options
. IIRC, initialData
was added originally as a bit of a hack...
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 agree, but the devs can pass uninitialised
for those to get the default values.
But maybe it's time we move last 3 or so parameters to options?
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.
Looking at this, I think a separate PR would be a good idea here too.
* @param {boolean} [opts.storageVertex] - Defines if the vertex buffer of the mesh can be used as | ||
* a storage buffer by a compute shader. Defaults to false. Only supported on WebGPU. | ||
* @param {boolean} [opts.storageIndex] - Defines if the index buffer of the mesh can be used as | ||
* a storage buffer by a compute shader. Defaults to false. Only supported on WebGPU. |
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 not sure why I feel uneasy about adding new WebGPU-only options to this API. I almost feel like shape creation should be very simple and pure. Like maybe it should return just bare position, normal, uv and index arrays. And you create the mesh yourself in whatever form you like (e.g. whether you want it to be used by a compute shader etc).
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 idea! Happy with a separate PR for this?
Approving despite my reservations - but sounds like things can be addressed in follow up PRs. 😄 |
adjusted APIs to allow vertex / index buffer to be marked as accessible by compute shaders:
IndexBuffer and VertexBuffer constructor now take options parameter, and can specify:
options.storage = true;
Mesh constructor now takes options parameter, which can be:
options.storageVertex = true;
options.storageIndex = true;
procedural API - createMesh, createSphere and similar have additional valid options in the options class:
options.storageVertex = true;
options.storageIndex = true;
vertex or index buffer can be attached to a compute shader:
Example modifying the vertex buffer:
potato.mov