Path: blob/21.2-virgl/src/gallium/drivers/etnaviv/etnaviv_query_acc_occlusion.c
4570 views
/*1* Copyright (c) 2017 Etnaviv Project2* Copyright (C) 2017 Zodiac Inflight Innovations3*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, sub license,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 the12* next paragraph) shall be included in all copies or substantial portions13* of the 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 NON-INFRINGEMENT. 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, ARISING20* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER21* DEALINGS IN THE SOFTWARE.22*23* Authors:24* Rob Clark <[email protected]>25* Christian Gmeiner <[email protected]>26*/2728#include "util/compiler.h"29#include "util/u_inlines.h"30#include "util/u_memory.h"3132#include "etnaviv_context.h"33#include "etnaviv_debug.h"34#include "etnaviv_emit.h"35#include "etnaviv_query_acc.h"36#include "etnaviv_screen.h"3738/*39* Occlusion Query:40*41* OCCLUSION_COUNTER and OCCLUSION_PREDICATE differ only in how they42* interpret results43*/4445static bool46occlusion_supports(unsigned query_type)47{48switch (query_type) {49case PIPE_QUERY_OCCLUSION_COUNTER:50FALLTHROUGH;51case PIPE_QUERY_OCCLUSION_PREDICATE:52FALLTHROUGH;53case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE:54return true;55default:56return false;57}58}5960static struct etna_acc_query *61occlusion_allocate(struct etna_context *ctx, ASSERTED unsigned query_type)62{63return CALLOC_STRUCT(etna_acc_query);64}6566static void67occlusion_resume(struct etna_acc_query *aq, struct etna_context *ctx)68{69struct etna_resource *rsc = etna_resource(aq->prsc);70struct etna_reloc r = {71.bo = rsc->bo,72.flags = ETNA_RELOC_WRITE73};7475if (aq->samples > 63) {76aq->samples = 63;77BUG("samples overflow");78}7980r.offset = aq->samples * 8; /* 64bit value */8182etna_set_state_reloc(ctx->stream, VIVS_GL_OCCLUSION_QUERY_ADDR, &r);83resource_written(ctx, aq->prsc);84}8586static void87occlusion_suspend(struct etna_acc_query *aq, struct etna_context *ctx)88{89/* 0x1DF5E76 is the value used by blob - but any random value will work */90etna_set_state(ctx->stream, VIVS_GL_OCCLUSION_QUERY_CONTROL, 0x1DF5E76);91resource_written(ctx, aq->prsc);92}9394static bool95occlusion_result(struct etna_acc_query *aq, void *buf,96union pipe_query_result *result)97{98uint64_t sum = 0;99uint64_t *ptr = (uint64_t *)buf;100101for (unsigned i = 0; i < aq->samples; i++)102sum += *(ptr + i);103104if (aq->base.type == PIPE_QUERY_OCCLUSION_COUNTER)105result->u64 = sum;106else107result->b = !!sum;108109return true;110}111112const struct etna_acc_sample_provider occlusion_provider = {113.supports = occlusion_supports,114.allocate = occlusion_allocate,115.suspend = occlusion_suspend,116.resume = occlusion_resume,117.result = occlusion_result,118};119120121