Repository navigation
Use EGL Sync Objects to ensure that shared WebGL textures are ready to be used - #1407
Conversation
| if self.dirty_webgl_contexts.contains(&id) { | ||
| webgl_context.make_current(); | ||
| // Call FenceSync and ClientWaitSync to ensure that textures are ready. | ||
| let sync = webgl_context.gl().fence_sync(gl::SYNC_GPU_COMMANDS_COMPLETE, 0); |
There was a problem hiding this comment.
we shouldn't be calling any GL functions directly from render_backend
There was a problem hiding this comment.
Do you mean that they should be called using WebGLCommand enum? (as it was done with the existing glFlush call)
There was a problem hiding this comment.
I suppose, yes. Just don't assume there is GL under the hood.
| // Sync objects are the recommended way to ensure that textures are ready in OpenGL 3.0+. | ||
| // They are more performant than glFinish and guarantee the completion of the GL commands. | ||
| for (id, webgl_context) in &self.webgl_contexts { | ||
| if self.dirty_webgl_contexts.contains(&id) { |
There was a problem hiding this comment.
could be if self.dirty_webgl_context.remove(&id) {..}
|
glClientWaitSync is only available on desktop GL 3.2+, I believe. Although we currently do require 3.2, we're meant to be dropping required desktop GL to 3.1... |
Yes, glClientWaitSync is available in GL 3.2+ and GL ES 3.0+. We could check if GL_ARB_sync extension is available in GL 3.1 and fallback to glFlush/glFinish if not. Do you want to do that in this PR or create an issue or handle this in the future WebGL separate crate? |
|
That's fine to do it as a follow up, so long as we have a valid fallback plan (which it sounds like we do). Thanks! |
|
☔ The latest upstream changes (presumably #1409) made this pull request unmergeable. Please resolve the merge conflicts. |
|
@MortimerGoro This needs a rebase. |
|
Done! |
glennw
left a comment
There was a problem hiding this comment.
One question, otherwise looks good.
| // Call FenceSync and ClientWaitSync to ensure that textures are ready. | ||
| let sync = gl.fence_sync(gl::SYNC_GPU_COMMANDS_COMPLETE, 0); | ||
| // SYNC_FLUSH_COMMANDS_BIT is used to automatically generate a glFlush before blocking on the sync object. | ||
| gl.client_wait_sync(sync, gl::SYNC_FLUSH_COMMANDS_BIT, gl::TIMEOUT_IGNORED); |
There was a problem hiding this comment.
Why does this need to be a glClientWaitSync ? Wouldn't a glWaitSync be more appropriate in this case, so that the CPU isn't blocked? I would have though a glWaitSync would be enough to sync between the two command streams?
There was a problem hiding this comment.
Yes, glWaitSync is enough. Just tried and it works ok.
|
Looks good, thanks! @bors-servo r+ |
|
📌 Commit 969a0d6 has been approved by |
Use EGL Sync Objects to ensure that shared WebGL textures are ready to be used Currently a glFlush call is issued at the start of the frame to guarantee that shared WebGL texture data is valid. But glFlush is not enough in some GPUs because it doesn't guarantee the completion of the GL commands when the shared texture is sampled. This leads to some graphic glitches on some demos or even nothing being rendered at all (GPU Mali-T880). glFinish guarantees the completion of the commands but it may hurt performance a lot. Sync objects are the recommended way to ensure that textures are ready in OpenGL 3.0+. They are more performant than glFinish and guarantee the completion of the GL commands. I added dirty checking so the sync is only performed when WebGL contexts are being used. This PR might be improved if we move the glClientWaitSync to the WR render thread (before the shared texture is used). The parallelism should be better that way. I don know where is the best place to add the sync wait in WR. If you can guide me on that I'll update the PR. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/1407) <!-- Reviewable:end -->
|
☀️ Test successful - status-travis |
This change caused many WebGL tests to fail in Servo, which is blocking the WebRender update. Partially revert the change in order to reland it later with the issue properly fixed.
|
This change is causing many Servo WebGL tests to fail, so I posted a PR to partially revert this (temporarily) in order to move the WebRender update forward. Sorry! |
|
Ok, no problem. I'm working on #1353 so the WebGL code will be refactored to a new component. I'll check all the WebGL tests after the refactor. |
Partially revert #1407 This change caused many WebGL tests to fail in Servo, which is blocking the WebRender update. Partially revert the change in order to reland it later with the issue properly fixed. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/1471) <!-- Reviewable:end -->
Currently a glFlush call is issued at the start of the frame to guarantee that shared WebGL texture data is valid. But glFlush is not enough in some GPUs because it doesn't guarantee the completion of the GL commands when the shared texture is sampled. This leads to some graphic glitches on some demos or even nothing being rendered at all (GPU Mali-T880). glFinish guarantees the completion of the commands but it may hurt performance a lot.
Sync objects are the recommended way to ensure that textures are ready in OpenGL 3.0+. They are more performant than glFinish and guarantee the completion of the GL commands.
I added dirty checking so the sync is only performed when WebGL contexts are being used. This PR might be improved if we move the glClientWaitSync to the WR render thread (before the shared texture is used). The parallelism should be better that way. I don know where is the best place to add the sync wait in WR. If you can guide me on that I'll update the PR.
This change is