Path: blob/21.2-virgl/src/gallium/drivers/radeonsi/si_query.h
4570 views
/*1* Copyright 2015 Advanced Micro Devices, Inc.2* All Rights Reserved.3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the "Software"),6* to deal in the Software without restriction, including without limitation7* the rights to use, copy, modify, merge, publish, distribute, sublicense,8* and/or sell copies of the Software, and to permit persons to whom the9* Software is furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice (including the next12* paragraph) shall be included in all copies or substantial portions of the13* Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL18* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,20* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE21* SOFTWARE.22*/2324#ifndef SI_QUERY_H25#define SI_QUERY_H2627#include "util/u_threaded_context.h"2829#include "ac_perfcounter.h"3031struct pipe_context;32struct pipe_query;33struct pipe_resource;3435struct si_screen;36struct si_context;37struct si_query;38struct si_query_buffer;39struct si_query_hw;40struct si_resource;4142#define SI_MAX_STREAMS 44344enum45{46SI_QUERY_DRAW_CALLS = PIPE_QUERY_DRIVER_SPECIFIC,47SI_QUERY_DECOMPRESS_CALLS,48SI_QUERY_PRIM_RESTART_CALLS,49SI_QUERY_COMPUTE_CALLS,50SI_QUERY_CP_DMA_CALLS,51SI_QUERY_NUM_VS_FLUSHES,52SI_QUERY_NUM_PS_FLUSHES,53SI_QUERY_NUM_CS_FLUSHES,54SI_QUERY_NUM_CB_CACHE_FLUSHES,55SI_QUERY_NUM_DB_CACHE_FLUSHES,56SI_QUERY_NUM_L2_INVALIDATES,57SI_QUERY_NUM_L2_WRITEBACKS,58SI_QUERY_NUM_RESIDENT_HANDLES,59SI_QUERY_TC_OFFLOADED_SLOTS,60SI_QUERY_TC_DIRECT_SLOTS,61SI_QUERY_TC_NUM_SYNCS,62SI_QUERY_CS_THREAD_BUSY,63SI_QUERY_GALLIUM_THREAD_BUSY,64SI_QUERY_REQUESTED_VRAM,65SI_QUERY_REQUESTED_GTT,66SI_QUERY_MAPPED_VRAM,67SI_QUERY_MAPPED_GTT,68SI_QUERY_SLAB_WASTED_VRAM,69SI_QUERY_SLAB_WASTED_GTT,70SI_QUERY_BUFFER_WAIT_TIME,71SI_QUERY_NUM_MAPPED_BUFFERS,72SI_QUERY_NUM_GFX_IBS,73SI_QUERY_GFX_BO_LIST_SIZE,74SI_QUERY_GFX_IB_SIZE,75SI_QUERY_NUM_BYTES_MOVED,76SI_QUERY_NUM_EVICTIONS,77SI_QUERY_NUM_VRAM_CPU_PAGE_FAULTS,78SI_QUERY_VRAM_USAGE,79SI_QUERY_VRAM_VIS_USAGE,80SI_QUERY_GTT_USAGE,81SI_QUERY_GPU_TEMPERATURE,82SI_QUERY_CURRENT_GPU_SCLK,83SI_QUERY_CURRENT_GPU_MCLK,84SI_QUERY_GPU_LOAD,85SI_QUERY_GPU_SHADERS_BUSY,86SI_QUERY_GPU_TA_BUSY,87SI_QUERY_GPU_GDS_BUSY,88SI_QUERY_GPU_VGT_BUSY,89SI_QUERY_GPU_IA_BUSY,90SI_QUERY_GPU_SX_BUSY,91SI_QUERY_GPU_WD_BUSY,92SI_QUERY_GPU_BCI_BUSY,93SI_QUERY_GPU_SC_BUSY,94SI_QUERY_GPU_PA_BUSY,95SI_QUERY_GPU_DB_BUSY,96SI_QUERY_GPU_CP_BUSY,97SI_QUERY_GPU_CB_BUSY,98SI_QUERY_GPU_SDMA_BUSY,99SI_QUERY_GPU_PFP_BUSY,100SI_QUERY_GPU_MEQ_BUSY,101SI_QUERY_GPU_ME_BUSY,102SI_QUERY_GPU_SURF_SYNC_BUSY,103SI_QUERY_GPU_CP_DMA_BUSY,104SI_QUERY_GPU_SCRATCH_RAM_BUSY,105SI_QUERY_NUM_COMPILATIONS,106SI_QUERY_NUM_SHADERS_CREATED,107SI_QUERY_BACK_BUFFER_PS_DRAW_RATIO,108SI_QUERY_GPIN_ASIC_ID,109SI_QUERY_GPIN_NUM_SIMD,110SI_QUERY_GPIN_NUM_RB,111SI_QUERY_GPIN_NUM_SPI,112SI_QUERY_GPIN_NUM_SE,113SI_QUERY_PD_NUM_PRIMS_ACCEPTED,114SI_QUERY_PD_NUM_PRIMS_REJECTED,115SI_QUERY_PD_NUM_PRIMS_INELIGIBLE,116SI_QUERY_LIVE_SHADER_CACHE_HITS,117SI_QUERY_LIVE_SHADER_CACHE_MISSES,118SI_QUERY_MEMORY_SHADER_CACHE_HITS,119SI_QUERY_MEMORY_SHADER_CACHE_MISSES,120SI_QUERY_DISK_SHADER_CACHE_HITS,121SI_QUERY_DISK_SHADER_CACHE_MISSES,122123SI_QUERY_FIRST_PERFCOUNTER = PIPE_QUERY_DRIVER_SPECIFIC + 100,124};125126enum127{128SI_QUERY_GROUP_GPIN = 0,129SI_NUM_SW_QUERY_GROUPS130};131132struct si_query_ops {133void (*destroy)(struct si_context *, struct si_query *);134bool (*begin)(struct si_context *, struct si_query *);135bool (*end)(struct si_context *, struct si_query *);136bool (*get_result)(struct si_context *, struct si_query *, bool wait,137union pipe_query_result *result);138void (*get_result_resource)(struct si_context *, struct si_query *, bool wait,139enum pipe_query_value_type result_type, int index,140struct pipe_resource *resource, unsigned offset);141142void (*suspend)(struct si_context *, struct si_query *);143void (*resume)(struct si_context *, struct si_query *);144};145146struct si_query {147struct threaded_query b;148const struct si_query_ops *ops;149150/* The PIPE_QUERY_xxx type of query */151unsigned type;152153/* The number of dwords for suspend. */154unsigned num_cs_dw_suspend;155156/* Linked list of queries that must be suspended at end of CS. */157struct list_head active_list;158};159160enum161{162SI_QUERY_HW_FLAG_NO_START = (1 << 0),163/* gap */164/* whether begin_query doesn't clear the result */165SI_QUERY_HW_FLAG_BEGIN_RESUMES = (1 << 2),166};167168struct si_query_hw_ops {169bool (*prepare_buffer)(struct si_context *, struct si_query_buffer *);170void (*emit_start)(struct si_context *, struct si_query_hw *, struct si_resource *buffer,171uint64_t va);172void (*emit_stop)(struct si_context *, struct si_query_hw *, struct si_resource *buffer,173uint64_t va);174void (*clear_result)(struct si_query_hw *, union pipe_query_result *);175void (*add_result)(struct si_screen *screen, struct si_query_hw *, void *buffer,176union pipe_query_result *result);177};178179struct si_query_buffer {180/* The buffer where query results are stored. */181struct si_resource *buf;182/* If a query buffer is full, a new buffer is created and the old one183* is put in here. When we calculate the result, we sum up the samples184* from all buffers. */185struct si_query_buffer *previous;186/* Offset of the next free result after current query data */187unsigned results_end;188bool unprepared;189};190191void si_query_buffer_destroy(struct si_screen *sctx, struct si_query_buffer *buffer);192void si_query_buffer_reset(struct si_context *sctx, struct si_query_buffer *buffer);193bool si_query_buffer_alloc(struct si_context *sctx, struct si_query_buffer *buffer,194bool (*prepare_buffer)(struct si_context *, struct si_query_buffer *),195unsigned size);196197struct si_query_hw {198struct si_query b;199struct si_query_hw_ops *ops;200unsigned flags;201202/* The query buffer and how many results are in it. */203struct si_query_buffer buffer;204/* Size of the result in memory for both begin_query and end_query,205* this can be one or two numbers, or it could even be a size of a structure. */206unsigned result_size;207/* For transform feedback: which stream the query is for */208unsigned stream;209210/* Workaround via compute shader */211struct si_resource *workaround_buf;212unsigned workaround_offset;213};214215void si_query_hw_destroy(struct si_context *sctx, struct si_query *squery);216bool si_query_hw_begin(struct si_context *sctx, struct si_query *squery);217bool si_query_hw_end(struct si_context *sctx, struct si_query *squery);218bool si_query_hw_get_result(struct si_context *sctx, struct si_query *squery, bool wait,219union pipe_query_result *result);220void si_query_hw_suspend(struct si_context *sctx, struct si_query *query);221void si_query_hw_resume(struct si_context *sctx, struct si_query *query);222223/* Shader-based queries */224225/**226* The query buffer is written to by ESGS NGG shaders with statistics about227* generated and (streamout-)emitted primitives.228*229* The context maintains a ring of these query buffers, and queries simply230* point into the ring, allowing an arbitrary number of queries to be active231* without additional GPU cost.232*/233struct gfx10_sh_query_buffer {234struct list_head list;235struct si_resource *buf;236unsigned refcount;237238/* Offset into the buffer in bytes; points at the first un-emitted entry. */239unsigned head;240};241242/* Memory layout of the query buffer. Must be kept in sync with shaders243* (including QBO shaders) and should be aligned to cachelines.244*245* The somewhat awkward memory layout is for compatibility with the246* SET_PREDICATION packet, which also means that we're setting the high bit247* of all those values unconditionally.248*/249struct gfx10_sh_query_buffer_mem {250struct {251uint64_t generated_primitives_start_dummy;252uint64_t emitted_primitives_start_dummy;253uint64_t generated_primitives;254uint64_t emitted_primitives;255} stream[4];256uint32_t fence; /* bottom-of-pipe fence: set to ~0 when draws have finished */257uint32_t pad[31];258};259260struct gfx10_sh_query {261struct si_query b;262263struct gfx10_sh_query_buffer *first;264struct gfx10_sh_query_buffer *last;265unsigned first_begin;266unsigned last_end;267268unsigned stream;269};270271struct pipe_query *gfx10_sh_query_create(struct si_screen *screen, enum pipe_query_type query_type,272unsigned index);273274/* Performance counters */275struct si_perfcounters {276struct ac_perfcounters base;277278unsigned num_stop_cs_dwords;279unsigned num_instance_cs_dwords;280};281282struct pipe_query *si_create_batch_query(struct pipe_context *ctx, unsigned num_queries,283unsigned *query_types);284285int si_get_perfcounter_info(struct si_screen *, unsigned index,286struct pipe_driver_query_info *info);287int si_get_perfcounter_group_info(struct si_screen *, unsigned index,288struct pipe_driver_query_group_info *info);289290struct si_qbo_state {291struct pipe_constant_buffer saved_const0;292};293294#endif /* SI_QUERY_H */295296297