summaryrefslogtreecommitdiff
path: root/src/cl_api_sampler.c
blob: d8dba29beced284edcb20c2148f2fa68f4f725a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
 * Copyright © 2012 Intel Corporation
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "cl_sampler.h"
#include "cl_context.h"
#include "cl_device_id.h"

cl_sampler
clCreateSampler(cl_context context,
                cl_bool normalized,
                cl_addressing_mode addressing,
                cl_filter_mode filter,
                cl_int *errcode_ret)
{
  cl_sampler sampler = NULL;
  cl_int err = CL_SUCCESS;
  cl_uint i;

  do {
    if (!CL_OBJECT_IS_CONTEXT(context)) {
      err = CL_INVALID_CONTEXT;
      break;
    }

    if (addressing < CL_ADDRESS_NONE || addressing > CL_ADDRESS_MIRRORED_REPEAT) {
      err = CL_INVALID_VALUE;
      break;
    }

    if (filter < CL_FILTER_NEAREST || filter > CL_FILTER_LINEAR) {
      err = CL_INVALID_VALUE;
      break;
    }

    /* Check if images are not supported by any device associated with context */
    for (i = 0; i < context->device_num; i++) {
      if (context->devices[i]->image_support == CL_FALSE) {
        err = CL_INVALID_OPERATION;
        break;
      }
    }
    if (err != CL_SUCCESS)
      break;

    sampler = cl_create_sampler(context, normalized, addressing, filter, &err);
  } while (0);

  if (errcode_ret)
    *errcode_ret = err;
  return sampler;
}

cl_int
clGetSamplerInfo(cl_sampler sampler,
                 cl_sampler_info param_name,
                 size_t param_value_size,
                 void *param_value,
                 size_t *param_value_size_ret)
{
  const void *src_ptr = NULL;
  size_t src_size = 0;
  cl_int ref;

  if (!CL_OBJECT_IS_SAMPLER(sampler)) {
    return CL_INVALID_SAMPLER;
  }

  if (param_name == CL_SAMPLER_REFERENCE_COUNT) {
    ref = CL_OBJECT_GET_REF(sampler);
    src_ptr = &ref;
    src_size = sizeof(cl_int);
  } else if (param_name == CL_SAMPLER_CONTEXT) {
    src_ptr = &sampler->ctx;
    src_size = sizeof(cl_context);
  } else if (param_name == CL_SAMPLER_NORMALIZED_COORDS) {
    src_ptr = &sampler->normalized_coords;
    src_size = sizeof(cl_bool);
  } else if (param_name == CL_SAMPLER_ADDRESSING_MODE) {
    src_ptr = &sampler->address;
    src_size = sizeof(cl_addressing_mode);
  } else if (param_name == CL_SAMPLER_FILTER_MODE) {
    src_ptr = &sampler->filter;
    src_size = sizeof(cl_filter_mode);
  } else {
    return CL_INVALID_VALUE;
  }

  return cl_get_info_helper(src_ptr, src_size,
                            param_value, param_value_size, param_value_size_ret);
}

cl_int
clRetainSampler(cl_sampler sampler)
{
  if (!CL_OBJECT_IS_SAMPLER(sampler)) {
    return CL_INVALID_SAMPLER;
  }

  cl_sampler_add_ref(sampler);
  return CL_SUCCESS;
}

cl_int
clReleaseSampler(cl_sampler sampler)
{
  if (!CL_OBJECT_IS_SAMPLER(sampler)) {
    return CL_INVALID_SAMPLER;
  }

  cl_sampler_delete(sampler);
  return CL_SUCCESS;
}