ddraw/tests: Introduce compare_uint().

Analogous to compare_float().

Signed-off-by: Chip Davis <cdavis@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Chip Davis 2020-03-30 20:30:07 +04:30 committed by Alexandre Julliard
parent efe7c309cd
commit d5f25c2cd7
5 changed files with 70 additions and 55 deletions

View File

@ -49,18 +49,6 @@ struct create_window_thread_param
HANDLE thread;
};
static BOOL compare_color(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
{
if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
c1 >>= 8; c2 >>= 8;
if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
c1 >>= 8; c2 >>= 8;
if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
c1 >>= 8; c2 >>= 8;
if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
return TRUE;
}
static BOOL compare_float(float f, float g, unsigned int ulps)
{
int x = *(int *)&f;
@ -85,6 +73,21 @@ static BOOL compare_vec4(const struct vec4 *vec, float x, float y, float z, floa
&& compare_float(vec->w, w, ulps);
}
static BOOL compare_uint(unsigned int x, unsigned int y, unsigned int max_diff)
{
unsigned int diff = x > y ? x - y : y - x;
return diff <= max_diff;
}
static BOOL compare_color(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
{
return compare_uint(c1 & 0xff, c2 & 0xff, max_diff)
&& compare_uint((c1 >> 8) & 0xff, (c2 >> 8) & 0xff, max_diff)
&& compare_uint((c1 >> 16) & 0xff, (c2 >> 16) & 0xff, max_diff)
&& compare_uint((c1 >> 24) & 0xff, (c2 >> 24) & 0xff, max_diff);
}
static BOOL ddraw_get_identifier(IDirectDraw *ddraw, DDDEVICEIDENTIFIER *identifier)
{
IDirectDraw4 *ddraw4;
@ -11770,7 +11773,7 @@ static void test_depth_readback(void)
depth = *((DWORD *)ptr) & z_mask;
expected_depth = (x * (0.9 / 640.0) + y * (0.1 / 480.0)) * z_mask;
max_diff = ((0.5f * 0.9f) / 640.0f) * z_mask;
ok(abs(expected_depth - depth) <= max_diff,
ok(compare_uint(expected_depth, depth, max_diff),
"z_depth %u: Got depth 0x%08x (diff %d), expected 0x%08x+/-%u, at %u, %u.\n",
z_depth, depth, expected_depth - depth, expected_depth, max_diff, x, y);
}

View File

@ -50,18 +50,6 @@ struct create_window_thread_param
HANDLE thread;
};
static BOOL compare_color(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
{
if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
c1 >>= 8; c2 >>= 8;
if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
c1 >>= 8; c2 >>= 8;
if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
c1 >>= 8; c2 >>= 8;
if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
return TRUE;
}
static BOOL compare_float(float f, float g, unsigned int ulps)
{
int x = *(int *)&f;
@ -86,6 +74,21 @@ static BOOL compare_vec4(const struct vec4 *vec, float x, float y, float z, floa
&& compare_float(vec->w, w, ulps);
}
static BOOL compare_uint(unsigned int x, unsigned int y, unsigned int max_diff)
{
unsigned int diff = x > y ? x - y : y - x;
return diff <= max_diff;
}
static BOOL compare_color(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
{
return compare_uint(c1 & 0xff, c2 & 0xff, max_diff)
&& compare_uint((c1 >> 8) & 0xff, (c2 >> 8) & 0xff, max_diff)
&& compare_uint((c1 >> 16) & 0xff, (c2 >> 16) & 0xff, max_diff)
&& compare_uint((c1 >> 24) & 0xff, (c2 >> 24) & 0xff, max_diff);
}
static BOOL ddraw_get_identifier(IDirectDraw2 *ddraw, DDDEVICEIDENTIFIER *identifier)
{
IDirectDraw4 *ddraw4;
@ -12749,10 +12752,10 @@ static void test_depth_readback(void)
/* The ddraw2 version of this test behaves similarly to the ddraw7 version on Nvidia GPUs,
* except that we only have D16 (broken on geforce 9) and D24X8 (broken on geforce 7) available.
* Accept all nvidia GPUs as broken here, but still expect one of the formats to pass. */
ok(abs(expected_depth - depth) <= max_diff || ddraw_is_nvidia(ddraw),
ok(compare_uint(expected_depth, depth, max_diff) || ddraw_is_nvidia(ddraw),
"Test %u: Got depth 0x%08x (diff %d), expected 0x%08x+/-%u, at %u, %u.\n",
i, depth, expected_depth - depth, expected_depth, max_diff, x, y);
if (abs(expected_depth - depth) > max_diff)
if (!compare_uint(expected_depth, depth, max_diff))
all_pass = FALSE;
}
}

View File

@ -80,16 +80,19 @@ static BOOL compare_vec4(const struct vec4 *vec, float x, float y, float z, floa
&& compare_float(vec->w, w, ulps);
}
static BOOL compare_uint(unsigned int x, unsigned int y, unsigned int max_diff)
{
unsigned int diff = x > y ? x - y : y - x;
return diff <= max_diff;
}
static BOOL compare_color(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
{
if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
c1 >>= 8; c2 >>= 8;
if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
c1 >>= 8; c2 >>= 8;
if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
c1 >>= 8; c2 >>= 8;
if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
return TRUE;
return compare_uint(c1 & 0xff, c2 & 0xff, max_diff)
&& compare_uint((c1 >> 8) & 0xff, (c2 >> 8) & 0xff, max_diff)
&& compare_uint((c1 >> 16) & 0xff, (c2 >> 16) & 0xff, max_diff)
&& compare_uint((c1 >> 24) & 0xff, (c2 >> 24) & 0xff, max_diff);
}
static BOOL ddraw_get_identifier(IDirectDraw4 *ddraw, DDDEVICEIDENTIFIER *identifier)
@ -15282,10 +15285,10 @@ static void test_depth_readback(void)
* returns 0 for that format. Give up on pre-filtering formats, accept Nvidia as generally
* broken here, but still expect at least one format (D16 or D24X8 in practise) to pass. */
todo_wine_if(tests[i].todo)
ok(abs(expected_depth - depth) <= max_diff || ddraw_is_nvidia(ddraw),
ok(compare_uint(expected_depth, depth, max_diff) || ddraw_is_nvidia(ddraw),
"Test %u: Got depth 0x%08x (diff %d), expected 0x%08x+/-%u, at %u, %u.\n",
i, depth, expected_depth - depth, expected_depth, max_diff, x, y);
if (abs(expected_depth - depth) > max_diff)
if (!compare_uint(expected_depth, depth, max_diff))
all_pass = FALSE;
hr = IDirectDrawSurface4_Unlock(ds, &r);

View File

@ -87,16 +87,19 @@ static BOOL compare_vec4(const struct vec4 *vec, float x, float y, float z, floa
&& compare_float(vec->w, w, ulps);
}
static BOOL compare_uint(unsigned int x, unsigned int y, unsigned int max_diff)
{
unsigned int diff = x > y ? x - y : y - x;
return diff <= max_diff;
}
static BOOL compare_color(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
{
if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
c1 >>= 8; c2 >>= 8;
if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
c1 >>= 8; c2 >>= 8;
if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
c1 >>= 8; c2 >>= 8;
if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
return TRUE;
return compare_uint(c1 & 0xff, c2 & 0xff, max_diff)
&& compare_uint((c1 >> 8) & 0xff, (c2 >> 8) & 0xff, max_diff)
&& compare_uint((c1 >> 16) & 0xff, (c2 >> 16) & 0xff, max_diff)
&& compare_uint((c1 >> 24) & 0xff, (c2 >> 24) & 0xff, max_diff);
}
static ULONG get_refcount(IUnknown *iface)
@ -14726,11 +14729,11 @@ static void test_depth_readback(void)
* Arx Fatalis is broken on the Geforce 9 in the same way it was broken in Wine (bug 43654).
* The !tests[i].s_depth is supposed to rule out D16 on GF9 and D24X8 on GF7. */
todo_wine_if(tests[i].todo)
ok(abs(expected_depth - depth) <= max_diff
ok(compare_uint(expected_depth, depth, max_diff)
|| (ddraw_is_nvidia(ddraw) && (all_zero || all_one || !tests[i].s_depth)),
"Test %u: Got depth 0x%08x (diff %d), expected 0x%08x+/-%u, at %u, %u.\n",
i, depth, expected_depth - depth, expected_depth, max_diff, x, y);
if (abs(expected_depth - depth) > max_diff)
if (!compare_uint(expected_depth, depth, max_diff))
all_pass = FALSE;
hr = IDirectDrawSurface7_Unlock(ds, &r);

View File

@ -45,16 +45,19 @@ static BOOL refdevice = FALSE;
static HRESULT (WINAPI *pDirectDrawCreateEx)(GUID *driver_guid,
void **ddraw, REFIID interface_iid, IUnknown *outer);
static BOOL compare_uint(unsigned int x, unsigned int y, unsigned int max_diff)
{
unsigned int diff = x > y ? x - y : y - x;
return diff <= max_diff;
}
static BOOL color_match(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
{
if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
c1 >>= 8; c2 >>= 8;
if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
c1 >>= 8; c2 >>= 8;
if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
c1 >>= 8; c2 >>= 8;
if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
return TRUE;
return compare_uint(c1 & 0xff, c2 & 0xff, max_diff)
&& compare_uint((c1 >> 8) & 0xff, (c2 >> 8) & 0xff, max_diff)
&& compare_uint((c1 >> 16) & 0xff, (c2 >> 16) & 0xff, max_diff)
&& compare_uint((c1 >> 24) & 0xff, (c2 >> 24) & 0xff, max_diff);
}
static HRESULT WINAPI enum_z_fmt(DDPIXELFORMAT *fmt, void *ctx)