only-fall-back-to-the-i965-driver-if-we-re-on-iHD.patch 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. From fbd756ab55f9351165f923b0411c31dd71319c78 Mon Sep 17 00:00:00 2001
  2. From: Ted Meyer <tmathmeyer@chromium.org>
  3. Date: Wed, 16 Sep 2020 17:42:03 +0000
  4. Subject: [PATCH] Only fall back to the i965 driver if we're on iHD
  5. I got my hands on an old AMD laptop, and the gallium driver worked very
  6. well and was saving power even at 720p, so there's no reason to block
  7. that for now.
  8. Bug: 1116703
  9. Change-Id: Ib15bc2b93f33e99adad7569dd825e167b503a0ea
  10. Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2409967
  11. Commit-Queue: Ted Meyer <tmathmeyer@chromium.org>
  12. Reviewed-by: Andres Calderon Jaramillo <andrescj@chromium.org>
  13. Cr-Commit-Position: refs/heads/master@{#807550}
  14. ---
  15. media/gpu/vaapi/vaapi_wrapper.cc | 73 ++++++++++++++++++++------------
  16. 1 file changed, 47 insertions(+), 26 deletions(-)
  17. diff --git a/media/gpu/vaapi/vaapi_wrapper.cc b/media/gpu/vaapi/vaapi_wrapper.cc
  18. index 2ad0b997e56..e30d1dfb73b 100644
  19. --- a/media/gpu/vaapi/vaapi_wrapper.cc
  20. +++ b/media/gpu/vaapi/vaapi_wrapper.cc
  21. @@ -409,6 +409,8 @@ class VADisplayState {
  22. // Implementation of Initialize() called only once.
  23. bool InitializeOnce() EXCLUSIVE_LOCKS_REQUIRED(va_lock_);
  24. + bool InitializeVaDisplay_Locked() EXCLUSIVE_LOCKS_REQUIRED(va_lock_);
  25. + bool InitializeVaDriver_Locked() EXCLUSIVE_LOCKS_REQUIRED(va_lock_);
  26. int refcount_ GUARDED_BY(va_lock_);
  27. @@ -472,11 +474,7 @@ bool VADisplayState::Initialize() {
  28. return success;
  29. }
  30. -bool VADisplayState::InitializeOnce() {
  31. - static_assert(
  32. - VA_MAJOR_VERSION >= 2 || (VA_MAJOR_VERSION == 1 && VA_MINOR_VERSION >= 1),
  33. - "Requires VA-API >= 1.1.0");
  34. -
  35. +bool VADisplayState::InitializeVaDisplay_Locked() {
  36. switch (gl::GetGLImplementation()) {
  37. case gl::kGLImplementationEGLGLES2:
  38. va_display_ = vaGetDisplayDRM(drm_fd_.get());
  39. @@ -519,25 +517,10 @@ bool VADisplayState::InitializeOnce() {
  40. return false;
  41. }
  42. - // Set VA logging level and driver name, unless already set.
  43. - constexpr char libva_log_level_env[] = "LIBVA_MESSAGING_LEVEL";
  44. - std::unique_ptr<base::Environment> env(base::Environment::Create());
  45. - if (!env->HasVar(libva_log_level_env))
  46. - env->SetVar(libva_log_level_env, "1");
  47. -
  48. -#if defined(USE_X11)
  49. - if (gl::GetGLImplementation() == gl::kGLImplementationEGLANGLE) {
  50. - DCHECK(!features::IsUsingOzonePlatform());
  51. - constexpr char libva_driver_impl_env[] = "LIBVA_DRIVER_NAME";
  52. - // TODO(crbug/1116703) The libva intel-media driver has a known segfault in
  53. - // vaPutSurface, so until this is fixed, fall back to the i965 driver. There
  54. - // is discussion of the issue here:
  55. - // https://github.com/intel/media-driver/issues/818
  56. - if (!env->HasVar(libva_driver_impl_env))
  57. - env->SetVar(libva_driver_impl_env, "i965");
  58. - }
  59. -#endif // USE_X11
  60. + return true;
  61. +}
  62. +bool VADisplayState::InitializeVaDriver_Locked() {
  63. // The VAAPI version.
  64. int major_version, minor_version;
  65. VAStatus va_res = vaInitialize(va_display_, &major_version, &minor_version);
  66. @@ -545,9 +528,6 @@ bool VADisplayState::InitializeOnce() {
  67. LOG(ERROR) << "vaInitialize failed: " << vaErrorStr(va_res);
  68. return false;
  69. }
  70. -
  71. - va_initialized_ = true;
  72. -
  73. const std::string va_vendor_string = vaQueryVendorString(va_display_);
  74. DLOG_IF(WARNING, va_vendor_string.empty())
  75. << "Vendor string empty or error reading.";
  76. @@ -555,6 +535,8 @@ bool VADisplayState::InitializeOnce() {
  77. << va_vendor_string;
  78. implementation_type_ = VendorStringToImplementationType(va_vendor_string);
  79. + va_initialized_ = true;
  80. +
  81. // The VAAPI version is determined from what is loaded on the system by
  82. // calling vaInitialize(). Since the libva is now ABI-compatible, relax the
  83. // version check which helps in upgrading the libva, without breaking any
  84. @@ -571,6 +553,45 @@ bool VADisplayState::InitializeOnce() {
  85. return true;
  86. }
  87. +bool VADisplayState::InitializeOnce() {
  88. + static_assert(
  89. + VA_MAJOR_VERSION >= 2 || (VA_MAJOR_VERSION == 1 && VA_MINOR_VERSION >= 1),
  90. + "Requires VA-API >= 1.1.0");
  91. +
  92. + // Set VA logging level, unless already set.
  93. + constexpr char libva_log_level_env[] = "LIBVA_MESSAGING_LEVEL";
  94. + std::unique_ptr<base::Environment> env(base::Environment::Create());
  95. + if (!env->HasVar(libva_log_level_env))
  96. + env->SetVar(libva_log_level_env, "1");
  97. +
  98. + if (!InitializeVaDisplay_Locked() || !InitializeVaDriver_Locked())
  99. + return false;
  100. +
  101. +#if defined(USE_X11)
  102. + if (gl::GetGLImplementation() == gl::kGLImplementationEGLANGLE &&
  103. + implementation_type_ == VAImplementation::kIntelIHD) {
  104. + DCHECK(!features::IsUsingOzonePlatform());
  105. + constexpr char libva_driver_impl_env[] = "LIBVA_DRIVER_NAME";
  106. + // TODO(crbug/1116703) The libva intel-media driver has a known segfault in
  107. + // vaPutSurface, so until this is fixed, fall back to the i965 driver. There
  108. + // is discussion of the issue here:
  109. + // https://github.com/intel/media-driver/issues/818
  110. + if (!env->HasVar(libva_driver_impl_env))
  111. + env->SetVar(libva_driver_impl_env, "i965");
  112. +
  113. + // Re-initialize with the new driver.
  114. + va_display_ = nullptr;
  115. + va_initialized_ = false;
  116. + implementation_type_ = VAImplementation::kInvalid;
  117. +
  118. + if (!InitializeVaDisplay_Locked() || !InitializeVaDriver_Locked())
  119. + return false;
  120. + }
  121. +#endif // USE_X11
  122. +
  123. + return true;
  124. +}
  125. +
  126. VAStatus VADisplayState::Deinitialize() {
  127. base::AutoLock auto_lock(va_lock_);
  128. VAStatus va_res = VA_STATUS_SUCCESS;