d3d10core/tests: Add depth bias clamp tests.

Signed-off-by: Zebediah Figura <z.figura12@gmail.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2018-10-08 21:55:40 +03:30 committed by Alexandre Julliard
parent 42b5d88f2e
commit 2f2f0de550
1 changed files with 110 additions and 86 deletions

View File

@ -14975,6 +14975,15 @@ static void test_stream_output_vs(void)
release_test_context(&test_context);
}
static float clamp_depth_bias(float bias, float clamp)
{
if (clamp > 0.0f)
return min(bias, clamp);
if (clamp < 0.0f)
return max(bias, clamp);
return bias;
}
static void test_depth_bias(void)
{
struct vec3 vertices[] =
@ -14988,14 +14997,14 @@ static void test_depth_bias(void)
D3D10_RASTERIZER_DESC rasterizer_desc;
struct swapchain_desc swapchain_desc;
D3D10_TEXTURE2D_DESC texture_desc;
double m, r, bias, depth, data;
double m, bias, depth, data;
struct resource_readback rb;
ID3D10DepthStencilView *dsv;
unsigned int expected_value;
unsigned int x, y, i, j, k;
ID3D10RasterizerState *rs;
ID3D10Texture2D *texture;
unsigned int format_idx;
unsigned int x, y, i, j;
unsigned int shift = 0;
ID3D10Device *device;
float *depth_values;
@ -15022,6 +15031,10 @@ static void test_depth_bias(void)
-10000, -1000, -100, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 50, 100, 200, 500, 1000, 10000,
};
static const float bias_clamp_tests[] =
{
0.0f, -1e-5f, 1e-5f,
};
static const float quad_slopes[] =
{
0.0f, 0.5f, 1.0f
@ -15114,6 +15127,10 @@ static void test_depth_bias(void)
for (j = 0; j < ARRAY_SIZE(bias_tests); ++j)
{
rasterizer_desc.DepthBias = bias_tests[j];
for (k = 0; k < ARRAY_SIZE(bias_clamp_tests); ++k)
{
rasterizer_desc.DepthBiasClamp = bias_clamp_tests[k];
ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &rs);
ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
ID3D10Device_RSSetState(device, rs);
@ -15123,13 +15140,14 @@ static void test_depth_bias(void)
{
case DXGI_FORMAT_D32_FLOAT:
bias = rasterizer_desc.DepthBias * pow(2.0f, quads[i].exponent - 23.0f);
bias = clamp_depth_bias(bias, rasterizer_desc.DepthBiasClamp);
depth = min(max(0.0f, quads[i].z + bias), 1.0f);
check_texture_float(texture, depth, 2);
break;
case DXGI_FORMAT_D24_UNORM_S8_UINT:
r = 1.0f / 16777215.0f;
bias = rasterizer_desc.DepthBias * r;
bias = clamp_depth_bias(rasterizer_desc.DepthBias / 16777215.0f,
rasterizer_desc.DepthBiasClamp);
depth = min(max(0.0f, quads[i].z + bias), 1.0f);
get_texture_readback(texture, 0, &rb);
@ -15149,8 +15167,8 @@ static void test_depth_bias(void)
release_resource_readback(&rb);
break;
case DXGI_FORMAT_D16_UNORM:
r = 1.0f / 65535.0f;
bias = rasterizer_desc.DepthBias * r;
bias = clamp_depth_bias(rasterizer_desc.DepthBias / 65535.0f,
rasterizer_desc.DepthBiasClamp);
depth = min(max(0.0f, quads[i].z + bias), 1.0f);
get_texture_readback(texture, 0, &rb);
@ -15173,6 +15191,7 @@ static void test_depth_bias(void)
ID3D10RasterizerState_Release(rs);
}
}
}
/* SlopeScaledDepthBias */
rasterizer_desc.DepthBias = 0;
@ -15212,6 +15231,10 @@ static void test_depth_bias(void)
for (j = 0; j < ARRAY_SIZE(slope_scaled_bias_tests); ++j)
{
rasterizer_desc.SlopeScaledDepthBias = slope_scaled_bias_tests[j];
for (k = 0; k < ARRAY_SIZE(bias_clamp_tests); ++k)
{
rasterizer_desc.DepthBiasClamp = bias_clamp_tests[k];
ID3D10Device_CreateRasterizerState(device, &rasterizer_desc, &rs);
ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
ID3D10Device_RSSetState(device, rs);
@ -15219,7 +15242,7 @@ static void test_depth_bias(void)
draw_quad(&test_context);
m = quad_slopes[i] / texture_desc.Height;
bias = rasterizer_desc.SlopeScaledDepthBias * m;
bias = clamp_depth_bias(rasterizer_desc.SlopeScaledDepthBias * m, rasterizer_desc.DepthBiasClamp);
get_texture_readback(texture, 0, &rb);
for (y = 0; y < texture_desc.Height; ++y)
{
@ -15255,6 +15278,7 @@ static void test_depth_bias(void)
ID3D10RasterizerState_Release(rs);
}
}
}
ID3D10Texture2D_Release(texture);
ID3D10DepthStencilView_Release(dsv);