[PATCH vkd3d 5/8] tests: Add tests for copying block-compressed texture regions of smallest miplevels.

Józef Kucia joseph.kucia at gmail.com
Tue Mar 19 08:41:02 CDT 2019


From: Józef Kucia <jkucia at codeweavers.com>

Signed-off-by: Józef Kucia <jkucia at codeweavers.com>
---
 tests/d3d12.c               | 40 +++++++++++++++-
 tests/d3d12_invalid_usage.c | 95 ++++++++++++++++++++-----------------
 tests/d3d12_test_utils.h    |  2 +
 3 files changed, 92 insertions(+), 45 deletions(-)

diff --git a/tests/d3d12.c b/tests/d3d12.c
index 89858ae01f02..c99928a40092 100644
--- a/tests/d3d12.c
+++ b/tests/d3d12.c
@@ -21177,8 +21177,8 @@ static void test_copy_block_compressed_texture(void)
     }
     ID3D12Resource_Unmap(src_buffer, 0, NULL);
 
-    texture = create_default_texture(device,
-            8, 8, DXGI_FORMAT_BC2_UNORM, 0, D3D12_RESOURCE_STATE_COPY_DEST);
+    texture = create_default_texture2d(device, 8, 8, 1, 4, DXGI_FORMAT_BC2_UNORM,
+            D3D12_RESOURCE_FLAG_NONE, D3D12_RESOURCE_STATE_COPY_DEST);
 
     /* copy from buffer to texture */
     dst_location.pResource = texture;
@@ -21210,6 +21210,16 @@ static void test_copy_block_compressed_texture(void)
     ID3D12GraphicsCommandList_CopyTextureRegion(command_list,
             &dst_location, 4, 4, 0, &src_location, &box);
 
+    /* miplevels smaller than 4x4 */
+    dst_location.SubresourceIndex = 2;
+    set_box(&box, 4, 0, 0, 8, 4, 1);
+    ID3D12GraphicsCommandList_CopyTextureRegion(command_list,
+            &dst_location, 0, 0, 0, &src_location, &box);
+    dst_location.SubresourceIndex = 3;
+    set_box(&box, 8, 0, 0, 12, 4, 1);
+    ID3D12GraphicsCommandList_CopyTextureRegion(command_list,
+            &dst_location, 0, 0, 0, &src_location, &box);
+
     transition_resource_state(command_list, texture,
             D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_COPY_SOURCE);
 
@@ -21272,6 +21282,32 @@ static void test_copy_block_compressed_texture(void)
             "Got {0x%08x, 0x%08x, 0x%08x, 0x%08x} at (%u, %u), expected {0x%08x, 0x%08x, 0x%08x, 0x%08x}.\n",
             got.x, got.y, got.z, got.w, x, y, expected.x, expected.y, expected.z, expected.w);
 
+    reset_command_list(command_list, context.allocator);
+    get_texture_readback_with_command_list(texture, 2, &rb, queue, command_list);
+    block_id = 1;
+    expected.x = block_id << 8 | 0;
+    expected.y = block_id << 8 | 1;
+    expected.z = block_id << 8 | 2;
+    expected.w = block_id << 8 | 3;
+    got = *get_readback_uvec4(&rb, 0, 0);
+    release_resource_readback(&rb);
+    ok(compare_uvec4(&got, &expected),
+            "Got {0x%08x, 0x%08x, 0x%08x, 0x%08x}, expected {0x%08x, 0x%08x, 0x%08x, 0x%08x}.\n",
+            got.x, got.y, got.z, got.w, expected.x, expected.y, expected.z, expected.w);
+
+    reset_command_list(command_list, context.allocator);
+    get_texture_readback_with_command_list(texture, 3, &rb, queue, command_list);
+    block_id = 2;
+    expected.x = block_id << 8 | 0;
+    expected.y = block_id << 8 | 1;
+    expected.z = block_id << 8 | 2;
+    expected.w = block_id << 8 | 3;
+    got = *get_readback_uvec4(&rb, 0, 0);
+    release_resource_readback(&rb);
+    ok(compare_uvec4(&got, &expected),
+            "Got {0x%08x, 0x%08x, 0x%08x, 0x%08x}, expected {0x%08x, 0x%08x, 0x%08x, 0x%08x}.\n",
+            got.x, got.y, got.z, got.w, expected.x, expected.y, expected.z, expected.w);
+
     reset_command_list(command_list, context.allocator);
     get_buffer_readback_with_command_list(dst_buffer, DXGI_FORMAT_R32_UINT, &rb, queue, command_list);
     for (y = 0; y < 24 / format_block_height(DXGI_FORMAT_BC2_UNORM); ++y)
diff --git a/tests/d3d12_invalid_usage.c b/tests/d3d12_invalid_usage.c
index a76873bd20e6..69ffda64fdba 100644
--- a/tests/d3d12_invalid_usage.c
+++ b/tests/d3d12_invalid_usage.c
@@ -18,6 +18,20 @@
 
 #include "d3d12_crosstest.h"
 
+#define recreate_command_list(a, b, c) recreate_command_list_(__LINE__, a, b, c)
+static void recreate_command_list_(unsigned int line, ID3D12Device *device,
+        ID3D12CommandAllocator *allocator, ID3D12GraphicsCommandList **command_list)
+{
+    HRESULT hr;
+
+    hr = ID3D12CommandAllocator_Reset(allocator);
+    ok_(line)(hr == S_OK, "Failed to reset command allocator, hr %#x.\n", hr);
+    ID3D12GraphicsCommandList_Release(*command_list);
+    hr = ID3D12Device_CreateCommandList(device, 0, D3D12_COMMAND_LIST_TYPE_DIRECT,
+            allocator, NULL, &IID_ID3D12GraphicsCommandList, (void **)command_list);
+    ok_(line)(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
+}
+
 static void test_invalid_texture_resource_barriers(void)
 {
     ID3D12Resource *texture, *readback_buffer, *upload_buffer;
@@ -78,12 +92,7 @@ static void test_invalid_texture_resource_barriers(void)
         wait_queue_idle(device, queue);
     }
 
-    ID3D12GraphicsCommandList_Release(command_list);
-    hr = ID3D12CommandAllocator_Reset(command_allocator);
-    ok(hr == S_OK, "Failed to reset command allocator, hr %#x.\n", hr);
-    hr = ID3D12Device_CreateCommandList(device, 0, D3D12_COMMAND_LIST_TYPE_DIRECT,
-            command_allocator, NULL, &IID_ID3D12GraphicsCommandList, (void **)&command_list);
-    ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
+    recreate_command_list(device, command_allocator, &command_list);
 
     /* The before state does not match with the previous state. */
     transition_resource_state(command_list, texture,
@@ -100,12 +109,7 @@ static void test_invalid_texture_resource_barriers(void)
         wait_queue_idle(device, queue);
     }
 
-    hr = ID3D12CommandAllocator_Reset(command_allocator);
-    ok(hr == S_OK, "Failed to reset command allocator, hr %#x.\n", hr);
-    ID3D12GraphicsCommandList_Release(command_list);
-    hr = ID3D12Device_CreateCommandList(device, 0, D3D12_COMMAND_LIST_TYPE_DIRECT,
-            command_allocator, NULL, &IID_ID3D12GraphicsCommandList, (void **)&command_list);
-    ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
+    recreate_command_list(device, command_allocator, &command_list);
 
     /* Exactly one write state or a combination of read-only states are allowed. */
     transition_resource_state(command_list, texture,
@@ -114,12 +118,7 @@ static void test_invalid_texture_resource_barriers(void)
     hr = ID3D12GraphicsCommandList_Close(command_list);
     ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
 
-    hr = ID3D12CommandAllocator_Reset(command_allocator);
-    ok(hr == S_OK, "Failed to reset command allocator, hr %#x.\n", hr);
-    ID3D12GraphicsCommandList_Release(command_list);
-    hr = ID3D12Device_CreateCommandList(device, 0, D3D12_COMMAND_LIST_TYPE_DIRECT,
-            command_allocator, NULL, &IID_ID3D12GraphicsCommandList, (void **)&command_list);
-    ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
+    recreate_command_list(device, command_allocator, &command_list);
 
     /* Readback resources cannot transition from D3D12_RESOURCE_STATE_COPY_DEST. */
     transition_resource_state(command_list, readback_buffer,
@@ -127,12 +126,7 @@ static void test_invalid_texture_resource_barriers(void)
     hr = ID3D12GraphicsCommandList_Close(command_list);
     todo ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
 
-    hr = ID3D12CommandAllocator_Reset(command_allocator);
-    ok(hr == S_OK, "Failed to reset command allocator, hr %#x.\n", hr);
-    ID3D12GraphicsCommandList_Release(command_list);
-    hr = ID3D12Device_CreateCommandList(device, 0, D3D12_COMMAND_LIST_TYPE_DIRECT,
-            command_allocator, NULL, &IID_ID3D12GraphicsCommandList, (void **)&command_list);
-    ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
+    recreate_command_list(device, command_allocator, &command_list);
 
     /* Upload resources cannot transition from D3D12_RESOURCE_STATE_GENERIC_READ. */
     transition_resource_state(command_list, upload_buffer,
@@ -203,12 +197,7 @@ static void test_invalid_copy_texture_region(void)
     hr = ID3D12GraphicsCommandList_Close(command_list);
     todo ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
 
-    hr = ID3D12CommandAllocator_Reset(command_allocator);
-    ok(hr == S_OK, "Failed to reset command allocator, hr %#x.\n", hr);
-    ID3D12GraphicsCommandList_Release(command_list);
-    hr = ID3D12Device_CreateCommandList(device, 0, D3D12_COMMAND_LIST_TYPE_DIRECT,
-            command_allocator, NULL, &IID_ID3D12GraphicsCommandList, (void **)&command_list);
-    ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
+    recreate_command_list(device, command_allocator, &command_list);
 
     src_location.PlacedFootprint.Footprint.Width = 4;
     src_location.PlacedFootprint.Footprint.Height = 4;
@@ -220,12 +209,7 @@ static void test_invalid_copy_texture_region(void)
     hr = ID3D12GraphicsCommandList_Close(command_list);
     todo ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
 
-    hr = ID3D12CommandAllocator_Reset(command_allocator);
-    ok(hr == S_OK, "Failed to reset command allocator, hr %#x.\n", hr);
-    ID3D12GraphicsCommandList_Release(command_list);
-    hr = ID3D12Device_CreateCommandList(device, 0, D3D12_COMMAND_LIST_TYPE_DIRECT,
-            command_allocator, NULL, &IID_ID3D12GraphicsCommandList, (void **)&command_list);
-    ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
+    recreate_command_list(device, command_allocator, &command_list);
 
     /* row pitch must be multiple of D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT */
     src_location.PlacedFootprint.Footprint.RowPitch
@@ -237,12 +221,7 @@ static void test_invalid_copy_texture_region(void)
     hr = ID3D12GraphicsCommandList_Close(command_list);
     todo ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
 
-    hr = ID3D12CommandAllocator_Reset(command_allocator);
-    ok(hr == S_OK, "Failed to reset command allocator, hr %#x.\n", hr);
-    ID3D12GraphicsCommandList_Release(command_list);
-    hr = ID3D12Device_CreateCommandList(device, 0, D3D12_COMMAND_LIST_TYPE_DIRECT,
-            command_allocator, NULL, &IID_ID3D12GraphicsCommandList, (void **)&command_list);
-    ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
+    recreate_command_list(device, command_allocator, &command_list);
 
     dst_location.pResource = dst_buffer;
     dst_location.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
@@ -266,12 +245,42 @@ static void test_invalid_copy_texture_region(void)
     hr = ID3D12GraphicsCommandList_Close(command_list);
     todo ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
 
+    recreate_command_list(device, command_allocator, &command_list);
+
+    ID3D12Resource_Release(src_texture);
+    src_texture = create_default_texture2d(device, 4, 4, 1, 3, DXGI_FORMAT_BC3_UNORM,
+            D3D12_RESOURCE_FLAG_NONE, D3D12_RESOURCE_STATE_COPY_SOURCE);
+
+    src_location.pResource = src_texture;
+    src_location.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
+    src_location.SubresourceIndex = 1;
+
+    /* coordinates must be multiple of block size even for smallest miplevels */
+    set_box(&box, 0, 0, 0, 2, 2, 1);
+    ID3D12GraphicsCommandList_CopyTextureRegion(command_list,
+            &dst_location, 0, 0, 0, &src_location, &box);
+
+    hr = ID3D12GraphicsCommandList_Close(command_list);
+    todo ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
+
+    recreate_command_list(device, command_allocator, &command_list);
+
+    src_location.SubresourceIndex = 2;
+
+    /* coordinates must be multiple of block size even for smallest miplevels */
+    set_box(&box, 0, 0, 0, 1, 1, 1);
+    ID3D12GraphicsCommandList_CopyTextureRegion(command_list,
+            &dst_location, 0, 0, 0, &src_location, &box);
+
+    hr = ID3D12GraphicsCommandList_Close(command_list);
+    todo ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
+
     ID3D12CommandAllocator_Release(command_allocator);
     ID3D12GraphicsCommandList_Release(command_list);
     ID3D12Resource_Release(dst_buffer);
     ID3D12Resource_Release(src_buffer);
-    ID3D12Resource_Release(dst_texture);
     ID3D12Resource_Release(src_texture);
+    ID3D12Resource_Release(dst_texture);
     refcount = ID3D12Device_Release(device);
     ok(!refcount, "ID3D12Device has %u references left.\n", (unsigned int)refcount);
 }
diff --git a/tests/d3d12_test_utils.h b/tests/d3d12_test_utils.h
index 14c6d04e3ada..f181fe4ec04e 100644
--- a/tests/d3d12_test_utils.h
+++ b/tests/d3d12_test_utils.h
@@ -348,7 +348,9 @@ static void get_texture_readback_with_command_list(ID3D12Resource *texture, unsi
 
     miplevel = sub_resource % resource_desc.MipLevels;
     rb->width = max(1, resource_desc.Width >> miplevel);
+    rb->width = align(rb->width, format_block_width(resource_desc.Format));
     rb->height = max(1, resource_desc.Height >> miplevel);
+    rb->height = align(rb->height, format_block_height(resource_desc.Format));
     rb->depth = resource_desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D
             ? max(1, resource_desc.DepthOrArraySize >> miplevel) : 1;
     rb->row_pitch = align(rb->width * format_size(resource_desc.Format), D3D12_TEXTURE_DATA_PITCH_ALIGNMENT);
-- 
2.19.2




More information about the wine-devel mailing list