Module: wine Branch: master Commit: 25f9fbcc6d263b10e773553fd0ef6b1594079f4d URL: http://source.winehq.org/git/wine.git/?a=commit;h=25f9fbcc6d263b10e773553fd0...
Author: Józef Kucia jkucia@codeweavers.com Date: Tue Mar 1 22:20:00 2016 +0100
d3d11/tests: Add test for multiple render targets.
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
---
dlls/d3d11/tests/d3d11.c | 192 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 192 insertions(+)
diff --git a/dlls/d3d11/tests/d3d11.c b/dlls/d3d11/tests/d3d11.c index 00b3d18..4054b2a 100644 --- a/dlls/d3d11/tests/d3d11.c +++ b/dlls/d3d11/tests/d3d11.c @@ -3564,6 +3564,197 @@ static void test_texture(void) DestroyWindow(window); }
+static void test_multiple_render_targets(void) +{ + D3D11_SUBRESOURCE_DATA resource_data; + D3D11_TEXTURE2D_DESC texture_desc; + ID3D11InputLayout *input_layout; + unsigned int stride, offset, i; + ID3D11RenderTargetView *rtv[4]; + D3D11_BUFFER_DESC buffer_desc; + ID3D11DeviceContext *context; + ID3D11Texture2D *rt[4]; + ID3D11VertexShader *vs; + ID3D11PixelShader *ps; + ID3D11Device *device; + D3D11_VIEWPORT vp; + ID3D11Buffer *vb; + ULONG refcount; + DWORD color; + HRESULT hr; + + 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, 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, + }; + static const DWORD ps_code[] = + { +#if 0 + struct output + { + float4 t1 : SV_TARGET0; + float4 t2 : SV_Target1; + float4 t3 : SV_TARGET2; + float4 t4 : SV_Target3; + }; + + output main(float4 position : SV_POSITION) + { + struct output o; + o.t1 = (float4)1.0f; + o.t2 = (float4)0.5f; + o.t3 = (float4)0.2f; + o.t4 = float4(0.0f, 0.2f, 0.5f, 1.0f); + return o; + } +#endif + 0x43425844, 0x8701ad18, 0xe3d5291d, 0x7b4288a6, 0x01917515, 0x00000001, 0x000001a8, 0x00000003, + 0x0000002c, 0x00000060, 0x000000e4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, + 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, + 0x4e47534f, 0x0000007c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x00000000, 0x00000003, + 0x00000000, 0x0000000f, 0x00000072, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, + 0x00000068, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x00000072, 0x00000003, + 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x545f5653, 0x45475241, 0x56530054, 0x7261545f, + 0x00746567, 0x52444853, 0x000000bc, 0x00000040, 0x0000002f, 0x03000065, 0x001020f2, 0x00000000, + 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2, + 0x00000003, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, + 0x3f800000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, + 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x3e4ccccd, + 0x3e4ccccd, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x00000000, 0x3e4ccccd, 0x3f000000, + 0x3f800000, 0x0100003e, + }; + static const struct + { + struct vec2 position; + } + quad[] = + { + {{-1.0f, -1.0f}}, + {{-1.0f, 1.0f}}, + {{ 1.0f, -1.0f}}, + {{ 1.0f, 1.0f}}, + }; + static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f}; + + if (!(device = create_device(NULL))) + { + skip("Failed to create device.\n"); + return; + } + + if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_9_3) + { + skip("Feature level 9_3 or higher is required.\n"); + ID3D11Device_Release(device); + return; + } + + 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; + + resource_data.pSysMem = quad; + resource_data.SysMemPitch = 0; + resource_data.SysMemSlicePitch = 0; + + hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb); + ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr); + + texture_desc.Width = 640; + texture_desc.Height = 480; + texture_desc.MipLevels = 1; + texture_desc.ArraySize = 1; + texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + texture_desc.SampleDesc.Count = 1; + texture_desc.SampleDesc.Quality = 0; + texture_desc.Usage = D3D11_USAGE_DEFAULT; + texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET; + texture_desc.CPUAccessFlags = 0; + texture_desc.MiscFlags = 0; + + for (i = 0; i < sizeof(rt) / sizeof(*rt); ++i) + { + hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt[i]); + ok(SUCCEEDED(hr), "Failed to create texture %u, hr %#x.\n", i, hr); + + hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt[i], NULL, &rtv[i]); + ok(SUCCEEDED(hr), "Failed to create rendertarget view %u, hr %#x.\n", i, 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); + + ID3D11Device_GetImmediateContext(device, &context); + + ID3D11DeviceContext_OMSetRenderTargets(context, 4, rtv, NULL); + ID3D11DeviceContext_IASetInputLayout(context, input_layout); + ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); + stride = sizeof(*quad); + offset = 0; + ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset); + ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0); + ID3D11DeviceContext_PSSetShader(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(context, 1, &vp); + + for (i = 0; i < sizeof(rtv) / sizeof(*rtv); ++i) + ID3D11DeviceContext_ClearRenderTargetView(context, rtv[i], red); + + ID3D11DeviceContext_Draw(context, 4, 0); + + color = get_texture_color(rt[0], 320, 240); + ok(compare_color(color, 0xffffffff, 2), "Got unexpected color 0x%08x.\n", color); + color = get_texture_color(rt[1], 320, 240); + ok(compare_color(color, 0x7f7f7f7f, 2), "Got unexpected color 0x%08x.\n", color); + color = get_texture_color(rt[2], 320, 240); + ok(compare_color(color, 0x33333333, 2), "Got unexpected color 0x%08x.\n", color); + color = get_texture_color(rt[3], 320, 240); + ok(compare_color(color, 0xff7f3300, 2), "Got unexpected color 0x%08x.\n", color); + + ID3D11Buffer_Release(vb); + ID3D11PixelShader_Release(ps); + ID3D11VertexShader_Release(vs); + ID3D11InputLayout_Release(input_layout); + for (i = 0; i < sizeof(rtv) / sizeof(*rtv); ++i) + ID3D11RenderTargetView_Release(rtv[i]); + for (i = 0; i < sizeof(rt) / sizeof(*rt); ++i) + ID3D11Texture2D_Release(rt[i]); + ID3D11DeviceContext_Release(context); + refcount = ID3D11Device_Release(device); + ok(!refcount, "Device has %u references left.\n", refcount); +} + static void test_scissor(void) { ID3D11DeviceContext *immediate_context; @@ -5205,6 +5396,7 @@ START_TEST(d3d11) test_private_data(); test_blend(); test_texture(); + test_multiple_render_targets(); test_scissor(); test_il_append_aligned(); test_fragment_coords();