gpu_preferences_unittest.cc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. // Copyright (c) 2017 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 <algorithm>
  5. #include <cstring>
  6. #include "base/command_line.h"
  7. #include "base/message_loop/message_pump_type.h"
  8. #include "build/build_config.h"
  9. #include "build/chromeos_buildflags.h"
  10. #include "gpu/config/gpu_switches.h"
  11. #include "gpu/ipc/common/gpu_preferences.mojom.h"
  12. #include "testing/gtest/include/gtest/gtest.h"
  13. namespace gpu {
  14. namespace {
  15. void CheckGpuPreferencesEqual(GpuPreferences left, GpuPreferences right) {
  16. EXPECT_EQ(left.disable_accelerated_video_decode,
  17. right.disable_accelerated_video_decode);
  18. EXPECT_EQ(left.disable_accelerated_video_encode,
  19. right.disable_accelerated_video_encode);
  20. EXPECT_EQ(left.gpu_startup_dialog, right.gpu_startup_dialog);
  21. EXPECT_EQ(left.disable_gpu_watchdog, right.disable_gpu_watchdog);
  22. EXPECT_EQ(left.gpu_sandbox_start_early, right.gpu_sandbox_start_early);
  23. EXPECT_EQ(left.enable_low_latency_dxva, right.enable_low_latency_dxva);
  24. EXPECT_EQ(left.enable_zero_copy_dxgi_video,
  25. right.enable_zero_copy_dxgi_video);
  26. EXPECT_EQ(left.enable_nv12_dxgi_video, right.enable_nv12_dxgi_video);
  27. EXPECT_EQ(left.enable_media_foundation_vea_on_windows7,
  28. right.enable_media_foundation_vea_on_windows7);
  29. EXPECT_EQ(left.disable_software_rasterizer,
  30. right.disable_software_rasterizer);
  31. EXPECT_EQ(left.log_gpu_control_list_decisions,
  32. right.log_gpu_control_list_decisions);
  33. EXPECT_EQ(left.compile_shader_always_succeeds,
  34. right.compile_shader_always_succeeds);
  35. EXPECT_EQ(left.disable_gl_error_limit, right.disable_gl_error_limit);
  36. EXPECT_EQ(left.disable_glsl_translator, right.disable_glsl_translator);
  37. EXPECT_EQ(left.disable_shader_name_hashing,
  38. right.disable_shader_name_hashing);
  39. EXPECT_EQ(left.enable_gpu_command_logging, right.enable_gpu_command_logging);
  40. EXPECT_EQ(left.enable_gpu_debugging, right.enable_gpu_debugging);
  41. EXPECT_EQ(left.enable_gpu_service_logging_gpu,
  42. right.enable_gpu_service_logging_gpu);
  43. EXPECT_EQ(left.enable_gpu_driver_debug_logging,
  44. right.enable_gpu_driver_debug_logging);
  45. EXPECT_EQ(left.disable_gpu_program_cache, right.disable_gpu_program_cache);
  46. EXPECT_EQ(left.enforce_gl_minimums, right.enforce_gl_minimums);
  47. EXPECT_EQ(left.force_gpu_mem_available_bytes,
  48. right.force_gpu_mem_available_bytes);
  49. EXPECT_EQ(left.force_gpu_mem_discardable_limit_bytes,
  50. right.force_gpu_mem_discardable_limit_bytes);
  51. EXPECT_EQ(left.gpu_program_cache_size, right.gpu_program_cache_size);
  52. EXPECT_EQ(left.disable_gpu_shader_disk_cache,
  53. right.disable_gpu_shader_disk_cache);
  54. EXPECT_EQ(left.enable_threaded_texture_mailboxes,
  55. right.enable_threaded_texture_mailboxes);
  56. EXPECT_EQ(left.gl_shader_interm_output, right.gl_shader_interm_output);
  57. EXPECT_EQ(left.enable_gpu_service_logging, right.enable_gpu_service_logging);
  58. EXPECT_EQ(left.enable_gpu_service_tracing, right.enable_gpu_service_tracing);
  59. EXPECT_EQ(left.use_passthrough_cmd_decoder,
  60. right.use_passthrough_cmd_decoder);
  61. EXPECT_EQ(left.disable_biplanar_gpu_memory_buffers_for_video_frames,
  62. right.disable_biplanar_gpu_memory_buffers_for_video_frames);
  63. EXPECT_EQ(left.texture_target_exception_list,
  64. right.texture_target_exception_list);
  65. EXPECT_EQ(left.ignore_gpu_blocklist, right.ignore_gpu_blocklist);
  66. EXPECT_EQ(left.watchdog_starts_backgrounded,
  67. right.watchdog_starts_backgrounded);
  68. EXPECT_EQ(left.gr_context_type, right.gr_context_type);
  69. EXPECT_EQ(left.use_vulkan, right.use_vulkan);
  70. EXPECT_EQ(left.enable_vulkan_protected_memory,
  71. right.enable_vulkan_protected_memory);
  72. EXPECT_EQ(left.vulkan_heap_memory_limit, right.vulkan_heap_memory_limit);
  73. EXPECT_EQ(left.vulkan_sync_cpu_memory_limit,
  74. right.vulkan_sync_cpu_memory_limit);
  75. EXPECT_EQ(left.enable_gpu_benchmarking_extension,
  76. right.enable_gpu_benchmarking_extension);
  77. EXPECT_EQ(left.enable_webgpu, right.enable_webgpu);
  78. EXPECT_EQ(left.enable_dawn_backend_validation,
  79. right.enable_dawn_backend_validation);
  80. EXPECT_EQ(left.enabled_dawn_features_list, right.enabled_dawn_features_list);
  81. EXPECT_EQ(left.disabled_dawn_features_list,
  82. right.disabled_dawn_features_list);
  83. EXPECT_EQ(left.enable_gpu_blocked_time_metric,
  84. right.enable_gpu_blocked_time_metric);
  85. EXPECT_EQ(left.enable_perf_data_collection,
  86. right.enable_perf_data_collection);
  87. #if defined(USE_OZONE)
  88. EXPECT_EQ(left.message_pump_type, right.message_pump_type);
  89. #endif
  90. EXPECT_EQ(left.enable_native_gpu_memory_buffers,
  91. right.enable_native_gpu_memory_buffers);
  92. #if BUILDFLAG(IS_CHROMEOS)
  93. EXPECT_EQ(left.enable_chromeos_direct_video_decoder,
  94. right.enable_chromeos_direct_video_decoder);
  95. #endif
  96. }
  97. } // namespace
  98. TEST(GpuPreferencesTest, EncodeDecode) {
  99. { // Testing default values.
  100. GpuPreferences input_prefs;
  101. GpuPreferences decoded_prefs;
  102. std::string encoded = input_prefs.ToSwitchValue();
  103. bool flag = decoded_prefs.FromSwitchValue(encoded);
  104. EXPECT_TRUE(flag);
  105. CheckGpuPreferencesEqual(input_prefs, decoded_prefs);
  106. }
  107. { // Change all fields to non default values.
  108. GpuPreferences input_prefs;
  109. GpuPreferences decoded_prefs;
  110. GpuPreferences default_prefs;
  111. mojom::GpuPreferences prefs_mojom;
  112. #define GPU_PREFERENCES_FIELD(name, value) \
  113. input_prefs.name = value; \
  114. EXPECT_NE(default_prefs.name, input_prefs.name); \
  115. prefs_mojom.name = value; \
  116. EXPECT_EQ(input_prefs.name, prefs_mojom.name);
  117. #define GPU_PREFERENCES_FIELD_ENUM(name, value, mojom_value) \
  118. input_prefs.name = value; \
  119. EXPECT_NE(default_prefs.name, input_prefs.name); \
  120. prefs_mojom.name = mojom_value; \
  121. EXPECT_EQ(static_cast<uint32_t>(input_prefs.name), \
  122. static_cast<uint32_t>(prefs_mojom.name));
  123. GPU_PREFERENCES_FIELD(disable_accelerated_video_decode, true)
  124. GPU_PREFERENCES_FIELD(disable_accelerated_video_encode, true)
  125. GPU_PREFERENCES_FIELD(gpu_startup_dialog, true)
  126. GPU_PREFERENCES_FIELD(disable_gpu_watchdog, true)
  127. GPU_PREFERENCES_FIELD(gpu_sandbox_start_early, true)
  128. GPU_PREFERENCES_FIELD(enable_low_latency_dxva, false)
  129. GPU_PREFERENCES_FIELD(enable_zero_copy_dxgi_video, true)
  130. GPU_PREFERENCES_FIELD(enable_nv12_dxgi_video, true)
  131. GPU_PREFERENCES_FIELD(enable_media_foundation_vea_on_windows7, true)
  132. GPU_PREFERENCES_FIELD(disable_software_rasterizer, true)
  133. GPU_PREFERENCES_FIELD(log_gpu_control_list_decisions, true)
  134. GPU_PREFERENCES_FIELD(compile_shader_always_succeeds, true)
  135. GPU_PREFERENCES_FIELD(disable_gl_error_limit, true)
  136. GPU_PREFERENCES_FIELD(disable_glsl_translator, true)
  137. GPU_PREFERENCES_FIELD(disable_shader_name_hashing, true)
  138. GPU_PREFERENCES_FIELD(enable_gpu_command_logging, true)
  139. GPU_PREFERENCES_FIELD(enable_gpu_debugging, true)
  140. GPU_PREFERENCES_FIELD(enable_gpu_service_logging_gpu, true)
  141. GPU_PREFERENCES_FIELD(enable_gpu_driver_debug_logging, true)
  142. GPU_PREFERENCES_FIELD(disable_gpu_program_cache, true)
  143. GPU_PREFERENCES_FIELD(enforce_gl_minimums, true)
  144. GPU_PREFERENCES_FIELD(force_gpu_mem_available_bytes, 4096)
  145. GPU_PREFERENCES_FIELD(force_gpu_mem_discardable_limit_bytes, 8092)
  146. GPU_PREFERENCES_FIELD(gpu_program_cache_size,
  147. kDefaultMaxProgramCacheMemoryBytes - 1)
  148. GPU_PREFERENCES_FIELD(disable_gpu_shader_disk_cache, true)
  149. GPU_PREFERENCES_FIELD(enable_threaded_texture_mailboxes, true)
  150. GPU_PREFERENCES_FIELD(gl_shader_interm_output, true)
  151. GPU_PREFERENCES_FIELD(enable_gpu_service_logging, true)
  152. GPU_PREFERENCES_FIELD(enable_gpu_service_tracing, true)
  153. GPU_PREFERENCES_FIELD(use_passthrough_cmd_decoder, true)
  154. GPU_PREFERENCES_FIELD(disable_biplanar_gpu_memory_buffers_for_video_frames,
  155. true)
  156. GPU_PREFERENCES_FIELD(ignore_gpu_blocklist, true)
  157. GPU_PREFERENCES_FIELD(watchdog_starts_backgrounded, true)
  158. GPU_PREFERENCES_FIELD_ENUM(gr_context_type, GrContextType::kVulkan,
  159. mojom::GrContextType::kVulkan)
  160. GPU_PREFERENCES_FIELD_ENUM(use_vulkan, VulkanImplementationName::kNative,
  161. mojom::VulkanImplementationName::kNative)
  162. GPU_PREFERENCES_FIELD(vulkan_heap_memory_limit, 1);
  163. GPU_PREFERENCES_FIELD(vulkan_sync_cpu_memory_limit, 1);
  164. GPU_PREFERENCES_FIELD(enable_gpu_benchmarking_extension, true)
  165. GPU_PREFERENCES_FIELD(enable_webgpu, true)
  166. GPU_PREFERENCES_FIELD_ENUM(enable_dawn_backend_validation,
  167. DawnBackendValidationLevel::kPartial,
  168. mojom::DawnBackendValidationLevel::kPartial)
  169. GPU_PREFERENCES_FIELD(enable_gpu_blocked_time_metric, true)
  170. GPU_PREFERENCES_FIELD(enable_perf_data_collection, true)
  171. #if defined(USE_OZONE)
  172. GPU_PREFERENCES_FIELD_ENUM(message_pump_type, base::MessagePumpType::UI,
  173. base::MessagePumpType::UI)
  174. #endif
  175. GPU_PREFERENCES_FIELD(enable_native_gpu_memory_buffers, true);
  176. #if BUILDFLAG(IS_CHROMEOS)
  177. GPU_PREFERENCES_FIELD(enable_chromeos_direct_video_decoder, true);
  178. #endif
  179. input_prefs.texture_target_exception_list.emplace_back(
  180. gfx::BufferUsage::SCANOUT, gfx::BufferFormat::RGBA_8888);
  181. input_prefs.texture_target_exception_list.emplace_back(
  182. gfx::BufferUsage::GPU_READ, gfx::BufferFormat::BGRA_8888);
  183. // Make sure every field is encoded/decoded.
  184. std::string encoded = input_prefs.ToSwitchValue();
  185. bool flag = decoded_prefs.FromSwitchValue(encoded);
  186. EXPECT_TRUE(flag);
  187. CheckGpuPreferencesEqual(input_prefs, decoded_prefs);
  188. }
  189. }
  190. // Helper test for decoding GPU preferences from a crash dump string.
  191. TEST(GpuPreferencesTest, DISABLED_DecodePreferences) {
  192. auto* command_line = base::CommandLine::ForCurrentProcess();
  193. if (!command_line->HasSwitch(switches::kGpuPreferences)) {
  194. LOG(ERROR) << "Please specify the preferences to decode via "
  195. << switches::kGpuPreferences;
  196. return;
  197. }
  198. const auto preferences =
  199. command_line->GetSwitchValueASCII(switches::kGpuPreferences);
  200. gpu::GpuPreferences gpu_preferences;
  201. if (!gpu_preferences.FromSwitchValue(preferences)) {
  202. LOG(ERROR) << "Failed to decode preferences: " << preferences;
  203. return;
  204. }
  205. printf("GpuPreferences = {\n");
  206. #define PRINT_BOOL(key) \
  207. printf(" %s: %s\n", #key, gpu_preferences.key ? "true" : "false")
  208. #define PRINT_INT(key) \
  209. printf(" %s: %d\n", #key, static_cast<uint32_t>(gpu_preferences.key))
  210. PRINT_BOOL(disable_accelerated_video_decode);
  211. PRINT_BOOL(disable_accelerated_video_encode);
  212. PRINT_BOOL(gpu_startup_dialog);
  213. PRINT_BOOL(disable_gpu_watchdog);
  214. PRINT_BOOL(gpu_sandbox_start_early);
  215. PRINT_BOOL(enable_low_latency_dxva);
  216. PRINT_BOOL(enable_zero_copy_dxgi_video);
  217. PRINT_BOOL(enable_nv12_dxgi_video);
  218. PRINT_BOOL(enable_media_foundation_vea_on_windows7);
  219. PRINT_BOOL(disable_software_rasterizer);
  220. PRINT_BOOL(log_gpu_control_list_decisions);
  221. PRINT_BOOL(compile_shader_always_succeeds);
  222. PRINT_BOOL(disable_gl_error_limit);
  223. PRINT_BOOL(disable_glsl_translator);
  224. PRINT_BOOL(disable_shader_name_hashing);
  225. PRINT_BOOL(enable_gpu_command_logging);
  226. PRINT_BOOL(enable_gpu_debugging);
  227. PRINT_BOOL(enable_gpu_service_logging_gpu);
  228. PRINT_BOOL(enable_gpu_driver_debug_logging);
  229. PRINT_BOOL(disable_gpu_program_cache);
  230. PRINT_BOOL(enforce_gl_minimums);
  231. PRINT_INT(force_gpu_mem_available_bytes);
  232. PRINT_INT(force_gpu_mem_discardable_limit_bytes);
  233. PRINT_INT(gpu_program_cache_size);
  234. PRINT_BOOL(disable_gpu_shader_disk_cache);
  235. PRINT_BOOL(enable_threaded_texture_mailboxes);
  236. PRINT_BOOL(gl_shader_interm_output);
  237. PRINT_BOOL(enable_gpu_service_logging);
  238. PRINT_BOOL(enable_gpu_service_tracing);
  239. PRINT_BOOL(use_passthrough_cmd_decoder);
  240. PRINT_BOOL(disable_biplanar_gpu_memory_buffers_for_video_frames);
  241. for (size_t i = 0; i < gpu_preferences.texture_target_exception_list.size();
  242. ++i) {
  243. PRINT_INT(texture_target_exception_list[i].usage);
  244. PRINT_INT(texture_target_exception_list[i].format);
  245. }
  246. PRINT_BOOL(ignore_gpu_blocklist);
  247. PRINT_BOOL(watchdog_starts_backgrounded);
  248. PRINT_INT(gr_context_type);
  249. PRINT_INT(use_vulkan);
  250. PRINT_INT(vulkan_heap_memory_limit);
  251. PRINT_INT(vulkan_sync_cpu_memory_limit);
  252. PRINT_BOOL(enable_gpu_benchmarking_extension);
  253. PRINT_BOOL(enable_webgpu);
  254. PRINT_INT(enable_dawn_backend_validation);
  255. PRINT_BOOL(enable_gpu_blocked_time_metric);
  256. PRINT_BOOL(enable_perf_data_collection);
  257. #if defined(USE_OZONE)
  258. PRINT_INT(message_pump_type);
  259. #endif
  260. PRINT_BOOL(enable_native_gpu_memory_buffers);
  261. #if BUILDFLAG(IS_CHROMEOS)
  262. PRINT_BOOL(enable_chromeos_direct_video_decoder);
  263. #endif
  264. printf("}\n");
  265. }
  266. } // namespace gpu