home/ atoms/ webgpu-draw-call

A WebGPU draw call requires setPipeline, setVertexBuffer, and draw called in sequence on a render pass encoder

To draw geometry in WebGPU inside a render pass: (1) pass.setPipeline(pipeline) to set the active render pipeline; (2) pass.setVertexBuffer(slot, buffer) for each vertex buffer; (3) optionally pass.setBindGroup(groupIndex, bindGroup) for uniforms/storage; (4) pass.draw(vertexCount, instanceCount). The draw() call’s vertexCount is the number of vertices (e.g., 6 for a quad); instanceCount defaults to 1. Nothing is drawn until submit() is called on the command buffer.

Examples

pass.setPipeline(cellPipeline);
pass.setVertexBuffer(0, vertexBuffer);
pass.setBindGroup(0, bindGroup);
pass.draw(vertices.length / 2, GRID_SIZE * GRID_SIZE);

Assessment

In what order must setPipeline, setVertexBuffer, and draw be called? What is the second argument to draw() used for?

“pass.setPipeline(cellPipeline); pass.setVertexBuffer(0, vertexBuffer); pass.draw(vertices.length / 2); // 6 vertices”
corpus · your-first-webgpu-app-google-codelab · chunk 9