• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1Name
2
3    NV_DX_interop2
4
5Name Strings
6
7    WGL_NV_DX_interop2
8
9Contributors
10
11    Nuno Subtil, NVIDIA
12    Kedarnath Thangudu, NVIDIA
13
14Contact
15
16    Nuno Subtil, NVIDIA Corporation (nsubtil 'at' nvidia.com)
17
18Status
19
20    Complete. Shipping with NVIDIA release 275 drivers, June 2011.
21
22Version
23
24    Last Modified Date:   October 4, 2011
25    Author Revision:      2
26
27Number
28
29    412
30
31Dependencies
32
33    OpenGL 2.1 is required.
34    WGL_NV_DX_interop is required.
35    Windows Display Driver Model (WDDM) capable operating system
36      (such as Vista or Windows 7) required.
37    Direct3D 10-capable GPU required for ID3D10Device usage.
38    Direct3D 11-capable GPU required for ID3D11Device usage.
39
40Overview
41
42    This extension expands on the specification of WGL_NV_DX_interop
43    to add support for DirectX version 10, 10.1 and 11 resources.
44
45New Procedures and Functions
46
47    None
48
49New Tokens
50
51    None
52
53Additions to the WGL Specification
54
55    None
56
57Additions to the WGL_NV_DX_interop specification
58
59    Add to the description of wglDXSetResourceShareHandleNV:
60
61    wglDXSetResourceShareHandle does not need to be called for DirectX
62    version 10 and 11 resources. Calling this function for DirectX 10
63    and 11 resources is not an error but has no effect.
64
65    Modify the last paragraph in the description of
66    wglDXRegisterObjectNV:
67
68    If the application explicitly requests a share handle for a DirectX
69    resource, results are undefined (and may include data corruption,
70    incorrect DirectX operation or program termination) if
71    wglDXRegisterObjectNV is called before calling
72    wglDXSetResourceShareHandleNV for the same resource. This
73    restriction does not apply to non-WDDM operating systems. This
74    restriction also does not apply to DirectX version 10 and 11
75    resources.
76
77    Add the following supported devices to table wgl.devicetypes:
78
79    -------------------------------------------------------------------------
80    DirectX device type      Device Restrictions
81    -------------------------------------------------------------------------
82    ID3D10Device             can only be used on WDDM operating systems;
83                             Must be multithreaded
84    ID3D11Device             can only be used on WDDM operating systems;
85                             XXX Must be multithreaded
86    -------------------------------------------------------------------------
87    Table wgl.devicetypes - Valid device types for the <dxDevice> parameter of
88    wglDXOpenDeviceNV and associated restrictions.
89    -------------------------------------------------------------------------
90
91    Add the following resources to table wgl.objtypes:
92
93    --------------------------------------------------------------------------
94    <type>              type of <name>     Valid DirectX resource types
95    --------------------------------------------------------------------------
96    TEXTURE_1D          texture            ID3D10Texture1D
97                                           ID3D11Texture1D
98    TEXTURE_1D_ARRAY    texture            ID3D10Texture1D
99                                           ID3D11Texture1D
100    TEXTURE_2D          texture            ID3D10Texture2D
101                                           ID3D11Texture2D
102    TEXTURE_2D_ARRAY    texture            ID3D10Texture2D
103                                           ID3D11Texture2D
104    TEXTURE_3D          texture            ID3D10Texture3D
105                                           ID3D11Texture3D
106    TEXTURE_CUBE_MAP    texture            ID3D10Texture2D
107                                           ID3D11Texture2D
108    TEXTURE_RECTANGLE   texture            ID3D10Texture2D
109                                           ID3D11Texture2D
110    RENDERBUFFER        renderbuffer       ID3D10Texture2D
111                                           ID3D11Texture2D
112    NONE                buffer             ID3D10Buffer
113                                           ID3D11Buffer
114    --------------------------------------------------------------------------
115    Table wgl.objtypes - Valid values for the <type> parameter of
116    wglDXRegisterObjectNV, and associated object types for GL and
117    DirectX.
118    --------------------------------------------------------------------------
119
120    Add the following resources to table wgl.restrictions:
121
122    --------------------------------------------------------------------------
123    Resource Type            Resource Restrictions
124    --------------------------------------------------------------------------
125    ID3D10Texture1D          Usage flags must be D3D10_USAGE_DEFAULT
126    ID3D10Texture2D          Usage flags must be D3D10_USAGE_DEFAULT
127    ID3D10Texture3D          Usage flags must be D3D10_USAGE_DEFAULT
128    ID3D10Buffer             Usage flags must be D3D10_USAGE_DEFAULT
129    ID3D11Texture1D          Usage flags must be D3D11_USAGE_DEFAULT
130    ID3D11Texture2D          Usage flags must be D3D11_USAGE_DEFAULT
131    ID3D11Texture3D          Usage flags must be D3D11_USAGE_DEFAULT
132    ID3D11Buffer             Usage flags must be D3D11_USAGE_DEFAULT
133    --------------------------------------------------------------------------
134    Table wgl.restrictions - Restrictions on DirectX resources that can
135    be registered via wglDXRegisterObjectNV
136    --------------------------------------------------------------------------
137
138Issues
139
140    1) How do we share D3D "tbuffers" with OpenGL?
141
142    RESOLUTION: D3D "tbuffers" are analogous to buffer textures in OpenGL
143    and do not have their own resource type. The ID3D1xBuffer backing the
144    "tbuffer" could be shared with OpenGL and attached to a buffer texture
145    by passing the interop buffer ID to TexBuffer().
146
147
148Sample Code
149    Example: Render to Direct3D 11 backbuffer with openGL.
150
151    // create D3D11 device, context and swap chain.
152    ID3D11Device *device;
153    ID3D11DeviceContext *devCtx;
154    IDXGISwapChain *swapChain;
155
156    DXGI_SWAP_CHAIN_DESC scd;
157
158    <set appropriate swap chain parameters in scd>
159
160    hr = D3D11CreateDeviceAndSwapChain(NULL,                        // pAdapter
161                                       D3D_DRIVER_TYPE_HARDWARE,    // DriverType
162                                       NULL,                        // Software
163                                       0,                           // Flags (Do not set D3D11_CREATE_DEVICE_SINGLETHREADED)
164                                       NULL,                        // pFeatureLevels
165                                       0,                           // FeatureLevels
166                                       D3D11_SDK_VERSION,           // SDKVersion
167                                       &scd,                        // pSwapChainDesc
168                                       &swapChain,                  // ppSwapChain
169                                       &device,                     // ppDevice
170                                       NULL,                        // pFeatureLevel
171                                       &devCtx);                    // ppImmediateContext
172
173    // Fetch the swapchain backbuffer
174    ID3D11Texture2D *dxColorbuffer;
175    swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID *)&dxColorbuffer);
176
177    // Create depth stencil texture
178    ID3D11Texture2D *dxDepthBuffer;
179    D3D11_TEXTURE2D_DESC depthDesc;
180    depthDesc.Usage = D3D11_USAGE_DEFAULT;
181    <set other depthDesc parameters appropriately>
182
183    // Create Views
184    ID3D11RenderTargetView *colorBufferView;
185    D3D11_RENDER_TARGET_VIEW_DESC rtd;
186    <set rtd parameters appropriately>
187    device->CreateRenderTargetView(dxColorbuffer, &rtd, &colorBufferView);
188
189    ID3D11DepthStencilView *depthBufferView;
190    D3D11_DEPTH_STENCIL_VIEW_DESC dsd;
191    <set dsd parameters appropriately>
192    device->CreateDepthStencilView(dxDepthBuffer, &dsd, &depthBufferView);
193
194    // Attach back buffer and depth texture to redertarget for the device.
195    devCtx->OMSetRenderTargets(1, &colorBufferView, depthBufferView);
196
197    // Register D3D11 device with GL
198    HANDLE gl_handleD3D;
199    gl_handleD3D = wglDXOpenDeviceNV(device);
200
201    // register the Direct3D color and depth/stencil buffers as
202    // renderbuffers in opengl
203    GLuint gl_names[2];
204    HANDLE gl_handles[2];
205
206    glGenRenderbuffers(2, gl_names);
207
208    gl_handles[0] = wglDXRegisterObjectNV(gl_handleD3D, dxColorBuffer,
209                                          gl_names[0],
210                                          GL_RENDERBUFFER,
211                                          WGL_ACCESS_READ_WRITE_NV);
212
213    gl_handles[1] = wglDXRegisterObjectNV(gl_handleD3D, dxDepthBuffer,
214                                          gl_names[1],
215                                          GL_RENDERBUFFER,
216                                          WGL_ACCESS_READ_WRITE_NV);
217
218    // attach the Direct3D buffers to an FBO
219    glBindFramebuffer(GL_FRAMEBUFFER, fbo);
220    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
221                              GL_RENDERBUFFER, gl_names[0]);
222    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
223                              GL_RENDERBUFFER, gl_names[1]);
224    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
225                              GL_RENDERBUFFER, gl_names[1]);
226
227    while (!done) {
228          <direct3d renders to the render targets>
229
230          // lock the render targets for GL access
231          wglDXLockObjectsNVX(handleD3D, 2, gl_handles);
232
233          <opengl renders to the render targets>
234
235          // unlock the render targets
236          wglDXUnlockObjectsNVX(handleD3D, 2, gl_handles);
237
238          <direct3d renders to the render targets and presents
239           the results on the screen>
240    }
241
242Revision History
243
244    Revision 1, 2009/06/13
245     - Initial revision
246    Revision 2, 2011/10/04
247     - Updated supported DX10/11 resources types and their restrictions.
248     - Updated the dependecies section.
249     - Added an issue explaining DX "tbuffer" sharing.
250     - Added sample code.
251