Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- dlls/d3d11/tests/d3d11.c | 201 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 197 insertions(+), 4 deletions(-)
diff --git a/dlls/d3d11/tests/d3d11.c b/dlls/d3d11/tests/d3d11.c index 27b0775cea1..dacfa0af4ac 100644 --- a/dlls/d3d11/tests/d3d11.c +++ b/dlls/d3d11/tests/d3d11.c @@ -1282,6 +1282,67 @@ static void check_texture_uvec4_(unsigned int line, ID3D11Texture2D *texture, check_texture_sub_resource_uvec4_(line, texture, sub_resource_idx, NULL, expected_value); }
+static void check_rect(struct resource_readback *rb, RECT r, const char *message) +{ + LONG x_coords[2][2] = + { + {r.left - 1, r.left + 1}, + {r.right + 1, r.right - 1}, + }; + LONG y_coords[2][2] = + { + {r.top - 1, r.top + 1}, + {r.bottom + 1, r.bottom - 1} + }; + unsigned int i, j, x_side, y_side; + DWORD color = 0; + LONG x = 0, y; + + if (r.left < 0 && r.top < 0 && r.right < 0 && r.bottom < 0) + { + BOOL all_match = TRUE; + + for (y = 0; y < rb->height; ++y) + { + for (x = 0; x < rb->width; ++x) + { + color = get_readback_color(rb, x, y, 0); + if (color != 0xff000000) + { + all_match = FALSE; + break; + } + } + if (!all_match) + break; + } + ok(all_match, "%s: pixel (%d, %d) has color %08x.\n", message, x, y, color); + return; + } + + for (i = 0; i < 2; ++i) + { + for (j = 0; j < 2; ++j) + { + for (x_side = 0; x_side < 2; ++x_side) + { + for (y_side = 0; y_side < 2; ++y_side) + { + DWORD expected = (x_side == 1 && y_side == 1) ? 0xffffffff : 0xff000000; + + x = x_coords[i][x_side]; + y = y_coords[j][y_side]; + if (x < 0 || x >= rb->width || y < 0 || y >= rb->height) + continue; + color = get_readback_color(rb, x, y, 0); + ok(color == expected, "%s: pixel (%d, %d) has color %08x, expected %08x.\n", + message, x, y, color, expected); + } + } + } + } +} + static IDXGIAdapter *create_adapter(void) { IDXGIFactory4 *factory4; @@ -1540,10 +1601,11 @@ struct d3d11_test_context ID3D11DeviceContext *immediate_context;
ID3D11InputLayout *input_layout; + ID3D11Buffer *vb; + unsigned int vb_stride; ID3D11VertexShader *vs; const DWORD *vs_code; ID3D11Buffer *vs_cb; - ID3D11Buffer *vb;
ID3D11PixelShader *ps; ID3D11Buffer *ps_cb; @@ -1662,7 +1724,7 @@ static void draw_quad_vs_(unsigned int line, struct d3d11_test_context *context, };
ID3D11Device *device = context->device; - unsigned int stride, offset; + unsigned int offset; HRESULT hr;
if (!vs_code) @@ -1690,13 +1752,15 @@ static void draw_quad_vs_(unsigned int line, struct d3d11_test_context *context, }
if (!context->vb) + { context->vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad); + context->vb_stride = sizeof(*quad); + }
ID3D11DeviceContext_IASetInputLayout(context->immediate_context, context->input_layout); ID3D11DeviceContext_IASetPrimitiveTopology(context->immediate_context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); - stride = sizeof(*quad); offset = 0; - ID3D11DeviceContext_IASetVertexBuffers(context->immediate_context, 0, 1, &context->vb, &stride, &offset); + ID3D11DeviceContext_IASetVertexBuffers(context->immediate_context, 0, 1, &context->vb, &context->vb_stride, &offset); ID3D11DeviceContext_VSSetShader(context->immediate_context, context->vs, NULL, 0);
ID3D11DeviceContext_Draw(context->immediate_context, 4, 0); @@ -1792,6 +1856,77 @@ static void draw_color_quad_(unsigned int line, struct d3d11_test_context *conte draw_quad_vs_(line, context, vs_code, vs_code_size); }
+#define draw_custom_quad(context, color, vs_code, vs_code_size, quad) \ + draw_custom_quad_(__LINE__, context, color, vs_code, vs_code_size, quad) +static void draw_custom_quad_(unsigned int line, struct d3d11_test_context *context, + const struct vec4 *color, const DWORD *vs_code, unsigned int vs_code_size, + const struct vec4 *quad) +{ + static const D3D11_INPUT_ELEMENT_DESC default_layout_desc[] = + { + {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0}, + }; + static const DWORD default_vs_code[] = + { +#if 0 + float4 main(float4 position : POSITION) : SV_POSITION + { + return position; + } +#endif + 0x43425844, 0x4fb19b86, 0x955fa240, 0x1a630688, 0x24eb9db4, 0x00000001, 0x000001e0, 0x00000006, + 0x00000038, 0x00000084, 0x000000d0, 0x00000134, 0x00000178, 0x000001ac, 0x53414e58, 0x00000044, + 0x00000044, 0xfffe0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, + 0x00240000, 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000, 0x02000001, 0xc00f0000, 0x80e40000, + 0x0000ffff, 0x50414e58, 0x00000044, 0x00000044, 0xfffe0200, 0x00000020, 0x00000024, 0x00240000, + 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000, + 0x02000001, 0xc00f0000, 0x80e40000, 0x0000ffff, 0x396e6f41, 0x0000005c, 0x0000005c, 0xfffe0200, + 0x00000034, 0x00000028, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240001, 0x00000000, + 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000, 0x04000004, 0xc0030000, 0x90ff0000, 0xa0e40000, + 0x90e40000, 0x02000001, 0xc00c0000, 0x90e40000, 0x0000ffff, 0x52444853, 0x0000003c, 0x00010040, + 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, + 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x0000002c, + 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, + 0x49534f50, 0x4e4f4954, 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, + 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, + }; + ID3D11Device *device = context->device; + HRESULT hr; + + if (!vs_code) + { + vs_code = default_vs_code; + vs_code_size = sizeof(default_vs_code); + } + + if (!context->input_layout) + { + hr = ID3D11Device_CreateInputLayout(device, default_layout_desc, + sizeof(default_layout_desc) / sizeof(*default_layout_desc), + vs_code, vs_code_size, &context->input_layout); + ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr); + } + + if (!context->vb) + { + context->vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(*quad) * 4, quad); + context->vb_stride = sizeof(*quad); + } + + if (context->vs_code != vs_code) + { + if (context->vs) + ID3D11VertexShader_Release(context->vs); + + hr = ID3D11Device_CreateVertexShader(device, vs_code, vs_code_size, NULL, &context->vs); + ok_(__FILE__, line)(hr == S_OK, "Failed to create vertex shader, hr %#x.\n", hr); + + context->vs_code = vs_code; + } + + draw_color_quad_(line, context, color, vs_code, vs_code_size); +} + static void test_create_device(void) { static const D3D_FEATURE_LEVEL default_feature_levels[] = @@ -29142,6 +29277,63 @@ static void test_standard_pattern(void) release_test_context(&test_context); }
+static void test_viewport(void) +{ + static const struct + { + D3D11_VIEWPORT vp; + RECT expected_rect; + const char *message; + } + tests[] = + { + {{ 0.0f, 0.0f, 640.0f, 480.0f}, { 0, 120, 479, 359}, "(0, 0) - (640, 480) viewport"}, + {{ 0.0f, 0.0f, 320.0f, 240.0f}, { 0, 60, 239, 179}, "(0, 0) - (320, 240) viewport"}, + {{ 0.0f, 0.0f, 1280.0f, 960.0f}, { 0, 240, 639, 479}, "(0, 0) - (1280, 960) viewport"}, + {{ 0.0f, 0.0f, 2000.0f, 1600.0f}, { 0, 400, 639, 479}, "(0, 0) - (2000, 1600) viewport"}, + {{ 100.0f, 100.0f, 640.0f, 480.0f}, {100, 220, 579, 459}, "(100, 100) - (640, 480) viewport"}, + {{ 100.4f, 100.4f, 640.0f, 480.0f}, {100, 220, 579, 459}, "(100.4, 100.4) - (640, 480) viewport"}, + {{ 100.5f, 100.5f, 640.0f, 480.0f}, {100, 220, 579, 459}, "(100.5, 100.5) - (640, 480) viewport"}, + {{ 100.6f, 100.6f, 640.0f, 480.0f}, {100, 220, 580, 460}, "(100.6, 100.6) - (640, 480) viewport"}, + {{ 100.9f, 100.9f, 640.0f, 480.0f}, {100, 220, 580, 460}, "(100.9, 100.9) - (640, 480) viewport"}, + {{-100.0f, -100.0f, 640.0f, 480.0f}, { 0, 20, 379, 259}, "(-100, -100) - (640, 480) viewport"}, + {{ 0.0f, 0.0f, 8192.0f, 8192.0f}, {-10, -10, -1, -1}, "(0, 0) - (8192, 8192) viewport"}, + {{ 0.0f, 0.0f, 8192.0f, 480.0f}, { 0, 120, 639, 359}, "(0, 0) - (8192, 480) viewport"}, + }; + static const struct vec4 quad[] = + { + {-1.5f, -0.5f, 0.1f, 1.0f}, + {-1.5f, 0.5f, 0.1f, 1.0f}, + { 0.5f, -0.5f, 0.1f, 1.0f}, + { 0.5f, 0.5f, 0.1f, 1.0f}, + }; + static const struct vec4 black = {0.0f, 0.0f, 0.0f, 1.0f}; + static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f}; + struct d3d11_test_context test_context; + ID3D11DeviceContext *context; + struct resource_readback rb; + unsigned int i; + + if (!init_test_context(&test_context, NULL)) + return; + + context = test_context.immediate_context; + + for (i = 0; i < ARRAY_SIZE(tests); ++i) + { + ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &black.x); + + ID3D11DeviceContext_RSSetViewports(context, 1, &tests[i].vp); + draw_custom_quad(&test_context, &white, NULL, 0, quad); + + get_texture_readback(test_context.backbuffer, 0, &rb); + check_rect(&rb, tests[i].expected_rect, tests[i].message); + release_resource_readback(&rb); + } + + release_test_context(&test_context); +} + START_TEST(d3d11) { unsigned int argc, i; @@ -29297,6 +29489,7 @@ START_TEST(d3d11) queue_test(test_staging_buffers); queue_test(test_render_a8); queue_test(test_standard_pattern); + queue_test(test_viewport);
run_queued_tests(); }