From 23c5ba8baa59262726e053631dadcf208e5d7c8d Mon Sep 17 00:00:00 2001 From: Gert Wollny Date: Sun, 1 Dec 2019 19:01:20 +0100 Subject: [PATCH] r600: Add functions to dump the shader info This will be helpful to compare TGSI and NIR code path, Signed-off-by: Gert Wollny Reviewed-by: Konstantin Kharlamov Part-of: --- src/gallium/drivers/r600/Makefile.sources | 2 + src/gallium/drivers/r600/meson.build | 2 + src/gallium/drivers/r600/r600_dump.c | 168 ++++++++++++++++++++++ src/gallium/drivers/r600/r600_dump.h | 39 +++++ 4 files changed, 211 insertions(+) create mode 100644 src/gallium/drivers/r600/r600_dump.c create mode 100644 src/gallium/drivers/r600/r600_dump.h diff --git a/src/gallium/drivers/r600/Makefile.sources b/src/gallium/drivers/r600/Makefile.sources index 60fdc05a876..763a49a07fa 100644 --- a/src/gallium/drivers/r600/Makefile.sources +++ b/src/gallium/drivers/r600/Makefile.sources @@ -16,6 +16,8 @@ C_SOURCES = \ r600_asm.h \ r600_blit.c \ r600d.h \ + r600_dump.c \ + r600_dump.h \ r600_formats.h \ r600_hw_context.c \ r600_isa.c \ diff --git a/src/gallium/drivers/r600/meson.build b/src/gallium/drivers/r600/meson.build index 099d0cd5ae9..91f62a8a701 100644 --- a/src/gallium/drivers/r600/meson.build +++ b/src/gallium/drivers/r600/meson.build @@ -35,6 +35,8 @@ files_r600 = files( 'r600_asm.h', 'r600_blit.c', 'r600d.h', + 'r600_dump.c', + 'r600_dump.h', 'r600_formats.h', 'r600_hw_context.c', 'r600_isa.c', diff --git a/src/gallium/drivers/r600/r600_dump.c b/src/gallium/drivers/r600/r600_dump.c new file mode 100644 index 00000000000..29a89605e22 --- /dev/null +++ b/src/gallium/drivers/r600/r600_dump.c @@ -0,0 +1,168 @@ +/* -*- mesa-c++ -*- + * + * Copyright (c) 2018 Collabora LTD + * + * Author: Gert Wollny + * + * 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 + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, 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 NON-INFRINGEMENT. IN NO EVENT SHALL + * THE AUTHOR(S) AND/OR THEIR SUPPLIERS 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 "r600_dump.h" +#include "r600_shader.h" + +void print_shader_info(FILE *f , int id, struct r600_shader *shader) +{ + +#define PRINT_INT_MEMBER(NAME) \ + if (shader-> NAME) fprintf(f, " shader->" #NAME "=%d;\n", shader-> NAME) +#define PRINT_UINT_MEMBER(NAME) \ + if (shader-> NAME) fprintf(f, " shader->" #NAME "=%u;\n", (unsigned)shader-> NAME) + +#define PRINT_INT_ARRAY_ELM(NAME, ELM) \ + if (shader->NAME[i].ELM) fprintf(f, " shader->" #NAME "[%d]." #ELM "=%d;\n", i, (int)shader->NAME[i].ELM) +#define PRINT_UINT_ARRAY_ELM(NAME, ELM) \ + if (shader->NAME[i].ELM) fprintf(f, " shader->" #NAME "[%d]." #ELM" =%u;\n", i, (unsigned)shader->NAME[i].ELM) + + fprintf(f, "#include \"gallium/drivers/r600/r600_shader.h\"\n"); + fprintf(f, "void shader_%d_fill_data(struct r600_shader *shader)\n{\n", id); + fprintf(f, " memset(shader, 0, sizeof(struct r600_shader));\n"); + + PRINT_UINT_MEMBER(processor_type); + PRINT_UINT_MEMBER(ninput); + PRINT_UINT_MEMBER(noutput); + PRINT_UINT_MEMBER(nhwatomic); + PRINT_UINT_MEMBER(nlds); + PRINT_UINT_MEMBER(nsys_inputs); + + for (unsigned i = 0; i < shader->ninput; ++i) { + PRINT_UINT_ARRAY_ELM(input, name); + PRINT_UINT_ARRAY_ELM(input, gpr); + PRINT_UINT_ARRAY_ELM(input, done); + PRINT_INT_ARRAY_ELM(input, sid); + PRINT_INT_ARRAY_ELM(input, spi_sid); + PRINT_UINT_ARRAY_ELM(input, interpolate); + PRINT_UINT_ARRAY_ELM(input, ij_index); + PRINT_UINT_ARRAY_ELM(input, interpolate_location); // TGSI_INTERPOLATE_LOC_CENTER, CENTROID, SAMPLE + PRINT_UINT_ARRAY_ELM(input, lds_pos); /* for evergreen */ + PRINT_UINT_ARRAY_ELM(input, back_color_input); + PRINT_UINT_ARRAY_ELM(input, write_mask); + PRINT_INT_ARRAY_ELM(input, ring_offset); + } + + for (unsigned i = 0; i < shader->noutput; ++i) { + PRINT_UINT_ARRAY_ELM(output, name); + PRINT_UINT_ARRAY_ELM(output, gpr); + PRINT_UINT_ARRAY_ELM(output, done); + PRINT_INT_ARRAY_ELM(output, sid); + PRINT_INT_ARRAY_ELM(output, spi_sid); + PRINT_UINT_ARRAY_ELM(output, interpolate); + PRINT_UINT_ARRAY_ELM(output, ij_index); + PRINT_UINT_ARRAY_ELM(output, interpolate_location); // TGSI_INTERPOLATE_LOC_CENTER, CENTROID, SAMPLE + PRINT_UINT_ARRAY_ELM(output, lds_pos); /* for evergreen */ + PRINT_UINT_ARRAY_ELM(output, back_color_input); + PRINT_UINT_ARRAY_ELM(output, write_mask); + PRINT_INT_ARRAY_ELM(output, ring_offset); + } + + for (unsigned i = 0; i < shader->nhwatomic; ++i) { + PRINT_UINT_ARRAY_ELM(atomics, start); + PRINT_UINT_ARRAY_ELM(atomics, end); + PRINT_UINT_ARRAY_ELM(atomics, buffer_id); + PRINT_UINT_ARRAY_ELM(atomics, hw_idx); + PRINT_UINT_ARRAY_ELM(atomics, array_id); + } + + PRINT_UINT_MEMBER(nhwatomic_ranges); + PRINT_UINT_MEMBER(uses_kill); + PRINT_UINT_MEMBER(fs_write_all); + PRINT_UINT_MEMBER(two_side); + PRINT_UINT_MEMBER(needs_scratch_space); + /* Number of color outputs in the TGSI shader, + * sometimes it could be higher than nr_cbufs (bug?). + * Also with writes_all property on eg+ it will be set to max CB number */ + PRINT_UINT_MEMBER(nr_ps_max_color_exports); + /* Real number of ps color exports compiled in the bytecode */ + PRINT_UINT_MEMBER(nr_ps_color_exports); + PRINT_UINT_MEMBER(ps_color_export_mask); + PRINT_UINT_MEMBER(ps_export_highest); + /* bit n is set if the shader writes gl_ClipDistance[n] */ + PRINT_UINT_MEMBER(cc_dist_mask); + PRINT_UINT_MEMBER(clip_dist_write); + PRINT_UINT_MEMBER(cull_dist_write); + PRINT_UINT_MEMBER(vs_position_window_space); + /* flag is set if the shader writes VS_OUT_MISC_VEC (e.g. for PSIZE) */ + PRINT_UINT_MEMBER(vs_out_misc_write); + PRINT_UINT_MEMBER(vs_out_point_size); + PRINT_UINT_MEMBER(vs_out_layer); + PRINT_UINT_MEMBER(vs_out_viewport); + PRINT_UINT_MEMBER(vs_out_edgeflag); + PRINT_UINT_MEMBER(has_txq_cube_array_z_comp); + PRINT_UINT_MEMBER(uses_tex_buffers); + PRINT_UINT_MEMBER(gs_prim_id_input); + PRINT_UINT_MEMBER(gs_tri_strip_adj_fix); + PRINT_UINT_MEMBER(ps_conservative_z); + + /* Size in bytes of a data item in the ring(s) (single vertex data). + Stages with only one ring items 123 will be set to 0. */ + + PRINT_UINT_MEMBER(ring_item_sizes[0]); + PRINT_UINT_MEMBER(ring_item_sizes[1]); + PRINT_UINT_MEMBER(ring_item_sizes[2]); + PRINT_UINT_MEMBER(ring_item_sizes[3]); + + PRINT_UINT_MEMBER(indirect_files); + PRINT_UINT_MEMBER(max_arrays); + PRINT_UINT_MEMBER(num_arrays); + PRINT_UINT_MEMBER(vs_as_es); + PRINT_UINT_MEMBER(vs_as_ls); + PRINT_UINT_MEMBER(vs_as_gs_a); + PRINT_UINT_MEMBER(tes_as_es); + PRINT_UINT_MEMBER(tcs_prim_mode); + PRINT_UINT_MEMBER(ps_prim_id_input); + + if (shader->num_arrays > 0) { + fprintf(stderr, " shader->arrays = new r600_shader_array[%d];\n", shader->num_arrays); + for (unsigned i = 0; i < shader->num_arrays; ++i) { + PRINT_UINT_ARRAY_ELM(arrays, gpr_start); + PRINT_UINT_ARRAY_ELM(arrays, gpr_count); + PRINT_UINT_ARRAY_ELM(arrays, comp_mask); + } + } + + PRINT_UINT_MEMBER(uses_doubles); + PRINT_UINT_MEMBER(uses_atomics); + PRINT_UINT_MEMBER(uses_images); + PRINT_UINT_MEMBER(uses_helper_invocation); + PRINT_UINT_MEMBER(atomic_base); + PRINT_UINT_MEMBER(rat_base); + PRINT_UINT_MEMBER(image_size_const_offset); + + fprintf(f, "}\n"); +} + +void print_pipe_info(FILE *f, struct tgsi_shader_info *shader) +{ + PRINT_UINT_MEMBER(shader_buffers_load); + PRINT_UINT_MEMBER(shader_buffers_store); + PRINT_UINT_MEMBER(shader_buffers_atomic); + PRINT_UINT_MEMBER(writes_memory); + PRINT_UINT_MEMBER(file_mask[TGSI_FILE_HW_ATOMIC]); + PRINT_UINT_MEMBER(file_count[TGSI_FILE_HW_ATOMIC]); +} diff --git a/src/gallium/drivers/r600/r600_dump.h b/src/gallium/drivers/r600/r600_dump.h new file mode 100644 index 00000000000..0bc57a08041 --- /dev/null +++ b/src/gallium/drivers/r600/r600_dump.h @@ -0,0 +1,39 @@ +/* -*- mesa-c++ -*- + * + * Copyright (c) 2018 Collabora LTD + * + * Author: Gert Wollny + * + * 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 + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, 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 NON-INFRINGEMENT. IN NO EVENT SHALL + * THE AUTHOR(S) AND/OR THEIR SUPPLIERS 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. + */ + +#ifndef R600_DUMP_H +#define R600_DUMP_H + +#include + +struct r600_shader; +struct tgsi_shader_info; + +void print_shader_info(FILE *f , int id, struct r600_shader *shader); + +void print_pipe_info(FILE *f, struct tgsi_shader_info *shader); + +#endif // R600_DUMP_H -- 2.30.2