d3d11/tests: Add test for stream output components.

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-11-07 14:29:16 +01:00 committed by Alexandre Julliard
parent b9464cfdc2
commit 9b8404bfda

View file

@ -21057,6 +21057,285 @@ static void test_stream_output_resume(void)
release_test_context(&test_context);
}
static void test_stream_output_components(void)
{
const D3D11_SO_DECLARATION_ENTRY *current_so_declaration;
struct d3d11_test_context test_context;
ID3D11InputLayout *input_layout[2];
ID3D11Buffer *vb[2], *so_buffer;
ID3D11DeviceContext *context;
struct resource_readback rb;
unsigned int stride, offset;
ID3D11GeometryShader *gs;
ID3D11VertexShader *vs;
ID3D11PixelShader *ps;
ID3D11Device *device;
const float *result;
unsigned int i, j;
HRESULT hr;
static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
static const DWORD vs_code[] =
{
#if 0
struct vertex
{
float4 position : POSITION;
float4 color : COLOR;
float4 color2 : COLOR2;
};
void main(in vertex i, out vertex o)
{
o = i;
}
#endif
0x43425844, 0x95991b76, 0x4898640b, 0xe36ad9d6, 0xfbfe78b4, 0x00000001, 0x00000194, 0x00000003,
0x0000002c, 0x00000094, 0x000000fc, 0x4e475349, 0x00000060, 0x00000003, 0x00000008, 0x00000050,
0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
0x00000003, 0x00000001, 0x00000f0f, 0x00000059, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x00000060, 0x00000003,
0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000059,
0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000059, 0x00000002, 0x00000000,
0x00000003, 0x00000002, 0x0000000f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853,
0x00000090, 0x00010040, 0x00000024, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2,
0x00000001, 0x0300005f, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065,
0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036,
0x001020f2, 0x00000002, 0x00101e46, 0x00000002, 0x0100003e,
};
static const DWORD gs_code[] =
{
#if 0
struct vertex
{
float4 position : POSITION;
float4 color : COLOR;
float4 color2 : COLOR2;
};
[maxvertexcount(1)]
void main(point vertex input[1], inout PointStream<vertex> output)
{
output.Append(input[0]);
}
#endif
0x43425844, 0x218f7d27, 0x555fa7f1, 0x282c545f, 0x3989c843, 0x00000001, 0x000001c0, 0x00000003,
0x0000002c, 0x00000094, 0x000000fc, 0x4e475349, 0x00000060, 0x00000003, 0x00000008, 0x00000050,
0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
0x00000003, 0x00000001, 0x00000f0f, 0x00000059, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x00000060, 0x00000003,
0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000059,
0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000059, 0x00000002, 0x00000000,
0x00000003, 0x00000002, 0x0000000f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853,
0x000000bc, 0x00020040, 0x0000002f, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x0400005f,
0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000002, 0x0100085d,
0x0100085c, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x03000065,
0x001020f2, 0x00000002, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46,
0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001,
0x06000036, 0x001020f2, 0x00000002, 0x00201e46, 0x00000000, 0x00000002, 0x01000013, 0x0100003e,
};
static const DWORD ps_code[] =
{
#if 0
float4 main(float4 position : SV_Position,
float2 texcoord : TEXCOORD) : SV_Target
{
return float4(position.xy, texcoord);
}
#endif
0x43425844, 0xa15616bc, 0x6862ab1c, 0x28b915c0, 0xdb0df67c, 0x00000001, 0x0000011c, 0x00000003,
0x0000002c, 0x00000084, 0x000000b8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x00000044, 0x00000000, 0x00000000,
0x00000003, 0x00000001, 0x00000303, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000005c,
0x00000040, 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03001062, 0x00101032,
0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00101046,
0x00000000, 0x05000036, 0x001020c2, 0x00000000, 0x00101406, 0x00000001, 0x0100003e,
};
static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
{
{"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
{"COLOR", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
{"COLOR", 2, DXGI_FORMAT_R32G32_FLOAT, 0, 28, D3D11_INPUT_PER_VERTEX_DATA, 0},
};
static const D3D11_INPUT_ELEMENT_DESC layout_desc2[] =
{
{"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
{"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
{"COLOR", 2, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 32, D3D11_INPUT_PER_VERTEX_DATA, 0},
};
static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
{
{0, "POSITION", 0, 0, 4, 0},
{0, "COLOR", 0, 0, 3, 0},
{0, "COLOR", 2, 0, 2, 0},
};
static const D3D11_SO_DECLARATION_ENTRY so_declaration2[] =
{
{0, "POSITION", 0, 0, 1, 0},
{0, "POSITION", 0, 1, 1, 0},
{0, "POSITION", 0, 2, 1, 0},
{0, "POSITION", 0, 3, 1, 0},
{0, "COLOR", 0, 0, 1, 0},
{0, "COLOR", 0, 1, 1, 0},
{0, "COLOR", 0, 2, 1, 0},
{0, "COLOR", 2, 0, 1, 0},
{0, "COLOR", 2, 1, 1, 0},
};
static const D3D11_SO_DECLARATION_ENTRY so_declaration3[] =
{
{0, "COLOR", 0, 2, 2, 0},
{0, "COLOR", 2, 3, 1, 0},
};
static const struct
{
struct vec4 position;
struct vec3 color;
struct vec2 color2;
}
vb_data[] =
{
{{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 0.0f}, {0.5f, 1.0f}},
{{-1.0f, 1.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f}},
{{ 1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 1.0f}, {0.5f, 0.4f}},
{{ 1.0f, 1.0f, 0.0f, 1.0f}, {1.0f, 1.0f, 0.0f}, {0.1f, 0.6f}},
};
static const struct
{
struct vec4 position;
struct vec4 color;
struct vec4 color2;
}
vb_data2[] =
{
{{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 2.0f, 3.0f, 4.0f}, {5.0f, 6.0f, 7.0f, 8.0f}},
{{-1.0f, 1.0f, 0.0f, 1.0f}, {9.0f, 1.1f, 1.2f, 1.3f}, {1.4f, 1.5f, 1.6f, 1.7f}},
{{ 1.0f, -1.0f, 0.0f, 1.0f}, {1.8f, 1.9f, 2.0f, 2.1f}, {2.2f, 2.3f, 2.4f, 2.5f}},
{{ 1.0f, 1.0f, 0.0f, 1.0f}, {2.5f, 2.6f, 2.7f, 2.8f}, {2.9f, 3.0f, 3.1f, 3.2f}},
};
static const unsigned int vb_stride[] = {sizeof(*vb_data), sizeof(*vb_data2)};
static const float expected_data[] =
{
-1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.5f, 1.0f,
-1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.5f, 0.4f,
1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.1f, 0.6f,
};
static const float expected_data2[] =
{
-1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 2.0f, 3.0f, 5.0f, 6.0f,
-1.0f, 1.0f, 0.0f, 1.0f, 9.0f, 1.1f, 1.2f, 1.4f, 1.5f,
1.0f, -1.0f, 0.0f, 1.0f, 1.8f, 1.9f, 2.0f, 2.2f, 2.3f,
1.0f, 1.0f, 0.0f, 1.0f, 2.5f, 2.6f, 2.7f, 2.9f, 3.0f,
};
static const float expected_data3[] =
{
3.0f, 4.0f, 8.0f, 1.2f, 1.3f, 1.7f, 2.0f, 2.1f, 2.5f, 2.7f, 2.8f, 3.2f,
};
static const struct
{
BOOL with_ps;
unsigned int vb_idx;
const D3D11_SO_DECLARATION_ENTRY *so_declaration;
unsigned int so_entry_count;
const float *expected_data;
unsigned int expected_data_size;
}
tests[] =
{
{TRUE, 0, so_declaration, ARRAY_SIZE(so_declaration), expected_data, ARRAY_SIZE(expected_data)},
{TRUE, 1, so_declaration, ARRAY_SIZE(so_declaration), expected_data2, ARRAY_SIZE(expected_data2)},
{TRUE, 0, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data, ARRAY_SIZE(expected_data)},
{TRUE, 1, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data2, ARRAY_SIZE(expected_data2)},
{TRUE, 1, so_declaration3, ARRAY_SIZE(so_declaration3), expected_data3, ARRAY_SIZE(expected_data3)},
{FALSE, 0, so_declaration, ARRAY_SIZE(so_declaration), expected_data, ARRAY_SIZE(expected_data)},
{FALSE, 1, so_declaration, ARRAY_SIZE(so_declaration), expected_data2, ARRAY_SIZE(expected_data2)},
{FALSE, 0, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data, ARRAY_SIZE(expected_data)},
{FALSE, 1, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data2, ARRAY_SIZE(expected_data2)},
{FALSE, 1, so_declaration3, ARRAY_SIZE(so_declaration3), expected_data3, ARRAY_SIZE(expected_data3)},
};
if (!init_test_context(&test_context, &feature_level))
return;
device = test_context.device;
context = test_context.immediate_context;
vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vb_data), vb_data);
vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vb_data2), vb_data2);
hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
vs_code, sizeof(vs_code), &input_layout[0]);
ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
hr = ID3D11Device_CreateInputLayout(device, layout_desc2, ARRAY_SIZE(layout_desc2),
vs_code, sizeof(vs_code), &input_layout[1]);
ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
gs = NULL;
current_so_declaration = NULL;
for (i = 0; i < ARRAY_SIZE(tests); ++i)
{
ID3D11DeviceContext_PSSetShader(context, tests[i].with_ps ? ps : NULL, NULL, 0);
if (current_so_declaration != tests[i].so_declaration)
{
if (gs)
ID3D11GeometryShader_Release(gs);
hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
tests[i].so_declaration, tests[i].so_entry_count, NULL, 0,
D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
current_so_declaration = tests[i].so_declaration;
}
ID3D11DeviceContext_IASetInputLayout(context, input_layout[tests[i].vb_idx]);
stride = vb_stride[tests[i].vb_idx];
offset = 0;
ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[tests[i].vb_idx], &stride, &offset);
offset = 0;
ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
ID3D11DeviceContext_Draw(context, 4, 0);
get_buffer_readback(so_buffer, &rb);
result = rb.map_desc.pData;
for (j = 0; j < tests[i].expected_data_size; ++j)
{
float expected_value = tests[i].expected_data[j];
ok(compare_float(result[j], expected_value, 2),
"Test %u: Got %.8e, expected %.8e at %u.\n",
i, result[j], expected_value, j);
}
release_resource_readback(&rb);
}
for (i = 0; i < ARRAY_SIZE(vb); ++i)
ID3D11Buffer_Release(vb[i]);
ID3D11Buffer_Release(so_buffer);
ID3D11VertexShader_Release(vs);
ID3D11GeometryShader_Release(gs);
ID3D11PixelShader_Release(ps);
for (i = 0; i < ARRAY_SIZE(input_layout); ++i)
ID3D11InputLayout_Release(input_layout[i]);
release_test_context(&test_context);
}
static void test_gather(void)
{
struct
@ -22135,6 +22414,7 @@ START_TEST(d3d11)
test_stream_output();
test_fl10_stream_output_desc();
test_stream_output_resume();
test_stream_output_components();
test_gather();
test_gather_c();
test_fractional_viewports();