[PATCH vkd3d v2 3/6] vkd3d: Handle SINT and UINT formats in ClearRenderTargetView().
Józef Kucia
joseph.kucia at gmail.com
Wed Jul 17 06:17:34 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>
---
libs/vkd3d/command.c | 24 +++++++++++++++-
libs/vkd3d/utils.c | 40 ++++++++++++++++++++++++++
libs/vkd3d/vkd3d_private.h | 2 ++
tests/d3d12.c | 59 +++++++++++++++++---------------------
4 files changed, 92 insertions(+), 33 deletions(-)
diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c
index eeae9cf4efe2..d620f9fd0f3c 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;
+ 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 (vk_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 (vk_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 5c8d3635b22c..d87349ab29a3 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 vk_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 vk_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 6e2dc2b2bb8e..79155768e2fe 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 vk_format_is_signed_integer(VkFormat format) DECLSPEC_HIDDEN;
+bool vk_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 4223ec2c690d..c53d6053de1c 100644
--- a/tests/d3d12.c
+++ b/tests/d3d12.c
@@ -4329,15 +4329,14 @@ 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) test_clear_rtv_r8g8b8a8_2d_(__LINE__, a, b, c, d, e, f, g)
+#define test_clear_rtv_r8g8b8a8_2d(a, b, c, d, e, f) test_clear_rtv_r8g8b8a8_2d_(__LINE__, a, b, c, d, e, f)
static void test_clear_rtv_r8g8b8a8_2d_(unsigned int line, const struct test_context *context,
ID3D12Resource *resource, D3D12_CPU_DESCRIPTOR_HANDLE rtv_handle,
- const float *color, unsigned int expected, unsigned int max_diff, bool is_todo)
+ const float *color, unsigned int expected, unsigned int max_diff)
{
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_uint_(line, resource, 0, context->queue, context->list, expected, max_diff);
reset_command_list(context->list, context->allocator);
@@ -4345,16 +4344,14 @@ 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)
+#define test_clear_rtv_r16g16b16a16_2d(a, b, c, d, e) test_clear_rtv_r16g16b16a16_2d_(__LINE__, a, b, c, d, e)
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)
+ ID3D12Resource *resource, D3D12_CPU_DESCRIPTOR_HANDLE rtv_handle, const float *color, uint64_t expected)
{
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);
+ check_sub_resource_uint64_(line, resource, 0, context->queue, context->list, expected, 0);
reset_command_list(context->list, context->allocator);
transition_resource_state(context->list, resource,
@@ -4395,7 +4392,6 @@ static void test_clear_render_target_view(void)
const float *color;
unsigned int expected;
unsigned int max_diff;
- bool is_todo;
}
test_r8g8b8a8_unorm[] =
{
@@ -4404,21 +4400,20 @@ static void test_clear_render_target_view(void)
},
test_r8g8b8a8_uint[] =
{
- {green, 0x01000100, 0, true},
- {color, 0x00000000, 0, true},
- {negative_value, 0x00000001, 0, true},
+ {green, 0x01000100, 0},
+ {color, 0x00000000, 0},
+ {negative_value, 0x00000001, 0},
},
test_r8g8b8a8_sint[] =
{
- {green, 0x01000100, 0, true},
- {color, 0x00000000, 0, true},
- {negative_value, 0xfe00ff01, 0, true},
+ {green, 0x01000100, 0},
+ {color, 0x00000000, 0},
+ {negative_value, 0xfe00ff01, 0},
};
static const struct
{
const float *color;
uint64_t expected;
- bool is_todo;
}
test_r16g16b16a16_unorm[] =
{
@@ -4426,15 +4421,15 @@ static void test_clear_render_target_view(void)
},
test_r16g16b16a16_uint[] =
{
- {green, 0x0010000, true},
- {color, 0x00000000, true},
- {negative_value, 0x00000001, true},
+ {green, 0x0010000},
+ {color, 0x00000000},
+ {negative_value, 0x00000001},
},
test_r16g16b16a16_sint[] =
{
- {green, 0x0010000, true},
- {color, 0x00000000, true},
- {negative_value, 0xfffe0000ffff0001, true},
+ {green, 0x0010000},
+ {color, 0x00000000},
+ {negative_value, 0xfffe0000ffff0001},
};
STATIC_ASSERT(ARRAY_SIZE(array_colors) == ARRAY_SIZE(array_expected_colors));
@@ -4487,14 +4482,14 @@ static void test_clear_render_target_view(void)
{
vkd3d_test_set_context("Test %u", i);
test_clear_rtv_r8g8b8a8_2d(&context, resource, rtv_handle, test_r8g8b8a8_unorm[i].color,
- test_r8g8b8a8_unorm[i].expected, test_r8g8b8a8_unorm[i].max_diff, test_r8g8b8a8_unorm[i].is_todo);
+ test_r8g8b8a8_unorm[i].expected, test_r8g8b8a8_unorm[i].max_diff);
}
vkd3d_test_set_context(NULL);
/* sRGB view */
rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
ID3D12Device_CreateRenderTargetView(device, resource, &rtv_desc, rtv_handle);
- test_clear_rtv_r8g8b8a8_2d(&context, resource, rtv_handle, color, 0xbf95bc59, 2, false);
+ test_clear_rtv_r8g8b8a8_2d(&context, resource, rtv_handle, color, 0xbf95bc59, 2);
/* DXGI_FORMAT_R8G8B8A8_UINT view */
rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UINT;
@@ -4503,7 +4498,7 @@ static void test_clear_render_target_view(void)
{
vkd3d_test_set_context("Test %u", i);
test_clear_rtv_r8g8b8a8_2d(&context, resource, rtv_handle, test_r8g8b8a8_uint[i].color,
- test_r8g8b8a8_uint[i].expected, test_r8g8b8a8_uint[i].max_diff, test_r8g8b8a8_uint[i].is_todo);
+ test_r8g8b8a8_uint[i].expected, test_r8g8b8a8_uint[i].max_diff);
}
vkd3d_test_set_context(NULL);
@@ -4514,7 +4509,7 @@ static void test_clear_render_target_view(void)
{
vkd3d_test_set_context("Test %u", i);
test_clear_rtv_r8g8b8a8_2d(&context, resource, rtv_handle, test_r8g8b8a8_sint[i].color,
- test_r8g8b8a8_sint[i].expected, test_r8g8b8a8_sint[i].max_diff, test_r8g8b8a8_sint[i].is_todo);
+ test_r8g8b8a8_sint[i].expected, test_r8g8b8a8_sint[i].max_diff);
}
vkd3d_test_set_context(NULL);
@@ -4537,8 +4532,8 @@ static void test_clear_render_target_view(void)
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);
+ test_clear_rtv_r16g16b16a16_2d(&context, resource, rtv_handle,
+ test_r16g16b16a16_unorm[i].color, test_r16g16b16a16_unorm[i].expected);
}
vkd3d_test_set_context(NULL);
@@ -4548,8 +4543,8 @@ static void test_clear_render_target_view(void)
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);
+ test_clear_rtv_r16g16b16a16_2d(&context, resource, rtv_handle,
+ test_r16g16b16a16_uint[i].color, test_r16g16b16a16_uint[i].expected);
}
vkd3d_test_set_context(NULL);
@@ -4559,8 +4554,8 @@ static void test_clear_render_target_view(void)
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);
+ test_clear_rtv_r16g16b16a16_2d(&context, resource, rtv_handle,
+ test_r16g16b16a16_sint[i].color, test_r16g16b16a16_sint[i].expected);
}
vkd3d_test_set_context(NULL);
--
2.21.0
More information about the wine-devel
mailing list