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