[PATCH 7/8] d3d11/tests: Add test for ClearDepthStencilView().

Józef Kucia jkucia at codeweavers.com
Sun Mar 13 18:03:08 CDT 2016


Signed-off-by: Józef Kucia <jkucia at codeweavers.com>
---
 dlls/d3d11/tests/d3d11.c | 132 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 132 insertions(+)

diff --git a/dlls/d3d11/tests/d3d11.c b/dlls/d3d11/tests/d3d11.c
index 2238380..76252ab 100644
--- a/dlls/d3d11/tests/d3d11.c
+++ b/dlls/d3d11/tests/d3d11.c
@@ -21,6 +21,14 @@
 #include "initguid.h"
 #include "d3d11.h"
 #include "wine/test.h"
+#include <limits.h>
+
+static inline float __port_nan(void)
+{
+    static const unsigned __nan_bytes = 0x7fc00000;
+    return *(const float *)&__nan_bytes;
+}
+#define NAN __port_nan()
 
 static const D3D_FEATURE_LEVEL d3d11_feature_levels[] =
 {
@@ -64,6 +72,22 @@ static ULONG get_refcount(IUnknown *iface)
     return IUnknown_Release(iface);
 }
 
+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_color(DWORD c1, DWORD c2, BYTE max_diff)
 {
     if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff)
@@ -134,6 +158,12 @@ static DWORD get_readback_color(struct texture_readback *rb, unsigned int x, uns
             ? ((DWORD *)rb->map_desc.pData)[rb->map_desc.RowPitch * y / sizeof(DWORD) + x] : 0xdeadbeef;
 }
 
+static float get_readback_float(struct texture_readback *rb, unsigned int x, unsigned int y)
+{
+    return rb->texture
+            ? ((float *)rb->map_desc.pData)[rb->map_desc.RowPitch * y / sizeof(float) + x] : NAN;
+}
+
 static void release_texture_readback(struct texture_readback *rb)
 {
     if (!rb->texture)
@@ -185,6 +215,35 @@ static void check_texture_color_(unsigned int line, ID3D11Texture2D *texture,
             "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
 }
 
+#define check_texture_float(r, f, d) check_texture_float_(__LINE__, r, f, d)
+static void check_texture_float_(unsigned int line, ID3D11Texture2D *texture,
+        float expected_value, BYTE max_diff)
+{
+    struct texture_readback rb;
+    unsigned int x = 0, y = 0;
+    BOOL all_match = TRUE;
+    float value = 0.0f;
+
+    get_texture_readback(texture, &rb);
+    for (y = 0; y < rb.height; ++y)
+    {
+        for (x = 0; x < rb.width; ++x)
+        {
+            value = get_readback_float(&rb, x, y);
+            if (!compare_float(value, expected_value, max_diff))
+            {
+                all_match = FALSE;
+                break;
+            }
+        }
+        if (!all_match)
+            break;
+    }
+    release_texture_readback(&rb);
+    ok_(__FILE__, line)(all_match,
+            "Got unexpected value %.8e at (%u, %u).\n", value, x, y);
+}
+
 static ID3D11Device *create_device(const D3D_FEATURE_LEVEL *feature_level)
 {
     static const D3D_FEATURE_LEVEL default_feature_level[] =
@@ -5097,6 +5156,78 @@ static void test_create_typeless_resource(void)
     ok(!refcount, "Device has %u references left.\n", refcount);
 }
 
+static void test_clear_depth_stencil_view(void)
+{
+    D3D11_TEXTURE2D_DESC texture_desc;
+    ID3D11Texture2D *depth_texture;
+    ID3D11DeviceContext *context;
+    ID3D11DepthStencilView *dsv;
+    ID3D11Device *device;
+    ULONG refcount;
+    HRESULT hr;
+
+    if (!(device = create_device(NULL)))
+    {
+        skip("Failed to create device.\n");
+        return;
+    }
+
+    ID3D11Device_GetImmediateContext(device, &context);
+
+    texture_desc.Width = 640;
+    texture_desc.Height = 480;
+    texture_desc.MipLevels = 1;
+    texture_desc.ArraySize = 1;
+    texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
+    texture_desc.SampleDesc.Count = 1;
+    texture_desc.SampleDesc.Quality = 0;
+    texture_desc.Usage = D3D11_USAGE_DEFAULT;
+    texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
+    texture_desc.CPUAccessFlags = 0;
+    texture_desc.MiscFlags = 0;
+    hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
+    ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
+
+    hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
+    ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
+
+    ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
+    check_texture_float(depth_texture, 1.0f, 0);
+
+    ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.25f, 0);
+    check_texture_float(depth_texture, 0.25f, 0);
+
+    ID3D11Texture2D_Release(depth_texture);
+    ID3D11DepthStencilView_Release(dsv);
+
+    texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
+    hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
+    ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
+
+    hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
+    ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
+
+    ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
+    todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
+
+    ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0xff);
+    todo_wine check_texture_color(depth_texture, 0xff000000, 0);
+
+    ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0xff);
+    check_texture_color(depth_texture, 0xffffffff, 0);
+
+    ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0);
+    check_texture_color(depth_texture, 0x00000000, 0);
+
+    ID3D11Texture2D_Release(depth_texture);
+    ID3D11DepthStencilView_Release(dsv);
+
+    ID3D11DeviceContext_Release(context);
+
+    refcount = ID3D11Device_Release(device);
+    ok(!refcount, "Device has %u references left.\n", refcount);
+}
+
 START_TEST(d3d11)
 {
     test_create_device();
@@ -5131,4 +5262,5 @@ START_TEST(d3d11)
     test_multisample_init();
     test_check_multisample_quality_levels();
     test_create_typeless_resource();
+    test_clear_depth_stencil_view();
 }
-- 
2.4.10




More information about the wine-patches mailing list