d3d9/tests: Add tests for device resets in d3d9ex.

This commit is contained in:
Henri Verbeet 2012-11-19 22:04:14 +01:00 committed by Alexandre Julliard
parent 84da62d993
commit 2f307a14f0
1 changed files with 480 additions and 0 deletions

View File

@ -93,6 +93,22 @@ done:
return device;
}
static HRESULT reset_device(IDirect3DDevice9Ex *device, HWND device_window, BOOL windowed)
{
D3DPRESENT_PARAMETERS present_parameters = {0};
present_parameters.Windowed = windowed;
present_parameters.hDeviceWindow = device_window;
present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
present_parameters.BackBufferWidth = 1024;
present_parameters.BackBufferHeight = 768;
present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
present_parameters.EnableAutoDepthStencil = TRUE;
present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
return IDirect3DDevice9_Reset(device, &present_parameters);
}
static ULONG getref(IUnknown *obj) {
IUnknown_AddRef(obj);
return IUnknown_Release(obj);
@ -430,6 +446,468 @@ done:
DestroyWindow(window);
}
static void test_reset(void)
{
static const DWORD simple_vs[] =
{
0xfffe0101, /* vs_1_1 */
0x0000001f, 0x80000000, 0x900f0000, /* dcl_position0 v0 */
0x00000009, 0xc0010000, 0x90e40000, 0xa0e40000, /* dp4 oPos.x, v0, c0 */
0x00000009, 0xc0020000, 0x90e40000, 0xa0e40001, /* dp4 oPos.y, v0, c1 */
0x00000009, 0xc0040000, 0x90e40000, 0xa0e40002, /* dp4 oPos.z, v0, c2 */
0x00000009, 0xc0080000, 0x90e40000, 0xa0e40003, /* dp4 oPos.w, v0, c3 */
0x0000ffff, /* end */
};
DWORD height, orig_height = GetSystemMetrics(SM_CYSCREEN);
DWORD width, orig_width = GetSystemMetrics(SM_CXSCREEN);
IDirect3DVertexShader9 *shader;
IDirect3DSwapChain9 *swapchain;
D3DDISPLAYMODE d3ddm, d3ddm2;
D3DPRESENT_PARAMETERS d3dpp;
IDirect3DDevice9Ex *device;
IDirect3DSurface9 *surface;
UINT i, adapter_mode_count;
IDirect3D9 *d3d9;
D3DVIEWPORT9 vp;
D3DCAPS9 caps;
UINT refcount;
DWORD value;
HWND window;
HRESULT hr;
RECT rect;
struct
{
UINT w;
UINT h;
} *modes = NULL;
UINT mode_count = 0;
window = create_window();
if (!(device = create_device(window, window, TRUE)))
{
skip("Failed to create a D3D device, skipping test.\n");
DestroyWindow(window);
return;
}
hr = IDirect3DDevice9Ex_GetDirect3D(device, &d3d9);
ok(SUCCEEDED(hr), "Failed to get d3d9, hr %#x.\n", hr);
hr = IDirect3DDevice9Ex_GetDeviceCaps(device, &caps);
ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
IDirect3D9_GetAdapterDisplayMode(d3d9, D3DADAPTER_DEFAULT, &d3ddm);
adapter_mode_count = IDirect3D9_GetAdapterModeCount(d3d9, D3DADAPTER_DEFAULT, d3ddm.Format);
modes = HeapAlloc(GetProcessHeap(), 0, sizeof(*modes) * adapter_mode_count);
for (i = 0; i < adapter_mode_count; ++i)
{
UINT j;
hr = IDirect3D9_EnumAdapterModes(d3d9, D3DADAPTER_DEFAULT, d3ddm.Format, i, &d3ddm2);
ok(SUCCEEDED(hr), "Failed to enumerate display mode, hr %#x.\n", hr);
for (j = 0; j < mode_count; ++j)
{
if (modes[j].w == d3ddm2.Width && modes[j].h == d3ddm2.Height)
break;
}
if (j == mode_count)
{
modes[j].w = d3ddm2.Width;
modes[j].h = d3ddm2.Height;
++mode_count;
}
/* We use them as invalid modes. */
if ((d3ddm2.Width == 801 && d3ddm2.Height == 600)
|| (d3ddm2.Width == 32 && d3ddm2.Height == 32))
{
skip("This system supports a screen resolution of %dx%d, not running mode tests.\n",
d3ddm2.Width, d3ddm2.Height);
goto cleanup;
}
}
if (mode_count < 2)
{
skip("Less than 2 modes supported, skipping mode tests.\n");
goto cleanup;
}
i = 0;
if (modes[i].w == orig_width && modes[i].h == orig_height)
++i;
memset(&d3dpp, 0, sizeof(d3dpp));
d3dpp.Windowed = FALSE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferWidth = modes[i].w;
d3dpp.BackBufferHeight = modes[i].h;
d3dpp.BackBufferFormat = d3ddm.Format;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
hr = IDirect3DDevice9Ex_Reset(device, &d3dpp);
ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
hr = IDirect3DDevice9Ex_TestCooperativeLevel(device);
ok(hr == D3D_OK, "Got unexpected cooperative level %#x.\n", hr);
width = GetSystemMetrics(SM_CXSCREEN);
height = GetSystemMetrics(SM_CYSCREEN);
ok(width == modes[i].w, "Got screen width %u, expected %u.\n", width, modes[i].w);
ok(height == modes[i].h, "Got screen height %u, expected %u.\n", height, modes[i].h);
hr = IDirect3DDevice9Ex_GetScissorRect(device, &rect);
ok(SUCCEEDED(hr), "Failed to get scissor rect, hr %#x.\n", hr);
ok(rect.left == 0 && rect.top == 0 && rect.right == modes[i].w && rect.bottom == modes[i].h,
"Got unexpected scissor rect {%d, %d, %d, %d}.\n",
rect.left, rect.top, rect.right, rect.bottom);
hr = IDirect3DDevice9Ex_GetViewport(device, &vp);
ok(SUCCEEDED(hr), "Failed to get viewport, hr %#x.\n", hr);
ok(vp.X == 0, "Got unexpected vp.X %u.\n", vp.X);
ok(vp.Y == 0, "Got unexpected vp.Y %u.\n", vp.Y);
ok(vp.Width == modes[i].w, "Got vp.Width %u, expected %u.\n", vp.Width, modes[i].w);
ok(vp.Height == modes[i].h, "Got vp.Height %u, expected %u.\n", vp.Height, modes[i].h);
ok(vp.MinZ == 0.0f, "Got unexpected vp.MinZ %.8e.\n", vp.MinZ);
ok(vp.MaxZ == 1.0f, "Got unexpected vp,MaxZ %.8e.\n", vp.MaxZ);
i = 1;
vp.X = 10;
vp.Y = 20;
vp.MinZ = 2.0f;
vp.MaxZ = 3.0f;
hr = IDirect3DDevice9Ex_SetViewport(device, &vp);
ok(SUCCEEDED(hr), "Failed to set viewport, hr %#x.\n", hr);
SetRect(&rect, 10, 20, 30, 40);
hr = IDirect3DDevice9Ex_SetScissorRect(device, &rect);
ok(SUCCEEDED(hr), "Failed to set scissor rect, hr %#x.\n", hr);
hr = IDirect3DDevice9_GetRenderState(device, D3DRS_LIGHTING, &value);
ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
ok(!!value, "Got unexpected value %#x for D3DRS_LIGHTING.\n", value);
hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
memset(&d3dpp, 0, sizeof(d3dpp));
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.Windowed = FALSE;
d3dpp.BackBufferWidth = modes[i].w;
d3dpp.BackBufferHeight = modes[i].h;
d3dpp.BackBufferFormat = d3ddm.Format;
hr = IDirect3DDevice9Ex_Reset(device, &d3dpp);
ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
hr = IDirect3DDevice9Ex_TestCooperativeLevel(device);
ok(hr == D3D_OK, "Got unexpected cooperative level %#x.\n", hr);
/* Render states are preserved in d3d9ex. */
hr = IDirect3DDevice9_GetRenderState(device, D3DRS_LIGHTING, &value);
ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
ok(!value, "Got unexpected value %#x for D3DRS_LIGHTING.\n", value);
hr = IDirect3DDevice9Ex_GetScissorRect(device, &rect);
ok(SUCCEEDED(hr), "Failed to get scissor rect, hr %#x.\n", hr);
ok(rect.left == 0 && rect.top == 0 && rect.right == modes[i].w && rect.bottom == modes[i].h,
"Got unexpected scissor rect {%d, %d, %d, %d}.\n",
rect.left, rect.top, rect.right, rect.bottom);
hr = IDirect3DDevice9Ex_GetViewport(device, &vp);
ok(SUCCEEDED(hr), "Failed to get viewport, hr %#x.\n", hr);
ok(vp.X == 0, "Got unexpected vp.X %u.\n", vp.X);
ok(vp.Y == 0, "Got unexpected vp.Y %u.\n", vp.Y);
ok(vp.Width == modes[i].w, "Got vp.Width %u, expected %u.\n", vp.Width, modes[i].w);
ok(vp.Height == modes[i].h, "Got vp.Height %u, expected %u.\n", vp.Height, modes[i].h);
ok(vp.MinZ == 2.0f, "Got unexpected vp.MinZ %.8e.\n", vp.MinZ);
ok(vp.MaxZ == 3.0f, "Got unexpected vp,MaxZ %.8e.\n", vp.MaxZ);
width = GetSystemMetrics(SM_CXSCREEN);
height = GetSystemMetrics(SM_CYSCREEN);
ok(width == modes[i].w, "Got screen width %u, expected %u.\n", width, modes[i].w);
ok(height == modes[i].h, "Got screen height %u, expected %u.\n", height, modes[i].h);
hr = IDirect3DDevice9Ex_GetSwapChain(device, 0, &swapchain);
ok(SUCCEEDED(hr), "Failed to get swapchain, hr %#x.\n", hr);
hr = IDirect3DSwapChain9_GetPresentParameters(swapchain, &d3dpp);
ok(SUCCEEDED(hr), "Failed to get present parameters, hr %#x.\n", hr);
ok(d3dpp.BackBufferWidth == modes[i].w, "Got backbuffer width %u, expected %u.\n",
d3dpp.BackBufferWidth, modes[i].w);
ok(d3dpp.BackBufferHeight == modes[i].h, "Got backbuffer height %u, expected %u.\n",
d3dpp.BackBufferHeight, modes[i].h);
IDirect3DSwapChain9_Release(swapchain);
memset(&d3dpp, 0, sizeof(d3dpp));
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.Windowed = TRUE;
d3dpp.BackBufferWidth = 400;
d3dpp.BackBufferHeight = 300;
hr = IDirect3DDevice9Ex_Reset(device, &d3dpp);
ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
hr = IDirect3DDevice9Ex_TestCooperativeLevel(device);
ok(hr == D3D_OK, "Got unexpected cooperative level %#x.\n", hr);
width = GetSystemMetrics(SM_CXSCREEN);
height = GetSystemMetrics(SM_CYSCREEN);
ok(width == orig_width, "Got screen width %u, expected %u.\n", width, orig_width);
ok(height == orig_height, "Got screen height %u, expected %u.\n", height, orig_height);
hr = IDirect3DDevice9Ex_GetScissorRect(device, &rect);
ok(SUCCEEDED(hr), "Failed to get scissor rect, hr %#x.\n", hr);
ok(rect.left == 0 && rect.top == 0 && rect.right == 400 && rect.bottom == 300,
"Got unexpected scissor rect {%d, %d, %d, %d}.\n",
rect.left, rect.top, rect.right, rect.bottom);
hr = IDirect3DDevice9Ex_GetViewport(device, &vp);
ok(SUCCEEDED(hr), "Failed to get viewport, hr %#x.\n", hr);
ok(vp.X == 0, "Got unexpected vp.X %u.\n", vp.X);
ok(vp.Y == 0, "Got unexpected vp.Y %u.\n", vp.Y);
ok(vp.Width == 400, "Got unexpected vp.Width %u.\n", vp.Width);
ok(vp.Height == 300, "Got unexpected vp.Height %u.\n", vp.Height);
ok(vp.MinZ == 2.0f, "Got unexpected vp.MinZ %.8e.\n", vp.MinZ);
ok(vp.MaxZ == 3.0f, "Got unexpected vp,MaxZ %.8e.\n", vp.MaxZ);
hr = IDirect3DDevice9Ex_GetSwapChain(device, 0, &swapchain);
ok(SUCCEEDED(hr), "Failed to get swapchain, hr %#x.\n", hr);
hr = IDirect3DSwapChain9_GetPresentParameters(swapchain, &d3dpp);
ok(SUCCEEDED(hr), "Failed to get present parameters, hr %#x.\n", hr);
ok(d3dpp.BackBufferWidth == 400, "Got unexpected backbuffer width %u.\n", d3dpp.BackBufferWidth);
ok(d3dpp.BackBufferHeight == 300, "Got unexpected backbuffer height %u.\n", d3dpp.BackBufferHeight);
IDirect3DSwapChain9_Release(swapchain);
SetRect(&rect, 0, 0, 200, 150);
ok(AdjustWindowRect(&rect, GetWindowLongW(window, GWL_STYLE), FALSE), "Failed to adjust window rect.\n");
ok(SetWindowPos(window, NULL, 0, 0, rect.right - rect.left, rect.bottom - rect.top,
SWP_NOMOVE | SWP_NOZORDER), "Failed to set window position.\n");
memset(&d3dpp, 0, sizeof(d3dpp));
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.Windowed = TRUE;
d3dpp.BackBufferWidth = 0;
d3dpp.BackBufferHeight = 0;
hr = IDirect3DDevice9Ex_Reset(device, &d3dpp);
ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
hr = IDirect3DDevice9Ex_TestCooperativeLevel(device);
ok(hr == D3D_OK, "Got unexpected cooperative level %#x.\n", hr);
hr = IDirect3DDevice9Ex_GetScissorRect(device, &rect);
ok(SUCCEEDED(hr), "Failed to get scissor rect, hr %#x.\n", hr);
todo_wine ok(rect.left == 0 && rect.top == 0 && rect.right == 200 && rect.bottom == 150,
"Got unexpected scissor rect {%d, %d, %d, %d}.\n",
rect.left, rect.top, rect.right, rect.bottom);
hr = IDirect3DDevice9Ex_GetViewport(device, &vp);
ok(SUCCEEDED(hr), "Failed to get viewport, hr %#x.\n", hr);
ok(vp.X == 0, "Got unexpected vp.X %u.\n", vp.X);
ok(vp.Y == 0, "Got unexpected vp.Y %u.\n", vp.Y);
todo_wine ok(vp.Width == 200, "Got unexpected vp.Width %u.\n", vp.Width);
todo_wine ok(vp.Height == 150, "Got unexpected vp.Height %u.\n", vp.Height);
ok(vp.MinZ == 2.0f, "Got unexpected vp.MinZ %.8e.\n", vp.MinZ);
ok(vp.MaxZ == 3.0f, "Got unexpected vp,MaxZ %.8e.\n", vp.MaxZ);
hr = IDirect3DDevice9Ex_GetSwapChain(device, 0, &swapchain);
ok(SUCCEEDED(hr), "Failed to get swapchain, hr %#x.\n", hr);
hr = IDirect3DSwapChain9_GetPresentParameters(swapchain, &d3dpp);
ok(SUCCEEDED(hr), "Failed to get present parameters, hr %#x.\n", hr);
todo_wine ok(d3dpp.BackBufferWidth == 200, "Got unexpected backbuffer width %u.\n", d3dpp.BackBufferWidth);
todo_wine ok(d3dpp.BackBufferHeight == 150, "Got unexpected backbuffer height %u.\n", d3dpp.BackBufferHeight);
IDirect3DSwapChain9_Release(swapchain);
memset(&d3dpp, 0, sizeof(d3dpp));
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.Windowed = TRUE;
d3dpp.BackBufferWidth = 400;
d3dpp.BackBufferHeight = 300;
/* Reset with resources in the default pool succeeds in d3d9ex. */
hr = IDirect3DDevice9Ex_CreateOffscreenPlainSurface(device, 16, 16,
D3DFMT_R5G6B5, D3DPOOL_DEFAULT, &surface, NULL);
ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
hr = IDirect3DDevice9Ex_Reset(device, &d3dpp);
ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
hr = IDirect3DDevice9Ex_TestCooperativeLevel(device);
ok(hr == D3D_OK, "Got unexpected cooperative level %#x.\n", hr);
IDirect3DSurface9_Release(surface);
if (caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP)
{
IDirect3DVolumeTexture9 *volume_texture;
hr = IDirect3DDevice9Ex_CreateVolumeTexture(device, 16, 16, 4, 1, 0,
D3DFMT_R5G6B5, D3DPOOL_DEFAULT, &volume_texture, NULL);
ok(SUCCEEDED(hr), "Failed to create volume texture, hr %#x.\n", hr);
hr = IDirect3DDevice9Ex_Reset(device, &d3dpp);
ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
hr = IDirect3DDevice9Ex_TestCooperativeLevel(device);
ok(hr == D3D_OK, "Got unexpected cooperative level %#x.\n", hr);
IDirect3DVolumeTexture9_Release(volume_texture);
}
else
{
skip("Volume textures not supported.\n");
}
/* Scratch and sysmem pools are fine too. */
hr = IDirect3DDevice9Ex_CreateOffscreenPlainSurface(device, 16, 16,
D3DFMT_R5G6B5, D3DPOOL_SCRATCH, &surface, NULL);
ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
hr = IDirect3DDevice9Ex_Reset(device, &d3dpp);
ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
hr = IDirect3DDevice9Ex_TestCooperativeLevel(device);
ok(hr == D3D_OK, "Got unexpected cooperative level %#x.\n", hr);
IDirect3DSurface9_Release(surface);
hr = IDirect3DDevice9Ex_CreateOffscreenPlainSurface(device, 16, 16,
D3DFMT_R5G6B5, D3DPOOL_SYSTEMMEM, &surface, NULL);
ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
hr = IDirect3DDevice9Ex_Reset(device, &d3dpp);
ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
hr = IDirect3DDevice9Ex_TestCooperativeLevel(device);
ok(hr == D3D_OK, "Got unexpected cooperative level %#x.\n", hr);
IDirect3DSurface9_Release(surface);
/* The depth stencil should get reset to the auto depth stencil when present. */
hr = IDirect3DDevice9Ex_SetDepthStencilSurface(device, NULL);
ok(SUCCEEDED(hr), "Failed to set depth/stencil surface, hr %#x.\n", hr);
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
hr = IDirect3DDevice9Ex_Reset(device, &d3dpp);
ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
hr = IDirect3DDevice9Ex_GetDepthStencilSurface(device, &surface);
ok(SUCCEEDED(hr), "Failed to get depth/stencil surface, hr %#x.\n", hr);
ok(!!surface, "Depth/stencil surface should not be NULL.\n");
IDirect3DSurface9_Release(surface);
d3dpp.EnableAutoDepthStencil = FALSE;
hr = IDirect3DDevice9Ex_Reset(device, &d3dpp);
ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
hr = IDirect3DDevice9Ex_GetDepthStencilSurface(device, &surface);
ok(hr == D3DERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
ok(!surface, "Depth/stencil surface should be NULL.\n");
/* References to implicit surfaces are allowed in d3d9ex. */
hr = IDirect3DDevice9Ex_GetBackBuffer(device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &surface);
ok(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
hr = IDirect3DDevice9Ex_Reset(device, &d3dpp);
ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
hr = IDirect3DDevice9Ex_TestCooperativeLevel(device);
ok(hr == D3D_OK, "Got unexpected cooperative level %#x.\n", hr);
IDirect3DSurface9_Release(surface);
/* Shaders are fine. */
hr = IDirect3DDevice9Ex_CreateVertexShader(device, simple_vs, &shader);
ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
hr = IDirect3DDevice9Ex_Reset(device, &d3dpp);
ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
IDirect3DVertexShader9_Release(shader);
/* Try setting invalid modes. */
memset(&d3dpp, 0, sizeof(d3dpp));
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.Windowed = FALSE;
d3dpp.BackBufferWidth = 32;
d3dpp.BackBufferHeight = 32;
hr = IDirect3DDevice9Ex_Reset(device, &d3dpp);
ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
hr = IDirect3DDevice9Ex_TestCooperativeLevel(device);
ok(hr == D3D_OK, "Got unexpected cooperative level %#x.\n", hr);
memset(&d3dpp, 0, sizeof(d3dpp));
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.Windowed = FALSE;
d3dpp.BackBufferWidth = 801;
d3dpp.BackBufferHeight = 600;
hr = IDirect3DDevice9Ex_Reset(device, &d3dpp);
ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
hr = IDirect3DDevice9Ex_TestCooperativeLevel(device);
ok(hr == D3D_OK, "Got unexpected cooperative level %#x.\n", hr);
hr = IDirect3D9_GetAdapterDisplayMode(d3d9, D3DADAPTER_DEFAULT, &d3ddm);
ok(SUCCEEDED(hr), "Failed to get display mode, hr %#x.\n", hr);
memset(&d3dpp, 0, sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = d3ddm.Format;
d3dpp.EnableAutoDepthStencil = FALSE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
cleanup:
HeapFree(GetProcessHeap(), 0, modes);
IDirect3D9_Release(d3d9);
refcount = IDirect3DDevice9Ex_Release(device);
ok(!refcount, "Device has %u references left.\n", refcount);
DestroyWindow(window);
}
static void test_reset_resources(void)
{
IDirect3DSurface9 *surface, *rt;
IDirect3DTexture9 *texture;
IDirect3DDevice9Ex *device;
unsigned int i;
D3DCAPS9 caps;
HWND window;
HRESULT hr;
ULONG ref;
window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW,
0, 0, 640, 480, 0, 0, 0, 0);
if (!(device = create_device(window, window, TRUE)))
{
skip("Failed to create a D3D device, skipping tests.\n");
goto done;
}
hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
hr = IDirect3DDevice9_CreateTexture(device, 128, 128, 1, D3DUSAGE_DEPTHSTENCIL,
D3DFMT_D24S8, D3DPOOL_DEFAULT, &texture, NULL);
ok(SUCCEEDED(hr), "Failed to create depth/stencil texture, hr %#x.\n", hr);
hr = IDirect3DTexture9_GetSurfaceLevel(texture, 0, &surface);
ok(SUCCEEDED(hr), "Failed to get surface, hr %#x.\n", hr);
IDirect3DTexture9_Release(texture);
hr = IDirect3DDevice9_SetDepthStencilSurface(device, surface);
ok(SUCCEEDED(hr), "Failed to set depth/stencil surface, hr %#x.\n", hr);
IDirect3DSurface9_Release(surface);
for (i = 0; i < caps.NumSimultaneousRTs; ++i)
{
hr = IDirect3DDevice9_CreateTexture(device, 128, 128, 1, D3DUSAGE_RENDERTARGET,
D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture, NULL);
ok(SUCCEEDED(hr), "Failed to create render target texture %u, hr %#x.\n", i, hr);
hr = IDirect3DTexture9_GetSurfaceLevel(texture, 0, &surface);
ok(SUCCEEDED(hr), "Failed to get surface %u, hr %#x.\n", i, hr);
IDirect3DTexture9_Release(texture);
hr = IDirect3DDevice9_SetRenderTarget(device, i, surface);
ok(SUCCEEDED(hr), "Failed to set render target surface %u, hr %#x.\n", i, hr);
IDirect3DSurface9_Release(surface);
}
hr = reset_device(device, window, TRUE);
ok(SUCCEEDED(hr), "Failed to reset device.\n");
hr = IDirect3DDevice9_GetBackBuffer(device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &rt);
ok(SUCCEEDED(hr), "Failed to get back buffer, hr %#x.\n", hr);
hr = IDirect3DDevice9_GetRenderTarget(device, 0, &surface);
ok(SUCCEEDED(hr), "Failed to get render target surface, hr %#x.\n", hr);
ok(surface == rt, "Got unexpected surface %p for render target.\n", surface);
IDirect3DSurface9_Release(surface);
IDirect3DSurface9_Release(rt);
for (i = 1; i < caps.NumSimultaneousRTs; ++i)
{
hr = IDirect3DDevice9_GetRenderTarget(device, i, &surface);
ok(hr == D3DERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
}
ref = IDirect3DDevice9_Release(device);
ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
done:
DestroyWindow(window);
}
START_TEST(d3d9ex)
{
d3d9_handle = LoadLibraryA("d3d9.dll");
@ -455,4 +933,6 @@ START_TEST(d3d9ex)
test_get_adapter_luid();
test_get_adapter_displaymode_ex();
test_texture_sysmem_create();
test_reset();
test_reset_resources();
}