Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3372)

Unified Diff: gpu/config/gpu_info_collector.cc

Issue 1503223005: Identify the active GPU using GL strings in multiple GPU situation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: gpu/config/gpu_info_collector.cc
diff --git a/gpu/config/gpu_info_collector.cc b/gpu/config/gpu_info_collector.cc
index beda6fd5b96951f75415860d851951ba52db1bf5..d31f2d5d3945d86b202e8ac2b2739fda501dc982 100644
--- a/gpu/config/gpu_info_collector.cc
+++ b/gpu/config/gpu_info_collector.cc
@@ -13,6 +13,7 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_split.h"
+#include "base/strings/string_util.h"
#include "base/trace_event/trace_event.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_context.h"
@@ -149,12 +150,22 @@ CollectInfoResult CollectGraphicsInfoGL(GPUInfo* gpu_info) {
gpu_info->pixel_shader_version = glsl_version;
gpu_info->vertex_shader_version = glsl_version;
+ IdentifyActiveGPU(gpu_info);
return CollectDriverInfoGL(gpu_info);
}
void MergeGPUInfoGL(GPUInfo* basic_gpu_info,
const GPUInfo& context_gpu_info) {
DCHECK(basic_gpu_info);
+ // Copy over active GPU setting because it might change.
+ basic_gpu_info->gpu.active = context_gpu_info.gpu.active;
+ size_t count = std::min(basic_gpu_info->secondary_gpus.size(),
+ context_gpu_info.secondary_gpus.size());
+ for (size_t ii = 0; ii < count; ++ii) {
+ basic_gpu_info->secondary_gpus[ii].active =
+ context_gpu_info.secondary_gpus[ii].active;
Ken Russell (switch to Gerrit) 2015/12/08 22:58:48 Are the secondary GPUs guaranteed to be in the sam
Zhenyao Mo 2015/12/09 18:36:53 I don't think the order will change because it's t
+ }
+
basic_gpu_info->gl_renderer = context_gpu_info.gl_renderer;
basic_gpu_info->gl_vendor = context_gpu_info.gl_vendor;
basic_gpu_info->gl_version = context_gpu_info.gl_version;
@@ -190,5 +201,65 @@ void MergeGPUInfoGL(GPUInfo* basic_gpu_info,
context_gpu_info.jpeg_decode_accelerator_supported;
}
+void IdentifyActiveGPU(GPUInfo* gpu_info) {
+ const std::string kNVidiaName = "nvidia";
+ const std::string kIntelName = "intel";
+ const std::string kAMDName = "amd";
+ const std::string kATIName = "ati";
+ const std::string kVendorNames[] = {
+ kNVidiaName, kIntelName, kAMDName, kATIName};
+
+ const uint32 kNVidiaID = 0x10de;
+ const uint32 kIntelID = 0x8086;
+ const uint32 kAMDID = 0x1002;
+ const uint32 kATIID = 0x1002;
+ const uint32 kVendorIDs[] = {
+ kNVidiaID, kIntelID, kAMDID, kATIID};
+
+ DCHECK(gpu_info);
+ if (gpu_info->secondary_gpus.size() == 0)
+ return;
+
+ uint32 active_vendor_id = 0;
+ if (!gpu_info->gl_vendor.empty()) {
+ std::string gl_vendor_lower = base::ToLowerASCII(gpu_info->gl_vendor);
+ for (size_t ii = 0; ii < arraysize(kVendorNames); ++ii) {
+ if (gl_vendor_lower.find(kVendorNames[ii]) != std::string::npos) {
+ active_vendor_id = kVendorIDs[ii];
Ken Russell (switch to Gerrit) 2015/12/08 22:58:48 We need to be very careful here. "ati" is a substr
Zhenyao Mo 2015/12/09 18:36:53 Done.
+ break;
+ }
+ }
+ }
+ if (active_vendor_id == 0 && !gpu_info->gl_renderer.empty()) {
+ std::string gl_renderer_lower = base::ToLowerASCII(gpu_info->gl_renderer);
+ for (size_t ii = 0; ii < arraysize(kVendorNames); ++ii) {
+ if (gl_renderer_lower.find(kVendorNames[ii]) != std::string::npos) {
+ active_vendor_id = kVendorIDs[ii];
+ break;
+ }
+ }
+ }
+ if (active_vendor_id == 0) {
+ // We fail to idendify the GPU vendor through GL_VENDOR/GL_RENDERER.
+ return;
+ }
+ gpu_info->gpu.active = false;
+ for (size_t ii = 0; ii < gpu_info->secondary_gpus.size(); ++ii)
+ gpu_info->secondary_gpus[ii].active = false;
+
+ // TODO(zmo): if two GPUs are from the same vendor, this code will always
+ // set the first GPU as active, which could be wrong.
+ if (active_vendor_id == gpu_info->gpu.vendor_id) {
+ gpu_info->gpu.active = true;
+ return;
+ }
+ for (size_t ii = 0; ii < gpu_info->secondary_gpus.size(); ++ii) {
+ if (active_vendor_id == gpu_info->secondary_gpus[ii].vendor_id) {
+ gpu_info->secondary_gpus[ii].active = true;
+ return;
+ }
+ }
+}
+
} // namespace gpu

Powered by Google App Engine
This is Rietveld 408576698