[PATCH 5/6] d3d8/tests: Add a shadow sampler test.

Henri Verbeet hverbeet at codeweavers.com
Mon May 17 04:14:49 CDT 2010


---
 dlls/d3d8/tests/visual.c |  214 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 214 insertions(+), 0 deletions(-)

diff --git a/dlls/d3d8/tests/visual.c b/dlls/d3d8/tests/visual.c
index 42f5f21..69e9faf 100644
--- a/dlls/d3d8/tests/visual.c
+++ b/dlls/d3d8/tests/visual.c
@@ -1556,6 +1556,219 @@ static void depth_buffer_test(IDirect3DDevice8 *device)
     ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
 }
 
+static void shadow_test(IDirect3DDevice8 *device)
+{
+    static const DWORD ps_code[] =
+    {
+        0xffff0101,                                                             /* ps_1_1                       */
+        0x00000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x00000000, /* def c0, 1.0, 0.0, 0.0, 0.0   */
+        0x00000051, 0xa00f0001, 0x00000000, 0x3f800000, 0x00000000, 0x00000000, /* def c1, 0.0, 1.0, 0.0, 0.0   */
+        0x00000051, 0xa00f0002, 0x00000000, 0x00000000, 0x3f800000, 0x00000000, /* def c2, 0.0, 0.0, 1.0, 0.0   */
+        0x00000042, 0xb00f0000,                                                 /* tex t0                       */
+        0x00000042, 0xb00f0001,                                                 /* tex t1                       */
+        0x00000008, 0xb0070001, 0xa0e40000, 0xb0e40001,                         /* dp3 t1.xyz, c0, t1           */
+        0x00000005, 0x80070000, 0xa0e40001, 0xb0e40001,                         /* mul r0.xyz, c1, t1           */
+        0x00000004, 0x80070000, 0xa0e40000, 0xb0e40000, 0x80e40000,             /* mad r0.xyz, c0, t0, r0       */
+        0x40000001, 0x80080000, 0xa0aa0002,                                     /* +mov r0.w, c2.z              */
+        0x0000ffff,                                                             /* end                          */
+    };
+    struct
+    {
+        D3DFORMAT format;
+        const char *name;
+    }
+    formats[] =
+    {
+        {D3DFMT_D16_LOCKABLE,   "D3DFMT_D16_LOCKABLE"},
+        {D3DFMT_D32,            "D3DFMT_D32"},
+        {D3DFMT_D15S1,          "D3DFMT_D15S1"},
+        {D3DFMT_D24S8,          "D3DFMT_D24S8"},
+        {D3DFMT_D24X8,          "D3DFMT_D24X8"},
+        {D3DFMT_D24X4S4,        "D3DFMT_D24X4S4"},
+        {D3DFMT_D16,            "D3DFMT_D16"},
+    };
+    struct
+    {
+        float x, y, z;
+        float s0, t0, p0;
+        float s1, t1, p1, q1;
+    }
+    quad[] =
+    {
+        { -1.0f,  1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f},
+        {  1.0f,  1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f},
+        { -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
+        {  1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f},
+    };
+    struct
+    {
+        UINT x, y;
+        D3DCOLOR color;
+    }
+    expected_colors[] =
+    {
+        {400,  60, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0x00)},
+        {560, 180, D3DCOLOR_ARGB(0x00, 0xff, 0x00, 0x00)},
+        {560, 300, D3DCOLOR_ARGB(0x00, 0xff, 0x00, 0x00)},
+        {400, 420, D3DCOLOR_ARGB(0x00, 0xff, 0xff, 0x00)},
+        {240, 420, D3DCOLOR_ARGB(0x00, 0xff, 0xff, 0x00)},
+        { 80, 300, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0x00)},
+        { 80, 180, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0x00)},
+        {240,  60, D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0x00)},
+    };
+
+    IDirect3DSurface8 *original_ds, *original_rt, *rt;
+    IDirect3D8 *d3d8;
+    D3DCAPS8 caps;
+    HRESULT hr;
+    DWORD ps;
+    UINT i;
+
+    hr = IDirect3DDevice8_GetDeviceCaps(device, &caps);
+    ok(SUCCEEDED(hr), "GetDeviceCaps failed, hr %#x.\n", hr);
+    if (caps.PixelShaderVersion < D3DPS_VERSION(1, 1))
+    {
+        skip("No pixel shader 1.1 support, skipping shadow test.\n");
+        return;
+    }
+
+    hr = IDirect3DDevice8_GetDirect3D(device, &d3d8);
+    ok(SUCCEEDED(hr), "GetDirect3D failed, hr %#x.\n", hr);
+    hr = IDirect3DDevice8_GetRenderTarget(device, &original_rt);
+    ok(SUCCEEDED(hr), "GetRenderTarget failed, hr %#x.\n", hr);
+    hr = IDirect3DDevice8_GetDepthStencilSurface(device, &original_ds);
+    ok(SUCCEEDED(hr), "GetDepthStencilSurface failed, hr %#x.\n", hr);
+
+    hr = IDirect3DDevice8_CreateRenderTarget(device, 1024, 1024, D3DFMT_A8R8G8B8,
+            D3DMULTISAMPLE_NONE, FALSE, &rt);
+    ok(SUCCEEDED(hr), "CreateRenderTarget failed, hr %#x.\n", hr);
+    hr = IDirect3DDevice8_CreatePixelShader(device, ps_code, &ps);
+    ok(SUCCEEDED(hr), "CreatePixelShader failed, hr %#x.\n", hr);
+
+    hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ | D3DFVF_TEX2
+            | D3DFVF_TEXCOORDSIZE3(0) | D3DFVF_TEXCOORDSIZE4(1));
+    ok(SUCCEEDED(hr), "SetVertexShader failed, hr %#x.\n", hr);
+    hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZENABLE, D3DZB_TRUE);
+    ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
+    hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZFUNC, D3DCMP_ALWAYS);
+    ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
+    hr = IDirect3DDevice8_SetRenderState(device, D3DRS_ZWRITEENABLE, TRUE);
+    ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
+    hr = IDirect3DDevice8_SetRenderState(device, D3DRS_LIGHTING, FALSE);
+    ok(SUCCEEDED(hr), "SetRenderState failed, hr %#x.\n", hr);
+
+    hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_MINFILTER, D3DTEXF_POINT);
+    ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
+    hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_MIPFILTER, D3DTEXF_POINT);
+    ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
+    hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_MAGFILTER, D3DTEXF_POINT);
+    ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
+    hr = IDirect3DDevice8_SetTextureStageState(device, 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT3);
+    ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
+
+    hr = IDirect3DDevice8_SetTextureStageState(device, 1, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);
+    ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
+    hr = IDirect3DDevice8_SetTextureStageState(device, 1, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);
+    ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
+    hr = IDirect3DDevice8_SetTextureStageState(device, 1, D3DTSS_MAGFILTER, D3DTEXF_POINT);
+    ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
+    hr = IDirect3DDevice8_SetTextureStageState(device, 1, D3DTSS_MINFILTER, D3DTEXF_POINT);
+    ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
+    hr = IDirect3DDevice8_SetTextureStageState(device, 1, D3DTSS_MIPFILTER, D3DTEXF_POINT);
+    ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
+    hr = IDirect3DDevice8_SetTextureStageState(device, 1, D3DTSS_TEXTURETRANSFORMFLAGS,
+            D3DTTFF_COUNT4 | D3DTTFF_PROJECTED);
+    ok(SUCCEEDED(hr), "SetTextureStageState failed, hr %#x.\n", hr);
+
+    for (i = 0; i < sizeof(formats) / sizeof(*formats); ++i)
+    {
+        D3DFORMAT format = formats[i].format;
+        IDirect3DTexture8 *texture;
+        IDirect3DSurface8 *ds;
+        unsigned int j;
+
+        hr = IDirect3D8_CheckDeviceFormat(d3d8, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,
+                D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE, format);
+        if (FAILED(hr)) continue;
+
+        hr = IDirect3DDevice8_CreateTexture(device, 1024, 1024, 1,
+                D3DUSAGE_DEPTHSTENCIL, format, D3DPOOL_DEFAULT, &texture);
+        ok(SUCCEEDED(hr), "CreateTexture failed, hr %#x.\n", hr);
+
+        hr = IDirect3DTexture8_GetSurfaceLevel(texture, 0, &ds);
+        ok(SUCCEEDED(hr), "GetSurfaceLevel failed, hr %#x.\n", hr);
+
+        hr = IDirect3DDevice8_SetRenderTarget(device, rt, ds);
+        ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
+
+        IDirect3DDevice8_SetPixelShader(device, 0);
+        ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
+
+        /* Setup the depth/stencil surface. */
+        hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0, 0.0f, 0);
+        ok(SUCCEEDED(hr), "Clear failed, hr %#x.\n", hr);
+
+        hr = IDirect3DDevice8_BeginScene(device);
+        ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
+        hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
+        ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
+        hr = IDirect3DDevice8_EndScene(device);
+        ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
+
+        hr = IDirect3DDevice8_SetRenderTarget(device, original_rt, NULL);
+        ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
+        IDirect3DSurface8_Release(ds);
+
+        hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *)texture);
+        ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
+        hr = IDirect3DDevice8_SetTexture(device, 1, (IDirect3DBaseTexture8 *)texture);
+        ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
+
+        hr = IDirect3DDevice8_SetPixelShader(device, ps);
+        ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
+
+        /* Do the actual shadow mapping. */
+        hr = IDirect3DDevice8_BeginScene(device);
+        ok(SUCCEEDED(hr), "BeginScene failed, hr %#x.\n", hr);
+        hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
+        ok(SUCCEEDED(hr), "DrawPrimitiveUP failed, hr %#x.\n", hr);
+        hr = IDirect3DDevice8_EndScene(device);
+        ok(SUCCEEDED(hr), "EndScene failed, hr %#x.\n", hr);
+
+        hr = IDirect3DDevice8_SetTexture(device, 0, NULL);
+        ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
+        hr = IDirect3DDevice8_SetTexture(device, 1, NULL);
+        ok(SUCCEEDED(hr), "SetTexture failed, hr %#x.\n", hr);
+        IDirect3DTexture8_Release(texture);
+
+        for (j = 0; j < sizeof(expected_colors) / sizeof(*expected_colors); ++j)
+        {
+            D3DCOLOR color = getPixelColor(device, expected_colors[j].x, expected_colors[j].y);
+            ok(color_match(color, expected_colors[j].color, 0),
+                    "Expected color 0x%08x at (%u, %u) for format %s, got 0x%08x.\n",
+                    expected_colors[j].color, expected_colors[j].x, expected_colors[j].y,
+                    formats[i].name, color);
+        }
+
+        hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
+        ok(SUCCEEDED(hr), "Present failed, hr %#x.\n", hr);
+    }
+
+    hr = IDirect3DDevice8_SetPixelShader(device, 0);
+    ok(SUCCEEDED(hr), "SetPixelShader failed, hr %#x.\n", hr);
+    hr = IDirect3DDevice8_DeletePixelShader(device, ps);
+    ok(SUCCEEDED(hr), "DeletePixelShader failed, hr %#x.\n", hr);
+
+    hr = IDirect3DDevice8_SetRenderTarget(device, original_rt, original_ds);
+    ok(SUCCEEDED(hr), "SetRenderTarget failed, hr %#x.\n", hr);
+    IDirect3DSurface8_Release(original_ds);
+
+    IDirect3DSurface8_Release(original_rt);
+    IDirect3DSurface8_Release(rt);
+
+    IDirect3D8_Release(d3d8);
+}
+
 START_TEST(visual)
 {
     IDirect3DDevice8 *device_ptr;
@@ -1631,6 +1844,7 @@ START_TEST(visual)
     p8_texture_test(device_ptr);
     texop_test(device_ptr);
     depth_buffer_test(device_ptr);
+    shadow_test(device_ptr);
 
 cleanup:
     if(device_ptr) {
-- 
1.6.4.4




More information about the wine-patches mailing list