Path: blob/21.2-virgl/src/gallium/drivers/nouveau/nvc0/nvc0_query_sw.c
4574 views
/*1* Copyright 2011 Christoph Bumiller2* Copyright 2015 Samuel Pitoiset3*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 shall be included in12* all copies or substantial portions of the 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 OR18* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,19* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR20* OTHER DEALINGS IN THE SOFTWARE.21*/2223#include "nvc0/nvc0_context.h"2425#include "nvc0_query_sw.h"2627/* === DRIVER STATISTICS === */2829#ifdef NOUVEAU_ENABLE_DRIVER_STATISTICS3031static const char *nvc0_sw_query_drv_stat_names[] =32{33"drv-tex_obj_current_count",34"drv-tex_obj_current_bytes",35"drv-buf_obj_current_count",36"drv-buf_obj_current_bytes_vid",37"drv-buf_obj_current_bytes_sys",38"drv-tex_transfers_rd",39"drv-tex_transfers_wr",40"drv-tex_copy_count",41"drv-tex_blit_count",42"drv-tex_cache_flush_count",43"drv-buf_transfers_rd",44"drv-buf_transfers_wr",45"drv-buf_read_bytes_staging_vid",46"drv-buf_write_bytes_direct",47"drv-buf_write_bytes_staging_vid",48"drv-buf_write_bytes_staging_sys",49"drv-buf_copy_bytes",50"drv-buf_non_kernel_fence_sync_count",51"drv-any_non_kernel_fence_sync_count",52"drv-query_sync_count",53"drv-gpu_serialize_count",54"drv-draw_calls_array",55"drv-draw_calls_indexed",56"drv-draw_calls_fallback_count",57"drv-user_buffer_upload_bytes",58"drv-constbuf_upload_count",59"drv-constbuf_upload_bytes",60"drv-pushbuf_count",61"drv-resource_validate_count"62};6364#endif /* NOUVEAU_ENABLE_DRIVER_STATISTICS */6566static void67nvc0_sw_destroy_query(struct nvc0_context *nvc0, struct nvc0_query *q)68{69struct nvc0_sw_query *sq = nvc0_sw_query(q);70FREE(sq);71}7273static bool74nvc0_sw_begin_query(struct nvc0_context *nvc0, struct nvc0_query *q)75{76#ifdef NOUVEAU_ENABLE_DRIVER_STATISTICS77struct nvc0_sw_query *sq = nvc0_sw_query(q);7879if (q->index >= 5) {80sq->value = nvc0->screen->base.stats.v[q->index];81} else {82sq->value = 0;83}84#endif85return true;86}8788static void89nvc0_sw_end_query(struct nvc0_context *nvc0, struct nvc0_query *q)90{91#ifdef NOUVEAU_ENABLE_DRIVER_STATISTICS92struct nvc0_sw_query *sq = nvc0_sw_query(q);93sq->value = nvc0->screen->base.stats.v[q->index] - sq->value;94#endif95}9697static bool98nvc0_sw_get_query_result(struct nvc0_context *nvc0, struct nvc0_query *q,99bool wait, union pipe_query_result *result)100{101#ifdef NOUVEAU_ENABLE_DRIVER_STATISTICS102struct nvc0_sw_query *sq = nvc0_sw_query(q);103uint64_t *res64 = (uint64_t *)result;104105res64[0] = sq->value;106#endif107return true;108}109110static const struct nvc0_query_funcs sw_query_funcs = {111.destroy_query = nvc0_sw_destroy_query,112.begin_query = nvc0_sw_begin_query,113.end_query = nvc0_sw_end_query,114.get_query_result = nvc0_sw_get_query_result,115};116117struct nvc0_query *118nvc0_sw_create_query(struct nvc0_context *nvcO, unsigned type, unsigned index)119{120struct nvc0_sw_query *sq;121struct nvc0_query *q;122123if (type < NVC0_SW_QUERY_DRV_STAT(0) || type > NVC0_SW_QUERY_DRV_STAT_LAST)124return NULL;125126sq = CALLOC_STRUCT(nvc0_sw_query);127if (!sq)128return NULL;129130q = &sq->base;131q->funcs = &sw_query_funcs;132q->type = type;133q->index = type - NVC0_SW_QUERY_DRV_STAT(0);134135return q;136}137138int139nvc0_sw_get_driver_query_info(struct nvc0_screen *screen, unsigned id,140struct pipe_driver_query_info *info)141{142int count = 0;143144count += NVC0_SW_QUERY_DRV_STAT_COUNT;145if (!info)146return count;147148#ifdef NOUVEAU_ENABLE_DRIVER_STATISTICS149if (id < count) {150info->name = nvc0_sw_query_drv_stat_names[id];151info->query_type = NVC0_SW_QUERY_DRV_STAT(id);152info->type = PIPE_DRIVER_QUERY_TYPE_UINT64;153info->max_value.u64 = 0;154if (strstr(info->name, "bytes"))155info->type = PIPE_DRIVER_QUERY_TYPE_BYTES;156info->group_id = NVC0_SW_QUERY_DRV_STAT_GROUP;157return 1;158}159#endif160return 0;161}162163164