Skip to content

Commit 7e641c2

Browse files
committed
wip
1 parent 77587fd commit 7e641c2

File tree

4 files changed

+573
-5
lines changed

4 files changed

+573
-5
lines changed

toc.hanson

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@
5858
'webgpu-resizing-the-canvas.md',
5959
'webgpu-multiple-canvases.md',
6060
'webgpu-points.md',
61-
'webgpu-from-webgl.md',
61+
'webgpu-from-webgl.md'
62+
'webgpu-optimization.md',
6263
'webgpu-resources.md',
6364
'webgpu-wgsl-function-reference.md',
6465
'webgpu-wgsl-offset-computer.md',

webgpu/lessons/webgpu-from-webgl.md

+11-4
Original file line numberDiff line numberDiff line change
@@ -1366,9 +1366,8 @@ WebGPU
13661366

13671367
{{{example url="../webgpu-cube-multiple.html"}}}
13681368

1369-
The important part to take away is that unlike WebGL, you'll need unique uniform buffers for
1370-
any uniforms that are object specific (like a world matrix), and, because of that you also
1371-
need a unique bind group per object.
1369+
The important part to take away is that unlike WebGL, you'll need uniform buffers for
1370+
any uniforms that are object specific (like a world matrix), and, because of that you also may need a unique bind group per object.
13721371

13731372
## Other random differences
13741373

@@ -1387,7 +1386,7 @@ corner in both WebGL and WebGPU. On the other hand, setting the viewport or scis
13871386
### WGSL uses `@builtin(???)` for GLSL's `gl_XXX` variables.
13881387

13891388
`gl_FragCoord` is `@builtin(position) myVarOrField: vec4f` and unlike
1390-
WebGL goes down the screen instead of up so 0,0 is the top left vs WebGL where 0,0 is the bottom left.
1389+
WebGL, goes down the screen instead of up so 0,0 is the top left vs WebGL where 0,0 is the bottom left.
13911390

13921391
`gl_VertexID` is `@builtin(vertex_index) myVarOrField: u32`
13931392

@@ -1410,6 +1409,14 @@ different GPU would clip or not clip based on the center of the point. So, it's
14101409
a good thing WebGPU doesn't support points of sizes other than 1.
14111410
This forces you to implement a portable point solution.
14121411

1412+
### WebGPU optimizations are different than WebGL
1413+
1414+
If you take a WebGL app and directly convert it to WebGPU you might find
1415+
it runs slower. To get the benefits of WebGPU you'll need to change the
1416+
way you organize and optimize how you draw.
1417+
See [this article on WebGPU optimization](webgpu-optimization.html) for
1418+
ideas.
1419+
14131420
---
14141421

14151422
If you were already familiar with WebGL then I hope this article was useful.

webgpu/lessons/webgpu-optimizating.md

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
Title: WebGPU Speed and Optimization
2+
Description: How to go faster in WebGPU
3+
TOC: Speed and Optimization
4+
5+
Most of the examples on this site are written to be as understandable
6+
as possible. That means they work, and they're correct, but they don't
7+
necessarily show the most efficient way to do something in WebGPU.
8+
Further, depending on what you need to do, there are a myriad of possible
9+
optimizations.
10+
11+
In this article will cover some of the most basic optimizations and
12+
discuss a few others.
13+
14+
The basics: The less work you do, and the less work you ask WebGPU to do
15+
the faster things will go.
16+
17+
In pretty much all of the examples to date, if we draw multiple shapes
18+
we've done the following steps
19+
20+
```
21+
* At Init time:
22+
* for each thing we want to draw
23+
* create a uniform buffer
24+
* create a bindGroup that references that buffer
25+
26+
* At Render time:
27+
* for each thing we want to draw
28+
* update a typed array with our uniform values for this object
29+
* copy the typed array to the uniform buffer for this object
30+
* bind the bindGroup for this object
31+
* draw
32+
```
33+
34+
35+
36+
Let's make an example we can optimize
37+
38+
* Pack your vertices
39+
* Use mappedOnCreation for initial data
40+
* Split uniform buffer (shared, material, per model)
41+
42+
* Texture Atlas or 2D-array
43+
* GPU Occlusion culling
44+
* GPU Scene graph matrix calculation
45+
* GPU Frustum culling
46+
* Indirect Drawing
47+
* Render Bundles

0 commit comments

Comments
 (0)