Commit ce6ad323 authored by Jonathan Backer's avatar Jonathan Backer Committed by Commit Bot

Avoid unnecessary call to MakeCurrent

SharedImage backend implementation is careful to restore GL state. The
reason we need to MakeCurrent is to create the texture in the correct
GPU process side share group.

With virtual contexts, we are often current with a different surface. By
skipping the unnecessary MakeCurrent, we avoid stalling GPU main thread
waiting for vblank on Nvidia GPUs (where use_virtualized_gl_contexts is
on by default).

Bug: 894100
Change-Id: Ibaf66ffffbe228d5413a50873e1809d115b86e59
Reviewed-on: https://chromium-review.googlesource.com/c/1320591
Commit-Queue: Jonathan Backer <backer@chromium.org>
Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606103}
parent df8e1f2a
......@@ -1309,7 +1309,9 @@ void InProcessCommandBuffer::CreateSharedImageOnGpuThread(
uint32_t usage,
const SyncToken& sync_token) {
DCHECK_CALLED_ON_VALID_SEQUENCE(gpu_sequence_checker_);
if (!MakeCurrent())
// |shared_image_factory_| never writes to the surface, so skip unnecessary
// MakeCurrent to mitigate driver bugs. https://crbug.com/457431
if (!context_->IsCurrent(nullptr) && !MakeCurrent())
return;
LazyCreateSharedImageFactory();
if (!shared_image_factory_->CreateSharedImage(mailbox, format, size,
......@@ -1366,7 +1368,9 @@ void InProcessCommandBuffer::UpdateSharedImageOnGpuThread(
void InProcessCommandBuffer::DestroySharedImageOnGpuThread(
const Mailbox& mailbox) {
DCHECK_CALLED_ON_VALID_SEQUENCE(gpu_sequence_checker_);
if (!MakeCurrent())
// |shared_image_factory_| never writes to the surface, so skip unnecessary
// MakeCurrent to mitigate driver bugs. https://crbug.com/457431
if (!context_->IsCurrent(nullptr) && !MakeCurrent())
return;
if (!shared_image_factory_ ||
!shared_image_factory_->DestroySharedImage(mailbox)) {
......
......@@ -144,6 +144,23 @@ void SharedImageStub::OnDestroySharedImage(const Mailbox& mailbox) {
}
}
bool SharedImageStub::MakeContextCurrent() {
DCHECK(context_state_);
DCHECK(!context_state_->context_lost);
// |factory_| never writes to the surface, so skip unnecessary MakeCurrent to
// mitigate driver bugs. https://crbug.com/457431
if (context_state_->context->IsCurrent(nullptr))
return true;
if (context_state_->context->MakeCurrent(context_state_->surface.get())) {
return true;
} else {
LOG(ERROR) << "SharedImageStub: MakeCurrent failed";
return false;
}
}
bool SharedImageStub::MakeContextCurrentAndCreateFactory() {
if (!factory_) {
auto* channel_manager = channel_->gpu_channel_manager();
......@@ -156,10 +173,8 @@ bool SharedImageStub::MakeContextCurrentAndCreateFactory() {
}
DCHECK(context_state_);
DCHECK(!context_state_->context_lost);
if (!context_state_->context->MakeCurrent(context_state_->surface.get())) {
LOG(ERROR) << "SharedImageStub: MakeCurrent failed";
if (!MakeContextCurrent())
return false;
}
gpu::GpuMemoryBufferFactory* gmb_factory =
channel_manager->gpu_memory_buffer_factory();
factory_ = std::make_unique<SharedImageFactory>(
......@@ -176,10 +191,9 @@ bool SharedImageStub::MakeContextCurrentAndCreateFactory() {
LOG(ERROR) << "SharedImageStub: context already lost";
return false;
} else {
if (context_state_->context->MakeCurrent(context_state_->surface.get()))
if (MakeContextCurrent())
return true;
context_state_->context_lost = true;
LOG(ERROR) << "SharedImageStub: MakeCurrent failed";
return false;
}
}
......
......@@ -50,6 +50,7 @@ class SharedImageStub : public IPC::Listener,
void OnCreateGMBSharedImage(GpuChannelMsg_CreateGMBSharedImage_Params params);
void OnUpdateSharedImage(const Mailbox& mailbox, uint32_t release_id);
void OnDestroySharedImage(const Mailbox& mailbox);
bool MakeContextCurrent();
bool MakeContextCurrentAndCreateFactory();
void OnError();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment