6.39. OpenGL 互操作性

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

模块

 

枚举

enum CUGLDeviceList

Functions

CUresult cuGLGetDevices ( unsigned int* pCudaDeviceCount, CUdevice* pCudaDevices, unsigned int  cudaDeviceCount, CUGLDeviceList deviceList )
Gets the CUDA devices associated with the current OpenGL context.
CUresult cuGraphicsGLRegisterBuffer ( CUgraphicsResource* pCudaResource, GLuint buffer, unsigned int  Flags )
Registers an OpenGL buffer object.
CUresult cuGraphicsGLRegisterImage ( CUgraphicsResource* pCudaResource, GLuint image, GLenum target, unsigned int  Flags )
Register an OpenGL texture or renderbuffer object.
CUresult cuWGLGetDevice ( CUdevice* pDevice, HGPUNV hGpu )
Gets the CUDA device associated with hGpu.

枚举

enum CUGLDeviceList

与OpenGL设备对应的CUDA设备

数值
CU_GL_DEVICE_LIST_ALL = 0x01
The CUDA devices for all GPUs used by the current OpenGL context
CU_GL_DEVICE_LIST_CURRENT_FRAME = 0x02
The CUDA devices for the GPUs used by the current OpenGL context in its currently rendering frame
CU_GL_DEVICE_LIST_NEXT_FRAME = 0x03
The CUDA devices for the GPUs to be used by the current OpenGL context in the next frame

Functions

CUresult cuGLGetDevices ( unsigned int* pCudaDeviceCount, CUdevice* pCudaDevices, unsigned int  cudaDeviceCount, CUGLDeviceList deviceList )
获取与当前OpenGL上下文关联的CUDA设备。
参数
pCudaDeviceCount
- Returned number of CUDA devices.
pCudaDevices
- Returned CUDA devices.
cudaDeviceCount
- The size of the output device array pCudaDevices.
deviceList
- The set of devices to return.
描述

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

deviceList 参数可以是以下任意一种:

Note:

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

另请参阅:

cuWGLGetDevice, cudaGLGetDevices

CUresult cuGraphicsGLRegisterBuffer ( CUgraphicsResource* pCudaResource, GLuint buffer, unsigned int  Flags )
注册一个OpenGL缓冲对象。
参数
pCudaResource
- Pointer to the returned object handle
buffer
- name of buffer object to be registered
Flags
- Register flags
描述

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

  • CU_GRAPHICS_REGISTER_FLAGS_NONE:指定不提供关于该资源使用方式的提示。因此假定该资源将被CUDA读取和写入。这是默认值。

  • CU_GRAPHICS_REGISTER_FLAGS_READ_ONLY: 指定CUDA不会写入该资源。

  • CU_GRAPHICS_REGISTER_FLAGS_WRITE_DISCARD: 指定CUDA不会读取该资源,而是会覆盖资源的全部内容,因此资源中原先存储的所有数据都不会被保留。

Note:

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

另请参阅:

cuGraphicsUnregisterResource, cuGraphicsMapResources, cuGraphicsResourceGetMappedPointer, cudaGraphicsGLRegisterBuffer

CUresult cuGraphicsGLRegisterImage ( CUgraphicsResource* pCudaResource, GLuint image, GLenum target, unsigned int  Flags )
注册一个OpenGL纹理或渲染缓冲对象。
参数
pCudaResource
- 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访问。注册对象的句柄将作为pCudaResource返回。

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

寄存器标志 Flags 用于指定预期用途,如下所示:

  • CU_GRAPHICS_REGISTER_FLAGS_NONE: 指定不提供关于该资源使用方式的提示。因此假定该资源将被CUDA读取和写入。这是默认值。

  • CU_GRAPHICS_REGISTER_FLAGS_READ_ONLY: 指定CUDA不会写入该资源。

  • CU_GRAPHICS_REGISTER_FLAGS_WRITE_DISCARD: 指定CUDA不会读取该资源,而是会覆盖资源的全部内容,因此资源中原先存储的所有数据都不会被保留。

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

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

支持以下图像格式。为简洁起见,列表已做缩写。例如,{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:

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

另请参阅:

cuGraphicsUnregisterResource, cuGraphicsMapResources, cuGraphicsSubResourceGetMappedArray, cudaGraphicsGLRegisterImage

CUresult cuWGLGetDevice ( CUdevice* pDevice, HGPUNV hGpu )
获取与hGpu关联的CUDA设备。
参数
pDevice
- Device associated with hGpu
hGpu
- Handle to a GPU, as queried via WGL_NV_gpu_affinity()
描述

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

Note:

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

另请参阅:

cuGLMapBufferObject, cuGLRegisterBufferObject, cuGLUnmapBufferObject, cuGLUnregisterBufferObject, cuGLUnmapBufferObjectAsync, cuGLSetBufferObjectMapFlags, cudaWGLGetDevice

OpenGL 互操作性 [已弃用]