[PATCH v3 6/6] d3d9/tests: Add Fetch4 tests

Daniel Ansorregui mailszeros at gmail.com
Sat Nov 24 14:13:37 CST 2018


- Implemented for texld/texldp/texldd/texldb/texldl
- In all cases tested on Windows10 + Intel
  Fetch4 enabled always produced same result (like texld)

Signed-off-by: Daniel Ansorregui <mailszeros at gmail.com>
---
 dlls/d3d9/tests/visual.c | 313 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 313 insertions(+)

diff --git a/dlls/d3d9/tests/visual.c b/dlls/d3d9/tests/visual.c
index 4f26b0d23f..a2c5f6285c 100644
--- a/dlls/d3d9/tests/visual.c
+++ b/dlls/d3d9/tests/visual.c
@@ -15104,6 +15104,318 @@ done:
     DestroyWindow(window);
 }
 
+static void fetch4_test(void)
+{
+    static const DWORD vs_code[] =
+    {
+        0xfffe0300,                                                 /* vs_3_0                 */
+        0x0200001f, 0x80000000, 0x900f0000,                         /* dcl_position v0        */
+        0x0200001f, 0x80000005, 0x900f0001,                         /* dcl_texcoord v1        */
+        0x0200001f, 0x80000000, 0xe00f0000,                         /* dcl_position o0        */
+        0x0200001f, 0x80000005, 0xe00f0001,                         /* dcl_texcoord o1        */
+        0x02000001, 0xe00f0000, 0x90e40000,                         /* mov o0, v0             */
+        0x02000001, 0xe00f0001, 0x90e40001,                         /* mov o1, v1             */
+        0x0000ffff
+    };
+    static const DWORD ps_code_texld[] =
+    {
+        0xffff0300,                                                             /* ps_3_0                       */
+        0x0200001f, 0x80000005, 0x900f0000,                                     /* dcl_texcoord v0              */
+        0x0200001f, 0x90000000, 0xa00f0800,                                     /* dcl_2d s0                    */
+        0x03000042, 0x800f0000, 0x90e40000, 0xa0e40800,                         /* texld r0, v0, s0             */
+        0x02000001, 0x800f0800, 0x80e40000,                                     /* mov oC0, r0                  */
+        0x0000ffff                                                              /* end                          */
+    };
+    static const DWORD ps_code_texldp[] =
+    {
+        0xffff0300,                                                             /* ps_3_0                       */
+        0x0200001f, 0x80000005, 0x900f0000,                                     /* dcl_texcoord v0              */
+        0x0200001f, 0x90000000, 0xa00f0800,                                     /* dcl_2d s0                    */
+        0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x3f000000, 0x3f000000, /* def c0, 0.0, 0.0, 0.5, 0.5   */
+        0x03000002, 0x800f0000, 0x90e40000, 0xa0e40000,                         /* add r0, v0, c0               */
+        0x03010042, 0x800f0000, 0x80e40000, 0xa0e40800,                         /* texldp r0, r0, s0            */
+        0x02000001, 0x800f0800, 0x80e40000,                                     /* mov oC0, r0                  */
+        0x0000ffff,                                                             /* end                          */
+    };
+    static const DWORD ps_code_texldd[] =
+    {
+        0xffff0300,                                                             /* ps_3_0                       */
+        0x0200001f, 0x80000005, 0x900f0000,                                     /* dcl_texcoord v0              */
+        0x0200001f, 0x90000000, 0xa00f0800,                                     /* dcl_2d s0                    */
+        0x05000051, 0xa00f0000, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, /* def c0, 0.5, 0.5, 0.5, 0.5   */
+        0x05000051, 0xa00f0001, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, /* def c0, 1.0, 1.0, 1.0, 1.0   */
+        0x02000001, 0x800f0002, 0xa0e40000,                                     /* mov r2, c0                   */
+        0x0500005d, 0x800f0000, 0x90e40000, 0xa0e40800, 0xa0e40000, 0x80e40002, /* texldd r0, v0, s0, c0, r2    */
+        0x02000001, 0x800f0800, 0x80e40000,                                     /* mov oC0, r0                  */
+        0x0000ffff,                                                             /* end                          */
+    };
+    static const DWORD ps_code_texldb[] =
+    {
+        0xffff0300,                                                             /* ps_3_0                       */
+        0x0200001f, 0x80000005, 0x900f0000,                                     /* dcl_texcoord v0              */
+        0x0200001f, 0x90000000, 0xa00f0800,                                     /* dcl_2d s0                    */
+        0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x40a00000, 0x40a00000, /* def c0, 0.0, 0.0, 5.0, 5.0   */
+        0x03000002, 0x800f0000, 0x90e40000, 0xa0e40000,                         /* add r0, v0, c0               */
+        0x03020042, 0x800f0000, 0x80e40000, 0xa0e40800,                         /* texldb r0, r0, s0            */
+        0x02000001, 0x800f0800, 0x80e40000,                                     /* mov oC0, r0                  */
+        0x0000ffff,                                                             /* end                          */
+    };
+    static const DWORD ps_code_texldl[] =
+    {
+        0xffff0300,                                                             /* ps_3_0                       */
+        0x0200001f, 0x80000005, 0x900f0000,                                     /* dcl_texcoord v0              */
+        0x0200001f, 0x90000000, 0xa00f0800,                                     /* dcl_2d s0                    */
+        0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x3f000000, 0x3f000000, /* def c0, 0.0, 0.0, 0.5, 0.5   */
+        0x03000002, 0x800f0000, 0x90e40000, 0xa0e40000,                         /* add r0, v0, c0               */
+        0x0300005f, 0x800f0000, 0x80e40000, 0xa0e40800,                         /* texldl r0, r0, s0            */
+        0x02000001, 0x800f0800, 0x80e40000,                                     /* mov oC0, r0                  */
+        0x0000ffff,                                                             /* end                          */
+    };
+
+    struct
+    {
+        float x, y, z;
+        float tu, tv;
+    }
+    quad[] =
+    {
+        {-1.0f, 1.0f, 0.0f,  0.0f,0.0f },
+        { 1.0f, 1.0f, 0.0f,  1.0f,0.0f },
+        {-1.0f,-1.0f, 0.0f,  0.0f,1.0f },
+        { 1.0f,-1.0f, 0.0f,  1.0f,1.0f }
+    };
+
+    struct struct_expected_color
+    {
+        UINT x, y;
+        D3DCOLOR color;
+    };
+    struct struct_expected_color expected_colors[] =
+    {
+        { 40, 30, 0x23102013},{160, 30, 0x22132312},{320, 30, 0x21122211},
+        {480, 30, 0x20112110},{600, 30, 0x23102013},
+        { 40,120, 0x13011002},{160,120, 0x120213f2},{320,120, 0x11f212f1},
+        {480,120, 0x10f11101},{600,120, 0x13011002},
+        { 40,240, 0x02030104},{160,240, 0xf20402f4},{320,240, 0xf1f4f2f3},
+        {480,240, 0x01f3f103},{600,240, 0x02030104},
+        { 40,360, 0x04200323},{160,360, 0xf4230422},{320,360, 0xf322f421},
+        {480,360, 0x0321f320},{600,360, 0x04200323},
+        { 40,450, 0x23102013},{160,450, 0x22132312},{320,450, 0x21122211},
+        {480,450, 0x20112110},{600,450, 0x23102013},
+    };
+    struct struct_expected_color expected_color = {40, 30, 0x0};
+
+    static const DWORD texture_data[4] = {0x10111213,
+                                          0x01f1f202,
+                                          0x03f3f404,
+                                          0x20212223};
+    static const DWORD texture_data2 = 0xff804000;
+
+    IDirect3DPixelShader9 *ps_texld, *ps_texldp, *ps_texldd, *ps_texldb, *ps_texldl;
+    IDirect3DTexture9 *texture_L8, *texture_A8, *texture_A8R8G8B8;
+    IDirect3DSurface9 *original_rt;
+    struct surface_readback rb;
+    IDirect3DVertexShader9 *vs;
+    IDirect3DDevice9 *device;
+    D3DLOCKED_RECT lr;
+    IDirect3D9 *d3d;
+    ULONG refcount;
+    D3DCAPS9 caps;
+    HWND window;
+    HRESULT hr;
+    UINT i, j;
+
+
+    window = create_window();
+    d3d = Direct3DCreate9(D3D_SDK_VERSION);
+    ok(!!d3d, "Failed to create a D3D object.\n");
+    if (FAILED(IDirect3D9_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
+            D3DFMT_X8R8G8B8, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, MAKEFOURCC('D','F','2','4'))))
+    {
+        skip("No DF24 support, skipping FETCH4 test.\n");
+        goto done;
+    }
+    if (!(device = create_device(d3d, window, window, TRUE)))
+    {
+        skip("Failed to create a D3D device, skipping tests.\n");
+        goto done;
+    }
+
+    hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
+    ok(SUCCEEDED(hr), "GetDeviceCaps failed, hr %#x.\n", hr);
+    if (caps.PixelShaderVersion < D3DPS_VERSION(3, 0))
+    {
+        skip("No pixel shader 3.0 support, skipping FETCH4 test.\n");
+        IDirect3DDevice9_Release(device);
+        goto done;
+    }
+    hr = IDirect3DDevice9_GetRenderTarget(device, 0, &original_rt);
+    ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
+
+    /* Create our texture for FETCH4 */
+    hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_L8, D3DPOOL_MANAGED, &texture_L8, NULL);
+    ok(hr == D3D_OK, "Failed to create texture, hr %#x.\n", hr);
+    memset(&lr, 0, sizeof(lr));
+    hr = IDirect3DTexture9_LockRect(texture_L8, 0, &lr, NULL, 0);
+    ok(hr == D3D_OK, "Failed to lock texture, hr %#x.\n", hr);
+    memcpy(lr.pBits, texture_data, sizeof(texture_data));
+    hr = IDirect3DTexture9_UnlockRect(texture_L8, 0);
+    ok(hr == D3D_OK, "Failed to unlock texture, hr %#x.\n", hr);
+    hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)texture_L8);
+    ok(hr == D3D_OK, "Failed to set texture, hr %#x.\n", hr);
+
+    /* Create Other textures to test FETCH4 does not work there */
+    hr = IDirect3DDevice9_CreateTexture(device, 2, 2, 1, 0, D3DFMT_A8, D3DPOOL_MANAGED, &texture_A8, NULL);
+    ok(hr == D3D_OK, "Failed to create texture, hr %#x.\n", hr);
+    memset(&lr, 0, sizeof(lr));
+    hr = IDirect3DTexture9_LockRect(texture_A8, 0, &lr, NULL, 0);
+    ok(hr == D3D_OK, "Failed to lock texture, hr %#x.\n", hr);
+    memcpy(lr.pBits, &texture_data2, 4);
+    hr = IDirect3DTexture9_UnlockRect(texture_A8, 0);
+    ok(hr == D3D_OK, "Failed to unlock texture, hr %#x.\n", hr);
+
+    hr = IDirect3DDevice9_CreateTexture(device, 2, 2, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture_A8R8G8B8, NULL);
+    ok(hr == D3D_OK, "Failed to create texture, hr %#x.\n", hr);
+    memset(&lr, 0, sizeof(lr));
+    hr = IDirect3DTexture9_LockRect(texture_A8R8G8B8, 0, &lr, NULL, 0);
+    ok(hr == D3D_OK, "Failed to lock texture, hr %#x.\n", hr);
+    memcpy(lr.pBits, &texture_data2, 4);
+    hr = IDirect3DTexture9_UnlockRect(texture_A8R8G8B8, 0);
+    ok(hr == D3D_OK, "Failed to unlock texture, hr %#x.\n", hr);
+
+    /* Create vertex shader */
+    hr = IDirect3DDevice9_CreateVertexShader(device, vs_code, &vs);
+    ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr);
+    hr = IDirect3DDevice9_SetVertexShader(device, vs);
+    ok(SUCCEEDED(hr), "Failed to set vertex shader, hr %#x.\n", hr);
+
+    /* Prepare the pixel shaders */
+    hr = IDirect3DDevice9_CreatePixelShader(device, ps_code_texld, &ps_texld);
+    ok(SUCCEEDED(hr), "CreatePixelShader failed, hr %#x.\n", hr);
+    hr = IDirect3DDevice9_CreatePixelShader(device, ps_code_texldp, &ps_texldp);
+    ok(SUCCEEDED(hr), "CreatePixelShader failed, hr %#x.\n", hr);
+    hr = IDirect3DDevice9_CreatePixelShader(device, ps_code_texldd, &ps_texldd);
+    ok(SUCCEEDED(hr), "CreatePixelShader failed, hr %#x.\n", hr);
+    hr = IDirect3DDevice9_CreatePixelShader(device, ps_code_texldb, &ps_texldb);
+    ok(SUCCEEDED(hr), "CreatePixelShader failed, hr %#x.\n", hr);
+    hr = IDirect3DDevice9_CreatePixelShader(device, ps_code_texldl, &ps_texldl);
+    ok(SUCCEEDED(hr), "CreatePixelShader failed, hr %#x.\n", hr);
+
+    hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
+    ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
+
+    /* According to the spec, FETCH4 is enabled when D3DSAMP_MIPMAPLODBIAS = GET4
+       and also D3DSAMP_MAGFILTER = D3DTEXF_POINT. But apparently only GET4 is needed
+       So the tests exercices that only GET4 is required, and any other parameter will work */
+    hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MIPMAPLODBIAS, MAKEFOURCC('G','E','T','4'));
+    ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
+    hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
+    ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
+    hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
+    ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
+    hr = IDirect3DDevice9_SetSamplerState(device, 0, D3DSAMP_MIPFILTER, D3DTEXF_NONE);
+    ok(SUCCEEDED(hr), "SetSamplerState failed, hr %#x.\n", hr);
+
+    /* Render with fetch4 and test if we obtain proper results */
+    for (i=0; i<5; i++)
+    {
+        if (i==0)
+            hr = IDirect3DDevice9_SetPixelShader(device, ps_texld);
+        else if(i==1)
+            hr = IDirect3DDevice9_SetPixelShader(device, ps_texldp);
+        else if(i==2)
+            hr = IDirect3DDevice9_SetPixelShader(device, ps_texldd);
+        else if(i==3)
+            hr = IDirect3DDevice9_SetPixelShader(device, ps_texldb);
+        else
+            hr = IDirect3DDevice9_SetPixelShader(device, ps_texldl);
+        ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
+
+        hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0, 0.0f, 0);
+        ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
+
+        hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
+        ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
+
+        hr = IDirect3DDevice9_BeginScene(device);
+        ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
+        hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
+        ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
+        hr = IDirect3DDevice9_EndScene(device);
+        ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
+
+        get_rt_readback(original_rt, &rb);
+        for (j = 0; j < ARRAY_SIZE(expected_colors); ++j)
+        {
+            D3DCOLOR color = get_readback_color(&rb, expected_colors[j].x, expected_colors[j].y);
+            ok(color_match(color, expected_colors[j].color, 1),
+                    "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
+                    expected_colors[j].color, expected_colors[j].x, expected_colors[j].y, color);
+        }
+        release_surface_readback(&rb);
+
+        hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
+        ok(SUCCEEDED(hr), "Present failed, hr %#x.\n", hr);
+    }
+
+    /* Test if FETCH4 is disabled when incompatible textures are used */
+    hr = IDirect3DDevice9_SetPixelShader(device, ps_texld);
+    ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
+    for (i=0; i<2; i++)
+    {
+        if (i==0)
+        {
+            hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)texture_A8);
+            expected_color.color = 0x0f000000;
+        }
+        else if(i==1)
+        {
+            hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)texture_A8R8G8B8);
+            expected_color.color = 0x64321900;
+        }
+        ok(hr == D3D_OK, "Failed to set texture, hr %#x.\n", hr);
+
+        hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0, 0.0f, 0);
+        ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
+
+        hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_TEX1);
+        ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr);
+
+        hr = IDirect3DDevice9_BeginScene(device);
+        ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
+        hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
+        ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
+        hr = IDirect3DDevice9_EndScene(device);
+        ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
+
+        get_rt_readback(original_rt, &rb);
+        D3DCOLOR color = get_readback_color(&rb, expected_color.x, expected_color.y);
+        ok(color_match(color, expected_color.color, 1),
+                "Expected color 0x%08x at (%u, %u), got 0x%08x.\n",
+                expected_color.color, expected_color.x, expected_color.y, color);
+        release_surface_readback(&rb);
+
+        hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
+        ok(SUCCEEDED(hr), "Present failed, hr %#x.\n", hr);
+    }
+
+    IDirect3DTexture9_Release(texture_L8);
+    IDirect3DTexture9_Release(texture_A8);
+    IDirect3DTexture9_Release(texture_A8R8G8B8);
+    IDirect3DPixelShader9_Release(ps_texld);
+    IDirect3DPixelShader9_Release(ps_texldp);
+    IDirect3DPixelShader9_Release(ps_texldb);
+    IDirect3DPixelShader9_Release(ps_texldd);
+    IDirect3DPixelShader9_Release(ps_texldl);
+    IDirect3DVertexShader9_Release(vs);
+    IDirect3DSurface9_Release(original_rt);
+    refcount = IDirect3DDevice9_Release(device);
+    ok(!refcount, "Device has %u references left.\n", refcount);
+done:
+    IDirect3D9_Release(d3d);
+    DestroyWindow(window);
+}
+
 static void shadow_test(void)
 {
     static const DWORD ps_code[] =
@@ -24291,6 +24603,7 @@ START_TEST(visual)
     depth_buffer2_test();
     depth_blit_test();
     intz_test();
+    fetch4_test();
     shadow_test();
     fp_special_test();
     depth_bounds_test();
-- 
2.17.1




More information about the wine-devel mailing list