[PATCH vkd3d v2 2/6] tests: Test ClearRenderTargetView() with R16G16B16A16 formats.

Józef Kucia joseph.kucia at gmail.com
Wed Jul 17 06:17:33 CDT 2019


From: Jactry Zeng <jzeng at codeweavers.com>

Signed-off-by: Jactry Zeng <jzeng at codeweavers.com>
Signed-off-by: Józef Kucia <jkucia at codeweavers.com>
---
 tests/d3d12.c            | 131 +++++++++++++++++++++++++++++++++++++++
 tests/d3d12_test_utils.h |   2 +
 2 files changed, 133 insertions(+)

diff --git a/tests/d3d12.c b/tests/d3d12.c
index 970e2ea32369..4223ec2c690d 100644
--- a/tests/d3d12.c
+++ b/tests/d3d12.c
@@ -89,6 +89,11 @@ static bool compare_uint16(uint16_t a, uint16_t b, unsigned int max_diff)
     return abs(a - b) <= max_diff;
 }
 
+static bool compare_uint64(uint64_t a, uint64_t b, unsigned int max_diff)
+{
+    return abs(a - b) <= max_diff;
+}
+
 static ULONG get_refcount(void *iface)
 {
     IUnknown *unk = iface;
@@ -531,6 +536,47 @@ static void check_sub_resource_uint16_(unsigned int line, ID3D12Resource *textur
     release_resource_readback(&rb);
 }
 
+#define check_readback_data_uint64(a, b, c, d) check_readback_data_uint64_(__LINE__, a, b, c, d)
+static void check_readback_data_uint64_(unsigned int line, struct resource_readback *rb,
+        const RECT *rect, uint64_t expected, unsigned int max_diff)
+{
+    RECT r = {0, 0, rb->width, rb->height};
+    unsigned int x = 0, y;
+    bool all_match = true;
+    uint64_t got = 0;
+
+    if (rect)
+        r = *rect;
+
+    for (y = r.top; y < r.bottom; ++y)
+    {
+        for (x = r.left; x < r.right; ++x)
+        {
+            got = get_readback_uint64(rb, x, y);
+            if (!compare_uint64(got, expected, max_diff))
+            {
+                all_match = false;
+                break;
+            }
+        }
+        if (!all_match)
+            break;
+    }
+    ok_(line)(all_match, "Got %#"PRIx64", expected %#"PRIx64" at (%u, %u).\n", got, expected, x, y);
+}
+
+#define check_sub_resource_uint64(a, b, c, d, e, f) check_sub_resource_uint64_(__LINE__, a, b, c, d, e, f)
+static void check_sub_resource_uint64_(unsigned int line, ID3D12Resource *texture,
+        unsigned int sub_resource_idx, ID3D12CommandQueue *queue, ID3D12GraphicsCommandList *command_list,
+        uint64_t expected, unsigned int max_diff)
+{
+    struct resource_readback rb;
+
+    get_texture_readback_with_command_list(texture, sub_resource_idx, &rb, queue, command_list);
+    check_readback_data_uint64_(line, &rb, NULL, expected, max_diff);
+    release_resource_readback(&rb);
+}
+
 #define check_sub_resource_vec4(a, b, c, d, e, f) check_sub_resource_vec4_(__LINE__, a, b, c, d, e, f)
 static void check_sub_resource_vec4_(unsigned int line, ID3D12Resource *texture,
         unsigned int sub_resource_idx, ID3D12CommandQueue *queue, ID3D12GraphicsCommandList *command_list,
@@ -4299,6 +4345,22 @@ static void test_clear_rtv_r8g8b8a8_2d_(unsigned int line, const struct test_con
             D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET);
 }
 
+#define test_clear_rtv_r16g16b16a16_2d(a, b, c, d, e, f, g) test_clear_rtv_r16g16b16a16_2d_(__LINE__, a, b, c, d, e, f, g)
+static void test_clear_rtv_r16g16b16a16_2d_(unsigned int line, const struct test_context *context,
+        ID3D12Resource *resource, D3D12_CPU_DESCRIPTOR_HANDLE rtv_handle,
+        const float *color, uint64_t expected, unsigned int max_diff, bool is_todo)
+{
+    ID3D12GraphicsCommandList_ClearRenderTargetView(context->list, rtv_handle, color, 0, NULL);
+    transition_resource_state(context->list, resource,
+            D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE);
+    todo_if(is_todo)
+    check_sub_resource_uint64_(line, resource, 0, context->queue, context->list, expected, max_diff);
+
+    reset_command_list(context->list, context->allocator);
+    transition_resource_state(context->list, resource,
+            D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET);
+}
+
 static void test_clear_render_target_view(void)
 {
     static const unsigned int array_expected_colors[] = {0xff00ff00, 0xff0000ff, 0xffff0000};
@@ -4352,6 +4414,28 @@ static void test_clear_render_target_view(void)
         {color, 0x00000000, 0, true},
         {negative_value, 0xfe00ff01, 0, true},
     };
+    static const struct
+    {
+        const float *color;
+        uint64_t expected;
+        bool is_todo;
+    }
+    test_r16g16b16a16_unorm[] =
+    {
+        {green, 0xffff0000},
+    },
+    test_r16g16b16a16_uint[] =
+    {
+        {green, 0x0010000, true},
+        {color, 0x00000000, true},
+        {negative_value, 0x00000001, true},
+    },
+    test_r16g16b16a16_sint[] =
+    {
+        {green, 0x0010000, true},
+        {color, 0x00000000, true},
+        {negative_value, 0xfffe0000ffff0001, true},
+    };
 
     STATIC_ASSERT(ARRAY_SIZE(array_colors) == ARRAY_SIZE(array_expected_colors));
 
@@ -4434,11 +4518,58 @@ static void test_clear_render_target_view(void)
     }
     vkd3d_test_set_context(NULL);
 
+    /* R16G16B16A16 views */
+    hr = ID3D12GraphicsCommandList_Close(command_list);
+    ok(hr == S_OK, "Failed to close command list, hr %#x.\n", hr);
+    reset_command_list(command_list, context.allocator);
+    ID3D12Resource_Release(resource);
+    resource_desc.Format = DXGI_FORMAT_R16G16B16A16_TYPELESS;
+    hr = ID3D12Device_CreateCommittedResource(device,
+            &heap_properties, D3D12_HEAP_FLAG_NONE, &resource_desc,
+            D3D12_RESOURCE_STATE_RENDER_TARGET, NULL,
+            &IID_ID3D12Resource, (void **)&resource);
+    ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
+
+    memset(&rtv_desc, 0, sizeof(rtv_desc));
+    rtv_desc.Format = DXGI_FORMAT_R16G16B16A16_UNORM;
+    rtv_desc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2D;
+    ID3D12Device_CreateRenderTargetView(device, resource, &rtv_desc, rtv_handle);
+    for (i = 0; i < ARRAY_SIZE(test_r16g16b16a16_unorm); i++)
+    {
+        vkd3d_test_set_context("Test %u", i);
+        test_clear_rtv_r16g16b16a16_2d(&context, resource, rtv_handle, test_r16g16b16a16_unorm[i].color,
+                test_r16g16b16a16_unorm[i].expected, 0, test_r16g16b16a16_unorm[i].is_todo);
+    }
+    vkd3d_test_set_context(NULL);
+
+    /* DXGI_FORMAT_R16G16B16A16_UINT view */
+    rtv_desc.Format = DXGI_FORMAT_R16G16B16A16_UINT;
+    ID3D12Device_CreateRenderTargetView(device, resource, &rtv_desc, rtv_handle);
+    for (i = 0; i < ARRAY_SIZE(test_r16g16b16a16_uint); i++)
+    {
+        vkd3d_test_set_context("Test %u", i);
+        test_clear_rtv_r16g16b16a16_2d(&context, resource, rtv_handle, test_r16g16b16a16_uint[i].color,
+                test_r16g16b16a16_uint[i].expected, 0, test_r16g16b16a16_uint[i].is_todo);
+    }
+    vkd3d_test_set_context(NULL);
+
+    /* DXGI_FORMAT_R16G16B16A16_SINT view */
+    rtv_desc.Format = DXGI_FORMAT_R16G16B16A16_SINT;
+    ID3D12Device_CreateRenderTargetView(device, resource, &rtv_desc, rtv_handle);
+    for (i = 0; i < ARRAY_SIZE(test_r16g16b16a16_sint); i++)
+    {
+        vkd3d_test_set_context("Test %u", i);
+        test_clear_rtv_r16g16b16a16_2d(&context, resource, rtv_handle, test_r16g16b16a16_sint[i].color,
+                test_r16g16b16a16_sint[i].expected, 0, test_r16g16b16a16_sint[i].is_todo);
+    }
+    vkd3d_test_set_context(NULL);
+
     /* 2D array texture */
     hr = ID3D12GraphicsCommandList_Close(command_list);
     ok(hr == S_OK, "Failed to close command list, hr %#x.\n", hr);
     reset_command_list(command_list, context.allocator);
     ID3D12Resource_Release(resource);
+    resource_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
     resource_desc.DepthOrArraySize = ARRAY_SIZE(array_colors);
     hr = ID3D12Device_CreateCommittedResource(device,
             &heap_properties, D3D12_HEAP_FLAG_NONE, &resource_desc,
diff --git a/tests/d3d12_test_utils.h b/tests/d3d12_test_utils.h
index 027a1fd68e97..5a9e1e7c9781 100644
--- a/tests/d3d12_test_utils.h
+++ b/tests/d3d12_test_utils.h
@@ -270,6 +270,8 @@ static unsigned int format_size(DXGI_FORMAT format)
         case DXGI_FORMAT_R32G32B32A32_UINT:
         case DXGI_FORMAT_R8G8_UNORM:
             return 16;
+        case DXGI_FORMAT_R16G16B16A16_TYPELESS:
+            return 8;
         case DXGI_FORMAT_R32_TYPELESS:
         case DXGI_FORMAT_D32_FLOAT:
         case DXGI_FORMAT_R32_FLOAT:
-- 
2.21.0




More information about the wine-devel mailing list