cl3/
d3d11.rs

1// Copyright (c) 2021-2025 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`
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(clippy::missing_safety_doc)]
21
22pub use opencl_sys::cl_d3d11::*;
23pub use opencl_sys::{
24    CL_INVALID_VALUE, CL_SUCCESS, cl_context, cl_int, cl_mem_flags, cl_mem_object_type, cl_uint,
25};
26
27#[allow(unused_imports)]
28use libc::c_void;
29#[allow(unused_imports)]
30use std::ptr;
31
32#[cfg(any(feature = "cl_khr_d3d11_sharing", feature = "dynamic"))]
33pub unsafe fn get_supported_d3d11_texture_formats_intel(
34    context: cl_context,
35    flags: cl_mem_flags,
36    image_type: cl_mem_object_type,
37    plane: cl_uint,
38) -> Result<Vec<cl_uint>, cl_int> {
39    let mut count: cl_uint = 0;
40    let status: cl_int = cl_call!(cl_d3d11::clGetSupportedD3D11TextureFormatsINTEL(
41        context,
42        flags,
43        image_type,
44        plane,
45        0,
46        ptr::null_mut(),
47        &raw mut count,
48    ));
49    if CL_SUCCESS != status {
50        Err(status)
51    } else if 0 < count {
52        // Get the d3d11_formats.
53        let len = count as usize;
54        let mut ids: Vec<cl_uint> = Vec::with_capacity(len);
55        let status: cl_int = cl_call!(cl_d3d11::clGetSupportedD3D11TextureFormatsINTEL(
56            context,
57            flags,
58            image_type,
59            plane,
60            count,
61            ids.as_mut_ptr(),
62            ptr::null_mut(),
63        ));
64        if CL_SUCCESS == status {
65            Ok(ids)
66        } else {
67            Err(status)
68        }
69    } else {
70        Ok(Vec::default())
71    }
72}