d3d11/tests: Add test for depth/stencil shader resource views.

Signed-off-by: Józef Kucia <jkucia@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Józef Kucia 2016-12-09 11:30:49 +01:00 committed by Alexandre Julliard
parent a02fd72965
commit 7ed0e33388
1 changed files with 349 additions and 0 deletions

View File

@ -6287,6 +6287,354 @@ static void test_texture(void)
release_test_context(&test_context);
}
static void test_depth_stencil_sampling(void)
{
ID3D11PixelShader *ps_cmp, *ps_depth, *ps_stencil, *ps_depth_stencil;
ID3D11ShaderResourceView *depth_srv, *stencil_srv;
ID3D11SamplerState *cmp_sampler, *sampler;
D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
struct d3d11_test_context test_context;
ID3D11Texture2D *texture, *rt_texture;
D3D11_TEXTURE2D_DESC texture_desc;
D3D11_SAMPLER_DESC sampler_desc;
ID3D11DeviceContext *context;
ID3D11DepthStencilView *dsv;
ID3D11RenderTargetView *rtv;
struct vec4 ps_constant;
ID3D11Device *device;
ID3D11Buffer *cb;
unsigned int i;
HRESULT hr;
static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
static const DWORD ps_compare_code[] =
{
#if 0
Texture2D t;
SamplerComparisonState s;
float ref;
float4 main(float4 position : SV_Position) : SV_Target
{
return t.SampleCmp(s, float2(position.x / 640.0f, position.y / 480.0f), ref);
}
#endif
0x43425844, 0xc2e0d84e, 0x0522c395, 0x9ff41580, 0xd3ca29cc, 0x00000001, 0x00000164, 0x00000003,
0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000c8, 0x00000040,
0x00000032, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000, 0x00000000,
0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000046,
0x00100012, 0x00000000, 0x00100046, 0x00000000, 0x00107006, 0x00000000, 0x00106000, 0x00000000,
0x0020800a, 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000,
0x0100003e,
};
static const DWORD ps_sample_code[] =
{
#if 0
Texture2D t;
SamplerState s;
float4 main(float4 position : SV_Position) : SV_Target
{
return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
}
#endif
0x43425844, 0x7472c092, 0x5548f00e, 0xf4e007f1, 0x5970429c, 0x00000001, 0x00000134, 0x00000003,
0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
};
static const DWORD ps_stencil_code[] =
{
#if 0
Texture2D<uint4> t;
float4 main(float4 position : SV_Position) : SV_Target
{
float2 s;
t.GetDimensions(s.x, s.y);
return t.Load(int3(float3(s.x * position.x / 640.0f, s.y * position.y / 480.0f, 0))).y;
}
#endif
0x43425844, 0x929fced8, 0x2cd93320, 0x0591ece3, 0xee50d04a, 0x00000001, 0x000001a0, 0x00000003,
0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
0x00000041, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2,
0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000,
0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046,
0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032,
0x00000000, 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000, 0x00004002, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100556, 0x00000000, 0x0100003e,
};
static const DWORD ps_depth_stencil_code[] =
{
#if 0
SamplerState samp;
Texture2D depth_tex;
Texture2D<uint4> stencil_tex;
float main(float4 position: SV_Position) : SV_Target
{
float2 s, p;
float depth, stencil;
depth_tex.GetDimensions(s.x, s.y);
p = float2(s.x * position.x / 640.0f, s.y * position.y / 480.0f);
depth = depth_tex.Sample(samp, p).r;
stencil = stencil_tex.Load(int3(float3(p.x, p.y, 0))).y;
return depth + stencil;
}
#endif
0x43425844, 0x348f8377, 0x977d1ee0, 0x8cca4f35, 0xff5c5afc, 0x00000001, 0x000001fc, 0x00000003,
0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000160, 0x00000040,
0x00000058, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
0x04001858, 0x00107000, 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2, 0x00000000,
0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000,
0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032, 0x00000001,
0x00100046, 0x00000000, 0x09000045, 0x001000f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46,
0x00000000, 0x00106000, 0x00000000, 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000001, 0x00100e46, 0x00000001,
0x00107e46, 0x00000001, 0x05000056, 0x00100022, 0x00000000, 0x0010001a, 0x00000001, 0x07000000,
0x00102012, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
};
static const struct test
{
DXGI_FORMAT typeless_format;
DXGI_FORMAT dsv_format;
DXGI_FORMAT depth_view_format;
DXGI_FORMAT stencil_view_format;
}
tests[] =
{
{DXGI_FORMAT_R32G8X24_TYPELESS, DXGI_FORMAT_D32_FLOAT_S8X24_UINT,
DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS, DXGI_FORMAT_X32_TYPELESS_G8X24_UINT},
{DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_D32_FLOAT,
DXGI_FORMAT_R32_FLOAT},
{DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT,
DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_X24_TYPELESS_G8_UINT},
{DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_D16_UNORM,
DXGI_FORMAT_R16_UNORM},
};
if (!init_test_context(&test_context, NULL))
return;
device = test_context.device;
context = test_context.immediate_context;
sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
sampler_desc.MipLODBias = 0.0f;
sampler_desc.MaxAnisotropy = 0;
sampler_desc.ComparisonFunc = D3D11_COMPARISON_GREATER;
sampler_desc.BorderColor[0] = 0.0f;
sampler_desc.BorderColor[1] = 0.0f;
sampler_desc.BorderColor[2] = 0.0f;
sampler_desc.BorderColor[3] = 0.0f;
sampler_desc.MinLOD = 0.0f;
sampler_desc.MaxLOD = 0.0f;
hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &cmp_sampler);
ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
ok(SUCCEEDED(hr), "Failed to create sampler state, 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_R32_FLOAT;
texture_desc.SampleDesc.Count = 1;
texture_desc.SampleDesc.Quality = 0;
texture_desc.Usage = D3D11_USAGE_DEFAULT;
texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
texture_desc.CPUAccessFlags = 0;
texture_desc.MiscFlags = 0;
hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, NULL, &rtv);
ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
memset(&ps_constant, 0, sizeof(ps_constant));
cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
hr = ID3D11Device_CreatePixelShader(device, ps_compare_code, sizeof(ps_compare_code), NULL, &ps_cmp);
ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
hr = ID3D11Device_CreatePixelShader(device, ps_sample_code, sizeof(ps_sample_code), NULL, &ps_depth);
ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
hr = ID3D11Device_CreatePixelShader(device, ps_stencil_code, sizeof(ps_stencil_code), NULL, &ps_stencil);
ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
hr = ID3D11Device_CreatePixelShader(device, ps_depth_stencil_code, sizeof(ps_depth_stencil_code), NULL,
&ps_depth_stencil);
ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
{
texture_desc.Format = tests[i].typeless_format;
texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
ok(SUCCEEDED(hr), "Failed to create texture for format %#x, hr %#x.\n",
texture_desc.Format, hr);
dsv_desc.Format = tests[i].dsv_format;
dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
dsv_desc.Flags = 0;
U(dsv_desc).Texture2D.MipSlice = 0;
hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
ok(SUCCEEDED(hr), "Failed to create depth stencil view for format %#x, hr %#x.\n",
dsv_desc.Format, hr);
srv_desc.Format = tests[i].depth_view_format;
srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
U(srv_desc).Texture2D.MostDetailedMip = 0;
U(srv_desc).Texture2D.MipLevels = 1;
hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &depth_srv);
ok(SUCCEEDED(hr), "Failed to create depth shader resource view for format %#x, hr %#x.\n",
srv_desc.Format, hr);
ID3D11DeviceContext_PSSetShader(context, ps_cmp, NULL, 0);
ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &depth_srv);
ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &cmp_sampler);
ps_constant.x = 0.5f;
ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
NULL, &ps_constant, 0, 0);
ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
draw_quad(&test_context);
check_texture_float(rt_texture, 0.0f, 2);
ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.0f, 0);
ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
draw_quad(&test_context);
check_texture_float(rt_texture, 1.0f, 2);
ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
draw_quad(&test_context);
check_texture_float(rt_texture, 0.0f, 2);
ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.6f, 0);
ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
draw_quad(&test_context);
check_texture_float(rt_texture, 0.0f, 2);
ps_constant.x = 0.7f;
ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
NULL, &ps_constant, 0, 0);
ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
draw_quad(&test_context);
check_texture_float(rt_texture, 1.0f, 2);
ID3D11DeviceContext_PSSetShader(context, ps_depth, NULL, 0);
ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
draw_quad(&test_context);
check_texture_float(rt_texture, 1.0f, 2);
ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.2f, 0);
ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
draw_quad(&test_context);
check_texture_float(rt_texture, 0.2f, 2);
if (!tests[i].stencil_view_format)
{
ID3D11DepthStencilView_Release(dsv);
ID3D11ShaderResourceView_Release(depth_srv);
ID3D11Texture2D_Release(texture);
continue;
}
srv_desc.Format = tests[i].stencil_view_format;
hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &stencil_srv);
ok(SUCCEEDED(hr), "Failed to create stencil shader resource view for format %#x, hr %#x.\n",
srv_desc.Format, hr);
ID3D11DeviceContext_PSSetShader(context, ps_stencil, NULL, 0);
ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &stencil_srv);
ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 0);
ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
draw_quad(&test_context);
check_texture_float(rt_texture, 0.0f, 0);
ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 100);
ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
draw_quad(&test_context);
check_texture_float(rt_texture, 100.0f, 0);
ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 255);
ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
draw_quad(&test_context);
check_texture_float(rt_texture, 255.0f, 0);
ID3D11DeviceContext_PSSetShader(context, ps_depth_stencil, NULL, 0);
ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &depth_srv);
ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &stencil_srv);
ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.3f, 3);
ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
draw_quad(&test_context);
check_texture_float(rt_texture, 3.3f, 2);
ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 3);
ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
draw_quad(&test_context);
check_texture_float(rt_texture, 4.0f, 2);
ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0);
ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
draw_quad(&test_context);
check_texture_float(rt_texture, 0.0f, 2);
ID3D11DepthStencilView_Release(dsv);
ID3D11ShaderResourceView_Release(depth_srv);
ID3D11ShaderResourceView_Release(stencil_srv);
ID3D11Texture2D_Release(texture);
}
ID3D11Buffer_Release(cb);
ID3D11PixelShader_Release(ps_cmp);
ID3D11PixelShader_Release(ps_depth);
ID3D11PixelShader_Release(ps_depth_stencil);
ID3D11PixelShader_Release(ps_stencil);
ID3D11RenderTargetView_Release(rtv);
ID3D11SamplerState_Release(cmp_sampler);
ID3D11SamplerState_Release(sampler);
ID3D11Texture2D_Release(rt_texture);
release_test_context(&test_context);
}
static void test_multiple_render_targets(void)
{
D3D11_TEXTURE2D_DESC texture_desc;
@ -12327,6 +12675,7 @@ START_TEST(d3d11)
test_private_data();
test_blend();
test_texture();
test_depth_stencil_sampling();
test_multiple_render_targets();
test_render_target_views();
test_scissor();