Repository navigation
Commit 0d02086
feat(⚡️): keep Dawn's compiled pipelines across launches (#594)
* feat(⚡️): keep Dawn's compiled pipelines across launches
* fix(⚡️): leave a cache write another process may still finish, and recreate a cleared cache directory
* chore(🐙): unit test the Dawn blob cache on the host
* chore(🐙): use POSIX calls in the blob cache test, as cpplint asks
* chore(📚): say what the pipeline cache keeps on each backend, and when its size is checked
* fix(⚡️): recreate the cache directory's parents, and keep the cache off when the JVM can't copy its path
* chore(🐙): test the cache's parent directories, and require the CMake its options need
* fix(⚡️): clear only the cache's own files, stay off without a usable directory, and let a failed JNI copy throw
* chore(🐙): test that the cache leaves other files alone and stays off without a directory
* fix(⚡️): trim the oldest cache entries to fit the limit, and check it as a session stores
* chore(🐙): test that the cache is trimmed rather than cleared, at setup and while storing
* fix(⚡️): keep one entry from taking the cache, and count replacements as no growth
An entry larger than half the limit is not stored, so one blob cannot take more
than half the cache from the others. A replacement counts only the bytes it
adds towards the next tidy, and the counter is reset with a compare-exchange so
growth that lands during a reset is kept. Tidy checks the inode as well as the
time and size before removing a file, so it does not remove one a store has
just replaced. The statics a flush on another thread may still use at exit are
never destroyed, and chain() says whether it chained the cache.
* fix(⚡️): persist Dawn's monolithic Vulkan pipeline cache
With vulkan_monolithic_pipeline_cache Dawn writes its one VkPipelineCache to the
blob cache only inside PerformIdleTasks(), which nothing called, so on Android
the Vulkan pipeline data never reached the disk. An IdleFlusher now calls it
about a second after the last pipeline was created (about ten seconds into a
long run of creations) and once on device.destroy(), for devices that have the
blob cache, run on Vulkan, and have the toggle applied. A device without
implicit synchronization is flushed only on destroy(). Cancelled on device
loss, and never waited for when the device is released, since that can happen
inside a Dawn callback. Messages Dawn logs during a flush stay native.
* chore(📚): say when the pipeline cache is written and how its size is kept
* refactor(⚡️): write blob cache entries on a thread of their own, and clear a cache past its limit
Dawn stores from the thread that compiles, a JS thread included, and holds
the device's lock while it stores its pipeline cache. A store now copies the
bytes and returns; one writer thread does the disk work, in order.
Tidying runs on that thread too, and is simpler: a cache found past 64 MB at
setup is cleared, since which of its entries the app still uses cannot be
told, and a session that would take the cache past the limit stops adding to
it (a replacement no larger than the entry it replaces is never dropped).
Only names shaped exactly like the cache's own are counted or removed.
* refactor(⚡️): flush the Vulkan pipeline cache on destroy and when the app pauses
Dawn writes its monolithic Vulkan pipeline cache only when the embedder says
the device is idle. Rather than guess at idleness with a thread of our own
(IdleFlusher), use the moments the platform gives: device.destroy(), and the
app going to the background, which Android reports through onHostPause. Each
device flushes on the thread of the runtime it was created on, so Dawn's
callbacks keep running where they always did. There is nothing to flush on
Metal, where Dawn stores its blobs as it compiles.
* fix(⚡️): flush the Vulkan pipeline cache every ten seconds, from any runtime, and never for an imported device
An app killed in the foreground lost every pipeline built since launch:
nothing flushed between onHostPause and destroy. GPUQueue::submit now asks
its device to flush when ten seconds have passed since the last one. That
is cheap: Dawn only serializes when a pipeline compiled since, and skips the
store when the cache's size did not change.
The pause flush posted to each device's runtime, but a worklet runtime of
the Mailbox kind delivers a post only with its next operation, so a device
created there never flushed. Devices with ImplicitDeviceSynchronization,
the default, now flush on the calling thread; PerformIdleTasks takes the
device's lock itself. Only devices without it are posted to their runtime.
A device from importDevice() belongs to someone else: it keeps its origin
and is never flushed, on destroy included.
* fix(⚡️): keep the writer thread alive through a failing store, and measure the cache again before dropping one
A job that threw took the writer thread down with it, and when no thread
could be started the jobs ran inline on Dawn's thread, under the device's
lock. Jobs now run under try/catch, and are dropped without a thread.
The byte count the writer keeps went stale when the OS purged the files but
kept the directory, so stores were dropped from an empty cache. A store that
would be dropped measures the directory first. Replacements no larger than
the entry they replace stay exempt, as the header promises.
Temporary names match exactly the one shape the cache writes; the test
pins the older `<hash>.<pid>.<seq>.tmp` shape as a file the cache leaves
alone. The test helpers that create and age files return whether they
did, and every call asserts it.
* chore(🐙): run the C++ unit tests in a job of their own, with the googletest download cached
The tests ran inside the Android build job, where a failure read as an
Android failure and a cold googletest fetch added to the slowest job. They
now run on ubuntu in under a minute, and actions/cache keeps the FetchContent
checkout under node_modules/.cache/cpp-tests/_deps, keyed on the CMake file.
* fix(⚡️): serialize the pipeline cache off the frame thread, hold no device wrapper on the UI thread, and measure the cache again only when it changed
The periodic flush of a device that synchronizes itself goes to the blob
cache's thread (DawnBlobCache::post), holding the device by its Dawn handle
and a shared flag rather than its wrapper, which must only go on its
runtime's thread. flushPipelineCaches() copies what it needs out of each
wrapper under the registry's mutex (the registry now holds plain pointers and
asks weak_from_this()), so the pause-time flush never takes a strong reference
on the UI thread. A store the cache refuses as too large is counted on the
calling thread, and a flush that sees the count move marks the device's
pipeline cache as outgrown and stops having Dawn serialize it.
In the cache, the directory is published before its tidying is posted, and a
store finding its directory untidied (the tidying dropped for want of a
thread, or the store bound for another directory) tidies it first. Before a
store is dropped the directory is measured again only when its modification
time changed since the last measure, or that measure is ten seconds old.
Also: GPUQueue's members in initializer order, the docs on when the Vulkan
cache data is written (a submit ten seconds after the last write), and the
googletest cache in CI limited to the download and its sub-build.
---------
Co-authored-by: William Candillon <wcandillon@gmail.com>1 parent 939a94c commit 0d02086
18 files changed
Lines changed: 1497 additions & 23 deletions
File tree
- .github/workflows
- apps/docs/content/docs/getting-started
- packages/webgpu
- android
- cpp
- src/main/java/com/webgpu
- apple
- cpp/rnwgpu
- api
- tests/cpp
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
310 | 310 | | |
311 | 311 | | |
312 | 312 | | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
313 | 345 | | |
314 | 346 | | |
315 | 347 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
105 | 121 | | |
106 | 122 | | |
107 | 123 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| 58 | + | |
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
| 26 | + | |
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
| |||
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
34 | | - | |
| 36 | + | |
35 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
36 | 48 | | |
37 | 49 | | |
38 | 50 | | |
| |||
45 | 57 | | |
46 | 58 | | |
47 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
48 | 70 | | |
49 | 71 | | |
50 | 72 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| 18 | + | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
| |||
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
29 | | - | |
| 31 | + | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
| |||
35 | 37 | | |
36 | 38 | | |
37 | 39 | | |
| 40 | + | |
38 | 41 | | |
39 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
40 | 68 | | |
41 | 69 | | |
42 | 70 | | |
| |||
47 | 75 | | |
48 | 76 | | |
49 | 77 | | |
50 | | - | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
51 | 82 | | |
52 | 83 | | |
53 | 84 | | |
54 | 85 | | |
55 | 86 | | |
56 | | - | |
| 87 | + | |
57 | 88 | | |
58 | 89 | | |
59 | 90 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
109 | 110 | | |
110 | 111 | | |
111 | 112 | | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
112 | 127 | | |
113 | 128 | | |
114 | 129 | | |
| |||
0 commit comments