d3d10core/tests: Test render to depth texture.

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-22 13:41:49 +01:00 committed by Alexandre Julliard
parent 53f4cc1a9e
commit 4037b48a4c
1 changed files with 181 additions and 14 deletions

View File

@ -2348,24 +2348,19 @@ static void test_scissor(void)
static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f}; static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
static const DWORD ps_code[] = static const DWORD ps_code[] =
{ {
/* float4 main(float4 position : SV_POSITION) : SV_Target #if 0
* { float4 main(float4 position : SV_POSITION) : SV_Target
* return float4(0.0, 1.0, 0.0, 1.0); {
* } */ return float4(0.0, 1.0, 0.0, 1.0);
0x43425844, 0xe70802a0, 0xee334047, 0x7bfd0c79, 0xaeff7804, 0x00000001, 0x000001b0, 0x00000005, }
0x00000034, 0x0000008c, 0x000000c0, 0x000000f4, 0x00000134, 0x46454452, 0x00000050, 0x00000000, #endif
0x00000000, 0x00000000, 0x0000001c, 0xffff0400, 0x00000100, 0x0000001c, 0x7263694d, 0x666f736f, 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, 0x6c69706d, 0x39207265, 0x2e30332e, 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
0x30303239, 0x3336312e, 0xab003438, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x54415453, 0x00000074, 0x00000002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000,
}; };
if (!init_test_context(&test_context)) if (!init_test_context(&test_context))
@ -5936,6 +5931,177 @@ static void test_clear_depth_stencil_view(void)
ok(!refcount, "Device has %u references left.\n", refcount); ok(!refcount, "Device has %u references left.\n", refcount);
} }
static void test_draw_depth_only(void)
{
ID3D10DepthStencilState *depth_stencil_state;
D3D10_DEPTH_STENCIL_DESC depth_stencil_desc;
struct d3d10core_test_context test_context;
ID3D10PixelShader *ps_color, *ps_depth;
D3D10_TEXTURE2D_DESC texture_desc;
D3D10_BUFFER_DESC buffer_desc;
ID3D10DepthStencilView *dsv;
struct texture_readback rb;
ID3D10Texture2D *texture;
ID3D10Device *device;
unsigned int i, j;
D3D10_VIEWPORT vp;
struct vec4 depth;
ID3D10Buffer *cb;
HRESULT hr;
static const DWORD ps_color_code[] =
{
#if 0
float4 main(float4 position : SV_POSITION) : SV_Target
{
return float4(0.0, 1.0, 0.0, 1.0);
}
#endif
0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
};
static const DWORD ps_depth_code[] =
{
#if 0
float depth;
float main() : SV_Depth
{
return depth;
}
#endif
0x43425844, 0x91af6cd0, 0x7e884502, 0xcede4f54, 0x6f2c9326, 0x00000001, 0x000000b0, 0x00000003,
0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0xffffffff,
0x00000e01, 0x445f5653, 0x68747065, 0xababab00, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x02000065, 0x0000c001, 0x05000036, 0x0000c001,
0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
};
if (!init_test_context(&test_context))
return;
device = test_context.device;
buffer_desc.ByteWidth = sizeof(depth);
buffer_desc.Usage = D3D10_USAGE_DEFAULT;
buffer_desc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
buffer_desc.CPUAccessFlags = 0;
buffer_desc.MiscFlags = 0;
hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &cb);
ok(SUCCEEDED(hr), "Failed to create constant buffer, hr %#x.\n", hr);
texture_desc.Width = 640;
texture_desc.Height = 480;
texture_desc.MipLevels = 1;
texture_desc.ArraySize = 1;
texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
texture_desc.SampleDesc.Count = 1;
texture_desc.SampleDesc.Quality = 0;
texture_desc.Usage = D3D10_USAGE_DEFAULT;
texture_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
texture_desc.CPUAccessFlags = 0;
texture_desc.MiscFlags = 0;
hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
hr = ID3D10Device_CreateDepthStencilView(device, (ID3D10Resource *)texture, NULL, &dsv);
ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
depth_stencil_desc.DepthEnable = TRUE;
depth_stencil_desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
depth_stencil_desc.DepthFunc = D3D10_COMPARISON_LESS;
depth_stencil_desc.StencilEnable = FALSE;
hr = ID3D10Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
hr = ID3D10Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), &ps_color);
ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
hr = ID3D10Device_CreatePixelShader(device, ps_depth_code, sizeof(ps_depth_code), &ps_depth);
ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
ID3D10Device_PSSetConstantBuffers(device, 0, 1, &cb);
ID3D10Device_PSSetShader(device, ps_color);
ID3D10Device_OMSetRenderTargets(device, 0, NULL, dsv);
ID3D10Device_OMSetDepthStencilState(device, depth_stencil_state, 0);
ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
check_texture_float(texture, 1.0f, 1);
draw_quad(&test_context);
check_texture_float(texture, 0.0f, 1);
ID3D10Device_PSSetShader(device, ps_depth);
depth.x = 0.7f;
ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &depth, 0, 0);
draw_quad(&test_context);
check_texture_float(texture, 0.0f, 1);
ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
check_texture_float(texture, 1.0f, 1);
draw_quad(&test_context);
check_texture_float(texture, 0.7f, 1);
depth.x = 0.8f;
ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &depth, 0, 0);
draw_quad(&test_context);
check_texture_float(texture, 0.7f, 1);
depth.x = 0.5f;
ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &depth, 0, 0);
draw_quad(&test_context);
check_texture_float(texture, 0.5f, 1);
ID3D10Device_ClearDepthStencilView(device, dsv, D3D10_CLEAR_DEPTH, 1.0f, 0);
depth.x = 0.1f;
for (i = 0; i < 4; ++i)
{
for (j = 0; j < 4; ++j)
{
depth.x = 1.0f / 16.0f * (j + 4 * i);
ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)cb, 0, NULL, &depth, 0, 0);
vp.TopLeftX = 160 * j;
vp.TopLeftY = 120 * i;
vp.Width = 160;
vp.Height = 120;
vp.MinDepth = 0.0f;
vp.MaxDepth = 1.0f;
ID3D10Device_RSSetViewports(device, 1, &vp);
draw_quad(&test_context);
}
}
get_texture_readback(texture, &rb);
for (i = 0; i < 4; ++i)
{
for (j = 0; j < 4; ++j)
{
float obtained_depth, expected_depth;
obtained_depth = get_readback_float(&rb, 80 + j * 160, 60 + i * 120);
expected_depth = 1.0f / 16.0f * (j + 4 * i);
ok(compare_float(obtained_depth, expected_depth, 1),
"Got unexpected depth %.8e at (%u, %u), expected %.8e.\n",
obtained_depth, j, i, expected_depth);
}
}
release_texture_readback(&rb);
ID3D10Buffer_Release(cb);
ID3D10PixelShader_Release(ps_color);
ID3D10PixelShader_Release(ps_depth);
ID3D10DepthStencilView_Release(dsv);
ID3D10DepthStencilState_Release(depth_stencil_state);
ID3D10Texture2D_Release(texture);
release_test_context(&test_context);
}
START_TEST(device) START_TEST(device)
{ {
test_feature_level(); test_feature_level();
@ -5970,4 +6136,5 @@ START_TEST(device)
test_cb_relative_addressing(); test_cb_relative_addressing();
test_swapchain_flip(); test_swapchain_flip();
test_clear_depth_stencil_view(); test_clear_depth_stencil_view();
test_draw_depth_only();
} }