d3d8: Do not set WINED3D_TEXTURE_CREATE_MAPPABLE for swapchain textures.
[wine.git] / dlls / d3d8 / tests / device.c
blob8495342c0d34f150d3f00016a0458af8fabb6a7c
1 /*
2 * Copyright (C) 2006 Vitaliy Margolen
3 * Copyright (C) 2006 Chris Robinson
4 * Copyright (C) 2006 Louis Lenders
5 * Copyright 2006-2007 Henri Verbeet
6 * Copyright 2006-2007, 2011-2013 Stefan Dösinger for CodeWeavers
7 * Copyright 2013 Henri Verbeet for CodeWeavers
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define WINVER 0x0602 /* for CURSOR_SUPPRESSED */
25 #include <stdlib.h>
26 #define COBJMACROS
27 #include <initguid.h>
28 #include <d3d8.h>
29 #include "wine/test.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 HWND device_window;
44 unsigned int width;
45 unsigned int height;
46 DWORD flags;
49 #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
50 #define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
52 static DEVMODEW registry_mode;
54 static HRESULT (WINAPI *ValidateVertexShader)(DWORD *, DWORD *, DWORD *, int, DWORD *);
55 static HRESULT (WINAPI *ValidatePixelShader)(DWORD *, DWORD *, int, DWORD *);
57 static BOOL (WINAPI *pGetCursorInfo)(PCURSORINFO);
59 static const DWORD simple_vs[] = {0xFFFE0101, /* vs_1_1 */
60 0x00000009, 0xC0010000, 0x90E40000, 0xA0E40000, /* dp4 oPos.x, v0, c0 */
61 0x00000009, 0xC0020000, 0x90E40000, 0xA0E40001, /* dp4 oPos.y, v0, c1 */
62 0x00000009, 0xC0040000, 0x90E40000, 0xA0E40002, /* dp4 oPos.z, v0, c2 */
63 0x00000009, 0xC0080000, 0x90E40000, 0xA0E40003, /* dp4 oPos.w, v0, c3 */
64 0x0000FFFF}; /* END */
65 static const DWORD simple_ps[] = {0xFFFF0101, /* ps_1_1 */
66 0x00000051, 0xA00F0001, 0x3F800000, 0x00000000, 0x00000000, 0x00000000, /* def c1 = 1.0, 0.0, 0.0, 0.0 */
67 0x00000042, 0xB00F0000, /* tex t0 */
68 0x00000008, 0x800F0000, 0xA0E40001, 0xA0E40000, /* dp3 r0, c1, c0 */
69 0x00000005, 0x800F0000, 0x90E40000, 0x80E40000, /* mul r0, v0, r0 */
70 0x00000005, 0x800F0000, 0xB0E40000, 0x80E40000, /* mul r0, t0, r0 */
71 0x0000FFFF}; /* END */
73 static int get_refcount(IUnknown *object)
75 IUnknown_AddRef( object );
76 return IUnknown_Release( object );
79 static HWND create_window(void)
81 RECT r = {0, 0, 640, 480};
83 AdjustWindowRect(&r, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
85 return CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
86 0, 0, r.right - r.left, r.bottom - r.top, NULL, NULL, NULL, NULL);
89 /* try to make sure pending X events have been processed before continuing */
90 static void flush_events(void)
92 MSG msg;
93 int diff = 200;
94 int min_timeout = 100;
95 DWORD time = GetTickCount() + diff;
97 while (diff > 0)
99 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
100 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
101 diff = time - GetTickCount();
105 static IDirect3DDevice8 *create_device(IDirect3D8 *d3d8, HWND focus_window, const struct device_desc *desc)
107 D3DPRESENT_PARAMETERS present_parameters = {0};
108 IDirect3DDevice8 *device;
109 DWORD behavior_flags = D3DCREATE_HARDWARE_VERTEXPROCESSING;
111 present_parameters.BackBufferWidth = 640;
112 present_parameters.BackBufferHeight = 480;
113 present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
114 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
115 present_parameters.hDeviceWindow = focus_window;
116 present_parameters.Windowed = TRUE;
117 present_parameters.EnableAutoDepthStencil = TRUE;
118 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
120 if (desc)
122 present_parameters.BackBufferWidth = desc->width;
123 present_parameters.BackBufferHeight = desc->height;
124 present_parameters.hDeviceWindow = desc->device_window;
125 present_parameters.Windowed = !(desc->flags & CREATE_DEVICE_FULLSCREEN);
126 if (desc->flags & CREATE_DEVICE_LOCKABLE_BACKBUFFER)
127 present_parameters.Flags |= D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
128 if (desc->flags & CREATE_DEVICE_SWVP_ONLY)
129 behavior_flags = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
130 if (desc->flags & CREATE_DEVICE_FPU_PRESERVE)
131 behavior_flags |= D3DCREATE_FPU_PRESERVE;
134 if (SUCCEEDED(IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, focus_window,
135 behavior_flags, &present_parameters, &device)))
136 return device;
138 present_parameters.AutoDepthStencilFormat = D3DFMT_D16;
139 if (SUCCEEDED(IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, focus_window,
140 behavior_flags, &present_parameters, &device)))
141 return device;
143 if (desc && desc->flags & CREATE_DEVICE_SWVP_ONLY)
144 return NULL;
145 behavior_flags ^= (D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_SOFTWARE_VERTEXPROCESSING);
147 if (SUCCEEDED(IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, focus_window,
148 behavior_flags, &present_parameters, &device)))
149 return device;
151 return NULL;
154 static HRESULT reset_device(IDirect3DDevice8 *device, const struct device_desc *desc)
156 D3DPRESENT_PARAMETERS present_parameters = {0};
158 present_parameters.BackBufferWidth = 640;
159 present_parameters.BackBufferHeight = 480;
160 present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
161 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
162 present_parameters.hDeviceWindow = NULL;
163 present_parameters.Windowed = TRUE;
164 present_parameters.EnableAutoDepthStencil = TRUE;
165 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
167 if (desc)
169 present_parameters.BackBufferWidth = desc->width;
170 present_parameters.BackBufferHeight = desc->height;
171 present_parameters.hDeviceWindow = desc->device_window;
172 present_parameters.Windowed = !(desc->flags & CREATE_DEVICE_FULLSCREEN);
175 return IDirect3DDevice8_Reset(device, &present_parameters);
178 #define CHECK_CALL(r,c,d,rc) \
179 if (SUCCEEDED(r)) {\
180 int tmp1 = get_refcount( (IUnknown *)d ); \
181 int rc_new = rc; \
182 ok(tmp1 == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, tmp1); \
183 } else {\
184 trace("%s failed: %#08x\n", c, r); \
187 #define CHECK_RELEASE(obj,d,rc) \
188 if (obj) { \
189 int tmp1, rc_new = rc; \
190 IUnknown_Release( (IUnknown*)obj ); \
191 tmp1 = get_refcount( (IUnknown *)d ); \
192 ok(tmp1 == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, tmp1); \
195 #define CHECK_REFCOUNT(obj,rc) \
197 int rc_new = rc; \
198 int count = get_refcount( (IUnknown *)obj ); \
199 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
202 #define CHECK_RELEASE_REFCOUNT(obj,rc) \
204 int rc_new = rc; \
205 int count = IUnknown_Release( (IUnknown *)obj ); \
206 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
209 #define CHECK_ADDREF_REFCOUNT(obj,rc) \
211 int rc_new = rc; \
212 int count = IUnknown_AddRef( (IUnknown *)obj ); \
213 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
216 #define CHECK_SURFACE_CONTAINER(obj,iid,expected) \
218 void *container_ptr = (void *)0x1337c0d3; \
219 hr = IDirect3DSurface8_GetContainer(obj, &iid, &container_ptr); \
220 ok(SUCCEEDED(hr) && container_ptr == expected, "GetContainer returned: hr %#08x, container_ptr %p. " \
221 "Expected hr %#08x, container_ptr %p\n", hr, container_ptr, S_OK, expected); \
222 if (container_ptr && container_ptr != (void *)0x1337c0d3) IUnknown_Release((IUnknown *)container_ptr); \
225 static void check_mipmap_levels(IDirect3DDevice8 *device, UINT width, UINT height, UINT count)
227 IDirect3DBaseTexture8* texture = NULL;
228 HRESULT hr = IDirect3DDevice8_CreateTexture( device, width, height, 0, 0,
229 D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, (IDirect3DTexture8**) &texture );
231 if (SUCCEEDED(hr)) {
232 DWORD levels = IDirect3DBaseTexture8_GetLevelCount(texture);
233 ok(levels == count, "Invalid level count. Expected %d got %u\n", count, levels);
234 } else
235 trace("CreateTexture failed: %#08x\n", hr);
237 if (texture) IDirect3DBaseTexture8_Release( texture );
240 static void test_mipmap_levels(void)
242 IDirect3DDevice8 *device;
243 IDirect3D8 *d3d;
244 ULONG refcount;
245 HWND window;
247 window = create_window();
248 ok(!!window, "Failed to create a window.\n");
249 d3d = Direct3DCreate8(D3D_SDK_VERSION);
250 ok(!!d3d, "Failed to create a D3D object.\n");
251 if (!(device = create_device(d3d, window, NULL)))
253 skip("Failed to create a 3D device, skipping test.\n");
254 goto cleanup;
257 check_mipmap_levels(device, 32, 32, 6);
258 check_mipmap_levels(device, 256, 1, 9);
259 check_mipmap_levels(device, 1, 256, 9);
260 check_mipmap_levels(device, 1, 1, 1);
262 refcount = IDirect3DDevice8_Release(device);
263 ok(!refcount, "Device has %u references left.\n", refcount);
264 cleanup:
265 IDirect3D8_Release(d3d);
266 DestroyWindow(window);
269 static void test_swapchain(void)
271 IDirect3DSwapChain8 *swapchain1;
272 IDirect3DSwapChain8 *swapchain2;
273 IDirect3DSwapChain8 *swapchain3;
274 IDirect3DSurface8 *backbuffer, *stereo_buffer;
275 D3DPRESENT_PARAMETERS d3dpp;
276 IDirect3DDevice8 *device;
277 IDirect3D8 *d3d;
278 ULONG refcount;
279 HWND window, window2;
280 HRESULT hr;
281 struct device_desc device_desc;
283 window = create_window();
284 ok(!!window, "Failed to create a window.\n");
285 window2 = create_window();
286 ok(!!window2, "Failed to create a window.\n");
287 d3d = Direct3DCreate8(D3D_SDK_VERSION);
288 ok(!!d3d, "Failed to create a D3D object.\n");
289 if (!(device = create_device(d3d, window, NULL)))
291 skip("Failed to create a 3D device, skipping test.\n");
292 goto cleanup;
295 backbuffer = (void *)0xdeadbeef;
296 /* IDirect3DDevice8::GetBackBuffer crashes if a NULL output pointer is passed. */
297 hr = IDirect3DDevice8_GetBackBuffer(device, 1, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
298 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
299 ok(!backbuffer, "The back buffer pointer is %p, expected NULL.\n", backbuffer);
301 hr = IDirect3DDevice8_GetBackBuffer(device, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
302 ok(SUCCEEDED(hr), "Failed to get back buffer, hr %#x.\n", hr);
303 IDirect3DSurface8_Release(backbuffer);
305 /* The back buffer type value is ignored. */
306 hr = IDirect3DDevice8_GetBackBuffer(device, 0, D3DBACKBUFFER_TYPE_LEFT, &stereo_buffer);
307 ok(SUCCEEDED(hr), "Failed to get the back buffer, hr %#x.\n", hr);
308 ok(stereo_buffer == backbuffer, "Expected left back buffer = %p, got %p.\n", backbuffer, stereo_buffer);
309 IDirect3DSurface8_Release(stereo_buffer);
310 hr = IDirect3DDevice8_GetBackBuffer(device, 0, D3DBACKBUFFER_TYPE_RIGHT, &stereo_buffer);
311 ok(SUCCEEDED(hr), "Failed to get the back buffer, hr %#x.\n", hr);
312 ok(stereo_buffer == backbuffer, "Expected right back buffer = %p, got %p.\n", backbuffer, stereo_buffer);
313 IDirect3DSurface8_Release(stereo_buffer);
314 hr = IDirect3DDevice8_GetBackBuffer(device, 0, (D3DBACKBUFFER_TYPE)0xdeadbeef, &stereo_buffer);
315 ok(SUCCEEDED(hr), "Failed to get the back buffer, hr %#x.\n", hr);
316 ok(stereo_buffer == backbuffer, "Expected unknown buffer = %p, got %p.\n", backbuffer, stereo_buffer);
317 IDirect3DSurface8_Release(stereo_buffer);
319 memset(&d3dpp, 0, sizeof(d3dpp));
320 d3dpp.Windowed = TRUE;
321 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
322 d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
324 /* Create a bunch of swapchains */
325 d3dpp.BackBufferCount = 0;
326 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain1);
327 ok(SUCCEEDED(hr), "Failed to create a swapchain (%#08x)\n", hr);
328 ok(d3dpp.BackBufferCount == 1, "The back buffer count in the presentparams struct is %d\n", d3dpp.BackBufferCount);
330 d3dpp.BackBufferCount = 1;
331 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain2);
332 ok(SUCCEEDED(hr), "Failed to create a swapchain (%#08x)\n", hr);
334 d3dpp.BackBufferCount = 2;
335 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain3);
336 ok(SUCCEEDED(hr), "Failed to create a swapchain (%#08x)\n", hr);
337 if(SUCCEEDED(hr)) {
338 /* Swapchain 3, created with backbuffercount 2 */
339 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 0, 0, NULL);
340 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
342 backbuffer = (void *) 0xdeadbeef;
343 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 0, 0, &backbuffer);
344 ok(SUCCEEDED(hr), "Failed to get the 1st back buffer (%#08x)\n", hr);
345 ok(backbuffer != NULL && backbuffer != (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer);
346 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
348 /* The back buffer type value is ignored. */
349 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 0, D3DBACKBUFFER_TYPE_LEFT, &stereo_buffer);
350 ok(SUCCEEDED(hr), "Failed to get the back buffer, hr %#x.\n", hr);
351 ok(stereo_buffer == backbuffer, "Expected left back buffer = %p, got %p.\n", backbuffer, stereo_buffer);
352 IDirect3DSurface8_Release(stereo_buffer);
353 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 0, D3DBACKBUFFER_TYPE_RIGHT, &stereo_buffer);
354 ok(SUCCEEDED(hr), "Failed to get the back buffer, hr %#x.\n", hr);
355 ok(stereo_buffer == backbuffer, "Expected right back buffer = %p, got %p.\n", backbuffer, stereo_buffer);
356 IDirect3DSurface8_Release(stereo_buffer);
357 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 0, (D3DBACKBUFFER_TYPE)0xdeadbeef, &stereo_buffer);
358 ok(SUCCEEDED(hr), "Failed to get the back buffer, hr %#x.\n", hr);
359 ok(stereo_buffer == backbuffer, "Expected unknown buffer = %p, got %p.\n", backbuffer, stereo_buffer);
360 IDirect3DSurface8_Release(stereo_buffer);
362 backbuffer = (void *) 0xdeadbeef;
363 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 1, 0, &backbuffer);
364 ok(SUCCEEDED(hr), "Failed to get the 2nd back buffer (%#08x)\n", hr);
365 ok(backbuffer != NULL && backbuffer != (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer);
366 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
368 backbuffer = (void *) 0xdeadbeef;
369 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 2, 0, &backbuffer);
370 ok(hr == D3DERR_INVALIDCALL, "GetBackBuffer returned %#08x\n", hr);
371 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
372 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
374 backbuffer = (void *) 0xdeadbeef;
375 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 3, 0, &backbuffer);
376 ok(FAILED(hr), "Failed to get the back buffer (%#08x)\n", hr);
377 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
378 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
381 /* Check the back buffers of the swapchains */
382 /* Swapchain 1, created with backbuffercount 0 */
383 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain1, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
384 ok(SUCCEEDED(hr), "Failed to get the back buffer (%#08x)\n", hr);
385 ok(backbuffer != NULL, "The back buffer is NULL (%#08x)\n", hr);
386 if(backbuffer) IDirect3DSurface8_Release(backbuffer);
388 backbuffer = (void *) 0xdeadbeef;
389 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain1, 1, 0, &backbuffer);
390 ok(FAILED(hr), "Failed to get the back buffer (%#08x)\n", hr);
391 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
392 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
394 /* Swapchain 2 - created with backbuffercount 1 */
395 backbuffer = (void *) 0xdeadbeef;
396 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain2, 0, 0, &backbuffer);
397 ok(SUCCEEDED(hr), "Failed to get the back buffer (%#08x)\n", hr);
398 ok(backbuffer != NULL && backbuffer != (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer);
399 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
401 backbuffer = (void *) 0xdeadbeef;
402 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain2, 1, 0, &backbuffer);
403 ok(hr == D3DERR_INVALIDCALL, "GetBackBuffer returned %#08x\n", hr);
404 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
405 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
407 backbuffer = (void *) 0xdeadbeef;
408 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain2, 2, 0, &backbuffer);
409 ok(FAILED(hr), "Failed to get the back buffer (%#08x)\n", hr);
410 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
411 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
413 IDirect3DSwapChain8_Release(swapchain3);
414 IDirect3DSwapChain8_Release(swapchain2);
415 IDirect3DSwapChain8_Release(swapchain1);
417 d3dpp.Windowed = FALSE;
418 d3dpp.hDeviceWindow = window;
419 d3dpp.BackBufferCount = 1;
420 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain1);
421 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x\n", hr);
422 d3dpp.hDeviceWindow = window2;
423 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain1);
424 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x\n", hr);
426 device_desc.width = registry_mode.dmPelsWidth;
427 device_desc.height = registry_mode.dmPelsHeight;
428 device_desc.device_window = window;
429 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
430 hr = reset_device(device, &device_desc);
431 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
433 d3dpp.hDeviceWindow = window;
434 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain1);
435 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x\n", hr);
436 d3dpp.hDeviceWindow = window2;
437 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain1);
438 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x\n", hr);
439 d3dpp.Windowed = TRUE;
440 d3dpp.hDeviceWindow = window;
441 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain1);
442 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x\n", hr);
443 d3dpp.hDeviceWindow = window2;
444 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain1);
445 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x\n", hr);
447 refcount = IDirect3DDevice8_Release(device);
448 ok(!refcount, "Device has %u references left.\n", refcount);
449 cleanup:
450 IDirect3D8_Release(d3d);
451 DestroyWindow(window2);
452 DestroyWindow(window);
455 static void test_refcount(void)
457 IDirect3DVertexBuffer8 *pVertexBuffer = NULL;
458 IDirect3DIndexBuffer8 *pIndexBuffer = NULL;
459 DWORD dVertexShader = -1;
460 DWORD dPixelShader = -1;
461 IDirect3DCubeTexture8 *pCubeTexture = NULL;
462 IDirect3DTexture8 *pTexture = NULL;
463 IDirect3DVolumeTexture8 *pVolumeTexture = NULL;
464 IDirect3DVolume8 *pVolumeLevel = NULL;
465 IDirect3DSurface8 *pStencilSurface = NULL;
466 IDirect3DSurface8 *pImageSurface = NULL;
467 IDirect3DSurface8 *pRenderTarget = NULL;
468 IDirect3DSurface8 *pRenderTarget2 = NULL;
469 IDirect3DSurface8 *pRenderTarget3 = NULL;
470 IDirect3DSurface8 *pTextureLevel = NULL;
471 IDirect3DSurface8 *pBackBuffer = NULL;
472 DWORD dStateBlock = -1;
473 IDirect3DSwapChain8 *pSwapChain = NULL;
474 D3DCAPS8 caps;
475 D3DPRESENT_PARAMETERS d3dpp;
476 IDirect3DDevice8 *device = NULL;
477 ULONG refcount = 0, tmp;
478 IDirect3D8 *d3d, *d3d2;
479 HWND window;
480 HRESULT hr;
482 DWORD decl[] =
484 D3DVSD_STREAM(0),
485 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
486 D3DVSD_REG(D3DVSDE_DIFFUSE, D3DVSDT_D3DCOLOR), /* D3DVSDE_DIFFUSE, Register v5 */
487 D3DVSD_END()
490 window = create_window();
491 ok(!!window, "Failed to create a window.\n");
492 d3d = Direct3DCreate8(D3D_SDK_VERSION);
493 ok(!!d3d, "Failed to create a D3D object.\n");
495 CHECK_REFCOUNT(d3d, 1);
497 if (!(device = create_device(d3d, window, NULL)))
499 skip("Failed to create a 3D device, skipping test.\n");
500 goto cleanup;
503 IDirect3DDevice8_GetDeviceCaps(device, &caps);
505 refcount = get_refcount((IUnknown *)device);
506 ok(refcount == 1, "Invalid device RefCount %d\n", refcount);
508 CHECK_REFCOUNT(d3d, 2);
510 hr = IDirect3DDevice8_GetDirect3D(device, &d3d2);
511 CHECK_CALL(hr, "GetDirect3D", device, refcount);
513 ok(d3d2 == d3d, "Expected IDirect3D8 pointers to be equal.\n");
514 CHECK_REFCOUNT(d3d, 3);
515 CHECK_RELEASE_REFCOUNT(d3d, 2);
518 * Check refcount of implicit surfaces. Findings:
519 * - the container is the device
520 * - they hold a reference to the device
521 * - they are created with a refcount of 0 (Get/Release returns original refcount)
522 * - they are not freed if refcount reaches 0.
523 * - the refcount is not forwarded to the container.
525 hr = IDirect3DDevice8_GetRenderTarget(device, &pRenderTarget);
526 CHECK_CALL(hr, "GetRenderTarget", device, ++refcount);
527 if (pRenderTarget)
529 CHECK_SURFACE_CONTAINER(pRenderTarget, IID_IDirect3DDevice8, device);
530 CHECK_REFCOUNT(pRenderTarget, 1);
532 CHECK_ADDREF_REFCOUNT(pRenderTarget, 2);
533 CHECK_REFCOUNT(device, refcount);
534 CHECK_RELEASE_REFCOUNT(pRenderTarget, 1);
535 CHECK_REFCOUNT(device, refcount);
537 hr = IDirect3DDevice8_GetRenderTarget(device, &pRenderTarget);
538 CHECK_CALL(hr, "GetRenderTarget", device, refcount);
539 CHECK_REFCOUNT(pRenderTarget, 2);
540 CHECK_RELEASE_REFCOUNT( pRenderTarget, 1);
541 CHECK_RELEASE_REFCOUNT( pRenderTarget, 0);
542 CHECK_REFCOUNT(device, --refcount);
544 /* The render target is released with the device, so AddRef with refcount=0 is fine here. */
545 CHECK_ADDREF_REFCOUNT(pRenderTarget, 1);
546 CHECK_REFCOUNT(device, ++refcount);
547 CHECK_RELEASE_REFCOUNT(pRenderTarget, 0);
548 CHECK_REFCOUNT(device, --refcount);
549 CHECK_RELEASE_REFCOUNT(pRenderTarget, 0);
550 CHECK_RELEASE_REFCOUNT(pRenderTarget, 0);
553 /* Render target and back buffer are identical. */
554 hr = IDirect3DDevice8_GetBackBuffer(device, 0, 0, &pBackBuffer);
555 CHECK_CALL(hr, "GetBackBuffer", device, ++refcount);
556 if (pBackBuffer)
558 CHECK_RELEASE_REFCOUNT(pBackBuffer, 0);
559 ok(pRenderTarget == pBackBuffer, "RenderTarget=%p and BackBuffer=%p should be the same.\n",
560 pRenderTarget, pBackBuffer);
561 CHECK_RELEASE_REFCOUNT(pBackBuffer, 0);
562 CHECK_RELEASE_REFCOUNT(pBackBuffer, 0);
563 pBackBuffer = NULL;
565 CHECK_REFCOUNT(device, --refcount);
567 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &pStencilSurface);
568 CHECK_CALL(hr, "GetDepthStencilSurface", device, ++refcount);
569 if (pStencilSurface)
571 CHECK_SURFACE_CONTAINER(pStencilSurface, IID_IDirect3DDevice8, device);
572 CHECK_REFCOUNT(pStencilSurface, 1);
574 CHECK_ADDREF_REFCOUNT(pStencilSurface, 2);
575 CHECK_REFCOUNT(device, refcount);
576 CHECK_RELEASE_REFCOUNT(pStencilSurface, 1);
577 CHECK_REFCOUNT(device, refcount);
579 CHECK_RELEASE_REFCOUNT( pStencilSurface, 0);
580 CHECK_REFCOUNT(device, --refcount);
582 /* The stencil surface is released with the device, so AddRef with refcount=0 is fine here. */
583 CHECK_ADDREF_REFCOUNT(pStencilSurface, 1);
584 CHECK_REFCOUNT(device, ++refcount);
585 CHECK_RELEASE_REFCOUNT(pStencilSurface, 0);
586 CHECK_REFCOUNT(device, --refcount);
587 CHECK_RELEASE_REFCOUNT(pStencilSurface, 0);
588 CHECK_RELEASE_REFCOUNT(pStencilSurface, 0);
589 pStencilSurface = NULL;
592 /* Buffers */
593 hr = IDirect3DDevice8_CreateIndexBuffer(device, 16, 0, D3DFMT_INDEX32, D3DPOOL_DEFAULT, &pIndexBuffer);
594 CHECK_CALL(hr, "CreateIndexBuffer", device, ++refcount);
595 if(pIndexBuffer)
597 tmp = get_refcount( (IUnknown *)pIndexBuffer );
599 hr = IDirect3DDevice8_SetIndices(device, pIndexBuffer, 0);
600 CHECK_CALL( hr, "SetIndices", pIndexBuffer, tmp);
601 hr = IDirect3DDevice8_SetIndices(device, NULL, 0);
602 CHECK_CALL( hr, "SetIndices", pIndexBuffer, tmp);
605 hr = IDirect3DDevice8_CreateVertexBuffer(device, 16, 0, D3DFVF_XYZ, D3DPOOL_DEFAULT, &pVertexBuffer);
606 CHECK_CALL(hr, "CreateVertexBuffer", device, ++refcount);
607 if(pVertexBuffer)
609 IDirect3DVertexBuffer8 *pVBuf = (void*)~0;
610 UINT stride = ~0;
612 tmp = get_refcount( (IUnknown *)pVertexBuffer );
614 hr = IDirect3DDevice8_SetStreamSource(device, 0, pVertexBuffer, 3 * sizeof(float));
615 CHECK_CALL( hr, "SetStreamSource", pVertexBuffer, tmp);
616 hr = IDirect3DDevice8_SetStreamSource(device, 0, NULL, 0);
617 CHECK_CALL( hr, "SetStreamSource", pVertexBuffer, tmp);
619 hr = IDirect3DDevice8_GetStreamSource(device, 0, &pVBuf, &stride);
620 ok(SUCCEEDED(hr), "GetStreamSource did not succeed with NULL stream!\n");
621 ok(pVBuf==NULL, "pVBuf not NULL (%p)!\n", pVBuf);
622 ok(stride==3*sizeof(float), "stride not 3 floats (got %u)!\n", stride);
625 /* Shaders */
626 hr = IDirect3DDevice8_CreateVertexShader(device, decl, simple_vs, &dVertexShader, 0);
627 CHECK_CALL(hr, "CreateVertexShader", device, refcount);
628 if (caps.PixelShaderVersion >= D3DPS_VERSION(1, 0))
630 hr = IDirect3DDevice8_CreatePixelShader(device, simple_ps, &dPixelShader);
631 CHECK_CALL(hr, "CreatePixelShader", device, refcount);
633 /* Textures */
634 hr = IDirect3DDevice8_CreateTexture(device, 32, 32, 3, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pTexture);
635 CHECK_CALL(hr, "CreateTexture", device, ++refcount);
636 if (pTexture)
638 tmp = get_refcount( (IUnknown *)pTexture );
640 /* SetTexture should not increase refcounts */
641 hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *) pTexture);
642 CHECK_CALL( hr, "SetTexture", pTexture, tmp);
643 hr = IDirect3DDevice8_SetTexture(device, 0, NULL);
644 CHECK_CALL( hr, "SetTexture", pTexture, tmp);
646 /* This should not increment device refcount */
647 hr = IDirect3DTexture8_GetSurfaceLevel( pTexture, 1, &pTextureLevel );
648 CHECK_CALL(hr, "GetSurfaceLevel", device, refcount);
649 /* But should increment texture's refcount */
650 CHECK_REFCOUNT( pTexture, tmp+1 );
651 /* Because the texture and surface refcount are identical */
652 if (pTextureLevel)
654 CHECK_REFCOUNT ( pTextureLevel, tmp+1 );
655 CHECK_ADDREF_REFCOUNT ( pTextureLevel, tmp+2 );
656 CHECK_REFCOUNT ( pTexture , tmp+2 );
657 CHECK_RELEASE_REFCOUNT( pTextureLevel, tmp+1 );
658 CHECK_REFCOUNT ( pTexture , tmp+1 );
659 CHECK_RELEASE_REFCOUNT( pTexture , tmp );
660 CHECK_REFCOUNT ( pTextureLevel, tmp );
663 if(caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP)
665 hr = IDirect3DDevice8_CreateCubeTexture(device, 32, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pCubeTexture);
666 CHECK_CALL(hr, "CreateCubeTexture", device, ++refcount);
668 else
670 skip("Cube textures not supported\n");
672 if(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP)
674 hr = IDirect3DDevice8_CreateVolumeTexture(device, 32, 32, 2, 0, 0,
675 D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pVolumeTexture);
676 CHECK_CALL(hr, "CreateVolumeTexture", device, ++refcount);
678 else
680 skip("Volume textures not supported\n");
683 if (pVolumeTexture)
685 tmp = get_refcount( (IUnknown *)pVolumeTexture );
687 /* This should not increment device refcount */
688 hr = IDirect3DVolumeTexture8_GetVolumeLevel(pVolumeTexture, 0, &pVolumeLevel);
689 CHECK_CALL(hr, "GetVolumeLevel", device, refcount);
690 /* But should increment volume texture's refcount */
691 CHECK_REFCOUNT( pVolumeTexture, tmp+1 );
692 /* Because the volume texture and volume refcount are identical */
693 if (pVolumeLevel)
695 CHECK_REFCOUNT ( pVolumeLevel , tmp+1 );
696 CHECK_ADDREF_REFCOUNT ( pVolumeLevel , tmp+2 );
697 CHECK_REFCOUNT ( pVolumeTexture, tmp+2 );
698 CHECK_RELEASE_REFCOUNT( pVolumeLevel , tmp+1 );
699 CHECK_REFCOUNT ( pVolumeTexture, tmp+1 );
700 CHECK_RELEASE_REFCOUNT( pVolumeTexture, tmp );
701 CHECK_REFCOUNT ( pVolumeLevel , tmp );
704 /* Surfaces */
705 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 32, 32,
706 D3DFMT_D16, D3DMULTISAMPLE_NONE, &pStencilSurface);
707 CHECK_CALL(hr, "CreateDepthStencilSurface", device, ++refcount);
708 CHECK_REFCOUNT( pStencilSurface, 1);
709 hr = IDirect3DDevice8_CreateImageSurface(device, 32, 32,
710 D3DFMT_X8R8G8B8, &pImageSurface);
711 CHECK_CALL(hr, "CreateImageSurface", device, ++refcount);
712 CHECK_REFCOUNT( pImageSurface, 1);
713 hr = IDirect3DDevice8_CreateRenderTarget(device, 32, 32,
714 D3DFMT_X8R8G8B8, D3DMULTISAMPLE_NONE, TRUE, &pRenderTarget3);
715 CHECK_CALL(hr, "CreateRenderTarget", device, ++refcount);
716 CHECK_REFCOUNT( pRenderTarget3, 1);
717 /* Misc */
718 hr = IDirect3DDevice8_CreateStateBlock(device, D3DSBT_ALL, &dStateBlock);
719 CHECK_CALL(hr, "CreateStateBlock", device, refcount);
721 memset(&d3dpp, 0, sizeof(d3dpp));
722 d3dpp.Windowed = TRUE;
723 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
724 d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
725 d3dpp.EnableAutoDepthStencil = TRUE;
726 d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
727 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &pSwapChain);
728 CHECK_CALL(hr, "CreateAdditionalSwapChain", device, ++refcount);
729 if(pSwapChain)
731 /* check implicit back buffer */
732 hr = IDirect3DSwapChain8_GetBackBuffer(pSwapChain, 0, 0, &pBackBuffer);
733 CHECK_CALL(hr, "GetBackBuffer", device, ++refcount);
734 CHECK_REFCOUNT( pSwapChain, 1);
735 if(pBackBuffer)
737 CHECK_SURFACE_CONTAINER(pBackBuffer, IID_IDirect3DDevice8, device);
738 CHECK_REFCOUNT( pBackBuffer, 1);
739 CHECK_RELEASE_REFCOUNT( pBackBuffer, 0);
740 CHECK_REFCOUNT(device, --refcount);
742 /* The back buffer is released with the swapchain, so AddRef with refcount=0 is fine here. */
743 CHECK_ADDREF_REFCOUNT(pBackBuffer, 1);
744 CHECK_REFCOUNT(device, ++refcount);
745 CHECK_RELEASE_REFCOUNT(pBackBuffer, 0);
746 CHECK_REFCOUNT(device, --refcount);
747 CHECK_RELEASE_REFCOUNT(pBackBuffer, 0);
748 CHECK_RELEASE_REFCOUNT(pBackBuffer, 0);
749 pBackBuffer = NULL;
751 CHECK_REFCOUNT( pSwapChain, 1);
754 if(pVertexBuffer)
756 BYTE *data;
757 /* Vertex buffers can be locked multiple times */
758 hr = IDirect3DVertexBuffer8_Lock(pVertexBuffer, 0, 0, &data, 0);
759 ok(hr == D3D_OK, "IDirect3DVertexBuffer8::Lock failed with %#08x\n", hr);
760 hr = IDirect3DVertexBuffer8_Lock(pVertexBuffer, 0, 0, &data, 0);
761 ok(hr == D3D_OK, "IDirect3DVertexBuffer8::Lock failed with %#08x\n", hr);
762 hr = IDirect3DVertexBuffer8_Unlock(pVertexBuffer);
763 ok(hr == D3D_OK, "IDirect3DVertexBuffer8::Unlock failed with %#08x\n", hr);
764 hr = IDirect3DVertexBuffer8_Unlock(pVertexBuffer);
765 ok(hr == D3D_OK, "IDirect3DVertexBuffer8::Unlock failed with %#08x\n", hr);
768 /* The implicit render target is not freed if refcount reaches 0.
769 * Otherwise GetRenderTarget would re-allocate it and the pointer would change.*/
770 hr = IDirect3DDevice8_GetRenderTarget(device, &pRenderTarget2);
771 CHECK_CALL(hr, "GetRenderTarget", device, ++refcount);
772 if (pRenderTarget2)
774 CHECK_RELEASE_REFCOUNT(pRenderTarget2, 0);
775 ok(pRenderTarget == pRenderTarget2, "RenderTarget=%p and RenderTarget2=%p should be the same.\n",
776 pRenderTarget, pRenderTarget2);
777 CHECK_REFCOUNT(device, --refcount);
778 CHECK_RELEASE_REFCOUNT(pRenderTarget2, 0);
779 CHECK_RELEASE_REFCOUNT(pRenderTarget2, 0);
780 pRenderTarget2 = NULL;
782 pRenderTarget = NULL;
784 cleanup:
785 CHECK_RELEASE(device, device, --refcount);
787 /* Buffers */
788 CHECK_RELEASE(pVertexBuffer, device, --refcount);
789 CHECK_RELEASE(pIndexBuffer, device, --refcount);
790 /* Shaders */
791 if (dVertexShader != ~0u)
792 IDirect3DDevice8_DeleteVertexShader(device, dVertexShader);
793 if (dPixelShader != ~0u)
794 IDirect3DDevice8_DeletePixelShader(device, dPixelShader);
795 /* Textures */
796 CHECK_RELEASE(pTexture, device, --refcount);
797 CHECK_RELEASE(pCubeTexture, device, --refcount);
798 CHECK_RELEASE(pVolumeTexture, device, --refcount);
799 /* Surfaces */
800 CHECK_RELEASE(pStencilSurface, device, --refcount);
801 CHECK_RELEASE(pImageSurface, device, --refcount);
802 CHECK_RELEASE(pRenderTarget3, device, --refcount);
803 /* Misc */
804 if (dStateBlock != ~0u)
805 IDirect3DDevice8_DeleteStateBlock(device, dStateBlock);
806 /* This will destroy device - cannot check the refcount here */
807 if (pSwapChain)
808 CHECK_RELEASE_REFCOUNT(pSwapChain, 0);
809 CHECK_RELEASE_REFCOUNT(d3d, 0);
810 DestroyWindow(window);
813 static void test_checkdevicemultisampletype(void)
815 IDirect3D8 *d3d;
816 HWND window;
817 HRESULT hr;
819 window = create_window();
820 ok(!!window, "Failed to create a window.\n");
821 d3d = Direct3DCreate8(D3D_SDK_VERSION);
822 ok(!!d3d, "Failed to create a D3D object.\n");
824 if (IDirect3D8_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
825 D3DFMT_X8R8G8B8, TRUE, D3DMULTISAMPLE_2_SAMPLES) == D3DERR_NOTAVAILABLE)
827 skip("Multisampling not supported for D3DFMT_X8R8G8B8, skipping test.\n");
828 goto cleanup;
831 hr = IDirect3D8_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
832 D3DFMT_UNKNOWN, TRUE, D3DMULTISAMPLE_NONE);
833 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
834 hr = IDirect3D8_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
835 65536, TRUE, D3DMULTISAMPLE_NONE);
836 todo_wine ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
838 hr = IDirect3D8_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
839 D3DFMT_X8R8G8B8, TRUE, D3DMULTISAMPLE_NONE);
840 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
841 hr = IDirect3D8_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
842 D3DFMT_X8R8G8B8, FALSE, D3DMULTISAMPLE_NONE);
843 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
845 hr = IDirect3D8_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
846 D3DFMT_X8R8G8B8, TRUE, D3DMULTISAMPLE_2_SAMPLES);
847 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
849 /* We assume D3DMULTISAMPLE_15_SAMPLES is never supported in practice. */
850 hr = IDirect3D8_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
851 D3DFMT_X8R8G8B8, TRUE, D3DMULTISAMPLE_15_SAMPLES);
852 ok(hr == D3DERR_NOTAVAILABLE, "Got unexpected hr %#x.\n", hr);
854 hr = IDirect3D8_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
855 D3DFMT_X8R8G8B8, TRUE, 65536);
856 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
858 hr = IDirect3D8_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
859 D3DFMT_DXT5, TRUE, D3DMULTISAMPLE_2_SAMPLES);
860 ok(hr == D3DERR_NOTAVAILABLE, "Got unexpected hr %#x.\n", hr);
862 cleanup:
863 IDirect3D8_Release(d3d);
864 DestroyWindow(window);
867 static void test_invalid_multisample(void)
869 IDirect3DDevice8 *device;
870 IDirect3DSurface8 *rt;
871 IDirect3D8 *d3d;
872 BOOL available;
873 ULONG refcount;
874 HWND window;
875 HRESULT hr;
877 window = create_window();
878 ok(!!window, "Failed to create a window.\n");
879 d3d = Direct3DCreate8(D3D_SDK_VERSION);
880 ok(!!d3d, "Failed to create a D3D object.\n");
882 if (!(device = create_device(d3d, window, NULL)))
884 skip("Failed to create a 3D device, skipping test.\n");
885 goto cleanup;
888 available = SUCCEEDED(IDirect3D8_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
889 D3DFMT_X8R8G8B8, TRUE, D3DMULTISAMPLE_2_SAMPLES));
891 hr = IDirect3DDevice8_CreateRenderTarget(device, 128, 128,
892 D3DFMT_X8R8G8B8, D3DMULTISAMPLE_2_SAMPLES, FALSE, &rt);
893 if (available)
895 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
896 IDirect3DSurface8_Release(rt);
898 else
900 ok(hr == D3DERR_NOTAVAILABLE, "Got unexpected hr %#x.\n", hr);
903 /* We assume D3DMULTISAMPLE_15_SAMPLES is never supported in practice. */
904 available = SUCCEEDED(IDirect3D8_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
905 D3DFMT_X8R8G8B8, TRUE, D3DMULTISAMPLE_15_SAMPLES));
906 hr = IDirect3DDevice8_CreateRenderTarget(device, 128, 128,
907 D3DFMT_X8R8G8B8, D3DMULTISAMPLE_15_SAMPLES, FALSE, &rt);
908 if (available)
910 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
911 IDirect3DSurface8_Release(rt);
913 else
915 ok(hr == D3DERR_NOTAVAILABLE, "Got unexpected hr %#x.\n", hr);
918 refcount = IDirect3DDevice8_Release(device);
919 ok(!refcount, "Device has %u references left.\n", refcount);
920 cleanup:
921 IDirect3D8_Release(d3d);
922 DestroyWindow(window);
925 static void test_cursor(void)
927 HMODULE user32_handle = GetModuleHandleA("user32.dll");
928 IDirect3DSurface8 *cursor = NULL;
929 IDirect3DDevice8 *device;
930 CURSORINFO info;
931 IDirect3D8 *d3d;
932 ULONG refcount;
933 HCURSOR cur;
934 HWND window;
935 HRESULT hr;
936 BOOL ret;
938 pGetCursorInfo = (void *)GetProcAddress(user32_handle, "GetCursorInfo");
939 if (!pGetCursorInfo)
941 win_skip("GetCursorInfo is not available\n");
942 return;
945 window = create_window();
946 ok(!!window, "Failed to create a window.\n");
948 ret = SetCursorPos(50, 50);
949 ok(ret, "Failed to set cursor position.\n");
950 flush_events();
952 memset(&info, 0, sizeof(info));
953 info.cbSize = sizeof(info);
954 ok(pGetCursorInfo(&info), "GetCursorInfo failed\n");
955 cur = info.hCursor;
957 d3d = Direct3DCreate8(D3D_SDK_VERSION);
958 ok(!!d3d, "Failed to create a D3D object.\n");
959 if (!(device = create_device(d3d, window, NULL)))
961 skip("Failed to create a 3D device, skipping test.\n");
962 goto cleanup;
965 hr = IDirect3DDevice8_CreateImageSurface(device, 32, 32, D3DFMT_A8R8G8B8, &cursor);
966 ok(SUCCEEDED(hr), "Failed to create cursor surface, hr %#x.\n", hr);
968 /* Initially hidden */
969 ret = IDirect3DDevice8_ShowCursor(device, TRUE);
970 ok(!ret, "IDirect3DDevice8_ShowCursor returned %d\n", ret);
972 /* Not enabled without a surface*/
973 ret = IDirect3DDevice8_ShowCursor(device, TRUE);
974 ok(!ret, "IDirect3DDevice8_ShowCursor returned %d\n", ret);
976 /* Fails */
977 hr = IDirect3DDevice8_SetCursorProperties(device, 0, 0, NULL);
978 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_SetCursorProperties returned %#08x\n", hr);
980 hr = IDirect3DDevice8_SetCursorProperties(device, 0, 0, cursor);
981 ok(hr == D3D_OK, "IDirect3DDevice8_SetCursorProperties returned %#08x\n", hr);
983 IDirect3DSurface8_Release(cursor);
985 memset(&info, 0, sizeof(info));
986 info.cbSize = sizeof(info);
987 ok(pGetCursorInfo(&info), "GetCursorInfo failed\n");
988 ok(info.flags & (CURSOR_SHOWING|CURSOR_SUPPRESSED), "The gdi cursor is hidden (%08x)\n", info.flags);
989 ok(info.hCursor == cur, "The cursor handle is %p\n", info.hCursor); /* unchanged */
991 /* Still hidden */
992 ret = IDirect3DDevice8_ShowCursor(device, TRUE);
993 ok(!ret, "IDirect3DDevice8_ShowCursor returned %d\n", ret);
995 /* Enabled now*/
996 ret = IDirect3DDevice8_ShowCursor(device, TRUE);
997 ok(ret, "IDirect3DDevice8_ShowCursor returned %d\n", ret);
999 memset(&info, 0, sizeof(info));
1000 info.cbSize = sizeof(info);
1001 ok(pGetCursorInfo(&info), "GetCursorInfo failed\n");
1002 ok(info.flags & (CURSOR_SHOWING|CURSOR_SUPPRESSED), "The gdi cursor is hidden (%08x)\n", info.flags);
1003 ok(info.hCursor != cur, "The cursor handle is %p\n", info.hCursor);
1005 refcount = IDirect3DDevice8_Release(device);
1006 ok(!refcount, "Device has %u references left.\n", refcount);
1007 cleanup:
1008 IDirect3D8_Release(d3d);
1009 DestroyWindow(window);
1012 static const POINT *expect_pos;
1014 static LRESULT CALLBACK test_cursor_proc(HWND window, UINT message, WPARAM wparam, LPARAM lparam)
1016 if (message == WM_MOUSEMOVE)
1018 if (expect_pos && expect_pos->x && expect_pos->y)
1020 POINT p = {GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam)};
1022 ClientToScreen(window, &p);
1023 if (expect_pos->x == p.x && expect_pos->y == p.y)
1024 ++expect_pos;
1028 return DefWindowProcA(window, message, wparam, lparam);
1031 static void test_cursor_pos(void)
1033 IDirect3DSurface8 *cursor;
1034 IDirect3DDevice8 *device;
1035 WNDCLASSA wc = {0};
1036 IDirect3D8 *d3d8;
1037 UINT refcount;
1038 HWND window;
1039 HRESULT hr;
1040 BOOL ret;
1042 /* Note that we don't check for movement we're not supposed to receive.
1043 * That's because it's hard to distinguish from the user accidentally
1044 * moving the mouse. */
1045 static const POINT points[] =
1047 {50, 50},
1048 {75, 75},
1049 {100, 100},
1050 {125, 125},
1051 {150, 150},
1052 {125, 125},
1053 {150, 150},
1054 {150, 150},
1055 {0, 0},
1058 wc.lpfnWndProc = test_cursor_proc;
1059 wc.lpszClassName = "d3d8_test_cursor_wc";
1060 ok(RegisterClassA(&wc), "Failed to register window class.\n");
1061 window = CreateWindowA("d3d8_test_cursor_wc", "d3d8_test", WS_POPUP | WS_SYSMENU,
1062 0, 0, 320, 240, NULL, NULL, NULL, NULL);
1063 ShowWindow(window, SW_SHOW);
1064 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
1065 ok(!!d3d8, "Failed to create a D3D object.\n");
1067 if (!(device = create_device(d3d8, window, NULL)))
1069 skip("Failed to create a D3D device, skipping tests.\n");
1070 goto done;
1073 hr = IDirect3DDevice8_CreateImageSurface(device, 32, 32, D3DFMT_A8R8G8B8, &cursor);
1074 ok(SUCCEEDED(hr), "Failed to create cursor surface, hr %#x.\n", hr);
1075 hr = IDirect3DDevice8_SetCursorProperties(device, 0, 0, cursor);
1076 ok(SUCCEEDED(hr), "Failed to set cursor properties, hr %#x.\n", hr);
1077 IDirect3DSurface8_Release(cursor);
1078 ret = IDirect3DDevice8_ShowCursor(device, TRUE);
1079 ok(!ret, "Failed to show cursor, hr %#x.\n", ret);
1081 flush_events();
1082 expect_pos = points;
1084 ret = SetCursorPos(50, 50);
1085 ok(ret, "Failed to set cursor position.\n");
1086 flush_events();
1088 IDirect3DDevice8_SetCursorPosition(device, 75, 75, 0);
1089 flush_events();
1090 /* SetCursorPosition() eats duplicates. */
1091 IDirect3DDevice8_SetCursorPosition(device, 75, 75, 0);
1092 flush_events();
1094 ret = SetCursorPos(100, 100);
1095 ok(ret, "Failed to set cursor position.\n");
1096 flush_events();
1097 /* Even if the position was set with SetCursorPos(). */
1098 IDirect3DDevice8_SetCursorPosition(device, 100, 100, 0);
1099 flush_events();
1101 IDirect3DDevice8_SetCursorPosition(device, 125, 125, 0);
1102 flush_events();
1103 ret = SetCursorPos(150, 150);
1104 ok(ret, "Failed to set cursor position.\n");
1105 flush_events();
1106 IDirect3DDevice8_SetCursorPosition(device, 125, 125, 0);
1107 flush_events();
1109 IDirect3DDevice8_SetCursorPosition(device, 150, 150, 0);
1110 flush_events();
1111 /* SetCursorPos() doesn't. */
1112 ret = SetCursorPos(150, 150);
1113 ok(ret, "Failed to set cursor position.\n");
1114 flush_events();
1116 ok(!expect_pos->x && !expect_pos->y, "Didn't receive MOUSEMOVE %u (%d, %d).\n",
1117 (unsigned)(expect_pos - points), expect_pos->x, expect_pos->y);
1119 refcount = IDirect3DDevice8_Release(device);
1120 ok(!refcount, "Device has %u references left.\n", refcount);
1121 done:
1122 DestroyWindow(window);
1123 UnregisterClassA("d3d8_test_cursor_wc", GetModuleHandleA(NULL));
1124 IDirect3D8_Release(d3d8);
1127 static void test_states(void)
1129 IDirect3DDevice8 *device;
1130 IDirect3D8 *d3d;
1131 ULONG refcount;
1132 HWND window;
1133 HRESULT hr;
1135 window = create_window();
1136 ok(!!window, "Failed to create a window.\n");
1137 d3d = Direct3DCreate8(D3D_SDK_VERSION);
1138 ok(!!d3d, "Failed to create a D3D object.\n");
1139 if (!(device = create_device(d3d, window, NULL)))
1141 skip("Failed to create a 3D device, skipping test.\n");
1142 goto cleanup;
1145 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZVISIBLE, TRUE);
1146 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState(D3DRS_ZVISIBLE, TRUE) returned %#08x\n", hr);
1147 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZVISIBLE, FALSE);
1148 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState(D3DRS_ZVISIBLE, FALSE) returned %#08x\n", hr);
1150 refcount = IDirect3DDevice8_Release(device);
1151 ok(!refcount, "Device has %u references left.\n", refcount);
1152 cleanup:
1153 IDirect3D8_Release(d3d);
1154 DestroyWindow(window);
1157 static void test_shader_versions(void)
1159 IDirect3D8 *d3d;
1160 D3DCAPS8 caps;
1161 HRESULT hr;
1163 d3d = Direct3DCreate8(D3D_SDK_VERSION);
1164 ok(!!d3d, "Failed to create a D3D object.\n");
1166 hr = IDirect3D8_GetDeviceCaps(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps);
1167 ok(SUCCEEDED(hr) || hr == D3DERR_NOTAVAILABLE, "Failed to get device caps, hr %#x.\n", hr);
1168 IDirect3D8_Release(d3d);
1169 if (FAILED(hr))
1171 skip("No Direct3D support, skipping test.\n");
1172 return;
1175 ok(caps.VertexShaderVersion <= D3DVS_VERSION(1,1),
1176 "Got unexpected VertexShaderVersion %#x.\n", caps.VertexShaderVersion);
1177 ok(caps.PixelShaderVersion <= D3DPS_VERSION(1,4),
1178 "Got unexpected PixelShaderVersion %#x.\n", caps.PixelShaderVersion);
1181 static void test_display_formats(void)
1183 D3DDEVTYPE device_type = D3DDEVTYPE_HAL;
1184 unsigned int backbuffer, display;
1185 unsigned int windowed, i;
1186 D3DDISPLAYMODE mode;
1187 IDirect3D8 *d3d8;
1188 BOOL should_pass;
1189 BOOL has_modes;
1190 HRESULT hr;
1192 static const struct
1194 const char *name;
1195 D3DFORMAT format;
1196 D3DFORMAT alpha_format;
1197 BOOL display;
1198 BOOL windowed;
1200 formats[] =
1202 {"D3DFMT_R5G6B5", D3DFMT_R5G6B5, 0, TRUE, TRUE},
1203 {"D3DFMT_X1R5G5B5", D3DFMT_X1R5G5B5, D3DFMT_A1R5G5B5, TRUE, TRUE},
1204 {"D3DFMT_A1R5G5B5", D3DFMT_A1R5G5B5, D3DFMT_A1R5G5B5, FALSE, FALSE},
1205 {"D3DFMT_X8R8G8B8", D3DFMT_X8R8G8B8, D3DFMT_A8R8G8B8, TRUE, TRUE},
1206 {"D3DFMT_A8R8G8B8", D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, FALSE, FALSE},
1207 {"D3DFMT_UNKNOWN", D3DFMT_UNKNOWN, 0, FALSE, FALSE},
1210 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
1211 ok(!!d3d8, "Failed to create a D3D object.\n");
1213 for (display = 0; display < ARRAY_SIZE(formats); ++display)
1215 for (i = 0, has_modes = FALSE; SUCCEEDED(IDirect3D8_EnumAdapterModes(d3d8, D3DADAPTER_DEFAULT, i, &mode)); ++i)
1217 if (mode.Format == formats[display].format)
1219 has_modes = TRUE;
1220 break;
1224 for (windowed = 0; windowed <= 1; ++windowed)
1226 for (backbuffer = 0; backbuffer < ARRAY_SIZE(formats); ++backbuffer)
1228 should_pass = FALSE;
1230 if (formats[display].display && (formats[display].windowed || !windowed) && (has_modes || windowed))
1232 D3DFORMAT backbuffer_format;
1234 if (windowed && formats[backbuffer].format == D3DFMT_UNKNOWN)
1235 backbuffer_format = formats[display].format;
1236 else
1237 backbuffer_format = formats[backbuffer].format;
1239 hr = IDirect3D8_CheckDeviceFormat(d3d8, D3DADAPTER_DEFAULT, device_type, formats[display].format,
1240 D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, backbuffer_format);
1241 should_pass = (hr == D3D_OK) && (formats[display].format == formats[backbuffer].format
1242 || (formats[display].alpha_format
1243 && formats[display].alpha_format == formats[backbuffer].alpha_format));
1246 hr = IDirect3D8_CheckDeviceType(d3d8, D3DADAPTER_DEFAULT, device_type,
1247 formats[display].format, formats[backbuffer].format, windowed);
1248 ok(SUCCEEDED(hr) == should_pass || broken(SUCCEEDED(hr) && !has_modes) /* Win8 64-bit */,
1249 "Got unexpected hr %#x for %s / %s, windowed %#x, should_pass %#x.\n",
1250 hr, formats[display].name, formats[backbuffer].name, windowed, should_pass);
1255 IDirect3D8_Release(d3d8);
1258 /* Test adapter display modes */
1259 static void test_display_modes(void)
1261 UINT max_modes, i;
1262 D3DDISPLAYMODE dmode;
1263 IDirect3D8 *d3d;
1264 HRESULT res;
1266 d3d = Direct3DCreate8(D3D_SDK_VERSION);
1267 ok(!!d3d, "Failed to create a D3D object.\n");
1269 max_modes = IDirect3D8_GetAdapterModeCount(d3d, D3DADAPTER_DEFAULT);
1270 ok(max_modes > 0 ||
1271 broken(max_modes == 0), /* VMware */
1272 "GetAdapterModeCount(D3DADAPTER_DEFAULT) returned 0!\n");
1274 for (i = 0; i < max_modes; ++i)
1276 res = IDirect3D8_EnumAdapterModes(d3d, D3DADAPTER_DEFAULT, i, &dmode);
1277 ok(res==D3D_OK, "EnumAdapterModes returned %#08x for mode %u!\n", res, i);
1278 if(res != D3D_OK)
1279 continue;
1281 ok(dmode.Format==D3DFMT_X8R8G8B8 || dmode.Format==D3DFMT_R5G6B5,
1282 "Unexpected display mode returned for mode %u: %#x\n", i , dmode.Format);
1285 IDirect3D8_Release(d3d);
1288 struct mode
1290 unsigned int w;
1291 unsigned int h;
1294 static int compare_mode(const void *a, const void *b)
1296 const struct mode *mode_a = a;
1297 const struct mode *mode_b = b;
1298 unsigned int w = mode_a->w - mode_b->w;
1299 unsigned int h = mode_a->h - mode_b->h;
1300 return abs(w) >= abs(h) ? -w : -h;
1303 static void test_reset(void)
1305 UINT width, orig_width = GetSystemMetrics(SM_CXSCREEN);
1306 UINT height, orig_height = GetSystemMetrics(SM_CYSCREEN);
1307 IDirect3DDevice8 *device1 = NULL;
1308 IDirect3DDevice8 *device2 = NULL;
1309 struct device_desc device_desc;
1310 D3DDISPLAYMODE d3ddm, d3ddm2;
1311 D3DSURFACE_DESC surface_desc;
1312 D3DPRESENT_PARAMETERS d3dpp;
1313 IDirect3DSurface8 *surface;
1314 IDirect3DTexture8 *texture;
1315 UINT adapter_mode_count;
1316 D3DLOCKED_RECT lockrect;
1317 UINT mode_count = 0;
1318 DEVMODEW devmode;
1319 IDirect3D8 *d3d8;
1320 RECT winrect, client_rect;
1321 D3DVIEWPORT8 vp;
1322 D3DCAPS8 caps;
1323 DWORD shader;
1324 DWORD value;
1325 HWND window;
1326 HRESULT hr;
1327 LONG ret;
1328 UINT i;
1330 static const DWORD decl[] =
1332 D3DVSD_STREAM(0),
1333 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT4),
1334 D3DVSD_END(),
1337 struct mode *modes = NULL;
1339 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
1340 100, 100, 160, 160, NULL, NULL, NULL, NULL);
1341 ok(!!window, "Failed to create a window.\n");
1342 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
1343 ok(!!d3d8, "Failed to create a D3D object.\n");
1345 hr = IDirect3D8_GetAdapterDisplayMode(d3d8, D3DADAPTER_DEFAULT, &d3ddm);
1346 ok(SUCCEEDED(hr), "GetAdapterDisplayMode failed, hr %#x.\n", hr);
1347 adapter_mode_count = IDirect3D8_GetAdapterModeCount(d3d8, D3DADAPTER_DEFAULT);
1348 modes = HeapAlloc(GetProcessHeap(), 0, sizeof(*modes) * adapter_mode_count);
1349 for (i = 0; i < adapter_mode_count; ++i)
1351 UINT j;
1353 memset(&d3ddm2, 0, sizeof(d3ddm2));
1354 hr = IDirect3D8_EnumAdapterModes(d3d8, D3DADAPTER_DEFAULT, i, &d3ddm2);
1355 ok(SUCCEEDED(hr), "EnumAdapterModes failed, hr %#x.\n", hr);
1357 if (d3ddm2.Format != d3ddm.Format)
1358 continue;
1360 for (j = 0; j < mode_count; ++j)
1362 if (modes[j].w == d3ddm2.Width && modes[j].h == d3ddm2.Height)
1363 break;
1365 if (j == mode_count)
1367 modes[j].w = d3ddm2.Width;
1368 modes[j].h = d3ddm2.Height;
1369 ++mode_count;
1372 /* We use them as invalid modes. */
1373 if ((d3ddm2.Width == 801 && d3ddm2.Height == 600)
1374 || (d3ddm2.Width == 32 && d3ddm2.Height == 32))
1376 skip("This system supports a screen resolution of %dx%d, not running mode tests.\n",
1377 d3ddm2.Width, d3ddm2.Height);
1378 goto cleanup;
1382 if (mode_count < 2)
1384 skip("Less than 2 modes supported, skipping mode tests.\n");
1385 goto cleanup;
1388 /* Prefer higher resolutions. */
1389 qsort(modes, mode_count, sizeof(*modes), compare_mode);
1391 i = 0;
1392 if (modes[i].w == orig_width && modes[i].h == orig_height) ++i;
1394 device_desc.width = modes[i].w;
1395 device_desc.height = modes[i].h;
1396 device_desc.device_window = window;
1397 device_desc.flags = CREATE_DEVICE_FULLSCREEN | CREATE_DEVICE_SWVP_ONLY;
1398 if (!(device1 = create_device(d3d8, window, &device_desc)))
1400 skip("Failed to create a D3D device, skipping tests.\n");
1401 goto cleanup;
1403 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1404 /* This skips the test on testbot Win 8 VMs. */
1405 if (hr == D3DERR_DEVICELOST)
1407 skip("Device is lost.\n");
1408 goto cleanup;
1410 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1412 hr = IDirect3DDevice8_GetDeviceCaps(device1, &caps);
1413 ok(SUCCEEDED(hr), "GetDeviceCaps failed, hr %#x.\n", hr);
1415 width = GetSystemMetrics(SM_CXSCREEN);
1416 height = GetSystemMetrics(SM_CYSCREEN);
1417 ok(width == modes[i].w, "Screen width is %u, expected %u.\n", width, modes[i].w);
1418 ok(height == modes[i].h, "Screen height is %u, expected %u.\n", height, modes[i].h);
1420 hr = IDirect3DDevice8_GetViewport(device1, &vp);
1421 ok(SUCCEEDED(hr), "GetViewport failed, hr %#x.\n", hr);
1422 ok(vp.X == 0, "D3DVIEWPORT->X = %u, expected 0.\n", vp.X);
1423 ok(vp.Y == 0, "D3DVIEWPORT->Y = %u, expected 0.\n", vp.Y);
1424 ok(vp.Width == modes[i].w, "D3DVIEWPORT->Width = %u, expected %u.\n", vp.Width, modes[i].w);
1425 ok(vp.Height == modes[i].h, "D3DVIEWPORT->Height = %u, expected %u.\n", vp.Height, modes[i].h);
1426 ok(vp.MinZ == 0, "D3DVIEWPORT->MinZ = %.8e, expected 0.\n", vp.MinZ);
1427 ok(vp.MaxZ == 1, "D3DVIEWPORT->MaxZ = %.8e, expected 1.\n", vp.MaxZ);
1429 i = 1;
1430 vp.X = 10;
1431 vp.Y = 20;
1432 vp.Width = modes[i].w / 2;
1433 vp.Height = modes[i].h / 2;
1434 vp.MinZ = 0.2f;
1435 vp.MaxZ = 0.3f;
1436 hr = IDirect3DDevice8_SetViewport(device1, &vp);
1437 ok(SUCCEEDED(hr), "SetViewport failed, hr %#x.\n", hr);
1439 hr = IDirect3DDevice8_GetRenderState(device1, D3DRS_LIGHTING, &value);
1440 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1441 ok(!!value, "Got unexpected value %#x for D3DRS_LIGHTING.\n", value);
1442 hr = IDirect3DDevice8_SetRenderState(device1, D3DRS_LIGHTING, FALSE);
1443 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
1445 memset(&d3dpp, 0, sizeof(d3dpp));
1446 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1447 d3dpp.Windowed = FALSE;
1448 d3dpp.BackBufferWidth = modes[i].w;
1449 d3dpp.BackBufferHeight = modes[i].h;
1450 d3dpp.BackBufferFormat = d3ddm.Format;
1451 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1452 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1453 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1454 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1456 hr = IDirect3DDevice8_GetRenderState(device1, D3DRS_LIGHTING, &value);
1457 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1458 ok(!!value, "Got unexpected value %#x for D3DRS_LIGHTING.\n", value);
1460 memset(&vp, 0, sizeof(vp));
1461 hr = IDirect3DDevice8_GetViewport(device1, &vp);
1462 ok(SUCCEEDED(hr), "GetViewport failed, hr %#x.\n", hr);
1463 ok(vp.X == 0, "D3DVIEWPORT->X = %u, expected 0.\n", vp.X);
1464 ok(vp.Y == 0, "D3DVIEWPORT->Y = %u, expected 0.\n", vp.Y);
1465 ok(vp.Width == modes[i].w, "D3DVIEWPORT->Width = %u, expected %u.\n", vp.Width, modes[i].w);
1466 ok(vp.Height == modes[i].h, "D3DVIEWPORT->Height = %u, expected %u.\n", vp.Height, modes[i].h);
1467 ok(vp.MinZ == 0, "D3DVIEWPORT->MinZ = %.8e, expected 0.\n", vp.MinZ);
1468 ok(vp.MaxZ == 1, "D3DVIEWPORT->MaxZ = %.8e, expected 1.\n", vp.MaxZ);
1470 width = GetSystemMetrics(SM_CXSCREEN);
1471 height = GetSystemMetrics(SM_CYSCREEN);
1472 ok(width == modes[i].w, "Screen width is %u, expected %u.\n", width, modes[i].w);
1473 ok(height == modes[i].h, "Screen height is %u, expected %u.\n", height, modes[i].h);
1475 hr = IDirect3DDevice8_GetRenderTarget(device1, &surface);
1476 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
1477 hr = IDirect3DSurface8_GetDesc(surface, &surface_desc);
1478 ok(hr == D3D_OK, "GetDesc failed, hr %#x.\n", hr);
1479 ok(surface_desc.Width == modes[i].w, "Back buffer width is %u, expected %u.\n",
1480 surface_desc.Width, modes[i].w);
1481 ok(surface_desc.Height == modes[i].h, "Back buffer height is %u, expected %u.\n",
1482 surface_desc.Height, modes[i].h);
1483 IDirect3DSurface8_Release(surface);
1485 memset(&d3dpp, 0, sizeof(d3dpp));
1486 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1487 d3dpp.Windowed = TRUE;
1488 d3dpp.BackBufferWidth = 400;
1489 d3dpp.BackBufferHeight = 300;
1490 d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
1491 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1492 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1493 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1494 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1496 memset(&vp, 0, sizeof(vp));
1497 hr = IDirect3DDevice8_GetViewport(device1, &vp);
1498 ok(SUCCEEDED(hr), "GetViewport failed, hr %#x.\n", hr);
1499 ok(vp.X == 0, "D3DVIEWPORT->X = %u, expected 0.\n", vp.X);
1500 ok(vp.Y == 0, "D3DVIEWPORT->Y = %u, expected 0.\n", vp.Y);
1501 ok(vp.Width == 400, "D3DVIEWPORT->Width = %u, expected 400.\n", vp.Width);
1502 ok(vp.Height == 300, "D3DVIEWPORT->Height = %u, expected 300.\n", vp.Height);
1503 ok(vp.MinZ == 0, "D3DVIEWPORT->MinZ = %.8e, expected 0.\n", vp.MinZ);
1504 ok(vp.MaxZ == 1, "D3DVIEWPORT->MaxZ = %.8e, expected 1.\n", vp.MaxZ);
1506 width = GetSystemMetrics(SM_CXSCREEN);
1507 height = GetSystemMetrics(SM_CYSCREEN);
1508 ok(width == orig_width, "Screen width is %u, expected %u.\n", width, orig_width);
1509 ok(height == orig_height, "Screen height is %u, expected %u.\n", height, orig_height);
1511 hr = IDirect3DDevice8_GetRenderTarget(device1, &surface);
1512 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
1513 hr = IDirect3DSurface8_GetDesc(surface, &surface_desc);
1514 ok(hr == D3D_OK, "GetDesc failed, hr %#x.\n", hr);
1515 ok(surface_desc.Width == 400, "Back buffer width is %u, expected 400.\n",
1516 surface_desc.Width);
1517 ok(surface_desc.Height == 300, "Back buffer height is %u, expected 300.\n",
1518 surface_desc.Height);
1519 IDirect3DSurface8_Release(surface);
1521 memset(&devmode, 0, sizeof(devmode));
1522 devmode.dmSize = sizeof(devmode);
1523 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
1524 devmode.dmPelsWidth = modes[1].w;
1525 devmode.dmPelsHeight = modes[1].h;
1526 ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
1527 ok(ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", ret);
1528 width = GetSystemMetrics(SM_CXSCREEN);
1529 height = GetSystemMetrics(SM_CYSCREEN);
1530 ok(width == modes[1].w, "Screen width is %u, expected %u.\n", width, modes[1].w);
1531 ok(height == modes[1].h, "Screen height is %u, expected %u.\n", height, modes[1].h);
1533 d3dpp.BackBufferWidth = 500;
1534 d3dpp.BackBufferHeight = 400;
1535 d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
1536 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1537 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1538 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1539 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1541 width = GetSystemMetrics(SM_CXSCREEN);
1542 height = GetSystemMetrics(SM_CYSCREEN);
1543 ok(width == modes[1].w, "Screen width is %u, expected %u.\n", width, modes[1].w);
1544 ok(height == modes[1].h, "Screen height is %u, expected %u.\n", height, modes[1].h);
1546 ZeroMemory(&vp, sizeof(vp));
1547 hr = IDirect3DDevice8_GetViewport(device1, &vp);
1548 ok(SUCCEEDED(hr), "GetViewport failed, hr %#x.\n", hr);
1549 ok(vp.X == 0, "D3DVIEWPORT->X = %d.\n", vp.X);
1550 ok(vp.Y == 0, "D3DVIEWPORT->Y = %d.\n", vp.Y);
1551 ok(vp.Width == 500, "D3DVIEWPORT->Width = %d.\n", vp.Width);
1552 ok(vp.Height == 400, "D3DVIEWPORT->Height = %d.\n", vp.Height);
1553 ok(vp.MinZ == 0, "D3DVIEWPORT->MinZ = %f.\n", vp.MinZ);
1554 ok(vp.MaxZ == 1, "D3DVIEWPORT->MaxZ = %f.\n", vp.MaxZ);
1556 hr = IDirect3DDevice8_GetRenderTarget(device1, &surface);
1557 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
1558 hr = IDirect3DSurface8_GetDesc(surface, &surface_desc);
1559 ok(hr == D3D_OK, "GetDesc failed, hr %#x.\n", hr);
1560 ok(surface_desc.Width == 500, "Back buffer width is %u, expected 500.\n",
1561 surface_desc.Width);
1562 ok(surface_desc.Height == 400, "Back buffer height is %u, expected 400.\n",
1563 surface_desc.Height);
1564 IDirect3DSurface8_Release(surface);
1566 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
1567 devmode.dmPelsWidth = orig_width;
1568 devmode.dmPelsHeight = orig_height;
1569 ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
1570 ok(ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", ret);
1571 width = GetSystemMetrics(SM_CXSCREEN);
1572 height = GetSystemMetrics(SM_CYSCREEN);
1573 ok(width == orig_width, "Got screen width %u, expected %u.\n", width, orig_width);
1574 ok(height == orig_height, "Got screen height %u, expected %u.\n", height, orig_height);
1576 winrect.left = 0;
1577 winrect.top = 0;
1578 winrect.right = 200;
1579 winrect.bottom = 150;
1580 ok(AdjustWindowRect(&winrect, WS_OVERLAPPEDWINDOW, FALSE), "AdjustWindowRect failed\n");
1581 ok(SetWindowPos(window, NULL, 0, 0,
1582 winrect.right-winrect.left,
1583 winrect.bottom-winrect.top,
1584 SWP_NOMOVE|SWP_NOZORDER),
1585 "SetWindowPos failed\n");
1587 /* Windows 10 gives us a different size than we requested with some DPI scaling settings (e.g. 172%). */
1588 GetClientRect(window, &client_rect);
1590 memset(&d3dpp, 0, sizeof(d3dpp));
1591 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1592 d3dpp.Windowed = TRUE;
1593 d3dpp.BackBufferWidth = 0;
1594 d3dpp.BackBufferHeight = 0;
1595 d3dpp.BackBufferFormat = d3ddm.Format;
1596 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1597 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1598 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1599 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1601 ok(!d3dpp.BackBufferWidth, "Got unexpected BackBufferWidth %u.\n", d3dpp.BackBufferWidth);
1602 ok(!d3dpp.BackBufferHeight, "Got unexpected BackBufferHeight %u.\n", d3dpp.BackBufferHeight);
1603 ok(d3dpp.BackBufferFormat == d3ddm.Format, "Got unexpected BackBufferFormat %#x, expected %#x.\n",
1604 d3dpp.BackBufferFormat, d3ddm.Format);
1605 ok(d3dpp.BackBufferCount == 1, "Got unexpected BackBufferCount %u.\n", d3dpp.BackBufferCount);
1606 ok(!d3dpp.MultiSampleType, "Got unexpected MultiSampleType %u.\n", d3dpp.MultiSampleType);
1607 ok(d3dpp.SwapEffect == D3DSWAPEFFECT_DISCARD, "Got unexpected SwapEffect %#x.\n", d3dpp.SwapEffect);
1608 ok(!d3dpp.hDeviceWindow, "Got unexpected hDeviceWindow %p.\n", d3dpp.hDeviceWindow);
1609 ok(d3dpp.Windowed, "Got unexpected Windowed %#x.\n", d3dpp.Windowed);
1610 ok(!d3dpp.EnableAutoDepthStencil, "Got unexpected EnableAutoDepthStencil %#x.\n", d3dpp.EnableAutoDepthStencil);
1611 ok(!d3dpp.AutoDepthStencilFormat, "Got unexpected AutoDepthStencilFormat %#x.\n", d3dpp.AutoDepthStencilFormat);
1612 ok(!d3dpp.Flags, "Got unexpected Flags %#x.\n", d3dpp.Flags);
1613 ok(!d3dpp.FullScreen_RefreshRateInHz, "Got unexpected FullScreen_RefreshRateInHz %u.\n",
1614 d3dpp.FullScreen_RefreshRateInHz);
1615 ok(!d3dpp.FullScreen_PresentationInterval, "Got unexpected FullScreen_PresentationInterval %#x.\n",
1616 d3dpp.FullScreen_PresentationInterval);
1618 memset(&vp, 0, sizeof(vp));
1619 hr = IDirect3DDevice8_GetViewport(device1, &vp);
1620 ok(SUCCEEDED(hr), "GetViewport failed, hr %#x.\n", hr);
1621 if (SUCCEEDED(hr))
1623 ok(vp.X == 0, "D3DVIEWPORT->X = %u, expected 0.\n", vp.X);
1624 ok(vp.Y == 0, "D3DVIEWPORT->Y = %u, expected 0.\n", vp.Y);
1625 ok(vp.Width == client_rect.right, "D3DVIEWPORT->Width = %d, expected %d\n",
1626 vp.Width, client_rect.right);
1627 ok(vp.Height == client_rect.bottom, "D3DVIEWPORT->Height = %d, expected %d\n",
1628 vp.Height, client_rect.bottom);
1629 ok(vp.MinZ == 0, "D3DVIEWPORT->MinZ = %.8e, expected 0.\n", vp.MinZ);
1630 ok(vp.MaxZ == 1, "D3DVIEWPORT->MaxZ = %.8e, expected 1.\n", vp.MaxZ);
1633 hr = IDirect3DDevice8_GetRenderTarget(device1, &surface);
1634 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
1635 hr = IDirect3DSurface8_GetDesc(surface, &surface_desc);
1636 ok(hr == D3D_OK, "GetDesc failed, hr %#x.\n", hr);
1637 ok(surface_desc.Format == d3ddm.Format, "Got unexpected Format %#x, expected %#x.\n",
1638 surface_desc.Format, d3ddm.Format);
1639 ok(!surface_desc.MultiSampleType, "Got unexpected MultiSampleType %u.\n", d3dpp.MultiSampleType);
1640 ok(surface_desc.Width == client_rect.right,
1641 "Back buffer width is %u, expected %d.\n", surface_desc.Width, client_rect.right);
1642 ok(surface_desc.Height == client_rect.bottom,
1643 "Back buffer height is %u, expected %d.\n", surface_desc.Height, client_rect.bottom);
1644 IDirect3DSurface8_Release(surface);
1646 memset(&d3dpp, 0, sizeof(d3dpp));
1647 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1648 d3dpp.Windowed = TRUE;
1649 d3dpp.BackBufferWidth = 400;
1650 d3dpp.BackBufferHeight = 300;
1651 d3dpp.BackBufferFormat = d3ddm.Format;
1653 /* Reset fails if there is a resource in the default pool. */
1654 hr = IDirect3DDevice8_CreateTexture(device1, 16, 16, 1, 0, D3DFMT_R5G6B5, D3DPOOL_DEFAULT, &texture);
1655 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
1656 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1657 ok(hr == D3DERR_DEVICELOST, "Reset returned %#x, expected %#x.\n", hr, D3DERR_DEVICELOST);
1658 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1659 ok(hr == D3DERR_DEVICENOTRESET, "TestCooperativeLevel returned %#x, expected %#x.\n", hr, D3DERR_DEVICENOTRESET);
1660 IDirect3DTexture8_Release(texture);
1661 /* Reset again to get the device out of the lost state. */
1662 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1663 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1664 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1665 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1667 if (caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP)
1669 IDirect3DVolumeTexture8 *volume_texture;
1671 hr = IDirect3DDevice8_CreateVolumeTexture(device1, 16, 16, 4, 1, 0,
1672 D3DFMT_R5G6B5, D3DPOOL_DEFAULT, &volume_texture);
1673 ok(SUCCEEDED(hr), "CreateVolumeTexture failed, hr %#x.\n", hr);
1674 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1675 ok(hr == D3DERR_DEVICELOST, "Reset returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
1676 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1677 ok(hr == D3DERR_DEVICENOTRESET, "TestCooperativeLevel returned %#x, expected %#x.\n",
1678 hr, D3DERR_DEVICENOTRESET);
1679 IDirect3DVolumeTexture8_Release(volume_texture);
1680 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1681 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1682 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1683 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1685 else
1687 skip("Volume textures not supported.\n");
1690 /* Scratch, sysmem and managed pool resources are fine. */
1691 hr = IDirect3DDevice8_CreateTexture(device1, 16, 16, 1, 0, D3DFMT_R5G6B5, D3DPOOL_SCRATCH, &texture);
1692 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
1693 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1694 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1695 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1696 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1697 IDirect3DTexture8_Release(texture);
1699 hr = IDirect3DDevice8_CreateTexture(device1, 16, 16, 1, 0, D3DFMT_R5G6B5, D3DPOOL_SYSTEMMEM, &texture);
1700 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
1701 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1702 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1703 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1704 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1705 IDirect3DTexture8_Release(texture);
1707 /* The depth stencil should get reset to the auto depth stencil when present. */
1708 hr = IDirect3DDevice8_SetRenderTarget(device1, NULL, NULL);
1709 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
1711 hr = IDirect3DDevice8_GetDepthStencilSurface(device1, &surface);
1712 ok(hr == D3DERR_NOTFOUND, "GetDepthStencilSurface returned %#x, expected %#x.\n", hr, D3DERR_NOTFOUND);
1713 ok(!surface, "Depth / stencil buffer should be NULL.\n");
1715 d3dpp.EnableAutoDepthStencil = TRUE;
1716 d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
1717 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1718 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1720 hr = IDirect3DDevice8_GetDepthStencilSurface(device1, &surface);
1721 ok(SUCCEEDED(hr), "GetDepthStencilSurface failed, hr %#x.\n", hr);
1722 ok(!!surface, "Depth / stencil buffer should not be NULL.\n");
1723 if (surface) IDirect3DSurface8_Release(surface);
1725 d3dpp.EnableAutoDepthStencil = FALSE;
1726 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1727 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1729 hr = IDirect3DDevice8_GetDepthStencilSurface(device1, &surface);
1730 ok(hr == D3DERR_NOTFOUND, "GetDepthStencilSurface returned %#x, expected %#x.\n", hr, D3DERR_NOTFOUND);
1731 ok(!surface, "Depth / stencil buffer should be NULL.\n");
1733 /* Will a sysmem or scratch resource survive while locked? */
1734 hr = IDirect3DDevice8_CreateTexture(device1, 16, 16, 1, 0, D3DFMT_R5G6B5, D3DPOOL_SYSTEMMEM, &texture);
1735 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
1736 hr = IDirect3DTexture8_LockRect(texture, 0, &lockrect, NULL, D3DLOCK_DISCARD);
1737 ok(SUCCEEDED(hr), "LockRect failed, hr %#x.\n", hr);
1738 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1739 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1740 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1741 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1742 IDirect3DTexture8_UnlockRect(texture, 0);
1743 IDirect3DTexture8_Release(texture);
1745 hr = IDirect3DDevice8_CreateTexture(device1, 16, 16, 1, 0, D3DFMT_R5G6B5, D3DPOOL_SCRATCH, &texture);
1746 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
1747 hr = IDirect3DTexture8_LockRect(texture, 0, &lockrect, NULL, D3DLOCK_DISCARD);
1748 ok(SUCCEEDED(hr), "LockRect failed, hr %#x.\n", hr);
1749 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1750 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1751 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1752 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1753 IDirect3DTexture8_UnlockRect(texture, 0);
1754 IDirect3DTexture8_Release(texture);
1756 hr = IDirect3DDevice8_CreateTexture(device1, 16, 16, 1, 0, D3DFMT_R5G6B5, D3DPOOL_MANAGED, &texture);
1757 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
1758 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1759 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1760 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1761 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1762 IDirect3DTexture8_Release(texture);
1764 /* A reference held to an implicit surface causes failures as well. */
1765 hr = IDirect3DDevice8_GetBackBuffer(device1, 0, D3DBACKBUFFER_TYPE_MONO, &surface);
1766 ok(SUCCEEDED(hr), "GetBackBuffer failed, hr %#x.\n", hr);
1767 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1768 ok(hr == D3DERR_DEVICELOST, "Reset returned %#x, expected %#x.\n", hr, D3DERR_DEVICELOST);
1769 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1770 ok(hr == D3DERR_DEVICENOTRESET, "TestCooperativeLevel returned %#x, expected %#x.\n", hr, D3DERR_DEVICENOTRESET);
1771 IDirect3DSurface8_Release(surface);
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 /* Shaders are fine as well. */
1778 hr = IDirect3DDevice8_CreateVertexShader(device1, decl, simple_vs, &shader, 0);
1779 ok(SUCCEEDED(hr), "CreateVertexShader failed, hr %#x.\n", hr);
1780 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1781 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1782 hr = IDirect3DDevice8_DeleteVertexShader(device1, shader);
1783 ok(SUCCEEDED(hr), "DeleteVertexShader failed, hr %#x.\n", hr);
1785 /* Try setting invalid modes. */
1786 memset(&d3dpp, 0, sizeof(d3dpp));
1787 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1788 d3dpp.Windowed = FALSE;
1789 d3dpp.BackBufferWidth = 32;
1790 d3dpp.BackBufferHeight = 32;
1791 d3dpp.BackBufferFormat = d3ddm.Format;
1792 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1793 ok(hr == D3DERR_INVALIDCALL, "Reset returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
1794 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1795 ok(hr == D3DERR_DEVICENOTRESET, "TestCooperativeLevel returned %#x, expected %#x.\n", hr, D3DERR_DEVICENOTRESET);
1797 memset(&d3dpp, 0, sizeof(d3dpp));
1798 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1799 d3dpp.Windowed = FALSE;
1800 d3dpp.BackBufferWidth = 801;
1801 d3dpp.BackBufferHeight = 600;
1802 d3dpp.BackBufferFormat = d3ddm.Format;
1803 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1804 ok(hr == D3DERR_INVALIDCALL, "Reset returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
1805 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1806 ok(hr == D3DERR_DEVICENOTRESET, "TestCooperativeLevel returned %#x, expected %#x.\n", hr, D3DERR_DEVICENOTRESET);
1808 memset(&d3dpp, 0, sizeof(d3dpp));
1809 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1810 d3dpp.Windowed = FALSE;
1811 d3dpp.BackBufferWidth = 0;
1812 d3dpp.BackBufferHeight = 0;
1813 d3dpp.BackBufferFormat = d3ddm.Format;
1814 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1815 ok(hr == D3DERR_INVALIDCALL, "Reset returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
1816 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1817 ok(hr == D3DERR_DEVICENOTRESET, "TestCooperativeLevel returned %#x, expected %#x.\n", hr, D3DERR_DEVICENOTRESET);
1819 hr = IDirect3D8_GetAdapterDisplayMode(d3d8, D3DADAPTER_DEFAULT, &d3ddm);
1820 ok(SUCCEEDED(hr), "GetAdapterDisplayMode failed, hr %#x.\n", hr);
1822 memset(&d3dpp, 0, sizeof(d3dpp));
1823 d3dpp.Windowed = TRUE;
1824 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1825 d3dpp.BackBufferFormat = d3ddm.Format;
1826 d3dpp.EnableAutoDepthStencil = FALSE;
1827 d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
1829 hr = IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
1830 window, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &device2);
1831 if (FAILED(hr))
1833 skip("Failed to create device, hr %#x.\n", hr);
1834 goto cleanup;
1837 hr = IDirect3DDevice8_TestCooperativeLevel(device2);
1838 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1840 d3dpp.Windowed = TRUE;
1841 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1842 d3dpp.BackBufferWidth = 400;
1843 d3dpp.BackBufferHeight = 300;
1844 d3dpp.BackBufferFormat = d3ddm.Format;
1845 d3dpp.EnableAutoDepthStencil = TRUE;
1846 d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
1848 hr = IDirect3DDevice8_Reset(device2, &d3dpp);
1849 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1850 if (FAILED(hr))
1851 goto cleanup;
1853 hr = IDirect3DDevice8_GetDepthStencilSurface(device2, &surface);
1854 ok(SUCCEEDED(hr), "GetDepthStencilSurface failed, hr %#x.\n", hr);
1855 ok(!!surface, "Depth / stencil buffer should not be NULL.\n");
1856 if (surface)
1857 IDirect3DSurface8_Release(surface);
1859 cleanup:
1860 HeapFree(GetProcessHeap(), 0, modes);
1861 if (device2)
1862 IDirect3DDevice8_Release(device2);
1863 if (device1)
1864 IDirect3DDevice8_Release(device1);
1865 IDirect3D8_Release(d3d8);
1866 DestroyWindow(window);
1869 static void test_scene(void)
1871 IDirect3DDevice8 *device;
1872 IDirect3D8 *d3d;
1873 ULONG refcount;
1874 HWND window;
1875 HRESULT hr;
1877 window = create_window();
1878 ok(!!window, "Failed to create a window.\n");
1879 d3d = Direct3DCreate8(D3D_SDK_VERSION);
1880 ok(!!d3d, "Failed to create a D3D object.\n");
1881 if (!(device = create_device(d3d, window, NULL)))
1883 skip("Failed to create a 3D device, skipping test.\n");
1884 goto cleanup;
1887 /* Test an EndScene without BeginScene. Should return an error */
1888 hr = IDirect3DDevice8_EndScene(device);
1889 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_EndScene returned %#08x\n", hr);
1891 /* Test a normal BeginScene / EndScene pair, this should work */
1892 hr = IDirect3DDevice8_BeginScene(device);
1893 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr);
1894 hr = IDirect3DDevice8_EndScene(device);
1895 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed with %#08x\n", hr);
1897 /* Test another EndScene without having begun a new scene. Should return an error */
1898 hr = IDirect3DDevice8_EndScene(device);
1899 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_EndScene returned %#08x\n", hr);
1901 /* Two nested BeginScene and EndScene calls */
1902 hr = IDirect3DDevice8_BeginScene(device);
1903 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr);
1904 hr = IDirect3DDevice8_BeginScene(device);
1905 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_BeginScene returned %#08x\n", hr);
1906 hr = IDirect3DDevice8_EndScene(device);
1907 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed with %#08x\n", hr);
1908 hr = IDirect3DDevice8_EndScene(device);
1909 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_EndScene returned %#08x\n", hr);
1911 /* StretchRect does not exit in Direct3D8, so no equivalent to the d3d9 stretchrect tests */
1913 refcount = IDirect3DDevice8_Release(device);
1914 ok(!refcount, "Device has %u references left.\n", refcount);
1915 cleanup:
1916 IDirect3D8_Release(d3d);
1917 DestroyWindow(window);
1920 static void test_shader(void)
1922 DWORD hPixelShader = 0, hVertexShader = 0;
1923 DWORD hPixelShader2 = 0, hVertexShader2 = 0;
1924 DWORD hTempHandle;
1925 D3DCAPS8 caps;
1926 DWORD fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE;
1927 IDirect3DDevice8 *device;
1928 IDirect3D8 *d3d;
1929 DWORD data_size;
1930 ULONG refcount;
1931 HWND window;
1932 HRESULT hr;
1933 void *data;
1935 static DWORD dwVertexDecl[] =
1937 D3DVSD_STREAM(0),
1938 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3),
1939 D3DVSD_END()
1941 DWORD decl_normal_float2[] =
1943 D3DVSD_STREAM(0),
1944 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
1945 D3DVSD_REG(D3DVSDE_NORMAL, D3DVSDT_FLOAT2), /* D3DVSDE_NORMAL, Register v1 */
1946 D3DVSD_END()
1948 DWORD decl_normal_float4[] =
1950 D3DVSD_STREAM(0),
1951 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
1952 D3DVSD_REG(D3DVSDE_NORMAL, D3DVSDT_FLOAT4), /* D3DVSDE_NORMAL, Register v1 */
1953 D3DVSD_END()
1955 DWORD decl_normal_d3dcolor[] =
1957 D3DVSD_STREAM(0),
1958 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
1959 D3DVSD_REG(D3DVSDE_NORMAL, D3DVSDT_D3DCOLOR),/* D3DVSDE_NORMAL, Register v1 */
1960 D3DVSD_END()
1962 const DWORD vertex_decl_size = sizeof(dwVertexDecl);
1963 const DWORD simple_vs_size = sizeof(simple_vs);
1964 const DWORD simple_ps_size = sizeof(simple_ps);
1966 window = create_window();
1967 ok(!!window, "Failed to create a window.\n");
1968 d3d = Direct3DCreate8(D3D_SDK_VERSION);
1969 ok(!!d3d, "Failed to create a D3D object.\n");
1970 if (!(device = create_device(d3d, window, NULL)))
1972 skip("Failed to create a 3D device, skipping test.\n");
1973 goto cleanup;
1976 IDirect3DDevice8_GetDeviceCaps(device, &caps);
1978 /* Test setting and retrieving a FVF */
1979 hr = IDirect3DDevice8_SetVertexShader(device, fvf);
1980 ok(SUCCEEDED(hr), "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
1981 hr = IDirect3DDevice8_GetVertexShader(device, &hTempHandle);
1982 ok(SUCCEEDED(hr), "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
1983 ok(hTempHandle == fvf, "Vertex shader %#08x is set, expected %#08x\n", hTempHandle, fvf);
1985 /* First create a vertex shader */
1986 hr = IDirect3DDevice8_SetVertexShader(device, 0);
1987 ok(SUCCEEDED(hr), "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
1988 hr = IDirect3DDevice8_CreateVertexShader(device, dwVertexDecl, simple_vs, &hVertexShader, 0);
1989 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1990 /* Msdn says that the new vertex shader is set immediately. This is wrong, apparently */
1991 hr = IDirect3DDevice8_GetVertexShader(device, &hTempHandle);
1992 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
1993 ok(hTempHandle == 0, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, 0);
1994 /* Assign the shader, then verify that GetVertexShader works */
1995 hr = IDirect3DDevice8_SetVertexShader(device, hVertexShader);
1996 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
1997 hr = IDirect3DDevice8_GetVertexShader(device, &hTempHandle);
1998 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
1999 ok(hTempHandle == hVertexShader, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, hVertexShader);
2000 /* Verify that we can retrieve the declaration */
2001 hr = IDirect3DDevice8_GetVertexShaderDeclaration(device, hVertexShader, NULL, &data_size);
2002 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderDeclaration returned %#08x\n", hr);
2003 ok(data_size == vertex_decl_size, "Got data_size %u, expected %u\n", data_size, vertex_decl_size);
2004 data = HeapAlloc(GetProcessHeap(), 0, vertex_decl_size);
2005 data_size = 1;
2006 hr = IDirect3DDevice8_GetVertexShaderDeclaration(device, hVertexShader, data, &data_size);
2007 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_GetVertexShaderDeclaration returned (%#08x), "
2008 "expected D3DERR_INVALIDCALL\n", hr);
2009 ok(data_size == 1, "Got data_size %u, expected 1\n", data_size);
2010 data_size = vertex_decl_size;
2011 hr = IDirect3DDevice8_GetVertexShaderDeclaration(device, hVertexShader, data, &data_size);
2012 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderDeclaration returned %#08x\n", hr);
2013 ok(data_size == vertex_decl_size, "Got data_size %u, expected %u\n", data_size, vertex_decl_size);
2014 ok(!memcmp(data, dwVertexDecl, vertex_decl_size), "data not equal to shader declaration\n");
2015 HeapFree(GetProcessHeap(), 0, data);
2016 /* Verify that we can retrieve the shader function */
2017 hr = IDirect3DDevice8_GetVertexShaderFunction(device, hVertexShader, NULL, &data_size);
2018 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderFunction returned %#08x\n", hr);
2019 ok(data_size == simple_vs_size, "Got data_size %u, expected %u\n", data_size, simple_vs_size);
2020 data = HeapAlloc(GetProcessHeap(), 0, simple_vs_size);
2021 data_size = 1;
2022 hr = IDirect3DDevice8_GetVertexShaderFunction(device, hVertexShader, data, &data_size);
2023 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_GetVertexShaderFunction returned (%#08x), "
2024 "expected D3DERR_INVALIDCALL\n", hr);
2025 ok(data_size == 1, "Got data_size %u, expected 1\n", data_size);
2026 data_size = simple_vs_size;
2027 hr = IDirect3DDevice8_GetVertexShaderFunction(device, hVertexShader, data, &data_size);
2028 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderFunction returned %#08x\n", hr);
2029 ok(data_size == simple_vs_size, "Got data_size %u, expected %u\n", data_size, simple_vs_size);
2030 ok(!memcmp(data, simple_vs, simple_vs_size), "data not equal to shader function\n");
2031 HeapFree(GetProcessHeap(), 0, data);
2032 /* Delete the assigned shader. This is supposed to work */
2033 hr = IDirect3DDevice8_DeleteVertexShader(device, hVertexShader);
2034 ok(hr == D3D_OK, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
2035 /* The shader should be unset now */
2036 hr = IDirect3DDevice8_GetVertexShader(device, &hTempHandle);
2037 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
2038 ok(hTempHandle == 0, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, 0);
2040 /* Test a broken declaration. 3DMark2001 tries to use normals with 2 components
2041 * First try the fixed function shader function, then a custom one
2043 hr = IDirect3DDevice8_CreateVertexShader(device, decl_normal_float2, 0, &hVertexShader, 0);
2044 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
2045 hr = IDirect3DDevice8_CreateVertexShader(device, decl_normal_float4, 0, &hVertexShader, 0);
2046 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
2047 hr = IDirect3DDevice8_CreateVertexShader(device, decl_normal_d3dcolor, 0, &hVertexShader, 0);
2048 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
2050 hr = IDirect3DDevice8_CreateVertexShader(device, decl_normal_float2, simple_vs, &hVertexShader, 0);
2051 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
2052 IDirect3DDevice8_DeleteVertexShader(device, hVertexShader);
2054 if (caps.PixelShaderVersion >= D3DPS_VERSION(1, 0))
2056 /* The same with a pixel shader */
2057 hr = IDirect3DDevice8_CreatePixelShader(device, simple_ps, &hPixelShader);
2058 ok(hr == D3D_OK, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr);
2059 /* Msdn says that the new pixel shader is set immediately. This is wrong, apparently */
2060 hr = IDirect3DDevice8_GetPixelShader(device, &hTempHandle);
2061 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr);
2062 ok(hTempHandle == 0, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, 0);
2063 /* Assign the shader, then verify that GetPixelShader works */
2064 hr = IDirect3DDevice8_SetPixelShader(device, hPixelShader);
2065 ok(hr == D3D_OK, "IDirect3DDevice8_SetPixelShader returned %#08x\n", hr);
2066 hr = IDirect3DDevice8_GetPixelShader(device, &hTempHandle);
2067 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr);
2068 ok(hTempHandle == hPixelShader, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, hPixelShader);
2069 /* Verify that we can retrieve the shader function */
2070 hr = IDirect3DDevice8_GetPixelShaderFunction(device, hPixelShader, NULL, &data_size);
2071 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShaderFunction returned %#08x\n", hr);
2072 ok(data_size == simple_ps_size, "Got data_size %u, expected %u\n", data_size, simple_ps_size);
2073 data = HeapAlloc(GetProcessHeap(), 0, simple_ps_size);
2074 data_size = 1;
2075 hr = IDirect3DDevice8_GetPixelShaderFunction(device, hPixelShader, data, &data_size);
2076 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_GetPixelShaderFunction returned (%#08x), "
2077 "expected D3DERR_INVALIDCALL\n", hr);
2078 ok(data_size == 1, "Got data_size %u, expected 1\n", data_size);
2079 data_size = simple_ps_size;
2080 hr = IDirect3DDevice8_GetPixelShaderFunction(device, hPixelShader, data, &data_size);
2081 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShaderFunction returned %#08x\n", hr);
2082 ok(data_size == simple_ps_size, "Got data_size %u, expected %u\n", data_size, simple_ps_size);
2083 ok(!memcmp(data, simple_ps, simple_ps_size), "data not equal to shader function\n");
2084 HeapFree(GetProcessHeap(), 0, data);
2085 /* Delete the assigned shader. This is supposed to work */
2086 hr = IDirect3DDevice8_DeletePixelShader(device, hPixelShader);
2087 ok(hr == D3D_OK, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
2088 /* The shader should be unset now */
2089 hr = IDirect3DDevice8_GetPixelShader(device, &hTempHandle);
2090 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr);
2091 ok(hTempHandle == 0, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, 0);
2093 /* What happens if a non-bound shader is deleted? */
2094 hr = IDirect3DDevice8_CreatePixelShader(device, simple_ps, &hPixelShader);
2095 ok(hr == D3D_OK, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr);
2096 hr = IDirect3DDevice8_CreatePixelShader(device, simple_ps, &hPixelShader2);
2097 ok(hr == D3D_OK, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr);
2099 hr = IDirect3DDevice8_SetPixelShader(device, hPixelShader);
2100 ok(hr == D3D_OK, "IDirect3DDevice8_SetPixelShader returned %#08x\n", hr);
2101 hr = IDirect3DDevice8_DeletePixelShader(device, hPixelShader2);
2102 ok(hr == D3D_OK, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
2103 hr = IDirect3DDevice8_GetPixelShader(device, &hTempHandle);
2104 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr);
2105 ok(hTempHandle == hPixelShader, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, hPixelShader);
2106 hr = IDirect3DDevice8_DeletePixelShader(device, hPixelShader);
2107 ok(hr == D3D_OK, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
2109 /* Check for double delete. */
2110 hr = IDirect3DDevice8_DeletePixelShader(device, hPixelShader2);
2111 ok(hr == D3DERR_INVALIDCALL || broken(hr == D3D_OK), "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
2112 hr = IDirect3DDevice8_DeletePixelShader(device, hPixelShader);
2113 ok(hr == D3DERR_INVALIDCALL || broken(hr == D3D_OK), "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
2115 else
2117 skip("Pixel shaders not supported\n");
2120 /* What happens if a non-bound shader is deleted? */
2121 hr = IDirect3DDevice8_CreateVertexShader(device, dwVertexDecl, NULL, &hVertexShader, 0);
2122 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
2123 hr = IDirect3DDevice8_CreateVertexShader(device, dwVertexDecl, NULL, &hVertexShader2, 0);
2124 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
2126 hr = IDirect3DDevice8_SetVertexShader(device, hVertexShader);
2127 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
2128 hr = IDirect3DDevice8_DeleteVertexShader(device, hVertexShader2);
2129 ok(hr == D3D_OK, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
2130 hr = IDirect3DDevice8_GetVertexShader(device, &hTempHandle);
2131 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
2132 ok(hTempHandle == hVertexShader, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, hVertexShader);
2133 hr = IDirect3DDevice8_DeleteVertexShader(device, hVertexShader);
2134 ok(hr == D3D_OK, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
2136 /* Check for double delete. */
2137 hr = IDirect3DDevice8_DeleteVertexShader(device, hVertexShader2);
2138 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
2139 hr = IDirect3DDevice8_DeleteVertexShader(device, hVertexShader);
2140 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
2142 refcount = IDirect3DDevice8_Release(device);
2143 ok(!refcount, "Device has %u references left.\n", refcount);
2144 cleanup:
2145 IDirect3D8_Release(d3d);
2146 DestroyWindow(window);
2149 static void test_limits(void)
2151 IDirect3DTexture8 *texture;
2152 IDirect3DDevice8 *device;
2153 IDirect3D8 *d3d;
2154 unsigned int i;
2155 ULONG refcount;
2156 HWND window;
2157 HRESULT hr;
2159 window = create_window();
2160 ok(!!window, "Failed to create a window.\n");
2161 d3d = Direct3DCreate8(D3D_SDK_VERSION);
2162 ok(!!d3d, "Failed to create a D3D object.\n");
2163 if (!(device = create_device(d3d, window, NULL)))
2165 skip("Failed to create a 3D device, skipping test.\n");
2166 goto cleanup;
2169 hr = IDirect3DDevice8_CreateTexture(device, 16, 16, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture);
2170 ok(hr == D3D_OK, "IDirect3DDevice8_CreateTexture failed with %#08x\n", hr);
2172 /* There are 8 texture stages. We should be able to access all of them */
2173 for (i = 0; i < 8; ++i)
2175 hr = IDirect3DDevice8_SetTexture(device, i, (IDirect3DBaseTexture8 *)texture);
2176 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %#08x\n", i, hr);
2177 hr = IDirect3DDevice8_SetTexture(device, i, NULL);
2178 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %#08x\n", i, hr);
2179 hr = IDirect3DDevice8_SetTextureStageState(device, i, D3DTSS_COLOROP, D3DTOP_ADD);
2180 ok(hr == D3D_OK, "IDirect3DDevice8_SetTextureStageState for texture %d failed with %#08x\n", i, hr);
2183 /* Investigations show that accessing higher textures stage states does
2184 * not return an error either. Writing to too high texture stages
2185 * (approximately texture 40) causes memory corruption in windows, so
2186 * there is no bounds checking. */
2187 IDirect3DTexture8_Release(texture);
2188 refcount = IDirect3DDevice8_Release(device);
2189 ok(!refcount, "Device has %u references left.\n", refcount);
2190 cleanup:
2191 IDirect3D8_Release(d3d);
2192 DestroyWindow(window);
2195 static void test_lights(void)
2197 IDirect3DDevice8 *device;
2198 IDirect3D8 *d3d8;
2199 ULONG refcount;
2200 HWND window;
2201 HRESULT hr;
2202 unsigned int i;
2203 BOOL enabled;
2204 D3DCAPS8 caps;
2206 window = create_window();
2207 ok(!!window, "Failed to create a window.\n");
2208 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
2209 ok(!!d3d8, "Failed to create a D3D object.\n");
2210 if (!(device = create_device(d3d8, window, NULL)))
2212 skip("Failed to create a 3D device, skipping test.\n");
2213 goto cleanup;
2216 memset(&caps, 0, sizeof(caps));
2217 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
2218 ok(hr == D3D_OK, "IDirect3DDevice8_GetDeviceCaps failed with %08x\n", hr);
2220 for(i = 1; i <= caps.MaxActiveLights; i++) {
2221 hr = IDirect3DDevice8_LightEnable(device, i, TRUE);
2222 ok(hr == D3D_OK, "Enabling light %u failed with %08x\n", i, hr);
2223 hr = IDirect3DDevice8_GetLightEnable(device, i, &enabled);
2224 ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL),
2225 "GetLightEnable on light %u failed with %08x\n", i, hr);
2226 ok(enabled, "Light %d is %s\n", i, enabled ? "enabled" : "disabled");
2229 /* TODO: Test the rendering results in this situation */
2230 hr = IDirect3DDevice8_LightEnable(device, i + 1, TRUE);
2231 ok(hr == D3D_OK, "Enabling one light more than supported returned %08x\n", hr);
2232 hr = IDirect3DDevice8_GetLightEnable(device, i + 1, &enabled);
2233 ok(hr == D3D_OK, "GetLightEnable on light %u failed with %08x\n", i + 1, hr);
2234 ok(enabled, "Light %d is %s\n", i + 1, enabled ? "enabled" : "disabled");
2235 hr = IDirect3DDevice8_LightEnable(device, i + 1, FALSE);
2236 ok(hr == D3D_OK, "Disabling the additional returned %08x\n", hr);
2238 for(i = 1; i <= caps.MaxActiveLights; i++) {
2239 hr = IDirect3DDevice8_LightEnable(device, i, FALSE);
2240 ok(hr == D3D_OK, "Disabling light %u failed with %08x\n", i, hr);
2243 refcount = IDirect3DDevice8_Release(device);
2244 ok(!refcount, "Device has %u references left.\n", refcount);
2245 cleanup:
2246 IDirect3D8_Release(d3d8);
2247 DestroyWindow(window);
2250 static void test_render_zero_triangles(void)
2252 IDirect3DDevice8 *device;
2253 IDirect3D8 *d3d8;
2254 ULONG refcount;
2255 HWND window;
2256 HRESULT hr;
2258 static const struct
2260 struct vec3 position;
2261 struct vec3 normal;
2262 DWORD diffuse;
2264 quad[] =
2266 {{0.0f, -1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
2267 {{0.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
2268 {{1.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
2269 {{1.0f, -1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
2272 window = create_window();
2273 ok(!!window, "Failed to create a window.\n");
2274 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
2275 ok(!!d3d8, "Failed to create a D3D object.\n");
2276 if (!(device = create_device(d3d8, window, NULL)))
2278 skip("Failed to create a 3D device, skipping test.\n");
2279 goto cleanup;
2282 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
2283 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
2285 hr = IDirect3DDevice8_BeginScene(device);
2286 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
2287 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 0 /* NumVerts */,
2288 0 /* PrimCount */, NULL, D3DFMT_INDEX16, quad, sizeof(quad[0]));
2289 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
2290 hr = IDirect3DDevice8_EndScene(device);
2291 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
2293 IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
2295 refcount = IDirect3DDevice8_Release(device);
2296 ok(!refcount, "Device has %u references left.\n", refcount);
2297 cleanup:
2298 IDirect3D8_Release(d3d8);
2299 DestroyWindow(window);
2302 static void test_depth_stencil_reset(void)
2304 D3DPRESENT_PARAMETERS present_parameters;
2305 D3DDISPLAYMODE display_mode;
2306 IDirect3DSurface8 *surface, *orig_rt;
2307 IDirect3DDevice8 *device = NULL;
2308 IDirect3D8 *d3d8;
2309 UINT refcount;
2310 HRESULT hr;
2311 HWND hwnd;
2313 hwnd = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
2314 100, 100, 160, 160, NULL, NULL, NULL, NULL);
2315 ok(!!hwnd, "Failed to create a window.\n");
2316 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
2317 ok(!!d3d8, "Failed to create a D3D object.\n");
2319 IDirect3D8_GetAdapterDisplayMode(d3d8, D3DADAPTER_DEFAULT, &display_mode);
2320 memset(&present_parameters, 0, sizeof(present_parameters));
2321 present_parameters.Windowed = TRUE;
2322 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
2323 present_parameters.BackBufferFormat = display_mode.Format;
2324 present_parameters.EnableAutoDepthStencil = TRUE;
2325 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
2327 hr = IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
2328 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device);
2329 if(FAILED(hr))
2331 skip("could not create device, IDirect3D8_CreateDevice returned %#x\n", hr);
2332 goto cleanup;
2335 hr = IDirect3DDevice8_GetRenderTarget(device, &orig_rt);
2336 ok(hr == D3D_OK, "GetRenderTarget failed with 0x%08x\n", hr);
2338 hr = IDirect3DDevice8_TestCooperativeLevel(device);
2339 ok(SUCCEEDED(hr), "TestCooperativeLevel failed with %#x\n", hr);
2341 hr = IDirect3DDevice8_SetRenderTarget(device, NULL, NULL);
2342 ok(hr == D3D_OK, "SetRenderTarget failed with 0x%08x\n", hr);
2344 hr = IDirect3DDevice8_GetRenderTarget(device, &surface);
2345 ok(hr == D3D_OK, "GetRenderTarget failed with 0x%08x\n", hr);
2346 ok(surface == orig_rt, "Render target is %p, should be %p\n", surface, orig_rt);
2347 if (surface) IDirect3DSurface8_Release(surface);
2348 IDirect3DSurface8_Release(orig_rt);
2350 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surface);
2351 ok(hr == D3DERR_NOTFOUND, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr);
2352 ok(surface == NULL, "Depth stencil should be NULL\n");
2354 present_parameters.EnableAutoDepthStencil = TRUE;
2355 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
2356 hr = IDirect3DDevice8_Reset(device, &present_parameters);
2357 ok(hr == D3D_OK, "Reset failed with 0x%08x\n", hr);
2359 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surface);
2360 ok(hr == D3D_OK, "GetDepthStencilSurface failed with 0x%08x\n", hr);
2361 ok(surface != NULL, "Depth stencil should not be NULL\n");
2362 if (surface) IDirect3DSurface8_Release(surface);
2364 present_parameters.EnableAutoDepthStencil = FALSE;
2365 hr = IDirect3DDevice8_Reset(device, &present_parameters);
2366 ok(hr == D3D_OK, "Reset failed with 0x%08x\n", hr);
2368 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surface);
2369 ok(hr == D3DERR_NOTFOUND, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr);
2370 ok(surface == NULL, "Depth stencil should be NULL\n");
2372 refcount = IDirect3DDevice8_Release(device);
2373 ok(!refcount, "Device has %u references left.\n", refcount);
2374 device = NULL;
2376 IDirect3D8_GetAdapterDisplayMode( d3d8, D3DADAPTER_DEFAULT, &display_mode );
2378 ZeroMemory( &present_parameters, sizeof(present_parameters) );
2379 present_parameters.Windowed = TRUE;
2380 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
2381 present_parameters.BackBufferFormat = display_mode.Format;
2382 present_parameters.EnableAutoDepthStencil = FALSE;
2383 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
2385 hr = IDirect3D8_CreateDevice( d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
2386 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device );
2388 if(FAILED(hr))
2390 skip("could not create device, IDirect3D8_CreateDevice returned %#x\n", hr);
2391 goto cleanup;
2394 hr = IDirect3DDevice8_TestCooperativeLevel(device);
2395 ok(hr == D3D_OK, "IDirect3DDevice8_TestCooperativeLevel after creation returned %#x\n", hr);
2397 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
2398 present_parameters.Windowed = TRUE;
2399 present_parameters.BackBufferWidth = 400;
2400 present_parameters.BackBufferHeight = 300;
2401 present_parameters.EnableAutoDepthStencil = TRUE;
2402 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
2404 hr = IDirect3DDevice8_Reset(device, &present_parameters);
2405 ok(hr == D3D_OK, "IDirect3DDevice8_Reset failed with 0x%08x\n", hr);
2407 if (FAILED(hr)) goto cleanup;
2409 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surface);
2410 ok(hr == D3D_OK, "GetDepthStencilSurface failed with 0x%08x\n", hr);
2411 ok(surface != NULL, "Depth stencil should not be NULL\n");
2412 if (surface) IDirect3DSurface8_Release(surface);
2414 cleanup:
2415 if (device)
2417 refcount = IDirect3DDevice8_Release(device);
2418 ok(!refcount, "Device has %u references left.\n", refcount);
2420 IDirect3D8_Release(d3d8);
2421 DestroyWindow(hwnd);
2424 static HWND filter_messages;
2426 enum message_window
2428 DEVICE_WINDOW,
2429 FOCUS_WINDOW,
2432 struct message
2434 UINT message;
2435 enum message_window window;
2436 BOOL check_wparam;
2437 WPARAM expect_wparam;
2438 HRESULT device_state;
2439 WINDOWPOS *store_wp;
2442 static const struct message *expect_messages;
2443 static HWND device_window, focus_window;
2444 static LONG windowposchanged_received, syscommand_received;
2445 static IDirect3DDevice8 *focus_test_device;
2447 struct wndproc_thread_param
2449 HWND dummy_window;
2450 HANDLE window_created;
2451 HANDLE test_finished;
2452 BOOL running_in_foreground;
2455 static LRESULT CALLBACK test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
2457 HRESULT hr;
2459 if (filter_messages && filter_messages == hwnd)
2461 if (message != WM_DISPLAYCHANGE && message != WM_IME_NOTIFY)
2462 todo_wine ok(0, "Received unexpected message %#x for window %p.\n", message, hwnd);
2465 if (expect_messages)
2467 HWND w;
2469 switch (expect_messages->window)
2471 case DEVICE_WINDOW:
2472 w = device_window;
2473 break;
2475 case FOCUS_WINDOW:
2476 w = focus_window;
2477 break;
2479 default:
2480 w = NULL;
2481 break;
2484 if (hwnd == w && expect_messages->message == message)
2486 if (expect_messages->check_wparam)
2487 ok(wparam == expect_messages->expect_wparam,
2488 "Got unexpected wparam %lx for message %x, expected %lx.\n",
2489 wparam, message, expect_messages->expect_wparam);
2491 if (expect_messages->store_wp)
2492 *expect_messages->store_wp = *(WINDOWPOS *)lparam;
2494 if (focus_test_device)
2496 hr = IDirect3DDevice8_TestCooperativeLevel(focus_test_device);
2497 /* Wined3d marks the device lost earlier than Windows (it follows ddraw
2498 * behavior. See test_wndproc before the focus_loss_messages sequence
2499 * about the D3DERR_DEVICENOTRESET behavior, */
2500 todo_wine_if(message != WM_ACTIVATEAPP || hr == D3D_OK)
2501 ok(hr == expect_messages->device_state,
2502 "Got device state %#x on message %#x, expected %#x.\n",
2503 hr, message, expect_messages->device_state);
2506 ++expect_messages;
2510 /* KDE randomly does something with the hidden window during the
2511 * mode change that sometimes generates a WM_WINDOWPOSCHANGING
2512 * message. A WM_WINDOWPOSCHANGED message is not generated, so
2513 * just flag WM_WINDOWPOSCHANGED as bad. */
2514 if (message == WM_WINDOWPOSCHANGED)
2515 InterlockedIncrement(&windowposchanged_received);
2516 else if (message == WM_SYSCOMMAND)
2517 InterlockedIncrement(&syscommand_received);
2519 return DefWindowProcA(hwnd, message, wparam, lparam);
2522 static DWORD WINAPI wndproc_thread(void *param)
2524 struct wndproc_thread_param *p = param;
2525 DWORD res;
2526 BOOL ret;
2528 p->dummy_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
2529 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, registry_mode.dmPelsWidth,
2530 registry_mode.dmPelsHeight, 0, 0, 0, 0);
2531 p->running_in_foreground = SetForegroundWindow(p->dummy_window);
2533 ret = SetEvent(p->window_created);
2534 ok(ret, "SetEvent failed, last error %#x.\n", GetLastError());
2536 for (;;)
2538 MSG msg;
2540 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2541 res = WaitForSingleObject(p->test_finished, 100);
2542 if (res == WAIT_OBJECT_0) break;
2543 if (res != WAIT_TIMEOUT)
2545 ok(0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
2546 break;
2550 DestroyWindow(p->dummy_window);
2552 return 0;
2555 static void test_wndproc(void)
2557 struct wndproc_thread_param thread_params;
2558 struct device_desc device_desc;
2559 IDirect3DDevice8 *device;
2560 WNDCLASSA wc = {0};
2561 IDirect3D8 *d3d8;
2562 HANDLE thread;
2563 LONG_PTR proc;
2564 ULONG ref;
2565 DWORD res, tid;
2566 HWND tmp;
2567 UINT i, adapter_mode_count;
2568 HRESULT hr;
2569 D3DDISPLAYMODE d3ddm;
2570 DWORD d3d_width = 0, d3d_height = 0, user32_width = 0, user32_height = 0;
2571 DEVMODEW devmode;
2572 LONG change_ret, device_style;
2573 BOOL ret;
2574 WINDOWPOS windowpos;
2576 static const struct message create_messages[] =
2578 {WM_WINDOWPOSCHANGING, FOCUS_WINDOW, FALSE, 0},
2579 /* Do not test wparam here. If device creation succeeds,
2580 * wparam is WA_ACTIVE. If device creation fails (testbot)
2581 * wparam is set to WA_INACTIVE on some Windows versions. */
2582 {WM_ACTIVATE, FOCUS_WINDOW, FALSE, 0},
2583 {WM_SETFOCUS, FOCUS_WINDOW, FALSE, 0},
2584 {WM_WINDOWPOSCHANGING, DEVICE_WINDOW, FALSE, 0},
2585 {WM_MOVE, DEVICE_WINDOW, FALSE, 0},
2586 {WM_SIZE, DEVICE_WINDOW, FALSE, 0},
2587 {0, 0, FALSE, 0},
2589 static const struct message focus_loss_messages[] =
2591 /* WM_ACTIVATE (wparam = WA_INACTIVE) is sent on Windows. It is
2592 * not reliable on X11 WMs. When the window focus follows the
2593 * mouse pointer the message is not sent.
2594 * {WM_ACTIVATE, FOCUS_WINDOW, TRUE, WA_INACTIVE}, */
2595 {WM_DISPLAYCHANGE, DEVICE_WINDOW, FALSE, 0, D3DERR_DEVICENOTRESET},
2596 /* WM_DISPLAYCHANGE is sent to the focus window too, but the order is
2597 * not deterministic. */
2598 {WM_WINDOWPOSCHANGING, DEVICE_WINDOW, FALSE, 0, D3DERR_DEVICENOTRESET},
2599 /* Windows sends WM_ACTIVATE to the device window, indicating that
2600 * SW_SHOWMINIMIZED is used instead of SW_MINIMIZE. Yet afterwards
2601 * the foreground and focus window are NULL. On Wine SW_SHOWMINIMIZED
2602 * leaves the device window active, breaking re-activation in the
2603 * lost device test.
2604 * {WM_ACTIVATE, DEVICE_WINDOW, TRUE, 0x200000 | WA_ACTIVE}, */
2605 {WM_WINDOWPOSCHANGED, DEVICE_WINDOW, FALSE, 0, D3DERR_DEVICENOTRESET},
2606 {WM_SIZE, DEVICE_WINDOW, TRUE, SIZE_MINIMIZED,
2607 D3DERR_DEVICENOTRESET},
2608 {WM_ACTIVATEAPP, FOCUS_WINDOW, TRUE, FALSE, D3DERR_DEVICELOST},
2609 /* WM_ACTIVATEAPP is sent to the device window too, but the order is
2610 * not deterministic. It may be sent after the focus window handling
2611 * or before. */
2612 {0, 0, FALSE, 0, 0},
2614 static const struct message reactivate_messages[] =
2616 {WM_WINDOWPOSCHANGING, DEVICE_WINDOW, FALSE, 0},
2617 {WM_WINDOWPOSCHANGED, DEVICE_WINDOW, FALSE, 0},
2618 {WM_MOVE, DEVICE_WINDOW, FALSE, 0},
2619 {WM_ACTIVATEAPP, FOCUS_WINDOW, TRUE, TRUE},
2620 {0, 0, FALSE, 0},
2622 static const struct message focus_loss_messages_hidden[] =
2624 {WM_DISPLAYCHANGE, DEVICE_WINDOW, FALSE, 0},
2625 {WM_ACTIVATEAPP, FOCUS_WINDOW, TRUE, FALSE},
2626 {0, 0, FALSE, 0},
2628 static const struct message focus_loss_messages_filtered[] =
2630 /* WM_ACTIVATE is delivered to the window proc because it is
2631 * generated by SetForegroundWindow before the d3d routine
2632 * starts it work. Don't check for it due to focus-follows-mouse
2633 * WMs though. */
2634 {WM_DISPLAYCHANGE, FOCUS_WINDOW, FALSE, 0},
2635 {WM_ACTIVATEAPP, FOCUS_WINDOW, TRUE, FALSE},
2636 {0, 0, FALSE, 0},
2638 static const struct message reactivate_messages_filtered[] =
2640 {WM_ACTIVATEAPP, FOCUS_WINDOW, TRUE, TRUE},
2641 {0, 0, FALSE, 0},
2643 static const struct message sc_restore_messages[] =
2645 /* WM_SYSCOMMAND is delivered only once, after d3d has already
2646 * processed it. Our wndproc has no way to prevent d3d from
2647 * handling the message. The second DefWindowProc call done by
2648 * our wndproc doesn't do any changes to the window because it
2649 * is already restored due to d3d's handling. */
2650 {WM_WINDOWPOSCHANGING, FOCUS_WINDOW, FALSE, 0},
2651 {WM_WINDOWPOSCHANGED, FOCUS_WINDOW, FALSE, 0},
2652 {WM_SIZE, FOCUS_WINDOW, TRUE, SIZE_RESTORED},
2653 {WM_SYSCOMMAND, FOCUS_WINDOW, TRUE, SC_RESTORE},
2654 {0, 0, FALSE, 0},
2656 static const struct message sc_minimize_messages[] =
2658 {WM_SYSCOMMAND, FOCUS_WINDOW, TRUE, SC_MINIMIZE},
2659 {WM_WINDOWPOSCHANGING, FOCUS_WINDOW, FALSE, 0},
2660 {WM_WINDOWPOSCHANGED, FOCUS_WINDOW, FALSE, 0},
2661 {WM_MOVE, FOCUS_WINDOW, FALSE, 0},
2662 {WM_SIZE, FOCUS_WINDOW, TRUE, SIZE_MINIMIZED},
2663 {0, 0, FALSE, 0},
2665 static const struct message sc_maximize_messages[] =
2667 {WM_SYSCOMMAND, FOCUS_WINDOW, TRUE, SC_MAXIMIZE},
2668 {WM_WINDOWPOSCHANGING, FOCUS_WINDOW, FALSE, 0},
2669 {WM_WINDOWPOSCHANGED, FOCUS_WINDOW, FALSE, 0},
2670 {WM_MOVE, FOCUS_WINDOW, FALSE, 0},
2671 {WM_SIZE, FOCUS_WINDOW, TRUE, SIZE_MAXIMIZED},
2672 {0, 0, FALSE, 0},
2674 struct message mode_change_messages[] =
2676 {WM_WINDOWPOSCHANGING, DEVICE_WINDOW, FALSE, 0},
2677 {WM_WINDOWPOSCHANGED, DEVICE_WINDOW, FALSE, 0},
2678 {WM_SIZE, DEVICE_WINDOW, FALSE, 0},
2679 /* TODO: WM_DISPLAYCHANGE is sent to the focus window too, but the order is
2680 * differs between Wine and Windows. */
2681 /* TODO 2: Windows sends a second WM_WINDOWPOSCHANGING(SWP_NOMOVE | SWP_NOSIZE
2682 * | SWP_NOACTIVATE) in this situation, suggesting a difference in their ShowWindow
2683 * implementation. This SetWindowPos call could in theory affect the Z order. Wine's
2684 * ShowWindow does not send such a message because the window is already visible. */
2685 {0, 0, FALSE, 0},
2687 struct message mode_change_messages_hidden[] =
2689 {WM_WINDOWPOSCHANGING, DEVICE_WINDOW, FALSE, 0},
2690 {WM_WINDOWPOSCHANGED, DEVICE_WINDOW, FALSE, 0},
2691 {WM_SIZE, DEVICE_WINDOW, FALSE, 0},
2692 {WM_SHOWWINDOW, DEVICE_WINDOW, FALSE, 0},
2693 {WM_WINDOWPOSCHANGING, DEVICE_WINDOW, FALSE, 0, ~0U, &windowpos},
2694 {WM_WINDOWPOSCHANGED, DEVICE_WINDOW, FALSE, 0},
2695 /* TODO: WM_DISPLAYCHANGE is sent to the focus window too, but the order is
2696 * differs between Wine and Windows. */
2697 {0, 0, FALSE, 0},
2700 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
2701 ok(!!d3d8, "Failed to create a D3D object.\n");
2703 adapter_mode_count = IDirect3D8_GetAdapterModeCount(d3d8, D3DADAPTER_DEFAULT);
2704 for (i = 0; i < adapter_mode_count; ++i)
2706 hr = IDirect3D8_EnumAdapterModes(d3d8, D3DADAPTER_DEFAULT, i, &d3ddm);
2707 ok(SUCCEEDED(hr), "Failed to enumerate display mode, hr %#x.\n", hr);
2709 if (d3ddm.Format != D3DFMT_X8R8G8B8)
2710 continue;
2711 if (d3ddm.Width == registry_mode.dmPelsWidth && d3ddm.Height == registry_mode.dmPelsHeight)
2712 continue;
2713 /* The r200 driver on Windows XP enumerates modes like 320x200 and 320x240 but
2714 * refuses to create a device at these sizes. */
2715 if (d3ddm.Width < 640 || d3ddm.Height < 480)
2716 continue;
2718 if (!user32_width)
2720 user32_width = d3ddm.Width;
2721 user32_height = d3ddm.Height;
2722 continue;
2725 /* Make sure the d3d mode is smaller in width or height and at most
2726 * equal in the other dimension than the mode passed to
2727 * ChangeDisplaySettings. Otherwise Windows shrinks the window to
2728 * the ChangeDisplaySettings parameters + 12. */
2729 if (d3ddm.Width == user32_width && d3ddm.Height == user32_height)
2730 continue;
2731 if (d3ddm.Width <= user32_width && d3ddm.Height <= user32_height)
2733 d3d_width = d3ddm.Width;
2734 d3d_height = d3ddm.Height;
2735 break;
2737 if (user32_width <= d3ddm.Width && user32_height <= d3ddm.Height)
2739 d3d_width = user32_width;
2740 d3d_height = user32_height;
2741 user32_width = d3ddm.Width;
2742 user32_height = d3ddm.Height;
2743 break;
2747 if (!d3d_width)
2749 skip("Could not find adequate modes, skipping mode tests.\n");
2750 IDirect3D8_Release(d3d8);
2751 return;
2754 wc.lpfnWndProc = test_proc;
2755 wc.lpszClassName = "d3d8_test_wndproc_wc";
2756 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2758 thread_params.window_created = CreateEventA(NULL, FALSE, FALSE, NULL);
2759 ok(!!thread_params.window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
2760 thread_params.test_finished = CreateEventA(NULL, FALSE, FALSE, NULL);
2761 ok(!!thread_params.test_finished, "CreateEvent failed, last error %#x.\n", GetLastError());
2763 memset(&devmode, 0, sizeof(devmode));
2764 devmode.dmSize = sizeof(devmode);
2765 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
2766 devmode.dmPelsWidth = user32_width;
2767 devmode.dmPelsHeight = user32_height;
2768 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2769 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2771 focus_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
2772 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION , 0, 0, user32_width, user32_height, 0, 0, 0, 0);
2773 device_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
2774 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION , 0, 0, user32_width, user32_height, 0, 0, 0, 0);
2775 thread = CreateThread(NULL, 0, wndproc_thread, &thread_params, 0, &tid);
2776 ok(!!thread, "Failed to create thread, last error %#x.\n", GetLastError());
2778 res = WaitForSingleObject(thread_params.window_created, INFINITE);
2779 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
2781 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
2782 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2783 (LONG_PTR)test_proc, proc);
2784 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2785 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2786 (LONG_PTR)test_proc, proc);
2788 trace("device_window %p, focus_window %p, dummy_window %p.\n",
2789 device_window, focus_window, thread_params.dummy_window);
2791 tmp = GetFocus();
2792 ok(tmp == device_window, "Expected focus %p, got %p.\n", device_window, tmp);
2793 if (thread_params.running_in_foreground)
2795 tmp = GetForegroundWindow();
2796 ok(tmp == thread_params.dummy_window, "Expected foreground window %p, got %p.\n",
2797 thread_params.dummy_window, tmp);
2799 else
2800 skip("Not running in foreground, skip foreground window test\n");
2802 flush_events();
2804 expect_messages = create_messages;
2806 device_desc.device_window = device_window;
2807 device_desc.width = d3d_width;
2808 device_desc.height = d3d_height;
2809 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
2810 if (!(device = create_device(d3d8, focus_window, &device_desc)))
2812 skip("Failed to create a D3D device, skipping tests.\n");
2813 goto done;
2816 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
2817 expect_messages->message, expect_messages->window);
2818 expect_messages = NULL;
2820 if (0) /* Disabled until we can make this work in a reliable way on Wine. */
2822 tmp = GetFocus();
2823 ok(tmp == focus_window, "Expected focus %p, got %p.\n", focus_window, tmp);
2824 tmp = GetForegroundWindow();
2825 ok(tmp == focus_window, "Expected foreground window %p, got %p.\n", focus_window, tmp);
2827 SetForegroundWindow(focus_window);
2828 flush_events();
2830 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
2831 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2832 (LONG_PTR)test_proc, proc);
2834 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2835 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx.\n", (LONG_PTR)test_proc);
2837 /* Change the mode while the device is in use and then drop focus. */
2838 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
2839 devmode.dmPelsWidth = user32_width;
2840 devmode.dmPelsHeight = user32_height;
2841 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2842 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x, i=%u.\n", change_ret, i);
2844 /* Wine doesn't (yet) mark the device not reset when the mode is changed, thus the todo_wine.
2845 * But sometimes focus-follows-mouse WMs also temporarily drop window focus, which makes
2846 * mark the device lost, then not reset, causing the test to succeed for the wrong reason. */
2847 hr = IDirect3DDevice8_TestCooperativeLevel(device);
2848 todo_wine_if (hr != D3DERR_DEVICENOTRESET)
2849 ok(hr == D3DERR_DEVICENOTRESET, "Got unexpected hr %#x.\n", hr);
2851 expect_messages = focus_loss_messages;
2852 focus_test_device = device;
2853 /* SetForegroundWindow is a poor replacement for the user pressing alt-tab or
2854 * manually changing the focus. It generates the same messages, but the task
2855 * bar still shows the previous foreground window as active, and the window has
2856 * an inactive titlebar if reactivated with SetForegroundWindow. Reactivating
2857 * the device is difficult, see below. */
2858 SetForegroundWindow(GetDesktopWindow());
2859 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
2860 expect_messages->message, expect_messages->window);
2861 expect_messages = NULL;
2862 tmp = GetFocus();
2863 ok(tmp != device_window, "The device window is active.\n");
2864 ok(tmp != focus_window, "The focus window is active.\n");
2865 focus_test_device = NULL;
2867 /* The Present call is necessary to make native realize the device is lost. */
2868 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
2869 ok(hr == D3DERR_DEVICELOST, "Got unexpected hr %#x.\n", hr);
2870 hr = IDirect3DDevice8_TestCooperativeLevel(device);
2871 /* Focus-follows-mouse WMs prematurely reactivate our window. */
2872 todo_wine_if (hr == D3DERR_DEVICENOTRESET)
2873 ok(hr == D3DERR_DEVICELOST, "Got unexpected hr %#x.\n", hr);
2875 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2876 ok(ret, "Failed to get display mode.\n");
2877 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
2878 && devmode.dmPelsHeight == registry_mode.dmPelsHeight, "Got unexpect screen size %ux%u.\n",
2879 devmode.dmPelsWidth, devmode.dmPelsHeight);
2881 /* I have to minimize and restore the focus window, otherwise native d3d9 fails
2882 * device::reset with D3DERR_DEVICELOST. This does not happen when the window
2883 * restore is triggered by the user. */
2884 expect_messages = reactivate_messages;
2885 ShowWindow(focus_window, SW_MINIMIZE);
2886 ShowWindow(focus_window, SW_RESTORE);
2887 /* Set focus twice to make KDE and fvwm in focus-follows-mouse mode happy. */
2888 SetForegroundWindow(focus_window);
2889 flush_events();
2890 SetForegroundWindow(focus_window);
2891 flush_events(); /* WM_WINDOWPOSCHANGING etc arrive after SetForegroundWindow returns. */
2892 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it, i=%u.\n",
2893 expect_messages->message, expect_messages->window, i);
2894 expect_messages = NULL;
2896 hr = IDirect3DDevice8_TestCooperativeLevel(device);
2897 ok(hr == D3DERR_DEVICENOTRESET, "Got unexpected hr %#x.\n", hr);
2899 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2900 ok(ret, "Failed to get display mode.\n");
2901 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
2902 && devmode.dmPelsHeight == registry_mode.dmPelsHeight, "Got unexpect screen size %ux%u.\n",
2903 devmode.dmPelsWidth, devmode.dmPelsHeight);
2905 hr = reset_device(device, &device_desc);
2906 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
2908 /* Remove the WS_VISIBLE flag to test hidden windows. This is enough to trigger d3d's hidden
2909 * window codepath, but does not actually hide the window without a SetWindowPos(SWP_FRAMECHANGED)
2910 * call. This way we avoid focus changes and random failures on focus follows mouse WMs. */
2911 device_style = GetWindowLongA(device_window, GWL_STYLE);
2912 SetWindowLongA(device_window, GWL_STYLE, device_style & ~WS_VISIBLE);
2913 flush_events();
2915 expect_messages = focus_loss_messages_hidden;
2916 windowposchanged_received = 0;
2917 SetForegroundWindow(GetDesktopWindow());
2918 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
2919 expect_messages->message, expect_messages->window);
2920 ok(!windowposchanged_received, "Received WM_WINDOWPOSCHANGED but did not expect it.\n");
2921 expect_messages = NULL;
2922 flush_events();
2924 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2925 ok(ret, "Failed to get display mode.\n");
2926 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth, "Got unexpect width %u.\n", devmode.dmPelsWidth);
2927 ok(devmode.dmPelsHeight == registry_mode.dmPelsHeight, "Got unexpect height %u.\n", devmode.dmPelsHeight);
2929 /* SW_SHOWMINNOACTIVE is needed to make FVWM happy. SW_SHOWNOACTIVATE is needed to make windows
2930 * send SIZE_RESTORED after ShowWindow(SW_SHOWMINNOACTIVE). */
2931 ShowWindow(focus_window, SW_SHOWNOACTIVATE);
2932 ShowWindow(focus_window, SW_SHOWMINNOACTIVE);
2933 flush_events();
2935 syscommand_received = 0;
2936 expect_messages = sc_restore_messages;
2937 SendMessageA(focus_window, WM_SYSCOMMAND, SC_RESTORE, 0);
2938 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
2939 expect_messages->message, expect_messages->window);
2940 ok(syscommand_received == 1, "Got unexpected number of WM_SYSCOMMAND messages: %d.\n", syscommand_received);
2941 expect_messages = NULL;
2942 flush_events();
2944 expect_messages = sc_minimize_messages;
2945 SendMessageA(focus_window, WM_SYSCOMMAND, SC_MINIMIZE, 0);
2946 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
2947 expect_messages->message, expect_messages->window);
2948 expect_messages = NULL;
2949 flush_events();
2951 expect_messages = sc_maximize_messages;
2952 SendMessageA(focus_window, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
2953 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
2954 expect_messages->message, expect_messages->window);
2955 expect_messages = NULL;
2956 flush_events();
2958 SetForegroundWindow(GetDesktopWindow());
2959 ShowWindow(device_window, SW_MINIMIZE);
2960 ShowWindow(focus_window, SW_MINIMIZE);
2961 ShowWindow(focus_window, SW_RESTORE);
2962 SetForegroundWindow(focus_window);
2963 flush_events();
2965 /* Releasing a device in lost state breaks follow-up tests on native. */
2966 hr = reset_device(device, &device_desc);
2967 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
2969 filter_messages = focus_window;
2970 ref = IDirect3DDevice8_Release(device);
2971 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
2973 /* Fix up the mode until Wine's device release behavior is fixed. */
2974 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
2975 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2977 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2978 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2979 (LONG_PTR)test_proc, proc);
2981 /* Hide the device window. It prevents WM_ACTIVATEAPP messages from being sent
2982 * on native in the test below. It isn't needed anyways. Creating the third
2983 * device will show it again. */
2984 filter_messages = NULL;
2985 ShowWindow(device_window, SW_HIDE);
2986 /* Remove the maximized state from the SYSCOMMAND test while we're not
2987 * interfering with a device. */
2988 ShowWindow(focus_window, SW_SHOWNORMAL);
2989 filter_messages = focus_window;
2991 device_desc.device_window = focus_window;
2992 if (!(device = create_device(d3d8, focus_window, &device_desc)))
2994 skip("Failed to create a D3D device, skipping tests.\n");
2995 goto done;
2998 filter_messages = NULL;
3000 expect_messages = focus_loss_messages_filtered;
3001 windowposchanged_received = 0;
3002 SetForegroundWindow(GetDesktopWindow());
3003 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
3004 expect_messages->message, expect_messages->window);
3005 ok(!windowposchanged_received, "Received WM_WINDOWPOSCHANGED but did not expect it.\n");
3006 expect_messages = NULL;
3008 /* The window is iconic even though no message was sent. */
3009 ok(IsIconic(focus_window), "The focus window is not iconic.\n");
3011 hr = IDirect3DDevice8_TestCooperativeLevel(device);
3012 ok(hr == D3DERR_DEVICELOST, "Got unexpected hr %#x.\n", hr);
3014 syscommand_received = 0;
3015 expect_messages = sc_restore_messages;
3016 SendMessageA(focus_window, WM_SYSCOMMAND, SC_RESTORE, 0);
3017 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
3018 expect_messages->message, expect_messages->window);
3019 ok(syscommand_received == 1, "Got unexpected number of WM_SYSCOMMAND messages: %d.\n", syscommand_received);
3020 expect_messages = NULL;
3021 flush_events();
3023 /* For FVWM. */
3024 ShowWindow(focus_window, SW_RESTORE);
3025 flush_events();
3027 expect_messages = sc_minimize_messages;
3028 SendMessageA(focus_window, WM_SYSCOMMAND, SC_MINIMIZE, 0);
3029 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
3030 expect_messages->message, expect_messages->window);
3031 expect_messages = NULL;
3032 /* Needed to make the next test reliably send WM_SIZE(SIZE_MAXIMIZED). Without
3033 * this call it sends WM_SIZE(SIZE_RESTORED). */
3034 ShowWindow(focus_window, SW_RESTORE);
3035 flush_events();
3037 expect_messages = sc_maximize_messages;
3038 SendMessageA(focus_window, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
3039 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
3040 expect_messages->message, expect_messages->window);
3041 expect_messages = NULL;
3042 SetForegroundWindow(GetDesktopWindow());
3043 flush_events();
3045 /* ShowWindow(SW_RESTORE); SetForegroundWindow(desktop); SetForegroundWindow(focus);
3046 * results in the second SetForegroundWindow call failing and the device not being
3047 * restored on native. Directly using ShowWindow(SW_RESTORE) works, but it means
3048 * we cannot test for the absence of WM_WINDOWPOSCHANGED messages. */
3049 expect_messages = reactivate_messages_filtered;
3050 ShowWindow(focus_window, SW_RESTORE);
3051 SetForegroundWindow(focus_window);
3052 flush_events();
3053 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it\n",
3054 expect_messages->message, expect_messages->window);
3055 expect_messages = NULL;
3057 filter_messages = focus_window;
3058 hr = IDirect3DDevice8_TestCooperativeLevel(device);
3059 ok(hr == D3DERR_DEVICENOTRESET, "Got unexpected hr %#x.\n", hr);
3061 hr = reset_device(device, &device_desc);
3062 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
3064 ref = IDirect3DDevice8_Release(device);
3065 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
3066 filter_messages = NULL;
3068 ShowWindow(device_window, SW_RESTORE);
3069 SetForegroundWindow(focus_window);
3070 flush_events();
3072 filter_messages = focus_window;
3073 device_desc.device_window = device_window;
3074 if (!(device = create_device(d3d8, focus_window, &device_desc)))
3076 skip("Failed to create a D3D device, skipping tests.\n");
3077 goto done;
3079 filter_messages = NULL;
3080 flush_events();
3082 device_desc.width = user32_width;
3083 device_desc.height = user32_height;
3085 expect_messages = mode_change_messages;
3086 filter_messages = focus_window;
3087 hr = reset_device(device, &device_desc);
3088 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
3089 filter_messages = NULL;
3091 flush_events();
3092 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it, i=%u.\n",
3093 expect_messages->message, expect_messages->window, i);
3095 /* World of Warplanes hides the window by removing WS_VISIBLE and expects Reset() to show it again. */
3096 device_style = GetWindowLongA(device_window, GWL_STYLE);
3097 SetWindowLongA(device_window, GWL_STYLE, device_style & ~WS_VISIBLE);
3099 flush_events();
3100 device_desc.width = d3d_width;
3101 device_desc.height = d3d_height;
3102 memset(&windowpos, 0, sizeof(windowpos));
3104 expect_messages = mode_change_messages_hidden;
3105 filter_messages = focus_window;
3106 hr = reset_device(device, &device_desc);
3107 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
3108 filter_messages = NULL;
3110 flush_events();
3111 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
3112 expect_messages->message, expect_messages->window);
3114 ok(windowpos.hwnd == device_window && !windowpos.hwndInsertAfter
3115 && !windowpos.x && !windowpos.y && !windowpos.cx && !windowpos.cy
3116 && windowpos.flags == (SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE),
3117 "Got unexpected WINDOWPOS hwnd=%p, insertAfter=%p, x=%d, y=%d, cx=%d, cy=%d, flags=%x\n",
3118 windowpos.hwnd, windowpos.hwndInsertAfter, windowpos.x, windowpos.y, windowpos.cx,
3119 windowpos.cy, windowpos.flags);
3121 device_style = GetWindowLongA(device_window, GWL_STYLE);
3122 ok(device_style & WS_VISIBLE, "Expected the device window to be visible.\n");
3124 proc = SetWindowLongPtrA(focus_window, GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
3125 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx.\n", (LONG_PTR)test_proc);
3127 ref = IDirect3DDevice8_Release(device);
3128 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
3130 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3131 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
3132 (LONG_PTR)DefWindowProcA, proc);
3134 done:
3135 filter_messages = NULL;
3136 IDirect3D8_Release(d3d8);
3138 SetEvent(thread_params.test_finished);
3139 WaitForSingleObject(thread, INFINITE);
3140 CloseHandle(thread_params.test_finished);
3141 CloseHandle(thread_params.window_created);
3142 CloseHandle(thread);
3144 DestroyWindow(device_window);
3145 DestroyWindow(focus_window);
3146 UnregisterClassA("d3d8_test_wndproc_wc", GetModuleHandleA(NULL));
3149 static void test_wndproc_windowed(void)
3151 struct wndproc_thread_param thread_params;
3152 struct device_desc device_desc;
3153 IDirect3DDevice8 *device;
3154 WNDCLASSA wc = {0};
3155 IDirect3D8 *d3d8;
3156 HANDLE thread;
3157 LONG_PTR proc;
3158 HRESULT hr;
3159 ULONG ref;
3160 DWORD res, tid;
3161 HWND tmp;
3163 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
3164 ok(!!d3d8, "Failed to create a D3D object.\n");
3166 wc.lpfnWndProc = test_proc;
3167 wc.lpszClassName = "d3d8_test_wndproc_wc";
3168 ok(RegisterClassA(&wc), "Failed to register window class.\n");
3170 thread_params.window_created = CreateEventA(NULL, FALSE, FALSE, NULL);
3171 ok(!!thread_params.window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
3172 thread_params.test_finished = CreateEventA(NULL, FALSE, FALSE, NULL);
3173 ok(!!thread_params.test_finished, "CreateEvent failed, last error %#x.\n", GetLastError());
3175 focus_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
3176 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, registry_mode.dmPelsWidth,
3177 registry_mode.dmPelsHeight, 0, 0, 0, 0);
3178 device_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
3179 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, registry_mode.dmPelsWidth,
3180 registry_mode.dmPelsHeight, 0, 0, 0, 0);
3181 thread = CreateThread(NULL, 0, wndproc_thread, &thread_params, 0, &tid);
3182 ok(!!thread, "Failed to create thread, last error %#x.\n", GetLastError());
3184 res = WaitForSingleObject(thread_params.window_created, INFINITE);
3185 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
3187 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
3188 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3189 (LONG_PTR)test_proc, proc);
3190 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3191 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3192 (LONG_PTR)test_proc, proc);
3194 trace("device_window %p, focus_window %p, dummy_window %p.\n",
3195 device_window, focus_window, thread_params.dummy_window);
3197 tmp = GetFocus();
3198 ok(tmp == device_window, "Expected focus %p, got %p.\n", device_window, tmp);
3199 if (thread_params.running_in_foreground)
3201 tmp = GetForegroundWindow();
3202 ok(tmp == thread_params.dummy_window, "Expected foreground window %p, got %p.\n",
3203 thread_params.dummy_window, tmp);
3205 else
3206 skip("Not running in foreground, skip foreground window test\n");
3208 filter_messages = focus_window;
3210 device_desc.device_window = device_window;
3211 device_desc.width = registry_mode.dmPelsWidth;
3212 device_desc.height = registry_mode.dmPelsHeight;
3213 device_desc.flags = 0;
3214 if (!(device = create_device(d3d8, focus_window, &device_desc)))
3216 skip("Failed to create a D3D device, skipping tests.\n");
3217 goto done;
3220 tmp = GetFocus();
3221 ok(tmp == device_window, "Expected focus %p, got %p.\n", device_window, tmp);
3222 tmp = GetForegroundWindow();
3223 ok(tmp == thread_params.dummy_window, "Expected foreground window %p, got %p.\n",
3224 thread_params.dummy_window, tmp);
3226 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
3227 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3228 (LONG_PTR)test_proc, proc);
3230 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3231 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3232 (LONG_PTR)test_proc, proc);
3234 filter_messages = NULL;
3236 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
3237 hr = reset_device(device, &device_desc);
3238 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
3240 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
3241 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3242 (LONG_PTR)test_proc, proc);
3244 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3245 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx.\n", (LONG_PTR)test_proc);
3247 device_desc.flags = 0;
3248 hr = reset_device(device, &device_desc);
3249 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
3251 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
3252 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3253 (LONG_PTR)test_proc, proc);
3255 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3256 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3257 (LONG_PTR)test_proc, proc);
3259 filter_messages = focus_window;
3261 ref = IDirect3DDevice8_Release(device);
3262 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
3264 filter_messages = device_window;
3266 device_desc.device_window = focus_window;
3267 if (!(device = create_device(d3d8, focus_window, &device_desc)))
3269 skip("Failed to create a D3D device, skipping tests.\n");
3270 goto done;
3273 filter_messages = NULL;
3275 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
3276 hr = reset_device(device, &device_desc);
3277 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
3279 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
3280 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3281 (LONG_PTR)test_proc, proc);
3283 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3284 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx.\n", (LONG_PTR)test_proc);
3286 device_desc.flags = 0;
3287 hr = reset_device(device, &device_desc);
3288 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
3290 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
3291 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3292 (LONG_PTR)test_proc, proc);
3294 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3295 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3296 (LONG_PTR)test_proc, proc);
3298 filter_messages = device_window;
3300 ref = IDirect3DDevice8_Release(device);
3301 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
3303 device_desc.device_window = device_window;
3304 if (!(device = create_device(d3d8, focus_window, &device_desc)))
3306 skip("Failed to create a D3D device, skipping tests.\n");
3307 goto done;
3310 filter_messages = NULL;
3312 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
3313 hr = reset_device(device, &device_desc);
3314 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
3316 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
3317 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3318 (LONG_PTR)test_proc, proc);
3320 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3321 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx.\n", (LONG_PTR)test_proc);
3323 device_desc.flags = 0;
3324 hr = reset_device(device, &device_desc);
3325 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
3327 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
3328 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3329 (LONG_PTR)test_proc, proc);
3331 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3332 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3333 (LONG_PTR)test_proc, proc);
3335 filter_messages = device_window;
3337 ref = IDirect3DDevice8_Release(device);
3338 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
3340 done:
3341 filter_messages = NULL;
3342 IDirect3D8_Release(d3d8);
3344 SetEvent(thread_params.test_finished);
3345 WaitForSingleObject(thread, INFINITE);
3346 CloseHandle(thread_params.test_finished);
3347 CloseHandle(thread_params.window_created);
3348 CloseHandle(thread);
3350 DestroyWindow(device_window);
3351 DestroyWindow(focus_window);
3352 UnregisterClassA("d3d8_test_wndproc_wc", GetModuleHandleA(NULL));
3355 static inline void set_fpu_cw(WORD cw)
3357 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3358 #define D3D8_TEST_SET_FPU_CW 1
3359 __asm__ volatile ("fnclex");
3360 __asm__ volatile ("fldcw %0" : : "m" (cw));
3361 #elif defined(__i386__) && defined(_MSC_VER)
3362 #define D3D8_TEST_SET_FPU_CW 1
3363 __asm fnclex;
3364 __asm fldcw cw;
3365 #endif
3368 static inline WORD get_fpu_cw(void)
3370 WORD cw = 0;
3371 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3372 #define D3D8_TEST_GET_FPU_CW 1
3373 __asm__ volatile ("fnstcw %0" : "=m" (cw));
3374 #elif defined(__i386__) && defined(_MSC_VER)
3375 #define D3D8_TEST_GET_FPU_CW 1
3376 __asm fnstcw cw;
3377 #endif
3378 return cw;
3381 static WORD callback_cw, callback_set_cw;
3382 static DWORD callback_tid;
3384 static HRESULT WINAPI dummy_object_QueryInterface(IUnknown *iface, REFIID riid, void **out)
3386 *out = NULL;
3387 return E_NOINTERFACE;
3390 static ULONG WINAPI dummy_object_AddRef(IUnknown *iface)
3392 callback_cw = get_fpu_cw();
3393 set_fpu_cw(callback_set_cw);
3394 callback_tid = GetCurrentThreadId();
3395 return 2;
3398 static ULONG WINAPI dummy_object_Release(IUnknown *iface)
3400 callback_cw = get_fpu_cw();
3401 set_fpu_cw(callback_set_cw);
3402 callback_tid = GetCurrentThreadId();
3403 return 1;
3406 static const IUnknownVtbl dummy_object_vtbl =
3408 dummy_object_QueryInterface,
3409 dummy_object_AddRef,
3410 dummy_object_Release,
3413 static const GUID d3d8_private_data_test_guid =
3415 0xfdb37466,
3416 0x428f,
3417 0x4edf,
3418 {0xa3,0x7f,0x9b,0x1d,0xf4,0x88,0xc5,0xfc}
3421 static void test_fpu_setup(void)
3423 #if defined(D3D8_TEST_SET_FPU_CW) && defined(D3D8_TEST_GET_FPU_CW)
3424 struct device_desc device_desc;
3425 IDirect3DDevice8 *device;
3426 D3DDISPLAYMODE d3ddm;
3427 IDirect3D8 *d3d8;
3428 HWND window;
3429 HRESULT hr;
3430 WORD cw;
3431 IDirect3DSurface8 *surface;
3432 IUnknown dummy_object = {&dummy_object_vtbl};
3434 window = create_window();
3435 ok(!!window, "Failed to create a window.\n");
3436 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
3437 ok(!!d3d8, "Failed to create a D3D object.\n");
3439 hr = IDirect3D8_GetAdapterDisplayMode(d3d8, D3DADAPTER_DEFAULT, &d3ddm);
3440 ok(SUCCEEDED(hr), "GetAdapterDisplayMode failed, hr %#x.\n", hr);
3442 device_desc.device_window = window;
3443 device_desc.width = 640;
3444 device_desc.height = 480;
3445 device_desc.flags = 0;
3447 set_fpu_cw(0xf60);
3448 cw = get_fpu_cw();
3449 ok(cw == 0xf60, "cw is %#x, expected 0xf60.\n", cw);
3451 if (!(device = create_device(d3d8, window, &device_desc)))
3453 skip("Failed to create a 3D device, skipping test.\n");
3454 set_fpu_cw(0x37f);
3455 goto done;
3458 cw = get_fpu_cw();
3459 ok(cw == 0x7f, "cw is %#x, expected 0x7f.\n", cw);
3461 hr = IDirect3DDevice8_GetRenderTarget(device, &surface);
3462 ok(SUCCEEDED(hr), "Failed to get render target surface, hr %#x.\n", hr);
3464 callback_set_cw = 0xf60;
3465 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
3466 &dummy_object, sizeof(IUnknown *), D3DSPD_IUNKNOWN);
3467 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
3468 ok(callback_cw == 0x7f, "Callback cw is %#x, expected 0x7f.\n", callback_cw);
3469 ok(callback_tid == GetCurrentThreadId(), "Got unexpected thread id.\n");
3470 cw = get_fpu_cw();
3471 ok(cw == 0xf60, "cw is %#x, expected 0xf60.\n", cw);
3473 callback_cw = 0;
3474 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
3475 &dummy_object, sizeof(IUnknown *), D3DSPD_IUNKNOWN);
3476 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
3477 ok(callback_cw == 0xf60, "Callback cw is %#x, expected 0xf60.\n", callback_cw);
3478 ok(callback_tid == GetCurrentThreadId(), "Got unexpected thread id.\n");
3480 callback_set_cw = 0x7f;
3481 set_fpu_cw(0x7f);
3483 IDirect3DSurface8_Release(surface);
3485 callback_cw = 0;
3486 IDirect3DDevice8_Release(device);
3487 ok(callback_cw == 0x7f, "Callback cw is %#x, expected 0x7f.\n", callback_cw);
3488 ok(callback_tid == GetCurrentThreadId(), "Got unexpected thread id.\n");
3490 cw = get_fpu_cw();
3491 ok(cw == 0x7f, "cw is %#x, expected 0x7f.\n", cw);
3492 set_fpu_cw(0xf60);
3493 cw = get_fpu_cw();
3494 ok(cw == 0xf60, "cw is %#x, expected 0xf60.\n", cw);
3496 device_desc.flags = CREATE_DEVICE_FPU_PRESERVE;
3497 device = create_device(d3d8, window, &device_desc);
3498 ok(!!device, "CreateDevice failed.\n");
3500 cw = get_fpu_cw();
3501 ok(cw == 0xf60, "cw is %#x, expected 0xf60.\n", cw);
3503 hr = IDirect3DDevice8_GetRenderTarget(device, &surface);
3504 ok(SUCCEEDED(hr), "Failed to get render target surface, hr %#x.\n", hr);
3506 callback_cw = 0;
3507 callback_set_cw = 0x37f;
3508 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
3509 &dummy_object, sizeof(IUnknown *), D3DSPD_IUNKNOWN);
3510 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
3511 ok(callback_cw == 0xf60, "Callback cw is %#x, expected 0xf60.\n", callback_cw);
3512 ok(callback_tid == GetCurrentThreadId(), "Got unexpected thread id.\n");
3513 cw = get_fpu_cw();
3514 ok(cw == 0x37f, "cw is %#x, expected 0x37f.\n", cw);
3516 IDirect3DSurface8_Release(surface);
3518 callback_cw = 0;
3519 IDirect3DDevice8_Release(device);
3520 ok(callback_cw == 0x37f, "Callback cw is %#x, expected 0x37f.\n", callback_cw);
3521 ok(callback_tid == GetCurrentThreadId(), "Got unexpected thread id.\n");
3523 done:
3524 DestroyWindow(window);
3525 IDirect3D8_Release(d3d8);
3526 #endif
3529 static void test_ApplyStateBlock(void)
3531 IDirect3DDevice8 *device;
3532 IDirect3D8 *d3d8;
3533 HWND window;
3534 HRESULT hr;
3535 DWORD received, token;
3537 window = create_window();
3538 ok(!!window, "Failed to create a window.\n");
3539 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
3540 ok(!!d3d8, "Failed to create a D3D object.\n");
3541 if (!(device = create_device(d3d8, window, NULL)))
3543 skip("Failed to create a 3D device, skipping test.\n");
3544 goto cleanup;
3547 IDirect3DDevice8_BeginStateBlock(device);
3548 IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, TRUE);
3549 IDirect3DDevice8_EndStateBlock(device, &token);
3550 ok(token, "Received zero stateblock handle.\n");
3551 IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, FALSE);
3553 hr = IDirect3DDevice8_GetRenderState(device, D3DRS_ZENABLE, &received);
3554 ok(hr == D3D_OK, "Expected D3D_OK, received %#x.\n", hr);
3555 ok(!received, "Expected = FALSE, received TRUE.\n");
3557 hr = IDirect3DDevice8_ApplyStateBlock(device, 0);
3558 ok(hr == D3D_OK, "Expected D3D_OK, received %#x.\n", hr);
3559 hr = IDirect3DDevice8_GetRenderState(device, D3DRS_ZENABLE, &received);
3560 ok(hr == D3D_OK, "Expected D3D_OK, received %#x.\n", hr);
3561 ok(!received, "Expected FALSE, received TRUE.\n");
3563 hr = IDirect3DDevice8_ApplyStateBlock(device, token);
3564 ok(hr == D3D_OK, "Expected D3D_OK, received %#x.\n", hr);
3565 hr = IDirect3DDevice8_GetRenderState(device, D3DRS_ZENABLE, &received);
3566 ok(hr == D3D_OK, "Expected D3D_OK, received %#x.\n", hr);
3567 ok(received, "Expected TRUE, received FALSE.\n");
3569 IDirect3DDevice8_DeleteStateBlock(device, token);
3570 IDirect3DDevice8_Release(device);
3571 cleanup:
3572 IDirect3D8_Release(d3d8);
3573 DestroyWindow(window);
3576 static void test_depth_stencil_size(void)
3578 IDirect3DDevice8 *device;
3579 IDirect3DSurface8 *ds, *rt, *ds_bigger, *ds_bigger2;
3580 IDirect3DSurface8 *surf;
3581 IDirect3D8 *d3d8;
3582 HRESULT hr;
3583 HWND hwnd;
3585 hwnd = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
3586 100, 100, 160, 160, NULL, NULL, NULL, NULL);
3587 ok(!!hwnd, "Failed to create a window.\n");
3588 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
3589 ok(!!d3d8, "Failed to create a D3D object.\n");
3591 if (!(device = create_device(d3d8, hwnd, NULL)))
3593 skip("Failed to create a 3D device, skipping test.\n");
3594 goto cleanup;
3597 hr = IDirect3DDevice8_CreateRenderTarget(device, 64, 64, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, FALSE, &rt);
3598 ok(SUCCEEDED(hr), "IDirect3DDevice8_CreateRenderTarget failed, hr %#x.\n", hr);
3599 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 32, 32, D3DFMT_D24X8, D3DMULTISAMPLE_NONE, &ds);
3600 ok(SUCCEEDED(hr), "IDirect3DDevice8_CreateDepthStencilSurface failed, hr %#x.\n", hr);
3601 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 128, 128, D3DFMT_D24X8, D3DMULTISAMPLE_NONE, &ds_bigger);
3602 ok(SUCCEEDED(hr), "IDirect3DDevice8_CreateDepthStencilSurface failed, hr %#x.\n", hr);
3603 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 128, 128, D3DFMT_D24X8, D3DMULTISAMPLE_NONE, &ds_bigger2);
3604 ok(SUCCEEDED(hr), "IDirect3DDevice8_CreateDepthStencilSurface failed, hr %#x.\n", hr);
3606 hr = IDirect3DDevice8_SetRenderTarget(device, rt, ds);
3607 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_SetRenderTarget returned %#x, expected D3DERR_INVALIDCALL.\n", hr);
3608 hr = IDirect3DDevice8_SetRenderTarget(device, rt, ds_bigger);
3609 ok(SUCCEEDED(hr), "IDirect3DDevice8_SetRenderTarget failed, hr %#x.\n", hr);
3611 /* try to set the small ds without changing the render target at the same time */
3612 hr = IDirect3DDevice8_SetRenderTarget(device, NULL, ds);
3613 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_SetRenderTarget returned %#x, expected D3DERR_INVALIDCALL.\n", hr);
3614 hr = IDirect3DDevice8_SetRenderTarget(device, NULL, ds_bigger2);
3615 ok(SUCCEEDED(hr), "IDirect3DDevice8_SetRenderTarget failed, hr %#x.\n", hr);
3617 hr = IDirect3DDevice8_GetRenderTarget(device, &surf);
3618 ok(hr == D3D_OK, "IDirect3DDevice8_GetRenderTarget failed, hr %#x.\n", hr);
3619 ok(surf == rt, "The render target is %p, expected %p\n", surf, rt);
3620 IDirect3DSurface8_Release(surf);
3621 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surf);
3622 ok(hr == D3D_OK, "IDirect3DDevice8_GetDepthStencilSurface failed, hr %#x.\n", hr);
3623 ok(surf == ds_bigger2, "The depth stencil is %p, expected %p\n", surf, ds_bigger2);
3624 IDirect3DSurface8_Release(surf);
3626 hr = IDirect3DDevice8_SetRenderTarget(device, NULL, NULL);
3627 ok(SUCCEEDED(hr), "IDirect3DDevice8_SetRenderTarget failed, hr %#x.\n", hr);
3628 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surf);
3629 ok(FAILED(hr), "IDirect3DDevice8_GetDepthStencilSurface should have failed, hr %#x.\n", hr);
3630 ok(surf == NULL, "The depth stencil is %p, expected NULL\n", surf);
3631 if (surf) IDirect3DSurface8_Release(surf);
3633 IDirect3DSurface8_Release(rt);
3634 IDirect3DSurface8_Release(ds);
3635 IDirect3DSurface8_Release(ds_bigger);
3636 IDirect3DSurface8_Release(ds_bigger2);
3638 cleanup:
3639 IDirect3D8_Release(d3d8);
3640 DestroyWindow(hwnd);
3643 static void test_window_style(void)
3645 RECT focus_rect, fullscreen_rect, r;
3646 LONG device_style, device_exstyle;
3647 LONG focus_style, focus_exstyle;
3648 struct device_desc device_desc;
3649 LONG style, expected_style;
3650 IDirect3DDevice8 *device;
3651 IDirect3D8 *d3d8;
3652 HRESULT hr;
3653 ULONG ref;
3654 BOOL ret;
3656 focus_window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
3657 0, 0, registry_mode.dmPelsWidth / 2, registry_mode.dmPelsHeight / 2, 0, 0, 0, 0);
3658 device_window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
3659 0, 0, registry_mode.dmPelsWidth / 2, registry_mode.dmPelsHeight / 2, 0, 0, 0, 0);
3660 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
3661 ok(!!d3d8, "Failed to create a D3D object.\n");
3663 device_style = GetWindowLongA(device_window, GWL_STYLE);
3664 device_exstyle = GetWindowLongA(device_window, GWL_EXSTYLE);
3665 focus_style = GetWindowLongA(focus_window, GWL_STYLE);
3666 focus_exstyle = GetWindowLongA(focus_window, GWL_EXSTYLE);
3668 SetRect(&fullscreen_rect, 0, 0, registry_mode.dmPelsWidth, registry_mode.dmPelsHeight);
3669 GetWindowRect(focus_window, &focus_rect);
3671 device_desc.device_window = device_window;
3672 device_desc.width = registry_mode.dmPelsWidth;
3673 device_desc.height = registry_mode.dmPelsHeight;
3674 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
3675 if (!(device = create_device(d3d8, focus_window, &device_desc)))
3677 skip("Failed to create a D3D device, skipping tests.\n");
3678 goto done;
3681 style = GetWindowLongA(device_window, GWL_STYLE);
3682 expected_style = device_style | WS_VISIBLE;
3683 todo_wine ok(style == expected_style, "Expected device window style %#x, got %#x.\n",
3684 expected_style, style);
3685 style = GetWindowLongA(device_window, GWL_EXSTYLE);
3686 expected_style = device_exstyle | WS_EX_TOPMOST;
3687 todo_wine ok(style == expected_style, "Expected device window extended style %#x, got %#x.\n",
3688 expected_style, style);
3690 style = GetWindowLongA(focus_window, GWL_STYLE);
3691 ok(style == focus_style, "Expected focus window style %#x, got %#x.\n",
3692 focus_style, style);
3693 style = GetWindowLongA(focus_window, GWL_EXSTYLE);
3694 ok(style == focus_exstyle, "Expected focus window extended style %#x, got %#x.\n",
3695 focus_exstyle, style);
3697 GetWindowRect(device_window, &r);
3698 ok(EqualRect(&r, &fullscreen_rect), "Expected %s, got %s.\n",
3699 wine_dbgstr_rect(&fullscreen_rect), wine_dbgstr_rect(&r));
3700 GetClientRect(device_window, &r);
3701 todo_wine ok(!EqualRect(&r, &fullscreen_rect), "Client rect and window rect are equal.\n");
3702 GetWindowRect(focus_window, &r);
3703 ok(EqualRect(&r, &focus_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&focus_rect),
3704 wine_dbgstr_rect(&r));
3706 device_desc.flags = 0;
3707 hr = reset_device(device, &device_desc);
3708 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
3710 style = GetWindowLongA(device_window, GWL_STYLE);
3711 expected_style = device_style | WS_VISIBLE;
3712 ok(style == expected_style, "Expected device window style %#x, got %#x.\n",
3713 expected_style, style);
3714 style = GetWindowLongA(device_window, GWL_EXSTYLE);
3715 expected_style = device_exstyle | WS_EX_TOPMOST;
3716 ok(style == expected_style, "Expected device window extended style %#x, got %#x.\n",
3717 expected_style, style);
3719 style = GetWindowLongA(focus_window, GWL_STYLE);
3720 ok(style == focus_style, "Expected focus window style %#x, got %#x.\n",
3721 focus_style, style);
3722 style = GetWindowLongA(focus_window, GWL_EXSTYLE);
3723 ok(style == focus_exstyle, "Expected focus window extended style %#x, got %#x.\n",
3724 focus_exstyle, style);
3726 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
3727 hr = reset_device(device, &device_desc);
3728 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
3729 ret = SetForegroundWindow(GetDesktopWindow());
3730 ok(ret, "Failed to set foreground window.\n");
3732 style = GetWindowLongA(device_window, GWL_STYLE);
3733 expected_style = device_style | WS_MINIMIZE | WS_VISIBLE;
3734 todo_wine ok(style == expected_style, "Expected device window style %#x, got %#x.\n",
3735 expected_style, style);
3736 style = GetWindowLongA(device_window, GWL_EXSTYLE);
3737 expected_style = device_exstyle | WS_EX_TOPMOST;
3738 todo_wine ok(style == expected_style, "Expected device window extended style %#x, got %#x.\n",
3739 expected_style, style);
3741 style = GetWindowLongA(focus_window, GWL_STYLE);
3742 ok(style == focus_style, "Expected focus window style %#x, got %#x.\n",
3743 focus_style, style);
3744 style = GetWindowLongA(focus_window, GWL_EXSTYLE);
3745 ok(style == focus_exstyle, "Expected focus window extended style %#x, got %#x.\n",
3746 focus_exstyle, style);
3748 /* Follow-up tests fail on native if the device is destroyed while lost. */
3749 ShowWindow(focus_window, SW_MINIMIZE);
3750 ShowWindow(focus_window, SW_RESTORE);
3751 ret = SetForegroundWindow(focus_window);
3752 ok(ret, "Failed to set foreground window.\n");
3753 flush_events();
3754 hr = reset_device(device, &device_desc);
3755 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
3757 ref = IDirect3DDevice8_Release(device);
3758 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
3760 done:
3761 IDirect3D8_Release(d3d8);
3763 DestroyWindow(device_window);
3764 DestroyWindow(focus_window);
3767 static void test_unsupported_shaders(void)
3769 IDirect3DDevice8 *device;
3770 IDirect3D8 *d3d;
3771 ULONG refcount;
3772 DWORD vs, ps;
3773 HWND window;
3774 HRESULT hr;
3775 D3DCAPS8 caps;
3777 static const DWORD vs_2_0[] =
3779 0xfffe0200, /* vs_2_0 */
3780 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
3781 0x02000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
3782 0x03000002, 0xd00f0000, 0x80e40001, 0xa0e40002, /* add oD0, r1, c2 */
3783 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
3784 0x0000ffff /* end */
3786 static const DWORD ps_2_0[] =
3788 0xffff0200, /* ps_2_0 */
3789 0x02000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
3790 0x03000002, 0x800f0000, 0x80e40001, 0xa0e40002, /* add r0, r1, c2 */
3791 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
3792 0x0000ffff /* end */
3794 #if 0
3795 vs_1_1
3796 dcl_position v0
3797 def c255, 1.0, 1.0, 1.0, 1.0
3798 add r0, v0, c255
3799 mov oPos, r0
3800 #endif
3801 static const DWORD vs_1_255[] =
3803 0xfffe0101,
3804 0x0000001f, 0x80000000, 0x900f0000,
3805 0x00000051, 0xa00f00ff, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
3806 0x00000002, 0x800f0000, 0x90e40000, 0xa0e400ff,
3807 0x00000001, 0xc00f0000, 0x80e40000,
3808 0x0000ffff
3810 #if 0
3811 vs_1_1
3812 dcl_position v0
3813 def c256, 1.0, 1.0, 1.0, 1.0
3814 add r0, v0, c256
3815 mov oPos, r0
3816 #endif
3817 static const DWORD vs_1_256[] =
3819 0xfffe0101,
3820 0x0000001f, 0x80000000, 0x900f0000,
3821 0x00000051, 0xa00f0100, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
3822 0x00000002, 0x800f0000, 0x90e40000, 0xa0e40100,
3823 0x00000001, 0xc00f0000, 0x80e40000,
3824 0x0000ffff
3827 static const DWORD decl[] =
3829 D3DVSD_STREAM(0),
3830 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3),
3831 D3DVSD_END()
3834 window = create_window();
3835 ok(!!window, "Failed to create a window.\n");
3836 d3d = Direct3DCreate8(D3D_SDK_VERSION);
3837 ok(!!d3d, "Failed to create a D3D object.\n");
3838 if (!(device = create_device(d3d, window, NULL)))
3840 skip("Failed to create a D3D device, skipping tests.\n");
3841 IDirect3D8_Release(d3d);
3842 DestroyWindow(window);
3843 return;
3846 hr = IDirect3DDevice8_CreateVertexShader(device, decl, simple_ps, &vs, 0);
3847 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
3849 hr = IDirect3DDevice8_CreatePixelShader(device, simple_vs, &ps);
3850 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr);
3852 hr = IDirect3DDevice8_CreateVertexShader(device, decl, vs_2_0, &vs, 0);
3853 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
3855 hr = IDirect3DDevice8_CreatePixelShader(device, ps_2_0, &ps);
3856 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr);
3858 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
3859 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
3860 if (caps.MaxVertexShaderConst < 256)
3862 hr = IDirect3DDevice8_CreateVertexShader(device, decl, vs_1_255, &vs, 0);
3863 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3865 else
3867 hr = IDirect3DDevice8_CreateVertexShader(device, decl, vs_1_255, &vs, 0);
3868 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3869 hr = IDirect3DDevice8_DeleteVertexShader(device, vs);
3870 ok(hr == D3D_OK, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
3871 hr = IDirect3DDevice8_CreateVertexShader(device, decl, vs_1_256, &vs, 0);
3872 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3875 refcount = IDirect3DDevice8_Release(device);
3876 ok(!refcount, "Device has %u references left.\n", refcount);
3877 IDirect3D8_Release(d3d);
3878 DestroyWindow(window);
3881 static void test_mode_change(void)
3883 RECT d3d_rect, focus_rect, r;
3884 struct device_desc device_desc;
3885 IDirect3DSurface8 *backbuffer;
3886 IDirect3DDevice8 *device;
3887 D3DSURFACE_DESC desc;
3888 IDirect3D8 *d3d8;
3889 DEVMODEW devmode;
3890 ULONG refcount;
3891 UINT adapter_mode_count, i;
3892 HRESULT hr;
3893 BOOL ret;
3894 LONG change_ret;
3895 D3DDISPLAYMODE d3ddm;
3896 DWORD d3d_width = 0, d3d_height = 0, user32_width = 0, user32_height = 0;
3898 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
3899 ok(!!d3d8, "Failed to create a D3D object.\n");
3901 adapter_mode_count = IDirect3D8_GetAdapterModeCount(d3d8, D3DADAPTER_DEFAULT);
3902 for (i = 0; i < adapter_mode_count; ++i)
3904 hr = IDirect3D8_EnumAdapterModes(d3d8, D3DADAPTER_DEFAULT, i, &d3ddm);
3905 ok(SUCCEEDED(hr), "Failed to enumerate display mode, hr %#x.\n", hr);
3907 if (d3ddm.Format != D3DFMT_X8R8G8B8)
3908 continue;
3909 if (d3ddm.Width == registry_mode.dmPelsWidth && d3ddm.Height == registry_mode.dmPelsHeight)
3910 continue;
3911 /* The r200 driver on Windows XP enumerates modes like 320x200 and 320x240 but
3912 * refuses to create a device at these sizes. */
3913 if (d3ddm.Width < 640 || d3ddm.Height < 480)
3914 continue;
3916 if (!user32_width)
3918 user32_width = d3ddm.Width;
3919 user32_height = d3ddm.Height;
3920 continue;
3923 /* Make sure the d3d mode is smaller in width or height and at most
3924 * equal in the other dimension than the mode passed to
3925 * ChangeDisplaySettings. Otherwise Windows shrinks the window to
3926 * the ChangeDisplaySettings parameters + 12. */
3927 if (d3ddm.Width == user32_width && d3ddm.Height == user32_height)
3928 continue;
3929 if (d3ddm.Width <= user32_width && d3ddm.Height <= user32_height)
3931 d3d_width = d3ddm.Width;
3932 d3d_height = d3ddm.Height;
3933 break;
3935 if (user32_width <= d3ddm.Width && user32_height <= d3ddm.Height)
3937 d3d_width = user32_width;
3938 d3d_height = user32_height;
3939 user32_width = d3ddm.Width;
3940 user32_height = d3ddm.Height;
3941 break;
3945 if (!d3d_width)
3947 skip("Could not find adequate modes, skipping mode tests.\n");
3948 IDirect3D8_Release(d3d8);
3949 return;
3952 memset(&devmode, 0, sizeof(devmode));
3953 devmode.dmSize = sizeof(devmode);
3954 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
3955 devmode.dmPelsWidth = user32_width;
3956 devmode.dmPelsHeight = user32_height;
3957 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
3958 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
3960 /* Make the windows visible, otherwise device::release does not restore the mode if
3961 * the application is not in foreground like on the testbot. */
3962 focus_window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
3963 0, 0, user32_width / 2, user32_height / 2, 0, 0, 0, 0);
3964 device_window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
3965 0, 0, user32_width / 2, user32_height / 2, 0, 0, 0, 0);
3967 SetRect(&d3d_rect, 0, 0, d3d_width, d3d_height);
3968 GetWindowRect(focus_window, &focus_rect);
3970 device_desc.device_window = device_window;
3971 device_desc.width = d3d_width;
3972 device_desc.height = d3d_height;
3973 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
3974 if (!(device = create_device(d3d8, focus_window, &device_desc)))
3976 skip("Failed to create a D3D device, skipping tests.\n");
3977 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
3978 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
3979 goto done;
3982 devmode.dmPelsWidth = user32_width;
3983 devmode.dmPelsHeight = user32_height;
3984 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
3985 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
3987 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
3988 ok(ret, "Failed to get display mode.\n");
3989 ok(devmode.dmPelsWidth == user32_width && devmode.dmPelsHeight == user32_height,
3990 "Expected resolution %ux%u, got %ux%u.\n",
3991 user32_width, user32_height, devmode.dmPelsWidth, devmode.dmPelsHeight);
3993 GetWindowRect(device_window, &r);
3994 ok(EqualRect(&r, &d3d_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&d3d_rect),
3995 wine_dbgstr_rect(&r));
3996 GetWindowRect(focus_window, &r);
3997 ok(EqualRect(&r, &focus_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&focus_rect),
3998 wine_dbgstr_rect(&r));
4000 hr = IDirect3DDevice8_GetBackBuffer(device, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
4001 ok(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
4002 hr = IDirect3DSurface8_GetDesc(backbuffer, &desc);
4003 ok(SUCCEEDED(hr), "Failed to get backbuffer desc, hr %#x.\n", hr);
4004 ok(desc.Width == d3d_width, "Got unexpected backbuffer width %u, expected %u.\n",
4005 desc.Width, d3d_width);
4006 ok(desc.Height == d3d_height, "Got unexpected backbuffer height %u, expected %u.\n",
4007 desc.Height, d3d_height);
4008 IDirect3DSurface8_Release(backbuffer);
4010 refcount = IDirect3DDevice8_Release(device);
4011 ok(!refcount, "Device has %u references left.\n", refcount);
4013 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
4014 ok(ret, "Failed to get display mode.\n");
4015 todo_wine ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
4016 && devmode.dmPelsHeight == registry_mode.dmPelsHeight,
4017 "Expected resolution %ux%u, got %ux%u.\n",
4018 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight, devmode.dmPelsWidth, devmode.dmPelsHeight);
4020 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
4021 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
4023 /* The mode restore also happens when the device was created at the original screen size. */
4025 device_desc.device_window = device_window;
4026 device_desc.width = registry_mode.dmPelsWidth;
4027 device_desc.height = registry_mode.dmPelsHeight;
4028 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
4029 ok(!!(device = create_device(d3d8, focus_window, &device_desc)), "Failed to create a D3D device.\n");
4031 devmode.dmPelsWidth = user32_width;
4032 devmode.dmPelsHeight = user32_height;
4033 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
4034 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
4036 refcount = IDirect3DDevice8_Release(device);
4037 ok(!refcount, "Device has %u references left.\n", refcount);
4039 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
4040 ok(ret, "Failed to get display mode.\n");
4041 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
4042 && devmode.dmPelsHeight == registry_mode.dmPelsHeight,
4043 "Expected resolution %ux%u, got %ux%u.\n",
4044 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight, devmode.dmPelsWidth, devmode.dmPelsHeight);
4046 done:
4047 DestroyWindow(device_window);
4048 DestroyWindow(focus_window);
4049 IDirect3D8_Release(d3d8);
4052 static void test_device_window_reset(void)
4054 RECT fullscreen_rect, device_rect, r;
4055 struct device_desc device_desc;
4056 IDirect3DDevice8 *device;
4057 WNDCLASSA wc = {0};
4058 IDirect3D8 *d3d8;
4059 LONG_PTR proc;
4060 HRESULT hr;
4061 ULONG ref;
4063 wc.lpfnWndProc = test_proc;
4064 wc.lpszClassName = "d3d8_test_wndproc_wc";
4065 ok(RegisterClassA(&wc), "Failed to register window class.\n");
4067 focus_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
4068 0, 0, registry_mode.dmPelsWidth / 2, registry_mode.dmPelsHeight / 2, 0, 0, 0, 0);
4069 device_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
4070 0, 0, registry_mode.dmPelsWidth / 2, registry_mode.dmPelsHeight / 2, 0, 0, 0, 0);
4071 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
4072 ok(!!d3d8, "Failed to create a D3D object.\n");
4074 SetRect(&fullscreen_rect, 0, 0, registry_mode.dmPelsWidth, registry_mode.dmPelsHeight);
4075 GetWindowRect(device_window, &device_rect);
4077 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
4078 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
4079 (LONG_PTR)test_proc, proc);
4080 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
4081 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
4082 (LONG_PTR)test_proc, proc);
4084 device_desc.device_window = NULL;
4085 device_desc.width = registry_mode.dmPelsWidth;
4086 device_desc.height = registry_mode.dmPelsHeight;
4087 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
4088 if (!(device = create_device(d3d8, focus_window, &device_desc)))
4090 skip("Failed to create a D3D device, skipping tests.\n");
4091 goto done;
4094 GetWindowRect(focus_window, &r);
4095 ok(EqualRect(&r, &fullscreen_rect), "Expected %s, got %s.\n",
4096 wine_dbgstr_rect(&fullscreen_rect), wine_dbgstr_rect(&r));
4097 GetWindowRect(device_window, &r);
4098 ok(EqualRect(&r, &device_rect), "Expected %s, got %s.\n", wine_dbgstr_rect(&device_rect),
4099 wine_dbgstr_rect(&r));
4101 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
4102 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
4103 (LONG_PTR)test_proc, proc);
4104 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
4105 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx.\n", (LONG_PTR)test_proc);
4107 device_desc.device_window = device_window;
4108 hr = reset_device(device, &device_desc);
4109 ok(SUCCEEDED(hr), "Failed to reset device.\n");
4111 GetWindowRect(focus_window, &r);
4112 ok(EqualRect(&r, &fullscreen_rect), "Expected %s, got %s.\n",
4113 wine_dbgstr_rect(&fullscreen_rect), wine_dbgstr_rect(&r));
4114 GetWindowRect(device_window, &r);
4115 ok(EqualRect(&r, &fullscreen_rect), "Expected %s, got %s.\n",
4116 wine_dbgstr_rect(&fullscreen_rect), wine_dbgstr_rect(&r));
4118 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
4119 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
4120 (LONG_PTR)test_proc, proc);
4121 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
4122 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx.\n", (LONG_PTR)test_proc);
4124 ref = IDirect3DDevice8_Release(device);
4125 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
4127 done:
4128 IDirect3D8_Release(d3d8);
4129 DestroyWindow(device_window);
4130 DestroyWindow(focus_window);
4131 UnregisterClassA("d3d8_test_wndproc_wc", GetModuleHandleA(NULL));
4134 static void depth_blit_test(void)
4136 IDirect3DDevice8 *device = NULL;
4137 IDirect3DSurface8 *backbuffer, *ds1, *ds2, *ds3;
4138 RECT src_rect;
4139 const POINT dst_point = {0, 0};
4140 IDirect3D8 *d3d8;
4141 HRESULT hr;
4142 HWND hwnd;
4144 hwnd = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
4145 100, 100, 160, 160, NULL, NULL, NULL, NULL);
4146 ok(!!hwnd, "Failed to create a window.\n");
4147 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
4148 ok(!!d3d8, "Failed to create a D3D object.\n");
4150 if (!(device = create_device(d3d8, hwnd, NULL)))
4152 skip("Failed to create a D3D device, skipping tests.\n");
4153 goto done;
4156 hr = IDirect3DDevice8_GetRenderTarget(device, &backbuffer);
4157 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
4158 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &ds1);
4159 ok(SUCCEEDED(hr), "GetDepthStencilSurface failed, hr %#x.\n", hr);
4160 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 640, 480, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, &ds2);
4161 ok(SUCCEEDED(hr), "CreateDepthStencilSurface failed, hr %#x.\n", hr);
4162 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 640, 480, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, &ds3);
4163 ok(SUCCEEDED(hr), "CreateDepthStencilSurface failed, hr %#x.\n", hr);
4165 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0, 0.0f, 0);
4166 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
4168 /* Partial blit. */
4169 SetRect(&src_rect, 0, 0, 320, 240);
4170 hr = IDirect3DDevice8_CopyRects(device, ds1, &src_rect, 1, ds2, &dst_point);
4171 ok(hr == D3DERR_INVALIDCALL, "CopyRects returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
4172 /* Flipped. */
4173 SetRect(&src_rect, 0, 480, 640, 0);
4174 hr = IDirect3DDevice8_CopyRects(device, ds1, &src_rect, 1, ds2, &dst_point);
4175 ok(hr == D3DERR_INVALIDCALL, "CopyRects returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
4176 /* Full, explicit. */
4177 SetRect(&src_rect, 0, 0, 640, 480);
4178 hr = IDirect3DDevice8_CopyRects(device, ds1, &src_rect, 1, ds2, &dst_point);
4179 ok(hr == D3DERR_INVALIDCALL, "CopyRects returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
4180 /* Depth -> color blit.*/
4181 hr = IDirect3DDevice8_CopyRects(device, ds1, &src_rect, 1, backbuffer, &dst_point);
4182 ok(hr == D3DERR_INVALIDCALL, "CopyRects returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
4183 /* Full, NULL rects, current depth stencil -> unbound depth stencil */
4184 hr = IDirect3DDevice8_CopyRects(device, ds1, NULL, 0, ds2, NULL);
4185 ok(hr == D3DERR_INVALIDCALL, "CopyRects returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
4186 /* Full, NULL rects, unbound depth stencil -> current depth stencil */
4187 hr = IDirect3DDevice8_CopyRects(device, ds2, NULL, 0, ds1, NULL);
4188 ok(hr == D3DERR_INVALIDCALL, "CopyRects returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
4189 /* Full, NULL rects, unbound depth stencil -> unbound depth stencil */
4190 hr = IDirect3DDevice8_CopyRects(device, ds2, NULL, 0, ds3, NULL);
4191 ok(hr == D3DERR_INVALIDCALL, "CopyRects returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
4193 IDirect3DSurface8_Release(backbuffer);
4194 IDirect3DSurface8_Release(ds3);
4195 IDirect3DSurface8_Release(ds2);
4196 IDirect3DSurface8_Release(ds1);
4198 done:
4199 if (device) IDirect3DDevice8_Release(device);
4200 IDirect3D8_Release(d3d8);
4201 DestroyWindow(hwnd);
4204 static void test_reset_resources(void)
4206 IDirect3DSurface8 *surface, *rt;
4207 IDirect3DTexture8 *texture;
4208 IDirect3DDevice8 *device;
4209 IDirect3D8 *d3d8;
4210 HWND window;
4211 HRESULT hr;
4212 ULONG ref;
4214 window = create_window();
4215 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
4216 ok(!!d3d8, "Failed to create a D3D object.\n");
4218 if (!(device = create_device(d3d8, window, NULL)))
4220 skip("Failed to create a D3D device, skipping tests.\n");
4221 goto done;
4224 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 128, 128, D3DFMT_D24S8,
4225 D3DMULTISAMPLE_NONE, &surface);
4226 ok(SUCCEEDED(hr), "Failed to create depth/stencil surface, hr %#x.\n", hr);
4228 hr = IDirect3DDevice8_CreateTexture(device, 128, 128, 1, D3DUSAGE_RENDERTARGET,
4229 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture);
4230 ok(SUCCEEDED(hr), "Failed to create render target texture, hr %#x.\n", hr);
4231 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 0, &rt);
4232 ok(SUCCEEDED(hr), "Failed to get surface, hr %#x.\n", hr);
4233 IDirect3DTexture8_Release(texture);
4235 hr = IDirect3DDevice8_SetRenderTarget(device, rt, surface);
4236 ok(SUCCEEDED(hr), "Failed to set render target surface, hr %#x.\n", hr);
4237 IDirect3DSurface8_Release(rt);
4238 IDirect3DSurface8_Release(surface);
4240 hr = reset_device(device, NULL);
4241 ok(SUCCEEDED(hr), "Failed to reset device.\n");
4243 hr = IDirect3DDevice8_GetBackBuffer(device, 0, D3DBACKBUFFER_TYPE_MONO, &rt);
4244 ok(SUCCEEDED(hr), "Failed to get back buffer, hr %#x.\n", hr);
4245 hr = IDirect3DDevice8_GetRenderTarget(device, &surface);
4246 ok(SUCCEEDED(hr), "Failed to get render target surface, hr %#x.\n", hr);
4247 ok(surface == rt, "Got unexpected surface %p for render target.\n", surface);
4248 IDirect3DSurface8_Release(surface);
4249 IDirect3DSurface8_Release(rt);
4251 ref = IDirect3DDevice8_Release(device);
4252 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
4254 done:
4255 IDirect3D8_Release(d3d8);
4256 DestroyWindow(window);
4259 static void test_set_rt_vp_scissor(void)
4261 IDirect3DDevice8 *device;
4262 IDirect3DSurface8 *rt;
4263 IDirect3D8 *d3d8;
4264 DWORD stateblock;
4265 D3DVIEWPORT8 vp;
4266 UINT refcount;
4267 HWND window;
4268 HRESULT hr;
4270 window = create_window();
4271 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
4272 ok(!!d3d8, "Failed to create a D3D object.\n");
4273 if (!(device = create_device(d3d8, window, NULL)))
4275 skip("Failed to create a D3D device, skipping tests.\n");
4276 IDirect3D8_Release(d3d8);
4277 DestroyWindow(window);
4278 return;
4281 hr = IDirect3DDevice8_CreateRenderTarget(device, 128, 128, D3DFMT_A8R8G8B8,
4282 D3DMULTISAMPLE_NONE, FALSE, &rt);
4283 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
4285 hr = IDirect3DDevice8_GetViewport(device, &vp);
4286 ok(SUCCEEDED(hr), "Failed to get viewport, hr %#x.\n", hr);
4287 ok(!vp.X, "Got unexpected vp.X %u.\n", vp.X);
4288 ok(!vp.Y, "Got unexpected vp.Y %u.\n", vp.Y);
4289 ok(vp.Width == 640, "Got unexpected vp.Width %u.\n", vp.Width);
4290 ok(vp.Height == 480, "Got unexpected vp.Height %u.\n", vp.Height);
4291 ok(vp.MinZ == 0.0f, "Got unexpected vp.MinZ %.8e.\n", vp.MinZ);
4292 ok(vp.MaxZ == 1.0f, "Got unexpected vp.MaxZ %.8e.\n", vp.MaxZ);
4294 hr = IDirect3DDevice8_BeginStateBlock(device);
4295 ok(SUCCEEDED(hr), "Failed to begin stateblock, hr %#x.\n", hr);
4297 hr = IDirect3DDevice8_SetRenderTarget(device, rt, NULL);
4298 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
4300 hr = IDirect3DDevice8_EndStateBlock(device, &stateblock);
4301 ok(SUCCEEDED(hr), "Failed to end stateblock, hr %#x.\n", hr);
4302 hr = IDirect3DDevice8_DeleteStateBlock(device, stateblock);
4303 ok(SUCCEEDED(hr), "Failed to delete stateblock, hr %#x.\n", hr);
4305 hr = IDirect3DDevice8_GetViewport(device, &vp);
4306 ok(SUCCEEDED(hr), "Failed to get viewport, hr %#x.\n", hr);
4307 ok(!vp.X, "Got unexpected vp.X %u.\n", vp.X);
4308 ok(!vp.Y, "Got unexpected vp.Y %u.\n", vp.Y);
4309 ok(vp.Width == 128, "Got unexpected vp.Width %u.\n", vp.Width);
4310 ok(vp.Height == 128, "Got unexpected vp.Height %u.\n", vp.Height);
4311 ok(vp.MinZ == 0.0f, "Got unexpected vp.MinZ %.8e.\n", vp.MinZ);
4312 ok(vp.MaxZ == 1.0f, "Got unexpected vp.MaxZ %.8e.\n", vp.MaxZ);
4314 hr = IDirect3DDevice8_SetRenderTarget(device, rt, NULL);
4315 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
4317 vp.X = 10;
4318 vp.Y = 20;
4319 vp.Width = 30;
4320 vp.Height = 40;
4321 vp.MinZ = 0.25f;
4322 vp.MaxZ = 0.75f;
4323 hr = IDirect3DDevice8_SetViewport(device, &vp);
4324 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
4326 hr = IDirect3DDevice8_SetRenderTarget(device, rt, NULL);
4327 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
4329 hr = IDirect3DDevice8_GetViewport(device, &vp);
4330 ok(SUCCEEDED(hr), "Failed to get viewport, hr %#x.\n", hr);
4331 ok(!vp.X, "Got unexpected vp.X %u.\n", vp.X);
4332 ok(!vp.Y, "Got unexpected vp.Y %u.\n", vp.Y);
4333 ok(vp.Width == 128, "Got unexpected vp.Width %u.\n", vp.Width);
4334 ok(vp.Height == 128, "Got unexpected vp.Height %u.\n", vp.Height);
4335 ok(vp.MinZ == 0.0f, "Got unexpected vp.MinZ %.8e.\n", vp.MinZ);
4336 ok(vp.MaxZ == 1.0f, "Got unexpected vp.MaxZ %.8e.\n", vp.MaxZ);
4338 IDirect3DSurface8_Release(rt);
4339 refcount = IDirect3DDevice8_Release(device);
4340 ok(!refcount, "Device has %u references left.\n", refcount);
4341 IDirect3D8_Release(d3d8);
4342 DestroyWindow(window);
4345 static void test_validate_vs(void)
4347 static DWORD vs[] =
4349 0xfffe0101, /* vs_1_1 */
4350 0x00000009, 0xc0010000, 0x90e40000, 0xa0e40000, /* dp4 oPos.x, v0, c0 */
4351 0x00000009, 0xc0020000, 0x90e40000, 0xa0e40001, /* dp4 oPos.y, v0, c1 */
4352 0x00000009, 0xc0040000, 0x90e40000, 0xa0e40002, /* dp4 oPos.z, v0, c2 */
4353 0x00000009, 0xc0080000, 0x90e40000, 0xa0e40003, /* dp4 oPos.w, v0, c3 */
4354 0x0000ffff, /* end */
4356 HRESULT hr;
4358 hr = ValidateVertexShader(0, 0, 0, 0, 0);
4359 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
4360 hr = ValidateVertexShader(0, 0, 0, 1, 0);
4361 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
4362 hr = ValidateVertexShader(vs, 0, 0, 0, 0);
4363 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4365 hr = ValidateVertexShader(vs, 0, 0, 1, 0);
4366 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4367 /* Seems to do some version checking. */
4368 *vs = 0xfffe0100; /* vs_1_0 */
4369 hr = ValidateVertexShader(vs, 0, 0, 0, 0);
4370 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4372 *vs = 0xfffe0102; /* bogus version */
4373 hr = ValidateVertexShader(vs, 0, 0, 1, 0);
4374 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
4375 /* I've seen that applications always pass the 2nd and 3rd parameter as 0.
4376 * Simple test with non-zero parameters. */
4377 *vs = 0xfffe0101; /* vs_1_1 */
4378 hr = ValidateVertexShader(vs, vs, 0, 1, 0);
4379 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
4381 hr = ValidateVertexShader(vs, 0, vs, 1, 0);
4382 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
4383 /* I've seen the 4th parameter always passed as either 0 or 1, but passing
4384 * other values doesn't seem to hurt. */
4385 hr = ValidateVertexShader(vs, 0, 0, 12345, 0);
4386 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4387 /* What is the 5th parameter? The following seems to work ok. */
4388 hr = ValidateVertexShader(vs, 0, 0, 1, vs);
4389 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4392 static void test_validate_ps(void)
4394 static DWORD ps[] =
4396 0xffff0101, /* ps_1_1 */
4397 0x00000051, 0xa00f0001, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c1 = 1.0, 0.0, 0.0, 0.0 */
4398 0x00000042, 0xb00f0000, /* tex t0 */
4399 0x00000008, 0x800f0000, 0xa0e40001, 0xa0e40000, /* dp3 r0, c1, c0 */
4400 0x00000005, 0x800f0000, 0x90e40000, 0x80e40000, /* mul r0, v0, r0 */
4401 0x00000005, 0x800f0000, 0xb0e40000, 0x80e40000, /* mul r0, t0, r0 */
4402 0x0000ffff, /* end */
4404 HRESULT hr;
4406 hr = ValidatePixelShader(0, 0, 0, 0);
4407 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
4408 hr = ValidatePixelShader(0, 0, 1, 0);
4409 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
4410 hr = ValidatePixelShader(ps, 0, 0, 0);
4411 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4413 hr = ValidatePixelShader(ps, 0, 1, 0);
4414 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4415 /* Seems to do some version checking. */
4416 *ps = 0xffff0105; /* bogus version */
4417 hr = ValidatePixelShader(ps, 0, 1, 0);
4418 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
4419 /* I've seen that applications always pass the 2nd parameter as 0.
4420 * Simple test with a non-zero parameter. */
4421 *ps = 0xffff0101; /* ps_1_1 */
4422 hr = ValidatePixelShader(ps, ps, 1, 0);
4423 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
4424 /* I've seen the 3rd parameter always passed as either 0 or 1, but passing
4425 * other values doesn't seem to hurt. */
4426 hr = ValidatePixelShader(ps, 0, 12345, 0);
4427 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4428 /* What is the 4th parameter? The following seems to work ok. */
4429 hr = ValidatePixelShader(ps, 0, 1, ps);
4430 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4433 static void test_volume_get_container(void)
4435 IDirect3DVolumeTexture8 *texture = NULL;
4436 IDirect3DVolume8 *volume = NULL;
4437 IDirect3DDevice8 *device;
4438 IUnknown *container;
4439 IDirect3D8 *d3d8;
4440 ULONG refcount;
4441 D3DCAPS8 caps;
4442 HWND window;
4443 HRESULT hr;
4445 window = create_window();
4446 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
4447 ok(!!d3d8, "Failed to create a D3D object.\n");
4448 if (!(device = create_device(d3d8, window, NULL)))
4450 skip("Failed to create a D3D device, skipping tests.\n");
4451 IDirect3D8_Release(d3d8);
4452 DestroyWindow(window);
4453 return;
4456 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
4457 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
4458 if (!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP))
4460 skip("No volume texture support, skipping tests.\n");
4461 IDirect3DDevice8_Release(device);
4462 IDirect3D8_Release(d3d8);
4463 DestroyWindow(window);
4464 return;
4467 hr = IDirect3DDevice8_CreateVolumeTexture(device, 128, 128, 128, 1, 0,
4468 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture);
4469 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x.\n", hr);
4470 ok(!!texture, "Got unexpected texture %p.\n", texture);
4472 hr = IDirect3DVolumeTexture8_GetVolumeLevel(texture, 0, &volume);
4473 ok(SUCCEEDED(hr), "Failed to get volume level, hr %#x.\n", hr);
4474 ok(!!volume, "Got unexpected volume %p.\n", volume);
4476 /* These should work... */
4477 container = NULL;
4478 hr = IDirect3DVolume8_GetContainer(volume, &IID_IUnknown, (void **)&container);
4479 ok(SUCCEEDED(hr), "Failed to get volume container, hr %#x.\n", hr);
4480 ok(container == (IUnknown *)texture, "Got unexpected container %p, expected %p.\n", container, texture);
4481 IUnknown_Release(container);
4483 container = NULL;
4484 hr = IDirect3DVolume8_GetContainer(volume, &IID_IDirect3DResource8, (void **)&container);
4485 ok(SUCCEEDED(hr), "Failed to get volume container, hr %#x.\n", hr);
4486 ok(container == (IUnknown *)texture, "Got unexpected container %p, expected %p.\n", container, texture);
4487 IUnknown_Release(container);
4489 container = NULL;
4490 hr = IDirect3DVolume8_GetContainer(volume, &IID_IDirect3DBaseTexture8, (void **)&container);
4491 ok(SUCCEEDED(hr), "Failed to get volume container, hr %#x.\n", hr);
4492 ok(container == (IUnknown *)texture, "Got unexpected container %p, expected %p.\n", container, texture);
4493 IUnknown_Release(container);
4495 container = NULL;
4496 hr = IDirect3DVolume8_GetContainer(volume, &IID_IDirect3DVolumeTexture8, (void **)&container);
4497 ok(SUCCEEDED(hr), "Failed to get volume container, hr %#x.\n", hr);
4498 ok(container == (IUnknown *)texture, "Got unexpected container %p, expected %p.\n", container, texture);
4499 IUnknown_Release(container);
4501 /* ...and this one shouldn't. This should return E_NOINTERFACE and set container to NULL. */
4502 hr = IDirect3DVolume8_GetContainer(volume, &IID_IDirect3DVolume8, (void **)&container);
4503 ok(hr == E_NOINTERFACE, "Got unexpected hr %#x.\n", hr);
4504 ok(!container, "Got unexpected container %p.\n", container);
4506 IDirect3DVolume8_Release(volume);
4507 IDirect3DVolumeTexture8_Release(texture);
4508 refcount = IDirect3DDevice8_Release(device);
4509 ok(!refcount, "Device has %u references left.\n", refcount);
4510 IDirect3D8_Release(d3d8);
4511 DestroyWindow(window);
4514 static void test_vb_lock_flags(void)
4516 static const struct
4518 DWORD flags;
4519 const char *debug_string;
4520 HRESULT result;
4522 test_data[] =
4524 {D3DLOCK_READONLY, "D3DLOCK_READONLY", D3D_OK },
4525 {D3DLOCK_DISCARD, "D3DLOCK_DISCARD", D3D_OK },
4526 {D3DLOCK_NOOVERWRITE, "D3DLOCK_NOOVERWRITE", D3D_OK },
4527 {D3DLOCK_NOOVERWRITE | D3DLOCK_DISCARD, "D3DLOCK_NOOVERWRITE | D3DLOCK_DISCARD", D3D_OK },
4528 {D3DLOCK_NOOVERWRITE | D3DLOCK_READONLY, "D3DLOCK_NOOVERWRITE | D3DLOCK_READONLY", D3D_OK },
4529 {D3DLOCK_READONLY | D3DLOCK_DISCARD, "D3DLOCK_READONLY | D3DLOCK_DISCARD", D3D_OK },
4530 /* Completely bogus flags aren't an error. */
4531 {0xdeadbeef, "0xdeadbeef", D3D_OK },
4533 IDirect3DVertexBuffer8 *buffer;
4534 IDirect3DDevice8 *device;
4535 IDirect3D8 *d3d8;
4536 unsigned int i;
4537 ULONG refcount;
4538 HWND window;
4539 HRESULT hr;
4540 BYTE *data;
4542 window = create_window();
4543 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
4544 ok(!!d3d8, "Failed to create a D3D object.\n");
4545 if (!(device = create_device(d3d8, window, NULL)))
4547 skip("Failed to create a D3D device, skipping tests.\n");
4548 IDirect3D8_Release(d3d8);
4549 DestroyWindow(window);
4550 return;
4553 hr = IDirect3DDevice8_CreateVertexBuffer(device, 1024, D3DUSAGE_DYNAMIC, 0, D3DPOOL_DEFAULT, &buffer);
4554 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
4556 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
4558 hr = IDirect3DVertexBuffer8_Lock(buffer, 0, 0, &data, test_data[i].flags);
4559 ok(hr == test_data[i].result, "Got unexpected hr %#x for %s.\n",
4560 hr, test_data[i].debug_string);
4561 if (SUCCEEDED(hr))
4563 ok(!!data, "Got unexpected data %p.\n", data);
4564 hr = IDirect3DVertexBuffer8_Unlock(buffer);
4565 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
4569 IDirect3DVertexBuffer8_Release(buffer);
4570 refcount = IDirect3DDevice8_Release(device);
4571 ok(!refcount, "Device has %u references left.\n", refcount);
4572 IDirect3D8_Release(d3d8);
4573 DestroyWindow(window);
4576 /* Test the default texture stage state values */
4577 static void test_texture_stage_states(void)
4579 IDirect3DDevice8 *device;
4580 IDirect3D8 *d3d8;
4581 unsigned int i;
4582 ULONG refcount;
4583 D3DCAPS8 caps;
4584 DWORD value;
4585 HWND window;
4586 HRESULT hr;
4588 window = create_window();
4589 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
4590 ok(!!d3d8, "Failed to create a D3D object.\n");
4591 if (!(device = create_device(d3d8, window, NULL)))
4593 skip("Failed to create a D3D device, skipping tests.\n");
4594 IDirect3D8_Release(d3d8);
4595 DestroyWindow(window);
4596 return;
4599 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
4600 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
4602 for (i = 0; i < caps.MaxTextureBlendStages; ++i)
4604 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_COLOROP, &value);
4605 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4606 ok(value == (i ? D3DTOP_DISABLE : D3DTOP_MODULATE),
4607 "Got unexpected value %#x for D3DTSS_COLOROP, stage %u.\n", value, i);
4608 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_COLORARG1, &value);
4609 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4610 ok(value == D3DTA_TEXTURE, "Got unexpected value %#x for D3DTSS_COLORARG1, stage %u.\n", value, i);
4611 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_COLORARG2, &value);
4612 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4613 ok(value == D3DTA_CURRENT, "Got unexpected value %#x for D3DTSS_COLORARG2, stage %u.\n", value, i);
4614 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_ALPHAOP, &value);
4615 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4616 ok(value == (i ? D3DTOP_DISABLE : D3DTOP_SELECTARG1),
4617 "Got unexpected value %#x for D3DTSS_ALPHAOP, stage %u.\n", value, i);
4618 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_ALPHAARG1, &value);
4619 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4620 ok(value == D3DTA_TEXTURE, "Got unexpected value %#x for D3DTSS_ALPHAARG1, stage %u.\n", value, i);
4621 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_ALPHAARG2, &value);
4622 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4623 ok(value == D3DTA_CURRENT, "Got unexpected value %#x for D3DTSS_ALPHAARG2, stage %u.\n", value, i);
4624 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_BUMPENVMAT00, &value);
4625 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4626 ok(!value, "Got unexpected value %#x for D3DTSS_BUMPENVMAT00, stage %u.\n", value, i);
4627 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_BUMPENVMAT01, &value);
4628 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4629 ok(!value, "Got unexpected value %#x for D3DTSS_BUMPENVMAT01, stage %u.\n", value, i);
4630 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_BUMPENVMAT10, &value);
4631 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4632 ok(!value, "Got unexpected value %#x for D3DTSS_BUMPENVMAT10, stage %u.\n", value, i);
4633 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_BUMPENVMAT11, &value);
4634 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4635 ok(!value, "Got unexpected value %#x for D3DTSS_BUMPENVMAT11, stage %u.\n", value, i);
4636 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_TEXCOORDINDEX, &value);
4637 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4638 ok(value == i, "Got unexpected value %#x for D3DTSS_TEXCOORDINDEX, stage %u.\n", value, i);
4639 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_BUMPENVLSCALE, &value);
4640 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4641 ok(!value, "Got unexpected value %#x for D3DTSS_BUMPENVLSCALE, stage %u.\n", value, i);
4642 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_BUMPENVLOFFSET, &value);
4643 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4644 ok(!value, "Got unexpected value %#x for D3DTSS_BUMPENVLOFFSET, stage %u.\n", value, i);
4645 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_TEXTURETRANSFORMFLAGS, &value);
4646 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4647 ok(value == D3DTTFF_DISABLE,
4648 "Got unexpected value %#x for D3DTSS_TEXTURETRANSFORMFLAGS, stage %u.\n", value, i);
4649 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_COLORARG0, &value);
4650 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4651 ok(value == D3DTA_CURRENT, "Got unexpected value %#x for D3DTSS_COLORARG0, stage %u.\n", value, i);
4652 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_ALPHAARG0, &value);
4653 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4654 ok(value == D3DTA_CURRENT, "Got unexpected value %#x for D3DTSS_ALPHAARG0, stage %u.\n", value, i);
4655 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_RESULTARG, &value);
4656 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4657 ok(value == D3DTA_CURRENT, "Got unexpected value %#x for D3DTSS_RESULTARG, stage %u.\n", value, i);
4660 refcount = IDirect3DDevice8_Release(device);
4661 ok(!refcount, "Device has %u references left.\n", refcount);
4662 IDirect3D8_Release(d3d8);
4663 DestroyWindow(window);
4666 static void test_cube_textures(void)
4668 IDirect3DCubeTexture8 *texture;
4669 IDirect3DDevice8 *device;
4670 IDirect3D8 *d3d8;
4671 ULONG refcount;
4672 D3DCAPS8 caps;
4673 HWND window;
4674 HRESULT hr;
4676 window = create_window();
4677 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
4678 ok(!!d3d8, "Failed to create a D3D object.\n");
4679 if (!(device = create_device(d3d8, window, NULL)))
4681 skip("Failed to create a D3D device, skipping tests.\n");
4682 IDirect3D8_Release(d3d8);
4683 DestroyWindow(window);
4684 return;
4687 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
4688 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
4690 if (caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP)
4692 hr = IDirect3DDevice8_CreateCubeTexture(device, 512, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &texture);
4693 ok(hr == D3D_OK, "Failed to create D3DPOOL_DEFAULT cube texture, hr %#x.\n", hr);
4694 IDirect3DCubeTexture8_Release(texture);
4695 hr = IDirect3DDevice8_CreateCubeTexture(device, 512, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &texture);
4696 ok(hr == D3D_OK, "Failed to create D3DPOOL_MANAGED cube texture, hr %#x.\n", hr);
4697 IDirect3DCubeTexture8_Release(texture);
4698 hr = IDirect3DDevice8_CreateCubeTexture(device, 512, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_SYSTEMMEM, &texture);
4699 ok(hr == D3D_OK, "Failed to create D3DPOOL_SYSTEMMEM cube texture, hr %#x.\n", hr);
4700 IDirect3DCubeTexture8_Release(texture);
4702 else
4704 hr = IDirect3DDevice8_CreateCubeTexture(device, 512, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &texture);
4705 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for D3DPOOL_DEFAULT cube texture.\n", hr);
4706 hr = IDirect3DDevice8_CreateCubeTexture(device, 512, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &texture);
4707 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for D3DPOOL_MANAGED cube texture.\n", hr);
4708 hr = IDirect3DDevice8_CreateCubeTexture(device, 512, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_SYSTEMMEM, &texture);
4709 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for D3DPOOL_SYSTEMMEM cube texture.\n", hr);
4711 hr = IDirect3DDevice8_CreateCubeTexture(device, 512, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_SCRATCH, &texture);
4712 ok(hr == D3D_OK, "Failed to create D3DPOOL_SCRATCH cube texture, hr %#x.\n", hr);
4713 IDirect3DCubeTexture8_Release(texture);
4715 refcount = IDirect3DDevice8_Release(device);
4716 ok(!refcount, "Device has %u references left.\n", refcount);
4717 IDirect3D8_Release(d3d8);
4718 DestroyWindow(window);
4721 static void test_get_set_texture(void)
4723 const IDirect3DBaseTexture8Vtbl *texture_vtbl;
4724 IDirect3DBaseTexture8 *texture;
4725 IDirect3DDevice8 *device;
4726 IDirect3D8 *d3d;
4727 ULONG refcount;
4728 HWND window;
4729 HRESULT hr;
4731 window = create_window();
4732 d3d = Direct3DCreate8(D3D_SDK_VERSION);
4733 ok(!!d3d, "Failed to create a D3D object.\n");
4734 if (!(device = create_device(d3d, window, NULL)))
4736 skip("Failed to create a D3D device, skipping tests.\n");
4737 IDirect3D8_Release(d3d);
4738 DestroyWindow(window);
4739 return;
4742 texture = (IDirect3DBaseTexture8 *)0xdeadbeef;
4743 hr = IDirect3DDevice8_SetTexture(device, 0, NULL);
4744 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
4745 hr = IDirect3DDevice8_GetTexture(device, 0, &texture);
4746 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
4747 ok(!texture, "Got unexpected texture %p.\n", texture);
4749 hr = IDirect3DDevice8_CreateTexture(device, 16, 16, 1, 0, D3DFMT_A8R8G8B8,
4750 D3DPOOL_MANAGED, (IDirect3DTexture8 **)&texture);
4751 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
4752 texture_vtbl = texture->lpVtbl;
4753 texture->lpVtbl = (IDirect3DBaseTexture8Vtbl *)0xdeadbeef;
4754 hr = IDirect3DDevice8_SetTexture(device, 0, texture);
4755 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
4756 hr = IDirect3DDevice8_SetTexture(device, 0, NULL);
4757 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
4758 texture->lpVtbl = NULL;
4759 hr = IDirect3DDevice8_SetTexture(device, 0, texture);
4760 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
4761 hr = IDirect3DDevice8_SetTexture(device, 0, NULL);
4762 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
4763 texture->lpVtbl = texture_vtbl;
4764 IDirect3DBaseTexture8_Release(texture);
4766 refcount = IDirect3DDevice8_Release(device);
4767 ok(!refcount, "Device has %u references left.\n", refcount);
4768 IDirect3D8_Release(d3d);
4769 DestroyWindow(window);
4772 /* Test the behaviour of the IDirect3DDevice8::CreateImageSurface() method.
4774 * The expected behaviour (as documented in the original DX8 docs) is that the
4775 * call returns a surface in the SYSTEMMEM pool. Games like Max Payne 1 and 2
4776 * depend on this behaviour.
4778 * A short remark in the DX9 docs however states that the pool of the returned
4779 * surface object is D3DPOOL_SCRATCH. This is misinformation and would result
4780 * in screenshots not appearing in the savegame loading menu of both games
4781 * mentioned above (engine tries to display a texture from the scratch pool).
4783 * This test verifies that the behaviour described in the original d3d8 docs
4784 * is the correct one. For more information about this issue, see the MSDN:
4785 * d3d9 docs: "Converting to Direct3D 9"
4786 * d3d9 reference: "IDirect3DDevice9::CreateOffscreenPlainSurface"
4787 * d3d8 reference: "IDirect3DDevice8::CreateImageSurface" */
4788 static void test_image_surface_pool(void)
4790 IDirect3DSurface8 *surface;
4791 IDirect3DDevice8 *device;
4792 D3DSURFACE_DESC desc;
4793 IDirect3D8 *d3d8;
4794 ULONG refcount;
4795 HWND window;
4796 HRESULT hr;
4798 window = create_window();
4799 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
4800 ok(!!d3d8, "Failed to create a D3D object.\n");
4801 if (!(device = create_device(d3d8, window, NULL)))
4803 skip("Failed to create a D3D device, skipping tests.\n");
4804 IDirect3D8_Release(d3d8);
4805 DestroyWindow(window);
4806 return;
4809 hr = IDirect3DDevice8_CreateImageSurface(device, 128, 128, D3DFMT_A8R8G8B8, &surface);
4810 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4811 hr = IDirect3DSurface8_GetDesc(surface, &desc);
4812 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
4813 ok(desc.Pool == D3DPOOL_SYSTEMMEM, "Got unexpected pool %#x.\n", desc.Pool);
4814 IDirect3DSurface8_Release(surface);
4816 refcount = IDirect3DDevice8_Release(device);
4817 ok(!refcount, "Device has %u references left.\n", refcount);
4818 IDirect3D8_Release(d3d8);
4819 DestroyWindow(window);
4822 static void test_surface_get_container(void)
4824 IDirect3DTexture8 *texture = NULL;
4825 IDirect3DSurface8 *surface = NULL;
4826 IDirect3DDevice8 *device;
4827 IUnknown *container;
4828 IDirect3D8 *d3d8;
4829 ULONG refcount;
4830 HWND window;
4831 HRESULT hr;
4833 window = create_window();
4834 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
4835 ok(!!d3d8, "Failed to create a D3D object.\n");
4836 if (!(device = create_device(d3d8, window, NULL)))
4838 skip("Failed to create a D3D device, skipping tests.\n");
4839 IDirect3D8_Release(d3d8);
4840 DestroyWindow(window);
4841 return;
4844 hr = IDirect3DDevice8_CreateTexture(device, 128, 128, 1, 0,
4845 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture);
4846 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
4847 ok(!!texture, "Got unexpected texture %p.\n", texture);
4849 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 0, &surface);
4850 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
4851 ok(!!surface, "Got unexpected surface %p.\n", surface);
4853 /* These should work... */
4854 container = NULL;
4855 hr = IDirect3DSurface8_GetContainer(surface, &IID_IUnknown, (void **)&container);
4856 ok(SUCCEEDED(hr), "Failed to get surface container, hr %#x.\n", hr);
4857 ok(container == (IUnknown *)texture, "Got unexpected container %p, expected %p.\n", container, texture);
4858 IUnknown_Release(container);
4860 container = NULL;
4861 hr = IDirect3DSurface8_GetContainer(surface, &IID_IDirect3DResource8, (void **)&container);
4862 ok(SUCCEEDED(hr), "Failed to get surface container, hr %#x.\n", hr);
4863 ok(container == (IUnknown *)texture, "Got unexpected container %p, expected %p.\n", container, texture);
4864 IUnknown_Release(container);
4866 container = NULL;
4867 hr = IDirect3DSurface8_GetContainer(surface, &IID_IDirect3DBaseTexture8, (void **)&container);
4868 ok(SUCCEEDED(hr), "Failed to get surface container, hr %#x.\n", hr);
4869 ok(container == (IUnknown *)texture, "Got unexpected container %p, expected %p.\n", container, texture);
4870 IUnknown_Release(container);
4872 container = NULL;
4873 hr = IDirect3DSurface8_GetContainer(surface, &IID_IDirect3DTexture8, (void **)&container);
4874 ok(SUCCEEDED(hr), "Failed to get surface container, hr %#x.\n", hr);
4875 ok(container == (IUnknown *)texture, "Got unexpected container %p, expected %p.\n", container, texture);
4876 IUnknown_Release(container);
4878 /* ...and this one shouldn't. This should return E_NOINTERFACE and set container to NULL. */
4879 hr = IDirect3DSurface8_GetContainer(surface, &IID_IDirect3DSurface8, (void **)&container);
4880 ok(hr == E_NOINTERFACE, "Got unexpected hr %#x.\n", hr);
4881 ok(!container, "Got unexpected container %p.\n", container);
4883 IDirect3DSurface8_Release(surface);
4884 IDirect3DTexture8_Release(texture);
4885 refcount = IDirect3DDevice8_Release(device);
4886 ok(!refcount, "Device has %u references left.\n", refcount);
4887 IDirect3D8_Release(d3d8);
4888 DestroyWindow(window);
4891 static void test_lockrect_invalid(void)
4893 static const RECT valid[] =
4895 {60, 60, 68, 68},
4896 {120, 60, 128, 68},
4897 {60, 120, 68, 128},
4899 static const RECT invalid[] =
4901 {60, 60, 60, 68}, /* 0 height */
4902 {60, 60, 68, 60}, /* 0 width */
4903 {68, 60, 60, 68}, /* left > right */
4904 {60, 68, 68, 60}, /* top > bottom */
4905 {-8, 60, 0, 68}, /* left < surface */
4906 {60, -8, 68, 0}, /* top < surface */
4907 {-16, 60, -8, 68}, /* right < surface */
4908 {60, -16, 68, -8}, /* bottom < surface */
4909 {60, 60, 136, 68}, /* right > surface */
4910 {60, 60, 68, 136}, /* bottom > surface */
4911 {136, 60, 144, 68}, /* left > surface */
4912 {60, 136, 68, 144}, /* top > surface */
4914 IDirect3DSurface8 *surface;
4915 IDirect3DTexture8 *texture;
4916 IDirect3DCubeTexture8 *cube_texture;
4917 D3DLOCKED_RECT locked_rect;
4918 IDirect3DDevice8 *device;
4919 HRESULT hr, expected_hr;
4920 IDirect3D8 *d3d8;
4921 unsigned int i, r;
4922 ULONG refcount;
4923 HWND window;
4924 BYTE *base;
4925 unsigned int offset, expected_offset;
4926 static const struct
4928 D3DRESOURCETYPE type;
4929 D3DPOOL pool;
4930 const char *name;
4931 BOOL validate, clear;
4933 resources[] =
4935 {D3DRTYPE_SURFACE, D3DPOOL_SCRATCH, "scratch surface", TRUE, TRUE},
4936 {D3DRTYPE_TEXTURE, D3DPOOL_MANAGED, "managed texture", FALSE, FALSE},
4937 {D3DRTYPE_TEXTURE, D3DPOOL_SYSTEMMEM, "sysmem texture", FALSE, FALSE},
4938 {D3DRTYPE_TEXTURE, D3DPOOL_SCRATCH, "scratch texture", FALSE, FALSE},
4939 {D3DRTYPE_CUBETEXTURE, D3DPOOL_MANAGED, "default cube texture", TRUE, TRUE},
4940 {D3DRTYPE_CUBETEXTURE, D3DPOOL_SYSTEMMEM, "sysmem cube texture", TRUE, TRUE},
4941 {D3DRTYPE_CUBETEXTURE, D3DPOOL_SCRATCH, "scratch cube texture", TRUE, TRUE},
4944 window = create_window();
4945 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
4946 ok(!!d3d8, "Failed to create a D3D object.\n");
4947 if (!(device = create_device(d3d8, window, NULL)))
4949 skip("Failed to create a D3D device, skipping tests.\n");
4950 IDirect3D8_Release(d3d8);
4951 DestroyWindow(window);
4952 return;
4955 for (r = 0; r < ARRAY_SIZE(resources); ++r)
4957 texture = NULL;
4958 cube_texture = NULL;
4959 switch (resources[r].type)
4961 case D3DRTYPE_SURFACE:
4962 hr = IDirect3DDevice8_CreateImageSurface(device, 128, 128, D3DFMT_A8R8G8B8, &surface);
4963 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x, type %s.\n", hr, resources[r].name);
4964 break;
4966 case D3DRTYPE_TEXTURE:
4967 hr = IDirect3DDevice8_CreateTexture(device, 128, 128, 1, 0, D3DFMT_A8R8G8B8,
4968 resources[r].pool, &texture);
4969 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x, type %s.\n", hr, resources[r].name);
4970 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 0, &surface);
4971 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x, type %s.\n", hr, resources[r].name);
4972 break;
4974 case D3DRTYPE_CUBETEXTURE:
4975 hr = IDirect3DDevice8_CreateCubeTexture(device, 128, 1, 0, D3DFMT_A8R8G8B8,
4976 resources[r].pool, &cube_texture);
4977 ok(SUCCEEDED(hr), "Failed to create cube texture, hr %#x, type %s.\n", hr, resources[r].name);
4978 hr = IDirect3DCubeTexture8_GetCubeMapSurface(cube_texture, D3DCUBEMAP_FACE_NEGATIVE_X, 0, &surface);
4979 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x, type %s.\n", hr, resources[r].name);
4980 break;
4982 default:
4983 break;
4986 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, NULL, 0);
4987 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, type %s.\n", hr, resources[r].name);
4988 base = locked_rect.pBits;
4989 hr = IDirect3DSurface8_UnlockRect(surface);
4990 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
4991 expected_hr = resources[r].type == D3DRTYPE_TEXTURE ? D3D_OK : D3DERR_INVALIDCALL;
4992 hr = IDirect3DSurface8_UnlockRect(surface);
4993 ok(hr == expected_hr, "Got hr %#x, expected %#x, type %s.\n", hr, expected_hr, resources[r].name);
4995 for (i = 0; i < ARRAY_SIZE(valid); ++i)
4997 const RECT *rect = &valid[i];
4999 locked_rect.pBits = (BYTE *)0xdeadbeef;
5000 locked_rect.Pitch = 0xdeadbeef;
5002 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, rect, 0);
5003 ok(SUCCEEDED(hr), "Failed to lock surface with rect %s, hr %#x, type %s.\n",
5004 wine_dbgstr_rect(rect), hr, resources[r].name);
5006 offset = (BYTE *)locked_rect.pBits - base;
5007 expected_offset = rect->top * locked_rect.Pitch + rect->left * 4;
5008 ok(offset == expected_offset,
5009 "Got unexpected offset %u (expected %u) for rect %s, type %s.\n",
5010 offset, expected_offset, wine_dbgstr_rect(rect), resources[r].name);
5012 hr = IDirect3DSurface8_UnlockRect(surface);
5013 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s\n", hr, resources[r].name);
5015 if (texture)
5017 hr = IDirect3DTexture8_LockRect(texture, 0, &locked_rect, rect, 0);
5018 ok(SUCCEEDED(hr), "Failed to lock surface with rect %s, hr %#x, type %s.\n",
5019 wine_dbgstr_rect(rect), hr, resources[r].name);
5021 offset = (BYTE *)locked_rect.pBits - base;
5022 ok(offset == expected_offset,
5023 "Got unexpected offset %u (expected %u) for rect %s, type %s.\n",
5024 offset, expected_offset, wine_dbgstr_rect(rect), resources[r].name);
5026 hr = IDirect3DTexture8_UnlockRect(texture, 0);
5027 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
5029 if (cube_texture)
5031 hr = IDirect3DCubeTexture8_LockRect(cube_texture, D3DCUBEMAP_FACE_NEGATIVE_X, 0, &locked_rect, rect, 0);
5032 ok(SUCCEEDED(hr), "Failed to lock surface with rect %s, hr %#x, type %s.\n",
5033 wine_dbgstr_rect(rect), hr, resources[r].name);
5035 offset = (BYTE *)locked_rect.pBits - base;
5036 ok(offset == expected_offset,
5037 "Got unexpected offset %u (expected %u) for rect %s, type %s.\n",
5038 offset, expected_offset, wine_dbgstr_rect(rect), resources[r].name);
5040 hr = IDirect3DCubeTexture8_UnlockRect(cube_texture, D3DCUBEMAP_FACE_NEGATIVE_X, 0);
5041 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
5045 for (i = 0; i < ARRAY_SIZE(invalid); ++i)
5047 const RECT *rect = &invalid[i];
5049 locked_rect.pBits = (void *)0xdeadbeef;
5050 locked_rect.Pitch = 1;
5051 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, rect, 0);
5052 if (resources[r].validate)
5053 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for rect %s, type %s.\n",
5054 hr, wine_dbgstr_rect(rect), resources[r].name);
5055 else
5056 ok(SUCCEEDED(hr), "Got unexpected hr %#x for rect %s, type %s.\n",
5057 hr, wine_dbgstr_rect(rect), resources[r].name);
5059 if (SUCCEEDED(hr))
5061 offset = (BYTE *)locked_rect.pBits - base;
5062 expected_offset = rect->top * locked_rect.Pitch + rect->left * 4;
5063 ok(offset == expected_offset,
5064 "Got unexpected offset %u (expected %u) for rect %s, type %s.\n",
5065 offset, expected_offset,wine_dbgstr_rect(rect), resources[r].name);
5067 hr = IDirect3DSurface8_UnlockRect(surface);
5068 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
5070 else
5072 ok(!locked_rect.pBits, "Got unexpected pBits %p, type %s.\n",
5073 locked_rect.pBits, resources[r].name);
5074 ok(!locked_rect.Pitch, "Got unexpected Pitch %u, type %s.\n",
5075 locked_rect.Pitch, resources[r].name);
5079 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, NULL, 0);
5080 ok(SUCCEEDED(hr), "Failed to lock surface with rect NULL, hr %#x, type %s.\n",
5081 hr, resources[r].name);
5082 locked_rect.pBits = (void *)0xdeadbeef;
5083 locked_rect.Pitch = 1;
5084 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, NULL, 0);
5085 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x, type %s.\n", hr, resources[r].name);
5086 if (resources[r].clear)
5088 ok(!locked_rect.pBits, "Got unexpected pBits %p, type %s.\n",
5089 locked_rect.pBits, resources[r].name);
5090 ok(!locked_rect.Pitch, "Got unexpected Pitch %u, type %s.\n",
5091 locked_rect.Pitch, resources[r].name);
5093 else
5095 ok(locked_rect.pBits == (void *)0xdeadbeef, "Got unexpected pBits %p, type %s.\n",
5096 locked_rect.pBits, resources[r].name);
5097 ok(locked_rect.Pitch == 1, "Got unexpected Pitch %u, type %s.\n",
5098 locked_rect.Pitch, resources[r].name);
5100 hr = IDirect3DSurface8_UnlockRect(surface);
5101 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
5103 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, &valid[0], 0);
5104 ok(hr == D3D_OK, "Got unexpected hr %#x for rect %s, type %s.\n",
5105 hr, wine_dbgstr_rect(&valid[0]), resources[r].name);
5106 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, &valid[0], 0);
5107 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for rect %s, type %s.\n",
5108 hr, wine_dbgstr_rect(&valid[0]), resources[r].name);
5109 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, &valid[1], 0);
5110 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for rect %s, type %s.\n",
5111 hr, wine_dbgstr_rect(&valid[1]), resources[r].name);
5112 hr = IDirect3DSurface8_UnlockRect(surface);
5113 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
5115 IDirect3DSurface8_Release(surface);
5116 if (texture)
5118 hr = IDirect3DTexture8_LockRect(texture, 0, &locked_rect, NULL, 0);
5119 ok(SUCCEEDED(hr), "Failed to lock texture with rect NULL, hr %#x, type %s.\n",
5120 hr, resources[r].name);
5121 locked_rect.pBits = (void *)0xdeadbeef;
5122 locked_rect.Pitch = 1;
5123 hr = IDirect3DTexture8_LockRect(texture, 0, &locked_rect, NULL, 0);
5124 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x, type %s.\n", hr, resources[r].name);
5125 ok(locked_rect.pBits == (void *)0xdeadbeef, "Got unexpected pBits %p, type %s.\n",
5126 locked_rect.pBits, resources[r].name);
5127 ok(locked_rect.Pitch == 1, "Got unexpected Pitch %u, type %s.\n",
5128 locked_rect.Pitch, resources[r].name);
5129 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, NULL, 0);
5130 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x, type %s.\n", hr, resources[r].name);
5131 hr = IDirect3DTexture8_UnlockRect(texture, 0);
5132 ok(SUCCEEDED(hr), "Failed to unlock texture, hr %#x, type %s.\n", hr, resources[r].name);
5133 hr = IDirect3DTexture8_UnlockRect(texture, 0);
5134 ok(hr == D3D_OK, "Got unexpected hr %#x, type %s.\n", hr, resources[r].name);
5136 hr = IDirect3DTexture8_LockRect(texture, 0, &locked_rect, &valid[0], 0);
5137 ok(hr == D3D_OK, "Got unexpected hr %#x for rect %s, type %s.\n",
5138 hr, wine_dbgstr_rect(&valid[0]), resources[r].name);
5139 hr = IDirect3DTexture8_LockRect(texture, 0, &locked_rect, &valid[0], 0);
5140 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for rect %s, type %s.\n",
5141 hr, wine_dbgstr_rect(&valid[0]), resources[r].name);
5142 hr = IDirect3DTexture8_LockRect(texture, 0, &locked_rect, &valid[1], 0);
5143 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for rect %s, type %s.\n",
5144 hr, wine_dbgstr_rect(&valid[1]), resources[r].name);
5145 hr = IDirect3DTexture8_UnlockRect(texture, 0);
5146 ok(SUCCEEDED(hr), "Failed to unlock texture, hr %#x, type %s.\n", hr, resources[r].name);
5148 IDirect3DTexture8_Release(texture);
5151 if (cube_texture)
5153 hr = IDirect3DCubeTexture8_LockRect(cube_texture, D3DCUBEMAP_FACE_NEGATIVE_X, 0,
5154 &locked_rect, NULL, 0);
5155 ok(SUCCEEDED(hr), "Failed to lock texture with rect NULL, hr %#x, type %s.\n",
5156 hr, resources[r].name);
5157 locked_rect.pBits = (void *)0xdeadbeef;
5158 locked_rect.Pitch = 1;
5159 hr = IDirect3DCubeTexture8_LockRect(cube_texture, D3DCUBEMAP_FACE_NEGATIVE_X, 0,
5160 &locked_rect, NULL, 0);
5161 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x, type %s.\n", hr, resources[r].name);
5162 ok(!locked_rect.pBits, "Got unexpected pBits %p, type %s.\n",
5163 locked_rect.pBits, resources[r].name);
5164 ok(!locked_rect.Pitch, "Got unexpected Pitch %u, type %s.\n",
5165 locked_rect.Pitch, resources[r].name);
5166 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, NULL, 0);
5167 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x, type %s.\n", hr, resources[r].name);
5168 hr = IDirect3DCubeTexture8_UnlockRect(cube_texture, D3DCUBEMAP_FACE_NEGATIVE_X, 0);
5169 ok(SUCCEEDED(hr), "Failed to unlock texture, hr %#x, type %s.\n", hr, resources[r].name);
5170 hr = IDirect3DCubeTexture8_UnlockRect(cube_texture, D3DCUBEMAP_FACE_NEGATIVE_X, 0);
5171 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x, type %s.\n", hr, resources[r].name);
5173 hr = IDirect3DCubeTexture8_LockRect(cube_texture, D3DCUBEMAP_FACE_NEGATIVE_X, 0,
5174 &locked_rect, &valid[0], 0);
5175 ok(hr == D3D_OK, "Got unexpected hr %#x for rect %s, type %s.\n",
5176 hr, wine_dbgstr_rect(&valid[0]), resources[r].name);
5177 hr = IDirect3DCubeTexture8_LockRect(cube_texture, D3DCUBEMAP_FACE_NEGATIVE_X, 0,
5178 &locked_rect, &valid[0], 0);
5179 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for rect %s, type %s.\n",
5180 hr, wine_dbgstr_rect(&valid[0]), resources[r].name);
5181 hr = IDirect3DCubeTexture8_LockRect(cube_texture, D3DCUBEMAP_FACE_NEGATIVE_X, 0,
5182 &locked_rect, &valid[1], 0);
5183 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for rect %s, type %s.\n",
5184 hr, wine_dbgstr_rect(&valid[1]), resources[r].name);
5185 hr = IDirect3DCubeTexture8_UnlockRect(cube_texture, D3DCUBEMAP_FACE_NEGATIVE_X, 0);
5186 ok(SUCCEEDED(hr), "Failed to unlock texture, hr %#x, type %s.\n", hr, resources[r].name);
5188 IDirect3DTexture8_Release(cube_texture);
5192 refcount = IDirect3DDevice8_Release(device);
5193 ok(!refcount, "Device has %u references left.\n", refcount);
5194 IDirect3D8_Release(d3d8);
5195 DestroyWindow(window);
5198 static void test_private_data(void)
5200 ULONG refcount, expected_refcount;
5201 IDirect3DTexture8 *texture;
5202 IDirect3DSurface8 *surface, *surface2;
5203 IDirect3DDevice8 *device;
5204 IDirect3D8 *d3d8;
5205 IUnknown *ptr;
5206 HWND window;
5207 HRESULT hr;
5208 DWORD size;
5209 DWORD data[4] = {1, 2, 3, 4};
5210 static const GUID d3d8_private_data_test_guid2 =
5212 0x2e5afac2,
5213 0x87b5,
5214 0x4c10,
5215 {0x9b,0x4b,0x89,0xd7,0xd1,0x12,0xe7,0x2b}
5218 window = create_window();
5219 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
5220 ok(!!d3d8, "Failed to create a D3D object.\n");
5221 if (!(device = create_device(d3d8, window, NULL)))
5223 skip("Failed to create a D3D device, skipping tests.\n");
5224 IDirect3D8_Release(d3d8);
5225 DestroyWindow(window);
5226 return;
5229 hr = IDirect3DDevice8_CreateImageSurface(device, 4, 4, D3DFMT_A8R8G8B8, &surface);
5230 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5232 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
5233 device, 0, D3DSPD_IUNKNOWN);
5234 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
5235 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
5236 device, 5, D3DSPD_IUNKNOWN);
5237 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
5238 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
5239 device, sizeof(IUnknown *) * 2, D3DSPD_IUNKNOWN);
5240 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
5242 /* A failing SetPrivateData call does not clear the old data with the same tag. */
5243 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid, device,
5244 sizeof(device), D3DSPD_IUNKNOWN);
5245 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
5246 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid, device,
5247 sizeof(device) * 2, D3DSPD_IUNKNOWN);
5248 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
5249 size = sizeof(ptr);
5250 hr = IDirect3DSurface8_GetPrivateData(surface, &d3d8_private_data_test_guid, &ptr, &size);
5251 ok(SUCCEEDED(hr), "Failed to get private data, hr %#x.\n", hr);
5252 IUnknown_Release(ptr);
5253 hr = IDirect3DSurface8_FreePrivateData(surface, &d3d8_private_data_test_guid);
5254 ok(SUCCEEDED(hr), "Failed to free private data, hr %#x.\n", hr);
5256 refcount = get_refcount((IUnknown *)device);
5257 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
5258 device, sizeof(IUnknown *), D3DSPD_IUNKNOWN);
5259 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
5260 expected_refcount = refcount + 1;
5261 refcount = get_refcount((IUnknown *)device);
5262 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5263 hr = IDirect3DSurface8_FreePrivateData(surface, &d3d8_private_data_test_guid);
5264 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
5265 expected_refcount = refcount - 1;
5266 refcount = get_refcount((IUnknown *)device);
5267 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5269 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
5270 device, sizeof(IUnknown *), D3DSPD_IUNKNOWN);
5271 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
5272 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
5273 surface, sizeof(IUnknown *), D3DSPD_IUNKNOWN);
5274 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
5275 refcount = get_refcount((IUnknown *)device);
5276 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5278 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
5279 device, sizeof(IUnknown *), D3DSPD_IUNKNOWN);
5280 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
5281 size = 2 * sizeof(ptr);
5282 hr = IDirect3DSurface8_GetPrivateData(surface, &d3d8_private_data_test_guid, &ptr, &size);
5283 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
5284 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5285 expected_refcount = refcount + 2;
5286 refcount = get_refcount((IUnknown *)device);
5287 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5288 ok(ptr == (IUnknown *)device, "Got unexpected ptr %p, expected %p.\n", ptr, device);
5289 IUnknown_Release(ptr);
5290 expected_refcount--;
5292 ptr = (IUnknown *)0xdeadbeef;
5293 size = 1;
5294 hr = IDirect3DSurface8_GetPrivateData(surface, &d3d8_private_data_test_guid, NULL, &size);
5295 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
5296 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5297 size = 2 * sizeof(ptr);
5298 hr = IDirect3DSurface8_GetPrivateData(surface, &d3d8_private_data_test_guid, NULL, &size);
5299 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
5300 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5301 refcount = get_refcount((IUnknown *)device);
5302 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5303 size = 1;
5304 hr = IDirect3DSurface8_GetPrivateData(surface, &d3d8_private_data_test_guid, &ptr, &size);
5305 ok(hr == D3DERR_MOREDATA, "Got unexpected hr %#x.\n", hr);
5306 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5307 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
5308 hr = IDirect3DSurface8_GetPrivateData(surface, &d3d8_private_data_test_guid2, NULL, NULL);
5309 ok(hr == D3DERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
5310 size = 0xdeadbabe;
5311 hr = IDirect3DSurface8_GetPrivateData(surface, &d3d8_private_data_test_guid2, &ptr, &size);
5312 ok(hr == D3DERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
5313 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
5314 ok(size == 0xdeadbabe, "Got unexpected size %u.\n", size);
5315 /* GetPrivateData with size = NULL causes an access violation on Windows if the
5316 * requested data exists. */
5318 /* Destroying the surface frees the held reference. */
5319 IDirect3DSurface8_Release(surface);
5320 expected_refcount = refcount - 2;
5321 refcount = get_refcount((IUnknown *)device);
5322 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5324 hr = IDirect3DDevice8_CreateTexture(device, 4, 4, 2, 0, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &texture);
5325 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5326 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 0, &surface);
5327 ok(SUCCEEDED(hr), "Failed to get texture level 0, hr %#x.\n", hr);
5328 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 1, &surface2);
5329 ok(SUCCEEDED(hr), "Failed to get texture level 1, hr %#x.\n", hr);
5331 hr = IDirect3DTexture8_SetPrivateData(texture, &d3d8_private_data_test_guid, data, sizeof(data), 0);
5332 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
5334 memset(data, 0, sizeof(data));
5335 size = sizeof(data);
5336 hr = IDirect3DSurface8_GetPrivateData(surface, &d3d8_private_data_test_guid, data, &size);
5337 ok(hr == D3DERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
5338 hr = IDirect3DTexture8_GetPrivateData(texture, &d3d8_private_data_test_guid, data, &size);
5339 ok(SUCCEEDED(hr), "Failed to get private data, hr %#x.\n", hr);
5340 ok(data[0] == 1 && data[1] == 2 && data[2] == 3 && data[3] == 4,
5341 "Got unexpected private data: %u, %u, %u, %u.\n", data[0], data[1], data[2], data[3]);
5343 hr = IDirect3DTexture8_FreePrivateData(texture, &d3d8_private_data_test_guid);
5344 ok(SUCCEEDED(hr), "Failed to free private data, hr %#x.\n", hr);
5346 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid, data, sizeof(data), 0);
5347 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
5348 hr = IDirect3DSurface8_GetPrivateData(surface2, &d3d8_private_data_test_guid, data, &size);
5349 ok(hr == D3DERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
5350 hr = IDirect3DSurface8_FreePrivateData(surface, &d3d8_private_data_test_guid);
5351 ok(SUCCEEDED(hr), "Failed to free private data, hr %#x.\n", hr);
5353 IDirect3DSurface8_Release(surface2);
5354 IDirect3DSurface8_Release(surface);
5355 IDirect3DTexture8_Release(texture);
5357 refcount = IDirect3DDevice8_Release(device);
5358 ok(!refcount, "Device has %u references left.\n", refcount);
5359 IDirect3D8_Release(d3d8);
5360 DestroyWindow(window);
5363 static void test_surface_dimensions(void)
5365 IDirect3DSurface8 *surface;
5366 IDirect3DDevice8 *device;
5367 IDirect3D8 *d3d8;
5368 ULONG refcount;
5369 HWND window;
5370 HRESULT hr;
5372 window = create_window();
5373 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
5374 ok(!!d3d8, "Failed to create a D3D object.\n");
5375 if (!(device = create_device(d3d8, window, NULL)))
5377 skip("Failed to create a D3D device, skipping tests.\n");
5378 IDirect3D8_Release(d3d8);
5379 DestroyWindow(window);
5380 return;
5383 hr = IDirect3DDevice8_CreateImageSurface(device, 0, 1, D3DFMT_A8R8G8B8, &surface);
5384 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
5385 hr = IDirect3DDevice8_CreateImageSurface(device, 1, 0, D3DFMT_A8R8G8B8, &surface);
5386 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
5388 refcount = IDirect3DDevice8_Release(device);
5389 ok(!refcount, "Device has %u references left.\n", refcount);
5390 IDirect3D8_Release(d3d8);
5391 DestroyWindow(window);
5394 static void test_surface_format_null(void)
5396 static const D3DFORMAT D3DFMT_NULL = MAKEFOURCC('N','U','L','L');
5397 IDirect3DTexture8 *texture;
5398 IDirect3DSurface8 *surface;
5399 IDirect3DSurface8 *rt, *ds;
5400 D3DLOCKED_RECT locked_rect;
5401 IDirect3DDevice8 *device;
5402 D3DSURFACE_DESC desc;
5403 IDirect3D8 *d3d;
5404 ULONG refcount;
5405 HWND window;
5406 HRESULT hr;
5408 d3d = Direct3DCreate8(D3D_SDK_VERSION);
5409 ok(!!d3d, "Failed to create a D3D object.\n");
5411 hr = IDirect3D8_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
5412 D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, D3DFMT_NULL);
5413 if (hr != D3D_OK)
5415 skip("No D3DFMT_NULL support, skipping test.\n");
5416 IDirect3D8_Release(d3d);
5417 return;
5420 window = create_window();
5421 if (!(device = create_device(d3d, window, NULL)))
5423 skip("Failed to create a D3D device, skipping tests.\n");
5424 IDirect3D8_Release(d3d);
5425 DestroyWindow(window);
5426 return;
5429 hr = IDirect3D8_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
5430 D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, D3DFMT_NULL);
5431 ok(hr == D3D_OK, "D3DFMT_NULL should be supported for render target textures, hr %#x.\n", hr);
5433 hr = IDirect3D8_CheckDepthStencilMatch(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
5434 D3DFMT_NULL, D3DFMT_D24S8);
5435 ok(SUCCEEDED(hr), "Depth stencil match failed for D3DFMT_NULL, hr %#x.\n", hr);
5437 hr = IDirect3DDevice8_CreateRenderTarget(device, 128, 128, D3DFMT_NULL,
5438 D3DMULTISAMPLE_NONE, TRUE, &surface);
5439 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
5441 hr = IDirect3DDevice8_GetRenderTarget(device, &rt);
5442 ok(SUCCEEDED(hr), "Failed to get original render target, hr %#x.\n", hr);
5444 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &ds);
5445 ok(SUCCEEDED(hr), "Failed to get original depth/stencil, hr %#x.\n", hr);
5447 hr = IDirect3DDevice8_SetRenderTarget(device, surface, NULL);
5448 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
5450 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00000000, 0.0f, 0);
5451 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
5453 hr = IDirect3DDevice8_SetRenderTarget(device, rt, ds);
5454 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
5456 IDirect3DSurface8_Release(rt);
5457 IDirect3DSurface8_Release(ds);
5459 hr = IDirect3DSurface8_GetDesc(surface, &desc);
5460 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5461 ok(desc.Width == 128, "Expected width 128, got %u.\n", desc.Width);
5462 ok(desc.Height == 128, "Expected height 128, got %u.\n", desc.Height);
5464 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, NULL, 0);
5465 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
5466 ok(locked_rect.Pitch, "Expected non-zero pitch, got %u.\n", locked_rect.Pitch);
5467 ok(!!locked_rect.pBits, "Expected non-NULL pBits, got %p.\n", locked_rect.pBits);
5469 hr = IDirect3DSurface8_UnlockRect(surface);
5470 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5472 IDirect3DSurface8_Release(surface);
5474 hr = IDirect3DDevice8_CreateTexture(device, 128, 128, 0, D3DUSAGE_RENDERTARGET,
5475 D3DFMT_NULL, D3DPOOL_DEFAULT, &texture);
5476 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5477 IDirect3DTexture8_Release(texture);
5479 refcount = IDirect3DDevice8_Release(device);
5480 ok(!refcount, "Device has %u references left.\n", refcount);
5481 IDirect3D8_Release(d3d);
5482 DestroyWindow(window);
5485 static void test_surface_double_unlock(void)
5487 static const D3DPOOL pools[] =
5489 D3DPOOL_DEFAULT,
5490 D3DPOOL_SYSTEMMEM,
5492 IDirect3DSurface8 *surface;
5493 IDirect3DDevice8 *device;
5494 D3DLOCKED_RECT lr;
5495 IDirect3D8 *d3d;
5496 unsigned int i;
5497 ULONG refcount;
5498 HWND window;
5499 HRESULT hr;
5501 window = create_window();
5502 d3d = Direct3DCreate8(D3D_SDK_VERSION);
5503 ok(!!d3d, "Failed to create a D3D object.\n");
5504 if (!(device = create_device(d3d, window, NULL)))
5506 skip("Failed to create a D3D device, skipping tests.\n");
5507 IDirect3D8_Release(d3d);
5508 DestroyWindow(window);
5509 return;
5512 for (i = 0; i < ARRAY_SIZE(pools); ++i)
5514 switch (pools[i])
5516 case D3DPOOL_DEFAULT:
5517 hr = IDirect3D8_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
5518 D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, D3DFMT_X8R8G8B8);
5519 if (FAILED(hr))
5521 skip("D3DFMT_X8R8G8B8 render targets not supported, skipping double unlock DEFAULT pool test.\n");
5522 continue;
5525 hr = IDirect3DDevice8_CreateRenderTarget(device, 64, 64, D3DFMT_X8R8G8B8,
5526 D3DMULTISAMPLE_NONE, TRUE, &surface);
5527 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
5528 break;
5530 case D3DPOOL_SYSTEMMEM:
5531 hr = IDirect3DDevice8_CreateImageSurface(device, 64, 64, D3DFMT_X8R8G8B8, &surface);
5532 ok(SUCCEEDED(hr), "Failed to create image surface, hr %#x.\n", hr);
5533 break;
5535 default:
5536 break;
5539 hr = IDirect3DSurface8_UnlockRect(surface);
5540 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x, for surface in pool %#x.\n", hr, pools[i]);
5541 hr = IDirect3DSurface8_LockRect(surface, &lr, NULL, 0);
5542 ok(SUCCEEDED(hr), "Failed to lock surface in pool %#x, hr %#x.\n", pools[i], hr);
5543 hr = IDirect3DSurface8_UnlockRect(surface);
5544 ok(SUCCEEDED(hr), "Failed to unlock surface in pool %#x, hr %#x.\n", pools[i], hr);
5545 hr = IDirect3DSurface8_UnlockRect(surface);
5546 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x, for surface in pool %#x.\n", hr, pools[i]);
5548 IDirect3DSurface8_Release(surface);
5551 refcount = IDirect3DDevice8_Release(device);
5552 ok(!refcount, "Device has %u references left.\n", refcount);
5553 IDirect3D8_Release(d3d);
5554 DestroyWindow(window);
5557 static void test_surface_blocks(void)
5559 static const struct
5561 D3DFORMAT fmt;
5562 const char *name;
5563 unsigned int block_width;
5564 unsigned int block_height;
5565 BOOL broken;
5566 BOOL create_size_checked, core_fmt;
5568 formats[] =
5570 {D3DFMT_DXT1, "D3DFMT_DXT1", 4, 4, FALSE, TRUE, TRUE },
5571 {D3DFMT_DXT2, "D3DFMT_DXT2", 4, 4, FALSE, TRUE, TRUE },
5572 {D3DFMT_DXT3, "D3DFMT_DXT3", 4, 4, FALSE, TRUE, TRUE },
5573 {D3DFMT_DXT4, "D3DFMT_DXT4", 4, 4, FALSE, TRUE, TRUE },
5574 {D3DFMT_DXT5, "D3DFMT_DXT5", 4, 4, FALSE, TRUE, TRUE },
5575 /* ATI1N and ATI2N have 2x2 blocks on all AMD cards and Geforce 7 cards,
5576 * which doesn't match the format spec. On newer Nvidia cards
5577 * they have the correct 4x4 block size */
5578 {MAKEFOURCC('A','T','I','1'), "ATI1N", 4, 4, TRUE, FALSE, FALSE},
5579 {MAKEFOURCC('A','T','I','2'), "ATI2N", 4, 4, TRUE, FALSE, FALSE},
5580 /* Windows drivers generally enforce block-aligned locks for
5581 * YUY2 and UYVY. The notable exception is the AMD r500 driver
5582 * in d3d8. The same driver checks the sizes in d3d9. */
5583 {D3DFMT_YUY2, "D3DFMT_YUY2", 2, 1, TRUE, FALSE, TRUE },
5584 {D3DFMT_UYVY, "D3DFMT_UYVY", 2, 1, TRUE, FALSE, TRUE },
5586 static const struct
5588 D3DPOOL pool;
5589 const char *name;
5590 /* Don't check the return value, Nvidia returns D3DERR_INVALIDCALL for some formats
5591 * and E_INVALIDARG/DDERR_INVALIDPARAMS for others. */
5592 BOOL success;
5594 pools[] =
5596 {D3DPOOL_DEFAULT, "D3DPOOL_DEFAULT", FALSE},
5597 {D3DPOOL_SCRATCH, "D3DPOOL_SCRATCH", TRUE},
5598 {D3DPOOL_SYSTEMMEM, "D3DPOOL_SYSTEMMEM",TRUE},
5599 {D3DPOOL_MANAGED, "D3DPOOL_MANAGED", TRUE},
5601 static struct
5603 D3DRESOURCETYPE rtype;
5604 const char *type_name;
5605 D3DPOOL pool;
5606 const char *pool_name;
5607 BOOL need_driver_support, need_runtime_support;
5609 create_tests[] =
5611 /* D3d8 only supports sysmem surfaces, which are created via CreateImageSurface. Other tests confirm
5612 * that they are D3DPOOL_SYSTEMMEM surfaces, but their creation restriction behaves like the scratch
5613 * pool in d3d9. */
5614 {D3DRTYPE_SURFACE, "D3DRTYPE_SURFACE", D3DPOOL_SYSTEMMEM, "D3DPOOL_SYSTEMMEM", FALSE, TRUE },
5616 {D3DRTYPE_TEXTURE, "D3DRTYPE_TEXTURE", D3DPOOL_DEFAULT, "D3DPOOL_DEFAULT", TRUE, FALSE },
5617 {D3DRTYPE_TEXTURE, "D3DRTYPE_TEXTURE", D3DPOOL_SYSTEMMEM, "D3DPOOL_SYSTEMMEM", TRUE, FALSE },
5618 {D3DRTYPE_TEXTURE, "D3DRTYPE_TEXTURE", D3DPOOL_MANAGED, "D3DPOOL_MANAGED", TRUE, FALSE },
5619 {D3DRTYPE_TEXTURE, "D3DRTYPE_TEXTURE", D3DPOOL_SCRATCH, "D3DPOOL_SCRATCH", FALSE, TRUE },
5621 {D3DRTYPE_CUBETEXTURE, "D3DRTYPE_CUBETEXTURE", D3DPOOL_DEFAULT, "D3DPOOL_DEFAULT", TRUE, FALSE },
5622 {D3DRTYPE_CUBETEXTURE, "D3DRTYPE_CUBETEXTURE", D3DPOOL_SYSTEMMEM, "D3DPOOL_SYSTEMMEM", TRUE, FALSE },
5623 {D3DRTYPE_CUBETEXTURE, "D3DRTYPE_CUBETEXTURE", D3DPOOL_MANAGED, "D3DPOOL_MANAGED", TRUE, FALSE },
5624 {D3DRTYPE_CUBETEXTURE, "D3DRTYPE_CUBETEXTURE", D3DPOOL_SCRATCH, "D3DPOOL_SCRATCH", FALSE, TRUE },
5626 IDirect3DTexture8 *texture;
5627 IDirect3DCubeTexture8 *cube_texture;
5628 IDirect3DSurface8 *surface;
5629 D3DLOCKED_RECT locked_rect;
5630 IDirect3DDevice8 *device;
5631 unsigned int i, j, k, w, h;
5632 IDirect3D8 *d3d;
5633 ULONG refcount;
5634 HWND window;
5635 HRESULT hr;
5636 RECT rect;
5637 BOOL tex_pow2, cube_pow2;
5638 D3DCAPS8 caps;
5639 static const RECT invalid[] =
5641 {60, 60, 60, 68}, /* 0 height */
5642 {60, 60, 68, 60}, /* 0 width */
5643 {68, 60, 60, 68}, /* left > right */
5644 {60, 68, 68, 60}, /* top > bottom */
5645 {-8, 60, 0, 68}, /* left < surface */
5646 {60, -8, 68, 0}, /* top < surface */
5647 {-16, 60, -8, 68}, /* right < surface */
5648 {60, -16, 68, -8}, /* bottom < surface */
5649 {60, 60, 136, 68}, /* right > surface */
5650 {60, 60, 68, 136}, /* bottom > surface */
5651 {136, 60, 144, 68}, /* left > surface */
5652 {60, 136, 68, 144}, /* top > surface */
5655 window = create_window();
5656 d3d = Direct3DCreate8(D3D_SDK_VERSION);
5657 ok(!!d3d, "Failed to create a D3D object.\n");
5658 if (!(device = create_device(d3d, window, NULL)))
5660 skip("Failed to create a D3D device, skipping tests.\n");
5661 IDirect3D8_Release(d3d);
5662 DestroyWindow(window);
5663 return;
5666 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
5667 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
5668 tex_pow2 = caps.TextureCaps & D3DPTEXTURECAPS_POW2;
5669 if (tex_pow2)
5670 tex_pow2 = !(caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL);
5671 cube_pow2 = !!(caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP_POW2);
5673 for (i = 0; i < ARRAY_SIZE(formats); ++i)
5675 BOOL tex_support, cube_support, surface_support, format_known;
5677 hr = IDirect3D8_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
5678 0, D3DRTYPE_TEXTURE, formats[i].fmt);
5679 tex_support = SUCCEEDED(hr);
5680 hr = IDirect3D8_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
5681 0, D3DRTYPE_CUBETEXTURE, formats[i].fmt);
5682 cube_support = SUCCEEDED(hr);
5683 hr = IDirect3D8_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
5684 0, D3DRTYPE_SURFACE, formats[i].fmt);
5685 surface_support = SUCCEEDED(hr);
5687 /* Scratch pool in general allows texture creation even if the driver does
5688 * not support the format. If the format is an extension format that is not
5689 * known to the runtime, like ATI2N, some driver support is required for
5690 * this to work.
5692 * It is also possible that Windows Vista and Windows 7 d3d8 runtimes know
5693 * about ATI2N. I cannot check this because all my Vista+ machines support
5694 * ATI2N in hardware, but none of my WinXP machines do. */
5695 format_known = tex_support || cube_support || surface_support;
5697 for (w = 1; w <= 8; w++)
5699 for (h = 1; h <= 8; h++)
5701 BOOL block_aligned = TRUE;
5702 BOOL size_is_pow2;
5704 if (w & (formats[i].block_width - 1) || h & (formats[i].block_height - 1))
5705 block_aligned = FALSE;
5707 size_is_pow2 = !(w & (w - 1) || h & (h - 1));
5709 for (j = 0; j < ARRAY_SIZE(create_tests); j++)
5711 BOOL support, pow2;
5712 HRESULT expect_hr;
5713 BOOL may_succeed = FALSE;
5714 IUnknown **check_null;
5716 if (!formats[i].core_fmt)
5718 /* AMD warns against creating ATI2N textures smaller than
5719 * the block size because the runtime cannot calculate the
5720 * correct texture size. Generalize this for all extension
5721 * formats. */
5722 if (w < formats[i].block_width || h < formats[i].block_height)
5723 continue;
5726 texture = (IDirect3DTexture8 *)0xdeadbeef;
5727 cube_texture = (IDirect3DCubeTexture8 *)0xdeadbeef;
5728 surface = (IDirect3DSurface8 *)0xdeadbeef;
5730 switch (create_tests[j].rtype)
5732 case D3DRTYPE_TEXTURE:
5733 check_null = (IUnknown **)&texture;
5734 hr = IDirect3DDevice8_CreateTexture(device, w, h, 1, 0,
5735 formats[i].fmt, create_tests[j].pool, &texture);
5736 support = tex_support;
5737 pow2 = tex_pow2;
5738 break;
5740 case D3DRTYPE_CUBETEXTURE:
5741 if (w != h)
5742 continue;
5743 check_null = (IUnknown **)&cube_texture;
5744 hr = IDirect3DDevice8_CreateCubeTexture(device, w, 1, 0,
5745 formats[i].fmt, create_tests[j].pool, &cube_texture);
5746 support = cube_support;
5747 pow2 = cube_pow2;
5748 break;
5750 case D3DRTYPE_SURFACE:
5751 check_null = (IUnknown **)&surface;
5752 hr = IDirect3DDevice8_CreateImageSurface(device, w, h,
5753 formats[i].fmt, &surface);
5754 support = surface_support;
5755 pow2 = FALSE;
5756 break;
5758 default:
5759 pow2 = FALSE;
5760 support = FALSE;
5761 check_null = NULL;
5762 break;
5765 if (create_tests[j].need_driver_support && !support)
5766 expect_hr = D3DERR_INVALIDCALL;
5767 else if (create_tests[j].need_runtime_support && !formats[i].core_fmt && !format_known)
5768 expect_hr = D3DERR_INVALIDCALL;
5769 else if (formats[i].create_size_checked && !block_aligned)
5770 expect_hr = D3DERR_INVALIDCALL;
5771 else if (pow2 && !size_is_pow2 && create_tests[j].need_driver_support)
5772 expect_hr = D3DERR_INVALIDCALL;
5773 else
5774 expect_hr = D3D_OK;
5776 if (!formats[i].core_fmt && !format_known && FAILED(expect_hr))
5777 may_succeed = TRUE;
5779 /* Wine knows about ATI2N and happily creates a scratch resource even if GL
5780 * does not support it. Accept scratch creation of extension formats on
5781 * Windows as well if it occurs. We don't really care if e.g. a Windows 7
5782 * on an r200 GPU creates scratch ATI2N texture even though the card doesn't
5783 * support it. */
5784 ok(hr == expect_hr || ((SUCCEEDED(hr) && may_succeed)),
5785 "Got unexpected hr %#x for format %s, pool %s, type %s, size %ux%u.\n",
5786 hr, formats[i].name, create_tests[j].pool_name, create_tests[j].type_name, w, h);
5788 if (FAILED(hr))
5789 ok(*check_null == NULL, "Got object ptr %p, expected NULL.\n", *check_null);
5790 else
5791 IUnknown_Release(*check_null);
5796 hr = IDirect3D8_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
5797 D3DUSAGE_DYNAMIC, D3DRTYPE_TEXTURE, formats[i].fmt);
5798 if (FAILED(hr))
5800 skip("Format %s not supported, skipping lockrect offset tests.\n", formats[i].name);
5801 continue;
5804 for (j = 0; j < ARRAY_SIZE(pools); ++j)
5806 hr = IDirect3DDevice8_CreateTexture(device, 128, 128, 1,
5807 pools[j].pool == D3DPOOL_DEFAULT ? D3DUSAGE_DYNAMIC : 0,
5808 formats[i].fmt, pools[j].pool, &texture);
5809 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5810 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 0, &surface);
5811 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
5812 IDirect3DTexture8_Release(texture);
5814 if (formats[i].block_width > 1)
5816 SetRect(&rect, formats[i].block_width >> 1, 0, formats[i].block_width, formats[i].block_height);
5817 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, &rect, 0);
5818 ok(FAILED(hr) == !pools[j].success || broken(formats[i].broken),
5819 "Partial block lock %s, expected %s, format %s, pool %s.\n",
5820 SUCCEEDED(hr) ? "succeeded" : "failed",
5821 pools[j].success ? "success" : "failure", formats[i].name, pools[j].name);
5822 if (SUCCEEDED(hr))
5824 hr = IDirect3DSurface8_UnlockRect(surface);
5825 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5828 SetRect(&rect, 0, 0, formats[i].block_width >> 1, formats[i].block_height);
5829 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, &rect, 0);
5830 ok(FAILED(hr) == !pools[j].success || broken(formats[i].broken),
5831 "Partial block lock %s, expected %s, format %s, pool %s.\n",
5832 SUCCEEDED(hr) ? "succeeded" : "failed",
5833 pools[j].success ? "success" : "failure", formats[i].name, pools[j].name);
5834 if (SUCCEEDED(hr))
5836 hr = IDirect3DSurface8_UnlockRect(surface);
5837 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5841 if (formats[i].block_height > 1)
5843 SetRect(&rect, 0, formats[i].block_height >> 1, formats[i].block_width, formats[i].block_height);
5844 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, &rect, 0);
5845 ok(FAILED(hr) == !pools[j].success || broken(formats[i].broken),
5846 "Partial block lock %s, expected %s, format %s, pool %s.\n",
5847 SUCCEEDED(hr) ? "succeeded" : "failed",
5848 pools[j].success ? "success" : "failure", formats[i].name, pools[j].name);
5849 if (SUCCEEDED(hr))
5851 hr = IDirect3DSurface8_UnlockRect(surface);
5852 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5855 SetRect(&rect, 0, 0, formats[i].block_width, formats[i].block_height >> 1);
5856 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, &rect, 0);
5857 ok(FAILED(hr) == !pools[j].success || broken(formats[i].broken),
5858 "Partial block lock %s, expected %s, format %s, pool %s.\n",
5859 SUCCEEDED(hr) ? "succeeded" : "failed",
5860 pools[j].success ? "success" : "failure", formats[i].name, pools[j].name);
5861 if (SUCCEEDED(hr))
5863 hr = IDirect3DSurface8_UnlockRect(surface);
5864 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5868 for (k = 0; k < ARRAY_SIZE(invalid); ++k)
5870 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, &invalid[k], 0);
5871 ok(FAILED(hr) == !pools[j].success, "Invalid lock %s(%#x), expected %s, format %s, pool %s, case %u.\n",
5872 SUCCEEDED(hr) ? "succeeded" : "failed", hr, pools[j].success ? "success" : "failure",
5873 formats[i].name, pools[j].name, k);
5874 if (SUCCEEDED(hr))
5876 hr = IDirect3DSurface8_UnlockRect(surface);
5877 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5881 SetRect(&rect, 0, 0, formats[i].block_width, formats[i].block_height);
5882 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, &rect, 0);
5883 ok(hr == D3D_OK, "Got unexpected hr %#x for format %s, pool %s.\n", hr, formats[i].name, pools[j].name);
5884 hr = IDirect3DSurface8_UnlockRect(surface);
5885 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5887 IDirect3DSurface8_Release(surface);
5890 if (formats[i].block_width == 1 && formats[i].block_height == 1)
5891 continue;
5892 if (!formats[i].core_fmt)
5893 continue;
5895 hr = IDirect3DDevice8_CreateTexture(device, formats[i].block_width, formats[i].block_height, 2,
5896 D3DUSAGE_DYNAMIC, formats[i].fmt, D3DPOOL_DEFAULT, &texture);
5897 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x, format %s.\n", hr, formats[i].name);
5899 hr = IDirect3DTexture8_LockRect(texture, 1, &locked_rect, NULL, 0);
5900 ok(SUCCEEDED(hr), "Failed lock texture, hr %#x.\n", hr);
5901 hr = IDirect3DTexture8_UnlockRect(texture, 1);
5902 ok(SUCCEEDED(hr), "Failed lock texture, hr %#x.\n", hr);
5904 rect.left = 0;
5905 rect.top = 0;
5906 rect.right = formats[i].block_width == 1 ? 1 : formats[i].block_width >> 1;
5907 rect.bottom = formats[i].block_height == 1 ? 1 : formats[i].block_height >> 1;
5908 hr = IDirect3DTexture8_LockRect(texture, 1, &locked_rect, &rect, 0);
5909 ok(SUCCEEDED(hr), "Failed lock texture, hr %#x.\n", hr);
5910 hr = IDirect3DTexture8_UnlockRect(texture, 1);
5911 ok(SUCCEEDED(hr), "Failed lock texture, hr %#x.\n", hr);
5913 rect.right = formats[i].block_width;
5914 rect.bottom = formats[i].block_height;
5915 hr = IDirect3DTexture8_LockRect(texture, 1, &locked_rect, &rect, 0);
5916 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
5917 if (SUCCEEDED(hr))
5918 IDirect3DTexture8_UnlockRect(texture, 1);
5920 IDirect3DTexture8_Release(texture);
5923 refcount = IDirect3DDevice8_Release(device);
5924 ok(!refcount, "Device has %u references left.\n", refcount);
5925 IDirect3D8_Release(d3d);
5926 DestroyWindow(window);
5929 static void test_set_palette(void)
5931 IDirect3DDevice8 *device;
5932 IDirect3D8 *d3d8;
5933 UINT refcount;
5934 HWND window;
5935 HRESULT hr;
5936 PALETTEENTRY pal[256];
5937 unsigned int i;
5938 D3DCAPS8 caps;
5940 window = create_window();
5941 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
5942 ok(!!d3d8, "Failed to create a D3D object.\n");
5943 if (!(device = create_device(d3d8, window, NULL)))
5945 skip("Failed to create a D3D device, skipping tests.\n");
5946 IDirect3D8_Release(d3d8);
5947 DestroyWindow(window);
5948 return;
5951 for (i = 0; i < ARRAY_SIZE(pal); i++)
5953 pal[i].peRed = i;
5954 pal[i].peGreen = i;
5955 pal[i].peBlue = i;
5956 pal[i].peFlags = 0xff;
5958 hr = IDirect3DDevice8_SetPaletteEntries(device, 0, pal);
5959 ok(SUCCEEDED(hr), "Failed to set palette entries, hr %#x.\n", hr);
5961 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
5962 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
5963 for (i = 0; i < ARRAY_SIZE(pal); i++)
5965 pal[i].peRed = i;
5966 pal[i].peGreen = i;
5967 pal[i].peBlue = i;
5968 pal[i].peFlags = i;
5970 if (caps.TextureCaps & D3DPTEXTURECAPS_ALPHAPALETTE)
5972 hr = IDirect3DDevice8_SetPaletteEntries(device, 0, pal);
5973 ok(SUCCEEDED(hr), "Failed to set palette entries, hr %#x.\n", hr);
5975 else
5977 hr = IDirect3DDevice8_SetPaletteEntries(device, 0, pal);
5978 ok(hr == D3DERR_INVALIDCALL, "SetPaletteEntries returned %#x, expected D3DERR_INVALIDCALL.\n", hr);
5981 refcount = IDirect3DDevice8_Release(device);
5982 ok(!refcount, "Device has %u references left.\n", refcount);
5983 IDirect3D8_Release(d3d8);
5984 DestroyWindow(window);
5987 static void test_swvp_buffer(void)
5989 IDirect3DDevice8 *device;
5990 IDirect3D8 *d3d8;
5991 UINT refcount;
5992 HWND window;
5993 HRESULT hr;
5994 unsigned int i;
5995 IDirect3DVertexBuffer8 *buffer;
5996 static const unsigned int bufsize = 1024;
5997 D3DVERTEXBUFFER_DESC desc;
5998 struct device_desc device_desc;
5999 struct
6001 float x, y, z;
6002 } *ptr, *ptr2;
6004 window = create_window();
6005 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
6006 ok(!!d3d8, "Failed to create a D3D object.\n");
6008 device_desc.device_window = window;
6009 device_desc.width = 640;
6010 device_desc.height = 480;
6011 device_desc.flags = CREATE_DEVICE_SWVP_ONLY;
6012 if (!(device = create_device(d3d8, window, &device_desc)))
6014 skip("Failed to create a D3D device, skipping tests.\n");
6015 IDirect3D8_Release(d3d8);
6016 DestroyWindow(window);
6017 return;
6020 hr = IDirect3DDevice8_CreateVertexBuffer(device, bufsize * sizeof(*ptr), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, 0,
6021 D3DPOOL_DEFAULT, &buffer);
6022 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
6023 hr = IDirect3DVertexBuffer8_GetDesc(buffer, &desc);
6024 ok(SUCCEEDED(hr), "Failed to get desc, hr %#x.\n", hr);
6025 ok(desc.Pool == D3DPOOL_DEFAULT, "Got pool %u, expected D3DPOOL_DEFAULT\n", desc.Pool);
6026 ok(desc.Usage == (D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY),
6027 "Got usage %u, expected D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY\n", desc.Usage);
6029 hr = IDirect3DVertexBuffer8_Lock(buffer, 0, bufsize * sizeof(*ptr), (BYTE **)&ptr, D3DLOCK_DISCARD);
6030 ok(SUCCEEDED(hr), "Failed to lock buffer, hr %#x.\n", hr);
6031 for (i = 0; i < bufsize; i++)
6033 ptr[i].x = i * 1.0f;
6034 ptr[i].y = i * 2.0f;
6035 ptr[i].z = i * 3.0f;
6037 hr = IDirect3DVertexBuffer8_Unlock(buffer);
6038 ok(SUCCEEDED(hr), "Failed to unlock buffer, hr %#x.\n", hr);
6040 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ);
6041 ok(SUCCEEDED(hr), "Failed to set fvf, hr %#x.\n", hr);
6042 hr = IDirect3DDevice8_SetStreamSource(device, 0, buffer, sizeof(*ptr));
6043 ok(SUCCEEDED(hr), "Failed to set stream source, hr %#x.\n", hr);
6044 hr = IDirect3DDevice8_BeginScene(device);
6045 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
6046 hr = IDirect3DDevice8_DrawPrimitive(device, D3DPT_TRIANGLELIST, 0, 2);
6047 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6048 hr = IDirect3DDevice8_EndScene(device);
6049 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
6051 hr = IDirect3DVertexBuffer8_Lock(buffer, 0, bufsize * sizeof(*ptr2), (BYTE **)&ptr2, D3DLOCK_DISCARD);
6052 ok(SUCCEEDED(hr), "Failed to lock buffer, hr %#x.\n", hr);
6053 ok(ptr == ptr2, "Lock returned two different pointers: %p, %p\n", ptr, ptr2);
6054 for (i = 0; i < bufsize; i++)
6056 if (ptr2[i].x != i * 1.0f || ptr2[i].y != i * 2.0f || ptr2[i].z != i * 3.0f)
6058 ok(FALSE, "Vertex %u is %f,%f,%f, expected %f,%f,%f\n", i,
6059 ptr2[i].x, ptr2[i].y, ptr2[i].z, i * 1.0f, i * 2.0f, i * 3.0f);
6060 break;
6063 hr = IDirect3DVertexBuffer8_Unlock(buffer);
6064 ok(SUCCEEDED(hr), "Failed to unlock buffer, hr %#x.\n", hr);
6066 IDirect3DVertexBuffer8_Release(buffer);
6067 refcount = IDirect3DDevice8_Release(device);
6068 ok(!refcount, "Device has %u references left.\n", refcount);
6069 IDirect3D8_Release(d3d8);
6070 DestroyWindow(window);
6073 static void test_managed_buffer(void)
6075 static const unsigned int vertex_count = 1024;
6076 IDirect3DVertexBuffer8 *buffer;
6077 D3DVERTEXBUFFER_DESC desc;
6078 IDirect3DDevice8 *device;
6079 struct vec3 *ptr, *ptr2;
6080 IDirect3D8 *d3d8;
6081 unsigned int i;
6082 UINT refcount;
6083 HWND window;
6084 HRESULT hr;
6086 window = create_window();
6087 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
6088 ok(!!d3d8, "Failed to create a D3D object.\n");
6089 if (!(device = create_device(d3d8, window, NULL)))
6091 skip("Failed to create a D3D device, skipping tests.\n");
6092 IDirect3D8_Release(d3d8);
6093 DestroyWindow(window);
6094 return;
6097 hr = IDirect3DDevice8_CreateVertexBuffer(device, vertex_count * sizeof(*ptr), 0, 0, D3DPOOL_MANAGED, &buffer);
6098 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
6099 hr = IDirect3DVertexBuffer8_GetDesc(buffer, &desc);
6100 ok(SUCCEEDED(hr), "Failed to get desc, hr %#x.\n", hr);
6101 ok(desc.Pool == D3DPOOL_MANAGED, "Got unexpected pool %#x.\n", desc.Pool);
6102 ok(!desc.Usage, "Got unexpected usage %#x.\n", desc.Usage);
6104 hr = IDirect3DVertexBuffer8_Lock(buffer, 0, vertex_count * sizeof(*ptr), (BYTE **)&ptr, D3DLOCK_DISCARD);
6105 ok(SUCCEEDED(hr), "Failed to lock buffer, hr %#x.\n", hr);
6106 for (i = 0; i < vertex_count; ++i)
6108 ptr[i].x = i * 1.0f;
6109 ptr[i].y = i * 2.0f;
6110 ptr[i].z = i * 3.0f;
6112 hr = IDirect3DVertexBuffer8_Unlock(buffer);
6113 ok(SUCCEEDED(hr), "Failed to unlock buffer, hr %#x.\n", hr);
6115 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ);
6116 ok(SUCCEEDED(hr), "Failed to set fvf, hr %#x.\n", hr);
6117 hr = IDirect3DDevice8_SetStreamSource(device, 0, buffer, sizeof(*ptr));
6118 ok(SUCCEEDED(hr), "Failed to set stream source, hr %#x.\n", hr);
6119 hr = IDirect3DDevice8_BeginScene(device);
6120 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
6121 hr = IDirect3DDevice8_DrawPrimitive(device, D3DPT_TRIANGLELIST, 0, 2);
6122 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6123 hr = IDirect3DDevice8_EndScene(device);
6124 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
6126 hr = IDirect3DVertexBuffer8_Lock(buffer, 0, vertex_count * sizeof(*ptr2), (BYTE **)&ptr2, D3DLOCK_DISCARD);
6127 ok(SUCCEEDED(hr), "Failed to lock buffer, hr %#x.\n", hr);
6128 ok(ptr2 == ptr, "Got unexpected ptr2 %p, expected %p.\n", ptr2, ptr);
6129 for (i = 0; i < vertex_count; ++i)
6131 if (ptr2[i].x != i * 1.0f || ptr2[i].y != i * 2.0f || ptr2[i].z != i * 3.0f)
6133 ok(FALSE, "Got unexpected vertex %u {%.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e}.\n",
6134 i, ptr2[i].x, ptr2[i].y, ptr2[i].z, i * 1.0f, i * 2.0f, i * 3.0f);
6135 break;
6138 hr = IDirect3DVertexBuffer8_Unlock(buffer);
6139 ok(SUCCEEDED(hr), "Failed to unlock buffer, hr %#x.\n", hr);
6141 IDirect3DVertexBuffer8_Release(buffer);
6142 refcount = IDirect3DDevice8_Release(device);
6143 ok(!refcount, "Device has %u references left.\n", refcount);
6144 IDirect3D8_Release(d3d8);
6145 DestroyWindow(window);
6148 static void test_npot_textures(void)
6150 IDirect3DDevice8 *device = NULL;
6151 IDirect3D8 *d3d8;
6152 ULONG refcount;
6153 HWND window = NULL;
6154 HRESULT hr;
6155 D3DCAPS8 caps;
6156 IDirect3DTexture8 *texture;
6157 IDirect3DCubeTexture8 *cube_texture;
6158 IDirect3DVolumeTexture8 *volume_texture;
6159 struct
6161 D3DPOOL pool;
6162 const char *pool_name;
6163 HRESULT hr;
6165 pools[] =
6167 { D3DPOOL_DEFAULT, "D3DPOOL_DEFAULT", D3DERR_INVALIDCALL },
6168 { D3DPOOL_MANAGED, "D3DPOOL_MANAGED", D3DERR_INVALIDCALL },
6169 { D3DPOOL_SYSTEMMEM, "D3DPOOL_SYSTEMMEM", D3DERR_INVALIDCALL },
6170 { D3DPOOL_SCRATCH, "D3DPOOL_SCRATCH", D3D_OK },
6172 unsigned int i, levels;
6173 BOOL tex_pow2, cube_pow2, vol_pow2;
6175 window = create_window();
6176 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
6177 ok(!!d3d8, "Failed to create a D3D object.\n");
6178 if (!(device = create_device(d3d8, window, NULL)))
6180 skip("Failed to create a D3D device, skipping tests.\n");
6181 goto done;
6184 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
6185 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
6186 tex_pow2 = !!(caps.TextureCaps & D3DPTEXTURECAPS_POW2);
6187 cube_pow2 = !!(caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP_POW2);
6188 vol_pow2 = !!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP_POW2);
6189 ok(cube_pow2 == tex_pow2, "Cube texture and 2d texture pow2 restrictions mismatch.\n");
6190 ok(vol_pow2 == tex_pow2, "Volume texture and 2d texture pow2 restrictions mismatch.\n");
6192 for (i = 0; i < ARRAY_SIZE(pools); i++)
6194 for (levels = 0; levels <= 2; levels++)
6196 HRESULT expected;
6198 hr = IDirect3DDevice8_CreateTexture(device, 10, 10, levels, 0, D3DFMT_X8R8G8B8,
6199 pools[i].pool, &texture);
6200 if (!tex_pow2)
6202 expected = D3D_OK;
6204 else if (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL)
6206 if (levels == 1)
6207 expected = D3D_OK;
6208 else
6209 expected = pools[i].hr;
6211 else
6213 expected = pools[i].hr;
6215 ok(hr == expected, "CreateTexture(w=h=10, %s, levels=%u) returned hr %#x, expected %#x.\n",
6216 pools[i].pool_name, levels, hr, expected);
6218 if (SUCCEEDED(hr))
6219 IDirect3DTexture8_Release(texture);
6222 hr = IDirect3DDevice8_CreateCubeTexture(device, 3, 1, 0, D3DFMT_X8R8G8B8,
6223 pools[i].pool, &cube_texture);
6224 if (tex_pow2)
6226 ok(hr == pools[i].hr, "CreateCubeTexture(EdgeLength=3, %s) returned hr %#x, expected %#x.\n",
6227 pools[i].pool_name, hr, pools[i].hr);
6229 else
6231 ok(SUCCEEDED(hr), "CreateCubeTexture(EdgeLength=3, %s) returned hr %#x, expected %#x.\n",
6232 pools[i].pool_name, hr, D3D_OK);
6235 if (SUCCEEDED(hr))
6236 IDirect3DCubeTexture8_Release(cube_texture);
6238 hr = IDirect3DDevice8_CreateVolumeTexture(device, 2, 2, 3, 1, 0, D3DFMT_X8R8G8B8,
6239 pools[i].pool, &volume_texture);
6240 if (tex_pow2)
6242 ok(hr == pools[i].hr, "CreateVolumeTextur(Depth=3, %s) returned hr %#x, expected %#x.\n",
6243 pools[i].pool_name, hr, pools[i].hr);
6245 else
6247 ok(SUCCEEDED(hr), "CreateVolumeTextur(Depth=3, %s) returned hr %#x, expected %#x.\n",
6248 pools[i].pool_name, hr, D3D_OK);
6251 if (SUCCEEDED(hr))
6252 IDirect3DVolumeTexture8_Release(volume_texture);
6255 done:
6256 if (device)
6258 refcount = IDirect3DDevice8_Release(device);
6259 ok(!refcount, "Device has %u references left.\n", refcount);
6261 IDirect3D8_Release(d3d8);
6262 DestroyWindow(window);
6266 static void test_volume_locking(void)
6268 IDirect3DDevice8 *device;
6269 IDirect3D8 *d3d8;
6270 HWND window;
6271 HRESULT hr;
6272 IDirect3DVolumeTexture8 *texture;
6273 unsigned int i;
6274 D3DLOCKED_BOX locked_box;
6275 ULONG refcount;
6276 D3DCAPS8 caps;
6277 static const struct
6279 D3DPOOL pool;
6280 DWORD usage;
6281 HRESULT create_hr, lock_hr;
6283 tests[] =
6285 { D3DPOOL_DEFAULT, 0, D3D_OK, D3DERR_INVALIDCALL },
6286 { D3DPOOL_DEFAULT, D3DUSAGE_DYNAMIC, D3D_OK, D3D_OK },
6287 { D3DPOOL_SYSTEMMEM, 0, D3D_OK, D3D_OK },
6288 { D3DPOOL_SYSTEMMEM, D3DUSAGE_DYNAMIC, D3D_OK, D3D_OK },
6289 { D3DPOOL_MANAGED, 0, D3D_OK, D3D_OK },
6290 { D3DPOOL_MANAGED, D3DUSAGE_DYNAMIC, D3DERR_INVALIDCALL, D3D_OK },
6291 { D3DPOOL_SCRATCH, 0, D3D_OK, D3D_OK },
6292 { D3DPOOL_SCRATCH, D3DUSAGE_DYNAMIC, D3DERR_INVALIDCALL, D3D_OK },
6295 window = create_window();
6296 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
6297 ok(!!d3d8, "Failed to create a D3D object.\n");
6298 if (!(device = create_device(d3d8, window, NULL)))
6300 skip("Failed to create a D3D device, skipping tests.\n");
6301 IDirect3D8_Release(d3d8);
6302 DestroyWindow(window);
6303 return;
6306 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
6307 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
6308 if (!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP))
6310 skip("Volume textures not supported, skipping test.\n");
6311 goto out;
6314 for (i = 0; i < ARRAY_SIZE(tests); i++)
6316 hr = IDirect3DDevice8_CreateVolumeTexture(device, 4, 4, 4, 1, tests[i].usage,
6317 D3DFMT_A8R8G8B8, tests[i].pool, &texture);
6318 ok(hr == tests[i].create_hr, "Creating volume texture pool=%u, usage=%#x returned %#x, expected %#x.\n",
6319 tests[i].pool, tests[i].usage, hr, tests[i].create_hr);
6320 if (FAILED(hr))
6321 continue;
6323 locked_box.pBits = (void *)0xdeadbeef;
6324 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, NULL, 0);
6325 ok(hr == tests[i].lock_hr, "Lock returned %#x, expected %#x.\n", hr, tests[i].lock_hr);
6326 if (SUCCEEDED(hr))
6328 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6329 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6331 else
6333 ok (locked_box.pBits == NULL, "Failed lock set pBits = %p, expected NULL.\n", locked_box.pBits);
6335 IDirect3DVolumeTexture8_Release(texture);
6338 out:
6339 refcount = IDirect3DDevice8_Release(device);
6340 ok(!refcount, "Device has %u references left.\n", refcount);
6341 IDirect3D8_Release(d3d8);
6342 DestroyWindow(window);
6345 static void test_update_volumetexture(void)
6347 IDirect3DDevice8 *device;
6348 IDirect3D8 *d3d8;
6349 HWND window;
6350 HRESULT hr;
6351 IDirect3DVolumeTexture8 *src, *dst;
6352 unsigned int i;
6353 D3DLOCKED_BOX locked_box;
6354 ULONG refcount;
6355 D3DCAPS8 caps;
6356 static const struct
6358 D3DPOOL src_pool, dst_pool;
6359 HRESULT hr;
6361 tests[] =
6363 { D3DPOOL_DEFAULT, D3DPOOL_DEFAULT, D3DERR_INVALIDCALL },
6364 { D3DPOOL_MANAGED, D3DPOOL_DEFAULT, D3DERR_INVALIDCALL },
6365 { D3DPOOL_SYSTEMMEM, D3DPOOL_DEFAULT, D3D_OK },
6366 { D3DPOOL_SCRATCH, D3DPOOL_DEFAULT, D3DERR_INVALIDCALL },
6368 { D3DPOOL_DEFAULT, D3DPOOL_MANAGED, D3DERR_INVALIDCALL },
6369 { D3DPOOL_MANAGED, D3DPOOL_MANAGED, D3DERR_INVALIDCALL },
6370 { D3DPOOL_SYSTEMMEM, D3DPOOL_MANAGED, D3DERR_INVALIDCALL },
6371 { D3DPOOL_SCRATCH, D3DPOOL_MANAGED, D3DERR_INVALIDCALL },
6373 { D3DPOOL_DEFAULT, D3DPOOL_SYSTEMMEM, D3DERR_INVALIDCALL },
6374 { D3DPOOL_MANAGED, D3DPOOL_SYSTEMMEM, D3DERR_INVALIDCALL },
6375 { D3DPOOL_SYSTEMMEM, D3DPOOL_SYSTEMMEM, D3DERR_INVALIDCALL },
6376 { D3DPOOL_SCRATCH, D3DPOOL_SYSTEMMEM, D3DERR_INVALIDCALL },
6378 { D3DPOOL_DEFAULT, D3DPOOL_SCRATCH, D3DERR_INVALIDCALL },
6379 { D3DPOOL_MANAGED, D3DPOOL_SCRATCH, D3DERR_INVALIDCALL },
6380 { D3DPOOL_SYSTEMMEM, D3DPOOL_SCRATCH, D3DERR_INVALIDCALL },
6381 { D3DPOOL_SCRATCH, D3DPOOL_SCRATCH, D3DERR_INVALIDCALL },
6383 static const struct
6385 UINT src_size, dst_size;
6386 UINT src_lvl, dst_lvl;
6387 D3DFORMAT src_fmt, dst_fmt;
6389 tests2[] =
6391 { 8, 8, 0, 0, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 },
6392 { 8, 8, 4, 4, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 },
6393 { 8, 8, 2, 2, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 },
6394 { 8, 8, 1, 1, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 },
6395 { 8, 8, 4, 0, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 },
6396 { 8, 8, 1, 4, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 }, /* Different level count */
6397 { 4, 8, 1, 1, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 }, /* Different size */
6398 { 8, 8, 4, 4, D3DFMT_A8R8G8B8, D3DFMT_X8R8G8B8 }, /* Different format */
6401 window = create_window();
6402 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
6403 ok(!!d3d8, "Failed to create a D3D object.\n");
6404 if (!(device = create_device(d3d8, window, NULL)))
6406 skip("Failed to create a D3D device, skipping tests.\n");
6407 IDirect3D8_Release(d3d8);
6408 DestroyWindow(window);
6409 return;
6412 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
6413 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
6414 if (!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP))
6416 skip("Volume textures not supported, skipping test.\n");
6417 goto out;
6420 for (i = 0; i < ARRAY_SIZE(tests); i++)
6422 DWORD src_usage = tests[i].src_pool == D3DPOOL_DEFAULT ? D3DUSAGE_DYNAMIC : 0;
6423 DWORD dst_usage = tests[i].dst_pool == D3DPOOL_DEFAULT ? D3DUSAGE_DYNAMIC : 0;
6425 hr = IDirect3DDevice8_CreateVolumeTexture(device, 1, 1, 1, 1, src_usage,
6426 D3DFMT_A8R8G8B8, tests[i].src_pool, &src);
6427 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x.\n", hr);
6428 hr = IDirect3DDevice8_CreateVolumeTexture(device, 1, 1, 1, 1, dst_usage,
6429 D3DFMT_A8R8G8B8, tests[i].dst_pool, &dst);
6430 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x.\n", hr);
6432 hr = IDirect3DVolumeTexture8_LockBox(src, 0, &locked_box, NULL, 0);
6433 ok(SUCCEEDED(hr), "Failed to lock volume texture, hr %#x.\n", hr);
6434 *((DWORD *)locked_box.pBits) = 0x11223344;
6435 hr = IDirect3DVolumeTexture8_UnlockBox(src, 0);
6436 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6438 hr = IDirect3DDevice8_UpdateTexture(device, (IDirect3DBaseTexture8 *)src, (IDirect3DBaseTexture8 *)dst);
6439 ok(hr == tests[i].hr, "UpdateTexture returned %#x, expected %#x, src pool %x, dst pool %u.\n",
6440 hr, tests[i].hr, tests[i].src_pool, tests[i].dst_pool);
6442 if (SUCCEEDED(hr))
6444 DWORD content = *((DWORD *)locked_box.pBits);
6445 hr = IDirect3DVolumeTexture8_LockBox(dst, 0, &locked_box, NULL, 0);
6446 ok(SUCCEEDED(hr), "Failed to lock volume texture, hr %#x.\n", hr);
6447 ok(content == 0x11223344, "Dest texture contained %#x, expected 0x11223344.\n", content);
6448 hr = IDirect3DVolumeTexture8_UnlockBox(dst, 0);
6449 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6451 IDirect3DVolumeTexture8_Release(src);
6452 IDirect3DVolumeTexture8_Release(dst);
6455 if (!(caps.TextureCaps & D3DPTEXTURECAPS_MIPVOLUMEMAP))
6457 skip("Mipmapped volume maps not supported.\n");
6458 goto out;
6461 for (i = 0; i < ARRAY_SIZE(tests2); i++)
6463 hr = IDirect3DDevice8_CreateVolumeTexture(device,
6464 tests2[i].src_size, tests2[i].src_size, tests2[i].src_size,
6465 tests2[i].src_lvl, 0, tests2[i].src_fmt, D3DPOOL_SYSTEMMEM, &src);
6466 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x, case %u.\n", hr, i);
6467 hr = IDirect3DDevice8_CreateVolumeTexture(device,
6468 tests2[i].dst_size, tests2[i].dst_size, tests2[i].dst_size,
6469 tests2[i].dst_lvl, 0, tests2[i].dst_fmt, D3DPOOL_DEFAULT, &dst);
6470 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x, case %u.\n", hr, i);
6472 hr = IDirect3DDevice8_UpdateTexture(device, (IDirect3DBaseTexture8 *)src, (IDirect3DBaseTexture8 *)dst);
6473 todo_wine_if (FAILED(hr))
6474 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x, case %u.\n", hr, i);
6476 IDirect3DVolumeTexture8_Release(src);
6477 IDirect3DVolumeTexture8_Release(dst);
6480 /* As far as I can see, UpdateTexture on non-matching texture behaves like a memcpy. The raw data
6481 * stays the same in a format change, a 2x2x1 texture is copied into the first row of a 4x4x1 texture,
6482 * etc. I could not get it to segfault, but the nonexistent 5th pixel of a 2x2x1 texture is copied into
6483 * pixel 1x2x1 of a 4x4x1 texture, demonstrating a read beyond the texture's end. I suspect any bad
6484 * memory access is silently ignored by the runtime, in the kernel or on the GPU.
6486 * I'm not adding tests for this behavior until an application needs it. */
6488 out:
6489 refcount = IDirect3DDevice8_Release(device);
6490 ok(!refcount, "Device has %u references left.\n", refcount);
6491 IDirect3D8_Release(d3d8);
6492 DestroyWindow(window);
6495 static void test_create_rt_ds_fail(void)
6497 IDirect3DDevice8 *device;
6498 HWND window;
6499 HRESULT hr;
6500 ULONG refcount;
6501 IDirect3D8 *d3d8;
6502 IDirect3DSurface8 *surface;
6504 window = create_window();
6505 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
6506 ok(!!d3d8, "Failed to create a D3D object.\n");
6507 if (!(device = create_device(d3d8, window, NULL)))
6509 skip("Failed to create a D3D device, skipping tests.\n");
6510 IDirect3D8_Release(d3d8);
6511 DestroyWindow(window);
6512 return;
6515 /* Output pointer == NULL segfaults on Windows. */
6517 surface = (IDirect3DSurface8 *)0xdeadbeef;
6518 hr = IDirect3DDevice8_CreateRenderTarget(device, 4, 4, D3DFMT_D16,
6519 D3DMULTISAMPLE_NONE, FALSE, &surface);
6520 ok(hr == D3DERR_INVALIDCALL, "Creating a D16 render target returned hr %#x.\n", hr);
6521 ok(surface == NULL, "Got pointer %p, expected NULL.\n", surface);
6522 if (SUCCEEDED(hr))
6523 IDirect3DSurface8_Release(surface);
6525 surface = (IDirect3DSurface8 *)0xdeadbeef;
6526 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 4, 4, D3DFMT_A8R8G8B8,
6527 D3DMULTISAMPLE_NONE, &surface);
6528 ok(hr == D3DERR_INVALIDCALL, "Creating a A8R8G8B8 depth stencil returned hr %#x.\n", hr);
6529 ok(surface == NULL, "Got pointer %p, expected NULL.\n", surface);
6530 if (SUCCEEDED(hr))
6531 IDirect3DSurface8_Release(surface);
6533 refcount = IDirect3DDevice8_Release(device);
6534 ok(!refcount, "Device has %u references left.\n", refcount);
6535 IDirect3D8_Release(d3d8);
6536 DestroyWindow(window);
6539 static void test_volume_blocks(void)
6541 IDirect3DDevice8 *device;
6542 IDirect3D8 *d3d8;
6543 UINT refcount;
6544 HWND window;
6545 HRESULT hr;
6546 D3DCAPS8 caps;
6547 IDirect3DVolumeTexture8 *texture;
6548 unsigned int w, h, d, i, j;
6549 static const struct
6551 D3DFORMAT fmt;
6552 const char *name;
6553 unsigned int block_width;
6554 unsigned int block_height;
6555 unsigned int block_depth;
6556 unsigned int block_size;
6557 unsigned int broken;
6558 BOOL create_size_checked, core_fmt;
6560 formats[] =
6562 /* Scratch volumes enforce DXTn block locks, unlike their surface counterparts.
6563 * ATI2N and YUV blocks are not enforced on any tested card (r200, gtx 460). */
6564 {D3DFMT_DXT1, "D3DFMT_DXT1", 4, 4, 1, 8, 0, TRUE, TRUE },
6565 {D3DFMT_DXT2, "D3DFMT_DXT2", 4, 4, 1, 16, 0, TRUE, TRUE },
6566 {D3DFMT_DXT3, "D3DFMT_DXT3", 4, 4, 1, 16, 0, TRUE, TRUE },
6567 {D3DFMT_DXT4, "D3DFMT_DXT4", 4, 4, 1, 16, 0, TRUE, TRUE },
6568 {D3DFMT_DXT5, "D3DFMT_DXT5", 4, 4, 1, 16, 0, TRUE, TRUE },
6569 {D3DFMT_DXT5, "D3DFMT_DXT5", 4, 4, 1, 16, 0, TRUE, TRUE },
6570 /* ATI2N has 2x2 blocks on all AMD cards and Geforce 7 cards,
6571 * which doesn't match the format spec. On newer Nvidia cards
6572 * it has the correct 4x4 block size.
6573 * ATI1N volume textures are only supported by AMD GPUs right
6574 * now and locking offsets seem just wrong. */
6575 {MAKEFOURCC('A','T','I','1'), "ATI1N", 4, 4, 1, 8, 2, FALSE, FALSE},
6576 {MAKEFOURCC('A','T','I','2'), "ATI2N", 4, 4, 1, 16, 1, FALSE, FALSE},
6577 {D3DFMT_YUY2, "D3DFMT_YUY2", 2, 1, 1, 4, 1, FALSE, TRUE },
6578 {D3DFMT_UYVY, "D3DFMT_UYVY", 2, 1, 1, 4, 1, FALSE, TRUE },
6580 static const struct
6582 D3DPOOL pool;
6583 const char *name;
6584 BOOL need_driver_support, need_runtime_support;
6586 create_tests[] =
6588 {D3DPOOL_DEFAULT, "D3DPOOL_DEFAULT", TRUE, FALSE},
6589 {D3DPOOL_SCRATCH, "D3DPOOL_SCRATCH", FALSE, TRUE },
6590 {D3DPOOL_SYSTEMMEM, "D3DPOOL_SYSTEMMEM",TRUE, FALSE},
6591 {D3DPOOL_MANAGED, "D3DPOOL_MANAGED", TRUE, FALSE},
6593 static const struct
6595 unsigned int x, y, z, x2, y2, z2;
6597 offset_tests[] =
6599 {0, 0, 0, 8, 8, 8},
6600 {0, 0, 3, 8, 8, 8},
6601 {0, 4, 0, 8, 8, 8},
6602 {0, 4, 3, 8, 8, 8},
6603 {4, 0, 0, 8, 8, 8},
6604 {4, 0, 3, 8, 8, 8},
6605 {4, 4, 0, 8, 8, 8},
6606 {4, 4, 3, 8, 8, 8},
6608 D3DBOX box;
6609 D3DLOCKED_BOX locked_box;
6610 BYTE *base;
6611 INT expected_row_pitch, expected_slice_pitch;
6612 BOOL support;
6613 BOOL pow2;
6614 unsigned int offset, expected_offset;
6616 window = create_window();
6617 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
6618 ok(!!d3d8, "Failed to create a D3D object.\n");
6619 if (!(device = create_device(d3d8, window, NULL)))
6621 skip("Failed to create a D3D device, skipping tests.\n");
6622 IDirect3D8_Release(d3d8);
6623 DestroyWindow(window);
6624 return;
6626 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
6627 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
6628 pow2 = !!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP_POW2);
6630 for (i = 0; i < ARRAY_SIZE(formats); i++)
6632 hr = IDirect3D8_CheckDeviceFormat(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
6633 0, D3DRTYPE_VOLUMETEXTURE, formats[i].fmt);
6634 support = SUCCEEDED(hr);
6636 /* Test creation restrictions */
6637 for (w = 1; w <= 8; w++)
6639 for (h = 1; h <= 8; h++)
6641 for (d = 1; d <= 8; d++)
6643 HRESULT expect_hr;
6644 BOOL size_is_pow2;
6645 BOOL block_aligned = TRUE;
6647 if (w & (formats[i].block_width - 1) || h & (formats[i].block_height - 1))
6648 block_aligned = FALSE;
6650 size_is_pow2 = !((w & (w - 1)) || (h & (h - 1)) || (d & (d - 1)));
6652 for (j = 0; j < ARRAY_SIZE(create_tests); j++)
6654 BOOL may_succeed = FALSE;
6656 if (create_tests[j].need_runtime_support && !formats[i].core_fmt && !support)
6657 expect_hr = D3DERR_INVALIDCALL;
6658 else if (formats[i].create_size_checked && !block_aligned)
6659 expect_hr = D3DERR_INVALIDCALL;
6660 else if (pow2 && !size_is_pow2 && create_tests[j].need_driver_support)
6661 expect_hr = D3DERR_INVALIDCALL;
6662 else if (create_tests[j].need_driver_support && !support)
6663 expect_hr = D3DERR_INVALIDCALL;
6664 else
6665 expect_hr = D3D_OK;
6667 texture = (IDirect3DVolumeTexture8 *)0xdeadbeef;
6668 hr = IDirect3DDevice8_CreateVolumeTexture(device, w, h, d, 1, 0,
6669 formats[i].fmt, create_tests[j].pool, &texture);
6671 /* Wine knows about ATI2N and happily creates a scratch resource even if GL
6672 * does not support it. Accept scratch creation of extension formats on
6673 * Windows as well if it occurs. We don't really care if e.g. a Windows 7
6674 * on an r200 GPU creates scratch ATI2N texture even though the card doesn't
6675 * support it. */
6676 if (!formats[i].core_fmt && !support && FAILED(expect_hr))
6677 may_succeed = TRUE;
6679 ok(hr == expect_hr || ((SUCCEEDED(hr) && may_succeed)),
6680 "Got unexpected hr %#x for format %s, pool %s, size %ux%ux%u.\n",
6681 hr, formats[i].name, create_tests[j].name, w, h, d);
6683 if (FAILED(hr))
6684 ok(texture == NULL, "Got texture ptr %p, expected NULL.\n", texture);
6685 else
6686 IDirect3DVolumeTexture8_Release(texture);
6692 if (!support && !formats[i].core_fmt)
6693 continue;
6695 hr = IDirect3DDevice8_CreateVolumeTexture(device, 24, 8, 8, 1, 0,
6696 formats[i].fmt, D3DPOOL_SCRATCH, &texture);
6697 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x.\n", hr);
6699 /* Test lockrect offset */
6700 for (j = 0; j < ARRAY_SIZE(offset_tests); j++)
6702 unsigned int bytes_per_pixel;
6703 bytes_per_pixel = formats[i].block_size / (formats[i].block_width * formats[i].block_height);
6705 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, NULL, 0);
6706 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6708 base = locked_box.pBits;
6709 if (formats[i].broken == 1)
6711 expected_row_pitch = bytes_per_pixel * 24;
6713 else if (formats[i].broken == 2)
6715 expected_row_pitch = 24;
6717 else
6719 expected_row_pitch = (24 /* tex width */ + formats[i].block_height - 1) / formats[i].block_width
6720 * formats[i].block_size;
6722 ok(locked_box.RowPitch == expected_row_pitch, "Got unexpected row pitch %d for format %s, expected %d.\n",
6723 locked_box.RowPitch, formats[i].name, expected_row_pitch);
6725 if (formats[i].broken)
6727 expected_slice_pitch = expected_row_pitch * 8;
6729 else
6731 expected_slice_pitch = (8 /* tex height */ + formats[i].block_depth - 1) / formats[i].block_height
6732 * expected_row_pitch;
6734 ok(locked_box.SlicePitch == expected_slice_pitch,
6735 "Got unexpected slice pitch %d for format %s, expected %d.\n",
6736 locked_box.SlicePitch, formats[i].name, expected_slice_pitch);
6738 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6739 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x, j %u.\n", hr, j);
6741 box.Left = offset_tests[j].x;
6742 box.Top = offset_tests[j].y;
6743 box.Front = offset_tests[j].z;
6744 box.Right = offset_tests[j].x2;
6745 box.Bottom = offset_tests[j].y2;
6746 box.Back = offset_tests[j].z2;
6747 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, &box, 0);
6748 ok(SUCCEEDED(hr), "Failed to lock volume texture, hr %#x, j %u.\n", hr, j);
6750 offset = (BYTE *)locked_box.pBits - base;
6751 if (formats[i].broken == 1)
6753 expected_offset = box.Front * expected_slice_pitch
6754 + box.Top * expected_row_pitch
6755 + box.Left * bytes_per_pixel;
6757 else if (formats[i].broken == 2)
6759 expected_offset = box.Front * expected_slice_pitch
6760 + box.Top * expected_row_pitch
6761 + box.Left;
6763 else
6765 expected_offset = (box.Front / formats[i].block_depth) * expected_slice_pitch
6766 + (box.Top / formats[i].block_height) * expected_row_pitch
6767 + (box.Left / formats[i].block_width) * formats[i].block_size;
6769 ok(offset == expected_offset, "Got unexpected offset %u for format %s, expected %u, box start %ux%ux%u.\n",
6770 offset, formats[i].name, expected_offset, box.Left, box.Top, box.Front);
6772 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6773 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6776 /* Test partial block locks */
6777 box.Front = 0;
6778 box.Back = 1;
6779 if (formats[i].block_width > 1)
6781 box.Left = formats[i].block_width >> 1;
6782 box.Top = 0;
6783 box.Right = formats[i].block_width;
6784 box.Bottom = formats[i].block_height;
6785 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, &box, 0);
6786 ok(FAILED(hr) || broken(formats[i].broken),
6787 "Partial block lock succeeded, expected failure, format %s.\n",
6788 formats[i].name);
6789 if (SUCCEEDED(hr))
6791 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6792 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6795 box.Left = 0;
6796 box.Top = 0;
6797 box.Right = formats[i].block_width >> 1;
6798 box.Bottom = formats[i].block_height;
6799 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, &box, 0);
6800 ok(FAILED(hr) || broken(formats[i].broken),
6801 "Partial block lock succeeded, expected failure, format %s.\n",
6802 formats[i].name);
6803 if (SUCCEEDED(hr))
6805 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6806 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6810 if (formats[i].block_height > 1)
6812 box.Left = 0;
6813 box.Top = formats[i].block_height >> 1;
6814 box.Right = formats[i].block_width;
6815 box.Bottom = formats[i].block_height;
6816 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, &box, 0);
6817 ok(FAILED(hr) || broken(formats[i].broken),
6818 "Partial block lock succeeded, expected failure, format %s.\n",
6819 formats[i].name);
6820 if (SUCCEEDED(hr))
6822 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6823 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6826 box.Left = 0;
6827 box.Top = 0;
6828 box.Right = formats[i].block_width;
6829 box.Bottom = formats[i].block_height >> 1;
6830 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, &box, 0);
6831 ok(FAILED(hr) || broken(formats[i].broken),
6832 "Partial block lock succeeded, expected failure, format %s.\n",
6833 formats[i].name);
6834 if (SUCCEEDED(hr))
6836 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6837 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6841 /* Test full block lock */
6842 box.Left = 0;
6843 box.Top = 0;
6844 box.Right = formats[i].block_width;
6845 box.Bottom = formats[i].block_height;
6846 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, &box, 0);
6847 ok(SUCCEEDED(hr), "Failed to lock volume texture, hr %#x.\n", hr);
6848 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6849 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6851 IDirect3DVolumeTexture8_Release(texture);
6853 /* Test mipmap locks. Don't do this with ATI2N, AMD warns that the runtime
6854 * does not allocate surfaces smaller than the blocksize properly. */
6855 if ((formats[i].block_width > 1 || formats[i].block_height > 1) && formats[i].core_fmt)
6857 hr = IDirect3DDevice8_CreateVolumeTexture(device, formats[i].block_width, formats[i].block_height,
6858 2, 2, 0, formats[i].fmt, D3DPOOL_SCRATCH, &texture);
6860 ok(SUCCEEDED(hr), "CreateVolumeTexture failed, hr %#x.\n", hr);
6861 hr = IDirect3DVolumeTexture8_LockBox(texture, 1, &locked_box, NULL, 0);
6862 ok(SUCCEEDED(hr), "Failed to lock volume texture mipmap, hr %#x.\n", hr);
6863 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 1);
6864 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6866 box.Left = box.Top = box.Front = 0;
6867 box.Right = formats[i].block_width == 1 ? 1 : formats[i].block_width >> 1;
6868 box.Bottom = formats[i].block_height == 1 ? 1 : formats[i].block_height >> 1;
6869 box.Back = 1;
6870 hr = IDirect3DVolumeTexture8_LockBox(texture, 1, &locked_box, &box, 0);
6871 ok(SUCCEEDED(hr), "Failed to lock volume texture mipmap, hr %#x.\n", hr);
6872 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 1);
6873 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6875 box.Right = formats[i].block_width;
6876 box.Bottom = formats[i].block_height;
6877 hr = IDirect3DVolumeTexture8_LockBox(texture, 1, &locked_box, &box, 0);
6878 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
6879 if (SUCCEEDED(hr))
6880 IDirect3DVolumeTexture8_UnlockBox(texture, 1);
6882 IDirect3DVolumeTexture8_Release(texture);
6886 refcount = IDirect3DDevice8_Release(device);
6887 ok(!refcount, "Device has %u references left.\n", refcount);
6888 IDirect3D8_Release(d3d8);
6889 DestroyWindow(window);
6892 static void test_lockbox_invalid(void)
6894 static const struct
6896 D3DBOX box;
6897 HRESULT result;
6899 test_data[] =
6901 {{0, 0, 2, 2, 0, 1}, D3D_OK}, /* Valid */
6902 {{0, 0, 4, 4, 0, 1}, D3D_OK}, /* Valid */
6903 {{0, 0, 0, 4, 0, 1}, D3DERR_INVALIDCALL}, /* 0 height */
6904 {{0, 0, 4, 0, 0, 1}, D3DERR_INVALIDCALL}, /* 0 width */
6905 {{0, 0, 4, 4, 1, 1}, D3DERR_INVALIDCALL}, /* 0 depth */
6906 {{4, 0, 0, 4, 0, 1}, D3DERR_INVALIDCALL}, /* left > right */
6907 {{0, 4, 4, 0, 0, 1}, D3DERR_INVALIDCALL}, /* top > bottom */
6908 {{0, 0, 4, 4, 1, 0}, D3DERR_INVALIDCALL}, /* back > front */
6909 {{0, 0, 8, 4, 0, 1}, D3DERR_INVALIDCALL}, /* right > surface */
6910 {{0, 0, 4, 8, 0, 1}, D3DERR_INVALIDCALL}, /* bottom > surface */
6911 {{0, 0, 4, 4, 0, 3}, D3DERR_INVALIDCALL}, /* back > surface */
6912 {{8, 0, 16, 4, 0, 1}, D3DERR_INVALIDCALL}, /* left > surface */
6913 {{0, 8, 4, 16, 0, 1}, D3DERR_INVALIDCALL}, /* top > surface */
6914 {{0, 0, 4, 4, 2, 4}, D3DERR_INVALIDCALL}, /* top > surface */
6916 static const D3DBOX test_boxt_2 = {2, 2, 4, 4, 0, 1};
6917 IDirect3DVolumeTexture8 *texture = NULL;
6918 D3DLOCKED_BOX locked_box;
6919 IDirect3DDevice8 *device;
6920 IDirect3D8 *d3d;
6921 unsigned int i;
6922 ULONG refcount;
6923 HWND window;
6924 BYTE *base;
6925 HRESULT hr;
6927 window = create_window();
6928 d3d = Direct3DCreate8(D3D_SDK_VERSION);
6929 ok(!!d3d, "Failed to create a D3D object.\n");
6930 if (!(device = create_device(d3d, window, NULL)))
6932 skip("Failed to create a D3D device, skipping tests.\n");
6933 IDirect3D8_Release(d3d);
6934 DestroyWindow(window);
6935 return;
6938 hr = IDirect3DDevice8_CreateVolumeTexture(device, 4, 4, 2, 1, 0,
6939 D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &texture);
6940 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x.\n", hr);
6941 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, NULL, 0);
6942 ok(SUCCEEDED(hr), "Failed to lock volume texture, hr %#x.\n", hr);
6943 base = locked_box.pBits;
6944 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6945 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6947 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
6949 unsigned int offset, expected_offset;
6950 const D3DBOX *box = &test_data[i].box;
6952 locked_box.pBits = (BYTE *)0xdeadbeef;
6953 locked_box.RowPitch = 0xdeadbeef;
6954 locked_box.SlicePitch = 0xdeadbeef;
6956 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, box, 0);
6957 /* Unlike surfaces, volumes properly check the box even in Windows XP */
6958 ok(hr == test_data[i].result,
6959 "Got unexpected hr %#x with box [%u, %u, %u]->[%u, %u, %u], expected %#x.\n",
6960 hr, box->Left, box->Top, box->Front, box->Right, box->Bottom, box->Back,
6961 test_data[i].result);
6962 if (FAILED(hr))
6963 continue;
6965 offset = (BYTE *)locked_box.pBits - base;
6966 expected_offset = box->Front * locked_box.SlicePitch + box->Top * locked_box.RowPitch + box->Left * 4;
6967 ok(offset == expected_offset,
6968 "Got unexpected offset %u (expected %u) for rect [%u, %u, %u]->[%u, %u, %u].\n",
6969 offset, expected_offset, box->Left, box->Top, box->Front, box->Right, box->Bottom, box->Back);
6971 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6972 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6975 /* locked_box = NULL throws an exception on Windows */
6976 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, NULL, 0);
6977 ok(SUCCEEDED(hr), "Failed to lock volume texture, hr %#x.\n", hr);
6978 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, NULL, 0);
6979 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
6980 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6981 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6982 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6983 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
6985 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, &test_data[0].box, 0);
6986 ok(hr == D3D_OK, "Got unexpected hr %#x for rect [%u, %u, %u]->[%u, %u, %u].\n",
6987 hr, test_data[0].box.Left, test_data[0].box.Top, test_data[0].box.Front,
6988 test_data[0].box.Right, test_data[0].box.Bottom, test_data[0].box.Back);
6989 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, &test_data[0].box, 0);
6990 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for rect [%u, %u, %u]->[%u, %u, %u].\n",
6991 hr, test_data[0].box.Left, test_data[0].box.Top, test_data[0].box.Front,
6992 test_data[0].box.Right, test_data[0].box.Bottom, test_data[0].box.Back);
6993 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, &test_boxt_2, 0);
6994 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for rect [%u, %u, %u]->[%u, %u, %u].\n",
6995 hr, test_boxt_2.Left, test_boxt_2.Top, test_boxt_2.Front,
6996 test_boxt_2.Right, test_boxt_2.Bottom, test_boxt_2.Back);
6997 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6998 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
7000 IDirect3DVolumeTexture8_Release(texture);
7001 refcount = IDirect3DDevice8_Release(device);
7002 ok(!refcount, "Device has %u references left.\n", refcount);
7003 IDirect3D8_Release(d3d);
7004 DestroyWindow(window);
7007 static void test_pixel_format(void)
7009 int format, test_format;
7010 PIXELFORMATDESCRIPTOR pfd;
7011 IDirect3D8 *d3d8 = NULL;
7012 IDirect3DDevice8 *device = NULL;
7013 HWND hwnd, hwnd2;
7014 HDC hdc, hdc2;
7015 HMODULE gl;
7016 HRESULT hr;
7018 static const float point[] = {0.0f, 0.0f, 0.0f};
7020 hwnd = create_window();
7021 ok(!!hwnd, "Failed to create window.\n");
7022 hwnd2 = create_window();
7023 ok(!!hwnd2, "Failed to create window.\n");
7025 hdc = GetDC(hwnd);
7026 ok(!!hdc, "Failed to get DC.\n");
7027 hdc2 = GetDC(hwnd2);
7028 ok(!!hdc2, "Failed to get DC.\n");
7030 gl = LoadLibraryA("opengl32.dll");
7031 ok(!!gl, "failed to load opengl32.dll; SetPixelFormat()/GetPixelFormat() may not work right\n");
7033 format = GetPixelFormat(hdc);
7034 ok(format == 0, "new window has pixel format %d\n", format);
7036 ZeroMemory(&pfd, sizeof(pfd));
7037 pfd.nSize = sizeof(pfd);
7038 pfd.nVersion = 1;
7039 pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
7040 pfd.iPixelType = PFD_TYPE_RGBA;
7041 pfd.iLayerType = PFD_MAIN_PLANE;
7042 format = ChoosePixelFormat(hdc, &pfd);
7043 if (format <= 0)
7045 skip("no pixel format available\n");
7046 goto cleanup;
7049 if (!SetPixelFormat(hdc, format, &pfd) || GetPixelFormat(hdc) != format)
7051 skip("failed to set pixel format\n");
7052 goto cleanup;
7055 if (!SetPixelFormat(hdc2, format, &pfd) || GetPixelFormat(hdc2) != format)
7057 skip("failed to set pixel format on second window\n");
7058 goto cleanup;
7061 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
7062 ok(!!d3d8, "Failed to create a D3D object.\n");
7064 test_format = GetPixelFormat(hdc);
7065 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7067 if (!(device = create_device(d3d8, hwnd, NULL)))
7069 skip("Failed to create device\n");
7070 goto cleanup;
7073 test_format = GetPixelFormat(hdc);
7074 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7076 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ);
7077 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
7079 test_format = GetPixelFormat(hdc);
7080 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7082 hr = IDirect3DDevice8_BeginScene(device);
7083 ok(SUCCEEDED(hr), "BeginScene failed %#x\n", hr);
7085 test_format = GetPixelFormat(hdc);
7086 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7088 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_POINTLIST, 1, point, 3 * sizeof(float));
7089 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
7091 test_format = GetPixelFormat(hdc);
7092 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7094 hr = IDirect3DDevice8_EndScene(device);
7095 ok(SUCCEEDED(hr), "EndScene failed %#x\n", hr);
7097 test_format = GetPixelFormat(hdc);
7098 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7100 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
7101 ok(SUCCEEDED(hr), "Present failed %#x\n", hr);
7103 test_format = GetPixelFormat(hdc);
7104 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7106 hr = IDirect3DDevice8_Present(device, NULL, NULL, hwnd2, NULL);
7107 ok(SUCCEEDED(hr), "Present failed %#x\n", hr);
7109 test_format = GetPixelFormat(hdc);
7110 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
7112 test_format = GetPixelFormat(hdc2);
7113 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
7115 cleanup:
7116 if (device)
7118 UINT refcount = IDirect3DDevice8_Release(device);
7119 ok(!refcount, "Device has %u references left.\n", refcount);
7121 if (d3d8)
7122 IDirect3D8_Release(d3d8);
7123 FreeLibrary(gl);
7124 ReleaseDC(hwnd2, hdc2);
7125 ReleaseDC(hwnd, hdc);
7126 DestroyWindow(hwnd2);
7127 DestroyWindow(hwnd);
7130 static void test_begin_end_state_block(void)
7132 IDirect3DDevice8 *device;
7133 DWORD stateblock;
7134 IDirect3D8 *d3d;
7135 ULONG refcount;
7136 HWND window;
7137 HRESULT hr;
7139 window = create_window();
7140 d3d = Direct3DCreate8(D3D_SDK_VERSION);
7141 ok(!!d3d, "Failed to create a D3D object.\n");
7142 if (!(device = create_device(d3d, window, NULL)))
7144 skip("Failed to create a D3D device, skipping tests.\n");
7145 IDirect3D8_Release(d3d);
7146 DestroyWindow(window);
7147 return;
7150 /* Should succeed. */
7151 hr = IDirect3DDevice8_BeginStateBlock(device);
7152 ok(SUCCEEDED(hr), "Failed to begin stateblock, hr %#x.\n", hr);
7154 /* Calling BeginStateBlock() while recording should return
7155 * D3DERR_INVALIDCALL. */
7156 hr = IDirect3DDevice8_BeginStateBlock(device);
7157 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
7159 /* Should succeed. */
7160 stateblock = 0xdeadbeef;
7161 hr = IDirect3DDevice8_EndStateBlock(device, &stateblock);
7162 ok(SUCCEEDED(hr), "Failed to end stateblock, hr %#x.\n", hr);
7163 ok(!!stateblock && stateblock != 0xdeadbeef, "Got unexpected stateblock %#x.\n", stateblock);
7164 IDirect3DDevice8_DeleteStateBlock(device, stateblock);
7166 /* Calling EndStateBlock() while not recording should return
7167 * D3DERR_INVALIDCALL. stateblock should not be touched. */
7168 stateblock = 0xdeadbeef;
7169 hr = IDirect3DDevice8_EndStateBlock(device, &stateblock);
7170 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
7171 ok(stateblock == 0xdeadbeef, "Got unexpected stateblock %#x.\n", stateblock);
7173 refcount = IDirect3DDevice8_Release(device);
7174 ok(!refcount, "Device has %u references left.\n", refcount);
7175 IDirect3D8_Release(d3d);
7176 DestroyWindow(window);
7179 static void test_shader_constant_apply(void)
7181 static const float vs_const[] = {1.0f, 2.0f, 3.0f, 4.0f};
7182 static const float ps_const[] = {5.0f, 6.0f, 7.0f, 8.0f};
7183 static const float initial[] = {0.0f, 0.0f, 0.0f, 0.0f};
7184 DWORD vs_version, ps_version;
7185 IDirect3DDevice8 *device;
7186 DWORD stateblock;
7187 IDirect3D8 *d3d;
7188 ULONG refcount;
7189 D3DCAPS8 caps;
7190 float ret[4];
7191 HWND window;
7192 HRESULT hr;
7194 window = create_window();
7195 d3d = Direct3DCreate8(D3D_SDK_VERSION);
7196 ok(!!d3d, "Failed to create a D3D object.\n");
7197 if (!(device = create_device(d3d, window, NULL)))
7199 skip("Failed to create a D3D device, skipping tests.\n");
7200 IDirect3D8_Release(d3d);
7201 DestroyWindow(window);
7202 return;
7205 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
7206 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
7207 vs_version = caps.VertexShaderVersion & 0xffff;
7208 ps_version = caps.PixelShaderVersion & 0xffff;
7210 if (vs_version)
7212 hr = IDirect3DDevice8_SetVertexShaderConstant(device, 0, initial, 1);
7213 ok(SUCCEEDED(hr), "Failed to set vertex shader constant, hr %#x.\n", hr);
7214 hr = IDirect3DDevice8_SetVertexShaderConstant(device, 1, initial, 1);
7215 ok(SUCCEEDED(hr), "Failed to set vertex shader constant, hr %#x.\n", hr);
7217 hr = IDirect3DDevice8_GetVertexShaderConstant(device, 0, ret, 1);
7218 ok(SUCCEEDED(hr), "Failed to get vertex shader constant, hr %#x.\n", hr);
7219 ok(!memcmp(ret, initial, sizeof(initial)),
7220 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7221 ret[0], ret[1], ret[2], ret[3], initial[0], initial[1], initial[2], initial[3]);
7222 hr = IDirect3DDevice8_GetVertexShaderConstant(device, 1, ret, 1);
7223 ok(SUCCEEDED(hr), "Failed to get vertex shader constant, hr %#x.\n", hr);
7224 ok(!memcmp(ret, initial, sizeof(initial)),
7225 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7226 ret[0], ret[1], ret[2], ret[3], initial[0], initial[1], initial[2], initial[3]);
7228 hr = IDirect3DDevice8_SetVertexShaderConstant(device, 0, vs_const, 1);
7229 ok(SUCCEEDED(hr), "Failed to set vertex shader constant, hr %#x.\n", hr);
7231 if (ps_version)
7233 hr = IDirect3DDevice8_SetPixelShaderConstant(device, 0, initial, 1);
7234 ok(SUCCEEDED(hr), "Failed to set pixel shader constant, hr %#x.\n", hr);
7235 hr = IDirect3DDevice8_SetPixelShaderConstant(device, 1, initial, 1);
7236 ok(SUCCEEDED(hr), "Failed to set pixel shader constant, hr %#x.\n", hr);
7238 hr = IDirect3DDevice8_GetPixelShaderConstant(device, 0, ret, 1);
7239 ok(SUCCEEDED(hr), "Failed to get pixel shader constant, hr %#x.\n", hr);
7240 ok(!memcmp(ret, initial, sizeof(initial)),
7241 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7242 ret[0], ret[1], ret[2], ret[3], initial[0], initial[1], initial[2], initial[3]);
7243 hr = IDirect3DDevice8_GetPixelShaderConstant(device, 1, ret, 1);
7244 ok(SUCCEEDED(hr), "Failed to get pixel shader constant, hr %#x.\n", hr);
7245 ok(!memcmp(ret, initial, sizeof(initial)),
7246 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7247 ret[0], ret[1], ret[2], ret[3], initial[0], initial[1], initial[2], initial[3]);
7249 hr = IDirect3DDevice8_SetPixelShaderConstant(device, 0, ps_const, 1);
7250 ok(SUCCEEDED(hr), "Failed to set pixel shader constant, hr %#x.\n", hr);
7253 hr = IDirect3DDevice8_BeginStateBlock(device);
7254 ok(SUCCEEDED(hr), "Failed to begin stateblock, hr %#x.\n", hr);
7256 if (vs_version)
7258 hr = IDirect3DDevice8_SetVertexShaderConstant(device, 1, vs_const, 1);
7259 ok(SUCCEEDED(hr), "Failed to set vertex shader constant, hr %#x.\n", hr);
7261 if (ps_version)
7263 hr = IDirect3DDevice8_SetPixelShaderConstant(device, 1, ps_const, 1);
7264 ok(SUCCEEDED(hr), "Failed to set pixel shader constant, hr %#x.\n", hr);
7267 hr = IDirect3DDevice8_EndStateBlock(device, &stateblock);
7268 ok(SUCCEEDED(hr), "Failed to end stateblock, hr %#x.\n", hr);
7270 if (vs_version)
7272 hr = IDirect3DDevice8_GetVertexShaderConstant(device, 0, ret, 1);
7273 ok(SUCCEEDED(hr), "Failed to get vertex shader constant, hr %#x.\n", hr);
7274 ok(!memcmp(ret, vs_const, sizeof(vs_const)),
7275 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7276 ret[0], ret[1], ret[2], ret[3], vs_const[0], vs_const[1], vs_const[2], vs_const[3]);
7277 hr = IDirect3DDevice8_GetVertexShaderConstant(device, 1, ret, 1);
7278 ok(SUCCEEDED(hr), "Failed to get vertex shader constant, hr %#x.\n", hr);
7279 ok(!memcmp(ret, initial, sizeof(initial)),
7280 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7281 ret[0], ret[1], ret[2], ret[3], initial[0], initial[1], initial[2], initial[3]);
7283 if (ps_version)
7285 hr = IDirect3DDevice8_GetPixelShaderConstant(device, 0, ret, 1);
7286 ok(SUCCEEDED(hr), "Failed to get pixel shader constant, hr %#x.\n", hr);
7287 ok(!memcmp(ret, ps_const, sizeof(ps_const)),
7288 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7289 ret[0], ret[1], ret[2], ret[3], ps_const[0], ps_const[1], ps_const[2], ps_const[3]);
7290 hr = IDirect3DDevice8_GetPixelShaderConstant(device, 1, ret, 1);
7291 ok(SUCCEEDED(hr), "Failed to get pixel shader constant, hr %#x.\n", hr);
7292 ok(!memcmp(ret, initial, sizeof(initial)),
7293 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7294 ret[0], ret[1], ret[2], ret[3], initial[0], initial[1], initial[2], initial[3]);
7297 /* Apply doesn't overwrite constants that aren't explicitly set on the
7298 * source stateblock. */
7299 hr = IDirect3DDevice8_ApplyStateBlock(device, stateblock);
7300 ok(SUCCEEDED(hr), "Failed to apply stateblock, hr %#x.\n", hr);
7302 if (vs_version)
7304 hr = IDirect3DDevice8_GetVertexShaderConstant(device, 0, ret, 1);
7305 ok(SUCCEEDED(hr), "Failed to get vertex shader constant, hr %#x.\n", hr);
7306 ok(!memcmp(ret, vs_const, sizeof(vs_const)),
7307 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7308 ret[0], ret[1], ret[2], ret[3], vs_const[0], vs_const[1], vs_const[2], vs_const[3]);
7309 hr = IDirect3DDevice8_GetVertexShaderConstant(device, 1, ret, 1);
7310 ok(SUCCEEDED(hr), "Failed to get vertex shader constant, hr %#x.\n", hr);
7311 ok(!memcmp(ret, vs_const, sizeof(vs_const)),
7312 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7313 ret[0], ret[1], ret[2], ret[3], vs_const[0], vs_const[1], vs_const[2], vs_const[3]);
7315 if (ps_version)
7317 hr = IDirect3DDevice8_GetPixelShaderConstant(device, 0, ret, 1);
7318 ok(SUCCEEDED(hr), "Failed to get pixel shader constant, hr %#x.\n", hr);
7319 ok(!memcmp(ret, ps_const, sizeof(ps_const)),
7320 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7321 ret[0], ret[1], ret[2], ret[3], ps_const[0], ps_const[1], ps_const[2], ps_const[3]);
7322 hr = IDirect3DDevice8_GetPixelShaderConstant(device, 1, ret, 1);
7323 ok(SUCCEEDED(hr), "Failed to get pixel shader constant, hr %#x.\n", hr);
7324 ok(!memcmp(ret, ps_const, sizeof(ps_const)),
7325 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7326 ret[0], ret[1], ret[2], ret[3], ps_const[0], ps_const[1], ps_const[2], ps_const[3]);
7329 IDirect3DDevice8_DeleteStateBlock(device, stateblock);
7330 refcount = IDirect3DDevice8_Release(device);
7331 ok(!refcount, "Device has %u references left.\n", refcount);
7332 IDirect3D8_Release(d3d);
7333 DestroyWindow(window);
7336 static void test_resource_type(void)
7338 IDirect3DDevice8 *device;
7339 IDirect3DSurface8 *surface;
7340 IDirect3DTexture8 *texture;
7341 IDirect3DCubeTexture8 *cube_texture;
7342 IDirect3DVolume8 *volume;
7343 IDirect3DVolumeTexture8 *volume_texture;
7344 D3DSURFACE_DESC surface_desc;
7345 D3DVOLUME_DESC volume_desc;
7346 D3DRESOURCETYPE type;
7347 IDirect3D8 *d3d;
7348 ULONG refcount;
7349 HWND window;
7350 HRESULT hr;
7351 D3DCAPS8 caps;
7353 window = create_window();
7354 d3d = Direct3DCreate8(D3D_SDK_VERSION);
7355 ok(!!d3d, "Failed to create a D3D object.\n");
7356 if (!(device = create_device(d3d, window, NULL)))
7358 skip("Failed to create a D3D device, skipping tests.\n");
7359 IDirect3D8_Release(d3d);
7360 DestroyWindow(window);
7361 return;
7364 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
7365 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
7367 hr = IDirect3DDevice8_CreateImageSurface(device, 4, 4, D3DFMT_X8R8G8B8, &surface);
7368 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7369 hr = IDirect3DSurface8_GetDesc(surface, &surface_desc);
7370 ok(SUCCEEDED(hr), "Failed to get surface description, hr %#x.\n", hr);
7371 ok(surface_desc.Type == D3DRTYPE_SURFACE, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7372 surface_desc.Type);
7373 IDirect3DSurface8_Release(surface);
7375 hr = IDirect3DDevice8_CreateTexture(device, 2, 8, 4, 0, D3DFMT_X8R8G8B8,
7376 D3DPOOL_SYSTEMMEM, &texture);
7377 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7378 type = IDirect3DTexture8_GetType(texture);
7379 ok(type == D3DRTYPE_TEXTURE, "Expected type D3DRTYPE_TEXTURE, got %u.\n", type);
7381 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 0, &surface);
7382 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
7383 hr = IDirect3DSurface8_GetDesc(surface, &surface_desc);
7384 ok(SUCCEEDED(hr), "Failed to get surface description, hr %#x.\n", hr);
7385 ok(surface_desc.Type == D3DRTYPE_SURFACE, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7386 surface_desc.Type);
7387 ok(surface_desc.Width == 2, "Expected width 2, got %u.\n", surface_desc.Width);
7388 ok(surface_desc.Height == 8, "Expected height 8, got %u.\n", surface_desc.Height);
7389 hr = IDirect3DTexture8_GetLevelDesc(texture, 0, &surface_desc);
7390 ok(SUCCEEDED(hr), "Failed to get level description, hr %#x.\n", hr);
7391 ok(surface_desc.Type == D3DRTYPE_SURFACE, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7392 surface_desc.Type);
7393 ok(surface_desc.Width == 2, "Expected width 2, got %u.\n", surface_desc.Width);
7394 ok(surface_desc.Height == 8, "Expected height 8, got %u.\n", surface_desc.Height);
7395 IDirect3DSurface8_Release(surface);
7397 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 2, &surface);
7398 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
7399 hr = IDirect3DSurface8_GetDesc(surface, &surface_desc);
7400 ok(SUCCEEDED(hr), "Failed to get surface description, hr %#x.\n", hr);
7401 ok(surface_desc.Type == D3DRTYPE_SURFACE, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7402 surface_desc.Type);
7403 ok(surface_desc.Width == 1, "Expected width 1, got %u.\n", surface_desc.Width);
7404 ok(surface_desc.Height == 2, "Expected height 2, got %u.\n", surface_desc.Height);
7405 hr = IDirect3DTexture8_GetLevelDesc(texture, 2, &surface_desc);
7406 ok(SUCCEEDED(hr), "Failed to get level description, hr %#x.\n", hr);
7407 ok(surface_desc.Type == D3DRTYPE_SURFACE, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7408 surface_desc.Type);
7409 ok(surface_desc.Width == 1, "Expected width 1, got %u.\n", surface_desc.Width);
7410 ok(surface_desc.Height == 2, "Expected height 2, got %u.\n", surface_desc.Height);
7411 IDirect3DSurface8_Release(surface);
7412 IDirect3DTexture8_Release(texture);
7414 if (caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP)
7416 hr = IDirect3DDevice8_CreateCubeTexture(device, 1, 1, 0, D3DFMT_X8R8G8B8,
7417 D3DPOOL_SYSTEMMEM, &cube_texture);
7418 ok(SUCCEEDED(hr), "Failed to create cube texture, hr %#x.\n", hr);
7419 type = IDirect3DCubeTexture8_GetType(cube_texture);
7420 ok(type == D3DRTYPE_CUBETEXTURE, "Expected type D3DRTYPE_CUBETEXTURE, got %u.\n", type);
7422 hr = IDirect3DCubeTexture8_GetCubeMapSurface(cube_texture,
7423 D3DCUBEMAP_FACE_NEGATIVE_X, 0, &surface);
7424 ok(SUCCEEDED(hr), "Failed to get cube map surface, hr %#x.\n", hr);
7425 hr = IDirect3DSurface8_GetDesc(surface, &surface_desc);
7426 ok(SUCCEEDED(hr), "Failed to get surface description, hr %#x.\n", hr);
7427 ok(surface_desc.Type == D3DRTYPE_SURFACE, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7428 surface_desc.Type);
7429 hr = IDirect3DCubeTexture8_GetLevelDesc(cube_texture, 0, &surface_desc);
7430 ok(SUCCEEDED(hr), "Failed to get level description, hr %#x.\n", hr);
7431 ok(surface_desc.Type == D3DRTYPE_SURFACE, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7432 surface_desc.Type);
7433 IDirect3DSurface8_Release(surface);
7434 IDirect3DCubeTexture8_Release(cube_texture);
7436 else
7437 skip("Cube maps not supported.\n");
7439 if (caps.TextureCaps & D3DPTEXTURECAPS_MIPVOLUMEMAP)
7441 hr = IDirect3DDevice8_CreateVolumeTexture(device, 2, 4, 8, 4, 0, D3DFMT_X8R8G8B8,
7442 D3DPOOL_SYSTEMMEM, &volume_texture);
7443 ok(SUCCEEDED(hr), "CreateVolumeTexture failed, hr %#x.\n", hr);
7444 type = IDirect3DVolumeTexture8_GetType(volume_texture);
7445 ok(type == D3DRTYPE_VOLUMETEXTURE, "Expected type D3DRTYPE_VOLUMETEXTURE, got %u.\n", type);
7447 hr = IDirect3DVolumeTexture8_GetVolumeLevel(volume_texture, 0, &volume);
7448 ok(SUCCEEDED(hr), "Failed to get volume level, hr %#x.\n", hr);
7449 /* IDirect3DVolume8 is not an IDirect3DResource8 and has no GetType method. */
7450 hr = IDirect3DVolume8_GetDesc(volume, &volume_desc);
7451 ok(SUCCEEDED(hr), "Failed to get volume description, hr %#x.\n", hr);
7452 ok(volume_desc.Type == D3DRTYPE_VOLUME, "Expected type D3DRTYPE_VOLUME, got %u.\n",
7453 volume_desc.Type);
7454 ok(volume_desc.Width == 2, "Expected width 2, got %u.\n", volume_desc.Width);
7455 ok(volume_desc.Height == 4, "Expected height 4, got %u.\n", volume_desc.Height);
7456 ok(volume_desc.Depth == 8, "Expected depth 8, got %u.\n", volume_desc.Depth);
7457 hr = IDirect3DVolumeTexture8_GetLevelDesc(volume_texture, 0, &volume_desc);
7458 ok(SUCCEEDED(hr), "Failed to get level description, hr %#x.\n", hr);
7459 ok(volume_desc.Type == D3DRTYPE_VOLUME, "Expected type D3DRTYPE_VOLUME, got %u.\n",
7460 volume_desc.Type);
7461 ok(volume_desc.Width == 2, "Expected width 2, got %u.\n", volume_desc.Width);
7462 ok(volume_desc.Height == 4, "Expected height 4, got %u.\n", volume_desc.Height);
7463 ok(volume_desc.Depth == 8, "Expected depth 8, got %u.\n", volume_desc.Depth);
7464 IDirect3DVolume8_Release(volume);
7466 hr = IDirect3DVolumeTexture8_GetVolumeLevel(volume_texture, 2, &volume);
7467 ok(SUCCEEDED(hr), "Failed to get volume level, hr %#x.\n", hr);
7468 hr = IDirect3DVolume8_GetDesc(volume, &volume_desc);
7469 ok(SUCCEEDED(hr), "Failed to get volume description, hr %#x.\n", hr);
7470 ok(volume_desc.Type == D3DRTYPE_VOLUME, "Expected type D3DRTYPE_VOLUME, got %u.\n",
7471 volume_desc.Type);
7472 ok(volume_desc.Width == 1, "Expected width 1, got %u.\n", volume_desc.Width);
7473 ok(volume_desc.Height == 1, "Expected height 1, got %u.\n", volume_desc.Height);
7474 ok(volume_desc.Depth == 2, "Expected depth 2, got %u.\n", volume_desc.Depth);
7475 hr = IDirect3DVolumeTexture8_GetLevelDesc(volume_texture, 2, &volume_desc);
7476 ok(SUCCEEDED(hr), "Failed to get level description, hr %#x.\n", hr);
7477 ok(volume_desc.Type == D3DRTYPE_VOLUME, "Expected type D3DRTYPE_VOLUME, got %u.\n",
7478 volume_desc.Type);
7479 ok(volume_desc.Width == 1, "Expected width 1, got %u.\n", volume_desc.Width);
7480 ok(volume_desc.Height == 1, "Expected height 1, got %u.\n", volume_desc.Height);
7481 ok(volume_desc.Depth == 2, "Expected depth 2, got %u.\n", volume_desc.Depth);
7482 IDirect3DVolume8_Release(volume);
7483 IDirect3DVolumeTexture8_Release(volume_texture);
7485 else
7486 skip("Mipmapped volume maps not supported.\n");
7488 refcount = IDirect3DDevice8_Release(device);
7489 ok(!refcount, "Device has %u references left.\n", refcount);
7490 IDirect3D8_Release(d3d);
7491 DestroyWindow(window);
7494 static void test_mipmap_lock(void)
7496 IDirect3DDevice8 *device;
7497 IDirect3DSurface8 *surface, *surface2, *surface_dst, *surface_dst2;
7498 IDirect3DTexture8 *texture, *texture_dst;
7499 IDirect3D8 *d3d;
7500 ULONG refcount;
7501 HWND window;
7502 HRESULT hr;
7503 D3DLOCKED_RECT locked_rect;
7505 window = create_window();
7506 d3d = Direct3DCreate8(D3D_SDK_VERSION);
7507 ok(!!d3d, "Failed to create a D3D object.\n");
7508 if (!(device = create_device(d3d, window, NULL)))
7510 skip("Failed to create a D3D device, skipping tests.\n");
7511 IDirect3D8_Release(d3d);
7512 DestroyWindow(window);
7513 return;
7516 hr = IDirect3DDevice8_CreateTexture(device, 4, 4, 2, 0, D3DFMT_X8R8G8B8,
7517 D3DPOOL_DEFAULT, &texture_dst);
7518 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7519 hr = IDirect3DTexture8_GetSurfaceLevel(texture_dst, 0, &surface_dst);
7520 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
7521 hr = IDirect3DTexture8_GetSurfaceLevel(texture_dst, 1, &surface_dst2);
7522 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
7524 hr = IDirect3DDevice8_CreateTexture(device, 4, 4, 2, 0, D3DFMT_X8R8G8B8,
7525 D3DPOOL_SYSTEMMEM, &texture);
7526 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7527 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 0, &surface);
7528 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
7529 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 1, &surface2);
7530 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
7532 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, NULL, 0);
7533 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
7534 hr = IDirect3DSurface8_LockRect(surface2, &locked_rect, NULL, 0);
7535 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
7536 hr = IDirect3DSurface8_UnlockRect(surface);
7537 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
7539 hr = IDirect3DDevice8_CopyRects(device, surface, NULL, 0, surface_dst, NULL);
7540 ok(SUCCEEDED(hr), "Failed to update surface, hr %#x.\n", hr);
7541 hr = IDirect3DDevice8_CopyRects(device, surface2, NULL, 0, surface_dst2, NULL);
7542 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
7544 /* Apparently there's no validation on the container. */
7545 hr = IDirect3DDevice8_UpdateTexture(device, (IDirect3DBaseTexture8 *)texture,
7546 (IDirect3DBaseTexture8 *)texture_dst);
7547 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x.\n", hr);
7549 hr = IDirect3DSurface8_UnlockRect(surface2);
7550 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
7552 IDirect3DSurface8_Release(surface_dst2);
7553 IDirect3DSurface8_Release(surface_dst);
7554 IDirect3DSurface8_Release(surface2);
7555 IDirect3DSurface8_Release(surface);
7556 IDirect3DTexture8_Release(texture_dst);
7557 IDirect3DTexture8_Release(texture);
7559 refcount = IDirect3DDevice8_Release(device);
7560 ok(!refcount, "Device has %u references left.\n", refcount);
7561 IDirect3D8_Release(d3d);
7562 DestroyWindow(window);
7565 static void test_writeonly_resource(void)
7567 IDirect3D8 *d3d;
7568 IDirect3DDevice8 *device;
7569 IDirect3DVertexBuffer8 *buffer;
7570 ULONG refcount;
7571 HWND window;
7572 HRESULT hr;
7573 BYTE *ptr;
7574 static const struct
7576 struct vec3 pos;
7578 quad[] =
7580 {{-1.0f, -1.0f, 0.0f}},
7581 {{-1.0f, 1.0f, 0.0f}},
7582 {{ 1.0f, -1.0f, 0.0f}},
7583 {{ 1.0f, 1.0f, 0.0f}}
7586 window = create_window();
7587 d3d = Direct3DCreate8(D3D_SDK_VERSION);
7588 ok(!!d3d, "Failed to create a D3D object.\n");
7589 if (!(device = create_device(d3d, window, NULL)))
7591 skip("Failed to create a D3D device, skipping tests.\n");
7592 IDirect3D8_Release(d3d);
7593 DestroyWindow(window);
7594 return;
7597 hr = IDirect3DDevice8_CreateVertexBuffer(device, sizeof(quad),
7598 D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &buffer);
7599 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
7601 hr = IDirect3DVertexBuffer8_Lock(buffer, 0, 0, &ptr, D3DLOCK_DISCARD);
7602 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
7603 memcpy(ptr, quad, sizeof(quad));
7604 hr = IDirect3DVertexBuffer8_Unlock(buffer);
7605 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
7606 hr = IDirect3DDevice8_SetStreamSource(device, 0, buffer, sizeof(*quad));
7607 ok(SUCCEEDED(hr), "Failed to set stream source, hr %#x.\n", hr);
7608 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ);
7609 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
7611 hr = IDirect3DDevice8_BeginScene(device);
7612 ok(SUCCEEDED(hr), "Failed to begin scene %#x\n", hr);
7613 hr = IDirect3DDevice8_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, 0, 2);
7614 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
7615 hr = IDirect3DDevice8_EndScene(device);
7616 ok(SUCCEEDED(hr), "Failed to end scene %#x\n", hr);
7618 hr = IDirect3DVertexBuffer8_Lock(buffer, 0, 0, &ptr, 0);
7619 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
7620 ok (!memcmp(ptr, quad, sizeof(quad)), "Got unexpected vertex buffer data.\n");
7621 hr = IDirect3DVertexBuffer8_Unlock(buffer);
7622 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
7624 hr = IDirect3DVertexBuffer8_Lock(buffer, 0, 0, &ptr, D3DLOCK_READONLY);
7625 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
7626 ok (!memcmp(ptr, quad, sizeof(quad)), "Got unexpected vertex buffer data.\n");
7627 hr = IDirect3DVertexBuffer8_Unlock(buffer);
7628 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
7630 refcount = IDirect3DVertexBuffer8_Release(buffer);
7631 ok(!refcount, "Vertex buffer has %u references left.\n", refcount);
7632 refcount = IDirect3DDevice8_Release(device);
7633 ok(!refcount, "Device has %u references left.\n", refcount);
7634 IDirect3D8_Release(d3d);
7635 DestroyWindow(window);
7638 static void test_lost_device(void)
7640 struct device_desc device_desc;
7641 IDirect3DDevice8 *device;
7642 IDirect3D8 *d3d;
7643 ULONG refcount;
7644 HWND window;
7645 HRESULT hr;
7646 BOOL ret;
7648 window = create_window();
7649 d3d = Direct3DCreate8(D3D_SDK_VERSION);
7650 ok(!!d3d, "Failed to create a D3D object.\n");
7651 device_desc.device_window = window;
7652 device_desc.width = registry_mode.dmPelsWidth;
7653 device_desc.height = registry_mode.dmPelsHeight;
7654 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
7655 if (!(device = create_device(d3d, window, &device_desc)))
7657 skip("Failed to create a D3D device, skipping tests.\n");
7658 goto done;
7661 hr = IDirect3DDevice8_TestCooperativeLevel(device);
7662 if (hr == D3DERR_DEVICELOST)
7664 win_skip("Broken TestCooperativeLevel(), skipping test.\n");
7665 IDirect3DDevice8_Release(device);
7666 goto done;
7668 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7669 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
7670 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7672 ret = SetForegroundWindow(GetDesktopWindow());
7673 ok(ret, "Failed to set foreground window.\n");
7674 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
7675 /* The device is not lost on Windows 10. */
7676 ok(hr == D3DERR_DEVICELOST || broken(hr == D3D_OK), "Got unexpected hr %#x.\n", hr);
7677 hr = IDirect3DDevice8_TestCooperativeLevel(device);
7678 ok(hr == D3DERR_DEVICELOST || broken(hr == D3D_OK), "Got unexpected hr %#x.\n", hr);
7680 ret = ShowWindow(window, SW_RESTORE);
7681 ok(ret, "Failed to restore window.\n");
7682 ret = SetForegroundWindow(window);
7683 ok(ret, "Failed to set foreground window.\n");
7684 hr = IDirect3DDevice8_TestCooperativeLevel(device);
7685 ok(hr == D3DERR_DEVICENOTRESET || broken(hr == D3D_OK), "Got unexpected hr %#x.\n", hr);
7686 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
7687 ok(hr == D3DERR_DEVICELOST || broken(hr == D3D_OK), "Got unexpected hr %#x.\n", hr);
7689 hr = reset_device(device, &device_desc);
7690 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7691 hr = IDirect3DDevice8_TestCooperativeLevel(device);
7692 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7693 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
7694 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7696 device_desc.flags = 0;
7697 hr = reset_device(device, &device_desc);
7698 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7699 hr = IDirect3DDevice8_TestCooperativeLevel(device);
7700 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7701 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
7702 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7704 ret = SetForegroundWindow(GetDesktopWindow());
7705 ok(ret, "Failed to set foreground window.\n");
7706 hr = IDirect3DDevice8_TestCooperativeLevel(device);
7707 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7708 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
7709 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7711 ret = ShowWindow(window, SW_RESTORE);
7712 ok(ret, "Failed to restore window.\n");
7713 hr = IDirect3DDevice8_TestCooperativeLevel(device);
7714 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7715 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
7716 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7718 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
7719 hr = reset_device(device, &device_desc);
7720 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7721 hr = IDirect3DDevice8_TestCooperativeLevel(device);
7722 /* The device is not lost on Windows 10. */
7723 todo_wine ok(hr == D3DERR_DEVICELOST || broken(hr == D3D_OK), "Got unexpected hr %#x.\n", hr);
7724 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
7725 todo_wine ok(hr == D3DERR_DEVICELOST || broken(hr == D3D_OK), "Got unexpected hr %#x.\n", hr);
7727 ret = SetForegroundWindow(GetDesktopWindow());
7728 ok(ret, "Failed to set foreground window.\n");
7729 hr = reset_device(device, &device_desc);
7730 ok(hr == D3DERR_DEVICELOST || broken(hr == D3D_OK), "Got unexpected hr %#x.\n", hr);
7731 ret = ShowWindow(window, SW_RESTORE);
7732 ok(ret, "Failed to restore window.\n");
7733 ret = SetForegroundWindow(window);
7734 ok(ret, "Failed to set foreground window.\n");
7735 hr = reset_device(device, &device_desc);
7736 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7738 refcount = IDirect3DDevice8_Release(device);
7739 ok(!refcount, "Device has %u references left.\n", refcount);
7740 done:
7741 IDirect3D8_Release(d3d);
7742 DestroyWindow(window);
7745 static void test_resource_priority(void)
7747 IDirect3DDevice8 *device;
7748 IDirect3DTexture8 *texture;
7749 IDirect3DVertexBuffer8 *buffer;
7750 IDirect3D8 *d3d;
7751 ULONG refcount;
7752 HWND window;
7753 HRESULT hr;
7754 static const struct
7756 D3DPOOL pool;
7757 const char *name;
7758 BOOL can_set_priority;
7760 test_data[] =
7762 {D3DPOOL_DEFAULT, "D3DPOOL_DEFAULT", FALSE},
7763 {D3DPOOL_SYSTEMMEM, "D3DPOOL_SYSTEMMEM", FALSE},
7764 {D3DPOOL_MANAGED, "D3DPOOL_MANAGED", TRUE},
7765 {D3DPOOL_SCRATCH, "D3DPOOL_SCRATCH", FALSE}
7767 unsigned int i;
7768 DWORD priority;
7770 window = create_window();
7771 d3d = Direct3DCreate8(D3D_SDK_VERSION);
7772 ok(!!d3d, "Failed to create a D3D object.\n");
7773 if (!(device = create_device(d3d, window, NULL)))
7775 skip("Failed to create a D3D device, skipping tests.\n");
7776 IDirect3D8_Release(d3d);
7777 DestroyWindow(window);
7778 return;
7781 for (i = 0; i < ARRAY_SIZE(test_data); i++)
7783 hr = IDirect3DDevice8_CreateTexture(device, 16, 16, 0, 0, D3DFMT_X8R8G8B8,
7784 test_data[i].pool, &texture);
7785 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x, pool %s.\n", hr, test_data[i].name);
7787 priority = IDirect3DTexture8_GetPriority(texture);
7788 ok(priority == 0, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
7789 priority = IDirect3DTexture8_SetPriority(texture, 1);
7790 ok(priority == 0, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
7791 priority = IDirect3DTexture8_GetPriority(texture);
7792 if (test_data[i].can_set_priority)
7794 ok(priority == 1, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
7795 priority = IDirect3DTexture8_SetPriority(texture, 0);
7796 ok(priority == 1, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
7798 else
7799 ok(priority == 0, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
7801 IDirect3DTexture8_Release(texture);
7803 if (test_data[i].pool != D3DPOOL_SCRATCH)
7805 hr = IDirect3DDevice8_CreateVertexBuffer(device, 256, 0, 0,
7806 test_data[i].pool, &buffer);
7807 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x, pool %s.\n", hr, test_data[i].name);
7809 priority = IDirect3DVertexBuffer8_GetPriority(buffer);
7810 ok(priority == 0, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
7811 priority = IDirect3DVertexBuffer8_SetPriority(buffer, 1);
7812 ok(priority == 0, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
7813 priority = IDirect3DVertexBuffer8_GetPriority(buffer);
7814 if (test_data[i].can_set_priority)
7816 ok(priority == 1, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
7817 priority = IDirect3DVertexBuffer8_SetPriority(buffer, 0);
7818 ok(priority == 1, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
7820 else
7821 ok(priority == 0, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
7823 IDirect3DVertexBuffer8_Release(buffer);
7827 refcount = IDirect3DDevice8_Release(device);
7828 ok(!refcount, "Device has %u references left.\n", refcount);
7829 IDirect3D8_Release(d3d);
7830 DestroyWindow(window);
7833 static void test_swapchain_parameters(void)
7835 IDirect3DSurface8 *backbuffer;
7836 IDirect3DDevice8 *device;
7837 HRESULT hr, expected_hr;
7838 IDirect3D8 *d3d;
7839 D3DCAPS8 caps;
7840 HWND window;
7841 unsigned int i, j;
7842 D3DPRESENT_PARAMETERS present_parameters, present_parameters_windowed = {0};
7843 static const struct
7845 BOOL windowed;
7846 UINT backbuffer_count;
7847 D3DSWAPEFFECT swap_effect;
7848 HRESULT hr;
7850 tests[] =
7852 /* Swap effect 0 is not allowed. */
7853 {TRUE, 1, 0, D3DERR_INVALIDCALL},
7854 {FALSE, 1, 0, D3DERR_INVALIDCALL},
7856 /* All (non-ex) swap effects are allowed in
7857 * windowed and fullscreen mode. */
7858 {TRUE, 1, D3DSWAPEFFECT_DISCARD, D3D_OK},
7859 {TRUE, 1, D3DSWAPEFFECT_FLIP, D3D_OK},
7860 {FALSE, 1, D3DSWAPEFFECT_DISCARD, D3D_OK},
7861 {FALSE, 1, D3DSWAPEFFECT_FLIP, D3D_OK},
7862 {FALSE, 1, D3DSWAPEFFECT_COPY, D3D_OK},
7864 /* Only one backbuffer in copy mode. Reset allows it for
7865 * some reason. */
7866 {TRUE, 0, D3DSWAPEFFECT_COPY, D3D_OK},
7867 {TRUE, 1, D3DSWAPEFFECT_COPY, D3D_OK},
7868 {TRUE, 2, D3DSWAPEFFECT_COPY, D3DERR_INVALIDCALL},
7869 {FALSE, 2, D3DSWAPEFFECT_COPY, D3DERR_INVALIDCALL},
7870 {TRUE, 0, D3DSWAPEFFECT_COPY_VSYNC, D3D_OK},
7871 {TRUE, 1, D3DSWAPEFFECT_COPY_VSYNC, D3D_OK},
7872 {TRUE, 2, D3DSWAPEFFECT_COPY_VSYNC, D3DERR_INVALIDCALL},
7873 {FALSE, 2, D3DSWAPEFFECT_COPY_VSYNC, D3DERR_INVALIDCALL},
7875 /* Ok with the others, in fullscreen and windowed mode. */
7876 {TRUE, 2, D3DSWAPEFFECT_DISCARD, D3D_OK},
7877 {TRUE, 2, D3DSWAPEFFECT_FLIP, D3D_OK},
7878 {FALSE, 2, D3DSWAPEFFECT_DISCARD, D3D_OK},
7879 {FALSE, 2, D3DSWAPEFFECT_FLIP, D3D_OK},
7881 /* Invalid swapeffects. */
7882 {TRUE, 1, D3DSWAPEFFECT_COPY_VSYNC + 1, D3DERR_INVALIDCALL},
7883 {FALSE, 1, D3DSWAPEFFECT_COPY_VSYNC + 1, D3DERR_INVALIDCALL},
7885 /* 3 is the highest allowed backbuffer count. */
7886 {TRUE, 3, D3DSWAPEFFECT_DISCARD, D3D_OK},
7887 {TRUE, 4, D3DSWAPEFFECT_DISCARD, D3DERR_INVALIDCALL},
7888 {TRUE, 4, D3DSWAPEFFECT_FLIP, D3DERR_INVALIDCALL},
7889 {FALSE, 4, D3DSWAPEFFECT_DISCARD, D3DERR_INVALIDCALL},
7890 {FALSE, 4, D3DSWAPEFFECT_FLIP, D3DERR_INVALIDCALL},
7893 window = create_window();
7894 d3d = Direct3DCreate8(D3D_SDK_VERSION);
7895 ok(!!d3d, "Failed to create a D3D object.\n");
7896 if (!(device = create_device(d3d, window, NULL)))
7898 skip("Failed to create a D3D device, skipping tests.\n");
7899 IDirect3D8_Release(d3d);
7900 DestroyWindow(window);
7901 return;
7903 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
7904 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
7905 IDirect3DDevice8_Release(device);
7907 present_parameters_windowed.BackBufferWidth = registry_mode.dmPelsWidth;
7908 present_parameters_windowed.BackBufferHeight = registry_mode.dmPelsHeight;
7909 present_parameters_windowed.hDeviceWindow = window;
7910 present_parameters_windowed.BackBufferFormat = D3DFMT_X8R8G8B8;
7911 present_parameters_windowed.SwapEffect = D3DSWAPEFFECT_COPY;
7912 present_parameters_windowed.Windowed = TRUE;
7913 present_parameters_windowed.BackBufferCount = 1;
7915 for (i = 0; i < ARRAY_SIZE(tests); ++i)
7917 UINT bb_count = tests[i].backbuffer_count ? tests[i].backbuffer_count : 1;
7919 memset(&present_parameters, 0, sizeof(present_parameters));
7920 present_parameters.BackBufferWidth = registry_mode.dmPelsWidth;
7921 present_parameters.BackBufferHeight = registry_mode.dmPelsHeight;
7922 present_parameters.hDeviceWindow = window;
7923 present_parameters.BackBufferFormat = D3DFMT_X8R8G8B8;
7925 present_parameters.SwapEffect = tests[i].swap_effect;
7926 present_parameters.Windowed = tests[i].windowed;
7927 present_parameters.BackBufferCount = tests[i].backbuffer_count;
7929 hr = IDirect3D8_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window,
7930 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device);
7931 ok(hr == tests[i].hr, "Expected hr %x, got %x, test %u.\n", tests[i].hr, hr, i);
7932 if (SUCCEEDED(hr))
7934 for (j = 0; j < bb_count; ++j)
7936 hr = IDirect3DDevice8_GetBackBuffer(device, j, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
7937 ok(SUCCEEDED(hr), "Failed to get backbuffer %u, hr %#x, test %u.\n", j, hr, i);
7938 IDirect3DSurface8_Release(backbuffer);
7940 hr = IDirect3DDevice8_GetBackBuffer(device, j, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
7941 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %x, test %u.\n", hr, i);
7943 IDirect3DDevice8_Release(device);
7946 hr = IDirect3D8_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window,
7947 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters_windowed, &device);
7948 ok(SUCCEEDED(hr), "Failed to create device, hr %#x, test %u.\n", hr, i);
7950 memset(&present_parameters, 0, sizeof(present_parameters));
7951 present_parameters.BackBufferWidth = registry_mode.dmPelsWidth;
7952 present_parameters.BackBufferHeight = registry_mode.dmPelsHeight;
7953 present_parameters.hDeviceWindow = window;
7954 present_parameters.BackBufferFormat = D3DFMT_X8R8G8B8;
7956 present_parameters.SwapEffect = tests[i].swap_effect;
7957 present_parameters.Windowed = tests[i].windowed;
7958 present_parameters.BackBufferCount = tests[i].backbuffer_count;
7960 hr = IDirect3DDevice8_Reset(device, &present_parameters);
7961 ok(hr == tests[i].hr, "Expected hr %x, got %x, test %u.\n", tests[i].hr, hr, i);
7963 if (FAILED(hr))
7965 hr = IDirect3DDevice8_Reset(device, &present_parameters_windowed);
7966 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x, test %u.\n", hr, i);
7968 else
7970 for (j = 0; j < bb_count; ++j)
7972 hr = IDirect3DDevice8_GetBackBuffer(device, j, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
7973 todo_wine_if (j)
7974 ok(SUCCEEDED(hr), "Failed to get backbuffer %u, hr %#x, test %u.\n", j, hr, i);
7975 if (SUCCEEDED(hr))
7976 IDirect3DSurface8_Release(backbuffer);
7978 hr = IDirect3DDevice8_GetBackBuffer(device, j, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
7979 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %x, test %u.\n", hr, i);
7981 IDirect3DDevice8_Release(device);
7984 for (i = 0; i < 10; ++i)
7986 memset(&present_parameters, 0, sizeof(present_parameters));
7987 present_parameters.BackBufferWidth = registry_mode.dmPelsWidth;
7988 present_parameters.BackBufferHeight = registry_mode.dmPelsHeight;
7989 present_parameters.hDeviceWindow = window;
7990 present_parameters.BackBufferFormat = D3DFMT_X8R8G8B8;
7991 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
7992 present_parameters.Windowed = FALSE;
7993 present_parameters.BackBufferCount = 2;
7995 present_parameters.FullScreen_PresentationInterval = i;
7996 switch (present_parameters.FullScreen_PresentationInterval)
7998 case D3DPRESENT_INTERVAL_ONE:
7999 case D3DPRESENT_INTERVAL_TWO:
8000 case D3DPRESENT_INTERVAL_THREE:
8001 case D3DPRESENT_INTERVAL_FOUR:
8002 if (!(caps.PresentationIntervals & present_parameters.FullScreen_PresentationInterval))
8003 continue;
8004 /* Fall through */
8005 case D3DPRESENT_INTERVAL_DEFAULT:
8006 expected_hr = D3D_OK;
8007 break;
8008 default:
8009 expected_hr = D3DERR_INVALIDCALL;
8010 break;
8013 hr = IDirect3D8_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window,
8014 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device);
8015 ok(hr == expected_hr, "Got unexpected hr %#x, test %u.\n", hr, i);
8016 if (SUCCEEDED(hr))
8017 IDirect3DDevice8_Release(device);
8020 IDirect3D8_Release(d3d);
8021 DestroyWindow(window);
8024 static void test_check_device_format(void)
8026 D3DDEVTYPE device_type;
8027 IDirect3D8 *d3d;
8028 HRESULT hr;
8030 d3d = Direct3DCreate8(D3D_SDK_VERSION);
8031 ok(!!d3d, "Failed to create a D3D object.\n");
8033 for (device_type = D3DDEVTYPE_HAL; device_type <= D3DDEVTYPE_SW; ++device_type)
8035 hr = IDirect3D8_CheckDeviceFormat(d3d, 0, device_type, D3DFMT_UNKNOWN,
8036 0, D3DRTYPE_SURFACE, D3DFMT_A8R8G8B8);
8037 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x, device type %#x.\n", hr, device_type);
8038 hr = IDirect3D8_CheckDeviceFormat(d3d, 0, device_type, D3DFMT_UNKNOWN,
8039 0, D3DRTYPE_TEXTURE, D3DFMT_A8R8G8B8);
8040 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x, device type %#x.\n", hr, device_type);
8041 hr = IDirect3D8_CheckDeviceFormat(d3d, 0, device_type, D3DFMT_UNKNOWN,
8042 0, D3DRTYPE_SURFACE, D3DFMT_X8R8G8B8);
8043 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x, device type %#x.\n", hr, device_type);
8044 hr = IDirect3D8_CheckDeviceFormat(d3d, 0, device_type, D3DFMT_UNKNOWN,
8045 0, D3DRTYPE_TEXTURE, D3DFMT_X8R8G8B8);
8046 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x, device type %#x.\n", hr, device_type);
8049 hr = IDirect3D8_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
8050 0, D3DRTYPE_VERTEXBUFFER, D3DFMT_VERTEXDATA);
8051 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8052 hr = IDirect3D8_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
8053 0, D3DRTYPE_INDEXBUFFER, D3DFMT_VERTEXDATA);
8054 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8055 hr = IDirect3D8_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
8056 0, D3DRTYPE_INDEXBUFFER, D3DFMT_INDEX16);
8057 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8059 hr = IDirect3D8_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
8060 D3DUSAGE_SOFTWAREPROCESSING, D3DRTYPE_VERTEXBUFFER, D3DFMT_VERTEXDATA);
8061 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8062 hr = IDirect3D8_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
8063 D3DUSAGE_SOFTWAREPROCESSING, D3DRTYPE_INDEXBUFFER, D3DFMT_VERTEXDATA);
8064 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8065 hr = IDirect3D8_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
8066 D3DUSAGE_SOFTWAREPROCESSING, D3DRTYPE_INDEXBUFFER, D3DFMT_INDEX16);
8067 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8069 IDirect3D8_Release(d3d);
8072 static void test_miptree_layout(void)
8074 unsigned int pool_idx, format_idx, base_dimension, level_count, offset, i, j;
8075 IDirect3DCubeTexture8 *texture_cube;
8076 IDirect3DTexture8 *texture_2d;
8077 IDirect3DDevice8 *device;
8078 D3DLOCKED_RECT map_desc;
8079 BYTE *base = NULL;
8080 IDirect3D8 *d3d;
8081 D3DCAPS8 caps;
8082 UINT refcount;
8083 HWND window;
8084 HRESULT hr;
8086 static const struct
8088 D3DFORMAT format;
8089 const char *name;
8091 formats[] =
8093 {D3DFMT_A8R8G8B8, "D3DFMT_A8R8G8B8"},
8094 {D3DFMT_A8, "D3DFMT_A8"},
8095 {D3DFMT_L8, "D3DFMT_L8"},
8096 {MAKEFOURCC('A','T','I','1'), "D3DFMT_ATI1"},
8097 {MAKEFOURCC('A','T','I','2'), "D3DFMT_ATI2"},
8099 static const struct
8101 D3DPOOL pool;
8102 const char *name;
8104 pools[] =
8106 {D3DPOOL_MANAGED, "D3DPOOL_MANAGED"},
8107 {D3DPOOL_SYSTEMMEM, "D3DPOOL_SYSTEMMEM"},
8108 {D3DPOOL_SCRATCH, "D3DPOOL_SCRATCH"},
8111 window = create_window();
8112 d3d = Direct3DCreate8(D3D_SDK_VERSION);
8113 ok(!!d3d, "Failed to create a D3D object.\n");
8114 if (!(device = create_device(d3d, window, NULL)))
8116 skip("Failed to create a D3D device, skipping tests.\n");
8117 goto done;
8120 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
8121 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
8123 base_dimension = 257;
8124 if (caps.TextureCaps & (D3DPTEXTURECAPS_POW2 | D3DPTEXTURECAPS_CUBEMAP_POW2))
8126 skip("Using power of two base dimension.\n");
8127 base_dimension = 256;
8130 for (format_idx = 0; format_idx < ARRAY_SIZE(formats); ++format_idx)
8132 if (FAILED(hr = IDirect3D8_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
8133 D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, formats[format_idx].format)))
8135 skip("%s textures not supported, skipping tests.\n", formats[format_idx].name);
8136 continue;
8139 for (pool_idx = 0; pool_idx < ARRAY_SIZE(pools); ++pool_idx)
8141 hr = IDirect3DDevice8_CreateTexture(device, base_dimension, base_dimension, 0, 0,
8142 formats[format_idx].format, pools[pool_idx].pool, &texture_2d);
8143 ok(SUCCEEDED(hr), "Failed to create a %s %s texture, hr %#x.\n",
8144 pools[pool_idx].name, formats[format_idx].name, hr);
8146 level_count = IDirect3DTexture8_GetLevelCount(texture_2d);
8147 for (i = 0, offset = 0; i < level_count; ++i)
8149 hr = IDirect3DTexture8_LockRect(texture_2d, i, &map_desc, NULL, 0);
8150 ok(SUCCEEDED(hr), "%s, %s: Failed to lock level %u, hr %#x.\n",
8151 pools[pool_idx].name, formats[format_idx].name, i, hr);
8153 if (!i)
8154 base = map_desc.pBits;
8155 else
8156 ok(map_desc.pBits == base + offset,
8157 "%s, %s, level %u: Got unexpected pBits %p, expected %p.\n",
8158 pools[pool_idx].name, formats[format_idx].name, i, map_desc.pBits, base + offset);
8159 offset += (base_dimension >> i) * map_desc.Pitch;
8161 hr = IDirect3DTexture8_UnlockRect(texture_2d, i);
8162 ok(SUCCEEDED(hr), "%s, %s Failed to unlock level %u, hr %#x.\n",
8163 pools[pool_idx].name, formats[format_idx].name, i, hr);
8166 IDirect3DTexture8_Release(texture_2d);
8169 if (FAILED(hr = IDirect3D8_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
8170 D3DFMT_X8R8G8B8, 0, D3DRTYPE_CUBETEXTURE, formats[format_idx].format)))
8172 skip("%s cube textures not supported, skipping tests.\n", formats[format_idx].name);
8173 continue;
8176 for (pool_idx = 0; pool_idx < ARRAY_SIZE(pools); ++pool_idx)
8178 hr = IDirect3DDevice8_CreateCubeTexture(device, base_dimension, 0, 0,
8179 formats[format_idx].format, pools[pool_idx].pool, &texture_cube);
8180 ok(SUCCEEDED(hr), "Failed to create a %s %s cube texture, hr %#x.\n",
8181 pools[pool_idx].name, formats[format_idx].name, hr);
8183 level_count = IDirect3DCubeTexture8_GetLevelCount(texture_cube);
8184 for (i = 0, offset = 0; i < 6; ++i)
8186 for (j = 0; j < level_count; ++j)
8188 hr = IDirect3DCubeTexture8_LockRect(texture_cube, i, j, &map_desc, NULL, 0);
8189 ok(SUCCEEDED(hr), "%s, %s: Failed to lock face %u, level %u, hr %#x.\n",
8190 pools[pool_idx].name, formats[format_idx].name, i, j, hr);
8192 if (!i && !j)
8193 base = map_desc.pBits;
8194 else
8195 ok(map_desc.pBits == base + offset,
8196 "%s, %s, face %u, level %u: Got unexpected pBits %p, expected %p.\n",
8197 pools[pool_idx].name, formats[format_idx].name, i, j, map_desc.pBits, base + offset);
8198 offset += (base_dimension >> j) * map_desc.Pitch;
8200 hr = IDirect3DCubeTexture8_UnlockRect(texture_cube, i, j);
8201 ok(SUCCEEDED(hr), "%s, %s: Failed to unlock face %u, level %u, hr %#x.\n",
8202 pools[pool_idx].name, formats[format_idx].name, i, j, hr);
8204 offset = (offset + 15) & ~15;
8207 IDirect3DCubeTexture8_Release(texture_cube);
8211 refcount = IDirect3DDevice8_Release(device);
8212 ok(!refcount, "Device has %u references left.\n", refcount);
8213 done:
8214 IDirect3D8_Release(d3d);
8215 DestroyWindow(window);
8218 static void test_render_target_device_mismatch(void)
8220 IDirect3DDevice8 *device, *device2;
8221 IDirect3DSurface8 *surface, *rt;
8222 IDirect3D8 *d3d;
8223 UINT refcount;
8224 HWND window;
8225 HRESULT hr;
8227 window = create_window();
8228 d3d = Direct3DCreate8(D3D_SDK_VERSION);
8229 ok(!!d3d, "Failed to create a D3D object.\n");
8230 if (!(device = create_device(d3d, window, NULL)))
8232 skip("Failed to create a D3D device.\n");
8233 IDirect3D8_Release(d3d);
8234 DestroyWindow(window);
8235 return;
8238 hr = IDirect3DDevice8_GetRenderTarget(device, &rt);
8239 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
8241 device2 = create_device(d3d, window, NULL);
8242 ok(!!device2, "Failed to create a D3D device.\n");
8244 hr = IDirect3DDevice8_CreateRenderTarget(device2, 640, 480,
8245 D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, FALSE, &surface);
8246 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
8248 hr = IDirect3DDevice8_SetRenderTarget(device, surface, NULL);
8249 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8251 IDirect3DSurface8_Release(surface);
8253 hr = IDirect3DDevice8_GetRenderTarget(device2, &surface);
8254 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
8256 hr = IDirect3DDevice8_SetRenderTarget(device, surface, NULL);
8257 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8259 IDirect3DSurface8_Release(surface);
8261 hr = IDirect3DDevice8_GetRenderTarget(device, &surface);
8262 ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
8263 ok(surface == rt, "Got unexpected render target %p, expected %p.\n", surface, rt);
8264 IDirect3DSurface8_Release(surface);
8265 IDirect3DSurface8_Release(rt);
8267 refcount = IDirect3DDevice8_Release(device);
8268 ok(!refcount, "Device has %u references left.\n", refcount);
8269 refcount = IDirect3DDevice8_Release(device2);
8270 ok(!refcount, "Device has %u references left.\n", refcount);
8271 IDirect3D8_Release(d3d);
8272 DestroyWindow(window);
8275 static void test_format_unknown(void)
8277 IDirect3DDevice8 *device;
8278 IDirect3D8 *d3d;
8279 UINT refcount;
8280 HWND window;
8281 void *iface;
8282 HRESULT hr;
8284 window = create_window();
8285 d3d = Direct3DCreate8(D3D_SDK_VERSION);
8286 ok(!!d3d, "Failed to create a D3D object.\n");
8287 if (!(device = create_device(d3d, window, NULL)))
8289 skip("Failed to create a D3D device.\n");
8290 IDirect3D8_Release(d3d);
8291 DestroyWindow(window);
8292 return;
8295 if (SUCCEEDED(IDirect3D8_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
8296 D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, D3DFMT_P8)))
8298 skip("P8 textures are supported, skipping some tests.\n");
8300 else
8302 iface = (void *)0xdeadbeef;
8303 hr = IDirect3DDevice8_CreateRenderTarget(device, 64, 64,
8304 D3DFMT_P8, D3DMULTISAMPLE_NONE, FALSE, (IDirect3DSurface8 **)&iface);
8305 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8306 ok(!iface, "Got unexpected iface %p.\n", iface);
8308 iface = (void *)0xdeadbeef;
8309 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 64, 64,
8310 D3DFMT_P8, D3DMULTISAMPLE_NONE, (IDirect3DSurface8 **)&iface);
8311 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8312 ok(!iface, "Got unexpected iface %p.\n", iface);
8314 iface = (void *)0xdeadbeef;
8315 hr = IDirect3DDevice8_CreateTexture(device, 64, 64, 1, 0,
8316 D3DFMT_P8, D3DPOOL_DEFAULT, (IDirect3DTexture8 **)&iface);
8317 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8318 ok(!iface, "Got unexpected iface %p.\n", iface);
8320 iface = (void *)0xdeadbeef;
8321 hr = IDirect3DDevice8_CreateCubeTexture(device, 64, 1, 0,
8322 D3DFMT_P8, D3DPOOL_DEFAULT, (IDirect3DCubeTexture8 **)&iface);
8323 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8324 ok(!iface, "Got unexpected iface %p.\n", iface);
8326 iface = (void *)0xdeadbeef;
8327 hr = IDirect3DDevice8_CreateVolumeTexture(device, 64, 64, 1, 1, 0,
8328 D3DFMT_P8, D3DPOOL_DEFAULT, (IDirect3DVolumeTexture8 **)&iface);
8329 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8330 ok(!iface, "Got unexpected iface %p.\n", iface);
8333 iface = (void *)0xdeadbeef;
8334 hr = IDirect3DDevice8_CreateRenderTarget(device, 64, 64,
8335 D3DFMT_UNKNOWN, D3DMULTISAMPLE_NONE, FALSE, (IDirect3DSurface8 **)&iface);
8336 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8337 ok(iface == (void *)0xdeadbeef, "Got unexpected iface %p.\n", iface);
8339 iface = (void *)0xdeadbeef;
8340 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 64, 64,
8341 D3DFMT_UNKNOWN, D3DMULTISAMPLE_NONE, (IDirect3DSurface8 **)&iface);
8342 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8343 ok(iface == (void *)0xdeadbeef, "Got unexpected iface %p.\n", iface);
8345 iface = (void *)0xdeadbeef;
8346 hr = IDirect3DDevice8_CreateImageSurface(device, 64, 64,
8347 D3DFMT_UNKNOWN, (IDirect3DSurface8 **)&iface);
8348 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8349 ok(!iface, "Got unexpected iface %p.\n", iface);
8351 iface = (void *)0xdeadbeef;
8352 hr = IDirect3DDevice8_CreateTexture(device, 64, 64, 1, 0,
8353 D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, (IDirect3DTexture8 **)&iface);
8354 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8355 ok(iface == (void *)0xdeadbeef, "Got unexpected iface %p.\n", iface);
8357 iface = (void *)0xdeadbeef;
8358 hr = IDirect3DDevice8_CreateCubeTexture(device, 64, 1, 0,
8359 D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, (IDirect3DCubeTexture8 **)&iface);
8360 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8361 ok(iface == (void *)0xdeadbeef, "Got unexpected iface %p.\n", iface);
8363 iface = (void *)0xdeadbeef;
8364 hr = IDirect3DDevice8_CreateVolumeTexture(device, 64, 64, 1, 1, 0,
8365 D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, (IDirect3DVolumeTexture8 **)&iface);
8366 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8367 ok(iface == (void *)0xdeadbeef, "Got unexpected iface %p.\n", iface);
8369 refcount = IDirect3DDevice8_Release(device);
8370 ok(!refcount, "Device has %u references left.\n", refcount);
8371 IDirect3D8_Release(d3d);
8372 DestroyWindow(window);
8375 static void test_destroyed_window(void)
8377 IDirect3DDevice8 *device;
8378 IDirect3D8 *d3d8;
8379 ULONG refcount;
8380 HWND window;
8381 HRESULT hr;
8383 /* No WS_VISIBLE. */
8384 window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW,
8385 0, 0, 640, 480, NULL, NULL, NULL, NULL);
8386 ok(!!window, "Failed to create a window.\n");
8388 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
8389 ok(!!d3d8, "Failed to create a D3D object.\n");
8390 device = create_device(d3d8, window, NULL);
8391 IDirect3D8_Release(d3d8);
8392 DestroyWindow(window);
8393 if (!device)
8395 skip("Failed to create a 3D device, skipping test.\n");
8396 return;
8399 hr = IDirect3DDevice8_BeginScene(device);
8400 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
8401 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00000000, 0.0f, 0);
8402 ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
8403 hr = IDirect3DDevice8_EndScene(device);
8404 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
8405 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
8406 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8408 refcount = IDirect3DDevice8_Release(device);
8409 ok(!refcount, "Device has %u references left.\n", refcount);
8412 static void test_lockable_backbuffer(void)
8414 D3DPRESENT_PARAMETERS present_parameters = {0};
8415 struct device_desc device_desc;
8416 IDirect3DSurface8 *surface;
8417 IDirect3DDevice8 *device;
8418 D3DLOCKED_RECT lockrect;
8419 IDirect3D8 *d3d;
8420 ULONG refcount;
8421 HWND window;
8422 HRESULT hr;
8424 window = create_window();
8425 d3d = Direct3DCreate8(D3D_SDK_VERSION);
8426 ok(!!d3d, "Failed to create a D3D object.\n");
8428 if (!(device = create_device(d3d, window, NULL)))
8430 skip("Failed to create a D3D device, skipping tests.\n");
8431 IDirect3D8_Release(d3d);
8432 DestroyWindow(window);
8433 return;
8436 hr = IDirect3DDevice8_GetBackBuffer(device, 0, D3DBACKBUFFER_TYPE_MONO, &surface);
8437 ok(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
8439 hr = IDirect3DSurface8_LockRect(surface, &lockrect, NULL, D3DLOCK_READONLY);
8440 todo_wine
8441 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
8443 IDirect3DSurface8_Release(surface);
8445 /* Reset with D3DPRESENTFLAG_LOCKABLE_BACKBUFFER. */
8446 present_parameters.BackBufferWidth = 640;
8447 present_parameters.BackBufferHeight = 480;
8448 present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
8449 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
8450 present_parameters.hDeviceWindow = window;
8451 present_parameters.Windowed = TRUE;
8452 present_parameters.EnableAutoDepthStencil = TRUE;
8453 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
8454 present_parameters.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
8456 hr = IDirect3DDevice8_Reset(device, &present_parameters);
8457 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
8459 hr = IDirect3DDevice8_GetBackBuffer(device, 0, D3DBACKBUFFER_TYPE_MONO, &surface);
8460 ok(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
8462 hr = IDirect3DSurface8_LockRect(surface, &lockrect, NULL, D3DLOCK_READONLY);
8463 ok(SUCCEEDED(hr), "Failed to lock rect, hr %#x.\n", hr);
8464 hr = IDirect3DSurface8_UnlockRect(surface);
8465 ok(SUCCEEDED(hr), "Failed to unlock rect, hr %#x.\n", hr);
8467 IDirect3DSurface8_Release(surface);
8468 refcount = IDirect3DDevice8_Release(device);
8469 ok(!refcount, "Device has %u references left.\n", refcount);
8471 device_desc.width = 640;
8472 device_desc.height = 480;
8473 device_desc.device_window = window;
8474 device_desc.flags = CREATE_DEVICE_LOCKABLE_BACKBUFFER;
8476 device = create_device(d3d, window, &device_desc);
8477 ok(!!device, "Failed to create device.\n");
8479 hr = IDirect3DDevice8_GetBackBuffer(device, 0, D3DBACKBUFFER_TYPE_MONO, &surface);
8480 ok(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
8482 hr = IDirect3DSurface8_LockRect(surface, &lockrect, NULL, D3DLOCK_READONLY);
8483 ok(SUCCEEDED(hr), "Failed to lock rect, hr %#x.\n", hr);
8484 hr = IDirect3DSurface8_UnlockRect(surface);
8485 ok(SUCCEEDED(hr), "Failed to unlock rect, hr %#x.\n", hr);
8487 IDirect3DSurface8_Release(surface);
8488 refcount = IDirect3DDevice8_Release(device);
8489 ok(!refcount, "Device has %u references left.\n", refcount);
8490 IDirect3D8_Release(d3d);
8491 DestroyWindow(window);
8494 static void test_clip_planes_limits(void)
8496 static const DWORD device_flags[] = {0, CREATE_DEVICE_SWVP_ONLY};
8497 IDirect3DDevice8 *device;
8498 struct device_desc desc;
8499 unsigned int i, j;
8500 IDirect3D8 *d3d;
8501 ULONG refcount;
8502 float plane[4];
8503 D3DCAPS8 caps;
8504 DWORD state;
8505 HWND window;
8506 HRESULT hr;
8508 window = create_window();
8509 d3d = Direct3DCreate8(D3D_SDK_VERSION);
8510 ok(!!d3d, "Failed to create a D3D object.\n");
8512 for (i = 0; i < ARRAY_SIZE(device_flags); ++i)
8514 desc.device_window = window;
8515 desc.width = 640;
8516 desc.height = 480;
8517 desc.flags = device_flags[i];
8518 if (!(device = create_device(d3d, window, &desc)))
8520 skip("Failed to create D3D device, flags %#x.\n", desc.flags);
8521 continue;
8524 memset(&caps, 0, sizeof(caps));
8525 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
8526 ok(hr == D3D_OK, "Failed to get caps, hr %#x.\n", hr);
8528 trace("Max user clip planes: %u.\n", caps.MaxUserClipPlanes);
8530 for (j = 0; j < caps.MaxUserClipPlanes; ++j)
8532 memset(plane, 0xff, sizeof(plane));
8533 hr = IDirect3DDevice8_GetClipPlane(device, j, plane);
8534 ok(hr == D3D_OK, "Failed to get clip plane %u, hr %#x.\n", j, hr);
8535 ok(!plane[0] && !plane[1] && !plane[2] && !plane[3],
8536 "Got unexpected plane %u: %.8e, %.8e, %.8e, %.8e.\n",
8537 j, plane[0], plane[1], plane[2], plane[3]);
8540 plane[0] = 2.0f;
8541 plane[1] = 8.0f;
8542 plane[2] = 5.0f;
8543 for (j = 0; j < caps.MaxUserClipPlanes; ++j)
8545 plane[3] = j;
8546 hr = IDirect3DDevice8_SetClipPlane(device, j, plane);
8547 ok(hr == D3D_OK, "Failed to set clip plane %u, hr %#x.\n", j, hr);
8549 for (j = 0; j < caps.MaxUserClipPlanes; ++j)
8551 memset(plane, 0xff, sizeof(plane));
8552 hr = IDirect3DDevice8_GetClipPlane(device, j, plane);
8553 ok(hr == D3D_OK, "Failed to get clip plane %u, hr %#x.\n", j, hr);
8554 ok(plane[0] == 2.0f && plane[1] == 8.0f && plane[2] == 5.0f && plane[3] == j,
8555 "Got unexpected plane %u: %.8e, %.8e, %.8e, %.8e.\n",
8556 j, plane[0], plane[1], plane[2], plane[3]);
8559 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_CLIPPLANEENABLE, 0xffffffff);
8560 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8561 hr = IDirect3DDevice8_GetRenderState(device, D3DRS_CLIPPLANEENABLE, &state);
8562 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
8563 ok(state == 0xffffffff, "Got unexpected state %#x.\n", state);
8564 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_CLIPPLANEENABLE, 0x80000000);
8565 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
8566 hr = IDirect3DDevice8_GetRenderState(device, D3DRS_CLIPPLANEENABLE, &state);
8567 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
8568 ok(state == 0x80000000, "Got unexpected state %#x.\n", state);
8570 refcount = IDirect3DDevice8_Release(device);
8571 ok(!refcount, "Device has %u references left.\n", refcount);
8574 IDirect3D8_Release(d3d);
8575 DestroyWindow(window);
8578 static void test_swapchain_multisample_reset(void)
8580 D3DPRESENT_PARAMETERS present_parameters;
8581 IDirect3DDevice8 *device;
8582 IDirect3D8 *d3d;
8583 ULONG refcount;
8584 HWND window;
8585 HRESULT hr;
8587 window = create_window();
8588 ok(!!window, "Failed to create a window.\n");
8589 d3d = Direct3DCreate8(D3D_SDK_VERSION);
8590 ok(!!d3d, "Failed to create D3D object.\n");
8592 if (IDirect3D8_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
8593 D3DFMT_A8R8G8B8, TRUE, D3DMULTISAMPLE_2_SAMPLES) == D3DERR_NOTAVAILABLE)
8595 skip("Multisampling not supported for D3DFMT_A8R8G8B8.\n");
8596 IDirect3D8_Release(d3d);
8597 DestroyWindow(window);
8598 return;
8601 if (!(device = create_device(d3d, window, NULL)))
8603 skip("Failed to create 3D device.\n");
8604 IDirect3D8_Release(d3d);
8605 DestroyWindow(window);
8606 return;
8609 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0);
8610 ok(hr == D3D_OK, "Failed to clear, hr %#x.\n", hr);
8612 memset(&present_parameters, 0, sizeof(present_parameters));
8613 present_parameters.BackBufferWidth = 640;
8614 present_parameters.BackBufferHeight = 480;
8615 present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
8616 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
8617 present_parameters.hDeviceWindow = NULL;
8618 present_parameters.Windowed = TRUE;
8619 present_parameters.MultiSampleType = D3DMULTISAMPLE_2_SAMPLES;
8620 hr = IDirect3DDevice8_Reset(device, &present_parameters);
8621 ok(hr == D3D_OK, "Failed to reset device, hr %#x.\n", hr);
8623 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 0.0f, 0);
8624 ok(hr == D3D_OK, "Failed to clear, hr %#x.\n", hr);
8626 refcount = IDirect3DDevice8_Release(device);
8627 ok(!refcount, "Device has %u references left.\n", refcount);
8628 IDirect3D8_Release(d3d);
8629 DestroyWindow(window);
8632 static void test_device_caps(void)
8634 IDirect3DDevice8 *device;
8635 IDirect3D8 *d3d;
8636 ULONG refcount;
8637 D3DCAPS8 caps;
8638 HWND window;
8639 HRESULT hr;
8641 window = create_window();
8642 d3d = Direct3DCreate8(D3D_SDK_VERSION);
8643 ok(!!d3d, "Failed to create a D3D object.\n");
8644 if (!(device = create_device(d3d, window, NULL)))
8646 skip("Failed to create a D3D device.\n");
8647 IDirect3D8_Release(d3d);
8648 DestroyWindow(window);
8649 return;
8652 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
8653 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
8655 ok(!(caps.Caps & ~D3DCAPS_READ_SCANLINE), "Caps field has unexpected flags %#x.\n", caps.Caps);
8656 ok(!(caps.Caps2 & ~(D3DCAPS2_CANCALIBRATEGAMMA | D3DCAPS2_CANRENDERWINDOWED
8657 | D3DCAPS2_CANMANAGERESOURCE | D3DCAPS2_DYNAMICTEXTURES | D3DCAPS2_FULLSCREENGAMMA
8658 | D3DCAPS2_NO2DDURING3DSCENE | D3DCAPS2_RESERVED)),
8659 "Caps2 field has unexpected flags %#x.\n", caps.Caps2);
8660 /* Nvidia returns that 0x400 flag, which is probably Vista+
8661 * D3DCAPS3_DXVAHD from d3d9caps.h */
8662 /* AMD doesn't filter all the ddraw / d3d9 caps. Consider that behavior
8663 * broken. */
8664 ok(!(caps.Caps3 & ~(D3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD | D3DCAPS3_RESERVED | 0x400))
8665 || broken(!(caps.Caps3 & ~(D3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD | 0x80))),
8666 "Caps3 field has unexpected flags %#x.\n", caps.Caps3);
8667 ok(!(caps.PrimitiveMiscCaps & ~(D3DPMISCCAPS_MASKZ | D3DPMISCCAPS_LINEPATTERNREP
8668 | D3DPMISCCAPS_CULLNONE | D3DPMISCCAPS_CULLCW | D3DPMISCCAPS_CULLCCW
8669 | D3DPMISCCAPS_COLORWRITEENABLE | D3DPMISCCAPS_CLIPPLANESCALEDPOINTS
8670 | D3DPMISCCAPS_CLIPTLVERTS | D3DPMISCCAPS_TSSARGTEMP | D3DPMISCCAPS_BLENDOP
8671 | D3DPMISCCAPS_NULLREFERENCE))
8672 || broken(!(caps.PrimitiveMiscCaps & ~0x003fdff6)),
8673 "PrimitiveMiscCaps field has unexpected flags %#x.\n", caps.PrimitiveMiscCaps);
8674 /* AMD includes an unknown 0x2 flag. */
8675 ok(!(caps.RasterCaps & ~(D3DPRASTERCAPS_DITHER | D3DPRASTERCAPS_PAT | D3DPRASTERCAPS_ZTEST
8676 | D3DPRASTERCAPS_FOGVERTEX | D3DPRASTERCAPS_FOGTABLE | D3DPRASTERCAPS_ANTIALIASEDGES
8677 | D3DPRASTERCAPS_MIPMAPLODBIAS | D3DPRASTERCAPS_ZBIAS | D3DPRASTERCAPS_ZBUFFERLESSHSR
8678 | D3DPRASTERCAPS_FOGRANGE | D3DPRASTERCAPS_ANISOTROPY | D3DPRASTERCAPS_WBUFFER
8679 | D3DPRASTERCAPS_WFOG | D3DPRASTERCAPS_ZFOG | D3DPRASTERCAPS_COLORPERSPECTIVE
8680 | D3DPRASTERCAPS_STRETCHBLTMULTISAMPLE))
8681 || broken(!(caps.RasterCaps & ~0x0ff7f19b)),
8682 "RasterCaps field has unexpected flags %#x.\n", caps.RasterCaps);
8683 ok(!(caps.SrcBlendCaps & ~(D3DPBLENDCAPS_ZERO | D3DPBLENDCAPS_ONE | D3DPBLENDCAPS_SRCCOLOR
8684 | D3DPBLENDCAPS_INVSRCCOLOR | D3DPBLENDCAPS_SRCALPHA | D3DPBLENDCAPS_INVSRCALPHA
8685 | D3DPBLENDCAPS_DESTALPHA | D3DPBLENDCAPS_INVDESTALPHA | D3DPBLENDCAPS_DESTCOLOR
8686 | D3DPBLENDCAPS_INVDESTCOLOR | D3DPBLENDCAPS_SRCALPHASAT | D3DPBLENDCAPS_BOTHSRCALPHA
8687 | D3DPBLENDCAPS_BOTHINVSRCALPHA)),
8688 "SrcBlendCaps field has unexpected flags %#x.\n", caps.SrcBlendCaps);
8689 ok(!(caps.DestBlendCaps & ~(D3DPBLENDCAPS_ZERO | D3DPBLENDCAPS_ONE | D3DPBLENDCAPS_SRCCOLOR
8690 | D3DPBLENDCAPS_INVSRCCOLOR | D3DPBLENDCAPS_SRCALPHA | D3DPBLENDCAPS_INVSRCALPHA
8691 | D3DPBLENDCAPS_DESTALPHA | D3DPBLENDCAPS_INVDESTALPHA | D3DPBLENDCAPS_DESTCOLOR
8692 | D3DPBLENDCAPS_INVDESTCOLOR | D3DPBLENDCAPS_SRCALPHASAT | D3DPBLENDCAPS_BOTHSRCALPHA
8693 | D3DPBLENDCAPS_BOTHINVSRCALPHA)),
8694 "DestBlendCaps field has unexpected flags %#x.\n", caps.DestBlendCaps);
8695 ok(!(caps.TextureCaps & ~(D3DPTEXTURECAPS_PERSPECTIVE | D3DPTEXTURECAPS_POW2
8696 | D3DPTEXTURECAPS_ALPHA | D3DPTEXTURECAPS_SQUAREONLY
8697 | D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE | D3DPTEXTURECAPS_ALPHAPALETTE
8698 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL | D3DPTEXTURECAPS_PROJECTED
8699 | D3DPTEXTURECAPS_CUBEMAP | D3DPTEXTURECAPS_VOLUMEMAP | D3DPTEXTURECAPS_MIPMAP
8700 | D3DPTEXTURECAPS_MIPVOLUMEMAP | D3DPTEXTURECAPS_MIPCUBEMAP
8701 | D3DPTEXTURECAPS_CUBEMAP_POW2 | D3DPTEXTURECAPS_VOLUMEMAP_POW2)),
8702 "TextureCaps field has unexpected flags %#x.\n", caps.TextureCaps);
8703 ok(!(caps.TextureFilterCaps & ~(D3DPTFILTERCAPS_MINFPOINT | D3DPTFILTERCAPS_MINFLINEAR
8704 | D3DPTFILTERCAPS_MINFANISOTROPIC | D3DPTFILTERCAPS_MIPFPOINT
8705 | D3DPTFILTERCAPS_MIPFLINEAR | D3DPTFILTERCAPS_MAGFPOINT | D3DPTFILTERCAPS_MAGFLINEAR
8706 | D3DPTFILTERCAPS_MAGFANISOTROPIC | D3DPTFILTERCAPS_MAGFAFLATCUBIC
8707 | D3DPTFILTERCAPS_MAGFGAUSSIANCUBIC))
8708 || broken(!(caps.TextureFilterCaps & ~0x0703073f)),
8709 "TextureFilterCaps field has unexpected flags %#x.\n", caps.TextureFilterCaps);
8710 ok(!(caps.CubeTextureFilterCaps & ~(D3DPTFILTERCAPS_MINFPOINT | D3DPTFILTERCAPS_MINFLINEAR
8711 | D3DPTFILTERCAPS_MINFANISOTROPIC | D3DPTFILTERCAPS_MIPFPOINT
8712 | D3DPTFILTERCAPS_MIPFLINEAR | D3DPTFILTERCAPS_MAGFPOINT | D3DPTFILTERCAPS_MAGFLINEAR
8713 | D3DPTFILTERCAPS_MAGFANISOTROPIC | D3DPTFILTERCAPS_MAGFAFLATCUBIC
8714 | D3DPTFILTERCAPS_MAGFGAUSSIANCUBIC)),
8715 "CubeTextureFilterCaps field has unexpected flags %#x.\n", caps.CubeTextureFilterCaps);
8716 ok(!(caps.VolumeTextureFilterCaps & ~(D3DPTFILTERCAPS_MINFPOINT | D3DPTFILTERCAPS_MINFLINEAR
8717 | D3DPTFILTERCAPS_MINFANISOTROPIC | D3DPTFILTERCAPS_MIPFPOINT
8718 | D3DPTFILTERCAPS_MIPFLINEAR | D3DPTFILTERCAPS_MAGFPOINT | D3DPTFILTERCAPS_MAGFLINEAR
8719 | D3DPTFILTERCAPS_MAGFANISOTROPIC | D3DPTFILTERCAPS_MAGFAFLATCUBIC
8720 | D3DPTFILTERCAPS_MAGFGAUSSIANCUBIC)),
8721 "VolumeTextureFilterCaps field has unexpected flags %#x.\n", caps.VolumeTextureFilterCaps);
8722 ok(!(caps.LineCaps & ~(D3DLINECAPS_TEXTURE | D3DLINECAPS_ZTEST | D3DLINECAPS_BLEND
8723 | D3DLINECAPS_ALPHACMP | D3DLINECAPS_FOG)),
8724 "LineCaps field has unexpected flags %#x.\n", caps.LineCaps);
8725 ok(!(caps.StencilCaps & ~(D3DSTENCILCAPS_KEEP | D3DSTENCILCAPS_ZERO | D3DSTENCILCAPS_REPLACE
8726 | D3DSTENCILCAPS_INCRSAT | D3DSTENCILCAPS_DECRSAT | D3DSTENCILCAPS_INVERT
8727 | D3DSTENCILCAPS_INCR | D3DSTENCILCAPS_DECR)),
8728 "StencilCaps field has unexpected flags %#x.\n", caps.StencilCaps);
8729 ok(!(caps.VertexProcessingCaps & ~(D3DVTXPCAPS_TEXGEN | D3DVTXPCAPS_MATERIALSOURCE7
8730 | D3DVTXPCAPS_DIRECTIONALLIGHTS | D3DVTXPCAPS_POSITIONALLIGHTS | D3DVTXPCAPS_LOCALVIEWER
8731 | D3DVTXPCAPS_TWEENING | D3DVTXPCAPS_NO_VSDT_UBYTE4)),
8732 "VertexProcessingCaps field has unexpected flags %#x.\n", caps.VertexProcessingCaps);
8733 /* Both Nvidia and AMD give 10 here. */
8734 ok(caps.MaxActiveLights <= 10,
8735 "MaxActiveLights field has unexpected value %u.\n", caps.MaxActiveLights);
8736 /* AMD gives 6, Nvidia returns 8. */
8737 ok(caps.MaxUserClipPlanes <= 8,
8738 "MaxUserClipPlanes field has unexpected value %u.\n", caps.MaxUserClipPlanes);
8740 refcount = IDirect3DDevice8_Release(device);
8741 ok(!refcount, "Device has %u references left.\n", refcount);
8742 IDirect3D8_Release(d3d);
8743 DestroyWindow(window);
8746 static void test_get_info(void)
8748 IDirect3DDevice8 *device;
8749 IDirect3D8 *d3d;
8750 BYTE info[1024];
8751 ULONG refcount;
8752 unsigned int i;
8753 HWND window;
8754 HRESULT hr;
8756 window = create_window();
8757 d3d = Direct3DCreate8(D3D_SDK_VERSION);
8758 ok(!!d3d, "Failed to create a D3D object.\n");
8759 if (!(device = create_device(d3d, window, NULL)))
8761 skip("Failed to create a D3D device.\n");
8762 IDirect3D8_Release(d3d);
8763 DestroyWindow(window);
8764 return;
8767 /* As called by Chessmaster 9000 (bug 42118). */
8768 hr = IDirect3DDevice8_GetInfo(device, 4, info, 16);
8769 ok(hr == S_FALSE, "Unexpected hr %#x.\n", hr);
8771 for (i = 0; i < 256; ++i)
8773 hr = IDirect3DDevice8_GetInfo(device, i, info, sizeof(info));
8774 if (i <= 4)
8775 ok(hr == (i < 4 ? E_FAIL : S_FALSE), "info_id %u, unexpected hr %#x.\n", i, hr);
8776 else
8777 ok(hr == E_FAIL || hr == S_FALSE, "info_id %u, unexpected hr %#x.\n", i, hr);
8780 refcount = IDirect3DDevice8_Release(device);
8781 ok(!refcount, "Device has %u references left.\n", refcount);
8782 IDirect3D8_Release(d3d);
8783 DestroyWindow(window);
8786 START_TEST(device)
8788 HMODULE d3d8_handle = GetModuleHandleA("d3d8.dll");
8789 WNDCLASSA wc = {0};
8790 IDirect3D8 *d3d8;
8791 DEVMODEW current_mode;
8793 if (!d3d8_handle)
8795 skip("Could not load d3d8.dll\n");
8796 return;
8799 memset(&current_mode, 0, sizeof(current_mode));
8800 current_mode.dmSize = sizeof(current_mode);
8801 ok(EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &current_mode), "Failed to get display mode.\n");
8802 registry_mode.dmSize = sizeof(registry_mode);
8803 ok(EnumDisplaySettingsW(NULL, ENUM_REGISTRY_SETTINGS, &registry_mode), "Failed to get display mode.\n");
8804 if (current_mode.dmPelsWidth != registry_mode.dmPelsWidth
8805 || current_mode.dmPelsHeight != registry_mode.dmPelsHeight)
8807 skip("Current mode does not match registry mode, skipping test.\n");
8808 return;
8811 wc.lpfnWndProc = DefWindowProcA;
8812 wc.lpszClassName = "d3d8_test_wc";
8813 RegisterClassA(&wc);
8815 ValidateVertexShader = (void *)GetProcAddress(d3d8_handle, "ValidateVertexShader");
8816 ValidatePixelShader = (void *)GetProcAddress(d3d8_handle, "ValidatePixelShader");
8818 if (!(d3d8 = Direct3DCreate8(D3D_SDK_VERSION)))
8820 skip("could not create D3D8\n");
8821 return;
8823 IDirect3D8_Release(d3d8);
8825 test_fpu_setup();
8826 test_display_formats();
8827 test_display_modes();
8828 test_shader_versions();
8829 test_swapchain();
8830 test_refcount();
8831 test_mipmap_levels();
8832 test_checkdevicemultisampletype();
8833 test_invalid_multisample();
8834 test_cursor();
8835 test_cursor_pos();
8836 test_states();
8837 test_reset();
8838 test_scene();
8839 test_shader();
8840 test_limits();
8841 test_lights();
8842 test_ApplyStateBlock();
8843 test_render_zero_triangles();
8844 test_depth_stencil_reset();
8845 test_wndproc();
8846 test_wndproc_windowed();
8847 test_depth_stencil_size();
8848 test_window_style();
8849 test_unsupported_shaders();
8850 test_mode_change();
8851 test_device_window_reset();
8852 test_reset_resources();
8853 depth_blit_test();
8854 test_set_rt_vp_scissor();
8855 test_validate_vs();
8856 test_validate_ps();
8857 test_volume_get_container();
8858 test_vb_lock_flags();
8859 test_texture_stage_states();
8860 test_cube_textures();
8861 test_get_set_texture();
8862 test_image_surface_pool();
8863 test_surface_get_container();
8864 test_lockrect_invalid();
8865 test_private_data();
8866 test_surface_dimensions();
8867 test_surface_format_null();
8868 test_surface_double_unlock();
8869 test_surface_blocks();
8870 test_set_palette();
8871 test_swvp_buffer();
8872 test_managed_buffer();
8873 test_npot_textures();
8874 test_volume_locking();
8875 test_update_volumetexture();
8876 test_create_rt_ds_fail();
8877 test_volume_blocks();
8878 test_lockbox_invalid();
8879 test_pixel_format();
8880 test_begin_end_state_block();
8881 test_shader_constant_apply();
8882 test_resource_type();
8883 test_mipmap_lock();
8884 test_writeonly_resource();
8885 test_lost_device();
8886 test_resource_priority();
8887 test_swapchain_parameters();
8888 test_check_device_format();
8889 test_miptree_layout();
8890 test_render_target_device_mismatch();
8891 test_format_unknown();
8892 test_destroyed_window();
8893 test_lockable_backbuffer();
8894 test_clip_planes_limits();
8895 test_swapchain_multisample_reset();
8896 test_device_caps();
8897 test_get_info();
8899 UnregisterClassA("d3d8_test_wc", GetModuleHandleA(NULL));