-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathenable-vaapi-on-linux.diff
291 lines (265 loc) · 12.1 KB
/
enable-vaapi-on-linux.diff
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
From 53b93dfe87fd10cced5d2a2a63072dfc7a2af6e4 Mon Sep 17 00:00:00 2001
From: Daniel Charles <[email protected]>
Date: Fri, 28 Jul 2017 16:31:47 -0700
Subject: [PATCH] Enable VAVDA, VAVEA and VAJDA on linux with VAAPI only
This patch contains all the changes necessary to use VA-API along with
vaapi-driver to run all media use cases supported with hardware acceleration.
It is intended to remain as experimental accessible from chrome://flags on linux.
It requires libva/intel-vaapi-driver to be installed on the system path where
chrome is executed. Other drivers could be tested if available. Flags are
kept independent for linux, where this feature has to be enabled before
actually using it. This should not change how other OSes use the flags
already, the new flags will show at the buttom on the section of unavailable
experiments
The changes cover a range of compiler pre-processor flags to enable the stack.
It moves the presandbox operations to the vaapi_wrapper class as the hook function
is available there. vaInit will open driver on the correct installed folder.
chrome flags consolidtation into only two flags for linux. Mjpeg and accelerated
video are used. The other flags are kept for ChromeOS and other OSes.
Developer testing was made on skylake hardware, ChromeOS and Ubuntu.
BUG=NONE
TEST="subjective testing with VAVDA,VAVEA and VAJDA, autotest for encoder"
TEST="and decoder hardware accelerated"
TEST="have libva/intel-vaapi-driver installed and not installed in the system"
TEST="repeat on different hardware families"
Cq-Include-Trybots: master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: Ifbbf5c9e5221a8b5733fc6d4d0cf984a1f103171
Signed-off-by: Daniel Charles <[email protected]>
---
Index: beta/chrome/browser/about_flags.cc
===================================================================
--- beta.orig/chrome/browser/about_flags.cc
+++ beta/chrome/browser/about_flags.cc
@@ -2646,7 +2646,7 @@ const FeatureEntry kFeatureEntries[] = {
"disable-accelerated-video-decode",
flag_descriptions::kAcceleratedVideoDecodeName,
flag_descriptions::kAcceleratedVideoDecodeDescription,
- kOsMac | kOsWin | kOsCrOS | kOsAndroid,
+ kOsAll,
SINGLE_DISABLE_VALUE_TYPE(switches::kDisableAcceleratedVideoDecode),
},
#endif // defined(OS_LINUX) && !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
@@ -3106,10 +3106,10 @@ const FeatureEntry kFeatureEntries[] = {
flag_descriptions::kWebXrForceRuntimeDescription, kOsDesktop,
MULTI_VALUE_TYPE(kWebXrForceRuntimeChoices)},
#endif // ENABLE_VR
-#if defined(OS_CHROMEOS)
+#if defined(OS_LINUX) && !defined(OS_ANDROID)
{"disable-accelerated-mjpeg-decode",
flag_descriptions::kAcceleratedMjpegDecodeName,
- flag_descriptions::kAcceleratedMjpegDecodeDescription, kOsCrOS,
+ flag_descriptions::kAcceleratedMjpegDecodeDescription, kOsCrOS | kOsLinux,
SINGLE_DISABLE_VALUE_TYPE(switches::kDisableAcceleratedMjpegDecode)},
#endif // OS_CHROMEOS
{"system-keyboard-lock", flag_descriptions::kSystemKeyboardLockName,
Index: beta/chrome/browser/flag_descriptions.cc
===================================================================
--- beta.orig/chrome/browser/flag_descriptions.cc
+++ beta/chrome/browser/flag_descriptions.cc
@@ -3512,9 +3512,7 @@ const char kVideoToolboxVp9DecodingDescr
#endif
-// Chrome OS -------------------------------------------------------------------
-
-#if defined(OS_CHROMEOS)
+#if defined(OS_LINUX) && !defined(OS_ANDROID)
const char kAcceleratedMjpegDecodeName[] =
"Hardware-accelerated mjpeg decode for captured frame";
@@ -3522,6 +3520,12 @@ const char kAcceleratedMjpegDecodeDescri
"Enable hardware-accelerated mjpeg decode for captured frame where "
"available.";
+#endif
+
+// Chrome OS -------------------------------------------------------------------
+
+#if defined(OS_CHROMEOS)
+
const char kAggregatedMlAppRankingName[] = "Rank suggested apps with ML.";
const char kAggregatedMlAppRankingDescription[] =
"Use the aggregated ML model to rank the suggested apps.";
Index: beta/chrome/browser/flag_descriptions.h
===================================================================
--- beta.orig/chrome/browser/flag_descriptions.h
+++ beta/chrome/browser/flag_descriptions.h
@@ -2023,13 +2023,17 @@ extern const char kVideoToolboxVp9Decodi
#endif // defined(OS_MAC)
-// Chrome OS ------------------------------------------------------------------
-
-#if defined(OS_CHROMEOS)
+#if defined(OS_LINUX) && !defined(OS_ANDROID)
extern const char kAcceleratedMjpegDecodeName[];
extern const char kAcceleratedMjpegDecodeDescription[];
+#endif
+
+// Chrome OS ------------------------------------------------------------------
+
+#if defined(OS_CHROMEOS)
+
extern const char kAggregatedMlAppRankingName[];
extern const char kAggregatedMlAppRankingDescription[];
Index: beta/content/gpu/BUILD.gn
===================================================================
--- beta.orig/content/gpu/BUILD.gn
+++ beta/content/gpu/BUILD.gn
@@ -5,6 +5,7 @@
import("//build/config/ui.gni")
import("//gpu/vulkan/features.gni")
import("//media/media_options.gni")
+import("//media/gpu/args.gni")
import("//ui/ozone/ozone.gni")
# See //content/BUILD.gn for how this works.
@@ -128,4 +129,8 @@ target(link_target_type, "gpu_sources")
(!is_chromecast || is_cast_desktop_build)) {
configs += [ "//build/config/linux/dri" ]
}
+
+ if (is_desktop_linux && use_vaapi) {
+ public_configs = [ "//build/config/linux/libva" ]
+ }
}
Index: beta/media/base/media_switches.cc
===================================================================
--- beta.orig/media/base/media_switches.cc
+++ beta/media/base/media_switches.cc
@@ -791,7 +791,7 @@ bool IsVideoCaptureAcceleratedJpegDecodi
switches::kUseFakeMjpegDecodeAccelerator)) {
return true;
}
-#if defined(OS_CHROMEOS)
+#if defined(OS_LINUX) && !defined(OS_ANDROID)
return true;
#endif
return false;
Index: beta/media/gpu/gpu_video_decode_accelerator_factory.cc
===================================================================
--- beta.orig/media/gpu/gpu_video_decode_accelerator_factory.cc
+++ beta/media/gpu/gpu_video_decode_accelerator_factory.cc
@@ -160,6 +160,8 @@ GpuVideoDecodeAcceleratorFactory::Create
vda = (this->*create_vda_function)(workarounds, gpu_preferences, media_log);
if (vda && vda->Initialize(config, client))
return vda;
+ else
+ LOG(ERROR) << "Initialization of one or more VDAs failed.";
}
return nullptr;
@@ -218,6 +220,7 @@ GpuVideoDecodeAcceleratorFactory::Create
const gpu::GpuDriverBugWorkarounds& workarounds,
const gpu::GpuPreferences& gpu_preferences,
MediaLog* media_log) const {
+ LOG(WARNING) << "Initializing VAAPI VDA.";
std::unique_ptr<VideoDecodeAccelerator> decoder;
decoder.reset(new VaapiVideoDecodeAccelerator(gl_client_.make_context_current,
gl_client_.bind_image));
Index: beta/media/gpu/ipc/service/gpu_video_decode_accelerator.cc
===================================================================
--- beta.orig/media/gpu/ipc/service/gpu_video_decode_accelerator.cc
+++ beta/media/gpu/ipc/service/gpu_video_decode_accelerator.cc
@@ -378,6 +378,7 @@ bool GpuVideoDecodeAccelerator::Initiali
LOG(ERROR) << "Failed creating the VDA factory";
return false;
}
+ LOG(WARNING) << "Created the VDA factory";
const gpu::GpuDriverBugWorkarounds& gpu_workarounds =
stub_->channel()->gpu_channel_manager()->gpu_driver_bug_workarounds();
@@ -398,6 +399,7 @@ bool GpuVideoDecodeAccelerator::Initiali
<< (config.is_encrypted() ? " with encryption" : "");
return false;
}
+ LOG(WARNING) << "Created VDA";
// Attempt to set up performing decoding tasks on IO thread, if supported by
// the VDA.
Index: beta/media/gpu/vaapi/vaapi_wrapper.cc
===================================================================
--- beta.orig/media/gpu/vaapi/vaapi_wrapper.cc
+++ beta/media/gpu/vaapi/vaapi_wrapper.cc
@@ -446,6 +446,11 @@ void VADisplayState::PreSandboxInitializ
base::File::FLAG_OPEN | base::File::FLAG_READ | base::File::FLAG_WRITE);
if (drm_file.IsValid())
VADisplayState::Get()->SetDrmFd(drm_file.GetPlatformFile());
+
+ const char kNvidiaPath[] = "/dev/dri/nvidiactl";
+ base::File nvidia_file = base::File(
+ base::FilePath::FromUTF8Unsafe(kNvidiaPath),
+ base::File::FLAG_OPEN | base::File::FLAG_READ | base::File::FLAG_WRITE);
}
VADisplayState::VADisplayState()
@@ -473,10 +478,6 @@ bool VADisplayState::Initialize() {
}
bool VADisplayState::InitializeOnce() {
- static_assert(
- VA_MAJOR_VERSION >= 2 || (VA_MAJOR_VERSION == 1 && VA_MINOR_VERSION >= 1),
- "Requires VA-API >= 1.1.0");
-
switch (gl::GetGLImplementation()) {
case gl::kGLImplementationEGLGLES2:
va_display_ = vaGetDisplayDRM(drm_fd_.get());
@@ -492,9 +493,13 @@ bool VADisplayState::InitializeOnce() {
break;
case gl::kGLImplementationEGLANGLE:
#if defined(USE_X11)
- if (!features::IsUsingOzonePlatform())
+ if (!features::IsUsingOzonePlatform()) {
va_display_ = vaGetDisplay(gfx::GetXDisplay());
+ if (vaDisplayIsValid(va_display_))
+ break;
+ }
#endif // USE_X11
+ va_display_ = vaGetDisplayDRM(drm_fd_.get());
break;
// Cannot infer platform from GL, try all available displays
case gl::kGLImplementationNone:
@@ -525,25 +530,23 @@ bool VADisplayState::InitializeOnce() {
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
-
// The VAAPI version.
int major_version, minor_version;
VAStatus va_res = vaInitialize(va_display_, &major_version, &minor_version);
if (va_res != VA_STATUS_SUCCESS) {
- LOG(ERROR) << "vaInitialize failed: " << vaErrorStr(va_res);
- return false;
+ LOG(ERROR) << "vaInitialize failed (ignore if using Wayland desktop environment): " << vaErrorStr(va_res);
+ va_display_ = vaGetDisplayDRM(drm_fd_.get());
+ if (!vaDisplayIsValid(va_display_)) {
+ LOG(ERROR) << "Could not get a valid DRM VA display";
+ return false;
+ }
+ va_res = vaInitialize(va_display_, &major_version, &minor_version);
+ if (va_res != VA_STATUS_SUCCESS) {
+ LOG(ERROR) << "vaInitialize failed using DRM: " << vaErrorStr(va_res);
+ return false;
+ } else {
+ LOG(WARNING) << "vaInitialize succeeded for DRM";
+ }
}
va_initialized_ = true;
@@ -551,7 +554,7 @@ bool VADisplayState::InitializeOnce() {
const std::string va_vendor_string = vaQueryVendorString(va_display_);
DLOG_IF(WARNING, va_vendor_string.empty())
<< "Vendor string empty or error reading.";
- DVLOG(1) << "VAAPI version: " << major_version << "." << minor_version << " "
+ VLOG(1) << "VAAPI version: " << major_version << "." << minor_version << " "
<< va_vendor_string;
implementation_type_ = VendorStringToImplementationType(va_vendor_string);
@@ -740,7 +743,7 @@ bool AreAttribsSupported(const base::Loc
if (attribs[i].type != required_attribs[i].type ||
(attribs[i].value & required_attribs[i].value) !=
required_attribs[i].value) {
- DVLOG(1) << "Unsupported value " << required_attribs[i].value
+ VLOG(1) << "Unsupported value " << required_attribs[i].value
<< " for attribute type " << required_attribs[i].type;
return false;
}