1 /* 2 * Copyright © 2021 Google, Inc. 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 24 #ifndef FREEDRENO_PERFETTO_H_ 25 #define FREEDRENO_PERFETTO_H_ 26 27 #ifdef __cplusplus 28 extern "C" { 29 #endif 30 31 #ifdef HAVE_PERFETTO 32 33 /** 34 * Render-stage id's 35 */ 36 enum fd_stage_id { 37 SURFACE_STAGE_ID, /* Surface is a sort of meta-stage for render-target info */ 38 BINNING_STAGE_ID, 39 GMEM_STAGE_ID, 40 BYPASS_STAGE_ID, 41 BLIT_STAGE_ID, 42 COMPUTE_STAGE_ID, 43 CLEAR_STAGE_ID, 44 TILE_LOAD_STAGE_ID, 45 TILE_STORE_STAGE_ID, 46 STATE_RESTORE_STAGE_ID, 47 VSC_OVERFLOW_STAGE_ID, 48 PROLOGUE_STAGE_ID, 49 50 NUM_STAGES 51 }; 52 53 static const struct { 54 const char *name; 55 const char *desc; 56 } stages[] = { 57 [SURFACE_STAGE_ID] = {"Surface"}, 58 [BINNING_STAGE_ID] = {"Binning", "Perform Visibility pass and determine target bins"}, 59 [GMEM_STAGE_ID] = {"Render", "Rendering to GMEM"}, 60 [BYPASS_STAGE_ID] = {"Render", "Rendering to system memory"}, 61 [BLIT_STAGE_ID] = {"Blit", "Performing a Blit operation"}, 62 [COMPUTE_STAGE_ID] = {"Compute", "Compute job"}, 63 [CLEAR_STAGE_ID] = {"Clear", "Clear (sysmem) or per-tile clear (GMEM)"}, 64 [TILE_LOAD_STAGE_ID] = {"Tile Load", "Per tile load (system memory to GMEM)"}, 65 [TILE_STORE_STAGE_ID] = {"Tile Store", "Per tile store (GMEM to system memory)"}, 66 [STATE_RESTORE_STAGE_ID] = {"State Restore", "Setup at the beginning of new cmdstream buffer"}, 67 [VSC_OVERFLOW_STAGE_ID] = {"VSC Overflow Test", ""}, 68 [PROLOGUE_STAGE_ID] = {"Prologue", "Preemble cmdstream (executed once before first tile)"}, 69 }; 70 71 /** 72 * Queue-id's 73 */ 74 enum { 75 DEFAULT_HW_QUEUE_ID, 76 }; 77 78 static const struct { 79 const char *name; 80 const char *desc; 81 } queues[] = { 82 [DEFAULT_HW_QUEUE_ID] = {"GPU Queue 0", "Default Adreno Hardware Queue"}, 83 }; 84 85 /** 86 * The u_trace tracepoints which are used to capture GPU timestamps and 87 * trigger perfetto events tend to come in begin/end pairs (ie. start 88 * and end of binning pass, etc), but perfetto wants one event for the 89 * whole pass. So we need to buffer up some state at the "begin" trae 90 * callback, and then emit the perfetto event at the "end" event based 91 * on previously recorded timestamp/data. This struct is where we can 92 * accumulate that state. 93 */ 94 struct fd_perfetto_state { 95 uint64_t start_ts[NUM_STAGES]; 96 97 /* 98 * Surface state for the renderpass: 99 */ 100 uint32_t submit_id; 101 enum pipe_format cbuf0_format : 16; 102 enum pipe_format zs_format : 16; 103 uint16_t width; 104 uint16_t height; 105 uint8_t mrts; 106 uint8_t samples; 107 uint16_t nbins; 108 uint16_t binw; 109 uint16_t binh; 110 // TODO # of draws and possibly estimated cost might be useful addition.. 111 112 /* 113 * Compute state for grids: 114 */ 115 uint8_t indirect; 116 uint8_t work_dim; 117 uint16_t local_size_x; 118 uint16_t local_size_y; 119 uint16_t local_size_z; 120 uint32_t num_groups_x; 121 uint32_t num_groups_y; 122 uint32_t num_groups_z; 123 uint32_t shader_id; 124 }; 125 126 void fd_perfetto_init(void); 127 128 struct fd_context; 129 void fd_perfetto_submit(struct fd_context *ctx); 130 131 #endif 132 133 #ifdef __cplusplus 134 } 135 #endif 136 137 #endif /* FREEDRENO_PERFETTO_H_ */ 138