Path: blob/21.2-virgl/src/gallium/frontends/clover/core/timestamp.cpp
4572 views
//1// Copyright 2013 Francisco Jerez2//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//2122#include "core/timestamp.hpp"23#include "core/queue.hpp"24#include "pipe/p_screen.h"25#include "pipe/p_context.h"2627using namespace clover;2829timestamp::query::query(command_queue &q) :30q(q),31_query(q.pipe->create_query(q.pipe, PIPE_QUERY_TIMESTAMP, 0)) {32q.pipe->end_query(q.pipe, _query);33}3435timestamp::query::query(query &&other) :36q(other.q),37_query(other._query) {38other._query = NULL;39}4041timestamp::query::~query() {42if (_query)43q().pipe->destroy_query(q().pipe, _query);44}4546cl_ulong47timestamp::query::operator()() const {48pipe_query_result result;4950if (!q().pipe->get_query_result(q().pipe, _query, false, &result))51throw error(CL_PROFILING_INFO_NOT_AVAILABLE);5253return result.u64;54}5556timestamp::current::current(command_queue &q) :57result(q.pipe->screen->get_timestamp(q.pipe->screen)) {58}5960cl_ulong61timestamp::current::operator()() const {62return result;63}646566