WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED WONTFIX
199142
[WHLSL] Compiles should be asynchronous
https://bugs.webkit.org/show_bug.cgi?id=199142
Summary
[WHLSL] Compiles should be asynchronous
Myles C. Maxfield
Reported
2019-06-23 22:02:09 PDT
Eventually, all of WebGPU should be asynchronous, but until we can get there, we can make shader compiles asynchronous. This involves two pieces: making the WHLSL compiler execute on another thread, and making the Metal shader compiler execute on another thread. Because the MSL shader compiler involves the MTLDevice, and I don't think MTLDevices are thread safe, we probably have to start that compilation from the main thread. We can't wrap all accesses to the MTLDevice in a mutex because we can't wrap CAMetalLayer's internal uses of the MTLDevice. Therefore, the flow probably has to work like this: 1. Kick off an asynchronous task to run the WHLSL compiler 2. When the WHLSL compiler is done, kick off a task back to the main loop to start the Metal shader compiler 3. From the main thread, use the asynchronous flavor of the Metal shader compiler. 4. In the completion callback, kick off another task back to the main thread to mark the compile as completed. setPipeline() requires knowing the results of this compilation. However, it can't simply block on the results of the asynchronous operation, because that would cause a deadlock if it occurs during step 2 above. (The main thread can't start the MSL compiler because it's being blocked by setPipeline() waiting on the results of the MSL compiler.) Instead, the internals of setPipeline() will probably have to see whether we're in step 2 or step 4, and if we're in step 2, block until the WHLSL compiler is complete, and then synchronously invoke the Metal compiler. Then, when step 3 executes, it should detect that the MSL compiler has already been invoked, and return early. We can do something similar for step 4.
Attachments
Use the asynchronous flavor of the MSL compiler
(7.02 KB, patch)
2019-06-23 22:03 PDT
,
Myles C. Maxfield
no flags
Details
Formatted Diff
Diff
Wrap each use of MTLDevice in a mutex
(31.34 KB, patch)
2019-06-23 22:04 PDT
,
Myles C. Maxfield
no flags
Details
Formatted Diff
Diff
View All
Add attachment
proposed patch, testcase, etc.
Myles C. Maxfield
Comment 1
2019-06-23 22:03:40 PDT
Created
attachment 372730
[details]
Use the asynchronous flavor of the MSL compiler
Myles C. Maxfield
Comment 2
2019-06-23 22:04:15 PDT
Created
attachment 372731
[details]
Wrap each use of MTLDevice in a mutex
Myles C. Maxfield
Comment 3
2019-06-23 22:09:26 PDT
Making the WHLSL compiler asynchronous is important if we want to move the standard library to a standalone file in WebCore's bundle. We don't want to do synchronous IO on the main thread, so doing it on another thread is important. Because we can block the main thread on the results of this asynchronous IO, this isn't a full solution, but having an asynchronous compile makes it at least possible to not block. Eventually, a better solution would be to move the entire WebGPU implementation to another thread (sort of like a GPU process architecture, except executing in a thread instead of a process).
Myles C. Maxfield
Comment 4
2020-05-05 00:42:36 PDT
WHLSL is no longer relevant.
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug