d3d8/tests: Test D3DPRESENT_PARAMETERS after a successful reset.
[wine/multimedia.git] / dlls / d3d8 / tests / device.c
blob92ec3d0cad28c9098c2ba8dd86821c9202a4cfc3
1 /*
2 * Copyright (C) 2006 Vitaliy Margolen
3 * Copyright (C) 2006 Chris Robinson
4 * Copyright (C) 2006 Louis Lenders
5 * Copyright 2006-2007 Henri Verbeet
6 * Copyright 2006-2007, 2011-2013 Stefan Dösinger for CodeWeavers
7 * Copyright 2013 Henri Verbeet for CodeWeavers
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define COBJMACROS
25 #include <initguid.h>
26 #include <d3d8.h>
27 #include "wine/test.h"
29 struct vec3
31 float x, y, z;
34 #define CREATE_DEVICE_FULLSCREEN 0x01
35 #define CREATE_DEVICE_FPU_PRESERVE 0x02
36 #define CREATE_DEVICE_SWVP_ONLY 0x04
38 struct device_desc
40 HWND device_window;
41 unsigned int width;
42 unsigned int height;
43 DWORD flags;
46 #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
47 #define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
49 static DEVMODEW registry_mode;
51 static HRESULT (WINAPI *ValidateVertexShader)(DWORD *, DWORD *, DWORD *, int, DWORD *);
52 static HRESULT (WINAPI *ValidatePixelShader)(DWORD *, DWORD *, int, DWORD *);
54 static BOOL (WINAPI *pGetCursorInfo)(PCURSORINFO);
56 static const DWORD simple_vs[] = {0xFFFE0101, /* vs_1_1 */
57 0x00000009, 0xC0010000, 0x90E40000, 0xA0E40000, /* dp4 oPos.x, v0, c0 */
58 0x00000009, 0xC0020000, 0x90E40000, 0xA0E40001, /* dp4 oPos.y, v0, c1 */
59 0x00000009, 0xC0040000, 0x90E40000, 0xA0E40002, /* dp4 oPos.z, v0, c2 */
60 0x00000009, 0xC0080000, 0x90E40000, 0xA0E40003, /* dp4 oPos.w, v0, c3 */
61 0x0000FFFF}; /* END */
62 static const DWORD simple_ps[] = {0xFFFF0101, /* ps_1_1 */
63 0x00000051, 0xA00F0001, 0x3F800000, 0x00000000, 0x00000000, 0x00000000, /* def c1 = 1.0, 0.0, 0.0, 0.0 */
64 0x00000042, 0xB00F0000, /* tex t0 */
65 0x00000008, 0x800F0000, 0xA0E40001, 0xA0E40000, /* dp3 r0, c1, c0 */
66 0x00000005, 0x800F0000, 0x90E40000, 0x80E40000, /* mul r0, v0, r0 */
67 0x00000005, 0x800F0000, 0xB0E40000, 0x80E40000, /* mul r0, t0, r0 */
68 0x0000FFFF}; /* END */
70 static int get_refcount(IUnknown *object)
72 IUnknown_AddRef( object );
73 return IUnknown_Release( object );
76 /* try to make sure pending X events have been processed before continuing */
77 static void flush_events(void)
79 MSG msg;
80 int diff = 200;
81 int min_timeout = 100;
82 DWORD time = GetTickCount() + diff;
84 while (diff > 0)
86 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
87 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
88 diff = time - GetTickCount();
92 static IDirect3DDevice8 *create_device(IDirect3D8 *d3d8, HWND focus_window, const struct device_desc *desc)
94 D3DPRESENT_PARAMETERS present_parameters = {0};
95 IDirect3DDevice8 *device;
96 DWORD behavior_flags = D3DCREATE_HARDWARE_VERTEXPROCESSING;
98 present_parameters.BackBufferWidth = 640;
99 present_parameters.BackBufferHeight = 480;
100 present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
101 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
102 present_parameters.hDeviceWindow = focus_window;
103 present_parameters.Windowed = TRUE;
104 present_parameters.EnableAutoDepthStencil = TRUE;
105 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
107 if (desc)
109 present_parameters.BackBufferWidth = desc->width;
110 present_parameters.BackBufferHeight = desc->height;
111 present_parameters.hDeviceWindow = desc->device_window;
112 present_parameters.Windowed = !(desc->flags & CREATE_DEVICE_FULLSCREEN);
113 if (desc->flags & CREATE_DEVICE_SWVP_ONLY)
114 behavior_flags = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
115 if (desc->flags & CREATE_DEVICE_FPU_PRESERVE)
116 behavior_flags |= D3DCREATE_FPU_PRESERVE;
119 if (SUCCEEDED(IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, focus_window,
120 behavior_flags, &present_parameters, &device)))
121 return device;
123 present_parameters.AutoDepthStencilFormat = D3DFMT_D16;
124 if (SUCCEEDED(IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, focus_window,
125 behavior_flags, &present_parameters, &device)))
126 return device;
128 if (desc && desc->flags & CREATE_DEVICE_SWVP_ONLY)
129 return NULL;
130 behavior_flags ^= (D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_SOFTWARE_VERTEXPROCESSING);
132 if (SUCCEEDED(IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, focus_window,
133 behavior_flags, &present_parameters, &device)))
134 return device;
136 return NULL;
139 static HRESULT reset_device(IDirect3DDevice8 *device, const struct device_desc *desc)
141 D3DPRESENT_PARAMETERS present_parameters = {0};
143 present_parameters.BackBufferWidth = 640;
144 present_parameters.BackBufferHeight = 480;
145 present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
146 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
147 present_parameters.hDeviceWindow = NULL;
148 present_parameters.Windowed = TRUE;
149 present_parameters.EnableAutoDepthStencil = TRUE;
150 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
152 if (desc)
154 present_parameters.BackBufferWidth = desc->width;
155 present_parameters.BackBufferHeight = desc->height;
156 present_parameters.hDeviceWindow = desc->device_window;
157 present_parameters.Windowed = !(desc->flags & CREATE_DEVICE_FULLSCREEN);
160 return IDirect3DDevice8_Reset(device, &present_parameters);
163 #define CHECK_CALL(r,c,d,rc) \
164 if (SUCCEEDED(r)) {\
165 int tmp1 = get_refcount( (IUnknown *)d ); \
166 int rc_new = rc; \
167 ok(tmp1 == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, tmp1); \
168 } else {\
169 trace("%s failed: %#08x\n", c, r); \
172 #define CHECK_RELEASE(obj,d,rc) \
173 if (obj) { \
174 int tmp1, rc_new = rc; \
175 IUnknown_Release( (IUnknown*)obj ); \
176 tmp1 = get_refcount( (IUnknown *)d ); \
177 ok(tmp1 == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, tmp1); \
180 #define CHECK_REFCOUNT(obj,rc) \
182 int rc_new = rc; \
183 int count = get_refcount( (IUnknown *)obj ); \
184 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
187 #define CHECK_RELEASE_REFCOUNT(obj,rc) \
189 int rc_new = rc; \
190 int count = IUnknown_Release( (IUnknown *)obj ); \
191 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
194 #define CHECK_ADDREF_REFCOUNT(obj,rc) \
196 int rc_new = rc; \
197 int count = IUnknown_AddRef( (IUnknown *)obj ); \
198 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
201 #define CHECK_SURFACE_CONTAINER(obj,iid,expected) \
203 void *container_ptr = (void *)0x1337c0d3; \
204 hr = IDirect3DSurface8_GetContainer(obj, &iid, &container_ptr); \
205 ok(SUCCEEDED(hr) && container_ptr == expected, "GetContainer returned: hr %#08x, container_ptr %p. " \
206 "Expected hr %#08x, container_ptr %p\n", hr, container_ptr, S_OK, expected); \
207 if (container_ptr && container_ptr != (void *)0x1337c0d3) IUnknown_Release((IUnknown *)container_ptr); \
210 static void check_mipmap_levels(IDirect3DDevice8 *device, UINT width, UINT height, UINT count)
212 IDirect3DBaseTexture8* texture = NULL;
213 HRESULT hr = IDirect3DDevice8_CreateTexture( device, width, height, 0, 0,
214 D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, (IDirect3DTexture8**) &texture );
216 if (SUCCEEDED(hr)) {
217 DWORD levels = IDirect3DBaseTexture8_GetLevelCount(texture);
218 ok(levels == count, "Invalid level count. Expected %d got %u\n", count, levels);
219 } else
220 trace("CreateTexture failed: %#08x\n", hr);
222 if (texture) IDirect3DBaseTexture8_Release( texture );
225 static void test_mipmap_levels(void)
227 IDirect3DDevice8 *device;
228 IDirect3D8 *d3d;
229 ULONG refcount;
230 HWND window;
232 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
233 0, 0, 640, 480, NULL, NULL, NULL, NULL);
234 ok(!!window, "Failed to create a window.\n");
235 d3d = Direct3DCreate8(D3D_SDK_VERSION);
236 ok(!!d3d, "Failed to create a D3D object.\n");
237 if (!(device = create_device(d3d, window, NULL)))
239 skip("Failed to create a 3D device, skipping test.\n");
240 goto cleanup;
243 check_mipmap_levels(device, 32, 32, 6);
244 check_mipmap_levels(device, 256, 1, 9);
245 check_mipmap_levels(device, 1, 256, 9);
246 check_mipmap_levels(device, 1, 1, 1);
248 refcount = IDirect3DDevice8_Release(device);
249 ok(!refcount, "Device has %u references left.\n", refcount);
250 cleanup:
251 IDirect3D8_Release(d3d);
252 DestroyWindow(window);
255 static void test_swapchain(void)
257 IDirect3DSwapChain8 *swapchain1;
258 IDirect3DSwapChain8 *swapchain2;
259 IDirect3DSwapChain8 *swapchain3;
260 IDirect3DSurface8 *backbuffer;
261 D3DPRESENT_PARAMETERS d3dpp;
262 IDirect3DDevice8 *device;
263 IDirect3D8 *d3d;
264 ULONG refcount;
265 HWND window, window2;
266 HRESULT hr;
267 struct device_desc device_desc;
269 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
270 0, 0, 640, 480, NULL, NULL, NULL, NULL);
271 ok(!!window, "Failed to create a window.\n");
272 window2 = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
273 0, 0, 640, 480, NULL, NULL, NULL, NULL);
274 ok(!!window2, "Failed to create a window.\n");
275 d3d = Direct3DCreate8(D3D_SDK_VERSION);
276 ok(!!d3d, "Failed to create a D3D object.\n");
277 if (!(device = create_device(d3d, window, NULL)))
279 skip("Failed to create a 3D device, skipping test.\n");
280 goto cleanup;
283 memset(&d3dpp, 0, sizeof(d3dpp));
284 d3dpp.Windowed = TRUE;
285 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
286 d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
288 /* Create a bunch of swapchains */
289 d3dpp.BackBufferCount = 0;
290 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain1);
291 ok(SUCCEEDED(hr), "Failed to create a swapchain (%#08x)\n", hr);
292 ok(d3dpp.BackBufferCount == 1, "The back buffer count in the presentparams struct is %d\n", d3dpp.BackBufferCount);
294 d3dpp.BackBufferCount = 1;
295 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain2);
296 ok(SUCCEEDED(hr), "Failed to create a swapchain (%#08x)\n", hr);
298 d3dpp.BackBufferCount = 2;
299 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain3);
300 ok(SUCCEEDED(hr), "Failed to create a swapchain (%#08x)\n", hr);
301 if(SUCCEEDED(hr)) {
302 /* Swapchain 3, created with backbuffercount 2 */
303 backbuffer = (void *) 0xdeadbeef;
304 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 0, 0, &backbuffer);
305 ok(SUCCEEDED(hr), "Failed to get the 1st back buffer (%#08x)\n", hr);
306 ok(backbuffer != NULL && backbuffer != (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer);
307 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
309 backbuffer = (void *) 0xdeadbeef;
310 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 1, 0, &backbuffer);
311 ok(SUCCEEDED(hr), "Failed to get the 2nd back buffer (%#08x)\n", hr);
312 ok(backbuffer != NULL && backbuffer != (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer);
313 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
315 backbuffer = (void *) 0xdeadbeef;
316 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 2, 0, &backbuffer);
317 ok(hr == D3DERR_INVALIDCALL, "GetBackBuffer returned %#08x\n", hr);
318 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
319 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
321 backbuffer = (void *) 0xdeadbeef;
322 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 3, 0, &backbuffer);
323 ok(FAILED(hr), "Failed to get the back buffer (%#08x)\n", hr);
324 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
325 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
328 /* Check the back buffers of the swapchains */
329 /* Swapchain 1, created with backbuffercount 0 */
330 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain1, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
331 ok(SUCCEEDED(hr), "Failed to get the back buffer (%#08x)\n", hr);
332 ok(backbuffer != NULL, "The back buffer is NULL (%#08x)\n", hr);
333 if(backbuffer) IDirect3DSurface8_Release(backbuffer);
335 backbuffer = (void *) 0xdeadbeef;
336 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain1, 1, 0, &backbuffer);
337 ok(FAILED(hr), "Failed to get the back buffer (%#08x)\n", hr);
338 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
339 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
341 /* Swapchain 2 - created with backbuffercount 1 */
342 backbuffer = (void *) 0xdeadbeef;
343 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain2, 0, 0, &backbuffer);
344 ok(SUCCEEDED(hr), "Failed to get the back buffer (%#08x)\n", hr);
345 ok(backbuffer != NULL && backbuffer != (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer);
346 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
348 backbuffer = (void *) 0xdeadbeef;
349 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain2, 1, 0, &backbuffer);
350 ok(hr == D3DERR_INVALIDCALL, "GetBackBuffer returned %#08x\n", hr);
351 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
352 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
354 backbuffer = (void *) 0xdeadbeef;
355 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain2, 2, 0, &backbuffer);
356 ok(FAILED(hr), "Failed to get the back buffer (%#08x)\n", hr);
357 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
358 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
360 IDirect3DSwapChain8_Release(swapchain3);
361 IDirect3DSwapChain8_Release(swapchain2);
362 IDirect3DSwapChain8_Release(swapchain1);
364 d3dpp.Windowed = FALSE;
365 d3dpp.hDeviceWindow = window;
366 d3dpp.BackBufferCount = 1;
367 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain1);
368 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x\n", hr);
369 d3dpp.hDeviceWindow = window2;
370 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain1);
371 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x\n", hr);
373 device_desc.width = registry_mode.dmPelsWidth;
374 device_desc.height = registry_mode.dmPelsHeight;
375 device_desc.device_window = window;
376 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
377 hr = reset_device(device, &device_desc);
378 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
380 d3dpp.hDeviceWindow = window;
381 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain1);
382 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x\n", hr);
383 d3dpp.hDeviceWindow = window2;
384 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain1);
385 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x\n", hr);
386 d3dpp.Windowed = TRUE;
387 d3dpp.hDeviceWindow = window;
388 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain1);
389 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x\n", hr);
390 d3dpp.hDeviceWindow = window2;
391 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain1);
392 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x\n", hr);
394 refcount = IDirect3DDevice8_Release(device);
395 ok(!refcount, "Device has %u references left.\n", refcount);
396 cleanup:
397 IDirect3D8_Release(d3d);
398 DestroyWindow(window2);
399 DestroyWindow(window);
402 static void test_refcount(void)
404 IDirect3DVertexBuffer8 *pVertexBuffer = NULL;
405 IDirect3DIndexBuffer8 *pIndexBuffer = NULL;
406 DWORD dVertexShader = -1;
407 DWORD dPixelShader = -1;
408 IDirect3DCubeTexture8 *pCubeTexture = NULL;
409 IDirect3DTexture8 *pTexture = NULL;
410 IDirect3DVolumeTexture8 *pVolumeTexture = NULL;
411 IDirect3DVolume8 *pVolumeLevel = NULL;
412 IDirect3DSurface8 *pStencilSurface = NULL;
413 IDirect3DSurface8 *pImageSurface = NULL;
414 IDirect3DSurface8 *pRenderTarget = NULL;
415 IDirect3DSurface8 *pRenderTarget2 = NULL;
416 IDirect3DSurface8 *pRenderTarget3 = NULL;
417 IDirect3DSurface8 *pTextureLevel = NULL;
418 IDirect3DSurface8 *pBackBuffer = NULL;
419 DWORD dStateBlock = -1;
420 IDirect3DSwapChain8 *pSwapChain = NULL;
421 D3DCAPS8 caps;
422 D3DPRESENT_PARAMETERS d3dpp;
423 IDirect3DDevice8 *device = NULL;
424 ULONG refcount = 0, tmp;
425 IDirect3D8 *d3d, *d3d2;
426 HWND window;
427 HRESULT hr;
429 DWORD decl[] =
431 D3DVSD_STREAM(0),
432 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
433 D3DVSD_REG(D3DVSDE_DIFFUSE, D3DVSDT_D3DCOLOR), /* D3DVSDE_DIFFUSE, Register v5 */
434 D3DVSD_END()
437 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
438 0, 0, 640, 480, NULL, NULL, NULL, NULL);
439 ok(!!window, "Failed to create a window.\n");
440 d3d = Direct3DCreate8(D3D_SDK_VERSION);
441 ok(!!d3d, "Failed to create a D3D object.\n");
443 CHECK_REFCOUNT(d3d, 1);
445 if (!(device = create_device(d3d, window, NULL)))
447 skip("Failed to create a 3D device, skipping test.\n");
448 goto cleanup;
451 IDirect3DDevice8_GetDeviceCaps(device, &caps);
453 refcount = get_refcount((IUnknown *)device);
454 ok(refcount == 1, "Invalid device RefCount %d\n", refcount);
456 CHECK_REFCOUNT(d3d, 2);
458 hr = IDirect3DDevice8_GetDirect3D(device, &d3d2);
459 CHECK_CALL(hr, "GetDirect3D", device, refcount);
461 ok(d3d2 == d3d, "Expected IDirect3D8 pointers to be equal.\n");
462 CHECK_REFCOUNT(d3d, 3);
463 CHECK_RELEASE_REFCOUNT(d3d, 2);
466 * Check refcount of implicit surfaces. Findings:
467 * - the container is the device
468 * - they hold a reference to the device
469 * - they are created with a refcount of 0 (Get/Release returns original refcount)
470 * - they are not freed if refcount reaches 0.
471 * - the refcount is not forwarded to the container.
473 hr = IDirect3DDevice8_GetRenderTarget(device, &pRenderTarget);
474 CHECK_CALL(hr, "GetRenderTarget", device, ++refcount);
475 if(pRenderTarget)
477 CHECK_SURFACE_CONTAINER(pRenderTarget, IID_IDirect3DDevice8, device);
478 CHECK_REFCOUNT( pRenderTarget, 1);
480 CHECK_ADDREF_REFCOUNT(pRenderTarget, 2);
481 CHECK_REFCOUNT(device, refcount);
482 CHECK_RELEASE_REFCOUNT(pRenderTarget, 1);
483 CHECK_REFCOUNT(device, refcount);
485 hr = IDirect3DDevice8_GetRenderTarget(device, &pRenderTarget);
486 CHECK_CALL(hr, "GetRenderTarget", device, refcount);
487 CHECK_REFCOUNT( pRenderTarget, 2);
488 CHECK_RELEASE_REFCOUNT( pRenderTarget, 1);
489 CHECK_RELEASE_REFCOUNT( pRenderTarget, 0);
490 CHECK_REFCOUNT(device, --refcount);
492 /* The render target is released with the device, so AddRef with refcount=0 is fine here. */
493 CHECK_ADDREF_REFCOUNT(pRenderTarget, 1);
494 CHECK_REFCOUNT(device, ++refcount);
495 CHECK_RELEASE_REFCOUNT(pRenderTarget, 0);
496 CHECK_REFCOUNT(device, --refcount);
499 /* Render target and back buffer are identical. */
500 hr = IDirect3DDevice8_GetBackBuffer(device, 0, 0, &pBackBuffer);
501 CHECK_CALL(hr, "GetBackBuffer", device, ++refcount);
502 if(pBackBuffer)
504 CHECK_RELEASE_REFCOUNT(pBackBuffer, 0);
505 ok(pRenderTarget == pBackBuffer, "RenderTarget=%p and BackBuffer=%p should be the same.\n",
506 pRenderTarget, pBackBuffer);
507 pBackBuffer = NULL;
509 CHECK_REFCOUNT(device, --refcount);
511 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &pStencilSurface);
512 CHECK_CALL(hr, "GetDepthStencilSurface", device, ++refcount);
513 if(pStencilSurface)
515 CHECK_SURFACE_CONTAINER(pStencilSurface, IID_IDirect3DDevice8, device);
516 CHECK_REFCOUNT( pStencilSurface, 1);
518 CHECK_ADDREF_REFCOUNT(pStencilSurface, 2);
519 CHECK_REFCOUNT(device, refcount);
520 CHECK_RELEASE_REFCOUNT(pStencilSurface, 1);
521 CHECK_REFCOUNT(device, refcount);
523 CHECK_RELEASE_REFCOUNT( pStencilSurface, 0);
524 CHECK_REFCOUNT(device, --refcount);
526 /* The stencil surface is released with the device, so AddRef with refcount=0 is fine here. */
527 CHECK_ADDREF_REFCOUNT(pStencilSurface, 1);
528 CHECK_REFCOUNT(device, ++refcount);
529 CHECK_RELEASE_REFCOUNT(pStencilSurface, 0);
530 CHECK_REFCOUNT(device, --refcount);
531 pStencilSurface = NULL;
534 /* Buffers */
535 hr = IDirect3DDevice8_CreateIndexBuffer(device, 16, 0, D3DFMT_INDEX32, D3DPOOL_DEFAULT, &pIndexBuffer);
536 CHECK_CALL(hr, "CreateIndexBuffer", device, ++refcount);
537 if(pIndexBuffer)
539 tmp = get_refcount( (IUnknown *)pIndexBuffer );
541 hr = IDirect3DDevice8_SetIndices(device, pIndexBuffer, 0);
542 CHECK_CALL( hr, "SetIndices", pIndexBuffer, tmp);
543 hr = IDirect3DDevice8_SetIndices(device, NULL, 0);
544 CHECK_CALL( hr, "SetIndices", pIndexBuffer, tmp);
547 hr = IDirect3DDevice8_CreateVertexBuffer(device, 16, 0, D3DFVF_XYZ, D3DPOOL_DEFAULT, &pVertexBuffer);
548 CHECK_CALL(hr, "CreateVertexBuffer", device, ++refcount);
549 if(pVertexBuffer)
551 IDirect3DVertexBuffer8 *pVBuf = (void*)~0;
552 UINT stride = ~0;
554 tmp = get_refcount( (IUnknown *)pVertexBuffer );
556 hr = IDirect3DDevice8_SetStreamSource(device, 0, pVertexBuffer, 3 * sizeof(float));
557 CHECK_CALL( hr, "SetStreamSource", pVertexBuffer, tmp);
558 hr = IDirect3DDevice8_SetStreamSource(device, 0, NULL, 0);
559 CHECK_CALL( hr, "SetStreamSource", pVertexBuffer, tmp);
561 hr = IDirect3DDevice8_GetStreamSource(device, 0, &pVBuf, &stride);
562 ok(SUCCEEDED(hr), "GetStreamSource did not succeed with NULL stream!\n");
563 ok(pVBuf==NULL, "pVBuf not NULL (%p)!\n", pVBuf);
564 ok(stride==3*sizeof(float), "stride not 3 floats (got %u)!\n", stride);
567 /* Shaders */
568 hr = IDirect3DDevice8_CreateVertexShader(device, decl, simple_vs, &dVertexShader, 0);
569 CHECK_CALL(hr, "CreateVertexShader", device, refcount);
570 if (caps.PixelShaderVersion >= D3DPS_VERSION(1, 0))
572 hr = IDirect3DDevice8_CreatePixelShader(device, simple_ps, &dPixelShader);
573 CHECK_CALL(hr, "CreatePixelShader", device, refcount);
575 /* Textures */
576 hr = IDirect3DDevice8_CreateTexture(device, 32, 32, 3, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pTexture);
577 CHECK_CALL(hr, "CreateTexture", device, ++refcount);
578 if (pTexture)
580 tmp = get_refcount( (IUnknown *)pTexture );
582 /* SetTexture should not increase refcounts */
583 hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *) pTexture);
584 CHECK_CALL( hr, "SetTexture", pTexture, tmp);
585 hr = IDirect3DDevice8_SetTexture(device, 0, NULL);
586 CHECK_CALL( hr, "SetTexture", pTexture, tmp);
588 /* This should not increment device refcount */
589 hr = IDirect3DTexture8_GetSurfaceLevel( pTexture, 1, &pTextureLevel );
590 CHECK_CALL(hr, "GetSurfaceLevel", device, refcount);
591 /* But should increment texture's refcount */
592 CHECK_REFCOUNT( pTexture, tmp+1 );
593 /* Because the texture and surface refcount are identical */
594 if (pTextureLevel)
596 CHECK_REFCOUNT ( pTextureLevel, tmp+1 );
597 CHECK_ADDREF_REFCOUNT ( pTextureLevel, tmp+2 );
598 CHECK_REFCOUNT ( pTexture , tmp+2 );
599 CHECK_RELEASE_REFCOUNT( pTextureLevel, tmp+1 );
600 CHECK_REFCOUNT ( pTexture , tmp+1 );
601 CHECK_RELEASE_REFCOUNT( pTexture , tmp );
602 CHECK_REFCOUNT ( pTextureLevel, tmp );
605 if(caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP)
607 hr = IDirect3DDevice8_CreateCubeTexture(device, 32, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pCubeTexture);
608 CHECK_CALL(hr, "CreateCubeTexture", device, ++refcount);
610 else
612 skip("Cube textures not supported\n");
614 if(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP)
616 hr = IDirect3DDevice8_CreateVolumeTexture(device, 32, 32, 2, 0, 0,
617 D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pVolumeTexture);
618 CHECK_CALL(hr, "CreateVolumeTexture", device, ++refcount);
620 else
622 skip("Volume textures not supported\n");
625 if (pVolumeTexture)
627 tmp = get_refcount( (IUnknown *)pVolumeTexture );
629 /* This should not increment device refcount */
630 hr = IDirect3DVolumeTexture8_GetVolumeLevel(pVolumeTexture, 0, &pVolumeLevel);
631 CHECK_CALL(hr, "GetVolumeLevel", device, refcount);
632 /* But should increment volume texture's refcount */
633 CHECK_REFCOUNT( pVolumeTexture, tmp+1 );
634 /* Because the volume texture and volume refcount are identical */
635 if (pVolumeLevel)
637 CHECK_REFCOUNT ( pVolumeLevel , tmp+1 );
638 CHECK_ADDREF_REFCOUNT ( pVolumeLevel , tmp+2 );
639 CHECK_REFCOUNT ( pVolumeTexture, tmp+2 );
640 CHECK_RELEASE_REFCOUNT( pVolumeLevel , tmp+1 );
641 CHECK_REFCOUNT ( pVolumeTexture, tmp+1 );
642 CHECK_RELEASE_REFCOUNT( pVolumeTexture, tmp );
643 CHECK_REFCOUNT ( pVolumeLevel , tmp );
646 /* Surfaces */
647 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 32, 32,
648 D3DFMT_D16, D3DMULTISAMPLE_NONE, &pStencilSurface);
649 CHECK_CALL(hr, "CreateDepthStencilSurface", device, ++refcount);
650 CHECK_REFCOUNT( pStencilSurface, 1);
651 hr = IDirect3DDevice8_CreateImageSurface(device, 32, 32,
652 D3DFMT_X8R8G8B8, &pImageSurface);
653 CHECK_CALL(hr, "CreateImageSurface", device, ++refcount);
654 CHECK_REFCOUNT( pImageSurface, 1);
655 hr = IDirect3DDevice8_CreateRenderTarget(device, 32, 32,
656 D3DFMT_X8R8G8B8, D3DMULTISAMPLE_NONE, TRUE, &pRenderTarget3);
657 CHECK_CALL(hr, "CreateRenderTarget", device, ++refcount);
658 CHECK_REFCOUNT( pRenderTarget3, 1);
659 /* Misc */
660 hr = IDirect3DDevice8_CreateStateBlock(device, D3DSBT_ALL, &dStateBlock);
661 CHECK_CALL(hr, "CreateStateBlock", device, refcount);
663 memset(&d3dpp, 0, sizeof(d3dpp));
664 d3dpp.Windowed = TRUE;
665 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
666 d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
667 d3dpp.EnableAutoDepthStencil = TRUE;
668 d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
669 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &pSwapChain);
670 CHECK_CALL(hr, "CreateAdditionalSwapChain", device, ++refcount);
671 if(pSwapChain)
673 /* check implicit back buffer */
674 hr = IDirect3DSwapChain8_GetBackBuffer(pSwapChain, 0, 0, &pBackBuffer);
675 CHECK_CALL(hr, "GetBackBuffer", device, ++refcount);
676 CHECK_REFCOUNT( pSwapChain, 1);
677 if(pBackBuffer)
679 CHECK_SURFACE_CONTAINER(pBackBuffer, IID_IDirect3DDevice8, device);
680 CHECK_REFCOUNT( pBackBuffer, 1);
681 CHECK_RELEASE_REFCOUNT( pBackBuffer, 0);
682 CHECK_REFCOUNT(device, --refcount);
684 /* The back buffer is released with the swapchain, so AddRef with refcount=0 is fine here. */
685 CHECK_ADDREF_REFCOUNT(pBackBuffer, 1);
686 CHECK_REFCOUNT(device, ++refcount);
687 CHECK_RELEASE_REFCOUNT(pBackBuffer, 0);
688 CHECK_REFCOUNT(device, --refcount);
689 pBackBuffer = NULL;
691 CHECK_REFCOUNT( pSwapChain, 1);
694 if(pVertexBuffer)
696 BYTE *data;
697 /* Vertex buffers can be locked multiple times */
698 hr = IDirect3DVertexBuffer8_Lock(pVertexBuffer, 0, 0, &data, 0);
699 ok(hr == D3D_OK, "IDirect3DVertexBuffer8::Lock failed with %#08x\n", hr);
700 hr = IDirect3DVertexBuffer8_Lock(pVertexBuffer, 0, 0, &data, 0);
701 ok(hr == D3D_OK, "IDirect3DVertexBuffer8::Lock failed with %#08x\n", hr);
702 hr = IDirect3DVertexBuffer8_Unlock(pVertexBuffer);
703 ok(hr == D3D_OK, "IDirect3DVertexBuffer8::Unlock failed with %#08x\n", hr);
704 hr = IDirect3DVertexBuffer8_Unlock(pVertexBuffer);
705 ok(hr == D3D_OK, "IDirect3DVertexBuffer8::Unlock failed with %#08x\n", hr);
708 /* The implicit render target is not freed if refcount reaches 0.
709 * Otherwise GetRenderTarget would re-allocate it and the pointer would change.*/
710 hr = IDirect3DDevice8_GetRenderTarget(device, &pRenderTarget2);
711 CHECK_CALL(hr, "GetRenderTarget", device, ++refcount);
712 if(pRenderTarget2)
714 CHECK_RELEASE_REFCOUNT(pRenderTarget2, 0);
715 ok(pRenderTarget == pRenderTarget2, "RenderTarget=%p and RenderTarget2=%p should be the same.\n",
716 pRenderTarget, pRenderTarget2);
717 CHECK_REFCOUNT(device, --refcount);
718 pRenderTarget2 = NULL;
720 pRenderTarget = NULL;
722 cleanup:
723 CHECK_RELEASE(device, device, --refcount);
725 /* Buffers */
726 CHECK_RELEASE(pVertexBuffer, device, --refcount);
727 CHECK_RELEASE(pIndexBuffer, device, --refcount);
728 /* Shaders */
729 if (dVertexShader != ~0u)
730 IDirect3DDevice8_DeleteVertexShader(device, dVertexShader);
731 if (dPixelShader != ~0u)
732 IDirect3DDevice8_DeletePixelShader(device, dPixelShader);
733 /* Textures */
734 CHECK_RELEASE(pTexture, device, --refcount);
735 CHECK_RELEASE(pCubeTexture, device, --refcount);
736 CHECK_RELEASE(pVolumeTexture, device, --refcount);
737 /* Surfaces */
738 CHECK_RELEASE(pStencilSurface, device, --refcount);
739 CHECK_RELEASE(pImageSurface, device, --refcount);
740 CHECK_RELEASE(pRenderTarget3, device, --refcount);
741 /* Misc */
742 if (dStateBlock != ~0u)
743 IDirect3DDevice8_DeleteStateBlock(device, dStateBlock);
744 /* This will destroy device - cannot check the refcount here */
745 if (pSwapChain)
746 CHECK_RELEASE_REFCOUNT(pSwapChain, 0);
747 CHECK_RELEASE_REFCOUNT(d3d, 0);
748 DestroyWindow(window);
751 static void test_cursor(void)
753 HMODULE user32_handle = GetModuleHandleA("user32.dll");
754 IDirect3DSurface8 *cursor = NULL;
755 IDirect3DDevice8 *device;
756 CURSORINFO info;
757 IDirect3D8 *d3d;
758 ULONG refcount;
759 HCURSOR cur;
760 HWND window;
761 HRESULT hr;
762 BOOL ret;
764 pGetCursorInfo = (void *)GetProcAddress(user32_handle, "GetCursorInfo");
765 if (!pGetCursorInfo)
767 win_skip("GetCursorInfo is not available\n");
768 return;
771 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
772 0, 0, 640, 480, NULL, NULL, NULL, NULL);
773 ok(!!window, "Failed to create a window.\n");
775 ret = SetCursorPos(50, 50);
776 ok(ret, "Failed to set cursor position.\n");
777 flush_events();
779 memset(&info, 0, sizeof(info));
780 info.cbSize = sizeof(info);
781 ok(pGetCursorInfo(&info), "GetCursorInfo failed\n");
782 cur = info.hCursor;
784 d3d = Direct3DCreate8(D3D_SDK_VERSION);
785 ok(!!d3d, "Failed to create a D3D object.\n");
786 if (!(device = create_device(d3d, window, NULL)))
788 skip("Failed to create a 3D device, skipping test.\n");
789 goto cleanup;
792 hr = IDirect3DDevice8_CreateImageSurface(device, 32, 32, D3DFMT_A8R8G8B8, &cursor);
793 ok(SUCCEEDED(hr), "Failed to create cursor surface, hr %#x.\n", hr);
795 /* Initially hidden */
796 hr = IDirect3DDevice8_ShowCursor(device, TRUE);
797 ok(hr == FALSE, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr);
799 /* Not enabled without a surface*/
800 hr = IDirect3DDevice8_ShowCursor(device, TRUE);
801 ok(hr == FALSE, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr);
803 /* Fails */
804 hr = IDirect3DDevice8_SetCursorProperties(device, 0, 0, NULL);
805 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_SetCursorProperties returned %#08x\n", hr);
807 hr = IDirect3DDevice8_SetCursorProperties(device, 0, 0, cursor);
808 ok(hr == D3D_OK, "IDirect3DDevice8_SetCursorProperties returned %#08x\n", hr);
810 IDirect3DSurface8_Release(cursor);
812 memset(&info, 0, sizeof(info));
813 info.cbSize = sizeof(info);
814 ok(pGetCursorInfo(&info), "GetCursorInfo failed\n");
815 ok(info.flags & CURSOR_SHOWING, "The gdi cursor is hidden (%08x)\n", info.flags);
816 ok(info.hCursor == cur, "The cursor handle is %p\n", info.hCursor); /* unchanged */
818 /* Still hidden */
819 hr = IDirect3DDevice8_ShowCursor(device, TRUE);
820 ok(hr == FALSE, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr);
822 /* Enabled now*/
823 hr = IDirect3DDevice8_ShowCursor(device, TRUE);
824 ok(hr == TRUE, "IDirect3DDevice8_ShowCursor returned %#08x\n", hr);
826 memset(&info, 0, sizeof(info));
827 info.cbSize = sizeof(info);
828 ok(pGetCursorInfo(&info), "GetCursorInfo failed\n");
829 ok(info.flags & CURSOR_SHOWING, "The gdi cursor is hidden (%08x)\n", info.flags);
830 ok(info.hCursor != cur, "The cursor handle is %p\n", info.hCursor);
832 refcount = IDirect3DDevice8_Release(device);
833 ok(!refcount, "Device has %u references left.\n", refcount);
834 cleanup:
835 IDirect3D8_Release(d3d);
836 DestroyWindow(window);
839 static const POINT *expect_pos;
841 static LRESULT CALLBACK test_cursor_proc(HWND window, UINT message, WPARAM wparam, LPARAM lparam)
843 if (message == WM_MOUSEMOVE)
845 if (expect_pos && expect_pos->x && expect_pos->y)
847 POINT p = {GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam)};
849 ClientToScreen(window, &p);
850 if (expect_pos->x == p.x && expect_pos->y == p.y)
851 ++expect_pos;
855 return DefWindowProcA(window, message, wparam, lparam);
858 static void test_cursor_pos(void)
860 IDirect3DSurface8 *cursor;
861 IDirect3DDevice8 *device;
862 WNDCLASSA wc = {0};
863 IDirect3D8 *d3d8;
864 UINT refcount;
865 HWND window;
866 HRESULT hr;
867 BOOL ret;
869 /* Note that we don't check for movement we're not supposed to receive.
870 * That's because it's hard to distinguish from the user accidentally
871 * moving the mouse. */
872 static const POINT points[] =
874 {50, 50},
875 {75, 75},
876 {100, 100},
877 {125, 125},
878 {150, 150},
879 {125, 125},
880 {150, 150},
881 {150, 150},
882 {0, 0},
885 wc.lpfnWndProc = test_cursor_proc;
886 wc.lpszClassName = "d3d8_test_cursor_wc";
887 ok(RegisterClassA(&wc), "Failed to register window class.\n");
888 window = CreateWindowA("d3d8_test_cursor_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
889 0, 0, 320, 240, NULL, NULL, NULL, NULL);
890 ShowWindow(window, SW_SHOW);
891 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
892 ok(!!d3d8, "Failed to create a D3D object.\n");
894 if (!(device = create_device(d3d8, window, NULL)))
896 skip("Failed to create a D3D device, skipping tests.\n");
897 goto done;
900 hr = IDirect3DDevice8_CreateImageSurface(device, 32, 32, D3DFMT_A8R8G8B8, &cursor);
901 ok(SUCCEEDED(hr), "Failed to create cursor surface, hr %#x.\n", hr);
902 hr = IDirect3DDevice8_SetCursorProperties(device, 0, 0, cursor);
903 ok(SUCCEEDED(hr), "Failed to set cursor properties, hr %#x.\n", hr);
904 IDirect3DSurface8_Release(cursor);
905 ret = IDirect3DDevice8_ShowCursor(device, TRUE);
906 ok(!ret, "Failed to show cursor, hr %#x.\n", ret);
908 flush_events();
909 expect_pos = points;
911 ret = SetCursorPos(50, 50);
912 ok(ret, "Failed to set cursor position.\n");
913 flush_events();
915 IDirect3DDevice8_SetCursorPosition(device, 75, 75, 0);
916 flush_events();
917 /* SetCursorPosition() eats duplicates. */
918 IDirect3DDevice8_SetCursorPosition(device, 75, 75, 0);
919 flush_events();
921 ret = SetCursorPos(100, 100);
922 ok(ret, "Failed to set cursor position.\n");
923 flush_events();
924 /* Even if the position was set with SetCursorPos(). */
925 IDirect3DDevice8_SetCursorPosition(device, 100, 100, 0);
926 flush_events();
928 IDirect3DDevice8_SetCursorPosition(device, 125, 125, 0);
929 flush_events();
930 ret = SetCursorPos(150, 150);
931 ok(ret, "Failed to set cursor position.\n");
932 flush_events();
933 IDirect3DDevice8_SetCursorPosition(device, 125, 125, 0);
934 flush_events();
936 IDirect3DDevice8_SetCursorPosition(device, 150, 150, 0);
937 flush_events();
938 /* SetCursorPos() doesn't. */
939 ret = SetCursorPos(150, 150);
940 ok(ret, "Failed to set cursor position.\n");
941 flush_events();
943 ok(!expect_pos->x && !expect_pos->y, "Didn't receive MOUSEMOVE %u (%d, %d).\n",
944 (unsigned)(expect_pos - points), expect_pos->x, expect_pos->y);
946 refcount = IDirect3DDevice8_Release(device);
947 ok(!refcount, "Device has %u references left.\n", refcount);
948 done:
949 DestroyWindow(window);
950 UnregisterClassA("d3d8_test_cursor_wc", GetModuleHandleA(NULL));
951 IDirect3D8_Release(d3d8);
954 static void test_states(void)
956 IDirect3DDevice8 *device;
957 IDirect3D8 *d3d;
958 ULONG refcount;
959 HWND window;
960 HRESULT hr;
962 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
963 0, 0, 640, 480, NULL, NULL, NULL, NULL);
964 ok(!!window, "Failed to create a window.\n");
965 d3d = Direct3DCreate8(D3D_SDK_VERSION);
966 ok(!!d3d, "Failed to create a D3D object.\n");
967 if (!(device = create_device(d3d, window, NULL)))
969 skip("Failed to create a 3D device, skipping test.\n");
970 goto cleanup;
973 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZVISIBLE, TRUE);
974 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState(D3DRS_ZVISIBLE, TRUE) returned %#08x\n", hr);
975 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZVISIBLE, FALSE);
976 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState(D3DRS_ZVISIBLE, FALSE) returned %#08x\n", hr);
978 refcount = IDirect3DDevice8_Release(device);
979 ok(!refcount, "Device has %u references left.\n", refcount);
980 cleanup:
981 IDirect3D8_Release(d3d);
982 DestroyWindow(window);
985 static void test_shader_versions(void)
987 IDirect3D8 *d3d;
988 D3DCAPS8 caps;
989 HRESULT hr;
991 d3d = Direct3DCreate8(D3D_SDK_VERSION);
992 ok(!!d3d, "Failed to create a D3D object.\n");
994 hr = IDirect3D8_GetDeviceCaps(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps);
995 ok(SUCCEEDED(hr) || hr == D3DERR_NOTAVAILABLE, "Failed to get device caps, hr %#x.\n", hr);
996 IDirect3D8_Release(d3d);
997 if (FAILED(hr))
999 skip("No Direct3D support, skipping test.\n");
1000 return;
1003 ok(caps.VertexShaderVersion <= D3DVS_VERSION(1,1),
1004 "Got unexpected VertexShaderVersion %#x.\n", caps.VertexShaderVersion);
1005 ok(caps.PixelShaderVersion <= D3DPS_VERSION(1,4),
1006 "Got unexpected PixelShaderVersion %#x.\n", caps.PixelShaderVersion);
1009 static void test_display_formats(void)
1011 D3DDEVTYPE device_type = D3DDEVTYPE_HAL;
1012 unsigned int backbuffer, display;
1013 unsigned int windowed, i;
1014 D3DDISPLAYMODE mode;
1015 IDirect3D8 *d3d8;
1016 BOOL should_pass;
1017 BOOL has_modes;
1018 HRESULT hr;
1020 static const struct
1022 const char *name;
1023 D3DFORMAT format;
1024 D3DFORMAT alpha_format;
1025 BOOL display;
1026 BOOL windowed;
1028 formats[] =
1030 {"D3DFMT_R5G6B5", D3DFMT_R5G6B5, 0, TRUE, TRUE},
1031 {"D3DFMT_X1R5G5B5", D3DFMT_X1R5G5B5, D3DFMT_A1R5G5B5, TRUE, TRUE},
1032 {"D3DFMT_A1R5G5B5", D3DFMT_A1R5G5B5, D3DFMT_A1R5G5B5, FALSE, FALSE},
1033 {"D3DFMT_X8R8G8B8", D3DFMT_X8R8G8B8, D3DFMT_A8R8G8B8, TRUE, TRUE},
1034 {"D3DFMT_A8R8G8B8", D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, FALSE, FALSE},
1035 {"D3DFMT_UNKNOWN", D3DFMT_UNKNOWN, 0, FALSE, FALSE},
1038 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
1039 ok(!!d3d8, "Failed to create a D3D object.\n");
1041 for (display = 0; display < sizeof(formats) / sizeof(*formats); ++display)
1043 for (i = 0, has_modes = FALSE; SUCCEEDED(IDirect3D8_EnumAdapterModes(d3d8, D3DADAPTER_DEFAULT, i, &mode)); ++i)
1045 if (mode.Format == formats[display].format)
1047 has_modes = TRUE;
1048 break;
1052 for (windowed = 0; windowed <= 1; ++windowed)
1054 for (backbuffer = 0; backbuffer < sizeof(formats) / sizeof(*formats); ++backbuffer)
1056 should_pass = FALSE;
1058 if (formats[display].display && (formats[display].windowed || !windowed) && (has_modes || windowed))
1060 D3DFORMAT backbuffer_format;
1062 if (windowed && formats[backbuffer].format == D3DFMT_UNKNOWN)
1063 backbuffer_format = formats[display].format;
1064 else
1065 backbuffer_format = formats[backbuffer].format;
1067 hr = IDirect3D8_CheckDeviceFormat(d3d8, D3DADAPTER_DEFAULT, device_type, formats[display].format,
1068 D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, backbuffer_format);
1069 should_pass = (hr == D3D_OK) && (formats[display].format == formats[backbuffer].format
1070 || (formats[display].alpha_format
1071 && formats[display].alpha_format == formats[backbuffer].alpha_format));
1074 hr = IDirect3D8_CheckDeviceType(d3d8, D3DADAPTER_DEFAULT, device_type,
1075 formats[display].format, formats[backbuffer].format, windowed);
1076 ok(SUCCEEDED(hr) == should_pass || broken(SUCCEEDED(hr) && !has_modes) /* Win8 64-bit */,
1077 "Got unexpected hr %#x for %s / %s, windowed %#x, should_pass %#x.\n",
1078 hr, formats[display].name, formats[backbuffer].name, windowed, should_pass);
1083 IDirect3D8_Release(d3d8);
1086 /* Test adapter display modes */
1087 static void test_display_modes(void)
1089 UINT max_modes, i;
1090 D3DDISPLAYMODE dmode;
1091 IDirect3D8 *d3d;
1092 HRESULT res;
1094 d3d = Direct3DCreate8(D3D_SDK_VERSION);
1095 ok(!!d3d, "Failed to create a D3D object.\n");
1097 max_modes = IDirect3D8_GetAdapterModeCount(d3d, D3DADAPTER_DEFAULT);
1098 ok(max_modes > 0 ||
1099 broken(max_modes == 0), /* VMware */
1100 "GetAdapterModeCount(D3DADAPTER_DEFAULT) returned 0!\n");
1102 for (i = 0; i < max_modes; ++i)
1104 res = IDirect3D8_EnumAdapterModes(d3d, D3DADAPTER_DEFAULT, i, &dmode);
1105 ok(res==D3D_OK, "EnumAdapterModes returned %#08x for mode %u!\n", res, i);
1106 if(res != D3D_OK)
1107 continue;
1109 ok(dmode.Format==D3DFMT_X8R8G8B8 || dmode.Format==D3DFMT_R5G6B5,
1110 "Unexpected display mode returned for mode %u: %#x\n", i , dmode.Format);
1113 IDirect3D8_Release(d3d);
1116 static void test_reset(void)
1118 UINT width, orig_width = GetSystemMetrics(SM_CXSCREEN);
1119 UINT height, orig_height = GetSystemMetrics(SM_CYSCREEN);
1120 IDirect3DDevice8 *device1 = NULL;
1121 IDirect3DDevice8 *device2 = NULL;
1122 struct device_desc device_desc;
1123 D3DDISPLAYMODE d3ddm, d3ddm2;
1124 D3DSURFACE_DESC surface_desc;
1125 D3DPRESENT_PARAMETERS d3dpp;
1126 IDirect3DSurface8 *surface;
1127 IDirect3DTexture8 *texture;
1128 UINT adapter_mode_count;
1129 D3DLOCKED_RECT lockrect;
1130 UINT mode_count = 0;
1131 IDirect3D8 *d3d8;
1132 RECT winrect;
1133 D3DVIEWPORT8 vp;
1134 D3DCAPS8 caps;
1135 DWORD shader;
1136 DWORD value;
1137 HWND window;
1138 HRESULT hr;
1139 UINT i;
1141 static const DWORD decl[] =
1143 D3DVSD_STREAM(0),
1144 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT4),
1145 D3DVSD_END(),
1148 struct
1150 UINT w;
1151 UINT h;
1152 } *modes = NULL;
1154 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
1155 100, 100, 160, 160, NULL, NULL, NULL, NULL);
1156 ok(!!window, "Failed to create a window.\n");
1157 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
1158 ok(!!d3d8, "Failed to create a D3D object.\n");
1160 hr = IDirect3D8_GetAdapterDisplayMode(d3d8, D3DADAPTER_DEFAULT, &d3ddm);
1161 ok(SUCCEEDED(hr), "GetAdapterDisplayMode failed, hr %#x.\n", hr);
1162 adapter_mode_count = IDirect3D8_GetAdapterModeCount(d3d8, D3DADAPTER_DEFAULT);
1163 modes = HeapAlloc(GetProcessHeap(), 0, sizeof(*modes) * adapter_mode_count);
1164 for (i = 0; i < adapter_mode_count; ++i)
1166 UINT j;
1168 memset(&d3ddm2, 0, sizeof(d3ddm2));
1169 hr = IDirect3D8_EnumAdapterModes(d3d8, D3DADAPTER_DEFAULT, i, &d3ddm2);
1170 ok(SUCCEEDED(hr), "EnumAdapterModes failed, hr %#x.\n", hr);
1172 if (d3ddm2.Format != d3ddm.Format)
1173 continue;
1175 for (j = 0; j < mode_count; ++j)
1177 if (modes[j].w == d3ddm2.Width && modes[j].h == d3ddm2.Height)
1178 break;
1180 if (j == mode_count)
1182 modes[j].w = d3ddm2.Width;
1183 modes[j].h = d3ddm2.Height;
1184 ++mode_count;
1187 /* We use them as invalid modes. */
1188 if ((d3ddm2.Width == 801 && d3ddm2.Height == 600)
1189 || (d3ddm2.Width == 32 && d3ddm2.Height == 32))
1191 skip("This system supports a screen resolution of %dx%d, not running mode tests.\n",
1192 d3ddm2.Width, d3ddm2.Height);
1193 goto cleanup;
1197 if (mode_count < 2)
1199 skip("Less than 2 modes supported, skipping mode tests.\n");
1200 goto cleanup;
1203 i = 0;
1204 if (modes[i].w == orig_width && modes[i].h == orig_height) ++i;
1206 device_desc.width = modes[i].w;
1207 device_desc.height = modes[i].h;
1208 device_desc.device_window = window;
1209 device_desc.flags = CREATE_DEVICE_FULLSCREEN | CREATE_DEVICE_SWVP_ONLY;
1210 if (!(device1 = create_device(d3d8, window, &device_desc)))
1212 skip("Failed to create a D3D device, skipping tests.\n");
1213 goto cleanup;
1215 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1216 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1218 hr = IDirect3DDevice8_GetDeviceCaps(device1, &caps);
1219 ok(SUCCEEDED(hr), "GetDeviceCaps failed, hr %#x.\n", hr);
1221 width = GetSystemMetrics(SM_CXSCREEN);
1222 height = GetSystemMetrics(SM_CYSCREEN);
1223 ok(width == modes[i].w, "Screen width is %u, expected %u.\n", width, modes[i].w);
1224 ok(height == modes[i].h, "Screen height is %u, expected %u.\n", height, modes[i].h);
1226 hr = IDirect3DDevice8_GetViewport(device1, &vp);
1227 ok(SUCCEEDED(hr), "GetViewport failed, hr %#x.\n", hr);
1228 if (SUCCEEDED(hr))
1230 ok(vp.X == 0, "D3DVIEWPORT->X = %u, expected 0.\n", vp.X);
1231 ok(vp.Y == 0, "D3DVIEWPORT->Y = %u, expected 0.\n", vp.Y);
1232 ok(vp.Width == modes[i].w, "D3DVIEWPORT->Width = %u, expected %u.\n", vp.Width, modes[i].w);
1233 ok(vp.Height == modes[i].h, "D3DVIEWPORT->Height = %u, expected %u.\n", vp.Height, modes[i].h);
1234 ok(vp.MinZ == 0, "D3DVIEWPORT->MinZ = %.8e, expected 0.\n", vp.MinZ);
1235 ok(vp.MaxZ == 1, "D3DVIEWPORT->MaxZ = %.8e, expected 1.\n", vp.MaxZ);
1238 i = 1;
1239 vp.X = 10;
1240 vp.Y = 20;
1241 vp.Width = modes[i].w / 2;
1242 vp.Height = modes[i].h / 2;
1243 vp.MinZ = 0.2f;
1244 vp.MaxZ = 0.3f;
1245 hr = IDirect3DDevice8_SetViewport(device1, &vp);
1246 ok(SUCCEEDED(hr), "SetViewport failed, hr %#x.\n", hr);
1248 hr = IDirect3DDevice8_GetRenderState(device1, D3DRS_LIGHTING, &value);
1249 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1250 ok(!!value, "Got unexpected value %#x for D3DRS_LIGHTING.\n", value);
1251 hr = IDirect3DDevice8_SetRenderState(device1, D3DRS_LIGHTING, FALSE);
1252 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
1254 memset(&d3dpp, 0, sizeof(d3dpp));
1255 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1256 d3dpp.Windowed = FALSE;
1257 d3dpp.BackBufferWidth = modes[i].w;
1258 d3dpp.BackBufferHeight = modes[i].h;
1259 d3dpp.BackBufferFormat = d3ddm.Format;
1260 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1261 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1262 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1263 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1265 hr = IDirect3DDevice8_GetRenderState(device1, D3DRS_LIGHTING, &value);
1266 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1267 ok(!!value, "Got unexpected value %#x for D3DRS_LIGHTING.\n", value);
1269 memset(&vp, 0, sizeof(vp));
1270 hr = IDirect3DDevice8_GetViewport(device1, &vp);
1271 ok(SUCCEEDED(hr), "GetViewport failed, hr %#x.\n", hr);
1272 if (SUCCEEDED(hr))
1274 ok(vp.X == 0, "D3DVIEWPORT->X = %u, expected 0.\n", vp.X);
1275 ok(vp.Y == 0, "D3DVIEWPORT->Y = %u, expected 0.\n", vp.Y);
1276 ok(vp.Width == modes[i].w, "D3DVIEWPORT->Width = %u, expected %u.\n", vp.Width, modes[i].w);
1277 ok(vp.Height == modes[i].h, "D3DVIEWPORT->Height = %u, expected %u.\n", vp.Height, modes[i].h);
1278 ok(vp.MinZ == 0, "D3DVIEWPORT->MinZ = %.8e, expected 0.\n", vp.MinZ);
1279 ok(vp.MaxZ == 1, "D3DVIEWPORT->MaxZ = %.8e, expected 1.\n", vp.MaxZ);
1282 width = GetSystemMetrics(SM_CXSCREEN);
1283 height = GetSystemMetrics(SM_CYSCREEN);
1284 ok(width == modes[i].w, "Screen width is %u, expected %u.\n", width, modes[i].w);
1285 ok(height == modes[i].h, "Screen height is %u, expected %u.\n", height, modes[i].h);
1287 hr = IDirect3DDevice8_GetRenderTarget(device1, &surface);
1288 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
1289 hr = IDirect3DSurface8_GetDesc(surface, &surface_desc);
1290 ok(hr == D3D_OK, "GetDesc failed, hr %#x.\n", hr);
1291 ok(surface_desc.Width == modes[i].w, "Back buffer width is %u, expected %u.\n",
1292 surface_desc.Width, modes[i].w);
1293 ok(surface_desc.Height == modes[i].h, "Back buffer height is %u, expected %u.\n",
1294 surface_desc.Height, modes[i].h);
1295 IDirect3DSurface8_Release(surface);
1297 memset(&d3dpp, 0, sizeof(d3dpp));
1298 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1299 d3dpp.Windowed = TRUE;
1300 d3dpp.BackBufferWidth = 400;
1301 d3dpp.BackBufferHeight = 300;
1302 d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
1303 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1304 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1305 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1306 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1308 memset(&vp, 0, sizeof(vp));
1309 hr = IDirect3DDevice8_GetViewport(device1, &vp);
1310 ok(SUCCEEDED(hr), "GetViewport failed, hr %#x.\n", hr);
1311 if (SUCCEEDED(hr))
1313 ok(vp.X == 0, "D3DVIEWPORT->X = %u, expected 0.\n", vp.X);
1314 ok(vp.Y == 0, "D3DVIEWPORT->Y = %u, expected 0.\n", vp.Y);
1315 ok(vp.Width == 400, "D3DVIEWPORT->Width = %u, expected 400.\n", vp.Width);
1316 ok(vp.Height == 300, "D3DVIEWPORT->Height = %u, expected 300.\n", vp.Height);
1317 ok(vp.MinZ == 0, "D3DVIEWPORT->MinZ = %.8e, expected 0.\n", vp.MinZ);
1318 ok(vp.MaxZ == 1, "D3DVIEWPORT->MaxZ = %.8e, expected 1.\n", vp.MaxZ);
1321 width = GetSystemMetrics(SM_CXSCREEN);
1322 height = GetSystemMetrics(SM_CYSCREEN);
1323 ok(width == orig_width, "Screen width is %u, expected %u.\n", width, orig_width);
1324 ok(height == orig_height, "Screen height is %u, expected %u.\n", height, orig_height);
1326 hr = IDirect3DDevice8_GetRenderTarget(device1, &surface);
1327 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
1328 hr = IDirect3DSurface8_GetDesc(surface, &surface_desc);
1329 ok(hr == D3D_OK, "GetDesc failed, hr %#x.\n", hr);
1330 ok(surface_desc.Width == 400, "Back buffer width is %u, expected 400.\n",
1331 surface_desc.Width);
1332 ok(surface_desc.Height == 300, "Back buffer height is %u, expected 300.\n",
1333 surface_desc.Height);
1334 IDirect3DSurface8_Release(surface);
1336 winrect.left = 0;
1337 winrect.top = 0;
1338 winrect.right = 200;
1339 winrect.bottom = 150;
1340 ok(AdjustWindowRect(&winrect, WS_OVERLAPPEDWINDOW, FALSE), "AdjustWindowRect failed\n");
1341 ok(SetWindowPos(window, NULL, 0, 0,
1342 winrect.right-winrect.left,
1343 winrect.bottom-winrect.top,
1344 SWP_NOMOVE|SWP_NOZORDER),
1345 "SetWindowPos failed\n");
1347 memset(&d3dpp, 0, sizeof(d3dpp));
1348 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1349 d3dpp.Windowed = TRUE;
1350 d3dpp.BackBufferWidth = 0;
1351 d3dpp.BackBufferHeight = 0;
1352 d3dpp.BackBufferFormat = d3ddm.Format;
1353 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1354 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1355 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1356 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1358 ok(!d3dpp.BackBufferWidth, "Got unexpected BackBufferWidth %u.\n", d3dpp.BackBufferWidth);
1359 ok(!d3dpp.BackBufferHeight, "Got unexpected BackBufferHeight %u.\n", d3dpp.BackBufferHeight);
1360 ok(d3dpp.BackBufferFormat == d3ddm.Format, "Got unexpected BackBufferFormat %#x, expected %#x.\n",
1361 d3dpp.BackBufferFormat, d3ddm.Format);
1362 todo_wine ok(d3dpp.BackBufferCount == 1, "Got unexpected BackBufferCount %u.\n", d3dpp.BackBufferCount);
1363 ok(!d3dpp.MultiSampleType, "Got unexpected MultiSampleType %u.\n", d3dpp.MultiSampleType);
1364 ok(d3dpp.SwapEffect == D3DSWAPEFFECT_DISCARD, "Got unexpected SwapEffect %#x.\n", d3dpp.SwapEffect);
1365 ok(!d3dpp.hDeviceWindow, "Got unexpected hDeviceWindow %p.\n", d3dpp.hDeviceWindow);
1366 ok(d3dpp.Windowed, "Got unexpected Windowed %#x.\n", d3dpp.Windowed);
1367 ok(!d3dpp.EnableAutoDepthStencil, "Got unexpected EnableAutoDepthStencil %#x.\n", d3dpp.EnableAutoDepthStencil);
1368 ok(!d3dpp.AutoDepthStencilFormat, "Got unexpected AutoDepthStencilFormat %#x.\n", d3dpp.AutoDepthStencilFormat);
1369 ok(!d3dpp.Flags, "Got unexpected Flags %#x.\n", d3dpp.Flags);
1370 ok(!d3dpp.FullScreen_RefreshRateInHz, "Got unexpected FullScreen_RefreshRateInHz %u.\n",
1371 d3dpp.FullScreen_RefreshRateInHz);
1372 ok(!d3dpp.FullScreen_PresentationInterval, "Got unexpected FullScreen_PresentationInterval %#x.\n",
1373 d3dpp.FullScreen_PresentationInterval);
1375 memset(&vp, 0, sizeof(vp));
1376 hr = IDirect3DDevice8_GetViewport(device1, &vp);
1377 ok(SUCCEEDED(hr), "GetViewport failed, hr %#x.\n", hr);
1378 if (SUCCEEDED(hr))
1380 ok(vp.X == 0, "D3DVIEWPORT->X = %u, expected 0.\n", vp.X);
1381 ok(vp.Y == 0, "D3DVIEWPORT->Y = %u, expected 0.\n", vp.Y);
1382 ok(vp.Width == 200, "D3DVIEWPORT->Width = %u, expected 200.\n", vp.Width);
1383 ok(vp.Height == 150, "D3DVIEWPORT->Height = %u, expected 150.\n", vp.Height);
1384 ok(vp.MinZ == 0, "D3DVIEWPORT->MinZ = %.8e, expected 0.\n", vp.MinZ);
1385 ok(vp.MaxZ == 1, "D3DVIEWPORT->MaxZ = %.8e, expected 1.\n", vp.MaxZ);
1388 hr = IDirect3DDevice8_GetRenderTarget(device1, &surface);
1389 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
1390 hr = IDirect3DSurface8_GetDesc(surface, &surface_desc);
1391 ok(hr == D3D_OK, "GetDesc failed, hr %#x.\n", hr);
1392 ok(surface_desc.Format == d3ddm.Format, "Got unexpected Format %#x, expected %#x.\n",
1393 surface_desc.Format, d3ddm.Format);
1394 ok(!surface_desc.MultiSampleType, "Got unexpected MultiSampleType %u.\n", d3dpp.MultiSampleType);
1395 ok(surface_desc.Width == 200, "Back buffer width is %u, expected 200.\n", surface_desc.Width);
1396 ok(surface_desc.Height == 150, "Back buffer height is %u, expected 150.\n", surface_desc.Height);
1397 IDirect3DSurface8_Release(surface);
1399 memset(&d3dpp, 0, sizeof(d3dpp));
1400 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1401 d3dpp.Windowed = TRUE;
1402 d3dpp.BackBufferWidth = 400;
1403 d3dpp.BackBufferHeight = 300;
1404 d3dpp.BackBufferFormat = d3ddm.Format;
1406 /* Reset fails if there is a resource in the default pool. */
1407 hr = IDirect3DDevice8_CreateTexture(device1, 16, 16, 1, 0, D3DFMT_R5G6B5, D3DPOOL_DEFAULT, &texture);
1408 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
1409 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1410 ok(hr == D3DERR_DEVICELOST, "Reset returned %#x, expected %#x.\n", hr, D3DERR_DEVICELOST);
1411 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1412 ok(hr == D3DERR_DEVICENOTRESET, "TestCooperativeLevel returned %#x, expected %#x.\n", hr, D3DERR_DEVICENOTRESET);
1413 IDirect3DTexture8_Release(texture);
1414 /* Reset again to get the device out of the lost state. */
1415 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1416 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1417 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1418 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1420 if (caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP)
1422 IDirect3DVolumeTexture8 *volume_texture;
1424 hr = IDirect3DDevice8_CreateVolumeTexture(device1, 16, 16, 4, 1, 0,
1425 D3DFMT_R5G6B5, D3DPOOL_DEFAULT, &volume_texture);
1426 ok(SUCCEEDED(hr), "CreateVolumeTexture failed, hr %#x.\n", hr);
1427 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1428 ok(hr == D3DERR_DEVICELOST, "Reset returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
1429 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1430 ok(hr == D3DERR_DEVICENOTRESET, "TestCooperativeLevel returned %#x, expected %#x.\n",
1431 hr, D3DERR_DEVICENOTRESET);
1432 IDirect3DVolumeTexture8_Release(volume_texture);
1433 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1434 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1435 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1436 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1438 else
1440 skip("Volume textures not supported.\n");
1443 /* Scratch, sysmem and managed pool resources are fine. */
1444 hr = IDirect3DDevice8_CreateTexture(device1, 16, 16, 1, 0, D3DFMT_R5G6B5, D3DPOOL_SCRATCH, &texture);
1445 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
1446 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1447 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1448 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1449 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1450 IDirect3DTexture8_Release(texture);
1452 hr = IDirect3DDevice8_CreateTexture(device1, 16, 16, 1, 0, D3DFMT_R5G6B5, D3DPOOL_SYSTEMMEM, &texture);
1453 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
1454 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1455 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1456 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1457 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1458 IDirect3DTexture8_Release(texture);
1460 /* The depth stencil should get reset to the auto depth stencil when present. */
1461 hr = IDirect3DDevice8_SetRenderTarget(device1, NULL, NULL);
1462 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
1464 hr = IDirect3DDevice8_GetDepthStencilSurface(device1, &surface);
1465 ok(hr == D3DERR_NOTFOUND, "GetDepthStencilSurface returned %#x, expected %#x.\n", hr, D3DERR_NOTFOUND);
1466 ok(!surface, "Depth / stencil buffer should be NULL.\n");
1468 d3dpp.EnableAutoDepthStencil = TRUE;
1469 d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
1470 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1471 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1473 hr = IDirect3DDevice8_GetDepthStencilSurface(device1, &surface);
1474 ok(SUCCEEDED(hr), "GetDepthStencilSurface failed, hr %#x.\n", hr);
1475 ok(!!surface, "Depth / stencil buffer should not be NULL.\n");
1476 if (surface) IDirect3DSurface8_Release(surface);
1478 d3dpp.EnableAutoDepthStencil = FALSE;
1479 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1480 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1482 hr = IDirect3DDevice8_GetDepthStencilSurface(device1, &surface);
1483 ok(hr == D3DERR_NOTFOUND, "GetDepthStencilSurface returned %#x, expected %#x.\n", hr, D3DERR_NOTFOUND);
1484 ok(!surface, "Depth / stencil buffer should be NULL.\n");
1486 /* Will a sysmem or scratch resource survive while locked? */
1487 hr = IDirect3DDevice8_CreateTexture(device1, 16, 16, 1, 0, D3DFMT_R5G6B5, D3DPOOL_SYSTEMMEM, &texture);
1488 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
1489 hr = IDirect3DTexture8_LockRect(texture, 0, &lockrect, NULL, D3DLOCK_DISCARD);
1490 ok(SUCCEEDED(hr), "LockRect failed, hr %#x.\n", hr);
1491 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1492 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1493 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1494 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1495 IDirect3DTexture8_UnlockRect(texture, 0);
1496 IDirect3DTexture8_Release(texture);
1498 hr = IDirect3DDevice8_CreateTexture(device1, 16, 16, 1, 0, D3DFMT_R5G6B5, D3DPOOL_SCRATCH, &texture);
1499 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
1500 hr = IDirect3DTexture8_LockRect(texture, 0, &lockrect, NULL, D3DLOCK_DISCARD);
1501 ok(SUCCEEDED(hr), "LockRect failed, hr %#x.\n", hr);
1502 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1503 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1504 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1505 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1506 IDirect3DTexture8_UnlockRect(texture, 0);
1507 IDirect3DTexture8_Release(texture);
1509 hr = IDirect3DDevice8_CreateTexture(device1, 16, 16, 1, 0, D3DFMT_R5G6B5, D3DPOOL_MANAGED, &texture);
1510 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
1511 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1512 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1513 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1514 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1515 IDirect3DTexture8_Release(texture);
1517 /* A reference held to an implicit surface causes failures as well. */
1518 hr = IDirect3DDevice8_GetBackBuffer(device1, 0, D3DBACKBUFFER_TYPE_MONO, &surface);
1519 ok(SUCCEEDED(hr), "GetBackBuffer failed, hr %#x.\n", hr);
1520 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1521 ok(hr == D3DERR_DEVICELOST, "Reset returned %#x, expected %#x.\n", hr, D3DERR_DEVICELOST);
1522 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1523 ok(hr == D3DERR_DEVICENOTRESET, "TestCooperativeLevel returned %#x, expected %#x.\n", hr, D3DERR_DEVICENOTRESET);
1524 IDirect3DSurface8_Release(surface);
1525 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1526 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1527 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1528 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1530 /* Shaders are fine as well. */
1531 hr = IDirect3DDevice8_CreateVertexShader(device1, decl, simple_vs, &shader, 0);
1532 ok(SUCCEEDED(hr), "CreateVertexShader failed, hr %#x.\n", hr);
1533 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1534 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1535 hr = IDirect3DDevice8_DeleteVertexShader(device1, shader);
1536 ok(SUCCEEDED(hr), "DeleteVertexShader failed, hr %#x.\n", hr);
1538 /* Try setting invalid modes. */
1539 memset(&d3dpp, 0, sizeof(d3dpp));
1540 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1541 d3dpp.Windowed = FALSE;
1542 d3dpp.BackBufferWidth = 32;
1543 d3dpp.BackBufferHeight = 32;
1544 d3dpp.BackBufferFormat = d3ddm.Format;
1545 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1546 ok(hr == D3DERR_INVALIDCALL, "Reset returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
1547 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1548 ok(hr == D3DERR_DEVICENOTRESET, "TestCooperativeLevel returned %#x, expected %#x.\n", hr, D3DERR_DEVICENOTRESET);
1550 memset(&d3dpp, 0, sizeof(d3dpp));
1551 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1552 d3dpp.Windowed = FALSE;
1553 d3dpp.BackBufferWidth = 801;
1554 d3dpp.BackBufferHeight = 600;
1555 d3dpp.BackBufferFormat = d3ddm.Format;
1556 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1557 ok(hr == D3DERR_INVALIDCALL, "Reset returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
1558 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1559 ok(hr == D3DERR_DEVICENOTRESET, "TestCooperativeLevel returned %#x, expected %#x.\n", hr, D3DERR_DEVICENOTRESET);
1561 memset(&d3dpp, 0, sizeof(d3dpp));
1562 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1563 d3dpp.Windowed = FALSE;
1564 d3dpp.BackBufferWidth = 0;
1565 d3dpp.BackBufferHeight = 0;
1566 d3dpp.BackBufferFormat = d3ddm.Format;
1567 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1568 ok(hr == D3DERR_INVALIDCALL, "Reset returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
1569 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1570 ok(hr == D3DERR_DEVICENOTRESET, "TestCooperativeLevel returned %#x, expected %#x.\n", hr, D3DERR_DEVICENOTRESET);
1572 hr = IDirect3D8_GetAdapterDisplayMode(d3d8, D3DADAPTER_DEFAULT, &d3ddm);
1573 ok(SUCCEEDED(hr), "GetAdapterDisplayMode failed, hr %#x.\n", hr);
1575 memset(&d3dpp, 0, sizeof(d3dpp));
1576 d3dpp.Windowed = TRUE;
1577 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1578 d3dpp.BackBufferFormat = d3ddm.Format;
1579 d3dpp.EnableAutoDepthStencil = FALSE;
1580 d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
1582 hr = IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
1583 window, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &device2);
1584 if (FAILED(hr))
1586 skip("Failed to create device, hr %#x.\n", hr);
1587 goto cleanup;
1590 hr = IDirect3DDevice8_TestCooperativeLevel(device2);
1591 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1593 d3dpp.Windowed = TRUE;
1594 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1595 d3dpp.BackBufferWidth = 400;
1596 d3dpp.BackBufferHeight = 300;
1597 d3dpp.BackBufferFormat = d3ddm.Format;
1598 d3dpp.EnableAutoDepthStencil = TRUE;
1599 d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
1601 hr = IDirect3DDevice8_Reset(device2, &d3dpp);
1602 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1603 if (FAILED(hr))
1604 goto cleanup;
1606 hr = IDirect3DDevice8_GetDepthStencilSurface(device2, &surface);
1607 ok(SUCCEEDED(hr), "GetDepthStencilSurface failed, hr %#x.\n", hr);
1608 ok(!!surface, "Depth / stencil buffer should not be NULL.\n");
1609 if (surface)
1610 IDirect3DSurface8_Release(surface);
1612 cleanup:
1613 HeapFree(GetProcessHeap(), 0, modes);
1614 if (device2)
1615 IDirect3DDevice8_Release(device2);
1616 if (device1)
1617 IDirect3DDevice8_Release(device1);
1618 IDirect3D8_Release(d3d8);
1619 DestroyWindow(window);
1622 static void test_scene(void)
1624 IDirect3DDevice8 *device;
1625 IDirect3D8 *d3d;
1626 ULONG refcount;
1627 HWND window;
1628 HRESULT hr;
1630 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
1631 0, 0, 640, 480, NULL, NULL, NULL, NULL);
1632 ok(!!window, "Failed to create a window.\n");
1633 d3d = Direct3DCreate8(D3D_SDK_VERSION);
1634 ok(!!d3d, "Failed to create a D3D object.\n");
1635 if (!(device = create_device(d3d, window, NULL)))
1637 skip("Failed to create a 3D device, skipping test.\n");
1638 goto cleanup;
1641 /* Test an EndScene without BeginScene. Should return an error */
1642 hr = IDirect3DDevice8_EndScene(device);
1643 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_EndScene returned %#08x\n", hr);
1645 /* Test a normal BeginScene / EndScene pair, this should work */
1646 hr = IDirect3DDevice8_BeginScene(device);
1647 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr);
1648 hr = IDirect3DDevice8_EndScene(device);
1649 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed with %#08x\n", hr);
1651 /* Test another EndScene without having begun a new scene. Should return an error */
1652 hr = IDirect3DDevice8_EndScene(device);
1653 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_EndScene returned %#08x\n", hr);
1655 /* Two nested BeginScene and EndScene calls */
1656 hr = IDirect3DDevice8_BeginScene(device);
1657 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr);
1658 hr = IDirect3DDevice8_BeginScene(device);
1659 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_BeginScene returned %#08x\n", hr);
1660 hr = IDirect3DDevice8_EndScene(device);
1661 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed with %#08x\n", hr);
1662 hr = IDirect3DDevice8_EndScene(device);
1663 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_EndScene returned %#08x\n", hr);
1665 /* StretchRect does not exit in Direct3D8, so no equivalent to the d3d9 stretchrect tests */
1667 refcount = IDirect3DDevice8_Release(device);
1668 ok(!refcount, "Device has %u references left.\n", refcount);
1669 cleanup:
1670 IDirect3D8_Release(d3d);
1671 DestroyWindow(window);
1674 static void test_shader(void)
1676 DWORD hPixelShader = 0, hVertexShader = 0;
1677 DWORD hPixelShader2 = 0, hVertexShader2 = 0;
1678 DWORD hTempHandle;
1679 D3DCAPS8 caps;
1680 DWORD fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE;
1681 IDirect3DDevice8 *device;
1682 IDirect3D8 *d3d;
1683 DWORD data_size;
1684 ULONG refcount;
1685 HWND window;
1686 HRESULT hr;
1687 void *data;
1689 static DWORD dwVertexDecl[] =
1691 D3DVSD_STREAM(0),
1692 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3),
1693 D3DVSD_END()
1695 DWORD decl_normal_float2[] =
1697 D3DVSD_STREAM(0),
1698 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
1699 D3DVSD_REG(D3DVSDE_NORMAL, D3DVSDT_FLOAT2), /* D3DVSDE_NORMAL, Register v1 */
1700 D3DVSD_END()
1702 DWORD decl_normal_float4[] =
1704 D3DVSD_STREAM(0),
1705 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
1706 D3DVSD_REG(D3DVSDE_NORMAL, D3DVSDT_FLOAT4), /* D3DVSDE_NORMAL, Register v1 */
1707 D3DVSD_END()
1709 DWORD decl_normal_d3dcolor[] =
1711 D3DVSD_STREAM(0),
1712 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
1713 D3DVSD_REG(D3DVSDE_NORMAL, D3DVSDT_D3DCOLOR),/* D3DVSDE_NORMAL, Register v1 */
1714 D3DVSD_END()
1716 const DWORD vertex_decl_size = sizeof(dwVertexDecl);
1717 const DWORD simple_vs_size = sizeof(simple_vs);
1718 const DWORD simple_ps_size = sizeof(simple_ps);
1720 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
1721 0, 0, 640, 480, NULL, NULL, NULL, NULL);
1722 ok(!!window, "Failed to create a window.\n");
1723 d3d = Direct3DCreate8(D3D_SDK_VERSION);
1724 ok(!!d3d, "Failed to create a D3D object.\n");
1725 if (!(device = create_device(d3d, window, NULL)))
1727 skip("Failed to create a 3D device, skipping test.\n");
1728 goto cleanup;
1731 IDirect3DDevice8_GetDeviceCaps(device, &caps);
1733 /* Test setting and retrieving a FVF */
1734 hr = IDirect3DDevice8_SetVertexShader(device, fvf);
1735 ok(SUCCEEDED(hr), "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
1736 hr = IDirect3DDevice8_GetVertexShader(device, &hTempHandle);
1737 ok(SUCCEEDED(hr), "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
1738 ok(hTempHandle == fvf, "Vertex shader %#08x is set, expected %#08x\n", hTempHandle, fvf);
1740 /* First create a vertex shader */
1741 hr = IDirect3DDevice8_SetVertexShader(device, 0);
1742 ok(SUCCEEDED(hr), "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
1743 hr = IDirect3DDevice8_CreateVertexShader(device, dwVertexDecl, simple_vs, &hVertexShader, 0);
1744 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1745 /* Msdn says that the new vertex shader is set immediately. This is wrong, apparently */
1746 hr = IDirect3DDevice8_GetVertexShader(device, &hTempHandle);
1747 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
1748 ok(hTempHandle == 0, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, 0);
1749 /* Assign the shader, then verify that GetVertexShader works */
1750 hr = IDirect3DDevice8_SetVertexShader(device, hVertexShader);
1751 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
1752 hr = IDirect3DDevice8_GetVertexShader(device, &hTempHandle);
1753 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
1754 ok(hTempHandle == hVertexShader, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, hVertexShader);
1755 /* Verify that we can retrieve the declaration */
1756 hr = IDirect3DDevice8_GetVertexShaderDeclaration(device, hVertexShader, NULL, &data_size);
1757 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderDeclaration returned %#08x\n", hr);
1758 ok(data_size == vertex_decl_size, "Got data_size %u, expected %u\n", data_size, vertex_decl_size);
1759 data = HeapAlloc(GetProcessHeap(), 0, vertex_decl_size);
1760 data_size = 1;
1761 hr = IDirect3DDevice8_GetVertexShaderDeclaration(device, hVertexShader, data, &data_size);
1762 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_GetVertexShaderDeclaration returned (%#08x), "
1763 "expected D3DERR_INVALIDCALL\n", hr);
1764 ok(data_size == 1, "Got data_size %u, expected 1\n", data_size);
1765 data_size = vertex_decl_size;
1766 hr = IDirect3DDevice8_GetVertexShaderDeclaration(device, hVertexShader, data, &data_size);
1767 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderDeclaration returned %#08x\n", hr);
1768 ok(data_size == vertex_decl_size, "Got data_size %u, expected %u\n", data_size, vertex_decl_size);
1769 ok(!memcmp(data, dwVertexDecl, vertex_decl_size), "data not equal to shader declaration\n");
1770 HeapFree(GetProcessHeap(), 0, data);
1771 /* Verify that we can retrieve the shader function */
1772 hr = IDirect3DDevice8_GetVertexShaderFunction(device, hVertexShader, NULL, &data_size);
1773 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderFunction returned %#08x\n", hr);
1774 ok(data_size == simple_vs_size, "Got data_size %u, expected %u\n", data_size, simple_vs_size);
1775 data = HeapAlloc(GetProcessHeap(), 0, simple_vs_size);
1776 data_size = 1;
1777 hr = IDirect3DDevice8_GetVertexShaderFunction(device, hVertexShader, data, &data_size);
1778 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_GetVertexShaderFunction returned (%#08x), "
1779 "expected D3DERR_INVALIDCALL\n", hr);
1780 ok(data_size == 1, "Got data_size %u, expected 1\n", data_size);
1781 data_size = simple_vs_size;
1782 hr = IDirect3DDevice8_GetVertexShaderFunction(device, hVertexShader, data, &data_size);
1783 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderFunction returned %#08x\n", hr);
1784 ok(data_size == simple_vs_size, "Got data_size %u, expected %u\n", data_size, simple_vs_size);
1785 ok(!memcmp(data, simple_vs, simple_vs_size), "data not equal to shader function\n");
1786 HeapFree(GetProcessHeap(), 0, data);
1787 /* Delete the assigned shader. This is supposed to work */
1788 hr = IDirect3DDevice8_DeleteVertexShader(device, hVertexShader);
1789 ok(hr == D3D_OK, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
1790 /* The shader should be unset now */
1791 hr = IDirect3DDevice8_GetVertexShader(device, &hTempHandle);
1792 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
1793 ok(hTempHandle == 0, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, 0);
1795 /* Test a broken declaration. 3DMark2001 tries to use normals with 2 components
1796 * First try the fixed function shader function, then a custom one
1798 hr = IDirect3DDevice8_CreateVertexShader(device, decl_normal_float2, 0, &hVertexShader, 0);
1799 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1800 hr = IDirect3DDevice8_CreateVertexShader(device, decl_normal_float4, 0, &hVertexShader, 0);
1801 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1802 hr = IDirect3DDevice8_CreateVertexShader(device, decl_normal_d3dcolor, 0, &hVertexShader, 0);
1803 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1805 hr = IDirect3DDevice8_CreateVertexShader(device, decl_normal_float2, simple_vs, &hVertexShader, 0);
1806 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1807 IDirect3DDevice8_DeleteVertexShader(device, hVertexShader);
1809 if (caps.PixelShaderVersion >= D3DPS_VERSION(1, 0))
1811 /* The same with a pixel shader */
1812 hr = IDirect3DDevice8_CreatePixelShader(device, simple_ps, &hPixelShader);
1813 ok(hr == D3D_OK, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr);
1814 /* Msdn says that the new pixel shader is set immediately. This is wrong, apparently */
1815 hr = IDirect3DDevice8_GetPixelShader(device, &hTempHandle);
1816 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr);
1817 ok(hTempHandle == 0, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, 0);
1818 /* Assign the shader, then verify that GetPixelShader works */
1819 hr = IDirect3DDevice8_SetPixelShader(device, hPixelShader);
1820 ok(hr == D3D_OK, "IDirect3DDevice8_SetPixelShader returned %#08x\n", hr);
1821 hr = IDirect3DDevice8_GetPixelShader(device, &hTempHandle);
1822 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr);
1823 ok(hTempHandle == hPixelShader, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, hPixelShader);
1824 /* Verify that we can retrieve the shader function */
1825 hr = IDirect3DDevice8_GetPixelShaderFunction(device, hPixelShader, NULL, &data_size);
1826 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShaderFunction returned %#08x\n", hr);
1827 ok(data_size == simple_ps_size, "Got data_size %u, expected %u\n", data_size, simple_ps_size);
1828 data = HeapAlloc(GetProcessHeap(), 0, simple_ps_size);
1829 data_size = 1;
1830 hr = IDirect3DDevice8_GetPixelShaderFunction(device, hPixelShader, data, &data_size);
1831 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_GetPixelShaderFunction returned (%#08x), "
1832 "expected D3DERR_INVALIDCALL\n", hr);
1833 ok(data_size == 1, "Got data_size %u, expected 1\n", data_size);
1834 data_size = simple_ps_size;
1835 hr = IDirect3DDevice8_GetPixelShaderFunction(device, hPixelShader, data, &data_size);
1836 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShaderFunction returned %#08x\n", hr);
1837 ok(data_size == simple_ps_size, "Got data_size %u, expected %u\n", data_size, simple_ps_size);
1838 ok(!memcmp(data, simple_ps, simple_ps_size), "data not equal to shader function\n");
1839 HeapFree(GetProcessHeap(), 0, data);
1840 /* Delete the assigned shader. This is supposed to work */
1841 hr = IDirect3DDevice8_DeletePixelShader(device, hPixelShader);
1842 ok(hr == D3D_OK, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
1843 /* The shader should be unset now */
1844 hr = IDirect3DDevice8_GetPixelShader(device, &hTempHandle);
1845 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr);
1846 ok(hTempHandle == 0, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, 0);
1848 /* What happens if a non-bound shader is deleted? */
1849 hr = IDirect3DDevice8_CreatePixelShader(device, simple_ps, &hPixelShader);
1850 ok(hr == D3D_OK, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr);
1851 hr = IDirect3DDevice8_CreatePixelShader(device, simple_ps, &hPixelShader2);
1852 ok(hr == D3D_OK, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr);
1854 hr = IDirect3DDevice8_SetPixelShader(device, hPixelShader);
1855 ok(hr == D3D_OK, "IDirect3DDevice8_SetPixelShader returned %#08x\n", hr);
1856 hr = IDirect3DDevice8_DeletePixelShader(device, hPixelShader2);
1857 ok(hr == D3D_OK, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
1858 hr = IDirect3DDevice8_GetPixelShader(device, &hTempHandle);
1859 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr);
1860 ok(hTempHandle == hPixelShader, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, hPixelShader);
1861 hr = IDirect3DDevice8_DeletePixelShader(device, hPixelShader);
1862 ok(hr == D3D_OK, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
1864 /* Check for double delete. */
1865 hr = IDirect3DDevice8_DeletePixelShader(device, hPixelShader2);
1866 ok(hr == D3DERR_INVALIDCALL || broken(hr == D3D_OK), "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
1867 hr = IDirect3DDevice8_DeletePixelShader(device, hPixelShader);
1868 ok(hr == D3DERR_INVALIDCALL || broken(hr == D3D_OK), "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
1870 else
1872 skip("Pixel shaders not supported\n");
1875 /* What happens if a non-bound shader is deleted? */
1876 hr = IDirect3DDevice8_CreateVertexShader(device, dwVertexDecl, NULL, &hVertexShader, 0);
1877 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1878 hr = IDirect3DDevice8_CreateVertexShader(device, dwVertexDecl, NULL, &hVertexShader2, 0);
1879 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1881 hr = IDirect3DDevice8_SetVertexShader(device, hVertexShader);
1882 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
1883 hr = IDirect3DDevice8_DeleteVertexShader(device, hVertexShader2);
1884 ok(hr == D3D_OK, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
1885 hr = IDirect3DDevice8_GetVertexShader(device, &hTempHandle);
1886 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
1887 ok(hTempHandle == hVertexShader, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, hVertexShader);
1888 hr = IDirect3DDevice8_DeleteVertexShader(device, hVertexShader);
1889 ok(hr == D3D_OK, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
1891 /* Check for double delete. */
1892 hr = IDirect3DDevice8_DeleteVertexShader(device, hVertexShader2);
1893 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
1894 hr = IDirect3DDevice8_DeleteVertexShader(device, hVertexShader);
1895 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
1897 refcount = IDirect3DDevice8_Release(device);
1898 ok(!refcount, "Device has %u references left.\n", refcount);
1899 cleanup:
1900 IDirect3D8_Release(d3d);
1901 DestroyWindow(window);
1904 static void test_limits(void)
1906 IDirect3DTexture8 *texture;
1907 IDirect3DDevice8 *device;
1908 IDirect3D8 *d3d;
1909 unsigned int i;
1910 ULONG refcount;
1911 HWND window;
1912 HRESULT hr;
1914 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
1915 0, 0, 640, 480, NULL, NULL, NULL, NULL);
1916 ok(!!window, "Failed to create a window.\n");
1917 d3d = Direct3DCreate8(D3D_SDK_VERSION);
1918 ok(!!d3d, "Failed to create a D3D object.\n");
1919 if (!(device = create_device(d3d, window, NULL)))
1921 skip("Failed to create a 3D device, skipping test.\n");
1922 goto cleanup;
1925 hr = IDirect3DDevice8_CreateTexture(device, 16, 16, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture);
1926 ok(hr == D3D_OK, "IDirect3DDevice8_CreateTexture failed with %#08x\n", hr);
1928 /* There are 8 texture stages. We should be able to access all of them */
1929 for (i = 0; i < 8; ++i)
1931 hr = IDirect3DDevice8_SetTexture(device, i, (IDirect3DBaseTexture8 *)texture);
1932 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %#08x\n", i, hr);
1933 hr = IDirect3DDevice8_SetTexture(device, i, NULL);
1934 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %#08x\n", i, hr);
1935 hr = IDirect3DDevice8_SetTextureStageState(device, i, D3DTSS_COLOROP, D3DTOP_ADD);
1936 ok(hr == D3D_OK, "IDirect3DDevice8_SetTextureStageState for texture %d failed with %#08x\n", i, hr);
1939 /* Investigations show that accessing higher textures stage states does
1940 * not return an error either. Writing to too high texture stages
1941 * (approximately texture 40) causes memory corruption in windows, so
1942 * there is no bounds checking. */
1943 IDirect3DTexture8_Release(texture);
1944 refcount = IDirect3DDevice8_Release(device);
1945 ok(!refcount, "Device has %u references left.\n", refcount);
1946 cleanup:
1947 IDirect3D8_Release(d3d);
1948 DestroyWindow(window);
1951 static void test_lights(void)
1953 IDirect3DDevice8 *device;
1954 IDirect3D8 *d3d8;
1955 ULONG refcount;
1956 HWND window;
1957 HRESULT hr;
1958 unsigned int i;
1959 BOOL enabled;
1960 D3DCAPS8 caps;
1962 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
1963 0, 0, 640, 480, NULL, NULL, NULL, NULL);
1964 ok(!!window, "Failed to create a window.\n");
1965 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
1966 ok(!!d3d8, "Failed to create a D3D object.\n");
1967 if (!(device = create_device(d3d8, window, NULL)))
1969 skip("Failed to create a 3D device, skipping test.\n");
1970 goto cleanup;
1973 memset(&caps, 0, sizeof(caps));
1974 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
1975 ok(hr == D3D_OK, "IDirect3DDevice8_GetDeviceCaps failed with %08x\n", hr);
1977 for(i = 1; i <= caps.MaxActiveLights; i++) {
1978 hr = IDirect3DDevice8_LightEnable(device, i, TRUE);
1979 ok(hr == D3D_OK, "Enabling light %u failed with %08x\n", i, hr);
1980 hr = IDirect3DDevice8_GetLightEnable(device, i, &enabled);
1981 ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL),
1982 "GetLightEnable on light %u failed with %08x\n", i, hr);
1983 ok(enabled, "Light %d is %s\n", i, enabled ? "enabled" : "disabled");
1986 /* TODO: Test the rendering results in this situation */
1987 hr = IDirect3DDevice8_LightEnable(device, i + 1, TRUE);
1988 ok(hr == D3D_OK, "Enabling one light more than supported returned %08x\n", hr);
1989 hr = IDirect3DDevice8_GetLightEnable(device, i + 1, &enabled);
1990 ok(hr == D3D_OK, "GetLightEnable on light %u failed with %08x\n", i + 1, hr);
1991 ok(enabled, "Light %d is %s\n", i + 1, enabled ? "enabled" : "disabled");
1992 hr = IDirect3DDevice8_LightEnable(device, i + 1, FALSE);
1993 ok(hr == D3D_OK, "Disabling the additional returned %08x\n", hr);
1995 for(i = 1; i <= caps.MaxActiveLights; i++) {
1996 hr = IDirect3DDevice8_LightEnable(device, i, FALSE);
1997 ok(hr == D3D_OK, "Disabling light %u failed with %08x\n", i, hr);
2000 refcount = IDirect3DDevice8_Release(device);
2001 ok(!refcount, "Device has %u references left.\n", refcount);
2002 cleanup:
2003 IDirect3D8_Release(d3d8);
2004 DestroyWindow(window);
2007 static void test_render_zero_triangles(void)
2009 IDirect3DDevice8 *device;
2010 IDirect3D8 *d3d8;
2011 ULONG refcount;
2012 HWND window;
2013 HRESULT hr;
2015 static const struct
2017 struct vec3 position;
2018 struct vec3 normal;
2019 DWORD diffuse;
2021 quad[] =
2023 {{0.0f, -1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
2024 {{0.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
2025 {{1.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
2026 {{1.0f, -1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
2029 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
2030 0, 0, 640, 480, NULL, NULL, NULL, NULL);
2031 ok(!!window, "Failed to create a window.\n");
2032 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
2033 ok(!!d3d8, "Failed to create a D3D object.\n");
2034 if (!(device = create_device(d3d8, window, NULL)))
2036 skip("Failed to create a 3D device, skipping test.\n");
2037 goto cleanup;
2040 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
2041 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
2043 hr = IDirect3DDevice8_BeginScene(device);
2044 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
2045 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 0 /* NumVerts */,
2046 0 /* PrimCount */, NULL, D3DFMT_INDEX16, quad, sizeof(quad[0]));
2047 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
2048 hr = IDirect3DDevice8_EndScene(device);
2049 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
2051 IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
2053 refcount = IDirect3DDevice8_Release(device);
2054 ok(!refcount, "Device has %u references left.\n", refcount);
2055 cleanup:
2056 IDirect3D8_Release(d3d8);
2057 DestroyWindow(window);
2060 static void test_depth_stencil_reset(void)
2062 D3DPRESENT_PARAMETERS present_parameters;
2063 D3DDISPLAYMODE display_mode;
2064 IDirect3DSurface8 *surface, *orig_rt;
2065 IDirect3DDevice8 *device = NULL;
2066 IDirect3D8 *d3d8;
2067 UINT refcount;
2068 HRESULT hr;
2069 HWND hwnd;
2071 hwnd = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
2072 100, 100, 160, 160, NULL, NULL, NULL, NULL);
2073 ok(!!hwnd, "Failed to create a window.\n");
2074 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
2075 ok(!!d3d8, "Failed to create a D3D object.\n");
2077 IDirect3D8_GetAdapterDisplayMode(d3d8, D3DADAPTER_DEFAULT, &display_mode);
2078 memset(&present_parameters, 0, sizeof(present_parameters));
2079 present_parameters.Windowed = TRUE;
2080 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
2081 present_parameters.BackBufferFormat = display_mode.Format;
2082 present_parameters.EnableAutoDepthStencil = TRUE;
2083 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
2085 hr = IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
2086 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device);
2087 if(FAILED(hr))
2089 skip("could not create device, IDirect3D8_CreateDevice returned %#x\n", hr);
2090 goto cleanup;
2093 hr = IDirect3DDevice8_GetRenderTarget(device, &orig_rt);
2094 ok(hr == D3D_OK, "GetRenderTarget failed with 0x%08x\n", hr);
2096 hr = IDirect3DDevice8_TestCooperativeLevel(device);
2097 ok(SUCCEEDED(hr), "TestCooperativeLevel failed with %#x\n", hr);
2099 hr = IDirect3DDevice8_SetRenderTarget(device, NULL, NULL);
2100 ok(hr == D3D_OK, "SetRenderTarget failed with 0x%08x\n", hr);
2102 hr = IDirect3DDevice8_GetRenderTarget(device, &surface);
2103 ok(hr == D3D_OK, "GetRenderTarget failed with 0x%08x\n", hr);
2104 ok(surface == orig_rt, "Render target is %p, should be %p\n", surface, orig_rt);
2105 if (surface) IDirect3DSurface8_Release(surface);
2106 IDirect3DSurface8_Release(orig_rt);
2108 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surface);
2109 ok(hr == D3DERR_NOTFOUND, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr);
2110 ok(surface == NULL, "Depth stencil should be NULL\n");
2112 present_parameters.EnableAutoDepthStencil = TRUE;
2113 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
2114 hr = IDirect3DDevice8_Reset(device, &present_parameters);
2115 ok(hr == D3D_OK, "Reset failed with 0x%08x\n", hr);
2117 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surface);
2118 ok(hr == D3D_OK, "GetDepthStencilSurface failed with 0x%08x\n", hr);
2119 ok(surface != NULL, "Depth stencil should not be NULL\n");
2120 if (surface) IDirect3DSurface8_Release(surface);
2122 present_parameters.EnableAutoDepthStencil = FALSE;
2123 hr = IDirect3DDevice8_Reset(device, &present_parameters);
2124 ok(hr == D3D_OK, "Reset failed with 0x%08x\n", hr);
2126 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surface);
2127 ok(hr == D3DERR_NOTFOUND, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr);
2128 ok(surface == NULL, "Depth stencil should be NULL\n");
2130 refcount = IDirect3DDevice8_Release(device);
2131 ok(!refcount, "Device has %u references left.\n", refcount);
2132 device = NULL;
2134 IDirect3D8_GetAdapterDisplayMode( d3d8, D3DADAPTER_DEFAULT, &display_mode );
2136 ZeroMemory( &present_parameters, sizeof(present_parameters) );
2137 present_parameters.Windowed = TRUE;
2138 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
2139 present_parameters.BackBufferFormat = display_mode.Format;
2140 present_parameters.EnableAutoDepthStencil = FALSE;
2141 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
2143 hr = IDirect3D8_CreateDevice( d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
2144 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device );
2146 if(FAILED(hr))
2148 skip("could not create device, IDirect3D8_CreateDevice returned %#x\n", hr);
2149 goto cleanup;
2152 hr = IDirect3DDevice8_TestCooperativeLevel(device);
2153 ok(hr == D3D_OK, "IDirect3DDevice8_TestCooperativeLevel after creation returned %#x\n", hr);
2155 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
2156 present_parameters.Windowed = TRUE;
2157 present_parameters.BackBufferWidth = 400;
2158 present_parameters.BackBufferHeight = 300;
2159 present_parameters.EnableAutoDepthStencil = TRUE;
2160 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
2162 hr = IDirect3DDevice8_Reset(device, &present_parameters);
2163 ok(hr == D3D_OK, "IDirect3DDevice8_Reset failed with 0x%08x\n", hr);
2165 if (FAILED(hr)) goto cleanup;
2167 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surface);
2168 ok(hr == D3D_OK, "GetDepthStencilSurface failed with 0x%08x\n", hr);
2169 ok(surface != NULL, "Depth stencil should not be NULL\n");
2170 if (surface) IDirect3DSurface8_Release(surface);
2172 cleanup:
2173 if (device)
2175 refcount = IDirect3DDevice8_Release(device);
2176 ok(!refcount, "Device has %u references left.\n", refcount);
2178 IDirect3D8_Release(d3d8);
2179 DestroyWindow(hwnd);
2182 static HWND filter_messages;
2184 enum message_window
2186 DEVICE_WINDOW,
2187 FOCUS_WINDOW,
2190 struct message
2192 UINT message;
2193 enum message_window window;
2194 BOOL check_wparam;
2195 WPARAM expect_wparam;
2198 static const struct message *expect_messages;
2199 static HWND device_window, focus_window;
2200 static LONG windowposchanged_received, syscommand_received;
2202 struct wndproc_thread_param
2204 HWND dummy_window;
2205 HANDLE window_created;
2206 HANDLE test_finished;
2207 BOOL running_in_foreground;
2210 static LRESULT CALLBACK test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
2212 if (filter_messages && filter_messages == hwnd)
2214 if (message != WM_DISPLAYCHANGE && message != WM_IME_NOTIFY)
2215 todo_wine ok(0, "Received unexpected message %#x for window %p.\n", message, hwnd);
2218 if (expect_messages)
2220 HWND w;
2222 switch (expect_messages->window)
2224 case DEVICE_WINDOW:
2225 w = device_window;
2226 break;
2228 case FOCUS_WINDOW:
2229 w = focus_window;
2230 break;
2232 default:
2233 w = NULL;
2234 break;
2237 if (hwnd == w && expect_messages->message == message)
2239 if (expect_messages->check_wparam)
2240 ok(wparam == expect_messages->expect_wparam,
2241 "Got unexpected wparam %lx for message %x, expected %lx.\n",
2242 wparam, message, expect_messages->expect_wparam);
2244 ++expect_messages;
2248 /* KDE randomly does something with the hidden window during the
2249 * mode change that sometimes generates a WM_WINDOWPOSCHANGING
2250 * message. A WM_WINDOWPOSCHANGED message is not generated, so
2251 * just flag WM_WINDOWPOSCHANGED as bad. */
2252 if (message == WM_WINDOWPOSCHANGED)
2253 InterlockedIncrement(&windowposchanged_received);
2254 else if (message == WM_SYSCOMMAND)
2255 InterlockedIncrement(&syscommand_received);
2257 return DefWindowProcA(hwnd, message, wparam, lparam);
2260 static DWORD WINAPI wndproc_thread(void *param)
2262 struct wndproc_thread_param *p = param;
2263 DWORD res;
2264 BOOL ret;
2266 p->dummy_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
2267 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, registry_mode.dmPelsWidth,
2268 registry_mode.dmPelsHeight, 0, 0, 0, 0);
2269 p->running_in_foreground = SetForegroundWindow(p->dummy_window);
2271 ret = SetEvent(p->window_created);
2272 ok(ret, "SetEvent failed, last error %#x.\n", GetLastError());
2274 for (;;)
2276 MSG msg;
2278 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2279 res = WaitForSingleObject(p->test_finished, 100);
2280 if (res == WAIT_OBJECT_0) break;
2281 if (res != WAIT_TIMEOUT)
2283 ok(0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
2284 break;
2288 DestroyWindow(p->dummy_window);
2290 return 0;
2293 static void test_wndproc(void)
2295 struct wndproc_thread_param thread_params;
2296 struct device_desc device_desc;
2297 IDirect3DDevice8 *device;
2298 WNDCLASSA wc = {0};
2299 IDirect3D8 *d3d8;
2300 HANDLE thread;
2301 LONG_PTR proc;
2302 ULONG ref;
2303 DWORD res, tid;
2304 HWND tmp;
2305 UINT i, adapter_mode_count;
2306 HRESULT hr;
2307 D3DDISPLAYMODE d3ddm;
2308 DWORD d3d_width = 0, d3d_height = 0, user32_width = 0, user32_height = 0;
2309 DEVMODEW devmode;
2310 LONG change_ret;
2311 BOOL ret;
2313 static const struct message create_messages[] =
2315 {WM_WINDOWPOSCHANGING, FOCUS_WINDOW, FALSE, 0},
2316 /* Do not test wparam here. If device creation succeeds,
2317 * wparam is WA_ACTIVE. If device creation fails (testbot)
2318 * wparam is set to WA_INACTIVE on some Windows versions. */
2319 {WM_ACTIVATE, FOCUS_WINDOW, FALSE, 0},
2320 {WM_SETFOCUS, FOCUS_WINDOW, FALSE, 0},
2321 {WM_WINDOWPOSCHANGING, DEVICE_WINDOW, FALSE, 0},
2322 {WM_MOVE, DEVICE_WINDOW, FALSE, 0},
2323 {WM_SIZE, DEVICE_WINDOW, FALSE, 0},
2324 {0, 0, FALSE, 0},
2326 static const struct message focus_loss_messages[] =
2328 /* WM_ACTIVATE (wparam = WA_INACTIVE) is sent on Windows. It is
2329 * not reliable on X11 WMs. When the window focus follows the
2330 * mouse pointer the message is not sent.
2331 * {WM_ACTIVATE, FOCUS_WINDOW, TRUE, WA_INACTIVE}, */
2332 {WM_DISPLAYCHANGE, DEVICE_WINDOW, FALSE, 0},
2333 /* WM_DISPLAYCHANGE is sent to the focus window too, but the order is
2334 * not deterministic. */
2335 {WM_WINDOWPOSCHANGING, DEVICE_WINDOW, FALSE, 0},
2336 /* Windows sends WM_ACTIVATE to the device window, indicating that
2337 * SW_SHOWMINIMIZED is used instead of SW_MINIMIZE. Yet afterwards
2338 * the foreground and focus window are NULL. On Wine SW_SHOWMINIMIZED
2339 * leaves the device window active, breaking re-activation in the
2340 * lost device test.
2341 * {WM_ACTIVATE, DEVICE_WINDOW, TRUE, 0x200000 | WA_ACTIVE}, */
2342 {WM_WINDOWPOSCHANGED, DEVICE_WINDOW, FALSE, 0},
2343 {WM_SIZE, DEVICE_WINDOW, TRUE, SIZE_MINIMIZED},
2344 {WM_ACTIVATEAPP, FOCUS_WINDOW, TRUE, FALSE},
2345 /* WM_ACTIVATEAPP is sent to the device window too, but the order is
2346 * not deterministic. It may be sent after the focus window handling
2347 * or before. */
2348 {0, 0, FALSE, 0},
2350 static const struct message reactivate_messages[] =
2352 {WM_WINDOWPOSCHANGING, DEVICE_WINDOW, FALSE, 0},
2353 {WM_WINDOWPOSCHANGED, DEVICE_WINDOW, FALSE, 0},
2354 {WM_MOVE, DEVICE_WINDOW, FALSE, 0},
2355 {WM_ACTIVATEAPP, FOCUS_WINDOW, TRUE, TRUE},
2356 {0, 0, FALSE, 0},
2358 static const struct message focus_loss_messages_hidden[] =
2360 {WM_DISPLAYCHANGE, DEVICE_WINDOW, FALSE, 0},
2361 {WM_ACTIVATEAPP, FOCUS_WINDOW, TRUE, FALSE},
2362 {0, 0, FALSE, 0},
2364 static const struct message focus_loss_messages_filtered[] =
2366 /* WM_ACTIVATE is delivered to the window proc because it is
2367 * generated by SetForegroundWindow before the d3d routine
2368 * starts it work. Don't check for it due to focus-follows-mouse
2369 * WMs though. */
2370 {WM_DISPLAYCHANGE, FOCUS_WINDOW, FALSE, 0},
2371 {WM_ACTIVATEAPP, FOCUS_WINDOW, TRUE, FALSE},
2372 {0, 0, FALSE, 0},
2374 static const struct message reactivate_messages_filtered[] =
2376 {WM_ACTIVATEAPP, FOCUS_WINDOW, TRUE, TRUE},
2377 {0, 0, FALSE, 0},
2379 static const struct message sc_restore_messages[] =
2381 /* WM_SYSCOMMAND is delivered only once, after d3d has already
2382 * processed it. Our wndproc has no way to prevent d3d from
2383 * handling the message. The second DefWindowProc call done by
2384 * our wndproc doesn't do any changes to the window because it
2385 * is already restored due to d3d's handling. */
2386 {WM_WINDOWPOSCHANGING, FOCUS_WINDOW, FALSE, 0},
2387 {WM_WINDOWPOSCHANGED, FOCUS_WINDOW, FALSE, 0},
2388 {WM_SIZE, FOCUS_WINDOW, TRUE, SIZE_RESTORED},
2389 {WM_SYSCOMMAND, FOCUS_WINDOW, TRUE, SC_RESTORE},
2390 {0, 0, FALSE, 0},
2392 static const struct message sc_minimize_messages[] =
2394 {WM_SYSCOMMAND, FOCUS_WINDOW, TRUE, SC_MINIMIZE},
2395 {WM_WINDOWPOSCHANGING, FOCUS_WINDOW, FALSE, 0},
2396 {WM_WINDOWPOSCHANGED, FOCUS_WINDOW, FALSE, 0},
2397 {WM_MOVE, FOCUS_WINDOW, FALSE, 0},
2398 {WM_SIZE, FOCUS_WINDOW, TRUE, SIZE_MINIMIZED},
2399 {0, 0, FALSE, 0},
2401 static const struct message sc_maximize_messages[] =
2403 {WM_SYSCOMMAND, FOCUS_WINDOW, TRUE, SC_MAXIMIZE},
2404 {WM_WINDOWPOSCHANGING, FOCUS_WINDOW, FALSE, 0},
2405 {WM_WINDOWPOSCHANGED, FOCUS_WINDOW, FALSE, 0},
2406 {WM_MOVE, FOCUS_WINDOW, FALSE, 0},
2407 {WM_SIZE, FOCUS_WINDOW, TRUE, SIZE_MAXIMIZED},
2408 {0, 0, FALSE, 0},
2411 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
2412 ok(!!d3d8, "Failed to create a D3D object.\n");
2414 adapter_mode_count = IDirect3D8_GetAdapterModeCount(d3d8, D3DADAPTER_DEFAULT);
2415 for (i = 0; i < adapter_mode_count; ++i)
2417 hr = IDirect3D8_EnumAdapterModes(d3d8, D3DADAPTER_DEFAULT, i, &d3ddm);
2418 ok(SUCCEEDED(hr), "Failed to enumerate display mode, hr %#x.\n", hr);
2420 if (d3ddm.Format != D3DFMT_X8R8G8B8)
2421 continue;
2422 if (d3ddm.Width == registry_mode.dmPelsWidth && d3ddm.Height == registry_mode.dmPelsHeight)
2423 continue;
2424 /* The r200 driver on Windows XP enumerates modes like 320x200 and 320x240 but
2425 * refuses to create a device at these sizes. */
2426 if (d3ddm.Width < 640 || d3ddm.Height < 480)
2427 continue;
2429 if (!user32_width)
2431 user32_width = d3ddm.Width;
2432 user32_height = d3ddm.Height;
2433 continue;
2436 /* Make sure the d3d mode is smaller in width or height and at most
2437 * equal in the other dimension than the mode passed to
2438 * ChangeDisplaySettings. Otherwise Windows shrinks the window to
2439 * the ChangeDisplaySettings parameters + 12. */
2440 if (d3ddm.Width == user32_width && d3ddm.Height == user32_height)
2441 continue;
2442 if (d3ddm.Width <= user32_width && d3ddm.Height <= user32_height)
2444 d3d_width = d3ddm.Width;
2445 d3d_height = d3ddm.Height;
2446 break;
2448 if (user32_width <= d3ddm.Width && user32_height <= d3ddm.Height)
2450 d3d_width = user32_width;
2451 d3d_height = user32_height;
2452 user32_width = d3ddm.Width;
2453 user32_height = d3ddm.Height;
2454 break;
2458 if (!d3d_width)
2460 skip("Could not find adequate modes, skipping mode tests.\n");
2461 IDirect3D8_Release(d3d8);
2462 return;
2465 wc.lpfnWndProc = test_proc;
2466 wc.lpszClassName = "d3d8_test_wndproc_wc";
2467 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2469 thread_params.window_created = CreateEventA(NULL, FALSE, FALSE, NULL);
2470 ok(!!thread_params.window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
2471 thread_params.test_finished = CreateEventA(NULL, FALSE, FALSE, NULL);
2472 ok(!!thread_params.test_finished, "CreateEvent failed, last error %#x.\n", GetLastError());
2474 memset(&devmode, 0, sizeof(devmode));
2475 devmode.dmSize = sizeof(devmode);
2476 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
2477 devmode.dmPelsWidth = user32_width;
2478 devmode.dmPelsHeight = user32_height;
2479 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2480 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2482 focus_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
2483 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION , 0, 0, user32_width, user32_height, 0, 0, 0, 0);
2484 device_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
2485 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION , 0, 0, user32_width, user32_height, 0, 0, 0, 0);
2486 thread = CreateThread(NULL, 0, wndproc_thread, &thread_params, 0, &tid);
2487 ok(!!thread, "Failed to create thread, last error %#x.\n", GetLastError());
2489 res = WaitForSingleObject(thread_params.window_created, INFINITE);
2490 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
2492 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
2493 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2494 (LONG_PTR)test_proc, proc);
2495 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2496 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2497 (LONG_PTR)test_proc, proc);
2499 trace("device_window %p, focus_window %p, dummy_window %p.\n",
2500 device_window, focus_window, thread_params.dummy_window);
2502 tmp = GetFocus();
2503 ok(tmp == device_window, "Expected focus %p, got %p.\n", device_window, tmp);
2504 if (thread_params.running_in_foreground)
2506 tmp = GetForegroundWindow();
2507 ok(tmp == thread_params.dummy_window, "Expected foreground window %p, got %p.\n",
2508 thread_params.dummy_window, tmp);
2510 else
2511 skip("Not running in foreground, skip foreground window test\n");
2513 flush_events();
2515 expect_messages = create_messages;
2517 device_desc.device_window = device_window;
2518 device_desc.width = d3d_width;
2519 device_desc.height = d3d_height;
2520 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
2521 if (!(device = create_device(d3d8, focus_window, &device_desc)))
2523 skip("Failed to create a D3D device, skipping tests.\n");
2524 goto done;
2527 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
2528 expect_messages->message, expect_messages->window);
2529 expect_messages = NULL;
2531 if (0) /* Disabled until we can make this work in a reliable way on Wine. */
2533 tmp = GetFocus();
2534 ok(tmp == focus_window, "Expected focus %p, got %p.\n", focus_window, tmp);
2535 tmp = GetForegroundWindow();
2536 ok(tmp == focus_window, "Expected foreground window %p, got %p.\n", focus_window, tmp);
2538 SetForegroundWindow(focus_window);
2539 flush_events();
2541 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
2542 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2543 (LONG_PTR)test_proc, proc);
2545 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2546 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx.\n", (LONG_PTR)test_proc);
2548 /* Change the mode while the device is in use and then drop focus. */
2549 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
2550 devmode.dmPelsWidth = user32_width;
2551 devmode.dmPelsHeight = user32_height;
2552 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2553 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x, i=%u.\n", change_ret, i);
2555 /* Wine doesn't (yet) mark the device not reset when the mode is changed, thus the todo_wine.
2556 * But sometimes focus-follows-mouse WMs also temporarily drop window focus, which makes
2557 * mark the device lost, then not reset, causing the test to succeed for the wrong reason. */
2558 hr = IDirect3DDevice8_TestCooperativeLevel(device);
2559 if (hr == D3DERR_DEVICENOTRESET)
2560 ok(hr == D3DERR_DEVICENOTRESET, "Got unexpected hr %#x.\n", hr);
2561 else
2562 todo_wine ok(hr == D3DERR_DEVICENOTRESET, "Got unexpected hr %#x.\n", hr);
2564 expect_messages = focus_loss_messages;
2565 /* SetForegroundWindow is a poor replacement for the user pressing alt-tab or
2566 * manually changing the focus. It generates the same messages, but the task
2567 * bar still shows the previous foreground window as active, and the window has
2568 * an inactive titlebar if reactivated with SetForegroundWindow. Reactivating
2569 * the device is difficult, see below. */
2570 SetForegroundWindow(GetDesktopWindow());
2571 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
2572 expect_messages->message, expect_messages->window);
2573 expect_messages = NULL;
2574 tmp = GetFocus();
2575 ok(tmp != device_window, "The device window is active.\n");
2576 ok(tmp != focus_window, "The focus window is active.\n");
2578 /* The Present call is necessary to make native realize the device is lost. */
2579 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
2580 ok(hr == D3DERR_DEVICELOST, "Got unexpected hr %#x.\n", hr);
2581 hr = IDirect3DDevice8_TestCooperativeLevel(device);
2582 /* Focus-follows-mouse WMs prematurely reactivate our window. */
2583 if (hr == D3DERR_DEVICENOTRESET)
2584 todo_wine ok(hr == D3DERR_DEVICELOST, "Got unexpected hr %#x.\n", hr);
2585 else
2586 ok(hr == D3DERR_DEVICELOST, "Got unexpected hr %#x.\n", hr);
2588 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2589 ok(ret, "Failed to get display mode.\n");
2590 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
2591 && devmode.dmPelsHeight == registry_mode.dmPelsHeight, "Got unexpect screen size %ux%u.\n",
2592 devmode.dmPelsWidth, devmode.dmPelsHeight);
2594 /* I have to minimize and restore the focus window, otherwise native d3d9 fails
2595 * device::reset with D3DERR_DEVICELOST. This does not happen when the window
2596 * restore is triggered by the user. */
2597 expect_messages = reactivate_messages;
2598 ShowWindow(focus_window, SW_MINIMIZE);
2599 ShowWindow(focus_window, SW_RESTORE);
2600 /* Set focus twice to make KDE and fvwm in focus-follows-mouse mode happy. */
2601 SetForegroundWindow(focus_window);
2602 flush_events();
2603 SetForegroundWindow(focus_window);
2604 flush_events(); /* WM_WINDOWPOSCHANGING etc arrive after SetForegroundWindow returns. */
2605 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it, i=%u.\n",
2606 expect_messages->message, expect_messages->window, i);
2607 expect_messages = NULL;
2609 hr = IDirect3DDevice8_TestCooperativeLevel(device);
2610 ok(hr == D3DERR_DEVICENOTRESET, "Got unexpected hr %#x.\n", hr);
2612 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2613 ok(ret, "Failed to get display mode.\n");
2614 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
2615 && devmode.dmPelsHeight == registry_mode.dmPelsHeight, "Got unexpect screen size %ux%u.\n",
2616 devmode.dmPelsWidth, devmode.dmPelsHeight);
2618 hr = reset_device(device, &device_desc);
2619 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
2621 ShowWindow(device_window, SW_HIDE);
2622 flush_events();
2624 expect_messages = focus_loss_messages_hidden;
2625 windowposchanged_received = 0;
2626 SetForegroundWindow(GetDesktopWindow());
2627 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
2628 expect_messages->message, expect_messages->window);
2629 ok(!windowposchanged_received, "Received WM_WINDOWPOSCHANGED but did not expect it.\n");
2630 expect_messages = NULL;
2631 flush_events();
2633 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2634 ok(ret, "Failed to get display mode.\n");
2635 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth, "Got unexpect width %u.\n", devmode.dmPelsWidth);
2636 ok(devmode.dmPelsHeight == registry_mode.dmPelsHeight, "Got unexpect height %u.\n", devmode.dmPelsHeight);
2638 /* SW_SHOWMINNOACTIVE is needed to make FVWM happy. SW_SHOWNOACTIVATE is needed to make windows
2639 * send SIZE_RESTORED after ShowWindow(SW_SHOWMINNOACTIVE). */
2640 ShowWindow(focus_window, SW_SHOWNOACTIVATE);
2641 ShowWindow(focus_window, SW_SHOWMINNOACTIVE);
2642 flush_events();
2644 syscommand_received = 0;
2645 expect_messages = sc_restore_messages;
2646 SendMessageA(focus_window, WM_SYSCOMMAND, SC_RESTORE, 0);
2647 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
2648 expect_messages->message, expect_messages->window);
2649 ok(syscommand_received == 1, "Got unexpected number of WM_SYSCOMMAND messages: %d.\n", syscommand_received);
2650 expect_messages = NULL;
2651 flush_events();
2653 expect_messages = sc_minimize_messages;
2654 SendMessageA(focus_window, WM_SYSCOMMAND, SC_MINIMIZE, 0);
2655 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
2656 expect_messages->message, expect_messages->window);
2657 expect_messages = NULL;
2658 flush_events();
2660 expect_messages = sc_maximize_messages;
2661 SendMessageA(focus_window, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
2662 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
2663 expect_messages->message, expect_messages->window);
2664 expect_messages = NULL;
2665 flush_events();
2667 SetForegroundWindow(GetDesktopWindow());
2668 ShowWindow(device_window, SW_MINIMIZE);
2669 ShowWindow(focus_window, SW_MINIMIZE);
2670 ShowWindow(focus_window, SW_RESTORE);
2671 SetForegroundWindow(focus_window);
2672 flush_events();
2674 /* Releasing a device in lost state breaks follow-up tests on native. */
2675 hr = reset_device(device, &device_desc);
2676 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
2678 filter_messages = focus_window;
2679 ref = IDirect3DDevice8_Release(device);
2680 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
2682 /* Fix up the mode until Wine's device release behavior is fixed. */
2683 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
2684 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2686 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2687 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2688 (LONG_PTR)test_proc, proc);
2690 /* Hide the device window. It prevents WM_ACTIVATEAPP messages from being sent
2691 * on native in the test below. It isn't needed anyways. Creating the third
2692 * device will show it again. */
2693 filter_messages = NULL;
2694 ShowWindow(device_window, SW_HIDE);
2695 /* Remove the maximized state from the SYSCOMMAND test while we're not
2696 * interfering with a device. */
2697 ShowWindow(focus_window, SW_SHOWNORMAL);
2698 filter_messages = focus_window;
2700 device_desc.device_window = focus_window;
2701 if (!(device = create_device(d3d8, focus_window, &device_desc)))
2703 skip("Failed to create a D3D device, skipping tests.\n");
2704 goto done;
2707 filter_messages = NULL;
2709 expect_messages = focus_loss_messages_filtered;
2710 windowposchanged_received = 0;
2711 SetForegroundWindow(GetDesktopWindow());
2712 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
2713 expect_messages->message, expect_messages->window);
2714 ok(!windowposchanged_received, "Received WM_WINDOWPOSCHANGED but did not expect it.\n");
2715 expect_messages = NULL;
2717 /* The window is iconic even though no message was sent. */
2718 ok(IsIconic(focus_window), "The focus window is not iconic.\n");
2720 hr = IDirect3DDevice8_TestCooperativeLevel(device);
2721 ok(hr == D3DERR_DEVICELOST, "Got unexpected hr %#x.\n", hr);
2723 syscommand_received = 0;
2724 expect_messages = sc_restore_messages;
2725 SendMessageA(focus_window, WM_SYSCOMMAND, SC_RESTORE, 0);
2726 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
2727 expect_messages->message, expect_messages->window);
2728 ok(syscommand_received == 1, "Got unexpected number of WM_SYSCOMMAND messages: %d.\n", syscommand_received);
2729 expect_messages = NULL;
2730 flush_events();
2732 /* For FVWM. */
2733 ShowWindow(focus_window, SW_RESTORE);
2734 flush_events();
2736 expect_messages = sc_minimize_messages;
2737 SendMessageA(focus_window, WM_SYSCOMMAND, SC_MINIMIZE, 0);
2738 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
2739 expect_messages->message, expect_messages->window);
2740 expect_messages = NULL;
2741 /* Needed to make the next test reliably send WM_SIZE(SIZE_MAXIMIZED). Without
2742 * this call it sends WM_SIZE(SIZE_RESTORED). */
2743 ShowWindow(focus_window, SW_RESTORE);
2744 flush_events();
2746 expect_messages = sc_maximize_messages;
2747 SendMessageA(focus_window, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
2748 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
2749 expect_messages->message, expect_messages->window);
2750 expect_messages = NULL;
2751 SetForegroundWindow(GetDesktopWindow());
2752 flush_events();
2754 /* ShowWindow(SW_RESTORE); SetForegroundWindow(desktop); SetForegroundWindow(focus);
2755 * results in the second SetForegroundWindow call failing and the device not being
2756 * restored on native. Directly using ShowWindow(SW_RESTORE) works, but it means
2757 * we cannot test for the absence of WM_WINDOWPOSCHANGED messages. */
2758 expect_messages = reactivate_messages_filtered;
2759 ShowWindow(focus_window, SW_RESTORE);
2760 SetForegroundWindow(focus_window);
2761 flush_events();
2762 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it\n",
2763 expect_messages->message, expect_messages->window);
2764 expect_messages = NULL;
2766 filter_messages = focus_window;
2767 hr = IDirect3DDevice8_TestCooperativeLevel(device);
2768 ok(hr == D3DERR_DEVICENOTRESET, "Got unexpected hr %#x.\n", hr);
2770 hr = reset_device(device, &device_desc);
2771 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
2773 ref = IDirect3DDevice8_Release(device);
2774 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
2776 device_desc.device_window = device_window;
2777 if (!(device = create_device(d3d8, focus_window, &device_desc)))
2779 skip("Failed to create a D3D device, skipping tests.\n");
2780 goto done;
2783 proc = SetWindowLongPtrA(focus_window, GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
2784 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx.\n", (LONG_PTR)test_proc);
2786 ref = IDirect3DDevice8_Release(device);
2787 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
2789 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2790 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2791 (LONG_PTR)DefWindowProcA, proc);
2793 done:
2794 filter_messages = NULL;
2795 IDirect3D8_Release(d3d8);
2797 SetEvent(thread_params.test_finished);
2798 WaitForSingleObject(thread, INFINITE);
2799 CloseHandle(thread_params.test_finished);
2800 CloseHandle(thread_params.window_created);
2801 CloseHandle(thread);
2803 DestroyWindow(device_window);
2804 DestroyWindow(focus_window);
2805 UnregisterClassA("d3d8_test_wndproc_wc", GetModuleHandleA(NULL));
2808 static void test_wndproc_windowed(void)
2810 struct wndproc_thread_param thread_params;
2811 struct device_desc device_desc;
2812 IDirect3DDevice8 *device;
2813 WNDCLASSA wc = {0};
2814 IDirect3D8 *d3d8;
2815 HANDLE thread;
2816 LONG_PTR proc;
2817 HRESULT hr;
2818 ULONG ref;
2819 DWORD res, tid;
2820 HWND tmp;
2822 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
2823 ok(!!d3d8, "Failed to create a D3D object.\n");
2825 wc.lpfnWndProc = test_proc;
2826 wc.lpszClassName = "d3d8_test_wndproc_wc";
2827 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2829 thread_params.window_created = CreateEventA(NULL, FALSE, FALSE, NULL);
2830 ok(!!thread_params.window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
2831 thread_params.test_finished = CreateEventA(NULL, FALSE, FALSE, NULL);
2832 ok(!!thread_params.test_finished, "CreateEvent failed, last error %#x.\n", GetLastError());
2834 focus_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
2835 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, registry_mode.dmPelsWidth,
2836 registry_mode.dmPelsHeight, 0, 0, 0, 0);
2837 device_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
2838 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, registry_mode.dmPelsWidth,
2839 registry_mode.dmPelsHeight, 0, 0, 0, 0);
2840 thread = CreateThread(NULL, 0, wndproc_thread, &thread_params, 0, &tid);
2841 ok(!!thread, "Failed to create thread, last error %#x.\n", GetLastError());
2843 res = WaitForSingleObject(thread_params.window_created, INFINITE);
2844 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
2846 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
2847 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2848 (LONG_PTR)test_proc, proc);
2849 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2850 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2851 (LONG_PTR)test_proc, proc);
2853 trace("device_window %p, focus_window %p, dummy_window %p.\n",
2854 device_window, focus_window, thread_params.dummy_window);
2856 tmp = GetFocus();
2857 ok(tmp == device_window, "Expected focus %p, got %p.\n", device_window, tmp);
2858 if (thread_params.running_in_foreground)
2860 tmp = GetForegroundWindow();
2861 ok(tmp == thread_params.dummy_window, "Expected foreground window %p, got %p.\n",
2862 thread_params.dummy_window, tmp);
2864 else
2865 skip("Not running in foreground, skip foreground window test\n");
2867 filter_messages = focus_window;
2869 device_desc.device_window = device_window;
2870 device_desc.width = registry_mode.dmPelsWidth;
2871 device_desc.height = registry_mode.dmPelsHeight;
2872 device_desc.flags = 0;
2873 if (!(device = create_device(d3d8, focus_window, &device_desc)))
2875 skip("Failed to create a D3D device, skipping tests.\n");
2876 goto done;
2879 tmp = GetFocus();
2880 ok(tmp == device_window, "Expected focus %p, got %p.\n", device_window, tmp);
2881 tmp = GetForegroundWindow();
2882 ok(tmp == thread_params.dummy_window, "Expected foreground window %p, got %p.\n",
2883 thread_params.dummy_window, tmp);
2885 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
2886 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2887 (LONG_PTR)test_proc, proc);
2889 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2890 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2891 (LONG_PTR)test_proc, proc);
2893 filter_messages = NULL;
2895 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
2896 hr = reset_device(device, &device_desc);
2897 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
2899 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
2900 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2901 (LONG_PTR)test_proc, proc);
2903 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2904 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx.\n", (LONG_PTR)test_proc);
2906 device_desc.flags = 0;
2907 hr = reset_device(device, &device_desc);
2908 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
2910 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
2911 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2912 (LONG_PTR)test_proc, proc);
2914 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2915 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2916 (LONG_PTR)test_proc, proc);
2918 filter_messages = focus_window;
2920 ref = IDirect3DDevice8_Release(device);
2921 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
2923 filter_messages = device_window;
2925 device_desc.device_window = focus_window;
2926 if (!(device = create_device(d3d8, focus_window, &device_desc)))
2928 skip("Failed to create a D3D device, skipping tests.\n");
2929 goto done;
2932 filter_messages = NULL;
2934 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
2935 hr = reset_device(device, &device_desc);
2936 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
2938 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
2939 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2940 (LONG_PTR)test_proc, proc);
2942 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2943 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx.\n", (LONG_PTR)test_proc);
2945 device_desc.flags = 0;
2946 hr = reset_device(device, &device_desc);
2947 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
2949 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
2950 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2951 (LONG_PTR)test_proc, proc);
2953 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2954 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2955 (LONG_PTR)test_proc, proc);
2957 filter_messages = device_window;
2959 ref = IDirect3DDevice8_Release(device);
2960 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
2962 device_desc.device_window = device_window;
2963 if (!(device = create_device(d3d8, focus_window, &device_desc)))
2965 skip("Failed to create a D3D device, skipping tests.\n");
2966 goto done;
2969 filter_messages = NULL;
2971 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
2972 hr = reset_device(device, &device_desc);
2973 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
2975 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
2976 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2977 (LONG_PTR)test_proc, proc);
2979 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2980 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx.\n", (LONG_PTR)test_proc);
2982 device_desc.flags = 0;
2983 hr = reset_device(device, &device_desc);
2984 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
2986 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
2987 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2988 (LONG_PTR)test_proc, proc);
2990 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2991 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2992 (LONG_PTR)test_proc, proc);
2994 filter_messages = device_window;
2996 ref = IDirect3DDevice8_Release(device);
2997 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
2999 done:
3000 filter_messages = NULL;
3001 IDirect3D8_Release(d3d8);
3003 SetEvent(thread_params.test_finished);
3004 WaitForSingleObject(thread, INFINITE);
3005 CloseHandle(thread_params.test_finished);
3006 CloseHandle(thread_params.window_created);
3007 CloseHandle(thread);
3009 DestroyWindow(device_window);
3010 DestroyWindow(focus_window);
3011 UnregisterClassA("d3d8_test_wndproc_wc", GetModuleHandleA(NULL));
3014 static inline void set_fpu_cw(WORD cw)
3016 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3017 #define D3D8_TEST_SET_FPU_CW 1
3018 __asm__ volatile ("fnclex");
3019 __asm__ volatile ("fldcw %0" : : "m" (cw));
3020 #elif defined(__i386__) && defined(_MSC_VER)
3021 #define D3D8_TEST_SET_FPU_CW 1
3022 __asm fnclex;
3023 __asm fldcw cw;
3024 #endif
3027 static inline WORD get_fpu_cw(void)
3029 WORD cw = 0;
3030 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3031 #define D3D8_TEST_GET_FPU_CW 1
3032 __asm__ volatile ("fnstcw %0" : "=m" (cw));
3033 #elif defined(__i386__) && defined(_MSC_VER)
3034 #define D3D8_TEST_GET_FPU_CW 1
3035 __asm fnstcw cw;
3036 #endif
3037 return cw;
3040 static WORD callback_cw, callback_set_cw;
3041 static DWORD callback_tid;
3043 static HRESULT WINAPI dummy_object_QueryInterface(IUnknown *iface, REFIID riid, void **out)
3045 *out = NULL;
3046 return E_NOINTERFACE;
3049 static ULONG WINAPI dummy_object_AddRef(IUnknown *iface)
3051 callback_cw = get_fpu_cw();
3052 set_fpu_cw(callback_set_cw);
3053 callback_tid = GetCurrentThreadId();
3054 return 2;
3057 static ULONG WINAPI dummy_object_Release(IUnknown *iface)
3059 callback_cw = get_fpu_cw();
3060 set_fpu_cw(callback_set_cw);
3061 callback_tid = GetCurrentThreadId();
3062 return 1;
3065 static const IUnknownVtbl dummy_object_vtbl =
3067 dummy_object_QueryInterface,
3068 dummy_object_AddRef,
3069 dummy_object_Release,
3072 static const GUID d3d8_private_data_test_guid =
3074 0xfdb37466,
3075 0x428f,
3076 0x4edf,
3077 {0xa3,0x7f,0x9b,0x1d,0xf4,0x88,0xc5,0xfc}
3080 static void test_fpu_setup(void)
3082 #if defined(D3D8_TEST_SET_FPU_CW) && defined(D3D8_TEST_GET_FPU_CW)
3083 struct device_desc device_desc;
3084 IDirect3DDevice8 *device;
3085 D3DDISPLAYMODE d3ddm;
3086 IDirect3D8 *d3d8;
3087 HWND window;
3088 HRESULT hr;
3089 WORD cw;
3090 IDirect3DSurface8 *surface;
3091 IUnknown dummy_object = {&dummy_object_vtbl};
3093 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_CAPTION, 0, 0,
3094 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight, 0, 0, 0, 0);
3095 ok(!!window, "Failed to create a window.\n");
3096 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
3097 ok(!!d3d8, "Failed to create a D3D object.\n");
3099 hr = IDirect3D8_GetAdapterDisplayMode(d3d8, D3DADAPTER_DEFAULT, &d3ddm);
3100 ok(SUCCEEDED(hr), "GetAdapterDisplayMode failed, hr %#x.\n", hr);
3102 device_desc.device_window = window;
3103 device_desc.width = 640;
3104 device_desc.height = 480;
3105 device_desc.flags = 0;
3107 set_fpu_cw(0xf60);
3108 cw = get_fpu_cw();
3109 ok(cw == 0xf60, "cw is %#x, expected 0xf60.\n", cw);
3111 if (!(device = create_device(d3d8, window, &device_desc)))
3113 skip("Failed to create a 3D device, skipping test.\n");
3114 set_fpu_cw(0x37f);
3115 goto done;
3118 cw = get_fpu_cw();
3119 ok(cw == 0x7f, "cw is %#x, expected 0x7f.\n", cw);
3121 hr = IDirect3DDevice8_GetRenderTarget(device, &surface);
3122 ok(SUCCEEDED(hr), "Failed to get render target surface, hr %#x.\n", hr);
3124 callback_set_cw = 0xf60;
3125 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
3126 &dummy_object, sizeof(IUnknown *), D3DSPD_IUNKNOWN);
3127 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
3128 ok(callback_cw == 0x7f, "Callback cw is %#x, expected 0x7f.\n", callback_cw);
3129 ok(callback_tid == GetCurrentThreadId(), "Got unexpected thread id.\n");
3130 cw = get_fpu_cw();
3131 ok(cw == 0xf60, "cw is %#x, expected 0xf60.\n", cw);
3133 callback_cw = 0;
3134 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
3135 &dummy_object, sizeof(IUnknown *), D3DSPD_IUNKNOWN);
3136 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
3137 ok(callback_cw == 0xf60, "Callback cw is %#x, expected 0xf60.\n", callback_cw);
3138 ok(callback_tid == GetCurrentThreadId(), "Got unexpected thread id.\n");
3140 callback_set_cw = 0x7f;
3141 set_fpu_cw(0x7f);
3143 IDirect3DSurface8_Release(surface);
3145 callback_cw = 0;
3146 IDirect3DDevice8_Release(device);
3147 ok(callback_cw == 0x7f, "Callback cw is %#x, expected 0x7f.\n", callback_cw);
3148 ok(callback_tid == GetCurrentThreadId(), "Got unexpected thread id.\n");
3150 cw = get_fpu_cw();
3151 ok(cw == 0x7f, "cw is %#x, expected 0x7f.\n", cw);
3152 set_fpu_cw(0xf60);
3153 cw = get_fpu_cw();
3154 ok(cw == 0xf60, "cw is %#x, expected 0xf60.\n", cw);
3156 device_desc.flags = CREATE_DEVICE_FPU_PRESERVE;
3157 device = create_device(d3d8, window, &device_desc);
3158 ok(!!device, "CreateDevice failed.\n");
3160 cw = get_fpu_cw();
3161 ok(cw == 0xf60, "cw is %#x, expected 0xf60.\n", cw);
3163 hr = IDirect3DDevice8_GetRenderTarget(device, &surface);
3164 ok(SUCCEEDED(hr), "Failed to get render target surface, hr %#x.\n", hr);
3166 callback_cw = 0;
3167 callback_set_cw = 0x37f;
3168 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
3169 &dummy_object, sizeof(IUnknown *), D3DSPD_IUNKNOWN);
3170 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
3171 ok(callback_cw == 0xf60, "Callback cw is %#x, expected 0xf60.\n", callback_cw);
3172 ok(callback_tid == GetCurrentThreadId(), "Got unexpected thread id.\n");
3173 cw = get_fpu_cw();
3174 ok(cw == 0x37f, "cw is %#x, expected 0x37f.\n", cw);
3176 IDirect3DSurface8_Release(surface);
3178 callback_cw = 0;
3179 IDirect3DDevice8_Release(device);
3180 ok(callback_cw == 0x37f, "Callback cw is %#x, expected 0x37f.\n", callback_cw);
3181 ok(callback_tid == GetCurrentThreadId(), "Got unexpected thread id.\n");
3183 done:
3184 DestroyWindow(window);
3185 IDirect3D8_Release(d3d8);
3186 #endif
3189 static void test_ApplyStateBlock(void)
3191 IDirect3DDevice8 *device;
3192 IDirect3D8 *d3d8;
3193 HWND window;
3194 HRESULT hr;
3195 DWORD received, token;
3197 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
3198 0, 0, 640, 480, NULL, NULL, NULL, NULL);
3199 ok(!!window, "Failed to create a window.\n");
3200 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
3201 ok(!!d3d8, "Failed to create a D3D object.\n");
3202 if (!(device = create_device(d3d8, window, NULL)))
3204 skip("Failed to create a 3D device, skipping test.\n");
3205 goto cleanup;
3208 IDirect3DDevice8_BeginStateBlock(device);
3209 IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, TRUE);
3210 IDirect3DDevice8_EndStateBlock(device, &token);
3211 ok(token, "Received zero stateblock handle.\n");
3212 IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, FALSE);
3214 hr = IDirect3DDevice8_GetRenderState(device, D3DRS_ZENABLE, &received);
3215 ok(hr == D3D_OK, "Expected D3D_OK, received %#x.\n", hr);
3216 ok(!received, "Expected = FALSE, received TRUE.\n");
3218 hr = IDirect3DDevice8_ApplyStateBlock(device, 0);
3219 ok(hr == D3D_OK, "Expected D3D_OK, received %#x.\n", hr);
3220 hr = IDirect3DDevice8_GetRenderState(device, D3DRS_ZENABLE, &received);
3221 ok(hr == D3D_OK, "Expected D3D_OK, received %#x.\n", hr);
3222 ok(!received, "Expected FALSE, received TRUE.\n");
3224 hr = IDirect3DDevice8_ApplyStateBlock(device, token);
3225 ok(hr == D3D_OK, "Expected D3D_OK, received %#x.\n", hr);
3226 hr = IDirect3DDevice8_GetRenderState(device, D3DRS_ZENABLE, &received);
3227 ok(hr == D3D_OK, "Expected D3D_OK, received %#x.\n", hr);
3228 ok(received, "Expected TRUE, received FALSE.\n");
3230 IDirect3DDevice8_DeleteStateBlock(device, token);
3231 IDirect3DDevice8_Release(device);
3232 cleanup:
3233 IDirect3D8_Release(d3d8);
3234 DestroyWindow(window);
3237 static void test_depth_stencil_size(void)
3239 IDirect3DDevice8 *device;
3240 IDirect3DSurface8 *ds, *rt, *ds_bigger, *ds_bigger2;
3241 IDirect3DSurface8 *surf;
3242 IDirect3D8 *d3d8;
3243 HRESULT hr;
3244 HWND hwnd;
3246 hwnd = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
3247 100, 100, 160, 160, NULL, NULL, NULL, NULL);
3248 ok(!!hwnd, "Failed to create a window.\n");
3249 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
3250 ok(!!d3d8, "Failed to create a D3D object.\n");
3252 if (!(device = create_device(d3d8, hwnd, NULL)))
3254 skip("Failed to create a 3D device, skipping test.\n");
3255 goto cleanup;
3258 hr = IDirect3DDevice8_CreateRenderTarget(device, 64, 64, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, FALSE, &rt);
3259 ok(SUCCEEDED(hr), "IDirect3DDevice8_CreateRenderTarget failed, hr %#x.\n", hr);
3260 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 32, 32, D3DFMT_D24X8, D3DMULTISAMPLE_NONE, &ds);
3261 ok(SUCCEEDED(hr), "IDirect3DDevice8_CreateDepthStencilSurface failed, hr %#x.\n", hr);
3262 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 128, 128, D3DFMT_D24X8, D3DMULTISAMPLE_NONE, &ds_bigger);
3263 ok(SUCCEEDED(hr), "IDirect3DDevice8_CreateDepthStencilSurface failed, hr %#x.\n", hr);
3264 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 128, 128, D3DFMT_D24X8, D3DMULTISAMPLE_NONE, &ds_bigger2);
3265 ok(SUCCEEDED(hr), "IDirect3DDevice8_CreateDepthStencilSurface failed, hr %#x.\n", hr);
3267 hr = IDirect3DDevice8_SetRenderTarget(device, rt, ds);
3268 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_SetRenderTarget returned %#x, expected D3DERR_INVALIDCALL.\n", hr);
3269 hr = IDirect3DDevice8_SetRenderTarget(device, rt, ds_bigger);
3270 ok(SUCCEEDED(hr), "IDirect3DDevice8_SetRenderTarget failed, hr %#x.\n", hr);
3272 /* try to set the small ds without changing the render target at the same time */
3273 hr = IDirect3DDevice8_SetRenderTarget(device, NULL, ds);
3274 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_SetRenderTarget returned %#x, expected D3DERR_INVALIDCALL.\n", hr);
3275 hr = IDirect3DDevice8_SetRenderTarget(device, NULL, ds_bigger2);
3276 ok(SUCCEEDED(hr), "IDirect3DDevice8_SetRenderTarget failed, hr %#x.\n", hr);
3278 hr = IDirect3DDevice8_GetRenderTarget(device, &surf);
3279 ok(hr == D3D_OK, "IDirect3DDevice8_GetRenderTarget failed, hr %#x.\n", hr);
3280 ok(surf == rt, "The render target is %p, expected %p\n", surf, rt);
3281 IDirect3DSurface8_Release(surf);
3282 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surf);
3283 ok(hr == D3D_OK, "IDirect3DDevice8_GetDepthStencilSurface failed, hr %#x.\n", hr);
3284 ok(surf == ds_bigger2, "The depth stencil is %p, expected %p\n", surf, ds_bigger2);
3285 IDirect3DSurface8_Release(surf);
3287 hr = IDirect3DDevice8_SetRenderTarget(device, NULL, NULL);
3288 ok(SUCCEEDED(hr), "IDirect3DDevice8_SetRenderTarget failed, hr %#x.\n", hr);
3289 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surf);
3290 ok(FAILED(hr), "IDirect3DDevice8_GetDepthStencilSurface should have failed, hr %#x.\n", hr);
3291 ok(surf == NULL, "The depth stencil is %p, expected NULL\n", surf);
3292 if (surf) IDirect3DSurface8_Release(surf);
3294 IDirect3DSurface8_Release(rt);
3295 IDirect3DSurface8_Release(ds);
3296 IDirect3DSurface8_Release(ds_bigger);
3297 IDirect3DSurface8_Release(ds_bigger2);
3299 cleanup:
3300 IDirect3D8_Release(d3d8);
3301 DestroyWindow(hwnd);
3304 static void test_window_style(void)
3306 RECT focus_rect, fullscreen_rect, r;
3307 LONG device_style, device_exstyle;
3308 LONG focus_style, focus_exstyle;
3309 struct device_desc device_desc;
3310 LONG style, expected_style;
3311 IDirect3DDevice8 *device;
3312 IDirect3D8 *d3d8;
3313 HRESULT hr;
3314 ULONG ref;
3315 BOOL ret;
3317 focus_window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
3318 0, 0, registry_mode.dmPelsWidth / 2, registry_mode.dmPelsHeight / 2, 0, 0, 0, 0);
3319 device_window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
3320 0, 0, registry_mode.dmPelsWidth / 2, registry_mode.dmPelsHeight / 2, 0, 0, 0, 0);
3321 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
3322 ok(!!d3d8, "Failed to create a D3D object.\n");
3324 device_style = GetWindowLongA(device_window, GWL_STYLE);
3325 device_exstyle = GetWindowLongA(device_window, GWL_EXSTYLE);
3326 focus_style = GetWindowLongA(focus_window, GWL_STYLE);
3327 focus_exstyle = GetWindowLongA(focus_window, GWL_EXSTYLE);
3329 SetRect(&fullscreen_rect, 0, 0, registry_mode.dmPelsWidth, registry_mode.dmPelsHeight);
3330 GetWindowRect(focus_window, &focus_rect);
3332 device_desc.device_window = device_window;
3333 device_desc.width = registry_mode.dmPelsWidth;
3334 device_desc.height = registry_mode.dmPelsHeight;
3335 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
3336 if (!(device = create_device(d3d8, focus_window, &device_desc)))
3338 skip("Failed to create a D3D device, skipping tests.\n");
3339 goto done;
3342 style = GetWindowLongA(device_window, GWL_STYLE);
3343 expected_style = device_style | WS_VISIBLE;
3344 todo_wine ok(style == expected_style, "Expected device window style %#x, got %#x.\n",
3345 expected_style, style);
3346 style = GetWindowLongA(device_window, GWL_EXSTYLE);
3347 expected_style = device_exstyle | WS_EX_TOPMOST;
3348 todo_wine ok(style == expected_style, "Expected device window extended style %#x, got %#x.\n",
3349 expected_style, style);
3351 style = GetWindowLongA(focus_window, GWL_STYLE);
3352 ok(style == focus_style, "Expected focus window style %#x, got %#x.\n",
3353 focus_style, style);
3354 style = GetWindowLongA(focus_window, GWL_EXSTYLE);
3355 ok(style == focus_exstyle, "Expected focus window extended style %#x, got %#x.\n",
3356 focus_exstyle, style);
3358 GetWindowRect(device_window, &r);
3359 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3360 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
3361 r.left, r.top, r.right, r.bottom);
3362 GetClientRect(device_window, &r);
3363 todo_wine ok(!EqualRect(&r, &fullscreen_rect), "Client rect and window rect are equal.\n");
3364 GetWindowRect(focus_window, &r);
3365 ok(EqualRect(&r, &focus_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3366 focus_rect.left, focus_rect.top, focus_rect.right, focus_rect.bottom,
3367 r.left, r.top, r.right, r.bottom);
3369 device_desc.flags = 0;
3370 hr = reset_device(device, &device_desc);
3371 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
3373 style = GetWindowLongA(device_window, GWL_STYLE);
3374 expected_style = device_style | WS_VISIBLE;
3375 ok(style == expected_style, "Expected device window style %#x, got %#x.\n",
3376 expected_style, style);
3377 style = GetWindowLongA(device_window, GWL_EXSTYLE);
3378 expected_style = device_exstyle | WS_EX_TOPMOST;
3379 ok(style == expected_style, "Expected device window extended style %#x, got %#x.\n",
3380 expected_style, style);
3382 style = GetWindowLongA(focus_window, GWL_STYLE);
3383 ok(style == focus_style, "Expected focus window style %#x, got %#x.\n",
3384 focus_style, style);
3385 style = GetWindowLongA(focus_window, GWL_EXSTYLE);
3386 ok(style == focus_exstyle, "Expected focus window extended style %#x, got %#x.\n",
3387 focus_exstyle, style);
3389 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
3390 hr = reset_device(device, &device_desc);
3391 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
3392 ret = SetForegroundWindow(GetDesktopWindow());
3393 ok(ret, "Failed to set foreground window.\n");
3395 style = GetWindowLongA(device_window, GWL_STYLE);
3396 expected_style = device_style | WS_MINIMIZE | WS_VISIBLE;
3397 todo_wine ok(style == expected_style, "Expected device window style %#x, got %#x.\n",
3398 expected_style, style);
3399 style = GetWindowLongA(device_window, GWL_EXSTYLE);
3400 expected_style = device_exstyle | WS_EX_TOPMOST;
3401 todo_wine ok(style == expected_style, "Expected device window extended style %#x, got %#x.\n",
3402 expected_style, style);
3404 style = GetWindowLongA(focus_window, GWL_STYLE);
3405 ok(style == focus_style, "Expected focus window style %#x, got %#x.\n",
3406 focus_style, style);
3407 style = GetWindowLongA(focus_window, GWL_EXSTYLE);
3408 ok(style == focus_exstyle, "Expected focus window extended style %#x, got %#x.\n",
3409 focus_exstyle, style);
3411 /* Follow-up tests fail on native if the device is destroyed while lost. */
3412 ShowWindow(focus_window, SW_MINIMIZE);
3413 ShowWindow(focus_window, SW_RESTORE);
3414 ret = SetForegroundWindow(focus_window);
3415 ok(ret, "Failed to set foreground window.\n");
3416 flush_events();
3417 hr = reset_device(device, &device_desc);
3418 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
3420 ref = IDirect3DDevice8_Release(device);
3421 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
3423 done:
3424 IDirect3D8_Release(d3d8);
3426 DestroyWindow(device_window);
3427 DestroyWindow(focus_window);
3430 static void test_unsupported_shaders(void)
3432 IDirect3DDevice8 *device;
3433 IDirect3D8 *d3d;
3434 ULONG refcount;
3435 DWORD vs, ps;
3436 HWND window;
3437 HRESULT hr;
3438 D3DCAPS8 caps;
3440 static const DWORD vs_2_0[] =
3442 0xfffe0200, /* vs_2_0 */
3443 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
3444 0x02000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
3445 0x03000002, 0xd00f0000, 0x80e40001, 0xa0e40002, /* add oD0, r1, c2 */
3446 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
3447 0x0000ffff /* end */
3449 static const DWORD ps_2_0[] =
3451 0xffff0200, /* ps_2_0 */
3452 0x02000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
3453 0x03000002, 0x800f0000, 0x80e40001, 0xa0e40002, /* add r0, r1, c2 */
3454 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
3455 0x0000ffff /* end */
3457 #if 0
3458 vs_1_1
3459 dcl_position v0
3460 def c255, 1.0, 1.0, 1.0, 1.0
3461 add r0, v0, c255
3462 mov oPos, r0
3463 #endif
3464 static const DWORD vs_1_255[] =
3466 0xfffe0101,
3467 0x0000001f, 0x80000000, 0x900f0000,
3468 0x00000051, 0xa00f00ff, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
3469 0x00000002, 0x800f0000, 0x90e40000, 0xa0e400ff,
3470 0x00000001, 0xc00f0000, 0x80e40000,
3471 0x0000ffff
3473 #if 0
3474 vs_1_1
3475 dcl_position v0
3476 def c256, 1.0, 1.0, 1.0, 1.0
3477 add r0, v0, c256
3478 mov oPos, r0
3479 #endif
3480 static const DWORD vs_1_256[] =
3482 0xfffe0101,
3483 0x0000001f, 0x80000000, 0x900f0000,
3484 0x00000051, 0xa00f0100, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
3485 0x00000002, 0x800f0000, 0x90e40000, 0xa0e40100,
3486 0x00000001, 0xc00f0000, 0x80e40000,
3487 0x0000ffff
3490 static const DWORD decl[] =
3492 D3DVSD_STREAM(0),
3493 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3),
3494 D3DVSD_END()
3497 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
3498 0, 0, 640, 480, NULL, NULL, NULL, NULL);
3499 ok(!!window, "Failed to create a window.\n");
3500 d3d = Direct3DCreate8(D3D_SDK_VERSION);
3501 ok(!!d3d, "Failed to create a D3D object.\n");
3502 if (!(device = create_device(d3d, window, NULL)))
3504 skip("Failed to create a D3D device, skipping tests.\n");
3505 IDirect3D8_Release(d3d);
3506 DestroyWindow(window);
3507 return;
3510 hr = IDirect3DDevice8_CreateVertexShader(device, decl, simple_ps, &vs, 0);
3511 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
3513 hr = IDirect3DDevice8_CreatePixelShader(device, simple_vs, &ps);
3514 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr);
3516 hr = IDirect3DDevice8_CreateVertexShader(device, decl, vs_2_0, &vs, 0);
3517 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
3519 hr = IDirect3DDevice8_CreatePixelShader(device, ps_2_0, &ps);
3520 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr);
3522 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
3523 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
3524 if (caps.MaxVertexShaderConst < 256)
3526 hr = IDirect3DDevice8_CreateVertexShader(device, decl, vs_1_255, &vs, 0);
3527 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3529 else
3531 hr = IDirect3DDevice8_CreateVertexShader(device, decl, vs_1_255, &vs, 0);
3532 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3533 hr = IDirect3DDevice8_DeleteVertexShader(device, vs);
3534 ok(hr == D3D_OK, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
3535 hr = IDirect3DDevice8_CreateVertexShader(device, decl, vs_1_256, &vs, 0);
3536 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3539 refcount = IDirect3DDevice8_Release(device);
3540 ok(!refcount, "Device has %u references left.\n", refcount);
3541 IDirect3D8_Release(d3d);
3542 DestroyWindow(window);
3545 static void test_mode_change(void)
3547 RECT d3d_rect, focus_rect, r;
3548 struct device_desc device_desc;
3549 IDirect3DSurface8 *backbuffer;
3550 IDirect3DDevice8 *device;
3551 D3DSURFACE_DESC desc;
3552 IDirect3D8 *d3d8;
3553 DEVMODEW devmode;
3554 ULONG refcount;
3555 UINT adapter_mode_count, i;
3556 HRESULT hr;
3557 BOOL ret;
3558 LONG change_ret;
3559 D3DDISPLAYMODE d3ddm;
3560 DWORD d3d_width = 0, d3d_height = 0, user32_width = 0, user32_height = 0;
3562 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
3563 ok(!!d3d8, "Failed to create a D3D object.\n");
3565 adapter_mode_count = IDirect3D8_GetAdapterModeCount(d3d8, D3DADAPTER_DEFAULT);
3566 for (i = 0; i < adapter_mode_count; ++i)
3568 hr = IDirect3D8_EnumAdapterModes(d3d8, D3DADAPTER_DEFAULT, i, &d3ddm);
3569 ok(SUCCEEDED(hr), "Failed to enumerate display mode, hr %#x.\n", hr);
3571 if (d3ddm.Format != D3DFMT_X8R8G8B8)
3572 continue;
3573 if (d3ddm.Width == registry_mode.dmPelsWidth && d3ddm.Height == registry_mode.dmPelsHeight)
3574 continue;
3575 /* The r200 driver on Windows XP enumerates modes like 320x200 and 320x240 but
3576 * refuses to create a device at these sizes. */
3577 if (d3ddm.Width < 640 || d3ddm.Height < 480)
3578 continue;
3580 if (!user32_width)
3582 user32_width = d3ddm.Width;
3583 user32_height = d3ddm.Height;
3584 continue;
3587 /* Make sure the d3d mode is smaller in width or height and at most
3588 * equal in the other dimension than the mode passed to
3589 * ChangeDisplaySettings. Otherwise Windows shrinks the window to
3590 * the ChangeDisplaySettings parameters + 12. */
3591 if (d3ddm.Width == user32_width && d3ddm.Height == user32_height)
3592 continue;
3593 if (d3ddm.Width <= user32_width && d3ddm.Height <= user32_height)
3595 d3d_width = d3ddm.Width;
3596 d3d_height = d3ddm.Height;
3597 break;
3599 if (user32_width <= d3ddm.Width && user32_height <= d3ddm.Height)
3601 d3d_width = user32_width;
3602 d3d_height = user32_height;
3603 user32_width = d3ddm.Width;
3604 user32_height = d3ddm.Height;
3605 break;
3609 if (!d3d_width)
3611 skip("Could not find adequate modes, skipping mode tests.\n");
3612 IDirect3D8_Release(d3d8);
3613 return;
3616 memset(&devmode, 0, sizeof(devmode));
3617 devmode.dmSize = sizeof(devmode);
3618 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
3619 devmode.dmPelsWidth = user32_width;
3620 devmode.dmPelsHeight = user32_height;
3621 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
3622 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
3624 /* Make the windows visible, otherwise device::release does not restore the mode if
3625 * the application is not in foreground like on the testbot. */
3626 focus_window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
3627 0, 0, user32_width / 2, user32_height / 2, 0, 0, 0, 0);
3628 device_window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
3629 0, 0, user32_width / 2, user32_height / 2, 0, 0, 0, 0);
3631 SetRect(&d3d_rect, 0, 0, d3d_width, d3d_height);
3632 GetWindowRect(focus_window, &focus_rect);
3634 device_desc.device_window = device_window;
3635 device_desc.width = d3d_width;
3636 device_desc.height = d3d_height;
3637 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
3638 if (!(device = create_device(d3d8, focus_window, &device_desc)))
3640 skip("Failed to create a D3D device, skipping tests.\n");
3641 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
3642 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
3643 goto done;
3646 devmode.dmPelsWidth = user32_width;
3647 devmode.dmPelsHeight = user32_height;
3648 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
3649 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
3651 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
3652 ok(ret, "Failed to get display mode.\n");
3653 ok(devmode.dmPelsWidth == user32_width && devmode.dmPelsHeight == user32_height,
3654 "Expected resolution %ux%u, got %ux%u.\n",
3655 user32_width, user32_height, devmode.dmPelsWidth, devmode.dmPelsHeight);
3657 GetWindowRect(device_window, &r);
3658 ok(EqualRect(&r, &d3d_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3659 d3d_rect.left, d3d_rect.top, d3d_rect.right, d3d_rect.bottom,
3660 r.left, r.top, r.right, r.bottom);
3661 GetWindowRect(focus_window, &r);
3662 ok(EqualRect(&r, &focus_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3663 focus_rect.left, focus_rect.top, focus_rect.right, focus_rect.bottom,
3664 r.left, r.top, r.right, r.bottom);
3666 hr = IDirect3DDevice8_GetBackBuffer(device, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
3667 ok(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
3668 hr = IDirect3DSurface8_GetDesc(backbuffer, &desc);
3669 ok(SUCCEEDED(hr), "Failed to get backbuffer desc, hr %#x.\n", hr);
3670 ok(desc.Width == d3d_width, "Got unexpected backbuffer width %u, expected %u.\n",
3671 desc.Width, d3d_width);
3672 ok(desc.Height == d3d_height, "Got unexpected backbuffer height %u, expected %u.\n",
3673 desc.Height, d3d_height);
3674 IDirect3DSurface8_Release(backbuffer);
3676 refcount = IDirect3DDevice8_Release(device);
3677 ok(!refcount, "Device has %u references left.\n", refcount);
3679 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
3680 ok(ret, "Failed to get display mode.\n");
3681 todo_wine ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
3682 && devmode.dmPelsHeight == registry_mode.dmPelsHeight,
3683 "Expected resolution %ux%u, got %ux%u.\n",
3684 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight, devmode.dmPelsWidth, devmode.dmPelsHeight);
3686 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
3687 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
3689 /* The mode restore also happens when the device was created at the original screen size. */
3691 device_desc.device_window = device_window;
3692 device_desc.width = registry_mode.dmPelsWidth;
3693 device_desc.height = registry_mode.dmPelsHeight;
3694 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
3695 ok(!!(device = create_device(d3d8, focus_window, &device_desc)), "Failed to create a D3D device.\n");
3697 devmode.dmPelsWidth = user32_width;
3698 devmode.dmPelsHeight = user32_height;
3699 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
3700 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
3702 refcount = IDirect3DDevice8_Release(device);
3703 ok(!refcount, "Device has %u references left.\n", refcount);
3705 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
3706 ok(ret, "Failed to get display mode.\n");
3707 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
3708 && devmode.dmPelsHeight == registry_mode.dmPelsHeight,
3709 "Expected resolution %ux%u, got %ux%u.\n",
3710 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight, devmode.dmPelsWidth, devmode.dmPelsHeight);
3712 done:
3713 DestroyWindow(device_window);
3714 DestroyWindow(focus_window);
3715 IDirect3D8_Release(d3d8);
3718 static void test_device_window_reset(void)
3720 RECT fullscreen_rect, device_rect, r;
3721 struct device_desc device_desc;
3722 IDirect3DDevice8 *device;
3723 WNDCLASSA wc = {0};
3724 IDirect3D8 *d3d8;
3725 LONG_PTR proc;
3726 HRESULT hr;
3727 ULONG ref;
3729 wc.lpfnWndProc = test_proc;
3730 wc.lpszClassName = "d3d8_test_wndproc_wc";
3731 ok(RegisterClassA(&wc), "Failed to register window class.\n");
3733 focus_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
3734 0, 0, registry_mode.dmPelsWidth / 2, registry_mode.dmPelsHeight / 2, 0, 0, 0, 0);
3735 device_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
3736 0, 0, registry_mode.dmPelsWidth / 2, registry_mode.dmPelsHeight / 2, 0, 0, 0, 0);
3737 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
3738 ok(!!d3d8, "Failed to create a D3D object.\n");
3740 SetRect(&fullscreen_rect, 0, 0, registry_mode.dmPelsWidth, registry_mode.dmPelsHeight);
3741 GetWindowRect(device_window, &device_rect);
3743 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
3744 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3745 (LONG_PTR)test_proc, proc);
3746 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3747 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3748 (LONG_PTR)test_proc, proc);
3750 device_desc.device_window = NULL;
3751 device_desc.width = registry_mode.dmPelsWidth;
3752 device_desc.height = registry_mode.dmPelsHeight;
3753 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
3754 if (!(device = create_device(d3d8, focus_window, &device_desc)))
3756 skip("Failed to create a D3D device, skipping tests.\n");
3757 goto done;
3760 GetWindowRect(focus_window, &r);
3761 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3762 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
3763 r.left, r.top, r.right, r.bottom);
3764 GetWindowRect(device_window, &r);
3765 ok(EqualRect(&r, &device_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3766 device_rect.left, device_rect.top, device_rect.right, device_rect.bottom,
3767 r.left, r.top, r.right, r.bottom);
3769 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
3770 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3771 (LONG_PTR)test_proc, proc);
3772 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3773 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx.\n", (LONG_PTR)test_proc);
3775 device_desc.device_window = device_window;
3776 hr = reset_device(device, &device_desc);
3777 ok(SUCCEEDED(hr), "Failed to reset device.\n");
3779 GetWindowRect(focus_window, &r);
3780 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3781 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
3782 r.left, r.top, r.right, r.bottom);
3783 GetWindowRect(device_window, &r);
3784 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3785 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
3786 r.left, r.top, r.right, r.bottom);
3788 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
3789 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3790 (LONG_PTR)test_proc, proc);
3791 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3792 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx.\n", (LONG_PTR)test_proc);
3794 ref = IDirect3DDevice8_Release(device);
3795 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
3797 done:
3798 IDirect3D8_Release(d3d8);
3799 DestroyWindow(device_window);
3800 DestroyWindow(focus_window);
3801 UnregisterClassA("d3d8_test_wndproc_wc", GetModuleHandleA(NULL));
3804 static void depth_blit_test(void)
3806 IDirect3DDevice8 *device = NULL;
3807 IDirect3DSurface8 *backbuffer, *ds1, *ds2, *ds3;
3808 RECT src_rect;
3809 const POINT dst_point = {0, 0};
3810 IDirect3D8 *d3d8;
3811 HRESULT hr;
3812 HWND hwnd;
3814 hwnd = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
3815 100, 100, 160, 160, NULL, NULL, NULL, NULL);
3816 ok(!!hwnd, "Failed to create a window.\n");
3817 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
3818 ok(!!d3d8, "Failed to create a D3D object.\n");
3820 if (!(device = create_device(d3d8, hwnd, NULL)))
3822 skip("Failed to create a D3D device, skipping tests.\n");
3823 goto done;
3826 hr = IDirect3DDevice8_GetRenderTarget(device, &backbuffer);
3827 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
3828 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &ds1);
3829 ok(SUCCEEDED(hr), "GetDepthStencilSurface failed, hr %#x.\n", hr);
3830 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 640, 480, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, &ds2);
3831 ok(SUCCEEDED(hr), "CreateDepthStencilSurface failed, hr %#x.\n", hr);
3832 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 640, 480, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, &ds3);
3833 ok(SUCCEEDED(hr), "CreateDepthStencilSurface failed, hr %#x.\n", hr);
3835 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0, 0.0f, 0);
3836 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
3838 /* Partial blit. */
3839 SetRect(&src_rect, 0, 0, 320, 240);
3840 hr = IDirect3DDevice8_CopyRects(device, ds1, &src_rect, 1, ds2, &dst_point);
3841 ok(hr == D3DERR_INVALIDCALL, "CopyRects returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
3842 /* Flipped. */
3843 SetRect(&src_rect, 0, 480, 640, 0);
3844 hr = IDirect3DDevice8_CopyRects(device, ds1, &src_rect, 1, ds2, &dst_point);
3845 ok(hr == D3DERR_INVALIDCALL, "CopyRects returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
3846 /* Full, explicit. */
3847 SetRect(&src_rect, 0, 0, 640, 480);
3848 hr = IDirect3DDevice8_CopyRects(device, ds1, &src_rect, 1, ds2, &dst_point);
3849 ok(hr == D3DERR_INVALIDCALL, "CopyRects returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
3850 /* Depth -> color blit.*/
3851 hr = IDirect3DDevice8_CopyRects(device, ds1, &src_rect, 1, backbuffer, &dst_point);
3852 ok(hr == D3DERR_INVALIDCALL, "CopyRects returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
3853 /* Full, NULL rects, current depth stencil -> unbound depth stencil */
3854 hr = IDirect3DDevice8_CopyRects(device, ds1, NULL, 0, ds2, NULL);
3855 ok(hr == D3DERR_INVALIDCALL, "CopyRects returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
3856 /* Full, NULL rects, unbound depth stencil -> current depth stencil */
3857 hr = IDirect3DDevice8_CopyRects(device, ds2, NULL, 0, ds1, NULL);
3858 ok(hr == D3DERR_INVALIDCALL, "CopyRects returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
3859 /* Full, NULL rects, unbound depth stencil -> unbound depth stencil */
3860 hr = IDirect3DDevice8_CopyRects(device, ds2, NULL, 0, ds3, NULL);
3861 ok(hr == D3DERR_INVALIDCALL, "CopyRects returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
3863 IDirect3DSurface8_Release(backbuffer);
3864 IDirect3DSurface8_Release(ds3);
3865 IDirect3DSurface8_Release(ds2);
3866 IDirect3DSurface8_Release(ds1);
3868 done:
3869 if (device) IDirect3DDevice8_Release(device);
3870 IDirect3D8_Release(d3d8);
3871 DestroyWindow(hwnd);
3874 static void test_reset_resources(void)
3876 IDirect3DSurface8 *surface, *rt;
3877 IDirect3DTexture8 *texture;
3878 IDirect3DDevice8 *device;
3879 IDirect3D8 *d3d8;
3880 HWND window;
3881 HRESULT hr;
3882 ULONG ref;
3884 window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW,
3885 0, 0, 640, 480, 0, 0, 0, 0);
3886 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
3887 ok(!!d3d8, "Failed to create a D3D object.\n");
3889 if (!(device = create_device(d3d8, window, NULL)))
3891 skip("Failed to create a D3D device, skipping tests.\n");
3892 goto done;
3895 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 128, 128, D3DFMT_D24S8,
3896 D3DMULTISAMPLE_NONE, &surface);
3897 ok(SUCCEEDED(hr), "Failed to create depth/stencil surface, hr %#x.\n", hr);
3899 hr = IDirect3DDevice8_CreateTexture(device, 128, 128, 1, D3DUSAGE_RENDERTARGET,
3900 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture);
3901 ok(SUCCEEDED(hr), "Failed to create render target texture, hr %#x.\n", hr);
3902 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 0, &rt);
3903 ok(SUCCEEDED(hr), "Failed to get surface, hr %#x.\n", hr);
3904 IDirect3DTexture8_Release(texture);
3906 hr = IDirect3DDevice8_SetRenderTarget(device, rt, surface);
3907 ok(SUCCEEDED(hr), "Failed to set render target surface, hr %#x.\n", hr);
3908 IDirect3DSurface8_Release(rt);
3909 IDirect3DSurface8_Release(surface);
3911 hr = reset_device(device, NULL);
3912 ok(SUCCEEDED(hr), "Failed to reset device.\n");
3914 hr = IDirect3DDevice8_GetBackBuffer(device, 0, D3DBACKBUFFER_TYPE_MONO, &rt);
3915 ok(SUCCEEDED(hr), "Failed to get back buffer, hr %#x.\n", hr);
3916 hr = IDirect3DDevice8_GetRenderTarget(device, &surface);
3917 ok(SUCCEEDED(hr), "Failed to get render target surface, hr %#x.\n", hr);
3918 ok(surface == rt, "Got unexpected surface %p for render target.\n", surface);
3919 IDirect3DSurface8_Release(surface);
3920 IDirect3DSurface8_Release(rt);
3922 ref = IDirect3DDevice8_Release(device);
3923 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
3925 done:
3926 IDirect3D8_Release(d3d8);
3927 DestroyWindow(window);
3930 static void test_set_rt_vp_scissor(void)
3932 IDirect3DDevice8 *device;
3933 IDirect3DSurface8 *rt;
3934 IDirect3D8 *d3d8;
3935 DWORD stateblock;
3936 D3DVIEWPORT8 vp;
3937 UINT refcount;
3938 HWND window;
3939 HRESULT hr;
3941 window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW,
3942 0, 0, 640, 480, 0, 0, 0, 0);
3943 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
3944 ok(!!d3d8, "Failed to create a D3D object.\n");
3945 if (!(device = create_device(d3d8, window, NULL)))
3947 skip("Failed to create a D3D device, skipping tests.\n");
3948 IDirect3D8_Release(d3d8);
3949 DestroyWindow(window);
3950 return;
3953 hr = IDirect3DDevice8_CreateRenderTarget(device, 128, 128, D3DFMT_A8R8G8B8,
3954 D3DMULTISAMPLE_NONE, FALSE, &rt);
3955 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
3957 hr = IDirect3DDevice8_GetViewport(device, &vp);
3958 ok(SUCCEEDED(hr), "Failed to get viewport, hr %#x.\n", hr);
3959 ok(!vp.X, "Got unexpected vp.X %u.\n", vp.X);
3960 ok(!vp.Y, "Got unexpected vp.Y %u.\n", vp.Y);
3961 ok(vp.Width == 640, "Got unexpected vp.Width %u.\n", vp.Width);
3962 ok(vp.Height == 480, "Got unexpected vp.Height %u.\n", vp.Height);
3963 ok(vp.MinZ == 0.0f, "Got unexpected vp.MinZ %.8e.\n", vp.MinZ);
3964 ok(vp.MaxZ == 1.0f, "Got unexpected vp.MaxZ %.8e.\n", vp.MaxZ);
3966 hr = IDirect3DDevice8_BeginStateBlock(device);
3967 ok(SUCCEEDED(hr), "Failed to begin stateblock, hr %#x.\n", hr);
3969 hr = IDirect3DDevice8_SetRenderTarget(device, rt, NULL);
3970 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
3972 hr = IDirect3DDevice8_EndStateBlock(device, &stateblock);
3973 ok(SUCCEEDED(hr), "Failed to end stateblock, hr %#x.\n", hr);
3974 hr = IDirect3DDevice8_DeleteStateBlock(device, stateblock);
3975 ok(SUCCEEDED(hr), "Failed to delete stateblock, hr %#x.\n", hr);
3977 hr = IDirect3DDevice8_GetViewport(device, &vp);
3978 ok(SUCCEEDED(hr), "Failed to get viewport, hr %#x.\n", hr);
3979 ok(!vp.X, "Got unexpected vp.X %u.\n", vp.X);
3980 ok(!vp.Y, "Got unexpected vp.Y %u.\n", vp.Y);
3981 ok(vp.Width == 128, "Got unexpected vp.Width %u.\n", vp.Width);
3982 ok(vp.Height == 128, "Got unexpected vp.Height %u.\n", vp.Height);
3983 ok(vp.MinZ == 0.0f, "Got unexpected vp.MinZ %.8e.\n", vp.MinZ);
3984 ok(vp.MaxZ == 1.0f, "Got unexpected vp.MaxZ %.8e.\n", vp.MaxZ);
3986 hr = IDirect3DDevice8_SetRenderTarget(device, rt, NULL);
3987 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
3989 vp.X = 10;
3990 vp.Y = 20;
3991 vp.Width = 30;
3992 vp.Height = 40;
3993 vp.MinZ = 0.25f;
3994 vp.MaxZ = 0.75f;
3995 hr = IDirect3DDevice8_SetViewport(device, &vp);
3996 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
3998 hr = IDirect3DDevice8_SetRenderTarget(device, rt, NULL);
3999 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
4001 hr = IDirect3DDevice8_GetViewport(device, &vp);
4002 ok(SUCCEEDED(hr), "Failed to get viewport, hr %#x.\n", hr);
4003 ok(!vp.X, "Got unexpected vp.X %u.\n", vp.X);
4004 ok(!vp.Y, "Got unexpected vp.Y %u.\n", vp.Y);
4005 ok(vp.Width == 128, "Got unexpected vp.Width %u.\n", vp.Width);
4006 ok(vp.Height == 128, "Got unexpected vp.Height %u.\n", vp.Height);
4007 ok(vp.MinZ == 0.0f, "Got unexpected vp.MinZ %.8e.\n", vp.MinZ);
4008 ok(vp.MaxZ == 1.0f, "Got unexpected vp.MaxZ %.8e.\n", vp.MaxZ);
4010 IDirect3DSurface8_Release(rt);
4011 refcount = IDirect3DDevice8_Release(device);
4012 ok(!refcount, "Device has %u references left.\n", refcount);
4013 IDirect3D8_Release(d3d8);
4014 DestroyWindow(window);
4017 static void test_validate_vs(void)
4019 static DWORD vs[] =
4021 0xfffe0101, /* vs_1_1 */
4022 0x00000009, 0xc0010000, 0x90e40000, 0xa0e40000, /* dp4 oPos.x, v0, c0 */
4023 0x00000009, 0xc0020000, 0x90e40000, 0xa0e40001, /* dp4 oPos.y, v0, c1 */
4024 0x00000009, 0xc0040000, 0x90e40000, 0xa0e40002, /* dp4 oPos.z, v0, c2 */
4025 0x00000009, 0xc0080000, 0x90e40000, 0xa0e40003, /* dp4 oPos.w, v0, c3 */
4026 0x0000ffff, /* end */
4028 HRESULT hr;
4030 hr = ValidateVertexShader(0, 0, 0, 0, 0);
4031 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
4032 hr = ValidateVertexShader(0, 0, 0, 1, 0);
4033 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
4034 hr = ValidateVertexShader(vs, 0, 0, 0, 0);
4035 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4037 hr = ValidateVertexShader(vs, 0, 0, 1, 0);
4038 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4039 /* Seems to do some version checking. */
4040 *vs = 0xfffe0100; /* vs_1_0 */
4041 hr = ValidateVertexShader(vs, 0, 0, 0, 0);
4042 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4044 *vs = 0xfffe0102; /* bogus version */
4045 hr = ValidateVertexShader(vs, 0, 0, 1, 0);
4046 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
4047 /* I've seen that applications always pass the 2nd and 3rd parameter as 0.
4048 * Simple test with non-zero parameters. */
4049 *vs = 0xfffe0101; /* vs_1_1 */
4050 hr = ValidateVertexShader(vs, vs, 0, 1, 0);
4051 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
4053 hr = ValidateVertexShader(vs, 0, vs, 1, 0);
4054 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
4055 /* I've seen the 4th parameter always passed as either 0 or 1, but passing
4056 * other values doesn't seem to hurt. */
4057 hr = ValidateVertexShader(vs, 0, 0, 12345, 0);
4058 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4059 /* What is the 5th parameter? The following seems to work ok. */
4060 hr = ValidateVertexShader(vs, 0, 0, 1, vs);
4061 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4064 static void test_validate_ps(void)
4066 static DWORD ps[] =
4068 0xffff0101, /* ps_1_1 */
4069 0x00000051, 0xa00f0001, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c1 = 1.0, 0.0, 0.0, 0.0 */
4070 0x00000042, 0xb00f0000, /* tex t0 */
4071 0x00000008, 0x800f0000, 0xa0e40001, 0xa0e40000, /* dp3 r0, c1, c0 */
4072 0x00000005, 0x800f0000, 0x90e40000, 0x80e40000, /* mul r0, v0, r0 */
4073 0x00000005, 0x800f0000, 0xb0e40000, 0x80e40000, /* mul r0, t0, r0 */
4074 0x0000ffff, /* end */
4076 HRESULT hr;
4078 hr = ValidatePixelShader(0, 0, 0, 0);
4079 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
4080 hr = ValidatePixelShader(0, 0, 1, 0);
4081 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
4082 hr = ValidatePixelShader(ps, 0, 0, 0);
4083 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4085 hr = ValidatePixelShader(ps, 0, 1, 0);
4086 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4087 /* Seems to do some version checking. */
4088 *ps = 0xffff0105; /* bogus version */
4089 hr = ValidatePixelShader(ps, 0, 1, 0);
4090 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
4091 /* I've seen that applications always pass the 2nd parameter as 0.
4092 * Simple test with a non-zero parameter. */
4093 *ps = 0xffff0101; /* ps_1_1 */
4094 hr = ValidatePixelShader(ps, ps, 1, 0);
4095 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
4096 /* I've seen the 3rd parameter always passed as either 0 or 1, but passing
4097 * other values doesn't seem to hurt. */
4098 hr = ValidatePixelShader(ps, 0, 12345, 0);
4099 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4100 /* What is the 4th parameter? The following seems to work ok. */
4101 hr = ValidatePixelShader(ps, 0, 1, ps);
4102 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4105 static void test_volume_get_container(void)
4107 IDirect3DVolumeTexture8 *texture = NULL;
4108 IDirect3DVolume8 *volume = NULL;
4109 IDirect3DDevice8 *device;
4110 IUnknown *container;
4111 IDirect3D8 *d3d8;
4112 ULONG refcount;
4113 D3DCAPS8 caps;
4114 HWND window;
4115 HRESULT hr;
4117 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
4118 0, 0, 640, 480, 0, 0, 0, 0);
4119 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
4120 ok(!!d3d8, "Failed to create a D3D object.\n");
4121 if (!(device = create_device(d3d8, window, NULL)))
4123 skip("Failed to create a D3D device, skipping tests.\n");
4124 IDirect3D8_Release(d3d8);
4125 DestroyWindow(window);
4126 return;
4129 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
4130 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
4131 if (!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP))
4133 skip("No volume texture support, skipping tests.\n");
4134 IDirect3DDevice8_Release(device);
4135 IDirect3D8_Release(d3d8);
4136 DestroyWindow(window);
4137 return;
4140 hr = IDirect3DDevice8_CreateVolumeTexture(device, 128, 128, 128, 1, 0,
4141 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture);
4142 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x.\n", hr);
4143 ok(!!texture, "Got unexpected texture %p.\n", texture);
4145 hr = IDirect3DVolumeTexture8_GetVolumeLevel(texture, 0, &volume);
4146 ok(SUCCEEDED(hr), "Failed to get volume level, hr %#x.\n", hr);
4147 ok(!!volume, "Got unexpected volume %p.\n", volume);
4149 /* These should work... */
4150 container = NULL;
4151 hr = IDirect3DVolume8_GetContainer(volume, &IID_IUnknown, (void **)&container);
4152 ok(SUCCEEDED(hr), "Failed to get volume container, hr %#x.\n", hr);
4153 ok(container == (IUnknown *)texture, "Got unexpected container %p, expected %p.\n", container, texture);
4154 IUnknown_Release(container);
4156 container = NULL;
4157 hr = IDirect3DVolume8_GetContainer(volume, &IID_IDirect3DResource8, (void **)&container);
4158 ok(SUCCEEDED(hr), "Failed to get volume container, hr %#x.\n", hr);
4159 ok(container == (IUnknown *)texture, "Got unexpected container %p, expected %p.\n", container, texture);
4160 IUnknown_Release(container);
4162 container = NULL;
4163 hr = IDirect3DVolume8_GetContainer(volume, &IID_IDirect3DBaseTexture8, (void **)&container);
4164 ok(SUCCEEDED(hr), "Failed to get volume container, hr %#x.\n", hr);
4165 ok(container == (IUnknown *)texture, "Got unexpected container %p, expected %p.\n", container, texture);
4166 IUnknown_Release(container);
4168 container = NULL;
4169 hr = IDirect3DVolume8_GetContainer(volume, &IID_IDirect3DVolumeTexture8, (void **)&container);
4170 ok(SUCCEEDED(hr), "Failed to get volume container, hr %#x.\n", hr);
4171 ok(container == (IUnknown *)texture, "Got unexpected container %p, expected %p.\n", container, texture);
4172 IUnknown_Release(container);
4174 /* ...and this one shouldn't. This should return E_NOINTERFACE and set container to NULL. */
4175 hr = IDirect3DVolume8_GetContainer(volume, &IID_IDirect3DVolume8, (void **)&container);
4176 ok(hr == E_NOINTERFACE, "Got unexpected hr %#x.\n", hr);
4177 ok(!container, "Got unexpected container %p.\n", container);
4179 IDirect3DVolume8_Release(volume);
4180 IDirect3DVolumeTexture8_Release(texture);
4181 refcount = IDirect3DDevice8_Release(device);
4182 ok(!refcount, "Device has %u references left.\n", refcount);
4183 IDirect3D8_Release(d3d8);
4184 DestroyWindow(window);
4187 static void test_vb_lock_flags(void)
4189 static const struct
4191 DWORD flags;
4192 const char *debug_string;
4193 HRESULT result;
4195 test_data[] =
4197 {D3DLOCK_READONLY, "D3DLOCK_READONLY", D3D_OK },
4198 {D3DLOCK_DISCARD, "D3DLOCK_DISCARD", D3D_OK },
4199 {D3DLOCK_NOOVERWRITE, "D3DLOCK_NOOVERWRITE", D3D_OK },
4200 {D3DLOCK_NOOVERWRITE | D3DLOCK_DISCARD, "D3DLOCK_NOOVERWRITE | D3DLOCK_DISCARD", D3D_OK },
4201 {D3DLOCK_NOOVERWRITE | D3DLOCK_READONLY, "D3DLOCK_NOOVERWRITE | D3DLOCK_READONLY", D3D_OK },
4202 {D3DLOCK_READONLY | D3DLOCK_DISCARD, "D3DLOCK_READONLY | D3DLOCK_DISCARD", D3D_OK },
4203 /* Completely bogus flags aren't an error. */
4204 {0xdeadbeef, "0xdeadbeef", D3D_OK },
4206 IDirect3DVertexBuffer8 *buffer;
4207 IDirect3DDevice8 *device;
4208 IDirect3D8 *d3d8;
4209 unsigned int i;
4210 ULONG refcount;
4211 HWND window;
4212 HRESULT hr;
4213 BYTE *data;
4215 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
4216 0, 0, 640, 480, 0, 0, 0, 0);
4217 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
4218 ok(!!d3d8, "Failed to create a D3D object.\n");
4219 if (!(device = create_device(d3d8, window, NULL)))
4221 skip("Failed to create a D3D device, skipping tests.\n");
4222 IDirect3D8_Release(d3d8);
4223 DestroyWindow(window);
4224 return;
4227 hr = IDirect3DDevice8_CreateVertexBuffer(device, 1024, D3DUSAGE_DYNAMIC, 0, D3DPOOL_DEFAULT, &buffer);
4228 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
4230 for (i = 0; i < (sizeof(test_data) / sizeof(*test_data)); ++i)
4232 hr = IDirect3DVertexBuffer8_Lock(buffer, 0, 0, &data, test_data[i].flags);
4233 ok(hr == test_data[i].result, "Got unexpected hr %#x for %s.\n",
4234 hr, test_data[i].debug_string);
4235 if (SUCCEEDED(hr))
4237 ok(!!data, "Got unexpected data %p.\n", data);
4238 hr = IDirect3DVertexBuffer8_Unlock(buffer);
4239 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
4243 IDirect3DVertexBuffer8_Release(buffer);
4244 refcount = IDirect3DDevice8_Release(device);
4245 ok(!refcount, "Device has %u references left.\n", refcount);
4246 IDirect3D8_Release(d3d8);
4247 DestroyWindow(window);
4250 /* Test the default texture stage state values */
4251 static void test_texture_stage_states(void)
4253 IDirect3DDevice8 *device;
4254 IDirect3D8 *d3d8;
4255 unsigned int i;
4256 ULONG refcount;
4257 D3DCAPS8 caps;
4258 DWORD value;
4259 HWND window;
4260 HRESULT hr;
4262 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
4263 0, 0, 640, 480, 0, 0, 0, 0);
4264 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
4265 ok(!!d3d8, "Failed to create a D3D object.\n");
4266 if (!(device = create_device(d3d8, window, NULL)))
4268 skip("Failed to create a D3D device, skipping tests.\n");
4269 IDirect3D8_Release(d3d8);
4270 DestroyWindow(window);
4271 return;
4274 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
4275 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
4277 for (i = 0; i < caps.MaxTextureBlendStages; ++i)
4279 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_COLOROP, &value);
4280 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4281 ok(value == (i ? D3DTOP_DISABLE : D3DTOP_MODULATE),
4282 "Got unexpected value %#x for D3DTSS_COLOROP, stage %u.\n", value, i);
4283 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_COLORARG1, &value);
4284 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4285 ok(value == D3DTA_TEXTURE, "Got unexpected value %#x for D3DTSS_COLORARG1, stage %u.\n", value, i);
4286 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_COLORARG2, &value);
4287 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4288 ok(value == D3DTA_CURRENT, "Got unexpected value %#x for D3DTSS_COLORARG2, stage %u.\n", value, i);
4289 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_ALPHAOP, &value);
4290 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4291 ok(value == (i ? D3DTOP_DISABLE : D3DTOP_SELECTARG1),
4292 "Got unexpected value %#x for D3DTSS_ALPHAOP, stage %u.\n", value, i);
4293 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_ALPHAARG1, &value);
4294 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4295 ok(value == D3DTA_TEXTURE, "Got unexpected value %#x for D3DTSS_ALPHAARG1, stage %u.\n", value, i);
4296 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_ALPHAARG2, &value);
4297 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4298 ok(value == D3DTA_CURRENT, "Got unexpected value %#x for D3DTSS_ALPHAARG2, stage %u.\n", value, i);
4299 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_BUMPENVMAT00, &value);
4300 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4301 ok(!value, "Got unexpected value %#x for D3DTSS_BUMPENVMAT00, stage %u.\n", value, i);
4302 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_BUMPENVMAT01, &value);
4303 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4304 ok(!value, "Got unexpected value %#x for D3DTSS_BUMPENVMAT01, stage %u.\n", value, i);
4305 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_BUMPENVMAT10, &value);
4306 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4307 ok(!value, "Got unexpected value %#x for D3DTSS_BUMPENVMAT10, stage %u.\n", value, i);
4308 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_BUMPENVMAT11, &value);
4309 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4310 ok(!value, "Got unexpected value %#x for D3DTSS_BUMPENVMAT11, stage %u.\n", value, i);
4311 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_TEXCOORDINDEX, &value);
4312 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4313 ok(value == i, "Got unexpected value %#x for D3DTSS_TEXCOORDINDEX, stage %u.\n", value, i);
4314 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_BUMPENVLSCALE, &value);
4315 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4316 ok(!value, "Got unexpected value %#x for D3DTSS_BUMPENVLSCALE, stage %u.\n", value, i);
4317 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_BUMPENVLOFFSET, &value);
4318 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4319 ok(!value, "Got unexpected value %#x for D3DTSS_BUMPENVLOFFSET, stage %u.\n", value, i);
4320 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_TEXTURETRANSFORMFLAGS, &value);
4321 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4322 ok(value == D3DTTFF_DISABLE,
4323 "Got unexpected value %#x for D3DTSS_TEXTURETRANSFORMFLAGS, stage %u.\n", value, i);
4324 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_COLORARG0, &value);
4325 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4326 ok(value == D3DTA_CURRENT, "Got unexpected value %#x for D3DTSS_COLORARG0, stage %u.\n", value, i);
4327 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_ALPHAARG0, &value);
4328 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4329 ok(value == D3DTA_CURRENT, "Got unexpected value %#x for D3DTSS_ALPHAARG0, stage %u.\n", value, i);
4330 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_RESULTARG, &value);
4331 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4332 ok(value == D3DTA_CURRENT, "Got unexpected value %#x for D3DTSS_RESULTARG, stage %u.\n", value, i);
4335 refcount = IDirect3DDevice8_Release(device);
4336 ok(!refcount, "Device has %u references left.\n", refcount);
4337 IDirect3D8_Release(d3d8);
4338 DestroyWindow(window);
4341 static void test_cube_textures(void)
4343 IDirect3DCubeTexture8 *texture;
4344 IDirect3DDevice8 *device;
4345 IDirect3D8 *d3d8;
4346 ULONG refcount;
4347 D3DCAPS8 caps;
4348 HWND window;
4349 HRESULT hr;
4351 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
4352 0, 0, 640, 480, 0, 0, 0, 0);
4353 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
4354 ok(!!d3d8, "Failed to create a D3D object.\n");
4355 if (!(device = create_device(d3d8, window, NULL)))
4357 skip("Failed to create a D3D device, skipping tests.\n");
4358 IDirect3D8_Release(d3d8);
4359 DestroyWindow(window);
4360 return;
4363 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
4364 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
4366 if (caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP)
4368 hr = IDirect3DDevice8_CreateCubeTexture(device, 512, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &texture);
4369 ok(hr == D3D_OK, "Failed to create D3DPOOL_DEFAULT cube texture, hr %#x.\n", hr);
4370 IDirect3DCubeTexture8_Release(texture);
4371 hr = IDirect3DDevice8_CreateCubeTexture(device, 512, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &texture);
4372 ok(hr == D3D_OK, "Failed to create D3DPOOL_MANAGED cube texture, hr %#x.\n", hr);
4373 IDirect3DCubeTexture8_Release(texture);
4374 hr = IDirect3DDevice8_CreateCubeTexture(device, 512, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_SYSTEMMEM, &texture);
4375 ok(hr == D3D_OK, "Failed to create D3DPOOL_SYSTEMMEM cube texture, hr %#x.\n", hr);
4376 IDirect3DCubeTexture8_Release(texture);
4378 else
4380 hr = IDirect3DDevice8_CreateCubeTexture(device, 512, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &texture);
4381 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for D3DPOOL_DEFAULT cube texture.\n", hr);
4382 hr = IDirect3DDevice8_CreateCubeTexture(device, 512, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &texture);
4383 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for D3DPOOL_MANAGED cube texture.\n", hr);
4384 hr = IDirect3DDevice8_CreateCubeTexture(device, 512, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_SYSTEMMEM, &texture);
4385 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for D3DPOOL_SYSTEMMEM cube texture.\n", hr);
4387 hr = IDirect3DDevice8_CreateCubeTexture(device, 512, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_SCRATCH, &texture);
4388 ok(hr == D3D_OK, "Failed to create D3DPOOL_SCRATCH cube texture, hr %#x.\n", hr);
4389 IDirect3DCubeTexture8_Release(texture);
4391 refcount = IDirect3DDevice8_Release(device);
4392 ok(!refcount, "Device has %u references left.\n", refcount);
4393 IDirect3D8_Release(d3d8);
4394 DestroyWindow(window);
4397 /* Test the behaviour of the IDirect3DDevice8::CreateImageSurface() method.
4399 * The expected behaviour (as documented in the original DX8 docs) is that the
4400 * call returns a surface in the SYSTEMMEM pool. Games like Max Payne 1 and 2
4401 * depend on this behaviour.
4403 * A short remark in the DX9 docs however states that the pool of the returned
4404 * surface object is D3DPOOL_SCRATCH. This is misinformation and would result
4405 * in screenshots not appearing in the savegame loading menu of both games
4406 * mentioned above (engine tries to display a texture from the scratch pool).
4408 * This test verifies that the behaviour described in the original d3d8 docs
4409 * is the correct one. For more information about this issue, see the MSDN:
4410 * d3d9 docs: "Converting to Direct3D 9"
4411 * d3d9 reference: "IDirect3DDevice9::CreateOffscreenPlainSurface"
4412 * d3d8 reference: "IDirect3DDevice8::CreateImageSurface" */
4413 static void test_image_surface_pool(void)
4415 IDirect3DSurface8 *surface;
4416 IDirect3DDevice8 *device;
4417 D3DSURFACE_DESC desc;
4418 IDirect3D8 *d3d8;
4419 ULONG refcount;
4420 HWND window;
4421 HRESULT hr;
4423 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
4424 0, 0, 640, 480, 0, 0, 0, 0);
4425 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
4426 ok(!!d3d8, "Failed to create a D3D object.\n");
4427 if (!(device = create_device(d3d8, window, NULL)))
4429 skip("Failed to create a D3D device, skipping tests.\n");
4430 IDirect3D8_Release(d3d8);
4431 DestroyWindow(window);
4432 return;
4435 hr = IDirect3DDevice8_CreateImageSurface(device, 128, 128, D3DFMT_A8R8G8B8, &surface);
4436 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4437 hr = IDirect3DSurface8_GetDesc(surface, &desc);
4438 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
4439 ok(desc.Pool == D3DPOOL_SYSTEMMEM, "Got unexpected pool %#x.\n", desc.Pool);
4440 IDirect3DSurface8_Release(surface);
4442 refcount = IDirect3DDevice8_Release(device);
4443 ok(!refcount, "Device has %u references left.\n", refcount);
4444 IDirect3D8_Release(d3d8);
4445 DestroyWindow(window);
4448 static void test_surface_get_container(void)
4450 IDirect3DTexture8 *texture = NULL;
4451 IDirect3DSurface8 *surface = NULL;
4452 IDirect3DDevice8 *device;
4453 IUnknown *container;
4454 IDirect3D8 *d3d8;
4455 ULONG refcount;
4456 HWND window;
4457 HRESULT hr;
4459 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
4460 0, 0, 640, 480, 0, 0, 0, 0);
4461 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
4462 ok(!!d3d8, "Failed to create a D3D object.\n");
4463 if (!(device = create_device(d3d8, window, NULL)))
4465 skip("Failed to create a D3D device, skipping tests.\n");
4466 IDirect3D8_Release(d3d8);
4467 DestroyWindow(window);
4468 return;
4471 hr = IDirect3DDevice8_CreateTexture(device, 128, 128, 1, 0,
4472 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture);
4473 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
4474 ok(!!texture, "Got unexpected texture %p.\n", texture);
4476 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 0, &surface);
4477 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
4478 ok(!!surface, "Got unexpected surface %p.\n", surface);
4480 /* These should work... */
4481 container = NULL;
4482 hr = IDirect3DSurface8_GetContainer(surface, &IID_IUnknown, (void **)&container);
4483 ok(SUCCEEDED(hr), "Failed to get surface container, hr %#x.\n", hr);
4484 ok(container == (IUnknown *)texture, "Got unexpected container %p, expected %p.\n", container, texture);
4485 IUnknown_Release(container);
4487 container = NULL;
4488 hr = IDirect3DSurface8_GetContainer(surface, &IID_IDirect3DResource8, (void **)&container);
4489 ok(SUCCEEDED(hr), "Failed to get surface container, hr %#x.\n", hr);
4490 ok(container == (IUnknown *)texture, "Got unexpected container %p, expected %p.\n", container, texture);
4491 IUnknown_Release(container);
4493 container = NULL;
4494 hr = IDirect3DSurface8_GetContainer(surface, &IID_IDirect3DBaseTexture8, (void **)&container);
4495 ok(SUCCEEDED(hr), "Failed to get surface container, hr %#x.\n", hr);
4496 ok(container == (IUnknown *)texture, "Got unexpected container %p, expected %p.\n", container, texture);
4497 IUnknown_Release(container);
4499 container = NULL;
4500 hr = IDirect3DSurface8_GetContainer(surface, &IID_IDirect3DTexture8, (void **)&container);
4501 ok(SUCCEEDED(hr), "Failed to get surface container, hr %#x.\n", hr);
4502 ok(container == (IUnknown *)texture, "Got unexpected container %p, expected %p.\n", container, texture);
4503 IUnknown_Release(container);
4505 /* ...and this one shouldn't. This should return E_NOINTERFACE and set container to NULL. */
4506 hr = IDirect3DSurface8_GetContainer(surface, &IID_IDirect3DSurface8, (void **)&container);
4507 ok(hr == E_NOINTERFACE, "Got unexpected hr %#x.\n", hr);
4508 ok(!container, "Got unexpected container %p.\n", container);
4510 IDirect3DSurface8_Release(surface);
4511 IDirect3DTexture8_Release(texture);
4512 refcount = IDirect3DDevice8_Release(device);
4513 ok(!refcount, "Device has %u references left.\n", refcount);
4514 IDirect3D8_Release(d3d8);
4515 DestroyWindow(window);
4518 static void test_lockrect_invalid(void)
4520 static const RECT valid[] =
4522 {60, 60, 68, 68},
4523 {120, 60, 128, 68},
4524 {60, 120, 68, 128},
4526 static const RECT invalid[] =
4528 {60, 60, 60, 68}, /* 0 height */
4529 {60, 60, 68, 60}, /* 0 width */
4530 {68, 60, 60, 68}, /* left > right */
4531 {60, 68, 68, 60}, /* top > bottom */
4532 {-8, 60, 0, 68}, /* left < surface */
4533 {60, -8, 68, 0}, /* top < surface */
4534 {-16, 60, -8, 68}, /* right < surface */
4535 {60, -16, 68, -8}, /* bottom < surface */
4536 {60, 60, 136, 68}, /* right > surface */
4537 {60, 60, 68, 136}, /* bottom > surface */
4538 {136, 60, 144, 68}, /* left > surface */
4539 {60, 136, 68, 144}, /* top > surface */
4541 IDirect3DSurface8 *surface = NULL;
4542 D3DLOCKED_RECT locked_rect;
4543 IDirect3DDevice8 *device;
4544 IDirect3D8 *d3d8;
4545 unsigned int i;
4546 ULONG refcount;
4547 HWND window;
4548 BYTE *base;
4549 HRESULT hr;
4551 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
4552 0, 0, 640, 480, 0, 0, 0, 0);
4553 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
4554 ok(!!d3d8, "Failed to create a D3D object.\n");
4555 if (!(device = create_device(d3d8, window, NULL)))
4557 skip("Failed to create a D3D device, skipping tests.\n");
4558 IDirect3D8_Release(d3d8);
4559 DestroyWindow(window);
4560 return;
4563 hr = IDirect3DDevice8_CreateImageSurface(device, 128, 128, D3DFMT_A8R8G8B8, &surface);
4564 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4565 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, NULL, 0);
4566 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
4567 base = locked_rect.pBits;
4568 hr = IDirect3DSurface8_UnlockRect(surface);
4569 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
4571 for (i = 0; i < (sizeof(valid) / sizeof(*valid)); ++i)
4573 unsigned int offset, expected_offset;
4574 const RECT *rect = &valid[i];
4576 locked_rect.pBits = (BYTE *)0xdeadbeef;
4577 locked_rect.Pitch = 0xdeadbeef;
4579 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, rect, 0);
4580 ok(SUCCEEDED(hr), "Failed to lock surface with rect [%d, %d]->[%d, %d], hr %#x.\n",
4581 rect->left, rect->top, rect->right, rect->bottom, hr);
4583 offset = (BYTE *)locked_rect.pBits - base;
4584 expected_offset = rect->top * locked_rect.Pitch + rect->left * 4;
4585 ok(offset == expected_offset,
4586 "Got unexpected offset %u (expected %u) for rect [%d, %d]->[%d, %d].\n",
4587 offset, expected_offset, rect->left, rect->top, rect->right, rect->bottom);
4589 hr = IDirect3DSurface8_UnlockRect(surface);
4590 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
4593 for (i = 0; i < (sizeof(invalid) / sizeof(*invalid)); ++i)
4595 const RECT *rect = &invalid[i];
4597 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, rect, 0);
4598 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for rect [%d, %d]->[%d, %d].\n",
4599 hr, rect->left, rect->top, rect->right, rect->bottom);
4602 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, NULL, 0);
4603 ok(SUCCEEDED(hr), "Failed to lock surface with rect NULL, hr %#x.\n", hr);
4604 locked_rect.pBits = (void *)0xdeadbeef;
4605 locked_rect.Pitch = 1;
4606 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, NULL, 0);
4607 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
4608 ok(!locked_rect.pBits, "Got unexpected pBits %p.\n", locked_rect.pBits);
4609 ok(!locked_rect.Pitch, "Got unexpected Pitch %u.\n", locked_rect.Pitch);
4610 hr = IDirect3DSurface8_UnlockRect(surface);
4611 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
4613 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, &valid[0], 0);
4614 ok(hr == D3D_OK, "Got unexpected hr %#x for rect [%d, %d]->[%d, %d].\n",
4615 hr, valid[0].left, valid[0].top, valid[0].right, valid[0].bottom);
4616 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, &valid[0], 0);
4617 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for rect [%d, %d]->[%d, %d].\n",
4618 hr, valid[0].left, valid[0].top, valid[0].right, valid[0].bottom);
4619 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, &valid[1], 0);
4620 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for rect [%d, %d]->[%d, %d].\n",
4621 hr, valid[1].left, valid[1].top, valid[1].right, valid[1].bottom);
4622 hr = IDirect3DSurface8_UnlockRect(surface);
4623 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
4625 IDirect3DSurface8_Release(surface);
4626 refcount = IDirect3DDevice8_Release(device);
4627 ok(!refcount, "Device has %u references left.\n", refcount);
4628 IDirect3D8_Release(d3d8);
4629 DestroyWindow(window);
4632 static void test_private_data(void)
4634 ULONG refcount, expected_refcount;
4635 IDirect3DTexture8 *texture;
4636 IDirect3DSurface8 *surface, *surface2;
4637 IDirect3DDevice8 *device;
4638 IDirect3D8 *d3d8;
4639 IUnknown *ptr;
4640 HWND window;
4641 HRESULT hr;
4642 DWORD size;
4643 DWORD data[4] = {1, 2, 3, 4};
4644 static const GUID d3d8_private_data_test_guid2 =
4646 0x2e5afac2,
4647 0x87b5,
4648 0x4c10,
4649 {0x9b,0x4b,0x89,0xd7,0xd1,0x12,0xe7,0x2b}
4652 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
4653 0, 0, 640, 480, 0, 0, 0, 0);
4654 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
4655 ok(!!d3d8, "Failed to create a D3D object.\n");
4656 if (!(device = create_device(d3d8, window, NULL)))
4658 skip("Failed to create a D3D device, skipping tests.\n");
4659 IDirect3D8_Release(d3d8);
4660 DestroyWindow(window);
4661 return;
4664 hr = IDirect3DDevice8_CreateImageSurface(device, 4, 4, D3DFMT_A8R8G8B8, &surface);
4665 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4667 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
4668 device, 0, D3DSPD_IUNKNOWN);
4669 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
4670 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
4671 device, 5, D3DSPD_IUNKNOWN);
4672 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
4673 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
4674 device, sizeof(IUnknown *) * 2, D3DSPD_IUNKNOWN);
4675 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
4677 /* A failing SetPrivateData call does not clear the old data with the same tag. */
4678 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid, device,
4679 sizeof(device), D3DSPD_IUNKNOWN);
4680 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
4681 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid, device,
4682 sizeof(device) * 2, D3DSPD_IUNKNOWN);
4683 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
4684 size = sizeof(ptr);
4685 hr = IDirect3DSurface8_GetPrivateData(surface, &d3d8_private_data_test_guid, &ptr, &size);
4686 ok(SUCCEEDED(hr), "Failed to get private data, hr %#x.\n", hr);
4687 IUnknown_Release(ptr);
4688 hr = IDirect3DSurface8_FreePrivateData(surface, &d3d8_private_data_test_guid);
4689 ok(SUCCEEDED(hr), "Failed to free private data, hr %#x.\n", hr);
4691 refcount = get_refcount((IUnknown *)device);
4692 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
4693 device, sizeof(IUnknown *), D3DSPD_IUNKNOWN);
4694 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
4695 expected_refcount = refcount + 1;
4696 refcount = get_refcount((IUnknown *)device);
4697 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4698 hr = IDirect3DSurface8_FreePrivateData(surface, &d3d8_private_data_test_guid);
4699 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
4700 expected_refcount = refcount - 1;
4701 refcount = get_refcount((IUnknown *)device);
4702 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4704 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
4705 device, sizeof(IUnknown *), D3DSPD_IUNKNOWN);
4706 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
4707 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
4708 surface, sizeof(IUnknown *), D3DSPD_IUNKNOWN);
4709 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
4710 refcount = get_refcount((IUnknown *)device);
4711 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4713 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
4714 device, sizeof(IUnknown *), D3DSPD_IUNKNOWN);
4715 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
4716 size = 2 * sizeof(ptr);
4717 hr = IDirect3DSurface8_GetPrivateData(surface, &d3d8_private_data_test_guid, &ptr, &size);
4718 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
4719 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
4720 expected_refcount = refcount + 2;
4721 refcount = get_refcount((IUnknown *)device);
4722 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4723 ok(ptr == (IUnknown *)device, "Got unexpected ptr %p, expected %p.\n", ptr, device);
4724 IUnknown_Release(ptr);
4725 expected_refcount--;
4727 ptr = (IUnknown *)0xdeadbeef;
4728 size = 1;
4729 hr = IDirect3DSurface8_GetPrivateData(surface, &d3d8_private_data_test_guid, NULL, &size);
4730 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
4731 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
4732 size = 2 * sizeof(ptr);
4733 hr = IDirect3DSurface8_GetPrivateData(surface, &d3d8_private_data_test_guid, NULL, &size);
4734 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
4735 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
4736 refcount = get_refcount((IUnknown *)device);
4737 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4738 size = 1;
4739 hr = IDirect3DSurface8_GetPrivateData(surface, &d3d8_private_data_test_guid, &ptr, &size);
4740 ok(hr == D3DERR_MOREDATA, "Got unexpected hr %#x.\n", hr);
4741 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
4742 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
4743 hr = IDirect3DSurface8_GetPrivateData(surface, &d3d8_private_data_test_guid2, NULL, NULL);
4744 ok(hr == D3DERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
4745 size = 0xdeadbabe;
4746 hr = IDirect3DSurface8_GetPrivateData(surface, &d3d8_private_data_test_guid2, &ptr, &size);
4747 ok(hr == D3DERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
4748 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
4749 ok(size == 0xdeadbabe, "Got unexpected size %u.\n", size);
4750 /* GetPrivateData with size = NULL causes an access violation on Windows if the
4751 * requested data exists. */
4753 /* Destroying the surface frees the held reference. */
4754 IDirect3DSurface8_Release(surface);
4755 expected_refcount = refcount - 2;
4756 refcount = get_refcount((IUnknown *)device);
4757 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4759 hr = IDirect3DDevice8_CreateTexture(device, 4, 4, 2, 0, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &texture);
4760 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
4761 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 0, &surface);
4762 ok(SUCCEEDED(hr), "Failed to get texture level 0, hr %#x.\n", hr);
4763 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 1, &surface2);
4764 ok(SUCCEEDED(hr), "Failed to get texture level 1, hr %#x.\n", hr);
4766 hr = IDirect3DTexture8_SetPrivateData(texture, &d3d8_private_data_test_guid, data, sizeof(data), 0);
4767 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
4769 memset(data, 0, sizeof(data));
4770 size = sizeof(data);
4771 hr = IDirect3DSurface8_GetPrivateData(surface, &d3d8_private_data_test_guid, data, &size);
4772 ok(hr == D3DERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
4773 hr = IDirect3DTexture8_GetPrivateData(texture, &d3d8_private_data_test_guid, data, &size);
4774 ok(SUCCEEDED(hr), "Failed to get private data, hr %#x.\n", hr);
4775 ok(data[0] == 1 && data[1] == 2 && data[2] == 3 && data[3] == 4,
4776 "Got unexpected private data: %u, %u, %u, %u.\n", data[0], data[1], data[2], data[3]);
4778 hr = IDirect3DTexture8_FreePrivateData(texture, &d3d8_private_data_test_guid);
4779 ok(SUCCEEDED(hr), "Failed to free private data, hr %#x.\n", hr);
4781 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid, data, sizeof(data), 0);
4782 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
4783 hr = IDirect3DSurface8_GetPrivateData(surface2, &d3d8_private_data_test_guid, data, &size);
4784 ok(hr == D3DERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
4785 hr = IDirect3DSurface8_FreePrivateData(surface, &d3d8_private_data_test_guid);
4786 ok(SUCCEEDED(hr), "Failed to free private data, hr %#x.\n", hr);
4788 IDirect3DSurface8_Release(surface2);
4789 IDirect3DSurface8_Release(surface);
4790 IDirect3DTexture8_Release(texture);
4792 refcount = IDirect3DDevice8_Release(device);
4793 ok(!refcount, "Device has %u references left.\n", refcount);
4794 IDirect3D8_Release(d3d8);
4795 DestroyWindow(window);
4798 static void test_surface_dimensions(void)
4800 IDirect3DSurface8 *surface;
4801 IDirect3DDevice8 *device;
4802 IDirect3D8 *d3d8;
4803 ULONG refcount;
4804 HWND window;
4805 HRESULT hr;
4807 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
4808 0, 0, 640, 480, 0, 0, 0, 0);
4809 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
4810 ok(!!d3d8, "Failed to create a D3D object.\n");
4811 if (!(device = create_device(d3d8, window, NULL)))
4813 skip("Failed to create a D3D device, skipping tests.\n");
4814 IDirect3D8_Release(d3d8);
4815 DestroyWindow(window);
4816 return;
4819 hr = IDirect3DDevice8_CreateImageSurface(device, 0, 1, D3DFMT_A8R8G8B8, &surface);
4820 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
4821 hr = IDirect3DDevice8_CreateImageSurface(device, 1, 0, D3DFMT_A8R8G8B8, &surface);
4822 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
4824 refcount = IDirect3DDevice8_Release(device);
4825 ok(!refcount, "Device has %u references left.\n", refcount);
4826 IDirect3D8_Release(d3d8);
4827 DestroyWindow(window);
4830 static void test_surface_format_null(void)
4832 static const D3DFORMAT D3DFMT_NULL = MAKEFOURCC('N','U','L','L');
4833 IDirect3DTexture8 *texture;
4834 IDirect3DSurface8 *surface;
4835 IDirect3DSurface8 *rt, *ds;
4836 D3DLOCKED_RECT locked_rect;
4837 IDirect3DDevice8 *device;
4838 D3DSURFACE_DESC desc;
4839 IDirect3D8 *d3d;
4840 ULONG refcount;
4841 HWND window;
4842 HRESULT hr;
4844 d3d = Direct3DCreate8(D3D_SDK_VERSION);
4845 ok(!!d3d, "Failed to create a D3D object.\n");
4847 hr = IDirect3D8_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
4848 D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, D3DFMT_NULL);
4849 if (hr != D3D_OK)
4851 skip("No D3DFMT_NULL support, skipping test.\n");
4852 IDirect3D8_Release(d3d);
4853 return;
4856 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
4857 0, 0, 640, 480, 0, 0, 0, 0);
4858 if (!(device = create_device(d3d, window, NULL)))
4860 skip("Failed to create a D3D device, skipping tests.\n");
4861 IDirect3D8_Release(d3d);
4862 DestroyWindow(window);
4863 return;
4866 hr = IDirect3D8_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
4867 D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, D3DFMT_NULL);
4868 ok(hr == D3D_OK, "D3DFMT_NULL should be supported for render target textures, hr %#x.\n", hr);
4870 hr = IDirect3D8_CheckDepthStencilMatch(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
4871 D3DFMT_NULL, D3DFMT_D24S8);
4872 ok(SUCCEEDED(hr), "Depth stencil match failed for D3DFMT_NULL, hr %#x.\n", hr);
4874 hr = IDirect3DDevice8_CreateRenderTarget(device, 128, 128, D3DFMT_NULL,
4875 D3DMULTISAMPLE_NONE, TRUE, &surface);
4876 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
4878 hr = IDirect3DDevice8_GetRenderTarget(device, &rt);
4879 ok(SUCCEEDED(hr), "Failed to get original render target, hr %#x.\n", hr);
4881 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &ds);
4882 ok(SUCCEEDED(hr), "Failed to get original depth/stencil, hr %#x.\n", hr);
4884 hr = IDirect3DDevice8_SetRenderTarget(device, surface, NULL);
4885 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
4887 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00000000, 0.0f, 0);
4888 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
4890 hr = IDirect3DDevice8_SetRenderTarget(device, rt, ds);
4891 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
4893 IDirect3DSurface8_Release(rt);
4894 IDirect3DSurface8_Release(ds);
4896 hr = IDirect3DSurface8_GetDesc(surface, &desc);
4897 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
4898 ok(desc.Width == 128, "Expected width 128, got %u.\n", desc.Width);
4899 ok(desc.Height == 128, "Expected height 128, got %u.\n", desc.Height);
4901 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, NULL, 0);
4902 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
4903 ok(locked_rect.Pitch, "Expected non-zero pitch, got %u.\n", locked_rect.Pitch);
4904 ok(!!locked_rect.pBits, "Expected non-NULL pBits, got %p.\n", locked_rect.pBits);
4906 hr = IDirect3DSurface8_UnlockRect(surface);
4907 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
4909 IDirect3DSurface8_Release(surface);
4911 hr = IDirect3DDevice8_CreateTexture(device, 128, 128, 0, D3DUSAGE_RENDERTARGET,
4912 D3DFMT_NULL, D3DPOOL_DEFAULT, &texture);
4913 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
4914 IDirect3DTexture8_Release(texture);
4916 refcount = IDirect3DDevice8_Release(device);
4917 ok(!refcount, "Device has %u references left.\n", refcount);
4918 IDirect3D8_Release(d3d);
4919 DestroyWindow(window);
4922 static void test_surface_double_unlock(void)
4924 static const D3DPOOL pools[] =
4926 D3DPOOL_DEFAULT,
4927 D3DPOOL_SYSTEMMEM,
4929 IDirect3DSurface8 *surface;
4930 IDirect3DDevice8 *device;
4931 D3DLOCKED_RECT lr;
4932 IDirect3D8 *d3d;
4933 unsigned int i;
4934 ULONG refcount;
4935 HWND window;
4936 HRESULT hr;
4938 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
4939 0, 0, 640, 480, 0, 0, 0, 0);
4940 d3d = Direct3DCreate8(D3D_SDK_VERSION);
4941 ok(!!d3d, "Failed to create a D3D object.\n");
4942 if (!(device = create_device(d3d, window, NULL)))
4944 skip("Failed to create a D3D device, skipping tests.\n");
4945 IDirect3D8_Release(d3d);
4946 DestroyWindow(window);
4947 return;
4950 for (i = 0; i < (sizeof(pools) / sizeof(*pools)); ++i)
4952 switch (pools[i])
4954 case D3DPOOL_DEFAULT:
4955 hr = IDirect3D8_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
4956 D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, D3DFMT_X8R8G8B8);
4957 if (FAILED(hr))
4959 skip("D3DFMT_X8R8G8B8 render targets not supported, skipping double unlock DEFAULT pool test.\n");
4960 continue;
4963 hr = IDirect3DDevice8_CreateRenderTarget(device, 64, 64, D3DFMT_X8R8G8B8,
4964 D3DMULTISAMPLE_NONE, TRUE, &surface);
4965 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
4966 break;
4968 case D3DPOOL_SYSTEMMEM:
4969 hr = IDirect3DDevice8_CreateImageSurface(device, 64, 64, D3DFMT_X8R8G8B8, &surface);
4970 ok(SUCCEEDED(hr), "Failed to create image surface, hr %#x.\n", hr);
4971 break;
4973 default:
4974 break;
4977 hr = IDirect3DSurface8_UnlockRect(surface);
4978 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x, for surface in pool %#x.\n", hr, pools[i]);
4979 hr = IDirect3DSurface8_LockRect(surface, &lr, NULL, 0);
4980 ok(SUCCEEDED(hr), "Failed to lock surface in pool %#x, hr %#x.\n", pools[i], hr);
4981 hr = IDirect3DSurface8_UnlockRect(surface);
4982 ok(SUCCEEDED(hr), "Failed to unlock surface in pool %#x, hr %#x.\n", pools[i], hr);
4983 hr = IDirect3DSurface8_UnlockRect(surface);
4984 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x, for surface in pool %#x.\n", hr, pools[i]);
4986 IDirect3DSurface8_Release(surface);
4989 refcount = IDirect3DDevice8_Release(device);
4990 ok(!refcount, "Device has %u references left.\n", refcount);
4991 IDirect3D8_Release(d3d);
4992 DestroyWindow(window);
4995 static void test_surface_blocks(void)
4997 static const struct
4999 D3DFORMAT fmt;
5000 const char *name;
5001 unsigned int block_width;
5002 unsigned int block_height;
5003 BOOL broken;
5004 BOOL create_size_checked, core_fmt;
5006 formats[] =
5008 {D3DFMT_DXT1, "D3DFMT_DXT1", 4, 4, FALSE, TRUE, TRUE },
5009 {D3DFMT_DXT2, "D3DFMT_DXT2", 4, 4, FALSE, TRUE, TRUE },
5010 {D3DFMT_DXT3, "D3DFMT_DXT3", 4, 4, FALSE, TRUE, TRUE },
5011 {D3DFMT_DXT4, "D3DFMT_DXT4", 4, 4, FALSE, TRUE, TRUE },
5012 {D3DFMT_DXT5, "D3DFMT_DXT5", 4, 4, FALSE, TRUE, TRUE },
5013 /* ATI1N and ATI2N have 2x2 blocks on all AMD cards and Geforce 7 cards,
5014 * which doesn't match the format spec. On newer Nvidia cards
5015 * they have the correct 4x4 block size */
5016 {MAKEFOURCC('A','T','I','1'), "ATI1N", 4, 4, TRUE, FALSE, FALSE},
5017 {MAKEFOURCC('A','T','I','2'), "ATI2N", 4, 4, TRUE, FALSE, FALSE},
5018 /* Windows drivers generally enforce block-aligned locks for
5019 * YUY2 and UYVY. The notable exception is the AMD r500 driver
5020 * in d3d8. The same driver checks the sizes in d3d9. */
5021 {D3DFMT_YUY2, "D3DFMT_YUY2", 2, 1, TRUE, FALSE, TRUE },
5022 {D3DFMT_UYVY, "D3DFMT_UYVY", 2, 1, TRUE, FALSE, TRUE },
5024 static const struct
5026 D3DPOOL pool;
5027 const char *name;
5028 /* Don't check the return value, Nvidia returns D3DERR_INVALIDCALL for some formats
5029 * and E_INVALIDARG/DDERR_INVALIDPARAMS for others. */
5030 BOOL success;
5032 pools[] =
5034 {D3DPOOL_DEFAULT, "D3DPOOL_DEFAULT", FALSE},
5035 {D3DPOOL_SCRATCH, "D3DPOOL_SCRATCH", TRUE},
5036 {D3DPOOL_SYSTEMMEM, "D3DPOOL_SYSTEMMEM",TRUE},
5037 {D3DPOOL_MANAGED, "D3DPOOL_MANAGED", TRUE},
5039 static struct
5041 D3DRESOURCETYPE rtype;
5042 const char *type_name;
5043 D3DPOOL pool;
5044 const char *pool_name;
5045 BOOL need_driver_support, need_runtime_support;
5047 create_tests[] =
5049 /* D3d8 only supports sysmem surfaces, which are created via CreateImageSurface. Other tests confirm
5050 * that they are D3DPOOL_SYSTEMMEM surfaces, but their creation restriction behaves like the scratch
5051 * pool in d3d9. */
5052 {D3DRTYPE_SURFACE, "D3DRTYPE_SURFACE", D3DPOOL_SYSTEMMEM, "D3DPOOL_SYSTEMMEM", FALSE, TRUE },
5054 {D3DRTYPE_TEXTURE, "D3DRTYPE_TEXTURE", D3DPOOL_DEFAULT, "D3DPOOL_DEFAULT", TRUE, FALSE },
5055 {D3DRTYPE_TEXTURE, "D3DRTYPE_TEXTURE", D3DPOOL_SYSTEMMEM, "D3DPOOL_SYSTEMMEM", TRUE, FALSE },
5056 {D3DRTYPE_TEXTURE, "D3DRTYPE_TEXTURE", D3DPOOL_MANAGED, "D3DPOOL_MANAGED", TRUE, FALSE },
5057 {D3DRTYPE_TEXTURE, "D3DRTYPE_TEXTURE", D3DPOOL_SCRATCH, "D3DPOOL_SCRATCH", FALSE, TRUE },
5059 {D3DRTYPE_CUBETEXTURE, "D3DRTYPE_CUBETEXTURE", D3DPOOL_DEFAULT, "D3DPOOL_DEFAULT", TRUE, FALSE },
5060 {D3DRTYPE_CUBETEXTURE, "D3DRTYPE_CUBETEXTURE", D3DPOOL_SYSTEMMEM, "D3DPOOL_SYSTEMMEM", TRUE, FALSE },
5061 {D3DRTYPE_CUBETEXTURE, "D3DRTYPE_CUBETEXTURE", D3DPOOL_MANAGED, "D3DPOOL_MANAGED", TRUE, FALSE },
5062 {D3DRTYPE_CUBETEXTURE, "D3DRTYPE_CUBETEXTURE", D3DPOOL_SCRATCH, "D3DPOOL_SCRATCH", FALSE, TRUE },
5064 IDirect3DTexture8 *texture;
5065 IDirect3DCubeTexture8 *cube_texture;
5066 IDirect3DSurface8 *surface;
5067 D3DLOCKED_RECT locked_rect;
5068 IDirect3DDevice8 *device;
5069 unsigned int i, j, w, h;
5070 IDirect3D8 *d3d;
5071 ULONG refcount;
5072 HWND window;
5073 HRESULT hr;
5074 RECT rect;
5075 BOOL tex_pow2, cube_pow2;
5076 D3DCAPS8 caps;
5078 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
5079 0, 0, 640, 480, 0, 0, 0, 0);
5080 d3d = Direct3DCreate8(D3D_SDK_VERSION);
5081 ok(!!d3d, "Failed to create a D3D object.\n");
5082 if (!(device = create_device(d3d, window, NULL)))
5084 skip("Failed to create a D3D device, skipping tests.\n");
5085 IDirect3D8_Release(d3d);
5086 DestroyWindow(window);
5087 return;
5090 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
5091 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
5092 tex_pow2 = caps.TextureCaps & D3DPTEXTURECAPS_POW2;
5093 if (tex_pow2)
5094 tex_pow2 = !(caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL);
5095 cube_pow2 = !!(caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP_POW2);
5097 for (i = 0; i < (sizeof(formats) / sizeof(*formats)); ++i)
5099 BOOL tex_support, cube_support, surface_support, format_known;
5101 hr = IDirect3D8_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
5102 0, D3DRTYPE_TEXTURE, formats[i].fmt);
5103 tex_support = SUCCEEDED(hr);
5104 hr = IDirect3D8_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
5105 0, D3DRTYPE_CUBETEXTURE, formats[i].fmt);
5106 cube_support = SUCCEEDED(hr);
5107 hr = IDirect3D8_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
5108 0, D3DRTYPE_SURFACE, formats[i].fmt);
5109 surface_support = SUCCEEDED(hr);
5111 /* Scratch pool in general allows texture creation even if the driver does
5112 * not support the format. If the format is an extension format that is not
5113 * known to the runtime, like ATI2N, some driver support is required for
5114 * this to work.
5116 * It is also possible that Windows Vista and Windows 7 d3d8 runtimes know
5117 * about ATI2N. I cannot check this because all my Vista+ machines support
5118 * ATI2N in hardware, but none of my WinXP machines do. */
5119 format_known = tex_support || cube_support || surface_support;
5121 for (w = 1; w <= 8; w++)
5123 for (h = 1; h <= 8; h++)
5125 BOOL block_aligned = TRUE;
5126 BOOL size_is_pow2;
5128 if (w & (formats[i].block_width - 1) || h & (formats[i].block_height - 1))
5129 block_aligned = FALSE;
5131 size_is_pow2 = !(w & (w - 1) || h & (h - 1));
5133 for (j = 0; j < sizeof(create_tests) / sizeof(*create_tests); j++)
5135 BOOL support, pow2;
5136 HRESULT expect_hr;
5137 BOOL may_succeed = FALSE;
5138 IUnknown **check_null;
5140 if (!formats[i].core_fmt)
5142 /* AMD warns against creating ATI2N textures smaller than
5143 * the block size because the runtime cannot calculate the
5144 * correct texture size. Generalize this for all extension
5145 * formats. */
5146 if (w < formats[i].block_width || h < formats[i].block_height)
5147 continue;
5150 texture = (IDirect3DTexture8 *)0xdeadbeef;
5151 cube_texture = (IDirect3DCubeTexture8 *)0xdeadbeef;
5152 surface = (IDirect3DSurface8 *)0xdeadbeef;
5154 switch (create_tests[j].rtype)
5156 case D3DRTYPE_TEXTURE:
5157 check_null = (IUnknown **)&texture;
5158 hr = IDirect3DDevice8_CreateTexture(device, w, h, 1, 0,
5159 formats[i].fmt, create_tests[j].pool, &texture);
5160 support = tex_support;
5161 pow2 = tex_pow2;
5162 break;
5164 case D3DRTYPE_CUBETEXTURE:
5165 if (w != h)
5166 continue;
5167 check_null = (IUnknown **)&cube_texture;
5168 hr = IDirect3DDevice8_CreateCubeTexture(device, w, 1, 0,
5169 formats[i].fmt, create_tests[j].pool, &cube_texture);
5170 support = cube_support;
5171 pow2 = cube_pow2;
5172 break;
5174 case D3DRTYPE_SURFACE:
5175 check_null = (IUnknown **)&surface;
5176 hr = IDirect3DDevice8_CreateImageSurface(device, w, h,
5177 formats[i].fmt, &surface);
5178 support = surface_support;
5179 pow2 = FALSE;
5180 break;
5182 default:
5183 pow2 = FALSE;
5184 support = FALSE;
5185 check_null = NULL;
5186 break;
5189 if (create_tests[j].need_driver_support && !support)
5190 expect_hr = D3DERR_INVALIDCALL;
5191 else if (create_tests[j].need_runtime_support && !formats[i].core_fmt && !format_known)
5192 expect_hr = D3DERR_INVALIDCALL;
5193 else if (formats[i].create_size_checked && !block_aligned)
5194 expect_hr = D3DERR_INVALIDCALL;
5195 else if (pow2 && !size_is_pow2 && create_tests[j].need_driver_support)
5196 expect_hr = D3DERR_INVALIDCALL;
5197 else
5198 expect_hr = D3D_OK;
5200 if (!formats[i].core_fmt && !format_known && FAILED(expect_hr))
5201 may_succeed = TRUE;
5203 /* Wine knows about ATI2N and happily creates a scratch resource even if GL
5204 * does not support it. Accept scratch creation of extension formats on
5205 * Windows as well if it occurs. We don't really care if e.g. a Windows 7
5206 * on an r200 GPU creates scratch ATI2N texture even though the card doesn't
5207 * support it. */
5208 ok(hr == expect_hr || ((SUCCEEDED(hr) && may_succeed)),
5209 "Got unexpected hr %#x for format %s, pool %s, type %s, size %ux%u.\n",
5210 hr, formats[i].name, create_tests[j].pool_name, create_tests[j].type_name, w, h);
5212 if (FAILED(hr))
5213 ok(*check_null == NULL, "Got object ptr %p, expected NULL.\n", *check_null);
5214 else
5215 IUnknown_Release(*check_null);
5220 hr = IDirect3D8_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
5221 D3DUSAGE_DYNAMIC, D3DRTYPE_TEXTURE, formats[i].fmt);
5222 if (FAILED(hr))
5224 skip("Format %s not supported, skipping lockrect offset tests.\n", formats[i].name);
5225 continue;
5228 for (j = 0; j < (sizeof(pools) / sizeof(*pools)); ++j)
5230 hr = IDirect3DDevice8_CreateTexture(device, 128, 128, 1,
5231 pools[j].pool == D3DPOOL_DEFAULT ? D3DUSAGE_DYNAMIC : 0,
5232 formats[i].fmt, pools[j].pool, &texture);
5233 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5234 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 0, &surface);
5235 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
5236 IDirect3DTexture8_Release(texture);
5238 if (formats[i].block_width > 1)
5240 SetRect(&rect, formats[i].block_width >> 1, 0, formats[i].block_width, formats[i].block_height);
5241 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, &rect, 0);
5242 ok(FAILED(hr) == !pools[j].success || broken(formats[i].broken),
5243 "Partial block lock %s, expected %s, format %s, pool %s.\n",
5244 SUCCEEDED(hr) ? "succeeded" : "failed",
5245 pools[j].success ? "success" : "failure", formats[i].name, pools[j].name);
5246 if (SUCCEEDED(hr))
5248 hr = IDirect3DSurface8_UnlockRect(surface);
5249 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5252 SetRect(&rect, 0, 0, formats[i].block_width >> 1, formats[i].block_height);
5253 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, &rect, 0);
5254 ok(FAILED(hr) == !pools[j].success || broken(formats[i].broken),
5255 "Partial block lock %s, expected %s, format %s, pool %s.\n",
5256 SUCCEEDED(hr) ? "succeeded" : "failed",
5257 pools[j].success ? "success" : "failure", formats[i].name, pools[j].name);
5258 if (SUCCEEDED(hr))
5260 hr = IDirect3DSurface8_UnlockRect(surface);
5261 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5265 if (formats[i].block_height > 1)
5267 SetRect(&rect, 0, formats[i].block_height >> 1, formats[i].block_width, formats[i].block_height);
5268 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, &rect, 0);
5269 ok(FAILED(hr) == !pools[j].success || broken(formats[i].broken),
5270 "Partial block lock %s, expected %s, format %s, pool %s.\n",
5271 SUCCEEDED(hr) ? "succeeded" : "failed",
5272 pools[j].success ? "success" : "failure", formats[i].name, pools[j].name);
5273 if (SUCCEEDED(hr))
5275 hr = IDirect3DSurface8_UnlockRect(surface);
5276 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5279 SetRect(&rect, 0, 0, formats[i].block_width, formats[i].block_height >> 1);
5280 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, &rect, 0);
5281 ok(FAILED(hr) == !pools[j].success || broken(formats[i].broken),
5282 "Partial block lock %s, expected %s, format %s, pool %s.\n",
5283 SUCCEEDED(hr) ? "succeeded" : "failed",
5284 pools[j].success ? "success" : "failure", formats[i].name, pools[j].name);
5285 if (SUCCEEDED(hr))
5287 hr = IDirect3DSurface8_UnlockRect(surface);
5288 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5292 SetRect(&rect, 0, 0, formats[i].block_width, formats[i].block_height);
5293 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, &rect, 0);
5294 ok(hr == D3D_OK, "Got unexpected hr %#x for format %s, pool %s.\n", hr, formats[i].name, pools[j].name);
5295 hr = IDirect3DSurface8_UnlockRect(surface);
5296 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5298 IDirect3DSurface8_Release(surface);
5301 if (formats[i].block_width == 1 && formats[i].block_height == 1)
5302 continue;
5303 if (!formats[i].core_fmt)
5304 continue;
5306 hr = IDirect3DDevice8_CreateTexture(device, formats[i].block_width, formats[i].block_height, 2,
5307 D3DUSAGE_DYNAMIC, formats[i].fmt, D3DPOOL_DEFAULT, &texture);
5308 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x, format %s.\n", hr, formats[i].name);
5310 hr = IDirect3DTexture8_LockRect(texture, 1, &locked_rect, NULL, 0);
5311 ok(SUCCEEDED(hr), "Failed lock texture, hr %#x.\n", hr);
5312 hr = IDirect3DTexture8_UnlockRect(texture, 1);
5313 ok(SUCCEEDED(hr), "Failed lock texture, hr %#x.\n", hr);
5315 rect.left = 0;
5316 rect.top = 0;
5317 rect.right = formats[i].block_width == 1 ? 1 : formats[i].block_width >> 1;
5318 rect.bottom = formats[i].block_height == 1 ? 1 : formats[i].block_height >> 1;
5319 hr = IDirect3DTexture8_LockRect(texture, 1, &locked_rect, &rect, 0);
5320 ok(SUCCEEDED(hr), "Failed lock texture, hr %#x.\n", hr);
5321 hr = IDirect3DTexture8_UnlockRect(texture, 1);
5322 ok(SUCCEEDED(hr), "Failed lock texture, hr %#x.\n", hr);
5324 rect.right = formats[i].block_width;
5325 rect.bottom = formats[i].block_height;
5326 hr = IDirect3DTexture8_LockRect(texture, 1, &locked_rect, &rect, 0);
5327 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
5328 if (SUCCEEDED(hr))
5329 IDirect3DTexture8_UnlockRect(texture, 1);
5331 IDirect3DTexture8_Release(texture);
5334 refcount = IDirect3DDevice8_Release(device);
5335 ok(!refcount, "Device has %u references left.\n", refcount);
5336 IDirect3D8_Release(d3d);
5337 DestroyWindow(window);
5340 static void test_set_palette(void)
5342 IDirect3DDevice8 *device;
5343 IDirect3D8 *d3d8;
5344 UINT refcount;
5345 HWND window;
5346 HRESULT hr;
5347 PALETTEENTRY pal[256];
5348 unsigned int i;
5349 D3DCAPS8 caps;
5351 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
5352 0, 0, 640, 480, 0, 0, 0, 0);
5353 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
5354 ok(!!d3d8, "Failed to create a D3D object.\n");
5355 if (!(device = create_device(d3d8, window, NULL)))
5357 skip("Failed to create a D3D device, skipping tests.\n");
5358 IDirect3D8_Release(d3d8);
5359 DestroyWindow(window);
5360 return;
5363 for (i = 0; i < sizeof(pal) / sizeof(*pal); i++)
5365 pal[i].peRed = i;
5366 pal[i].peGreen = i;
5367 pal[i].peBlue = i;
5368 pal[i].peFlags = 0xff;
5370 hr = IDirect3DDevice8_SetPaletteEntries(device, 0, pal);
5371 ok(SUCCEEDED(hr), "Failed to set palette entries, hr %#x.\n", hr);
5373 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
5374 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
5375 for (i = 0; i < sizeof(pal) / sizeof(*pal); i++)
5377 pal[i].peRed = i;
5378 pal[i].peGreen = i;
5379 pal[i].peBlue = i;
5380 pal[i].peFlags = i;
5382 if (caps.TextureCaps & D3DPTEXTURECAPS_ALPHAPALETTE)
5384 hr = IDirect3DDevice8_SetPaletteEntries(device, 0, pal);
5385 ok(SUCCEEDED(hr), "Failed to set palette entries, hr %#x.\n", hr);
5387 else
5389 hr = IDirect3DDevice8_SetPaletteEntries(device, 0, pal);
5390 ok(hr == D3DERR_INVALIDCALL, "SetPaletteEntries returned %#x, expected D3DERR_INVALIDCALL.\n", hr);
5393 refcount = IDirect3DDevice8_Release(device);
5394 ok(!refcount, "Device has %u references left.\n", refcount);
5395 IDirect3D8_Release(d3d8);
5396 DestroyWindow(window);
5399 static void test_swvp_buffer(void)
5401 IDirect3DDevice8 *device;
5402 IDirect3D8 *d3d8;
5403 UINT refcount;
5404 HWND window;
5405 HRESULT hr;
5406 unsigned int i;
5407 IDirect3DVertexBuffer8 *buffer;
5408 static const unsigned int bufsize = 1024;
5409 D3DVERTEXBUFFER_DESC desc;
5410 struct device_desc device_desc;
5411 struct
5413 float x, y, z;
5414 } *ptr, *ptr2;
5416 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
5417 0, 0, 640, 480, 0, 0, 0, 0);
5418 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
5419 ok(!!d3d8, "Failed to create a D3D object.\n");
5421 device_desc.device_window = window;
5422 device_desc.width = 640;
5423 device_desc.height = 480;
5424 device_desc.flags = CREATE_DEVICE_SWVP_ONLY;
5425 if (!(device = create_device(d3d8, window, &device_desc)))
5427 skip("Failed to create a D3D device, skipping tests.\n");
5428 IDirect3D8_Release(d3d8);
5429 DestroyWindow(window);
5430 return;
5433 hr = IDirect3DDevice8_CreateVertexBuffer(device, bufsize * sizeof(*ptr), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, 0,
5434 D3DPOOL_DEFAULT, &buffer);
5435 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
5436 hr = IDirect3DVertexBuffer8_GetDesc(buffer, &desc);
5437 ok(SUCCEEDED(hr), "Failed to get desc, hr %#x.\n", hr);
5438 ok(desc.Pool == D3DPOOL_DEFAULT, "Got pool %u, expected D3DPOOL_DEFAULT\n", desc.Pool);
5439 ok(desc.Usage == (D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY),
5440 "Got usage %u, expected D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY\n", desc.Usage);
5442 hr = IDirect3DVertexBuffer8_Lock(buffer, 0, bufsize * sizeof(*ptr), (BYTE **)&ptr, D3DLOCK_DISCARD);
5443 ok(SUCCEEDED(hr), "Failed to lock buffer, hr %#x.\n", hr);
5444 for (i = 0; i < bufsize; i++)
5446 ptr[i].x = i * 1.0f;
5447 ptr[i].y = i * 2.0f;
5448 ptr[i].z = i * 3.0f;
5450 hr = IDirect3DVertexBuffer8_Unlock(buffer);
5451 ok(SUCCEEDED(hr), "Failed to unlock buffer, hr %#x.\n", hr);
5453 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ);
5454 ok(SUCCEEDED(hr), "Failed to set fvf, hr %#x.\n", hr);
5455 hr = IDirect3DDevice8_SetStreamSource(device, 0, buffer, sizeof(*ptr));
5456 ok(SUCCEEDED(hr), "Failed to set stream source, hr %#x.\n", hr);
5457 hr = IDirect3DDevice8_BeginScene(device);
5458 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
5459 hr = IDirect3DDevice8_DrawPrimitive(device, D3DPT_TRIANGLELIST, 0, 2);
5460 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
5461 hr = IDirect3DDevice8_EndScene(device);
5462 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
5464 hr = IDirect3DVertexBuffer8_Lock(buffer, 0, bufsize * sizeof(*ptr2), (BYTE **)&ptr2, D3DLOCK_DISCARD);
5465 ok(SUCCEEDED(hr), "Failed to lock buffer, hr %#x.\n", hr);
5466 ok(ptr == ptr2, "Lock returned two different pointers: %p, %p\n", ptr, ptr2);
5467 for (i = 0; i < bufsize; i++)
5469 if (ptr2[i].x != i * 1.0f || ptr2[i].y != i * 2.0f || ptr2[i].z != i * 3.0f)
5471 ok(FALSE, "Vertex %u is %f,%f,%f, expected %f,%f,%f\n", i,
5472 ptr2[i].x, ptr2[i].y, ptr2[i].z, i * 1.0f, i * 2.0f, i * 3.0f);
5473 break;
5476 hr = IDirect3DVertexBuffer8_Unlock(buffer);
5477 ok(SUCCEEDED(hr), "Failed to unlock buffer, hr %#x.\n", hr);
5479 IDirect3DVertexBuffer8_Release(buffer);
5480 refcount = IDirect3DDevice8_Release(device);
5481 ok(!refcount, "Device has %u references left.\n", refcount);
5482 IDirect3D8_Release(d3d8);
5483 DestroyWindow(window);
5486 static void test_npot_textures(void)
5488 IDirect3DDevice8 *device = NULL;
5489 IDirect3D8 *d3d8;
5490 ULONG refcount;
5491 HWND window = NULL;
5492 HRESULT hr;
5493 D3DCAPS8 caps;
5494 IDirect3DTexture8 *texture;
5495 IDirect3DCubeTexture8 *cube_texture;
5496 IDirect3DVolumeTexture8 *volume_texture;
5497 struct
5499 D3DPOOL pool;
5500 const char *pool_name;
5501 HRESULT hr;
5503 pools[] =
5505 { D3DPOOL_DEFAULT, "D3DPOOL_DEFAULT", D3DERR_INVALIDCALL },
5506 { D3DPOOL_MANAGED, "D3DPOOL_MANAGED", D3DERR_INVALIDCALL },
5507 { D3DPOOL_SYSTEMMEM, "D3DPOOL_SYSTEMMEM", D3DERR_INVALIDCALL },
5508 { D3DPOOL_SCRATCH, "D3DPOOL_SCRATCH", D3D_OK },
5510 unsigned int i, levels;
5511 BOOL tex_pow2, cube_pow2, vol_pow2;
5513 window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW,
5514 0, 0, 640, 480, 0, 0, 0, 0);
5515 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
5516 ok(!!d3d8, "Failed to create a D3D object.\n");
5517 if (!(device = create_device(d3d8, window, NULL)))
5519 skip("Failed to create a D3D device, skipping tests.\n");
5520 goto done;
5523 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
5524 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
5525 tex_pow2 = !!(caps.TextureCaps & D3DPTEXTURECAPS_POW2);
5526 cube_pow2 = !!(caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP_POW2);
5527 vol_pow2 = !!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP_POW2);
5528 ok(cube_pow2 == tex_pow2, "Cube texture and 2d texture pow2 restrictions mismatch.\n");
5529 ok(vol_pow2 == tex_pow2, "Volume texture and 2d texture pow2 restrictions mismatch.\n");
5531 for (i = 0; i < sizeof(pools) / sizeof(*pools); i++)
5533 for (levels = 0; levels <= 2; levels++)
5535 HRESULT expected;
5537 hr = IDirect3DDevice8_CreateTexture(device, 10, 10, levels, 0, D3DFMT_X8R8G8B8,
5538 pools[i].pool, &texture);
5539 if (!tex_pow2)
5541 expected = D3D_OK;
5543 else if (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL)
5545 if (levels == 1)
5546 expected = D3D_OK;
5547 else
5548 expected = pools[i].hr;
5550 else
5552 expected = pools[i].hr;
5554 ok(hr == expected, "CreateTexture(w=h=10, %s, levels=%u) returned hr %#x, expected %#x.\n",
5555 pools[i].pool_name, levels, hr, expected);
5557 if (SUCCEEDED(hr))
5558 IDirect3DTexture8_Release(texture);
5561 hr = IDirect3DDevice8_CreateCubeTexture(device, 3, 1, 0, D3DFMT_X8R8G8B8,
5562 pools[i].pool, &cube_texture);
5563 if (tex_pow2)
5565 ok(hr == pools[i].hr, "CreateCubeTexture(EdgeLength=3, %s) returned hr %#x, expected %#x.\n",
5566 pools[i].pool_name, hr, pools[i].hr);
5568 else
5570 ok(SUCCEEDED(hr), "CreateCubeTexture(EdgeLength=3, %s) returned hr %#x, expected %#x.\n",
5571 pools[i].pool_name, hr, D3D_OK);
5574 if (SUCCEEDED(hr))
5575 IDirect3DCubeTexture8_Release(cube_texture);
5577 hr = IDirect3DDevice8_CreateVolumeTexture(device, 2, 2, 3, 1, 0, D3DFMT_X8R8G8B8,
5578 pools[i].pool, &volume_texture);
5579 if (tex_pow2)
5581 ok(hr == pools[i].hr, "CreateVolumeTextur(Depth=3, %s) returned hr %#x, expected %#x.\n",
5582 pools[i].pool_name, hr, pools[i].hr);
5584 else
5586 ok(SUCCEEDED(hr), "CreateVolumeTextur(Depth=3, %s) returned hr %#x, expected %#x.\n",
5587 pools[i].pool_name, hr, D3D_OK);
5590 if (SUCCEEDED(hr))
5591 IDirect3DVolumeTexture8_Release(volume_texture);
5594 done:
5595 if (device)
5597 refcount = IDirect3DDevice8_Release(device);
5598 ok(!refcount, "Device has %u references left.\n", refcount);
5600 IDirect3D8_Release(d3d8);
5601 DestroyWindow(window);
5605 static void test_volume_locking(void)
5607 IDirect3DDevice8 *device;
5608 IDirect3D8 *d3d8;
5609 HWND window;
5610 HRESULT hr;
5611 IDirect3DVolumeTexture8 *texture;
5612 unsigned int i;
5613 D3DLOCKED_BOX locked_box;
5614 ULONG refcount;
5615 D3DCAPS8 caps;
5616 static const struct
5618 D3DPOOL pool;
5619 DWORD usage;
5620 HRESULT create_hr, lock_hr;
5622 tests[] =
5624 { D3DPOOL_DEFAULT, 0, D3D_OK, D3DERR_INVALIDCALL },
5625 { D3DPOOL_DEFAULT, D3DUSAGE_DYNAMIC, D3D_OK, D3D_OK },
5626 { D3DPOOL_SYSTEMMEM, 0, D3D_OK, D3D_OK },
5627 { D3DPOOL_SYSTEMMEM, D3DUSAGE_DYNAMIC, D3D_OK, D3D_OK },
5628 { D3DPOOL_MANAGED, 0, D3D_OK, D3D_OK },
5629 { D3DPOOL_MANAGED, D3DUSAGE_DYNAMIC, D3DERR_INVALIDCALL, D3D_OK },
5630 { D3DPOOL_SCRATCH, 0, D3D_OK, D3D_OK },
5631 { D3DPOOL_SCRATCH, D3DUSAGE_DYNAMIC, D3DERR_INVALIDCALL, D3D_OK },
5634 window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW,
5635 0, 0, 640, 480, 0, 0, 0, 0);
5636 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
5637 ok(!!d3d8, "Failed to create a D3D object.\n");
5638 if (!(device = create_device(d3d8, window, NULL)))
5640 skip("Failed to create a D3D device, skipping tests.\n");
5641 IDirect3D8_Release(d3d8);
5642 DestroyWindow(window);
5643 return;
5646 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
5647 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
5648 if (!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP))
5650 skip("Volume textures not supported, skipping test.\n");
5651 goto out;
5654 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
5656 hr = IDirect3DDevice8_CreateVolumeTexture(device, 4, 4, 4, 1, tests[i].usage,
5657 D3DFMT_A8R8G8B8, tests[i].pool, &texture);
5658 ok(hr == tests[i].create_hr, "Creating volume texture pool=%u, usage=%#x returned %#x, expected %#x.\n",
5659 tests[i].pool, tests[i].usage, hr, tests[i].create_hr);
5660 if (FAILED(hr))
5661 continue;
5663 locked_box.pBits = (void *)0xdeadbeef;
5664 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, NULL, 0);
5665 ok(hr == tests[i].lock_hr, "Lock returned %#x, expected %#x.\n", hr, tests[i].lock_hr);
5666 if (SUCCEEDED(hr))
5668 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
5669 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
5671 else
5673 ok (locked_box.pBits == NULL, "Failed lock set pBits = %p, expected NULL.\n", locked_box.pBits);
5675 IDirect3DVolumeTexture8_Release(texture);
5678 out:
5679 refcount = IDirect3DDevice8_Release(device);
5680 ok(!refcount, "Device has %u references left.\n", refcount);
5681 IDirect3D8_Release(d3d8);
5682 DestroyWindow(window);
5685 static void test_update_volumetexture(void)
5687 IDirect3DDevice8 *device;
5688 IDirect3D8 *d3d8;
5689 HWND window;
5690 HRESULT hr;
5691 IDirect3DVolumeTexture8 *src, *dst;
5692 unsigned int i;
5693 D3DLOCKED_BOX locked_box;
5694 ULONG refcount;
5695 D3DCAPS8 caps;
5696 static const struct
5698 D3DPOOL src_pool, dst_pool;
5699 HRESULT hr;
5701 tests[] =
5703 { D3DPOOL_DEFAULT, D3DPOOL_DEFAULT, D3DERR_INVALIDCALL },
5704 { D3DPOOL_MANAGED, D3DPOOL_DEFAULT, D3DERR_INVALIDCALL },
5705 { D3DPOOL_SYSTEMMEM, D3DPOOL_DEFAULT, D3D_OK },
5706 { D3DPOOL_SCRATCH, D3DPOOL_DEFAULT, D3DERR_INVALIDCALL },
5708 { D3DPOOL_DEFAULT, D3DPOOL_MANAGED, D3DERR_INVALIDCALL },
5709 { D3DPOOL_MANAGED, D3DPOOL_MANAGED, D3DERR_INVALIDCALL },
5710 { D3DPOOL_SYSTEMMEM, D3DPOOL_MANAGED, D3DERR_INVALIDCALL },
5711 { D3DPOOL_SCRATCH, D3DPOOL_MANAGED, D3DERR_INVALIDCALL },
5713 { D3DPOOL_DEFAULT, D3DPOOL_SYSTEMMEM, D3DERR_INVALIDCALL },
5714 { D3DPOOL_MANAGED, D3DPOOL_SYSTEMMEM, D3DERR_INVALIDCALL },
5715 { D3DPOOL_SYSTEMMEM, D3DPOOL_SYSTEMMEM, D3DERR_INVALIDCALL },
5716 { D3DPOOL_SCRATCH, D3DPOOL_SYSTEMMEM, D3DERR_INVALIDCALL },
5718 { D3DPOOL_DEFAULT, D3DPOOL_SCRATCH, D3DERR_INVALIDCALL },
5719 { D3DPOOL_MANAGED, D3DPOOL_SCRATCH, D3DERR_INVALIDCALL },
5720 { D3DPOOL_SYSTEMMEM, D3DPOOL_SCRATCH, D3DERR_INVALIDCALL },
5721 { D3DPOOL_SCRATCH, D3DPOOL_SCRATCH, D3DERR_INVALIDCALL },
5723 static const struct
5725 UINT src_size, dst_size;
5726 UINT src_lvl, dst_lvl;
5727 D3DFORMAT src_fmt, dst_fmt;
5729 tests2[] =
5731 { 8, 8, 0, 0, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 },
5732 { 8, 8, 4, 4, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 },
5733 { 8, 8, 2, 2, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 },
5734 { 8, 8, 1, 1, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 },
5735 { 8, 8, 4, 0, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 },
5736 { 8, 8, 1, 4, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 }, /* Different level count */
5737 { 4, 8, 1, 1, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 }, /* Different size */
5738 { 8, 8, 4, 4, D3DFMT_A8R8G8B8, D3DFMT_X8R8G8B8 }, /* Different format */
5741 window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW,
5742 0, 0, 640, 480, 0, 0, 0, 0);
5743 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
5744 ok(!!d3d8, "Failed to create a D3D object.\n");
5745 if (!(device = create_device(d3d8, window, NULL)))
5747 skip("Failed to create a D3D device, skipping tests.\n");
5748 IDirect3D8_Release(d3d8);
5749 DestroyWindow(window);
5750 return;
5753 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
5754 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
5755 if (!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP))
5757 skip("Volume textures not supported, skipping test.\n");
5758 goto out;
5761 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
5763 DWORD src_usage = tests[i].src_pool == D3DPOOL_DEFAULT ? D3DUSAGE_DYNAMIC : 0;
5764 DWORD dst_usage = tests[i].dst_pool == D3DPOOL_DEFAULT ? D3DUSAGE_DYNAMIC : 0;
5766 hr = IDirect3DDevice8_CreateVolumeTexture(device, 1, 1, 1, 1, src_usage,
5767 D3DFMT_A8R8G8B8, tests[i].src_pool, &src);
5768 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x.\n", hr);
5769 hr = IDirect3DDevice8_CreateVolumeTexture(device, 1, 1, 1, 1, dst_usage,
5770 D3DFMT_A8R8G8B8, tests[i].dst_pool, &dst);
5771 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x.\n", hr);
5773 hr = IDirect3DVolumeTexture8_LockBox(src, 0, &locked_box, NULL, 0);
5774 ok(SUCCEEDED(hr), "Failed to lock volume texture, hr %#x.\n", hr);
5775 *((DWORD *)locked_box.pBits) = 0x11223344;
5776 hr = IDirect3DVolumeTexture8_UnlockBox(src, 0);
5777 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
5779 hr = IDirect3DDevice8_UpdateTexture(device, (IDirect3DBaseTexture8 *)src, (IDirect3DBaseTexture8 *)dst);
5780 ok(hr == tests[i].hr, "UpdateTexture returned %#x, expected %#x, src pool %x, dst pool %u.\n",
5781 hr, tests[i].hr, tests[i].src_pool, tests[i].dst_pool);
5783 if (SUCCEEDED(hr))
5785 DWORD content = *((DWORD *)locked_box.pBits);
5786 hr = IDirect3DVolumeTexture8_LockBox(dst, 0, &locked_box, NULL, 0);
5787 ok(SUCCEEDED(hr), "Failed to lock volume texture, hr %#x.\n", hr);
5788 ok(content == 0x11223344, "Dest texture contained %#x, expected 0x11223344.\n", content);
5789 hr = IDirect3DVolumeTexture8_UnlockBox(dst, 0);
5790 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
5792 IDirect3DVolumeTexture8_Release(src);
5793 IDirect3DVolumeTexture8_Release(dst);
5796 if (!(caps.TextureCaps & D3DPTEXTURECAPS_MIPVOLUMEMAP))
5798 skip("Mipmapped volume maps not supported.\n");
5799 goto out;
5802 for (i = 0; i < sizeof(tests2) / sizeof(*tests2); i++)
5804 hr = IDirect3DDevice8_CreateVolumeTexture(device,
5805 tests2[i].src_size, tests2[i].src_size, tests2[i].src_size,
5806 tests2[i].src_lvl, 0, tests2[i].src_fmt, D3DPOOL_SYSTEMMEM, &src);
5807 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x, case %u.\n", hr, i);
5808 hr = IDirect3DDevice8_CreateVolumeTexture(device,
5809 tests2[i].dst_size, tests2[i].dst_size, tests2[i].dst_size,
5810 tests2[i].dst_lvl, 0, tests2[i].dst_fmt, D3DPOOL_DEFAULT, &dst);
5811 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x, case %u.\n", hr, i);
5813 hr = IDirect3DDevice8_UpdateTexture(device, (IDirect3DBaseTexture8 *)src, (IDirect3DBaseTexture8 *)dst);
5814 if (FAILED(hr))
5815 todo_wine ok(SUCCEEDED(hr), "Failed to update texture, hr %#x, case %u.\n", hr, i);
5816 else
5817 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x, case %u.\n", hr, i);
5819 IDirect3DVolumeTexture8_Release(src);
5820 IDirect3DVolumeTexture8_Release(dst);
5823 /* As far as I can see, UpdateTexture on non-matching texture behaves like a memcpy. The raw data
5824 * stays the same in a format change, a 2x2x1 texture is copied into the first row of a 4x4x1 texture,
5825 * etc. I could not get it to segfault, but the nonexistent 5th pixel of a 2x2x1 texture is copied into
5826 * pixel 1x2x1 of a 4x4x1 texture, demonstrating a read beyond the texture's end. I suspect any bad
5827 * memory access is silently ignored by the runtime, in the kernel or on the GPU.
5829 * I'm not adding tests for this behavior until an application needs it. */
5831 out:
5832 refcount = IDirect3DDevice8_Release(device);
5833 ok(!refcount, "Device has %u references left.\n", refcount);
5834 IDirect3D8_Release(d3d8);
5835 DestroyWindow(window);
5838 static void test_create_rt_ds_fail(void)
5840 IDirect3DDevice8 *device;
5841 HWND window;
5842 HRESULT hr;
5843 ULONG refcount;
5844 IDirect3D8 *d3d8;
5845 IDirect3DSurface8 *surface;
5847 window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW,
5848 0, 0, 640, 480, 0, 0, 0, 0);
5849 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
5850 ok(!!d3d8, "Failed to create a D3D object.\n");
5851 if (!(device = create_device(d3d8, window, NULL)))
5853 skip("Failed to create a D3D device, skipping tests.\n");
5854 IDirect3D8_Release(d3d8);
5855 DestroyWindow(window);
5856 return;
5859 /* Output pointer == NULL segfaults on Windows. */
5861 surface = (IDirect3DSurface8 *)0xdeadbeef;
5862 hr = IDirect3DDevice8_CreateRenderTarget(device, 4, 4, D3DFMT_D16,
5863 D3DMULTISAMPLE_NONE, FALSE, &surface);
5864 ok(hr == D3DERR_INVALIDCALL, "Creating a D16 render target returned hr %#x.\n", hr);
5865 ok(surface == NULL, "Got pointer %p, expected NULL.\n", surface);
5866 if (SUCCEEDED(hr))
5867 IDirect3DSurface8_Release(surface);
5869 surface = (IDirect3DSurface8 *)0xdeadbeef;
5870 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 4, 4, D3DFMT_A8R8G8B8,
5871 D3DMULTISAMPLE_NONE, &surface);
5872 ok(hr == D3DERR_INVALIDCALL, "Creating a A8R8G8B8 depth stencil returned hr %#x.\n", hr);
5873 ok(surface == NULL, "Got pointer %p, expected NULL.\n", surface);
5874 if (SUCCEEDED(hr))
5875 IDirect3DSurface8_Release(surface);
5877 refcount = IDirect3DDevice8_Release(device);
5878 ok(!refcount, "Device has %u references left.\n", refcount);
5879 IDirect3D8_Release(d3d8);
5880 DestroyWindow(window);
5883 static void test_volume_blocks(void)
5885 IDirect3DDevice8 *device;
5886 IDirect3D8 *d3d8;
5887 UINT refcount;
5888 HWND window;
5889 HRESULT hr;
5890 D3DCAPS8 caps;
5891 IDirect3DVolumeTexture8 *texture;
5892 unsigned int w, h, d, i, j;
5893 static const struct
5895 D3DFORMAT fmt;
5896 const char *name;
5897 unsigned int block_width;
5898 unsigned int block_height;
5899 unsigned int block_depth;
5900 unsigned int block_size;
5901 unsigned int broken;
5902 BOOL create_size_checked, core_fmt;
5904 formats[] =
5906 /* Scratch volumes enforce DXTn block locks, unlike their surface counterparts.
5907 * ATI2N and YUV blocks are not enforced on any tested card (r200, gtx 460). */
5908 {D3DFMT_DXT1, "D3DFMT_DXT1", 4, 4, 1, 8, 0, TRUE, TRUE },
5909 {D3DFMT_DXT2, "D3DFMT_DXT2", 4, 4, 1, 16, 0, TRUE, TRUE },
5910 {D3DFMT_DXT3, "D3DFMT_DXT3", 4, 4, 1, 16, 0, TRUE, TRUE },
5911 {D3DFMT_DXT4, "D3DFMT_DXT4", 4, 4, 1, 16, 0, TRUE, TRUE },
5912 {D3DFMT_DXT5, "D3DFMT_DXT5", 4, 4, 1, 16, 0, TRUE, TRUE },
5913 {D3DFMT_DXT5, "D3DFMT_DXT5", 4, 4, 1, 16, 0, TRUE, TRUE },
5914 /* ATI2N has 2x2 blocks on all AMD cards and Geforce 7 cards,
5915 * which doesn't match the format spec. On newer Nvidia cards
5916 * it has the correct 4x4 block size.
5917 * ATI1N volume textures are only supported by AMD GPUs right
5918 * now and locking offsets seem just wrong. */
5919 {MAKEFOURCC('A','T','I','1'), "ATI1N", 4, 4, 1, 8, 2, FALSE, FALSE},
5920 {MAKEFOURCC('A','T','I','2'), "ATI2N", 4, 4, 1, 16, 1, FALSE, FALSE},
5921 {D3DFMT_YUY2, "D3DFMT_YUY2", 2, 1, 1, 4, 1, FALSE, TRUE },
5922 {D3DFMT_UYVY, "D3DFMT_UYVY", 2, 1, 1, 4, 1, FALSE, TRUE },
5924 static const struct
5926 D3DPOOL pool;
5927 const char *name;
5928 BOOL need_driver_support, need_runtime_support;
5930 create_tests[] =
5932 {D3DPOOL_DEFAULT, "D3DPOOL_DEFAULT", TRUE, FALSE},
5933 {D3DPOOL_SCRATCH, "D3DPOOL_SCRATCH", FALSE, TRUE },
5934 {D3DPOOL_SYSTEMMEM, "D3DPOOL_SYSTEMMEM",TRUE, FALSE},
5935 {D3DPOOL_MANAGED, "D3DPOOL_MANAGED", TRUE, FALSE},
5937 static const struct
5939 unsigned int x, y, z, x2, y2, z2;
5941 offset_tests[] =
5943 {0, 0, 0, 8, 8, 8},
5944 {0, 0, 3, 8, 8, 8},
5945 {0, 4, 0, 8, 8, 8},
5946 {0, 4, 3, 8, 8, 8},
5947 {4, 0, 0, 8, 8, 8},
5948 {4, 0, 3, 8, 8, 8},
5949 {4, 4, 0, 8, 8, 8},
5950 {4, 4, 3, 8, 8, 8},
5952 D3DBOX box;
5953 D3DLOCKED_BOX locked_box;
5954 BYTE *base;
5955 INT expected_row_pitch, expected_slice_pitch;
5956 BOOL support, support_2d;
5957 BOOL pow2;
5958 unsigned int offset, expected_offset;
5960 window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW,
5961 0, 0, 640, 480, 0, 0, 0, 0);
5962 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
5963 ok(!!d3d8, "Failed to create a D3D object.\n");
5964 if (!(device = create_device(d3d8, window, NULL)))
5966 skip("Failed to create a D3D device, skipping tests.\n");
5967 IDirect3D8_Release(d3d8);
5968 DestroyWindow(window);
5969 return;
5971 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
5972 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
5973 pow2 = !!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP_POW2);
5975 for (i = 0; i < sizeof(formats) / sizeof(*formats); i++)
5977 hr = IDirect3D8_CheckDeviceFormat(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
5978 0, D3DRTYPE_VOLUMETEXTURE, formats[i].fmt);
5979 support = SUCCEEDED(hr);
5980 hr = IDirect3D8_CheckDeviceFormat(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
5981 0, D3DRTYPE_TEXTURE, formats[i].fmt);
5982 support_2d = SUCCEEDED(hr);
5984 /* Test creation restrictions */
5985 for (w = 1; w <= 8; w++)
5987 for (h = 1; h <= 8; h++)
5989 for (d = 1; d <= 8; d++)
5991 HRESULT expect_hr;
5992 BOOL size_is_pow2;
5993 BOOL block_aligned = TRUE;
5995 if (w & (formats[i].block_width - 1) || h & (formats[i].block_height - 1))
5996 block_aligned = FALSE;
5998 size_is_pow2 = !((w & (w - 1)) || (h & (h - 1)) || (d & (d - 1)));
6000 for (j = 0; j < sizeof(create_tests) / sizeof(*create_tests); j++)
6002 BOOL may_succeed = FALSE;
6003 BOOL todo = FALSE;
6005 if (create_tests[j].need_runtime_support && !formats[i].core_fmt && !support)
6006 expect_hr = D3DERR_INVALIDCALL;
6007 else if (formats[i].create_size_checked && !block_aligned)
6008 expect_hr = D3DERR_INVALIDCALL;
6009 else if (pow2 && !size_is_pow2 && create_tests[j].need_driver_support)
6010 expect_hr = D3DERR_INVALIDCALL;
6011 else if (create_tests[j].need_driver_support && !support)
6013 todo = support_2d;
6014 expect_hr = D3DERR_INVALIDCALL;
6016 else
6017 expect_hr = D3D_OK;
6019 texture = (IDirect3DVolumeTexture8 *)0xdeadbeef;
6020 hr = IDirect3DDevice8_CreateVolumeTexture(device, w, h, d, 1, 0,
6021 formats[i].fmt, create_tests[j].pool, &texture);
6023 /* Wine knows about ATI2N and happily creates a scratch resource even if GL
6024 * does not support it. Accept scratch creation of extension formats on
6025 * Windows as well if it occurs. We don't really care if e.g. a Windows 7
6026 * on an r200 GPU creates scratch ATI2N texture even though the card doesn't
6027 * support it. */
6028 if (!formats[i].core_fmt && !support && FAILED(expect_hr))
6029 may_succeed = TRUE;
6031 if (todo)
6033 todo_wine ok(hr == expect_hr || ((SUCCEEDED(hr) && may_succeed)),
6034 "Got unexpected hr %#x for format %s, pool %s, size %ux%ux%u.\n",
6035 hr, formats[i].name, create_tests[j].name, w, h, d);
6037 else
6039 ok(hr == expect_hr || ((SUCCEEDED(hr) && may_succeed)),
6040 "Got unexpected hr %#x for format %s, pool %s, size %ux%ux%u.\n",
6041 hr, formats[i].name, create_tests[j].name, w, h, d);
6044 if (FAILED(hr))
6045 ok(texture == NULL, "Got texture ptr %p, expected NULL.\n", texture);
6046 else
6047 IDirect3DVolumeTexture8_Release(texture);
6053 if (!support && !formats[i].core_fmt)
6054 continue;
6056 hr = IDirect3DDevice8_CreateVolumeTexture(device, 24, 8, 8, 1, 0,
6057 formats[i].fmt, D3DPOOL_SCRATCH, &texture);
6058 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x.\n", hr);
6060 /* Test lockrect offset */
6061 for (j = 0; j < sizeof(offset_tests) / sizeof(*offset_tests); j++)
6063 unsigned int bytes_per_pixel;
6064 bytes_per_pixel = formats[i].block_size / (formats[i].block_width * formats[i].block_height);
6066 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, NULL, 0);
6067 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6069 base = locked_box.pBits;
6070 if (formats[i].broken == 1)
6072 expected_row_pitch = bytes_per_pixel * 24;
6074 else if (formats[i].broken == 2)
6076 expected_row_pitch = 24;
6078 else
6080 expected_row_pitch = (24 /* tex width */ + formats[i].block_height - 1) / formats[i].block_width
6081 * formats[i].block_size;
6083 ok(locked_box.RowPitch == expected_row_pitch, "Got unexpected row pitch %d for format %s, expected %d.\n",
6084 locked_box.RowPitch, formats[i].name, expected_row_pitch);
6086 if (formats[i].broken)
6088 expected_slice_pitch = expected_row_pitch * 8;
6090 else
6092 expected_slice_pitch = (8 /* tex height */ + formats[i].block_depth - 1) / formats[i].block_height
6093 * expected_row_pitch;
6095 ok(locked_box.SlicePitch == expected_slice_pitch,
6096 "Got unexpected slice pitch %d for format %s, expected %d.\n",
6097 locked_box.SlicePitch, formats[i].name, expected_slice_pitch);
6099 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6100 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x, j %u.\n", hr, j);
6102 box.Left = offset_tests[j].x;
6103 box.Top = offset_tests[j].y;
6104 box.Front = offset_tests[j].z;
6105 box.Right = offset_tests[j].x2;
6106 box.Bottom = offset_tests[j].y2;
6107 box.Back = offset_tests[j].z2;
6108 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, &box, 0);
6109 ok(SUCCEEDED(hr), "Failed to lock volume texture, hr %#x, j %u.\n", hr, j);
6111 offset = (BYTE *)locked_box.pBits - base;
6112 if (formats[i].broken == 1)
6114 expected_offset = box.Front * expected_slice_pitch
6115 + box.Top * expected_row_pitch
6116 + box.Left * bytes_per_pixel;
6118 else if (formats[i].broken == 2)
6120 expected_offset = box.Front * expected_slice_pitch
6121 + box.Top * expected_row_pitch
6122 + box.Left;
6124 else
6126 expected_offset = (box.Front / formats[i].block_depth) * expected_slice_pitch
6127 + (box.Top / formats[i].block_height) * expected_row_pitch
6128 + (box.Left / formats[i].block_width) * formats[i].block_size;
6130 ok(offset == expected_offset, "Got unexpected offset %u for format %s, expected %u, box start %ux%ux%u.\n",
6131 offset, formats[i].name, expected_offset, box.Left, box.Top, box.Front);
6133 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6134 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6137 /* Test partial block locks */
6138 box.Front = 0;
6139 box.Back = 1;
6140 if (formats[i].block_width > 1)
6142 box.Left = formats[i].block_width >> 1;
6143 box.Top = 0;
6144 box.Right = formats[i].block_width;
6145 box.Bottom = formats[i].block_height;
6146 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, &box, 0);
6147 ok(FAILED(hr) || broken(formats[i].broken),
6148 "Partial block lock succeeded, expected failure, format %s.\n",
6149 formats[i].name);
6150 if (SUCCEEDED(hr))
6152 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6153 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6156 box.Left = 0;
6157 box.Top = 0;
6158 box.Right = formats[i].block_width >> 1;
6159 box.Bottom = formats[i].block_height;
6160 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, &box, 0);
6161 ok(FAILED(hr) || broken(formats[i].broken),
6162 "Partial block lock succeeded, expected failure, format %s.\n",
6163 formats[i].name);
6164 if (SUCCEEDED(hr))
6166 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6167 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6171 if (formats[i].block_height > 1)
6173 box.Left = 0;
6174 box.Top = formats[i].block_height >> 1;
6175 box.Right = formats[i].block_width;
6176 box.Bottom = formats[i].block_height;
6177 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, &box, 0);
6178 ok(FAILED(hr) || broken(formats[i].broken),
6179 "Partial block lock succeeded, expected failure, format %s.\n",
6180 formats[i].name);
6181 if (SUCCEEDED(hr))
6183 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6184 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6187 box.Left = 0;
6188 box.Top = 0;
6189 box.Right = formats[i].block_width;
6190 box.Bottom = formats[i].block_height >> 1;
6191 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, &box, 0);
6192 ok(FAILED(hr) || broken(formats[i].broken),
6193 "Partial block lock succeeded, expected failure, format %s.\n",
6194 formats[i].name);
6195 if (SUCCEEDED(hr))
6197 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6198 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6202 /* Test full block lock */
6203 box.Left = 0;
6204 box.Top = 0;
6205 box.Right = formats[i].block_width;
6206 box.Bottom = formats[i].block_height;
6207 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, &box, 0);
6208 ok(SUCCEEDED(hr), "Failed to lock volume texture, hr %#x.\n", hr);
6209 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6210 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6212 IDirect3DVolumeTexture8_Release(texture);
6214 /* Test mipmap locks. Don't do this with ATI2N, AMD warns that the runtime
6215 * does not allocate surfaces smaller than the blocksize properly. */
6216 if ((formats[i].block_width > 1 || formats[i].block_height > 1) && formats[i].core_fmt)
6218 hr = IDirect3DDevice8_CreateVolumeTexture(device, formats[i].block_width, formats[i].block_height,
6219 2, 2, 0, formats[i].fmt, D3DPOOL_SCRATCH, &texture);
6221 ok(SUCCEEDED(hr), "CreateVolumeTexture failed, hr %#x.\n", hr);
6222 hr = IDirect3DVolumeTexture8_LockBox(texture, 1, &locked_box, NULL, 0);
6223 ok(SUCCEEDED(hr), "Failed to lock volume texture mipmap, hr %#x.\n", hr);
6224 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 1);
6225 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6227 box.Left = box.Top = box.Front = 0;
6228 box.Right = formats[i].block_width == 1 ? 1 : formats[i].block_width >> 1;
6229 box.Bottom = formats[i].block_height == 1 ? 1 : formats[i].block_height >> 1;
6230 box.Back = 1;
6231 hr = IDirect3DVolumeTexture8_LockBox(texture, 1, &locked_box, &box, 0);
6232 ok(SUCCEEDED(hr), "Failed to lock volume texture mipmap, hr %#x.\n", hr);
6233 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 1);
6234 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6236 box.Right = formats[i].block_width;
6237 box.Bottom = formats[i].block_height;
6238 hr = IDirect3DVolumeTexture8_LockBox(texture, 1, &locked_box, &box, 0);
6239 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
6240 if (SUCCEEDED(hr))
6241 IDirect3DVolumeTexture8_UnlockBox(texture, 1);
6243 IDirect3DVolumeTexture8_Release(texture);
6247 refcount = IDirect3DDevice8_Release(device);
6248 ok(!refcount, "Device has %u references left.\n", refcount);
6249 IDirect3D8_Release(d3d8);
6250 DestroyWindow(window);
6253 static void test_lockbox_invalid(void)
6255 static const struct
6257 D3DBOX box;
6258 HRESULT result;
6260 test_data[] =
6262 {{0, 0, 2, 2, 0, 1}, D3D_OK}, /* Valid */
6263 {{0, 0, 4, 4, 0, 1}, D3D_OK}, /* Valid */
6264 {{0, 0, 0, 4, 0, 1}, D3DERR_INVALIDCALL}, /* 0 height */
6265 {{0, 0, 4, 0, 0, 1}, D3DERR_INVALIDCALL}, /* 0 width */
6266 {{0, 0, 4, 4, 1, 1}, D3DERR_INVALIDCALL}, /* 0 depth */
6267 {{4, 0, 0, 4, 0, 1}, D3DERR_INVALIDCALL}, /* left > right */
6268 {{0, 4, 4, 0, 0, 1}, D3DERR_INVALIDCALL}, /* top > bottom */
6269 {{0, 0, 4, 4, 1, 0}, D3DERR_INVALIDCALL}, /* back > front */
6270 {{0, 0, 8, 4, 0, 1}, D3DERR_INVALIDCALL}, /* right > surface */
6271 {{0, 0, 4, 8, 0, 1}, D3DERR_INVALIDCALL}, /* bottom > surface */
6272 {{0, 0, 4, 4, 0, 3}, D3DERR_INVALIDCALL}, /* back > surface */
6273 {{8, 0, 16, 4, 0, 1}, D3DERR_INVALIDCALL}, /* left > surface */
6274 {{0, 8, 4, 16, 0, 1}, D3DERR_INVALIDCALL}, /* top > surface */
6275 {{0, 0, 4, 4, 2, 4}, D3DERR_INVALIDCALL}, /* top > surface */
6277 static const D3DBOX test_boxt_2 = {2, 2, 4, 4, 0, 1};
6278 IDirect3DVolumeTexture8 *texture = NULL;
6279 D3DLOCKED_BOX locked_box;
6280 IDirect3DDevice8 *device;
6281 IDirect3D8 *d3d;
6282 unsigned int i;
6283 ULONG refcount;
6284 HWND window;
6285 BYTE *base;
6286 HRESULT hr;
6288 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
6289 0, 0, 640, 480, 0, 0, 0, 0);
6290 d3d = Direct3DCreate8(D3D_SDK_VERSION);
6291 ok(!!d3d, "Failed to create a D3D object.\n");
6292 if (!(device = create_device(d3d, window, NULL)))
6294 skip("Failed to create a D3D device, skipping tests.\n");
6295 IDirect3D8_Release(d3d);
6296 DestroyWindow(window);
6297 return;
6300 hr = IDirect3DDevice8_CreateVolumeTexture(device, 4, 4, 2, 1, 0,
6301 D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &texture);
6302 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x.\n", hr);
6303 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, NULL, 0);
6304 ok(SUCCEEDED(hr), "Failed to lock volume texture, hr %#x.\n", hr);
6305 base = locked_box.pBits;
6306 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6307 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6309 for (i = 0; i < (sizeof(test_data) / sizeof(*test_data)); ++i)
6311 unsigned int offset, expected_offset;
6312 const D3DBOX *box = &test_data[i].box;
6314 locked_box.pBits = (BYTE *)0xdeadbeef;
6315 locked_box.RowPitch = 0xdeadbeef;
6316 locked_box.SlicePitch = 0xdeadbeef;
6318 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, box, 0);
6319 /* Unlike surfaces, volumes properly check the box even in Windows XP */
6320 ok(hr == test_data[i].result,
6321 "Got unexpected hr %#x with box [%u, %u, %u]->[%u, %u, %u], expected %#x.\n",
6322 hr, box->Left, box->Top, box->Front, box->Right, box->Bottom, box->Back,
6323 test_data[i].result);
6324 if (FAILED(hr))
6325 continue;
6327 offset = (BYTE *)locked_box.pBits - base;
6328 expected_offset = box->Front * locked_box.SlicePitch + box->Top * locked_box.RowPitch + box->Left * 4;
6329 ok(offset == expected_offset,
6330 "Got unexpected offset %u (expected %u) for rect [%u, %u, %u]->[%u, %u, %u].\n",
6331 offset, expected_offset, box->Left, box->Top, box->Front, box->Right, box->Bottom, box->Back);
6333 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6334 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6337 /* locked_box = NULL throws an exception on Windows */
6338 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, NULL, 0);
6339 ok(SUCCEEDED(hr), "Failed to lock volume texture, hr %#x.\n", hr);
6340 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, NULL, 0);
6341 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
6342 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6343 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6344 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6345 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
6347 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, &test_data[0].box, 0);
6348 ok(hr == D3D_OK, "Got unexpected hr %#x for rect [%u, %u, %u]->[%u, %u, %u].\n",
6349 hr, test_data[0].box.Left, test_data[0].box.Top, test_data[0].box.Front,
6350 test_data[0].box.Right, test_data[0].box.Bottom, test_data[0].box.Back);
6351 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, &test_data[0].box, 0);
6352 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for rect [%u, %u, %u]->[%u, %u, %u].\n",
6353 hr, test_data[0].box.Left, test_data[0].box.Top, test_data[0].box.Front,
6354 test_data[0].box.Right, test_data[0].box.Bottom, test_data[0].box.Back);
6355 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, &test_boxt_2, 0);
6356 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for rect [%u, %u, %u]->[%u, %u, %u].\n",
6357 hr, test_boxt_2.Left, test_boxt_2.Top, test_boxt_2.Front,
6358 test_boxt_2.Right, test_boxt_2.Bottom, test_boxt_2.Back);
6359 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6360 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6362 IDirect3DVolumeTexture8_Release(texture);
6363 refcount = IDirect3DDevice8_Release(device);
6364 ok(!refcount, "Device has %u references left.\n", refcount);
6365 IDirect3D8_Release(d3d);
6366 DestroyWindow(window);
6369 static void test_pixel_format(void)
6371 HWND hwnd, hwnd2 = NULL;
6372 HDC hdc, hdc2 = NULL;
6373 HMODULE gl = NULL;
6374 int format, test_format;
6375 PIXELFORMATDESCRIPTOR pfd;
6376 IDirect3D8 *d3d8 = NULL;
6377 IDirect3DDevice8 *device = NULL;
6378 HRESULT hr;
6379 static const float point[3] = {0.0, 0.0, 0.0};
6381 hwnd = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
6382 100, 100, 160, 160, NULL, NULL, NULL, NULL);
6383 if (!hwnd)
6385 skip("Failed to create window\n");
6386 return;
6389 hwnd2 = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
6390 100, 100, 160, 160, NULL, NULL, NULL, NULL);
6392 hdc = GetDC(hwnd);
6393 if (!hdc)
6395 skip("Failed to get DC\n");
6396 goto cleanup;
6399 if (hwnd2)
6400 hdc2 = GetDC(hwnd2);
6402 gl = LoadLibraryA("opengl32.dll");
6403 ok(!!gl, "failed to load opengl32.dll; SetPixelFormat()/GetPixelFormat() may not work right\n");
6405 format = GetPixelFormat(hdc);
6406 ok(format == 0, "new window has pixel format %d\n", format);
6408 ZeroMemory(&pfd, sizeof(pfd));
6409 pfd.nSize = sizeof(pfd);
6410 pfd.nVersion = 1;
6411 pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
6412 pfd.iPixelType = PFD_TYPE_RGBA;
6413 pfd.iLayerType = PFD_MAIN_PLANE;
6414 format = ChoosePixelFormat(hdc, &pfd);
6415 if (format <= 0)
6417 skip("no pixel format available\n");
6418 goto cleanup;
6421 if (!SetPixelFormat(hdc, format, &pfd) || GetPixelFormat(hdc) != format)
6423 skip("failed to set pixel format\n");
6424 goto cleanup;
6427 if (!hdc2 || !SetPixelFormat(hdc2, format, &pfd) || GetPixelFormat(hdc2) != format)
6429 skip("failed to set pixel format on second window\n");
6430 if (hdc2)
6432 ReleaseDC(hwnd2, hdc2);
6433 hdc2 = NULL;
6437 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
6438 ok(!!d3d8, "Failed to create a D3D object.\n");
6440 test_format = GetPixelFormat(hdc);
6441 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6443 if (!(device = create_device(d3d8, hwnd, NULL)))
6445 skip("Failed to create device\n");
6446 goto cleanup;
6449 test_format = GetPixelFormat(hdc);
6450 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6452 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ);
6453 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
6455 test_format = GetPixelFormat(hdc);
6456 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6458 hr = IDirect3DDevice8_BeginScene(device);
6459 ok(SUCCEEDED(hr), "BeginScene failed %#x\n", hr);
6461 test_format = GetPixelFormat(hdc);
6462 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6464 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_POINTLIST, 1, point, 3 * sizeof(float));
6465 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6467 test_format = GetPixelFormat(hdc);
6468 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6470 hr = IDirect3DDevice8_EndScene(device);
6471 ok(SUCCEEDED(hr), "EndScene failed %#x\n", hr);
6473 test_format = GetPixelFormat(hdc);
6474 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6476 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
6477 ok(SUCCEEDED(hr), "Present failed %#x\n", hr);
6479 test_format = GetPixelFormat(hdc);
6480 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6482 if (hdc2)
6484 hr = IDirect3DDevice8_Present(device, NULL, NULL, hwnd2, NULL);
6485 ok(SUCCEEDED(hr), "Present failed %#x\n", hr);
6487 test_format = GetPixelFormat(hdc);
6488 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6490 test_format = GetPixelFormat(hdc2);
6491 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
6494 cleanup:
6495 if (device)
6497 UINT refcount = IDirect3DDevice8_Release(device);
6498 ok(!refcount, "Device has %u references left.\n", refcount);
6500 if (d3d8) IDirect3D8_Release(d3d8);
6501 if (gl) FreeLibrary(gl);
6502 if (hdc) ReleaseDC(hwnd, hdc);
6503 if (hdc2) ReleaseDC(hwnd2, hdc2);
6504 if (hwnd) DestroyWindow(hwnd);
6505 if (hwnd2) DestroyWindow(hwnd2);
6508 static void test_begin_end_state_block(void)
6510 IDirect3DDevice8 *device;
6511 DWORD stateblock;
6512 IDirect3D8 *d3d;
6513 ULONG refcount;
6514 HWND window;
6515 HRESULT hr;
6517 window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW,
6518 0, 0, 640, 480, NULL, NULL, NULL, NULL);
6519 d3d = Direct3DCreate8(D3D_SDK_VERSION);
6520 ok(!!d3d, "Failed to create a D3D object.\n");
6521 if (!(device = create_device(d3d, window, NULL)))
6523 skip("Failed to create a D3D device, skipping tests.\n");
6524 IDirect3D8_Release(d3d);
6525 DestroyWindow(window);
6526 return;
6529 /* Should succeed. */
6530 hr = IDirect3DDevice8_BeginStateBlock(device);
6531 ok(SUCCEEDED(hr), "Failed to begin stateblock, hr %#x.\n", hr);
6533 /* Calling BeginStateBlock() while recording should return
6534 * D3DERR_INVALIDCALL. */
6535 hr = IDirect3DDevice8_BeginStateBlock(device);
6536 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
6538 /* Should succeed. */
6539 stateblock = 0xdeadbeef;
6540 hr = IDirect3DDevice8_EndStateBlock(device, &stateblock);
6541 ok(SUCCEEDED(hr), "Failed to end stateblock, hr %#x.\n", hr);
6542 ok(!!stateblock && stateblock != 0xdeadbeef, "Got unexpected stateblock %#x.\n", stateblock);
6543 IDirect3DDevice8_DeleteStateBlock(device, stateblock);
6545 /* Calling EndStateBlock() while not recording should return
6546 * D3DERR_INVALIDCALL. stateblock should not be touched. */
6547 stateblock = 0xdeadbeef;
6548 hr = IDirect3DDevice8_EndStateBlock(device, &stateblock);
6549 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
6550 ok(stateblock == 0xdeadbeef, "Got unexpected stateblock %#x.\n", stateblock);
6552 refcount = IDirect3DDevice8_Release(device);
6553 ok(!refcount, "Device has %u references left.\n", refcount);
6554 IDirect3D8_Release(d3d);
6555 DestroyWindow(window);
6558 static void test_shader_constant_apply(void)
6560 static const float vs_const[] = {1.0f, 2.0f, 3.0f, 4.0f};
6561 static const float ps_const[] = {5.0f, 6.0f, 7.0f, 8.0f};
6562 static const float initial[] = {0.0f, 0.0f, 0.0f, 0.0f};
6563 DWORD vs_version, ps_version;
6564 IDirect3DDevice8 *device;
6565 DWORD stateblock;
6566 IDirect3D8 *d3d;
6567 ULONG refcount;
6568 D3DCAPS8 caps;
6569 float ret[4];
6570 HWND window;
6571 HRESULT hr;
6573 window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW,
6574 0, 0, 640, 480, NULL, NULL, NULL, NULL);
6575 d3d = Direct3DCreate8(D3D_SDK_VERSION);
6576 ok(!!d3d, "Failed to create a D3D object.\n");
6577 if (!(device = create_device(d3d, window, NULL)))
6579 skip("Failed to create a D3D device, skipping tests.\n");
6580 IDirect3D8_Release(d3d);
6581 DestroyWindow(window);
6582 return;
6585 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
6586 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
6587 vs_version = caps.VertexShaderVersion & 0xffff;
6588 ps_version = caps.PixelShaderVersion & 0xffff;
6590 if (vs_version)
6592 hr = IDirect3DDevice8_SetVertexShaderConstant(device, 0, initial, 1);
6593 ok(SUCCEEDED(hr), "Failed to set vertex shader constant, hr %#x.\n", hr);
6594 hr = IDirect3DDevice8_SetVertexShaderConstant(device, 1, initial, 1);
6595 ok(SUCCEEDED(hr), "Failed to set vertex shader constant, hr %#x.\n", hr);
6597 hr = IDirect3DDevice8_GetVertexShaderConstant(device, 0, ret, 1);
6598 ok(SUCCEEDED(hr), "Failed to get vertex shader constant, hr %#x.\n", hr);
6599 ok(!memcmp(ret, initial, sizeof(initial)),
6600 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
6601 ret[0], ret[1], ret[2], ret[3], initial[0], initial[1], initial[2], initial[3]);
6602 hr = IDirect3DDevice8_GetVertexShaderConstant(device, 1, ret, 1);
6603 ok(SUCCEEDED(hr), "Failed to get vertex shader constant, hr %#x.\n", hr);
6604 ok(!memcmp(ret, initial, sizeof(initial)),
6605 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
6606 ret[0], ret[1], ret[2], ret[3], initial[0], initial[1], initial[2], initial[3]);
6608 hr = IDirect3DDevice8_SetVertexShaderConstant(device, 0, vs_const, 1);
6609 ok(SUCCEEDED(hr), "Failed to set vertex shader constant, hr %#x.\n", hr);
6611 if (ps_version)
6613 hr = IDirect3DDevice8_SetPixelShaderConstant(device, 0, initial, 1);
6614 ok(SUCCEEDED(hr), "Failed to set pixel shader constant, hr %#x.\n", hr);
6615 hr = IDirect3DDevice8_SetPixelShaderConstant(device, 1, initial, 1);
6616 ok(SUCCEEDED(hr), "Failed to set pixel shader constant, hr %#x.\n", hr);
6618 hr = IDirect3DDevice8_GetPixelShaderConstant(device, 0, ret, 1);
6619 ok(SUCCEEDED(hr), "Failed to get pixel shader constant, hr %#x.\n", hr);
6620 ok(!memcmp(ret, initial, sizeof(initial)),
6621 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
6622 ret[0], ret[1], ret[2], ret[3], initial[0], initial[1], initial[2], initial[3]);
6623 hr = IDirect3DDevice8_GetPixelShaderConstant(device, 1, ret, 1);
6624 ok(SUCCEEDED(hr), "Failed to get pixel shader constant, hr %#x.\n", hr);
6625 ok(!memcmp(ret, initial, sizeof(initial)),
6626 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
6627 ret[0], ret[1], ret[2], ret[3], initial[0], initial[1], initial[2], initial[3]);
6629 hr = IDirect3DDevice8_SetPixelShaderConstant(device, 0, ps_const, 1);
6630 ok(SUCCEEDED(hr), "Failed to set pixel shader constant, hr %#x.\n", hr);
6633 hr = IDirect3DDevice8_BeginStateBlock(device);
6634 ok(SUCCEEDED(hr), "Failed to begin stateblock, hr %#x.\n", hr);
6636 if (vs_version)
6638 hr = IDirect3DDevice8_SetVertexShaderConstant(device, 1, vs_const, 1);
6639 ok(SUCCEEDED(hr), "Failed to set vertex shader constant, hr %#x.\n", hr);
6641 if (ps_version)
6643 hr = IDirect3DDevice8_SetPixelShaderConstant(device, 1, ps_const, 1);
6644 ok(SUCCEEDED(hr), "Failed to set pixel shader constant, hr %#x.\n", hr);
6647 hr = IDirect3DDevice8_EndStateBlock(device, &stateblock);
6648 ok(SUCCEEDED(hr), "Failed to end stateblock, hr %#x.\n", hr);
6650 if (vs_version)
6652 hr = IDirect3DDevice8_GetVertexShaderConstant(device, 0, ret, 1);
6653 ok(SUCCEEDED(hr), "Failed to get vertex shader constant, hr %#x.\n", hr);
6654 ok(!memcmp(ret, vs_const, sizeof(vs_const)),
6655 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
6656 ret[0], ret[1], ret[2], ret[3], vs_const[0], vs_const[1], vs_const[2], vs_const[3]);
6657 hr = IDirect3DDevice8_GetVertexShaderConstant(device, 1, ret, 1);
6658 ok(SUCCEEDED(hr), "Failed to get vertex shader constant, hr %#x.\n", hr);
6659 ok(!memcmp(ret, initial, sizeof(initial)),
6660 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
6661 ret[0], ret[1], ret[2], ret[3], initial[0], initial[1], initial[2], initial[3]);
6663 if (ps_version)
6665 hr = IDirect3DDevice8_GetPixelShaderConstant(device, 0, ret, 1);
6666 ok(SUCCEEDED(hr), "Failed to get pixel shader constant, hr %#x.\n", hr);
6667 ok(!memcmp(ret, ps_const, sizeof(ps_const)),
6668 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
6669 ret[0], ret[1], ret[2], ret[3], ps_const[0], ps_const[1], ps_const[2], ps_const[3]);
6670 hr = IDirect3DDevice8_GetPixelShaderConstant(device, 1, ret, 1);
6671 ok(SUCCEEDED(hr), "Failed to get pixel shader constant, hr %#x.\n", hr);
6672 ok(!memcmp(ret, initial, sizeof(initial)),
6673 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
6674 ret[0], ret[1], ret[2], ret[3], initial[0], initial[1], initial[2], initial[3]);
6677 /* Apply doesn't overwrite constants that aren't explicitly set on the
6678 * source stateblock. */
6679 hr = IDirect3DDevice8_ApplyStateBlock(device, stateblock);
6680 ok(SUCCEEDED(hr), "Failed to apply stateblock, hr %#x.\n", hr);
6682 if (vs_version)
6684 hr = IDirect3DDevice8_GetVertexShaderConstant(device, 0, ret, 1);
6685 ok(SUCCEEDED(hr), "Failed to get vertex shader constant, hr %#x.\n", hr);
6686 ok(!memcmp(ret, vs_const, sizeof(vs_const)),
6687 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
6688 ret[0], ret[1], ret[2], ret[3], vs_const[0], vs_const[1], vs_const[2], vs_const[3]);
6689 hr = IDirect3DDevice8_GetVertexShaderConstant(device, 1, ret, 1);
6690 ok(SUCCEEDED(hr), "Failed to get vertex shader constant, hr %#x.\n", hr);
6691 ok(!memcmp(ret, vs_const, sizeof(vs_const)),
6692 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
6693 ret[0], ret[1], ret[2], ret[3], vs_const[0], vs_const[1], vs_const[2], vs_const[3]);
6695 if (ps_version)
6697 hr = IDirect3DDevice8_GetPixelShaderConstant(device, 0, ret, 1);
6698 ok(SUCCEEDED(hr), "Failed to get pixel shader constant, hr %#x.\n", hr);
6699 ok(!memcmp(ret, ps_const, sizeof(ps_const)),
6700 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
6701 ret[0], ret[1], ret[2], ret[3], ps_const[0], ps_const[1], ps_const[2], ps_const[3]);
6702 hr = IDirect3DDevice8_GetPixelShaderConstant(device, 1, ret, 1);
6703 ok(SUCCEEDED(hr), "Failed to get pixel shader constant, hr %#x.\n", hr);
6704 ok(!memcmp(ret, ps_const, sizeof(ps_const)),
6705 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
6706 ret[0], ret[1], ret[2], ret[3], ps_const[0], ps_const[1], ps_const[2], ps_const[3]);
6709 IDirect3DDevice8_DeleteStateBlock(device, stateblock);
6710 refcount = IDirect3DDevice8_Release(device);
6711 ok(!refcount, "Device has %u references left.\n", refcount);
6712 IDirect3D8_Release(d3d);
6713 DestroyWindow(window);
6716 static void test_resource_type(void)
6718 IDirect3DDevice8 *device;
6719 IDirect3DSurface8 *surface;
6720 IDirect3DTexture8 *texture;
6721 IDirect3DCubeTexture8 *cube_texture;
6722 IDirect3DVolume8 *volume;
6723 IDirect3DVolumeTexture8 *volume_texture;
6724 D3DSURFACE_DESC surface_desc;
6725 D3DVOLUME_DESC volume_desc;
6726 D3DRESOURCETYPE type;
6727 IDirect3D8 *d3d;
6728 ULONG refcount;
6729 HWND window;
6730 HRESULT hr;
6731 D3DCAPS8 caps;
6733 window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW,
6734 0, 0, 640, 480, NULL, NULL, NULL, NULL);
6735 d3d = Direct3DCreate8(D3D_SDK_VERSION);
6736 ok(!!d3d, "Failed to create a D3D object.\n");
6737 if (!(device = create_device(d3d, window, NULL)))
6739 skip("Failed to create a D3D device, skipping tests.\n");
6740 IDirect3D8_Release(d3d);
6741 DestroyWindow(window);
6742 return;
6745 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
6746 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
6748 hr = IDirect3DDevice8_CreateImageSurface(device, 4, 4, D3DFMT_X8R8G8B8, &surface);
6749 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6750 hr = IDirect3DSurface8_GetDesc(surface, &surface_desc);
6751 ok(SUCCEEDED(hr), "Failed to get surface description, hr %#x.\n", hr);
6752 ok(surface_desc.Type == D3DRTYPE_SURFACE, "Expected type D3DRTYPE_SURFACE, got %u.\n",
6753 surface_desc.Type);
6754 IDirect3DSurface8_Release(surface);
6756 hr = IDirect3DDevice8_CreateTexture(device, 2, 8, 4, 0, D3DFMT_X8R8G8B8,
6757 D3DPOOL_SYSTEMMEM, &texture);
6758 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6759 type = IDirect3DTexture8_GetType(texture);
6760 ok(type == D3DRTYPE_TEXTURE, "Expected type D3DRTYPE_TEXTURE, got %u.\n", type);
6762 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 0, &surface);
6763 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
6764 hr = IDirect3DSurface8_GetDesc(surface, &surface_desc);
6765 ok(SUCCEEDED(hr), "Failed to get surface description, hr %#x.\n", hr);
6766 ok(surface_desc.Type == D3DRTYPE_SURFACE, "Expected type D3DRTYPE_SURFACE, got %u.\n",
6767 surface_desc.Type);
6768 ok(surface_desc.Width == 2, "Expected width 2, got %u.\n", surface_desc.Width);
6769 ok(surface_desc.Height == 8, "Expected height 8, got %u.\n", surface_desc.Height);
6770 hr = IDirect3DTexture8_GetLevelDesc(texture, 0, &surface_desc);
6771 ok(SUCCEEDED(hr), "Failed to get level description, hr %#x.\n", hr);
6772 ok(surface_desc.Type == D3DRTYPE_SURFACE, "Expected type D3DRTYPE_SURFACE, got %u.\n",
6773 surface_desc.Type);
6774 ok(surface_desc.Width == 2, "Expected width 2, got %u.\n", surface_desc.Width);
6775 ok(surface_desc.Height == 8, "Expected height 8, got %u.\n", surface_desc.Height);
6776 IDirect3DSurface8_Release(surface);
6778 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 2, &surface);
6779 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
6780 hr = IDirect3DSurface8_GetDesc(surface, &surface_desc);
6781 ok(SUCCEEDED(hr), "Failed to get surface description, hr %#x.\n", hr);
6782 ok(surface_desc.Type == D3DRTYPE_SURFACE, "Expected type D3DRTYPE_SURFACE, got %u.\n",
6783 surface_desc.Type);
6784 ok(surface_desc.Width == 1, "Expected width 1, got %u.\n", surface_desc.Width);
6785 ok(surface_desc.Height == 2, "Expected height 2, got %u.\n", surface_desc.Height);
6786 hr = IDirect3DTexture8_GetLevelDesc(texture, 2, &surface_desc);
6787 ok(SUCCEEDED(hr), "Failed to get level description, hr %#x.\n", hr);
6788 ok(surface_desc.Type == D3DRTYPE_SURFACE, "Expected type D3DRTYPE_SURFACE, got %u.\n",
6789 surface_desc.Type);
6790 ok(surface_desc.Width == 1, "Expected width 1, got %u.\n", surface_desc.Width);
6791 ok(surface_desc.Height == 2, "Expected height 2, got %u.\n", surface_desc.Height);
6792 IDirect3DSurface8_Release(surface);
6793 IDirect3DTexture8_Release(texture);
6795 if (caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP)
6797 hr = IDirect3DDevice8_CreateCubeTexture(device, 1, 1, 0, D3DFMT_X8R8G8B8,
6798 D3DPOOL_SYSTEMMEM, &cube_texture);
6799 ok(SUCCEEDED(hr), "Failed to create cube texture, hr %#x.\n", hr);
6800 type = IDirect3DCubeTexture8_GetType(cube_texture);
6801 ok(type == D3DRTYPE_CUBETEXTURE, "Expected type D3DRTYPE_CUBETEXTURE, got %u.\n", type);
6803 hr = IDirect3DCubeTexture8_GetCubeMapSurface(cube_texture,
6804 D3DCUBEMAP_FACE_NEGATIVE_X, 0, &surface);
6805 ok(SUCCEEDED(hr), "Failed to get cube map surface, hr %#x.\n", hr);
6806 hr = IDirect3DSurface8_GetDesc(surface, &surface_desc);
6807 ok(SUCCEEDED(hr), "Failed to get surface description, hr %#x.\n", hr);
6808 ok(surface_desc.Type == D3DRTYPE_SURFACE, "Expected type D3DRTYPE_SURFACE, got %u.\n",
6809 surface_desc.Type);
6810 hr = IDirect3DCubeTexture8_GetLevelDesc(cube_texture, 0, &surface_desc);
6811 ok(SUCCEEDED(hr), "Failed to get level description, hr %#x.\n", hr);
6812 ok(surface_desc.Type == D3DRTYPE_SURFACE, "Expected type D3DRTYPE_SURFACE, got %u.\n",
6813 surface_desc.Type);
6814 IDirect3DSurface8_Release(surface);
6815 IDirect3DCubeTexture8_Release(cube_texture);
6817 else
6818 skip("Cube maps not supported.\n");
6820 if (caps.TextureCaps & D3DPTEXTURECAPS_MIPVOLUMEMAP)
6822 hr = IDirect3DDevice8_CreateVolumeTexture(device, 2, 4, 8, 4, 0, D3DFMT_X8R8G8B8,
6823 D3DPOOL_SYSTEMMEM, &volume_texture);
6824 ok(SUCCEEDED(hr), "CreateVolumeTexture failed, hr %#x.\n", hr);
6825 type = IDirect3DVolumeTexture8_GetType(volume_texture);
6826 ok(type == D3DRTYPE_VOLUMETEXTURE, "Expected type D3DRTYPE_VOLUMETEXTURE, got %u.\n", type);
6828 hr = IDirect3DVolumeTexture8_GetVolumeLevel(volume_texture, 0, &volume);
6829 ok(SUCCEEDED(hr), "Failed to get volume level, hr %#x.\n", hr);
6830 /* IDirect3DVolume8 is not an IDirect3DResource8 and has no GetType method. */
6831 hr = IDirect3DVolume8_GetDesc(volume, &volume_desc);
6832 ok(SUCCEEDED(hr), "Failed to get volume description, hr %#x.\n", hr);
6833 ok(volume_desc.Type == D3DRTYPE_VOLUME, "Expected type D3DRTYPE_VOLUME, got %u.\n",
6834 volume_desc.Type);
6835 ok(volume_desc.Width == 2, "Expected width 2, got %u.\n", volume_desc.Width);
6836 ok(volume_desc.Height == 4, "Expected height 4, got %u.\n", volume_desc.Height);
6837 ok(volume_desc.Depth == 8, "Expected depth 8, got %u.\n", volume_desc.Depth);
6838 hr = IDirect3DVolumeTexture8_GetLevelDesc(volume_texture, 0, &volume_desc);
6839 ok(SUCCEEDED(hr), "Failed to get level description, hr %#x.\n", hr);
6840 ok(volume_desc.Type == D3DRTYPE_VOLUME, "Expected type D3DRTYPE_VOLUME, got %u.\n",
6841 volume_desc.Type);
6842 ok(volume_desc.Width == 2, "Expected width 2, got %u.\n", volume_desc.Width);
6843 ok(volume_desc.Height == 4, "Expected height 4, got %u.\n", volume_desc.Height);
6844 ok(volume_desc.Depth == 8, "Expected depth 8, got %u.\n", volume_desc.Depth);
6845 IDirect3DVolume8_Release(volume);
6847 hr = IDirect3DVolumeTexture8_GetVolumeLevel(volume_texture, 2, &volume);
6848 ok(SUCCEEDED(hr), "Failed to get volume level, hr %#x.\n", hr);
6849 hr = IDirect3DVolume8_GetDesc(volume, &volume_desc);
6850 ok(SUCCEEDED(hr), "Failed to get volume description, hr %#x.\n", hr);
6851 ok(volume_desc.Type == D3DRTYPE_VOLUME, "Expected type D3DRTYPE_VOLUME, got %u.\n",
6852 volume_desc.Type);
6853 ok(volume_desc.Width == 1, "Expected width 1, got %u.\n", volume_desc.Width);
6854 ok(volume_desc.Height == 1, "Expected height 1, got %u.\n", volume_desc.Height);
6855 ok(volume_desc.Depth == 2, "Expected depth 2, got %u.\n", volume_desc.Depth);
6856 hr = IDirect3DVolumeTexture8_GetLevelDesc(volume_texture, 2, &volume_desc);
6857 ok(SUCCEEDED(hr), "Failed to get level description, hr %#x.\n", hr);
6858 ok(volume_desc.Type == D3DRTYPE_VOLUME, "Expected type D3DRTYPE_VOLUME, got %u.\n",
6859 volume_desc.Type);
6860 ok(volume_desc.Width == 1, "Expected width 1, got %u.\n", volume_desc.Width);
6861 ok(volume_desc.Height == 1, "Expected height 1, got %u.\n", volume_desc.Height);
6862 ok(volume_desc.Depth == 2, "Expected depth 2, got %u.\n", volume_desc.Depth);
6863 IDirect3DVolume8_Release(volume);
6864 IDirect3DVolumeTexture8_Release(volume_texture);
6866 else
6867 skip("Mipmapped volume maps not supported.\n");
6869 refcount = IDirect3DDevice8_Release(device);
6870 ok(!refcount, "Device has %u references left.\n", refcount);
6871 IDirect3D8_Release(d3d);
6872 DestroyWindow(window);
6875 static void test_mipmap_lock(void)
6877 IDirect3DDevice8 *device;
6878 IDirect3DSurface8 *surface, *surface2, *surface_dst, *surface_dst2;
6879 IDirect3DTexture8 *texture, *texture_dst;
6880 IDirect3D8 *d3d;
6881 ULONG refcount;
6882 HWND window;
6883 HRESULT hr;
6884 D3DLOCKED_RECT locked_rect;
6886 window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW,
6887 0, 0, 640, 480, NULL, NULL, NULL, NULL);
6888 d3d = Direct3DCreate8(D3D_SDK_VERSION);
6889 ok(!!d3d, "Failed to create a D3D object.\n");
6890 if (!(device = create_device(d3d, window, NULL)))
6892 skip("Failed to create a D3D device, skipping tests.\n");
6893 IDirect3D8_Release(d3d);
6894 DestroyWindow(window);
6895 return;
6898 hr = IDirect3DDevice8_CreateTexture(device, 4, 4, 2, 0, D3DFMT_X8R8G8B8,
6899 D3DPOOL_DEFAULT, &texture_dst);
6900 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6901 hr = IDirect3DTexture8_GetSurfaceLevel(texture_dst, 0, &surface_dst);
6902 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
6903 hr = IDirect3DTexture8_GetSurfaceLevel(texture_dst, 1, &surface_dst2);
6904 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
6906 hr = IDirect3DDevice8_CreateTexture(device, 4, 4, 2, 0, D3DFMT_X8R8G8B8,
6907 D3DPOOL_SYSTEMMEM, &texture);
6908 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6909 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 0, &surface);
6910 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
6911 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 1, &surface2);
6912 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
6914 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, NULL, 0);
6915 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
6916 hr = IDirect3DSurface8_LockRect(surface2, &locked_rect, NULL, 0);
6917 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
6918 hr = IDirect3DSurface8_UnlockRect(surface);
6919 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
6921 hr = IDirect3DDevice8_CopyRects(device, surface, NULL, 0, surface_dst, NULL);
6922 ok(SUCCEEDED(hr), "Failed to update surface, hr %#x.\n", hr);
6923 hr = IDirect3DDevice8_CopyRects(device, surface2, NULL, 0, surface_dst2, NULL);
6924 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
6926 /* Apparently there's no validation on the container. */
6927 hr = IDirect3DDevice8_UpdateTexture(device, (IDirect3DBaseTexture8 *)texture,
6928 (IDirect3DBaseTexture8 *)texture_dst);
6929 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x.\n", hr);
6931 hr = IDirect3DSurface8_UnlockRect(surface2);
6932 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
6934 IDirect3DSurface8_Release(surface_dst2);
6935 IDirect3DSurface8_Release(surface_dst);
6936 IDirect3DSurface8_Release(surface2);
6937 IDirect3DSurface8_Release(surface);
6938 IDirect3DTexture8_Release(texture_dst);
6939 IDirect3DTexture8_Release(texture);
6941 refcount = IDirect3DDevice8_Release(device);
6942 ok(!refcount, "Device has %u references left.\n", refcount);
6943 IDirect3D8_Release(d3d);
6944 DestroyWindow(window);
6947 static void test_writeonly_resource(void)
6949 IDirect3D8 *d3d;
6950 IDirect3DDevice8 *device;
6951 IDirect3DVertexBuffer8 *buffer;
6952 ULONG refcount;
6953 HWND window;
6954 HRESULT hr;
6955 BYTE *ptr;
6956 static const struct
6958 struct vec3 pos;
6960 quad[] =
6962 {{-1.0f, -1.0f, 0.0f}},
6963 {{-1.0f, 1.0f, 0.0f}},
6964 {{ 1.0f, -1.0f, 0.0f}},
6965 {{ 1.0f, 1.0f, 0.0f}}
6968 window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW,
6969 0, 0, 640, 480, NULL, NULL, NULL, NULL);
6970 d3d = Direct3DCreate8(D3D_SDK_VERSION);
6971 ok(!!d3d, "Failed to create a D3D object.\n");
6972 if (!(device = create_device(d3d, window, NULL)))
6974 skip("Failed to create a D3D device, skipping tests.\n");
6975 IDirect3D8_Release(d3d);
6976 DestroyWindow(window);
6977 return;
6980 hr = IDirect3DDevice8_CreateVertexBuffer(device, sizeof(quad),
6981 D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &buffer);
6982 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
6984 hr = IDirect3DVertexBuffer8_Lock(buffer, 0, 0, &ptr, D3DLOCK_DISCARD);
6985 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
6986 memcpy(ptr, quad, sizeof(quad));
6987 hr = IDirect3DVertexBuffer8_Unlock(buffer);
6988 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
6989 hr = IDirect3DDevice8_SetStreamSource(device, 0, buffer, sizeof(*quad));
6990 ok(SUCCEEDED(hr), "Failed to set stream source, hr %#x.\n", hr);
6991 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ);
6992 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
6994 hr = IDirect3DDevice8_BeginScene(device);
6995 ok(SUCCEEDED(hr), "Failed to begin scene %#x\n", hr);
6996 hr = IDirect3DDevice8_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, 0, 2);
6997 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6998 hr = IDirect3DDevice8_EndScene(device);
6999 ok(SUCCEEDED(hr), "Failed to end scene %#x\n", hr);
7001 hr = IDirect3DVertexBuffer8_Lock(buffer, 0, 0, &ptr, 0);
7002 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
7003 ok (!memcmp(ptr, quad, sizeof(quad)), "Got unexpected vertex buffer data.\n");
7004 hr = IDirect3DVertexBuffer8_Unlock(buffer);
7005 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
7007 hr = IDirect3DVertexBuffer8_Lock(buffer, 0, 0, &ptr, D3DLOCK_READONLY);
7008 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
7009 ok (!memcmp(ptr, quad, sizeof(quad)), "Got unexpected vertex buffer data.\n");
7010 hr = IDirect3DVertexBuffer8_Unlock(buffer);
7011 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
7013 refcount = IDirect3DVertexBuffer8_Release(buffer);
7014 ok(!refcount, "Vertex buffer has %u references left.\n", refcount);
7015 refcount = IDirect3DDevice8_Release(device);
7016 ok(!refcount, "Device has %u references left.\n", refcount);
7017 IDirect3D8_Release(d3d);
7018 DestroyWindow(window);
7021 static void test_lost_device(void)
7023 struct device_desc device_desc;
7024 IDirect3DDevice8 *device;
7025 IDirect3D8 *d3d;
7026 ULONG refcount;
7027 HWND window;
7028 HRESULT hr;
7029 BOOL ret;
7031 window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW,
7032 0, 0, 640, 480, NULL, NULL, NULL, NULL);
7033 d3d = Direct3DCreate8(D3D_SDK_VERSION);
7034 ok(!!d3d, "Failed to create a D3D object.\n");
7035 device_desc.device_window = window;
7036 device_desc.width = registry_mode.dmPelsWidth;
7037 device_desc.height = registry_mode.dmPelsHeight;
7038 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
7039 if (!(device = create_device(d3d, window, &device_desc)))
7041 skip("Failed to create a D3D device, skipping tests.\n");
7042 goto done;
7045 hr = IDirect3DDevice8_TestCooperativeLevel(device);
7046 if (hr == D3DERR_DEVICELOST)
7048 win_skip("Broken TestCooperativeLevel(), skipping test.\n");
7049 IDirect3DDevice8_Release(device);
7050 goto done;
7052 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7053 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
7054 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7056 ret = SetForegroundWindow(GetDesktopWindow());
7057 ok(ret, "Failed to set foreground window.\n");
7058 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
7059 ok(hr == D3DERR_DEVICELOST, "Got unexpected hr %#x.\n", hr);
7060 hr = IDirect3DDevice8_TestCooperativeLevel(device);
7061 ok(hr == D3DERR_DEVICELOST, "Got unexpected hr %#x.\n", hr);
7063 ret = ShowWindow(window, SW_RESTORE);
7064 ok(ret, "Failed to restore window.\n");
7065 ret = SetForegroundWindow(window);
7066 ok(ret, "Failed to set foreground window.\n");
7067 hr = IDirect3DDevice8_TestCooperativeLevel(device);
7068 ok(hr == D3DERR_DEVICENOTRESET, "Got unexpected hr %#x.\n", hr);
7069 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
7070 ok(hr == D3DERR_DEVICELOST, "Got unexpected hr %#x.\n", hr);
7072 hr = reset_device(device, &device_desc);
7073 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7074 hr = IDirect3DDevice8_TestCooperativeLevel(device);
7075 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7076 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
7077 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7079 device_desc.flags = 0;
7080 hr = reset_device(device, &device_desc);
7081 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7082 hr = IDirect3DDevice8_TestCooperativeLevel(device);
7083 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7084 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
7085 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7087 ret = SetForegroundWindow(GetDesktopWindow());
7088 ok(ret, "Failed to set foreground window.\n");
7089 hr = IDirect3DDevice8_TestCooperativeLevel(device);
7090 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7091 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
7092 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7094 ret = ShowWindow(window, SW_RESTORE);
7095 ok(ret, "Failed to restore window.\n");
7096 hr = IDirect3DDevice8_TestCooperativeLevel(device);
7097 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7098 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
7099 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7101 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
7102 hr = reset_device(device, &device_desc);
7103 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7104 hr = IDirect3DDevice8_TestCooperativeLevel(device);
7105 todo_wine ok(hr == D3DERR_DEVICELOST, "Got unexpected hr %#x.\n", hr);
7106 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
7107 todo_wine ok(hr == D3DERR_DEVICELOST, "Got unexpected hr %#x.\n", hr);
7109 ret = SetForegroundWindow(GetDesktopWindow());
7110 ok(ret, "Failed to set foreground window.\n");
7111 hr = reset_device(device, &device_desc);
7112 ok(hr == D3DERR_DEVICELOST, "Got unexpected hr %#x.\n", hr);
7113 ret = ShowWindow(window, SW_RESTORE);
7114 ok(ret, "Failed to restore window.\n");
7115 ret = SetForegroundWindow(window);
7116 ok(ret, "Failed to set foreground window.\n");
7117 hr = reset_device(device, &device_desc);
7118 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7120 refcount = IDirect3DDevice8_Release(device);
7121 ok(!refcount, "Device has %u references left.\n", refcount);
7122 done:
7123 IDirect3D8_Release(d3d);
7124 DestroyWindow(window);
7127 static void test_resource_priority(void)
7129 IDirect3DDevice8 *device;
7130 IDirect3DTexture8 *texture;
7131 IDirect3DVertexBuffer8 *buffer;
7132 IDirect3D8 *d3d;
7133 ULONG refcount;
7134 HWND window;
7135 HRESULT hr;
7136 static const struct
7138 D3DPOOL pool;
7139 const char *name;
7140 BOOL can_set_priority;
7142 test_data[] =
7144 {D3DPOOL_DEFAULT, "D3DPOOL_DEFAULT", FALSE},
7145 {D3DPOOL_SYSTEMMEM, "D3DPOOL_SYSTEMMEM", FALSE},
7146 {D3DPOOL_MANAGED, "D3DPOOL_MANAGED", TRUE},
7147 {D3DPOOL_SCRATCH, "D3DPOOL_SCRATCH", FALSE}
7149 unsigned int i;
7150 DWORD priority;
7152 window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW,
7153 0, 0, 640, 480, NULL, NULL, NULL, NULL);
7154 d3d = Direct3DCreate8(D3D_SDK_VERSION);
7155 ok(!!d3d, "Failed to create a D3D object.\n");
7156 if (!(device = create_device(d3d, window, NULL)))
7158 skip("Failed to create a D3D device, skipping tests.\n");
7159 IDirect3D8_Release(d3d);
7160 DestroyWindow(window);
7161 return;
7164 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); i++)
7166 hr = IDirect3DDevice8_CreateTexture(device, 16, 16, 0, 0, D3DFMT_X8R8G8B8,
7167 test_data[i].pool, &texture);
7168 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x, pool %s.\n", hr, test_data[i].name);
7170 priority = IDirect3DTexture8_GetPriority(texture);
7171 ok(priority == 0, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
7172 priority = IDirect3DTexture8_SetPriority(texture, 1);
7173 ok(priority == 0, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
7174 priority = IDirect3DTexture8_GetPriority(texture);
7175 if (test_data[i].can_set_priority)
7177 ok(priority == 1, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
7178 priority = IDirect3DTexture8_SetPriority(texture, 0);
7179 ok(priority == 1, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
7181 else
7182 ok(priority == 0, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
7184 IDirect3DTexture8_Release(texture);
7186 if (test_data[i].pool != D3DPOOL_SCRATCH)
7188 hr = IDirect3DDevice8_CreateVertexBuffer(device, 256, 0, 0,
7189 test_data[i].pool, &buffer);
7190 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x, pool %s.\n", hr, test_data[i].name);
7192 priority = IDirect3DVertexBuffer8_GetPriority(buffer);
7193 ok(priority == 0, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
7194 priority = IDirect3DVertexBuffer8_SetPriority(buffer, 1);
7195 ok(priority == 0, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
7196 priority = IDirect3DVertexBuffer8_GetPriority(buffer);
7197 if (test_data[i].can_set_priority)
7199 ok(priority == 1, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
7200 priority = IDirect3DVertexBuffer8_SetPriority(buffer, 0);
7201 ok(priority == 1, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
7203 else
7204 ok(priority == 0, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
7206 IDirect3DVertexBuffer8_Release(buffer);
7210 refcount = IDirect3DDevice8_Release(device);
7211 ok(!refcount, "Device has %u references left.\n", refcount);
7212 IDirect3D8_Release(d3d);
7213 DestroyWindow(window);
7216 START_TEST(device)
7218 HMODULE d3d8_handle = LoadLibraryA( "d3d8.dll" );
7219 WNDCLASSA wc = {0};
7220 IDirect3D8 *d3d8;
7221 DEVMODEW current_mode;
7223 if (!d3d8_handle)
7225 skip("Could not load d3d8.dll\n");
7226 return;
7229 memset(&current_mode, 0, sizeof(current_mode));
7230 current_mode.dmSize = sizeof(current_mode);
7231 ok(EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &current_mode), "Failed to get display mode.\n");
7232 registry_mode.dmSize = sizeof(registry_mode);
7233 ok(EnumDisplaySettingsW(NULL, ENUM_REGISTRY_SETTINGS, &registry_mode), "Failed to get display mode.\n");
7234 if (current_mode.dmPelsWidth != registry_mode.dmPelsWidth
7235 || current_mode.dmPelsHeight != registry_mode.dmPelsHeight)
7237 skip("Current mode does not match registry mode, skipping test.\n");
7238 return;
7241 wc.lpfnWndProc = DefWindowProcA;
7242 wc.lpszClassName = "d3d8_test_wc";
7243 RegisterClassA(&wc);
7245 ValidateVertexShader = (void *)GetProcAddress(d3d8_handle, "ValidateVertexShader");
7246 ValidatePixelShader = (void *)GetProcAddress(d3d8_handle, "ValidatePixelShader");
7248 if (!(d3d8 = Direct3DCreate8(D3D_SDK_VERSION)))
7250 skip("could not create D3D8\n");
7251 return;
7253 IDirect3D8_Release(d3d8);
7255 test_fpu_setup();
7256 test_display_formats();
7257 test_display_modes();
7258 test_shader_versions();
7259 test_swapchain();
7260 test_refcount();
7261 test_mipmap_levels();
7262 test_cursor();
7263 test_cursor_pos();
7264 test_states();
7265 test_reset();
7266 test_scene();
7267 test_shader();
7268 test_limits();
7269 test_lights();
7270 test_ApplyStateBlock();
7271 test_render_zero_triangles();
7272 test_depth_stencil_reset();
7273 test_wndproc();
7274 test_wndproc_windowed();
7275 test_depth_stencil_size();
7276 test_window_style();
7277 test_unsupported_shaders();
7278 test_mode_change();
7279 test_device_window_reset();
7280 test_reset_resources();
7281 depth_blit_test();
7282 test_set_rt_vp_scissor();
7283 test_validate_vs();
7284 test_validate_ps();
7285 test_volume_get_container();
7286 test_vb_lock_flags();
7287 test_texture_stage_states();
7288 test_cube_textures();
7289 test_image_surface_pool();
7290 test_surface_get_container();
7291 test_lockrect_invalid();
7292 test_private_data();
7293 test_surface_dimensions();
7294 test_surface_format_null();
7295 test_surface_double_unlock();
7296 test_surface_blocks();
7297 test_set_palette();
7298 test_swvp_buffer();
7299 test_npot_textures();
7300 test_volume_locking();
7301 test_update_volumetexture();
7302 test_create_rt_ds_fail();
7303 test_volume_blocks();
7304 test_lockbox_invalid();
7305 test_pixel_format();
7306 test_begin_end_state_block();
7307 test_shader_constant_apply();
7308 test_resource_type();
7309 test_mipmap_lock();
7310 test_writeonly_resource();
7311 test_lost_device();
7312 test_resource_priority();
7314 UnregisterClassA("d3d8_test_wc", GetModuleHandleA(NULL));