opencl_sys/
cl_d3d11.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_d3d11.h](https://github.com/KhronosGroup/OpenCL-Headers/blob/main/CL/cl_d3d11.h)
16//!
17//! `cl_d3d11.h` contains `OpenCL` extensions that provide interoperability with `Direct3D` 11.
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
22use 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::{DXGI_FORMAT, cl_int, cl_uint};
27use libc::c_void;
28
29// cl_khr_d3d11_sharing
30
31pub type cl_d3d11_device_source_khr = cl_uint;
32pub type cl_d3d11_device_set_khr = cl_uint;
33
34pub const CL_INVALID_D3D11_DEVICE_KHR: cl_int = -1006;
35pub const CL_INVALID_D3D11_RESOURCE_KHR: cl_int = -1007;
36pub const CL_D3D11_RESOURCE_ALREADY_ACQUIRED_KHR: cl_int = -1008;
37pub const CL_D3D11_RESOURCE_NOT_ACQUIRED_KHR: cl_int = -1009;
38
39pub const CL_D3D11_DEVICE_KHR: cl_d3d11_device_source_khr = 0x4019;
40pub const CL_D3D11_DXGI_ADAPTER_KHR: cl_d3d11_device_source_khr = 0x401A;
41
42pub const CL_PREFERRED_DEVICES_FOR_D3D11_KHR: cl_d3d11_device_set_khr = 0x401B;
43pub const CL_ALL_DEVICES_FOR_D3D11_KHR: cl_d3d11_device_set_khr = 0x401C;
44
45// cl_context_info
46pub const CL_CONTEXT_D3D11_DEVICE_KHR: cl_context_info = 0x401D;
47pub const CL_CONTEXT_D3D11_PREFER_SHARED_RESOURCES_KHR: cl_context_info = 0x402D;
48
49// cl_mem_info
50pub const CL_MEM_D3D11_RESOURCE_KHR: cl_mem_info = 0x401E;
51
52// cl_image_info
53pub const CL_IMAGE_D3D11_SUBRESOURCE_KHR: cl_image_info = 0x401F;
54
55// cl_command_type
56pub const CL_COMMAND_ACQUIRE_D3D11_OBJECTS_KHR: cl_command_type = 0x4020;
57pub const CL_COMMAND_RELEASE_D3D11_OBJECTS_KHR: cl_command_type = 0x4021;
58
59pub type ID3D11Buffer_ptr = *mut c_void;
60pub type ID3D11Texture2D_ptr = *mut c_void;
61pub type ID3D11Texture3D_ptr = *mut c_void;
62
63pub type clGetDeviceIDsFromD3D11KHR_t = Option<
64    unsafe extern "C" fn(
65        platform: cl_platform_id,
66        d3d_device_source: cl_d3d11_device_source_khr,
67        d3d_object: *mut c_void,
68        d3d_device_set: cl_d3d11_device_set_khr,
69        num_entries: cl_uint,
70        devices: *mut cl_device_id,
71        num_devices: *mut cl_uint,
72    ) -> cl_int,
73>;
74pub type clGetDeviceIDsFromD3D11KHR_fn = clGetDeviceIDsFromD3D11KHR_t;
75
76pub type clCreateFromD3D11BufferKHR_t = Option<
77    unsafe extern "C" fn(
78        context: cl_context,
79        flags: cl_mem_flags,
80        resource: ID3D11Buffer_ptr,
81        errcode_ret: *mut cl_int,
82    ) -> cl_mem,
83>;
84pub type clCreateFromD3D11BufferKHR_fn = clCreateFromD3D11BufferKHR_t;
85
86pub type clCreateFromD3D11Texture2DKHR_t = Option<
87    unsafe extern "C" fn(
88        context: cl_context,
89        flags: cl_mem_flags,
90        resource: ID3D11Texture2D_ptr,
91        subresource: cl_uint,
92        errcode_ret: *mut cl_int,
93    ) -> cl_mem,
94>;
95pub type clCreateFromD3D11Texture2DKHR_fn = clCreateFromD3D11Texture2DKHR_t;
96
97pub type clCreateFromD3D11Texture3DKHR_t = Option<
98    unsafe extern "C" fn(
99        context: cl_context,
100        flags: cl_mem_flags,
101        resource: ID3D11Texture3D_ptr,
102        subresource: cl_uint,
103        errcode_ret: *mut cl_int,
104    ) -> cl_mem,
105>;
106pub type clCreateFromD3D11Texture3DKHR_fn = clCreateFromD3D11Texture3DKHR_t;
107
108pub type clEnqueueAcquireD3D11ObjectsKHR_t = Option<
109    unsafe extern "C" fn(
110        command_queue: cl_command_queue,
111        num_objects: cl_uint,
112        mem_objects: *const cl_mem,
113        num_events_in_wait_list: cl_uint,
114        event_wait_list: *const cl_event,
115        event: *mut cl_event,
116    ) -> cl_int,
117>;
118pub type clEnqueueAcquireD3D11ObjectsKHR_fn = clEnqueueAcquireD3D11ObjectsKHR_t;
119
120pub type clEnqueueReleaseD3D11ObjectsKHR_t = Option<
121    unsafe extern "C" fn(
122        command_queue: cl_command_queue,
123        num_objects: cl_uint,
124        mem_objects: *const cl_mem,
125        num_events_in_wait_list: cl_uint,
126        event_wait_list: *const cl_event,
127        event: *mut cl_event,
128    ) -> cl_int,
129>;
130pub type clEnqueueReleaseD3D11ObjectsKHR_fn = clEnqueueReleaseD3D11ObjectsKHR_t;
131
132// when cl_khr_d3d11_sharing is supported
133
134pub type clGetSupportedD3D11TextureFormatsINTEL_t = Option<
135    unsafe extern "C" fn(
136        context: cl_context,
137        flags: cl_mem_flags,
138        image_type: cl_mem_object_type,
139        plane: cl_uint,
140        num_entries: cl_uint,
141        d3d11_formats: *mut DXGI_FORMAT,
142        num_surface_formats: *mut cl_uint,
143    ) -> cl_int,
144>;
145pub type clGetSupportedD3D11TextureFormatsINTEL_fn = clGetSupportedD3D11TextureFormatsINTEL_t;
146
147#[cfg_attr(not(target_os = "macos"), link(name = "OpenCL"))]
148#[cfg_attr(target_os = "macos", link(name = "OpenCL", kind = "framework"))]
149#[cfg(feature = "cl_khr_d3d11_sharing")]
150#[cfg(feature = "static")]
151unsafe extern "system" {
152
153    pub fn clGetSupportedD3D11TextureFormatsINTEL(
154        context: cl_context,
155        flags: cl_mem_flags,
156        image_type: cl_mem_object_type,
157        plane: cl_uint,
158        num_entries: cl_uint,
159        d3d11_formats: *mut DXGI_FORMAT,
160        num_surface_formats: *mut cl_uint,
161    ) -> cl_int;
162}