summaryrefslogtreecommitdiffstats
path: root/src/broadcom/clif/v3dx_dump.c
blob: b10b1c92a5ac8945c61ecf3d9590c8efc1fedf4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
 * Copyright © 2016-2018 Broadcom
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 */

#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "util/macros.h"
#include "broadcom/cle/v3d_decoder.h"
#include "clif_dump.h"
#include "clif_private.h"

#define __gen_user_data void
#define __gen_address_type uint32_t
#define __gen_address_offset(reloc) (*reloc)
#define __gen_emit_reloc(cl, reloc)
#define __gen_unpack_address(cl, s, e) (__gen_unpack_uint(cl, s, e) << (31 - (e - s)))
#include "broadcom/cle/v3dx_pack.h"
#include "broadcom/common/v3d_macros.h"

static char *
clif_name(const char *xml_name)
{
        char *name = malloc(strlen(xml_name) + 1);

        int j = 0;
        for (int i = 0; i < strlen(xml_name); i++) {
                if (xml_name[i] == ' ') {
                        name[j++] = '_';
                } else if (xml_name[i] == '(' || xml_name[i] == ')') {
                        /* skip */
                } else {
                        name[j++] = toupper(xml_name[i]);
                }
        }
        name[j++] = 0;

        return name;
}

bool
v3dX(clif_dump_packet)(struct clif_dump *clif, uint32_t offset,
                       const uint8_t *cl, uint32_t *size)
{
        struct v3d_group *inst = v3d_spec_find_instruction(clif->spec, cl);
        if (!inst) {
                out(clif, "0x%08x: Unknown packet %d!\n", offset, *cl);
                return false;
        }

        *size = v3d_group_get_length(inst);

        char *name = clif_name(v3d_group_get_name(inst));
        out(clif, "%s\n", name);
        free(name);
        v3d_print_group(clif, inst, 0, cl);

        switch (*cl) {
        case V3DX(GL_SHADER_STATE_opcode): {
                struct V3DX(GL_SHADER_STATE) values;
                V3DX(GL_SHADER_STATE_unpack)(cl, &values);

                struct reloc_worklist_entry *reloc =
                        clif_dump_add_address_to_worklist(clif,
                                                          reloc_gl_shader_state,
                                                          values.address);
                if (reloc) {
                        reloc->shader_state.num_attrs =
                                values.number_of_attribute_arrays;
                }
                return true;
        }

#if V3D_VERSION < 40
        case V3DX(STORE_MULTI_SAMPLE_RESOLVED_TILE_COLOR_BUFFER_EXTENDED_opcode): {
                struct V3DX(STORE_MULTI_SAMPLE_RESOLVED_TILE_COLOR_BUFFER_EXTENDED) values;
                V3DX(STORE_MULTI_SAMPLE_RESOLVED_TILE_COLOR_BUFFER_EXTENDED_unpack)(cl, &values);

                if (values.last_tile_of_frame)
                        return false;
                break;
        }
#endif /* V3D_VERSION < 40 */

#if V3D_VERSION > 40
        case V3DX(TRANSFORM_FEEDBACK_SPECS_opcode): {
                struct V3DX(TRANSFORM_FEEDBACK_SPECS) values;
                V3DX(TRANSFORM_FEEDBACK_SPECS_unpack)(cl, &values);
                struct v3d_group *spec = v3d_spec_find_struct(clif->spec,
                                                              "Transform Feedback Output Data Spec");
                assert(spec);

                cl += *size;

                for (int i = 0; i < values.number_of_16_bit_output_data_specs_following; i++) {
                        v3d_print_group(clif, spec, 0, cl);
                        cl += v3d_group_get_length(spec);
                        *size += v3d_group_get_length(spec);
                }
                out(clif, "@format ctrllist\n");
                break;
        }
#else /* V3D_VERSION < 40 */
        case V3DX(TRANSFORM_FEEDBACK_ENABLE_opcode): {
                struct V3DX(TRANSFORM_FEEDBACK_ENABLE) values;
                V3DX(TRANSFORM_FEEDBACK_ENABLE_unpack)(cl, &values);
                struct v3d_group *spec = v3d_spec_find_struct(clif->spec,
                                                              "Transform Feedback Output Data Spec");
                struct v3d_group *addr = v3d_spec_find_struct(clif->spec,
                                                              "Transform Feedback Output Address");
                assert(spec);
                assert(addr);

                cl += *size;

                for (int i = 0; i < values.number_of_16_bit_output_data_specs_following; i++) {
                        v3d_print_group(clif, spec, 0, cl);
                        cl += v3d_group_get_length(spec);
                        *size += v3d_group_get_length(spec);
                }

                for (int i = 0; i < values.number_of_32_bit_output_buffer_address_following; i++) {
                        v3d_print_group(clif, addr, 0, cl);
                        cl += v3d_group_get_length(addr);
                        *size += v3d_group_get_length(addr);
                }
                break;
        }
#endif /* V3D_VERSION < 40 */

        case V3DX(START_ADDRESS_OF_GENERIC_TILE_LIST_opcode): {
                struct V3DX(START_ADDRESS_OF_GENERIC_TILE_LIST) values;
                V3DX(START_ADDRESS_OF_GENERIC_TILE_LIST_unpack)(cl, &values);
                struct reloc_worklist_entry *reloc =
                        clif_dump_add_address_to_worklist(clif,
                                                          reloc_generic_tile_list,
                                                          values.start);
                reloc->generic_tile_list.end = values.end;
                break;
        }

        case V3DX(HALT_opcode):
                return false;
        }

        return true;
}