opencl_sys/
cl_dx9_media_sharing.rs

1// Copyright (c) 2021-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_dx9_media_sharing.h](https://github.com/KhronosGroup/OpenCL-Headers/blob/main/CL/cl_dx9_media_sharing.h)
16//!
17//! `cl_dx9_media_sharing.h` contains `OpenCL` extensions that provide interoperability with `Direct3D` 9.
18//! `OpenCL` extensions are documented in the [OpenCL-Registry](https://github.com/KhronosGroup/OpenCL-Registry)
19
20#![allow(non_camel_case_types, non_upper_case_globals)]
21
22pub use super::cl::{
23    cl_command_queue, cl_command_type, cl_context, cl_context_info, cl_device_id, cl_event,
24    cl_image_info, cl_mem, cl_mem_flags, cl_mem_info, cl_mem_object_type, cl_platform_id,
25};
26use super::cl_platform::{cl_int, cl_uint};
27use libc::c_void;
28
29// cl_khr_dx9_media_sharing
30
31pub type cl_dx9_media_adapter_type_khr = cl_uint;
32pub type cl_dx9_media_adapter_set_khr = cl_uint;
33pub type D3DFORMAT = cl_uint;
34
35pub type IDirect3DSurface9_ptr = *mut c_void;
36pub type HANDLE = *mut c_void;
37
38// #if defined(_WIN32)
39// #include <d3d9.h>
40#[repr(C)]
41#[derive(Debug, Copy, Clone)]
42pub struct cl_dx9_surface_info_khr {
43    pub resource: IDirect3DSurface9_ptr,
44    pub shared_handle: HANDLE,
45}
46// #endif
47
48pub const CL_INVALID_DX9_MEDIA_ADAPTER_KHR: cl_int = -1010;
49pub const CL_INVALID_DX9_MEDIA_SURFACE_KHR: cl_int = -1011;
50pub const CL_DX9_MEDIA_SURFACE_ALREADY_ACQUIRED_KHR: cl_int = -1012;
51pub const CL_DX9_MEDIA_SURFACE_NOT_ACQUIRED_KHR: cl_int = -1013;
52
53// cl_media_adapter_type_khr
54pub const CL_ADAPTER_D3D9_KHR: cl_dx9_media_adapter_type_khr = 0x2020;
55pub const CL_ADAPTER_D3D9EX_KHR: cl_dx9_media_adapter_type_khr = 0x2021;
56pub const CL_ADAPTER_DXVA_KHR: cl_dx9_media_adapter_type_khr = 0x2022;
57
58// cl_media_adapter_set_khr
59pub const CL_PREFERRED_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR: cl_dx9_media_adapter_set_khr = 0x2023;
60pub const CL_ALL_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR: cl_dx9_media_adapter_set_khr = 0x2024;
61
62// cl_context_info
63pub const CL_CONTEXT_ADAPTER_D3D9_KHR: cl_context_info = 0x2025;
64pub const CL_CONTEXT_ADAPTER_D3D9EX_KHR: cl_context_info = 0x2026;
65pub const CL_CONTEXT_ADAPTER_DXVA_KHR: cl_context_info = 0x2027;
66
67// cl_mem_info
68pub const CL_MEM_DX9_MEDIA_ADAPTER_TYPE_KHR: cl_mem_info = 0x2028;
69pub const CL_MEM_DX9_MEDIA_SURFACE_INFO_KHR: cl_mem_info = 0x2029;
70
71// cl_image_info
72pub const CL_IMAGE_DX9_MEDIA_PLANE_KHR: cl_image_info = 0x202A;
73
74// cl_command_type
75pub const CL_COMMAND_ACQUIRE_DX9_MEDIA_SURFACES_KHR: cl_command_type = 0x202B;
76pub const CL_COMMAND_RELEASE_DX9_MEDIA_SURFACES_KHR: cl_command_type = 0x202C;
77
78pub type clGetDeviceIDsFromDX9MediaAdapterKHR_t = Option<
79    unsafe extern "C" fn(
80        platform: cl_platform_id,
81        num_media_adapters: cl_uint,
82        media_adapter_type: *mut cl_dx9_media_adapter_type_khr,
83        media_adapters: *mut c_void,
84        media_adapter_set: cl_dx9_media_adapter_set_khr,
85        num_entries: cl_uint,
86        devices: *mut cl_device_id,
87        num_devices: *mut cl_uint,
88    ) -> cl_int,
89>;
90pub type clGetDeviceIDsFromDX9MediaAdapterKHR_fn = clGetDeviceIDsFromDX9MediaAdapterKHR_t;
91
92pub type clCreateFromDX9MediaSurfaceKHR_t = Option<
93    unsafe extern "C" fn(
94        context: cl_context,
95        flags: cl_mem_flags,
96        adapter_type: cl_dx9_media_adapter_type_khr,
97        surface_info: *mut c_void,
98        plane: cl_uint,
99        errcode_ret: *mut cl_int,
100    ) -> cl_mem,
101>;
102pub type clCreateFromDX9MediaSurfaceKHR_fn = clCreateFromDX9MediaSurfaceKHR_t;
103
104pub type clEnqueueAcquireDX9MediaSurfacesKHR_t = Option<
105    unsafe extern "C" fn(
106        command_queue: cl_command_queue,
107        num_objects: cl_uint,
108        mem_objects: *const cl_mem,
109        num_events_in_wait_list: cl_uint,
110        event_wait_list: *const cl_event,
111        event: *mut cl_event,
112    ) -> cl_int,
113>;
114pub type clEnqueueAcquireDX9MediaSurfacesKHR_fn = clEnqueueAcquireDX9MediaSurfacesKHR_t;
115
116pub type clEnqueueReleaseDX9MediaSurfacesKHR_t = Option<
117    unsafe extern "C" fn(
118        command_queue: cl_command_queue,
119        num_objects: cl_uint,
120        mem_objects: *const cl_mem,
121        num_events_in_wait_list: cl_uint,
122        event_wait_list: *const cl_event,
123        event: *mut cl_event,
124    ) -> cl_int,
125>;
126pub type clEnqueueReleaseDX9MediaSurfacesKHR_fn = clEnqueueReleaseDX9MediaSurfacesKHR_t;
127
128// cl_intel_dx9_media_sharing extension
129
130pub type cl_dx9_device_source_intel = cl_uint;
131pub type cl_dx9_device_set_intel = cl_uint;
132
133// error codes
134pub const CL_INVALID_DX9_DEVICE_INTEL: cl_int = -1010;
135pub const CL_INVALID_DX9_RESOURCE_INTEL: cl_int = -1011;
136pub const CL_DX9_RESOURCE_ALREADY_ACQUIRED_INTEL: cl_int = -1012;
137pub const CL_DX9_RESOURCE_NOT_ACQUIRED_INTEL: cl_int = -1013;
138
139// cl_dx9_device_source_intel
140pub const CL_D3D9_DEVICE_INTEL: cl_dx9_device_source_intel = 0x4022;
141pub const CL_D3D9EX_DEVICE_INTEL: cl_dx9_device_source_intel = 0x4070;
142pub const CL_DXVA_DEVICE_INTEL: cl_dx9_device_source_intel = 0x4071;
143
144// cl_dx9_device_set_intel
145pub const CL_PREFERRED_DEVICES_FOR_DX9_INTEL: cl_dx9_device_set_intel = 0x4024;
146pub const CL_ALL_DEVICES_FOR_DX9_INTEL: cl_dx9_device_set_intel = 0x4025;
147
148// cl_context_info
149pub const CL_CONTEXT_D3D9_DEVICE_INTEL: cl_context_info = 0x4026;
150pub const CL_CONTEXT_D3D9EX_DEVICE_INTEL: cl_context_info = 0x4072;
151pub const CL_CONTEXT_DXVA_DEVICE_INTEL: cl_context_info = 0x4073;
152
153// cl_mem_info
154pub const CL_MEM_DX9_RESOURCE_INTEL: cl_mem_info = 0x4027;
155pub const CL_MEM_DX9_SHARED_HANDLE_INTEL: cl_mem_info = 0x4074;
156
157// cl_image_info
158pub const CL_IMAGE_DX9_PLANE_INTEL: cl_image_info = 0x4075;
159
160// cl_command_type
161pub const CL_COMMAND_ACQUIRE_DX9_OBJECTS_INTEL: cl_command_type = 0x402A;
162pub const CL_COMMAND_RELEASE_DX9_OBJECTS_INTEL: cl_command_type = 0x402B;
163
164pub type clGetDeviceIDsFromDX9INTEL_t = Option<
165    unsafe extern "C" fn(
166        platform: cl_platform_id,
167        dx9_device_source: cl_dx9_device_source_intel,
168        dx9_object: *mut c_void,
169        dx9_device_set: cl_dx9_device_set_intel,
170        num_entries: cl_uint,
171        devices: *mut cl_device_id,
172        num_devices: *mut cl_uint,
173    ) -> cl_int,
174>;
175pub type clGetDeviceIDsFromDX9INTEL_fn = clGetDeviceIDsFromDX9INTEL_t;
176
177pub type clCreateFromDX9MediaSurfaceINTEL_t = Option<
178    unsafe extern "C" fn(
179        context: cl_context,
180        flags: cl_mem_flags,
181        resource: IDirect3DSurface9_ptr,
182        shared_handle: HANDLE,
183        plane: cl_uint,
184        errcode_ret: *mut cl_int,
185    ) -> cl_mem,
186>;
187pub type clCreateFromDX9MediaSurfaceINTEL_fn = clCreateFromDX9MediaSurfaceINTEL_t;
188
189pub type clEnqueueAcquireDX9ObjectsINTEL_t = Option<
190    unsafe extern "C" fn(
191        command_queue: cl_command_queue,
192        num_objects: cl_uint,
193        mem_objects: *const cl_mem,
194        num_events_in_wait_list: cl_uint,
195        event_wait_list: *const cl_event,
196        event: *mut cl_event,
197    ) -> cl_int,
198>;
199pub type clEnqueueAcquireDX9ObjectsINTEL_fn = clEnqueueAcquireDX9ObjectsINTEL_t;
200
201pub type clEnqueueReleaseDX9ObjectsINTEL_t = Option<
202    unsafe extern "C" fn(
203        command_queue: cl_command_queue,
204        num_objects: cl_uint,
205        mem_objects: *const cl_mem,
206        num_events_in_wait_list: cl_uint,
207        event_wait_list: *const cl_event,
208        event: *mut cl_event,
209    ) -> cl_int,
210>;
211pub type clEnqueueReleaseDX9ObjectsINTEL_fn = clEnqueueReleaseDX9ObjectsINTEL_t;
212
213pub type clGetSupportedDX9MediaSurfaceFormatsINTEL_t = Option<
214    unsafe extern "C" fn(
215        context: cl_context,
216        flags: cl_mem_flags,
217        image_type: cl_mem_object_type,
218        plane: cl_uint,
219        num_entries: cl_uint,
220        dx9_formats: *mut D3DFORMAT,
221        num_surface_formats: *mut cl_uint,
222    ) -> cl_int,
223>;
224pub type clGetSupportedDX9MediaSurfaceFormatsINTEL_fn = clGetSupportedDX9MediaSurfaceFormatsINTEL_t;
225
226#[cfg_attr(not(target_os = "macos"), link(name = "OpenCL"))]
227#[cfg_attr(target_os = "macos", link(name = "OpenCL", kind = "framework"))]
228#[cfg(feature = "cl_intel_dx9_media_sharing")]
229#[cfg(feature = "static")]
230unsafe extern "system" {
231
232    pub fn clGetDeviceIDsFromDX9INTEL(
233        platform: cl_platform_id,
234        dx9_device_source: cl_dx9_device_source_intel,
235        dx9_object: *mut c_void,
236        dx9_device_set: cl_dx9_device_set_intel,
237        num_entries: cl_uint,
238        devices: *mut cl_device_id,
239        num_devices: *mut cl_uint,
240    ) -> cl_int;
241
242    pub fn clCreateFromDX9MediaSurfaceINTEL(
243        context: cl_context,
244        flags: cl_mem_flags,
245        resource: IDirect3DSurface9_ptr,
246        sharedHandle: HANDLE,
247        plane: cl_uint,
248        errcode_ret: *mut cl_int,
249    ) -> cl_mem;
250
251    pub fn clEnqueueAcquireDX9ObjectsINTEL(
252        command_queue: cl_command_queue,
253        num_objects: cl_uint,
254        mem_objects: *const cl_mem,
255        num_events_in_wait_list: cl_uint,
256        event_wait_list: *const cl_event,
257        event: *mut cl_event,
258    ) -> cl_int;
259
260    pub fn clEnqueueReleaseDX9ObjectsINTEL(
261        command_queue: cl_command_queue,
262        num_objects: cl_uint,
263        mem_objects: *const cl_mem,
264        num_events_in_wait_list: cl_uint,
265        event_wait_list: *const cl_event,
266        event: *mut cl_event,
267    ) -> cl_int;
268}
269
270// cl_intel_sharing_format_query_dx9
271
272#[cfg_attr(not(target_os = "macos"), link(name = "OpenCL"))]
273#[cfg_attr(target_os = "macos", link(name = "OpenCL", kind = "framework"))]
274#[cfg(any(
275    feature = "cl_khr_dx9_media_sharing",
276    feature = "cl_intel_dx9_media_sharing"
277))]
278#[cfg(feature = "static")]
279unsafe extern "system" {
280
281    pub fn clGetSupportedDX9MediaSurfaceFormatsINTEL(
282        context: cl_context,
283        flags: cl_mem_flags,
284        image_type: cl_mem_object_type,
285        plane: cl_uint,
286        num_entries: cl_uint,
287        dx9_formats: *mut D3DFORMAT,
288        num_surface_formats: *mut cl_uint,
289    ) -> cl_int;
290}