From 468d5babc7f624da9ef768321706d93b0c886476 Mon Sep 17 00:00:00 2001 From: shallow-beach <96891913+shallow-beach@users.noreply.github.com> Date: Thu, 22 Aug 2024 11:42:01 -0700 Subject: [PATCH] Update webgpu-vertex-buffers.md (#154) * Update webgpu-vertex-buffers.md - c/e - little more on typed arrays (particularly views) + MDN ref - highlight first explicit use of `attributes` in webgpufundamentals * Update webgpu-vertex-buffers.md clarify language * Update webgpu-vertex-buffers.md code style * Update webgpu-vertex-buffers.md use anchor * Update webgpu-vertex-buffers.md rm beginner's emphasis on views * Update webgpu-vertex-buffers.md reminder lk to explanatory article --- webgpu/lessons/webgpu-vertex-buffers.md | 75 +++++++++++++------------ 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/webgpu/lessons/webgpu-vertex-buffers.md b/webgpu/lessons/webgpu-vertex-buffers.md index d06366f7..6213fcd5 100644 --- a/webgpu/lessons/webgpu-vertex-buffers.md +++ b/webgpu/lessons/webgpu-vertex-buffers.md @@ -64,10 +64,10 @@ struct VSOutput { ``` As you can see, it's a small change. The important part is declaring the -position field with `@location(0)` +position field with `@location(0)`. -Then, when we create the render pipeline, we have to tell WebGPU how to get data -for `@location(0)` +Next, we have to tell WebGPU how to get data for `@location(0)` - +for that, we use the render pipeline: ```js const pipeline = device.createRenderPipeline({ @@ -93,7 +93,7 @@ for `@location(0)` To the [`vertex`](GPUVertexState) entry of the [`pipeline` descriptor](GPURenderPipelineDescriptor) we added a `buffers` array which is used to describe how to pull data out of 1 or more vertex buffers. -For our first and only buffer, we set an `arrayStride` in number of bytes. a *stride* in this case is +For our first and only buffer, we set an `arrayStride` in number of bytes. A *stride* in this case is how many bytes to get from the data for one vertex in the buffer, to the next vertex in the buffer.
@@ -101,11 +101,13 @@ how many bytes to get from the data for one vertex in the buffer, to the next ve Since our data is `vec2f`, which is two float32 numbers, we set the `arrayStride` to 8. -Next we define an array of attributes. We only have one. `shaderLocation: 0` +Next we define an array of attributes. We only have one: `shaderLocation: 0` corresponds to `location(0)` in our `Vertex` struct. `offset: 0` says the data for this attribute starts at byte 0 in the vertex buffer. Finally `format: 'float32x2'` says we want WebGPU to pull the data out of the buffer as two 32bit -floating point numbers. +floating point numbers. Note the `attributes` property is the same entity pictured in the +[simplified draw diagram](webgpu-fundamentals.html#a-draw-diagram) +from the first article. We need to change the usages of the buffer holding vertex data from `STORAGE` to `VERTEX` and remove it from the bind group. @@ -134,8 +136,7 @@ to `VERTEX` and remove it from the bind group. }); ``` -And then at draw time we need to tell WebGPU which vertex buffer to -use +Then, at draw time we need to tell WebGPU which vertex buffer to use: ```js pass.setPipeline(pipeline); @@ -145,16 +146,16 @@ use The `0` here corresponds to first element of the render pipeline `buffers` array we specified above. -And with that we've switched from using a storage buffer for vertices to a +With that, we've switched from using a storage buffer for vertices to a vertex buffer. {{{example url="../webgpu-vertex-buffers.html"}}} -The state when the draw command is executed would look something like this +The state when the draw command is executed would look something like this:
-The attribute `format` field can be one of these types +The attribute `format` field can be one of these types: