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