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