17ec681f3Smrg#
27ec681f3Smrg# Copyright © 2021 Igalia S.L.
37ec681f3Smrg#
47ec681f3Smrg# Permission is hereby granted, free of charge, to any person obtaining a
57ec681f3Smrg# copy of this software and associated documentation files (the "Software"),
67ec681f3Smrg# to deal in the Software without restriction, including without limitation
77ec681f3Smrg# the rights to use, copy, modify, merge, publish, distribute, sublicense,
87ec681f3Smrg# and/or sell copies of the Software, and to permit persons to whom the
97ec681f3Smrg# Software is furnished to do so, subject to the following conditions:
107ec681f3Smrg#
117ec681f3Smrg# The above copyright notice and this permission notice (including the next
127ec681f3Smrg# paragraph) shall be included in all copies or substantial portions of the
137ec681f3Smrg# Software.
147ec681f3Smrg#
157ec681f3Smrg# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
167ec681f3Smrg# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
177ec681f3Smrg# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
187ec681f3Smrg# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
197ec681f3Smrg# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
207ec681f3Smrg# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
217ec681f3Smrg# SOFTWARE.
227ec681f3Smrg#
237ec681f3Smrg
247ec681f3Smrgimport argparse
257ec681f3Smrgimport sys
267ec681f3Smrg
277ec681f3Smrg#
287ec681f3Smrg# TODO can we do this with less boilerplate?
297ec681f3Smrg#
307ec681f3Smrgparser = argparse.ArgumentParser()
317ec681f3Smrgparser.add_argument('-p', '--import-path', required=True)
327ec681f3Smrgparser.add_argument('--utrace-src', required=True)
337ec681f3Smrgparser.add_argument('--utrace-hdr', required=True)
347ec681f3Smrgparser.add_argument('--perfetto-hdr', required=True)
357ec681f3Smrgargs = parser.parse_args()
367ec681f3Smrgsys.path.insert(0, args.import_path)
377ec681f3Smrg
387ec681f3Smrg
397ec681f3Smrgfrom u_trace import Header, HeaderScope
407ec681f3Smrgfrom u_trace import ForwardDecl
417ec681f3Smrgfrom u_trace import Tracepoint
427ec681f3Smrgfrom u_trace import TracepointArg as Arg
437ec681f3Smrgfrom u_trace import TracepointArgStruct as ArgStruct
447ec681f3Smrgfrom u_trace import utrace_generate
457ec681f3Smrgfrom u_trace import utrace_generate_perfetto_utils
467ec681f3Smrg
477ec681f3Smrg#
487ec681f3Smrg# Tracepoint definitions:
497ec681f3Smrg#
507ec681f3Smrg
517ec681f3SmrgHeader('util/u_dump.h')
527ec681f3SmrgHeader('vk_format.h')
537ec681f3SmrgHeader('freedreno/vulkan/tu_private.h', scope=HeaderScope.SOURCE)
547ec681f3Smrg
557ec681f3SmrgForwardDecl('struct tu_device')
567ec681f3Smrg
577ec681f3SmrgTracepoint('start_render_pass',
587ec681f3Smrg    tp_perfetto='tu_start_render_pass'
597ec681f3Smrg)
607ec681f3SmrgTracepoint('end_render_pass',
617ec681f3Smrg    args=[ArgStruct(type='const struct tu_framebuffer *', var='fb')],
627ec681f3Smrg    tp_struct=[Arg(type='uint16_t', name='width',        var='fb->width',                                    c_format='%u'),
637ec681f3Smrg               Arg(type='uint16_t', name='height',       var='fb->height',                                   c_format='%u'),
647ec681f3Smrg               Arg(type='uint8_t',  name='MRTs',         var='fb->attachment_count',                         c_format='%u'),
657ec681f3Smrg            #    Arg(type='uint8_t',  name='samples',      var='fb->samples',                                  c_format='%u'),
667ec681f3Smrg               Arg(type='uint16_t', name='numberOfBins', var='fb->tile_count.width * fb->tile_count.height', c_format='%u'),
677ec681f3Smrg               Arg(type='uint16_t', name='binWidth',     var='fb->tile0.width',                              c_format='%u'),
687ec681f3Smrg               Arg(type='uint16_t', name='binHeight',    var='fb->tile0.height',                             c_format='%u')],
697ec681f3Smrg    tp_perfetto='tu_end_render_pass')
707ec681f3Smrg
717ec681f3SmrgTracepoint('start_binning_ib',
727ec681f3Smrg    tp_perfetto='tu_start_binning_ib')
737ec681f3SmrgTracepoint('end_binning_ib',
747ec681f3Smrg    tp_perfetto='tu_end_binning_ib')
757ec681f3Smrg
767ec681f3SmrgTracepoint('start_resolve',
777ec681f3Smrg    tp_perfetto='tu_start_resolve')
787ec681f3SmrgTracepoint('end_resolve',
797ec681f3Smrg    tp_perfetto='tu_end_resolve')
807ec681f3Smrg
817ec681f3SmrgTracepoint('start_draw_ib_sysmem',
827ec681f3Smrg    tp_perfetto='tu_start_draw_ib_sysmem')
837ec681f3SmrgTracepoint('end_draw_ib_sysmem',
847ec681f3Smrg    tp_perfetto='tu_end_draw_ib_sysmem')
857ec681f3Smrg
867ec681f3SmrgTracepoint('start_draw_ib_gmem',
877ec681f3Smrg    tp_perfetto='tu_start_draw_ib_gmem')
887ec681f3SmrgTracepoint('end_draw_ib_gmem',
897ec681f3Smrg    tp_perfetto='tu_end_draw_ib_gmem')
907ec681f3Smrg
917ec681f3SmrgTracepoint('start_gmem_clear',
927ec681f3Smrg    tp_perfetto='tu_start_gmem_clear')
937ec681f3SmrgTracepoint('end_gmem_clear',
947ec681f3Smrg    args=[Arg(type='enum VkFormat',  var='format',  c_format='%s', to_prim_type='vk_format_description({})->short_name'),
957ec681f3Smrg          Arg(type='uint8_t',        var='samples', c_format='%u')],
967ec681f3Smrg    tp_perfetto='tu_end_gmem_clear')
977ec681f3Smrg
987ec681f3SmrgTracepoint('start_sysmem_clear',
997ec681f3Smrg    tp_perfetto='tu_start_sysmem_clear')
1007ec681f3SmrgTracepoint('end_sysmem_clear',
1017ec681f3Smrg    args=[Arg(type='enum VkFormat',  var='format',      c_format='%s', to_prim_type='vk_format_description({})->short_name'),
1027ec681f3Smrg          Arg(type='uint8_t',        var='uses_3d_ops', c_format='%u'),
1037ec681f3Smrg          Arg(type='uint8_t',        var='samples',     c_format='%u')],
1047ec681f3Smrg    tp_perfetto='tu_end_sysmem_clear')
1057ec681f3Smrg
1067ec681f3SmrgTracepoint('start_sysmem_clear_all',
1077ec681f3Smrg    tp_perfetto='tu_start_sysmem_clear_all')
1087ec681f3SmrgTracepoint('end_sysmem_clear_all',
1097ec681f3Smrg    args=[Arg(type='uint8_t',        var='mrt_count',   c_format='%u'),
1107ec681f3Smrg          Arg(type='uint8_t',        var='rect_count',  c_format='%u')],
1117ec681f3Smrg    tp_perfetto='tu_end_sysmem_clear_all')
1127ec681f3Smrg
1137ec681f3SmrgTracepoint('start_gmem_load',
1147ec681f3Smrg    tp_perfetto='tu_start_gmem_load')
1157ec681f3SmrgTracepoint('end_gmem_load',
1167ec681f3Smrg    args=[Arg(type='enum VkFormat',  var='format',   c_format='%s', to_prim_type='vk_format_description({})->short_name'),
1177ec681f3Smrg          Arg(type='uint8_t',        var='force_load', c_format='%u')],
1187ec681f3Smrg    tp_perfetto='tu_end_gmem_load')
1197ec681f3Smrg
1207ec681f3SmrgTracepoint('start_gmem_store',
1217ec681f3Smrg    tp_perfetto='tu_start_gmem_store')
1227ec681f3SmrgTracepoint('end_gmem_store',
1237ec681f3Smrg    args=[Arg(type='enum VkFormat',  var='format',   c_format='%s', to_prim_type='vk_format_description({})->short_name'),
1247ec681f3Smrg          Arg(type='uint8_t',        var='fast_path', c_format='%u'),
1257ec681f3Smrg          Arg(type='uint8_t',        var='unaligned', c_format='%u')],
1267ec681f3Smrg    tp_perfetto='tu_end_gmem_store')
1277ec681f3Smrg
1287ec681f3SmrgTracepoint('start_sysmem_resolve',
1297ec681f3Smrg    tp_perfetto='tu_start_sysmem_resolve')
1307ec681f3SmrgTracepoint('end_sysmem_resolve',
1317ec681f3Smrg    args=[Arg(type='enum VkFormat',  var='format',   c_format='%s', to_prim_type='vk_format_description({})->short_name')],
1327ec681f3Smrg    tp_perfetto='tu_end_sysmem_resolve')
1337ec681f3Smrg
1347ec681f3SmrgTracepoint('start_blit',
1357ec681f3Smrg    tp_perfetto='tu_start_blit',
1367ec681f3Smrg)
1377ec681f3SmrgTracepoint('end_blit',
1387ec681f3Smrg    # TODO: add source megapixels count and target megapixels count arguments
1397ec681f3Smrg    args=[Arg(type='uint8_t',        var='uses_3d_blit', c_format='%u'),
1407ec681f3Smrg          Arg(type='enum VkFormat',  var='src_format',   c_format='%s', to_prim_type='vk_format_description({})->short_name'),
1417ec681f3Smrg          Arg(type='enum VkFormat',  var='dst_format',   c_format='%s', to_prim_type='vk_format_description({})->short_name'),
1427ec681f3Smrg          Arg(type='uint8_t',        var='layers',       c_format='%u')],
1437ec681f3Smrg    tp_perfetto='tu_end_blit')
1447ec681f3Smrg
1457ec681f3SmrgTracepoint('start_compute',
1467ec681f3Smrg    tp_perfetto='tu_start_compute')
1477ec681f3SmrgTracepoint('end_compute',
1487ec681f3Smrg    args=[Arg(type='uint8_t',  var='indirect',       c_format='%u'),
1497ec681f3Smrg          Arg(type='uint16_t', var='local_size_x',   c_format='%u'),
1507ec681f3Smrg          Arg(type='uint16_t', var='local_size_y',   c_format='%u'),
1517ec681f3Smrg          Arg(type='uint16_t', var='local_size_z',   c_format='%u'),
1527ec681f3Smrg          Arg(type='uint16_t', var='num_groups_x',   c_format='%u'),
1537ec681f3Smrg          Arg(type='uint16_t', var='num_groups_y',   c_format='%u'),
1547ec681f3Smrg          Arg(type='uint16_t', var='num_groups_z',   c_format='%u')],
1557ec681f3Smrg    tp_perfetto='tu_end_compute')
1567ec681f3Smrg
1577ec681f3Smrgutrace_generate(cpath=args.utrace_src, hpath=args.utrace_hdr, ctx_param='struct tu_device *dev')
1587ec681f3Smrgutrace_generate_perfetto_utils(hpath=args.perfetto_hdr)
159