1 /* -*- mesa-c++ -*-
2 *
3 * Copyright (c) 2018 Collabora LTD
4 *
5 * Author: Gert Wollny <gert.wollny@collabora.com>
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * on the rights to use, copy, modify, merge, publish, distribute, sub
11 * license, and/or sell copies of the Software, and to permit persons to whom
12 * the Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
16 * Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27 #include "r600_dump.h"
28 #include "r600_shader.h"
29 #include "tgsi/tgsi_strings.h"
30
print_shader_info(FILE * f,int id,struct r600_shader * shader)31 void print_shader_info(FILE *f , int id, struct r600_shader *shader)
32 {
33
34 #define PRINT_INT_MEMBER(NAME) \
35 if (shader-> NAME) fprintf(f, " shader->" #NAME "=%d;\n", shader-> NAME)
36 #define PRINT_UINT_MEMBER(NAME) \
37 if (shader-> NAME) fprintf(f, " shader->" #NAME "=%u;\n", (unsigned)shader-> NAME)
38
39 #define PRINT_INT_ARRAY_ELM(NAME, ELM) \
40 if (shader->NAME[i].ELM) fprintf(f, " shader->" #NAME "[%d]." #ELM "=%d;\n", i, (int)shader->NAME[i].ELM)
41 #define PRINT_UINT_ARRAY_ELM(NAME, ELM) \
42 if (shader->NAME[i].ELM) fprintf(f, " shader->" #NAME "[%d]." #ELM" =%u;\n", i, (unsigned)shader->NAME[i].ELM)
43
44 fprintf(f, "#include \"gallium/drivers/r600/r600_shader.h\"\n");
45 fprintf(f, "void shader_%d_fill_data(struct r600_shader *shader)\n{\n", id);
46 fprintf(f, " memset(shader, 0, sizeof(struct r600_shader));\n");
47
48 PRINT_UINT_MEMBER(processor_type);
49 PRINT_UINT_MEMBER(ninput);
50 PRINT_UINT_MEMBER(noutput);
51 PRINT_UINT_MEMBER(nhwatomic);
52 PRINT_UINT_MEMBER(nlds);
53 PRINT_UINT_MEMBER(nsys_inputs);
54
55 for (unsigned i = 0; i < shader->ninput; ++i) {
56 PRINT_UINT_ARRAY_ELM(input, name);
57 PRINT_UINT_ARRAY_ELM(input, gpr);
58 PRINT_UINT_ARRAY_ELM(input, done);
59 PRINT_INT_ARRAY_ELM(input, sid);
60 PRINT_INT_ARRAY_ELM(input, spi_sid);
61 PRINT_UINT_ARRAY_ELM(input, interpolate);
62 PRINT_UINT_ARRAY_ELM(input, ij_index);
63 PRINT_UINT_ARRAY_ELM(input, interpolate_location); // TGSI_INTERPOLATE_LOC_CENTER, CENTROID, SAMPLE
64 PRINT_UINT_ARRAY_ELM(input, lds_pos); /* for evergreen */
65 PRINT_UINT_ARRAY_ELM(input, back_color_input);
66 PRINT_UINT_ARRAY_ELM(input, write_mask);
67 PRINT_INT_ARRAY_ELM(input, ring_offset);
68 }
69
70 for (unsigned i = 0; i < shader->noutput; ++i) {
71 PRINT_UINT_ARRAY_ELM(output, name);
72 PRINT_UINT_ARRAY_ELM(output, gpr);
73 PRINT_UINT_ARRAY_ELM(output, done);
74 PRINT_INT_ARRAY_ELM(output, sid);
75 PRINT_INT_ARRAY_ELM(output, spi_sid);
76 PRINT_UINT_ARRAY_ELM(output, interpolate);
77 PRINT_UINT_ARRAY_ELM(output, ij_index);
78 PRINT_UINT_ARRAY_ELM(output, interpolate_location); // TGSI_INTERPOLATE_LOC_CENTER, CENTROID, SAMPLE
79 PRINT_UINT_ARRAY_ELM(output, lds_pos); /* for evergreen */
80 PRINT_UINT_ARRAY_ELM(output, back_color_input);
81 PRINT_UINT_ARRAY_ELM(output, write_mask);
82 PRINT_INT_ARRAY_ELM(output, ring_offset);
83 }
84
85 for (unsigned i = 0; i < shader->nhwatomic; ++i) {
86 PRINT_UINT_ARRAY_ELM(atomics, start);
87 PRINT_UINT_ARRAY_ELM(atomics, end);
88 PRINT_UINT_ARRAY_ELM(atomics, buffer_id);
89 PRINT_UINT_ARRAY_ELM(atomics, hw_idx);
90 PRINT_UINT_ARRAY_ELM(atomics, array_id);
91 }
92
93 PRINT_UINT_MEMBER(nhwatomic_ranges);
94 PRINT_UINT_MEMBER(uses_kill);
95 PRINT_UINT_MEMBER(fs_write_all);
96 PRINT_UINT_MEMBER(two_side);
97 PRINT_UINT_MEMBER(needs_scratch_space);
98 /* Number of color outputs in the TGSI shader,
99 * sometimes it could be higher than nr_cbufs (bug?).
100 * Also with writes_all property on eg+ it will be set to max CB number */
101 PRINT_UINT_MEMBER(nr_ps_max_color_exports);
102 /* Real number of ps color exports compiled in the bytecode */
103 PRINT_UINT_MEMBER(nr_ps_color_exports);
104 PRINT_UINT_MEMBER(ps_color_export_mask);
105 PRINT_UINT_MEMBER(ps_export_highest);
106 /* bit n is set if the shader writes gl_ClipDistance[n] */
107 PRINT_UINT_MEMBER(cc_dist_mask);
108 PRINT_UINT_MEMBER(clip_dist_write);
109 PRINT_UINT_MEMBER(cull_dist_write);
110 PRINT_UINT_MEMBER(vs_position_window_space);
111 /* flag is set if the shader writes VS_OUT_MISC_VEC (e.g. for PSIZE) */
112 PRINT_UINT_MEMBER(vs_out_misc_write);
113 PRINT_UINT_MEMBER(vs_out_point_size);
114 PRINT_UINT_MEMBER(vs_out_layer);
115 PRINT_UINT_MEMBER(vs_out_viewport);
116 PRINT_UINT_MEMBER(vs_out_edgeflag);
117 PRINT_UINT_MEMBER(has_txq_cube_array_z_comp);
118 PRINT_UINT_MEMBER(uses_tex_buffers);
119 PRINT_UINT_MEMBER(gs_prim_id_input);
120 PRINT_UINT_MEMBER(gs_tri_strip_adj_fix);
121 PRINT_UINT_MEMBER(ps_conservative_z);
122
123 /* Size in bytes of a data item in the ring(s) (single vertex data).
124 Stages with only one ring items 123 will be set to 0. */
125
126 PRINT_UINT_MEMBER(ring_item_sizes[0]);
127 PRINT_UINT_MEMBER(ring_item_sizes[1]);
128 PRINT_UINT_MEMBER(ring_item_sizes[2]);
129 PRINT_UINT_MEMBER(ring_item_sizes[3]);
130
131 PRINT_UINT_MEMBER(indirect_files);
132 PRINT_UINT_MEMBER(max_arrays);
133 PRINT_UINT_MEMBER(num_arrays);
134 PRINT_UINT_MEMBER(vs_as_es);
135 PRINT_UINT_MEMBER(vs_as_ls);
136 PRINT_UINT_MEMBER(vs_as_gs_a);
137 PRINT_UINT_MEMBER(tes_as_es);
138 PRINT_UINT_MEMBER(tcs_prim_mode);
139 PRINT_UINT_MEMBER(ps_prim_id_input);
140
141 if (shader->num_arrays > 0) {
142 fprintf(stderr, " shader->arrays = new r600_shader_array[%d];\n", shader->num_arrays);
143 for (unsigned i = 0; i < shader->num_arrays; ++i) {
144 PRINT_UINT_ARRAY_ELM(arrays, gpr_start);
145 PRINT_UINT_ARRAY_ELM(arrays, gpr_count);
146 PRINT_UINT_ARRAY_ELM(arrays, comp_mask);
147 }
148 }
149
150 PRINT_UINT_MEMBER(uses_doubles);
151 PRINT_UINT_MEMBER(uses_atomics);
152 PRINT_UINT_MEMBER(uses_images);
153 PRINT_UINT_MEMBER(uses_helper_invocation);
154 PRINT_UINT_MEMBER(atomic_base);
155 PRINT_UINT_MEMBER(rat_base);
156 PRINT_UINT_MEMBER(image_size_const_offset);
157
158 fprintf(f, "}\n");
159 }
160
print_pipe_info(FILE * f,struct tgsi_shader_info * shader)161 void print_pipe_info(FILE *f, struct tgsi_shader_info *shader)
162 {
163 PRINT_UINT_MEMBER(shader_buffers_load);
164 PRINT_UINT_MEMBER(shader_buffers_store);
165 PRINT_UINT_MEMBER(shader_buffers_atomic);
166 PRINT_UINT_MEMBER(writes_memory);
167 PRINT_UINT_MEMBER(file_mask[TGSI_FILE_HW_ATOMIC]);
168 PRINT_UINT_MEMBER(file_count[TGSI_FILE_HW_ATOMIC]);
169
170 for(unsigned int i = 0; i < TGSI_PROPERTY_COUNT; ++i) {
171 if (shader->properties[i] != 0)
172 fprintf(stderr, "PROP: %s = %d\n", tgsi_property_names[i], shader->properties[i]);
173 }
174
175 #define PRINT_UINT_ARRAY_MEMBER(M, IDX) \
176 if (shader-> M [ IDX ]) fprintf(f, #M "[%d] = %d\n", IDX, (unsigned) shader-> M [ IDX ]);
177
178 for (int i = 0; i < shader->num_inputs; ++i) {
179 PRINT_UINT_ARRAY_MEMBER(input_semantic_name, i); /**< TGSI_SEMANTIC_x */
180 PRINT_UINT_ARRAY_MEMBER(input_semantic_index, i);
181 PRINT_UINT_ARRAY_MEMBER(input_interpolate, i);
182 PRINT_UINT_ARRAY_MEMBER(input_interpolate_loc, i);
183 PRINT_UINT_ARRAY_MEMBER(input_usage_mask, i);
184 PRINT_UINT_ARRAY_MEMBER(input_cylindrical_wrap, i);
185 }
186
187 for (int i = 0; i < shader->num_inputs; ++i) {
188 PRINT_UINT_ARRAY_MEMBER(output_semantic_name, i);
189 PRINT_UINT_ARRAY_MEMBER(output_semantic_index, i);
190 PRINT_UINT_ARRAY_MEMBER(output_usagemask, i);
191 PRINT_UINT_ARRAY_MEMBER(output_streams, i);
192 }
193
194 for (int i = 0; i < shader->num_system_values; ++i)
195 PRINT_UINT_ARRAY_MEMBER(system_value_semantic_name, i);
196
197 PRINT_UINT_MEMBER(reads_pervertex_outputs);
198 PRINT_UINT_MEMBER(reads_perpatch_outputs);
199 PRINT_UINT_MEMBER(reads_tessfactor_outputs);
200 }
201