• 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_COLOR_CLEAR,
48    INTEL_SNAPSHOT_MCS_PARTIAL_RESOLVE,
49    INTEL_SNAPSHOT_SLOW_COLOR_CLEAR,
50    INTEL_SNAPSHOT_SLOW_DEPTH_CLEAR,
51    INTEL_SNAPSHOT_SECONDARY_BATCH,
52    INTEL_SNAPSHOT_END,
53 };
54 
55 enum intel_measure_events {
56    INTEL_MEASURE_DRAW       = (1 << 0),
57    INTEL_MEASURE_RENDERPASS = (1 << 1),
58    INTEL_MEASURE_SHADER     = (1 << 2),
59    INTEL_MEASURE_BATCH      = (1 << 3),
60    INTEL_MEASURE_FRAME      = (1 << 4),
61 };
62 
63 struct intel_measure_config {
64 
65    /* Stderr, or optionally set with INTEL_MEASURE=file={path{ */
66    FILE                      *file;
67 
68    /* Events that will be measured.  Set only one flag, with
69     * INTEL_MEASURE=[draw,rt,shader,batch,frame] */
70    enum intel_measure_events  flags;
71 
72    /* Optionally set with INTEL_MEASURE=start={num} */
73    unsigned                   start_frame;
74 
75    /* Optionally calculated with INTEL_MEASURE=count={num} based on
76     * start_frame
77     */
78    unsigned                   end_frame;
79 
80    /* Number of events to combine per line of output. Optionally set with
81     * INTEL_MEASURE=interval={num}
82     */
83    unsigned                   event_interval;
84 
85    /* Max snapshots per batch.  Set with
86     * INTEL_MEASURE=batch_size={num}. Additional snapshots will be dropped.
87     */
88    unsigned                   batch_size;
89 
90    /* Max number of batch measurements that can be buffered, for combining
91     * snapshots into frame or interval data.
92     */
93    unsigned                   buffer_size;
94 
95    /* Fifo which will be read to enable measurements at run-time.  Set with
96     * INTEL_MEASURE=control={path}.  `echo {num} > {path}` will collect num
97     * frames of measurements, beginning with the next frame boundary.
98     */
99    int                        control_fh;
100 
101    /* true when snapshots are currently being collected */
102    bool                       enabled;
103 };
104 
105 struct intel_measure_batch;
106 
107 struct intel_measure_snapshot {
108    enum intel_measure_snapshot_type type;
109    unsigned count, event_count;
110    const char* event_name;
111    uintptr_t framebuffer, vs, tcs, tes, gs, fs, cs;
112    /* for vulkan secondary command buffers */
113    struct intel_measure_batch *secondary;
114 };
115 
116 struct intel_measure_buffered_result {
117    struct intel_measure_snapshot snapshot;
118    uint64_t start_ts, end_ts, idle_duration;
119    unsigned frame, batch_count, event_index;
120 };
121 
122 struct intel_measure_ringbuffer {
123    unsigned head, tail;
124    struct intel_measure_buffered_result results[0];
125 };
126 
127 struct intel_measure_device {
128    struct intel_measure_config *config;
129    unsigned frame;
130 
131    /* Holds the list of (iris/anv)_measure_batch snapshots that have been
132     * submitted for rendering, but have not completed.
133     */
134    pthread_mutex_t mutex;
135    struct list_head queued_snapshots;
136 
137    /* Holds completed snapshots that may need to be combined before being
138     * written out
139     */
140    struct intel_measure_ringbuffer *ringbuffer;
141 };
142 
143 struct intel_measure_batch {
144    struct list_head link;
145    unsigned index;
146    unsigned frame, batch_count, event_count;
147    uintptr_t framebuffer;
148    uint64_t *timestamps;
149    struct intel_measure_snapshot snapshots[0];
150 };
151 
152 void intel_measure_init(struct intel_measure_device *device);
153 const char * intel_measure_snapshot_string(enum intel_measure_snapshot_type type);
154 bool intel_measure_state_changed(const struct intel_measure_batch *batch,
155                                  uintptr_t vs, uintptr_t tcs, uintptr_t tes,
156                                  uintptr_t gs, uintptr_t fs, uintptr_t cs);
157 void intel_measure_frame_transition(unsigned frame);
158 
159 bool intel_measure_ready(struct intel_measure_batch *batch);
160 
161 struct intel_device_info;
162 void intel_measure_gather(struct intel_measure_device *device,
163                           struct intel_device_info *info);
164 
165 #endif /* INTEL_MEASURE_H */
166