-- v2: ddraw/tests: Release device earlier in test_d3d_state_reset().
From: Paul Gofman pgofman@codeweavers.com
--- dlls/ddraw/tests/ddraw1.c | 108 +++++++++++++++++++++++++++++++++++++- dlls/ddraw/tests/ddraw2.c | 64 ++++++++++++++++++++++ dlls/ddraw/tests/ddraw4.c | 62 ++++++++++++++++++++++ dlls/ddraw/tests/ddraw7.c | 61 +++++++++++++++++++++ 4 files changed, 294 insertions(+), 1 deletion(-)
diff --git a/dlls/ddraw/tests/ddraw1.c b/dlls/ddraw/tests/ddraw1.c index 167ef8a3dc4..3b41a1f0f1a 100644 --- a/dlls/ddraw/tests/ddraw1.c +++ b/dlls/ddraw/tests/ddraw1.c @@ -15579,6 +15579,7 @@ static void test_pinned_sysmem(void)
static void test_multiple_devices(void) { + D3DRECT clear_rect = {{0}, {0}, {640}, {480}}; static D3DMATRIX test_matrix = { 1.0f, 0.0f, 0.0f, 0.0f, @@ -15586,21 +15587,33 @@ static void test_multiple_devices(void) 0.0f, 0.0f, 3.0f, 0.0f, 0.0f, 0.0f, 0.0f, 4.0f, }; + static D3DLVERTEX quad[] = + { + {{-1.0f}, {-1.0f}, {0.1f}, 0, {0x800000ff}}, + {{-1.0f}, { 1.0f}, {0.1f}, 0, {0x800000ff}}, + {{ 1.0f}, {-1.0f}, {0.1f}, 0, {0x800000ff}}, + {{ 1.0f}, { 1.0f}, {0.1f}, 0, {0x800000ff}}, + };
D3DTEXTUREHANDLE texture_handle, texture_handle2, texture_handle3; - IDirectDrawSurface *texture_surf, *texture_surf2; + IDirectDrawSurface *texture_surf, *texture_surf2, *rt, *rt2; + IDirect3DExecuteBuffer *execute_buffer, *execute_buffer2; D3DMATERIALHANDLE mat_handle, mat_handle2; IDirect3DViewport *viewport, *viewport2; IDirect3DTexture *texture, *texture2; IDirect3DDevice *device, *device2; + D3DEXECUTEBUFFERDESC exec_desc; D3DMATRIXHANDLE matrix_handle; IDirectDraw *ddraw, *ddraw2; IDirect3DMaterial *material; DDSURFACEDESC surface_desc; D3DMATRIX matrix; + UINT inst_length; ULONG refcount; + DWORD colour; HWND window; HRESULT hr; + void *ptr;
window = create_window(); ddraw = create_ddraw(); @@ -15619,6 +15632,11 @@ static void test_multiple_devices(void) device2 = create_device_ex(ddraw2, window, DDSCL_NORMAL, &IID_IDirect3DHALDevice); ok(!!device2, "got NULL.\n");
+ hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice_QueryInterface(device2, &IID_IDirectDrawSurface, (void **)&rt2); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + viewport = create_viewport(device, 0, 0, 640, 480); viewport2 = create_viewport(device2, 0, 0, 640, 480);
@@ -15685,6 +15703,91 @@ static void test_multiple_devices(void) ok(hr == D3D_OK, "got %#lx.\n", hr); ok(!memcmp(&matrix, &test_matrix, sizeof(matrix)), "matrix does not match.\n");
+ memset(&exec_desc, 0, sizeof(exec_desc)); + exec_desc.dwSize = sizeof(exec_desc); + exec_desc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS; + exec_desc.dwBufferSize = 1024; + exec_desc.dwCaps = D3DDEBCAPS_SYSTEMMEMORY; + hr = IDirect3DDevice_CreateExecuteBuffer(device, &exec_desc, &execute_buffer, NULL); + ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc); + ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); + memcpy(exec_desc.lpData, quad, sizeof(quad)); + ptr = ((BYTE *)exec_desc.lpData) + sizeof(quad); + emit_set_rs(&ptr, D3DRENDERSTATE_ZENABLE, FALSE); + emit_set_rs(&ptr, D3DRENDERSTATE_ALPHATESTENABLE, FALSE); + emit_process_vertices(&ptr, D3DPROCESSVERTICES_TRANSFORM, 0, ARRAY_SIZE(quad)); + emit_tquad(&ptr, 0); + emit_end(&ptr); + inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData; + inst_length -= sizeof(quad); + hr = IDirect3DExecuteBuffer_Unlock(execute_buffer); + ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); + set_execute_data(execute_buffer, ARRAY_SIZE(quad), sizeof(quad), inst_length); + + memset(&exec_desc, 0, sizeof(exec_desc)); + exec_desc.dwSize = sizeof(exec_desc); + exec_desc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS; + exec_desc.dwBufferSize = 1024; + exec_desc.dwCaps = D3DDEBCAPS_SYSTEMMEMORY; + hr = IDirect3DDevice_CreateExecuteBuffer(device2, &exec_desc, &execute_buffer2, NULL); + ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DExecuteBuffer_Lock(execute_buffer2, &exec_desc); + ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); + memcpy(exec_desc.lpData, quad, sizeof(quad)); + ptr = ((BYTE *)exec_desc.lpData) + sizeof(quad); + emit_set_rs(&ptr, D3DRENDERSTATE_ZENABLE, FALSE); + emit_set_rs(&ptr, D3DRENDERSTATE_ALPHATESTENABLE, TRUE); + emit_set_rs(&ptr, D3DRENDERSTATE_ALPHAFUNC, D3DCMP_LESS); + emit_set_rs(&ptr, D3DRENDERSTATE_ALPHAREF, 0x70); + emit_process_vertices(&ptr, D3DPROCESSVERTICES_TRANSFORM, 0, ARRAY_SIZE(quad)); + emit_tquad(&ptr, 0); + emit_end(&ptr); + inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData; + inst_length -= sizeof(quad); + hr = IDirect3DExecuteBuffer_Unlock(execute_buffer2); + ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); + set_execute_data(execute_buffer2, ARRAY_SIZE(quad), sizeof(quad), inst_length); + + hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + colour = get_surface_color(rt, 320, 240); + hr = IDirect3DDevice_BeginScene(device); + ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED); + ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice_EndScene(device); + ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); + colour = get_surface_color(rt, 320, 240); + ok(colour == 0x0000ff, "got %#lx.\n", colour); + + hr = IDirect3DViewport_Clear(viewport2, 1, &clear_rect, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + colour = get_surface_color(rt2, 320, 240); + hr = IDirect3DDevice_BeginScene(device2); + ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice_Execute(device2, execute_buffer2, viewport2, D3DEXECUTE_CLIPPED); + ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice_EndScene(device2); + ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); + colour = get_surface_color(rt2, 320, 240); + ok(colour == 0xff0000, "got %#lx.\n", colour); + + hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + colour = get_surface_color(rt, 320, 240); + hr = IDirect3DDevice_BeginScene(device); + ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED); + ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice_EndScene(device); + ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); + colour = get_surface_color(rt, 320, 240); + ok(colour == 0x0000ff, "got %#lx.\n", colour); + + IDirect3DExecuteBuffer_Release(execute_buffer); + IDirect3DExecuteBuffer_Release(execute_buffer2); + IDirect3DTexture_Release(texture2); IDirectDrawSurface_Release(texture_surf2); IDirect3DTexture_Release(texture); @@ -15693,6 +15796,9 @@ static void test_multiple_devices(void) IDirect3DViewport_Release(viewport); IDirect3DViewport_Release(viewport2);
+ IDirectDrawSurface_Release(rt); + IDirectDrawSurface_Release(rt2); + refcount = IDirect3DDevice_Release(device); ok(!refcount, "Device has %lu references left.\n", refcount); refcount = IDirect3DDevice_Release(device2); diff --git a/dlls/ddraw/tests/ddraw2.c b/dlls/ddraw/tests/ddraw2.c index de4778e8d24..e0818c5f62b 100644 --- a/dlls/ddraw/tests/ddraw2.c +++ b/dlls/ddraw/tests/ddraw2.c @@ -16504,6 +16504,15 @@ static void run_for_each_device_type(void (*test_func)(const GUID *))
static void test_multiple_devices(void) { + D3DRECT clear_rect = {{0}, {0}, {640}, {480}}; + static D3DLVERTEX quad[] = + { + {{-1.0f}, {-1.0f}, {0.1f}, 0, {0x800000ff}}, + {{-1.0f}, { 1.0f}, {0.1f}, 0, {0x800000ff}}, + {{ 1.0f}, {-1.0f}, {0.1f}, 0, {0x800000ff}}, + {{ 1.0f}, { 1.0f}, {0.1f}, 0, {0x800000ff}}, + }; + D3DTEXTUREHANDLE texture_handle, texture_handle2, texture_handle3; IDirectDrawSurface *surface, *texture_surf, *texture_surf2; IDirect3DDevice2 *device, *device2, *device3; @@ -16515,6 +16524,7 @@ static void test_multiple_devices(void) DDSURFACEDESC surface_desc; IDirect3D2 *d3d; ULONG refcount; + DWORD colour; DWORD value; HWND window; HRESULT hr; @@ -16647,6 +16657,60 @@ static void test_multiple_devices(void) ok(hr == D3D_OK, "got %#lx.\n", hr); ok(texture_handle2 == texture_handle, "got different handles.\n");
+ hr = IDirect3DDevice2_SetRenderState(device, D3DRENDERSTATE_TEXTUREHANDLE, 0); + ok(hr == D3D_OK, "got %#lx.\n", hr); + hr = IDirect3DDevice2_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice2_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, FALSE); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice2_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + + hr = IDirect3DDevice2_SetRenderState(device2, D3DRENDERSTATE_TEXTUREHANDLE, 0); + ok(hr == D3D_OK, "got %#lx.\n", hr); + hr = IDirect3DDevice2_SetRenderState(device2, D3DRENDERSTATE_ZENABLE, FALSE); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice2_SetRenderState(device2, D3DRENDERSTATE_ALPHABLENDENABLE, FALSE); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice2_SetRenderState(device2, D3DRENDERSTATE_ALPHATESTENABLE, TRUE); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice2_SetRenderState(device2, D3DRENDERSTATE_ALPHAFUNC, D3DCMP_LESS); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice2_SetRenderState(device2, D3DRENDERSTATE_ALPHAREF, 0x70); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice2_SetRenderState(device2, D3DRENDERSTATE_LIGHTING, FALSE); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + + hr = IDirect3DViewport2_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice2_BeginScene(device); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice2_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DVT_LVERTEX, quad, ARRAY_SIZE(quad), 0); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice2_EndScene(device); + colour = get_surface_color(surface, 320, 240); + ok(colour == 0x0000ff, "got %#lx.\n", colour); + + hr = IDirect3DViewport2_Clear(viewport2, 1, &clear_rect, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice2_BeginScene(device2); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice2_DrawPrimitive(device2, D3DPT_TRIANGLESTRIP, D3DVT_LVERTEX, quad, ARRAY_SIZE(quad), 0); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice2_EndScene(device2); + colour = get_surface_color(surface, 320, 240); + ok(colour == 0xff0000, "got %#lx.\n", colour); + + hr = IDirect3DViewport2_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice2_BeginScene(device); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice2_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DVT_LVERTEX, quad, ARRAY_SIZE(quad), 0); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice2_EndScene(device); + colour = get_surface_color(surface, 320, 240); + todo_wine ok(colour == 0x0000ff, "got %#lx.\n", colour); + IDirect3DTexture2_Release(texture2); IDirect3DTexture2_Release(texture); IDirectDrawSurface_Release(texture_surf2); diff --git a/dlls/ddraw/tests/ddraw4.c b/dlls/ddraw/tests/ddraw4.c index 96bdbf37183..605d70d4b6d 100644 --- a/dlls/ddraw/tests/ddraw4.c +++ b/dlls/ddraw/tests/ddraw4.c @@ -19571,6 +19571,20 @@ static void test_enum_devices(void)
static void test_multiple_devices(void) { + D3DRECT clear_rect = {{0}, {0}, {640}, {480}}; + static struct + { + struct vec3 position; + DWORD diffuse; + } + quad[] = + { + {{-1.0f, -1.0f, 0.1f}, 0xff0000ff}, + {{-1.0f, 1.0f, 0.1f}, 0xff0000ff}, + {{ 1.0f, -1.0f, 0.1f}, 0xff0000ff}, + {{ 1.0f, 1.0f, 0.1f}, 0xff0000ff}, + }; + IDirect3DDevice3 *device, *device2, *device3; D3DMATERIALHANDLE mat_handle, mat_handle2; IDirect3DViewport3 *viewport, *viewport2; @@ -19579,6 +19593,7 @@ static void test_multiple_devices(void) IDirectDraw4 *ddraw; IDirect3D3 *d3d; ULONG refcount; + DWORD colour; DWORD value; HWND window; HRESULT hr; @@ -19655,6 +19670,53 @@ static void test_multiple_devices(void) ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); ok(!value, "got %#lx.\n", value);
+ hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, FALSE); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + + hr = IDirect3DDevice3_SetRenderState(device2, D3DRENDERSTATE_ZENABLE, TRUE); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice3_SetRenderState(device2, D3DRENDERSTATE_ALPHABLENDENABLE, FALSE); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice3_SetRenderState(device2, D3DRENDERSTATE_LIGHTING, FALSE); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + + hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff0000, 0.0f, 0); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice3_BeginScene(device); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, + D3DFVF_XYZ | D3DFVF_DIFFUSE, quad, ARRAY_SIZE(quad), 0); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice3_EndScene(device); + colour = get_surface_color(surface, 320, 240); + ok(colour == 0x0000ff, "got %#lx.\n", colour); + + hr = IDirect3DViewport3_Clear2(viewport2, 1, &clear_rect, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff0000, 0.0f, 0); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice3_BeginScene(device2); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice3_DrawPrimitive(device2, D3DPT_TRIANGLESTRIP, + D3DFVF_XYZ | D3DFVF_DIFFUSE, quad, ARRAY_SIZE(quad), 0); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice3_EndScene(device2); + colour = get_surface_color(surface, 320, 240); + ok(colour == 0xff0000, "got %#lx.\n", colour); + + hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff0000, 0.0f, 0); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice3_BeginScene(device); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, + D3DFVF_XYZ | D3DFVF_DIFFUSE, quad, ARRAY_SIZE(quad), 0); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice3_EndScene(device); + colour = get_surface_color(surface, 320, 240); + todo_wine ok(colour == 0x0000ff, "got %#lx.\n", colour); + IDirect3DMaterial3_Release(material); IDirect3DViewport3_Release(viewport); IDirect3DViewport3_Release(viewport2); diff --git a/dlls/ddraw/tests/ddraw7.c b/dlls/ddraw/tests/ddraw7.c index 343ca652214..f10c39f40ff 100644 --- a/dlls/ddraw/tests/ddraw7.c +++ b/dlls/ddraw/tests/ddraw7.c @@ -20067,12 +20067,26 @@ static void run_for_each_device_type(void (*test_func)(const GUID *))
static void test_multiple_devices(void) { + static struct + { + struct vec3 position; + DWORD diffuse; + } + quad[] = + { + {{-1.0f, -1.0f, 0.1f}, 0xff0000ff}, + {{-1.0f, 1.0f, 0.1f}, 0xff0000ff}, + {{ 1.0f, -1.0f, 0.1f}, 0xff0000ff}, + {{ 1.0f, 1.0f, 0.1f}, 0xff0000ff}, + }; + IDirect3DDevice7 *device, *device2; IDirectDrawSurface7 *surface; IDirectDraw7 *ddraw; IDirect3D7 *d3d; ULONG refcount; DWORD stateblock; + DWORD colour; DWORD value; HWND window; HRESULT hr; @@ -20117,6 +20131,53 @@ static void test_multiple_devices(void) ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); ok(!value, "got %#lx.\n", value);
+ hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, FALSE); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, FALSE); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + + hr = IDirect3DDevice7_SetRenderState(device2, D3DRENDERSTATE_ZENABLE, TRUE); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice7_SetRenderState(device2, D3DRENDERSTATE_ALPHABLENDENABLE, FALSE); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice7_SetRenderState(device2, D3DRENDERSTATE_LIGHTING, FALSE); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + + hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0f, 0); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice7_BeginScene(device); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, + D3DFVF_XYZ | D3DFVF_DIFFUSE, quad, ARRAY_SIZE(quad), 0); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice7_EndScene(device); + colour = get_surface_color(surface, 320, 240); + ok(colour == 0x0000ff, "got %#lx.\n", colour); + + hr = IDirect3DDevice7_Clear(device2, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0f, 0); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice7_BeginScene(device2); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice7_DrawPrimitive(device2, D3DPT_TRIANGLESTRIP, + D3DFVF_XYZ | D3DFVF_DIFFUSE, quad, ARRAY_SIZE(quad), 0); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice7_EndScene(device2); + colour = get_surface_color(surface, 320, 240); + ok(colour == 0xff0000, "got %#lx.\n", colour); + + hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0f, 0); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice7_BeginScene(device); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, + D3DFVF_XYZ | D3DFVF_DIFFUSE, quad, ARRAY_SIZE(quad), 0); + ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DDevice7_EndScene(device); + colour = get_surface_color(surface, 320, 240); + todo_wine ok(colour == 0x0000ff, "got %#lx.\n", colour); + refcount = IDirect3DDevice3_Release(device); ok(!refcount, "Device has %lu references left.\n", refcount); refcount = IDirect3DDevice3_Release(device2);
From: Paul Gofman pgofman@codeweavers.com
--- dlls/ddraw/ddraw_private.h | 1 + dlls/ddraw/device.c | 30 ++++++++++++++++-------------- dlls/ddraw/executebuffer.c | 6 ++---- 3 files changed, 19 insertions(+), 18 deletions(-)
diff --git a/dlls/ddraw/ddraw_private.h b/dlls/ddraw/ddraw_private.h index 36c63ee1160..882ff4c0708 100644 --- a/dlls/ddraw/ddraw_private.h +++ b/dlls/ddraw/ddraw_private.h @@ -711,6 +711,7 @@ static inline struct wined3d_texture *ddraw_surface_get_any_texture(struct ddraw }
void d3d_device_sync_surfaces(struct d3d_device *device); +void d3d_device_apply_state(struct d3d_device *device, BOOL clear_state);
/* Used for generic dumping */ struct flag_info diff --git a/dlls/ddraw/device.c b/dlls/ddraw/device.c index 360f93b516b..067dbf63485 100644 --- a/dlls/ddraw/device.c +++ b/dlls/ddraw/device.c @@ -3449,6 +3449,15 @@ void d3d_device_sync_surfaces(struct d3d_device *device) } }
+void d3d_device_apply_state(struct d3d_device *device, BOOL clear_state) +{ + if (clear_state) + wined3d_stateblock_apply_clear_state(device->state, device->wined3d_device); + else + wined3d_device_apply_stateblock(device->wined3d_device, device->state); + d3d_device_sync_surfaces(device); +} + static HRESULT d3d_device7_DrawPrimitive(IDirect3DDevice7 *iface, D3DPRIMITIVETYPE primitive_type, DWORD fvf, void *vertices, DWORD vertex_count, DWORD flags) @@ -3483,8 +3492,7 @@ static HRESULT d3d_device7_DrawPrimitive(IDirect3DDevice7 *iface, wined3d_stateblock_set_vertex_declaration(device->state, ddraw_find_decl(device->ddraw, fvf)); wined3d_device_context_set_primitive_type(device->immediate_context, wined3d_primitive_type_from_ddraw(primitive_type), 0); - wined3d_device_apply_stateblock(device->wined3d_device, device->state); - d3d_device_sync_surfaces(device); + d3d_device_apply_state(device, FALSE); wined3d_device_context_draw(device->immediate_context, vb_pos / stride, vertex_count, 0, 0);
done: @@ -3636,8 +3644,7 @@ static HRESULT d3d_device7_DrawIndexedPrimitive(IDirect3DDevice7 *iface, wined3d_stateblock_set_vertex_declaration(device->state, ddraw_find_decl(device->ddraw, fvf)); wined3d_device_context_set_primitive_type(device->immediate_context, wined3d_primitive_type_from_ddraw(primitive_type), 0); - wined3d_device_apply_stateblock(device->wined3d_device, device->state); - d3d_device_sync_surfaces(device); + d3d_device_apply_state(device, FALSE); wined3d_device_context_draw_indexed(device->immediate_context, (int)(vb_pos / stride) - min_index, ib_pos / sizeof(*indices), index_count, 0, 0);
@@ -3948,8 +3955,7 @@ static HRESULT d3d_device7_DrawPrimitiveStrided(IDirect3DDevice7 *iface, D3DPRIM
wined3d_device_context_set_primitive_type(device->immediate_context, wined3d_primitive_type_from_ddraw(primitive_type), 0); - wined3d_device_apply_stateblock(device->wined3d_device, device->state); - d3d_device_sync_surfaces(device); + d3d_device_apply_state(device, FALSE); wined3d_device_context_draw(device->immediate_context, vb_pos / dst_stride, vertex_count, 0, 0);
done: @@ -4054,8 +4060,7 @@ static HRESULT d3d_device7_DrawIndexedPrimitiveStrided(IDirect3DDevice7 *iface, wined3d_stateblock_set_vertex_declaration(device->state, ddraw_find_decl(device->ddraw, fvf)); wined3d_device_context_set_primitive_type(device->immediate_context, wined3d_primitive_type_from_ddraw(primitive_type), 0); - wined3d_device_apply_stateblock(device->wined3d_device, device->state); - d3d_device_sync_surfaces(device); + d3d_device_apply_state(device, FALSE); wined3d_device_context_draw_indexed(device->immediate_context, vb_pos / vtx_dst_stride, ib_pos / sizeof(WORD), index_count, 0, 0);
@@ -4181,8 +4186,7 @@ static HRESULT d3d_device7_DrawPrimitiveVB(IDirect3DDevice7 *iface, D3DPRIMITIVE /* Now draw the primitives */ wined3d_device_context_set_primitive_type(device->immediate_context, wined3d_primitive_type_from_ddraw(primitive_type), 0); - wined3d_device_apply_stateblock(device->wined3d_device, device->state); - d3d_device_sync_surfaces(device); + d3d_device_apply_state(device, FALSE); wined3d_device_context_draw(device->immediate_context, start_vertex, vertex_count, 0, 0);
wined3d_mutex_unlock(); @@ -4318,8 +4322,7 @@ static HRESULT d3d_device7_DrawIndexedPrimitiveVB(IDirect3DDevice7 *iface,
wined3d_device_context_set_primitive_type(device->immediate_context, wined3d_primitive_type_from_ddraw(primitive_type), 0); - wined3d_device_apply_stateblock(device->wined3d_device, device->state); - d3d_device_sync_surfaces(device); + d3d_device_apply_state(device, FALSE); wined3d_device_context_draw_indexed(device->immediate_context, start_vertex, ib_pos / sizeof(WORD), index_count, 0, 0);
@@ -5183,8 +5186,7 @@ static HRESULT d3d_device7_Clear(IDirect3DDevice7 *iface, DWORD count, }
wined3d_mutex_lock(); - wined3d_stateblock_apply_clear_state(device->state, device->wined3d_device); - d3d_device_sync_rendertarget(device); + d3d_device_apply_state(device, TRUE); hr = wined3d_device_clear(device->wined3d_device, count, (RECT *)rects, flags, &c, z, stencil); wined3d_mutex_unlock();
diff --git a/dlls/ddraw/executebuffer.c b/dlls/ddraw/executebuffer.c index b0d60c6fb65..84bf091db1b 100644 --- a/dlls/ddraw/executebuffer.c +++ b/dlls/ddraw/executebuffer.c @@ -80,8 +80,7 @@ HRESULT d3d_execute_buffer_execute(struct d3d_execute_buffer *buffer, struct d3d wined3d_stateblock_set_vertex_declaration(device->state, ddraw_find_decl(device->ddraw, D3DFVF_TLVERTEX));
- wined3d_device_apply_stateblock(device->wined3d_device, device->state); - d3d_device_sync_surfaces(device); + d3d_device_apply_state(device, FALSE); for (i = 0; i < count; ++i) wined3d_device_context_draw(device->immediate_context, p[i].wFirst, p[i].wCount, 0, 0);
@@ -189,8 +188,7 @@ HRESULT d3d_execute_buffer_execute(struct d3d_execute_buffer *buffer, struct d3d wined3d_stateblock_set_vertex_declaration(device->state, ddraw_find_decl(device->ddraw, D3DFVF_TLVERTEX)); wined3d_stateblock_set_index_buffer(device->state, buffer->index_buffer, WINED3DFMT_R16_UINT); - wined3d_device_apply_stateblock(device->wined3d_device, device->state); - d3d_device_sync_surfaces(device); + d3d_device_apply_state(device, FALSE); wined3d_device_context_draw_indexed(device->immediate_context, 0, index_pos, index_count, 0, 0);
buffer->index_pos = index_pos + index_count;
From: Paul Gofman pgofman@codeweavers.com
--- dlls/ddraw/ddraw_private.h | 1 + dlls/ddraw/device.c | 8 ++++++++ dlls/ddraw/tests/ddraw2.c | 2 +- dlls/ddraw/tests/ddraw4.c | 2 +- dlls/ddraw/tests/ddraw7.c | 2 +- dlls/wined3d/stateblock.c | 7 +++++++ dlls/wined3d/wined3d.spec | 1 + include/wine/wined3d.h | 2 ++ 8 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/dlls/ddraw/ddraw_private.h b/dlls/ddraw/ddraw_private.h index 882ff4c0708..bd1df8e1b82 100644 --- a/dlls/ddraw/ddraw_private.h +++ b/dlls/ddraw/ddraw_private.h @@ -114,6 +114,7 @@ struct ddraw /* D3D things */ HWND d3d_window; struct list d3ddevice_list; + struct d3d_device *device_last_applied_state; int d3dversion;
/* Various HWNDs */ diff --git a/dlls/ddraw/device.c b/dlls/ddraw/device.c index 067dbf63485..e3c3f7197ea 100644 --- a/dlls/ddraw/device.c +++ b/dlls/ddraw/device.c @@ -325,6 +325,9 @@ static ULONG WINAPI d3d_device_inner_Release(IUnknown *iface) if (This->recording) wined3d_stateblock_decref(This->recording);
+ if (This->ddraw->device_last_applied_state == This) + This->ddraw->device_last_applied_state = NULL; + /* Releasing the render target below may release the last reference to the ddraw object. Detach * the device from it before so it doesn't try to save / restore state on the teared down device. */ if (This->ddraw) @@ -3451,6 +3454,11 @@ void d3d_device_sync_surfaces(struct d3d_device *device)
void d3d_device_apply_state(struct d3d_device *device, BOOL clear_state) { + if (device->ddraw->device_last_applied_state != device) + { + wined3d_stateblock_savedstates_set_all(device->wined3d_device, device->state); + device->ddraw->device_last_applied_state = device; + } if (clear_state) wined3d_stateblock_apply_clear_state(device->state, device->wined3d_device); else diff --git a/dlls/ddraw/tests/ddraw2.c b/dlls/ddraw/tests/ddraw2.c index e0818c5f62b..2336f09032d 100644 --- a/dlls/ddraw/tests/ddraw2.c +++ b/dlls/ddraw/tests/ddraw2.c @@ -16709,7 +16709,7 @@ static void test_multiple_devices(void) ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); hr = IDirect3DDevice2_EndScene(device); colour = get_surface_color(surface, 320, 240); - todo_wine ok(colour == 0x0000ff, "got %#lx.\n", colour); + ok(colour == 0x0000ff, "got %#lx.\n", colour);
IDirect3DTexture2_Release(texture2); IDirect3DTexture2_Release(texture); diff --git a/dlls/ddraw/tests/ddraw4.c b/dlls/ddraw/tests/ddraw4.c index 605d70d4b6d..88fe35e5ebc 100644 --- a/dlls/ddraw/tests/ddraw4.c +++ b/dlls/ddraw/tests/ddraw4.c @@ -19715,7 +19715,7 @@ static void test_multiple_devices(void) ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); hr = IDirect3DDevice3_EndScene(device); colour = get_surface_color(surface, 320, 240); - todo_wine ok(colour == 0x0000ff, "got %#lx.\n", colour); + ok(colour == 0x0000ff, "got %#lx.\n", colour);
IDirect3DMaterial3_Release(material); IDirect3DViewport3_Release(viewport); diff --git a/dlls/ddraw/tests/ddraw7.c b/dlls/ddraw/tests/ddraw7.c index f10c39f40ff..6a173f64f67 100644 --- a/dlls/ddraw/tests/ddraw7.c +++ b/dlls/ddraw/tests/ddraw7.c @@ -20176,7 +20176,7 @@ static void test_multiple_devices(void) ok(hr == DD_OK, "Got unexpected hr %#lx.\n", hr); hr = IDirect3DDevice7_EndScene(device); colour = get_surface_color(surface, 320, 240); - todo_wine ok(colour == 0x0000ff, "got %#lx.\n", colour); + ok(colour == 0x0000ff, "got %#lx.\n", colour);
refcount = IDirect3DDevice3_Release(device); ok(!refcount, "Device has %lu references left.\n", refcount); diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c index 80c1a6ea5b7..954b0f76547 100644 --- a/dlls/wined3d/stateblock.c +++ b/dlls/wined3d/stateblock.c @@ -309,6 +309,13 @@ static void stateblock_savedstates_set_all(struct wined3d_saved_states *states, memset(states->vs_consts_f, 0xffu, sizeof(states->vs_consts_f)); }
+void CDECL wined3d_stateblock_savedstates_set_all(struct wined3d_device *device, struct wined3d_stateblock *stateblock) +{ + const struct wined3d_d3d_info *d3d_info = &device->adapter->d3d_info; + + stateblock_savedstates_set_all(&stateblock->changed, d3d_info->limits.vs_uniform_count, d3d_info->limits.ps_uniform_count); +} + static void stateblock_savedstates_set_pixel(struct wined3d_saved_states *states, const DWORD num_constants) { DWORD texture_mask = 0; diff --git a/dlls/wined3d/wined3d.spec b/dlls/wined3d/wined3d.spec index 16c7624eb9c..846317a824c 100644 --- a/dlls/wined3d/wined3d.spec +++ b/dlls/wined3d/wined3d.spec @@ -245,6 +245,7 @@ @ cdecl wined3d_stateblock_init_contained_states(ptr) @ cdecl wined3d_stateblock_multiply_transform(ptr long ptr) @ cdecl wined3d_stateblock_reset(ptr) +@ cdecl wined3d_stateblock_savedstates_set_all(ptr ptr) @ cdecl wined3d_stateblock_set_base_vertex_index(ptr long) @ cdecl wined3d_stateblock_set_clip_plane(ptr long ptr) @ cdecl wined3d_stateblock_set_index_buffer(ptr ptr long) diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h index b9ae23bac16..36163d50af5 100644 --- a/include/wine/wined3d.h +++ b/include/wine/wined3d.h @@ -2369,6 +2369,8 @@ ULONG __cdecl wined3d_depth_stencil_state_incref(struct wined3d_depth_stencil_st
HRESULT __cdecl wined3d_device_acquire_focus_window(struct wined3d_device *device, HWND window); void __cdecl wined3d_device_apply_stateblock(struct wined3d_device *device, struct wined3d_stateblock *stateblock); +void __cdecl wined3d_stateblock_savedstates_set_all(struct wined3d_device *device, struct wined3d_stateblock *stateblock); + HRESULT __cdecl wined3d_device_begin_scene(struct wined3d_device *device); HRESULT __cdecl wined3d_device_clear(struct wined3d_device *device, unsigned int rect_count, const RECT *rects, uint32_t flags, const struct wined3d_color *color, float z, unsigned int stencil);
From: Paul Gofman pgofman@codeweavers.com
--- dlls/ddraw/tests/ddraw2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dlls/ddraw/tests/ddraw2.c b/dlls/ddraw/tests/ddraw2.c index 2336f09032d..828a3ff857b 100644 --- a/dlls/ddraw/tests/ddraw2.c +++ b/dlls/ddraw/tests/ddraw2.c @@ -16821,9 +16821,9 @@ static void test_d3d_state_reset(void) ok(hr == DD_OK, "got %#lx.\n", hr);
IDirect3DViewport2_Release(viewport); + IDirect3DDevice2_Release(device); IDirectDrawSurface_Release(surface); IDirectDraw2_Release(ddraw); - IDirect3DDevice2_Release(device); DestroyWindow(window); }
Hi,
It looks like your patch introduced the new failures shown below. Please investigate and fix them before resubmitting your patch. If they are not new, fixing them anyway would help a lot. Otherwise please ask for the known failures list to be updated.
The tests also ran into some preexisting test failures. If you know how to fix them that would be helpful. See the TestBot job for the details:
The full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=150484
Your paranoid android.
=== w10pro64 (64 bit report) ===
ddraw: ddraw4.c:2822: Test failed: Expected message 0x46, but didn't receive it. ddraw4.c:2945: Test failed: Failed to set foreground window. ddraw4.c:2953: Test failed: Failed to set foreground window. ddraw4.c:2979: Test failed: Expected window style 0x14cf0000, got 0x4cf0000. ddraw4.c:2982: Test failed: Expected window extended style 0x108, got 0x100. ddraw4.c:2989: Test failed: Expected window extended style 0x108, got 0x100. ddraw4.c:2998: Test failed: Expected window extended style 0x108, got 0x100. ddraw4.c:3007: Test failed: Expected window extended style 0x108, got 0x100. ddraw4.c:3010: Test failed: Failed to set foreground window. ddraw4.c:3017: Test failed: Expected window style 0x14cf0000, got 0x4cf0000. ddraw4.c:3020: Test failed: Expected window extended style 0x108, got 0x100. ddraw4.c:3033: Test failed: Failed to set foreground window. ddraw4.c:3058: Test failed: Failed to set foreground window. ddraw4.c:3073: Test failed: Failed to set foreground window. ddraw4.c:3082: Test failed: Expected window extended style 0x108, got 0x100. ddraw4.c:3102: Test failed: Expected window extended style 0x108, got 0x100. ddraw4.c:3105: Test failed: Failed to set foreground window. ddraw4.c:3108: Test failed: Expected window style 0x34cf0000, got 0x14cf0000. ddraw4.c:3111: Test failed: Expected window extended style 0x108, got 0x100. ddraw4.c:3124: Test failed: Expected WS_EX_TOPMOST. ddraw4.c:3141: Test failed: Expected WS_EX_TOPMOST. ddraw4.c:3503: Test failed: Failed to set foreground window. ddraw4.c:3504: Test failed: Expected message 0x6, but didn't receive it. ddraw4.c:3511: Test failed: Got unexpected screen size 800x600. ddraw4.c:706: Test failed: Got unexpected wparam 0 for message 0x1c, expected 0x1. ddraw4.c:3517: Test failed: Expected message 0x5, but didn't receive it. ddraw4.c:3520: Test failed: Expected (0,0)-(640,480), got (-32000,-32000)-(-31840,-31972). ddraw4.c:3524: Test failed: Got unexpected screen size 1024x768. ddraw4.c:3537: Test failed: Expected message 0x46, but didn't receive it. ddraw4.c:3978: Test failed: Expected (0,0)-(1024,768), got (-8,-8)-(1032,736). ddraw4.c:4050: Test failed: Expected (0,0)-(640,480), got (-8,-8)-(648,448). ddraw4.c:4075: Test failed: Expected (0,0)-(640,480), got (-8,-8)-(648,448).
v2: - added patch which fixes a crash in test_d3d_state_reset(). The sequence of releasing ddraw objects matters on early ddraw versions (as they have unobvious refcounting), that was a reason for various test crashes in the past.