wined3d: Allocate system memory for complete textures.
[wine.git] / dlls / d3d8 / tests / device.c
blob11969f4657670e568e7ac5945dd6673cdd130bbe
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 #define COBJMACROS
26 #include <initguid.h>
27 #include <d3d8.h>
28 #include "wine/test.h"
30 struct vec3
32 float x, y, z;
35 #define CREATE_DEVICE_FULLSCREEN 0x01
36 #define CREATE_DEVICE_FPU_PRESERVE 0x02
37 #define CREATE_DEVICE_SWVP_ONLY 0x04
39 struct device_desc
41 HWND device_window;
42 unsigned int width;
43 unsigned int height;
44 DWORD flags;
47 #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
48 #define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
50 static DEVMODEW registry_mode;
52 static HRESULT (WINAPI *ValidateVertexShader)(DWORD *, DWORD *, DWORD *, int, DWORD *);
53 static HRESULT (WINAPI *ValidatePixelShader)(DWORD *, DWORD *, int, DWORD *);
55 static BOOL (WINAPI *pGetCursorInfo)(PCURSORINFO);
57 static const DWORD simple_vs[] = {0xFFFE0101, /* vs_1_1 */
58 0x00000009, 0xC0010000, 0x90E40000, 0xA0E40000, /* dp4 oPos.x, v0, c0 */
59 0x00000009, 0xC0020000, 0x90E40000, 0xA0E40001, /* dp4 oPos.y, v0, c1 */
60 0x00000009, 0xC0040000, 0x90E40000, 0xA0E40002, /* dp4 oPos.z, v0, c2 */
61 0x00000009, 0xC0080000, 0x90E40000, 0xA0E40003, /* dp4 oPos.w, v0, c3 */
62 0x0000FFFF}; /* END */
63 static const DWORD simple_ps[] = {0xFFFF0101, /* ps_1_1 */
64 0x00000051, 0xA00F0001, 0x3F800000, 0x00000000, 0x00000000, 0x00000000, /* def c1 = 1.0, 0.0, 0.0, 0.0 */
65 0x00000042, 0xB00F0000, /* tex t0 */
66 0x00000008, 0x800F0000, 0xA0E40001, 0xA0E40000, /* dp3 r0, c1, c0 */
67 0x00000005, 0x800F0000, 0x90E40000, 0x80E40000, /* mul r0, v0, r0 */
68 0x00000005, 0x800F0000, 0xB0E40000, 0x80E40000, /* mul r0, t0, r0 */
69 0x0000FFFF}; /* END */
71 static int get_refcount(IUnknown *object)
73 IUnknown_AddRef( object );
74 return IUnknown_Release( object );
77 /* try to make sure pending X events have been processed before continuing */
78 static void flush_events(void)
80 MSG msg;
81 int diff = 200;
82 int min_timeout = 100;
83 DWORD time = GetTickCount() + diff;
85 while (diff > 0)
87 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
88 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
89 diff = time - GetTickCount();
93 static IDirect3DDevice8 *create_device(IDirect3D8 *d3d8, HWND focus_window, const struct device_desc *desc)
95 D3DPRESENT_PARAMETERS present_parameters = {0};
96 IDirect3DDevice8 *device;
97 DWORD behavior_flags = D3DCREATE_HARDWARE_VERTEXPROCESSING;
99 present_parameters.BackBufferWidth = 640;
100 present_parameters.BackBufferHeight = 480;
101 present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
102 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
103 present_parameters.hDeviceWindow = focus_window;
104 present_parameters.Windowed = TRUE;
105 present_parameters.EnableAutoDepthStencil = TRUE;
106 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
108 if (desc)
110 present_parameters.BackBufferWidth = desc->width;
111 present_parameters.BackBufferHeight = desc->height;
112 present_parameters.hDeviceWindow = desc->device_window;
113 present_parameters.Windowed = !(desc->flags & CREATE_DEVICE_FULLSCREEN);
114 if (desc->flags & CREATE_DEVICE_SWVP_ONLY)
115 behavior_flags = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
116 if (desc->flags & CREATE_DEVICE_FPU_PRESERVE)
117 behavior_flags |= D3DCREATE_FPU_PRESERVE;
120 if (SUCCEEDED(IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, focus_window,
121 behavior_flags, &present_parameters, &device)))
122 return device;
124 present_parameters.AutoDepthStencilFormat = D3DFMT_D16;
125 if (SUCCEEDED(IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, focus_window,
126 behavior_flags, &present_parameters, &device)))
127 return device;
129 if (desc && desc->flags & CREATE_DEVICE_SWVP_ONLY)
130 return NULL;
131 behavior_flags ^= (D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_SOFTWARE_VERTEXPROCESSING);
133 if (SUCCEEDED(IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, focus_window,
134 behavior_flags, &present_parameters, &device)))
135 return device;
137 return NULL;
140 static HRESULT reset_device(IDirect3DDevice8 *device, const struct device_desc *desc)
142 D3DPRESENT_PARAMETERS present_parameters = {0};
144 present_parameters.BackBufferWidth = 640;
145 present_parameters.BackBufferHeight = 480;
146 present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
147 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
148 present_parameters.hDeviceWindow = NULL;
149 present_parameters.Windowed = TRUE;
150 present_parameters.EnableAutoDepthStencil = TRUE;
151 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
153 if (desc)
155 present_parameters.BackBufferWidth = desc->width;
156 present_parameters.BackBufferHeight = desc->height;
157 present_parameters.hDeviceWindow = desc->device_window;
158 present_parameters.Windowed = !(desc->flags & CREATE_DEVICE_FULLSCREEN);
161 return IDirect3DDevice8_Reset(device, &present_parameters);
164 #define CHECK_CALL(r,c,d,rc) \
165 if (SUCCEEDED(r)) {\
166 int tmp1 = get_refcount( (IUnknown *)d ); \
167 int rc_new = rc; \
168 ok(tmp1 == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, tmp1); \
169 } else {\
170 trace("%s failed: %#08x\n", c, r); \
173 #define CHECK_RELEASE(obj,d,rc) \
174 if (obj) { \
175 int tmp1, rc_new = rc; \
176 IUnknown_Release( (IUnknown*)obj ); \
177 tmp1 = get_refcount( (IUnknown *)d ); \
178 ok(tmp1 == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, tmp1); \
181 #define CHECK_REFCOUNT(obj,rc) \
183 int rc_new = rc; \
184 int count = get_refcount( (IUnknown *)obj ); \
185 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
188 #define CHECK_RELEASE_REFCOUNT(obj,rc) \
190 int rc_new = rc; \
191 int count = IUnknown_Release( (IUnknown *)obj ); \
192 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
195 #define CHECK_ADDREF_REFCOUNT(obj,rc) \
197 int rc_new = rc; \
198 int count = IUnknown_AddRef( (IUnknown *)obj ); \
199 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
202 #define CHECK_SURFACE_CONTAINER(obj,iid,expected) \
204 void *container_ptr = (void *)0x1337c0d3; \
205 hr = IDirect3DSurface8_GetContainer(obj, &iid, &container_ptr); \
206 ok(SUCCEEDED(hr) && container_ptr == expected, "GetContainer returned: hr %#08x, container_ptr %p. " \
207 "Expected hr %#08x, container_ptr %p\n", hr, container_ptr, S_OK, expected); \
208 if (container_ptr && container_ptr != (void *)0x1337c0d3) IUnknown_Release((IUnknown *)container_ptr); \
211 static void check_mipmap_levels(IDirect3DDevice8 *device, UINT width, UINT height, UINT count)
213 IDirect3DBaseTexture8* texture = NULL;
214 HRESULT hr = IDirect3DDevice8_CreateTexture( device, width, height, 0, 0,
215 D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, (IDirect3DTexture8**) &texture );
217 if (SUCCEEDED(hr)) {
218 DWORD levels = IDirect3DBaseTexture8_GetLevelCount(texture);
219 ok(levels == count, "Invalid level count. Expected %d got %u\n", count, levels);
220 } else
221 trace("CreateTexture failed: %#08x\n", hr);
223 if (texture) IDirect3DBaseTexture8_Release( texture );
226 static void test_mipmap_levels(void)
228 IDirect3DDevice8 *device;
229 IDirect3D8 *d3d;
230 ULONG refcount;
231 HWND window;
233 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
234 0, 0, 640, 480, NULL, NULL, NULL, NULL);
235 ok(!!window, "Failed to create a window.\n");
236 d3d = Direct3DCreate8(D3D_SDK_VERSION);
237 ok(!!d3d, "Failed to create a D3D object.\n");
238 if (!(device = create_device(d3d, window, NULL)))
240 skip("Failed to create a 3D device, skipping test.\n");
241 goto cleanup;
244 check_mipmap_levels(device, 32, 32, 6);
245 check_mipmap_levels(device, 256, 1, 9);
246 check_mipmap_levels(device, 1, 256, 9);
247 check_mipmap_levels(device, 1, 1, 1);
249 refcount = IDirect3DDevice8_Release(device);
250 ok(!refcount, "Device has %u references left.\n", refcount);
251 cleanup:
252 IDirect3D8_Release(d3d);
253 DestroyWindow(window);
256 static void test_swapchain(void)
258 IDirect3DSwapChain8 *swapchain1;
259 IDirect3DSwapChain8 *swapchain2;
260 IDirect3DSwapChain8 *swapchain3;
261 IDirect3DSurface8 *backbuffer, *stereo_buffer;
262 D3DPRESENT_PARAMETERS d3dpp;
263 IDirect3DDevice8 *device;
264 IDirect3D8 *d3d;
265 ULONG refcount;
266 HWND window, window2;
267 HRESULT hr;
268 struct device_desc device_desc;
270 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
271 0, 0, 640, 480, NULL, NULL, NULL, NULL);
272 ok(!!window, "Failed to create a window.\n");
273 window2 = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
274 0, 0, 640, 480, NULL, NULL, NULL, NULL);
275 ok(!!window2, "Failed to create a window.\n");
276 d3d = Direct3DCreate8(D3D_SDK_VERSION);
277 ok(!!d3d, "Failed to create a D3D object.\n");
278 if (!(device = create_device(d3d, window, NULL)))
280 skip("Failed to create a 3D device, skipping test.\n");
281 goto cleanup;
284 backbuffer = (void *)0xdeadbeef;
285 /* IDirect3DDevice8::GetBackBuffer crashes if a NULL output pointer is passed. */
286 hr = IDirect3DDevice8_GetBackBuffer(device, 1, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
287 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
288 ok(!backbuffer, "The back buffer pointer is %p, expected NULL.\n", backbuffer);
290 hr = IDirect3DDevice8_GetBackBuffer(device, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
291 ok(SUCCEEDED(hr), "Failed to get back buffer, hr %#x.\n", hr);
292 IDirect3DSurface8_Release(backbuffer);
294 /* The back buffer type value is ignored. */
295 hr = IDirect3DDevice8_GetBackBuffer(device, 0, D3DBACKBUFFER_TYPE_LEFT, &stereo_buffer);
296 ok(SUCCEEDED(hr), "Failed to get the back buffer, hr %#x.\n", hr);
297 ok(stereo_buffer == backbuffer, "Expected left back buffer = %p, got %p.\n", backbuffer, stereo_buffer);
298 IDirect3DSurface8_Release(stereo_buffer);
299 hr = IDirect3DDevice8_GetBackBuffer(device, 0, D3DBACKBUFFER_TYPE_RIGHT, &stereo_buffer);
300 ok(SUCCEEDED(hr), "Failed to get the back buffer, hr %#x.\n", hr);
301 ok(stereo_buffer == backbuffer, "Expected right back buffer = %p, got %p.\n", backbuffer, stereo_buffer);
302 IDirect3DSurface8_Release(stereo_buffer);
303 hr = IDirect3DDevice8_GetBackBuffer(device, 0, (D3DBACKBUFFER_TYPE)0xdeadbeef, &stereo_buffer);
304 ok(SUCCEEDED(hr), "Failed to get the back buffer, hr %#x.\n", hr);
305 ok(stereo_buffer == backbuffer, "Expected unknown buffer = %p, got %p.\n", backbuffer, stereo_buffer);
306 IDirect3DSurface8_Release(stereo_buffer);
308 memset(&d3dpp, 0, sizeof(d3dpp));
309 d3dpp.Windowed = TRUE;
310 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
311 d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
313 /* Create a bunch of swapchains */
314 d3dpp.BackBufferCount = 0;
315 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain1);
316 ok(SUCCEEDED(hr), "Failed to create a swapchain (%#08x)\n", hr);
317 ok(d3dpp.BackBufferCount == 1, "The back buffer count in the presentparams struct is %d\n", d3dpp.BackBufferCount);
319 d3dpp.BackBufferCount = 1;
320 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain2);
321 ok(SUCCEEDED(hr), "Failed to create a swapchain (%#08x)\n", hr);
323 d3dpp.BackBufferCount = 2;
324 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain3);
325 ok(SUCCEEDED(hr), "Failed to create a swapchain (%#08x)\n", hr);
326 if(SUCCEEDED(hr)) {
327 /* Swapchain 3, created with backbuffercount 2 */
328 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 0, 0, NULL);
329 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
331 backbuffer = (void *) 0xdeadbeef;
332 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 0, 0, &backbuffer);
333 ok(SUCCEEDED(hr), "Failed to get the 1st back buffer (%#08x)\n", hr);
334 ok(backbuffer != NULL && backbuffer != (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer);
335 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
337 /* The back buffer type value is ignored. */
338 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 0, D3DBACKBUFFER_TYPE_LEFT, &stereo_buffer);
339 ok(SUCCEEDED(hr), "Failed to get the back buffer, hr %#x.\n", hr);
340 ok(stereo_buffer == backbuffer, "Expected left back buffer = %p, got %p.\n", backbuffer, stereo_buffer);
341 IDirect3DSurface8_Release(stereo_buffer);
342 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 0, D3DBACKBUFFER_TYPE_RIGHT, &stereo_buffer);
343 ok(SUCCEEDED(hr), "Failed to get the back buffer, hr %#x.\n", hr);
344 ok(stereo_buffer == backbuffer, "Expected right back buffer = %p, got %p.\n", backbuffer, stereo_buffer);
345 IDirect3DSurface8_Release(stereo_buffer);
346 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 0, (D3DBACKBUFFER_TYPE)0xdeadbeef, &stereo_buffer);
347 ok(SUCCEEDED(hr), "Failed to get the back buffer, hr %#x.\n", hr);
348 ok(stereo_buffer == backbuffer, "Expected unknown buffer = %p, got %p.\n", backbuffer, stereo_buffer);
349 IDirect3DSurface8_Release(stereo_buffer);
351 backbuffer = (void *) 0xdeadbeef;
352 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 1, 0, &backbuffer);
353 ok(SUCCEEDED(hr), "Failed to get the 2nd back buffer (%#08x)\n", hr);
354 ok(backbuffer != NULL && backbuffer != (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer);
355 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
357 backbuffer = (void *) 0xdeadbeef;
358 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 2, 0, &backbuffer);
359 ok(hr == D3DERR_INVALIDCALL, "GetBackBuffer returned %#08x\n", hr);
360 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
361 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
363 backbuffer = (void *) 0xdeadbeef;
364 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain3, 3, 0, &backbuffer);
365 ok(FAILED(hr), "Failed to get the back buffer (%#08x)\n", hr);
366 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
367 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
370 /* Check the back buffers of the swapchains */
371 /* Swapchain 1, created with backbuffercount 0 */
372 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain1, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
373 ok(SUCCEEDED(hr), "Failed to get the back buffer (%#08x)\n", hr);
374 ok(backbuffer != NULL, "The back buffer is NULL (%#08x)\n", hr);
375 if(backbuffer) IDirect3DSurface8_Release(backbuffer);
377 backbuffer = (void *) 0xdeadbeef;
378 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain1, 1, 0, &backbuffer);
379 ok(FAILED(hr), "Failed to get the back buffer (%#08x)\n", hr);
380 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
381 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
383 /* Swapchain 2 - created with backbuffercount 1 */
384 backbuffer = (void *) 0xdeadbeef;
385 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain2, 0, 0, &backbuffer);
386 ok(SUCCEEDED(hr), "Failed to get the back buffer (%#08x)\n", hr);
387 ok(backbuffer != NULL && backbuffer != (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer);
388 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
390 backbuffer = (void *) 0xdeadbeef;
391 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain2, 1, 0, &backbuffer);
392 ok(hr == D3DERR_INVALIDCALL, "GetBackBuffer returned %#08x\n", hr);
393 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
394 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
396 backbuffer = (void *) 0xdeadbeef;
397 hr = IDirect3DSwapChain8_GetBackBuffer(swapchain2, 2, 0, &backbuffer);
398 ok(FAILED(hr), "Failed to get the back buffer (%#08x)\n", hr);
399 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
400 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer);
402 IDirect3DSwapChain8_Release(swapchain3);
403 IDirect3DSwapChain8_Release(swapchain2);
404 IDirect3DSwapChain8_Release(swapchain1);
406 d3dpp.Windowed = FALSE;
407 d3dpp.hDeviceWindow = window;
408 d3dpp.BackBufferCount = 1;
409 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain1);
410 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x\n", hr);
411 d3dpp.hDeviceWindow = window2;
412 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain1);
413 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x\n", hr);
415 device_desc.width = registry_mode.dmPelsWidth;
416 device_desc.height = registry_mode.dmPelsHeight;
417 device_desc.device_window = window;
418 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
419 hr = reset_device(device, &device_desc);
420 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
422 d3dpp.hDeviceWindow = window;
423 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain1);
424 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x\n", hr);
425 d3dpp.hDeviceWindow = window2;
426 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain1);
427 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x\n", hr);
428 d3dpp.Windowed = TRUE;
429 d3dpp.hDeviceWindow = window;
430 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain1);
431 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x\n", hr);
432 d3dpp.hDeviceWindow = window2;
433 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &swapchain1);
434 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x\n", hr);
436 refcount = IDirect3DDevice8_Release(device);
437 ok(!refcount, "Device has %u references left.\n", refcount);
438 cleanup:
439 IDirect3D8_Release(d3d);
440 DestroyWindow(window2);
441 DestroyWindow(window);
444 static void test_refcount(void)
446 IDirect3DVertexBuffer8 *pVertexBuffer = NULL;
447 IDirect3DIndexBuffer8 *pIndexBuffer = NULL;
448 DWORD dVertexShader = -1;
449 DWORD dPixelShader = -1;
450 IDirect3DCubeTexture8 *pCubeTexture = NULL;
451 IDirect3DTexture8 *pTexture = NULL;
452 IDirect3DVolumeTexture8 *pVolumeTexture = NULL;
453 IDirect3DVolume8 *pVolumeLevel = NULL;
454 IDirect3DSurface8 *pStencilSurface = NULL;
455 IDirect3DSurface8 *pImageSurface = NULL;
456 IDirect3DSurface8 *pRenderTarget = NULL;
457 IDirect3DSurface8 *pRenderTarget2 = NULL;
458 IDirect3DSurface8 *pRenderTarget3 = NULL;
459 IDirect3DSurface8 *pTextureLevel = NULL;
460 IDirect3DSurface8 *pBackBuffer = NULL;
461 DWORD dStateBlock = -1;
462 IDirect3DSwapChain8 *pSwapChain = NULL;
463 D3DCAPS8 caps;
464 D3DPRESENT_PARAMETERS d3dpp;
465 IDirect3DDevice8 *device = NULL;
466 ULONG refcount = 0, tmp;
467 IDirect3D8 *d3d, *d3d2;
468 HWND window;
469 HRESULT hr;
471 DWORD decl[] =
473 D3DVSD_STREAM(0),
474 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
475 D3DVSD_REG(D3DVSDE_DIFFUSE, D3DVSDT_D3DCOLOR), /* D3DVSDE_DIFFUSE, Register v5 */
476 D3DVSD_END()
479 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
480 0, 0, 640, 480, NULL, NULL, NULL, NULL);
481 ok(!!window, "Failed to create a window.\n");
482 d3d = Direct3DCreate8(D3D_SDK_VERSION);
483 ok(!!d3d, "Failed to create a D3D object.\n");
485 CHECK_REFCOUNT(d3d, 1);
487 if (!(device = create_device(d3d, window, NULL)))
489 skip("Failed to create a 3D device, skipping test.\n");
490 goto cleanup;
493 IDirect3DDevice8_GetDeviceCaps(device, &caps);
495 refcount = get_refcount((IUnknown *)device);
496 ok(refcount == 1, "Invalid device RefCount %d\n", refcount);
498 CHECK_REFCOUNT(d3d, 2);
500 hr = IDirect3DDevice8_GetDirect3D(device, &d3d2);
501 CHECK_CALL(hr, "GetDirect3D", device, refcount);
503 ok(d3d2 == d3d, "Expected IDirect3D8 pointers to be equal.\n");
504 CHECK_REFCOUNT(d3d, 3);
505 CHECK_RELEASE_REFCOUNT(d3d, 2);
508 * Check refcount of implicit surfaces. Findings:
509 * - the container is the device
510 * - they hold a reference to the device
511 * - they are created with a refcount of 0 (Get/Release returns original refcount)
512 * - they are not freed if refcount reaches 0.
513 * - the refcount is not forwarded to the container.
515 hr = IDirect3DDevice8_GetRenderTarget(device, &pRenderTarget);
516 CHECK_CALL(hr, "GetRenderTarget", device, ++refcount);
517 if(pRenderTarget)
519 CHECK_SURFACE_CONTAINER(pRenderTarget, IID_IDirect3DDevice8, device);
520 CHECK_REFCOUNT( pRenderTarget, 1);
522 CHECK_ADDREF_REFCOUNT(pRenderTarget, 2);
523 CHECK_REFCOUNT(device, refcount);
524 CHECK_RELEASE_REFCOUNT(pRenderTarget, 1);
525 CHECK_REFCOUNT(device, refcount);
527 hr = IDirect3DDevice8_GetRenderTarget(device, &pRenderTarget);
528 CHECK_CALL(hr, "GetRenderTarget", device, refcount);
529 CHECK_REFCOUNT( pRenderTarget, 2);
530 CHECK_RELEASE_REFCOUNT( pRenderTarget, 1);
531 CHECK_RELEASE_REFCOUNT( pRenderTarget, 0);
532 CHECK_REFCOUNT(device, --refcount);
534 /* The render target is released with the device, so AddRef with refcount=0 is fine here. */
535 CHECK_ADDREF_REFCOUNT(pRenderTarget, 1);
536 CHECK_REFCOUNT(device, ++refcount);
537 CHECK_RELEASE_REFCOUNT(pRenderTarget, 0);
538 CHECK_REFCOUNT(device, --refcount);
541 /* Render target and back buffer are identical. */
542 hr = IDirect3DDevice8_GetBackBuffer(device, 0, 0, &pBackBuffer);
543 CHECK_CALL(hr, "GetBackBuffer", device, ++refcount);
544 if(pBackBuffer)
546 CHECK_RELEASE_REFCOUNT(pBackBuffer, 0);
547 ok(pRenderTarget == pBackBuffer, "RenderTarget=%p and BackBuffer=%p should be the same.\n",
548 pRenderTarget, pBackBuffer);
549 pBackBuffer = NULL;
551 CHECK_REFCOUNT(device, --refcount);
553 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &pStencilSurface);
554 CHECK_CALL(hr, "GetDepthStencilSurface", device, ++refcount);
555 if(pStencilSurface)
557 CHECK_SURFACE_CONTAINER(pStencilSurface, IID_IDirect3DDevice8, device);
558 CHECK_REFCOUNT( pStencilSurface, 1);
560 CHECK_ADDREF_REFCOUNT(pStencilSurface, 2);
561 CHECK_REFCOUNT(device, refcount);
562 CHECK_RELEASE_REFCOUNT(pStencilSurface, 1);
563 CHECK_REFCOUNT(device, refcount);
565 CHECK_RELEASE_REFCOUNT( pStencilSurface, 0);
566 CHECK_REFCOUNT(device, --refcount);
568 /* The stencil surface is released with the device, so AddRef with refcount=0 is fine here. */
569 CHECK_ADDREF_REFCOUNT(pStencilSurface, 1);
570 CHECK_REFCOUNT(device, ++refcount);
571 CHECK_RELEASE_REFCOUNT(pStencilSurface, 0);
572 CHECK_REFCOUNT(device, --refcount);
573 pStencilSurface = NULL;
576 /* Buffers */
577 hr = IDirect3DDevice8_CreateIndexBuffer(device, 16, 0, D3DFMT_INDEX32, D3DPOOL_DEFAULT, &pIndexBuffer);
578 CHECK_CALL(hr, "CreateIndexBuffer", device, ++refcount);
579 if(pIndexBuffer)
581 tmp = get_refcount( (IUnknown *)pIndexBuffer );
583 hr = IDirect3DDevice8_SetIndices(device, pIndexBuffer, 0);
584 CHECK_CALL( hr, "SetIndices", pIndexBuffer, tmp);
585 hr = IDirect3DDevice8_SetIndices(device, NULL, 0);
586 CHECK_CALL( hr, "SetIndices", pIndexBuffer, tmp);
589 hr = IDirect3DDevice8_CreateVertexBuffer(device, 16, 0, D3DFVF_XYZ, D3DPOOL_DEFAULT, &pVertexBuffer);
590 CHECK_CALL(hr, "CreateVertexBuffer", device, ++refcount);
591 if(pVertexBuffer)
593 IDirect3DVertexBuffer8 *pVBuf = (void*)~0;
594 UINT stride = ~0;
596 tmp = get_refcount( (IUnknown *)pVertexBuffer );
598 hr = IDirect3DDevice8_SetStreamSource(device, 0, pVertexBuffer, 3 * sizeof(float));
599 CHECK_CALL( hr, "SetStreamSource", pVertexBuffer, tmp);
600 hr = IDirect3DDevice8_SetStreamSource(device, 0, NULL, 0);
601 CHECK_CALL( hr, "SetStreamSource", pVertexBuffer, tmp);
603 hr = IDirect3DDevice8_GetStreamSource(device, 0, &pVBuf, &stride);
604 ok(SUCCEEDED(hr), "GetStreamSource did not succeed with NULL stream!\n");
605 ok(pVBuf==NULL, "pVBuf not NULL (%p)!\n", pVBuf);
606 ok(stride==3*sizeof(float), "stride not 3 floats (got %u)!\n", stride);
609 /* Shaders */
610 hr = IDirect3DDevice8_CreateVertexShader(device, decl, simple_vs, &dVertexShader, 0);
611 CHECK_CALL(hr, "CreateVertexShader", device, refcount);
612 if (caps.PixelShaderVersion >= D3DPS_VERSION(1, 0))
614 hr = IDirect3DDevice8_CreatePixelShader(device, simple_ps, &dPixelShader);
615 CHECK_CALL(hr, "CreatePixelShader", device, refcount);
617 /* Textures */
618 hr = IDirect3DDevice8_CreateTexture(device, 32, 32, 3, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pTexture);
619 CHECK_CALL(hr, "CreateTexture", device, ++refcount);
620 if (pTexture)
622 tmp = get_refcount( (IUnknown *)pTexture );
624 /* SetTexture should not increase refcounts */
625 hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *) pTexture);
626 CHECK_CALL( hr, "SetTexture", pTexture, tmp);
627 hr = IDirect3DDevice8_SetTexture(device, 0, NULL);
628 CHECK_CALL( hr, "SetTexture", pTexture, tmp);
630 /* This should not increment device refcount */
631 hr = IDirect3DTexture8_GetSurfaceLevel( pTexture, 1, &pTextureLevel );
632 CHECK_CALL(hr, "GetSurfaceLevel", device, refcount);
633 /* But should increment texture's refcount */
634 CHECK_REFCOUNT( pTexture, tmp+1 );
635 /* Because the texture and surface refcount are identical */
636 if (pTextureLevel)
638 CHECK_REFCOUNT ( pTextureLevel, tmp+1 );
639 CHECK_ADDREF_REFCOUNT ( pTextureLevel, tmp+2 );
640 CHECK_REFCOUNT ( pTexture , tmp+2 );
641 CHECK_RELEASE_REFCOUNT( pTextureLevel, tmp+1 );
642 CHECK_REFCOUNT ( pTexture , tmp+1 );
643 CHECK_RELEASE_REFCOUNT( pTexture , tmp );
644 CHECK_REFCOUNT ( pTextureLevel, tmp );
647 if(caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP)
649 hr = IDirect3DDevice8_CreateCubeTexture(device, 32, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pCubeTexture);
650 CHECK_CALL(hr, "CreateCubeTexture", device, ++refcount);
652 else
654 skip("Cube textures not supported\n");
656 if(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP)
658 hr = IDirect3DDevice8_CreateVolumeTexture(device, 32, 32, 2, 0, 0,
659 D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pVolumeTexture);
660 CHECK_CALL(hr, "CreateVolumeTexture", device, ++refcount);
662 else
664 skip("Volume textures not supported\n");
667 if (pVolumeTexture)
669 tmp = get_refcount( (IUnknown *)pVolumeTexture );
671 /* This should not increment device refcount */
672 hr = IDirect3DVolumeTexture8_GetVolumeLevel(pVolumeTexture, 0, &pVolumeLevel);
673 CHECK_CALL(hr, "GetVolumeLevel", device, refcount);
674 /* But should increment volume texture's refcount */
675 CHECK_REFCOUNT( pVolumeTexture, tmp+1 );
676 /* Because the volume texture and volume refcount are identical */
677 if (pVolumeLevel)
679 CHECK_REFCOUNT ( pVolumeLevel , tmp+1 );
680 CHECK_ADDREF_REFCOUNT ( pVolumeLevel , tmp+2 );
681 CHECK_REFCOUNT ( pVolumeTexture, tmp+2 );
682 CHECK_RELEASE_REFCOUNT( pVolumeLevel , tmp+1 );
683 CHECK_REFCOUNT ( pVolumeTexture, tmp+1 );
684 CHECK_RELEASE_REFCOUNT( pVolumeTexture, tmp );
685 CHECK_REFCOUNT ( pVolumeLevel , tmp );
688 /* Surfaces */
689 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 32, 32,
690 D3DFMT_D16, D3DMULTISAMPLE_NONE, &pStencilSurface);
691 CHECK_CALL(hr, "CreateDepthStencilSurface", device, ++refcount);
692 CHECK_REFCOUNT( pStencilSurface, 1);
693 hr = IDirect3DDevice8_CreateImageSurface(device, 32, 32,
694 D3DFMT_X8R8G8B8, &pImageSurface);
695 CHECK_CALL(hr, "CreateImageSurface", device, ++refcount);
696 CHECK_REFCOUNT( pImageSurface, 1);
697 hr = IDirect3DDevice8_CreateRenderTarget(device, 32, 32,
698 D3DFMT_X8R8G8B8, D3DMULTISAMPLE_NONE, TRUE, &pRenderTarget3);
699 CHECK_CALL(hr, "CreateRenderTarget", device, ++refcount);
700 CHECK_REFCOUNT( pRenderTarget3, 1);
701 /* Misc */
702 hr = IDirect3DDevice8_CreateStateBlock(device, D3DSBT_ALL, &dStateBlock);
703 CHECK_CALL(hr, "CreateStateBlock", device, refcount);
705 memset(&d3dpp, 0, sizeof(d3dpp));
706 d3dpp.Windowed = TRUE;
707 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
708 d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
709 d3dpp.EnableAutoDepthStencil = TRUE;
710 d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
711 hr = IDirect3DDevice8_CreateAdditionalSwapChain(device, &d3dpp, &pSwapChain);
712 CHECK_CALL(hr, "CreateAdditionalSwapChain", device, ++refcount);
713 if(pSwapChain)
715 /* check implicit back buffer */
716 hr = IDirect3DSwapChain8_GetBackBuffer(pSwapChain, 0, 0, &pBackBuffer);
717 CHECK_CALL(hr, "GetBackBuffer", device, ++refcount);
718 CHECK_REFCOUNT( pSwapChain, 1);
719 if(pBackBuffer)
721 CHECK_SURFACE_CONTAINER(pBackBuffer, IID_IDirect3DDevice8, device);
722 CHECK_REFCOUNT( pBackBuffer, 1);
723 CHECK_RELEASE_REFCOUNT( pBackBuffer, 0);
724 CHECK_REFCOUNT(device, --refcount);
726 /* The back buffer is released with the swapchain, so AddRef with refcount=0 is fine here. */
727 CHECK_ADDREF_REFCOUNT(pBackBuffer, 1);
728 CHECK_REFCOUNT(device, ++refcount);
729 CHECK_RELEASE_REFCOUNT(pBackBuffer, 0);
730 CHECK_REFCOUNT(device, --refcount);
731 pBackBuffer = NULL;
733 CHECK_REFCOUNT( pSwapChain, 1);
736 if(pVertexBuffer)
738 BYTE *data;
739 /* Vertex buffers can be locked multiple times */
740 hr = IDirect3DVertexBuffer8_Lock(pVertexBuffer, 0, 0, &data, 0);
741 ok(hr == D3D_OK, "IDirect3DVertexBuffer8::Lock failed with %#08x\n", hr);
742 hr = IDirect3DVertexBuffer8_Lock(pVertexBuffer, 0, 0, &data, 0);
743 ok(hr == D3D_OK, "IDirect3DVertexBuffer8::Lock failed with %#08x\n", hr);
744 hr = IDirect3DVertexBuffer8_Unlock(pVertexBuffer);
745 ok(hr == D3D_OK, "IDirect3DVertexBuffer8::Unlock failed with %#08x\n", hr);
746 hr = IDirect3DVertexBuffer8_Unlock(pVertexBuffer);
747 ok(hr == D3D_OK, "IDirect3DVertexBuffer8::Unlock failed with %#08x\n", hr);
750 /* The implicit render target is not freed if refcount reaches 0.
751 * Otherwise GetRenderTarget would re-allocate it and the pointer would change.*/
752 hr = IDirect3DDevice8_GetRenderTarget(device, &pRenderTarget2);
753 CHECK_CALL(hr, "GetRenderTarget", device, ++refcount);
754 if(pRenderTarget2)
756 CHECK_RELEASE_REFCOUNT(pRenderTarget2, 0);
757 ok(pRenderTarget == pRenderTarget2, "RenderTarget=%p and RenderTarget2=%p should be the same.\n",
758 pRenderTarget, pRenderTarget2);
759 CHECK_REFCOUNT(device, --refcount);
760 pRenderTarget2 = NULL;
762 pRenderTarget = NULL;
764 cleanup:
765 CHECK_RELEASE(device, device, --refcount);
767 /* Buffers */
768 CHECK_RELEASE(pVertexBuffer, device, --refcount);
769 CHECK_RELEASE(pIndexBuffer, device, --refcount);
770 /* Shaders */
771 if (dVertexShader != ~0u)
772 IDirect3DDevice8_DeleteVertexShader(device, dVertexShader);
773 if (dPixelShader != ~0u)
774 IDirect3DDevice8_DeletePixelShader(device, dPixelShader);
775 /* Textures */
776 CHECK_RELEASE(pTexture, device, --refcount);
777 CHECK_RELEASE(pCubeTexture, device, --refcount);
778 CHECK_RELEASE(pVolumeTexture, device, --refcount);
779 /* Surfaces */
780 CHECK_RELEASE(pStencilSurface, device, --refcount);
781 CHECK_RELEASE(pImageSurface, device, --refcount);
782 CHECK_RELEASE(pRenderTarget3, device, --refcount);
783 /* Misc */
784 if (dStateBlock != ~0u)
785 IDirect3DDevice8_DeleteStateBlock(device, dStateBlock);
786 /* This will destroy device - cannot check the refcount here */
787 if (pSwapChain)
788 CHECK_RELEASE_REFCOUNT(pSwapChain, 0);
789 CHECK_RELEASE_REFCOUNT(d3d, 0);
790 DestroyWindow(window);
793 static void test_checkdevicemultisampletype(void)
795 IDirect3D8 *d3d;
796 HWND window;
797 HRESULT hr;
799 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
800 0, 0, 640, 480, NULL, NULL, NULL, NULL);
801 ok(!!window, "Failed to create a window.\n");
802 d3d = Direct3DCreate8(D3D_SDK_VERSION);
803 ok(!!d3d, "Failed to create a D3D object.\n");
805 if (IDirect3D8_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
806 D3DFMT_X8R8G8B8, TRUE, D3DMULTISAMPLE_2_SAMPLES) == D3DERR_NOTAVAILABLE)
808 skip("Multisampling not supported for D3DFMT_X8R8G8B8, skipping test.\n");
809 goto cleanup;
812 hr = IDirect3D8_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
813 D3DFMT_UNKNOWN, TRUE, D3DMULTISAMPLE_NONE);
814 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
815 hr = IDirect3D8_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
816 65536, TRUE, D3DMULTISAMPLE_NONE);
817 todo_wine ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
819 hr = IDirect3D8_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
820 D3DFMT_X8R8G8B8, TRUE, D3DMULTISAMPLE_NONE);
821 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
822 hr = IDirect3D8_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
823 D3DFMT_X8R8G8B8, FALSE, D3DMULTISAMPLE_NONE);
824 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
826 hr = IDirect3D8_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
827 D3DFMT_X8R8G8B8, TRUE, D3DMULTISAMPLE_2_SAMPLES);
828 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
830 /* We assume D3DMULTISAMPLE_15_SAMPLES is never supported in practice. */
831 hr = IDirect3D8_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
832 D3DFMT_X8R8G8B8, TRUE, D3DMULTISAMPLE_15_SAMPLES);
833 ok(hr == D3DERR_NOTAVAILABLE, "Got unexpected hr %#x.\n", hr);
835 hr = IDirect3D8_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
836 D3DFMT_X8R8G8B8, TRUE, 65536);
837 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
839 hr = IDirect3D8_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
840 D3DFMT_DXT5, TRUE, D3DMULTISAMPLE_2_SAMPLES);
841 ok(hr == D3DERR_NOTAVAILABLE, "Got unexpected hr %#x.\n", hr);
843 cleanup:
844 IDirect3D8_Release(d3d);
845 DestroyWindow(window);
848 static void test_invalid_multisample(void)
850 IDirect3DDevice8 *device;
851 IDirect3DSurface8 *rt;
852 IDirect3D8 *d3d;
853 BOOL available;
854 ULONG refcount;
855 HWND window;
856 HRESULT hr;
858 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
859 0, 0, 640, 480, NULL, NULL, NULL, NULL);
860 ok(!!window, "Failed to create a window.\n");
861 d3d = Direct3DCreate8(D3D_SDK_VERSION);
862 ok(!!d3d, "Failed to create a D3D object.\n");
864 if (!(device = create_device(d3d, window, NULL)))
866 skip("Failed to create a 3D device, skipping test.\n");
867 goto cleanup;
870 available = SUCCEEDED(IDirect3D8_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
871 D3DFMT_X8R8G8B8, TRUE, D3DMULTISAMPLE_2_SAMPLES));
873 hr = IDirect3DDevice8_CreateRenderTarget(device, 128, 128,
874 D3DFMT_X8R8G8B8, D3DMULTISAMPLE_2_SAMPLES, FALSE, &rt);
875 if (available)
877 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
878 IDirect3DSurface8_Release(rt);
880 else
882 ok(hr == D3DERR_NOTAVAILABLE, "Got unexpected hr %#x.\n", hr);
885 /* We assume D3DMULTISAMPLE_15_SAMPLES is never supported in practice. */
886 available = SUCCEEDED(IDirect3D8_CheckDeviceMultiSampleType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
887 D3DFMT_X8R8G8B8, TRUE, D3DMULTISAMPLE_15_SAMPLES));
888 hr = IDirect3DDevice8_CreateRenderTarget(device, 128, 128,
889 D3DFMT_X8R8G8B8, D3DMULTISAMPLE_15_SAMPLES, FALSE, &rt);
890 if (available)
892 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
893 IDirect3DSurface8_Release(rt);
895 else
897 ok(hr == D3DERR_NOTAVAILABLE, "Got unexpected hr %#x.\n", hr);
900 refcount = IDirect3DDevice8_Release(device);
901 ok(!refcount, "Device has %u references left.\n", refcount);
902 cleanup:
903 IDirect3D8_Release(d3d);
904 DestroyWindow(window);
907 static void test_cursor(void)
909 HMODULE user32_handle = GetModuleHandleA("user32.dll");
910 IDirect3DSurface8 *cursor = NULL;
911 IDirect3DDevice8 *device;
912 CURSORINFO info;
913 IDirect3D8 *d3d;
914 ULONG refcount;
915 HCURSOR cur;
916 HWND window;
917 HRESULT hr;
918 BOOL ret;
920 pGetCursorInfo = (void *)GetProcAddress(user32_handle, "GetCursorInfo");
921 if (!pGetCursorInfo)
923 win_skip("GetCursorInfo is not available\n");
924 return;
927 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
928 0, 0, 640, 480, NULL, NULL, NULL, NULL);
929 ok(!!window, "Failed to create a window.\n");
931 ret = SetCursorPos(50, 50);
932 ok(ret, "Failed to set cursor position.\n");
933 flush_events();
935 memset(&info, 0, sizeof(info));
936 info.cbSize = sizeof(info);
937 ok(pGetCursorInfo(&info), "GetCursorInfo failed\n");
938 cur = info.hCursor;
940 d3d = Direct3DCreate8(D3D_SDK_VERSION);
941 ok(!!d3d, "Failed to create a D3D object.\n");
942 if (!(device = create_device(d3d, window, NULL)))
944 skip("Failed to create a 3D device, skipping test.\n");
945 goto cleanup;
948 hr = IDirect3DDevice8_CreateImageSurface(device, 32, 32, D3DFMT_A8R8G8B8, &cursor);
949 ok(SUCCEEDED(hr), "Failed to create cursor surface, hr %#x.\n", hr);
951 /* Initially hidden */
952 ret = IDirect3DDevice8_ShowCursor(device, TRUE);
953 ok(!ret, "IDirect3DDevice8_ShowCursor returned %d\n", ret);
955 /* Not enabled without a surface*/
956 ret = IDirect3DDevice8_ShowCursor(device, TRUE);
957 ok(!ret, "IDirect3DDevice8_ShowCursor returned %d\n", ret);
959 /* Fails */
960 hr = IDirect3DDevice8_SetCursorProperties(device, 0, 0, NULL);
961 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_SetCursorProperties returned %#08x\n", hr);
963 hr = IDirect3DDevice8_SetCursorProperties(device, 0, 0, cursor);
964 ok(hr == D3D_OK, "IDirect3DDevice8_SetCursorProperties returned %#08x\n", hr);
966 IDirect3DSurface8_Release(cursor);
968 memset(&info, 0, sizeof(info));
969 info.cbSize = sizeof(info);
970 ok(pGetCursorInfo(&info), "GetCursorInfo failed\n");
971 ok(info.flags & (CURSOR_SHOWING|CURSOR_SUPPRESSED), "The gdi cursor is hidden (%08x)\n", info.flags);
972 ok(info.hCursor == cur, "The cursor handle is %p\n", info.hCursor); /* unchanged */
974 /* Still hidden */
975 ret = IDirect3DDevice8_ShowCursor(device, TRUE);
976 ok(!ret, "IDirect3DDevice8_ShowCursor returned %d\n", ret);
978 /* Enabled now*/
979 ret = IDirect3DDevice8_ShowCursor(device, TRUE);
980 ok(ret, "IDirect3DDevice8_ShowCursor returned %d\n", ret);
982 memset(&info, 0, sizeof(info));
983 info.cbSize = sizeof(info);
984 ok(pGetCursorInfo(&info), "GetCursorInfo failed\n");
985 ok(info.flags & (CURSOR_SHOWING|CURSOR_SUPPRESSED), "The gdi cursor is hidden (%08x)\n", info.flags);
986 ok(info.hCursor != cur, "The cursor handle is %p\n", info.hCursor);
988 refcount = IDirect3DDevice8_Release(device);
989 ok(!refcount, "Device has %u references left.\n", refcount);
990 cleanup:
991 IDirect3D8_Release(d3d);
992 DestroyWindow(window);
995 static const POINT *expect_pos;
997 static LRESULT CALLBACK test_cursor_proc(HWND window, UINT message, WPARAM wparam, LPARAM lparam)
999 if (message == WM_MOUSEMOVE)
1001 if (expect_pos && expect_pos->x && expect_pos->y)
1003 POINT p = {GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam)};
1005 ClientToScreen(window, &p);
1006 if (expect_pos->x == p.x && expect_pos->y == p.y)
1007 ++expect_pos;
1011 return DefWindowProcA(window, message, wparam, lparam);
1014 static void test_cursor_pos(void)
1016 IDirect3DSurface8 *cursor;
1017 IDirect3DDevice8 *device;
1018 WNDCLASSA wc = {0};
1019 IDirect3D8 *d3d8;
1020 UINT refcount;
1021 HWND window;
1022 HRESULT hr;
1023 BOOL ret;
1025 /* Note that we don't check for movement we're not supposed to receive.
1026 * That's because it's hard to distinguish from the user accidentally
1027 * moving the mouse. */
1028 static const POINT points[] =
1030 {50, 50},
1031 {75, 75},
1032 {100, 100},
1033 {125, 125},
1034 {150, 150},
1035 {125, 125},
1036 {150, 150},
1037 {150, 150},
1038 {0, 0},
1041 wc.lpfnWndProc = test_cursor_proc;
1042 wc.lpszClassName = "d3d8_test_cursor_wc";
1043 ok(RegisterClassA(&wc), "Failed to register window class.\n");
1044 window = CreateWindowA("d3d8_test_cursor_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
1045 0, 0, 320, 240, NULL, NULL, NULL, NULL);
1046 ShowWindow(window, SW_SHOW);
1047 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
1048 ok(!!d3d8, "Failed to create a D3D object.\n");
1050 if (!(device = create_device(d3d8, window, NULL)))
1052 skip("Failed to create a D3D device, skipping tests.\n");
1053 goto done;
1056 hr = IDirect3DDevice8_CreateImageSurface(device, 32, 32, D3DFMT_A8R8G8B8, &cursor);
1057 ok(SUCCEEDED(hr), "Failed to create cursor surface, hr %#x.\n", hr);
1058 hr = IDirect3DDevice8_SetCursorProperties(device, 0, 0, cursor);
1059 ok(SUCCEEDED(hr), "Failed to set cursor properties, hr %#x.\n", hr);
1060 IDirect3DSurface8_Release(cursor);
1061 ret = IDirect3DDevice8_ShowCursor(device, TRUE);
1062 ok(!ret, "Failed to show cursor, hr %#x.\n", ret);
1064 flush_events();
1065 expect_pos = points;
1067 ret = SetCursorPos(50, 50);
1068 ok(ret, "Failed to set cursor position.\n");
1069 flush_events();
1071 IDirect3DDevice8_SetCursorPosition(device, 75, 75, 0);
1072 flush_events();
1073 /* SetCursorPosition() eats duplicates. */
1074 IDirect3DDevice8_SetCursorPosition(device, 75, 75, 0);
1075 flush_events();
1077 ret = SetCursorPos(100, 100);
1078 ok(ret, "Failed to set cursor position.\n");
1079 flush_events();
1080 /* Even if the position was set with SetCursorPos(). */
1081 IDirect3DDevice8_SetCursorPosition(device, 100, 100, 0);
1082 flush_events();
1084 IDirect3DDevice8_SetCursorPosition(device, 125, 125, 0);
1085 flush_events();
1086 ret = SetCursorPos(150, 150);
1087 ok(ret, "Failed to set cursor position.\n");
1088 flush_events();
1089 IDirect3DDevice8_SetCursorPosition(device, 125, 125, 0);
1090 flush_events();
1092 IDirect3DDevice8_SetCursorPosition(device, 150, 150, 0);
1093 flush_events();
1094 /* SetCursorPos() doesn't. */
1095 ret = SetCursorPos(150, 150);
1096 ok(ret, "Failed to set cursor position.\n");
1097 flush_events();
1099 ok(!expect_pos->x && !expect_pos->y, "Didn't receive MOUSEMOVE %u (%d, %d).\n",
1100 (unsigned)(expect_pos - points), expect_pos->x, expect_pos->y);
1102 refcount = IDirect3DDevice8_Release(device);
1103 ok(!refcount, "Device has %u references left.\n", refcount);
1104 done:
1105 DestroyWindow(window);
1106 UnregisterClassA("d3d8_test_cursor_wc", GetModuleHandleA(NULL));
1107 IDirect3D8_Release(d3d8);
1110 static void test_states(void)
1112 IDirect3DDevice8 *device;
1113 IDirect3D8 *d3d;
1114 ULONG refcount;
1115 HWND window;
1116 HRESULT hr;
1118 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
1119 0, 0, 640, 480, NULL, NULL, NULL, NULL);
1120 ok(!!window, "Failed to create a window.\n");
1121 d3d = Direct3DCreate8(D3D_SDK_VERSION);
1122 ok(!!d3d, "Failed to create a D3D object.\n");
1123 if (!(device = create_device(d3d, window, NULL)))
1125 skip("Failed to create a 3D device, skipping test.\n");
1126 goto cleanup;
1129 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZVISIBLE, TRUE);
1130 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState(D3DRS_ZVISIBLE, TRUE) returned %#08x\n", hr);
1131 hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZVISIBLE, FALSE);
1132 ok(hr == D3D_OK, "IDirect3DDevice8_SetRenderState(D3DRS_ZVISIBLE, FALSE) returned %#08x\n", hr);
1134 refcount = IDirect3DDevice8_Release(device);
1135 ok(!refcount, "Device has %u references left.\n", refcount);
1136 cleanup:
1137 IDirect3D8_Release(d3d);
1138 DestroyWindow(window);
1141 static void test_shader_versions(void)
1143 IDirect3D8 *d3d;
1144 D3DCAPS8 caps;
1145 HRESULT hr;
1147 d3d = Direct3DCreate8(D3D_SDK_VERSION);
1148 ok(!!d3d, "Failed to create a D3D object.\n");
1150 hr = IDirect3D8_GetDeviceCaps(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps);
1151 ok(SUCCEEDED(hr) || hr == D3DERR_NOTAVAILABLE, "Failed to get device caps, hr %#x.\n", hr);
1152 IDirect3D8_Release(d3d);
1153 if (FAILED(hr))
1155 skip("No Direct3D support, skipping test.\n");
1156 return;
1159 ok(caps.VertexShaderVersion <= D3DVS_VERSION(1,1),
1160 "Got unexpected VertexShaderVersion %#x.\n", caps.VertexShaderVersion);
1161 ok(caps.PixelShaderVersion <= D3DPS_VERSION(1,4),
1162 "Got unexpected PixelShaderVersion %#x.\n", caps.PixelShaderVersion);
1165 static void test_display_formats(void)
1167 D3DDEVTYPE device_type = D3DDEVTYPE_HAL;
1168 unsigned int backbuffer, display;
1169 unsigned int windowed, i;
1170 D3DDISPLAYMODE mode;
1171 IDirect3D8 *d3d8;
1172 BOOL should_pass;
1173 BOOL has_modes;
1174 HRESULT hr;
1176 static const struct
1178 const char *name;
1179 D3DFORMAT format;
1180 D3DFORMAT alpha_format;
1181 BOOL display;
1182 BOOL windowed;
1184 formats[] =
1186 {"D3DFMT_R5G6B5", D3DFMT_R5G6B5, 0, TRUE, TRUE},
1187 {"D3DFMT_X1R5G5B5", D3DFMT_X1R5G5B5, D3DFMT_A1R5G5B5, TRUE, TRUE},
1188 {"D3DFMT_A1R5G5B5", D3DFMT_A1R5G5B5, D3DFMT_A1R5G5B5, FALSE, FALSE},
1189 {"D3DFMT_X8R8G8B8", D3DFMT_X8R8G8B8, D3DFMT_A8R8G8B8, TRUE, TRUE},
1190 {"D3DFMT_A8R8G8B8", D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, FALSE, FALSE},
1191 {"D3DFMT_UNKNOWN", D3DFMT_UNKNOWN, 0, FALSE, FALSE},
1194 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
1195 ok(!!d3d8, "Failed to create a D3D object.\n");
1197 for (display = 0; display < sizeof(formats) / sizeof(*formats); ++display)
1199 for (i = 0, has_modes = FALSE; SUCCEEDED(IDirect3D8_EnumAdapterModes(d3d8, D3DADAPTER_DEFAULT, i, &mode)); ++i)
1201 if (mode.Format == formats[display].format)
1203 has_modes = TRUE;
1204 break;
1208 for (windowed = 0; windowed <= 1; ++windowed)
1210 for (backbuffer = 0; backbuffer < sizeof(formats) / sizeof(*formats); ++backbuffer)
1212 should_pass = FALSE;
1214 if (formats[display].display && (formats[display].windowed || !windowed) && (has_modes || windowed))
1216 D3DFORMAT backbuffer_format;
1218 if (windowed && formats[backbuffer].format == D3DFMT_UNKNOWN)
1219 backbuffer_format = formats[display].format;
1220 else
1221 backbuffer_format = formats[backbuffer].format;
1223 hr = IDirect3D8_CheckDeviceFormat(d3d8, D3DADAPTER_DEFAULT, device_type, formats[display].format,
1224 D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, backbuffer_format);
1225 should_pass = (hr == D3D_OK) && (formats[display].format == formats[backbuffer].format
1226 || (formats[display].alpha_format
1227 && formats[display].alpha_format == formats[backbuffer].alpha_format));
1230 hr = IDirect3D8_CheckDeviceType(d3d8, D3DADAPTER_DEFAULT, device_type,
1231 formats[display].format, formats[backbuffer].format, windowed);
1232 ok(SUCCEEDED(hr) == should_pass || broken(SUCCEEDED(hr) && !has_modes) /* Win8 64-bit */,
1233 "Got unexpected hr %#x for %s / %s, windowed %#x, should_pass %#x.\n",
1234 hr, formats[display].name, formats[backbuffer].name, windowed, should_pass);
1239 IDirect3D8_Release(d3d8);
1242 /* Test adapter display modes */
1243 static void test_display_modes(void)
1245 UINT max_modes, i;
1246 D3DDISPLAYMODE dmode;
1247 IDirect3D8 *d3d;
1248 HRESULT res;
1250 d3d = Direct3DCreate8(D3D_SDK_VERSION);
1251 ok(!!d3d, "Failed to create a D3D object.\n");
1253 max_modes = IDirect3D8_GetAdapterModeCount(d3d, D3DADAPTER_DEFAULT);
1254 ok(max_modes > 0 ||
1255 broken(max_modes == 0), /* VMware */
1256 "GetAdapterModeCount(D3DADAPTER_DEFAULT) returned 0!\n");
1258 for (i = 0; i < max_modes; ++i)
1260 res = IDirect3D8_EnumAdapterModes(d3d, D3DADAPTER_DEFAULT, i, &dmode);
1261 ok(res==D3D_OK, "EnumAdapterModes returned %#08x for mode %u!\n", res, i);
1262 if(res != D3D_OK)
1263 continue;
1265 ok(dmode.Format==D3DFMT_X8R8G8B8 || dmode.Format==D3DFMT_R5G6B5,
1266 "Unexpected display mode returned for mode %u: %#x\n", i , dmode.Format);
1269 IDirect3D8_Release(d3d);
1272 static void test_reset(void)
1274 UINT width, orig_width = GetSystemMetrics(SM_CXSCREEN);
1275 UINT height, orig_height = GetSystemMetrics(SM_CYSCREEN);
1276 IDirect3DDevice8 *device1 = NULL;
1277 IDirect3DDevice8 *device2 = NULL;
1278 struct device_desc device_desc;
1279 D3DDISPLAYMODE d3ddm, d3ddm2;
1280 D3DSURFACE_DESC surface_desc;
1281 D3DPRESENT_PARAMETERS d3dpp;
1282 IDirect3DSurface8 *surface;
1283 IDirect3DTexture8 *texture;
1284 UINT adapter_mode_count;
1285 D3DLOCKED_RECT lockrect;
1286 UINT mode_count = 0;
1287 IDirect3D8 *d3d8;
1288 RECT winrect;
1289 D3DVIEWPORT8 vp;
1290 D3DCAPS8 caps;
1291 DWORD shader;
1292 DWORD value;
1293 HWND window;
1294 HRESULT hr;
1295 UINT i;
1297 static const DWORD decl[] =
1299 D3DVSD_STREAM(0),
1300 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT4),
1301 D3DVSD_END(),
1304 struct
1306 UINT w;
1307 UINT h;
1308 } *modes = NULL;
1310 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
1311 100, 100, 160, 160, NULL, NULL, NULL, NULL);
1312 ok(!!window, "Failed to create a window.\n");
1313 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
1314 ok(!!d3d8, "Failed to create a D3D object.\n");
1316 hr = IDirect3D8_GetAdapterDisplayMode(d3d8, D3DADAPTER_DEFAULT, &d3ddm);
1317 ok(SUCCEEDED(hr), "GetAdapterDisplayMode failed, hr %#x.\n", hr);
1318 adapter_mode_count = IDirect3D8_GetAdapterModeCount(d3d8, D3DADAPTER_DEFAULT);
1319 modes = HeapAlloc(GetProcessHeap(), 0, sizeof(*modes) * adapter_mode_count);
1320 for (i = 0; i < adapter_mode_count; ++i)
1322 UINT j;
1324 memset(&d3ddm2, 0, sizeof(d3ddm2));
1325 hr = IDirect3D8_EnumAdapterModes(d3d8, D3DADAPTER_DEFAULT, i, &d3ddm2);
1326 ok(SUCCEEDED(hr), "EnumAdapterModes failed, hr %#x.\n", hr);
1328 if (d3ddm2.Format != d3ddm.Format)
1329 continue;
1331 for (j = 0; j < mode_count; ++j)
1333 if (modes[j].w == d3ddm2.Width && modes[j].h == d3ddm2.Height)
1334 break;
1336 if (j == mode_count)
1338 modes[j].w = d3ddm2.Width;
1339 modes[j].h = d3ddm2.Height;
1340 ++mode_count;
1343 /* We use them as invalid modes. */
1344 if ((d3ddm2.Width == 801 && d3ddm2.Height == 600)
1345 || (d3ddm2.Width == 32 && d3ddm2.Height == 32))
1347 skip("This system supports a screen resolution of %dx%d, not running mode tests.\n",
1348 d3ddm2.Width, d3ddm2.Height);
1349 goto cleanup;
1353 if (mode_count < 2)
1355 skip("Less than 2 modes supported, skipping mode tests.\n");
1356 goto cleanup;
1359 i = 0;
1360 if (modes[i].w == orig_width && modes[i].h == orig_height) ++i;
1362 device_desc.width = modes[i].w;
1363 device_desc.height = modes[i].h;
1364 device_desc.device_window = window;
1365 device_desc.flags = CREATE_DEVICE_FULLSCREEN | CREATE_DEVICE_SWVP_ONLY;
1366 if (!(device1 = create_device(d3d8, window, &device_desc)))
1368 skip("Failed to create a D3D device, skipping tests.\n");
1369 goto cleanup;
1371 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1372 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1374 hr = IDirect3DDevice8_GetDeviceCaps(device1, &caps);
1375 ok(SUCCEEDED(hr), "GetDeviceCaps failed, hr %#x.\n", hr);
1377 width = GetSystemMetrics(SM_CXSCREEN);
1378 height = GetSystemMetrics(SM_CYSCREEN);
1379 ok(width == modes[i].w, "Screen width is %u, expected %u.\n", width, modes[i].w);
1380 ok(height == modes[i].h, "Screen height is %u, expected %u.\n", height, modes[i].h);
1382 hr = IDirect3DDevice8_GetViewport(device1, &vp);
1383 ok(SUCCEEDED(hr), "GetViewport failed, hr %#x.\n", hr);
1384 if (SUCCEEDED(hr))
1386 ok(vp.X == 0, "D3DVIEWPORT->X = %u, expected 0.\n", vp.X);
1387 ok(vp.Y == 0, "D3DVIEWPORT->Y = %u, expected 0.\n", vp.Y);
1388 ok(vp.Width == modes[i].w, "D3DVIEWPORT->Width = %u, expected %u.\n", vp.Width, modes[i].w);
1389 ok(vp.Height == modes[i].h, "D3DVIEWPORT->Height = %u, expected %u.\n", vp.Height, modes[i].h);
1390 ok(vp.MinZ == 0, "D3DVIEWPORT->MinZ = %.8e, expected 0.\n", vp.MinZ);
1391 ok(vp.MaxZ == 1, "D3DVIEWPORT->MaxZ = %.8e, expected 1.\n", vp.MaxZ);
1394 i = 1;
1395 vp.X = 10;
1396 vp.Y = 20;
1397 vp.Width = modes[i].w / 2;
1398 vp.Height = modes[i].h / 2;
1399 vp.MinZ = 0.2f;
1400 vp.MaxZ = 0.3f;
1401 hr = IDirect3DDevice8_SetViewport(device1, &vp);
1402 ok(SUCCEEDED(hr), "SetViewport failed, hr %#x.\n", hr);
1404 hr = IDirect3DDevice8_GetRenderState(device1, D3DRS_LIGHTING, &value);
1405 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1406 ok(!!value, "Got unexpected value %#x for D3DRS_LIGHTING.\n", value);
1407 hr = IDirect3DDevice8_SetRenderState(device1, D3DRS_LIGHTING, FALSE);
1408 ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
1410 memset(&d3dpp, 0, sizeof(d3dpp));
1411 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1412 d3dpp.Windowed = FALSE;
1413 d3dpp.BackBufferWidth = modes[i].w;
1414 d3dpp.BackBufferHeight = modes[i].h;
1415 d3dpp.BackBufferFormat = d3ddm.Format;
1416 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1417 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1418 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1419 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1421 hr = IDirect3DDevice8_GetRenderState(device1, D3DRS_LIGHTING, &value);
1422 ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
1423 ok(!!value, "Got unexpected value %#x for D3DRS_LIGHTING.\n", value);
1425 memset(&vp, 0, sizeof(vp));
1426 hr = IDirect3DDevice8_GetViewport(device1, &vp);
1427 ok(SUCCEEDED(hr), "GetViewport failed, hr %#x.\n", hr);
1428 if (SUCCEEDED(hr))
1430 ok(vp.X == 0, "D3DVIEWPORT->X = %u, expected 0.\n", vp.X);
1431 ok(vp.Y == 0, "D3DVIEWPORT->Y = %u, expected 0.\n", vp.Y);
1432 ok(vp.Width == modes[i].w, "D3DVIEWPORT->Width = %u, expected %u.\n", vp.Width, modes[i].w);
1433 ok(vp.Height == modes[i].h, "D3DVIEWPORT->Height = %u, expected %u.\n", vp.Height, modes[i].h);
1434 ok(vp.MinZ == 0, "D3DVIEWPORT->MinZ = %.8e, expected 0.\n", vp.MinZ);
1435 ok(vp.MaxZ == 1, "D3DVIEWPORT->MaxZ = %.8e, expected 1.\n", vp.MaxZ);
1438 width = GetSystemMetrics(SM_CXSCREEN);
1439 height = GetSystemMetrics(SM_CYSCREEN);
1440 ok(width == modes[i].w, "Screen width is %u, expected %u.\n", width, modes[i].w);
1441 ok(height == modes[i].h, "Screen height is %u, expected %u.\n", height, modes[i].h);
1443 hr = IDirect3DDevice8_GetRenderTarget(device1, &surface);
1444 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
1445 hr = IDirect3DSurface8_GetDesc(surface, &surface_desc);
1446 ok(hr == D3D_OK, "GetDesc failed, hr %#x.\n", hr);
1447 ok(surface_desc.Width == modes[i].w, "Back buffer width is %u, expected %u.\n",
1448 surface_desc.Width, modes[i].w);
1449 ok(surface_desc.Height == modes[i].h, "Back buffer height is %u, expected %u.\n",
1450 surface_desc.Height, modes[i].h);
1451 IDirect3DSurface8_Release(surface);
1453 memset(&d3dpp, 0, sizeof(d3dpp));
1454 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1455 d3dpp.Windowed = TRUE;
1456 d3dpp.BackBufferWidth = 400;
1457 d3dpp.BackBufferHeight = 300;
1458 d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
1459 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1460 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1461 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1462 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1464 memset(&vp, 0, sizeof(vp));
1465 hr = IDirect3DDevice8_GetViewport(device1, &vp);
1466 ok(SUCCEEDED(hr), "GetViewport failed, hr %#x.\n", hr);
1467 if (SUCCEEDED(hr))
1469 ok(vp.X == 0, "D3DVIEWPORT->X = %u, expected 0.\n", vp.X);
1470 ok(vp.Y == 0, "D3DVIEWPORT->Y = %u, expected 0.\n", vp.Y);
1471 ok(vp.Width == 400, "D3DVIEWPORT->Width = %u, expected 400.\n", vp.Width);
1472 ok(vp.Height == 300, "D3DVIEWPORT->Height = %u, expected 300.\n", vp.Height);
1473 ok(vp.MinZ == 0, "D3DVIEWPORT->MinZ = %.8e, expected 0.\n", vp.MinZ);
1474 ok(vp.MaxZ == 1, "D3DVIEWPORT->MaxZ = %.8e, expected 1.\n", vp.MaxZ);
1477 width = GetSystemMetrics(SM_CXSCREEN);
1478 height = GetSystemMetrics(SM_CYSCREEN);
1479 ok(width == orig_width, "Screen width is %u, expected %u.\n", width, orig_width);
1480 ok(height == orig_height, "Screen height is %u, expected %u.\n", height, orig_height);
1482 hr = IDirect3DDevice8_GetRenderTarget(device1, &surface);
1483 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
1484 hr = IDirect3DSurface8_GetDesc(surface, &surface_desc);
1485 ok(hr == D3D_OK, "GetDesc failed, hr %#x.\n", hr);
1486 ok(surface_desc.Width == 400, "Back buffer width is %u, expected 400.\n",
1487 surface_desc.Width);
1488 ok(surface_desc.Height == 300, "Back buffer height is %u, expected 300.\n",
1489 surface_desc.Height);
1490 IDirect3DSurface8_Release(surface);
1492 winrect.left = 0;
1493 winrect.top = 0;
1494 winrect.right = 200;
1495 winrect.bottom = 150;
1496 ok(AdjustWindowRect(&winrect, WS_OVERLAPPEDWINDOW, FALSE), "AdjustWindowRect failed\n");
1497 ok(SetWindowPos(window, NULL, 0, 0,
1498 winrect.right-winrect.left,
1499 winrect.bottom-winrect.top,
1500 SWP_NOMOVE|SWP_NOZORDER),
1501 "SetWindowPos failed\n");
1503 memset(&d3dpp, 0, sizeof(d3dpp));
1504 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1505 d3dpp.Windowed = TRUE;
1506 d3dpp.BackBufferWidth = 0;
1507 d3dpp.BackBufferHeight = 0;
1508 d3dpp.BackBufferFormat = d3ddm.Format;
1509 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1510 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1511 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1512 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1514 ok(!d3dpp.BackBufferWidth, "Got unexpected BackBufferWidth %u.\n", d3dpp.BackBufferWidth);
1515 ok(!d3dpp.BackBufferHeight, "Got unexpected BackBufferHeight %u.\n", d3dpp.BackBufferHeight);
1516 ok(d3dpp.BackBufferFormat == d3ddm.Format, "Got unexpected BackBufferFormat %#x, expected %#x.\n",
1517 d3dpp.BackBufferFormat, d3ddm.Format);
1518 ok(d3dpp.BackBufferCount == 1, "Got unexpected BackBufferCount %u.\n", d3dpp.BackBufferCount);
1519 ok(!d3dpp.MultiSampleType, "Got unexpected MultiSampleType %u.\n", d3dpp.MultiSampleType);
1520 ok(d3dpp.SwapEffect == D3DSWAPEFFECT_DISCARD, "Got unexpected SwapEffect %#x.\n", d3dpp.SwapEffect);
1521 ok(!d3dpp.hDeviceWindow, "Got unexpected hDeviceWindow %p.\n", d3dpp.hDeviceWindow);
1522 ok(d3dpp.Windowed, "Got unexpected Windowed %#x.\n", d3dpp.Windowed);
1523 ok(!d3dpp.EnableAutoDepthStencil, "Got unexpected EnableAutoDepthStencil %#x.\n", d3dpp.EnableAutoDepthStencil);
1524 ok(!d3dpp.AutoDepthStencilFormat, "Got unexpected AutoDepthStencilFormat %#x.\n", d3dpp.AutoDepthStencilFormat);
1525 ok(!d3dpp.Flags, "Got unexpected Flags %#x.\n", d3dpp.Flags);
1526 ok(!d3dpp.FullScreen_RefreshRateInHz, "Got unexpected FullScreen_RefreshRateInHz %u.\n",
1527 d3dpp.FullScreen_RefreshRateInHz);
1528 ok(!d3dpp.FullScreen_PresentationInterval, "Got unexpected FullScreen_PresentationInterval %#x.\n",
1529 d3dpp.FullScreen_PresentationInterval);
1531 memset(&vp, 0, sizeof(vp));
1532 hr = IDirect3DDevice8_GetViewport(device1, &vp);
1533 ok(SUCCEEDED(hr), "GetViewport failed, hr %#x.\n", hr);
1534 if (SUCCEEDED(hr))
1536 ok(vp.X == 0, "D3DVIEWPORT->X = %u, expected 0.\n", vp.X);
1537 ok(vp.Y == 0, "D3DVIEWPORT->Y = %u, expected 0.\n", vp.Y);
1538 ok(vp.Width == 200, "D3DVIEWPORT->Width = %u, expected 200.\n", vp.Width);
1539 ok(vp.Height == 150, "D3DVIEWPORT->Height = %u, expected 150.\n", vp.Height);
1540 ok(vp.MinZ == 0, "D3DVIEWPORT->MinZ = %.8e, expected 0.\n", vp.MinZ);
1541 ok(vp.MaxZ == 1, "D3DVIEWPORT->MaxZ = %.8e, expected 1.\n", vp.MaxZ);
1544 hr = IDirect3DDevice8_GetRenderTarget(device1, &surface);
1545 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
1546 hr = IDirect3DSurface8_GetDesc(surface, &surface_desc);
1547 ok(hr == D3D_OK, "GetDesc failed, hr %#x.\n", hr);
1548 ok(surface_desc.Format == d3ddm.Format, "Got unexpected Format %#x, expected %#x.\n",
1549 surface_desc.Format, d3ddm.Format);
1550 ok(!surface_desc.MultiSampleType, "Got unexpected MultiSampleType %u.\n", d3dpp.MultiSampleType);
1551 ok(surface_desc.Width == 200, "Back buffer width is %u, expected 200.\n", surface_desc.Width);
1552 ok(surface_desc.Height == 150, "Back buffer height is %u, expected 150.\n", surface_desc.Height);
1553 IDirect3DSurface8_Release(surface);
1555 memset(&d3dpp, 0, sizeof(d3dpp));
1556 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1557 d3dpp.Windowed = TRUE;
1558 d3dpp.BackBufferWidth = 400;
1559 d3dpp.BackBufferHeight = 300;
1560 d3dpp.BackBufferFormat = d3ddm.Format;
1562 /* Reset fails if there is a resource in the default pool. */
1563 hr = IDirect3DDevice8_CreateTexture(device1, 16, 16, 1, 0, D3DFMT_R5G6B5, D3DPOOL_DEFAULT, &texture);
1564 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
1565 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1566 ok(hr == D3DERR_DEVICELOST, "Reset returned %#x, expected %#x.\n", hr, D3DERR_DEVICELOST);
1567 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1568 ok(hr == D3DERR_DEVICENOTRESET, "TestCooperativeLevel returned %#x, expected %#x.\n", hr, D3DERR_DEVICENOTRESET);
1569 IDirect3DTexture8_Release(texture);
1570 /* Reset again to get the device out of the lost state. */
1571 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1572 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1573 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1574 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1576 if (caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP)
1578 IDirect3DVolumeTexture8 *volume_texture;
1580 hr = IDirect3DDevice8_CreateVolumeTexture(device1, 16, 16, 4, 1, 0,
1581 D3DFMT_R5G6B5, D3DPOOL_DEFAULT, &volume_texture);
1582 ok(SUCCEEDED(hr), "CreateVolumeTexture failed, hr %#x.\n", hr);
1583 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1584 ok(hr == D3DERR_DEVICELOST, "Reset returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
1585 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1586 ok(hr == D3DERR_DEVICENOTRESET, "TestCooperativeLevel returned %#x, expected %#x.\n",
1587 hr, D3DERR_DEVICENOTRESET);
1588 IDirect3DVolumeTexture8_Release(volume_texture);
1589 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1590 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1591 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1592 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1594 else
1596 skip("Volume textures not supported.\n");
1599 /* Scratch, sysmem and managed pool resources are fine. */
1600 hr = IDirect3DDevice8_CreateTexture(device1, 16, 16, 1, 0, D3DFMT_R5G6B5, D3DPOOL_SCRATCH, &texture);
1601 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
1602 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1603 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1604 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1605 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1606 IDirect3DTexture8_Release(texture);
1608 hr = IDirect3DDevice8_CreateTexture(device1, 16, 16, 1, 0, D3DFMT_R5G6B5, D3DPOOL_SYSTEMMEM, &texture);
1609 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
1610 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1611 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1612 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1613 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1614 IDirect3DTexture8_Release(texture);
1616 /* The depth stencil should get reset to the auto depth stencil when present. */
1617 hr = IDirect3DDevice8_SetRenderTarget(device1, NULL, NULL);
1618 ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
1620 hr = IDirect3DDevice8_GetDepthStencilSurface(device1, &surface);
1621 ok(hr == D3DERR_NOTFOUND, "GetDepthStencilSurface returned %#x, expected %#x.\n", hr, D3DERR_NOTFOUND);
1622 ok(!surface, "Depth / stencil buffer should be NULL.\n");
1624 d3dpp.EnableAutoDepthStencil = TRUE;
1625 d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
1626 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1627 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1629 hr = IDirect3DDevice8_GetDepthStencilSurface(device1, &surface);
1630 ok(SUCCEEDED(hr), "GetDepthStencilSurface failed, hr %#x.\n", hr);
1631 ok(!!surface, "Depth / stencil buffer should not be NULL.\n");
1632 if (surface) IDirect3DSurface8_Release(surface);
1634 d3dpp.EnableAutoDepthStencil = FALSE;
1635 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1636 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1638 hr = IDirect3DDevice8_GetDepthStencilSurface(device1, &surface);
1639 ok(hr == D3DERR_NOTFOUND, "GetDepthStencilSurface returned %#x, expected %#x.\n", hr, D3DERR_NOTFOUND);
1640 ok(!surface, "Depth / stencil buffer should be NULL.\n");
1642 /* Will a sysmem or scratch resource survive while locked? */
1643 hr = IDirect3DDevice8_CreateTexture(device1, 16, 16, 1, 0, D3DFMT_R5G6B5, D3DPOOL_SYSTEMMEM, &texture);
1644 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
1645 hr = IDirect3DTexture8_LockRect(texture, 0, &lockrect, NULL, D3DLOCK_DISCARD);
1646 ok(SUCCEEDED(hr), "LockRect failed, hr %#x.\n", hr);
1647 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1648 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1649 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1650 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1651 IDirect3DTexture8_UnlockRect(texture, 0);
1652 IDirect3DTexture8_Release(texture);
1654 hr = IDirect3DDevice8_CreateTexture(device1, 16, 16, 1, 0, D3DFMT_R5G6B5, D3DPOOL_SCRATCH, &texture);
1655 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
1656 hr = IDirect3DTexture8_LockRect(texture, 0, &lockrect, NULL, D3DLOCK_DISCARD);
1657 ok(SUCCEEDED(hr), "LockRect failed, hr %#x.\n", hr);
1658 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1659 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1660 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1661 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1662 IDirect3DTexture8_UnlockRect(texture, 0);
1663 IDirect3DTexture8_Release(texture);
1665 hr = IDirect3DDevice8_CreateTexture(device1, 16, 16, 1, 0, D3DFMT_R5G6B5, D3DPOOL_MANAGED, &texture);
1666 ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
1667 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1668 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1669 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1670 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1671 IDirect3DTexture8_Release(texture);
1673 /* A reference held to an implicit surface causes failures as well. */
1674 hr = IDirect3DDevice8_GetBackBuffer(device1, 0, D3DBACKBUFFER_TYPE_MONO, &surface);
1675 ok(SUCCEEDED(hr), "GetBackBuffer failed, hr %#x.\n", hr);
1676 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1677 ok(hr == D3DERR_DEVICELOST, "Reset returned %#x, expected %#x.\n", hr, D3DERR_DEVICELOST);
1678 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1679 ok(hr == D3DERR_DEVICENOTRESET, "TestCooperativeLevel returned %#x, expected %#x.\n", hr, D3DERR_DEVICENOTRESET);
1680 IDirect3DSurface8_Release(surface);
1681 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1682 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1683 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1684 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1686 /* Shaders are fine as well. */
1687 hr = IDirect3DDevice8_CreateVertexShader(device1, decl, simple_vs, &shader, 0);
1688 ok(SUCCEEDED(hr), "CreateVertexShader failed, hr %#x.\n", hr);
1689 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1690 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1691 hr = IDirect3DDevice8_DeleteVertexShader(device1, shader);
1692 ok(SUCCEEDED(hr), "DeleteVertexShader failed, hr %#x.\n", hr);
1694 /* Try setting invalid modes. */
1695 memset(&d3dpp, 0, sizeof(d3dpp));
1696 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1697 d3dpp.Windowed = FALSE;
1698 d3dpp.BackBufferWidth = 32;
1699 d3dpp.BackBufferHeight = 32;
1700 d3dpp.BackBufferFormat = d3ddm.Format;
1701 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1702 ok(hr == D3DERR_INVALIDCALL, "Reset returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
1703 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1704 ok(hr == D3DERR_DEVICENOTRESET, "TestCooperativeLevel returned %#x, expected %#x.\n", hr, D3DERR_DEVICENOTRESET);
1706 memset(&d3dpp, 0, sizeof(d3dpp));
1707 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1708 d3dpp.Windowed = FALSE;
1709 d3dpp.BackBufferWidth = 801;
1710 d3dpp.BackBufferHeight = 600;
1711 d3dpp.BackBufferFormat = d3ddm.Format;
1712 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1713 ok(hr == D3DERR_INVALIDCALL, "Reset returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
1714 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1715 ok(hr == D3DERR_DEVICENOTRESET, "TestCooperativeLevel returned %#x, expected %#x.\n", hr, D3DERR_DEVICENOTRESET);
1717 memset(&d3dpp, 0, sizeof(d3dpp));
1718 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1719 d3dpp.Windowed = FALSE;
1720 d3dpp.BackBufferWidth = 0;
1721 d3dpp.BackBufferHeight = 0;
1722 d3dpp.BackBufferFormat = d3ddm.Format;
1723 hr = IDirect3DDevice8_Reset(device1, &d3dpp);
1724 ok(hr == D3DERR_INVALIDCALL, "Reset returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
1725 hr = IDirect3DDevice8_TestCooperativeLevel(device1);
1726 ok(hr == D3DERR_DEVICENOTRESET, "TestCooperativeLevel returned %#x, expected %#x.\n", hr, D3DERR_DEVICENOTRESET);
1728 hr = IDirect3D8_GetAdapterDisplayMode(d3d8, D3DADAPTER_DEFAULT, &d3ddm);
1729 ok(SUCCEEDED(hr), "GetAdapterDisplayMode failed, hr %#x.\n", hr);
1731 memset(&d3dpp, 0, sizeof(d3dpp));
1732 d3dpp.Windowed = TRUE;
1733 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1734 d3dpp.BackBufferFormat = d3ddm.Format;
1735 d3dpp.EnableAutoDepthStencil = FALSE;
1736 d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
1738 hr = IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
1739 window, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &device2);
1740 if (FAILED(hr))
1742 skip("Failed to create device, hr %#x.\n", hr);
1743 goto cleanup;
1746 hr = IDirect3DDevice8_TestCooperativeLevel(device2);
1747 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1749 d3dpp.Windowed = TRUE;
1750 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1751 d3dpp.BackBufferWidth = 400;
1752 d3dpp.BackBufferHeight = 300;
1753 d3dpp.BackBufferFormat = d3ddm.Format;
1754 d3dpp.EnableAutoDepthStencil = TRUE;
1755 d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
1757 hr = IDirect3DDevice8_Reset(device2, &d3dpp);
1758 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1759 if (FAILED(hr))
1760 goto cleanup;
1762 hr = IDirect3DDevice8_GetDepthStencilSurface(device2, &surface);
1763 ok(SUCCEEDED(hr), "GetDepthStencilSurface failed, hr %#x.\n", hr);
1764 ok(!!surface, "Depth / stencil buffer should not be NULL.\n");
1765 if (surface)
1766 IDirect3DSurface8_Release(surface);
1768 cleanup:
1769 HeapFree(GetProcessHeap(), 0, modes);
1770 if (device2)
1771 IDirect3DDevice8_Release(device2);
1772 if (device1)
1773 IDirect3DDevice8_Release(device1);
1774 IDirect3D8_Release(d3d8);
1775 DestroyWindow(window);
1778 static void test_scene(void)
1780 IDirect3DDevice8 *device;
1781 IDirect3D8 *d3d;
1782 ULONG refcount;
1783 HWND window;
1784 HRESULT hr;
1786 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
1787 0, 0, 640, 480, NULL, NULL, NULL, NULL);
1788 ok(!!window, "Failed to create a window.\n");
1789 d3d = Direct3DCreate8(D3D_SDK_VERSION);
1790 ok(!!d3d, "Failed to create a D3D object.\n");
1791 if (!(device = create_device(d3d, window, NULL)))
1793 skip("Failed to create a 3D device, skipping test.\n");
1794 goto cleanup;
1797 /* Test an EndScene without BeginScene. Should return an error */
1798 hr = IDirect3DDevice8_EndScene(device);
1799 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_EndScene returned %#08x\n", hr);
1801 /* Test a normal BeginScene / EndScene pair, this should work */
1802 hr = IDirect3DDevice8_BeginScene(device);
1803 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr);
1804 hr = IDirect3DDevice8_EndScene(device);
1805 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed with %#08x\n", hr);
1807 /* Test another EndScene without having begun a new scene. Should return an error */
1808 hr = IDirect3DDevice8_EndScene(device);
1809 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_EndScene returned %#08x\n", hr);
1811 /* Two nested BeginScene and EndScene calls */
1812 hr = IDirect3DDevice8_BeginScene(device);
1813 ok(hr == D3D_OK, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr);
1814 hr = IDirect3DDevice8_BeginScene(device);
1815 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_BeginScene returned %#08x\n", hr);
1816 hr = IDirect3DDevice8_EndScene(device);
1817 ok(hr == D3D_OK, "IDirect3DDevice8_EndScene failed with %#08x\n", hr);
1818 hr = IDirect3DDevice8_EndScene(device);
1819 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_EndScene returned %#08x\n", hr);
1821 /* StretchRect does not exit in Direct3D8, so no equivalent to the d3d9 stretchrect tests */
1823 refcount = IDirect3DDevice8_Release(device);
1824 ok(!refcount, "Device has %u references left.\n", refcount);
1825 cleanup:
1826 IDirect3D8_Release(d3d);
1827 DestroyWindow(window);
1830 static void test_shader(void)
1832 DWORD hPixelShader = 0, hVertexShader = 0;
1833 DWORD hPixelShader2 = 0, hVertexShader2 = 0;
1834 DWORD hTempHandle;
1835 D3DCAPS8 caps;
1836 DWORD fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE;
1837 IDirect3DDevice8 *device;
1838 IDirect3D8 *d3d;
1839 DWORD data_size;
1840 ULONG refcount;
1841 HWND window;
1842 HRESULT hr;
1843 void *data;
1845 static DWORD dwVertexDecl[] =
1847 D3DVSD_STREAM(0),
1848 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3),
1849 D3DVSD_END()
1851 DWORD decl_normal_float2[] =
1853 D3DVSD_STREAM(0),
1854 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
1855 D3DVSD_REG(D3DVSDE_NORMAL, D3DVSDT_FLOAT2), /* D3DVSDE_NORMAL, Register v1 */
1856 D3DVSD_END()
1858 DWORD decl_normal_float4[] =
1860 D3DVSD_STREAM(0),
1861 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
1862 D3DVSD_REG(D3DVSDE_NORMAL, D3DVSDT_FLOAT4), /* D3DVSDE_NORMAL, Register v1 */
1863 D3DVSD_END()
1865 DWORD decl_normal_d3dcolor[] =
1867 D3DVSD_STREAM(0),
1868 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), /* D3DVSDE_POSITION, Register v0 */
1869 D3DVSD_REG(D3DVSDE_NORMAL, D3DVSDT_D3DCOLOR),/* D3DVSDE_NORMAL, Register v1 */
1870 D3DVSD_END()
1872 const DWORD vertex_decl_size = sizeof(dwVertexDecl);
1873 const DWORD simple_vs_size = sizeof(simple_vs);
1874 const DWORD simple_ps_size = sizeof(simple_ps);
1876 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
1877 0, 0, 640, 480, NULL, NULL, NULL, NULL);
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 IDirect3DDevice8_GetDeviceCaps(device, &caps);
1889 /* Test setting and retrieving a FVF */
1890 hr = IDirect3DDevice8_SetVertexShader(device, fvf);
1891 ok(SUCCEEDED(hr), "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
1892 hr = IDirect3DDevice8_GetVertexShader(device, &hTempHandle);
1893 ok(SUCCEEDED(hr), "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
1894 ok(hTempHandle == fvf, "Vertex shader %#08x is set, expected %#08x\n", hTempHandle, fvf);
1896 /* First create a vertex shader */
1897 hr = IDirect3DDevice8_SetVertexShader(device, 0);
1898 ok(SUCCEEDED(hr), "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
1899 hr = IDirect3DDevice8_CreateVertexShader(device, dwVertexDecl, simple_vs, &hVertexShader, 0);
1900 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1901 /* Msdn says that the new vertex shader is set immediately. This is wrong, apparently */
1902 hr = IDirect3DDevice8_GetVertexShader(device, &hTempHandle);
1903 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
1904 ok(hTempHandle == 0, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, 0);
1905 /* Assign the shader, then verify that GetVertexShader works */
1906 hr = IDirect3DDevice8_SetVertexShader(device, hVertexShader);
1907 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
1908 hr = IDirect3DDevice8_GetVertexShader(device, &hTempHandle);
1909 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
1910 ok(hTempHandle == hVertexShader, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, hVertexShader);
1911 /* Verify that we can retrieve the declaration */
1912 hr = IDirect3DDevice8_GetVertexShaderDeclaration(device, hVertexShader, NULL, &data_size);
1913 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderDeclaration returned %#08x\n", hr);
1914 ok(data_size == vertex_decl_size, "Got data_size %u, expected %u\n", data_size, vertex_decl_size);
1915 data = HeapAlloc(GetProcessHeap(), 0, vertex_decl_size);
1916 data_size = 1;
1917 hr = IDirect3DDevice8_GetVertexShaderDeclaration(device, hVertexShader, data, &data_size);
1918 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_GetVertexShaderDeclaration returned (%#08x), "
1919 "expected D3DERR_INVALIDCALL\n", hr);
1920 ok(data_size == 1, "Got data_size %u, expected 1\n", data_size);
1921 data_size = vertex_decl_size;
1922 hr = IDirect3DDevice8_GetVertexShaderDeclaration(device, hVertexShader, data, &data_size);
1923 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderDeclaration returned %#08x\n", hr);
1924 ok(data_size == vertex_decl_size, "Got data_size %u, expected %u\n", data_size, vertex_decl_size);
1925 ok(!memcmp(data, dwVertexDecl, vertex_decl_size), "data not equal to shader declaration\n");
1926 HeapFree(GetProcessHeap(), 0, data);
1927 /* Verify that we can retrieve the shader function */
1928 hr = IDirect3DDevice8_GetVertexShaderFunction(device, hVertexShader, NULL, &data_size);
1929 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderFunction returned %#08x\n", hr);
1930 ok(data_size == simple_vs_size, "Got data_size %u, expected %u\n", data_size, simple_vs_size);
1931 data = HeapAlloc(GetProcessHeap(), 0, simple_vs_size);
1932 data_size = 1;
1933 hr = IDirect3DDevice8_GetVertexShaderFunction(device, hVertexShader, data, &data_size);
1934 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_GetVertexShaderFunction returned (%#08x), "
1935 "expected D3DERR_INVALIDCALL\n", hr);
1936 ok(data_size == 1, "Got data_size %u, expected 1\n", data_size);
1937 data_size = simple_vs_size;
1938 hr = IDirect3DDevice8_GetVertexShaderFunction(device, hVertexShader, data, &data_size);
1939 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShaderFunction returned %#08x\n", hr);
1940 ok(data_size == simple_vs_size, "Got data_size %u, expected %u\n", data_size, simple_vs_size);
1941 ok(!memcmp(data, simple_vs, simple_vs_size), "data not equal to shader function\n");
1942 HeapFree(GetProcessHeap(), 0, data);
1943 /* Delete the assigned shader. This is supposed to work */
1944 hr = IDirect3DDevice8_DeleteVertexShader(device, hVertexShader);
1945 ok(hr == D3D_OK, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
1946 /* The shader should be unset now */
1947 hr = IDirect3DDevice8_GetVertexShader(device, &hTempHandle);
1948 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
1949 ok(hTempHandle == 0, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, 0);
1951 /* Test a broken declaration. 3DMark2001 tries to use normals with 2 components
1952 * First try the fixed function shader function, then a custom one
1954 hr = IDirect3DDevice8_CreateVertexShader(device, decl_normal_float2, 0, &hVertexShader, 0);
1955 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1956 hr = IDirect3DDevice8_CreateVertexShader(device, decl_normal_float4, 0, &hVertexShader, 0);
1957 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1958 hr = IDirect3DDevice8_CreateVertexShader(device, decl_normal_d3dcolor, 0, &hVertexShader, 0);
1959 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1961 hr = IDirect3DDevice8_CreateVertexShader(device, decl_normal_float2, simple_vs, &hVertexShader, 0);
1962 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
1963 IDirect3DDevice8_DeleteVertexShader(device, hVertexShader);
1965 if (caps.PixelShaderVersion >= D3DPS_VERSION(1, 0))
1967 /* The same with a pixel shader */
1968 hr = IDirect3DDevice8_CreatePixelShader(device, simple_ps, &hPixelShader);
1969 ok(hr == D3D_OK, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr);
1970 /* Msdn says that the new pixel shader is set immediately. This is wrong, apparently */
1971 hr = IDirect3DDevice8_GetPixelShader(device, &hTempHandle);
1972 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr);
1973 ok(hTempHandle == 0, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, 0);
1974 /* Assign the shader, then verify that GetPixelShader works */
1975 hr = IDirect3DDevice8_SetPixelShader(device, hPixelShader);
1976 ok(hr == D3D_OK, "IDirect3DDevice8_SetPixelShader returned %#08x\n", hr);
1977 hr = IDirect3DDevice8_GetPixelShader(device, &hTempHandle);
1978 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr);
1979 ok(hTempHandle == hPixelShader, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, hPixelShader);
1980 /* Verify that we can retrieve the shader function */
1981 hr = IDirect3DDevice8_GetPixelShaderFunction(device, hPixelShader, NULL, &data_size);
1982 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShaderFunction returned %#08x\n", hr);
1983 ok(data_size == simple_ps_size, "Got data_size %u, expected %u\n", data_size, simple_ps_size);
1984 data = HeapAlloc(GetProcessHeap(), 0, simple_ps_size);
1985 data_size = 1;
1986 hr = IDirect3DDevice8_GetPixelShaderFunction(device, hPixelShader, data, &data_size);
1987 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_GetPixelShaderFunction returned (%#08x), "
1988 "expected D3DERR_INVALIDCALL\n", hr);
1989 ok(data_size == 1, "Got data_size %u, expected 1\n", data_size);
1990 data_size = simple_ps_size;
1991 hr = IDirect3DDevice8_GetPixelShaderFunction(device, hPixelShader, data, &data_size);
1992 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShaderFunction returned %#08x\n", hr);
1993 ok(data_size == simple_ps_size, "Got data_size %u, expected %u\n", data_size, simple_ps_size);
1994 ok(!memcmp(data, simple_ps, simple_ps_size), "data not equal to shader function\n");
1995 HeapFree(GetProcessHeap(), 0, data);
1996 /* Delete the assigned shader. This is supposed to work */
1997 hr = IDirect3DDevice8_DeletePixelShader(device, hPixelShader);
1998 ok(hr == D3D_OK, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
1999 /* The shader should be unset now */
2000 hr = IDirect3DDevice8_GetPixelShader(device, &hTempHandle);
2001 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr);
2002 ok(hTempHandle == 0, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, 0);
2004 /* What happens if a non-bound shader is deleted? */
2005 hr = IDirect3DDevice8_CreatePixelShader(device, simple_ps, &hPixelShader);
2006 ok(hr == D3D_OK, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr);
2007 hr = IDirect3DDevice8_CreatePixelShader(device, simple_ps, &hPixelShader2);
2008 ok(hr == D3D_OK, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr);
2010 hr = IDirect3DDevice8_SetPixelShader(device, hPixelShader);
2011 ok(hr == D3D_OK, "IDirect3DDevice8_SetPixelShader returned %#08x\n", hr);
2012 hr = IDirect3DDevice8_DeletePixelShader(device, hPixelShader2);
2013 ok(hr == D3D_OK, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
2014 hr = IDirect3DDevice8_GetPixelShader(device, &hTempHandle);
2015 ok(hr == D3D_OK, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr);
2016 ok(hTempHandle == hPixelShader, "Pixel Shader %d is set, expected shader %d\n", hTempHandle, hPixelShader);
2017 hr = IDirect3DDevice8_DeletePixelShader(device, hPixelShader);
2018 ok(hr == D3D_OK, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
2020 /* Check for double delete. */
2021 hr = IDirect3DDevice8_DeletePixelShader(device, hPixelShader2);
2022 ok(hr == D3DERR_INVALIDCALL || broken(hr == D3D_OK), "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
2023 hr = IDirect3DDevice8_DeletePixelShader(device, hPixelShader);
2024 ok(hr == D3DERR_INVALIDCALL || broken(hr == D3D_OK), "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr);
2026 else
2028 skip("Pixel shaders not supported\n");
2031 /* What happens if a non-bound shader is deleted? */
2032 hr = IDirect3DDevice8_CreateVertexShader(device, dwVertexDecl, NULL, &hVertexShader, 0);
2033 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
2034 hr = IDirect3DDevice8_CreateVertexShader(device, dwVertexDecl, NULL, &hVertexShader2, 0);
2035 ok(hr == D3D_OK, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
2037 hr = IDirect3DDevice8_SetVertexShader(device, hVertexShader);
2038 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
2039 hr = IDirect3DDevice8_DeleteVertexShader(device, hVertexShader2);
2040 ok(hr == D3D_OK, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
2041 hr = IDirect3DDevice8_GetVertexShader(device, &hTempHandle);
2042 ok(hr == D3D_OK, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr);
2043 ok(hTempHandle == hVertexShader, "Vertex Shader %d is set, expected shader %d\n", hTempHandle, hVertexShader);
2044 hr = IDirect3DDevice8_DeleteVertexShader(device, hVertexShader);
2045 ok(hr == D3D_OK, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
2047 /* Check for double delete. */
2048 hr = IDirect3DDevice8_DeleteVertexShader(device, hVertexShader2);
2049 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
2050 hr = IDirect3DDevice8_DeleteVertexShader(device, hVertexShader);
2051 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
2053 refcount = IDirect3DDevice8_Release(device);
2054 ok(!refcount, "Device has %u references left.\n", refcount);
2055 cleanup:
2056 IDirect3D8_Release(d3d);
2057 DestroyWindow(window);
2060 static void test_limits(void)
2062 IDirect3DTexture8 *texture;
2063 IDirect3DDevice8 *device;
2064 IDirect3D8 *d3d;
2065 unsigned int i;
2066 ULONG refcount;
2067 HWND window;
2068 HRESULT hr;
2070 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
2071 0, 0, 640, 480, NULL, NULL, NULL, NULL);
2072 ok(!!window, "Failed to create a window.\n");
2073 d3d = Direct3DCreate8(D3D_SDK_VERSION);
2074 ok(!!d3d, "Failed to create a D3D object.\n");
2075 if (!(device = create_device(d3d, window, NULL)))
2077 skip("Failed to create a 3D device, skipping test.\n");
2078 goto cleanup;
2081 hr = IDirect3DDevice8_CreateTexture(device, 16, 16, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture);
2082 ok(hr == D3D_OK, "IDirect3DDevice8_CreateTexture failed with %#08x\n", hr);
2084 /* There are 8 texture stages. We should be able to access all of them */
2085 for (i = 0; i < 8; ++i)
2087 hr = IDirect3DDevice8_SetTexture(device, i, (IDirect3DBaseTexture8 *)texture);
2088 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %#08x\n", i, hr);
2089 hr = IDirect3DDevice8_SetTexture(device, i, NULL);
2090 ok(hr == D3D_OK, "IDirect3DDevice8_SetTexture for sampler %d failed with %#08x\n", i, hr);
2091 hr = IDirect3DDevice8_SetTextureStageState(device, i, D3DTSS_COLOROP, D3DTOP_ADD);
2092 ok(hr == D3D_OK, "IDirect3DDevice8_SetTextureStageState for texture %d failed with %#08x\n", i, hr);
2095 /* Investigations show that accessing higher textures stage states does
2096 * not return an error either. Writing to too high texture stages
2097 * (approximately texture 40) causes memory corruption in windows, so
2098 * there is no bounds checking. */
2099 IDirect3DTexture8_Release(texture);
2100 refcount = IDirect3DDevice8_Release(device);
2101 ok(!refcount, "Device has %u references left.\n", refcount);
2102 cleanup:
2103 IDirect3D8_Release(d3d);
2104 DestroyWindow(window);
2107 static void test_lights(void)
2109 IDirect3DDevice8 *device;
2110 IDirect3D8 *d3d8;
2111 ULONG refcount;
2112 HWND window;
2113 HRESULT hr;
2114 unsigned int i;
2115 BOOL enabled;
2116 D3DCAPS8 caps;
2118 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
2119 0, 0, 640, 480, NULL, NULL, NULL, NULL);
2120 ok(!!window, "Failed to create a window.\n");
2121 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
2122 ok(!!d3d8, "Failed to create a D3D object.\n");
2123 if (!(device = create_device(d3d8, window, NULL)))
2125 skip("Failed to create a 3D device, skipping test.\n");
2126 goto cleanup;
2129 memset(&caps, 0, sizeof(caps));
2130 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
2131 ok(hr == D3D_OK, "IDirect3DDevice8_GetDeviceCaps failed with %08x\n", hr);
2133 for(i = 1; i <= caps.MaxActiveLights; i++) {
2134 hr = IDirect3DDevice8_LightEnable(device, i, TRUE);
2135 ok(hr == D3D_OK, "Enabling light %u failed with %08x\n", i, hr);
2136 hr = IDirect3DDevice8_GetLightEnable(device, i, &enabled);
2137 ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL),
2138 "GetLightEnable on light %u failed with %08x\n", i, hr);
2139 ok(enabled, "Light %d is %s\n", i, enabled ? "enabled" : "disabled");
2142 /* TODO: Test the rendering results in this situation */
2143 hr = IDirect3DDevice8_LightEnable(device, i + 1, TRUE);
2144 ok(hr == D3D_OK, "Enabling one light more than supported returned %08x\n", hr);
2145 hr = IDirect3DDevice8_GetLightEnable(device, i + 1, &enabled);
2146 ok(hr == D3D_OK, "GetLightEnable on light %u failed with %08x\n", i + 1, hr);
2147 ok(enabled, "Light %d is %s\n", i + 1, enabled ? "enabled" : "disabled");
2148 hr = IDirect3DDevice8_LightEnable(device, i + 1, FALSE);
2149 ok(hr == D3D_OK, "Disabling the additional returned %08x\n", hr);
2151 for(i = 1; i <= caps.MaxActiveLights; i++) {
2152 hr = IDirect3DDevice8_LightEnable(device, i, FALSE);
2153 ok(hr == D3D_OK, "Disabling light %u failed with %08x\n", i, hr);
2156 refcount = IDirect3DDevice8_Release(device);
2157 ok(!refcount, "Device has %u references left.\n", refcount);
2158 cleanup:
2159 IDirect3D8_Release(d3d8);
2160 DestroyWindow(window);
2163 static void test_render_zero_triangles(void)
2165 IDirect3DDevice8 *device;
2166 IDirect3D8 *d3d8;
2167 ULONG refcount;
2168 HWND window;
2169 HRESULT hr;
2171 static const struct
2173 struct vec3 position;
2174 struct vec3 normal;
2175 DWORD diffuse;
2177 quad[] =
2179 {{0.0f, -1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
2180 {{0.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
2181 {{1.0f, 0.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
2182 {{1.0f, -1.0f, 0.1f}, {1.0f, 1.0f, 1.0f}, 0xff0000ff},
2185 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
2186 0, 0, 640, 480, NULL, NULL, NULL, NULL);
2187 ok(!!window, "Failed to create a window.\n");
2188 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
2189 ok(!!d3d8, "Failed to create a D3D object.\n");
2190 if (!(device = create_device(d3d8, window, NULL)))
2192 skip("Failed to create a 3D device, skipping test.\n");
2193 goto cleanup;
2196 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
2197 ok(hr == D3D_OK, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr);
2199 hr = IDirect3DDevice8_BeginScene(device);
2200 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
2201 hr = IDirect3DDevice8_DrawIndexedPrimitiveUP(device, D3DPT_TRIANGLELIST, 0 /* MinIndex */, 0 /* NumVerts */,
2202 0 /* PrimCount */, NULL, D3DFMT_INDEX16, quad, sizeof(quad[0]));
2203 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
2204 hr = IDirect3DDevice8_EndScene(device);
2205 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
2207 IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
2209 refcount = IDirect3DDevice8_Release(device);
2210 ok(!refcount, "Device has %u references left.\n", refcount);
2211 cleanup:
2212 IDirect3D8_Release(d3d8);
2213 DestroyWindow(window);
2216 static void test_depth_stencil_reset(void)
2218 D3DPRESENT_PARAMETERS present_parameters;
2219 D3DDISPLAYMODE display_mode;
2220 IDirect3DSurface8 *surface, *orig_rt;
2221 IDirect3DDevice8 *device = NULL;
2222 IDirect3D8 *d3d8;
2223 UINT refcount;
2224 HRESULT hr;
2225 HWND hwnd;
2227 hwnd = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
2228 100, 100, 160, 160, NULL, NULL, NULL, NULL);
2229 ok(!!hwnd, "Failed to create a window.\n");
2230 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
2231 ok(!!d3d8, "Failed to create a D3D object.\n");
2233 IDirect3D8_GetAdapterDisplayMode(d3d8, D3DADAPTER_DEFAULT, &display_mode);
2234 memset(&present_parameters, 0, sizeof(present_parameters));
2235 present_parameters.Windowed = TRUE;
2236 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
2237 present_parameters.BackBufferFormat = display_mode.Format;
2238 present_parameters.EnableAutoDepthStencil = TRUE;
2239 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
2241 hr = IDirect3D8_CreateDevice(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
2242 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device);
2243 if(FAILED(hr))
2245 skip("could not create device, IDirect3D8_CreateDevice returned %#x\n", hr);
2246 goto cleanup;
2249 hr = IDirect3DDevice8_GetRenderTarget(device, &orig_rt);
2250 ok(hr == D3D_OK, "GetRenderTarget failed with 0x%08x\n", hr);
2252 hr = IDirect3DDevice8_TestCooperativeLevel(device);
2253 ok(SUCCEEDED(hr), "TestCooperativeLevel failed with %#x\n", hr);
2255 hr = IDirect3DDevice8_SetRenderTarget(device, NULL, NULL);
2256 ok(hr == D3D_OK, "SetRenderTarget failed with 0x%08x\n", hr);
2258 hr = IDirect3DDevice8_GetRenderTarget(device, &surface);
2259 ok(hr == D3D_OK, "GetRenderTarget failed with 0x%08x\n", hr);
2260 ok(surface == orig_rt, "Render target is %p, should be %p\n", surface, orig_rt);
2261 if (surface) IDirect3DSurface8_Release(surface);
2262 IDirect3DSurface8_Release(orig_rt);
2264 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surface);
2265 ok(hr == D3DERR_NOTFOUND, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr);
2266 ok(surface == NULL, "Depth stencil should be NULL\n");
2268 present_parameters.EnableAutoDepthStencil = TRUE;
2269 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
2270 hr = IDirect3DDevice8_Reset(device, &present_parameters);
2271 ok(hr == D3D_OK, "Reset failed with 0x%08x\n", hr);
2273 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surface);
2274 ok(hr == D3D_OK, "GetDepthStencilSurface failed with 0x%08x\n", hr);
2275 ok(surface != NULL, "Depth stencil should not be NULL\n");
2276 if (surface) IDirect3DSurface8_Release(surface);
2278 present_parameters.EnableAutoDepthStencil = FALSE;
2279 hr = IDirect3DDevice8_Reset(device, &present_parameters);
2280 ok(hr == D3D_OK, "Reset failed with 0x%08x\n", hr);
2282 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surface);
2283 ok(hr == D3DERR_NOTFOUND, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr);
2284 ok(surface == NULL, "Depth stencil should be NULL\n");
2286 refcount = IDirect3DDevice8_Release(device);
2287 ok(!refcount, "Device has %u references left.\n", refcount);
2288 device = NULL;
2290 IDirect3D8_GetAdapterDisplayMode( d3d8, D3DADAPTER_DEFAULT, &display_mode );
2292 ZeroMemory( &present_parameters, sizeof(present_parameters) );
2293 present_parameters.Windowed = TRUE;
2294 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
2295 present_parameters.BackBufferFormat = display_mode.Format;
2296 present_parameters.EnableAutoDepthStencil = FALSE;
2297 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
2299 hr = IDirect3D8_CreateDevice( d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
2300 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device );
2302 if(FAILED(hr))
2304 skip("could not create device, IDirect3D8_CreateDevice returned %#x\n", hr);
2305 goto cleanup;
2308 hr = IDirect3DDevice8_TestCooperativeLevel(device);
2309 ok(hr == D3D_OK, "IDirect3DDevice8_TestCooperativeLevel after creation returned %#x\n", hr);
2311 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
2312 present_parameters.Windowed = TRUE;
2313 present_parameters.BackBufferWidth = 400;
2314 present_parameters.BackBufferHeight = 300;
2315 present_parameters.EnableAutoDepthStencil = TRUE;
2316 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
2318 hr = IDirect3DDevice8_Reset(device, &present_parameters);
2319 ok(hr == D3D_OK, "IDirect3DDevice8_Reset failed with 0x%08x\n", hr);
2321 if (FAILED(hr)) goto cleanup;
2323 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surface);
2324 ok(hr == D3D_OK, "GetDepthStencilSurface failed with 0x%08x\n", hr);
2325 ok(surface != NULL, "Depth stencil should not be NULL\n");
2326 if (surface) IDirect3DSurface8_Release(surface);
2328 cleanup:
2329 if (device)
2331 refcount = IDirect3DDevice8_Release(device);
2332 ok(!refcount, "Device has %u references left.\n", refcount);
2334 IDirect3D8_Release(d3d8);
2335 DestroyWindow(hwnd);
2338 static HWND filter_messages;
2340 enum message_window
2342 DEVICE_WINDOW,
2343 FOCUS_WINDOW,
2346 struct message
2348 UINT message;
2349 enum message_window window;
2350 BOOL check_wparam;
2351 WPARAM expect_wparam;
2354 static const struct message *expect_messages;
2355 static HWND device_window, focus_window;
2356 static LONG windowposchanged_received, syscommand_received;
2358 struct wndproc_thread_param
2360 HWND dummy_window;
2361 HANDLE window_created;
2362 HANDLE test_finished;
2363 BOOL running_in_foreground;
2366 static LRESULT CALLBACK test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
2368 if (filter_messages && filter_messages == hwnd)
2370 if (message != WM_DISPLAYCHANGE && message != WM_IME_NOTIFY)
2371 todo_wine ok(0, "Received unexpected message %#x for window %p.\n", message, hwnd);
2374 if (expect_messages)
2376 HWND w;
2378 switch (expect_messages->window)
2380 case DEVICE_WINDOW:
2381 w = device_window;
2382 break;
2384 case FOCUS_WINDOW:
2385 w = focus_window;
2386 break;
2388 default:
2389 w = NULL;
2390 break;
2393 if (hwnd == w && expect_messages->message == message)
2395 if (expect_messages->check_wparam)
2396 ok(wparam == expect_messages->expect_wparam,
2397 "Got unexpected wparam %lx for message %x, expected %lx.\n",
2398 wparam, message, expect_messages->expect_wparam);
2400 ++expect_messages;
2404 /* KDE randomly does something with the hidden window during the
2405 * mode change that sometimes generates a WM_WINDOWPOSCHANGING
2406 * message. A WM_WINDOWPOSCHANGED message is not generated, so
2407 * just flag WM_WINDOWPOSCHANGED as bad. */
2408 if (message == WM_WINDOWPOSCHANGED)
2409 InterlockedIncrement(&windowposchanged_received);
2410 else if (message == WM_SYSCOMMAND)
2411 InterlockedIncrement(&syscommand_received);
2413 return DefWindowProcA(hwnd, message, wparam, lparam);
2416 static DWORD WINAPI wndproc_thread(void *param)
2418 struct wndproc_thread_param *p = param;
2419 DWORD res;
2420 BOOL ret;
2422 p->dummy_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
2423 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, registry_mode.dmPelsWidth,
2424 registry_mode.dmPelsHeight, 0, 0, 0, 0);
2425 p->running_in_foreground = SetForegroundWindow(p->dummy_window);
2427 ret = SetEvent(p->window_created);
2428 ok(ret, "SetEvent failed, last error %#x.\n", GetLastError());
2430 for (;;)
2432 MSG msg;
2434 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2435 res = WaitForSingleObject(p->test_finished, 100);
2436 if (res == WAIT_OBJECT_0) break;
2437 if (res != WAIT_TIMEOUT)
2439 ok(0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
2440 break;
2444 DestroyWindow(p->dummy_window);
2446 return 0;
2449 static void test_wndproc(void)
2451 struct wndproc_thread_param thread_params;
2452 struct device_desc device_desc;
2453 IDirect3DDevice8 *device;
2454 WNDCLASSA wc = {0};
2455 IDirect3D8 *d3d8;
2456 HANDLE thread;
2457 LONG_PTR proc;
2458 ULONG ref;
2459 DWORD res, tid;
2460 HWND tmp;
2461 UINT i, adapter_mode_count;
2462 HRESULT hr;
2463 D3DDISPLAYMODE d3ddm;
2464 DWORD d3d_width = 0, d3d_height = 0, user32_width = 0, user32_height = 0;
2465 DEVMODEW devmode;
2466 LONG change_ret;
2467 BOOL ret;
2469 static const struct message create_messages[] =
2471 {WM_WINDOWPOSCHANGING, FOCUS_WINDOW, FALSE, 0},
2472 /* Do not test wparam here. If device creation succeeds,
2473 * wparam is WA_ACTIVE. If device creation fails (testbot)
2474 * wparam is set to WA_INACTIVE on some Windows versions. */
2475 {WM_ACTIVATE, FOCUS_WINDOW, FALSE, 0},
2476 {WM_SETFOCUS, FOCUS_WINDOW, FALSE, 0},
2477 {WM_WINDOWPOSCHANGING, DEVICE_WINDOW, FALSE, 0},
2478 {WM_MOVE, DEVICE_WINDOW, FALSE, 0},
2479 {WM_SIZE, DEVICE_WINDOW, FALSE, 0},
2480 {0, 0, FALSE, 0},
2482 static const struct message focus_loss_messages[] =
2484 /* WM_ACTIVATE (wparam = WA_INACTIVE) is sent on Windows. It is
2485 * not reliable on X11 WMs. When the window focus follows the
2486 * mouse pointer the message is not sent.
2487 * {WM_ACTIVATE, FOCUS_WINDOW, TRUE, WA_INACTIVE}, */
2488 {WM_DISPLAYCHANGE, DEVICE_WINDOW, FALSE, 0},
2489 /* WM_DISPLAYCHANGE is sent to the focus window too, but the order is
2490 * not deterministic. */
2491 {WM_WINDOWPOSCHANGING, DEVICE_WINDOW, FALSE, 0},
2492 /* Windows sends WM_ACTIVATE to the device window, indicating that
2493 * SW_SHOWMINIMIZED is used instead of SW_MINIMIZE. Yet afterwards
2494 * the foreground and focus window are NULL. On Wine SW_SHOWMINIMIZED
2495 * leaves the device window active, breaking re-activation in the
2496 * lost device test.
2497 * {WM_ACTIVATE, DEVICE_WINDOW, TRUE, 0x200000 | WA_ACTIVE}, */
2498 {WM_WINDOWPOSCHANGED, DEVICE_WINDOW, FALSE, 0},
2499 {WM_SIZE, DEVICE_WINDOW, TRUE, SIZE_MINIMIZED},
2500 {WM_ACTIVATEAPP, FOCUS_WINDOW, TRUE, FALSE},
2501 /* WM_ACTIVATEAPP is sent to the device window too, but the order is
2502 * not deterministic. It may be sent after the focus window handling
2503 * or before. */
2504 {0, 0, FALSE, 0},
2506 static const struct message reactivate_messages[] =
2508 {WM_WINDOWPOSCHANGING, DEVICE_WINDOW, FALSE, 0},
2509 {WM_WINDOWPOSCHANGED, DEVICE_WINDOW, FALSE, 0},
2510 {WM_MOVE, DEVICE_WINDOW, FALSE, 0},
2511 {WM_ACTIVATEAPP, FOCUS_WINDOW, TRUE, TRUE},
2512 {0, 0, FALSE, 0},
2514 static const struct message focus_loss_messages_hidden[] =
2516 {WM_DISPLAYCHANGE, DEVICE_WINDOW, FALSE, 0},
2517 {WM_ACTIVATEAPP, FOCUS_WINDOW, TRUE, FALSE},
2518 {0, 0, FALSE, 0},
2520 static const struct message focus_loss_messages_filtered[] =
2522 /* WM_ACTIVATE is delivered to the window proc because it is
2523 * generated by SetForegroundWindow before the d3d routine
2524 * starts it work. Don't check for it due to focus-follows-mouse
2525 * WMs though. */
2526 {WM_DISPLAYCHANGE, FOCUS_WINDOW, FALSE, 0},
2527 {WM_ACTIVATEAPP, FOCUS_WINDOW, TRUE, FALSE},
2528 {0, 0, FALSE, 0},
2530 static const struct message reactivate_messages_filtered[] =
2532 {WM_ACTIVATEAPP, FOCUS_WINDOW, TRUE, TRUE},
2533 {0, 0, FALSE, 0},
2535 static const struct message sc_restore_messages[] =
2537 /* WM_SYSCOMMAND is delivered only once, after d3d has already
2538 * processed it. Our wndproc has no way to prevent d3d from
2539 * handling the message. The second DefWindowProc call done by
2540 * our wndproc doesn't do any changes to the window because it
2541 * is already restored due to d3d's handling. */
2542 {WM_WINDOWPOSCHANGING, FOCUS_WINDOW, FALSE, 0},
2543 {WM_WINDOWPOSCHANGED, FOCUS_WINDOW, FALSE, 0},
2544 {WM_SIZE, FOCUS_WINDOW, TRUE, SIZE_RESTORED},
2545 {WM_SYSCOMMAND, FOCUS_WINDOW, TRUE, SC_RESTORE},
2546 {0, 0, FALSE, 0},
2548 static const struct message sc_minimize_messages[] =
2550 {WM_SYSCOMMAND, FOCUS_WINDOW, TRUE, SC_MINIMIZE},
2551 {WM_WINDOWPOSCHANGING, FOCUS_WINDOW, FALSE, 0},
2552 {WM_WINDOWPOSCHANGED, FOCUS_WINDOW, FALSE, 0},
2553 {WM_MOVE, FOCUS_WINDOW, FALSE, 0},
2554 {WM_SIZE, FOCUS_WINDOW, TRUE, SIZE_MINIMIZED},
2555 {0, 0, FALSE, 0},
2557 static const struct message sc_maximize_messages[] =
2559 {WM_SYSCOMMAND, FOCUS_WINDOW, TRUE, SC_MAXIMIZE},
2560 {WM_WINDOWPOSCHANGING, FOCUS_WINDOW, FALSE, 0},
2561 {WM_WINDOWPOSCHANGED, FOCUS_WINDOW, FALSE, 0},
2562 {WM_MOVE, FOCUS_WINDOW, FALSE, 0},
2563 {WM_SIZE, FOCUS_WINDOW, TRUE, SIZE_MAXIMIZED},
2564 {0, 0, FALSE, 0},
2567 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
2568 ok(!!d3d8, "Failed to create a D3D object.\n");
2570 adapter_mode_count = IDirect3D8_GetAdapterModeCount(d3d8, D3DADAPTER_DEFAULT);
2571 for (i = 0; i < adapter_mode_count; ++i)
2573 hr = IDirect3D8_EnumAdapterModes(d3d8, D3DADAPTER_DEFAULT, i, &d3ddm);
2574 ok(SUCCEEDED(hr), "Failed to enumerate display mode, hr %#x.\n", hr);
2576 if (d3ddm.Format != D3DFMT_X8R8G8B8)
2577 continue;
2578 if (d3ddm.Width == registry_mode.dmPelsWidth && d3ddm.Height == registry_mode.dmPelsHeight)
2579 continue;
2580 /* The r200 driver on Windows XP enumerates modes like 320x200 and 320x240 but
2581 * refuses to create a device at these sizes. */
2582 if (d3ddm.Width < 640 || d3ddm.Height < 480)
2583 continue;
2585 if (!user32_width)
2587 user32_width = d3ddm.Width;
2588 user32_height = d3ddm.Height;
2589 continue;
2592 /* Make sure the d3d mode is smaller in width or height and at most
2593 * equal in the other dimension than the mode passed to
2594 * ChangeDisplaySettings. Otherwise Windows shrinks the window to
2595 * the ChangeDisplaySettings parameters + 12. */
2596 if (d3ddm.Width == user32_width && d3ddm.Height == user32_height)
2597 continue;
2598 if (d3ddm.Width <= user32_width && d3ddm.Height <= user32_height)
2600 d3d_width = d3ddm.Width;
2601 d3d_height = d3ddm.Height;
2602 break;
2604 if (user32_width <= d3ddm.Width && user32_height <= d3ddm.Height)
2606 d3d_width = user32_width;
2607 d3d_height = user32_height;
2608 user32_width = d3ddm.Width;
2609 user32_height = d3ddm.Height;
2610 break;
2614 if (!d3d_width)
2616 skip("Could not find adequate modes, skipping mode tests.\n");
2617 IDirect3D8_Release(d3d8);
2618 return;
2621 wc.lpfnWndProc = test_proc;
2622 wc.lpszClassName = "d3d8_test_wndproc_wc";
2623 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2625 thread_params.window_created = CreateEventA(NULL, FALSE, FALSE, NULL);
2626 ok(!!thread_params.window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
2627 thread_params.test_finished = CreateEventA(NULL, FALSE, FALSE, NULL);
2628 ok(!!thread_params.test_finished, "CreateEvent failed, last error %#x.\n", GetLastError());
2630 memset(&devmode, 0, sizeof(devmode));
2631 devmode.dmSize = sizeof(devmode);
2632 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
2633 devmode.dmPelsWidth = user32_width;
2634 devmode.dmPelsHeight = user32_height;
2635 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2636 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2638 focus_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
2639 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION , 0, 0, user32_width, user32_height, 0, 0, 0, 0);
2640 device_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
2641 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION , 0, 0, user32_width, user32_height, 0, 0, 0, 0);
2642 thread = CreateThread(NULL, 0, wndproc_thread, &thread_params, 0, &tid);
2643 ok(!!thread, "Failed to create thread, last error %#x.\n", GetLastError());
2645 res = WaitForSingleObject(thread_params.window_created, INFINITE);
2646 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
2648 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
2649 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2650 (LONG_PTR)test_proc, proc);
2651 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2652 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2653 (LONG_PTR)test_proc, proc);
2655 trace("device_window %p, focus_window %p, dummy_window %p.\n",
2656 device_window, focus_window, thread_params.dummy_window);
2658 tmp = GetFocus();
2659 ok(tmp == device_window, "Expected focus %p, got %p.\n", device_window, tmp);
2660 if (thread_params.running_in_foreground)
2662 tmp = GetForegroundWindow();
2663 ok(tmp == thread_params.dummy_window, "Expected foreground window %p, got %p.\n",
2664 thread_params.dummy_window, tmp);
2666 else
2667 skip("Not running in foreground, skip foreground window test\n");
2669 flush_events();
2671 expect_messages = create_messages;
2673 device_desc.device_window = device_window;
2674 device_desc.width = d3d_width;
2675 device_desc.height = d3d_height;
2676 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
2677 if (!(device = create_device(d3d8, focus_window, &device_desc)))
2679 skip("Failed to create a D3D device, skipping tests.\n");
2680 goto done;
2683 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
2684 expect_messages->message, expect_messages->window);
2685 expect_messages = NULL;
2687 if (0) /* Disabled until we can make this work in a reliable way on Wine. */
2689 tmp = GetFocus();
2690 ok(tmp == focus_window, "Expected focus %p, got %p.\n", focus_window, tmp);
2691 tmp = GetForegroundWindow();
2692 ok(tmp == focus_window, "Expected foreground window %p, got %p.\n", focus_window, tmp);
2694 SetForegroundWindow(focus_window);
2695 flush_events();
2697 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
2698 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2699 (LONG_PTR)test_proc, proc);
2701 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2702 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx.\n", (LONG_PTR)test_proc);
2704 /* Change the mode while the device is in use and then drop focus. */
2705 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
2706 devmode.dmPelsWidth = user32_width;
2707 devmode.dmPelsHeight = user32_height;
2708 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
2709 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x, i=%u.\n", change_ret, i);
2711 /* Wine doesn't (yet) mark the device not reset when the mode is changed, thus the todo_wine.
2712 * But sometimes focus-follows-mouse WMs also temporarily drop window focus, which makes
2713 * mark the device lost, then not reset, causing the test to succeed for the wrong reason. */
2714 hr = IDirect3DDevice8_TestCooperativeLevel(device);
2715 todo_wine_if (hr != D3DERR_DEVICENOTRESET)
2716 ok(hr == D3DERR_DEVICENOTRESET, "Got unexpected hr %#x.\n", hr);
2718 expect_messages = focus_loss_messages;
2719 /* SetForegroundWindow is a poor replacement for the user pressing alt-tab or
2720 * manually changing the focus. It generates the same messages, but the task
2721 * bar still shows the previous foreground window as active, and the window has
2722 * an inactive titlebar if reactivated with SetForegroundWindow. Reactivating
2723 * the device is difficult, see below. */
2724 SetForegroundWindow(GetDesktopWindow());
2725 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
2726 expect_messages->message, expect_messages->window);
2727 expect_messages = NULL;
2728 tmp = GetFocus();
2729 ok(tmp != device_window, "The device window is active.\n");
2730 ok(tmp != focus_window, "The focus window is active.\n");
2732 /* The Present call is necessary to make native realize the device is lost. */
2733 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
2734 ok(hr == D3DERR_DEVICELOST, "Got unexpected hr %#x.\n", hr);
2735 hr = IDirect3DDevice8_TestCooperativeLevel(device);
2736 /* Focus-follows-mouse WMs prematurely reactivate our window. */
2737 todo_wine_if (hr == D3DERR_DEVICENOTRESET)
2738 ok(hr == D3DERR_DEVICELOST, "Got unexpected hr %#x.\n", hr);
2740 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2741 ok(ret, "Failed to get display mode.\n");
2742 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
2743 && devmode.dmPelsHeight == registry_mode.dmPelsHeight, "Got unexpect screen size %ux%u.\n",
2744 devmode.dmPelsWidth, devmode.dmPelsHeight);
2746 /* I have to minimize and restore the focus window, otherwise native d3d9 fails
2747 * device::reset with D3DERR_DEVICELOST. This does not happen when the window
2748 * restore is triggered by the user. */
2749 expect_messages = reactivate_messages;
2750 ShowWindow(focus_window, SW_MINIMIZE);
2751 ShowWindow(focus_window, SW_RESTORE);
2752 /* Set focus twice to make KDE and fvwm in focus-follows-mouse mode happy. */
2753 SetForegroundWindow(focus_window);
2754 flush_events();
2755 SetForegroundWindow(focus_window);
2756 flush_events(); /* WM_WINDOWPOSCHANGING etc arrive after SetForegroundWindow returns. */
2757 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it, i=%u.\n",
2758 expect_messages->message, expect_messages->window, i);
2759 expect_messages = NULL;
2761 hr = IDirect3DDevice8_TestCooperativeLevel(device);
2762 ok(hr == D3DERR_DEVICENOTRESET, "Got unexpected hr %#x.\n", hr);
2764 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2765 ok(ret, "Failed to get display mode.\n");
2766 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
2767 && devmode.dmPelsHeight == registry_mode.dmPelsHeight, "Got unexpect screen size %ux%u.\n",
2768 devmode.dmPelsWidth, devmode.dmPelsHeight);
2770 hr = reset_device(device, &device_desc);
2771 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
2773 ShowWindow(device_window, SW_HIDE);
2774 flush_events();
2776 expect_messages = focus_loss_messages_hidden;
2777 windowposchanged_received = 0;
2778 SetForegroundWindow(GetDesktopWindow());
2779 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
2780 expect_messages->message, expect_messages->window);
2781 ok(!windowposchanged_received, "Received WM_WINDOWPOSCHANGED but did not expect it.\n");
2782 expect_messages = NULL;
2783 flush_events();
2785 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
2786 ok(ret, "Failed to get display mode.\n");
2787 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth, "Got unexpect width %u.\n", devmode.dmPelsWidth);
2788 ok(devmode.dmPelsHeight == registry_mode.dmPelsHeight, "Got unexpect height %u.\n", devmode.dmPelsHeight);
2790 /* SW_SHOWMINNOACTIVE is needed to make FVWM happy. SW_SHOWNOACTIVATE is needed to make windows
2791 * send SIZE_RESTORED after ShowWindow(SW_SHOWMINNOACTIVE). */
2792 ShowWindow(focus_window, SW_SHOWNOACTIVATE);
2793 ShowWindow(focus_window, SW_SHOWMINNOACTIVE);
2794 flush_events();
2796 syscommand_received = 0;
2797 expect_messages = sc_restore_messages;
2798 SendMessageA(focus_window, WM_SYSCOMMAND, SC_RESTORE, 0);
2799 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
2800 expect_messages->message, expect_messages->window);
2801 ok(syscommand_received == 1, "Got unexpected number of WM_SYSCOMMAND messages: %d.\n", syscommand_received);
2802 expect_messages = NULL;
2803 flush_events();
2805 expect_messages = sc_minimize_messages;
2806 SendMessageA(focus_window, WM_SYSCOMMAND, SC_MINIMIZE, 0);
2807 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
2808 expect_messages->message, expect_messages->window);
2809 expect_messages = NULL;
2810 flush_events();
2812 expect_messages = sc_maximize_messages;
2813 SendMessageA(focus_window, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
2814 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
2815 expect_messages->message, expect_messages->window);
2816 expect_messages = NULL;
2817 flush_events();
2819 SetForegroundWindow(GetDesktopWindow());
2820 ShowWindow(device_window, SW_MINIMIZE);
2821 ShowWindow(focus_window, SW_MINIMIZE);
2822 ShowWindow(focus_window, SW_RESTORE);
2823 SetForegroundWindow(focus_window);
2824 flush_events();
2826 /* Releasing a device in lost state breaks follow-up tests on native. */
2827 hr = reset_device(device, &device_desc);
2828 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
2830 filter_messages = focus_window;
2831 ref = IDirect3DDevice8_Release(device);
2832 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
2834 /* Fix up the mode until Wine's device release behavior is fixed. */
2835 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
2836 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
2838 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2839 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2840 (LONG_PTR)test_proc, proc);
2842 /* Hide the device window. It prevents WM_ACTIVATEAPP messages from being sent
2843 * on native in the test below. It isn't needed anyways. Creating the third
2844 * device will show it again. */
2845 filter_messages = NULL;
2846 ShowWindow(device_window, SW_HIDE);
2847 /* Remove the maximized state from the SYSCOMMAND test while we're not
2848 * interfering with a device. */
2849 ShowWindow(focus_window, SW_SHOWNORMAL);
2850 filter_messages = focus_window;
2852 device_desc.device_window = focus_window;
2853 if (!(device = create_device(d3d8, focus_window, &device_desc)))
2855 skip("Failed to create a D3D device, skipping tests.\n");
2856 goto done;
2859 filter_messages = NULL;
2861 expect_messages = focus_loss_messages_filtered;
2862 windowposchanged_received = 0;
2863 SetForegroundWindow(GetDesktopWindow());
2864 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
2865 expect_messages->message, expect_messages->window);
2866 ok(!windowposchanged_received, "Received WM_WINDOWPOSCHANGED but did not expect it.\n");
2867 expect_messages = NULL;
2869 /* The window is iconic even though no message was sent. */
2870 ok(IsIconic(focus_window), "The focus window is not iconic.\n");
2872 hr = IDirect3DDevice8_TestCooperativeLevel(device);
2873 ok(hr == D3DERR_DEVICELOST, "Got unexpected hr %#x.\n", hr);
2875 syscommand_received = 0;
2876 expect_messages = sc_restore_messages;
2877 SendMessageA(focus_window, WM_SYSCOMMAND, SC_RESTORE, 0);
2878 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
2879 expect_messages->message, expect_messages->window);
2880 ok(syscommand_received == 1, "Got unexpected number of WM_SYSCOMMAND messages: %d.\n", syscommand_received);
2881 expect_messages = NULL;
2882 flush_events();
2884 /* For FVWM. */
2885 ShowWindow(focus_window, SW_RESTORE);
2886 flush_events();
2888 expect_messages = sc_minimize_messages;
2889 SendMessageA(focus_window, WM_SYSCOMMAND, SC_MINIMIZE, 0);
2890 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
2891 expect_messages->message, expect_messages->window);
2892 expect_messages = NULL;
2893 /* Needed to make the next test reliably send WM_SIZE(SIZE_MAXIMIZED). Without
2894 * this call it sends WM_SIZE(SIZE_RESTORED). */
2895 ShowWindow(focus_window, SW_RESTORE);
2896 flush_events();
2898 expect_messages = sc_maximize_messages;
2899 SendMessageA(focus_window, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
2900 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
2901 expect_messages->message, expect_messages->window);
2902 expect_messages = NULL;
2903 SetForegroundWindow(GetDesktopWindow());
2904 flush_events();
2906 /* ShowWindow(SW_RESTORE); SetForegroundWindow(desktop); SetForegroundWindow(focus);
2907 * results in the second SetForegroundWindow call failing and the device not being
2908 * restored on native. Directly using ShowWindow(SW_RESTORE) works, but it means
2909 * we cannot test for the absence of WM_WINDOWPOSCHANGED messages. */
2910 expect_messages = reactivate_messages_filtered;
2911 ShowWindow(focus_window, SW_RESTORE);
2912 SetForegroundWindow(focus_window);
2913 flush_events();
2914 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it\n",
2915 expect_messages->message, expect_messages->window);
2916 expect_messages = NULL;
2918 filter_messages = focus_window;
2919 hr = IDirect3DDevice8_TestCooperativeLevel(device);
2920 ok(hr == D3DERR_DEVICENOTRESET, "Got unexpected hr %#x.\n", hr);
2922 hr = reset_device(device, &device_desc);
2923 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
2925 ref = IDirect3DDevice8_Release(device);
2926 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
2928 device_desc.device_window = device_window;
2929 if (!(device = create_device(d3d8, focus_window, &device_desc)))
2931 skip("Failed to create a D3D device, skipping tests.\n");
2932 goto done;
2935 proc = SetWindowLongPtrA(focus_window, GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
2936 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx.\n", (LONG_PTR)test_proc);
2938 ref = IDirect3DDevice8_Release(device);
2939 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
2941 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2942 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2943 (LONG_PTR)DefWindowProcA, proc);
2945 done:
2946 filter_messages = NULL;
2947 IDirect3D8_Release(d3d8);
2949 SetEvent(thread_params.test_finished);
2950 WaitForSingleObject(thread, INFINITE);
2951 CloseHandle(thread_params.test_finished);
2952 CloseHandle(thread_params.window_created);
2953 CloseHandle(thread);
2955 DestroyWindow(device_window);
2956 DestroyWindow(focus_window);
2957 UnregisterClassA("d3d8_test_wndproc_wc", GetModuleHandleA(NULL));
2960 static void test_wndproc_windowed(void)
2962 struct wndproc_thread_param thread_params;
2963 struct device_desc device_desc;
2964 IDirect3DDevice8 *device;
2965 WNDCLASSA wc = {0};
2966 IDirect3D8 *d3d8;
2967 HANDLE thread;
2968 LONG_PTR proc;
2969 HRESULT hr;
2970 ULONG ref;
2971 DWORD res, tid;
2972 HWND tmp;
2974 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
2975 ok(!!d3d8, "Failed to create a D3D object.\n");
2977 wc.lpfnWndProc = test_proc;
2978 wc.lpszClassName = "d3d8_test_wndproc_wc";
2979 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2981 thread_params.window_created = CreateEventA(NULL, FALSE, FALSE, NULL);
2982 ok(!!thread_params.window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
2983 thread_params.test_finished = CreateEventA(NULL, FALSE, FALSE, NULL);
2984 ok(!!thread_params.test_finished, "CreateEvent failed, last error %#x.\n", GetLastError());
2986 focus_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
2987 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, registry_mode.dmPelsWidth,
2988 registry_mode.dmPelsHeight, 0, 0, 0, 0);
2989 device_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
2990 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, registry_mode.dmPelsWidth,
2991 registry_mode.dmPelsHeight, 0, 0, 0, 0);
2992 thread = CreateThread(NULL, 0, wndproc_thread, &thread_params, 0, &tid);
2993 ok(!!thread, "Failed to create thread, last error %#x.\n", GetLastError());
2995 res = WaitForSingleObject(thread_params.window_created, INFINITE);
2996 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
2998 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
2999 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3000 (LONG_PTR)test_proc, proc);
3001 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3002 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3003 (LONG_PTR)test_proc, proc);
3005 trace("device_window %p, focus_window %p, dummy_window %p.\n",
3006 device_window, focus_window, thread_params.dummy_window);
3008 tmp = GetFocus();
3009 ok(tmp == device_window, "Expected focus %p, got %p.\n", device_window, tmp);
3010 if (thread_params.running_in_foreground)
3012 tmp = GetForegroundWindow();
3013 ok(tmp == thread_params.dummy_window, "Expected foreground window %p, got %p.\n",
3014 thread_params.dummy_window, tmp);
3016 else
3017 skip("Not running in foreground, skip foreground window test\n");
3019 filter_messages = focus_window;
3021 device_desc.device_window = device_window;
3022 device_desc.width = registry_mode.dmPelsWidth;
3023 device_desc.height = registry_mode.dmPelsHeight;
3024 device_desc.flags = 0;
3025 if (!(device = create_device(d3d8, focus_window, &device_desc)))
3027 skip("Failed to create a D3D device, skipping tests.\n");
3028 goto done;
3031 tmp = GetFocus();
3032 ok(tmp == device_window, "Expected focus %p, got %p.\n", device_window, tmp);
3033 tmp = GetForegroundWindow();
3034 ok(tmp == thread_params.dummy_window, "Expected foreground window %p, got %p.\n",
3035 thread_params.dummy_window, tmp);
3037 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
3038 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3039 (LONG_PTR)test_proc, proc);
3041 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3042 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3043 (LONG_PTR)test_proc, proc);
3045 filter_messages = NULL;
3047 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
3048 hr = reset_device(device, &device_desc);
3049 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
3051 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
3052 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3053 (LONG_PTR)test_proc, proc);
3055 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3056 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx.\n", (LONG_PTR)test_proc);
3058 device_desc.flags = 0;
3059 hr = reset_device(device, &device_desc);
3060 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
3062 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
3063 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3064 (LONG_PTR)test_proc, proc);
3066 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3067 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3068 (LONG_PTR)test_proc, proc);
3070 filter_messages = focus_window;
3072 ref = IDirect3DDevice8_Release(device);
3073 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
3075 filter_messages = device_window;
3077 device_desc.device_window = focus_window;
3078 if (!(device = create_device(d3d8, focus_window, &device_desc)))
3080 skip("Failed to create a D3D device, skipping tests.\n");
3081 goto done;
3084 filter_messages = NULL;
3086 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
3087 hr = reset_device(device, &device_desc);
3088 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
3090 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
3091 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3092 (LONG_PTR)test_proc, proc);
3094 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3095 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx.\n", (LONG_PTR)test_proc);
3097 device_desc.flags = 0;
3098 hr = reset_device(device, &device_desc);
3099 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
3101 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
3102 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3103 (LONG_PTR)test_proc, proc);
3105 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3106 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3107 (LONG_PTR)test_proc, proc);
3109 filter_messages = device_window;
3111 ref = IDirect3DDevice8_Release(device);
3112 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
3114 device_desc.device_window = device_window;
3115 if (!(device = create_device(d3d8, focus_window, &device_desc)))
3117 skip("Failed to create a D3D device, skipping tests.\n");
3118 goto done;
3121 filter_messages = NULL;
3123 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
3124 hr = reset_device(device, &device_desc);
3125 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
3127 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
3128 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3129 (LONG_PTR)test_proc, proc);
3131 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3132 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx.\n", (LONG_PTR)test_proc);
3134 device_desc.flags = 0;
3135 hr = reset_device(device, &device_desc);
3136 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
3138 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
3139 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3140 (LONG_PTR)test_proc, proc);
3142 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3143 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3144 (LONG_PTR)test_proc, proc);
3146 filter_messages = device_window;
3148 ref = IDirect3DDevice8_Release(device);
3149 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
3151 done:
3152 filter_messages = NULL;
3153 IDirect3D8_Release(d3d8);
3155 SetEvent(thread_params.test_finished);
3156 WaitForSingleObject(thread, INFINITE);
3157 CloseHandle(thread_params.test_finished);
3158 CloseHandle(thread_params.window_created);
3159 CloseHandle(thread);
3161 DestroyWindow(device_window);
3162 DestroyWindow(focus_window);
3163 UnregisterClassA("d3d8_test_wndproc_wc", GetModuleHandleA(NULL));
3166 static inline void set_fpu_cw(WORD cw)
3168 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3169 #define D3D8_TEST_SET_FPU_CW 1
3170 __asm__ volatile ("fnclex");
3171 __asm__ volatile ("fldcw %0" : : "m" (cw));
3172 #elif defined(__i386__) && defined(_MSC_VER)
3173 #define D3D8_TEST_SET_FPU_CW 1
3174 __asm fnclex;
3175 __asm fldcw cw;
3176 #endif
3179 static inline WORD get_fpu_cw(void)
3181 WORD cw = 0;
3182 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3183 #define D3D8_TEST_GET_FPU_CW 1
3184 __asm__ volatile ("fnstcw %0" : "=m" (cw));
3185 #elif defined(__i386__) && defined(_MSC_VER)
3186 #define D3D8_TEST_GET_FPU_CW 1
3187 __asm fnstcw cw;
3188 #endif
3189 return cw;
3192 static WORD callback_cw, callback_set_cw;
3193 static DWORD callback_tid;
3195 static HRESULT WINAPI dummy_object_QueryInterface(IUnknown *iface, REFIID riid, void **out)
3197 *out = NULL;
3198 return E_NOINTERFACE;
3201 static ULONG WINAPI dummy_object_AddRef(IUnknown *iface)
3203 callback_cw = get_fpu_cw();
3204 set_fpu_cw(callback_set_cw);
3205 callback_tid = GetCurrentThreadId();
3206 return 2;
3209 static ULONG WINAPI dummy_object_Release(IUnknown *iface)
3211 callback_cw = get_fpu_cw();
3212 set_fpu_cw(callback_set_cw);
3213 callback_tid = GetCurrentThreadId();
3214 return 1;
3217 static const IUnknownVtbl dummy_object_vtbl =
3219 dummy_object_QueryInterface,
3220 dummy_object_AddRef,
3221 dummy_object_Release,
3224 static const GUID d3d8_private_data_test_guid =
3226 0xfdb37466,
3227 0x428f,
3228 0x4edf,
3229 {0xa3,0x7f,0x9b,0x1d,0xf4,0x88,0xc5,0xfc}
3232 static void test_fpu_setup(void)
3234 #if defined(D3D8_TEST_SET_FPU_CW) && defined(D3D8_TEST_GET_FPU_CW)
3235 struct device_desc device_desc;
3236 IDirect3DDevice8 *device;
3237 D3DDISPLAYMODE d3ddm;
3238 IDirect3D8 *d3d8;
3239 HWND window;
3240 HRESULT hr;
3241 WORD cw;
3242 IDirect3DSurface8 *surface;
3243 IUnknown dummy_object = {&dummy_object_vtbl};
3245 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_CAPTION, 0, 0,
3246 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight, 0, 0, 0, 0);
3247 ok(!!window, "Failed to create a window.\n");
3248 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
3249 ok(!!d3d8, "Failed to create a D3D object.\n");
3251 hr = IDirect3D8_GetAdapterDisplayMode(d3d8, D3DADAPTER_DEFAULT, &d3ddm);
3252 ok(SUCCEEDED(hr), "GetAdapterDisplayMode failed, hr %#x.\n", hr);
3254 device_desc.device_window = window;
3255 device_desc.width = 640;
3256 device_desc.height = 480;
3257 device_desc.flags = 0;
3259 set_fpu_cw(0xf60);
3260 cw = get_fpu_cw();
3261 ok(cw == 0xf60, "cw is %#x, expected 0xf60.\n", cw);
3263 if (!(device = create_device(d3d8, window, &device_desc)))
3265 skip("Failed to create a 3D device, skipping test.\n");
3266 set_fpu_cw(0x37f);
3267 goto done;
3270 cw = get_fpu_cw();
3271 ok(cw == 0x7f, "cw is %#x, expected 0x7f.\n", cw);
3273 hr = IDirect3DDevice8_GetRenderTarget(device, &surface);
3274 ok(SUCCEEDED(hr), "Failed to get render target surface, hr %#x.\n", hr);
3276 callback_set_cw = 0xf60;
3277 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
3278 &dummy_object, sizeof(IUnknown *), D3DSPD_IUNKNOWN);
3279 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
3280 ok(callback_cw == 0x7f, "Callback cw is %#x, expected 0x7f.\n", callback_cw);
3281 ok(callback_tid == GetCurrentThreadId(), "Got unexpected thread id.\n");
3282 cw = get_fpu_cw();
3283 ok(cw == 0xf60, "cw is %#x, expected 0xf60.\n", cw);
3285 callback_cw = 0;
3286 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
3287 &dummy_object, sizeof(IUnknown *), D3DSPD_IUNKNOWN);
3288 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
3289 ok(callback_cw == 0xf60, "Callback cw is %#x, expected 0xf60.\n", callback_cw);
3290 ok(callback_tid == GetCurrentThreadId(), "Got unexpected thread id.\n");
3292 callback_set_cw = 0x7f;
3293 set_fpu_cw(0x7f);
3295 IDirect3DSurface8_Release(surface);
3297 callback_cw = 0;
3298 IDirect3DDevice8_Release(device);
3299 ok(callback_cw == 0x7f, "Callback cw is %#x, expected 0x7f.\n", callback_cw);
3300 ok(callback_tid == GetCurrentThreadId(), "Got unexpected thread id.\n");
3302 cw = get_fpu_cw();
3303 ok(cw == 0x7f, "cw is %#x, expected 0x7f.\n", cw);
3304 set_fpu_cw(0xf60);
3305 cw = get_fpu_cw();
3306 ok(cw == 0xf60, "cw is %#x, expected 0xf60.\n", cw);
3308 device_desc.flags = CREATE_DEVICE_FPU_PRESERVE;
3309 device = create_device(d3d8, window, &device_desc);
3310 ok(!!device, "CreateDevice failed.\n");
3312 cw = get_fpu_cw();
3313 ok(cw == 0xf60, "cw is %#x, expected 0xf60.\n", cw);
3315 hr = IDirect3DDevice8_GetRenderTarget(device, &surface);
3316 ok(SUCCEEDED(hr), "Failed to get render target surface, hr %#x.\n", hr);
3318 callback_cw = 0;
3319 callback_set_cw = 0x37f;
3320 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
3321 &dummy_object, sizeof(IUnknown *), D3DSPD_IUNKNOWN);
3322 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
3323 ok(callback_cw == 0xf60, "Callback cw is %#x, expected 0xf60.\n", callback_cw);
3324 ok(callback_tid == GetCurrentThreadId(), "Got unexpected thread id.\n");
3325 cw = get_fpu_cw();
3326 ok(cw == 0x37f, "cw is %#x, expected 0x37f.\n", cw);
3328 IDirect3DSurface8_Release(surface);
3330 callback_cw = 0;
3331 IDirect3DDevice8_Release(device);
3332 ok(callback_cw == 0x37f, "Callback cw is %#x, expected 0x37f.\n", callback_cw);
3333 ok(callback_tid == GetCurrentThreadId(), "Got unexpected thread id.\n");
3335 done:
3336 DestroyWindow(window);
3337 IDirect3D8_Release(d3d8);
3338 #endif
3341 static void test_ApplyStateBlock(void)
3343 IDirect3DDevice8 *device;
3344 IDirect3D8 *d3d8;
3345 HWND window;
3346 HRESULT hr;
3347 DWORD received, token;
3349 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
3350 0, 0, 640, 480, NULL, NULL, NULL, NULL);
3351 ok(!!window, "Failed to create a window.\n");
3352 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
3353 ok(!!d3d8, "Failed to create a D3D object.\n");
3354 if (!(device = create_device(d3d8, window, NULL)))
3356 skip("Failed to create a 3D device, skipping test.\n");
3357 goto cleanup;
3360 IDirect3DDevice8_BeginStateBlock(device);
3361 IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, TRUE);
3362 IDirect3DDevice8_EndStateBlock(device, &token);
3363 ok(token, "Received zero stateblock handle.\n");
3364 IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, FALSE);
3366 hr = IDirect3DDevice8_GetRenderState(device, D3DRS_ZENABLE, &received);
3367 ok(hr == D3D_OK, "Expected D3D_OK, received %#x.\n", hr);
3368 ok(!received, "Expected = FALSE, received TRUE.\n");
3370 hr = IDirect3DDevice8_ApplyStateBlock(device, 0);
3371 ok(hr == D3D_OK, "Expected D3D_OK, received %#x.\n", hr);
3372 hr = IDirect3DDevice8_GetRenderState(device, D3DRS_ZENABLE, &received);
3373 ok(hr == D3D_OK, "Expected D3D_OK, received %#x.\n", hr);
3374 ok(!received, "Expected FALSE, received TRUE.\n");
3376 hr = IDirect3DDevice8_ApplyStateBlock(device, token);
3377 ok(hr == D3D_OK, "Expected D3D_OK, received %#x.\n", hr);
3378 hr = IDirect3DDevice8_GetRenderState(device, D3DRS_ZENABLE, &received);
3379 ok(hr == D3D_OK, "Expected D3D_OK, received %#x.\n", hr);
3380 ok(received, "Expected TRUE, received FALSE.\n");
3382 IDirect3DDevice8_DeleteStateBlock(device, token);
3383 IDirect3DDevice8_Release(device);
3384 cleanup:
3385 IDirect3D8_Release(d3d8);
3386 DestroyWindow(window);
3389 static void test_depth_stencil_size(void)
3391 IDirect3DDevice8 *device;
3392 IDirect3DSurface8 *ds, *rt, *ds_bigger, *ds_bigger2;
3393 IDirect3DSurface8 *surf;
3394 IDirect3D8 *d3d8;
3395 HRESULT hr;
3396 HWND hwnd;
3398 hwnd = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
3399 100, 100, 160, 160, NULL, NULL, NULL, NULL);
3400 ok(!!hwnd, "Failed to create a window.\n");
3401 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
3402 ok(!!d3d8, "Failed to create a D3D object.\n");
3404 if (!(device = create_device(d3d8, hwnd, NULL)))
3406 skip("Failed to create a 3D device, skipping test.\n");
3407 goto cleanup;
3410 hr = IDirect3DDevice8_CreateRenderTarget(device, 64, 64, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, FALSE, &rt);
3411 ok(SUCCEEDED(hr), "IDirect3DDevice8_CreateRenderTarget failed, hr %#x.\n", hr);
3412 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 32, 32, D3DFMT_D24X8, D3DMULTISAMPLE_NONE, &ds);
3413 ok(SUCCEEDED(hr), "IDirect3DDevice8_CreateDepthStencilSurface failed, hr %#x.\n", hr);
3414 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 128, 128, D3DFMT_D24X8, D3DMULTISAMPLE_NONE, &ds_bigger);
3415 ok(SUCCEEDED(hr), "IDirect3DDevice8_CreateDepthStencilSurface failed, hr %#x.\n", hr);
3416 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 128, 128, D3DFMT_D24X8, D3DMULTISAMPLE_NONE, &ds_bigger2);
3417 ok(SUCCEEDED(hr), "IDirect3DDevice8_CreateDepthStencilSurface failed, hr %#x.\n", hr);
3419 hr = IDirect3DDevice8_SetRenderTarget(device, rt, ds);
3420 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_SetRenderTarget returned %#x, expected D3DERR_INVALIDCALL.\n", hr);
3421 hr = IDirect3DDevice8_SetRenderTarget(device, rt, ds_bigger);
3422 ok(SUCCEEDED(hr), "IDirect3DDevice8_SetRenderTarget failed, hr %#x.\n", hr);
3424 /* try to set the small ds without changing the render target at the same time */
3425 hr = IDirect3DDevice8_SetRenderTarget(device, NULL, ds);
3426 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_SetRenderTarget returned %#x, expected D3DERR_INVALIDCALL.\n", hr);
3427 hr = IDirect3DDevice8_SetRenderTarget(device, NULL, ds_bigger2);
3428 ok(SUCCEEDED(hr), "IDirect3DDevice8_SetRenderTarget failed, hr %#x.\n", hr);
3430 hr = IDirect3DDevice8_GetRenderTarget(device, &surf);
3431 ok(hr == D3D_OK, "IDirect3DDevice8_GetRenderTarget failed, hr %#x.\n", hr);
3432 ok(surf == rt, "The render target is %p, expected %p\n", surf, rt);
3433 IDirect3DSurface8_Release(surf);
3434 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surf);
3435 ok(hr == D3D_OK, "IDirect3DDevice8_GetDepthStencilSurface failed, hr %#x.\n", hr);
3436 ok(surf == ds_bigger2, "The depth stencil is %p, expected %p\n", surf, ds_bigger2);
3437 IDirect3DSurface8_Release(surf);
3439 hr = IDirect3DDevice8_SetRenderTarget(device, NULL, NULL);
3440 ok(SUCCEEDED(hr), "IDirect3DDevice8_SetRenderTarget failed, hr %#x.\n", hr);
3441 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &surf);
3442 ok(FAILED(hr), "IDirect3DDevice8_GetDepthStencilSurface should have failed, hr %#x.\n", hr);
3443 ok(surf == NULL, "The depth stencil is %p, expected NULL\n", surf);
3444 if (surf) IDirect3DSurface8_Release(surf);
3446 IDirect3DSurface8_Release(rt);
3447 IDirect3DSurface8_Release(ds);
3448 IDirect3DSurface8_Release(ds_bigger);
3449 IDirect3DSurface8_Release(ds_bigger2);
3451 cleanup:
3452 IDirect3D8_Release(d3d8);
3453 DestroyWindow(hwnd);
3456 static void test_window_style(void)
3458 RECT focus_rect, fullscreen_rect, r;
3459 LONG device_style, device_exstyle;
3460 LONG focus_style, focus_exstyle;
3461 struct device_desc device_desc;
3462 LONG style, expected_style;
3463 IDirect3DDevice8 *device;
3464 IDirect3D8 *d3d8;
3465 HRESULT hr;
3466 ULONG ref;
3467 BOOL ret;
3469 focus_window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
3470 0, 0, registry_mode.dmPelsWidth / 2, registry_mode.dmPelsHeight / 2, 0, 0, 0, 0);
3471 device_window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
3472 0, 0, registry_mode.dmPelsWidth / 2, registry_mode.dmPelsHeight / 2, 0, 0, 0, 0);
3473 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
3474 ok(!!d3d8, "Failed to create a D3D object.\n");
3476 device_style = GetWindowLongA(device_window, GWL_STYLE);
3477 device_exstyle = GetWindowLongA(device_window, GWL_EXSTYLE);
3478 focus_style = GetWindowLongA(focus_window, GWL_STYLE);
3479 focus_exstyle = GetWindowLongA(focus_window, GWL_EXSTYLE);
3481 SetRect(&fullscreen_rect, 0, 0, registry_mode.dmPelsWidth, registry_mode.dmPelsHeight);
3482 GetWindowRect(focus_window, &focus_rect);
3484 device_desc.device_window = device_window;
3485 device_desc.width = registry_mode.dmPelsWidth;
3486 device_desc.height = registry_mode.dmPelsHeight;
3487 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
3488 if (!(device = create_device(d3d8, focus_window, &device_desc)))
3490 skip("Failed to create a D3D device, skipping tests.\n");
3491 goto done;
3494 style = GetWindowLongA(device_window, GWL_STYLE);
3495 expected_style = device_style | WS_VISIBLE;
3496 todo_wine ok(style == expected_style, "Expected device window style %#x, got %#x.\n",
3497 expected_style, style);
3498 style = GetWindowLongA(device_window, GWL_EXSTYLE);
3499 expected_style = device_exstyle | WS_EX_TOPMOST;
3500 todo_wine ok(style == expected_style, "Expected device window extended style %#x, got %#x.\n",
3501 expected_style, style);
3503 style = GetWindowLongA(focus_window, GWL_STYLE);
3504 ok(style == focus_style, "Expected focus window style %#x, got %#x.\n",
3505 focus_style, style);
3506 style = GetWindowLongA(focus_window, GWL_EXSTYLE);
3507 ok(style == focus_exstyle, "Expected focus window extended style %#x, got %#x.\n",
3508 focus_exstyle, style);
3510 GetWindowRect(device_window, &r);
3511 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3512 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
3513 r.left, r.top, r.right, r.bottom);
3514 GetClientRect(device_window, &r);
3515 todo_wine ok(!EqualRect(&r, &fullscreen_rect), "Client rect and window rect are equal.\n");
3516 GetWindowRect(focus_window, &r);
3517 ok(EqualRect(&r, &focus_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3518 focus_rect.left, focus_rect.top, focus_rect.right, focus_rect.bottom,
3519 r.left, r.top, r.right, r.bottom);
3521 device_desc.flags = 0;
3522 hr = reset_device(device, &device_desc);
3523 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
3525 style = GetWindowLongA(device_window, GWL_STYLE);
3526 expected_style = device_style | WS_VISIBLE;
3527 ok(style == expected_style, "Expected device window style %#x, got %#x.\n",
3528 expected_style, style);
3529 style = GetWindowLongA(device_window, GWL_EXSTYLE);
3530 expected_style = device_exstyle | WS_EX_TOPMOST;
3531 ok(style == expected_style, "Expected device window extended style %#x, got %#x.\n",
3532 expected_style, style);
3534 style = GetWindowLongA(focus_window, GWL_STYLE);
3535 ok(style == focus_style, "Expected focus window style %#x, got %#x.\n",
3536 focus_style, style);
3537 style = GetWindowLongA(focus_window, GWL_EXSTYLE);
3538 ok(style == focus_exstyle, "Expected focus window extended style %#x, got %#x.\n",
3539 focus_exstyle, style);
3541 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
3542 hr = reset_device(device, &device_desc);
3543 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
3544 ret = SetForegroundWindow(GetDesktopWindow());
3545 ok(ret, "Failed to set foreground window.\n");
3547 style = GetWindowLongA(device_window, GWL_STYLE);
3548 expected_style = device_style | WS_MINIMIZE | WS_VISIBLE;
3549 todo_wine ok(style == expected_style, "Expected device window style %#x, got %#x.\n",
3550 expected_style, style);
3551 style = GetWindowLongA(device_window, GWL_EXSTYLE);
3552 expected_style = device_exstyle | WS_EX_TOPMOST;
3553 todo_wine ok(style == expected_style, "Expected device window extended style %#x, got %#x.\n",
3554 expected_style, style);
3556 style = GetWindowLongA(focus_window, GWL_STYLE);
3557 ok(style == focus_style, "Expected focus window style %#x, got %#x.\n",
3558 focus_style, style);
3559 style = GetWindowLongA(focus_window, GWL_EXSTYLE);
3560 ok(style == focus_exstyle, "Expected focus window extended style %#x, got %#x.\n",
3561 focus_exstyle, style);
3563 /* Follow-up tests fail on native if the device is destroyed while lost. */
3564 ShowWindow(focus_window, SW_MINIMIZE);
3565 ShowWindow(focus_window, SW_RESTORE);
3566 ret = SetForegroundWindow(focus_window);
3567 ok(ret, "Failed to set foreground window.\n");
3568 flush_events();
3569 hr = reset_device(device, &device_desc);
3570 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
3572 ref = IDirect3DDevice8_Release(device);
3573 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
3575 done:
3576 IDirect3D8_Release(d3d8);
3578 DestroyWindow(device_window);
3579 DestroyWindow(focus_window);
3582 static void test_unsupported_shaders(void)
3584 IDirect3DDevice8 *device;
3585 IDirect3D8 *d3d;
3586 ULONG refcount;
3587 DWORD vs, ps;
3588 HWND window;
3589 HRESULT hr;
3590 D3DCAPS8 caps;
3592 static const DWORD vs_2_0[] =
3594 0xfffe0200, /* vs_2_0 */
3595 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
3596 0x02000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
3597 0x03000002, 0xd00f0000, 0x80e40001, 0xa0e40002, /* add oD0, r1, c2 */
3598 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
3599 0x0000ffff /* end */
3601 static const DWORD ps_2_0[] =
3603 0xffff0200, /* ps_2_0 */
3604 0x02000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
3605 0x03000002, 0x800f0000, 0x80e40001, 0xa0e40002, /* add r0, r1, c2 */
3606 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
3607 0x0000ffff /* end */
3609 #if 0
3610 vs_1_1
3611 dcl_position v0
3612 def c255, 1.0, 1.0, 1.0, 1.0
3613 add r0, v0, c255
3614 mov oPos, r0
3615 #endif
3616 static const DWORD vs_1_255[] =
3618 0xfffe0101,
3619 0x0000001f, 0x80000000, 0x900f0000,
3620 0x00000051, 0xa00f00ff, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
3621 0x00000002, 0x800f0000, 0x90e40000, 0xa0e400ff,
3622 0x00000001, 0xc00f0000, 0x80e40000,
3623 0x0000ffff
3625 #if 0
3626 vs_1_1
3627 dcl_position v0
3628 def c256, 1.0, 1.0, 1.0, 1.0
3629 add r0, v0, c256
3630 mov oPos, r0
3631 #endif
3632 static const DWORD vs_1_256[] =
3634 0xfffe0101,
3635 0x0000001f, 0x80000000, 0x900f0000,
3636 0x00000051, 0xa00f0100, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
3637 0x00000002, 0x800f0000, 0x90e40000, 0xa0e40100,
3638 0x00000001, 0xc00f0000, 0x80e40000,
3639 0x0000ffff
3642 static const DWORD decl[] =
3644 D3DVSD_STREAM(0),
3645 D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3),
3646 D3DVSD_END()
3649 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
3650 0, 0, 640, 480, NULL, NULL, NULL, NULL);
3651 ok(!!window, "Failed to create a window.\n");
3652 d3d = Direct3DCreate8(D3D_SDK_VERSION);
3653 ok(!!d3d, "Failed to create a D3D object.\n");
3654 if (!(device = create_device(d3d, window, NULL)))
3656 skip("Failed to create a D3D device, skipping tests.\n");
3657 IDirect3D8_Release(d3d);
3658 DestroyWindow(window);
3659 return;
3662 hr = IDirect3DDevice8_CreateVertexShader(device, decl, simple_ps, &vs, 0);
3663 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
3665 hr = IDirect3DDevice8_CreatePixelShader(device, simple_vs, &ps);
3666 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr);
3668 hr = IDirect3DDevice8_CreateVertexShader(device, decl, vs_2_0, &vs, 0);
3669 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr);
3671 hr = IDirect3DDevice8_CreatePixelShader(device, ps_2_0, &ps);
3672 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr);
3674 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
3675 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
3676 if (caps.MaxVertexShaderConst < 256)
3678 hr = IDirect3DDevice8_CreateVertexShader(device, decl, vs_1_255, &vs, 0);
3679 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3681 else
3683 hr = IDirect3DDevice8_CreateVertexShader(device, decl, vs_1_255, &vs, 0);
3684 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
3685 hr = IDirect3DDevice8_DeleteVertexShader(device, vs);
3686 ok(hr == D3D_OK, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr);
3687 hr = IDirect3DDevice8_CreateVertexShader(device, decl, vs_1_256, &vs, 0);
3688 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
3691 refcount = IDirect3DDevice8_Release(device);
3692 ok(!refcount, "Device has %u references left.\n", refcount);
3693 IDirect3D8_Release(d3d);
3694 DestroyWindow(window);
3697 static void test_mode_change(void)
3699 RECT d3d_rect, focus_rect, r;
3700 struct device_desc device_desc;
3701 IDirect3DSurface8 *backbuffer;
3702 IDirect3DDevice8 *device;
3703 D3DSURFACE_DESC desc;
3704 IDirect3D8 *d3d8;
3705 DEVMODEW devmode;
3706 ULONG refcount;
3707 UINT adapter_mode_count, i;
3708 HRESULT hr;
3709 BOOL ret;
3710 LONG change_ret;
3711 D3DDISPLAYMODE d3ddm;
3712 DWORD d3d_width = 0, d3d_height = 0, user32_width = 0, user32_height = 0;
3714 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
3715 ok(!!d3d8, "Failed to create a D3D object.\n");
3717 adapter_mode_count = IDirect3D8_GetAdapterModeCount(d3d8, D3DADAPTER_DEFAULT);
3718 for (i = 0; i < adapter_mode_count; ++i)
3720 hr = IDirect3D8_EnumAdapterModes(d3d8, D3DADAPTER_DEFAULT, i, &d3ddm);
3721 ok(SUCCEEDED(hr), "Failed to enumerate display mode, hr %#x.\n", hr);
3723 if (d3ddm.Format != D3DFMT_X8R8G8B8)
3724 continue;
3725 if (d3ddm.Width == registry_mode.dmPelsWidth && d3ddm.Height == registry_mode.dmPelsHeight)
3726 continue;
3727 /* The r200 driver on Windows XP enumerates modes like 320x200 and 320x240 but
3728 * refuses to create a device at these sizes. */
3729 if (d3ddm.Width < 640 || d3ddm.Height < 480)
3730 continue;
3732 if (!user32_width)
3734 user32_width = d3ddm.Width;
3735 user32_height = d3ddm.Height;
3736 continue;
3739 /* Make sure the d3d mode is smaller in width or height and at most
3740 * equal in the other dimension than the mode passed to
3741 * ChangeDisplaySettings. Otherwise Windows shrinks the window to
3742 * the ChangeDisplaySettings parameters + 12. */
3743 if (d3ddm.Width == user32_width && d3ddm.Height == user32_height)
3744 continue;
3745 if (d3ddm.Width <= user32_width && d3ddm.Height <= user32_height)
3747 d3d_width = d3ddm.Width;
3748 d3d_height = d3ddm.Height;
3749 break;
3751 if (user32_width <= d3ddm.Width && user32_height <= d3ddm.Height)
3753 d3d_width = user32_width;
3754 d3d_height = user32_height;
3755 user32_width = d3ddm.Width;
3756 user32_height = d3ddm.Height;
3757 break;
3761 if (!d3d_width)
3763 skip("Could not find adequate modes, skipping mode tests.\n");
3764 IDirect3D8_Release(d3d8);
3765 return;
3768 memset(&devmode, 0, sizeof(devmode));
3769 devmode.dmSize = sizeof(devmode);
3770 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
3771 devmode.dmPelsWidth = user32_width;
3772 devmode.dmPelsHeight = user32_height;
3773 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
3774 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
3776 /* Make the windows visible, otherwise device::release does not restore the mode if
3777 * the application is not in foreground like on the testbot. */
3778 focus_window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
3779 0, 0, user32_width / 2, user32_height / 2, 0, 0, 0, 0);
3780 device_window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
3781 0, 0, user32_width / 2, user32_height / 2, 0, 0, 0, 0);
3783 SetRect(&d3d_rect, 0, 0, d3d_width, d3d_height);
3784 GetWindowRect(focus_window, &focus_rect);
3786 device_desc.device_window = device_window;
3787 device_desc.width = d3d_width;
3788 device_desc.height = d3d_height;
3789 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
3790 if (!(device = create_device(d3d8, focus_window, &device_desc)))
3792 skip("Failed to create a D3D device, skipping tests.\n");
3793 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
3794 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
3795 goto done;
3798 devmode.dmPelsWidth = user32_width;
3799 devmode.dmPelsHeight = user32_height;
3800 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
3801 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
3803 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
3804 ok(ret, "Failed to get display mode.\n");
3805 ok(devmode.dmPelsWidth == user32_width && devmode.dmPelsHeight == user32_height,
3806 "Expected resolution %ux%u, got %ux%u.\n",
3807 user32_width, user32_height, devmode.dmPelsWidth, devmode.dmPelsHeight);
3809 GetWindowRect(device_window, &r);
3810 ok(EqualRect(&r, &d3d_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3811 d3d_rect.left, d3d_rect.top, d3d_rect.right, d3d_rect.bottom,
3812 r.left, r.top, r.right, r.bottom);
3813 GetWindowRect(focus_window, &r);
3814 ok(EqualRect(&r, &focus_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3815 focus_rect.left, focus_rect.top, focus_rect.right, focus_rect.bottom,
3816 r.left, r.top, r.right, r.bottom);
3818 hr = IDirect3DDevice8_GetBackBuffer(device, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
3819 ok(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
3820 hr = IDirect3DSurface8_GetDesc(backbuffer, &desc);
3821 ok(SUCCEEDED(hr), "Failed to get backbuffer desc, hr %#x.\n", hr);
3822 ok(desc.Width == d3d_width, "Got unexpected backbuffer width %u, expected %u.\n",
3823 desc.Width, d3d_width);
3824 ok(desc.Height == d3d_height, "Got unexpected backbuffer height %u, expected %u.\n",
3825 desc.Height, d3d_height);
3826 IDirect3DSurface8_Release(backbuffer);
3828 refcount = IDirect3DDevice8_Release(device);
3829 ok(!refcount, "Device has %u references left.\n", refcount);
3831 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
3832 ok(ret, "Failed to get display mode.\n");
3833 todo_wine ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
3834 && devmode.dmPelsHeight == registry_mode.dmPelsHeight,
3835 "Expected resolution %ux%u, got %ux%u.\n",
3836 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight, devmode.dmPelsWidth, devmode.dmPelsHeight);
3838 change_ret = ChangeDisplaySettingsW(NULL, CDS_FULLSCREEN);
3839 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
3841 /* The mode restore also happens when the device was created at the original screen size. */
3843 device_desc.device_window = device_window;
3844 device_desc.width = registry_mode.dmPelsWidth;
3845 device_desc.height = registry_mode.dmPelsHeight;
3846 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
3847 ok(!!(device = create_device(d3d8, focus_window, &device_desc)), "Failed to create a D3D device.\n");
3849 devmode.dmPelsWidth = user32_width;
3850 devmode.dmPelsHeight = user32_height;
3851 change_ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
3852 ok(change_ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", change_ret);
3854 refcount = IDirect3DDevice8_Release(device);
3855 ok(!refcount, "Device has %u references left.\n", refcount);
3857 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
3858 ok(ret, "Failed to get display mode.\n");
3859 ok(devmode.dmPelsWidth == registry_mode.dmPelsWidth
3860 && devmode.dmPelsHeight == registry_mode.dmPelsHeight,
3861 "Expected resolution %ux%u, got %ux%u.\n",
3862 registry_mode.dmPelsWidth, registry_mode.dmPelsHeight, devmode.dmPelsWidth, devmode.dmPelsHeight);
3864 done:
3865 DestroyWindow(device_window);
3866 DestroyWindow(focus_window);
3867 IDirect3D8_Release(d3d8);
3870 static void test_device_window_reset(void)
3872 RECT fullscreen_rect, device_rect, r;
3873 struct device_desc device_desc;
3874 IDirect3DDevice8 *device;
3875 WNDCLASSA wc = {0};
3876 IDirect3D8 *d3d8;
3877 LONG_PTR proc;
3878 HRESULT hr;
3879 ULONG ref;
3881 wc.lpfnWndProc = test_proc;
3882 wc.lpszClassName = "d3d8_test_wndproc_wc";
3883 ok(RegisterClassA(&wc), "Failed to register window class.\n");
3885 focus_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
3886 0, 0, registry_mode.dmPelsWidth / 2, registry_mode.dmPelsHeight / 2, 0, 0, 0, 0);
3887 device_window = CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
3888 0, 0, registry_mode.dmPelsWidth / 2, registry_mode.dmPelsHeight / 2, 0, 0, 0, 0);
3889 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
3890 ok(!!d3d8, "Failed to create a D3D object.\n");
3892 SetRect(&fullscreen_rect, 0, 0, registry_mode.dmPelsWidth, registry_mode.dmPelsHeight);
3893 GetWindowRect(device_window, &device_rect);
3895 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
3896 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3897 (LONG_PTR)test_proc, proc);
3898 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3899 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3900 (LONG_PTR)test_proc, proc);
3902 device_desc.device_window = NULL;
3903 device_desc.width = registry_mode.dmPelsWidth;
3904 device_desc.height = registry_mode.dmPelsHeight;
3905 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
3906 if (!(device = create_device(d3d8, focus_window, &device_desc)))
3908 skip("Failed to create a D3D device, skipping tests.\n");
3909 goto done;
3912 GetWindowRect(focus_window, &r);
3913 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3914 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
3915 r.left, r.top, r.right, r.bottom);
3916 GetWindowRect(device_window, &r);
3917 ok(EqualRect(&r, &device_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3918 device_rect.left, device_rect.top, device_rect.right, device_rect.bottom,
3919 r.left, r.top, r.right, r.bottom);
3921 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
3922 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3923 (LONG_PTR)test_proc, proc);
3924 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3925 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx.\n", (LONG_PTR)test_proc);
3927 device_desc.device_window = device_window;
3928 hr = reset_device(device, &device_desc);
3929 ok(SUCCEEDED(hr), "Failed to reset device.\n");
3931 GetWindowRect(focus_window, &r);
3932 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3933 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
3934 r.left, r.top, r.right, r.bottom);
3935 GetWindowRect(device_window, &r);
3936 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3937 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
3938 r.left, r.top, r.right, r.bottom);
3940 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
3941 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3942 (LONG_PTR)test_proc, proc);
3943 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3944 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx.\n", (LONG_PTR)test_proc);
3946 ref = IDirect3DDevice8_Release(device);
3947 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
3949 done:
3950 IDirect3D8_Release(d3d8);
3951 DestroyWindow(device_window);
3952 DestroyWindow(focus_window);
3953 UnregisterClassA("d3d8_test_wndproc_wc", GetModuleHandleA(NULL));
3956 static void depth_blit_test(void)
3958 IDirect3DDevice8 *device = NULL;
3959 IDirect3DSurface8 *backbuffer, *ds1, *ds2, *ds3;
3960 RECT src_rect;
3961 const POINT dst_point = {0, 0};
3962 IDirect3D8 *d3d8;
3963 HRESULT hr;
3964 HWND hwnd;
3966 hwnd = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
3967 100, 100, 160, 160, NULL, NULL, NULL, NULL);
3968 ok(!!hwnd, "Failed to create a window.\n");
3969 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
3970 ok(!!d3d8, "Failed to create a D3D object.\n");
3972 if (!(device = create_device(d3d8, hwnd, NULL)))
3974 skip("Failed to create a D3D device, skipping tests.\n");
3975 goto done;
3978 hr = IDirect3DDevice8_GetRenderTarget(device, &backbuffer);
3979 ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
3980 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &ds1);
3981 ok(SUCCEEDED(hr), "GetDepthStencilSurface failed, hr %#x.\n", hr);
3982 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 640, 480, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, &ds2);
3983 ok(SUCCEEDED(hr), "CreateDepthStencilSurface failed, hr %#x.\n", hr);
3984 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 640, 480, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, &ds3);
3985 ok(SUCCEEDED(hr), "CreateDepthStencilSurface failed, hr %#x.\n", hr);
3987 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0, 0.0f, 0);
3988 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
3990 /* Partial blit. */
3991 SetRect(&src_rect, 0, 0, 320, 240);
3992 hr = IDirect3DDevice8_CopyRects(device, ds1, &src_rect, 1, ds2, &dst_point);
3993 ok(hr == D3DERR_INVALIDCALL, "CopyRects returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
3994 /* Flipped. */
3995 SetRect(&src_rect, 0, 480, 640, 0);
3996 hr = IDirect3DDevice8_CopyRects(device, ds1, &src_rect, 1, ds2, &dst_point);
3997 ok(hr == D3DERR_INVALIDCALL, "CopyRects returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
3998 /* Full, explicit. */
3999 SetRect(&src_rect, 0, 0, 640, 480);
4000 hr = IDirect3DDevice8_CopyRects(device, ds1, &src_rect, 1, ds2, &dst_point);
4001 ok(hr == D3DERR_INVALIDCALL, "CopyRects returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
4002 /* Depth -> color blit.*/
4003 hr = IDirect3DDevice8_CopyRects(device, ds1, &src_rect, 1, backbuffer, &dst_point);
4004 ok(hr == D3DERR_INVALIDCALL, "CopyRects returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
4005 /* Full, NULL rects, current depth stencil -> unbound depth stencil */
4006 hr = IDirect3DDevice8_CopyRects(device, ds1, NULL, 0, ds2, NULL);
4007 ok(hr == D3DERR_INVALIDCALL, "CopyRects returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
4008 /* Full, NULL rects, unbound depth stencil -> current depth stencil */
4009 hr = IDirect3DDevice8_CopyRects(device, ds2, NULL, 0, ds1, NULL);
4010 ok(hr == D3DERR_INVALIDCALL, "CopyRects returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
4011 /* Full, NULL rects, unbound depth stencil -> unbound depth stencil */
4012 hr = IDirect3DDevice8_CopyRects(device, ds2, NULL, 0, ds3, NULL);
4013 ok(hr == D3DERR_INVALIDCALL, "CopyRects returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
4015 IDirect3DSurface8_Release(backbuffer);
4016 IDirect3DSurface8_Release(ds3);
4017 IDirect3DSurface8_Release(ds2);
4018 IDirect3DSurface8_Release(ds1);
4020 done:
4021 if (device) IDirect3DDevice8_Release(device);
4022 IDirect3D8_Release(d3d8);
4023 DestroyWindow(hwnd);
4026 static void test_reset_resources(void)
4028 IDirect3DSurface8 *surface, *rt;
4029 IDirect3DTexture8 *texture;
4030 IDirect3DDevice8 *device;
4031 IDirect3D8 *d3d8;
4032 HWND window;
4033 HRESULT hr;
4034 ULONG ref;
4036 window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW,
4037 0, 0, 640, 480, 0, 0, 0, 0);
4038 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
4039 ok(!!d3d8, "Failed to create a D3D object.\n");
4041 if (!(device = create_device(d3d8, window, NULL)))
4043 skip("Failed to create a D3D device, skipping tests.\n");
4044 goto done;
4047 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 128, 128, D3DFMT_D24S8,
4048 D3DMULTISAMPLE_NONE, &surface);
4049 ok(SUCCEEDED(hr), "Failed to create depth/stencil surface, hr %#x.\n", hr);
4051 hr = IDirect3DDevice8_CreateTexture(device, 128, 128, 1, D3DUSAGE_RENDERTARGET,
4052 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture);
4053 ok(SUCCEEDED(hr), "Failed to create render target texture, hr %#x.\n", hr);
4054 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 0, &rt);
4055 ok(SUCCEEDED(hr), "Failed to get surface, hr %#x.\n", hr);
4056 IDirect3DTexture8_Release(texture);
4058 hr = IDirect3DDevice8_SetRenderTarget(device, rt, surface);
4059 ok(SUCCEEDED(hr), "Failed to set render target surface, hr %#x.\n", hr);
4060 IDirect3DSurface8_Release(rt);
4061 IDirect3DSurface8_Release(surface);
4063 hr = reset_device(device, NULL);
4064 ok(SUCCEEDED(hr), "Failed to reset device.\n");
4066 hr = IDirect3DDevice8_GetBackBuffer(device, 0, D3DBACKBUFFER_TYPE_MONO, &rt);
4067 ok(SUCCEEDED(hr), "Failed to get back buffer, hr %#x.\n", hr);
4068 hr = IDirect3DDevice8_GetRenderTarget(device, &surface);
4069 ok(SUCCEEDED(hr), "Failed to get render target surface, hr %#x.\n", hr);
4070 ok(surface == rt, "Got unexpected surface %p for render target.\n", surface);
4071 IDirect3DSurface8_Release(surface);
4072 IDirect3DSurface8_Release(rt);
4074 ref = IDirect3DDevice8_Release(device);
4075 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
4077 done:
4078 IDirect3D8_Release(d3d8);
4079 DestroyWindow(window);
4082 static void test_set_rt_vp_scissor(void)
4084 IDirect3DDevice8 *device;
4085 IDirect3DSurface8 *rt;
4086 IDirect3D8 *d3d8;
4087 DWORD stateblock;
4088 D3DVIEWPORT8 vp;
4089 UINT refcount;
4090 HWND window;
4091 HRESULT hr;
4093 window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW,
4094 0, 0, 640, 480, 0, 0, 0, 0);
4095 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
4096 ok(!!d3d8, "Failed to create a D3D object.\n");
4097 if (!(device = create_device(d3d8, window, NULL)))
4099 skip("Failed to create a D3D device, skipping tests.\n");
4100 IDirect3D8_Release(d3d8);
4101 DestroyWindow(window);
4102 return;
4105 hr = IDirect3DDevice8_CreateRenderTarget(device, 128, 128, D3DFMT_A8R8G8B8,
4106 D3DMULTISAMPLE_NONE, FALSE, &rt);
4107 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
4109 hr = IDirect3DDevice8_GetViewport(device, &vp);
4110 ok(SUCCEEDED(hr), "Failed to get viewport, hr %#x.\n", hr);
4111 ok(!vp.X, "Got unexpected vp.X %u.\n", vp.X);
4112 ok(!vp.Y, "Got unexpected vp.Y %u.\n", vp.Y);
4113 ok(vp.Width == 640, "Got unexpected vp.Width %u.\n", vp.Width);
4114 ok(vp.Height == 480, "Got unexpected vp.Height %u.\n", vp.Height);
4115 ok(vp.MinZ == 0.0f, "Got unexpected vp.MinZ %.8e.\n", vp.MinZ);
4116 ok(vp.MaxZ == 1.0f, "Got unexpected vp.MaxZ %.8e.\n", vp.MaxZ);
4118 hr = IDirect3DDevice8_BeginStateBlock(device);
4119 ok(SUCCEEDED(hr), "Failed to begin stateblock, hr %#x.\n", hr);
4121 hr = IDirect3DDevice8_SetRenderTarget(device, rt, NULL);
4122 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
4124 hr = IDirect3DDevice8_EndStateBlock(device, &stateblock);
4125 ok(SUCCEEDED(hr), "Failed to end stateblock, hr %#x.\n", hr);
4126 hr = IDirect3DDevice8_DeleteStateBlock(device, stateblock);
4127 ok(SUCCEEDED(hr), "Failed to delete stateblock, hr %#x.\n", hr);
4129 hr = IDirect3DDevice8_GetViewport(device, &vp);
4130 ok(SUCCEEDED(hr), "Failed to get viewport, hr %#x.\n", hr);
4131 ok(!vp.X, "Got unexpected vp.X %u.\n", vp.X);
4132 ok(!vp.Y, "Got unexpected vp.Y %u.\n", vp.Y);
4133 ok(vp.Width == 128, "Got unexpected vp.Width %u.\n", vp.Width);
4134 ok(vp.Height == 128, "Got unexpected vp.Height %u.\n", vp.Height);
4135 ok(vp.MinZ == 0.0f, "Got unexpected vp.MinZ %.8e.\n", vp.MinZ);
4136 ok(vp.MaxZ == 1.0f, "Got unexpected vp.MaxZ %.8e.\n", vp.MaxZ);
4138 hr = IDirect3DDevice8_SetRenderTarget(device, rt, NULL);
4139 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
4141 vp.X = 10;
4142 vp.Y = 20;
4143 vp.Width = 30;
4144 vp.Height = 40;
4145 vp.MinZ = 0.25f;
4146 vp.MaxZ = 0.75f;
4147 hr = IDirect3DDevice8_SetViewport(device, &vp);
4148 ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
4150 hr = IDirect3DDevice8_SetRenderTarget(device, rt, NULL);
4151 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
4153 hr = IDirect3DDevice8_GetViewport(device, &vp);
4154 ok(SUCCEEDED(hr), "Failed to get viewport, hr %#x.\n", hr);
4155 ok(!vp.X, "Got unexpected vp.X %u.\n", vp.X);
4156 ok(!vp.Y, "Got unexpected vp.Y %u.\n", vp.Y);
4157 ok(vp.Width == 128, "Got unexpected vp.Width %u.\n", vp.Width);
4158 ok(vp.Height == 128, "Got unexpected vp.Height %u.\n", vp.Height);
4159 ok(vp.MinZ == 0.0f, "Got unexpected vp.MinZ %.8e.\n", vp.MinZ);
4160 ok(vp.MaxZ == 1.0f, "Got unexpected vp.MaxZ %.8e.\n", vp.MaxZ);
4162 IDirect3DSurface8_Release(rt);
4163 refcount = IDirect3DDevice8_Release(device);
4164 ok(!refcount, "Device has %u references left.\n", refcount);
4165 IDirect3D8_Release(d3d8);
4166 DestroyWindow(window);
4169 static void test_validate_vs(void)
4171 static DWORD vs[] =
4173 0xfffe0101, /* vs_1_1 */
4174 0x00000009, 0xc0010000, 0x90e40000, 0xa0e40000, /* dp4 oPos.x, v0, c0 */
4175 0x00000009, 0xc0020000, 0x90e40000, 0xa0e40001, /* dp4 oPos.y, v0, c1 */
4176 0x00000009, 0xc0040000, 0x90e40000, 0xa0e40002, /* dp4 oPos.z, v0, c2 */
4177 0x00000009, 0xc0080000, 0x90e40000, 0xa0e40003, /* dp4 oPos.w, v0, c3 */
4178 0x0000ffff, /* end */
4180 HRESULT hr;
4182 hr = ValidateVertexShader(0, 0, 0, 0, 0);
4183 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
4184 hr = ValidateVertexShader(0, 0, 0, 1, 0);
4185 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
4186 hr = ValidateVertexShader(vs, 0, 0, 0, 0);
4187 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4189 hr = ValidateVertexShader(vs, 0, 0, 1, 0);
4190 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4191 /* Seems to do some version checking. */
4192 *vs = 0xfffe0100; /* vs_1_0 */
4193 hr = ValidateVertexShader(vs, 0, 0, 0, 0);
4194 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4196 *vs = 0xfffe0102; /* bogus version */
4197 hr = ValidateVertexShader(vs, 0, 0, 1, 0);
4198 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
4199 /* I've seen that applications always pass the 2nd and 3rd parameter as 0.
4200 * Simple test with non-zero parameters. */
4201 *vs = 0xfffe0101; /* vs_1_1 */
4202 hr = ValidateVertexShader(vs, vs, 0, 1, 0);
4203 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
4205 hr = ValidateVertexShader(vs, 0, vs, 1, 0);
4206 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
4207 /* I've seen the 4th parameter always passed as either 0 or 1, but passing
4208 * other values doesn't seem to hurt. */
4209 hr = ValidateVertexShader(vs, 0, 0, 12345, 0);
4210 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4211 /* What is the 5th parameter? The following seems to work ok. */
4212 hr = ValidateVertexShader(vs, 0, 0, 1, vs);
4213 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4216 static void test_validate_ps(void)
4218 static DWORD ps[] =
4220 0xffff0101, /* ps_1_1 */
4221 0x00000051, 0xa00f0001, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c1 = 1.0, 0.0, 0.0, 0.0 */
4222 0x00000042, 0xb00f0000, /* tex t0 */
4223 0x00000008, 0x800f0000, 0xa0e40001, 0xa0e40000, /* dp3 r0, c1, c0 */
4224 0x00000005, 0x800f0000, 0x90e40000, 0x80e40000, /* mul r0, v0, r0 */
4225 0x00000005, 0x800f0000, 0xb0e40000, 0x80e40000, /* mul r0, t0, r0 */
4226 0x0000ffff, /* end */
4228 HRESULT hr;
4230 hr = ValidatePixelShader(0, 0, 0, 0);
4231 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
4232 hr = ValidatePixelShader(0, 0, 1, 0);
4233 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
4234 hr = ValidatePixelShader(ps, 0, 0, 0);
4235 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4237 hr = ValidatePixelShader(ps, 0, 1, 0);
4238 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4239 /* Seems to do some version checking. */
4240 *ps = 0xffff0105; /* bogus version */
4241 hr = ValidatePixelShader(ps, 0, 1, 0);
4242 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
4243 /* I've seen that applications always pass the 2nd parameter as 0.
4244 * Simple test with a non-zero parameter. */
4245 *ps = 0xffff0101; /* ps_1_1 */
4246 hr = ValidatePixelShader(ps, ps, 1, 0);
4247 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
4248 /* I've seen the 3rd parameter always passed as either 0 or 1, but passing
4249 * other values doesn't seem to hurt. */
4250 hr = ValidatePixelShader(ps, 0, 12345, 0);
4251 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4252 /* What is the 4th parameter? The following seems to work ok. */
4253 hr = ValidatePixelShader(ps, 0, 1, ps);
4254 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
4257 static void test_volume_get_container(void)
4259 IDirect3DVolumeTexture8 *texture = NULL;
4260 IDirect3DVolume8 *volume = NULL;
4261 IDirect3DDevice8 *device;
4262 IUnknown *container;
4263 IDirect3D8 *d3d8;
4264 ULONG refcount;
4265 D3DCAPS8 caps;
4266 HWND window;
4267 HRESULT hr;
4269 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
4270 0, 0, 640, 480, 0, 0, 0, 0);
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_GetDeviceCaps(device, &caps);
4282 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
4283 if (!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP))
4285 skip("No volume texture support, skipping tests.\n");
4286 IDirect3DDevice8_Release(device);
4287 IDirect3D8_Release(d3d8);
4288 DestroyWindow(window);
4289 return;
4292 hr = IDirect3DDevice8_CreateVolumeTexture(device, 128, 128, 128, 1, 0,
4293 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture);
4294 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x.\n", hr);
4295 ok(!!texture, "Got unexpected texture %p.\n", texture);
4297 hr = IDirect3DVolumeTexture8_GetVolumeLevel(texture, 0, &volume);
4298 ok(SUCCEEDED(hr), "Failed to get volume level, hr %#x.\n", hr);
4299 ok(!!volume, "Got unexpected volume %p.\n", volume);
4301 /* These should work... */
4302 container = NULL;
4303 hr = IDirect3DVolume8_GetContainer(volume, &IID_IUnknown, (void **)&container);
4304 ok(SUCCEEDED(hr), "Failed to get volume container, hr %#x.\n", hr);
4305 ok(container == (IUnknown *)texture, "Got unexpected container %p, expected %p.\n", container, texture);
4306 IUnknown_Release(container);
4308 container = NULL;
4309 hr = IDirect3DVolume8_GetContainer(volume, &IID_IDirect3DResource8, (void **)&container);
4310 ok(SUCCEEDED(hr), "Failed to get volume container, hr %#x.\n", hr);
4311 ok(container == (IUnknown *)texture, "Got unexpected container %p, expected %p.\n", container, texture);
4312 IUnknown_Release(container);
4314 container = NULL;
4315 hr = IDirect3DVolume8_GetContainer(volume, &IID_IDirect3DBaseTexture8, (void **)&container);
4316 ok(SUCCEEDED(hr), "Failed to get volume container, hr %#x.\n", hr);
4317 ok(container == (IUnknown *)texture, "Got unexpected container %p, expected %p.\n", container, texture);
4318 IUnknown_Release(container);
4320 container = NULL;
4321 hr = IDirect3DVolume8_GetContainer(volume, &IID_IDirect3DVolumeTexture8, (void **)&container);
4322 ok(SUCCEEDED(hr), "Failed to get volume container, hr %#x.\n", hr);
4323 ok(container == (IUnknown *)texture, "Got unexpected container %p, expected %p.\n", container, texture);
4324 IUnknown_Release(container);
4326 /* ...and this one shouldn't. This should return E_NOINTERFACE and set container to NULL. */
4327 hr = IDirect3DVolume8_GetContainer(volume, &IID_IDirect3DVolume8, (void **)&container);
4328 ok(hr == E_NOINTERFACE, "Got unexpected hr %#x.\n", hr);
4329 ok(!container, "Got unexpected container %p.\n", container);
4331 IDirect3DVolume8_Release(volume);
4332 IDirect3DVolumeTexture8_Release(texture);
4333 refcount = IDirect3DDevice8_Release(device);
4334 ok(!refcount, "Device has %u references left.\n", refcount);
4335 IDirect3D8_Release(d3d8);
4336 DestroyWindow(window);
4339 static void test_vb_lock_flags(void)
4341 static const struct
4343 DWORD flags;
4344 const char *debug_string;
4345 HRESULT result;
4347 test_data[] =
4349 {D3DLOCK_READONLY, "D3DLOCK_READONLY", D3D_OK },
4350 {D3DLOCK_DISCARD, "D3DLOCK_DISCARD", D3D_OK },
4351 {D3DLOCK_NOOVERWRITE, "D3DLOCK_NOOVERWRITE", D3D_OK },
4352 {D3DLOCK_NOOVERWRITE | D3DLOCK_DISCARD, "D3DLOCK_NOOVERWRITE | D3DLOCK_DISCARD", D3D_OK },
4353 {D3DLOCK_NOOVERWRITE | D3DLOCK_READONLY, "D3DLOCK_NOOVERWRITE | D3DLOCK_READONLY", D3D_OK },
4354 {D3DLOCK_READONLY | D3DLOCK_DISCARD, "D3DLOCK_READONLY | D3DLOCK_DISCARD", D3D_OK },
4355 /* Completely bogus flags aren't an error. */
4356 {0xdeadbeef, "0xdeadbeef", D3D_OK },
4358 IDirect3DVertexBuffer8 *buffer;
4359 IDirect3DDevice8 *device;
4360 IDirect3D8 *d3d8;
4361 unsigned int i;
4362 ULONG refcount;
4363 HWND window;
4364 HRESULT hr;
4365 BYTE *data;
4367 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
4368 0, 0, 640, 480, 0, 0, 0, 0);
4369 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
4370 ok(!!d3d8, "Failed to create a D3D object.\n");
4371 if (!(device = create_device(d3d8, window, NULL)))
4373 skip("Failed to create a D3D device, skipping tests.\n");
4374 IDirect3D8_Release(d3d8);
4375 DestroyWindow(window);
4376 return;
4379 hr = IDirect3DDevice8_CreateVertexBuffer(device, 1024, D3DUSAGE_DYNAMIC, 0, D3DPOOL_DEFAULT, &buffer);
4380 ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr);
4382 for (i = 0; i < (sizeof(test_data) / sizeof(*test_data)); ++i)
4384 hr = IDirect3DVertexBuffer8_Lock(buffer, 0, 0, &data, test_data[i].flags);
4385 ok(hr == test_data[i].result, "Got unexpected hr %#x for %s.\n",
4386 hr, test_data[i].debug_string);
4387 if (SUCCEEDED(hr))
4389 ok(!!data, "Got unexpected data %p.\n", data);
4390 hr = IDirect3DVertexBuffer8_Unlock(buffer);
4391 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
4395 IDirect3DVertexBuffer8_Release(buffer);
4396 refcount = IDirect3DDevice8_Release(device);
4397 ok(!refcount, "Device has %u references left.\n", refcount);
4398 IDirect3D8_Release(d3d8);
4399 DestroyWindow(window);
4402 /* Test the default texture stage state values */
4403 static void test_texture_stage_states(void)
4405 IDirect3DDevice8 *device;
4406 IDirect3D8 *d3d8;
4407 unsigned int i;
4408 ULONG refcount;
4409 D3DCAPS8 caps;
4410 DWORD value;
4411 HWND window;
4412 HRESULT hr;
4414 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
4415 0, 0, 640, 480, 0, 0, 0, 0);
4416 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
4417 ok(!!d3d8, "Failed to create a D3D object.\n");
4418 if (!(device = create_device(d3d8, window, NULL)))
4420 skip("Failed to create a D3D device, skipping tests.\n");
4421 IDirect3D8_Release(d3d8);
4422 DestroyWindow(window);
4423 return;
4426 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
4427 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
4429 for (i = 0; i < caps.MaxTextureBlendStages; ++i)
4431 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_COLOROP, &value);
4432 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4433 ok(value == (i ? D3DTOP_DISABLE : D3DTOP_MODULATE),
4434 "Got unexpected value %#x for D3DTSS_COLOROP, stage %u.\n", value, i);
4435 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_COLORARG1, &value);
4436 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4437 ok(value == D3DTA_TEXTURE, "Got unexpected value %#x for D3DTSS_COLORARG1, stage %u.\n", value, i);
4438 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_COLORARG2, &value);
4439 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4440 ok(value == D3DTA_CURRENT, "Got unexpected value %#x for D3DTSS_COLORARG2, stage %u.\n", value, i);
4441 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_ALPHAOP, &value);
4442 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4443 ok(value == (i ? D3DTOP_DISABLE : D3DTOP_SELECTARG1),
4444 "Got unexpected value %#x for D3DTSS_ALPHAOP, stage %u.\n", value, i);
4445 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_ALPHAARG1, &value);
4446 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4447 ok(value == D3DTA_TEXTURE, "Got unexpected value %#x for D3DTSS_ALPHAARG1, stage %u.\n", value, i);
4448 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_ALPHAARG2, &value);
4449 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4450 ok(value == D3DTA_CURRENT, "Got unexpected value %#x for D3DTSS_ALPHAARG2, stage %u.\n", value, i);
4451 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_BUMPENVMAT00, &value);
4452 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4453 ok(!value, "Got unexpected value %#x for D3DTSS_BUMPENVMAT00, stage %u.\n", value, i);
4454 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_BUMPENVMAT01, &value);
4455 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4456 ok(!value, "Got unexpected value %#x for D3DTSS_BUMPENVMAT01, stage %u.\n", value, i);
4457 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_BUMPENVMAT10, &value);
4458 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4459 ok(!value, "Got unexpected value %#x for D3DTSS_BUMPENVMAT10, stage %u.\n", value, i);
4460 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_BUMPENVMAT11, &value);
4461 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4462 ok(!value, "Got unexpected value %#x for D3DTSS_BUMPENVMAT11, stage %u.\n", value, i);
4463 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_TEXCOORDINDEX, &value);
4464 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4465 ok(value == i, "Got unexpected value %#x for D3DTSS_TEXCOORDINDEX, stage %u.\n", value, i);
4466 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_BUMPENVLSCALE, &value);
4467 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4468 ok(!value, "Got unexpected value %#x for D3DTSS_BUMPENVLSCALE, stage %u.\n", value, i);
4469 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_BUMPENVLOFFSET, &value);
4470 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4471 ok(!value, "Got unexpected value %#x for D3DTSS_BUMPENVLOFFSET, stage %u.\n", value, i);
4472 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_TEXTURETRANSFORMFLAGS, &value);
4473 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4474 ok(value == D3DTTFF_DISABLE,
4475 "Got unexpected value %#x for D3DTSS_TEXTURETRANSFORMFLAGS, stage %u.\n", value, i);
4476 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_COLORARG0, &value);
4477 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4478 ok(value == D3DTA_CURRENT, "Got unexpected value %#x for D3DTSS_COLORARG0, stage %u.\n", value, i);
4479 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_ALPHAARG0, &value);
4480 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4481 ok(value == D3DTA_CURRENT, "Got unexpected value %#x for D3DTSS_ALPHAARG0, stage %u.\n", value, i);
4482 hr = IDirect3DDevice8_GetTextureStageState(device, i, D3DTSS_RESULTARG, &value);
4483 ok(SUCCEEDED(hr), "Failed to get texture stage state, hr %#x.\n", hr);
4484 ok(value == D3DTA_CURRENT, "Got unexpected value %#x for D3DTSS_RESULTARG, stage %u.\n", value, i);
4487 refcount = IDirect3DDevice8_Release(device);
4488 ok(!refcount, "Device has %u references left.\n", refcount);
4489 IDirect3D8_Release(d3d8);
4490 DestroyWindow(window);
4493 static void test_cube_textures(void)
4495 IDirect3DCubeTexture8 *texture;
4496 IDirect3DDevice8 *device;
4497 IDirect3D8 *d3d8;
4498 ULONG refcount;
4499 D3DCAPS8 caps;
4500 HWND window;
4501 HRESULT hr;
4503 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
4504 0, 0, 640, 480, 0, 0, 0, 0);
4505 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
4506 ok(!!d3d8, "Failed to create a D3D object.\n");
4507 if (!(device = create_device(d3d8, window, NULL)))
4509 skip("Failed to create a D3D device, skipping tests.\n");
4510 IDirect3D8_Release(d3d8);
4511 DestroyWindow(window);
4512 return;
4515 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
4516 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
4518 if (caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP)
4520 hr = IDirect3DDevice8_CreateCubeTexture(device, 512, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &texture);
4521 ok(hr == D3D_OK, "Failed to create D3DPOOL_DEFAULT cube texture, hr %#x.\n", hr);
4522 IDirect3DCubeTexture8_Release(texture);
4523 hr = IDirect3DDevice8_CreateCubeTexture(device, 512, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &texture);
4524 ok(hr == D3D_OK, "Failed to create D3DPOOL_MANAGED cube texture, hr %#x.\n", hr);
4525 IDirect3DCubeTexture8_Release(texture);
4526 hr = IDirect3DDevice8_CreateCubeTexture(device, 512, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_SYSTEMMEM, &texture);
4527 ok(hr == D3D_OK, "Failed to create D3DPOOL_SYSTEMMEM cube texture, hr %#x.\n", hr);
4528 IDirect3DCubeTexture8_Release(texture);
4530 else
4532 hr = IDirect3DDevice8_CreateCubeTexture(device, 512, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &texture);
4533 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for D3DPOOL_DEFAULT cube texture.\n", hr);
4534 hr = IDirect3DDevice8_CreateCubeTexture(device, 512, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &texture);
4535 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for D3DPOOL_MANAGED cube texture.\n", hr);
4536 hr = IDirect3DDevice8_CreateCubeTexture(device, 512, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_SYSTEMMEM, &texture);
4537 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for D3DPOOL_SYSTEMMEM cube texture.\n", hr);
4539 hr = IDirect3DDevice8_CreateCubeTexture(device, 512, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_SCRATCH, &texture);
4540 ok(hr == D3D_OK, "Failed to create D3DPOOL_SCRATCH cube texture, hr %#x.\n", hr);
4541 IDirect3DCubeTexture8_Release(texture);
4543 refcount = IDirect3DDevice8_Release(device);
4544 ok(!refcount, "Device has %u references left.\n", refcount);
4545 IDirect3D8_Release(d3d8);
4546 DestroyWindow(window);
4549 static void test_get_set_texture(void)
4551 const IDirect3DBaseTexture8Vtbl *texture_vtbl;
4552 IDirect3DBaseTexture8 *texture;
4553 IDirect3DDevice8 *device;
4554 IDirect3D8 *d3d;
4555 ULONG refcount;
4556 HWND window;
4557 HRESULT hr;
4559 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
4560 0, 0, 640, 480, 0, 0, 0, 0);
4561 d3d = Direct3DCreate8(D3D_SDK_VERSION);
4562 ok(!!d3d, "Failed to create a D3D object.\n");
4563 if (!(device = create_device(d3d, window, NULL)))
4565 skip("Failed to create a D3D device, skipping tests.\n");
4566 IDirect3D8_Release(d3d);
4567 DestroyWindow(window);
4568 return;
4571 texture = (IDirect3DBaseTexture8 *)0xdeadbeef;
4572 hr = IDirect3DDevice8_SetTexture(device, 0, NULL);
4573 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
4574 hr = IDirect3DDevice8_GetTexture(device, 0, &texture);
4575 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
4576 ok(!texture, "Got unexpected texture %p.\n", texture);
4578 hr = IDirect3DDevice8_CreateTexture(device, 16, 16, 1, 0, D3DFMT_A8R8G8B8,
4579 D3DPOOL_MANAGED, (IDirect3DTexture8 **)&texture);
4580 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
4581 texture_vtbl = texture->lpVtbl;
4582 texture->lpVtbl = (IDirect3DBaseTexture8Vtbl *)0xdeadbeef;
4583 hr = IDirect3DDevice8_SetTexture(device, 0, texture);
4584 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
4585 hr = IDirect3DDevice8_SetTexture(device, 0, NULL);
4586 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
4587 texture->lpVtbl = NULL;
4588 hr = IDirect3DDevice8_SetTexture(device, 0, texture);
4589 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
4590 hr = IDirect3DDevice8_SetTexture(device, 0, NULL);
4591 ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
4592 texture->lpVtbl = texture_vtbl;
4593 IDirect3DBaseTexture8_Release(texture);
4595 refcount = IDirect3DDevice8_Release(device);
4596 ok(!refcount, "Device has %u references left.\n", refcount);
4597 IDirect3D8_Release(d3d);
4598 DestroyWindow(window);
4601 /* Test the behaviour of the IDirect3DDevice8::CreateImageSurface() method.
4603 * The expected behaviour (as documented in the original DX8 docs) is that the
4604 * call returns a surface in the SYSTEMMEM pool. Games like Max Payne 1 and 2
4605 * depend on this behaviour.
4607 * A short remark in the DX9 docs however states that the pool of the returned
4608 * surface object is D3DPOOL_SCRATCH. This is misinformation and would result
4609 * in screenshots not appearing in the savegame loading menu of both games
4610 * mentioned above (engine tries to display a texture from the scratch pool).
4612 * This test verifies that the behaviour described in the original d3d8 docs
4613 * is the correct one. For more information about this issue, see the MSDN:
4614 * d3d9 docs: "Converting to Direct3D 9"
4615 * d3d9 reference: "IDirect3DDevice9::CreateOffscreenPlainSurface"
4616 * d3d8 reference: "IDirect3DDevice8::CreateImageSurface" */
4617 static void test_image_surface_pool(void)
4619 IDirect3DSurface8 *surface;
4620 IDirect3DDevice8 *device;
4621 D3DSURFACE_DESC desc;
4622 IDirect3D8 *d3d8;
4623 ULONG refcount;
4624 HWND window;
4625 HRESULT hr;
4627 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
4628 0, 0, 640, 480, 0, 0, 0, 0);
4629 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
4630 ok(!!d3d8, "Failed to create a D3D object.\n");
4631 if (!(device = create_device(d3d8, window, NULL)))
4633 skip("Failed to create a D3D device, skipping tests.\n");
4634 IDirect3D8_Release(d3d8);
4635 DestroyWindow(window);
4636 return;
4639 hr = IDirect3DDevice8_CreateImageSurface(device, 128, 128, D3DFMT_A8R8G8B8, &surface);
4640 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4641 hr = IDirect3DSurface8_GetDesc(surface, &desc);
4642 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
4643 ok(desc.Pool == D3DPOOL_SYSTEMMEM, "Got unexpected pool %#x.\n", desc.Pool);
4644 IDirect3DSurface8_Release(surface);
4646 refcount = IDirect3DDevice8_Release(device);
4647 ok(!refcount, "Device has %u references left.\n", refcount);
4648 IDirect3D8_Release(d3d8);
4649 DestroyWindow(window);
4652 static void test_surface_get_container(void)
4654 IDirect3DTexture8 *texture = NULL;
4655 IDirect3DSurface8 *surface = NULL;
4656 IDirect3DDevice8 *device;
4657 IUnknown *container;
4658 IDirect3D8 *d3d8;
4659 ULONG refcount;
4660 HWND window;
4661 HRESULT hr;
4663 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
4664 0, 0, 640, 480, 0, 0, 0, 0);
4665 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
4666 ok(!!d3d8, "Failed to create a D3D object.\n");
4667 if (!(device = create_device(d3d8, window, NULL)))
4669 skip("Failed to create a D3D device, skipping tests.\n");
4670 IDirect3D8_Release(d3d8);
4671 DestroyWindow(window);
4672 return;
4675 hr = IDirect3DDevice8_CreateTexture(device, 128, 128, 1, 0,
4676 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture);
4677 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
4678 ok(!!texture, "Got unexpected texture %p.\n", texture);
4680 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 0, &surface);
4681 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
4682 ok(!!surface, "Got unexpected surface %p.\n", surface);
4684 /* These should work... */
4685 container = NULL;
4686 hr = IDirect3DSurface8_GetContainer(surface, &IID_IUnknown, (void **)&container);
4687 ok(SUCCEEDED(hr), "Failed to get surface container, hr %#x.\n", hr);
4688 ok(container == (IUnknown *)texture, "Got unexpected container %p, expected %p.\n", container, texture);
4689 IUnknown_Release(container);
4691 container = NULL;
4692 hr = IDirect3DSurface8_GetContainer(surface, &IID_IDirect3DResource8, (void **)&container);
4693 ok(SUCCEEDED(hr), "Failed to get surface container, hr %#x.\n", hr);
4694 ok(container == (IUnknown *)texture, "Got unexpected container %p, expected %p.\n", container, texture);
4695 IUnknown_Release(container);
4697 container = NULL;
4698 hr = IDirect3DSurface8_GetContainer(surface, &IID_IDirect3DBaseTexture8, (void **)&container);
4699 ok(SUCCEEDED(hr), "Failed to get surface container, hr %#x.\n", hr);
4700 ok(container == (IUnknown *)texture, "Got unexpected container %p, expected %p.\n", container, texture);
4701 IUnknown_Release(container);
4703 container = NULL;
4704 hr = IDirect3DSurface8_GetContainer(surface, &IID_IDirect3DTexture8, (void **)&container);
4705 ok(SUCCEEDED(hr), "Failed to get surface container, hr %#x.\n", hr);
4706 ok(container == (IUnknown *)texture, "Got unexpected container %p, expected %p.\n", container, texture);
4707 IUnknown_Release(container);
4709 /* ...and this one shouldn't. This should return E_NOINTERFACE and set container to NULL. */
4710 hr = IDirect3DSurface8_GetContainer(surface, &IID_IDirect3DSurface8, (void **)&container);
4711 ok(hr == E_NOINTERFACE, "Got unexpected hr %#x.\n", hr);
4712 ok(!container, "Got unexpected container %p.\n", container);
4714 IDirect3DSurface8_Release(surface);
4715 IDirect3DTexture8_Release(texture);
4716 refcount = IDirect3DDevice8_Release(device);
4717 ok(!refcount, "Device has %u references left.\n", refcount);
4718 IDirect3D8_Release(d3d8);
4719 DestroyWindow(window);
4722 static void test_lockrect_invalid(void)
4724 static const RECT valid[] =
4726 {60, 60, 68, 68},
4727 {120, 60, 128, 68},
4728 {60, 120, 68, 128},
4730 static const RECT invalid[] =
4732 {60, 60, 60, 68}, /* 0 height */
4733 {60, 60, 68, 60}, /* 0 width */
4734 {68, 60, 60, 68}, /* left > right */
4735 {60, 68, 68, 60}, /* top > bottom */
4736 {-8, 60, 0, 68}, /* left < surface */
4737 {60, -8, 68, 0}, /* top < surface */
4738 {-16, 60, -8, 68}, /* right < surface */
4739 {60, -16, 68, -8}, /* bottom < surface */
4740 {60, 60, 136, 68}, /* right > surface */
4741 {60, 60, 68, 136}, /* bottom > surface */
4742 {136, 60, 144, 68}, /* left > surface */
4743 {60, 136, 68, 144}, /* top > surface */
4745 IDirect3DSurface8 *surface;
4746 IDirect3DTexture8 *texture;
4747 IDirect3DCubeTexture8 *cube_texture;
4748 D3DLOCKED_RECT locked_rect;
4749 IDirect3DDevice8 *device;
4750 IDirect3D8 *d3d8;
4751 unsigned int i, r;
4752 ULONG refcount;
4753 HWND window;
4754 BYTE *base;
4755 HRESULT hr;
4756 unsigned int offset, expected_offset;
4757 static const struct
4759 D3DRESOURCETYPE type;
4760 D3DPOOL pool;
4761 const char *name;
4762 BOOL validate, clear;
4764 resources[] =
4766 {D3DRTYPE_SURFACE, D3DPOOL_SCRATCH, "scratch surface", TRUE, TRUE},
4767 {D3DRTYPE_TEXTURE, D3DPOOL_MANAGED, "managed texture", FALSE, FALSE},
4768 {D3DRTYPE_TEXTURE, D3DPOOL_SYSTEMMEM, "sysmem texture", FALSE, FALSE},
4769 {D3DRTYPE_TEXTURE, D3DPOOL_SCRATCH, "scratch texture", FALSE, FALSE},
4770 {D3DRTYPE_CUBETEXTURE, D3DPOOL_MANAGED, "default cube texture", TRUE, TRUE},
4771 {D3DRTYPE_CUBETEXTURE, D3DPOOL_SYSTEMMEM, "sysmem cube texture", TRUE, TRUE},
4772 {D3DRTYPE_CUBETEXTURE, D3DPOOL_SCRATCH, "scratch cube texture", TRUE, TRUE},
4775 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
4776 0, 0, 640, 480, 0, 0, 0, 0);
4777 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
4778 ok(!!d3d8, "Failed to create a D3D object.\n");
4779 if (!(device = create_device(d3d8, window, NULL)))
4781 skip("Failed to create a D3D device, skipping tests.\n");
4782 IDirect3D8_Release(d3d8);
4783 DestroyWindow(window);
4784 return;
4787 for (r = 0; r < sizeof(resources) / sizeof(*resources); ++r)
4789 texture = NULL;
4790 cube_texture = NULL;
4791 switch (resources[r].type)
4793 case D3DRTYPE_SURFACE:
4794 hr = IDirect3DDevice8_CreateImageSurface(device, 128, 128, D3DFMT_A8R8G8B8, &surface);
4795 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x, type %s.\n", hr, resources[r].name);
4796 break;
4798 case D3DRTYPE_TEXTURE:
4799 hr = IDirect3DDevice8_CreateTexture(device, 128, 128, 1, 0, D3DFMT_A8R8G8B8,
4800 resources[r].pool, &texture);
4801 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x, type %s.\n", hr, resources[r].name);
4802 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 0, &surface);
4803 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x, type %s.\n", hr, resources[r].name);
4804 break;
4806 case D3DRTYPE_CUBETEXTURE:
4807 hr = IDirect3DDevice8_CreateCubeTexture(device, 128, 1, 0, D3DFMT_A8R8G8B8,
4808 resources[r].pool, &cube_texture);
4809 ok(SUCCEEDED(hr), "Failed to create cube texture, hr %#x, type %s.\n", hr, resources[r].name);
4810 hr = IDirect3DCubeTexture8_GetCubeMapSurface(cube_texture, D3DCUBEMAP_FACE_NEGATIVE_X, 0, &surface);
4811 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x, type %s.\n", hr, resources[r].name);
4812 break;
4814 default:
4815 break;
4817 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, NULL, 0);
4818 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x, type %s.\n", hr, resources[r].name);
4819 base = locked_rect.pBits;
4820 hr = IDirect3DSurface8_UnlockRect(surface);
4821 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
4823 for (i = 0; i < (sizeof(valid) / sizeof(*valid)); ++i)
4825 const RECT *rect = &valid[i];
4827 locked_rect.pBits = (BYTE *)0xdeadbeef;
4828 locked_rect.Pitch = 0xdeadbeef;
4830 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, rect, 0);
4831 ok(SUCCEEDED(hr), "Failed to lock surface with rect [%d, %d]->[%d, %d], hr %#x, type %s.\n",
4832 rect->left, rect->top, rect->right, rect->bottom, hr, resources[r].name);
4834 offset = (BYTE *)locked_rect.pBits - base;
4835 expected_offset = rect->top * locked_rect.Pitch + rect->left * 4;
4836 ok(offset == expected_offset,
4837 "Got unexpected offset %u (expected %u) for rect [%d, %d]->[%d, %d], type %s.\n",
4838 offset, expected_offset, rect->left, rect->top, rect->right, rect->bottom,
4839 resources[r].name);
4841 hr = IDirect3DSurface8_UnlockRect(surface);
4842 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s\n", hr, resources[r].name);
4844 if (texture)
4846 hr = IDirect3DTexture8_LockRect(texture, 0, &locked_rect, rect, 0);
4847 ok(SUCCEEDED(hr), "Failed to lock surface with rect [%d, %d]->[%d, %d], hr %#x, type %s.\n",
4848 rect->left, rect->top, rect->right, rect->bottom, hr, resources[r].name);
4850 offset = (BYTE *)locked_rect.pBits - base;
4851 ok(offset == expected_offset,
4852 "Got unexpected offset %u (expected %u) for rect [%d, %d]->[%d, %d], type %s.\n",
4853 offset, expected_offset, rect->left, rect->top, rect->right, rect->bottom,
4854 resources[r].name);
4856 hr = IDirect3DTexture8_UnlockRect(texture, 0);
4857 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
4859 if (cube_texture)
4861 hr = IDirect3DCubeTexture8_LockRect(cube_texture, D3DCUBEMAP_FACE_NEGATIVE_X, 0, &locked_rect, rect, 0);
4862 ok(SUCCEEDED(hr), "Failed to lock surface with rect [%d, %d]->[%d, %d], hr %#x, type %s.\n",
4863 rect->left, rect->top, rect->right, rect->bottom, hr, resources[r].name);
4865 offset = (BYTE *)locked_rect.pBits - base;
4866 ok(offset == expected_offset,
4867 "Got unexpected offset %u (expected %u) for rect [%d, %d]->[%d, %d], type %s.\n",
4868 offset, expected_offset, rect->left, rect->top, rect->right, rect->bottom,
4869 resources[r].name);
4871 hr = IDirect3DCubeTexture8_UnlockRect(cube_texture, D3DCUBEMAP_FACE_NEGATIVE_X, 0);
4872 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
4876 for (i = 0; i < (sizeof(invalid) / sizeof(*invalid)); ++i)
4878 const RECT *rect = &invalid[i];
4880 locked_rect.pBits = (void *)0xdeadbeef;
4881 locked_rect.Pitch = 1;
4882 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, rect, 0);
4883 if (resources[r].validate)
4884 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for rect [%d, %d]->[%d, %d], type %s.\n",
4885 hr, rect->left, rect->top, rect->right, rect->bottom, resources[r].name);
4886 else
4887 ok(SUCCEEDED(hr), "Got unexpected hr %#x for rect [%d, %d]->[%d, %d], type %s.\n",
4888 hr, rect->left, rect->top, rect->right, rect->bottom, resources[r].name);
4890 if (SUCCEEDED(hr))
4892 offset = (BYTE *)locked_rect.pBits - base;
4893 expected_offset = rect->top * locked_rect.Pitch + rect->left * 4;
4894 ok(offset == expected_offset,
4895 "Got unexpected offset %u (expected %u) for rect [%d, %d]->[%d, %d], type %s.\n",
4896 offset, expected_offset, rect->left, rect->top,
4897 rect->right, rect->bottom, resources[r].name);
4899 hr = IDirect3DSurface8_UnlockRect(surface);
4900 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
4902 else
4904 ok(!locked_rect.pBits, "Got unexpected pBits %p, type %s.\n",
4905 locked_rect.pBits, resources[r].name);
4906 ok(!locked_rect.Pitch, "Got unexpected Pitch %u, type %s.\n",
4907 locked_rect.Pitch, resources[r].name);
4911 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, NULL, 0);
4912 ok(SUCCEEDED(hr), "Failed to lock surface with rect NULL, hr %#x, type %s.\n",
4913 hr, resources[r].name);
4914 locked_rect.pBits = (void *)0xdeadbeef;
4915 locked_rect.Pitch = 1;
4916 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, NULL, 0);
4917 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x, type %s.\n", hr, resources[r].name);
4918 if (resources[r].clear)
4920 ok(!locked_rect.pBits, "Got unexpected pBits %p, type %s.\n",
4921 locked_rect.pBits, resources[r].name);
4922 ok(!locked_rect.Pitch, "Got unexpected Pitch %u, type %s.\n",
4923 locked_rect.Pitch, resources[r].name);
4925 else
4927 ok(locked_rect.pBits == (void *)0xdeadbeef, "Got unexpected pBits %p, type %s.\n",
4928 locked_rect.pBits, resources[r].name);
4929 ok(locked_rect.Pitch == 1, "Got unexpected Pitch %u, type %s.\n",
4930 locked_rect.Pitch, resources[r].name);
4932 hr = IDirect3DSurface8_UnlockRect(surface);
4933 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
4935 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, &valid[0], 0);
4936 ok(hr == D3D_OK, "Got unexpected hr %#x for rect [%d, %d]->[%d, %d], type %s.\n",
4937 hr, valid[0].left, valid[0].top, valid[0].right, valid[0].bottom, resources[r].name);
4938 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, &valid[0], 0);
4939 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for rect [%d, %d]->[%d, %d], type %s.\n",
4940 hr, valid[0].left, valid[0].top, valid[0].right, valid[0].bottom, resources[r].name);
4941 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, &valid[1], 0);
4942 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for rect [%d, %d]->[%d, %d], type %s.\n",
4943 hr, valid[1].left, valid[1].top, valid[1].right, valid[1].bottom, resources[r].name);
4944 hr = IDirect3DSurface8_UnlockRect(surface);
4945 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x, type %s.\n", hr, resources[r].name);
4947 IDirect3DSurface8_Release(surface);
4948 if (texture)
4950 hr = IDirect3DTexture8_LockRect(texture, 0, &locked_rect, NULL, 0);
4951 ok(SUCCEEDED(hr), "Failed to lock texture with rect NULL, hr %#x, type %s.\n",
4952 hr, resources[r].name);
4953 locked_rect.pBits = (void *)0xdeadbeef;
4954 locked_rect.Pitch = 1;
4955 hr = IDirect3DTexture8_LockRect(texture, 0, &locked_rect, NULL, 0);
4956 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x, type %s.\n", hr, resources[r].name);
4957 ok(locked_rect.pBits == (void *)0xdeadbeef, "Got unexpected pBits %p, type %s.\n",
4958 locked_rect.pBits, resources[r].name);
4959 ok(locked_rect.Pitch == 1, "Got unexpected Pitch %u, type %s.\n",
4960 locked_rect.Pitch, resources[r].name);
4961 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, NULL, 0);
4962 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x, type %s.\n", hr, resources[r].name);
4963 hr = IDirect3DTexture8_UnlockRect(texture, 0);
4964 ok(SUCCEEDED(hr), "Failed to unlock texture, hr %#x, type %s.\n", hr, resources[r].name);
4966 hr = IDirect3DTexture8_LockRect(texture, 0, &locked_rect, &valid[0], 0);
4967 ok(hr == D3D_OK, "Got unexpected hr %#x for rect [%d, %d]->[%d, %d], type %s.\n",
4968 hr, valid[0].left, valid[0].top, valid[0].right, valid[0].bottom, resources[r].name);
4969 hr = IDirect3DTexture8_LockRect(texture, 0, &locked_rect, &valid[0], 0);
4970 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for rect [%d, %d]->[%d, %d], type %s.\n",
4971 hr, valid[0].left, valid[0].top, valid[0].right, valid[0].bottom, resources[r].name);
4972 hr = IDirect3DTexture8_LockRect(texture, 0, &locked_rect, &valid[1], 0);
4973 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for rect [%d, %d]->[%d, %d], type %s.\n",
4974 hr, valid[1].left, valid[1].top, valid[1].right, valid[1].bottom, resources[r].name);
4975 hr = IDirect3DTexture8_UnlockRect(texture, 0);
4976 ok(SUCCEEDED(hr), "Failed to unlock texture, hr %#x, type %s.\n", hr, resources[r].name);
4978 IDirect3DTexture8_Release(texture);
4981 if (cube_texture)
4983 hr = IDirect3DCubeTexture8_LockRect(cube_texture, D3DCUBEMAP_FACE_NEGATIVE_X, 0,
4984 &locked_rect, NULL, 0);
4985 ok(SUCCEEDED(hr), "Failed to lock texture with rect NULL, hr %#x, type %s.\n",
4986 hr, resources[r].name);
4987 locked_rect.pBits = (void *)0xdeadbeef;
4988 locked_rect.Pitch = 1;
4989 hr = IDirect3DCubeTexture8_LockRect(cube_texture, D3DCUBEMAP_FACE_NEGATIVE_X, 0,
4990 &locked_rect, NULL, 0);
4991 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x, type %s.\n", hr, resources[r].name);
4992 ok(!locked_rect.pBits, "Got unexpected pBits %p, type %s.\n",
4993 locked_rect.pBits, resources[r].name);
4994 ok(!locked_rect.Pitch, "Got unexpected Pitch %u, type %s.\n",
4995 locked_rect.Pitch, resources[r].name);
4996 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, NULL, 0);
4997 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x, type %s.\n", hr, resources[r].name);
4998 hr = IDirect3DCubeTexture8_UnlockRect(cube_texture, D3DCUBEMAP_FACE_NEGATIVE_X, 0);
4999 ok(SUCCEEDED(hr), "Failed to unlock texture, hr %#x, type %s.\n", hr, resources[r].name);
5001 hr = IDirect3DCubeTexture8_LockRect(cube_texture, D3DCUBEMAP_FACE_NEGATIVE_X, 0,
5002 &locked_rect, &valid[0], 0);
5003 ok(hr == D3D_OK, "Got unexpected hr %#x for rect [%d, %d]->[%d, %d], type %s.\n",
5004 hr, valid[0].left, valid[0].top, valid[0].right, valid[0].bottom, resources[r].name);
5005 hr = IDirect3DCubeTexture8_LockRect(cube_texture, D3DCUBEMAP_FACE_NEGATIVE_X, 0,
5006 &locked_rect, &valid[0], 0);
5007 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for rect [%d, %d]->[%d, %d], type %s.\n",
5008 hr, valid[0].left, valid[0].top, valid[0].right, valid[0].bottom, resources[r].name);
5009 hr = IDirect3DCubeTexture8_LockRect(cube_texture, D3DCUBEMAP_FACE_NEGATIVE_X, 0,
5010 &locked_rect, &valid[1], 0);
5011 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for rect [%d, %d]->[%d, %d], type %s.\n",
5012 hr, valid[1].left, valid[1].top, valid[1].right, valid[1].bottom, resources[r].name);
5013 hr = IDirect3DCubeTexture8_UnlockRect(cube_texture, D3DCUBEMAP_FACE_NEGATIVE_X, 0);
5014 ok(SUCCEEDED(hr), "Failed to unlock texture, hr %#x, type %s.\n", hr, resources[r].name);
5016 IDirect3DTexture8_Release(cube_texture);
5020 refcount = IDirect3DDevice8_Release(device);
5021 ok(!refcount, "Device has %u references left.\n", refcount);
5022 IDirect3D8_Release(d3d8);
5023 DestroyWindow(window);
5026 static void test_private_data(void)
5028 ULONG refcount, expected_refcount;
5029 IDirect3DTexture8 *texture;
5030 IDirect3DSurface8 *surface, *surface2;
5031 IDirect3DDevice8 *device;
5032 IDirect3D8 *d3d8;
5033 IUnknown *ptr;
5034 HWND window;
5035 HRESULT hr;
5036 DWORD size;
5037 DWORD data[4] = {1, 2, 3, 4};
5038 static const GUID d3d8_private_data_test_guid2 =
5040 0x2e5afac2,
5041 0x87b5,
5042 0x4c10,
5043 {0x9b,0x4b,0x89,0xd7,0xd1,0x12,0xe7,0x2b}
5046 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
5047 0, 0, 640, 480, 0, 0, 0, 0);
5048 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
5049 ok(!!d3d8, "Failed to create a D3D object.\n");
5050 if (!(device = create_device(d3d8, window, NULL)))
5052 skip("Failed to create a D3D device, skipping tests.\n");
5053 IDirect3D8_Release(d3d8);
5054 DestroyWindow(window);
5055 return;
5058 hr = IDirect3DDevice8_CreateImageSurface(device, 4, 4, D3DFMT_A8R8G8B8, &surface);
5059 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5061 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
5062 device, 0, D3DSPD_IUNKNOWN);
5063 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
5064 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
5065 device, 5, D3DSPD_IUNKNOWN);
5066 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
5067 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
5068 device, sizeof(IUnknown *) * 2, D3DSPD_IUNKNOWN);
5069 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
5071 /* A failing SetPrivateData call does not clear the old data with the same tag. */
5072 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid, device,
5073 sizeof(device), D3DSPD_IUNKNOWN);
5074 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
5075 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid, device,
5076 sizeof(device) * 2, D3DSPD_IUNKNOWN);
5077 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
5078 size = sizeof(ptr);
5079 hr = IDirect3DSurface8_GetPrivateData(surface, &d3d8_private_data_test_guid, &ptr, &size);
5080 ok(SUCCEEDED(hr), "Failed to get private data, hr %#x.\n", hr);
5081 IUnknown_Release(ptr);
5082 hr = IDirect3DSurface8_FreePrivateData(surface, &d3d8_private_data_test_guid);
5083 ok(SUCCEEDED(hr), "Failed to free private data, hr %#x.\n", hr);
5085 refcount = get_refcount((IUnknown *)device);
5086 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
5087 device, sizeof(IUnknown *), D3DSPD_IUNKNOWN);
5088 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
5089 expected_refcount = refcount + 1;
5090 refcount = get_refcount((IUnknown *)device);
5091 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5092 hr = IDirect3DSurface8_FreePrivateData(surface, &d3d8_private_data_test_guid);
5093 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
5094 expected_refcount = refcount - 1;
5095 refcount = get_refcount((IUnknown *)device);
5096 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5098 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
5099 device, sizeof(IUnknown *), D3DSPD_IUNKNOWN);
5100 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
5101 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
5102 surface, sizeof(IUnknown *), D3DSPD_IUNKNOWN);
5103 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
5104 refcount = get_refcount((IUnknown *)device);
5105 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5107 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid,
5108 device, sizeof(IUnknown *), D3DSPD_IUNKNOWN);
5109 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
5110 size = 2 * sizeof(ptr);
5111 hr = IDirect3DSurface8_GetPrivateData(surface, &d3d8_private_data_test_guid, &ptr, &size);
5112 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
5113 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5114 expected_refcount = refcount + 2;
5115 refcount = get_refcount((IUnknown *)device);
5116 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5117 ok(ptr == (IUnknown *)device, "Got unexpected ptr %p, expected %p.\n", ptr, device);
5118 IUnknown_Release(ptr);
5119 expected_refcount--;
5121 ptr = (IUnknown *)0xdeadbeef;
5122 size = 1;
5123 hr = IDirect3DSurface8_GetPrivateData(surface, &d3d8_private_data_test_guid, NULL, &size);
5124 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
5125 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5126 size = 2 * sizeof(ptr);
5127 hr = IDirect3DSurface8_GetPrivateData(surface, &d3d8_private_data_test_guid, NULL, &size);
5128 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
5129 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5130 refcount = get_refcount((IUnknown *)device);
5131 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5132 size = 1;
5133 hr = IDirect3DSurface8_GetPrivateData(surface, &d3d8_private_data_test_guid, &ptr, &size);
5134 ok(hr == D3DERR_MOREDATA, "Got unexpected hr %#x.\n", hr);
5135 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
5136 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
5137 hr = IDirect3DSurface8_GetPrivateData(surface, &d3d8_private_data_test_guid2, NULL, NULL);
5138 ok(hr == D3DERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
5139 size = 0xdeadbabe;
5140 hr = IDirect3DSurface8_GetPrivateData(surface, &d3d8_private_data_test_guid2, &ptr, &size);
5141 ok(hr == D3DERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
5142 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
5143 ok(size == 0xdeadbabe, "Got unexpected size %u.\n", size);
5144 /* GetPrivateData with size = NULL causes an access violation on Windows if the
5145 * requested data exists. */
5147 /* Destroying the surface frees the held reference. */
5148 IDirect3DSurface8_Release(surface);
5149 expected_refcount = refcount - 2;
5150 refcount = get_refcount((IUnknown *)device);
5151 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5153 hr = IDirect3DDevice8_CreateTexture(device, 4, 4, 2, 0, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &texture);
5154 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5155 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 0, &surface);
5156 ok(SUCCEEDED(hr), "Failed to get texture level 0, hr %#x.\n", hr);
5157 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 1, &surface2);
5158 ok(SUCCEEDED(hr), "Failed to get texture level 1, hr %#x.\n", hr);
5160 hr = IDirect3DTexture8_SetPrivateData(texture, &d3d8_private_data_test_guid, data, sizeof(data), 0);
5161 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
5163 memset(data, 0, sizeof(data));
5164 size = sizeof(data);
5165 hr = IDirect3DSurface8_GetPrivateData(surface, &d3d8_private_data_test_guid, data, &size);
5166 ok(hr == D3DERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
5167 hr = IDirect3DTexture8_GetPrivateData(texture, &d3d8_private_data_test_guid, data, &size);
5168 ok(SUCCEEDED(hr), "Failed to get private data, hr %#x.\n", hr);
5169 ok(data[0] == 1 && data[1] == 2 && data[2] == 3 && data[3] == 4,
5170 "Got unexpected private data: %u, %u, %u, %u.\n", data[0], data[1], data[2], data[3]);
5172 hr = IDirect3DTexture8_FreePrivateData(texture, &d3d8_private_data_test_guid);
5173 ok(SUCCEEDED(hr), "Failed to free private data, hr %#x.\n", hr);
5175 hr = IDirect3DSurface8_SetPrivateData(surface, &d3d8_private_data_test_guid, data, sizeof(data), 0);
5176 ok(SUCCEEDED(hr), "Failed to set private data, hr %#x.\n", hr);
5177 hr = IDirect3DSurface8_GetPrivateData(surface2, &d3d8_private_data_test_guid, data, &size);
5178 ok(hr == D3DERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
5179 hr = IDirect3DSurface8_FreePrivateData(surface, &d3d8_private_data_test_guid);
5180 ok(SUCCEEDED(hr), "Failed to free private data, hr %#x.\n", hr);
5182 IDirect3DSurface8_Release(surface2);
5183 IDirect3DSurface8_Release(surface);
5184 IDirect3DTexture8_Release(texture);
5186 refcount = IDirect3DDevice8_Release(device);
5187 ok(!refcount, "Device has %u references left.\n", refcount);
5188 IDirect3D8_Release(d3d8);
5189 DestroyWindow(window);
5192 static void test_surface_dimensions(void)
5194 IDirect3DSurface8 *surface;
5195 IDirect3DDevice8 *device;
5196 IDirect3D8 *d3d8;
5197 ULONG refcount;
5198 HWND window;
5199 HRESULT hr;
5201 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
5202 0, 0, 640, 480, 0, 0, 0, 0);
5203 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
5204 ok(!!d3d8, "Failed to create a D3D object.\n");
5205 if (!(device = create_device(d3d8, window, NULL)))
5207 skip("Failed to create a D3D device, skipping tests.\n");
5208 IDirect3D8_Release(d3d8);
5209 DestroyWindow(window);
5210 return;
5213 hr = IDirect3DDevice8_CreateImageSurface(device, 0, 1, D3DFMT_A8R8G8B8, &surface);
5214 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
5215 hr = IDirect3DDevice8_CreateImageSurface(device, 1, 0, D3DFMT_A8R8G8B8, &surface);
5216 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
5218 refcount = IDirect3DDevice8_Release(device);
5219 ok(!refcount, "Device has %u references left.\n", refcount);
5220 IDirect3D8_Release(d3d8);
5221 DestroyWindow(window);
5224 static void test_surface_format_null(void)
5226 static const D3DFORMAT D3DFMT_NULL = MAKEFOURCC('N','U','L','L');
5227 IDirect3DTexture8 *texture;
5228 IDirect3DSurface8 *surface;
5229 IDirect3DSurface8 *rt, *ds;
5230 D3DLOCKED_RECT locked_rect;
5231 IDirect3DDevice8 *device;
5232 D3DSURFACE_DESC desc;
5233 IDirect3D8 *d3d;
5234 ULONG refcount;
5235 HWND window;
5236 HRESULT hr;
5238 d3d = Direct3DCreate8(D3D_SDK_VERSION);
5239 ok(!!d3d, "Failed to create a D3D object.\n");
5241 hr = IDirect3D8_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
5242 D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, D3DFMT_NULL);
5243 if (hr != D3D_OK)
5245 skip("No D3DFMT_NULL support, skipping test.\n");
5246 IDirect3D8_Release(d3d);
5247 return;
5250 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
5251 0, 0, 640, 480, 0, 0, 0, 0);
5252 if (!(device = create_device(d3d, window, NULL)))
5254 skip("Failed to create a D3D device, skipping tests.\n");
5255 IDirect3D8_Release(d3d);
5256 DestroyWindow(window);
5257 return;
5260 hr = IDirect3D8_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
5261 D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, D3DFMT_NULL);
5262 ok(hr == D3D_OK, "D3DFMT_NULL should be supported for render target textures, hr %#x.\n", hr);
5264 hr = IDirect3D8_CheckDepthStencilMatch(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
5265 D3DFMT_NULL, D3DFMT_D24S8);
5266 ok(SUCCEEDED(hr), "Depth stencil match failed for D3DFMT_NULL, hr %#x.\n", hr);
5268 hr = IDirect3DDevice8_CreateRenderTarget(device, 128, 128, D3DFMT_NULL,
5269 D3DMULTISAMPLE_NONE, TRUE, &surface);
5270 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
5272 hr = IDirect3DDevice8_GetRenderTarget(device, &rt);
5273 ok(SUCCEEDED(hr), "Failed to get original render target, hr %#x.\n", hr);
5275 hr = IDirect3DDevice8_GetDepthStencilSurface(device, &ds);
5276 ok(SUCCEEDED(hr), "Failed to get original depth/stencil, hr %#x.\n", hr);
5278 hr = IDirect3DDevice8_SetRenderTarget(device, surface, NULL);
5279 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
5281 hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00000000, 0.0f, 0);
5282 ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
5284 hr = IDirect3DDevice8_SetRenderTarget(device, rt, ds);
5285 ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr);
5287 IDirect3DSurface8_Release(rt);
5288 IDirect3DSurface8_Release(ds);
5290 hr = IDirect3DSurface8_GetDesc(surface, &desc);
5291 ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
5292 ok(desc.Width == 128, "Expected width 128, got %u.\n", desc.Width);
5293 ok(desc.Height == 128, "Expected height 128, got %u.\n", desc.Height);
5295 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, NULL, 0);
5296 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
5297 ok(locked_rect.Pitch, "Expected non-zero pitch, got %u.\n", locked_rect.Pitch);
5298 ok(!!locked_rect.pBits, "Expected non-NULL pBits, got %p.\n", locked_rect.pBits);
5300 hr = IDirect3DSurface8_UnlockRect(surface);
5301 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5303 IDirect3DSurface8_Release(surface);
5305 hr = IDirect3DDevice8_CreateTexture(device, 128, 128, 0, D3DUSAGE_RENDERTARGET,
5306 D3DFMT_NULL, D3DPOOL_DEFAULT, &texture);
5307 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5308 IDirect3DTexture8_Release(texture);
5310 refcount = IDirect3DDevice8_Release(device);
5311 ok(!refcount, "Device has %u references left.\n", refcount);
5312 IDirect3D8_Release(d3d);
5313 DestroyWindow(window);
5316 static void test_surface_double_unlock(void)
5318 static const D3DPOOL pools[] =
5320 D3DPOOL_DEFAULT,
5321 D3DPOOL_SYSTEMMEM,
5323 IDirect3DSurface8 *surface;
5324 IDirect3DDevice8 *device;
5325 D3DLOCKED_RECT lr;
5326 IDirect3D8 *d3d;
5327 unsigned int i;
5328 ULONG refcount;
5329 HWND window;
5330 HRESULT hr;
5332 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
5333 0, 0, 640, 480, 0, 0, 0, 0);
5334 d3d = Direct3DCreate8(D3D_SDK_VERSION);
5335 ok(!!d3d, "Failed to create a D3D object.\n");
5336 if (!(device = create_device(d3d, window, NULL)))
5338 skip("Failed to create a D3D device, skipping tests.\n");
5339 IDirect3D8_Release(d3d);
5340 DestroyWindow(window);
5341 return;
5344 for (i = 0; i < (sizeof(pools) / sizeof(*pools)); ++i)
5346 switch (pools[i])
5348 case D3DPOOL_DEFAULT:
5349 hr = IDirect3D8_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
5350 D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, D3DFMT_X8R8G8B8);
5351 if (FAILED(hr))
5353 skip("D3DFMT_X8R8G8B8 render targets not supported, skipping double unlock DEFAULT pool test.\n");
5354 continue;
5357 hr = IDirect3DDevice8_CreateRenderTarget(device, 64, 64, D3DFMT_X8R8G8B8,
5358 D3DMULTISAMPLE_NONE, TRUE, &surface);
5359 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
5360 break;
5362 case D3DPOOL_SYSTEMMEM:
5363 hr = IDirect3DDevice8_CreateImageSurface(device, 64, 64, D3DFMT_X8R8G8B8, &surface);
5364 ok(SUCCEEDED(hr), "Failed to create image surface, hr %#x.\n", hr);
5365 break;
5367 default:
5368 break;
5371 hr = IDirect3DSurface8_UnlockRect(surface);
5372 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x, for surface in pool %#x.\n", hr, pools[i]);
5373 hr = IDirect3DSurface8_LockRect(surface, &lr, NULL, 0);
5374 ok(SUCCEEDED(hr), "Failed to lock surface in pool %#x, hr %#x.\n", pools[i], hr);
5375 hr = IDirect3DSurface8_UnlockRect(surface);
5376 ok(SUCCEEDED(hr), "Failed to unlock surface in pool %#x, hr %#x.\n", pools[i], hr);
5377 hr = IDirect3DSurface8_UnlockRect(surface);
5378 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x, for surface in pool %#x.\n", hr, pools[i]);
5380 IDirect3DSurface8_Release(surface);
5383 refcount = IDirect3DDevice8_Release(device);
5384 ok(!refcount, "Device has %u references left.\n", refcount);
5385 IDirect3D8_Release(d3d);
5386 DestroyWindow(window);
5389 static void test_surface_blocks(void)
5391 static const struct
5393 D3DFORMAT fmt;
5394 const char *name;
5395 unsigned int block_width;
5396 unsigned int block_height;
5397 BOOL broken;
5398 BOOL create_size_checked, core_fmt;
5400 formats[] =
5402 {D3DFMT_DXT1, "D3DFMT_DXT1", 4, 4, FALSE, TRUE, TRUE },
5403 {D3DFMT_DXT2, "D3DFMT_DXT2", 4, 4, FALSE, TRUE, TRUE },
5404 {D3DFMT_DXT3, "D3DFMT_DXT3", 4, 4, FALSE, TRUE, TRUE },
5405 {D3DFMT_DXT4, "D3DFMT_DXT4", 4, 4, FALSE, TRUE, TRUE },
5406 {D3DFMT_DXT5, "D3DFMT_DXT5", 4, 4, FALSE, TRUE, TRUE },
5407 /* ATI1N and ATI2N have 2x2 blocks on all AMD cards and Geforce 7 cards,
5408 * which doesn't match the format spec. On newer Nvidia cards
5409 * they have the correct 4x4 block size */
5410 {MAKEFOURCC('A','T','I','1'), "ATI1N", 4, 4, TRUE, FALSE, FALSE},
5411 {MAKEFOURCC('A','T','I','2'), "ATI2N", 4, 4, TRUE, FALSE, FALSE},
5412 /* Windows drivers generally enforce block-aligned locks for
5413 * YUY2 and UYVY. The notable exception is the AMD r500 driver
5414 * in d3d8. The same driver checks the sizes in d3d9. */
5415 {D3DFMT_YUY2, "D3DFMT_YUY2", 2, 1, TRUE, FALSE, TRUE },
5416 {D3DFMT_UYVY, "D3DFMT_UYVY", 2, 1, TRUE, FALSE, TRUE },
5418 static const struct
5420 D3DPOOL pool;
5421 const char *name;
5422 /* Don't check the return value, Nvidia returns D3DERR_INVALIDCALL for some formats
5423 * and E_INVALIDARG/DDERR_INVALIDPARAMS for others. */
5424 BOOL success;
5426 pools[] =
5428 {D3DPOOL_DEFAULT, "D3DPOOL_DEFAULT", FALSE},
5429 {D3DPOOL_SCRATCH, "D3DPOOL_SCRATCH", TRUE},
5430 {D3DPOOL_SYSTEMMEM, "D3DPOOL_SYSTEMMEM",TRUE},
5431 {D3DPOOL_MANAGED, "D3DPOOL_MANAGED", TRUE},
5433 static struct
5435 D3DRESOURCETYPE rtype;
5436 const char *type_name;
5437 D3DPOOL pool;
5438 const char *pool_name;
5439 BOOL need_driver_support, need_runtime_support;
5441 create_tests[] =
5443 /* D3d8 only supports sysmem surfaces, which are created via CreateImageSurface. Other tests confirm
5444 * that they are D3DPOOL_SYSTEMMEM surfaces, but their creation restriction behaves like the scratch
5445 * pool in d3d9. */
5446 {D3DRTYPE_SURFACE, "D3DRTYPE_SURFACE", D3DPOOL_SYSTEMMEM, "D3DPOOL_SYSTEMMEM", FALSE, TRUE },
5448 {D3DRTYPE_TEXTURE, "D3DRTYPE_TEXTURE", D3DPOOL_DEFAULT, "D3DPOOL_DEFAULT", TRUE, FALSE },
5449 {D3DRTYPE_TEXTURE, "D3DRTYPE_TEXTURE", D3DPOOL_SYSTEMMEM, "D3DPOOL_SYSTEMMEM", TRUE, FALSE },
5450 {D3DRTYPE_TEXTURE, "D3DRTYPE_TEXTURE", D3DPOOL_MANAGED, "D3DPOOL_MANAGED", TRUE, FALSE },
5451 {D3DRTYPE_TEXTURE, "D3DRTYPE_TEXTURE", D3DPOOL_SCRATCH, "D3DPOOL_SCRATCH", FALSE, TRUE },
5453 {D3DRTYPE_CUBETEXTURE, "D3DRTYPE_CUBETEXTURE", D3DPOOL_DEFAULT, "D3DPOOL_DEFAULT", TRUE, FALSE },
5454 {D3DRTYPE_CUBETEXTURE, "D3DRTYPE_CUBETEXTURE", D3DPOOL_SYSTEMMEM, "D3DPOOL_SYSTEMMEM", TRUE, FALSE },
5455 {D3DRTYPE_CUBETEXTURE, "D3DRTYPE_CUBETEXTURE", D3DPOOL_MANAGED, "D3DPOOL_MANAGED", TRUE, FALSE },
5456 {D3DRTYPE_CUBETEXTURE, "D3DRTYPE_CUBETEXTURE", D3DPOOL_SCRATCH, "D3DPOOL_SCRATCH", FALSE, TRUE },
5458 IDirect3DTexture8 *texture;
5459 IDirect3DCubeTexture8 *cube_texture;
5460 IDirect3DSurface8 *surface;
5461 D3DLOCKED_RECT locked_rect;
5462 IDirect3DDevice8 *device;
5463 unsigned int i, j, k, w, h;
5464 IDirect3D8 *d3d;
5465 ULONG refcount;
5466 HWND window;
5467 HRESULT hr;
5468 RECT rect;
5469 BOOL tex_pow2, cube_pow2;
5470 D3DCAPS8 caps;
5471 static const RECT invalid[] =
5473 {60, 60, 60, 68}, /* 0 height */
5474 {60, 60, 68, 60}, /* 0 width */
5475 {68, 60, 60, 68}, /* left > right */
5476 {60, 68, 68, 60}, /* top > bottom */
5477 {-8, 60, 0, 68}, /* left < surface */
5478 {60, -8, 68, 0}, /* top < surface */
5479 {-16, 60, -8, 68}, /* right < surface */
5480 {60, -16, 68, -8}, /* bottom < surface */
5481 {60, 60, 136, 68}, /* right > surface */
5482 {60, 60, 68, 136}, /* bottom > surface */
5483 {136, 60, 144, 68}, /* left > surface */
5484 {60, 136, 68, 144}, /* top > surface */
5487 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
5488 0, 0, 640, 480, 0, 0, 0, 0);
5489 d3d = Direct3DCreate8(D3D_SDK_VERSION);
5490 ok(!!d3d, "Failed to create a D3D object.\n");
5491 if (!(device = create_device(d3d, window, NULL)))
5493 skip("Failed to create a D3D device, skipping tests.\n");
5494 IDirect3D8_Release(d3d);
5495 DestroyWindow(window);
5496 return;
5499 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
5500 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
5501 tex_pow2 = caps.TextureCaps & D3DPTEXTURECAPS_POW2;
5502 if (tex_pow2)
5503 tex_pow2 = !(caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL);
5504 cube_pow2 = !!(caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP_POW2);
5506 for (i = 0; i < (sizeof(formats) / sizeof(*formats)); ++i)
5508 BOOL tex_support, cube_support, surface_support, format_known;
5510 hr = IDirect3D8_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
5511 0, D3DRTYPE_TEXTURE, formats[i].fmt);
5512 tex_support = SUCCEEDED(hr);
5513 hr = IDirect3D8_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
5514 0, D3DRTYPE_CUBETEXTURE, formats[i].fmt);
5515 cube_support = SUCCEEDED(hr);
5516 hr = IDirect3D8_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
5517 0, D3DRTYPE_SURFACE, formats[i].fmt);
5518 surface_support = SUCCEEDED(hr);
5520 /* Scratch pool in general allows texture creation even if the driver does
5521 * not support the format. If the format is an extension format that is not
5522 * known to the runtime, like ATI2N, some driver support is required for
5523 * this to work.
5525 * It is also possible that Windows Vista and Windows 7 d3d8 runtimes know
5526 * about ATI2N. I cannot check this because all my Vista+ machines support
5527 * ATI2N in hardware, but none of my WinXP machines do. */
5528 format_known = tex_support || cube_support || surface_support;
5530 for (w = 1; w <= 8; w++)
5532 for (h = 1; h <= 8; h++)
5534 BOOL block_aligned = TRUE;
5535 BOOL size_is_pow2;
5537 if (w & (formats[i].block_width - 1) || h & (formats[i].block_height - 1))
5538 block_aligned = FALSE;
5540 size_is_pow2 = !(w & (w - 1) || h & (h - 1));
5542 for (j = 0; j < sizeof(create_tests) / sizeof(*create_tests); j++)
5544 BOOL support, pow2;
5545 HRESULT expect_hr;
5546 BOOL may_succeed = FALSE;
5547 IUnknown **check_null;
5549 if (!formats[i].core_fmt)
5551 /* AMD warns against creating ATI2N textures smaller than
5552 * the block size because the runtime cannot calculate the
5553 * correct texture size. Generalize this for all extension
5554 * formats. */
5555 if (w < formats[i].block_width || h < formats[i].block_height)
5556 continue;
5559 texture = (IDirect3DTexture8 *)0xdeadbeef;
5560 cube_texture = (IDirect3DCubeTexture8 *)0xdeadbeef;
5561 surface = (IDirect3DSurface8 *)0xdeadbeef;
5563 switch (create_tests[j].rtype)
5565 case D3DRTYPE_TEXTURE:
5566 check_null = (IUnknown **)&texture;
5567 hr = IDirect3DDevice8_CreateTexture(device, w, h, 1, 0,
5568 formats[i].fmt, create_tests[j].pool, &texture);
5569 support = tex_support;
5570 pow2 = tex_pow2;
5571 break;
5573 case D3DRTYPE_CUBETEXTURE:
5574 if (w != h)
5575 continue;
5576 check_null = (IUnknown **)&cube_texture;
5577 hr = IDirect3DDevice8_CreateCubeTexture(device, w, 1, 0,
5578 formats[i].fmt, create_tests[j].pool, &cube_texture);
5579 support = cube_support;
5580 pow2 = cube_pow2;
5581 break;
5583 case D3DRTYPE_SURFACE:
5584 check_null = (IUnknown **)&surface;
5585 hr = IDirect3DDevice8_CreateImageSurface(device, w, h,
5586 formats[i].fmt, &surface);
5587 support = surface_support;
5588 pow2 = FALSE;
5589 break;
5591 default:
5592 pow2 = FALSE;
5593 support = FALSE;
5594 check_null = NULL;
5595 break;
5598 if (create_tests[j].need_driver_support && !support)
5599 expect_hr = D3DERR_INVALIDCALL;
5600 else if (create_tests[j].need_runtime_support && !formats[i].core_fmt && !format_known)
5601 expect_hr = D3DERR_INVALIDCALL;
5602 else if (formats[i].create_size_checked && !block_aligned)
5603 expect_hr = D3DERR_INVALIDCALL;
5604 else if (pow2 && !size_is_pow2 && create_tests[j].need_driver_support)
5605 expect_hr = D3DERR_INVALIDCALL;
5606 else
5607 expect_hr = D3D_OK;
5609 if (!formats[i].core_fmt && !format_known && FAILED(expect_hr))
5610 may_succeed = TRUE;
5612 /* Wine knows about ATI2N and happily creates a scratch resource even if GL
5613 * does not support it. Accept scratch creation of extension formats on
5614 * Windows as well if it occurs. We don't really care if e.g. a Windows 7
5615 * on an r200 GPU creates scratch ATI2N texture even though the card doesn't
5616 * support it. */
5617 ok(hr == expect_hr || ((SUCCEEDED(hr) && may_succeed)),
5618 "Got unexpected hr %#x for format %s, pool %s, type %s, size %ux%u.\n",
5619 hr, formats[i].name, create_tests[j].pool_name, create_tests[j].type_name, w, h);
5621 if (FAILED(hr))
5622 ok(*check_null == NULL, "Got object ptr %p, expected NULL.\n", *check_null);
5623 else
5624 IUnknown_Release(*check_null);
5629 hr = IDirect3D8_CheckDeviceFormat(d3d, 0, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
5630 D3DUSAGE_DYNAMIC, D3DRTYPE_TEXTURE, formats[i].fmt);
5631 if (FAILED(hr))
5633 skip("Format %s not supported, skipping lockrect offset tests.\n", formats[i].name);
5634 continue;
5637 for (j = 0; j < (sizeof(pools) / sizeof(*pools)); ++j)
5639 hr = IDirect3DDevice8_CreateTexture(device, 128, 128, 1,
5640 pools[j].pool == D3DPOOL_DEFAULT ? D3DUSAGE_DYNAMIC : 0,
5641 formats[i].fmt, pools[j].pool, &texture);
5642 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5643 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 0, &surface);
5644 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
5645 IDirect3DTexture8_Release(texture);
5647 if (formats[i].block_width > 1)
5649 SetRect(&rect, formats[i].block_width >> 1, 0, formats[i].block_width, formats[i].block_height);
5650 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, &rect, 0);
5651 ok(FAILED(hr) == !pools[j].success || broken(formats[i].broken),
5652 "Partial block lock %s, expected %s, format %s, pool %s.\n",
5653 SUCCEEDED(hr) ? "succeeded" : "failed",
5654 pools[j].success ? "success" : "failure", formats[i].name, pools[j].name);
5655 if (SUCCEEDED(hr))
5657 hr = IDirect3DSurface8_UnlockRect(surface);
5658 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5661 SetRect(&rect, 0, 0, formats[i].block_width >> 1, formats[i].block_height);
5662 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, &rect, 0);
5663 ok(FAILED(hr) == !pools[j].success || broken(formats[i].broken),
5664 "Partial block lock %s, expected %s, format %s, pool %s.\n",
5665 SUCCEEDED(hr) ? "succeeded" : "failed",
5666 pools[j].success ? "success" : "failure", formats[i].name, pools[j].name);
5667 if (SUCCEEDED(hr))
5669 hr = IDirect3DSurface8_UnlockRect(surface);
5670 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5674 if (formats[i].block_height > 1)
5676 SetRect(&rect, 0, formats[i].block_height >> 1, formats[i].block_width, formats[i].block_height);
5677 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, &rect, 0);
5678 ok(FAILED(hr) == !pools[j].success || broken(formats[i].broken),
5679 "Partial block lock %s, expected %s, format %s, pool %s.\n",
5680 SUCCEEDED(hr) ? "succeeded" : "failed",
5681 pools[j].success ? "success" : "failure", formats[i].name, pools[j].name);
5682 if (SUCCEEDED(hr))
5684 hr = IDirect3DSurface8_UnlockRect(surface);
5685 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5688 SetRect(&rect, 0, 0, formats[i].block_width, formats[i].block_height >> 1);
5689 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, &rect, 0);
5690 ok(FAILED(hr) == !pools[j].success || broken(formats[i].broken),
5691 "Partial block lock %s, expected %s, format %s, pool %s.\n",
5692 SUCCEEDED(hr) ? "succeeded" : "failed",
5693 pools[j].success ? "success" : "failure", formats[i].name, pools[j].name);
5694 if (SUCCEEDED(hr))
5696 hr = IDirect3DSurface8_UnlockRect(surface);
5697 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5701 for (k = 0; k < sizeof(invalid) / sizeof(*invalid); ++k)
5703 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, &invalid[k], 0);
5704 ok(FAILED(hr) == !pools[j].success, "Invalid lock %s(%#x), expected %s, format %s, pool %s, case %u.\n",
5705 SUCCEEDED(hr) ? "succeeded" : "failed", hr, pools[j].success ? "success" : "failure",
5706 formats[i].name, pools[j].name, k);
5707 if (SUCCEEDED(hr))
5709 hr = IDirect3DSurface8_UnlockRect(surface);
5710 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5714 SetRect(&rect, 0, 0, formats[i].block_width, formats[i].block_height);
5715 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, &rect, 0);
5716 ok(hr == D3D_OK, "Got unexpected hr %#x for format %s, pool %s.\n", hr, formats[i].name, pools[j].name);
5717 hr = IDirect3DSurface8_UnlockRect(surface);
5718 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5720 IDirect3DSurface8_Release(surface);
5723 if (formats[i].block_width == 1 && formats[i].block_height == 1)
5724 continue;
5725 if (!formats[i].core_fmt)
5726 continue;
5728 hr = IDirect3DDevice8_CreateTexture(device, formats[i].block_width, formats[i].block_height, 2,
5729 D3DUSAGE_DYNAMIC, formats[i].fmt, D3DPOOL_DEFAULT, &texture);
5730 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x, format %s.\n", hr, formats[i].name);
5732 hr = IDirect3DTexture8_LockRect(texture, 1, &locked_rect, NULL, 0);
5733 ok(SUCCEEDED(hr), "Failed lock texture, hr %#x.\n", hr);
5734 hr = IDirect3DTexture8_UnlockRect(texture, 1);
5735 ok(SUCCEEDED(hr), "Failed lock texture, hr %#x.\n", hr);
5737 rect.left = 0;
5738 rect.top = 0;
5739 rect.right = formats[i].block_width == 1 ? 1 : formats[i].block_width >> 1;
5740 rect.bottom = formats[i].block_height == 1 ? 1 : formats[i].block_height >> 1;
5741 hr = IDirect3DTexture8_LockRect(texture, 1, &locked_rect, &rect, 0);
5742 ok(SUCCEEDED(hr), "Failed lock texture, hr %#x.\n", hr);
5743 hr = IDirect3DTexture8_UnlockRect(texture, 1);
5744 ok(SUCCEEDED(hr), "Failed lock texture, hr %#x.\n", hr);
5746 rect.right = formats[i].block_width;
5747 rect.bottom = formats[i].block_height;
5748 hr = IDirect3DTexture8_LockRect(texture, 1, &locked_rect, &rect, 0);
5749 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
5750 if (SUCCEEDED(hr))
5751 IDirect3DTexture8_UnlockRect(texture, 1);
5753 IDirect3DTexture8_Release(texture);
5756 refcount = IDirect3DDevice8_Release(device);
5757 ok(!refcount, "Device has %u references left.\n", refcount);
5758 IDirect3D8_Release(d3d);
5759 DestroyWindow(window);
5762 static void test_set_palette(void)
5764 IDirect3DDevice8 *device;
5765 IDirect3D8 *d3d8;
5766 UINT refcount;
5767 HWND window;
5768 HRESULT hr;
5769 PALETTEENTRY pal[256];
5770 unsigned int i;
5771 D3DCAPS8 caps;
5773 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
5774 0, 0, 640, 480, 0, 0, 0, 0);
5775 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
5776 ok(!!d3d8, "Failed to create a D3D object.\n");
5777 if (!(device = create_device(d3d8, window, NULL)))
5779 skip("Failed to create a D3D device, skipping tests.\n");
5780 IDirect3D8_Release(d3d8);
5781 DestroyWindow(window);
5782 return;
5785 for (i = 0; i < sizeof(pal) / sizeof(*pal); i++)
5787 pal[i].peRed = i;
5788 pal[i].peGreen = i;
5789 pal[i].peBlue = i;
5790 pal[i].peFlags = 0xff;
5792 hr = IDirect3DDevice8_SetPaletteEntries(device, 0, pal);
5793 ok(SUCCEEDED(hr), "Failed to set palette entries, hr %#x.\n", hr);
5795 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
5796 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
5797 for (i = 0; i < sizeof(pal) / sizeof(*pal); i++)
5799 pal[i].peRed = i;
5800 pal[i].peGreen = i;
5801 pal[i].peBlue = i;
5802 pal[i].peFlags = i;
5804 if (caps.TextureCaps & D3DPTEXTURECAPS_ALPHAPALETTE)
5806 hr = IDirect3DDevice8_SetPaletteEntries(device, 0, pal);
5807 ok(SUCCEEDED(hr), "Failed to set palette entries, hr %#x.\n", hr);
5809 else
5811 hr = IDirect3DDevice8_SetPaletteEntries(device, 0, pal);
5812 ok(hr == D3DERR_INVALIDCALL, "SetPaletteEntries returned %#x, expected D3DERR_INVALIDCALL.\n", hr);
5815 refcount = IDirect3DDevice8_Release(device);
5816 ok(!refcount, "Device has %u references left.\n", refcount);
5817 IDirect3D8_Release(d3d8);
5818 DestroyWindow(window);
5821 static void test_swvp_buffer(void)
5823 IDirect3DDevice8 *device;
5824 IDirect3D8 *d3d8;
5825 UINT refcount;
5826 HWND window;
5827 HRESULT hr;
5828 unsigned int i;
5829 IDirect3DVertexBuffer8 *buffer;
5830 static const unsigned int bufsize = 1024;
5831 D3DVERTEXBUFFER_DESC desc;
5832 struct device_desc device_desc;
5833 struct
5835 float x, y, z;
5836 } *ptr, *ptr2;
5838 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
5839 0, 0, 640, 480, 0, 0, 0, 0);
5840 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
5841 ok(!!d3d8, "Failed to create a D3D object.\n");
5843 device_desc.device_window = window;
5844 device_desc.width = 640;
5845 device_desc.height = 480;
5846 device_desc.flags = CREATE_DEVICE_SWVP_ONLY;
5847 if (!(device = create_device(d3d8, window, &device_desc)))
5849 skip("Failed to create a D3D device, skipping tests.\n");
5850 IDirect3D8_Release(d3d8);
5851 DestroyWindow(window);
5852 return;
5855 hr = IDirect3DDevice8_CreateVertexBuffer(device, bufsize * sizeof(*ptr), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, 0,
5856 D3DPOOL_DEFAULT, &buffer);
5857 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
5858 hr = IDirect3DVertexBuffer8_GetDesc(buffer, &desc);
5859 ok(SUCCEEDED(hr), "Failed to get desc, hr %#x.\n", hr);
5860 ok(desc.Pool == D3DPOOL_DEFAULT, "Got pool %u, expected D3DPOOL_DEFAULT\n", desc.Pool);
5861 ok(desc.Usage == (D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY),
5862 "Got usage %u, expected D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY\n", desc.Usage);
5864 hr = IDirect3DVertexBuffer8_Lock(buffer, 0, bufsize * sizeof(*ptr), (BYTE **)&ptr, D3DLOCK_DISCARD);
5865 ok(SUCCEEDED(hr), "Failed to lock buffer, hr %#x.\n", hr);
5866 for (i = 0; i < bufsize; i++)
5868 ptr[i].x = i * 1.0f;
5869 ptr[i].y = i * 2.0f;
5870 ptr[i].z = i * 3.0f;
5872 hr = IDirect3DVertexBuffer8_Unlock(buffer);
5873 ok(SUCCEEDED(hr), "Failed to unlock buffer, hr %#x.\n", hr);
5875 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ);
5876 ok(SUCCEEDED(hr), "Failed to set fvf, hr %#x.\n", hr);
5877 hr = IDirect3DDevice8_SetStreamSource(device, 0, buffer, sizeof(*ptr));
5878 ok(SUCCEEDED(hr), "Failed to set stream source, hr %#x.\n", hr);
5879 hr = IDirect3DDevice8_BeginScene(device);
5880 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
5881 hr = IDirect3DDevice8_DrawPrimitive(device, D3DPT_TRIANGLELIST, 0, 2);
5882 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
5883 hr = IDirect3DDevice8_EndScene(device);
5884 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
5886 hr = IDirect3DVertexBuffer8_Lock(buffer, 0, bufsize * sizeof(*ptr2), (BYTE **)&ptr2, D3DLOCK_DISCARD);
5887 ok(SUCCEEDED(hr), "Failed to lock buffer, hr %#x.\n", hr);
5888 ok(ptr == ptr2, "Lock returned two different pointers: %p, %p\n", ptr, ptr2);
5889 for (i = 0; i < bufsize; i++)
5891 if (ptr2[i].x != i * 1.0f || ptr2[i].y != i * 2.0f || ptr2[i].z != i * 3.0f)
5893 ok(FALSE, "Vertex %u is %f,%f,%f, expected %f,%f,%f\n", i,
5894 ptr2[i].x, ptr2[i].y, ptr2[i].z, i * 1.0f, i * 2.0f, i * 3.0f);
5895 break;
5898 hr = IDirect3DVertexBuffer8_Unlock(buffer);
5899 ok(SUCCEEDED(hr), "Failed to unlock buffer, hr %#x.\n", hr);
5901 IDirect3DVertexBuffer8_Release(buffer);
5902 refcount = IDirect3DDevice8_Release(device);
5903 ok(!refcount, "Device has %u references left.\n", refcount);
5904 IDirect3D8_Release(d3d8);
5905 DestroyWindow(window);
5908 static void test_managed_buffer(void)
5910 static const unsigned int vertex_count = 1024;
5911 IDirect3DVertexBuffer8 *buffer;
5912 D3DVERTEXBUFFER_DESC desc;
5913 IDirect3DDevice8 *device;
5914 struct vec3 *ptr, *ptr2;
5915 IDirect3D8 *d3d8;
5916 unsigned int i;
5917 UINT refcount;
5918 HWND window;
5919 HRESULT hr;
5921 window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW,
5922 0, 0, 640, 480, 0, 0, 0, 0);
5923 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
5924 ok(!!d3d8, "Failed to create a D3D object.\n");
5925 if (!(device = create_device(d3d8, window, NULL)))
5927 skip("Failed to create a D3D device, skipping tests.\n");
5928 IDirect3D8_Release(d3d8);
5929 DestroyWindow(window);
5930 return;
5933 hr = IDirect3DDevice8_CreateVertexBuffer(device, vertex_count * sizeof(*ptr), 0, 0, D3DPOOL_MANAGED, &buffer);
5934 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
5935 hr = IDirect3DVertexBuffer8_GetDesc(buffer, &desc);
5936 ok(SUCCEEDED(hr), "Failed to get desc, hr %#x.\n", hr);
5937 ok(desc.Pool == D3DPOOL_MANAGED, "Got unexpected pool %#x.\n", desc.Pool);
5938 ok(!desc.Usage, "Got unexpected usage %#x.\n", desc.Usage);
5940 hr = IDirect3DVertexBuffer8_Lock(buffer, 0, vertex_count * sizeof(*ptr), (BYTE **)&ptr, D3DLOCK_DISCARD);
5941 ok(SUCCEEDED(hr), "Failed to lock buffer, hr %#x.\n", hr);
5942 for (i = 0; i < vertex_count; ++i)
5944 ptr[i].x = i * 1.0f;
5945 ptr[i].y = i * 2.0f;
5946 ptr[i].z = i * 3.0f;
5948 hr = IDirect3DVertexBuffer8_Unlock(buffer);
5949 ok(SUCCEEDED(hr), "Failed to unlock buffer, hr %#x.\n", hr);
5951 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ);
5952 ok(SUCCEEDED(hr), "Failed to set fvf, hr %#x.\n", hr);
5953 hr = IDirect3DDevice8_SetStreamSource(device, 0, buffer, sizeof(*ptr));
5954 ok(SUCCEEDED(hr), "Failed to set stream source, hr %#x.\n", hr);
5955 hr = IDirect3DDevice8_BeginScene(device);
5956 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
5957 hr = IDirect3DDevice8_DrawPrimitive(device, D3DPT_TRIANGLELIST, 0, 2);
5958 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
5959 hr = IDirect3DDevice8_EndScene(device);
5960 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
5962 hr = IDirect3DVertexBuffer8_Lock(buffer, 0, vertex_count * sizeof(*ptr2), (BYTE **)&ptr2, D3DLOCK_DISCARD);
5963 ok(SUCCEEDED(hr), "Failed to lock buffer, hr %#x.\n", hr);
5964 ok(ptr2 == ptr, "Got unexpected ptr2 %p, expected %p.\n", ptr2, ptr);
5965 for (i = 0; i < vertex_count; ++i)
5967 if (ptr2[i].x != i * 1.0f || ptr2[i].y != i * 2.0f || ptr2[i].z != i * 3.0f)
5969 ok(FALSE, "Got unexpected vertex %u {%.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e}.\n",
5970 i, ptr2[i].x, ptr2[i].y, ptr2[i].z, i * 1.0f, i * 2.0f, i * 3.0f);
5971 break;
5974 hr = IDirect3DVertexBuffer8_Unlock(buffer);
5975 ok(SUCCEEDED(hr), "Failed to unlock buffer, hr %#x.\n", hr);
5977 IDirect3DVertexBuffer8_Release(buffer);
5978 refcount = IDirect3DDevice8_Release(device);
5979 ok(!refcount, "Device has %u references left.\n", refcount);
5980 IDirect3D8_Release(d3d8);
5981 DestroyWindow(window);
5984 static void test_npot_textures(void)
5986 IDirect3DDevice8 *device = NULL;
5987 IDirect3D8 *d3d8;
5988 ULONG refcount;
5989 HWND window = NULL;
5990 HRESULT hr;
5991 D3DCAPS8 caps;
5992 IDirect3DTexture8 *texture;
5993 IDirect3DCubeTexture8 *cube_texture;
5994 IDirect3DVolumeTexture8 *volume_texture;
5995 struct
5997 D3DPOOL pool;
5998 const char *pool_name;
5999 HRESULT hr;
6001 pools[] =
6003 { D3DPOOL_DEFAULT, "D3DPOOL_DEFAULT", D3DERR_INVALIDCALL },
6004 { D3DPOOL_MANAGED, "D3DPOOL_MANAGED", D3DERR_INVALIDCALL },
6005 { D3DPOOL_SYSTEMMEM, "D3DPOOL_SYSTEMMEM", D3DERR_INVALIDCALL },
6006 { D3DPOOL_SCRATCH, "D3DPOOL_SCRATCH", D3D_OK },
6008 unsigned int i, levels;
6009 BOOL tex_pow2, cube_pow2, vol_pow2;
6011 window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW,
6012 0, 0, 640, 480, 0, 0, 0, 0);
6013 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
6014 ok(!!d3d8, "Failed to create a D3D object.\n");
6015 if (!(device = create_device(d3d8, window, NULL)))
6017 skip("Failed to create a D3D device, skipping tests.\n");
6018 goto done;
6021 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
6022 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
6023 tex_pow2 = !!(caps.TextureCaps & D3DPTEXTURECAPS_POW2);
6024 cube_pow2 = !!(caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP_POW2);
6025 vol_pow2 = !!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP_POW2);
6026 ok(cube_pow2 == tex_pow2, "Cube texture and 2d texture pow2 restrictions mismatch.\n");
6027 ok(vol_pow2 == tex_pow2, "Volume texture and 2d texture pow2 restrictions mismatch.\n");
6029 for (i = 0; i < sizeof(pools) / sizeof(*pools); i++)
6031 for (levels = 0; levels <= 2; levels++)
6033 HRESULT expected;
6035 hr = IDirect3DDevice8_CreateTexture(device, 10, 10, levels, 0, D3DFMT_X8R8G8B8,
6036 pools[i].pool, &texture);
6037 if (!tex_pow2)
6039 expected = D3D_OK;
6041 else if (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL)
6043 if (levels == 1)
6044 expected = D3D_OK;
6045 else
6046 expected = pools[i].hr;
6048 else
6050 expected = pools[i].hr;
6052 ok(hr == expected, "CreateTexture(w=h=10, %s, levels=%u) returned hr %#x, expected %#x.\n",
6053 pools[i].pool_name, levels, hr, expected);
6055 if (SUCCEEDED(hr))
6056 IDirect3DTexture8_Release(texture);
6059 hr = IDirect3DDevice8_CreateCubeTexture(device, 3, 1, 0, D3DFMT_X8R8G8B8,
6060 pools[i].pool, &cube_texture);
6061 if (tex_pow2)
6063 ok(hr == pools[i].hr, "CreateCubeTexture(EdgeLength=3, %s) returned hr %#x, expected %#x.\n",
6064 pools[i].pool_name, hr, pools[i].hr);
6066 else
6068 ok(SUCCEEDED(hr), "CreateCubeTexture(EdgeLength=3, %s) returned hr %#x, expected %#x.\n",
6069 pools[i].pool_name, hr, D3D_OK);
6072 if (SUCCEEDED(hr))
6073 IDirect3DCubeTexture8_Release(cube_texture);
6075 hr = IDirect3DDevice8_CreateVolumeTexture(device, 2, 2, 3, 1, 0, D3DFMT_X8R8G8B8,
6076 pools[i].pool, &volume_texture);
6077 if (tex_pow2)
6079 ok(hr == pools[i].hr, "CreateVolumeTextur(Depth=3, %s) returned hr %#x, expected %#x.\n",
6080 pools[i].pool_name, hr, pools[i].hr);
6082 else
6084 ok(SUCCEEDED(hr), "CreateVolumeTextur(Depth=3, %s) returned hr %#x, expected %#x.\n",
6085 pools[i].pool_name, hr, D3D_OK);
6088 if (SUCCEEDED(hr))
6089 IDirect3DVolumeTexture8_Release(volume_texture);
6092 done:
6093 if (device)
6095 refcount = IDirect3DDevice8_Release(device);
6096 ok(!refcount, "Device has %u references left.\n", refcount);
6098 IDirect3D8_Release(d3d8);
6099 DestroyWindow(window);
6103 static void test_volume_locking(void)
6105 IDirect3DDevice8 *device;
6106 IDirect3D8 *d3d8;
6107 HWND window;
6108 HRESULT hr;
6109 IDirect3DVolumeTexture8 *texture;
6110 unsigned int i;
6111 D3DLOCKED_BOX locked_box;
6112 ULONG refcount;
6113 D3DCAPS8 caps;
6114 static const struct
6116 D3DPOOL pool;
6117 DWORD usage;
6118 HRESULT create_hr, lock_hr;
6120 tests[] =
6122 { D3DPOOL_DEFAULT, 0, D3D_OK, D3DERR_INVALIDCALL },
6123 { D3DPOOL_DEFAULT, D3DUSAGE_DYNAMIC, D3D_OK, D3D_OK },
6124 { D3DPOOL_SYSTEMMEM, 0, D3D_OK, D3D_OK },
6125 { D3DPOOL_SYSTEMMEM, D3DUSAGE_DYNAMIC, D3D_OK, D3D_OK },
6126 { D3DPOOL_MANAGED, 0, D3D_OK, D3D_OK },
6127 { D3DPOOL_MANAGED, D3DUSAGE_DYNAMIC, D3DERR_INVALIDCALL, D3D_OK },
6128 { D3DPOOL_SCRATCH, 0, D3D_OK, D3D_OK },
6129 { D3DPOOL_SCRATCH, D3DUSAGE_DYNAMIC, D3DERR_INVALIDCALL, D3D_OK },
6132 window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW,
6133 0, 0, 640, 480, 0, 0, 0, 0);
6134 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
6135 ok(!!d3d8, "Failed to create a D3D object.\n");
6136 if (!(device = create_device(d3d8, window, NULL)))
6138 skip("Failed to create a D3D device, skipping tests.\n");
6139 IDirect3D8_Release(d3d8);
6140 DestroyWindow(window);
6141 return;
6144 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
6145 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
6146 if (!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP))
6148 skip("Volume textures not supported, skipping test.\n");
6149 goto out;
6152 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
6154 hr = IDirect3DDevice8_CreateVolumeTexture(device, 4, 4, 4, 1, tests[i].usage,
6155 D3DFMT_A8R8G8B8, tests[i].pool, &texture);
6156 ok(hr == tests[i].create_hr, "Creating volume texture pool=%u, usage=%#x returned %#x, expected %#x.\n",
6157 tests[i].pool, tests[i].usage, hr, tests[i].create_hr);
6158 if (FAILED(hr))
6159 continue;
6161 locked_box.pBits = (void *)0xdeadbeef;
6162 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, NULL, 0);
6163 ok(hr == tests[i].lock_hr, "Lock returned %#x, expected %#x.\n", hr, tests[i].lock_hr);
6164 if (SUCCEEDED(hr))
6166 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6167 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6169 else
6171 ok (locked_box.pBits == NULL, "Failed lock set pBits = %p, expected NULL.\n", locked_box.pBits);
6173 IDirect3DVolumeTexture8_Release(texture);
6176 out:
6177 refcount = IDirect3DDevice8_Release(device);
6178 ok(!refcount, "Device has %u references left.\n", refcount);
6179 IDirect3D8_Release(d3d8);
6180 DestroyWindow(window);
6183 static void test_update_volumetexture(void)
6185 IDirect3DDevice8 *device;
6186 IDirect3D8 *d3d8;
6187 HWND window;
6188 HRESULT hr;
6189 IDirect3DVolumeTexture8 *src, *dst;
6190 unsigned int i;
6191 D3DLOCKED_BOX locked_box;
6192 ULONG refcount;
6193 D3DCAPS8 caps;
6194 static const struct
6196 D3DPOOL src_pool, dst_pool;
6197 HRESULT hr;
6199 tests[] =
6201 { D3DPOOL_DEFAULT, D3DPOOL_DEFAULT, D3DERR_INVALIDCALL },
6202 { D3DPOOL_MANAGED, D3DPOOL_DEFAULT, D3DERR_INVALIDCALL },
6203 { D3DPOOL_SYSTEMMEM, D3DPOOL_DEFAULT, D3D_OK },
6204 { D3DPOOL_SCRATCH, D3DPOOL_DEFAULT, D3DERR_INVALIDCALL },
6206 { D3DPOOL_DEFAULT, D3DPOOL_MANAGED, D3DERR_INVALIDCALL },
6207 { D3DPOOL_MANAGED, D3DPOOL_MANAGED, D3DERR_INVALIDCALL },
6208 { D3DPOOL_SYSTEMMEM, D3DPOOL_MANAGED, D3DERR_INVALIDCALL },
6209 { D3DPOOL_SCRATCH, D3DPOOL_MANAGED, D3DERR_INVALIDCALL },
6211 { D3DPOOL_DEFAULT, D3DPOOL_SYSTEMMEM, D3DERR_INVALIDCALL },
6212 { D3DPOOL_MANAGED, D3DPOOL_SYSTEMMEM, D3DERR_INVALIDCALL },
6213 { D3DPOOL_SYSTEMMEM, D3DPOOL_SYSTEMMEM, D3DERR_INVALIDCALL },
6214 { D3DPOOL_SCRATCH, D3DPOOL_SYSTEMMEM, D3DERR_INVALIDCALL },
6216 { D3DPOOL_DEFAULT, D3DPOOL_SCRATCH, D3DERR_INVALIDCALL },
6217 { D3DPOOL_MANAGED, D3DPOOL_SCRATCH, D3DERR_INVALIDCALL },
6218 { D3DPOOL_SYSTEMMEM, D3DPOOL_SCRATCH, D3DERR_INVALIDCALL },
6219 { D3DPOOL_SCRATCH, D3DPOOL_SCRATCH, D3DERR_INVALIDCALL },
6221 static const struct
6223 UINT src_size, dst_size;
6224 UINT src_lvl, dst_lvl;
6225 D3DFORMAT src_fmt, dst_fmt;
6227 tests2[] =
6229 { 8, 8, 0, 0, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 },
6230 { 8, 8, 4, 4, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 },
6231 { 8, 8, 2, 2, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 },
6232 { 8, 8, 1, 1, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 },
6233 { 8, 8, 4, 0, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 },
6234 { 8, 8, 1, 4, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 }, /* Different level count */
6235 { 4, 8, 1, 1, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8 }, /* Different size */
6236 { 8, 8, 4, 4, D3DFMT_A8R8G8B8, D3DFMT_X8R8G8B8 }, /* Different format */
6239 window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW,
6240 0, 0, 640, 480, 0, 0, 0, 0);
6241 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
6242 ok(!!d3d8, "Failed to create a D3D object.\n");
6243 if (!(device = create_device(d3d8, window, NULL)))
6245 skip("Failed to create a D3D device, skipping tests.\n");
6246 IDirect3D8_Release(d3d8);
6247 DestroyWindow(window);
6248 return;
6251 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
6252 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
6253 if (!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP))
6255 skip("Volume textures not supported, skipping test.\n");
6256 goto out;
6259 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
6261 DWORD src_usage = tests[i].src_pool == D3DPOOL_DEFAULT ? D3DUSAGE_DYNAMIC : 0;
6262 DWORD dst_usage = tests[i].dst_pool == D3DPOOL_DEFAULT ? D3DUSAGE_DYNAMIC : 0;
6264 hr = IDirect3DDevice8_CreateVolumeTexture(device, 1, 1, 1, 1, src_usage,
6265 D3DFMT_A8R8G8B8, tests[i].src_pool, &src);
6266 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x.\n", hr);
6267 hr = IDirect3DDevice8_CreateVolumeTexture(device, 1, 1, 1, 1, dst_usage,
6268 D3DFMT_A8R8G8B8, tests[i].dst_pool, &dst);
6269 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x.\n", hr);
6271 hr = IDirect3DVolumeTexture8_LockBox(src, 0, &locked_box, NULL, 0);
6272 ok(SUCCEEDED(hr), "Failed to lock volume texture, hr %#x.\n", hr);
6273 *((DWORD *)locked_box.pBits) = 0x11223344;
6274 hr = IDirect3DVolumeTexture8_UnlockBox(src, 0);
6275 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6277 hr = IDirect3DDevice8_UpdateTexture(device, (IDirect3DBaseTexture8 *)src, (IDirect3DBaseTexture8 *)dst);
6278 ok(hr == tests[i].hr, "UpdateTexture returned %#x, expected %#x, src pool %x, dst pool %u.\n",
6279 hr, tests[i].hr, tests[i].src_pool, tests[i].dst_pool);
6281 if (SUCCEEDED(hr))
6283 DWORD content = *((DWORD *)locked_box.pBits);
6284 hr = IDirect3DVolumeTexture8_LockBox(dst, 0, &locked_box, NULL, 0);
6285 ok(SUCCEEDED(hr), "Failed to lock volume texture, hr %#x.\n", hr);
6286 ok(content == 0x11223344, "Dest texture contained %#x, expected 0x11223344.\n", content);
6287 hr = IDirect3DVolumeTexture8_UnlockBox(dst, 0);
6288 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6290 IDirect3DVolumeTexture8_Release(src);
6291 IDirect3DVolumeTexture8_Release(dst);
6294 if (!(caps.TextureCaps & D3DPTEXTURECAPS_MIPVOLUMEMAP))
6296 skip("Mipmapped volume maps not supported.\n");
6297 goto out;
6300 for (i = 0; i < sizeof(tests2) / sizeof(*tests2); i++)
6302 hr = IDirect3DDevice8_CreateVolumeTexture(device,
6303 tests2[i].src_size, tests2[i].src_size, tests2[i].src_size,
6304 tests2[i].src_lvl, 0, tests2[i].src_fmt, D3DPOOL_SYSTEMMEM, &src);
6305 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x, case %u.\n", hr, i);
6306 hr = IDirect3DDevice8_CreateVolumeTexture(device,
6307 tests2[i].dst_size, tests2[i].dst_size, tests2[i].dst_size,
6308 tests2[i].dst_lvl, 0, tests2[i].dst_fmt, D3DPOOL_DEFAULT, &dst);
6309 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x, case %u.\n", hr, i);
6311 hr = IDirect3DDevice8_UpdateTexture(device, (IDirect3DBaseTexture8 *)src, (IDirect3DBaseTexture8 *)dst);
6312 todo_wine_if (FAILED(hr))
6313 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x, case %u.\n", hr, i);
6315 IDirect3DVolumeTexture8_Release(src);
6316 IDirect3DVolumeTexture8_Release(dst);
6319 /* As far as I can see, UpdateTexture on non-matching texture behaves like a memcpy. The raw data
6320 * stays the same in a format change, a 2x2x1 texture is copied into the first row of a 4x4x1 texture,
6321 * etc. I could not get it to segfault, but the nonexistent 5th pixel of a 2x2x1 texture is copied into
6322 * pixel 1x2x1 of a 4x4x1 texture, demonstrating a read beyond the texture's end. I suspect any bad
6323 * memory access is silently ignored by the runtime, in the kernel or on the GPU.
6325 * I'm not adding tests for this behavior until an application needs it. */
6327 out:
6328 refcount = IDirect3DDevice8_Release(device);
6329 ok(!refcount, "Device has %u references left.\n", refcount);
6330 IDirect3D8_Release(d3d8);
6331 DestroyWindow(window);
6334 static void test_create_rt_ds_fail(void)
6336 IDirect3DDevice8 *device;
6337 HWND window;
6338 HRESULT hr;
6339 ULONG refcount;
6340 IDirect3D8 *d3d8;
6341 IDirect3DSurface8 *surface;
6343 window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW,
6344 0, 0, 640, 480, 0, 0, 0, 0);
6345 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
6346 ok(!!d3d8, "Failed to create a D3D object.\n");
6347 if (!(device = create_device(d3d8, window, NULL)))
6349 skip("Failed to create a D3D device, skipping tests.\n");
6350 IDirect3D8_Release(d3d8);
6351 DestroyWindow(window);
6352 return;
6355 /* Output pointer == NULL segfaults on Windows. */
6357 surface = (IDirect3DSurface8 *)0xdeadbeef;
6358 hr = IDirect3DDevice8_CreateRenderTarget(device, 4, 4, D3DFMT_D16,
6359 D3DMULTISAMPLE_NONE, FALSE, &surface);
6360 ok(hr == D3DERR_INVALIDCALL, "Creating a D16 render target returned hr %#x.\n", hr);
6361 ok(surface == NULL, "Got pointer %p, expected NULL.\n", surface);
6362 if (SUCCEEDED(hr))
6363 IDirect3DSurface8_Release(surface);
6365 surface = (IDirect3DSurface8 *)0xdeadbeef;
6366 hr = IDirect3DDevice8_CreateDepthStencilSurface(device, 4, 4, D3DFMT_A8R8G8B8,
6367 D3DMULTISAMPLE_NONE, &surface);
6368 ok(hr == D3DERR_INVALIDCALL, "Creating a A8R8G8B8 depth stencil returned hr %#x.\n", hr);
6369 ok(surface == NULL, "Got pointer %p, expected NULL.\n", surface);
6370 if (SUCCEEDED(hr))
6371 IDirect3DSurface8_Release(surface);
6373 refcount = IDirect3DDevice8_Release(device);
6374 ok(!refcount, "Device has %u references left.\n", refcount);
6375 IDirect3D8_Release(d3d8);
6376 DestroyWindow(window);
6379 static void test_volume_blocks(void)
6381 IDirect3DDevice8 *device;
6382 IDirect3D8 *d3d8;
6383 UINT refcount;
6384 HWND window;
6385 HRESULT hr;
6386 D3DCAPS8 caps;
6387 IDirect3DVolumeTexture8 *texture;
6388 unsigned int w, h, d, i, j;
6389 static const struct
6391 D3DFORMAT fmt;
6392 const char *name;
6393 unsigned int block_width;
6394 unsigned int block_height;
6395 unsigned int block_depth;
6396 unsigned int block_size;
6397 unsigned int broken;
6398 BOOL create_size_checked, core_fmt;
6400 formats[] =
6402 /* Scratch volumes enforce DXTn block locks, unlike their surface counterparts.
6403 * ATI2N and YUV blocks are not enforced on any tested card (r200, gtx 460). */
6404 {D3DFMT_DXT1, "D3DFMT_DXT1", 4, 4, 1, 8, 0, TRUE, TRUE },
6405 {D3DFMT_DXT2, "D3DFMT_DXT2", 4, 4, 1, 16, 0, TRUE, TRUE },
6406 {D3DFMT_DXT3, "D3DFMT_DXT3", 4, 4, 1, 16, 0, TRUE, TRUE },
6407 {D3DFMT_DXT4, "D3DFMT_DXT4", 4, 4, 1, 16, 0, TRUE, TRUE },
6408 {D3DFMT_DXT5, "D3DFMT_DXT5", 4, 4, 1, 16, 0, TRUE, TRUE },
6409 {D3DFMT_DXT5, "D3DFMT_DXT5", 4, 4, 1, 16, 0, TRUE, TRUE },
6410 /* ATI2N has 2x2 blocks on all AMD cards and Geforce 7 cards,
6411 * which doesn't match the format spec. On newer Nvidia cards
6412 * it has the correct 4x4 block size.
6413 * ATI1N volume textures are only supported by AMD GPUs right
6414 * now and locking offsets seem just wrong. */
6415 {MAKEFOURCC('A','T','I','1'), "ATI1N", 4, 4, 1, 8, 2, FALSE, FALSE},
6416 {MAKEFOURCC('A','T','I','2'), "ATI2N", 4, 4, 1, 16, 1, FALSE, FALSE},
6417 {D3DFMT_YUY2, "D3DFMT_YUY2", 2, 1, 1, 4, 1, FALSE, TRUE },
6418 {D3DFMT_UYVY, "D3DFMT_UYVY", 2, 1, 1, 4, 1, FALSE, TRUE },
6420 static const struct
6422 D3DPOOL pool;
6423 const char *name;
6424 BOOL need_driver_support, need_runtime_support;
6426 create_tests[] =
6428 {D3DPOOL_DEFAULT, "D3DPOOL_DEFAULT", TRUE, FALSE},
6429 {D3DPOOL_SCRATCH, "D3DPOOL_SCRATCH", FALSE, TRUE },
6430 {D3DPOOL_SYSTEMMEM, "D3DPOOL_SYSTEMMEM",TRUE, FALSE},
6431 {D3DPOOL_MANAGED, "D3DPOOL_MANAGED", TRUE, FALSE},
6433 static const struct
6435 unsigned int x, y, z, x2, y2, z2;
6437 offset_tests[] =
6439 {0, 0, 0, 8, 8, 8},
6440 {0, 0, 3, 8, 8, 8},
6441 {0, 4, 0, 8, 8, 8},
6442 {0, 4, 3, 8, 8, 8},
6443 {4, 0, 0, 8, 8, 8},
6444 {4, 0, 3, 8, 8, 8},
6445 {4, 4, 0, 8, 8, 8},
6446 {4, 4, 3, 8, 8, 8},
6448 D3DBOX box;
6449 D3DLOCKED_BOX locked_box;
6450 BYTE *base;
6451 INT expected_row_pitch, expected_slice_pitch;
6452 BOOL support;
6453 BOOL pow2;
6454 unsigned int offset, expected_offset;
6456 window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW,
6457 0, 0, 640, 480, 0, 0, 0, 0);
6458 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
6459 ok(!!d3d8, "Failed to create a D3D object.\n");
6460 if (!(device = create_device(d3d8, window, NULL)))
6462 skip("Failed to create a D3D device, skipping tests.\n");
6463 IDirect3D8_Release(d3d8);
6464 DestroyWindow(window);
6465 return;
6467 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
6468 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
6469 pow2 = !!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP_POW2);
6471 for (i = 0; i < sizeof(formats) / sizeof(*formats); i++)
6473 hr = IDirect3D8_CheckDeviceFormat(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
6474 0, D3DRTYPE_VOLUMETEXTURE, formats[i].fmt);
6475 support = SUCCEEDED(hr);
6477 /* Test creation restrictions */
6478 for (w = 1; w <= 8; w++)
6480 for (h = 1; h <= 8; h++)
6482 for (d = 1; d <= 8; d++)
6484 HRESULT expect_hr;
6485 BOOL size_is_pow2;
6486 BOOL block_aligned = TRUE;
6488 if (w & (formats[i].block_width - 1) || h & (formats[i].block_height - 1))
6489 block_aligned = FALSE;
6491 size_is_pow2 = !((w & (w - 1)) || (h & (h - 1)) || (d & (d - 1)));
6493 for (j = 0; j < sizeof(create_tests) / sizeof(*create_tests); j++)
6495 BOOL may_succeed = FALSE;
6497 if (create_tests[j].need_runtime_support && !formats[i].core_fmt && !support)
6498 expect_hr = D3DERR_INVALIDCALL;
6499 else if (formats[i].create_size_checked && !block_aligned)
6500 expect_hr = D3DERR_INVALIDCALL;
6501 else if (pow2 && !size_is_pow2 && create_tests[j].need_driver_support)
6502 expect_hr = D3DERR_INVALIDCALL;
6503 else if (create_tests[j].need_driver_support && !support)
6504 expect_hr = D3DERR_INVALIDCALL;
6505 else
6506 expect_hr = D3D_OK;
6508 texture = (IDirect3DVolumeTexture8 *)0xdeadbeef;
6509 hr = IDirect3DDevice8_CreateVolumeTexture(device, w, h, d, 1, 0,
6510 formats[i].fmt, create_tests[j].pool, &texture);
6512 /* Wine knows about ATI2N and happily creates a scratch resource even if GL
6513 * does not support it. Accept scratch creation of extension formats on
6514 * Windows as well if it occurs. We don't really care if e.g. a Windows 7
6515 * on an r200 GPU creates scratch ATI2N texture even though the card doesn't
6516 * support it. */
6517 if (!formats[i].core_fmt && !support && FAILED(expect_hr))
6518 may_succeed = TRUE;
6520 ok(hr == expect_hr || ((SUCCEEDED(hr) && may_succeed)),
6521 "Got unexpected hr %#x for format %s, pool %s, size %ux%ux%u.\n",
6522 hr, formats[i].name, create_tests[j].name, w, h, d);
6524 if (FAILED(hr))
6525 ok(texture == NULL, "Got texture ptr %p, expected NULL.\n", texture);
6526 else
6527 IDirect3DVolumeTexture8_Release(texture);
6533 if (!support && !formats[i].core_fmt)
6534 continue;
6536 hr = IDirect3DDevice8_CreateVolumeTexture(device, 24, 8, 8, 1, 0,
6537 formats[i].fmt, D3DPOOL_SCRATCH, &texture);
6538 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x.\n", hr);
6540 /* Test lockrect offset */
6541 for (j = 0; j < sizeof(offset_tests) / sizeof(*offset_tests); j++)
6543 unsigned int bytes_per_pixel;
6544 bytes_per_pixel = formats[i].block_size / (formats[i].block_width * formats[i].block_height);
6546 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, NULL, 0);
6547 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6549 base = locked_box.pBits;
6550 if (formats[i].broken == 1)
6552 expected_row_pitch = bytes_per_pixel * 24;
6554 else if (formats[i].broken == 2)
6556 expected_row_pitch = 24;
6558 else
6560 expected_row_pitch = (24 /* tex width */ + formats[i].block_height - 1) / formats[i].block_width
6561 * formats[i].block_size;
6563 ok(locked_box.RowPitch == expected_row_pitch, "Got unexpected row pitch %d for format %s, expected %d.\n",
6564 locked_box.RowPitch, formats[i].name, expected_row_pitch);
6566 if (formats[i].broken)
6568 expected_slice_pitch = expected_row_pitch * 8;
6570 else
6572 expected_slice_pitch = (8 /* tex height */ + formats[i].block_depth - 1) / formats[i].block_height
6573 * expected_row_pitch;
6575 ok(locked_box.SlicePitch == expected_slice_pitch,
6576 "Got unexpected slice pitch %d for format %s, expected %d.\n",
6577 locked_box.SlicePitch, formats[i].name, expected_slice_pitch);
6579 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6580 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x, j %u.\n", hr, j);
6582 box.Left = offset_tests[j].x;
6583 box.Top = offset_tests[j].y;
6584 box.Front = offset_tests[j].z;
6585 box.Right = offset_tests[j].x2;
6586 box.Bottom = offset_tests[j].y2;
6587 box.Back = offset_tests[j].z2;
6588 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, &box, 0);
6589 ok(SUCCEEDED(hr), "Failed to lock volume texture, hr %#x, j %u.\n", hr, j);
6591 offset = (BYTE *)locked_box.pBits - base;
6592 if (formats[i].broken == 1)
6594 expected_offset = box.Front * expected_slice_pitch
6595 + box.Top * expected_row_pitch
6596 + box.Left * bytes_per_pixel;
6598 else if (formats[i].broken == 2)
6600 expected_offset = box.Front * expected_slice_pitch
6601 + box.Top * expected_row_pitch
6602 + box.Left;
6604 else
6606 expected_offset = (box.Front / formats[i].block_depth) * expected_slice_pitch
6607 + (box.Top / formats[i].block_height) * expected_row_pitch
6608 + (box.Left / formats[i].block_width) * formats[i].block_size;
6610 ok(offset == expected_offset, "Got unexpected offset %u for format %s, expected %u, box start %ux%ux%u.\n",
6611 offset, formats[i].name, expected_offset, box.Left, box.Top, box.Front);
6613 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6614 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6617 /* Test partial block locks */
6618 box.Front = 0;
6619 box.Back = 1;
6620 if (formats[i].block_width > 1)
6622 box.Left = formats[i].block_width >> 1;
6623 box.Top = 0;
6624 box.Right = formats[i].block_width;
6625 box.Bottom = formats[i].block_height;
6626 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, &box, 0);
6627 ok(FAILED(hr) || broken(formats[i].broken),
6628 "Partial block lock succeeded, expected failure, format %s.\n",
6629 formats[i].name);
6630 if (SUCCEEDED(hr))
6632 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6633 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6636 box.Left = 0;
6637 box.Top = 0;
6638 box.Right = formats[i].block_width >> 1;
6639 box.Bottom = formats[i].block_height;
6640 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, &box, 0);
6641 ok(FAILED(hr) || broken(formats[i].broken),
6642 "Partial block lock succeeded, expected failure, format %s.\n",
6643 formats[i].name);
6644 if (SUCCEEDED(hr))
6646 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6647 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6651 if (formats[i].block_height > 1)
6653 box.Left = 0;
6654 box.Top = formats[i].block_height >> 1;
6655 box.Right = formats[i].block_width;
6656 box.Bottom = formats[i].block_height;
6657 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, &box, 0);
6658 ok(FAILED(hr) || broken(formats[i].broken),
6659 "Partial block lock succeeded, expected failure, format %s.\n",
6660 formats[i].name);
6661 if (SUCCEEDED(hr))
6663 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6664 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6667 box.Left = 0;
6668 box.Top = 0;
6669 box.Right = formats[i].block_width;
6670 box.Bottom = formats[i].block_height >> 1;
6671 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, &box, 0);
6672 ok(FAILED(hr) || broken(formats[i].broken),
6673 "Partial block lock succeeded, expected failure, format %s.\n",
6674 formats[i].name);
6675 if (SUCCEEDED(hr))
6677 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6678 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6682 /* Test full block lock */
6683 box.Left = 0;
6684 box.Top = 0;
6685 box.Right = formats[i].block_width;
6686 box.Bottom = formats[i].block_height;
6687 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, &box, 0);
6688 ok(SUCCEEDED(hr), "Failed to lock volume texture, hr %#x.\n", hr);
6689 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6690 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6692 IDirect3DVolumeTexture8_Release(texture);
6694 /* Test mipmap locks. Don't do this with ATI2N, AMD warns that the runtime
6695 * does not allocate surfaces smaller than the blocksize properly. */
6696 if ((formats[i].block_width > 1 || formats[i].block_height > 1) && formats[i].core_fmt)
6698 hr = IDirect3DDevice8_CreateVolumeTexture(device, formats[i].block_width, formats[i].block_height,
6699 2, 2, 0, formats[i].fmt, D3DPOOL_SCRATCH, &texture);
6701 ok(SUCCEEDED(hr), "CreateVolumeTexture failed, hr %#x.\n", hr);
6702 hr = IDirect3DVolumeTexture8_LockBox(texture, 1, &locked_box, NULL, 0);
6703 ok(SUCCEEDED(hr), "Failed to lock volume texture mipmap, hr %#x.\n", hr);
6704 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 1);
6705 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6707 box.Left = box.Top = box.Front = 0;
6708 box.Right = formats[i].block_width == 1 ? 1 : formats[i].block_width >> 1;
6709 box.Bottom = formats[i].block_height == 1 ? 1 : formats[i].block_height >> 1;
6710 box.Back = 1;
6711 hr = IDirect3DVolumeTexture8_LockBox(texture, 1, &locked_box, &box, 0);
6712 ok(SUCCEEDED(hr), "Failed to lock volume texture mipmap, hr %#x.\n", hr);
6713 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 1);
6714 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6716 box.Right = formats[i].block_width;
6717 box.Bottom = formats[i].block_height;
6718 hr = IDirect3DVolumeTexture8_LockBox(texture, 1, &locked_box, &box, 0);
6719 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
6720 if (SUCCEEDED(hr))
6721 IDirect3DVolumeTexture8_UnlockBox(texture, 1);
6723 IDirect3DVolumeTexture8_Release(texture);
6727 refcount = IDirect3DDevice8_Release(device);
6728 ok(!refcount, "Device has %u references left.\n", refcount);
6729 IDirect3D8_Release(d3d8);
6730 DestroyWindow(window);
6733 static void test_lockbox_invalid(void)
6735 static const struct
6737 D3DBOX box;
6738 HRESULT result;
6740 test_data[] =
6742 {{0, 0, 2, 2, 0, 1}, D3D_OK}, /* Valid */
6743 {{0, 0, 4, 4, 0, 1}, D3D_OK}, /* Valid */
6744 {{0, 0, 0, 4, 0, 1}, D3DERR_INVALIDCALL}, /* 0 height */
6745 {{0, 0, 4, 0, 0, 1}, D3DERR_INVALIDCALL}, /* 0 width */
6746 {{0, 0, 4, 4, 1, 1}, D3DERR_INVALIDCALL}, /* 0 depth */
6747 {{4, 0, 0, 4, 0, 1}, D3DERR_INVALIDCALL}, /* left > right */
6748 {{0, 4, 4, 0, 0, 1}, D3DERR_INVALIDCALL}, /* top > bottom */
6749 {{0, 0, 4, 4, 1, 0}, D3DERR_INVALIDCALL}, /* back > front */
6750 {{0, 0, 8, 4, 0, 1}, D3DERR_INVALIDCALL}, /* right > surface */
6751 {{0, 0, 4, 8, 0, 1}, D3DERR_INVALIDCALL}, /* bottom > surface */
6752 {{0, 0, 4, 4, 0, 3}, D3DERR_INVALIDCALL}, /* back > surface */
6753 {{8, 0, 16, 4, 0, 1}, D3DERR_INVALIDCALL}, /* left > surface */
6754 {{0, 8, 4, 16, 0, 1}, D3DERR_INVALIDCALL}, /* top > surface */
6755 {{0, 0, 4, 4, 2, 4}, D3DERR_INVALIDCALL}, /* top > surface */
6757 static const D3DBOX test_boxt_2 = {2, 2, 4, 4, 0, 1};
6758 IDirect3DVolumeTexture8 *texture = NULL;
6759 D3DLOCKED_BOX locked_box;
6760 IDirect3DDevice8 *device;
6761 IDirect3D8 *d3d;
6762 unsigned int i;
6763 ULONG refcount;
6764 HWND window;
6765 BYTE *base;
6766 HRESULT hr;
6768 window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
6769 0, 0, 640, 480, 0, 0, 0, 0);
6770 d3d = Direct3DCreate8(D3D_SDK_VERSION);
6771 ok(!!d3d, "Failed to create a D3D object.\n");
6772 if (!(device = create_device(d3d, window, NULL)))
6774 skip("Failed to create a D3D device, skipping tests.\n");
6775 IDirect3D8_Release(d3d);
6776 DestroyWindow(window);
6777 return;
6780 hr = IDirect3DDevice8_CreateVolumeTexture(device, 4, 4, 2, 1, 0,
6781 D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &texture);
6782 ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x.\n", hr);
6783 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, NULL, 0);
6784 ok(SUCCEEDED(hr), "Failed to lock volume texture, hr %#x.\n", hr);
6785 base = locked_box.pBits;
6786 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6787 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6789 for (i = 0; i < (sizeof(test_data) / sizeof(*test_data)); ++i)
6791 unsigned int offset, expected_offset;
6792 const D3DBOX *box = &test_data[i].box;
6794 locked_box.pBits = (BYTE *)0xdeadbeef;
6795 locked_box.RowPitch = 0xdeadbeef;
6796 locked_box.SlicePitch = 0xdeadbeef;
6798 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, box, 0);
6799 /* Unlike surfaces, volumes properly check the box even in Windows XP */
6800 ok(hr == test_data[i].result,
6801 "Got unexpected hr %#x with box [%u, %u, %u]->[%u, %u, %u], expected %#x.\n",
6802 hr, box->Left, box->Top, box->Front, box->Right, box->Bottom, box->Back,
6803 test_data[i].result);
6804 if (FAILED(hr))
6805 continue;
6807 offset = (BYTE *)locked_box.pBits - base;
6808 expected_offset = box->Front * locked_box.SlicePitch + box->Top * locked_box.RowPitch + box->Left * 4;
6809 ok(offset == expected_offset,
6810 "Got unexpected offset %u (expected %u) for rect [%u, %u, %u]->[%u, %u, %u].\n",
6811 offset, expected_offset, box->Left, box->Top, box->Front, box->Right, box->Bottom, box->Back);
6813 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6814 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6817 /* locked_box = NULL throws an exception on Windows */
6818 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, NULL, 0);
6819 ok(SUCCEEDED(hr), "Failed to lock volume texture, hr %#x.\n", hr);
6820 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, NULL, 0);
6821 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
6822 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6823 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6824 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6825 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
6827 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, &test_data[0].box, 0);
6828 ok(hr == D3D_OK, "Got unexpected hr %#x for rect [%u, %u, %u]->[%u, %u, %u].\n",
6829 hr, test_data[0].box.Left, test_data[0].box.Top, test_data[0].box.Front,
6830 test_data[0].box.Right, test_data[0].box.Bottom, test_data[0].box.Back);
6831 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, &test_data[0].box, 0);
6832 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for rect [%u, %u, %u]->[%u, %u, %u].\n",
6833 hr, test_data[0].box.Left, test_data[0].box.Top, test_data[0].box.Front,
6834 test_data[0].box.Right, test_data[0].box.Bottom, test_data[0].box.Back);
6835 hr = IDirect3DVolumeTexture8_LockBox(texture, 0, &locked_box, &test_boxt_2, 0);
6836 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x for rect [%u, %u, %u]->[%u, %u, %u].\n",
6837 hr, test_boxt_2.Left, test_boxt_2.Top, test_boxt_2.Front,
6838 test_boxt_2.Right, test_boxt_2.Bottom, test_boxt_2.Back);
6839 hr = IDirect3DVolumeTexture8_UnlockBox(texture, 0);
6840 ok(SUCCEEDED(hr), "Failed to unlock volume texture, hr %#x.\n", hr);
6842 IDirect3DVolumeTexture8_Release(texture);
6843 refcount = IDirect3DDevice8_Release(device);
6844 ok(!refcount, "Device has %u references left.\n", refcount);
6845 IDirect3D8_Release(d3d);
6846 DestroyWindow(window);
6849 static void test_pixel_format(void)
6851 HWND hwnd, hwnd2 = NULL;
6852 HDC hdc, hdc2 = NULL;
6853 HMODULE gl = NULL;
6854 int format, test_format;
6855 PIXELFORMATDESCRIPTOR pfd;
6856 IDirect3D8 *d3d8 = NULL;
6857 IDirect3DDevice8 *device = NULL;
6858 HRESULT hr;
6859 static const float point[3] = {0.0, 0.0, 0.0};
6861 hwnd = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
6862 100, 100, 160, 160, NULL, NULL, NULL, NULL);
6863 if (!hwnd)
6865 skip("Failed to create window\n");
6866 return;
6869 hwnd2 = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW,
6870 100, 100, 160, 160, NULL, NULL, NULL, NULL);
6872 hdc = GetDC(hwnd);
6873 if (!hdc)
6875 skip("Failed to get DC\n");
6876 goto cleanup;
6879 if (hwnd2)
6880 hdc2 = GetDC(hwnd2);
6882 gl = LoadLibraryA("opengl32.dll");
6883 ok(!!gl, "failed to load opengl32.dll; SetPixelFormat()/GetPixelFormat() may not work right\n");
6885 format = GetPixelFormat(hdc);
6886 ok(format == 0, "new window has pixel format %d\n", format);
6888 ZeroMemory(&pfd, sizeof(pfd));
6889 pfd.nSize = sizeof(pfd);
6890 pfd.nVersion = 1;
6891 pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
6892 pfd.iPixelType = PFD_TYPE_RGBA;
6893 pfd.iLayerType = PFD_MAIN_PLANE;
6894 format = ChoosePixelFormat(hdc, &pfd);
6895 if (format <= 0)
6897 skip("no pixel format available\n");
6898 goto cleanup;
6901 if (!SetPixelFormat(hdc, format, &pfd) || GetPixelFormat(hdc) != format)
6903 skip("failed to set pixel format\n");
6904 goto cleanup;
6907 if (!hdc2 || !SetPixelFormat(hdc2, format, &pfd) || GetPixelFormat(hdc2) != format)
6909 skip("failed to set pixel format on second window\n");
6910 if (hdc2)
6912 ReleaseDC(hwnd2, hdc2);
6913 hdc2 = NULL;
6917 d3d8 = Direct3DCreate8(D3D_SDK_VERSION);
6918 ok(!!d3d8, "Failed to create a D3D object.\n");
6920 test_format = GetPixelFormat(hdc);
6921 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6923 if (!(device = create_device(d3d8, hwnd, NULL)))
6925 skip("Failed to create device\n");
6926 goto cleanup;
6929 test_format = GetPixelFormat(hdc);
6930 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6932 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ);
6933 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
6935 test_format = GetPixelFormat(hdc);
6936 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6938 hr = IDirect3DDevice8_BeginScene(device);
6939 ok(SUCCEEDED(hr), "BeginScene failed %#x\n", hr);
6941 test_format = GetPixelFormat(hdc);
6942 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6944 hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_POINTLIST, 1, point, 3 * sizeof(float));
6945 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6947 test_format = GetPixelFormat(hdc);
6948 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6950 hr = IDirect3DDevice8_EndScene(device);
6951 ok(SUCCEEDED(hr), "EndScene failed %#x\n", hr);
6953 test_format = GetPixelFormat(hdc);
6954 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6956 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
6957 ok(SUCCEEDED(hr), "Present failed %#x\n", hr);
6959 test_format = GetPixelFormat(hdc);
6960 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6962 if (hdc2)
6964 hr = IDirect3DDevice8_Present(device, NULL, NULL, hwnd2, NULL);
6965 ok(SUCCEEDED(hr), "Present failed %#x\n", hr);
6967 test_format = GetPixelFormat(hdc);
6968 ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format);
6970 test_format = GetPixelFormat(hdc2);
6971 ok(test_format == format, "second window has pixel format %d, expected %d\n", test_format, format);
6974 cleanup:
6975 if (device)
6977 UINT refcount = IDirect3DDevice8_Release(device);
6978 ok(!refcount, "Device has %u references left.\n", refcount);
6980 if (d3d8) IDirect3D8_Release(d3d8);
6981 if (gl) FreeLibrary(gl);
6982 if (hdc) ReleaseDC(hwnd, hdc);
6983 if (hdc2) ReleaseDC(hwnd2, hdc2);
6984 if (hwnd) DestroyWindow(hwnd);
6985 if (hwnd2) DestroyWindow(hwnd2);
6988 static void test_begin_end_state_block(void)
6990 IDirect3DDevice8 *device;
6991 DWORD stateblock;
6992 IDirect3D8 *d3d;
6993 ULONG refcount;
6994 HWND window;
6995 HRESULT hr;
6997 window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW,
6998 0, 0, 640, 480, NULL, NULL, NULL, NULL);
6999 d3d = Direct3DCreate8(D3D_SDK_VERSION);
7000 ok(!!d3d, "Failed to create a D3D object.\n");
7001 if (!(device = create_device(d3d, window, NULL)))
7003 skip("Failed to create a D3D device, skipping tests.\n");
7004 IDirect3D8_Release(d3d);
7005 DestroyWindow(window);
7006 return;
7009 /* Should succeed. */
7010 hr = IDirect3DDevice8_BeginStateBlock(device);
7011 ok(SUCCEEDED(hr), "Failed to begin stateblock, hr %#x.\n", hr);
7013 /* Calling BeginStateBlock() while recording should return
7014 * D3DERR_INVALIDCALL. */
7015 hr = IDirect3DDevice8_BeginStateBlock(device);
7016 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
7018 /* Should succeed. */
7019 stateblock = 0xdeadbeef;
7020 hr = IDirect3DDevice8_EndStateBlock(device, &stateblock);
7021 ok(SUCCEEDED(hr), "Failed to end stateblock, hr %#x.\n", hr);
7022 ok(!!stateblock && stateblock != 0xdeadbeef, "Got unexpected stateblock %#x.\n", stateblock);
7023 IDirect3DDevice8_DeleteStateBlock(device, stateblock);
7025 /* Calling EndStateBlock() while not recording should return
7026 * D3DERR_INVALIDCALL. stateblock should not be touched. */
7027 stateblock = 0xdeadbeef;
7028 hr = IDirect3DDevice8_EndStateBlock(device, &stateblock);
7029 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
7030 ok(stateblock == 0xdeadbeef, "Got unexpected stateblock %#x.\n", stateblock);
7032 refcount = IDirect3DDevice8_Release(device);
7033 ok(!refcount, "Device has %u references left.\n", refcount);
7034 IDirect3D8_Release(d3d);
7035 DestroyWindow(window);
7038 static void test_shader_constant_apply(void)
7040 static const float vs_const[] = {1.0f, 2.0f, 3.0f, 4.0f};
7041 static const float ps_const[] = {5.0f, 6.0f, 7.0f, 8.0f};
7042 static const float initial[] = {0.0f, 0.0f, 0.0f, 0.0f};
7043 DWORD vs_version, ps_version;
7044 IDirect3DDevice8 *device;
7045 DWORD stateblock;
7046 IDirect3D8 *d3d;
7047 ULONG refcount;
7048 D3DCAPS8 caps;
7049 float ret[4];
7050 HWND window;
7051 HRESULT hr;
7053 window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW,
7054 0, 0, 640, 480, NULL, NULL, NULL, NULL);
7055 d3d = Direct3DCreate8(D3D_SDK_VERSION);
7056 ok(!!d3d, "Failed to create a D3D object.\n");
7057 if (!(device = create_device(d3d, window, NULL)))
7059 skip("Failed to create a D3D device, skipping tests.\n");
7060 IDirect3D8_Release(d3d);
7061 DestroyWindow(window);
7062 return;
7065 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
7066 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
7067 vs_version = caps.VertexShaderVersion & 0xffff;
7068 ps_version = caps.PixelShaderVersion & 0xffff;
7070 if (vs_version)
7072 hr = IDirect3DDevice8_SetVertexShaderConstant(device, 0, initial, 1);
7073 ok(SUCCEEDED(hr), "Failed to set vertex shader constant, hr %#x.\n", hr);
7074 hr = IDirect3DDevice8_SetVertexShaderConstant(device, 1, initial, 1);
7075 ok(SUCCEEDED(hr), "Failed to set vertex shader constant, hr %#x.\n", hr);
7077 hr = IDirect3DDevice8_GetVertexShaderConstant(device, 0, ret, 1);
7078 ok(SUCCEEDED(hr), "Failed to get vertex shader constant, hr %#x.\n", hr);
7079 ok(!memcmp(ret, initial, sizeof(initial)),
7080 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7081 ret[0], ret[1], ret[2], ret[3], initial[0], initial[1], initial[2], initial[3]);
7082 hr = IDirect3DDevice8_GetVertexShaderConstant(device, 1, ret, 1);
7083 ok(SUCCEEDED(hr), "Failed to get vertex shader constant, hr %#x.\n", hr);
7084 ok(!memcmp(ret, initial, sizeof(initial)),
7085 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7086 ret[0], ret[1], ret[2], ret[3], initial[0], initial[1], initial[2], initial[3]);
7088 hr = IDirect3DDevice8_SetVertexShaderConstant(device, 0, vs_const, 1);
7089 ok(SUCCEEDED(hr), "Failed to set vertex shader constant, hr %#x.\n", hr);
7091 if (ps_version)
7093 hr = IDirect3DDevice8_SetPixelShaderConstant(device, 0, initial, 1);
7094 ok(SUCCEEDED(hr), "Failed to set pixel shader constant, hr %#x.\n", hr);
7095 hr = IDirect3DDevice8_SetPixelShaderConstant(device, 1, initial, 1);
7096 ok(SUCCEEDED(hr), "Failed to set pixel shader constant, hr %#x.\n", hr);
7098 hr = IDirect3DDevice8_GetPixelShaderConstant(device, 0, ret, 1);
7099 ok(SUCCEEDED(hr), "Failed to get pixel shader constant, hr %#x.\n", hr);
7100 ok(!memcmp(ret, initial, sizeof(initial)),
7101 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7102 ret[0], ret[1], ret[2], ret[3], initial[0], initial[1], initial[2], initial[3]);
7103 hr = IDirect3DDevice8_GetPixelShaderConstant(device, 1, ret, 1);
7104 ok(SUCCEEDED(hr), "Failed to get pixel shader constant, hr %#x.\n", hr);
7105 ok(!memcmp(ret, initial, sizeof(initial)),
7106 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7107 ret[0], ret[1], ret[2], ret[3], initial[0], initial[1], initial[2], initial[3]);
7109 hr = IDirect3DDevice8_SetPixelShaderConstant(device, 0, ps_const, 1);
7110 ok(SUCCEEDED(hr), "Failed to set pixel shader constant, hr %#x.\n", hr);
7113 hr = IDirect3DDevice8_BeginStateBlock(device);
7114 ok(SUCCEEDED(hr), "Failed to begin stateblock, hr %#x.\n", hr);
7116 if (vs_version)
7118 hr = IDirect3DDevice8_SetVertexShaderConstant(device, 1, vs_const, 1);
7119 ok(SUCCEEDED(hr), "Failed to set vertex shader constant, hr %#x.\n", hr);
7121 if (ps_version)
7123 hr = IDirect3DDevice8_SetPixelShaderConstant(device, 1, ps_const, 1);
7124 ok(SUCCEEDED(hr), "Failed to set pixel shader constant, hr %#x.\n", hr);
7127 hr = IDirect3DDevice8_EndStateBlock(device, &stateblock);
7128 ok(SUCCEEDED(hr), "Failed to end stateblock, hr %#x.\n", hr);
7130 if (vs_version)
7132 hr = IDirect3DDevice8_GetVertexShaderConstant(device, 0, ret, 1);
7133 ok(SUCCEEDED(hr), "Failed to get vertex shader constant, hr %#x.\n", hr);
7134 ok(!memcmp(ret, vs_const, sizeof(vs_const)),
7135 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7136 ret[0], ret[1], ret[2], ret[3], vs_const[0], vs_const[1], vs_const[2], vs_const[3]);
7137 hr = IDirect3DDevice8_GetVertexShaderConstant(device, 1, ret, 1);
7138 ok(SUCCEEDED(hr), "Failed to get vertex shader constant, hr %#x.\n", hr);
7139 ok(!memcmp(ret, initial, sizeof(initial)),
7140 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7141 ret[0], ret[1], ret[2], ret[3], initial[0], initial[1], initial[2], initial[3]);
7143 if (ps_version)
7145 hr = IDirect3DDevice8_GetPixelShaderConstant(device, 0, ret, 1);
7146 ok(SUCCEEDED(hr), "Failed to get pixel shader constant, hr %#x.\n", hr);
7147 ok(!memcmp(ret, ps_const, sizeof(ps_const)),
7148 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7149 ret[0], ret[1], ret[2], ret[3], ps_const[0], ps_const[1], ps_const[2], ps_const[3]);
7150 hr = IDirect3DDevice8_GetPixelShaderConstant(device, 1, ret, 1);
7151 ok(SUCCEEDED(hr), "Failed to get pixel shader constant, hr %#x.\n", hr);
7152 ok(!memcmp(ret, initial, sizeof(initial)),
7153 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7154 ret[0], ret[1], ret[2], ret[3], initial[0], initial[1], initial[2], initial[3]);
7157 /* Apply doesn't overwrite constants that aren't explicitly set on the
7158 * source stateblock. */
7159 hr = IDirect3DDevice8_ApplyStateBlock(device, stateblock);
7160 ok(SUCCEEDED(hr), "Failed to apply stateblock, hr %#x.\n", hr);
7162 if (vs_version)
7164 hr = IDirect3DDevice8_GetVertexShaderConstant(device, 0, ret, 1);
7165 ok(SUCCEEDED(hr), "Failed to get vertex shader constant, hr %#x.\n", hr);
7166 ok(!memcmp(ret, vs_const, sizeof(vs_const)),
7167 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7168 ret[0], ret[1], ret[2], ret[3], vs_const[0], vs_const[1], vs_const[2], vs_const[3]);
7169 hr = IDirect3DDevice8_GetVertexShaderConstant(device, 1, ret, 1);
7170 ok(SUCCEEDED(hr), "Failed to get vertex shader constant, hr %#x.\n", hr);
7171 ok(!memcmp(ret, vs_const, sizeof(vs_const)),
7172 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7173 ret[0], ret[1], ret[2], ret[3], vs_const[0], vs_const[1], vs_const[2], vs_const[3]);
7175 if (ps_version)
7177 hr = IDirect3DDevice8_GetPixelShaderConstant(device, 0, ret, 1);
7178 ok(SUCCEEDED(hr), "Failed to get pixel shader constant, hr %#x.\n", hr);
7179 ok(!memcmp(ret, ps_const, sizeof(ps_const)),
7180 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7181 ret[0], ret[1], ret[2], ret[3], ps_const[0], ps_const[1], ps_const[2], ps_const[3]);
7182 hr = IDirect3DDevice8_GetPixelShaderConstant(device, 1, ret, 1);
7183 ok(SUCCEEDED(hr), "Failed to get pixel shader constant, hr %#x.\n", hr);
7184 ok(!memcmp(ret, ps_const, sizeof(ps_const)),
7185 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7186 ret[0], ret[1], ret[2], ret[3], ps_const[0], ps_const[1], ps_const[2], ps_const[3]);
7189 IDirect3DDevice8_DeleteStateBlock(device, stateblock);
7190 refcount = IDirect3DDevice8_Release(device);
7191 ok(!refcount, "Device has %u references left.\n", refcount);
7192 IDirect3D8_Release(d3d);
7193 DestroyWindow(window);
7196 static void test_resource_type(void)
7198 IDirect3DDevice8 *device;
7199 IDirect3DSurface8 *surface;
7200 IDirect3DTexture8 *texture;
7201 IDirect3DCubeTexture8 *cube_texture;
7202 IDirect3DVolume8 *volume;
7203 IDirect3DVolumeTexture8 *volume_texture;
7204 D3DSURFACE_DESC surface_desc;
7205 D3DVOLUME_DESC volume_desc;
7206 D3DRESOURCETYPE type;
7207 IDirect3D8 *d3d;
7208 ULONG refcount;
7209 HWND window;
7210 HRESULT hr;
7211 D3DCAPS8 caps;
7213 window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW,
7214 0, 0, 640, 480, NULL, NULL, NULL, NULL);
7215 d3d = Direct3DCreate8(D3D_SDK_VERSION);
7216 ok(!!d3d, "Failed to create a D3D object.\n");
7217 if (!(device = create_device(d3d, window, NULL)))
7219 skip("Failed to create a D3D device, skipping tests.\n");
7220 IDirect3D8_Release(d3d);
7221 DestroyWindow(window);
7222 return;
7225 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
7226 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
7228 hr = IDirect3DDevice8_CreateImageSurface(device, 4, 4, D3DFMT_X8R8G8B8, &surface);
7229 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
7230 hr = IDirect3DSurface8_GetDesc(surface, &surface_desc);
7231 ok(SUCCEEDED(hr), "Failed to get surface description, hr %#x.\n", hr);
7232 ok(surface_desc.Type == D3DRTYPE_SURFACE, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7233 surface_desc.Type);
7234 IDirect3DSurface8_Release(surface);
7236 hr = IDirect3DDevice8_CreateTexture(device, 2, 8, 4, 0, D3DFMT_X8R8G8B8,
7237 D3DPOOL_SYSTEMMEM, &texture);
7238 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7239 type = IDirect3DTexture8_GetType(texture);
7240 ok(type == D3DRTYPE_TEXTURE, "Expected type D3DRTYPE_TEXTURE, got %u.\n", type);
7242 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 0, &surface);
7243 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
7244 hr = IDirect3DSurface8_GetDesc(surface, &surface_desc);
7245 ok(SUCCEEDED(hr), "Failed to get surface description, hr %#x.\n", hr);
7246 ok(surface_desc.Type == D3DRTYPE_SURFACE, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7247 surface_desc.Type);
7248 ok(surface_desc.Width == 2, "Expected width 2, got %u.\n", surface_desc.Width);
7249 ok(surface_desc.Height == 8, "Expected height 8, got %u.\n", surface_desc.Height);
7250 hr = IDirect3DTexture8_GetLevelDesc(texture, 0, &surface_desc);
7251 ok(SUCCEEDED(hr), "Failed to get level description, hr %#x.\n", hr);
7252 ok(surface_desc.Type == D3DRTYPE_SURFACE, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7253 surface_desc.Type);
7254 ok(surface_desc.Width == 2, "Expected width 2, got %u.\n", surface_desc.Width);
7255 ok(surface_desc.Height == 8, "Expected height 8, got %u.\n", surface_desc.Height);
7256 IDirect3DSurface8_Release(surface);
7258 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 2, &surface);
7259 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
7260 hr = IDirect3DSurface8_GetDesc(surface, &surface_desc);
7261 ok(SUCCEEDED(hr), "Failed to get surface description, hr %#x.\n", hr);
7262 ok(surface_desc.Type == D3DRTYPE_SURFACE, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7263 surface_desc.Type);
7264 ok(surface_desc.Width == 1, "Expected width 1, got %u.\n", surface_desc.Width);
7265 ok(surface_desc.Height == 2, "Expected height 2, got %u.\n", surface_desc.Height);
7266 hr = IDirect3DTexture8_GetLevelDesc(texture, 2, &surface_desc);
7267 ok(SUCCEEDED(hr), "Failed to get level description, hr %#x.\n", hr);
7268 ok(surface_desc.Type == D3DRTYPE_SURFACE, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7269 surface_desc.Type);
7270 ok(surface_desc.Width == 1, "Expected width 1, got %u.\n", surface_desc.Width);
7271 ok(surface_desc.Height == 2, "Expected height 2, got %u.\n", surface_desc.Height);
7272 IDirect3DSurface8_Release(surface);
7273 IDirect3DTexture8_Release(texture);
7275 if (caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP)
7277 hr = IDirect3DDevice8_CreateCubeTexture(device, 1, 1, 0, D3DFMT_X8R8G8B8,
7278 D3DPOOL_SYSTEMMEM, &cube_texture);
7279 ok(SUCCEEDED(hr), "Failed to create cube texture, hr %#x.\n", hr);
7280 type = IDirect3DCubeTexture8_GetType(cube_texture);
7281 ok(type == D3DRTYPE_CUBETEXTURE, "Expected type D3DRTYPE_CUBETEXTURE, got %u.\n", type);
7283 hr = IDirect3DCubeTexture8_GetCubeMapSurface(cube_texture,
7284 D3DCUBEMAP_FACE_NEGATIVE_X, 0, &surface);
7285 ok(SUCCEEDED(hr), "Failed to get cube map surface, hr %#x.\n", hr);
7286 hr = IDirect3DSurface8_GetDesc(surface, &surface_desc);
7287 ok(SUCCEEDED(hr), "Failed to get surface description, hr %#x.\n", hr);
7288 ok(surface_desc.Type == D3DRTYPE_SURFACE, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7289 surface_desc.Type);
7290 hr = IDirect3DCubeTexture8_GetLevelDesc(cube_texture, 0, &surface_desc);
7291 ok(SUCCEEDED(hr), "Failed to get level description, hr %#x.\n", hr);
7292 ok(surface_desc.Type == D3DRTYPE_SURFACE, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7293 surface_desc.Type);
7294 IDirect3DSurface8_Release(surface);
7295 IDirect3DCubeTexture8_Release(cube_texture);
7297 else
7298 skip("Cube maps not supported.\n");
7300 if (caps.TextureCaps & D3DPTEXTURECAPS_MIPVOLUMEMAP)
7302 hr = IDirect3DDevice8_CreateVolumeTexture(device, 2, 4, 8, 4, 0, D3DFMT_X8R8G8B8,
7303 D3DPOOL_SYSTEMMEM, &volume_texture);
7304 ok(SUCCEEDED(hr), "CreateVolumeTexture failed, hr %#x.\n", hr);
7305 type = IDirect3DVolumeTexture8_GetType(volume_texture);
7306 ok(type == D3DRTYPE_VOLUMETEXTURE, "Expected type D3DRTYPE_VOLUMETEXTURE, got %u.\n", type);
7308 hr = IDirect3DVolumeTexture8_GetVolumeLevel(volume_texture, 0, &volume);
7309 ok(SUCCEEDED(hr), "Failed to get volume level, hr %#x.\n", hr);
7310 /* IDirect3DVolume8 is not an IDirect3DResource8 and has no GetType method. */
7311 hr = IDirect3DVolume8_GetDesc(volume, &volume_desc);
7312 ok(SUCCEEDED(hr), "Failed to get volume description, hr %#x.\n", hr);
7313 ok(volume_desc.Type == D3DRTYPE_VOLUME, "Expected type D3DRTYPE_VOLUME, got %u.\n",
7314 volume_desc.Type);
7315 ok(volume_desc.Width == 2, "Expected width 2, got %u.\n", volume_desc.Width);
7316 ok(volume_desc.Height == 4, "Expected height 4, got %u.\n", volume_desc.Height);
7317 ok(volume_desc.Depth == 8, "Expected depth 8, got %u.\n", volume_desc.Depth);
7318 hr = IDirect3DVolumeTexture8_GetLevelDesc(volume_texture, 0, &volume_desc);
7319 ok(SUCCEEDED(hr), "Failed to get level description, hr %#x.\n", hr);
7320 ok(volume_desc.Type == D3DRTYPE_VOLUME, "Expected type D3DRTYPE_VOLUME, got %u.\n",
7321 volume_desc.Type);
7322 ok(volume_desc.Width == 2, "Expected width 2, got %u.\n", volume_desc.Width);
7323 ok(volume_desc.Height == 4, "Expected height 4, got %u.\n", volume_desc.Height);
7324 ok(volume_desc.Depth == 8, "Expected depth 8, got %u.\n", volume_desc.Depth);
7325 IDirect3DVolume8_Release(volume);
7327 hr = IDirect3DVolumeTexture8_GetVolumeLevel(volume_texture, 2, &volume);
7328 ok(SUCCEEDED(hr), "Failed to get volume level, hr %#x.\n", hr);
7329 hr = IDirect3DVolume8_GetDesc(volume, &volume_desc);
7330 ok(SUCCEEDED(hr), "Failed to get volume description, hr %#x.\n", hr);
7331 ok(volume_desc.Type == D3DRTYPE_VOLUME, "Expected type D3DRTYPE_VOLUME, got %u.\n",
7332 volume_desc.Type);
7333 ok(volume_desc.Width == 1, "Expected width 1, got %u.\n", volume_desc.Width);
7334 ok(volume_desc.Height == 1, "Expected height 1, got %u.\n", volume_desc.Height);
7335 ok(volume_desc.Depth == 2, "Expected depth 2, got %u.\n", volume_desc.Depth);
7336 hr = IDirect3DVolumeTexture8_GetLevelDesc(volume_texture, 2, &volume_desc);
7337 ok(SUCCEEDED(hr), "Failed to get level description, hr %#x.\n", hr);
7338 ok(volume_desc.Type == D3DRTYPE_VOLUME, "Expected type D3DRTYPE_VOLUME, got %u.\n",
7339 volume_desc.Type);
7340 ok(volume_desc.Width == 1, "Expected width 1, got %u.\n", volume_desc.Width);
7341 ok(volume_desc.Height == 1, "Expected height 1, got %u.\n", volume_desc.Height);
7342 ok(volume_desc.Depth == 2, "Expected depth 2, got %u.\n", volume_desc.Depth);
7343 IDirect3DVolume8_Release(volume);
7344 IDirect3DVolumeTexture8_Release(volume_texture);
7346 else
7347 skip("Mipmapped volume maps not supported.\n");
7349 refcount = IDirect3DDevice8_Release(device);
7350 ok(!refcount, "Device has %u references left.\n", refcount);
7351 IDirect3D8_Release(d3d);
7352 DestroyWindow(window);
7355 static void test_mipmap_lock(void)
7357 IDirect3DDevice8 *device;
7358 IDirect3DSurface8 *surface, *surface2, *surface_dst, *surface_dst2;
7359 IDirect3DTexture8 *texture, *texture_dst;
7360 IDirect3D8 *d3d;
7361 ULONG refcount;
7362 HWND window;
7363 HRESULT hr;
7364 D3DLOCKED_RECT locked_rect;
7366 window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW,
7367 0, 0, 640, 480, NULL, NULL, NULL, NULL);
7368 d3d = Direct3DCreate8(D3D_SDK_VERSION);
7369 ok(!!d3d, "Failed to create a D3D object.\n");
7370 if (!(device = create_device(d3d, window, NULL)))
7372 skip("Failed to create a D3D device, skipping tests.\n");
7373 IDirect3D8_Release(d3d);
7374 DestroyWindow(window);
7375 return;
7378 hr = IDirect3DDevice8_CreateTexture(device, 4, 4, 2, 0, D3DFMT_X8R8G8B8,
7379 D3DPOOL_DEFAULT, &texture_dst);
7380 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7381 hr = IDirect3DTexture8_GetSurfaceLevel(texture_dst, 0, &surface_dst);
7382 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
7383 hr = IDirect3DTexture8_GetSurfaceLevel(texture_dst, 1, &surface_dst2);
7384 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
7386 hr = IDirect3DDevice8_CreateTexture(device, 4, 4, 2, 0, D3DFMT_X8R8G8B8,
7387 D3DPOOL_SYSTEMMEM, &texture);
7388 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7389 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 0, &surface);
7390 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
7391 hr = IDirect3DTexture8_GetSurfaceLevel(texture, 1, &surface2);
7392 ok(SUCCEEDED(hr), "Failed to get surface level, hr %#x.\n", hr);
7394 hr = IDirect3DSurface8_LockRect(surface, &locked_rect, NULL, 0);
7395 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
7396 hr = IDirect3DSurface8_LockRect(surface2, &locked_rect, NULL, 0);
7397 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
7398 hr = IDirect3DSurface8_UnlockRect(surface);
7399 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
7401 hr = IDirect3DDevice8_CopyRects(device, surface, NULL, 0, surface_dst, NULL);
7402 ok(SUCCEEDED(hr), "Failed to update surface, hr %#x.\n", hr);
7403 hr = IDirect3DDevice8_CopyRects(device, surface2, NULL, 0, surface_dst2, NULL);
7404 todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
7406 /* Apparently there's no validation on the container. */
7407 hr = IDirect3DDevice8_UpdateTexture(device, (IDirect3DBaseTexture8 *)texture,
7408 (IDirect3DBaseTexture8 *)texture_dst);
7409 ok(SUCCEEDED(hr), "Failed to update texture, hr %#x.\n", hr);
7411 hr = IDirect3DSurface8_UnlockRect(surface2);
7412 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
7414 IDirect3DSurface8_Release(surface_dst2);
7415 IDirect3DSurface8_Release(surface_dst);
7416 IDirect3DSurface8_Release(surface2);
7417 IDirect3DSurface8_Release(surface);
7418 IDirect3DTexture8_Release(texture_dst);
7419 IDirect3DTexture8_Release(texture);
7421 refcount = IDirect3DDevice8_Release(device);
7422 ok(!refcount, "Device has %u references left.\n", refcount);
7423 IDirect3D8_Release(d3d);
7424 DestroyWindow(window);
7427 static void test_writeonly_resource(void)
7429 IDirect3D8 *d3d;
7430 IDirect3DDevice8 *device;
7431 IDirect3DVertexBuffer8 *buffer;
7432 ULONG refcount;
7433 HWND window;
7434 HRESULT hr;
7435 BYTE *ptr;
7436 static const struct
7438 struct vec3 pos;
7440 quad[] =
7442 {{-1.0f, -1.0f, 0.0f}},
7443 {{-1.0f, 1.0f, 0.0f}},
7444 {{ 1.0f, -1.0f, 0.0f}},
7445 {{ 1.0f, 1.0f, 0.0f}}
7448 window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW,
7449 0, 0, 640, 480, NULL, NULL, NULL, NULL);
7450 d3d = Direct3DCreate8(D3D_SDK_VERSION);
7451 ok(!!d3d, "Failed to create a D3D object.\n");
7452 if (!(device = create_device(d3d, window, NULL)))
7454 skip("Failed to create a D3D device, skipping tests.\n");
7455 IDirect3D8_Release(d3d);
7456 DestroyWindow(window);
7457 return;
7460 hr = IDirect3DDevice8_CreateVertexBuffer(device, sizeof(quad),
7461 D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &buffer);
7462 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
7464 hr = IDirect3DVertexBuffer8_Lock(buffer, 0, 0, &ptr, D3DLOCK_DISCARD);
7465 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
7466 memcpy(ptr, quad, sizeof(quad));
7467 hr = IDirect3DVertexBuffer8_Unlock(buffer);
7468 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
7469 hr = IDirect3DDevice8_SetStreamSource(device, 0, buffer, sizeof(*quad));
7470 ok(SUCCEEDED(hr), "Failed to set stream source, hr %#x.\n", hr);
7471 hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ);
7472 ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
7474 hr = IDirect3DDevice8_BeginScene(device);
7475 ok(SUCCEEDED(hr), "Failed to begin scene %#x\n", hr);
7476 hr = IDirect3DDevice8_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, 0, 2);
7477 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
7478 hr = IDirect3DDevice8_EndScene(device);
7479 ok(SUCCEEDED(hr), "Failed to end scene %#x\n", hr);
7481 hr = IDirect3DVertexBuffer8_Lock(buffer, 0, 0, &ptr, 0);
7482 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
7483 ok (!memcmp(ptr, quad, sizeof(quad)), "Got unexpected vertex buffer data.\n");
7484 hr = IDirect3DVertexBuffer8_Unlock(buffer);
7485 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
7487 hr = IDirect3DVertexBuffer8_Lock(buffer, 0, 0, &ptr, D3DLOCK_READONLY);
7488 ok(SUCCEEDED(hr), "Failed to lock vertex buffer, hr %#x.\n", hr);
7489 ok (!memcmp(ptr, quad, sizeof(quad)), "Got unexpected vertex buffer data.\n");
7490 hr = IDirect3DVertexBuffer8_Unlock(buffer);
7491 ok(SUCCEEDED(hr), "Failed to unlock vertex buffer, hr %#x.\n", hr);
7493 refcount = IDirect3DVertexBuffer8_Release(buffer);
7494 ok(!refcount, "Vertex buffer has %u references left.\n", refcount);
7495 refcount = IDirect3DDevice8_Release(device);
7496 ok(!refcount, "Device has %u references left.\n", refcount);
7497 IDirect3D8_Release(d3d);
7498 DestroyWindow(window);
7501 static void test_lost_device(void)
7503 struct device_desc device_desc;
7504 IDirect3DDevice8 *device;
7505 IDirect3D8 *d3d;
7506 ULONG refcount;
7507 HWND window;
7508 HRESULT hr;
7509 BOOL ret;
7511 window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW,
7512 0, 0, 640, 480, NULL, NULL, NULL, NULL);
7513 d3d = Direct3DCreate8(D3D_SDK_VERSION);
7514 ok(!!d3d, "Failed to create a D3D object.\n");
7515 device_desc.device_window = window;
7516 device_desc.width = registry_mode.dmPelsWidth;
7517 device_desc.height = registry_mode.dmPelsHeight;
7518 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
7519 if (!(device = create_device(d3d, window, &device_desc)))
7521 skip("Failed to create a D3D device, skipping tests.\n");
7522 goto done;
7525 hr = IDirect3DDevice8_TestCooperativeLevel(device);
7526 if (hr == D3DERR_DEVICELOST)
7528 win_skip("Broken TestCooperativeLevel(), skipping test.\n");
7529 IDirect3DDevice8_Release(device);
7530 goto done;
7532 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7533 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
7534 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7536 ret = SetForegroundWindow(GetDesktopWindow());
7537 ok(ret, "Failed to set foreground window.\n");
7538 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
7539 ok(hr == D3DERR_DEVICELOST, "Got unexpected hr %#x.\n", hr);
7540 hr = IDirect3DDevice8_TestCooperativeLevel(device);
7541 ok(hr == D3DERR_DEVICELOST, "Got unexpected hr %#x.\n", hr);
7543 ret = ShowWindow(window, SW_RESTORE);
7544 ok(ret, "Failed to restore window.\n");
7545 ret = SetForegroundWindow(window);
7546 ok(ret, "Failed to set foreground window.\n");
7547 hr = IDirect3DDevice8_TestCooperativeLevel(device);
7548 ok(hr == D3DERR_DEVICENOTRESET, "Got unexpected hr %#x.\n", hr);
7549 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
7550 ok(hr == D3DERR_DEVICELOST, "Got unexpected hr %#x.\n", hr);
7552 hr = reset_device(device, &device_desc);
7553 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7554 hr = IDirect3DDevice8_TestCooperativeLevel(device);
7555 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7556 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
7557 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7559 device_desc.flags = 0;
7560 hr = reset_device(device, &device_desc);
7561 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7562 hr = IDirect3DDevice8_TestCooperativeLevel(device);
7563 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7564 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
7565 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7567 ret = SetForegroundWindow(GetDesktopWindow());
7568 ok(ret, "Failed to set foreground window.\n");
7569 hr = IDirect3DDevice8_TestCooperativeLevel(device);
7570 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7571 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
7572 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7574 ret = ShowWindow(window, SW_RESTORE);
7575 ok(ret, "Failed to restore window.\n");
7576 hr = IDirect3DDevice8_TestCooperativeLevel(device);
7577 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7578 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
7579 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7581 device_desc.flags = CREATE_DEVICE_FULLSCREEN;
7582 hr = reset_device(device, &device_desc);
7583 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7584 hr = IDirect3DDevice8_TestCooperativeLevel(device);
7585 todo_wine ok(hr == D3DERR_DEVICELOST, "Got unexpected hr %#x.\n", hr);
7586 hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
7587 todo_wine ok(hr == D3DERR_DEVICELOST, "Got unexpected hr %#x.\n", hr);
7589 ret = SetForegroundWindow(GetDesktopWindow());
7590 ok(ret, "Failed to set foreground window.\n");
7591 hr = reset_device(device, &device_desc);
7592 ok(hr == D3DERR_DEVICELOST, "Got unexpected hr %#x.\n", hr);
7593 ret = ShowWindow(window, SW_RESTORE);
7594 ok(ret, "Failed to restore window.\n");
7595 ret = SetForegroundWindow(window);
7596 ok(ret, "Failed to set foreground window.\n");
7597 hr = reset_device(device, &device_desc);
7598 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
7600 refcount = IDirect3DDevice8_Release(device);
7601 ok(!refcount, "Device has %u references left.\n", refcount);
7602 done:
7603 IDirect3D8_Release(d3d);
7604 DestroyWindow(window);
7607 static void test_resource_priority(void)
7609 IDirect3DDevice8 *device;
7610 IDirect3DTexture8 *texture;
7611 IDirect3DVertexBuffer8 *buffer;
7612 IDirect3D8 *d3d;
7613 ULONG refcount;
7614 HWND window;
7615 HRESULT hr;
7616 static const struct
7618 D3DPOOL pool;
7619 const char *name;
7620 BOOL can_set_priority;
7622 test_data[] =
7624 {D3DPOOL_DEFAULT, "D3DPOOL_DEFAULT", FALSE},
7625 {D3DPOOL_SYSTEMMEM, "D3DPOOL_SYSTEMMEM", FALSE},
7626 {D3DPOOL_MANAGED, "D3DPOOL_MANAGED", TRUE},
7627 {D3DPOOL_SCRATCH, "D3DPOOL_SCRATCH", FALSE}
7629 unsigned int i;
7630 DWORD priority;
7632 window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW,
7633 0, 0, 640, 480, NULL, NULL, NULL, NULL);
7634 d3d = Direct3DCreate8(D3D_SDK_VERSION);
7635 ok(!!d3d, "Failed to create a D3D object.\n");
7636 if (!(device = create_device(d3d, window, NULL)))
7638 skip("Failed to create a D3D device, skipping tests.\n");
7639 IDirect3D8_Release(d3d);
7640 DestroyWindow(window);
7641 return;
7644 for (i = 0; i < sizeof(test_data) / sizeof(*test_data); i++)
7646 hr = IDirect3DDevice8_CreateTexture(device, 16, 16, 0, 0, D3DFMT_X8R8G8B8,
7647 test_data[i].pool, &texture);
7648 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x, pool %s.\n", hr, test_data[i].name);
7650 priority = IDirect3DTexture8_GetPriority(texture);
7651 ok(priority == 0, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
7652 priority = IDirect3DTexture8_SetPriority(texture, 1);
7653 ok(priority == 0, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
7654 priority = IDirect3DTexture8_GetPriority(texture);
7655 if (test_data[i].can_set_priority)
7657 ok(priority == 1, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
7658 priority = IDirect3DTexture8_SetPriority(texture, 0);
7659 ok(priority == 1, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
7661 else
7662 ok(priority == 0, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
7664 IDirect3DTexture8_Release(texture);
7666 if (test_data[i].pool != D3DPOOL_SCRATCH)
7668 hr = IDirect3DDevice8_CreateVertexBuffer(device, 256, 0, 0,
7669 test_data[i].pool, &buffer);
7670 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x, pool %s.\n", hr, test_data[i].name);
7672 priority = IDirect3DVertexBuffer8_GetPriority(buffer);
7673 ok(priority == 0, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
7674 priority = IDirect3DVertexBuffer8_SetPriority(buffer, 1);
7675 ok(priority == 0, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
7676 priority = IDirect3DVertexBuffer8_GetPriority(buffer);
7677 if (test_data[i].can_set_priority)
7679 ok(priority == 1, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
7680 priority = IDirect3DVertexBuffer8_SetPriority(buffer, 0);
7681 ok(priority == 1, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
7683 else
7684 ok(priority == 0, "Got unexpected priority %u, pool %s.\n", priority, test_data[i].name);
7686 IDirect3DVertexBuffer8_Release(buffer);
7690 refcount = IDirect3DDevice8_Release(device);
7691 ok(!refcount, "Device has %u references left.\n", refcount);
7692 IDirect3D8_Release(d3d);
7693 DestroyWindow(window);
7696 static void test_swapchain_parameters(void)
7698 IDirect3DDevice8 *device;
7699 IDirect3D8 *d3d;
7700 IDirect3DSurface8 *backbuffer;
7701 HWND window;
7702 HRESULT hr;
7703 unsigned int i, j;
7704 D3DPRESENT_PARAMETERS present_parameters, present_parameters_windowed = {0};
7705 static const struct
7707 BOOL windowed;
7708 UINT backbuffer_count;
7709 D3DSWAPEFFECT swap_effect;
7710 HRESULT hr;
7712 tests[] =
7714 /* Swap effect 0 is not allowed. */
7715 {TRUE, 1, 0, D3DERR_INVALIDCALL},
7716 {FALSE, 1, 0, D3DERR_INVALIDCALL},
7718 /* All (non-ex) swap effects are allowed in
7719 * windowed and fullscreen mode. */
7720 {TRUE, 1, D3DSWAPEFFECT_DISCARD, D3D_OK},
7721 {TRUE, 1, D3DSWAPEFFECT_FLIP, D3D_OK},
7722 {FALSE, 1, D3DSWAPEFFECT_DISCARD, D3D_OK},
7723 {FALSE, 1, D3DSWAPEFFECT_FLIP, D3D_OK},
7724 {FALSE, 1, D3DSWAPEFFECT_COPY, D3D_OK},
7726 /* Only one backbuffer in copy mode. Reset allows it for
7727 * some reason. */
7728 {TRUE, 0, D3DSWAPEFFECT_COPY, D3D_OK},
7729 {TRUE, 1, D3DSWAPEFFECT_COPY, D3D_OK},
7730 {TRUE, 2, D3DSWAPEFFECT_COPY, D3DERR_INVALIDCALL},
7731 {FALSE, 2, D3DSWAPEFFECT_COPY, D3DERR_INVALIDCALL},
7732 {TRUE, 0, D3DSWAPEFFECT_COPY_VSYNC, D3D_OK},
7733 {TRUE, 1, D3DSWAPEFFECT_COPY_VSYNC, D3D_OK},
7734 {TRUE, 2, D3DSWAPEFFECT_COPY_VSYNC, D3DERR_INVALIDCALL},
7735 {FALSE, 2, D3DSWAPEFFECT_COPY_VSYNC, D3DERR_INVALIDCALL},
7737 /* Ok with the others, in fullscreen and windowed mode. */
7738 {TRUE, 2, D3DSWAPEFFECT_DISCARD, D3D_OK},
7739 {TRUE, 2, D3DSWAPEFFECT_FLIP, D3D_OK},
7740 {FALSE, 2, D3DSWAPEFFECT_DISCARD, D3D_OK},
7741 {FALSE, 2, D3DSWAPEFFECT_FLIP, D3D_OK},
7743 /* Invalid swapeffects. */
7744 {TRUE, 1, D3DSWAPEFFECT_COPY_VSYNC + 1, D3DERR_INVALIDCALL},
7745 {FALSE, 1, D3DSWAPEFFECT_COPY_VSYNC + 1, D3DERR_INVALIDCALL},
7747 /* 3 is the highest allowed backbuffer count. */
7748 {TRUE, 3, D3DSWAPEFFECT_DISCARD, D3D_OK},
7749 {TRUE, 4, D3DSWAPEFFECT_DISCARD, D3DERR_INVALIDCALL},
7750 {TRUE, 4, D3DSWAPEFFECT_FLIP, D3DERR_INVALIDCALL},
7751 {FALSE, 4, D3DSWAPEFFECT_DISCARD, D3DERR_INVALIDCALL},
7752 {FALSE, 4, D3DSWAPEFFECT_FLIP, D3DERR_INVALIDCALL},
7755 window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW,
7756 0, 0, 640, 480, NULL, NULL, NULL, NULL);
7757 d3d = Direct3DCreate8(D3D_SDK_VERSION);
7758 ok(!!d3d, "Failed to create a D3D object.\n");
7759 if (!(device = create_device(d3d, window, NULL)))
7761 skip("Failed to create a D3D device, skipping tests.\n");
7762 IDirect3D8_Release(d3d);
7763 DestroyWindow(window);
7764 return;
7766 IDirect3DDevice8_Release(device);
7768 present_parameters_windowed.BackBufferWidth = registry_mode.dmPelsWidth;
7769 present_parameters_windowed.BackBufferHeight = registry_mode.dmPelsHeight;
7770 present_parameters_windowed.hDeviceWindow = window;
7771 present_parameters_windowed.BackBufferFormat = D3DFMT_X8R8G8B8;
7772 present_parameters_windowed.SwapEffect = D3DSWAPEFFECT_COPY;
7773 present_parameters_windowed.Windowed = TRUE;
7774 present_parameters_windowed.BackBufferCount = 1;
7776 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
7778 UINT bb_count = tests[i].backbuffer_count ? tests[i].backbuffer_count : 1;
7780 memset(&present_parameters, 0, sizeof(present_parameters));
7781 present_parameters.BackBufferWidth = registry_mode.dmPelsWidth;
7782 present_parameters.BackBufferHeight = registry_mode.dmPelsHeight;
7783 present_parameters.hDeviceWindow = window;
7784 present_parameters.BackBufferFormat = D3DFMT_X8R8G8B8;
7786 present_parameters.SwapEffect = tests[i].swap_effect;
7787 present_parameters.Windowed = tests[i].windowed;
7788 present_parameters.BackBufferCount = tests[i].backbuffer_count;
7790 hr = IDirect3D8_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window,
7791 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device);
7792 ok(hr == tests[i].hr, "Expected hr %x, got %x, test %u.\n", tests[i].hr, hr, i);
7793 if (SUCCEEDED(hr))
7795 for (j = 0; j < bb_count; ++j)
7797 hr = IDirect3DDevice8_GetBackBuffer(device, j, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
7798 ok(SUCCEEDED(hr), "Failed to get backbuffer %u, hr %#x, test %u.\n", j, hr, i);
7799 IDirect3DSurface8_Release(backbuffer);
7801 hr = IDirect3DDevice8_GetBackBuffer(device, j, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
7802 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %x, test %u.\n", hr, i);
7804 IDirect3DDevice8_Release(device);
7807 hr = IDirect3D8_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window,
7808 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters_windowed, &device);
7809 ok(SUCCEEDED(hr), "Failed to create device, hr %#x, test %u.\n", hr, i);
7811 memset(&present_parameters, 0, sizeof(present_parameters));
7812 present_parameters.BackBufferWidth = registry_mode.dmPelsWidth;
7813 present_parameters.BackBufferHeight = registry_mode.dmPelsHeight;
7814 present_parameters.hDeviceWindow = window;
7815 present_parameters.BackBufferFormat = D3DFMT_X8R8G8B8;
7817 present_parameters.SwapEffect = tests[i].swap_effect;
7818 present_parameters.Windowed = tests[i].windowed;
7819 present_parameters.BackBufferCount = tests[i].backbuffer_count;
7821 hr = IDirect3DDevice8_Reset(device, &present_parameters);
7822 ok(hr == tests[i].hr, "Expected hr %x, got %x, test %u.\n", tests[i].hr, hr, i);
7824 if (FAILED(hr))
7826 hr = IDirect3DDevice8_Reset(device, &present_parameters_windowed);
7827 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x, test %u.\n", hr, i);
7829 else
7831 for (j = 0; j < bb_count; ++j)
7833 hr = IDirect3DDevice8_GetBackBuffer(device, j, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
7834 todo_wine_if (j)
7835 ok(SUCCEEDED(hr), "Failed to get backbuffer %u, hr %#x, test %u.\n", j, hr, i);
7836 if (SUCCEEDED(hr))
7837 IDirect3DSurface8_Release(backbuffer);
7839 hr = IDirect3DDevice8_GetBackBuffer(device, j, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
7840 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %x, test %u.\n", hr, i);
7842 IDirect3DDevice8_Release(device);
7845 IDirect3D8_Release(d3d);
7846 DestroyWindow(window);
7849 static void test_miptree_layout(void)
7851 unsigned int pool_idx, format_idx, base_dimension, level_count, offset, i, j;
7852 IDirect3DCubeTexture8 *texture_cube;
7853 IDirect3DTexture8 *texture_2d;
7854 IDirect3DDevice8 *device;
7855 D3DLOCKED_RECT map_desc;
7856 BYTE *base = NULL;
7857 IDirect3D8 *d3d;
7858 D3DCAPS8 caps;
7859 UINT refcount;
7860 HWND window;
7861 HRESULT hr;
7863 static const struct
7865 D3DFORMAT format;
7866 const char *name;
7868 formats[] =
7870 {D3DFMT_A8R8G8B8, "D3DFMT_A8R8G8B8"},
7871 {D3DFMT_A8, "D3DFMT_A8"},
7872 {D3DFMT_L8, "D3DFMT_L8"},
7874 static const struct
7876 D3DPOOL pool;
7877 const char *name;
7879 pools[] =
7881 {D3DPOOL_MANAGED, "D3DPOOL_MANAGED"},
7882 {D3DPOOL_SYSTEMMEM, "D3DPOOL_SYSTEMMEM"},
7883 {D3DPOOL_SCRATCH, "D3DPOOL_SCRATCH"},
7886 window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW,
7887 0, 0, 640, 480, NULL, NULL, NULL, NULL);
7888 d3d = Direct3DCreate8(D3D_SDK_VERSION);
7889 ok(!!d3d, "Failed to create a D3D object.\n");
7890 if (!(device = create_device(d3d, window, NULL)))
7892 skip("Failed to create a D3D device, skipping tests.\n");
7893 goto done;
7896 hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
7897 ok(SUCCEEDED(hr), "Failed to get caps, hr %#x.\n", hr);
7899 base_dimension = 257;
7900 if (caps.TextureCaps & (D3DPTEXTURECAPS_POW2 | D3DPTEXTURECAPS_CUBEMAP_POW2))
7902 skip("Using power of two base dimension.\n");
7903 base_dimension = 256;
7906 for (format_idx = 0; format_idx < sizeof(formats) / sizeof(*formats); ++format_idx)
7908 if (FAILED(hr = IDirect3D8_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
7909 D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, formats[format_idx].format)))
7911 skip("%s textures not supported, skipping tests.\n", formats[format_idx].name);
7912 continue;
7915 for (pool_idx = 0; pool_idx < sizeof(pools) / sizeof(*pools); ++pool_idx)
7917 hr = IDirect3DDevice8_CreateTexture(device, base_dimension, base_dimension, 0, 0,
7918 formats[format_idx].format, pools[pool_idx].pool, &texture_2d);
7919 ok(SUCCEEDED(hr), "Failed to create a %s %s texture, hr %#x.\n",
7920 pools[pool_idx].name, formats[format_idx].name, hr);
7922 level_count = IDirect3DTexture8_GetLevelCount(texture_2d);
7923 for (i = 0, offset = 0; i < level_count; ++i)
7925 hr = IDirect3DTexture8_LockRect(texture_2d, i, &map_desc, NULL, 0);
7926 ok(SUCCEEDED(hr), "%s, %s: Failed to lock level %u, hr %#x.\n",
7927 pools[pool_idx].name, formats[format_idx].name, i, hr);
7929 if (!i)
7930 base = map_desc.pBits;
7931 else
7932 ok(map_desc.pBits == base + offset,
7933 "%s, %s, level %u: Got unexpected pBits %p, expected %p.\n",
7934 pools[pool_idx].name, formats[format_idx].name, i, map_desc.pBits, base + offset);
7935 offset += (base_dimension >> i) * map_desc.Pitch;
7937 hr = IDirect3DTexture8_UnlockRect(texture_2d, i);
7938 ok(SUCCEEDED(hr), "%s, %s Failed to unlock level %u, hr %#x.\n",
7939 pools[pool_idx].name, formats[format_idx].name, i, hr);
7942 IDirect3DTexture8_Release(texture_2d);
7945 if (FAILED(hr = IDirect3D8_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
7946 D3DFMT_X8R8G8B8, 0, D3DRTYPE_CUBETEXTURE, formats[format_idx].format)))
7948 skip("%s cube textures not supported, skipping tests.\n", formats[format_idx].name);
7949 continue;
7952 for (pool_idx = 0; pool_idx < sizeof(pools) / sizeof(*pools); ++pool_idx)
7954 hr = IDirect3DDevice8_CreateCubeTexture(device, base_dimension, 0, 0,
7955 formats[format_idx].format, pools[pool_idx].pool, &texture_cube);
7956 ok(SUCCEEDED(hr), "Failed to create a %s %s cube texture, hr %#x.\n",
7957 pools[pool_idx].name, formats[format_idx].name, hr);
7959 level_count = IDirect3DCubeTexture8_GetLevelCount(texture_cube);
7960 for (i = 0, offset = 0; i < 6; ++i)
7962 for (j = 0; j < level_count; ++j)
7964 hr = IDirect3DCubeTexture8_LockRect(texture_cube, i, j, &map_desc, NULL, 0);
7965 ok(SUCCEEDED(hr), "%s, %s: Failed to lock face %u, level %u, hr %#x.\n",
7966 pools[pool_idx].name, formats[format_idx].name, i, j, hr);
7968 if (!i && !j)
7969 base = map_desc.pBits;
7970 else
7971 ok(map_desc.pBits == base + offset,
7972 "%s, %s, face %u, level %u: Got unexpected pBits %p, expected %p.\n",
7973 pools[pool_idx].name, formats[format_idx].name, i, j, map_desc.pBits, base + offset);
7974 offset += (base_dimension >> j) * map_desc.Pitch;
7976 hr = IDirect3DCubeTexture8_UnlockRect(texture_cube, i, j);
7977 ok(SUCCEEDED(hr), "%s, %s: Failed to unlock face %u, level %u, hr %#x.\n",
7978 pools[pool_idx].name, formats[format_idx].name, i, j, hr);
7980 offset = (offset + 15) & ~15;
7983 IDirect3DCubeTexture8_Release(texture_cube);
7987 refcount = IDirect3DDevice8_Release(device);
7988 ok(!refcount, "Device has %u references left.\n", refcount);
7989 done:
7990 IDirect3D8_Release(d3d);
7991 DestroyWindow(window);
7994 START_TEST(device)
7996 HMODULE d3d8_handle = LoadLibraryA( "d3d8.dll" );
7997 WNDCLASSA wc = {0};
7998 IDirect3D8 *d3d8;
7999 DEVMODEW current_mode;
8001 if (!d3d8_handle)
8003 skip("Could not load d3d8.dll\n");
8004 return;
8007 memset(&current_mode, 0, sizeof(current_mode));
8008 current_mode.dmSize = sizeof(current_mode);
8009 ok(EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &current_mode), "Failed to get display mode.\n");
8010 registry_mode.dmSize = sizeof(registry_mode);
8011 ok(EnumDisplaySettingsW(NULL, ENUM_REGISTRY_SETTINGS, &registry_mode), "Failed to get display mode.\n");
8012 if (current_mode.dmPelsWidth != registry_mode.dmPelsWidth
8013 || current_mode.dmPelsHeight != registry_mode.dmPelsHeight)
8015 skip("Current mode does not match registry mode, skipping test.\n");
8016 return;
8019 wc.lpfnWndProc = DefWindowProcA;
8020 wc.lpszClassName = "d3d8_test_wc";
8021 RegisterClassA(&wc);
8023 ValidateVertexShader = (void *)GetProcAddress(d3d8_handle, "ValidateVertexShader");
8024 ValidatePixelShader = (void *)GetProcAddress(d3d8_handle, "ValidatePixelShader");
8026 if (!(d3d8 = Direct3DCreate8(D3D_SDK_VERSION)))
8028 skip("could not create D3D8\n");
8029 return;
8031 IDirect3D8_Release(d3d8);
8033 test_fpu_setup();
8034 test_display_formats();
8035 test_display_modes();
8036 test_shader_versions();
8037 test_swapchain();
8038 test_refcount();
8039 test_mipmap_levels();
8040 test_checkdevicemultisampletype();
8041 test_invalid_multisample();
8042 test_cursor();
8043 test_cursor_pos();
8044 test_states();
8045 test_reset();
8046 test_scene();
8047 test_shader();
8048 test_limits();
8049 test_lights();
8050 test_ApplyStateBlock();
8051 test_render_zero_triangles();
8052 test_depth_stencil_reset();
8053 test_wndproc();
8054 test_wndproc_windowed();
8055 test_depth_stencil_size();
8056 test_window_style();
8057 test_unsupported_shaders();
8058 test_mode_change();
8059 test_device_window_reset();
8060 test_reset_resources();
8061 depth_blit_test();
8062 test_set_rt_vp_scissor();
8063 test_validate_vs();
8064 test_validate_ps();
8065 test_volume_get_container();
8066 test_vb_lock_flags();
8067 test_texture_stage_states();
8068 test_cube_textures();
8069 test_get_set_texture();
8070 test_image_surface_pool();
8071 test_surface_get_container();
8072 test_lockrect_invalid();
8073 test_private_data();
8074 test_surface_dimensions();
8075 test_surface_format_null();
8076 test_surface_double_unlock();
8077 test_surface_blocks();
8078 test_set_palette();
8079 test_swvp_buffer();
8080 test_managed_buffer();
8081 test_npot_textures();
8082 test_volume_locking();
8083 test_update_volumetexture();
8084 test_create_rt_ds_fail();
8085 test_volume_blocks();
8086 test_lockbox_invalid();
8087 test_pixel_format();
8088 test_begin_end_state_block();
8089 test_shader_constant_apply();
8090 test_resource_type();
8091 test_mipmap_lock();
8092 test_writeonly_resource();
8093 test_lost_device();
8094 test_resource_priority();
8095 test_swapchain_parameters();
8096 test_miptree_layout();
8098 UnregisterClassA("d3d8_test_wc", GetModuleHandleA(NULL));