From: Jactry Zeng Subject: [PATCH vkd3d 1/3] tests: Test ClearRenderTargetView() with R8G8B8A8_{SINT,UINT} formats. Message-Id: <4f619868-a6ab-245a-e9a5-4444fe4f40b1@codeweavers.com> Date: Tue, 16 Jul 2019 15:45:52 +0800 Signed-off-by: Jactry Zeng --- tests/d3d12.c | 97 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 75 insertions(+), 22 deletions(-) diff --git a/tests/d3d12.c b/tests/d3d12.c index bd055fb..bf063bf 100644 --- a/tests/d3d12.c +++ b/tests/d3d12.c @@ -4283,6 +4283,23 @@ static void test_clear_depth_stencil_view(void) destroy_test_context(&context); } +#define test_clear_rtv_r8g8b8a8_2d(a, b, c, d, e, f, g, h, i) test_clear_rtv_r8g8b8a8_2d_(__LINE__, a, b, c, d, e, f, g, h, i) +static void test_clear_rtv_r8g8b8a8_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_uint_(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}; @@ -4292,6 +4309,7 @@ static void test_clear_render_target_view(void) {1.0f, 0.0f, 0.0f, 1.0f}, {0.0f, 0.0f, 1.0f, 1.0f}, }; + static const float negative_value[] = {1.0f, -1.0f, -0.5f, -2.0f}; static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f}; static const float green[] = {0.0f, 1.0f, 0.0f, 1.0f}; ID3D12GraphicsCommandList *command_list; @@ -4311,6 +4329,30 @@ static void test_clear_render_target_view(void) unsigned int i; D3D12_BOX box; HRESULT hr; + static const struct + { + const float *color; + unsigned int max_diff; + unsigned int expected; + bool is_todo; + } + test_r8g8b8a8_unorm[] = + { + {green, 0, 0xff00ff00, false}, + {color, 2, 0xbf4c7f19, false}, + }, + test_r8g8b8a8_uint[] = + { + {green, 0, 0x01000100, true}, + {color, 0, 0x00000000, true}, + {negative_value, 0, 0x00000001, true}, + }, + test_r8g8b8a8_sint[] = + { + {green, 0, 0x01000100, true}, + {color, 0, 0x00000000, true}, + {negative_value, 0, 0xfe00ff01, true}, + }; STATIC_ASSERT(ARRAY_SIZE(array_colors) == ARRAY_SIZE(array_expected_colors)); @@ -4358,32 +4400,44 @@ static void test_clear_render_target_view(void) rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; rtv_desc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2D; ID3D12Device_CreateRenderTargetView(device, resource, &rtv_desc, rtv_handle); - - ID3D12GraphicsCommandList_ClearRenderTargetView(command_list, rtv_handle, green, 0, NULL); - transition_resource_state(command_list, resource, - D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE); - check_sub_resource_uint(resource, 0, queue, command_list, 0xff00ff00, 0); - - reset_command_list(command_list, context.allocator); - transition_resource_state(command_list, resource, - D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET); - - 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); - check_sub_resource_uint(resource, 0, queue, command_list, 0xbf4c7f19, 2); + for (i = 0; i < ARRAY_SIZE(test_r8g8b8a8_unorm); i++) + { + vkd3d_test_set_context("Test %u", i); + test_clear_rtv_r8g8b8a8_2d(command_list, rtv_handle, test_r8g8b8a8_unorm[i].color, resource, queue, + test_r8g8b8a8_unorm[i].expected, context.allocator, test_r8g8b8a8_unorm[i].max_diff, + test_r8g8b8a8_unorm[i].is_todo); + } + vkd3d_test_set_context(NULL); /* sRGB view */ - reset_command_list(command_list, context.allocator); - transition_resource_state(command_list, resource, - D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET); rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB; ID3D12Device_CreateRenderTargetView(device, resource, &rtv_desc, rtv_handle); + test_clear_rtv_r8g8b8a8_2d(command_list, rtv_handle, color, resource, queue, + 0xbf95bc59, context.allocator, 2, FALSE); - 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); - check_sub_resource_uint(resource, 0, queue, command_list, 0xbf95bc59, 2); + /* DXGI_FORMAT_R8G8B8A8_UINT view */ + rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UINT; + ID3D12Device_CreateRenderTargetView(device, resource, &rtv_desc, rtv_handle); + for (i = 0; i < ARRAY_SIZE(test_r8g8b8a8_uint); i++) + { + vkd3d_test_set_context("Test %u", i); + test_clear_rtv_r8g8b8a8_2d(command_list, rtv_handle, test_r8g8b8a8_uint[i].color, resource, queue, + test_r8g8b8a8_uint[i].expected, context.allocator, test_r8g8b8a8_uint[i].max_diff, + test_r8g8b8a8_uint[i].is_todo); + } + vkd3d_test_set_context(NULL); + + /* DXGI_FORMAT_R8G8B8A8_SINT view */ + rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_SINT; + ID3D12Device_CreateRenderTargetView(device, resource, &rtv_desc, rtv_handle); + for (i = 0; i < ARRAY_SIZE(test_r8g8b8a8_sint); i++) + { + vkd3d_test_set_context("Test %u", i); + test_clear_rtv_r8g8b8a8_2d(command_list, rtv_handle, test_r8g8b8a8_sint[i].color, resource, queue, + test_r8g8b8a8_sint[i].expected, context.allocator, test_r8g8b8a8_sint[i].max_diff, + test_r8g8b8a8_sint[i].is_todo); + } + vkd3d_test_set_context(NULL); /* 2D array texture */ ID3D12Resource_Release(resource); @@ -4394,7 +4448,6 @@ static void test_clear_render_target_view(void) &IID_ID3D12Resource, (void **)&resource); ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr); - reset_command_list(command_list, context.allocator); for (i = 0; i < ARRAY_SIZE(array_colors); ++i) { memset(&rtv_desc, 0, sizeof(rtv_desc)); -- 2.20.1