1# 2# Copyright © 2021 Intel Corporation 3# 4# Permission is hereby granted, free of charge, to any person obtaining a 5# copy of this software and associated documentation files (the "Software"), 6# to deal in the Software without restriction, including without limitation 7# the rights to use, copy, modify, merge, publish, distribute, sublicense, 8# and/or sell copies of the Software, and to permit persons to whom the 9# Software is furnished to do so, subject to the following conditions: 10# 11# The above copyright notice and this permission notice (including the next 12# paragraph) shall be included in all copies or substantial portions of the 13# Software. 14# 15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21# SOFTWARE. 22# 23 24import argparse 25import sys 26 27# 28# Tracepoint definitions: 29# 30def define_tracepoints(args): 31 from u_trace import Header, HeaderScope 32 from u_trace import ForwardDecl 33 from u_trace import Tracepoint 34 from u_trace import TracepointArg as Arg 35 from u_trace import TracepointArgStruct as ArgStruct 36 37 Header('intel_driver_ds.h', scope=HeaderScope.SOURCE) 38 Header('blorp/blorp_priv.h', scope=HeaderScope.HEADER) 39 Header('ds/intel_driver_ds.h', scope=HeaderScope.HEADER) 40 41 def begin_end_tp(name, tp_args=[], tp_struct=None, tp_print=None, end_pipelined=True): 42 Tracepoint('intel_begin_{0}'.format(name), 43 tp_perfetto='intel_ds_begin_{0}'.format(name)) 44 Tracepoint('intel_end_{0}'.format(name), 45 args=tp_args, 46 tp_struct=tp_struct, 47 tp_perfetto='intel_ds_end_{0}'.format(name), 48 tp_print=tp_print, 49 end_of_pipe=end_pipelined) 50 51 52 begin_end_tp('batch', 53 tp_args=[Arg(type='uint8_t', var='name', c_format='%hhu'),], 54 end_pipelined=False) 55 56 begin_end_tp('cmd_buffer', 57 tp_args=[Arg(type='uint8_t', var='level', c_format='%hhu'),], 58 end_pipelined=False) 59 60 begin_end_tp('render_pass', 61 tp_args=[Arg(type='uint16_t', var='width', c_format='%hu'), 62 Arg(type='uint16_t', var='height', c_format='%hu'), 63 Arg(type='uint8_t', var='att_count', c_format='%hhu'), 64 Arg(type='uint8_t', var='msaa', c_format='%hhu'),]) 65 66 begin_end_tp('dyn_render_pass', 67 tp_args=[Arg(type='uint16_t', var='width', c_format='%hu'), 68 Arg(type='uint16_t', var='height', c_format='%hu'), 69 Arg(type='uint8_t', var='att_count', c_format='%hhu'), 70 Arg(type='uint8_t', var='msaa', c_format='%hhu'), 71 Arg(type='uint8_t', var='suspend', c_format='%hhu'), 72 Arg(type='uint8_t', var='resume', c_format='%hhu'),]) 73 74 begin_end_tp('blorp', 75 tp_args=[Arg(type='uint32_t', name='width', var='width', c_format='%u'), 76 Arg(type='uint32_t', name='height', var='height', c_format='%u'), 77 Arg(type='enum isl_aux_op', name='hiz_op', var='hiz_op', c_format='%s', to_prim_type='isl_aux_op_to_name({})'), 78 Arg(type='enum isl_aux_op', name='fast_clear_op', var='fast_clear_op', c_format='%s', to_prim_type='isl_aux_op_to_name({})'), 79 Arg(type='enum blorp_shader_type', name='blorp_type', var='shader_type', c_format='%s', to_prim_type='blorp_shader_type_to_name({})'), 80 Arg(type='enum blorp_shader_pipeline', name='blorp_pipe', var='shader_pipe', c_format='%s', to_prim_type='blorp_shader_pipeline_to_name({})'),]) 81 82 begin_end_tp('draw', 83 tp_args=[Arg(type='uint32_t', var='count', c_format='%u')]) 84 begin_end_tp('draw_multi', 85 tp_args=[Arg(type='uint32_t', var='count', c_format='%u'),]) 86 begin_end_tp('draw_indexed', 87 tp_args=[Arg(type='uint32_t', var='count', c_format='%u'),]) 88 begin_end_tp('draw_indexed_multi', 89 tp_args=[Arg(type='uint32_t', var='count', c_format='%u'),]) 90 begin_end_tp('draw_indirect_byte_count', 91 tp_args=[Arg(type='uint32_t', var='instance_count', c_format='%u'),]) 92 begin_end_tp('draw_indirect', 93 tp_args=[Arg(type='uint32_t', var='draw_count', c_format='%u'),]) 94 begin_end_tp('draw_indexed_indirect', 95 tp_args=[Arg(type='uint32_t', var='draw_count', c_format='%u'),]) 96 begin_end_tp('draw_indirect_count', 97 tp_args=[Arg(type='uint32_t', var='max_draw_count', c_format='%u'),]) 98 begin_end_tp('draw_indexed_indirect_count', 99 tp_args=[Arg(type='uint32_t', var='max_draw_count', c_format='%u'),]) 100 101 begin_end_tp('compute', 102 tp_args=[Arg(type='uint32_t', var='group_x', c_format='%u'), 103 Arg(type='uint32_t', var='group_y', c_format='%u'), 104 Arg(type='uint32_t', var='group_z', c_format='%u'),], 105 tp_print=['group=%ux%ux%u', '__entry->group_x', '__entry->group_y', '__entry->group_z']) 106 107 def flag_bits(args): 108 bits = [Arg(type='enum intel_ds_stall_flag', name='flags', var='decode_cb(flags)', c_format='0x%x')] 109 for a in args: 110 bits.append(Arg(type='bool', name=a[1], var='__entry->flags & INTEL_DS_{0}_BIT'.format(a[0]), c_format='%u')) 111 return bits 112 113 def stall_args(args): 114 fmt = '' 115 exprs = [] 116 for a in args: 117 fmt += '%s' 118 exprs.append('(__entry->flags & INTEL_DS_{0}_BIT) ? "+{1}" : ""'.format(a[0], a[1])) 119 fmt += ' : %s' 120 exprs.append('__entry->reason ? __entry->reason : "unknown"') 121 fmt = [fmt] 122 fmt += exprs 123 return fmt 124 125 stall_flags = [['DEPTH_CACHE_FLUSH', 'depth_flush'], 126 ['DATA_CACHE_FLUSH', 'dc_flush'], 127 ['HDC_PIPELINE_FLUSH', 'hdc_flush'], 128 ['RENDER_TARGET_CACHE_FLUSH', 'rt_flush'], 129 ['TILE_CACHE_FLUSH', 'tile_flush'], 130 ['STATE_CACHE_INVALIDATE', 'state_inval'], 131 ['CONST_CACHE_INVALIDATE', 'const_inval'], 132 ['VF_CACHE_INVALIDATE', 'vf_inval'], 133 ['TEXTURE_CACHE_INVALIDATE', 'tex_inval'], 134 ['INST_CACHE_INVALIDATE', 'ic_inval'], 135 ['STALL_AT_SCOREBOARD', 'pb_stall'], 136 ['DEPTH_STALL', 'depth_stall'], 137 ['CS_STALL', 'cs_stall']] 138 139 begin_end_tp('stall', 140 tp_args=[ArgStruct(type='uint32_t', var='flags'), 141 ArgStruct(type='intel_ds_stall_cb_t', var='decode_cb'), 142 ArgStruct(type='const char *', var='reason'),], 143 tp_struct=[Arg(type='uint32_t', name='flags', var='decode_cb(flags)', c_format='0x%x'), 144 Arg(type='const char *', name='reason', var='reason', c_format='%s'),], 145 tp_print=stall_args(stall_flags), 146 end_pipelined=False) 147 148 149def generate_code(args): 150 from u_trace import utrace_generate 151 from u_trace import utrace_generate_perfetto_utils 152 153 utrace_generate(cpath=args.utrace_src, hpath=args.utrace_hdr, 154 ctx_param='struct intel_ds_device *dev', 155 need_cs_param=False) 156 utrace_generate_perfetto_utils(hpath=args.perfetto_hdr) 157 158 159def main(): 160 parser = argparse.ArgumentParser() 161 parser.add_argument('-p', '--import-path', required=True) 162 parser.add_argument('--utrace-src', required=True) 163 parser.add_argument('--utrace-hdr', required=True) 164 parser.add_argument('--perfetto-hdr', required=True) 165 args = parser.parse_args() 166 sys.path.insert(0, args.import_path) 167 define_tracepoints(args) 168 generate_code(args) 169 170 171if __name__ == '__main__': 172 main() 173