• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2020 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  * on the rights to use, copy, modify, merge, publish, distribute, sub
8  * license, and/or sell copies of the Software, and to permit persons to whom
9  * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
18  * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21  * USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23 
24 #ifndef INTEL_MEASURE_H
25 #define INTEL_MEASURE_H
26 
27 #include <pthread.h>
28 #include <stdio.h>
29 #include <stdbool.h>
30 #include <stdint.h>
31 
32 #include "util/list.h"
33 
34 enum intel_measure_snapshot_type {
35    INTEL_SNAPSHOT_UNDEFINED,
36    INTEL_SNAPSHOT_BLIT,
37    INTEL_SNAPSHOT_CCS_AMBIGUATE,
38    INTEL_SNAPSHOT_CCS_COLOR_CLEAR,
39    INTEL_SNAPSHOT_CCS_PARTIAL_RESOLVE,
40    INTEL_SNAPSHOT_CCS_RESOLVE,
41    INTEL_SNAPSHOT_COMPUTE,
42    INTEL_SNAPSHOT_COPY,
43    INTEL_SNAPSHOT_DRAW,
44    INTEL_SNAPSHOT_HIZ_AMBIGUATE,
45    INTEL_SNAPSHOT_HIZ_CLEAR,
46    INTEL_SNAPSHOT_HIZ_RESOLVE,
47    INTEL_SNAPSHOT_MCS_AMBIGUATE,
48    INTEL_SNAPSHOT_MCS_COLOR_CLEAR,
49    INTEL_SNAPSHOT_MCS_PARTIAL_RESOLVE,
50    INTEL_SNAPSHOT_SLOW_COLOR_CLEAR,
51    INTEL_SNAPSHOT_SLOW_DEPTH_CLEAR,
52    INTEL_SNAPSHOT_SECONDARY_BATCH,
53    INTEL_SNAPSHOT_END,
54 };
55 
56 enum intel_measure_events {
57    INTEL_MEASURE_DRAW       = (1 << 0),
58    INTEL_MEASURE_RENDERPASS = (1 << 1),
59    INTEL_MEASURE_SHADER     = (1 << 2),
60    INTEL_MEASURE_BATCH      = (1 << 3),
61    INTEL_MEASURE_FRAME      = (1 << 4),
62 };
63 
64 enum intel_measure_device_type { INTEL_MEASURE_DEVICE_VK=0, INTEL_MEASURE_DEVICE_OGL };
65 
66 struct intel_measure_config {
67 
68    /* Stderr, or optionally set with INTEL_MEASURE=file={path{ */
69    FILE                      *file;
70 
71    /* Defer log file create until first write */
72    char                      *deferred_create_filename;
73 
74    /* Events that will be measured.  Set only one flag, with
75     * INTEL_MEASURE=[draw,rt,shader,batch,frame] */
76    enum intel_measure_events  flags;
77 
78    /* Optionally set with INTEL_MEASURE=start={num} */
79    unsigned                   start_frame;
80 
81    /* Optionally calculated with INTEL_MEASURE=count={num} based on
82     * start_frame
83     */
84    unsigned                   end_frame;
85 
86    /* Number of events to combine per line of output. Optionally set with
87     * INTEL_MEASURE=interval={num}
88     */
89    unsigned                   event_interval;
90 
91    /* Max snapshots per batch.  Set with
92     * INTEL_MEASURE=batch_size={num}. Additional snapshots will be dropped.
93     */
94    unsigned                   batch_size;
95 
96    /* Max number of batch measurements that can be buffered, for combining
97     * snapshots into frame or interval data.
98     */
99    unsigned                   buffer_size;
100 
101    /* Fifo which will be read to enable measurements at run-time.  Set with
102     * INTEL_MEASURE=control={path}.  `echo {num} > {path}` will collect num
103     * frames of measurements, beginning with the next frame boundary.
104     */
105    int                        control_fh;
106 
107    /* true when snapshots are currently being collected */
108    bool                       enabled;
109 
110    /* Measure CPU timing, not GPU timing */
111    bool                       cpu_measure;
112 };
113 
114 struct intel_measure_batch;
115 
116 struct intel_measure_snapshot {
117    enum intel_measure_snapshot_type type;
118    unsigned count, event_count;
119    const char* event_name;
120    uint32_t renderpass;
121    uint32_t vs, tcs, tes, gs, fs, cs, ms, ts;
122    /* for vulkan secondary command buffers */
123    struct intel_measure_batch *secondary;
124 };
125 
126 struct intel_measure_buffered_result {
127    struct intel_measure_snapshot snapshot;
128    uint64_t start_ts, end_ts, idle_duration, batch_size;
129    unsigned frame, batch_count, event_index, primary_renderpass;
130 ;
131 };
132 
133 struct intel_measure_ringbuffer {
134    unsigned head, tail;
135    struct intel_measure_buffered_result results[0];
136 };
137 
138 /* This function will be called when enqueued snapshots have been processed */
139 typedef void (*intel_measure_release_batch_cb)(struct intel_measure_batch *base);
140 
141 struct intel_measure_device {
142    struct intel_measure_config *config;
143    unsigned frame;
144    unsigned render_pass_count;
145    intel_measure_release_batch_cb release_batch;
146    enum intel_measure_device_type type;
147 
148    /* Holds the list of (iris/anv)_measure_batch snapshots that have been
149     * submitted for rendering, but have not completed.
150     */
151    pthread_mutex_t mutex;
152    struct list_head queued_snapshots;
153 
154    /* Holds completed snapshots that may need to be combined before being
155     * written out
156     */
157    struct intel_measure_ringbuffer *ringbuffer;
158 };
159 
160 struct intel_measure_batch {
161    struct list_head link;
162    unsigned index;
163    unsigned frame, batch_count, event_count;
164    uint64_t batch_size;
165    uint32_t renderpass, primary_renderpass;
166    uint64_t *timestamps;
167    struct intel_measure_snapshot snapshots[0];
168 };
169 
170 void intel_measure_init(struct intel_measure_device *device);
171 const char * intel_measure_snapshot_string(enum intel_measure_snapshot_type type);
172 bool intel_measure_state_changed(const struct intel_measure_batch *batch,
173                                  uint32_t vs, uint32_t tcs, uint32_t tes,
174                                  uint32_t gs, uint32_t fs, uint32_t cs,
175                                  uint32_t ms, uint32_t ts);
176 void intel_measure_frame_transition(unsigned frame);
177 
178 bool intel_measure_ready(struct intel_measure_batch *batch);
179 
180 struct intel_device_info;
181 void intel_measure_print_cpu_result(unsigned int frame,
182                                     unsigned int batch_count,
183                                     uint64_t batch_size,
184                                     unsigned int event_index,
185                                     unsigned int event_count,
186                                     unsigned int count,
187                                     const char* event_name);
188 void intel_measure_gather(struct intel_measure_device *device,
189                           const struct intel_device_info *info);
190 
191 #endif /* INTEL_MEASURE_H */
192