Commit 0fb7ef15 authored by Patrick To's avatar Patrick To Committed by Commit Bot

Revert back to the default GPU when no renderers are using WebXR

The GPU process may have been restarted and initialized on a different
GPU than the default if the VR headset is not plugged into the default
GPU. Staying on this XR compatible GPU can drain battery a lot quicker.
When there are no longer any renderers using WebXR, this change reverts
reverts the GPU process back to the default GPU.

Bug: 1090951
Change-Id: Ibc5e7f709d2c82d5a6e8cbda08766d1d654951a3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2321771
Commit-Queue: Patrick To <patrto@microsoft.com>
Reviewed-by: default avatarAlexander Cooper <alcooper@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798950}
parent f9c85f1b
......@@ -15,7 +15,6 @@
#include "base/memory/singleton.h"
#include "base/strings/string_number_conversions.h"
#include "base/trace_event/common/trace_event_common.h"
#include "build/build_config.h"
#include "content/browser/xr/xr_utils.h"
#include "content/public/browser/device_service.h"
#include "content/public/browser/gpu_data_manager.h"
......@@ -340,12 +339,24 @@ void XRRuntimeManagerImpl::MakeXrCompatible() {
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kUseAdapterLuid, luid_string);
// Store the current GPU so we can revert back once XR is no longer needed.
// If default_gpu_ is nonzero, we have already previously stored the
// default GPU and should not overwrite it.
if (default_gpu_.LowPart == 0 && default_gpu_.HighPart == 0) {
default_gpu_ = content::GpuDataManager::GetInstance()
->GetGPUInfo()
.active_gpu()
.luid;
}
xr_compatible_restarted_gpu_ = true;
// Get notified when the new GPU process sends back its GPUInfo. This
// indicates that the GPU process has finished initializing and the GPUInfo
// contains the LUID of the active adapter.
content::GpuDataManager::GetInstance()->AddObserver(this);
content::KillGpuProcess();
return;
#else
// MakeXrCompatible is not yet supported on other platforms so
......@@ -408,6 +419,27 @@ XRRuntimeManagerImpl::~XRRuntimeManagerImpl() {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
CHECK_EQ(g_xr_runtime_manager, this);
g_xr_runtime_manager = nullptr;
// If a GPU adapter LUID was added to the command line to pass to the GPU
// process, remove the switch so subsequent GPU processes initialize on the
// default GPU.
if (xr_compatible_restarted_gpu_) {
base::CommandLine::ForCurrentProcess()->RemoveSwitch(
switches::kUseAdapterLuid);
#if defined(OS_WIN)
// If we changed the GPU, revert it back to the default GPU. This is
// separate from xr_compatible_restarted_gpu_ because the GPU process may
// not have been successfully initialized using the specified GPU and is
// still on the default adapter.
LUID active_gpu =
content::GpuDataManager::GetInstance()->GetGPUInfo().active_gpu().luid;
if (active_gpu.LowPart != default_gpu_.LowPart ||
active_gpu.HighPart != default_gpu_.HighPart) {
content::KillGpuProcess();
}
#endif
}
}
scoped_refptr<XRRuntimeManagerImpl> XRRuntimeManagerImpl::CreateInstance(
......
......@@ -18,6 +18,7 @@
#include "base/optional.h"
#include "base/threading/thread_checker.h"
#include "base/timer/timer.h"
#include "build/build_config.h"
#include "content/browser/xr/service/browser_xr_runtime_impl.h"
#include "content/browser/xr/service/vr_service_impl.h"
#include "content/common/content_export.h"
......@@ -130,6 +131,11 @@ class CONTENT_EXPORT XRRuntimeManagerImpl
bool providers_initialized_ = false;
size_t num_initialized_providers_ = 0;
bool xr_compatible_restarted_gpu_ = false;
#if defined(OS_WIN)
LUID default_gpu_ = {0, 0};
#endif
std::set<VRServiceImpl*> services_;
THREAD_CHECKER(thread_checker_);
......
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