6.32. 图形互操作性

本节介绍低级别CUDA驱动程序应用程序编程接口的图形互操作性功能。

Functions

CUresult cuGraphicsMapResources ( unsigned int  count, CUgraphicsResource* resources, CUstream hStream )
Map graphics resources for access by CUDA.
CUresult cuGraphicsResourceGetMappedMipmappedArray ( CUmipmappedArray* pMipmappedArray, CUgraphicsResource resource )
Get a mipmapped array through which to access a mapped graphics resource.
CUresult cuGraphicsResourceGetMappedPointer ( CUdeviceptr* pDevPtr, size_t* pSize, CUgraphicsResource resource )
Get a device pointer through which to access a mapped graphics resource.
CUresult cuGraphicsResourceSetMapFlags ( CUgraphicsResource resource, unsigned int  flags )
Set usage flags for mapping a graphics resource.
CUresult cuGraphicsSubResourceGetMappedArray ( CUarray* pArray, CUgraphicsResource resource, unsigned int  arrayIndex, unsigned int  mipLevel )
Get an array through which to access a subresource of a mapped graphics resource.
CUresult cuGraphicsUnmapResources ( unsigned int  count, CUgraphicsResource* resources, CUstream hStream )
Unmap graphics resources.
CUresult cuGraphicsUnregisterResource ( CUgraphicsResource resource )
Unregisters a graphics resource for access by CUDA.

Functions

CUresult cuGraphicsMapResources ( unsigned int  count, CUgraphicsResource* resources, CUstream hStream )
映射图形资源以供CUDA访问。
参数
count
- Number of resources to map
resources
- Resources to map for CUDA usage
hStream
- Stream with which to synchronize
描述

映射resources中的count个图形资源以供CUDA访问。

resources中的资源在被取消映射之前,可以被CUDA访问。在CUDA映射期间,注册resources的图形API不应访问任何资源。如果应用程序这样做,结果将是未定义的。

该函数提供同步保证,确保在cuGraphicsMapResources()之前发出的所有图形调用都会完成,然后才会开始执行在stream中后续发出的任何CUDA工作。

如果resources包含任何重复条目,则返回CUDA_ERROR_INVALID_HANDLE。如果resources中的任何资源当前已映射供CUDA访问,则返回CUDA_ERROR_ALREADY_MAPPED

Note:
  • 此函数使用标准的默认流语义。

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

另请参阅:

cuGraphicsResourceGetMappedPointer, cuGraphicsSubResourceGetMappedArray, cuGraphicsUnmapResources, cudaGraphicsMapResources

CUresult cuGraphicsResourceGetMappedMipmappedArray ( CUmipmappedArray* pMipmappedArray, CUgraphicsResource resource )
获取一个mipmapped数组,用于访问映射的图形资源。
参数
pMipmappedArray
- Returned mipmapped array through which resource may be accessed
resource
- Mapped resource to access
描述

*pMipmappedArray中返回一个mipmapped数组,通过该数组可以访问映射的图形资源resource。每次映射resource时,*pMipmappedArray中设置的值可能会发生变化。

如果resource不是纹理,则无法通过mipmapped数组访问,并返回CUDA_ERROR_NOT_MAPPED_AS_ARRAY。如果resource未被映射,则返回CUDA_ERROR_NOT_MAPPED

Note:

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

另请参阅:

cuGraphicsResourceGetMappedPointer, cudaGraphicsResourceGetMappedMipmappedArray

CUresult cuGraphicsResourceGetMappedPointer ( CUdeviceptr* pDevPtr, size_t* pSize, CUgraphicsResource resource )
获取一个设备指针,用于访问映射的图形资源。
参数
pDevPtr
- Returned pointer through which resource may be accessed
pSize
- Returned size of the buffer accessible starting at *pPointer
resource
- Mapped resource to access
描述

*pDevPtr中返回一个指针,通过该指针可以访问映射的图形资源resource。在pSize中返回可从该指针访问的内存大小(以字节为单位)。每次映射resource时,pPointer中设置的值可能会发生变化。

如果resource不是缓冲区,则无法通过指针访问,并返回CUDA_ERROR_NOT_MAPPED_AS_POINTER。如果resource未被映射,则返回CUDA_ERROR_NOT_MAPPED

Note:

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

另请参阅:

cuGraphicsMapResources, cuGraphicsSubResourceGetMappedArray, cudaGraphicsResourceGetMappedPointer

CUresult cuGraphicsResourceSetMapFlags ( CUgraphicsResource resource, unsigned int  flags )
设置用于映射图形资源的使用标志。
参数
resource
- Registered resource to set flags for
flags
- Parameters for resource mapping
描述

设置flags以映射图形资源resource

flags的更改将在下次映射resource时生效。flags参数可以是以下任意一种:

  • CU_GRAPHICS_MAP_RESOURCE_FLAGS_NONE: 指定不提供关于该资源使用方式的提示。因此默认假设该资源将被CUDA内核进行读写操作。这是默认值。

  • CU_GRAPHICS_MAP_RESOURCE_FLAGS_READONLY: 指定访问该资源的CUDA内核将不会对该资源进行写入操作。

  • CU_GRAPHICS_MAP_RESOURCE_FLAGS_WRITEDISCARD: 指定访问此资源的CUDA内核将不会读取该资源,而是会覆盖资源的全部内容,因此资源中先前存储的所有数据都将被丢弃。

如果resource当前已映射供CUDA访问,则返回CUDA_ERROR_ALREADY_MAPPED。如果flags不是上述值之一,则返回CUDA_ERROR_INVALID_VALUE

Note:

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

另请参阅:

cuGraphicsMapResources, cudaGraphicsResourceSetMapFlags

CUresult cuGraphicsSubResourceGetMappedArray ( CUarray* pArray, CUgraphicsResource resource, unsigned int  arrayIndex, unsigned int  mipLevel )
获取一个数组,用于访问映射图形资源的子资源。
参数
pArray
- Returned array through which a subresource of resource may be accessed
resource
- Mapped resource to access
arrayIndex
- Array index for array textures or cubemap face index as defined by CUarray_cubemap_face for cubemap textures for the subresource to access
mipLevel
- Mipmap level for the subresource to access
描述

*pArray中返回一个数组,通过该数组可以访问映射图形资源resource中对应于数组索引arrayIndex和mipmap级别mipLevel的子资源。每次映射resource时,*pArray中设置的值可能会发生变化。

如果resource不是纹理,则无法通过数组访问,并返回CUDA_ERROR_NOT_MAPPED_AS_ARRAY。如果arrayIndex不是resource的有效数组索引,则返回CUDA_ERROR_INVALID_VALUE。如果mipLevel不是resource的有效mipmap级别,则返回CUDA_ERROR_INVALID_VALUE。如果resource未被映射,则返回CUDA_ERROR_NOT_MAPPED

Note:

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

另请参阅:

cuGraphicsResourceGetMappedPointer, cudaGraphicsSubResourceGetMappedArray

CUresult cuGraphicsUnmapResources ( unsigned int  count, CUgraphicsResource* resources, CUstream hStream )
解除图形资源映射。
参数
count
- Number of resources to unmap
resources
- Resources to unmap
hStream
- Stream with which to synchronize
描述

解除映射resources中的count个图形资源。

一旦解除映射,resources中的资源在重新映射之前将无法被CUDA访问。

此函数提供同步保证,确保在cuGraphicsUnmapResources()之前通过stream发出的任何CUDA工作都将在后续图形工作开始前完成。

如果resources包含任何重复条目,则返回CUDA_ERROR_INVALID_HANDLE。如果resources中有任何资源当前未被CUDA映射以供访问,则返回CUDA_ERROR_NOT_MAPPED

Note:
  • 此函数使用标准的默认流语义。

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

另请参阅:

cuGraphicsMapResources, cudaGraphicsUnmapResources

CUresult cuGraphicsUnregisterResource ( CUgraphicsResource resource )
注销一个图形资源,使其不再被CUDA访问。
参数
resource
- Resource to unregister
描述

注销图形资源resource,使其无法被CUDA访问,除非重新注册。

如果resource无效,则返回CUDA_ERROR_INVALID_HANDLE

Note:

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

另请参阅:

cuGraphicsD3D9RegisterResource, cuGraphicsD3D10RegisterResource, cuGraphicsD3D11RegisterResource, cuGraphicsGLRegisterBuffer, cuGraphicsGLRegisterImage, cudaGraphicsUnregisterResource