6.42. Direct3D 11 互操作性

本节介绍低级CUDA驱动程序应用程序编程接口中与Direct3D 11互操作的功能。 请注意,Direct3D 11资源的映射是通过图形API无关的资源映射接口执行的,该接口在图形互操作性中有详细描述。

模块

 

枚举

enum CUd3d11DeviceList

Functions

CUresult cuD3D11GetDevice ( CUdevice* pCudaDevice, IDXGIAdapter* pAdapter )
Gets the CUDA device corresponding to a display adapter.
CUresult cuD3D11GetDevices ( unsigned int* pCudaDeviceCount, CUdevice* pCudaDevices, unsigned int  cudaDeviceCount, ID3D11Device* pD3D11Device, CUd3d11DeviceList deviceList )
Gets the CUDA devices corresponding to a Direct3D 11 device.
CUresult cuGraphicsD3D11RegisterResource ( CUgraphicsResource* pCudaResource, ID3D11Resource* pD3DResource, unsigned int  Flags )
Register a Direct3D 11 resource for access by CUDA.

枚举

enum CUd3d11DeviceList

与D3D11设备对应的CUDA设备

数值
CU_D3D11_DEVICE_LIST_ALL = 0x01
The CUDA devices for all GPUs used by a D3D11 device
CU_D3D11_DEVICE_LIST_CURRENT_FRAME = 0x02
The CUDA devices for the GPUs used by a D3D11 device in its currently rendering frame
CU_D3D11_DEVICE_LIST_NEXT_FRAME = 0x03
The CUDA devices for the GPUs to be used by a D3D11 device in the next frame

Functions

CUresult cuD3D11GetDevice ( CUdevice* pCudaDevice, IDXGIAdapter* pAdapter )
获取与显示适配器对应的CUDA设备。
参数
pCudaDevice
- Returned CUDA device corresponding to pAdapter
pAdapter
- Adapter to query for CUDA device
描述

*pCudaDevice中返回与从IDXGIFactory::EnumAdapters获取的适配器pAdapter对应的CUDA兼容设备。

如果pAdapter上没有设备兼容CUDA,该调用将返回CUDA_ERROR_NO_DEVICE

Note:

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

另请参阅:

cuD3D11GetDevices, cudaD3D11GetDevice

CUresult cuD3D11GetDevices ( unsigned int* pCudaDeviceCount, CUdevice* pCudaDevices, unsigned int  cudaDeviceCount, ID3D11Device* pD3D11Device, CUd3d11DeviceList 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 CU_D3D11_DEVICE_LIST_ALL for all devices, CU_D3D11_DEVICE_LIST_CURRENT_FRAME for the devices used to render the current frame (in SLI), or CU_D3D11_DEVICE_LIST_NEXT_FRAME 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,则该调用将返回CUDA_ERROR_NO_DEVICE

Note:

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

另请参阅:

cuD3D11GetDevice, cudaD3D11GetDevices

CUresult cuGraphicsD3D11RegisterResource ( CUgraphicsResource* pCudaResource, ID3D11Resource* pD3DResource, unsigned int  Flags )
注册一个Direct3D 11资源以便通过CUDA访问。
参数
pCudaResource
- Returned graphics resource handle
pD3DResource
- Direct3D resource to register
Flags
- Parameters for resource registration
描述

将Direct3D 11资源pD3DResource注册为可由CUDA访问,并在pCudaResource中返回一个指向pD3Dresource的CUDA句柄。返回的pCudaResource句柄可用于映射和取消映射该资源,直到它被注销为止。调用成功后,会增加pD3DResource的内部引用计数。当通过cuGraphicsUnregisterResource()注销该资源时,此引用计数将递减。

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

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

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

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

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

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

Flags参数可用于在注册时指定附加参数。该参数的有效值为

  • CU_GRAPHICS_REGISTER_FLAGS_NONE: 指定不提供关于该资源使用方式的任何提示。

  • CU_GRAPHICS_REGISTER_FLAGS_SURFACE_LDST: 指定CUDA将把此资源绑定到表面引用。

  • CU_GRAPHICS_REGISTER_FLAGS_TEXTURE_GATHER: 指定CUDA将对此资源执行纹理收集操作。

并非所有上述类型的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类型不正确或已被注册,则返回CUDA_ERROR_INVALID_HANDLE。如果pD3DResource无法注册,则返回CUDA_ERROR_UNKNOWN。如果Flags不是上述指定值之一,则返回CUDA_ERROR_INVALID_VALUE

Note:

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

另请参阅:

cuGraphicsUnregisterResource, cuGraphicsMapResources, cuGraphicsSubResourceGetMappedArray, cuGraphicsResourceGetMappedPointer, cudaGraphicsD3D11RegisterResource

Direct3D 11 互操作性 [已弃用]