1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright © 2021 Google, Inc.
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci * Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20bf215546Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21bf215546Sopenharmony_ci * SOFTWARE.
22bf215546Sopenharmony_ci */
23bf215546Sopenharmony_ci
24bf215546Sopenharmony_ci#ifndef FREEDRENO_PERFETTO_H_
25bf215546Sopenharmony_ci#define FREEDRENO_PERFETTO_H_
26bf215546Sopenharmony_ci
27bf215546Sopenharmony_ci#ifdef __cplusplus
28bf215546Sopenharmony_ciextern "C" {
29bf215546Sopenharmony_ci#endif
30bf215546Sopenharmony_ci
31bf215546Sopenharmony_ci#ifdef HAVE_PERFETTO
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_ci/**
34bf215546Sopenharmony_ci * Render-stage id's
35bf215546Sopenharmony_ci */
36bf215546Sopenharmony_cienum fd_stage_id {
37bf215546Sopenharmony_ci   SURFACE_STAGE_ID, /* Surface is a sort of meta-stage for render-target info */
38bf215546Sopenharmony_ci   BINNING_STAGE_ID,
39bf215546Sopenharmony_ci   GMEM_STAGE_ID,
40bf215546Sopenharmony_ci   BYPASS_STAGE_ID,
41bf215546Sopenharmony_ci   BLIT_STAGE_ID,
42bf215546Sopenharmony_ci   COMPUTE_STAGE_ID,
43bf215546Sopenharmony_ci   CLEAR_RESTORE_STAGE_ID,
44bf215546Sopenharmony_ci   RESOLVE_STAGE_ID,
45bf215546Sopenharmony_ci   STATE_RESTORE_STAGE_ID,
46bf215546Sopenharmony_ci   VSC_OVERFLOW_STAGE_ID,
47bf215546Sopenharmony_ci   PROLOGUE_STAGE_ID,
48bf215546Sopenharmony_ci
49bf215546Sopenharmony_ci   NUM_STAGES
50bf215546Sopenharmony_ci};
51bf215546Sopenharmony_ci
52bf215546Sopenharmony_cistatic const struct {
53bf215546Sopenharmony_ci   const char *name;
54bf215546Sopenharmony_ci   const char *desc;
55bf215546Sopenharmony_ci} stages[] = {
56bf215546Sopenharmony_ci   [SURFACE_STAGE_ID] = {"Surface"},
57bf215546Sopenharmony_ci   [BINNING_STAGE_ID] = {"Binning", "Perform Visibility pass and determine target bins"},
58bf215546Sopenharmony_ci   [GMEM_STAGE_ID]    = {"Render", "Rendering to GMEM"},
59bf215546Sopenharmony_ci   [BYPASS_STAGE_ID]  = {"Render", "Rendering to system memory"},
60bf215546Sopenharmony_ci   [BLIT_STAGE_ID]    = {"Blit", "Performing a Blit operation"},
61bf215546Sopenharmony_ci   [COMPUTE_STAGE_ID] = {"Compute", "Compute job"},
62bf215546Sopenharmony_ci   [CLEAR_RESTORE_STAGE_ID] = {"Clear/Restore", "Clear (sysmem) or per-tile clear or restore (GMEM)"},
63bf215546Sopenharmony_ci   [RESOLVE_STAGE_ID] = {"Resolve", "Per tile resolve (GMEM to system memory"},
64bf215546Sopenharmony_ci   [STATE_RESTORE_STAGE_ID] = {"State Restore", "Setup at the beginning of new cmdstream buffer"},
65bf215546Sopenharmony_ci   [VSC_OVERFLOW_STAGE_ID] = {"VSC Overflow Test", ""},
66bf215546Sopenharmony_ci   [PROLOGUE_STAGE_ID] = {"Prologue", "Preemble cmdstream (executed once before first tile)"},
67bf215546Sopenharmony_ci};
68bf215546Sopenharmony_ci
69bf215546Sopenharmony_ci/**
70bf215546Sopenharmony_ci * Queue-id's
71bf215546Sopenharmony_ci */
72bf215546Sopenharmony_cienum {
73bf215546Sopenharmony_ci   DEFAULT_HW_QUEUE_ID,
74bf215546Sopenharmony_ci};
75bf215546Sopenharmony_ci
76bf215546Sopenharmony_cistatic const struct {
77bf215546Sopenharmony_ci   const char *name;
78bf215546Sopenharmony_ci   const char *desc;
79bf215546Sopenharmony_ci} queues[] = {
80bf215546Sopenharmony_ci   [DEFAULT_HW_QUEUE_ID] = {"GPU Queue 0", "Default Adreno Hardware Queue"},
81bf215546Sopenharmony_ci};
82bf215546Sopenharmony_ci
83bf215546Sopenharmony_ci/**
84bf215546Sopenharmony_ci * The u_trace tracepoints which are used to capture GPU timestamps and
85bf215546Sopenharmony_ci * trigger perfetto events tend to come in begin/end pairs (ie. start
86bf215546Sopenharmony_ci * and end of binning pass, etc), but perfetto wants one event for the
87bf215546Sopenharmony_ci * whole pass.  So we need to buffer up some state at the "begin" trae
88bf215546Sopenharmony_ci * callback, and then emit the perfetto event at the "end" event based
89bf215546Sopenharmony_ci * on previously recorded timestamp/data.  This struct is where we can
90bf215546Sopenharmony_ci * accumulate that state.
91bf215546Sopenharmony_ci */
92bf215546Sopenharmony_cistruct fd_perfetto_state {
93bf215546Sopenharmony_ci   uint64_t start_ts[NUM_STAGES];
94bf215546Sopenharmony_ci
95bf215546Sopenharmony_ci   /*
96bf215546Sopenharmony_ci    * Surface state for the renderpass:
97bf215546Sopenharmony_ci    */
98bf215546Sopenharmony_ci   uint32_t submit_id;
99bf215546Sopenharmony_ci   enum pipe_format cbuf0_format : 16;
100bf215546Sopenharmony_ci   enum pipe_format zs_format : 16;
101bf215546Sopenharmony_ci   uint16_t width;
102bf215546Sopenharmony_ci   uint16_t height;
103bf215546Sopenharmony_ci   uint8_t mrts;
104bf215546Sopenharmony_ci   uint8_t samples;
105bf215546Sopenharmony_ci   uint16_t nbins;
106bf215546Sopenharmony_ci   uint16_t binw;
107bf215546Sopenharmony_ci   uint16_t binh;
108bf215546Sopenharmony_ci   // TODO # of draws and possibly estimated cost might be useful addition..
109bf215546Sopenharmony_ci};
110bf215546Sopenharmony_ci
111bf215546Sopenharmony_civoid fd_perfetto_init(void);
112bf215546Sopenharmony_ci
113bf215546Sopenharmony_cistruct fd_context;
114bf215546Sopenharmony_civoid fd_perfetto_submit(struct fd_context *ctx);
115bf215546Sopenharmony_ci
116bf215546Sopenharmony_ci#endif
117bf215546Sopenharmony_ci
118bf215546Sopenharmony_ci#ifdef __cplusplus
119bf215546Sopenharmony_ci}
120bf215546Sopenharmony_ci#endif
121bf215546Sopenharmony_ci
122bf215546Sopenharmony_ci#endif /* FREEDRENO_PERFETTO_H_ */
123