Skip to content

Use EGL Sync Objects to ensure that shared WebGL textures are ready to be used - #1407

Merged
bors-servo merged 1 commit into
servo:masterfrom
MortimerGoro:glsync
Jul 5, 2017
Merged

bors-servo merged 1 commit into
servo:masterfrom
MortimerGoro:glsync

Conversation

@MortimerGoro

@MortimerGoro MortimerGoro commented Jun 20, 2017 •

Copy link
Copy Markdown
Contributor

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 Reviewable

Comment thread webrender/src/render_backend.rs Outdated
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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't be calling any GL functions directly from render_backend

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean that they should be called using WebGLCommand enum? (as it was done with the existing glFlush call)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose, yes. Just don't assume there is GL under the hood.

Comment thread webrender/src/render_backend.rs Outdated
// 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) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be if self.dirty_webgl_context.remove(&id) {..}

@glennw

glennw commented Jun 20, 2017

Copy link
Copy Markdown
Member

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...

@MortimerGoro

MortimerGoro commented Jun 20, 2017 •

Copy link
Copy Markdown
Contributor Author

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?

@glennw

glennw commented Jun 20, 2017

Copy link
Copy Markdown
Member

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!

@bors-servo

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #1409) made this pull request unmergeable. Please resolve the merge conflicts.

@glennw

glennw commented Jul 5, 2017

Copy link
Copy Markdown
Member

@MortimerGoro This needs a rebase.

@MortimerGoro

Copy link
Copy Markdown
Contributor Author

Done!

@glennw glennw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question, otherwise looks good.

Comment thread webrender_api/src/webgl.rs Outdated
// 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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, glWaitSync is enough. Just tried and it works ok.

@glennw

glennw commented Jul 5, 2017

Copy link
Copy Markdown
Member

Looks good, thanks!

@bors-servo r+

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit 969a0d6 has been approved by glennw

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit 969a0d6 with merge 0fc57c6...

bors-servo pushed a commit that referenced this pull request Jul 5, 2017
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 -->
@bors-servo

Copy link
Copy Markdown
Contributor

☀️ Test successful - status-travis
Approved by: glennw
Pushing 0fc57c6 to master...

@bors-servo
bors-servo merged commit 969a0d6 into servo:master Jul 5, 2017
mrobinson added a commit to mrobinson/webrender that referenced this pull request Jul 12, 2017
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.
@mrobinson

Copy link
Copy Markdown
Member

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!

#1471

@MortimerGoro

MortimerGoro commented Jul 12, 2017 •

Copy link
Copy Markdown
Contributor Author

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.

bors-servo pushed a commit that referenced this pull request Jul 12, 2017
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 -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants