From: Jactry Zeng Subject: [PATCH vkd3d 3/3] vkd3d: Handle SINT and UINT format in ClearRenderTargetView(). Message-Id: <09fc68af-67c1-0b83-e62b-4b9c4317be57@codeweavers.com> Date: Tue, 16 Jul 2019 15:46:27 +0800 Signed-off-by: Jactry Zeng --- libs/vkd3d/command.c | 24 ++++++++++++++++++++++- libs/vkd3d/utils.c | 40 ++++++++++++++++++++++++++++++++++++++ libs/vkd3d/vkd3d_private.h | 2 ++ tests/d3d12.c | 24 +++++++++++------------ 4 files changed, 77 insertions(+), 13 deletions(-) diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c index eeae9cf..12eea0e 100644 --- a/libs/vkd3d/command.c +++ b/libs/vkd3d/command.c @@ -4631,11 +4631,11 @@ static void STDMETHODCALLTYPE d3d12_command_list_ClearDepthStencilView(ID3D12Gra static void STDMETHODCALLTYPE d3d12_command_list_ClearRenderTargetView(ID3D12GraphicsCommandList1 *iface, D3D12_CPU_DESCRIPTOR_HANDLE rtv, const FLOAT color[4], UINT rect_count, const D3D12_RECT *rects) { - const union VkClearValue clear_value = {{{color[0], color[1], color[2], color[3]}}}; struct d3d12_command_list *list = impl_from_ID3D12GraphicsCommandList1(iface); const struct d3d12_rtv_desc *rtv_desc = d3d12_rtv_desc_from_cpu_handle(rtv); struct VkAttachmentDescription attachment_desc; struct VkAttachmentReference color_reference; + union VkClearValue clear_value; TRACE("iface %p, rtv %#lx, color %p, rect_count %u, rects %p.\n", iface, rtv.ptr, color, rect_count, rects); @@ -4655,6 +4655,28 @@ static void STDMETHODCALLTYPE d3d12_command_list_ClearRenderTargetView(ID3D12Gra color_reference.attachment = 0; color_reference.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + if (vkd3d_format_is_signed_integer(rtv_desc->format)) + { + clear_value.color.uint32[0] = color[0]; + clear_value.color.uint32[1] = color[1]; + clear_value.color.uint32[2] = color[2]; + clear_value.color.uint32[3] = color[3]; + } + else if (vkd3d_format_is_unsigned_integer(rtv_desc->format)) + { + clear_value.color.uint32[0] = max(0, color[0]); + clear_value.color.uint32[1] = max(0, color[1]); + clear_value.color.uint32[2] = max(0, color[2]); + clear_value.color.uint32[3] = max(0, color[3]); + } + else + { + clear_value.color.float32[0] = color[0]; + clear_value.color.float32[1] = color[1]; + clear_value.color.float32[2] = color[2]; + clear_value.color.float32[3] = color[3]; + } + d3d12_command_list_clear(list, &attachment_desc, &color_reference, NULL, rtv_desc->view, rtv_desc->width, rtv_desc->height, rtv_desc->layer_count, &clear_value, rect_count, rects); diff --git a/libs/vkd3d/utils.c b/libs/vkd3d/utils.c index 5c8d363..f41d5bb 100644 --- a/libs/vkd3d/utils.c +++ b/libs/vkd3d/utils.c @@ -262,6 +262,46 @@ bool dxgi_format_is_typeless(DXGI_FORMAT dxgi_format) } } +bool vkd3d_format_is_signed_integer(VkFormat format) +{ + switch (format) + { + case VK_FORMAT_R32G32B32A32_SINT: + case VK_FORMAT_R16G16B16A16_SINT: + case VK_FORMAT_R32G32B32_SINT: + case VK_FORMAT_R8G8B8A8_SINT: + case VK_FORMAT_R32G32_SINT: + case VK_FORMAT_R16G16_SINT: + case VK_FORMAT_R8G8_SINT: + case VK_FORMAT_R32_SINT: + case VK_FORMAT_R16_SINT: + case VK_FORMAT_R8_SINT: + return true; + default: + return false; + } +} + +bool vkd3d_format_is_unsigned_integer(VkFormat format) +{ + switch (format) + { + case VK_FORMAT_R32G32B32A32_UINT: + case VK_FORMAT_R16G16B16A16_UINT: + case VK_FORMAT_R32G32B32_UINT: + case VK_FORMAT_R8G8B8A8_UINT: + case VK_FORMAT_R32G32_UINT: + case VK_FORMAT_R16G16_UINT: + case VK_FORMAT_R8G8_UINT: + case VK_FORMAT_R32_UINT: + case VK_FORMAT_R16_UINT: + case VK_FORMAT_R8_UINT: + return true; + default: + return false; + } +} + DXGI_FORMAT vkd3d_get_dxgi_format(VkFormat format) { DXGI_FORMAT dxgi_format; diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index 6e2dc2b..9fc3abb 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -1123,6 +1123,8 @@ HRESULT vkd3d_init_depth_stencil_formats(struct d3d12_device *device) DECLSPEC_H void vkd3d_cleanup_depth_stencil_formats(struct d3d12_device *device) DECLSPEC_HIDDEN; bool dxgi_format_is_typeless(DXGI_FORMAT dxgi_format) DECLSPEC_HIDDEN; +bool vkd3d_format_is_signed_integer(VkFormat format) DECLSPEC_HIDDEN; +bool vkd3d_format_is_unsigned_integer(VkFormat format) DECLSPEC_HIDDEN; static inline const struct vkd3d_format *vkd3d_format_from_d3d12_resource_desc( const struct d3d12_device *device, const D3D12_RESOURCE_DESC *desc, DXGI_FORMAT view_format) diff --git a/tests/d3d12.c b/tests/d3d12.c index 09cd884..9837184 100644 --- a/tests/d3d12.c +++ b/tests/d3d12.c @@ -4406,15 +4406,15 @@ static void test_clear_render_target_view(void) }, test_r8g8b8a8_uint[] = { - {green, 0, 0x01000100, true}, - {color, 0, 0x00000000, true}, - {negative_value, 0, 0x00000001, true}, + {green, 0, 0x01000100, false}, + {color, 0, 0x00000000, false}, + {negative_value, 0, 0x00000001, false}, }, test_r8g8b8a8_sint[] = { - {green, 0, 0x01000100, true}, - {color, 0, 0x00000000, true}, - {negative_value, 0, 0xfe00ff01, true}, + {green, 0, 0x01000100, false}, + {color, 0, 0x00000000, false}, + {negative_value, 0, 0xfe00ff01, false}, }; static const struct { @@ -4430,15 +4430,15 @@ static void test_clear_render_target_view(void) }, test_r16g16b16a16_uint[] = { - {green, 0, 0x0010000, true}, - {color, 0, 0x00000000, true}, - {negative_value, 0, 0x00000001, true}, + {green, 0, 0x0010000, false}, + {color, 0, 0x00000000, false}, + {negative_value, 0, 0x00000001, false}, }, test_r16g16b16a16_sint[] = { - {green, 0, 0x0010000, true}, - {color, 0, 0x00000000, true}, - {negative_value, 0, 0xfffe0000ffff0001, true}, + {green, 0, 0x0010000, false}, + {color, 0, 0x00000000, false}, + {negative_value, 0, 0xfffe0000ffff0001, false}, }; STATIC_ASSERT(ARRAY_SIZE(array_colors) == ARRAY_SIZE(array_expected_colors)); -- 2.20.1