6.16. OpenGL 互操作性

本节介绍CUDA运行时应用程序编程接口中与OpenGL互操作相关的功能。需要注意的是,OpenGL资源的映射是通过图形API无关的资源映射接口实现的,具体描述请参见Graphics Interopability

枚举

enum cudaGLDeviceList

Functions

__host__cudaError_t cudaGLGetDevices ( unsigned int* pCudaDeviceCount, int* pCudaDevices, unsigned int  cudaDeviceCount, cudaGLDeviceList deviceList )
Gets the CUDA devices associated with the current OpenGL context.
__host__cudaError_t cudaGraphicsGLRegisterBuffer ( cudaGraphicsResource** resource, GLuint buffer, unsigned int  flags )
Registers an OpenGL buffer object.
__host__cudaError_t cudaGraphicsGLRegisterImage ( cudaGraphicsResource** resource, GLuint image, GLenum target, unsigned int  flags )
Register an OpenGL texture or renderbuffer object.
__host__cudaError_t cudaWGLGetDevice ( int* device, HGPUNV hGpu )
Gets the CUDA device associated with hGpu.

枚举

enum cudaGLDeviceList

与当前OpenGL上下文对应的CUDA设备

数值
cudaGLDeviceListAll = 1
The CUDA devices for all GPUs used by the current OpenGL context
cudaGLDeviceListCurrentFrame = 2
The CUDA devices for the GPUs used by the current OpenGL context in its currently rendering frame
cudaGLDeviceListNextFrame = 3
The CUDA devices for the GPUs to be used by the current OpenGL context in the next frame

Functions

__host__cudaError_t cudaGLGetDevices ( unsigned int* pCudaDeviceCount, int* pCudaDevices, unsigned int  cudaDeviceCount, cudaGLDeviceList deviceList )
获取与当前OpenGL上下文关联的CUDA设备。
参数
pCudaDeviceCount
- Returned number of CUDA devices corresponding to the current OpenGL context
pCudaDevices
- Returned CUDA devices corresponding to the current OpenGL context
cudaDeviceCount
- The size of the output device array pCudaDevices
deviceList
- The set of devices to return. This set may be cudaGLDeviceListAll for all devices, cudaGLDeviceListCurrentFrame for the devices used to render the current frame (in SLI), or cudaGLDeviceListNextFrame for the devices used to render the next frame (in SLI).
描述

*pCudaDeviceCount中返回与当前OpenGL上下文对应的CUDA兼容设备数量。同时在*pCudaDevices中最多返回cudaDeviceCount个与当前OpenGL上下文对应的CUDA兼容设备。如果当前OpenGL上下文使用的任何GPU不支持CUDA,则该调用将返回cudaErrorNoDevice

Note:
  • 此功能在Mac OS X上不受支持。

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

另请参阅:

cudaGraphicsUnregisterResource, cudaGraphicsMapResources, cudaGraphicsSubResourceGetMappedArray, cudaGraphicsResourceGetMappedPointer, cuGLGetDevices

__host__cudaError_t cudaGraphicsGLRegisterBuffer ( cudaGraphicsResource** resource, GLuint buffer, unsigned int  flags )
注册一个OpenGL缓冲对象。
参数
resource
- Pointer to the returned object handle
buffer
- name of buffer object to be registered
flags
- Register flags
描述

注册由buffer指定的缓冲区对象以供CUDA访问。注册对象的句柄将作为resource返回。注册标志flags用于指定预期用途,如下所示:

Note:

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

另请参阅:

cudaGraphicsUnregisterResource, cudaGraphicsMapResources, cudaGraphicsResourceGetMappedPointer, cuGraphicsGLRegisterBuffer

__host__cudaError_t cudaGraphicsGLRegisterImage ( cudaGraphicsResource** resource, GLuint image, GLenum target, unsigned int  flags )
注册一个OpenGL纹理或渲染缓冲对象。
参数
resource
- Pointer to the returned object handle
image
- name of texture or renderbuffer object to be registered
target
- Identifies the type of object specified by image
flags
- Register flags
描述

image指定的纹理或渲染缓冲对象注册为可供CUDA访问。注册后的对象句柄将作为resource返回。

target 必须与对象类型匹配,且必须是 GL_TEXTURE_2D、GL_TEXTURE_RECTANGLE、GL_TEXTURE_CUBE_MAP、GL_TEXTURE_3D、GL_TEXTURE_2D_ARRAY 或 GL_RENDERBUFFER 之一。

注册标志flags用于指定预期用途,如下所示:

支持以下图像格式。为简洁起见,列表已做缩写。例如,{GL_R, GL_RG} X {8, 16}将展开为以下4种格式:{GL_R8, GL_R16, GL_RG8, GL_RG16}:

  • GL_RED, GL_RG, GL_RGBA, GL_LUMINANCE, GL_ALPHA, GL_LUMINANCE_ALPHA, GL_INTENSITY

  • {GL_R, GL_RG, GL_RGBA} X {8, 16, 16F, 32F, 8UI, 16UI, 32UI, 8I, 16I, 32I}

  • {GL_LUMINANCE, GL_ALPHA, GL_LUMINANCE_ALPHA, GL_INTENSITY} X {8, 16, 16F_ARB, 32F_ARB, 8UI_EXT, 16UI_EXT, 32UI_EXT, 8I_EXT, 16I_EXT, 32I_EXT}

以下图像类别目前被禁止:

  • 带边框的纹理

  • 多重采样渲染缓冲区

Note:

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

另请参阅:

cudaGraphicsUnregisterResource, cudaGraphicsMapResources, cudaGraphicsSubResourceGetMappedArray, cuGraphicsGLRegisterImage

__host__cudaError_t cudaWGLGetDevice ( int* device, HGPUNV hGpu )
获取与hGpu关联的CUDA设备。
参数
device
- Returns the device associated with hGpu, or -1 if hGpu is not a compute device.
hGpu
- Handle to a GPU, as queried via WGL_NV_gpu_affinity
返回

cudaSuccess

描述

返回与hGpu关联的CUDA设备(如果适用)。

Note:

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

另请参阅:

WGL_NV_gpu_affinity, cuWGLGetDevice