| Flutter Impeller |

driver_info_vk_unittests.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter 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 "impeller/playground/playground_test.h"
6 #include "impeller/renderer/backend/vulkan/context_vk.h"
7 #include "impeller/renderer/backend/vulkan/driver_info_vk.h"
8 #include "impeller/renderer/backend/vulkan/surface_context_vk.h"
9 #include "impeller/renderer/backend/vulkan/test/mock_vulkan.h"
10
11 namespace impeller::testing {
12
13 using DriverInfoVKTest = PlaygroundTest;
14 INSTANTIATE_VULKAN_PLAYGROUND_SUITE(DriverInfoVKTest);
15
16 TEST_P(DriverInfoVKTest, CanQueryDriverInfo) {
17 ASSERT_TRUE(GetContext());
18 const auto& driver_info =
19 SurfaceContextVK::Cast(*GetContext()).GetParent()->GetDriverInfo();
20 ASSERT_NE(driver_info, nullptr);
21 // 1.1 is the base Impeller version. The driver can't be lower than that.
22 ASSERT_TRUE(driver_info->GetAPIVersion().IsAtLeast(Version{1, 1, 0}));
23 ASSERT_NE(driver_info->GetVendor(), VendorVK::kUnknown);
24 ASSERT_NE(driver_info->GetDeviceType(), DeviceTypeVK::kUnknown);
25 ASSERT_NE(driver_info->GetDriverName(), "");
26 EXPECT_FALSE(driver_info->IsKnownBadDriver());
27 }
28
29 TEST_P(DriverInfoVKTest, CanDumpToLog) {
30 ASSERT_TRUE(GetContext());
31 const auto& driver_info =
32 SurfaceContextVK::Cast(*GetContext()).GetParent()->GetDriverInfo();
33 ASSERT_NE(driver_info, nullptr);
34 fml::testing::LogCapture log;
35 driver_info->DumpToLog();
36 EXPECT_TRUE(log.str().find("Driver Information") != std::string::npos);
37 }
38
39 TEST(DriverInfoVKTest, CanIdentifyBadMaleoonDriver) {
40 auto const context =
41 MockVulkanContextBuilder()
42 .SetPhysicalPropertiesCallback(
43 [](VkPhysicalDevice device, VkPhysicalDeviceProperties* prop) {
44 prop->vendorID = 0x19E5; // Huawei
45 prop->deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU;
46 })
47 .Build();
48
49 EXPECT_TRUE(context->GetDriverInfo()->IsKnownBadDriver());
50 }
51
52 bool IsBadVersionTest(std::string_view driver_name, bool qc = true) {
53 auto const context =
54 MockVulkanContextBuilder()
55 .SetPhysicalPropertiesCallback(
56 [&driver_name, qc](VkPhysicalDevice device,
57 VkPhysicalDeviceProperties* prop) {
58 if (qc) {
59 prop->vendorID = 0x168C; // Qualcomm
60 } else {
61 prop->vendorID = 0x13B5; // ARM
62 }
63 driver_name.copy(prop->deviceName, driver_name.size());
64 prop->deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU;
65 })
66 .Build();
67 return context->GetDriverInfo()->IsKnownBadDriver();
68 }
69
70 bool CanBatchSubmitTest(std::string_view driver_name, bool qc = true) {
71 auto const context =
72 MockVulkanContextBuilder()
73 .SetPhysicalPropertiesCallback(
74 [&driver_name, qc](VkPhysicalDevice device,
75 VkPhysicalDeviceProperties* prop) {
76 if (qc) {
77 prop->vendorID = 0x168C; // Qualcomm
78 } else {
79 prop->vendorID = 0x13B5; // ARM
80 }
81 driver_name.copy(prop->deviceName, driver_name.size());
82 prop->deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU;
83 })
84 .Build();
85 return !GetWorkaroundsFromDriverInfo(*context->GetDriverInfo())
86 .batch_submit_command_buffer_timeout;
87 }
88
89 TEST(DriverInfoVKTest, CanBatchSubmitCommandBuffers) {
90 // Old Adreno no batch submit!
91 EXPECT_FALSE(CanBatchSubmitTest("Adreno (TM) 540", true));
92
93 EXPECT_TRUE(CanBatchSubmitTest("Mali-G51", false));
94 EXPECT_TRUE(CanBatchSubmitTest("Adreno (TM) 750", true));
95 }
96
97 bool CanUsePrimitiveRestartSubmitTest(std::string_view driver_name,
98 bool qc = true) {
99 auto const context =
100 MockVulkanContextBuilder()
101 .SetPhysicalPropertiesCallback(
102 [&driver_name, qc](VkPhysicalDevice device,
103 VkPhysicalDeviceProperties* prop) {
104 if (qc) {
105 prop->vendorID = 0x168C; // Qualcomm
106 } else {
107 prop->vendorID = 0x13B5; // ARM
108 }
109 driver_name.copy(prop->deviceName, driver_name.size());
110 prop->deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU;
111 })
112 .Build();
113 return !GetWorkaroundsFromDriverInfo(*context->GetDriverInfo())
114 .slow_primitive_restart_performance;
115 }
116
117 TEST(DriverInfoVKTest, CanUsePrimitiveRestart) {
118 // Adreno no primitive restart
119 EXPECT_FALSE(CanUsePrimitiveRestartSubmitTest("Adreno (TM) 540", true));
120 EXPECT_FALSE(CanUsePrimitiveRestartSubmitTest("Adreno (TM) 750", true));
121
122 // Mali A-OK
123 EXPECT_TRUE(CanUsePrimitiveRestartSubmitTest("Mali-G51", false));
124 }
125
126 bool CanUseMipgeneration(std::string_view driver_name, bool qc = true) {
127 auto const context =
128 MockVulkanContextBuilder()
129 .SetPhysicalPropertiesCallback(
130 [&driver_name, qc](VkPhysicalDevice device,
131 VkPhysicalDeviceProperties* prop) {
132 if (qc) {
133 prop->vendorID = 0x168C; // Qualcomm
134 } else {
135 prop->vendorID = 0x13B5; // ARM
136 }
137 driver_name.copy(prop->deviceName, driver_name.size());
138 prop->deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU;
139 })
140 .Build();
141 return !GetWorkaroundsFromDriverInfo(*context->GetDriverInfo())
142 .broken_mipmap_generation;
143 }
144
145 TEST(DriverInfoVKTest, CanGenerateMipMaps) {
146 // Adreno no mips
147 EXPECT_FALSE(CanUseMipgeneration("Adreno (TM) 540", true));
148 EXPECT_FALSE(CanUseMipgeneration("Adreno (TM) 750", true));
149
150 // Mali A-OK
151 EXPECT_TRUE(CanUseMipgeneration("Mali-G51", false));
152 }
153
154 TEST(DriverInfoVKTest, DriverParsingMali) {
155 EXPECT_EQ(GetMaliVersion("Mali-G51-MORE STUFF"), MaliGPU::kG51);
156 EXPECT_EQ(GetMaliVersion("Mali-G51"), MaliGPU::kG51);
157 EXPECT_EQ(GetMaliVersion("Mali-111111"), MaliGPU::kUnknown);
158 }
159
160 TEST(DriverInfoVKTest, DriverParsingAdreno) {
161 EXPECT_EQ(GetAdrenoVersion("Adreno (TM) 540"), AdrenoGPU::kAdreno540);
162 EXPECT_EQ(GetAdrenoVersion("Foo Bar"), AdrenoGPU::kUnknown);
163 }
164
165 TEST(DriverInfoVKTest, DisabledDevices) {
166 EXPECT_FALSE(IsBadVersionTest("Adreno (TM) 620"));
167 EXPECT_FALSE(IsBadVersionTest("Adreno (TM) 610"));
168 EXPECT_FALSE(IsBadVersionTest("Adreno (TM) 530"));
169 EXPECT_FALSE(IsBadVersionTest("Adreno (TM) 512"));
170 EXPECT_FALSE(IsBadVersionTest("Adreno (TM) 509"));
171 EXPECT_FALSE(IsBadVersionTest("Adreno (TM) 508"));
172 EXPECT_FALSE(IsBadVersionTest("Adreno (TM) 506"));
173 EXPECT_FALSE(IsBadVersionTest("Adreno (TM) 505"));
174 EXPECT_FALSE(IsBadVersionTest("Adreno (TM) 504"));
175 EXPECT_FALSE(IsBadVersionTest("Adreno (TM) 630"));
176 EXPECT_FALSE(IsBadVersionTest("Adreno (TM) 640"));
177 EXPECT_FALSE(IsBadVersionTest("Adreno (TM) 650"));
178 }
179
180 TEST(DriverInfoVKTest, EnabledDevicesMali) {
181 EXPECT_FALSE(IsBadVersionTest("Mali-G52", /*qc=*/false));
182 EXPECT_FALSE(IsBadVersionTest("Mali-G54-MORE STUFF", /*qc=*/false));
183 }
184
185 TEST(DriverInfoVKTest, EnabledDevicesAdreno) {
186 EXPECT_FALSE(IsBadVersionTest("Adreno (TM) 750"));
187 EXPECT_FALSE(IsBadVersionTest("Adreno (TM) 740"));
188 EXPECT_FALSE(IsBadVersionTest("Adreno (TM) 732"));
189 EXPECT_FALSE(IsBadVersionTest("Adreno (TM) 730"));
190 EXPECT_FALSE(IsBadVersionTest("Adreno (TM) 725"));
191 EXPECT_FALSE(IsBadVersionTest("Adreno (TM) 720"));
192 EXPECT_FALSE(IsBadVersionTest("Adreno (TM) 710"));
193 EXPECT_FALSE(IsBadVersionTest("Adreno (TM) 702"));
194 }
195
196 bool CanUseFramebufferFetch(std::string_view driver_name, bool qc = true) {
197 auto const context =
198 MockVulkanContextBuilder()
199 .SetPhysicalPropertiesCallback(
200 [&driver_name, qc](VkPhysicalDevice device,
201 VkPhysicalDeviceProperties* prop) {
202 if (qc) {
203 prop->vendorID = 0x168C; // Qualcomm
204 } else {
205 prop->vendorID = 0x13B5; // ARM
206 }
207 driver_name.copy(prop->deviceName, driver_name.size());
208 prop->deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU;
209 })
210 .Build();
211 return !GetWorkaroundsFromDriverInfo(*context->GetDriverInfo())
212 .input_attachment_self_dependency_broken;
213 }
214
215 TEST(DriverInfoVKTest, CanUseFramebufferFetch) {
216 // Adreno no primitive restart on models as or older than 630.
217 EXPECT_FALSE(CanUseFramebufferFetch("Adreno (TM) 540", true));
218 EXPECT_FALSE(CanUseFramebufferFetch("Adreno (TM) 630", true));
219
220 EXPECT_TRUE(CanUseFramebufferFetch("Adreno (TM) 640", true));
221 EXPECT_TRUE(CanUseFramebufferFetch("Adreno (TM) 750", true));
222 EXPECT_TRUE(CanUseFramebufferFetch("Mali-G51", false));
223 }
224
225 TEST(DriverInfoVKTest, DisableOldXclipseDriver) {
226 auto context =
227 MockVulkanContextBuilder()
228 .SetPhysicalPropertiesCallback(
229 [](VkPhysicalDevice device, VkPhysicalDeviceProperties* prop) {
230 prop->vendorID = 0x144D; // Samsung
231 prop->deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU;
232 // Version 1.1.0
233 prop->apiVersion = (1 << 22) | (1 << 12);
234 })
235 .Build();
236
237 EXPECT_TRUE(context->GetDriverInfo()->IsKnownBadDriver());
238
239 context =
240 MockVulkanContextBuilder()
241 .SetPhysicalPropertiesCallback(
242 [](VkPhysicalDevice device, VkPhysicalDeviceProperties* prop) {
243 prop->vendorID = 0x144D; // Samsung
244 prop->deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU;
245 // Version 1.3.0
246 prop->apiVersion = (1 << 22) | (3 << 12);
247 })
248 .Build();
249
250 EXPECT_FALSE(context->GetDriverInfo()->IsKnownBadDriver());
251 }
252
253 TEST(DriverInfoVKTest, AllPowerVRDisabled) {
254 auto const context =
255 MockVulkanContextBuilder()
256 .SetPhysicalPropertiesCallback(
257 [](VkPhysicalDevice device, VkPhysicalDeviceProperties* prop) {
258 prop->vendorID = 0x1010;
259 prop->deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU;
260 })
261 .Build();
262
263 EXPECT_TRUE(context->GetDriverInfo()->IsKnownBadDriver());
264 }
265
266 } // namespace impeller::testing
impeller::BackendCast< SurfaceContextVK, Context >::Cast
static SurfaceContextVK & Cast(Context &base)
Definition: backend_cast.h:13
impeller::PlaygroundTest
Definition: playground_test.h:22
impeller::SurfaceContextVK::GetParent
const std::shared_ptr< ContextVK > & GetParent() const
Definition: surface_context_vk.cc:119
context_vk.h
driver_info_vk.h
impeller::testing
Definition: allocation_size_unittests.cc:8
impeller::testing::CanUseFramebufferFetch
bool CanUseFramebufferFetch(std::string_view driver_name, bool qc=true)
Definition: driver_info_vk_unittests.cc:196
impeller::testing::TEST
TEST(AllocationSizeTest, CanCreateTypedAllocations)
Definition: allocation_size_unittests.cc:10
impeller::testing::CanUseMipgeneration
bool CanUseMipgeneration(std::string_view driver_name, bool qc=true)
Definition: driver_info_vk_unittests.cc:126
impeller::testing::TEST_P
TEST_P(AiksTest, DrawAtlasNoColor)
Definition: aiks_dl_atlas_unittests.cc:57
impeller::testing::IsBadVersionTest
bool IsBadVersionTest(std::string_view driver_name, bool qc=true)
Definition: driver_info_vk_unittests.cc:52
impeller::testing::INSTANTIATE_VULKAN_PLAYGROUND_SUITE
INSTANTIATE_VULKAN_PLAYGROUND_SUITE(DriverInfoVKTest)
impeller::testing::CanUsePrimitiveRestartSubmitTest
bool CanUsePrimitiveRestartSubmitTest(std::string_view driver_name, bool qc=true)
Definition: driver_info_vk_unittests.cc:97
impeller::testing::CanBatchSubmitTest
bool CanBatchSubmitTest(std::string_view driver_name, bool qc=true)
Definition: driver_info_vk_unittests.cc:70
impeller::MaliGPU::kUnknown
@ kUnknown
impeller::MaliGPU::kG51
@ kG51
impeller::VendorVK::kUnknown
@ kUnknown
impeller::AdrenoGPU::kUnknown
@ kUnknown
impeller::AdrenoGPU::kAdreno540
@ kAdreno540
impeller::GetMaliVersion
MaliGPU GetMaliVersion(std::string_view version)
Definition: driver_info_vk.cc:122
impeller::GetAdrenoVersion
AdrenoGPU GetAdrenoVersion(std::string_view version)
Definition: driver_info_vk.cc:108
impeller::DeviceTypeVK::kUnknown
@ kUnknown
impeller::GetWorkaroundsFromDriverInfo
WorkaroundsVK GetWorkaroundsFromDriverInfo(DriverInfoVK &driver_info)
Definition: workarounds_vk.cc:10
playground_test.h
impeller::Version
Definition: version.h:16
impeller::WorkaroundsVK::broken_mipmap_generation
bool broken_mipmap_generation
Definition: workarounds_vk.h:36
impeller::WorkaroundsVK::batch_submit_command_buffer_timeout
bool batch_submit_command_buffer_timeout
Definition: workarounds_vk.h:24
impeller::WorkaroundsVK::slow_primitive_restart_performance
bool slow_primitive_restart_performance
Definition: workarounds_vk.h:18
impeller::WorkaroundsVK::input_attachment_self_dependency_broken
bool input_attachment_self_dependency_broken
Definition: workarounds_vk.h:28
surface_context_vk.h