From c3e48c9b190b5f02a2624d27918fdb97d36e05bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zef=20Kucia?= Date: Fri, 6 Nov 2015 01:28:28 +0100 Subject: [PATCH] d3d11/tests: Port test_blend() from d3d10core. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Józef Kucia Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- dlls/d3d11/tests/d3d11.c | 258 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 258 insertions(+) diff --git a/dlls/d3d11/tests/d3d11.c b/dlls/d3d11/tests/d3d11.c index d7ace558a54..ddb524dac9c 100644 --- a/dlls/d3d11/tests/d3d11.c +++ b/dlls/d3d11/tests/d3d11.c @@ -38,6 +38,11 @@ struct vec2 float x, y; }; +struct vec3 +{ + float x, y, z; +}; + struct vec4 { float x, y, z, w; @@ -2544,6 +2549,258 @@ static void test_private_data(void) ok(!refcount, "Test object has %u references left.\n", refcount); } +static void test_blend(void) +{ + ID3D11RenderTargetView *backbuffer_rtv, *offscreen_rtv; + ID3D11BlendState *src_blend, *dst_blend; + ID3D11Texture2D *backbuffer, *offscreen; + D3D11_SUBRESOURCE_DATA buffer_data; + D3D11_TEXTURE2D_DESC texture_desc; + ID3D11InputLayout *input_layout; + D3D11_BUFFER_DESC buffer_desc; + ID3D11DeviceContext *context; + D3D11_BLEND_DESC blend_desc; + unsigned int stride, offset; + IDXGISwapChain *swapchain; + ID3D11VertexShader *vs; + ID3D11PixelShader *ps; + ID3D11Device *device; + D3D11_VIEWPORT vp; + ID3D11Buffer *vb; + ULONG refcount; + DWORD color; + HWND window; + HRESULT hr; + + static const DWORD vs_code[] = + { +#if 0 + struct vs_out + { + float4 position : SV_POSITION; + float4 color : COLOR; + }; + + struct vs_out main(float4 position : POSITION, float4 color : COLOR) + { + struct vs_out o; + + o.position = position; + o.color = color; + + return o; + } +#endif + 0x43425844, 0x5c73b061, 0x5c71125f, 0x3f8b345f, 0xce04b9ab, 0x00000001, 0x00000140, 0x00000003, + 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038, + 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000, + 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f, + 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000, + 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653, + 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040, 0x0000001a, + 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067, 0x001020f2, + 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, + 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x0100003e, + }; + static const DWORD ps_code[] = + { +#if 0 + struct vs_out + { + float4 position : SV_POSITION; + float4 color : COLOR; + }; + + float4 main(struct vs_out i) : SV_TARGET + { + return i.color; + } +#endif + 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003, + 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, + 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, + 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, + 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, + 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, + 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, + 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e, + }; + static const struct + { + struct vec3 position; + DWORD diffuse; + } + quads[] = + { + /* quad1 */ + {{-1.0f, -1.0f, 0.1f}, 0x4000ff00}, + {{-1.0f, 0.0f, 0.1f}, 0x4000ff00}, + {{ 1.0f, -1.0f, 0.1f}, 0x4000ff00}, + {{ 1.0f, 0.0f, 0.1f}, 0x4000ff00}, + /* quad2 */ + {{-1.0f, 0.0f, 0.1f}, 0xc0ff0000}, + {{-1.0f, 1.0f, 0.1f}, 0xc0ff0000}, + {{ 1.0f, 0.0f, 0.1f}, 0xc0ff0000}, + {{ 1.0f, 1.0f, 0.1f}, 0xc0ff0000}, + }; + static const D3D11_INPUT_ELEMENT_DESC layout_desc[] = + { + {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0}, + {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0}, + }; + static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f}; + static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f}; + + 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(quads); + 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 = quads; + 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); + + hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer, NULL, &backbuffer_rtv); + ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr); + + memset(&blend_desc, 0, sizeof(blend_desc)); + blend_desc.RenderTarget[0].BlendEnable = TRUE; + blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA; + blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA; + blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; + blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA; + blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA; + blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; + blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; + + hr = ID3D11Device_CreateBlendState(device, &blend_desc, &src_blend); + ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr); + + blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_DEST_ALPHA; + blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_DEST_ALPHA; + blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_DEST_ALPHA; + blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_DEST_ALPHA; + + hr = ID3D11Device_CreateBlendState(device, &blend_desc, &dst_blend); + ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr); + + ID3D11Device_GetImmediateContext(device, &context); + + ID3D11DeviceContext_OMSetRenderTargets(context, 1, &backbuffer_rtv, NULL); + ID3D11DeviceContext_IASetInputLayout(context, input_layout); + ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); + stride = sizeof(*quads); + 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); + + ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_rtv, red); + + ID3D11DeviceContext_OMSetBlendState(context, src_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK); + ID3D11DeviceContext_Draw(context, 4, 0); + ID3D11DeviceContext_OMSetBlendState(context, dst_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK); + ID3D11DeviceContext_Draw(context, 4, 4); + + color = get_texture_color(backbuffer, 320, 360); + ok(compare_color(color, 0x700040bf, 1), "Got unexpected color 0x%08x.\n", color); + color = get_texture_color(backbuffer, 320, 120); + ok(compare_color(color, 0xa080007f, 1), "Got unexpected color 0x%08x.\n", color); + + texture_desc.Width = 128; + texture_desc.Height = 128; + texture_desc.MipLevels = 1; + texture_desc.ArraySize = 1; + texture_desc.Format = DXGI_FORMAT_B8G8R8X8_UNORM; + texture_desc.SampleDesc.Count = 1; + texture_desc.SampleDesc.Quality = 0; + texture_desc.Usage = D3D11_USAGE_DEFAULT; + texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET; + texture_desc.CPUAccessFlags = 0; + texture_desc.MiscFlags = 0; + + /* DXGI_FORMAT_B8G8R8X8_UNORM is not supported on all implementations. */ + if (FAILED(ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen))) + { + skip("DXGI_FORMAT_B8G8R8X8_UNORM not supported.\n"); + goto done; + } + + hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv); + ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr); + + ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL); + + vp.TopLeftX = 0.0f; + vp.TopLeftY = 0.0f; + vp.Width = 128.0f; + vp.Height = 128.0f; + vp.MinDepth = 0.0f; + vp.MaxDepth = 1.0f; + ID3D11DeviceContext_RSSetViewports(context, 1, &vp); + + ID3D11DeviceContext_ClearRenderTargetView(context, offscreen_rtv, red); + + ID3D11DeviceContext_OMSetBlendState(context, src_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK); + ID3D11DeviceContext_Draw(context, 4, 0); + ID3D11DeviceContext_OMSetBlendState(context, dst_blend, blend_factor, D3D11_DEFAULT_SAMPLE_MASK); + ID3D11DeviceContext_Draw(context, 4, 4); + + color = get_texture_color(offscreen, 64, 96) & 0x00ffffff; + ok(compare_color(color, 0x00bf4000, 1), "Got unexpected color 0x%08x.\n", color); + color = get_texture_color(offscreen, 64, 32) & 0x00ffffff; + ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color); + + ID3D11RenderTargetView_Release(offscreen_rtv); + ID3D11Texture2D_Release(offscreen); +done: + ID3D11BlendState_Release(dst_blend); + ID3D11BlendState_Release(src_blend); + ID3D11PixelShader_Release(ps); + ID3D11VertexShader_Release(vs); + ID3D11Buffer_Release(vb); + ID3D11InputLayout_Release(input_layout); + ID3D11RenderTargetView_Release(backbuffer_rtv); + ID3D11Texture2D_Release(backbuffer); + IDXGISwapChain_Release(swapchain); + ID3D11DeviceContext_Release(context); + refcount = ID3D11Device_Release(device); + ok(!refcount, "Device has %u references left.\n", refcount); + DestroyWindow(window); +} + static void test_scissor(void) { ID3D11DeviceContext *immediate_context; @@ -3154,6 +3411,7 @@ START_TEST(d3d11) test_create_predicate(); test_device_removed_reason(); test_private_data(); + test_blend(); test_scissor(); test_il_append_aligned(); test_resource_map();