1 // Copyright 2016 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 5 #ifndef GPU_CONFIG_GPU_PREFERENCES_H_ 6 #define GPU_CONFIG_GPU_PREFERENCES_H_ 7 8 #include <stddef.h> 9 #include <string> 10 #include <vector> 11 12 #include "base/macros.h" 13 #include "build/build_config.h" 14 #include "build/chromeos_buildflags.h" 15 #include "gpu/gpu_export.h" 16 #include "media/media_buildflags.h" 17 #include "ui/gfx/buffer_types.h" 18 19 #if defined(USE_OZONE) 20 #include "base/message_loop/message_pump_type.h" 21 #endif 22 23 namespace gpu { 24 25 // The size to set for the program cache for default and low-end device cases. 26 #if !defined(OS_ANDROID) 27 const size_t kDefaultMaxProgramCacheMemoryBytes = 6 * 1024 * 1024; 28 #else 29 const size_t kDefaultMaxProgramCacheMemoryBytes = 2 * 1024 * 1024; 30 const size_t kLowEndMaxProgramCacheMemoryBytes = 128 * 1024; 31 #endif 32 33 enum class VulkanImplementationName : uint32_t { 34 kNone = 0, 35 kNative = 1, 36 kForcedNative = 2, // Cannot be overridden by GPU blocklist. 37 kSwiftshader = 3, 38 kLast = kSwiftshader, 39 }; 40 41 enum class GrContextType : uint32_t { 42 kGL = 0, 43 kVulkan = 1, 44 kMetal = 2, 45 kDawn = 3, 46 kLast = kDawn, 47 }; 48 49 // NOTE: if you modify this structure then you must also modify the 50 // following two files to keep them in sync: 51 // src/gpu/ipc/common/gpu_preferences.mojom 52 // src/gpu/ipc/common/gpu_preferences_mojom_traits.h 53 struct GPU_EXPORT GpuPreferences { 54 public: 55 GpuPreferences(); 56 57 GpuPreferences(const GpuPreferences& other); 58 59 ~GpuPreferences(); 60 61 // Encode struct into a string so it can be passed as a commandline switch. 62 std::string ToSwitchValue(); 63 64 // Decode the encoded string back to GpuPrefences struct. 65 // If return false, |this| won't be touched. 66 bool FromSwitchValue(const std::string& data); 67 68 // =================================== 69 // Settings from //content/public/common/content_switches.h 70 71 // Disables hardware acceleration of video decode, where available. 72 bool disable_accelerated_video_decode = false; 73 74 // Disables hardware acceleration of video decode, where available. 75 bool disable_accelerated_video_encode = false; 76 77 // Causes the GPU process to display a dialog on launch. 78 bool gpu_startup_dialog = false; 79 80 // Disable the thread that crashes the GPU process if it stops responding to 81 // messages. 82 bool disable_gpu_watchdog = false; 83 84 // Starts the GPU sandbox before creating a GL context. 85 bool gpu_sandbox_start_early = false; 86 87 // Enables using CODECAPI_AVLowLatencyMode. Windows only. 88 bool enable_low_latency_dxva = true; 89 90 // Enables support for avoiding copying DXGI NV12 textures. Windows only. 91 bool enable_zero_copy_dxgi_video = false; 92 93 // Enables support for outputting NV12 video frames. Windows only. 94 bool enable_nv12_dxgi_video = false; 95 96 // Enables MediaFoundationVideoEncoderAccelerator on Windows 7. Windows 7 does 97 // not support some of the attributes which may impact the performance or the 98 // quality of output. So this flag is disabled by default. Windows only. 99 bool enable_media_foundation_vea_on_windows7 = false; 100 101 // Disables the use of a 3D software rasterizer, for example, SwiftShader. 102 bool disable_software_rasterizer = false; 103 104 bool log_gpu_control_list_decisions = false; 105 106 // =================================== 107 // Settings from //gpu/command_buffer/service/gpu_switches.cc 108 109 // Always return success when compiling a shader. Linking will still fail. 110 bool compile_shader_always_succeeds = false; 111 112 // Disable the GL error log limit. 113 bool disable_gl_error_limit = false; 114 115 // Disable the GLSL translator. 116 bool disable_glsl_translator = false; 117 118 // Turn off user-defined name hashing in shaders. 119 bool disable_shader_name_hashing = false; 120 121 // Turn on Logging GPU commands. 122 bool enable_gpu_command_logging = false; 123 124 // Turn on Calling GL Error after every command. 125 bool enable_gpu_debugging = false; 126 127 // Enable GPU service logging. 128 bool enable_gpu_service_logging_gpu = false; 129 130 // Enable logging of GPU driver debug messages. 131 bool enable_gpu_driver_debug_logging = false; 132 133 // Turn off gpu program caching 134 bool disable_gpu_program_cache = false; 135 136 // Enforce GL minimums. 137 bool enforce_gl_minimums = false; 138 139 // Sets the total amount of memory that may be allocated for GPU resources. 140 uint32_t force_gpu_mem_available_bytes = 0u; 141 142 // Sets the maximum discardable cache size limit for GPU resources. 143 uint32_t force_gpu_mem_discardable_limit_bytes = 0u; 144 145 // Sets maximum texture size. 146 uint32_t force_max_texture_size = 0u; 147 148 // Sets the maximum size of the in-memory gpu program cache, in kb 149 uint32_t gpu_program_cache_size = kDefaultMaxProgramCacheMemoryBytes; 150 151 // Disables the GPU shader on disk cache. 152 bool disable_gpu_shader_disk_cache = false; 153 154 // Simulates shared textures when share groups are not available. 155 // Not available everywhere. 156 bool enable_threaded_texture_mailboxes = false; 157 158 // Include ANGLE's intermediate representation (AST) output in shader 159 // compilation info logs. 160 bool gl_shader_interm_output = false; 161 162 // Emulate ESSL lowp and mediump float precisions by mutating the shaders to 163 // round intermediate values in ANGLE. 164 bool emulate_shader_precision = false; 165 166 // =================================== 167 // Settings from //gpu/config/gpu_switches.h 168 169 // Enables the use of SurfaceControl for overlays on Android. 170 bool enable_android_surface_control = false; 171 172 // =================================== 173 // Settings from //ui/gl/gl_switches.h 174 175 // Turns on GPU logging (debug build only). 176 bool enable_gpu_service_logging = false; 177 178 // Turns on calling TRACE for every GL call. 179 bool enable_gpu_service_tracing = false; 180 181 // Use the Pass-through command decoder, skipping all validation and state 182 // tracking. 183 bool use_passthrough_cmd_decoder = false; 184 185 // Disable using a single multiplanar GpuMemoryBuffer to store biplanar 186 // VideoFrames (e.g. NV12), see https://crbug.com/791676. 187 bool disable_biplanar_gpu_memory_buffers_for_video_frames = false; 188 189 // List of texture usage & formats that require use of a platform specific 190 // texture target. 191 std::vector<gfx::BufferUsageAndFormat> texture_target_exception_list; 192 193 // =================================== 194 // Settings from //gpu/config/gpu_switches.h 195 196 // Ignores GPU blocklist. 197 bool ignore_gpu_blocklist = false; 198 199 // Oop rasterization preferences in the GPU process. disable wins over 200 // enable, and neither means use defaults from GpuFeatureInfo. 201 bool enable_oop_rasterization = false; 202 bool disable_oop_rasterization = false; 203 204 bool enable_oop_rasterization_ddl = false; 205 206 // Start the watchdog suspended, as the app is already backgrounded and won't 207 // send a background/suspend signal. 208 bool watchdog_starts_backgrounded = false; 209 210 // =================================== 211 // Settings from //gpu/command_buffer/service/gpu_switches.h 212 // The type of the GrContext. 213 GrContextType gr_context_type = GrContextType::kGL; 214 215 // Use Vulkan for rasterization and display compositing. 216 VulkanImplementationName use_vulkan = VulkanImplementationName::kNone; 217 218 // Enable using vulkan protected memory. 219 bool enable_vulkan_protected_memory = false; 220 221 // Enforce using vulkan protected memory. 222 bool enforce_vulkan_protected_memory = false; 223 224 // Use vulkan VK_KHR_surface for presenting. 225 bool disable_vulkan_surface = false; 226 227 // If Vulkan initialization has failed, do not fallback to GL. This is for 228 // testing in order to detect regressions which crash Vulkan. 229 bool disable_vulkan_fallback_to_gl_for_testing = false; 230 231 // Heap memory limit for Vulkan. Allocations will fail when this limit is 232 // reached for a heap. 233 uint32_t vulkan_heap_memory_limit = 0u; 234 235 // Sync CPU memory limit for Vulkan. Submission of GPU work will be 236 // synchronize with the CPU in order to free released memory immediately 237 // when this limit is reached. 238 uint32_t vulkan_sync_cpu_memory_limit = 0u; 239 240 // Use Metal for rasterization and Skia-based display compositing. Note that 241 // this is compatible with GL-based display compositing. 242 bool enable_metal = false; 243 244 // =================================== 245 // Settings from //cc/base/switches.h 246 // Enable the GPU benchmarking extension; used by tests only. 247 bool enable_gpu_benchmarking_extension = false; 248 249 // Enable the WebGPU command buffer. 250 bool enable_webgpu = false; 251 252 // Enable validation layers in Dawn backends. 253 bool enable_dawn_backend_validation = false; 254 255 // Enable the toggle Toggle::DisableRobustness when creating Dawn device for 256 // the investigation of the performance issues related to the implementation 257 // of robustness in Dawn. 258 bool disable_dawn_robustness = false; 259 260 // Enable measuring blocked time on GPU Main thread 261 bool enable_gpu_blocked_time_metric = false; 262 263 // Enable collecting perf data for device categorization purpose. Currently 264 // only enabled on Windows platform for the info collection GPU process. 265 bool enable_perf_data_collection = false; 266 267 #if defined(USE_OZONE) 268 // Determines message pump type for the GPU thread. 269 base::MessagePumpType message_pump_type = base::MessagePumpType::DEFAULT; 270 #endif 271 272 // =================================== 273 // Settings from //ui/gfx/switches.h 274 275 // Enable native CPU-mappable GPU memory buffer support on Linux. 276 bool enable_native_gpu_memory_buffers = false; 277 278 // =================================== 279 // Settings from //media/base/media_switches.h 280 281 #if BUILDFLAG(IS_ASH) 282 // The direct VideoDecoder is disallowed in this particular SoC/platform. This 283 // flag is a reflection of whatever ChromeOS command line builder says. 284 bool platform_disallows_chromeos_direct_video_decoder = false; 285 #endif 286 287 // Disables oppr debug crash dumps. 288 bool disable_oopr_debug_crash_dump = false; 289 290 // Please update gpu_preferences_unittest.cc when making additions or 291 // changes to this struct. 292 }; 293 294 } // namespace gpu 295 296 #endif // GPU_CONFIG_GPU_PREFERENCES_H_ 297