Path: blob/21.2-virgl/src/gallium/drivers/r600/r600_query.h
4570 views
/*1* Copyright 2015 Advanced Micro Devices, Inc.2*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* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* 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 NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,19* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE20* SOFTWARE.21*22* Authors:23* Nicolai Hähnle <[email protected]>24*25*/2627#ifndef R600_QUERY_H28#define R600_QUERY_H2930#include "util/u_threaded_context.h"3132struct pipe_context;33struct pipe_query;34struct pipe_resource;3536struct r600_common_context;37struct r600_common_screen;38struct r600_query;39struct r600_query_hw;40struct r600_resource;4142enum {43R600_QUERY_DRAW_CALLS = PIPE_QUERY_DRIVER_SPECIFIC,44R600_QUERY_DECOMPRESS_CALLS,45R600_QUERY_MRT_DRAW_CALLS,46R600_QUERY_PRIM_RESTART_CALLS,47R600_QUERY_SPILL_DRAW_CALLS,48R600_QUERY_COMPUTE_CALLS,49R600_QUERY_SPILL_COMPUTE_CALLS,50R600_QUERY_DMA_CALLS,51R600_QUERY_CP_DMA_CALLS,52R600_QUERY_NUM_VS_FLUSHES,53R600_QUERY_NUM_PS_FLUSHES,54R600_QUERY_NUM_CS_FLUSHES,55R600_QUERY_NUM_CB_CACHE_FLUSHES,56R600_QUERY_NUM_DB_CACHE_FLUSHES,57R600_QUERY_NUM_RESIDENT_HANDLES,58R600_QUERY_TC_OFFLOADED_SLOTS,59R600_QUERY_TC_DIRECT_SLOTS,60R600_QUERY_TC_NUM_SYNCS,61R600_QUERY_CS_THREAD_BUSY,62R600_QUERY_GALLIUM_THREAD_BUSY,63R600_QUERY_REQUESTED_VRAM,64R600_QUERY_REQUESTED_GTT,65R600_QUERY_MAPPED_VRAM,66R600_QUERY_MAPPED_GTT,67R600_QUERY_BUFFER_WAIT_TIME,68R600_QUERY_NUM_MAPPED_BUFFERS,69R600_QUERY_NUM_GFX_IBS,70R600_QUERY_NUM_SDMA_IBS,71R600_QUERY_GFX_BO_LIST_SIZE,72R600_QUERY_NUM_BYTES_MOVED,73R600_QUERY_NUM_EVICTIONS,74R600_QUERY_NUM_VRAM_CPU_PAGE_FAULTS,75R600_QUERY_VRAM_USAGE,76R600_QUERY_VRAM_VIS_USAGE,77R600_QUERY_GTT_USAGE,78R600_QUERY_GPU_TEMPERATURE,79R600_QUERY_CURRENT_GPU_SCLK,80R600_QUERY_CURRENT_GPU_MCLK,81R600_QUERY_GPU_LOAD,82R600_QUERY_GPU_SHADERS_BUSY,83R600_QUERY_GPU_TA_BUSY,84R600_QUERY_GPU_GDS_BUSY,85R600_QUERY_GPU_VGT_BUSY,86R600_QUERY_GPU_IA_BUSY,87R600_QUERY_GPU_SX_BUSY,88R600_QUERY_GPU_WD_BUSY,89R600_QUERY_GPU_BCI_BUSY,90R600_QUERY_GPU_SC_BUSY,91R600_QUERY_GPU_PA_BUSY,92R600_QUERY_GPU_DB_BUSY,93R600_QUERY_GPU_CP_BUSY,94R600_QUERY_GPU_CB_BUSY,95R600_QUERY_GPU_SDMA_BUSY,96R600_QUERY_GPU_PFP_BUSY,97R600_QUERY_GPU_MEQ_BUSY,98R600_QUERY_GPU_ME_BUSY,99R600_QUERY_GPU_SURF_SYNC_BUSY,100R600_QUERY_GPU_CP_DMA_BUSY,101R600_QUERY_GPU_SCRATCH_RAM_BUSY,102R600_QUERY_NUM_COMPILATIONS,103R600_QUERY_NUM_SHADERS_CREATED,104R600_QUERY_NUM_SHADER_CACHE_HITS,105R600_QUERY_GPIN_ASIC_ID,106R600_QUERY_GPIN_NUM_SIMD,107R600_QUERY_GPIN_NUM_RB,108R600_QUERY_GPIN_NUM_SPI,109R600_QUERY_GPIN_NUM_SE,110111R600_QUERY_FIRST_PERFCOUNTER = PIPE_QUERY_DRIVER_SPECIFIC + 100,112};113114enum {115R600_QUERY_GROUP_GPIN = 0,116R600_NUM_SW_QUERY_GROUPS117};118119struct r600_query_ops {120void (*destroy)(struct r600_common_screen *, struct r600_query *);121bool (*begin)(struct r600_common_context *, struct r600_query *);122bool (*end)(struct r600_common_context *, struct r600_query *);123bool (*get_result)(struct r600_common_context *,124struct r600_query *, bool wait,125union pipe_query_result *result);126void (*get_result_resource)(struct r600_common_context *,127struct r600_query *, bool wait,128enum pipe_query_value_type result_type,129int index,130struct pipe_resource *resource,131unsigned offset);132};133134struct r600_query {135struct threaded_query b;136struct r600_query_ops *ops;137138/* The type of query */139unsigned type;140};141142enum {143R600_QUERY_HW_FLAG_NO_START = (1 << 0),144/* gap */145/* whether begin_query doesn't clear the result */146R600_QUERY_HW_FLAG_BEGIN_RESUMES = (1 << 2),147};148149struct r600_query_hw_ops {150bool (*prepare_buffer)(struct r600_common_screen *,151struct r600_query_hw *,152struct r600_resource *);153void (*emit_start)(struct r600_common_context *,154struct r600_query_hw *,155struct r600_resource *buffer, uint64_t va);156void (*emit_stop)(struct r600_common_context *,157struct r600_query_hw *,158struct r600_resource *buffer, uint64_t va);159void (*clear_result)(struct r600_query_hw *, union pipe_query_result *);160void (*add_result)(struct r600_common_screen *screen,161struct r600_query_hw *, void *buffer,162union pipe_query_result *result);163};164165struct r600_query_buffer {166/* The buffer where query results are stored. */167struct r600_resource *buf;168/* Offset of the next free result after current query data */169unsigned results_end;170/* If a query buffer is full, a new buffer is created and the old one171* is put in here. When we calculate the result, we sum up the samples172* from all buffers. */173struct r600_query_buffer *previous;174};175176struct r600_query_hw {177struct r600_query b;178struct r600_query_hw_ops *ops;179unsigned flags;180181/* The query buffer and how many results are in it. */182struct r600_query_buffer buffer;183/* Size of the result in memory for both begin_query and end_query,184* this can be one or two numbers, or it could even be a size of a structure. */185unsigned result_size;186/* The number of dwords for begin_query or end_query. */187unsigned num_cs_dw_begin;188unsigned num_cs_dw_end;189/* Linked list of queries */190struct list_head list;191/* For transform feedback: which stream the query is for */192unsigned stream;193};194195bool r600_query_hw_init(struct r600_common_screen *rscreen,196struct r600_query_hw *query);197void r600_query_hw_destroy(struct r600_common_screen *rscreen,198struct r600_query *rquery);199bool r600_query_hw_begin(struct r600_common_context *rctx,200struct r600_query *rquery);201bool r600_query_hw_end(struct r600_common_context *rctx,202struct r600_query *rquery);203bool r600_query_hw_get_result(struct r600_common_context *rctx,204struct r600_query *rquery,205bool wait,206union pipe_query_result *result);207208/* Performance counters */209enum {210/* This block is part of the shader engine */211R600_PC_BLOCK_SE = (1 << 0),212213/* Expose per-instance groups instead of summing all instances (within214* an SE). */215R600_PC_BLOCK_INSTANCE_GROUPS = (1 << 1),216217/* Expose per-SE groups instead of summing instances across SEs. */218R600_PC_BLOCK_SE_GROUPS = (1 << 2),219220/* Shader block */221R600_PC_BLOCK_SHADER = (1 << 3),222223/* Non-shader block with perfcounters windowed by shaders. */224R600_PC_BLOCK_SHADER_WINDOWED = (1 << 4),225};226227/* Describes a hardware block with performance counters. Multiple instances of228* each block, possibly per-SE, may exist on the chip. Depending on the block229* and on the user's configuration, we either230* (a) expose every instance as a performance counter group,231* (b) expose a single performance counter group that reports the sum over all232* instances, or233* (c) expose one performance counter group per instance, but summed over all234* shader engines.235*/236struct r600_perfcounter_block {237const char *basename;238unsigned flags;239unsigned num_counters;240unsigned num_selectors;241unsigned num_instances;242243unsigned num_groups;244char *group_names;245unsigned group_name_stride;246247char *selector_names;248unsigned selector_name_stride;249250void *data;251};252253struct r600_perfcounters {254unsigned num_groups;255unsigned num_blocks;256struct r600_perfcounter_block *blocks;257258unsigned num_start_cs_dwords;259unsigned num_stop_cs_dwords;260unsigned num_instance_cs_dwords;261unsigned num_shaders_cs_dwords;262263unsigned num_shader_types;264const char * const *shader_type_suffixes;265const unsigned *shader_type_bits;266267void (*get_size)(struct r600_perfcounter_block *,268unsigned count, unsigned *selectors,269unsigned *num_select_dw, unsigned *num_read_dw);270271void (*emit_instance)(struct r600_common_context *,272int se, int instance);273void (*emit_shaders)(struct r600_common_context *, unsigned shaders);274void (*emit_select)(struct r600_common_context *,275struct r600_perfcounter_block *,276unsigned count, unsigned *selectors);277void (*emit_start)(struct r600_common_context *,278struct r600_resource *buffer, uint64_t va);279void (*emit_stop)(struct r600_common_context *,280struct r600_resource *buffer, uint64_t va);281void (*emit_read)(struct r600_common_context *,282struct r600_perfcounter_block *,283unsigned count, unsigned *selectors,284struct r600_resource *buffer, uint64_t va);285286void (*cleanup)(struct r600_common_screen *);287288bool separate_se;289bool separate_instance;290};291292struct pipe_query *r600_create_batch_query(struct pipe_context *ctx,293unsigned num_queries,294unsigned *query_types);295296int r600_get_perfcounter_info(struct r600_common_screen *,297unsigned index,298struct pipe_driver_query_info *info);299int r600_get_perfcounter_group_info(struct r600_common_screen *,300unsigned index,301struct pipe_driver_query_group_info *info);302303bool r600_perfcounters_init(struct r600_perfcounters *, unsigned num_blocks);304void r600_perfcounters_add_block(struct r600_common_screen *,305struct r600_perfcounters *,306const char *name, unsigned flags,307unsigned counters, unsigned selectors,308unsigned instances, void *data);309void r600_perfcounters_do_destroy(struct r600_perfcounters *);310void r600_query_hw_reset_buffers(struct r600_common_context *rctx,311struct r600_query_hw *query);312313struct r600_qbo_state {314void *saved_compute;315struct pipe_constant_buffer saved_const0;316struct pipe_shader_buffer saved_ssbo[3];317};318319#endif /* R600_QUERY_H */320321322