1 /*
2 * Copyright (c) 2019 Andreas Baierl <ichgeh@imkreisrum.de>
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, sub license,
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
12 * next paragraph) shall be included in all copies or substantial portions
13 * of the 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 NON-INFRINGEMENT. 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
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
25 #include "util/u_math.h"
26
27 #include <stdio.h>
28 #include <stdint.h>
29 #include <string.h>
30
31 #include "lima_context.h"
32 #include "lima_parser.h"
33 #include "lima_texture.h"
34
35 typedef struct {
36 char *info;
37 } render_state_info;
38
39 static render_state_info render_state_infos[] = {
40 { .info = "BLEND_COLOR_BG", },
41 { .info = "BLEND_COLOR_RA", },
42 { .info = "ALPHA_BLEND", },
43 { .info = "DEPTH_TEST", },
44 { .info = "DEPTH_RANGE", },
45 { .info = "STENCIL_FRONT", },
46 { .info = "STENCIL_BACK", },
47 { .info = "STENCIL_TEST", },
48 { .info = "MULTI_SAMPLE", },
49 { .info = "SHADER_ADDRESS (FS)", },
50 { .info = "VARYING_TYPES", },
51 { .info = "UNIFORMS_ADDRESS (PP)", },
52 { .info = "TEXTURES_ADDRESS", },
53 { .info = "AUX0", },
54 { .info = "AUX1", },
55 { .info = "VARYINGS_ADDRESS", },
56 };
57
58 /* VS CMD stream parser functions */
59
60 static void
parse_vs_draw(FILE * fp,uint32_t * value1,uint32_t * value2)61 parse_vs_draw(FILE *fp, uint32_t *value1, uint32_t *value2)
62 {
63 if ((*value1 == 0x00000000) && (*value2 == 0x00000000))
64 fprintf(fp, "\t/* ---EMPTY CMD */\n");
65 else
66 fprintf(fp, "\t/* DRAW: num: %d, index_draw: %s */\n",
67 (*value1 & 0xff000000) >> 24 | (*value2 & 0x000000ff) << 8,
68 (*value1 & 0x00000001) ? "true" : "false");
69 }
70
71 static void
parse_vs_shader_info(FILE * fp,uint32_t * value1,uint32_t * value2)72 parse_vs_shader_info(FILE *fp, uint32_t *value1, uint32_t *value2)
73 {
74 fprintf(fp, "\t/* SHADER_INFO: prefetch: %d, size: %d */\n",
75 (*value1 & 0xfff00000) >> 20,
76 (((*value1 & 0x000fffff) >> 10) + 1) << 4);
77 }
78
79 static void
parse_vs_unknown1(FILE * fp,uint32_t * value1,uint32_t * value2)80 parse_vs_unknown1(FILE *fp, uint32_t *value1, uint32_t *value2)
81 {
82 fprintf(fp, "\t/* UNKNOWN_1 */\n");
83 }
84
85 static void
parse_vs_varying_attribute_count(FILE * fp,uint32_t * value1,uint32_t * value2)86 parse_vs_varying_attribute_count(FILE *fp, uint32_t *value1, uint32_t *value2)
87 {
88 fprintf(fp, "\t/* VARYING_ATTRIBUTE_COUNT: nr_vary: %d, nr_attr: %d */\n",
89 ((*value1 & 0x00ffffff) >> 8) + 1, (*value1 >> 24) + 1);
90 }
91
92 static void
parse_vs_attributes_address(FILE * fp,uint32_t * value1,uint32_t * value2)93 parse_vs_attributes_address(FILE *fp, uint32_t *value1, uint32_t *value2)
94 {
95 fprintf(fp, "\t/* ATTRIBUTES_ADDRESS: address: 0x%08x, size: %d */\n",
96 *value1, (*value2 & 0x0fffffff) >> 17);
97 }
98
99 static void
parse_vs_varyings_address(FILE * fp,uint32_t * value1,uint32_t * value2)100 parse_vs_varyings_address(FILE *fp, uint32_t *value1, uint32_t *value2)
101 {
102 fprintf(fp, "\t/* VARYINGS_ADDRESS: varying info @ 0x%08x, size: %d */\n",
103 *value1, (*value2 & 0x0fffffff) >> 17);
104 }
105
106 static void
parse_vs_uniforms_address(FILE * fp,uint32_t * value1,uint32_t * value2)107 parse_vs_uniforms_address(FILE *fp, uint32_t *value1, uint32_t *value2)
108 {
109 fprintf(fp, "\t/* UNIFORMS_ADDRESS (GP): address: 0x%08x, size: %d */\n",
110 *value1, (*value2 & 0x0fffffff) >> 12);
111 }
112
113 static void
parse_vs_shader_address(FILE * fp,uint32_t * value1,uint32_t * value2)114 parse_vs_shader_address(FILE *fp, uint32_t *value1, uint32_t *value2)
115 {
116 fprintf(fp, "\t/* SHADER_ADDRESS (VS): address: 0x%08x, size: %d */\n",
117 *value1, (*value2 & 0x0fffffff) >> 12);
118 }
119
120 static void
parse_vs_semaphore(FILE * fp,uint32_t * value1,uint32_t * value2)121 parse_vs_semaphore(FILE *fp, uint32_t *value1, uint32_t *value2)
122 {
123 if (*value1 == 0x00028000)
124 fprintf(fp, "\t/* SEMAPHORE_BEGIN_1 */\n");
125 else if (*value1 == 0x00000001)
126 fprintf(fp, "\t/* SEMAPHORE_BEGIN_2 */\n");
127 else if (*value1 == 0x00000000)
128 fprintf(fp, "\t/* SEMAPHORE_END: index_draw disabled */\n");
129 else if (*value1 == 0x00018000)
130 fprintf(fp, "\t/* SEMAPHORE_END: index_draw enabled */\n");
131 else
132 fprintf(fp, "\t/* SEMAPHORE - cmd unknown! */\n");
133 }
134
135 static void
parse_vs_unknown2(FILE * fp,uint32_t * value1,uint32_t * value2)136 parse_vs_unknown2(FILE *fp, uint32_t *value1, uint32_t *value2)
137 {
138 fprintf(fp, "\t/* UNKNOWN_2 */\n");
139 }
140
141 static void
parse_vs_continue(FILE * fp,uint32_t * value1,uint32_t * value2)142 parse_vs_continue(FILE *fp, uint32_t *value1, uint32_t *value2)
143 {
144 fprintf(fp, "\t/* CONTINUE: at 0x%08x */\n", *value1);
145 }
146
147 void
lima_parse_vs(FILE * fp,uint32_t * data,int size,uint32_t start)148 lima_parse_vs(FILE *fp, uint32_t *data, int size, uint32_t start)
149 {
150 uint32_t *value1;
151 uint32_t *value2;
152
153 fprintf(fp, "\n");
154 fprintf(fp, "/* ============ VS CMD STREAM BEGIN ============= */\n");
155 for (int i = 0; i * 4 < size; i += 2) {
156 value1 = &data[i];
157 value2 = &data[i + 1];
158 fprintf(fp, "/* 0x%08x (0x%08x) */\t0x%08x 0x%08x",
159 start + i * 4, i * 4, *value1, *value2);
160
161 if ((*value2 & 0xffff0000) == 0x00000000)
162 parse_vs_draw(fp, value1, value2);
163 else if ((*value2 & 0xff0000ff) == 0x10000040)
164 parse_vs_shader_info(fp, value1, value2);
165 else if ((*value2 & 0xff0000ff) == 0x10000041)
166 parse_vs_unknown1(fp, value1, value2);
167 else if ((*value2 & 0xff0000ff) == 0x10000042)
168 parse_vs_varying_attribute_count(fp, value1, value2);
169 else if ((*value2 & 0xff0000ff) == 0x20000000)
170 parse_vs_attributes_address(fp, value1, value2);
171 else if ((*value2 & 0xff0000ff) == 0x20000008)
172 parse_vs_varyings_address(fp, value1, value2);
173 else if ((*value2 & 0xff000000) == 0x30000000)
174 parse_vs_uniforms_address(fp, value1, value2);
175 else if ((*value2 & 0xff000000) == 0x40000000)
176 parse_vs_shader_address(fp, value1, value2);
177 else if ((*value2 & 0xff000000)== 0x50000000)
178 parse_vs_semaphore(fp, value1, value2);
179 else if ((*value2 & 0xff000000) == 0x60000000)
180 parse_vs_unknown2(fp, value1, value2);
181 else if ((*value2 & 0xff000000) == 0xf0000000)
182 parse_vs_continue(fp, value1, value2);
183 else
184 fprintf(fp, "\t/* --- unknown cmd --- */\n");
185 }
186 fprintf(fp, "/* ============ VS CMD STREAM END =============== */\n");
187 fprintf(fp, "\n");
188 }
189
190 /* PLBU CMD stream parser functions */
191
192 static void
parse_plbu_block_step(FILE * fp,uint32_t * value1,uint32_t * value2)193 parse_plbu_block_step(FILE *fp, uint32_t *value1, uint32_t *value2)
194 {
195 fprintf(fp, "\t/* BLOCK_STEP: shift_min: %d, shift_h: %d, shift_w: %d */\n",
196 (*value1 & 0xf0000000) >> 28,
197 (*value1 & 0x0fff0000) >> 16,
198 *value1 & 0x0000ffff);
199 }
200
201 static void
parse_plbu_tiled_dimensions(FILE * fp,uint32_t * value1,uint32_t * value2)202 parse_plbu_tiled_dimensions(FILE *fp, uint32_t *value1, uint32_t *value2)
203 {
204 fprintf(fp, "\t/* TILED_DIMENSIONS: tiled_w: %d, tiled_h: %d */\n",
205 ((*value1 & 0xff000000) >> 24) + 1,
206 ((*value1 & 0x00ffff00) >> 8) + 1);
207 }
208
209 static void
parse_plbu_block_stride(FILE * fp,uint32_t * value1,uint32_t * value2)210 parse_plbu_block_stride(FILE *fp, uint32_t *value1, uint32_t *value2)
211 {
212 fprintf(fp, "\t/* BLOCK_STRIDE: block_w: %d */\n", *value1 & 0x000000ff);
213 }
214
215 static void
parse_plbu_array_address(FILE * fp,uint32_t * value1,uint32_t * value2)216 parse_plbu_array_address(FILE *fp, uint32_t *value1, uint32_t *value2)
217 {
218 fprintf(fp, "\t/* ARRAY_ADDRESS: gp_stream: 0x%08x, block_num (block_w * block_h): %d */\n",
219 *value1, (*value2 & 0x00ffffff) + 1);
220 }
221
222 static void
parse_plbu_viewport_left(FILE * fp,float * value1,uint32_t * value2)223 parse_plbu_viewport_left(FILE *fp, float *value1, uint32_t *value2)
224 {
225 fprintf(fp, "\t/* VIEWPORT_LEFT: viewport_left: %f */\n", *value1);
226 }
227
228 static void
parse_plbu_viewport_right(FILE * fp,float * value1,uint32_t * value2)229 parse_plbu_viewport_right(FILE *fp, float *value1, uint32_t *value2)
230 {
231 fprintf(fp, "\t/* VIEWPORT_RIGHT: viewport_right: %f */\n", *value1);
232 }
233
234 static void
parse_plbu_viewport_bottom(FILE * fp,float * value1,uint32_t * value2)235 parse_plbu_viewport_bottom(FILE *fp, float *value1, uint32_t *value2)
236 {
237 fprintf(fp, "\t/* VIEWPORT_BOTTOM: viewport_bottom: %f */\n", *value1);
238 }
239
240 static void
parse_plbu_viewport_top(FILE * fp,float * value1,uint32_t * value2)241 parse_plbu_viewport_top(FILE *fp, float *value1, uint32_t *value2)
242 {
243 fprintf(fp, "\t/* VIEWPORT_TOP: viewport_top: %f */\n", *value1);
244 }
245
246 static void
parse_plbu_semaphore(FILE * fp,uint32_t * value1,uint32_t * value2)247 parse_plbu_semaphore(FILE *fp, uint32_t *value1, uint32_t *value2)
248 {
249 if (*value1 == 0x00010002)
250 fprintf(fp, "\t/* ARRAYS_SEMAPHORE_BEGIN */\n");
251 else if (*value1 == 0x00010001)
252 fprintf(fp, "\t/* ARRAYS_SEMAPHORE_END */\n");
253 else
254 fprintf(fp, "\t/* SEMAPHORE - cmd unknown! */\n");
255 }
256
257 static void
parse_plbu_primitive_setup(FILE * fp,uint32_t * value1,uint32_t * value2)258 parse_plbu_primitive_setup(FILE *fp, uint32_t *value1, uint32_t *value2)
259 {
260 if (*value1 == 0x00000200)
261 fprintf(fp, "\t/* UNKNOWN_2 (PRIMITIVE_SETUP INIT?) */\n");
262 else
263 fprintf(fp, "\t/* PRIMITIVE_SETUP: %scull: %d (0x%x), index_size: %d */\n",
264 (*value1 & 0x1000) ? "force point size, " : "",
265 (*value1 & 0x000f0000) >> 16, (*value1 & 0x000f0000) >> 16,
266 (*value1 & 0x00000e00) >> 9);
267 }
268
269 static void
parse_plbu_rsw_vertex_array(FILE * fp,uint32_t * value1,uint32_t * value2)270 parse_plbu_rsw_vertex_array(FILE *fp, uint32_t *value1, uint32_t *value2)
271 {
272 fprintf(fp, "\t/* RSW_VERTEX_ARRAY: rsw: 0x%08x, gl_pos: 0x%08x */\n",
273 *value1,
274 (*value2 & 0x0fffffff) << 4);
275 }
276
277 static void
parse_plbu_scissors(FILE * fp,uint32_t * value1,uint32_t * value2)278 parse_plbu_scissors(FILE *fp, uint32_t *value1, uint32_t *value2)
279 {
280 float minx = (*value1 & 0xc0000000) >> 30 | (*value2 & 0x00001fff) << 2;
281 float maxx = ((*value2 & 0x0fffe000) >> 13) + 1;
282 float miny = *value1 & 0x00003fff;
283 float maxy = ((*value1 & 0x3fff8000) >> 15) + 1;
284
285 fprintf(fp, "\t/* SCISSORS: minx: %f, maxx: %f, miny: %f, maxy: %f */\n",
286 minx, maxx, miny, maxy);
287 }
288
289 static void
parse_plbu_unknown_1(FILE * fp,uint32_t * value1,uint32_t * value2)290 parse_plbu_unknown_1(FILE *fp, uint32_t *value1, uint32_t *value2)
291 {
292 fprintf(fp, "\t/* UNKNOWN_1 */\n");
293 }
294
295 static void
parse_plbu_low_prim_size(FILE * fp,float * value1,uint32_t * value2)296 parse_plbu_low_prim_size(FILE *fp, float *value1, uint32_t *value2)
297 {
298 fprintf(fp, "\t/* LOW_PRIM_SIZE: size: %f */\n", *value1);
299 }
300
301 static void
parse_plbu_depth_range_near(FILE * fp,float * value1,uint32_t * value2)302 parse_plbu_depth_range_near(FILE *fp, float *value1, uint32_t *value2)
303 {
304 fprintf(fp, "\t/* DEPTH_RANG_NEAR: depth_range: %f */\n", *value1);
305 }
306
307 static void
parse_plbu_depth_range_far(FILE * fp,float * value1,uint32_t * value2)308 parse_plbu_depth_range_far(FILE *fp, float *value1, uint32_t *value2)
309 {
310 fprintf(fp, "\t/* DEPTH_RANGE_FAR: depth_range: %f */\n", *value1);
311 }
312
313 static void
parse_plbu_indexed_dest(FILE * fp,uint32_t * value1,uint32_t * value2)314 parse_plbu_indexed_dest(FILE *fp, uint32_t *value1, uint32_t *value2)
315 {
316 fprintf(fp, "\t/* INDEXED_DEST: gl_pos: 0x%08x */\n", *value1);
317 }
318
319 static void
parse_plbu_indexed_pt_size(FILE * fp,uint32_t * value1,uint32_t * value2)320 parse_plbu_indexed_pt_size(FILE *fp, uint32_t *value1, uint32_t *value2)
321 {
322 fprintf(fp, "\t/* INDEXED_PT_SIZE: pt_size: 0x%08x */\n", *value1);
323 }
324
325 static void
parse_plbu_indices(FILE * fp,uint32_t * value1,uint32_t * value2)326 parse_plbu_indices(FILE *fp, uint32_t *value1, uint32_t *value2)
327 {
328 fprintf(fp, "\t/* INDICES: indices: 0x%08x */\n", *value1);
329 }
330
331 static void
parse_plbu_draw_arrays(FILE * fp,uint32_t * value1,uint32_t * value2)332 parse_plbu_draw_arrays(FILE *fp, uint32_t *value1, uint32_t *value2)
333 {
334 if ((*value1 == 0x00000000) && (*value2 == 0x00000000)) {
335 fprintf(fp, "\t/* ---EMPTY CMD */\n");
336 return;
337 }
338
339 uint32_t count = (*value1 & 0xff000000) >> 24 | (*value2 & 0x000000ff) << 8;
340 uint32_t start = *value1 & 0x00ffffff;
341 uint32_t mode = (*value2 & 0x001f0000) >> 16;
342
343 fprintf(fp, "\t/* DRAW_ARRAYS: count: %d, start: %d, mode: %d (0x%x) */\n",
344 count, start, mode, mode);
345 }
346
347 static void
parse_plbu_draw_elements(FILE * fp,uint32_t * value1,uint32_t * value2)348 parse_plbu_draw_elements(FILE *fp, uint32_t *value1, uint32_t *value2)
349 {
350 uint32_t count = (*value1 & 0xff000000) >> 24 | (*value2 & 0x000000ff) << 8;
351 uint32_t start = *value1 & 0x00ffffff;
352 uint32_t mode = (*value2 & 0x001f0000) >> 16;
353
354 fprintf(fp, "\t/* DRAW_ELEMENTS: count: %d, start: %d, mode: %d (0x%x) */\n",
355 count, start, mode, mode);
356 }
357
358 static void
parse_plbu_continue(FILE * fp,uint32_t * value1,uint32_t * value2)359 parse_plbu_continue(FILE *fp, uint32_t *value1, uint32_t *value2)
360 {
361 fprintf(fp, "\t/* CONTINUE: continue at 0x%08x */\n", *value1);
362 }
363
364 static void
parse_plbu_end(FILE * fp,uint32_t * value1,uint32_t * value2)365 parse_plbu_end(FILE *fp, uint32_t *value1, uint32_t *value2)
366 {
367 fprintf(fp, "\t/* END (FINISH/FLUSH) */\n");
368 }
369
370 void
lima_parse_plbu(FILE * fp,uint32_t * data,int size,uint32_t start)371 lima_parse_plbu(FILE *fp, uint32_t *data, int size, uint32_t start)
372 {
373 uint32_t *value1;
374 uint32_t *value2;
375
376 fprintf(fp, "/* ============ PLBU CMD STREAM BEGIN ============= */\n");
377 for (int i = 0; i * 4 < size; i += 2) {
378 value1 = &data[i];
379 value2 = &data[i + 1];
380 fprintf(fp, "/* 0x%08x (0x%08x) */\t0x%08x 0x%08x",
381 start + i * 4, i * 4, *value1, *value2);
382
383 if ((*value2 & 0xffe00000) == 0x00000000)
384 parse_plbu_draw_arrays(fp, value1, value2);
385 else if ((*value2 & 0xffe00000) == 0x00200000)
386 parse_plbu_draw_elements(fp, value1, value2);
387 else if ((*value2 & 0xff000fff) == 0x10000100)
388 parse_plbu_indexed_dest(fp, value1, value2);
389 else if ((*value2 & 0xff000fff) == 0x10000101)
390 parse_plbu_indices(fp, value1, value2);
391 else if ((*value2 & 0xff000fff) == 0x10000102)
392 parse_plbu_indexed_pt_size(fp, value1, value2);
393 else if ((*value2 & 0xff000fff) == 0x10000105)
394 parse_plbu_viewport_bottom(fp, (float *)value1, value2);
395 else if ((*value2 & 0xff000fff) == 0x10000106)
396 parse_plbu_viewport_top(fp, (float *)value1, value2);
397 else if ((*value2 & 0xff000fff) == 0x10000107)
398 parse_plbu_viewport_left(fp, (float *)value1, value2);
399 else if ((*value2 & 0xff000fff) == 0x10000108)
400 parse_plbu_viewport_right(fp, (float *)value1, value2);
401 else if ((*value2 & 0xff000fff) == 0x10000109)
402 parse_plbu_tiled_dimensions(fp, value1, value2);
403 else if ((*value2 & 0xff000fff) == 0x1000010a)
404 parse_plbu_unknown_1(fp, value1, value2);
405 else if ((*value2 & 0xff000fff) == 0x1000010b) /* also unknown_2 */
406 parse_plbu_primitive_setup(fp, value1, value2);
407 else if ((*value2 & 0xff000fff) == 0x1000010c)
408 parse_plbu_block_step(fp, value1, value2);
409 else if ((*value2 & 0xff000fff) == 0x1000010d)
410 parse_plbu_low_prim_size(fp, (float *)value1, value2);
411 else if ((*value2 & 0xff000fff) == 0x1000010e)
412 parse_plbu_depth_range_near(fp, (float *)value1, value2);
413 else if ((*value2 & 0xff000fff) == 0x1000010f)
414 parse_plbu_depth_range_far(fp, (float *)value1, value2);
415 else if ((*value2 & 0xff000000) == 0x28000000)
416 parse_plbu_array_address(fp, value1, value2);
417 else if ((*value2 & 0xf0000000) == 0x30000000)
418 parse_plbu_block_stride(fp, value1, value2);
419 else if (*value2 == 0x50000000)
420 parse_plbu_end(fp, value1, value2);
421 else if ((*value2 & 0xf0000000)== 0x60000000)
422 parse_plbu_semaphore(fp, value1, value2);
423 else if ((*value2 & 0xf0000000)== 0x70000000)
424 parse_plbu_scissors(fp, value1, value2);
425 else if ((*value2 & 0xf0000000)== 0x80000000)
426 parse_plbu_rsw_vertex_array(fp, value1, value2);
427 else if ((*value2 & 0xf0000000)== 0xf0000000)
428 parse_plbu_continue(fp, value1, value2);
429 else
430 fprintf(fp, "\t/* --- unknown cmd --- */\n");
431 }
432 fprintf(fp, "/* ============ PLBU CMD STREAM END =============== */\n");
433 fprintf(fp, "\n");
434 }
435
436 static void
parse_rsw(FILE * fp,uint32_t * value,int i,uint32_t * helper)437 parse_rsw(FILE *fp, uint32_t *value, int i, uint32_t *helper)
438 {
439 fprintf(fp, "\t/* %s", render_state_infos[i].info);
440
441 switch (i) {
442 case 0: /* BLEND COLOR BG */
443 fprintf(fp, ": blend_color.color[1] = %f, blend_color.color[2] = %f */\n",
444 (float)(ubyte_to_float((*value & 0xffff0000) >> 16)),
445 (float)(ubyte_to_float(*value & 0x0000ffff)));
446 break;
447 case 1: /* BLEND COLOR RA */
448 fprintf(fp, ": blend_color.color[3] = %f, blend_color.color[0] = %f */\n",
449 (float)(ubyte_to_float((*value & 0xffff0000) >> 16)),
450 (float)(ubyte_to_float(*value & 0x0000ffff)));
451 break;
452 case 2: /* ALPHA BLEND */
453 fprintf(fp, "(1): colormask 0x%02x, rgb_func %d (%s), alpha_func %d (%s) */\n",
454 (*value & 0xf0000000) >> 28, /* colormask */
455 (*value & 0x00000007),
456 lima_get_blend_func_string((*value & 0x00000007)), /* rgb_func */
457 (*value & 0x00000038) >> 3,
458 lima_get_blend_func_string((*value & 0x00000038) >> 3)); /* alpha_func */
459 /* add a few tabs for alignment */
460 fprintf(fp, "\t\t\t\t\t\t/* %s(2)", render_state_infos[i].info);
461 fprintf(fp, ": rgb_src_factor %d (%s), rbg_dst_factor %d (%s) */\n",
462 (*value & 0x000007c0) >> 6,
463 lima_get_blendfactor_string((*value & 0x000007c0) >> 6), /* rgb_src_factor */
464 (*value & 0x0000f800) >> 11,
465 lima_get_blendfactor_string((*value & 0x0000f800) >> 11)); /* rgb_dst_factor */
466 fprintf(fp, "\t\t\t\t\t\t/* %s(3)", render_state_infos[i].info);
467 fprintf(fp, ": alpha_src_factor %d (%s), alpha_dst_factor %d (%s), bits 24-27 0x%02x */\n",
468 (*value & 0x000f0000) >> 16,
469 lima_get_blendfactor_string((*value & 0x000f0000) >> 16), /* alpha_src_factor */
470 (*value & 0x00f00000) >> 20,
471 lima_get_blendfactor_string((*value & 0x00f00000) >> 20), /* alpha_dst_factor */
472 (*value & 0x0f000000) >> 24); /* bits 24-27 */
473 break;
474 case 3: /* DEPTH TEST */
475 if ((*value & 0x00000001) == 0x00000001)
476 fprintf(fp, "(1): depth test enabled && writes allowed");
477 else
478 fprintf(fp, "(1): depth test disabled || writes not allowed");
479
480 fprintf(fp, "\n\t\t\t\t\t\t/* %s(2)", render_state_infos[i].info);
481 fprintf(fp, ": depth_func %d (%s)", ((*value & 0x0000000e) >> 1),
482 lima_get_compare_func_string((*value & 0x0000000e) >> 1));
483 fprintf(fp, ", offset_scale: %d", (*value & 0x00ff0000) >> 16);
484 fprintf(fp, ", offset_units: %d", (*value & 0xff000000) >> 24);
485 if (*value & 0x400)
486 fprintf(fp, ", shader writes depth or stencil");
487 if (*value & 0x800)
488 fprintf(fp, ", shader writes depth");
489 if (*value & 0x1000)
490 fprintf(fp, ", shader writes stencil");
491 fprintf(fp, " */\n\t\t\t\t\t\t/* %s(3)", render_state_infos[i].info);
492 fprintf(fp, ": unknown bits 4-9: 0x%08x", *value & 0x000003f0);
493 fprintf(fp, ", unknown bits 13-15: 0x%08x */\n", *value & 0x00000e000);
494 break;
495 case 4: /* DEPTH RANGE */
496 fprintf(fp, ": viewport.far = %f, viewport.near = %f */\n",
497 (float)(ushort_to_float((*value & 0xffff0000) >> 16)),
498 (float)(ushort_to_float(*value & 0x0000ffff)));
499 break;
500 case 5: /* STENCIL FRONT */
501 fprintf(fp, "(1): valuemask 0x%02x, ref value %d (0x%02x), stencil_func %d (%s)*/\n",
502 (*value & 0xff000000) >> 24, /* valuemask */
503 (*value & 0x00ff0000) >> 16, (*value & 0x00ff0000) >> 16, /* ref value */
504 (*value & 0x00000007),
505 lima_get_compare_func_string((*value & 0x00000007))); /* stencil_func */
506 /* add a few tabs for alignment */
507 fprintf(fp, "\t\t\t\t\t\t/* %s(2)", render_state_infos[i].info);
508 fprintf(fp, ": fail_op %d (%s), zfail_op %d (%s), zpass_op %d (%s), unknown (12-15) 0x%02x */\n",
509 (*value & 0x00000038) >> 3,
510 lima_get_stencil_op_string((*value & 0x00000038) >> 3), /* fail_op */
511 (*value & 0x000001c0) >> 6,
512 lima_get_stencil_op_string((*value & 0x000001c0) >> 6), /* zfail_op */
513 (*value & 0x00000e00) >> 9,
514 lima_get_stencil_op_string((*value & 0x00000e00) >> 9), /* zpass_op */
515 (*value & 0x0000f000) >> 12); /* unknown */
516 break;
517 case 6: /* STENCIL BACK */
518 fprintf(fp, "(1): valuemask 0x%02x, ref value %d (0x%02x), stencil_func %d (%s)*/\n",
519 (*value & 0xff000000) >> 24, /* valuemask */
520 (*value & 0x00ff0000) >> 16, (*value & 0x00ff0000) >> 16, /* ref value */
521 (*value & 0x00000007),
522 lima_get_compare_func_string((*value & 0x00000007))); /* stencil_func */
523 /* add a few tabs for alignment */
524 fprintf(fp, "\t\t\t\t\t\t/* %s(2)", render_state_infos[i].info);
525 fprintf(fp, ": fail_op %d (%s), zfail_op %d (%s), zpass_op %d (%s), unknown (12-15) 0x%02x */\n",
526 (*value & 0x00000038) >> 3,
527 lima_get_stencil_op_string((*value & 0x00000038) >> 3), /* fail_op */
528 (*value & 0x000001c0) >> 6,
529 lima_get_stencil_op_string((*value & 0x000001c0) >> 6), /* zfail_op */
530 (*value & 0x00000e00) >> 9,
531 lima_get_stencil_op_string((*value & 0x00000e00) >> 9), /* zpass_op */
532 (*value & 0x0000f000) >> 12); /* unknown */
533 break;
534 case 7: /* STENCIL TEST */
535 fprintf(fp, "(1): stencil_front writemask 0x%02x, stencil_back writemask 0x%02x */\n",
536 (*value & 0x000000ff), /* front writemask */
537 (*value & 0x0000ff00) >> 8); /* back writemask */
538 /* add a few tabs for alignment */
539 fprintf(fp, "\t\t\t\t\t\t/* %s(2)", render_state_infos[i].info);
540 fprintf(fp, ": unknown (bits 16-31) 0x%04x */\n",
541 (*value & 0xffff0000) >> 16); /* unknown, alpha ref_value? */
542 break;
543 case 8: /* MULTI SAMPLE */
544 if ((*value & 0x00000f00) == 0x00000000)
545 fprintf(fp, ": points");
546 else if ((*value & 0x00000f00) == 0x00000400)
547 fprintf(fp, ": lines");
548 else if ((*value & 0x00000f00) == 0x00000800)
549 fprintf(fp, ": triangles");
550 else
551 fprintf(fp, ": unknown");
552
553 if ((*value & 0x00000078) == 0x00000068)
554 fprintf(fp, ", fb_samples */\n");
555 else if ((*value & 0x00000078) == 0x00000000)
556 fprintf(fp, " */\n");
557 else
558 fprintf(fp, ", UNKNOWN\n");
559 break;
560 case 9: /* SHADER ADDRESS */
561 fprintf(fp, ": fs shader @ 0x%08x, first instr length %d */\n",
562 *value & 0xffffffe0, *value & 0x0000001f);
563 break;
564 case 10: /* VARYING TYPES */
565 fprintf(fp, "(1): ");
566 int val, j;
567 /* 0 - 5 */
568 for (j = 0; j < 6; j++) {
569 val = (*value >> (j * 3)) & 0x07;
570 fprintf(fp, "val %d-%d, ", j, val);
571 }
572 /* 6 - 9 */
573 /* add a few tabs for alignment */
574 fprintf(fp, "\n\t\t\t\t\t\t/* %s(2): ", render_state_infos[i].info);
575 for (j = 6; j < 10; j++) {
576 val = (*value >> (j * 3)) & 0x07;
577 fprintf(fp, "val %d-%d, ", j, val);
578 }
579 /* 10 */
580 val = ((*value & 0xc0000000) >> 30) | ((*helper & 0x00000001) << 2);
581 fprintf(fp, "val %d-%d, ", j, val);
582 j++;
583 /* 11 */
584 val = (*helper & 0x0000000e) >> 1;
585 fprintf(fp, "val %d-%d */\n", j, val);
586 break;
587 case 11: /* UNIFORMS ADDRESS */
588 fprintf(fp, ": pp uniform info @ 0x%08x, bits: 0x%01x */\n",
589 *value & 0xfffffff0, *value & 0x0000000f);
590 break;
591 case 12: /* TEXTURES ADDRESS */
592 fprintf(fp, ": address: 0x%08x */\n", *value);
593 break;
594 case 13: /* AUX0 */
595 fprintf(fp, "(1): varying_stride: %d", /* bits 0 - 4 varying stride, 8 aligned */
596 (*value & 0x0000001f) << 3);
597 if ((*value & 0x00000020) == 0x00000020) /* bit 5 has num_samplers */
598 fprintf(fp, ", num_samplers %d",
599 (*value & 0xffffc000) >> 14); /* bits 14 - 31 num_samplers */
600
601 if ((*value & 0x00000080) == 0x00000080) /* bit 7 has_fs_uniforms */
602 fprintf(fp, ", has_fs_uniforms */");
603 else
604 fprintf(fp, " */");
605
606 fprintf(fp, "\n\t\t\t\t\t\t/* %s(2):", render_state_infos[i].info);
607 if ((*value & 0x00000200) == 0x00000200) /* bit 9 early-z */
608 fprintf(fp, " early-z enabled");
609 else
610 fprintf(fp, " early-z disabled");
611
612 if ((*value & 0x00001000) == 0x00001000) /* bit 12 pixel-kill */
613 fprintf(fp, ", pixel kill enabled");
614 else
615 fprintf(fp, ", pixel kill disabled");
616
617 if ((*value & 0x00000040) == 0x00000040) /* bit 6 unknown */
618 fprintf(fp, ", bit 6 set");
619
620 if ((*value & 0x00000100) == 0x00000100) /* bit 8 unknown */
621 fprintf(fp, ", bit 8 set");
622
623 if (((*value & 0x00000c00) >> 10) > 0) /* bit 10 - 11 unknown */
624 fprintf(fp, ", bit 10 - 11: %d", ((*value & 0x00000c00) >> 10));
625
626 if ((*value & 0x00002000) == 0x00002000) /* bit 13 unknown */
627 fprintf(fp, ", bit 13 set");
628 fprintf(fp, " */\n");
629 break;
630 case 14: /* AUX1 */
631 fprintf(fp, ": ");
632 if ((*value & 0x00002000) == 0x00002000)
633 fprintf(fp, "blend->base.dither true, ");
634 if ((*value & 0x00010000) == 0x00010000)
635 fprintf(fp, "ctx->const_buffer[PIPE_SHADER_FRAGMENT].buffer true ");
636 fprintf(fp, "*/\n");
637 break;
638 case 15: /* VARYINGS ADDRESS */
639 fprintf(fp, ": varyings @ 0x%08x */\n", *value & 0xfffffff0);
640 break;
641 default: /* should never be executed! */
642 fprintf(fp, ": something went wrong!!! */\n");
643 break;
644 }
645 }
646
647 void
lima_parse_render_state(FILE * fp,uint32_t * data,int size,uint32_t start)648 lima_parse_render_state(FILE *fp, uint32_t *data, int size, uint32_t start)
649 {
650 uint32_t *value;
651
652 fprintf(fp, "/* ============ RSW BEGIN ========================= */\n");
653 for (int i = 0; i * 4 < size; i++) {
654 value = &data[i];
655 fprintf(fp, "/* 0x%08x (0x%08x) */\t0x%08x",
656 start + i * 4, i * 4, *value);
657 if (i == 10)
658 parse_rsw(fp, value, i, &data[15]);
659 else
660 parse_rsw(fp, value, i, NULL);
661 }
662 fprintf(fp, "/* ============ RSW END =========================== */\n");
663 }
664
665 static void
parse_texture(FILE * fp,uint32_t * data,uint32_t start,uint32_t offset)666 parse_texture(FILE *fp, uint32_t *data, uint32_t start, uint32_t offset)
667 {
668 uint32_t i = 0;
669 offset /= 4;
670 lima_tex_desc *desc = (lima_tex_desc *)&data[offset];
671
672 /* Word 0 */
673 fprintf(fp, "/* 0x%08x (0x%08x) */\t0x%08x\n",
674 start + i * 4, i * 4, *(&data[i + offset]));
675 i++;
676 fprintf(fp, "\t format: 0x%x (%d)\n", desc->format, desc->format);
677 fprintf(fp, "\t flag1: 0x%x (%d)\n", desc->flag1, desc->flag1);
678 fprintf(fp, "\t swap_r_b: 0x%x (%d)\n", desc->swap_r_b, desc->swap_r_b);
679 fprintf(fp, "\t unknown_0_1: 0x%x (%d)\n", desc->unknown_0_1, desc->unknown_0_1);
680 fprintf(fp, "\t stride: 0x%x (%d)\n", desc->stride, desc->stride);
681 fprintf(fp, "\t unknown_0_2: 0x%x (%d)\n", desc->unknown_0_2, desc->unknown_0_2);
682
683 /* Word 1 - 3 */
684 fprintf(fp, "/* 0x%08x (0x%08x) */\t0x%08x 0x%08x 0x%08x\n",
685 start + i * 4, i * 4, *(&data[i + offset]), *(&data[i + 1 + offset]), *(&data[i + 2 + offset]));
686 i += 3;
687 fprintf(fp, "\t unknown_1_1: 0x%x (%d)\n", desc->unknown_1_1, desc->unknown_1_1);
688 fprintf(fp, "\t unnorm_coords: 0x%x (%d)\n", desc->unnorm_coords, desc->unnorm_coords);
689 fprintf(fp, "\t unknown_1_2: 0x%x (%d)\n", desc->unknown_1_2, desc->unknown_1_2);
690 fprintf(fp, "\t texture_type: 0x%x (%d)\n", desc->texture_type, desc->texture_type);
691 fprintf(fp, "\t min_lod: 0x%x (%d) (%f)\n", desc->min_lod, desc->min_lod, lima_fixed8_to_float(desc->min_lod));
692 fprintf(fp, "\t max_lod: 0x%x (%d) (%f)\n", desc->max_lod, desc->max_lod, lima_fixed8_to_float(desc->max_lod));
693 fprintf(fp, "\t lod_bias: 0x%x (%d) (%f)\n", desc->lod_bias, desc->lod_bias, lima_fixed8_to_float(desc->lod_bias));
694 fprintf(fp, "\t unknown_2_1: 0x%x (%d)\n", desc->unknown_2_1, desc->unknown_2_1);
695 fprintf(fp, "\t has_stride: 0x%x (%d)\n", desc->has_stride, desc->has_stride);
696 fprintf(fp, "\t min_mipfilter_2: 0x%x (%d)\n", desc->min_mipfilter_2, desc->min_mipfilter_2);
697 fprintf(fp, "\t min_img_filter_nearest: 0x%x (%d)\n", desc->min_img_filter_nearest, desc->min_img_filter_nearest);
698 fprintf(fp, "\t mag_img_filter_nearest: 0x%x (%d)\n", desc->mag_img_filter_nearest, desc->mag_img_filter_nearest);
699 fprintf(fp, "\t wrap_s_clamp_to_edge: 0x%x (%d)\n", desc->wrap_s_clamp_to_edge, desc->wrap_s_clamp_to_edge);
700 fprintf(fp, "\t wrap_s_clamp: 0x%x (%d)\n", desc->wrap_s_clamp, desc->wrap_s_clamp);
701 fprintf(fp, "\t wrap_s_mirror_repeat: 0x%x (%d)\n", desc->wrap_s_mirror_repeat, desc->wrap_s_mirror_repeat);
702 fprintf(fp, "\t wrap_t_clamp_to_edge: 0x%x (%d)\n", desc->wrap_t_clamp_to_edge, desc->wrap_t_clamp_to_edge);
703 fprintf(fp, "\t wrap_t_clamp: 0x%x (%d)\n", desc->wrap_t_clamp, desc->wrap_t_clamp);
704 fprintf(fp, "\t wrap_t_mirror_repeat: 0x%x (%d)\n", desc->wrap_t_mirror_repeat, desc->wrap_t_mirror_repeat);
705 fprintf(fp, "\t unknown_2_2: 0x%x (%d)\n", desc->unknown_2_2, desc->unknown_2_2);
706 fprintf(fp, "\t width: 0x%x (%d)\n", desc->width, desc->width);
707 fprintf(fp, "\t height: 0x%x (%d)\n", desc->height, desc->height);
708 fprintf(fp, "\t unknown_3_1: 0x%x (%d)\n", desc->unknown_3_1, desc->unknown_3_1);
709 fprintf(fp, "\t unknown_3_2: 0x%x (%d)\n", desc->unknown_3_2, desc->unknown_3_2);
710
711 /* Word 4 */
712 fprintf(fp, "/* 0x%08x (0x%08x) */\t0x%08x\n",
713 start + i * 4, i * 4, *(&data[i + offset]));
714 i++;
715 fprintf(fp, "\t unknown_4: 0x%x (%d)\n", desc->unknown_4, desc->unknown_4);
716
717 /* Word 5 */
718 fprintf(fp, "/* 0x%08x (0x%08x) */\t0x%08x\n",
719 start + i * 4, i * 4, *(&data[i + offset]));
720 i++;
721 fprintf(fp, "\t unknown_5: 0x%x (%d)\n", desc->unknown_5, desc->unknown_5);
722
723 /* Word 6 - */
724 fprintf(fp, "/* 0x%08x (0x%08x) */",
725 start + i * 4, i * 4);
726 fprintf(fp, "\t");
727
728 int miplevels = (int)lima_fixed8_to_float(desc->max_lod);
729 for (int k = 0; k < ((((miplevels + 1) * 26) + 64) / 32); k++)
730 fprintf(fp, "0x%08x ", *(&data[i + offset + k]));
731 fprintf(fp, "\n");
732
733 i++;
734 fprintf(fp, "\t unknown_6_1: 0x%x (%d)\n", desc->va_s.unknown_6_1, desc->va_s.unknown_6_1);
735 fprintf(fp, "\t layout: 0x%x (%d)\n", desc->va_s.layout, desc->va_s.layout);
736 fprintf(fp, "\t unknown_6_2: 0x%x (%d)\n", desc->va_s.unknown_6_2, desc->va_s.unknown_6_2);
737 fprintf(fp, "\t unknown_6_3: 0x%x (%d)\n", desc->va_s.unknown_6_3, desc->va_s.unknown_6_3);
738
739 /* first level */
740 fprintf(fp, "\t va_0: 0x%x \n", desc->va_s.va_0 << 6);
741
742 /* second level up to desc->miplevels */
743 int j;
744 unsigned va_bit_idx;
745 unsigned va_idx;
746 uint32_t va;
747 uint32_t va_1;
748 uint32_t va_2;
749 for (j = 1; j <= miplevels; j++) {
750 va = 0;
751 va_1 = 0;
752 va_2 = 0;
753
754 va_bit_idx = VA_BIT_OFFSET + (VA_BIT_SIZE * j);
755 va_idx = va_bit_idx / 32;
756 va_bit_idx %= 32;
757
758 /* the first (32 - va_bit_idx) bits */
759 va_1 |= (*(&data[i + offset + va_idx - 1]) >> va_bit_idx);
760
761 /* do we need some bits from the following word? */
762 if (va_bit_idx > 6) {
763 /* shift left and right again to erase the unneeded bits, keep space for va1 */
764 va_2 |= (*(&data[i + offset + va_idx]) << (2 * 32 - VA_BIT_SIZE - va_bit_idx));
765 va_2 >>= ((2 * 32 - VA_BIT_SIZE - va_bit_idx) - (32 - va_bit_idx));
766 va |= va_2;
767 }
768 va |= va_1;
769 va <<= 6;
770 fprintf(fp, "\t va_%d: 0x%x \n", j, va);
771 }
772 }
773
774 void
lima_parse_texture_descriptor(FILE * fp,uint32_t * data,int size,uint32_t start,uint32_t offset)775 lima_parse_texture_descriptor(FILE *fp, uint32_t *data, int size, uint32_t start, uint32_t offset)
776 {
777 fprintf(fp, "/* ============ TEXTURE BEGIN ===================== */\n");
778 parse_texture(fp, data, start, offset);
779 fprintf(fp, "/* ============ TEXTURE END ======================= */\n");
780 }
781