Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/freedreno/common/freedreno_devices.py
4565 views
1
#
2
# Copyright © 2021 Google, Inc.
3
#
4
# Permission is hereby granted, free of charge, to any person obtaining a
5
# copy of this software and associated documentation files (the "Software"),
6
# to deal in the Software without restriction, including without limitation
7
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
# and/or sell copies of the Software, and to permit persons to whom the
9
# Software is furnished to do so, subject to the following conditions:
10
#
11
# The above copyright notice and this permission notice (including the next
12
# paragraph) shall be included in all copies or substantial portions of the
13
# Software.
14
#
15
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21
# IN THE SOFTWARE.
22
23
from mako.template import Template
24
import sys
25
26
def max_bitfield_val(high, low, shift):
27
return ((1 << (high - low)) - 1) << shift
28
29
class State(object):
30
def __init__(self):
31
# List of unique device-info structs, multiple different GPU ids
32
# can map to a single info struct in cases where the differences
33
# are not sw visible, or the only differences are parameters
34
# queried from the kernel (like GMEM size)
35
self.gpu_infos = []
36
37
# Table mapping GPU id to device-info struct
38
self.gpus = {}
39
40
def info_index(self, gpu_info):
41
i = 0
42
for info in self.gpu_infos:
43
if gpu_info == info:
44
return i
45
i += 1
46
raise Error("invalid info")
47
48
s = State()
49
50
def add_gpus(ids, info):
51
for id in ids:
52
s.gpus[id] = info
53
54
class GPUId(object):
55
def __init__(self, gpu_id, name=None):
56
self.gpu_id = gpu_id
57
if name == None:
58
name = "FD%d" % gpu_id
59
self.name = name
60
61
class Struct(object):
62
"""A helper class that stringifies itself to a 'C' struct initializer
63
"""
64
def __str__(self):
65
s = "{"
66
for name, value in vars(self).items():
67
s += "." + name + "=" + str(value) + ","
68
return s + "}"
69
70
class GPUInfo(Struct):
71
"""Base class for any generation of adreno, consists of GMEM layout
72
related parameters
73
74
Note that tile_max_h is normally only constrained by corresponding
75
bitfield size/shift (ie. VSC_BIN_SIZE, or similar), but tile_max_h
76
tends to have lower limits, in which case a comment will describe
77
the bitfield size/shift
78
"""
79
def __init__(self, gmem_align_w, gmem_align_h,
80
tile_align_w, tile_align_h,
81
tile_max_w, tile_max_h, num_vsc_pipes):
82
self.gmem_align_w = gmem_align_w
83
self.gmem_align_h = gmem_align_h
84
self.tile_align_w = tile_align_w
85
self.tile_align_h = tile_align_h
86
self.tile_max_w = tile_max_w
87
self.tile_max_h = tile_max_h
88
self.num_vsc_pipes = num_vsc_pipes
89
90
s.gpu_infos.append(self)
91
92
93
class A6xxGPUInfo(GPUInfo):
94
"""The a6xx generation has a lot more parameters, and is broken down
95
into distinct sub-generations. The template parameter avoids
96
duplication of parameters that are unique to the sub-generation.
97
"""
98
def __init__(self, template, num_sp_cores, num_ccu,
99
RB_UNKNOWN_8E04_blit, PC_UNKNOWN_9805,
100
SP_UNKNOWN_A0F8):
101
super().__init__(gmem_align_w = 16, gmem_align_h = 4,
102
tile_align_w = 32, tile_align_h = 32,
103
tile_max_w = 1024, # max_bitfield_val(5, 0, 5)
104
tile_max_h = max_bitfield_val(14, 8, 4),
105
num_vsc_pipes = 32)
106
assert(num_sp_cores == num_ccu)
107
108
self.num_sp_cores = num_sp_cores
109
110
# 96 tile alignment seems correlated to 3 CCU
111
if num_ccu == 3:
112
self.tile_align_w = 96
113
114
self.a6xx = Struct()
115
self.a6xx.magic = Struct()
116
117
# Various "magic" register values:
118
self.a6xx.magic.RB_UNKNOWN_8E04_blit = RB_UNKNOWN_8E04_blit
119
self.a6xx.magic.PC_UNKNOWN_9805 = PC_UNKNOWN_9805
120
self.a6xx.magic.SP_UNKNOWN_A0F8 = SP_UNKNOWN_A0F8
121
122
# Things that earlier gens have and later gens remove, provide
123
# defaults here and let them be overridden by sub-gen template:
124
self.a6xx.has_cp_reg_write = True
125
self.a6xx.has_8bpp_ubwc = True
126
127
for name, val in template.items():
128
setattr(self.a6xx, name, val)
129
130
# a2xx is really two sub-generations, a20x and a22x, but we don't currently
131
# capture that in the device-info tables
132
add_gpus([
133
GPUId(200),
134
GPUId(201),
135
GPUId(205),
136
GPUId(220),
137
], GPUInfo(
138
gmem_align_w = 32, gmem_align_h = 32,
139
tile_align_w = 32, tile_align_h = 32,
140
tile_max_w = 512,
141
tile_max_h = ~0, # TODO
142
num_vsc_pipes = 8,
143
))
144
145
add_gpus([
146
GPUId(305),
147
GPUId(307),
148
GPUId(320),
149
GPUId(330),
150
], GPUInfo(
151
gmem_align_w = 32, gmem_align_h = 32,
152
tile_align_w = 32, tile_align_h = 32,
153
tile_max_w = 992, # max_bitfield_val(4, 0, 5)
154
tile_max_h = max_bitfield_val(9, 5, 5),
155
num_vsc_pipes = 8,
156
))
157
158
add_gpus([
159
GPUId(405),
160
GPUId(420),
161
GPUId(430),
162
], GPUInfo(
163
gmem_align_w = 32, gmem_align_h = 32,
164
tile_align_w = 32, tile_align_h = 32,
165
tile_max_w = 1024, # max_bitfield_val(4, 0, 5)
166
tile_max_h = max_bitfield_val(9, 5, 5),
167
num_vsc_pipes = 8,
168
))
169
170
add_gpus([
171
GPUId(510),
172
GPUId(530),
173
GPUId(540),
174
], GPUInfo(
175
gmem_align_w = 64, gmem_align_h = 32,
176
tile_align_w = 64, tile_align_h = 32,
177
tile_max_w = 1024, # max_bitfield_val(7, 0, 5)
178
tile_max_h = max_bitfield_val(16, 9, 5),
179
num_vsc_pipes = 16,
180
))
181
182
# a6xx can be divided into distinct sub-generations, where certain device-
183
# info parameters are keyed to the sub-generation. These templates reduce
184
# the copypaste
185
186
# a615, a618, a630:
187
a6xx_gen1 = dict(
188
fibers_per_sp = 128 * 16,
189
reg_size_vec4 = 96,
190
ccu_cntl_gmem_unk2 = True,
191
indirect_draw_wfm_quirk = True,
192
)
193
194
# a640, a680:
195
a6xx_gen2 = dict(
196
fibers_per_sp = 128 * 4 * 16,
197
reg_size_vec4 = 96,
198
supports_multiview_mask = True,
199
has_z24uint_s8uint = True,
200
indirect_draw_wfm_quirk = True,
201
)
202
203
# a650:
204
a6xx_gen3 = dict(
205
fibers_per_sp = 128 * 2 * 16,
206
reg_size_vec4 = 64,
207
supports_multiview_mask = True,
208
has_z24uint_s8uint = True,
209
tess_use_shared = True,
210
storage_16bit = True,
211
has_tex_filter_cubic = True,
212
has_sample_locations = True,
213
)
214
215
# a635, a650:
216
a6xx_gen4 = dict(
217
fibers_per_sp = 128 * 2 * 16,
218
reg_size_vec4 = 64,
219
supports_multiview_mask = True,
220
has_z24uint_s8uint = True,
221
tess_use_shared = True,
222
storage_16bit = True,
223
has_tex_filter_cubic = True,
224
has_sample_locations = True,
225
has_cp_reg_write = False,
226
has_8bpp_ubwc = False,
227
)
228
229
add_gpus([
230
GPUId(615),
231
GPUId(618),
232
], A6xxGPUInfo(
233
a6xx_gen1,
234
num_sp_cores = 1,
235
num_ccu = 1,
236
RB_UNKNOWN_8E04_blit = 0x00100000,
237
PC_UNKNOWN_9805 = 0,
238
SP_UNKNOWN_A0F8 = 0,
239
))
240
241
add_gpus([
242
GPUId(630),
243
], A6xxGPUInfo(
244
a6xx_gen1,
245
num_sp_cores = 2,
246
num_ccu = 2,
247
RB_UNKNOWN_8E04_blit = 0x01000000,
248
PC_UNKNOWN_9805 = 1,
249
SP_UNKNOWN_A0F8 = 1,
250
))
251
252
add_gpus([
253
GPUId(640),
254
], A6xxGPUInfo(
255
a6xx_gen2,
256
num_sp_cores = 2,
257
num_ccu = 2,
258
RB_UNKNOWN_8E04_blit = 0x00100000,
259
PC_UNKNOWN_9805 = 1,
260
SP_UNKNOWN_A0F8 = 1,
261
))
262
263
add_gpus([
264
GPUId(650),
265
], A6xxGPUInfo(
266
a6xx_gen3,
267
num_sp_cores = 3,
268
num_ccu = 3,
269
RB_UNKNOWN_8E04_blit = 0x04100000,
270
PC_UNKNOWN_9805 = 2,
271
SP_UNKNOWN_A0F8 = 2,
272
))
273
274
add_gpus([
275
GPUId(635, "Adreno 7c Gen 3"),
276
], A6xxGPUInfo(
277
a6xx_gen4,
278
num_sp_cores = 2,
279
num_ccu = 2,
280
RB_UNKNOWN_8E04_blit = 0x00100000,
281
PC_UNKNOWN_9805 = 1,
282
SP_UNKNOWN_A0F8 = 1,
283
))
284
285
add_gpus([
286
GPUId(660),
287
], A6xxGPUInfo(
288
a6xx_gen4,
289
num_sp_cores = 3,
290
num_ccu = 3,
291
RB_UNKNOWN_8E04_blit = 0x04100000,
292
PC_UNKNOWN_9805 = 2,
293
SP_UNKNOWN_A0F8 = 2,
294
))
295
296
template = """\
297
/* Copyright (C) 2021 Google, Inc.
298
*
299
* Permission is hereby granted, free of charge, to any person obtaining a
300
* copy of this software and associated documentation files (the "Software"),
301
* to deal in the Software without restriction, including without limitation
302
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
303
* and/or sell copies of the Software, and to permit persons to whom the
304
* Software is furnished to do so, subject to the following conditions:
305
*
306
* The above copyright notice and this permission notice (including the next
307
* paragraph) shall be included in all copies or substantial portions of the
308
* Software.
309
*
310
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
311
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
312
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
313
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
314
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
315
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
316
* IN THE SOFTWARE.
317
*/
318
319
#include "freedreno_dev_info.h"
320
321
/* Map python to C: */
322
#define True true
323
#define False false
324
325
%for info in s.gpu_infos:
326
static const struct fd_dev_info __info${s.info_index(info)} = ${str(info)};
327
%endfor
328
329
const struct fd_dev_id fd_dev_ids[] = {
330
%for id, info in s.gpus.items():
331
{ ${id.gpu_id}, "${id.name}", &__info${s.info_index(info)} },
332
%endfor
333
};
334
const unsigned fd_dev_ids_count = ${len(s.gpus)};
335
"""
336
337
print(Template(template).render(s=s))
338
339
340