Path: blob/21.2-virgl/src/gallium/drivers/lima/lima_parser.c
4565 views
/*1* Copyright (c) 2019 Andreas Baierl <[email protected]>2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sub license,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the11* next paragraph) shall be included in all copies or substantial portions12* of the Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER20* DEALINGS IN THE SOFTWARE.21*22*/2324#include "util/u_math.h"2526#include <stdio.h>27#include <stdint.h>28#include <string.h>2930#include "lima_context.h"31#include "lima_parser.h"32#include "lima_texture.h"3334typedef struct {35char *info;36} render_state_info;3738static render_state_info render_state_infos[] = {39{ .info = "BLEND_COLOR_BG", },40{ .info = "BLEND_COLOR_RA", },41{ .info = "ALPHA_BLEND", },42{ .info = "DEPTH_TEST", },43{ .info = "DEPTH_RANGE", },44{ .info = "STENCIL_FRONT", },45{ .info = "STENCIL_BACK", },46{ .info = "STENCIL_TEST", },47{ .info = "MULTI_SAMPLE", },48{ .info = "SHADER_ADDRESS (FS)", },49{ .info = "VARYING_TYPES", },50{ .info = "UNIFORMS_ADDRESS (PP)", },51{ .info = "TEXTURES_ADDRESS", },52{ .info = "AUX0", },53{ .info = "AUX1", },54{ .info = "VARYINGS_ADDRESS", },55};5657/* VS CMD stream parser functions */5859static void60parse_vs_draw(FILE *fp, uint32_t *value1, uint32_t *value2)61{62if ((*value1 == 0x00000000) && (*value2 == 0x00000000))63fprintf(fp, "\t/* ---EMPTY CMD */\n");64else65fprintf(fp, "\t/* DRAW: num: %d, index_draw: %s */\n",66(*value1 & 0xff000000) >> 24 | (*value2 & 0x000000ff) << 8,67(*value1 & 0x00000001) ? "true" : "false");68}6970static void71parse_vs_shader_info(FILE *fp, uint32_t *value1, uint32_t *value2)72{73fprintf(fp, "\t/* SHADER_INFO: prefetch: %d, size: %d */\n",74(*value1 & 0xfff00000) >> 20,75(((*value1 & 0x000fffff) >> 10) + 1) << 4);76}7778static void79parse_vs_unknown1(FILE *fp, uint32_t *value1, uint32_t *value2)80{81fprintf(fp, "\t/* UNKNOWN_1 */\n");82}8384static void85parse_vs_varying_attribute_count(FILE *fp, uint32_t *value1, uint32_t *value2)86{87fprintf(fp, "\t/* VARYING_ATTRIBUTE_COUNT: nr_vary: %d, nr_attr: %d */\n",88((*value1 & 0x00ffffff) >> 8) + 1, (*value1 >> 24) + 1);89}9091static void92parse_vs_attributes_address(FILE *fp, uint32_t *value1, uint32_t *value2)93{94fprintf(fp, "\t/* ATTRIBUTES_ADDRESS: address: 0x%08x, size: %d */\n",95*value1, (*value2 & 0x0fffffff) >> 17);96}9798static void99parse_vs_varyings_address(FILE *fp, uint32_t *value1, uint32_t *value2)100{101fprintf(fp, "\t/* VARYINGS_ADDRESS: varying info @ 0x%08x, size: %d */\n",102*value1, (*value2 & 0x0fffffff) >> 17);103}104105static void106parse_vs_uniforms_address(FILE *fp, uint32_t *value1, uint32_t *value2)107{108fprintf(fp, "\t/* UNIFORMS_ADDRESS (GP): address: 0x%08x, size: %d */\n",109*value1, (*value2 & 0x0fffffff) >> 12);110}111112static void113parse_vs_shader_address(FILE *fp, uint32_t *value1, uint32_t *value2)114{115fprintf(fp, "\t/* SHADER_ADDRESS (VS): address: 0x%08x, size: %d */\n",116*value1, (*value2 & 0x0fffffff) >> 12);117}118119static void120parse_vs_semaphore(FILE *fp, uint32_t *value1, uint32_t *value2)121{122if (*value1 == 0x00028000)123fprintf(fp, "\t/* SEMAPHORE_BEGIN_1 */\n");124else if (*value1 == 0x00000001)125fprintf(fp, "\t/* SEMAPHORE_BEGIN_2 */\n");126else if (*value1 == 0x00000000)127fprintf(fp, "\t/* SEMAPHORE_END: index_draw disabled */\n");128else if (*value1 == 0x00018000)129fprintf(fp, "\t/* SEMAPHORE_END: index_draw enabled */\n");130else131fprintf(fp, "\t/* SEMAPHORE - cmd unknown! */\n");132}133134static void135parse_vs_unknown2(FILE *fp, uint32_t *value1, uint32_t *value2)136{137fprintf(fp, "\t/* UNKNOWN_2 */\n");138}139140static void141parse_vs_continue(FILE *fp, uint32_t *value1, uint32_t *value2)142{143fprintf(fp, "\t/* CONTINUE: at 0x%08x */\n", *value1);144}145146void147lima_parse_vs(FILE *fp, uint32_t *data, int size, uint32_t start)148{149uint32_t *value1;150uint32_t *value2;151152fprintf(fp, "\n");153fprintf(fp, "/* ============ VS CMD STREAM BEGIN ============= */\n");154for (int i = 0; i * 4 < size; i += 2) {155value1 = &data[i];156value2 = &data[i + 1];157fprintf(fp, "/* 0x%08x (0x%08x) */\t0x%08x 0x%08x",158start + i * 4, i * 4, *value1, *value2);159160if ((*value2 & 0xffff0000) == 0x00000000)161parse_vs_draw(fp, value1, value2);162else if ((*value2 & 0xff0000ff) == 0x10000040)163parse_vs_shader_info(fp, value1, value2);164else if ((*value2 & 0xff0000ff) == 0x10000041)165parse_vs_unknown1(fp, value1, value2);166else if ((*value2 & 0xff0000ff) == 0x10000042)167parse_vs_varying_attribute_count(fp, value1, value2);168else if ((*value2 & 0xff0000ff) == 0x20000000)169parse_vs_attributes_address(fp, value1, value2);170else if ((*value2 & 0xff0000ff) == 0x20000008)171parse_vs_varyings_address(fp, value1, value2);172else if ((*value2 & 0xff000000) == 0x30000000)173parse_vs_uniforms_address(fp, value1, value2);174else if ((*value2 & 0xff000000) == 0x40000000)175parse_vs_shader_address(fp, value1, value2);176else if ((*value2 & 0xff000000)== 0x50000000)177parse_vs_semaphore(fp, value1, value2);178else if ((*value2 & 0xff000000) == 0x60000000)179parse_vs_unknown2(fp, value1, value2);180else if ((*value2 & 0xff000000) == 0xf0000000)181parse_vs_continue(fp, value1, value2);182else183fprintf(fp, "\t/* --- unknown cmd --- */\n");184}185fprintf(fp, "/* ============ VS CMD STREAM END =============== */\n");186fprintf(fp, "\n");187}188189/* PLBU CMD stream parser functions */190191static void192parse_plbu_block_step(FILE *fp, uint32_t *value1, uint32_t *value2)193{194fprintf(fp, "\t/* BLOCK_STEP: shift_min: %d, shift_h: %d, shift_w: %d */\n",195(*value1 & 0xf0000000) >> 28,196(*value1 & 0x0fff0000) >> 16,197*value1 & 0x0000ffff);198}199200static void201parse_plbu_tiled_dimensions(FILE *fp, uint32_t *value1, uint32_t *value2)202{203fprintf(fp, "\t/* TILED_DIMENSIONS: tiled_w: %d, tiled_h: %d */\n",204((*value1 & 0xff000000) >> 24) + 1,205((*value1 & 0x00ffff00) >> 8) + 1);206}207208static void209parse_plbu_block_stride(FILE *fp, uint32_t *value1, uint32_t *value2)210{211fprintf(fp, "\t/* BLOCK_STRIDE: block_w: %d */\n", *value1 & 0x000000ff);212}213214static void215parse_plbu_array_address(FILE *fp, uint32_t *value1, uint32_t *value2)216{217fprintf(fp, "\t/* ARRAY_ADDRESS: gp_stream: 0x%08x, block_num (block_w * block_h): %d */\n",218*value1, (*value2 & 0x00ffffff) + 1);219}220221static void222parse_plbu_viewport_left(FILE *fp, float *value1, uint32_t *value2)223{224fprintf(fp, "\t/* VIEWPORT_LEFT: viewport_left: %f */\n", *value1);225}226227static void228parse_plbu_viewport_right(FILE *fp, float *value1, uint32_t *value2)229{230fprintf(fp, "\t/* VIEWPORT_RIGHT: viewport_right: %f */\n", *value1);231}232233static void234parse_plbu_viewport_bottom(FILE *fp, float *value1, uint32_t *value2)235{236fprintf(fp, "\t/* VIEWPORT_BOTTOM: viewport_bottom: %f */\n", *value1);237}238239static void240parse_plbu_viewport_top(FILE *fp, float *value1, uint32_t *value2)241{242fprintf(fp, "\t/* VIEWPORT_TOP: viewport_top: %f */\n", *value1);243}244245static void246parse_plbu_semaphore(FILE *fp, uint32_t *value1, uint32_t *value2)247{248if (*value1 == 0x00010002)249fprintf(fp, "\t/* ARRAYS_SEMAPHORE_BEGIN */\n");250else if (*value1 == 0x00010001)251fprintf(fp, "\t/* ARRAYS_SEMAPHORE_END */\n");252else253fprintf(fp, "\t/* SEMAPHORE - cmd unknown! */\n");254}255256static void257parse_plbu_primitive_setup(FILE *fp, uint32_t *value1, uint32_t *value2)258{259if (*value1 == 0x00000200)260fprintf(fp, "\t/* UNKNOWN_2 (PRIMITIVE_SETUP INIT?) */\n");261else262fprintf(fp, "\t/* PRIMITIVE_SETUP: %scull: %d (0x%x), index_size: %d */\n",263(*value1 & 0x1000) ? "force point size, " : "",264(*value1 & 0x000f0000) >> 16, (*value1 & 0x000f0000) >> 16,265(*value1 & 0x00000e00) >> 9);266}267268static void269parse_plbu_rsw_vertex_array(FILE *fp, uint32_t *value1, uint32_t *value2)270{271fprintf(fp, "\t/* RSW_VERTEX_ARRAY: rsw: 0x%08x, gl_pos: 0x%08x */\n",272*value1,273(*value2 & 0x0fffffff) << 4);274}275276static void277parse_plbu_scissors(FILE *fp, uint32_t *value1, uint32_t *value2)278{279float minx = (*value1 & 0xc0000000) >> 30 | (*value2 & 0x00001fff) << 2;280float maxx = ((*value2 & 0x0fffe000) >> 13) + 1;281float miny = *value1 & 0x00003fff;282float maxy = ((*value1 & 0x3fff8000) >> 15) + 1;283284fprintf(fp, "\t/* SCISSORS: minx: %f, maxx: %f, miny: %f, maxy: %f */\n",285minx, maxx, miny, maxy);286}287288static void289parse_plbu_unknown_1(FILE *fp, uint32_t *value1, uint32_t *value2)290{291fprintf(fp, "\t/* UNKNOWN_1 */\n");292}293294static void295parse_plbu_low_prim_size(FILE *fp, float *value1, uint32_t *value2)296{297fprintf(fp, "\t/* LOW_PRIM_SIZE: size: %f */\n", *value1);298}299300static void301parse_plbu_depth_range_near(FILE *fp, float *value1, uint32_t *value2)302{303fprintf(fp, "\t/* DEPTH_RANG_NEAR: depth_range: %f */\n", *value1);304}305306static void307parse_plbu_depth_range_far(FILE *fp, float *value1, uint32_t *value2)308{309fprintf(fp, "\t/* DEPTH_RANGE_FAR: depth_range: %f */\n", *value1);310}311312static void313parse_plbu_indexed_dest(FILE *fp, uint32_t *value1, uint32_t *value2)314{315fprintf(fp, "\t/* INDEXED_DEST: gl_pos: 0x%08x */\n", *value1);316}317318static void319parse_plbu_indexed_pt_size(FILE *fp, uint32_t *value1, uint32_t *value2)320{321fprintf(fp, "\t/* INDEXED_PT_SIZE: pt_size: 0x%08x */\n", *value1);322}323324static void325parse_plbu_indices(FILE *fp, uint32_t *value1, uint32_t *value2)326{327fprintf(fp, "\t/* INDICES: indices: 0x%08x */\n", *value1);328}329330static void331parse_plbu_draw_arrays(FILE *fp, uint32_t *value1, uint32_t *value2)332{333if ((*value1 == 0x00000000) && (*value2 == 0x00000000)) {334fprintf(fp, "\t/* ---EMPTY CMD */\n");335return;336}337338uint32_t count = (*value1 & 0xff000000) >> 24 | (*value2 & 0x000000ff) << 8;339uint32_t start = *value1 & 0x00ffffff;340uint32_t mode = (*value2 & 0x001f0000) >> 16;341342fprintf(fp, "\t/* DRAW_ARRAYS: count: %d, start: %d, mode: %d (0x%x) */\n",343count, start, mode, mode);344}345346static void347parse_plbu_draw_elements(FILE *fp, uint32_t *value1, uint32_t *value2)348{349uint32_t count = (*value1 & 0xff000000) >> 24 | (*value2 & 0x000000ff) << 8;350uint32_t start = *value1 & 0x00ffffff;351uint32_t mode = (*value2 & 0x001f0000) >> 16;352353fprintf(fp, "\t/* DRAW_ELEMENTS: count: %d, start: %d, mode: %d (0x%x) */\n",354count, start, mode, mode);355}356357static void358parse_plbu_continue(FILE *fp, uint32_t *value1, uint32_t *value2)359{360fprintf(fp, "\t/* CONTINUE: continue at 0x%08x */\n", *value1);361}362363static void364parse_plbu_end(FILE *fp, uint32_t *value1, uint32_t *value2)365{366fprintf(fp, "\t/* END (FINISH/FLUSH) */\n");367}368369void370lima_parse_plbu(FILE *fp, uint32_t *data, int size, uint32_t start)371{372uint32_t *value1;373uint32_t *value2;374375fprintf(fp, "/* ============ PLBU CMD STREAM BEGIN ============= */\n");376for (int i = 0; i * 4 < size; i += 2) {377value1 = &data[i];378value2 = &data[i + 1];379fprintf(fp, "/* 0x%08x (0x%08x) */\t0x%08x 0x%08x",380start + i * 4, i * 4, *value1, *value2);381382if ((*value2 & 0xffe00000) == 0x00000000)383parse_plbu_draw_arrays(fp, value1, value2);384else if ((*value2 & 0xffe00000) == 0x00200000)385parse_plbu_draw_elements(fp, value1, value2);386else if ((*value2 & 0xff000fff) == 0x10000100)387parse_plbu_indexed_dest(fp, value1, value2);388else if ((*value2 & 0xff000fff) == 0x10000101)389parse_plbu_indices(fp, value1, value2);390else if ((*value2 & 0xff000fff) == 0x10000102)391parse_plbu_indexed_pt_size(fp, value1, value2);392else if ((*value2 & 0xff000fff) == 0x10000105)393parse_plbu_viewport_bottom(fp, (float *)value1, value2);394else if ((*value2 & 0xff000fff) == 0x10000106)395parse_plbu_viewport_top(fp, (float *)value1, value2);396else if ((*value2 & 0xff000fff) == 0x10000107)397parse_plbu_viewport_left(fp, (float *)value1, value2);398else if ((*value2 & 0xff000fff) == 0x10000108)399parse_plbu_viewport_right(fp, (float *)value1, value2);400else if ((*value2 & 0xff000fff) == 0x10000109)401parse_plbu_tiled_dimensions(fp, value1, value2);402else if ((*value2 & 0xff000fff) == 0x1000010a)403parse_plbu_unknown_1(fp, value1, value2);404else if ((*value2 & 0xff000fff) == 0x1000010b) /* also unknown_2 */405parse_plbu_primitive_setup(fp, value1, value2);406else if ((*value2 & 0xff000fff) == 0x1000010c)407parse_plbu_block_step(fp, value1, value2);408else if ((*value2 & 0xff000fff) == 0x1000010d)409parse_plbu_low_prim_size(fp, (float *)value1, value2);410else if ((*value2 & 0xff000fff) == 0x1000010e)411parse_plbu_depth_range_near(fp, (float *)value1, value2);412else if ((*value2 & 0xff000fff) == 0x1000010f)413parse_plbu_depth_range_far(fp, (float *)value1, value2);414else if ((*value2 & 0xff000000) == 0x28000000)415parse_plbu_array_address(fp, value1, value2);416else if ((*value2 & 0xf0000000) == 0x30000000)417parse_plbu_block_stride(fp, value1, value2);418else if (*value2 == 0x50000000)419parse_plbu_end(fp, value1, value2);420else if ((*value2 & 0xf0000000)== 0x60000000)421parse_plbu_semaphore(fp, value1, value2);422else if ((*value2 & 0xf0000000)== 0x70000000)423parse_plbu_scissors(fp, value1, value2);424else if ((*value2 & 0xf0000000)== 0x80000000)425parse_plbu_rsw_vertex_array(fp, value1, value2);426else if ((*value2 & 0xf0000000)== 0xf0000000)427parse_plbu_continue(fp, value1, value2);428else429fprintf(fp, "\t/* --- unknown cmd --- */\n");430}431fprintf(fp, "/* ============ PLBU CMD STREAM END =============== */\n");432fprintf(fp, "\n");433}434435static void436parse_rsw(FILE *fp, uint32_t *value, int i, uint32_t *helper)437{438fprintf(fp, "\t/* %s", render_state_infos[i].info);439440switch (i) {441case 0: /* BLEND COLOR BG */442fprintf(fp, ": blend_color.color[1] = %f, blend_color.color[2] = %f */\n",443(float)(ubyte_to_float((*value & 0xffff0000) >> 16)),444(float)(ubyte_to_float(*value & 0x0000ffff)));445break;446case 1: /* BLEND COLOR RA */447fprintf(fp, ": blend_color.color[3] = %f, blend_color.color[0] = %f */\n",448(float)(ubyte_to_float((*value & 0xffff0000) >> 16)),449(float)(ubyte_to_float(*value & 0x0000ffff)));450break;451case 2: /* ALPHA BLEND */452fprintf(fp, "(1): colormask 0x%02x, rgb_func %d (%s), alpha_func %d (%s) */\n",453(*value & 0xf0000000) >> 28, /* colormask */454(*value & 0x00000007),455lima_get_blend_func_string((*value & 0x00000007)), /* rgb_func */456(*value & 0x00000038) >> 3,457lima_get_blend_func_string((*value & 0x00000038) >> 3)); /* alpha_func */458/* add a few tabs for alignment */459fprintf(fp, "\t\t\t\t\t\t/* %s(2)", render_state_infos[i].info);460fprintf(fp, ": rgb_src_factor %d (%s), rbg_dst_factor %d (%s) */\n",461(*value & 0x000007c0) >> 6,462lima_get_blendfactor_string((*value & 0x000007c0) >> 6), /* rgb_src_factor */463(*value & 0x0000f800) >> 11,464lima_get_blendfactor_string((*value & 0x0000f800) >> 11)); /* rgb_dst_factor */465fprintf(fp, "\t\t\t\t\t\t/* %s(3)", render_state_infos[i].info);466fprintf(fp, ": alpha_src_factor %d (%s), alpha_dst_factor %d (%s), bits 24-27 0x%02x */\n",467(*value & 0x000f0000) >> 16,468lima_get_blendfactor_string((*value & 0x000f0000) >> 16), /* alpha_src_factor */469(*value & 0x00f00000) >> 20,470lima_get_blendfactor_string((*value & 0x00f00000) >> 20), /* alpha_dst_factor */471(*value & 0x0f000000) >> 24); /* bits 24-27 */472break;473case 3: /* DEPTH TEST */474if ((*value & 0x00000001) == 0x00000001)475fprintf(fp, "(1): depth test enabled && writes allowed");476else477fprintf(fp, "(1): depth test disabled || writes not allowed");478479fprintf(fp, "\n\t\t\t\t\t\t/* %s(2)", render_state_infos[i].info);480fprintf(fp, ": depth_func %d (%s)", ((*value & 0x0000000e) >> 1),481lima_get_compare_func_string((*value & 0x0000000e) >> 1));482fprintf(fp, ", offset_scale: %d", (*value & 0x00ff0000) >> 16);483fprintf(fp, ", offset_units: %d", (*value & 0xff000000) >> 24);484if (*value & 0x400)485fprintf(fp, ", shader writes depth or stencil");486if (*value & 0x800)487fprintf(fp, ", shader writes depth");488if (*value & 0x1000)489fprintf(fp, ", shader writes stencil");490fprintf(fp, " */\n\t\t\t\t\t\t/* %s(3)", render_state_infos[i].info);491fprintf(fp, ": unknown bits 4-9: 0x%08x", *value & 0x000003f0);492fprintf(fp, ", unknown bits 13-15: 0x%08x */\n", *value & 0x00000e000);493break;494case 4: /* DEPTH RANGE */495fprintf(fp, ": viewport.far = %f, viewport.near = %f */\n",496(float)(ushort_to_float((*value & 0xffff0000) >> 16)),497(float)(ushort_to_float(*value & 0x0000ffff)));498break;499case 5: /* STENCIL FRONT */500fprintf(fp, "(1): valuemask 0x%02x, ref value %d (0x%02x), stencil_func %d (%s)*/\n",501(*value & 0xff000000) >> 24, /* valuemask */502(*value & 0x00ff0000) >> 16, (*value & 0x00ff0000) >> 16, /* ref value */503(*value & 0x00000007),504lima_get_compare_func_string((*value & 0x00000007))); /* stencil_func */505/* add a few tabs for alignment */506fprintf(fp, "\t\t\t\t\t\t/* %s(2)", render_state_infos[i].info);507fprintf(fp, ": fail_op %d (%s), zfail_op %d (%s), zpass_op %d (%s), unknown (12-15) 0x%02x */\n",508(*value & 0x00000038) >> 3,509lima_get_stencil_op_string((*value & 0x00000038) >> 3), /* fail_op */510(*value & 0x000001c0) >> 6,511lima_get_stencil_op_string((*value & 0x000001c0) >> 6), /* zfail_op */512(*value & 0x00000e00) >> 9,513lima_get_stencil_op_string((*value & 0x00000e00) >> 9), /* zpass_op */514(*value & 0x0000f000) >> 12); /* unknown */515break;516case 6: /* STENCIL BACK */517fprintf(fp, "(1): valuemask 0x%02x, ref value %d (0x%02x), stencil_func %d (%s)*/\n",518(*value & 0xff000000) >> 24, /* valuemask */519(*value & 0x00ff0000) >> 16, (*value & 0x00ff0000) >> 16, /* ref value */520(*value & 0x00000007),521lima_get_compare_func_string((*value & 0x00000007))); /* stencil_func */522/* add a few tabs for alignment */523fprintf(fp, "\t\t\t\t\t\t/* %s(2)", render_state_infos[i].info);524fprintf(fp, ": fail_op %d (%s), zfail_op %d (%s), zpass_op %d (%s), unknown (12-15) 0x%02x */\n",525(*value & 0x00000038) >> 3,526lima_get_stencil_op_string((*value & 0x00000038) >> 3), /* fail_op */527(*value & 0x000001c0) >> 6,528lima_get_stencil_op_string((*value & 0x000001c0) >> 6), /* zfail_op */529(*value & 0x00000e00) >> 9,530lima_get_stencil_op_string((*value & 0x00000e00) >> 9), /* zpass_op */531(*value & 0x0000f000) >> 12); /* unknown */532break;533case 7: /* STENCIL TEST */534fprintf(fp, "(1): stencil_front writemask 0x%02x, stencil_back writemask 0x%02x */\n",535(*value & 0x000000ff), /* front writemask */536(*value & 0x0000ff00) >> 8); /* back writemask */537/* add a few tabs for alignment */538fprintf(fp, "\t\t\t\t\t\t/* %s(2)", render_state_infos[i].info);539fprintf(fp, ": alpha_ref_value: 0x%02x */\n", (*value & 0x00ff0000) >> 16);540fprintf(fp, "\t\t\t\t\t\t/* %s(3)", render_state_infos[i].info);541fprintf(fp, ": unknown (bits 24-31) 0x%02x */\n",542(*value & 0xff000000) >> 24); /* unknown */543break;544case 8: /* MULTI SAMPLE */545if ((*value & 0x00000f00) == 0x00000000)546fprintf(fp, ": points");547else if ((*value & 0x00000f00) == 0x00000400)548fprintf(fp, ": lines");549else if ((*value & 0x00000f00) == 0x00000800)550fprintf(fp, ": triangles");551else552fprintf(fp, ": unknown");553554if ((*value & 0x00000078) == 0x00000068)555fprintf(fp, ", fb_samples */\n");556else if ((*value & 0x00000078) == 0x00000000)557fprintf(fp, " */\n");558else559fprintf(fp, ", UNKNOWN\n");560fprintf(fp, "\t\t\t\t\t\t/* %s(2)", render_state_infos[i].info);561fprintf(fp, ": alpha_test_func: %d (%s) */\n",562(*value & 0x00000007),563lima_get_compare_func_string((*value & 0x00000007))); /* alpha_test_func */564break;565case 9: /* SHADER ADDRESS */566fprintf(fp, ": fs shader @ 0x%08x, first instr length %d */\n",567*value & 0xffffffe0, *value & 0x0000001f);568break;569case 10: /* VARYING TYPES */570fprintf(fp, "(1): ");571int val, j;572/* 0 - 5 */573for (j = 0; j < 6; j++) {574val = (*value >> (j * 3)) & 0x07;575fprintf(fp, "val %d-%d, ", j, val);576}577/* 6 - 9 */578/* add a few tabs for alignment */579fprintf(fp, "\n\t\t\t\t\t\t/* %s(2): ", render_state_infos[i].info);580for (j = 6; j < 10; j++) {581val = (*value >> (j * 3)) & 0x07;582fprintf(fp, "val %d-%d, ", j, val);583}584/* 10 */585val = ((*value & 0xc0000000) >> 30) | ((*helper & 0x00000001) << 2);586fprintf(fp, "val %d-%d, ", j, val);587j++;588/* 11 */589val = (*helper & 0x0000000e) >> 1;590fprintf(fp, "val %d-%d */\n", j, val);591break;592case 11: /* UNIFORMS ADDRESS */593fprintf(fp, ": pp uniform info @ 0x%08x, bits: 0x%01x */\n",594*value & 0xfffffff0, *value & 0x0000000f);595break;596case 12: /* TEXTURES ADDRESS */597fprintf(fp, ": address: 0x%08x */\n", *value);598break;599case 13: /* AUX0 */600fprintf(fp, "(1): varying_stride: %d", /* bits 0 - 4 varying stride, 8 aligned */601(*value & 0x0000001f) << 3);602if ((*value & 0x00000020) == 0x00000020) /* bit 5 has num_samplers */603fprintf(fp, ", num_samplers %d",604(*value & 0xffffc000) >> 14); /* bits 14 - 31 num_samplers */605606if ((*value & 0x00000080) == 0x00000080) /* bit 7 has_fs_uniforms */607fprintf(fp, ", has_fs_uniforms */");608else609fprintf(fp, " */");610611fprintf(fp, "\n\t\t\t\t\t\t/* %s(2):", render_state_infos[i].info);612if ((*value & 0x00000200) == 0x00000200) /* bit 9 early-z */613fprintf(fp, " early-z enabled");614else615fprintf(fp, " early-z disabled");616617if ((*value & 0x00001000) == 0x00001000) /* bit 12 pixel-kill */618fprintf(fp, ", pixel kill enabled");619else620fprintf(fp, ", pixel kill disabled");621622if ((*value & 0x00000040) == 0x00000040) /* bit 6 unknown */623fprintf(fp, ", bit 6 set");624625if ((*value & 0x00000100) == 0x00000100) /* bit 8 unknown */626fprintf(fp, ", bit 8 set");627628if (((*value & 0x00000c00) >> 10) > 0) /* bit 10 - 11 unknown */629fprintf(fp, ", bit 10 - 11: %d", ((*value & 0x00000c00) >> 10));630631if ((*value & 0x00002000) == 0x00002000) /* bit 13 unknown */632fprintf(fp, ", bit 13 set");633fprintf(fp, " */\n");634break;635case 14: /* AUX1 */636fprintf(fp, ": ");637if ((*value & 0x00002000) == 0x00002000)638fprintf(fp, "blend->base.dither true, ");639if ((*value & 0x00010000) == 0x00010000)640fprintf(fp, "ctx->const_buffer[PIPE_SHADER_FRAGMENT].buffer true ");641fprintf(fp, "*/\n");642break;643case 15: /* VARYINGS ADDRESS */644fprintf(fp, ": varyings @ 0x%08x */\n", *value & 0xfffffff0);645break;646default: /* should never be executed! */647fprintf(fp, ": something went wrong!!! */\n");648break;649}650}651652void653lima_parse_render_state(FILE *fp, uint32_t *data, int size, uint32_t start)654{655uint32_t *value;656657fprintf(fp, "/* ============ RSW BEGIN ========================= */\n");658for (int i = 0; i * 4 < size; i++) {659value = &data[i];660fprintf(fp, "/* 0x%08x (0x%08x) */\t0x%08x",661start + i * 4, i * 4, *value);662if (i == 10)663parse_rsw(fp, value, i, &data[15]);664else665parse_rsw(fp, value, i, NULL);666}667fprintf(fp, "/* ============ RSW END =========================== */\n");668}669670static void671parse_texture(FILE *fp, uint32_t *data, uint32_t start, uint32_t offset)672{673uint32_t i = 0;674offset /= 4;675lima_tex_desc *desc = (lima_tex_desc *)&data[offset];676677/* Word 0 */678fprintf(fp, "/* 0x%08x (0x%08x) */\t0x%08x\n",679start + i * 4, i * 4, *(&data[i + offset]));680i++;681fprintf(fp, "\t format: 0x%x (%d)\n", desc->format, desc->format);682fprintf(fp, "\t flag1: 0x%x (%d)\n", desc->flag1, desc->flag1);683fprintf(fp, "\t swap_r_b: 0x%x (%d)\n", desc->swap_r_b, desc->swap_r_b);684fprintf(fp, "\t unknown_0_1: 0x%x (%d)\n", desc->unknown_0_1, desc->unknown_0_1);685fprintf(fp, "\t stride: 0x%x (%d)\n", desc->stride, desc->stride);686fprintf(fp, "\t unknown_0_2: 0x%x (%d)\n", desc->unknown_0_2, desc->unknown_0_2);687688/* Word 1 - 3 */689fprintf(fp, "/* 0x%08x (0x%08x) */\t0x%08x 0x%08x 0x%08x\n",690start + i * 4, i * 4, *(&data[i + offset]), *(&data[i + 1 + offset]), *(&data[i + 2 + offset]));691i += 3;692fprintf(fp, "\t unknown_1_1: 0x%x (%d)\n", desc->unknown_1_1, desc->unknown_1_1);693fprintf(fp, "\t unnorm_coords: 0x%x (%d)\n", desc->unnorm_coords, desc->unnorm_coords);694fprintf(fp, "\t unknown_1_2: 0x%x (%d)\n", desc->unknown_1_2, desc->unknown_1_2);695fprintf(fp, "\t texture_type: 0x%x (%d)\n", desc->texture_type, desc->texture_type);696fprintf(fp, "\t min_lod: 0x%x (%d) (%f)\n", desc->min_lod, desc->min_lod, lima_fixed8_to_float(desc->min_lod));697fprintf(fp, "\t max_lod: 0x%x (%d) (%f)\n", desc->max_lod, desc->max_lod, lima_fixed8_to_float(desc->max_lod));698fprintf(fp, "\t lod_bias: 0x%x (%d) (%f)\n", desc->lod_bias, desc->lod_bias, lima_fixed8_to_float(desc->lod_bias));699fprintf(fp, "\t unknown_2_1: 0x%x (%d)\n", desc->unknown_2_1, desc->unknown_2_1);700fprintf(fp, "\t has_stride: 0x%x (%d)\n", desc->has_stride, desc->has_stride);701fprintf(fp, "\t min_mipfilter_2: 0x%x (%d)\n", desc->min_mipfilter_2, desc->min_mipfilter_2);702fprintf(fp, "\t min_img_filter_nearest: 0x%x (%d)\n", desc->min_img_filter_nearest, desc->min_img_filter_nearest);703fprintf(fp, "\t mag_img_filter_nearest: 0x%x (%d)\n", desc->mag_img_filter_nearest, desc->mag_img_filter_nearest);704fprintf(fp, "\t wrap_s_clamp_to_edge: 0x%x (%d)\n", desc->wrap_s_clamp_to_edge, desc->wrap_s_clamp_to_edge);705fprintf(fp, "\t wrap_s_clamp: 0x%x (%d)\n", desc->wrap_s_clamp, desc->wrap_s_clamp);706fprintf(fp, "\t wrap_s_mirror_repeat: 0x%x (%d)\n", desc->wrap_s_mirror_repeat, desc->wrap_s_mirror_repeat);707fprintf(fp, "\t wrap_t_clamp_to_edge: 0x%x (%d)\n", desc->wrap_t_clamp_to_edge, desc->wrap_t_clamp_to_edge);708fprintf(fp, "\t wrap_t_clamp: 0x%x (%d)\n", desc->wrap_t_clamp, desc->wrap_t_clamp);709fprintf(fp, "\t wrap_t_mirror_repeat: 0x%x (%d)\n", desc->wrap_t_mirror_repeat, desc->wrap_t_mirror_repeat);710fprintf(fp, "\t unknown_2_2: 0x%x (%d)\n", desc->unknown_2_2, desc->unknown_2_2);711fprintf(fp, "\t width: 0x%x (%d)\n", desc->width, desc->width);712fprintf(fp, "\t height: 0x%x (%d)\n", desc->height, desc->height);713fprintf(fp, "\t unknown_3_1: 0x%x (%d)\n", desc->unknown_3_1, desc->unknown_3_1);714fprintf(fp, "\t unknown_3_2: 0x%x (%d)\n", desc->unknown_3_2, desc->unknown_3_2);715716/* Word 4 */717fprintf(fp, "/* 0x%08x (0x%08x) */\t0x%08x\n",718start + i * 4, i * 4, *(&data[i + offset]));719i++;720fprintf(fp, "\t unknown_4: 0x%x (%d)\n", desc->unknown_4, desc->unknown_4);721722/* Word 5 */723fprintf(fp, "/* 0x%08x (0x%08x) */\t0x%08x\n",724start + i * 4, i * 4, *(&data[i + offset]));725i++;726fprintf(fp, "\t unknown_5: 0x%x (%d)\n", desc->unknown_5, desc->unknown_5);727728/* Word 6 - */729fprintf(fp, "/* 0x%08x (0x%08x) */",730start + i * 4, i * 4);731fprintf(fp, "\t");732733int miplevels = (int)lima_fixed8_to_float(desc->max_lod);734for (int k = 0; k < ((((miplevels + 1) * 26) + 64) / 32); k++)735fprintf(fp, "0x%08x ", *(&data[i + offset + k]));736fprintf(fp, "\n");737738i++;739fprintf(fp, "\t unknown_6_1: 0x%x (%d)\n", desc->va_s.unknown_6_1, desc->va_s.unknown_6_1);740fprintf(fp, "\t layout: 0x%x (%d)\n", desc->va_s.layout, desc->va_s.layout);741fprintf(fp, "\t unknown_6_2: 0x%x (%d)\n", desc->va_s.unknown_6_2, desc->va_s.unknown_6_2);742fprintf(fp, "\t unknown_6_3: 0x%x (%d)\n", desc->va_s.unknown_6_3, desc->va_s.unknown_6_3);743744/* first level */745fprintf(fp, "\t va_0: 0x%x \n", desc->va_s.va_0 << 6);746747/* second level up to desc->miplevels */748int j;749unsigned va_bit_idx;750unsigned va_idx;751uint32_t va;752uint32_t va_1;753uint32_t va_2;754for (j = 1; j <= miplevels; j++) {755va = 0;756va_1 = 0;757va_2 = 0;758759va_bit_idx = VA_BIT_OFFSET + (VA_BIT_SIZE * j);760va_idx = va_bit_idx / 32;761va_bit_idx %= 32;762763/* the first (32 - va_bit_idx) bits */764va_1 |= (*(&data[i + offset + va_idx - 1]) >> va_bit_idx);765766/* do we need some bits from the following word? */767if (va_bit_idx > 6) {768/* shift left and right again to erase the unneeded bits, keep space for va1 */769va_2 |= (*(&data[i + offset + va_idx]) << (2 * 32 - VA_BIT_SIZE - va_bit_idx));770va_2 >>= ((2 * 32 - VA_BIT_SIZE - va_bit_idx) - (32 - va_bit_idx));771va |= va_2;772}773va |= va_1;774va <<= 6;775fprintf(fp, "\t va_%d: 0x%x \n", j, va);776}777}778779void780lima_parse_texture_descriptor(FILE *fp, uint32_t *data, int size, uint32_t start, uint32_t offset)781{782fprintf(fp, "/* ============ TEXTURE BEGIN ===================== */\n");783parse_texture(fp, data, start, offset);784fprintf(fp, "/* ============ TEXTURE END ======================= */\n");785}786787788