Path: blob/21.2-virgl/src/intel/common/intel_measure.h
4547 views
/*1* Copyright © 2020 Intel Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* on the rights to use, copy, modify, merge, publish, distribute, sub7* license, and/or sell copies of the Software, and to permit persons to whom8* the Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL17* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,18* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR19* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE20* USE OR OTHER DEALINGS IN THE SOFTWARE.21*/2223#ifndef INTEL_MEASURE_H24#define INTEL_MEASURE_H2526#include <pthread.h>27#include <stdio.h>28#include <stdbool.h>29#include <stdint.h>3031#include "util/list.h"3233enum intel_measure_snapshot_type {34INTEL_SNAPSHOT_UNDEFINED,35INTEL_SNAPSHOT_BLIT,36INTEL_SNAPSHOT_CCS_AMBIGUATE,37INTEL_SNAPSHOT_CCS_COLOR_CLEAR,38INTEL_SNAPSHOT_CCS_PARTIAL_RESOLVE,39INTEL_SNAPSHOT_CCS_RESOLVE,40INTEL_SNAPSHOT_COMPUTE,41INTEL_SNAPSHOT_COPY,42INTEL_SNAPSHOT_DRAW,43INTEL_SNAPSHOT_HIZ_AMBIGUATE,44INTEL_SNAPSHOT_HIZ_CLEAR,45INTEL_SNAPSHOT_HIZ_RESOLVE,46INTEL_SNAPSHOT_MCS_COLOR_CLEAR,47INTEL_SNAPSHOT_MCS_PARTIAL_RESOLVE,48INTEL_SNAPSHOT_SLOW_COLOR_CLEAR,49INTEL_SNAPSHOT_SLOW_DEPTH_CLEAR,50INTEL_SNAPSHOT_SECONDARY_BATCH,51INTEL_SNAPSHOT_END,52};5354enum intel_measure_events {55INTEL_MEASURE_DRAW = (1 << 0),56INTEL_MEASURE_RENDERPASS = (1 << 1),57INTEL_MEASURE_SHADER = (1 << 2),58INTEL_MEASURE_BATCH = (1 << 3),59INTEL_MEASURE_FRAME = (1 << 4),60};6162struct intel_measure_config {6364/* Stderr, or optionally set with INTEL_MEASURE=file={path{ */65FILE *file;6667/* Events that will be measured. Set only one flag, with68* INTEL_MEASURE=[draw,rt,shader,batch,frame] */69enum intel_measure_events flags;7071/* Optionally set with INTEL_MEASURE=start={num} */72unsigned start_frame;7374/* Optionally calculated with INTEL_MEASURE=count={num} based on75* start_frame76*/77unsigned end_frame;7879/* Number of events to combine per line of output. Optionally set with80* INTEL_MEASURE=interval={num}81*/82unsigned event_interval;8384/* Max snapshots per batch. Set with85* INTEL_MEASURE=batch_size={num}. Additional snapshots will be dropped.86*/87unsigned batch_size;8889/* Max number of batch measurements that can be buffered, for combining90* snapshots into frame or interval data.91*/92unsigned buffer_size;9394/* Fifo which will be read to enable measurements at run-time. Set with95* INTEL_MEASURE=control={path}. `echo {num} > {path}` will collect num96* frames of measurements, beginning with the next frame boundary.97*/98int control_fh;99100/* true when snapshots are currently being collected */101bool enabled;102};103104struct intel_measure_batch;105106struct intel_measure_snapshot {107enum intel_measure_snapshot_type type;108unsigned count, event_count;109const char* event_name;110uintptr_t framebuffer, vs, tcs, tes, gs, fs, cs;111/* for vulkan secondary command buffers */112struct intel_measure_batch *secondary;113};114115struct intel_measure_buffered_result {116struct intel_measure_snapshot snapshot;117uint64_t start_ts, end_ts, idle_duration;118unsigned frame, batch_count, event_index;119};120121struct intel_measure_ringbuffer {122unsigned head, tail;123struct intel_measure_buffered_result results[0];124};125126struct intel_measure_device {127struct intel_measure_config *config;128unsigned frame;129130/* Holds the list of (iris/anv)_measure_batch snapshots that have been131* submitted for rendering, but have not completed.132*/133pthread_mutex_t mutex;134struct list_head queued_snapshots;135136/* Holds completed snapshots that may need to be combined before being137* written out138*/139struct intel_measure_ringbuffer *ringbuffer;140};141142struct intel_measure_batch {143struct list_head link;144unsigned index;145unsigned frame, batch_count, event_count;146uintptr_t framebuffer;147uint64_t *timestamps;148struct intel_measure_snapshot snapshots[0];149};150151void intel_measure_init(struct intel_measure_device *device);152const char * intel_measure_snapshot_string(enum intel_measure_snapshot_type type);153bool intel_measure_state_changed(const struct intel_measure_batch *batch,154uintptr_t vs, uintptr_t tcs, uintptr_t tes,155uintptr_t gs, uintptr_t fs, uintptr_t cs);156void intel_measure_frame_transition(unsigned frame);157158bool intel_measure_ready(struct intel_measure_batch *batch);159160struct intel_device_info;161void intel_measure_gather(struct intel_measure_device *device,162struct intel_device_info *info);163164#endif /* INTEL_MEASURE_H */165166167