opencl_sys/
cl_gl.rs

1// Copyright (c) 2022-2023 Via Technology Ltd.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//    http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! FFI bindings for [cl_gl.h](https://github.com/KhronosGroup/OpenCL-Headers/blob/main/CL/cl_gl.h)  
16//! `OpenCL` extensions are documented in the [OpenCL-Registry](https://github.com/KhronosGroup/OpenCL-Registry)
17
18#![allow(non_camel_case_types, non_upper_case_globals)]
19
20use super::cl::{
21    cl_command_queue, cl_context, cl_context_properties, cl_event, cl_mem, cl_mem_flags,
22    cl_mem_object_type,
23};
24use libc::{c_void, size_t};
25
26use super::cl_platform::{cl_int, cl_uint};
27
28pub type cl_gl_object_type = cl_uint;
29pub type cl_gl_texture_info = cl_uint;
30pub type cl_gl_platform_info = cl_uint;
31pub type cl_GLsync = *mut c_void;
32
33pub type cl_GLuint = u32;
34pub type cl_GLint = i32;
35pub type cl_GLenum = u32;
36
37pub type cl_gl_context_info = cl_uint;
38
39// cl_gl_object_type = 0x2000 - 0x200F enum values are currently taken
40pub const CL_GL_OBJECT_BUFFER: cl_gl_object_type = 0x2000;
41pub const CL_GL_OBJECT_TEXTURE2D: cl_gl_object_type = 0x2001;
42pub const CL_GL_OBJECT_TEXTURE3D: cl_gl_object_type = 0x2002;
43pub const CL_GL_OBJECT_RENDERBUFFER: cl_gl_object_type = 0x2003;
44// #ifdef CL_VERSION_1_2
45pub const CL_GL_OBJECT_TEXTURE2D_ARRAY: cl_gl_object_type = 0x200E;
46pub const CL_GL_OBJECT_TEXTURE1D: cl_gl_object_type = 0x200F;
47pub const CL_GL_OBJECT_TEXTURE1D_ARRAY: cl_gl_object_type = 0x2010;
48pub const CL_GL_OBJECT_TEXTURE_BUFFER: cl_gl_object_type = 0x2011;
49// #endif
50
51// cl_gl_texture_info
52pub const CL_GL_TEXTURE_TARGET: cl_gl_texture_info = 0x2004;
53pub const CL_GL_MIPMAP_LEVEL: cl_gl_texture_info = 0x2005;
54// #ifdef CL_VERSION_1_2
55pub const CL_GL_NUM_SAMPLES: cl_gl_texture_info = 0x2012;
56// #endif
57
58pub type clGetGLContextInfoKHR_t = Option<
59    unsafe extern "C" fn(
60        properties: *const cl_context_properties,
61        param_name: cl_gl_context_info,
62        param_value_size: size_t,
63        param_value: *mut c_void,
64        param_value_size_ret: *mut size_t,
65    ) -> cl_int,
66>;
67pub type clGetGLContextInfoKHR_fn = clGetGLContextInfoKHR_t;
68
69pub type clCreateFromGLBuffer_t = Option<
70    unsafe extern "C" fn(
71        context: cl_context,
72        flags: cl_mem_flags,
73        bufobj: cl_GLuint,
74        errcode_ret: *mut cl_int,
75    ) -> cl_mem,
76>;
77pub type clCreateFromGLBuffer_fn = clCreateFromGLBuffer_t;
78
79pub type clCreateFromGLTexture_t = Option<
80    unsafe extern "C" fn(
81        context: cl_context,
82        flags: cl_mem_flags,
83        target: cl_GLenum,
84        miplevel: cl_GLint,
85        texture: cl_GLuint,
86        errcode_ret: *mut cl_int,
87    ) -> cl_mem,
88>;
89pub type clCreateFromGLTexture_fn = clCreateFromGLTexture_t;
90
91pub type clCreateFromGLRenderbuffer_t = Option<
92    unsafe extern "C" fn(
93        context: cl_context,
94        flags: cl_mem_flags,
95        renderbuffer: cl_GLuint,
96        errcode_ret: *mut cl_int,
97    ) -> cl_mem,
98>;
99pub type clCreateFromGLRenderbuffer_fn = clCreateFromGLRenderbuffer_t;
100
101pub type clGetGLObjectInfo_t = Option<
102    unsafe extern "C" fn(
103        memobj: cl_mem,
104        gl_object_type: *mut cl_gl_object_type,
105        gl_object_name: *mut cl_GLuint,
106    ) -> cl_int,
107>;
108pub type clGetGLObjectInfo_fn = clGetGLObjectInfo_t;
109
110pub type clGetGLTextureInfo_t = Option<
111    unsafe extern "C" fn(
112        memobj: cl_mem,
113        param_name: cl_gl_texture_info,
114        param_value_size: size_t,
115        param_value: *mut c_void,
116        param_value_size_ret: *mut size_t,
117    ) -> cl_int,
118>;
119pub type clGetGLTextureInfo_fn = clGetGLTextureInfo_t;
120
121pub type clEnqueueAcquireGLObjects_t = Option<
122    unsafe extern "C" fn(
123        command_queue: cl_command_queue,
124        num_objects: cl_uint,
125        mem_objects: *const cl_mem,
126        num_events_in_wait_list: cl_uint,
127        event_wait_list: *const cl_event,
128        event: *mut cl_event,
129    ) -> cl_int,
130>;
131pub type clEnqueueAcquireGLObjects_fn = clEnqueueAcquireGLObjects_t;
132
133pub type clEnqueueReleaseGLObjects_t = Option<
134    unsafe extern "C" fn(
135        command_queue: cl_command_queue,
136        num_objects: cl_uint,
137        mem_objects: *const cl_mem,
138        num_events_in_wait_list: cl_uint,
139        event_wait_list: *const cl_event,
140        event: *mut cl_event,
141    ) -> cl_int,
142>;
143pub type clEnqueueReleaseGLObjects_fn = clEnqueueReleaseGLObjects_t;
144
145pub type clCreateFromGLTexture2D_t = Option<
146    unsafe extern "C" fn(
147        context: cl_context,
148        flags: cl_mem_flags,
149        target: cl_GLenum,
150        miplevel: cl_GLint,
151        texture: cl_GLuint,
152        errcode_ret: *mut cl_int,
153    ) -> cl_mem,
154>;
155pub type clCreateFromGLTexture2D_fn = clCreateFromGLTexture2D_t;
156
157pub type clCreateFromGLTexture3D_t = Option<
158    unsafe extern "C" fn(
159        context: cl_context,
160        flags: cl_mem_flags,
161        target: cl_GLenum,
162        miplevel: cl_GLint,
163        texture: cl_GLuint,
164        errcode_ret: *mut cl_int,
165    ) -> cl_mem,
166>;
167pub type clCreateFromGLTexture3D_fn = clCreateFromGLTexture3D_t;
168
169pub type clCreateEventFromGLsyncKHR_t = Option<
170    unsafe extern "C" fn(
171        context: cl_context,
172        sync: cl_GLsync,
173        errcode_ret: *mut cl_int,
174    ) -> cl_event,
175>;
176pub type clCreateEventFromGLsyncKHR_fn = clCreateEventFromGLsyncKHR_t;
177
178pub type clGetSupportedGLTextureFormatsINTEL_t = Option<
179    unsafe extern "C" fn(
180        context: cl_context,
181        flags: cl_mem_flags,
182        image_type: cl_mem_object_type,
183        num_entries: cl_uint,
184        gl_formats: *mut cl_GLenum,
185        num_texture_formats: *mut cl_uint,
186    ) -> cl_int,
187>;
188pub type clGetSupportedGLTextureFormatsINTEL_fn = clGetSupportedGLTextureFormatsINTEL_t;
189
190#[cfg_attr(not(target_os = "macos"), link(name = "OpenCL"))]
191#[cfg_attr(target_os = "macos", link(name = "OpenCL", kind = "framework"))]
192#[cfg(feature = "static")]
193extern "system" {
194
195    pub fn clCreateFromGLBuffer(
196        context: cl_context,
197        flags: cl_mem_flags,
198        bufobj: cl_GLuint,
199        errcode_ret: *mut cl_int,
200    ) -> cl_mem;
201
202    #[cfg(feature = "CL_VERSION_1_2")]
203    pub fn clCreateFromGLTexture(
204        context: cl_context,
205        flags: cl_mem_flags,
206        target: cl_GLenum,
207        miplevel: cl_GLint,
208        texture: cl_GLuint,
209        errcode_ret: *mut cl_int,
210    ) -> cl_mem;
211
212    pub fn clCreateFromGLRenderbuffer(
213        context: cl_context,
214        flags: cl_mem_flags,
215        renderbuffer: cl_GLuint,
216        errcode_ret: *mut cl_int,
217    ) -> cl_mem;
218
219    pub fn clGetGLObjectInfo(
220        memobj: cl_mem,
221        gl_object_type: *mut cl_gl_object_type,
222        gl_object_name: *mut cl_GLuint,
223    ) -> cl_int;
224
225    pub fn clGetGLTextureInfo(
226        memobj: cl_mem,
227        param_name: cl_gl_texture_info,
228        param_value_size: size_t,
229        param_value: *mut c_void,
230        param_value_size_ret: *mut size_t,
231    ) -> cl_int;
232
233    pub fn clEnqueueAcquireGLObjects(
234        command_queue: cl_command_queue,
235        num_objects: cl_uint,
236        mem_objects: *const cl_mem,
237        num_events_in_wait_list: cl_uint,
238        event_wait_list: *const cl_event,
239        event: *mut cl_event,
240    ) -> cl_int;
241
242    pub fn clEnqueueReleaseGLObjects(
243        command_queue: cl_command_queue,
244        num_objects: cl_uint,
245        mem_objects: *const cl_mem,
246        num_events_in_wait_list: cl_uint,
247        event_wait_list: *const cl_event,
248        event: *mut cl_event,
249    ) -> cl_int;
250
251    // Deprecated OpenCL 1.1 APIs
252    #[cfg_attr(
253        any(
254            feature = "CL_VERSION_1_2",
255            feature = "CL_VERSION_2_0",
256            feature = "CL_VERSION_2_1",
257            feature = "CL_VERSION_2_2",
258            feature = "CL_VERSION_3_0"
259        ),
260        deprecated(
261            since = "0.1.0",
262            note = "From CL_VERSION_1_2 use clCreateFromGLTexture"
263        )
264    )]
265    pub fn clCreateFromGLTexture2D(
266        context: cl_context,
267        flags: cl_mem_flags,
268        texture_target: cl_GLenum,
269        miplevel: cl_GLint,
270        texture: cl_GLuint,
271        errcode_ret: *mut cl_int,
272    ) -> cl_mem;
273
274    #[cfg_attr(
275        any(
276            feature = "CL_VERSION_1_2",
277            feature = "CL_VERSION_2_0",
278            feature = "CL_VERSION_2_1",
279            feature = "CL_VERSION_2_2",
280            feature = "CL_VERSION_3_0"
281        ),
282        deprecated(
283            since = "0.1.0",
284            note = "From CL_VERSION_1_2 use clCreateFromGLTexture"
285        )
286    )]
287    pub fn clCreateFromGLTexture3D(
288        context: cl_context,
289        flags: cl_mem_flags,
290        texture_target: cl_GLenum,
291        miplevel: cl_GLint,
292        texture: cl_GLuint,
293        errcode_ret: *mut cl_int,
294    ) -> cl_mem;
295
296}
297
298// cl_khr_gl_sharing extension
299// * NOTE: Originally lower case: `cl_kgr_gl_sharing`
300pub const CL_KHR_GL_SHARING: cl_int = 1;
301
302// Additional Error Codes
303pub const CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR: cl_int = -1000;
304
305// cl_gl_context_info
306pub const CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR: cl_gl_context_info = 0x2006;
307pub const CL_DEVICES_FOR_GL_CONTEXT_KHR: cl_gl_context_info = 0x2007;
308
309// Additional cl_context_properties
310pub const CL_GL_CONTEXT_KHR: cl_context_properties = 0x2008;
311pub const CL_EGL_DISPLAY_KHR: cl_context_properties = 0x2009;
312pub const CL_GLX_DISPLAY_KHR: cl_context_properties = 0x200A;
313pub const CL_WGL_HDC_KHR: cl_context_properties = 0x200B;
314pub const CL_CGL_SHAREGROUP_KHR: cl_context_properties = 0x200C;
315
316// cl_khr_gl_event extension
317pub const CL_COMMAND_GL_FENCE_SYNC_OBJECT_KHR: cl_uint = 0x200D;
318
319#[cfg_attr(not(target_os = "macos"), link(name = "OpenCL"))]
320#[cfg_attr(target_os = "macos", link(name = "OpenCL", kind = "framework"))]
321#[cfg(feature = "static")]
322extern "system" {
323
324    pub fn clGetGLContextInfoKHR(
325        properties: *const cl_context_properties,
326        param_name: cl_gl_context_info,
327        param_value_size: size_t,
328        param_value: *mut c_void,
329        param_value_size_ret: *mut size_t,
330    ) -> cl_int;
331
332    pub fn clCreateEventFromGLsyncKHR(
333        context: cl_context,
334        sync: cl_GLsync,
335        errcode_ret: *mut cl_int,
336    ) -> cl_event;
337
338    pub fn clGetSupportedGLTextureFormatsINTEL(
339        context: cl_context,
340        flags: cl_mem_flags,
341        image_type: cl_mem_object_type,
342        num_entries: cl_uint,
343        gl_formats: *mut cl_GLenum,
344        num_texture_formats: *mut cl_uint,
345    ) -> cl_int;
346}