blob: b3d4d1c1fe4719f0ce4002c8e42050ae21de80cb [file] [log] [blame]
[email protected]84ad3a72012-02-07 00:29:451// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]a80f5ece2011-10-20 23:56:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
avif15d60a2015-12-21 17:06:335#include <stdint.h>
6
[email protected]d7b5cc72013-05-23 20:05:007#include "gpu/config/gpu_info.h"
[email protected]a80f5ece2011-10-20 23:56:558
Miguel Casas28ee90f2019-05-28 19:12:269#include "ui/gfx/buffer_format_util.h"
10
[email protected]fd4dcc52013-08-15 11:37:4311namespace {
12
henryhsud1185442015-04-10 06:39:1413void EnumerateGPUDevice(const gpu::GPUInfo::GPUDevice& device,
14 gpu::GPUInfo::Enumerator* enumerator) {
[email protected]fd4dcc52013-08-15 11:37:4315 enumerator->BeginGPUDevice();
16 enumerator->AddInt("vendorId", device.vendor_id);
17 enumerator->AddInt("deviceId", device.device_id);
[email protected]20e7cfc2014-04-02 17:33:1318 enumerator->AddBool("active", device.active);
[email protected]fd4dcc52013-08-15 11:37:4319 enumerator->AddString("vendorString", device.vendor_string);
20 enumerator->AddString("deviceString", device.device_string);
Zhenyao Mofbea81d2018-06-01 17:29:2721 enumerator->AddString("driverVendor", device.driver_vendor);
22 enumerator->AddString("driverVersion", device.driver_version);
23 enumerator->AddString("driverDate", device.driver_date);
Olli Etuaho1241aea2018-08-09 07:49:1524 enumerator->AddInt("cudaComputeCapabilityMajor",
25 device.cuda_compute_capability_major);
[email protected]fd4dcc52013-08-15 11:37:4326 enumerator->EndGPUDevice();
27}
28
henryhsud1185442015-04-10 06:39:1429void EnumerateVideoDecodeAcceleratorSupportedProfile(
30 const gpu::VideoDecodeAcceleratorSupportedProfile& profile,
31 gpu::GPUInfo::Enumerator* enumerator) {
32 enumerator->BeginVideoDecodeAcceleratorSupportedProfile();
33 enumerator->AddInt("profile", profile.profile);
34 enumerator->AddInt("maxResolutionWidth", profile.max_resolution.width());
35 enumerator->AddInt("maxResolutionHeight", profile.max_resolution.height());
36 enumerator->AddInt("minResolutionWidth", profile.min_resolution.width());
37 enumerator->AddInt("minResolutionHeight", profile.min_resolution.height());
dalecurtis4708098a2016-03-19 04:54:1138 enumerator->AddBool("encrypted_only", profile.encrypted_only);
henryhsud1185442015-04-10 06:39:1439 enumerator->EndVideoDecodeAcceleratorSupportedProfile();
40}
41
wuchengli79808322014-09-23 05:58:1442void EnumerateVideoEncodeAcceleratorSupportedProfile(
henryhsud1185442015-04-10 06:39:1443 const gpu::VideoEncodeAcceleratorSupportedProfile& profile,
44 gpu::GPUInfo::Enumerator* enumerator) {
wuchengli79808322014-09-23 05:58:1445 enumerator->BeginVideoEncodeAcceleratorSupportedProfile();
46 enumerator->AddInt("profile", profile.profile);
47 enumerator->AddInt("maxResolutionWidth", profile.max_resolution.width());
48 enumerator->AddInt("maxResolutionHeight", profile.max_resolution.height());
49 enumerator->AddInt("maxFramerateNumerator", profile.max_framerate_numerator);
50 enumerator->AddInt("maxFramerateDenominator",
51 profile.max_framerate_denominator);
52 enumerator->EndVideoEncodeAcceleratorSupportedProfile();
53}
54
Andres Calderon Jaramilloc68cd9142019-02-16 00:43:3355const char* ImageDecodeAcceleratorTypeToString(
56 gpu::ImageDecodeAcceleratorType type) {
57 switch (type) {
58 case gpu::ImageDecodeAcceleratorType::kJpeg:
59 return "JPEG";
60 case gpu::ImageDecodeAcceleratorType::kUnknown:
61 return "Unknown";
62 }
63}
64
65const char* ImageDecodeAcceleratorSubsamplingToString(
66 gpu::ImageDecodeAcceleratorSubsampling subsampling) {
67 switch (subsampling) {
68 case gpu::ImageDecodeAcceleratorSubsampling::k420:
69 return "4:2:0";
70 case gpu::ImageDecodeAcceleratorSubsampling::k422:
71 return "4:2:2";
Andres Calderon Jaramillo4fdf6c42019-03-21 15:45:0672 case gpu::ImageDecodeAcceleratorSubsampling::k444:
73 return "4:4:4";
Andres Calderon Jaramilloc68cd9142019-02-16 00:43:3374 }
75}
76
77void EnumerateImageDecodeAcceleratorSupportedProfile(
78 const gpu::ImageDecodeAcceleratorSupportedProfile& profile,
79 gpu::GPUInfo::Enumerator* enumerator) {
80 enumerator->BeginImageDecodeAcceleratorSupportedProfile();
81 enumerator->AddString("imageType",
82 ImageDecodeAcceleratorTypeToString(profile.image_type));
83 enumerator->AddString("minEncodedDimensions",
84 profile.min_encoded_dimensions.ToString());
85 enumerator->AddString("maxEncodedDimensions",
86 profile.max_encoded_dimensions.ToString());
87 std::string subsamplings;
88 for (size_t i = 0; i < profile.subsamplings.size(); i++) {
89 if (i > 0)
90 subsamplings += ", ";
91 subsamplings +=
92 ImageDecodeAcceleratorSubsamplingToString(profile.subsamplings[i]);
93 }
94 enumerator->AddString("subsamplings", subsamplings);
95 enumerator->EndImageDecodeAcceleratorSupportedProfile();
96}
97
Sunny Sachanandanifc66e9a2018-07-10 18:08:2998#if defined(OS_WIN)
Zhenyao Moda88bdc2018-09-27 01:47:3399void EnumerateDx12VulkanVersionInfo(const gpu::Dx12VulkanVersionInfo& info,
100 gpu::GPUInfo::Enumerator* enumerator) {
101 enumerator->BeginDx12VulkanVersionInfo();
102 enumerator->AddBool("supportsDx12", info.supports_dx12);
103 enumerator->AddBool("supportsVulkan", info.supports_vulkan);
104 enumerator->AddInt("dx12FeatureLevel",
105 static_cast<int>(info.d3d12_feature_level));
106 enumerator->AddInt("vulkanVersion", static_cast<int>(info.vulkan_version));
107 enumerator->EndDx12VulkanVersionInfo();
108}
Sunny Sachanandanifc66e9a2018-07-10 18:08:29109#endif
110
[email protected]fd4dcc52013-08-15 11:37:43111} // namespace
112
[email protected]d7b5cc72013-05-23 20:05:00113namespace gpu {
[email protected]a80f5ece2011-10-20 23:56:55114
Sunny Sachanandani3dcb5da2018-10-18 04:59:43115#if defined(OS_WIN)
Zhenyao Mo4178e192019-05-16 21:46:11116const char* OverlaySupportToString(gpu::OverlaySupport support) {
117 switch (support) {
118 case gpu::OverlaySupport::kNone:
119 return "NONE";
120 case gpu::OverlaySupport::kDirect:
121 return "DIRECT";
122 case gpu::OverlaySupport::kScaling:
123 return "SCALING";
Sunny Sachanandanifc66e9a2018-07-10 18:08:29124 }
Sunny Sachanandanifc66e9a2018-07-10 18:08:29125}
Zhenyao Mo4178e192019-05-16 21:46:11126#endif // OS_WIN
Sunny Sachanandanifc66e9a2018-07-10 18:08:29127
liberato575877902015-12-10 17:16:26128VideoDecodeAcceleratorCapabilities::VideoDecodeAcceleratorCapabilities()
129 : flags(0) {}
130
vmpstr3b7b8b22016-03-01 23:00:20131VideoDecodeAcceleratorCapabilities::VideoDecodeAcceleratorCapabilities(
132 const VideoDecodeAcceleratorCapabilities& other) = default;
133
Chris Watkins81030772017-12-07 01:20:56134VideoDecodeAcceleratorCapabilities::~VideoDecodeAcceleratorCapabilities() =
135 default;
liberato575877902015-12-10 17:16:26136
Andres Calderon Jaramilloc68cd9142019-02-16 00:43:33137ImageDecodeAcceleratorSupportedProfile::ImageDecodeAcceleratorSupportedProfile()
138 : image_type(ImageDecodeAcceleratorType::kUnknown) {}
139
140ImageDecodeAcceleratorSupportedProfile::ImageDecodeAcceleratorSupportedProfile(
141 const ImageDecodeAcceleratorSupportedProfile& other) = default;
142
143ImageDecodeAcceleratorSupportedProfile::ImageDecodeAcceleratorSupportedProfile(
144 ImageDecodeAcceleratorSupportedProfile&& other) = default;
145
146ImageDecodeAcceleratorSupportedProfile::
147 ~ImageDecodeAcceleratorSupportedProfile() = default;
148
149ImageDecodeAcceleratorSupportedProfile& ImageDecodeAcceleratorSupportedProfile::
150operator=(const ImageDecodeAcceleratorSupportedProfile& other) = default;
151
152ImageDecodeAcceleratorSupportedProfile& ImageDecodeAcceleratorSupportedProfile::
153operator=(ImageDecodeAcceleratorSupportedProfile&& other) = default;
154
[email protected]a094e2c2012-05-10 23:02:42155GPUInfo::GPUDevice::GPUDevice()
156 : vendor_id(0),
[email protected]20e7cfc2014-04-02 17:33:13157 device_id(0),
Olli Etuaho1241aea2018-08-09 07:49:15158 active(false),
159 cuda_compute_capability_major(0) {}
[email protected]a094e2c2012-05-10 23:02:42160
Zhenyao Mofbea81d2018-06-01 17:29:27161GPUInfo::GPUDevice::GPUDevice(const GPUInfo::GPUDevice& other) = default;
162
163GPUInfo::GPUDevice::GPUDevice(GPUInfo::GPUDevice&& other) noexcept = default;
164
165GPUInfo::GPUDevice::~GPUDevice() noexcept = default;
166
167GPUInfo::GPUDevice& GPUInfo::GPUDevice::operator=(
168 const GPUInfo::GPUDevice& other) = default;
169
170GPUInfo::GPUDevice& GPUInfo::GPUDevice::operator=(
171 GPUInfo::GPUDevice&& other) noexcept = default;
[email protected]a094e2c2012-05-10 23:02:42172
[email protected]a80f5ece2011-10-20 23:56:55173GPUInfo::GPUInfo()
zmo84eae5e2014-09-05 01:36:23174 : optimus(false),
[email protected]c32b0c2c2012-04-07 01:34:33175 amd_switchable(false),
[email protected]6c7784e2013-08-01 22:41:28176 gl_reset_notification_strategy(0),
[email protected]fad3ccf2012-09-11 22:36:00177 software_rendering(false),
[email protected]47752982014-07-29 08:01:43178 sandboxed(false),
bajonese3677b649ff2015-07-25 00:41:56179 in_process_gpu(true),
geofflang774e87a2016-12-05 16:29:01180 passthrough_cmd_decoder(false),
Jonathan Backera57031b2018-06-04 15:44:32181 jpeg_decode_accelerator_supported(false),
Antonio Gomes5b4d98e2017-08-24 05:53:07182#if defined(USE_X11)
thomasanderson62ba78ff2016-10-01 02:03:42183 system_visual(0),
Jonathan Backera57031b2018-06-04 15:44:32184 rgba_visual(0),
thomasanderson62ba78ff2016-10-01 02:03:42185#endif
Jonathan Backera57031b2018-06-04 15:44:32186 oop_rasterization_supported(false) {
[email protected]a80f5ece2011-10-20 23:56:55187}
188
vmpstr3b7b8b22016-03-01 23:00:20189GPUInfo::GPUInfo(const GPUInfo& other) = default;
190
Chris Watkins81030772017-12-07 01:20:56191GPUInfo::~GPUInfo() = default;
[email protected]a80f5ece2011-10-20 23:56:55192
Zhenyao Mofbea81d2018-06-01 17:29:27193GPUInfo::GPUDevice& GPUInfo::active_gpu() {
194 return const_cast<GPUInfo::GPUDevice&>(
195 const_cast<const GPUInfo&>(*this).active_gpu());
196}
197
ccameron8c3b0dd132017-05-16 19:30:50198const GPUInfo::GPUDevice& GPUInfo::active_gpu() const {
Zhenyao Moc4f79c32018-01-27 02:44:13199 if (gpu.active || secondary_gpus.empty())
ccameron8c3b0dd132017-05-16 19:30:50200 return gpu;
Zhenyao Mofbea81d2018-06-01 17:29:27201 for (const auto& secondary_gpu : secondary_gpus) {
ccameron8c3b0dd132017-05-16 19:30:50202 if (secondary_gpu.active)
203 return secondary_gpu;
204 }
Zhenyao Mofbea81d2018-06-01 17:29:27205 DVLOG(2) << "No active GPU found, returning primary GPU.";
ccameron8c3b0dd132017-05-16 19:30:50206 return gpu;
207}
208
Zhenyao Mo68ef56d2018-04-21 01:05:10209bool GPUInfo::IsInitialized() const {
210 return gpu.vendor_id != 0 || !gl_vendor.empty();
211}
212
[email protected]fd4dcc52013-08-15 11:37:43213void GPUInfo::EnumerateFields(Enumerator* enumerator) const {
214 struct GPUInfoKnownFields {
[email protected]fd4dcc52013-08-15 11:37:43215 base::TimeDelta initialization_time;
216 bool optimus;
217 bool amd_switchable;
[email protected]fd4dcc52013-08-15 11:37:43218 GPUDevice gpu;
219 std::vector<GPUDevice> secondary_gpus;
[email protected]fd4dcc52013-08-15 11:37:43220 std::string pixel_shader_version;
221 std::string vertex_shader_version;
senorblancob7a64d572015-04-08 16:59:02222 std::string max_msaa_samples;
[email protected]2ac8e51c2014-04-21 20:54:13223 std::string machine_model_name;
224 std::string machine_model_version;
[email protected]fd4dcc52013-08-15 11:37:43225 std::string gl_version_string;
226 std::string gl_vendor;
227 std::string gl_renderer;
228 std::string gl_extensions;
229 std::string gl_ws_vendor;
230 std::string gl_ws_version;
231 std::string gl_ws_extensions;
avif15d60a2015-12-21 17:06:33232 uint32_t gl_reset_notification_strategy;
[email protected]fd4dcc52013-08-15 11:37:43233 bool software_rendering;
Jonathan Backer01293832019-03-20 20:27:10234 std::string direct_rendering_version;
[email protected]fd4dcc52013-08-15 11:37:43235 bool sandboxed;
bajonese3677b649ff2015-07-25 00:41:56236 bool in_process_gpu;
geofflang774e87a2016-12-05 16:29:01237 bool passthrough_cmd_decoder;
Bo Liu9cad099c2017-07-06 14:45:27238 bool can_support_threaded_texture_mailbox;
[email protected]fd4dcc52013-08-15 11:37:43239#if defined(OS_WIN)
Sunny Sachanandani6e844c42018-11-09 20:27:12240 bool direct_composition;
241 bool supports_overlays;
Zhenyao Mo4178e192019-05-16 21:46:11242 OverlaySupport yuy2_overlay_support;
243 OverlaySupport nv12_overlay_support;
[email protected]fd4dcc52013-08-15 11:37:43244 DxDiagNode dx_diagnostics;
Zhenyao Moda88bdc2018-09-27 01:47:33245 Dx12VulkanVersionInfo dx12_vulkan_version_info;
[email protected]fd4dcc52013-08-15 11:37:43246#endif
Maggie Chen35d65e4a2018-04-12 21:15:25247
liberato575877902015-12-10 17:16:26248 VideoDecodeAcceleratorCapabilities video_decode_accelerator_capabilities;
henryhsud1185442015-04-10 06:39:14249 VideoEncodeAcceleratorSupportedProfiles
wuchengli79808322014-09-23 05:58:14250 video_encode_accelerator_supported_profiles;
henryhsu74f6ef12015-07-23 08:34:37251 bool jpeg_decode_accelerator_supported;
Andres Calderon Jaramilloc68cd9142019-02-16 00:43:33252
253 ImageDecodeAcceleratorSupportedProfiles
254 image_decode_accelerator_supported_profiles;
255
Miguel Casas28ee90f2019-05-28 19:12:26256 std::vector<gfx::BufferFormat>
257 supported_buffer_formats_for_allocation_and_texturing;
258
Antonio Gomes5b4d98e2017-08-24 05:53:07259#if defined(USE_X11)
thomasanderson62ba78ff2016-10-01 02:03:42260 VisualID system_visual;
261 VisualID rgba_visual;
262#endif
Andres Calderon Jaramilloc68cd9142019-02-16 00:43:33263
Jonathan Backera57031b2018-06-04 15:44:32264 bool oop_rasterization_supported;
[email protected]fd4dcc52013-08-15 11:37:43265 };
266
267 // If this assert fails then most likely something below needs to be updated.
268 // Note that this assert is only approximate. If a new field is added to
269 // GPUInfo which fits within the current padding then it will not be caught.
mostynb7f032092014-12-20 00:36:44270 static_assert(
[email protected]fd4dcc52013-08-15 11:37:43271 sizeof(GPUInfo) == sizeof(GPUInfoKnownFields),
mostynb7f032092014-12-20 00:36:44272 "fields have changed in GPUInfo, GPUInfoKnownFields must be updated");
[email protected]fd4dcc52013-08-15 11:37:43273
274 // Required fields (according to DevTools protocol) first.
[email protected]2ac8e51c2014-04-21 20:54:13275 enumerator->AddString("machineModelName", machine_model_name);
276 enumerator->AddString("machineModelVersion", machine_model_version);
henryhsud1185442015-04-10 06:39:14277 EnumerateGPUDevice(gpu, enumerator);
Jonathan Backera57031b2018-06-04 15:44:32278 for (const auto& secondary_gpu : secondary_gpus)
henryhsud1185442015-04-10 06:39:14279 EnumerateGPUDevice(secondary_gpu, enumerator);
[email protected]fd4dcc52013-08-15 11:37:43280
281 enumerator->BeginAuxAttributes();
Miguel Casas28ee90f2019-05-28 19:12:26282 enumerator->AddTimeDeltaInSecondsF("initializationTime", initialization_time);
[email protected]fd4dcc52013-08-15 11:37:43283 enumerator->AddBool("optimus", optimus);
284 enumerator->AddBool("amdSwitchable", amd_switchable);
[email protected]fd4dcc52013-08-15 11:37:43285 enumerator->AddString("pixelShaderVersion", pixel_shader_version);
286 enumerator->AddString("vertexShaderVersion", vertex_shader_version);
senorblancob7a64d572015-04-08 16:59:02287 enumerator->AddString("maxMsaaSamples", max_msaa_samples);
[email protected]fd4dcc52013-08-15 11:37:43288 enumerator->AddString("glVersion", gl_version);
[email protected]fd4dcc52013-08-15 11:37:43289 enumerator->AddString("glVendor", gl_vendor);
290 enumerator->AddString("glRenderer", gl_renderer);
291 enumerator->AddString("glExtensions", gl_extensions);
292 enumerator->AddString("glWsVendor", gl_ws_vendor);
293 enumerator->AddString("glWsVersion", gl_ws_version);
294 enumerator->AddString("glWsExtensions", gl_ws_extensions);
295 enumerator->AddInt(
296 "glResetNotificationStrategy",
297 static_cast<int>(gl_reset_notification_strategy));
[email protected]fd4dcc52013-08-15 11:37:43298 // TODO(kbr): add performance_stats.
299 enumerator->AddBool("softwareRendering", software_rendering);
Jonathan Backer01293832019-03-20 20:27:10300 enumerator->AddString("directRenderingVersion", direct_rendering_version);
[email protected]fd4dcc52013-08-15 11:37:43301 enumerator->AddBool("sandboxed", sandboxed);
bajonese3677b649ff2015-07-25 00:41:56302 enumerator->AddBool("inProcessGpu", in_process_gpu);
geofflang774e87a2016-12-05 16:29:01303 enumerator->AddBool("passthroughCmdDecoder", passthrough_cmd_decoder);
Bo Liu9cad099c2017-07-06 14:45:27304 enumerator->AddBool("canSupportThreadedTextureMailbox",
305 can_support_threaded_texture_mailbox);
[email protected]fd4dcc52013-08-15 11:37:43306 // TODO(kbr): add dx_diagnostics on Windows.
Maggie Chen35d65e4a2018-04-12 21:15:25307#if defined(OS_WIN)
Sunny Sachanandani6e844c42018-11-09 20:27:12308 enumerator->AddBool("directComposition", direct_composition);
309 enumerator->AddBool("supportsOverlays", supports_overlays);
Zhenyao Mo4178e192019-05-16 21:46:11310 enumerator->AddString("yuy2OverlaySupport",
311 OverlaySupportToString(yuy2_overlay_support));
312 enumerator->AddString("nv12OverlaySupport",
313 OverlaySupportToString(nv12_overlay_support));
Zhenyao Moda88bdc2018-09-27 01:47:33314 EnumerateDx12VulkanVersionInfo(dx12_vulkan_version_info, enumerator);
Maggie Chen35d65e4a2018-04-12 21:15:25315#endif
liberato575877902015-12-10 17:16:26316 enumerator->AddInt("videoDecodeAcceleratorFlags",
317 video_decode_accelerator_capabilities.flags);
Miguel Casas28ee90f2019-05-28 19:12:26318
319 // TODO(crbug.com/966839): Fix the two supported profile dumping below.
liberato575877902015-12-10 17:16:26320 for (const auto& profile :
321 video_decode_accelerator_capabilities.supported_profiles)
henryhsud1185442015-04-10 06:39:14322 EnumerateVideoDecodeAcceleratorSupportedProfile(profile, enumerator);
323 for (const auto& profile : video_encode_accelerator_supported_profiles)
324 EnumerateVideoEncodeAcceleratorSupportedProfile(profile, enumerator);
henryhsu74f6ef12015-07-23 08:34:37325 enumerator->AddBool("jpegDecodeAcceleratorSupported",
326 jpeg_decode_accelerator_supported);
Andres Calderon Jaramilloc68cd9142019-02-16 00:43:33327 for (const auto& profile : image_decode_accelerator_supported_profiles)
328 EnumerateImageDecodeAcceleratorSupportedProfile(profile, enumerator);
Antonio Gomes5b4d98e2017-08-24 05:53:07329#if defined(USE_X11)
thomasanderson62ba78ff2016-10-01 02:03:42330 enumerator->AddInt64("systemVisual", system_visual);
331 enumerator->AddInt64("rgbaVisual", rgba_visual);
332#endif
Jonathan Backera57031b2018-06-04 15:44:32333 enumerator->AddBool("oopRasterizationSupported", oop_rasterization_supported);
Miguel Casas28ee90f2019-05-28 19:12:26334 std::string supported_formats;
335 for (const auto& format :
336 supported_buffer_formats_for_allocation_and_texturing) {
337 supported_formats += gfx::BufferFormatToString(format);
338 supported_formats += " ";
339 }
340 enumerator->AddString("supportedBufferFormatsForAllocationAndTexturing",
341 supported_formats);
[email protected]fd4dcc52013-08-15 11:37:43342 enumerator->EndAuxAttributes();
343}
344
[email protected]d7b5cc72013-05-23 20:05:00345} // namespace gpu