wined3d: Support multiple outputs.
[wine.git] / dlls / d3d8 / tests / device.c
blob4eb1ab65e72d60521240ca196114d5e85fdc0826
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 #include <stdlib.h>
25 #define COBJMACROS
26 #include <initguid.h>
27 #include <d3d8.h>
28 #include "wine/test.h"
29 #include "wine/heap.h"
31 struct vec3
33 float x, y, z;
36 #define CREATE_DEVICE_FULLSCREEN 0x01
37 #define CREATE_DEVICE_FPU_PRESERVE 0x02
38 #define CREATE_DEVICE_SWVP_ONLY 0x04
39 #define CREATE_DEVICE_LOCKABLE_BACKBUFFER 0x08
41 struct device_desc
43 unsigned int adapter_ordinal;
44 HWND device_window;
45 unsigned int width;
46 unsigned int height;
47 DWORD flags;
50 #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
51 #define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
53 static DEVMODEW registry_mode;
55 static HRESULT (WINAPI *ValidateVertexShader)(const DWORD *, const DWORD *, const D3DCAPS8 *, BOOL, char **);
56 static HRESULT (WINAPI *ValidatePixelShader)(const DWORD *, const D3DCAPS8 *, BOOL, char **);
58 static const DWORD simple_vs[] = {0xFFFE0101, /* vs_1_1 */
59 0x00000009, 0xC0010000, 0x90E40000, 0xA0E40000, /* dp4 oPos.x, v0, c0 */
60 0x00000009, 0xC0020000, 0x90E40000, 0xA0E40001, /* dp4 oPos.y, v0, c1 */
61 0x00000009, 0xC0040000, 0x90E40000, 0xA0E40002, /* dp4 oPos.z, v0, c2 */
62 0x00000009, 0xC0080000, 0x90E40000, 0xA0E40003, /* dp4 oPos.w, v0, c3 */
63 0x0000FFFF}; /* END */
64 static const DWORD simple_ps[] = {0xFFFF0101, /* ps_1_1 */
65 0x00000051, 0xA00F0001, 0x3F800000, 0x00000000, 0x00000000, 0x00000000, /* def c1 = 1.0, 0.0, 0.0, 0.0 */
66 0x00000042, 0xB00F0000, /* tex t0 */
67 0x00000008, 0x800F0000, 0xA0E40001, 0xA0E40000, /* dp3 r0, c1, c0 */
68 0x00000005, 0x800F0000, 0x90E40000, 0x80E40000, /* mul r0, v0, r0 */
69 0x00000005, 0x800F0000, 0xB0E40000, 0x80E40000, /* mul r0, t0, r0 */
70 0x0000FFFF}; /* END */
72 static int get_refcount(IUnknown *object)
74 IUnknown_AddRef( object );
75 return IUnknown_Release( object );
78 static void get_virtual_rect(RECT *rect)
80 rect->left = GetSystemMetrics(SM_XVIRTUALSCREEN);
81 rect->top = GetSystemMetrics(SM_YVIRTUALSCREEN);
82 rect->right = rect->left + GetSystemMetrics(SM_CXVIRTUALSCREEN);
83 rect->bottom = rect->top + GetSystemMetrics(SM_CYVIRTUALSCREEN);
86 static HWND create_window(void)
88 RECT r = {0, 0, 640, 480};
90 AdjustWindowRect(&r, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
92 return CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
93 0, 0, r.right - r.left, r.bottom - r.top, NULL, NULL, NULL, NULL);
96 /* try to make sure pending X events have been processed before continuing */
97 static void flush_events(void)
99 MSG msg;
100 int diff = 200;
101 int min_timeout = 100;
102 DWORD time = GetTickCount() + diff;
104 while (diff > 0)
106 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
107 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
108 diff = time - GetTickCount();
112 static BOOL adapter_is_warp(const D3DADAPTER_IDENTIFIER8 *identifier)
114 return !strcmp(identifier->Driver, "d3d10warp.dll");
117 static BOOL equal_mode_rect(const DEVMODEW *mode1, const DEVMODEW *mode2)
119 return mode1->dmPosition.x == mode2->dmPosition.x
120 && mode1->dmPosition.y == mode2->dmPosition.y
121 && mode1->dmPelsWidth == mode2->dmPelsWidth
122 && mode1->dmPelsHeight == mode2->dmPelsHeight;
125 /* Free original_modes after finished using it */
126 static BOOL save_display_modes(DEVMODEW **original_modes, unsigned int *display_count)
128 unsigned int number, size = 2, count = 0, index = 0;
129 DISPLAY_DEVICEW display_device;
130 DEVMODEW *modes, *tmp;
132 if (!(modes = heap_alloc(size * sizeof(*modes))))
133 return FALSE;
135 display_device.cb = sizeof(display_device);
136 while (EnumDisplayDevicesW(NULL, index++, &display_device, 0))
138 /* Skip software devices */
139 if (swscanf(display_device.DeviceName, L"\\\\.\\DISPLAY%u", &number) != 1)
140 continue;
142 if (!(display_device.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP))
143 continue;
145 if (count >= size)
147 size *= 2;
148 if (!(tmp = heap_realloc(modes, size * sizeof(*modes))))
150 heap_free(modes);
151 return FALSE;
153 modes = tmp;
156 memset(&modes[count], 0, sizeof(modes[count]));
157 modes[count].dmSize = sizeof(modes[count]);
158 if (!EnumDisplaySettingsW(display_device.DeviceName, ENUM_CURRENT_SETTINGS, &modes[count]))
160 heap_free(modes);
161 return FALSE;
164 lstrcpyW(modes[count++].dmDeviceName, display_device.DeviceName);
167 *original_modes = modes;
168 *display_count = count;
169 return TRUE;
172 static BOOL restore_display_modes(DEVMODEW *modes, unsigned int count)
174 unsigned int index;
175 LONG ret;
177 for (index = 0; index < count; ++index)
179 ret = ChangeDisplaySettingsExW(modes[index].dmDeviceName, &modes[index], NULL,
180 CDS_UPDATEREGISTRY | CDS_NORESET, NULL);
181 if (ret != DISP_CHANGE_SUCCESSFUL)
182 return FALSE;
184 ret = ChangeDisplaySettingsExW(NULL, NULL, NULL, 0, NULL);
185 return ret == DISP_CHANGE_SUCCESSFUL;
188 static IDirect3DDevice8 *create_device(IDirect3D8 *d3d8, HWND focus_window, const struct device_desc *desc)
190 D3DPRESENT_PARAMETERS present_parameters = {0};
191 unsigned int adapter_ordinal;
192 IDirect3DDevice8 *device;
193 DWORD behavior_flags = D3DCREATE_HARDWARE_VERTEXPROCESSING;
195 adapter_ordinal = D3DADAPTER_DEFAULT;
196 present_parameters.BackBufferWidth = 640;
197 present_parameters.BackBufferHeight = 480;
198 present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
199 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
200 present_parameters.hDeviceWindow = focus_window;
201 present_parameters.Windowed = TRUE;
202 present_parameters.EnableAutoDepthStencil = TRUE;
203 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
205 if (desc)
207 adapter_ordinal = desc->adapter_ordinal;
208 present_parameters.BackBufferWidth = desc->width;
209 present_parameters.BackBufferHeight = desc->height;
210 present_parameters.hDeviceWindow = desc->device_window;
211 present_parameters.Windowed = !(desc->flags & CREATE_DEVICE_FULLSCREEN);
212 if (desc->flags & CREATE_DEVICE_LOCKABLE_BACKBUFFER)
213 present_parameters.Flags |= D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
214 if (desc->flags & CREATE_DEVICE_SWVP_ONLY)
215 behavior_flags = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
216 if (desc->flags & CREATE_DEVICE_FPU_PRESERVE)
217 behavior_flags |= D3DCREATE_FPU_PRESERVE;
220 if (SUCCEEDED(IDirect3D8_CreateDevice(d3d8, adapter_ordinal, D3DDEVTYPE_HAL, focus_window,
221 behavior_flags, &present_parameters, &device)))
222 return device;
224 present_parameters.AutoDepthStencilFormat = D3DFMT_D16;
225 if (SUCCEEDED(IDirect3D8_CreateDevice(d3d8, adapter_ordinal, D3DDEVTYPE_HAL, focus_window,
226 behavior_flags, &present_parameters, &device)))
227 return device;
229 if (desc && desc->flags & CREATE_DEVICE_SWVP_ONLY)
230 return NULL;
231 behavior_flags ^= (D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_SOFTWARE_VERTEXPROCESSING);
233 if (SUCCEEDED(IDirect3D8_CreateDevice(d3d8, adapter_ordinal, D3DDEVTYPE_HAL, focus_window,
234 behavior_flags, &present_parameters, &device)))
235 return device;
237 return NULL;
240 static HRESULT reset_device(IDirect3DDevice8 *device, const struct device_desc *desc)
242 D3DPRESENT_PARAMETERS present_parameters = {0};
244 present_parameters.BackBufferWidth = 640;
245 present_parameters.BackBufferHeight = 480;
246 present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
247 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
248 present_parameters.hDeviceWindow = NULL;
249 present_parameters.Windowed = TRUE;
250 present_parameters.EnableAutoDepthStencil = TRUE;
251 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
253 if (desc)
255 present_parameters.BackBufferWidth = desc->width;
256 present_parameters.BackBufferHeight = desc->height;
257 present_parameters.hDeviceWindow = desc->device_window;
258 present_parameters.Windowed = !(desc->flags & CREATE_DEVICE_FULLSCREEN);
261 return IDirect3DDevice8_Reset(device, &present_parameters);
264 #define CHECK_CALL(r,c,d,rc) \
265 if (SUCCEEDED(r)) {\
266 int tmp1 = get_refcount( (IUnknown *)d ); \
267 int rc_new = rc; \
268 ok(tmp1 == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, tmp1); \
269 } else {\
270 trace("%s failed: %#08x\n", c, r); \
273 #define CHECK_RELEASE(obj,d,rc) \
274 if (obj) { \
275 int tmp1, rc_new = rc; \
276 IUnknown_Release( (IUnknown*)obj ); \
277 tmp1 = get_refcount( (IUnknown *)d ); \
278 ok(tmp1 == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, tmp1); \
281 #define CHECK_REFCOUNT(obj,rc) \
283 int rc_new = rc; \
284 int count = get_refcount( (IUnknown *)obj ); \
285 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
288 #define CHECK_RELEASE_REFCOUNT(obj,rc) \
290 int rc_new = rc; \
291 int count = IUnknown_Release( (IUnknown *)obj ); \
292 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
295 #define CHECK_ADDREF_REFCOUNT(obj,rc) \
297 int rc_new = rc; \
298 int count = IUnknown_AddRef( (IUnknown *)obj ); \
299 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
302 #define CHECK_SURFACE_CONTAINER(obj,iid,expected) \
304 void *container_ptr = (void *)0x1337c0d3; \
305 hr = IDirect3DSurface8_GetContainer(obj, &iid, &container_ptr); \
306 ok(SUCCEEDED(hr) && container_ptr == expected, "GetContainer returned: hr %#08x, container_ptr %p. " \
307 "Expected hr %#08x, container_ptr %p\n", hr, container_ptr, S_OK, expected); \
308 if (container_ptr && container_ptr != (void *)0x1337c0d3) IUnknown_Release((IUnknown *)container_ptr); \
311 static void check_mipmap_levels(IDirect3DDevice8 *device, UINT width, UINT height, UINT count)
313 IDirect3DBaseTexture8* texture = NULL;
314 HRESULT hr = IDirect3DDevice8_CreateTexture( device, width, height, 0, 0,
315 D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, (IDirect3DTexture8**) &texture );
317 if (SUCCEEDED(hr)) {
318 DWORD levels = IDirect3DBaseTexture8_GetLevelCount(texture);
319 ok(levels == count, "Invalid level count. Expected %d got %u\n", count, levels);
320 } else
321 trace("CreateTexture failed: %#08x\n", hr);
323 if (texture) IDirect3DBaseTexture8_Release( texture );
326 static void test_mipmap_levels(void)
328 IDirect3DDevice8 *device;
329 IDirect3D8 *d3d;
330 ULONG refcount;
331 HWND window;
333 window = create_window();
334 ok(!!window, "Failed to create a window.\n");
335 d3d = Direct3DCreate8(D3D_SDK_VERSION);
336 ok(!!d3d, "Failed to create a D3D object.\n");
337 if (!(device = create_device(d3d, window, NULL)))
339 skip("Failed to create a 3D device, skipping test.\n");
340 goto cleanup;
343 check_mipmap_levels(device, 32, 32, 6);
344 check_mipmap_levels(device, 256, 1, 9);
345 check_mipmap_levels(device, 1, 256, 9);
346 check_mipmap_levels(device, 1, 1, 1);
348 refcount = IDirect3DDevice8_Release(device);
349 ok(!refcount, "Device has %u references left.\n", refcount);
350 cleanup:
351 IDirect3D8_Release(d3d);
352 DestroyWindow(window);
355 static void test_swapchain(void)
357 IDirect3DSwapChain8 *swapchain1;
358 IDirect3DSwapChain8 *swapchain2;
359 IDirect3DSwapChain8 *swapchain3;
360 IDirect3DSurface8 *backbuffer, *stereo_buffer;
361 D3DPRESENT_PARAMETERS d3dpp;
362 IDirect3DDevice8 *device;
363 IDirect3D8 *d3d;
364 ULONG refcount;
365 HWND window, window2;
366 HRESULT hr;
367 struct device_desc device_desc;
369 window = create_window();
370 ok(!!window, "Failed to create a window.\n");
371 window2 = create_window();
372 ok(!!window2, "Failed to create a window.\n");
373 d3d = Direct3DCreate8(D3D_SDK_VERSION);
374 ok(!!d3d, "Failed to create a D3D object.\n");
375 if (!(device = create_device(d3d, window, NULL)))
377 skip("Failed to create a 3D device, skipping test.\n");
378 goto cleanup;
381 backbuffer = (void *)0xdeadbeef;
382 /* IDirect3DDevice8::GetBackBuffer crashes if a NULL output pointer is passed. */
383 hr = IDirect3DDevice8_GetBackBuffer(device, 1, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
384 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
385 ok(!backbuffer, "The back buffer pointer is %p, expected NULL.\n", backbuffer);
387 hr = IDirect3DDevice8_GetBackBuffer(device, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
388 ok(SUCCEEDED(hr), "Failed to get back buffer, hr %#x.\n", hr);
389 IDirect3DSurface8_Release(backbuffer);
391 /* The back buffer type value is ignored. */
392 hr = IDirect3DDevice8_GetBackBuffer(device, 0, D3DBACKBUFFER_TYPE_LEFT, &stereo_buffer);
393 ok(SUCCEEDED(hr), "Failed to get the back buffer, hr %#x.\n", hr);
394 ok(stereo_buffer == backbuffer, "Expected left back buffer = %p, got %p.\n", backbuffer, stereo_buffer);
395 IDirect3DSurface8_Release(stereo_buffer);
396 hr = IDirect3DDevice8_GetBackBuffer(device, 0, D3DBACKBUFFER_TYPE_RIGHT, &stereo_buffer);
397 ok(SUCCEEDED(hr), "Failed to get the back buffer, hr %#x.\n", hr);
398 ok(stereo_buffer == backbuffer, "Expected right back buffer = %p, got %p.\n", backbuffer, stereo_buffer);
399 IDirect3DSurface8_Release(stereo_buffer);
400 hr = IDirect3DDevice8_GetBackBuffer(device, 0, (D3DBACKBUFFER_TYPE)0xdeadbeef, &stereo_buffer);
401 ok(SUCCEEDED(hr), "Failed to get the back buffer, hr %#x.\n", hr);
402 ok(stereo_buffer == backbuffer, "Expected unknown buffer = %p, got %p.\n", backbuffer, stereo_buffer);
403 IDirect3DSurface8_Release(stereo_buffer);
405 memset(&d3dpp, 0, sizeof(d3dpp));
406 d3dpp.Windowed = TRUE;
407 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
408 d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
410 /* Create a bunch of swapchains */
411 d3dpp.BackBufferCount = 0;
412 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain1);
413 ok(SUCCEEDED(hr), "Failed to create a swapchain (%#08x)\n", hr);
414 ok(d3dpp.BackBufferCount == 1, "The back buffer count in the presentparams struct is %d\n", d3dpp.BackBufferCount);
416 d3dpp.BackBufferCount = 1;
417 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain2);
418 ok(SUCCEEDED(hr), "Failed to create a swapchain (%#08x)\n", hr);
420 d3dpp.BackBufferCount = 2;
421 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain3);
422 ok(SUCCEEDED(hr), "Failed to create a swapchain (%#08x)\n", hr);
423 if(SUCCEEDED(hr)) {
424 /* Swapchain 3, created with backbuffercount 2 */
425 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 0, 0, NULL);
426 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
428 backbuffer = (void *) 0xdeadbeef;
429 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 0, 0, &backbuffer);
430 ok(SUCCEEDED(hr), "Failed to get the 1st back buffer (%#08x)\n", hr);
431 ok(backbuffer != NULL && backbuffer != (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer);
432 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
434 /* The back buffer type value is ignored. */
435 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 0, D3DBACKBUFFER_TYPE_LEFT, &stereo_buffer);
436 ok(SUCCEEDED(hr), "Failed to get the back buffer, hr %#x.\n", hr);
437 ok(stereo_buffer == backbuffer, "Expected left back buffer = %p, got %p.\n", backbuffer, stereo_buffer);
438 IDirect3DSurface8_Release(stereo_buffer);
439 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 0, D3DBACKBUFFER_TYPE_RIGHT, &stereo_buffer);
440 ok(SUCCEEDED(hr), "Failed to get the back buffer, hr %#x.\n", hr);
441 ok(stereo_buffer == backbuffer, "Expected right back buffer = %p, got %p.\n", backbuffer, stereo_buffer);
442 IDirect3DSurface8_Release(stereo_buffer);
443 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 0, (D3DBACKBUFFER_TYPE)0xdeadbeef, &stereo_buffer);
444 ok(SUCCEEDED(hr), "Failed to get the back buffer, hr %#x.\n", hr);
445 ok(stereo_buffer == backbuffer, "Expected unknown buffer = %p, got %p.\n", backbuffer, stereo_buffer);
446 IDirect3DSurface8_Release(stereo_buffer);
448 backbuffer = (void *) 0xdeadbeef;
449 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 1, 0, &backbuffer);
450 ok(SUCCEEDED(hr), "Failed to get the 2nd back buffer (%#08x)\n", hr);
451 ok(backbuffer != NULL && backbuffer != (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer);
452 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
454 backbuffer = (void *) 0xdeadbeef;
455 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 2, 0, &backbuffer);
456 ok(hr == D3DERR_INVALIDCALL, "GetBackBuffer returned %#08x\n", hr);
457 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
458 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
460 backbuffer = (void *) 0xdeadbeef;
461 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 3, 0, &backbuffer);
462 ok(FAILED(hr), "Failed to get the back buffer (%#08x)\n", hr);
463 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
464 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
467 /* Check the back buffers of the swapchains */
468 /* Swapchain 1, created with backbuffercount 0 */
469 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain1, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
470 ok(SUCCEEDED(hr), "Failed to get the back buffer (%#08x)\n", hr);
471 ok(backbuffer != NULL, "The back buffer is NULL (%#08x)\n", hr);
472 if(backbuffer) IDirect3DSurface8_Release(backbuffer);
474 backbuffer = (void *) 0xdeadbeef;
475 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain1, 1, 0, &backbuffer);
476 ok(FAILED(hr), "Failed to get the back buffer (%#08x)\n", hr);
477 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
478 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
480 /* Swapchain 2 - created with backbuffercount 1 */
481 backbuffer = (void *) 0xdeadbeef;
482 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain2, 0, 0, &backbuffer);
483 ok(SUCCEEDED(hr), "Failed to get the back buffer (%#08x)\n", hr);
484 ok(backbuffer != NULL && backbuffer != (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer);
485 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
487 backbuffer = (void *) 0xdeadbeef;
488 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain2, 1, 0, &backbuffer);
489 ok(hr == D3DERR_INVALIDCALL, "GetBackBuffer returned %#08x\n", hr);
490 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
491 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
493 backbuffer = (void *) 0xdeadbeef;
494 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain2, 2, 0, &backbuffer);
495 ok(FAILED(hr), "Failed to get the back buffer (%#08x)\n", hr);
496 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
497 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
499 IDirect3DSwapChain8_Release(swapchain3);
500 IDirect3DSwapChain8_Release(swapchain2);
501 IDirect3DSwapChain8_Release(swapchain1);
503 d3dpp.Windowed = FALSE;
504 d3dpp.hDeviceWindow = window;
505 d3dpp.BackBufferCount = 1;
506 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain1);
507 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x\n", hr);
508 d3dpp.hDeviceWindow = window2;
509 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain1);
510 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x\n", hr);
512 device_desc.width = registry_mode.dmPelsWidth;
513 device_desc.height = registry_mode.dmPelsHeight;
514 device_desc.device_window = window;
515 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
516 hr = reset_device(device, &device_desc);
517 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
519 d3dpp.hDeviceWindow = window;
520 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain1);
521 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x\n", hr);
522 d3dpp.hDeviceWindow = window2;
523 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain1);
524 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x\n", hr);
525 d3dpp.Windowed = TRUE;
526 d3dpp.hDeviceWindow = window;
527 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain1);
528 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x\n", hr);
529 d3dpp.hDeviceWindow = window2;
530 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain1);
531 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x\n", hr);
533 refcount = IDirect3DDevice8_Release(device);
534 ok(!refcount, "Device has %u references left.\n", refcount);
535 cleanup:
536 IDirect3D8_Release(d3d);
537 DestroyWindow(window2);
538 DestroyWindow(window);
541 static void test_refcount(void)
543 IDirect3DVertexBuffer8 *pVertexBuffer = NULL;
544 IDirect3DIndexBuffer8 *pIndexBuffer = NULL;
545 DWORD dVertexShader = -1;
546 DWORD dPixelShader = -1;
547 IDirect3DCubeTexture8 *pCubeTexture = NULL;
548 IDirect3DTexture8 *pTexture = NULL;
549 IDirect3DVolumeTexture8 *pVolumeTexture = NULL;
550 IDirect3DVolume8 *pVolumeLevel = NULL;
551 IDirect3DSurface8 *pStencilSurface = NULL;
552 IDirect3DSurface8 *pImageSurface = NULL;
553 IDirect3DSurface8 *pRenderTarget = NULL;
554 IDirect3DSurface8 *pRenderTarget2 = NULL;
555 IDirect3DSurface8 *pRenderTarget3 = NULL;
556 IDirect3DSurface8 *pTextureLevel = NULL;
557 IDirect3DSurface8 *pBackBuffer = NULL;
558 DWORD dStateBlock = -1;
559 IDirect3DSwapChain8 *pSwapChain = NULL;
560 D3DCAPS8 caps;
561 D3DPRESENT_PARAMETERS d3dpp;
562 IDirect3DDevice8 *device = NULL;
563 ULONG refcount = 0, tmp;
564 IDirect3D8 *d3d, *d3d2;
565 HWND window;
566 HRESULT hr;
568 DWORD decl[] =
570 D3DVSD_STREAM(0),
571 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
572 D3DVSD_REG(D3DVSDE_DIFFUSE, D3DVSDT_D3DCOLOR), /* D3DVSDE_DIFFUSE, Register v5 */
573 D3DVSD_END()
576 window = create_window();
577 ok(!!window, "Failed to create a window.\n");
578 d3d = Direct3DCreate8(D3D_SDK_VERSION);
579 ok(!!d3d, "Failed to create a D3D object.\n");
581 CHECK_REFCOUNT(d3d, 1);
583 if (!(device = create_device(d3d, window, NULL)))
585 skip("Failed to create a 3D device, skipping test.\n");
586 goto cleanup;
589 IDirect3DDevice8_GetDeviceCaps(device, &caps);
591 refcount = get_refcount((IUnknown *)device);
592 ok(refcount == 1, "Invalid device RefCount %d\n", refcount);
594 CHECK_REFCOUNT(d3d, 2);
596 hr = IDirect3DDevice8_GetDirect3D(device, &d3d2);
597 CHECK_CALL(hr, "GetDirect3D", device, refcount);
599 ok(d3d2 == d3d, "Expected IDirect3D8 pointers to be equal.\n");
600 CHECK_REFCOUNT(d3d, 3);
601 CHECK_RELEASE_REFCOUNT(d3d, 2);
604 * Check refcount of implicit surfaces. Findings:
605 * - the container is the device
606 * - they hold a reference to the device
607 * - they are created with a refcount of 0 (Get/Release returns original refcount)
608 * - they are not freed if refcount reaches 0.
609 * - the refcount is not forwarded to the container.
611 hr = IDirect3DDevice8_GetRenderTarget(device, &pRenderTarget);
612 CHECK_CALL(hr, "GetRenderTarget", device, ++refcount);
613 if (pRenderTarget)
615 CHECK_SURFACE_CONTAINER(pRenderTarget, IID_IDirect3DDevice8, device);
616 CHECK_REFCOUNT(pRenderTarget, 1);
618 CHECK_ADDREF_REFCOUNT(pRenderTarget, 2);
619 CHECK_REFCOUNT(device, refcount);
620 CHECK_RELEASE_REFCOUNT(pRenderTarget, 1);
621 CHECK_REFCOUNT(device, refcount);
623 hr = IDirect3DDevice8_GetRenderTarget(device, &pRenderTarget);
624 CHECK_CALL(hr, "GetRenderTarget", device, refcount);
625 CHECK_REFCOUNT(pRenderTarget, 2);
626 CHECK_RELEASE_REFCOUNT( pRenderTarget, 1);
627 CHECK_RELEASE_REFCOUNT( pRenderTarget, 0);
628 CHECK_REFCOUNT(device, --refcount);
630 /* The render target is released with the device, so AddRef with refcount=0 is fine here. */
631 CHECK_ADDREF_REFCOUNT(pRenderTarget, 1);
632 CHECK_REFCOUNT(device, ++refcount);
633 CHECK_RELEASE_REFCOUNT(pRenderTarget, 0);
634 CHECK_REFCOUNT(device, --refcount);
635 CHECK_RELEASE_REFCOUNT(pRenderTarget, 0);
636 CHECK_RELEASE_REFCOUNT(pRenderTarget, 0);
639 /* Render target and back buffer are identical. */
640 hr = IDirect3DDevice8_GetBackBuffer(device, 0, 0, &pBackBuffer);
641 CHECK_CALL(hr, "GetBackBuffer", device, ++refcount);
642 if (pBackBuffer)
644 CHECK_RELEASE_REFCOUNT(pBackBuffer, 0);
645 ok(pRenderTarget == pBackBuffer, "RenderTarget=%p and BackBuffer=%p should be the same.\n",
646 pRenderTarget, pBackBuffer);
647 CHECK_RELEASE_REFCOUNT(pBackBuffer, 0);
648 CHECK_RELEASE_REFCOUNT(pBackBuffer, 0);
649 pBackBuffer = NULL;
651 CHECK_REFCOUNT(device, --refcount);
653 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &pStencilSurface);
654 CHECK_CALL(hr, "GetDepthStencilSurface", device, ++refcount);
655 if (pStencilSurface)
657 CHECK_SURFACE_CONTAINER(pStencilSurface, IID_IDirect3DDevice8, device);
658 CHECK_REFCOUNT(pStencilSurface, 1);
660 CHECK_ADDREF_REFCOUNT(pStencilSurface, 2);
661 CHECK_REFCOUNT(device, refcount);
662 CHECK_RELEASE_REFCOUNT(pStencilSurface, 1);
663 CHECK_REFCOUNT(device, refcount);
665 CHECK_RELEASE_REFCOUNT( pStencilSurface, 0);
666 CHECK_REFCOUNT(device, --refcount);
668 /* The stencil surface is released with the device, so AddRef with refcount=0 is fine here. */
669 CHECK_ADDREF_REFCOUNT(pStencilSurface, 1);
670 CHECK_REFCOUNT(device, ++refcount);
671 CHECK_RELEASE_REFCOUNT(pStencilSurface, 0);
672 CHECK_REFCOUNT(device, --refcount);
673 CHECK_RELEASE_REFCOUNT(pStencilSurface, 0);
674 CHECK_RELEASE_REFCOUNT(pStencilSurface, 0);
675 pStencilSurface = NULL;
678 /* Buffers */
679 hr = IDirect3DDevice8_CreateIndexBuffer(device, 16, 0, D3DFMT_INDEX32, D3DPOOL_DEFAULT, &pIndexBuffer);
680 CHECK_CALL(hr, "CreateIndexBuffer", device, ++refcount);
681 if(pIndexBuffer)
683 tmp = get_refcount( (IUnknown *)pIndexBuffer );
685 hr = IDirect3DDevice8_SetIndices(device, pIndexBuffer, 0);
686 CHECK_CALL( hr, "SetIndices", pIndexBuffer, tmp);
687 hr = IDirect3DDevice8_SetIndices(device, NULL, 0);
688 CHECK_CALL( hr, "SetIndices", pIndexBuffer, tmp);
691 hr = IDirect3DDevice8_CreateVertexBuffer(device, 16, 0, D3DFVF_XYZ, D3DPOOL_DEFAULT, &pVertexBuffer);
692 CHECK_CALL(hr, "CreateVertexBuffer", device, ++refcount);
693 if(pVertexBuffer)
695 IDirect3DVertexBuffer8 *pVBuf = (void*)~0;
696 UINT stride = ~0;
698 tmp = get_refcount( (IUnknown *)pVertexBuffer );
700 hr = IDirect3DDevice8_SetStreamSource(device, 0, pVertexBuffer, 3 * sizeof(float));
701 CHECK_CALL( hr, "SetStreamSource", pVertexBuffer, tmp);
702 hr = IDirect3DDevice8_SetStreamSource(device, 0, NULL, 0);
703 CHECK_CALL( hr, "SetStreamSource", pVertexBuffer, tmp);
705 hr = IDirect3DDevice8_GetStreamSource(device, 0, &pVBuf, &stride);
706 ok(SUCCEEDED(hr), "GetStreamSource did not succeed with NULL stream!\n");
707 ok(pVBuf==NULL, "pVBuf not NULL (%p)!\n", pVBuf);
708 ok(stride==3*sizeof(float), "stride not 3 floats (got %u)!\n", stride);
711 /* Shaders */
712 hr = IDirect3DDevice8_CreateVertexShader(device, decl, simple_vs, &dVertexShader, 0);
713 CHECK_CALL(hr, "CreateVertexShader", device, refcount);
714 if (caps.PixelShaderVersion >= D3DPS_VERSION(1, 0))
716 hr = IDirect3DDevice8_CreatePixelShader(device, simple_ps, &dPixelShader);
717 CHECK_CALL(hr, "CreatePixelShader", device, refcount);
719 /* Textures */
720 hr = IDirect3DDevice8_CreateTexture(device, 32, 32, 3, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pTexture);
721 CHECK_CALL(hr, "CreateTexture", device, ++refcount);
722 if (pTexture)
724 tmp = get_refcount( (IUnknown *)pTexture );
726 /* SetTexture should not increase refcounts */
727 hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *) pTexture);
728 CHECK_CALL( hr, "SetTexture", pTexture, tmp);
729 hr = IDirect3DDevice8_SetTexture(device, 0, NULL);
730 CHECK_CALL( hr, "SetTexture", pTexture, tmp);
732 /* This should not increment device refcount */
733 hr = IDirect3DTexture8_GetSurfaceLevel( pTexture, 1, &pTextureLevel );
734 CHECK_CALL(hr, "GetSurfaceLevel", device, refcount);
735 /* But should increment texture's refcount */
736 CHECK_REFCOUNT( pTexture, tmp+1 );
737 /* Because the texture and surface refcount are identical */
738 if (pTextureLevel)
740 CHECK_REFCOUNT ( pTextureLevel, tmp+1 );
741 CHECK_ADDREF_REFCOUNT ( pTextureLevel, tmp+2 );
742 CHECK_REFCOUNT ( pTexture , tmp+2 );
743 CHECK_RELEASE_REFCOUNT( pTextureLevel, tmp+1 );
744 CHECK_REFCOUNT ( pTexture , tmp+1 );
745 CHECK_RELEASE_REFCOUNT( pTexture , tmp );
746 CHECK_REFCOUNT ( pTextureLevel, tmp );
749 if(caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP)
751 hr = IDirect3DDevice8_CreateCubeTexture(device, 32, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pCubeTexture);
752 CHECK_CALL(hr, "CreateCubeTexture", device, ++refcount);
754 else
756 skip("Cube textures not supported\n");
758 if(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP)
760 hr = IDirect3DDevice8_CreateVolumeTexture(device, 32, 32, 2, 0, 0,
761 D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pVolumeTexture);
762 CHECK_CALL(hr, "CreateVolumeTexture", device, ++refcount);
764 else
766 skip("Volume textures not supported\n");
769 if (pVolumeTexture)
771 tmp = get_refcount( (IUnknown *)pVolumeTexture );
773 /* This should not increment device refcount */
774 hr = IDirect3DVolumeTexture8_GetVolumeLevel(pVolumeTexture, 0, &pVolumeLevel);
775 CHECK_CALL(hr, "GetVolumeLevel", device, refcount);
776 /* But should increment volume texture's refcount */
777 CHECK_REFCOUNT( pVolumeTexture, tmp+1 );
778 /* Because the volume texture and volume refcount are identical */
779 if (pVolumeLevel)
781 CHECK_REFCOUNT ( pVolumeLevel , tmp+1 );
782 CHECK_ADDREF_REFCOUNT ( pVolumeLevel , tmp+2 );
783 CHECK_REFCOUNT ( pVolumeTexture, tmp+2 );
784 CHECK_RELEASE_REFCOUNT( pVolumeLevel , tmp+1 );
785 CHECK_REFCOUNT ( pVolumeTexture, tmp+1 );
786 CHECK_RELEASE_REFCOUNT( pVolumeTexture, tmp );
787 CHECK_REFCOUNT ( pVolumeLevel , tmp );
790 /* Surfaces */
791 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 32, 32,
792 D3DFMT_D16, D3DMULTISAMPLE_NONE, &pStencilSurface);
793 CHECK_CALL(hr, "CreateDepthStencilSurface", device, ++refcount);
794 CHECK_REFCOUNT( pStencilSurface, 1);
795 hr = IDirect3DDevice8_CreateImageSurface(device, 32, 32,
796 D3DFMT_X8R8G8B8, &pImageSurface);
797 CHECK_CALL(hr, "CreateImageSurface", device, ++refcount);
798 CHECK_REFCOUNT( pImageSurface, 1);
799 hr = IDirect3DDevice8_CreateRenderTarget(device, 32, 32,
800 D3DFMT_X8R8G8B8, D3DMULTISAMPLE_NONE, TRUE, &pRenderTarget3);
801 CHECK_CALL(hr, "CreateRenderTarget", device, ++refcount);
802 CHECK_REFCOUNT( pRenderTarget3, 1);
803 /* Misc */
804 hr = IDirect3DDevice8_CreateStateBlock(device, D3DSBT_ALL, &dStateBlock);
805 CHECK_CALL(hr, "CreateStateBlock", device, refcount);
807 memset(&d3dpp, 0, sizeof(d3dpp));
808 d3dpp.Windowed = TRUE;
809 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
810 d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
811 d3dpp.EnableAutoDepthStencil = TRUE;
812 d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
813 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &pSwapChain);
814 CHECK_CALL(hr, "CreateAdditionalSwapChain", device, ++refcount);
815 if(pSwapChain)
817 /* check implicit back buffer */
818 hr = IDirect3DSwapChain8_GetBackBuffer(pSwapChain, 0, 0, &pBackBuffer);
819 CHECK_CALL(hr, "GetBackBuffer", device, ++refcount);
820 CHECK_REFCOUNT( pSwapChain, 1);
821 if(pBackBuffer)
823 CHECK_SURFACE_CONTAINER(pBackBuffer, IID_IDirect3DDevice8, device);
824 CHECK_REFCOUNT( pBackBuffer, 1);
825 CHECK_RELEASE_REFCOUNT( pBackBuffer, 0);
826 CHECK_REFCOUNT(device, --refcount);
828 /* The back buffer is released with the swapchain, so AddRef with refcount=0 is fine here. */
829 CHECK_ADDREF_REFCOUNT(pBackBuffer, 1);
830 CHECK_REFCOUNT(device, ++refcount);
831 CHECK_RELEASE_REFCOUNT(pBackBuffer, 0);
832 CHECK_REFCOUNT(device, --refcount);
833 CHECK_RELEASE_REFCOUNT(pBackBuffer, 0);
834 CHECK_RELEASE_REFCOUNT(pBackBuffer, 0);
835 pBackBuffer = NULL;
837 CHECK_REFCOUNT( pSwapChain, 1);
840 if(pVertexBuffer)
842 BYTE *data;
843 /* Vertex buffers can be locked multiple times */
844 hr = IDirect3DVertexBuffer8_Lock(pVertexBuffer, 0, 0, &data, 0);
845 ok(hr == D3D_OK, "IDirect3DVertexBuffer8::Lock failed with %#08x\n", hr);
846 hr = IDirect3DVertexBuffer8_Lock(pVertexBuffer, 0, 0, &data, 0);
847 ok(hr == D3D_OK, "IDirect3DVertexBuffer8::Lock failed with %#08x\n", hr);
848 hr = IDirect3DVertexBuffer8_Unlock(pVertexBuffer);
849 ok(hr == D3D_OK, "IDirect3DVertexBuffer8::Unlock failed with %#08x\n", hr);
850 hr = IDirect3DVertexBuffer8_Unlock(pVertexBuffer);
851 ok(hr == D3D_OK, "IDirect3DVertexBuffer8::Unlock failed with %#08x\n", hr);
854 /* The implicit render target is not freed if refcount reaches 0.
855 * Otherwise GetRenderTarget would re-allocate it and the pointer would change.*/
856 hr = IDirect3DDevice8_GetRenderTarget(device, &pRenderTarget2);
857 CHECK_CALL(hr, "GetRenderTarget", device, ++refcount);
858 if (pRenderTarget2)
860 CHECK_RELEASE_REFCOUNT(pRenderTarget2, 0);
861 ok(pRenderTarget == pRenderTarget2, "RenderTarget=%p and RenderTarget2=%p should be the same.\n",
862 pRenderTarget, pRenderTarget2);
863 CHECK_REFCOUNT(device, --refcount);
864 CHECK_RELEASE_REFCOUNT(pRenderTarget2, 0);
865 CHECK_RELEASE_REFCOUNT(pRenderTarget2, 0);
866 pRenderTarget2 = NULL;
868 pRenderTarget = NULL;
870 cleanup:
871 CHECK_RELEASE(device, device, --refcount);
873 /* Buffers */
874 CHECK_RELEASE(pVertexBuffer, device, --refcount);
875 CHECK_RELEASE(pIndexBuffer, device, --refcount);
876 /* Shaders */
877 if (dVertexShader != ~0u)
878 IDirect3DDevice8_DeleteVertexShader(device, dVertexShader);
879 if (dPixelShader != ~0u)
880 IDirect3DDevice8_DeletePixelShader(device, dPixelShader);
881 /* Textures */
882 CHECK_RELEASE(pTexture, device, --refcount);
883 CHECK_RELEASE(pCubeTexture, device, --refcount);
884 CHECK_RELEASE(pVolumeTexture, device, --refcount);
885 /* Surfaces */
886 CHECK_RELEASE(pStencilSurface, device, --refcount);
887 CHECK_RELEASE(pImageSurface, device, --refcount);
888 CHECK_RELEASE(pRenderTarget3, device, --refcount);
889 /* Misc */
890 if (dStateBlock != ~0u)
891 IDirect3DDevice8_DeleteStateBlock(device, dStateBlock);
892 /* This will destroy device - cannot check the refcount here */
893 if (pSwapChain)
894 CHECK_RELEASE_REFCOUNT(pSwapChain, 0);
895 CHECK_RELEASE_REFCOUNT(d3d, 0);
896 DestroyWindow(window);
899 static void test_checkdevicemultisampletype(void)
901 IDirect3D8 *d3d;
902 HWND window;
903 HRESULT hr;
905 window = create_window();
906 ok(!!window, "Failed to create a window.\n");
907 d3d = Direct3DCreate8(D3D_SDK_VERSION);
908 ok(!!d3d, "Failed to create a D3D object.\n");
910 if (IDirect3D8_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
911 D3DFMT_X8R8G8B8, TRUE, D3DMULTISAMPLE_2_SAMPLES) == D3DERR_NOTAVAILABLE)
913 skip("Multisampling not supported for D3DFMT_X8R8G8B8, skipping test.\n");
914 goto cleanup;
917 hr = IDirect3D8_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
918 D3DFMT_UNKNOWN, TRUE, D3DMULTISAMPLE_NONE);
919 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
920 hr = IDirect3D8_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
921 65536, TRUE, D3DMULTISAMPLE_NONE);
922 todo_wine ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
924 hr = IDirect3D8_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
925 D3DFMT_X8R8G8B8, TRUE, D3DMULTISAMPLE_NONE);
926 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
927 hr = IDirect3D8_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
928 D3DFMT_X8R8G8B8, FALSE, D3DMULTISAMPLE_NONE);
929 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
931 hr = IDirect3D8_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
932 D3DFMT_X8R8G8B8, TRUE, D3DMULTISAMPLE_2_SAMPLES);
933 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
935 /* We assume D3DMULTISAMPLE_15_SAMPLES is never supported in practice. */
936 hr = IDirect3D8_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
937 D3DFMT_X8R8G8B8, TRUE, D3DMULTISAMPLE_15_SAMPLES);
938 ok(hr == D3DERR_NOTAVAILABLE, "Got unexpected hr %#x.\n", hr);
940 hr = IDirect3D8_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
941 D3DFMT_X8R8G8B8, TRUE, 65536);
942 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
944 hr = IDirect3D8_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
945 D3DFMT_DXT5, TRUE, D3DMULTISAMPLE_2_SAMPLES);
946 ok(hr == D3DERR_NOTAVAILABLE, "Got unexpected hr %#x.\n", hr);
948 cleanup:
949 IDirect3D8_Release(d3d);
950 DestroyWindow(window);
953 static void test_invalid_multisample(void)
955 IDirect3DDevice8 *device;
956 IDirect3DSurface8 *rt;
957 IDirect3D8 *d3d;
958 BOOL available;
959 ULONG refcount;
960 HWND window;
961 HRESULT hr;
963 window = create_window();
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");
968 if (!(device = create_device(d3d, window, NULL)))
970 skip("Failed to create a 3D device, skipping test.\n");
971 goto cleanup;
974 available = SUCCEEDED(IDirect3D8_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
975 D3DFMT_X8R8G8B8, TRUE, D3DMULTISAMPLE_2_SAMPLES));
977 hr = IDirect3DDevice8_CreateRenderTarget(device, 128, 128,
978 D3DFMT_X8R8G8B8, D3DMULTISAMPLE_2_SAMPLES, FALSE, &rt);
979 if (available)
981 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
982 IDirect3DSurface8_Release(rt);
984 else
986 ok(hr == D3DERR_NOTAVAILABLE, "Got unexpected hr %#x.\n", hr);
989 /* We assume D3DMULTISAMPLE_15_SAMPLES is never supported in practice. */
990 available = SUCCEEDED(IDirect3D8_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
991 D3DFMT_X8R8G8B8, TRUE, D3DMULTISAMPLE_15_SAMPLES));
992 hr = IDirect3DDevice8_CreateRenderTarget(device, 128, 128,
993 D3DFMT_X8R8G8B8, D3DMULTISAMPLE_15_SAMPLES, FALSE, &rt);
994 if (available)
996 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
997 IDirect3DSurface8_Release(rt);
999 else
1001 ok(hr == D3DERR_NOTAVAILABLE, "Got unexpected hr %#x.\n", hr);
1004 refcount = IDirect3DDevice8_Release(device);
1005 ok(!refcount, "Device has %u references left.\n", refcount);
1006 cleanup:
1007 IDirect3D8_Release(d3d);
1008 DestroyWindow(window);
1011 static void test_cursor(void)
1013 unsigned int adapter_idx, adapter_count, test_idx;
1014 IDirect3DSurface8 *cursor = NULL;
1015 struct device_desc device_desc;
1016 unsigned int width, height;
1017 IDirect3DDevice8 *device;
1018 HRESULT expected_hr, hr;
1019 D3DDISPLAYMODE mode;
1020 CURSORINFO info;
1021 IDirect3D8 *d3d;
1022 ULONG refcount;
1023 HCURSOR cur;
1024 HWND window;
1025 BOOL ret;
1027 static const DWORD device_flags[] = {0, CREATE_DEVICE_FULLSCREEN};
1028 static const SIZE cursor_sizes[] =
1030 {1, 1},
1031 {2, 4},
1032 {3, 2},
1033 {2, 3},
1034 {6, 6},
1037 window = create_window();
1038 ok(!!window, "Failed to create a window.\n");
1040 ret = SetCursorPos(50, 50);
1041 ok(ret, "Failed to set cursor position.\n");
1042 flush_events();
1044 memset(&info, 0, sizeof(info));
1045 info.cbSize = sizeof(info);
1046 ok(GetCursorInfo(&info), "GetCursorInfo failed\n");
1047 cur = info.hCursor;
1049 d3d = Direct3DCreate8(D3D_SDK_VERSION);
1050 ok(!!d3d, "Failed to create a D3D object.\n");
1051 if (!(device = create_device(d3d, window, NULL)))
1053 skip("Failed to create a 3D device, skipping test.\n");
1054 goto cleanup;
1057 hr = IDirect3DDevice8_CreateImageSurface(device, 32, 32, D3DFMT_A8R8G8B8, &cursor);
1058 ok(SUCCEEDED(hr), "Failed to create cursor surface, hr %#x.\n", hr);
1060 /* Initially hidden */
1061 ret = IDirect3DDevice8_ShowCursor(device, TRUE);
1062 ok(!ret, "IDirect3DDevice8_ShowCursor returned %d\n", ret);
1064 /* Not enabled without a surface*/
1065 ret = IDirect3DDevice8_ShowCursor(device, TRUE);
1066 ok(!ret, "IDirect3DDevice8_ShowCursor returned %d\n", ret);
1068 /* Fails */
1069 hr = IDirect3DDevice8_SetCursorProperties(device, 0, 0, NULL);
1070 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_SetCursorProperties returned %#08x\n", hr);
1072 hr = IDirect3DDevice8_SetCursorProperties(device, 0, 0, cursor);
1073 ok(hr == D3D_OK, "IDirect3DDevice8_SetCursorProperties returned %#08x\n", hr);
1075 IDirect3DSurface8_Release(cursor);
1077 memset(&info, 0, sizeof(info));
1078 info.cbSize = sizeof(info);
1079 ok(GetCursorInfo(&info), "GetCursorInfo failed\n");
1080 ok(info.flags & (CURSOR_SHOWING|CURSOR_SUPPRESSED), "The gdi cursor is hidden (%08x)\n", info.flags);
1081 ok(info.hCursor == cur, "The cursor handle is %p\n", info.hCursor); /* unchanged */
1083 /* Still hidden */
1084 ret = IDirect3DDevice8_ShowCursor(device, TRUE);
1085 ok(!ret, "IDirect3DDevice8_ShowCursor returned %d\n", ret);
1087 /* Enabled now*/
1088 ret = IDirect3DDevice8_ShowCursor(device, TRUE);
1089 ok(ret, "IDirect3DDevice8_ShowCursor returned %d\n", ret);
1091 memset(&info, 0, sizeof(info));
1092 info.cbSize = sizeof(info);
1093 ok(GetCursorInfo(&info), "GetCursorInfo failed\n");
1094 ok(info.flags & (CURSOR_SHOWING|CURSOR_SUPPRESSED), "The gdi cursor is hidden (%08x)\n", info.flags);
1095 ok(info.hCursor != cur, "The cursor handle is %p\n", info.hCursor);
1097 /* Cursor dimensions must all be powers of two */
1098 for (test_idx = 0; test_idx < ARRAY_SIZE(cursor_sizes); ++test_idx)
1100 width = cursor_sizes[test_idx].cx;
1101 height = cursor_sizes[test_idx].cy;
1102 hr = IDirect3DDevice8_CreateImageSurface(device, width, height, D3DFMT_A8R8G8B8, &cursor);
1103 ok(hr == D3D_OK, "Test %u: CreateImageSurface failed, hr %#x.\n", test_idx, hr);
1104 hr = IDirect3DDevice8_SetCursorProperties(device, 0, 0, cursor);
1105 if (width && !(width & (width - 1)) && height && !(height & (height - 1)))
1106 expected_hr = D3D_OK;
1107 else
1108 expected_hr = D3DERR_INVALIDCALL;
1109 ok(hr == expected_hr, "Test %u: Expect SetCursorProperties return %#x, got %#x.\n",
1110 test_idx, expected_hr, hr);
1111 IDirect3DSurface8_Release(cursor);
1114 refcount = IDirect3DDevice8_Release(device);
1115 ok(!refcount, "Device has %u references left.\n", refcount);
1117 /* Cursor dimensions must not exceed adapter display mode */
1118 device_desc.device_window = window;
1119 device_desc.width = 640;
1120 device_desc.height = 480;
1122 adapter_count = IDirect3D8_GetAdapterCount(d3d);
1123 for (adapter_idx = 0; adapter_idx < adapter_count; ++adapter_idx)
1125 for (test_idx = 0; test_idx < ARRAY_SIZE(device_flags); ++test_idx)
1127 device_desc.adapter_ordinal = adapter_idx;
1128 device_desc.flags = device_flags[test_idx];
1129 if (!(device = create_device(d3d, window, &device_desc)))
1131 skip("Adapter %u test %u: Failed to create a D3D device.\n", adapter_idx, test_idx);
1132 break;
1135 hr = IDirect3D8_GetAdapterDisplayMode(d3d, adapter_idx, &mode);
1136 ok(hr == D3D_OK, "Adapter %u test %u: GetAdapterDisplayMode failed, hr %#x.\n",
1137 adapter_idx, test_idx, hr);
1139 /* Find the largest width and height that are powers of two and less than the display mode */
1140 width = 1;
1141 height = 1;
1142 while (width * 2 <= mode.Width)
1143 width *= 2;
1144 while (height * 2 <= mode.Height)
1145 height *= 2;
1147 hr = IDirect3DDevice8_CreateImageSurface(device, width, height, D3DFMT_A8R8G8B8, &cursor);
1148 ok(hr == D3D_OK, "Adapter %u test %u: CreateImageSurface failed, hr %#x.\n",
1149 adapter_idx, test_idx, hr);
1150 hr = IDirect3DDevice8_SetCursorProperties(device, 0, 0, cursor);
1151 ok(hr == D3D_OK, "Adapter %u test %u: SetCursorProperties failed, hr %#x.\n",
1152 adapter_idx, test_idx, hr);
1153 IDirect3DSurface8_Release(cursor);
1155 hr = IDirect3DDevice8_CreateImageSurface(device, width * 2, height, D3DFMT_A8R8G8B8,
1156 &cursor);
1157 ok(hr == D3D_OK, "Adapter %u test %u: CreateImageSurface failed, hr %#x.\n",
1158 adapter_idx, test_idx, hr);
1159 hr = IDirect3DDevice8_SetCursorProperties(device, 0, 0, cursor);
1160 ok(hr == D3DERR_INVALIDCALL,
1161 "Adapter %u test %u: Expect SetCursorProperties return %#x, got %#x.\n",
1162 adapter_idx, test_idx, D3DERR_INVALIDCALL, hr);
1163 IDirect3DSurface8_Release(cursor);
1165 hr = IDirect3DDevice8_CreateImageSurface(device, width, height * 2, D3DFMT_A8R8G8B8,
1166 &cursor);
1167 ok(hr == D3D_OK, "Adapter %u test %u: CreateImageSurface failed, hr %#x.\n",
1168 adapter_idx, test_idx, hr);
1169 hr = IDirect3DDevice8_SetCursorProperties(device, 0, 0, cursor);
1170 ok(hr == D3DERR_INVALIDCALL,
1171 "Adapter %u test %u: Expect SetCursorProperties return %#x, got %#x.\n",
1172 adapter_idx, test_idx, D3DERR_INVALIDCALL, hr);
1173 IDirect3DSurface8_Release(cursor);
1175 refcount = IDirect3DDevice8_Release(device);
1176 ok(!refcount, "Adapter %u: Device has %u references left.\n", adapter_idx, refcount);
1179 cleanup:
1180 IDirect3D8_Release(d3d);
1181 DestroyWindow(window);
1184 static const POINT *expect_pos;
1186 static LRESULT CALLBACK test_cursor_proc(HWND window, UINT message, WPARAM wparam, LPARAM lparam)
1188 if (message == WM_MOUSEMOVE)
1190 if (expect_pos && expect_pos->x && expect_pos->y)
1192 POINT p = {GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam)};
1194 ClientToScreen(window, &p);
1195 if (expect_pos->x == p.x && expect_pos->y == p.y)
1196 ++expect_pos;
1200 return DefWindowProcA(window, message, wparam, lparam);
1203 static void test_cursor_pos(void)
1205 IDirect3DSurface8 *cursor;
1206 IDirect3DDevice8 *device;
1207 WNDCLASSA wc = {0};
1208 IDirect3D8 *d3d8;
1209 UINT refcount;
1210 HWND window;
1211 HRESULT hr;
1212 BOOL ret;
1214 /* Note that we don't check for movement we're not supposed to receive.
1215 * That's because it's hard to distinguish from the user accidentally
1216 * moving the mouse. */
1217 static const POINT points[] =
1219 {50, 50},
1220 {75, 75},
1221 {100, 100},
1222 {125, 125},
1223 {150, 150},
1224 {125, 125},
1225 {150, 150},
1226 {150, 150},
1227 {0, 0},
1230 wc.lpfnWndProc = test_cursor_proc;
1231 wc.lpszClassName = "d3d8_test_cursor_wc";
1232 ok(RegisterClassA(&wc), "Failed to register window class.\n");
1233 window = CreateWindowA("d3d8_test_cursor_wc", "d3d8_test", WS_POPUP | WS_SYSMENU,
1234 0, 0, 320, 240, NULL, NULL, NULL, NULL);
1235 ShowWindow(window, SW_SHOW);
1236 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
1237 ok(!!d3d8, "Failed to create a D3D object.\n");
1239 if (!(device = create_device(d3d8, window, NULL)))
1241 skip("Failed to create a D3D device, skipping tests.\n");
1242 goto done;
1245 hr = IDirect3DDevice8_CreateImageSurface(device, 32, 32, D3DFMT_A8R8G8B8, &cursor);
1246 ok(SUCCEEDED(hr), "Failed to create cursor surface, hr %#x.\n", hr);
1247 hr = IDirect3DDevice8_SetCursorProperties(device, 0, 0, cursor);
1248 ok(SUCCEEDED(hr), "Failed to set cursor properties, hr %#x.\n", hr);
1249 IDirect3DSurface8_Release(cursor);
1250 ret = IDirect3DDevice8_ShowCursor(device, TRUE);
1251 ok(!ret, "Failed to show cursor, hr %#x.\n", ret);
1253 flush_events();
1254 expect_pos = points;
1256 ret = SetCursorPos(50, 50);
1257 ok(ret, "Failed to set cursor position.\n");
1258 flush_events();
1260 IDirect3DDevice8_SetCursorPosition(device, 75, 75, 0);
1261 flush_events();
1262 /* SetCursorPosition() eats duplicates. */
1263 IDirect3DDevice8_SetCursorPosition(device, 75, 75, 0);
1264 flush_events();
1266 ret = SetCursorPos(100, 100);
1267 ok(ret, "Failed to set cursor position.\n");
1268 flush_events();
1269 /* Even if the position was set with SetCursorPos(). */
1270 IDirect3DDevice8_SetCursorPosition(device, 100, 100, 0);
1271 flush_events();
1273 IDirect3DDevice8_SetCursorPosition(device, 125, 125, 0);
1274 flush_events();
1275 ret = SetCursorPos(150, 150);
1276 ok(ret, "Failed to set cursor position.\n");
1277 flush_events();
1278 IDirect3DDevice8_SetCursorPosition(device, 125, 125, 0);
1279 flush_events();
1281 IDirect3DDevice8_SetCursorPosition(device, 150, 150, 0);
1282 flush_events();
1283 /* SetCursorPos() doesn't. */
1284 ret = SetCursorPos(150, 150);
1285 ok(ret, "Failed to set cursor position.\n");
1286 flush_events();
1288 ok(!expect_pos->x && !expect_pos->y, "Didn't receive MOUSEMOVE %u (%d, %d).\n",
1289 (unsigned)(expect_pos - points), expect_pos->x, expect_pos->y);
1291 refcount = IDirect3DDevice8_Release(device);
1292 ok(!refcount, "Device has %u references left.\n", refcount);
1293 done:
1294 DestroyWindow(window);
1295 UnregisterClassA("d3d8_test_cursor_wc", GetModuleHandleA(NULL));
1296 IDirect3D8_Release(d3d8);
1299 static void test_states(void)
1301 IDirect3DDevice8 *device;
1302 IDirect3D8 *d3d;
1303 ULONG refcount;
1304 HWND window;
1305 HRESULT hr;
1307 window = create_window();
1308 ok(!!window, "Failed to create a window.\n");
1309 d3d = Direct3DCreate8(D3D_SDK_VERSION);
1310 ok(!!d3d, "Failed to create a D3D object.\n");
1311 if (!(device = create_device(d3d, window, NULL)))
1313 skip("Failed to create a 3D device, skipping test.\n");
1314 goto cleanup;
1317 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZVISIBLE, TRUE);
1318 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState(D3DRS_ZVISIBLE, TRUE) returned %#08x\n", hr);
1319 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZVISIBLE, FALSE);
1320 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState(D3DRS_ZVISIBLE, FALSE) returned %#08x\n", hr);
1322 refcount = IDirect3DDevice8_Release(device);
1323 ok(!refcount, "Device has %u references left.\n", refcount);
1324 cleanup:
1325 IDirect3D8_Release(d3d);
1326 DestroyWindow(window);
1329 static void test_shader_versions(void)
1331 IDirect3D8 *d3d;
1332 D3DCAPS8 caps;
1333 HRESULT hr;
1335 d3d = Direct3DCreate8(D3D_SDK_VERSION);
1336 ok(!!d3d, "Failed to create a D3D object.\n");
1338 hr = IDirect3D8_GetDeviceCaps(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps);
1339 ok(SUCCEEDED(hr) || hr == D3DERR_NOTAVAILABLE, "Failed to get device caps, hr %#x.\n", hr);
1340 IDirect3D8_Release(d3d);
1341 if (FAILED(hr))
1343 skip("No Direct3D support, skipping test.\n");
1344 return;
1347 ok(caps.VertexShaderVersion <= D3DVS_VERSION(1,1),
1348 "Got unexpected VertexShaderVersion %#x.\n", caps.VertexShaderVersion);
1349 ok(caps.PixelShaderVersion <= D3DPS_VERSION(1,4),
1350 "Got unexpected PixelShaderVersion %#x.\n", caps.PixelShaderVersion);
1353 static void test_display_formats(void)
1355 D3DDEVTYPE device_type = D3DDEVTYPE_HAL;
1356 unsigned int backbuffer, display;
1357 unsigned int windowed, i;
1358 D3DDISPLAYMODE mode;
1359 IDirect3D8 *d3d8;
1360 BOOL should_pass;
1361 BOOL has_modes;
1362 HRESULT hr;
1364 static const struct
1366 const char *name;
1367 D3DFORMAT format;
1368 D3DFORMAT alpha_format;
1369 BOOL display;
1370 BOOL windowed;
1372 formats[] =
1374 {"D3DFMT_R5G6B5", D3DFMT_R5G6B5, 0, TRUE, TRUE},
1375 {"D3DFMT_X1R5G5B5", D3DFMT_X1R5G5B5, D3DFMT_A1R5G5B5, TRUE, TRUE},
1376 {"D3DFMT_A1R5G5B5", D3DFMT_A1R5G5B5, D3DFMT_A1R5G5B5, FALSE, FALSE},
1377 {"D3DFMT_X8R8G8B8", D3DFMT_X8R8G8B8, D3DFMT_A8R8G8B8, TRUE, TRUE},
1378 {"D3DFMT_A8R8G8B8", D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, FALSE, FALSE},
1379 {"D3DFMT_UNKNOWN", D3DFMT_UNKNOWN, 0, FALSE, FALSE},
1382 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
1383 ok(!!d3d8, "Failed to create a D3D object.\n");
1385 for (display = 0; display < ARRAY_SIZE(formats); ++display)
1387 for (i = 0, has_modes = FALSE; SUCCEEDED(IDirect3D8_EnumAdapterModes(d3d8, D3DADAPTER_DEFAULT, i, &mode)); ++i)
1389 if (mode.Format == formats[display].format)
1391 has_modes = TRUE;
1392 break;
1396 for (windowed = 0; windowed <= 1; ++windowed)
1398 for (backbuffer = 0; backbuffer < ARRAY_SIZE(formats); ++backbuffer)
1400 should_pass = FALSE;
1402 if (formats[display].display && (formats[display].windowed || !windowed) && (has_modes || windowed))
1404 D3DFORMAT backbuffer_format;
1406 if (windowed && formats[backbuffer].format == D3DFMT_UNKNOWN)
1407 backbuffer_format = formats[display].format;
1408 else
1409 backbuffer_format = formats[backbuffer].format;
1411 hr = IDirect3D8_CheckDeviceFormat(d3d8, D3DADAPTER_DEFAULT, device_type, formats[display].format,
1412 D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, backbuffer_format);
1413 should_pass = (hr == D3D_OK) && (formats[display].format == formats[backbuffer].format
1414 || (formats[display].alpha_format
1415 && formats[display].alpha_format == formats[backbuffer].alpha_format));
1418 hr = IDirect3D8_CheckDeviceType(d3d8, D3DADAPTER_DEFAULT, device_type,
1419 formats[display].format, formats[backbuffer].format, windowed);
1420 ok(SUCCEEDED(hr) == should_pass || broken(SUCCEEDED(hr) && !has_modes) /* Win8 64-bit */,
1421 "Got unexpected hr %#x for %s / %s, windowed %#x, should_pass %#x.\n",
1422 hr, formats[display].name, formats[backbuffer].name, windowed, should_pass);
1427 IDirect3D8_Release(d3d8);
1430 /* Test adapter display modes */
1431 static void test_display_modes(void)
1433 UINT max_modes, i;
1434 D3DDISPLAYMODE dmode;
1435 IDirect3D8 *d3d;
1436 HRESULT res;
1438 d3d = Direct3DCreate8(D3D_SDK_VERSION);
1439 ok(!!d3d, "Failed to create a D3D object.\n");
1441 max_modes = IDirect3D8_GetAdapterModeCount(d3d, D3DADAPTER_DEFAULT);
1442 ok(max_modes > 0 ||
1443 broken(max_modes == 0), /* VMware */
1444 "GetAdapterModeCount(D3DADAPTER_DEFAULT) returned 0!\n");
1446 for (i = 0; i < max_modes; ++i)
1448 res = IDirect3D8_EnumAdapterModes(d3d, D3DADAPTER_DEFAULT, i, &dmode);
1449 ok(res==D3D_OK, "EnumAdapterModes returned %#08x for mode %u!\n", res, i);
1450 if(res != D3D_OK)
1451 continue;
1453 ok(dmode.Format==D3DFMT_X8R8G8B8 || dmode.Format==D3DFMT_R5G6B5,
1454 "Unexpected display mode returned for mode %u: %#x\n", i , dmode.Format);
1457 IDirect3D8_Release(d3d);
1460 struct mode
1462 unsigned int w;
1463 unsigned int h;
1466 static int compare_mode(const void *a, const void *b)
1468 const struct mode *mode_a = a;
1469 const struct mode *mode_b = b;
1470 int w = mode_a->w - mode_b->w;
1471 int h = mode_a->h - mode_b->h;
1472 return abs(w) >= abs(h) ? -w : -h;
1475 static void test_reset(void)
1477 UINT width, orig_width = GetSystemMetrics(SM_CXSCREEN);
1478 UINT height, orig_height = GetSystemMetrics(SM_CYSCREEN);
1479 IDirect3DDevice8 *device1 = NULL;
1480 IDirect3DDevice8 *device2 = NULL;
1481 struct device_desc device_desc;
1482 D3DDISPLAYMODE d3ddm, d3ddm2;
1483 D3DSURFACE_DESC surface_desc;
1484 D3DPRESENT_PARAMETERS d3dpp;
1485 IDirect3DSurface8 *surface;
1486 IDirect3DTexture8 *texture;
1487 IDirect3DVertexBuffer8 *vb;
1488 IDirect3DIndexBuffer8 *ib;
1489 UINT adapter_mode_count;
1490 D3DLOCKED_RECT lockrect;
1491 UINT mode_count = 0;
1492 DEVMODEW devmode;
1493 IDirect3D8 *d3d8;
1494 RECT winrect, client_rect;
1495 D3DVIEWPORT8 vp;
1496 ULONG refcount;
1497 D3DCAPS8 caps;
1498 DWORD shader;
1499 DWORD value;
1500 HWND window;
1501 HRESULT hr;
1502 LONG ret;
1503 UINT i;
1505 static const DWORD decl[] =
1507 D3DVSD_STREAM(0),
1508 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT4),
1509 D3DVSD_END(),
1512 struct mode *modes = NULL;
1514 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
1515 100, 100, 160, 160, NULL, NULL, NULL, NULL);
1516 ok(!!window, "Failed to create a window.\n");
1517 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
1518 ok(!!d3d8, "Failed to create a D3D object.\n");
1520 hr = IDirect3D8_GetAdapterDisplayMode(d3d8, D3DADAPTER_DEFAULT, &d3ddm);
1521 ok(SUCCEEDED(hr), "GetAdapterDisplayMode failed, hr %#x.\n", hr);
1522 adapter_mode_count = IDirect3D8_GetAdapterModeCount(d3d8, D3DADAPTER_DEFAULT);
1523 modes = HeapAlloc(GetProcessHeap(), 0, sizeof(*modes) * adapter_mode_count);
1524 for (i = 0; i < adapter_mode_count; ++i)
1526 UINT j;
1528 memset(&d3ddm2, 0, sizeof(d3ddm2));
1529 hr = IDirect3D8_EnumAdapterModes(d3d8, D3DADAPTER_DEFAULT, i, &d3ddm2);
1530 ok(SUCCEEDED(hr), "EnumAdapterModes failed, hr %#x.\n", hr);
1532 if (d3ddm2.Format != d3ddm.Format)
1533 continue;
1535 for (j = 0; j < mode_count; ++j)
1537 if (modes[j].w == d3ddm2.Width && modes[j].h == d3ddm2.Height)
1538 break;
1540 if (j == mode_count)
1542 modes[j].w = d3ddm2.Width;
1543 modes[j].h = d3ddm2.Height;
1544 ++mode_count;
1547 /* We use them as invalid modes. */
1548 if ((d3ddm2.Width == 801 && d3ddm2.Height == 600)
1549 || (d3ddm2.Width == 32 && d3ddm2.Height == 32))
1551 skip("This system supports a screen resolution of %dx%d, not running mode tests.\n",
1552 d3ddm2.Width, d3ddm2.Height);
1553 goto cleanup;
1557 if (mode_count < 2)
1559 skip("Less than 2 modes supported, skipping mode tests.\n");
1560 goto cleanup;
1563 /* Prefer higher resolutions. */
1564 qsort(modes, mode_count, sizeof(*modes), compare_mode);
1566 i = 0;
1567 if (modes[i].w == orig_width && modes[i].h == orig_height) ++i;
1569 device_desc.adapter_ordinal = D3DADAPTER_DEFAULT;
1570 device_desc.width = modes[i].w;
1571 device_desc.height = modes[i].h;
1572 device_desc.device_window = window;
1573 device_desc.flags = CREATE_DEVICE_FULLSCREEN | CREATE_DEVICE_SWVP_ONLY;
1574 if (!(device1 = create_device(d3d8, window, &device_desc)))
1576 skip("Failed to create a D3D device, skipping tests.\n");
1577 goto cleanup;
1579 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1580 /* This skips the test on testbot Win 8 VMs. */
1581 if (hr == D3DERR_DEVICELOST)
1583 skip("Device is lost.\n");
1584 goto cleanup;
1586 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1588 hr = IDirect3DDevice8_GetDeviceCaps(device1, &caps);
1589 ok(SUCCEEDED(hr), "GetDeviceCaps failed, hr %#x.\n", hr);
1591 width = GetSystemMetrics(SM_CXSCREEN);
1592 height = GetSystemMetrics(SM_CYSCREEN);
1593 ok(width == modes[i].w, "Screen width is %u, expected %u.\n", width, modes[i].w);
1594 ok(height == modes[i].h, "Screen height is %u, expected %u.\n", height, modes[i].h);
1596 hr = IDirect3DDevice8_GetViewport(device1, &vp);
1597 ok(SUCCEEDED(hr), "GetViewport failed, hr %#x.\n", hr);
1598 ok(vp.X == 0, "D3DVIEWPORT->X = %u, expected 0.\n", vp.X);
1599 ok(vp.Y == 0, "D3DVIEWPORT->Y = %u, expected 0.\n", vp.Y);
1600 ok(vp.Width == modes[i].w, "D3DVIEWPORT->Width = %u, expected %u.\n", vp.Width, modes[i].w);
1601 ok(vp.Height == modes[i].h, "D3DVIEWPORT->Height = %u, expected %u.\n", vp.Height, modes[i].h);
1602 ok(vp.MinZ == 0, "D3DVIEWPORT->MinZ = %.8e, expected 0.\n", vp.MinZ);
1603 ok(vp.MaxZ == 1, "D3DVIEWPORT->MaxZ = %.8e, expected 1.\n", vp.MaxZ);
1605 i = 1;
1606 vp.X = 10;
1607 vp.Y = 20;
1608 vp.Width = modes[i].w / 2;
1609 vp.Height = modes[i].h / 2;
1610 vp.MinZ = 0.2f;
1611 vp.MaxZ = 0.3f;
1612 hr = IDirect3DDevice8_SetViewport(device1, &vp);
1613 ok(SUCCEEDED(hr), "SetViewport failed, hr %#x.\n", hr);
1615 hr = IDirect3DDevice8_GetRenderState(device1, D3DRS_LIGHTING, &value);
1616 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1617 ok(!!value, "Got unexpected value %#x for D3DRS_LIGHTING.\n", value);
1618 hr = IDirect3DDevice8_SetRenderState(device1, D3DRS_LIGHTING, FALSE);
1619 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
1621 memset(&d3dpp, 0, sizeof(d3dpp));
1622 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1623 d3dpp.Windowed = FALSE;
1624 d3dpp.BackBufferWidth = modes[i].w;
1625 d3dpp.BackBufferHeight = modes[i].h;
1626 d3dpp.BackBufferFormat = d3ddm.Format;
1627 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1628 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1629 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1630 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1632 hr = IDirect3DDevice8_GetRenderState(device1, D3DRS_LIGHTING, &value);
1633 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1634 ok(!!value, "Got unexpected value %#x for D3DRS_LIGHTING.\n", value);
1636 memset(&vp, 0, sizeof(vp));
1637 hr = IDirect3DDevice8_GetViewport(device1, &vp);
1638 ok(SUCCEEDED(hr), "GetViewport failed, hr %#x.\n", hr);
1639 ok(vp.X == 0, "D3DVIEWPORT->X = %u, expected 0.\n", vp.X);
1640 ok(vp.Y == 0, "D3DVIEWPORT->Y = %u, expected 0.\n", vp.Y);
1641 ok(vp.Width == modes[i].w, "D3DVIEWPORT->Width = %u, expected %u.\n", vp.Width, modes[i].w);
1642 ok(vp.Height == modes[i].h, "D3DVIEWPORT->Height = %u, expected %u.\n", vp.Height, modes[i].h);
1643 ok(vp.MinZ == 0, "D3DVIEWPORT->MinZ = %.8e, expected 0.\n", vp.MinZ);
1644 ok(vp.MaxZ == 1, "D3DVIEWPORT->MaxZ = %.8e, expected 1.\n", vp.MaxZ);
1646 width = GetSystemMetrics(SM_CXSCREEN);
1647 height = GetSystemMetrics(SM_CYSCREEN);
1648 ok(width == modes[i].w, "Screen width is %u, expected %u.\n", width, modes[i].w);
1649 ok(height == modes[i].h, "Screen height is %u, expected %u.\n", height, modes[i].h);
1651 hr = IDirect3DDevice8_GetRenderTarget(device1, &surface);
1652 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
1653 hr = IDirect3DSurface8_GetDesc(surface, &surface_desc);
1654 ok(hr == D3D_OK, "GetDesc failed, hr %#x.\n", hr);
1655 ok(surface_desc.Width == modes[i].w, "Back buffer width is %u, expected %u.\n",
1656 surface_desc.Width, modes[i].w);
1657 ok(surface_desc.Height == modes[i].h, "Back buffer height is %u, expected %u.\n",
1658 surface_desc.Height, modes[i].h);
1659 IDirect3DSurface8_Release(surface);
1661 memset(&d3dpp, 0, sizeof(d3dpp));
1662 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1663 d3dpp.Windowed = TRUE;
1664 d3dpp.BackBufferWidth = 400;
1665 d3dpp.BackBufferHeight = 300;
1666 d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
1667 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1668 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1669 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1670 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1672 memset(&vp, 0, sizeof(vp));
1673 hr = IDirect3DDevice8_GetViewport(device1, &vp);
1674 ok(SUCCEEDED(hr), "GetViewport failed, hr %#x.\n", hr);
1675 ok(vp.X == 0, "D3DVIEWPORT->X = %u, expected 0.\n", vp.X);
1676 ok(vp.Y == 0, "D3DVIEWPORT->Y = %u, expected 0.\n", vp.Y);
1677 ok(vp.Width == 400, "D3DVIEWPORT->Width = %u, expected 400.\n", vp.Width);
1678 ok(vp.Height == 300, "D3DVIEWPORT->Height = %u, expected 300.\n", vp.Height);
1679 ok(vp.MinZ == 0, "D3DVIEWPORT->MinZ = %.8e, expected 0.\n", vp.MinZ);
1680 ok(vp.MaxZ == 1, "D3DVIEWPORT->MaxZ = %.8e, expected 1.\n", vp.MaxZ);
1682 width = GetSystemMetrics(SM_CXSCREEN);
1683 height = GetSystemMetrics(SM_CYSCREEN);
1684 ok(width == orig_width, "Screen width is %u, expected %u.\n", width, orig_width);
1685 ok(height == orig_height, "Screen height is %u, expected %u.\n", height, orig_height);
1687 hr = IDirect3DDevice8_GetRenderTarget(device1, &surface);
1688 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
1689 hr = IDirect3DSurface8_GetDesc(surface, &surface_desc);
1690 ok(hr == D3D_OK, "GetDesc failed, hr %#x.\n", hr);
1691 ok(surface_desc.Width == 400, "Back buffer width is %u, expected 400.\n",
1692 surface_desc.Width);
1693 ok(surface_desc.Height == 300, "Back buffer height is %u, expected 300.\n",
1694 surface_desc.Height);
1695 IDirect3DSurface8_Release(surface);
1697 memset(&devmode, 0, sizeof(devmode));
1698 devmode.dmSize = sizeof(devmode);
1699 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
1700 devmode.dmPelsWidth = modes[1].w;
1701 devmode.dmPelsHeight = modes[1].h;
1702 ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
1703 ok(ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", ret);
1704 width = GetSystemMetrics(SM_CXSCREEN);
1705 height = GetSystemMetrics(SM_CYSCREEN);
1706 ok(width == modes[1].w, "Screen width is %u, expected %u.\n", width, modes[1].w);
1707 ok(height == modes[1].h, "Screen height is %u, expected %u.\n", height, modes[1].h);
1709 d3dpp.BackBufferWidth = 500;
1710 d3dpp.BackBufferHeight = 400;
1711 d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
1712 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1713 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1714 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1715 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1717 width = GetSystemMetrics(SM_CXSCREEN);
1718 height = GetSystemMetrics(SM_CYSCREEN);
1719 ok(width == modes[1].w, "Screen width is %u, expected %u.\n", width, modes[1].w);
1720 ok(height == modes[1].h, "Screen height is %u, expected %u.\n", height, modes[1].h);
1722 ZeroMemory(&vp, sizeof(vp));
1723 hr = IDirect3DDevice8_GetViewport(device1, &vp);
1724 ok(SUCCEEDED(hr), "GetViewport failed, hr %#x.\n", hr);
1725 ok(vp.X == 0, "D3DVIEWPORT->X = %d.\n", vp.X);
1726 ok(vp.Y == 0, "D3DVIEWPORT->Y = %d.\n", vp.Y);
1727 ok(vp.Width == 500, "D3DVIEWPORT->Width = %d.\n", vp.Width);
1728 ok(vp.Height == 400, "D3DVIEWPORT->Height = %d.\n", vp.Height);
1729 ok(vp.MinZ == 0, "D3DVIEWPORT->MinZ = %f.\n", vp.MinZ);
1730 ok(vp.MaxZ == 1, "D3DVIEWPORT->MaxZ = %f.\n", vp.MaxZ);
1732 hr = IDirect3DDevice8_GetRenderTarget(device1, &surface);
1733 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
1734 hr = IDirect3DSurface8_GetDesc(surface, &surface_desc);
1735 ok(hr == D3D_OK, "GetDesc failed, hr %#x.\n", hr);
1736 ok(surface_desc.Width == 500, "Back buffer width is %u, expected 500.\n",
1737 surface_desc.Width);
1738 ok(surface_desc.Height == 400, "Back buffer height is %u, expected 400.\n",
1739 surface_desc.Height);
1740 IDirect3DSurface8_Release(surface);
1742 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
1743 devmode.dmPelsWidth = orig_width;
1744 devmode.dmPelsHeight = orig_height;
1745 ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
1746 ok(ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", ret);
1747 width = GetSystemMetrics(SM_CXSCREEN);
1748 height = GetSystemMetrics(SM_CYSCREEN);
1749 ok(width == orig_width, "Got screen width %u, expected %u.\n", width, orig_width);
1750 ok(height == orig_height, "Got screen height %u, expected %u.\n", height, orig_height);
1752 winrect.left = 0;
1753 winrect.top = 0;
1754 winrect.right = 200;
1755 winrect.bottom = 150;
1756 ok(AdjustWindowRect(&winrect, WS_OVERLAPPEDWINDOW, FALSE), "AdjustWindowRect failed\n");
1757 ok(SetWindowPos(window, NULL, 0, 0,
1758 winrect.right-winrect.left,
1759 winrect.bottom-winrect.top,
1760 SWP_NOMOVE|SWP_NOZORDER),
1761 "SetWindowPos failed\n");
1763 /* Windows 10 gives us a different size than we requested with some DPI scaling settings (e.g. 172%). */
1764 GetClientRect(window, &client_rect);
1766 memset(&d3dpp, 0, sizeof(d3dpp));
1767 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1768 d3dpp.Windowed = TRUE;
1769 d3dpp.BackBufferWidth = 0;
1770 d3dpp.BackBufferHeight = 0;
1771 d3dpp.BackBufferFormat = d3ddm.Format;
1772 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1773 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1774 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1775 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1777 ok(!d3dpp.BackBufferWidth, "Got unexpected BackBufferWidth %u.\n", d3dpp.BackBufferWidth);
1778 ok(!d3dpp.BackBufferHeight, "Got unexpected BackBufferHeight %u.\n", d3dpp.BackBufferHeight);
1779 ok(d3dpp.BackBufferFormat == d3ddm.Format, "Got unexpected BackBufferFormat %#x, expected %#x.\n",
1780 d3dpp.BackBufferFormat, d3ddm.Format);
1781 ok(d3dpp.BackBufferCount == 1, "Got unexpected BackBufferCount %u.\n", d3dpp.BackBufferCount);
1782 ok(!d3dpp.MultiSampleType, "Got unexpected MultiSampleType %u.\n", d3dpp.MultiSampleType);
1783 ok(d3dpp.SwapEffect == D3DSWAPEFFECT_DISCARD, "Got unexpected SwapEffect %#x.\n", d3dpp.SwapEffect);
1784 ok(!d3dpp.hDeviceWindow, "Got unexpected hDeviceWindow %p.\n", d3dpp.hDeviceWindow);
1785 ok(d3dpp.Windowed, "Got unexpected Windowed %#x.\n", d3dpp.Windowed);
1786 ok(!d3dpp.EnableAutoDepthStencil, "Got unexpected EnableAutoDepthStencil %#x.\n", d3dpp.EnableAutoDepthStencil);
1787 ok(!d3dpp.AutoDepthStencilFormat, "Got unexpected AutoDepthStencilFormat %#x.\n", d3dpp.AutoDepthStencilFormat);
1788 ok(!d3dpp.Flags, "Got unexpected Flags %#x.\n", d3dpp.Flags);
1789 ok(!d3dpp.FullScreen_RefreshRateInHz, "Got unexpected FullScreen_RefreshRateInHz %u.\n",
1790 d3dpp.FullScreen_RefreshRateInHz);
1791 ok(!d3dpp.FullScreen_PresentationInterval, "Got unexpected FullScreen_PresentationInterval %#x.\n",
1792 d3dpp.FullScreen_PresentationInterval);
1794 memset(&vp, 0, sizeof(vp));
1795 hr = IDirect3DDevice8_GetViewport(device1, &vp);
1796 ok(SUCCEEDED(hr), "GetViewport failed, hr %#x.\n", hr);
1797 if (SUCCEEDED(hr))
1799 ok(vp.X == 0, "D3DVIEWPORT->X = %u, expected 0.\n", vp.X);
1800 ok(vp.Y == 0, "D3DVIEWPORT->Y = %u, expected 0.\n", vp.Y);
1801 ok(vp.Width == client_rect.right, "D3DVIEWPORT->Width = %d, expected %d\n",
1802 vp.Width, client_rect.right);
1803 ok(vp.Height == client_rect.bottom, "D3DVIEWPORT->Height = %d, expected %d\n",
1804 vp.Height, client_rect.bottom);
1805 ok(vp.MinZ == 0, "D3DVIEWPORT->MinZ = %.8e, expected 0.\n", vp.MinZ);
1806 ok(vp.MaxZ == 1, "D3DVIEWPORT->MaxZ = %.8e, expected 1.\n", vp.MaxZ);
1809 hr = IDirect3DDevice8_GetRenderTarget(device1, &surface);
1810 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
1811 hr = IDirect3DSurface8_GetDesc(surface, &surface_desc);
1812 ok(hr == D3D_OK, "GetDesc failed, hr %#x.\n", hr);
1813 ok(surface_desc.Format == d3ddm.Format, "Got unexpected Format %#x, expected %#x.\n",
1814 surface_desc.Format, d3ddm.Format);
1815 ok(!surface_desc.MultiSampleType, "Got unexpected MultiSampleType %u.\n", d3dpp.MultiSampleType);
1816 ok(surface_desc.Width == client_rect.right,
1817 "Back buffer width is %u, expected %d.\n", surface_desc.Width, client_rect.right);
1818 ok(surface_desc.Height == client_rect.bottom,
1819 "Back buffer height is %u, expected %d.\n", surface_desc.Height, client_rect.bottom);
1820 IDirect3DSurface8_Release(surface);
1822 memset(&d3dpp, 0, sizeof(d3dpp));
1823 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1824 d3dpp.Windowed = TRUE;
1825 d3dpp.BackBufferWidth = 400;
1826 d3dpp.BackBufferHeight = 300;
1827 d3dpp.BackBufferFormat = d3ddm.Format;
1829 /* Reset fails if there is a resource in the default pool. */
1830 hr = IDirect3DDevice8_CreateTexture(device1, 16, 16, 1, 0, D3DFMT_R5G6B5, D3DPOOL_DEFAULT, &texture);
1831 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
1832 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1833 ok(hr == D3DERR_DEVICELOST, "Reset returned %#x, expected %#x.\n", hr, D3DERR_DEVICELOST);
1834 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1835 ok(hr == D3DERR_DEVICENOTRESET, "TestCooperativeLevel returned %#x, expected %#x.\n", hr, D3DERR_DEVICENOTRESET);
1836 IDirect3DTexture8_Release(texture);
1837 /* Reset again to get the device out of the lost state. */
1838 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1839 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1840 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1841 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1843 if (caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP)
1845 IDirect3DVolumeTexture8 *volume_texture;
1847 hr = IDirect3DDevice8_CreateVolumeTexture(device1, 16, 16, 4, 1, 0,
1848 D3DFMT_R5G6B5, D3DPOOL_DEFAULT, &volume_texture);
1849 ok(SUCCEEDED(hr), "CreateVolumeTexture failed, hr %#x.\n", hr);
1850 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1851 ok(hr == D3DERR_DEVICELOST, "Reset returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
1852 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1853 ok(hr == D3DERR_DEVICENOTRESET, "TestCooperativeLevel returned %#x, expected %#x.\n",
1854 hr, D3DERR_DEVICENOTRESET);
1855 IDirect3DVolumeTexture8_Release(volume_texture);
1856 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1857 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1858 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1859 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1861 else
1863 skip("Volume textures not supported.\n");
1866 /* Test with DEFAULT pool resources bound but otherwise not referenced. */
1867 hr = IDirect3DDevice8_CreateVertexBuffer(device1, 16, 0,
1868 D3DFVF_XYZ, D3DPOOL_DEFAULT, &vb);
1869 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1870 hr = IDirect3DDevice8_SetStreamSource(device1, 0, vb, 16);
1871 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1872 refcount = IDirect3DVertexBuffer8_Release(vb);
1873 ok(!refcount, "Unexpected refcount %u.\n", refcount);
1874 hr = IDirect3DDevice8_CreateIndexBuffer(device1, 16, 0,
1875 D3DFMT_INDEX16, D3DPOOL_DEFAULT, &ib);
1876 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1877 hr = IDirect3DDevice8_SetIndices(device1, ib, 0);
1878 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1879 refcount = IDirect3DIndexBuffer8_Release(ib);
1880 ok(!refcount, "Unexpected refcount %u.\n", refcount);
1881 hr = IDirect3DDevice8_CreateTexture(device1, 16, 16, 0, 0,
1882 D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &texture);
1883 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1884 hr = IDirect3DDevice8_SetTexture(device1, i, (IDirect3DBaseTexture8 *)texture);
1885 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1887 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1888 ok(hr == D3DERR_DEVICELOST, "Got unexpected hr %#x.\n", hr);
1889 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1890 ok(hr == D3DERR_DEVICENOTRESET, "Got unexpected hr %#x.\n", hr);
1892 /* Crashes on Windows. */
1893 if (0)
1895 hr = IDirect3DDevice8_GetIndices(device1, &ib, &i);
1896 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
1898 refcount = IDirect3DTexture8_Release(texture);
1899 ok(!refcount, "Unexpected refcount %u.\n", refcount);
1901 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1902 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1903 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1904 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
1906 /* Scratch, sysmem and managed pool resources are fine. */
1907 hr = IDirect3DDevice8_CreateTexture(device1, 16, 16, 1, 0, D3DFMT_R5G6B5, D3DPOOL_SCRATCH, &texture);
1908 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
1909 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1910 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1911 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1912 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1913 IDirect3DTexture8_Release(texture);
1915 hr = IDirect3DDevice8_CreateTexture(device1, 16, 16, 1, 0, D3DFMT_R5G6B5, D3DPOOL_SYSTEMMEM, &texture);
1916 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
1917 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1918 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1919 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1920 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1921 IDirect3DTexture8_Release(texture);
1923 hr = IDirect3DDevice8_CreateVertexBuffer(device1, 16, 0,
1924 D3DFVF_XYZ, D3DPOOL_SYSTEMMEM, &vb);
1925 ok(hr == D3D_OK, "Failed to create vertex buffer, hr %#x.\n", hr);
1926 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1927 ok(hr == D3D_OK, "Failed to reset device, hr %#x.\n", hr);
1928 IDirect3DVertexBuffer8_Release(vb);
1930 hr = IDirect3DDevice8_CreateIndexBuffer(device1, 16, 0,
1931 D3DFMT_INDEX16, D3DPOOL_SYSTEMMEM, &ib);
1932 ok(hr == D3D_OK, "Failed to create index buffer, hr %#x.\n", hr);
1933 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1934 ok(hr == D3D_OK, "Failed to reset device, hr %#x.\n", hr);
1935 IDirect3DIndexBuffer8_Release(ib);
1937 /* The depth stencil should get reset to the auto depth stencil when present. */
1938 hr = IDirect3DDevice8_SetRenderTarget(device1, NULL, NULL);
1939 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
1941 hr = IDirect3DDevice8_GetDepthStencilSurface(device1, &surface);
1942 ok(hr == D3DERR_NOTFOUND, "GetDepthStencilSurface returned %#x, expected %#x.\n", hr, D3DERR_NOTFOUND);
1943 ok(!surface, "Depth / stencil buffer should be NULL.\n");
1945 d3dpp.EnableAutoDepthStencil = TRUE;
1946 d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
1947 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1948 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1950 hr = IDirect3DDevice8_GetDepthStencilSurface(device1, &surface);
1951 ok(SUCCEEDED(hr), "GetDepthStencilSurface failed, hr %#x.\n", hr);
1952 ok(!!surface, "Depth / stencil buffer should not be NULL.\n");
1953 if (surface) IDirect3DSurface8_Release(surface);
1955 d3dpp.EnableAutoDepthStencil = FALSE;
1956 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1957 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1959 hr = IDirect3DDevice8_GetDepthStencilSurface(device1, &surface);
1960 ok(hr == D3DERR_NOTFOUND, "GetDepthStencilSurface returned %#x, expected %#x.\n", hr, D3DERR_NOTFOUND);
1961 ok(!surface, "Depth / stencil buffer should be NULL.\n");
1963 /* Will a sysmem or scratch resource survive while locked? */
1964 hr = IDirect3DDevice8_CreateTexture(device1, 16, 16, 1, 0, D3DFMT_R5G6B5, D3DPOOL_SYSTEMMEM, &texture);
1965 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
1966 hr = IDirect3DTexture8_LockRect(texture, 0, &lockrect, NULL, D3DLOCK_DISCARD);
1967 ok(SUCCEEDED(hr), "LockRect failed, hr %#x.\n", hr);
1968 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1969 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1970 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1971 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1972 IDirect3DTexture8_UnlockRect(texture, 0);
1973 IDirect3DTexture8_Release(texture);
1975 hr = IDirect3DDevice8_CreateTexture(device1, 16, 16, 1, 0, D3DFMT_R5G6B5, D3DPOOL_SCRATCH, &texture);
1976 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
1977 hr = IDirect3DTexture8_LockRect(texture, 0, &lockrect, NULL, D3DLOCK_DISCARD);
1978 ok(SUCCEEDED(hr), "LockRect failed, hr %#x.\n", hr);
1979 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1980 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1981 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1982 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1983 IDirect3DTexture8_UnlockRect(texture, 0);
1984 IDirect3DTexture8_Release(texture);
1986 hr = IDirect3DDevice8_CreateTexture(device1, 16, 16, 1, 0, D3DFMT_R5G6B5, D3DPOOL_MANAGED, &texture);
1987 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
1988 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1989 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1990 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1991 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1992 IDirect3DTexture8_Release(texture);
1994 /* A reference held to an implicit surface causes failures as well. */
1995 hr = IDirect3DDevice8_GetBackBuffer(device1, 0, D3DBACKBUFFER_TYPE_MONO, &surface);
1996 ok(SUCCEEDED(hr), "GetBackBuffer failed, hr %#x.\n", hr);
1997 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1998 ok(hr == D3DERR_DEVICELOST, "Reset returned %#x, expected %#x.\n", hr, D3DERR_DEVICELOST);
1999 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
2000 ok(hr == D3DERR_DEVICENOTRESET, "TestCooperativeLevel returned %#x, expected %#x.\n", hr, D3DERR_DEVICENOTRESET);
2001 IDirect3DSurface8_Release(surface);
2002 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
2003 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
2004 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
2005 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
2007 /* Shaders are fine as well. */
2008 hr = IDirect3DDevice8_CreateVertexShader(device1, decl, simple_vs, &shader, 0);
2009 ok(SUCCEEDED(hr), "CreateVertexShader failed, hr %#x.\n", hr);
2010 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
2011 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
2012 hr = IDirect3DDevice8_DeleteVertexShader(device1, shader);
2013 ok(SUCCEEDED(hr), "DeleteVertexShader failed, hr %#x.\n", hr);
2015 /* Try setting invalid modes. */
2016 memset(&d3dpp, 0, sizeof(d3dpp));
2017 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
2018 d3dpp.Windowed = FALSE;
2019 d3dpp.BackBufferWidth = 32;
2020 d3dpp.BackBufferHeight = 32;
2021 d3dpp.BackBufferFormat = d3ddm.Format;
2022 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
2023 ok(hr == D3DERR_INVALIDCALL, "Reset returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
2024 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
2025 ok(hr == D3DERR_DEVICENOTRESET, "TestCooperativeLevel returned %#x, expected %#x.\n", hr, D3DERR_DEVICENOTRESET);
2027 memset(&d3dpp, 0, sizeof(d3dpp));
2028 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
2029 d3dpp.Windowed = FALSE;
2030 d3dpp.BackBufferWidth = 801;
2031 d3dpp.BackBufferHeight = 600;
2032 d3dpp.BackBufferFormat = d3ddm.Format;
2033 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
2034 ok(hr == D3DERR_INVALIDCALL, "Reset returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
2035 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
2036 ok(hr == D3DERR_DEVICENOTRESET, "TestCooperativeLevel returned %#x, expected %#x.\n", hr, D3DERR_DEVICENOTRESET);
2038 memset(&d3dpp, 0, sizeof(d3dpp));
2039 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
2040 d3dpp.Windowed = FALSE;
2041 d3dpp.BackBufferWidth = 0;
2042 d3dpp.BackBufferHeight = 0;
2043 d3dpp.BackBufferFormat = d3ddm.Format;
2044 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
2045 ok(hr == D3DERR_INVALIDCALL, "Reset returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
2046 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
2047 ok(hr == D3DERR_DEVICENOTRESET, "TestCooperativeLevel returned %#x, expected %#x.\n", hr, D3DERR_DEVICENOTRESET);
2049 hr = IDirect3D8_GetAdapterDisplayMode(d3d8, D3DADAPTER_DEFAULT, &d3ddm);
2050 ok(SUCCEEDED(hr), "GetAdapterDisplayMode failed, hr %#x.\n", hr);
2052 memset(&d3dpp, 0, sizeof(d3dpp));
2053 d3dpp.Windowed = TRUE;
2054 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
2055 d3dpp.BackBufferFormat = d3ddm.Format;
2056 d3dpp.EnableAutoDepthStencil = FALSE;
2057 d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
2059 hr = IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
2060 window, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &device2);
2061 if (FAILED(hr))
2063 skip("Failed to create device, hr %#x.\n", hr);
2064 goto cleanup;
2067 hr = IDirect3DDevice8_TestCooperativeLevel(device2);
2068 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
2070 d3dpp.Windowed = TRUE;
2071 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
2072 d3dpp.BackBufferWidth = 400;
2073 d3dpp.BackBufferHeight = 300;
2074 d3dpp.BackBufferFormat = d3ddm.Format;
2075 d3dpp.EnableAutoDepthStencil = TRUE;
2076 d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
2078 hr = IDirect3DDevice8_Reset(device2, &d3dpp);
2079 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
2080 if (FAILED(hr))
2081 goto cleanup;
2083 hr = IDirect3DDevice8_GetDepthStencilSurface(device2, &surface);
2084 ok(SUCCEEDED(hr), "GetDepthStencilSurface failed, hr %#x.\n", hr);
2085 ok(!!surface, "Depth / stencil buffer should not be NULL.\n");
2086 if (surface)
2087 IDirect3DSurface8_Release(surface);
2089 cleanup:
2090 HeapFree(GetProcessHeap(), 0, modes);
2091 if (device2)
2092 IDirect3DDevice8_Release(device2);
2093 if (device1)
2094 IDirect3DDevice8_Release(device1);
2095 IDirect3D8_Release(d3d8);
2096 DestroyWindow(window);
2099 static void test_scene(void)
2101 IDirect3DDevice8 *device;
2102 IDirect3D8 *d3d;
2103 ULONG refcount;
2104 HWND window;
2105 HRESULT hr;
2107 window = create_window();
2108 ok(!!window, "Failed to create a window.\n");
2109 d3d = Direct3DCreate8(D3D_SDK_VERSION);
2110 ok(!!d3d, "Failed to create a D3D object.\n");
2111 if (!(device = create_device(d3d, window, NULL)))
2113 skip("Failed to create a 3D device, skipping test.\n");
2114 goto cleanup;
2117 /* Test an EndScene without BeginScene. Should return an error */
2118 hr = IDirect3DDevice8_EndScene(device);
2119 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_EndScene returned %#08x\n", hr);
2121 /* Test a normal BeginScene / EndScene pair, this should work */
2122 hr = IDirect3DDevice8_BeginScene(device);
2123 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr);
2124 hr = IDirect3DDevice8_EndScene(device);
2125 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed with %#08x\n", hr);
2127 /* Test another EndScene without having begun a new scene. Should return an error */
2128 hr = IDirect3DDevice8_EndScene(device);
2129 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_EndScene returned %#08x\n", hr);
2131 /* Two nested BeginScene and EndScene calls */
2132 hr = IDirect3DDevice8_BeginScene(device);
2133 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr);
2134 hr = IDirect3DDevice8_BeginScene(device);
2135 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_BeginScene returned %#08x\n", hr);
2136 hr = IDirect3DDevice8_EndScene(device);
2137 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed with %#08x\n", hr);
2138 hr = IDirect3DDevice8_EndScene(device);
2139 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_EndScene returned %#08x\n", hr);
2141 /* StretchRect does not exit in Direct3D8, so no equivalent to the d3d9 stretchrect tests */
2143 refcount = IDirect3DDevice8_Release(device);
2144 ok(!refcount, "Device has %u references left.\n", refcount);
2145 cleanup:
2146 IDirect3D8_Release(d3d);
2147 DestroyWindow(window);
2150 static void test_shader(void)
2152 DWORD hPixelShader = 0, hVertexShader = 0;
2153 DWORD hPixelShader2 = 0, hVertexShader2 = 0;
2154 DWORD hTempHandle;
2155 D3DCAPS8 caps;
2156 DWORD fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE;
2157 IDirect3DDevice8 *device;
2158 IDirect3D8 *d3d;
2159 DWORD data_size;
2160 ULONG refcount;
2161 HWND window;
2162 HRESULT hr;
2163 void *data;
2165 static DWORD dwVertexDecl[] =
2167 D3DVSD_STREAM(0),
2168 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3),
2169 D3DVSD_END()
2171 DWORD decl_normal_float2[] =
2173 D3DVSD_STREAM(0),
2174 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
2175 D3DVSD_REG(D3DVSDE_NORMAL, D3DVSDT_FLOAT2), /* D3DVSDE_NORMAL, Register v1 */
2176 D3DVSD_END()
2178 DWORD decl_normal_float4[] =
2180 D3DVSD_STREAM(0),
2181 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
2182 D3DVSD_REG(D3DVSDE_NORMAL, D3DVSDT_FLOAT4), /* D3DVSDE_NORMAL, Register v1 */
2183 D3DVSD_END()
2185 DWORD decl_normal_d3dcolor[] =
2187 D3DVSD_STREAM(0),
2188 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
2189 D3DVSD_REG(D3DVSDE_NORMAL, D3DVSDT_D3DCOLOR),/* D3DVSDE_NORMAL, Register v1 */
2190 D3DVSD_END()
2192 const DWORD vertex_decl_size = sizeof(dwVertexDecl);
2193 const DWORD simple_vs_size = sizeof(simple_vs);
2194 const DWORD simple_ps_size = sizeof(simple_ps);
2196 window = create_window();
2197 ok(!!window, "Failed to create a window.\n");
2198 d3d = Direct3DCreate8(D3D_SDK_VERSION);
2199 ok(!!d3d, "Failed to create a D3D object.\n");
2200 if (!(device = create_device(d3d, window, NULL)))
2202 skip("Failed to create a 3D device, skipping test.\n");
2203 goto cleanup;
2206 IDirect3DDevice8_GetDeviceCaps(device, &caps);
2208 /* Test setting and retrieving a FVF */
2209 hr = IDirect3DDevice8_SetVertexShader(device, fvf);
2210 ok(SUCCEEDED(hr), "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
2211 hr = IDirect3DDevice8_GetVertexShader(device, &hTempHandle);
2212 ok(SUCCEEDED(hr), "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
2213 ok(hTempHandle == fvf, "Vertex shader %#08x is set, expected %#08x\n", hTempHandle, fvf);
2215 /* First create a vertex shader */
2216 hr = IDirect3DDevice8_SetVertexShader(device, 0);
2217 ok(SUCCEEDED(hr), "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
2218 hr = IDirect3DDevice8_CreateVertexShader(device, dwVertexDecl, simple_vs, &hVertexShader, 0);
2219 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
2220 /* Msdn says that the new vertex shader is set immediately. This is wrong, apparently */
2221 hr = IDirect3DDevice8_GetVertexShader(device, &hTempHandle);
2222 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
2223 ok(hTempHandle == 0, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, 0);
2224 /* Assign the shader, then verify that GetVertexShader works */
2225 hr = IDirect3DDevice8_SetVertexShader(device, hVertexShader);
2226 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
2227 hr = IDirect3DDevice8_GetVertexShader(device, &hTempHandle);
2228 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
2229 ok(hTempHandle == hVertexShader, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, hVertexShader);
2230 /* Verify that we can retrieve the declaration */
2231 hr = IDirect3DDevice8_GetVertexShaderDeclaration(device, hVertexShader, NULL, &data_size);
2232 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderDeclaration returned %#08x\n", hr);
2233 ok(data_size == vertex_decl_size, "Got data_size %u, expected %u\n", data_size, vertex_decl_size);
2234 data = HeapAlloc(GetProcessHeap(), 0, vertex_decl_size);
2235 data_size = 1;
2236 hr = IDirect3DDevice8_GetVertexShaderDeclaration(device, hVertexShader, data, &data_size);
2237 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_GetVertexShaderDeclaration returned (%#08x), "
2238 "expected D3DERR_INVALIDCALL\n", hr);
2239 ok(data_size == 1, "Got data_size %u, expected 1\n", data_size);
2240 data_size = vertex_decl_size;
2241 hr = IDirect3DDevice8_GetVertexShaderDeclaration(device, hVertexShader, data, &data_size);
2242 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderDeclaration returned %#08x\n", hr);
2243 ok(data_size == vertex_decl_size, "Got data_size %u, expected %u\n", data_size, vertex_decl_size);
2244 ok(!memcmp(data, dwVertexDecl, vertex_decl_size), "data not equal to shader declaration\n");
2245 HeapFree(GetProcessHeap(), 0, data);
2246 /* Verify that we can retrieve the shader function */
2247 hr = IDirect3DDevice8_GetVertexShaderFunction(device, hVertexShader, NULL, &data_size);
2248 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderFunction returned %#08x\n", hr);
2249 ok(data_size == simple_vs_size, "Got data_size %u, expected %u\n", data_size, simple_vs_size);
2250 data = HeapAlloc(GetProcessHeap(), 0, simple_vs_size);
2251 data_size = 1;
2252 hr = IDirect3DDevice8_GetVertexShaderFunction(device, hVertexShader, data, &data_size);
2253 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_GetVertexShaderFunction returned (%#08x), "
2254 "expected D3DERR_INVALIDCALL\n", hr);
2255 ok(data_size == 1, "Got data_size %u, expected 1\n", data_size);
2256 data_size = simple_vs_size;
2257 hr = IDirect3DDevice8_GetVertexShaderFunction(device, hVertexShader, data, &data_size);
2258 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderFunction returned %#08x\n", hr);
2259 ok(data_size == simple_vs_size, "Got data_size %u, expected %u\n", data_size, simple_vs_size);
2260 ok(!memcmp(data, simple_vs, simple_vs_size), "data not equal to shader function\n");
2261 HeapFree(GetProcessHeap(), 0, data);
2262 /* Delete the assigned shader. This is supposed to work */
2263 hr = IDirect3DDevice8_DeleteVertexShader(device, hVertexShader);
2264 ok(hr == D3D_OK, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
2265 /* The shader should be unset now */
2266 hr = IDirect3DDevice8_GetVertexShader(device, &hTempHandle);
2267 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
2268 ok(hTempHandle == 0, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, 0);
2270 /* Test a broken declaration. 3DMark2001 tries to use normals with 2 components
2271 * First try the fixed function shader function, then a custom one
2273 hr = IDirect3DDevice8_CreateVertexShader(device, decl_normal_float2, 0, &hVertexShader, 0);
2274 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
2275 hr = IDirect3DDevice8_CreateVertexShader(device, decl_normal_float4, 0, &hVertexShader, 0);
2276 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
2277 hr = IDirect3DDevice8_CreateVertexShader(device, decl_normal_d3dcolor, 0, &hVertexShader, 0);
2278 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
2280 hr = IDirect3DDevice8_CreateVertexShader(device, decl_normal_float2, simple_vs, &hVertexShader, 0);
2281 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
2282 IDirect3DDevice8_DeleteVertexShader(device, hVertexShader);
2284 if (caps.PixelShaderVersion >= D3DPS_VERSION(1, 0))
2286 /* The same with a pixel shader */
2287 hr = IDirect3DDevice8_CreatePixelShader(device, simple_ps, &hPixelShader);
2288 ok(hr == D3D_OK, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr);
2289 /* Msdn says that the new pixel shader is set immediately. This is wrong, apparently */
2290 hr = IDirect3DDevice8_GetPixelShader(device, &hTempHandle);
2291 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr);
2292 ok(hTempHandle == 0, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, 0);
2293 /* Assign the shader, then verify that GetPixelShader works */
2294 hr = IDirect3DDevice8_SetPixelShader(device, hPixelShader);
2295 ok(hr == D3D_OK, "IDirect3DDevice8_SetPixelShader returned %#08x\n", hr);
2296 hr = IDirect3DDevice8_GetPixelShader(device, &hTempHandle);
2297 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr);
2298 ok(hTempHandle == hPixelShader, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, hPixelShader);
2299 /* Verify that we can retrieve the shader function */
2300 hr = IDirect3DDevice8_GetPixelShaderFunction(device, hPixelShader, NULL, &data_size);
2301 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShaderFunction returned %#08x\n", hr);
2302 ok(data_size == simple_ps_size, "Got data_size %u, expected %u\n", data_size, simple_ps_size);
2303 data = HeapAlloc(GetProcessHeap(), 0, simple_ps_size);
2304 data_size = 1;
2305 hr = IDirect3DDevice8_GetPixelShaderFunction(device, hPixelShader, data, &data_size);
2306 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_GetPixelShaderFunction returned (%#08x), "
2307 "expected D3DERR_INVALIDCALL\n", hr);
2308 ok(data_size == 1, "Got data_size %u, expected 1\n", data_size);
2309 data_size = simple_ps_size;
2310 hr = IDirect3DDevice8_GetPixelShaderFunction(device, hPixelShader, data, &data_size);
2311 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShaderFunction returned %#08x\n", hr);
2312 ok(data_size == simple_ps_size, "Got data_size %u, expected %u\n", data_size, simple_ps_size);
2313 ok(!memcmp(data, simple_ps, simple_ps_size), "data not equal to shader function\n");
2314 HeapFree(GetProcessHeap(), 0, data);
2315 /* Delete the assigned shader. This is supposed to work */
2316 hr = IDirect3DDevice8_DeletePixelShader(device, hPixelShader);
2317 ok(hr == D3D_OK, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
2318 /* The shader should be unset now */
2319 hr = IDirect3DDevice8_GetPixelShader(device, &hTempHandle);
2320 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr);
2321 ok(hTempHandle == 0, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, 0);
2323 /* What happens if a non-bound shader is deleted? */
2324 hr = IDirect3DDevice8_CreatePixelShader(device, simple_ps, &hPixelShader);
2325 ok(hr == D3D_OK, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr);
2326 hr = IDirect3DDevice8_CreatePixelShader(device, simple_ps, &hPixelShader2);
2327 ok(hr == D3D_OK, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr);
2329 hr = IDirect3DDevice8_SetPixelShader(device, hPixelShader);
2330 ok(hr == D3D_OK, "IDirect3DDevice8_SetPixelShader returned %#08x\n", hr);
2331 hr = IDirect3DDevice8_DeletePixelShader(device, hPixelShader2);
2332 ok(hr == D3D_OK, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
2333 hr = IDirect3DDevice8_GetPixelShader(device, &hTempHandle);
2334 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr);
2335 ok(hTempHandle == hPixelShader, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, hPixelShader);
2336 hr = IDirect3DDevice8_DeletePixelShader(device, hPixelShader);
2337 ok(hr == D3D_OK, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
2339 /* Check for double delete. */
2340 hr = IDirect3DDevice8_DeletePixelShader(device, hPixelShader2);
2341 ok(hr == D3DERR_INVALIDCALL || broken(hr == D3D_OK), "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
2342 hr = IDirect3DDevice8_DeletePixelShader(device, hPixelShader);
2343 ok(hr == D3DERR_INVALIDCALL || broken(hr == D3D_OK), "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
2345 else
2347 skip("Pixel shaders not supported\n");
2350 /* What happens if a non-bound shader is deleted? */
2351 hr = IDirect3DDevice8_CreateVertexShader(device, dwVertexDecl, NULL, &hVertexShader, 0);
2352 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
2353 hr = IDirect3DDevice8_CreateVertexShader(device, dwVertexDecl, NULL, &hVertexShader2, 0);
2354 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
2356 hr = IDirect3DDevice8_SetVertexShader(device, hVertexShader);
2357 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
2358 hr = IDirect3DDevice8_DeleteVertexShader(device, hVertexShader2);
2359 ok(hr == D3D_OK, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
2360 hr = IDirect3DDevice8_GetVertexShader(device, &hTempHandle);
2361 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
2362 ok(hTempHandle == hVertexShader, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, hVertexShader);
2363 hr = IDirect3DDevice8_DeleteVertexShader(device, hVertexShader);
2364 ok(hr == D3D_OK, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
2366 /* Check for double delete. */
2367 hr = IDirect3DDevice8_DeleteVertexShader(device, hVertexShader2);
2368 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
2369 hr = IDirect3DDevice8_DeleteVertexShader(device, hVertexShader);
2370 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
2372 refcount = IDirect3DDevice8_Release(device);
2373 ok(!refcount, "Device has %u references left.\n", refcount);
2374 cleanup:
2375 IDirect3D8_Release(d3d);
2376 DestroyWindow(window);
2379 static void test_limits(void)
2381 IDirect3DTexture8 *texture;
2382 IDirect3DDevice8 *device;
2383 IDirect3D8 *d3d;
2384 unsigned int i;
2385 ULONG refcount;
2386 HWND window;
2387 HRESULT hr;
2389 window = create_window();
2390 ok(!!window, "Failed to create a window.\n");
2391 d3d = Direct3DCreate8(D3D_SDK_VERSION);
2392 ok(!!d3d, "Failed to create a D3D object.\n");
2393 if (!(device = create_device(d3d, window, NULL)))
2395 skip("Failed to create a 3D device, skipping test.\n");
2396 goto cleanup;
2399 hr = IDirect3DDevice8_CreateTexture(device, 16, 16, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture);
2400 ok(hr == D3D_OK, "IDirect3DDevice8_CreateTexture failed with %#08x\n", hr);
2402 /* There are 8 texture stages. We should be able to access all of them */
2403 for (i = 0; i < 8; ++i)
2405 hr = IDirect3DDevice8_SetTexture(device, i, (IDirect3DBaseTexture8 *)texture);
2406 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %#08x\n", i, hr);
2407 hr = IDirect3DDevice8_SetTexture(device, i, NULL);
2408 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %#08x\n", i, hr);
2409 hr = IDirect3DDevice8_SetTextureStageState(device, i, D3DTSS_COLOROP, D3DTOP_ADD);
2410 ok(hr == D3D_OK, "IDirect3DDevice8_SetTextureStageState for texture %d failed with %#08x\n", i, hr);
2413 /* Investigations show that accessing higher textures stage states does
2414 * not return an error either. Writing to too high texture stages
2415 * (approximately texture 40) causes memory corruption in windows, so
2416 * there is no bounds checking. */
2417 IDirect3DTexture8_Release(texture);
2418 refcount = IDirect3DDevice8_Release(device);
2419 ok(!refcount, "Device has %u references left.\n", refcount);
2420 cleanup:
2421 IDirect3D8_Release(d3d);
2422 DestroyWindow(window);
2425 static void test_lights(void)
2427 IDirect3DDevice8 *device;
2428 IDirect3D8 *d3d8;
2429 ULONG refcount;
2430 HWND window;
2431 HRESULT hr;
2432 unsigned int i;
2433 BOOL enabled;
2434 D3DCAPS8 caps;
2436 window = create_window();
2437 ok(!!window, "Failed to create a window.\n");
2438 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
2439 ok(!!d3d8, "Failed to create a D3D object.\n");
2440 if (!(device = create_device(d3d8, window, NULL)))
2442 skip("Failed to create a 3D device, skipping test.\n");
2443 goto cleanup;
2446 memset(&caps, 0, sizeof(caps));
2447 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
2448 ok(hr == D3D_OK, "IDirect3DDevice8_GetDeviceCaps failed with %08x\n", hr);
2450 for(i = 1; i <= caps.MaxActiveLights; i++) {
2451 hr = IDirect3DDevice8_LightEnable(device, i, TRUE);
2452 ok(hr == D3D_OK, "Enabling light %u failed with %08x\n", i, hr);
2453 hr = IDirect3DDevice8_GetLightEnable(device, i, &enabled);
2454 ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL),
2455 "GetLightEnable on light %u failed with %08x\n", i, hr);
2456 ok(enabled, "Light %d is %s\n", i, enabled ? "enabled" : "disabled");
2459 /* TODO: Test the rendering results in this situation */
2460 hr = IDirect3DDevice8_LightEnable(device, i + 1, TRUE);
2461 ok(hr == D3D_OK, "Enabling one light more than supported returned %08x\n", hr);
2462 hr = IDirect3DDevice8_GetLightEnable(device, i + 1, &enabled);
2463 ok(hr == D3D_OK, "GetLightEnable on light %u failed with %08x\n", i + 1, hr);
2464 ok(enabled, "Light %d is %s\n", i + 1, enabled ? "enabled" : "disabled");
2465 hr = IDirect3DDevice8_LightEnable(device, i + 1, FALSE);
2466 ok(hr == D3D_OK, "Disabling the additional returned %08x\n", hr);
2468 for(i = 1; i <= caps.MaxActiveLights; i++) {
2469 hr = IDirect3DDevice8_LightEnable(device, i, FALSE);
2470 ok(hr == D3D_OK, "Disabling light %u failed with %08x\n", i, hr);
2473 refcount = IDirect3DDevice8_Release(device);
2474 ok(!refcount, "Device has %u references left.\n", refcount);
2475 cleanup:
2476 IDirect3D8_Release(d3d8);
2477 DestroyWindow(window);
2480 static void test_set_stream_source(void)
2482 IDirect3DVertexBuffer8 *vb, *current_vb;
2483 IDirect3DDevice8 *device;
2484 unsigned int stride;
2485 IDirect3D8 *d3d8;
2486 ULONG refcount;
2487 HWND window;
2488 HRESULT hr;
2490 window = create_window();
2491 ok(!!window, "Failed to create a window.\n");
2492 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
2493 ok(!!d3d8, "Failed to create a D3D object.\n");
2494 if (!(device = create_device(d3d8, window, NULL)))
2496 skip("Failed to create a 3D device, skipping test.\n");
2497 goto cleanup;
2500 hr = IDirect3DDevice8_CreateVertexBuffer(device, 512, 0, 0, D3DPOOL_DEFAULT, &vb);
2501 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
2503 hr = IDirect3DDevice8_SetStreamSource(device, 0, vb, 32);
2504 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
2506 hr = IDirect3DDevice8_SetStreamSource(device, 0, NULL, 0);
2507 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
2508 hr = IDirect3DDevice8_GetStreamSource(device, 0, &current_vb, &stride);
2509 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
2510 ok(!current_vb, "Got unexpected vb %p.\n", current_vb);
2511 ok(stride == 32, "Got unexpected stride %u.\n", stride);
2513 hr = IDirect3DDevice8_SetStreamSource(device, 0, vb, 0);
2514 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
2515 hr = IDirect3DDevice8_GetStreamSource(device, 0, &current_vb, &stride);
2516 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
2517 ok(current_vb == vb, "Got unexpected vb %p.\n", current_vb);
2518 IDirect3DVertexBuffer8_Release(current_vb);
2519 ok(!stride, "Got unexpected stride %u.\n", stride);
2521 IDirect3DVertexBuffer8_Release(vb);
2522 refcount = IDirect3DDevice8_Release(device);
2523 ok(!refcount, "Device has %u references left.\n", refcount);
2524 cleanup:
2525 IDirect3D8_Release(d3d8);
2526 DestroyWindow(window);
2529 static void test_render_zero_triangles(void)
2531 IDirect3DDevice8 *device;
2532 IDirect3D8 *d3d8;
2533 ULONG refcount;
2534 HWND window;
2535 HRESULT hr;
2537 static const struct
2539 struct vec3 position;
2540 struct vec3 normal;
2541 DWORD diffuse;
2543 quad[] =
2545 {{0.0f, -1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
2546 {{0.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
2547 {{1.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
2548 {{1.0f, -1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
2551 window = create_window();
2552 ok(!!window, "Failed to create a window.\n");
2553 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
2554 ok(!!d3d8, "Failed to create a D3D object.\n");
2555 if (!(device = create_device(d3d8, window, NULL)))
2557 skip("Failed to create a 3D device, skipping test.\n");
2558 goto cleanup;
2561 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
2562 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
2564 hr = IDirect3DDevice8_BeginScene(device);
2565 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
2566 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 0 /* NumVerts */,
2567 0 /* PrimCount */, NULL, D3DFMT_INDEX16, quad, sizeof(quad[0]));
2568 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
2569 hr = IDirect3DDevice8_EndScene(device);
2570 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
2572 IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
2574 refcount = IDirect3DDevice8_Release(device);
2575 ok(!refcount, "Device has %u references left.\n", refcount);
2576 cleanup:
2577 IDirect3D8_Release(d3d8);
2578 DestroyWindow(window);
2581 static void test_depth_stencil_reset(void)
2583 D3DPRESENT_PARAMETERS present_parameters;
2584 D3DDISPLAYMODE display_mode;
2585 IDirect3DSurface8 *surface, *orig_rt;
2586 IDirect3DDevice8 *device = NULL;
2587 IDirect3D8 *d3d8;
2588 UINT refcount;
2589 HRESULT hr;
2590 HWND hwnd;
2592 hwnd = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
2593 100, 100, 160, 160, NULL, NULL, NULL, NULL);
2594 ok(!!hwnd, "Failed to create a window.\n");
2595 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
2596 ok(!!d3d8, "Failed to create a D3D object.\n");
2598 IDirect3D8_GetAdapterDisplayMode(d3d8, D3DADAPTER_DEFAULT, &display_mode);
2599 memset(&present_parameters, 0, sizeof(present_parameters));
2600 present_parameters.Windowed = TRUE;
2601 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
2602 present_parameters.BackBufferFormat = display_mode.Format;
2603 present_parameters.EnableAutoDepthStencil = TRUE;
2604 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
2606 hr = IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
2607 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device);
2608 if(FAILED(hr))
2610 skip("could not create device, IDirect3D8_CreateDevice returned %#x\n", hr);
2611 goto cleanup;
2614 hr = IDirect3DDevice8_GetRenderTarget(device, &orig_rt);
2615 ok(hr == D3D_OK, "GetRenderTarget failed with 0x%08x\n", hr);
2617 hr = IDirect3DDevice8_TestCooperativeLevel(device);
2618 ok(SUCCEEDED(hr), "TestCooperativeLevel failed with %#x\n", hr);
2620 hr = IDirect3DDevice8_SetRenderTarget(device, NULL, NULL);
2621 ok(hr == D3D_OK, "SetRenderTarget failed with 0x%08x\n", hr);
2623 hr = IDirect3DDevice8_GetRenderTarget(device, &surface);
2624 ok(hr == D3D_OK, "GetRenderTarget failed with 0x%08x\n", hr);
2625 ok(surface == orig_rt, "Render target is %p, should be %p\n", surface, orig_rt);
2626 if (surface) IDirect3DSurface8_Release(surface);
2627 IDirect3DSurface8_Release(orig_rt);
2629 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surface);
2630 ok(hr == D3DERR_NOTFOUND, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr);
2631 ok(surface == NULL, "Depth stencil should be NULL\n");
2633 present_parameters.EnableAutoDepthStencil = TRUE;
2634 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
2635 hr = IDirect3DDevice8_Reset(device, &present_parameters);
2636 ok(hr == D3D_OK, "Reset failed with 0x%08x\n", hr);
2638 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surface);
2639 ok(hr == D3D_OK, "GetDepthStencilSurface failed with 0x%08x\n", hr);
2640 ok(surface != NULL, "Depth stencil should not be NULL\n");
2641 if (surface) IDirect3DSurface8_Release(surface);
2643 present_parameters.EnableAutoDepthStencil = FALSE;
2644 hr = IDirect3DDevice8_Reset(device, &present_parameters);
2645 ok(hr == D3D_OK, "Reset failed with 0x%08x\n", hr);
2647 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surface);
2648 ok(hr == D3DERR_NOTFOUND, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr);
2649 ok(surface == NULL, "Depth stencil should be NULL\n");
2651 refcount = IDirect3DDevice8_Release(device);
2652 ok(!refcount, "Device has %u references left.\n", refcount);
2653 device = NULL;
2655 IDirect3D8_GetAdapterDisplayMode( d3d8, D3DADAPTER_DEFAULT, &display_mode );
2657 ZeroMemory( &present_parameters, sizeof(present_parameters) );
2658 present_parameters.Windowed = TRUE;
2659 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
2660 present_parameters.BackBufferFormat = display_mode.Format;
2661 present_parameters.EnableAutoDepthStencil = FALSE;
2662 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
2664 hr = IDirect3D8_CreateDevice( d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
2665 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device );
2667 if(FAILED(hr))
2669 skip("could not create device, IDirect3D8_CreateDevice returned %#x\n", hr);
2670 goto cleanup;
2673 hr = IDirect3DDevice8_TestCooperativeLevel(device);
2674 ok(hr == D3D_OK, "IDirect3DDevice8_TestCooperativeLevel after creation returned %#x\n", hr);
2676 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
2677 present_parameters.Windowed = TRUE;
2678 present_parameters.BackBufferWidth = 400;
2679 present_parameters.BackBufferHeight = 300;
2680 present_parameters.EnableAutoDepthStencil = TRUE;
2681 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
2683 hr = IDirect3DDevice8_Reset(device, &present_parameters);
2684 ok(hr == D3D_OK, "IDirect3DDevice8_Reset failed with 0x%08x\n", hr);
2686 if (FAILED(hr)) goto cleanup;
2688 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surface);
2689 ok(hr == D3D_OK, "GetDepthStencilSurface failed with 0x%08x\n", hr);
2690 ok(surface != NULL, "Depth stencil should not be NULL\n");
2691 if (surface) IDirect3DSurface8_Release(surface);
2693 cleanup:
2694 if (device)
2696 refcount = IDirect3DDevice8_Release(device);
2697 ok(!refcount, "Device has %u references left.\n", refcount);
2699 IDirect3D8_Release(d3d8);
2700 DestroyWindow(hwnd);
2703 static HWND filter_messages;
2705 enum message_window
2707 DEVICE_WINDOW,
2708 FOCUS_WINDOW,
2711 struct message
2713 UINT message;
2714 enum message_window window;
2715 BOOL check_wparam;
2716 WPARAM expect_wparam;
2717 HRESULT device_state;
2718 WINDOWPOS *store_wp;
2721 static const struct message *expect_messages;
2722 static HWND device_window, focus_window;
2723 static LONG windowposchanged_received, syscommand_received;
2724 static IDirect3DDevice8 *focus_test_device;
2726 struct wndproc_thread_param
2728 HWND dummy_window;
2729 HANDLE window_created;
2730 HANDLE test_finished;
2731 BOOL running_in_foreground;
2734 static LRESULT CALLBACK test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
2736 HRESULT hr;
2738 if (filter_messages && filter_messages == hwnd)
2740 if (message != WM_DISPLAYCHANGE && message != WM_IME_NOTIFY)
2741 todo_wine ok(0, "Received unexpected message %#x for window %p.\n", message, hwnd);
2744 if (expect_messages)
2746 HWND w;
2748 switch (expect_messages->window)
2750 case DEVICE_WINDOW:
2751 w = device_window;
2752 break;
2754 case FOCUS_WINDOW:
2755 w = focus_window;
2756 break;
2758 default:
2759 w = NULL;
2760 break;
2763 if (hwnd == w && expect_messages->message == message)
2765 if (expect_messages->check_wparam)
2766 ok(wparam == expect_messages->expect_wparam,
2767 "Got unexpected wparam %lx for message %x, expected %lx.\n",
2768 wparam, message, expect_messages->expect_wparam);
2770 if (expect_messages->store_wp)
2771 *expect_messages->store_wp = *(WINDOWPOS *)lparam;
2773 if (focus_test_device)
2775 hr = IDirect3DDevice8_TestCooperativeLevel(focus_test_device);
2776 /* Wined3d marks the device lost earlier than Windows (it follows ddraw
2777 * behavior. See test_wndproc before the focus_loss_messages sequence
2778 * about the D3DERR_DEVICENOTRESET behavior, */
2779 todo_wine_if(message != WM_ACTIVATEAPP || hr == D3D_OK)
2780 ok(hr == expect_messages->device_state,
2781 "Got device state %#x on message %#x, expected %#x.\n",
2782 hr, message, expect_messages->device_state);
2785 ++expect_messages;
2789 /* KDE randomly does something with the hidden window during the
2790 * mode change that sometimes generates a WM_WINDOWPOSCHANGING
2791 * message. A WM_WINDOWPOSCHANGED message is not generated, so
2792 * just flag WM_WINDOWPOSCHANGED as bad. */
2793 if (message == WM_WINDOWPOSCHANGED)
2794 InterlockedIncrement(&windowposchanged_received);
2795 else if (message == WM_SYSCOMMAND)
2796 InterlockedIncrement(&syscommand_received);
2798 return DefWindowProcA(hwnd, message, wparam, lparam);
2801 static DWORD WINAPI wndproc_thread(void *param)
2803 struct wndproc_thread_param *p = param;
2804 DWORD res;
2805 BOOL ret;
2807 p->dummy_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
2808 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, registry_mode.dmPelsWidth,
2809 registry_mode.dmPelsHeight, 0, 0, 0, 0);
2810 p->running_in_foreground = SetForegroundWindow(p->dummy_window);
2812 ret = SetEvent(p->window_created);
2813 ok(ret, "SetEvent failed, last error %#x.\n", GetLastError());
2815 for (;;)
2817 MSG msg;
2819 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2820 res = WaitForSingleObject(p->test_finished, 100);
2821 if (res == WAIT_OBJECT_0) break;
2822 if (res != WAIT_TIMEOUT)
2824 ok(0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
2825 break;
2829 DestroyWindow(p->dummy_window);
2831 return 0;
2834 static void test_wndproc(void)
2836 struct wndproc_thread_param thread_params;
2837 struct device_desc device_desc;
2838 static WINDOWPOS windowpos;
2839 IDirect3DDevice8 *device;
2840 WNDCLASSA wc = {0};
2841 IDirect3D8 *d3d8;
2842 HANDLE thread;
2843 LONG_PTR proc;
2844 ULONG ref;
2845 DWORD res, tid;
2846 HWND tmp;
2847 UINT i, adapter_mode_count;
2848 HRESULT hr;
2849 D3DDISPLAYMODE d3ddm;
2850 DWORD d3d_width = 0, d3d_height = 0, user32_width = 0, user32_height = 0;
2851 DEVMODEW devmode;
2852 LONG change_ret, device_style;
2853 BOOL ret;
2855 static const struct message create_messages[] =
2857 {WM_WINDOWPOSCHANGING, FOCUS_WINDOW, FALSE, 0},
2858 /* Do not test wparam here. If device creation succeeds,
2859 * wparam is WA_ACTIVE. If device creation fails (testbot)
2860 * wparam is set to WA_INACTIVE on some Windows versions. */
2861 {WM_ACTIVATE, FOCUS_WINDOW, FALSE, 0},
2862 {WM_SETFOCUS, FOCUS_WINDOW, FALSE, 0},
2863 {WM_WINDOWPOSCHANGING, DEVICE_WINDOW, FALSE, 0},
2864 {WM_MOVE, DEVICE_WINDOW, FALSE, 0},
2865 {WM_SIZE, DEVICE_WINDOW, FALSE, 0},
2866 {0, 0, FALSE, 0},
2868 static const struct message focus_loss_messages[] =
2870 /* WM_ACTIVATE (wparam = WA_INACTIVE) is sent on Windows. It is
2871 * not reliable on X11 WMs. When the window focus follows the
2872 * mouse pointer the message is not sent.
2873 * {WM_ACTIVATE, FOCUS_WINDOW, TRUE, WA_INACTIVE}, */
2874 {WM_DISPLAYCHANGE, DEVICE_WINDOW, FALSE, 0, D3DERR_DEVICENOTRESET},
2875 /* WM_DISPLAYCHANGE is sent to the focus window too, but the order is
2876 * not deterministic. */
2877 {WM_WINDOWPOSCHANGING, DEVICE_WINDOW, FALSE, 0, D3DERR_DEVICENOTRESET},
2878 /* Windows sends WM_ACTIVATE to the device window, indicating that
2879 * SW_SHOWMINIMIZED is used instead of SW_MINIMIZE. Yet afterwards
2880 * the foreground and focus window are NULL. On Wine SW_SHOWMINIMIZED
2881 * leaves the device window active, breaking re-activation in the
2882 * lost device test.
2883 * {WM_ACTIVATE, DEVICE_WINDOW, TRUE, 0x200000 | WA_ACTIVE}, */
2884 {WM_WINDOWPOSCHANGED, DEVICE_WINDOW, FALSE, 0, D3DERR_DEVICENOTRESET},
2885 {WM_SIZE, DEVICE_WINDOW, TRUE, SIZE_MINIMIZED,
2886 D3DERR_DEVICENOTRESET},
2887 {WM_ACTIVATEAPP, FOCUS_WINDOW, TRUE, FALSE, D3DERR_DEVICELOST},
2888 /* WM_ACTIVATEAPP is sent to the device window too, but the order is
2889 * not deterministic. It may be sent after the focus window handling
2890 * or before. */
2891 {0, 0, FALSE, 0, 0},
2893 static const struct message reactivate_messages[] =
2895 {WM_WINDOWPOSCHANGING, DEVICE_WINDOW, FALSE, 0},
2896 {WM_WINDOWPOSCHANGED, DEVICE_WINDOW, FALSE, 0},
2897 {WM_MOVE, DEVICE_WINDOW, FALSE, 0},
2898 {WM_ACTIVATEAPP, FOCUS_WINDOW, TRUE, TRUE},
2899 {0, 0, FALSE, 0},
2901 static const struct message focus_loss_messages_hidden[] =
2903 {WM_DISPLAYCHANGE, DEVICE_WINDOW, FALSE, 0},
2904 {WM_ACTIVATEAPP, FOCUS_WINDOW, TRUE, FALSE},
2905 {0, 0, FALSE, 0},
2907 static const struct message focus_loss_messages_filtered[] =
2909 /* WM_ACTIVATE is delivered to the window proc because it is
2910 * generated by SetForegroundWindow before the d3d routine
2911 * starts it work. Don't check for it due to focus-follows-mouse
2912 * WMs though. */
2913 {WM_DISPLAYCHANGE, FOCUS_WINDOW, FALSE, 0},
2914 {WM_ACTIVATEAPP, FOCUS_WINDOW, TRUE, FALSE},
2915 {0, 0, FALSE, 0},
2917 static const struct message reactivate_messages_filtered[] =
2919 {WM_ACTIVATEAPP, FOCUS_WINDOW, TRUE, TRUE},
2920 {0, 0, FALSE, 0},
2922 static const struct message sc_restore_messages[] =
2924 /* WM_SYSCOMMAND is delivered only once, after d3d has already
2925 * processed it. Our wndproc has no way to prevent d3d from
2926 * handling the message. The second DefWindowProc call done by
2927 * our wndproc doesn't do any changes to the window because it
2928 * is already restored due to d3d's handling. */
2929 {WM_WINDOWPOSCHANGING, FOCUS_WINDOW, FALSE, 0},
2930 {WM_WINDOWPOSCHANGED, FOCUS_WINDOW, FALSE, 0},
2931 {WM_SIZE, FOCUS_WINDOW, TRUE, SIZE_RESTORED},
2932 {WM_SYSCOMMAND, FOCUS_WINDOW, TRUE, SC_RESTORE},
2933 {0, 0, FALSE, 0},
2935 static const struct message sc_minimize_messages[] =
2937 {WM_SYSCOMMAND, FOCUS_WINDOW, TRUE, SC_MINIMIZE},
2938 {WM_WINDOWPOSCHANGING, FOCUS_WINDOW, FALSE, 0},
2939 {WM_WINDOWPOSCHANGED, FOCUS_WINDOW, FALSE, 0},
2940 {WM_MOVE, FOCUS_WINDOW, FALSE, 0},
2941 {WM_SIZE, FOCUS_WINDOW, TRUE, SIZE_MINIMIZED},
2942 {0, 0, FALSE, 0},
2944 static const struct message sc_maximize_messages[] =
2946 {WM_SYSCOMMAND, FOCUS_WINDOW, TRUE, SC_MAXIMIZE},
2947 {WM_WINDOWPOSCHANGING, FOCUS_WINDOW, FALSE, 0},
2948 {WM_WINDOWPOSCHANGED, FOCUS_WINDOW, FALSE, 0},
2949 {WM_MOVE, FOCUS_WINDOW, FALSE, 0},
2950 {WM_SIZE, FOCUS_WINDOW, TRUE, SIZE_MAXIMIZED},
2951 {0, 0, FALSE, 0},
2953 static const struct message mode_change_messages[] =
2955 {WM_WINDOWPOSCHANGING, DEVICE_WINDOW, FALSE, 0},
2956 {WM_WINDOWPOSCHANGED, DEVICE_WINDOW, FALSE, 0},
2957 {WM_SIZE, DEVICE_WINDOW, FALSE, 0},
2958 /* TODO: WM_DISPLAYCHANGE is sent to the focus window too, but the order is
2959 * differs between Wine and Windows. */
2960 /* TODO 2: Windows sends a second WM_WINDOWPOSCHANGING(SWP_NOMOVE | SWP_NOSIZE
2961 * | SWP_NOACTIVATE) in this situation, suggesting a difference in their ShowWindow
2962 * implementation. This SetWindowPos call could in theory affect the Z order. Wine's
2963 * ShowWindow does not send such a message because the window is already visible. */
2964 {0, 0, FALSE, 0},
2966 static const struct message mode_change_messages_hidden[] =
2968 {WM_WINDOWPOSCHANGING, DEVICE_WINDOW, FALSE, 0},
2969 {WM_WINDOWPOSCHANGED, DEVICE_WINDOW, FALSE, 0},
2970 {WM_SIZE, DEVICE_WINDOW, FALSE, 0},
2971 {WM_SHOWWINDOW, DEVICE_WINDOW, FALSE, 0},
2972 {WM_WINDOWPOSCHANGING, DEVICE_WINDOW, FALSE, 0, ~0U, &windowpos},
2973 {WM_WINDOWPOSCHANGED, DEVICE_WINDOW, FALSE, 0},
2974 /* TODO: WM_DISPLAYCHANGE is sent to the focus window too, but the order is
2975 * differs between Wine and Windows. */
2976 {0, 0, FALSE, 0},
2979 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
2980 ok(!!d3d8, "Failed to create a D3D object.\n");
2982 adapter_mode_count = IDirect3D8_GetAdapterModeCount(d3d8, D3DADAPTER_DEFAULT);
2983 for (i = 0; i < adapter_mode_count; ++i)
2985 hr = IDirect3D8_EnumAdapterModes(d3d8, D3DADAPTER_DEFAULT, i, &d3ddm);
2986 ok(SUCCEEDED(hr), "Failed to enumerate display mode, hr %#x.\n", hr);
2988 if (d3ddm.Format != D3DFMT_X8R8G8B8)
2989 continue;
2990 if (d3ddm.Width == registry_mode.dmPelsWidth && d3ddm.Height == registry_mode.dmPelsHeight)
2991 continue;
2992 /* The r200 driver on Windows XP enumerates modes like 320x200 and 320x240 but
2993 * refuses to create a device at these sizes. */
2994 if (d3ddm.Width < 640 || d3ddm.Height < 480)
2995 continue;
2997 if (!user32_width)
2999 user32_width = d3ddm.Width;
3000 user32_height = d3ddm.Height;
3001 continue;
3004 /* Make sure the d3d mode is smaller in width or height and at most
3005 * equal in the other dimension than the mode passed to
3006 * ChangeDisplaySettings. Otherwise Windows shrinks the window to
3007 * the ChangeDisplaySettings parameters + 12. */
3008 if (d3ddm.Width == user32_width && d3ddm.Height == user32_height)
3009 continue;
3010 if (d3ddm.Width <= user32_width && d3ddm.Height <= user32_height)
3012 d3d_width = d3ddm.Width;
3013 d3d_height = d3ddm.Height;
3014 break;
3016 if (user32_width <= d3ddm.Width && user32_height <= d3ddm.Height)
3018 d3d_width = user32_width;
3019 d3d_height = user32_height;
3020 user32_width = d3ddm.Width;
3021 user32_height = d3ddm.Height;
3022 break;
3026 if (!d3d_width)
3028 skip("Could not find adequate modes, skipping mode tests.\n");
3029 IDirect3D8_Release(d3d8);
3030 return;
3033 filter_messages = NULL;
3034 expect_messages = NULL;
3036 wc.lpfnWndProc = test_proc;
3037 wc.lpszClassName = "d3d8_test_wndproc_wc";
3038 ok(RegisterClassA(&wc), "Failed to register window class.\n");
3040 thread_params.window_created = CreateEventA(NULL, FALSE, FALSE, NULL);
3041 ok(!!thread_params.window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
3042 thread_params.test_finished = CreateEventA(NULL, FALSE, FALSE, NULL);
3043 ok(!!thread_params.test_finished, "CreateEvent failed, last error %#x.\n", GetLastError());
3045 memset(&devmode, 0, sizeof(devmode));
3046 devmode.dmSize = sizeof(devmode);
3047 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
3048 devmode.dmPelsWidth = user32_width;
3049 devmode.dmPelsHeight = user32_height;
3050 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
3051 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
3053 focus_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
3054 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION , 0, 0, user32_width, user32_height, 0, 0, 0, 0);
3055 device_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
3056 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION , 0, 0, user32_width, user32_height, 0, 0, 0, 0);
3057 thread = CreateThread(NULL, 0, wndproc_thread, &thread_params, 0, &tid);
3058 ok(!!thread, "Failed to create thread, last error %#x.\n", GetLastError());
3060 res = WaitForSingleObject(thread_params.window_created, INFINITE);
3061 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
3063 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
3064 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3065 (LONG_PTR)test_proc, proc);
3066 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3067 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3068 (LONG_PTR)test_proc, proc);
3070 trace("device_window %p, focus_window %p, dummy_window %p.\n",
3071 device_window, focus_window, thread_params.dummy_window);
3073 tmp = GetFocus();
3074 ok(tmp == device_window, "Expected focus %p, got %p.\n", device_window, tmp);
3075 if (thread_params.running_in_foreground)
3077 tmp = GetForegroundWindow();
3078 ok(tmp == thread_params.dummy_window, "Expected foreground window %p, got %p.\n",
3079 thread_params.dummy_window, tmp);
3081 else
3082 skip("Not running in foreground, skip foreground window test\n");
3084 flush_events();
3086 expect_messages = create_messages;
3088 device_desc.adapter_ordinal = D3DADAPTER_DEFAULT;
3089 device_desc.device_window = device_window;
3090 device_desc.width = d3d_width;
3091 device_desc.height = d3d_height;
3092 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
3093 if (!(device = create_device(d3d8, focus_window, &device_desc)))
3095 skip("Failed to create a D3D device, skipping tests.\n");
3096 goto done;
3099 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
3100 expect_messages->message, expect_messages->window);
3101 expect_messages = NULL;
3103 if (0) /* Disabled until we can make this work in a reliable way on Wine. */
3105 tmp = GetFocus();
3106 ok(tmp == focus_window, "Expected focus %p, got %p.\n", focus_window, tmp);
3107 tmp = GetForegroundWindow();
3108 ok(tmp == focus_window, "Expected foreground window %p, got %p.\n", focus_window, tmp);
3110 SetForegroundWindow(focus_window);
3111 flush_events();
3113 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
3114 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3115 (LONG_PTR)test_proc, proc);
3117 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3118 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx.\n", (LONG_PTR)test_proc);
3120 /* Change the mode while the device is in use and then drop focus. */
3121 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
3122 devmode.dmPelsWidth = user32_width;
3123 devmode.dmPelsHeight = user32_height;
3124 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
3125 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x, i=%u.\n", change_ret, i);
3127 /* Wine doesn't (yet) mark the device not reset when the mode is changed, thus the todo_wine.
3128 * But sometimes focus-follows-mouse WMs also temporarily drop window focus, which makes
3129 * mark the device lost, then not reset, causing the test to succeed for the wrong reason. */
3130 hr = IDirect3DDevice8_TestCooperativeLevel(device);
3131 todo_wine_if (hr != D3DERR_DEVICENOTRESET)
3132 ok(hr == D3DERR_DEVICENOTRESET, "Got unexpected hr %#x.\n", hr);
3134 expect_messages = focus_loss_messages;
3135 focus_test_device = device;
3136 /* SetForegroundWindow is a poor replacement for the user pressing alt-tab or
3137 * manually changing the focus. It generates the same messages, but the task
3138 * bar still shows the previous foreground window as active, and the window has
3139 * an inactive titlebar if reactivated with SetForegroundWindow. Reactivating
3140 * the device is difficult, see below. */
3141 SetForegroundWindow(GetDesktopWindow());
3142 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
3143 expect_messages->message, expect_messages->window);
3144 expect_messages = NULL;
3145 tmp = GetFocus();
3146 ok(tmp != device_window, "The device window is active.\n");
3147 ok(tmp != focus_window, "The focus window is active.\n");
3148 focus_test_device = NULL;
3150 /* The Present call is necessary to make native realize the device is lost. */
3151 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
3152 ok(hr == D3DERR_DEVICELOST, "Got unexpected hr %#x.\n", hr);
3153 hr = IDirect3DDevice8_TestCooperativeLevel(device);
3154 /* Focus-follows-mouse WMs prematurely reactivate our window. */
3155 todo_wine_if (hr == D3DERR_DEVICENOTRESET)
3156 ok(hr == D3DERR_DEVICELOST, "Got unexpected hr %#x.\n", hr);
3158 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
3159 ok(ret, "Failed to get display mode.\n");
3160 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
3161 && devmode.dmPelsHeight == registry_mode.dmPelsHeight, "Got unexpected screen size %ux%u.\n",
3162 devmode.dmPelsWidth, devmode.dmPelsHeight);
3164 /* I have to minimize and restore the focus window, otherwise native d3d8 fails
3165 * device::reset with D3DERR_DEVICELOST. This does not happen when the window
3166 * restore is triggered by the user. */
3167 expect_messages = reactivate_messages;
3168 ShowWindow(focus_window, SW_MINIMIZE);
3169 ShowWindow(focus_window, SW_RESTORE);
3170 /* Set focus twice to make KDE and fvwm in focus-follows-mouse mode happy. */
3171 SetForegroundWindow(focus_window);
3172 flush_events();
3173 SetForegroundWindow(focus_window);
3174 flush_events(); /* WM_WINDOWPOSCHANGING etc arrive after SetForegroundWindow returns. */
3175 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it, i=%u.\n",
3176 expect_messages->message, expect_messages->window, i);
3177 expect_messages = NULL;
3179 hr = IDirect3DDevice8_TestCooperativeLevel(device);
3180 ok(hr == D3DERR_DEVICENOTRESET, "Got unexpected hr %#x.\n", hr);
3182 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
3183 ok(ret, "Failed to get display mode.\n");
3184 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
3185 && devmode.dmPelsHeight == registry_mode.dmPelsHeight, "Got unexpected screen size %ux%u.\n",
3186 devmode.dmPelsWidth, devmode.dmPelsHeight);
3188 hr = reset_device(device, &device_desc);
3189 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
3191 /* Remove the WS_VISIBLE flag to test hidden windows. This is enough to trigger d3d's hidden
3192 * window codepath, but does not actually hide the window without a SetWindowPos(SWP_FRAMECHANGED)
3193 * call. This way we avoid focus changes and random failures on focus follows mouse WMs. */
3194 device_style = GetWindowLongA(device_window, GWL_STYLE);
3195 SetWindowLongA(device_window, GWL_STYLE, device_style & ~WS_VISIBLE);
3196 flush_events();
3198 expect_messages = focus_loss_messages_hidden;
3199 windowposchanged_received = 0;
3200 SetForegroundWindow(GetDesktopWindow());
3201 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
3202 expect_messages->message, expect_messages->window);
3203 ok(!windowposchanged_received, "Received WM_WINDOWPOSCHANGED but did not expect it.\n");
3204 expect_messages = NULL;
3205 flush_events();
3207 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
3208 ok(ret, "Failed to get display mode.\n");
3209 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth, "Got unexpected width %u.\n", devmode.dmPelsWidth);
3210 ok(devmode.dmPelsHeight == registry_mode.dmPelsHeight, "Got unexpected height %u.\n", devmode.dmPelsHeight);
3212 /* SW_SHOWMINNOACTIVE is needed to make FVWM happy. SW_SHOWNOACTIVATE is needed to make windows
3213 * send SIZE_RESTORED after ShowWindow(SW_SHOWMINNOACTIVE). */
3214 ShowWindow(focus_window, SW_SHOWNOACTIVATE);
3215 ShowWindow(focus_window, SW_SHOWMINNOACTIVE);
3216 flush_events();
3218 syscommand_received = 0;
3219 expect_messages = sc_restore_messages;
3220 SendMessageA(focus_window, WM_SYSCOMMAND, SC_RESTORE, 0);
3221 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
3222 expect_messages->message, expect_messages->window);
3223 ok(syscommand_received == 1, "Got unexpected number of WM_SYSCOMMAND messages: %d.\n", syscommand_received);
3224 expect_messages = NULL;
3225 flush_events();
3227 expect_messages = sc_minimize_messages;
3228 SendMessageA(focus_window, WM_SYSCOMMAND, SC_MINIMIZE, 0);
3229 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
3230 expect_messages->message, expect_messages->window);
3231 expect_messages = NULL;
3232 flush_events();
3234 expect_messages = sc_maximize_messages;
3235 SendMessageA(focus_window, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
3236 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
3237 expect_messages->message, expect_messages->window);
3238 expect_messages = NULL;
3239 flush_events();
3241 SetForegroundWindow(GetDesktopWindow());
3242 ShowWindow(device_window, SW_MINIMIZE);
3243 ShowWindow(focus_window, SW_MINIMIZE);
3244 ShowWindow(focus_window, SW_RESTORE);
3245 SetForegroundWindow(focus_window);
3246 flush_events();
3248 /* Releasing a device in lost state breaks follow-up tests on native. */
3249 hr = reset_device(device, &device_desc);
3250 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
3252 filter_messages = focus_window;
3253 ref = IDirect3DDevice8_Release(device);
3254 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
3256 /* Fix up the mode until Wine's device release behavior is fixed. */
3257 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
3258 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
3260 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3261 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3262 (LONG_PTR)test_proc, proc);
3264 /* Hide the device window. It prevents WM_ACTIVATEAPP messages from being sent
3265 * on native in the test below. It isn't needed anyways. Creating the third
3266 * device will show it again. */
3267 filter_messages = NULL;
3268 ShowWindow(device_window, SW_HIDE);
3269 /* Remove the maximized state from the SYSCOMMAND test while we're not
3270 * interfering with a device. */
3271 ShowWindow(focus_window, SW_SHOWNORMAL);
3273 /* On Windows 10 style change messages are delivered on device
3274 * creation. */
3275 device_desc.device_window = focus_window;
3276 if (!(device = create_device(d3d8, focus_window, &device_desc)))
3278 skip("Failed to create a D3D device, skipping tests.\n");
3279 goto done;
3282 filter_messages = NULL;
3284 expect_messages = focus_loss_messages_filtered;
3285 windowposchanged_received = 0;
3286 SetForegroundWindow(GetDesktopWindow());
3287 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
3288 expect_messages->message, expect_messages->window);
3289 expect_messages = NULL;
3291 /* The window is iconic even though no message was sent. */
3292 ok(IsIconic(focus_window), "The focus window is not iconic.\n");
3294 hr = IDirect3DDevice8_TestCooperativeLevel(device);
3295 ok(hr == D3DERR_DEVICELOST, "Got unexpected hr %#x.\n", hr);
3297 syscommand_received = 0;
3298 expect_messages = sc_restore_messages;
3299 SendMessageA(focus_window, WM_SYSCOMMAND, SC_RESTORE, 0);
3300 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
3301 expect_messages->message, expect_messages->window);
3302 ok(syscommand_received == 1, "Got unexpected number of WM_SYSCOMMAND messages: %d.\n", syscommand_received);
3303 expect_messages = NULL;
3304 flush_events();
3306 /* For FVWM. */
3307 ShowWindow(focus_window, SW_RESTORE);
3308 flush_events();
3310 expect_messages = sc_minimize_messages;
3311 SendMessageA(focus_window, WM_SYSCOMMAND, SC_MINIMIZE, 0);
3312 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
3313 expect_messages->message, expect_messages->window);
3314 expect_messages = NULL;
3315 /* Needed to make the next test reliably send WM_SIZE(SIZE_MAXIMIZED). Without
3316 * this call it sends WM_SIZE(SIZE_RESTORED). */
3317 ShowWindow(focus_window, SW_RESTORE);
3318 flush_events();
3320 expect_messages = sc_maximize_messages;
3321 SendMessageA(focus_window, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
3322 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
3323 expect_messages->message, expect_messages->window);
3324 expect_messages = NULL;
3325 flush_events();
3326 SetForegroundWindow(GetDesktopWindow());
3327 flush_events();
3329 /* ShowWindow(SW_RESTORE); SetForegroundWindow(desktop); SetForegroundWindow(focus);
3330 * results in the second SetForegroundWindow call failing and the device not being
3331 * restored on native. Directly using ShowWindow(SW_RESTORE) works, but it means
3332 * we cannot test for the absence of WM_WINDOWPOSCHANGED messages. */
3333 expect_messages = reactivate_messages_filtered;
3334 ShowWindow(focus_window, SW_RESTORE);
3335 SetForegroundWindow(focus_window);
3336 flush_events();
3337 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it\n",
3338 expect_messages->message, expect_messages->window);
3339 expect_messages = NULL;
3341 filter_messages = focus_window;
3342 hr = IDirect3DDevice8_TestCooperativeLevel(device);
3343 ok(hr == D3DERR_DEVICENOTRESET, "Got unexpected hr %#x.\n", hr);
3345 filter_messages = NULL;
3346 hr = reset_device(device, &device_desc);
3347 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
3349 ref = IDirect3DDevice8_Release(device);
3350 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
3351 filter_messages = NULL;
3353 ShowWindow(device_window, SW_RESTORE);
3354 SetForegroundWindow(focus_window);
3355 flush_events();
3357 filter_messages = focus_window;
3358 device_desc.device_window = device_window;
3359 if (!(device = create_device(d3d8, focus_window, &device_desc)))
3361 skip("Failed to create a D3D device, skipping tests.\n");
3362 goto done;
3364 filter_messages = NULL;
3365 flush_events();
3367 device_desc.width = user32_width;
3368 device_desc.height = user32_height;
3370 expect_messages = mode_change_messages;
3371 filter_messages = focus_window;
3372 hr = reset_device(device, &device_desc);
3373 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
3374 filter_messages = NULL;
3376 flush_events();
3377 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it, i=%u.\n",
3378 expect_messages->message, expect_messages->window, i);
3379 expect_messages = NULL;
3381 /* World of Warplanes hides the window by removing WS_VISIBLE and expects Reset() to show it again. */
3382 device_style = GetWindowLongA(device_window, GWL_STYLE);
3383 SetWindowLongA(device_window, GWL_STYLE, device_style & ~WS_VISIBLE);
3385 flush_events();
3386 device_desc.width = d3d_width;
3387 device_desc.height = d3d_height;
3388 memset(&windowpos, 0, sizeof(windowpos));
3390 expect_messages = mode_change_messages_hidden;
3391 filter_messages = focus_window;
3392 hr = reset_device(device, &device_desc);
3393 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
3394 filter_messages = NULL;
3396 flush_events();
3397 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
3398 expect_messages->message, expect_messages->window);
3399 expect_messages = NULL;
3401 ok(windowpos.hwnd == device_window && !windowpos.hwndInsertAfter
3402 && !windowpos.x && !windowpos.y && !windowpos.cx && !windowpos.cy
3403 && windowpos.flags == (SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE),
3404 "Got unexpected WINDOWPOS hwnd=%p, insertAfter=%p, x=%d, y=%d, cx=%d, cy=%d, flags=%x\n",
3405 windowpos.hwnd, windowpos.hwndInsertAfter, windowpos.x, windowpos.y, windowpos.cx,
3406 windowpos.cy, windowpos.flags);
3408 device_style = GetWindowLongA(device_window, GWL_STYLE);
3409 ok(device_style & WS_VISIBLE, "Expected the device window to be visible.\n");
3411 proc = SetWindowLongPtrA(focus_window, GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
3412 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx.\n", (LONG_PTR)test_proc);
3414 ref = IDirect3DDevice8_Release(device);
3415 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
3417 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3418 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
3419 (LONG_PTR)DefWindowProcA, proc);
3421 done:
3422 filter_messages = NULL;
3423 expect_messages = NULL;
3424 IDirect3D8_Release(d3d8);
3426 SetEvent(thread_params.test_finished);
3427 WaitForSingleObject(thread, INFINITE);
3428 CloseHandle(thread_params.test_finished);
3429 CloseHandle(thread_params.window_created);
3430 CloseHandle(thread);
3432 DestroyWindow(device_window);
3433 DestroyWindow(focus_window);
3434 UnregisterClassA("d3d8_test_wndproc_wc", GetModuleHandleA(NULL));
3435 change_ret = ChangeDisplaySettingsExW(NULL, NULL, NULL, 0, NULL);
3436 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsExW failed with %d.\n", change_ret);
3439 static void test_wndproc_windowed(void)
3441 struct wndproc_thread_param thread_params;
3442 struct device_desc device_desc;
3443 IDirect3DDevice8 *device;
3444 WNDCLASSA wc = {0};
3445 IDirect3D8 *d3d8;
3446 HANDLE thread;
3447 LONG_PTR proc;
3448 HRESULT hr;
3449 ULONG ref;
3450 DWORD res, tid;
3451 HWND tmp;
3453 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
3454 ok(!!d3d8, "Failed to create a D3D object.\n");
3456 filter_messages = NULL;
3457 expect_messages = NULL;
3459 wc.lpfnWndProc = test_proc;
3460 wc.lpszClassName = "d3d8_test_wndproc_wc";
3461 ok(RegisterClassA(&wc), "Failed to register window class.\n");
3463 thread_params.window_created = CreateEventA(NULL, FALSE, FALSE, NULL);
3464 ok(!!thread_params.window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
3465 thread_params.test_finished = CreateEventA(NULL, FALSE, FALSE, NULL);
3466 ok(!!thread_params.test_finished, "CreateEvent failed, last error %#x.\n", GetLastError());
3468 focus_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
3469 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, registry_mode.dmPelsWidth,
3470 registry_mode.dmPelsHeight, 0, 0, 0, 0);
3471 device_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
3472 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, registry_mode.dmPelsWidth,
3473 registry_mode.dmPelsHeight, 0, 0, 0, 0);
3474 thread = CreateThread(NULL, 0, wndproc_thread, &thread_params, 0, &tid);
3475 ok(!!thread, "Failed to create thread, last error %#x.\n", GetLastError());
3477 res = WaitForSingleObject(thread_params.window_created, INFINITE);
3478 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
3480 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
3481 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3482 (LONG_PTR)test_proc, proc);
3483 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3484 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3485 (LONG_PTR)test_proc, proc);
3487 trace("device_window %p, focus_window %p, dummy_window %p.\n",
3488 device_window, focus_window, thread_params.dummy_window);
3490 tmp = GetFocus();
3491 ok(tmp == device_window, "Expected focus %p, got %p.\n", device_window, tmp);
3492 if (thread_params.running_in_foreground)
3494 tmp = GetForegroundWindow();
3495 ok(tmp == thread_params.dummy_window, "Expected foreground window %p, got %p.\n",
3496 thread_params.dummy_window, tmp);
3498 else
3499 skip("Not running in foreground, skip foreground window test\n");
3501 filter_messages = focus_window;
3503 device_desc.adapter_ordinal = D3DADAPTER_DEFAULT;
3504 device_desc.device_window = device_window;
3505 device_desc.width = registry_mode.dmPelsWidth;
3506 device_desc.height = registry_mode.dmPelsHeight;
3507 device_desc.flags = 0;
3508 if (!(device = create_device(d3d8, focus_window, &device_desc)))
3510 skip("Failed to create a D3D device, skipping tests.\n");
3511 goto done;
3514 tmp = GetFocus();
3515 ok(tmp == device_window, "Expected focus %p, got %p.\n", device_window, tmp);
3516 tmp = GetForegroundWindow();
3517 ok(tmp == thread_params.dummy_window, "Expected foreground window %p, got %p.\n",
3518 thread_params.dummy_window, tmp);
3520 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
3521 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3522 (LONG_PTR)test_proc, proc);
3524 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3525 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3526 (LONG_PTR)test_proc, proc);
3528 filter_messages = NULL;
3530 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
3531 hr = reset_device(device, &device_desc);
3532 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
3534 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
3535 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3536 (LONG_PTR)test_proc, proc);
3538 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3539 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx.\n", (LONG_PTR)test_proc);
3541 device_desc.flags = 0;
3542 hr = reset_device(device, &device_desc);
3543 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
3545 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
3546 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3547 (LONG_PTR)test_proc, proc);
3549 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3550 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3551 (LONG_PTR)test_proc, proc);
3553 filter_messages = focus_window;
3555 ref = IDirect3DDevice8_Release(device);
3556 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
3558 filter_messages = device_window;
3560 device_desc.device_window = focus_window;
3561 if (!(device = create_device(d3d8, focus_window, &device_desc)))
3563 skip("Failed to create a D3D device, skipping tests.\n");
3564 goto done;
3567 filter_messages = NULL;
3569 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
3570 hr = reset_device(device, &device_desc);
3571 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
3573 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
3574 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3575 (LONG_PTR)test_proc, proc);
3577 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3578 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx.\n", (LONG_PTR)test_proc);
3580 device_desc.flags = 0;
3581 hr = reset_device(device, &device_desc);
3582 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
3584 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
3585 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3586 (LONG_PTR)test_proc, proc);
3588 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3589 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3590 (LONG_PTR)test_proc, proc);
3592 filter_messages = device_window;
3594 ref = IDirect3DDevice8_Release(device);
3595 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
3597 device_desc.device_window = device_window;
3598 if (!(device = create_device(d3d8, focus_window, &device_desc)))
3600 skip("Failed to create a D3D device, skipping tests.\n");
3601 goto done;
3604 filter_messages = NULL;
3606 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
3607 hr = reset_device(device, &device_desc);
3608 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
3610 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
3611 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3612 (LONG_PTR)test_proc, proc);
3614 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3615 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx.\n", (LONG_PTR)test_proc);
3617 device_desc.flags = 0;
3618 hr = reset_device(device, &device_desc);
3619 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
3621 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
3622 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3623 (LONG_PTR)test_proc, proc);
3625 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3626 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3627 (LONG_PTR)test_proc, proc);
3629 filter_messages = device_window;
3631 ref = IDirect3DDevice8_Release(device);
3632 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
3634 done:
3635 filter_messages = NULL;
3636 IDirect3D8_Release(d3d8);
3638 SetEvent(thread_params.test_finished);
3639 WaitForSingleObject(thread, INFINITE);
3640 CloseHandle(thread_params.test_finished);
3641 CloseHandle(thread_params.window_created);
3642 CloseHandle(thread);
3644 DestroyWindow(device_window);
3645 DestroyWindow(focus_window);
3646 UnregisterClassA("d3d8_test_wndproc_wc", GetModuleHandleA(NULL));
3649 static inline void set_fpu_cw(WORD cw)
3651 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3652 #define D3D8_TEST_SET_FPU_CW 1
3653 __asm__ volatile ("fnclex");
3654 __asm__ volatile ("fldcw %0" : : "m" (cw));
3655 #elif defined(__i386__) && defined(_MSC_VER)
3656 #define D3D8_TEST_SET_FPU_CW 1
3657 __asm fnclex;
3658 __asm fldcw cw;
3659 #endif
3662 static inline WORD get_fpu_cw(void)
3664 WORD cw = 0;
3665 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3666 #define D3D8_TEST_GET_FPU_CW 1
3667 __asm__ volatile ("fnstcw %0" : "=m" (cw));
3668 #elif defined(__i386__) && defined(_MSC_VER)
3669 #define D3D8_TEST_GET_FPU_CW 1
3670 __asm fnstcw cw;
3671 #endif
3672 return cw;
3675 static WORD callback_cw, callback_set_cw;
3676 static DWORD callback_tid;
3678 static HRESULT WINAPI dummy_object_QueryInterface(IUnknown *iface, REFIID riid, void **out)
3680 *out = NULL;
3681 return E_NOINTERFACE;
3684 static ULONG WINAPI dummy_object_AddRef(IUnknown *iface)
3686 callback_cw = get_fpu_cw();
3687 set_fpu_cw(callback_set_cw);
3688 callback_tid = GetCurrentThreadId();
3689 return 2;
3692 static ULONG WINAPI dummy_object_Release(IUnknown *iface)
3694 callback_cw = get_fpu_cw();
3695 set_fpu_cw(callback_set_cw);
3696 callback_tid = GetCurrentThreadId();
3697 return 1;
3700 static const IUnknownVtbl dummy_object_vtbl =
3702 dummy_object_QueryInterface,
3703 dummy_object_AddRef,
3704 dummy_object_Release,
3707 static const GUID d3d8_private_data_test_guid =
3709 0xfdb37466,
3710 0x428f,
3711 0x4edf,
3712 {0xa3,0x7f,0x9b,0x1d,0xf4,0x88,0xc5,0xfc}
3715 static void test_fpu_setup(void)
3717 #if defined(D3D8_TEST_SET_FPU_CW) && defined(D3D8_TEST_GET_FPU_CW)
3718 struct device_desc device_desc;
3719 IDirect3DDevice8 *device;
3720 D3DDISPLAYMODE d3ddm;
3721 IDirect3D8 *d3d8;
3722 HWND window;
3723 HRESULT hr;
3724 WORD cw;
3725 IDirect3DSurface8 *surface;
3726 IUnknown dummy_object = {&dummy_object_vtbl};
3728 window = create_window();
3729 ok(!!window, "Failed to create a window.\n");
3730 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
3731 ok(!!d3d8, "Failed to create a D3D object.\n");
3733 hr = IDirect3D8_GetAdapterDisplayMode(d3d8, D3DADAPTER_DEFAULT, &d3ddm);
3734 ok(SUCCEEDED(hr), "GetAdapterDisplayMode failed, hr %#x.\n", hr);
3736 device_desc.adapter_ordinal = D3DADAPTER_DEFAULT;
3737 device_desc.device_window = window;
3738 device_desc.width = 640;
3739 device_desc.height = 480;
3740 device_desc.flags = 0;
3742 set_fpu_cw(0xf60);
3743 cw = get_fpu_cw();
3744 ok(cw == 0xf60, "cw is %#x, expected 0xf60.\n", cw);
3746 if (!(device = create_device(d3d8, window, &device_desc)))
3748 skip("Failed to create a 3D device, skipping test.\n");
3749 set_fpu_cw(0x37f);
3750 goto done;
3753 cw = get_fpu_cw();
3754 ok(cw == 0x7f, "cw is %#x, expected 0x7f.\n", cw);
3756 hr = IDirect3DDevice8_GetRenderTarget(device, &surface);
3757 ok(SUCCEEDED(hr), "Failed to get render target surface, hr %#x.\n", hr);
3759 callback_set_cw = 0xf60;
3760 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
3761 &dummy_object, sizeof(IUnknown *), D3DSPD_IUNKNOWN);
3762 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
3763 ok(callback_cw == 0x7f, "Callback cw is %#x, expected 0x7f.\n", callback_cw);
3764 ok(callback_tid == GetCurrentThreadId(), "Got unexpected thread id.\n");
3765 cw = get_fpu_cw();
3766 ok(cw == 0xf60, "cw is %#x, expected 0xf60.\n", cw);
3768 callback_cw = 0;
3769 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
3770 &dummy_object, sizeof(IUnknown *), D3DSPD_IUNKNOWN);
3771 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
3772 ok(callback_cw == 0xf60, "Callback cw is %#x, expected 0xf60.\n", callback_cw);
3773 ok(callback_tid == GetCurrentThreadId(), "Got unexpected thread id.\n");
3775 callback_set_cw = 0x7f;
3776 set_fpu_cw(0x7f);
3778 IDirect3DSurface8_Release(surface);
3780 callback_cw = 0;
3781 IDirect3DDevice8_Release(device);
3782 ok(callback_cw == 0x7f, "Callback cw is %#x, expected 0x7f.\n", callback_cw);
3783 ok(callback_tid == GetCurrentThreadId(), "Got unexpected thread id.\n");
3785 cw = get_fpu_cw();
3786 ok(cw == 0x7f, "cw is %#x, expected 0x7f.\n", cw);
3787 set_fpu_cw(0xf60);
3788 cw = get_fpu_cw();
3789 ok(cw == 0xf60, "cw is %#x, expected 0xf60.\n", cw);
3791 device_desc.flags = CREATE_DEVICE_FPU_PRESERVE;
3792 device = create_device(d3d8, window, &device_desc);
3793 ok(!!device, "CreateDevice failed.\n");
3795 cw = get_fpu_cw();
3796 ok(cw == 0xf60, "cw is %#x, expected 0xf60.\n", cw);
3798 hr = IDirect3DDevice8_GetRenderTarget(device, &surface);
3799 ok(SUCCEEDED(hr), "Failed to get render target surface, hr %#x.\n", hr);
3801 callback_cw = 0;
3802 callback_set_cw = 0x37f;
3803 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
3804 &dummy_object, sizeof(IUnknown *), D3DSPD_IUNKNOWN);
3805 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
3806 ok(callback_cw == 0xf60, "Callback cw is %#x, expected 0xf60.\n", callback_cw);
3807 ok(callback_tid == GetCurrentThreadId(), "Got unexpected thread id.\n");
3808 cw = get_fpu_cw();
3809 ok(cw == 0x37f, "cw is %#x, expected 0x37f.\n", cw);
3811 IDirect3DSurface8_Release(surface);
3813 callback_cw = 0;
3814 IDirect3DDevice8_Release(device);
3815 ok(callback_cw == 0x37f, "Callback cw is %#x, expected 0x37f.\n", callback_cw);
3816 ok(callback_tid == GetCurrentThreadId(), "Got unexpected thread id.\n");
3818 done:
3819 DestroyWindow(window);
3820 IDirect3D8_Release(d3d8);
3821 #endif
3824 static void test_ApplyStateBlock(void)
3826 IDirect3DDevice8 *device;
3827 IDirect3D8 *d3d8;
3828 HWND window;
3829 HRESULT hr;
3830 DWORD received, token;
3832 window = create_window();
3833 ok(!!window, "Failed to create a window.\n");
3834 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
3835 ok(!!d3d8, "Failed to create a D3D object.\n");
3836 if (!(device = create_device(d3d8, window, NULL)))
3838 skip("Failed to create a 3D device, skipping test.\n");
3839 goto cleanup;
3842 IDirect3DDevice8_BeginStateBlock(device);
3843 IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, TRUE);
3844 IDirect3DDevice8_EndStateBlock(device, &token);
3845 ok(token, "Received zero stateblock handle.\n");
3846 IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, FALSE);
3848 hr = IDirect3DDevice8_GetRenderState(device, D3DRS_ZENABLE, &received);
3849 ok(hr == D3D_OK, "Expected D3D_OK, received %#x.\n", hr);
3850 ok(!received, "Expected = FALSE, received TRUE.\n");
3852 hr = IDirect3DDevice8_ApplyStateBlock(device, 0);
3853 ok(hr == D3D_OK, "Expected D3D_OK, received %#x.\n", hr);
3854 hr = IDirect3DDevice8_GetRenderState(device, D3DRS_ZENABLE, &received);
3855 ok(hr == D3D_OK, "Expected D3D_OK, received %#x.\n", hr);
3856 ok(!received, "Expected FALSE, received TRUE.\n");
3858 hr = IDirect3DDevice8_ApplyStateBlock(device, token);
3859 ok(hr == D3D_OK, "Expected D3D_OK, received %#x.\n", hr);
3860 hr = IDirect3DDevice8_GetRenderState(device, D3DRS_ZENABLE, &received);
3861 ok(hr == D3D_OK, "Expected D3D_OK, received %#x.\n", hr);
3862 ok(received, "Expected TRUE, received FALSE.\n");
3864 IDirect3DDevice8_DeleteStateBlock(device, token);
3865 IDirect3DDevice8_Release(device);
3866 cleanup:
3867 IDirect3D8_Release(d3d8);
3868 DestroyWindow(window);
3871 static void test_depth_stencil_size(void)
3873 IDirect3DDevice8 *device;
3874 IDirect3DSurface8 *ds, *rt, *ds_bigger, *ds_bigger2;
3875 IDirect3DSurface8 *surf;
3876 IDirect3D8 *d3d8;
3877 HRESULT hr;
3878 HWND hwnd;
3880 hwnd = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
3881 100, 100, 160, 160, NULL, NULL, NULL, NULL);
3882 ok(!!hwnd, "Failed to create a window.\n");
3883 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
3884 ok(!!d3d8, "Failed to create a D3D object.\n");
3886 if (!(device = create_device(d3d8, hwnd, NULL)))
3888 skip("Failed to create a 3D device, skipping test.\n");
3889 goto cleanup;
3892 hr = IDirect3DDevice8_CreateRenderTarget(device, 64, 64, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, FALSE, &rt);
3893 ok(SUCCEEDED(hr), "IDirect3DDevice8_CreateRenderTarget failed, hr %#x.\n", hr);
3894 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 32, 32, D3DFMT_D24X8, D3DMULTISAMPLE_NONE, &ds);
3895 ok(SUCCEEDED(hr), "IDirect3DDevice8_CreateDepthStencilSurface failed, hr %#x.\n", hr);
3896 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 128, 128, D3DFMT_D24X8, D3DMULTISAMPLE_NONE, &ds_bigger);
3897 ok(SUCCEEDED(hr), "IDirect3DDevice8_CreateDepthStencilSurface failed, hr %#x.\n", hr);
3898 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 128, 128, D3DFMT_D24X8, D3DMULTISAMPLE_NONE, &ds_bigger2);
3899 ok(SUCCEEDED(hr), "IDirect3DDevice8_CreateDepthStencilSurface failed, hr %#x.\n", hr);
3901 hr = IDirect3DDevice8_SetRenderTarget(device, rt, ds);
3902 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_SetRenderTarget returned %#x, expected D3DERR_INVALIDCALL.\n", hr);
3903 hr = IDirect3DDevice8_SetRenderTarget(device, rt, ds_bigger);
3904 ok(SUCCEEDED(hr), "IDirect3DDevice8_SetRenderTarget failed, hr %#x.\n", hr);
3906 /* try to set the small ds without changing the render target at the same time */
3907 hr = IDirect3DDevice8_SetRenderTarget(device, NULL, ds);
3908 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_SetRenderTarget returned %#x, expected D3DERR_INVALIDCALL.\n", hr);
3909 hr = IDirect3DDevice8_SetRenderTarget(device, NULL, ds_bigger2);
3910 ok(SUCCEEDED(hr), "IDirect3DDevice8_SetRenderTarget failed, hr %#x.\n", hr);
3912 hr = IDirect3DDevice8_GetRenderTarget(device, &surf);
3913 ok(hr == D3D_OK, "IDirect3DDevice8_GetRenderTarget failed, hr %#x.\n", hr);
3914 ok(surf == rt, "The render target is %p, expected %p\n", surf, rt);
3915 IDirect3DSurface8_Release(surf);
3916 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surf);
3917 ok(hr == D3D_OK, "IDirect3DDevice8_GetDepthStencilSurface failed, hr %#x.\n", hr);
3918 ok(surf == ds_bigger2, "The depth stencil is %p, expected %p\n", surf, ds_bigger2);
3919 IDirect3DSurface8_Release(surf);
3921 hr = IDirect3DDevice8_SetRenderTarget(device, NULL, NULL);
3922 ok(SUCCEEDED(hr), "IDirect3DDevice8_SetRenderTarget failed, hr %#x.\n", hr);
3923 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surf);
3924 ok(FAILED(hr), "IDirect3DDevice8_GetDepthStencilSurface should have failed, hr %#x.\n", hr);
3925 ok(surf == NULL, "The depth stencil is %p, expected NULL\n", surf);
3926 if (surf) IDirect3DSurface8_Release(surf);
3928 IDirect3DSurface8_Release(rt);
3929 IDirect3DSurface8_Release(ds);
3930 IDirect3DSurface8_Release(ds_bigger);
3931 IDirect3DSurface8_Release(ds_bigger2);
3933 cleanup:
3934 IDirect3D8_Release(d3d8);
3935 DestroyWindow(hwnd);
3938 static void test_window_style(void)
3940 RECT focus_rect, fullscreen_rect, r;
3941 LONG device_style, device_exstyle;
3942 LONG focus_style, focus_exstyle;
3943 struct device_desc device_desc;
3944 LONG style, expected_style;
3945 IDirect3DDevice8 *device;
3946 IDirect3D8 *d3d8;
3947 HRESULT hr;
3948 ULONG ref;
3949 BOOL ret;
3951 focus_window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
3952 0, 0, registry_mode.dmPelsWidth / 2, registry_mode.dmPelsHeight / 2, 0, 0, 0, 0);
3953 device_window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
3954 0, 0, registry_mode.dmPelsWidth / 2, registry_mode.dmPelsHeight / 2, 0, 0, 0, 0);
3955 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
3956 ok(!!d3d8, "Failed to create a D3D object.\n");
3958 device_style = GetWindowLongA(device_window, GWL_STYLE);
3959 device_exstyle = GetWindowLongA(device_window, GWL_EXSTYLE);
3960 focus_style = GetWindowLongA(focus_window, GWL_STYLE);
3961 focus_exstyle = GetWindowLongA(focus_window, GWL_EXSTYLE);
3963 SetRect(&fullscreen_rect, 0, 0, registry_mode.dmPelsWidth, registry_mode.dmPelsHeight);
3964 GetWindowRect(focus_window, &focus_rect);
3966 device_desc.adapter_ordinal = D3DADAPTER_DEFAULT;
3967 device_desc.device_window = device_window;
3968 device_desc.width = registry_mode.dmPelsWidth;
3969 device_desc.height = registry_mode.dmPelsHeight;
3970 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
3971 if (!(device = create_device(d3d8, focus_window, &device_desc)))
3973 skip("Failed to create a D3D device, skipping tests.\n");
3974 goto done;
3977 style = GetWindowLongA(device_window, GWL_STYLE);
3978 expected_style = device_style | WS_VISIBLE;
3979 todo_wine ok(style == expected_style || broken(style == (expected_style & ~WS_OVERLAPPEDWINDOW)) /* w1064v1809 */,
3980 "Expected device window style %#x, got %#x.\n",
3981 expected_style, style);
3982 style = GetWindowLongA(device_window, GWL_EXSTYLE);
3983 expected_style = device_exstyle | WS_EX_TOPMOST;
3984 todo_wine ok(style == expected_style || broken(style == (expected_style & ~WS_EX_OVERLAPPEDWINDOW)) /* w1064v1809 */,
3985 "Expected device window extended style %#x, got %#x.\n",
3986 expected_style, style);
3988 style = GetWindowLongA(focus_window, GWL_STYLE);
3989 ok(style == focus_style, "Expected focus window style %#x, got %#x.\n",
3990 focus_style, style);
3991 style = GetWindowLongA(focus_window, GWL_EXSTYLE);
3992 ok(style == focus_exstyle, "Expected focus window extended style %#x, got %#x.\n",
3993 focus_exstyle, style);
3995 GetWindowRect(device_window, &r);
3996 ok(EqualRect(&r, &fullscreen_rect), "Expected %s, got %s.\n",
3997 wine_dbgstr_rect(&fullscreen_rect), wine_dbgstr_rect(&r));
3998 GetClientRect(device_window, &r);
3999 todo_wine ok(!EqualRect(&r, &fullscreen_rect) || broken(!(style & WS_THICKFRAME)) /* w1064v1809 */,
4000 "Client rect and window rect are equal.\n");
4001 GetWindowRect(focus_window, &r);
4002 ok(EqualRect(&r, &focus_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&focus_rect),
4003 wine_dbgstr_rect(&r));
4005 device_desc.flags = 0;
4006 hr = reset_device(device, &device_desc);
4007 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
4009 style = GetWindowLongA(device_window, GWL_STYLE);
4010 expected_style = device_style | WS_VISIBLE;
4011 ok(style == expected_style, "Expected device window style %#x, got %#x.\n",
4012 expected_style, style);
4013 style = GetWindowLongA(device_window, GWL_EXSTYLE);
4014 expected_style = device_exstyle | WS_EX_TOPMOST;
4015 ok(style == expected_style, "Expected device window extended style %#x, got %#x.\n",
4016 expected_style, style);
4018 style = GetWindowLongA(focus_window, GWL_STYLE);
4019 ok(style == focus_style, "Expected focus window style %#x, got %#x.\n",
4020 focus_style, style);
4021 style = GetWindowLongA(focus_window, GWL_EXSTYLE);
4022 ok(style == focus_exstyle, "Expected focus window extended style %#x, got %#x.\n",
4023 focus_exstyle, style);
4025 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
4026 hr = reset_device(device, &device_desc);
4027 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
4028 ret = SetForegroundWindow(GetDesktopWindow());
4029 ok(ret, "Failed to set foreground window.\n");
4031 style = GetWindowLongA(device_window, GWL_STYLE);
4032 expected_style = device_style | WS_MINIMIZE | WS_VISIBLE;
4033 todo_wine ok(style == expected_style, "Expected device window style %#x, got %#x.\n",
4034 expected_style, style);
4035 style = GetWindowLongA(device_window, GWL_EXSTYLE);
4036 expected_style = device_exstyle | WS_EX_TOPMOST;
4037 todo_wine ok(style == expected_style, "Expected device window extended style %#x, got %#x.\n",
4038 expected_style, style);
4040 style = GetWindowLongA(focus_window, GWL_STYLE);
4041 ok(style == focus_style, "Expected focus window style %#x, got %#x.\n",
4042 focus_style, style);
4043 style = GetWindowLongA(focus_window, GWL_EXSTYLE);
4044 ok(style == focus_exstyle, "Expected focus window extended style %#x, got %#x.\n",
4045 focus_exstyle, style);
4047 /* Follow-up tests fail on native if the device is destroyed while lost. */
4048 ShowWindow(focus_window, SW_MINIMIZE);
4049 ShowWindow(focus_window, SW_RESTORE);
4050 ret = SetForegroundWindow(focus_window);
4051 ok(ret, "Failed to set foreground window.\n");
4052 flush_events();
4053 hr = reset_device(device, &device_desc);
4054 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
4056 ref = IDirect3DDevice8_Release(device);
4057 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
4059 done:
4060 IDirect3D8_Release(d3d8);
4062 DestroyWindow(device_window);
4063 DestroyWindow(focus_window);
4066 static void test_unsupported_shaders(void)
4068 IDirect3DDevice8 *device;
4069 IDirect3D8 *d3d;
4070 ULONG refcount;
4071 DWORD vs, ps;
4072 HWND window;
4073 HRESULT hr;
4074 D3DCAPS8 caps;
4076 static const DWORD vs_2_0[] =
4078 0xfffe0200, /* vs_2_0 */
4079 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
4080 0x02000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
4081 0x03000002, 0xd00f0000, 0x80e40001, 0xa0e40002, /* add oD0, r1, c2 */
4082 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
4083 0x0000ffff /* end */
4085 static const DWORD ps_2_0[] =
4087 0xffff0200, /* ps_2_0 */
4088 0x02000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
4089 0x03000002, 0x800f0000, 0x80e40001, 0xa0e40002, /* add r0, r1, c2 */
4090 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
4091 0x0000ffff /* end */
4093 #if 0
4094 vs_1_1
4095 dcl_position v0
4096 def c255, 1.0, 1.0, 1.0, 1.0
4097 add r0, v0, c255
4098 mov oPos, r0
4099 #endif
4100 static const DWORD vs_1_255[] =
4102 0xfffe0101,
4103 0x0000001f, 0x80000000, 0x900f0000,
4104 0x00000051, 0xa00f00ff, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
4105 0x00000002, 0x800f0000, 0x90e40000, 0xa0e400ff,
4106 0x00000001, 0xc00f0000, 0x80e40000,
4107 0x0000ffff
4109 #if 0
4110 vs_1_1
4111 dcl_position v0
4112 def c256, 1.0, 1.0, 1.0, 1.0
4113 add r0, v0, c256
4114 mov oPos, r0
4115 #endif
4116 static const DWORD vs_1_256[] =
4118 0xfffe0101,
4119 0x0000001f, 0x80000000, 0x900f0000,
4120 0x00000051, 0xa00f0100, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
4121 0x00000002, 0x800f0000, 0x90e40000, 0xa0e40100,
4122 0x00000001, 0xc00f0000, 0x80e40000,
4123 0x0000ffff
4126 static const DWORD decl[] =
4128 D3DVSD_STREAM(0),
4129 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3),
4130 D3DVSD_END()
4133 window = create_window();
4134 ok(!!window, "Failed to create a window.\n");
4135 d3d = Direct3DCreate8(D3D_SDK_VERSION);
4136 ok(!!d3d, "Failed to create a D3D object.\n");
4137 if (!(device = create_device(d3d, window, NULL)))
4139 skip("Failed to create a D3D device, skipping tests.\n");
4140 IDirect3D8_Release(d3d);
4141 DestroyWindow(window);
4142 return;
4145 hr = IDirect3DDevice8_CreateVertexShader(device, decl, simple_ps, &vs, 0);
4146 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
4148 hr = IDirect3DDevice8_CreatePixelShader(device, simple_vs, &ps);
4149 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr);
4151 hr = IDirect3DDevice8_CreateVertexShader(device, decl, vs_2_0, &vs, 0);
4152 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
4154 hr = IDirect3DDevice8_CreatePixelShader(device, ps_2_0, &ps);
4155 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr);
4157 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
4158 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
4159 if (caps.MaxVertexShaderConst < 256)
4161 hr = IDirect3DDevice8_CreateVertexShader(device, decl, vs_1_255, &vs, 0);
4162 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
4164 else
4166 hr = IDirect3DDevice8_CreateVertexShader(device, decl, vs_1_255, &vs, 0);
4167 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
4168 hr = IDirect3DDevice8_DeleteVertexShader(device, vs);
4169 ok(hr == D3D_OK, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
4170 hr = IDirect3DDevice8_CreateVertexShader(device, decl, vs_1_256, &vs, 0);
4171 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
4174 refcount = IDirect3DDevice8_Release(device);
4175 ok(!refcount, "Device has %u references left.\n", refcount);
4176 IDirect3D8_Release(d3d);
4177 DestroyWindow(window);
4180 static void test_mode_change(void)
4182 DEVMODEW old_devmode, devmode, devmode2, *original_modes = NULL;
4183 struct device_desc device_desc, device_desc2;
4184 WCHAR second_monitor_name[CCHDEVICENAME];
4185 IDirect3DDevice8 *device, *device2;
4186 unsigned int display_count = 0;
4187 RECT d3d_rect, focus_rect, r;
4188 IDirect3DSurface8 *backbuffer;
4189 MONITORINFOEXW monitor_info;
4190 HMONITOR second_monitor;
4191 D3DSURFACE_DESC desc;
4192 IDirect3D8 *d3d8;
4193 ULONG refcount;
4194 UINT adapter_mode_count, i;
4195 HRESULT hr;
4196 BOOL ret;
4197 LONG change_ret;
4198 D3DDISPLAYMODE d3ddm;
4199 DWORD d3d_width = 0, d3d_height = 0, user32_width = 0, user32_height = 0;
4201 memset(&devmode, 0, sizeof(devmode));
4202 devmode.dmSize = sizeof(devmode);
4203 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
4204 ok(ret, "EnumDisplaySettingsW failed, error %#x.\n", GetLastError());
4205 ok(equal_mode_rect(&devmode, &registry_mode), "Got a different mode.\n");
4206 ret = EnumDisplaySettingsW(NULL, ENUM_REGISTRY_SETTINGS, &devmode);
4207 ok(ret, "EnumDisplaySettingsW failed, error %#x.\n", GetLastError());
4208 ok(equal_mode_rect(&devmode, &registry_mode), "Got a different mode.\n");
4210 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
4211 ok(!!d3d8, "Failed to create a D3D object.\n");
4213 adapter_mode_count = IDirect3D8_GetAdapterModeCount(d3d8, D3DADAPTER_DEFAULT);
4214 for (i = 0; i < adapter_mode_count; ++i)
4216 hr = IDirect3D8_EnumAdapterModes(d3d8, D3DADAPTER_DEFAULT, i, &d3ddm);
4217 ok(SUCCEEDED(hr), "Failed to enumerate display mode, hr %#x.\n", hr);
4219 if (d3ddm.Format != D3DFMT_X8R8G8B8)
4220 continue;
4221 if (d3ddm.Width == registry_mode.dmPelsWidth && d3ddm.Height == registry_mode.dmPelsHeight)
4222 continue;
4223 /* The r200 driver on Windows XP enumerates modes like 320x200 and 320x240 but
4224 * refuses to create a device at these sizes. */
4225 if (d3ddm.Width < 640 || d3ddm.Height < 480)
4226 continue;
4228 if (!user32_width)
4230 user32_width = d3ddm.Width;
4231 user32_height = d3ddm.Height;
4232 continue;
4235 /* Make sure the d3d mode is smaller in width or height and at most
4236 * equal in the other dimension than the mode passed to
4237 * ChangeDisplaySettings. Otherwise Windows shrinks the window to
4238 * the ChangeDisplaySettings parameters + 12. */
4239 if (d3ddm.Width == user32_width && d3ddm.Height == user32_height)
4240 continue;
4241 if (d3ddm.Width <= user32_width && d3ddm.Height <= user32_height)
4243 d3d_width = d3ddm.Width;
4244 d3d_height = d3ddm.Height;
4245 break;
4247 if (user32_width <= d3ddm.Width && user32_height <= d3ddm.Height)
4249 d3d_width = user32_width;
4250 d3d_height = user32_height;
4251 user32_width = d3ddm.Width;
4252 user32_height = d3ddm.Height;
4253 break;
4257 if (!d3d_width)
4259 skip("Could not find adequate modes, skipping mode tests.\n");
4260 IDirect3D8_Release(d3d8);
4261 return;
4264 ret = save_display_modes(&original_modes, &display_count);
4265 ok(ret, "Failed to save original display modes.\n");
4267 memset(&devmode, 0, sizeof(devmode));
4268 devmode.dmSize = sizeof(devmode);
4269 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
4270 devmode.dmPelsWidth = user32_width;
4271 devmode.dmPelsHeight = user32_height;
4272 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
4273 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
4275 /* Make the windows visible, otherwise device::release does not restore the mode if
4276 * the application is not in foreground like on the testbot. */
4277 focus_window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4278 0, 0, user32_width / 2, user32_height / 2, 0, 0, 0, 0);
4279 device_window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
4280 0, 0, user32_width / 2, user32_height / 2, 0, 0, 0, 0);
4282 SetRect(&d3d_rect, 0, 0, d3d_width, d3d_height);
4283 GetWindowRect(focus_window, &focus_rect);
4285 device_desc.adapter_ordinal = D3DADAPTER_DEFAULT;
4286 device_desc.device_window = device_window;
4287 device_desc.width = d3d_width;
4288 device_desc.height = d3d_height;
4289 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
4290 if (!(device = create_device(d3d8, focus_window, &device_desc)))
4292 skip("Failed to create a D3D device, skipping tests.\n");
4293 goto done;
4296 devmode.dmPelsWidth = user32_width;
4297 devmode.dmPelsHeight = user32_height;
4298 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
4299 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
4301 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
4302 ok(ret, "Failed to get display mode.\n");
4303 ok(devmode.dmPelsWidth == user32_width && devmode.dmPelsHeight == user32_height,
4304 "Expected resolution %ux%u, got %ux%u.\n",
4305 user32_width, user32_height, devmode.dmPelsWidth, devmode.dmPelsHeight);
4307 GetWindowRect(device_window, &r);
4308 ok(EqualRect(&r, &d3d_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&d3d_rect),
4309 wine_dbgstr_rect(&r));
4310 GetWindowRect(focus_window, &r);
4311 ok(EqualRect(&r, &focus_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&focus_rect),
4312 wine_dbgstr_rect(&r));
4314 hr = IDirect3DDevice8_GetBackBuffer(device, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
4315 ok(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
4316 hr = IDirect3DSurface8_GetDesc(backbuffer, &desc);
4317 ok(SUCCEEDED(hr), "Failed to get backbuffer desc, hr %#x.\n", hr);
4318 ok(desc.Width == d3d_width, "Got unexpected backbuffer width %u, expected %u.\n",
4319 desc.Width, d3d_width);
4320 ok(desc.Height == d3d_height, "Got unexpected backbuffer height %u, expected %u.\n",
4321 desc.Height, d3d_height);
4322 IDirect3DSurface8_Release(backbuffer);
4324 refcount = IDirect3DDevice8_Release(device);
4325 ok(!refcount, "Device has %u references left.\n", refcount);
4327 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
4328 ok(ret, "Failed to get display mode.\n");
4329 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
4330 && devmode.dmPelsHeight == registry_mode.dmPelsHeight,
4331 "Expected resolution %ux%u, got %ux%u.\n",
4332 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight, devmode.dmPelsWidth, devmode.dmPelsHeight);
4334 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
4335 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
4337 /* The mode restore also happens when the device was created at the original screen size. */
4339 device_desc.adapter_ordinal = D3DADAPTER_DEFAULT;
4340 device_desc.device_window = device_window;
4341 device_desc.width = registry_mode.dmPelsWidth;
4342 device_desc.height = registry_mode.dmPelsHeight;
4343 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
4344 ok(!!(device = create_device(d3d8, focus_window, &device_desc)), "Failed to create a D3D device.\n");
4346 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
4347 devmode.dmPelsWidth = user32_width;
4348 devmode.dmPelsHeight = user32_height;
4349 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
4350 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
4352 refcount = IDirect3DDevice8_Release(device);
4353 ok(!refcount, "Device has %u references left.\n", refcount);
4355 memset(&devmode2, 0, sizeof(devmode2));
4356 devmode2.dmSize = sizeof(devmode2);
4357 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode2);
4358 ok(ret, "Failed to get display mode.\n");
4359 ok(devmode2.dmPelsWidth == registry_mode.dmPelsWidth
4360 && devmode2.dmPelsHeight == registry_mode.dmPelsHeight,
4361 "Expected resolution %ux%u, got %ux%u.\n", registry_mode.dmPelsWidth,
4362 registry_mode.dmPelsHeight, devmode2.dmPelsWidth, devmode2.dmPelsHeight);
4363 ret = restore_display_modes(original_modes, display_count);
4364 ok(ret, "Failed to restore display modes.\n");
4366 /* Test that no mode restorations if no mode changes happened */
4367 change_ret = ChangeDisplaySettingsW(&devmode, CDS_UPDATEREGISTRY | CDS_NORESET);
4368 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsW failed with %d.\n", change_ret);
4370 device_desc.adapter_ordinal = D3DADAPTER_DEFAULT;
4371 device_desc.device_window = device_window;
4372 device_desc.width = d3d_width;
4373 device_desc.height = d3d_height;
4374 device_desc.flags = 0;
4375 device = create_device(d3d8, device_window, &device_desc);
4376 ok(!!device, "Failed to create a D3D device.\n");
4377 refcount = IDirect3DDevice8_Release(device);
4378 ok(!refcount, "Device has %u references left.\n", refcount);
4380 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode2);
4381 ok(ret, "EnumDisplaySettingsW failed, error %#x.\n", GetLastError());
4382 ok(equal_mode_rect(&devmode2, &registry_mode), "Got a different mode.\n");
4383 ret = restore_display_modes(original_modes, display_count);
4384 ok(ret, "Failed to restore display modes.\n");
4386 /* Test that mode restorations use display settings in the registry with a fullscreen device */
4387 change_ret = ChangeDisplaySettingsW(&devmode, CDS_UPDATEREGISTRY | CDS_NORESET);
4388 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsW failed with %d.\n", change_ret);
4390 device_desc.adapter_ordinal = D3DADAPTER_DEFAULT;
4391 device_desc.device_window = device_window;
4392 device_desc.width = registry_mode.dmPelsWidth;
4393 device_desc.height = registry_mode.dmPelsHeight;
4394 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
4395 device = create_device(d3d8, device_window, &device_desc);
4396 ok(!!device, "Failed to create a D3D device.\n");
4397 refcount = IDirect3DDevice8_Release(device);
4398 ok(!refcount, "Device has %u references left.\n", refcount);
4400 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode2);
4401 ok(ret, "EnumDisplaySettingsW failed, error %#x.\n", GetLastError());
4402 ok(equal_mode_rect(&devmode2, &devmode), "Got a different mode.\n");
4403 ret = EnumDisplaySettingsW(NULL, ENUM_REGISTRY_SETTINGS, &devmode2);
4404 ok(ret, "EnumDisplaySettingsW failed, error %#x.\n", GetLastError());
4405 ok(equal_mode_rect(&devmode2, &devmode), "Got a different mode.\n");
4406 ret = restore_display_modes(original_modes, display_count);
4407 ok(ret, "Failed to restore display modes.\n");
4409 /* Test that mode restorations use display settings in the registry with a fullscreen device
4410 * having the same display mode and then reset to a different mode */
4411 change_ret = ChangeDisplaySettingsW(&devmode, CDS_UPDATEREGISTRY | CDS_NORESET);
4412 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsW failed with %d.\n", change_ret);
4414 device_desc.adapter_ordinal = D3DADAPTER_DEFAULT;
4415 device_desc.device_window = device_window;
4416 device_desc.width = registry_mode.dmPelsWidth;
4417 device_desc.height = registry_mode.dmPelsHeight;
4418 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
4419 device = create_device(d3d8, device_window, &device_desc);
4420 ok(!!device, "Failed to create a D3D device.\n");
4422 device_desc.width = d3d_width;
4423 device_desc.height = d3d_height;
4424 hr = reset_device(device, &device_desc);
4425 ok(hr == D3D_OK, "Failed to reset device, hr %#x.\n", hr);
4426 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode2);
4427 ok(ret, "EnumDisplaySettingsW failed, error %#x.\n", GetLastError());
4428 ok(devmode2.dmPelsWidth == d3d_width && devmode2.dmPelsHeight == d3d_height,
4429 "Expected resolution %ux%u, got %ux%u.\n", d3d_width, d3d_height,
4430 devmode2.dmPelsWidth, devmode2.dmPelsHeight);
4432 refcount = IDirect3DDevice8_Release(device);
4433 ok(!refcount, "Device has %u references left.\n", refcount);
4435 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode2);
4436 ok(ret, "EnumDisplaySettingsW failed, error %#x.\n", GetLastError());
4437 ok(equal_mode_rect(&devmode2, &devmode), "Got a different mode.\n");
4438 ret = EnumDisplaySettingsW(NULL, ENUM_REGISTRY_SETTINGS, &devmode2);
4439 ok(ret, "EnumDisplaySettingsW failed, error %#x.\n", GetLastError());
4440 ok(equal_mode_rect(&devmode2, &devmode), "Got a different mode.\n");
4441 ret = restore_display_modes(original_modes, display_count);
4442 ok(ret, "Failed to restore display modes.\n");
4444 if (IDirect3D8_GetAdapterCount(d3d8) < 2)
4446 skip("Following tests require two adapters.\n");
4447 goto done;
4450 second_monitor = IDirect3D8_GetAdapterMonitor(d3d8, 1);
4451 monitor_info.cbSize = sizeof(monitor_info);
4452 ret = GetMonitorInfoW(second_monitor, (MONITORINFO *)&monitor_info);
4453 ok(ret, "GetMonitorInfoW failed, error %#x.\n", GetLastError());
4454 lstrcpyW(second_monitor_name, monitor_info.szDevice);
4456 memset(&old_devmode, 0, sizeof(old_devmode));
4457 old_devmode.dmSize = sizeof(old_devmode);
4458 ret = EnumDisplaySettingsW(second_monitor_name, ENUM_CURRENT_SETTINGS, &old_devmode);
4459 ok(ret, "EnumDisplaySettingsW failed, error %#x.\n", GetLastError());
4461 i = 0;
4462 d3d_width = 0;
4463 d3d_height = 0;
4464 user32_width = 0;
4465 user32_height = 0;
4466 while (EnumDisplaySettingsW(second_monitor_name, i++, &devmode))
4468 if (devmode.dmPelsWidth == old_devmode.dmPelsWidth
4469 && devmode.dmPelsHeight == old_devmode.dmPelsHeight)
4470 continue;
4472 if (!d3d_width && !d3d_height)
4474 d3d_width = devmode.dmPelsWidth;
4475 d3d_height = devmode.dmPelsHeight;
4476 continue;
4479 if (devmode.dmPelsWidth == d3d_width && devmode.dmPelsHeight == d3d_height)
4480 continue;
4482 user32_width = devmode.dmPelsWidth;
4483 user32_height = devmode.dmPelsHeight;
4484 break;
4486 if (!user32_width || !user32_height)
4488 skip("Failed to find three different display modes for the second monitor.\n");
4489 goto done;
4492 /* Test that mode restorations also happen for non-primary monitors on device resets */
4493 device_desc.adapter_ordinal = D3DADAPTER_DEFAULT;
4494 device_desc.device_window = device_window;
4495 device_desc.width = registry_mode.dmPelsWidth;
4496 device_desc.height = registry_mode.dmPelsHeight;
4497 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
4498 device = create_device(d3d8, device_window, &device_desc);
4499 ok(!!device, "Failed to create a D3D device.\n");
4501 change_ret = ChangeDisplaySettingsExW(second_monitor_name, &devmode, NULL, CDS_RESET, NULL);
4502 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsExW failed with %d.\n", change_ret);
4503 ret = EnumDisplaySettingsW(second_monitor_name, ENUM_CURRENT_SETTINGS, &devmode2);
4504 ok(ret, "EnumDisplaySettingsW failed, error %#x.\n", GetLastError());
4505 if (devmode2.dmPelsWidth == old_devmode.dmPelsWidth
4506 && devmode2.dmPelsHeight == old_devmode.dmPelsHeight)
4508 skip("Failed to change display settings of the second monitor.\n");
4509 refcount = IDirect3DDevice8_Release(device);
4510 ok(!refcount, "Device has %u references left.\n", refcount);
4511 goto done;
4514 device_desc.flags = 0;
4515 hr = reset_device(device, &device_desc);
4516 ok(hr == D3D_OK, "Failed to reset device, hr %#x.\n", hr);
4518 ret = EnumDisplaySettingsW(second_monitor_name, ENUM_CURRENT_SETTINGS, &devmode2);
4519 ok(ret, "EnumDisplaySettingsW failed, error %#x.\n", GetLastError());
4520 ok(equal_mode_rect(&devmode2, &old_devmode), "Got a different mode.\n");
4521 ret = EnumDisplaySettingsW(second_monitor_name, ENUM_REGISTRY_SETTINGS, &devmode2);
4522 ok(ret, "EnumDisplaySettingsW failed, error %#x.\n", GetLastError());
4523 ok(equal_mode_rect(&devmode2, &old_devmode), "Got a different mode.\n");
4524 hr = IDirect3D8_GetAdapterDisplayMode(d3d8, 1, &d3ddm);
4525 ok(hr == S_OK, "GetAdapterDisplayMode failed, hr %#x.\n", hr);
4526 ok(d3ddm.Width == old_devmode.dmPelsWidth, "Expected width %u, got %u.\n",
4527 old_devmode.dmPelsWidth, d3ddm.Width);
4528 ok(d3ddm.Height == old_devmode.dmPelsHeight, "Expected height %u, got %u.\n",
4529 old_devmode.dmPelsHeight, d3ddm.Height);
4531 refcount = IDirect3DDevice8_Release(device);
4532 ok(!refcount, "Device has %u references left.\n", refcount);
4533 ret = restore_display_modes(original_modes, display_count);
4534 ok(ret, "Failed to restore display modes.\n");
4536 /* Test that mode restorations happen for non-primary monitors on device releases */
4537 device_desc.adapter_ordinal = D3DADAPTER_DEFAULT;
4538 device_desc.device_window = device_window;
4539 device_desc.width = registry_mode.dmPelsWidth;
4540 device_desc.height = registry_mode.dmPelsHeight;
4541 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
4542 device = create_device(d3d8, device_window, &device_desc);
4543 ok(!!device, "Failed to create a D3D device.\n");
4545 change_ret = ChangeDisplaySettingsExW(second_monitor_name, &devmode, NULL, CDS_RESET, NULL);
4546 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsExW failed with %d.\n", change_ret);
4548 refcount = IDirect3DDevice8_Release(device);
4549 ok(!refcount, "Device has %u references left.\n", refcount);
4551 ret = EnumDisplaySettingsW(second_monitor_name, ENUM_CURRENT_SETTINGS, &devmode2);
4552 ok(ret, "EnumDisplaySettingsW failed, error %#x.\n", GetLastError());
4553 ok(equal_mode_rect(&devmode2, &old_devmode), "Got a different mode.\n");
4554 ret = EnumDisplaySettingsW(second_monitor_name, ENUM_REGISTRY_SETTINGS, &devmode2);
4555 ok(ret, "EnumDisplaySettingsW failed, error %#x.\n", GetLastError());
4556 ok(equal_mode_rect(&devmode2, &old_devmode), "Got a different mode.\n");
4557 hr = IDirect3D8_GetAdapterDisplayMode(d3d8, 1, &d3ddm);
4558 ok(hr == S_OK, "GetAdapterDisplayMode failed, hr %#x.\n", hr);
4559 ok(d3ddm.Width == old_devmode.dmPelsWidth, "Expected width %u, got %u.\n",
4560 old_devmode.dmPelsWidth, d3ddm.Width);
4561 ok(d3ddm.Height == old_devmode.dmPelsHeight, "Expected height %u, got %u.\n",
4562 old_devmode.dmPelsHeight, d3ddm.Height);
4563 ret = restore_display_modes(original_modes, display_count);
4564 ok(ret, "Failed to restore display modes.\n");
4566 /* Test that mode restorations for non-primary monitors use display settings in the registry */
4567 device = create_device(d3d8, device_window, &device_desc);
4568 ok(!!device, "Failed to create a D3D device.\n");
4570 change_ret = ChangeDisplaySettingsExW(second_monitor_name, &devmode, NULL,
4571 CDS_UPDATEREGISTRY | CDS_NORESET, NULL);
4572 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsExW failed with %d.\n", change_ret);
4574 refcount = IDirect3DDevice8_Release(device);
4575 ok(!refcount, "Device has %u references left.\n", refcount);
4577 ret = EnumDisplaySettingsW(second_monitor_name, ENUM_CURRENT_SETTINGS, &devmode2);
4578 ok(ret, "EnumDisplaySettingsW failed, error %#x.\n", GetLastError());
4579 ok(devmode2.dmPelsWidth == devmode.dmPelsWidth && devmode2.dmPelsHeight == devmode.dmPelsHeight,
4580 "Expected resolution %ux%u, got %ux%u.\n", devmode.dmPelsWidth, devmode.dmPelsHeight,
4581 devmode2.dmPelsWidth, devmode2.dmPelsHeight);
4582 ret = EnumDisplaySettingsW(second_monitor_name, ENUM_REGISTRY_SETTINGS, &devmode2);
4583 ok(ret, "EnumDisplaySettingsW failed, error %#x.\n", GetLastError());
4584 ok(devmode2.dmPelsWidth == devmode.dmPelsWidth && devmode2.dmPelsHeight == devmode.dmPelsHeight,
4585 "Expected resolution %ux%u, got %ux%u.\n", devmode.dmPelsWidth, devmode.dmPelsHeight,
4586 devmode2.dmPelsWidth, devmode2.dmPelsHeight);
4587 hr = IDirect3D8_GetAdapterDisplayMode(d3d8, 1, &d3ddm);
4588 ok(hr == S_OK, "GetAdapterDisplayMode failed, hr %#x.\n", hr);
4589 ok(d3ddm.Width == devmode.dmPelsWidth && d3ddm.Height == devmode.dmPelsHeight,
4590 "Expected resolution %ux%u, got %ux%u.\n", devmode.dmPelsWidth, devmode.dmPelsHeight,
4591 d3ddm.Width, d3ddm.Height);
4592 ret = restore_display_modes(original_modes, display_count);
4593 ok(ret, "Failed to restore display modes.\n");
4595 /* Test mode restorations when there are two fullscreen devices and one of them got reset */
4596 device = create_device(d3d8, focus_window, &device_desc);
4597 ok(!!device, "Failed to create a D3D device.\n");
4599 device_desc2.adapter_ordinal = 1;
4600 device_desc2.device_window = device_window;
4601 device_desc2.width = d3d_width;
4602 device_desc2.height = d3d_height;
4603 device_desc2.flags = CREATE_DEVICE_FULLSCREEN;
4604 device2 = create_device(d3d8, focus_window, &device_desc2);
4605 ok(!!device2, "Failed to create a D3D device.\n");
4607 change_ret = ChangeDisplaySettingsExW(second_monitor_name, &devmode, NULL, CDS_RESET, NULL);
4608 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsExW failed with %d.\n", change_ret);
4610 device_desc.flags = 0;
4611 hr = reset_device(device, &device_desc);
4612 ok(hr == D3D_OK, "Failed to reset device, hr %#x.\n", hr);
4614 ret = EnumDisplaySettingsW(second_monitor_name, ENUM_CURRENT_SETTINGS, &devmode2);
4615 ok(ret, "EnumDisplaySettingsW failed, error %#x.\n", GetLastError());
4616 ok(equal_mode_rect(&devmode2, &old_devmode), "Got a different mode.\n");
4617 ret = EnumDisplaySettingsW(second_monitor_name, ENUM_REGISTRY_SETTINGS, &devmode2);
4618 ok(ret, "EnumDisplaySettingsW failed, error %#x.\n", GetLastError());
4619 ok(equal_mode_rect(&devmode2, &old_devmode), "Got a different mode.\n");
4620 hr = IDirect3D8_GetAdapterDisplayMode(d3d8, 1, &d3ddm);
4621 ok(hr == S_OK, "GetAdapterDisplayMode failed, hr %#x.\n", hr);
4622 ok(d3ddm.Width == old_devmode.dmPelsWidth && d3ddm.Height == old_devmode.dmPelsHeight,
4623 "Expected resolution %ux%u, got %ux%u.\n", old_devmode.dmPelsWidth,
4624 old_devmode.dmPelsHeight, d3ddm.Width, d3ddm.Height);
4626 refcount = IDirect3DDevice8_Release(device2);
4627 ok(!refcount, "Device has %u references left.\n", refcount);
4628 refcount = IDirect3DDevice8_Release(device);
4629 ok(!refcount, "Device has %u references left.\n", refcount);
4630 ret = restore_display_modes(original_modes, display_count);
4631 ok(ret, "Failed to restore display modes.\n");
4633 /* Test mode restoration when there are two fullscreen devices and one of them got released */
4634 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
4635 device = create_device(d3d8, focus_window, &device_desc);
4636 ok(!!device, "Failed to create a D3D device.\n");
4637 device2 = create_device(d3d8, focus_window, &device_desc2);
4638 ok(!!device2, "Failed to create a D3D device.\n");
4640 change_ret = ChangeDisplaySettingsExW(second_monitor_name, &devmode, NULL, CDS_RESET, NULL);
4641 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "ChangeDisplaySettingsExW failed with %d.\n", change_ret);
4643 refcount = IDirect3DDevice8_Release(device);
4644 ok(!refcount, "Device has %u references left.\n", refcount);
4646 ret = EnumDisplaySettingsW(second_monitor_name, ENUM_CURRENT_SETTINGS, &devmode2);
4647 ok(ret, "EnumDisplaySettingsW failed, error %#x.\n", GetLastError());
4648 ok(equal_mode_rect(&devmode2, &old_devmode), "Got a different mode.\n");
4649 ret = EnumDisplaySettingsW(second_monitor_name, ENUM_REGISTRY_SETTINGS, &devmode2);
4650 ok(ret, "EnumDisplaySettingsW failed, error %#x.\n", GetLastError());
4651 ok(equal_mode_rect(&devmode2, &old_devmode), "Got a different mode.\n");
4652 hr = IDirect3D8_GetAdapterDisplayMode(d3d8, 1, &d3ddm);
4653 ok(hr == S_OK, "GetAdapterDisplayMode failed, hr %#x.\n", hr);
4654 ok(d3ddm.Width == old_devmode.dmPelsWidth && d3ddm.Height == old_devmode.dmPelsHeight,
4655 "Expected resolution %ux%u, got %ux%u.\n", old_devmode.dmPelsWidth,
4656 old_devmode.dmPelsHeight, d3ddm.Width, d3ddm.Height);
4658 refcount = IDirect3DDevice8_Release(device2);
4659 ok(!refcount, "Device has %u references left.\n", refcount);
4661 done:
4662 DestroyWindow(device_window);
4663 DestroyWindow(focus_window);
4664 IDirect3D8_Release(d3d8);
4665 ret = restore_display_modes(original_modes, display_count);
4666 ok(ret, "Failed to restore display modes.\n");
4667 heap_free(original_modes);
4670 static void test_device_window_reset(void)
4672 RECT fullscreen_rect, device_rect, r;
4673 struct device_desc device_desc;
4674 IDirect3DDevice8 *device;
4675 WNDCLASSA wc = {0};
4676 IDirect3D8 *d3d8;
4677 LONG_PTR proc;
4678 HRESULT hr;
4679 ULONG ref;
4681 filter_messages = NULL;
4682 expect_messages = NULL;
4684 wc.lpfnWndProc = test_proc;
4685 wc.lpszClassName = "d3d8_test_wndproc_wc";
4686 ok(RegisterClassA(&wc), "Failed to register window class.\n");
4688 focus_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
4689 0, 0, registry_mode.dmPelsWidth / 2, registry_mode.dmPelsHeight / 2, 0, 0, 0, 0);
4690 device_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
4691 0, 0, registry_mode.dmPelsWidth / 2, registry_mode.dmPelsHeight / 2, 0, 0, 0, 0);
4692 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
4693 ok(!!d3d8, "Failed to create a D3D object.\n");
4695 SetRect(&fullscreen_rect, 0, 0, registry_mode.dmPelsWidth, registry_mode.dmPelsHeight);
4696 GetWindowRect(device_window, &device_rect);
4698 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
4699 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
4700 (LONG_PTR)test_proc, proc);
4701 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
4702 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
4703 (LONG_PTR)test_proc, proc);
4705 device_desc.adapter_ordinal = D3DADAPTER_DEFAULT;
4706 device_desc.device_window = NULL;
4707 device_desc.width = registry_mode.dmPelsWidth;
4708 device_desc.height = registry_mode.dmPelsHeight;
4709 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
4710 if (!(device = create_device(d3d8, focus_window, &device_desc)))
4712 skip("Failed to create a D3D device, skipping tests.\n");
4713 goto done;
4716 GetWindowRect(focus_window, &r);
4717 ok(EqualRect(&r, &fullscreen_rect), "Expected %s, got %s.\n",
4718 wine_dbgstr_rect(&fullscreen_rect), wine_dbgstr_rect(&r));
4719 GetWindowRect(device_window, &r);
4720 ok(EqualRect(&r, &device_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&device_rect),
4721 wine_dbgstr_rect(&r));
4723 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
4724 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
4725 (LONG_PTR)test_proc, proc);
4726 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
4727 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx.\n", (LONG_PTR)test_proc);
4729 device_desc.device_window = device_window;
4730 hr = reset_device(device, &device_desc);
4731 ok(SUCCEEDED(hr), "Failed to reset device.\n");
4733 GetWindowRect(focus_window, &r);
4734 ok(EqualRect(&r, &fullscreen_rect), "Expected %s, got %s.\n",
4735 wine_dbgstr_rect(&fullscreen_rect), wine_dbgstr_rect(&r));
4736 GetWindowRect(device_window, &r);
4737 ok(EqualRect(&r, &fullscreen_rect), "Expected %s, got %s.\n",
4738 wine_dbgstr_rect(&fullscreen_rect), wine_dbgstr_rect(&r));
4740 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
4741 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
4742 (LONG_PTR)test_proc, proc);
4743 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
4744 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx.\n", (LONG_PTR)test_proc);
4746 ref = IDirect3DDevice8_Release(device);
4747 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
4749 done:
4750 IDirect3D8_Release(d3d8);
4751 DestroyWindow(device_window);
4752 DestroyWindow(focus_window);
4753 UnregisterClassA("d3d8_test_wndproc_wc", GetModuleHandleA(NULL));
4756 static void depth_blit_test(void)
4758 IDirect3DDevice8 *device = NULL;
4759 IDirect3DSurface8 *backbuffer, *ds1, *ds2, *ds3;
4760 RECT src_rect;
4761 const POINT dst_point = {0, 0};
4762 IDirect3D8 *d3d8;
4763 HRESULT hr;
4764 HWND hwnd;
4766 hwnd = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
4767 100, 100, 160, 160, NULL, NULL, NULL, NULL);
4768 ok(!!hwnd, "Failed to create a window.\n");
4769 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
4770 ok(!!d3d8, "Failed to create a D3D object.\n");
4772 if (!(device = create_device(d3d8, hwnd, NULL)))
4774 skip("Failed to create a D3D device, skipping tests.\n");
4775 goto done;
4778 hr = IDirect3DDevice8_GetRenderTarget(device, &backbuffer);
4779 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
4780 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &ds1);
4781 ok(SUCCEEDED(hr), "GetDepthStencilSurface failed, hr %#x.\n", hr);
4782 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 640, 480, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, &ds2);
4783 ok(SUCCEEDED(hr), "CreateDepthStencilSurface failed, hr %#x.\n", hr);
4784 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 640, 480, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, &ds3);
4785 ok(SUCCEEDED(hr), "CreateDepthStencilSurface failed, hr %#x.\n", hr);
4787 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0, 0.0f, 0);
4788 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
4790 /* Partial blit. */
4791 SetRect(&src_rect, 0, 0, 320, 240);
4792 hr = IDirect3DDevice8_CopyRects(device, ds1, &src_rect, 1, ds2, &dst_point);
4793 ok(hr == D3DERR_INVALIDCALL, "CopyRects returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
4794 /* Flipped. */
4795 SetRect(&src_rect, 0, 480, 640, 0);
4796 hr = IDirect3DDevice8_CopyRects(device, ds1, &src_rect, 1, ds2, &dst_point);
4797 ok(hr == D3DERR_INVALIDCALL, "CopyRects returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
4798 /* Full, explicit. */
4799 SetRect(&src_rect, 0, 0, 640, 480);
4800 hr = IDirect3DDevice8_CopyRects(device, ds1, &src_rect, 1, ds2, &dst_point);
4801 ok(hr == D3DERR_INVALIDCALL, "CopyRects returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
4802 /* Depth -> color blit.*/
4803 hr = IDirect3DDevice8_CopyRects(device, ds1, &src_rect, 1, backbuffer, &dst_point);
4804 ok(hr == D3DERR_INVALIDCALL, "CopyRects returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
4805 /* Full, NULL rects, current depth stencil -> unbound depth stencil */
4806 hr = IDirect3DDevice8_CopyRects(device, ds1, NULL, 0, ds2, NULL);
4807 ok(hr == D3DERR_INVALIDCALL, "CopyRects returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
4808 /* Full, NULL rects, unbound depth stencil -> current depth stencil */
4809 hr = IDirect3DDevice8_CopyRects(device, ds2, NULL, 0, ds1, NULL);
4810 ok(hr == D3DERR_INVALIDCALL, "CopyRects returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
4811 /* Full, NULL rects, unbound depth stencil -> unbound depth stencil */
4812 hr = IDirect3DDevice8_CopyRects(device, ds2, NULL, 0, ds3, NULL);
4813 ok(hr == D3DERR_INVALIDCALL, "CopyRects returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
4815 IDirect3DSurface8_Release(backbuffer);
4816 IDirect3DSurface8_Release(ds3);
4817 IDirect3DSurface8_Release(ds2);
4818 IDirect3DSurface8_Release(ds1);
4820 done:
4821 if (device) IDirect3DDevice8_Release(device);
4822 IDirect3D8_Release(d3d8);
4823 DestroyWindow(hwnd);
4826 static void test_reset_resources(void)
4828 IDirect3DSurface8 *surface, *rt;
4829 IDirect3DTexture8 *texture;
4830 IDirect3DDevice8 *device;
4831 IDirect3D8 *d3d8;
4832 HWND window;
4833 HRESULT hr;
4834 ULONG ref;
4836 window = create_window();
4837 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
4838 ok(!!d3d8, "Failed to create a D3D object.\n");
4840 if (!(device = create_device(d3d8, window, NULL)))
4842 skip("Failed to create a D3D device, skipping tests.\n");
4843 goto done;
4846 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 128, 128, D3DFMT_D24S8,
4847 D3DMULTISAMPLE_NONE, &surface);
4848 ok(SUCCEEDED(hr), "Failed to create depth/stencil surface, hr %#x.\n", hr);
4850 hr = IDirect3DDevice8_CreateTexture(device, 128, 128, 1, D3DUSAGE_RENDERTARGET,
4851 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture);
4852 ok(SUCCEEDED(hr), "Failed to create render target texture, hr %#x.\n", hr);
4853 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 0, &rt);
4854 ok(SUCCEEDED(hr), "Failed to get surface, hr %#x.\n", hr);
4855 IDirect3DTexture8_Release(texture);
4857 hr = IDirect3DDevice8_SetRenderTarget(device, rt, surface);
4858 ok(SUCCEEDED(hr), "Failed to set render target surface, hr %#x.\n", hr);
4859 IDirect3DSurface8_Release(rt);
4860 IDirect3DSurface8_Release(surface);
4862 hr = reset_device(device, NULL);
4863 ok(SUCCEEDED(hr), "Failed to reset device.\n");
4865 hr = IDirect3DDevice8_GetBackBuffer(device, 0, D3DBACKBUFFER_TYPE_MONO, &rt);
4866 ok(SUCCEEDED(hr), "Failed to get back buffer, hr %#x.\n", hr);
4867 hr = IDirect3DDevice8_GetRenderTarget(device, &surface);
4868 ok(SUCCEEDED(hr), "Failed to get render target surface, hr %#x.\n", hr);
4869 ok(surface == rt, "Got unexpected surface %p for render target.\n", surface);
4870 IDirect3DSurface8_Release(surface);
4871 IDirect3DSurface8_Release(rt);
4873 ref = IDirect3DDevice8_Release(device);
4874 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
4876 done:
4877 IDirect3D8_Release(d3d8);
4878 DestroyWindow(window);
4881 static void test_set_rt_vp_scissor(void)
4883 IDirect3DDevice8 *device;
4884 IDirect3DSurface8 *rt;
4885 IDirect3D8 *d3d8;
4886 DWORD stateblock;
4887 D3DVIEWPORT8 vp;
4888 UINT refcount;
4889 HWND window;
4890 HRESULT hr;
4892 window = create_window();
4893 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
4894 ok(!!d3d8, "Failed to create a D3D object.\n");
4895 if (!(device = create_device(d3d8, window, NULL)))
4897 skip("Failed to create a D3D device, skipping tests.\n");
4898 IDirect3D8_Release(d3d8);
4899 DestroyWindow(window);
4900 return;
4903 hr = IDirect3DDevice8_CreateRenderTarget(device, 128, 128, D3DFMT_A8R8G8B8,
4904 D3DMULTISAMPLE_NONE, FALSE, &rt);
4905 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
4907 hr = IDirect3DDevice8_GetViewport(device, &vp);
4908 ok(SUCCEEDED(hr), "Failed to get viewport, hr %#x.\n", hr);
4909 ok(!vp.X, "Got unexpected vp.X %u.\n", vp.X);
4910 ok(!vp.Y, "Got unexpected vp.Y %u.\n", vp.Y);
4911 ok(vp.Width == 640, "Got unexpected vp.Width %u.\n", vp.Width);
4912 ok(vp.Height == 480, "Got unexpected vp.Height %u.\n", vp.Height);
4913 ok(vp.MinZ == 0.0f, "Got unexpected vp.MinZ %.8e.\n", vp.MinZ);
4914 ok(vp.MaxZ == 1.0f, "Got unexpected vp.MaxZ %.8e.\n", vp.MaxZ);
4916 hr = IDirect3DDevice8_BeginStateBlock(device);
4917 ok(SUCCEEDED(hr), "Failed to begin stateblock, hr %#x.\n", hr);
4919 hr = IDirect3DDevice8_SetRenderTarget(device, rt, NULL);
4920 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
4922 hr = IDirect3DDevice8_EndStateBlock(device, &stateblock);
4923 ok(SUCCEEDED(hr), "Failed to end stateblock, hr %#x.\n", hr);
4924 hr = IDirect3DDevice8_DeleteStateBlock(device, stateblock);
4925 ok(SUCCEEDED(hr), "Failed to delete stateblock, hr %#x.\n", hr);
4927 hr = IDirect3DDevice8_GetViewport(device, &vp);
4928 ok(SUCCEEDED(hr), "Failed to get viewport, hr %#x.\n", hr);
4929 ok(!vp.X, "Got unexpected vp.X %u.\n", vp.X);
4930 ok(!vp.Y, "Got unexpected vp.Y %u.\n", vp.Y);
4931 ok(vp.Width == 128, "Got unexpected vp.Width %u.\n", vp.Width);
4932 ok(vp.Height == 128, "Got unexpected vp.Height %u.\n", vp.Height);
4933 ok(vp.MinZ == 0.0f, "Got unexpected vp.MinZ %.8e.\n", vp.MinZ);
4934 ok(vp.MaxZ == 1.0f, "Got unexpected vp.MaxZ %.8e.\n", vp.MaxZ);
4936 hr = IDirect3DDevice8_SetRenderTarget(device, rt, NULL);
4937 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
4939 vp.X = 10;
4940 vp.Y = 20;
4941 vp.Width = 30;
4942 vp.Height = 40;
4943 vp.MinZ = 0.25f;
4944 vp.MaxZ = 0.75f;
4945 hr = IDirect3DDevice8_SetViewport(device, &vp);
4946 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
4948 hr = IDirect3DDevice8_SetRenderTarget(device, rt, NULL);
4949 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
4951 hr = IDirect3DDevice8_GetViewport(device, &vp);
4952 ok(SUCCEEDED(hr), "Failed to get viewport, hr %#x.\n", hr);
4953 ok(!vp.X, "Got unexpected vp.X %u.\n", vp.X);
4954 ok(!vp.Y, "Got unexpected vp.Y %u.\n", vp.Y);
4955 ok(vp.Width == 128, "Got unexpected vp.Width %u.\n", vp.Width);
4956 ok(vp.Height == 128, "Got unexpected vp.Height %u.\n", vp.Height);
4957 ok(vp.MinZ == 0.0f, "Got unexpected vp.MinZ %.8e.\n", vp.MinZ);
4958 ok(vp.MaxZ == 1.0f, "Got unexpected vp.MaxZ %.8e.\n", vp.MaxZ);
4960 IDirect3DSurface8_Release(rt);
4961 refcount = IDirect3DDevice8_Release(device);
4962 ok(!refcount, "Device has %u references left.\n", refcount);
4963 IDirect3D8_Release(d3d8);
4964 DestroyWindow(window);
4967 static void test_validate_vs(void)
4969 static DWORD vs_code[] =
4971 0xfffe0101, /* vs_1_1 */
4972 0x00000009, 0xc0010000, 0x90e40000, 0xa0e40000, /* dp4 oPos.x, v0, c0 */
4973 0x00000009, 0xc0020000, 0x90e40000, 0xa0e40001, /* dp4 oPos.y, v0, c1 */
4974 0x00000009, 0xc0040000, 0x90e40000, 0xa0e40002, /* dp4 oPos.z, v0, c2 */
4975 0x00000009, 0xc0080000, 0x90e40000, 0xa0e40003, /* dp4 oPos.w, v0, c3 */
4976 0x0000ffff, /* end */
4978 D3DCAPS8 caps;
4979 char *errors;
4980 HRESULT hr;
4982 static DWORD declaration_valid1[] =
4984 D3DVSD_STREAM(0),
4985 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT4),
4986 D3DVSD_END()
4988 static DWORD declaration_valid2[] =
4990 D3DVSD_STREAM(0),
4991 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT2),
4992 D3DVSD_END()
4994 static DWORD declaration_invalid[] =
4996 D3DVSD_STREAM(0),
4997 D3DVSD_REG(D3DVSDE_NORMAL, D3DVSDT_FLOAT4),
4998 D3DVSD_END()
5001 hr = ValidateVertexShader(NULL, NULL, NULL, FALSE, NULL);
5002 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
5003 hr = ValidateVertexShader(NULL, NULL, NULL, TRUE, NULL);
5004 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
5005 hr = ValidateVertexShader(NULL, NULL, NULL, FALSE, &errors);
5006 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
5007 ok(!*errors, "Got unexpected string \"%s\".\n", errors);
5008 heap_free(errors);
5009 hr = ValidateVertexShader(NULL, NULL, NULL, TRUE, &errors);
5010 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
5011 ok(!!*errors, "Got unexpected empty string.\n");
5012 heap_free(errors);
5014 hr = ValidateVertexShader(vs_code, NULL, NULL, FALSE, NULL);
5015 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5016 hr = ValidateVertexShader(vs_code, NULL, NULL, TRUE, NULL);
5017 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5018 hr = ValidateVertexShader(vs_code, NULL, NULL, TRUE, &errors);
5019 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5020 ok(!*errors, "Got unexpected string \"%s\".\n", errors);
5021 heap_free(errors);
5023 hr = ValidateVertexShader(vs_code, declaration_valid1, NULL, FALSE, NULL);
5024 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5025 hr = ValidateVertexShader(vs_code, declaration_valid2, NULL, FALSE, NULL);
5026 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5027 hr = ValidateVertexShader(vs_code, declaration_invalid, NULL, FALSE, NULL);
5028 todo_wine ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
5030 memset(&caps, 0, sizeof(caps));
5031 caps.VertexShaderVersion = D3DVS_VERSION(1, 1);
5032 caps.MaxVertexShaderConst = 4;
5033 hr = ValidateVertexShader(vs_code, NULL, &caps, FALSE, NULL);
5034 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5035 caps.VertexShaderVersion = D3DVS_VERSION(1, 0);
5036 hr = ValidateVertexShader(vs_code, NULL, &caps, FALSE, NULL);
5037 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
5038 caps.VertexShaderVersion = D3DVS_VERSION(1, 2);
5039 hr = ValidateVertexShader(vs_code, NULL, &caps, FALSE, NULL);
5040 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5041 caps.VertexShaderVersion = D3DVS_VERSION(8, 8);
5042 hr = ValidateVertexShader(vs_code, NULL, &caps, FALSE, NULL);
5043 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5044 caps.VertexShaderVersion = D3DVS_VERSION(1, 1);
5045 caps.MaxVertexShaderConst = 3;
5046 hr = ValidateVertexShader(vs_code, NULL, &caps, FALSE, NULL);
5047 todo_wine ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
5049 *vs_code = D3DVS_VERSION(1, 0);
5050 hr = ValidateVertexShader(vs_code, NULL, NULL, FALSE, NULL);
5051 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5052 *vs_code = D3DVS_VERSION(1, 2);
5053 hr = ValidateVertexShader(vs_code, NULL, NULL, TRUE, NULL);
5054 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
5055 hr = ValidateVertexShader(vs_code, NULL, NULL, FALSE, &errors);
5056 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
5057 ok(!*errors, "Got unexpected string \"%s\".\n", errors);
5058 heap_free(errors);
5059 hr = ValidateVertexShader(vs_code, NULL, NULL, TRUE, &errors);
5060 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
5061 ok(!!*errors, "Got unexpected empty string.\n");
5062 heap_free(errors);
5065 static void test_validate_ps(void)
5067 static DWORD ps_1_1_code[] =
5069 0xffff0101, /* ps_1_1 */
5070 0x00000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
5071 0x00000002, 0x800f0000, 0x80e40001, 0xa0e40002, /* add r0, r1, c2 */
5072 0x0000ffff /* end */
5074 static const DWORD ps_2_0_code[] =
5076 0xffff0200, /* ps_2_0 */
5077 0x02000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
5078 0x03000002, 0x800f0000, 0x80e40001, 0xa0e40002, /* add r0, r1, c2 */
5079 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
5080 0x0000ffff /* end */
5082 D3DCAPS8 caps;
5083 char *errors;
5084 HRESULT hr;
5086 hr = ValidatePixelShader(NULL, NULL, FALSE, NULL);
5087 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
5088 hr = ValidatePixelShader(NULL, NULL, TRUE, NULL);
5089 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
5090 errors = (void *)0xcafeface;
5091 hr = ValidatePixelShader(NULL, NULL, FALSE, &errors);
5092 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
5093 ok(errors == (void *)0xcafeface, "Got unexpected errors %p.\n", errors);
5094 errors = (void *)0xcafeface;
5095 hr = ValidatePixelShader(NULL, NULL, TRUE, &errors);
5096 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
5097 ok(errors == (void *)0xcafeface, "Got unexpected errors %p.\n", errors);
5099 hr = ValidatePixelShader(ps_1_1_code, NULL, FALSE, NULL);
5100 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5101 hr = ValidatePixelShader(ps_1_1_code, NULL, TRUE, NULL);
5102 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5103 hr = ValidatePixelShader(ps_1_1_code, NULL, TRUE, &errors);
5104 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5105 ok(!*errors, "Got unexpected string \"%s\".\n", errors);
5106 heap_free(errors);
5108 memset(&caps, 0, sizeof(caps));
5109 caps.PixelShaderVersion = D3DPS_VERSION(1, 1);
5110 hr = ValidatePixelShader(ps_1_1_code, &caps, FALSE, NULL);
5111 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5112 caps.PixelShaderVersion = D3DPS_VERSION(1, 0);
5113 hr = ValidatePixelShader(ps_1_1_code, &caps, FALSE, NULL);
5114 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
5115 caps.PixelShaderVersion = D3DPS_VERSION(1, 2);
5116 hr = ValidatePixelShader(ps_1_1_code, &caps, FALSE, NULL);
5117 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5118 caps.PixelShaderVersion = D3DPS_VERSION(8, 8);
5119 hr = ValidatePixelShader(ps_1_1_code, &caps, FALSE, NULL);
5120 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5122 *ps_1_1_code = D3DPS_VERSION(1, 0);
5123 hr = ValidatePixelShader(ps_1_1_code, NULL, FALSE, NULL);
5124 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5125 *ps_1_1_code = D3DPS_VERSION(1, 4);
5126 hr = ValidatePixelShader(ps_1_1_code, NULL, FALSE, NULL);
5127 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5128 hr = ValidatePixelShader(ps_2_0_code, NULL, FALSE, NULL);
5129 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
5130 *ps_1_1_code = D3DPS_VERSION(1, 5);
5131 hr = ValidatePixelShader(ps_1_1_code, NULL, TRUE, NULL);
5132 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
5133 hr = ValidatePixelShader(ps_1_1_code, NULL, FALSE, &errors);
5134 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
5135 ok(!*errors, "Got unexpected string \"%s\".\n", errors);
5136 heap_free(errors);
5137 hr = ValidatePixelShader(ps_1_1_code, NULL, TRUE, &errors);
5138 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
5139 ok(!!*errors, "Got unexpected empty string.\n");
5140 heap_free(errors);
5143 static void test_volume_get_container(void)
5145 IDirect3DVolumeTexture8 *texture = NULL;
5146 IDirect3DVolume8 *volume = NULL;
5147 IDirect3DDevice8 *device;
5148 IUnknown *container;
5149 IDirect3D8 *d3d8;
5150 ULONG refcount;
5151 D3DCAPS8 caps;
5152 HWND window;
5153 HRESULT hr;
5155 window = create_window();
5156 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
5157 ok(!!d3d8, "Failed to create a D3D object.\n");
5158 if (!(device = create_device(d3d8, window, NULL)))
5160 skip("Failed to create a D3D device, skipping tests.\n");
5161 IDirect3D8_Release(d3d8);
5162 DestroyWindow(window);
5163 return;
5166 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
5167 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
5168 if (!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP))
5170 skip("No volume texture support, skipping tests.\n");
5171 IDirect3DDevice8_Release(device);
5172 IDirect3D8_Release(d3d8);
5173 DestroyWindow(window);
5174 return;
5177 hr = IDirect3DDevice8_CreateVolumeTexture(device, 128, 128, 128, 1, 0,
5178 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture);
5179 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x.\n", hr);
5180 ok(!!texture, "Got unexpected texture %p.\n", texture);
5182 hr = IDirect3DVolumeTexture8_GetVolumeLevel(texture, 0, &volume);
5183 ok(SUCCEEDED(hr), "Failed to get volume level, hr %#x.\n", hr);
5184 ok(!!volume, "Got unexpected volume %p.\n", volume);
5186 /* These should work... */
5187 container = NULL;
5188 hr = IDirect3DVolume8_GetContainer(volume, &IID_IUnknown, (void **)&container);
5189 ok(SUCCEEDED(hr), "Failed to get volume container, hr %#x.\n", hr);
5190 ok(container == (IUnknown *)texture, "Got unexpected container %p, expected %p.\n", container, texture);
5191 IUnknown_Release(container);
5193 container = NULL;
5194 hr = IDirect3DVolume8_GetContainer(volume, &IID_IDirect3DResource8, (void **)&container);
5195 ok(SUCCEEDED(hr), "Failed to get volume container, hr %#x.\n", hr);
5196 ok(container == (IUnknown *)texture, "Got unexpected container %p, expected %p.\n", container, texture);
5197 IUnknown_Release(container);
5199 container = NULL;
5200 hr = IDirect3DVolume8_GetContainer(volume, &IID_IDirect3DBaseTexture8, (void **)&container);
5201 ok(SUCCEEDED(hr), "Failed to get volume container, hr %#x.\n", hr);
5202 ok(container == (IUnknown *)texture, "Got unexpected container %p, expected %p.\n", container, texture);
5203 IUnknown_Release(container);
5205 container = NULL;
5206 hr = IDirect3DVolume8_GetContainer(volume, &IID_IDirect3DVolumeTexture8, (void **)&container);
5207 ok(SUCCEEDED(hr), "Failed to get volume container, hr %#x.\n", hr);
5208 ok(container == (IUnknown *)texture, "Got unexpected container %p, expected %p.\n", container, texture);
5209 IUnknown_Release(container);
5211 /* ...and this one shouldn't. This should return E_NOINTERFACE and set container to NULL. */
5212 hr = IDirect3DVolume8_GetContainer(volume, &IID_IDirect3DVolume8, (void **)&container);
5213 ok(hr == E_NOINTERFACE, "Got unexpected hr %#x.\n", hr);
5214 ok(!container, "Got unexpected container %p.\n", container);
5216 IDirect3DVolume8_Release(volume);
5217 IDirect3DVolumeTexture8_Release(texture);
5218 refcount = IDirect3DDevice8_Release(device);
5219 ok(!refcount, "Device has %u references left.\n", refcount);
5220 IDirect3D8_Release(d3d8);
5221 DestroyWindow(window);
5224 static void test_vb_lock_flags(void)
5226 static const struct
5228 DWORD flags;
5229 const char *debug_string;
5230 HRESULT result;
5232 test_data[] =
5234 {D3DLOCK_READONLY, "D3DLOCK_READONLY", D3D_OK },
5235 {D3DLOCK_DISCARD, "D3DLOCK_DISCARD", D3D_OK },
5236 {D3DLOCK_NOOVERWRITE, "D3DLOCK_NOOVERWRITE", D3D_OK },
5237 {D3DLOCK_NOOVERWRITE | D3DLOCK_DISCARD, "D3DLOCK_NOOVERWRITE | D3DLOCK_DISCARD", D3D_OK },
5238 {D3DLOCK_NOOVERWRITE | D3DLOCK_READONLY, "D3DLOCK_NOOVERWRITE | D3DLOCK_READONLY", D3D_OK },
5239 {D3DLOCK_READONLY | D3DLOCK_DISCARD, "D3DLOCK_READONLY | D3DLOCK_DISCARD", D3D_OK },
5240 /* Completely bogus flags aren't an error. */
5241 {0xdeadbeef, "0xdeadbeef", D3D_OK },
5243 IDirect3DVertexBuffer8 *buffer;
5244 IDirect3DDevice8 *device;
5245 IDirect3D8 *d3d8;
5246 unsigned int i;
5247 ULONG refcount;
5248 HWND window;
5249 HRESULT hr;
5250 BYTE *data;
5252 window = create_window();
5253 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
5254 ok(!!d3d8, "Failed to create a D3D object.\n");
5255 if (!(device = create_device(d3d8, window, NULL)))
5257 skip("Failed to create a D3D device, skipping tests.\n");
5258 IDirect3D8_Release(d3d8);
5259 DestroyWindow(window);
5260 return;
5263 hr = IDirect3DDevice8_CreateVertexBuffer(device, 1024, D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY,
5264 0, D3DPOOL_DEFAULT, &buffer);
5265 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
5267 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
5269 hr = IDirect3DVertexBuffer8_Lock(buffer, 0, 0, &data, test_data[i].flags);
5270 ok(hr == test_data[i].result, "Got unexpected hr %#x for %s.\n",
5271 hr, test_data[i].debug_string);
5272 if (SUCCEEDED(hr))
5274 ok(!!data, "Got unexpected data %p.\n", data);
5275 hr = IDirect3DVertexBuffer8_Unlock(buffer);
5276 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
5280 IDirect3DVertexBuffer8_Release(buffer);
5281 refcount = IDirect3DDevice8_Release(device);
5282 ok(!refcount, "Device has %u references left.\n", refcount);
5283 IDirect3D8_Release(d3d8);
5284 DestroyWindow(window);
5287 /* Test the default texture stage state values */
5288 static void test_texture_stage_states(void)
5290 IDirect3DDevice8 *device;
5291 IDirect3D8 *d3d8;
5292 unsigned int i;
5293 ULONG refcount;
5294 D3DCAPS8 caps;
5295 DWORD value;
5296 HWND window;
5297 HRESULT hr;
5299 window = create_window();
5300 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
5301 ok(!!d3d8, "Failed to create a D3D object.\n");
5302 if (!(device = create_device(d3d8, window, NULL)))
5304 skip("Failed to create a D3D device, skipping tests.\n");
5305 IDirect3D8_Release(d3d8);
5306 DestroyWindow(window);
5307 return;
5310 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
5311 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
5313 for (i = 0; i < caps.MaxTextureBlendStages; ++i)
5315 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_COLOROP, &value);
5316 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
5317 ok(value == (i ? D3DTOP_DISABLE : D3DTOP_MODULATE),
5318 "Got unexpected value %#x for D3DTSS_COLOROP, stage %u.\n", value, i);
5319 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_COLORARG1, &value);
5320 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
5321 ok(value == D3DTA_TEXTURE, "Got unexpected value %#x for D3DTSS_COLORARG1, stage %u.\n", value, i);
5322 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_COLORARG2, &value);
5323 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
5324 ok(value == D3DTA_CURRENT, "Got unexpected value %#x for D3DTSS_COLORARG2, stage %u.\n", value, i);
5325 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_ALPHAOP, &value);
5326 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
5327 ok(value == (i ? D3DTOP_DISABLE : D3DTOP_SELECTARG1),
5328 "Got unexpected value %#x for D3DTSS_ALPHAOP, stage %u.\n", value, i);
5329 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_ALPHAARG1, &value);
5330 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
5331 ok(value == D3DTA_TEXTURE, "Got unexpected value %#x for D3DTSS_ALPHAARG1, stage %u.\n", value, i);
5332 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_ALPHAARG2, &value);
5333 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
5334 ok(value == D3DTA_CURRENT, "Got unexpected value %#x for D3DTSS_ALPHAARG2, stage %u.\n", value, i);
5335 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_BUMPENVMAT00, &value);
5336 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
5337 ok(!value, "Got unexpected value %#x for D3DTSS_BUMPENVMAT00, stage %u.\n", value, i);
5338 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_BUMPENVMAT01, &value);
5339 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
5340 ok(!value, "Got unexpected value %#x for D3DTSS_BUMPENVMAT01, stage %u.\n", value, i);
5341 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_BUMPENVMAT10, &value);
5342 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
5343 ok(!value, "Got unexpected value %#x for D3DTSS_BUMPENVMAT10, stage %u.\n", value, i);
5344 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_BUMPENVMAT11, &value);
5345 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
5346 ok(!value, "Got unexpected value %#x for D3DTSS_BUMPENVMAT11, stage %u.\n", value, i);
5347 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_TEXCOORDINDEX, &value);
5348 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
5349 ok(value == i, "Got unexpected value %#x for D3DTSS_TEXCOORDINDEX, stage %u.\n", value, i);
5350 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_BUMPENVLSCALE, &value);
5351 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
5352 ok(!value, "Got unexpected value %#x for D3DTSS_BUMPENVLSCALE, stage %u.\n", value, i);
5353 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_BUMPENVLOFFSET, &value);
5354 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
5355 ok(!value, "Got unexpected value %#x for D3DTSS_BUMPENVLOFFSET, stage %u.\n", value, i);
5356 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_TEXTURETRANSFORMFLAGS, &value);
5357 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
5358 ok(value == D3DTTFF_DISABLE,
5359 "Got unexpected value %#x for D3DTSS_TEXTURETRANSFORMFLAGS, stage %u.\n", value, i);
5360 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_COLORARG0, &value);
5361 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
5362 ok(value == D3DTA_CURRENT, "Got unexpected value %#x for D3DTSS_COLORARG0, stage %u.\n", value, i);
5363 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_ALPHAARG0, &value);
5364 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
5365 ok(value == D3DTA_CURRENT, "Got unexpected value %#x for D3DTSS_ALPHAARG0, stage %u.\n", value, i);
5366 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_RESULTARG, &value);
5367 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
5368 ok(value == D3DTA_CURRENT, "Got unexpected value %#x for D3DTSS_RESULTARG, stage %u.\n", value, i);
5371 refcount = IDirect3DDevice8_Release(device);
5372 ok(!refcount, "Device has %u references left.\n", refcount);
5373 IDirect3D8_Release(d3d8);
5374 DestroyWindow(window);
5377 static void test_cube_textures(void)
5379 IDirect3DCubeTexture8 *texture;
5380 IDirect3DDevice8 *device;
5381 IDirect3D8 *d3d8;
5382 ULONG refcount;
5383 D3DCAPS8 caps;
5384 HWND window;
5385 HRESULT hr;
5387 window = create_window();
5388 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
5389 ok(!!d3d8, "Failed to create a D3D object.\n");
5390 if (!(device = create_device(d3d8, window, NULL)))
5392 skip("Failed to create a D3D device, skipping tests.\n");
5393 IDirect3D8_Release(d3d8);
5394 DestroyWindow(window);
5395 return;
5398 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
5399 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
5401 if (caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP)
5403 hr = IDirect3DDevice8_CreateCubeTexture(device, 512, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &texture);
5404 ok(hr == D3D_OK, "Failed to create D3DPOOL_DEFAULT cube texture, hr %#x.\n", hr);
5405 IDirect3DCubeTexture8_Release(texture);
5406 hr = IDirect3DDevice8_CreateCubeTexture(device, 512, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &texture);
5407 ok(hr == D3D_OK, "Failed to create D3DPOOL_MANAGED cube texture, hr %#x.\n", hr);
5408 IDirect3DCubeTexture8_Release(texture);
5409 hr = IDirect3DDevice8_CreateCubeTexture(device, 512, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_SYSTEMMEM, &texture);
5410 ok(hr == D3D_OK, "Failed to create D3DPOOL_SYSTEMMEM cube texture, hr %#x.\n", hr);
5411 IDirect3DCubeTexture8_Release(texture);
5413 else
5415 hr = IDirect3DDevice8_CreateCubeTexture(device, 512, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &texture);
5416 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for D3DPOOL_DEFAULT cube texture.\n", hr);
5417 hr = IDirect3DDevice8_CreateCubeTexture(device, 512, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &texture);
5418 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for D3DPOOL_MANAGED cube texture.\n", hr);
5419 hr = IDirect3DDevice8_CreateCubeTexture(device, 512, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_SYSTEMMEM, &texture);
5420 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for D3DPOOL_SYSTEMMEM cube texture.\n", hr);
5422 hr = IDirect3DDevice8_CreateCubeTexture(device, 512, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_SCRATCH, &texture);
5423 ok(hr == D3D_OK, "Failed to create D3DPOOL_SCRATCH cube texture, hr %#x.\n", hr);
5424 IDirect3DCubeTexture8_Release(texture);
5426 refcount = IDirect3DDevice8_Release(device);
5427 ok(!refcount, "Device has %u references left.\n", refcount);
5428 IDirect3D8_Release(d3d8);
5429 DestroyWindow(window);
5432 static void test_get_set_texture(void)
5434 const IDirect3DBaseTexture8Vtbl *texture_vtbl;
5435 IDirect3DBaseTexture8 *texture;
5436 IDirect3DDevice8 *device;
5437 IDirect3D8 *d3d;
5438 ULONG refcount;
5439 HWND window;
5440 HRESULT hr;
5442 window = create_window();
5443 d3d = Direct3DCreate8(D3D_SDK_VERSION);
5444 ok(!!d3d, "Failed to create a D3D object.\n");
5445 if (!(device = create_device(d3d, window, NULL)))
5447 skip("Failed to create a D3D device, skipping tests.\n");
5448 IDirect3D8_Release(d3d);
5449 DestroyWindow(window);
5450 return;
5453 texture = (IDirect3DBaseTexture8 *)0xdeadbeef;
5454 hr = IDirect3DDevice8_SetTexture(device, 0, NULL);
5455 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
5456 hr = IDirect3DDevice8_GetTexture(device, 0, &texture);
5457 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
5458 ok(!texture, "Got unexpected texture %p.\n", texture);
5460 hr = IDirect3DDevice8_CreateTexture(device, 16, 16, 1, 0, D3DFMT_A8R8G8B8,
5461 D3DPOOL_MANAGED, (IDirect3DTexture8 **)&texture);
5462 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5463 texture_vtbl = texture->lpVtbl;
5464 texture->lpVtbl = (IDirect3DBaseTexture8Vtbl *)0xdeadbeef;
5465 hr = IDirect3DDevice8_SetTexture(device, 0, texture);
5466 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
5467 hr = IDirect3DDevice8_SetTexture(device, 0, NULL);
5468 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
5469 texture->lpVtbl = NULL;
5470 hr = IDirect3DDevice8_SetTexture(device, 0, texture);
5471 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
5472 hr = IDirect3DDevice8_SetTexture(device, 0, NULL);
5473 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
5474 texture->lpVtbl = texture_vtbl;
5475 IDirect3DBaseTexture8_Release(texture);
5477 refcount = IDirect3DDevice8_Release(device);
5478 ok(!refcount, "Device has %u references left.\n", refcount);
5479 IDirect3D8_Release(d3d);
5480 DestroyWindow(window);
5483 /* Test the behaviour of the IDirect3DDevice8::CreateImageSurface() method.
5485 * The expected behaviour (as documented in the original DX8 docs) is that the
5486 * call returns a surface in the SYSTEMMEM pool. Games like Max Payne 1 and 2
5487 * depend on this behaviour.
5489 * A short remark in the DX9 docs however states that the pool of the returned
5490 * surface object is D3DPOOL_SCRATCH. This is misinformation and would result
5491 * in screenshots not appearing in the savegame loading menu of both games
5492 * mentioned above (engine tries to display a texture from the scratch pool).
5494 * This test verifies that the behaviour described in the original d3d8 docs
5495 * is the correct one. For more information about this issue, see the MSDN:
5496 * d3d9 docs: "Converting to Direct3D 9"
5497 * d3d9 reference: "IDirect3DDevice9::CreateOffscreenPlainSurface"
5498 * d3d8 reference: "IDirect3DDevice8::CreateImageSurface" */
5499 static void test_image_surface_pool(void)
5501 IDirect3DSurface8 *surface;
5502 IDirect3DDevice8 *device;
5503 D3DSURFACE_DESC desc;
5504 IDirect3D8 *d3d8;
5505 ULONG refcount;
5506 HWND window;
5507 HRESULT hr;
5509 window = create_window();
5510 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
5511 ok(!!d3d8, "Failed to create a D3D object.\n");
5512 if (!(device = create_device(d3d8, window, NULL)))
5514 skip("Failed to create a D3D device, skipping tests.\n");
5515 IDirect3D8_Release(d3d8);
5516 DestroyWindow(window);
5517 return;
5520 hr = IDirect3DDevice8_CreateImageSurface(device, 128, 128, D3DFMT_A8R8G8B8, &surface);
5521 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5522 hr = IDirect3DSurface8_GetDesc(surface, &desc);
5523 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5524 ok(desc.Pool == D3DPOOL_SYSTEMMEM, "Got unexpected pool %#x.\n", desc.Pool);
5525 IDirect3DSurface8_Release(surface);
5527 refcount = IDirect3DDevice8_Release(device);
5528 ok(!refcount, "Device has %u references left.\n", refcount);
5529 IDirect3D8_Release(d3d8);
5530 DestroyWindow(window);
5533 static void test_surface_get_container(void)
5535 IDirect3DTexture8 *texture = NULL;
5536 IDirect3DSurface8 *surface = NULL;
5537 IDirect3DDevice8 *device;
5538 IUnknown *container;
5539 IDirect3D8 *d3d8;
5540 ULONG refcount;
5541 HWND window;
5542 HRESULT hr;
5544 window = create_window();
5545 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
5546 ok(!!d3d8, "Failed to create a D3D object.\n");
5547 if (!(device = create_device(d3d8, window, NULL)))
5549 skip("Failed to create a D3D device, skipping tests.\n");
5550 IDirect3D8_Release(d3d8);
5551 DestroyWindow(window);
5552 return;
5555 hr = IDirect3DDevice8_CreateTexture(device, 128, 128, 1, 0,
5556 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture);
5557 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5558 ok(!!texture, "Got unexpected texture %p.\n", texture);
5560 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 0, &surface);
5561 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
5562 ok(!!surface, "Got unexpected surface %p.\n", surface);
5564 /* These should work... */
5565 container = NULL;
5566 hr = IDirect3DSurface8_GetContainer(surface, &IID_IUnknown, (void **)&container);
5567 ok(SUCCEEDED(hr), "Failed to get surface container, hr %#x.\n", hr);
5568 ok(container == (IUnknown *)texture, "Got unexpected container %p, expected %p.\n", container, texture);
5569 IUnknown_Release(container);
5571 container = NULL;
5572 hr = IDirect3DSurface8_GetContainer(surface, &IID_IDirect3DResource8, (void **)&container);
5573 ok(SUCCEEDED(hr), "Failed to get surface container, hr %#x.\n", hr);
5574 ok(container == (IUnknown *)texture, "Got unexpected container %p, expected %p.\n", container, texture);
5575 IUnknown_Release(container);
5577 container = NULL;
5578 hr = IDirect3DSurface8_GetContainer(surface, &IID_IDirect3DBaseTexture8, (void **)&container);
5579 ok(SUCCEEDED(hr), "Failed to get surface container, hr %#x.\n", hr);
5580 ok(container == (IUnknown *)texture, "Got unexpected container %p, expected %p.\n", container, texture);
5581 IUnknown_Release(container);
5583 container = NULL;
5584 hr = IDirect3DSurface8_GetContainer(surface, &IID_IDirect3DTexture8, (void **)&container);
5585 ok(SUCCEEDED(hr), "Failed to get surface container, hr %#x.\n", hr);
5586 ok(container == (IUnknown *)texture, "Got unexpected container %p, expected %p.\n", container, texture);
5587 IUnknown_Release(container);
5589 /* ...and this one shouldn't. This should return E_NOINTERFACE and set container to NULL. */
5590 hr = IDirect3DSurface8_GetContainer(surface, &IID_IDirect3DSurface8, (void **)&container);
5591 ok(hr == E_NOINTERFACE, "Got unexpected hr %#x.\n", hr);
5592 ok(!container, "Got unexpected container %p.\n", container);
5594 IDirect3DSurface8_Release(surface);
5595 IDirect3DTexture8_Release(texture);
5596 refcount = IDirect3DDevice8_Release(device);
5597 ok(!refcount, "Device has %u references left.\n", refcount);
5598 IDirect3D8_Release(d3d8);
5599 DestroyWindow(window);
5602 static void test_lockrect_invalid(void)
5604 static const RECT valid[] =
5606 {60, 60, 68, 68},
5607 {120, 60, 128, 68},
5608 {60, 120, 68, 128},
5610 static const RECT invalid[] =
5612 {60, 60, 60, 68}, /* 0 height */
5613 {60, 60, 68, 60}, /* 0 width */
5614 {68, 60, 60, 68}, /* left > right */
5615 {60, 68, 68, 60}, /* top > bottom */
5616 {-8, 60, 0, 68}, /* left < surface */
5617 {60, -8, 68, 0}, /* top < surface */
5618 {-16, 60, -8, 68}, /* right < surface */
5619 {60, -16, 68, -8}, /* bottom < surface */
5620 {60, 60, 136, 68}, /* right > surface */
5621 {60, 60, 68, 136}, /* bottom > surface */
5622 {136, 60, 144, 68}, /* left > surface */
5623 {60, 136, 68, 144}, /* top > surface */
5625 IDirect3DSurface8 *surface;
5626 IDirect3DTexture8 *texture;
5627 IDirect3DCubeTexture8 *cube_texture;
5628 D3DLOCKED_RECT locked_rect;
5629 IDirect3DDevice8 *device;
5630 HRESULT hr, expected_hr;
5631 IDirect3D8 *d3d8;
5632 unsigned int i, r;
5633 ULONG refcount;
5634 HWND window;
5635 BYTE *base;
5636 unsigned int offset, expected_offset;
5637 static const struct
5639 D3DRESOURCETYPE type;
5640 D3DPOOL pool;
5641 const char *name;
5642 BOOL validate, clear;
5644 resources[] =
5646 {D3DRTYPE_SURFACE, D3DPOOL_SCRATCH, "scratch surface", TRUE, TRUE},
5647 {D3DRTYPE_TEXTURE, D3DPOOL_MANAGED, "managed texture", FALSE, FALSE},
5648 {D3DRTYPE_TEXTURE, D3DPOOL_SYSTEMMEM, "sysmem texture", FALSE, FALSE},
5649 {D3DRTYPE_TEXTURE, D3DPOOL_SCRATCH, "scratch texture", FALSE, FALSE},
5650 {D3DRTYPE_CUBETEXTURE, D3DPOOL_MANAGED, "default cube texture", TRUE, TRUE},
5651 {D3DRTYPE_CUBETEXTURE, D3DPOOL_SYSTEMMEM, "sysmem cube texture", TRUE, TRUE},
5652 {D3DRTYPE_CUBETEXTURE, D3DPOOL_SCRATCH, "scratch cube texture", TRUE, TRUE},
5655 window = create_window();
5656 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
5657 ok(!!d3d8, "Failed to create a D3D object.\n");
5658 if (!(device = create_device(d3d8, window, NULL)))
5660 skip("Failed to create a D3D device, skipping tests.\n");
5661 IDirect3D8_Release(d3d8);
5662 DestroyWindow(window);
5663 return;
5666 for (r = 0; r < ARRAY_SIZE(resources); ++r)
5668 texture = NULL;
5669 cube_texture = NULL;
5670 switch (resources[r].type)
5672 case D3DRTYPE_SURFACE:
5673 hr = IDirect3DDevice8_CreateImageSurface(device, 128, 128, D3DFMT_A8R8G8B8, &surface);
5674 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x, type %s.\n", hr, resources[r].name);
5675 break;
5677 case D3DRTYPE_TEXTURE:
5678 hr = IDirect3DDevice8_CreateTexture(device, 128, 128, 1, 0, D3DFMT_A8R8G8B8,
5679 resources[r].pool, &texture);
5680 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x, type %s.\n", hr, resources[r].name);
5681 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 0, &surface);
5682 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x, type %s.\n", hr, resources[r].name);
5683 break;
5685 case D3DRTYPE_CUBETEXTURE:
5686 hr = IDirect3DDevice8_CreateCubeTexture(device, 128, 1, 0, D3DFMT_A8R8G8B8,
5687 resources[r].pool, &cube_texture);
5688 ok(SUCCEEDED(hr), "Failed to create cube texture, hr %#x, type %s.\n", hr, resources[r].name);
5689 hr = IDirect3DCubeTexture8_GetCubeMapSurface(cube_texture, D3DCUBEMAP_FACE_NEGATIVE_X, 0, &surface);
5690 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x, type %s.\n", hr, resources[r].name);
5691 break;
5693 default:
5694 break;
5697 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, NULL, 0);
5698 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, type %s.\n", hr, resources[r].name);
5699 base = locked_rect.pBits;
5700 hr = IDirect3DSurface8_UnlockRect(surface);
5701 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
5702 expected_hr = resources[r].type == D3DRTYPE_TEXTURE ? D3D_OK : D3DERR_INVALIDCALL;
5703 hr = IDirect3DSurface8_UnlockRect(surface);
5704 ok(hr == expected_hr, "Got hr %#x, expected %#x, type %s.\n", hr, expected_hr, resources[r].name);
5706 for (i = 0; i < ARRAY_SIZE(valid); ++i)
5708 const RECT *rect = &valid[i];
5710 locked_rect.pBits = (BYTE *)0xdeadbeef;
5711 locked_rect.Pitch = 0xdeadbeef;
5713 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, rect, 0);
5714 ok(SUCCEEDED(hr), "Failed to lock surface with rect %s, hr %#x, type %s.\n",
5715 wine_dbgstr_rect(rect), hr, resources[r].name);
5717 offset = (BYTE *)locked_rect.pBits - base;
5718 expected_offset = rect->top * locked_rect.Pitch + rect->left * 4;
5719 ok(offset == expected_offset,
5720 "Got unexpected offset %u (expected %u) for rect %s, type %s.\n",
5721 offset, expected_offset, wine_dbgstr_rect(rect), resources[r].name);
5723 hr = IDirect3DSurface8_UnlockRect(surface);
5724 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s\n", hr, resources[r].name);
5726 if (texture)
5728 hr = IDirect3DTexture8_LockRect(texture, 0, &locked_rect, rect, 0);
5729 ok(SUCCEEDED(hr), "Failed to lock surface with rect %s, hr %#x, type %s.\n",
5730 wine_dbgstr_rect(rect), hr, resources[r].name);
5732 offset = (BYTE *)locked_rect.pBits - base;
5733 ok(offset == expected_offset,
5734 "Got unexpected offset %u (expected %u) for rect %s, type %s.\n",
5735 offset, expected_offset, wine_dbgstr_rect(rect), resources[r].name);
5737 hr = IDirect3DTexture8_UnlockRect(texture, 0);
5738 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
5740 if (cube_texture)
5742 hr = IDirect3DCubeTexture8_LockRect(cube_texture, D3DCUBEMAP_FACE_NEGATIVE_X, 0, &locked_rect, rect, 0);
5743 ok(SUCCEEDED(hr), "Failed to lock surface with rect %s, hr %#x, type %s.\n",
5744 wine_dbgstr_rect(rect), hr, resources[r].name);
5746 offset = (BYTE *)locked_rect.pBits - base;
5747 ok(offset == expected_offset,
5748 "Got unexpected offset %u (expected %u) for rect %s, type %s.\n",
5749 offset, expected_offset, wine_dbgstr_rect(rect), resources[r].name);
5751 hr = IDirect3DCubeTexture8_UnlockRect(cube_texture, D3DCUBEMAP_FACE_NEGATIVE_X, 0);
5752 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
5756 for (i = 0; i < ARRAY_SIZE(invalid); ++i)
5758 const RECT *rect = &invalid[i];
5760 locked_rect.pBits = (void *)0xdeadbeef;
5761 locked_rect.Pitch = 1;
5762 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, rect, 0);
5763 if (resources[r].validate)
5764 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for rect %s, type %s.\n",
5765 hr, wine_dbgstr_rect(rect), resources[r].name);
5766 else
5767 ok(SUCCEEDED(hr), "Got unexpected hr %#x for rect %s, type %s.\n",
5768 hr, wine_dbgstr_rect(rect), resources[r].name);
5770 if (SUCCEEDED(hr))
5772 offset = (BYTE *)locked_rect.pBits - base;
5773 expected_offset = rect->top * locked_rect.Pitch + rect->left * 4;
5774 ok(offset == expected_offset,
5775 "Got unexpected offset %u (expected %u) for rect %s, type %s.\n",
5776 offset, expected_offset,wine_dbgstr_rect(rect), resources[r].name);
5778 hr = IDirect3DSurface8_UnlockRect(surface);
5779 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
5781 else
5783 ok(!locked_rect.pBits, "Got unexpected pBits %p, type %s.\n",
5784 locked_rect.pBits, resources[r].name);
5785 ok(!locked_rect.Pitch, "Got unexpected Pitch %u, type %s.\n",
5786 locked_rect.Pitch, resources[r].name);
5790 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, NULL, 0);
5791 ok(SUCCEEDED(hr), "Failed to lock surface with rect NULL, hr %#x, type %s.\n",
5792 hr, resources[r].name);
5793 locked_rect.pBits = (void *)0xdeadbeef;
5794 locked_rect.Pitch = 1;
5795 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, NULL, 0);
5796 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x, type %s.\n", hr, resources[r].name);
5797 if (resources[r].clear)
5799 ok(!locked_rect.pBits, "Got unexpected pBits %p, type %s.\n",
5800 locked_rect.pBits, resources[r].name);
5801 ok(!locked_rect.Pitch, "Got unexpected Pitch %u, type %s.\n",
5802 locked_rect.Pitch, resources[r].name);
5804 else
5806 ok(locked_rect.pBits == (void *)0xdeadbeef, "Got unexpected pBits %p, type %s.\n",
5807 locked_rect.pBits, resources[r].name);
5808 ok(locked_rect.Pitch == 1, "Got unexpected Pitch %u, type %s.\n",
5809 locked_rect.Pitch, resources[r].name);
5811 hr = IDirect3DSurface8_UnlockRect(surface);
5812 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
5814 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, &valid[0], 0);
5815 ok(hr == D3D_OK, "Got unexpected hr %#x for rect %s, type %s.\n",
5816 hr, wine_dbgstr_rect(&valid[0]), resources[r].name);
5817 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, &valid[0], 0);
5818 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for rect %s, type %s.\n",
5819 hr, wine_dbgstr_rect(&valid[0]), resources[r].name);
5820 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, &valid[1], 0);
5821 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for rect %s, type %s.\n",
5822 hr, wine_dbgstr_rect(&valid[1]), resources[r].name);
5823 hr = IDirect3DSurface8_UnlockRect(surface);
5824 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
5826 IDirect3DSurface8_Release(surface);
5827 if (texture)
5829 hr = IDirect3DTexture8_LockRect(texture, 0, &locked_rect, NULL, 0);
5830 ok(SUCCEEDED(hr), "Failed to lock texture with rect NULL, hr %#x, type %s.\n",
5831 hr, resources[r].name);
5832 locked_rect.pBits = (void *)0xdeadbeef;
5833 locked_rect.Pitch = 1;
5834 hr = IDirect3DTexture8_LockRect(texture, 0, &locked_rect, NULL, 0);
5835 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x, type %s.\n", hr, resources[r].name);
5836 ok(locked_rect.pBits == (void *)0xdeadbeef, "Got unexpected pBits %p, type %s.\n",
5837 locked_rect.pBits, resources[r].name);
5838 ok(locked_rect.Pitch == 1, "Got unexpected Pitch %u, type %s.\n",
5839 locked_rect.Pitch, resources[r].name);
5840 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, NULL, 0);
5841 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x, type %s.\n", hr, resources[r].name);
5842 hr = IDirect3DTexture8_UnlockRect(texture, 0);
5843 ok(SUCCEEDED(hr), "Failed to unlock texture, hr %#x, type %s.\n", hr, resources[r].name);
5844 hr = IDirect3DTexture8_UnlockRect(texture, 0);
5845 ok(hr == D3D_OK, "Got unexpected hr %#x, type %s.\n", hr, resources[r].name);
5847 hr = IDirect3DTexture8_LockRect(texture, 0, &locked_rect, &valid[0], 0);
5848 ok(hr == D3D_OK, "Got unexpected hr %#x for rect %s, type %s.\n",
5849 hr, wine_dbgstr_rect(&valid[0]), resources[r].name);
5850 hr = IDirect3DTexture8_LockRect(texture, 0, &locked_rect, &valid[0], 0);
5851 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for rect %s, type %s.\n",
5852 hr, wine_dbgstr_rect(&valid[0]), resources[r].name);
5853 hr = IDirect3DTexture8_LockRect(texture, 0, &locked_rect, &valid[1], 0);
5854 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for rect %s, type %s.\n",
5855 hr, wine_dbgstr_rect(&valid[1]), resources[r].name);
5856 hr = IDirect3DTexture8_UnlockRect(texture, 0);
5857 ok(SUCCEEDED(hr), "Failed to unlock texture, hr %#x, type %s.\n", hr, resources[r].name);
5859 IDirect3DTexture8_Release(texture);
5861 hr = IDirect3DDevice8_CreateTexture(device, 128, 128, 1, D3DUSAGE_WRITEONLY,
5862 D3DFMT_A8R8G8B8, resources[r].pool, &texture);
5863 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for type %s.\n",
5864 hr, resources[r].name);
5867 if (cube_texture)
5869 hr = IDirect3DCubeTexture8_LockRect(cube_texture, D3DCUBEMAP_FACE_NEGATIVE_X, 0,
5870 &locked_rect, NULL, 0);
5871 ok(SUCCEEDED(hr), "Failed to lock texture with rect NULL, hr %#x, type %s.\n",
5872 hr, resources[r].name);
5873 locked_rect.pBits = (void *)0xdeadbeef;
5874 locked_rect.Pitch = 1;
5875 hr = IDirect3DCubeTexture8_LockRect(cube_texture, D3DCUBEMAP_FACE_NEGATIVE_X, 0,
5876 &locked_rect, NULL, 0);
5877 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x, type %s.\n", hr, resources[r].name);
5878 ok(!locked_rect.pBits, "Got unexpected pBits %p, type %s.\n",
5879 locked_rect.pBits, resources[r].name);
5880 ok(!locked_rect.Pitch, "Got unexpected Pitch %u, type %s.\n",
5881 locked_rect.Pitch, resources[r].name);
5882 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, NULL, 0);
5883 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x, type %s.\n", hr, resources[r].name);
5884 hr = IDirect3DCubeTexture8_UnlockRect(cube_texture, D3DCUBEMAP_FACE_NEGATIVE_X, 0);
5885 ok(SUCCEEDED(hr), "Failed to unlock texture, hr %#x, type %s.\n", hr, resources[r].name);
5886 hr = IDirect3DCubeTexture8_UnlockRect(cube_texture, D3DCUBEMAP_FACE_NEGATIVE_X, 0);
5887 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x, type %s.\n", hr, resources[r].name);
5889 hr = IDirect3DCubeTexture8_LockRect(cube_texture, D3DCUBEMAP_FACE_NEGATIVE_X, 0,
5890 &locked_rect, &valid[0], 0);
5891 ok(hr == D3D_OK, "Got unexpected hr %#x for rect %s, type %s.\n",
5892 hr, wine_dbgstr_rect(&valid[0]), resources[r].name);
5893 hr = IDirect3DCubeTexture8_LockRect(cube_texture, D3DCUBEMAP_FACE_NEGATIVE_X, 0,
5894 &locked_rect, &valid[0], 0);
5895 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for rect %s, type %s.\n",
5896 hr, wine_dbgstr_rect(&valid[0]), resources[r].name);
5897 hr = IDirect3DCubeTexture8_LockRect(cube_texture, D3DCUBEMAP_FACE_NEGATIVE_X, 0,
5898 &locked_rect, &valid[1], 0);
5899 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for rect %s, type %s.\n",
5900 hr, wine_dbgstr_rect(&valid[1]), resources[r].name);
5901 hr = IDirect3DCubeTexture8_UnlockRect(cube_texture, D3DCUBEMAP_FACE_NEGATIVE_X, 0);
5902 ok(SUCCEEDED(hr), "Failed to unlock texture, hr %#x, type %s.\n", hr, resources[r].name);
5904 IDirect3DTexture8_Release(cube_texture);
5906 hr = IDirect3DDevice8_CreateCubeTexture(device, 128, 1, D3DUSAGE_WRITEONLY, D3DFMT_A8R8G8B8,
5907 resources[r].pool, &cube_texture);
5908 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for type %s.\n",
5909 hr, resources[r].name);
5913 refcount = IDirect3DDevice8_Release(device);
5914 ok(!refcount, "Device has %u references left.\n", refcount);
5915 IDirect3D8_Release(d3d8);
5916 DestroyWindow(window);
5919 static void test_private_data(void)
5921 ULONG refcount, expected_refcount;
5922 IDirect3DTexture8 *texture;
5923 IDirect3DSurface8 *surface, *surface2;
5924 IDirect3DDevice8 *device;
5925 IDirect3D8 *d3d8;
5926 IUnknown *ptr;
5927 HWND window;
5928 HRESULT hr;
5929 DWORD size;
5930 DWORD data[4] = {1, 2, 3, 4};
5931 static const GUID d3d8_private_data_test_guid2 =
5933 0x2e5afac2,
5934 0x87b5,
5935 0x4c10,
5936 {0x9b,0x4b,0x89,0xd7,0xd1,0x12,0xe7,0x2b}
5939 window = create_window();
5940 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
5941 ok(!!d3d8, "Failed to create a D3D object.\n");
5942 if (!(device = create_device(d3d8, window, NULL)))
5944 skip("Failed to create a D3D device, skipping tests.\n");
5945 IDirect3D8_Release(d3d8);
5946 DestroyWindow(window);
5947 return;
5950 hr = IDirect3DDevice8_CreateImageSurface(device, 4, 4, D3DFMT_A8R8G8B8, &surface);
5951 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5953 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
5954 device, 0, D3DSPD_IUNKNOWN);
5955 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
5956 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
5957 device, 5, D3DSPD_IUNKNOWN);
5958 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
5959 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
5960 device, sizeof(IUnknown *) * 2, D3DSPD_IUNKNOWN);
5961 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
5963 /* A failing SetPrivateData call does not clear the old data with the same tag. */
5964 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid, device,
5965 sizeof(device), D3DSPD_IUNKNOWN);
5966 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
5967 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid, device,
5968 sizeof(device) * 2, D3DSPD_IUNKNOWN);
5969 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
5970 size = sizeof(ptr);
5971 hr = IDirect3DSurface8_GetPrivateData(surface, &d3d8_private_data_test_guid, &ptr, &size);
5972 ok(SUCCEEDED(hr), "Failed to get private data, hr %#x.\n", hr);
5973 IUnknown_Release(ptr);
5974 hr = IDirect3DSurface8_FreePrivateData(surface, &d3d8_private_data_test_guid);
5975 ok(SUCCEEDED(hr), "Failed to free private data, hr %#x.\n", hr);
5977 refcount = get_refcount((IUnknown *)device);
5978 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
5979 device, sizeof(IUnknown *), D3DSPD_IUNKNOWN);
5980 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
5981 expected_refcount = refcount + 1;
5982 refcount = get_refcount((IUnknown *)device);
5983 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5984 hr = IDirect3DSurface8_FreePrivateData(surface, &d3d8_private_data_test_guid);
5985 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
5986 expected_refcount = refcount - 1;
5987 refcount = get_refcount((IUnknown *)device);
5988 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5990 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
5991 device, sizeof(IUnknown *), D3DSPD_IUNKNOWN);
5992 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
5993 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
5994 surface, sizeof(IUnknown *), D3DSPD_IUNKNOWN);
5995 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
5996 refcount = get_refcount((IUnknown *)device);
5997 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5999 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
6000 device, sizeof(IUnknown *), D3DSPD_IUNKNOWN);
6001 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
6002 size = 2 * sizeof(ptr);
6003 hr = IDirect3DSurface8_GetPrivateData(surface, &d3d8_private_data_test_guid, &ptr, &size);
6004 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
6005 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
6006 expected_refcount = refcount + 2;
6007 refcount = get_refcount((IUnknown *)device);
6008 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6009 ok(ptr == (IUnknown *)device, "Got unexpected ptr %p, expected %p.\n", ptr, device);
6010 IUnknown_Release(ptr);
6011 expected_refcount--;
6013 ptr = (IUnknown *)0xdeadbeef;
6014 size = 1;
6015 hr = IDirect3DSurface8_GetPrivateData(surface, &d3d8_private_data_test_guid, NULL, &size);
6016 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
6017 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
6018 size = 2 * sizeof(ptr);
6019 hr = IDirect3DSurface8_GetPrivateData(surface, &d3d8_private_data_test_guid, NULL, &size);
6020 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
6021 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
6022 refcount = get_refcount((IUnknown *)device);
6023 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6024 size = 1;
6025 hr = IDirect3DSurface8_GetPrivateData(surface, &d3d8_private_data_test_guid, &ptr, &size);
6026 ok(hr == D3DERR_MOREDATA, "Got unexpected hr %#x.\n", hr);
6027 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
6028 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
6029 hr = IDirect3DSurface8_GetPrivateData(surface, &d3d8_private_data_test_guid2, NULL, NULL);
6030 ok(hr == D3DERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
6031 size = 0xdeadbabe;
6032 hr = IDirect3DSurface8_GetPrivateData(surface, &d3d8_private_data_test_guid2, &ptr, &size);
6033 ok(hr == D3DERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
6034 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
6035 ok(size == 0xdeadbabe, "Got unexpected size %u.\n", size);
6036 /* GetPrivateData with size = NULL causes an access violation on Windows if the
6037 * requested data exists. */
6039 /* Destroying the surface frees the held reference. */
6040 IDirect3DSurface8_Release(surface);
6041 expected_refcount = refcount - 2;
6042 refcount = get_refcount((IUnknown *)device);
6043 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6045 hr = IDirect3DDevice8_CreateTexture(device, 4, 4, 2, 0, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &texture);
6046 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6047 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 0, &surface);
6048 ok(SUCCEEDED(hr), "Failed to get texture level 0, hr %#x.\n", hr);
6049 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 1, &surface2);
6050 ok(SUCCEEDED(hr), "Failed to get texture level 1, hr %#x.\n", hr);
6052 hr = IDirect3DTexture8_SetPrivateData(texture, &d3d8_private_data_test_guid, data, sizeof(data), 0);
6053 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
6055 memset(data, 0, sizeof(data));
6056 size = sizeof(data);
6057 hr = IDirect3DSurface8_GetPrivateData(surface, &d3d8_private_data_test_guid, data, &size);
6058 ok(hr == D3DERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
6059 hr = IDirect3DTexture8_GetPrivateData(texture, &d3d8_private_data_test_guid, data, &size);
6060 ok(SUCCEEDED(hr), "Failed to get private data, hr %#x.\n", hr);
6061 ok(data[0] == 1 && data[1] == 2 && data[2] == 3 && data[3] == 4,
6062 "Got unexpected private data: %u, %u, %u, %u.\n", data[0], data[1], data[2], data[3]);
6064 hr = IDirect3DTexture8_FreePrivateData(texture, &d3d8_private_data_test_guid);
6065 ok(SUCCEEDED(hr), "Failed to free private data, hr %#x.\n", hr);
6067 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid, data, sizeof(data), 0);
6068 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
6069 hr = IDirect3DSurface8_GetPrivateData(surface2, &d3d8_private_data_test_guid, data, &size);
6070 ok(hr == D3DERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
6071 hr = IDirect3DSurface8_FreePrivateData(surface, &d3d8_private_data_test_guid);
6072 ok(SUCCEEDED(hr), "Failed to free private data, hr %#x.\n", hr);
6074 IDirect3DSurface8_Release(surface2);
6075 IDirect3DSurface8_Release(surface);
6076 IDirect3DTexture8_Release(texture);
6078 refcount = IDirect3DDevice8_Release(device);
6079 ok(!refcount, "Device has %u references left.\n", refcount);
6080 IDirect3D8_Release(d3d8);
6081 DestroyWindow(window);
6084 static void test_surface_dimensions(void)
6086 IDirect3DSurface8 *surface;
6087 IDirect3DDevice8 *device;
6088 IDirect3D8 *d3d8;
6089 ULONG refcount;
6090 HWND window;
6091 HRESULT hr;
6093 window = create_window();
6094 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
6095 ok(!!d3d8, "Failed to create a D3D object.\n");
6096 if (!(device = create_device(d3d8, window, NULL)))
6098 skip("Failed to create a D3D device, skipping tests.\n");
6099 IDirect3D8_Release(d3d8);
6100 DestroyWindow(window);
6101 return;
6104 hr = IDirect3DDevice8_CreateImageSurface(device, 0, 1, D3DFMT_A8R8G8B8, &surface);
6105 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
6106 hr = IDirect3DDevice8_CreateImageSurface(device, 1, 0, D3DFMT_A8R8G8B8, &surface);
6107 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
6109 refcount = IDirect3DDevice8_Release(device);
6110 ok(!refcount, "Device has %u references left.\n", refcount);
6111 IDirect3D8_Release(d3d8);
6112 DestroyWindow(window);
6115 static void test_surface_format_null(void)
6117 static const D3DFORMAT D3DFMT_NULL = MAKEFOURCC('N','U','L','L');
6118 IDirect3DTexture8 *texture;
6119 IDirect3DSurface8 *surface;
6120 IDirect3DSurface8 *rt, *ds;
6121 D3DLOCKED_RECT locked_rect;
6122 IDirect3DDevice8 *device;
6123 D3DSURFACE_DESC desc;
6124 IDirect3D8 *d3d;
6125 ULONG refcount;
6126 HWND window;
6127 HRESULT hr;
6129 d3d = Direct3DCreate8(D3D_SDK_VERSION);
6130 ok(!!d3d, "Failed to create a D3D object.\n");
6132 hr = IDirect3D8_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
6133 D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, D3DFMT_NULL);
6134 if (hr != D3D_OK)
6136 skip("No D3DFMT_NULL support, skipping test.\n");
6137 IDirect3D8_Release(d3d);
6138 return;
6141 window = create_window();
6142 if (!(device = create_device(d3d, window, NULL)))
6144 skip("Failed to create a D3D device, skipping tests.\n");
6145 IDirect3D8_Release(d3d);
6146 DestroyWindow(window);
6147 return;
6150 hr = IDirect3D8_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
6151 D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, D3DFMT_NULL);
6152 ok(hr == D3D_OK, "D3DFMT_NULL should be supported for render target textures, hr %#x.\n", hr);
6154 hr = IDirect3D8_CheckDepthStencilMatch(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
6155 D3DFMT_NULL, D3DFMT_D24S8);
6156 ok(SUCCEEDED(hr), "Depth stencil match failed for D3DFMT_NULL, hr %#x.\n", hr);
6158 hr = IDirect3DDevice8_CreateRenderTarget(device, 128, 128, D3DFMT_NULL,
6159 D3DMULTISAMPLE_NONE, TRUE, &surface);
6160 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
6162 hr = IDirect3DDevice8_GetRenderTarget(device, &rt);
6163 ok(SUCCEEDED(hr), "Failed to get original render target, hr %#x.\n", hr);
6165 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &ds);
6166 ok(SUCCEEDED(hr), "Failed to get original depth/stencil, hr %#x.\n", hr);
6168 hr = IDirect3DDevice8_SetRenderTarget(device, surface, NULL);
6169 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
6171 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00000000, 0.0f, 0);
6172 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
6174 hr = IDirect3DDevice8_SetRenderTarget(device, rt, ds);
6175 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
6177 IDirect3DSurface8_Release(rt);
6178 IDirect3DSurface8_Release(ds);
6180 hr = IDirect3DSurface8_GetDesc(surface, &desc);
6181 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
6182 ok(desc.Width == 128, "Expected width 128, got %u.\n", desc.Width);
6183 ok(desc.Height == 128, "Expected height 128, got %u.\n", desc.Height);
6185 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, NULL, 0);
6186 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
6187 ok(locked_rect.Pitch, "Expected non-zero pitch, got %u.\n", locked_rect.Pitch);
6188 ok(!!locked_rect.pBits, "Expected non-NULL pBits, got %p.\n", locked_rect.pBits);
6190 hr = IDirect3DSurface8_UnlockRect(surface);
6191 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
6193 IDirect3DSurface8_Release(surface);
6195 hr = IDirect3DDevice8_CreateTexture(device, 128, 128, 0, D3DUSAGE_RENDERTARGET,
6196 D3DFMT_NULL, D3DPOOL_DEFAULT, &texture);
6197 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6198 IDirect3DTexture8_Release(texture);
6200 refcount = IDirect3DDevice8_Release(device);
6201 ok(!refcount, "Device has %u references left.\n", refcount);
6202 IDirect3D8_Release(d3d);
6203 DestroyWindow(window);
6206 static void test_surface_double_unlock(void)
6208 static const D3DPOOL pools[] =
6210 D3DPOOL_DEFAULT,
6211 D3DPOOL_SYSTEMMEM,
6213 IDirect3DSurface8 *surface;
6214 IDirect3DDevice8 *device;
6215 D3DLOCKED_RECT lr;
6216 IDirect3D8 *d3d;
6217 unsigned int i;
6218 ULONG refcount;
6219 HWND window;
6220 HRESULT hr;
6222 window = create_window();
6223 d3d = Direct3DCreate8(D3D_SDK_VERSION);
6224 ok(!!d3d, "Failed to create a D3D object.\n");
6225 if (!(device = create_device(d3d, window, NULL)))
6227 skip("Failed to create a D3D device, skipping tests.\n");
6228 IDirect3D8_Release(d3d);
6229 DestroyWindow(window);
6230 return;
6233 for (i = 0; i < ARRAY_SIZE(pools); ++i)
6235 switch (pools[i])
6237 case D3DPOOL_DEFAULT:
6238 hr = IDirect3D8_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
6239 D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, D3DFMT_X8R8G8B8);
6240 if (FAILED(hr))
6242 skip("D3DFMT_X8R8G8B8 render targets not supported, skipping double unlock DEFAULT pool test.\n");
6243 continue;
6246 hr = IDirect3DDevice8_CreateRenderTarget(device, 64, 64, D3DFMT_X8R8G8B8,
6247 D3DMULTISAMPLE_NONE, TRUE, &surface);
6248 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
6249 break;
6251 case D3DPOOL_SYSTEMMEM:
6252 hr = IDirect3DDevice8_CreateImageSurface(device, 64, 64, D3DFMT_X8R8G8B8, &surface);
6253 ok(SUCCEEDED(hr), "Failed to create image surface, hr %#x.\n", hr);
6254 break;
6256 default:
6257 break;
6260 hr = IDirect3DSurface8_UnlockRect(surface);
6261 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x, for surface in pool %#x.\n", hr, pools[i]);
6262 hr = IDirect3DSurface8_LockRect(surface, &lr, NULL, 0);
6263 ok(SUCCEEDED(hr), "Failed to lock surface in pool %#x, hr %#x.\n", pools[i], hr);
6264 hr = IDirect3DSurface8_UnlockRect(surface);
6265 ok(SUCCEEDED(hr), "Failed to unlock surface in pool %#x, hr %#x.\n", pools[i], hr);
6266 hr = IDirect3DSurface8_UnlockRect(surface);
6267 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x, for surface in pool %#x.\n", hr, pools[i]);
6269 IDirect3DSurface8_Release(surface);
6272 refcount = IDirect3DDevice8_Release(device);
6273 ok(!refcount, "Device has %u references left.\n", refcount);
6274 IDirect3D8_Release(d3d);
6275 DestroyWindow(window);
6278 static void test_surface_blocks(void)
6280 static const struct
6282 D3DFORMAT fmt;
6283 const char *name;
6284 unsigned int block_width;
6285 unsigned int block_height;
6286 BOOL broken;
6287 BOOL create_size_checked, core_fmt;
6289 formats[] =
6291 {D3DFMT_DXT1, "D3DFMT_DXT1", 4, 4, FALSE, TRUE, TRUE },
6292 {D3DFMT_DXT2, "D3DFMT_DXT2", 4, 4, FALSE, TRUE, TRUE },
6293 {D3DFMT_DXT3, "D3DFMT_DXT3", 4, 4, FALSE, TRUE, TRUE },
6294 {D3DFMT_DXT4, "D3DFMT_DXT4", 4, 4, FALSE, TRUE, TRUE },
6295 {D3DFMT_DXT5, "D3DFMT_DXT5", 4, 4, FALSE, TRUE, TRUE },
6296 /* ATI1N and ATI2N have 2x2 blocks on all AMD cards and Geforce 7 cards,
6297 * which doesn't match the format spec. On newer Nvidia cards
6298 * they have the correct 4x4 block size */
6299 {MAKEFOURCC('A','T','I','1'), "ATI1N", 4, 4, TRUE, FALSE, FALSE},
6300 {MAKEFOURCC('A','T','I','2'), "ATI2N", 4, 4, TRUE, FALSE, FALSE},
6301 /* Windows drivers generally enforce block-aligned locks for
6302 * YUY2 and UYVY. The notable exception is the AMD r500 driver
6303 * in d3d8. The same driver checks the sizes in d3d9. */
6304 {D3DFMT_YUY2, "D3DFMT_YUY2", 2, 1, TRUE, FALSE, TRUE },
6305 {D3DFMT_UYVY, "D3DFMT_UYVY", 2, 1, TRUE, FALSE, TRUE },
6307 static const struct
6309 D3DPOOL pool;
6310 const char *name;
6311 /* Don't check the return value, Nvidia returns D3DERR_INVALIDCALL for some formats
6312 * and E_INVALIDARG/DDERR_INVALIDPARAMS for others. */
6313 BOOL success;
6315 pools[] =
6317 {D3DPOOL_DEFAULT, "D3DPOOL_DEFAULT", FALSE},
6318 {D3DPOOL_SCRATCH, "D3DPOOL_SCRATCH", TRUE},
6319 {D3DPOOL_SYSTEMMEM, "D3DPOOL_SYSTEMMEM",TRUE},
6320 {D3DPOOL_MANAGED, "D3DPOOL_MANAGED", TRUE},
6322 static struct
6324 D3DRESOURCETYPE rtype;
6325 const char *type_name;
6326 D3DPOOL pool;
6327 const char *pool_name;
6328 BOOL need_driver_support, need_runtime_support;
6330 create_tests[] =
6332 /* D3d8 only supports sysmem surfaces, which are created via CreateImageSurface. Other tests confirm
6333 * that they are D3DPOOL_SYSTEMMEM surfaces, but their creation restriction behaves like the scratch
6334 * pool in d3d9. */
6335 {D3DRTYPE_SURFACE, "D3DRTYPE_SURFACE", D3DPOOL_SYSTEMMEM, "D3DPOOL_SYSTEMMEM", FALSE, TRUE },
6337 {D3DRTYPE_TEXTURE, "D3DRTYPE_TEXTURE", D3DPOOL_DEFAULT, "D3DPOOL_DEFAULT", TRUE, FALSE },
6338 {D3DRTYPE_TEXTURE, "D3DRTYPE_TEXTURE", D3DPOOL_SYSTEMMEM, "D3DPOOL_SYSTEMMEM", TRUE, FALSE },
6339 {D3DRTYPE_TEXTURE, "D3DRTYPE_TEXTURE", D3DPOOL_MANAGED, "D3DPOOL_MANAGED", TRUE, FALSE },
6340 {D3DRTYPE_TEXTURE, "D3DRTYPE_TEXTURE", D3DPOOL_SCRATCH, "D3DPOOL_SCRATCH", FALSE, TRUE },
6342 {D3DRTYPE_CUBETEXTURE, "D3DRTYPE_CUBETEXTURE", D3DPOOL_DEFAULT, "D3DPOOL_DEFAULT", TRUE, FALSE },
6343 {D3DRTYPE_CUBETEXTURE, "D3DRTYPE_CUBETEXTURE", D3DPOOL_SYSTEMMEM, "D3DPOOL_SYSTEMMEM", TRUE, FALSE },
6344 {D3DRTYPE_CUBETEXTURE, "D3DRTYPE_CUBETEXTURE", D3DPOOL_MANAGED, "D3DPOOL_MANAGED", TRUE, FALSE },
6345 {D3DRTYPE_CUBETEXTURE, "D3DRTYPE_CUBETEXTURE", D3DPOOL_SCRATCH, "D3DPOOL_SCRATCH", FALSE, TRUE },
6347 IDirect3DTexture8 *texture;
6348 IDirect3DCubeTexture8 *cube_texture;
6349 IDirect3DSurface8 *surface;
6350 D3DLOCKED_RECT locked_rect;
6351 IDirect3DDevice8 *device;
6352 unsigned int i, j, k, w, h;
6353 IDirect3D8 *d3d;
6354 ULONG refcount;
6355 HWND window;
6356 HRESULT hr;
6357 RECT rect;
6358 BOOL tex_pow2, cube_pow2;
6359 D3DCAPS8 caps;
6360 static const RECT invalid[] =
6362 {60, 60, 60, 68}, /* 0 height */
6363 {60, 60, 68, 60}, /* 0 width */
6364 {68, 60, 60, 68}, /* left > right */
6365 {60, 68, 68, 60}, /* top > bottom */
6366 {-8, 60, 0, 68}, /* left < surface */
6367 {60, -8, 68, 0}, /* top < surface */
6368 {-16, 60, -8, 68}, /* right < surface */
6369 {60, -16, 68, -8}, /* bottom < surface */
6370 {60, 60, 136, 68}, /* right > surface */
6371 {60, 60, 68, 136}, /* bottom > surface */
6372 {136, 60, 144, 68}, /* left > surface */
6373 {60, 136, 68, 144}, /* top > surface */
6376 window = create_window();
6377 d3d = Direct3DCreate8(D3D_SDK_VERSION);
6378 ok(!!d3d, "Failed to create a D3D object.\n");
6379 if (!(device = create_device(d3d, window, NULL)))
6381 skip("Failed to create a D3D device, skipping tests.\n");
6382 IDirect3D8_Release(d3d);
6383 DestroyWindow(window);
6384 return;
6387 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
6388 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
6389 tex_pow2 = caps.TextureCaps & D3DPTEXTURECAPS_POW2;
6390 if (tex_pow2)
6391 tex_pow2 = !(caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL);
6392 cube_pow2 = !!(caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP_POW2);
6394 for (i = 0; i < ARRAY_SIZE(formats); ++i)
6396 BOOL tex_support, cube_support, surface_support, format_known;
6398 hr = IDirect3D8_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
6399 0, D3DRTYPE_TEXTURE, formats[i].fmt);
6400 tex_support = SUCCEEDED(hr);
6401 hr = IDirect3D8_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
6402 0, D3DRTYPE_CUBETEXTURE, formats[i].fmt);
6403 cube_support = SUCCEEDED(hr);
6404 hr = IDirect3D8_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
6405 0, D3DRTYPE_SURFACE, formats[i].fmt);
6406 surface_support = SUCCEEDED(hr);
6408 /* Scratch pool in general allows texture creation even if the driver does
6409 * not support the format. If the format is an extension format that is not
6410 * known to the runtime, like ATI2N, some driver support is required for
6411 * this to work.
6413 * It is also possible that Windows Vista and Windows 7 d3d8 runtimes know
6414 * about ATI2N. I cannot check this because all my Vista+ machines support
6415 * ATI2N in hardware, but none of my WinXP machines do. */
6416 format_known = tex_support || cube_support || surface_support;
6418 for (w = 1; w <= 8; w++)
6420 for (h = 1; h <= 8; h++)
6422 BOOL block_aligned = TRUE;
6423 BOOL size_is_pow2;
6425 if (w & (formats[i].block_width - 1) || h & (formats[i].block_height - 1))
6426 block_aligned = FALSE;
6428 size_is_pow2 = !(w & (w - 1) || h & (h - 1));
6430 for (j = 0; j < ARRAY_SIZE(create_tests); j++)
6432 BOOL support, pow2;
6433 HRESULT expect_hr;
6434 BOOL may_succeed = FALSE;
6435 IUnknown **check_null;
6437 if (!formats[i].core_fmt)
6439 /* AMD warns against creating ATI2N textures smaller than
6440 * the block size because the runtime cannot calculate the
6441 * correct texture size. Generalize this for all extension
6442 * formats. */
6443 if (w < formats[i].block_width || h < formats[i].block_height)
6444 continue;
6447 texture = (IDirect3DTexture8 *)0xdeadbeef;
6448 cube_texture = (IDirect3DCubeTexture8 *)0xdeadbeef;
6449 surface = (IDirect3DSurface8 *)0xdeadbeef;
6451 switch (create_tests[j].rtype)
6453 case D3DRTYPE_TEXTURE:
6454 check_null = (IUnknown **)&texture;
6455 hr = IDirect3DDevice8_CreateTexture(device, w, h, 1, 0,
6456 formats[i].fmt, create_tests[j].pool, &texture);
6457 support = tex_support;
6458 pow2 = tex_pow2;
6459 break;
6461 case D3DRTYPE_CUBETEXTURE:
6462 if (w != h)
6463 continue;
6464 check_null = (IUnknown **)&cube_texture;
6465 hr = IDirect3DDevice8_CreateCubeTexture(device, w, 1, 0,
6466 formats[i].fmt, create_tests[j].pool, &cube_texture);
6467 support = cube_support;
6468 pow2 = cube_pow2;
6469 break;
6471 case D3DRTYPE_SURFACE:
6472 check_null = (IUnknown **)&surface;
6473 hr = IDirect3DDevice8_CreateImageSurface(device, w, h,
6474 formats[i].fmt, &surface);
6475 support = surface_support;
6476 pow2 = FALSE;
6477 break;
6479 default:
6480 pow2 = FALSE;
6481 support = FALSE;
6482 check_null = NULL;
6483 break;
6486 if (create_tests[j].need_driver_support && !support)
6487 expect_hr = D3DERR_INVALIDCALL;
6488 else if (create_tests[j].need_runtime_support && !formats[i].core_fmt && !format_known)
6489 expect_hr = D3DERR_INVALIDCALL;
6490 else if (formats[i].create_size_checked && !block_aligned)
6491 expect_hr = D3DERR_INVALIDCALL;
6492 else if (pow2 && !size_is_pow2 && create_tests[j].need_driver_support)
6493 expect_hr = D3DERR_INVALIDCALL;
6494 else
6495 expect_hr = D3D_OK;
6497 if (!formats[i].core_fmt && !format_known && FAILED(expect_hr))
6498 may_succeed = TRUE;
6500 /* Wine knows about ATI2N and happily creates a scratch resource even if GL
6501 * does not support it. Accept scratch creation of extension formats on
6502 * Windows as well if it occurs. We don't really care if e.g. a Windows 7
6503 * on an r200 GPU creates scratch ATI2N texture even though the card doesn't
6504 * support it. */
6505 ok(hr == expect_hr || ((SUCCEEDED(hr) && may_succeed)),
6506 "Got unexpected hr %#x for format %s, pool %s, type %s, size %ux%u.\n",
6507 hr, formats[i].name, create_tests[j].pool_name, create_tests[j].type_name, w, h);
6509 if (FAILED(hr))
6510 ok(*check_null == NULL, "Got object ptr %p, expected NULL.\n", *check_null);
6511 else
6512 IUnknown_Release(*check_null);
6517 hr = IDirect3D8_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
6518 D3DUSAGE_DYNAMIC, D3DRTYPE_TEXTURE, formats[i].fmt);
6519 if (FAILED(hr))
6521 skip("Format %s not supported, skipping lockrect offset tests.\n", formats[i].name);
6522 continue;
6525 for (j = 0; j < ARRAY_SIZE(pools); ++j)
6527 hr = IDirect3DDevice8_CreateTexture(device, 128, 128, 1,
6528 pools[j].pool == D3DPOOL_DEFAULT ? D3DUSAGE_DYNAMIC : 0,
6529 formats[i].fmt, pools[j].pool, &texture);
6530 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6531 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 0, &surface);
6532 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
6533 IDirect3DTexture8_Release(texture);
6535 if (formats[i].block_width > 1)
6537 SetRect(&rect, formats[i].block_width >> 1, 0, formats[i].block_width, formats[i].block_height);
6538 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, &rect, 0);
6539 ok(FAILED(hr) == !pools[j].success || broken(formats[i].broken),
6540 "Partial block lock %s, expected %s, format %s, pool %s.\n",
6541 SUCCEEDED(hr) ? "succeeded" : "failed",
6542 pools[j].success ? "success" : "failure", formats[i].name, pools[j].name);
6543 if (SUCCEEDED(hr))
6545 hr = IDirect3DSurface8_UnlockRect(surface);
6546 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
6549 SetRect(&rect, 0, 0, formats[i].block_width >> 1, formats[i].block_height);
6550 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, &rect, 0);
6551 ok(FAILED(hr) == !pools[j].success || broken(formats[i].broken),
6552 "Partial block lock %s, expected %s, format %s, pool %s.\n",
6553 SUCCEEDED(hr) ? "succeeded" : "failed",
6554 pools[j].success ? "success" : "failure", formats[i].name, pools[j].name);
6555 if (SUCCEEDED(hr))
6557 hr = IDirect3DSurface8_UnlockRect(surface);
6558 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
6562 if (formats[i].block_height > 1)
6564 SetRect(&rect, 0, formats[i].block_height >> 1, formats[i].block_width, formats[i].block_height);
6565 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, &rect, 0);
6566 ok(FAILED(hr) == !pools[j].success || broken(formats[i].broken),
6567 "Partial block lock %s, expected %s, format %s, pool %s.\n",
6568 SUCCEEDED(hr) ? "succeeded" : "failed",
6569 pools[j].success ? "success" : "failure", formats[i].name, pools[j].name);
6570 if (SUCCEEDED(hr))
6572 hr = IDirect3DSurface8_UnlockRect(surface);
6573 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
6576 SetRect(&rect, 0, 0, formats[i].block_width, formats[i].block_height >> 1);
6577 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, &rect, 0);
6578 ok(FAILED(hr) == !pools[j].success || broken(formats[i].broken),
6579 "Partial block lock %s, expected %s, format %s, pool %s.\n",
6580 SUCCEEDED(hr) ? "succeeded" : "failed",
6581 pools[j].success ? "success" : "failure", formats[i].name, pools[j].name);
6582 if (SUCCEEDED(hr))
6584 hr = IDirect3DSurface8_UnlockRect(surface);
6585 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
6589 for (k = 0; k < ARRAY_SIZE(invalid); ++k)
6591 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, &invalid[k], 0);
6592 ok(FAILED(hr) == !pools[j].success, "Invalid lock %s(%#x), expected %s, format %s, pool %s, case %u.\n",
6593 SUCCEEDED(hr) ? "succeeded" : "failed", hr, pools[j].success ? "success" : "failure",
6594 formats[i].name, pools[j].name, k);
6595 if (SUCCEEDED(hr))
6597 hr = IDirect3DSurface8_UnlockRect(surface);
6598 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
6602 SetRect(&rect, 0, 0, formats[i].block_width, formats[i].block_height);
6603 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, &rect, 0);
6604 ok(hr == D3D_OK, "Got unexpected hr %#x for format %s, pool %s.\n", hr, formats[i].name, pools[j].name);
6605 hr = IDirect3DSurface8_UnlockRect(surface);
6606 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
6608 IDirect3DSurface8_Release(surface);
6611 if (formats[i].block_width == 1 && formats[i].block_height == 1)
6612 continue;
6613 if (!formats[i].core_fmt)
6614 continue;
6616 hr = IDirect3DDevice8_CreateTexture(device, formats[i].block_width, formats[i].block_height, 2,
6617 D3DUSAGE_DYNAMIC, formats[i].fmt, D3DPOOL_DEFAULT, &texture);
6618 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x, format %s.\n", hr, formats[i].name);
6620 hr = IDirect3DTexture8_LockRect(texture, 1, &locked_rect, NULL, 0);
6621 ok(SUCCEEDED(hr), "Failed lock texture, hr %#x.\n", hr);
6622 hr = IDirect3DTexture8_UnlockRect(texture, 1);
6623 ok(SUCCEEDED(hr), "Failed lock texture, hr %#x.\n", hr);
6625 rect.left = 0;
6626 rect.top = 0;
6627 rect.right = formats[i].block_width == 1 ? 1 : formats[i].block_width >> 1;
6628 rect.bottom = formats[i].block_height == 1 ? 1 : formats[i].block_height >> 1;
6629 hr = IDirect3DTexture8_LockRect(texture, 1, &locked_rect, &rect, 0);
6630 ok(SUCCEEDED(hr), "Failed lock texture, hr %#x.\n", hr);
6631 hr = IDirect3DTexture8_UnlockRect(texture, 1);
6632 ok(SUCCEEDED(hr), "Failed lock texture, hr %#x.\n", hr);
6634 rect.right = formats[i].block_width;
6635 rect.bottom = formats[i].block_height;
6636 hr = IDirect3DTexture8_LockRect(texture, 1, &locked_rect, &rect, 0);
6637 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
6638 if (SUCCEEDED(hr))
6639 IDirect3DTexture8_UnlockRect(texture, 1);
6641 IDirect3DTexture8_Release(texture);
6644 refcount = IDirect3DDevice8_Release(device);
6645 ok(!refcount, "Device has %u references left.\n", refcount);
6646 IDirect3D8_Release(d3d);
6647 DestroyWindow(window);
6650 static void test_set_palette(void)
6652 IDirect3DDevice8 *device;
6653 IDirect3D8 *d3d8;
6654 UINT refcount;
6655 HWND window;
6656 HRESULT hr;
6657 PALETTEENTRY pal[256];
6658 unsigned int i;
6659 D3DCAPS8 caps;
6661 window = create_window();
6662 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
6663 ok(!!d3d8, "Failed to create a D3D object.\n");
6664 if (!(device = create_device(d3d8, window, NULL)))
6666 skip("Failed to create a D3D device, skipping tests.\n");
6667 IDirect3D8_Release(d3d8);
6668 DestroyWindow(window);
6669 return;
6672 for (i = 0; i < ARRAY_SIZE(pal); i++)
6674 pal[i].peRed = i;
6675 pal[i].peGreen = i;
6676 pal[i].peBlue = i;
6677 pal[i].peFlags = 0xff;
6679 hr = IDirect3DDevice8_SetPaletteEntries(device, 0, pal);
6680 ok(SUCCEEDED(hr), "Failed to set palette entries, hr %#x.\n", hr);
6682 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
6683 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
6684 for (i = 0; i < ARRAY_SIZE(pal); i++)
6686 pal[i].peRed = i;
6687 pal[i].peGreen = i;
6688 pal[i].peBlue = i;
6689 pal[i].peFlags = i;
6691 if (caps.TextureCaps & D3DPTEXTURECAPS_ALPHAPALETTE)
6693 hr = IDirect3DDevice8_SetPaletteEntries(device, 0, pal);
6694 ok(SUCCEEDED(hr), "Failed to set palette entries, hr %#x.\n", hr);
6696 else
6698 hr = IDirect3DDevice8_SetPaletteEntries(device, 0, pal);
6699 ok(hr == D3DERR_INVALIDCALL, "SetPaletteEntries returned %#x, expected D3DERR_INVALIDCALL.\n", hr);
6702 refcount = IDirect3DDevice8_Release(device);
6703 ok(!refcount, "Device has %u references left.\n", refcount);
6704 IDirect3D8_Release(d3d8);
6705 DestroyWindow(window);
6708 static void test_pinned_buffers(void)
6710 static const struct
6712 DWORD device_flags;
6713 DWORD usage;
6714 D3DPOOL pool;
6716 tests[] =
6718 {CREATE_DEVICE_SWVP_ONLY, D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DPOOL_DEFAULT},
6719 {0, 0, D3DPOOL_MANAGED},
6720 {0, 0, D3DPOOL_SYSTEMMEM},
6722 static const unsigned int vertex_count = 1024;
6723 struct device_desc device_desc;
6724 IDirect3DVertexBuffer8 *buffer;
6725 D3DVERTEXBUFFER_DESC desc;
6726 IDirect3DDevice8 *device;
6727 struct vec3 *ptr, *ptr2;
6728 unsigned int i, test;
6729 IDirect3D8 *d3d;
6730 UINT refcount;
6731 HWND window;
6732 HRESULT hr;
6734 window = create_window();
6735 d3d = Direct3DCreate8(D3D_SDK_VERSION);
6736 ok(!!d3d, "Failed to create a D3D object.\n");
6738 for (test = 0; test < ARRAY_SIZE(tests); ++test)
6740 device_desc.adapter_ordinal = D3DADAPTER_DEFAULT;
6741 device_desc.device_window = window;
6742 device_desc.width = 640;
6743 device_desc.height = 480;
6744 device_desc.flags = tests[test].device_flags;
6745 if (!(device = create_device(d3d, window, &device_desc)))
6747 skip("Test %u: failed to create a D3D device.\n", test);
6748 continue;
6751 hr = IDirect3DDevice8_CreateVertexBuffer(device, vertex_count * sizeof(*ptr),
6752 tests[test].usage, 0, tests[test].pool, &buffer);
6753 ok(hr == D3D_OK, "Test %u: got unexpected hr %#x.\n", test, hr);
6754 hr = IDirect3DVertexBuffer8_GetDesc(buffer, &desc);
6755 ok(hr == D3D_OK, "Test %u: got unexpected hr %#x.\n", test, hr);
6756 ok(desc.Pool == tests[test].pool, "Test %u: got unexpected pool %#x.\n", test, desc.Pool);
6757 ok(desc.Usage == tests[test].usage, "Test %u: got unexpected usage %#x.\n", test, desc.Usage);
6759 hr = IDirect3DVertexBuffer8_Lock(buffer, 0, vertex_count * sizeof(*ptr), (BYTE **)&ptr, D3DLOCK_DISCARD);
6760 ok(hr == D3D_OK, "Test %u: got unexpected hr %#x.\n", test, hr);
6761 for (i = 0; i < vertex_count; ++i)
6763 ptr[i].x = i * 1.0f;
6764 ptr[i].y = i * 2.0f;
6765 ptr[i].z = i * 3.0f;
6767 hr = IDirect3DVertexBuffer8_Unlock(buffer);
6768 ok(hr == D3D_OK, "Test %u: got unexpected hr %#x.\n", test, hr);
6770 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ);
6771 ok(hr == D3D_OK, "Test %u: got unexpected hr %#x.\n", test, hr);
6772 hr = IDirect3DDevice8_SetStreamSource(device, 0, buffer, sizeof(*ptr));
6773 ok(hr == D3D_OK, "Test %u: got unexpected hr %#x.\n", test, hr);
6774 hr = IDirect3DDevice8_BeginScene(device);
6775 ok(hr == D3D_OK, "Test %u: got unexpected hr %#x.\n", test, hr);
6776 hr = IDirect3DDevice8_DrawPrimitive(device, D3DPT_TRIANGLELIST, 0, 2);
6777 ok(hr == D3D_OK, "Test %u: got unexpected hr %#x.\n", test, hr);
6778 hr = IDirect3DDevice8_EndScene(device);
6779 ok(hr == D3D_OK, "Test %u: got unexpected hr %#x.\n", test, hr);
6781 hr = IDirect3DVertexBuffer8_Lock(buffer, 0, vertex_count * sizeof(*ptr2), (BYTE **)&ptr2, D3DLOCK_DISCARD);
6782 ok(hr == D3D_OK, "Test %u: got unexpected hr %#x.\n", test, hr);
6783 ok(ptr2 == ptr, "Test %u: got unexpected ptr2 %p, expected %p.\n", test, ptr2, ptr);
6784 for (i = 0; i < vertex_count; ++i)
6786 if (ptr2[i].x != i * 1.0f || ptr2[i].y != i * 2.0f || ptr2[i].z != i * 3.0f)
6788 ok(FALSE, "Test %u: got unexpected vertex %u {%.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e}.\n",
6789 test, i, ptr2[i].x, ptr2[i].y, ptr2[i].z, i * 1.0f, i * 2.0f, i * 3.0f);
6790 break;
6793 hr = IDirect3DVertexBuffer8_Unlock(buffer);
6794 ok(hr == D3D_OK, "Test %u: got unexpected hr %#x.\n", test, hr);
6796 IDirect3DVertexBuffer8_Release(buffer);
6797 refcount = IDirect3DDevice8_Release(device);
6798 ok(!refcount, "Test %u: device has %u references left.\n", test, refcount);
6800 IDirect3D8_Release(d3d);
6801 DestroyWindow(window);
6804 static void test_npot_textures(void)
6806 IDirect3DDevice8 *device = NULL;
6807 IDirect3D8 *d3d8;
6808 ULONG refcount;
6809 HWND window = NULL;
6810 HRESULT hr;
6811 D3DCAPS8 caps;
6812 IDirect3DTexture8 *texture;
6813 IDirect3DCubeTexture8 *cube_texture;
6814 IDirect3DVolumeTexture8 *volume_texture;
6815 struct
6817 D3DPOOL pool;
6818 const char *pool_name;
6819 HRESULT hr;
6821 pools[] =
6823 { D3DPOOL_DEFAULT, "D3DPOOL_DEFAULT", D3DERR_INVALIDCALL },
6824 { D3DPOOL_MANAGED, "D3DPOOL_MANAGED", D3DERR_INVALIDCALL },
6825 { D3DPOOL_SYSTEMMEM, "D3DPOOL_SYSTEMMEM", D3DERR_INVALIDCALL },
6826 { D3DPOOL_SCRATCH, "D3DPOOL_SCRATCH", D3D_OK },
6828 unsigned int i, levels;
6829 BOOL tex_pow2, cube_pow2, vol_pow2;
6831 window = create_window();
6832 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
6833 ok(!!d3d8, "Failed to create a D3D object.\n");
6834 if (!(device = create_device(d3d8, window, NULL)))
6836 skip("Failed to create a D3D device, skipping tests.\n");
6837 goto done;
6840 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
6841 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
6842 tex_pow2 = !!(caps.TextureCaps & D3DPTEXTURECAPS_POW2);
6843 cube_pow2 = !!(caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP_POW2);
6844 vol_pow2 = !!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP_POW2);
6845 ok(cube_pow2 == tex_pow2, "Cube texture and 2d texture pow2 restrictions mismatch.\n");
6846 ok(vol_pow2 == tex_pow2, "Volume texture and 2d texture pow2 restrictions mismatch.\n");
6848 for (i = 0; i < ARRAY_SIZE(pools); i++)
6850 for (levels = 0; levels <= 2; levels++)
6852 HRESULT expected;
6854 hr = IDirect3DDevice8_CreateTexture(device, 10, 10, levels, 0, D3DFMT_X8R8G8B8,
6855 pools[i].pool, &texture);
6856 if (!tex_pow2)
6858 expected = D3D_OK;
6860 else if (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL)
6862 if (levels == 1)
6863 expected = D3D_OK;
6864 else
6865 expected = pools[i].hr;
6867 else
6869 expected = pools[i].hr;
6871 ok(hr == expected, "CreateTexture(w=h=10, %s, levels=%u) returned hr %#x, expected %#x.\n",
6872 pools[i].pool_name, levels, hr, expected);
6874 if (SUCCEEDED(hr))
6875 IDirect3DTexture8_Release(texture);
6878 hr = IDirect3DDevice8_CreateCubeTexture(device, 3, 1, 0, D3DFMT_X8R8G8B8,
6879 pools[i].pool, &cube_texture);
6880 if (tex_pow2)
6882 ok(hr == pools[i].hr, "CreateCubeTexture(EdgeLength=3, %s) returned hr %#x, expected %#x.\n",
6883 pools[i].pool_name, hr, pools[i].hr);
6885 else
6887 ok(SUCCEEDED(hr), "CreateCubeTexture(EdgeLength=3, %s) returned hr %#x, expected %#x.\n",
6888 pools[i].pool_name, hr, D3D_OK);
6891 if (SUCCEEDED(hr))
6892 IDirect3DCubeTexture8_Release(cube_texture);
6894 hr = IDirect3DDevice8_CreateVolumeTexture(device, 2, 2, 3, 1, 0, D3DFMT_X8R8G8B8,
6895 pools[i].pool, &volume_texture);
6896 if (tex_pow2)
6898 ok(hr == pools[i].hr, "CreateVolumeTextur(Depth=3, %s) returned hr %#x, expected %#x.\n",
6899 pools[i].pool_name, hr, pools[i].hr);
6901 else
6903 ok(SUCCEEDED(hr), "CreateVolumeTextur(Depth=3, %s) returned hr %#x, expected %#x.\n",
6904 pools[i].pool_name, hr, D3D_OK);
6907 if (SUCCEEDED(hr))
6908 IDirect3DVolumeTexture8_Release(volume_texture);
6911 done:
6912 if (device)
6914 refcount = IDirect3DDevice8_Release(device);
6915 ok(!refcount, "Device has %u references left.\n", refcount);
6917 IDirect3D8_Release(d3d8);
6918 DestroyWindow(window);
6922 static void test_volume_locking(void)
6924 IDirect3DDevice8 *device;
6925 IDirect3D8 *d3d8;
6926 HWND window;
6927 HRESULT hr;
6928 IDirect3DVolumeTexture8 *texture;
6929 unsigned int i;
6930 D3DLOCKED_BOX locked_box;
6931 ULONG refcount;
6932 D3DCAPS8 caps;
6933 static const struct
6935 D3DPOOL pool;
6936 DWORD usage;
6937 HRESULT create_hr, lock_hr;
6939 tests[] =
6941 { D3DPOOL_DEFAULT, 0, D3D_OK, D3DERR_INVALIDCALL },
6942 { D3DPOOL_DEFAULT, D3DUSAGE_DYNAMIC, D3D_OK, D3D_OK },
6943 { D3DPOOL_SYSTEMMEM, 0, D3D_OK, D3D_OK },
6944 { D3DPOOL_SYSTEMMEM, D3DUSAGE_DYNAMIC, D3D_OK, D3D_OK },
6945 { D3DPOOL_MANAGED, 0, D3D_OK, D3D_OK },
6946 { D3DPOOL_MANAGED, D3DUSAGE_DYNAMIC, D3DERR_INVALIDCALL, D3D_OK },
6947 { D3DPOOL_SCRATCH, 0, D3D_OK, D3D_OK },
6948 { D3DPOOL_SCRATCH, D3DUSAGE_DYNAMIC, D3DERR_INVALIDCALL, D3D_OK },
6951 window = create_window();
6952 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
6953 ok(!!d3d8, "Failed to create a D3D object.\n");
6954 if (!(device = create_device(d3d8, window, NULL)))
6956 skip("Failed to create a D3D device, skipping tests.\n");
6957 IDirect3D8_Release(d3d8);
6958 DestroyWindow(window);
6959 return;
6962 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
6963 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
6964 if (!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP))
6966 skip("Volume textures not supported, skipping test.\n");
6967 goto out;
6970 for (i = 0; i < ARRAY_SIZE(tests); i++)
6972 hr = IDirect3DDevice8_CreateVolumeTexture(device, 4, 4, 4, 1, tests[i].usage,
6973 D3DFMT_A8R8G8B8, tests[i].pool, &texture);
6974 ok(hr == tests[i].create_hr, "Creating volume texture pool=%u, usage=%#x returned %#x, expected %#x.\n",
6975 tests[i].pool, tests[i].usage, hr, tests[i].create_hr);
6976 if (FAILED(hr))
6977 continue;
6979 locked_box.pBits = (void *)0xdeadbeef;
6980 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, NULL, 0);
6981 ok(hr == tests[i].lock_hr, "Lock returned %#x, expected %#x.\n", hr, tests[i].lock_hr);
6982 if (SUCCEEDED(hr))
6984 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6985 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6987 else
6989 ok (locked_box.pBits == NULL, "Failed lock set pBits = %p, expected NULL.\n", locked_box.pBits);
6991 IDirect3DVolumeTexture8_Release(texture);
6994 out:
6995 refcount = IDirect3DDevice8_Release(device);
6996 ok(!refcount, "Device has %u references left.\n", refcount);
6997 IDirect3D8_Release(d3d8);
6998 DestroyWindow(window);
7001 static void test_update_volumetexture(void)
7003 D3DADAPTER_IDENTIFIER8 identifier;
7004 IDirect3DDevice8 *device;
7005 IDirect3D8 *d3d8;
7006 HWND window;
7007 HRESULT hr;
7008 IDirect3DVolumeTexture8 *src, *dst;
7009 unsigned int i;
7010 D3DLOCKED_BOX locked_box;
7011 ULONG refcount;
7012 D3DCAPS8 caps;
7013 BOOL is_warp;
7014 static const struct
7016 D3DPOOL src_pool, dst_pool;
7017 HRESULT hr;
7019 tests[] =
7021 { D3DPOOL_DEFAULT, D3DPOOL_DEFAULT, D3DERR_INVALIDCALL },
7022 { D3DPOOL_MANAGED, D3DPOOL_DEFAULT, D3DERR_INVALIDCALL },
7023 { D3DPOOL_SYSTEMMEM, D3DPOOL_DEFAULT, D3D_OK },
7024 { D3DPOOL_SCRATCH, D3DPOOL_DEFAULT, D3DERR_INVALIDCALL },
7026 { D3DPOOL_DEFAULT, D3DPOOL_MANAGED, D3DERR_INVALIDCALL },
7027 { D3DPOOL_MANAGED, D3DPOOL_MANAGED, D3DERR_INVALIDCALL },
7028 { D3DPOOL_SYSTEMMEM, D3DPOOL_MANAGED, D3DERR_INVALIDCALL },
7029 { D3DPOOL_SCRATCH, D3DPOOL_MANAGED, D3DERR_INVALIDCALL },
7031 { D3DPOOL_DEFAULT, D3DPOOL_SYSTEMMEM, D3DERR_INVALIDCALL },
7032 { D3DPOOL_MANAGED, D3DPOOL_SYSTEMMEM, D3DERR_INVALIDCALL },
7033 { D3DPOOL_SYSTEMMEM, D3DPOOL_SYSTEMMEM, D3DERR_INVALIDCALL },
7034 { D3DPOOL_SCRATCH, D3DPOOL_SYSTEMMEM, D3DERR_INVALIDCALL },
7036 { D3DPOOL_DEFAULT, D3DPOOL_SCRATCH, D3DERR_INVALIDCALL },
7037 { D3DPOOL_MANAGED, D3DPOOL_SCRATCH, D3DERR_INVALIDCALL },
7038 { D3DPOOL_SYSTEMMEM, D3DPOOL_SCRATCH, D3DERR_INVALIDCALL },
7039 { D3DPOOL_SCRATCH, D3DPOOL_SCRATCH, D3DERR_INVALIDCALL },
7041 static const struct
7043 UINT src_size, dst_size;
7044 UINT src_lvl, dst_lvl;
7045 D3DFORMAT src_fmt, dst_fmt;
7047 tests2[] =
7049 { 8, 8, 0, 0, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 },
7050 { 8, 8, 4, 4, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 },
7051 { 8, 8, 2, 2, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 },
7052 { 8, 8, 1, 1, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 },
7053 { 8, 8, 4, 0, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 },
7054 { 8, 8, 1, 4, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 }, /* Different level count */
7055 { 4, 8, 1, 1, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 }, /* Different size */
7056 { 8, 8, 4, 4, D3DFMT_A8R8G8B8, D3DFMT_X8R8G8B8 }, /* Different format */
7059 window = create_window();
7060 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
7061 ok(!!d3d8, "Failed to create a D3D object.\n");
7062 hr = IDirect3D8_GetAdapterIdentifier(d3d8, D3DADAPTER_DEFAULT, 0, &identifier);
7063 ok(SUCCEEDED(hr), "Failed to get adapter identifier, hr %#x.\n", hr);
7064 is_warp = adapter_is_warp(&identifier);
7065 if (!(device = create_device(d3d8, window, NULL)))
7067 skip("Failed to create a D3D device, skipping tests.\n");
7068 IDirect3D8_Release(d3d8);
7069 DestroyWindow(window);
7070 return;
7073 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
7074 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
7075 if (!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP))
7077 skip("Volume textures not supported, skipping test.\n");
7078 goto out;
7081 for (i = 0; i < ARRAY_SIZE(tests); i++)
7083 DWORD src_usage = tests[i].src_pool == D3DPOOL_DEFAULT ? D3DUSAGE_DYNAMIC : 0;
7084 DWORD dst_usage = tests[i].dst_pool == D3DPOOL_DEFAULT ? D3DUSAGE_DYNAMIC : 0;
7086 hr = IDirect3DDevice8_CreateVolumeTexture(device, 1, 1, 1, 1, src_usage,
7087 D3DFMT_A8R8G8B8, tests[i].src_pool, &src);
7088 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x.\n", hr);
7089 hr = IDirect3DDevice8_CreateVolumeTexture(device, 1, 1, 1, 1, dst_usage,
7090 D3DFMT_A8R8G8B8, tests[i].dst_pool, &dst);
7091 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x.\n", hr);
7093 hr = IDirect3DVolumeTexture8_LockBox(src, 0, &locked_box, NULL, 0);
7094 ok(SUCCEEDED(hr), "Failed to lock volume texture, hr %#x.\n", hr);
7095 *((DWORD *)locked_box.pBits) = 0x11223344;
7096 hr = IDirect3DVolumeTexture8_UnlockBox(src, 0);
7097 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
7099 hr = IDirect3DDevice8_UpdateTexture(device, (IDirect3DBaseTexture8 *)src, (IDirect3DBaseTexture8 *)dst);
7100 ok(hr == tests[i].hr, "UpdateTexture returned %#x, expected %#x, src pool %x, dst pool %u.\n",
7101 hr, tests[i].hr, tests[i].src_pool, tests[i].dst_pool);
7103 if (SUCCEEDED(hr))
7105 DWORD content = *((DWORD *)locked_box.pBits);
7106 hr = IDirect3DVolumeTexture8_LockBox(dst, 0, &locked_box, NULL, 0);
7107 ok(SUCCEEDED(hr), "Failed to lock volume texture, hr %#x.\n", hr);
7108 ok(content == 0x11223344, "Dest texture contained %#x, expected 0x11223344.\n", content);
7109 hr = IDirect3DVolumeTexture8_UnlockBox(dst, 0);
7110 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
7112 IDirect3DVolumeTexture8_Release(src);
7113 IDirect3DVolumeTexture8_Release(dst);
7116 if (!(caps.TextureCaps & D3DPTEXTURECAPS_MIPVOLUMEMAP))
7118 skip("Mipmapped volume maps not supported.\n");
7119 goto out;
7122 for (i = 0; i < ARRAY_SIZE(tests2); i++)
7124 hr = IDirect3DDevice8_CreateVolumeTexture(device,
7125 tests2[i].src_size, tests2[i].src_size, tests2[i].src_size,
7126 tests2[i].src_lvl, 0, tests2[i].src_fmt, D3DPOOL_SYSTEMMEM, &src);
7127 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x, case %u.\n", hr, i);
7128 hr = IDirect3DDevice8_CreateVolumeTexture(device,
7129 tests2[i].dst_size, tests2[i].dst_size, tests2[i].dst_size,
7130 tests2[i].dst_lvl, 0, tests2[i].dst_fmt, D3DPOOL_DEFAULT, &dst);
7131 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x, case %u.\n", hr, i);
7133 hr = IDirect3DDevice8_UpdateTexture(device, (IDirect3DBaseTexture8 *)src, (IDirect3DBaseTexture8 *)dst);
7134 todo_wine_if (FAILED(hr))
7135 ok(SUCCEEDED(hr) || (is_warp && (i == 6 || i == 7)), /* Fails with Win10 WARP driver */
7136 "Failed to update texture, hr %#x, case %u.\n", hr, i);
7138 IDirect3DVolumeTexture8_Release(src);
7139 IDirect3DVolumeTexture8_Release(dst);
7142 /* As far as I can see, UpdateTexture on non-matching texture behaves like a memcpy. The raw data
7143 * stays the same in a format change, a 2x2x1 texture is copied into the first row of a 4x4x1 texture,
7144 * etc. I could not get it to segfault, but the nonexistent 5th pixel of a 2x2x1 texture is copied into
7145 * pixel 1x2x1 of a 4x4x1 texture, demonstrating a read beyond the texture's end. I suspect any bad
7146 * memory access is silently ignored by the runtime, in the kernel or on the GPU.
7148 * I'm not adding tests for this behavior until an application needs it. */
7150 out:
7151 refcount = IDirect3DDevice8_Release(device);
7152 ok(!refcount, "Device has %u references left.\n", refcount);
7153 IDirect3D8_Release(d3d8);
7154 DestroyWindow(window);
7157 static void test_create_rt_ds_fail(void)
7159 IDirect3DDevice8 *device;
7160 HWND window;
7161 HRESULT hr;
7162 ULONG refcount;
7163 IDirect3D8 *d3d8;
7164 IDirect3DSurface8 *surface;
7166 window = create_window();
7167 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
7168 ok(!!d3d8, "Failed to create a D3D object.\n");
7169 if (!(device = create_device(d3d8, window, NULL)))
7171 skip("Failed to create a D3D device, skipping tests.\n");
7172 IDirect3D8_Release(d3d8);
7173 DestroyWindow(window);
7174 return;
7177 /* Output pointer == NULL segfaults on Windows. */
7179 surface = (IDirect3DSurface8 *)0xdeadbeef;
7180 hr = IDirect3DDevice8_CreateRenderTarget(device, 4, 4, D3DFMT_D16,
7181 D3DMULTISAMPLE_NONE, FALSE, &surface);
7182 ok(hr == D3DERR_INVALIDCALL, "Creating a D16 render target returned hr %#x.\n", hr);
7183 ok(surface == NULL, "Got pointer %p, expected NULL.\n", surface);
7184 if (SUCCEEDED(hr))
7185 IDirect3DSurface8_Release(surface);
7187 surface = (IDirect3DSurface8 *)0xdeadbeef;
7188 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 4, 4, D3DFMT_A8R8G8B8,
7189 D3DMULTISAMPLE_NONE, &surface);
7190 ok(hr == D3DERR_INVALIDCALL, "Creating a A8R8G8B8 depth stencil returned hr %#x.\n", hr);
7191 ok(surface == NULL, "Got pointer %p, expected NULL.\n", surface);
7192 if (SUCCEEDED(hr))
7193 IDirect3DSurface8_Release(surface);
7195 refcount = IDirect3DDevice8_Release(device);
7196 ok(!refcount, "Device has %u references left.\n", refcount);
7197 IDirect3D8_Release(d3d8);
7198 DestroyWindow(window);
7201 static void test_volume_blocks(void)
7203 IDirect3DDevice8 *device;
7204 IDirect3D8 *d3d8;
7205 UINT refcount;
7206 HWND window;
7207 HRESULT hr;
7208 D3DCAPS8 caps;
7209 IDirect3DVolumeTexture8 *texture;
7210 unsigned int w, h, d, i, j;
7211 static const struct
7213 D3DFORMAT fmt;
7214 const char *name;
7215 unsigned int block_width;
7216 unsigned int block_height;
7217 unsigned int block_depth;
7218 unsigned int block_size;
7219 unsigned int broken;
7220 BOOL create_size_checked, core_fmt;
7222 formats[] =
7224 /* Scratch volumes enforce DXTn block locks, unlike their surface counterparts.
7225 * ATI2N and YUV blocks are not enforced on any tested card (r200, gtx 460). */
7226 {D3DFMT_DXT1, "D3DFMT_DXT1", 4, 4, 1, 8, 0, TRUE, TRUE },
7227 {D3DFMT_DXT2, "D3DFMT_DXT2", 4, 4, 1, 16, 0, TRUE, TRUE },
7228 {D3DFMT_DXT3, "D3DFMT_DXT3", 4, 4, 1, 16, 0, TRUE, TRUE },
7229 {D3DFMT_DXT4, "D3DFMT_DXT4", 4, 4, 1, 16, 0, TRUE, TRUE },
7230 {D3DFMT_DXT5, "D3DFMT_DXT5", 4, 4, 1, 16, 0, TRUE, TRUE },
7231 {D3DFMT_DXT5, "D3DFMT_DXT5", 4, 4, 1, 16, 0, TRUE, TRUE },
7232 /* ATI2N has 2x2 blocks on all AMD cards and Geforce 7 cards,
7233 * which doesn't match the format spec. On newer Nvidia cards
7234 * it has the correct 4x4 block size.
7235 * ATI1N volume textures are only supported by AMD GPUs right
7236 * now and locking offsets seem just wrong. */
7237 {MAKEFOURCC('A','T','I','1'), "ATI1N", 4, 4, 1, 8, 2, FALSE, FALSE},
7238 {MAKEFOURCC('A','T','I','2'), "ATI2N", 4, 4, 1, 16, 1, FALSE, FALSE},
7239 {D3DFMT_YUY2, "D3DFMT_YUY2", 2, 1, 1, 4, 1, FALSE, TRUE },
7240 {D3DFMT_UYVY, "D3DFMT_UYVY", 2, 1, 1, 4, 1, FALSE, TRUE },
7242 static const struct
7244 D3DPOOL pool;
7245 const char *name;
7246 BOOL need_driver_support, need_runtime_support;
7248 create_tests[] =
7250 {D3DPOOL_DEFAULT, "D3DPOOL_DEFAULT", TRUE, FALSE},
7251 {D3DPOOL_SCRATCH, "D3DPOOL_SCRATCH", FALSE, TRUE },
7252 {D3DPOOL_SYSTEMMEM, "D3DPOOL_SYSTEMMEM",TRUE, FALSE},
7253 {D3DPOOL_MANAGED, "D3DPOOL_MANAGED", TRUE, FALSE},
7255 static const struct
7257 unsigned int x, y, z, x2, y2, z2;
7259 offset_tests[] =
7261 {0, 0, 0, 8, 8, 8},
7262 {0, 0, 3, 8, 8, 8},
7263 {0, 4, 0, 8, 8, 8},
7264 {0, 4, 3, 8, 8, 8},
7265 {4, 0, 0, 8, 8, 8},
7266 {4, 0, 3, 8, 8, 8},
7267 {4, 4, 0, 8, 8, 8},
7268 {4, 4, 3, 8, 8, 8},
7270 D3DBOX box;
7271 D3DLOCKED_BOX locked_box;
7272 BYTE *base;
7273 INT expected_row_pitch, expected_slice_pitch;
7274 BOOL support;
7275 BOOL pow2;
7276 unsigned int offset, expected_offset;
7278 window = create_window();
7279 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
7280 ok(!!d3d8, "Failed to create a D3D object.\n");
7281 if (!(device = create_device(d3d8, window, NULL)))
7283 skip("Failed to create a D3D device, skipping tests.\n");
7284 IDirect3D8_Release(d3d8);
7285 DestroyWindow(window);
7286 return;
7288 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
7289 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
7290 pow2 = !!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP_POW2);
7292 for (i = 0; i < ARRAY_SIZE(formats); i++)
7294 hr = IDirect3D8_CheckDeviceFormat(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
7295 0, D3DRTYPE_VOLUMETEXTURE, formats[i].fmt);
7296 support = SUCCEEDED(hr);
7298 /* Test creation restrictions */
7299 for (w = 1; w <= 8; w++)
7301 for (h = 1; h <= 8; h++)
7303 for (d = 1; d <= 8; d++)
7305 HRESULT expect_hr;
7306 BOOL size_is_pow2;
7307 BOOL block_aligned = TRUE;
7309 if (w & (formats[i].block_width - 1) || h & (formats[i].block_height - 1))
7310 block_aligned = FALSE;
7312 size_is_pow2 = !((w & (w - 1)) || (h & (h - 1)) || (d & (d - 1)));
7314 for (j = 0; j < ARRAY_SIZE(create_tests); j++)
7316 BOOL may_succeed = FALSE;
7318 if (create_tests[j].need_runtime_support && !formats[i].core_fmt && !support)
7319 expect_hr = D3DERR_INVALIDCALL;
7320 else if (formats[i].create_size_checked && !block_aligned)
7321 expect_hr = D3DERR_INVALIDCALL;
7322 else if (pow2 && !size_is_pow2 && create_tests[j].need_driver_support)
7323 expect_hr = D3DERR_INVALIDCALL;
7324 else if (create_tests[j].need_driver_support && !support)
7325 expect_hr = D3DERR_INVALIDCALL;
7326 else
7327 expect_hr = D3D_OK;
7329 texture = (IDirect3DVolumeTexture8 *)0xdeadbeef;
7330 hr = IDirect3DDevice8_CreateVolumeTexture(device, w, h, d, 1, 0,
7331 formats[i].fmt, create_tests[j].pool, &texture);
7333 /* Wine knows about ATI2N and happily creates a scratch resource even if GL
7334 * does not support it. Accept scratch creation of extension formats on
7335 * Windows as well if it occurs. We don't really care if e.g. a Windows 7
7336 * on an r200 GPU creates scratch ATI2N texture even though the card doesn't
7337 * support it. */
7338 if (!formats[i].core_fmt && !support && FAILED(expect_hr))
7339 may_succeed = TRUE;
7341 ok(hr == expect_hr || ((SUCCEEDED(hr) && may_succeed)),
7342 "Got unexpected hr %#x for format %s, pool %s, size %ux%ux%u.\n",
7343 hr, formats[i].name, create_tests[j].name, w, h, d);
7345 if (FAILED(hr))
7346 ok(texture == NULL, "Got texture ptr %p, expected NULL.\n", texture);
7347 else
7348 IDirect3DVolumeTexture8_Release(texture);
7354 if (!support && !formats[i].core_fmt)
7355 continue;
7357 hr = IDirect3DDevice8_CreateVolumeTexture(device, 24, 8, 8, 1, 0,
7358 formats[i].fmt, D3DPOOL_SCRATCH, &texture);
7359 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x.\n", hr);
7361 /* Test lockrect offset */
7362 for (j = 0; j < ARRAY_SIZE(offset_tests); j++)
7364 unsigned int bytes_per_pixel;
7365 bytes_per_pixel = formats[i].block_size / (formats[i].block_width * formats[i].block_height);
7367 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, NULL, 0);
7368 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
7370 base = locked_box.pBits;
7371 if (formats[i].broken == 1)
7373 expected_row_pitch = bytes_per_pixel * 24;
7375 else if (formats[i].broken == 2)
7377 expected_row_pitch = 24;
7379 else
7381 expected_row_pitch = (24 /* tex width */ + formats[i].block_height - 1) / formats[i].block_width
7382 * formats[i].block_size;
7384 ok(locked_box.RowPitch == expected_row_pitch, "Got unexpected row pitch %d for format %s, expected %d.\n",
7385 locked_box.RowPitch, formats[i].name, expected_row_pitch);
7387 if (formats[i].broken)
7389 expected_slice_pitch = expected_row_pitch * 8;
7391 else
7393 expected_slice_pitch = (8 /* tex height */ + formats[i].block_depth - 1) / formats[i].block_height
7394 * expected_row_pitch;
7396 ok(locked_box.SlicePitch == expected_slice_pitch,
7397 "Got unexpected slice pitch %d for format %s, expected %d.\n",
7398 locked_box.SlicePitch, formats[i].name, expected_slice_pitch);
7400 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
7401 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x, j %u.\n", hr, j);
7403 box.Left = offset_tests[j].x;
7404 box.Top = offset_tests[j].y;
7405 box.Front = offset_tests[j].z;
7406 box.Right = offset_tests[j].x2;
7407 box.Bottom = offset_tests[j].y2;
7408 box.Back = offset_tests[j].z2;
7409 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, &box, 0);
7410 ok(SUCCEEDED(hr), "Failed to lock volume texture, hr %#x, j %u.\n", hr, j);
7412 offset = (BYTE *)locked_box.pBits - base;
7413 if (formats[i].broken == 1)
7415 expected_offset = box.Front * expected_slice_pitch
7416 + box.Top * expected_row_pitch
7417 + box.Left * bytes_per_pixel;
7419 else if (formats[i].broken == 2)
7421 expected_offset = box.Front * expected_slice_pitch
7422 + box.Top * expected_row_pitch
7423 + box.Left;
7425 else
7427 expected_offset = (box.Front / formats[i].block_depth) * expected_slice_pitch
7428 + (box.Top / formats[i].block_height) * expected_row_pitch
7429 + (box.Left / formats[i].block_width) * formats[i].block_size;
7431 ok(offset == expected_offset, "Got unexpected offset %u for format %s, expected %u, box start %ux%ux%u.\n",
7432 offset, formats[i].name, expected_offset, box.Left, box.Top, box.Front);
7434 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
7435 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
7438 /* Test partial block locks */
7439 box.Front = 0;
7440 box.Back = 1;
7441 if (formats[i].block_width > 1)
7443 box.Left = formats[i].block_width >> 1;
7444 box.Top = 0;
7445 box.Right = formats[i].block_width;
7446 box.Bottom = formats[i].block_height;
7447 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, &box, 0);
7448 ok(FAILED(hr) || broken(formats[i].broken),
7449 "Partial block lock succeeded, expected failure, format %s.\n",
7450 formats[i].name);
7451 if (SUCCEEDED(hr))
7453 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
7454 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
7457 box.Left = 0;
7458 box.Top = 0;
7459 box.Right = formats[i].block_width >> 1;
7460 box.Bottom = formats[i].block_height;
7461 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, &box, 0);
7462 ok(FAILED(hr) || broken(formats[i].broken),
7463 "Partial block lock succeeded, expected failure, format %s.\n",
7464 formats[i].name);
7465 if (SUCCEEDED(hr))
7467 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
7468 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
7472 if (formats[i].block_height > 1)
7474 box.Left = 0;
7475 box.Top = formats[i].block_height >> 1;
7476 box.Right = formats[i].block_width;
7477 box.Bottom = formats[i].block_height;
7478 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, &box, 0);
7479 ok(FAILED(hr) || broken(formats[i].broken),
7480 "Partial block lock succeeded, expected failure, format %s.\n",
7481 formats[i].name);
7482 if (SUCCEEDED(hr))
7484 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
7485 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
7488 box.Left = 0;
7489 box.Top = 0;
7490 box.Right = formats[i].block_width;
7491 box.Bottom = formats[i].block_height >> 1;
7492 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, &box, 0);
7493 ok(FAILED(hr) || broken(formats[i].broken),
7494 "Partial block lock succeeded, expected failure, format %s.\n",
7495 formats[i].name);
7496 if (SUCCEEDED(hr))
7498 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
7499 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
7503 /* Test full block lock */
7504 box.Left = 0;
7505 box.Top = 0;
7506 box.Right = formats[i].block_width;
7507 box.Bottom = formats[i].block_height;
7508 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, &box, 0);
7509 ok(SUCCEEDED(hr), "Failed to lock volume texture, hr %#x.\n", hr);
7510 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
7511 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
7513 IDirect3DVolumeTexture8_Release(texture);
7515 /* Test mipmap locks. Don't do this with ATI2N, AMD warns that the runtime
7516 * does not allocate surfaces smaller than the blocksize properly. */
7517 if ((formats[i].block_width > 1 || formats[i].block_height > 1) && formats[i].core_fmt)
7519 hr = IDirect3DDevice8_CreateVolumeTexture(device, formats[i].block_width, formats[i].block_height,
7520 2, 2, 0, formats[i].fmt, D3DPOOL_SCRATCH, &texture);
7522 ok(SUCCEEDED(hr), "CreateVolumeTexture failed, hr %#x.\n", hr);
7523 hr = IDirect3DVolumeTexture8_LockBox(texture, 1, &locked_box, NULL, 0);
7524 ok(SUCCEEDED(hr), "Failed to lock volume texture mipmap, hr %#x.\n", hr);
7525 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 1);
7526 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
7528 box.Left = box.Top = box.Front = 0;
7529 box.Right = formats[i].block_width == 1 ? 1 : formats[i].block_width >> 1;
7530 box.Bottom = formats[i].block_height == 1 ? 1 : formats[i].block_height >> 1;
7531 box.Back = 1;
7532 hr = IDirect3DVolumeTexture8_LockBox(texture, 1, &locked_box, &box, 0);
7533 ok(SUCCEEDED(hr), "Failed to lock volume texture mipmap, hr %#x.\n", hr);
7534 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 1);
7535 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
7537 box.Right = formats[i].block_width;
7538 box.Bottom = formats[i].block_height;
7539 hr = IDirect3DVolumeTexture8_LockBox(texture, 1, &locked_box, &box, 0);
7540 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
7541 if (SUCCEEDED(hr))
7542 IDirect3DVolumeTexture8_UnlockBox(texture, 1);
7544 IDirect3DVolumeTexture8_Release(texture);
7548 refcount = IDirect3DDevice8_Release(device);
7549 ok(!refcount, "Device has %u references left.\n", refcount);
7550 IDirect3D8_Release(d3d8);
7551 DestroyWindow(window);
7554 static void test_lockbox_invalid(void)
7556 static const struct
7558 D3DBOX box;
7559 HRESULT result;
7561 test_data[] =
7563 {{0, 0, 2, 2, 0, 1}, D3D_OK}, /* Valid */
7564 {{0, 0, 4, 4, 0, 1}, D3D_OK}, /* Valid */
7565 {{0, 0, 0, 4, 0, 1}, D3DERR_INVALIDCALL}, /* 0 height */
7566 {{0, 0, 4, 0, 0, 1}, D3DERR_INVALIDCALL}, /* 0 width */
7567 {{0, 0, 4, 4, 1, 1}, D3DERR_INVALIDCALL}, /* 0 depth */
7568 {{4, 0, 0, 4, 0, 1}, D3DERR_INVALIDCALL}, /* left > right */
7569 {{0, 4, 4, 0, 0, 1}, D3DERR_INVALIDCALL}, /* top > bottom */
7570 {{0, 0, 4, 4, 1, 0}, D3DERR_INVALIDCALL}, /* back > front */
7571 {{0, 0, 8, 4, 0, 1}, D3DERR_INVALIDCALL}, /* right > surface */
7572 {{0, 0, 4, 8, 0, 1}, D3DERR_INVALIDCALL}, /* bottom > surface */
7573 {{0, 0, 4, 4, 0, 3}, D3DERR_INVALIDCALL}, /* back > surface */
7574 {{8, 0, 16, 4, 0, 1}, D3DERR_INVALIDCALL}, /* left > surface */
7575 {{0, 8, 4, 16, 0, 1}, D3DERR_INVALIDCALL}, /* top > surface */
7576 {{0, 0, 4, 4, 2, 4}, D3DERR_INVALIDCALL}, /* top > surface */
7578 static const D3DBOX test_boxt_2 = {2, 2, 4, 4, 0, 1};
7579 IDirect3DVolumeTexture8 *texture = NULL;
7580 D3DLOCKED_BOX locked_box;
7581 IDirect3DDevice8 *device;
7582 IDirect3D8 *d3d;
7583 unsigned int i;
7584 ULONG refcount;
7585 HWND window;
7586 BYTE *base;
7587 HRESULT hr;
7589 window = create_window();
7590 d3d = Direct3DCreate8(D3D_SDK_VERSION);
7591 ok(!!d3d, "Failed to create a D3D object.\n");
7592 if (!(device = create_device(d3d, window, NULL)))
7594 skip("Failed to create a D3D device, skipping tests.\n");
7595 IDirect3D8_Release(d3d);
7596 DestroyWindow(window);
7597 return;
7600 hr = IDirect3DDevice8_CreateVolumeTexture(device, 4, 4, 2, 1, 0,
7601 D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &texture);
7602 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x.\n", hr);
7603 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, NULL, 0);
7604 ok(SUCCEEDED(hr), "Failed to lock volume texture, hr %#x.\n", hr);
7605 base = locked_box.pBits;
7606 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
7607 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
7609 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
7611 unsigned int offset, expected_offset;
7612 const D3DBOX *box = &test_data[i].box;
7614 locked_box.pBits = (BYTE *)0xdeadbeef;
7615 locked_box.RowPitch = 0xdeadbeef;
7616 locked_box.SlicePitch = 0xdeadbeef;
7618 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, box, 0);
7619 /* Unlike surfaces, volumes properly check the box even in Windows XP */
7620 ok(hr == test_data[i].result,
7621 "Got unexpected hr %#x with box [%u, %u, %u]->[%u, %u, %u], expected %#x.\n",
7622 hr, box->Left, box->Top, box->Front, box->Right, box->Bottom, box->Back,
7623 test_data[i].result);
7624 if (FAILED(hr))
7625 continue;
7627 offset = (BYTE *)locked_box.pBits - base;
7628 expected_offset = box->Front * locked_box.SlicePitch + box->Top * locked_box.RowPitch + box->Left * 4;
7629 ok(offset == expected_offset,
7630 "Got unexpected offset %u (expected %u) for rect [%u, %u, %u]->[%u, %u, %u].\n",
7631 offset, expected_offset, box->Left, box->Top, box->Front, box->Right, box->Bottom, box->Back);
7633 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
7634 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
7637 /* locked_box = NULL throws an exception on Windows */
7638 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, NULL, 0);
7639 ok(SUCCEEDED(hr), "Failed to lock volume texture, hr %#x.\n", hr);
7640 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, NULL, 0);
7641 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
7642 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
7643 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
7644 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
7645 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
7647 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, &test_data[0].box, 0);
7648 ok(hr == D3D_OK, "Got unexpected hr %#x for rect [%u, %u, %u]->[%u, %u, %u].\n",
7649 hr, test_data[0].box.Left, test_data[0].box.Top, test_data[0].box.Front,
7650 test_data[0].box.Right, test_data[0].box.Bottom, test_data[0].box.Back);
7651 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, &test_data[0].box, 0);
7652 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for rect [%u, %u, %u]->[%u, %u, %u].\n",
7653 hr, test_data[0].box.Left, test_data[0].box.Top, test_data[0].box.Front,
7654 test_data[0].box.Right, test_data[0].box.Bottom, test_data[0].box.Back);
7655 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, &test_boxt_2, 0);
7656 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for rect [%u, %u, %u]->[%u, %u, %u].\n",
7657 hr, test_boxt_2.Left, test_boxt_2.Top, test_boxt_2.Front,
7658 test_boxt_2.Right, test_boxt_2.Bottom, test_boxt_2.Back);
7659 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
7660 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
7662 IDirect3DVolumeTexture8_Release(texture);
7664 hr = IDirect3DDevice8_CreateVolumeTexture(device, 4, 4, 2, 1, D3DUSAGE_WRITEONLY,
7665 D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &texture);
7666 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
7668 refcount = IDirect3DDevice8_Release(device);
7669 ok(!refcount, "Device has %u references left.\n", refcount);
7670 IDirect3D8_Release(d3d);
7671 DestroyWindow(window);
7674 static void test_pixel_format(void)
7676 int format, test_format;
7677 PIXELFORMATDESCRIPTOR pfd;
7678 IDirect3D8 *d3d8 = NULL;
7679 IDirect3DDevice8 *device = NULL;
7680 HWND hwnd, hwnd2;
7681 HDC hdc, hdc2;
7682 HMODULE gl;
7683 HRESULT hr;
7685 static const float point[] = {0.0f, 0.0f, 0.0f};
7687 hwnd = create_window();
7688 ok(!!hwnd, "Failed to create window.\n");
7689 hwnd2 = create_window();
7690 ok(!!hwnd2, "Failed to create window.\n");
7692 hdc = GetDC(hwnd);
7693 ok(!!hdc, "Failed to get DC.\n");
7694 hdc2 = GetDC(hwnd2);
7695 ok(!!hdc2, "Failed to get DC.\n");
7697 gl = LoadLibraryA("opengl32.dll");
7698 ok(!!gl, "failed to load opengl32.dll; SetPixelFormat()/GetPixelFormat() may not work right\n");
7700 format = GetPixelFormat(hdc);
7701 ok(format == 0, "new window has pixel format %d\n", format);
7703 ZeroMemory(&pfd, sizeof(pfd));
7704 pfd.nSize = sizeof(pfd);
7705 pfd.nVersion = 1;
7706 pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
7707 pfd.iPixelType = PFD_TYPE_RGBA;
7708 pfd.iLayerType = PFD_MAIN_PLANE;
7709 format = ChoosePixelFormat(hdc, &pfd);
7710 if (format <= 0)
7712 skip("no pixel format available\n");
7713 goto cleanup;
7716 if (!SetPixelFormat(hdc, format, &pfd) || GetPixelFormat(hdc) != format)
7718 skip("failed to set pixel format\n");
7719 goto cleanup;
7722 if (!SetPixelFormat(hdc2, format, &pfd) || GetPixelFormat(hdc2) != format)
7724 skip("failed to set pixel format on second window\n");
7725 goto cleanup;
7728 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
7729 ok(!!d3d8, "Failed to create a D3D object.\n");
7731 test_format = GetPixelFormat(hdc);
7732 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7734 if (!(device = create_device(d3d8, hwnd, NULL)))
7736 skip("Failed to create device\n");
7737 goto cleanup;
7740 test_format = GetPixelFormat(hdc);
7741 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7743 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ);
7744 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
7746 test_format = GetPixelFormat(hdc);
7747 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7749 hr = IDirect3DDevice8_BeginScene(device);
7750 ok(SUCCEEDED(hr), "BeginScene failed %#x\n", hr);
7752 test_format = GetPixelFormat(hdc);
7753 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7755 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_POINTLIST, 1, point, 3 * sizeof(float));
7756 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
7758 test_format = GetPixelFormat(hdc);
7759 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7761 hr = IDirect3DDevice8_EndScene(device);
7762 ok(SUCCEEDED(hr), "EndScene failed %#x\n", hr);
7764 test_format = GetPixelFormat(hdc);
7765 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7767 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
7768 ok(SUCCEEDED(hr), "Present failed %#x\n", hr);
7770 test_format = GetPixelFormat(hdc);
7771 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7773 hr = IDirect3DDevice8_Present(device, NULL, NULL, hwnd2, NULL);
7774 ok(SUCCEEDED(hr), "Present failed %#x\n", hr);
7776 test_format = GetPixelFormat(hdc);
7777 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7779 test_format = GetPixelFormat(hdc2);
7780 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
7782 cleanup:
7783 if (device)
7785 UINT refcount = IDirect3DDevice8_Release(device);
7786 ok(!refcount, "Device has %u references left.\n", refcount);
7788 if (d3d8)
7789 IDirect3D8_Release(d3d8);
7790 FreeLibrary(gl);
7791 ReleaseDC(hwnd2, hdc2);
7792 ReleaseDC(hwnd, hdc);
7793 DestroyWindow(hwnd2);
7794 DestroyWindow(hwnd);
7797 static void test_begin_end_state_block(void)
7799 DWORD stateblock, stateblock2;
7800 IDirect3DDevice8 *device;
7801 IDirect3D8 *d3d;
7802 ULONG refcount;
7803 DWORD value;
7804 HWND window;
7805 HRESULT hr;
7807 window = create_window();
7808 d3d = Direct3DCreate8(D3D_SDK_VERSION);
7809 ok(!!d3d, "Failed to create a D3D object.\n");
7810 if (!(device = create_device(d3d, window, NULL)))
7812 skip("Failed to create a D3D device, skipping tests.\n");
7813 IDirect3D8_Release(d3d);
7814 DestroyWindow(window);
7815 return;
7818 hr = IDirect3DDevice8_BeginStateBlock(device);
7819 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7821 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
7822 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7824 stateblock = 0xdeadbeef;
7825 hr = IDirect3DDevice8_EndStateBlock(device, &stateblock);
7826 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7827 ok(!!stateblock && stateblock != 0xdeadbeef, "Got unexpected stateblock %#x.\n", stateblock);
7829 stateblock2 = 0xdeadbeef;
7830 hr = IDirect3DDevice8_EndStateBlock(device, &stateblock2);
7831 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
7832 ok(stateblock2 == 0xdeadbeef, "Got unexpected stateblock %#x.\n", stateblock2);
7834 hr = IDirect3DDevice8_GetRenderState(device, D3DRS_LIGHTING, &value);
7835 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7836 ok(value == TRUE, "Got unexpected value %#x.\n", value);
7838 hr = IDirect3DDevice8_BeginStateBlock(device);
7839 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7841 hr = IDirect3DDevice8_BeginStateBlock(device);
7842 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
7844 hr = IDirect3DDevice8_ApplyStateBlock(device, stateblock);
7845 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
7847 hr = IDirect3DDevice8_CaptureStateBlock(device, stateblock);
7848 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
7850 hr = IDirect3DDevice8_CreateStateBlock(device, D3DSBT_ALL, &stateblock2);
7851 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
7853 hr = IDirect3DDevice8_GetRenderState(device, D3DRS_LIGHTING, &value);
7854 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7855 ok(value == TRUE, "Got unexpected value %#x.\n", value);
7857 hr = IDirect3DDevice8_EndStateBlock(device, &stateblock2);
7858 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7860 hr = IDirect3DDevice8_ApplyStateBlock(device, stateblock2);
7861 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7863 hr = IDirect3DDevice8_GetRenderState(device, D3DRS_LIGHTING, &value);
7864 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7865 ok(value == TRUE, "Got unexpected value %#x.\n", value);
7867 refcount = IDirect3DDevice8_Release(device);
7868 ok(!refcount, "Device has %u references left.\n", refcount);
7869 IDirect3D8_Release(d3d);
7870 DestroyWindow(window);
7873 static void test_shader_constant_apply(void)
7875 static const float vs_const[] = {1.0f, 2.0f, 3.0f, 4.0f};
7876 static const float ps_const[] = {5.0f, 6.0f, 7.0f, 8.0f};
7877 static const float initial[] = {0.0f, 0.0f, 0.0f, 0.0f};
7878 DWORD vs_version, ps_version;
7879 IDirect3DDevice8 *device;
7880 DWORD stateblock;
7881 IDirect3D8 *d3d;
7882 ULONG refcount;
7883 D3DCAPS8 caps;
7884 float ret[4];
7885 HWND window;
7886 HRESULT hr;
7888 window = create_window();
7889 d3d = Direct3DCreate8(D3D_SDK_VERSION);
7890 ok(!!d3d, "Failed to create a D3D object.\n");
7891 if (!(device = create_device(d3d, window, NULL)))
7893 skip("Failed to create a D3D device, skipping tests.\n");
7894 IDirect3D8_Release(d3d);
7895 DestroyWindow(window);
7896 return;
7899 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
7900 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
7901 vs_version = caps.VertexShaderVersion & 0xffff;
7902 ps_version = caps.PixelShaderVersion & 0xffff;
7904 if (vs_version)
7906 hr = IDirect3DDevice8_SetVertexShaderConstant(device, 0, initial, 1);
7907 ok(SUCCEEDED(hr), "Failed to set vertex shader constant, hr %#x.\n", hr);
7908 hr = IDirect3DDevice8_SetVertexShaderConstant(device, 1, initial, 1);
7909 ok(SUCCEEDED(hr), "Failed to set vertex shader constant, hr %#x.\n", hr);
7911 hr = IDirect3DDevice8_GetVertexShaderConstant(device, 0, ret, 1);
7912 ok(SUCCEEDED(hr), "Failed to get vertex shader constant, hr %#x.\n", hr);
7913 ok(!memcmp(ret, initial, sizeof(initial)),
7914 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7915 ret[0], ret[1], ret[2], ret[3], initial[0], initial[1], initial[2], initial[3]);
7916 hr = IDirect3DDevice8_GetVertexShaderConstant(device, 1, ret, 1);
7917 ok(SUCCEEDED(hr), "Failed to get vertex shader constant, hr %#x.\n", hr);
7918 ok(!memcmp(ret, initial, sizeof(initial)),
7919 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7920 ret[0], ret[1], ret[2], ret[3], initial[0], initial[1], initial[2], initial[3]);
7922 hr = IDirect3DDevice8_SetVertexShaderConstant(device, 0, vs_const, 1);
7923 ok(SUCCEEDED(hr), "Failed to set vertex shader constant, hr %#x.\n", hr);
7925 if (ps_version)
7927 hr = IDirect3DDevice8_SetPixelShaderConstant(device, 0, initial, 1);
7928 ok(SUCCEEDED(hr), "Failed to set pixel shader constant, hr %#x.\n", hr);
7929 hr = IDirect3DDevice8_SetPixelShaderConstant(device, 1, initial, 1);
7930 ok(SUCCEEDED(hr), "Failed to set pixel shader constant, hr %#x.\n", hr);
7932 hr = IDirect3DDevice8_GetPixelShaderConstant(device, 0, ret, 1);
7933 ok(SUCCEEDED(hr), "Failed to get pixel shader constant, hr %#x.\n", hr);
7934 ok(!memcmp(ret, initial, sizeof(initial)),
7935 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7936 ret[0], ret[1], ret[2], ret[3], initial[0], initial[1], initial[2], initial[3]);
7937 hr = IDirect3DDevice8_GetPixelShaderConstant(device, 1, ret, 1);
7938 ok(SUCCEEDED(hr), "Failed to get pixel shader constant, hr %#x.\n", hr);
7939 ok(!memcmp(ret, initial, sizeof(initial)),
7940 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7941 ret[0], ret[1], ret[2], ret[3], initial[0], initial[1], initial[2], initial[3]);
7943 hr = IDirect3DDevice8_SetPixelShaderConstant(device, 0, ps_const, 1);
7944 ok(SUCCEEDED(hr), "Failed to set pixel shader constant, hr %#x.\n", hr);
7947 hr = IDirect3DDevice8_BeginStateBlock(device);
7948 ok(SUCCEEDED(hr), "Failed to begin stateblock, hr %#x.\n", hr);
7950 if (vs_version)
7952 hr = IDirect3DDevice8_SetVertexShaderConstant(device, 1, vs_const, 1);
7953 ok(SUCCEEDED(hr), "Failed to set vertex shader constant, hr %#x.\n", hr);
7955 if (ps_version)
7957 hr = IDirect3DDevice8_SetPixelShaderConstant(device, 1, ps_const, 1);
7958 ok(SUCCEEDED(hr), "Failed to set pixel shader constant, hr %#x.\n", hr);
7961 hr = IDirect3DDevice8_EndStateBlock(device, &stateblock);
7962 ok(SUCCEEDED(hr), "Failed to end stateblock, hr %#x.\n", hr);
7964 if (vs_version)
7966 hr = IDirect3DDevice8_GetVertexShaderConstant(device, 0, ret, 1);
7967 ok(SUCCEEDED(hr), "Failed to get vertex shader constant, hr %#x.\n", hr);
7968 ok(!memcmp(ret, vs_const, sizeof(vs_const)),
7969 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7970 ret[0], ret[1], ret[2], ret[3], vs_const[0], vs_const[1], vs_const[2], vs_const[3]);
7971 hr = IDirect3DDevice8_GetVertexShaderConstant(device, 1, ret, 1);
7972 ok(SUCCEEDED(hr), "Failed to get vertex shader constant, hr %#x.\n", hr);
7973 ok(!memcmp(ret, initial, sizeof(initial)),
7974 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7975 ret[0], ret[1], ret[2], ret[3], initial[0], initial[1], initial[2], initial[3]);
7977 if (ps_version)
7979 hr = IDirect3DDevice8_GetPixelShaderConstant(device, 0, ret, 1);
7980 ok(SUCCEEDED(hr), "Failed to get pixel shader constant, hr %#x.\n", hr);
7981 ok(!memcmp(ret, ps_const, sizeof(ps_const)),
7982 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7983 ret[0], ret[1], ret[2], ret[3], ps_const[0], ps_const[1], ps_const[2], ps_const[3]);
7984 hr = IDirect3DDevice8_GetPixelShaderConstant(device, 1, ret, 1);
7985 ok(SUCCEEDED(hr), "Failed to get pixel shader constant, hr %#x.\n", hr);
7986 ok(!memcmp(ret, initial, sizeof(initial)),
7987 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7988 ret[0], ret[1], ret[2], ret[3], initial[0], initial[1], initial[2], initial[3]);
7991 /* Apply doesn't overwrite constants that aren't explicitly set on the
7992 * source stateblock. */
7993 hr = IDirect3DDevice8_ApplyStateBlock(device, stateblock);
7994 ok(SUCCEEDED(hr), "Failed to apply stateblock, hr %#x.\n", hr);
7996 if (vs_version)
7998 hr = IDirect3DDevice8_GetVertexShaderConstant(device, 0, ret, 1);
7999 ok(SUCCEEDED(hr), "Failed to get vertex shader constant, hr %#x.\n", hr);
8000 ok(!memcmp(ret, vs_const, sizeof(vs_const)),
8001 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
8002 ret[0], ret[1], ret[2], ret[3], vs_const[0], vs_const[1], vs_const[2], vs_const[3]);
8003 hr = IDirect3DDevice8_GetVertexShaderConstant(device, 1, ret, 1);
8004 ok(SUCCEEDED(hr), "Failed to get vertex shader constant, hr %#x.\n", hr);
8005 ok(!memcmp(ret, vs_const, sizeof(vs_const)),
8006 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
8007 ret[0], ret[1], ret[2], ret[3], vs_const[0], vs_const[1], vs_const[2], vs_const[3]);
8009 if (ps_version)
8011 hr = IDirect3DDevice8_GetPixelShaderConstant(device, 0, ret, 1);
8012 ok(SUCCEEDED(hr), "Failed to get pixel shader constant, hr %#x.\n", hr);
8013 ok(!memcmp(ret, ps_const, sizeof(ps_const)),
8014 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
8015 ret[0], ret[1], ret[2], ret[3], ps_const[0], ps_const[1], ps_const[2], ps_const[3]);
8016 hr = IDirect3DDevice8_GetPixelShaderConstant(device, 1, ret, 1);
8017 ok(SUCCEEDED(hr), "Failed to get pixel shader constant, hr %#x.\n", hr);
8018 ok(!memcmp(ret, ps_const, sizeof(ps_const)),
8019 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
8020 ret[0], ret[1], ret[2], ret[3], ps_const[0], ps_const[1], ps_const[2], ps_const[3]);
8023 IDirect3DDevice8_DeleteStateBlock(device, stateblock);
8024 refcount = IDirect3DDevice8_Release(device);
8025 ok(!refcount, "Device has %u references left.\n", refcount);
8026 IDirect3D8_Release(d3d);
8027 DestroyWindow(window);
8030 static void test_resource_type(void)
8032 IDirect3DDevice8 *device;
8033 IDirect3DSurface8 *surface;
8034 IDirect3DTexture8 *texture;
8035 IDirect3DCubeTexture8 *cube_texture;
8036 IDirect3DVolume8 *volume;
8037 IDirect3DVolumeTexture8 *volume_texture;
8038 D3DSURFACE_DESC surface_desc;
8039 D3DVOLUME_DESC volume_desc;
8040 D3DRESOURCETYPE type;
8041 IDirect3D8 *d3d;
8042 ULONG refcount;
8043 HWND window;
8044 HRESULT hr;
8045 D3DCAPS8 caps;
8047 window = create_window();
8048 d3d = Direct3DCreate8(D3D_SDK_VERSION);
8049 ok(!!d3d, "Failed to create a D3D object.\n");
8050 if (!(device = create_device(d3d, window, NULL)))
8052 skip("Failed to create a D3D device, skipping tests.\n");
8053 IDirect3D8_Release(d3d);
8054 DestroyWindow(window);
8055 return;
8058 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
8059 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
8061 hr = IDirect3DDevice8_CreateImageSurface(device, 4, 4, D3DFMT_X8R8G8B8, &surface);
8062 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
8063 hr = IDirect3DSurface8_GetDesc(surface, &surface_desc);
8064 ok(SUCCEEDED(hr), "Failed to get surface description, hr %#x.\n", hr);
8065 ok(surface_desc.Type == D3DRTYPE_SURFACE, "Expected type D3DRTYPE_SURFACE, got %u.\n",
8066 surface_desc.Type);
8067 IDirect3DSurface8_Release(surface);
8069 hr = IDirect3DDevice8_CreateTexture(device, 2, 8, 4, 0, D3DFMT_X8R8G8B8,
8070 D3DPOOL_SYSTEMMEM, &texture);
8071 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8072 type = IDirect3DTexture8_GetType(texture);
8073 ok(type == D3DRTYPE_TEXTURE, "Expected type D3DRTYPE_TEXTURE, got %u.\n", type);
8075 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 0, &surface);
8076 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
8077 hr = IDirect3DSurface8_GetDesc(surface, &surface_desc);
8078 ok(SUCCEEDED(hr), "Failed to get surface description, hr %#x.\n", hr);
8079 ok(surface_desc.Type == D3DRTYPE_SURFACE, "Expected type D3DRTYPE_SURFACE, got %u.\n",
8080 surface_desc.Type);
8081 ok(surface_desc.Width == 2, "Expected width 2, got %u.\n", surface_desc.Width);
8082 ok(surface_desc.Height == 8, "Expected height 8, got %u.\n", surface_desc.Height);
8083 hr = IDirect3DTexture8_GetLevelDesc(texture, 0, &surface_desc);
8084 ok(SUCCEEDED(hr), "Failed to get level description, hr %#x.\n", hr);
8085 ok(surface_desc.Type == D3DRTYPE_SURFACE, "Expected type D3DRTYPE_SURFACE, got %u.\n",
8086 surface_desc.Type);
8087 ok(surface_desc.Width == 2, "Expected width 2, got %u.\n", surface_desc.Width);
8088 ok(surface_desc.Height == 8, "Expected height 8, got %u.\n", surface_desc.Height);
8089 IDirect3DSurface8_Release(surface);
8091 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 2, &surface);
8092 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
8093 hr = IDirect3DSurface8_GetDesc(surface, &surface_desc);
8094 ok(SUCCEEDED(hr), "Failed to get surface description, hr %#x.\n", hr);
8095 ok(surface_desc.Type == D3DRTYPE_SURFACE, "Expected type D3DRTYPE_SURFACE, got %u.\n",
8096 surface_desc.Type);
8097 ok(surface_desc.Width == 1, "Expected width 1, got %u.\n", surface_desc.Width);
8098 ok(surface_desc.Height == 2, "Expected height 2, got %u.\n", surface_desc.Height);
8099 hr = IDirect3DTexture8_GetLevelDesc(texture, 2, &surface_desc);
8100 ok(SUCCEEDED(hr), "Failed to get level description, hr %#x.\n", hr);
8101 ok(surface_desc.Type == D3DRTYPE_SURFACE, "Expected type D3DRTYPE_SURFACE, got %u.\n",
8102 surface_desc.Type);
8103 ok(surface_desc.Width == 1, "Expected width 1, got %u.\n", surface_desc.Width);
8104 ok(surface_desc.Height == 2, "Expected height 2, got %u.\n", surface_desc.Height);
8105 IDirect3DSurface8_Release(surface);
8106 IDirect3DTexture8_Release(texture);
8108 if (caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP)
8110 hr = IDirect3DDevice8_CreateCubeTexture(device, 1, 1, 0, D3DFMT_X8R8G8B8,
8111 D3DPOOL_SYSTEMMEM, &cube_texture);
8112 ok(SUCCEEDED(hr), "Failed to create cube texture, hr %#x.\n", hr);
8113 type = IDirect3DCubeTexture8_GetType(cube_texture);
8114 ok(type == D3DRTYPE_CUBETEXTURE, "Expected type D3DRTYPE_CUBETEXTURE, got %u.\n", type);
8116 hr = IDirect3DCubeTexture8_GetCubeMapSurface(cube_texture,
8117 D3DCUBEMAP_FACE_NEGATIVE_X, 0, &surface);
8118 ok(SUCCEEDED(hr), "Failed to get cube map surface, hr %#x.\n", hr);
8119 hr = IDirect3DSurface8_GetDesc(surface, &surface_desc);
8120 ok(SUCCEEDED(hr), "Failed to get surface description, hr %#x.\n", hr);
8121 ok(surface_desc.Type == D3DRTYPE_SURFACE, "Expected type D3DRTYPE_SURFACE, got %u.\n",
8122 surface_desc.Type);
8123 hr = IDirect3DCubeTexture8_GetLevelDesc(cube_texture, 0, &surface_desc);
8124 ok(SUCCEEDED(hr), "Failed to get level description, hr %#x.\n", hr);
8125 ok(surface_desc.Type == D3DRTYPE_SURFACE, "Expected type D3DRTYPE_SURFACE, got %u.\n",
8126 surface_desc.Type);
8127 IDirect3DSurface8_Release(surface);
8128 IDirect3DCubeTexture8_Release(cube_texture);
8130 else
8131 skip("Cube maps not supported.\n");
8133 if (caps.TextureCaps & D3DPTEXTURECAPS_MIPVOLUMEMAP)
8135 hr = IDirect3DDevice8_CreateVolumeTexture(device, 2, 4, 8, 4, 0, D3DFMT_X8R8G8B8,
8136 D3DPOOL_SYSTEMMEM, &volume_texture);
8137 ok(SUCCEEDED(hr), "CreateVolumeTexture failed, hr %#x.\n", hr);
8138 type = IDirect3DVolumeTexture8_GetType(volume_texture);
8139 ok(type == D3DRTYPE_VOLUMETEXTURE, "Expected type D3DRTYPE_VOLUMETEXTURE, got %u.\n", type);
8141 hr = IDirect3DVolumeTexture8_GetVolumeLevel(volume_texture, 0, &volume);
8142 ok(SUCCEEDED(hr), "Failed to get volume level, hr %#x.\n", hr);
8143 /* IDirect3DVolume8 is not an IDirect3DResource8 and has no GetType method. */
8144 hr = IDirect3DVolume8_GetDesc(volume, &volume_desc);
8145 ok(SUCCEEDED(hr), "Failed to get volume description, hr %#x.\n", hr);
8146 ok(volume_desc.Type == D3DRTYPE_VOLUME, "Expected type D3DRTYPE_VOLUME, got %u.\n",
8147 volume_desc.Type);
8148 ok(volume_desc.Width == 2, "Expected width 2, got %u.\n", volume_desc.Width);
8149 ok(volume_desc.Height == 4, "Expected height 4, got %u.\n", volume_desc.Height);
8150 ok(volume_desc.Depth == 8, "Expected depth 8, got %u.\n", volume_desc.Depth);
8151 hr = IDirect3DVolumeTexture8_GetLevelDesc(volume_texture, 0, &volume_desc);
8152 ok(SUCCEEDED(hr), "Failed to get level description, hr %#x.\n", hr);
8153 ok(volume_desc.Type == D3DRTYPE_VOLUME, "Expected type D3DRTYPE_VOLUME, got %u.\n",
8154 volume_desc.Type);
8155 ok(volume_desc.Width == 2, "Expected width 2, got %u.\n", volume_desc.Width);
8156 ok(volume_desc.Height == 4, "Expected height 4, got %u.\n", volume_desc.Height);
8157 ok(volume_desc.Depth == 8, "Expected depth 8, got %u.\n", volume_desc.Depth);
8158 IDirect3DVolume8_Release(volume);
8160 hr = IDirect3DVolumeTexture8_GetVolumeLevel(volume_texture, 2, &volume);
8161 ok(SUCCEEDED(hr), "Failed to get volume level, hr %#x.\n", hr);
8162 hr = IDirect3DVolume8_GetDesc(volume, &volume_desc);
8163 ok(SUCCEEDED(hr), "Failed to get volume description, hr %#x.\n", hr);
8164 ok(volume_desc.Type == D3DRTYPE_VOLUME, "Expected type D3DRTYPE_VOLUME, got %u.\n",
8165 volume_desc.Type);
8166 ok(volume_desc.Width == 1, "Expected width 1, got %u.\n", volume_desc.Width);
8167 ok(volume_desc.Height == 1, "Expected height 1, got %u.\n", volume_desc.Height);
8168 ok(volume_desc.Depth == 2, "Expected depth 2, got %u.\n", volume_desc.Depth);
8169 hr = IDirect3DVolumeTexture8_GetLevelDesc(volume_texture, 2, &volume_desc);
8170 ok(SUCCEEDED(hr), "Failed to get level description, hr %#x.\n", hr);
8171 ok(volume_desc.Type == D3DRTYPE_VOLUME, "Expected type D3DRTYPE_VOLUME, got %u.\n",
8172 volume_desc.Type);
8173 ok(volume_desc.Width == 1, "Expected width 1, got %u.\n", volume_desc.Width);
8174 ok(volume_desc.Height == 1, "Expected height 1, got %u.\n", volume_desc.Height);
8175 ok(volume_desc.Depth == 2, "Expected depth 2, got %u.\n", volume_desc.Depth);
8176 IDirect3DVolume8_Release(volume);
8177 IDirect3DVolumeTexture8_Release(volume_texture);
8179 else
8180 skip("Mipmapped volume maps not supported.\n");
8182 refcount = IDirect3DDevice8_Release(device);
8183 ok(!refcount, "Device has %u references left.\n", refcount);
8184 IDirect3D8_Release(d3d);
8185 DestroyWindow(window);
8188 static void test_mipmap_lock(void)
8190 IDirect3DDevice8 *device;
8191 IDirect3DSurface8 *surface, *surface2, *surface_dst, *surface_dst2;
8192 IDirect3DTexture8 *texture, *texture_dst;
8193 IDirect3D8 *d3d;
8194 ULONG refcount;
8195 HWND window;
8196 HRESULT hr;
8197 D3DLOCKED_RECT locked_rect;
8199 window = create_window();
8200 d3d = Direct3DCreate8(D3D_SDK_VERSION);
8201 ok(!!d3d, "Failed to create a D3D object.\n");
8202 if (!(device = create_device(d3d, window, NULL)))
8204 skip("Failed to create a D3D device, skipping tests.\n");
8205 IDirect3D8_Release(d3d);
8206 DestroyWindow(window);
8207 return;
8210 hr = IDirect3DDevice8_CreateTexture(device, 4, 4, 2, 0, D3DFMT_X8R8G8B8,
8211 D3DPOOL_DEFAULT, &texture_dst);
8212 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8213 hr = IDirect3DTexture8_GetSurfaceLevel(texture_dst, 0, &surface_dst);
8214 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
8215 hr = IDirect3DTexture8_GetSurfaceLevel(texture_dst, 1, &surface_dst2);
8216 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
8218 hr = IDirect3DDevice8_CreateTexture(device, 4, 4, 2, 0, D3DFMT_X8R8G8B8,
8219 D3DPOOL_SYSTEMMEM, &texture);
8220 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
8221 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 0, &surface);
8222 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
8223 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 1, &surface2);
8224 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
8226 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, NULL, 0);
8227 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
8228 hr = IDirect3DSurface8_LockRect(surface2, &locked_rect, NULL, 0);
8229 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
8230 hr = IDirect3DSurface8_UnlockRect(surface);
8231 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
8233 hr = IDirect3DDevice8_CopyRects(device, surface, NULL, 0, surface_dst, NULL);
8234 ok(SUCCEEDED(hr), "Failed to update surface, hr %#x.\n", hr);
8235 hr = IDirect3DDevice8_CopyRects(device, surface2, NULL, 0, surface_dst2, NULL);
8236 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8238 /* Apparently there's no validation on the container. */
8239 hr = IDirect3DDevice8_UpdateTexture(device, (IDirect3DBaseTexture8 *)texture,
8240 (IDirect3DBaseTexture8 *)texture_dst);
8241 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x.\n", hr);
8243 hr = IDirect3DSurface8_UnlockRect(surface2);
8244 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
8246 IDirect3DSurface8_Release(surface_dst2);
8247 IDirect3DSurface8_Release(surface_dst);
8248 IDirect3DSurface8_Release(surface2);
8249 IDirect3DSurface8_Release(surface);
8250 IDirect3DTexture8_Release(texture_dst);
8251 IDirect3DTexture8_Release(texture);
8253 refcount = IDirect3DDevice8_Release(device);
8254 ok(!refcount, "Device has %u references left.\n", refcount);
8255 IDirect3D8_Release(d3d);
8256 DestroyWindow(window);
8259 static void test_writeonly_resource(void)
8261 IDirect3D8 *d3d;
8262 IDirect3DDevice8 *device;
8263 IDirect3DVertexBuffer8 *buffer;
8264 ULONG refcount;
8265 HWND window;
8266 HRESULT hr;
8267 BYTE *ptr;
8268 static const struct
8270 struct vec3 pos;
8272 quad[] =
8274 {{-1.0f, -1.0f, 0.0f}},
8275 {{-1.0f, 1.0f, 0.0f}},
8276 {{ 1.0f, -1.0f, 0.0f}},
8277 {{ 1.0f, 1.0f, 0.0f}}
8280 window = create_window();
8281 d3d = Direct3DCreate8(D3D_SDK_VERSION);
8282 ok(!!d3d, "Failed to create a D3D object.\n");
8283 if (!(device = create_device(d3d, window, NULL)))
8285 skip("Failed to create a D3D device, skipping tests.\n");
8286 IDirect3D8_Release(d3d);
8287 DestroyWindow(window);
8288 return;
8291 hr = IDirect3DDevice8_CreateVertexBuffer(device, sizeof(quad),
8292 D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &buffer);
8293 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
8295 hr = IDirect3DVertexBuffer8_Lock(buffer, 0, 0, &ptr, D3DLOCK_DISCARD);
8296 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
8297 memcpy(ptr, quad, sizeof(quad));
8298 hr = IDirect3DVertexBuffer8_Unlock(buffer);
8299 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
8300 hr = IDirect3DDevice8_SetStreamSource(device, 0, buffer, sizeof(*quad));
8301 ok(SUCCEEDED(hr), "Failed to set stream source, hr %#x.\n", hr);
8302 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ);
8303 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
8305 hr = IDirect3DDevice8_BeginScene(device);
8306 ok(SUCCEEDED(hr), "Failed to begin scene %#x\n", hr);
8307 hr = IDirect3DDevice8_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, 0, 2);
8308 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
8309 hr = IDirect3DDevice8_EndScene(device);
8310 ok(SUCCEEDED(hr), "Failed to end scene %#x\n", hr);
8312 hr = IDirect3DVertexBuffer8_Lock(buffer, 0, 0, &ptr, 0);
8313 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
8314 ok (!memcmp(ptr, quad, sizeof(quad)), "Got unexpected vertex buffer data.\n");
8315 hr = IDirect3DVertexBuffer8_Unlock(buffer);
8316 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
8318 hr = IDirect3DVertexBuffer8_Lock(buffer, 0, 0, &ptr, D3DLOCK_READONLY);
8319 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
8320 ok (!memcmp(ptr, quad, sizeof(quad)), "Got unexpected vertex buffer data.\n");
8321 hr = IDirect3DVertexBuffer8_Unlock(buffer);
8322 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
8324 refcount = IDirect3DVertexBuffer8_Release(buffer);
8325 ok(!refcount, "Vertex buffer has %u references left.\n", refcount);
8326 refcount = IDirect3DDevice8_Release(device);
8327 ok(!refcount, "Device has %u references left.\n", refcount);
8328 IDirect3D8_Release(d3d);
8329 DestroyWindow(window);
8332 static void test_lost_device(void)
8334 D3DADAPTER_IDENTIFIER8 identifier;
8335 struct device_desc device_desc;
8336 IDirect3DDevice8 *device;
8337 IDirect3D8 *d3d;
8338 ULONG refcount;
8339 HWND window;
8340 HRESULT hr;
8341 BOOL ret;
8343 window = create_window();
8344 d3d = Direct3DCreate8(D3D_SDK_VERSION);
8345 ok(!!d3d, "Failed to create a D3D object.\n");
8346 hr = IDirect3D8_GetAdapterIdentifier(d3d, D3DADAPTER_DEFAULT, 0, &identifier);
8347 ok(SUCCEEDED(hr), "Failed to get adapter identifier, hr %#x.\n", hr);
8348 device_desc.adapter_ordinal = D3DADAPTER_DEFAULT;
8349 device_desc.device_window = window;
8350 device_desc.width = registry_mode.dmPelsWidth;
8351 device_desc.height = registry_mode.dmPelsHeight;
8352 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
8353 if (!(device = create_device(d3d, window, &device_desc)))
8355 skip("Failed to create a D3D device, skipping tests.\n");
8356 goto done;
8359 hr = IDirect3DDevice8_TestCooperativeLevel(device);
8360 if (hr == D3DERR_DEVICELOST)
8362 win_skip("Broken TestCooperativeLevel(), skipping test.\n");
8363 IDirect3DDevice8_Release(device);
8364 goto done;
8366 if (adapter_is_warp(&identifier))
8368 win_skip("Windows 10 WARP crashes during this test.\n");
8369 IDirect3DDevice8_Release(device);
8370 goto done;
8373 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
8374 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
8375 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
8377 ret = SetForegroundWindow(GetDesktopWindow());
8378 ok(ret, "Failed to set foreground window.\n");
8379 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
8380 /* The device is not lost on Windows 10. */
8381 ok(hr == D3DERR_DEVICELOST || broken(hr == D3D_OK), "Got unexpected hr %#x.\n", hr);
8382 hr = IDirect3DDevice8_TestCooperativeLevel(device);
8383 ok(hr == D3DERR_DEVICELOST || broken(hr == D3D_OK), "Got unexpected hr %#x.\n", hr);
8385 ret = ShowWindow(window, SW_RESTORE);
8386 ok(ret, "Failed to restore window.\n");
8387 ret = SetForegroundWindow(window);
8388 ok(ret, "Failed to set foreground window.\n");
8389 hr = IDirect3DDevice8_TestCooperativeLevel(device);
8390 ok(hr == D3DERR_DEVICENOTRESET || broken(hr == D3D_OK), "Got unexpected hr %#x.\n", hr);
8391 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
8392 ok(hr == D3DERR_DEVICELOST || broken(hr == D3D_OK), "Got unexpected hr %#x.\n", hr);
8394 hr = reset_device(device, &device_desc);
8395 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
8396 hr = IDirect3DDevice8_TestCooperativeLevel(device);
8397 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
8398 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
8399 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
8401 device_desc.flags = 0;
8402 hr = reset_device(device, &device_desc);
8403 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
8404 hr = IDirect3DDevice8_TestCooperativeLevel(device);
8405 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
8406 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
8407 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
8409 ret = SetForegroundWindow(GetDesktopWindow());
8410 ok(ret, "Failed to set foreground window.\n");
8411 hr = IDirect3DDevice8_TestCooperativeLevel(device);
8412 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
8413 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
8414 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
8416 ret = ShowWindow(window, SW_RESTORE);
8417 ok(ret, "Failed to restore window.\n");
8418 hr = IDirect3DDevice8_TestCooperativeLevel(device);
8419 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
8420 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
8421 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
8423 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
8424 hr = reset_device(device, &device_desc);
8425 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
8426 hr = IDirect3DDevice8_TestCooperativeLevel(device);
8427 /* The device is not lost on Windows 10. */
8428 todo_wine ok(hr == D3DERR_DEVICELOST || broken(hr == D3D_OK), "Got unexpected hr %#x.\n", hr);
8429 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
8430 todo_wine ok(hr == D3DERR_DEVICELOST || broken(hr == D3D_OK), "Got unexpected hr %#x.\n", hr);
8432 ret = SetForegroundWindow(GetDesktopWindow());
8433 ok(ret, "Failed to set foreground window.\n");
8434 hr = reset_device(device, &device_desc);
8435 ok(hr == D3DERR_DEVICELOST || broken(hr == D3D_OK), "Got unexpected hr %#x.\n", hr);
8436 ret = ShowWindow(window, SW_RESTORE);
8437 ok(ret, "Failed to restore window.\n");
8438 ret = SetForegroundWindow(window);
8439 ok(ret, "Failed to set foreground window.\n");
8440 hr = reset_device(device, &device_desc);
8441 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
8443 refcount = IDirect3DDevice8_Release(device);
8444 ok(!refcount, "Device has %u references left.\n", refcount);
8445 done:
8446 IDirect3D8_Release(d3d);
8447 DestroyWindow(window);
8450 static void test_resource_priority(void)
8452 IDirect3DDevice8 *device;
8453 IDirect3DTexture8 *texture;
8454 IDirect3DVertexBuffer8 *buffer;
8455 IDirect3D8 *d3d;
8456 ULONG refcount;
8457 HWND window;
8458 HRESULT hr;
8459 static const struct
8461 D3DPOOL pool;
8462 const char *name;
8463 BOOL can_set_priority;
8465 test_data[] =
8467 {D3DPOOL_DEFAULT, "D3DPOOL_DEFAULT", FALSE},
8468 {D3DPOOL_SYSTEMMEM, "D3DPOOL_SYSTEMMEM", FALSE},
8469 {D3DPOOL_MANAGED, "D3DPOOL_MANAGED", TRUE},
8470 {D3DPOOL_SCRATCH, "D3DPOOL_SCRATCH", FALSE}
8472 unsigned int i;
8473 DWORD priority;
8475 window = create_window();
8476 d3d = Direct3DCreate8(D3D_SDK_VERSION);
8477 ok(!!d3d, "Failed to create a D3D object.\n");
8478 if (!(device = create_device(d3d, window, NULL)))
8480 skip("Failed to create a D3D device, skipping tests.\n");
8481 IDirect3D8_Release(d3d);
8482 DestroyWindow(window);
8483 return;
8486 for (i = 0; i < ARRAY_SIZE(test_data); i++)
8488 hr = IDirect3DDevice8_CreateTexture(device, 16, 16, 0, 0, D3DFMT_X8R8G8B8,
8489 test_data[i].pool, &texture);
8490 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x, pool %s.\n", hr, test_data[i].name);
8492 priority = IDirect3DTexture8_GetPriority(texture);
8493 ok(priority == 0, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
8494 priority = IDirect3DTexture8_SetPriority(texture, 1);
8495 ok(priority == 0, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
8496 priority = IDirect3DTexture8_GetPriority(texture);
8497 if (test_data[i].can_set_priority)
8499 ok(priority == 1, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
8500 priority = IDirect3DTexture8_SetPriority(texture, 0);
8501 ok(priority == 1, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
8503 else
8504 ok(priority == 0, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
8506 IDirect3DTexture8_Release(texture);
8508 if (test_data[i].pool != D3DPOOL_SCRATCH)
8510 hr = IDirect3DDevice8_CreateVertexBuffer(device, 256, 0, 0,
8511 test_data[i].pool, &buffer);
8512 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x, pool %s.\n", hr, test_data[i].name);
8514 priority = IDirect3DVertexBuffer8_GetPriority(buffer);
8515 ok(priority == 0, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
8516 priority = IDirect3DVertexBuffer8_SetPriority(buffer, 1);
8517 ok(priority == 0, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
8518 priority = IDirect3DVertexBuffer8_GetPriority(buffer);
8519 if (test_data[i].can_set_priority)
8521 ok(priority == 1, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
8522 priority = IDirect3DVertexBuffer8_SetPriority(buffer, 0);
8523 ok(priority == 1, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
8525 else
8526 ok(priority == 0, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
8528 IDirect3DVertexBuffer8_Release(buffer);
8532 refcount = IDirect3DDevice8_Release(device);
8533 ok(!refcount, "Device has %u references left.\n", refcount);
8534 IDirect3D8_Release(d3d);
8535 DestroyWindow(window);
8538 static void test_swapchain_parameters(void)
8540 IDirect3DSurface8 *backbuffer;
8541 IDirect3DDevice8 *device;
8542 HRESULT hr, expected_hr;
8543 IDirect3D8 *d3d;
8544 D3DCAPS8 caps;
8545 HWND window;
8546 unsigned int i, j;
8547 D3DPRESENT_PARAMETERS present_parameters, present_parameters_windowed = {0};
8548 static const struct
8550 BOOL windowed;
8551 UINT backbuffer_count;
8552 D3DSWAPEFFECT swap_effect;
8553 HRESULT hr;
8555 tests[] =
8557 /* Swap effect 0 is not allowed. */
8558 {TRUE, 1, 0, D3DERR_INVALIDCALL},
8559 {FALSE, 1, 0, D3DERR_INVALIDCALL},
8561 /* All (non-ex) swap effects are allowed in
8562 * windowed and fullscreen mode. */
8563 {TRUE, 1, D3DSWAPEFFECT_DISCARD, D3D_OK},
8564 {TRUE, 1, D3DSWAPEFFECT_FLIP, D3D_OK},
8565 {FALSE, 1, D3DSWAPEFFECT_DISCARD, D3D_OK},
8566 {FALSE, 1, D3DSWAPEFFECT_FLIP, D3D_OK},
8567 {FALSE, 1, D3DSWAPEFFECT_COPY, D3D_OK},
8569 /* Only one backbuffer in copy mode. Reset allows it for
8570 * some reason. */
8571 {TRUE, 0, D3DSWAPEFFECT_COPY, D3D_OK},
8572 {TRUE, 1, D3DSWAPEFFECT_COPY, D3D_OK},
8573 {TRUE, 2, D3DSWAPEFFECT_COPY, D3DERR_INVALIDCALL},
8574 {FALSE, 2, D3DSWAPEFFECT_COPY, D3DERR_INVALIDCALL},
8575 {TRUE, 0, D3DSWAPEFFECT_COPY_VSYNC, D3D_OK},
8576 {TRUE, 1, D3DSWAPEFFECT_COPY_VSYNC, D3D_OK},
8577 {TRUE, 2, D3DSWAPEFFECT_COPY_VSYNC, D3DERR_INVALIDCALL},
8578 {FALSE, 2, D3DSWAPEFFECT_COPY_VSYNC, D3DERR_INVALIDCALL},
8580 /* Ok with the others, in fullscreen and windowed mode. */
8581 {TRUE, 2, D3DSWAPEFFECT_DISCARD, D3D_OK},
8582 {TRUE, 2, D3DSWAPEFFECT_FLIP, D3D_OK},
8583 {FALSE, 2, D3DSWAPEFFECT_DISCARD, D3D_OK},
8584 {FALSE, 2, D3DSWAPEFFECT_FLIP, D3D_OK},
8586 /* Invalid swapeffects. */
8587 {TRUE, 1, D3DSWAPEFFECT_COPY_VSYNC + 1, D3DERR_INVALIDCALL},
8588 {FALSE, 1, D3DSWAPEFFECT_COPY_VSYNC + 1, D3DERR_INVALIDCALL},
8590 /* 3 is the highest allowed backbuffer count. */
8591 {TRUE, 3, D3DSWAPEFFECT_DISCARD, D3D_OK},
8592 {TRUE, 4, D3DSWAPEFFECT_DISCARD, D3DERR_INVALIDCALL},
8593 {TRUE, 4, D3DSWAPEFFECT_FLIP, D3DERR_INVALIDCALL},
8594 {FALSE, 4, D3DSWAPEFFECT_DISCARD, D3DERR_INVALIDCALL},
8595 {FALSE, 4, D3DSWAPEFFECT_FLIP, D3DERR_INVALIDCALL},
8598 window = create_window();
8599 d3d = Direct3DCreate8(D3D_SDK_VERSION);
8600 ok(!!d3d, "Failed to create a D3D object.\n");
8601 if (!(device = create_device(d3d, window, NULL)))
8603 skip("Failed to create a D3D device, skipping tests.\n");
8604 IDirect3D8_Release(d3d);
8605 DestroyWindow(window);
8606 return;
8608 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
8609 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
8610 IDirect3DDevice8_Release(device);
8612 present_parameters_windowed.BackBufferWidth = registry_mode.dmPelsWidth;
8613 present_parameters_windowed.BackBufferHeight = registry_mode.dmPelsHeight;
8614 present_parameters_windowed.hDeviceWindow = window;
8615 present_parameters_windowed.BackBufferFormat = D3DFMT_X8R8G8B8;
8616 present_parameters_windowed.SwapEffect = D3DSWAPEFFECT_COPY;
8617 present_parameters_windowed.Windowed = TRUE;
8618 present_parameters_windowed.BackBufferCount = 1;
8620 for (i = 0; i < ARRAY_SIZE(tests); ++i)
8622 UINT bb_count = tests[i].backbuffer_count ? tests[i].backbuffer_count : 1;
8624 memset(&present_parameters, 0, sizeof(present_parameters));
8625 present_parameters.BackBufferWidth = registry_mode.dmPelsWidth;
8626 present_parameters.BackBufferHeight = registry_mode.dmPelsHeight;
8627 present_parameters.hDeviceWindow = window;
8628 present_parameters.BackBufferFormat = D3DFMT_X8R8G8B8;
8630 present_parameters.SwapEffect = tests[i].swap_effect;
8631 present_parameters.Windowed = tests[i].windowed;
8632 present_parameters.BackBufferCount = tests[i].backbuffer_count;
8634 hr = IDirect3D8_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window,
8635 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device);
8636 ok(hr == tests[i].hr, "Expected hr %x, got %x, test %u.\n", tests[i].hr, hr, i);
8637 if (SUCCEEDED(hr))
8639 for (j = 0; j < bb_count; ++j)
8641 hr = IDirect3DDevice8_GetBackBuffer(device, j, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
8642 ok(SUCCEEDED(hr), "Failed to get backbuffer %u, hr %#x, test %u.\n", j, hr, i);
8643 IDirect3DSurface8_Release(backbuffer);
8645 hr = IDirect3DDevice8_GetBackBuffer(device, j, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
8646 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %x, test %u.\n", hr, i);
8648 IDirect3DDevice8_Release(device);
8651 hr = IDirect3D8_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window,
8652 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters_windowed, &device);
8653 ok(SUCCEEDED(hr), "Failed to create device, hr %#x, test %u.\n", hr, i);
8655 memset(&present_parameters, 0, sizeof(present_parameters));
8656 present_parameters.BackBufferWidth = registry_mode.dmPelsWidth;
8657 present_parameters.BackBufferHeight = registry_mode.dmPelsHeight;
8658 present_parameters.hDeviceWindow = window;
8659 present_parameters.BackBufferFormat = D3DFMT_X8R8G8B8;
8661 present_parameters.SwapEffect = tests[i].swap_effect;
8662 present_parameters.Windowed = tests[i].windowed;
8663 present_parameters.BackBufferCount = tests[i].backbuffer_count;
8665 hr = IDirect3DDevice8_Reset(device, &present_parameters);
8666 ok(hr == tests[i].hr, "Expected hr %x, got %x, test %u.\n", tests[i].hr, hr, i);
8668 if (FAILED(hr))
8670 hr = IDirect3DDevice8_Reset(device, &present_parameters_windowed);
8671 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x, test %u.\n", hr, i);
8673 else
8675 for (j = 0; j < bb_count; ++j)
8677 hr = IDirect3DDevice8_GetBackBuffer(device, j, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
8678 todo_wine_if (j)
8679 ok(SUCCEEDED(hr), "Failed to get backbuffer %u, hr %#x, test %u.\n", j, hr, i);
8680 if (SUCCEEDED(hr))
8681 IDirect3DSurface8_Release(backbuffer);
8683 hr = IDirect3DDevice8_GetBackBuffer(device, j, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
8684 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %x, test %u.\n", hr, i);
8686 IDirect3DDevice8_Release(device);
8689 for (i = 0; i < 10; ++i)
8691 memset(&present_parameters, 0, sizeof(present_parameters));
8692 present_parameters.BackBufferWidth = registry_mode.dmPelsWidth;
8693 present_parameters.BackBufferHeight = registry_mode.dmPelsHeight;
8694 present_parameters.hDeviceWindow = window;
8695 present_parameters.BackBufferFormat = D3DFMT_X8R8G8B8;
8696 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
8697 present_parameters.Windowed = FALSE;
8698 present_parameters.BackBufferCount = 2;
8700 present_parameters.FullScreen_PresentationInterval = i;
8701 switch (present_parameters.FullScreen_PresentationInterval)
8703 case D3DPRESENT_INTERVAL_ONE:
8704 case D3DPRESENT_INTERVAL_TWO:
8705 case D3DPRESENT_INTERVAL_THREE:
8706 case D3DPRESENT_INTERVAL_FOUR:
8707 if (!(caps.PresentationIntervals & present_parameters.FullScreen_PresentationInterval))
8708 continue;
8709 /* Fall through */
8710 case D3DPRESENT_INTERVAL_DEFAULT:
8711 expected_hr = D3D_OK;
8712 break;
8713 default:
8714 expected_hr = D3DERR_INVALIDCALL;
8715 break;
8718 hr = IDirect3D8_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window,
8719 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device);
8720 ok(hr == expected_hr, "Got unexpected hr %#x, test %u.\n", hr, i);
8721 if (SUCCEEDED(hr))
8722 IDirect3DDevice8_Release(device);
8725 IDirect3D8_Release(d3d);
8726 DestroyWindow(window);
8729 static void test_check_device_format(void)
8731 D3DDEVTYPE device_type;
8732 IDirect3D8 *d3d;
8733 HRESULT hr;
8735 d3d = Direct3DCreate8(D3D_SDK_VERSION);
8736 ok(!!d3d, "Failed to create a D3D object.\n");
8738 for (device_type = D3DDEVTYPE_HAL; device_type <= D3DDEVTYPE_SW; ++device_type)
8740 hr = IDirect3D8_CheckDeviceFormat(d3d, 0, device_type, D3DFMT_UNKNOWN,
8741 0, D3DRTYPE_SURFACE, D3DFMT_A8R8G8B8);
8742 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x, device type %#x.\n", hr, device_type);
8743 hr = IDirect3D8_CheckDeviceFormat(d3d, 0, device_type, D3DFMT_UNKNOWN,
8744 0, D3DRTYPE_TEXTURE, D3DFMT_A8R8G8B8);
8745 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x, device type %#x.\n", hr, device_type);
8746 hr = IDirect3D8_CheckDeviceFormat(d3d, 0, device_type, D3DFMT_UNKNOWN,
8747 0, D3DRTYPE_SURFACE, D3DFMT_X8R8G8B8);
8748 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x, device type %#x.\n", hr, device_type);
8749 hr = IDirect3D8_CheckDeviceFormat(d3d, 0, device_type, D3DFMT_UNKNOWN,
8750 0, D3DRTYPE_TEXTURE, D3DFMT_X8R8G8B8);
8751 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x, device type %#x.\n", hr, device_type);
8754 hr = IDirect3D8_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_A8R8G8B8,
8755 0, D3DRTYPE_TEXTURE, D3DFMT_X8R8G8B8);
8756 ok(hr == D3DERR_NOTAVAILABLE, "Got unexpected hr %#x.\n", hr);
8757 hr = IDirect3D8_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
8758 0, D3DRTYPE_TEXTURE, D3DFMT_X8R8G8B8);
8759 ok(hr == D3D_OK || hr == D3DERR_NOTAVAILABLE, "Got unexpected hr %#x.\n", hr);
8761 hr = IDirect3D8_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
8762 0, D3DRTYPE_VERTEXBUFFER, D3DFMT_VERTEXDATA);
8763 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8764 hr = IDirect3D8_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
8765 0, D3DRTYPE_INDEXBUFFER, D3DFMT_VERTEXDATA);
8766 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8767 hr = IDirect3D8_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
8768 0, D3DRTYPE_INDEXBUFFER, D3DFMT_INDEX16);
8769 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8771 hr = IDirect3D8_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
8772 D3DUSAGE_SOFTWAREPROCESSING, D3DRTYPE_VERTEXBUFFER, D3DFMT_VERTEXDATA);
8773 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8774 hr = IDirect3D8_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
8775 D3DUSAGE_SOFTWAREPROCESSING, D3DRTYPE_INDEXBUFFER, D3DFMT_VERTEXDATA);
8776 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8777 hr = IDirect3D8_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
8778 D3DUSAGE_SOFTWAREPROCESSING, D3DRTYPE_INDEXBUFFER, D3DFMT_INDEX16);
8779 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8781 hr = IDirect3D8_CheckDepthStencilMatch(d3d, D3DADAPTER_DEFAULT,
8782 D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DFMT_A8R8G8B8, D3DFMT_D32);
8783 ok(hr == D3DERR_NOTAVAILABLE || broken(hr == D3DERR_INVALIDCALL /* Windows 10 */),
8784 "Got unexpected hr %#x.\n", hr);
8786 hr = IDirect3D8_CheckDepthStencilMatch(d3d, D3DADAPTER_DEFAULT,
8787 D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DFMT_R5G6B5, D3DFMT_D32);
8788 ok(hr == D3DERR_NOTAVAILABLE || broken(hr == D3DERR_INVALIDCALL /* Windows 10 */),
8789 "Got unexpected hr %#x.\n", hr);
8791 IDirect3D8_Release(d3d);
8794 static void test_miptree_layout(void)
8796 unsigned int pool_idx, format_idx, base_dimension, level_count, offset, i, j;
8797 IDirect3DCubeTexture8 *texture_cube;
8798 IDirect3DTexture8 *texture_2d;
8799 IDirect3DDevice8 *device;
8800 D3DLOCKED_RECT map_desc;
8801 BYTE *base = NULL;
8802 IDirect3D8 *d3d;
8803 D3DCAPS8 caps;
8804 UINT refcount;
8805 HWND window;
8806 HRESULT hr;
8808 static const struct
8810 D3DFORMAT format;
8811 const char *name;
8813 formats[] =
8815 {D3DFMT_A8R8G8B8, "D3DFMT_A8R8G8B8"},
8816 {D3DFMT_A8, "D3DFMT_A8"},
8817 {D3DFMT_L8, "D3DFMT_L8"},
8818 {MAKEFOURCC('A','T','I','1'), "D3DFMT_ATI1"},
8819 {MAKEFOURCC('A','T','I','2'), "D3DFMT_ATI2"},
8821 static const struct
8823 D3DPOOL pool;
8824 const char *name;
8826 pools[] =
8828 {D3DPOOL_MANAGED, "D3DPOOL_MANAGED"},
8829 {D3DPOOL_SYSTEMMEM, "D3DPOOL_SYSTEMMEM"},
8830 {D3DPOOL_SCRATCH, "D3DPOOL_SCRATCH"},
8833 window = create_window();
8834 d3d = Direct3DCreate8(D3D_SDK_VERSION);
8835 ok(!!d3d, "Failed to create a D3D object.\n");
8836 if (!(device = create_device(d3d, window, NULL)))
8838 skip("Failed to create a D3D device, skipping tests.\n");
8839 goto done;
8842 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
8843 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
8845 base_dimension = 257;
8846 if (caps.TextureCaps & (D3DPTEXTURECAPS_POW2 | D3DPTEXTURECAPS_CUBEMAP_POW2))
8848 skip("Using power of two base dimension.\n");
8849 base_dimension = 256;
8852 for (format_idx = 0; format_idx < ARRAY_SIZE(formats); ++format_idx)
8854 if (FAILED(hr = IDirect3D8_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
8855 D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, formats[format_idx].format)))
8857 skip("%s textures not supported, skipping tests.\n", formats[format_idx].name);
8858 continue;
8861 for (pool_idx = 0; pool_idx < ARRAY_SIZE(pools); ++pool_idx)
8863 hr = IDirect3DDevice8_CreateTexture(device, base_dimension, base_dimension, 0, 0,
8864 formats[format_idx].format, pools[pool_idx].pool, &texture_2d);
8865 ok(SUCCEEDED(hr), "Failed to create a %s %s texture, hr %#x.\n",
8866 pools[pool_idx].name, formats[format_idx].name, hr);
8868 level_count = IDirect3DTexture8_GetLevelCount(texture_2d);
8869 for (i = 0, offset = 0; i < level_count; ++i)
8871 hr = IDirect3DTexture8_LockRect(texture_2d, i, &map_desc, NULL, 0);
8872 ok(SUCCEEDED(hr), "%s, %s: Failed to lock level %u, hr %#x.\n",
8873 pools[pool_idx].name, formats[format_idx].name, i, hr);
8875 if (!i)
8876 base = map_desc.pBits;
8877 else
8878 ok(map_desc.pBits == base + offset,
8879 "%s, %s, level %u: Got unexpected pBits %p, expected %p.\n",
8880 pools[pool_idx].name, formats[format_idx].name, i, map_desc.pBits, base + offset);
8881 offset += (base_dimension >> i) * map_desc.Pitch;
8883 hr = IDirect3DTexture8_UnlockRect(texture_2d, i);
8884 ok(SUCCEEDED(hr), "%s, %s Failed to unlock level %u, hr %#x.\n",
8885 pools[pool_idx].name, formats[format_idx].name, i, hr);
8888 IDirect3DTexture8_Release(texture_2d);
8891 if (FAILED(hr = IDirect3D8_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
8892 D3DFMT_X8R8G8B8, 0, D3DRTYPE_CUBETEXTURE, formats[format_idx].format)))
8894 skip("%s cube textures not supported, skipping tests.\n", formats[format_idx].name);
8895 continue;
8898 for (pool_idx = 0; pool_idx < ARRAY_SIZE(pools); ++pool_idx)
8900 hr = IDirect3DDevice8_CreateCubeTexture(device, base_dimension, 0, 0,
8901 formats[format_idx].format, pools[pool_idx].pool, &texture_cube);
8902 ok(SUCCEEDED(hr), "Failed to create a %s %s cube texture, hr %#x.\n",
8903 pools[pool_idx].name, formats[format_idx].name, hr);
8905 level_count = IDirect3DCubeTexture8_GetLevelCount(texture_cube);
8906 for (i = 0, offset = 0; i < 6; ++i)
8908 for (j = 0; j < level_count; ++j)
8910 hr = IDirect3DCubeTexture8_LockRect(texture_cube, i, j, &map_desc, NULL, 0);
8911 ok(SUCCEEDED(hr), "%s, %s: Failed to lock face %u, level %u, hr %#x.\n",
8912 pools[pool_idx].name, formats[format_idx].name, i, j, hr);
8914 if (!i && !j)
8915 base = map_desc.pBits;
8916 else
8917 ok(map_desc.pBits == base + offset,
8918 "%s, %s, face %u, level %u: Got unexpected pBits %p, expected %p.\n",
8919 pools[pool_idx].name, formats[format_idx].name, i, j, map_desc.pBits, base + offset);
8920 offset += (base_dimension >> j) * map_desc.Pitch;
8922 hr = IDirect3DCubeTexture8_UnlockRect(texture_cube, i, j);
8923 ok(SUCCEEDED(hr), "%s, %s: Failed to unlock face %u, level %u, hr %#x.\n",
8924 pools[pool_idx].name, formats[format_idx].name, i, j, hr);
8926 offset = (offset + 15) & ~15;
8929 IDirect3DCubeTexture8_Release(texture_cube);
8933 refcount = IDirect3DDevice8_Release(device);
8934 ok(!refcount, "Device has %u references left.\n", refcount);
8935 done:
8936 IDirect3D8_Release(d3d);
8937 DestroyWindow(window);
8940 static void test_render_target_device_mismatch(void)
8942 IDirect3DDevice8 *device, *device2;
8943 IDirect3DSurface8 *surface, *rt;
8944 IDirect3D8 *d3d;
8945 UINT refcount;
8946 HWND window;
8947 HRESULT hr;
8949 window = create_window();
8950 d3d = Direct3DCreate8(D3D_SDK_VERSION);
8951 ok(!!d3d, "Failed to create a D3D object.\n");
8952 if (!(device = create_device(d3d, window, NULL)))
8954 skip("Failed to create a D3D device.\n");
8955 IDirect3D8_Release(d3d);
8956 DestroyWindow(window);
8957 return;
8960 hr = IDirect3DDevice8_GetRenderTarget(device, &rt);
8961 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
8963 device2 = create_device(d3d, window, NULL);
8964 ok(!!device2, "Failed to create a D3D device.\n");
8966 hr = IDirect3DDevice8_CreateRenderTarget(device2, 640, 480,
8967 D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, FALSE, &surface);
8968 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
8970 hr = IDirect3DDevice8_SetRenderTarget(device, surface, NULL);
8971 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8973 IDirect3DSurface8_Release(surface);
8975 hr = IDirect3DDevice8_GetRenderTarget(device2, &surface);
8976 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
8978 hr = IDirect3DDevice8_SetRenderTarget(device, surface, NULL);
8979 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8981 IDirect3DSurface8_Release(surface);
8983 hr = IDirect3DDevice8_GetRenderTarget(device, &surface);
8984 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
8985 ok(surface == rt, "Got unexpected render target %p, expected %p.\n", surface, rt);
8986 IDirect3DSurface8_Release(surface);
8987 IDirect3DSurface8_Release(rt);
8989 refcount = IDirect3DDevice8_Release(device);
8990 ok(!refcount, "Device has %u references left.\n", refcount);
8991 refcount = IDirect3DDevice8_Release(device2);
8992 ok(!refcount, "Device has %u references left.\n", refcount);
8993 IDirect3D8_Release(d3d);
8994 DestroyWindow(window);
8997 static void test_format_unknown(void)
8999 IDirect3DDevice8 *device;
9000 IDirect3D8 *d3d;
9001 UINT refcount;
9002 HWND window;
9003 void *iface;
9004 HRESULT hr;
9006 window = create_window();
9007 d3d = Direct3DCreate8(D3D_SDK_VERSION);
9008 ok(!!d3d, "Failed to create a D3D object.\n");
9009 if (!(device = create_device(d3d, window, NULL)))
9011 skip("Failed to create a D3D device.\n");
9012 IDirect3D8_Release(d3d);
9013 DestroyWindow(window);
9014 return;
9017 if (SUCCEEDED(IDirect3D8_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
9018 D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, D3DFMT_P8)))
9020 skip("P8 textures are supported, skipping some tests.\n");
9022 else
9024 iface = (void *)0xdeadbeef;
9025 hr = IDirect3DDevice8_CreateRenderTarget(device, 64, 64,
9026 D3DFMT_P8, D3DMULTISAMPLE_NONE, FALSE, (IDirect3DSurface8 **)&iface);
9027 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
9028 ok(!iface, "Got unexpected iface %p.\n", iface);
9030 iface = (void *)0xdeadbeef;
9031 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 64, 64,
9032 D3DFMT_P8, D3DMULTISAMPLE_NONE, (IDirect3DSurface8 **)&iface);
9033 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
9034 ok(!iface, "Got unexpected iface %p.\n", iface);
9036 iface = (void *)0xdeadbeef;
9037 hr = IDirect3DDevice8_CreateTexture(device, 64, 64, 1, 0,
9038 D3DFMT_P8, D3DPOOL_DEFAULT, (IDirect3DTexture8 **)&iface);
9039 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
9040 ok(!iface, "Got unexpected iface %p.\n", iface);
9042 iface = (void *)0xdeadbeef;
9043 hr = IDirect3DDevice8_CreateCubeTexture(device, 64, 1, 0,
9044 D3DFMT_P8, D3DPOOL_DEFAULT, (IDirect3DCubeTexture8 **)&iface);
9045 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
9046 ok(!iface, "Got unexpected iface %p.\n", iface);
9048 iface = (void *)0xdeadbeef;
9049 hr = IDirect3DDevice8_CreateVolumeTexture(device, 64, 64, 1, 1, 0,
9050 D3DFMT_P8, D3DPOOL_DEFAULT, (IDirect3DVolumeTexture8 **)&iface);
9051 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
9052 ok(!iface, "Got unexpected iface %p.\n", iface);
9055 iface = (void *)0xdeadbeef;
9056 hr = IDirect3DDevice8_CreateRenderTarget(device, 64, 64,
9057 D3DFMT_UNKNOWN, D3DMULTISAMPLE_NONE, FALSE, (IDirect3DSurface8 **)&iface);
9058 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
9059 ok(iface == (void *)0xdeadbeef, "Got unexpected iface %p.\n", iface);
9061 iface = (void *)0xdeadbeef;
9062 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 64, 64,
9063 D3DFMT_UNKNOWN, D3DMULTISAMPLE_NONE, (IDirect3DSurface8 **)&iface);
9064 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
9065 ok(iface == (void *)0xdeadbeef, "Got unexpected iface %p.\n", iface);
9067 iface = (void *)0xdeadbeef;
9068 hr = IDirect3DDevice8_CreateImageSurface(device, 64, 64,
9069 D3DFMT_UNKNOWN, (IDirect3DSurface8 **)&iface);
9070 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
9071 ok(!iface, "Got unexpected iface %p.\n", iface);
9073 iface = (void *)0xdeadbeef;
9074 hr = IDirect3DDevice8_CreateTexture(device, 64, 64, 1, 0,
9075 D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, (IDirect3DTexture8 **)&iface);
9076 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
9077 ok(iface == (void *)0xdeadbeef, "Got unexpected iface %p.\n", iface);
9079 iface = (void *)0xdeadbeef;
9080 hr = IDirect3DDevice8_CreateCubeTexture(device, 64, 1, 0,
9081 D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, (IDirect3DCubeTexture8 **)&iface);
9082 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
9083 ok(iface == (void *)0xdeadbeef, "Got unexpected iface %p.\n", iface);
9085 iface = (void *)0xdeadbeef;
9086 hr = IDirect3DDevice8_CreateVolumeTexture(device, 64, 64, 1, 1, 0,
9087 D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, (IDirect3DVolumeTexture8 **)&iface);
9088 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
9089 ok(iface == (void *)0xdeadbeef, "Got unexpected iface %p.\n", iface);
9091 refcount = IDirect3DDevice8_Release(device);
9092 ok(!refcount, "Device has %u references left.\n", refcount);
9093 IDirect3D8_Release(d3d);
9094 DestroyWindow(window);
9097 static void test_destroyed_window(void)
9099 IDirect3DDevice8 *device;
9100 IDirect3D8 *d3d8;
9101 ULONG refcount;
9102 HWND window;
9103 HRESULT hr;
9105 /* No WS_VISIBLE. */
9106 window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW,
9107 0, 0, 640, 480, NULL, NULL, NULL, NULL);
9108 ok(!!window, "Failed to create a window.\n");
9110 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
9111 ok(!!d3d8, "Failed to create a D3D object.\n");
9112 device = create_device(d3d8, window, NULL);
9113 IDirect3D8_Release(d3d8);
9114 DestroyWindow(window);
9115 if (!device)
9117 skip("Failed to create a 3D device, skipping test.\n");
9118 return;
9121 hr = IDirect3DDevice8_BeginScene(device);
9122 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
9123 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00000000, 0.0f, 0);
9124 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
9125 hr = IDirect3DDevice8_EndScene(device);
9126 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
9127 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
9128 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
9130 refcount = IDirect3DDevice8_Release(device);
9131 ok(!refcount, "Device has %u references left.\n", refcount);
9134 static void test_lockable_backbuffer(void)
9136 D3DPRESENT_PARAMETERS present_parameters = {0};
9137 struct device_desc device_desc;
9138 IDirect3DSurface8 *surface;
9139 IDirect3DDevice8 *device;
9140 D3DLOCKED_RECT lockrect;
9141 IDirect3D8 *d3d;
9142 ULONG refcount;
9143 HWND window;
9144 HRESULT hr;
9146 window = create_window();
9147 d3d = Direct3DCreate8(D3D_SDK_VERSION);
9148 ok(!!d3d, "Failed to create a D3D object.\n");
9150 if (!(device = create_device(d3d, window, NULL)))
9152 skip("Failed to create a D3D device, skipping tests.\n");
9153 IDirect3D8_Release(d3d);
9154 DestroyWindow(window);
9155 return;
9158 hr = IDirect3DDevice8_GetBackBuffer(device, 0, D3DBACKBUFFER_TYPE_MONO, &surface);
9159 ok(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
9161 hr = IDirect3DSurface8_LockRect(surface, &lockrect, NULL, D3DLOCK_READONLY);
9162 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
9164 IDirect3DSurface8_Release(surface);
9166 /* Reset with D3DPRESENTFLAG_LOCKABLE_BACKBUFFER. */
9167 present_parameters.BackBufferWidth = 640;
9168 present_parameters.BackBufferHeight = 480;
9169 present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
9170 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
9171 present_parameters.hDeviceWindow = window;
9172 present_parameters.Windowed = TRUE;
9173 present_parameters.EnableAutoDepthStencil = TRUE;
9174 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
9175 present_parameters.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
9177 hr = IDirect3DDevice8_Reset(device, &present_parameters);
9178 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
9180 hr = IDirect3DDevice8_GetBackBuffer(device, 0, D3DBACKBUFFER_TYPE_MONO, &surface);
9181 ok(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
9183 hr = IDirect3DSurface8_LockRect(surface, &lockrect, NULL, D3DLOCK_READONLY);
9184 ok(SUCCEEDED(hr), "Failed to lock rect, hr %#x.\n", hr);
9185 hr = IDirect3DSurface8_UnlockRect(surface);
9186 ok(SUCCEEDED(hr), "Failed to unlock rect, hr %#x.\n", hr);
9188 IDirect3DSurface8_Release(surface);
9189 refcount = IDirect3DDevice8_Release(device);
9190 ok(!refcount, "Device has %u references left.\n", refcount);
9192 device_desc.adapter_ordinal = D3DADAPTER_DEFAULT;
9193 device_desc.width = 640;
9194 device_desc.height = 480;
9195 device_desc.device_window = window;
9196 device_desc.flags = CREATE_DEVICE_LOCKABLE_BACKBUFFER;
9198 device = create_device(d3d, window, &device_desc);
9199 ok(!!device, "Failed to create device.\n");
9201 hr = IDirect3DDevice8_GetBackBuffer(device, 0, D3DBACKBUFFER_TYPE_MONO, &surface);
9202 ok(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
9204 hr = IDirect3DSurface8_LockRect(surface, &lockrect, NULL, D3DLOCK_READONLY);
9205 ok(SUCCEEDED(hr), "Failed to lock rect, hr %#x.\n", hr);
9206 hr = IDirect3DSurface8_UnlockRect(surface);
9207 ok(SUCCEEDED(hr), "Failed to unlock rect, hr %#x.\n", hr);
9209 IDirect3DSurface8_Release(surface);
9210 refcount = IDirect3DDevice8_Release(device);
9211 ok(!refcount, "Device has %u references left.\n", refcount);
9212 IDirect3D8_Release(d3d);
9213 DestroyWindow(window);
9216 static void test_clip_planes_limits(void)
9218 static const DWORD device_flags[] = {0, CREATE_DEVICE_SWVP_ONLY};
9219 IDirect3DDevice8 *device;
9220 struct device_desc desc;
9221 unsigned int i, j;
9222 IDirect3D8 *d3d;
9223 ULONG refcount;
9224 float plane[4];
9225 D3DCAPS8 caps;
9226 DWORD state;
9227 HWND window;
9228 HRESULT hr;
9230 window = create_window();
9231 d3d = Direct3DCreate8(D3D_SDK_VERSION);
9232 ok(!!d3d, "Failed to create a D3D object.\n");
9234 for (i = 0; i < ARRAY_SIZE(device_flags); ++i)
9236 desc.adapter_ordinal = D3DADAPTER_DEFAULT;
9237 desc.device_window = window;
9238 desc.width = 640;
9239 desc.height = 480;
9240 desc.flags = device_flags[i];
9241 if (!(device = create_device(d3d, window, &desc)))
9243 skip("Failed to create D3D device, flags %#x.\n", desc.flags);
9244 continue;
9247 memset(&caps, 0, sizeof(caps));
9248 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
9249 ok(hr == D3D_OK, "Failed to get caps, hr %#x.\n", hr);
9251 trace("Max user clip planes: %u.\n", caps.MaxUserClipPlanes);
9253 for (j = 0; j < caps.MaxUserClipPlanes; ++j)
9255 memset(plane, 0xff, sizeof(plane));
9256 hr = IDirect3DDevice8_GetClipPlane(device, j, plane);
9257 ok(hr == D3D_OK, "Failed to get clip plane %u, hr %#x.\n", j, hr);
9258 ok(!plane[0] && !plane[1] && !plane[2] && !plane[3],
9259 "Got unexpected plane %u: %.8e, %.8e, %.8e, %.8e.\n",
9260 j, plane[0], plane[1], plane[2], plane[3]);
9263 plane[0] = 2.0f;
9264 plane[1] = 8.0f;
9265 plane[2] = 5.0f;
9266 for (j = 0; j < caps.MaxUserClipPlanes; ++j)
9268 plane[3] = j;
9269 hr = IDirect3DDevice8_SetClipPlane(device, j, plane);
9270 ok(hr == D3D_OK, "Failed to set clip plane %u, hr %#x.\n", j, hr);
9272 for (j = 0; j < caps.MaxUserClipPlanes; ++j)
9274 memset(plane, 0xff, sizeof(plane));
9275 hr = IDirect3DDevice8_GetClipPlane(device, j, plane);
9276 ok(hr == D3D_OK, "Failed to get clip plane %u, hr %#x.\n", j, hr);
9277 ok(plane[0] == 2.0f && plane[1] == 8.0f && plane[2] == 5.0f && plane[3] == j,
9278 "Got unexpected plane %u: %.8e, %.8e, %.8e, %.8e.\n",
9279 j, plane[0], plane[1], plane[2], plane[3]);
9282 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_CLIPPLANEENABLE, 0xffffffff);
9283 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9284 hr = IDirect3DDevice8_GetRenderState(device, D3DRS_CLIPPLANEENABLE, &state);
9285 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
9286 ok(state == 0xffffffff, "Got unexpected state %#x.\n", state);
9287 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_CLIPPLANEENABLE, 0x80000000);
9288 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
9289 hr = IDirect3DDevice8_GetRenderState(device, D3DRS_CLIPPLANEENABLE, &state);
9290 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
9291 ok(state == 0x80000000, "Got unexpected state %#x.\n", state);
9293 refcount = IDirect3DDevice8_Release(device);
9294 ok(!refcount, "Device has %u references left.\n", refcount);
9297 IDirect3D8_Release(d3d);
9298 DestroyWindow(window);
9301 static void test_swapchain_multisample_reset(void)
9303 D3DPRESENT_PARAMETERS present_parameters;
9304 IDirect3DDevice8 *device;
9305 IDirect3D8 *d3d;
9306 ULONG refcount;
9307 HWND window;
9308 HRESULT hr;
9310 window = create_window();
9311 ok(!!window, "Failed to create a window.\n");
9312 d3d = Direct3DCreate8(D3D_SDK_VERSION);
9313 ok(!!d3d, "Failed to create D3D object.\n");
9315 if (IDirect3D8_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
9316 D3DFMT_A8R8G8B8, TRUE, D3DMULTISAMPLE_2_SAMPLES) == D3DERR_NOTAVAILABLE)
9318 skip("Multisampling not supported for D3DFMT_A8R8G8B8.\n");
9319 IDirect3D8_Release(d3d);
9320 DestroyWindow(window);
9321 return;
9324 if (!(device = create_device(d3d, window, NULL)))
9326 skip("Failed to create 3D device.\n");
9327 IDirect3D8_Release(d3d);
9328 DestroyWindow(window);
9329 return;
9332 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0);
9333 ok(hr == D3D_OK, "Failed to clear, hr %#x.\n", hr);
9335 memset(&present_parameters, 0, sizeof(present_parameters));
9336 present_parameters.BackBufferWidth = 640;
9337 present_parameters.BackBufferHeight = 480;
9338 present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
9339 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
9340 present_parameters.hDeviceWindow = NULL;
9341 present_parameters.Windowed = TRUE;
9342 present_parameters.MultiSampleType = D3DMULTISAMPLE_2_SAMPLES;
9343 hr = IDirect3DDevice8_Reset(device, &present_parameters);
9344 ok(hr == D3D_OK, "Failed to reset device, hr %#x.\n", hr);
9346 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0f, 0);
9347 ok(hr == D3D_OK, "Failed to clear, hr %#x.\n", hr);
9349 refcount = IDirect3DDevice8_Release(device);
9350 ok(!refcount, "Device has %u references left.\n", refcount);
9351 IDirect3D8_Release(d3d);
9352 DestroyWindow(window);
9355 static void test_device_caps(void)
9357 unsigned int adapter_idx, adapter_count;
9358 struct device_desc device_desc;
9359 IDirect3DDevice8 *device;
9360 IDirect3D8 *d3d;
9361 ULONG refcount;
9362 D3DCAPS8 caps;
9363 HWND window;
9364 HRESULT hr;
9366 window = create_window();
9367 d3d = Direct3DCreate8(D3D_SDK_VERSION);
9368 ok(!!d3d, "Failed to create a D3D object.\n");
9370 device_desc.device_window = window;
9371 device_desc.width = 640;
9372 device_desc.height = 480;
9373 device_desc.flags = 0;
9375 adapter_count = IDirect3D8_GetAdapterCount(d3d);
9376 for (adapter_idx = 0; adapter_idx < adapter_count; ++adapter_idx)
9378 /* Test IDirect3D8_GetDeviceCaps */
9379 hr = IDirect3D8_GetDeviceCaps(d3d, adapter_idx, D3DDEVTYPE_HAL, &caps);
9380 ok(hr == D3D_OK || hr == D3DERR_NOTAVAILABLE, "Adapter %u: GetDeviceCaps failed, hr %#x.\n",
9381 adapter_idx, hr);
9382 if (hr == D3DERR_NOTAVAILABLE)
9384 skip("Adapter %u: No Direct3D support, skipping test.\n", adapter_idx);
9385 break;
9387 ok(caps.AdapterOrdinal == adapter_idx, "Adapter %u: Got unexpected adapter ordinal %u.\n",
9388 adapter_idx, caps.AdapterOrdinal);
9390 /* Test IDirect3DDevice8_GetDeviceCaps */
9391 device_desc.adapter_ordinal = adapter_idx;
9392 device = create_device(d3d, window, &device_desc);
9393 if (!device)
9395 skip("Adapter %u: Failed to create a D3D device, skipping test.\n", adapter_idx);
9396 break;
9398 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
9399 ok(SUCCEEDED(hr), "Adapter %u: Failed to get caps, hr %#x.\n", adapter_idx, hr);
9401 ok(caps.AdapterOrdinal == adapter_idx, "Adapter %u: Got unexpected adapter ordinal %u.\n",
9402 adapter_idx, caps.AdapterOrdinal);
9403 ok(!(caps.Caps & ~D3DCAPS_READ_SCANLINE),
9404 "Adapter %u: Caps field has unexpected flags %#x.\n", adapter_idx, caps.Caps);
9405 ok(!(caps.Caps2 & ~(D3DCAPS2_CANCALIBRATEGAMMA | D3DCAPS2_CANRENDERWINDOWED
9406 | D3DCAPS2_CANMANAGERESOURCE | D3DCAPS2_DYNAMICTEXTURES | D3DCAPS2_FULLSCREENGAMMA
9407 | D3DCAPS2_NO2DDURING3DSCENE | D3DCAPS2_RESERVED)),
9408 "Adapter %u: Caps2 field has unexpected flags %#x.\n", adapter_idx, caps.Caps2);
9409 /* Nvidia returns that 0x400 flag, which is probably Vista+
9410 * D3DCAPS3_DXVAHD from d3d9caps.h */
9411 /* AMD doesn't filter all the ddraw / d3d9 caps. Consider that behavior
9412 * broken. */
9413 ok(!(caps.Caps3 & ~(D3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD | D3DCAPS3_RESERVED | 0x400))
9414 || broken(!(caps.Caps3 & ~(D3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD | 0x80))),
9415 "Adapter %u: Caps3 field has unexpected flags %#x.\n", adapter_idx, caps.Caps3);
9416 ok(!(caps.PrimitiveMiscCaps & ~(D3DPMISCCAPS_MASKZ | D3DPMISCCAPS_LINEPATTERNREP
9417 | D3DPMISCCAPS_CULLNONE | D3DPMISCCAPS_CULLCW | D3DPMISCCAPS_CULLCCW
9418 | D3DPMISCCAPS_COLORWRITEENABLE | D3DPMISCCAPS_CLIPPLANESCALEDPOINTS
9419 | D3DPMISCCAPS_CLIPTLVERTS | D3DPMISCCAPS_TSSARGTEMP | D3DPMISCCAPS_BLENDOP
9420 | D3DPMISCCAPS_NULLREFERENCE))
9421 || broken(!(caps.PrimitiveMiscCaps & ~0x003fdff6)),
9422 "Adapter %u: PrimitiveMiscCaps field has unexpected flags %#x.\n", adapter_idx,
9423 caps.PrimitiveMiscCaps);
9424 /* AMD includes an unknown 0x2 flag. */
9425 ok(!(caps.RasterCaps & ~(D3DPRASTERCAPS_DITHER | D3DPRASTERCAPS_PAT | D3DPRASTERCAPS_ZTEST
9426 | D3DPRASTERCAPS_FOGVERTEX | D3DPRASTERCAPS_FOGTABLE | D3DPRASTERCAPS_ANTIALIASEDGES
9427 | D3DPRASTERCAPS_MIPMAPLODBIAS | D3DPRASTERCAPS_ZBIAS | D3DPRASTERCAPS_ZBUFFERLESSHSR
9428 | D3DPRASTERCAPS_FOGRANGE | D3DPRASTERCAPS_ANISOTROPY | D3DPRASTERCAPS_WBUFFER
9429 | D3DPRASTERCAPS_WFOG | D3DPRASTERCAPS_ZFOG | D3DPRASTERCAPS_COLORPERSPECTIVE
9430 | D3DPRASTERCAPS_STRETCHBLTMULTISAMPLE))
9431 || broken(!(caps.RasterCaps & ~0x0ff7f19b)),
9432 "Adapter %u: RasterCaps field has unexpected flags %#x.\n", adapter_idx,
9433 caps.RasterCaps);
9434 ok(!(caps.SrcBlendCaps & ~(D3DPBLENDCAPS_ZERO | D3DPBLENDCAPS_ONE | D3DPBLENDCAPS_SRCCOLOR
9435 | D3DPBLENDCAPS_INVSRCCOLOR | D3DPBLENDCAPS_SRCALPHA | D3DPBLENDCAPS_INVSRCALPHA
9436 | D3DPBLENDCAPS_DESTALPHA | D3DPBLENDCAPS_INVDESTALPHA | D3DPBLENDCAPS_DESTCOLOR
9437 | D3DPBLENDCAPS_INVDESTCOLOR | D3DPBLENDCAPS_SRCALPHASAT | D3DPBLENDCAPS_BOTHSRCALPHA
9438 | D3DPBLENDCAPS_BOTHINVSRCALPHA)),
9439 "Adapter %u: SrcBlendCaps field has unexpected flags %#x.\n", adapter_idx,
9440 caps.SrcBlendCaps);
9441 ok(!(caps.DestBlendCaps & ~(D3DPBLENDCAPS_ZERO | D3DPBLENDCAPS_ONE | D3DPBLENDCAPS_SRCCOLOR
9442 | D3DPBLENDCAPS_INVSRCCOLOR | D3DPBLENDCAPS_SRCALPHA | D3DPBLENDCAPS_INVSRCALPHA
9443 | D3DPBLENDCAPS_DESTALPHA | D3DPBLENDCAPS_INVDESTALPHA | D3DPBLENDCAPS_DESTCOLOR
9444 | D3DPBLENDCAPS_INVDESTCOLOR | D3DPBLENDCAPS_SRCALPHASAT | D3DPBLENDCAPS_BOTHSRCALPHA
9445 | D3DPBLENDCAPS_BOTHINVSRCALPHA)),
9446 "Adapter %u: DestBlendCaps field has unexpected flags %#x.\n", adapter_idx,
9447 caps.DestBlendCaps);
9448 ok(!(caps.TextureCaps & ~(D3DPTEXTURECAPS_PERSPECTIVE | D3DPTEXTURECAPS_POW2
9449 | D3DPTEXTURECAPS_ALPHA | D3DPTEXTURECAPS_SQUAREONLY
9450 | D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE | D3DPTEXTURECAPS_ALPHAPALETTE
9451 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL | D3DPTEXTURECAPS_PROJECTED
9452 | D3DPTEXTURECAPS_CUBEMAP | D3DPTEXTURECAPS_VOLUMEMAP | D3DPTEXTURECAPS_MIPMAP
9453 | D3DPTEXTURECAPS_MIPVOLUMEMAP | D3DPTEXTURECAPS_MIPCUBEMAP
9454 | D3DPTEXTURECAPS_CUBEMAP_POW2 | D3DPTEXTURECAPS_VOLUMEMAP_POW2)),
9455 "Adapter %u: TextureCaps field has unexpected flags %#x.\n", adapter_idx,
9456 caps.TextureCaps);
9457 ok(!(caps.TextureFilterCaps & ~(D3DPTFILTERCAPS_MINFPOINT | D3DPTFILTERCAPS_MINFLINEAR
9458 | D3DPTFILTERCAPS_MINFANISOTROPIC | D3DPTFILTERCAPS_MIPFPOINT
9459 | D3DPTFILTERCAPS_MIPFLINEAR | D3DPTFILTERCAPS_MAGFPOINT | D3DPTFILTERCAPS_MAGFLINEAR
9460 | D3DPTFILTERCAPS_MAGFANISOTROPIC | D3DPTFILTERCAPS_MAGFAFLATCUBIC
9461 | D3DPTFILTERCAPS_MAGFGAUSSIANCUBIC))
9462 || broken(!(caps.TextureFilterCaps & ~0x0703073f)),
9463 "Adapter %u: TextureFilterCaps field has unexpected flags %#x.\n", adapter_idx,
9464 caps.TextureFilterCaps);
9465 ok(!(caps.CubeTextureFilterCaps & ~(D3DPTFILTERCAPS_MINFPOINT | D3DPTFILTERCAPS_MINFLINEAR
9466 | D3DPTFILTERCAPS_MINFANISOTROPIC | D3DPTFILTERCAPS_MIPFPOINT
9467 | D3DPTFILTERCAPS_MIPFLINEAR | D3DPTFILTERCAPS_MAGFPOINT | D3DPTFILTERCAPS_MAGFLINEAR
9468 | D3DPTFILTERCAPS_MAGFANISOTROPIC | D3DPTFILTERCAPS_MAGFAFLATCUBIC
9469 | D3DPTFILTERCAPS_MAGFGAUSSIANCUBIC)),
9470 "Adapter %u: CubeTextureFilterCaps field has unexpected flags %#x.\n", adapter_idx,
9471 caps.CubeTextureFilterCaps);
9472 ok(!(caps.VolumeTextureFilterCaps & ~(D3DPTFILTERCAPS_MINFPOINT | D3DPTFILTERCAPS_MINFLINEAR
9473 | D3DPTFILTERCAPS_MINFANISOTROPIC | D3DPTFILTERCAPS_MIPFPOINT
9474 | D3DPTFILTERCAPS_MIPFLINEAR | D3DPTFILTERCAPS_MAGFPOINT | D3DPTFILTERCAPS_MAGFLINEAR
9475 | D3DPTFILTERCAPS_MAGFANISOTROPIC | D3DPTFILTERCAPS_MAGFAFLATCUBIC
9476 | D3DPTFILTERCAPS_MAGFGAUSSIANCUBIC)),
9477 "Adapter %u: VolumeTextureFilterCaps field has unexpected flags %#x.\n",
9478 adapter_idx, caps.VolumeTextureFilterCaps);
9479 ok(!(caps.LineCaps & ~(D3DLINECAPS_TEXTURE | D3DLINECAPS_ZTEST | D3DLINECAPS_BLEND
9480 | D3DLINECAPS_ALPHACMP | D3DLINECAPS_FOG)),
9481 "Adapter %u: LineCaps field has unexpected flags %#x.\n", adapter_idx,
9482 caps.LineCaps);
9483 ok(!(caps.StencilCaps & ~(D3DSTENCILCAPS_KEEP | D3DSTENCILCAPS_ZERO | D3DSTENCILCAPS_REPLACE
9484 | D3DSTENCILCAPS_INCRSAT | D3DSTENCILCAPS_DECRSAT | D3DSTENCILCAPS_INVERT
9485 | D3DSTENCILCAPS_INCR | D3DSTENCILCAPS_DECR)),
9486 "Adapter %u: StencilCaps field has unexpected flags %#x.\n", adapter_idx,
9487 caps.StencilCaps);
9488 ok(!(caps.VertexProcessingCaps & ~(D3DVTXPCAPS_TEXGEN | D3DVTXPCAPS_MATERIALSOURCE7
9489 | D3DVTXPCAPS_DIRECTIONALLIGHTS | D3DVTXPCAPS_POSITIONALLIGHTS | D3DVTXPCAPS_LOCALVIEWER
9490 | D3DVTXPCAPS_TWEENING | D3DVTXPCAPS_NO_VSDT_UBYTE4)),
9491 "Adapter %u: VertexProcessingCaps field has unexpected flags %#x.\n", adapter_idx,
9492 caps.VertexProcessingCaps);
9493 /* Both Nvidia and AMD give 10 here. */
9494 ok(caps.MaxActiveLights <= 10,
9495 "Adapter %u: MaxActiveLights field has unexpected value %u.\n", adapter_idx,
9496 caps.MaxActiveLights);
9497 /* AMD gives 6, Nvidia returns 8. */
9498 ok(caps.MaxUserClipPlanes <= 8,
9499 "Adapter %u: MaxUserClipPlanes field has unexpected value %u.\n", adapter_idx,
9500 caps.MaxUserClipPlanes);
9501 ok(caps.MaxVertexW == 0.0f || caps.MaxVertexW >= 1e10f,
9502 "Adapter %u: MaxVertexW field has unexpected value %.8e.\n", adapter_idx,
9503 caps.MaxVertexW);
9505 refcount = IDirect3DDevice8_Release(device);
9506 ok(!refcount, "Adapter %u: Device has %u references left.\n", adapter_idx, refcount);
9508 IDirect3D8_Release(d3d);
9509 DestroyWindow(window);
9512 static void test_get_info(void)
9514 IDirect3DDevice8 *device;
9515 IDirect3D8 *d3d;
9516 BYTE info[1024];
9517 ULONG refcount;
9518 unsigned int i;
9519 HWND window;
9520 HRESULT hr;
9522 window = create_window();
9523 d3d = Direct3DCreate8(D3D_SDK_VERSION);
9524 ok(!!d3d, "Failed to create a D3D object.\n");
9525 if (!(device = create_device(d3d, window, NULL)))
9527 skip("Failed to create a D3D device.\n");
9528 IDirect3D8_Release(d3d);
9529 DestroyWindow(window);
9530 return;
9533 /* As called by Chessmaster 9000 (bug 42118). */
9534 hr = IDirect3DDevice8_GetInfo(device, 4, info, 16);
9535 ok(hr == S_FALSE, "Unexpected hr %#x.\n", hr);
9537 for (i = 0; i < 256; ++i)
9539 hr = IDirect3DDevice8_GetInfo(device, i, info, sizeof(info));
9540 if (i <= 4)
9541 ok(hr == (i < 4 ? E_FAIL : S_FALSE), "info_id %u, unexpected hr %#x.\n", i, hr);
9542 else
9543 ok(hr == E_FAIL || hr == S_FALSE, "info_id %u, unexpected hr %#x.\n", i, hr);
9546 refcount = IDirect3DDevice8_Release(device);
9547 ok(!refcount, "Device has %u references left.\n", refcount);
9548 IDirect3D8_Release(d3d);
9549 DestroyWindow(window);
9552 static void test_resource_access(void)
9554 IDirect3DSurface8 *backbuffer, *depth_stencil;
9555 D3DFORMAT colour_format, depth_format, format;
9556 BOOL depth_2d, depth_cube, depth_plain;
9557 D3DADAPTER_IDENTIFIER8 identifier;
9558 struct device_desc device_desc;
9559 D3DSURFACE_DESC surface_desc;
9560 IDirect3DDevice8 *device;
9561 unsigned int i, j;
9562 IDirect3D8 *d3d;
9563 ULONG refcount;
9564 HWND window;
9565 HRESULT hr;
9566 BOOL warp;
9568 enum surface_type
9570 SURFACE_2D,
9571 SURFACE_CUBE,
9572 SURFACE_RT,
9573 SURFACE_DS,
9574 SURFACE_IMAGE,
9577 enum resource_format
9579 FORMAT_COLOUR,
9580 FORMAT_ATI2,
9581 FORMAT_DEPTH,
9584 static const struct
9586 D3DPOOL pool;
9587 enum resource_format format;
9588 DWORD usage;
9589 BOOL valid;
9591 tests[] =
9593 /* 0 */
9594 {D3DPOOL_DEFAULT, FORMAT_COLOUR, 0, TRUE},
9595 {D3DPOOL_DEFAULT, FORMAT_ATI2, 0, TRUE},
9596 {D3DPOOL_DEFAULT, FORMAT_DEPTH, 0, TRUE},
9597 {D3DPOOL_DEFAULT, FORMAT_COLOUR, D3DUSAGE_RENDERTARGET, TRUE},
9598 {D3DPOOL_DEFAULT, FORMAT_DEPTH, D3DUSAGE_RENDERTARGET, FALSE},
9599 {D3DPOOL_DEFAULT, FORMAT_COLOUR, D3DUSAGE_DEPTHSTENCIL, FALSE},
9600 {D3DPOOL_DEFAULT, FORMAT_DEPTH, D3DUSAGE_DEPTHSTENCIL, TRUE},
9601 /* 7 */
9602 {D3DPOOL_DEFAULT, FORMAT_COLOUR, D3DUSAGE_DYNAMIC, TRUE},
9603 {D3DPOOL_DEFAULT, FORMAT_ATI2, D3DUSAGE_DYNAMIC, TRUE},
9604 {D3DPOOL_DEFAULT, FORMAT_DEPTH, D3DUSAGE_DYNAMIC, TRUE},
9605 {D3DPOOL_DEFAULT, FORMAT_COLOUR, D3DUSAGE_DYNAMIC | D3DUSAGE_RENDERTARGET, FALSE},
9606 {D3DPOOL_DEFAULT, FORMAT_DEPTH, D3DUSAGE_DYNAMIC | D3DUSAGE_RENDERTARGET, FALSE},
9607 {D3DPOOL_DEFAULT, FORMAT_COLOUR, D3DUSAGE_DYNAMIC | D3DUSAGE_DEPTHSTENCIL, FALSE},
9608 {D3DPOOL_DEFAULT, FORMAT_DEPTH, D3DUSAGE_DYNAMIC | D3DUSAGE_DEPTHSTENCIL, FALSE},
9609 /* 14 */
9610 {D3DPOOL_MANAGED, FORMAT_COLOUR, 0, TRUE},
9611 {D3DPOOL_MANAGED, FORMAT_ATI2, 0, TRUE},
9612 {D3DPOOL_MANAGED, FORMAT_DEPTH, 0, FALSE},
9613 {D3DPOOL_MANAGED, FORMAT_COLOUR, D3DUSAGE_RENDERTARGET, FALSE},
9614 {D3DPOOL_MANAGED, FORMAT_DEPTH, D3DUSAGE_RENDERTARGET, FALSE},
9615 {D3DPOOL_MANAGED, FORMAT_COLOUR, D3DUSAGE_DEPTHSTENCIL, FALSE},
9616 {D3DPOOL_MANAGED, FORMAT_DEPTH, D3DUSAGE_DEPTHSTENCIL, FALSE},
9617 /* 21 */
9618 {D3DPOOL_SYSTEMMEM, FORMAT_COLOUR, 0, TRUE},
9619 {D3DPOOL_SYSTEMMEM, FORMAT_ATI2, 0, TRUE},
9620 {D3DPOOL_SYSTEMMEM, FORMAT_DEPTH, 0, FALSE},
9621 {D3DPOOL_SYSTEMMEM, FORMAT_COLOUR, D3DUSAGE_RENDERTARGET, FALSE},
9622 {D3DPOOL_SYSTEMMEM, FORMAT_DEPTH, D3DUSAGE_RENDERTARGET, FALSE},
9623 {D3DPOOL_SYSTEMMEM, FORMAT_COLOUR, D3DUSAGE_DEPTHSTENCIL, FALSE},
9624 {D3DPOOL_SYSTEMMEM, FORMAT_DEPTH, D3DUSAGE_DEPTHSTENCIL, FALSE},
9625 /* 28 */
9626 {D3DPOOL_SCRATCH, FORMAT_COLOUR, 0, TRUE},
9627 {D3DPOOL_SCRATCH, FORMAT_ATI2, 0, TRUE},
9628 {D3DPOOL_SCRATCH, FORMAT_DEPTH, 0, FALSE},
9629 {D3DPOOL_SCRATCH, FORMAT_COLOUR, D3DUSAGE_RENDERTARGET, FALSE},
9630 {D3DPOOL_SCRATCH, FORMAT_DEPTH, D3DUSAGE_RENDERTARGET, FALSE},
9631 {D3DPOOL_SCRATCH, FORMAT_COLOUR, D3DUSAGE_DEPTHSTENCIL, FALSE},
9632 {D3DPOOL_SCRATCH, FORMAT_DEPTH, D3DUSAGE_DEPTHSTENCIL, FALSE},
9634 static const struct
9636 const char *name;
9637 enum surface_type type;
9639 surface_types[] =
9641 {"2D", SURFACE_2D},
9642 {"CUBE", SURFACE_CUBE},
9643 {"RT", SURFACE_RT},
9644 {"DS", SURFACE_DS},
9645 {"IMAGE", SURFACE_IMAGE},
9648 window = create_window();
9649 d3d = Direct3DCreate8(D3D_SDK_VERSION);
9650 ok(!!d3d, "Failed to create a D3D object.\n");
9651 hr = IDirect3D8_GetAdapterIdentifier(d3d, D3DADAPTER_DEFAULT, 0, &identifier);
9652 ok(SUCCEEDED(hr), "Failed to get adapter identifier, hr %#x.\n", hr);
9653 warp = adapter_is_warp(&identifier);
9655 device_desc.adapter_ordinal = D3DADAPTER_DEFAULT;
9656 device_desc.device_window = window;
9657 device_desc.width = 16;
9658 device_desc.height = 16;
9659 device_desc.flags = 0;
9660 if (!(device = create_device(d3d, window, &device_desc)))
9662 skip("Failed to create a D3D device.\n");
9663 IDirect3D8_Release(d3d);
9664 DestroyWindow(window);
9665 return;
9668 hr = IDirect3DDevice8_GetBackBuffer(device, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
9669 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
9670 hr = IDirect3DSurface8_GetDesc(backbuffer, &surface_desc);
9671 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
9672 colour_format = surface_desc.Format;
9674 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &depth_stencil);
9675 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
9676 hr = IDirect3DSurface8_GetDesc(depth_stencil, &surface_desc);
9677 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
9678 depth_format = surface_desc.Format;
9680 depth_2d = SUCCEEDED(IDirect3D8_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
9681 D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, depth_format));
9682 depth_cube = SUCCEEDED(IDirect3D8_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
9683 D3DFMT_X8R8G8B8, 0, D3DRTYPE_CUBETEXTURE, depth_format));
9684 depth_plain = SUCCEEDED(IDirect3D8_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
9685 D3DFMT_X8R8G8B8, 0, D3DRTYPE_SURFACE, depth_format));
9687 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZRHW);
9688 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
9690 for (i = 0; i < ARRAY_SIZE(surface_types); ++i)
9692 for (j = 0; j < ARRAY_SIZE(tests); ++j)
9694 IDirect3DCubeTexture8 *texture_cube;
9695 IDirect3DBaseTexture8 *texture;
9696 IDirect3DTexture8 *texture_2d;
9697 IDirect3DSurface8 *surface;
9698 HRESULT expected_hr;
9699 D3DLOCKED_RECT lr;
9701 if (tests[j].format == FORMAT_ATI2)
9702 format = MAKEFOURCC('A','T','I','2');
9703 else if (tests[j].format == FORMAT_DEPTH)
9704 format = depth_format;
9705 else
9706 format = colour_format;
9708 if (tests[j].format == FORMAT_ATI2 && FAILED(IDirect3D8_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT,
9709 D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, format)))
9711 skip("ATI2N texture not supported.\n");
9712 continue;
9715 switch (surface_types[i].type)
9717 case SURFACE_2D:
9718 hr = IDirect3DDevice8_CreateTexture(device, 16, 16, 1,
9719 tests[j].usage, format, tests[j].pool, &texture_2d);
9720 todo_wine_if(!tests[j].valid && tests[j].format == FORMAT_DEPTH && !tests[j].usage)
9721 ok(hr == (tests[j].valid && (tests[j].format != FORMAT_DEPTH || depth_2d)
9722 ? D3D_OK : D3DERR_INVALIDCALL),
9723 "Test %s %u: Got unexpected hr %#x.\n", surface_types[i].name, j, hr);
9724 if (FAILED(hr))
9725 continue;
9727 hr = IDirect3DTexture8_GetSurfaceLevel(texture_2d, 0, &surface);
9728 ok(hr == D3D_OK, "Test %s %u: Got unexpected hr %#x.\n", surface_types[i].name, j, hr);
9729 IDirect3DTexture8_Release(texture_2d);
9730 break;
9732 case SURFACE_CUBE:
9733 hr = IDirect3DDevice8_CreateCubeTexture(device, 16, 1,
9734 tests[j].usage, format, tests[j].pool, &texture_cube);
9735 todo_wine_if(!tests[j].valid && tests[j].format == FORMAT_DEPTH && !tests[j].usage)
9736 ok(hr == (tests[j].valid && (tests[j].format != FORMAT_DEPTH || depth_cube)
9737 ? D3D_OK : D3DERR_INVALIDCALL),
9738 "Test %s %u: Got unexpected hr %#x.\n", surface_types[i].name, j, hr);
9739 if (FAILED(hr))
9740 continue;
9742 hr = IDirect3DCubeTexture8_GetCubeMapSurface(texture_cube,
9743 D3DCUBEMAP_FACE_POSITIVE_X, 0, &surface);
9744 ok(hr == D3D_OK, "Test %s %u: Got unexpected hr %#x.\n", surface_types[i].name, j, hr);
9745 IDirect3DCubeTexture8_Release(texture_cube);
9746 break;
9748 case SURFACE_RT:
9749 hr = IDirect3DDevice8_CreateRenderTarget(device, 16, 16, format,
9750 D3DMULTISAMPLE_NONE, tests[j].usage & D3DUSAGE_DYNAMIC, &surface);
9751 ok(hr == (tests[j].format == FORMAT_COLOUR ? D3D_OK : D3DERR_INVALIDCALL),
9752 "Test %s %u: Got unexpected hr %#x.\n", surface_types[i].name, j, hr);
9753 if (FAILED(hr))
9754 continue;
9755 break;
9757 case SURFACE_DS:
9758 hr = IDirect3DDevice8_CreateDepthStencilSurface(device,
9759 16, 16, format, D3DMULTISAMPLE_NONE, &surface);
9760 todo_wine_if(tests[j].format == FORMAT_ATI2)
9761 ok(hr == (tests[j].format == FORMAT_DEPTH ? D3D_OK
9762 : tests[j].format == FORMAT_COLOUR ? D3DERR_INVALIDCALL : E_INVALIDARG)
9763 || (tests[j].format == FORMAT_ATI2 && hr == D3D_OK),
9764 "Test %s %u: Got unexpected hr %#x.\n", surface_types[i].name, j, hr);
9765 if (FAILED(hr))
9766 continue;
9767 break;
9769 case SURFACE_IMAGE:
9770 hr = IDirect3DDevice8_CreateImageSurface(device, 16, 16, format, &surface);
9771 ok(hr == ((tests[j].format != FORMAT_DEPTH || depth_plain) ? D3D_OK : D3DERR_INVALIDCALL),
9772 "Test %s %u: Got unexpected hr %#x.\n", surface_types[i].name, j, hr);
9773 if (FAILED(hr))
9774 continue;
9775 break;
9777 default:
9778 ok(0, "Invalid surface type %#x.\n", surface_types[i].type);
9779 continue;
9782 hr = IDirect3DSurface8_GetDesc(surface, &surface_desc);
9783 ok(hr == D3D_OK, "Test %s %u: Got unexpected hr %#x.\n", surface_types[i].name, j, hr);
9784 if (surface_types[i].type == SURFACE_RT)
9786 ok(surface_desc.Usage == D3DUSAGE_RENDERTARGET, "Test %s %u: Got unexpected usage %#x.\n",
9787 surface_types[i].name, j, surface_desc.Usage);
9788 ok(surface_desc.Pool == D3DPOOL_DEFAULT, "Test %s %u: Got unexpected pool %#x.\n",
9789 surface_types[i].name, j, surface_desc.Pool);
9791 else if (surface_types[i].type == SURFACE_DS)
9793 ok(surface_desc.Usage == D3DUSAGE_DEPTHSTENCIL, "Test %s %u: Got unexpected usage %#x.\n",
9794 surface_types[i].name, j, surface_desc.Usage);
9795 ok(surface_desc.Pool == D3DPOOL_DEFAULT, "Test %s %u: Got unexpected pool %#x.\n",
9796 surface_types[i].name, j, surface_desc.Pool);
9798 else if (surface_types[i].type == SURFACE_IMAGE)
9800 ok(!surface_desc.Usage, "Test %s %u: Got unexpected usage %#x.\n",
9801 surface_types[i].name, j, surface_desc.Usage);
9802 ok(surface_desc.Pool == D3DPOOL_SYSTEMMEM, "Test %s %u: Got unexpected pool %#x.\n",
9803 surface_types[i].name, j, surface_desc.Pool);
9805 else
9807 ok(surface_desc.Usage == tests[j].usage, "Test %s %u: Got unexpected usage %#x.\n",
9808 surface_types[i].name, j, surface_desc.Usage);
9809 ok(surface_desc.Pool == tests[j].pool, "Test %s %u: Got unexpected pool %#x.\n",
9810 surface_types[i].name, j, surface_desc.Pool);
9813 hr = IDirect3DSurface8_LockRect(surface, &lr, NULL, 0);
9814 if (surface_desc.Pool != D3DPOOL_DEFAULT || surface_desc.Usage & D3DUSAGE_DYNAMIC
9815 || (surface_types[i].type == SURFACE_RT && tests[j].usage & D3DUSAGE_DYNAMIC)
9816 || surface_types[i].type == SURFACE_IMAGE
9817 || tests[j].format == FORMAT_ATI2)
9818 expected_hr = D3D_OK;
9819 else
9820 expected_hr = D3DERR_INVALIDCALL;
9821 ok(hr == expected_hr, "Test %s %u: Got unexpected hr %#x.\n", surface_types[i].name, j, hr);
9822 hr = IDirect3DSurface8_UnlockRect(surface);
9823 todo_wine_if(expected_hr != D3D_OK && surface_types[i].type == SURFACE_2D)
9824 ok(hr == expected_hr, "Test %s %u: Got unexpected hr %#x.\n", surface_types[i].name, j, hr);
9826 if (SUCCEEDED(IDirect3DSurface8_GetContainer(surface, &IID_IDirect3DBaseTexture8, (void **)&texture)))
9828 hr = IDirect3DDevice8_SetTexture(device, 0, texture);
9829 ok(hr == D3D_OK, "Test %s %u: Got unexpected hr %#x.\n", surface_types[i].name, j, hr);
9830 hr = IDirect3DDevice8_SetTexture(device, 0, NULL);
9831 ok(hr == D3D_OK, "Test %s %u: Got unexpected hr %#x.\n", surface_types[i].name, j, hr);
9832 IDirect3DBaseTexture8_Release(texture);
9835 hr = IDirect3DDevice8_SetRenderTarget(device, surface, depth_stencil);
9836 ok(hr == (surface_desc.Usage & D3DUSAGE_RENDERTARGET ? D3D_OK : D3DERR_INVALIDCALL),
9837 "Test %s %u: Got unexpected hr %#x.\n", surface_types[i].name, j, hr);
9838 hr = IDirect3DDevice8_SetRenderTarget(device, backbuffer, depth_stencil);
9839 ok(hr == D3D_OK, "Test %s %u: Got unexpected hr %#x.\n", surface_types[i].name, j, hr);
9841 hr = IDirect3DDevice8_SetRenderTarget(device, backbuffer, surface);
9842 ok(hr == (surface_desc.Usage & D3DUSAGE_DEPTHSTENCIL ? D3D_OK : D3DERR_INVALIDCALL),
9843 "Test %s %u: Got unexpected hr %#x.\n", surface_types[i].name, j, hr);
9844 hr = IDirect3DDevice8_SetRenderTarget(device, backbuffer, depth_stencil);
9845 ok(hr == D3D_OK, "Test %s %u: Got unexpected hr %#x.\n", surface_types[i].name, j, hr);
9847 IDirect3DSurface8_Release(surface);
9851 for (i = 0; i < ARRAY_SIZE(tests); ++i)
9853 IDirect3DVolumeTexture8 *texture;
9854 D3DVOLUME_DESC volume_desc;
9855 IDirect3DVolume8 *volume;
9856 HRESULT expected_hr;
9857 D3DLOCKED_BOX lb;
9859 if (tests[i].format == FORMAT_DEPTH)
9860 continue;
9862 if (tests[i].format == FORMAT_ATI2)
9863 format = MAKEFOURCC('A','T','I','2');
9864 else
9865 format = colour_format;
9867 hr = IDirect3DDevice8_CreateVolumeTexture(device, 16, 16, 1, 1,
9868 tests[i].usage, format, tests[i].pool, &texture);
9869 ok((hr == ((!(tests[i].usage & ~D3DUSAGE_DYNAMIC) && tests[i].format != FORMAT_ATI2)
9870 || (tests[i].pool == D3DPOOL_SCRATCH && !tests[i].usage)
9871 ? D3D_OK : D3DERR_INVALIDCALL))
9872 || (tests[i].format == FORMAT_ATI2 && (hr == D3D_OK || warp)),
9873 "Test %u: Got unexpected hr %#x.\n", i, hr);
9874 if (FAILED(hr))
9875 continue;
9877 hr = IDirect3DVolumeTexture8_GetVolumeLevel(texture, 0, &volume);
9878 ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", i, hr);
9880 hr = IDirect3DVolume8_GetDesc(volume, &volume_desc);
9881 ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", i, hr);
9882 ok(volume_desc.Usage == tests[i].usage, "Test %u: Got unexpected usage %#x.\n", i, volume_desc.Usage);
9883 ok(volume_desc.Pool == tests[i].pool, "Test %u: Got unexpected pool %#x.\n", i, volume_desc.Pool);
9885 hr = IDirect3DVolume8_LockBox(volume, &lb, NULL, 0);
9886 if (volume_desc.Pool != D3DPOOL_DEFAULT || volume_desc.Usage & D3DUSAGE_DYNAMIC)
9887 expected_hr = D3D_OK;
9888 else
9889 expected_hr = D3DERR_INVALIDCALL;
9890 ok(hr == expected_hr || (volume_desc.Pool == D3DPOOL_DEFAULT && hr == D3D_OK),
9891 "Test %u: Got unexpected hr %#x.\n", i, hr);
9892 hr = IDirect3DVolume8_UnlockBox(volume);
9893 ok(hr == expected_hr || (volume_desc.Pool == D3DPOOL_DEFAULT && hr == D3D_OK),
9894 "Test %u: Got unexpected hr %#x.\n", i, hr);
9896 hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *)texture);
9897 ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", i, hr);
9898 hr = IDirect3DDevice8_SetTexture(device, 0, NULL);
9899 ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", i, hr);
9901 IDirect3DVolume8_Release(volume);
9902 IDirect3DVolumeTexture8_Release(texture);
9905 for (i = 0; i < ARRAY_SIZE(tests); ++i)
9907 D3DINDEXBUFFER_DESC ib_desc;
9908 IDirect3DIndexBuffer8 *ib;
9909 BYTE *data;
9911 hr = IDirect3DDevice8_CreateIndexBuffer(device, 16, tests[i].usage,
9912 tests[i].format == FORMAT_COLOUR ? D3DFMT_INDEX32 : D3DFMT_INDEX16, tests[i].pool, &ib);
9913 ok(hr == (tests[i].pool == D3DPOOL_SCRATCH || (tests[i].usage & ~D3DUSAGE_DYNAMIC)
9914 ? D3DERR_INVALIDCALL : D3D_OK), "Test %u: Got unexpected hr %#x.\n", i, hr);
9915 if (FAILED(hr))
9916 continue;
9918 hr = IDirect3DIndexBuffer8_GetDesc(ib, &ib_desc);
9919 ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", i, hr);
9920 ok(ib_desc.Usage == tests[i].usage, "Test %u: Got unexpected usage %#x.\n", i, ib_desc.Usage);
9921 ok(ib_desc.Pool == tests[i].pool, "Test %u: Got unexpected pool %#x.\n", i, ib_desc.Pool);
9923 hr = IDirect3DIndexBuffer8_Lock(ib, 0, 0, &data, 0);
9924 ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", i, hr);
9925 hr = IDirect3DIndexBuffer8_Unlock(ib);
9926 ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", i, hr);
9928 hr = IDirect3DDevice8_SetIndices(device, ib, 0);
9929 ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", i, hr);
9930 hr = IDirect3DDevice8_SetIndices(device, NULL, 0);
9931 ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", i, hr);
9933 IDirect3DIndexBuffer8_Release(ib);
9936 for (i = 0; i < ARRAY_SIZE(tests); ++i)
9938 D3DVERTEXBUFFER_DESC vb_desc;
9939 IDirect3DVertexBuffer8 *vb;
9940 BYTE *data;
9942 hr = IDirect3DDevice8_CreateVertexBuffer(device, 16, tests[i].usage,
9943 tests[i].format == FORMAT_COLOUR ? 0 : D3DFVF_XYZRHW, tests[i].pool, &vb);
9944 ok(hr == (tests[i].pool == D3DPOOL_SCRATCH || (tests[i].usage & ~D3DUSAGE_DYNAMIC)
9945 ? D3DERR_INVALIDCALL : D3D_OK), "Test %u: Got unexpected hr %#x.\n", i, hr);
9946 if (FAILED(hr))
9947 continue;
9949 hr = IDirect3DVertexBuffer8_GetDesc(vb, &vb_desc);
9950 ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", i, hr);
9951 ok(vb_desc.Usage == tests[i].usage, "Test %u: Got unexpected usage %#x.\n", i, vb_desc.Usage);
9952 ok(vb_desc.Pool == tests[i].pool, "Test %u: Got unexpected pool %#x.\n", i, vb_desc.Pool);
9954 hr = IDirect3DVertexBuffer8_Lock(vb, 0, 0, &data, 0);
9955 ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", i, hr);
9956 hr = IDirect3DVertexBuffer8_Unlock(vb);
9957 ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", i, hr);
9959 hr = IDirect3DDevice8_SetStreamSource(device, 0, vb, 16);
9960 ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", i, hr);
9961 hr = IDirect3DDevice8_SetStreamSource(device, 0, NULL, 0);
9962 ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", i, hr);
9964 IDirect3DVertexBuffer8_Release(vb);
9967 IDirect3DSurface8_Release(depth_stencil);
9968 IDirect3DSurface8_Release(backbuffer);
9969 refcount = IDirect3DDevice8_Release(device);
9970 ok(!refcount, "Device has %u references left.\n", refcount);
9971 IDirect3D8_Release(d3d);
9972 DestroyWindow(window);
9975 static void test_multiply_transform(void)
9977 IDirect3DDevice8 *device;
9978 D3DMATRIX ret_mat;
9979 DWORD stateblock;
9980 IDirect3D8 *d3d;
9981 unsigned int i;
9982 ULONG refcount;
9983 HWND window;
9984 HRESULT hr;
9986 static const D3DTRANSFORMSTATETYPE tests[] =
9988 D3DTS_VIEW,
9989 D3DTS_PROJECTION,
9990 D3DTS_TEXTURE0,
9991 D3DTS_TEXTURE1,
9992 D3DTS_TEXTURE2,
9993 D3DTS_TEXTURE3,
9994 D3DTS_TEXTURE4,
9995 D3DTS_TEXTURE5,
9996 D3DTS_TEXTURE6,
9997 D3DTS_TEXTURE7,
9998 D3DTS_WORLDMATRIX(0),
9999 D3DTS_WORLDMATRIX(1),
10000 D3DTS_WORLDMATRIX(2),
10001 D3DTS_WORLDMATRIX(3),
10002 D3DTS_WORLDMATRIX(255),
10005 static const D3DMATRIX mat1 =
10007 1.0f, 0.0f, 0.0f, 0.0f,
10008 0.0f, 1.0f, 0.0f, 0.0f,
10009 0.0f, 0.0f, 1.0f, 0.0f,
10010 0.0f, 0.0f, 0.0f, 1.0f,
10011 }}},
10012 mat2 =
10014 2.0f, 0.0f, 0.0f, 0.0f,
10015 0.0f, 2.0f, 0.0f, 0.0f,
10016 0.0f, 0.0f, 2.0f, 0.0f,
10017 0.0f, 0.0f, 0.0f, 2.0f,
10018 }}};
10020 window = create_window();
10021 ok(!!window, "Failed to create a window.\n");
10022 d3d = Direct3DCreate8(D3D_SDK_VERSION);
10023 ok(!!d3d, "Failed to create D3D object.\n");
10025 if (!(device = create_device(d3d, window, NULL)))
10027 skip("Failed to create 3D device.\n");
10028 IDirect3D8_Release(d3d);
10029 DestroyWindow(window);
10030 return;
10033 for (i = 0; i < ARRAY_SIZE(tests); ++i)
10035 hr = IDirect3DDevice8_GetTransform(device, tests[i], &ret_mat);
10036 ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", i, hr);
10037 ok(!memcmp(&ret_mat, &mat1, sizeof(mat1)), "Test %u: Got unexpected transform matrix.\n", i);
10039 hr = IDirect3DDevice8_MultiplyTransform(device, tests[i], &mat2);
10040 ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", i, hr);
10042 hr = IDirect3DDevice8_GetTransform(device, tests[i], &ret_mat);
10043 ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", i, hr);
10044 ok(!memcmp(&ret_mat, &mat2, sizeof(mat2)), "Test %u: Got unexpected transform matrix.\n", i);
10046 /* MultiplyTransform() goes directly into the primary stateblock. */
10048 hr = IDirect3DDevice8_SetTransform(device, tests[i], &mat1);
10049 ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", i, hr);
10051 hr = IDirect3DDevice8_BeginStateBlock(device);
10052 ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", i, hr);
10054 hr = IDirect3DDevice8_MultiplyTransform(device, tests[i], &mat2);
10055 ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", i, hr);
10057 hr = IDirect3DDevice8_EndStateBlock(device, &stateblock);
10058 ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", i, hr);
10060 hr = IDirect3DDevice8_GetTransform(device, tests[i], &ret_mat);
10061 ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", i, hr);
10062 ok(!memcmp(&ret_mat, &mat2, sizeof(mat2)), "Test %u: Got unexpected transform matrix.\n", i);
10064 hr = IDirect3DDevice8_CaptureStateBlock(device, stateblock);
10065 ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", i, hr);
10067 hr = IDirect3DDevice8_SetTransform(device, tests[i], &mat1);
10068 ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", i, hr);
10070 hr = IDirect3DDevice8_ApplyStateBlock(device, stateblock);
10071 ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", i, hr);
10073 hr = IDirect3DDevice8_GetTransform(device, tests[i], &ret_mat);
10074 ok(hr == D3D_OK, "Test %u: Got unexpected hr %#x.\n", i, hr);
10075 ok(!memcmp(&ret_mat, &mat1, sizeof(mat1)), "Test %u: Got unexpected transform matrix.\n", i);
10077 IDirect3DDevice8_DeleteStateBlock(device, stateblock);
10080 refcount = IDirect3DDevice8_Release(device);
10081 ok(!refcount, "Device has %u references left.\n", refcount);
10082 IDirect3D8_Release(d3d);
10083 DestroyWindow(window);
10086 static void test_draw_primitive(void)
10088 static const struct
10090 float position[3];
10091 DWORD color;
10093 quad[] =
10095 {{-1.0f, -1.0f, 0.0f}, 0xffff0000},
10096 {{-1.0f, 1.0f, 0.0f}, 0xffff0000},
10097 {{ 1.0f, 1.0f, 0.0f}, 0xffff0000},
10098 {{ 1.0f, -1.0f, 0.0f}, 0xffff0000},
10099 {{-1.0f, -1.0f, 0.0f}, 0xffff0000},
10101 static const WORD indices[] = {0, 1, 2, 3, 0, 2};
10103 IDirect3DVertexBuffer8 *vertex_buffer, *current_vb;
10104 IDirect3DIndexBuffer8 *index_buffer, *current_ib;
10105 UINT stride, base_vertex_index;
10106 IDirect3DDevice8 *device;
10107 DWORD stateblock;
10108 IDirect3D8 *d3d;
10109 ULONG refcount;
10110 HWND window;
10111 HRESULT hr;
10112 BYTE *ptr;
10114 window = create_window();
10115 d3d = Direct3DCreate8(D3D_SDK_VERSION);
10116 ok(!!d3d, "Failed to create a D3D object.\n");
10117 if (!(device = create_device(d3d, window, NULL)))
10119 skip("Failed to create a D3D device.\n");
10120 IDirect3D8_Release(d3d);
10121 DestroyWindow(window);
10122 return;
10125 hr = IDirect3DDevice8_CreateVertexBuffer(device, sizeof(quad), 0, 0,
10126 D3DPOOL_DEFAULT, &vertex_buffer);
10127 ok(SUCCEEDED(hr), "CreateVertexBuffer failed, hr %#x.\n", hr);
10128 hr = IDirect3DVertexBuffer8_Lock(vertex_buffer, 0, 0, &ptr, D3DLOCK_DISCARD);
10129 ok(SUCCEEDED(hr), "Lock failed, hr %#x.\n", hr);
10130 memcpy(ptr, quad, sizeof(quad));
10131 hr = IDirect3DVertexBuffer8_Unlock(vertex_buffer);
10132 ok(SUCCEEDED(hr), "Unlock failed, hr %#x.\n", hr);
10133 hr = IDirect3DDevice8_SetStreamSource(device, 0, vertex_buffer, sizeof(*quad));
10134 ok(SUCCEEDED(hr), "SetStreamSource failed, hr %#x.\n", hr);
10135 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
10136 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
10138 hr = IDirect3DDevice8_CreateIndexBuffer(device, sizeof(indices), 0, D3DFMT_INDEX16,
10139 D3DPOOL_DEFAULT, &index_buffer);
10140 ok(SUCCEEDED(hr), "CreateIndexBuffer failed, hr %#x.\n", hr);
10141 hr = IDirect3DIndexBuffer8_Lock(index_buffer, 0, 0, &ptr, D3DLOCK_DISCARD);
10142 ok(SUCCEEDED(hr), "Lock failed, hr %#x.\n", hr);
10143 memcpy(ptr, indices, sizeof(indices));
10144 hr = IDirect3DIndexBuffer8_Unlock(index_buffer);
10145 ok(SUCCEEDED(hr), "Unlock failed, hr %#x.\n", hr);
10147 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
10148 ok(SUCCEEDED(hr), "SetRenderState D3DRS_LIGHTING failed, hr %#x.\n", hr);
10150 hr = IDirect3DDevice8_BeginScene(device);
10151 ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
10153 hr = IDirect3DDevice8_DrawPrimitive(device, D3DPT_TRIANGLELIST, 0, 2);
10154 ok(SUCCEEDED(hr), "DrawPrimitive failed, hr %#x.\n", hr);
10156 hr = IDirect3DDevice8_GetStreamSource(device, 0, &current_vb, &stride);
10157 ok(SUCCEEDED(hr), "GetStreamSource failed, hr %#x.\n", hr);
10158 ok(current_vb == vertex_buffer, "Unexpected vb %p.\n", current_vb);
10159 ok(stride == sizeof(*quad), "Unexpected stride %u.\n", stride);
10160 IDirect3DVertexBuffer8_Release(current_vb);
10162 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLELIST, 0, quad, 0);
10163 ok(hr == D3D_OK, "DrawPrimitiveUP failed, hr %#x.\n", hr);
10164 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLELIST, 0, quad, sizeof(*quad));
10165 ok(hr == D3D_OK, "DrawPrimitiveUP failed, hr %#x.\n", hr);
10167 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLELIST, 2, quad, sizeof(*quad));
10168 ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
10170 hr = IDirect3DDevice8_GetStreamSource(device, 0, &current_vb, &stride);
10171 ok(SUCCEEDED(hr), "GetStreamSource failed, hr %#x.\n", hr);
10172 ok(!current_vb, "Unexpected vb %p.\n", current_vb);
10173 ok(!stride, "Unexpected stride %u.\n", stride);
10175 /* NULL index buffer, NULL stream source. */
10176 hr = IDirect3DDevice8_SetIndices(device, NULL, 0);
10177 ok(SUCCEEDED(hr), "SetIndices failed, hr %#x.\n", hr);
10178 hr = IDirect3DDevice8_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, 0, 4, 0, 2);
10179 todo_wine ok(SUCCEEDED(hr), "DrawIndexedPrimitive failed, hr %#x.\n", hr);
10181 /* Valid index buffer, NULL stream source. */
10182 hr = IDirect3DDevice8_SetIndices(device, index_buffer, 1);
10183 ok(SUCCEEDED(hr), "SetIndices failed, hr %#x.\n", hr);
10184 hr = IDirect3DDevice8_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, 0, 4, 0, 2);
10185 ok(SUCCEEDED(hr), "DrawIndexedPrimitive failed, hr %#x.\n", hr);
10187 hr = IDirect3DDevice8_GetIndices(device, &current_ib, &base_vertex_index);
10188 ok(SUCCEEDED(hr), "GetIndices failed, hr %#x.\n", hr);
10189 ok(current_ib == index_buffer, "Unexpected index buffer %p.\n", current_ib);
10190 ok(base_vertex_index == 1, "Unexpected base vertex index %u.\n", base_vertex_index);
10191 IDirect3DIndexBuffer8_Release(current_ib);
10193 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0, 4, 0,
10194 indices, D3DFMT_INDEX16, quad, 0);
10195 ok(SUCCEEDED(hr), "DrawIndexedPrimitiveUP failed, hr %#x.\n", hr);
10196 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0, 4, 2,
10197 indices, D3DFMT_INDEX16, quad, 0);
10198 ok(SUCCEEDED(hr), "DrawIndexedPrimitiveUP failed, hr %#x.\n", hr);
10200 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0, 4, 2,
10201 indices, D3DFMT_INDEX16, quad, sizeof(*quad));
10202 ok(SUCCEEDED(hr), "DrawIndexedPrimitiveUP failed, hr %#x.\n", hr);
10204 hr = IDirect3DDevice8_GetIndices(device, &current_ib, &base_vertex_index);
10205 ok(SUCCEEDED(hr), "GetIndices failed, hr %#x.\n", hr);
10206 ok(!current_ib, "Unexpected index buffer %p.\n", current_ib);
10207 ok(!base_vertex_index, "Unexpected base vertex index %u.\n", base_vertex_index);
10209 /* Resetting of stream source and index buffer is not recorded in stateblocks. */
10211 hr = IDirect3DDevice8_SetStreamSource(device, 0, vertex_buffer, sizeof(*quad));
10212 ok(SUCCEEDED(hr), "SetStreamSource failed, hr %#x.\n", hr);
10213 hr = IDirect3DDevice8_SetIndices(device, index_buffer, 1);
10214 ok(SUCCEEDED(hr), "SetIndices failed, hr %#x.\n", hr);
10216 hr = IDirect3DDevice8_BeginStateBlock(device);
10217 ok(SUCCEEDED(hr), "BeginStateBlock failed, hr %#x.\n", hr);
10219 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0, 4, 2,
10220 indices, D3DFMT_INDEX16, quad, sizeof(*quad));
10221 ok(SUCCEEDED(hr), "DrawIndexedPrimitiveUP failed, hr %#x.\n", hr);
10223 hr = IDirect3DDevice8_EndStateBlock(device, &stateblock);
10224 ok(SUCCEEDED(hr), "BeginStateBlock failed, hr %#x.\n", hr);
10226 hr = IDirect3DDevice8_GetStreamSource(device, 0, &current_vb, &stride);
10227 ok(SUCCEEDED(hr), "GetStreamSource failed, hr %#x.\n", hr);
10228 ok(!current_vb, "Unexpected vb %p.\n", current_vb);
10229 ok(!stride, "Unexpected stride %u.\n", stride);
10230 hr = IDirect3DDevice8_GetIndices(device, &current_ib, &base_vertex_index);
10231 ok(SUCCEEDED(hr), "GetIndices failed, hr %#x.\n", hr);
10232 ok(!current_ib, "Unexpected index buffer %p.\n", current_ib);
10233 ok(!base_vertex_index, "Unexpected base vertex index %u.\n", base_vertex_index);
10235 hr = IDirect3DDevice8_CaptureStateBlock(device, stateblock);
10236 ok(SUCCEEDED(hr), "Capture failed, hr %#x.\n", hr);
10238 hr = IDirect3DDevice8_SetStreamSource(device, 0, vertex_buffer, sizeof(*quad));
10239 ok(SUCCEEDED(hr), "SetStreamSource failed, hr %#x.\n", hr);
10240 hr = IDirect3DDevice8_SetIndices(device, index_buffer, 1);
10241 ok(SUCCEEDED(hr), "SetIndices failed, hr %#x.\n", hr);
10243 hr = IDirect3DDevice8_ApplyStateBlock(device, stateblock);
10244 ok(SUCCEEDED(hr), "Apply failed, hr %#x.\n", hr);
10246 hr = IDirect3DDevice8_GetStreamSource(device, 0, &current_vb, &stride);
10247 ok(SUCCEEDED(hr), "GetStreamSource failed, hr %#x.\n", hr);
10248 ok(current_vb == vertex_buffer, "Unexpected vb %p.\n", current_vb);
10249 ok(stride == sizeof(*quad), "Unexpected stride %u.\n", stride);
10250 IDirect3DVertexBuffer8_Release(current_vb);
10251 hr = IDirect3DDevice8_GetIndices(device, &current_ib, &base_vertex_index);
10252 ok(SUCCEEDED(hr), "GetIndices failed, hr %#x.\n", hr);
10253 ok(current_ib == index_buffer, "Unexpected index buffer %p.\n", current_ib);
10254 ok(base_vertex_index == 1, "Unexpected base vertex index %u.\n", base_vertex_index);
10255 IDirect3DIndexBuffer8_Release(current_ib);
10257 hr = IDirect3DDevice8_EndScene(device);
10258 ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
10260 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
10261 ok(SUCCEEDED(hr), "Present failed, hr %#x.\n", hr);
10263 IDirect3DDevice8_DeleteStateBlock(device, stateblock);
10264 IDirect3DVertexBuffer8_Release(vertex_buffer);
10265 IDirect3DIndexBuffer8_Release(index_buffer);
10266 refcount = IDirect3DDevice8_Release(device);
10267 ok(!refcount, "Device has %u references left.\n", refcount);
10268 IDirect3D8_Release(d3d);
10269 DestroyWindow(window);
10272 static void test_get_display_mode(void)
10274 static const DWORD creation_flags[] = {0, CREATE_DEVICE_FULLSCREEN};
10275 unsigned int adapter_idx, adapter_count, mode_idx, test_idx;
10276 RECT previous_monitor_rect;
10277 unsigned int width, height;
10278 IDirect3DDevice8 *device;
10279 MONITORINFO monitor_info;
10280 struct device_desc desc;
10281 D3DDISPLAYMODE mode;
10282 HMONITOR monitor;
10283 IDirect3D8 *d3d;
10284 ULONG refcount;
10285 HWND window;
10286 HRESULT hr;
10287 BOOL ret;
10289 window = create_window();
10290 d3d = Direct3DCreate8(D3D_SDK_VERSION);
10291 ok(!!d3d, "Failed to create a D3D object.\n");
10293 if (!(device = create_device(d3d, window, NULL)))
10295 skip("Failed to create a D3D device.\n");
10296 IDirect3D8_Release(d3d);
10297 DestroyWindow(window);
10298 return;
10301 hr = IDirect3DDevice8_GetDisplayMode(device, &mode);
10302 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
10303 ok(mode.Format == D3DFMT_X8R8G8B8, "Unexpected format %#x.\n", mode.Format);
10304 hr = IDirect3D8_GetAdapterDisplayMode(d3d, D3DADAPTER_DEFAULT, &mode);
10305 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
10306 ok(mode.Format == D3DFMT_X8R8G8B8, "Unexpected format %#x.\n", mode.Format);
10308 refcount = IDirect3DDevice8_Release(device);
10309 ok(!refcount, "Device has %u references left.\n", refcount);
10311 desc.adapter_ordinal = D3DADAPTER_DEFAULT;
10312 desc.device_window = window;
10313 desc.width = 640;
10314 desc.height = 480;
10315 desc.flags = CREATE_DEVICE_FULLSCREEN;
10316 if (!(device = create_device(d3d, window, &desc)))
10318 skip("Failed to create a D3D device.\n");
10319 IDirect3D8_Release(d3d);
10320 DestroyWindow(window);
10321 return;
10324 hr = IDirect3DDevice8_GetDisplayMode(device, &mode);
10325 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
10326 ok(mode.Width == 640, "Unexpected width %u.\n", mode.Width);
10327 ok(mode.Height == 480, "Unexpected width %u.\n", mode.Height);
10328 ok(mode.Format == D3DFMT_X8R8G8B8, "Unexpected format %#x.\n", mode.Format);
10329 hr = IDirect3D8_GetAdapterDisplayMode(d3d, D3DADAPTER_DEFAULT, &mode);
10330 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
10331 ok(mode.Width == 640, "Unexpected width %u.\n", mode.Width);
10332 ok(mode.Height == 480, "Unexpected width %u.\n", mode.Height);
10333 ok(mode.Format == D3DFMT_X8R8G8B8, "Unexpected format %#x.\n", mode.Format);
10335 refcount = IDirect3DDevice8_Release(device);
10336 ok(!refcount, "Device has %u references left.\n", refcount);
10337 DestroyWindow(window);
10339 /* D3D8 uses adapter indices to determine which adapter to use to get the display mode */
10340 adapter_count = IDirect3D8_GetAdapterCount(d3d);
10341 for (adapter_idx = 0; adapter_idx < adapter_count; ++adapter_idx)
10343 if (!adapter_idx)
10345 desc.width = 640;
10346 desc.height = 480;
10348 else
10350 /* Find a mode different than that of the previous adapter, so that tests can be sure
10351 * that they are comparing to the current adapter display mode */
10352 monitor = IDirect3D8_GetAdapterMonitor(d3d, adapter_idx - 1);
10353 ok(!!monitor, "Adapter %u: GetAdapterMonitor failed.\n", adapter_idx - 1);
10354 monitor_info.cbSize = sizeof(monitor_info);
10355 ret = GetMonitorInfoW(monitor, &monitor_info);
10356 ok(ret, "Adapter %u: GetMonitorInfoW failed, error %#x.\n", adapter_idx - 1,
10357 GetLastError());
10358 previous_monitor_rect = monitor_info.rcMonitor;
10360 desc.width = monitor_info.rcMonitor.right - monitor_info.rcMonitor.left;
10361 desc.height = monitor_info.rcMonitor.bottom - monitor_info.rcMonitor.top;
10362 for (mode_idx = 0; SUCCEEDED(IDirect3D8_EnumAdapterModes(d3d, adapter_idx, mode_idx,
10363 &mode)); ++mode_idx)
10365 if (mode.Format != D3DFMT_X8R8G8B8)
10366 continue;
10367 if (mode.Width < 640 || mode.Height < 480)
10368 continue;
10369 if (mode.Width != desc.width && mode.Height != desc.height)
10370 break;
10372 ok(mode.Width != desc.width && mode.Height != desc.height,
10373 "Adapter %u: Failed to find a different mode than %ux%u.\n", adapter_idx,
10374 desc.width, desc.height);
10375 desc.width = mode.Width;
10376 desc.height = mode.Height;
10379 for (test_idx = 0; test_idx < ARRAY_SIZE(creation_flags); ++test_idx)
10381 window = create_window();
10382 desc.adapter_ordinal = adapter_idx;
10383 desc.device_window = window;
10384 desc.flags = creation_flags[test_idx];
10385 if (!(device = create_device(d3d, window, &desc)))
10387 skip("Adapter %u test %u: Failed to create a D3D device.\n", adapter_idx, test_idx);
10388 DestroyWindow(window);
10389 continue;
10392 monitor = IDirect3D8_GetAdapterMonitor(d3d, adapter_idx);
10393 ok(!!monitor, "Adapter %u test %u: GetAdapterMonitor failed.\n", adapter_idx, test_idx);
10394 monitor_info.cbSize = sizeof(monitor_info);
10395 ret = GetMonitorInfoW(monitor, &monitor_info);
10396 ok(ret, "Adapter %u test %u: GetMonitorInfoW failed, error %#x.\n", adapter_idx,
10397 test_idx, GetLastError());
10398 width = monitor_info.rcMonitor.right - monitor_info.rcMonitor.left;
10399 height = monitor_info.rcMonitor.bottom - monitor_info.rcMonitor.top;
10401 if (adapter_idx)
10403 /* Move the device window to the previous monitor to test that the device window
10404 * position doesn't affect which adapter to use to get the display mode */
10405 ret = SetWindowPos(window, 0, previous_monitor_rect.left, previous_monitor_rect.top,
10406 0, 0, SWP_NOZORDER | SWP_NOSIZE);
10407 ok(ret, "Adapter %u test %u: SetWindowPos failed, error %#x.\n", adapter_idx,
10408 test_idx, GetLastError());
10411 hr = IDirect3D8_GetAdapterDisplayMode(d3d, adapter_idx, &mode);
10412 ok(hr == D3D_OK, "Adapter %u test %u: GetAdapterDisplayMode failed, hr %#x.\n",
10413 adapter_idx, test_idx, hr);
10414 ok(mode.Width == width, "Adapter %u test %u: Expect width %u, got %u.\n", adapter_idx,
10415 test_idx, width, mode.Width);
10416 ok(mode.Height == height, "Adapter %u test %u: Expect height %u, got %u.\n",
10417 adapter_idx, test_idx, height, mode.Height);
10419 hr = IDirect3DDevice8_GetDisplayMode(device, &mode);
10420 ok(hr == D3D_OK, "Adapter %u test %u: GetDisplayMode failed, hr %#x.\n", adapter_idx,
10421 test_idx, hr);
10422 ok(mode.Width == width, "Adapter %u test %u: Expect width %u, got %u.\n", adapter_idx,
10423 test_idx, width, mode.Width);
10424 ok(mode.Height == height, "Adapter %u test %u: Expect height %u, got %u.\n",
10425 adapter_idx, test_idx, height, mode.Height);
10427 refcount = IDirect3DDevice8_Release(device);
10428 ok(!refcount, "Adapter %u test %u: Device has %u references left.\n", adapter_idx,
10429 test_idx, refcount);
10430 DestroyWindow(window);
10434 IDirect3D8_Release(d3d);
10437 static void test_multi_adapter(void)
10439 unsigned int i, adapter_count, expected_adapter_count = 0;
10440 DISPLAY_DEVICEA display_device;
10441 MONITORINFOEXA monitor_info;
10442 DEVMODEA old_mode, mode;
10443 HMONITOR monitor;
10444 IDirect3D8 *d3d;
10445 LONG ret;
10447 d3d = Direct3DCreate8(D3D_SDK_VERSION);
10448 ok(!!d3d, "Failed to create a D3D object.\n");
10450 display_device.cb = sizeof(display_device);
10451 for (i = 0; EnumDisplayDevicesA(NULL, i, &display_device, 0); ++i)
10453 if (display_device.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)
10454 ++expected_adapter_count;
10457 adapter_count = IDirect3D8_GetAdapterCount(d3d);
10458 ok(adapter_count == expected_adapter_count, "Got unexpected adapter count %u, expected %u.\n",
10459 adapter_count, expected_adapter_count);
10461 for (i = 0; i < adapter_count; ++i)
10463 monitor = IDirect3D8_GetAdapterMonitor(d3d, i);
10464 ok(!!monitor, "Adapter %u: Failed to get monitor.\n", i);
10466 monitor_info.cbSize = sizeof(monitor_info);
10467 ret = GetMonitorInfoA(monitor, (MONITORINFO *)&monitor_info);
10468 ok(ret, "Adapter %u: Failed to get monitor info, error %#x.\n", i, GetLastError());
10470 if (!i)
10471 ok(monitor_info.dwFlags == MONITORINFOF_PRIMARY,
10472 "Adapter %u: Got unexpected monitor flags %#x.\n", i, monitor_info.dwFlags);
10473 else
10474 ok(!monitor_info.dwFlags, "Adapter %u: Got unexpected monitor flags %#x.\n", i,
10475 monitor_info.dwFlags);
10477 /* Test D3D adapters after they got detached */
10478 if (monitor_info.dwFlags == MONITORINFOF_PRIMARY)
10479 continue;
10481 /* Save current display settings */
10482 memset(&old_mode, 0, sizeof(old_mode));
10483 old_mode.dmSize = sizeof(old_mode);
10484 ret = EnumDisplaySettingsA(monitor_info.szDevice, ENUM_CURRENT_SETTINGS, &old_mode);
10485 /* Win10 TestBots may return FALSE but it's actually successful */
10486 ok(ret || broken(!ret), "Adapter %u: EnumDisplaySettingsA failed for %s, error %#x.\n", i,
10487 monitor_info.szDevice, GetLastError());
10489 /* Detach */
10490 memset(&mode, 0, sizeof(mode));
10491 mode.dmSize = sizeof(mode);
10492 mode.dmFields = DM_POSITION | DM_PELSWIDTH | DM_PELSHEIGHT;
10493 mode.dmPosition = old_mode.dmPosition;
10494 ret = ChangeDisplaySettingsExA(monitor_info.szDevice, &mode, NULL,
10495 CDS_UPDATEREGISTRY | CDS_NORESET, NULL);
10496 ok(ret == DISP_CHANGE_SUCCESSFUL,
10497 "Adapter %u: ChangeDisplaySettingsExA %s returned unexpected %d.\n", i,
10498 monitor_info.szDevice, ret);
10499 ret = ChangeDisplaySettingsExA(monitor_info.szDevice, NULL, NULL, 0, NULL);
10500 ok(ret == DISP_CHANGE_SUCCESSFUL,
10501 "Adapter %u: ChangeDisplaySettingsExA %s returned unexpected %d.\n", i,
10502 monitor_info.szDevice, ret);
10504 /* Check if it is really detached */
10505 memset(&mode, 0, sizeof(mode));
10506 mode.dmSize = sizeof(mode);
10507 ret = EnumDisplaySettingsA(monitor_info.szDevice, ENUM_CURRENT_SETTINGS, &mode);
10508 /* Win10 TestBots may return FALSE but it's actually successful */
10509 ok(ret || broken(!ret) , "Adapter %u: EnumDisplaySettingsA failed for %s, error %#x.\n", i,
10510 monitor_info.szDevice, GetLastError());
10511 if (mode.dmPelsWidth && mode.dmPelsHeight)
10513 skip("Adapter %u: Failed to detach device %s.\n", i, monitor_info.szDevice);
10514 continue;
10517 /* Detaching adapter shouldn't reduce the adapter count */
10518 expected_adapter_count = adapter_count;
10519 adapter_count = IDirect3D8_GetAdapterCount(d3d);
10520 ok(adapter_count == expected_adapter_count,
10521 "Adapter %u: Got unexpected adapter count %u, expected %u.\n", i, adapter_count,
10522 expected_adapter_count);
10524 monitor = IDirect3D8_GetAdapterMonitor(d3d, i);
10525 ok(!monitor, "Adapter %u: Expect monitor to be NULL.\n", i);
10527 /* Restore settings */
10528 ret = ChangeDisplaySettingsExA(monitor_info.szDevice, &old_mode, NULL,
10529 CDS_UPDATEREGISTRY | CDS_NORESET, NULL);
10530 ok(ret == DISP_CHANGE_SUCCESSFUL,
10531 "Adapter %u: ChangeDisplaySettingsExA %s returned unexpected %d.\n", i,
10532 monitor_info.szDevice, ret);
10533 ret = ChangeDisplaySettingsExA(monitor_info.szDevice, NULL, NULL, 0, NULL);
10534 ok(ret == DISP_CHANGE_SUCCESSFUL,
10535 "Adapter %u: ChangeDisplaySettingsExA %s returned unexpected %d.\n", i,
10536 monitor_info.szDevice, ret);
10539 IDirect3D8_Release(d3d);
10542 static void test_creation_parameters(void)
10544 unsigned int adapter_idx, adapter_count;
10545 D3DDEVICE_CREATION_PARAMETERS params;
10546 struct device_desc device_desc;
10547 IDirect3DDevice8 *device;
10548 IDirect3D8 *d3d;
10549 HWND window;
10550 HRESULT hr;
10552 window = create_window();
10553 ok(!!window, "Failed to create a window.\n");
10554 d3d = Direct3DCreate8(D3D_SDK_VERSION);
10555 ok(!!d3d, "Failed to create a D3D object.\n");
10557 device_desc.device_window = window;
10558 device_desc.width = 640;
10559 device_desc.height = 480;
10560 device_desc.flags = 0;
10562 adapter_count = IDirect3D8_GetAdapterCount(d3d);
10563 for (adapter_idx = 0; adapter_idx < adapter_count; ++adapter_idx)
10565 device_desc.adapter_ordinal = adapter_idx;
10566 if (!(device = create_device(d3d, window, &device_desc)))
10568 skip("Adapter %u: Failed to create a D3D device.\n", adapter_idx);
10569 break;
10572 memset(&params, 0, sizeof(params));
10573 hr = IDirect3DDevice8_GetCreationParameters(device, &params);
10574 ok(hr == D3D_OK, "Adapter %u: GetCreationParameters failed, hr %#x.\n", adapter_idx, hr);
10575 ok(params.AdapterOrdinal == adapter_idx, "Adapter %u: Got unexpected adapter ordinal %u.\n",
10576 adapter_idx, params.AdapterOrdinal);
10577 ok(params.DeviceType == D3DDEVTYPE_HAL, "Adapter %u: Expect device type %#x, got %#x.\n",
10578 adapter_idx, D3DDEVTYPE_HAL, params.DeviceType);
10579 ok(params.hFocusWindow == window, "Adapter %u: Expect focus window %p, got %p.\n",
10580 adapter_idx, window, params.hFocusWindow);
10582 IDirect3DDevice8_Release(device);
10585 IDirect3D8_Release(d3d);
10586 DestroyWindow(window);
10589 static void test_cursor_clipping(void)
10591 unsigned int adapter_idx, adapter_count, mode_idx;
10592 D3DDISPLAYMODE mode, current_mode;
10593 struct device_desc device_desc;
10594 RECT virtual_rect, clip_rect;
10595 IDirect3DDevice8 *device;
10596 IDirect3D8 *d3d;
10597 HWND window;
10598 HRESULT hr;
10599 BOOL ret;
10601 window = create_window();
10602 ok(!!window, "Failed to create a window.\n");
10603 d3d = Direct3DCreate8(D3D_SDK_VERSION);
10604 ok(!!d3d, "Failed to create a D3D object.\n");
10606 device_desc.device_window = window;
10607 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
10609 adapter_count = IDirect3D8_GetAdapterCount(d3d);
10610 for (adapter_idx = 0; adapter_idx < adapter_count; ++adapter_idx)
10612 hr = IDirect3D8_GetAdapterDisplayMode(d3d, adapter_idx, &current_mode);
10613 ok(hr == D3D_OK, "Adapter %u: GetAdapterDisplayMode failed, hr %#x.\n", adapter_idx, hr);
10614 for (mode_idx = 0; SUCCEEDED(IDirect3D8_EnumAdapterModes(d3d, adapter_idx, mode_idx, &mode));
10615 ++mode_idx)
10617 if (mode.Format != D3DFMT_X8R8G8B8)
10618 continue;
10619 if (mode.Width < 640 || mode.Height < 480)
10620 continue;
10621 if (mode.Width != current_mode.Width && mode.Height != current_mode.Height)
10622 break;
10624 ok(mode.Width != current_mode.Width && mode.Height != current_mode.Height,
10625 "Adapter %u: Failed to find a different mode than %ux%u.\n", adapter_idx,
10626 current_mode.Width, current_mode.Height);
10628 ret = ClipCursor(NULL);
10629 ok(ret, "Adapter %u: ClipCursor failed, error %#x.\n", adapter_idx,
10630 GetLastError());
10631 get_virtual_rect(&virtual_rect);
10632 ret = GetClipCursor(&clip_rect);
10633 ok(ret, "Adapter %u: GetClipCursor failed, error %#x.\n", adapter_idx,
10634 GetLastError());
10635 ok(EqualRect(&clip_rect, &virtual_rect), "Adapter %u: Expect clip rect %s, got %s.\n",
10636 adapter_idx, wine_dbgstr_rect(&virtual_rect), wine_dbgstr_rect(&clip_rect));
10638 device_desc.adapter_ordinal = adapter_idx;
10639 device_desc.width = mode.Width;
10640 device_desc.height = mode.Height;
10641 if (!(device = create_device(d3d, window, &device_desc)))
10643 skip("Adapter %u: Failed to create a D3D device.\n", adapter_idx);
10644 break;
10646 flush_events();
10647 get_virtual_rect(&virtual_rect);
10648 ret = GetClipCursor(&clip_rect);
10649 ok(ret, "Adapter %u: GetClipCursor failed, error %#x.\n", adapter_idx,
10650 GetLastError());
10651 ok(EqualRect(&clip_rect, &virtual_rect), "Adapter %u: Expect clip rect %s, got %s.\n",
10652 adapter_idx, wine_dbgstr_rect(&virtual_rect), wine_dbgstr_rect(&clip_rect));
10654 IDirect3DDevice8_Release(device);
10655 flush_events();
10656 get_virtual_rect(&virtual_rect);
10657 ret = GetClipCursor(&clip_rect);
10658 ok(ret, "Adapter %u: GetClipCursor failed, error %#x.\n", adapter_idx,
10659 GetLastError());
10660 ok(EqualRect(&clip_rect, &virtual_rect), "Adapter %u: Expect clip rect %s, got %s.\n",
10661 adapter_idx, wine_dbgstr_rect(&virtual_rect), wine_dbgstr_rect(&clip_rect));
10664 IDirect3D8_Release(d3d);
10665 DestroyWindow(window);
10668 static void test_window_position(void)
10670 unsigned int adapter_idx, adapter_count;
10671 struct device_desc device_desc;
10672 IDirect3DDevice8 *device;
10673 MONITORINFO monitor_info;
10674 HMONITOR monitor;
10675 RECT window_rect;
10676 IDirect3D8 *d3d;
10677 HWND window;
10678 HRESULT hr;
10679 BOOL ret;
10681 d3d = Direct3DCreate8(D3D_SDK_VERSION);
10682 ok(!!d3d, "Failed to create a D3D object.\n");
10684 adapter_count = IDirect3D8_GetAdapterCount(d3d);
10685 for (adapter_idx = 0; adapter_idx < adapter_count; ++adapter_idx)
10687 monitor = IDirect3D8_GetAdapterMonitor(d3d, adapter_idx);
10688 ok(!!monitor, "Adapter %u: GetAdapterMonitor failed.\n", adapter_idx);
10689 monitor_info.cbSize = sizeof(monitor_info);
10690 ret = GetMonitorInfoW(monitor, &monitor_info);
10691 ok(ret, "Adapter %u: GetMonitorInfoW failed, error %#x.\n", adapter_idx, GetLastError());
10693 window = create_window();
10694 device_desc.adapter_ordinal = adapter_idx;
10695 device_desc.device_window = window;
10696 device_desc.width = monitor_info.rcMonitor.right - monitor_info.rcMonitor.left;
10697 device_desc.height = monitor_info.rcMonitor.bottom - monitor_info.rcMonitor.top;
10698 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
10699 if (!(device = create_device(d3d, window, &device_desc)))
10701 skip("Adapter %u: Failed to create a D3D device, skipping tests.\n", adapter_idx);
10702 DestroyWindow(window);
10703 continue;
10705 flush_events();
10706 ret = GetWindowRect(window, &window_rect);
10707 ok(ret, "Adapter %u: GetWindowRect failed, error %#x.\n", adapter_idx, GetLastError());
10708 ok(EqualRect(&window_rect, &monitor_info.rcMonitor),
10709 "Adapter %u: Expect window rect %s, got %s.\n", adapter_idx,
10710 wine_dbgstr_rect(&monitor_info.rcMonitor), wine_dbgstr_rect(&window_rect));
10712 /* Device resets should restore the window rectangle to fit the whole monitor */
10713 ret = SetWindowPos(window, 0, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
10714 ok(ret, "Adapter %u: SetWindowPos failed, error %#x.\n", adapter_idx, GetLastError());
10715 hr = reset_device(device, &device_desc);
10716 ok(hr == D3D_OK, "Adapter %u: Failed to reset device, hr %#x.\n", adapter_idx, hr);
10717 flush_events();
10718 ret = GetWindowRect(window, &window_rect);
10719 ok(ret, "Adapter %u: GetWindowRect failed, error %#x.\n", adapter_idx, GetLastError());
10720 ok(EqualRect(&window_rect, &monitor_info.rcMonitor),
10721 "Adapter %u: Expect window rect %s, got %s.\n", adapter_idx,
10722 wine_dbgstr_rect(&monitor_info.rcMonitor), wine_dbgstr_rect(&window_rect));
10724 /* Window activation should restore the window rectangle to fit the whole monitor */
10725 ret = SetWindowPos(window, 0, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
10726 ok(ret, "Adapter %u: SetWindowPos failed, error %#x.\n", adapter_idx, GetLastError());
10727 ret = SetForegroundWindow(GetDesktopWindow());
10728 ok(ret, "Adapter %u: SetForegroundWindow failed, error %#x.\n", adapter_idx, GetLastError());
10729 flush_events();
10730 ret = ShowWindow(window, SW_RESTORE);
10731 ok(ret, "Adapter %u: Failed to restore window, error %#x.\n", adapter_idx, GetLastError());
10732 flush_events();
10733 ret = SetForegroundWindow(window);
10734 ok(ret, "Adapter %u: SetForegroundWindow failed, error %#x.\n", adapter_idx, GetLastError());
10735 flush_events();
10736 ret = GetWindowRect(window, &window_rect);
10737 ok(ret, "Adapter %u: GetWindowRect failed, error %#x.\n", adapter_idx, GetLastError());
10738 ok(EqualRect(&window_rect, &monitor_info.rcMonitor),
10739 "Adapter %u: Expect window rect %s, got %s.\n", adapter_idx,
10740 wine_dbgstr_rect(&monitor_info.rcMonitor), wine_dbgstr_rect(&window_rect));
10742 IDirect3DDevice8_Release(device);
10743 DestroyWindow(window);
10746 IDirect3D8_Release(d3d);
10749 START_TEST(device)
10751 HMODULE d3d8_handle = GetModuleHandleA("d3d8.dll");
10752 WNDCLASSA wc = {0};
10753 IDirect3D8 *d3d8;
10754 DEVMODEW current_mode;
10756 if (!d3d8_handle)
10758 skip("Could not load d3d8.dll\n");
10759 return;
10762 memset(&current_mode, 0, sizeof(current_mode));
10763 current_mode.dmSize = sizeof(current_mode);
10764 ok(EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &current_mode), "Failed to get display mode.\n");
10765 registry_mode.dmSize = sizeof(registry_mode);
10766 ok(EnumDisplaySettingsW(NULL, ENUM_REGISTRY_SETTINGS, &registry_mode), "Failed to get display mode.\n");
10767 if (current_mode.dmPelsWidth != registry_mode.dmPelsWidth
10768 || current_mode.dmPelsHeight != registry_mode.dmPelsHeight)
10770 skip("Current mode does not match registry mode, skipping test.\n");
10771 return;
10774 wc.lpfnWndProc = DefWindowProcA;
10775 wc.lpszClassName = "d3d8_test_wc";
10776 RegisterClassA(&wc);
10778 ValidateVertexShader = (void *)GetProcAddress(d3d8_handle, "ValidateVertexShader");
10779 ValidatePixelShader = (void *)GetProcAddress(d3d8_handle, "ValidatePixelShader");
10781 if (!(d3d8 = Direct3DCreate8(D3D_SDK_VERSION)))
10783 skip("could not create D3D8\n");
10784 return;
10786 IDirect3D8_Release(d3d8);
10788 test_fpu_setup();
10789 test_display_formats();
10790 test_display_modes();
10791 test_shader_versions();
10792 test_swapchain();
10793 test_refcount();
10794 test_mipmap_levels();
10795 test_checkdevicemultisampletype();
10796 test_invalid_multisample();
10797 test_cursor();
10798 test_cursor_pos();
10799 test_states();
10800 test_reset();
10801 test_scene();
10802 test_shader();
10803 test_limits();
10804 test_lights();
10805 test_set_stream_source();
10806 test_ApplyStateBlock();
10807 test_render_zero_triangles();
10808 test_depth_stencil_reset();
10809 test_wndproc();
10810 test_wndproc_windowed();
10811 test_depth_stencil_size();
10812 test_window_style();
10813 test_unsupported_shaders();
10814 test_mode_change();
10815 test_device_window_reset();
10816 test_reset_resources();
10817 depth_blit_test();
10818 test_set_rt_vp_scissor();
10819 test_validate_vs();
10820 test_validate_ps();
10821 test_volume_get_container();
10822 test_vb_lock_flags();
10823 test_texture_stage_states();
10824 test_cube_textures();
10825 test_get_set_texture();
10826 test_image_surface_pool();
10827 test_surface_get_container();
10828 test_lockrect_invalid();
10829 test_private_data();
10830 test_surface_dimensions();
10831 test_surface_format_null();
10832 test_surface_double_unlock();
10833 test_surface_blocks();
10834 test_set_palette();
10835 test_pinned_buffers();
10836 test_npot_textures();
10837 test_volume_locking();
10838 test_update_volumetexture();
10839 test_create_rt_ds_fail();
10840 test_volume_blocks();
10841 test_lockbox_invalid();
10842 test_pixel_format();
10843 test_begin_end_state_block();
10844 test_shader_constant_apply();
10845 test_resource_type();
10846 test_mipmap_lock();
10847 test_writeonly_resource();
10848 test_lost_device();
10849 test_resource_priority();
10850 test_swapchain_parameters();
10851 test_check_device_format();
10852 test_miptree_layout();
10853 test_render_target_device_mismatch();
10854 test_format_unknown();
10855 test_destroyed_window();
10856 test_lockable_backbuffer();
10857 test_clip_planes_limits();
10858 test_swapchain_multisample_reset();
10859 test_device_caps();
10860 test_get_info();
10861 test_resource_access();
10862 test_multiply_transform();
10863 test_draw_primitive();
10864 test_get_display_mode();
10865 test_multi_adapter();
10866 test_creation_parameters();
10867 test_cursor_clipping();
10868 test_window_position();
10870 UnregisterClassA("d3d8_test_wc", GetModuleHandleA(NULL));