Path: blob/21.2-virgl/src/gallium/drivers/nouveau/nvc0/nvc0_query_hw.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#define NVC0_PUSH_EXPLICIT_SPACE_CHECKING2425#include "nvc0/nvc0_context.h"26#include "nvc0/nvc0_query_hw.h"27#include "nvc0/nvc0_query_hw_metric.h"28#include "nvc0/nvc0_query_hw_sm.h"2930#define NVC0_HW_QUERY_ALLOC_SPACE 2563132bool33nvc0_hw_query_allocate(struct nvc0_context *nvc0, struct nvc0_query *q,34int size)35{36struct nvc0_hw_query *hq = nvc0_hw_query(q);37struct nvc0_screen *screen = nvc0->screen;38int ret;3940if (hq->bo) {41nouveau_bo_ref(NULL, &hq->bo);42if (hq->mm) {43if (hq->state == NVC0_HW_QUERY_STATE_READY)44nouveau_mm_free(hq->mm);45else46nouveau_fence_work(screen->base.fence.current,47nouveau_mm_free_work, hq->mm);48}49}50if (size) {51hq->mm = nouveau_mm_allocate(screen->base.mm_GART, size, &hq->bo,52&hq->base_offset);53if (!hq->bo)54return false;55hq->offset = hq->base_offset;5657ret = nouveau_bo_map(hq->bo, 0, screen->base.client);58if (ret) {59nvc0_hw_query_allocate(nvc0, q, 0);60return false;61}62hq->data = (uint32_t *)((uint8_t *)hq->bo->map + hq->base_offset);63}64return true;65}6667static void68nvc0_hw_query_get(struct nouveau_pushbuf *push, struct nvc0_query *q,69unsigned offset, uint32_t get)70{71struct nvc0_hw_query *hq = nvc0_hw_query(q);7273offset += hq->offset;7475PUSH_SPACE(push, 5);76PUSH_REFN (push, hq->bo, NOUVEAU_BO_GART | NOUVEAU_BO_WR);77BEGIN_NVC0(push, NVC0_3D(QUERY_ADDRESS_HIGH), 4);78PUSH_DATAh(push, hq->bo->offset + offset);79PUSH_DATA (push, hq->bo->offset + offset);80PUSH_DATA (push, hq->sequence);81PUSH_DATA (push, get);82}8384static void85nvc0_hw_query_rotate(struct nvc0_context *nvc0, struct nvc0_query *q)86{87struct nvc0_hw_query *hq = nvc0_hw_query(q);8889hq->offset += hq->rotate;90hq->data += hq->rotate / sizeof(*hq->data);91if (hq->offset - hq->base_offset == NVC0_HW_QUERY_ALLOC_SPACE)92nvc0_hw_query_allocate(nvc0, q, NVC0_HW_QUERY_ALLOC_SPACE);93}9495static inline void96nvc0_hw_query_update(struct nouveau_client *cli, struct nvc0_query *q)97{98struct nvc0_hw_query *hq = nvc0_hw_query(q);99100if (hq->is64bit) {101if (nouveau_fence_signalled(hq->fence))102hq->state = NVC0_HW_QUERY_STATE_READY;103} else {104if (hq->data[0] == hq->sequence)105hq->state = NVC0_HW_QUERY_STATE_READY;106}107}108109static void110nvc0_hw_destroy_query(struct nvc0_context *nvc0, struct nvc0_query *q)111{112struct nvc0_hw_query *hq = nvc0_hw_query(q);113114if (hq->funcs && hq->funcs->destroy_query) {115hq->funcs->destroy_query(nvc0, hq);116return;117}118119nvc0_hw_query_allocate(nvc0, q, 0);120nouveau_fence_ref(NULL, &hq->fence);121FREE(hq);122}123124static void125nvc0_hw_query_write_compute_invocations(struct nvc0_context *nvc0,126struct nvc0_hw_query *hq,127uint32_t offset)128{129struct nouveau_pushbuf *push = nvc0->base.pushbuf;130131nouveau_pushbuf_space(push, 16, 0, 8);132PUSH_REFN(push, hq->bo, NOUVEAU_BO_GART | NOUVEAU_BO_WR);133BEGIN_1IC0(push, NVC0_3D(MACRO_COMPUTE_COUNTER_TO_QUERY), 4);134PUSH_DATA (push, nvc0->compute_invocations);135PUSH_DATAh(push, nvc0->compute_invocations);136PUSH_DATAh(push, hq->bo->offset + hq->offset + offset);137PUSH_DATA (push, hq->bo->offset + hq->offset + offset);138}139140static bool141nvc0_hw_begin_query(struct nvc0_context *nvc0, struct nvc0_query *q)142{143struct nouveau_pushbuf *push = nvc0->base.pushbuf;144struct nvc0_hw_query *hq = nvc0_hw_query(q);145bool ret = true;146147if (hq->funcs && hq->funcs->begin_query)148return hq->funcs->begin_query(nvc0, hq);149150/* For occlusion queries we have to change the storage, because a previous151* query might set the initial render condition to false even *after* we re-152* initialized it to true.153*/154if (hq->rotate) {155nvc0_hw_query_rotate(nvc0, q);156157/* XXX: can we do this with the GPU, and sync with respect to a previous158* query ?159*/160hq->data[0] = hq->sequence; /* initialize sequence */161hq->data[1] = 1; /* initial render condition = true */162hq->data[4] = hq->sequence + 1; /* for comparison COND_MODE */163hq->data[5] = 0;164}165hq->sequence++;166167switch (q->type) {168case PIPE_QUERY_OCCLUSION_COUNTER:169case PIPE_QUERY_OCCLUSION_PREDICATE:170case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE:171if (nvc0->screen->num_occlusion_queries_active++) {172nvc0_hw_query_get(push, q, 0x10, 0x0100f002);173} else {174PUSH_SPACE(push, 3);175BEGIN_NVC0(push, NVC0_3D(COUNTER_RESET), 1);176PUSH_DATA (push, NVC0_3D_COUNTER_RESET_SAMPLECNT);177IMMED_NVC0(push, NVC0_3D(SAMPLECNT_ENABLE), 1);178/* Given that the counter is reset, the contents at 0x10 are179* equivalent to doing the query -- we would get hq->sequence as the180* payload and 0 as the reported value. This is already set up above181* as in the hq->rotate case.182*/183}184break;185case PIPE_QUERY_PRIMITIVES_GENERATED:186nvc0_hw_query_get(push, q, 0x10, 0x09005002 | (q->index << 5));187break;188case PIPE_QUERY_PRIMITIVES_EMITTED:189nvc0_hw_query_get(push, q, 0x10, 0x05805002 | (q->index << 5));190break;191case PIPE_QUERY_SO_STATISTICS:192nvc0_hw_query_get(push, q, 0x20, 0x05805002 | (q->index << 5));193nvc0_hw_query_get(push, q, 0x30, 0x06805002 | (q->index << 5));194break;195case PIPE_QUERY_SO_OVERFLOW_PREDICATE:196nvc0_hw_query_get(push, q, 0x10, 0x03005002 | (q->index << 5));197break;198case PIPE_QUERY_SO_OVERFLOW_ANY_PREDICATE:199/* XXX: This get actually writes the number of overflowed streams */200nvc0_hw_query_get(push, q, 0x10, 0x0f005002);201break;202case PIPE_QUERY_TIME_ELAPSED:203nvc0_hw_query_get(push, q, 0x10, 0x00005002);204break;205case PIPE_QUERY_PIPELINE_STATISTICS:206nvc0_hw_query_get(push, q, 0xc0 + 0x00, 0x00801002); /* VFETCH, VERTICES */207nvc0_hw_query_get(push, q, 0xc0 + 0x10, 0x01801002); /* VFETCH, PRIMS */208nvc0_hw_query_get(push, q, 0xc0 + 0x20, 0x02802002); /* VP, LAUNCHES */209nvc0_hw_query_get(push, q, 0xc0 + 0x30, 0x03806002); /* GP, LAUNCHES */210nvc0_hw_query_get(push, q, 0xc0 + 0x40, 0x04806002); /* GP, PRIMS_OUT */211nvc0_hw_query_get(push, q, 0xc0 + 0x50, 0x07804002); /* RAST, PRIMS_IN */212nvc0_hw_query_get(push, q, 0xc0 + 0x60, 0x08804002); /* RAST, PRIMS_OUT */213nvc0_hw_query_get(push, q, 0xc0 + 0x70, 0x0980a002); /* ROP, PIXELS */214nvc0_hw_query_get(push, q, 0xc0 + 0x80, 0x0d808002); /* TCP, LAUNCHES */215nvc0_hw_query_get(push, q, 0xc0 + 0x90, 0x0e809002); /* TEP, LAUNCHES */216nvc0_hw_query_write_compute_invocations(nvc0, hq, 0xc0 + 0xa0);217break;218default:219break;220}221hq->state = NVC0_HW_QUERY_STATE_ACTIVE;222return ret;223}224225static void226nvc0_hw_end_query(struct nvc0_context *nvc0, struct nvc0_query *q)227{228struct nouveau_pushbuf *push = nvc0->base.pushbuf;229struct nvc0_hw_query *hq = nvc0_hw_query(q);230231if (hq->funcs && hq->funcs->end_query) {232hq->funcs->end_query(nvc0, hq);233return;234}235236if (hq->state != NVC0_HW_QUERY_STATE_ACTIVE) {237/* some queries don't require 'begin' to be called (e.g. GPU_FINISHED) */238if (hq->rotate)239nvc0_hw_query_rotate(nvc0, q);240hq->sequence++;241}242hq->state = NVC0_HW_QUERY_STATE_ENDED;243244switch (q->type) {245case PIPE_QUERY_OCCLUSION_COUNTER:246case PIPE_QUERY_OCCLUSION_PREDICATE:247case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE:248nvc0_hw_query_get(push, q, 0, 0x0100f002);249if (--nvc0->screen->num_occlusion_queries_active == 0) {250PUSH_SPACE(push, 1);251IMMED_NVC0(push, NVC0_3D(SAMPLECNT_ENABLE), 0);252}253break;254case PIPE_QUERY_PRIMITIVES_GENERATED:255nvc0_hw_query_get(push, q, 0, 0x09005002 | (q->index << 5));256break;257case PIPE_QUERY_PRIMITIVES_EMITTED:258nvc0_hw_query_get(push, q, 0, 0x05805002 | (q->index << 5));259break;260case PIPE_QUERY_SO_STATISTICS:261nvc0_hw_query_get(push, q, 0x00, 0x05805002 | (q->index << 5));262nvc0_hw_query_get(push, q, 0x10, 0x06805002 | (q->index << 5));263break;264case PIPE_QUERY_SO_OVERFLOW_PREDICATE:265nvc0_hw_query_get(push, q, 0x00, 0x03005002 | (q->index << 5));266break;267case PIPE_QUERY_SO_OVERFLOW_ANY_PREDICATE:268/* XXX: This get actually writes the number of overflowed streams */269nvc0_hw_query_get(push, q, 0x00, 0x0f005002);270break;271case PIPE_QUERY_TIMESTAMP:272case PIPE_QUERY_TIME_ELAPSED:273nvc0_hw_query_get(push, q, 0, 0x00005002);274break;275case PIPE_QUERY_GPU_FINISHED:276nvc0_hw_query_get(push, q, 0, 0x1000f010);277break;278case PIPE_QUERY_PIPELINE_STATISTICS:279nvc0_hw_query_get(push, q, 0x00, 0x00801002); /* VFETCH, VERTICES */280nvc0_hw_query_get(push, q, 0x10, 0x01801002); /* VFETCH, PRIMS */281nvc0_hw_query_get(push, q, 0x20, 0x02802002); /* VP, LAUNCHES */282nvc0_hw_query_get(push, q, 0x30, 0x03806002); /* GP, LAUNCHES */283nvc0_hw_query_get(push, q, 0x40, 0x04806002); /* GP, PRIMS_OUT */284nvc0_hw_query_get(push, q, 0x50, 0x07804002); /* RAST, PRIMS_IN */285nvc0_hw_query_get(push, q, 0x60, 0x08804002); /* RAST, PRIMS_OUT */286nvc0_hw_query_get(push, q, 0x70, 0x0980a002); /* ROP, PIXELS */287nvc0_hw_query_get(push, q, 0x80, 0x0d808002); /* TCP, LAUNCHES */288nvc0_hw_query_get(push, q, 0x90, 0x0e809002); /* TEP, LAUNCHES */289nvc0_hw_query_write_compute_invocations(nvc0, hq, 0xa0);290break;291case PIPE_QUERY_TIMESTAMP_DISJOINT:292/* This query is not issued on GPU because disjoint is forced to false */293hq->state = NVC0_HW_QUERY_STATE_READY;294break;295case NVC0_HW_QUERY_TFB_BUFFER_OFFSET:296/* indexed by TFB buffer instead of by vertex stream */297nvc0_hw_query_get(push, q, 0x00, 0x0d005002 | (q->index << 5));298break;299default:300break;301}302if (hq->is64bit)303nouveau_fence_ref(nvc0->screen->base.fence.current, &hq->fence);304}305306static bool307nvc0_hw_get_query_result(struct nvc0_context *nvc0, struct nvc0_query *q,308bool wait, union pipe_query_result *result)309{310struct nvc0_hw_query *hq = nvc0_hw_query(q);311uint64_t *res64 = (uint64_t*)result;312uint32_t *res32 = (uint32_t*)result;313uint8_t *res8 = (uint8_t*)result;314uint64_t *data64 = (uint64_t *)hq->data;315unsigned i;316317if (hq->funcs && hq->funcs->get_query_result)318return hq->funcs->get_query_result(nvc0, hq, wait, result);319320if (hq->state != NVC0_HW_QUERY_STATE_READY)321nvc0_hw_query_update(nvc0->screen->base.client, q);322323if (hq->state != NVC0_HW_QUERY_STATE_READY) {324if (!wait) {325if (hq->state != NVC0_HW_QUERY_STATE_FLUSHED) {326hq->state = NVC0_HW_QUERY_STATE_FLUSHED;327/* flush for silly apps that spin on GL_QUERY_RESULT_AVAILABLE */328PUSH_KICK(nvc0->base.pushbuf);329}330return false;331}332if (nouveau_bo_wait(hq->bo, NOUVEAU_BO_RD, nvc0->screen->base.client))333return false;334NOUVEAU_DRV_STAT(&nvc0->screen->base, query_sync_count, 1);335}336hq->state = NVC0_HW_QUERY_STATE_READY;337338switch (q->type) {339case PIPE_QUERY_GPU_FINISHED:340res8[0] = true;341break;342case PIPE_QUERY_OCCLUSION_COUNTER: /* u32 sequence, u32 count, u64 time */343res64[0] = hq->data[1] - hq->data[5];344break;345case PIPE_QUERY_OCCLUSION_PREDICATE:346case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE:347res8[0] = hq->data[1] != hq->data[5];348break;349case PIPE_QUERY_PRIMITIVES_GENERATED: /* u64 count, u64 time */350case PIPE_QUERY_PRIMITIVES_EMITTED: /* u64 count, u64 time */351res64[0] = data64[0] - data64[2];352break;353case PIPE_QUERY_SO_STATISTICS:354res64[0] = data64[0] - data64[4];355res64[1] = data64[2] - data64[6];356break;357case PIPE_QUERY_SO_OVERFLOW_PREDICATE:358case PIPE_QUERY_SO_OVERFLOW_ANY_PREDICATE:359res8[0] = data64[0] != data64[2];360break;361case PIPE_QUERY_TIMESTAMP:362res64[0] = data64[1];363break;364case PIPE_QUERY_TIMESTAMP_DISJOINT:365res64[0] = 1000000000;366res8[8] = false;367break;368case PIPE_QUERY_TIME_ELAPSED:369res64[0] = data64[1] - data64[3];370break;371case PIPE_QUERY_PIPELINE_STATISTICS:372for (i = 0; i < 11; ++i)373res64[i] = data64[i * 2] - data64[24 + i * 2];374break;375case NVC0_HW_QUERY_TFB_BUFFER_OFFSET:376res32[0] = hq->data[1];377break;378default:379assert(0); /* can't happen, we don't create queries with invalid type */380return false;381}382383return true;384}385386static void387nvc0_hw_get_query_result_resource(struct nvc0_context *nvc0,388struct nvc0_query *q,389bool wait,390enum pipe_query_value_type result_type,391int index,392struct pipe_resource *resource,393unsigned offset)394{395struct nouveau_pushbuf *push = nvc0->base.pushbuf;396struct nvc0_hw_query *hq = nvc0_hw_query(q);397struct nv04_resource *buf = nv04_resource(resource);398unsigned qoffset = 0, stride;399400assert(!hq->funcs || !hq->funcs->get_query_result);401402if (index == -1) {403/* TODO: Use a macro to write the availability of the query */404if (hq->state != NVC0_HW_QUERY_STATE_READY)405nvc0_hw_query_update(nvc0->screen->base.client, q);406uint32_t ready[2] = {hq->state == NVC0_HW_QUERY_STATE_READY};407nvc0->base.push_cb(&nvc0->base, buf, offset,408result_type >= PIPE_QUERY_TYPE_I64 ? 2 : 1,409ready);410411util_range_add(&buf->base, &buf->valid_buffer_range, offset,412offset + (result_type >= PIPE_QUERY_TYPE_I64 ? 8 : 4));413414nvc0_resource_validate(buf, NOUVEAU_BO_WR);415416return;417}418419/* If the fence guarding this query has not been emitted, that makes a lot420* of the following logic more complicated.421*/422if (hq->is64bit && hq->fence->state < NOUVEAU_FENCE_STATE_EMITTED)423nouveau_fence_emit(hq->fence);424425/* We either need to compute a 32- or 64-bit difference between 2 values,426* and then store the result as either a 32- or 64-bit value. As such let's427* treat all inputs as 64-bit (and just push an extra 0 for the 32-bit428* ones), and have one macro that clamps result to i32, u32, or just429* outputs the difference (no need to worry about 64-bit clamping).430*/431if (hq->state != NVC0_HW_QUERY_STATE_READY)432nvc0_hw_query_update(nvc0->screen->base.client, q);433434if (wait && hq->state != NVC0_HW_QUERY_STATE_READY)435nvc0_hw_query_fifo_wait(nvc0, q);436437nouveau_pushbuf_space(push, 32, 2, 3);438PUSH_REFN (push, hq->bo, NOUVEAU_BO_GART | NOUVEAU_BO_RD);439PUSH_REFN (push, buf->bo, buf->domain | NOUVEAU_BO_WR);440BEGIN_1IC0(push, NVC0_3D(MACRO_QUERY_BUFFER_WRITE), 9);441switch (q->type) {442case PIPE_QUERY_OCCLUSION_PREDICATE:443case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE: /* XXX what if 64-bit? */444case PIPE_QUERY_SO_OVERFLOW_PREDICATE:445case PIPE_QUERY_SO_OVERFLOW_ANY_PREDICATE:446PUSH_DATA(push, 0x00000001);447break;448default:449if (result_type == PIPE_QUERY_TYPE_I32)450PUSH_DATA(push, 0x7fffffff);451else if (result_type == PIPE_QUERY_TYPE_U32)452PUSH_DATA(push, 0xffffffff);453else454PUSH_DATA(push, 0x00000000);455break;456}457458switch (q->type) {459case PIPE_QUERY_SO_STATISTICS:460stride = 2;461break;462case PIPE_QUERY_PIPELINE_STATISTICS:463stride = 12;464break;465case PIPE_QUERY_TIME_ELAPSED:466case PIPE_QUERY_TIMESTAMP:467qoffset = 8;468FALLTHROUGH;469default:470assert(index == 0);471stride = 1;472break;473}474475if (hq->is64bit || qoffset) {476nouveau_pushbuf_data(push, hq->bo, hq->offset + qoffset + 16 * index,4778 | NVC0_IB_ENTRY_1_NO_PREFETCH);478if (q->type == PIPE_QUERY_TIMESTAMP) {479PUSH_DATA(push, 0);480PUSH_DATA(push, 0);481} else {482nouveau_pushbuf_data(push, hq->bo, hq->offset + qoffset +48316 * (index + stride),4848 | NVC0_IB_ENTRY_1_NO_PREFETCH);485}486} else {487nouveau_pushbuf_data(push, hq->bo, hq->offset + 4,4884 | NVC0_IB_ENTRY_1_NO_PREFETCH);489PUSH_DATA(push, 0);490nouveau_pushbuf_data(push, hq->bo, hq->offset + 16 + 4,4914 | NVC0_IB_ENTRY_1_NO_PREFETCH);492PUSH_DATA(push, 0);493}494495if (wait || hq->state == NVC0_HW_QUERY_STATE_READY) {496PUSH_DATA(push, 0);497PUSH_DATA(push, 0);498} else if (hq->is64bit) {499PUSH_DATA(push, hq->fence->sequence);500nouveau_pushbuf_data(push, nvc0->screen->fence.bo, 0,5014 | NVC0_IB_ENTRY_1_NO_PREFETCH);502} else {503PUSH_DATA(push, hq->sequence);504nouveau_pushbuf_data(push, hq->bo, hq->offset,5054 | NVC0_IB_ENTRY_1_NO_PREFETCH);506}507PUSH_DATAh(push, buf->address + offset);508PUSH_DATA (push, buf->address + offset);509510util_range_add(&buf->base, &buf->valid_buffer_range, offset,511offset + (result_type >= PIPE_QUERY_TYPE_I64 ? 8 : 4));512513nvc0_resource_validate(buf, NOUVEAU_BO_WR);514}515516static const struct nvc0_query_funcs hw_query_funcs = {517.destroy_query = nvc0_hw_destroy_query,518.begin_query = nvc0_hw_begin_query,519.end_query = nvc0_hw_end_query,520.get_query_result = nvc0_hw_get_query_result,521.get_query_result_resource = nvc0_hw_get_query_result_resource,522};523524struct nvc0_query *525nvc0_hw_create_query(struct nvc0_context *nvc0, unsigned type, unsigned index)526{527struct nvc0_hw_query *hq;528struct nvc0_query *q;529unsigned space = NVC0_HW_QUERY_ALLOC_SPACE;530531hq = nvc0_hw_sm_create_query(nvc0, type);532if (hq) {533hq->base.funcs = &hw_query_funcs;534return (struct nvc0_query *)hq;535}536537hq = nvc0_hw_metric_create_query(nvc0, type);538if (hq) {539hq->base.funcs = &hw_query_funcs;540return (struct nvc0_query *)hq;541}542543hq = CALLOC_STRUCT(nvc0_hw_query);544if (!hq)545return NULL;546547q = &hq->base;548q->funcs = &hw_query_funcs;549q->type = type;550q->index = index;551552switch (q->type) {553case PIPE_QUERY_OCCLUSION_COUNTER:554case PIPE_QUERY_OCCLUSION_PREDICATE:555case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE:556hq->rotate = 32;557space = NVC0_HW_QUERY_ALLOC_SPACE;558break;559case PIPE_QUERY_PIPELINE_STATISTICS:560hq->is64bit = true;561space = 512;562break;563case PIPE_QUERY_SO_STATISTICS:564hq->is64bit = true;565space = 64;566break;567case PIPE_QUERY_SO_OVERFLOW_PREDICATE:568case PIPE_QUERY_SO_OVERFLOW_ANY_PREDICATE:569case PIPE_QUERY_PRIMITIVES_GENERATED:570case PIPE_QUERY_PRIMITIVES_EMITTED:571hq->is64bit = true;572space = 32;573break;574case PIPE_QUERY_TIME_ELAPSED:575case PIPE_QUERY_TIMESTAMP:576case PIPE_QUERY_TIMESTAMP_DISJOINT:577case PIPE_QUERY_GPU_FINISHED:578space = 32;579break;580case NVC0_HW_QUERY_TFB_BUFFER_OFFSET:581space = 16;582break;583default:584debug_printf("invalid query type: %u\n", type);585FREE(q);586return NULL;587}588589if (!nvc0_hw_query_allocate(nvc0, q, space)) {590FREE(hq);591return NULL;592}593594if (hq->rotate) {595/* we advance before query_begin ! */596hq->offset -= hq->rotate;597hq->data -= hq->rotate / sizeof(*hq->data);598} else599if (!hq->is64bit)600hq->data[0] = 0; /* initialize sequence */601602return q;603}604605int606nvc0_hw_get_driver_query_info(struct nvc0_screen *screen, unsigned id,607struct pipe_driver_query_info *info)608{609int num_hw_sm_queries = 0, num_hw_metric_queries = 0;610611num_hw_sm_queries = nvc0_hw_sm_get_driver_query_info(screen, 0, NULL);612num_hw_metric_queries =613nvc0_hw_metric_get_driver_query_info(screen, 0, NULL);614615if (!info)616return num_hw_sm_queries + num_hw_metric_queries;617618if (id < num_hw_sm_queries)619return nvc0_hw_sm_get_driver_query_info(screen, id, info);620621return nvc0_hw_metric_get_driver_query_info(screen,622id - num_hw_sm_queries, info);623}624625void626nvc0_hw_query_pushbuf_submit(struct nouveau_pushbuf *push,627struct nvc0_query *q, unsigned result_offset)628{629struct nvc0_hw_query *hq = nvc0_hw_query(q);630631PUSH_REFN(push, hq->bo, NOUVEAU_BO_RD | NOUVEAU_BO_GART);632nouveau_pushbuf_data(push, hq->bo, hq->offset + result_offset, 4 |633NVC0_IB_ENTRY_1_NO_PREFETCH);634}635636void637nvc0_hw_query_fifo_wait(struct nvc0_context *nvc0, struct nvc0_query *q)638{639struct nouveau_pushbuf *push = nvc0->base.pushbuf;640struct nvc0_hw_query *hq = nvc0_hw_query(q);641unsigned offset = hq->offset;642643/* ensure the query's fence has been emitted */644if (hq->is64bit && hq->fence->state < NOUVEAU_FENCE_STATE_EMITTED)645nouveau_fence_emit(hq->fence);646647PUSH_SPACE(push, 5);648PUSH_REFN (push, hq->bo, NOUVEAU_BO_GART | NOUVEAU_BO_RD);649BEGIN_NVC0(push, SUBC_3D(NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH), 4);650if (hq->is64bit) {651PUSH_DATAh(push, nvc0->screen->fence.bo->offset);652PUSH_DATA (push, nvc0->screen->fence.bo->offset);653PUSH_DATA (push, hq->fence->sequence);654} else {655PUSH_DATAh(push, hq->bo->offset + offset);656PUSH_DATA (push, hq->bo->offset + offset);657PUSH_DATA (push, hq->sequence);658}659PUSH_DATA (push, (1 << 12) |660NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_GEQUAL);661}662663664