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
28 #include "wine/test.h"
29 #include "wine/heap.h"
36 #define CREATE_DEVICE_FULLSCREEN 0x01
37 #define CREATE_DEVICE_FPU_PRESERVE 0x02
38 #define CREATE_DEVICE_SWVP_ONLY 0x04
39 #define CREATE_DEVICE_LOCKABLE_BACKBUFFER 0x08
43 unsigned int adapter_ordinal
;
50 #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
51 #define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
53 static DEVMODEW registry_mode
;
55 static HRESULT (WINAPI
*ValidateVertexShader
)(const DWORD
*, const DWORD
*, const D3DCAPS8
*, BOOL
, char **);
56 static HRESULT (WINAPI
*ValidatePixelShader
)(const DWORD
*, const D3DCAPS8
*, BOOL
, char **);
58 static const DWORD simple_vs
[] = {0xFFFE0101, /* vs_1_1 */
59 0x00000009, 0xC0010000, 0x90E40000, 0xA0E40000, /* dp4 oPos.x, v0, c0 */
60 0x00000009, 0xC0020000, 0x90E40000, 0xA0E40001, /* dp4 oPos.y, v0, c1 */
61 0x00000009, 0xC0040000, 0x90E40000, 0xA0E40002, /* dp4 oPos.z, v0, c2 */
62 0x00000009, 0xC0080000, 0x90E40000, 0xA0E40003, /* dp4 oPos.w, v0, c3 */
63 0x0000FFFF}; /* END */
64 static const DWORD simple_ps
[] = {0xFFFF0101, /* ps_1_1 */
65 0x00000051, 0xA00F0001, 0x3F800000, 0x00000000, 0x00000000, 0x00000000, /* def c1 = 1.0, 0.0, 0.0, 0.0 */
66 0x00000042, 0xB00F0000, /* tex t0 */
67 0x00000008, 0x800F0000, 0xA0E40001, 0xA0E40000, /* dp3 r0, c1, c0 */
68 0x00000005, 0x800F0000, 0x90E40000, 0x80E40000, /* mul r0, v0, r0 */
69 0x00000005, 0x800F0000, 0xB0E40000, 0x80E40000, /* mul r0, t0, r0 */
70 0x0000FFFF}; /* END */
72 static int get_refcount(IUnknown
*object
)
74 IUnknown_AddRef( object
);
75 return IUnknown_Release( object
);
78 static void get_virtual_rect(RECT
*rect
)
80 rect
->left
= GetSystemMetrics(SM_XVIRTUALSCREEN
);
81 rect
->top
= GetSystemMetrics(SM_YVIRTUALSCREEN
);
82 rect
->right
= rect
->left
+ GetSystemMetrics(SM_CXVIRTUALSCREEN
);
83 rect
->bottom
= rect
->top
+ GetSystemMetrics(SM_CYVIRTUALSCREEN
);
86 static HWND
create_window(void)
88 RECT r
= {0, 0, 640, 480};
90 AdjustWindowRect(&r
, WS_OVERLAPPEDWINDOW
| WS_VISIBLE
, FALSE
);
92 return CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
93 0, 0, r
.right
- r
.left
, r
.bottom
- r
.top
, NULL
, NULL
, NULL
, NULL
);
96 /* try to make sure pending X events have been processed before continuing */
97 static void flush_events(void)
101 int min_timeout
= 100;
102 DWORD time
= GetTickCount() + diff
;
106 if (MsgWaitForMultipleObjects( 0, NULL
, FALSE
, min_timeout
, QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
107 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
108 diff
= time
- GetTickCount();
112 static BOOL
adapter_is_warp(const D3DADAPTER_IDENTIFIER8
*identifier
)
114 return !strcmp(identifier
->Driver
, "d3d10warp.dll");
117 static IDirect3DDevice8
*create_device(IDirect3D8
*d3d8
, HWND focus_window
, const struct device_desc
*desc
)
119 D3DPRESENT_PARAMETERS present_parameters
= {0};
120 unsigned int adapter_ordinal
;
121 IDirect3DDevice8
*device
;
122 DWORD behavior_flags
= D3DCREATE_HARDWARE_VERTEXPROCESSING
;
124 adapter_ordinal
= D3DADAPTER_DEFAULT
;
125 present_parameters
.BackBufferWidth
= 640;
126 present_parameters
.BackBufferHeight
= 480;
127 present_parameters
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
128 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
129 present_parameters
.hDeviceWindow
= focus_window
;
130 present_parameters
.Windowed
= TRUE
;
131 present_parameters
.EnableAutoDepthStencil
= TRUE
;
132 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
136 adapter_ordinal
= desc
->adapter_ordinal
;
137 present_parameters
.BackBufferWidth
= desc
->width
;
138 present_parameters
.BackBufferHeight
= desc
->height
;
139 present_parameters
.hDeviceWindow
= desc
->device_window
;
140 present_parameters
.Windowed
= !(desc
->flags
& CREATE_DEVICE_FULLSCREEN
);
141 if (desc
->flags
& CREATE_DEVICE_LOCKABLE_BACKBUFFER
)
142 present_parameters
.Flags
|= D3DPRESENTFLAG_LOCKABLE_BACKBUFFER
;
143 if (desc
->flags
& CREATE_DEVICE_SWVP_ONLY
)
144 behavior_flags
= D3DCREATE_SOFTWARE_VERTEXPROCESSING
;
145 if (desc
->flags
& CREATE_DEVICE_FPU_PRESERVE
)
146 behavior_flags
|= D3DCREATE_FPU_PRESERVE
;
149 if (SUCCEEDED(IDirect3D8_CreateDevice(d3d8
, adapter_ordinal
, D3DDEVTYPE_HAL
, focus_window
,
150 behavior_flags
, &present_parameters
, &device
)))
153 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D16
;
154 if (SUCCEEDED(IDirect3D8_CreateDevice(d3d8
, adapter_ordinal
, D3DDEVTYPE_HAL
, focus_window
,
155 behavior_flags
, &present_parameters
, &device
)))
158 if (desc
&& desc
->flags
& CREATE_DEVICE_SWVP_ONLY
)
160 behavior_flags
^= (D3DCREATE_HARDWARE_VERTEXPROCESSING
| D3DCREATE_SOFTWARE_VERTEXPROCESSING
);
162 if (SUCCEEDED(IDirect3D8_CreateDevice(d3d8
, adapter_ordinal
, D3DDEVTYPE_HAL
, focus_window
,
163 behavior_flags
, &present_parameters
, &device
)))
169 static HRESULT
reset_device(IDirect3DDevice8
*device
, const struct device_desc
*desc
)
171 D3DPRESENT_PARAMETERS present_parameters
= {0};
173 present_parameters
.BackBufferWidth
= 640;
174 present_parameters
.BackBufferHeight
= 480;
175 present_parameters
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
176 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
177 present_parameters
.hDeviceWindow
= NULL
;
178 present_parameters
.Windowed
= TRUE
;
179 present_parameters
.EnableAutoDepthStencil
= TRUE
;
180 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
184 present_parameters
.BackBufferWidth
= desc
->width
;
185 present_parameters
.BackBufferHeight
= desc
->height
;
186 present_parameters
.hDeviceWindow
= desc
->device_window
;
187 present_parameters
.Windowed
= !(desc
->flags
& CREATE_DEVICE_FULLSCREEN
);
190 return IDirect3DDevice8_Reset(device
, &present_parameters
);
193 #define CHECK_CALL(r,c,d,rc) \
195 int tmp1 = get_refcount( (IUnknown *)d ); \
197 ok(tmp1 == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, tmp1); \
199 trace("%s failed: %#08x\n", c, r); \
202 #define CHECK_RELEASE(obj,d,rc) \
204 int tmp1, rc_new = rc; \
205 IUnknown_Release( (IUnknown*)obj ); \
206 tmp1 = get_refcount( (IUnknown *)d ); \
207 ok(tmp1 == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, tmp1); \
210 #define CHECK_REFCOUNT(obj,rc) \
213 int count = get_refcount( (IUnknown *)obj ); \
214 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
217 #define CHECK_RELEASE_REFCOUNT(obj,rc) \
220 int count = IUnknown_Release( (IUnknown *)obj ); \
221 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
224 #define CHECK_ADDREF_REFCOUNT(obj,rc) \
227 int count = IUnknown_AddRef( (IUnknown *)obj ); \
228 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
231 #define CHECK_SURFACE_CONTAINER(obj,iid,expected) \
233 void *container_ptr = (void *)0x1337c0d3; \
234 hr = IDirect3DSurface8_GetContainer(obj, &iid, &container_ptr); \
235 ok(SUCCEEDED(hr) && container_ptr == expected, "GetContainer returned: hr %#08x, container_ptr %p. " \
236 "Expected hr %#08x, container_ptr %p\n", hr, container_ptr, S_OK, expected); \
237 if (container_ptr && container_ptr != (void *)0x1337c0d3) IUnknown_Release((IUnknown *)container_ptr); \
240 static void check_mipmap_levels(IDirect3DDevice8
*device
, UINT width
, UINT height
, UINT count
)
242 IDirect3DBaseTexture8
* texture
= NULL
;
243 HRESULT hr
= IDirect3DDevice8_CreateTexture( device
, width
, height
, 0, 0,
244 D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, (IDirect3DTexture8
**) &texture
);
247 DWORD levels
= IDirect3DBaseTexture8_GetLevelCount(texture
);
248 ok(levels
== count
, "Invalid level count. Expected %d got %u\n", count
, levels
);
250 trace("CreateTexture failed: %#08x\n", hr
);
252 if (texture
) IDirect3DBaseTexture8_Release( texture
);
255 static void test_mipmap_levels(void)
257 IDirect3DDevice8
*device
;
262 window
= create_window();
263 ok(!!window
, "Failed to create a window.\n");
264 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
265 ok(!!d3d
, "Failed to create a D3D object.\n");
266 if (!(device
= create_device(d3d
, window
, NULL
)))
268 skip("Failed to create a 3D device, skipping test.\n");
272 check_mipmap_levels(device
, 32, 32, 6);
273 check_mipmap_levels(device
, 256, 1, 9);
274 check_mipmap_levels(device
, 1, 256, 9);
275 check_mipmap_levels(device
, 1, 1, 1);
277 refcount
= IDirect3DDevice8_Release(device
);
278 ok(!refcount
, "Device has %u references left.\n", refcount
);
280 IDirect3D8_Release(d3d
);
281 DestroyWindow(window
);
284 static void test_swapchain(void)
286 IDirect3DSwapChain8
*swapchain1
;
287 IDirect3DSwapChain8
*swapchain2
;
288 IDirect3DSwapChain8
*swapchain3
;
289 IDirect3DSurface8
*backbuffer
, *stereo_buffer
;
290 D3DPRESENT_PARAMETERS d3dpp
;
291 IDirect3DDevice8
*device
;
294 HWND window
, window2
;
296 struct device_desc device_desc
;
298 window
= create_window();
299 ok(!!window
, "Failed to create a window.\n");
300 window2
= create_window();
301 ok(!!window2
, "Failed to create a window.\n");
302 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
303 ok(!!d3d
, "Failed to create a D3D object.\n");
304 if (!(device
= create_device(d3d
, window
, NULL
)))
306 skip("Failed to create a 3D device, skipping test.\n");
310 backbuffer
= (void *)0xdeadbeef;
311 /* IDirect3DDevice8::GetBackBuffer crashes if a NULL output pointer is passed. */
312 hr
= IDirect3DDevice8_GetBackBuffer(device
, 1, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
313 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
314 ok(!backbuffer
, "The back buffer pointer is %p, expected NULL.\n", backbuffer
);
316 hr
= IDirect3DDevice8_GetBackBuffer(device
, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
317 ok(SUCCEEDED(hr
), "Failed to get back buffer, hr %#x.\n", hr
);
318 IDirect3DSurface8_Release(backbuffer
);
320 /* The back buffer type value is ignored. */
321 hr
= IDirect3DDevice8_GetBackBuffer(device
, 0, D3DBACKBUFFER_TYPE_LEFT
, &stereo_buffer
);
322 ok(SUCCEEDED(hr
), "Failed to get the back buffer, hr %#x.\n", hr
);
323 ok(stereo_buffer
== backbuffer
, "Expected left back buffer = %p, got %p.\n", backbuffer
, stereo_buffer
);
324 IDirect3DSurface8_Release(stereo_buffer
);
325 hr
= IDirect3DDevice8_GetBackBuffer(device
, 0, D3DBACKBUFFER_TYPE_RIGHT
, &stereo_buffer
);
326 ok(SUCCEEDED(hr
), "Failed to get the back buffer, hr %#x.\n", hr
);
327 ok(stereo_buffer
== backbuffer
, "Expected right back buffer = %p, got %p.\n", backbuffer
, stereo_buffer
);
328 IDirect3DSurface8_Release(stereo_buffer
);
329 hr
= IDirect3DDevice8_GetBackBuffer(device
, 0, (D3DBACKBUFFER_TYPE
)0xdeadbeef, &stereo_buffer
);
330 ok(SUCCEEDED(hr
), "Failed to get the back buffer, hr %#x.\n", hr
);
331 ok(stereo_buffer
== backbuffer
, "Expected unknown buffer = %p, got %p.\n", backbuffer
, stereo_buffer
);
332 IDirect3DSurface8_Release(stereo_buffer
);
334 memset(&d3dpp
, 0, sizeof(d3dpp
));
335 d3dpp
.Windowed
= TRUE
;
336 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
337 d3dpp
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
339 /* Create a bunch of swapchains */
340 d3dpp
.BackBufferCount
= 0;
341 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(device
, &d3dpp
, &swapchain1
);
342 ok(SUCCEEDED(hr
), "Failed to create a swapchain (%#08x)\n", hr
);
343 ok(d3dpp
.BackBufferCount
== 1, "The back buffer count in the presentparams struct is %d\n", d3dpp
.BackBufferCount
);
345 d3dpp
.BackBufferCount
= 1;
346 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(device
, &d3dpp
, &swapchain2
);
347 ok(SUCCEEDED(hr
), "Failed to create a swapchain (%#08x)\n", hr
);
349 d3dpp
.BackBufferCount
= 2;
350 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(device
, &d3dpp
, &swapchain3
);
351 ok(SUCCEEDED(hr
), "Failed to create a swapchain (%#08x)\n", hr
);
353 /* Swapchain 3, created with backbuffercount 2 */
354 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain3
, 0, 0, NULL
);
355 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
357 backbuffer
= (void *) 0xdeadbeef;
358 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain3
, 0, 0, &backbuffer
);
359 ok(SUCCEEDED(hr
), "Failed to get the 1st back buffer (%#08x)\n", hr
);
360 ok(backbuffer
!= NULL
&& backbuffer
!= (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer
);
361 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
363 /* The back buffer type value is ignored. */
364 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain3
, 0, D3DBACKBUFFER_TYPE_LEFT
, &stereo_buffer
);
365 ok(SUCCEEDED(hr
), "Failed to get the back buffer, hr %#x.\n", hr
);
366 ok(stereo_buffer
== backbuffer
, "Expected left back buffer = %p, got %p.\n", backbuffer
, stereo_buffer
);
367 IDirect3DSurface8_Release(stereo_buffer
);
368 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain3
, 0, D3DBACKBUFFER_TYPE_RIGHT
, &stereo_buffer
);
369 ok(SUCCEEDED(hr
), "Failed to get the back buffer, hr %#x.\n", hr
);
370 ok(stereo_buffer
== backbuffer
, "Expected right back buffer = %p, got %p.\n", backbuffer
, stereo_buffer
);
371 IDirect3DSurface8_Release(stereo_buffer
);
372 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain3
, 0, (D3DBACKBUFFER_TYPE
)0xdeadbeef, &stereo_buffer
);
373 ok(SUCCEEDED(hr
), "Failed to get the back buffer, hr %#x.\n", hr
);
374 ok(stereo_buffer
== backbuffer
, "Expected unknown buffer = %p, got %p.\n", backbuffer
, stereo_buffer
);
375 IDirect3DSurface8_Release(stereo_buffer
);
377 backbuffer
= (void *) 0xdeadbeef;
378 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain3
, 1, 0, &backbuffer
);
379 ok(SUCCEEDED(hr
), "Failed to get the 2nd back buffer (%#08x)\n", hr
);
380 ok(backbuffer
!= NULL
&& backbuffer
!= (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer
);
381 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
383 backbuffer
= (void *) 0xdeadbeef;
384 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain3
, 2, 0, &backbuffer
);
385 ok(hr
== D3DERR_INVALIDCALL
, "GetBackBuffer returned %#08x\n", hr
);
386 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
387 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
389 backbuffer
= (void *) 0xdeadbeef;
390 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain3
, 3, 0, &backbuffer
);
391 ok(FAILED(hr
), "Failed to get the back buffer (%#08x)\n", hr
);
392 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
393 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
396 /* Check the back buffers of the swapchains */
397 /* Swapchain 1, created with backbuffercount 0 */
398 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain1
, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
399 ok(SUCCEEDED(hr
), "Failed to get the back buffer (%#08x)\n", hr
);
400 ok(backbuffer
!= NULL
, "The back buffer is NULL (%#08x)\n", hr
);
401 if(backbuffer
) IDirect3DSurface8_Release(backbuffer
);
403 backbuffer
= (void *) 0xdeadbeef;
404 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain1
, 1, 0, &backbuffer
);
405 ok(FAILED(hr
), "Failed to get the back buffer (%#08x)\n", hr
);
406 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
407 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
409 /* Swapchain 2 - created with backbuffercount 1 */
410 backbuffer
= (void *) 0xdeadbeef;
411 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain2
, 0, 0, &backbuffer
);
412 ok(SUCCEEDED(hr
), "Failed to get the back buffer (%#08x)\n", hr
);
413 ok(backbuffer
!= NULL
&& backbuffer
!= (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer
);
414 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
416 backbuffer
= (void *) 0xdeadbeef;
417 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain2
, 1, 0, &backbuffer
);
418 ok(hr
== D3DERR_INVALIDCALL
, "GetBackBuffer returned %#08x\n", hr
);
419 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
420 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
422 backbuffer
= (void *) 0xdeadbeef;
423 hr
= IDirect3DSwapChain8_GetBackBuffer(swapchain2
, 2, 0, &backbuffer
);
424 ok(FAILED(hr
), "Failed to get the back buffer (%#08x)\n", hr
);
425 ok(backbuffer
== (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer
);
426 if(backbuffer
&& backbuffer
!= (void *) 0xdeadbeef) IDirect3DSurface8_Release(backbuffer
);
428 IDirect3DSwapChain8_Release(swapchain3
);
429 IDirect3DSwapChain8_Release(swapchain2
);
430 IDirect3DSwapChain8_Release(swapchain1
);
432 d3dpp
.Windowed
= FALSE
;
433 d3dpp
.hDeviceWindow
= window
;
434 d3dpp
.BackBufferCount
= 1;
435 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(device
, &d3dpp
, &swapchain1
);
436 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x\n", hr
);
437 d3dpp
.hDeviceWindow
= window2
;
438 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(device
, &d3dpp
, &swapchain1
);
439 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x\n", hr
);
441 device_desc
.width
= registry_mode
.dmPelsWidth
;
442 device_desc
.height
= registry_mode
.dmPelsHeight
;
443 device_desc
.device_window
= window
;
444 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
445 hr
= reset_device(device
, &device_desc
);
446 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
448 d3dpp
.hDeviceWindow
= window
;
449 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(device
, &d3dpp
, &swapchain1
);
450 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x\n", hr
);
451 d3dpp
.hDeviceWindow
= window2
;
452 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(device
, &d3dpp
, &swapchain1
);
453 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x\n", hr
);
454 d3dpp
.Windowed
= TRUE
;
455 d3dpp
.hDeviceWindow
= window
;
456 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(device
, &d3dpp
, &swapchain1
);
457 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x\n", hr
);
458 d3dpp
.hDeviceWindow
= window2
;
459 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(device
, &d3dpp
, &swapchain1
);
460 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x\n", hr
);
462 refcount
= IDirect3DDevice8_Release(device
);
463 ok(!refcount
, "Device has %u references left.\n", refcount
);
465 IDirect3D8_Release(d3d
);
466 DestroyWindow(window2
);
467 DestroyWindow(window
);
470 static void test_refcount(void)
472 IDirect3DVertexBuffer8
*pVertexBuffer
= NULL
;
473 IDirect3DIndexBuffer8
*pIndexBuffer
= NULL
;
474 DWORD dVertexShader
= -1;
475 DWORD dPixelShader
= -1;
476 IDirect3DCubeTexture8
*pCubeTexture
= NULL
;
477 IDirect3DTexture8
*pTexture
= NULL
;
478 IDirect3DVolumeTexture8
*pVolumeTexture
= NULL
;
479 IDirect3DVolume8
*pVolumeLevel
= NULL
;
480 IDirect3DSurface8
*pStencilSurface
= NULL
;
481 IDirect3DSurface8
*pImageSurface
= NULL
;
482 IDirect3DSurface8
*pRenderTarget
= NULL
;
483 IDirect3DSurface8
*pRenderTarget2
= NULL
;
484 IDirect3DSurface8
*pRenderTarget3
= NULL
;
485 IDirect3DSurface8
*pTextureLevel
= NULL
;
486 IDirect3DSurface8
*pBackBuffer
= NULL
;
487 DWORD dStateBlock
= -1;
488 IDirect3DSwapChain8
*pSwapChain
= NULL
;
490 D3DPRESENT_PARAMETERS d3dpp
;
491 IDirect3DDevice8
*device
= NULL
;
492 ULONG refcount
= 0, tmp
;
493 IDirect3D8
*d3d
, *d3d2
;
500 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT3
), /* D3DVSDE_POSITION, Register v0 */
501 D3DVSD_REG(D3DVSDE_DIFFUSE
, D3DVSDT_D3DCOLOR
), /* D3DVSDE_DIFFUSE, Register v5 */
505 window
= create_window();
506 ok(!!window
, "Failed to create a window.\n");
507 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
508 ok(!!d3d
, "Failed to create a D3D object.\n");
510 CHECK_REFCOUNT(d3d
, 1);
512 if (!(device
= create_device(d3d
, window
, NULL
)))
514 skip("Failed to create a 3D device, skipping test.\n");
518 IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
520 refcount
= get_refcount((IUnknown
*)device
);
521 ok(refcount
== 1, "Invalid device RefCount %d\n", refcount
);
523 CHECK_REFCOUNT(d3d
, 2);
525 hr
= IDirect3DDevice8_GetDirect3D(device
, &d3d2
);
526 CHECK_CALL(hr
, "GetDirect3D", device
, refcount
);
528 ok(d3d2
== d3d
, "Expected IDirect3D8 pointers to be equal.\n");
529 CHECK_REFCOUNT(d3d
, 3);
530 CHECK_RELEASE_REFCOUNT(d3d
, 2);
533 * Check refcount of implicit surfaces. Findings:
534 * - the container is the device
535 * - they hold a reference to the device
536 * - they are created with a refcount of 0 (Get/Release returns original refcount)
537 * - they are not freed if refcount reaches 0.
538 * - the refcount is not forwarded to the container.
540 hr
= IDirect3DDevice8_GetRenderTarget(device
, &pRenderTarget
);
541 CHECK_CALL(hr
, "GetRenderTarget", device
, ++refcount
);
544 CHECK_SURFACE_CONTAINER(pRenderTarget
, IID_IDirect3DDevice8
, device
);
545 CHECK_REFCOUNT(pRenderTarget
, 1);
547 CHECK_ADDREF_REFCOUNT(pRenderTarget
, 2);
548 CHECK_REFCOUNT(device
, refcount
);
549 CHECK_RELEASE_REFCOUNT(pRenderTarget
, 1);
550 CHECK_REFCOUNT(device
, refcount
);
552 hr
= IDirect3DDevice8_GetRenderTarget(device
, &pRenderTarget
);
553 CHECK_CALL(hr
, "GetRenderTarget", device
, refcount
);
554 CHECK_REFCOUNT(pRenderTarget
, 2);
555 CHECK_RELEASE_REFCOUNT( pRenderTarget
, 1);
556 CHECK_RELEASE_REFCOUNT( pRenderTarget
, 0);
557 CHECK_REFCOUNT(device
, --refcount
);
559 /* The render target is released with the device, so AddRef with refcount=0 is fine here. */
560 CHECK_ADDREF_REFCOUNT(pRenderTarget
, 1);
561 CHECK_REFCOUNT(device
, ++refcount
);
562 CHECK_RELEASE_REFCOUNT(pRenderTarget
, 0);
563 CHECK_REFCOUNT(device
, --refcount
);
564 CHECK_RELEASE_REFCOUNT(pRenderTarget
, 0);
565 CHECK_RELEASE_REFCOUNT(pRenderTarget
, 0);
568 /* Render target and back buffer are identical. */
569 hr
= IDirect3DDevice8_GetBackBuffer(device
, 0, 0, &pBackBuffer
);
570 CHECK_CALL(hr
, "GetBackBuffer", device
, ++refcount
);
573 CHECK_RELEASE_REFCOUNT(pBackBuffer
, 0);
574 ok(pRenderTarget
== pBackBuffer
, "RenderTarget=%p and BackBuffer=%p should be the same.\n",
575 pRenderTarget
, pBackBuffer
);
576 CHECK_RELEASE_REFCOUNT(pBackBuffer
, 0);
577 CHECK_RELEASE_REFCOUNT(pBackBuffer
, 0);
580 CHECK_REFCOUNT(device
, --refcount
);
582 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &pStencilSurface
);
583 CHECK_CALL(hr
, "GetDepthStencilSurface", device
, ++refcount
);
586 CHECK_SURFACE_CONTAINER(pStencilSurface
, IID_IDirect3DDevice8
, device
);
587 CHECK_REFCOUNT(pStencilSurface
, 1);
589 CHECK_ADDREF_REFCOUNT(pStencilSurface
, 2);
590 CHECK_REFCOUNT(device
, refcount
);
591 CHECK_RELEASE_REFCOUNT(pStencilSurface
, 1);
592 CHECK_REFCOUNT(device
, refcount
);
594 CHECK_RELEASE_REFCOUNT( pStencilSurface
, 0);
595 CHECK_REFCOUNT(device
, --refcount
);
597 /* The stencil surface is released with the device, so AddRef with refcount=0 is fine here. */
598 CHECK_ADDREF_REFCOUNT(pStencilSurface
, 1);
599 CHECK_REFCOUNT(device
, ++refcount
);
600 CHECK_RELEASE_REFCOUNT(pStencilSurface
, 0);
601 CHECK_REFCOUNT(device
, --refcount
);
602 CHECK_RELEASE_REFCOUNT(pStencilSurface
, 0);
603 CHECK_RELEASE_REFCOUNT(pStencilSurface
, 0);
604 pStencilSurface
= NULL
;
608 hr
= IDirect3DDevice8_CreateIndexBuffer(device
, 16, 0, D3DFMT_INDEX32
, D3DPOOL_DEFAULT
, &pIndexBuffer
);
609 CHECK_CALL(hr
, "CreateIndexBuffer", device
, ++refcount
);
612 tmp
= get_refcount( (IUnknown
*)pIndexBuffer
);
614 hr
= IDirect3DDevice8_SetIndices(device
, pIndexBuffer
, 0);
615 CHECK_CALL( hr
, "SetIndices", pIndexBuffer
, tmp
);
616 hr
= IDirect3DDevice8_SetIndices(device
, NULL
, 0);
617 CHECK_CALL( hr
, "SetIndices", pIndexBuffer
, tmp
);
620 hr
= IDirect3DDevice8_CreateVertexBuffer(device
, 16, 0, D3DFVF_XYZ
, D3DPOOL_DEFAULT
, &pVertexBuffer
);
621 CHECK_CALL(hr
, "CreateVertexBuffer", device
, ++refcount
);
624 IDirect3DVertexBuffer8
*pVBuf
= (void*)~0;
627 tmp
= get_refcount( (IUnknown
*)pVertexBuffer
);
629 hr
= IDirect3DDevice8_SetStreamSource(device
, 0, pVertexBuffer
, 3 * sizeof(float));
630 CHECK_CALL( hr
, "SetStreamSource", pVertexBuffer
, tmp
);
631 hr
= IDirect3DDevice8_SetStreamSource(device
, 0, NULL
, 0);
632 CHECK_CALL( hr
, "SetStreamSource", pVertexBuffer
, tmp
);
634 hr
= IDirect3DDevice8_GetStreamSource(device
, 0, &pVBuf
, &stride
);
635 ok(SUCCEEDED(hr
), "GetStreamSource did not succeed with NULL stream!\n");
636 ok(pVBuf
==NULL
, "pVBuf not NULL (%p)!\n", pVBuf
);
637 ok(stride
==3*sizeof(float), "stride not 3 floats (got %u)!\n", stride
);
641 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl
, simple_vs
, &dVertexShader
, 0);
642 CHECK_CALL(hr
, "CreateVertexShader", device
, refcount
);
643 if (caps
.PixelShaderVersion
>= D3DPS_VERSION(1, 0))
645 hr
= IDirect3DDevice8_CreatePixelShader(device
, simple_ps
, &dPixelShader
);
646 CHECK_CALL(hr
, "CreatePixelShader", device
, refcount
);
649 hr
= IDirect3DDevice8_CreateTexture(device
, 32, 32, 3, 0, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &pTexture
);
650 CHECK_CALL(hr
, "CreateTexture", device
, ++refcount
);
653 tmp
= get_refcount( (IUnknown
*)pTexture
);
655 /* SetTexture should not increase refcounts */
656 hr
= IDirect3DDevice8_SetTexture(device
, 0, (IDirect3DBaseTexture8
*) pTexture
);
657 CHECK_CALL( hr
, "SetTexture", pTexture
, tmp
);
658 hr
= IDirect3DDevice8_SetTexture(device
, 0, NULL
);
659 CHECK_CALL( hr
, "SetTexture", pTexture
, tmp
);
661 /* This should not increment device refcount */
662 hr
= IDirect3DTexture8_GetSurfaceLevel( pTexture
, 1, &pTextureLevel
);
663 CHECK_CALL(hr
, "GetSurfaceLevel", device
, refcount
);
664 /* But should increment texture's refcount */
665 CHECK_REFCOUNT( pTexture
, tmp
+1 );
666 /* Because the texture and surface refcount are identical */
669 CHECK_REFCOUNT ( pTextureLevel
, tmp
+1 );
670 CHECK_ADDREF_REFCOUNT ( pTextureLevel
, tmp
+2 );
671 CHECK_REFCOUNT ( pTexture
, tmp
+2 );
672 CHECK_RELEASE_REFCOUNT( pTextureLevel
, tmp
+1 );
673 CHECK_REFCOUNT ( pTexture
, tmp
+1 );
674 CHECK_RELEASE_REFCOUNT( pTexture
, tmp
);
675 CHECK_REFCOUNT ( pTextureLevel
, tmp
);
678 if(caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP
)
680 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 32, 0, 0, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &pCubeTexture
);
681 CHECK_CALL(hr
, "CreateCubeTexture", device
, ++refcount
);
685 skip("Cube textures not supported\n");
687 if(caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP
)
689 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 32, 32, 2, 0, 0,
690 D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &pVolumeTexture
);
691 CHECK_CALL(hr
, "CreateVolumeTexture", device
, ++refcount
);
695 skip("Volume textures not supported\n");
700 tmp
= get_refcount( (IUnknown
*)pVolumeTexture
);
702 /* This should not increment device refcount */
703 hr
= IDirect3DVolumeTexture8_GetVolumeLevel(pVolumeTexture
, 0, &pVolumeLevel
);
704 CHECK_CALL(hr
, "GetVolumeLevel", device
, refcount
);
705 /* But should increment volume texture's refcount */
706 CHECK_REFCOUNT( pVolumeTexture
, tmp
+1 );
707 /* Because the volume texture and volume refcount are identical */
710 CHECK_REFCOUNT ( pVolumeLevel
, tmp
+1 );
711 CHECK_ADDREF_REFCOUNT ( pVolumeLevel
, tmp
+2 );
712 CHECK_REFCOUNT ( pVolumeTexture
, tmp
+2 );
713 CHECK_RELEASE_REFCOUNT( pVolumeLevel
, tmp
+1 );
714 CHECK_REFCOUNT ( pVolumeTexture
, tmp
+1 );
715 CHECK_RELEASE_REFCOUNT( pVolumeTexture
, tmp
);
716 CHECK_REFCOUNT ( pVolumeLevel
, tmp
);
720 hr
= IDirect3DDevice8_CreateDepthStencilSurface(device
, 32, 32,
721 D3DFMT_D16
, D3DMULTISAMPLE_NONE
, &pStencilSurface
);
722 CHECK_CALL(hr
, "CreateDepthStencilSurface", device
, ++refcount
);
723 CHECK_REFCOUNT( pStencilSurface
, 1);
724 hr
= IDirect3DDevice8_CreateImageSurface(device
, 32, 32,
725 D3DFMT_X8R8G8B8
, &pImageSurface
);
726 CHECK_CALL(hr
, "CreateImageSurface", device
, ++refcount
);
727 CHECK_REFCOUNT( pImageSurface
, 1);
728 hr
= IDirect3DDevice8_CreateRenderTarget(device
, 32, 32,
729 D3DFMT_X8R8G8B8
, D3DMULTISAMPLE_NONE
, TRUE
, &pRenderTarget3
);
730 CHECK_CALL(hr
, "CreateRenderTarget", device
, ++refcount
);
731 CHECK_REFCOUNT( pRenderTarget3
, 1);
733 hr
= IDirect3DDevice8_CreateStateBlock(device
, D3DSBT_ALL
, &dStateBlock
);
734 CHECK_CALL(hr
, "CreateStateBlock", device
, refcount
);
736 memset(&d3dpp
, 0, sizeof(d3dpp
));
737 d3dpp
.Windowed
= TRUE
;
738 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
739 d3dpp
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
740 d3dpp
.EnableAutoDepthStencil
= TRUE
;
741 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D16
;
742 hr
= IDirect3DDevice8_CreateAdditionalSwapChain(device
, &d3dpp
, &pSwapChain
);
743 CHECK_CALL(hr
, "CreateAdditionalSwapChain", device
, ++refcount
);
746 /* check implicit back buffer */
747 hr
= IDirect3DSwapChain8_GetBackBuffer(pSwapChain
, 0, 0, &pBackBuffer
);
748 CHECK_CALL(hr
, "GetBackBuffer", device
, ++refcount
);
749 CHECK_REFCOUNT( pSwapChain
, 1);
752 CHECK_SURFACE_CONTAINER(pBackBuffer
, IID_IDirect3DDevice8
, device
);
753 CHECK_REFCOUNT( pBackBuffer
, 1);
754 CHECK_RELEASE_REFCOUNT( pBackBuffer
, 0);
755 CHECK_REFCOUNT(device
, --refcount
);
757 /* The back buffer is released with the swapchain, so AddRef with refcount=0 is fine here. */
758 CHECK_ADDREF_REFCOUNT(pBackBuffer
, 1);
759 CHECK_REFCOUNT(device
, ++refcount
);
760 CHECK_RELEASE_REFCOUNT(pBackBuffer
, 0);
761 CHECK_REFCOUNT(device
, --refcount
);
762 CHECK_RELEASE_REFCOUNT(pBackBuffer
, 0);
763 CHECK_RELEASE_REFCOUNT(pBackBuffer
, 0);
766 CHECK_REFCOUNT( pSwapChain
, 1);
772 /* Vertex buffers can be locked multiple times */
773 hr
= IDirect3DVertexBuffer8_Lock(pVertexBuffer
, 0, 0, &data
, 0);
774 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer8::Lock failed with %#08x\n", hr
);
775 hr
= IDirect3DVertexBuffer8_Lock(pVertexBuffer
, 0, 0, &data
, 0);
776 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer8::Lock failed with %#08x\n", hr
);
777 hr
= IDirect3DVertexBuffer8_Unlock(pVertexBuffer
);
778 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer8::Unlock failed with %#08x\n", hr
);
779 hr
= IDirect3DVertexBuffer8_Unlock(pVertexBuffer
);
780 ok(hr
== D3D_OK
, "IDirect3DVertexBuffer8::Unlock failed with %#08x\n", hr
);
783 /* The implicit render target is not freed if refcount reaches 0.
784 * Otherwise GetRenderTarget would re-allocate it and the pointer would change.*/
785 hr
= IDirect3DDevice8_GetRenderTarget(device
, &pRenderTarget2
);
786 CHECK_CALL(hr
, "GetRenderTarget", device
, ++refcount
);
789 CHECK_RELEASE_REFCOUNT(pRenderTarget2
, 0);
790 ok(pRenderTarget
== pRenderTarget2
, "RenderTarget=%p and RenderTarget2=%p should be the same.\n",
791 pRenderTarget
, pRenderTarget2
);
792 CHECK_REFCOUNT(device
, --refcount
);
793 CHECK_RELEASE_REFCOUNT(pRenderTarget2
, 0);
794 CHECK_RELEASE_REFCOUNT(pRenderTarget2
, 0);
795 pRenderTarget2
= NULL
;
797 pRenderTarget
= NULL
;
800 CHECK_RELEASE(device
, device
, --refcount
);
803 CHECK_RELEASE(pVertexBuffer
, device
, --refcount
);
804 CHECK_RELEASE(pIndexBuffer
, device
, --refcount
);
806 if (dVertexShader
!= ~0u)
807 IDirect3DDevice8_DeleteVertexShader(device
, dVertexShader
);
808 if (dPixelShader
!= ~0u)
809 IDirect3DDevice8_DeletePixelShader(device
, dPixelShader
);
811 CHECK_RELEASE(pTexture
, device
, --refcount
);
812 CHECK_RELEASE(pCubeTexture
, device
, --refcount
);
813 CHECK_RELEASE(pVolumeTexture
, device
, --refcount
);
815 CHECK_RELEASE(pStencilSurface
, device
, --refcount
);
816 CHECK_RELEASE(pImageSurface
, device
, --refcount
);
817 CHECK_RELEASE(pRenderTarget3
, device
, --refcount
);
819 if (dStateBlock
!= ~0u)
820 IDirect3DDevice8_DeleteStateBlock(device
, dStateBlock
);
821 /* This will destroy device - cannot check the refcount here */
823 CHECK_RELEASE_REFCOUNT(pSwapChain
, 0);
824 CHECK_RELEASE_REFCOUNT(d3d
, 0);
825 DestroyWindow(window
);
828 static void test_checkdevicemultisampletype(void)
834 window
= create_window();
835 ok(!!window
, "Failed to create a window.\n");
836 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
837 ok(!!d3d
, "Failed to create a D3D object.\n");
839 if (IDirect3D8_CheckDeviceMultiSampleType(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
840 D3DFMT_X8R8G8B8
, TRUE
, D3DMULTISAMPLE_2_SAMPLES
) == D3DERR_NOTAVAILABLE
)
842 skip("Multisampling not supported for D3DFMT_X8R8G8B8, skipping test.\n");
846 hr
= IDirect3D8_CheckDeviceMultiSampleType(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
847 D3DFMT_UNKNOWN
, TRUE
, D3DMULTISAMPLE_NONE
);
848 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
849 hr
= IDirect3D8_CheckDeviceMultiSampleType(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
850 65536, TRUE
, D3DMULTISAMPLE_NONE
);
851 todo_wine
ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
853 hr
= IDirect3D8_CheckDeviceMultiSampleType(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
854 D3DFMT_X8R8G8B8
, TRUE
, D3DMULTISAMPLE_NONE
);
855 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
856 hr
= IDirect3D8_CheckDeviceMultiSampleType(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
857 D3DFMT_X8R8G8B8
, FALSE
, D3DMULTISAMPLE_NONE
);
858 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
860 hr
= IDirect3D8_CheckDeviceMultiSampleType(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
861 D3DFMT_X8R8G8B8
, TRUE
, D3DMULTISAMPLE_2_SAMPLES
);
862 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
864 /* We assume D3DMULTISAMPLE_15_SAMPLES is never supported in practice. */
865 hr
= IDirect3D8_CheckDeviceMultiSampleType(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
866 D3DFMT_X8R8G8B8
, TRUE
, D3DMULTISAMPLE_15_SAMPLES
);
867 ok(hr
== D3DERR_NOTAVAILABLE
, "Got unexpected hr %#x.\n", hr
);
869 hr
= IDirect3D8_CheckDeviceMultiSampleType(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
870 D3DFMT_X8R8G8B8
, TRUE
, 65536);
871 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
873 hr
= IDirect3D8_CheckDeviceMultiSampleType(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
874 D3DFMT_DXT5
, TRUE
, D3DMULTISAMPLE_2_SAMPLES
);
875 ok(hr
== D3DERR_NOTAVAILABLE
, "Got unexpected hr %#x.\n", hr
);
878 IDirect3D8_Release(d3d
);
879 DestroyWindow(window
);
882 static void test_invalid_multisample(void)
884 IDirect3DDevice8
*device
;
885 IDirect3DSurface8
*rt
;
892 window
= create_window();
893 ok(!!window
, "Failed to create a window.\n");
894 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
895 ok(!!d3d
, "Failed to create a D3D object.\n");
897 if (!(device
= create_device(d3d
, window
, NULL
)))
899 skip("Failed to create a 3D device, skipping test.\n");
903 available
= SUCCEEDED(IDirect3D8_CheckDeviceMultiSampleType(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
904 D3DFMT_X8R8G8B8
, TRUE
, D3DMULTISAMPLE_2_SAMPLES
));
906 hr
= IDirect3DDevice8_CreateRenderTarget(device
, 128, 128,
907 D3DFMT_X8R8G8B8
, D3DMULTISAMPLE_2_SAMPLES
, FALSE
, &rt
);
910 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
911 IDirect3DSurface8_Release(rt
);
915 ok(hr
== D3DERR_NOTAVAILABLE
, "Got unexpected hr %#x.\n", hr
);
918 /* We assume D3DMULTISAMPLE_15_SAMPLES is never supported in practice. */
919 available
= SUCCEEDED(IDirect3D8_CheckDeviceMultiSampleType(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
920 D3DFMT_X8R8G8B8
, TRUE
, D3DMULTISAMPLE_15_SAMPLES
));
921 hr
= IDirect3DDevice8_CreateRenderTarget(device
, 128, 128,
922 D3DFMT_X8R8G8B8
, D3DMULTISAMPLE_15_SAMPLES
, FALSE
, &rt
);
925 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
926 IDirect3DSurface8_Release(rt
);
930 ok(hr
== D3DERR_NOTAVAILABLE
, "Got unexpected hr %#x.\n", hr
);
933 refcount
= IDirect3DDevice8_Release(device
);
934 ok(!refcount
, "Device has %u references left.\n", refcount
);
936 IDirect3D8_Release(d3d
);
937 DestroyWindow(window
);
940 static void test_cursor(void)
942 unsigned int adapter_idx
, adapter_count
, test_idx
;
943 IDirect3DSurface8
*cursor
= NULL
;
944 struct device_desc device_desc
;
945 unsigned int width
, height
;
946 IDirect3DDevice8
*device
;
947 HRESULT expected_hr
, hr
;
956 static const DWORD device_flags
[] = {0, CREATE_DEVICE_FULLSCREEN
};
957 static const SIZE cursor_sizes
[] =
966 window
= create_window();
967 ok(!!window
, "Failed to create a window.\n");
969 ret
= SetCursorPos(50, 50);
970 ok(ret
, "Failed to set cursor position.\n");
973 memset(&info
, 0, sizeof(info
));
974 info
.cbSize
= sizeof(info
);
975 ok(GetCursorInfo(&info
), "GetCursorInfo failed\n");
978 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
979 ok(!!d3d
, "Failed to create a D3D object.\n");
980 if (!(device
= create_device(d3d
, window
, NULL
)))
982 skip("Failed to create a 3D device, skipping test.\n");
986 hr
= IDirect3DDevice8_CreateImageSurface(device
, 32, 32, D3DFMT_A8R8G8B8
, &cursor
);
987 ok(SUCCEEDED(hr
), "Failed to create cursor surface, hr %#x.\n", hr
);
989 /* Initially hidden */
990 ret
= IDirect3DDevice8_ShowCursor(device
, TRUE
);
991 ok(!ret
, "IDirect3DDevice8_ShowCursor returned %d\n", ret
);
993 /* Not enabled without a surface*/
994 ret
= IDirect3DDevice8_ShowCursor(device
, TRUE
);
995 ok(!ret
, "IDirect3DDevice8_ShowCursor returned %d\n", ret
);
998 hr
= IDirect3DDevice8_SetCursorProperties(device
, 0, 0, NULL
);
999 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_SetCursorProperties returned %#08x\n", hr
);
1001 hr
= IDirect3DDevice8_SetCursorProperties(device
, 0, 0, cursor
);
1002 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetCursorProperties returned %#08x\n", hr
);
1004 IDirect3DSurface8_Release(cursor
);
1006 memset(&info
, 0, sizeof(info
));
1007 info
.cbSize
= sizeof(info
);
1008 ok(GetCursorInfo(&info
), "GetCursorInfo failed\n");
1009 ok(info
.flags
& (CURSOR_SHOWING
|CURSOR_SUPPRESSED
), "The gdi cursor is hidden (%08x)\n", info
.flags
);
1010 ok(info
.hCursor
== cur
, "The cursor handle is %p\n", info
.hCursor
); /* unchanged */
1013 ret
= IDirect3DDevice8_ShowCursor(device
, TRUE
);
1014 ok(!ret
, "IDirect3DDevice8_ShowCursor returned %d\n", ret
);
1017 ret
= IDirect3DDevice8_ShowCursor(device
, TRUE
);
1018 ok(ret
, "IDirect3DDevice8_ShowCursor returned %d\n", ret
);
1020 memset(&info
, 0, sizeof(info
));
1021 info
.cbSize
= sizeof(info
);
1022 ok(GetCursorInfo(&info
), "GetCursorInfo failed\n");
1023 ok(info
.flags
& (CURSOR_SHOWING
|CURSOR_SUPPRESSED
), "The gdi cursor is hidden (%08x)\n", info
.flags
);
1024 ok(info
.hCursor
!= cur
, "The cursor handle is %p\n", info
.hCursor
);
1026 /* Cursor dimensions must all be powers of two */
1027 for (test_idx
= 0; test_idx
< ARRAY_SIZE(cursor_sizes
); ++test_idx
)
1029 width
= cursor_sizes
[test_idx
].cx
;
1030 height
= cursor_sizes
[test_idx
].cy
;
1031 hr
= IDirect3DDevice8_CreateImageSurface(device
, width
, height
, D3DFMT_A8R8G8B8
, &cursor
);
1032 ok(hr
== D3D_OK
, "Test %u: CreateImageSurface failed, hr %#x.\n", test_idx
, hr
);
1033 hr
= IDirect3DDevice8_SetCursorProperties(device
, 0, 0, cursor
);
1034 if (width
&& !(width
& (width
- 1)) && height
&& !(height
& (height
- 1)))
1035 expected_hr
= D3D_OK
;
1037 expected_hr
= D3DERR_INVALIDCALL
;
1038 ok(hr
== expected_hr
, "Test %u: Expect SetCursorProperties return %#x, got %#x.\n",
1039 test_idx
, expected_hr
, hr
);
1040 IDirect3DSurface8_Release(cursor
);
1043 refcount
= IDirect3DDevice8_Release(device
);
1044 ok(!refcount
, "Device has %u references left.\n", refcount
);
1046 /* Cursor dimensions must not exceed adapter display mode */
1047 device_desc
.device_window
= window
;
1048 device_desc
.width
= 640;
1049 device_desc
.height
= 480;
1051 adapter_count
= IDirect3D8_GetAdapterCount(d3d
);
1052 for (adapter_idx
= 0; adapter_idx
< adapter_count
; ++adapter_idx
)
1054 for (test_idx
= 0; test_idx
< ARRAY_SIZE(device_flags
); ++test_idx
)
1056 device_desc
.adapter_ordinal
= adapter_idx
;
1057 device_desc
.flags
= device_flags
[test_idx
];
1058 if (!(device
= create_device(d3d
, window
, &device_desc
)))
1060 skip("Adapter %u test %u: Failed to create a D3D device.\n", adapter_idx
, test_idx
);
1064 hr
= IDirect3D8_GetAdapterDisplayMode(d3d
, adapter_idx
, &mode
);
1065 ok(hr
== D3D_OK
, "Adapter %u test %u: GetAdapterDisplayMode failed, hr %#x.\n",
1066 adapter_idx
, test_idx
, hr
);
1068 /* Find the largest width and height that are powers of two and less than the display mode */
1071 while (width
* 2 <= mode
.Width
)
1073 while (height
* 2 <= mode
.Height
)
1076 hr
= IDirect3DDevice8_CreateImageSurface(device
, width
, height
, D3DFMT_A8R8G8B8
, &cursor
);
1077 ok(hr
== D3D_OK
, "Adapter %u test %u: CreateImageSurface failed, hr %#x.\n",
1078 adapter_idx
, test_idx
, hr
);
1079 hr
= IDirect3DDevice8_SetCursorProperties(device
, 0, 0, cursor
);
1080 ok(hr
== D3D_OK
, "Adapter %u test %u: SetCursorProperties failed, hr %#x.\n",
1081 adapter_idx
, test_idx
, hr
);
1082 IDirect3DSurface8_Release(cursor
);
1084 hr
= IDirect3DDevice8_CreateImageSurface(device
, width
* 2, height
, D3DFMT_A8R8G8B8
,
1086 ok(hr
== D3D_OK
, "Adapter %u test %u: CreateImageSurface failed, hr %#x.\n",
1087 adapter_idx
, test_idx
, hr
);
1088 hr
= IDirect3DDevice8_SetCursorProperties(device
, 0, 0, cursor
);
1089 ok(hr
== D3DERR_INVALIDCALL
,
1090 "Adapter %u test %u: Expect SetCursorProperties return %#x, got %#x.\n",
1091 adapter_idx
, test_idx
, D3DERR_INVALIDCALL
, hr
);
1092 IDirect3DSurface8_Release(cursor
);
1094 hr
= IDirect3DDevice8_CreateImageSurface(device
, width
, height
* 2, D3DFMT_A8R8G8B8
,
1096 ok(hr
== D3D_OK
, "Adapter %u test %u: CreateImageSurface failed, hr %#x.\n",
1097 adapter_idx
, test_idx
, hr
);
1098 hr
= IDirect3DDevice8_SetCursorProperties(device
, 0, 0, cursor
);
1099 ok(hr
== D3DERR_INVALIDCALL
,
1100 "Adapter %u test %u: Expect SetCursorProperties return %#x, got %#x.\n",
1101 adapter_idx
, test_idx
, D3DERR_INVALIDCALL
, hr
);
1102 IDirect3DSurface8_Release(cursor
);
1104 refcount
= IDirect3DDevice8_Release(device
);
1105 ok(!refcount
, "Adapter %u: Device has %u references left.\n", adapter_idx
, refcount
);
1109 IDirect3D8_Release(d3d
);
1110 DestroyWindow(window
);
1113 static const POINT
*expect_pos
;
1115 static LRESULT CALLBACK
test_cursor_proc(HWND window
, UINT message
, WPARAM wparam
, LPARAM lparam
)
1117 if (message
== WM_MOUSEMOVE
)
1119 if (expect_pos
&& expect_pos
->x
&& expect_pos
->y
)
1121 POINT p
= {GET_X_LPARAM(lparam
), GET_Y_LPARAM(lparam
)};
1123 ClientToScreen(window
, &p
);
1124 if (expect_pos
->x
== p
.x
&& expect_pos
->y
== p
.y
)
1129 return DefWindowProcA(window
, message
, wparam
, lparam
);
1132 static void test_cursor_pos(void)
1134 IDirect3DSurface8
*cursor
;
1135 IDirect3DDevice8
*device
;
1143 /* Note that we don't check for movement we're not supposed to receive.
1144 * That's because it's hard to distinguish from the user accidentally
1145 * moving the mouse. */
1146 static const POINT points
[] =
1159 wc
.lpfnWndProc
= test_cursor_proc
;
1160 wc
.lpszClassName
= "d3d8_test_cursor_wc";
1161 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
1162 window
= CreateWindowA("d3d8_test_cursor_wc", "d3d8_test", WS_POPUP
| WS_SYSMENU
,
1163 0, 0, 320, 240, NULL
, NULL
, NULL
, NULL
);
1164 ShowWindow(window
, SW_SHOW
);
1165 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
1166 ok(!!d3d8
, "Failed to create a D3D object.\n");
1168 if (!(device
= create_device(d3d8
, window
, NULL
)))
1170 skip("Failed to create a D3D device, skipping tests.\n");
1174 hr
= IDirect3DDevice8_CreateImageSurface(device
, 32, 32, D3DFMT_A8R8G8B8
, &cursor
);
1175 ok(SUCCEEDED(hr
), "Failed to create cursor surface, hr %#x.\n", hr
);
1176 hr
= IDirect3DDevice8_SetCursorProperties(device
, 0, 0, cursor
);
1177 ok(SUCCEEDED(hr
), "Failed to set cursor properties, hr %#x.\n", hr
);
1178 IDirect3DSurface8_Release(cursor
);
1179 ret
= IDirect3DDevice8_ShowCursor(device
, TRUE
);
1180 ok(!ret
, "Failed to show cursor, hr %#x.\n", ret
);
1183 expect_pos
= points
;
1185 ret
= SetCursorPos(50, 50);
1186 ok(ret
, "Failed to set cursor position.\n");
1189 IDirect3DDevice8_SetCursorPosition(device
, 75, 75, 0);
1191 /* SetCursorPosition() eats duplicates. */
1192 IDirect3DDevice8_SetCursorPosition(device
, 75, 75, 0);
1195 ret
= SetCursorPos(100, 100);
1196 ok(ret
, "Failed to set cursor position.\n");
1198 /* Even if the position was set with SetCursorPos(). */
1199 IDirect3DDevice8_SetCursorPosition(device
, 100, 100, 0);
1202 IDirect3DDevice8_SetCursorPosition(device
, 125, 125, 0);
1204 ret
= SetCursorPos(150, 150);
1205 ok(ret
, "Failed to set cursor position.\n");
1207 IDirect3DDevice8_SetCursorPosition(device
, 125, 125, 0);
1210 IDirect3DDevice8_SetCursorPosition(device
, 150, 150, 0);
1212 /* SetCursorPos() doesn't. */
1213 ret
= SetCursorPos(150, 150);
1214 ok(ret
, "Failed to set cursor position.\n");
1217 ok(!expect_pos
->x
&& !expect_pos
->y
, "Didn't receive MOUSEMOVE %u (%d, %d).\n",
1218 (unsigned)(expect_pos
- points
), expect_pos
->x
, expect_pos
->y
);
1220 refcount
= IDirect3DDevice8_Release(device
);
1221 ok(!refcount
, "Device has %u references left.\n", refcount
);
1223 DestroyWindow(window
);
1224 UnregisterClassA("d3d8_test_cursor_wc", GetModuleHandleA(NULL
));
1225 IDirect3D8_Release(d3d8
);
1228 static void test_states(void)
1230 IDirect3DDevice8
*device
;
1236 window
= create_window();
1237 ok(!!window
, "Failed to create a window.\n");
1238 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
1239 ok(!!d3d
, "Failed to create a D3D object.\n");
1240 if (!(device
= create_device(d3d
, window
, NULL
)))
1242 skip("Failed to create a 3D device, skipping test.\n");
1246 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ZVISIBLE
, TRUE
);
1247 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState(D3DRS_ZVISIBLE, TRUE) returned %#08x\n", hr
);
1248 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_ZVISIBLE
, FALSE
);
1249 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetRenderState(D3DRS_ZVISIBLE, FALSE) returned %#08x\n", hr
);
1251 refcount
= IDirect3DDevice8_Release(device
);
1252 ok(!refcount
, "Device has %u references left.\n", refcount
);
1254 IDirect3D8_Release(d3d
);
1255 DestroyWindow(window
);
1258 static void test_shader_versions(void)
1264 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
1265 ok(!!d3d
, "Failed to create a D3D object.\n");
1267 hr
= IDirect3D8_GetDeviceCaps(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, &caps
);
1268 ok(SUCCEEDED(hr
) || hr
== D3DERR_NOTAVAILABLE
, "Failed to get device caps, hr %#x.\n", hr
);
1269 IDirect3D8_Release(d3d
);
1272 skip("No Direct3D support, skipping test.\n");
1276 ok(caps
.VertexShaderVersion
<= D3DVS_VERSION(1,1),
1277 "Got unexpected VertexShaderVersion %#x.\n", caps
.VertexShaderVersion
);
1278 ok(caps
.PixelShaderVersion
<= D3DPS_VERSION(1,4),
1279 "Got unexpected PixelShaderVersion %#x.\n", caps
.PixelShaderVersion
);
1282 static void test_display_formats(void)
1284 D3DDEVTYPE device_type
= D3DDEVTYPE_HAL
;
1285 unsigned int backbuffer
, display
;
1286 unsigned int windowed
, i
;
1287 D3DDISPLAYMODE mode
;
1297 D3DFORMAT alpha_format
;
1303 {"D3DFMT_R5G6B5", D3DFMT_R5G6B5
, 0, TRUE
, TRUE
},
1304 {"D3DFMT_X1R5G5B5", D3DFMT_X1R5G5B5
, D3DFMT_A1R5G5B5
, TRUE
, TRUE
},
1305 {"D3DFMT_A1R5G5B5", D3DFMT_A1R5G5B5
, D3DFMT_A1R5G5B5
, FALSE
, FALSE
},
1306 {"D3DFMT_X8R8G8B8", D3DFMT_X8R8G8B8
, D3DFMT_A8R8G8B8
, TRUE
, TRUE
},
1307 {"D3DFMT_A8R8G8B8", D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
, FALSE
, FALSE
},
1308 {"D3DFMT_UNKNOWN", D3DFMT_UNKNOWN
, 0, FALSE
, FALSE
},
1311 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
1312 ok(!!d3d8
, "Failed to create a D3D object.\n");
1314 for (display
= 0; display
< ARRAY_SIZE(formats
); ++display
)
1316 for (i
= 0, has_modes
= FALSE
; SUCCEEDED(IDirect3D8_EnumAdapterModes(d3d8
, D3DADAPTER_DEFAULT
, i
, &mode
)); ++i
)
1318 if (mode
.Format
== formats
[display
].format
)
1325 for (windowed
= 0; windowed
<= 1; ++windowed
)
1327 for (backbuffer
= 0; backbuffer
< ARRAY_SIZE(formats
); ++backbuffer
)
1329 should_pass
= FALSE
;
1331 if (formats
[display
].display
&& (formats
[display
].windowed
|| !windowed
) && (has_modes
|| windowed
))
1333 D3DFORMAT backbuffer_format
;
1335 if (windowed
&& formats
[backbuffer
].format
== D3DFMT_UNKNOWN
)
1336 backbuffer_format
= formats
[display
].format
;
1338 backbuffer_format
= formats
[backbuffer
].format
;
1340 hr
= IDirect3D8_CheckDeviceFormat(d3d8
, D3DADAPTER_DEFAULT
, device_type
, formats
[display
].format
,
1341 D3DUSAGE_RENDERTARGET
, D3DRTYPE_SURFACE
, backbuffer_format
);
1342 should_pass
= (hr
== D3D_OK
) && (formats
[display
].format
== formats
[backbuffer
].format
1343 || (formats
[display
].alpha_format
1344 && formats
[display
].alpha_format
== formats
[backbuffer
].alpha_format
));
1347 hr
= IDirect3D8_CheckDeviceType(d3d8
, D3DADAPTER_DEFAULT
, device_type
,
1348 formats
[display
].format
, formats
[backbuffer
].format
, windowed
);
1349 ok(SUCCEEDED(hr
) == should_pass
|| broken(SUCCEEDED(hr
) && !has_modes
) /* Win8 64-bit */,
1350 "Got unexpected hr %#x for %s / %s, windowed %#x, should_pass %#x.\n",
1351 hr
, formats
[display
].name
, formats
[backbuffer
].name
, windowed
, should_pass
);
1356 IDirect3D8_Release(d3d8
);
1359 /* Test adapter display modes */
1360 static void test_display_modes(void)
1363 D3DDISPLAYMODE dmode
;
1367 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
1368 ok(!!d3d
, "Failed to create a D3D object.\n");
1370 max_modes
= IDirect3D8_GetAdapterModeCount(d3d
, D3DADAPTER_DEFAULT
);
1372 broken(max_modes
== 0), /* VMware */
1373 "GetAdapterModeCount(D3DADAPTER_DEFAULT) returned 0!\n");
1375 for (i
= 0; i
< max_modes
; ++i
)
1377 res
= IDirect3D8_EnumAdapterModes(d3d
, D3DADAPTER_DEFAULT
, i
, &dmode
);
1378 ok(res
==D3D_OK
, "EnumAdapterModes returned %#08x for mode %u!\n", res
, i
);
1382 ok(dmode
.Format
==D3DFMT_X8R8G8B8
|| dmode
.Format
==D3DFMT_R5G6B5
,
1383 "Unexpected display mode returned for mode %u: %#x\n", i
, dmode
.Format
);
1386 IDirect3D8_Release(d3d
);
1395 static int compare_mode(const void *a
, const void *b
)
1397 const struct mode
*mode_a
= a
;
1398 const struct mode
*mode_b
= b
;
1399 int w
= mode_a
->w
- mode_b
->w
;
1400 int h
= mode_a
->h
- mode_b
->h
;
1401 return abs(w
) >= abs(h
) ? -w
: -h
;
1404 static void test_reset(void)
1406 UINT width
, orig_width
= GetSystemMetrics(SM_CXSCREEN
);
1407 UINT height
, orig_height
= GetSystemMetrics(SM_CYSCREEN
);
1408 IDirect3DDevice8
*device1
= NULL
;
1409 IDirect3DDevice8
*device2
= NULL
;
1410 struct device_desc device_desc
;
1411 D3DDISPLAYMODE d3ddm
, d3ddm2
;
1412 D3DSURFACE_DESC surface_desc
;
1413 D3DPRESENT_PARAMETERS d3dpp
;
1414 IDirect3DSurface8
*surface
;
1415 IDirect3DTexture8
*texture
;
1416 IDirect3DVertexBuffer8
*vb
;
1417 IDirect3DIndexBuffer8
*ib
;
1418 UINT adapter_mode_count
;
1419 D3DLOCKED_RECT lockrect
;
1420 UINT mode_count
= 0;
1423 RECT winrect
, client_rect
;
1434 static const DWORD decl
[] =
1437 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT4
),
1441 struct mode
*modes
= NULL
;
1443 window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
1444 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
1445 ok(!!window
, "Failed to create a window.\n");
1446 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
1447 ok(!!d3d8
, "Failed to create a D3D object.\n");
1449 hr
= IDirect3D8_GetAdapterDisplayMode(d3d8
, D3DADAPTER_DEFAULT
, &d3ddm
);
1450 ok(SUCCEEDED(hr
), "GetAdapterDisplayMode failed, hr %#x.\n", hr
);
1451 adapter_mode_count
= IDirect3D8_GetAdapterModeCount(d3d8
, D3DADAPTER_DEFAULT
);
1452 modes
= HeapAlloc(GetProcessHeap(), 0, sizeof(*modes
) * adapter_mode_count
);
1453 for (i
= 0; i
< adapter_mode_count
; ++i
)
1457 memset(&d3ddm2
, 0, sizeof(d3ddm2
));
1458 hr
= IDirect3D8_EnumAdapterModes(d3d8
, D3DADAPTER_DEFAULT
, i
, &d3ddm2
);
1459 ok(SUCCEEDED(hr
), "EnumAdapterModes failed, hr %#x.\n", hr
);
1461 if (d3ddm2
.Format
!= d3ddm
.Format
)
1464 for (j
= 0; j
< mode_count
; ++j
)
1466 if (modes
[j
].w
== d3ddm2
.Width
&& modes
[j
].h
== d3ddm2
.Height
)
1469 if (j
== mode_count
)
1471 modes
[j
].w
= d3ddm2
.Width
;
1472 modes
[j
].h
= d3ddm2
.Height
;
1476 /* We use them as invalid modes. */
1477 if ((d3ddm2
.Width
== 801 && d3ddm2
.Height
== 600)
1478 || (d3ddm2
.Width
== 32 && d3ddm2
.Height
== 32))
1480 skip("This system supports a screen resolution of %dx%d, not running mode tests.\n",
1481 d3ddm2
.Width
, d3ddm2
.Height
);
1488 skip("Less than 2 modes supported, skipping mode tests.\n");
1492 /* Prefer higher resolutions. */
1493 qsort(modes
, mode_count
, sizeof(*modes
), compare_mode
);
1496 if (modes
[i
].w
== orig_width
&& modes
[i
].h
== orig_height
) ++i
;
1498 device_desc
.adapter_ordinal
= D3DADAPTER_DEFAULT
;
1499 device_desc
.width
= modes
[i
].w
;
1500 device_desc
.height
= modes
[i
].h
;
1501 device_desc
.device_window
= window
;
1502 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
| CREATE_DEVICE_SWVP_ONLY
;
1503 if (!(device1
= create_device(d3d8
, window
, &device_desc
)))
1505 skip("Failed to create a D3D device, skipping tests.\n");
1508 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1509 /* This skips the test on testbot Win 8 VMs. */
1510 if (hr
== D3DERR_DEVICELOST
)
1512 skip("Device is lost.\n");
1515 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1517 hr
= IDirect3DDevice8_GetDeviceCaps(device1
, &caps
);
1518 ok(SUCCEEDED(hr
), "GetDeviceCaps failed, hr %#x.\n", hr
);
1520 width
= GetSystemMetrics(SM_CXSCREEN
);
1521 height
= GetSystemMetrics(SM_CYSCREEN
);
1522 ok(width
== modes
[i
].w
, "Screen width is %u, expected %u.\n", width
, modes
[i
].w
);
1523 ok(height
== modes
[i
].h
, "Screen height is %u, expected %u.\n", height
, modes
[i
].h
);
1525 hr
= IDirect3DDevice8_GetViewport(device1
, &vp
);
1526 ok(SUCCEEDED(hr
), "GetViewport failed, hr %#x.\n", hr
);
1527 ok(vp
.X
== 0, "D3DVIEWPORT->X = %u, expected 0.\n", vp
.X
);
1528 ok(vp
.Y
== 0, "D3DVIEWPORT->Y = %u, expected 0.\n", vp
.Y
);
1529 ok(vp
.Width
== modes
[i
].w
, "D3DVIEWPORT->Width = %u, expected %u.\n", vp
.Width
, modes
[i
].w
);
1530 ok(vp
.Height
== modes
[i
].h
, "D3DVIEWPORT->Height = %u, expected %u.\n", vp
.Height
, modes
[i
].h
);
1531 ok(vp
.MinZ
== 0, "D3DVIEWPORT->MinZ = %.8e, expected 0.\n", vp
.MinZ
);
1532 ok(vp
.MaxZ
== 1, "D3DVIEWPORT->MaxZ = %.8e, expected 1.\n", vp
.MaxZ
);
1537 vp
.Width
= modes
[i
].w
/ 2;
1538 vp
.Height
= modes
[i
].h
/ 2;
1541 hr
= IDirect3DDevice8_SetViewport(device1
, &vp
);
1542 ok(SUCCEEDED(hr
), "SetViewport failed, hr %#x.\n", hr
);
1544 hr
= IDirect3DDevice8_GetRenderState(device1
, D3DRS_LIGHTING
, &value
);
1545 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
1546 ok(!!value
, "Got unexpected value %#x for D3DRS_LIGHTING.\n", value
);
1547 hr
= IDirect3DDevice8_SetRenderState(device1
, D3DRS_LIGHTING
, FALSE
);
1548 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
1550 memset(&d3dpp
, 0, sizeof(d3dpp
));
1551 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1552 d3dpp
.Windowed
= FALSE
;
1553 d3dpp
.BackBufferWidth
= modes
[i
].w
;
1554 d3dpp
.BackBufferHeight
= modes
[i
].h
;
1555 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1556 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1557 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1558 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1559 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1561 hr
= IDirect3DDevice8_GetRenderState(device1
, D3DRS_LIGHTING
, &value
);
1562 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
1563 ok(!!value
, "Got unexpected value %#x for D3DRS_LIGHTING.\n", value
);
1565 memset(&vp
, 0, sizeof(vp
));
1566 hr
= IDirect3DDevice8_GetViewport(device1
, &vp
);
1567 ok(SUCCEEDED(hr
), "GetViewport failed, hr %#x.\n", hr
);
1568 ok(vp
.X
== 0, "D3DVIEWPORT->X = %u, expected 0.\n", vp
.X
);
1569 ok(vp
.Y
== 0, "D3DVIEWPORT->Y = %u, expected 0.\n", vp
.Y
);
1570 ok(vp
.Width
== modes
[i
].w
, "D3DVIEWPORT->Width = %u, expected %u.\n", vp
.Width
, modes
[i
].w
);
1571 ok(vp
.Height
== modes
[i
].h
, "D3DVIEWPORT->Height = %u, expected %u.\n", vp
.Height
, modes
[i
].h
);
1572 ok(vp
.MinZ
== 0, "D3DVIEWPORT->MinZ = %.8e, expected 0.\n", vp
.MinZ
);
1573 ok(vp
.MaxZ
== 1, "D3DVIEWPORT->MaxZ = %.8e, expected 1.\n", vp
.MaxZ
);
1575 width
= GetSystemMetrics(SM_CXSCREEN
);
1576 height
= GetSystemMetrics(SM_CYSCREEN
);
1577 ok(width
== modes
[i
].w
, "Screen width is %u, expected %u.\n", width
, modes
[i
].w
);
1578 ok(height
== modes
[i
].h
, "Screen height is %u, expected %u.\n", height
, modes
[i
].h
);
1580 hr
= IDirect3DDevice8_GetRenderTarget(device1
, &surface
);
1581 ok(SUCCEEDED(hr
), "GetRenderTarget failed, hr %#x.\n", hr
);
1582 hr
= IDirect3DSurface8_GetDesc(surface
, &surface_desc
);
1583 ok(hr
== D3D_OK
, "GetDesc failed, hr %#x.\n", hr
);
1584 ok(surface_desc
.Width
== modes
[i
].w
, "Back buffer width is %u, expected %u.\n",
1585 surface_desc
.Width
, modes
[i
].w
);
1586 ok(surface_desc
.Height
== modes
[i
].h
, "Back buffer height is %u, expected %u.\n",
1587 surface_desc
.Height
, modes
[i
].h
);
1588 IDirect3DSurface8_Release(surface
);
1590 memset(&d3dpp
, 0, sizeof(d3dpp
));
1591 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1592 d3dpp
.Windowed
= TRUE
;
1593 d3dpp
.BackBufferWidth
= 400;
1594 d3dpp
.BackBufferHeight
= 300;
1595 d3dpp
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
1596 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1597 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1598 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1599 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1601 memset(&vp
, 0, sizeof(vp
));
1602 hr
= IDirect3DDevice8_GetViewport(device1
, &vp
);
1603 ok(SUCCEEDED(hr
), "GetViewport failed, hr %#x.\n", hr
);
1604 ok(vp
.X
== 0, "D3DVIEWPORT->X = %u, expected 0.\n", vp
.X
);
1605 ok(vp
.Y
== 0, "D3DVIEWPORT->Y = %u, expected 0.\n", vp
.Y
);
1606 ok(vp
.Width
== 400, "D3DVIEWPORT->Width = %u, expected 400.\n", vp
.Width
);
1607 ok(vp
.Height
== 300, "D3DVIEWPORT->Height = %u, expected 300.\n", vp
.Height
);
1608 ok(vp
.MinZ
== 0, "D3DVIEWPORT->MinZ = %.8e, expected 0.\n", vp
.MinZ
);
1609 ok(vp
.MaxZ
== 1, "D3DVIEWPORT->MaxZ = %.8e, expected 1.\n", vp
.MaxZ
);
1611 width
= GetSystemMetrics(SM_CXSCREEN
);
1612 height
= GetSystemMetrics(SM_CYSCREEN
);
1613 ok(width
== orig_width
, "Screen width is %u, expected %u.\n", width
, orig_width
);
1614 ok(height
== orig_height
, "Screen height is %u, expected %u.\n", height
, orig_height
);
1616 hr
= IDirect3DDevice8_GetRenderTarget(device1
, &surface
);
1617 ok(SUCCEEDED(hr
), "GetRenderTarget failed, hr %#x.\n", hr
);
1618 hr
= IDirect3DSurface8_GetDesc(surface
, &surface_desc
);
1619 ok(hr
== D3D_OK
, "GetDesc failed, hr %#x.\n", hr
);
1620 ok(surface_desc
.Width
== 400, "Back buffer width is %u, expected 400.\n",
1621 surface_desc
.Width
);
1622 ok(surface_desc
.Height
== 300, "Back buffer height is %u, expected 300.\n",
1623 surface_desc
.Height
);
1624 IDirect3DSurface8_Release(surface
);
1626 memset(&devmode
, 0, sizeof(devmode
));
1627 devmode
.dmSize
= sizeof(devmode
);
1628 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
1629 devmode
.dmPelsWidth
= modes
[1].w
;
1630 devmode
.dmPelsHeight
= modes
[1].h
;
1631 ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
1632 ok(ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", ret
);
1633 width
= GetSystemMetrics(SM_CXSCREEN
);
1634 height
= GetSystemMetrics(SM_CYSCREEN
);
1635 ok(width
== modes
[1].w
, "Screen width is %u, expected %u.\n", width
, modes
[1].w
);
1636 ok(height
== modes
[1].h
, "Screen height is %u, expected %u.\n", height
, modes
[1].h
);
1638 d3dpp
.BackBufferWidth
= 500;
1639 d3dpp
.BackBufferHeight
= 400;
1640 d3dpp
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
1641 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1642 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1643 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1644 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1646 width
= GetSystemMetrics(SM_CXSCREEN
);
1647 height
= GetSystemMetrics(SM_CYSCREEN
);
1648 ok(width
== modes
[1].w
, "Screen width is %u, expected %u.\n", width
, modes
[1].w
);
1649 ok(height
== modes
[1].h
, "Screen height is %u, expected %u.\n", height
, modes
[1].h
);
1651 ZeroMemory(&vp
, sizeof(vp
));
1652 hr
= IDirect3DDevice8_GetViewport(device1
, &vp
);
1653 ok(SUCCEEDED(hr
), "GetViewport failed, hr %#x.\n", hr
);
1654 ok(vp
.X
== 0, "D3DVIEWPORT->X = %d.\n", vp
.X
);
1655 ok(vp
.Y
== 0, "D3DVIEWPORT->Y = %d.\n", vp
.Y
);
1656 ok(vp
.Width
== 500, "D3DVIEWPORT->Width = %d.\n", vp
.Width
);
1657 ok(vp
.Height
== 400, "D3DVIEWPORT->Height = %d.\n", vp
.Height
);
1658 ok(vp
.MinZ
== 0, "D3DVIEWPORT->MinZ = %f.\n", vp
.MinZ
);
1659 ok(vp
.MaxZ
== 1, "D3DVIEWPORT->MaxZ = %f.\n", vp
.MaxZ
);
1661 hr
= IDirect3DDevice8_GetRenderTarget(device1
, &surface
);
1662 ok(SUCCEEDED(hr
), "GetRenderTarget failed, hr %#x.\n", hr
);
1663 hr
= IDirect3DSurface8_GetDesc(surface
, &surface_desc
);
1664 ok(hr
== D3D_OK
, "GetDesc failed, hr %#x.\n", hr
);
1665 ok(surface_desc
.Width
== 500, "Back buffer width is %u, expected 500.\n",
1666 surface_desc
.Width
);
1667 ok(surface_desc
.Height
== 400, "Back buffer height is %u, expected 400.\n",
1668 surface_desc
.Height
);
1669 IDirect3DSurface8_Release(surface
);
1671 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
1672 devmode
.dmPelsWidth
= orig_width
;
1673 devmode
.dmPelsHeight
= orig_height
;
1674 ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
1675 ok(ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", ret
);
1676 width
= GetSystemMetrics(SM_CXSCREEN
);
1677 height
= GetSystemMetrics(SM_CYSCREEN
);
1678 ok(width
== orig_width
, "Got screen width %u, expected %u.\n", width
, orig_width
);
1679 ok(height
== orig_height
, "Got screen height %u, expected %u.\n", height
, orig_height
);
1683 winrect
.right
= 200;
1684 winrect
.bottom
= 150;
1685 ok(AdjustWindowRect(&winrect
, WS_OVERLAPPEDWINDOW
, FALSE
), "AdjustWindowRect failed\n");
1686 ok(SetWindowPos(window
, NULL
, 0, 0,
1687 winrect
.right
-winrect
.left
,
1688 winrect
.bottom
-winrect
.top
,
1689 SWP_NOMOVE
|SWP_NOZORDER
),
1690 "SetWindowPos failed\n");
1692 /* Windows 10 gives us a different size than we requested with some DPI scaling settings (e.g. 172%). */
1693 GetClientRect(window
, &client_rect
);
1695 memset(&d3dpp
, 0, sizeof(d3dpp
));
1696 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1697 d3dpp
.Windowed
= TRUE
;
1698 d3dpp
.BackBufferWidth
= 0;
1699 d3dpp
.BackBufferHeight
= 0;
1700 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1701 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1702 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1703 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1704 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1706 ok(!d3dpp
.BackBufferWidth
, "Got unexpected BackBufferWidth %u.\n", d3dpp
.BackBufferWidth
);
1707 ok(!d3dpp
.BackBufferHeight
, "Got unexpected BackBufferHeight %u.\n", d3dpp
.BackBufferHeight
);
1708 ok(d3dpp
.BackBufferFormat
== d3ddm
.Format
, "Got unexpected BackBufferFormat %#x, expected %#x.\n",
1709 d3dpp
.BackBufferFormat
, d3ddm
.Format
);
1710 ok(d3dpp
.BackBufferCount
== 1, "Got unexpected BackBufferCount %u.\n", d3dpp
.BackBufferCount
);
1711 ok(!d3dpp
.MultiSampleType
, "Got unexpected MultiSampleType %u.\n", d3dpp
.MultiSampleType
);
1712 ok(d3dpp
.SwapEffect
== D3DSWAPEFFECT_DISCARD
, "Got unexpected SwapEffect %#x.\n", d3dpp
.SwapEffect
);
1713 ok(!d3dpp
.hDeviceWindow
, "Got unexpected hDeviceWindow %p.\n", d3dpp
.hDeviceWindow
);
1714 ok(d3dpp
.Windowed
, "Got unexpected Windowed %#x.\n", d3dpp
.Windowed
);
1715 ok(!d3dpp
.EnableAutoDepthStencil
, "Got unexpected EnableAutoDepthStencil %#x.\n", d3dpp
.EnableAutoDepthStencil
);
1716 ok(!d3dpp
.AutoDepthStencilFormat
, "Got unexpected AutoDepthStencilFormat %#x.\n", d3dpp
.AutoDepthStencilFormat
);
1717 ok(!d3dpp
.Flags
, "Got unexpected Flags %#x.\n", d3dpp
.Flags
);
1718 ok(!d3dpp
.FullScreen_RefreshRateInHz
, "Got unexpected FullScreen_RefreshRateInHz %u.\n",
1719 d3dpp
.FullScreen_RefreshRateInHz
);
1720 ok(!d3dpp
.FullScreen_PresentationInterval
, "Got unexpected FullScreen_PresentationInterval %#x.\n",
1721 d3dpp
.FullScreen_PresentationInterval
);
1723 memset(&vp
, 0, sizeof(vp
));
1724 hr
= IDirect3DDevice8_GetViewport(device1
, &vp
);
1725 ok(SUCCEEDED(hr
), "GetViewport failed, hr %#x.\n", hr
);
1728 ok(vp
.X
== 0, "D3DVIEWPORT->X = %u, expected 0.\n", vp
.X
);
1729 ok(vp
.Y
== 0, "D3DVIEWPORT->Y = %u, expected 0.\n", vp
.Y
);
1730 ok(vp
.Width
== client_rect
.right
, "D3DVIEWPORT->Width = %d, expected %d\n",
1731 vp
.Width
, client_rect
.right
);
1732 ok(vp
.Height
== client_rect
.bottom
, "D3DVIEWPORT->Height = %d, expected %d\n",
1733 vp
.Height
, client_rect
.bottom
);
1734 ok(vp
.MinZ
== 0, "D3DVIEWPORT->MinZ = %.8e, expected 0.\n", vp
.MinZ
);
1735 ok(vp
.MaxZ
== 1, "D3DVIEWPORT->MaxZ = %.8e, expected 1.\n", vp
.MaxZ
);
1738 hr
= IDirect3DDevice8_GetRenderTarget(device1
, &surface
);
1739 ok(SUCCEEDED(hr
), "GetRenderTarget failed, hr %#x.\n", hr
);
1740 hr
= IDirect3DSurface8_GetDesc(surface
, &surface_desc
);
1741 ok(hr
== D3D_OK
, "GetDesc failed, hr %#x.\n", hr
);
1742 ok(surface_desc
.Format
== d3ddm
.Format
, "Got unexpected Format %#x, expected %#x.\n",
1743 surface_desc
.Format
, d3ddm
.Format
);
1744 ok(!surface_desc
.MultiSampleType
, "Got unexpected MultiSampleType %u.\n", d3dpp
.MultiSampleType
);
1745 ok(surface_desc
.Width
== client_rect
.right
,
1746 "Back buffer width is %u, expected %d.\n", surface_desc
.Width
, client_rect
.right
);
1747 ok(surface_desc
.Height
== client_rect
.bottom
,
1748 "Back buffer height is %u, expected %d.\n", surface_desc
.Height
, client_rect
.bottom
);
1749 IDirect3DSurface8_Release(surface
);
1751 memset(&d3dpp
, 0, sizeof(d3dpp
));
1752 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1753 d3dpp
.Windowed
= TRUE
;
1754 d3dpp
.BackBufferWidth
= 400;
1755 d3dpp
.BackBufferHeight
= 300;
1756 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1758 /* Reset fails if there is a resource in the default pool. */
1759 hr
= IDirect3DDevice8_CreateTexture(device1
, 16, 16, 1, 0, D3DFMT_R5G6B5
, D3DPOOL_DEFAULT
, &texture
);
1760 ok(SUCCEEDED(hr
), "CreateTexture failed, hr %#x.\n", hr
);
1761 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1762 ok(hr
== D3DERR_DEVICELOST
, "Reset returned %#x, expected %#x.\n", hr
, D3DERR_DEVICELOST
);
1763 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1764 ok(hr
== D3DERR_DEVICENOTRESET
, "TestCooperativeLevel returned %#x, expected %#x.\n", hr
, D3DERR_DEVICENOTRESET
);
1765 IDirect3DTexture8_Release(texture
);
1766 /* Reset again to get the device out of the lost state. */
1767 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1768 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1769 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1770 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1772 if (caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP
)
1774 IDirect3DVolumeTexture8
*volume_texture
;
1776 hr
= IDirect3DDevice8_CreateVolumeTexture(device1
, 16, 16, 4, 1, 0,
1777 D3DFMT_R5G6B5
, D3DPOOL_DEFAULT
, &volume_texture
);
1778 ok(SUCCEEDED(hr
), "CreateVolumeTexture failed, hr %#x.\n", hr
);
1779 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1780 ok(hr
== D3DERR_DEVICELOST
, "Reset returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
1781 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1782 ok(hr
== D3DERR_DEVICENOTRESET
, "TestCooperativeLevel returned %#x, expected %#x.\n",
1783 hr
, D3DERR_DEVICENOTRESET
);
1784 IDirect3DVolumeTexture8_Release(volume_texture
);
1785 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1786 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1787 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1788 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1792 skip("Volume textures not supported.\n");
1795 /* Test with DEFAULT pool resources bound but otherwise not referenced. */
1796 hr
= IDirect3DDevice8_CreateVertexBuffer(device1
, 16, 0,
1797 D3DFVF_XYZ
, D3DPOOL_DEFAULT
, &vb
);
1798 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
1799 hr
= IDirect3DDevice8_SetStreamSource(device1
, 0, vb
, 16);
1800 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
1801 refcount
= IDirect3DVertexBuffer8_Release(vb
);
1802 ok(!refcount
, "Unexpected refcount %u.\n", refcount
);
1803 hr
= IDirect3DDevice8_CreateIndexBuffer(device1
, 16, 0,
1804 D3DFMT_INDEX16
, D3DPOOL_DEFAULT
, &ib
);
1805 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
1806 hr
= IDirect3DDevice8_SetIndices(device1
, ib
, 0);
1807 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
1808 refcount
= IDirect3DIndexBuffer8_Release(ib
);
1809 ok(!refcount
, "Unexpected refcount %u.\n", refcount
);
1810 hr
= IDirect3DDevice8_CreateTexture(device1
, 16, 16, 0, 0,
1811 D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &texture
);
1812 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
1813 hr
= IDirect3DDevice8_SetTexture(device1
, i
, (IDirect3DBaseTexture8
*)texture
);
1814 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
1816 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1817 ok(hr
== D3DERR_DEVICELOST
, "Got unexpected hr %#x.\n", hr
);
1818 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1819 ok(hr
== D3DERR_DEVICENOTRESET
, "Got unexpected hr %#x.\n", hr
);
1821 /* Crashes on Windows. */
1824 hr
= IDirect3DDevice8_GetIndices(device1
, &ib
, &i
);
1825 todo_wine
ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
1827 refcount
= IDirect3DTexture8_Release(texture
);
1828 ok(!refcount
, "Unexpected refcount %u.\n", refcount
);
1830 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1831 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
1832 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1833 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
1835 /* Scratch, sysmem and managed pool resources are fine. */
1836 hr
= IDirect3DDevice8_CreateTexture(device1
, 16, 16, 1, 0, D3DFMT_R5G6B5
, D3DPOOL_SCRATCH
, &texture
);
1837 ok(SUCCEEDED(hr
), "CreateTexture failed, hr %#x.\n", hr
);
1838 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1839 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1840 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1841 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1842 IDirect3DTexture8_Release(texture
);
1844 hr
= IDirect3DDevice8_CreateTexture(device1
, 16, 16, 1, 0, D3DFMT_R5G6B5
, D3DPOOL_SYSTEMMEM
, &texture
);
1845 ok(SUCCEEDED(hr
), "CreateTexture failed, hr %#x.\n", hr
);
1846 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1847 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1848 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1849 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1850 IDirect3DTexture8_Release(texture
);
1852 hr
= IDirect3DDevice8_CreateVertexBuffer(device1
, 16, 0,
1853 D3DFVF_XYZ
, D3DPOOL_SYSTEMMEM
, &vb
);
1854 ok(hr
== D3D_OK
, "Failed to create vertex buffer, hr %#x.\n", hr
);
1855 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1856 ok(hr
== D3D_OK
, "Failed to reset device, hr %#x.\n", hr
);
1857 IDirect3DVertexBuffer8_Release(vb
);
1859 hr
= IDirect3DDevice8_CreateIndexBuffer(device1
, 16, 0,
1860 D3DFMT_INDEX16
, D3DPOOL_SYSTEMMEM
, &ib
);
1861 ok(hr
== D3D_OK
, "Failed to create index buffer, hr %#x.\n", hr
);
1862 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1863 ok(hr
== D3D_OK
, "Failed to reset device, hr %#x.\n", hr
);
1864 IDirect3DIndexBuffer8_Release(ib
);
1866 /* The depth stencil should get reset to the auto depth stencil when present. */
1867 hr
= IDirect3DDevice8_SetRenderTarget(device1
, NULL
, NULL
);
1868 ok(SUCCEEDED(hr
), "SetRenderTarget failed, hr %#x.\n", hr
);
1870 hr
= IDirect3DDevice8_GetDepthStencilSurface(device1
, &surface
);
1871 ok(hr
== D3DERR_NOTFOUND
, "GetDepthStencilSurface returned %#x, expected %#x.\n", hr
, D3DERR_NOTFOUND
);
1872 ok(!surface
, "Depth / stencil buffer should be NULL.\n");
1874 d3dpp
.EnableAutoDepthStencil
= TRUE
;
1875 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
1876 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1877 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1879 hr
= IDirect3DDevice8_GetDepthStencilSurface(device1
, &surface
);
1880 ok(SUCCEEDED(hr
), "GetDepthStencilSurface failed, hr %#x.\n", hr
);
1881 ok(!!surface
, "Depth / stencil buffer should not be NULL.\n");
1882 if (surface
) IDirect3DSurface8_Release(surface
);
1884 d3dpp
.EnableAutoDepthStencil
= FALSE
;
1885 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1886 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1888 hr
= IDirect3DDevice8_GetDepthStencilSurface(device1
, &surface
);
1889 ok(hr
== D3DERR_NOTFOUND
, "GetDepthStencilSurface returned %#x, expected %#x.\n", hr
, D3DERR_NOTFOUND
);
1890 ok(!surface
, "Depth / stencil buffer should be NULL.\n");
1892 /* Will a sysmem or scratch resource survive while locked? */
1893 hr
= IDirect3DDevice8_CreateTexture(device1
, 16, 16, 1, 0, D3DFMT_R5G6B5
, D3DPOOL_SYSTEMMEM
, &texture
);
1894 ok(SUCCEEDED(hr
), "CreateTexture failed, hr %#x.\n", hr
);
1895 hr
= IDirect3DTexture8_LockRect(texture
, 0, &lockrect
, NULL
, D3DLOCK_DISCARD
);
1896 ok(SUCCEEDED(hr
), "LockRect failed, hr %#x.\n", hr
);
1897 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1898 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1899 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1900 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1901 IDirect3DTexture8_UnlockRect(texture
, 0);
1902 IDirect3DTexture8_Release(texture
);
1904 hr
= IDirect3DDevice8_CreateTexture(device1
, 16, 16, 1, 0, D3DFMT_R5G6B5
, D3DPOOL_SCRATCH
, &texture
);
1905 ok(SUCCEEDED(hr
), "CreateTexture failed, hr %#x.\n", hr
);
1906 hr
= IDirect3DTexture8_LockRect(texture
, 0, &lockrect
, NULL
, D3DLOCK_DISCARD
);
1907 ok(SUCCEEDED(hr
), "LockRect failed, hr %#x.\n", hr
);
1908 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1909 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1910 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1911 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1912 IDirect3DTexture8_UnlockRect(texture
, 0);
1913 IDirect3DTexture8_Release(texture
);
1915 hr
= IDirect3DDevice8_CreateTexture(device1
, 16, 16, 1, 0, D3DFMT_R5G6B5
, D3DPOOL_MANAGED
, &texture
);
1916 ok(SUCCEEDED(hr
), "CreateTexture failed, hr %#x.\n", hr
);
1917 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1918 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1919 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1920 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1921 IDirect3DTexture8_Release(texture
);
1923 /* A reference held to an implicit surface causes failures as well. */
1924 hr
= IDirect3DDevice8_GetBackBuffer(device1
, 0, D3DBACKBUFFER_TYPE_MONO
, &surface
);
1925 ok(SUCCEEDED(hr
), "GetBackBuffer failed, hr %#x.\n", hr
);
1926 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1927 ok(hr
== D3DERR_DEVICELOST
, "Reset returned %#x, expected %#x.\n", hr
, D3DERR_DEVICELOST
);
1928 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1929 ok(hr
== D3DERR_DEVICENOTRESET
, "TestCooperativeLevel returned %#x, expected %#x.\n", hr
, D3DERR_DEVICENOTRESET
);
1930 IDirect3DSurface8_Release(surface
);
1931 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1932 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1933 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1934 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1936 /* Shaders are fine as well. */
1937 hr
= IDirect3DDevice8_CreateVertexShader(device1
, decl
, simple_vs
, &shader
, 0);
1938 ok(SUCCEEDED(hr
), "CreateVertexShader failed, hr %#x.\n", hr
);
1939 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1940 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
1941 hr
= IDirect3DDevice8_DeleteVertexShader(device1
, shader
);
1942 ok(SUCCEEDED(hr
), "DeleteVertexShader failed, hr %#x.\n", hr
);
1944 /* Try setting invalid modes. */
1945 memset(&d3dpp
, 0, sizeof(d3dpp
));
1946 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1947 d3dpp
.Windowed
= FALSE
;
1948 d3dpp
.BackBufferWidth
= 32;
1949 d3dpp
.BackBufferHeight
= 32;
1950 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1951 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1952 ok(hr
== D3DERR_INVALIDCALL
, "Reset returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
1953 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1954 ok(hr
== D3DERR_DEVICENOTRESET
, "TestCooperativeLevel returned %#x, expected %#x.\n", hr
, D3DERR_DEVICENOTRESET
);
1956 memset(&d3dpp
, 0, sizeof(d3dpp
));
1957 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1958 d3dpp
.Windowed
= FALSE
;
1959 d3dpp
.BackBufferWidth
= 801;
1960 d3dpp
.BackBufferHeight
= 600;
1961 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1962 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1963 ok(hr
== D3DERR_INVALIDCALL
, "Reset returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
1964 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1965 ok(hr
== D3DERR_DEVICENOTRESET
, "TestCooperativeLevel returned %#x, expected %#x.\n", hr
, D3DERR_DEVICENOTRESET
);
1967 memset(&d3dpp
, 0, sizeof(d3dpp
));
1968 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1969 d3dpp
.Windowed
= FALSE
;
1970 d3dpp
.BackBufferWidth
= 0;
1971 d3dpp
.BackBufferHeight
= 0;
1972 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1973 hr
= IDirect3DDevice8_Reset(device1
, &d3dpp
);
1974 ok(hr
== D3DERR_INVALIDCALL
, "Reset returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
1975 hr
= IDirect3DDevice8_TestCooperativeLevel(device1
);
1976 ok(hr
== D3DERR_DEVICENOTRESET
, "TestCooperativeLevel returned %#x, expected %#x.\n", hr
, D3DERR_DEVICENOTRESET
);
1978 hr
= IDirect3D8_GetAdapterDisplayMode(d3d8
, D3DADAPTER_DEFAULT
, &d3ddm
);
1979 ok(SUCCEEDED(hr
), "GetAdapterDisplayMode failed, hr %#x.\n", hr
);
1981 memset(&d3dpp
, 0, sizeof(d3dpp
));
1982 d3dpp
.Windowed
= TRUE
;
1983 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
1984 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
1985 d3dpp
.EnableAutoDepthStencil
= FALSE
;
1986 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
1988 hr
= IDirect3D8_CreateDevice(d3d8
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
1989 window
, D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &device2
);
1992 skip("Failed to create device, hr %#x.\n", hr
);
1996 hr
= IDirect3DDevice8_TestCooperativeLevel(device2
);
1997 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed, hr %#x.\n", hr
);
1999 d3dpp
.Windowed
= TRUE
;
2000 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
2001 d3dpp
.BackBufferWidth
= 400;
2002 d3dpp
.BackBufferHeight
= 300;
2003 d3dpp
.BackBufferFormat
= d3ddm
.Format
;
2004 d3dpp
.EnableAutoDepthStencil
= TRUE
;
2005 d3dpp
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
2007 hr
= IDirect3DDevice8_Reset(device2
, &d3dpp
);
2008 ok(SUCCEEDED(hr
), "Reset failed, hr %#x.\n", hr
);
2012 hr
= IDirect3DDevice8_GetDepthStencilSurface(device2
, &surface
);
2013 ok(SUCCEEDED(hr
), "GetDepthStencilSurface failed, hr %#x.\n", hr
);
2014 ok(!!surface
, "Depth / stencil buffer should not be NULL.\n");
2016 IDirect3DSurface8_Release(surface
);
2019 HeapFree(GetProcessHeap(), 0, modes
);
2021 IDirect3DDevice8_Release(device2
);
2023 IDirect3DDevice8_Release(device1
);
2024 IDirect3D8_Release(d3d8
);
2025 DestroyWindow(window
);
2028 static void test_scene(void)
2030 IDirect3DDevice8
*device
;
2036 window
= create_window();
2037 ok(!!window
, "Failed to create a window.\n");
2038 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
2039 ok(!!d3d
, "Failed to create a D3D object.\n");
2040 if (!(device
= create_device(d3d
, window
, NULL
)))
2042 skip("Failed to create a 3D device, skipping test.\n");
2046 /* Test an EndScene without BeginScene. Should return an error */
2047 hr
= IDirect3DDevice8_EndScene(device
);
2048 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_EndScene returned %#08x\n", hr
);
2050 /* Test a normal BeginScene / EndScene pair, this should work */
2051 hr
= IDirect3DDevice8_BeginScene(device
);
2052 ok(hr
== D3D_OK
, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr
);
2053 hr
= IDirect3DDevice8_EndScene(device
);
2054 ok(hr
== D3D_OK
, "IDirect3DDevice8_EndScene failed with %#08x\n", hr
);
2056 /* Test another EndScene without having begun a new scene. Should return an error */
2057 hr
= IDirect3DDevice8_EndScene(device
);
2058 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_EndScene returned %#08x\n", hr
);
2060 /* Two nested BeginScene and EndScene calls */
2061 hr
= IDirect3DDevice8_BeginScene(device
);
2062 ok(hr
== D3D_OK
, "IDirect3DDevice8_BeginScene failed with %#08x\n", hr
);
2063 hr
= IDirect3DDevice8_BeginScene(device
);
2064 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_BeginScene returned %#08x\n", hr
);
2065 hr
= IDirect3DDevice8_EndScene(device
);
2066 ok(hr
== D3D_OK
, "IDirect3DDevice8_EndScene failed with %#08x\n", hr
);
2067 hr
= IDirect3DDevice8_EndScene(device
);
2068 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_EndScene returned %#08x\n", hr
);
2070 /* StretchRect does not exit in Direct3D8, so no equivalent to the d3d9 stretchrect tests */
2072 refcount
= IDirect3DDevice8_Release(device
);
2073 ok(!refcount
, "Device has %u references left.\n", refcount
);
2075 IDirect3D8_Release(d3d
);
2076 DestroyWindow(window
);
2079 static void test_shader(void)
2081 DWORD hPixelShader
= 0, hVertexShader
= 0;
2082 DWORD hPixelShader2
= 0, hVertexShader2
= 0;
2085 DWORD fvf
= D3DFVF_XYZ
| D3DFVF_DIFFUSE
;
2086 IDirect3DDevice8
*device
;
2094 static DWORD dwVertexDecl
[] =
2097 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT3
),
2100 DWORD decl_normal_float2
[] =
2103 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT3
), /* D3DVSDE_POSITION, Register v0 */
2104 D3DVSD_REG(D3DVSDE_NORMAL
, D3DVSDT_FLOAT2
), /* D3DVSDE_NORMAL, Register v1 */
2107 DWORD decl_normal_float4
[] =
2110 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT3
), /* D3DVSDE_POSITION, Register v0 */
2111 D3DVSD_REG(D3DVSDE_NORMAL
, D3DVSDT_FLOAT4
), /* D3DVSDE_NORMAL, Register v1 */
2114 DWORD decl_normal_d3dcolor
[] =
2117 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT3
), /* D3DVSDE_POSITION, Register v0 */
2118 D3DVSD_REG(D3DVSDE_NORMAL
, D3DVSDT_D3DCOLOR
),/* D3DVSDE_NORMAL, Register v1 */
2121 const DWORD vertex_decl_size
= sizeof(dwVertexDecl
);
2122 const DWORD simple_vs_size
= sizeof(simple_vs
);
2123 const DWORD simple_ps_size
= sizeof(simple_ps
);
2125 window
= create_window();
2126 ok(!!window
, "Failed to create a window.\n");
2127 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
2128 ok(!!d3d
, "Failed to create a D3D object.\n");
2129 if (!(device
= create_device(d3d
, window
, NULL
)))
2131 skip("Failed to create a 3D device, skipping test.\n");
2135 IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
2137 /* Test setting and retrieving a FVF */
2138 hr
= IDirect3DDevice8_SetVertexShader(device
, fvf
);
2139 ok(SUCCEEDED(hr
), "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr
);
2140 hr
= IDirect3DDevice8_GetVertexShader(device
, &hTempHandle
);
2141 ok(SUCCEEDED(hr
), "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr
);
2142 ok(hTempHandle
== fvf
, "Vertex shader %#08x is set, expected %#08x\n", hTempHandle
, fvf
);
2144 /* First create a vertex shader */
2145 hr
= IDirect3DDevice8_SetVertexShader(device
, 0);
2146 ok(SUCCEEDED(hr
), "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr
);
2147 hr
= IDirect3DDevice8_CreateVertexShader(device
, dwVertexDecl
, simple_vs
, &hVertexShader
, 0);
2148 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
2149 /* Msdn says that the new vertex shader is set immediately. This is wrong, apparently */
2150 hr
= IDirect3DDevice8_GetVertexShader(device
, &hTempHandle
);
2151 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr
);
2152 ok(hTempHandle
== 0, "Vertex Shader %d is set, expected shader %d\n", hTempHandle
, 0);
2153 /* Assign the shader, then verify that GetVertexShader works */
2154 hr
= IDirect3DDevice8_SetVertexShader(device
, hVertexShader
);
2155 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr
);
2156 hr
= IDirect3DDevice8_GetVertexShader(device
, &hTempHandle
);
2157 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr
);
2158 ok(hTempHandle
== hVertexShader
, "Vertex Shader %d is set, expected shader %d\n", hTempHandle
, hVertexShader
);
2159 /* Verify that we can retrieve the declaration */
2160 hr
= IDirect3DDevice8_GetVertexShaderDeclaration(device
, hVertexShader
, NULL
, &data_size
);
2161 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShaderDeclaration returned %#08x\n", hr
);
2162 ok(data_size
== vertex_decl_size
, "Got data_size %u, expected %u\n", data_size
, vertex_decl_size
);
2163 data
= HeapAlloc(GetProcessHeap(), 0, vertex_decl_size
);
2165 hr
= IDirect3DDevice8_GetVertexShaderDeclaration(device
, hVertexShader
, data
, &data_size
);
2166 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_GetVertexShaderDeclaration returned (%#08x), "
2167 "expected D3DERR_INVALIDCALL\n", hr
);
2168 ok(data_size
== 1, "Got data_size %u, expected 1\n", data_size
);
2169 data_size
= vertex_decl_size
;
2170 hr
= IDirect3DDevice8_GetVertexShaderDeclaration(device
, hVertexShader
, data
, &data_size
);
2171 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShaderDeclaration returned %#08x\n", hr
);
2172 ok(data_size
== vertex_decl_size
, "Got data_size %u, expected %u\n", data_size
, vertex_decl_size
);
2173 ok(!memcmp(data
, dwVertexDecl
, vertex_decl_size
), "data not equal to shader declaration\n");
2174 HeapFree(GetProcessHeap(), 0, data
);
2175 /* Verify that we can retrieve the shader function */
2176 hr
= IDirect3DDevice8_GetVertexShaderFunction(device
, hVertexShader
, NULL
, &data_size
);
2177 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShaderFunction returned %#08x\n", hr
);
2178 ok(data_size
== simple_vs_size
, "Got data_size %u, expected %u\n", data_size
, simple_vs_size
);
2179 data
= HeapAlloc(GetProcessHeap(), 0, simple_vs_size
);
2181 hr
= IDirect3DDevice8_GetVertexShaderFunction(device
, hVertexShader
, data
, &data_size
);
2182 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_GetVertexShaderFunction returned (%#08x), "
2183 "expected D3DERR_INVALIDCALL\n", hr
);
2184 ok(data_size
== 1, "Got data_size %u, expected 1\n", data_size
);
2185 data_size
= simple_vs_size
;
2186 hr
= IDirect3DDevice8_GetVertexShaderFunction(device
, hVertexShader
, data
, &data_size
);
2187 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShaderFunction returned %#08x\n", hr
);
2188 ok(data_size
== simple_vs_size
, "Got data_size %u, expected %u\n", data_size
, simple_vs_size
);
2189 ok(!memcmp(data
, simple_vs
, simple_vs_size
), "data not equal to shader function\n");
2190 HeapFree(GetProcessHeap(), 0, data
);
2191 /* Delete the assigned shader. This is supposed to work */
2192 hr
= IDirect3DDevice8_DeleteVertexShader(device
, hVertexShader
);
2193 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr
);
2194 /* The shader should be unset now */
2195 hr
= IDirect3DDevice8_GetVertexShader(device
, &hTempHandle
);
2196 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr
);
2197 ok(hTempHandle
== 0, "Vertex Shader %d is set, expected shader %d\n", hTempHandle
, 0);
2199 /* Test a broken declaration. 3DMark2001 tries to use normals with 2 components
2200 * First try the fixed function shader function, then a custom one
2202 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl_normal_float2
, 0, &hVertexShader
, 0);
2203 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
2204 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl_normal_float4
, 0, &hVertexShader
, 0);
2205 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
2206 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl_normal_d3dcolor
, 0, &hVertexShader
, 0);
2207 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
2209 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl_normal_float2
, simple_vs
, &hVertexShader
, 0);
2210 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
2211 IDirect3DDevice8_DeleteVertexShader(device
, hVertexShader
);
2213 if (caps
.PixelShaderVersion
>= D3DPS_VERSION(1, 0))
2215 /* The same with a pixel shader */
2216 hr
= IDirect3DDevice8_CreatePixelShader(device
, simple_ps
, &hPixelShader
);
2217 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr
);
2218 /* Msdn says that the new pixel shader is set immediately. This is wrong, apparently */
2219 hr
= IDirect3DDevice8_GetPixelShader(device
, &hTempHandle
);
2220 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr
);
2221 ok(hTempHandle
== 0, "Pixel Shader %d is set, expected shader %d\n", hTempHandle
, 0);
2222 /* Assign the shader, then verify that GetPixelShader works */
2223 hr
= IDirect3DDevice8_SetPixelShader(device
, hPixelShader
);
2224 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetPixelShader returned %#08x\n", hr
);
2225 hr
= IDirect3DDevice8_GetPixelShader(device
, &hTempHandle
);
2226 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr
);
2227 ok(hTempHandle
== hPixelShader
, "Pixel Shader %d is set, expected shader %d\n", hTempHandle
, hPixelShader
);
2228 /* Verify that we can retrieve the shader function */
2229 hr
= IDirect3DDevice8_GetPixelShaderFunction(device
, hPixelShader
, NULL
, &data_size
);
2230 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetPixelShaderFunction returned %#08x\n", hr
);
2231 ok(data_size
== simple_ps_size
, "Got data_size %u, expected %u\n", data_size
, simple_ps_size
);
2232 data
= HeapAlloc(GetProcessHeap(), 0, simple_ps_size
);
2234 hr
= IDirect3DDevice8_GetPixelShaderFunction(device
, hPixelShader
, data
, &data_size
);
2235 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_GetPixelShaderFunction returned (%#08x), "
2236 "expected D3DERR_INVALIDCALL\n", hr
);
2237 ok(data_size
== 1, "Got data_size %u, expected 1\n", data_size
);
2238 data_size
= simple_ps_size
;
2239 hr
= IDirect3DDevice8_GetPixelShaderFunction(device
, hPixelShader
, data
, &data_size
);
2240 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetPixelShaderFunction returned %#08x\n", hr
);
2241 ok(data_size
== simple_ps_size
, "Got data_size %u, expected %u\n", data_size
, simple_ps_size
);
2242 ok(!memcmp(data
, simple_ps
, simple_ps_size
), "data not equal to shader function\n");
2243 HeapFree(GetProcessHeap(), 0, data
);
2244 /* Delete the assigned shader. This is supposed to work */
2245 hr
= IDirect3DDevice8_DeletePixelShader(device
, hPixelShader
);
2246 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr
);
2247 /* The shader should be unset now */
2248 hr
= IDirect3DDevice8_GetPixelShader(device
, &hTempHandle
);
2249 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr
);
2250 ok(hTempHandle
== 0, "Pixel Shader %d is set, expected shader %d\n", hTempHandle
, 0);
2252 /* What happens if a non-bound shader is deleted? */
2253 hr
= IDirect3DDevice8_CreatePixelShader(device
, simple_ps
, &hPixelShader
);
2254 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr
);
2255 hr
= IDirect3DDevice8_CreatePixelShader(device
, simple_ps
, &hPixelShader2
);
2256 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr
);
2258 hr
= IDirect3DDevice8_SetPixelShader(device
, hPixelShader
);
2259 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetPixelShader returned %#08x\n", hr
);
2260 hr
= IDirect3DDevice8_DeletePixelShader(device
, hPixelShader2
);
2261 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr
);
2262 hr
= IDirect3DDevice8_GetPixelShader(device
, &hTempHandle
);
2263 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetPixelShader returned %#08x\n", hr
);
2264 ok(hTempHandle
== hPixelShader
, "Pixel Shader %d is set, expected shader %d\n", hTempHandle
, hPixelShader
);
2265 hr
= IDirect3DDevice8_DeletePixelShader(device
, hPixelShader
);
2266 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr
);
2268 /* Check for double delete. */
2269 hr
= IDirect3DDevice8_DeletePixelShader(device
, hPixelShader2
);
2270 ok(hr
== D3DERR_INVALIDCALL
|| broken(hr
== D3D_OK
), "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr
);
2271 hr
= IDirect3DDevice8_DeletePixelShader(device
, hPixelShader
);
2272 ok(hr
== D3DERR_INVALIDCALL
|| broken(hr
== D3D_OK
), "IDirect3DDevice8_DeletePixelShader returned %#08x\n", hr
);
2276 skip("Pixel shaders not supported\n");
2279 /* What happens if a non-bound shader is deleted? */
2280 hr
= IDirect3DDevice8_CreateVertexShader(device
, dwVertexDecl
, NULL
, &hVertexShader
, 0);
2281 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
2282 hr
= IDirect3DDevice8_CreateVertexShader(device
, dwVertexDecl
, NULL
, &hVertexShader2
, 0);
2283 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
2285 hr
= IDirect3DDevice8_SetVertexShader(device
, hVertexShader
);
2286 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr
);
2287 hr
= IDirect3DDevice8_DeleteVertexShader(device
, hVertexShader2
);
2288 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr
);
2289 hr
= IDirect3DDevice8_GetVertexShader(device
, &hTempHandle
);
2290 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetVertexShader returned %#08x\n", hr
);
2291 ok(hTempHandle
== hVertexShader
, "Vertex Shader %d is set, expected shader %d\n", hTempHandle
, hVertexShader
);
2292 hr
= IDirect3DDevice8_DeleteVertexShader(device
, hVertexShader
);
2293 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr
);
2295 /* Check for double delete. */
2296 hr
= IDirect3DDevice8_DeleteVertexShader(device
, hVertexShader2
);
2297 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr
);
2298 hr
= IDirect3DDevice8_DeleteVertexShader(device
, hVertexShader
);
2299 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr
);
2301 refcount
= IDirect3DDevice8_Release(device
);
2302 ok(!refcount
, "Device has %u references left.\n", refcount
);
2304 IDirect3D8_Release(d3d
);
2305 DestroyWindow(window
);
2308 static void test_limits(void)
2310 IDirect3DTexture8
*texture
;
2311 IDirect3DDevice8
*device
;
2318 window
= create_window();
2319 ok(!!window
, "Failed to create a window.\n");
2320 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
2321 ok(!!d3d
, "Failed to create a D3D object.\n");
2322 if (!(device
= create_device(d3d
, window
, NULL
)))
2324 skip("Failed to create a 3D device, skipping test.\n");
2328 hr
= IDirect3DDevice8_CreateTexture(device
, 16, 16, 1, 0, D3DFMT_A8R8G8B8
, D3DPOOL_MANAGED
, &texture
);
2329 ok(hr
== D3D_OK
, "IDirect3DDevice8_CreateTexture failed with %#08x\n", hr
);
2331 /* There are 8 texture stages. We should be able to access all of them */
2332 for (i
= 0; i
< 8; ++i
)
2334 hr
= IDirect3DDevice8_SetTexture(device
, i
, (IDirect3DBaseTexture8
*)texture
);
2335 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTexture for sampler %d failed with %#08x\n", i
, hr
);
2336 hr
= IDirect3DDevice8_SetTexture(device
, i
, NULL
);
2337 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTexture for sampler %d failed with %#08x\n", i
, hr
);
2338 hr
= IDirect3DDevice8_SetTextureStageState(device
, i
, D3DTSS_COLOROP
, D3DTOP_ADD
);
2339 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetTextureStageState for texture %d failed with %#08x\n", i
, hr
);
2342 /* Investigations show that accessing higher textures stage states does
2343 * not return an error either. Writing to too high texture stages
2344 * (approximately texture 40) causes memory corruption in windows, so
2345 * there is no bounds checking. */
2346 IDirect3DTexture8_Release(texture
);
2347 refcount
= IDirect3DDevice8_Release(device
);
2348 ok(!refcount
, "Device has %u references left.\n", refcount
);
2350 IDirect3D8_Release(d3d
);
2351 DestroyWindow(window
);
2354 static void test_lights(void)
2356 IDirect3DDevice8
*device
;
2365 window
= create_window();
2366 ok(!!window
, "Failed to create a window.\n");
2367 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
2368 ok(!!d3d8
, "Failed to create a D3D object.\n");
2369 if (!(device
= create_device(d3d8
, window
, NULL
)))
2371 skip("Failed to create a 3D device, skipping test.\n");
2375 memset(&caps
, 0, sizeof(caps
));
2376 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
2377 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetDeviceCaps failed with %08x\n", hr
);
2379 for(i
= 1; i
<= caps
.MaxActiveLights
; i
++) {
2380 hr
= IDirect3DDevice8_LightEnable(device
, i
, TRUE
);
2381 ok(hr
== D3D_OK
, "Enabling light %u failed with %08x\n", i
, hr
);
2382 hr
= IDirect3DDevice8_GetLightEnable(device
, i
, &enabled
);
2383 ok(hr
== D3D_OK
|| broken(hr
== D3DERR_INVALIDCALL
),
2384 "GetLightEnable on light %u failed with %08x\n", i
, hr
);
2385 ok(enabled
, "Light %d is %s\n", i
, enabled
? "enabled" : "disabled");
2388 /* TODO: Test the rendering results in this situation */
2389 hr
= IDirect3DDevice8_LightEnable(device
, i
+ 1, TRUE
);
2390 ok(hr
== D3D_OK
, "Enabling one light more than supported returned %08x\n", hr
);
2391 hr
= IDirect3DDevice8_GetLightEnable(device
, i
+ 1, &enabled
);
2392 ok(hr
== D3D_OK
, "GetLightEnable on light %u failed with %08x\n", i
+ 1, hr
);
2393 ok(enabled
, "Light %d is %s\n", i
+ 1, enabled
? "enabled" : "disabled");
2394 hr
= IDirect3DDevice8_LightEnable(device
, i
+ 1, FALSE
);
2395 ok(hr
== D3D_OK
, "Disabling the additional returned %08x\n", hr
);
2397 for(i
= 1; i
<= caps
.MaxActiveLights
; i
++) {
2398 hr
= IDirect3DDevice8_LightEnable(device
, i
, FALSE
);
2399 ok(hr
== D3D_OK
, "Disabling light %u failed with %08x\n", i
, hr
);
2402 refcount
= IDirect3DDevice8_Release(device
);
2403 ok(!refcount
, "Device has %u references left.\n", refcount
);
2405 IDirect3D8_Release(d3d8
);
2406 DestroyWindow(window
);
2409 static void test_set_stream_source(void)
2411 IDirect3DVertexBuffer8
*vb
, *current_vb
;
2412 IDirect3DDevice8
*device
;
2413 unsigned int stride
;
2419 window
= create_window();
2420 ok(!!window
, "Failed to create a window.\n");
2421 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
2422 ok(!!d3d8
, "Failed to create a D3D object.\n");
2423 if (!(device
= create_device(d3d8
, window
, NULL
)))
2425 skip("Failed to create a 3D device, skipping test.\n");
2429 hr
= IDirect3DDevice8_CreateVertexBuffer(device
, 512, 0, 0, D3DPOOL_DEFAULT
, &vb
);
2430 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
2432 hr
= IDirect3DDevice8_SetStreamSource(device
, 0, vb
, 32);
2433 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
2435 hr
= IDirect3DDevice8_SetStreamSource(device
, 0, NULL
, 0);
2436 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
2437 hr
= IDirect3DDevice8_GetStreamSource(device
, 0, ¤t_vb
, &stride
);
2438 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
2439 ok(!current_vb
, "Got unexpected vb %p.\n", current_vb
);
2440 ok(stride
== 32, "Got unexpected stride %u.\n", stride
);
2442 hr
= IDirect3DDevice8_SetStreamSource(device
, 0, vb
, 0);
2443 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
2444 hr
= IDirect3DDevice8_GetStreamSource(device
, 0, ¤t_vb
, &stride
);
2445 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
2446 ok(current_vb
== vb
, "Got unexpected vb %p.\n", current_vb
);
2447 IDirect3DVertexBuffer8_Release(current_vb
);
2448 ok(!stride
, "Got unexpected stride %u.\n", stride
);
2450 IDirect3DVertexBuffer8_Release(vb
);
2451 refcount
= IDirect3DDevice8_Release(device
);
2452 ok(!refcount
, "Device has %u references left.\n", refcount
);
2454 IDirect3D8_Release(d3d8
);
2455 DestroyWindow(window
);
2458 static void test_render_zero_triangles(void)
2460 IDirect3DDevice8
*device
;
2468 struct vec3 position
;
2474 {{0.0f
, -1.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
2475 {{0.0f
, 0.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
2476 {{1.0f
, 0.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
2477 {{1.0f
, -1.0f
, 0.1f
}, {1.0f
, 1.0f
, 1.0f
}, 0xff0000ff},
2480 window
= create_window();
2481 ok(!!window
, "Failed to create a window.\n");
2482 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
2483 ok(!!d3d8
, "Failed to create a D3D object.\n");
2484 if (!(device
= create_device(d3d8
, window
, NULL
)))
2486 skip("Failed to create a 3D device, skipping test.\n");
2490 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
2491 ok(hr
== D3D_OK
, "IDirect3DDevice8_SetVertexShader returned %#08x\n", hr
);
2493 hr
= IDirect3DDevice8_BeginScene(device
);
2494 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
2495 hr
= IDirect3DDevice8_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0 /* MinIndex */, 0 /* NumVerts */,
2496 0 /* PrimCount */, NULL
, D3DFMT_INDEX16
, quad
, sizeof(quad
[0]));
2497 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
2498 hr
= IDirect3DDevice8_EndScene(device
);
2499 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
2501 IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
2503 refcount
= IDirect3DDevice8_Release(device
);
2504 ok(!refcount
, "Device has %u references left.\n", refcount
);
2506 IDirect3D8_Release(d3d8
);
2507 DestroyWindow(window
);
2510 static void test_depth_stencil_reset(void)
2512 D3DPRESENT_PARAMETERS present_parameters
;
2513 D3DDISPLAYMODE display_mode
;
2514 IDirect3DSurface8
*surface
, *orig_rt
;
2515 IDirect3DDevice8
*device
= NULL
;
2521 hwnd
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
2522 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
2523 ok(!!hwnd
, "Failed to create a window.\n");
2524 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
2525 ok(!!d3d8
, "Failed to create a D3D object.\n");
2527 IDirect3D8_GetAdapterDisplayMode(d3d8
, D3DADAPTER_DEFAULT
, &display_mode
);
2528 memset(&present_parameters
, 0, sizeof(present_parameters
));
2529 present_parameters
.Windowed
= TRUE
;
2530 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
2531 present_parameters
.BackBufferFormat
= display_mode
.Format
;
2532 present_parameters
.EnableAutoDepthStencil
= TRUE
;
2533 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
2535 hr
= IDirect3D8_CreateDevice(d3d8
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd
,
2536 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
2539 skip("could not create device, IDirect3D8_CreateDevice returned %#x\n", hr
);
2543 hr
= IDirect3DDevice8_GetRenderTarget(device
, &orig_rt
);
2544 ok(hr
== D3D_OK
, "GetRenderTarget failed with 0x%08x\n", hr
);
2546 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
2547 ok(SUCCEEDED(hr
), "TestCooperativeLevel failed with %#x\n", hr
);
2549 hr
= IDirect3DDevice8_SetRenderTarget(device
, NULL
, NULL
);
2550 ok(hr
== D3D_OK
, "SetRenderTarget failed with 0x%08x\n", hr
);
2552 hr
= IDirect3DDevice8_GetRenderTarget(device
, &surface
);
2553 ok(hr
== D3D_OK
, "GetRenderTarget failed with 0x%08x\n", hr
);
2554 ok(surface
== orig_rt
, "Render target is %p, should be %p\n", surface
, orig_rt
);
2555 if (surface
) IDirect3DSurface8_Release(surface
);
2556 IDirect3DSurface8_Release(orig_rt
);
2558 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &surface
);
2559 ok(hr
== D3DERR_NOTFOUND
, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr
);
2560 ok(surface
== NULL
, "Depth stencil should be NULL\n");
2562 present_parameters
.EnableAutoDepthStencil
= TRUE
;
2563 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
2564 hr
= IDirect3DDevice8_Reset(device
, &present_parameters
);
2565 ok(hr
== D3D_OK
, "Reset failed with 0x%08x\n", hr
);
2567 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &surface
);
2568 ok(hr
== D3D_OK
, "GetDepthStencilSurface failed with 0x%08x\n", hr
);
2569 ok(surface
!= NULL
, "Depth stencil should not be NULL\n");
2570 if (surface
) IDirect3DSurface8_Release(surface
);
2572 present_parameters
.EnableAutoDepthStencil
= FALSE
;
2573 hr
= IDirect3DDevice8_Reset(device
, &present_parameters
);
2574 ok(hr
== D3D_OK
, "Reset failed with 0x%08x\n", hr
);
2576 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &surface
);
2577 ok(hr
== D3DERR_NOTFOUND
, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr
);
2578 ok(surface
== NULL
, "Depth stencil should be NULL\n");
2580 refcount
= IDirect3DDevice8_Release(device
);
2581 ok(!refcount
, "Device has %u references left.\n", refcount
);
2584 IDirect3D8_GetAdapterDisplayMode( d3d8
, D3DADAPTER_DEFAULT
, &display_mode
);
2586 ZeroMemory( &present_parameters
, sizeof(present_parameters
) );
2587 present_parameters
.Windowed
= TRUE
;
2588 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
2589 present_parameters
.BackBufferFormat
= display_mode
.Format
;
2590 present_parameters
.EnableAutoDepthStencil
= FALSE
;
2591 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
2593 hr
= IDirect3D8_CreateDevice( d3d8
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, hwnd
,
2594 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
2598 skip("could not create device, IDirect3D8_CreateDevice returned %#x\n", hr
);
2602 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
2603 ok(hr
== D3D_OK
, "IDirect3DDevice8_TestCooperativeLevel after creation returned %#x\n", hr
);
2605 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
2606 present_parameters
.Windowed
= TRUE
;
2607 present_parameters
.BackBufferWidth
= 400;
2608 present_parameters
.BackBufferHeight
= 300;
2609 present_parameters
.EnableAutoDepthStencil
= TRUE
;
2610 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
2612 hr
= IDirect3DDevice8_Reset(device
, &present_parameters
);
2613 ok(hr
== D3D_OK
, "IDirect3DDevice8_Reset failed with 0x%08x\n", hr
);
2615 if (FAILED(hr
)) goto cleanup
;
2617 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &surface
);
2618 ok(hr
== D3D_OK
, "GetDepthStencilSurface failed with 0x%08x\n", hr
);
2619 ok(surface
!= NULL
, "Depth stencil should not be NULL\n");
2620 if (surface
) IDirect3DSurface8_Release(surface
);
2625 refcount
= IDirect3DDevice8_Release(device
);
2626 ok(!refcount
, "Device has %u references left.\n", refcount
);
2628 IDirect3D8_Release(d3d8
);
2629 DestroyWindow(hwnd
);
2632 static HWND filter_messages
;
2643 enum message_window window
;
2645 WPARAM expect_wparam
;
2646 HRESULT device_state
;
2647 WINDOWPOS
*store_wp
;
2650 static const struct message
*expect_messages
;
2651 static HWND device_window
, focus_window
;
2652 static LONG windowposchanged_received
, syscommand_received
;
2653 static IDirect3DDevice8
*focus_test_device
;
2655 struct wndproc_thread_param
2658 HANDLE window_created
;
2659 HANDLE test_finished
;
2660 BOOL running_in_foreground
;
2663 static LRESULT CALLBACK
test_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
2667 if (filter_messages
&& filter_messages
== hwnd
)
2669 if (message
!= WM_DISPLAYCHANGE
&& message
!= WM_IME_NOTIFY
)
2670 todo_wine
ok(0, "Received unexpected message %#x for window %p.\n", message
, hwnd
);
2673 if (expect_messages
)
2677 switch (expect_messages
->window
)
2692 if (hwnd
== w
&& expect_messages
->message
== message
)
2694 if (expect_messages
->check_wparam
)
2695 ok(wparam
== expect_messages
->expect_wparam
,
2696 "Got unexpected wparam %lx for message %x, expected %lx.\n",
2697 wparam
, message
, expect_messages
->expect_wparam
);
2699 if (expect_messages
->store_wp
)
2700 *expect_messages
->store_wp
= *(WINDOWPOS
*)lparam
;
2702 if (focus_test_device
)
2704 hr
= IDirect3DDevice8_TestCooperativeLevel(focus_test_device
);
2705 /* Wined3d marks the device lost earlier than Windows (it follows ddraw
2706 * behavior. See test_wndproc before the focus_loss_messages sequence
2707 * about the D3DERR_DEVICENOTRESET behavior, */
2708 todo_wine_if(message
!= WM_ACTIVATEAPP
|| hr
== D3D_OK
)
2709 ok(hr
== expect_messages
->device_state
,
2710 "Got device state %#x on message %#x, expected %#x.\n",
2711 hr
, message
, expect_messages
->device_state
);
2718 /* KDE randomly does something with the hidden window during the
2719 * mode change that sometimes generates a WM_WINDOWPOSCHANGING
2720 * message. A WM_WINDOWPOSCHANGED message is not generated, so
2721 * just flag WM_WINDOWPOSCHANGED as bad. */
2722 if (message
== WM_WINDOWPOSCHANGED
)
2723 InterlockedIncrement(&windowposchanged_received
);
2724 else if (message
== WM_SYSCOMMAND
)
2725 InterlockedIncrement(&syscommand_received
);
2727 return DefWindowProcA(hwnd
, message
, wparam
, lparam
);
2730 static DWORD WINAPI
wndproc_thread(void *param
)
2732 struct wndproc_thread_param
*p
= param
;
2736 p
->dummy_window
= CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
2737 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, registry_mode
.dmPelsWidth
,
2738 registry_mode
.dmPelsHeight
, 0, 0, 0, 0);
2739 p
->running_in_foreground
= SetForegroundWindow(p
->dummy_window
);
2741 ret
= SetEvent(p
->window_created
);
2742 ok(ret
, "SetEvent failed, last error %#x.\n", GetLastError());
2748 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
2749 res
= WaitForSingleObject(p
->test_finished
, 100);
2750 if (res
== WAIT_OBJECT_0
) break;
2751 if (res
!= WAIT_TIMEOUT
)
2753 ok(0, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
2758 DestroyWindow(p
->dummy_window
);
2763 static void test_wndproc(void)
2765 struct wndproc_thread_param thread_params
;
2766 struct device_desc device_desc
;
2767 static WINDOWPOS windowpos
;
2768 IDirect3DDevice8
*device
;
2776 UINT i
, adapter_mode_count
;
2778 D3DDISPLAYMODE d3ddm
;
2779 DWORD d3d_width
= 0, d3d_height
= 0, user32_width
= 0, user32_height
= 0;
2781 LONG change_ret
, device_style
;
2784 static const struct message create_messages
[] =
2786 {WM_WINDOWPOSCHANGING
, FOCUS_WINDOW
, FALSE
, 0},
2787 /* Do not test wparam here. If device creation succeeds,
2788 * wparam is WA_ACTIVE. If device creation fails (testbot)
2789 * wparam is set to WA_INACTIVE on some Windows versions. */
2790 {WM_ACTIVATE
, FOCUS_WINDOW
, FALSE
, 0},
2791 {WM_SETFOCUS
, FOCUS_WINDOW
, FALSE
, 0},
2792 {WM_WINDOWPOSCHANGING
, DEVICE_WINDOW
, FALSE
, 0},
2793 {WM_MOVE
, DEVICE_WINDOW
, FALSE
, 0},
2794 {WM_SIZE
, DEVICE_WINDOW
, FALSE
, 0},
2797 static const struct message focus_loss_messages
[] =
2799 /* WM_ACTIVATE (wparam = WA_INACTIVE) is sent on Windows. It is
2800 * not reliable on X11 WMs. When the window focus follows the
2801 * mouse pointer the message is not sent.
2802 * {WM_ACTIVATE, FOCUS_WINDOW, TRUE, WA_INACTIVE}, */
2803 {WM_DISPLAYCHANGE
, DEVICE_WINDOW
, FALSE
, 0, D3DERR_DEVICENOTRESET
},
2804 /* WM_DISPLAYCHANGE is sent to the focus window too, but the order is
2805 * not deterministic. */
2806 {WM_WINDOWPOSCHANGING
, DEVICE_WINDOW
, FALSE
, 0, D3DERR_DEVICENOTRESET
},
2807 /* Windows sends WM_ACTIVATE to the device window, indicating that
2808 * SW_SHOWMINIMIZED is used instead of SW_MINIMIZE. Yet afterwards
2809 * the foreground and focus window are NULL. On Wine SW_SHOWMINIMIZED
2810 * leaves the device window active, breaking re-activation in the
2812 * {WM_ACTIVATE, DEVICE_WINDOW, TRUE, 0x200000 | WA_ACTIVE}, */
2813 {WM_WINDOWPOSCHANGED
, DEVICE_WINDOW
, FALSE
, 0, D3DERR_DEVICENOTRESET
},
2814 {WM_SIZE
, DEVICE_WINDOW
, TRUE
, SIZE_MINIMIZED
,
2815 D3DERR_DEVICENOTRESET
},
2816 {WM_ACTIVATEAPP
, FOCUS_WINDOW
, TRUE
, FALSE
, D3DERR_DEVICELOST
},
2817 /* WM_ACTIVATEAPP is sent to the device window too, but the order is
2818 * not deterministic. It may be sent after the focus window handling
2820 {0, 0, FALSE
, 0, 0},
2822 static const struct message reactivate_messages
[] =
2824 {WM_WINDOWPOSCHANGING
, DEVICE_WINDOW
, FALSE
, 0},
2825 {WM_WINDOWPOSCHANGED
, DEVICE_WINDOW
, FALSE
, 0},
2826 {WM_MOVE
, DEVICE_WINDOW
, FALSE
, 0},
2827 {WM_ACTIVATEAPP
, FOCUS_WINDOW
, TRUE
, TRUE
},
2830 static const struct message focus_loss_messages_hidden
[] =
2832 {WM_DISPLAYCHANGE
, DEVICE_WINDOW
, FALSE
, 0},
2833 {WM_ACTIVATEAPP
, FOCUS_WINDOW
, TRUE
, FALSE
},
2836 static const struct message focus_loss_messages_filtered
[] =
2838 /* WM_ACTIVATE is delivered to the window proc because it is
2839 * generated by SetForegroundWindow before the d3d routine
2840 * starts it work. Don't check for it due to focus-follows-mouse
2842 {WM_DISPLAYCHANGE
, FOCUS_WINDOW
, FALSE
, 0},
2843 {WM_ACTIVATEAPP
, FOCUS_WINDOW
, TRUE
, FALSE
},
2846 static const struct message reactivate_messages_filtered
[] =
2848 {WM_ACTIVATEAPP
, FOCUS_WINDOW
, TRUE
, TRUE
},
2851 static const struct message sc_restore_messages
[] =
2853 /* WM_SYSCOMMAND is delivered only once, after d3d has already
2854 * processed it. Our wndproc has no way to prevent d3d from
2855 * handling the message. The second DefWindowProc call done by
2856 * our wndproc doesn't do any changes to the window because it
2857 * is already restored due to d3d's handling. */
2858 {WM_WINDOWPOSCHANGING
, FOCUS_WINDOW
, FALSE
, 0},
2859 {WM_WINDOWPOSCHANGED
, FOCUS_WINDOW
, FALSE
, 0},
2860 {WM_SIZE
, FOCUS_WINDOW
, TRUE
, SIZE_RESTORED
},
2861 {WM_SYSCOMMAND
, FOCUS_WINDOW
, TRUE
, SC_RESTORE
},
2864 static const struct message sc_minimize_messages
[] =
2866 {WM_SYSCOMMAND
, FOCUS_WINDOW
, TRUE
, SC_MINIMIZE
},
2867 {WM_WINDOWPOSCHANGING
, FOCUS_WINDOW
, FALSE
, 0},
2868 {WM_WINDOWPOSCHANGED
, FOCUS_WINDOW
, FALSE
, 0},
2869 {WM_MOVE
, FOCUS_WINDOW
, FALSE
, 0},
2870 {WM_SIZE
, FOCUS_WINDOW
, TRUE
, SIZE_MINIMIZED
},
2873 static const struct message sc_maximize_messages
[] =
2875 {WM_SYSCOMMAND
, FOCUS_WINDOW
, TRUE
, SC_MAXIMIZE
},
2876 {WM_WINDOWPOSCHANGING
, FOCUS_WINDOW
, FALSE
, 0},
2877 {WM_WINDOWPOSCHANGED
, FOCUS_WINDOW
, FALSE
, 0},
2878 {WM_MOVE
, FOCUS_WINDOW
, FALSE
, 0},
2879 {WM_SIZE
, FOCUS_WINDOW
, TRUE
, SIZE_MAXIMIZED
},
2882 static const struct message mode_change_messages
[] =
2884 {WM_WINDOWPOSCHANGING
, DEVICE_WINDOW
, FALSE
, 0},
2885 {WM_WINDOWPOSCHANGED
, DEVICE_WINDOW
, FALSE
, 0},
2886 {WM_SIZE
, DEVICE_WINDOW
, FALSE
, 0},
2887 /* TODO: WM_DISPLAYCHANGE is sent to the focus window too, but the order is
2888 * differs between Wine and Windows. */
2889 /* TODO 2: Windows sends a second WM_WINDOWPOSCHANGING(SWP_NOMOVE | SWP_NOSIZE
2890 * | SWP_NOACTIVATE) in this situation, suggesting a difference in their ShowWindow
2891 * implementation. This SetWindowPos call could in theory affect the Z order. Wine's
2892 * ShowWindow does not send such a message because the window is already visible. */
2895 static const struct message mode_change_messages_hidden
[] =
2897 {WM_WINDOWPOSCHANGING
, DEVICE_WINDOW
, FALSE
, 0},
2898 {WM_WINDOWPOSCHANGED
, DEVICE_WINDOW
, FALSE
, 0},
2899 {WM_SIZE
, DEVICE_WINDOW
, FALSE
, 0},
2900 {WM_SHOWWINDOW
, DEVICE_WINDOW
, FALSE
, 0},
2901 {WM_WINDOWPOSCHANGING
, DEVICE_WINDOW
, FALSE
, 0, ~0U, &windowpos
},
2902 {WM_WINDOWPOSCHANGED
, DEVICE_WINDOW
, FALSE
, 0},
2903 /* TODO: WM_DISPLAYCHANGE is sent to the focus window too, but the order is
2904 * differs between Wine and Windows. */
2908 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
2909 ok(!!d3d8
, "Failed to create a D3D object.\n");
2911 adapter_mode_count
= IDirect3D8_GetAdapterModeCount(d3d8
, D3DADAPTER_DEFAULT
);
2912 for (i
= 0; i
< adapter_mode_count
; ++i
)
2914 hr
= IDirect3D8_EnumAdapterModes(d3d8
, D3DADAPTER_DEFAULT
, i
, &d3ddm
);
2915 ok(SUCCEEDED(hr
), "Failed to enumerate display mode, hr %#x.\n", hr
);
2917 if (d3ddm
.Format
!= D3DFMT_X8R8G8B8
)
2919 if (d3ddm
.Width
== registry_mode
.dmPelsWidth
&& d3ddm
.Height
== registry_mode
.dmPelsHeight
)
2921 /* The r200 driver on Windows XP enumerates modes like 320x200 and 320x240 but
2922 * refuses to create a device at these sizes. */
2923 if (d3ddm
.Width
< 640 || d3ddm
.Height
< 480)
2928 user32_width
= d3ddm
.Width
;
2929 user32_height
= d3ddm
.Height
;
2933 /* Make sure the d3d mode is smaller in width or height and at most
2934 * equal in the other dimension than the mode passed to
2935 * ChangeDisplaySettings. Otherwise Windows shrinks the window to
2936 * the ChangeDisplaySettings parameters + 12. */
2937 if (d3ddm
.Width
== user32_width
&& d3ddm
.Height
== user32_height
)
2939 if (d3ddm
.Width
<= user32_width
&& d3ddm
.Height
<= user32_height
)
2941 d3d_width
= d3ddm
.Width
;
2942 d3d_height
= d3ddm
.Height
;
2945 if (user32_width
<= d3ddm
.Width
&& user32_height
<= d3ddm
.Height
)
2947 d3d_width
= user32_width
;
2948 d3d_height
= user32_height
;
2949 user32_width
= d3ddm
.Width
;
2950 user32_height
= d3ddm
.Height
;
2957 skip("Could not find adequate modes, skipping mode tests.\n");
2958 IDirect3D8_Release(d3d8
);
2962 filter_messages
= NULL
;
2963 expect_messages
= NULL
;
2965 wc
.lpfnWndProc
= test_proc
;
2966 wc
.lpszClassName
= "d3d8_test_wndproc_wc";
2967 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2969 thread_params
.window_created
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
2970 ok(!!thread_params
.window_created
, "CreateEvent failed, last error %#x.\n", GetLastError());
2971 thread_params
.test_finished
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
2972 ok(!!thread_params
.test_finished
, "CreateEvent failed, last error %#x.\n", GetLastError());
2974 memset(&devmode
, 0, sizeof(devmode
));
2975 devmode
.dmSize
= sizeof(devmode
);
2976 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
2977 devmode
.dmPelsWidth
= user32_width
;
2978 devmode
.dmPelsHeight
= user32_height
;
2979 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2980 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2982 focus_window
= CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
2983 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, user32_width
, user32_height
, 0, 0, 0, 0);
2984 device_window
= CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
2985 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, user32_width
, user32_height
, 0, 0, 0, 0);
2986 thread
= CreateThread(NULL
, 0, wndproc_thread
, &thread_params
, 0, &tid
);
2987 ok(!!thread
, "Failed to create thread, last error %#x.\n", GetLastError());
2989 res
= WaitForSingleObject(thread_params
.window_created
, INFINITE
);
2990 ok(res
== WAIT_OBJECT_0
, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
2992 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
2993 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2994 (LONG_PTR
)test_proc
, proc
);
2995 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
2996 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2997 (LONG_PTR
)test_proc
, proc
);
2999 trace("device_window %p, focus_window %p, dummy_window %p.\n",
3000 device_window
, focus_window
, thread_params
.dummy_window
);
3003 ok(tmp
== device_window
, "Expected focus %p, got %p.\n", device_window
, tmp
);
3004 if (thread_params
.running_in_foreground
)
3006 tmp
= GetForegroundWindow();
3007 ok(tmp
== thread_params
.dummy_window
, "Expected foreground window %p, got %p.\n",
3008 thread_params
.dummy_window
, tmp
);
3011 skip("Not running in foreground, skip foreground window test\n");
3015 expect_messages
= create_messages
;
3017 device_desc
.adapter_ordinal
= D3DADAPTER_DEFAULT
;
3018 device_desc
.device_window
= device_window
;
3019 device_desc
.width
= d3d_width
;
3020 device_desc
.height
= d3d_height
;
3021 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
3022 if (!(device
= create_device(d3d8
, focus_window
, &device_desc
)))
3024 skip("Failed to create a D3D device, skipping tests.\n");
3028 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it.\n",
3029 expect_messages
->message
, expect_messages
->window
);
3030 expect_messages
= NULL
;
3032 if (0) /* Disabled until we can make this work in a reliable way on Wine. */
3035 ok(tmp
== focus_window
, "Expected focus %p, got %p.\n", focus_window
, tmp
);
3036 tmp
= GetForegroundWindow();
3037 ok(tmp
== focus_window
, "Expected foreground window %p, got %p.\n", focus_window
, tmp
);
3039 SetForegroundWindow(focus_window
);
3042 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
3043 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3044 (LONG_PTR
)test_proc
, proc
);
3046 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
3047 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx.\n", (LONG_PTR
)test_proc
);
3049 /* Change the mode while the device is in use and then drop focus. */
3050 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
3051 devmode
.dmPelsWidth
= user32_width
;
3052 devmode
.dmPelsHeight
= user32_height
;
3053 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
3054 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x, i=%u.\n", change_ret
, i
);
3056 /* Wine doesn't (yet) mark the device not reset when the mode is changed, thus the todo_wine.
3057 * But sometimes focus-follows-mouse WMs also temporarily drop window focus, which makes
3058 * mark the device lost, then not reset, causing the test to succeed for the wrong reason. */
3059 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
3060 todo_wine_if (hr
!= D3DERR_DEVICENOTRESET
)
3061 ok(hr
== D3DERR_DEVICENOTRESET
, "Got unexpected hr %#x.\n", hr
);
3063 expect_messages
= focus_loss_messages
;
3064 focus_test_device
= device
;
3065 /* SetForegroundWindow is a poor replacement for the user pressing alt-tab or
3066 * manually changing the focus. It generates the same messages, but the task
3067 * bar still shows the previous foreground window as active, and the window has
3068 * an inactive titlebar if reactivated with SetForegroundWindow. Reactivating
3069 * the device is difficult, see below. */
3070 SetForegroundWindow(GetDesktopWindow());
3071 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it.\n",
3072 expect_messages
->message
, expect_messages
->window
);
3073 expect_messages
= NULL
;
3075 ok(tmp
!= device_window
, "The device window is active.\n");
3076 ok(tmp
!= focus_window
, "The focus window is active.\n");
3077 focus_test_device
= NULL
;
3079 /* The Present call is necessary to make native realize the device is lost. */
3080 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
3081 ok(hr
== D3DERR_DEVICELOST
, "Got unexpected hr %#x.\n", hr
);
3082 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
3083 /* Focus-follows-mouse WMs prematurely reactivate our window. */
3084 todo_wine_if (hr
== D3DERR_DEVICENOTRESET
)
3085 ok(hr
== D3DERR_DEVICELOST
, "Got unexpected hr %#x.\n", hr
);
3087 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
3088 ok(ret
, "Failed to get display mode.\n");
3089 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
3090 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
, "Got unexpected screen size %ux%u.\n",
3091 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
3093 /* I have to minimize and restore the focus window, otherwise native d3d8 fails
3094 * device::reset with D3DERR_DEVICELOST. This does not happen when the window
3095 * restore is triggered by the user. */
3096 expect_messages
= reactivate_messages
;
3097 ShowWindow(focus_window
, SW_MINIMIZE
);
3098 ShowWindow(focus_window
, SW_RESTORE
);
3099 /* Set focus twice to make KDE and fvwm in focus-follows-mouse mode happy. */
3100 SetForegroundWindow(focus_window
);
3102 SetForegroundWindow(focus_window
);
3103 flush_events(); /* WM_WINDOWPOSCHANGING etc arrive after SetForegroundWindow returns. */
3104 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it, i=%u.\n",
3105 expect_messages
->message
, expect_messages
->window
, i
);
3106 expect_messages
= NULL
;
3108 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
3109 ok(hr
== D3DERR_DEVICENOTRESET
, "Got unexpected hr %#x.\n", hr
);
3111 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
3112 ok(ret
, "Failed to get display mode.\n");
3113 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
3114 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
, "Got unexpected screen size %ux%u.\n",
3115 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
3117 hr
= reset_device(device
, &device_desc
);
3118 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
3120 /* Remove the WS_VISIBLE flag to test hidden windows. This is enough to trigger d3d's hidden
3121 * window codepath, but does not actually hide the window without a SetWindowPos(SWP_FRAMECHANGED)
3122 * call. This way we avoid focus changes and random failures on focus follows mouse WMs. */
3123 device_style
= GetWindowLongA(device_window
, GWL_STYLE
);
3124 SetWindowLongA(device_window
, GWL_STYLE
, device_style
& ~WS_VISIBLE
);
3127 expect_messages
= focus_loss_messages_hidden
;
3128 windowposchanged_received
= 0;
3129 SetForegroundWindow(GetDesktopWindow());
3130 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it.\n",
3131 expect_messages
->message
, expect_messages
->window
);
3132 ok(!windowposchanged_received
, "Received WM_WINDOWPOSCHANGED but did not expect it.\n");
3133 expect_messages
= NULL
;
3136 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
3137 ok(ret
, "Failed to get display mode.\n");
3138 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
, "Got unexpected width %u.\n", devmode
.dmPelsWidth
);
3139 ok(devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
, "Got unexpected height %u.\n", devmode
.dmPelsHeight
);
3141 /* SW_SHOWMINNOACTIVE is needed to make FVWM happy. SW_SHOWNOACTIVATE is needed to make windows
3142 * send SIZE_RESTORED after ShowWindow(SW_SHOWMINNOACTIVE). */
3143 ShowWindow(focus_window
, SW_SHOWNOACTIVATE
);
3144 ShowWindow(focus_window
, SW_SHOWMINNOACTIVE
);
3147 syscommand_received
= 0;
3148 expect_messages
= sc_restore_messages
;
3149 SendMessageA(focus_window
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
3150 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it.\n",
3151 expect_messages
->message
, expect_messages
->window
);
3152 ok(syscommand_received
== 1, "Got unexpected number of WM_SYSCOMMAND messages: %d.\n", syscommand_received
);
3153 expect_messages
= NULL
;
3156 expect_messages
= sc_minimize_messages
;
3157 SendMessageA(focus_window
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
3158 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it.\n",
3159 expect_messages
->message
, expect_messages
->window
);
3160 expect_messages
= NULL
;
3163 expect_messages
= sc_maximize_messages
;
3164 SendMessageA(focus_window
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
3165 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it.\n",
3166 expect_messages
->message
, expect_messages
->window
);
3167 expect_messages
= NULL
;
3170 SetForegroundWindow(GetDesktopWindow());
3171 ShowWindow(device_window
, SW_MINIMIZE
);
3172 ShowWindow(focus_window
, SW_MINIMIZE
);
3173 ShowWindow(focus_window
, SW_RESTORE
);
3174 SetForegroundWindow(focus_window
);
3177 /* Releasing a device in lost state breaks follow-up tests on native. */
3178 hr
= reset_device(device
, &device_desc
);
3179 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
3181 filter_messages
= focus_window
;
3182 ref
= IDirect3DDevice8_Release(device
);
3183 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
3185 /* Fix up the mode until Wine's device release behavior is fixed. */
3186 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
3187 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
3189 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
3190 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3191 (LONG_PTR
)test_proc
, proc
);
3193 /* Hide the device window. It prevents WM_ACTIVATEAPP messages from being sent
3194 * on native in the test below. It isn't needed anyways. Creating the third
3195 * device will show it again. */
3196 filter_messages
= NULL
;
3197 ShowWindow(device_window
, SW_HIDE
);
3198 /* Remove the maximized state from the SYSCOMMAND test while we're not
3199 * interfering with a device. */
3200 ShowWindow(focus_window
, SW_SHOWNORMAL
);
3202 /* On Windows 10 style change messages are delivered on device
3204 device_desc
.device_window
= focus_window
;
3205 if (!(device
= create_device(d3d8
, focus_window
, &device_desc
)))
3207 skip("Failed to create a D3D device, skipping tests.\n");
3211 filter_messages
= NULL
;
3213 expect_messages
= focus_loss_messages_filtered
;
3214 windowposchanged_received
= 0;
3215 SetForegroundWindow(GetDesktopWindow());
3216 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it.\n",
3217 expect_messages
->message
, expect_messages
->window
);
3218 expect_messages
= NULL
;
3220 /* The window is iconic even though no message was sent. */
3221 ok(IsIconic(focus_window
), "The focus window is not iconic.\n");
3223 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
3224 ok(hr
== D3DERR_DEVICELOST
, "Got unexpected hr %#x.\n", hr
);
3226 syscommand_received
= 0;
3227 expect_messages
= sc_restore_messages
;
3228 SendMessageA(focus_window
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
3229 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it.\n",
3230 expect_messages
->message
, expect_messages
->window
);
3231 ok(syscommand_received
== 1, "Got unexpected number of WM_SYSCOMMAND messages: %d.\n", syscommand_received
);
3232 expect_messages
= NULL
;
3236 ShowWindow(focus_window
, SW_RESTORE
);
3239 expect_messages
= sc_minimize_messages
;
3240 SendMessageA(focus_window
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
3241 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it.\n",
3242 expect_messages
->message
, expect_messages
->window
);
3243 expect_messages
= NULL
;
3244 /* Needed to make the next test reliably send WM_SIZE(SIZE_MAXIMIZED). Without
3245 * this call it sends WM_SIZE(SIZE_RESTORED). */
3246 ShowWindow(focus_window
, SW_RESTORE
);
3249 expect_messages
= sc_maximize_messages
;
3250 SendMessageA(focus_window
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
3251 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it.\n",
3252 expect_messages
->message
, expect_messages
->window
);
3253 expect_messages
= NULL
;
3255 SetForegroundWindow(GetDesktopWindow());
3258 /* ShowWindow(SW_RESTORE); SetForegroundWindow(desktop); SetForegroundWindow(focus);
3259 * results in the second SetForegroundWindow call failing and the device not being
3260 * restored on native. Directly using ShowWindow(SW_RESTORE) works, but it means
3261 * we cannot test for the absence of WM_WINDOWPOSCHANGED messages. */
3262 expect_messages
= reactivate_messages_filtered
;
3263 ShowWindow(focus_window
, SW_RESTORE
);
3264 SetForegroundWindow(focus_window
);
3266 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it\n",
3267 expect_messages
->message
, expect_messages
->window
);
3268 expect_messages
= NULL
;
3270 filter_messages
= focus_window
;
3271 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
3272 ok(hr
== D3DERR_DEVICENOTRESET
, "Got unexpected hr %#x.\n", hr
);
3274 filter_messages
= NULL
;
3275 hr
= reset_device(device
, &device_desc
);
3276 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
3278 ref
= IDirect3DDevice8_Release(device
);
3279 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
3280 filter_messages
= NULL
;
3282 ShowWindow(device_window
, SW_RESTORE
);
3283 SetForegroundWindow(focus_window
);
3286 filter_messages
= focus_window
;
3287 device_desc
.device_window
= device_window
;
3288 if (!(device
= create_device(d3d8
, focus_window
, &device_desc
)))
3290 skip("Failed to create a D3D device, skipping tests.\n");
3293 filter_messages
= NULL
;
3296 device_desc
.width
= user32_width
;
3297 device_desc
.height
= user32_height
;
3299 expect_messages
= mode_change_messages
;
3300 filter_messages
= focus_window
;
3301 hr
= reset_device(device
, &device_desc
);
3302 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
3303 filter_messages
= NULL
;
3306 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it, i=%u.\n",
3307 expect_messages
->message
, expect_messages
->window
, i
);
3308 expect_messages
= NULL
;
3310 /* World of Warplanes hides the window by removing WS_VISIBLE and expects Reset() to show it again. */
3311 device_style
= GetWindowLongA(device_window
, GWL_STYLE
);
3312 SetWindowLongA(device_window
, GWL_STYLE
, device_style
& ~WS_VISIBLE
);
3315 device_desc
.width
= d3d_width
;
3316 device_desc
.height
= d3d_height
;
3317 memset(&windowpos
, 0, sizeof(windowpos
));
3319 expect_messages
= mode_change_messages_hidden
;
3320 filter_messages
= focus_window
;
3321 hr
= reset_device(device
, &device_desc
);
3322 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
3323 filter_messages
= NULL
;
3326 ok(!expect_messages
->message
, "Expected message %#x for window %#x, but didn't receive it.\n",
3327 expect_messages
->message
, expect_messages
->window
);
3328 expect_messages
= NULL
;
3330 ok(windowpos
.hwnd
== device_window
&& !windowpos
.hwndInsertAfter
3331 && !windowpos
.x
&& !windowpos
.y
&& !windowpos
.cx
&& !windowpos
.cy
3332 && windowpos
.flags
== (SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
),
3333 "Got unexpected WINDOWPOS hwnd=%p, insertAfter=%p, x=%d, y=%d, cx=%d, cy=%d, flags=%x\n",
3334 windowpos
.hwnd
, windowpos
.hwndInsertAfter
, windowpos
.x
, windowpos
.y
, windowpos
.cx
,
3335 windowpos
.cy
, windowpos
.flags
);
3337 device_style
= GetWindowLongA(device_window
, GWL_STYLE
);
3338 ok(device_style
& WS_VISIBLE
, "Expected the device window to be visible.\n");
3340 proc
= SetWindowLongPtrA(focus_window
, GWLP_WNDPROC
, (LONG_PTR
)DefWindowProcA
);
3341 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx.\n", (LONG_PTR
)test_proc
);
3343 ref
= IDirect3DDevice8_Release(device
);
3344 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
3346 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
3347 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
3348 (LONG_PTR
)DefWindowProcA
, proc
);
3351 filter_messages
= NULL
;
3352 expect_messages
= NULL
;
3353 IDirect3D8_Release(d3d8
);
3355 SetEvent(thread_params
.test_finished
);
3356 WaitForSingleObject(thread
, INFINITE
);
3357 CloseHandle(thread_params
.test_finished
);
3358 CloseHandle(thread_params
.window_created
);
3359 CloseHandle(thread
);
3361 DestroyWindow(device_window
);
3362 DestroyWindow(focus_window
);
3363 UnregisterClassA("d3d8_test_wndproc_wc", GetModuleHandleA(NULL
));
3366 static void test_wndproc_windowed(void)
3368 struct wndproc_thread_param thread_params
;
3369 struct device_desc device_desc
;
3370 IDirect3DDevice8
*device
;
3380 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
3381 ok(!!d3d8
, "Failed to create a D3D object.\n");
3383 filter_messages
= NULL
;
3384 expect_messages
= NULL
;
3386 wc
.lpfnWndProc
= test_proc
;
3387 wc
.lpszClassName
= "d3d8_test_wndproc_wc";
3388 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
3390 thread_params
.window_created
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
3391 ok(!!thread_params
.window_created
, "CreateEvent failed, last error %#x.\n", GetLastError());
3392 thread_params
.test_finished
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
3393 ok(!!thread_params
.test_finished
, "CreateEvent failed, last error %#x.\n", GetLastError());
3395 focus_window
= CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
3396 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, registry_mode
.dmPelsWidth
,
3397 registry_mode
.dmPelsHeight
, 0, 0, 0, 0);
3398 device_window
= CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test",
3399 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, registry_mode
.dmPelsWidth
,
3400 registry_mode
.dmPelsHeight
, 0, 0, 0, 0);
3401 thread
= CreateThread(NULL
, 0, wndproc_thread
, &thread_params
, 0, &tid
);
3402 ok(!!thread
, "Failed to create thread, last error %#x.\n", GetLastError());
3404 res
= WaitForSingleObject(thread_params
.window_created
, INFINITE
);
3405 ok(res
== WAIT_OBJECT_0
, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
3407 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
3408 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3409 (LONG_PTR
)test_proc
, proc
);
3410 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
3411 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3412 (LONG_PTR
)test_proc
, proc
);
3414 trace("device_window %p, focus_window %p, dummy_window %p.\n",
3415 device_window
, focus_window
, thread_params
.dummy_window
);
3418 ok(tmp
== device_window
, "Expected focus %p, got %p.\n", device_window
, tmp
);
3419 if (thread_params
.running_in_foreground
)
3421 tmp
= GetForegroundWindow();
3422 ok(tmp
== thread_params
.dummy_window
, "Expected foreground window %p, got %p.\n",
3423 thread_params
.dummy_window
, tmp
);
3426 skip("Not running in foreground, skip foreground window test\n");
3428 filter_messages
= focus_window
;
3430 device_desc
.adapter_ordinal
= D3DADAPTER_DEFAULT
;
3431 device_desc
.device_window
= device_window
;
3432 device_desc
.width
= registry_mode
.dmPelsWidth
;
3433 device_desc
.height
= registry_mode
.dmPelsHeight
;
3434 device_desc
.flags
= 0;
3435 if (!(device
= create_device(d3d8
, focus_window
, &device_desc
)))
3437 skip("Failed to create a D3D device, skipping tests.\n");
3442 ok(tmp
== device_window
, "Expected focus %p, got %p.\n", device_window
, tmp
);
3443 tmp
= GetForegroundWindow();
3444 ok(tmp
== thread_params
.dummy_window
, "Expected foreground window %p, got %p.\n",
3445 thread_params
.dummy_window
, tmp
);
3447 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
3448 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3449 (LONG_PTR
)test_proc
, proc
);
3451 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
3452 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3453 (LONG_PTR
)test_proc
, proc
);
3455 filter_messages
= NULL
;
3457 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
3458 hr
= reset_device(device
, &device_desc
);
3459 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
3461 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
3462 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3463 (LONG_PTR
)test_proc
, proc
);
3465 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
3466 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx.\n", (LONG_PTR
)test_proc
);
3468 device_desc
.flags
= 0;
3469 hr
= reset_device(device
, &device_desc
);
3470 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
3472 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
3473 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3474 (LONG_PTR
)test_proc
, proc
);
3476 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
3477 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3478 (LONG_PTR
)test_proc
, proc
);
3480 filter_messages
= focus_window
;
3482 ref
= IDirect3DDevice8_Release(device
);
3483 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
3485 filter_messages
= device_window
;
3487 device_desc
.device_window
= focus_window
;
3488 if (!(device
= create_device(d3d8
, focus_window
, &device_desc
)))
3490 skip("Failed to create a D3D device, skipping tests.\n");
3494 filter_messages
= NULL
;
3496 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
3497 hr
= reset_device(device
, &device_desc
);
3498 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
3500 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
3501 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3502 (LONG_PTR
)test_proc
, proc
);
3504 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
3505 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx.\n", (LONG_PTR
)test_proc
);
3507 device_desc
.flags
= 0;
3508 hr
= reset_device(device
, &device_desc
);
3509 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
3511 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
3512 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3513 (LONG_PTR
)test_proc
, proc
);
3515 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
3516 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3517 (LONG_PTR
)test_proc
, proc
);
3519 filter_messages
= device_window
;
3521 ref
= IDirect3DDevice8_Release(device
);
3522 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
3524 device_desc
.device_window
= device_window
;
3525 if (!(device
= create_device(d3d8
, focus_window
, &device_desc
)))
3527 skip("Failed to create a D3D device, skipping tests.\n");
3531 filter_messages
= NULL
;
3533 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
3534 hr
= reset_device(device
, &device_desc
);
3535 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
3537 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
3538 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3539 (LONG_PTR
)test_proc
, proc
);
3541 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
3542 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx.\n", (LONG_PTR
)test_proc
);
3544 device_desc
.flags
= 0;
3545 hr
= reset_device(device
, &device_desc
);
3546 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
3548 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
3549 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3550 (LONG_PTR
)test_proc
, proc
);
3552 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
3553 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
3554 (LONG_PTR
)test_proc
, proc
);
3556 filter_messages
= device_window
;
3558 ref
= IDirect3DDevice8_Release(device
);
3559 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
3562 filter_messages
= NULL
;
3563 IDirect3D8_Release(d3d8
);
3565 SetEvent(thread_params
.test_finished
);
3566 WaitForSingleObject(thread
, INFINITE
);
3567 CloseHandle(thread_params
.test_finished
);
3568 CloseHandle(thread_params
.window_created
);
3569 CloseHandle(thread
);
3571 DestroyWindow(device_window
);
3572 DestroyWindow(focus_window
);
3573 UnregisterClassA("d3d8_test_wndproc_wc", GetModuleHandleA(NULL
));
3576 static inline void set_fpu_cw(WORD cw
)
3578 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3579 #define D3D8_TEST_SET_FPU_CW 1
3580 __asm__
volatile ("fnclex");
3581 __asm__
volatile ("fldcw %0" : : "m" (cw
));
3582 #elif defined(__i386__) && defined(_MSC_VER)
3583 #define D3D8_TEST_SET_FPU_CW 1
3589 static inline WORD
get_fpu_cw(void)
3592 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3593 #define D3D8_TEST_GET_FPU_CW 1
3594 __asm__
volatile ("fnstcw %0" : "=m" (cw
));
3595 #elif defined(__i386__) && defined(_MSC_VER)
3596 #define D3D8_TEST_GET_FPU_CW 1
3602 static WORD callback_cw
, callback_set_cw
;
3603 static DWORD callback_tid
;
3605 static HRESULT WINAPI
dummy_object_QueryInterface(IUnknown
*iface
, REFIID riid
, void **out
)
3608 return E_NOINTERFACE
;
3611 static ULONG WINAPI
dummy_object_AddRef(IUnknown
*iface
)
3613 callback_cw
= get_fpu_cw();
3614 set_fpu_cw(callback_set_cw
);
3615 callback_tid
= GetCurrentThreadId();
3619 static ULONG WINAPI
dummy_object_Release(IUnknown
*iface
)
3621 callback_cw
= get_fpu_cw();
3622 set_fpu_cw(callback_set_cw
);
3623 callback_tid
= GetCurrentThreadId();
3627 static const IUnknownVtbl dummy_object_vtbl
=
3629 dummy_object_QueryInterface
,
3630 dummy_object_AddRef
,
3631 dummy_object_Release
,
3634 static const GUID d3d8_private_data_test_guid
=
3639 {0xa3,0x7f,0x9b,0x1d,0xf4,0x88,0xc5,0xfc}
3642 static void test_fpu_setup(void)
3644 #if defined(D3D8_TEST_SET_FPU_CW) && defined(D3D8_TEST_GET_FPU_CW)
3645 struct device_desc device_desc
;
3646 IDirect3DDevice8
*device
;
3647 D3DDISPLAYMODE d3ddm
;
3652 IDirect3DSurface8
*surface
;
3653 IUnknown dummy_object
= {&dummy_object_vtbl
};
3655 window
= create_window();
3656 ok(!!window
, "Failed to create a window.\n");
3657 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
3658 ok(!!d3d8
, "Failed to create a D3D object.\n");
3660 hr
= IDirect3D8_GetAdapterDisplayMode(d3d8
, D3DADAPTER_DEFAULT
, &d3ddm
);
3661 ok(SUCCEEDED(hr
), "GetAdapterDisplayMode failed, hr %#x.\n", hr
);
3663 device_desc
.adapter_ordinal
= D3DADAPTER_DEFAULT
;
3664 device_desc
.device_window
= window
;
3665 device_desc
.width
= 640;
3666 device_desc
.height
= 480;
3667 device_desc
.flags
= 0;
3671 ok(cw
== 0xf60, "cw is %#x, expected 0xf60.\n", cw
);
3673 if (!(device
= create_device(d3d8
, window
, &device_desc
)))
3675 skip("Failed to create a 3D device, skipping test.\n");
3681 ok(cw
== 0x7f, "cw is %#x, expected 0x7f.\n", cw
);
3683 hr
= IDirect3DDevice8_GetRenderTarget(device
, &surface
);
3684 ok(SUCCEEDED(hr
), "Failed to get render target surface, hr %#x.\n", hr
);
3686 callback_set_cw
= 0xf60;
3687 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
,
3688 &dummy_object
, sizeof(IUnknown
*), D3DSPD_IUNKNOWN
);
3689 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
3690 ok(callback_cw
== 0x7f, "Callback cw is %#x, expected 0x7f.\n", callback_cw
);
3691 ok(callback_tid
== GetCurrentThreadId(), "Got unexpected thread id.\n");
3693 ok(cw
== 0xf60, "cw is %#x, expected 0xf60.\n", cw
);
3696 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
,
3697 &dummy_object
, sizeof(IUnknown
*), D3DSPD_IUNKNOWN
);
3698 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
3699 ok(callback_cw
== 0xf60, "Callback cw is %#x, expected 0xf60.\n", callback_cw
);
3700 ok(callback_tid
== GetCurrentThreadId(), "Got unexpected thread id.\n");
3702 callback_set_cw
= 0x7f;
3705 IDirect3DSurface8_Release(surface
);
3708 IDirect3DDevice8_Release(device
);
3709 ok(callback_cw
== 0x7f, "Callback cw is %#x, expected 0x7f.\n", callback_cw
);
3710 ok(callback_tid
== GetCurrentThreadId(), "Got unexpected thread id.\n");
3713 ok(cw
== 0x7f, "cw is %#x, expected 0x7f.\n", cw
);
3716 ok(cw
== 0xf60, "cw is %#x, expected 0xf60.\n", cw
);
3718 device_desc
.flags
= CREATE_DEVICE_FPU_PRESERVE
;
3719 device
= create_device(d3d8
, window
, &device_desc
);
3720 ok(!!device
, "CreateDevice failed.\n");
3723 ok(cw
== 0xf60, "cw is %#x, expected 0xf60.\n", cw
);
3725 hr
= IDirect3DDevice8_GetRenderTarget(device
, &surface
);
3726 ok(SUCCEEDED(hr
), "Failed to get render target surface, hr %#x.\n", hr
);
3729 callback_set_cw
= 0x37f;
3730 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
,
3731 &dummy_object
, sizeof(IUnknown
*), D3DSPD_IUNKNOWN
);
3732 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
3733 ok(callback_cw
== 0xf60, "Callback cw is %#x, expected 0xf60.\n", callback_cw
);
3734 ok(callback_tid
== GetCurrentThreadId(), "Got unexpected thread id.\n");
3736 ok(cw
== 0x37f, "cw is %#x, expected 0x37f.\n", cw
);
3738 IDirect3DSurface8_Release(surface
);
3741 IDirect3DDevice8_Release(device
);
3742 ok(callback_cw
== 0x37f, "Callback cw is %#x, expected 0x37f.\n", callback_cw
);
3743 ok(callback_tid
== GetCurrentThreadId(), "Got unexpected thread id.\n");
3746 DestroyWindow(window
);
3747 IDirect3D8_Release(d3d8
);
3751 static void test_ApplyStateBlock(void)
3753 IDirect3DDevice8
*device
;
3757 DWORD received
, token
;
3759 window
= create_window();
3760 ok(!!window
, "Failed to create a window.\n");
3761 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
3762 ok(!!d3d8
, "Failed to create a D3D object.\n");
3763 if (!(device
= create_device(d3d8
, window
, NULL
)))
3765 skip("Failed to create a 3D device, skipping test.\n");
3769 IDirect3DDevice8_BeginStateBlock(device
);
3770 IDirect3DDevice8_SetRenderState(device
, D3DRS_ZENABLE
, TRUE
);
3771 IDirect3DDevice8_EndStateBlock(device
, &token
);
3772 ok(token
, "Received zero stateblock handle.\n");
3773 IDirect3DDevice8_SetRenderState(device
, D3DRS_ZENABLE
, FALSE
);
3775 hr
= IDirect3DDevice8_GetRenderState(device
, D3DRS_ZENABLE
, &received
);
3776 ok(hr
== D3D_OK
, "Expected D3D_OK, received %#x.\n", hr
);
3777 ok(!received
, "Expected = FALSE, received TRUE.\n");
3779 hr
= IDirect3DDevice8_ApplyStateBlock(device
, 0);
3780 ok(hr
== D3D_OK
, "Expected D3D_OK, received %#x.\n", hr
);
3781 hr
= IDirect3DDevice8_GetRenderState(device
, D3DRS_ZENABLE
, &received
);
3782 ok(hr
== D3D_OK
, "Expected D3D_OK, received %#x.\n", hr
);
3783 ok(!received
, "Expected FALSE, received TRUE.\n");
3785 hr
= IDirect3DDevice8_ApplyStateBlock(device
, token
);
3786 ok(hr
== D3D_OK
, "Expected D3D_OK, received %#x.\n", hr
);
3787 hr
= IDirect3DDevice8_GetRenderState(device
, D3DRS_ZENABLE
, &received
);
3788 ok(hr
== D3D_OK
, "Expected D3D_OK, received %#x.\n", hr
);
3789 ok(received
, "Expected TRUE, received FALSE.\n");
3791 IDirect3DDevice8_DeleteStateBlock(device
, token
);
3792 IDirect3DDevice8_Release(device
);
3794 IDirect3D8_Release(d3d8
);
3795 DestroyWindow(window
);
3798 static void test_depth_stencil_size(void)
3800 IDirect3DDevice8
*device
;
3801 IDirect3DSurface8
*ds
, *rt
, *ds_bigger
, *ds_bigger2
;
3802 IDirect3DSurface8
*surf
;
3807 hwnd
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
3808 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
3809 ok(!!hwnd
, "Failed to create a window.\n");
3810 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
3811 ok(!!d3d8
, "Failed to create a D3D object.\n");
3813 if (!(device
= create_device(d3d8
, hwnd
, NULL
)))
3815 skip("Failed to create a 3D device, skipping test.\n");
3819 hr
= IDirect3DDevice8_CreateRenderTarget(device
, 64, 64, D3DFMT_A8R8G8B8
, D3DMULTISAMPLE_NONE
, FALSE
, &rt
);
3820 ok(SUCCEEDED(hr
), "IDirect3DDevice8_CreateRenderTarget failed, hr %#x.\n", hr
);
3821 hr
= IDirect3DDevice8_CreateDepthStencilSurface(device
, 32, 32, D3DFMT_D24X8
, D3DMULTISAMPLE_NONE
, &ds
);
3822 ok(SUCCEEDED(hr
), "IDirect3DDevice8_CreateDepthStencilSurface failed, hr %#x.\n", hr
);
3823 hr
= IDirect3DDevice8_CreateDepthStencilSurface(device
, 128, 128, D3DFMT_D24X8
, D3DMULTISAMPLE_NONE
, &ds_bigger
);
3824 ok(SUCCEEDED(hr
), "IDirect3DDevice8_CreateDepthStencilSurface failed, hr %#x.\n", hr
);
3825 hr
= IDirect3DDevice8_CreateDepthStencilSurface(device
, 128, 128, D3DFMT_D24X8
, D3DMULTISAMPLE_NONE
, &ds_bigger2
);
3826 ok(SUCCEEDED(hr
), "IDirect3DDevice8_CreateDepthStencilSurface failed, hr %#x.\n", hr
);
3828 hr
= IDirect3DDevice8_SetRenderTarget(device
, rt
, ds
);
3829 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_SetRenderTarget returned %#x, expected D3DERR_INVALIDCALL.\n", hr
);
3830 hr
= IDirect3DDevice8_SetRenderTarget(device
, rt
, ds_bigger
);
3831 ok(SUCCEEDED(hr
), "IDirect3DDevice8_SetRenderTarget failed, hr %#x.\n", hr
);
3833 /* try to set the small ds without changing the render target at the same time */
3834 hr
= IDirect3DDevice8_SetRenderTarget(device
, NULL
, ds
);
3835 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_SetRenderTarget returned %#x, expected D3DERR_INVALIDCALL.\n", hr
);
3836 hr
= IDirect3DDevice8_SetRenderTarget(device
, NULL
, ds_bigger2
);
3837 ok(SUCCEEDED(hr
), "IDirect3DDevice8_SetRenderTarget failed, hr %#x.\n", hr
);
3839 hr
= IDirect3DDevice8_GetRenderTarget(device
, &surf
);
3840 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetRenderTarget failed, hr %#x.\n", hr
);
3841 ok(surf
== rt
, "The render target is %p, expected %p\n", surf
, rt
);
3842 IDirect3DSurface8_Release(surf
);
3843 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &surf
);
3844 ok(hr
== D3D_OK
, "IDirect3DDevice8_GetDepthStencilSurface failed, hr %#x.\n", hr
);
3845 ok(surf
== ds_bigger2
, "The depth stencil is %p, expected %p\n", surf
, ds_bigger2
);
3846 IDirect3DSurface8_Release(surf
);
3848 hr
= IDirect3DDevice8_SetRenderTarget(device
, NULL
, NULL
);
3849 ok(SUCCEEDED(hr
), "IDirect3DDevice8_SetRenderTarget failed, hr %#x.\n", hr
);
3850 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &surf
);
3851 ok(FAILED(hr
), "IDirect3DDevice8_GetDepthStencilSurface should have failed, hr %#x.\n", hr
);
3852 ok(surf
== NULL
, "The depth stencil is %p, expected NULL\n", surf
);
3853 if (surf
) IDirect3DSurface8_Release(surf
);
3855 IDirect3DSurface8_Release(rt
);
3856 IDirect3DSurface8_Release(ds
);
3857 IDirect3DSurface8_Release(ds_bigger
);
3858 IDirect3DSurface8_Release(ds_bigger2
);
3861 IDirect3D8_Release(d3d8
);
3862 DestroyWindow(hwnd
);
3865 static void test_window_style(void)
3867 RECT focus_rect
, fullscreen_rect
, r
;
3868 LONG device_style
, device_exstyle
;
3869 LONG focus_style
, focus_exstyle
;
3870 struct device_desc device_desc
;
3871 LONG style
, expected_style
;
3872 IDirect3DDevice8
*device
;
3878 focus_window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
3879 0, 0, registry_mode
.dmPelsWidth
/ 2, registry_mode
.dmPelsHeight
/ 2, 0, 0, 0, 0);
3880 device_window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
3881 0, 0, registry_mode
.dmPelsWidth
/ 2, registry_mode
.dmPelsHeight
/ 2, 0, 0, 0, 0);
3882 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
3883 ok(!!d3d8
, "Failed to create a D3D object.\n");
3885 device_style
= GetWindowLongA(device_window
, GWL_STYLE
);
3886 device_exstyle
= GetWindowLongA(device_window
, GWL_EXSTYLE
);
3887 focus_style
= GetWindowLongA(focus_window
, GWL_STYLE
);
3888 focus_exstyle
= GetWindowLongA(focus_window
, GWL_EXSTYLE
);
3890 SetRect(&fullscreen_rect
, 0, 0, registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
);
3891 GetWindowRect(focus_window
, &focus_rect
);
3893 device_desc
.adapter_ordinal
= D3DADAPTER_DEFAULT
;
3894 device_desc
.device_window
= device_window
;
3895 device_desc
.width
= registry_mode
.dmPelsWidth
;
3896 device_desc
.height
= registry_mode
.dmPelsHeight
;
3897 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
3898 if (!(device
= create_device(d3d8
, focus_window
, &device_desc
)))
3900 skip("Failed to create a D3D device, skipping tests.\n");
3904 style
= GetWindowLongA(device_window
, GWL_STYLE
);
3905 expected_style
= device_style
| WS_VISIBLE
;
3906 todo_wine
ok(style
== expected_style
|| broken(style
== (expected_style
& ~WS_OVERLAPPEDWINDOW
)) /* w1064v1809 */,
3907 "Expected device window style %#x, got %#x.\n",
3908 expected_style
, style
);
3909 style
= GetWindowLongA(device_window
, GWL_EXSTYLE
);
3910 expected_style
= device_exstyle
| WS_EX_TOPMOST
;
3911 todo_wine
ok(style
== expected_style
|| broken(style
== (expected_style
& ~WS_EX_OVERLAPPEDWINDOW
)) /* w1064v1809 */,
3912 "Expected device window extended style %#x, got %#x.\n",
3913 expected_style
, style
);
3915 style
= GetWindowLongA(focus_window
, GWL_STYLE
);
3916 ok(style
== focus_style
, "Expected focus window style %#x, got %#x.\n",
3917 focus_style
, style
);
3918 style
= GetWindowLongA(focus_window
, GWL_EXSTYLE
);
3919 ok(style
== focus_exstyle
, "Expected focus window extended style %#x, got %#x.\n",
3920 focus_exstyle
, style
);
3922 GetWindowRect(device_window
, &r
);
3923 ok(EqualRect(&r
, &fullscreen_rect
), "Expected %s, got %s.\n",
3924 wine_dbgstr_rect(&fullscreen_rect
), wine_dbgstr_rect(&r
));
3925 GetClientRect(device_window
, &r
);
3926 todo_wine
ok(!EqualRect(&r
, &fullscreen_rect
) || broken(!(style
& WS_THICKFRAME
)) /* w1064v1809 */,
3927 "Client rect and window rect are equal.\n");
3928 GetWindowRect(focus_window
, &r
);
3929 ok(EqualRect(&r
, &focus_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&focus_rect
),
3930 wine_dbgstr_rect(&r
));
3932 device_desc
.flags
= 0;
3933 hr
= reset_device(device
, &device_desc
);
3934 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
3936 style
= GetWindowLongA(device_window
, GWL_STYLE
);
3937 expected_style
= device_style
| WS_VISIBLE
;
3938 ok(style
== expected_style
, "Expected device window style %#x, got %#x.\n",
3939 expected_style
, style
);
3940 style
= GetWindowLongA(device_window
, GWL_EXSTYLE
);
3941 expected_style
= device_exstyle
| WS_EX_TOPMOST
;
3942 ok(style
== expected_style
, "Expected device window extended style %#x, got %#x.\n",
3943 expected_style
, style
);
3945 style
= GetWindowLongA(focus_window
, GWL_STYLE
);
3946 ok(style
== focus_style
, "Expected focus window style %#x, got %#x.\n",
3947 focus_style
, style
);
3948 style
= GetWindowLongA(focus_window
, GWL_EXSTYLE
);
3949 ok(style
== focus_exstyle
, "Expected focus window extended style %#x, got %#x.\n",
3950 focus_exstyle
, style
);
3952 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
3953 hr
= reset_device(device
, &device_desc
);
3954 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
3955 ret
= SetForegroundWindow(GetDesktopWindow());
3956 ok(ret
, "Failed to set foreground window.\n");
3958 style
= GetWindowLongA(device_window
, GWL_STYLE
);
3959 expected_style
= device_style
| WS_MINIMIZE
| WS_VISIBLE
;
3960 todo_wine
ok(style
== expected_style
, "Expected device window style %#x, got %#x.\n",
3961 expected_style
, style
);
3962 style
= GetWindowLongA(device_window
, GWL_EXSTYLE
);
3963 expected_style
= device_exstyle
| WS_EX_TOPMOST
;
3964 todo_wine
ok(style
== expected_style
, "Expected device window extended style %#x, got %#x.\n",
3965 expected_style
, style
);
3967 style
= GetWindowLongA(focus_window
, GWL_STYLE
);
3968 ok(style
== focus_style
, "Expected focus window style %#x, got %#x.\n",
3969 focus_style
, style
);
3970 style
= GetWindowLongA(focus_window
, GWL_EXSTYLE
);
3971 ok(style
== focus_exstyle
, "Expected focus window extended style %#x, got %#x.\n",
3972 focus_exstyle
, style
);
3974 /* Follow-up tests fail on native if the device is destroyed while lost. */
3975 ShowWindow(focus_window
, SW_MINIMIZE
);
3976 ShowWindow(focus_window
, SW_RESTORE
);
3977 ret
= SetForegroundWindow(focus_window
);
3978 ok(ret
, "Failed to set foreground window.\n");
3980 hr
= reset_device(device
, &device_desc
);
3981 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
3983 ref
= IDirect3DDevice8_Release(device
);
3984 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
3987 IDirect3D8_Release(d3d8
);
3989 DestroyWindow(device_window
);
3990 DestroyWindow(focus_window
);
3993 static void test_unsupported_shaders(void)
3995 IDirect3DDevice8
*device
;
4003 static const DWORD vs_2_0
[] =
4005 0xfffe0200, /* vs_2_0 */
4006 0x0200001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
4007 0x02000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
4008 0x03000002, 0xd00f0000, 0x80e40001, 0xa0e40002, /* add oD0, r1, c2 */
4009 0x02000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
4010 0x0000ffff /* end */
4012 static const DWORD ps_2_0
[] =
4014 0xffff0200, /* ps_2_0 */
4015 0x02000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
4016 0x03000002, 0x800f0000, 0x80e40001, 0xa0e40002, /* add r0, r1, c2 */
4017 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
4018 0x0000ffff /* end */
4023 def c255
, 1.0, 1.0, 1.0, 1.0
4027 static const DWORD vs_1_255
[] =
4030 0x0000001f, 0x80000000, 0x900f0000,
4031 0x00000051, 0xa00f00ff, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
4032 0x00000002, 0x800f0000, 0x90e40000, 0xa0e400ff,
4033 0x00000001, 0xc00f0000, 0x80e40000,
4039 def c256
, 1.0, 1.0, 1.0, 1.0
4043 static const DWORD vs_1_256
[] =
4046 0x0000001f, 0x80000000, 0x900f0000,
4047 0x00000051, 0xa00f0100, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
4048 0x00000002, 0x800f0000, 0x90e40000, 0xa0e40100,
4049 0x00000001, 0xc00f0000, 0x80e40000,
4053 static const DWORD decl
[] =
4056 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT3
),
4060 window
= create_window();
4061 ok(!!window
, "Failed to create a window.\n");
4062 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
4063 ok(!!d3d
, "Failed to create a D3D object.\n");
4064 if (!(device
= create_device(d3d
, window
, NULL
)))
4066 skip("Failed to create a D3D device, skipping tests.\n");
4067 IDirect3D8_Release(d3d
);
4068 DestroyWindow(window
);
4072 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl
, simple_ps
, &vs
, 0);
4073 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
4075 hr
= IDirect3DDevice8_CreatePixelShader(device
, simple_vs
, &ps
);
4076 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr
);
4078 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl
, vs_2_0
, &vs
, 0);
4079 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_CreateVertexShader returned %#08x\n", hr
);
4081 hr
= IDirect3DDevice8_CreatePixelShader(device
, ps_2_0
, &ps
);
4082 ok(hr
== D3DERR_INVALIDCALL
, "IDirect3DDevice8_CreatePixelShader returned %#08x\n", hr
);
4084 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
4085 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
4086 if (caps
.MaxVertexShaderConst
< 256)
4088 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl
, vs_1_255
, &vs
, 0);
4089 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
4093 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl
, vs_1_255
, &vs
, 0);
4094 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
4095 hr
= IDirect3DDevice8_DeleteVertexShader(device
, vs
);
4096 ok(hr
== D3D_OK
, "IDirect3DDevice8_DeleteVertexShader returned %#08x\n", hr
);
4097 hr
= IDirect3DDevice8_CreateVertexShader(device
, decl
, vs_1_256
, &vs
, 0);
4098 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
4101 refcount
= IDirect3DDevice8_Release(device
);
4102 ok(!refcount
, "Device has %u references left.\n", refcount
);
4103 IDirect3D8_Release(d3d
);
4104 DestroyWindow(window
);
4107 static void test_mode_change(void)
4109 RECT d3d_rect
, focus_rect
, r
;
4110 struct device_desc device_desc
;
4111 IDirect3DSurface8
*backbuffer
;
4112 IDirect3DDevice8
*device
;
4113 D3DSURFACE_DESC desc
;
4117 UINT adapter_mode_count
, i
;
4121 D3DDISPLAYMODE d3ddm
;
4122 DWORD d3d_width
= 0, d3d_height
= 0, user32_width
= 0, user32_height
= 0;
4124 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
4125 ok(!!d3d8
, "Failed to create a D3D object.\n");
4127 adapter_mode_count
= IDirect3D8_GetAdapterModeCount(d3d8
, D3DADAPTER_DEFAULT
);
4128 for (i
= 0; i
< adapter_mode_count
; ++i
)
4130 hr
= IDirect3D8_EnumAdapterModes(d3d8
, D3DADAPTER_DEFAULT
, i
, &d3ddm
);
4131 ok(SUCCEEDED(hr
), "Failed to enumerate display mode, hr %#x.\n", hr
);
4133 if (d3ddm
.Format
!= D3DFMT_X8R8G8B8
)
4135 if (d3ddm
.Width
== registry_mode
.dmPelsWidth
&& d3ddm
.Height
== registry_mode
.dmPelsHeight
)
4137 /* The r200 driver on Windows XP enumerates modes like 320x200 and 320x240 but
4138 * refuses to create a device at these sizes. */
4139 if (d3ddm
.Width
< 640 || d3ddm
.Height
< 480)
4144 user32_width
= d3ddm
.Width
;
4145 user32_height
= d3ddm
.Height
;
4149 /* Make sure the d3d mode is smaller in width or height and at most
4150 * equal in the other dimension than the mode passed to
4151 * ChangeDisplaySettings. Otherwise Windows shrinks the window to
4152 * the ChangeDisplaySettings parameters + 12. */
4153 if (d3ddm
.Width
== user32_width
&& d3ddm
.Height
== user32_height
)
4155 if (d3ddm
.Width
<= user32_width
&& d3ddm
.Height
<= user32_height
)
4157 d3d_width
= d3ddm
.Width
;
4158 d3d_height
= d3ddm
.Height
;
4161 if (user32_width
<= d3ddm
.Width
&& user32_height
<= d3ddm
.Height
)
4163 d3d_width
= user32_width
;
4164 d3d_height
= user32_height
;
4165 user32_width
= d3ddm
.Width
;
4166 user32_height
= d3ddm
.Height
;
4173 skip("Could not find adequate modes, skipping mode tests.\n");
4174 IDirect3D8_Release(d3d8
);
4178 memset(&devmode
, 0, sizeof(devmode
));
4179 devmode
.dmSize
= sizeof(devmode
);
4180 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
4181 devmode
.dmPelsWidth
= user32_width
;
4182 devmode
.dmPelsHeight
= user32_height
;
4183 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
4184 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
4186 /* Make the windows visible, otherwise device::release does not restore the mode if
4187 * the application is not in foreground like on the testbot. */
4188 focus_window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
4189 0, 0, user32_width
/ 2, user32_height
/ 2, 0, 0, 0, 0);
4190 device_window
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
4191 0, 0, user32_width
/ 2, user32_height
/ 2, 0, 0, 0, 0);
4193 SetRect(&d3d_rect
, 0, 0, d3d_width
, d3d_height
);
4194 GetWindowRect(focus_window
, &focus_rect
);
4196 device_desc
.adapter_ordinal
= D3DADAPTER_DEFAULT
;
4197 device_desc
.device_window
= device_window
;
4198 device_desc
.width
= d3d_width
;
4199 device_desc
.height
= d3d_height
;
4200 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
4201 if (!(device
= create_device(d3d8
, focus_window
, &device_desc
)))
4203 skip("Failed to create a D3D device, skipping tests.\n");
4204 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
4205 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
4209 devmode
.dmPelsWidth
= user32_width
;
4210 devmode
.dmPelsHeight
= user32_height
;
4211 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
4212 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
4214 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
4215 ok(ret
, "Failed to get display mode.\n");
4216 ok(devmode
.dmPelsWidth
== user32_width
&& devmode
.dmPelsHeight
== user32_height
,
4217 "Expected resolution %ux%u, got %ux%u.\n",
4218 user32_width
, user32_height
, devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
4220 GetWindowRect(device_window
, &r
);
4221 ok(EqualRect(&r
, &d3d_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&d3d_rect
),
4222 wine_dbgstr_rect(&r
));
4223 GetWindowRect(focus_window
, &r
);
4224 ok(EqualRect(&r
, &focus_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&focus_rect
),
4225 wine_dbgstr_rect(&r
));
4227 hr
= IDirect3DDevice8_GetBackBuffer(device
, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
4228 ok(SUCCEEDED(hr
), "Failed to get backbuffer, hr %#x.\n", hr
);
4229 hr
= IDirect3DSurface8_GetDesc(backbuffer
, &desc
);
4230 ok(SUCCEEDED(hr
), "Failed to get backbuffer desc, hr %#x.\n", hr
);
4231 ok(desc
.Width
== d3d_width
, "Got unexpected backbuffer width %u, expected %u.\n",
4232 desc
.Width
, d3d_width
);
4233 ok(desc
.Height
== d3d_height
, "Got unexpected backbuffer height %u, expected %u.\n",
4234 desc
.Height
, d3d_height
);
4235 IDirect3DSurface8_Release(backbuffer
);
4237 refcount
= IDirect3DDevice8_Release(device
);
4238 ok(!refcount
, "Device has %u references left.\n", refcount
);
4240 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
4241 ok(ret
, "Failed to get display mode.\n");
4242 todo_wine
ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
4243 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
,
4244 "Expected resolution %ux%u, got %ux%u.\n",
4245 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
, devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
4247 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
4248 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
4250 /* The mode restore also happens when the device was created at the original screen size. */
4252 device_desc
.adapter_ordinal
= D3DADAPTER_DEFAULT
;
4253 device_desc
.device_window
= device_window
;
4254 device_desc
.width
= registry_mode
.dmPelsWidth
;
4255 device_desc
.height
= registry_mode
.dmPelsHeight
;
4256 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
4257 ok(!!(device
= create_device(d3d8
, focus_window
, &device_desc
)), "Failed to create a D3D device.\n");
4259 devmode
.dmPelsWidth
= user32_width
;
4260 devmode
.dmPelsHeight
= user32_height
;
4261 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
4262 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
4264 refcount
= IDirect3DDevice8_Release(device
);
4265 ok(!refcount
, "Device has %u references left.\n", refcount
);
4267 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
4268 ok(ret
, "Failed to get display mode.\n");
4269 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
4270 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
,
4271 "Expected resolution %ux%u, got %ux%u.\n",
4272 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
, devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
4275 DestroyWindow(device_window
);
4276 DestroyWindow(focus_window
);
4277 IDirect3D8_Release(d3d8
);
4280 static void test_device_window_reset(void)
4282 RECT fullscreen_rect
, device_rect
, r
;
4283 struct device_desc device_desc
;
4284 IDirect3DDevice8
*device
;
4291 filter_messages
= NULL
;
4292 expect_messages
= NULL
;
4294 wc
.lpfnWndProc
= test_proc
;
4295 wc
.lpszClassName
= "d3d8_test_wndproc_wc";
4296 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
4298 focus_window
= CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
4299 0, 0, registry_mode
.dmPelsWidth
/ 2, registry_mode
.dmPelsHeight
/ 2, 0, 0, 0, 0);
4300 device_window
= CreateWindowA("d3d8_test_wndproc_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
4301 0, 0, registry_mode
.dmPelsWidth
/ 2, registry_mode
.dmPelsHeight
/ 2, 0, 0, 0, 0);
4302 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
4303 ok(!!d3d8
, "Failed to create a D3D object.\n");
4305 SetRect(&fullscreen_rect
, 0, 0, registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
);
4306 GetWindowRect(device_window
, &device_rect
);
4308 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
4309 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
4310 (LONG_PTR
)test_proc
, proc
);
4311 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
4312 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
4313 (LONG_PTR
)test_proc
, proc
);
4315 device_desc
.adapter_ordinal
= D3DADAPTER_DEFAULT
;
4316 device_desc
.device_window
= NULL
;
4317 device_desc
.width
= registry_mode
.dmPelsWidth
;
4318 device_desc
.height
= registry_mode
.dmPelsHeight
;
4319 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
4320 if (!(device
= create_device(d3d8
, focus_window
, &device_desc
)))
4322 skip("Failed to create a D3D device, skipping tests.\n");
4326 GetWindowRect(focus_window
, &r
);
4327 ok(EqualRect(&r
, &fullscreen_rect
), "Expected %s, got %s.\n",
4328 wine_dbgstr_rect(&fullscreen_rect
), wine_dbgstr_rect(&r
));
4329 GetWindowRect(device_window
, &r
);
4330 ok(EqualRect(&r
, &device_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&device_rect
),
4331 wine_dbgstr_rect(&r
));
4333 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
4334 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
4335 (LONG_PTR
)test_proc
, proc
);
4336 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
4337 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx.\n", (LONG_PTR
)test_proc
);
4339 device_desc
.device_window
= device_window
;
4340 hr
= reset_device(device
, &device_desc
);
4341 ok(SUCCEEDED(hr
), "Failed to reset device.\n");
4343 GetWindowRect(focus_window
, &r
);
4344 ok(EqualRect(&r
, &fullscreen_rect
), "Expected %s, got %s.\n",
4345 wine_dbgstr_rect(&fullscreen_rect
), wine_dbgstr_rect(&r
));
4346 GetWindowRect(device_window
, &r
);
4347 ok(EqualRect(&r
, &fullscreen_rect
), "Expected %s, got %s.\n",
4348 wine_dbgstr_rect(&fullscreen_rect
), wine_dbgstr_rect(&r
));
4350 proc
= GetWindowLongPtrA(device_window
, GWLP_WNDPROC
);
4351 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
4352 (LONG_PTR
)test_proc
, proc
);
4353 proc
= GetWindowLongPtrA(focus_window
, GWLP_WNDPROC
);
4354 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx.\n", (LONG_PTR
)test_proc
);
4356 ref
= IDirect3DDevice8_Release(device
);
4357 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
4360 IDirect3D8_Release(d3d8
);
4361 DestroyWindow(device_window
);
4362 DestroyWindow(focus_window
);
4363 UnregisterClassA("d3d8_test_wndproc_wc", GetModuleHandleA(NULL
));
4366 static void depth_blit_test(void)
4368 IDirect3DDevice8
*device
= NULL
;
4369 IDirect3DSurface8
*backbuffer
, *ds1
, *ds2
, *ds3
;
4371 const POINT dst_point
= {0, 0};
4376 hwnd
= CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW
,
4377 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
4378 ok(!!hwnd
, "Failed to create a window.\n");
4379 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
4380 ok(!!d3d8
, "Failed to create a D3D object.\n");
4382 if (!(device
= create_device(d3d8
, hwnd
, NULL
)))
4384 skip("Failed to create a D3D device, skipping tests.\n");
4388 hr
= IDirect3DDevice8_GetRenderTarget(device
, &backbuffer
);
4389 ok(SUCCEEDED(hr
), "GetRenderTarget failed, hr %#x.\n", hr
);
4390 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &ds1
);
4391 ok(SUCCEEDED(hr
), "GetDepthStencilSurface failed, hr %#x.\n", hr
);
4392 hr
= IDirect3DDevice8_CreateDepthStencilSurface(device
, 640, 480, D3DFMT_D24S8
, D3DMULTISAMPLE_NONE
, &ds2
);
4393 ok(SUCCEEDED(hr
), "CreateDepthStencilSurface failed, hr %#x.\n", hr
);
4394 hr
= IDirect3DDevice8_CreateDepthStencilSurface(device
, 640, 480, D3DFMT_D24S8
, D3DMULTISAMPLE_NONE
, &ds3
);
4395 ok(SUCCEEDED(hr
), "CreateDepthStencilSurface failed, hr %#x.\n", hr
);
4397 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_ZBUFFER
, 0, 0.0f
, 0);
4398 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
4401 SetRect(&src_rect
, 0, 0, 320, 240);
4402 hr
= IDirect3DDevice8_CopyRects(device
, ds1
, &src_rect
, 1, ds2
, &dst_point
);
4403 ok(hr
== D3DERR_INVALIDCALL
, "CopyRects returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
4405 SetRect(&src_rect
, 0, 480, 640, 0);
4406 hr
= IDirect3DDevice8_CopyRects(device
, ds1
, &src_rect
, 1, ds2
, &dst_point
);
4407 ok(hr
== D3DERR_INVALIDCALL
, "CopyRects returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
4408 /* Full, explicit. */
4409 SetRect(&src_rect
, 0, 0, 640, 480);
4410 hr
= IDirect3DDevice8_CopyRects(device
, ds1
, &src_rect
, 1, ds2
, &dst_point
);
4411 ok(hr
== D3DERR_INVALIDCALL
, "CopyRects returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
4412 /* Depth -> color blit.*/
4413 hr
= IDirect3DDevice8_CopyRects(device
, ds1
, &src_rect
, 1, backbuffer
, &dst_point
);
4414 ok(hr
== D3DERR_INVALIDCALL
, "CopyRects returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
4415 /* Full, NULL rects, current depth stencil -> unbound depth stencil */
4416 hr
= IDirect3DDevice8_CopyRects(device
, ds1
, NULL
, 0, ds2
, NULL
);
4417 ok(hr
== D3DERR_INVALIDCALL
, "CopyRects returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
4418 /* Full, NULL rects, unbound depth stencil -> current depth stencil */
4419 hr
= IDirect3DDevice8_CopyRects(device
, ds2
, NULL
, 0, ds1
, NULL
);
4420 ok(hr
== D3DERR_INVALIDCALL
, "CopyRects returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
4421 /* Full, NULL rects, unbound depth stencil -> unbound depth stencil */
4422 hr
= IDirect3DDevice8_CopyRects(device
, ds2
, NULL
, 0, ds3
, NULL
);
4423 ok(hr
== D3DERR_INVALIDCALL
, "CopyRects returned %#x, expected %#x.\n", hr
, D3DERR_INVALIDCALL
);
4425 IDirect3DSurface8_Release(backbuffer
);
4426 IDirect3DSurface8_Release(ds3
);
4427 IDirect3DSurface8_Release(ds2
);
4428 IDirect3DSurface8_Release(ds1
);
4431 if (device
) IDirect3DDevice8_Release(device
);
4432 IDirect3D8_Release(d3d8
);
4433 DestroyWindow(hwnd
);
4436 static void test_reset_resources(void)
4438 IDirect3DSurface8
*surface
, *rt
;
4439 IDirect3DTexture8
*texture
;
4440 IDirect3DDevice8
*device
;
4446 window
= create_window();
4447 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
4448 ok(!!d3d8
, "Failed to create a D3D object.\n");
4450 if (!(device
= create_device(d3d8
, window
, NULL
)))
4452 skip("Failed to create a D3D device, skipping tests.\n");
4456 hr
= IDirect3DDevice8_CreateDepthStencilSurface(device
, 128, 128, D3DFMT_D24S8
,
4457 D3DMULTISAMPLE_NONE
, &surface
);
4458 ok(SUCCEEDED(hr
), "Failed to create depth/stencil surface, hr %#x.\n", hr
);
4460 hr
= IDirect3DDevice8_CreateTexture(device
, 128, 128, 1, D3DUSAGE_RENDERTARGET
,
4461 D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &texture
);
4462 ok(SUCCEEDED(hr
), "Failed to create render target texture, hr %#x.\n", hr
);
4463 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 0, &rt
);
4464 ok(SUCCEEDED(hr
), "Failed to get surface, hr %#x.\n", hr
);
4465 IDirect3DTexture8_Release(texture
);
4467 hr
= IDirect3DDevice8_SetRenderTarget(device
, rt
, surface
);
4468 ok(SUCCEEDED(hr
), "Failed to set render target surface, hr %#x.\n", hr
);
4469 IDirect3DSurface8_Release(rt
);
4470 IDirect3DSurface8_Release(surface
);
4472 hr
= reset_device(device
, NULL
);
4473 ok(SUCCEEDED(hr
), "Failed to reset device.\n");
4475 hr
= IDirect3DDevice8_GetBackBuffer(device
, 0, D3DBACKBUFFER_TYPE_MONO
, &rt
);
4476 ok(SUCCEEDED(hr
), "Failed to get back buffer, hr %#x.\n", hr
);
4477 hr
= IDirect3DDevice8_GetRenderTarget(device
, &surface
);
4478 ok(SUCCEEDED(hr
), "Failed to get render target surface, hr %#x.\n", hr
);
4479 ok(surface
== rt
, "Got unexpected surface %p for render target.\n", surface
);
4480 IDirect3DSurface8_Release(surface
);
4481 IDirect3DSurface8_Release(rt
);
4483 ref
= IDirect3DDevice8_Release(device
);
4484 ok(ref
== 0, "The device was not properly freed: refcount %u.\n", ref
);
4487 IDirect3D8_Release(d3d8
);
4488 DestroyWindow(window
);
4491 static void test_set_rt_vp_scissor(void)
4493 IDirect3DDevice8
*device
;
4494 IDirect3DSurface8
*rt
;
4502 window
= create_window();
4503 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
4504 ok(!!d3d8
, "Failed to create a D3D object.\n");
4505 if (!(device
= create_device(d3d8
, window
, NULL
)))
4507 skip("Failed to create a D3D device, skipping tests.\n");
4508 IDirect3D8_Release(d3d8
);
4509 DestroyWindow(window
);
4513 hr
= IDirect3DDevice8_CreateRenderTarget(device
, 128, 128, D3DFMT_A8R8G8B8
,
4514 D3DMULTISAMPLE_NONE
, FALSE
, &rt
);
4515 ok(SUCCEEDED(hr
), "Failed to create render target, hr %#x.\n", hr
);
4517 hr
= IDirect3DDevice8_GetViewport(device
, &vp
);
4518 ok(SUCCEEDED(hr
), "Failed to get viewport, hr %#x.\n", hr
);
4519 ok(!vp
.X
, "Got unexpected vp.X %u.\n", vp
.X
);
4520 ok(!vp
.Y
, "Got unexpected vp.Y %u.\n", vp
.Y
);
4521 ok(vp
.Width
== 640, "Got unexpected vp.Width %u.\n", vp
.Width
);
4522 ok(vp
.Height
== 480, "Got unexpected vp.Height %u.\n", vp
.Height
);
4523 ok(vp
.MinZ
== 0.0f
, "Got unexpected vp.MinZ %.8e.\n", vp
.MinZ
);
4524 ok(vp
.MaxZ
== 1.0f
, "Got unexpected vp.MaxZ %.8e.\n", vp
.MaxZ
);
4526 hr
= IDirect3DDevice8_BeginStateBlock(device
);
4527 ok(SUCCEEDED(hr
), "Failed to begin stateblock, hr %#x.\n", hr
);
4529 hr
= IDirect3DDevice8_SetRenderTarget(device
, rt
, NULL
);
4530 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
4532 hr
= IDirect3DDevice8_EndStateBlock(device
, &stateblock
);
4533 ok(SUCCEEDED(hr
), "Failed to end stateblock, hr %#x.\n", hr
);
4534 hr
= IDirect3DDevice8_DeleteStateBlock(device
, stateblock
);
4535 ok(SUCCEEDED(hr
), "Failed to delete stateblock, hr %#x.\n", hr
);
4537 hr
= IDirect3DDevice8_GetViewport(device
, &vp
);
4538 ok(SUCCEEDED(hr
), "Failed to get viewport, hr %#x.\n", hr
);
4539 ok(!vp
.X
, "Got unexpected vp.X %u.\n", vp
.X
);
4540 ok(!vp
.Y
, "Got unexpected vp.Y %u.\n", vp
.Y
);
4541 ok(vp
.Width
== 128, "Got unexpected vp.Width %u.\n", vp
.Width
);
4542 ok(vp
.Height
== 128, "Got unexpected vp.Height %u.\n", vp
.Height
);
4543 ok(vp
.MinZ
== 0.0f
, "Got unexpected vp.MinZ %.8e.\n", vp
.MinZ
);
4544 ok(vp
.MaxZ
== 1.0f
, "Got unexpected vp.MaxZ %.8e.\n", vp
.MaxZ
);
4546 hr
= IDirect3DDevice8_SetRenderTarget(device
, rt
, NULL
);
4547 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
4555 hr
= IDirect3DDevice8_SetViewport(device
, &vp
);
4556 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
4558 hr
= IDirect3DDevice8_SetRenderTarget(device
, rt
, NULL
);
4559 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
4561 hr
= IDirect3DDevice8_GetViewport(device
, &vp
);
4562 ok(SUCCEEDED(hr
), "Failed to get viewport, hr %#x.\n", hr
);
4563 ok(!vp
.X
, "Got unexpected vp.X %u.\n", vp
.X
);
4564 ok(!vp
.Y
, "Got unexpected vp.Y %u.\n", vp
.Y
);
4565 ok(vp
.Width
== 128, "Got unexpected vp.Width %u.\n", vp
.Width
);
4566 ok(vp
.Height
== 128, "Got unexpected vp.Height %u.\n", vp
.Height
);
4567 ok(vp
.MinZ
== 0.0f
, "Got unexpected vp.MinZ %.8e.\n", vp
.MinZ
);
4568 ok(vp
.MaxZ
== 1.0f
, "Got unexpected vp.MaxZ %.8e.\n", vp
.MaxZ
);
4570 IDirect3DSurface8_Release(rt
);
4571 refcount
= IDirect3DDevice8_Release(device
);
4572 ok(!refcount
, "Device has %u references left.\n", refcount
);
4573 IDirect3D8_Release(d3d8
);
4574 DestroyWindow(window
);
4577 static void test_validate_vs(void)
4579 static DWORD vs_code
[] =
4581 0xfffe0101, /* vs_1_1 */
4582 0x00000009, 0xc0010000, 0x90e40000, 0xa0e40000, /* dp4 oPos.x, v0, c0 */
4583 0x00000009, 0xc0020000, 0x90e40000, 0xa0e40001, /* dp4 oPos.y, v0, c1 */
4584 0x00000009, 0xc0040000, 0x90e40000, 0xa0e40002, /* dp4 oPos.z, v0, c2 */
4585 0x00000009, 0xc0080000, 0x90e40000, 0xa0e40003, /* dp4 oPos.w, v0, c3 */
4586 0x0000ffff, /* end */
4592 static DWORD declaration_valid1
[] =
4595 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT4
),
4598 static DWORD declaration_valid2
[] =
4601 D3DVSD_REG(D3DVSDE_POSITION
, D3DVSDT_FLOAT2
),
4604 static DWORD declaration_invalid
[] =
4607 D3DVSD_REG(D3DVSDE_NORMAL
, D3DVSDT_FLOAT4
),
4611 hr
= ValidateVertexShader(NULL
, NULL
, NULL
, FALSE
, NULL
);
4612 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
4613 hr
= ValidateVertexShader(NULL
, NULL
, NULL
, TRUE
, NULL
);
4614 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
4615 hr
= ValidateVertexShader(NULL
, NULL
, NULL
, FALSE
, &errors
);
4616 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
4617 ok(!*errors
, "Got unexpected string \"%s\".\n", errors
);
4619 hr
= ValidateVertexShader(NULL
, NULL
, NULL
, TRUE
, &errors
);
4620 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
4621 ok(!!*errors
, "Got unexpected empty string.\n");
4624 hr
= ValidateVertexShader(vs_code
, NULL
, NULL
, FALSE
, NULL
);
4625 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
4626 hr
= ValidateVertexShader(vs_code
, NULL
, NULL
, TRUE
, NULL
);
4627 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
4628 hr
= ValidateVertexShader(vs_code
, NULL
, NULL
, TRUE
, &errors
);
4629 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
4630 ok(!*errors
, "Got unexpected string \"%s\".\n", errors
);
4633 hr
= ValidateVertexShader(vs_code
, declaration_valid1
, NULL
, FALSE
, NULL
);
4634 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
4635 hr
= ValidateVertexShader(vs_code
, declaration_valid2
, NULL
, FALSE
, NULL
);
4636 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
4637 hr
= ValidateVertexShader(vs_code
, declaration_invalid
, NULL
, FALSE
, NULL
);
4638 todo_wine
ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
4640 memset(&caps
, 0, sizeof(caps
));
4641 caps
.VertexShaderVersion
= D3DVS_VERSION(1, 1);
4642 caps
.MaxVertexShaderConst
= 4;
4643 hr
= ValidateVertexShader(vs_code
, NULL
, &caps
, FALSE
, NULL
);
4644 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
4645 caps
.VertexShaderVersion
= D3DVS_VERSION(1, 0);
4646 hr
= ValidateVertexShader(vs_code
, NULL
, &caps
, FALSE
, NULL
);
4647 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
4648 caps
.VertexShaderVersion
= D3DVS_VERSION(1, 2);
4649 hr
= ValidateVertexShader(vs_code
, NULL
, &caps
, FALSE
, NULL
);
4650 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
4651 caps
.VertexShaderVersion
= D3DVS_VERSION(8, 8);
4652 hr
= ValidateVertexShader(vs_code
, NULL
, &caps
, FALSE
, NULL
);
4653 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
4654 caps
.VertexShaderVersion
= D3DVS_VERSION(1, 1);
4655 caps
.MaxVertexShaderConst
= 3;
4656 hr
= ValidateVertexShader(vs_code
, NULL
, &caps
, FALSE
, NULL
);
4657 todo_wine
ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
4659 *vs_code
= D3DVS_VERSION(1, 0);
4660 hr
= ValidateVertexShader(vs_code
, NULL
, NULL
, FALSE
, NULL
);
4661 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
4662 *vs_code
= D3DVS_VERSION(1, 2);
4663 hr
= ValidateVertexShader(vs_code
, NULL
, NULL
, TRUE
, NULL
);
4664 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
4665 hr
= ValidateVertexShader(vs_code
, NULL
, NULL
, FALSE
, &errors
);
4666 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
4667 ok(!*errors
, "Got unexpected string \"%s\".\n", errors
);
4669 hr
= ValidateVertexShader(vs_code
, NULL
, NULL
, TRUE
, &errors
);
4670 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
4671 ok(!!*errors
, "Got unexpected empty string.\n");
4675 static void test_validate_ps(void)
4677 static DWORD ps_1_1_code
[] =
4679 0xffff0101, /* ps_1_1 */
4680 0x00000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
4681 0x00000002, 0x800f0000, 0x80e40001, 0xa0e40002, /* add r0, r1, c2 */
4682 0x0000ffff /* end */
4684 static const DWORD ps_2_0_code
[] =
4686 0xffff0200, /* ps_2_0 */
4687 0x02000001, 0x800f0001, 0xa0e40001, /* mov r1, c1 */
4688 0x03000002, 0x800f0000, 0x80e40001, 0xa0e40002, /* add r0, r1, c2 */
4689 0x02000001, 0x800f0800, 0x80e40000, /* mov oC0, r0 */
4690 0x0000ffff /* end */
4696 hr
= ValidatePixelShader(NULL
, NULL
, FALSE
, NULL
);
4697 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
4698 hr
= ValidatePixelShader(NULL
, NULL
, TRUE
, NULL
);
4699 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
4700 errors
= (void *)0xcafeface;
4701 hr
= ValidatePixelShader(NULL
, NULL
, FALSE
, &errors
);
4702 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
4703 ok(errors
== (void *)0xcafeface, "Got unexpected errors %p.\n", errors
);
4704 errors
= (void *)0xcafeface;
4705 hr
= ValidatePixelShader(NULL
, NULL
, TRUE
, &errors
);
4706 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
4707 ok(errors
== (void *)0xcafeface, "Got unexpected errors %p.\n", errors
);
4709 hr
= ValidatePixelShader(ps_1_1_code
, NULL
, FALSE
, NULL
);
4710 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
4711 hr
= ValidatePixelShader(ps_1_1_code
, NULL
, TRUE
, NULL
);
4712 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
4713 hr
= ValidatePixelShader(ps_1_1_code
, NULL
, TRUE
, &errors
);
4714 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
4715 ok(!*errors
, "Got unexpected string \"%s\".\n", errors
);
4718 memset(&caps
, 0, sizeof(caps
));
4719 caps
.PixelShaderVersion
= D3DPS_VERSION(1, 1);
4720 hr
= ValidatePixelShader(ps_1_1_code
, &caps
, FALSE
, NULL
);
4721 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
4722 caps
.PixelShaderVersion
= D3DPS_VERSION(1, 0);
4723 hr
= ValidatePixelShader(ps_1_1_code
, &caps
, FALSE
, NULL
);
4724 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
4725 caps
.PixelShaderVersion
= D3DPS_VERSION(1, 2);
4726 hr
= ValidatePixelShader(ps_1_1_code
, &caps
, FALSE
, NULL
);
4727 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
4728 caps
.PixelShaderVersion
= D3DPS_VERSION(8, 8);
4729 hr
= ValidatePixelShader(ps_1_1_code
, &caps
, FALSE
, NULL
);
4730 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
4732 *ps_1_1_code
= D3DPS_VERSION(1, 0);
4733 hr
= ValidatePixelShader(ps_1_1_code
, NULL
, FALSE
, NULL
);
4734 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
4735 *ps_1_1_code
= D3DPS_VERSION(1, 4);
4736 hr
= ValidatePixelShader(ps_1_1_code
, NULL
, FALSE
, NULL
);
4737 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
4738 hr
= ValidatePixelShader(ps_2_0_code
, NULL
, FALSE
, NULL
);
4739 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
4740 *ps_1_1_code
= D3DPS_VERSION(1, 5);
4741 hr
= ValidatePixelShader(ps_1_1_code
, NULL
, TRUE
, NULL
);
4742 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
4743 hr
= ValidatePixelShader(ps_1_1_code
, NULL
, FALSE
, &errors
);
4744 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
4745 ok(!*errors
, "Got unexpected string \"%s\".\n", errors
);
4747 hr
= ValidatePixelShader(ps_1_1_code
, NULL
, TRUE
, &errors
);
4748 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
4749 ok(!!*errors
, "Got unexpected empty string.\n");
4753 static void test_volume_get_container(void)
4755 IDirect3DVolumeTexture8
*texture
= NULL
;
4756 IDirect3DVolume8
*volume
= NULL
;
4757 IDirect3DDevice8
*device
;
4758 IUnknown
*container
;
4765 window
= create_window();
4766 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
4767 ok(!!d3d8
, "Failed to create a D3D object.\n");
4768 if (!(device
= create_device(d3d8
, window
, NULL
)))
4770 skip("Failed to create a D3D device, skipping tests.\n");
4771 IDirect3D8_Release(d3d8
);
4772 DestroyWindow(window
);
4776 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
4777 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
4778 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP
))
4780 skip("No volume texture support, skipping tests.\n");
4781 IDirect3DDevice8_Release(device
);
4782 IDirect3D8_Release(d3d8
);
4783 DestroyWindow(window
);
4787 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 128, 128, 128, 1, 0,
4788 D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &texture
);
4789 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x.\n", hr
);
4790 ok(!!texture
, "Got unexpected texture %p.\n", texture
);
4792 hr
= IDirect3DVolumeTexture8_GetVolumeLevel(texture
, 0, &volume
);
4793 ok(SUCCEEDED(hr
), "Failed to get volume level, hr %#x.\n", hr
);
4794 ok(!!volume
, "Got unexpected volume %p.\n", volume
);
4796 /* These should work... */
4798 hr
= IDirect3DVolume8_GetContainer(volume
, &IID_IUnknown
, (void **)&container
);
4799 ok(SUCCEEDED(hr
), "Failed to get volume container, hr %#x.\n", hr
);
4800 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
4801 IUnknown_Release(container
);
4804 hr
= IDirect3DVolume8_GetContainer(volume
, &IID_IDirect3DResource8
, (void **)&container
);
4805 ok(SUCCEEDED(hr
), "Failed to get volume container, hr %#x.\n", hr
);
4806 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
4807 IUnknown_Release(container
);
4810 hr
= IDirect3DVolume8_GetContainer(volume
, &IID_IDirect3DBaseTexture8
, (void **)&container
);
4811 ok(SUCCEEDED(hr
), "Failed to get volume container, hr %#x.\n", hr
);
4812 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
4813 IUnknown_Release(container
);
4816 hr
= IDirect3DVolume8_GetContainer(volume
, &IID_IDirect3DVolumeTexture8
, (void **)&container
);
4817 ok(SUCCEEDED(hr
), "Failed to get volume container, hr %#x.\n", hr
);
4818 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
4819 IUnknown_Release(container
);
4821 /* ...and this one shouldn't. This should return E_NOINTERFACE and set container to NULL. */
4822 hr
= IDirect3DVolume8_GetContainer(volume
, &IID_IDirect3DVolume8
, (void **)&container
);
4823 ok(hr
== E_NOINTERFACE
, "Got unexpected hr %#x.\n", hr
);
4824 ok(!container
, "Got unexpected container %p.\n", container
);
4826 IDirect3DVolume8_Release(volume
);
4827 IDirect3DVolumeTexture8_Release(texture
);
4828 refcount
= IDirect3DDevice8_Release(device
);
4829 ok(!refcount
, "Device has %u references left.\n", refcount
);
4830 IDirect3D8_Release(d3d8
);
4831 DestroyWindow(window
);
4834 static void test_vb_lock_flags(void)
4839 const char *debug_string
;
4844 {D3DLOCK_READONLY
, "D3DLOCK_READONLY", D3D_OK
},
4845 {D3DLOCK_DISCARD
, "D3DLOCK_DISCARD", D3D_OK
},
4846 {D3DLOCK_NOOVERWRITE
, "D3DLOCK_NOOVERWRITE", D3D_OK
},
4847 {D3DLOCK_NOOVERWRITE
| D3DLOCK_DISCARD
, "D3DLOCK_NOOVERWRITE | D3DLOCK_DISCARD", D3D_OK
},
4848 {D3DLOCK_NOOVERWRITE
| D3DLOCK_READONLY
, "D3DLOCK_NOOVERWRITE | D3DLOCK_READONLY", D3D_OK
},
4849 {D3DLOCK_READONLY
| D3DLOCK_DISCARD
, "D3DLOCK_READONLY | D3DLOCK_DISCARD", D3D_OK
},
4850 /* Completely bogus flags aren't an error. */
4851 {0xdeadbeef, "0xdeadbeef", D3D_OK
},
4853 IDirect3DVertexBuffer8
*buffer
;
4854 IDirect3DDevice8
*device
;
4862 window
= create_window();
4863 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
4864 ok(!!d3d8
, "Failed to create a D3D object.\n");
4865 if (!(device
= create_device(d3d8
, window
, NULL
)))
4867 skip("Failed to create a D3D device, skipping tests.\n");
4868 IDirect3D8_Release(d3d8
);
4869 DestroyWindow(window
);
4873 hr
= IDirect3DDevice8_CreateVertexBuffer(device
, 1024, D3DUSAGE_DYNAMIC
| D3DUSAGE_WRITEONLY
,
4874 0, D3DPOOL_DEFAULT
, &buffer
);
4875 ok(SUCCEEDED(hr
), "Failed to create vertex buffer, hr %#x.\n", hr
);
4877 for (i
= 0; i
< ARRAY_SIZE(test_data
); ++i
)
4879 hr
= IDirect3DVertexBuffer8_Lock(buffer
, 0, 0, &data
, test_data
[i
].flags
);
4880 ok(hr
== test_data
[i
].result
, "Got unexpected hr %#x for %s.\n",
4881 hr
, test_data
[i
].debug_string
);
4884 ok(!!data
, "Got unexpected data %p.\n", data
);
4885 hr
= IDirect3DVertexBuffer8_Unlock(buffer
);
4886 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
4890 IDirect3DVertexBuffer8_Release(buffer
);
4891 refcount
= IDirect3DDevice8_Release(device
);
4892 ok(!refcount
, "Device has %u references left.\n", refcount
);
4893 IDirect3D8_Release(d3d8
);
4894 DestroyWindow(window
);
4897 /* Test the default texture stage state values */
4898 static void test_texture_stage_states(void)
4900 IDirect3DDevice8
*device
;
4909 window
= create_window();
4910 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
4911 ok(!!d3d8
, "Failed to create a D3D object.\n");
4912 if (!(device
= create_device(d3d8
, window
, NULL
)))
4914 skip("Failed to create a D3D device, skipping tests.\n");
4915 IDirect3D8_Release(d3d8
);
4916 DestroyWindow(window
);
4920 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
4921 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
4923 for (i
= 0; i
< caps
.MaxTextureBlendStages
; ++i
)
4925 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_COLOROP
, &value
);
4926 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4927 ok(value
== (i
? D3DTOP_DISABLE
: D3DTOP_MODULATE
),
4928 "Got unexpected value %#x for D3DTSS_COLOROP, stage %u.\n", value
, i
);
4929 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_COLORARG1
, &value
);
4930 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4931 ok(value
== D3DTA_TEXTURE
, "Got unexpected value %#x for D3DTSS_COLORARG1, stage %u.\n", value
, i
);
4932 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_COLORARG2
, &value
);
4933 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4934 ok(value
== D3DTA_CURRENT
, "Got unexpected value %#x for D3DTSS_COLORARG2, stage %u.\n", value
, i
);
4935 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_ALPHAOP
, &value
);
4936 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4937 ok(value
== (i
? D3DTOP_DISABLE
: D3DTOP_SELECTARG1
),
4938 "Got unexpected value %#x for D3DTSS_ALPHAOP, stage %u.\n", value
, i
);
4939 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_ALPHAARG1
, &value
);
4940 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4941 ok(value
== D3DTA_TEXTURE
, "Got unexpected value %#x for D3DTSS_ALPHAARG1, stage %u.\n", value
, i
);
4942 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_ALPHAARG2
, &value
);
4943 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4944 ok(value
== D3DTA_CURRENT
, "Got unexpected value %#x for D3DTSS_ALPHAARG2, stage %u.\n", value
, i
);
4945 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_BUMPENVMAT00
, &value
);
4946 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4947 ok(!value
, "Got unexpected value %#x for D3DTSS_BUMPENVMAT00, stage %u.\n", value
, i
);
4948 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_BUMPENVMAT01
, &value
);
4949 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4950 ok(!value
, "Got unexpected value %#x for D3DTSS_BUMPENVMAT01, stage %u.\n", value
, i
);
4951 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_BUMPENVMAT10
, &value
);
4952 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4953 ok(!value
, "Got unexpected value %#x for D3DTSS_BUMPENVMAT10, stage %u.\n", value
, i
);
4954 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_BUMPENVMAT11
, &value
);
4955 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4956 ok(!value
, "Got unexpected value %#x for D3DTSS_BUMPENVMAT11, stage %u.\n", value
, i
);
4957 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_TEXCOORDINDEX
, &value
);
4958 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4959 ok(value
== i
, "Got unexpected value %#x for D3DTSS_TEXCOORDINDEX, stage %u.\n", value
, i
);
4960 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_BUMPENVLSCALE
, &value
);
4961 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4962 ok(!value
, "Got unexpected value %#x for D3DTSS_BUMPENVLSCALE, stage %u.\n", value
, i
);
4963 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_BUMPENVLOFFSET
, &value
);
4964 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4965 ok(!value
, "Got unexpected value %#x for D3DTSS_BUMPENVLOFFSET, stage %u.\n", value
, i
);
4966 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_TEXTURETRANSFORMFLAGS
, &value
);
4967 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4968 ok(value
== D3DTTFF_DISABLE
,
4969 "Got unexpected value %#x for D3DTSS_TEXTURETRANSFORMFLAGS, stage %u.\n", value
, i
);
4970 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_COLORARG0
, &value
);
4971 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4972 ok(value
== D3DTA_CURRENT
, "Got unexpected value %#x for D3DTSS_COLORARG0, stage %u.\n", value
, i
);
4973 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_ALPHAARG0
, &value
);
4974 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4975 ok(value
== D3DTA_CURRENT
, "Got unexpected value %#x for D3DTSS_ALPHAARG0, stage %u.\n", value
, i
);
4976 hr
= IDirect3DDevice8_GetTextureStageState(device
, i
, D3DTSS_RESULTARG
, &value
);
4977 ok(SUCCEEDED(hr
), "Failed to get texture stage state, hr %#x.\n", hr
);
4978 ok(value
== D3DTA_CURRENT
, "Got unexpected value %#x for D3DTSS_RESULTARG, stage %u.\n", value
, i
);
4981 refcount
= IDirect3DDevice8_Release(device
);
4982 ok(!refcount
, "Device has %u references left.\n", refcount
);
4983 IDirect3D8_Release(d3d8
);
4984 DestroyWindow(window
);
4987 static void test_cube_textures(void)
4989 IDirect3DCubeTexture8
*texture
;
4990 IDirect3DDevice8
*device
;
4997 window
= create_window();
4998 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
4999 ok(!!d3d8
, "Failed to create a D3D object.\n");
5000 if (!(device
= create_device(d3d8
, window
, NULL
)))
5002 skip("Failed to create a D3D device, skipping tests.\n");
5003 IDirect3D8_Release(d3d8
);
5004 DestroyWindow(window
);
5008 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
5009 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
5011 if (caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP
)
5013 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 512, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &texture
);
5014 ok(hr
== D3D_OK
, "Failed to create D3DPOOL_DEFAULT cube texture, hr %#x.\n", hr
);
5015 IDirect3DCubeTexture8_Release(texture
);
5016 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 512, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_MANAGED
, &texture
);
5017 ok(hr
== D3D_OK
, "Failed to create D3DPOOL_MANAGED cube texture, hr %#x.\n", hr
);
5018 IDirect3DCubeTexture8_Release(texture
);
5019 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 512, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_SYSTEMMEM
, &texture
);
5020 ok(hr
== D3D_OK
, "Failed to create D3DPOOL_SYSTEMMEM cube texture, hr %#x.\n", hr
);
5021 IDirect3DCubeTexture8_Release(texture
);
5025 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 512, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
, &texture
);
5026 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for D3DPOOL_DEFAULT cube texture.\n", hr
);
5027 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 512, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_MANAGED
, &texture
);
5028 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for D3DPOOL_MANAGED cube texture.\n", hr
);
5029 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 512, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_SYSTEMMEM
, &texture
);
5030 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for D3DPOOL_SYSTEMMEM cube texture.\n", hr
);
5032 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 512, 1, 0, D3DFMT_X8R8G8B8
, D3DPOOL_SCRATCH
, &texture
);
5033 ok(hr
== D3D_OK
, "Failed to create D3DPOOL_SCRATCH cube texture, hr %#x.\n", hr
);
5034 IDirect3DCubeTexture8_Release(texture
);
5036 refcount
= IDirect3DDevice8_Release(device
);
5037 ok(!refcount
, "Device has %u references left.\n", refcount
);
5038 IDirect3D8_Release(d3d8
);
5039 DestroyWindow(window
);
5042 static void test_get_set_texture(void)
5044 const IDirect3DBaseTexture8Vtbl
*texture_vtbl
;
5045 IDirect3DBaseTexture8
*texture
;
5046 IDirect3DDevice8
*device
;
5052 window
= create_window();
5053 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
5054 ok(!!d3d
, "Failed to create a D3D object.\n");
5055 if (!(device
= create_device(d3d
, window
, NULL
)))
5057 skip("Failed to create a D3D device, skipping tests.\n");
5058 IDirect3D8_Release(d3d
);
5059 DestroyWindow(window
);
5063 texture
= (IDirect3DBaseTexture8
*)0xdeadbeef;
5064 hr
= IDirect3DDevice8_SetTexture(device
, 0, NULL
);
5065 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
5066 hr
= IDirect3DDevice8_GetTexture(device
, 0, &texture
);
5067 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
5068 ok(!texture
, "Got unexpected texture %p.\n", texture
);
5070 hr
= IDirect3DDevice8_CreateTexture(device
, 16, 16, 1, 0, D3DFMT_A8R8G8B8
,
5071 D3DPOOL_MANAGED
, (IDirect3DTexture8
**)&texture
);
5072 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
5073 texture_vtbl
= texture
->lpVtbl
;
5074 texture
->lpVtbl
= (IDirect3DBaseTexture8Vtbl
*)0xdeadbeef;
5075 hr
= IDirect3DDevice8_SetTexture(device
, 0, texture
);
5076 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
5077 hr
= IDirect3DDevice8_SetTexture(device
, 0, NULL
);
5078 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
5079 texture
->lpVtbl
= NULL
;
5080 hr
= IDirect3DDevice8_SetTexture(device
, 0, texture
);
5081 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
5082 hr
= IDirect3DDevice8_SetTexture(device
, 0, NULL
);
5083 ok(SUCCEEDED(hr
), "Failed to set texture, hr %#x.\n", hr
);
5084 texture
->lpVtbl
= texture_vtbl
;
5085 IDirect3DBaseTexture8_Release(texture
);
5087 refcount
= IDirect3DDevice8_Release(device
);
5088 ok(!refcount
, "Device has %u references left.\n", refcount
);
5089 IDirect3D8_Release(d3d
);
5090 DestroyWindow(window
);
5093 /* Test the behaviour of the IDirect3DDevice8::CreateImageSurface() method.
5095 * The expected behaviour (as documented in the original DX8 docs) is that the
5096 * call returns a surface in the SYSTEMMEM pool. Games like Max Payne 1 and 2
5097 * depend on this behaviour.
5099 * A short remark in the DX9 docs however states that the pool of the returned
5100 * surface object is D3DPOOL_SCRATCH. This is misinformation and would result
5101 * in screenshots not appearing in the savegame loading menu of both games
5102 * mentioned above (engine tries to display a texture from the scratch pool).
5104 * This test verifies that the behaviour described in the original d3d8 docs
5105 * is the correct one. For more information about this issue, see the MSDN:
5106 * d3d9 docs: "Converting to Direct3D 9"
5107 * d3d9 reference: "IDirect3DDevice9::CreateOffscreenPlainSurface"
5108 * d3d8 reference: "IDirect3DDevice8::CreateImageSurface" */
5109 static void test_image_surface_pool(void)
5111 IDirect3DSurface8
*surface
;
5112 IDirect3DDevice8
*device
;
5113 D3DSURFACE_DESC desc
;
5119 window
= create_window();
5120 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
5121 ok(!!d3d8
, "Failed to create a D3D object.\n");
5122 if (!(device
= create_device(d3d8
, window
, NULL
)))
5124 skip("Failed to create a D3D device, skipping tests.\n");
5125 IDirect3D8_Release(d3d8
);
5126 DestroyWindow(window
);
5130 hr
= IDirect3DDevice8_CreateImageSurface(device
, 128, 128, D3DFMT_A8R8G8B8
, &surface
);
5131 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5132 hr
= IDirect3DSurface8_GetDesc(surface
, &desc
);
5133 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5134 ok(desc
.Pool
== D3DPOOL_SYSTEMMEM
, "Got unexpected pool %#x.\n", desc
.Pool
);
5135 IDirect3DSurface8_Release(surface
);
5137 refcount
= IDirect3DDevice8_Release(device
);
5138 ok(!refcount
, "Device has %u references left.\n", refcount
);
5139 IDirect3D8_Release(d3d8
);
5140 DestroyWindow(window
);
5143 static void test_surface_get_container(void)
5145 IDirect3DTexture8
*texture
= NULL
;
5146 IDirect3DSurface8
*surface
= NULL
;
5147 IDirect3DDevice8
*device
;
5148 IUnknown
*container
;
5154 window
= create_window();
5155 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
5156 ok(!!d3d8
, "Failed to create a D3D object.\n");
5157 if (!(device
= create_device(d3d8
, window
, NULL
)))
5159 skip("Failed to create a D3D device, skipping tests.\n");
5160 IDirect3D8_Release(d3d8
);
5161 DestroyWindow(window
);
5165 hr
= IDirect3DDevice8_CreateTexture(device
, 128, 128, 1, 0,
5166 D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &texture
);
5167 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
5168 ok(!!texture
, "Got unexpected texture %p.\n", texture
);
5170 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 0, &surface
);
5171 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
5172 ok(!!surface
, "Got unexpected surface %p.\n", surface
);
5174 /* These should work... */
5176 hr
= IDirect3DSurface8_GetContainer(surface
, &IID_IUnknown
, (void **)&container
);
5177 ok(SUCCEEDED(hr
), "Failed to get surface container, hr %#x.\n", hr
);
5178 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
5179 IUnknown_Release(container
);
5182 hr
= IDirect3DSurface8_GetContainer(surface
, &IID_IDirect3DResource8
, (void **)&container
);
5183 ok(SUCCEEDED(hr
), "Failed to get surface container, hr %#x.\n", hr
);
5184 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
5185 IUnknown_Release(container
);
5188 hr
= IDirect3DSurface8_GetContainer(surface
, &IID_IDirect3DBaseTexture8
, (void **)&container
);
5189 ok(SUCCEEDED(hr
), "Failed to get surface container, hr %#x.\n", hr
);
5190 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
5191 IUnknown_Release(container
);
5194 hr
= IDirect3DSurface8_GetContainer(surface
, &IID_IDirect3DTexture8
, (void **)&container
);
5195 ok(SUCCEEDED(hr
), "Failed to get surface container, hr %#x.\n", hr
);
5196 ok(container
== (IUnknown
*)texture
, "Got unexpected container %p, expected %p.\n", container
, texture
);
5197 IUnknown_Release(container
);
5199 /* ...and this one shouldn't. This should return E_NOINTERFACE and set container to NULL. */
5200 hr
= IDirect3DSurface8_GetContainer(surface
, &IID_IDirect3DSurface8
, (void **)&container
);
5201 ok(hr
== E_NOINTERFACE
, "Got unexpected hr %#x.\n", hr
);
5202 ok(!container
, "Got unexpected container %p.\n", container
);
5204 IDirect3DSurface8_Release(surface
);
5205 IDirect3DTexture8_Release(texture
);
5206 refcount
= IDirect3DDevice8_Release(device
);
5207 ok(!refcount
, "Device has %u references left.\n", refcount
);
5208 IDirect3D8_Release(d3d8
);
5209 DestroyWindow(window
);
5212 static void test_lockrect_invalid(void)
5214 static const RECT valid
[] =
5220 static const RECT invalid
[] =
5222 {60, 60, 60, 68}, /* 0 height */
5223 {60, 60, 68, 60}, /* 0 width */
5224 {68, 60, 60, 68}, /* left > right */
5225 {60, 68, 68, 60}, /* top > bottom */
5226 {-8, 60, 0, 68}, /* left < surface */
5227 {60, -8, 68, 0}, /* top < surface */
5228 {-16, 60, -8, 68}, /* right < surface */
5229 {60, -16, 68, -8}, /* bottom < surface */
5230 {60, 60, 136, 68}, /* right > surface */
5231 {60, 60, 68, 136}, /* bottom > surface */
5232 {136, 60, 144, 68}, /* left > surface */
5233 {60, 136, 68, 144}, /* top > surface */
5235 IDirect3DSurface8
*surface
;
5236 IDirect3DTexture8
*texture
;
5237 IDirect3DCubeTexture8
*cube_texture
;
5238 D3DLOCKED_RECT locked_rect
;
5239 IDirect3DDevice8
*device
;
5240 HRESULT hr
, expected_hr
;
5246 unsigned int offset
, expected_offset
;
5249 D3DRESOURCETYPE type
;
5252 BOOL validate
, clear
;
5256 {D3DRTYPE_SURFACE
, D3DPOOL_SCRATCH
, "scratch surface", TRUE
, TRUE
},
5257 {D3DRTYPE_TEXTURE
, D3DPOOL_MANAGED
, "managed texture", FALSE
, FALSE
},
5258 {D3DRTYPE_TEXTURE
, D3DPOOL_SYSTEMMEM
, "sysmem texture", FALSE
, FALSE
},
5259 {D3DRTYPE_TEXTURE
, D3DPOOL_SCRATCH
, "scratch texture", FALSE
, FALSE
},
5260 {D3DRTYPE_CUBETEXTURE
, D3DPOOL_MANAGED
, "default cube texture", TRUE
, TRUE
},
5261 {D3DRTYPE_CUBETEXTURE
, D3DPOOL_SYSTEMMEM
, "sysmem cube texture", TRUE
, TRUE
},
5262 {D3DRTYPE_CUBETEXTURE
, D3DPOOL_SCRATCH
, "scratch cube texture", TRUE
, TRUE
},
5265 window
= create_window();
5266 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
5267 ok(!!d3d8
, "Failed to create a D3D object.\n");
5268 if (!(device
= create_device(d3d8
, window
, NULL
)))
5270 skip("Failed to create a D3D device, skipping tests.\n");
5271 IDirect3D8_Release(d3d8
);
5272 DestroyWindow(window
);
5276 for (r
= 0; r
< ARRAY_SIZE(resources
); ++r
)
5279 cube_texture
= NULL
;
5280 switch (resources
[r
].type
)
5282 case D3DRTYPE_SURFACE
:
5283 hr
= IDirect3DDevice8_CreateImageSurface(device
, 128, 128, D3DFMT_A8R8G8B8
, &surface
);
5284 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
5287 case D3DRTYPE_TEXTURE
:
5288 hr
= IDirect3DDevice8_CreateTexture(device
, 128, 128, 1, 0, D3DFMT_A8R8G8B8
,
5289 resources
[r
].pool
, &texture
);
5290 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x, type %s.\n", hr
, resources
[r
].name
);
5291 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 0, &surface
);
5292 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x, type %s.\n", hr
, resources
[r
].name
);
5295 case D3DRTYPE_CUBETEXTURE
:
5296 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 128, 1, 0, D3DFMT_A8R8G8B8
,
5297 resources
[r
].pool
, &cube_texture
);
5298 ok(SUCCEEDED(hr
), "Failed to create cube texture, hr %#x, type %s.\n", hr
, resources
[r
].name
);
5299 hr
= IDirect3DCubeTexture8_GetCubeMapSurface(cube_texture
, D3DCUBEMAP_FACE_NEGATIVE_X
, 0, &surface
);
5300 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x, type %s.\n", hr
, resources
[r
].name
);
5307 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, NULL
, 0);
5308 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
5309 base
= locked_rect
.pBits
;
5310 hr
= IDirect3DSurface8_UnlockRect(surface
);
5311 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
5312 expected_hr
= resources
[r
].type
== D3DRTYPE_TEXTURE
? D3D_OK
: D3DERR_INVALIDCALL
;
5313 hr
= IDirect3DSurface8_UnlockRect(surface
);
5314 ok(hr
== expected_hr
, "Got hr %#x, expected %#x, type %s.\n", hr
, expected_hr
, resources
[r
].name
);
5316 for (i
= 0; i
< ARRAY_SIZE(valid
); ++i
)
5318 const RECT
*rect
= &valid
[i
];
5320 locked_rect
.pBits
= (BYTE
*)0xdeadbeef;
5321 locked_rect
.Pitch
= 0xdeadbeef;
5323 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, rect
, 0);
5324 ok(SUCCEEDED(hr
), "Failed to lock surface with rect %s, hr %#x, type %s.\n",
5325 wine_dbgstr_rect(rect
), hr
, resources
[r
].name
);
5327 offset
= (BYTE
*)locked_rect
.pBits
- base
;
5328 expected_offset
= rect
->top
* locked_rect
.Pitch
+ rect
->left
* 4;
5329 ok(offset
== expected_offset
,
5330 "Got unexpected offset %u (expected %u) for rect %s, type %s.\n",
5331 offset
, expected_offset
, wine_dbgstr_rect(rect
), resources
[r
].name
);
5333 hr
= IDirect3DSurface8_UnlockRect(surface
);
5334 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s\n", hr
, resources
[r
].name
);
5338 hr
= IDirect3DTexture8_LockRect(texture
, 0, &locked_rect
, rect
, 0);
5339 ok(SUCCEEDED(hr
), "Failed to lock surface with rect %s, hr %#x, type %s.\n",
5340 wine_dbgstr_rect(rect
), hr
, resources
[r
].name
);
5342 offset
= (BYTE
*)locked_rect
.pBits
- base
;
5343 ok(offset
== expected_offset
,
5344 "Got unexpected offset %u (expected %u) for rect %s, type %s.\n",
5345 offset
, expected_offset
, wine_dbgstr_rect(rect
), resources
[r
].name
);
5347 hr
= IDirect3DTexture8_UnlockRect(texture
, 0);
5348 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
5352 hr
= IDirect3DCubeTexture8_LockRect(cube_texture
, D3DCUBEMAP_FACE_NEGATIVE_X
, 0, &locked_rect
, rect
, 0);
5353 ok(SUCCEEDED(hr
), "Failed to lock surface with rect %s, hr %#x, type %s.\n",
5354 wine_dbgstr_rect(rect
), hr
, resources
[r
].name
);
5356 offset
= (BYTE
*)locked_rect
.pBits
- base
;
5357 ok(offset
== expected_offset
,
5358 "Got unexpected offset %u (expected %u) for rect %s, type %s.\n",
5359 offset
, expected_offset
, wine_dbgstr_rect(rect
), resources
[r
].name
);
5361 hr
= IDirect3DCubeTexture8_UnlockRect(cube_texture
, D3DCUBEMAP_FACE_NEGATIVE_X
, 0);
5362 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
5366 for (i
= 0; i
< ARRAY_SIZE(invalid
); ++i
)
5368 const RECT
*rect
= &invalid
[i
];
5370 locked_rect
.pBits
= (void *)0xdeadbeef;
5371 locked_rect
.Pitch
= 1;
5372 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, rect
, 0);
5373 if (resources
[r
].validate
)
5374 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for rect %s, type %s.\n",
5375 hr
, wine_dbgstr_rect(rect
), resources
[r
].name
);
5377 ok(SUCCEEDED(hr
), "Got unexpected hr %#x for rect %s, type %s.\n",
5378 hr
, wine_dbgstr_rect(rect
), resources
[r
].name
);
5382 offset
= (BYTE
*)locked_rect
.pBits
- base
;
5383 expected_offset
= rect
->top
* locked_rect
.Pitch
+ rect
->left
* 4;
5384 ok(offset
== expected_offset
,
5385 "Got unexpected offset %u (expected %u) for rect %s, type %s.\n",
5386 offset
, expected_offset
,wine_dbgstr_rect(rect
), resources
[r
].name
);
5388 hr
= IDirect3DSurface8_UnlockRect(surface
);
5389 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
5393 ok(!locked_rect
.pBits
, "Got unexpected pBits %p, type %s.\n",
5394 locked_rect
.pBits
, resources
[r
].name
);
5395 ok(!locked_rect
.Pitch
, "Got unexpected Pitch %u, type %s.\n",
5396 locked_rect
.Pitch
, resources
[r
].name
);
5400 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, NULL
, 0);
5401 ok(SUCCEEDED(hr
), "Failed to lock surface with rect NULL, hr %#x, type %s.\n",
5402 hr
, resources
[r
].name
);
5403 locked_rect
.pBits
= (void *)0xdeadbeef;
5404 locked_rect
.Pitch
= 1;
5405 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, NULL
, 0);
5406 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x, type %s.\n", hr
, resources
[r
].name
);
5407 if (resources
[r
].clear
)
5409 ok(!locked_rect
.pBits
, "Got unexpected pBits %p, type %s.\n",
5410 locked_rect
.pBits
, resources
[r
].name
);
5411 ok(!locked_rect
.Pitch
, "Got unexpected Pitch %u, type %s.\n",
5412 locked_rect
.Pitch
, resources
[r
].name
);
5416 ok(locked_rect
.pBits
== (void *)0xdeadbeef, "Got unexpected pBits %p, type %s.\n",
5417 locked_rect
.pBits
, resources
[r
].name
);
5418 ok(locked_rect
.Pitch
== 1, "Got unexpected Pitch %u, type %s.\n",
5419 locked_rect
.Pitch
, resources
[r
].name
);
5421 hr
= IDirect3DSurface8_UnlockRect(surface
);
5422 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
5424 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, &valid
[0], 0);
5425 ok(hr
== D3D_OK
, "Got unexpected hr %#x for rect %s, type %s.\n",
5426 hr
, wine_dbgstr_rect(&valid
[0]), resources
[r
].name
);
5427 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, &valid
[0], 0);
5428 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for rect %s, type %s.\n",
5429 hr
, wine_dbgstr_rect(&valid
[0]), resources
[r
].name
);
5430 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, &valid
[1], 0);
5431 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for rect %s, type %s.\n",
5432 hr
, wine_dbgstr_rect(&valid
[1]), resources
[r
].name
);
5433 hr
= IDirect3DSurface8_UnlockRect(surface
);
5434 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
5436 IDirect3DSurface8_Release(surface
);
5439 hr
= IDirect3DTexture8_LockRect(texture
, 0, &locked_rect
, NULL
, 0);
5440 ok(SUCCEEDED(hr
), "Failed to lock texture with rect NULL, hr %#x, type %s.\n",
5441 hr
, resources
[r
].name
);
5442 locked_rect
.pBits
= (void *)0xdeadbeef;
5443 locked_rect
.Pitch
= 1;
5444 hr
= IDirect3DTexture8_LockRect(texture
, 0, &locked_rect
, NULL
, 0);
5445 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x, type %s.\n", hr
, resources
[r
].name
);
5446 ok(locked_rect
.pBits
== (void *)0xdeadbeef, "Got unexpected pBits %p, type %s.\n",
5447 locked_rect
.pBits
, resources
[r
].name
);
5448 ok(locked_rect
.Pitch
== 1, "Got unexpected Pitch %u, type %s.\n",
5449 locked_rect
.Pitch
, resources
[r
].name
);
5450 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, NULL
, 0);
5451 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x, type %s.\n", hr
, resources
[r
].name
);
5452 hr
= IDirect3DTexture8_UnlockRect(texture
, 0);
5453 ok(SUCCEEDED(hr
), "Failed to unlock texture, hr %#x, type %s.\n", hr
, resources
[r
].name
);
5454 hr
= IDirect3DTexture8_UnlockRect(texture
, 0);
5455 ok(hr
== D3D_OK
, "Got unexpected hr %#x, type %s.\n", hr
, resources
[r
].name
);
5457 hr
= IDirect3DTexture8_LockRect(texture
, 0, &locked_rect
, &valid
[0], 0);
5458 ok(hr
== D3D_OK
, "Got unexpected hr %#x for rect %s, type %s.\n",
5459 hr
, wine_dbgstr_rect(&valid
[0]), resources
[r
].name
);
5460 hr
= IDirect3DTexture8_LockRect(texture
, 0, &locked_rect
, &valid
[0], 0);
5461 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for rect %s, type %s.\n",
5462 hr
, wine_dbgstr_rect(&valid
[0]), resources
[r
].name
);
5463 hr
= IDirect3DTexture8_LockRect(texture
, 0, &locked_rect
, &valid
[1], 0);
5464 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for rect %s, type %s.\n",
5465 hr
, wine_dbgstr_rect(&valid
[1]), resources
[r
].name
);
5466 hr
= IDirect3DTexture8_UnlockRect(texture
, 0);
5467 ok(SUCCEEDED(hr
), "Failed to unlock texture, hr %#x, type %s.\n", hr
, resources
[r
].name
);
5469 IDirect3DTexture8_Release(texture
);
5471 hr
= IDirect3DDevice8_CreateTexture(device
, 128, 128, 1, D3DUSAGE_WRITEONLY
,
5472 D3DFMT_A8R8G8B8
, resources
[r
].pool
, &texture
);
5473 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for type %s.\n",
5474 hr
, resources
[r
].name
);
5479 hr
= IDirect3DCubeTexture8_LockRect(cube_texture
, D3DCUBEMAP_FACE_NEGATIVE_X
, 0,
5480 &locked_rect
, NULL
, 0);
5481 ok(SUCCEEDED(hr
), "Failed to lock texture with rect NULL, hr %#x, type %s.\n",
5482 hr
, resources
[r
].name
);
5483 locked_rect
.pBits
= (void *)0xdeadbeef;
5484 locked_rect
.Pitch
= 1;
5485 hr
= IDirect3DCubeTexture8_LockRect(cube_texture
, D3DCUBEMAP_FACE_NEGATIVE_X
, 0,
5486 &locked_rect
, NULL
, 0);
5487 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x, type %s.\n", hr
, resources
[r
].name
);
5488 ok(!locked_rect
.pBits
, "Got unexpected pBits %p, type %s.\n",
5489 locked_rect
.pBits
, resources
[r
].name
);
5490 ok(!locked_rect
.Pitch
, "Got unexpected Pitch %u, type %s.\n",
5491 locked_rect
.Pitch
, resources
[r
].name
);
5492 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, NULL
, 0);
5493 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x, type %s.\n", hr
, resources
[r
].name
);
5494 hr
= IDirect3DCubeTexture8_UnlockRect(cube_texture
, D3DCUBEMAP_FACE_NEGATIVE_X
, 0);
5495 ok(SUCCEEDED(hr
), "Failed to unlock texture, hr %#x, type %s.\n", hr
, resources
[r
].name
);
5496 hr
= IDirect3DCubeTexture8_UnlockRect(cube_texture
, D3DCUBEMAP_FACE_NEGATIVE_X
, 0);
5497 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x, type %s.\n", hr
, resources
[r
].name
);
5499 hr
= IDirect3DCubeTexture8_LockRect(cube_texture
, D3DCUBEMAP_FACE_NEGATIVE_X
, 0,
5500 &locked_rect
, &valid
[0], 0);
5501 ok(hr
== D3D_OK
, "Got unexpected hr %#x for rect %s, type %s.\n",
5502 hr
, wine_dbgstr_rect(&valid
[0]), resources
[r
].name
);
5503 hr
= IDirect3DCubeTexture8_LockRect(cube_texture
, D3DCUBEMAP_FACE_NEGATIVE_X
, 0,
5504 &locked_rect
, &valid
[0], 0);
5505 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for rect %s, type %s.\n",
5506 hr
, wine_dbgstr_rect(&valid
[0]), resources
[r
].name
);
5507 hr
= IDirect3DCubeTexture8_LockRect(cube_texture
, D3DCUBEMAP_FACE_NEGATIVE_X
, 0,
5508 &locked_rect
, &valid
[1], 0);
5509 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for rect %s, type %s.\n",
5510 hr
, wine_dbgstr_rect(&valid
[1]), resources
[r
].name
);
5511 hr
= IDirect3DCubeTexture8_UnlockRect(cube_texture
, D3DCUBEMAP_FACE_NEGATIVE_X
, 0);
5512 ok(SUCCEEDED(hr
), "Failed to unlock texture, hr %#x, type %s.\n", hr
, resources
[r
].name
);
5514 IDirect3DTexture8_Release(cube_texture
);
5516 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 128, 1, D3DUSAGE_WRITEONLY
, D3DFMT_A8R8G8B8
,
5517 resources
[r
].pool
, &cube_texture
);
5518 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for type %s.\n",
5519 hr
, resources
[r
].name
);
5523 refcount
= IDirect3DDevice8_Release(device
);
5524 ok(!refcount
, "Device has %u references left.\n", refcount
);
5525 IDirect3D8_Release(d3d8
);
5526 DestroyWindow(window
);
5529 static void test_private_data(void)
5531 ULONG refcount
, expected_refcount
;
5532 IDirect3DTexture8
*texture
;
5533 IDirect3DSurface8
*surface
, *surface2
;
5534 IDirect3DDevice8
*device
;
5540 DWORD data
[4] = {1, 2, 3, 4};
5541 static const GUID d3d8_private_data_test_guid2
=
5546 {0x9b,0x4b,0x89,0xd7,0xd1,0x12,0xe7,0x2b}
5549 window
= create_window();
5550 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
5551 ok(!!d3d8
, "Failed to create a D3D object.\n");
5552 if (!(device
= create_device(d3d8
, window
, NULL
)))
5554 skip("Failed to create a D3D device, skipping tests.\n");
5555 IDirect3D8_Release(d3d8
);
5556 DestroyWindow(window
);
5560 hr
= IDirect3DDevice8_CreateImageSurface(device
, 4, 4, D3DFMT_A8R8G8B8
, &surface
);
5561 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5563 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
,
5564 device
, 0, D3DSPD_IUNKNOWN
);
5565 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
5566 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
,
5567 device
, 5, D3DSPD_IUNKNOWN
);
5568 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
5569 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
,
5570 device
, sizeof(IUnknown
*) * 2, D3DSPD_IUNKNOWN
);
5571 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
5573 /* A failing SetPrivateData call does not clear the old data with the same tag. */
5574 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
, device
,
5575 sizeof(device
), D3DSPD_IUNKNOWN
);
5576 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
5577 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
, device
,
5578 sizeof(device
) * 2, D3DSPD_IUNKNOWN
);
5579 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
5581 hr
= IDirect3DSurface8_GetPrivateData(surface
, &d3d8_private_data_test_guid
, &ptr
, &size
);
5582 ok(SUCCEEDED(hr
), "Failed to get private data, hr %#x.\n", hr
);
5583 IUnknown_Release(ptr
);
5584 hr
= IDirect3DSurface8_FreePrivateData(surface
, &d3d8_private_data_test_guid
);
5585 ok(SUCCEEDED(hr
), "Failed to free private data, hr %#x.\n", hr
);
5587 refcount
= get_refcount((IUnknown
*)device
);
5588 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
,
5589 device
, sizeof(IUnknown
*), D3DSPD_IUNKNOWN
);
5590 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
5591 expected_refcount
= refcount
+ 1;
5592 refcount
= get_refcount((IUnknown
*)device
);
5593 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
5594 hr
= IDirect3DSurface8_FreePrivateData(surface
, &d3d8_private_data_test_guid
);
5595 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
5596 expected_refcount
= refcount
- 1;
5597 refcount
= get_refcount((IUnknown
*)device
);
5598 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
5600 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
,
5601 device
, sizeof(IUnknown
*), D3DSPD_IUNKNOWN
);
5602 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
5603 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
,
5604 surface
, sizeof(IUnknown
*), D3DSPD_IUNKNOWN
);
5605 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
5606 refcount
= get_refcount((IUnknown
*)device
);
5607 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
5609 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
,
5610 device
, sizeof(IUnknown
*), D3DSPD_IUNKNOWN
);
5611 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
5612 size
= 2 * sizeof(ptr
);
5613 hr
= IDirect3DSurface8_GetPrivateData(surface
, &d3d8_private_data_test_guid
, &ptr
, &size
);
5614 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
5615 ok(size
== sizeof(device
), "Got unexpected size %u.\n", size
);
5616 expected_refcount
= refcount
+ 2;
5617 refcount
= get_refcount((IUnknown
*)device
);
5618 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
5619 ok(ptr
== (IUnknown
*)device
, "Got unexpected ptr %p, expected %p.\n", ptr
, device
);
5620 IUnknown_Release(ptr
);
5621 expected_refcount
--;
5623 ptr
= (IUnknown
*)0xdeadbeef;
5625 hr
= IDirect3DSurface8_GetPrivateData(surface
, &d3d8_private_data_test_guid
, NULL
, &size
);
5626 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
5627 ok(size
== sizeof(device
), "Got unexpected size %u.\n", size
);
5628 size
= 2 * sizeof(ptr
);
5629 hr
= IDirect3DSurface8_GetPrivateData(surface
, &d3d8_private_data_test_guid
, NULL
, &size
);
5630 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
5631 ok(size
== sizeof(device
), "Got unexpected size %u.\n", size
);
5632 refcount
= get_refcount((IUnknown
*)device
);
5633 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
5635 hr
= IDirect3DSurface8_GetPrivateData(surface
, &d3d8_private_data_test_guid
, &ptr
, &size
);
5636 ok(hr
== D3DERR_MOREDATA
, "Got unexpected hr %#x.\n", hr
);
5637 ok(size
== sizeof(device
), "Got unexpected size %u.\n", size
);
5638 ok(ptr
== (IUnknown
*)0xdeadbeef, "Got unexpected pointer %p.\n", ptr
);
5639 hr
= IDirect3DSurface8_GetPrivateData(surface
, &d3d8_private_data_test_guid2
, NULL
, NULL
);
5640 ok(hr
== D3DERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
5642 hr
= IDirect3DSurface8_GetPrivateData(surface
, &d3d8_private_data_test_guid2
, &ptr
, &size
);
5643 ok(hr
== D3DERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
5644 ok(ptr
== (IUnknown
*)0xdeadbeef, "Got unexpected pointer %p.\n", ptr
);
5645 ok(size
== 0xdeadbabe, "Got unexpected size %u.\n", size
);
5646 /* GetPrivateData with size = NULL causes an access violation on Windows if the
5647 * requested data exists. */
5649 /* Destroying the surface frees the held reference. */
5650 IDirect3DSurface8_Release(surface
);
5651 expected_refcount
= refcount
- 2;
5652 refcount
= get_refcount((IUnknown
*)device
);
5653 ok(refcount
== expected_refcount
, "Got unexpected refcount %u, expected %u.\n", refcount
, expected_refcount
);
5655 hr
= IDirect3DDevice8_CreateTexture(device
, 4, 4, 2, 0, D3DFMT_A8R8G8B8
, D3DPOOL_SCRATCH
, &texture
);
5656 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
5657 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 0, &surface
);
5658 ok(SUCCEEDED(hr
), "Failed to get texture level 0, hr %#x.\n", hr
);
5659 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 1, &surface2
);
5660 ok(SUCCEEDED(hr
), "Failed to get texture level 1, hr %#x.\n", hr
);
5662 hr
= IDirect3DTexture8_SetPrivateData(texture
, &d3d8_private_data_test_guid
, data
, sizeof(data
), 0);
5663 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
5665 memset(data
, 0, sizeof(data
));
5666 size
= sizeof(data
);
5667 hr
= IDirect3DSurface8_GetPrivateData(surface
, &d3d8_private_data_test_guid
, data
, &size
);
5668 ok(hr
== D3DERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
5669 hr
= IDirect3DTexture8_GetPrivateData(texture
, &d3d8_private_data_test_guid
, data
, &size
);
5670 ok(SUCCEEDED(hr
), "Failed to get private data, hr %#x.\n", hr
);
5671 ok(data
[0] == 1 && data
[1] == 2 && data
[2] == 3 && data
[3] == 4,
5672 "Got unexpected private data: %u, %u, %u, %u.\n", data
[0], data
[1], data
[2], data
[3]);
5674 hr
= IDirect3DTexture8_FreePrivateData(texture
, &d3d8_private_data_test_guid
);
5675 ok(SUCCEEDED(hr
), "Failed to free private data, hr %#x.\n", hr
);
5677 hr
= IDirect3DSurface8_SetPrivateData(surface
, &d3d8_private_data_test_guid
, data
, sizeof(data
), 0);
5678 ok(SUCCEEDED(hr
), "Failed to set private data, hr %#x.\n", hr
);
5679 hr
= IDirect3DSurface8_GetPrivateData(surface2
, &d3d8_private_data_test_guid
, data
, &size
);
5680 ok(hr
== D3DERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
5681 hr
= IDirect3DSurface8_FreePrivateData(surface
, &d3d8_private_data_test_guid
);
5682 ok(SUCCEEDED(hr
), "Failed to free private data, hr %#x.\n", hr
);
5684 IDirect3DSurface8_Release(surface2
);
5685 IDirect3DSurface8_Release(surface
);
5686 IDirect3DTexture8_Release(texture
);
5688 refcount
= IDirect3DDevice8_Release(device
);
5689 ok(!refcount
, "Device has %u references left.\n", refcount
);
5690 IDirect3D8_Release(d3d8
);
5691 DestroyWindow(window
);
5694 static void test_surface_dimensions(void)
5696 IDirect3DSurface8
*surface
;
5697 IDirect3DDevice8
*device
;
5703 window
= create_window();
5704 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
5705 ok(!!d3d8
, "Failed to create a D3D object.\n");
5706 if (!(device
= create_device(d3d8
, window
, NULL
)))
5708 skip("Failed to create a D3D device, skipping tests.\n");
5709 IDirect3D8_Release(d3d8
);
5710 DestroyWindow(window
);
5714 hr
= IDirect3DDevice8_CreateImageSurface(device
, 0, 1, D3DFMT_A8R8G8B8
, &surface
);
5715 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
5716 hr
= IDirect3DDevice8_CreateImageSurface(device
, 1, 0, D3DFMT_A8R8G8B8
, &surface
);
5717 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
5719 refcount
= IDirect3DDevice8_Release(device
);
5720 ok(!refcount
, "Device has %u references left.\n", refcount
);
5721 IDirect3D8_Release(d3d8
);
5722 DestroyWindow(window
);
5725 static void test_surface_format_null(void)
5727 static const D3DFORMAT D3DFMT_NULL
= MAKEFOURCC('N','U','L','L');
5728 IDirect3DTexture8
*texture
;
5729 IDirect3DSurface8
*surface
;
5730 IDirect3DSurface8
*rt
, *ds
;
5731 D3DLOCKED_RECT locked_rect
;
5732 IDirect3DDevice8
*device
;
5733 D3DSURFACE_DESC desc
;
5739 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
5740 ok(!!d3d
, "Failed to create a D3D object.\n");
5742 hr
= IDirect3D8_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
5743 D3DUSAGE_RENDERTARGET
, D3DRTYPE_SURFACE
, D3DFMT_NULL
);
5746 skip("No D3DFMT_NULL support, skipping test.\n");
5747 IDirect3D8_Release(d3d
);
5751 window
= create_window();
5752 if (!(device
= create_device(d3d
, window
, NULL
)))
5754 skip("Failed to create a D3D device, skipping tests.\n");
5755 IDirect3D8_Release(d3d
);
5756 DestroyWindow(window
);
5760 hr
= IDirect3D8_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
5761 D3DUSAGE_RENDERTARGET
, D3DRTYPE_TEXTURE
, D3DFMT_NULL
);
5762 ok(hr
== D3D_OK
, "D3DFMT_NULL should be supported for render target textures, hr %#x.\n", hr
);
5764 hr
= IDirect3D8_CheckDepthStencilMatch(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
5765 D3DFMT_NULL
, D3DFMT_D24S8
);
5766 ok(SUCCEEDED(hr
), "Depth stencil match failed for D3DFMT_NULL, hr %#x.\n", hr
);
5768 hr
= IDirect3DDevice8_CreateRenderTarget(device
, 128, 128, D3DFMT_NULL
,
5769 D3DMULTISAMPLE_NONE
, TRUE
, &surface
);
5770 ok(SUCCEEDED(hr
), "Failed to create render target, hr %#x.\n", hr
);
5772 hr
= IDirect3DDevice8_GetRenderTarget(device
, &rt
);
5773 ok(SUCCEEDED(hr
), "Failed to get original render target, hr %#x.\n", hr
);
5775 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &ds
);
5776 ok(SUCCEEDED(hr
), "Failed to get original depth/stencil, hr %#x.\n", hr
);
5778 hr
= IDirect3DDevice8_SetRenderTarget(device
, surface
, NULL
);
5779 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
5781 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x00000000, 0.0f
, 0);
5782 ok(SUCCEEDED(hr
), "Clear failed, hr %#x.\n", hr
);
5784 hr
= IDirect3DDevice8_SetRenderTarget(device
, rt
, ds
);
5785 ok(SUCCEEDED(hr
), "Failed to set render target, hr %#x.\n", hr
);
5787 IDirect3DSurface8_Release(rt
);
5788 IDirect3DSurface8_Release(ds
);
5790 hr
= IDirect3DSurface8_GetDesc(surface
, &desc
);
5791 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
5792 ok(desc
.Width
== 128, "Expected width 128, got %u.\n", desc
.Width
);
5793 ok(desc
.Height
== 128, "Expected height 128, got %u.\n", desc
.Height
);
5795 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, NULL
, 0);
5796 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
5797 ok(locked_rect
.Pitch
, "Expected non-zero pitch, got %u.\n", locked_rect
.Pitch
);
5798 ok(!!locked_rect
.pBits
, "Expected non-NULL pBits, got %p.\n", locked_rect
.pBits
);
5800 hr
= IDirect3DSurface8_UnlockRect(surface
);
5801 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
5803 IDirect3DSurface8_Release(surface
);
5805 hr
= IDirect3DDevice8_CreateTexture(device
, 128, 128, 0, D3DUSAGE_RENDERTARGET
,
5806 D3DFMT_NULL
, D3DPOOL_DEFAULT
, &texture
);
5807 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
5808 IDirect3DTexture8_Release(texture
);
5810 refcount
= IDirect3DDevice8_Release(device
);
5811 ok(!refcount
, "Device has %u references left.\n", refcount
);
5812 IDirect3D8_Release(d3d
);
5813 DestroyWindow(window
);
5816 static void test_surface_double_unlock(void)
5818 static const D3DPOOL pools
[] =
5823 IDirect3DSurface8
*surface
;
5824 IDirect3DDevice8
*device
;
5832 window
= create_window();
5833 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
5834 ok(!!d3d
, "Failed to create a D3D object.\n");
5835 if (!(device
= create_device(d3d
, window
, NULL
)))
5837 skip("Failed to create a D3D device, skipping tests.\n");
5838 IDirect3D8_Release(d3d
);
5839 DestroyWindow(window
);
5843 for (i
= 0; i
< ARRAY_SIZE(pools
); ++i
)
5847 case D3DPOOL_DEFAULT
:
5848 hr
= IDirect3D8_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
5849 D3DUSAGE_RENDERTARGET
, D3DRTYPE_SURFACE
, D3DFMT_X8R8G8B8
);
5852 skip("D3DFMT_X8R8G8B8 render targets not supported, skipping double unlock DEFAULT pool test.\n");
5856 hr
= IDirect3DDevice8_CreateRenderTarget(device
, 64, 64, D3DFMT_X8R8G8B8
,
5857 D3DMULTISAMPLE_NONE
, TRUE
, &surface
);
5858 ok(SUCCEEDED(hr
), "Failed to create render target, hr %#x.\n", hr
);
5861 case D3DPOOL_SYSTEMMEM
:
5862 hr
= IDirect3DDevice8_CreateImageSurface(device
, 64, 64, D3DFMT_X8R8G8B8
, &surface
);
5863 ok(SUCCEEDED(hr
), "Failed to create image surface, hr %#x.\n", hr
);
5870 hr
= IDirect3DSurface8_UnlockRect(surface
);
5871 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x, for surface in pool %#x.\n", hr
, pools
[i
]);
5872 hr
= IDirect3DSurface8_LockRect(surface
, &lr
, NULL
, 0);
5873 ok(SUCCEEDED(hr
), "Failed to lock surface in pool %#x, hr %#x.\n", pools
[i
], hr
);
5874 hr
= IDirect3DSurface8_UnlockRect(surface
);
5875 ok(SUCCEEDED(hr
), "Failed to unlock surface in pool %#x, hr %#x.\n", pools
[i
], hr
);
5876 hr
= IDirect3DSurface8_UnlockRect(surface
);
5877 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x, for surface in pool %#x.\n", hr
, pools
[i
]);
5879 IDirect3DSurface8_Release(surface
);
5882 refcount
= IDirect3DDevice8_Release(device
);
5883 ok(!refcount
, "Device has %u references left.\n", refcount
);
5884 IDirect3D8_Release(d3d
);
5885 DestroyWindow(window
);
5888 static void test_surface_blocks(void)
5894 unsigned int block_width
;
5895 unsigned int block_height
;
5897 BOOL create_size_checked
, core_fmt
;
5901 {D3DFMT_DXT1
, "D3DFMT_DXT1", 4, 4, FALSE
, TRUE
, TRUE
},
5902 {D3DFMT_DXT2
, "D3DFMT_DXT2", 4, 4, FALSE
, TRUE
, TRUE
},
5903 {D3DFMT_DXT3
, "D3DFMT_DXT3", 4, 4, FALSE
, TRUE
, TRUE
},
5904 {D3DFMT_DXT4
, "D3DFMT_DXT4", 4, 4, FALSE
, TRUE
, TRUE
},
5905 {D3DFMT_DXT5
, "D3DFMT_DXT5", 4, 4, FALSE
, TRUE
, TRUE
},
5906 /* ATI1N and ATI2N have 2x2 blocks on all AMD cards and Geforce 7 cards,
5907 * which doesn't match the format spec. On newer Nvidia cards
5908 * they have the correct 4x4 block size */
5909 {MAKEFOURCC('A','T','I','1'), "ATI1N", 4, 4, TRUE
, FALSE
, FALSE
},
5910 {MAKEFOURCC('A','T','I','2'), "ATI2N", 4, 4, TRUE
, FALSE
, FALSE
},
5911 /* Windows drivers generally enforce block-aligned locks for
5912 * YUY2 and UYVY. The notable exception is the AMD r500 driver
5913 * in d3d8. The same driver checks the sizes in d3d9. */
5914 {D3DFMT_YUY2
, "D3DFMT_YUY2", 2, 1, TRUE
, FALSE
, TRUE
},
5915 {D3DFMT_UYVY
, "D3DFMT_UYVY", 2, 1, TRUE
, FALSE
, TRUE
},
5921 /* Don't check the return value, Nvidia returns D3DERR_INVALIDCALL for some formats
5922 * and E_INVALIDARG/DDERR_INVALIDPARAMS for others. */
5927 {D3DPOOL_DEFAULT
, "D3DPOOL_DEFAULT", FALSE
},
5928 {D3DPOOL_SCRATCH
, "D3DPOOL_SCRATCH", TRUE
},
5929 {D3DPOOL_SYSTEMMEM
, "D3DPOOL_SYSTEMMEM",TRUE
},
5930 {D3DPOOL_MANAGED
, "D3DPOOL_MANAGED", TRUE
},
5934 D3DRESOURCETYPE rtype
;
5935 const char *type_name
;
5937 const char *pool_name
;
5938 BOOL need_driver_support
, need_runtime_support
;
5942 /* D3d8 only supports sysmem surfaces, which are created via CreateImageSurface. Other tests confirm
5943 * that they are D3DPOOL_SYSTEMMEM surfaces, but their creation restriction behaves like the scratch
5945 {D3DRTYPE_SURFACE
, "D3DRTYPE_SURFACE", D3DPOOL_SYSTEMMEM
, "D3DPOOL_SYSTEMMEM", FALSE
, TRUE
},
5947 {D3DRTYPE_TEXTURE
, "D3DRTYPE_TEXTURE", D3DPOOL_DEFAULT
, "D3DPOOL_DEFAULT", TRUE
, FALSE
},
5948 {D3DRTYPE_TEXTURE
, "D3DRTYPE_TEXTURE", D3DPOOL_SYSTEMMEM
, "D3DPOOL_SYSTEMMEM", TRUE
, FALSE
},
5949 {D3DRTYPE_TEXTURE
, "D3DRTYPE_TEXTURE", D3DPOOL_MANAGED
, "D3DPOOL_MANAGED", TRUE
, FALSE
},
5950 {D3DRTYPE_TEXTURE
, "D3DRTYPE_TEXTURE", D3DPOOL_SCRATCH
, "D3DPOOL_SCRATCH", FALSE
, TRUE
},
5952 {D3DRTYPE_CUBETEXTURE
, "D3DRTYPE_CUBETEXTURE", D3DPOOL_DEFAULT
, "D3DPOOL_DEFAULT", TRUE
, FALSE
},
5953 {D3DRTYPE_CUBETEXTURE
, "D3DRTYPE_CUBETEXTURE", D3DPOOL_SYSTEMMEM
, "D3DPOOL_SYSTEMMEM", TRUE
, FALSE
},
5954 {D3DRTYPE_CUBETEXTURE
, "D3DRTYPE_CUBETEXTURE", D3DPOOL_MANAGED
, "D3DPOOL_MANAGED", TRUE
, FALSE
},
5955 {D3DRTYPE_CUBETEXTURE
, "D3DRTYPE_CUBETEXTURE", D3DPOOL_SCRATCH
, "D3DPOOL_SCRATCH", FALSE
, TRUE
},
5957 IDirect3DTexture8
*texture
;
5958 IDirect3DCubeTexture8
*cube_texture
;
5959 IDirect3DSurface8
*surface
;
5960 D3DLOCKED_RECT locked_rect
;
5961 IDirect3DDevice8
*device
;
5962 unsigned int i
, j
, k
, w
, h
;
5968 BOOL tex_pow2
, cube_pow2
;
5970 static const RECT invalid
[] =
5972 {60, 60, 60, 68}, /* 0 height */
5973 {60, 60, 68, 60}, /* 0 width */
5974 {68, 60, 60, 68}, /* left > right */
5975 {60, 68, 68, 60}, /* top > bottom */
5976 {-8, 60, 0, 68}, /* left < surface */
5977 {60, -8, 68, 0}, /* top < surface */
5978 {-16, 60, -8, 68}, /* right < surface */
5979 {60, -16, 68, -8}, /* bottom < surface */
5980 {60, 60, 136, 68}, /* right > surface */
5981 {60, 60, 68, 136}, /* bottom > surface */
5982 {136, 60, 144, 68}, /* left > surface */
5983 {60, 136, 68, 144}, /* top > surface */
5986 window
= create_window();
5987 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
5988 ok(!!d3d
, "Failed to create a D3D object.\n");
5989 if (!(device
= create_device(d3d
, window
, NULL
)))
5991 skip("Failed to create a D3D device, skipping tests.\n");
5992 IDirect3D8_Release(d3d
);
5993 DestroyWindow(window
);
5997 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
5998 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
5999 tex_pow2
= caps
.TextureCaps
& D3DPTEXTURECAPS_POW2
;
6001 tex_pow2
= !(caps
.TextureCaps
& D3DPTEXTURECAPS_NONPOW2CONDITIONAL
);
6002 cube_pow2
= !!(caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP_POW2
);
6004 for (i
= 0; i
< ARRAY_SIZE(formats
); ++i
)
6006 BOOL tex_support
, cube_support
, surface_support
, format_known
;
6008 hr
= IDirect3D8_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
6009 0, D3DRTYPE_TEXTURE
, formats
[i
].fmt
);
6010 tex_support
= SUCCEEDED(hr
);
6011 hr
= IDirect3D8_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
6012 0, D3DRTYPE_CUBETEXTURE
, formats
[i
].fmt
);
6013 cube_support
= SUCCEEDED(hr
);
6014 hr
= IDirect3D8_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
6015 0, D3DRTYPE_SURFACE
, formats
[i
].fmt
);
6016 surface_support
= SUCCEEDED(hr
);
6018 /* Scratch pool in general allows texture creation even if the driver does
6019 * not support the format. If the format is an extension format that is not
6020 * known to the runtime, like ATI2N, some driver support is required for
6023 * It is also possible that Windows Vista and Windows 7 d3d8 runtimes know
6024 * about ATI2N. I cannot check this because all my Vista+ machines support
6025 * ATI2N in hardware, but none of my WinXP machines do. */
6026 format_known
= tex_support
|| cube_support
|| surface_support
;
6028 for (w
= 1; w
<= 8; w
++)
6030 for (h
= 1; h
<= 8; h
++)
6032 BOOL block_aligned
= TRUE
;
6035 if (w
& (formats
[i
].block_width
- 1) || h
& (formats
[i
].block_height
- 1))
6036 block_aligned
= FALSE
;
6038 size_is_pow2
= !(w
& (w
- 1) || h
& (h
- 1));
6040 for (j
= 0; j
< ARRAY_SIZE(create_tests
); j
++)
6044 BOOL may_succeed
= FALSE
;
6045 IUnknown
**check_null
;
6047 if (!formats
[i
].core_fmt
)
6049 /* AMD warns against creating ATI2N textures smaller than
6050 * the block size because the runtime cannot calculate the
6051 * correct texture size. Generalize this for all extension
6053 if (w
< formats
[i
].block_width
|| h
< formats
[i
].block_height
)
6057 texture
= (IDirect3DTexture8
*)0xdeadbeef;
6058 cube_texture
= (IDirect3DCubeTexture8
*)0xdeadbeef;
6059 surface
= (IDirect3DSurface8
*)0xdeadbeef;
6061 switch (create_tests
[j
].rtype
)
6063 case D3DRTYPE_TEXTURE
:
6064 check_null
= (IUnknown
**)&texture
;
6065 hr
= IDirect3DDevice8_CreateTexture(device
, w
, h
, 1, 0,
6066 formats
[i
].fmt
, create_tests
[j
].pool
, &texture
);
6067 support
= tex_support
;
6071 case D3DRTYPE_CUBETEXTURE
:
6074 check_null
= (IUnknown
**)&cube_texture
;
6075 hr
= IDirect3DDevice8_CreateCubeTexture(device
, w
, 1, 0,
6076 formats
[i
].fmt
, create_tests
[j
].pool
, &cube_texture
);
6077 support
= cube_support
;
6081 case D3DRTYPE_SURFACE
:
6082 check_null
= (IUnknown
**)&surface
;
6083 hr
= IDirect3DDevice8_CreateImageSurface(device
, w
, h
,
6084 formats
[i
].fmt
, &surface
);
6085 support
= surface_support
;
6096 if (create_tests
[j
].need_driver_support
&& !support
)
6097 expect_hr
= D3DERR_INVALIDCALL
;
6098 else if (create_tests
[j
].need_runtime_support
&& !formats
[i
].core_fmt
&& !format_known
)
6099 expect_hr
= D3DERR_INVALIDCALL
;
6100 else if (formats
[i
].create_size_checked
&& !block_aligned
)
6101 expect_hr
= D3DERR_INVALIDCALL
;
6102 else if (pow2
&& !size_is_pow2
&& create_tests
[j
].need_driver_support
)
6103 expect_hr
= D3DERR_INVALIDCALL
;
6107 if (!formats
[i
].core_fmt
&& !format_known
&& FAILED(expect_hr
))
6110 /* Wine knows about ATI2N and happily creates a scratch resource even if GL
6111 * does not support it. Accept scratch creation of extension formats on
6112 * Windows as well if it occurs. We don't really care if e.g. a Windows 7
6113 * on an r200 GPU creates scratch ATI2N texture even though the card doesn't
6115 ok(hr
== expect_hr
|| ((SUCCEEDED(hr
) && may_succeed
)),
6116 "Got unexpected hr %#x for format %s, pool %s, type %s, size %ux%u.\n",
6117 hr
, formats
[i
].name
, create_tests
[j
].pool_name
, create_tests
[j
].type_name
, w
, h
);
6120 ok(*check_null
== NULL
, "Got object ptr %p, expected NULL.\n", *check_null
);
6122 IUnknown_Release(*check_null
);
6127 hr
= IDirect3D8_CheckDeviceFormat(d3d
, 0, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
6128 D3DUSAGE_DYNAMIC
, D3DRTYPE_TEXTURE
, formats
[i
].fmt
);
6131 skip("Format %s not supported, skipping lockrect offset tests.\n", formats
[i
].name
);
6135 for (j
= 0; j
< ARRAY_SIZE(pools
); ++j
)
6137 hr
= IDirect3DDevice8_CreateTexture(device
, 128, 128, 1,
6138 pools
[j
].pool
== D3DPOOL_DEFAULT
? D3DUSAGE_DYNAMIC
: 0,
6139 formats
[i
].fmt
, pools
[j
].pool
, &texture
);
6140 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
6141 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 0, &surface
);
6142 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
6143 IDirect3DTexture8_Release(texture
);
6145 if (formats
[i
].block_width
> 1)
6147 SetRect(&rect
, formats
[i
].block_width
>> 1, 0, formats
[i
].block_width
, formats
[i
].block_height
);
6148 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, &rect
, 0);
6149 ok(FAILED(hr
) == !pools
[j
].success
|| broken(formats
[i
].broken
),
6150 "Partial block lock %s, expected %s, format %s, pool %s.\n",
6151 SUCCEEDED(hr
) ? "succeeded" : "failed",
6152 pools
[j
].success
? "success" : "failure", formats
[i
].name
, pools
[j
].name
);
6155 hr
= IDirect3DSurface8_UnlockRect(surface
);
6156 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
6159 SetRect(&rect
, 0, 0, formats
[i
].block_width
>> 1, formats
[i
].block_height
);
6160 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, &rect
, 0);
6161 ok(FAILED(hr
) == !pools
[j
].success
|| broken(formats
[i
].broken
),
6162 "Partial block lock %s, expected %s, format %s, pool %s.\n",
6163 SUCCEEDED(hr
) ? "succeeded" : "failed",
6164 pools
[j
].success
? "success" : "failure", formats
[i
].name
, pools
[j
].name
);
6167 hr
= IDirect3DSurface8_UnlockRect(surface
);
6168 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
6172 if (formats
[i
].block_height
> 1)
6174 SetRect(&rect
, 0, formats
[i
].block_height
>> 1, formats
[i
].block_width
, formats
[i
].block_height
);
6175 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, &rect
, 0);
6176 ok(FAILED(hr
) == !pools
[j
].success
|| broken(formats
[i
].broken
),
6177 "Partial block lock %s, expected %s, format %s, pool %s.\n",
6178 SUCCEEDED(hr
) ? "succeeded" : "failed",
6179 pools
[j
].success
? "success" : "failure", formats
[i
].name
, pools
[j
].name
);
6182 hr
= IDirect3DSurface8_UnlockRect(surface
);
6183 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
6186 SetRect(&rect
, 0, 0, formats
[i
].block_width
, formats
[i
].block_height
>> 1);
6187 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, &rect
, 0);
6188 ok(FAILED(hr
) == !pools
[j
].success
|| broken(formats
[i
].broken
),
6189 "Partial block lock %s, expected %s, format %s, pool %s.\n",
6190 SUCCEEDED(hr
) ? "succeeded" : "failed",
6191 pools
[j
].success
? "success" : "failure", formats
[i
].name
, pools
[j
].name
);
6194 hr
= IDirect3DSurface8_UnlockRect(surface
);
6195 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
6199 for (k
= 0; k
< ARRAY_SIZE(invalid
); ++k
)
6201 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, &invalid
[k
], 0);
6202 ok(FAILED(hr
) == !pools
[j
].success
, "Invalid lock %s(%#x), expected %s, format %s, pool %s, case %u.\n",
6203 SUCCEEDED(hr
) ? "succeeded" : "failed", hr
, pools
[j
].success
? "success" : "failure",
6204 formats
[i
].name
, pools
[j
].name
, k
);
6207 hr
= IDirect3DSurface8_UnlockRect(surface
);
6208 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
6212 SetRect(&rect
, 0, 0, formats
[i
].block_width
, formats
[i
].block_height
);
6213 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, &rect
, 0);
6214 ok(hr
== D3D_OK
, "Got unexpected hr %#x for format %s, pool %s.\n", hr
, formats
[i
].name
, pools
[j
].name
);
6215 hr
= IDirect3DSurface8_UnlockRect(surface
);
6216 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
6218 IDirect3DSurface8_Release(surface
);
6221 if (formats
[i
].block_width
== 1 && formats
[i
].block_height
== 1)
6223 if (!formats
[i
].core_fmt
)
6226 hr
= IDirect3DDevice8_CreateTexture(device
, formats
[i
].block_width
, formats
[i
].block_height
, 2,
6227 D3DUSAGE_DYNAMIC
, formats
[i
].fmt
, D3DPOOL_DEFAULT
, &texture
);
6228 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x, format %s.\n", hr
, formats
[i
].name
);
6230 hr
= IDirect3DTexture8_LockRect(texture
, 1, &locked_rect
, NULL
, 0);
6231 ok(SUCCEEDED(hr
), "Failed lock texture, hr %#x.\n", hr
);
6232 hr
= IDirect3DTexture8_UnlockRect(texture
, 1);
6233 ok(SUCCEEDED(hr
), "Failed lock texture, hr %#x.\n", hr
);
6237 rect
.right
= formats
[i
].block_width
== 1 ? 1 : formats
[i
].block_width
>> 1;
6238 rect
.bottom
= formats
[i
].block_height
== 1 ? 1 : formats
[i
].block_height
>> 1;
6239 hr
= IDirect3DTexture8_LockRect(texture
, 1, &locked_rect
, &rect
, 0);
6240 ok(SUCCEEDED(hr
), "Failed lock texture, hr %#x.\n", hr
);
6241 hr
= IDirect3DTexture8_UnlockRect(texture
, 1);
6242 ok(SUCCEEDED(hr
), "Failed lock texture, hr %#x.\n", hr
);
6244 rect
.right
= formats
[i
].block_width
;
6245 rect
.bottom
= formats
[i
].block_height
;
6246 hr
= IDirect3DTexture8_LockRect(texture
, 1, &locked_rect
, &rect
, 0);
6247 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
6249 IDirect3DTexture8_UnlockRect(texture
, 1);
6251 IDirect3DTexture8_Release(texture
);
6254 refcount
= IDirect3DDevice8_Release(device
);
6255 ok(!refcount
, "Device has %u references left.\n", refcount
);
6256 IDirect3D8_Release(d3d
);
6257 DestroyWindow(window
);
6260 static void test_set_palette(void)
6262 IDirect3DDevice8
*device
;
6267 PALETTEENTRY pal
[256];
6271 window
= create_window();
6272 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
6273 ok(!!d3d8
, "Failed to create a D3D object.\n");
6274 if (!(device
= create_device(d3d8
, window
, NULL
)))
6276 skip("Failed to create a D3D device, skipping tests.\n");
6277 IDirect3D8_Release(d3d8
);
6278 DestroyWindow(window
);
6282 for (i
= 0; i
< ARRAY_SIZE(pal
); i
++)
6287 pal
[i
].peFlags
= 0xff;
6289 hr
= IDirect3DDevice8_SetPaletteEntries(device
, 0, pal
);
6290 ok(SUCCEEDED(hr
), "Failed to set palette entries, hr %#x.\n", hr
);
6292 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
6293 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
6294 for (i
= 0; i
< ARRAY_SIZE(pal
); i
++)
6301 if (caps
.TextureCaps
& D3DPTEXTURECAPS_ALPHAPALETTE
)
6303 hr
= IDirect3DDevice8_SetPaletteEntries(device
, 0, pal
);
6304 ok(SUCCEEDED(hr
), "Failed to set palette entries, hr %#x.\n", hr
);
6308 hr
= IDirect3DDevice8_SetPaletteEntries(device
, 0, pal
);
6309 ok(hr
== D3DERR_INVALIDCALL
, "SetPaletteEntries returned %#x, expected D3DERR_INVALIDCALL.\n", hr
);
6312 refcount
= IDirect3DDevice8_Release(device
);
6313 ok(!refcount
, "Device has %u references left.\n", refcount
);
6314 IDirect3D8_Release(d3d8
);
6315 DestroyWindow(window
);
6318 static void test_pinned_buffers(void)
6328 {CREATE_DEVICE_SWVP_ONLY
, D3DUSAGE_DYNAMIC
| D3DUSAGE_WRITEONLY
, D3DPOOL_DEFAULT
},
6329 {0, 0, D3DPOOL_MANAGED
},
6330 {0, 0, D3DPOOL_SYSTEMMEM
},
6332 static const unsigned int vertex_count
= 1024;
6333 struct device_desc device_desc
;
6334 IDirect3DVertexBuffer8
*buffer
;
6335 D3DVERTEXBUFFER_DESC desc
;
6336 IDirect3DDevice8
*device
;
6337 struct vec3
*ptr
, *ptr2
;
6338 unsigned int i
, test
;
6344 window
= create_window();
6345 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
6346 ok(!!d3d
, "Failed to create a D3D object.\n");
6348 for (test
= 0; test
< ARRAY_SIZE(tests
); ++test
)
6350 device_desc
.adapter_ordinal
= D3DADAPTER_DEFAULT
;
6351 device_desc
.device_window
= window
;
6352 device_desc
.width
= 640;
6353 device_desc
.height
= 480;
6354 device_desc
.flags
= tests
[test
].device_flags
;
6355 if (!(device
= create_device(d3d
, window
, &device_desc
)))
6357 skip("Test %u: failed to create a D3D device.\n", test
);
6361 hr
= IDirect3DDevice8_CreateVertexBuffer(device
, vertex_count
* sizeof(*ptr
),
6362 tests
[test
].usage
, 0, tests
[test
].pool
, &buffer
);
6363 ok(hr
== D3D_OK
, "Test %u: got unexpected hr %#x.\n", test
, hr
);
6364 hr
= IDirect3DVertexBuffer8_GetDesc(buffer
, &desc
);
6365 ok(hr
== D3D_OK
, "Test %u: got unexpected hr %#x.\n", test
, hr
);
6366 ok(desc
.Pool
== tests
[test
].pool
, "Test %u: got unexpected pool %#x.\n", test
, desc
.Pool
);
6367 ok(desc
.Usage
== tests
[test
].usage
, "Test %u: got unexpected usage %#x.\n", test
, desc
.Usage
);
6369 hr
= IDirect3DVertexBuffer8_Lock(buffer
, 0, vertex_count
* sizeof(*ptr
), (BYTE
**)&ptr
, D3DLOCK_DISCARD
);
6370 ok(hr
== D3D_OK
, "Test %u: got unexpected hr %#x.\n", test
, hr
);
6371 for (i
= 0; i
< vertex_count
; ++i
)
6373 ptr
[i
].x
= i
* 1.0f
;
6374 ptr
[i
].y
= i
* 2.0f
;
6375 ptr
[i
].z
= i
* 3.0f
;
6377 hr
= IDirect3DVertexBuffer8_Unlock(buffer
);
6378 ok(hr
== D3D_OK
, "Test %u: got unexpected hr %#x.\n", test
, hr
);
6380 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
);
6381 ok(hr
== D3D_OK
, "Test %u: got unexpected hr %#x.\n", test
, hr
);
6382 hr
= IDirect3DDevice8_SetStreamSource(device
, 0, buffer
, sizeof(*ptr
));
6383 ok(hr
== D3D_OK
, "Test %u: got unexpected hr %#x.\n", test
, hr
);
6384 hr
= IDirect3DDevice8_BeginScene(device
);
6385 ok(hr
== D3D_OK
, "Test %u: got unexpected hr %#x.\n", test
, hr
);
6386 hr
= IDirect3DDevice8_DrawPrimitive(device
, D3DPT_TRIANGLELIST
, 0, 2);
6387 ok(hr
== D3D_OK
, "Test %u: got unexpected hr %#x.\n", test
, hr
);
6388 hr
= IDirect3DDevice8_EndScene(device
);
6389 ok(hr
== D3D_OK
, "Test %u: got unexpected hr %#x.\n", test
, hr
);
6391 hr
= IDirect3DVertexBuffer8_Lock(buffer
, 0, vertex_count
* sizeof(*ptr2
), (BYTE
**)&ptr2
, D3DLOCK_DISCARD
);
6392 ok(hr
== D3D_OK
, "Test %u: got unexpected hr %#x.\n", test
, hr
);
6393 ok(ptr2
== ptr
, "Test %u: got unexpected ptr2 %p, expected %p.\n", test
, ptr2
, ptr
);
6394 for (i
= 0; i
< vertex_count
; ++i
)
6396 if (ptr2
[i
].x
!= i
* 1.0f
|| ptr2
[i
].y
!= i
* 2.0f
|| ptr2
[i
].z
!= i
* 3.0f
)
6398 ok(FALSE
, "Test %u: got unexpected vertex %u {%.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e}.\n",
6399 test
, i
, ptr2
[i
].x
, ptr2
[i
].y
, ptr2
[i
].z
, i
* 1.0f
, i
* 2.0f
, i
* 3.0f
);
6403 hr
= IDirect3DVertexBuffer8_Unlock(buffer
);
6404 ok(hr
== D3D_OK
, "Test %u: got unexpected hr %#x.\n", test
, hr
);
6406 IDirect3DVertexBuffer8_Release(buffer
);
6407 refcount
= IDirect3DDevice8_Release(device
);
6408 ok(!refcount
, "Test %u: device has %u references left.\n", test
, refcount
);
6410 IDirect3D8_Release(d3d
);
6411 DestroyWindow(window
);
6414 static void test_npot_textures(void)
6416 IDirect3DDevice8
*device
= NULL
;
6422 IDirect3DTexture8
*texture
;
6423 IDirect3DCubeTexture8
*cube_texture
;
6424 IDirect3DVolumeTexture8
*volume_texture
;
6428 const char *pool_name
;
6433 { D3DPOOL_DEFAULT
, "D3DPOOL_DEFAULT", D3DERR_INVALIDCALL
},
6434 { D3DPOOL_MANAGED
, "D3DPOOL_MANAGED", D3DERR_INVALIDCALL
},
6435 { D3DPOOL_SYSTEMMEM
, "D3DPOOL_SYSTEMMEM", D3DERR_INVALIDCALL
},
6436 { D3DPOOL_SCRATCH
, "D3DPOOL_SCRATCH", D3D_OK
},
6438 unsigned int i
, levels
;
6439 BOOL tex_pow2
, cube_pow2
, vol_pow2
;
6441 window
= create_window();
6442 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
6443 ok(!!d3d8
, "Failed to create a D3D object.\n");
6444 if (!(device
= create_device(d3d8
, window
, NULL
)))
6446 skip("Failed to create a D3D device, skipping tests.\n");
6450 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
6451 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
6452 tex_pow2
= !!(caps
.TextureCaps
& D3DPTEXTURECAPS_POW2
);
6453 cube_pow2
= !!(caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP_POW2
);
6454 vol_pow2
= !!(caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP_POW2
);
6455 ok(cube_pow2
== tex_pow2
, "Cube texture and 2d texture pow2 restrictions mismatch.\n");
6456 ok(vol_pow2
== tex_pow2
, "Volume texture and 2d texture pow2 restrictions mismatch.\n");
6458 for (i
= 0; i
< ARRAY_SIZE(pools
); i
++)
6460 for (levels
= 0; levels
<= 2; levels
++)
6464 hr
= IDirect3DDevice8_CreateTexture(device
, 10, 10, levels
, 0, D3DFMT_X8R8G8B8
,
6465 pools
[i
].pool
, &texture
);
6470 else if (caps
.TextureCaps
& D3DPTEXTURECAPS_NONPOW2CONDITIONAL
)
6475 expected
= pools
[i
].hr
;
6479 expected
= pools
[i
].hr
;
6481 ok(hr
== expected
, "CreateTexture(w=h=10, %s, levels=%u) returned hr %#x, expected %#x.\n",
6482 pools
[i
].pool_name
, levels
, hr
, expected
);
6485 IDirect3DTexture8_Release(texture
);
6488 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 3, 1, 0, D3DFMT_X8R8G8B8
,
6489 pools
[i
].pool
, &cube_texture
);
6492 ok(hr
== pools
[i
].hr
, "CreateCubeTexture(EdgeLength=3, %s) returned hr %#x, expected %#x.\n",
6493 pools
[i
].pool_name
, hr
, pools
[i
].hr
);
6497 ok(SUCCEEDED(hr
), "CreateCubeTexture(EdgeLength=3, %s) returned hr %#x, expected %#x.\n",
6498 pools
[i
].pool_name
, hr
, D3D_OK
);
6502 IDirect3DCubeTexture8_Release(cube_texture
);
6504 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 2, 2, 3, 1, 0, D3DFMT_X8R8G8B8
,
6505 pools
[i
].pool
, &volume_texture
);
6508 ok(hr
== pools
[i
].hr
, "CreateVolumeTextur(Depth=3, %s) returned hr %#x, expected %#x.\n",
6509 pools
[i
].pool_name
, hr
, pools
[i
].hr
);
6513 ok(SUCCEEDED(hr
), "CreateVolumeTextur(Depth=3, %s) returned hr %#x, expected %#x.\n",
6514 pools
[i
].pool_name
, hr
, D3D_OK
);
6518 IDirect3DVolumeTexture8_Release(volume_texture
);
6524 refcount
= IDirect3DDevice8_Release(device
);
6525 ok(!refcount
, "Device has %u references left.\n", refcount
);
6527 IDirect3D8_Release(d3d8
);
6528 DestroyWindow(window
);
6532 static void test_volume_locking(void)
6534 IDirect3DDevice8
*device
;
6538 IDirect3DVolumeTexture8
*texture
;
6540 D3DLOCKED_BOX locked_box
;
6547 HRESULT create_hr
, lock_hr
;
6551 { D3DPOOL_DEFAULT
, 0, D3D_OK
, D3DERR_INVALIDCALL
},
6552 { D3DPOOL_DEFAULT
, D3DUSAGE_DYNAMIC
, D3D_OK
, D3D_OK
},
6553 { D3DPOOL_SYSTEMMEM
, 0, D3D_OK
, D3D_OK
},
6554 { D3DPOOL_SYSTEMMEM
, D3DUSAGE_DYNAMIC
, D3D_OK
, D3D_OK
},
6555 { D3DPOOL_MANAGED
, 0, D3D_OK
, D3D_OK
},
6556 { D3DPOOL_MANAGED
, D3DUSAGE_DYNAMIC
, D3DERR_INVALIDCALL
, D3D_OK
},
6557 { D3DPOOL_SCRATCH
, 0, D3D_OK
, D3D_OK
},
6558 { D3DPOOL_SCRATCH
, D3DUSAGE_DYNAMIC
, D3DERR_INVALIDCALL
, D3D_OK
},
6561 window
= create_window();
6562 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
6563 ok(!!d3d8
, "Failed to create a D3D object.\n");
6564 if (!(device
= create_device(d3d8
, window
, NULL
)))
6566 skip("Failed to create a D3D device, skipping tests.\n");
6567 IDirect3D8_Release(d3d8
);
6568 DestroyWindow(window
);
6572 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
6573 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
6574 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP
))
6576 skip("Volume textures not supported, skipping test.\n");
6580 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
6582 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 4, 4, 4, 1, tests
[i
].usage
,
6583 D3DFMT_A8R8G8B8
, tests
[i
].pool
, &texture
);
6584 ok(hr
== tests
[i
].create_hr
, "Creating volume texture pool=%u, usage=%#x returned %#x, expected %#x.\n",
6585 tests
[i
].pool
, tests
[i
].usage
, hr
, tests
[i
].create_hr
);
6589 locked_box
.pBits
= (void *)0xdeadbeef;
6590 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, NULL
, 0);
6591 ok(hr
== tests
[i
].lock_hr
, "Lock returned %#x, expected %#x.\n", hr
, tests
[i
].lock_hr
);
6594 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
6595 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6599 ok (locked_box
.pBits
== NULL
, "Failed lock set pBits = %p, expected NULL.\n", locked_box
.pBits
);
6601 IDirect3DVolumeTexture8_Release(texture
);
6605 refcount
= IDirect3DDevice8_Release(device
);
6606 ok(!refcount
, "Device has %u references left.\n", refcount
);
6607 IDirect3D8_Release(d3d8
);
6608 DestroyWindow(window
);
6611 static void test_update_volumetexture(void)
6613 D3DADAPTER_IDENTIFIER8 identifier
;
6614 IDirect3DDevice8
*device
;
6618 IDirect3DVolumeTexture8
*src
, *dst
;
6620 D3DLOCKED_BOX locked_box
;
6626 D3DPOOL src_pool
, dst_pool
;
6631 { D3DPOOL_DEFAULT
, D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
},
6632 { D3DPOOL_MANAGED
, D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
},
6633 { D3DPOOL_SYSTEMMEM
, D3DPOOL_DEFAULT
, D3D_OK
},
6634 { D3DPOOL_SCRATCH
, D3DPOOL_DEFAULT
, D3DERR_INVALIDCALL
},
6636 { D3DPOOL_DEFAULT
, D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
},
6637 { D3DPOOL_MANAGED
, D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
},
6638 { D3DPOOL_SYSTEMMEM
, D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
},
6639 { D3DPOOL_SCRATCH
, D3DPOOL_MANAGED
, D3DERR_INVALIDCALL
},
6641 { D3DPOOL_DEFAULT
, D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
},
6642 { D3DPOOL_MANAGED
, D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
},
6643 { D3DPOOL_SYSTEMMEM
, D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
},
6644 { D3DPOOL_SCRATCH
, D3DPOOL_SYSTEMMEM
, D3DERR_INVALIDCALL
},
6646 { D3DPOOL_DEFAULT
, D3DPOOL_SCRATCH
, D3DERR_INVALIDCALL
},
6647 { D3DPOOL_MANAGED
, D3DPOOL_SCRATCH
, D3DERR_INVALIDCALL
},
6648 { D3DPOOL_SYSTEMMEM
, D3DPOOL_SCRATCH
, D3DERR_INVALIDCALL
},
6649 { D3DPOOL_SCRATCH
, D3DPOOL_SCRATCH
, D3DERR_INVALIDCALL
},
6653 UINT src_size
, dst_size
;
6654 UINT src_lvl
, dst_lvl
;
6655 D3DFORMAT src_fmt
, dst_fmt
;
6659 { 8, 8, 0, 0, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
},
6660 { 8, 8, 4, 4, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
},
6661 { 8, 8, 2, 2, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
},
6662 { 8, 8, 1, 1, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
},
6663 { 8, 8, 4, 0, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
},
6664 { 8, 8, 1, 4, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
}, /* Different level count */
6665 { 4, 8, 1, 1, D3DFMT_A8R8G8B8
, D3DFMT_A8R8G8B8
}, /* Different size */
6666 { 8, 8, 4, 4, D3DFMT_A8R8G8B8
, D3DFMT_X8R8G8B8
}, /* Different format */
6669 window
= create_window();
6670 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
6671 ok(!!d3d8
, "Failed to create a D3D object.\n");
6672 hr
= IDirect3D8_GetAdapterIdentifier(d3d8
, D3DADAPTER_DEFAULT
, 0, &identifier
);
6673 ok(SUCCEEDED(hr
), "Failed to get adapter identifier, hr %#x.\n", hr
);
6674 is_warp
= adapter_is_warp(&identifier
);
6675 if (!(device
= create_device(d3d8
, window
, NULL
)))
6677 skip("Failed to create a D3D device, skipping tests.\n");
6678 IDirect3D8_Release(d3d8
);
6679 DestroyWindow(window
);
6683 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
6684 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
6685 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP
))
6687 skip("Volume textures not supported, skipping test.\n");
6691 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
6693 DWORD src_usage
= tests
[i
].src_pool
== D3DPOOL_DEFAULT
? D3DUSAGE_DYNAMIC
: 0;
6694 DWORD dst_usage
= tests
[i
].dst_pool
== D3DPOOL_DEFAULT
? D3DUSAGE_DYNAMIC
: 0;
6696 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 1, 1, 1, 1, src_usage
,
6697 D3DFMT_A8R8G8B8
, tests
[i
].src_pool
, &src
);
6698 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x.\n", hr
);
6699 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 1, 1, 1, 1, dst_usage
,
6700 D3DFMT_A8R8G8B8
, tests
[i
].dst_pool
, &dst
);
6701 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x.\n", hr
);
6703 hr
= IDirect3DVolumeTexture8_LockBox(src
, 0, &locked_box
, NULL
, 0);
6704 ok(SUCCEEDED(hr
), "Failed to lock volume texture, hr %#x.\n", hr
);
6705 *((DWORD
*)locked_box
.pBits
) = 0x11223344;
6706 hr
= IDirect3DVolumeTexture8_UnlockBox(src
, 0);
6707 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6709 hr
= IDirect3DDevice8_UpdateTexture(device
, (IDirect3DBaseTexture8
*)src
, (IDirect3DBaseTexture8
*)dst
);
6710 ok(hr
== tests
[i
].hr
, "UpdateTexture returned %#x, expected %#x, src pool %x, dst pool %u.\n",
6711 hr
, tests
[i
].hr
, tests
[i
].src_pool
, tests
[i
].dst_pool
);
6715 DWORD content
= *((DWORD
*)locked_box
.pBits
);
6716 hr
= IDirect3DVolumeTexture8_LockBox(dst
, 0, &locked_box
, NULL
, 0);
6717 ok(SUCCEEDED(hr
), "Failed to lock volume texture, hr %#x.\n", hr
);
6718 ok(content
== 0x11223344, "Dest texture contained %#x, expected 0x11223344.\n", content
);
6719 hr
= IDirect3DVolumeTexture8_UnlockBox(dst
, 0);
6720 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6722 IDirect3DVolumeTexture8_Release(src
);
6723 IDirect3DVolumeTexture8_Release(dst
);
6726 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_MIPVOLUMEMAP
))
6728 skip("Mipmapped volume maps not supported.\n");
6732 for (i
= 0; i
< ARRAY_SIZE(tests2
); i
++)
6734 hr
= IDirect3DDevice8_CreateVolumeTexture(device
,
6735 tests2
[i
].src_size
, tests2
[i
].src_size
, tests2
[i
].src_size
,
6736 tests2
[i
].src_lvl
, 0, tests2
[i
].src_fmt
, D3DPOOL_SYSTEMMEM
, &src
);
6737 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x, case %u.\n", hr
, i
);
6738 hr
= IDirect3DDevice8_CreateVolumeTexture(device
,
6739 tests2
[i
].dst_size
, tests2
[i
].dst_size
, tests2
[i
].dst_size
,
6740 tests2
[i
].dst_lvl
, 0, tests2
[i
].dst_fmt
, D3DPOOL_DEFAULT
, &dst
);
6741 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x, case %u.\n", hr
, i
);
6743 hr
= IDirect3DDevice8_UpdateTexture(device
, (IDirect3DBaseTexture8
*)src
, (IDirect3DBaseTexture8
*)dst
);
6744 todo_wine_if (FAILED(hr
))
6745 ok(SUCCEEDED(hr
) || (is_warp
&& (i
== 6 || i
== 7)), /* Fails with Win10 WARP driver */
6746 "Failed to update texture, hr %#x, case %u.\n", hr
, i
);
6748 IDirect3DVolumeTexture8_Release(src
);
6749 IDirect3DVolumeTexture8_Release(dst
);
6752 /* As far as I can see, UpdateTexture on non-matching texture behaves like a memcpy. The raw data
6753 * stays the same in a format change, a 2x2x1 texture is copied into the first row of a 4x4x1 texture,
6754 * etc. I could not get it to segfault, but the nonexistent 5th pixel of a 2x2x1 texture is copied into
6755 * pixel 1x2x1 of a 4x4x1 texture, demonstrating a read beyond the texture's end. I suspect any bad
6756 * memory access is silently ignored by the runtime, in the kernel or on the GPU.
6758 * I'm not adding tests for this behavior until an application needs it. */
6761 refcount
= IDirect3DDevice8_Release(device
);
6762 ok(!refcount
, "Device has %u references left.\n", refcount
);
6763 IDirect3D8_Release(d3d8
);
6764 DestroyWindow(window
);
6767 static void test_create_rt_ds_fail(void)
6769 IDirect3DDevice8
*device
;
6774 IDirect3DSurface8
*surface
;
6776 window
= create_window();
6777 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
6778 ok(!!d3d8
, "Failed to create a D3D object.\n");
6779 if (!(device
= create_device(d3d8
, window
, NULL
)))
6781 skip("Failed to create a D3D device, skipping tests.\n");
6782 IDirect3D8_Release(d3d8
);
6783 DestroyWindow(window
);
6787 /* Output pointer == NULL segfaults on Windows. */
6789 surface
= (IDirect3DSurface8
*)0xdeadbeef;
6790 hr
= IDirect3DDevice8_CreateRenderTarget(device
, 4, 4, D3DFMT_D16
,
6791 D3DMULTISAMPLE_NONE
, FALSE
, &surface
);
6792 ok(hr
== D3DERR_INVALIDCALL
, "Creating a D16 render target returned hr %#x.\n", hr
);
6793 ok(surface
== NULL
, "Got pointer %p, expected NULL.\n", surface
);
6795 IDirect3DSurface8_Release(surface
);
6797 surface
= (IDirect3DSurface8
*)0xdeadbeef;
6798 hr
= IDirect3DDevice8_CreateDepthStencilSurface(device
, 4, 4, D3DFMT_A8R8G8B8
,
6799 D3DMULTISAMPLE_NONE
, &surface
);
6800 ok(hr
== D3DERR_INVALIDCALL
, "Creating a A8R8G8B8 depth stencil returned hr %#x.\n", hr
);
6801 ok(surface
== NULL
, "Got pointer %p, expected NULL.\n", surface
);
6803 IDirect3DSurface8_Release(surface
);
6805 refcount
= IDirect3DDevice8_Release(device
);
6806 ok(!refcount
, "Device has %u references left.\n", refcount
);
6807 IDirect3D8_Release(d3d8
);
6808 DestroyWindow(window
);
6811 static void test_volume_blocks(void)
6813 IDirect3DDevice8
*device
;
6819 IDirect3DVolumeTexture8
*texture
;
6820 unsigned int w
, h
, d
, i
, j
;
6825 unsigned int block_width
;
6826 unsigned int block_height
;
6827 unsigned int block_depth
;
6828 unsigned int block_size
;
6829 unsigned int broken
;
6830 BOOL create_size_checked
, core_fmt
;
6834 /* Scratch volumes enforce DXTn block locks, unlike their surface counterparts.
6835 * ATI2N and YUV blocks are not enforced on any tested card (r200, gtx 460). */
6836 {D3DFMT_DXT1
, "D3DFMT_DXT1", 4, 4, 1, 8, 0, TRUE
, TRUE
},
6837 {D3DFMT_DXT2
, "D3DFMT_DXT2", 4, 4, 1, 16, 0, TRUE
, TRUE
},
6838 {D3DFMT_DXT3
, "D3DFMT_DXT3", 4, 4, 1, 16, 0, TRUE
, TRUE
},
6839 {D3DFMT_DXT4
, "D3DFMT_DXT4", 4, 4, 1, 16, 0, TRUE
, TRUE
},
6840 {D3DFMT_DXT5
, "D3DFMT_DXT5", 4, 4, 1, 16, 0, TRUE
, TRUE
},
6841 {D3DFMT_DXT5
, "D3DFMT_DXT5", 4, 4, 1, 16, 0, TRUE
, TRUE
},
6842 /* ATI2N has 2x2 blocks on all AMD cards and Geforce 7 cards,
6843 * which doesn't match the format spec. On newer Nvidia cards
6844 * it has the correct 4x4 block size.
6845 * ATI1N volume textures are only supported by AMD GPUs right
6846 * now and locking offsets seem just wrong. */
6847 {MAKEFOURCC('A','T','I','1'), "ATI1N", 4, 4, 1, 8, 2, FALSE
, FALSE
},
6848 {MAKEFOURCC('A','T','I','2'), "ATI2N", 4, 4, 1, 16, 1, FALSE
, FALSE
},
6849 {D3DFMT_YUY2
, "D3DFMT_YUY2", 2, 1, 1, 4, 1, FALSE
, TRUE
},
6850 {D3DFMT_UYVY
, "D3DFMT_UYVY", 2, 1, 1, 4, 1, FALSE
, TRUE
},
6856 BOOL need_driver_support
, need_runtime_support
;
6860 {D3DPOOL_DEFAULT
, "D3DPOOL_DEFAULT", TRUE
, FALSE
},
6861 {D3DPOOL_SCRATCH
, "D3DPOOL_SCRATCH", FALSE
, TRUE
},
6862 {D3DPOOL_SYSTEMMEM
, "D3DPOOL_SYSTEMMEM",TRUE
, FALSE
},
6863 {D3DPOOL_MANAGED
, "D3DPOOL_MANAGED", TRUE
, FALSE
},
6867 unsigned int x
, y
, z
, x2
, y2
, z2
;
6881 D3DLOCKED_BOX locked_box
;
6883 INT expected_row_pitch
, expected_slice_pitch
;
6886 unsigned int offset
, expected_offset
;
6888 window
= create_window();
6889 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
6890 ok(!!d3d8
, "Failed to create a D3D object.\n");
6891 if (!(device
= create_device(d3d8
, window
, NULL
)))
6893 skip("Failed to create a D3D device, skipping tests.\n");
6894 IDirect3D8_Release(d3d8
);
6895 DestroyWindow(window
);
6898 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
6899 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
6900 pow2
= !!(caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP_POW2
);
6902 for (i
= 0; i
< ARRAY_SIZE(formats
); i
++)
6904 hr
= IDirect3D8_CheckDeviceFormat(d3d8
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
6905 0, D3DRTYPE_VOLUMETEXTURE
, formats
[i
].fmt
);
6906 support
= SUCCEEDED(hr
);
6908 /* Test creation restrictions */
6909 for (w
= 1; w
<= 8; w
++)
6911 for (h
= 1; h
<= 8; h
++)
6913 for (d
= 1; d
<= 8; d
++)
6917 BOOL block_aligned
= TRUE
;
6919 if (w
& (formats
[i
].block_width
- 1) || h
& (formats
[i
].block_height
- 1))
6920 block_aligned
= FALSE
;
6922 size_is_pow2
= !((w
& (w
- 1)) || (h
& (h
- 1)) || (d
& (d
- 1)));
6924 for (j
= 0; j
< ARRAY_SIZE(create_tests
); j
++)
6926 BOOL may_succeed
= FALSE
;
6928 if (create_tests
[j
].need_runtime_support
&& !formats
[i
].core_fmt
&& !support
)
6929 expect_hr
= D3DERR_INVALIDCALL
;
6930 else if (formats
[i
].create_size_checked
&& !block_aligned
)
6931 expect_hr
= D3DERR_INVALIDCALL
;
6932 else if (pow2
&& !size_is_pow2
&& create_tests
[j
].need_driver_support
)
6933 expect_hr
= D3DERR_INVALIDCALL
;
6934 else if (create_tests
[j
].need_driver_support
&& !support
)
6935 expect_hr
= D3DERR_INVALIDCALL
;
6939 texture
= (IDirect3DVolumeTexture8
*)0xdeadbeef;
6940 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, w
, h
, d
, 1, 0,
6941 formats
[i
].fmt
, create_tests
[j
].pool
, &texture
);
6943 /* Wine knows about ATI2N and happily creates a scratch resource even if GL
6944 * does not support it. Accept scratch creation of extension formats on
6945 * Windows as well if it occurs. We don't really care if e.g. a Windows 7
6946 * on an r200 GPU creates scratch ATI2N texture even though the card doesn't
6948 if (!formats
[i
].core_fmt
&& !support
&& FAILED(expect_hr
))
6951 ok(hr
== expect_hr
|| ((SUCCEEDED(hr
) && may_succeed
)),
6952 "Got unexpected hr %#x for format %s, pool %s, size %ux%ux%u.\n",
6953 hr
, formats
[i
].name
, create_tests
[j
].name
, w
, h
, d
);
6956 ok(texture
== NULL
, "Got texture ptr %p, expected NULL.\n", texture
);
6958 IDirect3DVolumeTexture8_Release(texture
);
6964 if (!support
&& !formats
[i
].core_fmt
)
6967 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 24, 8, 8, 1, 0,
6968 formats
[i
].fmt
, D3DPOOL_SCRATCH
, &texture
);
6969 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x.\n", hr
);
6971 /* Test lockrect offset */
6972 for (j
= 0; j
< ARRAY_SIZE(offset_tests
); j
++)
6974 unsigned int bytes_per_pixel
;
6975 bytes_per_pixel
= formats
[i
].block_size
/ (formats
[i
].block_width
* formats
[i
].block_height
);
6977 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, NULL
, 0);
6978 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
6980 base
= locked_box
.pBits
;
6981 if (formats
[i
].broken
== 1)
6983 expected_row_pitch
= bytes_per_pixel
* 24;
6985 else if (formats
[i
].broken
== 2)
6987 expected_row_pitch
= 24;
6991 expected_row_pitch
= (24 /* tex width */ + formats
[i
].block_height
- 1) / formats
[i
].block_width
6992 * formats
[i
].block_size
;
6994 ok(locked_box
.RowPitch
== expected_row_pitch
, "Got unexpected row pitch %d for format %s, expected %d.\n",
6995 locked_box
.RowPitch
, formats
[i
].name
, expected_row_pitch
);
6997 if (formats
[i
].broken
)
6999 expected_slice_pitch
= expected_row_pitch
* 8;
7003 expected_slice_pitch
= (8 /* tex height */ + formats
[i
].block_depth
- 1) / formats
[i
].block_height
7004 * expected_row_pitch
;
7006 ok(locked_box
.SlicePitch
== expected_slice_pitch
,
7007 "Got unexpected slice pitch %d for format %s, expected %d.\n",
7008 locked_box
.SlicePitch
, formats
[i
].name
, expected_slice_pitch
);
7010 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
7011 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x, j %u.\n", hr
, j
);
7013 box
.Left
= offset_tests
[j
].x
;
7014 box
.Top
= offset_tests
[j
].y
;
7015 box
.Front
= offset_tests
[j
].z
;
7016 box
.Right
= offset_tests
[j
].x2
;
7017 box
.Bottom
= offset_tests
[j
].y2
;
7018 box
.Back
= offset_tests
[j
].z2
;
7019 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, &box
, 0);
7020 ok(SUCCEEDED(hr
), "Failed to lock volume texture, hr %#x, j %u.\n", hr
, j
);
7022 offset
= (BYTE
*)locked_box
.pBits
- base
;
7023 if (formats
[i
].broken
== 1)
7025 expected_offset
= box
.Front
* expected_slice_pitch
7026 + box
.Top
* expected_row_pitch
7027 + box
.Left
* bytes_per_pixel
;
7029 else if (formats
[i
].broken
== 2)
7031 expected_offset
= box
.Front
* expected_slice_pitch
7032 + box
.Top
* expected_row_pitch
7037 expected_offset
= (box
.Front
/ formats
[i
].block_depth
) * expected_slice_pitch
7038 + (box
.Top
/ formats
[i
].block_height
) * expected_row_pitch
7039 + (box
.Left
/ formats
[i
].block_width
) * formats
[i
].block_size
;
7041 ok(offset
== expected_offset
, "Got unexpected offset %u for format %s, expected %u, box start %ux%ux%u.\n",
7042 offset
, formats
[i
].name
, expected_offset
, box
.Left
, box
.Top
, box
.Front
);
7044 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
7045 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
7048 /* Test partial block locks */
7051 if (formats
[i
].block_width
> 1)
7053 box
.Left
= formats
[i
].block_width
>> 1;
7055 box
.Right
= formats
[i
].block_width
;
7056 box
.Bottom
= formats
[i
].block_height
;
7057 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, &box
, 0);
7058 ok(FAILED(hr
) || broken(formats
[i
].broken
),
7059 "Partial block lock succeeded, expected failure, format %s.\n",
7063 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
7064 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
7069 box
.Right
= formats
[i
].block_width
>> 1;
7070 box
.Bottom
= formats
[i
].block_height
;
7071 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, &box
, 0);
7072 ok(FAILED(hr
) || broken(formats
[i
].broken
),
7073 "Partial block lock succeeded, expected failure, format %s.\n",
7077 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
7078 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
7082 if (formats
[i
].block_height
> 1)
7085 box
.Top
= formats
[i
].block_height
>> 1;
7086 box
.Right
= formats
[i
].block_width
;
7087 box
.Bottom
= formats
[i
].block_height
;
7088 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, &box
, 0);
7089 ok(FAILED(hr
) || broken(formats
[i
].broken
),
7090 "Partial block lock succeeded, expected failure, format %s.\n",
7094 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
7095 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
7100 box
.Right
= formats
[i
].block_width
;
7101 box
.Bottom
= formats
[i
].block_height
>> 1;
7102 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, &box
, 0);
7103 ok(FAILED(hr
) || broken(formats
[i
].broken
),
7104 "Partial block lock succeeded, expected failure, format %s.\n",
7108 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
7109 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
7113 /* Test full block lock */
7116 box
.Right
= formats
[i
].block_width
;
7117 box
.Bottom
= formats
[i
].block_height
;
7118 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, &box
, 0);
7119 ok(SUCCEEDED(hr
), "Failed to lock volume texture, hr %#x.\n", hr
);
7120 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
7121 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
7123 IDirect3DVolumeTexture8_Release(texture
);
7125 /* Test mipmap locks. Don't do this with ATI2N, AMD warns that the runtime
7126 * does not allocate surfaces smaller than the blocksize properly. */
7127 if ((formats
[i
].block_width
> 1 || formats
[i
].block_height
> 1) && formats
[i
].core_fmt
)
7129 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, formats
[i
].block_width
, formats
[i
].block_height
,
7130 2, 2, 0, formats
[i
].fmt
, D3DPOOL_SCRATCH
, &texture
);
7132 ok(SUCCEEDED(hr
), "CreateVolumeTexture failed, hr %#x.\n", hr
);
7133 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 1, &locked_box
, NULL
, 0);
7134 ok(SUCCEEDED(hr
), "Failed to lock volume texture mipmap, hr %#x.\n", hr
);
7135 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 1);
7136 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
7138 box
.Left
= box
.Top
= box
.Front
= 0;
7139 box
.Right
= formats
[i
].block_width
== 1 ? 1 : formats
[i
].block_width
>> 1;
7140 box
.Bottom
= formats
[i
].block_height
== 1 ? 1 : formats
[i
].block_height
>> 1;
7142 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 1, &locked_box
, &box
, 0);
7143 ok(SUCCEEDED(hr
), "Failed to lock volume texture mipmap, hr %#x.\n", hr
);
7144 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 1);
7145 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
7147 box
.Right
= formats
[i
].block_width
;
7148 box
.Bottom
= formats
[i
].block_height
;
7149 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 1, &locked_box
, &box
, 0);
7150 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
7152 IDirect3DVolumeTexture8_UnlockBox(texture
, 1);
7154 IDirect3DVolumeTexture8_Release(texture
);
7158 refcount
= IDirect3DDevice8_Release(device
);
7159 ok(!refcount
, "Device has %u references left.\n", refcount
);
7160 IDirect3D8_Release(d3d8
);
7161 DestroyWindow(window
);
7164 static void test_lockbox_invalid(void)
7173 {{0, 0, 2, 2, 0, 1}, D3D_OK
}, /* Valid */
7174 {{0, 0, 4, 4, 0, 1}, D3D_OK
}, /* Valid */
7175 {{0, 0, 0, 4, 0, 1}, D3DERR_INVALIDCALL
}, /* 0 height */
7176 {{0, 0, 4, 0, 0, 1}, D3DERR_INVALIDCALL
}, /* 0 width */
7177 {{0, 0, 4, 4, 1, 1}, D3DERR_INVALIDCALL
}, /* 0 depth */
7178 {{4, 0, 0, 4, 0, 1}, D3DERR_INVALIDCALL
}, /* left > right */
7179 {{0, 4, 4, 0, 0, 1}, D3DERR_INVALIDCALL
}, /* top > bottom */
7180 {{0, 0, 4, 4, 1, 0}, D3DERR_INVALIDCALL
}, /* back > front */
7181 {{0, 0, 8, 4, 0, 1}, D3DERR_INVALIDCALL
}, /* right > surface */
7182 {{0, 0, 4, 8, 0, 1}, D3DERR_INVALIDCALL
}, /* bottom > surface */
7183 {{0, 0, 4, 4, 0, 3}, D3DERR_INVALIDCALL
}, /* back > surface */
7184 {{8, 0, 16, 4, 0, 1}, D3DERR_INVALIDCALL
}, /* left > surface */
7185 {{0, 8, 4, 16, 0, 1}, D3DERR_INVALIDCALL
}, /* top > surface */
7186 {{0, 0, 4, 4, 2, 4}, D3DERR_INVALIDCALL
}, /* top > surface */
7188 static const D3DBOX test_boxt_2
= {2, 2, 4, 4, 0, 1};
7189 IDirect3DVolumeTexture8
*texture
= NULL
;
7190 D3DLOCKED_BOX locked_box
;
7191 IDirect3DDevice8
*device
;
7199 window
= create_window();
7200 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
7201 ok(!!d3d
, "Failed to create a D3D object.\n");
7202 if (!(device
= create_device(d3d
, window
, NULL
)))
7204 skip("Failed to create a D3D device, skipping tests.\n");
7205 IDirect3D8_Release(d3d
);
7206 DestroyWindow(window
);
7210 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 4, 4, 2, 1, 0,
7211 D3DFMT_A8R8G8B8
, D3DPOOL_SCRATCH
, &texture
);
7212 ok(SUCCEEDED(hr
), "Failed to create volume texture, hr %#x.\n", hr
);
7213 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, NULL
, 0);
7214 ok(SUCCEEDED(hr
), "Failed to lock volume texture, hr %#x.\n", hr
);
7215 base
= locked_box
.pBits
;
7216 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
7217 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
7219 for (i
= 0; i
< ARRAY_SIZE(test_data
); ++i
)
7221 unsigned int offset
, expected_offset
;
7222 const D3DBOX
*box
= &test_data
[i
].box
;
7224 locked_box
.pBits
= (BYTE
*)0xdeadbeef;
7225 locked_box
.RowPitch
= 0xdeadbeef;
7226 locked_box
.SlicePitch
= 0xdeadbeef;
7228 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, box
, 0);
7229 /* Unlike surfaces, volumes properly check the box even in Windows XP */
7230 ok(hr
== test_data
[i
].result
,
7231 "Got unexpected hr %#x with box [%u, %u, %u]->[%u, %u, %u], expected %#x.\n",
7232 hr
, box
->Left
, box
->Top
, box
->Front
, box
->Right
, box
->Bottom
, box
->Back
,
7233 test_data
[i
].result
);
7237 offset
= (BYTE
*)locked_box
.pBits
- base
;
7238 expected_offset
= box
->Front
* locked_box
.SlicePitch
+ box
->Top
* locked_box
.RowPitch
+ box
->Left
* 4;
7239 ok(offset
== expected_offset
,
7240 "Got unexpected offset %u (expected %u) for rect [%u, %u, %u]->[%u, %u, %u].\n",
7241 offset
, expected_offset
, box
->Left
, box
->Top
, box
->Front
, box
->Right
, box
->Bottom
, box
->Back
);
7243 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
7244 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
7247 /* locked_box = NULL throws an exception on Windows */
7248 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, NULL
, 0);
7249 ok(SUCCEEDED(hr
), "Failed to lock volume texture, hr %#x.\n", hr
);
7250 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, NULL
, 0);
7251 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
7252 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
7253 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
7254 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
7255 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
7257 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, &test_data
[0].box
, 0);
7258 ok(hr
== D3D_OK
, "Got unexpected hr %#x for rect [%u, %u, %u]->[%u, %u, %u].\n",
7259 hr
, test_data
[0].box
.Left
, test_data
[0].box
.Top
, test_data
[0].box
.Front
,
7260 test_data
[0].box
.Right
, test_data
[0].box
.Bottom
, test_data
[0].box
.Back
);
7261 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, &test_data
[0].box
, 0);
7262 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for rect [%u, %u, %u]->[%u, %u, %u].\n",
7263 hr
, test_data
[0].box
.Left
, test_data
[0].box
.Top
, test_data
[0].box
.Front
,
7264 test_data
[0].box
.Right
, test_data
[0].box
.Bottom
, test_data
[0].box
.Back
);
7265 hr
= IDirect3DVolumeTexture8_LockBox(texture
, 0, &locked_box
, &test_boxt_2
, 0);
7266 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x for rect [%u, %u, %u]->[%u, %u, %u].\n",
7267 hr
, test_boxt_2
.Left
, test_boxt_2
.Top
, test_boxt_2
.Front
,
7268 test_boxt_2
.Right
, test_boxt_2
.Bottom
, test_boxt_2
.Back
);
7269 hr
= IDirect3DVolumeTexture8_UnlockBox(texture
, 0);
7270 ok(SUCCEEDED(hr
), "Failed to unlock volume texture, hr %#x.\n", hr
);
7272 IDirect3DVolumeTexture8_Release(texture
);
7274 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 4, 4, 2, 1, D3DUSAGE_WRITEONLY
,
7275 D3DFMT_A8R8G8B8
, D3DPOOL_SCRATCH
, &texture
);
7276 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
7278 refcount
= IDirect3DDevice8_Release(device
);
7279 ok(!refcount
, "Device has %u references left.\n", refcount
);
7280 IDirect3D8_Release(d3d
);
7281 DestroyWindow(window
);
7284 static void test_pixel_format(void)
7286 int format
, test_format
;
7287 PIXELFORMATDESCRIPTOR pfd
;
7288 IDirect3D8
*d3d8
= NULL
;
7289 IDirect3DDevice8
*device
= NULL
;
7295 static const float point
[] = {0.0f
, 0.0f
, 0.0f
};
7297 hwnd
= create_window();
7298 ok(!!hwnd
, "Failed to create window.\n");
7299 hwnd2
= create_window();
7300 ok(!!hwnd2
, "Failed to create window.\n");
7303 ok(!!hdc
, "Failed to get DC.\n");
7304 hdc2
= GetDC(hwnd2
);
7305 ok(!!hdc2
, "Failed to get DC.\n");
7307 gl
= LoadLibraryA("opengl32.dll");
7308 ok(!!gl
, "failed to load opengl32.dll; SetPixelFormat()/GetPixelFormat() may not work right\n");
7310 format
= GetPixelFormat(hdc
);
7311 ok(format
== 0, "new window has pixel format %d\n", format
);
7313 ZeroMemory(&pfd
, sizeof(pfd
));
7314 pfd
.nSize
= sizeof(pfd
);
7316 pfd
.dwFlags
= PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
;
7317 pfd
.iPixelType
= PFD_TYPE_RGBA
;
7318 pfd
.iLayerType
= PFD_MAIN_PLANE
;
7319 format
= ChoosePixelFormat(hdc
, &pfd
);
7322 skip("no pixel format available\n");
7326 if (!SetPixelFormat(hdc
, format
, &pfd
) || GetPixelFormat(hdc
) != format
)
7328 skip("failed to set pixel format\n");
7332 if (!SetPixelFormat(hdc2
, format
, &pfd
) || GetPixelFormat(hdc2
) != format
)
7334 skip("failed to set pixel format on second window\n");
7338 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
7339 ok(!!d3d8
, "Failed to create a D3D object.\n");
7341 test_format
= GetPixelFormat(hdc
);
7342 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7344 if (!(device
= create_device(d3d8
, hwnd
, NULL
)))
7346 skip("Failed to create device\n");
7350 test_format
= GetPixelFormat(hdc
);
7351 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7353 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
);
7354 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
7356 test_format
= GetPixelFormat(hdc
);
7357 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7359 hr
= IDirect3DDevice8_BeginScene(device
);
7360 ok(SUCCEEDED(hr
), "BeginScene failed %#x\n", hr
);
7362 test_format
= GetPixelFormat(hdc
);
7363 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7365 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_POINTLIST
, 1, point
, 3 * sizeof(float));
7366 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7368 test_format
= GetPixelFormat(hdc
);
7369 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7371 hr
= IDirect3DDevice8_EndScene(device
);
7372 ok(SUCCEEDED(hr
), "EndScene failed %#x\n", hr
);
7374 test_format
= GetPixelFormat(hdc
);
7375 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7377 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
7378 ok(SUCCEEDED(hr
), "Present failed %#x\n", hr
);
7380 test_format
= GetPixelFormat(hdc
);
7381 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7383 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, hwnd2
, NULL
);
7384 ok(SUCCEEDED(hr
), "Present failed %#x\n", hr
);
7386 test_format
= GetPixelFormat(hdc
);
7387 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
7389 test_format
= GetPixelFormat(hdc2
);
7390 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
7395 UINT refcount
= IDirect3DDevice8_Release(device
);
7396 ok(!refcount
, "Device has %u references left.\n", refcount
);
7399 IDirect3D8_Release(d3d8
);
7401 ReleaseDC(hwnd2
, hdc2
);
7402 ReleaseDC(hwnd
, hdc
);
7403 DestroyWindow(hwnd2
);
7404 DestroyWindow(hwnd
);
7407 static void test_begin_end_state_block(void)
7409 DWORD stateblock
, stateblock2
;
7410 IDirect3DDevice8
*device
;
7417 window
= create_window();
7418 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
7419 ok(!!d3d
, "Failed to create a D3D object.\n");
7420 if (!(device
= create_device(d3d
, window
, NULL
)))
7422 skip("Failed to create a D3D device, skipping tests.\n");
7423 IDirect3D8_Release(d3d
);
7424 DestroyWindow(window
);
7428 hr
= IDirect3DDevice8_BeginStateBlock(device
);
7429 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7431 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
7432 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7434 stateblock
= 0xdeadbeef;
7435 hr
= IDirect3DDevice8_EndStateBlock(device
, &stateblock
);
7436 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7437 ok(!!stateblock
&& stateblock
!= 0xdeadbeef, "Got unexpected stateblock %#x.\n", stateblock
);
7439 stateblock2
= 0xdeadbeef;
7440 hr
= IDirect3DDevice8_EndStateBlock(device
, &stateblock2
);
7441 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
7442 ok(stateblock2
== 0xdeadbeef, "Got unexpected stateblock %#x.\n", stateblock2
);
7444 hr
= IDirect3DDevice8_GetRenderState(device
, D3DRS_LIGHTING
, &value
);
7445 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7446 ok(value
== TRUE
, "Got unexpected value %#x.\n", value
);
7448 hr
= IDirect3DDevice8_BeginStateBlock(device
);
7449 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7451 hr
= IDirect3DDevice8_BeginStateBlock(device
);
7452 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
7454 hr
= IDirect3DDevice8_ApplyStateBlock(device
, stateblock
);
7455 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
7457 hr
= IDirect3DDevice8_CaptureStateBlock(device
, stateblock
);
7458 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
7460 hr
= IDirect3DDevice8_CreateStateBlock(device
, D3DSBT_ALL
, &stateblock2
);
7461 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
7463 hr
= IDirect3DDevice8_GetRenderState(device
, D3DRS_LIGHTING
, &value
);
7464 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7465 ok(value
== TRUE
, "Got unexpected value %#x.\n", value
);
7467 hr
= IDirect3DDevice8_EndStateBlock(device
, &stateblock2
);
7468 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7470 hr
= IDirect3DDevice8_ApplyStateBlock(device
, stateblock2
);
7471 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7473 hr
= IDirect3DDevice8_GetRenderState(device
, D3DRS_LIGHTING
, &value
);
7474 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7475 ok(value
== TRUE
, "Got unexpected value %#x.\n", value
);
7477 refcount
= IDirect3DDevice8_Release(device
);
7478 ok(!refcount
, "Device has %u references left.\n", refcount
);
7479 IDirect3D8_Release(d3d
);
7480 DestroyWindow(window
);
7483 static void test_shader_constant_apply(void)
7485 static const float vs_const
[] = {1.0f
, 2.0f
, 3.0f
, 4.0f
};
7486 static const float ps_const
[] = {5.0f
, 6.0f
, 7.0f
, 8.0f
};
7487 static const float initial
[] = {0.0f
, 0.0f
, 0.0f
, 0.0f
};
7488 DWORD vs_version
, ps_version
;
7489 IDirect3DDevice8
*device
;
7498 window
= create_window();
7499 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
7500 ok(!!d3d
, "Failed to create a D3D object.\n");
7501 if (!(device
= create_device(d3d
, window
, NULL
)))
7503 skip("Failed to create a D3D device, skipping tests.\n");
7504 IDirect3D8_Release(d3d
);
7505 DestroyWindow(window
);
7509 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
7510 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
7511 vs_version
= caps
.VertexShaderVersion
& 0xffff;
7512 ps_version
= caps
.PixelShaderVersion
& 0xffff;
7516 hr
= IDirect3DDevice8_SetVertexShaderConstant(device
, 0, initial
, 1);
7517 ok(SUCCEEDED(hr
), "Failed to set vertex shader constant, hr %#x.\n", hr
);
7518 hr
= IDirect3DDevice8_SetVertexShaderConstant(device
, 1, initial
, 1);
7519 ok(SUCCEEDED(hr
), "Failed to set vertex shader constant, hr %#x.\n", hr
);
7521 hr
= IDirect3DDevice8_GetVertexShaderConstant(device
, 0, ret
, 1);
7522 ok(SUCCEEDED(hr
), "Failed to get vertex shader constant, hr %#x.\n", hr
);
7523 ok(!memcmp(ret
, initial
, sizeof(initial
)),
7524 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7525 ret
[0], ret
[1], ret
[2], ret
[3], initial
[0], initial
[1], initial
[2], initial
[3]);
7526 hr
= IDirect3DDevice8_GetVertexShaderConstant(device
, 1, ret
, 1);
7527 ok(SUCCEEDED(hr
), "Failed to get vertex shader constant, hr %#x.\n", hr
);
7528 ok(!memcmp(ret
, initial
, sizeof(initial
)),
7529 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7530 ret
[0], ret
[1], ret
[2], ret
[3], initial
[0], initial
[1], initial
[2], initial
[3]);
7532 hr
= IDirect3DDevice8_SetVertexShaderConstant(device
, 0, vs_const
, 1);
7533 ok(SUCCEEDED(hr
), "Failed to set vertex shader constant, hr %#x.\n", hr
);
7537 hr
= IDirect3DDevice8_SetPixelShaderConstant(device
, 0, initial
, 1);
7538 ok(SUCCEEDED(hr
), "Failed to set pixel shader constant, hr %#x.\n", hr
);
7539 hr
= IDirect3DDevice8_SetPixelShaderConstant(device
, 1, initial
, 1);
7540 ok(SUCCEEDED(hr
), "Failed to set pixel shader constant, hr %#x.\n", hr
);
7542 hr
= IDirect3DDevice8_GetPixelShaderConstant(device
, 0, ret
, 1);
7543 ok(SUCCEEDED(hr
), "Failed to get pixel shader constant, hr %#x.\n", hr
);
7544 ok(!memcmp(ret
, initial
, sizeof(initial
)),
7545 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7546 ret
[0], ret
[1], ret
[2], ret
[3], initial
[0], initial
[1], initial
[2], initial
[3]);
7547 hr
= IDirect3DDevice8_GetPixelShaderConstant(device
, 1, ret
, 1);
7548 ok(SUCCEEDED(hr
), "Failed to get pixel shader constant, hr %#x.\n", hr
);
7549 ok(!memcmp(ret
, initial
, sizeof(initial
)),
7550 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7551 ret
[0], ret
[1], ret
[2], ret
[3], initial
[0], initial
[1], initial
[2], initial
[3]);
7553 hr
= IDirect3DDevice8_SetPixelShaderConstant(device
, 0, ps_const
, 1);
7554 ok(SUCCEEDED(hr
), "Failed to set pixel shader constant, hr %#x.\n", hr
);
7557 hr
= IDirect3DDevice8_BeginStateBlock(device
);
7558 ok(SUCCEEDED(hr
), "Failed to begin stateblock, hr %#x.\n", hr
);
7562 hr
= IDirect3DDevice8_SetVertexShaderConstant(device
, 1, vs_const
, 1);
7563 ok(SUCCEEDED(hr
), "Failed to set vertex shader constant, hr %#x.\n", hr
);
7567 hr
= IDirect3DDevice8_SetPixelShaderConstant(device
, 1, ps_const
, 1);
7568 ok(SUCCEEDED(hr
), "Failed to set pixel shader constant, hr %#x.\n", hr
);
7571 hr
= IDirect3DDevice8_EndStateBlock(device
, &stateblock
);
7572 ok(SUCCEEDED(hr
), "Failed to end stateblock, hr %#x.\n", hr
);
7576 hr
= IDirect3DDevice8_GetVertexShaderConstant(device
, 0, ret
, 1);
7577 ok(SUCCEEDED(hr
), "Failed to get vertex shader constant, hr %#x.\n", hr
);
7578 ok(!memcmp(ret
, vs_const
, sizeof(vs_const
)),
7579 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7580 ret
[0], ret
[1], ret
[2], ret
[3], vs_const
[0], vs_const
[1], vs_const
[2], vs_const
[3]);
7581 hr
= IDirect3DDevice8_GetVertexShaderConstant(device
, 1, ret
, 1);
7582 ok(SUCCEEDED(hr
), "Failed to get vertex shader constant, hr %#x.\n", hr
);
7583 ok(!memcmp(ret
, initial
, sizeof(initial
)),
7584 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7585 ret
[0], ret
[1], ret
[2], ret
[3], initial
[0], initial
[1], initial
[2], initial
[3]);
7589 hr
= IDirect3DDevice8_GetPixelShaderConstant(device
, 0, ret
, 1);
7590 ok(SUCCEEDED(hr
), "Failed to get pixel shader constant, hr %#x.\n", hr
);
7591 ok(!memcmp(ret
, ps_const
, sizeof(ps_const
)),
7592 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7593 ret
[0], ret
[1], ret
[2], ret
[3], ps_const
[0], ps_const
[1], ps_const
[2], ps_const
[3]);
7594 hr
= IDirect3DDevice8_GetPixelShaderConstant(device
, 1, ret
, 1);
7595 ok(SUCCEEDED(hr
), "Failed to get pixel shader constant, hr %#x.\n", hr
);
7596 ok(!memcmp(ret
, initial
, sizeof(initial
)),
7597 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7598 ret
[0], ret
[1], ret
[2], ret
[3], initial
[0], initial
[1], initial
[2], initial
[3]);
7601 /* Apply doesn't overwrite constants that aren't explicitly set on the
7602 * source stateblock. */
7603 hr
= IDirect3DDevice8_ApplyStateBlock(device
, stateblock
);
7604 ok(SUCCEEDED(hr
), "Failed to apply stateblock, hr %#x.\n", hr
);
7608 hr
= IDirect3DDevice8_GetVertexShaderConstant(device
, 0, ret
, 1);
7609 ok(SUCCEEDED(hr
), "Failed to get vertex shader constant, hr %#x.\n", hr
);
7610 ok(!memcmp(ret
, vs_const
, sizeof(vs_const
)),
7611 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7612 ret
[0], ret
[1], ret
[2], ret
[3], vs_const
[0], vs_const
[1], vs_const
[2], vs_const
[3]);
7613 hr
= IDirect3DDevice8_GetVertexShaderConstant(device
, 1, ret
, 1);
7614 ok(SUCCEEDED(hr
), "Failed to get vertex shader constant, hr %#x.\n", hr
);
7615 ok(!memcmp(ret
, vs_const
, sizeof(vs_const
)),
7616 "Got unexpected vertex shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7617 ret
[0], ret
[1], ret
[2], ret
[3], vs_const
[0], vs_const
[1], vs_const
[2], vs_const
[3]);
7621 hr
= IDirect3DDevice8_GetPixelShaderConstant(device
, 0, ret
, 1);
7622 ok(SUCCEEDED(hr
), "Failed to get pixel shader constant, hr %#x.\n", hr
);
7623 ok(!memcmp(ret
, ps_const
, sizeof(ps_const
)),
7624 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7625 ret
[0], ret
[1], ret
[2], ret
[3], ps_const
[0], ps_const
[1], ps_const
[2], ps_const
[3]);
7626 hr
= IDirect3DDevice8_GetPixelShaderConstant(device
, 1, ret
, 1);
7627 ok(SUCCEEDED(hr
), "Failed to get pixel shader constant, hr %#x.\n", hr
);
7628 ok(!memcmp(ret
, ps_const
, sizeof(ps_const
)),
7629 "Got unexpected pixel shader constant {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
7630 ret
[0], ret
[1], ret
[2], ret
[3], ps_const
[0], ps_const
[1], ps_const
[2], ps_const
[3]);
7633 IDirect3DDevice8_DeleteStateBlock(device
, stateblock
);
7634 refcount
= IDirect3DDevice8_Release(device
);
7635 ok(!refcount
, "Device has %u references left.\n", refcount
);
7636 IDirect3D8_Release(d3d
);
7637 DestroyWindow(window
);
7640 static void test_resource_type(void)
7642 IDirect3DDevice8
*device
;
7643 IDirect3DSurface8
*surface
;
7644 IDirect3DTexture8
*texture
;
7645 IDirect3DCubeTexture8
*cube_texture
;
7646 IDirect3DVolume8
*volume
;
7647 IDirect3DVolumeTexture8
*volume_texture
;
7648 D3DSURFACE_DESC surface_desc
;
7649 D3DVOLUME_DESC volume_desc
;
7650 D3DRESOURCETYPE type
;
7657 window
= create_window();
7658 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
7659 ok(!!d3d
, "Failed to create a D3D object.\n");
7660 if (!(device
= create_device(d3d
, window
, NULL
)))
7662 skip("Failed to create a D3D device, skipping tests.\n");
7663 IDirect3D8_Release(d3d
);
7664 DestroyWindow(window
);
7668 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
7669 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
7671 hr
= IDirect3DDevice8_CreateImageSurface(device
, 4, 4, D3DFMT_X8R8G8B8
, &surface
);
7672 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7673 hr
= IDirect3DSurface8_GetDesc(surface
, &surface_desc
);
7674 ok(SUCCEEDED(hr
), "Failed to get surface description, hr %#x.\n", hr
);
7675 ok(surface_desc
.Type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7677 IDirect3DSurface8_Release(surface
);
7679 hr
= IDirect3DDevice8_CreateTexture(device
, 2, 8, 4, 0, D3DFMT_X8R8G8B8
,
7680 D3DPOOL_SYSTEMMEM
, &texture
);
7681 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
7682 type
= IDirect3DTexture8_GetType(texture
);
7683 ok(type
== D3DRTYPE_TEXTURE
, "Expected type D3DRTYPE_TEXTURE, got %u.\n", type
);
7685 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 0, &surface
);
7686 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
7687 hr
= IDirect3DSurface8_GetDesc(surface
, &surface_desc
);
7688 ok(SUCCEEDED(hr
), "Failed to get surface description, hr %#x.\n", hr
);
7689 ok(surface_desc
.Type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7691 ok(surface_desc
.Width
== 2, "Expected width 2, got %u.\n", surface_desc
.Width
);
7692 ok(surface_desc
.Height
== 8, "Expected height 8, got %u.\n", surface_desc
.Height
);
7693 hr
= IDirect3DTexture8_GetLevelDesc(texture
, 0, &surface_desc
);
7694 ok(SUCCEEDED(hr
), "Failed to get level description, hr %#x.\n", hr
);
7695 ok(surface_desc
.Type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7697 ok(surface_desc
.Width
== 2, "Expected width 2, got %u.\n", surface_desc
.Width
);
7698 ok(surface_desc
.Height
== 8, "Expected height 8, got %u.\n", surface_desc
.Height
);
7699 IDirect3DSurface8_Release(surface
);
7701 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 2, &surface
);
7702 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
7703 hr
= IDirect3DSurface8_GetDesc(surface
, &surface_desc
);
7704 ok(SUCCEEDED(hr
), "Failed to get surface description, hr %#x.\n", hr
);
7705 ok(surface_desc
.Type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7707 ok(surface_desc
.Width
== 1, "Expected width 1, got %u.\n", surface_desc
.Width
);
7708 ok(surface_desc
.Height
== 2, "Expected height 2, got %u.\n", surface_desc
.Height
);
7709 hr
= IDirect3DTexture8_GetLevelDesc(texture
, 2, &surface_desc
);
7710 ok(SUCCEEDED(hr
), "Failed to get level description, hr %#x.\n", hr
);
7711 ok(surface_desc
.Type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7713 ok(surface_desc
.Width
== 1, "Expected width 1, got %u.\n", surface_desc
.Width
);
7714 ok(surface_desc
.Height
== 2, "Expected height 2, got %u.\n", surface_desc
.Height
);
7715 IDirect3DSurface8_Release(surface
);
7716 IDirect3DTexture8_Release(texture
);
7718 if (caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP
)
7720 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 1, 1, 0, D3DFMT_X8R8G8B8
,
7721 D3DPOOL_SYSTEMMEM
, &cube_texture
);
7722 ok(SUCCEEDED(hr
), "Failed to create cube texture, hr %#x.\n", hr
);
7723 type
= IDirect3DCubeTexture8_GetType(cube_texture
);
7724 ok(type
== D3DRTYPE_CUBETEXTURE
, "Expected type D3DRTYPE_CUBETEXTURE, got %u.\n", type
);
7726 hr
= IDirect3DCubeTexture8_GetCubeMapSurface(cube_texture
,
7727 D3DCUBEMAP_FACE_NEGATIVE_X
, 0, &surface
);
7728 ok(SUCCEEDED(hr
), "Failed to get cube map surface, hr %#x.\n", hr
);
7729 hr
= IDirect3DSurface8_GetDesc(surface
, &surface_desc
);
7730 ok(SUCCEEDED(hr
), "Failed to get surface description, hr %#x.\n", hr
);
7731 ok(surface_desc
.Type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7733 hr
= IDirect3DCubeTexture8_GetLevelDesc(cube_texture
, 0, &surface_desc
);
7734 ok(SUCCEEDED(hr
), "Failed to get level description, hr %#x.\n", hr
);
7735 ok(surface_desc
.Type
== D3DRTYPE_SURFACE
, "Expected type D3DRTYPE_SURFACE, got %u.\n",
7737 IDirect3DSurface8_Release(surface
);
7738 IDirect3DCubeTexture8_Release(cube_texture
);
7741 skip("Cube maps not supported.\n");
7743 if (caps
.TextureCaps
& D3DPTEXTURECAPS_MIPVOLUMEMAP
)
7745 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 2, 4, 8, 4, 0, D3DFMT_X8R8G8B8
,
7746 D3DPOOL_SYSTEMMEM
, &volume_texture
);
7747 ok(SUCCEEDED(hr
), "CreateVolumeTexture failed, hr %#x.\n", hr
);
7748 type
= IDirect3DVolumeTexture8_GetType(volume_texture
);
7749 ok(type
== D3DRTYPE_VOLUMETEXTURE
, "Expected type D3DRTYPE_VOLUMETEXTURE, got %u.\n", type
);
7751 hr
= IDirect3DVolumeTexture8_GetVolumeLevel(volume_texture
, 0, &volume
);
7752 ok(SUCCEEDED(hr
), "Failed to get volume level, hr %#x.\n", hr
);
7753 /* IDirect3DVolume8 is not an IDirect3DResource8 and has no GetType method. */
7754 hr
= IDirect3DVolume8_GetDesc(volume
, &volume_desc
);
7755 ok(SUCCEEDED(hr
), "Failed to get volume description, hr %#x.\n", hr
);
7756 ok(volume_desc
.Type
== D3DRTYPE_VOLUME
, "Expected type D3DRTYPE_VOLUME, got %u.\n",
7758 ok(volume_desc
.Width
== 2, "Expected width 2, got %u.\n", volume_desc
.Width
);
7759 ok(volume_desc
.Height
== 4, "Expected height 4, got %u.\n", volume_desc
.Height
);
7760 ok(volume_desc
.Depth
== 8, "Expected depth 8, got %u.\n", volume_desc
.Depth
);
7761 hr
= IDirect3DVolumeTexture8_GetLevelDesc(volume_texture
, 0, &volume_desc
);
7762 ok(SUCCEEDED(hr
), "Failed to get level description, hr %#x.\n", hr
);
7763 ok(volume_desc
.Type
== D3DRTYPE_VOLUME
, "Expected type D3DRTYPE_VOLUME, got %u.\n",
7765 ok(volume_desc
.Width
== 2, "Expected width 2, got %u.\n", volume_desc
.Width
);
7766 ok(volume_desc
.Height
== 4, "Expected height 4, got %u.\n", volume_desc
.Height
);
7767 ok(volume_desc
.Depth
== 8, "Expected depth 8, got %u.\n", volume_desc
.Depth
);
7768 IDirect3DVolume8_Release(volume
);
7770 hr
= IDirect3DVolumeTexture8_GetVolumeLevel(volume_texture
, 2, &volume
);
7771 ok(SUCCEEDED(hr
), "Failed to get volume level, hr %#x.\n", hr
);
7772 hr
= IDirect3DVolume8_GetDesc(volume
, &volume_desc
);
7773 ok(SUCCEEDED(hr
), "Failed to get volume description, hr %#x.\n", hr
);
7774 ok(volume_desc
.Type
== D3DRTYPE_VOLUME
, "Expected type D3DRTYPE_VOLUME, got %u.\n",
7776 ok(volume_desc
.Width
== 1, "Expected width 1, got %u.\n", volume_desc
.Width
);
7777 ok(volume_desc
.Height
== 1, "Expected height 1, got %u.\n", volume_desc
.Height
);
7778 ok(volume_desc
.Depth
== 2, "Expected depth 2, got %u.\n", volume_desc
.Depth
);
7779 hr
= IDirect3DVolumeTexture8_GetLevelDesc(volume_texture
, 2, &volume_desc
);
7780 ok(SUCCEEDED(hr
), "Failed to get level description, hr %#x.\n", hr
);
7781 ok(volume_desc
.Type
== D3DRTYPE_VOLUME
, "Expected type D3DRTYPE_VOLUME, got %u.\n",
7783 ok(volume_desc
.Width
== 1, "Expected width 1, got %u.\n", volume_desc
.Width
);
7784 ok(volume_desc
.Height
== 1, "Expected height 1, got %u.\n", volume_desc
.Height
);
7785 ok(volume_desc
.Depth
== 2, "Expected depth 2, got %u.\n", volume_desc
.Depth
);
7786 IDirect3DVolume8_Release(volume
);
7787 IDirect3DVolumeTexture8_Release(volume_texture
);
7790 skip("Mipmapped volume maps not supported.\n");
7792 refcount
= IDirect3DDevice8_Release(device
);
7793 ok(!refcount
, "Device has %u references left.\n", refcount
);
7794 IDirect3D8_Release(d3d
);
7795 DestroyWindow(window
);
7798 static void test_mipmap_lock(void)
7800 IDirect3DDevice8
*device
;
7801 IDirect3DSurface8
*surface
, *surface2
, *surface_dst
, *surface_dst2
;
7802 IDirect3DTexture8
*texture
, *texture_dst
;
7807 D3DLOCKED_RECT locked_rect
;
7809 window
= create_window();
7810 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
7811 ok(!!d3d
, "Failed to create a D3D object.\n");
7812 if (!(device
= create_device(d3d
, window
, NULL
)))
7814 skip("Failed to create a D3D device, skipping tests.\n");
7815 IDirect3D8_Release(d3d
);
7816 DestroyWindow(window
);
7820 hr
= IDirect3DDevice8_CreateTexture(device
, 4, 4, 2, 0, D3DFMT_X8R8G8B8
,
7821 D3DPOOL_DEFAULT
, &texture_dst
);
7822 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
7823 hr
= IDirect3DTexture8_GetSurfaceLevel(texture_dst
, 0, &surface_dst
);
7824 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
7825 hr
= IDirect3DTexture8_GetSurfaceLevel(texture_dst
, 1, &surface_dst2
);
7826 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
7828 hr
= IDirect3DDevice8_CreateTexture(device
, 4, 4, 2, 0, D3DFMT_X8R8G8B8
,
7829 D3DPOOL_SYSTEMMEM
, &texture
);
7830 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x.\n", hr
);
7831 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 0, &surface
);
7832 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
7833 hr
= IDirect3DTexture8_GetSurfaceLevel(texture
, 1, &surface2
);
7834 ok(SUCCEEDED(hr
), "Failed to get surface level, hr %#x.\n", hr
);
7836 hr
= IDirect3DSurface8_LockRect(surface
, &locked_rect
, NULL
, 0);
7837 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
7838 hr
= IDirect3DSurface8_LockRect(surface2
, &locked_rect
, NULL
, 0);
7839 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
7840 hr
= IDirect3DSurface8_UnlockRect(surface
);
7841 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
7843 hr
= IDirect3DDevice8_CopyRects(device
, surface
, NULL
, 0, surface_dst
, NULL
);
7844 ok(SUCCEEDED(hr
), "Failed to update surface, hr %#x.\n", hr
);
7845 hr
= IDirect3DDevice8_CopyRects(device
, surface2
, NULL
, 0, surface_dst2
, NULL
);
7846 todo_wine
ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
7848 /* Apparently there's no validation on the container. */
7849 hr
= IDirect3DDevice8_UpdateTexture(device
, (IDirect3DBaseTexture8
*)texture
,
7850 (IDirect3DBaseTexture8
*)texture_dst
);
7851 ok(SUCCEEDED(hr
), "Failed to update texture, hr %#x.\n", hr
);
7853 hr
= IDirect3DSurface8_UnlockRect(surface2
);
7854 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
7856 IDirect3DSurface8_Release(surface_dst2
);
7857 IDirect3DSurface8_Release(surface_dst
);
7858 IDirect3DSurface8_Release(surface2
);
7859 IDirect3DSurface8_Release(surface
);
7860 IDirect3DTexture8_Release(texture_dst
);
7861 IDirect3DTexture8_Release(texture
);
7863 refcount
= IDirect3DDevice8_Release(device
);
7864 ok(!refcount
, "Device has %u references left.\n", refcount
);
7865 IDirect3D8_Release(d3d
);
7866 DestroyWindow(window
);
7869 static void test_writeonly_resource(void)
7872 IDirect3DDevice8
*device
;
7873 IDirect3DVertexBuffer8
*buffer
;
7884 {{-1.0f
, -1.0f
, 0.0f
}},
7885 {{-1.0f
, 1.0f
, 0.0f
}},
7886 {{ 1.0f
, -1.0f
, 0.0f
}},
7887 {{ 1.0f
, 1.0f
, 0.0f
}}
7890 window
= create_window();
7891 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
7892 ok(!!d3d
, "Failed to create a D3D object.\n");
7893 if (!(device
= create_device(d3d
, window
, NULL
)))
7895 skip("Failed to create a D3D device, skipping tests.\n");
7896 IDirect3D8_Release(d3d
);
7897 DestroyWindow(window
);
7901 hr
= IDirect3DDevice8_CreateVertexBuffer(device
, sizeof(quad
),
7902 D3DUSAGE_DYNAMIC
| D3DUSAGE_WRITEONLY
, 0, D3DPOOL_DEFAULT
, &buffer
);
7903 ok(SUCCEEDED(hr
), "Failed to create buffer, hr %#x.\n", hr
);
7905 hr
= IDirect3DVertexBuffer8_Lock(buffer
, 0, 0, &ptr
, D3DLOCK_DISCARD
);
7906 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
7907 memcpy(ptr
, quad
, sizeof(quad
));
7908 hr
= IDirect3DVertexBuffer8_Unlock(buffer
);
7909 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
7910 hr
= IDirect3DDevice8_SetStreamSource(device
, 0, buffer
, sizeof(*quad
));
7911 ok(SUCCEEDED(hr
), "Failed to set stream source, hr %#x.\n", hr
);
7912 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
);
7913 ok(SUCCEEDED(hr
), "Failed to set FVF, hr %#x.\n", hr
);
7915 hr
= IDirect3DDevice8_BeginScene(device
);
7916 ok(SUCCEEDED(hr
), "Failed to begin scene %#x\n", hr
);
7917 hr
= IDirect3DDevice8_DrawPrimitive(device
, D3DPT_TRIANGLESTRIP
, 0, 2);
7918 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7919 hr
= IDirect3DDevice8_EndScene(device
);
7920 ok(SUCCEEDED(hr
), "Failed to end scene %#x\n", hr
);
7922 hr
= IDirect3DVertexBuffer8_Lock(buffer
, 0, 0, &ptr
, 0);
7923 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
7924 ok (!memcmp(ptr
, quad
, sizeof(quad
)), "Got unexpected vertex buffer data.\n");
7925 hr
= IDirect3DVertexBuffer8_Unlock(buffer
);
7926 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
7928 hr
= IDirect3DVertexBuffer8_Lock(buffer
, 0, 0, &ptr
, D3DLOCK_READONLY
);
7929 ok(SUCCEEDED(hr
), "Failed to lock vertex buffer, hr %#x.\n", hr
);
7930 ok (!memcmp(ptr
, quad
, sizeof(quad
)), "Got unexpected vertex buffer data.\n");
7931 hr
= IDirect3DVertexBuffer8_Unlock(buffer
);
7932 ok(SUCCEEDED(hr
), "Failed to unlock vertex buffer, hr %#x.\n", hr
);
7934 refcount
= IDirect3DVertexBuffer8_Release(buffer
);
7935 ok(!refcount
, "Vertex buffer has %u references left.\n", refcount
);
7936 refcount
= IDirect3DDevice8_Release(device
);
7937 ok(!refcount
, "Device has %u references left.\n", refcount
);
7938 IDirect3D8_Release(d3d
);
7939 DestroyWindow(window
);
7942 static void test_lost_device(void)
7944 D3DADAPTER_IDENTIFIER8 identifier
;
7945 struct device_desc device_desc
;
7946 IDirect3DDevice8
*device
;
7953 window
= create_window();
7954 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
7955 ok(!!d3d
, "Failed to create a D3D object.\n");
7956 hr
= IDirect3D8_GetAdapterIdentifier(d3d
, D3DADAPTER_DEFAULT
, 0, &identifier
);
7957 ok(SUCCEEDED(hr
), "Failed to get adapter identifier, hr %#x.\n", hr
);
7958 device_desc
.adapter_ordinal
= D3DADAPTER_DEFAULT
;
7959 device_desc
.device_window
= window
;
7960 device_desc
.width
= registry_mode
.dmPelsWidth
;
7961 device_desc
.height
= registry_mode
.dmPelsHeight
;
7962 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
7963 if (!(device
= create_device(d3d
, window
, &device_desc
)))
7965 skip("Failed to create a D3D device, skipping tests.\n");
7969 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
7970 if (hr
== D3DERR_DEVICELOST
)
7972 win_skip("Broken TestCooperativeLevel(), skipping test.\n");
7973 IDirect3DDevice8_Release(device
);
7976 if (adapter_is_warp(&identifier
))
7978 win_skip("Windows 10 WARP crashes during this test.\n");
7979 IDirect3DDevice8_Release(device
);
7983 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7984 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
7985 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
7987 ret
= SetForegroundWindow(GetDesktopWindow());
7988 ok(ret
, "Failed to set foreground window.\n");
7989 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
7990 /* The device is not lost on Windows 10. */
7991 ok(hr
== D3DERR_DEVICELOST
|| broken(hr
== D3D_OK
), "Got unexpected hr %#x.\n", hr
);
7992 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
7993 ok(hr
== D3DERR_DEVICELOST
|| broken(hr
== D3D_OK
), "Got unexpected hr %#x.\n", hr
);
7995 ret
= ShowWindow(window
, SW_RESTORE
);
7996 ok(ret
, "Failed to restore window.\n");
7997 ret
= SetForegroundWindow(window
);
7998 ok(ret
, "Failed to set foreground window.\n");
7999 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
8000 ok(hr
== D3DERR_DEVICENOTRESET
|| broken(hr
== D3D_OK
), "Got unexpected hr %#x.\n", hr
);
8001 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
8002 ok(hr
== D3DERR_DEVICELOST
|| broken(hr
== D3D_OK
), "Got unexpected hr %#x.\n", hr
);
8004 hr
= reset_device(device
, &device_desc
);
8005 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
8006 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
8007 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
8008 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
8009 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
8011 device_desc
.flags
= 0;
8012 hr
= reset_device(device
, &device_desc
);
8013 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
8014 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
8015 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
8016 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
8017 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
8019 ret
= SetForegroundWindow(GetDesktopWindow());
8020 ok(ret
, "Failed to set foreground window.\n");
8021 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
8022 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
8023 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
8024 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
8026 ret
= ShowWindow(window
, SW_RESTORE
);
8027 ok(ret
, "Failed to restore window.\n");
8028 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
8029 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
8030 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
8031 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
8033 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
8034 hr
= reset_device(device
, &device_desc
);
8035 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
8036 hr
= IDirect3DDevice8_TestCooperativeLevel(device
);
8037 /* The device is not lost on Windows 10. */
8038 todo_wine
ok(hr
== D3DERR_DEVICELOST
|| broken(hr
== D3D_OK
), "Got unexpected hr %#x.\n", hr
);
8039 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
8040 todo_wine
ok(hr
== D3DERR_DEVICELOST
|| broken(hr
== D3D_OK
), "Got unexpected hr %#x.\n", hr
);
8042 ret
= SetForegroundWindow(GetDesktopWindow());
8043 ok(ret
, "Failed to set foreground window.\n");
8044 hr
= reset_device(device
, &device_desc
);
8045 ok(hr
== D3DERR_DEVICELOST
|| broken(hr
== D3D_OK
), "Got unexpected hr %#x.\n", hr
);
8046 ret
= ShowWindow(window
, SW_RESTORE
);
8047 ok(ret
, "Failed to restore window.\n");
8048 ret
= SetForegroundWindow(window
);
8049 ok(ret
, "Failed to set foreground window.\n");
8050 hr
= reset_device(device
, &device_desc
);
8051 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
8053 refcount
= IDirect3DDevice8_Release(device
);
8054 ok(!refcount
, "Device has %u references left.\n", refcount
);
8056 IDirect3D8_Release(d3d
);
8057 DestroyWindow(window
);
8060 static void test_resource_priority(void)
8062 IDirect3DDevice8
*device
;
8063 IDirect3DTexture8
*texture
;
8064 IDirect3DVertexBuffer8
*buffer
;
8073 BOOL can_set_priority
;
8077 {D3DPOOL_DEFAULT
, "D3DPOOL_DEFAULT", FALSE
},
8078 {D3DPOOL_SYSTEMMEM
, "D3DPOOL_SYSTEMMEM", FALSE
},
8079 {D3DPOOL_MANAGED
, "D3DPOOL_MANAGED", TRUE
},
8080 {D3DPOOL_SCRATCH
, "D3DPOOL_SCRATCH", FALSE
}
8085 window
= create_window();
8086 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
8087 ok(!!d3d
, "Failed to create a D3D object.\n");
8088 if (!(device
= create_device(d3d
, window
, NULL
)))
8090 skip("Failed to create a D3D device, skipping tests.\n");
8091 IDirect3D8_Release(d3d
);
8092 DestroyWindow(window
);
8096 for (i
= 0; i
< ARRAY_SIZE(test_data
); i
++)
8098 hr
= IDirect3DDevice8_CreateTexture(device
, 16, 16, 0, 0, D3DFMT_X8R8G8B8
,
8099 test_data
[i
].pool
, &texture
);
8100 ok(SUCCEEDED(hr
), "Failed to create texture, hr %#x, pool %s.\n", hr
, test_data
[i
].name
);
8102 priority
= IDirect3DTexture8_GetPriority(texture
);
8103 ok(priority
== 0, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
8104 priority
= IDirect3DTexture8_SetPriority(texture
, 1);
8105 ok(priority
== 0, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
8106 priority
= IDirect3DTexture8_GetPriority(texture
);
8107 if (test_data
[i
].can_set_priority
)
8109 ok(priority
== 1, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
8110 priority
= IDirect3DTexture8_SetPriority(texture
, 0);
8111 ok(priority
== 1, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
8114 ok(priority
== 0, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
8116 IDirect3DTexture8_Release(texture
);
8118 if (test_data
[i
].pool
!= D3DPOOL_SCRATCH
)
8120 hr
= IDirect3DDevice8_CreateVertexBuffer(device
, 256, 0, 0,
8121 test_data
[i
].pool
, &buffer
);
8122 ok(SUCCEEDED(hr
), "Failed to create buffer, hr %#x, pool %s.\n", hr
, test_data
[i
].name
);
8124 priority
= IDirect3DVertexBuffer8_GetPriority(buffer
);
8125 ok(priority
== 0, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
8126 priority
= IDirect3DVertexBuffer8_SetPriority(buffer
, 1);
8127 ok(priority
== 0, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
8128 priority
= IDirect3DVertexBuffer8_GetPriority(buffer
);
8129 if (test_data
[i
].can_set_priority
)
8131 ok(priority
== 1, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
8132 priority
= IDirect3DVertexBuffer8_SetPriority(buffer
, 0);
8133 ok(priority
== 1, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
8136 ok(priority
== 0, "Got unexpected priority %u, pool %s.\n", priority
, test_data
[i
].name
);
8138 IDirect3DVertexBuffer8_Release(buffer
);
8142 refcount
= IDirect3DDevice8_Release(device
);
8143 ok(!refcount
, "Device has %u references left.\n", refcount
);
8144 IDirect3D8_Release(d3d
);
8145 DestroyWindow(window
);
8148 static void test_swapchain_parameters(void)
8150 IDirect3DSurface8
*backbuffer
;
8151 IDirect3DDevice8
*device
;
8152 HRESULT hr
, expected_hr
;
8157 D3DPRESENT_PARAMETERS present_parameters
, present_parameters_windowed
= {0};
8161 UINT backbuffer_count
;
8162 D3DSWAPEFFECT swap_effect
;
8167 /* Swap effect 0 is not allowed. */
8168 {TRUE
, 1, 0, D3DERR_INVALIDCALL
},
8169 {FALSE
, 1, 0, D3DERR_INVALIDCALL
},
8171 /* All (non-ex) swap effects are allowed in
8172 * windowed and fullscreen mode. */
8173 {TRUE
, 1, D3DSWAPEFFECT_DISCARD
, D3D_OK
},
8174 {TRUE
, 1, D3DSWAPEFFECT_FLIP
, D3D_OK
},
8175 {FALSE
, 1, D3DSWAPEFFECT_DISCARD
, D3D_OK
},
8176 {FALSE
, 1, D3DSWAPEFFECT_FLIP
, D3D_OK
},
8177 {FALSE
, 1, D3DSWAPEFFECT_COPY
, D3D_OK
},
8179 /* Only one backbuffer in copy mode. Reset allows it for
8181 {TRUE
, 0, D3DSWAPEFFECT_COPY
, D3D_OK
},
8182 {TRUE
, 1, D3DSWAPEFFECT_COPY
, D3D_OK
},
8183 {TRUE
, 2, D3DSWAPEFFECT_COPY
, D3DERR_INVALIDCALL
},
8184 {FALSE
, 2, D3DSWAPEFFECT_COPY
, D3DERR_INVALIDCALL
},
8185 {TRUE
, 0, D3DSWAPEFFECT_COPY_VSYNC
, D3D_OK
},
8186 {TRUE
, 1, D3DSWAPEFFECT_COPY_VSYNC
, D3D_OK
},
8187 {TRUE
, 2, D3DSWAPEFFECT_COPY_VSYNC
, D3DERR_INVALIDCALL
},
8188 {FALSE
, 2, D3DSWAPEFFECT_COPY_VSYNC
, D3DERR_INVALIDCALL
},
8190 /* Ok with the others, in fullscreen and windowed mode. */
8191 {TRUE
, 2, D3DSWAPEFFECT_DISCARD
, D3D_OK
},
8192 {TRUE
, 2, D3DSWAPEFFECT_FLIP
, D3D_OK
},
8193 {FALSE
, 2, D3DSWAPEFFECT_DISCARD
, D3D_OK
},
8194 {FALSE
, 2, D3DSWAPEFFECT_FLIP
, D3D_OK
},
8196 /* Invalid swapeffects. */
8197 {TRUE
, 1, D3DSWAPEFFECT_COPY_VSYNC
+ 1, D3DERR_INVALIDCALL
},
8198 {FALSE
, 1, D3DSWAPEFFECT_COPY_VSYNC
+ 1, D3DERR_INVALIDCALL
},
8200 /* 3 is the highest allowed backbuffer count. */
8201 {TRUE
, 3, D3DSWAPEFFECT_DISCARD
, D3D_OK
},
8202 {TRUE
, 4, D3DSWAPEFFECT_DISCARD
, D3DERR_INVALIDCALL
},
8203 {TRUE
, 4, D3DSWAPEFFECT_FLIP
, D3DERR_INVALIDCALL
},
8204 {FALSE
, 4, D3DSWAPEFFECT_DISCARD
, D3DERR_INVALIDCALL
},
8205 {FALSE
, 4, D3DSWAPEFFECT_FLIP
, D3DERR_INVALIDCALL
},
8208 window
= create_window();
8209 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
8210 ok(!!d3d
, "Failed to create a D3D object.\n");
8211 if (!(device
= create_device(d3d
, window
, NULL
)))
8213 skip("Failed to create a D3D device, skipping tests.\n");
8214 IDirect3D8_Release(d3d
);
8215 DestroyWindow(window
);
8218 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
8219 ok(SUCCEEDED(hr
), "Failed to get device caps, hr %#x.\n", hr
);
8220 IDirect3DDevice8_Release(device
);
8222 present_parameters_windowed
.BackBufferWidth
= registry_mode
.dmPelsWidth
;
8223 present_parameters_windowed
.BackBufferHeight
= registry_mode
.dmPelsHeight
;
8224 present_parameters_windowed
.hDeviceWindow
= window
;
8225 present_parameters_windowed
.BackBufferFormat
= D3DFMT_X8R8G8B8
;
8226 present_parameters_windowed
.SwapEffect
= D3DSWAPEFFECT_COPY
;
8227 present_parameters_windowed
.Windowed
= TRUE
;
8228 present_parameters_windowed
.BackBufferCount
= 1;
8230 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
)
8232 UINT bb_count
= tests
[i
].backbuffer_count
? tests
[i
].backbuffer_count
: 1;
8234 memset(&present_parameters
, 0, sizeof(present_parameters
));
8235 present_parameters
.BackBufferWidth
= registry_mode
.dmPelsWidth
;
8236 present_parameters
.BackBufferHeight
= registry_mode
.dmPelsHeight
;
8237 present_parameters
.hDeviceWindow
= window
;
8238 present_parameters
.BackBufferFormat
= D3DFMT_X8R8G8B8
;
8240 present_parameters
.SwapEffect
= tests
[i
].swap_effect
;
8241 present_parameters
.Windowed
= tests
[i
].windowed
;
8242 present_parameters
.BackBufferCount
= tests
[i
].backbuffer_count
;
8244 hr
= IDirect3D8_CreateDevice(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, window
,
8245 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
8246 ok(hr
== tests
[i
].hr
, "Expected hr %x, got %x, test %u.\n", tests
[i
].hr
, hr
, i
);
8249 for (j
= 0; j
< bb_count
; ++j
)
8251 hr
= IDirect3DDevice8_GetBackBuffer(device
, j
, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
8252 ok(SUCCEEDED(hr
), "Failed to get backbuffer %u, hr %#x, test %u.\n", j
, hr
, i
);
8253 IDirect3DSurface8_Release(backbuffer
);
8255 hr
= IDirect3DDevice8_GetBackBuffer(device
, j
, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
8256 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %x, test %u.\n", hr
, i
);
8258 IDirect3DDevice8_Release(device
);
8261 hr
= IDirect3D8_CreateDevice(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, window
,
8262 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters_windowed
, &device
);
8263 ok(SUCCEEDED(hr
), "Failed to create device, hr %#x, test %u.\n", hr
, i
);
8265 memset(&present_parameters
, 0, sizeof(present_parameters
));
8266 present_parameters
.BackBufferWidth
= registry_mode
.dmPelsWidth
;
8267 present_parameters
.BackBufferHeight
= registry_mode
.dmPelsHeight
;
8268 present_parameters
.hDeviceWindow
= window
;
8269 present_parameters
.BackBufferFormat
= D3DFMT_X8R8G8B8
;
8271 present_parameters
.SwapEffect
= tests
[i
].swap_effect
;
8272 present_parameters
.Windowed
= tests
[i
].windowed
;
8273 present_parameters
.BackBufferCount
= tests
[i
].backbuffer_count
;
8275 hr
= IDirect3DDevice8_Reset(device
, &present_parameters
);
8276 ok(hr
== tests
[i
].hr
, "Expected hr %x, got %x, test %u.\n", tests
[i
].hr
, hr
, i
);
8280 hr
= IDirect3DDevice8_Reset(device
, &present_parameters_windowed
);
8281 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x, test %u.\n", hr
, i
);
8285 for (j
= 0; j
< bb_count
; ++j
)
8287 hr
= IDirect3DDevice8_GetBackBuffer(device
, j
, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
8289 ok(SUCCEEDED(hr
), "Failed to get backbuffer %u, hr %#x, test %u.\n", j
, hr
, i
);
8291 IDirect3DSurface8_Release(backbuffer
);
8293 hr
= IDirect3DDevice8_GetBackBuffer(device
, j
, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
8294 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %x, test %u.\n", hr
, i
);
8296 IDirect3DDevice8_Release(device
);
8299 for (i
= 0; i
< 10; ++i
)
8301 memset(&present_parameters
, 0, sizeof(present_parameters
));
8302 present_parameters
.BackBufferWidth
= registry_mode
.dmPelsWidth
;
8303 present_parameters
.BackBufferHeight
= registry_mode
.dmPelsHeight
;
8304 present_parameters
.hDeviceWindow
= window
;
8305 present_parameters
.BackBufferFormat
= D3DFMT_X8R8G8B8
;
8306 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
8307 present_parameters
.Windowed
= FALSE
;
8308 present_parameters
.BackBufferCount
= 2;
8310 present_parameters
.FullScreen_PresentationInterval
= i
;
8311 switch (present_parameters
.FullScreen_PresentationInterval
)
8313 case D3DPRESENT_INTERVAL_ONE
:
8314 case D3DPRESENT_INTERVAL_TWO
:
8315 case D3DPRESENT_INTERVAL_THREE
:
8316 case D3DPRESENT_INTERVAL_FOUR
:
8317 if (!(caps
.PresentationIntervals
& present_parameters
.FullScreen_PresentationInterval
))
8320 case D3DPRESENT_INTERVAL_DEFAULT
:
8321 expected_hr
= D3D_OK
;
8324 expected_hr
= D3DERR_INVALIDCALL
;
8328 hr
= IDirect3D8_CreateDevice(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, window
,
8329 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
8330 ok(hr
== expected_hr
, "Got unexpected hr %#x, test %u.\n", hr
, i
);
8332 IDirect3DDevice8_Release(device
);
8335 IDirect3D8_Release(d3d
);
8336 DestroyWindow(window
);
8339 static void test_check_device_format(void)
8341 D3DDEVTYPE device_type
;
8345 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
8346 ok(!!d3d
, "Failed to create a D3D object.\n");
8348 for (device_type
= D3DDEVTYPE_HAL
; device_type
<= D3DDEVTYPE_SW
; ++device_type
)
8350 hr
= IDirect3D8_CheckDeviceFormat(d3d
, 0, device_type
, D3DFMT_UNKNOWN
,
8351 0, D3DRTYPE_SURFACE
, D3DFMT_A8R8G8B8
);
8352 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x, device type %#x.\n", hr
, device_type
);
8353 hr
= IDirect3D8_CheckDeviceFormat(d3d
, 0, device_type
, D3DFMT_UNKNOWN
,
8354 0, D3DRTYPE_TEXTURE
, D3DFMT_A8R8G8B8
);
8355 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x, device type %#x.\n", hr
, device_type
);
8356 hr
= IDirect3D8_CheckDeviceFormat(d3d
, 0, device_type
, D3DFMT_UNKNOWN
,
8357 0, D3DRTYPE_SURFACE
, D3DFMT_X8R8G8B8
);
8358 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x, device type %#x.\n", hr
, device_type
);
8359 hr
= IDirect3D8_CheckDeviceFormat(d3d
, 0, device_type
, D3DFMT_UNKNOWN
,
8360 0, D3DRTYPE_TEXTURE
, D3DFMT_X8R8G8B8
);
8361 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x, device type %#x.\n", hr
, device_type
);
8364 hr
= IDirect3D8_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, D3DFMT_A8R8G8B8
,
8365 0, D3DRTYPE_TEXTURE
, D3DFMT_X8R8G8B8
);
8366 ok(hr
== D3DERR_NOTAVAILABLE
, "Got unexpected hr %#x.\n", hr
);
8367 hr
= IDirect3D8_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
8368 0, D3DRTYPE_TEXTURE
, D3DFMT_X8R8G8B8
);
8369 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
, "Got unexpected hr %#x.\n", hr
);
8371 hr
= IDirect3D8_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
8372 0, D3DRTYPE_VERTEXBUFFER
, D3DFMT_VERTEXDATA
);
8373 todo_wine
ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
8374 hr
= IDirect3D8_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
8375 0, D3DRTYPE_INDEXBUFFER
, D3DFMT_VERTEXDATA
);
8376 todo_wine
ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
8377 hr
= IDirect3D8_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
8378 0, D3DRTYPE_INDEXBUFFER
, D3DFMT_INDEX16
);
8379 todo_wine
ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
8381 hr
= IDirect3D8_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
8382 D3DUSAGE_SOFTWAREPROCESSING
, D3DRTYPE_VERTEXBUFFER
, D3DFMT_VERTEXDATA
);
8383 todo_wine
ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
8384 hr
= IDirect3D8_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
8385 D3DUSAGE_SOFTWAREPROCESSING
, D3DRTYPE_INDEXBUFFER
, D3DFMT_VERTEXDATA
);
8386 todo_wine
ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
8387 hr
= IDirect3D8_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
,
8388 D3DUSAGE_SOFTWAREPROCESSING
, D3DRTYPE_INDEXBUFFER
, D3DFMT_INDEX16
);
8389 todo_wine
ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
8391 hr
= IDirect3D8_CheckDepthStencilMatch(d3d
, D3DADAPTER_DEFAULT
,
8392 D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
, D3DFMT_A8R8G8B8
, D3DFMT_D32
);
8393 ok(hr
== D3DERR_NOTAVAILABLE
|| broken(hr
== D3DERR_INVALIDCALL
/* Windows 10 */),
8394 "Got unexpected hr %#x.\n", hr
);
8396 hr
= IDirect3D8_CheckDepthStencilMatch(d3d
, D3DADAPTER_DEFAULT
,
8397 D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
, D3DFMT_R5G6B5
, D3DFMT_D32
);
8398 ok(hr
== D3DERR_NOTAVAILABLE
|| broken(hr
== D3DERR_INVALIDCALL
/* Windows 10 */),
8399 "Got unexpected hr %#x.\n", hr
);
8401 IDirect3D8_Release(d3d
);
8404 static void test_miptree_layout(void)
8406 unsigned int pool_idx
, format_idx
, base_dimension
, level_count
, offset
, i
, j
;
8407 IDirect3DCubeTexture8
*texture_cube
;
8408 IDirect3DTexture8
*texture_2d
;
8409 IDirect3DDevice8
*device
;
8410 D3DLOCKED_RECT map_desc
;
8425 {D3DFMT_A8R8G8B8
, "D3DFMT_A8R8G8B8"},
8426 {D3DFMT_A8
, "D3DFMT_A8"},
8427 {D3DFMT_L8
, "D3DFMT_L8"},
8428 {MAKEFOURCC('A','T','I','1'), "D3DFMT_ATI1"},
8429 {MAKEFOURCC('A','T','I','2'), "D3DFMT_ATI2"},
8438 {D3DPOOL_MANAGED
, "D3DPOOL_MANAGED"},
8439 {D3DPOOL_SYSTEMMEM
, "D3DPOOL_SYSTEMMEM"},
8440 {D3DPOOL_SCRATCH
, "D3DPOOL_SCRATCH"},
8443 window
= create_window();
8444 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
8445 ok(!!d3d
, "Failed to create a D3D object.\n");
8446 if (!(device
= create_device(d3d
, window
, NULL
)))
8448 skip("Failed to create a D3D device, skipping tests.\n");
8452 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
8453 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
8455 base_dimension
= 257;
8456 if (caps
.TextureCaps
& (D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_CUBEMAP_POW2
))
8458 skip("Using power of two base dimension.\n");
8459 base_dimension
= 256;
8462 for (format_idx
= 0; format_idx
< ARRAY_SIZE(formats
); ++format_idx
)
8464 if (FAILED(hr
= IDirect3D8_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
8465 D3DFMT_X8R8G8B8
, 0, D3DRTYPE_TEXTURE
, formats
[format_idx
].format
)))
8467 skip("%s textures not supported, skipping tests.\n", formats
[format_idx
].name
);
8471 for (pool_idx
= 0; pool_idx
< ARRAY_SIZE(pools
); ++pool_idx
)
8473 hr
= IDirect3DDevice8_CreateTexture(device
, base_dimension
, base_dimension
, 0, 0,
8474 formats
[format_idx
].format
, pools
[pool_idx
].pool
, &texture_2d
);
8475 ok(SUCCEEDED(hr
), "Failed to create a %s %s texture, hr %#x.\n",
8476 pools
[pool_idx
].name
, formats
[format_idx
].name
, hr
);
8478 level_count
= IDirect3DTexture8_GetLevelCount(texture_2d
);
8479 for (i
= 0, offset
= 0; i
< level_count
; ++i
)
8481 hr
= IDirect3DTexture8_LockRect(texture_2d
, i
, &map_desc
, NULL
, 0);
8482 ok(SUCCEEDED(hr
), "%s, %s: Failed to lock level %u, hr %#x.\n",
8483 pools
[pool_idx
].name
, formats
[format_idx
].name
, i
, hr
);
8486 base
= map_desc
.pBits
;
8488 ok(map_desc
.pBits
== base
+ offset
,
8489 "%s, %s, level %u: Got unexpected pBits %p, expected %p.\n",
8490 pools
[pool_idx
].name
, formats
[format_idx
].name
, i
, map_desc
.pBits
, base
+ offset
);
8491 offset
+= (base_dimension
>> i
) * map_desc
.Pitch
;
8493 hr
= IDirect3DTexture8_UnlockRect(texture_2d
, i
);
8494 ok(SUCCEEDED(hr
), "%s, %s Failed to unlock level %u, hr %#x.\n",
8495 pools
[pool_idx
].name
, formats
[format_idx
].name
, i
, hr
);
8498 IDirect3DTexture8_Release(texture_2d
);
8501 if (FAILED(hr
= IDirect3D8_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
8502 D3DFMT_X8R8G8B8
, 0, D3DRTYPE_CUBETEXTURE
, formats
[format_idx
].format
)))
8504 skip("%s cube textures not supported, skipping tests.\n", formats
[format_idx
].name
);
8508 for (pool_idx
= 0; pool_idx
< ARRAY_SIZE(pools
); ++pool_idx
)
8510 hr
= IDirect3DDevice8_CreateCubeTexture(device
, base_dimension
, 0, 0,
8511 formats
[format_idx
].format
, pools
[pool_idx
].pool
, &texture_cube
);
8512 ok(SUCCEEDED(hr
), "Failed to create a %s %s cube texture, hr %#x.\n",
8513 pools
[pool_idx
].name
, formats
[format_idx
].name
, hr
);
8515 level_count
= IDirect3DCubeTexture8_GetLevelCount(texture_cube
);
8516 for (i
= 0, offset
= 0; i
< 6; ++i
)
8518 for (j
= 0; j
< level_count
; ++j
)
8520 hr
= IDirect3DCubeTexture8_LockRect(texture_cube
, i
, j
, &map_desc
, NULL
, 0);
8521 ok(SUCCEEDED(hr
), "%s, %s: Failed to lock face %u, level %u, hr %#x.\n",
8522 pools
[pool_idx
].name
, formats
[format_idx
].name
, i
, j
, hr
);
8525 base
= map_desc
.pBits
;
8527 ok(map_desc
.pBits
== base
+ offset
,
8528 "%s, %s, face %u, level %u: Got unexpected pBits %p, expected %p.\n",
8529 pools
[pool_idx
].name
, formats
[format_idx
].name
, i
, j
, map_desc
.pBits
, base
+ offset
);
8530 offset
+= (base_dimension
>> j
) * map_desc
.Pitch
;
8532 hr
= IDirect3DCubeTexture8_UnlockRect(texture_cube
, i
, j
);
8533 ok(SUCCEEDED(hr
), "%s, %s: Failed to unlock face %u, level %u, hr %#x.\n",
8534 pools
[pool_idx
].name
, formats
[format_idx
].name
, i
, j
, hr
);
8536 offset
= (offset
+ 15) & ~15;
8539 IDirect3DCubeTexture8_Release(texture_cube
);
8543 refcount
= IDirect3DDevice8_Release(device
);
8544 ok(!refcount
, "Device has %u references left.\n", refcount
);
8546 IDirect3D8_Release(d3d
);
8547 DestroyWindow(window
);
8550 static void test_render_target_device_mismatch(void)
8552 IDirect3DDevice8
*device
, *device2
;
8553 IDirect3DSurface8
*surface
, *rt
;
8559 window
= create_window();
8560 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
8561 ok(!!d3d
, "Failed to create a D3D object.\n");
8562 if (!(device
= create_device(d3d
, window
, NULL
)))
8564 skip("Failed to create a D3D device.\n");
8565 IDirect3D8_Release(d3d
);
8566 DestroyWindow(window
);
8570 hr
= IDirect3DDevice8_GetRenderTarget(device
, &rt
);
8571 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
8573 device2
= create_device(d3d
, window
, NULL
);
8574 ok(!!device2
, "Failed to create a D3D device.\n");
8576 hr
= IDirect3DDevice8_CreateRenderTarget(device2
, 640, 480,
8577 D3DFMT_A8R8G8B8
, D3DMULTISAMPLE_NONE
, FALSE
, &surface
);
8578 ok(SUCCEEDED(hr
), "Failed to create render target, hr %#x.\n", hr
);
8580 hr
= IDirect3DDevice8_SetRenderTarget(device
, surface
, NULL
);
8581 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
8583 IDirect3DSurface8_Release(surface
);
8585 hr
= IDirect3DDevice8_GetRenderTarget(device2
, &surface
);
8586 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
8588 hr
= IDirect3DDevice8_SetRenderTarget(device
, surface
, NULL
);
8589 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
8591 IDirect3DSurface8_Release(surface
);
8593 hr
= IDirect3DDevice8_GetRenderTarget(device
, &surface
);
8594 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
8595 ok(surface
== rt
, "Got unexpected render target %p, expected %p.\n", surface
, rt
);
8596 IDirect3DSurface8_Release(surface
);
8597 IDirect3DSurface8_Release(rt
);
8599 refcount
= IDirect3DDevice8_Release(device
);
8600 ok(!refcount
, "Device has %u references left.\n", refcount
);
8601 refcount
= IDirect3DDevice8_Release(device2
);
8602 ok(!refcount
, "Device has %u references left.\n", refcount
);
8603 IDirect3D8_Release(d3d
);
8604 DestroyWindow(window
);
8607 static void test_format_unknown(void)
8609 IDirect3DDevice8
*device
;
8616 window
= create_window();
8617 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
8618 ok(!!d3d
, "Failed to create a D3D object.\n");
8619 if (!(device
= create_device(d3d
, window
, NULL
)))
8621 skip("Failed to create a D3D device.\n");
8622 IDirect3D8_Release(d3d
);
8623 DestroyWindow(window
);
8627 if (SUCCEEDED(IDirect3D8_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
8628 D3DFMT_X8R8G8B8
, 0, D3DRTYPE_TEXTURE
, D3DFMT_P8
)))
8630 skip("P8 textures are supported, skipping some tests.\n");
8634 iface
= (void *)0xdeadbeef;
8635 hr
= IDirect3DDevice8_CreateRenderTarget(device
, 64, 64,
8636 D3DFMT_P8
, D3DMULTISAMPLE_NONE
, FALSE
, (IDirect3DSurface8
**)&iface
);
8637 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
8638 ok(!iface
, "Got unexpected iface %p.\n", iface
);
8640 iface
= (void *)0xdeadbeef;
8641 hr
= IDirect3DDevice8_CreateDepthStencilSurface(device
, 64, 64,
8642 D3DFMT_P8
, D3DMULTISAMPLE_NONE
, (IDirect3DSurface8
**)&iface
);
8643 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
8644 ok(!iface
, "Got unexpected iface %p.\n", iface
);
8646 iface
= (void *)0xdeadbeef;
8647 hr
= IDirect3DDevice8_CreateTexture(device
, 64, 64, 1, 0,
8648 D3DFMT_P8
, D3DPOOL_DEFAULT
, (IDirect3DTexture8
**)&iface
);
8649 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
8650 ok(!iface
, "Got unexpected iface %p.\n", iface
);
8652 iface
= (void *)0xdeadbeef;
8653 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 64, 1, 0,
8654 D3DFMT_P8
, D3DPOOL_DEFAULT
, (IDirect3DCubeTexture8
**)&iface
);
8655 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
8656 ok(!iface
, "Got unexpected iface %p.\n", iface
);
8658 iface
= (void *)0xdeadbeef;
8659 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 64, 64, 1, 1, 0,
8660 D3DFMT_P8
, D3DPOOL_DEFAULT
, (IDirect3DVolumeTexture8
**)&iface
);
8661 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
8662 ok(!iface
, "Got unexpected iface %p.\n", iface
);
8665 iface
= (void *)0xdeadbeef;
8666 hr
= IDirect3DDevice8_CreateRenderTarget(device
, 64, 64,
8667 D3DFMT_UNKNOWN
, D3DMULTISAMPLE_NONE
, FALSE
, (IDirect3DSurface8
**)&iface
);
8668 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
8669 ok(iface
== (void *)0xdeadbeef, "Got unexpected iface %p.\n", iface
);
8671 iface
= (void *)0xdeadbeef;
8672 hr
= IDirect3DDevice8_CreateDepthStencilSurface(device
, 64, 64,
8673 D3DFMT_UNKNOWN
, D3DMULTISAMPLE_NONE
, (IDirect3DSurface8
**)&iface
);
8674 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
8675 ok(iface
== (void *)0xdeadbeef, "Got unexpected iface %p.\n", iface
);
8677 iface
= (void *)0xdeadbeef;
8678 hr
= IDirect3DDevice8_CreateImageSurface(device
, 64, 64,
8679 D3DFMT_UNKNOWN
, (IDirect3DSurface8
**)&iface
);
8680 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
8681 ok(!iface
, "Got unexpected iface %p.\n", iface
);
8683 iface
= (void *)0xdeadbeef;
8684 hr
= IDirect3DDevice8_CreateTexture(device
, 64, 64, 1, 0,
8685 D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
, (IDirect3DTexture8
**)&iface
);
8686 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
8687 ok(iface
== (void *)0xdeadbeef, "Got unexpected iface %p.\n", iface
);
8689 iface
= (void *)0xdeadbeef;
8690 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 64, 1, 0,
8691 D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
, (IDirect3DCubeTexture8
**)&iface
);
8692 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
8693 ok(iface
== (void *)0xdeadbeef, "Got unexpected iface %p.\n", iface
);
8695 iface
= (void *)0xdeadbeef;
8696 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 64, 64, 1, 1, 0,
8697 D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
, (IDirect3DVolumeTexture8
**)&iface
);
8698 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
8699 ok(iface
== (void *)0xdeadbeef, "Got unexpected iface %p.\n", iface
);
8701 refcount
= IDirect3DDevice8_Release(device
);
8702 ok(!refcount
, "Device has %u references left.\n", refcount
);
8703 IDirect3D8_Release(d3d
);
8704 DestroyWindow(window
);
8707 static void test_destroyed_window(void)
8709 IDirect3DDevice8
*device
;
8715 /* No WS_VISIBLE. */
8716 window
= CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW
,
8717 0, 0, 640, 480, NULL
, NULL
, NULL
, NULL
);
8718 ok(!!window
, "Failed to create a window.\n");
8720 d3d8
= Direct3DCreate8(D3D_SDK_VERSION
);
8721 ok(!!d3d8
, "Failed to create a D3D object.\n");
8722 device
= create_device(d3d8
, window
, NULL
);
8723 IDirect3D8_Release(d3d8
);
8724 DestroyWindow(window
);
8727 skip("Failed to create a 3D device, skipping test.\n");
8731 hr
= IDirect3DDevice8_BeginScene(device
);
8732 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
8733 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0x00000000, 0.0f
, 0);
8734 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
8735 hr
= IDirect3DDevice8_EndScene(device
);
8736 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8737 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
8738 todo_wine
ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
8740 refcount
= IDirect3DDevice8_Release(device
);
8741 ok(!refcount
, "Device has %u references left.\n", refcount
);
8744 static void test_lockable_backbuffer(void)
8746 D3DPRESENT_PARAMETERS present_parameters
= {0};
8747 struct device_desc device_desc
;
8748 IDirect3DSurface8
*surface
;
8749 IDirect3DDevice8
*device
;
8750 D3DLOCKED_RECT lockrect
;
8756 window
= create_window();
8757 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
8758 ok(!!d3d
, "Failed to create a D3D object.\n");
8760 if (!(device
= create_device(d3d
, window
, NULL
)))
8762 skip("Failed to create a D3D device, skipping tests.\n");
8763 IDirect3D8_Release(d3d
);
8764 DestroyWindow(window
);
8768 hr
= IDirect3DDevice8_GetBackBuffer(device
, 0, D3DBACKBUFFER_TYPE_MONO
, &surface
);
8769 ok(SUCCEEDED(hr
), "Failed to get backbuffer, hr %#x.\n", hr
);
8771 hr
= IDirect3DSurface8_LockRect(surface
, &lockrect
, NULL
, D3DLOCK_READONLY
);
8772 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
8774 IDirect3DSurface8_Release(surface
);
8776 /* Reset with D3DPRESENTFLAG_LOCKABLE_BACKBUFFER. */
8777 present_parameters
.BackBufferWidth
= 640;
8778 present_parameters
.BackBufferHeight
= 480;
8779 present_parameters
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
8780 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
8781 present_parameters
.hDeviceWindow
= window
;
8782 present_parameters
.Windowed
= TRUE
;
8783 present_parameters
.EnableAutoDepthStencil
= TRUE
;
8784 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
8785 present_parameters
.Flags
= D3DPRESENTFLAG_LOCKABLE_BACKBUFFER
;
8787 hr
= IDirect3DDevice8_Reset(device
, &present_parameters
);
8788 ok(SUCCEEDED(hr
), "Failed to reset device, hr %#x.\n", hr
);
8790 hr
= IDirect3DDevice8_GetBackBuffer(device
, 0, D3DBACKBUFFER_TYPE_MONO
, &surface
);
8791 ok(SUCCEEDED(hr
), "Failed to get backbuffer, hr %#x.\n", hr
);
8793 hr
= IDirect3DSurface8_LockRect(surface
, &lockrect
, NULL
, D3DLOCK_READONLY
);
8794 ok(SUCCEEDED(hr
), "Failed to lock rect, hr %#x.\n", hr
);
8795 hr
= IDirect3DSurface8_UnlockRect(surface
);
8796 ok(SUCCEEDED(hr
), "Failed to unlock rect, hr %#x.\n", hr
);
8798 IDirect3DSurface8_Release(surface
);
8799 refcount
= IDirect3DDevice8_Release(device
);
8800 ok(!refcount
, "Device has %u references left.\n", refcount
);
8802 device_desc
.adapter_ordinal
= D3DADAPTER_DEFAULT
;
8803 device_desc
.width
= 640;
8804 device_desc
.height
= 480;
8805 device_desc
.device_window
= window
;
8806 device_desc
.flags
= CREATE_DEVICE_LOCKABLE_BACKBUFFER
;
8808 device
= create_device(d3d
, window
, &device_desc
);
8809 ok(!!device
, "Failed to create device.\n");
8811 hr
= IDirect3DDevice8_GetBackBuffer(device
, 0, D3DBACKBUFFER_TYPE_MONO
, &surface
);
8812 ok(SUCCEEDED(hr
), "Failed to get backbuffer, hr %#x.\n", hr
);
8814 hr
= IDirect3DSurface8_LockRect(surface
, &lockrect
, NULL
, D3DLOCK_READONLY
);
8815 ok(SUCCEEDED(hr
), "Failed to lock rect, hr %#x.\n", hr
);
8816 hr
= IDirect3DSurface8_UnlockRect(surface
);
8817 ok(SUCCEEDED(hr
), "Failed to unlock rect, hr %#x.\n", hr
);
8819 IDirect3DSurface8_Release(surface
);
8820 refcount
= IDirect3DDevice8_Release(device
);
8821 ok(!refcount
, "Device has %u references left.\n", refcount
);
8822 IDirect3D8_Release(d3d
);
8823 DestroyWindow(window
);
8826 static void test_clip_planes_limits(void)
8828 static const DWORD device_flags
[] = {0, CREATE_DEVICE_SWVP_ONLY
};
8829 IDirect3DDevice8
*device
;
8830 struct device_desc desc
;
8840 window
= create_window();
8841 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
8842 ok(!!d3d
, "Failed to create a D3D object.\n");
8844 for (i
= 0; i
< ARRAY_SIZE(device_flags
); ++i
)
8846 desc
.adapter_ordinal
= D3DADAPTER_DEFAULT
;
8847 desc
.device_window
= window
;
8850 desc
.flags
= device_flags
[i
];
8851 if (!(device
= create_device(d3d
, window
, &desc
)))
8853 skip("Failed to create D3D device, flags %#x.\n", desc
.flags
);
8857 memset(&caps
, 0, sizeof(caps
));
8858 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
8859 ok(hr
== D3D_OK
, "Failed to get caps, hr %#x.\n", hr
);
8861 trace("Max user clip planes: %u.\n", caps
.MaxUserClipPlanes
);
8863 for (j
= 0; j
< caps
.MaxUserClipPlanes
; ++j
)
8865 memset(plane
, 0xff, sizeof(plane
));
8866 hr
= IDirect3DDevice8_GetClipPlane(device
, j
, plane
);
8867 ok(hr
== D3D_OK
, "Failed to get clip plane %u, hr %#x.\n", j
, hr
);
8868 ok(!plane
[0] && !plane
[1] && !plane
[2] && !plane
[3],
8869 "Got unexpected plane %u: %.8e, %.8e, %.8e, %.8e.\n",
8870 j
, plane
[0], plane
[1], plane
[2], plane
[3]);
8876 for (j
= 0; j
< caps
.MaxUserClipPlanes
; ++j
)
8879 hr
= IDirect3DDevice8_SetClipPlane(device
, j
, plane
);
8880 ok(hr
== D3D_OK
, "Failed to set clip plane %u, hr %#x.\n", j
, hr
);
8882 for (j
= 0; j
< caps
.MaxUserClipPlanes
; ++j
)
8884 memset(plane
, 0xff, sizeof(plane
));
8885 hr
= IDirect3DDevice8_GetClipPlane(device
, j
, plane
);
8886 ok(hr
== D3D_OK
, "Failed to get clip plane %u, hr %#x.\n", j
, hr
);
8887 ok(plane
[0] == 2.0f
&& plane
[1] == 8.0f
&& plane
[2] == 5.0f
&& plane
[3] == j
,
8888 "Got unexpected plane %u: %.8e, %.8e, %.8e, %.8e.\n",
8889 j
, plane
[0], plane
[1], plane
[2], plane
[3]);
8892 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_CLIPPLANEENABLE
, 0xffffffff);
8893 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8894 hr
= IDirect3DDevice8_GetRenderState(device
, D3DRS_CLIPPLANEENABLE
, &state
);
8895 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
8896 ok(state
== 0xffffffff, "Got unexpected state %#x.\n", state
);
8897 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_CLIPPLANEENABLE
, 0x80000000);
8898 ok(SUCCEEDED(hr
), "Failed to set render state, hr %#x.\n", hr
);
8899 hr
= IDirect3DDevice8_GetRenderState(device
, D3DRS_CLIPPLANEENABLE
, &state
);
8900 ok(SUCCEEDED(hr
), "Failed to get render state, hr %#x.\n", hr
);
8901 ok(state
== 0x80000000, "Got unexpected state %#x.\n", state
);
8903 refcount
= IDirect3DDevice8_Release(device
);
8904 ok(!refcount
, "Device has %u references left.\n", refcount
);
8907 IDirect3D8_Release(d3d
);
8908 DestroyWindow(window
);
8911 static void test_swapchain_multisample_reset(void)
8913 D3DPRESENT_PARAMETERS present_parameters
;
8914 IDirect3DDevice8
*device
;
8920 window
= create_window();
8921 ok(!!window
, "Failed to create a window.\n");
8922 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
8923 ok(!!d3d
, "Failed to create D3D object.\n");
8925 if (IDirect3D8_CheckDeviceMultiSampleType(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
8926 D3DFMT_A8R8G8B8
, TRUE
, D3DMULTISAMPLE_2_SAMPLES
) == D3DERR_NOTAVAILABLE
)
8928 skip("Multisampling not supported for D3DFMT_A8R8G8B8.\n");
8929 IDirect3D8_Release(d3d
);
8930 DestroyWindow(window
);
8934 if (!(device
= create_device(d3d
, window
, NULL
)))
8936 skip("Failed to create 3D device.\n");
8937 IDirect3D8_Release(d3d
);
8938 DestroyWindow(window
);
8942 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
, 0xffffffff, 1.0f
, 0);
8943 ok(hr
== D3D_OK
, "Failed to clear, hr %#x.\n", hr
);
8945 memset(&present_parameters
, 0, sizeof(present_parameters
));
8946 present_parameters
.BackBufferWidth
= 640;
8947 present_parameters
.BackBufferHeight
= 480;
8948 present_parameters
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
8949 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
8950 present_parameters
.hDeviceWindow
= NULL
;
8951 present_parameters
.Windowed
= TRUE
;
8952 present_parameters
.MultiSampleType
= D3DMULTISAMPLE_2_SAMPLES
;
8953 hr
= IDirect3DDevice8_Reset(device
, &present_parameters
);
8954 ok(hr
== D3D_OK
, "Failed to reset device, hr %#x.\n", hr
);
8956 hr
= IDirect3DDevice8_Clear(device
, 0, NULL
, D3DCLEAR_TARGET
, 0xffffffff, 0.0f
, 0);
8957 ok(hr
== D3D_OK
, "Failed to clear, hr %#x.\n", hr
);
8959 refcount
= IDirect3DDevice8_Release(device
);
8960 ok(!refcount
, "Device has %u references left.\n", refcount
);
8961 IDirect3D8_Release(d3d
);
8962 DestroyWindow(window
);
8965 static void test_device_caps(void)
8967 unsigned int adapter_idx
, adapter_count
;
8968 struct device_desc device_desc
;
8969 IDirect3DDevice8
*device
;
8976 window
= create_window();
8977 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
8978 ok(!!d3d
, "Failed to create a D3D object.\n");
8980 device_desc
.device_window
= window
;
8981 device_desc
.width
= 640;
8982 device_desc
.height
= 480;
8983 device_desc
.flags
= 0;
8985 adapter_count
= IDirect3D8_GetAdapterCount(d3d
);
8986 for (adapter_idx
= 0; adapter_idx
< adapter_count
; ++adapter_idx
)
8988 /* Test IDirect3D8_GetDeviceCaps */
8989 hr
= IDirect3D8_GetDeviceCaps(d3d
, adapter_idx
, D3DDEVTYPE_HAL
, &caps
);
8990 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
, "Adapter %u: GetDeviceCaps failed, hr %#x.\n",
8992 if (hr
== D3DERR_NOTAVAILABLE
)
8994 skip("Adapter %u: No Direct3D support, skipping test.\n", adapter_idx
);
8997 ok(caps
.AdapterOrdinal
== adapter_idx
, "Adapter %u: Got unexpected adapter ordinal %u.\n",
8998 adapter_idx
, caps
.AdapterOrdinal
);
9000 /* Test IDirect3DDevice8_GetDeviceCaps */
9001 device_desc
.adapter_ordinal
= adapter_idx
;
9002 device
= create_device(d3d
, window
, &device_desc
);
9005 skip("Adapter %u: Failed to create a D3D device, skipping test.\n", adapter_idx
);
9008 hr
= IDirect3DDevice8_GetDeviceCaps(device
, &caps
);
9009 ok(SUCCEEDED(hr
), "Adapter %u: Failed to get caps, hr %#x.\n", adapter_idx
, hr
);
9011 ok(caps
.AdapterOrdinal
== adapter_idx
, "Adapter %u: Got unexpected adapter ordinal %u.\n",
9012 adapter_idx
, caps
.AdapterOrdinal
);
9013 ok(!(caps
.Caps
& ~D3DCAPS_READ_SCANLINE
),
9014 "Adapter %u: Caps field has unexpected flags %#x.\n", adapter_idx
, caps
.Caps
);
9015 ok(!(caps
.Caps2
& ~(D3DCAPS2_CANCALIBRATEGAMMA
| D3DCAPS2_CANRENDERWINDOWED
9016 | D3DCAPS2_CANMANAGERESOURCE
| D3DCAPS2_DYNAMICTEXTURES
| D3DCAPS2_FULLSCREENGAMMA
9017 | D3DCAPS2_NO2DDURING3DSCENE
| D3DCAPS2_RESERVED
)),
9018 "Adapter %u: Caps2 field has unexpected flags %#x.\n", adapter_idx
, caps
.Caps2
);
9019 /* Nvidia returns that 0x400 flag, which is probably Vista+
9020 * D3DCAPS3_DXVAHD from d3d9caps.h */
9021 /* AMD doesn't filter all the ddraw / d3d9 caps. Consider that behavior
9023 ok(!(caps
.Caps3
& ~(D3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD
| D3DCAPS3_RESERVED
| 0x400))
9024 || broken(!(caps
.Caps3
& ~(D3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD
| 0x80))),
9025 "Adapter %u: Caps3 field has unexpected flags %#x.\n", adapter_idx
, caps
.Caps3
);
9026 ok(!(caps
.PrimitiveMiscCaps
& ~(D3DPMISCCAPS_MASKZ
| D3DPMISCCAPS_LINEPATTERNREP
9027 | D3DPMISCCAPS_CULLNONE
| D3DPMISCCAPS_CULLCW
| D3DPMISCCAPS_CULLCCW
9028 | D3DPMISCCAPS_COLORWRITEENABLE
| D3DPMISCCAPS_CLIPPLANESCALEDPOINTS
9029 | D3DPMISCCAPS_CLIPTLVERTS
| D3DPMISCCAPS_TSSARGTEMP
| D3DPMISCCAPS_BLENDOP
9030 | D3DPMISCCAPS_NULLREFERENCE
))
9031 || broken(!(caps
.PrimitiveMiscCaps
& ~0x003fdff6)),
9032 "Adapter %u: PrimitiveMiscCaps field has unexpected flags %#x.\n", adapter_idx
,
9033 caps
.PrimitiveMiscCaps
);
9034 /* AMD includes an unknown 0x2 flag. */
9035 ok(!(caps
.RasterCaps
& ~(D3DPRASTERCAPS_DITHER
| D3DPRASTERCAPS_PAT
| D3DPRASTERCAPS_ZTEST
9036 | D3DPRASTERCAPS_FOGVERTEX
| D3DPRASTERCAPS_FOGTABLE
| D3DPRASTERCAPS_ANTIALIASEDGES
9037 | D3DPRASTERCAPS_MIPMAPLODBIAS
| D3DPRASTERCAPS_ZBIAS
| D3DPRASTERCAPS_ZBUFFERLESSHSR
9038 | D3DPRASTERCAPS_FOGRANGE
| D3DPRASTERCAPS_ANISOTROPY
| D3DPRASTERCAPS_WBUFFER
9039 | D3DPRASTERCAPS_WFOG
| D3DPRASTERCAPS_ZFOG
| D3DPRASTERCAPS_COLORPERSPECTIVE
9040 | D3DPRASTERCAPS_STRETCHBLTMULTISAMPLE
))
9041 || broken(!(caps
.RasterCaps
& ~0x0ff7f19b)),
9042 "Adapter %u: RasterCaps field has unexpected flags %#x.\n", adapter_idx
,
9044 ok(!(caps
.SrcBlendCaps
& ~(D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
9045 | D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
9046 | D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
9047 | D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
9048 | D3DPBLENDCAPS_BOTHINVSRCALPHA
)),
9049 "Adapter %u: SrcBlendCaps field has unexpected flags %#x.\n", adapter_idx
,
9051 ok(!(caps
.DestBlendCaps
& ~(D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
9052 | D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
9053 | D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
9054 | D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
9055 | D3DPBLENDCAPS_BOTHINVSRCALPHA
)),
9056 "Adapter %u: DestBlendCaps field has unexpected flags %#x.\n", adapter_idx
,
9057 caps
.DestBlendCaps
);
9058 ok(!(caps
.TextureCaps
& ~(D3DPTEXTURECAPS_PERSPECTIVE
| D3DPTEXTURECAPS_POW2
9059 | D3DPTEXTURECAPS_ALPHA
| D3DPTEXTURECAPS_SQUAREONLY
9060 | D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE
| D3DPTEXTURECAPS_ALPHAPALETTE
9061 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PROJECTED
9062 | D3DPTEXTURECAPS_CUBEMAP
| D3DPTEXTURECAPS_VOLUMEMAP
| D3DPTEXTURECAPS_MIPMAP
9063 | D3DPTEXTURECAPS_MIPVOLUMEMAP
| D3DPTEXTURECAPS_MIPCUBEMAP
9064 | D3DPTEXTURECAPS_CUBEMAP_POW2
| D3DPTEXTURECAPS_VOLUMEMAP_POW2
)),
9065 "Adapter %u: TextureCaps field has unexpected flags %#x.\n", adapter_idx
,
9067 ok(!(caps
.TextureFilterCaps
& ~(D3DPTFILTERCAPS_MINFPOINT
| D3DPTFILTERCAPS_MINFLINEAR
9068 | D3DPTFILTERCAPS_MINFANISOTROPIC
| D3DPTFILTERCAPS_MIPFPOINT
9069 | D3DPTFILTERCAPS_MIPFLINEAR
| D3DPTFILTERCAPS_MAGFPOINT
| D3DPTFILTERCAPS_MAGFLINEAR
9070 | D3DPTFILTERCAPS_MAGFANISOTROPIC
| D3DPTFILTERCAPS_MAGFAFLATCUBIC
9071 | D3DPTFILTERCAPS_MAGFGAUSSIANCUBIC
))
9072 || broken(!(caps
.TextureFilterCaps
& ~0x0703073f)),
9073 "Adapter %u: TextureFilterCaps field has unexpected flags %#x.\n", adapter_idx
,
9074 caps
.TextureFilterCaps
);
9075 ok(!(caps
.CubeTextureFilterCaps
& ~(D3DPTFILTERCAPS_MINFPOINT
| D3DPTFILTERCAPS_MINFLINEAR
9076 | D3DPTFILTERCAPS_MINFANISOTROPIC
| D3DPTFILTERCAPS_MIPFPOINT
9077 | D3DPTFILTERCAPS_MIPFLINEAR
| D3DPTFILTERCAPS_MAGFPOINT
| D3DPTFILTERCAPS_MAGFLINEAR
9078 | D3DPTFILTERCAPS_MAGFANISOTROPIC
| D3DPTFILTERCAPS_MAGFAFLATCUBIC
9079 | D3DPTFILTERCAPS_MAGFGAUSSIANCUBIC
)),
9080 "Adapter %u: CubeTextureFilterCaps field has unexpected flags %#x.\n", adapter_idx
,
9081 caps
.CubeTextureFilterCaps
);
9082 ok(!(caps
.VolumeTextureFilterCaps
& ~(D3DPTFILTERCAPS_MINFPOINT
| D3DPTFILTERCAPS_MINFLINEAR
9083 | D3DPTFILTERCAPS_MINFANISOTROPIC
| D3DPTFILTERCAPS_MIPFPOINT
9084 | D3DPTFILTERCAPS_MIPFLINEAR
| D3DPTFILTERCAPS_MAGFPOINT
| D3DPTFILTERCAPS_MAGFLINEAR
9085 | D3DPTFILTERCAPS_MAGFANISOTROPIC
| D3DPTFILTERCAPS_MAGFAFLATCUBIC
9086 | D3DPTFILTERCAPS_MAGFGAUSSIANCUBIC
)),
9087 "Adapter %u: VolumeTextureFilterCaps field has unexpected flags %#x.\n",
9088 adapter_idx
, caps
.VolumeTextureFilterCaps
);
9089 ok(!(caps
.LineCaps
& ~(D3DLINECAPS_TEXTURE
| D3DLINECAPS_ZTEST
| D3DLINECAPS_BLEND
9090 | D3DLINECAPS_ALPHACMP
| D3DLINECAPS_FOG
)),
9091 "Adapter %u: LineCaps field has unexpected flags %#x.\n", adapter_idx
,
9093 ok(!(caps
.StencilCaps
& ~(D3DSTENCILCAPS_KEEP
| D3DSTENCILCAPS_ZERO
| D3DSTENCILCAPS_REPLACE
9094 | D3DSTENCILCAPS_INCRSAT
| D3DSTENCILCAPS_DECRSAT
| D3DSTENCILCAPS_INVERT
9095 | D3DSTENCILCAPS_INCR
| D3DSTENCILCAPS_DECR
)),
9096 "Adapter %u: StencilCaps field has unexpected flags %#x.\n", adapter_idx
,
9098 ok(!(caps
.VertexProcessingCaps
& ~(D3DVTXPCAPS_TEXGEN
| D3DVTXPCAPS_MATERIALSOURCE7
9099 | D3DVTXPCAPS_DIRECTIONALLIGHTS
| D3DVTXPCAPS_POSITIONALLIGHTS
| D3DVTXPCAPS_LOCALVIEWER
9100 | D3DVTXPCAPS_TWEENING
| D3DVTXPCAPS_NO_VSDT_UBYTE4
)),
9101 "Adapter %u: VertexProcessingCaps field has unexpected flags %#x.\n", adapter_idx
,
9102 caps
.VertexProcessingCaps
);
9103 /* Both Nvidia and AMD give 10 here. */
9104 ok(caps
.MaxActiveLights
<= 10,
9105 "Adapter %u: MaxActiveLights field has unexpected value %u.\n", adapter_idx
,
9106 caps
.MaxActiveLights
);
9107 /* AMD gives 6, Nvidia returns 8. */
9108 ok(caps
.MaxUserClipPlanes
<= 8,
9109 "Adapter %u: MaxUserClipPlanes field has unexpected value %u.\n", adapter_idx
,
9110 caps
.MaxUserClipPlanes
);
9111 ok(caps
.MaxVertexW
== 0.0f
|| caps
.MaxVertexW
>= 1e10f
,
9112 "Adapter %u: MaxVertexW field has unexpected value %.8e.\n", adapter_idx
,
9115 refcount
= IDirect3DDevice8_Release(device
);
9116 ok(!refcount
, "Adapter %u: Device has %u references left.\n", adapter_idx
, refcount
);
9118 IDirect3D8_Release(d3d
);
9119 DestroyWindow(window
);
9122 static void test_get_info(void)
9124 IDirect3DDevice8
*device
;
9132 window
= create_window();
9133 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
9134 ok(!!d3d
, "Failed to create a D3D object.\n");
9135 if (!(device
= create_device(d3d
, window
, NULL
)))
9137 skip("Failed to create a D3D device.\n");
9138 IDirect3D8_Release(d3d
);
9139 DestroyWindow(window
);
9143 /* As called by Chessmaster 9000 (bug 42118). */
9144 hr
= IDirect3DDevice8_GetInfo(device
, 4, info
, 16);
9145 ok(hr
== S_FALSE
, "Unexpected hr %#x.\n", hr
);
9147 for (i
= 0; i
< 256; ++i
)
9149 hr
= IDirect3DDevice8_GetInfo(device
, i
, info
, sizeof(info
));
9151 ok(hr
== (i
< 4 ? E_FAIL
: S_FALSE
), "info_id %u, unexpected hr %#x.\n", i
, hr
);
9153 ok(hr
== E_FAIL
|| hr
== S_FALSE
, "info_id %u, unexpected hr %#x.\n", i
, hr
);
9156 refcount
= IDirect3DDevice8_Release(device
);
9157 ok(!refcount
, "Device has %u references left.\n", refcount
);
9158 IDirect3D8_Release(d3d
);
9159 DestroyWindow(window
);
9162 static void test_resource_access(void)
9164 IDirect3DSurface8
*backbuffer
, *depth_stencil
;
9165 D3DFORMAT colour_format
, depth_format
, format
;
9166 BOOL depth_2d
, depth_cube
, depth_plain
;
9167 D3DADAPTER_IDENTIFIER8 identifier
;
9168 struct device_desc device_desc
;
9169 D3DSURFACE_DESC surface_desc
;
9170 IDirect3DDevice8
*device
;
9187 enum resource_format
9197 enum resource_format format
;
9204 {D3DPOOL_DEFAULT
, FORMAT_COLOUR
, 0, TRUE
},
9205 {D3DPOOL_DEFAULT
, FORMAT_ATI2
, 0, TRUE
},
9206 {D3DPOOL_DEFAULT
, FORMAT_DEPTH
, 0, TRUE
},
9207 {D3DPOOL_DEFAULT
, FORMAT_COLOUR
, D3DUSAGE_RENDERTARGET
, TRUE
},
9208 {D3DPOOL_DEFAULT
, FORMAT_DEPTH
, D3DUSAGE_RENDERTARGET
, FALSE
},
9209 {D3DPOOL_DEFAULT
, FORMAT_COLOUR
, D3DUSAGE_DEPTHSTENCIL
, FALSE
},
9210 {D3DPOOL_DEFAULT
, FORMAT_DEPTH
, D3DUSAGE_DEPTHSTENCIL
, TRUE
},
9212 {D3DPOOL_DEFAULT
, FORMAT_COLOUR
, D3DUSAGE_DYNAMIC
, TRUE
},
9213 {D3DPOOL_DEFAULT
, FORMAT_ATI2
, D3DUSAGE_DYNAMIC
, TRUE
},
9214 {D3DPOOL_DEFAULT
, FORMAT_DEPTH
, D3DUSAGE_DYNAMIC
, TRUE
},
9215 {D3DPOOL_DEFAULT
, FORMAT_COLOUR
, D3DUSAGE_DYNAMIC
| D3DUSAGE_RENDERTARGET
, FALSE
},
9216 {D3DPOOL_DEFAULT
, FORMAT_DEPTH
, D3DUSAGE_DYNAMIC
| D3DUSAGE_RENDERTARGET
, FALSE
},
9217 {D3DPOOL_DEFAULT
, FORMAT_COLOUR
, D3DUSAGE_DYNAMIC
| D3DUSAGE_DEPTHSTENCIL
, FALSE
},
9218 {D3DPOOL_DEFAULT
, FORMAT_DEPTH
, D3DUSAGE_DYNAMIC
| D3DUSAGE_DEPTHSTENCIL
, FALSE
},
9220 {D3DPOOL_MANAGED
, FORMAT_COLOUR
, 0, TRUE
},
9221 {D3DPOOL_MANAGED
, FORMAT_ATI2
, 0, TRUE
},
9222 {D3DPOOL_MANAGED
, FORMAT_DEPTH
, 0, FALSE
},
9223 {D3DPOOL_MANAGED
, FORMAT_COLOUR
, D3DUSAGE_RENDERTARGET
, FALSE
},
9224 {D3DPOOL_MANAGED
, FORMAT_DEPTH
, D3DUSAGE_RENDERTARGET
, FALSE
},
9225 {D3DPOOL_MANAGED
, FORMAT_COLOUR
, D3DUSAGE_DEPTHSTENCIL
, FALSE
},
9226 {D3DPOOL_MANAGED
, FORMAT_DEPTH
, D3DUSAGE_DEPTHSTENCIL
, FALSE
},
9228 {D3DPOOL_SYSTEMMEM
, FORMAT_COLOUR
, 0, TRUE
},
9229 {D3DPOOL_SYSTEMMEM
, FORMAT_ATI2
, 0, TRUE
},
9230 {D3DPOOL_SYSTEMMEM
, FORMAT_DEPTH
, 0, FALSE
},
9231 {D3DPOOL_SYSTEMMEM
, FORMAT_COLOUR
, D3DUSAGE_RENDERTARGET
, FALSE
},
9232 {D3DPOOL_SYSTEMMEM
, FORMAT_DEPTH
, D3DUSAGE_RENDERTARGET
, FALSE
},
9233 {D3DPOOL_SYSTEMMEM
, FORMAT_COLOUR
, D3DUSAGE_DEPTHSTENCIL
, FALSE
},
9234 {D3DPOOL_SYSTEMMEM
, FORMAT_DEPTH
, D3DUSAGE_DEPTHSTENCIL
, FALSE
},
9236 {D3DPOOL_SCRATCH
, FORMAT_COLOUR
, 0, TRUE
},
9237 {D3DPOOL_SCRATCH
, FORMAT_ATI2
, 0, TRUE
},
9238 {D3DPOOL_SCRATCH
, FORMAT_DEPTH
, 0, FALSE
},
9239 {D3DPOOL_SCRATCH
, FORMAT_COLOUR
, D3DUSAGE_RENDERTARGET
, FALSE
},
9240 {D3DPOOL_SCRATCH
, FORMAT_DEPTH
, D3DUSAGE_RENDERTARGET
, FALSE
},
9241 {D3DPOOL_SCRATCH
, FORMAT_COLOUR
, D3DUSAGE_DEPTHSTENCIL
, FALSE
},
9242 {D3DPOOL_SCRATCH
, FORMAT_DEPTH
, D3DUSAGE_DEPTHSTENCIL
, FALSE
},
9247 enum surface_type type
;
9252 {"CUBE", SURFACE_CUBE
},
9255 {"IMAGE", SURFACE_IMAGE
},
9258 window
= create_window();
9259 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
9260 ok(!!d3d
, "Failed to create a D3D object.\n");
9261 hr
= IDirect3D8_GetAdapterIdentifier(d3d
, D3DADAPTER_DEFAULT
, 0, &identifier
);
9262 ok(SUCCEEDED(hr
), "Failed to get adapter identifier, hr %#x.\n", hr
);
9263 warp
= adapter_is_warp(&identifier
);
9265 device_desc
.adapter_ordinal
= D3DADAPTER_DEFAULT
;
9266 device_desc
.device_window
= window
;
9267 device_desc
.width
= 16;
9268 device_desc
.height
= 16;
9269 device_desc
.flags
= 0;
9270 if (!(device
= create_device(d3d
, window
, &device_desc
)))
9272 skip("Failed to create a D3D device.\n");
9273 IDirect3D8_Release(d3d
);
9274 DestroyWindow(window
);
9278 hr
= IDirect3DDevice8_GetBackBuffer(device
, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
9279 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
9280 hr
= IDirect3DSurface8_GetDesc(backbuffer
, &surface_desc
);
9281 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
9282 colour_format
= surface_desc
.Format
;
9284 hr
= IDirect3DDevice8_GetDepthStencilSurface(device
, &depth_stencil
);
9285 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
9286 hr
= IDirect3DSurface8_GetDesc(depth_stencil
, &surface_desc
);
9287 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
9288 depth_format
= surface_desc
.Format
;
9290 depth_2d
= SUCCEEDED(IDirect3D8_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
9291 D3DFMT_X8R8G8B8
, 0, D3DRTYPE_TEXTURE
, depth_format
));
9292 depth_cube
= SUCCEEDED(IDirect3D8_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
9293 D3DFMT_X8R8G8B8
, 0, D3DRTYPE_CUBETEXTURE
, depth_format
));
9294 depth_plain
= SUCCEEDED(IDirect3D8_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
9295 D3DFMT_X8R8G8B8
, 0, D3DRTYPE_SURFACE
, depth_format
));
9297 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZRHW
);
9298 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
9300 for (i
= 0; i
< ARRAY_SIZE(surface_types
); ++i
)
9302 for (j
= 0; j
< ARRAY_SIZE(tests
); ++j
)
9304 IDirect3DCubeTexture8
*texture_cube
;
9305 IDirect3DBaseTexture8
*texture
;
9306 IDirect3DTexture8
*texture_2d
;
9307 IDirect3DSurface8
*surface
;
9308 HRESULT expected_hr
;
9311 if (tests
[j
].format
== FORMAT_ATI2
)
9312 format
= MAKEFOURCC('A','T','I','2');
9313 else if (tests
[j
].format
== FORMAT_DEPTH
)
9314 format
= depth_format
;
9316 format
= colour_format
;
9318 if (tests
[j
].format
== FORMAT_ATI2
&& FAILED(IDirect3D8_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
,
9319 D3DDEVTYPE_HAL
, D3DFMT_X8R8G8B8
, 0, D3DRTYPE_TEXTURE
, format
)))
9321 skip("ATI2N texture not supported.\n");
9325 switch (surface_types
[i
].type
)
9328 hr
= IDirect3DDevice8_CreateTexture(device
, 16, 16, 1,
9329 tests
[j
].usage
, format
, tests
[j
].pool
, &texture_2d
);
9330 todo_wine_if(!tests
[j
].valid
&& tests
[j
].format
== FORMAT_DEPTH
&& !tests
[j
].usage
)
9331 ok(hr
== (tests
[j
].valid
&& (tests
[j
].format
!= FORMAT_DEPTH
|| depth_2d
)
9332 ? D3D_OK
: D3DERR_INVALIDCALL
),
9333 "Test %s %u: Got unexpected hr %#x.\n", surface_types
[i
].name
, j
, hr
);
9337 hr
= IDirect3DTexture8_GetSurfaceLevel(texture_2d
, 0, &surface
);
9338 ok(hr
== D3D_OK
, "Test %s %u: Got unexpected hr %#x.\n", surface_types
[i
].name
, j
, hr
);
9339 IDirect3DTexture8_Release(texture_2d
);
9343 hr
= IDirect3DDevice8_CreateCubeTexture(device
, 16, 1,
9344 tests
[j
].usage
, format
, tests
[j
].pool
, &texture_cube
);
9345 todo_wine_if(!tests
[j
].valid
&& tests
[j
].format
== FORMAT_DEPTH
&& !tests
[j
].usage
)
9346 ok(hr
== (tests
[j
].valid
&& (tests
[j
].format
!= FORMAT_DEPTH
|| depth_cube
)
9347 ? D3D_OK
: D3DERR_INVALIDCALL
),
9348 "Test %s %u: Got unexpected hr %#x.\n", surface_types
[i
].name
, j
, hr
);
9352 hr
= IDirect3DCubeTexture8_GetCubeMapSurface(texture_cube
,
9353 D3DCUBEMAP_FACE_POSITIVE_X
, 0, &surface
);
9354 ok(hr
== D3D_OK
, "Test %s %u: Got unexpected hr %#x.\n", surface_types
[i
].name
, j
, hr
);
9355 IDirect3DCubeTexture8_Release(texture_cube
);
9359 hr
= IDirect3DDevice8_CreateRenderTarget(device
, 16, 16, format
,
9360 D3DMULTISAMPLE_NONE
, tests
[j
].usage
& D3DUSAGE_DYNAMIC
, &surface
);
9361 ok(hr
== (tests
[j
].format
== FORMAT_COLOUR
? D3D_OK
: D3DERR_INVALIDCALL
),
9362 "Test %s %u: Got unexpected hr %#x.\n", surface_types
[i
].name
, j
, hr
);
9368 hr
= IDirect3DDevice8_CreateDepthStencilSurface(device
,
9369 16, 16, format
, D3DMULTISAMPLE_NONE
, &surface
);
9370 todo_wine_if(tests
[j
].format
== FORMAT_ATI2
)
9371 ok(hr
== (tests
[j
].format
== FORMAT_DEPTH
? D3D_OK
9372 : tests
[j
].format
== FORMAT_COLOUR
? D3DERR_INVALIDCALL
: E_INVALIDARG
)
9373 || (tests
[j
].format
== FORMAT_ATI2
&& hr
== D3D_OK
),
9374 "Test %s %u: Got unexpected hr %#x.\n", surface_types
[i
].name
, j
, hr
);
9380 hr
= IDirect3DDevice8_CreateImageSurface(device
, 16, 16, format
, &surface
);
9381 ok(hr
== ((tests
[j
].format
!= FORMAT_DEPTH
|| depth_plain
) ? D3D_OK
: D3DERR_INVALIDCALL
),
9382 "Test %s %u: Got unexpected hr %#x.\n", surface_types
[i
].name
, j
, hr
);
9388 ok(0, "Invalid surface type %#x.\n", surface_types
[i
].type
);
9392 hr
= IDirect3DSurface8_GetDesc(surface
, &surface_desc
);
9393 ok(hr
== D3D_OK
, "Test %s %u: Got unexpected hr %#x.\n", surface_types
[i
].name
, j
, hr
);
9394 if (surface_types
[i
].type
== SURFACE_RT
)
9396 ok(surface_desc
.Usage
== D3DUSAGE_RENDERTARGET
, "Test %s %u: Got unexpected usage %#x.\n",
9397 surface_types
[i
].name
, j
, surface_desc
.Usage
);
9398 ok(surface_desc
.Pool
== D3DPOOL_DEFAULT
, "Test %s %u: Got unexpected pool %#x.\n",
9399 surface_types
[i
].name
, j
, surface_desc
.Pool
);
9401 else if (surface_types
[i
].type
== SURFACE_DS
)
9403 ok(surface_desc
.Usage
== D3DUSAGE_DEPTHSTENCIL
, "Test %s %u: Got unexpected usage %#x.\n",
9404 surface_types
[i
].name
, j
, surface_desc
.Usage
);
9405 ok(surface_desc
.Pool
== D3DPOOL_DEFAULT
, "Test %s %u: Got unexpected pool %#x.\n",
9406 surface_types
[i
].name
, j
, surface_desc
.Pool
);
9408 else if (surface_types
[i
].type
== SURFACE_IMAGE
)
9410 ok(!surface_desc
.Usage
, "Test %s %u: Got unexpected usage %#x.\n",
9411 surface_types
[i
].name
, j
, surface_desc
.Usage
);
9412 ok(surface_desc
.Pool
== D3DPOOL_SYSTEMMEM
, "Test %s %u: Got unexpected pool %#x.\n",
9413 surface_types
[i
].name
, j
, surface_desc
.Pool
);
9417 ok(surface_desc
.Usage
== tests
[j
].usage
, "Test %s %u: Got unexpected usage %#x.\n",
9418 surface_types
[i
].name
, j
, surface_desc
.Usage
);
9419 ok(surface_desc
.Pool
== tests
[j
].pool
, "Test %s %u: Got unexpected pool %#x.\n",
9420 surface_types
[i
].name
, j
, surface_desc
.Pool
);
9423 hr
= IDirect3DSurface8_LockRect(surface
, &lr
, NULL
, 0);
9424 if (surface_desc
.Pool
!= D3DPOOL_DEFAULT
|| surface_desc
.Usage
& D3DUSAGE_DYNAMIC
9425 || (surface_types
[i
].type
== SURFACE_RT
&& tests
[j
].usage
& D3DUSAGE_DYNAMIC
)
9426 || surface_types
[i
].type
== SURFACE_IMAGE
9427 || tests
[j
].format
== FORMAT_ATI2
)
9428 expected_hr
= D3D_OK
;
9430 expected_hr
= D3DERR_INVALIDCALL
;
9431 ok(hr
== expected_hr
, "Test %s %u: Got unexpected hr %#x.\n", surface_types
[i
].name
, j
, hr
);
9432 hr
= IDirect3DSurface8_UnlockRect(surface
);
9433 todo_wine_if(expected_hr
!= D3D_OK
&& surface_types
[i
].type
== SURFACE_2D
)
9434 ok(hr
== expected_hr
, "Test %s %u: Got unexpected hr %#x.\n", surface_types
[i
].name
, j
, hr
);
9436 if (SUCCEEDED(IDirect3DSurface8_GetContainer(surface
, &IID_IDirect3DBaseTexture8
, (void **)&texture
)))
9438 hr
= IDirect3DDevice8_SetTexture(device
, 0, texture
);
9439 ok(hr
== D3D_OK
, "Test %s %u: Got unexpected hr %#x.\n", surface_types
[i
].name
, j
, hr
);
9440 hr
= IDirect3DDevice8_SetTexture(device
, 0, NULL
);
9441 ok(hr
== D3D_OK
, "Test %s %u: Got unexpected hr %#x.\n", surface_types
[i
].name
, j
, hr
);
9442 IDirect3DBaseTexture8_Release(texture
);
9445 hr
= IDirect3DDevice8_SetRenderTarget(device
, surface
, depth_stencil
);
9446 ok(hr
== (surface_desc
.Usage
& D3DUSAGE_RENDERTARGET
? D3D_OK
: D3DERR_INVALIDCALL
),
9447 "Test %s %u: Got unexpected hr %#x.\n", surface_types
[i
].name
, j
, hr
);
9448 hr
= IDirect3DDevice8_SetRenderTarget(device
, backbuffer
, depth_stencil
);
9449 ok(hr
== D3D_OK
, "Test %s %u: Got unexpected hr %#x.\n", surface_types
[i
].name
, j
, hr
);
9451 hr
= IDirect3DDevice8_SetRenderTarget(device
, backbuffer
, surface
);
9452 ok(hr
== (surface_desc
.Usage
& D3DUSAGE_DEPTHSTENCIL
? D3D_OK
: D3DERR_INVALIDCALL
),
9453 "Test %s %u: Got unexpected hr %#x.\n", surface_types
[i
].name
, j
, hr
);
9454 hr
= IDirect3DDevice8_SetRenderTarget(device
, backbuffer
, depth_stencil
);
9455 ok(hr
== D3D_OK
, "Test %s %u: Got unexpected hr %#x.\n", surface_types
[i
].name
, j
, hr
);
9457 IDirect3DSurface8_Release(surface
);
9461 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
)
9463 IDirect3DVolumeTexture8
*texture
;
9464 D3DVOLUME_DESC volume_desc
;
9465 IDirect3DVolume8
*volume
;
9466 HRESULT expected_hr
;
9469 if (tests
[i
].format
== FORMAT_DEPTH
)
9472 if (tests
[i
].format
== FORMAT_ATI2
)
9473 format
= MAKEFOURCC('A','T','I','2');
9475 format
= colour_format
;
9477 hr
= IDirect3DDevice8_CreateVolumeTexture(device
, 16, 16, 1, 1,
9478 tests
[i
].usage
, format
, tests
[i
].pool
, &texture
);
9479 ok((hr
== ((!(tests
[i
].usage
& ~D3DUSAGE_DYNAMIC
) && tests
[i
].format
!= FORMAT_ATI2
)
9480 || (tests
[i
].pool
== D3DPOOL_SCRATCH
&& !tests
[i
].usage
)
9481 ? D3D_OK
: D3DERR_INVALIDCALL
))
9482 || (tests
[i
].format
== FORMAT_ATI2
&& (hr
== D3D_OK
|| warp
)),
9483 "Test %u: Got unexpected hr %#x.\n", i
, hr
);
9487 hr
= IDirect3DVolumeTexture8_GetVolumeLevel(texture
, 0, &volume
);
9488 ok(hr
== D3D_OK
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
9490 hr
= IDirect3DVolume8_GetDesc(volume
, &volume_desc
);
9491 ok(hr
== D3D_OK
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
9492 ok(volume_desc
.Usage
== tests
[i
].usage
, "Test %u: Got unexpected usage %#x.\n", i
, volume_desc
.Usage
);
9493 ok(volume_desc
.Pool
== tests
[i
].pool
, "Test %u: Got unexpected pool %#x.\n", i
, volume_desc
.Pool
);
9495 hr
= IDirect3DVolume8_LockBox(volume
, &lb
, NULL
, 0);
9496 if (volume_desc
.Pool
!= D3DPOOL_DEFAULT
|| volume_desc
.Usage
& D3DUSAGE_DYNAMIC
)
9497 expected_hr
= D3D_OK
;
9499 expected_hr
= D3DERR_INVALIDCALL
;
9500 ok(hr
== expected_hr
|| (volume_desc
.Pool
== D3DPOOL_DEFAULT
&& hr
== D3D_OK
),
9501 "Test %u: Got unexpected hr %#x.\n", i
, hr
);
9502 hr
= IDirect3DVolume8_UnlockBox(volume
);
9503 ok(hr
== expected_hr
|| (volume_desc
.Pool
== D3DPOOL_DEFAULT
&& hr
== D3D_OK
),
9504 "Test %u: Got unexpected hr %#x.\n", i
, hr
);
9506 hr
= IDirect3DDevice8_SetTexture(device
, 0, (IDirect3DBaseTexture8
*)texture
);
9507 ok(hr
== D3D_OK
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
9508 hr
= IDirect3DDevice8_SetTexture(device
, 0, NULL
);
9509 ok(hr
== D3D_OK
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
9511 IDirect3DVolume8_Release(volume
);
9512 IDirect3DVolumeTexture8_Release(texture
);
9515 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
)
9517 D3DINDEXBUFFER_DESC ib_desc
;
9518 IDirect3DIndexBuffer8
*ib
;
9521 hr
= IDirect3DDevice8_CreateIndexBuffer(device
, 16, tests
[i
].usage
,
9522 tests
[i
].format
== FORMAT_COLOUR
? D3DFMT_INDEX32
: D3DFMT_INDEX16
, tests
[i
].pool
, &ib
);
9523 ok(hr
== (tests
[i
].pool
== D3DPOOL_SCRATCH
|| (tests
[i
].usage
& ~D3DUSAGE_DYNAMIC
)
9524 ? D3DERR_INVALIDCALL
: D3D_OK
), "Test %u: Got unexpected hr %#x.\n", i
, hr
);
9528 hr
= IDirect3DIndexBuffer8_GetDesc(ib
, &ib_desc
);
9529 ok(hr
== D3D_OK
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
9530 ok(ib_desc
.Usage
== tests
[i
].usage
, "Test %u: Got unexpected usage %#x.\n", i
, ib_desc
.Usage
);
9531 ok(ib_desc
.Pool
== tests
[i
].pool
, "Test %u: Got unexpected pool %#x.\n", i
, ib_desc
.Pool
);
9533 hr
= IDirect3DIndexBuffer8_Lock(ib
, 0, 0, &data
, 0);
9534 ok(hr
== D3D_OK
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
9535 hr
= IDirect3DIndexBuffer8_Unlock(ib
);
9536 ok(hr
== D3D_OK
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
9538 hr
= IDirect3DDevice8_SetIndices(device
, ib
, 0);
9539 ok(hr
== D3D_OK
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
9540 hr
= IDirect3DDevice8_SetIndices(device
, NULL
, 0);
9541 ok(hr
== D3D_OK
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
9543 IDirect3DIndexBuffer8_Release(ib
);
9546 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
)
9548 D3DVERTEXBUFFER_DESC vb_desc
;
9549 IDirect3DVertexBuffer8
*vb
;
9552 hr
= IDirect3DDevice8_CreateVertexBuffer(device
, 16, tests
[i
].usage
,
9553 tests
[i
].format
== FORMAT_COLOUR
? 0 : D3DFVF_XYZRHW
, tests
[i
].pool
, &vb
);
9554 ok(hr
== (tests
[i
].pool
== D3DPOOL_SCRATCH
|| (tests
[i
].usage
& ~D3DUSAGE_DYNAMIC
)
9555 ? D3DERR_INVALIDCALL
: D3D_OK
), "Test %u: Got unexpected hr %#x.\n", i
, hr
);
9559 hr
= IDirect3DVertexBuffer8_GetDesc(vb
, &vb_desc
);
9560 ok(hr
== D3D_OK
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
9561 ok(vb_desc
.Usage
== tests
[i
].usage
, "Test %u: Got unexpected usage %#x.\n", i
, vb_desc
.Usage
);
9562 ok(vb_desc
.Pool
== tests
[i
].pool
, "Test %u: Got unexpected pool %#x.\n", i
, vb_desc
.Pool
);
9564 hr
= IDirect3DVertexBuffer8_Lock(vb
, 0, 0, &data
, 0);
9565 ok(hr
== D3D_OK
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
9566 hr
= IDirect3DVertexBuffer8_Unlock(vb
);
9567 ok(hr
== D3D_OK
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
9569 hr
= IDirect3DDevice8_SetStreamSource(device
, 0, vb
, 16);
9570 ok(hr
== D3D_OK
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
9571 hr
= IDirect3DDevice8_SetStreamSource(device
, 0, NULL
, 0);
9572 ok(hr
== D3D_OK
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
9574 IDirect3DVertexBuffer8_Release(vb
);
9577 IDirect3DSurface8_Release(depth_stencil
);
9578 IDirect3DSurface8_Release(backbuffer
);
9579 refcount
= IDirect3DDevice8_Release(device
);
9580 ok(!refcount
, "Device has %u references left.\n", refcount
);
9581 IDirect3D8_Release(d3d
);
9582 DestroyWindow(window
);
9585 static void test_multiply_transform(void)
9587 IDirect3DDevice8
*device
;
9596 static const D3DTRANSFORMSTATETYPE tests
[] =
9608 D3DTS_WORLDMATRIX(0),
9609 D3DTS_WORLDMATRIX(1),
9610 D3DTS_WORLDMATRIX(2),
9611 D3DTS_WORLDMATRIX(3),
9612 D3DTS_WORLDMATRIX(255),
9615 static const D3DMATRIX mat1
=
9617 1.0f
, 0.0f
, 0.0f
, 0.0f
,
9618 0.0f
, 1.0f
, 0.0f
, 0.0f
,
9619 0.0f
, 0.0f
, 1.0f
, 0.0f
,
9620 0.0f
, 0.0f
, 0.0f
, 1.0f
,
9624 2.0f
, 0.0f
, 0.0f
, 0.0f
,
9625 0.0f
, 2.0f
, 0.0f
, 0.0f
,
9626 0.0f
, 0.0f
, 2.0f
, 0.0f
,
9627 0.0f
, 0.0f
, 0.0f
, 2.0f
,
9630 window
= create_window();
9631 ok(!!window
, "Failed to create a window.\n");
9632 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
9633 ok(!!d3d
, "Failed to create D3D object.\n");
9635 if (!(device
= create_device(d3d
, window
, NULL
)))
9637 skip("Failed to create 3D device.\n");
9638 IDirect3D8_Release(d3d
);
9639 DestroyWindow(window
);
9643 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
)
9645 hr
= IDirect3DDevice8_GetTransform(device
, tests
[i
], &ret_mat
);
9646 ok(hr
== D3D_OK
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
9647 ok(!memcmp(&ret_mat
, &mat1
, sizeof(mat1
)), "Test %u: Got unexpected transform matrix.\n", i
);
9649 hr
= IDirect3DDevice8_MultiplyTransform(device
, tests
[i
], &mat2
);
9650 ok(hr
== D3D_OK
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
9652 hr
= IDirect3DDevice8_GetTransform(device
, tests
[i
], &ret_mat
);
9653 ok(hr
== D3D_OK
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
9654 ok(!memcmp(&ret_mat
, &mat2
, sizeof(mat2
)), "Test %u: Got unexpected transform matrix.\n", i
);
9656 /* MultiplyTransform() goes directly into the primary stateblock. */
9658 hr
= IDirect3DDevice8_SetTransform(device
, tests
[i
], &mat1
);
9659 ok(hr
== D3D_OK
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
9661 hr
= IDirect3DDevice8_BeginStateBlock(device
);
9662 ok(hr
== D3D_OK
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
9664 hr
= IDirect3DDevice8_MultiplyTransform(device
, tests
[i
], &mat2
);
9665 ok(hr
== D3D_OK
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
9667 hr
= IDirect3DDevice8_EndStateBlock(device
, &stateblock
);
9668 ok(hr
== D3D_OK
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
9670 hr
= IDirect3DDevice8_GetTransform(device
, tests
[i
], &ret_mat
);
9671 ok(hr
== D3D_OK
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
9672 ok(!memcmp(&ret_mat
, &mat2
, sizeof(mat2
)), "Test %u: Got unexpected transform matrix.\n", i
);
9674 hr
= IDirect3DDevice8_CaptureStateBlock(device
, stateblock
);
9675 ok(hr
== D3D_OK
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
9677 hr
= IDirect3DDevice8_SetTransform(device
, tests
[i
], &mat1
);
9678 ok(hr
== D3D_OK
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
9680 hr
= IDirect3DDevice8_ApplyStateBlock(device
, stateblock
);
9681 ok(hr
== D3D_OK
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
9683 hr
= IDirect3DDevice8_GetTransform(device
, tests
[i
], &ret_mat
);
9684 ok(hr
== D3D_OK
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
9685 ok(!memcmp(&ret_mat
, &mat1
, sizeof(mat1
)), "Test %u: Got unexpected transform matrix.\n", i
);
9687 IDirect3DDevice8_DeleteStateBlock(device
, stateblock
);
9690 refcount
= IDirect3DDevice8_Release(device
);
9691 ok(!refcount
, "Device has %u references left.\n", refcount
);
9692 IDirect3D8_Release(d3d
);
9693 DestroyWindow(window
);
9696 static void test_draw_primitive(void)
9705 {{-1.0f
, -1.0f
, 0.0f
}, 0xffff0000},
9706 {{-1.0f
, 1.0f
, 0.0f
}, 0xffff0000},
9707 {{ 1.0f
, 1.0f
, 0.0f
}, 0xffff0000},
9708 {{ 1.0f
, -1.0f
, 0.0f
}, 0xffff0000},
9709 {{-1.0f
, -1.0f
, 0.0f
}, 0xffff0000},
9711 static const WORD indices
[] = {0, 1, 2, 3, 0, 2};
9713 IDirect3DVertexBuffer8
*vertex_buffer
, *current_vb
;
9714 IDirect3DIndexBuffer8
*index_buffer
, *current_ib
;
9715 UINT stride
, base_vertex_index
;
9716 IDirect3DDevice8
*device
;
9724 window
= create_window();
9725 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
9726 ok(!!d3d
, "Failed to create a D3D object.\n");
9727 if (!(device
= create_device(d3d
, window
, NULL
)))
9729 skip("Failed to create a D3D device.\n");
9730 IDirect3D8_Release(d3d
);
9731 DestroyWindow(window
);
9735 hr
= IDirect3DDevice8_CreateVertexBuffer(device
, sizeof(quad
), 0, 0,
9736 D3DPOOL_DEFAULT
, &vertex_buffer
);
9737 ok(SUCCEEDED(hr
), "CreateVertexBuffer failed, hr %#x.\n", hr
);
9738 hr
= IDirect3DVertexBuffer8_Lock(vertex_buffer
, 0, 0, &ptr
, D3DLOCK_DISCARD
);
9739 ok(SUCCEEDED(hr
), "Lock failed, hr %#x.\n", hr
);
9740 memcpy(ptr
, quad
, sizeof(quad
));
9741 hr
= IDirect3DVertexBuffer8_Unlock(vertex_buffer
);
9742 ok(SUCCEEDED(hr
), "Unlock failed, hr %#x.\n", hr
);
9743 hr
= IDirect3DDevice8_SetStreamSource(device
, 0, vertex_buffer
, sizeof(*quad
));
9744 ok(SUCCEEDED(hr
), "SetStreamSource failed, hr %#x.\n", hr
);
9745 hr
= IDirect3DDevice8_SetVertexShader(device
, D3DFVF_XYZ
| D3DFVF_DIFFUSE
);
9746 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
9748 hr
= IDirect3DDevice8_CreateIndexBuffer(device
, sizeof(indices
), 0, D3DFMT_INDEX16
,
9749 D3DPOOL_DEFAULT
, &index_buffer
);
9750 ok(SUCCEEDED(hr
), "CreateIndexBuffer failed, hr %#x.\n", hr
);
9751 hr
= IDirect3DIndexBuffer8_Lock(index_buffer
, 0, 0, &ptr
, D3DLOCK_DISCARD
);
9752 ok(SUCCEEDED(hr
), "Lock failed, hr %#x.\n", hr
);
9753 memcpy(ptr
, indices
, sizeof(indices
));
9754 hr
= IDirect3DIndexBuffer8_Unlock(index_buffer
);
9755 ok(SUCCEEDED(hr
), "Unlock failed, hr %#x.\n", hr
);
9757 hr
= IDirect3DDevice8_SetRenderState(device
, D3DRS_LIGHTING
, FALSE
);
9758 ok(SUCCEEDED(hr
), "SetRenderState D3DRS_LIGHTING failed, hr %#x.\n", hr
);
9760 hr
= IDirect3DDevice8_BeginScene(device
);
9761 ok(SUCCEEDED(hr
), "BeginScene failed, hr %#x.\n", hr
);
9763 hr
= IDirect3DDevice8_DrawPrimitive(device
, D3DPT_TRIANGLELIST
, 0, 2);
9764 ok(SUCCEEDED(hr
), "DrawPrimitive failed, hr %#x.\n", hr
);
9766 hr
= IDirect3DDevice8_GetStreamSource(device
, 0, ¤t_vb
, &stride
);
9767 ok(SUCCEEDED(hr
), "GetStreamSource failed, hr %#x.\n", hr
);
9768 ok(current_vb
== vertex_buffer
, "Unexpected vb %p.\n", current_vb
);
9769 ok(stride
== sizeof(*quad
), "Unexpected stride %u.\n", stride
);
9770 IDirect3DVertexBuffer8_Release(current_vb
);
9772 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0, quad
, 0);
9773 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed, hr %#x.\n", hr
);
9774 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0, quad
, sizeof(*quad
));
9775 ok(hr
== D3D_OK
, "DrawPrimitiveUP failed, hr %#x.\n", hr
);
9777 hr
= IDirect3DDevice8_DrawPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 2, quad
, sizeof(*quad
));
9778 ok(SUCCEEDED(hr
), "DrawPrimitiveUP failed, hr %#x.\n", hr
);
9780 hr
= IDirect3DDevice8_GetStreamSource(device
, 0, ¤t_vb
, &stride
);
9781 ok(SUCCEEDED(hr
), "GetStreamSource failed, hr %#x.\n", hr
);
9782 ok(!current_vb
, "Unexpected vb %p.\n", current_vb
);
9783 ok(!stride
, "Unexpected stride %u.\n", stride
);
9785 /* NULL index buffer, NULL stream source. */
9786 hr
= IDirect3DDevice8_SetIndices(device
, NULL
, 0);
9787 ok(SUCCEEDED(hr
), "SetIndices failed, hr %#x.\n", hr
);
9788 hr
= IDirect3DDevice8_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, 0, 4, 0, 2);
9789 todo_wine
ok(SUCCEEDED(hr
), "DrawIndexedPrimitive failed, hr %#x.\n", hr
);
9791 /* Valid index buffer, NULL stream source. */
9792 hr
= IDirect3DDevice8_SetIndices(device
, index_buffer
, 1);
9793 ok(SUCCEEDED(hr
), "SetIndices failed, hr %#x.\n", hr
);
9794 hr
= IDirect3DDevice8_DrawIndexedPrimitive(device
, D3DPT_TRIANGLELIST
, 0, 4, 0, 2);
9795 ok(SUCCEEDED(hr
), "DrawIndexedPrimitive failed, hr %#x.\n", hr
);
9797 hr
= IDirect3DDevice8_GetIndices(device
, ¤t_ib
, &base_vertex_index
);
9798 ok(SUCCEEDED(hr
), "GetIndices failed, hr %#x.\n", hr
);
9799 ok(current_ib
== index_buffer
, "Unexpected index buffer %p.\n", current_ib
);
9800 ok(base_vertex_index
== 1, "Unexpected base vertex index %u.\n", base_vertex_index
);
9801 IDirect3DIndexBuffer8_Release(current_ib
);
9803 hr
= IDirect3DDevice8_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0, 4, 0,
9804 indices
, D3DFMT_INDEX16
, quad
, 0);
9805 ok(SUCCEEDED(hr
), "DrawIndexedPrimitiveUP failed, hr %#x.\n", hr
);
9806 hr
= IDirect3DDevice8_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0, 4, 2,
9807 indices
, D3DFMT_INDEX16
, quad
, 0);
9808 ok(SUCCEEDED(hr
), "DrawIndexedPrimitiveUP failed, hr %#x.\n", hr
);
9810 hr
= IDirect3DDevice8_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0, 4, 2,
9811 indices
, D3DFMT_INDEX16
, quad
, sizeof(*quad
));
9812 ok(SUCCEEDED(hr
), "DrawIndexedPrimitiveUP failed, hr %#x.\n", hr
);
9814 hr
= IDirect3DDevice8_GetIndices(device
, ¤t_ib
, &base_vertex_index
);
9815 ok(SUCCEEDED(hr
), "GetIndices failed, hr %#x.\n", hr
);
9816 ok(!current_ib
, "Unexpected index buffer %p.\n", current_ib
);
9817 ok(!base_vertex_index
, "Unexpected base vertex index %u.\n", base_vertex_index
);
9819 /* Resetting of stream source and index buffer is not recorded in stateblocks. */
9821 hr
= IDirect3DDevice8_SetStreamSource(device
, 0, vertex_buffer
, sizeof(*quad
));
9822 ok(SUCCEEDED(hr
), "SetStreamSource failed, hr %#x.\n", hr
);
9823 hr
= IDirect3DDevice8_SetIndices(device
, index_buffer
, 1);
9824 ok(SUCCEEDED(hr
), "SetIndices failed, hr %#x.\n", hr
);
9826 hr
= IDirect3DDevice8_BeginStateBlock(device
);
9827 ok(SUCCEEDED(hr
), "BeginStateBlock failed, hr %#x.\n", hr
);
9829 hr
= IDirect3DDevice8_DrawIndexedPrimitiveUP(device
, D3DPT_TRIANGLELIST
, 0, 4, 2,
9830 indices
, D3DFMT_INDEX16
, quad
, sizeof(*quad
));
9831 ok(SUCCEEDED(hr
), "DrawIndexedPrimitiveUP failed, hr %#x.\n", hr
);
9833 hr
= IDirect3DDevice8_EndStateBlock(device
, &stateblock
);
9834 ok(SUCCEEDED(hr
), "BeginStateBlock failed, hr %#x.\n", hr
);
9836 hr
= IDirect3DDevice8_GetStreamSource(device
, 0, ¤t_vb
, &stride
);
9837 ok(SUCCEEDED(hr
), "GetStreamSource failed, hr %#x.\n", hr
);
9838 ok(!current_vb
, "Unexpected vb %p.\n", current_vb
);
9839 ok(!stride
, "Unexpected stride %u.\n", stride
);
9840 hr
= IDirect3DDevice8_GetIndices(device
, ¤t_ib
, &base_vertex_index
);
9841 ok(SUCCEEDED(hr
), "GetIndices failed, hr %#x.\n", hr
);
9842 ok(!current_ib
, "Unexpected index buffer %p.\n", current_ib
);
9843 ok(!base_vertex_index
, "Unexpected base vertex index %u.\n", base_vertex_index
);
9845 hr
= IDirect3DDevice8_CaptureStateBlock(device
, stateblock
);
9846 ok(SUCCEEDED(hr
), "Capture failed, hr %#x.\n", hr
);
9848 hr
= IDirect3DDevice8_SetStreamSource(device
, 0, vertex_buffer
, sizeof(*quad
));
9849 ok(SUCCEEDED(hr
), "SetStreamSource failed, hr %#x.\n", hr
);
9850 hr
= IDirect3DDevice8_SetIndices(device
, index_buffer
, 1);
9851 ok(SUCCEEDED(hr
), "SetIndices failed, hr %#x.\n", hr
);
9853 hr
= IDirect3DDevice8_ApplyStateBlock(device
, stateblock
);
9854 ok(SUCCEEDED(hr
), "Apply failed, hr %#x.\n", hr
);
9856 hr
= IDirect3DDevice8_GetStreamSource(device
, 0, ¤t_vb
, &stride
);
9857 ok(SUCCEEDED(hr
), "GetStreamSource failed, hr %#x.\n", hr
);
9858 ok(current_vb
== vertex_buffer
, "Unexpected vb %p.\n", current_vb
);
9859 ok(stride
== sizeof(*quad
), "Unexpected stride %u.\n", stride
);
9860 IDirect3DVertexBuffer8_Release(current_vb
);
9861 hr
= IDirect3DDevice8_GetIndices(device
, ¤t_ib
, &base_vertex_index
);
9862 ok(SUCCEEDED(hr
), "GetIndices failed, hr %#x.\n", hr
);
9863 ok(current_ib
== index_buffer
, "Unexpected index buffer %p.\n", current_ib
);
9864 ok(base_vertex_index
== 1, "Unexpected base vertex index %u.\n", base_vertex_index
);
9865 IDirect3DIndexBuffer8_Release(current_ib
);
9867 hr
= IDirect3DDevice8_EndScene(device
);
9868 ok(SUCCEEDED(hr
), "EndScene failed, hr %#x.\n", hr
);
9870 hr
= IDirect3DDevice8_Present(device
, NULL
, NULL
, NULL
, NULL
);
9871 ok(SUCCEEDED(hr
), "Present failed, hr %#x.\n", hr
);
9873 IDirect3DDevice8_DeleteStateBlock(device
, stateblock
);
9874 IDirect3DVertexBuffer8_Release(vertex_buffer
);
9875 IDirect3DIndexBuffer8_Release(index_buffer
);
9876 refcount
= IDirect3DDevice8_Release(device
);
9877 ok(!refcount
, "Device has %u references left.\n", refcount
);
9878 IDirect3D8_Release(d3d
);
9879 DestroyWindow(window
);
9882 static void test_get_display_mode(void)
9884 IDirect3DDevice8
*device
;
9885 struct device_desc desc
;
9886 D3DDISPLAYMODE mode
;
9892 window
= create_window();
9893 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
9894 ok(!!d3d
, "Failed to create a D3D object.\n");
9896 if (!(device
= create_device(d3d
, window
, NULL
)))
9898 skip("Failed to create a D3D device.\n");
9899 IDirect3D8_Release(d3d
);
9900 DestroyWindow(window
);
9904 hr
= IDirect3DDevice8_GetDisplayMode(device
, &mode
);
9905 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
9906 ok(mode
.Format
== D3DFMT_X8R8G8B8
, "Unexpected format %#x.\n", mode
.Format
);
9907 hr
= IDirect3D8_GetAdapterDisplayMode(d3d
, D3DADAPTER_DEFAULT
, &mode
);
9908 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
9909 ok(mode
.Format
== D3DFMT_X8R8G8B8
, "Unexpected format %#x.\n", mode
.Format
);
9911 refcount
= IDirect3DDevice8_Release(device
);
9912 ok(!refcount
, "Device has %u references left.\n", refcount
);
9914 desc
.adapter_ordinal
= D3DADAPTER_DEFAULT
;
9915 desc
.device_window
= window
;
9918 desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
9919 if (!(device
= create_device(d3d
, window
, &desc
)))
9921 skip("Failed to create a D3D device.\n");
9922 IDirect3D8_Release(d3d
);
9923 DestroyWindow(window
);
9927 hr
= IDirect3DDevice8_GetDisplayMode(device
, &mode
);
9928 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
9929 ok(mode
.Width
== 640, "Unexpected width %u.\n", mode
.Width
);
9930 ok(mode
.Height
== 480, "Unexpected width %u.\n", mode
.Height
);
9931 ok(mode
.Format
== D3DFMT_X8R8G8B8
, "Unexpected format %#x.\n", mode
.Format
);
9932 hr
= IDirect3D8_GetAdapterDisplayMode(d3d
, D3DADAPTER_DEFAULT
, &mode
);
9933 ok(hr
== D3D_OK
, "Got unexpected hr %#x.\n", hr
);
9934 ok(mode
.Width
== 640, "Unexpected width %u.\n", mode
.Width
);
9935 ok(mode
.Height
== 480, "Unexpected width %u.\n", mode
.Height
);
9936 ok(mode
.Format
== D3DFMT_X8R8G8B8
, "Unexpected format %#x.\n", mode
.Format
);
9938 refcount
= IDirect3DDevice8_Release(device
);
9939 ok(!refcount
, "Device has %u references left.\n", refcount
);
9940 IDirect3D8_Release(d3d
);
9941 DestroyWindow(window
);
9944 static void test_multi_adapter(void)
9946 unsigned int i
, adapter_count
, expected_adapter_count
= 0;
9947 DISPLAY_DEVICEA display_device
;
9948 MONITORINFOEXA monitor_info
;
9949 DEVMODEA old_mode
, mode
;
9954 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
9955 ok(!!d3d
, "Failed to create a D3D object.\n");
9957 display_device
.cb
= sizeof(display_device
);
9958 for (i
= 0; EnumDisplayDevicesA(NULL
, i
, &display_device
, 0); ++i
)
9960 if (display_device
.StateFlags
& DISPLAY_DEVICE_ATTACHED_TO_DESKTOP
)
9961 ++expected_adapter_count
;
9964 adapter_count
= IDirect3D8_GetAdapterCount(d3d
);
9965 todo_wine_if(expected_adapter_count
> 1)
9966 ok(adapter_count
== expected_adapter_count
, "Got unexpected adapter count %u, expected %u.\n",
9967 adapter_count
, expected_adapter_count
);
9969 for (i
= 0; i
< adapter_count
; ++i
)
9971 monitor
= IDirect3D8_GetAdapterMonitor(d3d
, i
);
9972 ok(!!monitor
, "Adapter %u: Failed to get monitor.\n", i
);
9974 monitor_info
.cbSize
= sizeof(monitor_info
);
9975 ok(GetMonitorInfoA(monitor
, (MONITORINFO
*)&monitor_info
),
9976 "Adapter %u: Failed to get monitor info, error %#x.\n", i
, GetLastError());
9979 ok(monitor_info
.dwFlags
== MONITORINFOF_PRIMARY
,
9980 "Adapter %u: Got unexpected monitor flags %#x.\n", i
, monitor_info
.dwFlags
);
9982 ok(!monitor_info
.dwFlags
, "Adapter %u: Got unexpected monitor flags %#x.\n", i
,
9983 monitor_info
.dwFlags
);
9985 /* Test D3D adapters after they got detached */
9986 if (monitor_info
.dwFlags
== MONITORINFOF_PRIMARY
)
9989 /* Save current display settings */
9990 memset(&old_mode
, 0, sizeof(old_mode
));
9991 old_mode
.dmSize
= sizeof(old_mode
);
9992 ret
= EnumDisplaySettingsA(monitor_info
.szDevice
, ENUM_CURRENT_SETTINGS
, &old_mode
);
9993 /* Win10 TestBots may return FALSE but it's actually successful */
9994 ok(ret
|| broken(!ret
), "Adapter %u: EnumDisplaySettingsA failed for %s, error %#x.\n", i
,
9995 monitor_info
.szDevice
, GetLastError());
9998 memset(&mode
, 0, sizeof(mode
));
9999 mode
.dmSize
= sizeof(mode
);
10000 mode
.dmFields
= DM_POSITION
| DM_PELSWIDTH
| DM_PELSHEIGHT
;
10001 mode
.dmPosition
= old_mode
.dmPosition
;
10002 ret
= ChangeDisplaySettingsExA(monitor_info
.szDevice
, &mode
, NULL
,
10003 CDS_UPDATEREGISTRY
| CDS_NORESET
, NULL
);
10004 ok(ret
== DISP_CHANGE_SUCCESSFUL
,
10005 "Adapter %u: ChangeDisplaySettingsExA %s returned unexpected %d.\n", i
,
10006 monitor_info
.szDevice
, ret
);
10007 ret
= ChangeDisplaySettingsExA(monitor_info
.szDevice
, NULL
, NULL
, 0, NULL
);
10008 ok(ret
== DISP_CHANGE_SUCCESSFUL
,
10009 "Adapter %u: ChangeDisplaySettingsExA %s returned unexpected %d.\n", i
,
10010 monitor_info
.szDevice
, ret
);
10012 /* Check if it is really detached */
10013 memset(&mode
, 0, sizeof(mode
));
10014 mode
.dmSize
= sizeof(mode
);
10015 ret
= EnumDisplaySettingsA(monitor_info
.szDevice
, ENUM_CURRENT_SETTINGS
, &mode
);
10016 /* Win10 TestBots may return FALSE but it's actually successful */
10017 ok(ret
|| broken(!ret
) , "Adapter %u: EnumDisplaySettingsA failed for %s, error %#x.\n", i
,
10018 monitor_info
.szDevice
, GetLastError());
10019 if (mode
.dmPelsWidth
&& mode
.dmPelsHeight
)
10021 skip("Adapter %u: Failed to detach device %s.\n", i
, monitor_info
.szDevice
);
10025 /* Detaching adapter shouldn't reduce the adapter count */
10026 expected_adapter_count
= adapter_count
;
10027 adapter_count
= IDirect3D8_GetAdapterCount(d3d
);
10028 ok(adapter_count
== expected_adapter_count
,
10029 "Adapter %u: Got unexpected adapter count %u, expected %u.\n", i
, adapter_count
,
10030 expected_adapter_count
);
10032 monitor
= IDirect3D8_GetAdapterMonitor(d3d
, i
);
10033 ok(!monitor
, "Adapter %u: Expect monitor to be NULL.\n", i
);
10035 /* Restore settings */
10036 ret
= ChangeDisplaySettingsExA(monitor_info
.szDevice
, &old_mode
, NULL
,
10037 CDS_UPDATEREGISTRY
| CDS_NORESET
, NULL
);
10038 ok(ret
== DISP_CHANGE_SUCCESSFUL
,
10039 "Adapter %u: ChangeDisplaySettingsExA %s returned unexpected %d.\n", i
,
10040 monitor_info
.szDevice
, ret
);
10041 ret
= ChangeDisplaySettingsExA(monitor_info
.szDevice
, NULL
, NULL
, 0, NULL
);
10042 ok(ret
== DISP_CHANGE_SUCCESSFUL
,
10043 "Adapter %u: ChangeDisplaySettingsExA %s returned unexpected %d.\n", i
,
10044 monitor_info
.szDevice
, ret
);
10047 IDirect3D8_Release(d3d
);
10050 static void test_creation_parameters(void)
10052 unsigned int adapter_idx
, adapter_count
;
10053 D3DDEVICE_CREATION_PARAMETERS params
;
10054 struct device_desc device_desc
;
10055 IDirect3DDevice8
*device
;
10060 window
= create_window();
10061 ok(!!window
, "Failed to create a window.\n");
10062 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
10063 ok(!!d3d
, "Failed to create a D3D object.\n");
10065 device_desc
.device_window
= window
;
10066 device_desc
.width
= 640;
10067 device_desc
.height
= 480;
10068 device_desc
.flags
= 0;
10070 adapter_count
= IDirect3D8_GetAdapterCount(d3d
);
10071 for (adapter_idx
= 0; adapter_idx
< adapter_count
; ++adapter_idx
)
10073 device_desc
.adapter_ordinal
= adapter_idx
;
10074 if (!(device
= create_device(d3d
, window
, &device_desc
)))
10076 skip("Adapter %u: Failed to create a D3D device.\n", adapter_idx
);
10080 memset(¶ms
, 0, sizeof(params
));
10081 hr
= IDirect3DDevice8_GetCreationParameters(device
, ¶ms
);
10082 ok(hr
== D3D_OK
, "Adapter %u: GetCreationParameters failed, hr %#x.\n", adapter_idx
, hr
);
10083 ok(params
.AdapterOrdinal
== adapter_idx
, "Adapter %u: Got unexpected adapter ordinal %u.\n",
10084 adapter_idx
, params
.AdapterOrdinal
);
10085 ok(params
.DeviceType
== D3DDEVTYPE_HAL
, "Adapter %u: Expect device type %#x, got %#x.\n",
10086 adapter_idx
, D3DDEVTYPE_HAL
, params
.DeviceType
);
10087 ok(params
.hFocusWindow
== window
, "Adapter %u: Expect focus window %p, got %p.\n",
10088 adapter_idx
, window
, params
.hFocusWindow
);
10090 IDirect3DDevice8_Release(device
);
10093 IDirect3D8_Release(d3d
);
10094 DestroyWindow(window
);
10097 static void test_cursor_clipping(void)
10099 unsigned int adapter_idx
, adapter_count
, mode_idx
;
10100 D3DDISPLAYMODE mode
, current_mode
;
10101 struct device_desc device_desc
;
10102 RECT virtual_rect
, clip_rect
;
10103 IDirect3DDevice8
*device
;
10108 window
= create_window();
10109 ok(!!window
, "Failed to create a window.\n");
10110 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
10111 ok(!!d3d
, "Failed to create a D3D object.\n");
10113 device_desc
.device_window
= window
;
10114 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
10116 adapter_count
= IDirect3D8_GetAdapterCount(d3d
);
10117 for (adapter_idx
= 0; adapter_idx
< adapter_count
; ++adapter_idx
)
10119 hr
= IDirect3D8_GetAdapterDisplayMode(d3d
, adapter_idx
, ¤t_mode
);
10120 ok(hr
== D3D_OK
, "Adapter %u: GetAdapterDisplayMode failed, hr %#x.\n", adapter_idx
, hr
);
10121 for (mode_idx
= 0; SUCCEEDED(IDirect3D8_EnumAdapterModes(d3d
, adapter_idx
, mode_idx
, &mode
));
10124 if (mode
.Format
!= D3DFMT_X8R8G8B8
)
10126 if (mode
.Width
< 640 || mode
.Height
< 480)
10128 if (mode
.Width
!= current_mode
.Width
&& mode
.Height
!= current_mode
.Height
)
10131 ok(mode
.Width
!= current_mode
.Width
&& mode
.Height
!= current_mode
.Height
,
10132 "Adapter %u: Failed to find a different mode than %ux%u.\n", adapter_idx
,
10133 current_mode
.Width
, current_mode
.Height
);
10135 ok(ClipCursor(NULL
), "Adapter %u: ClipCursor failed, error %#x.\n", adapter_idx
,
10137 get_virtual_rect(&virtual_rect
);
10138 ok(GetClipCursor(&clip_rect
), "Adapter %u: GetClipCursor failed, error %#x.\n", adapter_idx
,
10140 ok(EqualRect(&clip_rect
, &virtual_rect
), "Adapter %u: Expect clip rect %s, got %s.\n",
10141 adapter_idx
, wine_dbgstr_rect(&virtual_rect
), wine_dbgstr_rect(&clip_rect
));
10143 device_desc
.adapter_ordinal
= adapter_idx
;
10144 device_desc
.width
= mode
.Width
;
10145 device_desc
.height
= mode
.Height
;
10146 if (!(device
= create_device(d3d
, window
, &device_desc
)))
10148 skip("Adapter %u: Failed to create a D3D device.\n", adapter_idx
);
10152 get_virtual_rect(&virtual_rect
);
10153 ok(GetClipCursor(&clip_rect
), "Adapter %u: GetClipCursor failed, error %#x.\n", adapter_idx
,
10155 ok(EqualRect(&clip_rect
, &virtual_rect
), "Adapter %u: Expect clip rect %s, got %s.\n",
10156 adapter_idx
, wine_dbgstr_rect(&virtual_rect
), wine_dbgstr_rect(&clip_rect
));
10158 IDirect3DDevice8_Release(device
);
10160 get_virtual_rect(&virtual_rect
);
10161 ok(GetClipCursor(&clip_rect
), "Adapter %u: GetClipCursor failed, error %#x.\n", adapter_idx
,
10163 ok(EqualRect(&clip_rect
, &virtual_rect
), "Adapter %u: Expect clip rect %s, got %s.\n",
10164 adapter_idx
, wine_dbgstr_rect(&virtual_rect
), wine_dbgstr_rect(&clip_rect
));
10167 IDirect3D8_Release(d3d
);
10168 DestroyWindow(window
);
10171 static void test_window_position(void)
10173 unsigned int adapter_idx
, adapter_count
;
10174 struct device_desc device_desc
;
10175 IDirect3DDevice8
*device
;
10176 MONITORINFO monitor_info
;
10184 d3d
= Direct3DCreate8(D3D_SDK_VERSION
);
10185 ok(!!d3d
, "Failed to create a D3D object.\n");
10187 adapter_count
= IDirect3D8_GetAdapterCount(d3d
);
10188 for (adapter_idx
= 0; adapter_idx
< adapter_count
; ++adapter_idx
)
10190 monitor
= IDirect3D8_GetAdapterMonitor(d3d
, adapter_idx
);
10191 ok(!!monitor
, "Adapter %u: GetAdapterMonitor failed.\n", adapter_idx
);
10192 monitor_info
.cbSize
= sizeof(monitor_info
);
10193 ret
= GetMonitorInfoW(monitor
, &monitor_info
);
10194 ok(ret
, "Adapter %u: GetMonitorInfoW failed, error %#x.\n", adapter_idx
, GetLastError());
10196 window
= create_window();
10197 device_desc
.adapter_ordinal
= adapter_idx
;
10198 device_desc
.device_window
= window
;
10199 device_desc
.width
= monitor_info
.rcMonitor
.right
- monitor_info
.rcMonitor
.left
;
10200 device_desc
.height
= monitor_info
.rcMonitor
.bottom
- monitor_info
.rcMonitor
.top
;
10201 device_desc
.flags
= CREATE_DEVICE_FULLSCREEN
;
10202 if (!(device
= create_device(d3d
, window
, &device_desc
)))
10204 skip("Adapter %u: Failed to create a D3D device, skipping tests.\n", adapter_idx
);
10205 DestroyWindow(window
);
10209 ret
= GetWindowRect(window
, &window_rect
);
10210 ok(ret
, "Adapter %u: GetWindowRect failed, error %#x.\n", adapter_idx
, GetLastError());
10211 ok(EqualRect(&window_rect
, &monitor_info
.rcMonitor
),
10212 "Adapter %u: Expect window rect %s, got %s.\n", adapter_idx
,
10213 wine_dbgstr_rect(&monitor_info
.rcMonitor
), wine_dbgstr_rect(&window_rect
));
10215 /* Device resets should restore the window rectangle to fit the whole monitor */
10216 ret
= SetWindowPos(window
, 0, 0, 0, 0, 0, SWP_NOZORDER
| SWP_NOSIZE
);
10217 ok(ret
, "Adapter %u: SetWindowPos failed, error %#x.\n", adapter_idx
, GetLastError());
10218 hr
= reset_device(device
, &device_desc
);
10219 ok(hr
== D3D_OK
, "Adapter %u: Failed to reset device, hr %#x.\n", adapter_idx
, hr
);
10221 ret
= GetWindowRect(window
, &window_rect
);
10222 ok(ret
, "Adapter %u: GetWindowRect failed, error %#x.\n", adapter_idx
, GetLastError());
10223 ok(EqualRect(&window_rect
, &monitor_info
.rcMonitor
),
10224 "Adapter %u: Expect window rect %s, got %s.\n", adapter_idx
,
10225 wine_dbgstr_rect(&monitor_info
.rcMonitor
), wine_dbgstr_rect(&window_rect
));
10227 /* Window activation should restore the window rectangle to fit the whole monitor */
10228 ret
= SetWindowPos(window
, 0, 0, 0, 0, 0, SWP_NOZORDER
| SWP_NOSIZE
);
10229 ok(ret
, "Adapter %u: SetWindowPos failed, error %#x.\n", adapter_idx
, GetLastError());
10230 ret
= SetForegroundWindow(GetDesktopWindow());
10231 ok(ret
, "Adapter %u: SetForegroundWindow failed, error %#x.\n", adapter_idx
, GetLastError());
10233 ret
= ShowWindow(window
, SW_RESTORE
);
10234 ok(ret
, "Adapter %u: Failed to restore window, error %#x.\n", adapter_idx
, GetLastError());
10236 ret
= SetForegroundWindow(window
);
10237 ok(ret
, "Adapter %u: SetForegroundWindow failed, error %#x.\n", adapter_idx
, GetLastError());
10239 ret
= GetWindowRect(window
, &window_rect
);
10240 ok(ret
, "Adapter %u: GetWindowRect failed, error %#x.\n", adapter_idx
, GetLastError());
10241 ok(EqualRect(&window_rect
, &monitor_info
.rcMonitor
),
10242 "Adapter %u: Expect window rect %s, got %s.\n", adapter_idx
,
10243 wine_dbgstr_rect(&monitor_info
.rcMonitor
), wine_dbgstr_rect(&window_rect
));
10245 IDirect3DDevice8_Release(device
);
10246 DestroyWindow(window
);
10249 IDirect3D8_Release(d3d
);
10254 HMODULE d3d8_handle
= GetModuleHandleA("d3d8.dll");
10255 WNDCLASSA wc
= {0};
10257 DEVMODEW current_mode
;
10261 skip("Could not load d3d8.dll\n");
10265 memset(¤t_mode
, 0, sizeof(current_mode
));
10266 current_mode
.dmSize
= sizeof(current_mode
);
10267 ok(EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, ¤t_mode
), "Failed to get display mode.\n");
10268 registry_mode
.dmSize
= sizeof(registry_mode
);
10269 ok(EnumDisplaySettingsW(NULL
, ENUM_REGISTRY_SETTINGS
, ®istry_mode
), "Failed to get display mode.\n");
10270 if (current_mode
.dmPelsWidth
!= registry_mode
.dmPelsWidth
10271 || current_mode
.dmPelsHeight
!= registry_mode
.dmPelsHeight
)
10273 skip("Current mode does not match registry mode, skipping test.\n");
10277 wc
.lpfnWndProc
= DefWindowProcA
;
10278 wc
.lpszClassName
= "d3d8_test_wc";
10279 RegisterClassA(&wc
);
10281 ValidateVertexShader
= (void *)GetProcAddress(d3d8_handle
, "ValidateVertexShader");
10282 ValidatePixelShader
= (void *)GetProcAddress(d3d8_handle
, "ValidatePixelShader");
10284 if (!(d3d8
= Direct3DCreate8(D3D_SDK_VERSION
)))
10286 skip("could not create D3D8\n");
10289 IDirect3D8_Release(d3d8
);
10292 test_display_formats();
10293 test_display_modes();
10294 test_shader_versions();
10297 test_mipmap_levels();
10298 test_checkdevicemultisampletype();
10299 test_invalid_multisample();
10308 test_set_stream_source();
10309 test_ApplyStateBlock();
10310 test_render_zero_triangles();
10311 test_depth_stencil_reset();
10313 test_wndproc_windowed();
10314 test_depth_stencil_size();
10315 test_window_style();
10316 test_unsupported_shaders();
10317 test_mode_change();
10318 test_device_window_reset();
10319 test_reset_resources();
10321 test_set_rt_vp_scissor();
10322 test_validate_vs();
10323 test_validate_ps();
10324 test_volume_get_container();
10325 test_vb_lock_flags();
10326 test_texture_stage_states();
10327 test_cube_textures();
10328 test_get_set_texture();
10329 test_image_surface_pool();
10330 test_surface_get_container();
10331 test_lockrect_invalid();
10332 test_private_data();
10333 test_surface_dimensions();
10334 test_surface_format_null();
10335 test_surface_double_unlock();
10336 test_surface_blocks();
10337 test_set_palette();
10338 test_pinned_buffers();
10339 test_npot_textures();
10340 test_volume_locking();
10341 test_update_volumetexture();
10342 test_create_rt_ds_fail();
10343 test_volume_blocks();
10344 test_lockbox_invalid();
10345 test_pixel_format();
10346 test_begin_end_state_block();
10347 test_shader_constant_apply();
10348 test_resource_type();
10349 test_mipmap_lock();
10350 test_writeonly_resource();
10351 test_lost_device();
10352 test_resource_priority();
10353 test_swapchain_parameters();
10354 test_check_device_format();
10355 test_miptree_layout();
10356 test_render_target_device_mismatch();
10357 test_format_unknown();
10358 test_destroyed_window();
10359 test_lockable_backbuffer();
10360 test_clip_planes_limits();
10361 test_swapchain_multisample_reset();
10362 test_device_caps();
10364 test_resource_access();
10365 test_multiply_transform();
10366 test_draw_primitive();
10367 test_get_display_mode();
10368 test_multi_adapter();
10369 test_creation_parameters();
10370 test_cursor_clipping();
10371 test_window_position();
10373 UnregisterClassA("d3d8_test_wc", GetModuleHandleA(NULL
));