6.22. Direct3D 11 互操作性

本节介绍CUDA运行时应用程序编程接口中与Direct3D 11互操作的函数。需要注意的是,Direct3D 11资源的映射是通过图形API无关的资源映射接口实现的,该接口在图形互操作性中有详细描述。

枚举

enum cudaD3D11DeviceList

Functions

__host__cudaError_t cudaD3D11GetDevice ( int* device, IDXGIAdapter* pAdapter )
Gets the device number for an adapter.
__host__cudaError_t cudaD3D11GetDevices ( unsigned int* pCudaDeviceCount, int* pCudaDevices, unsigned int  cudaDeviceCount, ID3D11Device* pD3D11Device, cudaD3D11DeviceList deviceList )
Gets the CUDA devices corresponding to a Direct3D 11 device.
__host__cudaError_t cudaGraphicsD3D11RegisterResource ( cudaGraphicsResource** resource, ID3D11Resource* pD3DResource, unsigned int  flags )
Register a Direct3D 11 resource for access by CUDA.

枚举

enum cudaD3D11DeviceList

与D3D11设备对应的CUDA设备

数值
cudaD3D11DeviceListAll = 1
The CUDA devices for all GPUs used by a D3D11 device
cudaD3D11DeviceListCurrentFrame = 2
The CUDA devices for the GPUs used by a D3D11 device in its currently rendering frame
cudaD3D11DeviceListNextFrame = 3
The CUDA devices for the GPUs to be used by a D3D11 device in the next frame

Functions

__host__cudaError_t cudaD3D11GetDevice ( int* device, IDXGIAdapter* pAdapter )
获取适配器的设备编号。
参数
device
- Returns the device corresponding to pAdapter
pAdapter
- D3D11 adapter to get device for
描述

*device中返回与从IDXGIFactory::EnumAdapters获取的适配器pAdapter对应的CUDA兼容设备。仅当适配器pAdapter上的设备支持CUDA时,此调用才会成功。

Note:

请注意,此函数也可能返回之前异步启动的错误代码。

另请参阅:

cudaGraphicsUnregisterResource, cudaGraphicsMapResources, cudaGraphicsSubResourceGetMappedArray, cudaGraphicsResourceGetMappedPointer, cuD3D11GetDevice

__host__cudaError_t cudaD3D11GetDevices ( unsigned int* pCudaDeviceCount, int* pCudaDevices, unsigned int  cudaDeviceCount, ID3D11Device* pD3D11Device, cudaD3D11DeviceList deviceList )
获取与Direct3D 11设备对应的CUDA设备。
参数
pCudaDeviceCount
- Returned number of CUDA devices corresponding to pD3D11Device
pCudaDevices
- Returned CUDA devices corresponding to pD3D11Device
cudaDeviceCount
- The size of the output device array pCudaDevices
pD3D11Device
- Direct3D 11 device to query for CUDA devices
deviceList
- The set of devices to return. This set may be cudaD3D11DeviceListAll for all devices, cudaD3D11DeviceListCurrentFrame for the devices used to render the current frame (in SLI), or cudaD3D11DeviceListNextFrame for the devices used to render the next frame (in SLI).
描述

*pCudaDeviceCount中返回与Direct3D 11设备pD3D11Device对应的CUDA兼容设备数量。同时在*pCudaDevices中最多返回cudaDeviceCount个与Direct3D 11设备pD3D11Device对应的CUDA兼容设备。

如果用于渲染pDevice的GPU中有不支持CUDA的,则该调用将返回cudaErrorNoDevice

Note:

请注意,此函数也可能返回之前异步启动的错误代码。

另请参阅:

cudaGraphicsUnregisterResource, cudaGraphicsMapResources, cudaGraphicsSubResourceGetMappedArray, cudaGraphicsResourceGetMappedPointer, cuD3D11GetDevices

__host__cudaError_t cudaGraphicsD3D11RegisterResource ( cudaGraphicsResource** resource, ID3D11Resource* pD3DResource, unsigned int  flags )
注册一个Direct3D 11资源以便通过CUDA访问。
参数
resource
- Pointer to returned resource handle
pD3DResource
- Direct3D resource to register
flags
- Parameters for resource registration
描述

注册Direct3D 11资源pD3DResource以便CUDA访问。

如果此调用成功,应用程序将能够映射和取消映射此资源,直到通过cudaGraphicsUnregisterResource()取消注册为止。此外,在成功时,此调用将增加pD3DResource的内部引用计数。当通过cudaGraphicsUnregisterResource()取消注册此资源时,该引用计数将递减。

此调用可能具有较高的开销,在交互式应用中不应每帧都调用。

pD3DResource的类型必须是以下之一。

  • ID3D11Buffer: 可以通过设备指针访问

  • ID3D11Texture1D: 可以通过数组访问纹理的各个子资源

  • ID3D11Texture2D: 可以通过数组访问纹理的各个子资源

  • ID3D11Texture3D: 可以通过数组访问纹理的各个子资源

flags参数可用于在注册时指定额外参数。该参数的有效值为

并非所有上述类型的Direct3D资源都能用于与CUDA的互操作性。以下是一些限制。

  • 主渲染目标可能未在CUDA中注册。

  • 无法共享那些格式不是1、2或4通道的8位、16位或32位整数或浮点数据的纹理。

  • 深度或模板格式的表面无法共享。

以下是支持的DXGI格式的完整列表。为简洁起见,A_{B,C,D}表示A_B、A_C和A_D。

  • DXGI_FORMAT_A8_UNORM

  • DXGI_FORMAT_B8G8R8A8_UNORM

  • DXGI_FORMAT_B8G8R8X8_UNORM

  • DXGI_FORMAT_R16_FLOAT

  • DXGI_FORMAT_R16G16B16A16_{FLOAT,SINT,SNORM,UINT,UNORM}

  • DXGI_FORMAT_R16G16_{FLOAT,SINT,SNORM,UINT,UNORM}

  • DXGI_FORMAT_R16_{SINT,SNORM,UINT,UNORM}

  • DXGI_FORMAT_R32_FLOAT

  • DXGI_FORMAT_R32G32B32A32_{FLOAT,SINT,UINT}

  • DXGI_FORMAT_R32G32_{FLOAT,SINT,UINT}

  • DXGI_FORMAT_R32_{SINT,UINT}

  • DXGI_FORMAT_R8G8B8A8_{SINT,SNORM,UINT,UNORM,UNORM_SRGB}

  • DXGI_FORMAT_R8G8_{SINT,SNORM,UINT,UNORM}

  • DXGI_FORMAT_R8_{SINT,SNORM,UINT,UNORM}

如果pD3DResource类型不正确或已被注册,则返回cudaErrorInvalidResourceHandle。如果pD3DResource无法注册,则返回cudaErrorUnknown

Note:

请注意,此函数也可能返回之前异步启动的错误代码。

另请参阅:

cudaGraphicsUnregisterResource, cudaGraphicsMapResources, cudaGraphicsSubResourceGetMappedArray, cudaGraphicsResourceGetMappedPointer, cuGraphicsD3D11RegisterResource