17ec681f3Smrg/* 27ec681f3Smrg * Copyright © 2020 Intel Corporation 37ec681f3Smrg * 47ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a 57ec681f3Smrg * copy of this software and associated documentation files (the "Software"), 67ec681f3Smrg * to deal in the Software without restriction, including without limitation 77ec681f3Smrg * on the rights to use, copy, modify, merge, publish, distribute, sub 87ec681f3Smrg * license, and/or sell copies of the Software, and to permit persons to whom 97ec681f3Smrg * the Software is furnished to do so, subject to the following conditions: 107ec681f3Smrg * 117ec681f3Smrg * The above copyright notice and this permission notice (including the next 127ec681f3Smrg * paragraph) shall be included in all copies or substantial portions of the 137ec681f3Smrg * Software. 147ec681f3Smrg * 157ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 167ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 177ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 187ec681f3Smrg * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 197ec681f3Smrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 207ec681f3Smrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 217ec681f3Smrg * USE OR OTHER DEALINGS IN THE SOFTWARE. 227ec681f3Smrg */ 237ec681f3Smrg 247ec681f3Smrg#ifndef INTEL_MEASURE_H 257ec681f3Smrg#define INTEL_MEASURE_H 267ec681f3Smrg 277ec681f3Smrg#include <pthread.h> 287ec681f3Smrg#include <stdio.h> 297ec681f3Smrg#include <stdbool.h> 307ec681f3Smrg#include <stdint.h> 317ec681f3Smrg 327ec681f3Smrg#include "util/list.h" 337ec681f3Smrg 347ec681f3Smrgenum intel_measure_snapshot_type { 357ec681f3Smrg INTEL_SNAPSHOT_UNDEFINED, 367ec681f3Smrg INTEL_SNAPSHOT_BLIT, 377ec681f3Smrg INTEL_SNAPSHOT_CCS_AMBIGUATE, 387ec681f3Smrg INTEL_SNAPSHOT_CCS_COLOR_CLEAR, 397ec681f3Smrg INTEL_SNAPSHOT_CCS_PARTIAL_RESOLVE, 407ec681f3Smrg INTEL_SNAPSHOT_CCS_RESOLVE, 417ec681f3Smrg INTEL_SNAPSHOT_COMPUTE, 427ec681f3Smrg INTEL_SNAPSHOT_COPY, 437ec681f3Smrg INTEL_SNAPSHOT_DRAW, 447ec681f3Smrg INTEL_SNAPSHOT_HIZ_AMBIGUATE, 457ec681f3Smrg INTEL_SNAPSHOT_HIZ_CLEAR, 467ec681f3Smrg INTEL_SNAPSHOT_HIZ_RESOLVE, 477ec681f3Smrg INTEL_SNAPSHOT_MCS_COLOR_CLEAR, 487ec681f3Smrg INTEL_SNAPSHOT_MCS_PARTIAL_RESOLVE, 497ec681f3Smrg INTEL_SNAPSHOT_SLOW_COLOR_CLEAR, 507ec681f3Smrg INTEL_SNAPSHOT_SLOW_DEPTH_CLEAR, 517ec681f3Smrg INTEL_SNAPSHOT_SECONDARY_BATCH, 527ec681f3Smrg INTEL_SNAPSHOT_END, 537ec681f3Smrg}; 547ec681f3Smrg 557ec681f3Smrgenum intel_measure_events { 567ec681f3Smrg INTEL_MEASURE_DRAW = (1 << 0), 577ec681f3Smrg INTEL_MEASURE_RENDERPASS = (1 << 1), 587ec681f3Smrg INTEL_MEASURE_SHADER = (1 << 2), 597ec681f3Smrg INTEL_MEASURE_BATCH = (1 << 3), 607ec681f3Smrg INTEL_MEASURE_FRAME = (1 << 4), 617ec681f3Smrg}; 627ec681f3Smrg 637ec681f3Smrgstruct intel_measure_config { 647ec681f3Smrg 657ec681f3Smrg /* Stderr, or optionally set with INTEL_MEASURE=file={path{ */ 667ec681f3Smrg FILE *file; 677ec681f3Smrg 687ec681f3Smrg /* Events that will be measured. Set only one flag, with 697ec681f3Smrg * INTEL_MEASURE=[draw,rt,shader,batch,frame] */ 707ec681f3Smrg enum intel_measure_events flags; 717ec681f3Smrg 727ec681f3Smrg /* Optionally set with INTEL_MEASURE=start={num} */ 737ec681f3Smrg unsigned start_frame; 747ec681f3Smrg 757ec681f3Smrg /* Optionally calculated with INTEL_MEASURE=count={num} based on 767ec681f3Smrg * start_frame 777ec681f3Smrg */ 787ec681f3Smrg unsigned end_frame; 797ec681f3Smrg 807ec681f3Smrg /* Number of events to combine per line of output. Optionally set with 817ec681f3Smrg * INTEL_MEASURE=interval={num} 827ec681f3Smrg */ 837ec681f3Smrg unsigned event_interval; 847ec681f3Smrg 857ec681f3Smrg /* Max snapshots per batch. Set with 867ec681f3Smrg * INTEL_MEASURE=batch_size={num}. Additional snapshots will be dropped. 877ec681f3Smrg */ 887ec681f3Smrg unsigned batch_size; 897ec681f3Smrg 907ec681f3Smrg /* Max number of batch measurements that can be buffered, for combining 917ec681f3Smrg * snapshots into frame or interval data. 927ec681f3Smrg */ 937ec681f3Smrg unsigned buffer_size; 947ec681f3Smrg 957ec681f3Smrg /* Fifo which will be read to enable measurements at run-time. Set with 967ec681f3Smrg * INTEL_MEASURE=control={path}. `echo {num} > {path}` will collect num 977ec681f3Smrg * frames of measurements, beginning with the next frame boundary. 987ec681f3Smrg */ 997ec681f3Smrg int control_fh; 1007ec681f3Smrg 1017ec681f3Smrg /* true when snapshots are currently being collected */ 1027ec681f3Smrg bool enabled; 1037ec681f3Smrg}; 1047ec681f3Smrg 1057ec681f3Smrgstruct intel_measure_batch; 1067ec681f3Smrg 1077ec681f3Smrgstruct intel_measure_snapshot { 1087ec681f3Smrg enum intel_measure_snapshot_type type; 1097ec681f3Smrg unsigned count, event_count; 1107ec681f3Smrg const char* event_name; 1117ec681f3Smrg uintptr_t framebuffer, vs, tcs, tes, gs, fs, cs; 1127ec681f3Smrg /* for vulkan secondary command buffers */ 1137ec681f3Smrg struct intel_measure_batch *secondary; 1147ec681f3Smrg}; 1157ec681f3Smrg 1167ec681f3Smrgstruct intel_measure_buffered_result { 1177ec681f3Smrg struct intel_measure_snapshot snapshot; 1187ec681f3Smrg uint64_t start_ts, end_ts, idle_duration; 1197ec681f3Smrg unsigned frame, batch_count, event_index; 1207ec681f3Smrg}; 1217ec681f3Smrg 1227ec681f3Smrgstruct intel_measure_ringbuffer { 1237ec681f3Smrg unsigned head, tail; 1247ec681f3Smrg struct intel_measure_buffered_result results[0]; 1257ec681f3Smrg}; 1267ec681f3Smrg 1277ec681f3Smrgstruct intel_measure_device { 1287ec681f3Smrg struct intel_measure_config *config; 1297ec681f3Smrg unsigned frame; 1307ec681f3Smrg 1317ec681f3Smrg /* Holds the list of (iris/anv)_measure_batch snapshots that have been 1327ec681f3Smrg * submitted for rendering, but have not completed. 1337ec681f3Smrg */ 1347ec681f3Smrg pthread_mutex_t mutex; 1357ec681f3Smrg struct list_head queued_snapshots; 1367ec681f3Smrg 1377ec681f3Smrg /* Holds completed snapshots that may need to be combined before being 1387ec681f3Smrg * written out 1397ec681f3Smrg */ 1407ec681f3Smrg struct intel_measure_ringbuffer *ringbuffer; 1417ec681f3Smrg}; 1427ec681f3Smrg 1437ec681f3Smrgstruct intel_measure_batch { 1447ec681f3Smrg struct list_head link; 1457ec681f3Smrg unsigned index; 1467ec681f3Smrg unsigned frame, batch_count, event_count; 1477ec681f3Smrg uintptr_t framebuffer; 1487ec681f3Smrg uint64_t *timestamps; 1497ec681f3Smrg struct intel_measure_snapshot snapshots[0]; 1507ec681f3Smrg}; 1517ec681f3Smrg 1527ec681f3Smrgvoid intel_measure_init(struct intel_measure_device *device); 1537ec681f3Smrgconst char * intel_measure_snapshot_string(enum intel_measure_snapshot_type type); 1547ec681f3Smrgbool intel_measure_state_changed(const struct intel_measure_batch *batch, 1557ec681f3Smrg uintptr_t vs, uintptr_t tcs, uintptr_t tes, 1567ec681f3Smrg uintptr_t gs, uintptr_t fs, uintptr_t cs); 1577ec681f3Smrgvoid intel_measure_frame_transition(unsigned frame); 1587ec681f3Smrg 1597ec681f3Smrgbool intel_measure_ready(struct intel_measure_batch *batch); 1607ec681f3Smrg 1617ec681f3Smrgstruct intel_device_info; 1627ec681f3Smrgvoid intel_measure_gather(struct intel_measure_device *device, 1637ec681f3Smrg struct intel_device_info *info); 1647ec681f3Smrg 1657ec681f3Smrg#endif /* INTEL_MEASURE_H */ 166