1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright © 2021 Google, Inc.
3bf215546Sopenharmony_ci * SPDX-License-Identifier: MIT
4bf215546Sopenharmony_ci */
5bf215546Sopenharmony_ci
6bf215546Sopenharmony_ci#ifndef TU_PERFETTO_H_
7bf215546Sopenharmony_ci#define TU_PERFETTO_H_
8bf215546Sopenharmony_ci
9bf215546Sopenharmony_ci#ifdef __cplusplus
10bf215546Sopenharmony_ciextern "C" {
11bf215546Sopenharmony_ci#endif
12bf215546Sopenharmony_ci
13bf215546Sopenharmony_ci#ifdef HAVE_PERFETTO
14bf215546Sopenharmony_ci
15bf215546Sopenharmony_ci/**
16bf215546Sopenharmony_ci * Render-stage id's
17bf215546Sopenharmony_ci */
18bf215546Sopenharmony_cienum tu_stage_id {
19bf215546Sopenharmony_ci   SURFACE_STAGE_ID, /* Surface is a sort of meta-stage for render-target info */
20bf215546Sopenharmony_ci   BINNING_STAGE_ID,
21bf215546Sopenharmony_ci   GMEM_STAGE_ID,
22bf215546Sopenharmony_ci   BYPASS_STAGE_ID,
23bf215546Sopenharmony_ci   BLIT_STAGE_ID,
24bf215546Sopenharmony_ci   COMPUTE_STAGE_ID,
25bf215546Sopenharmony_ci   CLEAR_SYSMEM_STAGE_ID,
26bf215546Sopenharmony_ci   CLEAR_GMEM_STAGE_ID,
27bf215546Sopenharmony_ci   GMEM_LOAD_STAGE_ID,
28bf215546Sopenharmony_ci   GMEM_STORE_STAGE_ID,
29bf215546Sopenharmony_ci   SYSMEM_RESOLVE_STAGE_ID,
30bf215546Sopenharmony_ci   // TODO add the rest
31bf215546Sopenharmony_ci
32bf215546Sopenharmony_ci   NUM_STAGES
33bf215546Sopenharmony_ci};
34bf215546Sopenharmony_ci
35bf215546Sopenharmony_cistatic const struct {
36bf215546Sopenharmony_ci   const char *name;
37bf215546Sopenharmony_ci   const char *desc;
38bf215546Sopenharmony_ci} stages[] = {
39bf215546Sopenharmony_ci   [SURFACE_STAGE_ID] = {"Surface"},
40bf215546Sopenharmony_ci   [BINNING_STAGE_ID] = {"Binning", "Perform Visibility pass and determine target bins"},
41bf215546Sopenharmony_ci   [GMEM_STAGE_ID]    = {"Render", "Rendering to GMEM"},
42bf215546Sopenharmony_ci   [BYPASS_STAGE_ID]  = {"Render", "Rendering to system memory"},
43bf215546Sopenharmony_ci   [BLIT_STAGE_ID]    = {"Blit", "Performing a Blit operation"},
44bf215546Sopenharmony_ci   [COMPUTE_STAGE_ID] = {"Compute", "Compute job"},
45bf215546Sopenharmony_ci   [CLEAR_SYSMEM_STAGE_ID] = {"Clear Sysmem", ""},
46bf215546Sopenharmony_ci   [CLEAR_GMEM_STAGE_ID] = {"Clear GMEM", "Per-tile (GMEM) clear"},
47bf215546Sopenharmony_ci   [GMEM_LOAD_STAGE_ID] = {"GMEM Load", "Per tile system memory to GMEM load"},
48bf215546Sopenharmony_ci   [GMEM_STORE_STAGE_ID] = {"GMEM Store", "Per tile GMEM to system memory store"},
49bf215546Sopenharmony_ci   [SYSMEM_RESOLVE_STAGE_ID] = {"SysMem Resolve", "System memory MSAA resolve"},
50bf215546Sopenharmony_ci   // TODO add the rest
51bf215546Sopenharmony_ci};
52bf215546Sopenharmony_ci
53bf215546Sopenharmony_ci/**
54bf215546Sopenharmony_ci * Queue-id's
55bf215546Sopenharmony_ci */
56bf215546Sopenharmony_cienum {
57bf215546Sopenharmony_ci   DEFAULT_HW_QUEUE_ID,
58bf215546Sopenharmony_ci};
59bf215546Sopenharmony_ci
60bf215546Sopenharmony_cistatic const struct {
61bf215546Sopenharmony_ci   const char *name;
62bf215546Sopenharmony_ci   const char *desc;
63bf215546Sopenharmony_ci} queues[] = {
64bf215546Sopenharmony_ci   [DEFAULT_HW_QUEUE_ID] = {"GPU Queue 0", "Default Adreno Hardware Queue"},
65bf215546Sopenharmony_ci};
66bf215546Sopenharmony_ci
67bf215546Sopenharmony_cistruct tu_perfetto_state {
68bf215546Sopenharmony_ci   uint64_t start_ts[NUM_STAGES];
69bf215546Sopenharmony_ci};
70bf215546Sopenharmony_ci
71bf215546Sopenharmony_civoid tu_perfetto_init(void);
72bf215546Sopenharmony_ci
73bf215546Sopenharmony_cistruct tu_device;
74bf215546Sopenharmony_civoid tu_perfetto_submit(struct tu_device *dev, uint32_t submission_id);
75bf215546Sopenharmony_ci
76bf215546Sopenharmony_ci/* Helpers */
77bf215546Sopenharmony_ci
78bf215546Sopenharmony_cistruct tu_perfetto_state *
79bf215546Sopenharmony_citu_device_get_perfetto_state(struct tu_device *dev);
80bf215546Sopenharmony_ci
81bf215546Sopenharmony_ciint
82bf215546Sopenharmony_citu_device_get_gpu_timestamp(struct tu_device *dev,
83bf215546Sopenharmony_ci                            uint64_t *ts);
84bf215546Sopenharmony_ci
85bf215546Sopenharmony_ciint
86bf215546Sopenharmony_citu_device_get_suspend_count(struct tu_device *dev,
87bf215546Sopenharmony_ci                            uint64_t *suspend_count);
88bf215546Sopenharmony_ci
89bf215546Sopenharmony_ciuint64_t
90bf215546Sopenharmony_citu_device_ticks_to_ns(struct tu_device *dev, uint64_t ts);
91bf215546Sopenharmony_ci
92bf215546Sopenharmony_cistruct tu_u_trace_submission_data;
93bf215546Sopenharmony_ciuint32_t
94bf215546Sopenharmony_citu_u_trace_submission_data_get_submit_id(const struct tu_u_trace_submission_data *data);
95bf215546Sopenharmony_ci
96bf215546Sopenharmony_ci#endif
97bf215546Sopenharmony_ci
98bf215546Sopenharmony_ci#ifdef __cplusplus
99bf215546Sopenharmony_ci}
100bf215546Sopenharmony_ci#endif
101bf215546Sopenharmony_ci
102bf215546Sopenharmony_ci#endif /* TU_PERFETTO_H_ */
103