• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #define PRINT_BOOL_ARRAY_ELM(NAME, ELM) \
44    if (shader->NAME[i].ELM) fprintf(f, "  shader->"  #NAME "[%d]." #ELM "=%s;\n", i, shader->NAME[i].ELM ? "true" : "false")
45 
46    fprintf(f, "#include \"gallium/drivers/r600/r600_shader.h\"\n");
47    fprintf(f, "void shader_%d_fill_data(struct r600_shader *shader)\n{\n", id);
48    fprintf(f, "  memset(shader, 0, sizeof(struct r600_shader));\n");
49 
50    PRINT_UINT_MEMBER(processor_type);
51    PRINT_UINT_MEMBER(ninput);
52    PRINT_UINT_MEMBER(noutput);
53    PRINT_UINT_MEMBER(nhwatomic);
54    PRINT_UINT_MEMBER(nlds);
55    PRINT_UINT_MEMBER(nsys_inputs);
56    PRINT_UINT_MEMBER(highest_export_param);
57 
58    for (unsigned i = 0; i < shader->ninput; ++i) {
59       PRINT_INT_ARRAY_ELM(input, varying_slot);
60       PRINT_INT_ARRAY_ELM(input, system_value);
61       PRINT_UINT_ARRAY_ELM(input, gpr);
62       PRINT_INT_ARRAY_ELM(input, spi_sid);
63       PRINT_UINT_ARRAY_ELM(input, interpolate);
64       PRINT_UINT_ARRAY_ELM(input, ij_index);
65       PRINT_UINT_ARRAY_ELM(input, interpolate_location); //  TGSI_INTERPOLATE_LOC_CENTER, CENTROID, SAMPLE
66       PRINT_UINT_ARRAY_ELM(input, lds_pos); /* for evergreen */
67       PRINT_INT_ARRAY_ELM(input, ring_offset);
68       PRINT_BOOL_ARRAY_ELM(input, uses_interpolate_at_centroid);
69    }
70 
71    for (unsigned i = 0; i < shader->noutput; ++i) {
72       PRINT_INT_ARRAY_ELM(output, varying_slot);
73       PRINT_INT_ARRAY_ELM(output, frag_result);
74       PRINT_UINT_ARRAY_ELM(output, gpr);
75       PRINT_INT_ARRAY_ELM(output, spi_sid);
76       PRINT_UINT_ARRAY_ELM(output, write_mask);
77       PRINT_INT_ARRAY_ELM(output, export_param);
78       PRINT_INT_ARRAY_ELM(output, ring_offset);
79    }
80 
81    for (unsigned i = 0; i < shader->nhwatomic; ++i) {
82       PRINT_UINT_ARRAY_ELM(atomics, start);
83       PRINT_UINT_ARRAY_ELM(atomics, end);
84       PRINT_UINT_ARRAY_ELM(atomics, buffer_id);
85       PRINT_UINT_ARRAY_ELM(atomics, hw_idx);
86    }
87 
88    PRINT_UINT_MEMBER(nhwatomic_ranges);
89    PRINT_UINT_MEMBER(uses_kill);
90    PRINT_UINT_MEMBER(fs_write_all);
91    PRINT_UINT_MEMBER(two_side);
92    PRINT_UINT_MEMBER(needs_scratch_space);
93    /* Real number of ps color exports compiled in the bytecode */
94    PRINT_UINT_MEMBER(nr_ps_color_exports);
95    PRINT_UINT_MEMBER(ps_color_export_mask);
96    PRINT_UINT_MEMBER(ps_export_highest);
97    /* bit n is set if the shader writes gl_ClipDistance[n] */
98    PRINT_UINT_MEMBER(cc_dist_mask);
99    PRINT_UINT_MEMBER(clip_dist_write);
100    PRINT_UINT_MEMBER(cull_dist_write);
101    PRINT_UINT_MEMBER(vs_position_window_space);
102    /* flag is set if the shader writes VS_OUT_MISC_VEC (e.g. for PSIZE) */
103    PRINT_UINT_MEMBER(vs_out_misc_write);
104    PRINT_UINT_MEMBER(vs_out_point_size);
105    PRINT_UINT_MEMBER(vs_out_layer);
106    PRINT_UINT_MEMBER(vs_out_viewport);
107    PRINT_UINT_MEMBER(vs_out_edgeflag);
108    PRINT_UINT_MEMBER(has_txq_cube_array_z_comp);
109    PRINT_UINT_MEMBER(uses_tex_buffers);
110    PRINT_UINT_MEMBER(gs_prim_id_input);
111    PRINT_UINT_MEMBER(gs_tri_strip_adj_fix);
112    PRINT_UINT_MEMBER(ps_conservative_z);
113 
114    /* Size in bytes of a data item in the ring(s) (single vertex data).
115       Stages with only one ring items 123 will be set to 0. */
116 
117    PRINT_UINT_MEMBER(ring_item_sizes[0]);
118    PRINT_UINT_MEMBER(ring_item_sizes[1]);
119    PRINT_UINT_MEMBER(ring_item_sizes[2]);
120    PRINT_UINT_MEMBER(ring_item_sizes[3]);
121 
122    PRINT_UINT_MEMBER(indirect_files);
123    PRINT_UINT_MEMBER(max_arrays);
124    PRINT_UINT_MEMBER(num_arrays);
125    PRINT_UINT_MEMBER(vs_as_es);
126    PRINT_UINT_MEMBER(vs_as_ls);
127    PRINT_UINT_MEMBER(vs_as_gs_a);
128    PRINT_UINT_MEMBER(tes_as_es);
129    PRINT_UINT_MEMBER(tcs_prim_mode);
130 
131    if (shader->num_arrays > 0) {
132       fprintf(stderr, "  shader->arrays = new r600_shader_array[%d];\n", shader->num_arrays);
133       for (unsigned i = 0; i  < shader->num_arrays; ++i) {
134          PRINT_UINT_ARRAY_ELM(arrays, gpr_start);
135          PRINT_UINT_ARRAY_ELM(arrays, gpr_count);
136          PRINT_UINT_ARRAY_ELM(arrays, comp_mask);
137       }
138    }
139 
140    PRINT_UINT_MEMBER(uses_doubles);
141    PRINT_UINT_MEMBER(uses_atomics);
142    PRINT_UINT_MEMBER(uses_images);
143    PRINT_UINT_MEMBER(uses_helper_invocation);
144    PRINT_UINT_MEMBER(atomic_base);
145    PRINT_UINT_MEMBER(rat_base);
146    PRINT_UINT_MEMBER(image_size_const_offset);
147 
148    fprintf(f, "}\n");
149 }
150 
print_pipe_info(FILE * f,struct tgsi_shader_info * shader)151 void print_pipe_info(FILE *f, struct tgsi_shader_info *shader)
152 {
153    PRINT_UINT_MEMBER(shader_buffers_load);
154    PRINT_UINT_MEMBER(shader_buffers_store);
155    PRINT_UINT_MEMBER(shader_buffers_atomic);
156    PRINT_UINT_MEMBER(writes_memory);
157    PRINT_UINT_MEMBER(file_mask[TGSI_FILE_HW_ATOMIC]);
158    PRINT_UINT_MEMBER(file_count[TGSI_FILE_HW_ATOMIC]);
159 
160    for(unsigned int i = 0; i < TGSI_PROPERTY_COUNT; ++i) {
161       if (shader->properties[i] != 0)
162 	 fprintf(stderr, "PROP: %s = %d\n", tgsi_property_names[i], shader->properties[i]);
163    }
164 
165 #define PRINT_UINT_ARRAY_MEMBER(M, IDX) \
166    if (shader-> M [ IDX ])  fprintf(f, #M "[%d] = %d\n",  IDX, (unsigned) shader-> M [ IDX ]);
167 
168    for (int i = 0; i < shader->num_inputs; ++i) {
169       PRINT_UINT_ARRAY_MEMBER(input_semantic_name, i); /**< TGSI_SEMANTIC_x */
170       PRINT_UINT_ARRAY_MEMBER(input_semantic_index, i);
171       PRINT_UINT_ARRAY_MEMBER(input_interpolate, i);
172       PRINT_UINT_ARRAY_MEMBER(input_interpolate_loc, i);
173       PRINT_UINT_ARRAY_MEMBER(input_usage_mask, i);
174    }
175 
176    for (int i = 0; i < shader->num_outputs; ++i) {
177       PRINT_UINT_ARRAY_MEMBER(output_semantic_name, i);
178       PRINT_UINT_ARRAY_MEMBER(output_semantic_index, i);
179       PRINT_UINT_ARRAY_MEMBER(output_usagemask, i);
180       PRINT_UINT_ARRAY_MEMBER(output_streams, i);
181    }
182 
183    for (int i = 0; i < shader->num_system_values; ++i)
184       PRINT_UINT_ARRAY_MEMBER(system_value_semantic_name, i);
185 
186    PRINT_UINT_MEMBER(reads_pervertex_outputs);
187    PRINT_UINT_MEMBER(reads_perpatch_outputs);
188    PRINT_UINT_MEMBER(reads_tessfactor_outputs);
189 }
190