WebGPU Example: Mapping a Buffer for Read Access

This program is meant to illustrate using a "staging buffer" to read data from a buffer on the GPU back to the JavaScript side of the program. The computation uses the trapezoid rule to approximate a definite integral, but the point is that a bunch of numbers have to be computed and then added up. When you click the "Compute" button, the numbers are computed in the GPU, then copied back to JavaScript and added up. The sum is reported at the bottom of the page. If you click "Compute With Reduce", the sum is computed more efficiently on the GPU, and only the final answer is copied back to JavaScript.

 

f(x) =

xmin =

xmax =

intervals =