Signed-off-by: Jactry Zeng jzeng@codeweavers.com --- tests/d3d12.c | 137 +++++++++++++++++++++++++++++++++++++++ tests/d3d12_test_utils.h | 2 + 2 files changed, 139 insertions(+)
diff --git a/tests/d3d12.c b/tests/d3d12.c index bf063bf..09cd884 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, @@ -4300,6 +4346,23 @@ static void test_clear_rtv_r8g8b8a8_2d_(unsigned int line, ID3D12GraphicsCommand D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET); }
+#define test_clear_rtv_r16g16b16a16_2d(a, b, c, d, e, f, g, h, i) test_clear_rtv_r16g16b16a16_2d_(__LINE__, a, b, c, d, e, f, g, h, i) +static void test_clear_rtv_r16g16b16a16_2d_(unsigned int line, ID3D12GraphicsCommandList *command_list, + D3D12_CPU_DESCRIPTOR_HANDLE rtv_handle, const float *color, ID3D12Resource *resource, + ID3D12CommandQueue *queue, const unsigned int expected, ID3D12CommandAllocator *allocator, + unsigned int max_diff, BOOL is_todo) +{ + ID3D12GraphicsCommandList_ClearRenderTargetView(command_list, rtv_handle, color, 0, NULL); + transition_resource_state(command_list, resource, + D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE); + todo_if(is_todo) + check_sub_resource_uint64_(line, resource, 0, queue, command_list, expected, max_diff); + + reset_command_list(command_list, allocator); + transition_resource_state(command_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}; @@ -4353,6 +4416,30 @@ static void test_clear_render_target_view(void) {color, 0, 0x00000000, true}, {negative_value, 0, 0xfe00ff01, true}, }; + static const struct + { + const float *color; + unsigned int max_diff; + uint64_t expected; + bool is_todo; + } + test_r16g16b16a16_unorm[] = + { + {green, 0, 0xffff0000, false}, + {color, 0, 0x8000199a, false}, + }, + test_r16g16b16a16_uint[] = + { + {green, 0, 0x0010000, true}, + {color, 0, 0x00000000, true}, + {negative_value, 0, 0x00000001, true}, + }, + test_r16g16b16a16_sint[] = + { + {green, 0, 0x0010000, true}, + {color, 0, 0x00000000, true}, + {negative_value, 0, 0xfffe0000ffff0001, true}, + };
STATIC_ASSERT(ARRAY_SIZE(array_colors) == ARRAY_SIZE(array_expected_colors));
@@ -4541,6 +4628,56 @@ static void test_clear_render_target_view(void) check_readback_data_uint(&rb, &box, 0xbf4c7f19, 1); release_resource_readback(&rb);
+ /* R16G16B16A16 views */ + reset_command_list(command_list, context.allocator); + ID3D12Resource_Release(resource); + resource_desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; + resource_desc.DepthOrArraySize = 1; + resource_desc.Format = DXGI_FORMAT_R16G16B16A16_TYPELESS; + clear_value.Format = DXGI_FORMAT_R16G16B16A16_UNORM; + hr = ID3D12Device_CreateCommittedResource(device, + &heap_properties, D3D12_HEAP_FLAG_NONE, &resource_desc, + D3D12_RESOURCE_STATE_RENDER_TARGET, &clear_value, + &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(command_list, rtv_handle, test_r16g16b16a16_unorm[i].color, resource, queue, + test_r16g16b16a16_unorm[i].expected, context.allocator, test_r16g16b16a16_unorm[i].max_diff, + 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(command_list, rtv_handle, test_r16g16b16a16_uint[i].color, resource, queue, + test_r16g16b16a16_uint[i].expected, context.allocator, test_r16g16b16a16_uint[i].max_diff, + 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(command_list, rtv_handle, test_r16g16b16a16_sint[i].color, resource, queue, + test_r16g16b16a16_sint[i].expected, context.allocator, test_r16g16b16a16_sint[i].max_diff, + test_r16g16b16a16_sint[i].is_todo); + } + vkd3d_test_set_context(NULL); + ID3D12Resource_Release(resource); ID3D12DescriptorHeap_Release(rtv_heap); destroy_test_context(&context); diff --git a/tests/d3d12_test_utils.h b/tests/d3d12_test_utils.h index 027a1fd..5a9e1e7 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: