James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 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 | |
| 5 | #include "base/command_line.h" |
| 6 | #include "base/logging.h" |
| 7 | #include "base/memory/scoped_ptr.h" |
| 8 | #include "gpu/config/gpu_control_list_jsons.h" |
| 9 | #include "gpu/config/gpu_driver_bug_list.h" |
| 10 | #include "gpu/config/gpu_driver_bug_workaround_type.h" |
| 11 | #include "gpu/config/gpu_info.h" |
| 12 | #include "testing/gtest/include/gtest/gtest.h" |
| 13 | |
| 14 | #define LONG_STRING_CONST(...) #__VA_ARGS__ |
| 15 | |
| 16 | namespace gpu { |
| 17 | |
| 18 | class GpuDriverBugListTest : public testing::Test { |
| 19 | public: |
| 20 | GpuDriverBugListTest() { } |
| 21 | |
James Robinson | 53b7758 | 2014-10-28 17:00:48 -0700 | [diff] [blame] | 22 | ~GpuDriverBugListTest() override {} |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 23 | |
| 24 | const GPUInfo& gpu_info() const { |
| 25 | return gpu_info_; |
| 26 | } |
| 27 | |
| 28 | protected: |
James Robinson | 53b7758 | 2014-10-28 17:00:48 -0700 | [diff] [blame] | 29 | void SetUp() override { |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 30 | gpu_info_.gpu.vendor_id = 0x10de; |
| 31 | gpu_info_.gpu.device_id = 0x0640; |
| 32 | gpu_info_.driver_vendor = "NVIDIA"; |
| 33 | gpu_info_.driver_version = "1.6.18"; |
| 34 | gpu_info_.driver_date = "7-14-2009"; |
| 35 | gpu_info_.machine_model_name = "MacBookPro"; |
| 36 | gpu_info_.machine_model_version = "7.1"; |
| 37 | gpu_info_.gl_vendor = "NVIDIA Corporation"; |
| 38 | gpu_info_.gl_renderer = "NVIDIA GeForce GT 120 OpenGL Engine"; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 39 | } |
| 40 | |
James Robinson | 53b7758 | 2014-10-28 17:00:48 -0700 | [diff] [blame] | 41 | void TearDown() override {} |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 42 | |
| 43 | private: |
| 44 | GPUInfo gpu_info_; |
| 45 | }; |
| 46 | |
| 47 | TEST_F(GpuDriverBugListTest, CurrentDriverBugListValidation) { |
| 48 | scoped_ptr<GpuDriverBugList> list(GpuDriverBugList::Create()); |
| 49 | std::string json; |
| 50 | EXPECT_TRUE(list->LoadList(kGpuDriverBugListJson, GpuControlList::kAllOs)); |
| 51 | } |
| 52 | |
| 53 | TEST_F(GpuDriverBugListTest, CurrentListForARM) { |
| 54 | scoped_ptr<GpuDriverBugList> list(GpuDriverBugList::Create()); |
| 55 | EXPECT_TRUE(list->LoadList(kGpuDriverBugListJson, GpuControlList::kAllOs)); |
| 56 | |
| 57 | GPUInfo gpu_info; |
| 58 | gpu_info.gl_vendor = "ARM"; |
| 59 | gpu_info.gl_renderer = "MALi_T604"; |
| 60 | std::set<int> bugs = list->MakeDecision( |
| 61 | GpuControlList::kOsAndroid, "4.1", gpu_info); |
| 62 | EXPECT_EQ(1u, bugs.count(USE_CLIENT_SIDE_ARRAYS_FOR_STREAM_BUFFERS)); |
| 63 | } |
| 64 | |
| 65 | TEST_F(GpuDriverBugListTest, CurrentListForImagination) { |
| 66 | scoped_ptr<GpuDriverBugList> list(GpuDriverBugList::Create()); |
| 67 | EXPECT_TRUE(list->LoadList(kGpuDriverBugListJson, GpuControlList::kAllOs)); |
| 68 | |
| 69 | GPUInfo gpu_info; |
| 70 | gpu_info.gl_vendor = "Imagination Technologies"; |
| 71 | gpu_info.gl_renderer = "PowerVR SGX 540"; |
| 72 | std::set<int> bugs = list->MakeDecision( |
| 73 | GpuControlList::kOsAndroid, "4.1", gpu_info); |
| 74 | EXPECT_EQ(1u, bugs.count(USE_CLIENT_SIDE_ARRAYS_FOR_STREAM_BUFFERS)); |
| 75 | } |
| 76 | |
| 77 | TEST_F(GpuDriverBugListTest, GpuSwitching) { |
| 78 | const std::string json = LONG_STRING_CONST( |
| 79 | { |
| 80 | "name": "gpu driver bug list", |
| 81 | "version": "0.1", |
| 82 | "entries": [ |
| 83 | { |
| 84 | "id": 1, |
| 85 | "os": { |
| 86 | "type": "macosx" |
| 87 | }, |
| 88 | "features": [ |
| 89 | "force_discrete_gpu" |
| 90 | ] |
| 91 | }, |
| 92 | { |
| 93 | "id": 2, |
| 94 | "os": { |
| 95 | "type": "win" |
| 96 | }, |
| 97 | "features": [ |
| 98 | "force_integrated_gpu" |
| 99 | ] |
| 100 | } |
| 101 | ] |
| 102 | } |
| 103 | ); |
| 104 | scoped_ptr<GpuDriverBugList> driver_bug_list(GpuDriverBugList::Create()); |
| 105 | EXPECT_TRUE(driver_bug_list->LoadList(json, GpuControlList::kAllOs)); |
| 106 | std::set<int> switching = driver_bug_list->MakeDecision( |
| 107 | GpuControlList::kOsMacosx, "10.8", gpu_info()); |
| 108 | EXPECT_EQ(1u, switching.size()); |
| 109 | EXPECT_EQ(1u, switching.count(FORCE_DISCRETE_GPU)); |
| 110 | std::vector<uint32> entries; |
| 111 | driver_bug_list->GetDecisionEntries(&entries, false); |
| 112 | ASSERT_EQ(1u, entries.size()); |
| 113 | EXPECT_EQ(1u, entries[0]); |
| 114 | |
| 115 | driver_bug_list.reset(GpuDriverBugList::Create()); |
| 116 | EXPECT_TRUE(driver_bug_list->LoadList(json, GpuControlList::kAllOs)); |
| 117 | switching = driver_bug_list->MakeDecision( |
| 118 | GpuControlList::kOsWin, "6.1", gpu_info()); |
| 119 | EXPECT_EQ(1u, switching.size()); |
| 120 | EXPECT_EQ(1u, switching.count(FORCE_INTEGRATED_GPU)); |
| 121 | driver_bug_list->GetDecisionEntries(&entries, false); |
| 122 | ASSERT_EQ(1u, entries.size()); |
| 123 | EXPECT_EQ(2u, entries[0]); |
| 124 | } |
| 125 | |
| 126 | TEST_F(GpuDriverBugListTest, AppendSingleWorkaround) { |
| 127 | base::CommandLine command_line(0, NULL); |
| 128 | command_line.AppendSwitch( |
| 129 | GpuDriverBugWorkaroundTypeToString(DISABLE_MULTISAMPLING)); |
| 130 | std::set<int> workarounds; |
| 131 | workarounds.insert(EXIT_ON_CONTEXT_LOST); |
| 132 | workarounds.insert(INIT_VERTEX_ATTRIBUTES); |
| 133 | EXPECT_EQ(2u, workarounds.size()); |
| 134 | GpuDriverBugList::AppendWorkaroundsFromCommandLine( |
| 135 | &workarounds, command_line); |
| 136 | EXPECT_EQ(3u, workarounds.size()); |
| 137 | EXPECT_EQ(1u, workarounds.count(DISABLE_MULTISAMPLING)); |
| 138 | } |
| 139 | |
| 140 | TEST_F(GpuDriverBugListTest, AppendForceGPUWorkaround) { |
| 141 | base::CommandLine command_line(0, NULL); |
| 142 | command_line.AppendSwitch( |
| 143 | GpuDriverBugWorkaroundTypeToString(FORCE_DISCRETE_GPU)); |
| 144 | std::set<int> workarounds; |
| 145 | workarounds.insert(EXIT_ON_CONTEXT_LOST); |
| 146 | workarounds.insert(FORCE_INTEGRATED_GPU); |
| 147 | EXPECT_EQ(2u, workarounds.size()); |
| 148 | EXPECT_EQ(1u, workarounds.count(FORCE_INTEGRATED_GPU)); |
| 149 | GpuDriverBugList::AppendWorkaroundsFromCommandLine( |
| 150 | &workarounds, command_line); |
| 151 | EXPECT_EQ(2u, workarounds.size()); |
| 152 | EXPECT_EQ(0u, workarounds.count(FORCE_INTEGRATED_GPU)); |
| 153 | EXPECT_EQ(1u, workarounds.count(FORCE_DISCRETE_GPU)); |
| 154 | } |
| 155 | |
| 156 | TEST_F(GpuDriverBugListTest, NVIDIANumberingScheme) { |
| 157 | const std::string json = LONG_STRING_CONST( |
| 158 | { |
| 159 | "name": "gpu driver bug list", |
| 160 | "version": "0.1", |
| 161 | "entries": [ |
| 162 | { |
| 163 | "id": 1, |
| 164 | "os": { |
| 165 | "type": "win" |
| 166 | }, |
| 167 | "vendor_id": "0x10de", |
| 168 | "driver_version": { |
| 169 | "op": "<=", |
| 170 | "value": "8.17.12.6973" |
| 171 | }, |
| 172 | "features": [ |
| 173 | "disable_d3d11" |
| 174 | ] |
| 175 | } |
| 176 | ] |
| 177 | } |
| 178 | ); |
| 179 | |
| 180 | scoped_ptr<GpuDriverBugList> list(GpuDriverBugList::Create()); |
| 181 | EXPECT_TRUE(list->LoadList(json, GpuControlList::kAllOs)); |
| 182 | |
| 183 | GPUInfo gpu_info; |
| 184 | gpu_info.gl_vendor = "NVIDIA"; |
| 185 | gpu_info.gl_renderer = "NVIDIA GeForce GT 120 OpenGL Engine"; |
| 186 | gpu_info.gpu.vendor_id = 0x10de; |
| 187 | gpu_info.gpu.device_id = 0x0640; |
| 188 | |
| 189 | // test the same driver version number |
| 190 | gpu_info.driver_version = "8.17.12.6973"; |
| 191 | std::set<int> bugs = list->MakeDecision( |
| 192 | GpuControlList::kOsWin, "7.0", gpu_info); |
| 193 | EXPECT_EQ(1u, bugs.count(DISABLE_D3D11)); |
| 194 | |
| 195 | // test a lower driver version number |
| 196 | gpu_info.driver_version = "8.15.11.8647"; |
| 197 | |
| 198 | bugs = list->MakeDecision(GpuControlList::kOsWin, "7.0", gpu_info); |
| 199 | EXPECT_EQ(1u, bugs.count(DISABLE_D3D11)); |
| 200 | |
| 201 | // test a higher driver version number |
| 202 | gpu_info.driver_version = "9.18.13.2723"; |
| 203 | bugs = list->MakeDecision(GpuControlList::kOsWin, "7.0", gpu_info); |
| 204 | EXPECT_EQ(0u, bugs.count(DISABLE_D3D11)); |
| 205 | } |
| 206 | |
| 207 | } // namespace gpu |
| 208 | |