[PATCH vkd3d 3/8] tests: Allow probing a single component.

Giovanni Mascellani gmascellani at codeweavers.com
Thu May 5 08:16:54 CDT 2022


Signed-off-by: Giovanni Mascellani <gmascellani at codeweavers.com>
---
 tests/d3d12_test_utils.h     | 19 +++++++++++++------
 tests/shader_runner.c        | 32 +++++++++++++++++++++++---------
 tests/shader_runner.h        |  3 ++-
 tests/shader_runner_d3d11.c  | 20 ++++++++++++++------
 tests/shader_runner_d3d12.c  |  4 ++--
 tests/shader_runner_d3d9.c   | 20 ++++++++++++++------
 tests/shader_runner_vulkan.c | 20 ++++++++++++++------
 tests/utils.h                |  9 +++++++++
 8 files changed, 91 insertions(+), 36 deletions(-)

diff --git a/tests/d3d12_test_utils.h b/tests/d3d12_test_utils.h
index bb298082..9fdc4bb3 100644
--- a/tests/d3d12_test_utils.h
+++ b/tests/d3d12_test_utils.h
@@ -569,9 +569,9 @@ static void check_readback_data_uint_(unsigned int line, struct resource_readbac
     ok_(line)(all_match, "Got 0x%08x, expected 0x%08x at (%u, %u, %u).\n", got, expected, x, y, z);
 }
 
-#define check_readback_data_vec4(a, b, c, d) check_readback_data_vec4_(__LINE__, a, b, c, d)
+#define check_readback_data_vec4(a, b, c, d, e) check_readback_data_vec4_(__LINE__, a, b, c, d, e)
 static void check_readback_data_vec4_(unsigned int line, struct resource_readback *rb,
-        const RECT *rect, const struct vec4 *expected, unsigned int max_diff)
+        const RECT *rect, const struct vec4 *expected, unsigned int max_diff, unsigned int comp_count)
 {
     RECT r = {0, 0, rb->width, rb->height};
     unsigned int x = 0, y = 0;
@@ -586,7 +586,7 @@ static void check_readback_data_vec4_(unsigned int line, struct resource_readbac
         for (x = r.left; x < r.right; ++x)
         {
             got = *get_readback_vec4(rb, x, y);
-            if (!compare_vec4(&got, expected, max_diff))
+            if (!compare_vec4_count(&got, expected, max_diff, comp_count))
             {
                 all_match = false;
                 break;
@@ -595,8 +595,15 @@ static void check_readback_data_vec4_(unsigned int line, struct resource_readbac
         if (!all_match)
             break;
     }
-    ok_(line)(all_match, "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e} at (%u, %u).\n",
-            got.x, got.y, got.z, got.w, expected->x, expected->y, expected->z, expected->w, x, y);
+    if (comp_count == 4)
+    {
+        ok_(line)(all_match, "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e} at (%u, %u).\n",
+                got.x, got.y, got.z, got.w, expected->x, expected->y, expected->z, expected->w, x, y);
+    }
+    else
+    {
+        ok_(line)(all_match, "Got %.8e, expected %.8e at (%u, %u).\n", got.x, expected->x, x, y);
+    }
 }
 
 #define check_sub_resource_uint(a, b, c, d, e, f) check_sub_resource_uint_(__LINE__, a, b, c, d, e, f)
@@ -619,7 +626,7 @@ static inline void check_sub_resource_vec4_(unsigned int line, ID3D12Resource *t
     struct resource_readback rb;
 
     get_texture_readback_with_command_list(texture, sub_resource_idx, &rb, queue, command_list);
-    check_readback_data_vec4_(line, &rb, NULL, expected, max_diff);
+    check_readback_data_vec4_(line, &rb, NULL, expected, max_diff, 4);
     release_resource_readback(&rb);
 }
 
diff --git a/tests/shader_runner.c b/tests/shader_runner.c
index a820810a..f8fd6e3e 100644
--- a/tests/shader_runner.c
+++ b/tests/shader_runner.c
@@ -411,7 +411,7 @@ static void parse_test_directive(struct shader_runner *runner, const char *line)
     }
     else if (match_string(line, "probe", &line))
     {
-        unsigned int left, top, right, bottom, ulps;
+        unsigned int left, top, right, bottom, ulps, comp_count;
         struct vec4 v;
         int ret, len;
         RECT rect;
@@ -434,16 +434,30 @@ static void parse_test_directive(struct shader_runner *runner, const char *line)
             line += len;
         }
 
-        if (!match_string(line, "rgba", &line))
-            fatal_error("Malformed probe arguments '%s'.\n", line);
-
-        ret = sscanf(line, "( %f , %f , %f , %f ) %u", &v.x, &v.y, &v.z, &v.w, &ulps);
-        if (ret < 4)
+        if (match_string(line, "rgba", &line))
+        {
+            comp_count = 4;
+            ret = sscanf(line, "( %f , %f , %f , %f ) %u", &v.x, &v.y, &v.z, &v.w, &ulps);
+            if (ret < 4)
+                fatal_error("Malformed probe arguments '%s'.\n", line);
+            if (ret < 5)
+                ulps = 0;
+        }
+        else if (match_string(line, "r", &line))
+        {
+            comp_count = 1;
+            ret = sscanf(line, "%f %u", &v.x, &ulps);
+            if (ret < 1)
+                fatal_error("Malformed probe arguments '%s'.\n", line);
+            if (ret < 2)
+                ulps = 0;
+        }
+        else
+        {
             fatal_error("Malformed probe arguments '%s'.\n", line);
-        if (ret < 5)
-            ulps = 0;
+        }
 
-        runner->ops->probe_vec4(runner, &rect, &v, ulps);
+        runner->ops->probe_vec4(runner, &rect, &v, ulps, comp_count);
     }
     else if (match_string(line, "uniform", &line))
     {
diff --git a/tests/shader_runner.h b/tests/shader_runner.h
index 9685eaa3..a85b84e2 100644
--- a/tests/shader_runner.h
+++ b/tests/shader_runner.h
@@ -123,7 +123,8 @@ struct shader_runner_ops
     struct resource *(*create_resource)(struct shader_runner *runner, const struct resource_params *params);
     void (*destroy_resource)(struct shader_runner *runner, struct resource *resource);
     bool (*draw)(struct shader_runner *runner, D3D_PRIMITIVE_TOPOLOGY primitive_topology, unsigned int vertex_count);
-    void (*probe_vec4)(struct shader_runner *runner, const RECT *rect, const struct vec4 *v, unsigned int ulps);
+    void (*probe_vec4)(struct shader_runner *runner, const RECT *rect, const struct vec4 *v,
+            unsigned int ulps, unsigned int comp_count);
 };
 
 void fatal_error(const char *format, ...) VKD3D_NORETURN VKD3D_PRINTF_FUNC(1, 2);
diff --git a/tests/shader_runner_d3d11.c b/tests/shader_runner_d3d11.c
index 9d1ed09b..5a67f501 100644
--- a/tests/shader_runner_d3d11.c
+++ b/tests/shader_runner_d3d11.c
@@ -576,7 +576,7 @@ static const struct vec4 *get_readback_vec4(struct resource_readback *rb, unsign
 }
 
 static void check_readback_data_vec4(struct resource_readback *rb,
-        const RECT *rect, const struct vec4 *expected, unsigned int max_diff)
+        const RECT *rect, const struct vec4 *expected, unsigned int max_diff, unsigned int comp_count)
 {
     unsigned int x = 0, y = 0;
     struct vec4 got = {0};
@@ -587,7 +587,7 @@ static void check_readback_data_vec4(struct resource_readback *rb,
         for (x = rect->left; x < rect->right; ++x)
         {
             got = *get_readback_vec4(rb, x, y);
-            if (!compare_vec4(&got, expected, max_diff))
+            if (!compare_vec4_count(&got, expected, max_diff, comp_count))
             {
                 all_match = false;
                 break;
@@ -596,17 +596,25 @@ static void check_readback_data_vec4(struct resource_readback *rb,
         if (!all_match)
             break;
     }
-    ok(all_match, "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e} at (%u, %u).\n",
-            got.x, got.y, got.z, got.w, expected->x, expected->y, expected->z, expected->w, x, y);
+    if (comp_count == 4)
+    {
+        ok(all_match, "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e} at (%u, %u).\n",
+                got.x, got.y, got.z, got.w, expected->x, expected->y, expected->z, expected->w, x, y);
+    }
+    else
+    {
+        ok(all_match, "Got %.8e, expected %.8e at (%u, %u).\n", got.x, expected->x, x, y);
+    }
 }
 
-static void d3d11_runner_probe_vec4(struct shader_runner *r, const RECT *rect, const struct vec4 *v, unsigned int ulps)
+static void d3d11_runner_probe_vec4(struct shader_runner *r, const RECT *rect, const struct vec4 *v,
+        unsigned int ulps, unsigned int comp_count)
 {
     struct d3d11_shader_runner *runner = d3d11_shader_runner(r);
     struct resource_readback rb;
 
     init_readback(runner, &rb);
-    check_readback_data_vec4(&rb, rect, v, ulps);
+    check_readback_data_vec4(&rb, rect, v, ulps, comp_count);
     release_readback(runner, &rb);
 }
 
diff --git a/tests/shader_runner_d3d12.c b/tests/shader_runner_d3d12.c
index 1fa2a461..1822029d 100644
--- a/tests/shader_runner_d3d12.c
+++ b/tests/shader_runner_d3d12.c
@@ -310,7 +310,7 @@ static bool d3d12_runner_draw(struct shader_runner *r,
 }
 
 static void d3d12_runner_probe_vec4(struct shader_runner *r,
-        const RECT *rect, const struct vec4 *v, unsigned int ulps)
+        const RECT *rect, const struct vec4 *v, unsigned int ulps, unsigned int comp_count)
 {
     struct d3d12_shader_runner *runner = d3d12_shader_runner(r);
     struct test_context *test_context = &runner->test_context;
@@ -320,7 +320,7 @@ static void d3d12_runner_probe_vec4(struct shader_runner *r,
             D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE);
     get_texture_readback_with_command_list(test_context->render_target, 0, &rb,
             test_context->queue, test_context->list);
-    todo_if (runner->r.is_todo) check_readback_data_vec4(&rb, rect, v, ulps);
+    todo_if (runner->r.is_todo) check_readback_data_vec4(&rb, rect, v, ulps, comp_count);
     release_resource_readback(&rb);
     reset_command_list(test_context->list, test_context->allocator);
     transition_resource_state(test_context->list, test_context->render_target,
diff --git a/tests/shader_runner_d3d9.c b/tests/shader_runner_d3d9.c
index f2875d42..0b2f71ad 100644
--- a/tests/shader_runner_d3d9.c
+++ b/tests/shader_runner_d3d9.c
@@ -479,7 +479,7 @@ static const struct vec4 *get_readback_vec4(const struct resource_readback *rb,
 }
 
 static void check_readback_data_vec4(struct resource_readback *rb,
-        const RECT *rect, const struct vec4 *expected, unsigned int max_diff)
+        const RECT *rect, const struct vec4 *expected, unsigned int max_diff, unsigned int comp_count)
 {
     unsigned int x = 0, y = 0;
     struct vec4 got = {0};
@@ -490,7 +490,7 @@ static void check_readback_data_vec4(struct resource_readback *rb,
         for (x = rect->left; x < rect->right; ++x)
         {
             got = *get_readback_vec4(rb, x, y);
-            if (!compare_vec4(&got, expected, max_diff))
+            if (!compare_vec4_count(&got, expected, max_diff, comp_count))
             {
                 all_match = false;
                 break;
@@ -499,8 +499,15 @@ static void check_readback_data_vec4(struct resource_readback *rb,
         if (!all_match)
             break;
     }
-    ok(all_match, "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e} at (%u, %u).\n",
-            got.x, got.y, got.z, got.w, expected->x, expected->y, expected->z, expected->w, x, y);
+    if (comp_count == 4)
+    {
+        ok(all_match, "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e} at (%u, %u).\n",
+                got.x, got.y, got.z, got.w, expected->x, expected->y, expected->z, expected->w, x, y);
+    }
+    else
+    {
+        ok(all_match, "Got %.8e, expected %.8e at (%u, %u).\n", got.x, expected->x, x, y);
+    }
 }
 
 static void release_readback(struct resource_readback *rb)
@@ -509,13 +516,14 @@ static void release_readback(struct resource_readback *rb)
     IDirect3DSurface9_Release(rb->surface);
 }
 
-static void d3d9_runner_probe_vec4(struct shader_runner *r, const RECT *rect, const struct vec4 *v, unsigned int ulps)
+static void d3d9_runner_probe_vec4(struct shader_runner *r, const RECT *rect, const struct vec4 *v,
+        unsigned int ulps, unsigned int comp_count)
 {
     struct d3d9_shader_runner *runner = d3d9_shader_runner(r);
     struct resource_readback rb;
 
     init_readback(runner, &rb);
-    check_readback_data_vec4(&rb, rect, v, ulps);
+    check_readback_data_vec4(&rb, rect, v, ulps, comp_count);
     release_readback(&rb);
 }
 
diff --git a/tests/shader_runner_vulkan.c b/tests/shader_runner_vulkan.c
index 5d4b65cf..8b461993 100644
--- a/tests/shader_runner_vulkan.c
+++ b/tests/shader_runner_vulkan.c
@@ -831,7 +831,7 @@ static const struct vec4 *get_readback_vec4(const uint8_t *data, unsigned int ro
 }
 
 static void check_readback_data_vec4(const uint8_t *data, unsigned int row_pitch,
-        const RECT *rect, const struct vec4 *expected, unsigned int max_diff)
+        const RECT *rect, const struct vec4 *expected, unsigned int max_diff, unsigned int comp_count)
 {
     unsigned int x = 0, y = 0;
     struct vec4 got = {0};
@@ -842,7 +842,7 @@ static void check_readback_data_vec4(const uint8_t *data, unsigned int row_pitch
         for (x = rect->left; x < rect->right; ++x)
         {
             got = *get_readback_vec4(data, row_pitch, x, y);
-            if (!compare_vec4(&got, expected, max_diff))
+            if (!compare_vec4_count(&got, expected, max_diff, comp_count))
             {
                 all_match = false;
                 break;
@@ -851,11 +851,19 @@ static void check_readback_data_vec4(const uint8_t *data, unsigned int row_pitch
         if (!all_match)
             break;
     }
-    ok(all_match, "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e} at (%u, %u).\n",
-            got.x, got.y, got.z, got.w, expected->x, expected->y, expected->z, expected->w, x, y);
+    if (comp_count == 4)
+    {
+        ok(all_match, "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e} at (%u, %u).\n",
+                got.x, got.y, got.z, got.w, expected->x, expected->y, expected->z, expected->w, x, y);
+    }
+    else
+    {
+        ok(all_match, "Got %.8e, expected %.8e at (%u, %u).\n", got.x, expected->x, x, y);
+    }
 }
 
-static void vulkan_runner_probe_vec4(struct shader_runner *r, const RECT *rect, const struct vec4 *v, unsigned int ulps)
+static void vulkan_runner_probe_vec4(struct shader_runner *r, const RECT *rect, const struct vec4 *v,
+        unsigned int ulps, unsigned int comp_count)
 {
     struct vulkan_shader_runner *runner = vulkan_shader_runner(r);
     VkDevice device = runner->device;
@@ -890,7 +898,7 @@ static void vulkan_runner_probe_vec4(struct shader_runner *r, const RECT *rect,
     end_command_buffer(runner);
 
     VK_CALL(vkMapMemory(device, memory, 0, VK_WHOLE_SIZE, 0, &data));
-    todo_if (runner->r.is_todo) check_readback_data_vec4(data, row_pitch, rect, v, ulps);
+    todo_if (runner->r.is_todo) check_readback_data_vec4(data, row_pitch, rect, v, ulps, comp_count);
     VK_CALL(vkUnmapMemory(device, memory));
 
     VK_CALL(vkFreeMemory(device, memory, NULL));
diff --git a/tests/utils.h b/tests/utils.h
index 563f0b0f..8adfd5cb 100644
--- a/tests/utils.h
+++ b/tests/utils.h
@@ -94,6 +94,15 @@ static inline bool compare_vec4(const struct vec4 *v1, const struct vec4 *v2, un
             && compare_float(v1->w, v2->w, ulps);
 }
 
+static inline bool compare_vec4_count(const struct vec4 *v1, const struct vec4 *v2, unsigned int ulps,
+        unsigned int comp_count)
+{
+    return (comp_count < 1 || compare_float(v1->x, v2->x, ulps))
+            && (comp_count < 2 || compare_float(v1->y, v2->y, ulps))
+            && (comp_count < 3 || compare_float(v1->z, v2->z, ulps))
+            && (comp_count < 4 || compare_float(v1->w, v2->w, ulps));
+}
+
 static inline void set_rect(RECT *rect, int left, int top, int right, int bottom)
 {
     rect->left = left;
-- 
2.36.0




More information about the wine-devel mailing list