summarylogtreecommitdiffstats
path: root/only-fall-back-to-the-i965-driver-if-we-re-on-iHD.patch
blob: ed811bce106a54f10f4caf8921fcfc85c5705ca0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
From fbd756ab55f9351165f923b0411c31dd71319c78 Mon Sep 17 00:00:00 2001
From: Ted Meyer <tmathmeyer@chromium.org>
Date: Wed, 16 Sep 2020 17:42:03 +0000
Subject: [PATCH] Only fall back to the i965 driver if we're on iHD

I got my hands on an old AMD laptop, and the gallium driver worked very
well and was saving power even at 720p, so there's no reason to block
that for now.

Bug: 1116703
Change-Id: Ib15bc2b93f33e99adad7569dd825e167b503a0ea
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2409967
Commit-Queue: Ted Meyer <tmathmeyer@chromium.org>
Reviewed-by: Andres Calderon Jaramillo <andrescj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#807550}
---
 media/gpu/vaapi/vaapi_wrapper.cc | 73 ++++++++++++++++++++------------
 1 file changed, 47 insertions(+), 26 deletions(-)

diff --git a/media/gpu/vaapi/vaapi_wrapper.cc b/media/gpu/vaapi/vaapi_wrapper.cc
index 2ad0b997e56..e30d1dfb73b 100644
--- a/media/gpu/vaapi/vaapi_wrapper.cc
+++ b/media/gpu/vaapi/vaapi_wrapper.cc
@@ -409,6 +409,8 @@ class VADisplayState {
 
   // Implementation of Initialize() called only once.
   bool InitializeOnce() EXCLUSIVE_LOCKS_REQUIRED(va_lock_);
+  bool InitializeVaDisplay_Locked() EXCLUSIVE_LOCKS_REQUIRED(va_lock_);
+  bool InitializeVaDriver_Locked() EXCLUSIVE_LOCKS_REQUIRED(va_lock_);
 
   int refcount_ GUARDED_BY(va_lock_);
 
@@ -472,11 +474,7 @@ bool VADisplayState::Initialize() {
   return success;
 }
 
-bool VADisplayState::InitializeOnce() {
-  static_assert(
-      VA_MAJOR_VERSION >= 2 || (VA_MAJOR_VERSION == 1 && VA_MINOR_VERSION >= 1),
-      "Requires VA-API >= 1.1.0");
-
+bool VADisplayState::InitializeVaDisplay_Locked() {
   switch (gl::GetGLImplementation()) {
     case gl::kGLImplementationEGLGLES2:
       va_display_ = vaGetDisplayDRM(drm_fd_.get());
@@ -519,25 +517,10 @@ bool VADisplayState::InitializeOnce() {
     return false;
   }
 
-  // Set VA logging level and driver name, unless already set.
-  constexpr char libva_log_level_env[] = "LIBVA_MESSAGING_LEVEL";
-  std::unique_ptr<base::Environment> env(base::Environment::Create());
-  if (!env->HasVar(libva_log_level_env))
-    env->SetVar(libva_log_level_env, "1");
-
-#if defined(USE_X11)
-  if (gl::GetGLImplementation() == gl::kGLImplementationEGLANGLE) {
-    DCHECK(!features::IsUsingOzonePlatform());
-    constexpr char libva_driver_impl_env[] = "LIBVA_DRIVER_NAME";
-    // TODO(crbug/1116703) The libva intel-media driver has a known segfault in
-    // vaPutSurface, so until this is fixed, fall back to the i965 driver. There
-    // is discussion of the issue here:
-    // https://github.com/intel/media-driver/issues/818
-    if (!env->HasVar(libva_driver_impl_env))
-      env->SetVar(libva_driver_impl_env, "i965");
-  }
-#endif  // USE_X11
+  return true;
+}
 
+bool VADisplayState::InitializeVaDriver_Locked() {
   // The VAAPI version.
   int major_version, minor_version;
   VAStatus va_res = vaInitialize(va_display_, &major_version, &minor_version);
@@ -545,9 +528,6 @@ bool VADisplayState::InitializeOnce() {
     LOG(ERROR) << "vaInitialize failed: " << vaErrorStr(va_res);
     return false;
   }
-
-  va_initialized_ = true;
-
   const std::string va_vendor_string = vaQueryVendorString(va_display_);
   DLOG_IF(WARNING, va_vendor_string.empty())
       << "Vendor string empty or error reading.";
@@ -555,6 +535,8 @@ bool VADisplayState::InitializeOnce() {
            << va_vendor_string;
   implementation_type_ = VendorStringToImplementationType(va_vendor_string);
 
+  va_initialized_ = true;
+
   // The VAAPI version is determined from what is loaded on the system by
   // calling vaInitialize(). Since the libva is now ABI-compatible, relax the
   // version check which helps in upgrading the libva, without breaking any
@@ -571,6 +553,45 @@ bool VADisplayState::InitializeOnce() {
   return true;
 }
 
+bool VADisplayState::InitializeOnce() {
+  static_assert(
+      VA_MAJOR_VERSION >= 2 || (VA_MAJOR_VERSION == 1 && VA_MINOR_VERSION >= 1),
+      "Requires VA-API >= 1.1.0");
+
+  // Set VA logging level, unless already set.
+  constexpr char libva_log_level_env[] = "LIBVA_MESSAGING_LEVEL";
+  std::unique_ptr<base::Environment> env(base::Environment::Create());
+  if (!env->HasVar(libva_log_level_env))
+    env->SetVar(libva_log_level_env, "1");
+
+  if (!InitializeVaDisplay_Locked() || !InitializeVaDriver_Locked())
+    return false;
+
+#if defined(USE_X11)
+  if (gl::GetGLImplementation() == gl::kGLImplementationEGLANGLE &&
+      implementation_type_ == VAImplementation::kIntelIHD) {
+    DCHECK(!features::IsUsingOzonePlatform());
+    constexpr char libva_driver_impl_env[] = "LIBVA_DRIVER_NAME";
+    // TODO(crbug/1116703) The libva intel-media driver has a known segfault in
+    // vaPutSurface, so until this is fixed, fall back to the i965 driver. There
+    // is discussion of the issue here:
+    // https://github.com/intel/media-driver/issues/818
+    if (!env->HasVar(libva_driver_impl_env))
+      env->SetVar(libva_driver_impl_env, "i965");
+
+    // Re-initialize with the new driver.
+    va_display_ = nullptr;
+    va_initialized_ = false;
+    implementation_type_ = VAImplementation::kInvalid;
+
+    if (!InitializeVaDisplay_Locked() || !InitializeVaDriver_Locked())
+      return false;
+  }
+#endif  // USE_X11
+
+  return true;
+}
+
 VAStatus VADisplayState::Deinitialize() {
   base::AutoLock auto_lock(va_lock_);
   VAStatus va_res = VA_STATUS_SUCCESS;