From 70edcf2f216f1cf9f7732b48e7b0d14a88937d22 Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Tue, 26 Apr 2022 23:52:30 -0500 Subject: [PATCH] d3d8/tests: Add more tests for D3DLOCK_NO_DIRTY_UPDATE. Signed-off-by: Zebediah Figura Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- dlls/d3d8/tests/visual.c | 87 +++++++++++++++++++++++++++++++++++----- 1 file changed, 76 insertions(+), 11 deletions(-) diff --git a/dlls/d3d8/tests/visual.c b/dlls/d3d8/tests/visual.c index 41fc0cbf16a..87b3c120b4f 100644 --- a/dlls/d3d8/tests/visual.c +++ b/dlls/d3d8/tests/visual.c @@ -5639,7 +5639,7 @@ static void add_dirty_rect_test(void) ok(color_match(color, 0x0000ff00, 1), "Expected color 0x0000ff00, got 0x%08x.\n", color); - /* Locks with NO_DIRTY_UPDATE are ignored. */ + /* UpdateTexture() ignores locks made with D3DLOCK_NO_DIRTY_UPDATE. */ fill_surface(surface_src_green, 0x00000080, D3DLOCK_NO_DIRTY_UPDATE); hr = IDirect3DDevice8_UpdateTexture(device, (IDirect3DBaseTexture8 *)tex_src_green, (IDirect3DBaseTexture8 *)tex_dst2); @@ -5651,6 +5651,15 @@ static void add_dirty_rect_test(void) hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL); ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr); + /* Manually copying the surface works, though. */ + hr = IDirect3DDevice8_CopyRects(device, surface_src_green, NULL, 0, surface_dst2, NULL); + ok(hr == D3D_OK, "Failed to copy rects, hr %#x.\n", hr); + add_dirty_rect_test_draw(device); + color = getPixelColor(device, 320, 240); + ok(color_match(color, 0x00000080, 1), "Got unexpected colour 0x%08x.\n", color); + hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL); + ok(hr == D3D_OK, "Failed to present, hr %#x.\n", hr); + /* Readonly maps write to D3DPOOL_SYSTEMMEM, but don't record a dirty rectangle. */ fill_surface(surface_src_green, 0x000000ff, D3DLOCK_READONLY); hr = IDirect3DDevice8_UpdateTexture(device, (IDirect3DBaseTexture8 *)tex_src_green, @@ -5658,8 +5667,7 @@ static void add_dirty_rect_test(void) ok(SUCCEEDED(hr), "Failed to update texture, hr %#x.\n", hr); add_dirty_rect_test_draw(device); color = getPixelColor(device, 320, 240); - ok(color_match(color, 0x0000ff00, 1), - "Expected color 0x0000ff00, got 0x%08x.\n", color); + ok(color_match(color, 0x00000080, 1), "Got unexpected colour 0x%08x.\n", color); hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL); ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr); @@ -5724,7 +5732,7 @@ static void add_dirty_rect_test(void) hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL); ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr); - /* UpdateSurface ignores the missing dirty marker. */ + /* CopyRects() ignores the missing dirty marker. */ hr = IDirect3DDevice8_UpdateTexture(device, (IDirect3DBaseTexture8 *)tex_src_red, (IDirect3DBaseTexture8 *)tex_dst2); hr = IDirect3DDevice8_CopyRects(device, surface_src_green, NULL, 0, surface_dst2, NULL); @@ -5775,17 +5783,28 @@ static void add_dirty_rect_test(void) ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr); /* AddDirtyRect uploads the new contents. - * Side note, not tested in the test: Partial surface updates work, and two separate - * dirty rectangles are tracked individually. Tested on Nvidia Kepler, other drivers - * untested. */ - hr = IDirect3DTexture8_AddDirtyRect(tex_managed, NULL); - ok(SUCCEEDED(hr), "Failed to add dirty rect, hr %#x.\n", hr); + * Partial surface updates work, and two separate dirty rectangles are + * tracked individually. Tested on Nvidia Kepler, other drivers untested. */ + hr = IDirect3DTexture8_AddDirtyRect(tex_managed, &part_rect); + ok(hr == S_OK, "Failed to add dirty rect, hr %#x.\n", hr); add_dirty_rect_test_draw(device); color = getPixelColor(device, 320, 240); - ok(color_match(color, 0x0000ff00, 1), - "Expected color 0x0000ff00, got 0x%08x.\n", color); + ok(color_match(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color); + color = getPixelColor(device, 1, 1); + todo_wine ok(color_match(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color); hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL); ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr); + + hr = IDirect3DTexture8_AddDirtyRect(tex_managed, NULL); + ok(hr == S_OK, "Failed to add dirty rect, hr %#x.\n", hr); + add_dirty_rect_test_draw(device); + color = getPixelColor(device, 320, 240); + ok(color_match(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color); + color = getPixelColor(device, 1, 1); + ok(color_match(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color); + hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL); + ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr); + hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_MAXMIPLEVEL, 1); ok(SUCCEEDED(hr), "Failed to set texture stage state, hr %#x.\n", hr); add_dirty_rect_test_draw(device); @@ -5812,6 +5831,18 @@ static void add_dirty_rect_test(void) hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL); ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr); + /* Test blitting from a managed texture. */ + fill_surface(surface_managed0, 0x0000ff00, D3DLOCK_NO_DIRTY_UPDATE); + hr = IDirect3DDevice8_CopyRects(device, surface_managed0, NULL, 0, surface_dst2, NULL); + ok(hr == D3D_OK, "Failed to update surface, hr %#x.\n", hr); + hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *)tex_dst2); + ok(hr == D3D_OK, "Failed to set texture, hr %#x.\n", hr); + add_dirty_rect_test_draw(device); + color = getPixelColor(device, 320, 240); + ok(color_match(color, 0x0000ff00, 1), "Got unexpected colour 0x%08x.\n", color); + hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL); + ok(hr == D3D_OK, "Failed to present, hr %#x.\n", hr); + /* Tests with dynamic textures */ fill_surface(surface_dynamic, 0x0000ffff, 0); hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *)tex_dynamic); @@ -5869,6 +5900,40 @@ static void add_dirty_rect_test(void) IDirect3DTexture8_Release(tex_dst2); IDirect3DTexture8_Release(tex_managed); IDirect3DTexture8_Release(tex_dynamic); + + /* As above, test CopyRect() after locking the source with + * D3DLOCK_NO_DIRTY_UPDATE, but this time do it immediately after creating + * the destination texture. This is a regression test for a previously + * broken code path. */ + + hr = IDirect3DDevice8_CreateTexture(device, 256, 256, 1, 0, D3DFMT_X8R8G8B8, + D3DPOOL_DEFAULT, &tex_dst2); + ok(hr == D3D_OK, "Failed to create texture, hr %#x.\n", hr); + hr = IDirect3DDevice8_CreateTexture(device, 256, 256, 1, 0, D3DFMT_X8R8G8B8, + D3DPOOL_SYSTEMMEM, &tex_src_green); + ok(hr == D3D_OK, "Failed to create texture, hr %#x.\n", hr); + + hr = IDirect3DTexture8_GetSurfaceLevel(tex_dst2, 0, &surface_dst2); + ok(hr == D3D_OK, "Failed to get surface level, hr %#x.\n", hr); + hr = IDirect3DTexture8_GetSurfaceLevel(tex_src_green, 0, &surface_src_green); + ok(hr == D3D_OK, "Failed to get surface level, hr %#x.\n", hr); + + hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *)tex_dst2); + ok(hr == D3D_OK, "Failed to set texture, hr %#x.\n", hr); + fill_surface(surface_src_green, 0x00ff0000, D3DLOCK_NO_DIRTY_UPDATE); + hr = IDirect3DDevice8_CopyRects(device, surface_src_green, NULL, 0, surface_dst2, NULL); + ok(hr == D3D_OK, "Failed to copy rects, hr %#x.\n", hr); + add_dirty_rect_test_draw(device); + color = getPixelColor(device, 320, 240); + todo_wine ok(color_match(color, 0x00ff0000, 1), "Got unexpected colour 0x%08x.\n", color); + hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL); + ok(hr == D3D_OK, "Failed to present, hr %#x.\n", hr); + + IDirect3DSurface8_Release(surface_dst2); + IDirect3DSurface8_Release(surface_src_green); + IDirect3DTexture8_Release(tex_dst2); + IDirect3DTexture8_Release(tex_src_green); + refcount = IDirect3DDevice8_Release(device); ok(!refcount, "Device has %u references left.\n", refcount); done: