codekingpro/portable-devtools
114k
1/*
2 * Copyright 1993-2012 NVIDIA Corporation. All rights reserved.
3 *
4 * NOTICE TO LICENSEE:
5 *
6 * This source code and/or documentation ("Licensed Deliverables") are
7 * subject to NVIDIA intellectual property rights under U.S. and
8 * international Copyright laws.
9 *
10 * These Licensed Deliverables contained herein is PROPRIETARY and
11 * CONFIDENTIAL to NVIDIA and is being provided under the terms and
12 * conditions of a form of NVIDIA software license agreement by and
13 * between NVIDIA and Licensee ("License Agreement") or electronically
14 * accepted by Licensee. Notwithstanding any terms or conditions to
15 * the contrary in the License Agreement, reproduction or disclosure
16 * of the Licensed Deliverables to any third party without the express
17 * written consent of NVIDIA is prohibited.
18 *
19 * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE
20 * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE
21 * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS
22 * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND.
23 * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED
24 * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY,
25 * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE.
26 * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE
27 * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY
28 * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
29 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
30 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
31 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
32 * OF THESE LICENSED DELIVERABLES.
33 *
34 * U.S. Government End Users. These Licensed Deliverables are a
35 * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT
36 * 1995), consisting of "commercial computer software" and "commercial
37 * computer software documentation" as such terms are used in 48
38 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government
39 * only as a commercial end item. Consistent with 48 C.F.R.12.212 and
40 * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all
41 * U.S. Government End Users acquire the Licensed Deliverables with
42 * only those rights set forth herein.
43 *
44 * Any use of the Licensed Deliverables in individual and commercial
45 * software must include, in the user documentation and internal
46 * comments to the code, the above Disclaimer and U.S. Government End
47 * Users Notice.
48 */
49
50#if !defined(__CUDA_D3D11_INTEROP_H__)
51#define __CUDA_D3D11_INTEROP_H__
52
53#include "cuda_runtime_api.h"
54
55/** \cond impl_private */
56#if !defined(__dv)
57
58#if defined(__cplusplus)
59
60#define __dv(v) \
61 = v
62
63#else /* __cplusplus */
64
65#define __dv(v)
66
67#endif /* __cplusplus */
68
69#endif /* !__dv */
70/** \endcond impl_private */
71
72#include <d3d11.h>
73
74/** \cond impl_private */
75#if defined(__DOXYGEN_ONLY__) || defined(CUDA_ENABLE_DEPRECATED)
76#define __CUDA_DEPRECATED
77#elif defined(_MSC_VER)
78#define __CUDA_DEPRECATED __declspec(deprecated)
79#elif defined(__GNUC__)
80#define __CUDA_DEPRECATED __attribute__((deprecated))
81#else
82#define __CUDA_DEPRECATED
83#endif
84/** \endcond impl_private */
85
86#if defined(__cplusplus)
87extern "C" {
88#endif /* __cplusplus */
89
90/**
91 * \addtogroup CUDART_D3D11 Direct3D 11 Interoperability
92 * This section describes the Direct3D 11 interoperability functions of the CUDA
93 * runtime application programming interface. Note that mapping of Direct3D 11
94 * resources is performed with the graphics API agnostic, resource mapping
95 * interface described in \ref CUDART_INTEROP "Graphics Interopability".
96 *
97 * @{
98 */
99
100/**
101 * CUDA devices corresponding to a D3D11 device
102 */
103enum cudaD3D11DeviceList
104{
105 cudaD3D11DeviceListAll = 1, /**< The CUDA devices for all GPUs used by a D3D11 device */
106 cudaD3D11DeviceListCurrentFrame = 2, /**< The CUDA devices for the GPUs used by a D3D11 device in its currently rendering frame */
107 cudaD3D11DeviceListNextFrame = 3 /**< The CUDA devices for the GPUs to be used by a D3D11 device in the next frame */
108};
109
110/**
111 * \brief Register a Direct3D 11 resource for access by CUDA
112 *
113 * Registers the Direct3D 11 resource \p pD3DResource for access by CUDA.
114 *
115 * If this call is successful, then the application will be able to map and
116 * unmap this resource until it is unregistered through
117 * ::cudaGraphicsUnregisterResource(). Also on success, this call will increase the
118 * internal reference count on \p pD3DResource. This reference count will be
119 * decremented when this resource is unregistered through
120 * ::cudaGraphicsUnregisterResource().
121 *
122 * This call potentially has a high-overhead and should not be called every frame
123 * in interactive applications.
124 *
125 * The type of \p pD3DResource must be one of the following.
126 *
127 * - ::ID3D11Buffer: may be accessed via a device pointer
128 * - ::ID3D11Texture1D: individual subresources of the texture may be accessed via arrays
129 * - ::ID3D11Texture2D: individual subresources of the texture may be accessed via arrays
130 * - ::ID3D11Texture3D: individual subresources of the texture may be accessed via arrays
131 *
132 * The \p flags argument may be used to specify additional parameters at register
133 * time. The valid values for this parameter are
134 *
135 * - ::cudaGraphicsRegisterFlagsNone: Specifies no hints about how this
136 * resource will be used.
137 * - ::cudaGraphicsRegisterFlagsSurfaceLoadStore: Specifies that CUDA will
138 * bind this resource to a surface reference.
139 * - ::cudaGraphicsRegisterFlagsTextureGather: Specifies that CUDA will perform
140 * texture gather operations on this resource.
141 *
142 * Not all Direct3D resources of the above types may be used for
143 * interoperability with CUDA. The following are some limitations.
144 *
145 * - The primary rendertarget may not be registered with CUDA.
146 * - Textures which are not of a format which is 1, 2, or 4 channels of 8, 16,
147 * or 32-bit integer or floating-point data cannot be shared.
148 * - Surfaces of depth or stencil formats cannot be shared.
149 *
150 * A complete list of supported DXGI formats is as follows. For compactness the
151 * notation A_{B,C,D} represents A_B, A_C, and A_D.
152 * - DXGI_FORMAT_A8_UNORM
153 * - DXGI_FORMAT_B8G8R8A8_UNORM
154 * - DXGI_FORMAT_B8G8R8X8_UNORM
155 * - DXGI_FORMAT_R16_FLOAT
156 * - DXGI_FORMAT_R16G16B16A16_{FLOAT,SINT,SNORM,UINT,UNORM}
157 * - DXGI_FORMAT_R16G16_{FLOAT,SINT,SNORM,UINT,UNORM}
158 * - DXGI_FORMAT_R16_{SINT,SNORM,UINT,UNORM}
159 * - DXGI_FORMAT_R32_FLOAT
160 * - DXGI_FORMAT_R32G32B32A32_{FLOAT,SINT,UINT}
161 * - DXGI_FORMAT_R32G32_{FLOAT,SINT,UINT}
162 * - DXGI_FORMAT_R32_{SINT,UINT}
163 * - DXGI_FORMAT_R8G8B8A8_{SINT,SNORM,UINT,UNORM,UNORM_SRGB}
164 * - DXGI_FORMAT_R8G8_{SINT,SNORM,UINT,UNORM}
165 * - DXGI_FORMAT_R8_{SINT,SNORM,UINT,UNORM}
166 *
167 * If \p pD3DResource is of incorrect type or is already registered, then
168 * ::cudaErrorInvalidResourceHandle is returned.
169 * If \p pD3DResource cannot be registered, then ::cudaErrorUnknown is returned.
170 *
171 * \param resource - Pointer to returned resource handle
172 * \param pD3DResource - Direct3D resource to register
173 * \param flags - Parameters for resource registration
174 *
175 * \return
176 * ::cudaSuccess,
177 * ::cudaErrorInvalidDevice,
178 * ::cudaErrorInvalidValue,
179 * ::cudaErrorInvalidResourceHandle,
180 * ::cudaErrorUnknown
181 * \notefnerr
182 *
183 * \sa
184 * ::cudaGraphicsUnregisterResource,
185 * ::cudaGraphicsMapResources,
186 * ::cudaGraphicsSubResourceGetMappedArray,
187 * ::cudaGraphicsResourceGetMappedPointer,
188 * ::cuGraphicsD3D11RegisterResource
189 */
190extern __host__ cudaError_t CUDARTAPI cudaGraphicsD3D11RegisterResource(struct cudaGraphicsResource **resource, ID3D11Resource *pD3DResource, unsigned int flags);
191
192/**
193 * \brief Gets the device number for an adapter
194 *
195 * Returns in \p *device the CUDA-compatible device corresponding to the
196 * adapter \p pAdapter obtained from ::IDXGIFactory::EnumAdapters. This call
197 * will succeed only if a device on adapter \p pAdapter is CUDA-compatible.
198 *
199 * \param device - Returns the device corresponding to pAdapter
200 * \param pAdapter - D3D11 adapter to get device for
201 *
202 * \return
203 * ::cudaSuccess,
204 * ::cudaErrorInvalidValue,
205 * ::cudaErrorUnknown
206 * \notefnerr
207 *
208 * \sa
209 * ::cudaGraphicsUnregisterResource,
210 * ::cudaGraphicsMapResources,
211 * ::cudaGraphicsSubResourceGetMappedArray,
212 * ::cudaGraphicsResourceGetMappedPointer,
213 * ::cuD3D11GetDevice
214 */
215extern __host__ cudaError_t CUDARTAPI cudaD3D11GetDevice(int *device, IDXGIAdapter *pAdapter);
216
217/**
218 * \brief Gets the CUDA devices corresponding to a Direct3D 11 device
219 *
220 * Returns in \p *pCudaDeviceCount the number of CUDA-compatible devices corresponding
221 * to the Direct3D 11 device \p pD3D11Device.
222 * Also returns in \p *pCudaDevices at most \p cudaDeviceCount of the the CUDA-compatible devices
223 * corresponding to the Direct3D 11 device \p pD3D11Device.
224 *
225 * If any of the GPUs being used to render \p pDevice are not CUDA capable then the
226 * call will return ::cudaErrorNoDevice.
227 *
228 * \param pCudaDeviceCount - Returned number of CUDA devices corresponding to \p pD3D11Device
229 * \param pCudaDevices - Returned CUDA devices corresponding to \p pD3D11Device
230 * \param cudaDeviceCount - The size of the output device array \p pCudaDevices
231 * \param pD3D11Device - Direct3D 11 device to query for CUDA devices
232 * \param deviceList - The set of devices to return. This set may be
233 * ::cudaD3D11DeviceListAll for all devices,
234 * ::cudaD3D11DeviceListCurrentFrame for the devices used to
235 * render the current frame (in SLI), or
236 * ::cudaD3D11DeviceListNextFrame for the devices used to
237 * render the next frame (in SLI).
238 *
239 * \return
240 * ::cudaSuccess,
241 * ::cudaErrorNoDevice,
242 * ::cudaErrorUnknown
243 * \notefnerr
244 *
245 * \sa
246 * ::cudaGraphicsUnregisterResource,
247 * ::cudaGraphicsMapResources,
248 * ::cudaGraphicsSubResourceGetMappedArray,
249 * ::cudaGraphicsResourceGetMappedPointer,
250 * ::cuD3D11GetDevices
251 */
252extern __host__ cudaError_t CUDARTAPI cudaD3D11GetDevices(unsigned int *pCudaDeviceCount, int *pCudaDevices, unsigned int cudaDeviceCount, ID3D11Device *pD3D11Device, enum cudaD3D11DeviceList deviceList);
253
254/** @} */ /* END CUDART_D3D11 */
255
256/**
257 * \addtogroup CUDART_D3D11_DEPRECATED Direct3D 11 Interoperability [DEPRECATED]
258 * This section describes deprecated Direct3D 11 interoperability functions.
259 *
260 * @{
261 */
262
263/**
264 * \brief Gets the Direct3D device against which the current CUDA context was
265 * created
266 *
267 * \deprecated This function is deprecated as of CUDA 5.0.
268 *
269 * This function is deprecated and should no longer be used. It is
270 * no longer necessary to associate a CUDA device with a D3D11
271 * device in order to achieve maximum interoperability performance.
272 *
273 * \param ppD3D11Device - Returns the Direct3D device for this thread
274 *
275 * \return
276 * ::cudaSuccess,
277 * ::cudaErrorUnknown
278 * \notefnerr
279 *
280 * \sa
281 * ::cudaD3D11SetDirect3DDevice
282 */
283extern __CUDA_DEPRECATED __host__ cudaError_t CUDARTAPI cudaD3D11GetDirect3DDevice(ID3D11Device **ppD3D11Device);
284
285/**
286 * \brief Sets the Direct3D 11 device to use for interoperability with
287 * a CUDA device
288 *
289 * \deprecated This function is deprecated as of CUDA 5.0.
290 *
291 * This function is deprecated and should no longer be used. It is
292 * no longer necessary to associate a CUDA device with a D3D11
293 * device in order to achieve maximum interoperability performance.
294 *
295 * This function will immediately initialize the primary context on
296 * \p device if needed.
297 *
298 * \param pD3D11Device - Direct3D device to use for interoperability
299 * \param device - The CUDA device to use. This device must be among the devices
300 * returned when querying ::cudaD3D11DeviceListAll from ::cudaD3D11GetDevices,
301 * may be set to -1 to automatically select an appropriate CUDA device.
302 *
303 * \return
304 * ::cudaSuccess,
305 * ::cudaErrorInitializationError,
306 * ::cudaErrorInvalidValue,
307 * ::cudaErrorSetOnActiveProcess
308 * \notefnerr
309 *
310 * \sa
311 * ::cudaD3D11GetDevice,
312 * ::cudaGraphicsD3D11RegisterResource,
313 * ::cudaDeviceReset
314 */
315extern __CUDA_DEPRECATED __host__ cudaError_t CUDARTAPI cudaD3D11SetDirect3DDevice(ID3D11Device *pD3D11Device, int device __dv(-1));
316
317/** @} */ /* END CUDART_D3D11_DEPRECATED */
318
319#if defined(__cplusplus)
320}
321#endif /* __cplusplus */
322
323#undef __dv
324#undef __CUDA_DEPRECATED
325
326#endif /* __CUDA_D3D11_INTEROP_H__ */
327 