Top Banner
Michael I Gold Michael I Gold NVIDIA Corporation NVIDIA Corporation OpenGL Interoperability OpenGL Interoperability
16

GTC 2009 OpenGL Gold

Jan 18, 2015

Download

Technology

Mark Kilgard

Michael Gold's slides presented at GPU Technology Conference (GTC) in San Jose on September 30, 2009
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: GTC 2009 OpenGL Gold

Michael I GoldMichael I GoldNVIDIA CorporationNVIDIA Corporation

OpenGL InteroperabilityOpenGL Interoperability

Page 2: GTC 2009 OpenGL Gold

What is Interoperability?

•Share memory objects between APIs or contexts within an API

•Share within a device, or between devices

• Implicit or explicit synchronization

Page 3: GTC 2009 OpenGL Gold

Who can play?

•CUDA•OpenCL•OpenGL•Direct3D

Page 4: GTC 2009 OpenGL Gold

CUDA Interoperability

• Import OpenGL buffer objects as CUDA device pointers–Read or write buffer memory directly

from a kernel

– Implicit synchronization within a CPU thread

•Texture support coming soon

Page 5: GTC 2009 OpenGL Gold

CUDA Interop: ExampleApplication

OpenGLdriver

CUDAdriver

Quadro or GeForce

display

Tesla or

GeForceInterop

fast

•Multi-card interop fastest with GL on Quadro. Transfer between cards w/o CPU intervention

•GeForce performs indirect copy, functional but slower

Interop

faster

Page 6: GTC 2009 OpenGL Gold

CUDA example: Initalization// Create a GL buffer object

glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffer);

glBufferData(GL_PIXEL_UNPACK_BUFFER, buffer_size, NULL, GL_STREAM_COPY);

// Register the buffer object for CUDA interop

cuGLRegisterBufferObject(buffer);

cuGLSetBufferObjectMapFlags(buffer, CU_GL_MAP_RESOURCE_FLAGS_WRITE_DISCARD);

Page 7: GTC 2009 OpenGL Gold

CUDA example: Per-frame usage// map the buffer, invoke a kernel to populate it, and release it back to OpenGL

cuGLMapBufferObjectAsync(&dptr, &size, buffer, stream);

call_kernel(dptr, size);

cuGLUnmapBufferObjectAsync(&dptr, &size, buffer, stream);

// Use the buffer as a pixel buffer object to populate a texture

glTexSubImage2D( … , NULL);

Page 8: GTC 2009 OpenGL Gold

CUDA resources

•Drivers, Toolkit and SDKhttp://www.nvidia.com/cuda

•Forumshttp://forums.nvidia.com

Page 9: GTC 2009 OpenGL Gold

OpenCL Interoperability

•Analogous to CUDA–Create cl_mem from textures and

buffers

•Requires explicit synchronization

Page 10: GTC 2009 OpenGL Gold

OpenCL Shared Objects

OpenCL 3D image object

OpenGL renderbuffer

OpenGL buffer OpenCL buffer object

OpenGL texture 2D(or cubemap face)

OpenGL texture 3D

OpenCL 2D image object

OpenCL 2D image object

clCreateFromGLBuffer

clCreateFromGLTexture2D

clCreateFromGLTexture3D

clCreateFromGLRenderbuffer

OpenGL OpenCL

Page 11: GTC 2009 OpenGL Gold

OpenGL Interoperability• Copy between image objects

– 3D memcpy

– No format conversions

• Copy between dimensionalities– E.g. A slice of a 3D texture and a face of a cubemap

are treated equally

• Copy between GPUs– Complements WGL_NV_gpu_affinity

Page 12: GTC 2009 OpenGL Gold

OpenGL Interop: ExampleApplication

OpenGLdriver

OpenGLdriver

Quadro

display

Quadro

Interop

fast

•Quadro only

•Transfer between cards, no host copy

•Rendering window constrained to affinity GPU

GPU affinity

Offscreen buffer

Page 13: GTC 2009 OpenGL Gold

OpenGL Interop: UsagewglCopyImageSubDataNV(

hSrcRC, srcName, srcTarget, srcLevel, srcX, srcY, srcZ,

hDstRC, dstName, dstTarget, dstLevel, dstX, dstY, dstZ,

width, height, depth);

Page 15: GTC 2009 OpenGL Gold

Direct3D Interoperability

• Import Direct3D buffer and image resources into OpenGL

– Vertex and Index buffers -> buffer objects

– Textures and surfaces -> textures and renderbuffers

• Currently WinXP / Direct3D 9 only

• Experimental extension– WGL_NVX_DX_interop

Page 16: GTC 2009 OpenGL Gold

Direct3D Interop: ExampleApplication

OpenGLdriver

DXdriver

Quadroor

GeForce

display

Interop

fast

•OGL can map DX buffers, not the other way

•Single GPU only (at this time)