Path: blob/21.2-virgl/src/gallium/frontends/clover/api/sampler.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/sampler.hpp"2425using namespace clover;2627CLOVER_API cl_sampler28clCreateSampler(cl_context d_ctx, cl_bool norm_mode,29cl_addressing_mode addr_mode, cl_filter_mode filter_mode,30cl_int *r_errcode) try {31auto &ctx = obj(d_ctx);3233if (!any_of(std::mem_fn(&device::image_support), ctx.devices()))34throw error(CL_INVALID_OPERATION);3536ret_error(r_errcode, CL_SUCCESS);37return new sampler(ctx, norm_mode, addr_mode, filter_mode);3839} catch (error &e) {40ret_error(r_errcode, e);41return NULL;42}4344CLOVER_API cl_int45clRetainSampler(cl_sampler d_s) try {46obj(d_s).retain();47return CL_SUCCESS;4849} catch (error &e) {50return e.get();51}5253CLOVER_API cl_int54clReleaseSampler(cl_sampler d_s) try {55if (obj(d_s).release())56delete pobj(d_s);5758return CL_SUCCESS;5960} catch (error &e) {61return e.get();62}6364CLOVER_API cl_int65clGetSamplerInfo(cl_sampler d_s, cl_sampler_info param,66size_t size, void *r_buf, size_t *r_size) try {67property_buffer buf { r_buf, size, r_size };68auto &s = obj(d_s);6970switch (param) {71case CL_SAMPLER_REFERENCE_COUNT:72buf.as_scalar<cl_uint>() = s.ref_count();73break;7475case CL_SAMPLER_CONTEXT:76buf.as_scalar<cl_context>() = desc(s.context());77break;7879case CL_SAMPLER_NORMALIZED_COORDS:80buf.as_scalar<cl_bool>() = s.norm_mode();81break;8283case CL_SAMPLER_ADDRESSING_MODE:84buf.as_scalar<cl_addressing_mode>() = s.addr_mode();85break;8687case CL_SAMPLER_FILTER_MODE:88buf.as_scalar<cl_filter_mode>() = s.filter_mode();89break;9091default:92throw error(CL_INVALID_VALUE);93}9495return CL_SUCCESS;9697} catch (error &e) {98return e.get();99}100101102