[PATCH v2 2/3] d3dcompiler/tests: Port some tests to shader model 4.

Matteo Bruni mbruni at codeweavers.com
Fri Feb 28 04:24:00 CST 2020


From: Zebediah Figura <z.figura12 at gmail.com>

In particular, port those for which there is an interesting difference in
code generation.

Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni at codeweavers.com>
---
 dlls/d3dcompiler_43/tests/Makefile.in  |   1 +
 dlls/d3dcompiler_43/tests/hlsl_d3d11.c | 562 +++++++++++++++++++++++++
 dlls/d3dcompiler_43/tests/hlsl_d3d9.c  |  37 +-
 dlls/d3dcompiler_47/tests/Makefile.in  |   1 +
 4 files changed, 585 insertions(+), 16 deletions(-)
 create mode 100644 dlls/d3dcompiler_43/tests/hlsl_d3d11.c

diff --git a/dlls/d3dcompiler_43/tests/Makefile.in b/dlls/d3dcompiler_43/tests/Makefile.in
index f00d8560826..1b9024b7a55 100644
--- a/dlls/d3dcompiler_43/tests/Makefile.in
+++ b/dlls/d3dcompiler_43/tests/Makefile.in
@@ -5,5 +5,6 @@ EXTRADEFS = -DD3D_COMPILER_VERSION=43
 C_SRCS = \
 	asm.c \
 	blob.c \
+	hlsl_d3d11.c \
 	hlsl_d3d9.c \
 	reflection.c
diff --git a/dlls/d3dcompiler_43/tests/hlsl_d3d11.c b/dlls/d3dcompiler_43/tests/hlsl_d3d11.c
new file mode 100644
index 00000000000..ed95457f1c7
--- /dev/null
+++ b/dlls/d3dcompiler_43/tests/hlsl_d3d11.c
@@ -0,0 +1,562 @@
+/*
+ * Copyright (C) 2020 Zebediah Figura for CodeWeavers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <limits.h>
+#include <math.h>
+
+#define COBJMACROS
+#include "d3dcompiler.h"
+#include "d3d11.h"
+#include "wine/test.h"
+
+static pD3DCompile ppD3DCompile;
+static HRESULT (WINAPI *pD3DReflect)(const void *data, SIZE_T size, REFIID iid, void **out);
+
+static HRESULT (WINAPI *pD3D11CreateDevice)(IDXGIAdapter *adapter, D3D_DRIVER_TYPE driver_type,
+        HMODULE swrast, UINT flags, const D3D_FEATURE_LEVEL *feature_levels, UINT levels,
+        UINT sdk_version, ID3D11Device **device_out, D3D_FEATURE_LEVEL *obtained_feature_level,
+        ID3D11DeviceContext **immediate_context);
+
+struct vec2
+{
+    float x, y;
+};
+
+struct vec4
+{
+    float x, y, z, w;
+};
+
+#define compile_shader(a, b) compile_shader_(__LINE__, a, b)
+static ID3D10Blob *compile_shader_(unsigned int line, const char *source, const char *target)
+{
+    ID3D10Blob *blob = NULL, *errors = NULL;
+    HRESULT hr;
+
+    hr = ppD3DCompile(source, strlen(source), NULL, NULL, NULL, "main", target, 0, 0, &blob, &errors);
+    ok_(__FILE__, line)(hr == S_OK, "Failed to compile shader, hr %#x.\n", hr);
+    if (errors)
+    {
+        if (winetest_debug > 1)
+            trace_(__FILE__, line)("%s\n", (char *)ID3D10Blob_GetBufferPointer(errors));
+        ID3D10Blob_Release(errors);
+    }
+    return blob;
+}
+
+static BOOL compare_float(float f, float g, unsigned int ulps)
+{
+    int x = *(int *)&f;
+    int y = *(int *)&g;
+
+    if (x < 0)
+        x = INT_MIN - x;
+    if (y < 0)
+        y = INT_MIN - y;
+
+    if (abs(x - y) > ulps)
+        return FALSE;
+
+    return TRUE;
+}
+
+static BOOL compare_vec4(const struct vec4 *vec, float x, float y, float z, float w, unsigned int ulps)
+{
+    return compare_float(vec->x, x, ulps)
+            && compare_float(vec->y, y, ulps)
+            && compare_float(vec->z, z, ulps)
+            && compare_float(vec->w, w, ulps);
+}
+
+struct test_context
+{
+    ID3D11Device *device;
+    HWND window;
+    IDXGISwapChain *swapchain;
+    ID3D11Texture2D *rt;
+    ID3D11RenderTargetView *rtv;
+    ID3D11DeviceContext *immediate_context;
+
+    ID3D11InputLayout *input_layout;
+    ID3D11VertexShader *vs;
+    ID3D11Buffer *vb;
+};
+
+static ID3D11Device *create_device(void)
+{
+    static const D3D_FEATURE_LEVEL feature_level[] =
+    {
+        D3D_FEATURE_LEVEL_11_0,
+        D3D_FEATURE_LEVEL_10_1,
+        D3D_FEATURE_LEVEL_10_0,
+    };
+    ID3D11Device *device;
+
+    if (SUCCEEDED(pD3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0,
+            feature_level, ARRAY_SIZE(feature_level), D3D11_SDK_VERSION, &device, NULL, NULL)))
+        return device;
+    if (SUCCEEDED(pD3D11CreateDevice(NULL, D3D_DRIVER_TYPE_WARP, NULL, 0,
+            feature_level, ARRAY_SIZE(feature_level), D3D11_SDK_VERSION, &device, NULL, NULL)))
+        return device;
+    if (SUCCEEDED(pD3D11CreateDevice(NULL, D3D_DRIVER_TYPE_REFERENCE, NULL, 0,
+            feature_level, ARRAY_SIZE(feature_level), D3D11_SDK_VERSION, &device, NULL, NULL)))
+        return device;
+
+    return NULL;
+}
+
+static IDXGISwapChain *create_swapchain(ID3D11Device *device, HWND window)
+{
+    DXGI_SWAP_CHAIN_DESC dxgi_desc;
+    IDXGISwapChain *swapchain;
+    IDXGIDevice *dxgi_device;
+    IDXGIAdapter *adapter;
+    IDXGIFactory *factory;
+    HRESULT hr;
+
+    hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
+    ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
+    hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
+    ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
+    IDXGIDevice_Release(dxgi_device);
+    hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
+    ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
+    IDXGIAdapter_Release(adapter);
+
+    dxgi_desc.BufferDesc.Width = 640;
+    dxgi_desc.BufferDesc.Height = 480;
+    dxgi_desc.BufferDesc.RefreshRate.Numerator = 60;
+    dxgi_desc.BufferDesc.RefreshRate.Denominator = 1;
+    dxgi_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
+    dxgi_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
+    dxgi_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
+    dxgi_desc.SampleDesc.Count = 1;
+    dxgi_desc.SampleDesc.Quality = 0;
+    dxgi_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
+    dxgi_desc.BufferCount = 1;
+    dxgi_desc.OutputWindow = window;
+    dxgi_desc.Windowed = TRUE;
+    dxgi_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
+    dxgi_desc.Flags = 0;
+
+    hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &dxgi_desc, &swapchain);
+    ok(SUCCEEDED(hr), "Failed to create swapchain, hr %#x.\n", hr);
+    IDXGIFactory_Release(factory);
+
+    return swapchain;
+}
+
+#define init_test_context(a) init_test_context_(__LINE__, a)
+static BOOL init_test_context_(unsigned int line, struct test_context *context)
+{
+    const D3D11_TEXTURE2D_DESC texture_desc =
+    {
+        .Width = 640,
+        .Height = 480,
+        .MipLevels = 1,
+        .ArraySize = 1,
+        .Format = DXGI_FORMAT_R32G32B32A32_FLOAT,
+        .SampleDesc.Count = 1,
+        .Usage = D3D11_USAGE_DEFAULT,
+        .BindFlags = D3D11_BIND_RENDER_TARGET,
+    };
+    unsigned int rt_width, rt_height;
+    D3D11_VIEWPORT vp;
+    HRESULT hr;
+    RECT rect;
+
+    memset(context, 0, sizeof(*context));
+
+    if (!(context->device = create_device()))
+    {
+        skip_(__FILE__, line)("Failed to create device.\n");
+        return FALSE;
+    }
+
+    rt_width = 640;
+    rt_height = 480;
+    SetRect(&rect, 0, 0, rt_width, rt_height);
+    AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE);
+    context->window = CreateWindowA("static", "d3dcompiler_test", WS_OVERLAPPEDWINDOW,
+            0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
+    context->swapchain = create_swapchain(context->device, context->window);
+
+    hr = ID3D11Device_CreateTexture2D(context->device, &texture_desc, NULL, &context->rt);
+    ok_(__FILE__, line)(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
+
+    hr = ID3D11Device_CreateRenderTargetView(context->device, (ID3D11Resource *)context->rt, NULL, &context->rtv);
+    ok_(__FILE__, line)(hr == S_OK, "Failed to create rendertarget view, hr %#x.\n", hr);
+
+    ID3D11Device_GetImmediateContext(context->device, &context->immediate_context);
+
+    ID3D11DeviceContext_OMSetRenderTargets(context->immediate_context, 1, &context->rtv, NULL);
+
+    vp.TopLeftX = 0.0f;
+    vp.TopLeftY = 0.0f;
+    vp.Width = rt_width;
+    vp.Height = rt_height;
+    vp.MinDepth = 0.0f;
+    vp.MaxDepth = 1.0f;
+    ID3D11DeviceContext_RSSetViewports(context->immediate_context, 1, &vp);
+
+    return TRUE;
+}
+
+#define release_test_context(context) release_test_context_(__LINE__, context)
+static void release_test_context_(unsigned int line, struct test_context *context)
+{
+    ULONG ref;
+
+    if (context->input_layout)
+        ID3D11InputLayout_Release(context->input_layout);
+    if (context->vs)
+        ID3D11VertexShader_Release(context->vs);
+    if (context->vb)
+        ID3D11Buffer_Release(context->vb);
+
+    ID3D11DeviceContext_Release(context->immediate_context);
+    ID3D11RenderTargetView_Release(context->rtv);
+    ID3D11Texture2D_Release(context->rt);
+    IDXGISwapChain_Release(context->swapchain);
+    DestroyWindow(context->window);
+
+    ref = ID3D11Device_Release(context->device);
+    ok_(__FILE__, line)(!ref, "Device has %u references left.\n", ref);
+}
+
+#define create_buffer(a, b, c, d) create_buffer_(__LINE__, a, b, c, d)
+static ID3D11Buffer *create_buffer_(unsigned int line, ID3D11Device *device,
+        unsigned int bind_flags, unsigned int size, const void *data)
+{
+    D3D11_SUBRESOURCE_DATA resource_data = {.pSysMem = data};
+    D3D11_BUFFER_DESC buffer_desc =
+    {
+        .ByteWidth = size,
+        .Usage = D3D11_USAGE_DEFAULT,
+        .BindFlags = bind_flags,
+    };
+    ID3D11Buffer *buffer;
+    HRESULT hr;
+
+    hr = ID3D11Device_CreateBuffer(device, &buffer_desc, data ? &resource_data : NULL, &buffer);
+    ok_(__FILE__, line)(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
+    return buffer;
+}
+
+#define draw_quad(context, ps_code) draw_quad_(__LINE__, context, ps_code)
+static void draw_quad_(unsigned int line, struct test_context *context, ID3D10Blob *ps_code)
+{
+    static const D3D11_INPUT_ELEMENT_DESC default_layout_desc[] =
+    {
+        {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
+    };
+
+    static const char vs_source[] =
+        "float4 main(float4 position : POSITION) : SV_POSITION\n"
+        "{\n"
+        "    return position;\n"
+        "}";
+
+    static const struct vec2 quad[] =
+    {
+        {-1.0f, -1.0f},
+        {-1.0f,  1.0f},
+        { 1.0f, -1.0f},
+        { 1.0f,  1.0f},
+    };
+
+    ID3D11Device *device = context->device;
+    unsigned int stride, offset;
+    ID3D11PixelShader *ps;
+    HRESULT hr;
+
+    if (!context->vs)
+    {
+        ID3D10Blob *vs_code = compile_shader_(line, vs_source, "vs_4_0");
+
+        hr = ID3D11Device_CreateInputLayout(device, default_layout_desc, ARRAY_SIZE(default_layout_desc),
+                ID3D10Blob_GetBufferPointer(vs_code), ID3D10Blob_GetBufferSize(vs_code), &context->input_layout);
+        ok_(__FILE__, line)(hr == S_OK, "Failed to create input layout, hr %#x.\n", hr);
+
+        hr = ID3D11Device_CreateVertexShader(device, ID3D10Blob_GetBufferPointer(vs_code),
+                ID3D10Blob_GetBufferSize(vs_code), NULL, &context->vs);
+        ok_(__FILE__, line)(hr == S_OK, "Failed to create vertex shader, hr %#x.\n", hr);
+    }
+
+    if (!context->vb)
+        context->vb = create_buffer_(line, device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
+
+    hr = ID3D11Device_CreatePixelShader(device, ID3D10Blob_GetBufferPointer(ps_code),
+            ID3D10Blob_GetBufferSize(ps_code), NULL, &ps);
+    ok_(__FILE__, line)(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
+
+    ID3D11DeviceContext_IASetInputLayout(context->immediate_context, context->input_layout);
+    ID3D11DeviceContext_IASetPrimitiveTopology(context->immediate_context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
+    stride = sizeof(*quad);
+    offset = 0;
+    ID3D11DeviceContext_IASetVertexBuffers(context->immediate_context, 0, 1, &context->vb, &stride, &offset);
+    ID3D11DeviceContext_VSSetShader(context->immediate_context, context->vs, NULL, 0);
+    ID3D11DeviceContext_PSSetShader(context->immediate_context, ps, NULL, 0);
+
+    ID3D11DeviceContext_Draw(context->immediate_context, 4, 0);
+
+    ID3D11PixelShader_Release(ps);
+}
+
+struct readback
+{
+    ID3D11Resource *resource;
+    D3D11_MAPPED_SUBRESOURCE map_desc;
+};
+
+static void init_readback(struct test_context *context, struct readback *rb)
+{
+    D3D11_TEXTURE2D_DESC texture_desc;
+    HRESULT hr;
+
+    ID3D11Texture2D_GetDesc(context->rt, &texture_desc);
+    texture_desc.Usage = D3D11_USAGE_STAGING;
+    texture_desc.BindFlags = 0;
+    texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
+    texture_desc.MiscFlags = 0;
+    hr = ID3D11Device_CreateTexture2D(context->device, &texture_desc, NULL, (ID3D11Texture2D **)&rb->resource);
+    ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
+
+    ID3D11DeviceContext_CopyResource(context->immediate_context, rb->resource, (ID3D11Resource *)context->rt);
+    hr = ID3D11DeviceContext_Map(context->immediate_context, rb->resource, 0, D3D11_MAP_READ, 0, &rb->map_desc);
+    ok(hr == S_OK, "Failed to map texture, hr %#x.\n", hr);
+}
+
+static void release_readback(struct test_context *context, struct readback *rb)
+{
+    ID3D11DeviceContext_Unmap(context->immediate_context, rb->resource, 0);
+    ID3D11Resource_Release(rb->resource);
+}
+
+static const struct vec4 *get_readback_vec4(struct readback *rb, unsigned int x, unsigned int y)
+{
+    return (struct vec4 *)((BYTE *)rb->map_desc.pData + y * rb->map_desc.RowPitch) + x;
+}
+
+static struct vec4 get_color_vec4(struct test_context *context, unsigned int x, unsigned int y)
+{
+    struct readback rb;
+    struct vec4 ret;
+
+    init_readback(context, &rb);
+    ret = *get_readback_vec4(&rb, x, y);
+    release_readback(context, &rb);
+    return ret;
+}
+
+static void test_swizzle(void)
+{
+    static const struct vec4 uniform = {0.0303f, 0.0f, 0.0f, 0.0202f};
+    struct test_context test_context;
+    ID3D10Blob *ps_code = NULL;
+    ID3D11Buffer *cb;
+    struct vec4 v;
+
+    static const char ps_source[] =
+        "uniform float4 color;\n"
+        "float4 main() : SV_TARGET\n"
+        "{\n"
+        "    float4 ret = color;\n"
+        "    ret.gb = ret.ra;\n"
+        "    ret.ra = float2(0.0101, 0.0404);\n"
+        "    return ret;\n"
+        "}";
+
+    if (!init_test_context(&test_context))
+        return;
+
+    todo_wine ps_code = compile_shader(ps_source, "ps_4_0");
+    if (ps_code)
+    {
+        cb = create_buffer(test_context.device, D3D11_BIND_CONSTANT_BUFFER, sizeof(uniform), &uniform);
+        ID3D11DeviceContext_PSSetConstantBuffers(test_context.immediate_context, 0, 1, &cb);
+        draw_quad(&test_context, ps_code);
+
+        v = get_color_vec4(&test_context, 0, 0);
+        ok(compare_vec4(&v, 0.0101f, 0.0303f, 0.0202f, 0.0404f, 0),
+                "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v.x, v.y, v.z, v.w);
+
+        ID3D11Buffer_Release(cb);
+        ID3D10Blob_Release(ps_code);
+    }
+    release_test_context(&test_context);
+}
+
+static void test_math(void)
+{
+    static const float uniforms[8] = {2.5f, 0.3f, 0.2f, 0.7f, 0.1f, 1.5f};
+    struct test_context test_context;
+    ID3D10Blob *ps_code = NULL;
+    ID3D11Buffer *cb;
+    struct vec4 v;
+
+    static const char ps_source[] =
+        "float4 main(uniform float u, uniform float v, uniform float w, uniform float x,\n"
+        "            uniform float y, uniform float z) : SV_TARGET\n"
+        "{\n"
+        "    return float4(x * y - z / w + --u / -v,\n"
+        "            z * x / y + w / -v,\n"
+        "            u + v - w,\n"
+        "            x / y / w);\n"
+        "}";
+
+    if (!init_test_context(&test_context))
+        return;
+
+    todo_wine ps_code = compile_shader(ps_source, "ps_4_0");
+    if (ps_code)
+    {
+        cb = create_buffer(test_context.device, D3D11_BIND_CONSTANT_BUFFER, sizeof(uniforms), uniforms);
+        ID3D11DeviceContext_PSSetConstantBuffers(test_context.immediate_context, 0, 1, &cb);
+        draw_quad(&test_context, ps_code);
+
+        v = get_color_vec4(&test_context, 0, 0);
+        ok(compare_vec4(&v, -12.43f, 9.833333f, 1.6f, 35.0f, 1),
+                "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v.x, v.y, v.z, v.w);
+
+        ID3D11Buffer_Release(cb);
+        ID3D10Blob_Release(ps_code);
+    }
+    release_test_context(&test_context);
+}
+
+static void test_conditionals(void)
+{
+    struct test_context test_context;
+    ID3D10Blob *ps_code = NULL;
+    const struct vec4 *v;
+    struct readback rb;
+    unsigned int i;
+
+    static const char ps_source[] =
+        "float4 main(float4 pos : SV_POSITION) : SV_TARGET\n"
+        "{\n"
+        "    if(pos.x > 200.0)\n"
+        "        return float4(0.1, 0.2, 0.3, 0.4);\n"
+        "    else\n"
+        "        return float4(0.9, 0.8, 0.7, 0.6);\n"
+        "}";
+
+    if (!init_test_context(&test_context))
+        return;
+
+    todo_wine ps_code = compile_shader(ps_source, "ps_4_0");
+    if (ps_code)
+    {
+        draw_quad(&test_context, ps_code);
+        init_readback(&test_context, &rb);
+
+        for (i = 0; i < 200; i += 40)
+        {
+            v = get_readback_vec4(&rb, i, 0);
+            ok(compare_vec4(v, 0.9f, 0.8f, 0.7f, 0.6f, 0),
+                    "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v->x, v->y, v->z, v->w);
+        }
+
+        for (i = 240; i < 640; i += 40)
+        {
+            v = get_readback_vec4(&rb, i, 0);
+            ok(compare_vec4(v, 0.1f, 0.2f, 0.3f, 0.4f, 0),
+                    "Got unexpected value {%.8e, %.8e, %.8e, %.8e}.\n", v->x, v->y, v->z, v->w);
+        }
+
+        release_readback(&test_context, &rb);
+        ID3D10Blob_Release(ps_code);
+    }
+    release_test_context(&test_context);
+}
+
+static void test_trig(void)
+{
+    struct test_context test_context;
+    ID3D10Blob *ps_code = NULL;
+    const struct vec4 *v;
+    struct readback rb;
+    unsigned int i;
+
+    static const char ps_source[] =
+        "float4 main(float4 pos : SV_POSITION) : SV_TARGET\n"
+        "{\n"
+        "    return float4(sin(pos.x - 0.5), cos(pos.x - 0.5), 0, 0);\n"
+        "}";
+
+    if (!init_test_context(&test_context))
+        return;
+
+    todo_wine ps_code = compile_shader(ps_source, "ps_4_0");
+    if (ps_code)
+    {
+        draw_quad(&test_context, ps_code);
+        init_readback(&test_context, &rb);
+
+        for (i = 0; i < 640; i += 20)
+        {
+            v = get_readback_vec4(&rb, i, 0);
+            ok(compare_vec4(v, sinf(i), cosf(i), 0.0f, 0.0f, 8192),
+                    "Test %u: Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
+                    i, v->x, v->y, v->z, v->w, sinf(i), cos(i), 0.0f, 0.0f);
+        }
+
+        release_readback(&test_context, &rb);
+        ID3D10Blob_Release(ps_code);
+    }
+    release_test_context(&test_context);
+}
+
+static BOOL load_d3dcompiler(void)
+{
+    HMODULE module;
+
+#if D3D_COMPILER_VERSION == 47
+    if (!(module = LoadLibraryA("d3dcompiler_47.dll"))) return FALSE;
+#else
+    if (!(module = LoadLibraryA("d3dcompiler_43.dll"))) return FALSE;
+#endif
+
+    ppD3DCompile = (void *)GetProcAddress(module, "D3DCompile");
+    pD3DReflect = (void *)GetProcAddress(module, "D3DReflect");
+    return TRUE;
+}
+
+START_TEST(hlsl_d3d11)
+{
+    HMODULE mod;
+
+    if (!load_d3dcompiler())
+    {
+        win_skip("Could not load DLL.\n");
+        return;
+    }
+
+    if (!(mod = LoadLibraryA("d3d11.dll")))
+    {
+        skip("Direct3D 11 is not available.\n");
+        return;
+    }
+    pD3D11CreateDevice = (void *)GetProcAddress(mod, "D3D11CreateDevice");
+
+    test_swizzle();
+    test_math();
+    test_conditionals();
+    test_trig();
+}
diff --git a/dlls/d3dcompiler_43/tests/hlsl_d3d9.c b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c
index 79f54d200e2..36ea9c37650 100644
--- a/dlls/d3dcompiler_43/tests/hlsl_d3d9.c
+++ b/dlls/d3dcompiler_43/tests/hlsl_d3d9.c
@@ -578,63 +578,68 @@ static void test_fail(void)
 {
     static const char *tests[] =
     {
-        "float4 test(float2 pos: TEXCOORD0) : COLOR\n"
+        "float4 test() : SV_TARGET\n"
         "{\n"
         "   return y;\n"
         "}",
 
-        "float4 test(float2 pos: TEXCOORD0) : COLOR\n"
+        "float4 test() : SV_TARGET\n"
         "{\n"
         "  float4 x = float4(0, 0, 0, 0);\n"
         "  x.xzzx = float4(1, 2, 3, 4);\n"
         "  return x;\n"
         "}",
 
-        "float4 test(float2 pos: TEXCOORD0) : COLOR\n"
+        "float4 test(float2 pos: TEXCOORD0) : SV_TARGET\n"
         "{\n"
         "  float4 x = pos;\n"
         "  return x;\n"
         "}",
 
-        "float4 test(float2 pos, TEXCOORD0) ; COLOR\n"
+        "float4 test(float2 pos, TEXCOORD0) ; SV_TARGET\n"
         "{\n"
         "  pos = float4 x;\n"
         "  mul(float4(5, 4, 3, 2), mvp) = x;\n"
         "  return float4;\n"
         "}",
 
-        "float4 563r(float2 45s: TEXCOORD0) : COLOR\n"
+        "float4 563r(float2 45s: TEXCOORD0) : SV_TARGET\n"
         "{\n"
         "  float2 x = 45s;\n"
         "  return float4(x.x, x.y, 0, 0);\n"
         "}",
 
-        "float4 test(float2 pos: TEXCOORD0) : COLOR\n"
+        "float4 test() : SV_TARGET\n"
         "{\n"
         "   struct { int b,c; } x = {0};\n"
         "   return y;\n"
         "}",
 
-        "float4 test(float2 pos: TEXCOORD0) : COLOR\n"
+        "float4 test() : SV_TARGET\n"
         "{\n"
         "   struct {} x = {};\n"
         "   return y;\n"
         "}",
     };
 
+    static const char *targets[] = {"ps_2_0", "ps_3_0", "ps_4_0"};
+
     ID3D10Blob *compiled, *errors;
-    unsigned int i;
+    unsigned int i, j;
     HRESULT hr;
 
-    for (i = 0; i < ARRAY_SIZE(tests); ++i)
+    for (j = 0; j < ARRAY_SIZE(targets); ++j)
     {
-        compiled = errors = NULL;
-        hr = ppD3DCompile(tests[i], strlen(tests[i]), NULL, NULL, NULL, "test", "ps_2_0", 0, 0, &compiled, &errors);
-        todo_wine ok(hr == E_FAIL, "Test %u, got unexpected hr %#x.\n", i, hr);
-        todo_wine_if (i == 1) ok(!!errors, "Test %u, expected non-NULL error blob.\n", i);
-        ok(!compiled, "Test %u, expected no compiled shader blob.\n", i);
-        if (errors)
-            ID3D10Blob_Release(errors);
+        for (i = 0; i < ARRAY_SIZE(tests); ++i)
+        {
+            compiled = errors = NULL;
+            hr = ppD3DCompile(tests[i], strlen(tests[i]), NULL, NULL, NULL, "test", targets[j], 0, 0, &compiled, &errors);
+            todo_wine ok(hr == E_FAIL, "Test %u, target %s, got unexpected hr %#x.\n", i, targets[j], hr);
+            todo_wine_if (i == 1) ok(!!errors, "Test %u, target %s, expected non-NULL error blob.\n", i, targets[j]);
+            ok(!compiled, "Test %u, target %s, expected no compiled shader blob.\n", i, targets[j]);
+            if (errors)
+                ID3D10Blob_Release(errors);
+        }
     }
 }
 
diff --git a/dlls/d3dcompiler_47/tests/Makefile.in b/dlls/d3dcompiler_47/tests/Makefile.in
index 032e16fdb8f..80e0144bc40 100644
--- a/dlls/d3dcompiler_47/tests/Makefile.in
+++ b/dlls/d3dcompiler_47/tests/Makefile.in
@@ -6,5 +6,6 @@ PARENTSRC = ../../d3dcompiler_43/tests
 C_SRCS = \
 	asm.c \
 	blob.c \
+	hlsl_d3d11.c \
 	hlsl_d3d9.c \
 	reflection.c
-- 
2.24.1




More information about the wine-devel mailing list