6.20. Direct3D 10 互操作性

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

枚举

enum cudaD3D10DeviceList

Functions

__host__cudaError_t cudaD3D10GetDevice ( int* device, IDXGIAdapter* pAdapter )
Gets the device number for an adapter.
__host__cudaError_t cudaD3D10GetDevices ( unsigned int* pCudaDeviceCount, int* pCudaDevices, unsigned int  cudaDeviceCount, ID3D10Device* pD3D10Device, cudaD3D10DeviceList deviceList )
Gets the CUDA devices corresponding to a Direct3D 10 device.
__host__cudaError_t cudaGraphicsD3D10RegisterResource ( cudaGraphicsResource** resource, ID3D10Resource* pD3DResource, unsigned int  flags )
Registers a Direct3D 10 resource for access by CUDA.

枚举

enum cudaD3D10DeviceList

与D3D10设备对应的CUDA设备

数值
cudaD3D10DeviceListAll = 1
The CUDA devices for all GPUs used by a D3D10 device
cudaD3D10DeviceListCurrentFrame = 2
The CUDA devices for the GPUs used by a D3D10 device in its currently rendering frame
cudaD3D10DeviceListNextFrame = 3
The CUDA devices for the GPUs to be used by a D3D10 device in the next frame

Functions

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

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

Note:

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

另请参阅:

cudaGraphicsD3D10RegisterResource, cuD3D10GetDevice

__host__cudaError_t cudaD3D10GetDevices ( unsigned int* pCudaDeviceCount, int* pCudaDevices, unsigned int  cudaDeviceCount, ID3D10Device* pD3D10Device, cudaD3D10DeviceList deviceList )
获取与Direct3D 10设备对应的CUDA设备。
参数
pCudaDeviceCount
- Returned number of CUDA devices corresponding to pD3D10Device
pCudaDevices
- Returned CUDA devices corresponding to pD3D10Device
cudaDeviceCount
- The size of the output device array pCudaDevices
pD3D10Device
- Direct3D 10 device to query for CUDA devices
deviceList
- The set of devices to return. This set may be cudaD3D10DeviceListAll for all devices, cudaD3D10DeviceListCurrentFrame for the devices used to render the current frame (in SLI), or cudaD3D10DeviceListNextFrame for the devices used to render the next frame (in SLI).
描述

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

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

Note:

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

另请参阅:

cudaGraphicsUnregisterResource, cudaGraphicsMapResources, cudaGraphicsSubResourceGetMappedArray, cudaGraphicsResourceGetMappedPointer, cuD3D10GetDevices

__host__cudaError_t cudaGraphicsD3D10RegisterResource ( cudaGraphicsResource** resource, ID3D10Resource* pD3DResource, unsigned int  flags )
注册一个Direct3D 10资源以供CUDA访问。
参数
resource
- Pointer to returned resource handle
pD3DResource
- Direct3D resource to register
flags
- Parameters for resource registration
描述

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

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

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

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

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

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

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

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

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, cuGraphicsD3D10RegisterResource