17ec681f3Smrg/* -*- mesa-c++  -*-
27ec681f3Smrg *
37ec681f3Smrg * Copyright (c) 2018 Collabora LTD
47ec681f3Smrg *
57ec681f3Smrg * Author: Gert Wollny <gert.wollny@collabora.com>
67ec681f3Smrg *
77ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a
87ec681f3Smrg * copy of this software and associated documentation files (the "Software"),
97ec681f3Smrg * to deal in the Software without restriction, including without limitation
107ec681f3Smrg * on the rights to use, copy, modify, merge, publish, distribute, sub
117ec681f3Smrg * license, and/or sell copies of the Software, and to permit persons to whom
127ec681f3Smrg * the Software is furnished to do so, subject to the following conditions:
137ec681f3Smrg *
147ec681f3Smrg * The above copyright notice and this permission notice (including the next
157ec681f3Smrg * paragraph) shall be included in all copies or substantial portions of the
167ec681f3Smrg * Software.
177ec681f3Smrg *
187ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
197ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
207ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
217ec681f3Smrg * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
227ec681f3Smrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
237ec681f3Smrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
247ec681f3Smrg * USE OR OTHER DEALINGS IN THE SOFTWARE.
257ec681f3Smrg */
267ec681f3Smrg
277ec681f3Smrg#include "r600_dump.h"
287ec681f3Smrg#include "r600_shader.h"
297ec681f3Smrg#include "tgsi/tgsi_strings.h"
307ec681f3Smrg
317ec681f3Smrgvoid print_shader_info(FILE *f , int id, struct r600_shader *shader)
327ec681f3Smrg{
337ec681f3Smrg
347ec681f3Smrg#define PRINT_INT_MEMBER(NAME) \
357ec681f3Smrg   if (shader-> NAME) fprintf(f, "  shader->"  #NAME  "=%d;\n", shader-> NAME)
367ec681f3Smrg#define PRINT_UINT_MEMBER(NAME) \
377ec681f3Smrg   if (shader-> NAME) fprintf(f, "  shader->"  #NAME  "=%u;\n", (unsigned)shader-> NAME)
387ec681f3Smrg
397ec681f3Smrg#define PRINT_INT_ARRAY_ELM(NAME, ELM) \
407ec681f3Smrg   if (shader->NAME[i].ELM) fprintf(f, "  shader->"  #NAME "[%d]." #ELM "=%d;\n", i, (int)shader->NAME[i].ELM)
417ec681f3Smrg#define PRINT_UINT_ARRAY_ELM(NAME, ELM) \
427ec681f3Smrg   if (shader->NAME[i].ELM) fprintf(f, "  shader->"  #NAME "[%d]." #ELM" =%u;\n", i, (unsigned)shader->NAME[i].ELM)
437ec681f3Smrg
447ec681f3Smrg   fprintf(f, "#include \"gallium/drivers/r600/r600_shader.h\"\n");
457ec681f3Smrg   fprintf(f, "void shader_%d_fill_data(struct r600_shader *shader)\n{\n", id);
467ec681f3Smrg   fprintf(f, "  memset(shader, 0, sizeof(struct r600_shader));\n");
477ec681f3Smrg
487ec681f3Smrg   PRINT_UINT_MEMBER(processor_type);
497ec681f3Smrg   PRINT_UINT_MEMBER(ninput);
507ec681f3Smrg   PRINT_UINT_MEMBER(noutput);
517ec681f3Smrg   PRINT_UINT_MEMBER(nhwatomic);
527ec681f3Smrg   PRINT_UINT_MEMBER(nlds);
537ec681f3Smrg   PRINT_UINT_MEMBER(nsys_inputs);
547ec681f3Smrg
557ec681f3Smrg   for (unsigned i = 0; i < shader->ninput; ++i) {
567ec681f3Smrg      PRINT_UINT_ARRAY_ELM(input, name);
577ec681f3Smrg      PRINT_UINT_ARRAY_ELM(input, gpr);
587ec681f3Smrg      PRINT_UINT_ARRAY_ELM(input, done);
597ec681f3Smrg      PRINT_INT_ARRAY_ELM(input, sid);
607ec681f3Smrg      PRINT_INT_ARRAY_ELM(input, spi_sid);
617ec681f3Smrg      PRINT_UINT_ARRAY_ELM(input, interpolate);
627ec681f3Smrg      PRINT_UINT_ARRAY_ELM(input, ij_index);
637ec681f3Smrg      PRINT_UINT_ARRAY_ELM(input, interpolate_location); //  TGSI_INTERPOLATE_LOC_CENTER, CENTROID, SAMPLE
647ec681f3Smrg      PRINT_UINT_ARRAY_ELM(input, lds_pos); /* for evergreen */
657ec681f3Smrg      PRINT_UINT_ARRAY_ELM(input, back_color_input);
667ec681f3Smrg      PRINT_UINT_ARRAY_ELM(input, write_mask);
677ec681f3Smrg      PRINT_INT_ARRAY_ELM(input, ring_offset);
687ec681f3Smrg   }
697ec681f3Smrg
707ec681f3Smrg   for (unsigned i = 0; i < shader->noutput; ++i) {
717ec681f3Smrg      PRINT_UINT_ARRAY_ELM(output, name);
727ec681f3Smrg      PRINT_UINT_ARRAY_ELM(output, gpr);
737ec681f3Smrg      PRINT_UINT_ARRAY_ELM(output, done);
747ec681f3Smrg      PRINT_INT_ARRAY_ELM(output, sid);
757ec681f3Smrg      PRINT_INT_ARRAY_ELM(output, spi_sid);
767ec681f3Smrg      PRINT_UINT_ARRAY_ELM(output, interpolate);
777ec681f3Smrg      PRINT_UINT_ARRAY_ELM(output, ij_index);
787ec681f3Smrg      PRINT_UINT_ARRAY_ELM(output, interpolate_location); //  TGSI_INTERPOLATE_LOC_CENTER, CENTROID, SAMPLE
797ec681f3Smrg      PRINT_UINT_ARRAY_ELM(output, lds_pos); /* for evergreen */
807ec681f3Smrg      PRINT_UINT_ARRAY_ELM(output, back_color_input);
817ec681f3Smrg      PRINT_UINT_ARRAY_ELM(output, write_mask);
827ec681f3Smrg      PRINT_INT_ARRAY_ELM(output, ring_offset);
837ec681f3Smrg   }
847ec681f3Smrg
857ec681f3Smrg   for (unsigned i = 0; i < shader->nhwatomic; ++i) {
867ec681f3Smrg      PRINT_UINT_ARRAY_ELM(atomics, start);
877ec681f3Smrg      PRINT_UINT_ARRAY_ELM(atomics, end);
887ec681f3Smrg      PRINT_UINT_ARRAY_ELM(atomics, buffer_id);
897ec681f3Smrg      PRINT_UINT_ARRAY_ELM(atomics, hw_idx);
907ec681f3Smrg      PRINT_UINT_ARRAY_ELM(atomics, array_id);
917ec681f3Smrg   }
927ec681f3Smrg
937ec681f3Smrg   PRINT_UINT_MEMBER(nhwatomic_ranges);
947ec681f3Smrg   PRINT_UINT_MEMBER(uses_kill);
957ec681f3Smrg   PRINT_UINT_MEMBER(fs_write_all);
967ec681f3Smrg   PRINT_UINT_MEMBER(two_side);
977ec681f3Smrg   PRINT_UINT_MEMBER(needs_scratch_space);
987ec681f3Smrg   /* Number of color outputs in the TGSI shader,
997ec681f3Smrg    * sometimes it could be higher than nr_cbufs (bug?).
1007ec681f3Smrg    * Also with writes_all property on eg+ it will be set to max CB number */
1017ec681f3Smrg   PRINT_UINT_MEMBER(nr_ps_max_color_exports);
1027ec681f3Smrg   /* Real number of ps color exports compiled in the bytecode */
1037ec681f3Smrg   PRINT_UINT_MEMBER(nr_ps_color_exports);
1047ec681f3Smrg   PRINT_UINT_MEMBER(ps_color_export_mask);
1057ec681f3Smrg   PRINT_UINT_MEMBER(ps_export_highest);
1067ec681f3Smrg   /* bit n is set if the shader writes gl_ClipDistance[n] */
1077ec681f3Smrg   PRINT_UINT_MEMBER(cc_dist_mask);
1087ec681f3Smrg   PRINT_UINT_MEMBER(clip_dist_write);
1097ec681f3Smrg   PRINT_UINT_MEMBER(cull_dist_write);
1107ec681f3Smrg   PRINT_UINT_MEMBER(vs_position_window_space);
1117ec681f3Smrg   /* flag is set if the shader writes VS_OUT_MISC_VEC (e.g. for PSIZE) */
1127ec681f3Smrg   PRINT_UINT_MEMBER(vs_out_misc_write);
1137ec681f3Smrg   PRINT_UINT_MEMBER(vs_out_point_size);
1147ec681f3Smrg   PRINT_UINT_MEMBER(vs_out_layer);
1157ec681f3Smrg   PRINT_UINT_MEMBER(vs_out_viewport);
1167ec681f3Smrg   PRINT_UINT_MEMBER(vs_out_edgeflag);
1177ec681f3Smrg   PRINT_UINT_MEMBER(has_txq_cube_array_z_comp);
1187ec681f3Smrg   PRINT_UINT_MEMBER(uses_tex_buffers);
1197ec681f3Smrg   PRINT_UINT_MEMBER(gs_prim_id_input);
1207ec681f3Smrg   PRINT_UINT_MEMBER(gs_tri_strip_adj_fix);
1217ec681f3Smrg   PRINT_UINT_MEMBER(ps_conservative_z);
1227ec681f3Smrg
1237ec681f3Smrg   /* Size in bytes of a data item in the ring(s) (single vertex data).
1247ec681f3Smrg      Stages with only one ring items 123 will be set to 0. */
1257ec681f3Smrg
1267ec681f3Smrg   PRINT_UINT_MEMBER(ring_item_sizes[0]);
1277ec681f3Smrg   PRINT_UINT_MEMBER(ring_item_sizes[1]);
1287ec681f3Smrg   PRINT_UINT_MEMBER(ring_item_sizes[2]);
1297ec681f3Smrg   PRINT_UINT_MEMBER(ring_item_sizes[3]);
1307ec681f3Smrg
1317ec681f3Smrg   PRINT_UINT_MEMBER(indirect_files);
1327ec681f3Smrg   PRINT_UINT_MEMBER(max_arrays);
1337ec681f3Smrg   PRINT_UINT_MEMBER(num_arrays);
1347ec681f3Smrg   PRINT_UINT_MEMBER(vs_as_es);
1357ec681f3Smrg   PRINT_UINT_MEMBER(vs_as_ls);
1367ec681f3Smrg   PRINT_UINT_MEMBER(vs_as_gs_a);
1377ec681f3Smrg   PRINT_UINT_MEMBER(tes_as_es);
1387ec681f3Smrg   PRINT_UINT_MEMBER(tcs_prim_mode);
1397ec681f3Smrg   PRINT_UINT_MEMBER(ps_prim_id_input);
1407ec681f3Smrg
1417ec681f3Smrg   if (shader->num_arrays > 0) {
1427ec681f3Smrg      fprintf(stderr, "  shader->arrays = new r600_shader_array[%d];\n", shader->num_arrays);
1437ec681f3Smrg      for (unsigned i = 0; i  < shader->num_arrays; ++i) {
1447ec681f3Smrg         PRINT_UINT_ARRAY_ELM(arrays, gpr_start);
1457ec681f3Smrg         PRINT_UINT_ARRAY_ELM(arrays, gpr_count);
1467ec681f3Smrg         PRINT_UINT_ARRAY_ELM(arrays, comp_mask);
1477ec681f3Smrg      }
1487ec681f3Smrg   }
1497ec681f3Smrg
1507ec681f3Smrg   PRINT_UINT_MEMBER(uses_doubles);
1517ec681f3Smrg   PRINT_UINT_MEMBER(uses_atomics);
1527ec681f3Smrg   PRINT_UINT_MEMBER(uses_images);
1537ec681f3Smrg   PRINT_UINT_MEMBER(uses_helper_invocation);
1547ec681f3Smrg   PRINT_UINT_MEMBER(atomic_base);
1557ec681f3Smrg   PRINT_UINT_MEMBER(rat_base);
1567ec681f3Smrg   PRINT_UINT_MEMBER(image_size_const_offset);
1577ec681f3Smrg
1587ec681f3Smrg   fprintf(f, "}\n");
1597ec681f3Smrg}
1607ec681f3Smrg
1617ec681f3Smrgvoid print_pipe_info(FILE *f, struct tgsi_shader_info *shader)
1627ec681f3Smrg{
1637ec681f3Smrg   PRINT_UINT_MEMBER(shader_buffers_load);
1647ec681f3Smrg   PRINT_UINT_MEMBER(shader_buffers_store);
1657ec681f3Smrg   PRINT_UINT_MEMBER(shader_buffers_atomic);
1667ec681f3Smrg   PRINT_UINT_MEMBER(writes_memory);
1677ec681f3Smrg   PRINT_UINT_MEMBER(file_mask[TGSI_FILE_HW_ATOMIC]);
1687ec681f3Smrg   PRINT_UINT_MEMBER(file_count[TGSI_FILE_HW_ATOMIC]);
1697ec681f3Smrg
1707ec681f3Smrg   for(unsigned int i = 0; i < TGSI_PROPERTY_COUNT; ++i) {
1717ec681f3Smrg      if (shader->properties[i] != 0)
1727ec681f3Smrg	 fprintf(stderr, "PROP: %s = %d\n", tgsi_property_names[i], shader->properties[i]);
1737ec681f3Smrg   }
1747ec681f3Smrg
1757ec681f3Smrg#define PRINT_UINT_ARRAY_MEMBER(M, IDX) \
1767ec681f3Smrg   if (shader-> M [ IDX ])  fprintf(f, #M "[%d] = %d\n",  IDX, (unsigned) shader-> M [ IDX ]);
1777ec681f3Smrg
1787ec681f3Smrg   for (int i = 0; i < shader->num_inputs; ++i) {
1797ec681f3Smrg      PRINT_UINT_ARRAY_MEMBER(input_semantic_name, i); /**< TGSI_SEMANTIC_x */
1807ec681f3Smrg      PRINT_UINT_ARRAY_MEMBER(input_semantic_index, i);
1817ec681f3Smrg      PRINT_UINT_ARRAY_MEMBER(input_interpolate, i);
1827ec681f3Smrg      PRINT_UINT_ARRAY_MEMBER(input_interpolate_loc, i);
1837ec681f3Smrg      PRINT_UINT_ARRAY_MEMBER(input_usage_mask, i);
1847ec681f3Smrg   }
1857ec681f3Smrg
1867ec681f3Smrg   for (int i = 0; i < shader->num_inputs; ++i) {
1877ec681f3Smrg      PRINT_UINT_ARRAY_MEMBER(output_semantic_name, i);
1887ec681f3Smrg      PRINT_UINT_ARRAY_MEMBER(output_semantic_index, i);
1897ec681f3Smrg      PRINT_UINT_ARRAY_MEMBER(output_usagemask, i);
1907ec681f3Smrg      PRINT_UINT_ARRAY_MEMBER(output_streams, i);
1917ec681f3Smrg   }
1927ec681f3Smrg
1937ec681f3Smrg   for (int i = 0; i < shader->num_system_values; ++i)
1947ec681f3Smrg      PRINT_UINT_ARRAY_MEMBER(system_value_semantic_name, i);
1957ec681f3Smrg
1967ec681f3Smrg   PRINT_UINT_MEMBER(reads_pervertex_outputs);
1977ec681f3Smrg   PRINT_UINT_MEMBER(reads_perpatch_outputs);
1987ec681f3Smrg   PRINT_UINT_MEMBER(reads_tessfactor_outputs);
1997ec681f3Smrg}
200