From 53b93dfe87fd10cced5d2a2a63072dfc7a2af6e4 Mon Sep 17 00:00:00 2001 From: Daniel Charles 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" R=posciak@chromium.org R=kcwu@chromium.org 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 --- Index: dev/chrome/browser/about_flags.cc =================================================================== --- dev.orig/chrome/browser/about_flags.cc +++ dev/chrome/browser/about_flags.cc @@ -3014,7 +3014,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) || BUILDFLAG(IS_CHROMEOS_LACROS)) && @@ -3510,10 +3510,10 @@ const FeatureEntry kFeatureEntries[] = { flag_descriptions::kWebXrForceRuntimeDescription, kOsDesktop, MULTI_VALUE_TYPE(kWebXrForceRuntimeChoices)}, #endif // ENABLE_VR -#if BUILDFLAG(IS_CHROMEOS_ASH) +#if (BUILDFLAG(IS_CHROMEOS_ASH)) || (defined(OS_LINUX) && !defined(OS_ANDROID) && !defined(OS_CHROMEOS)) {"disable-accelerated-mjpeg-decode", flag_descriptions::kAcceleratedMjpegDecodeName, - flag_descriptions::kAcceleratedMjpegDecodeDescription, kOsCrOS, + flag_descriptions::kAcceleratedMjpegDecodeDescription, kOsCrOS | kOsLinux, SINGLE_DISABLE_VALUE_TYPE(switches::kDisableAcceleratedMjpegDecode)}, #endif // BUILDFLAG(IS_CHROMEOS_ASH) {"system-keyboard-lock", flag_descriptions::kSystemKeyboardLockName, Index: dev/chrome/browser/flag_descriptions.cc =================================================================== --- dev.orig/chrome/browser/flag_descriptions.cc +++ dev/chrome/browser/flag_descriptions.cc @@ -3656,7 +3656,7 @@ const char kVideoToolboxVp9DecodingDescr // Chrome OS ------------------------------------------------------------------- -#if BUILDFLAG(IS_CHROMEOS_ASH) +#if (BUILDFLAG(IS_CHROMEOS_ASH)) || (defined(OS_LINUX) && !defined(OS_ANDROID) && !defined(OS_CHROMEOS)) const char kAccountManagementFlowsV2Name[] = "Enable redesign of account management flows"; @@ -3671,6 +3671,12 @@ const char kAcceleratedMjpegDecodeDescri "Enable hardware-accelerated mjpeg decode for captured frame where " "available."; +#endif + +// Chrome OS ------------------------------------------------------------------- + +#if defined(OS_CHROMEOS) + const char kAllowDisableMouseAccelerationName[] = "Allow disabling mouse acceleration"; const char kAllowDisableMouseAccelerationDescription[] = Index: dev/chrome/browser/flag_descriptions.h =================================================================== --- dev.orig/chrome/browser/flag_descriptions.h +++ dev/chrome/browser/flag_descriptions.h @@ -2114,7 +2114,7 @@ extern const char kVideoToolboxVp9Decodi // Chrome OS ------------------------------------------------------------------ -#if BUILDFLAG(IS_CHROMEOS_ASH) +#if (BUILDFLAG(IS_CHROMEOS_ASH)) || (defined(OS_LINUX) && !defined(OS_ANDROID) && !defined(OS_CHROMEOS)) extern const char kAccountManagementFlowsV2Name[]; extern const char kAccountManagementFlowsV2Description[]; @@ -2122,6 +2122,12 @@ extern const char kAccountManagementFlow extern const char kAcceleratedMjpegDecodeName[]; extern const char kAcceleratedMjpegDecodeDescription[]; +#endif + +// Chrome OS ------------------------------------------------------------------ + +#if defined(OS_CHROMEOS) + extern const char kAllowDisableMouseAccelerationName[]; extern const char kAllowDisableMouseAccelerationDescription[]; Index: dev/content/gpu/BUILD.gn =================================================================== --- dev.orig/content/gpu/BUILD.gn +++ dev/content/gpu/BUILD.gn @@ -6,6 +6,7 @@ import("//build/config/chromeos/ui_mode. import("//build/config/ui.gni") import("//gpu/vulkan/features.gni") import("//media/media_options.gni") +import("//media/gpu/args.gni") # See //content/BUILD.gn for how this works. group("gpu") { @@ -140,4 +141,8 @@ target(link_target_type, "gpu_sources") (!is_chromecast || is_cast_desktop_build)) { configs += [ "//build/config/linux/dri" ] } + + if (is_linux && use_vaapi) { + public_configs = [ "//build/config/linux/libva" ] + } } Index: dev/media/gpu/gpu_video_decode_accelerator_factory.cc =================================================================== --- dev.orig/media/gpu/gpu_video_decode_accelerator_factory.cc +++ dev/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 decoder; decoder.reset(new VaapiVideoDecodeAccelerator(gl_client_.make_context_current, gl_client_.bind_image)); Index: dev/media/gpu/ipc/service/gpu_video_decode_accelerator.cc =================================================================== --- dev.orig/media/gpu/ipc/service/gpu_video_decode_accelerator.cc +++ dev/media/gpu/ipc/service/gpu_video_decode_accelerator.cc @@ -384,6 +384,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(); @@ -404,6 +405,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: dev/media/gpu/vaapi/vaapi_wrapper.cc =================================================================== --- dev.orig/media/gpu/vaapi/vaapi_wrapper.cc +++ dev/media/gpu/vaapi/vaapi_wrapper.cc @@ -520,6 +520,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() @@ -626,10 +631,6 @@ bool VADisplayState::InitializeVaDriver_ } 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 env(base::Environment::Create()); @@ -650,7 +651,6 @@ bool VADisplayState::InitializeOnce() { // 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; @@ -856,7 +856,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 << " for " + VLOG(1) << "Unsupported value " << required_attribs[i].value << " for " << vaConfigAttribTypeStr(required_attribs[i].type); return false; }