This repository has been archived by the owner on May 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
modifiers.c
264 lines (241 loc) · 6.65 KB
/
modifiers.c
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
#include <drm_fourcc.h>
#include "tables.h"
static void print_nvidia_modifier(uint64_t mod) {
if (!(mod & 0x10)) {
printf("NVIDIA(unknown)");
return;
}
uint64_t h = mod & 0xF;
uint64_t k = (mod >> 12) & 0xFF;
uint64_t g = (mod >> 20) & 0x3;
uint64_t s = (mod >> 22) & 0x1;
uint64_t c = (mod >> 23) & 0x7;
printf("NVIDIA_BLOCK_LINEAR_2D(h=%"PRIu64", k=%"PRIu64", g=%"PRIu64", "
"s=%"PRIu64", c=%"PRIu64")", h, k, g, s, c);
}
static const char *amd_tile_version_str(uint64_t tile_version) {
switch (tile_version) {
case AMD_FMT_MOD_TILE_VER_GFX9:
return "GFX9";
case AMD_FMT_MOD_TILE_VER_GFX10:
return "GFX10";
case AMD_FMT_MOD_TILE_VER_GFX10_RBPLUS:
return "GFX10_RBPLUS";
}
return "Unknown";
}
static const char *amd_tile_str(uint64_t tile, uint64_t tile_version) {
switch (tile_version) {
case AMD_FMT_MOD_TILE_VER_GFX10_RBPLUS:
/* fallthrough */
case AMD_FMT_MOD_TILE_VER_GFX10:
/* fallthrough */
case AMD_FMT_MOD_TILE_VER_GFX9:
switch (tile) {
case AMD_FMT_MOD_TILE_GFX9_64K_S:
return "GFX9_64K_S";
case AMD_FMT_MOD_TILE_GFX9_64K_D:
return "GFX9_64K_D";
case AMD_FMT_MOD_TILE_GFX9_64K_S_X:
return "GFX9_64K_S_X";
case AMD_FMT_MOD_TILE_GFX9_64K_D_X:
return "GFX9_64K_D_X";
case AMD_FMT_MOD_TILE_GFX9_64K_R_X:
return "GFX9_64K_R_X";
}
}
return "Unknown";
}
static const char *amd_dcc_block_size_str(uint64_t size) {
switch (size) {
case AMD_FMT_MOD_DCC_BLOCK_64B:
return "64B";
case AMD_FMT_MOD_DCC_BLOCK_128B:
return "128B";
case AMD_FMT_MOD_DCC_BLOCK_256B:
return "256B";
}
return "Unknown";
}
static bool amd_gfx9_tile_is_x_t(uint64_t tile) {
switch (tile) {
case AMD_FMT_MOD_TILE_GFX9_64K_S_X:
case AMD_FMT_MOD_TILE_GFX9_64K_D_X:
case AMD_FMT_MOD_TILE_GFX9_64K_R_X:
return true;
}
return false;
}
static void print_amd_modifier(uint64_t mod) {
uint64_t tile_version = AMD_FMT_MOD_GET(TILE_VERSION, mod);
uint64_t tile = AMD_FMT_MOD_GET(TILE, mod);
uint64_t dcc = AMD_FMT_MOD_GET(DCC, mod);
uint64_t dcc_retile = AMD_FMT_MOD_GET(DCC_RETILE, mod);
printf("AMD(TILE_VERSION = %s, TILE = %s",
amd_tile_version_str(tile_version), amd_tile_str(tile, tile_version));
if (dcc) {
printf(", DCC");
if (dcc_retile) {
printf(", DCC_RETILE");
}
if (!dcc_retile && AMD_FMT_MOD_GET(DCC_PIPE_ALIGN, mod)) {
printf(", DCC_PIPE_ALIGN");
}
if (AMD_FMT_MOD_GET(DCC_INDEPENDENT_64B, mod)) {
printf(", DCC_INDEPENDENT_64B");
}
if (AMD_FMT_MOD_GET(DCC_INDEPENDENT_128B, mod)) {
printf(", DCC_INDEPENDENT_128B");
}
uint64_t dcc_max_compressed_block =
AMD_FMT_MOD_GET(DCC_MAX_COMPRESSED_BLOCK, mod);
printf(", DCC_MAX_COMPRESSED_BLOCK = %s",
amd_dcc_block_size_str(dcc_max_compressed_block));
if (AMD_FMT_MOD_GET(DCC_CONSTANT_ENCODE, mod)) {
printf(", DCC_CONSTANT_ENCODE");
}
}
if (tile_version >= AMD_FMT_MOD_TILE_VER_GFX9 && amd_gfx9_tile_is_x_t(tile)) {
printf(", PIPE_XOR_BITS = %"PRIu64, AMD_FMT_MOD_GET(PIPE_XOR_BITS, mod));
if (tile_version == AMD_FMT_MOD_TILE_VER_GFX9) {
printf(", BANK_XOR_BITS = %"PRIu64, AMD_FMT_MOD_GET(BANK_XOR_BITS, mod));
}
if (tile_version == AMD_FMT_MOD_TILE_VER_GFX10_RBPLUS) {
printf(", PACKERS = %"PRIu64, AMD_FMT_MOD_GET(PACKERS, mod));
}
if (tile_version == AMD_FMT_MOD_TILE_VER_GFX9 && dcc) {
printf(", RB = %"PRIu64, AMD_FMT_MOD_GET(RB, mod));
}
if (tile_version == AMD_FMT_MOD_TILE_VER_GFX9 && dcc &&
(dcc_retile || AMD_FMT_MOD_GET(DCC_PIPE_ALIGN, mod))) {
printf(", PIPE = %"PRIu64, AMD_FMT_MOD_GET(PIPE, mod));
}
}
printf(")");
}
static const char *arm_afbc_block_size_str(uint64_t block_size) {
switch (block_size) {
case AFBC_FORMAT_MOD_BLOCK_SIZE_16x16:
return "16x16";
case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8:
return "32x8";
case AFBC_FORMAT_MOD_BLOCK_SIZE_64x4:
return "64x4";
case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8_64x4:
return "32x8_64x4";
}
return "Unknown";
}
static const char *arm_afrc_cu_size_str(uint64_t cu_size) {
switch (cu_size) {
case AFRC_FORMAT_MOD_CU_SIZE_16:
return "16";
case AFRC_FORMAT_MOD_CU_SIZE_24:
return "24";
case AFRC_FORMAT_MOD_CU_SIZE_32:
return "32";
}
return "Unknown";
}
static void print_arm_modifier(uint64_t mod) {
uint64_t type = (mod >> 52) & 0xF;
uint64_t value = mod & 0x000FFFFFFFFFFFFFULL;
switch (type) {
case DRM_FORMAT_MOD_ARM_TYPE_AFBC:;
uint64_t block_size = value & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK;
printf("ARM_AFBC(BLOCK_SIZE = %s", arm_afbc_block_size_str(block_size));
if (value & AFBC_FORMAT_MOD_YTR) {
printf(", YTR");
}
if (value & AFBC_FORMAT_MOD_SPLIT) {
printf(", SPLIT");
}
if (value & AFBC_FORMAT_MOD_SPARSE) {
printf(", SPARSE");
}
if (value & AFBC_FORMAT_MOD_CBR) {
printf(", CBR");
}
if (value & AFBC_FORMAT_MOD_TILED) {
printf(", TILED");
}
if (value & AFBC_FORMAT_MOD_SC) {
printf(", SC");
}
if (value & AFBC_FORMAT_MOD_DB) {
printf(", DB");
}
if (value & AFBC_FORMAT_MOD_BCH) {
printf(", BCH");
}
if (value & AFBC_FORMAT_MOD_USM) {
printf(", USM");
}
printf(")");
break;
case DRM_FORMAT_MOD_ARM_TYPE_MISC:
switch (mod) {
case DRM_FORMAT_MOD_ARM_16X16_BLOCK_U_INTERLEAVED:
printf("ARM_16X16_BLOCK_U_INTERLEAVED");
break;
default:
printf("ARM_MISC(unknown)");
}
break;
case DRM_FORMAT_MOD_ARM_TYPE_AFRC:
uint64_t cu_size_p0 = value & AFRC_FORMAT_MOD_CU_SIZE_MASK;
uint64_t cu_size_p12 = (value >> 4) & AFRC_FORMAT_MOD_CU_SIZE_MASK;
printf("ARM_AFRC(");
printf("CU_SIZE_P0 = %s", arm_afrc_cu_size_str(cu_size_p0));
printf(", CU_SIZE_P12 = %s", arm_afrc_cu_size_str(cu_size_p12));
if (value & AFRC_FORMAT_MOD_LAYOUT_SCAN)
printf(", SCAN");
else
printf(", ROT");
printf(")");
break;
default:
printf("ARM(unknown)");
}
}
static const char *amlogic_layout_str(uint64_t layout) {
switch (layout) {
case AMLOGIC_FBC_LAYOUT_BASIC:
return "BASIC";
case AMLOGIC_FBC_LAYOUT_SCATTER:
return "SCATTER";
}
return "Unknown";
}
static void print_amlogic_modifier(uint64_t mod) {
uint64_t layout = mod & 0xFF;
uint64_t options = (mod >> 8) & 0xFF;
printf("AMLOGIC_FBC(layout = %s, options = %s)",
amlogic_layout_str(layout),
(options & AMLOGIC_FBC_OPTION_MEM_SAVING) ? "MEM_SAVING" : "0");
}
static uint8_t mod_vendor(uint64_t mod) {
return (uint8_t)(mod >> 56);
}
void print_modifier(uint64_t mod) {
switch (mod_vendor(mod)) {
case DRM_FORMAT_MOD_VENDOR_NVIDIA:
print_nvidia_modifier(mod);
break;
case DRM_FORMAT_MOD_VENDOR_AMD:
print_amd_modifier(mod);
break;
case DRM_FORMAT_MOD_VENDOR_ARM:
print_arm_modifier(mod);
break;
case DRM_FORMAT_MOD_VENDOR_AMLOGIC:
print_amlogic_modifier(mod);
break;
default:
printf("%s", basic_modifier_str(mod));
}
printf(" (0x%"PRIx64")", mod);
}