зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1565668 - Add back-pressure to WebRender+OGL by implementing RenderCompositorOGL::WaitForGPU(). r=sotaro
Without CoreAnimation, back-pressure was applied by SwapBuffers: On a double-buffered NSOpenGLContext which is bound to an NSView, [context flushBuffer] waits for the previous frame to be finished. With CoreAnimation, the context is no longer bound to an NSView, and SwapBuffers acts as a regular glFlush. glFlush on its own does not prevent overproduction. If we submit GPU work at a faster rate than the GPU can handle, we end up delaying the window server's GPU work. This can cause the window server to skip frames. So even if Gecko can produce frames at 60FPS, the window server might only present those frames at 30FPS, skipping every second frame. Differential Revision: https://phabricator.services.mozilla.com/D26412 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
4cb29aef1d
Коммит
daf06d791b
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "GLContext.h"
|
||||
#include "GLContextProvider.h"
|
||||
#include "mozilla/StaticPrefs.h"
|
||||
#include "mozilla/widget/CompositorWidget.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
@ -29,11 +30,30 @@ UniquePtr<RenderCompositor> RenderCompositorOGL::Create(
|
|||
|
||||
RenderCompositorOGL::RenderCompositorOGL(
|
||||
RefPtr<gl::GLContext>&& aGL, RefPtr<widget::CompositorWidget>&& aWidget)
|
||||
: RenderCompositor(std::move(aWidget)), mGL(aGL) {
|
||||
: RenderCompositor(std::move(aWidget)),
|
||||
mGL(aGL),
|
||||
mPreviousFrameDoneSync(nullptr),
|
||||
mThisFrameDoneSync(nullptr) {
|
||||
MOZ_ASSERT(mGL);
|
||||
}
|
||||
|
||||
RenderCompositorOGL::~RenderCompositorOGL() {}
|
||||
RenderCompositorOGL::~RenderCompositorOGL() {
|
||||
if (!mGL->MakeCurrent()) {
|
||||
gfxCriticalNote
|
||||
<< "Failed to make render context current during destroying.";
|
||||
// Leak resources!
|
||||
mPreviousFrameDoneSync = nullptr;
|
||||
mThisFrameDoneSync = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
if (mPreviousFrameDoneSync) {
|
||||
mGL->fDeleteSync(mPreviousFrameDoneSync);
|
||||
}
|
||||
if (mThisFrameDoneSync) {
|
||||
mGL->fDeleteSync(mThisFrameDoneSync);
|
||||
}
|
||||
}
|
||||
|
||||
bool RenderCompositorOGL::BeginFrame() {
|
||||
if (!mGL->MakeCurrent()) {
|
||||
|
@ -45,7 +65,38 @@ bool RenderCompositorOGL::BeginFrame() {
|
|||
return true;
|
||||
}
|
||||
|
||||
void RenderCompositorOGL::EndFrame() { mGL->SwapBuffers(); }
|
||||
void RenderCompositorOGL::EndFrame() {
|
||||
InsertFrameDoneSync();
|
||||
mGL->SwapBuffers();
|
||||
}
|
||||
|
||||
void RenderCompositorOGL::InsertFrameDoneSync() {
|
||||
#ifdef XP_MACOSX
|
||||
// Only do this on macOS.
|
||||
// On other platforms, SwapBuffers automatically applies back-pressure.
|
||||
if (StaticPrefs::gfx_core_animation_enabled()) {
|
||||
if (mThisFrameDoneSync) {
|
||||
mGL->fDeleteSync(mThisFrameDoneSync);
|
||||
}
|
||||
mThisFrameDoneSync =
|
||||
mGL->fFenceSync(LOCAL_GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool RenderCompositorOGL::WaitForGPU() {
|
||||
if (mPreviousFrameDoneSync) {
|
||||
AUTO_PROFILER_LABEL("Waiting for GPU to finish previous frame", GRAPHICS);
|
||||
mGL->fClientWaitSync(mPreviousFrameDoneSync,
|
||||
LOCAL_GL_SYNC_FLUSH_COMMANDS_BIT,
|
||||
LOCAL_GL_TIMEOUT_IGNORED);
|
||||
mGL->fDeleteSync(mPreviousFrameDoneSync);
|
||||
}
|
||||
mPreviousFrameDoneSync = mThisFrameDoneSync;
|
||||
mThisFrameDoneSync = nullptr;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RenderCompositorOGL::Pause() {}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ class RenderCompositorOGL : public RenderCompositor {
|
|||
|
||||
bool BeginFrame() override;
|
||||
void EndFrame() override;
|
||||
bool WaitForGPU() override;
|
||||
void Pause() override;
|
||||
bool Resume() override;
|
||||
|
||||
|
@ -34,7 +35,13 @@ class RenderCompositorOGL : public RenderCompositor {
|
|||
LayoutDeviceIntSize GetBufferSize() override;
|
||||
|
||||
protected:
|
||||
void InsertFrameDoneSync();
|
||||
|
||||
RefPtr<gl::GLContext> mGL;
|
||||
|
||||
// Used to apply back-pressure in WaitForGPU().
|
||||
GLsync mPreviousFrameDoneSync;
|
||||
GLsync mThisFrameDoneSync;
|
||||
};
|
||||
|
||||
} // namespace wr
|
||||
|
|
Загрузка…
Ссылка в новой задаче