-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support running WebGL in its own thread or on the main thread. #23777
Conversation
@bors-servo try=wpt |
Support running WebGL in its own thread or on the main thread. This is the final missing piece to support WebGL in ANGLE on Windows. ANGLE doesn't support multiple GL contexts on separate threads using the same underlying Direct3d device, so we need to process all GL operations for WebGL on the same thread as the compositor. These changes try to retain enough flexibility to support both approaches so we can get WebGL working on Windows ASAP. --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #23697 - [x] There are tests for these changes <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23777) <!-- Reviewable:end -->
One missing piece - I totally stubbed out the main-thread support for dom2texture in OutputHandler. |
💔 Test failed - linux-rel-wpt |
c97999d
to
f069ede
Compare
@bors-servo try=wpt |
Support running WebGL in its own thread or on the main thread. This is the final missing piece to support WebGL in ANGLE on Windows. ANGLE doesn't support multiple GL contexts on separate threads using the same underlying Direct3d device, so we need to process all GL operations for WebGL on the same thread as the compositor. These changes try to retain enough flexibility to support both approaches so we can get WebGL working on Windows ASAP. --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #23697 - [x] There are tests for these changes <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23777) <!-- Reviewable:end -->
💔 Test failed - linux-rel-css |
With the off thread tests, lots of gl errors like:
With the main thread tests, lots of gl errors like:
|
@bors-servo try=wpt |
Support running WebGL in its own thread or on the main thread. This is the final missing piece to support WebGL in ANGLE on Windows. ANGLE doesn't support multiple GL contexts on separate threads using the same underlying Direct3d device, so we need to process all GL operations for WebGL on the same thread as the compositor. These changes try to retain enough flexibility to support both approaches so we can get WebGL working on Windows ASAP. --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #23697 - [x] There are tests for these changes <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23777) <!-- Reviewable:end -->
💔 Test failed - linux-rel-css |
@bors-servo try=wpt |
Would you like me to review this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sigh, this is adding yet more complexity to the main event loop, but there's not much we can do about that. My main concern is the extra thread that's being spawned, that wakes the main event loop up for each GL command. That's a lot of context switching and message forwarding!
Also, doesn't the WebGL thread keep track of the current GL context? Isn't it going to be rather surprised if the current GL context isn't the one it expects?
components/canvas/webgl_thread.rs
Outdated
// Interpose a new channel in between the existing WebGL channel endpoints. | ||
// This will bounce all WebGL messages through a second thread adding a small | ||
// delay, but this will also ensure that the main thread will wake up and | ||
// process the WebGL message when it arrives. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh that's annoying. It introduces yet another thread, which is context switched in for every GL command, plus it calls the event loop waker on every GL command. This seems quite expensive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we not move this logic into webgl, so the event loop waker is only used on commands like gl.finish()
? (Similar to how the canvas is dirtied at the moment).
@@ -71,6 +71,13 @@ where | |||
WebGLReceiver::Mpsc(ref receiver) => receiver.recv().map_err(|_| ()), | |||
} | |||
} | |||
|
|||
pub fn try_recv(&self) -> Result<T, ()> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This version of try_recv
doesn't distinguish between failure due to no message being present, and failure due to the channel being closed. Annoying, but possibly inevitable, unless there's some secret ipc-fu.
@asajeffrey Done! I tested all four permutations of ipc/main-thread and everything works. I need to rebase to pick up the clone->clone_box changes, but this is ready for review. |
Okay, this looks good. The only thing I think I'd do differently is make the event loop waker non-optional. At this point you can r=me. |
@bors-servo r=asajeffrey |
📌 Commit a2ca3dd has been approved by |
Support running WebGL in its own thread or on the main thread. This is the final missing piece to support WebGL in ANGLE on Windows. ANGLE doesn't support multiple GL contexts on separate threads using the same underlying Direct3d device, so we need to process all GL operations for WebGL on the same thread as the compositor. These changes try to retain enough flexibility to support both approaches so we can get WebGL working on Windows ASAP. --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #23697 - [x] There are tests for these changes <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23777) <!-- Reviewable:end -->
💔 Test failed - linux-rel-wpt |
|
Support running WebGL in its own thread or on the main thread. This is the final missing piece to support WebGL in ANGLE on Windows. ANGLE doesn't support multiple GL contexts on separate threads using the same underlying Direct3d device, so we need to process all GL operations for WebGL on the same thread as the compositor. These changes try to retain enough flexibility to support both approaches so we can get WebGL working on Windows ASAP. --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #23697 - [x] There are tests for these changes <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23777) <!-- Reviewable:end -->
☀️ Test successful - linux-rel-css, linux-rel-wpt, status-taskcluster |
This is the final missing piece to support WebGL in ANGLE on Windows. ANGLE doesn't support multiple GL contexts on separate threads using the same underlying Direct3d device, so we need to process all GL operations for WebGL on the same thread as the compositor. These changes try to retain enough flexibility to support both approaches so we can get WebGL working on Windows ASAP.
./mach build -d
does not report any errors./mach test-tidy
does not report any errorsThis change is