[PATCH 5/5] d3d10core/tests: Port test_viewport() to d3d10core.
Matteo Bruni
mbruni at codeweavers.com
Tue Feb 12 11:26:01 CST 2019
Signed-off-by: Matteo Bruni <mbruni at codeweavers.com>
---
dlls/d3d10core/tests/d3d10core.c | 189 ++++++++++++++++++++++++++++++-
1 file changed, 185 insertions(+), 4 deletions(-)
diff --git a/dlls/d3d10core/tests/d3d10core.c b/dlls/d3d10core/tests/d3d10core.c
index 9ce385db6c8..5fcb82aebae 100644
--- a/dlls/d3d10core/tests/d3d10core.c
+++ b/dlls/d3d10core/tests/d3d10core.c
@@ -1092,6 +1092,67 @@ static IDXGIAdapter *create_adapter(void)
return adapter;
}
+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);
+ 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);
+ ok(color == expected, "%s: pixel (%d, %d) has color %08x, expected %08x.\n",
+ message, x, y, color, expected);
+ }
+ }
+ }
+ }
+}
+
static ID3D10Device *create_device(void)
{
unsigned int flags = 0;
@@ -1265,10 +1326,11 @@ struct d3d10core_test_context
ID3D10RenderTargetView *backbuffer_rtv;
ID3D10InputLayout *input_layout;
+ ID3D10Buffer *vb;
+ unsigned int vb_stride;
ID3D10VertexShader *vs;
const DWORD *vs_code;
ID3D10Buffer *vs_cb;
- ID3D10Buffer *vb;
ID3D10PixelShader *ps;
ID3D10Buffer *ps_cb;
@@ -1373,7 +1435,7 @@ static void draw_quad_vs_(unsigned int line, struct d3d10core_test_context *cont
};
ID3D10Device *device = context->device;
- unsigned int stride, offset;
+ unsigned int offset;
HRESULT hr;
if (!vs_code)
@@ -1390,7 +1452,10 @@ static void draw_quad_vs_(unsigned int line, struct d3d10core_test_context *cont
}
if (!context->vb)
+ {
context->vb = create_buffer(device, D3D10_BIND_VERTEX_BUFFER, sizeof(quad), quad);
+ context->vb_stride = sizeof(*quad);
+ }
if (context->vs_code != vs_code)
{
@@ -1405,9 +1470,8 @@ static void draw_quad_vs_(unsigned int line, struct d3d10core_test_context *cont
ID3D10Device_IASetInputLayout(context->device, context->input_layout);
ID3D10Device_IASetPrimitiveTopology(context->device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
- stride = sizeof(*quad);
offset = 0;
- ID3D10Device_IASetVertexBuffers(context->device, 0, 1, &context->vb, &stride, &offset);
+ ID3D10Device_IASetVertexBuffers(context->device, 0, 1, &context->vb, &context->vb_stride, &offset);
ID3D10Device_VSSetShader(context->device, context->vs);
ID3D10Device_Draw(context->device, 4, 0);
@@ -1491,6 +1555,69 @@ static void draw_color_quad_(unsigned int line, struct d3d10core_test_context *c
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 d3d10core_test_context *context,
+ const struct vec4 *color, const DWORD *vs_code, unsigned int vs_code_size,
+ const struct vec4 *quad)
+{
+ static const D3D10_INPUT_ELEMENT_DESC default_layout_desc[] =
+ {
+ {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
+ };
+ static const DWORD default_vs_code[] =
+ {
+#if 0
+ float4 main(float4 position : POSITION) : SV_POSITION
+ {
+ return position;
+ }
+#endif
+ 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
+ 0x0000002c, 0x00000060, 0x00000094, 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, 0x52444853, 0x0000003c, 0x00010040,
+ 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
+ 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
+ };
+ ID3D10Device *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 = ID3D10Device_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, D3D10_BIND_VERTEX_BUFFER, sizeof(*quad) * 4, quad);
+ context->vb_stride = sizeof(*quad);
+ }
+
+ if (context->vs_code != vs_code)
+ {
+ if (context->vs)
+ ID3D10VertexShader_Release(context->vs);
+
+ hr = ID3D10Device_CreateVertexShader(device, vs_code, vs_code_size, &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_feature_level(void)
{
D3D_FEATURE_LEVEL feature_level;
@@ -17879,6 +18006,59 @@ static void test_render_a8(void)
release_test_context(&test_context);
}
+static void test_viewport(void)
+{
+ static const struct
+ {
+ D3D10_VIEWPORT vp;
+ RECT expected_rect;
+ const char *message;
+ }
+ tests[] =
+ {
+ {{ 0, 0, 640, 480}, { 0, 120, 479, 359}, "(0, 0) - (640, 480) viewport"},
+ {{ 0, 0, 320, 240}, { 0, 60, 239, 179}, "(0, 0) - (320, 240) viewport"},
+ {{ 0, 0, 1280, 960}, { 0, 240, 639, 479}, "(0, 0) - (1280, 960) viewport"},
+ {{ 0, 0, 2000, 1600}, { 0, 400, 639, 479}, "(0, 0) - (2000, 1600) viewport"},
+ {{ 100, 100, 640, 480}, {100, 220, 579, 459}, "(100, 100) - (640, 480) viewport"},
+ {{-100, -100, 640, 480}, { 0, 20, 379, 259}, "(-100, -100) - (640, 480) viewport"},
+ {{ 0, 0, 8192, 8192}, {-10, -10, -1, -1}, "(0, 0) - (8192, 8192) viewport"},
+ {{ 0, 0, 8192, 480}, { 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 d3d10core_test_context test_context;
+ struct resource_readback rb;
+ ID3D10Device *device;
+ unsigned int i;
+
+ if (!init_test_context(&test_context))
+ return;
+
+ device = test_context.device;
+
+ for (i = 0; i < ARRAY_SIZE(tests); ++i)
+ {
+ ID3D10Device_ClearRenderTargetView(device, test_context.backbuffer_rtv, &black.x);
+
+ ID3D10Device_RSSetViewports(device, 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(d3d10core)
{
unsigned int argc, i;
@@ -17994,6 +18174,7 @@ START_TEST(d3d10core)
queue_test(test_depth_clip);
queue_test(test_staging_buffers);
queue_test(test_render_a8);
+ queue_test(test_viewport);
run_queued_tests();
--
2.19.2
More information about the wine-devel
mailing list