From: Jactry Zeng jzeng@codeweavers.com
Signed-off-by: Jactry Zeng jzeng@codeweavers.com Signed-off-by: Józef Kucia jkucia@codeweavers.com ---
Version 3: Store format type in vkd3d_format.
--- libs/vkd3d/command.c | 24 +++++++++++++++++++- libs/vkd3d/utils.c | 46 +++++++++++++++++++++----------------- libs/vkd3d/vkd3d_private.h | 8 +++++++ tests/d3d12.c | 11 +++++---- 4 files changed, 61 insertions(+), 28 deletions(-)
diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c index 30b4ae344df8..379cd7d10274 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 (rtv_desc->format->type == VKD3D_FORMAT_TYPE_UINT) + { + 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 if (rtv_desc->format->type == VKD3D_FORMAT_TYPE_SINT) + { + clear_value.color.int32[0] = color[0]; + clear_value.color.int32[1] = color[1]; + clear_value.color.int32[2] = color[2]; + clear_value.color.int32[3] = 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..816ec5e16e03 100644 --- a/libs/vkd3d/utils.c +++ b/libs/vkd3d/utils.c @@ -24,64 +24,66 @@ #define DEPTH (VK_IMAGE_ASPECT_DEPTH_BIT) #define STENCIL (VK_IMAGE_ASPECT_STENCIL_BIT) #define DEPTH_STENCIL (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT) +#define SINT VKD3D_FORMAT_TYPE_SINT +#define UINT VKD3D_FORMAT_TYPE_UINT static const struct vkd3d_format vkd3d_formats[] = { {DXGI_FORMAT_R32G32B32A32_TYPELESS, VK_FORMAT_R32G32B32A32_SFLOAT, 16, 1, 1, 1, COLOR, 1}, {DXGI_FORMAT_R32G32B32A32_FLOAT, VK_FORMAT_R32G32B32A32_SFLOAT, 16, 1, 1, 1, COLOR, 1}, - {DXGI_FORMAT_R32G32B32A32_UINT, VK_FORMAT_R32G32B32A32_UINT, 16, 1, 1, 1, COLOR, 1}, - {DXGI_FORMAT_R32G32B32A32_SINT, VK_FORMAT_R32G32B32A32_SINT, 16, 1, 1, 1, COLOR, 1}, + {DXGI_FORMAT_R32G32B32A32_UINT, VK_FORMAT_R32G32B32A32_UINT, 16, 1, 1, 1, COLOR, 1, UINT}, + {DXGI_FORMAT_R32G32B32A32_SINT, VK_FORMAT_R32G32B32A32_SINT, 16, 1, 1, 1, COLOR, 1, SINT}, {DXGI_FORMAT_R32G32B32_TYPELESS, VK_FORMAT_R32G32B32_SFLOAT, 12, 1, 1, 1, COLOR, 1}, {DXGI_FORMAT_R32G32B32_FLOAT, VK_FORMAT_R32G32B32_SFLOAT, 12, 1, 1, 1, COLOR, 1}, - {DXGI_FORMAT_R32G32B32_UINT, VK_FORMAT_R32G32B32_UINT, 12, 1, 1, 1, COLOR, 1}, - {DXGI_FORMAT_R32G32B32_SINT, VK_FORMAT_R32G32B32_SINT, 12, 1, 1, 1, COLOR, 1}, + {DXGI_FORMAT_R32G32B32_UINT, VK_FORMAT_R32G32B32_UINT, 12, 1, 1, 1, COLOR, 1, UINT}, + {DXGI_FORMAT_R32G32B32_SINT, VK_FORMAT_R32G32B32_SINT, 12, 1, 1, 1, COLOR, 1, SINT}, {DXGI_FORMAT_R16G16B16A16_TYPELESS, VK_FORMAT_R16G16B16A16_SFLOAT, 8, 1, 1, 1, COLOR, 1}, {DXGI_FORMAT_R16G16B16A16_FLOAT, VK_FORMAT_R16G16B16A16_SFLOAT, 8, 1, 1, 1, COLOR, 1}, {DXGI_FORMAT_R16G16B16A16_UNORM, VK_FORMAT_R16G16B16A16_UNORM, 8, 1, 1, 1, COLOR, 1}, - {DXGI_FORMAT_R16G16B16A16_UINT, VK_FORMAT_R16G16B16A16_UINT, 8, 1, 1, 1, COLOR, 1}, + {DXGI_FORMAT_R16G16B16A16_UINT, VK_FORMAT_R16G16B16A16_UINT, 8, 1, 1, 1, COLOR, 1, UINT}, {DXGI_FORMAT_R16G16B16A16_SNORM, VK_FORMAT_R16G16B16A16_SNORM, 8, 1, 1, 1, COLOR, 1}, - {DXGI_FORMAT_R16G16B16A16_SINT, VK_FORMAT_R16G16B16A16_SINT, 8, 1, 1, 1, COLOR, 1}, + {DXGI_FORMAT_R16G16B16A16_SINT, VK_FORMAT_R16G16B16A16_SINT, 8, 1, 1, 1, COLOR, 1, SINT}, {DXGI_FORMAT_R32G32_TYPELESS, VK_FORMAT_R32G32_SFLOAT, 8, 1, 1, 1, COLOR, 1}, {DXGI_FORMAT_R32G32_FLOAT, VK_FORMAT_R32G32_SFLOAT, 8, 1, 1, 1, COLOR, 1}, - {DXGI_FORMAT_R32G32_UINT, VK_FORMAT_R32G32_UINT, 8, 1, 1, 1, COLOR, 1}, - {DXGI_FORMAT_R32G32_SINT, VK_FORMAT_R32G32_SINT, 8, 1, 1, 1, COLOR, 1}, + {DXGI_FORMAT_R32G32_UINT, VK_FORMAT_R32G32_UINT, 8, 1, 1, 1, COLOR, 1, UINT}, + {DXGI_FORMAT_R32G32_SINT, VK_FORMAT_R32G32_SINT, 8, 1, 1, 1, COLOR, 1, SINT}, {DXGI_FORMAT_R10G10B10A2_TYPELESS, VK_FORMAT_A2B10G10R10_UNORM_PACK32, 4, 1, 1, 1, COLOR, 1}, {DXGI_FORMAT_R10G10B10A2_UNORM, VK_FORMAT_A2B10G10R10_UNORM_PACK32, 4, 1, 1, 1, COLOR, 1}, - {DXGI_FORMAT_R10G10B10A2_UINT, VK_FORMAT_A2B10G10R10_UINT_PACK32, 4, 1, 1, 1, COLOR, 1}, + {DXGI_FORMAT_R10G10B10A2_UINT, VK_FORMAT_A2B10G10R10_UINT_PACK32, 4, 1, 1, 1, COLOR, 1, UINT}, {DXGI_FORMAT_R11G11B10_FLOAT, VK_FORMAT_B10G11R11_UFLOAT_PACK32, 4, 1, 1, 1, COLOR, 1}, {DXGI_FORMAT_R8G8_TYPELESS, VK_FORMAT_R8G8_UNORM, 2, 1, 1, 1, COLOR, 1}, {DXGI_FORMAT_R8G8_UNORM, VK_FORMAT_R8G8_UNORM, 2, 1, 1, 1, COLOR, 1}, - {DXGI_FORMAT_R8G8_UINT, VK_FORMAT_R8G8_UINT, 2, 1, 1, 1, COLOR, 1}, + {DXGI_FORMAT_R8G8_UINT, VK_FORMAT_R8G8_UINT, 2, 1, 1, 1, COLOR, 1, UINT}, {DXGI_FORMAT_R8G8_SNORM, VK_FORMAT_R8G8_SNORM, 2, 1, 1, 1, COLOR, 1}, - {DXGI_FORMAT_R8G8_SINT, VK_FORMAT_R8G8_SINT, 2, 1, 1, 1, COLOR, 1}, + {DXGI_FORMAT_R8G8_SINT, VK_FORMAT_R8G8_SINT, 2, 1, 1, 1, COLOR, 1, SINT}, {DXGI_FORMAT_R8G8B8A8_TYPELESS, VK_FORMAT_R8G8B8A8_UNORM, 4, 1, 1, 1, COLOR, 1}, {DXGI_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_R8G8B8A8_UNORM, 4, 1, 1, 1, COLOR, 1}, {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, VK_FORMAT_R8G8B8A8_SRGB, 4, 1, 1, 1, COLOR, 1}, - {DXGI_FORMAT_R8G8B8A8_UINT, VK_FORMAT_R8G8B8A8_UINT, 4, 1, 1, 1, COLOR, 1}, + {DXGI_FORMAT_R8G8B8A8_UINT, VK_FORMAT_R8G8B8A8_UINT, 4, 1, 1, 1, COLOR, 1, UINT}, {DXGI_FORMAT_R8G8B8A8_SNORM, VK_FORMAT_R8G8B8A8_SNORM, 4, 1, 1, 1, COLOR, 1}, - {DXGI_FORMAT_R8G8B8A8_SINT, VK_FORMAT_R8G8B8A8_SINT, 4, 1, 1, 1, COLOR, 1}, + {DXGI_FORMAT_R8G8B8A8_SINT, VK_FORMAT_R8G8B8A8_SINT, 4, 1, 1, 1, COLOR, 1, SINT}, {DXGI_FORMAT_R16G16_TYPELESS, VK_FORMAT_R16G16_SFLOAT, 4, 1, 1, 1, COLOR, 1}, {DXGI_FORMAT_R16G16_FLOAT, VK_FORMAT_R16G16_SFLOAT, 4, 1, 1, 1, COLOR, 1}, {DXGI_FORMAT_R16G16_UNORM, VK_FORMAT_R16G16_UNORM, 4, 1, 1, 1, COLOR, 1}, - {DXGI_FORMAT_R16G16_UINT, VK_FORMAT_R16G16_UINT, 4, 1, 1, 1, COLOR, 1}, + {DXGI_FORMAT_R16G16_UINT, VK_FORMAT_R16G16_UINT, 4, 1, 1, 1, COLOR, 1, UINT}, {DXGI_FORMAT_R16G16_SNORM, VK_FORMAT_R16G16_SNORM, 4, 1, 1, 1, COLOR, 1}, - {DXGI_FORMAT_R16G16_SINT, VK_FORMAT_R16G16_SINT, 4, 1, 1, 1, COLOR, 1}, + {DXGI_FORMAT_R16G16_SINT, VK_FORMAT_R16G16_SINT, 4, 1, 1, 1, COLOR, 1, SINT}, {DXGI_FORMAT_R32_TYPELESS, VK_FORMAT_R32_UINT, 4, 1, 1, 1, COLOR, 1}, {DXGI_FORMAT_D32_FLOAT, VK_FORMAT_D32_SFLOAT, 4, 1, 1, 1, DEPTH, 1}, {DXGI_FORMAT_R32_FLOAT, VK_FORMAT_R32_SFLOAT, 4, 1, 1, 1, COLOR, 1}, - {DXGI_FORMAT_R32_UINT, VK_FORMAT_R32_UINT, 4, 1, 1, 1, COLOR, 1}, - {DXGI_FORMAT_R32_SINT, VK_FORMAT_R32_SINT, 4, 1, 1, 1, COLOR, 1}, + {DXGI_FORMAT_R32_UINT, VK_FORMAT_R32_UINT, 4, 1, 1, 1, COLOR, 1, UINT}, + {DXGI_FORMAT_R32_SINT, VK_FORMAT_R32_SINT, 4, 1, 1, 1, COLOR, 1, SINT}, {DXGI_FORMAT_R16_TYPELESS, VK_FORMAT_R16_UINT, 2, 1, 1, 1, COLOR, 1}, {DXGI_FORMAT_R16_FLOAT, VK_FORMAT_R16_SFLOAT, 2, 1, 1, 1, COLOR, 1}, {DXGI_FORMAT_D16_UNORM, VK_FORMAT_D16_UNORM, 2, 1, 1, 1, DEPTH, 1}, {DXGI_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM, 2, 1, 1, 1, COLOR, 1}, - {DXGI_FORMAT_R16_UINT, VK_FORMAT_R16_UINT, 2, 1, 1, 1, COLOR, 1}, + {DXGI_FORMAT_R16_UINT, VK_FORMAT_R16_UINT, 2, 1, 1, 1, COLOR, 1, UINT}, {DXGI_FORMAT_R16_SNORM, VK_FORMAT_R16_SNORM, 2, 1, 1, 1, COLOR, 1}, - {DXGI_FORMAT_R16_SINT, VK_FORMAT_R16_SINT, 2, 1, 1, 1, COLOR, 1}, + {DXGI_FORMAT_R16_SINT, VK_FORMAT_R16_SINT, 2, 1, 1, 1, COLOR, 1, SINT}, {DXGI_FORMAT_R8_TYPELESS, VK_FORMAT_R8_UNORM, 1, 1, 1, 1, COLOR, 1}, {DXGI_FORMAT_R8_UNORM, VK_FORMAT_R8_UNORM, 1, 1, 1, 1, COLOR, 1}, - {DXGI_FORMAT_R8_UINT, VK_FORMAT_R8_UINT, 1, 1, 1, 1, COLOR, 1}, + {DXGI_FORMAT_R8_UINT, VK_FORMAT_R8_UINT, 1, 1, 1, 1, COLOR, 1, UINT}, {DXGI_FORMAT_R8_SNORM, VK_FORMAT_R8_SNORM, 1, 1, 1, 1, COLOR, 1}, - {DXGI_FORMAT_R8_SINT, VK_FORMAT_R8_SINT, 1, 1, 1, 1, COLOR, 1}, + {DXGI_FORMAT_R8_SINT, VK_FORMAT_R8_SINT, 1, 1, 1, 1, COLOR, 1, SINT}, {DXGI_FORMAT_A8_UNORM, VK_FORMAT_R8_UNORM, 1, 1, 1, 1, COLOR, 1}, {DXGI_FORMAT_B8G8R8A8_UNORM, VK_FORMAT_B8G8R8A8_UNORM, 4, 1, 1, 1, COLOR, 1}, {DXGI_FORMAT_B8G8R8X8_UNORM, VK_FORMAT_B8G8R8A8_UNORM, 4, 1, 1, 1, COLOR, 1}, @@ -132,6 +134,8 @@ static const struct vkd3d_format vkd3d_depth_stencil_formats[] = #undef DEPTH #undef STENCIL #undef DEPTH_STENCIL +#undef SINT +#undef UINT
HRESULT vkd3d_init_depth_stencil_formats(struct d3d12_device *device) { diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index fe939e548258..20f16ea3ad7e 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -1098,6 +1098,13 @@ static inline unsigned int d3d12_device_get_descriptor_handle_increment_size(str }
/* utils */ +enum vkd3d_format_type +{ + VKD3D_FORMAT_TYPE_OTHER, + VKD3D_FORMAT_TYPE_SINT, + VKD3D_FORMAT_TYPE_UINT, +}; + struct vkd3d_format { DXGI_FORMAT dxgi_format; @@ -1108,6 +1115,7 @@ struct vkd3d_format size_t block_byte_count; VkImageAspectFlags vk_aspect_mask; unsigned int plane_count; + enum vkd3d_format_type type; bool is_emulated; };
diff --git a/tests/d3d12.c b/tests/d3d12.c index aa09295466b9..151fb6bad913 100644 --- a/tests/d3d12.c +++ b/tests/d3d12.c @@ -4346,8 +4346,7 @@ static void test_clear_rtv_r8g8b8a8_2d_(unsigned int line, const struct test_con
#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) + 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, @@ -4483,7 +4482,7 @@ static void test_clear_render_target_view(void) for (i = 0; i < ARRAY_SIZE(test_r8g8b8a8); ++i) { vkd3d_test_set_context("Test %u", i); - todo test_clear_rtv_r8g8b8a8_2d(&context, resource, rtv_handle, + test_clear_rtv_r8g8b8a8_2d(&context, resource, rtv_handle, test_r8g8b8a8[i].color, test_r8g8b8a8[i].uint_result, 0); } vkd3d_test_set_context(NULL); @@ -4494,7 +4493,7 @@ static void test_clear_render_target_view(void) for (i = 0; i < ARRAY_SIZE(test_r8g8b8a8); ++i) { vkd3d_test_set_context("Test %u", i); - todo test_clear_rtv_r8g8b8a8_2d(&context, resource, rtv_handle, + test_clear_rtv_r8g8b8a8_2d(&context, resource, rtv_handle, test_r8g8b8a8[i].color, test_r8g8b8a8[i].sint_result, 0); } vkd3d_test_set_context(NULL); @@ -4532,7 +4531,7 @@ static void test_clear_render_target_view(void) for (i = 0; i < ARRAY_SIZE(test_r16g16b16a16); ++i) { vkd3d_test_set_context("Test %u", i); - todo test_clear_rtv_r16g16b16a16_2d(&context, resource, rtv_handle, + test_clear_rtv_r16g16b16a16_2d(&context, resource, rtv_handle, test_r16g16b16a16[i].color, test_r16g16b16a16[i].uint_result); } vkd3d_test_set_context(NULL); @@ -4543,7 +4542,7 @@ static void test_clear_render_target_view(void) for (i = 0; i < ARRAY_SIZE(test_r16g16b16a16); ++i) { vkd3d_test_set_context("Test %u", i); - todo test_clear_rtv_r16g16b16a16_2d(&context, resource, rtv_handle, + test_clear_rtv_r16g16b16a16_2d(&context, resource, rtv_handle, test_r16g16b16a16[i].color, test_r16g16b16a16[i].sint_result); } vkd3d_test_set_context(NULL);