d3d11/tests: Introduce check_texture_color().

Signed-off-by: Józef Kucia <jkucia@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Józef Kucia 2016-03-01 22:20:01 +01:00 committed by Alexandre Julliard
parent 25f9fbcc6d
commit 0ac8dd6976
1 changed files with 41 additions and 43 deletions

View File

@ -85,6 +85,7 @@ struct texture_readback
ID3D11Resource *texture;
D3D11_MAPPED_SUBRESOURCE map_desc;
ID3D11DeviceContext *immediate_context;
unsigned int width, height;
};
static void get_texture_readback(ID3D11Texture2D *texture, struct texture_readback *rb)
@ -109,6 +110,9 @@ static void get_texture_readback(ID3D11Texture2D *texture, struct texture_readba
return;
}
rb->width = texture_desc.Width;
rb->height = texture_desc.Height;
ID3D11Device_GetImmediateContext(device, &rb->immediate_context);
ID3D11DeviceContext_CopyResource(rb->immediate_context, rb->texture, (ID3D11Resource *)texture);
@ -152,6 +156,35 @@ static DWORD get_texture_color(ID3D11Texture2D *texture, unsigned int x, unsigne
return color;
}
#define check_texture_color(t, c, d) check_texture_color_(__LINE__, t, c, d)
static void check_texture_color_(unsigned int line, ID3D11Texture2D *texture,
DWORD expected_color, BYTE max_diff)
{
struct texture_readback rb;
unsigned int x = 0, y = 0;
BOOL all_match = TRUE;
DWORD color = 0;
get_texture_readback(texture, &rb);
for (y = 0; y < rb.height; ++y)
{
for (x = 0; x < rb.width; ++x)
{
color = get_readback_color(&rb, x, y);
if (!compare_color(color, expected_color, max_diff))
{
all_match = FALSE;
break;
}
}
if (!all_match)
break;
}
release_texture_readback(&rb);
ok_(__FILE__, line)(all_match,
"Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
}
static ID3D11Device *create_device(const D3D_FEATURE_LEVEL *feature_level)
{
ID3D11Device *device;
@ -3580,7 +3613,6 @@ static void test_multiple_render_targets(void)
D3D11_VIEWPORT vp;
ID3D11Buffer *vb;
ULONG refcount;
DWORD color;
HRESULT hr;
static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
@ -3733,14 +3765,10 @@ static void test_multiple_render_targets(void)
ID3D11DeviceContext_Draw(context, 4, 0);
color = get_texture_color(rt[0], 320, 240);
ok(compare_color(color, 0xffffffff, 2), "Got unexpected color 0x%08x.\n", color);
color = get_texture_color(rt[1], 320, 240);
ok(compare_color(color, 0x7f7f7f7f, 2), "Got unexpected color 0x%08x.\n", color);
color = get_texture_color(rt[2], 320, 240);
ok(compare_color(color, 0x33333333, 2), "Got unexpected color 0x%08x.\n", color);
color = get_texture_color(rt[3], 320, 240);
ok(compare_color(color, 0xff7f3300, 2), "Got unexpected color 0x%08x.\n", color);
check_texture_color(rt[0], 0xffffffff, 2);
check_texture_color(rt[1], 0x7f7f7f7f, 2);
check_texture_color(rt[2], 0x33333333, 2);
check_texture_color(rt[3], 0xff7f3300, 2);
ID3D11Buffer_Release(vb);
ID3D11PixelShader_Release(ps);
@ -3917,8 +3945,7 @@ static void test_scissor(void)
ID3D11DeviceContext_OMSetRenderTargets(immediate_context, 1, &rtv, NULL);
ID3D11DeviceContext_ClearRenderTargetView(immediate_context, rtv, red);
color = get_texture_color(backbuffer, 320, 240);
ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
check_texture_color(backbuffer, 0xff0000ff, 1);
ID3D11DeviceContext_Draw(immediate_context, 4, 0);
color = get_texture_color(backbuffer, 320, 60);
@ -4617,19 +4644,10 @@ static void test_update_subresource(void)
ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_rtv, red);
check_texture_color(backbuffer, 0x7f0000ff, 1);
ID3D11DeviceContext_Draw(context, 4, 0);
get_texture_readback(backbuffer, &rb);
for (i = 0; i < 4; ++i)
{
for (j = 0; j < 4; ++j)
{
color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
ok(compare_color(color, 0x00000000, 0),
"Got unexpected color 0x%08x at (%u, %u).\n", color, j, i);
}
}
release_texture_readback(&rb);
check_texture_color(backbuffer, 0x00000000, 0);
set_box(&box, 1, 1, 0, 3, 3, 1);
ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
@ -5113,11 +5131,7 @@ static void test_multisample_init(void)
ID3D11Device *device;
ID3D11DeviceContext *context;
ULONG refcount;
DWORD color;
HRESULT hr;
unsigned int x, y;
struct texture_readback rb;
BOOL all_zero = TRUE;
UINT count = 0;
HWND window;
IDXGISwapChain *swapchain;
@ -5166,23 +5180,7 @@ static void test_multisample_init(void)
ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)backbuffer, 0,
(ID3D11Resource *)multi, 0, DXGI_FORMAT_R8G8B8A8_UNORM);
get_texture_readback(backbuffer, &rb);
for (y = 0; y < 480; ++y)
{
for (x = 0; x < 640; ++x)
{
color = get_readback_color(&rb, x, y);
if (!compare_color(color, 0x00000000, 0))
{
all_zero = FALSE;
break;
}
}
if (!all_zero)
break;
}
release_texture_readback(&rb);
todo_wine ok(all_zero, "Got unexpected color 0x%08x, position %ux%u.\n", color, x, y);
todo_wine check_texture_color(backbuffer, 0x00000000, 0);
ID3D11DeviceContext_Release(context);
ID3D11RenderTargetView_Release(rtview);