Skip to content

Commit c19f7d9

Browse files
farshedgreggman
authored andcommitted
Update webgpu-storage-buffers.md
1 parent 3133d24 commit c19f7d9

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

webgpu/lessons/webgpu-storage-buffers.md

+23-23
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This article is about storage buffers and continues where the
77

88
Storage buffers are similar to uniform buffers in many ways.
99
If all we did was change `UNIFORM` to `STORAGE` in our JavaScript
10-
and `var<uniform>` to `var<storage, read>` in our WGSL the examples
10+
and `var<uniform>` to `var<storage, read>` in our WGSL, the examples
1111
on the previous page would just work.
1212

1313
In fact, here are the differences, without renaming variables to have more
@@ -39,7 +39,7 @@ and in our WSGL
3939
@group(0) @binding(1) var<storage, read> otherStruct: OtherStruct;
4040
```
4141

42-
And with no other changes it works, just like before
42+
And with no other changes it works, just like before.
4343

4444
{{{example url="../webgpu-simple-triangle-storage-split-minimal-changes.html"}}}
4545

@@ -61,19 +61,19 @@ The major differences between uniform buffers and storage buffers are:
6161
* The minimum maximum size of a uniform buffer is 64k
6262
* The minimum maximum size of a storage buffer is 128meg
6363

64-
By minimum maximum, there is a maximum size a buffer of certain type
65-
can be. For uniform buffers that maximum size is at least 64k.
66-
For storage buffers it's at least 128meg. We'll cover limits in
64+
By minimum maximum, there is a maximum size a buffer of a certain type
65+
can be. For uniform buffers, the maximum size is at least 64k.
66+
For storage buffers, it's at least 128meg. We'll cover limits in
6767
[another article](webgpu-limits-and-features.html).
6868

69-
3. Storage buffers can be read/write, Uniform buffers are read-only
69+
3. Storage buffers can be read/write, Uniform buffers are read-only.
7070

7171
We saw an example of writing to a storage buffer in the compute shader
7272
example in [the first article](webgpu-fundamentals.html).
7373

7474
## <a id="a-instancing"></a>Instancing with Storage Buffers
7575

76-
Given the first 2 points above, lets take our last example and change it
76+
Given the first 2 points above, let's take our last example and change it
7777
to draw all 100 triangles in a single draw call. This is a use-case that
7878
*might* fit storage buffers. I say might because again, WebGPU is similar
7979
to other programming languages. There are many ways to achieve the same thing.
@@ -82,9 +82,9 @@ has multiple ways we can achieve it. When it comes to drawing triangles,
8282
all that WebGPU cares about is we return a value for `builtin(position)` from
8383
the vertex shader and return a color/value for `location(0)` from the fragment shader.[^colorAttachments]
8484

85-
[^colorAttachments]: We can have multiple color attachments and then we'll need to return more colors/value for `location(1)`, `location(2)`, etc..
85+
[^colorAttachments]: We can have multiple color attachments and then we'll need to return more colors/values for `location(1)`, `location(2)`, etc...
8686

87-
The first thing we'll do is change our storage declarations to a runtime sized
87+
The first thing we'll do is change our storage declarations to runtime-sized
8888
arrays.
8989

9090
```wgsl
@@ -94,7 +94,7 @@ arrays.
9494
+@group(0) @binding(1) var<storage, read> otherStructs: array<OtherStruct>;
9595
```
9696

97-
Then we'll change the shader to use these values
97+
Then we'll change the shader to use these values.
9898

9999
```wgsl
100100
@vertex fn vs(
@@ -118,11 +118,11 @@ Then we'll change the shader to use these values
118118
We added a new parameter to our vertex shader called
119119
`instanceIndex` and gave it the `@builtin(instance_index)` attribute
120120
which means it gets its value from WebGPU for each "instance" drawn.
121-
When we call `draw` we can pass a second argument for *number of instances*
121+
When we call `draw`, we can pass a second argument for *number of instances*
122122
and for each instance drawn, the number of the instance being processed
123123
will be passed to our function.
124124

125-
Using `instanceIndex` we can get specific struct elements from our arrays
125+
Using `instanceIndex`, we can get specific struct elements from our arrays
126126
of structs.
127127

128128
We also need to get the color from the correct array element and use
@@ -133,7 +133,7 @@ would be more common to look up the color in the vertex shader and just pass
133133
the color.
134134

135135
To do this we'll use another struct like we did in
136-
[the article on inter-stage variables](webgpu-inter-stage-variables.html)
136+
[the article on inter-stage variables](webgpu-inter-stage-variables.html).
137137

138138
```wgsl
139139
+struct VSOutput {
@@ -174,7 +174,7 @@ To do this we'll use another struct like we did in
174174

175175
Now that we've modified our WGSL shaders, let's update the JavaScript.
176176

177-
Here's the setup
177+
Here's the setup.
178178

179179
```js
180180
const kNumObjects = 100;
@@ -296,11 +296,11 @@ and `instance_index` set to 0 ~ kNumObjects - 1
296296

297297
We managed to draw all 100 triangles, each with a different scale, color, and
298298
offset, with a single draw call. For situations where you want to draw lots
299-
of instances of the same object this is one way to do it.
299+
of instances of the same object, this is one way to do it.
300300

301301
## Using storage buffers for vertex data
302302

303-
Until this point we've used a hard coded triangle directly in our shader.
303+
Until this point, we've used a hard-coded triangle directly in our shader.
304304
One use case of storage buffers is to store vertex data. Just like we indexed
305305
the current storage buffers by `instance_index` in our example above, we could
306306
index another storage buffer with `vertex_index` to get vertex data.
@@ -356,8 +356,8 @@ struct VSOutput {
356356
}
357357
```
358358

359-
Now we need to setup one more storage buffer with some vertex data.
360-
First lets make a function to generate some vertex data. Lets make a circle.
359+
Now we need to set up one more storage buffer with some vertex data.
360+
First, let's make a function to generate some vertex data. Let's make a circle.
361361
<a id="a-create-circle"></a>
362362

363363
```js
@@ -411,11 +411,11 @@ function createCircleVertices({
411411
}
412412
```
413413

414-
The code above makes a circle from triangles like this
414+
The code above makes a circle from triangles like this.
415415

416416
<div class="webgpu_center"><div class="center"><div data-diagram="circle" style="width: 300px;"></div></div></div>
417417

418-
So we can use that to fill a storage buffer with the vertices for a circle
418+
So we can use that to fill a storage buffer with the vertices for a circle.
419419

420420
```js
421421
// setup a storage buffer with vertex data
@@ -445,7 +445,7 @@ And then we need to add it to our bind group.
445445
});
446446
```
447447

448-
and finally at render time we need to ask to render all the vertices in the circle.
448+
and finally, at render time, we need to ask to render all the vertices in the circle.
449449

450450
```js
451451
- pass.draw(3, kNumObjects); // call our vertex shader 3 times for several instances
@@ -470,11 +470,11 @@ we could have just as easily used no struct and just directly used a `vec2f`.
470470
@group(0) @binding(2) var<storage, read> pos: vec2f;
471471
```
472472

473-
But, by making it a struct it would arguably be easier to add per-vertex
473+
But, by making it a struct, it would arguably be easier to add per-vertex
474474
data later?
475475

476476
Passing in vertices via storage buffers is gaining popularity.
477-
I'm told though that some older devices it's slower than the *classic* way
477+
I'm told though that for some older devices, it's slower than the *classic* way
478478
which we'll cover next in an article on [vertex buffers](webgpu-vertex-buffers.html).
479479

480480
<!-- keep this at the bottom of the article -->

0 commit comments

Comments
 (0)