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

Implementation of StorageBuffer on WebGPU #6201

Merged
merged 8 commits into from
Apr 2, 2024
Merged

Conversation

mvaligursky
Copy link
Contributor

@mvaligursky mvaligursky commented Mar 25, 2024

related to #6009

  • implementation of the StorageBuffer class, to be used with WebGPU's Compute for read/write data.

intended public API

StorageBuffer.constructor(device, byteSize, bufferUsage);
StorageBuffer.destroy();

// clear part of the buffer to 0
StorageBuffer.clear(offset, size);

// async read of the GPU buffer
StorageBuffer.read(offset, size, allocatedTypeArray) : Promise<ArrayBuffer>;

// async upload (not implemented yet, follow up PR)
StorageBuffer.write(data, offset);
  • Compute now handles StorageBuffer as input / output. This will be slightly expanded in the follow up PRs (for example read-only buffer)
  • new example which demonstrate how to create a compute shader that generates a histogram, from the rendered image, downloads the results to CPU and renders it using lines. This is not the most performant implementation, as it requires async data download to the CPU, but this example demonstrates exactly that case, where a result of compute is needed on CPU. We'll have another example where compute generated storage buffer gets consumed by the GPU directly vertex of fragment shader).

Screenshot 2024-03-25 at 16 21 10

@mvaligursky mvaligursky self-assigned this Mar 25, 2024
@mvaligursky mvaligursky requested a review from a team March 25, 2024 16:31
@mvaligursky mvaligursky mentioned this pull request Mar 25, 2024
Comment on lines +103 to +114
// format of a bind group, providing resources for the compute shader
computeBindGroupFormat: new pc.BindGroupFormat(device, [
// no uniform buffer
], [
// input texture - the scene color map
new pc.BindTextureFormat('uSceneColorMap', pc.SHADERSTAGE_COMPUTE)
], [
// no storage textures
], [
// output storage buffer
new pc.BindStorageBufferFormat('outBuffer', pc.SHADERSTAGE_COMPUTE)
])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This array format seems v messy maybe replace with an object with keys to describe each array?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah good suggestion, but outside of the scope of this PR.

@mvaligursky mvaligursky requested a review from a team March 26, 2024 14:06
mvaligursky and others added 2 commits March 26, 2024 16:25
Co-authored-by: Will Eastcott <will@playcanvas.com>
Co-authored-by: Will Eastcott <will@playcanvas.com>
Copy link
Contributor

@willeastcott willeastcott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving with minor comments. Nice! 👏

Co-authored-by: Will Eastcott <will@playcanvas.com>
@mvaligursky mvaligursky merged commit 762317b into main Apr 2, 2024
7 checks passed
@mvaligursky mvaligursky deleted the mv-storage-buffer branch April 2, 2024 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants