17ec681f3Smrg//
27ec681f3Smrg// Copyright 2012 Francisco Jerez
37ec681f3Smrg//
47ec681f3Smrg// Permission is hereby granted, free of charge, to any person obtaining a
57ec681f3Smrg// copy of this software and associated documentation files (the "Software"),
67ec681f3Smrg// to deal in the Software without restriction, including without limitation
77ec681f3Smrg// the rights to use, copy, modify, merge, publish, distribute, sublicense,
87ec681f3Smrg// and/or sell copies of the Software, and to permit persons to whom the
97ec681f3Smrg// Software is furnished to do so, subject to the following conditions:
107ec681f3Smrg//
117ec681f3Smrg// The above copyright notice and this permission notice shall be included in
127ec681f3Smrg// all copies or substantial portions of the Software.
137ec681f3Smrg//
147ec681f3Smrg// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
157ec681f3Smrg// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
167ec681f3Smrg// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
177ec681f3Smrg// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
187ec681f3Smrg// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
197ec681f3Smrg// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
207ec681f3Smrg// OTHER DEALINGS IN THE SOFTWARE.
217ec681f3Smrg//
227ec681f3Smrg
237ec681f3Smrg#include "api/util.hpp"
247ec681f3Smrg#include "core/sampler.hpp"
257ec681f3Smrg
267ec681f3Smrgusing namespace clover;
277ec681f3Smrg
287ec681f3SmrgCLOVER_API cl_sampler
297ec681f3SmrgclCreateSampler(cl_context d_ctx, cl_bool norm_mode,
307ec681f3Smrg                cl_addressing_mode addr_mode, cl_filter_mode filter_mode,
317ec681f3Smrg                cl_int *r_errcode) try {
327ec681f3Smrg   auto &ctx = obj(d_ctx);
337ec681f3Smrg
347ec681f3Smrg   if (!any_of(std::mem_fn(&device::image_support), ctx.devices()))
357ec681f3Smrg      throw error(CL_INVALID_OPERATION);
367ec681f3Smrg
377ec681f3Smrg   ret_error(r_errcode, CL_SUCCESS);
387ec681f3Smrg   return new sampler(ctx, norm_mode, addr_mode, filter_mode);
397ec681f3Smrg
407ec681f3Smrg} catch (error &e) {
417ec681f3Smrg   ret_error(r_errcode, e);
427ec681f3Smrg   return NULL;
437ec681f3Smrg}
447ec681f3Smrg
457ec681f3SmrgCLOVER_API cl_int
467ec681f3SmrgclRetainSampler(cl_sampler d_s) try {
477ec681f3Smrg   obj(d_s).retain();
487ec681f3Smrg   return CL_SUCCESS;
497ec681f3Smrg
507ec681f3Smrg} catch (error &e) {
517ec681f3Smrg   return e.get();
527ec681f3Smrg}
537ec681f3Smrg
547ec681f3SmrgCLOVER_API cl_int
557ec681f3SmrgclReleaseSampler(cl_sampler d_s) try {
567ec681f3Smrg   if (obj(d_s).release())
577ec681f3Smrg      delete pobj(d_s);
587ec681f3Smrg
597ec681f3Smrg   return CL_SUCCESS;
607ec681f3Smrg
617ec681f3Smrg} catch (error &e) {
627ec681f3Smrg   return e.get();
637ec681f3Smrg}
647ec681f3Smrg
657ec681f3SmrgCLOVER_API cl_int
667ec681f3SmrgclGetSamplerInfo(cl_sampler d_s, cl_sampler_info param,
677ec681f3Smrg                 size_t size, void *r_buf, size_t *r_size) try {
687ec681f3Smrg   property_buffer buf { r_buf, size, r_size };
697ec681f3Smrg   auto &s = obj(d_s);
707ec681f3Smrg
717ec681f3Smrg   switch (param) {
727ec681f3Smrg   case CL_SAMPLER_REFERENCE_COUNT:
737ec681f3Smrg      buf.as_scalar<cl_uint>() = s.ref_count();
747ec681f3Smrg      break;
757ec681f3Smrg
767ec681f3Smrg   case CL_SAMPLER_CONTEXT:
777ec681f3Smrg      buf.as_scalar<cl_context>() = desc(s.context());
787ec681f3Smrg      break;
797ec681f3Smrg
807ec681f3Smrg   case CL_SAMPLER_NORMALIZED_COORDS:
817ec681f3Smrg      buf.as_scalar<cl_bool>() = s.norm_mode();
827ec681f3Smrg      break;
837ec681f3Smrg
847ec681f3Smrg   case CL_SAMPLER_ADDRESSING_MODE:
857ec681f3Smrg      buf.as_scalar<cl_addressing_mode>() = s.addr_mode();
867ec681f3Smrg      break;
877ec681f3Smrg
887ec681f3Smrg   case CL_SAMPLER_FILTER_MODE:
897ec681f3Smrg      buf.as_scalar<cl_filter_mode>() = s.filter_mode();
907ec681f3Smrg      break;
917ec681f3Smrg
927ec681f3Smrg   default:
937ec681f3Smrg      throw error(CL_INVALID_VALUE);
947ec681f3Smrg   }
957ec681f3Smrg
967ec681f3Smrg   return CL_SUCCESS;
977ec681f3Smrg
987ec681f3Smrg} catch (error &e) {
997ec681f3Smrg   return e.get();
1007ec681f3Smrg}
101