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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#![allow(non_camel_case_types)]
use super::error_codes::{CL_INVALID_VALUE, CL_SUCCESS};
use super::info_type::InfoType;
use super::types::{
cl_addressing_mode, cl_bool, cl_context, cl_filter_mode, cl_int, cl_sampler, cl_sampler_info,
cl_sampler_properties, cl_uint, cl_ulong,
};
use super::{api_info_size, api_info_value, api_info_vector};
#[allow(unused_imports)]
use cl_sys::{
clCreateSampler, clCreateSamplerWithProperties, clGetSamplerInfo, clReleaseSampler,
clRetainSampler,
};
use libc::{c_void, intptr_t, size_t};
use std::mem;
use std::ptr;
#[cfg(feature = "CL_VERSION_1_2")]
#[inline]
pub fn create_sampler(
context: cl_context,
normalize_coords: cl_bool,
addressing_mode: cl_addressing_mode,
filter_mode: cl_filter_mode,
) -> Result<cl_sampler, cl_int> {
let mut status: cl_int = CL_INVALID_VALUE;
let sampler: cl_sampler = unsafe {
clCreateSampler(
context,
normalize_coords,
addressing_mode,
filter_mode,
&mut status,
)
};
if CL_SUCCESS != status {
Err(status)
} else {
Ok(sampler)
}
}
#[cfg(feature = "CL_VERSION_2_0")]
#[inline]
pub fn create_sampler_with_properties(
context: cl_context,
properties: *const cl_sampler_properties,
) -> Result<cl_sampler, cl_int> {
let mut status: cl_int = CL_INVALID_VALUE;
let sampler: cl_sampler =
unsafe { clCreateSamplerWithProperties(context, properties, &mut status) };
if CL_SUCCESS != status {
Err(status)
} else {
Ok(sampler)
}
}
#[inline]
pub fn retain_sampler(sampler: cl_sampler) -> Result<(), cl_int> {
let status: cl_int = unsafe { clRetainSampler(sampler) };
if CL_SUCCESS != status {
Err(status)
} else {
Ok(())
}
}
#[inline]
pub fn release_sampler(sampler: cl_sampler) -> Result<(), cl_int> {
let status: cl_int = unsafe { clReleaseSampler(sampler) };
if CL_SUCCESS != status {
Err(status)
} else {
Ok(())
}
}
#[derive(Clone, Copy, Debug)]
pub enum SamplerInfo {
CL_SAMPLER_REFERENCE_COUNT = 0x1150,
CL_SAMPLER_CONTEXT = 0x1151,
CL_SAMPLER_NORMALIZED_COORDS = 0x1152,
CL_SAMPLER_ADDRESSING_MODE = 0x1153,
CL_SAMPLER_FILTER_MODE = 0x1154,
CL_SAMPLER_PROPERTIES = 0x1158,
}
pub fn get_sampler_info(sampler: cl_sampler, param_name: SamplerInfo) -> Result<InfoType, cl_int> {
let param_id = param_name as cl_sampler_info;
match param_name {
SamplerInfo::CL_SAMPLER_REFERENCE_COUNT
| SamplerInfo::CL_SAMPLER_NORMALIZED_COORDS
| SamplerInfo::CL_SAMPLER_ADDRESSING_MODE
| SamplerInfo::CL_SAMPLER_FILTER_MODE => {
api_info_value!(get_value, cl_uint, clGetSamplerInfo);
Ok(InfoType::Uint(get_value(sampler, param_id)?))
}
SamplerInfo::CL_SAMPLER_CONTEXT => {
api_info_value!(get_value, intptr_t, clGetSamplerInfo);
Ok(InfoType::Ptr(get_value(sampler, param_id)?))
}
SamplerInfo::CL_SAMPLER_PROPERTIES
=> {
api_info_size!(get_size, clGetSamplerInfo);
api_info_vector!(get_vec, cl_ulong, clGetSamplerInfo);
let size = get_size(sampler, param_id)?;
Ok(InfoType::VecUlong(get_vec(sampler, param_id, size,)?))
}
}
}