Path: blob/21.2-virgl/src/gallium/frontends/clover/api/queue.cpp
4572 views
//1// Copyright 2012 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 "api/util.hpp"23#include "core/queue.hpp"2425using namespace clover;2627CLOVER_API cl_command_queue28clCreateCommandQueue(cl_context d_ctx, cl_device_id d_dev,29cl_command_queue_properties props,30cl_int *r_errcode) try {31auto &ctx = obj(d_ctx);32auto &dev = obj(d_dev);3334if (!count(dev, ctx.devices()))35throw error(CL_INVALID_DEVICE);3637if (props & ~(CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE |38CL_QUEUE_PROFILING_ENABLE))39throw error(CL_INVALID_VALUE);4041ret_error(r_errcode, CL_SUCCESS);42return new command_queue(ctx, dev, props);4344} catch (error &e) {45ret_error(r_errcode, e);46return NULL;47}4849CLOVER_API cl_int50clRetainCommandQueue(cl_command_queue d_q) try {51obj(d_q).retain();52return CL_SUCCESS;5354} catch (error &e) {55return e.get();56}5758CLOVER_API cl_int59clReleaseCommandQueue(cl_command_queue d_q) try {60auto &q = obj(d_q);6162q.flush();6364if (q.release())65delete pobj(d_q);6667return CL_SUCCESS;6869} catch (error &e) {70return e.get();71}7273CLOVER_API cl_int74clGetCommandQueueInfo(cl_command_queue d_q, cl_command_queue_info param,75size_t size, void *r_buf, size_t *r_size) try {76property_buffer buf { r_buf, size, r_size };77auto &q = obj(d_q);7879switch (param) {80case CL_QUEUE_CONTEXT:81buf.as_scalar<cl_context>() = desc(q.context());82break;8384case CL_QUEUE_DEVICE:85buf.as_scalar<cl_device_id>() = desc(q.device());86break;8788case CL_QUEUE_REFERENCE_COUNT:89buf.as_scalar<cl_uint>() = q.ref_count();90break;9192case CL_QUEUE_PROPERTIES:93buf.as_scalar<cl_command_queue_properties>() = q.props();94break;9596case CL_QUEUE_PROPERTIES_ARRAY:97buf.as_vector<cl_queue_properties>() = q.properties();98break;99100case CL_QUEUE_DEVICE_DEFAULT:101if (r_size)102*r_size = 0;103break;104105case CL_QUEUE_SIZE:106throw error(CL_INVALID_COMMAND_QUEUE);107break;108109default:110throw error(CL_INVALID_VALUE);111}112113return CL_SUCCESS;114115} catch (error &e) {116return e.get();117}118119CLOVER_API cl_int120clFlush(cl_command_queue d_q) try {121obj(d_q).flush();122return CL_SUCCESS;123124} catch (error &e) {125return e.get();126}127128CLOVER_API cl_command_queue129clCreateCommandQueueWithProperties(cl_context d_ctx, cl_device_id d_dev,130const cl_queue_properties *d_properties,131cl_int *r_errcode) try {132auto &ctx = obj(d_ctx);133auto &dev = obj(d_dev);134135if (!count(dev, ctx.devices()))136throw error(CL_INVALID_DEVICE);137138ret_error(r_errcode, CL_SUCCESS);139std::vector<cl_queue_properties> properties;140141if (d_properties) {142int idx = -1;143/* these come in pairs, bail if the first is 0 */144do {145idx++;146properties.push_back(d_properties[idx]);147} while (d_properties[idx & ~1]);148}149return new command_queue(ctx, dev, properties);150151} catch (error &e) {152ret_error(r_errcode, e);153return NULL;154}155156157