diff --git a/dlls/d3d10core/tests/device.c b/dlls/d3d10core/tests/device.c index dd9ef4666a8..36a4ab0fbbc 100644 --- a/dlls/d3d10core/tests/device.c +++ b/dlls/d3d10core/tests/device.c @@ -22,11 +22,21 @@ #include "wine/test.h" #include +struct vec2 +{ + float x, y; +}; + struct vec3 { float x, y, z; }; +struct vec4 +{ + float x, y, z, w; +}; + static ULONG get_refcount(IUnknown *iface) { IUnknown_AddRef(iface); @@ -2688,6 +2698,242 @@ static void test_private_data(void) ok(!refcount, "Test object has %u references left.\n", refcount); } +static void test_il_append_aligned(void) +{ + ID3D10RenderTargetView *backbuffer_rtv; + D3D10_SUBRESOURCE_DATA resource_data; + ID3D10InputLayout *input_layout; + D3D10_BUFFER_DESC buffer_desc; + ID3D10Texture2D *backbuffer; + unsigned int stride, offset; + IDXGISwapChain *swapchain; + ID3D10VertexShader *vs; + ID3D10PixelShader *ps; + ID3D10Device *device; + ID3D10Buffer *vb[3]; + D3D10_VIEWPORT vp; + ULONG refcount; + DWORD color; + HWND window; + HRESULT hr; + + static const D3D10_INPUT_ELEMENT_DESC layout_desc[] = + { + {"COLOR", 2, DXGI_FORMAT_R32G32_FLOAT, 1, D3D10_APPEND_ALIGNED_ELEMENT, + D3D10_INPUT_PER_INSTANCE_DATA, 2}, + {"COLOR", 3, DXGI_FORMAT_R32G32_FLOAT, 2, D3D10_APPEND_ALIGNED_ELEMENT, + D3D10_INPUT_PER_INSTANCE_DATA, 1}, + {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D10_APPEND_ALIGNED_ELEMENT, + D3D10_INPUT_PER_VERTEX_DATA, 0}, + {"COLOR", 0, DXGI_FORMAT_R32G32_FLOAT, 2, D3D10_APPEND_ALIGNED_ELEMENT, + D3D10_INPUT_PER_INSTANCE_DATA, 1}, + {"COLOR", 1, DXGI_FORMAT_R32G32_FLOAT, 1, D3D10_APPEND_ALIGNED_ELEMENT, + D3D10_INPUT_PER_INSTANCE_DATA, 2}, + }; + static const DWORD vs_code[] = + { +#if 0 + struct vs_in + { + float4 position : POSITION; + float2 color_xy : COLOR0; + float2 color_zw : COLOR1; + unsigned int instance_id : SV_INSTANCEID; + }; + + struct vs_out + { + float4 position : SV_POSITION; + float2 color_xy : COLOR0; + float2 color_zw : COLOR1; + }; + + struct vs_out main(struct vs_in i) + { + struct vs_out o; + + o.position = i.position; + o.position.x += i.instance_id * 0.5; + o.color_xy = i.color_xy; + o.color_zw = i.color_zw; + + return o; + } +#endif + 0x43425844, 0x52e3bf46, 0x6300403d, 0x624cffe4, 0xa4fc0013, 0x00000001, 0x00000214, 0x00000003, + 0x0000002c, 0x000000bc, 0x00000128, 0x4e475349, 0x00000088, 0x00000004, 0x00000008, 0x00000068, + 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000, + 0x00000003, 0x00000001, 0x00000303, 0x00000071, 0x00000001, 0x00000000, 0x00000003, 0x00000002, + 0x00000303, 0x00000077, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x49534f50, + 0x4e4f4954, 0x4c4f4300, 0x5300524f, 0x4e495f56, 0x4e415453, 0x44494543, 0xababab00, 0x4e47534f, + 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, + 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03, 0x0000005c, + 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000030c, 0x505f5653, 0x5449534f, 0x004e4f49, + 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000e4, 0x00010040, 0x00000039, 0x0300005f, 0x001010f2, + 0x00000000, 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x00101032, 0x00000002, 0x04000060, + 0x00101012, 0x00000003, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, + 0x00102032, 0x00000001, 0x03000065, 0x001020c2, 0x00000001, 0x02000068, 0x00000001, 0x05000056, + 0x00100012, 0x00000000, 0x0010100a, 0x00000003, 0x09000032, 0x00102012, 0x00000000, 0x0010000a, + 0x00000000, 0x00004001, 0x3f000000, 0x0010100a, 0x00000000, 0x05000036, 0x001020e2, 0x00000000, + 0x00101e56, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046, 0x00000001, 0x05000036, + 0x001020c2, 0x00000001, 0x00101406, 0x00000002, 0x0100003e, + }; + static const DWORD ps_code[] = + { +#if 0 + struct vs_out + { + float4 position : SV_POSITION; + float2 color_xy : COLOR0; + float2 color_zw : COLOR1; + }; + + float4 main(struct vs_out i) : SV_TARGET + { + return float4(i.color_xy.xy, i.color_zw.xy); + } +#endif + 0x43425844, 0x64e48a09, 0xaa484d46, 0xe40a6e78, 0x9885edf3, 0x00000001, 0x00000118, 0x00000003, + 0x0000002c, 0x00000098, 0x000000cc, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050, + 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, + 0x00000003, 0x00000001, 0x00000303, 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, + 0x00000c0c, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, + 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, + 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000044, 0x00000040, 0x00000011, 0x03001062, + 0x00101032, 0x00000001, 0x03001062, 0x001010c2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, + 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e, + }; + static const struct + { + struct vec4 position; + } + stream0[] = + { + {{-1.0f, -1.0f, 0.0f, 1.0f}}, + {{-1.0f, 1.0f, 0.0f, 1.0f}}, + {{-0.5f, -1.0f, 0.0f, 1.0f}}, + {{-0.5f, 1.0f, 0.0f, 1.0f}}, + }; + static const struct + { + struct vec2 color2; + struct vec2 color1; + } + stream1[] = + { + {{0.5f, 0.5f}, {0.0f, 1.0f}}, + {{0.5f, 0.5f}, {1.0f, 1.0f}}, + }; + static const struct + { + struct vec2 color3; + struct vec2 color0; + } + stream2[] = + { + {{0.5f, 0.5f}, {1.0f, 0.0f}}, + {{0.5f, 0.5f}, {0.0f, 1.0f}}, + {{0.5f, 0.5f}, {0.0f, 0.0f}}, + {{0.5f, 0.5f}, {1.0f, 0.0f}}, + }; + static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f}; + + if (!(device = create_device())) + { + skip("Failed to create device, skipping tests.\n"); + return; + } + window = CreateWindowA("static", "d3d10core_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_ID3D10Texture2D, (void **)&backbuffer); + ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr); + + hr = ID3D10Device_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(stream0); + buffer_desc.Usage = D3D10_USAGE_DEFAULT; + buffer_desc.BindFlags = D3D10_BIND_VERTEX_BUFFER; + buffer_desc.CPUAccessFlags = 0; + buffer_desc.MiscFlags = 0; + + resource_data.pSysMem = stream0; + resource_data.SysMemPitch = 0; + resource_data.SysMemSlicePitch = 0; + + hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb[0]); + ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr); + + buffer_desc.ByteWidth = sizeof(stream1); + resource_data.pSysMem = stream1; + + hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb[1]); + ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr); + + buffer_desc.ByteWidth = sizeof(stream2); + resource_data.pSysMem = stream2; + + hr = ID3D10Device_CreateBuffer(device, &buffer_desc, &resource_data, &vb[2]); + ok(SUCCEEDED(hr), "Failed to create vertex buffer, hr %#x.\n", hr); + + hr = ID3D10Device_CreateVertexShader(device, vs_code, sizeof(vs_code), &vs); + ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr); + hr = ID3D10Device_CreatePixelShader(device, ps_code, sizeof(ps_code), &ps); + ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr); + + hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)backbuffer, NULL, &backbuffer_rtv); + ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr); + + ID3D10Device_OMSetRenderTargets(device, 1, &backbuffer_rtv, NULL); + ID3D10Device_IASetInputLayout(device, input_layout); + ID3D10Device_IASetPrimitiveTopology(device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); + offset = 0; + stride = sizeof(*stream0); + ID3D10Device_IASetVertexBuffers(device, 0, 1, &vb[0], &stride, &offset); + stride = sizeof(*stream1); + ID3D10Device_IASetVertexBuffers(device, 1, 1, &vb[1], &stride, &offset); + stride = sizeof(*stream2); + ID3D10Device_IASetVertexBuffers(device, 2, 1, &vb[2], &stride, &offset); + ID3D10Device_VSSetShader(device, vs); + ID3D10Device_PSSetShader(device, ps); + + vp.TopLeftX = 0; + vp.TopLeftY = 0; + vp.Width = 640; + vp.Height = 480; + vp.MinDepth = 0.0f; + vp.MaxDepth = 1.0f; + ID3D10Device_RSSetViewports(device, 1, &vp); + + ID3D10Device_ClearRenderTargetView(device, backbuffer_rtv, red); + + ID3D10Device_DrawInstanced(device, 4, 4, 0, 0); + + 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, 240, 240); + ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color); + color = get_texture_color(backbuffer, 400, 240); + ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color); + color = get_texture_color(backbuffer, 560, 240); + ok(compare_color(color, 0xffff00ff, 1), "Got unexpected color 0x%08x.\n", color); + + ID3D10PixelShader_Release(ps); + ID3D10VertexShader_Release(vs); + ID3D10Buffer_Release(vb[2]); + ID3D10Buffer_Release(vb[1]); + ID3D10Buffer_Release(vb[0]); + ID3D10InputLayout_Release(input_layout); + ID3D10RenderTargetView_Release(backbuffer_rtv); + ID3D10Texture2D_Release(backbuffer); + IDXGISwapChain_Release(swapchain); + refcount = ID3D10Device_Release(device); + ok(!refcount, "Device has %u references left.\n", refcount); + DestroyWindow(window); +} + START_TEST(device) { test_create_texture2d(); @@ -2707,4 +2953,5 @@ START_TEST(device) test_blend(); test_texture(); test_private_data(); + test_il_append_aligned(); }