gpu_driver_bug_list_unittest.cc 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Copyright (c) 2013 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 "gpu/config/gpu_driver_bug_list.h"
  5. #include <vector>
  6. #include "base/command_line.h"
  7. #include "build/build_config.h"
  8. #include "gpu/config/gpu_driver_bug_workaround_type.h"
  9. #include "gpu/config/gpu_info.h"
  10. #include "testing/gtest/include/gtest/gtest.h"
  11. namespace gpu {
  12. class GpuDriverBugListTest : public testing::Test {
  13. public:
  14. GpuDriverBugListTest() = default;
  15. ~GpuDriverBugListTest() override = default;
  16. };
  17. #if BUILDFLAG(IS_ANDROID)
  18. TEST_F(GpuDriverBugListTest, CurrentListForARM) {
  19. std::unique_ptr<GpuDriverBugList> list = GpuDriverBugList::Create();
  20. GPUInfo gpu_info;
  21. gpu_info.gl_vendor = "ARM";
  22. gpu_info.gl_renderer = "MALi_T604";
  23. gpu_info.gl_version = "OpenGL ES 2.0";
  24. std::set<int> bugs = list->MakeDecision(
  25. GpuControlList::kOsAndroid, "4.1", gpu_info);
  26. EXPECT_EQ(1u, bugs.count(USE_CLIENT_SIDE_ARRAYS_FOR_STREAM_BUFFERS));
  27. }
  28. TEST_F(GpuDriverBugListTest, CurrentListForImagination) {
  29. std::unique_ptr<GpuDriverBugList> list = GpuDriverBugList::Create();
  30. GPUInfo gpu_info;
  31. gpu_info.gl_vendor = "Imagination Technologies";
  32. gpu_info.gl_renderer = "PowerVR SGX 540";
  33. gpu_info.gl_version = "OpenGL ES 2.0";
  34. std::set<int> bugs = list->MakeDecision(
  35. GpuControlList::kOsAndroid, "4.1", gpu_info);
  36. EXPECT_EQ(1u, bugs.count(USE_CLIENT_SIDE_ARRAYS_FOR_STREAM_BUFFERS));
  37. }
  38. #endif // BUILDFLAG(IS_ANDROID)
  39. TEST_F(GpuDriverBugListTest, AppendSingleWorkaround) {
  40. base::CommandLine command_line(0, nullptr);
  41. command_line.AppendSwitch(GpuDriverBugWorkaroundTypeToString(
  42. DISABLE_CHROMIUM_FRAMEBUFFER_MULTISAMPLE));
  43. std::set<int> workarounds;
  44. workarounds.insert(EXIT_ON_CONTEXT_LOST);
  45. workarounds.insert(INIT_VERTEX_ATTRIBUTES);
  46. EXPECT_EQ(2u, workarounds.size());
  47. GpuDriverBugList::AppendWorkaroundsFromCommandLine(
  48. &workarounds, command_line);
  49. EXPECT_EQ(3u, workarounds.size());
  50. EXPECT_EQ(1u, workarounds.count(DISABLE_CHROMIUM_FRAMEBUFFER_MULTISAMPLE));
  51. }
  52. TEST_F(GpuDriverBugListTest, AppendForceGPUWorkaround) {
  53. base::CommandLine command_line(0, nullptr);
  54. command_line.AppendSwitch(
  55. GpuDriverBugWorkaroundTypeToString(FORCE_HIGH_PERFORMANCE_GPU));
  56. std::set<int> workarounds;
  57. workarounds.insert(EXIT_ON_CONTEXT_LOST);
  58. workarounds.insert(FORCE_LOW_POWER_GPU);
  59. EXPECT_EQ(2u, workarounds.size());
  60. EXPECT_EQ(1u, workarounds.count(FORCE_LOW_POWER_GPU));
  61. GpuDriverBugList::AppendWorkaroundsFromCommandLine(
  62. &workarounds, command_line);
  63. EXPECT_EQ(2u, workarounds.size());
  64. EXPECT_EQ(0u, workarounds.count(FORCE_LOW_POWER_GPU));
  65. EXPECT_EQ(1u, workarounds.count(FORCE_HIGH_PERFORMANCE_GPU));
  66. }
  67. // Test for invariant "Assume the newly last added entry has the largest ID".
  68. // See GpuControlList::GpuControlList.
  69. // It checks gpu_driver_bug_list.json
  70. TEST_F(GpuDriverBugListTest, TestBlocklistIsValid) {
  71. std::unique_ptr<GpuDriverBugList> list(GpuDriverBugList::Create());
  72. auto max_entry_id = list->max_entry_id();
  73. std::vector<uint32_t> indices(list->num_entries());
  74. int current = 0;
  75. std::generate(indices.begin(), indices.end(),
  76. [&current] () { return current++; });
  77. auto entries = list->GetEntryIDsFromIndices(indices);
  78. auto real_max_entry_id = *std::max_element(entries.begin(), entries.end());
  79. EXPECT_EQ(real_max_entry_id, max_entry_id);
  80. }
  81. } // namespace gpu