d3d11/tests: Port test_scissor() from d3d10core.

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 2015-11-06 01:28:26 +01:00 committed by Alexandre Julliard
parent 95998504bd
commit 6e22a5d69f
1 changed files with 206 additions and 0 deletions

View File

@ -2544,6 +2544,211 @@ static void test_private_data(void)
ok(!refcount, "Test object has %u references left.\n", refcount);
}
static void test_scissor(void)
{
ID3D11DeviceContext *immediate_context;
D3D11_SUBRESOURCE_DATA buffer_data;
ID3D11InputLayout *input_layout;
D3D11_RASTERIZER_DESC rs_desc;
D3D11_BUFFER_DESC buffer_desc;
ID3D11RenderTargetView *rtv;
ID3D11Texture2D *backbuffer;
unsigned int stride, offset;
ID3D11RasterizerState *rs;
IDXGISwapChain *swapchain;
D3D11_RECT scissor_rect;
ID3D11VertexShader *vs;
ID3D11PixelShader *ps;
ID3D11Device *device;
D3D11_VIEWPORT vp;
ID3D11Buffer *vb;
ULONG refcount;
DWORD color;
HWND window;
HRESULT hr;
static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
{
{"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
};
static const DWORD vs_code[] =
{
#if 0
float4 main(float4 position : POSITION) : SV_POSITION
{
return position;
}
#endif
0x43425844, 0x1fa8c27f, 0x52d2f21d, 0xc196fdb7, 0x376f283a, 0x00000001, 0x000001b4, 0x00000005,
0x00000034, 0x0000008c, 0x000000c0, 0x000000f4, 0x00000138, 0x46454452, 0x00000050, 0x00000000,
0x00000000, 0x00000000, 0x0000001c, 0xfffe0400, 0x00000100, 0x0000001c, 0x7263694d, 0x666f736f,
0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, 0x6c69706d, 0x39207265, 0x2e30332e,
0x30303239, 0x3336312e, 0xab003438, 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, 0x54415453, 0x00000074,
0x00000002, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
};
static const DWORD ps_code[] =
{
#if 0
float4 main(float4 position : SV_POSITION) : SV_Target
{
return float4(0.0, 1.0, 0.0, 1.0);
}
#endif
0x43425844, 0xe70802a0, 0xee334047, 0x7bfd0c79, 0xaeff7804, 0x00000001, 0x000001b0, 0x00000005,
0x00000034, 0x0000008c, 0x000000c0, 0x000000f4, 0x00000134, 0x46454452, 0x00000050, 0x00000000,
0x00000000, 0x00000000, 0x0000001c, 0xffff0400, 0x00000100, 0x0000001c, 0x7263694d, 0x666f736f,
0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, 0x6c69706d, 0x39207265, 0x2e30332e,
0x30303239, 0x3336312e, 0xab003438, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x54415453, 0x00000074, 0x00000002,
0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000,
};
static const struct
{
float x, y;
}
quad[] =
{
{-1.0f, -1.0f},
{-1.0f, 1.0f},
{ 1.0f, -1.0f},
{ 1.0f, 1.0f},
};
if (!(device = create_device(NULL)))
{
skip("Failed to create device.\n");
return;
}
window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
0, 0, 640, 480, NULL, NULL, NULL, NULL);
swapchain = create_swapchain(device, window, TRUE);
hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D11Texture2D, (void **)&backbuffer);
ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
hr = ID3D11Device_CreateInputLayout(device, layout_desc, sizeof(layout_desc) / sizeof(*layout_desc),
vs_code, sizeof(vs_code), &input_layout);
ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
buffer_desc.ByteWidth = sizeof(quad);
buffer_desc.Usage = D3D11_USAGE_DEFAULT;
buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
buffer_desc.CPUAccessFlags = 0;
buffer_desc.MiscFlags = 0;
buffer_desc.StructureByteStride = 0;
buffer_data.pSysMem = quad;
buffer_data.SysMemPitch = 0;
buffer_data.SysMemSlicePitch = 0;
hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &buffer_data, &vb);
ok(SUCCEEDED(hr), "Failed to create vertex buffer, 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);
rs_desc.FillMode = D3D11_FILL_SOLID;
rs_desc.CullMode = D3D11_CULL_BACK;
rs_desc.FrontCounterClockwise = FALSE;
rs_desc.DepthBias = 0;
rs_desc.DepthBiasClamp = 0.0f;
rs_desc.SlopeScaledDepthBias = 0.0f;
rs_desc.DepthClipEnable = TRUE;
rs_desc.ScissorEnable = TRUE;
rs_desc.MultisampleEnable = FALSE;
rs_desc.AntialiasedLineEnable = FALSE;
hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer, NULL, &rtv);
ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
ID3D11Device_GetImmediateContext(device, &immediate_context);
ID3D11DeviceContext_IASetInputLayout(immediate_context, input_layout);
ID3D11DeviceContext_IASetPrimitiveTopology(immediate_context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
stride = sizeof(*quad);
offset = 0;
ID3D11DeviceContext_IASetVertexBuffers(immediate_context, 0, 1, &vb, &stride, &offset);
ID3D11DeviceContext_VSSetShader(immediate_context, vs, NULL, 0);
ID3D11DeviceContext_PSSetShader(immediate_context, ps, NULL, 0);
vp.TopLeftX = 0.0f;
vp.TopLeftY = 0.0f;
vp.Width = 640.0f;
vp.Height = 480.0f;
vp.MinDepth = 0.0f;
vp.MaxDepth = 1.0f;
ID3D11DeviceContext_RSSetViewports(immediate_context, 1, &vp);
scissor_rect.left = 160;
scissor_rect.top = 120;
scissor_rect.right = 480;
scissor_rect.bottom = 360;
ID3D11DeviceContext_RSSetScissorRects(immediate_context, 1, &scissor_rect);
ID3D11DeviceContext_OMSetRenderTargets(immediate_context, 1, &rtv, NULL);
ID3D11DeviceContext_ClearRenderTargetView(immediate_context, rtv, red);
color = get_texture_color(backbuffer, 320, 240);
ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
ID3D11DeviceContext_Draw(immediate_context, 4, 0);
color = get_texture_color(backbuffer, 320, 60);
ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
color = get_texture_color(backbuffer, 80, 240);
ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
color = get_texture_color(backbuffer, 320, 240);
ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
color = get_texture_color(backbuffer, 560, 240);
ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
color = get_texture_color(backbuffer, 320, 420);
ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
ID3D11DeviceContext_ClearRenderTargetView(immediate_context, rtv, red);
ID3D11DeviceContext_RSSetState(immediate_context, rs);
ID3D11DeviceContext_Draw(immediate_context, 4, 0);
color = get_texture_color(backbuffer, 320, 60);
ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
color = get_texture_color(backbuffer, 80, 240);
ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
color = get_texture_color(backbuffer, 320, 240);
ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
color = get_texture_color(backbuffer, 560, 240);
ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
color = get_texture_color(backbuffer, 320, 420);
ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
ID3D11RenderTargetView_Release(rtv);
ID3D11RasterizerState_Release(rs);
ID3D11PixelShader_Release(ps);
ID3D11VertexShader_Release(vs);
ID3D11Buffer_Release(vb);
ID3D11InputLayout_Release(input_layout);
ID3D11Texture2D_Release(backbuffer);
IDXGISwapChain_Release(swapchain);
ID3D11DeviceContext_Release(immediate_context);
refcount = ID3D11Device_Release(device);
ok(!refcount, "Device has %u references left.\n", refcount);
DestroyWindow(window);
}
static void test_il_append_aligned(void)
{
ID3D11RenderTargetView *backbuffer_rtv;
@ -2949,6 +3154,7 @@ START_TEST(d3d11)
test_create_predicate();
test_device_removed_reason();
test_private_data();
test_scissor();
test_il_append_aligned();
test_resource_map();
}