Commit 7520af47 authored by Zebediah Figura's avatar Zebediah Figura Committed by Alexandre Julliard

d3d11/tests: Add a test for independent blend.

parent 655fea55
......@@ -29850,6 +29850,152 @@ static void test_color_mask(void)
release_test_context(&test_context);
}
static void test_independent_blend(void)
{
struct d3d11_test_context test_context;
D3D11_TEXTURE2D_DESC texture_desc;
ID3D11RenderTargetView *rtvs[8];
ID3D11BlendState *blend_state;
ID3D11DeviceContext *context;
struct resource_readback rb;
ID3D11Texture2D *rts[8];
ID3D11PixelShader *ps;
ID3D11Device *device;
unsigned int i;
DWORD color;
HRESULT hr;
static const DWORD ps_code[] =
{
#if 0
void main(float4 position : SV_Position,
out float4 t0 : SV_Target0, out float4 t1 : SV_Target1,
out float4 t2 : SV_Target2, out float4 t3 : SV_Target3,
out float4 t4 : SV_Target4, out float4 t5 : SV_Target5,
out float4 t6 : SV_Target6, out float4 t7 : SV_Target7)
{
t0 = t1 = t2 = t3 = t4 = t5 = t6 = t7 = float4(0.1f, 0.2f, 0.3f, 0.4f);
}
#endif
0x43425844, 0xb3dca7dc, 0x4a31f0f1, 0x747569cb, 0xae7af5ce, 0x00000001, 0x000002b0, 0x00000003,
0x0000002c, 0x00000060, 0x0000013c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69,
0x4e47534f, 0x000000d4, 0x00000008, 0x00000008, 0x000000c8, 0x00000000, 0x00000000, 0x00000003,
0x00000000, 0x0000000f, 0x000000c8, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
0x000000c8, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x000000c8, 0x00000003,
0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x000000c8, 0x00000004, 0x00000000, 0x00000003,
0x00000004, 0x0000000f, 0x000000c8, 0x00000005, 0x00000000, 0x00000003, 0x00000005, 0x0000000f,
0x000000c8, 0x00000006, 0x00000000, 0x00000003, 0x00000006, 0x0000000f, 0x000000c8, 0x00000007,
0x00000000, 0x00000003, 0x00000007, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853,
0x0000016c, 0x00000040, 0x0000005b, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000003, 0x03000065,
0x001020f2, 0x00000004, 0x03000065, 0x001020f2, 0x00000005, 0x03000065, 0x001020f2, 0x00000006,
0x03000065, 0x001020f2, 0x00000007, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3dcccccd,
0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3dcccccd,
0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3dcccccd,
0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x3dcccccd,
0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000004, 0x00004002, 0x3dcccccd,
0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000005, 0x00004002, 0x3dcccccd,
0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000006, 0x00004002, 0x3dcccccd,
0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000007, 0x00004002, 0x3dcccccd,
0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x0100003e,
};
D3D11_BLEND_DESC blend_desc =
{
.IndependentBlendEnable = TRUE,
.RenderTarget =
{
{TRUE, D3D11_BLEND_SRC_ALPHA, D3D11_BLEND_DEST_ALPHA, D3D11_BLEND_OP_ADD,
D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL},
{TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL},
{TRUE, D3D11_BLEND_SRC_COLOR, D3D11_BLEND_DEST_COLOR, D3D11_BLEND_OP_ADD,
D3D11_BLEND_SRC_ALPHA, D3D11_BLEND_DEST_ALPHA, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL},
{TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MIN,
D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MIN, D3D11_COLOR_WRITE_ENABLE_ALL},
{TRUE, D3D11_BLEND_BLEND_FACTOR, D3D11_BLEND_BLEND_FACTOR, D3D11_BLEND_OP_ADD,
D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL},
{TRUE, D3D11_BLEND_INV_SRC_ALPHA, D3D11_BLEND_INV_BLEND_FACTOR, D3D11_BLEND_OP_SUBTRACT,
D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_REV_SUBTRACT, D3D11_COLOR_WRITE_ENABLE_ALL},
{FALSE},
{TRUE, D3D11_BLEND_DEST_COLOR, D3D11_BLEND_SRC_COLOR, D3D11_BLEND_OP_ADD,
D3D11_BLEND_INV_SRC_ALPHA, D3D11_BLEND_INV_DEST_ALPHA, D3D11_BLEND_OP_SUBTRACT,
D3D11_COLOR_WRITE_ENABLE_ALL},
},
};
static const DWORD expected_colors[] =
{0x66426e1c, 0xb34c3319, 0xa6214a05, 0x66333319, 0xb34c4829, 0x4d19000a, 0xb333801a, 0x081f3305};
static const float clear_color[] = {0.1f, 0.5f, 0.2f, 0.7f};
static const float blend_factor[] = {0.8f, 0.4f, 0.6f, 0.2f};
if (!init_test_context(&test_context, NULL))
return;
device = test_context.device;
context = test_context.immediate_context;
hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
ID3D11DeviceContext_OMSetBlendState(context, blend_state, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
ID3D11BlendState_Release(blend_state);
for (i = 0; i < 8; ++i)
{
ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rts[i]);
ok(hr == S_OK, "Failed to create texture %u, hr %#x.\n", i, hr);
hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rts[i], NULL, &rtvs[i]);
ok(hr == S_OK, "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
}
ID3D11DeviceContext_OMSetRenderTargets(context, 8, rtvs, NULL);
for (i = 0; i < 8; ++i)
ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], clear_color);
draw_quad(&test_context);
for (i = 0; i < 8; ++i)
{
get_texture_readback(rts[i], 0, &rb);
color = get_readback_color(&rb, 320, 240, 0);
todo_wine_if (i)
ok(compare_color(color, expected_colors[i], 1), "%u: Got unexpected color 0x%08x.\n", i, color);
release_resource_readback(&rb);
}
blend_desc.IndependentBlendEnable = FALSE;
hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
ID3D11DeviceContext_OMSetBlendState(context, blend_state, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
ID3D11BlendState_Release(blend_state);
for (i = 0; i < 8; ++i)
ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], clear_color);
draw_quad(&test_context);
for (i = 0; i < 8; ++i)
{
get_texture_readback(rts[i], 0, &rb);
color = get_readback_color(&rb, 320, 240, 0);
ok(compare_color(color, expected_colors[0], 1), "%u: Got unexpected color 0x%08x.\n", i, color);
release_resource_readback(&rb);
ID3D11Texture2D_Release(rts[i]);
ID3D11RenderTargetView_Release(rtvs[i]);
}
ID3D11PixelShader_Release(ps);
release_test_context(&test_context);
}
START_TEST(d3d11)
{
unsigned int argc, i;
......@@ -30011,6 +30157,7 @@ START_TEST(d3d11)
queue_test(test_desktop_window);
queue_test(test_sample_attached_rtv);
queue_test(test_color_mask);
queue_test(test_independent_blend);
run_queued_tests();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment