[PATCH 1/6] d3d10core/tests: Check all sub-resources in check_texture_* functions.

Józef Kucia jkucia at codeweavers.com
Fri May 13 06:55:26 CDT 2016


Signed-off-by: Józef Kucia <jkucia at codeweavers.com>
---
 dlls/d3d10core/tests/device.c | 83 ++++++++++++++++++++++++++++++-------------
 1 file changed, 58 insertions(+), 25 deletions(-)

diff --git a/dlls/d3d10core/tests/device.c b/dlls/d3d10core/tests/device.c
index 8e69656..a4fa401 100644
--- a/dlls/d3d10core/tests/device.c
+++ b/dlls/d3d10core/tests/device.c
@@ -91,12 +91,14 @@ struct texture_readback
 {
     ID3D10Texture2D *texture;
     D3D10_MAPPED_TEXTURE2D mapped_texture;
-    unsigned int width, height;
+    unsigned int width, height, sub_resource_idx;
 };
 
-static void get_texture_readback(ID3D10Texture2D *texture, struct texture_readback *rb)
+static void get_texture_readback(ID3D10Texture2D *texture, unsigned int sub_resource_idx,
+        struct texture_readback *rb)
 {
     D3D10_TEXTURE2D_DESC texture_desc;
+    unsigned int miplevel;
     ID3D10Device *device;
     HRESULT hr;
 
@@ -116,13 +118,16 @@ static void get_texture_readback(ID3D10Texture2D *texture, struct texture_readba
         return;
     }
 
-    rb->width = texture_desc.Width;
-    rb->height = texture_desc.Height;
+    miplevel = sub_resource_idx % texture_desc.MipLevels;
+    rb->width = max(1, texture_desc.Width >> miplevel);
+    rb->height = max(1, texture_desc.Height >> miplevel);
+    rb->sub_resource_idx = sub_resource_idx;
 
     ID3D10Device_CopyResource(device, (ID3D10Resource *)rb->texture, (ID3D10Resource *)texture);
-    if (FAILED(hr = ID3D10Texture2D_Map(rb->texture, 0, D3D10_MAP_READ, 0, &rb->mapped_texture)))
+    if (FAILED(hr = ID3D10Texture2D_Map(rb->texture, sub_resource_idx,
+            D3D10_MAP_READ, 0, &rb->mapped_texture)))
     {
-        trace("Failed to map texture, hr %#x.\n", hr);
+        trace("Failed to map sub-resource %u, hr %#x.\n", sub_resource_idx, hr);
         ID3D10Texture2D_Release(rb->texture);
         rb->texture = NULL;
     }
@@ -142,7 +147,7 @@ static float get_readback_float(struct texture_readback *rb, unsigned int x, uns
 
 static void release_texture_readback(struct texture_readback *rb)
 {
-    ID3D10Texture2D_Unmap(rb->texture, 0);
+    ID3D10Texture2D_Unmap(rb->texture, rb->sub_resource_idx);
     ID3D10Texture2D_Release(rb->texture);
 }
 
@@ -151,23 +156,23 @@ static DWORD get_texture_color(ID3D10Texture2D *texture, unsigned int x, unsigne
     struct texture_readback rb;
     DWORD color;
 
-    get_texture_readback(texture, &rb);
+    get_texture_readback(texture, 0, &rb);
     color = get_readback_color(&rb, x, y);
     release_texture_readback(&rb);
 
     return color;
 }
 
-#define check_texture_color(t, c, d) check_texture_color_(__LINE__, t, c, d)
-static void check_texture_color_(unsigned int line, ID3D10Texture2D *texture,
-        DWORD expected_color, BYTE max_diff)
+#define check_texture_sub_resource_color(t, s, c, d) check_texture_sub_resource_color_(__LINE__, t, s, c, d)
+static void check_texture_sub_resource_color_(unsigned int line, ID3D10Texture2D *texture,
+        unsigned int sub_resource_idx, DWORD expected_color, BYTE max_diff)
 {
     struct texture_readback rb;
     unsigned int x = 0, y = 0;
     BOOL all_match = TRUE;
     DWORD color = 0;
 
-    get_texture_readback(texture, &rb);
+    get_texture_readback(texture, sub_resource_idx, &rb);
     for (y = 0; y < rb.height; ++y)
     {
         for (x = 0; x < rb.width; ++x)
@@ -184,19 +189,33 @@ static void check_texture_color_(unsigned int line, ID3D10Texture2D *texture,
     }
     release_texture_readback(&rb);
     ok_(__FILE__, line)(all_match,
-            "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
+            "Got unexpected color 0x%08x at (%u, %u), sub-resource %u.\n",
+            color, x, y, sub_resource_idx);
 }
 
-#define check_texture_float(r, f, d) check_texture_float_(__LINE__, r, f, d)
-static void check_texture_float_(unsigned int line, ID3D10Texture2D *texture,
-        float expected_value, BYTE max_diff)
+#define check_texture_color(t, c, d) check_texture_color_(__LINE__, t, c, d)
+static void check_texture_color_(unsigned int line, ID3D10Texture2D *texture,
+        DWORD expected_color, BYTE max_diff)
+{
+    unsigned int sub_resource_idx, sub_resource_count;
+    D3D10_TEXTURE2D_DESC texture_desc;
+
+    ID3D10Texture2D_GetDesc(texture, &texture_desc);
+    sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
+    for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
+        check_texture_sub_resource_color_(line, texture, sub_resource_idx, expected_color, max_diff);
+}
+
+#define check_texture_sub_resource_float(r, s, f, d) check_texture_sub_resource_float_(__LINE__, r, s, f, d)
+static void check_texture_sub_resource_float_(unsigned int line, ID3D10Texture2D *texture,
+        unsigned int sub_resource_idx, 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);
+    get_texture_readback(texture, sub_resource_idx, &rb);
     for (y = 0; y < rb.height; ++y)
     {
         for (x = 0; x < rb.width; ++x)
@@ -213,7 +232,21 @@ static void check_texture_float_(unsigned int line, ID3D10Texture2D *texture,
     }
     release_texture_readback(&rb);
     ok_(__FILE__, line)(all_match,
-            "Got unexpected value %.8e at (%u, %u).\n", value, x, y);
+            "Got unexpected value %.8e at (%u, %u), sub-resource %u.\n",
+            value, x, y, sub_resource_idx);
+}
+
+#define check_texture_float(r, f, d) check_texture_float_(__LINE__, r, f, d)
+static void check_texture_float_(unsigned int line, ID3D10Texture2D *texture,
+        float expected_value, BYTE max_diff)
+{
+    unsigned int sub_resource_idx, sub_resource_count;
+    D3D10_TEXTURE2D_DESC texture_desc;
+
+    ID3D10Texture2D_GetDesc(texture, &texture_desc);
+    sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
+    for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
+        check_texture_sub_resource_float_(line, texture, sub_resource_idx, expected_value, max_diff);
 }
 
 static ID3D10Device *create_device(void)
@@ -4255,7 +4288,7 @@ static void test_texture(void)
 
         draw_quad(&test_context);
 
-        get_texture_readback(test_context.backbuffer, &rb);
+        get_texture_readback(test_context.backbuffer, 0, &rb);
         for (y = 0; y < 4; ++y)
         {
             for (x = 0; x < 4; ++x)
@@ -5121,7 +5154,7 @@ static void test_update_subresource(void)
     ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, &box,
             bitmap_data, 4 * sizeof(*bitmap_data), 0);
     draw_quad(&test_context);
-    get_texture_readback(test_context.backbuffer, &rb);
+    get_texture_readback(test_context.backbuffer, 0, &rb);
     for (i = 0; i < 4; ++i)
     {
         for (j = 0; j < 4; ++j)
@@ -5137,7 +5170,7 @@ static void test_update_subresource(void)
     ID3D10Device_UpdateSubresource(device, (ID3D10Resource *)texture, 0, NULL,
             bitmap_data, 4 * sizeof(*bitmap_data), 0);
     draw_quad(&test_context);
-    get_texture_readback(test_context.backbuffer, &rb);
+    get_texture_readback(test_context.backbuffer, 0, &rb);
     for (i = 0; i < 4; ++i)
     {
         for (j = 0; j < 4; ++j)
@@ -5321,7 +5354,7 @@ static void test_copy_subresource_region(void)
     ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
             0, 0, 0, (ID3D10Resource *)src_texture, 0, &box);
     draw_quad(&test_context);
-    get_texture_readback(test_context.backbuffer, &rb);
+    get_texture_readback(test_context.backbuffer, 0, &rb);
     for (i = 0; i < 4; ++i)
     {
         for (j = 0; j < 4; ++j)
@@ -5337,7 +5370,7 @@ static void test_copy_subresource_region(void)
     ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_texture, 0,
             0, 0, 0, (ID3D10Resource *)src_texture, 0, NULL);
     draw_quad(&test_context);
-    get_texture_readback(test_context.backbuffer, &rb);
+    get_texture_readback(test_context.backbuffer, 0, &rb);
     for (i = 0; i < 4; ++i)
     {
         for (j = 0; j < 4; ++j)
@@ -5419,7 +5452,7 @@ static void test_copy_subresource_region(void)
     ID3D10Device_CopySubresourceRegion(device, (ID3D10Resource *)dst_buffer, 0,
             0, 0, 0, (ID3D10Resource *)src_buffer, 0, &box);
     draw_quad(&test_context);
-    get_texture_readback(test_context.backbuffer, &rb);
+    get_texture_readback(test_context.backbuffer, 0, &rb);
     for (i = 0; i < 4; ++i)
     {
         for (j = 0; j < 4; ++j)
@@ -6402,7 +6435,7 @@ static void test_draw_depth_only(void)
             draw_quad(&test_context);
         }
     }
-    get_texture_readback(texture, &rb);
+    get_texture_readback(texture, 0, &rb);
     for (i = 0; i < 4; ++i)
     {
         for (j = 0; j < 4; ++j)
-- 
2.7.3




More information about the wine-patches mailing list