2 * Copyright (C) 2008 Stefan Dösinger(for CodeWeavers)
3 * Copyright (C) 2010 Louis Lenders
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 /* This file contains tests specific to IDirect3D9Ex and IDirect3DDevice9Ex, like
21 * how to obtain them. For testing rendering with extended functions use visual.c
25 #include "wine/test.h"
31 static HMODULE d3d9_handle
= 0;
33 static BOOL (WINAPI
*pEnumDisplaySettingsExA
)(LPCSTR
, DWORD
, DEVMODEA
*, DWORD
);
34 static LONG (WINAPI
*pChangeDisplaySettingsExA
)(LPCSTR
, LPDEVMODE
, HWND
, DWORD
, LPVOID
);
36 static IDirect3D9
* (WINAPI
*pDirect3DCreate9
)(UINT SDKVersion
);
37 static HRESULT (WINAPI
*pDirect3DCreate9Ex
)(UINT SDKVersion
, IDirect3D9Ex
**d3d9ex
);
39 static HWND
create_window(void)
43 wc
.lpfnWndProc
= DefWindowProc
;
44 wc
.lpszClassName
= "d3d9_test_wc";
47 ret
= CreateWindow("d3d9_test_wc", "d3d9_test",
48 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
52 static IDirect3DDevice9Ex
*create_device(HWND device_window
, HWND focus_window
, BOOL windowed
)
54 D3DPRESENT_PARAMETERS present_parameters
= {0};
55 IDirect3DDevice9Ex
*device
;
56 D3DDISPLAYMODEEX mode
, *m
;
59 if (FAILED(pDirect3DCreate9Ex(D3D_SDK_VERSION
, &d3d9
)))
62 present_parameters
.Windowed
= windowed
;
63 present_parameters
.hDeviceWindow
= device_window
;
64 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
65 present_parameters
.BackBufferWidth
= 640;
66 present_parameters
.BackBufferHeight
= 480;
67 present_parameters
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
68 present_parameters
.EnableAutoDepthStencil
= TRUE
;
69 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
71 mode
.Size
= sizeof(mode
);
75 mode
.Format
= D3DFMT_A8R8G8B8
;
76 mode
.ScanLineOrdering
= 0;
78 m
= windowed
? NULL
: &mode
;
79 if (SUCCEEDED(IDirect3D9Ex_CreateDeviceEx(d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, focus_window
,
80 D3DCREATE_HARDWARE_VERTEXPROCESSING
, &present_parameters
, m
, &device
))) goto done
;
82 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D16
;
83 if (SUCCEEDED(IDirect3D9Ex_CreateDeviceEx(d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, focus_window
,
84 D3DCREATE_HARDWARE_VERTEXPROCESSING
, &present_parameters
, m
, &device
))) goto done
;
86 if (SUCCEEDED(IDirect3D9Ex_CreateDeviceEx(d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, focus_window
,
87 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, m
, &device
))) goto done
;
92 IDirect3D9Ex_Release(d3d9
);
96 static HRESULT
reset_device(IDirect3DDevice9Ex
*device
, HWND device_window
, BOOL windowed
)
98 D3DPRESENT_PARAMETERS present_parameters
= {0};
100 present_parameters
.Windowed
= windowed
;
101 present_parameters
.hDeviceWindow
= device_window
;
102 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
103 present_parameters
.BackBufferWidth
= 1024;
104 present_parameters
.BackBufferHeight
= 768;
105 present_parameters
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
106 present_parameters
.EnableAutoDepthStencil
= TRUE
;
107 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
109 return IDirect3DDevice9_Reset(device
, &present_parameters
);
112 static ULONG
getref(IUnknown
*obj
) {
113 IUnknown_AddRef(obj
);
114 return IUnknown_Release(obj
);
117 static void test_qi_base_to_ex(void)
119 IDirect3D9
*d3d9
= pDirect3DCreate9(D3D_SDK_VERSION
);
120 IDirect3D9Ex
*d3d9ex
= (void *) 0xdeadbeef;
121 IDirect3DDevice9
*device
;
122 IDirect3DDevice9Ex
*deviceEx
= (void *) 0xdeadbeef;
124 HWND window
= create_window();
125 D3DPRESENT_PARAMETERS present_parameters
;
129 skip("Direct3D9 is not available\n");
133 hr
= IDirect3D9_QueryInterface(d3d9
, &IID_IDirect3D9Ex
, (void **) &d3d9ex
);
134 ok(hr
== E_NOINTERFACE
,
135 "IDirect3D9::QueryInterface for IID_IDirect3D9Ex returned %08x, expected E_NOINTERFACE\n",
137 ok(d3d9ex
== NULL
, "QueryInterface returned interface %p, expected NULL\n", d3d9ex
);
138 if(d3d9ex
) IDirect3D9Ex_Release(d3d9ex
);
140 memset(&present_parameters
, 0, sizeof(present_parameters
));
141 present_parameters
.Windowed
= TRUE
;
142 present_parameters
.hDeviceWindow
= window
;
143 present_parameters
.SwapEffect
= D3DSWAPEFFECT_COPY
;
144 present_parameters
.BackBufferWidth
= 640;
145 present_parameters
.BackBufferHeight
= 480;
146 present_parameters
.EnableAutoDepthStencil
= FALSE
;
147 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D16
;
148 hr
= IDirect3D9_CreateDevice(d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, present_parameters
.hDeviceWindow
, D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
150 skip("Failed to create a regular Direct3DDevice9, skipping QI tests\n");
154 hr
= IDirect3DDevice9_QueryInterface(device
, &IID_IDirect3DDevice9Ex
, (void **) &deviceEx
);
155 ok(hr
== E_NOINTERFACE
,
156 "IDirect3D9Device::QueryInterface for IID_IDirect3DDevice9Ex returned %08x, expected E_NOINTERFACE\n",
158 ok(deviceEx
== NULL
, "QueryInterface returned interface %p, expected NULL\n", deviceEx
);
159 if(deviceEx
) IDirect3DDevice9Ex_Release(deviceEx
);
161 IDirect3DDevice9_Release(device
);
164 IDirect3D9_Release(d3d9
);
165 DestroyWindow(window
);
168 static void test_qi_ex_to_base(void)
170 IDirect3D9
*d3d9
= (void *) 0xdeadbeef;
171 IDirect3D9Ex
*d3d9ex
;
172 IDirect3DDevice9
*device
;
173 IDirect3DDevice9Ex
*deviceEx
= (void *) 0xdeadbeef;
175 HWND window
= create_window();
176 D3DPRESENT_PARAMETERS present_parameters
;
179 hr
= pDirect3DCreate9Ex(D3D_SDK_VERSION
, &d3d9ex
);
180 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
, "Direct3DCreate9Ex returned %08x\n", hr
);
182 skip("Direct3D9Ex is not available\n");
186 hr
= IDirect3D9Ex_QueryInterface(d3d9ex
, &IID_IDirect3D9
, (void **) &d3d9
);
188 "IDirect3D9Ex::QueryInterface for IID_IDirect3D9 returned %08x, expected D3D_OK\n",
190 ok(d3d9
!= NULL
&& d3d9
!= (void *) 0xdeadbeef,
191 "QueryInterface returned interface %p, expected != NULL && != 0xdeadbeef\n", d3d9
);
192 ref
= getref((IUnknown
*) d3d9ex
);
193 ok(ref
== 2, "IDirect3D9Ex refcount is %d, expected 2\n", ref
);
194 ref
= getref((IUnknown
*) d3d9
);
195 ok(ref
== 2, "IDirect3D9 refcount is %d, expected 2\n", ref
);
197 memset(&present_parameters
, 0, sizeof(present_parameters
));
198 present_parameters
.Windowed
= TRUE
;
199 present_parameters
.hDeviceWindow
= window
;
200 present_parameters
.SwapEffect
= D3DSWAPEFFECT_COPY
;
201 present_parameters
.BackBufferWidth
= 640;
202 present_parameters
.BackBufferHeight
= 480;
203 present_parameters
.EnableAutoDepthStencil
= FALSE
;
204 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D16
;
206 /* First, try to create a normal device with IDirect3D9Ex::CreateDevice and QI it for IDirect3DDevice9Ex */
207 hr
= IDirect3D9Ex_CreateDevice(d3d9ex
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, present_parameters
.hDeviceWindow
, D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
209 skip("Failed to create a regular Direct3DDevice9, skipping QI tests\n");
213 hr
= IDirect3DDevice9_QueryInterface(device
, &IID_IDirect3DDevice9Ex
, (void **) &deviceEx
);
215 "IDirect3D9Device::QueryInterface for IID_IDirect3DDevice9Ex returned %08x, expected D3D_OK\n",
217 ok(deviceEx
!= NULL
&& deviceEx
!= (void *) 0xdeadbeef,
218 "QueryInterface returned interface %p, expected != NULL && != 0xdeadbeef\n", deviceEx
);
219 ref
= getref((IUnknown
*) device
);
220 ok(ref
== 2, "IDirect3DDevice9 refcount is %d, expected 2\n", ref
);
221 ref
= getref((IUnknown
*) deviceEx
);
222 ok(ref
== 2, "IDirect3DDevice9Ex refcount is %d, expected 2\n", ref
);
223 if(deviceEx
) IDirect3DDevice9Ex_Release(deviceEx
);
224 IDirect3DDevice9_Release(device
);
226 /* Next, try to create a normal device with IDirect3D9::CreateDevice(non-ex) and QI it */
227 hr
= IDirect3D9_CreateDevice(d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, present_parameters
.hDeviceWindow
, D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
229 skip("Failed to create a regular Direct3DDevice9, skipping QI tests\n");
233 hr
= IDirect3DDevice9_QueryInterface(device
, &IID_IDirect3DDevice9Ex
, (void **) &deviceEx
);
235 "IDirect3D9Device::QueryInterface for IID_IDirect3DDevice9Ex returned %08x, expected D3D_OK\n",
237 ok(deviceEx
!= NULL
&& deviceEx
!= (void *) 0xdeadbeef,
238 "QueryInterface returned interface %p, expected != NULL && != 0xdeadbeef\n", deviceEx
);
239 ref
= getref((IUnknown
*) device
);
240 ok(ref
== 2, "IDirect3DDevice9 refcount is %d, expected 2\n", ref
);
241 ref
= getref((IUnknown
*) deviceEx
);
242 ok(ref
== 2, "IDirect3DDevice9Ex refcount is %d, expected 2\n", ref
);
243 if(deviceEx
) IDirect3DDevice9Ex_Release(deviceEx
);
244 IDirect3DDevice9_Release(device
);
246 IDirect3D9_Release(d3d9
);
247 IDirect3D9Ex_Release(d3d9ex
);
250 DestroyWindow(window
);
253 static void test_get_adapter_luid(void)
255 HWND window
= create_window();
256 IDirect3D9Ex
*d3d9ex
;
261 hr
= pDirect3DCreate9Ex(D3D_SDK_VERSION
, &d3d9ex
);
264 skip("Direct3D9Ex is not available.\n");
265 DestroyWindow(window
);
269 count
= IDirect3D9Ex_GetAdapterCount(d3d9ex
);
272 skip("No adapters available.\n");
273 IDirect3D9Ex_Release(d3d9ex
);
274 DestroyWindow(window
);
278 hr
= IDirect3D9Ex_GetAdapterLUID(d3d9ex
, D3DADAPTER_DEFAULT
, &luid
);
279 ok(SUCCEEDED(hr
), "GetAdapterLUID failed, hr %#x.\n", hr
);
280 trace("adapter luid: %08x:%08x.\n", luid
.HighPart
, luid
.LowPart
);
282 IDirect3D9Ex_Release(d3d9ex
);
285 static void test_get_adapter_displaymode_ex(void)
287 HWND window
= create_window();
288 IDirect3D9
*d3d9
= (void *) 0xdeadbeef;
289 IDirect3D9Ex
*d3d9ex
;
293 D3DDISPLAYMODEEX mode_ex
;
294 D3DDISPLAYROTATION rotation
;
299 hr
= pDirect3DCreate9Ex(D3D_SDK_VERSION
, &d3d9ex
);
302 skip("Direct3D9Ex is not available (%#x)\n", hr
);
303 DestroyWindow(window
);
307 count
= IDirect3D9Ex_GetAdapterCount(d3d9ex
);
310 skip("No adapters available.\n");
311 IDirect3D9Ex_Release(d3d9ex
);
312 DestroyWindow(window
);
316 hr
= IDirect3D9Ex_QueryInterface(d3d9ex
, &IID_IDirect3D9
, (void **) &d3d9
);
318 "IDirect3D9Ex::QueryInterface for IID_IDirect3D9 returned %08x, expected D3D_OK\n",
320 ok(d3d9
!= NULL
&& d3d9
!= (void *) 0xdeadbeef,
321 "QueryInterface returned interface %p, expected != NULL && != 0xdeadbeef\n", d3d9
);
322 /* change displayorientation*/
323 hdll
= GetModuleHandleA("user32.dll");
324 pEnumDisplaySettingsExA
= (void*)GetProcAddress(hdll
, "EnumDisplaySettingsExA");
325 pChangeDisplaySettingsExA
= (void*)GetProcAddress(hdll
, "ChangeDisplaySettingsExA");
327 if (!pEnumDisplaySettingsExA
|| !pChangeDisplaySettingsExA
) goto out
;
329 memset(&startmode
, 0, sizeof(startmode
));
330 startmode
.dmSize
= sizeof(startmode
);
331 retval
= pEnumDisplaySettingsExA(NULL
, ENUM_CURRENT_SETTINGS
, &startmode
, 0);
332 ok(retval
, "Failed to retrieve current display mode, retval %d.\n", retval
);
333 if (!retval
) goto out
;
335 startmode
.dmFields
= DM_DISPLAYORIENTATION
| DM_PELSWIDTH
| DM_PELSHEIGHT
;
336 S2(U1(startmode
)).dmDisplayOrientation
= DMDO_180
;
337 retval
= pChangeDisplaySettingsExA(NULL
, &startmode
, NULL
, 0, NULL
);
339 if(retval
== DISP_CHANGE_BADMODE
)
341 trace(" Test skipped: graphics mode is not supported\n");
345 ok(retval
== DISP_CHANGE_SUCCESSFUL
,"ChangeDisplaySettingsEx failed with %d\n", retval
);
346 /* try retrieve orientation info with EnumDisplaySettingsEx*/
347 startmode
.dmFields
= 0;
348 S2(U1(startmode
)).dmDisplayOrientation
= 0;
349 ok(pEnumDisplaySettingsExA(NULL
, ENUM_CURRENT_SETTINGS
, &startmode
, EDS_ROTATEDMODE
), "EnumDisplaySettingsEx failed\n");
351 /*now that orientation has changed start tests for GetAdapterDisplayModeEx: invalid Size*/
352 memset(&mode_ex
, 0, sizeof(mode_ex
));
353 hr
= IDirect3D9Ex_GetAdapterDisplayModeEx(d3d9ex
, D3DADAPTER_DEFAULT
, &mode_ex
, &rotation
);
354 ok(hr
== D3DERR_INVALIDCALL
, "GetAdapterDisplayModeEx returned %#x instead of D3DERR_INVALIDCALL\n", hr
);
356 mode_ex
.Size
= sizeof(D3DDISPLAYMODEEX
);
358 hr
= IDirect3D9Ex_GetAdapterDisplayModeEx(d3d9ex
, count
+ 1, &mode_ex
, &rotation
);
359 ok(hr
== D3DERR_INVALIDCALL
, "GetAdapterDisplayModeEx returned %#x instead of D3DERR_INVALIDCALL\n", hr
);
360 /*valid count and valid Size*/
361 hr
= IDirect3D9Ex_GetAdapterDisplayModeEx(d3d9ex
, D3DADAPTER_DEFAULT
, &mode_ex
, &rotation
);
362 ok(SUCCEEDED(hr
), "GetAdapterDisplayModeEx failed, hr %#x.\n", hr
);
364 /* Compare what GetAdapterDisplayMode returns with what GetAdapterDisplayModeEx returns*/
365 hr
= IDirect3D9_GetAdapterDisplayMode(d3d9
, D3DADAPTER_DEFAULT
, &mode
);
366 ok(SUCCEEDED(hr
), "GetAdapterDisplayMode failed, hr %#x.\n", hr
);
368 ok(mode_ex
.Size
== sizeof(D3DDISPLAYMODEEX
), "size is %d\n", mode_ex
.Size
);
369 ok(mode_ex
.Width
== mode
.Width
, "width is %d instead of %d\n", mode_ex
.Width
, mode
.Width
);
370 ok(mode_ex
.Height
== mode
.Height
, "height is %d instead of %d\n", mode_ex
.Height
, mode
.Height
);
371 ok(mode_ex
.RefreshRate
== mode
.RefreshRate
, "RefreshRate is %d instead of %d\n",
372 mode_ex
.RefreshRate
, mode
.RefreshRate
);
373 ok(mode_ex
.Format
== mode
.Format
, "format is %x instead of %x\n", mode_ex
.Format
, mode
.Format
);
374 /* Don't know yet how to test for ScanLineOrdering, just testing that it
375 * is set to a value by GetAdapterDisplayModeEx(). */
376 ok(mode_ex
.ScanLineOrdering
!= 0, "ScanLineOrdering returned 0\n");
377 /* Check that orientation is returned correctly by GetAdapterDisplayModeEx
378 * and EnumDisplaySettingsEx(). */
379 todo_wine
ok(S2(U1(startmode
)).dmDisplayOrientation
== DMDO_180
&& rotation
== D3DDISPLAYROTATION_180
,
380 "rotation is %d instead of %d\n", rotation
, S2(U1(startmode
)).dmDisplayOrientation
);
382 trace("GetAdapterDisplayModeEx returned Width = %d,Height = %d, RefreshRate = %d, Format = %x, ScanLineOrdering = %x, rotation = %d\n",
383 mode_ex
.Width
, mode_ex
.Height
, mode_ex
.RefreshRate
, mode_ex
.Format
, mode_ex
.ScanLineOrdering
, rotation
);
385 /* test GetAdapterDisplayModeEx with null pointer for D3DDISPLAYROTATION */
386 memset(&mode_ex
, 0, sizeof(mode_ex
));
387 mode_ex
.Size
= sizeof(D3DDISPLAYMODEEX
);
389 hr
= IDirect3D9Ex_GetAdapterDisplayModeEx(d3d9ex
, D3DADAPTER_DEFAULT
, &mode_ex
, NULL
);
390 ok(SUCCEEDED(hr
), "GetAdapterDisplayModeEx failed, hr %#x.\n", hr
);
392 ok(mode_ex
.Size
== sizeof(D3DDISPLAYMODEEX
), "size is %d\n", mode_ex
.Size
);
393 ok(mode_ex
.Width
== mode
.Width
, "width is %d instead of %d\n", mode_ex
.Width
, mode
.Width
);
394 ok(mode_ex
.Height
== mode
.Height
, "height is %d instead of %d\n", mode_ex
.Height
, mode
.Height
);
395 ok(mode_ex
.RefreshRate
== mode
.RefreshRate
, "RefreshRate is %d instead of %d\n",
396 mode_ex
.RefreshRate
, mode
.RefreshRate
);
397 ok(mode_ex
.Format
== mode
.Format
, "format is %x instead of %x\n", mode_ex
.Format
, mode
.Format
);
398 /* Don't know yet how to test for ScanLineOrdering, just testing that it
399 * is set to a value by GetAdapterDisplayModeEx(). */
400 ok(mode_ex
.ScanLineOrdering
!= 0, "ScanLineOrdering returned 0\n");
402 /* return to the default mode */
403 pChangeDisplaySettingsExA(NULL
, NULL
, NULL
, 0, NULL
);
405 IDirect3D9_Release(d3d9
);
406 IDirect3D9Ex_Release(d3d9ex
);
409 static void test_texture_sysmem_create(void)
411 IDirect3DDevice9Ex
*device
;
412 IDirect3DTexture9
*texture
;
413 D3DLOCKED_RECT locked_rect
;
419 window
= create_window();
420 if (!(device
= create_device(window
, window
, TRUE
)))
422 skip("Failed to create a D3D device, skipping tests.\n");
426 mem
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, 128 * 128 * 4);
427 hr
= IDirect3DDevice9Ex_CreateTexture(device
, 128, 128, 0, 0, D3DFMT_A8R8G8B8
,
428 D3DPOOL_SYSTEMMEM
, &texture
, &mem
);
429 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
430 hr
= IDirect3DDevice9Ex_CreateTexture(device
, 128, 128, 1, 0, D3DFMT_A8R8G8B8
,
431 D3DPOOL_SYSTEMMEM
, &texture
, &mem
);
432 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
433 hr
= IDirect3DTexture9_LockRect(texture
, 0, &locked_rect
, NULL
, 0);
434 ok(SUCCEEDED(hr
), "Failed to lock texture, hr %#x.\n", hr
);
435 ok(locked_rect
.Pitch
== 128 * 4, "Got unexpected pitch %d.\n", locked_rect
.Pitch
);
436 ok(locked_rect
.pBits
== mem
, "Got unexpected pBits %p, expected %p.\n", locked_rect
.pBits
, mem
);
437 hr
= IDirect3DTexture9_UnlockRect(texture
, 0);
438 ok(SUCCEEDED(hr
), "Failed to unlock texture, hr %#x.\n", hr
);
439 IDirect3DTexture9_Release(texture
);
440 HeapFree(GetProcessHeap(), 0, mem
);
442 refcount
= IDirect3DDevice9Ex_Release(device
);
443 ok(!refcount
, "Device has %u references left.\n", refcount
);
446 DestroyWindow(window
);
449 static void test_reset(void)
451 static const DWORD simple_vs
[] =
453 0xfffe0101, /* vs_1_1 */
454 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position0 v0 */
455 0x00000009, 0xc0010000, 0x90e40000, 0xa0e40000, /* dp4 oPos.x, v0, c0 */
456 0x00000009, 0xc0020000, 0x90e40000, 0xa0e40001, /* dp4 oPos.y, v0, c1 */
457 0x00000009, 0xc0040000, 0x90e40000, 0xa0e40002, /* dp4 oPos.z, v0, c2 */
458 0x00000009, 0xc0080000, 0x90e40000, 0xa0e40003, /* dp4 oPos.w, v0, c3 */
459 0x0000ffff, /* end */
462 DWORD height
, orig_height
= GetSystemMetrics(SM_CYSCREEN
);
463 DWORD width
, orig_width
= GetSystemMetrics(SM_CXSCREEN
);
464 IDirect3DVertexShader9
*shader
;
465 IDirect3DSwapChain9
*swapchain
;
466 D3DDISPLAYMODE d3ddm
, d3ddm2
;
467 D3DPRESENT_PARAMETERS d3dpp
;
468 IDirect3DDevice9Ex
*device
;
469 IDirect3DSurface9
*surface
;
470 UINT i
, adapter_mode_count
;
486 window
= create_window();
487 if (!(device
= create_device(window
, window
, TRUE
)))
489 skip("Failed to create a D3D device, skipping test.\n");
490 DestroyWindow(window
);
494 hr
= IDirect3DDevice9Ex_GetDirect3D(device
, &d3d9
);
495 ok(SUCCEEDED(hr
), "Failed to get d3d9, hr %#x.\n", hr
);
496 hr
= IDirect3DDevice9Ex_GetDeviceCaps(device
, &caps
);
497 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
499 IDirect3D9_GetAdapterDisplayMode(d3d9
, D3DADAPTER_DEFAULT
, &d3ddm
);
500 adapter_mode_count
= IDirect3D9_GetAdapterModeCount(d3d9
, D3DADAPTER_DEFAULT
, d3ddm
.Format
);
501 modes
= HeapAlloc(GetProcessHeap(), 0, sizeof(*modes
) * adapter_mode_count
);
502 for (i
= 0; i
< adapter_mode_count
; ++i
)
506 hr
= IDirect3D9_EnumAdapterModes(d3d9
, D3DADAPTER_DEFAULT
, d3ddm
.Format
, i
, &d3ddm2
);
507 ok(SUCCEEDED(hr
), "Failed to enumerate display mode, hr %#x.\n", hr
);
509 for (j
= 0; j
< mode_count
; ++j
)
511 if (modes
[j
].w
== d3ddm2
.Width
&& modes
[j
].h
== d3ddm2
.Height
)
516 modes
[j
].w
= d3ddm2
.Width
;
517 modes
[j
].h
= d3ddm2
.Height
;
521 /* We use them as invalid modes. */
522 if ((d3ddm2
.Width
== 801 && d3ddm2
.Height
== 600)
523 || (d3ddm2
.Width
== 32 && d3ddm2
.Height
== 32))
525 skip("This system supports a screen resolution of %dx%d, not running mode tests.\n",
526 d3ddm2
.Width
, d3ddm2
.Height
);
533 skip("Less than 2 modes supported, skipping mode tests.\n");
538 if (modes
[i
].w
== orig_width
&& modes
[i
].h
== orig_height
)
541 memset(&d3dpp
, 0, sizeof(d3dpp
));
542 d3dpp
.Windowed
= FALSE
;
543 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
544 d3dpp
.BackBufferWidth
= modes
[i
].w
;
545 d3dpp
.BackBufferHeight
= modes
[i
].h
;
546 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
547 d3dpp
.EnableAutoDepthStencil
= TRUE
;
548 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
549 hr
= IDirect3DDevice9Ex_Reset(device
, &d3dpp
);
550 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
551 hr
= IDirect3DDevice9Ex_TestCooperativeLevel(device
);
552 ok(hr
== D3D_OK
, "Got unexpected cooperative level %#x.\n", hr
);
554 width
= GetSystemMetrics(SM_CXSCREEN
);
555 height
= GetSystemMetrics(SM_CYSCREEN
);
556 ok(width
== modes
[i
].w
, "Got screen width %u, expected %u.\n", width
, modes
[i
].w
);
557 ok(height
== modes
[i
].h
, "Got screen height %u, expected %u.\n", height
, modes
[i
].h
);
559 hr
= IDirect3DDevice9Ex_GetScissorRect(device
, &rect
);
560 ok(SUCCEEDED(hr
), "Failed to get scissor rect, hr %#x.\n", hr
);
561 ok(rect
.left
== 0 && rect
.top
== 0 && rect
.right
== modes
[i
].w
&& rect
.bottom
== modes
[i
].h
,
562 "Got unexpected scissor rect {%d, %d, %d, %d}.\n",
563 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
565 hr
= IDirect3DDevice9Ex_GetViewport(device
, &vp
);
566 ok(SUCCEEDED(hr
), "Failed to get viewport, hr %#x.\n", hr
);
567 ok(vp
.X
== 0, "Got unexpected vp.X %u.\n", vp
.X
);
568 ok(vp
.Y
== 0, "Got unexpected vp.Y %u.\n", vp
.Y
);
569 ok(vp
.Width
== modes
[i
].w
, "Got vp.Width %u, expected %u.\n", vp
.Width
, modes
[i
].w
);
570 ok(vp
.Height
== modes
[i
].h
, "Got vp.Height %u, expected %u.\n", vp
.Height
, modes
[i
].h
);
571 ok(vp
.MinZ
== 0.0f
, "Got unexpected vp.MinZ %.8e.\n", vp
.MinZ
);
572 ok(vp
.MaxZ
== 1.0f
, "Got unexpected vp,MaxZ %.8e.\n", vp
.MaxZ
);
579 hr
= IDirect3DDevice9Ex_SetViewport(device
, &vp
);
580 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
582 SetRect(&rect
, 10, 20, 30, 40);
583 hr
= IDirect3DDevice9Ex_SetScissorRect(device
, &rect
);
584 ok(SUCCEEDED(hr
), "Failed to set scissor rect, hr %#x.\n", hr
);
586 hr
= IDirect3DDevice9_GetRenderState(device
, D3DRS_LIGHTING
, &value
);
587 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
588 ok(!!value
, "Got unexpected value %#x for D3DRS_LIGHTING.\n", value
);
589 hr
= IDirect3DDevice9_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
590 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
592 memset(&d3dpp
, 0, sizeof(d3dpp
));
593 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
594 d3dpp
.Windowed
= FALSE
;
595 d3dpp
.BackBufferWidth
= modes
[i
].w
;
596 d3dpp
.BackBufferHeight
= modes
[i
].h
;
597 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
598 hr
= IDirect3DDevice9Ex_Reset(device
, &d3dpp
);
599 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
600 hr
= IDirect3DDevice9Ex_TestCooperativeLevel(device
);
601 ok(hr
== D3D_OK
, "Got unexpected cooperative level %#x.\n", hr
);
603 /* Render states are preserved in d3d9ex. */
604 hr
= IDirect3DDevice9_GetRenderState(device
, D3DRS_LIGHTING
, &value
);
605 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
606 ok(!value
, "Got unexpected value %#x for D3DRS_LIGHTING.\n", value
);
608 hr
= IDirect3DDevice9Ex_GetScissorRect(device
, &rect
);
609 ok(SUCCEEDED(hr
), "Failed to get scissor rect, hr %#x.\n", hr
);
610 ok(rect
.left
== 0 && rect
.top
== 0 && rect
.right
== modes
[i
].w
&& rect
.bottom
== modes
[i
].h
,
611 "Got unexpected scissor rect {%d, %d, %d, %d}.\n",
612 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
614 hr
= IDirect3DDevice9Ex_GetViewport(device
, &vp
);
615 ok(SUCCEEDED(hr
), "Failed to get viewport, hr %#x.\n", hr
);
616 ok(vp
.X
== 0, "Got unexpected vp.X %u.\n", vp
.X
);
617 ok(vp
.Y
== 0, "Got unexpected vp.Y %u.\n", vp
.Y
);
618 ok(vp
.Width
== modes
[i
].w
, "Got vp.Width %u, expected %u.\n", vp
.Width
, modes
[i
].w
);
619 ok(vp
.Height
== modes
[i
].h
, "Got vp.Height %u, expected %u.\n", vp
.Height
, modes
[i
].h
);
620 ok(vp
.MinZ
== 2.0f
, "Got unexpected vp.MinZ %.8e.\n", vp
.MinZ
);
621 ok(vp
.MaxZ
== 3.0f
, "Got unexpected vp,MaxZ %.8e.\n", vp
.MaxZ
);
623 width
= GetSystemMetrics(SM_CXSCREEN
);
624 height
= GetSystemMetrics(SM_CYSCREEN
);
625 ok(width
== modes
[i
].w
, "Got screen width %u, expected %u.\n", width
, modes
[i
].w
);
626 ok(height
== modes
[i
].h
, "Got screen height %u, expected %u.\n", height
, modes
[i
].h
);
628 hr
= IDirect3DDevice9Ex_GetSwapChain(device
, 0, &swapchain
);
629 ok(SUCCEEDED(hr
), "Failed to get swapchain, hr %#x.\n", hr
);
630 hr
= IDirect3DSwapChain9_GetPresentParameters(swapchain
, &d3dpp
);
631 ok(SUCCEEDED(hr
), "Failed to get present parameters, hr %#x.\n", hr
);
632 ok(d3dpp
.BackBufferWidth
== modes
[i
].w
, "Got backbuffer width %u, expected %u.\n",
633 d3dpp
.BackBufferWidth
, modes
[i
].w
);
634 ok(d3dpp
.BackBufferHeight
== modes
[i
].h
, "Got backbuffer height %u, expected %u.\n",
635 d3dpp
.BackBufferHeight
, modes
[i
].h
);
636 IDirect3DSwapChain9_Release(swapchain
);
638 memset(&d3dpp
, 0, sizeof(d3dpp
));
639 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
640 d3dpp
.Windowed
= TRUE
;
641 d3dpp
.BackBufferWidth
= 400;
642 d3dpp
.BackBufferHeight
= 300;
643 hr
= IDirect3DDevice9Ex_Reset(device
, &d3dpp
);
644 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
645 hr
= IDirect3DDevice9Ex_TestCooperativeLevel(device
);
646 ok(hr
== D3D_OK
, "Got unexpected cooperative level %#x.\n", hr
);
648 width
= GetSystemMetrics(SM_CXSCREEN
);
649 height
= GetSystemMetrics(SM_CYSCREEN
);
650 ok(width
== orig_width
, "Got screen width %u, expected %u.\n", width
, orig_width
);
651 ok(height
== orig_height
, "Got screen height %u, expected %u.\n", height
, orig_height
);
653 hr
= IDirect3DDevice9Ex_GetScissorRect(device
, &rect
);
654 ok(SUCCEEDED(hr
), "Failed to get scissor rect, hr %#x.\n", hr
);
655 ok(rect
.left
== 0 && rect
.top
== 0 && rect
.right
== 400 && rect
.bottom
== 300,
656 "Got unexpected scissor rect {%d, %d, %d, %d}.\n",
657 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
659 hr
= IDirect3DDevice9Ex_GetViewport(device
, &vp
);
660 ok(SUCCEEDED(hr
), "Failed to get viewport, hr %#x.\n", hr
);
661 ok(vp
.X
== 0, "Got unexpected vp.X %u.\n", vp
.X
);
662 ok(vp
.Y
== 0, "Got unexpected vp.Y %u.\n", vp
.Y
);
663 ok(vp
.Width
== 400, "Got unexpected vp.Width %u.\n", vp
.Width
);
664 ok(vp
.Height
== 300, "Got unexpected vp.Height %u.\n", vp
.Height
);
665 ok(vp
.MinZ
== 2.0f
, "Got unexpected vp.MinZ %.8e.\n", vp
.MinZ
);
666 ok(vp
.MaxZ
== 3.0f
, "Got unexpected vp,MaxZ %.8e.\n", vp
.MaxZ
);
668 hr
= IDirect3DDevice9Ex_GetSwapChain(device
, 0, &swapchain
);
669 ok(SUCCEEDED(hr
), "Failed to get swapchain, hr %#x.\n", hr
);
670 hr
= IDirect3DSwapChain9_GetPresentParameters(swapchain
, &d3dpp
);
671 ok(SUCCEEDED(hr
), "Failed to get present parameters, hr %#x.\n", hr
);
672 ok(d3dpp
.BackBufferWidth
== 400, "Got unexpected backbuffer width %u.\n", d3dpp
.BackBufferWidth
);
673 ok(d3dpp
.BackBufferHeight
== 300, "Got unexpected backbuffer height %u.\n", d3dpp
.BackBufferHeight
);
674 IDirect3DSwapChain9_Release(swapchain
);
676 SetRect(&rect
, 0, 0, 200, 150);
677 ok(AdjustWindowRect(&rect
, GetWindowLongW(window
, GWL_STYLE
), FALSE
), "Failed to adjust window rect.\n");
678 ok(SetWindowPos(window
, NULL
, 0, 0, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
679 SWP_NOMOVE
| SWP_NOZORDER
), "Failed to set window position.\n");
681 memset(&d3dpp
, 0, sizeof(d3dpp
));
682 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
683 d3dpp
.Windowed
= TRUE
;
684 d3dpp
.BackBufferWidth
= 0;
685 d3dpp
.BackBufferHeight
= 0;
686 hr
= IDirect3DDevice9Ex_Reset(device
, &d3dpp
);
687 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
688 hr
= IDirect3DDevice9Ex_TestCooperativeLevel(device
);
689 ok(hr
== D3D_OK
, "Got unexpected cooperative level %#x.\n", hr
);
691 hr
= IDirect3DDevice9Ex_GetScissorRect(device
, &rect
);
692 ok(SUCCEEDED(hr
), "Failed to get scissor rect, hr %#x.\n", hr
);
693 ok(rect
.left
== 0 && rect
.top
== 0 && rect
.right
== 200 && rect
.bottom
== 150,
694 "Got unexpected scissor rect {%d, %d, %d, %d}.\n",
695 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
697 hr
= IDirect3DDevice9Ex_GetViewport(device
, &vp
);
698 ok(SUCCEEDED(hr
), "Failed to get viewport, hr %#x.\n", hr
);
699 ok(vp
.X
== 0, "Got unexpected vp.X %u.\n", vp
.X
);
700 ok(vp
.Y
== 0, "Got unexpected vp.Y %u.\n", vp
.Y
);
701 ok(vp
.Width
== 200, "Got unexpected vp.Width %u.\n", vp
.Width
);
702 ok(vp
.Height
== 150, "Got unexpected vp.Height %u.\n", vp
.Height
);
703 ok(vp
.MinZ
== 2.0f
, "Got unexpected vp.MinZ %.8e.\n", vp
.MinZ
);
704 ok(vp
.MaxZ
== 3.0f
, "Got unexpected vp,MaxZ %.8e.\n", vp
.MaxZ
);
706 hr
= IDirect3DDevice9Ex_GetSwapChain(device
, 0, &swapchain
);
707 ok(SUCCEEDED(hr
), "Failed to get swapchain, hr %#x.\n", hr
);
708 hr
= IDirect3DSwapChain9_GetPresentParameters(swapchain
, &d3dpp
);
709 ok(SUCCEEDED(hr
), "Failed to get present parameters, hr %#x.\n", hr
);
710 ok(d3dpp
.BackBufferWidth
== 200, "Got unexpected backbuffer width %u.\n", d3dpp
.BackBufferWidth
);
711 ok(d3dpp
.BackBufferHeight
== 150, "Got unexpected backbuffer height %u.\n", d3dpp
.BackBufferHeight
);
712 IDirect3DSwapChain9_Release(swapchain
);
714 memset(&d3dpp
, 0, sizeof(d3dpp
));
715 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
716 d3dpp
.Windowed
= TRUE
;
717 d3dpp
.BackBufferWidth
= 400;
718 d3dpp
.BackBufferHeight
= 300;
720 /* Reset with resources in the default pool succeeds in d3d9ex. */
721 hr
= IDirect3DDevice9Ex_CreateOffscreenPlainSurface(device
, 16, 16,
722 D3DFMT_R5G6B5
, D3DPOOL_DEFAULT
, &surface
, NULL
);
723 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
724 hr
= IDirect3DDevice9Ex_Reset(device
, &d3dpp
);
725 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
726 hr
= IDirect3DDevice9Ex_TestCooperativeLevel(device
);
727 ok(hr
== D3D_OK
, "Got unexpected cooperative level %#x.\n", hr
);
728 IDirect3DSurface9_Release(surface
);
730 if (caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP
)
732 IDirect3DVolumeTexture9
*volume_texture
;
734 hr
= IDirect3DDevice9Ex_CreateVolumeTexture(device
, 16, 16, 4, 1, 0,
735 D3DFMT_R5G6B5
, D3DPOOL_DEFAULT
, &volume_texture
, NULL
);
736 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x.\n", hr
);
737 hr
= IDirect3DDevice9Ex_Reset(device
, &d3dpp
);
738 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
739 hr
= IDirect3DDevice9Ex_TestCooperativeLevel(device
);
740 ok(hr
== D3D_OK
, "Got unexpected cooperative level %#x.\n", hr
);
741 IDirect3DVolumeTexture9_Release(volume_texture
);
745 skip("Volume textures not supported.\n");
748 /* Scratch and sysmem pools are fine too. */
749 hr
= IDirect3DDevice9Ex_CreateOffscreenPlainSurface(device
, 16, 16,
750 D3DFMT_R5G6B5
, D3DPOOL_SCRATCH
, &surface
, NULL
);
751 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
752 hr
= IDirect3DDevice9Ex_Reset(device
, &d3dpp
);
753 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
754 hr
= IDirect3DDevice9Ex_TestCooperativeLevel(device
);
755 ok(hr
== D3D_OK
, "Got unexpected cooperative level %#x.\n", hr
);
756 IDirect3DSurface9_Release(surface
);
758 hr
= IDirect3DDevice9Ex_CreateOffscreenPlainSurface(device
, 16, 16,
759 D3DFMT_R5G6B5
, D3DPOOL_SYSTEMMEM
, &surface
, NULL
);
760 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
761 hr
= IDirect3DDevice9Ex_Reset(device
, &d3dpp
);
762 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
763 hr
= IDirect3DDevice9Ex_TestCooperativeLevel(device
);
764 ok(hr
== D3D_OK
, "Got unexpected cooperative level %#x.\n", hr
);
765 IDirect3DSurface9_Release(surface
);
767 /* The depth stencil should get reset to the auto depth stencil when present. */
768 hr
= IDirect3DDevice9Ex_SetDepthStencilSurface(device
, NULL
);
769 ok(SUCCEEDED(hr
), "Failed to set depth/stencil surface, hr %#x.\n", hr
);
771 d3dpp
.EnableAutoDepthStencil
= TRUE
;
772 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
773 hr
= IDirect3DDevice9Ex_Reset(device
, &d3dpp
);
774 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
775 hr
= IDirect3DDevice9Ex_GetDepthStencilSurface(device
, &surface
);
776 ok(SUCCEEDED(hr
), "Failed to get depth/stencil surface, hr %#x.\n", hr
);
777 ok(!!surface
, "Depth/stencil surface should not be NULL.\n");
778 IDirect3DSurface9_Release(surface
);
780 d3dpp
.EnableAutoDepthStencil
= FALSE
;
781 hr
= IDirect3DDevice9Ex_Reset(device
, &d3dpp
);
782 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
783 hr
= IDirect3DDevice9Ex_GetDepthStencilSurface(device
, &surface
);
784 ok(hr
== D3DERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
785 ok(!surface
, "Depth/stencil surface should be NULL.\n");
787 /* References to implicit surfaces are allowed in d3d9ex. */
788 hr
= IDirect3DDevice9Ex_GetBackBuffer(device
, 0, 0, D3DBACKBUFFER_TYPE_MONO
, &surface
);
789 ok(SUCCEEDED(hr
), "Failed to get backbuffer, hr %#x.\n", hr
);
790 hr
= IDirect3DDevice9Ex_Reset(device
, &d3dpp
);
791 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
792 hr
= IDirect3DDevice9Ex_TestCooperativeLevel(device
);
793 ok(hr
== D3D_OK
, "Got unexpected cooperative level %#x.\n", hr
);
794 IDirect3DSurface9_Release(surface
);
796 /* Shaders are fine. */
797 hr
= IDirect3DDevice9Ex_CreateVertexShader(device
, simple_vs
, &shader
);
798 ok(SUCCEEDED(hr
), "Failed to create vertex shader, hr %#x.\n", hr
);
799 hr
= IDirect3DDevice9Ex_Reset(device
, &d3dpp
);
800 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
801 IDirect3DVertexShader9_Release(shader
);
803 /* Try setting invalid modes. */
804 memset(&d3dpp
, 0, sizeof(d3dpp
));
805 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
806 d3dpp
.Windowed
= FALSE
;
807 d3dpp
.BackBufferWidth
= 32;
808 d3dpp
.BackBufferHeight
= 32;
809 hr
= IDirect3DDevice9Ex_Reset(device
, &d3dpp
);
810 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
811 hr
= IDirect3DDevice9Ex_TestCooperativeLevel(device
);
812 ok(hr
== D3D_OK
, "Got unexpected cooperative level %#x.\n", hr
);
814 memset(&d3dpp
, 0, sizeof(d3dpp
));
815 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
816 d3dpp
.Windowed
= FALSE
;
817 d3dpp
.BackBufferWidth
= 801;
818 d3dpp
.BackBufferHeight
= 600;
819 hr
= IDirect3DDevice9Ex_Reset(device
, &d3dpp
);
820 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
821 hr
= IDirect3DDevice9Ex_TestCooperativeLevel(device
);
822 ok(hr
== D3D_OK
, "Got unexpected cooperative level %#x.\n", hr
);
824 hr
= IDirect3D9_GetAdapterDisplayMode(d3d9
, D3DADAPTER_DEFAULT
, &d3ddm
);
825 ok(SUCCEEDED(hr
), "Failed to get display mode, hr %#x.\n", hr
);
827 memset(&d3dpp
, 0, sizeof(d3dpp
));
828 d3dpp
.Windowed
= TRUE
;
829 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
830 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
831 d3dpp
.EnableAutoDepthStencil
= FALSE
;
832 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
835 HeapFree(GetProcessHeap(), 0, modes
);
836 IDirect3D9_Release(d3d9
);
837 refcount
= IDirect3DDevice9Ex_Release(device
);
838 ok(!refcount
, "Device has %u references left.\n", refcount
);
839 DestroyWindow(window
);
842 static void test_reset_resources(void)
844 IDirect3DSurface9
*surface
, *rt
;
845 IDirect3DTexture9
*texture
;
846 IDirect3DDevice9Ex
*device
;
853 window
= CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW
,
854 0, 0, 640, 480, 0, 0, 0, 0);
855 if (!(device
= create_device(window
, window
, TRUE
)))
857 skip("Failed to create a D3D device, skipping tests.\n");
861 hr
= IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
862 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
864 hr
= IDirect3DDevice9_CreateTexture(device
, 128, 128, 1, D3DUSAGE_DEPTHSTENCIL
,
865 D3DFMT_D24S8
, D3DPOOL_DEFAULT
, &texture
, NULL
);
866 ok(SUCCEEDED(hr
), "Failed to create depth/stencil texture, hr %#x.\n", hr
);
867 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
868 ok(SUCCEEDED(hr
), "Failed to get surface, hr %#x.\n", hr
);
869 IDirect3DTexture9_Release(texture
);
870 hr
= IDirect3DDevice9_SetDepthStencilSurface(device
, surface
);
871 ok(SUCCEEDED(hr
), "Failed to set depth/stencil surface, hr %#x.\n", hr
);
872 IDirect3DSurface9_Release(surface
);
874 for (i
= 0; i
< caps
.NumSimultaneousRTs
; ++i
)
876 hr
= IDirect3DDevice9_CreateTexture(device
, 128, 128, 1, D3DUSAGE_RENDERTARGET
,
877 D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &texture
, NULL
);
878 ok(SUCCEEDED(hr
), "Failed to create render target texture %u, hr %#x.\n", i
, hr
);
879 hr
= IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
880 ok(SUCCEEDED(hr
), "Failed to get surface %u, hr %#x.\n", i
, hr
);
881 IDirect3DTexture9_Release(texture
);
882 hr
= IDirect3DDevice9_SetRenderTarget(device
, i
, surface
);
883 ok(SUCCEEDED(hr
), "Failed to set render target surface %u, hr %#x.\n", i
, hr
);
884 IDirect3DSurface9_Release(surface
);
887 hr
= reset_device(device
, window
, TRUE
);
888 ok(SUCCEEDED(hr
), "Failed to reset device.\n");
890 hr
= IDirect3DDevice9_GetBackBuffer(device
, 0, 0, D3DBACKBUFFER_TYPE_MONO
, &rt
);
891 ok(SUCCEEDED(hr
), "Failed to get back buffer, hr %#x.\n", hr
);
892 hr
= IDirect3DDevice9_GetRenderTarget(device
, 0, &surface
);
893 ok(SUCCEEDED(hr
), "Failed to get render target surface, hr %#x.\n", hr
);
894 ok(surface
== rt
, "Got unexpected surface %p for render target.\n", surface
);
895 IDirect3DSurface9_Release(surface
);
896 IDirect3DSurface9_Release(rt
);
898 for (i
= 1; i
< caps
.NumSimultaneousRTs
; ++i
)
900 hr
= IDirect3DDevice9_GetRenderTarget(device
, i
, &surface
);
901 ok(hr
== D3DERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
904 ref
= IDirect3DDevice9_Release(device
);
905 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
908 DestroyWindow(window
);
911 static void test_vidmem_accounting(void)
913 IDirect3DDevice9Ex
*device
;
918 UINT vidmem_start
, vidmem_end
;
920 IDirect3DTexture9
*textures
[20];
922 window
= CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW
,
923 0, 0, 640, 480, 0, 0, 0, 0);
924 if (!(device
= create_device(window
, window
, TRUE
)))
926 skip("Failed to create a D3D device, skipping tests.\n");
930 vidmem_start
= IDirect3DDevice9_GetAvailableTextureMem(device
);
931 memset(textures
, 0, sizeof(textures
));
932 for (i
= 0; i
< 20 && SUCCEEDED(hr
); i
++)
934 hr
= IDirect3DDevice9_CreateTexture(device
, 1024, 1024, 1, D3DUSAGE_RENDERTARGET
,
935 D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &textures
[i
], NULL
);
936 /* No D3DERR_OUTOFVIDEOMEMORY in d3d9ex */
937 ok(SUCCEEDED(hr
) || hr
== E_OUTOFMEMORY
, "Failed to create texture, hr %#x.\n", hr
);
939 vidmem_end
= IDirect3DDevice9_GetAvailableTextureMem(device
);
941 diff
= vidmem_start
- vidmem_end
;
943 ok(diff
< 1024 * 1024, "Expected a video memory difference of less than 1 MB, got %u MB.\n",
946 for (i
= 0; i
< 20; i
++)
949 IDirect3DTexture9_Release(textures
[i
]);
952 ref
= IDirect3DDevice9_Release(device
);
953 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
956 DestroyWindow(window
);
961 d3d9_handle
= LoadLibraryA("d3d9.dll");
964 skip("Could not load d3d9.dll\n");
967 pDirect3DCreate9
= (void *)GetProcAddress(d3d9_handle
, "Direct3DCreate9");
968 ok(pDirect3DCreate9
!= NULL
, "Failed to get address of Direct3DCreate9\n");
969 if(!pDirect3DCreate9
) {
973 pDirect3DCreate9Ex
= (void *)GetProcAddress(d3d9_handle
, "Direct3DCreate9Ex");
974 if (!pDirect3DCreate9Ex
) {
975 win_skip("Failed to get address of Direct3DCreate9Ex\n");
979 test_qi_base_to_ex();
980 test_qi_ex_to_base();
981 test_get_adapter_luid();
982 test_get_adapter_displaymode_ex();
983 test_texture_sysmem_create();
985 test_reset_resources();
986 test_vidmem_accounting();