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).
返回
cudaSuccess, cudaErrorNoDevice, cudaErrorInvalidGraphicsContext, cudaErrorOperatingSystem, cudaErrorUnknown
描述
在*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
返回
cudaSuccess, cudaErrorInvalidDevice, cudaErrorInvalidValue, cudaErrorInvalidResourceHandle, cudaErrorOperatingSystem, cudaErrorUnknown
描述
注册由buffer指定的缓冲区对象以供CUDA访问。注册对象的句柄将作为resource返回。注册标志flags用于指定预期用途,如下所示:
-
cudaGraphicsRegisterFlagsNone: 指定该资源的使用方式无任何提示。因此默认假设该资源将被CUDA进行读写操作。此为默认值。
-
cudaGraphicsRegisterFlagsReadOnly: 指定CUDA不会写入此资源。
-
cudaGraphicsRegisterFlagsWriteDiscard: 指定CUDA不会读取该资源,而是会覆盖资源的全部内容,因此资源中原先存储的所有数据都不会被保留。
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
返回
cudaSuccess, cudaErrorInvalidDevice, cudaErrorInvalidValue, cudaErrorInvalidResourceHandle, cudaErrorOperatingSystem, cudaErrorUnknown
描述
将image指定的纹理或渲染缓冲对象注册为可供CUDA访问。注册后的对象句柄将作为resource返回。
target 必须与对象类型匹配,且必须是 GL_TEXTURE_2D、GL_TEXTURE_RECTANGLE、GL_TEXTURE_CUBE_MAP、GL_TEXTURE_3D、GL_TEXTURE_2D_ARRAY 或 GL_RENDERBUFFER 之一。
注册标志flags用于指定预期用途,如下所示:
-
cudaGraphicsRegisterFlagsNone: 指定该资源的使用方式无任何提示。因此默认假设该资源将被CUDA进行读写操作。此为默认值。
-
cudaGraphicsRegisterFlagsReadOnly: 指定CUDA不会写入此资源。
-
cudaGraphicsRegisterFlagsWriteDiscard: 指定CUDA不会读取该资源,而是会覆盖资源的全部内容,因此资源中原先存储的所有数据都不会被保留。
-
cudaGraphicsRegisterFlagsSurfaceLoadStore: 指定CUDA将把此资源绑定到表面引用。
-
cudaGraphicsRegisterFlagsTextureGather: 指定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:请注意,此函数也可能返回之前异步启动的错误代码。
另请参阅:
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
返回