d3d11/tests: Add test for cube maps.

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 2017-03-08 12:07:22 +01:00 committed by Alexandre Julliard
parent 9cb650a3b8
commit 6144fb4670
1 changed files with 307 additions and 0 deletions

View File

@ -6440,6 +6440,312 @@ static void test_texture(void)
release_test_context(&test_context);
}
static void test_cube_maps(void)
{
struct shader
{
const DWORD *code;
size_t size;
};
unsigned int i, j, sub_resource_idx, sub_resource_count;
struct d3d11_test_context test_context;
D3D11_TEXTURE2D_DESC texture_desc;
const struct shader *current_ps;
D3D_FEATURE_LEVEL feature_level;
ID3D11ShaderResourceView *srv;
ID3D11DeviceContext *context;
ID3D11Texture2D *rtv_texture;
ID3D11RenderTargetView *rtv;
struct vec4 expected_result;
ID3D11Resource *texture;
ID3D11PixelShader *ps;
ID3D11Device *device;
float data[64 * 64];
ID3D11Buffer *cb;
HRESULT hr;
RECT rect;
struct
{
unsigned int face;
unsigned int level;
unsigned int cube;
unsigned int padding;
} constant;
static const DWORD ps_cube_code[] =
{
#if 0
TextureCube t;
SamplerState s;
uint face;
uint level;
float4 main(float4 position : SV_POSITION) : SV_Target
{
float2 p;
p.x = position.x / 640.0f;
p.y = position.y / 480.0f;
float3 coord;
switch (face)
{
case 0:
coord = float3(1.0f, p.x, p.y);
break;
case 1:
coord = float3(-1.0f, p.x, p.y);
break;
case 2:
coord = float3(p.x, 1.0f, p.y);
break;
case 3:
coord = float3(p.x, -1.0f, p.y);
break;
case 4:
coord = float3(p.x, p.y, 1.0f);
break;
case 5:
default:
coord = float3(p.x, p.y, -1.0f);
break;
}
return t.SampleLevel(s, coord, level);
}
#endif
0x43425844, 0x039aee18, 0xfd630453, 0xb884cf0f, 0x10100744, 0x00000001, 0x00000310, 0x00000003,
0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000274, 0x00000040,
0x0000009d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
0x04003058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400004c, 0x0020800a, 0x00000000,
0x00000000, 0x03000006, 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000, 0x00004001,
0x3f800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x00000000,
0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001, 0x05000036,
0x00100012, 0x00000000, 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106,
0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006,
0x00004001, 0x00000002, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001,
0x3f800000, 0x01000002, 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052, 0x00000000,
0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036,
0x00100022, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001, 0x00000004,
0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889,
0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000, 0x01000002,
0x0100000a, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0xbf800000,
0x01000002, 0x01000017, 0x06000056, 0x00100082, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
0x0b000048, 0x001020f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000,
0x00000000, 0x0010003a, 0x00000000, 0x0100003e,
};
static const struct shader ps_cube = {ps_cube_code, sizeof(ps_cube_code)};
static const DWORD ps_cube_array_code[] =
{
#if 0
TextureCubeArray t;
SamplerState s;
uint face;
uint level;
uint cube;
float4 main(float4 position : SV_POSITION) : SV_Target
{
float2 p;
p.x = position.x / 640.0f;
p.y = position.y / 480.0f;
float3 coord;
switch (face)
{
case 0:
coord = float3(1.0f, p.x, p.y);
break;
case 1:
coord = float3(-1.0f, p.x, p.y);
break;
case 2:
coord = float3(p.x, 1.0f, p.y);
break;
case 3:
coord = float3(p.x, -1.0f, p.y);
break;
case 4:
coord = float3(p.x, p.y, 1.0f);
break;
case 5:
default:
coord = float3(p.x, p.y, -1.0f);
break;
}
return t.SampleLevel(s, float4(coord, cube), level);
}
#endif
0x43425844, 0xb8d5b94a, 0xdb4be034, 0x183aed19, 0xad4af415, 0x00000001, 0x00000328, 0x00000003,
0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000028c, 0x00000041,
0x000000a3, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
0x00000000, 0x04005058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0400004c, 0x0020800a,
0x00000000, 0x00000000, 0x03000006, 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000,
0x00004001, 0x3f800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001,
0x05000036, 0x00100012, 0x00000000, 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000,
0x00101106, 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002,
0x03000006, 0x00004001, 0x00000002, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000,
0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000,
0x00004001, 0x3f800000, 0x01000002, 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052,
0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000,
0x05000036, 0x00100022, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001,
0x00000004, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000,
0x01000002, 0x0100000a, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002,
0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001,
0xbf800000, 0x01000002, 0x01000017, 0x06000056, 0x00100032, 0x00000001, 0x00208a66, 0x00000000,
0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x0010000a, 0x00000001, 0x0b000048, 0x001020f2,
0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0010001a,
0x00000001, 0x0100003e,
};
static const struct shader ps_cube_array = {ps_cube_array_code, sizeof(ps_cube_array_code)};
static const struct ps_test
{
const struct shader *ps;
unsigned int miplevel_count;
unsigned int array_size;
}
ps_tests[] =
{
{&ps_cube, 1, 6},
{&ps_cube, 2, 6},
{&ps_cube, 3, 6},
{&ps_cube, 0, 6},
{&ps_cube_array, 1, 12},
{&ps_cube_array, 2, 12},
{&ps_cube_array, 3, 12},
{&ps_cube_array, 0, 12},
};
if (!init_test_context(&test_context, NULL))
return;
device = test_context.device;
context = test_context.immediate_context;
feature_level = ID3D11Device_GetFeatureLevel(device);
ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rtv_texture, NULL, &rtv);
ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
memset(&constant, 0, sizeof(constant));
cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
ps = NULL;
current_ps = NULL;
for (i = 0; i < sizeof(ps_tests) / sizeof(*ps_tests); ++i)
{
const struct ps_test *test = &ps_tests[i];
if (test->array_size / 6 > 1 && feature_level < D3D_FEATURE_LEVEL_10_1)
{
skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
continue;
}
if (current_ps != test->ps)
{
if (ps)
ID3D11PixelShader_Release(ps);
current_ps = test->ps;
hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
}
if (!test->miplevel_count)
{
srv = NULL;
ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
memset(&expected_result, 0, sizeof(expected_result));
memset(&constant, 0, sizeof(constant));
ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
draw_quad(&test_context);
check_texture_vec4(rtv_texture, &expected_result, 0);
constant.level = 1;
ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
draw_quad(&test_context);
check_texture_vec4(rtv_texture, &expected_result, 0);
continue;
}
texture_desc.Width = 64;
texture_desc.Height = 64;
texture_desc.MipLevels = test->miplevel_count;
texture_desc.ArraySize = test->array_size;
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_SHADER_RESOURCE;
texture_desc.CPUAccessFlags = 0;
texture_desc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&texture);
ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
hr = ID3D11Device_CreateShaderResourceView(device, texture, NULL, &srv);
ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
{
for (j = 0; j < sizeof(data) / sizeof(*data); ++j)
data[j] = sub_resource_idx;
ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, sub_resource_idx, NULL,
data, texture_desc.Width * sizeof(*data), 0);
}
expected_result.y = expected_result.z = 0.0f;
expected_result.w = 1.0f;
for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
{
constant.face = (sub_resource_idx / texture_desc.MipLevels) % 6;
constant.level = sub_resource_idx % texture_desc.MipLevels;
constant.cube = (sub_resource_idx / texture_desc.MipLevels) / 6;
ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
draw_quad(&test_context);
expected_result.x = sub_resource_idx;
/* Avoid testing values affected by seamless cube map filtering. */
SetRect(&rect, 100, 100, 540, 380);
check_texture_sub_resource_vec4(rtv_texture, 0, &rect, &expected_result, 0);
}
ID3D11Resource_Release(texture);
ID3D11ShaderResourceView_Release(srv);
}
ID3D11PixelShader_Release(ps);
ID3D11Buffer_Release(cb);
ID3D11RenderTargetView_Release(rtv);
ID3D11Texture2D_Release(rtv_texture);
release_test_context(&test_context);
}
static void test_depth_stencil_sampling(void)
{
ID3D11PixelShader *ps_cmp, *ps_depth, *ps_stencil, *ps_depth_stencil;
@ -15390,6 +15696,7 @@ START_TEST(d3d11)
test_private_data();
test_blend();
test_texture();
test_cube_maps();
test_depth_stencil_sampling();
test_multiple_render_targets();
test_render_target_views();