gl_switches.cc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ui/gl/gl_switches.h"
  5. #include "build/build_config.h"
  6. #include "ui/gl/gl_display_manager.h"
  7. #if BUILDFLAG(IS_ANDROID)
  8. #include "base/android/build_info.h"
  9. #endif
  10. namespace gl {
  11. const char kGLImplementationDesktopName[] = "desktop";
  12. const char kGLImplementationAppleName[] = "apple";
  13. const char kGLImplementationEGLName[] = "egl";
  14. const char kGLImplementationANGLEName[] = "angle";
  15. const char kGLImplementationMockName[] = "mock";
  16. const char kGLImplementationStubName[] = "stub";
  17. const char kGLImplementationDisabledName[] = "disabled";
  18. const char kANGLEImplementationDefaultName[] = "default";
  19. const char kANGLEImplementationD3D9Name[] = "d3d9";
  20. const char kANGLEImplementationD3D11Name[] = "d3d11";
  21. const char kANGLEImplementationD3D11on12Name[] = "d3d11on12";
  22. const char kANGLEImplementationOpenGLName[] = "gl";
  23. const char kANGLEImplementationOpenGLEGLName[] = "gl-egl";
  24. const char kANGLEImplementationOpenGLESName[] = "gles";
  25. const char kANGLEImplementationOpenGLESEGLName[] = "gles-egl";
  26. const char kANGLEImplementationNullName[] = "null";
  27. const char kANGLEImplementationVulkanName[] = "vulkan";
  28. const char kANGLEImplementationSwiftShaderName[] = "swiftshader";
  29. const char kANGLEImplementationSwiftShaderForWebGLName[] = "swiftshader-webgl";
  30. const char kANGLEImplementationMetalName[] = "metal";
  31. const char kANGLEImplementationNoneName[] = "";
  32. // Special switches for "NULL"/stub driver implementations.
  33. const char kANGLEImplementationD3D11NULLName[] = "d3d11-null";
  34. const char kANGLEImplementationOpenGLNULLName[] = "gl-null";
  35. const char kANGLEImplementationOpenGLESNULLName[] = "gles-null";
  36. const char kANGLEImplementationVulkanNULLName[] = "vulkan-null";
  37. const char kANGLEImplementationMetalNULLName[] = "metal-null";
  38. // The command decoder names that can be passed to --use-cmd-decoder.
  39. const char kCmdDecoderValidatingName[] = "validating";
  40. const char kCmdDecoderPassthroughName[] = "passthrough";
  41. // Swap chain formats for direct composition SDR video overlays.
  42. const char kSwapChainFormatNV12[] = "nv12";
  43. const char kSwapChainFormatYUY2[] = "yuy2";
  44. const char kSwapChainFormatBGRA[] = "bgra";
  45. } // namespace gl
  46. namespace switches {
  47. // Disables use of D3D11.
  48. const char kDisableD3D11[] = "disable-d3d11";
  49. // Disables use of ES3 backend (use ES2 backend instead).
  50. const char kDisableES3GLContext[] = "disable-es3-gl-context";
  51. // Disables use of ES3 backend at a lower level, for testing purposes.
  52. // This isn't guaranteed to work everywhere, so it's test-only.
  53. const char kDisableES3GLContextForTesting[] =
  54. "disable-es3-gl-context-for-testing";
  55. // Disable workarounds for various GPU driver bugs.
  56. const char kDisableGpuDriverBugWorkarounds[] =
  57. "disable-gpu-driver-bug-workarounds";
  58. // Stop the GPU from synchronizing presentation with vblank.
  59. const char kDisableGpuVsync[] = "disable-gpu-vsync";
  60. // Turns on GPU logging (debug build only).
  61. const char kEnableGPUServiceLogging[] = "enable-gpu-service-logging";
  62. // Turns on calling TRACE for every GL call.
  63. const char kEnableGPUServiceTracing[] = "enable-gpu-service-tracing";
  64. // Select which ANGLE backend to use. Options are:
  65. // default: Attempts several ANGLE renderers until one successfully
  66. // initializes, varying ES support by platform.
  67. // d3d9: Legacy D3D9 renderer, ES2 only.
  68. // d3d11: D3D11 renderer, ES2 and ES3.
  69. // warp: D3D11 renderer using software rasterization, ES2 and ES3.
  70. // gl: Desktop GL renderer, ES2 and ES3.
  71. // gles: GLES renderer, ES2 and ES3.
  72. const char kUseANGLE[] = "use-angle";
  73. // Use the Pass-through command decoder, skipping all validation and state
  74. // tracking. Switch lives in ui/gl because it affects the GL binding
  75. // initialization on platforms that would otherwise not default to using
  76. // EGL bindings.
  77. const char kUseCmdDecoder[] = "use-cmd-decoder";
  78. // ANGLE features are defined per-backend in third_party/angle/include/platform
  79. // Enables specified comma separated ANGLE features if found.
  80. const char kEnableANGLEFeatures[] = "enable-angle-features";
  81. // Disables specified comma separated ANGLE features if found.
  82. const char kDisableANGLEFeatures[] = "disable-angle-features";
  83. // Select which implementation of GL the GPU process should use. Options are:
  84. // desktop: whatever desktop OpenGL the user has installed (Linux and Mac
  85. // default).
  86. // egl: whatever EGL / GLES2 the user has installed (Windows default - actually
  87. // ANGLE).
  88. // swiftshader: The SwiftShader software renderer.
  89. const char kUseGL[] = "use-gl";
  90. // Inform Chrome that a GPU context will not be lost in power saving mode,
  91. // screen saving mode, etc. Note that this flag does not ensure that a GPU
  92. // context will never be lost in any situations, say, a GPU reset.
  93. const char kGpuNoContextLost[] = "gpu-no-context-lost";
  94. // Flag used for Linux tests: for desktop GL bindings, try to load this GL
  95. // library first, but fall back to regular library if loading fails.
  96. const char kTestGLLib[] = "test-gl-lib";
  97. // Use hardware gpu, if available, for tests.
  98. const char kUseGpuInTests[] = "use-gpu-in-tests";
  99. // Enable use of the SGI_video_sync extension, which can have
  100. // driver/sandbox/window manager compatibility issues.
  101. const char kEnableSgiVideoSync[] = "enable-sgi-video-sync";
  102. // Disables GL drawing operations which produce pixel output. With this
  103. // the GL output will not be correct but tests will run faster.
  104. const char kDisableGLDrawingForTests[] = "disable-gl-drawing-for-tests";
  105. // Forces the use of software GL instead of hardware gpu for tests.
  106. const char kOverrideUseSoftwareGLForTests[] =
  107. "override-use-software-gl-for-tests";
  108. // Disables specified comma separated GL Extensions if found.
  109. const char kDisableGLExtensions[] = "disable-gl-extensions";
  110. // Enables SwapBuffersWithBounds if it is supported.
  111. const char kEnableSwapBuffersWithBounds[] = "enable-swap-buffers-with-bounds";
  112. // Disables DirectComposition surface.
  113. const char kDisableDirectComposition[] = "disable-direct-composition";
  114. // Enables using DirectComposition video overlays, even if hardware overlays
  115. // aren't supported.
  116. const char kEnableDirectCompositionVideoOverlays[] =
  117. "enable-direct-composition-video-overlays";
  118. // Disables using DirectComposition video overlays, even if hardware overlays
  119. // are supported.
  120. const char kDisableDirectCompositionVideoOverlays[] =
  121. "disable-direct-composition-video-overlays";
  122. // Initialize the GPU process using the adapter with the specified LUID. This is
  123. // only used on Windows, as LUID is a Windows specific structure.
  124. const char kUseAdapterLuid[] = "use-adapter-luid";
  125. // Enable kDirectCompositionForceFullDamage feature regardless of overlay
  126. // support.
  127. const char kDirectCompositionForceFullDamageForTesting[] =
  128. "direct-composition-force-full-damage-for-testing";
  129. // Used for overriding the swap chain format for direct composition SDR video
  130. // overlays.
  131. const char kDirectCompositionVideoSwapChainFormat[] =
  132. "direct-composition-video-swap-chain-format";
  133. // This is the list of switches passed from this file that are passed from the
  134. // GpuProcessHost to the GPU Process. Add your switch to this list if you need
  135. // to read it in the GPU process, else don't add it.
  136. const char* const kGLSwitchesCopiedFromGpuProcessHost[] = {
  137. kDisableGpuDriverBugWorkarounds,
  138. kDisableGpuVsync,
  139. kDisableD3D11,
  140. kDisableES3GLContext,
  141. kDisableES3GLContextForTesting,
  142. kEnableGPUServiceLogging,
  143. kEnableGPUServiceTracing,
  144. kEnableSgiVideoSync,
  145. kGpuNoContextLost,
  146. kDisableGLDrawingForTests,
  147. kOverrideUseSoftwareGLForTests,
  148. kUseANGLE,
  149. kEnableSwapBuffersWithBounds,
  150. kDisableDirectComposition,
  151. kEnableDirectCompositionVideoOverlays,
  152. kDisableDirectCompositionVideoOverlays,
  153. kDirectCompositionForceFullDamageForTesting,
  154. kDirectCompositionVideoSwapChainFormat,
  155. };
  156. const int kGLSwitchesCopiedFromGpuProcessHostNumSwitches =
  157. std::size(kGLSwitchesCopiedFromGpuProcessHost);
  158. } // namespace switches
  159. namespace features {
  160. // Use BufferCount of 3 for the direct composition root swap chain.
  161. const base::Feature kDCompTripleBufferRootSwapChain{
  162. "DCompTripleBufferRootSwapChain", base::FEATURE_DISABLED_BY_DEFAULT};
  163. // Use BufferCount of 3 for direct composition video swap chains.
  164. const base::Feature kDCompTripleBufferVideoSwapChain{
  165. "DCompTripleBufferVideoSwapChain", base::FEATURE_DISABLED_BY_DEFAULT};
  166. // Forces Chrome's main backbuffer to full damage if the actual damage
  167. // is large enough and allows DWM to consider the main backbuffer as an
  168. // an overlay candidate.
  169. const base::Feature kDirectCompositionForceFullDamage{
  170. "DirectCompositionForceFullDamage", base::FEATURE_DISABLED_BY_DEFAULT};
  171. // Use presentation feedback event queries (must be enabled) to limit latency.
  172. const base::Feature kDirectCompositionLowLatencyPresentation{
  173. "DirectCompositionLowLatencyPresentation",
  174. base::FEATURE_DISABLED_BY_DEFAULT};
  175. // Allow overlay swapchain to present on all GPUs even if they only support
  176. // software overlays. GPU deny lists limit it to NVIDIA only at the moment.
  177. const base::Feature kDirectCompositionSoftwareOverlays{
  178. "DirectCompositionSoftwareOverlays", base::FEATURE_ENABLED_BY_DEFAULT};
  179. // TODO(crbug.com/1269749): This is used temporarily for verifying
  180. // the draw offset bug. The code should be removed once the bug is fixed.
  181. const base::Feature kDirectCompositionVerifyDrawOffset{
  182. "DirectCompositionVerifyDrawOffset", base::FEATURE_DISABLED_BY_DEFAULT};
  183. const base::FeatureParam<int> kVerifyDrawOffsetX{
  184. &kDirectCompositionVerifyDrawOffset, "verify_draw_offset_x", 0};
  185. const base::FeatureParam<int> kVerifyDrawOffsetY{
  186. &kDirectCompositionVerifyDrawOffset, "verify_draw_offset_y", 0};
  187. // Allow dual GPU rendering through EGL where supported, i.e., allow a WebGL
  188. // or WebGPU context to be on the high performance GPU if preferred and Chrome
  189. // internal rendering to be on the low power GPU.
  190. const base::Feature kEGLDualGpuRendering{"EGLDualGpuRendering",
  191. base::FEATURE_DISABLED_BY_DEFAULT};
  192. // Allow overlay swapchain to use Intel video processor for super resolution.
  193. const base::Feature kIntelVpSuperResolution{"IntelVpSuperResolution",
  194. base::FEATURE_DISABLED_BY_DEFAULT};
  195. // Default to using ANGLE's OpenGL backend
  196. const base::Feature kDefaultANGLEOpenGL{"DefaultANGLEOpenGL",
  197. base::FEATURE_DISABLED_BY_DEFAULT};
  198. // Default to using ANGLE's Metal backend.
  199. const base::Feature kDefaultANGLEMetal{"DefaultANGLEMetal",
  200. base::FEATURE_DISABLED_BY_DEFAULT};
  201. // Default to using ANGLE's Vulkan backend.
  202. const base::Feature kDefaultANGLEVulkan{"DefaultANGLEVulkan",
  203. base::FEATURE_DISABLED_BY_DEFAULT};
  204. // Track current program's shaders at glUseProgram() call for crash report
  205. // purpose. Only effective on Windows because the attached shaders may only
  206. // be reliably retrieved with ANGLE backend.
  207. const base::Feature kTrackCurrentShaders{"TrackCurrentShaders",
  208. base::FEATURE_DISABLED_BY_DEFAULT};
  209. // Enable sharing Vulkan device queue with ANGLE's Vulkan backend.
  210. const base::Feature kVulkanFromANGLE{"VulkanFromANGLE",
  211. base::FEATURE_DISABLED_BY_DEFAULT};
  212. bool IsDefaultANGLEVulkan() {
  213. #if BUILDFLAG(IS_ANDROID)
  214. // No support for devices before Q -- exit before checking feature flags
  215. // so that devices are not counted in finch trials.
  216. if (base::android::BuildInfo::GetInstance()->sdk_int() <
  217. base::android::SDK_VERSION_Q)
  218. return false;
  219. #endif // BUILDFLAG(IS_ANDROID)
  220. return base::FeatureList::IsEnabled(kDefaultANGLEVulkan);
  221. }
  222. // Use waitable swap chain on Windows to reduce display latency.
  223. const base::Feature kDXGIWaitableSwapChain{"DXGIWaitableSwapChain",
  224. base::FEATURE_DISABLED_BY_DEFAULT};
  225. // If using waitable swap chain, specify the maximum number of queued frames.
  226. const base::FeatureParam<int> kDXGIWaitableSwapChainMaxQueuedFrames{
  227. &kDXGIWaitableSwapChain, "DXGIWaitableSwapChainMaxQueuedFrames", 2};
  228. bool SupportsEGLDualGpuRendering() {
  229. #if defined(USE_EGL) && (BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC))
  230. gl::GLDisplayEGL* display_default =
  231. gl::GLDisplayManagerEGL::GetInstance()->GetDisplay(
  232. gl::GpuPreference::kDefault);
  233. DCHECK(display_default);
  234. gl::GLDisplayEGL* display_high_performance =
  235. gl::GLDisplayManagerEGL::GetInstance()->GetDisplay(
  236. gl::GpuPreference::kHighPerformance);
  237. if (!display_high_performance || display_default == display_high_performance)
  238. return false;
  239. return base::FeatureList::IsEnabled(kEGLDualGpuRendering);
  240. #else
  241. return false;
  242. #endif // USE_EGL && (IS_WIN || IS_MAC)
  243. }
  244. } // namespace features