1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
gpu / config / webgpu_blocklist_unittest.cc [blame]
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "gpu/config/webgpu_blocklist.h"
#include "build/build_config.h"
#include "gpu/config/webgpu_blocklist_impl.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/dawn/include/dawn/webgpu.h"
#include "ui/gl/buildflags.h"
#if BUILDFLAG(IS_ANDROID)
#include "base/android/build_info.h"
#endif
namespace gpu {
bool IsWebGPUAdapterBlocklisted(const WGPUAdapterInfo& info,
const char* blocklist_string = "") {
return detail::GetWebGPUAdapterBlocklistReason(
*reinterpret_cast<const wgpu::AdapterInfo*>(&info),
{
.blocklist_string = blocklist_string,
}) != WebGPUBlocklistReason::None;
}
class WebGPUBlocklistTest : public testing::Test {};
#if BUILDFLAG(IS_ANDROID)
// Android is currently more restrictive than other platforms around which GPUs
// are allowed, which causes the usual tests to fail. This test exercises the
// Android-specific restrictions.
TEST_F(WebGPUBlocklistTest, BlockAndroidVendorId) {
const auto* build_info = base::android::BuildInfo::GetInstance();
WGPUAdapterInfo info1 = {};
info1.vendorID = 0x13B5;
WGPUAdapterInfo info2 = {};
info2.vendorID = 0x5143;
WGPUAdapterInfo info3 = {};
info3.vendorID = 0x8086;
if (build_info->sdk_int() < base::android::SDK_VERSION_S) {
// If the Android version is R or lower everything should be blocked.
EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info1));
EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info2));
EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info3));
return;
}
// Test the default vendor blocks
EXPECT_FALSE(IsWebGPUAdapterBlocklisted(info1));
EXPECT_FALSE(IsWebGPUAdapterBlocklisted(info2));
// Test that blocking a vendor which is otherwise allowed still works
EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info1, "13b5"));
EXPECT_FALSE(IsWebGPUAdapterBlocklisted(info2, "13b5"));
// Test blocking *
EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info1, "*"));
EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info2, "*"));
// Test blocking a list of patterns
EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info1, "13b5|5143"));
EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info2, "13b5|5143"));
}
#else
TEST_F(WebGPUBlocklistTest, BlockVendorId) {
WGPUAdapterInfo info1 = {};
info1.vendorID = 0x8086;
WGPUAdapterInfo info2 = {};
info2.vendorID = 0x1002;
WGPUAdapterInfo info3 = {};
info3.vendorID = 0x0042;
// Test blocking exactly a vendorID
EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info1, "8086"));
EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info2, "1002"));
EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info3, "42"));
// Test blocking a mismatching vendorID
EXPECT_FALSE(IsWebGPUAdapterBlocklisted(info1, "1002"));
// Test blocking *
EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info1, "*"));
EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info2, "*"));
EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info3, "*"));
// Test blocking a list of patterns
EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info1, "8086|1002"));
EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info2, "8086|1002"));
EXPECT_FALSE(IsWebGPUAdapterBlocklisted(info3, "8086|1002"));
}
TEST_F(WebGPUBlocklistTest, BlockDeviceIdOrArch) {
WGPUAdapterInfo info1 = {};
info1.vendorID = 0x8086;
info1.deviceID = 0x1;
info1.architecture = {"gen-9", WGPU_STRLEN};
WGPUAdapterInfo info2 = {};
info2.vendorID = 0x8086;
info2.deviceID = 0x2;
info2.architecture = {"gen-9", WGPU_STRLEN};
WGPUAdapterInfo info3 = {};
info3.vendorID = 0x1002;
info3.deviceID = 0x1;
info3.architecture = {"gcn-3", WGPU_STRLEN};
// Test blocking exactly a vendor and deviceID
EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info1, "8086:1"));
EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info2, "8086:2"));
EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info3, "1002:1"));
// Test blocking exactly a vendor and architecture
EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info1, "8086:gen-9"));
EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info2, "8086:gen-9"));
EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info3, "1002:gcn-3"));
// Test blocking a mismatching deviceID
EXPECT_FALSE(IsWebGPUAdapterBlocklisted(info1, "8086:2"));
// Test blocking a mismatching architecture
EXPECT_FALSE(IsWebGPUAdapterBlocklisted(info1, "8086:gen-8"));
EXPECT_FALSE(IsWebGPUAdapterBlocklisted(info3, "1002:gcn-4"));
// Test blocking a mismatching vendor id, with matching architecture
EXPECT_FALSE(IsWebGPUAdapterBlocklisted(info1, "1002:gen-9"));
EXPECT_FALSE(IsWebGPUAdapterBlocklisted(info3, "8086:gcn-3"));
// Test blocking *
EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info1, "8086:*"));
EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info2, "8086:*"));
EXPECT_FALSE(IsWebGPUAdapterBlocklisted(info3, "8086:*"));
// Test blocking a list of deviceIDs
EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info1, "8086:1|8086:2"));
EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info2, "8086:1|8086:2"));
EXPECT_FALSE(IsWebGPUAdapterBlocklisted(info3, "8086:1|8086:2"));
// Test blocking any vendor ID with a list of architectures
EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info1, "*:gen-9|*:gcn-3"));
EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info2, "*:gen-9|*:gcn-3"));
EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info3, "*:gen-9|*:gcn-3"));
}
TEST_F(WebGPUBlocklistTest, BlockDriverDescription) {
WGPUAdapterInfo info1 = {};
info1.vendorID = 0x8086;
info1.deviceID = 0x1;
info1.architecture = {"gen-9", WGPU_STRLEN};
info1.description = {"D3D12 driver version 31.0.101.2111", WGPU_STRLEN};
WGPUAdapterInfo info2 = {};
info2.vendorID = 0x8086;
info2.deviceID = 0x1;
info2.architecture = {"gen-9", WGPU_STRLEN};
info2.description = {"D3D12 driver version 33.0.100.0004", WGPU_STRLEN};
WGPUAdapterInfo info3 = {};
info3.vendorID = 0x1002;
info3.deviceID = 0x1;
info3.architecture = {"gcn-3", WGPU_STRLEN};
info3.description = {"D3D12 driver version 31.0.203.3113", WGPU_STRLEN};
// Test blocking specific driver versions, with vendor+device ids
EXPECT_TRUE(IsWebGPUAdapterBlocklisted(
info1, "8086:1:D3D12 driver version 31.0.101.2111"));
EXPECT_TRUE(IsWebGPUAdapterBlocklisted(
info2, "8086:1:D3D12 driver version 33.0.100.0004"));
EXPECT_TRUE(IsWebGPUAdapterBlocklisted(
info3, "1002:1:D3D12 driver version 31.0.203.3113"));
// Test blocking specific driver versions, regardless of vendor+device ids
EXPECT_TRUE(IsWebGPUAdapterBlocklisted(
info1, "*:*:D3D12 driver version 31.0.101.2111"));
EXPECT_TRUE(IsWebGPUAdapterBlocklisted(
info2, "*:*:D3D12 driver version 33.0.100.0004"));
EXPECT_TRUE(IsWebGPUAdapterBlocklisted(
info3, "*:*:D3D12 driver version 31.0.203.3113"));
// Test blocking specific driver version patterns
EXPECT_TRUE(
IsWebGPUAdapterBlocklisted(info1, "*:*:D3D12 driver version 3*.0.1*"));
EXPECT_TRUE(
IsWebGPUAdapterBlocklisted(info2, "*:*:D3D12 driver version 3*.0.1*"));
EXPECT_FALSE(
IsWebGPUAdapterBlocklisted(info3, "*:*:D3D12 driver version 3*.0.1*"));
EXPECT_TRUE(
IsWebGPUAdapterBlocklisted(info1, "*:*:D3D12 driver version 31.*"));
EXPECT_FALSE(
IsWebGPUAdapterBlocklisted(info2, "*:*:D3D12 driver version 31.*"));
EXPECT_TRUE(
IsWebGPUAdapterBlocklisted(info3, "*:*:D3D12 driver version 31.*"));
}
#endif // BUILDFLAG(IS_ANDROID) else
} // namespace gpu