Path: blob/21.2-virgl/src/gallium/drivers/nouveau/nvc0/nvc0_query.c
4574 views
/*1* Copyright 2011 Nouveau Project2*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 shall be included in11* all copies or substantial portions of the Software.12*13* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL16* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR17* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,18* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR19* OTHER DEALINGS IN THE SOFTWARE.20*21* Authors: Christoph Bumiller22*/2324#define NVC0_PUSH_EXPLICIT_SPACE_CHECKING2526#include "nvc0/nvc0_context.h"27#include "nvc0/nvc0_query.h"28#include "nvc0/nvc0_query_sw.h"29#include "nvc0/nvc0_query_hw.h"30#include "nvc0/nvc0_query_hw_metric.h"31#include "nvc0/nvc0_query_hw_sm.h"3233static struct pipe_query *34nvc0_create_query(struct pipe_context *pipe, unsigned type, unsigned index)35{36struct nvc0_context *nvc0 = nvc0_context(pipe);37struct nvc0_query *q;3839q = nvc0_sw_create_query(nvc0, type, index);40if (!q)41q = nvc0_hw_create_query(nvc0, type, index);4243return (struct pipe_query *)q;44}4546static void47nvc0_destroy_query(struct pipe_context *pipe, struct pipe_query *pq)48{49struct nvc0_query *q = nvc0_query(pq);50q->funcs->destroy_query(nvc0_context(pipe), q);51}5253static bool54nvc0_begin_query(struct pipe_context *pipe, struct pipe_query *pq)55{56struct nvc0_query *q = nvc0_query(pq);57return q->funcs->begin_query(nvc0_context(pipe), q);58}5960static bool61nvc0_end_query(struct pipe_context *pipe, struct pipe_query *pq)62{63struct nvc0_query *q = nvc0_query(pq);64q->funcs->end_query(nvc0_context(pipe), q);65return true;66}6768static bool69nvc0_get_query_result(struct pipe_context *pipe, struct pipe_query *pq,70bool wait, union pipe_query_result *result)71{72struct nvc0_query *q = nvc0_query(pq);73return q->funcs->get_query_result(nvc0_context(pipe), q, wait, result);74}7576static void77nvc0_get_query_result_resource(struct pipe_context *pipe,78struct pipe_query *pq,79bool wait,80enum pipe_query_value_type result_type,81int index,82struct pipe_resource *resource,83unsigned offset)84{85struct nvc0_query *q = nvc0_query(pq);86if (!q->funcs->get_query_result_resource) {87assert(!"Unexpected lack of get_query_result_resource");88return;89}90q->funcs->get_query_result_resource(nvc0_context(pipe), q, wait, result_type,91index, resource, offset);92}9394static void95nvc0_render_condition(struct pipe_context *pipe,96struct pipe_query *pq,97bool condition, enum pipe_render_cond_flag mode)98{99struct nvc0_context *nvc0 = nvc0_context(pipe);100struct nouveau_pushbuf *push = nvc0->base.pushbuf;101struct nvc0_query *q = nvc0_query(pq);102struct nvc0_hw_query *hq = nvc0_hw_query(q);103uint32_t cond;104bool wait =105mode != PIPE_RENDER_COND_NO_WAIT &&106mode != PIPE_RENDER_COND_BY_REGION_NO_WAIT;107108if (!pq) {109cond = NVC0_3D_COND_MODE_ALWAYS;110}111else {112/* NOTE: comparison of 2 queries only works if both have completed */113switch (q->type) {114case PIPE_QUERY_SO_OVERFLOW_PREDICATE:115case PIPE_QUERY_SO_OVERFLOW_ANY_PREDICATE:116cond = condition ? NVC0_3D_COND_MODE_EQUAL :117NVC0_3D_COND_MODE_NOT_EQUAL;118wait = true;119break;120case PIPE_QUERY_OCCLUSION_COUNTER:121case PIPE_QUERY_OCCLUSION_PREDICATE:122case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE:123if (hq->state == NVC0_HW_QUERY_STATE_READY)124wait = true;125if (likely(!condition)) {126cond = wait ? NVC0_3D_COND_MODE_NOT_EQUAL : NVC0_3D_COND_MODE_ALWAYS;127} else {128cond = wait ? NVC0_3D_COND_MODE_EQUAL : NVC0_3D_COND_MODE_ALWAYS;129}130break;131default:132assert(!"render condition query not a predicate");133cond = NVC0_3D_COND_MODE_ALWAYS;134break;135}136}137138nvc0->cond_query = pq;139nvc0->cond_cond = condition;140nvc0->cond_condmode = cond;141nvc0->cond_mode = mode;142143if (!pq) {144PUSH_SPACE(push, 2);145IMMED_NVC0(push, NVC0_3D(COND_MODE), cond);146if (nvc0->screen->compute)147IMMED_NVC0(push, NVC0_CP(COND_MODE), cond);148return;149}150151if (wait && hq->state != NVC0_HW_QUERY_STATE_READY)152nvc0_hw_query_fifo_wait(nvc0, q);153154PUSH_SPACE(push, 10);155PUSH_REFN (push, hq->bo, NOUVEAU_BO_GART | NOUVEAU_BO_RD);156BEGIN_NVC0(push, NVC0_3D(COND_ADDRESS_HIGH), 3);157PUSH_DATAh(push, hq->bo->offset + hq->offset);158PUSH_DATA (push, hq->bo->offset + hq->offset);159PUSH_DATA (push, cond);160BEGIN_NVC0(push, NVC0_2D(COND_ADDRESS_HIGH), 2);161PUSH_DATAh(push, hq->bo->offset + hq->offset);162PUSH_DATA (push, hq->bo->offset + hq->offset);163if (nvc0->screen->compute) {164BEGIN_NVC0(push, NVC0_CP(COND_ADDRESS_HIGH), 3);165PUSH_DATAh(push, hq->bo->offset + hq->offset);166PUSH_DATA (push, hq->bo->offset + hq->offset);167PUSH_DATA (push, cond);168}169}170171int172nvc0_screen_get_driver_query_info(struct pipe_screen *pscreen,173unsigned id,174struct pipe_driver_query_info *info)175{176struct nvc0_screen *screen = nvc0_screen(pscreen);177int num_sw_queries = 0, num_hw_queries = 0;178179num_sw_queries = nvc0_sw_get_driver_query_info(screen, 0, NULL);180num_hw_queries = nvc0_hw_get_driver_query_info(screen, 0, NULL);181182if (!info)183return num_sw_queries + num_hw_queries;184185/* Init default values. */186info->name = "this_is_not_the_query_you_are_looking_for";187info->query_type = 0xdeadd01d;188info->max_value.u64 = 0;189info->type = PIPE_DRIVER_QUERY_TYPE_UINT64;190info->group_id = -1;191info->flags = 0;192193#ifdef NOUVEAU_ENABLE_DRIVER_STATISTICS194if (id < num_sw_queries)195return nvc0_sw_get_driver_query_info(screen, id, info);196#endif197198return nvc0_hw_get_driver_query_info(screen, id - num_sw_queries, info);199}200201int202nvc0_screen_get_driver_query_group_info(struct pipe_screen *pscreen,203unsigned id,204struct pipe_driver_query_group_info *info)205{206struct nvc0_screen *screen = nvc0_screen(pscreen);207int count = 0;208int map[3] = {};209210if (screen->base.drm->version >= 0x01000101) {211if (screen->compute) {212if (screen->base.class_3d <= GM200_3D_CLASS) {213map[count++] = NVC0_HW_SM_QUERY_GROUP;214map[count++] = NVC0_HW_METRIC_QUERY_GROUP;215}216}217}218219#ifdef NOUVEAU_ENABLE_DRIVER_STATISTICS220map[count++] = NVC0_SW_QUERY_DRV_STAT_GROUP;221#endif222223if (!info)224return count;225226switch (map[id]) {227case NVC0_HW_SM_QUERY_GROUP:228if (screen->compute && screen->base.class_3d <= GM200_3D_CLASS) {229info->name = "MP counters";230231/* Expose the maximum number of hardware counters available, although232* some queries use more than one counter. Expect failures in that233* case but as performance counters are for developers, this should234* not have a real impact. */235info->max_active_queries = 8;236info->num_queries = nvc0_hw_sm_get_num_queries(screen);237return 1;238}239break;240case NVC0_HW_METRIC_QUERY_GROUP:241if (screen->compute && screen->base.class_3d <= GM200_3D_CLASS) {242info->name = "Performance metrics";243info->max_active_queries = 4; /* A metric uses at least 2 queries */244info->num_queries = nvc0_hw_metric_get_num_queries(screen);245return 1;246}247break;248#ifdef NOUVEAU_ENABLE_DRIVER_STATISTICS249case NVC0_SW_QUERY_DRV_STAT_GROUP:250info->name = "Driver statistics";251info->max_active_queries = NVC0_SW_QUERY_DRV_STAT_COUNT;252info->num_queries = NVC0_SW_QUERY_DRV_STAT_COUNT;253return 1;254#endif255}256257/* user asked for info about non-existing query group */258info->name = "this_is_not_the_query_group_you_are_looking_for";259info->max_active_queries = 0;260info->num_queries = 0;261return 0;262}263264static void265nvc0_set_active_query_state(struct pipe_context *pipe, bool enable)266{267}268269void270nvc0_init_query_functions(struct nvc0_context *nvc0)271{272struct pipe_context *pipe = &nvc0->base.pipe;273274pipe->create_query = nvc0_create_query;275pipe->destroy_query = nvc0_destroy_query;276pipe->begin_query = nvc0_begin_query;277pipe->end_query = nvc0_end_query;278pipe->get_query_result = nvc0_get_query_result;279pipe->get_query_result_resource = nvc0_get_query_result_resource;280pipe->set_active_query_state = nvc0_set_active_query_state;281pipe->render_condition = nvc0_render_condition;282nvc0->cond_condmode = NVC0_3D_COND_MODE_ALWAYS;283}284285286