From c75f9ee39dffc0c319c067e2bde047d1f8af5359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zef=20Kucia?= Date: Tue, 28 Aug 2018 12:19:55 +0200 Subject: [PATCH] vkd3d: Export vkd3d_get_dxgi_format() function. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Józef Kucia Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- include/vkd3d.h | 1 + libs/vkd3d/utils.c | 18 +++++++++++++ libs/vkd3d/vkd3d.map | 1 + tests/vkd3d_api.c | 64 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+) diff --git a/include/vkd3d.h b/include/vkd3d.h index fcff1668..de805420 100644 --- a/include/vkd3d.h +++ b/include/vkd3d.h @@ -144,6 +144,7 @@ HRESULT vkd3d_serialize_root_signature(const D3D12_ROOT_SIGNATURE_DESC *desc, HRESULT vkd3d_create_root_signature_deserializer(const void *data, SIZE_T data_size, REFIID iid, void **deserializer); +DXGI_FORMAT vkd3d_get_dxgi_format(VkFormat format); VkFormat vkd3d_get_vk_format(DXGI_FORMAT format); #endif /* VKD3D_NO_PROTOTYPES */ diff --git a/libs/vkd3d/utils.c b/libs/vkd3d/utils.c index 11c46dd4..682822e8 100644 --- a/libs/vkd3d/utils.c +++ b/libs/vkd3d/utils.c @@ -200,6 +200,24 @@ bool dxgi_format_is_typeless(DXGI_FORMAT dxgi_format) } } +DXGI_FORMAT vkd3d_get_dxgi_format(VkFormat format) +{ + DXGI_FORMAT dxgi_format; + VkFormat vk_format; + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(vkd3d_formats); ++i) + { + vk_format = vkd3d_formats[i].vk_format; + dxgi_format = vkd3d_formats[i].dxgi_format; + if (vk_format == format && !dxgi_format_is_typeless(dxgi_format)) + return dxgi_format; + } + + FIXME("Unhandled Vulkan format %#x.\n", format); + return DXGI_FORMAT_UNKNOWN; +} + bool is_valid_feature_level(D3D_FEATURE_LEVEL feature_level) { static const D3D_FEATURE_LEVEL valid_feature_levels[] = diff --git a/libs/vkd3d/vkd3d.map b/libs/vkd3d/vkd3d.map index 7d0f8388..f43c85c1 100644 --- a/libs/vkd3d/vkd3d.map +++ b/libs/vkd3d/vkd3d.map @@ -7,6 +7,7 @@ global: vkd3d_create_instance; vkd3d_create_root_signature_deserializer; vkd3d_get_device_parent; + vkd3d_get_dxgi_format; vkd3d_get_vk_device; vkd3d_get_vk_format; vkd3d_get_vk_physical_device; diff --git a/tests/vkd3d_api.c b/tests/vkd3d_api.c index 2c022ba1..e0912c54 100644 --- a/tests/vkd3d_api.c +++ b/tests/vkd3d_api.c @@ -899,6 +899,69 @@ static void test_vulkan_resource_present_state(void) destroy_test_context(&context); } +static void test_formats(void) +{ + DXGI_FORMAT dxgi_format, format; + VkFormat vk_format; + unsigned int i; + + static const DXGI_FORMAT formats[] = + { + DXGI_FORMAT_R32G32B32A32_FLOAT, + DXGI_FORMAT_R32G32B32A32_UINT, + DXGI_FORMAT_R32G32B32A32_SINT, + DXGI_FORMAT_R32G32B32_FLOAT, + DXGI_FORMAT_R32G32B32_UINT, + DXGI_FORMAT_R32G32B32_SINT, + DXGI_FORMAT_R16G16B16A16_FLOAT, + DXGI_FORMAT_R16G16B16A16_UNORM, + DXGI_FORMAT_R16G16B16A16_UINT, + DXGI_FORMAT_R16G16B16A16_SNORM, + DXGI_FORMAT_R16G16B16A16_SINT, + DXGI_FORMAT_R32G32_FLOAT, + DXGI_FORMAT_R32G32_UINT, + DXGI_FORMAT_R32G32_SINT, + DXGI_FORMAT_R10G10B10A2_UNORM, + DXGI_FORMAT_R11G11B10_FLOAT, + DXGI_FORMAT_R8G8B8A8_UNORM, + DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, + DXGI_FORMAT_R8G8B8A8_UINT, + DXGI_FORMAT_R8G8B8A8_SNORM, + DXGI_FORMAT_R8G8B8A8_SINT, + DXGI_FORMAT_R16G16_FLOAT, + DXGI_FORMAT_R16G16_UNORM, + DXGI_FORMAT_R16G16_UINT, + DXGI_FORMAT_R16G16_SNORM, + DXGI_FORMAT_R16G16_SINT, + DXGI_FORMAT_D32_FLOAT, + DXGI_FORMAT_R32_FLOAT, + DXGI_FORMAT_R32_UINT, + DXGI_FORMAT_R32_SINT, + DXGI_FORMAT_R8G8_UNORM, + DXGI_FORMAT_R8G8_UINT, + DXGI_FORMAT_R8G8_SNORM, + DXGI_FORMAT_R8G8_SINT, + DXGI_FORMAT_R16_FLOAT, + DXGI_FORMAT_D16_UNORM, + DXGI_FORMAT_R16_UNORM, + DXGI_FORMAT_R16_UINT, + DXGI_FORMAT_R16_SNORM, + DXGI_FORMAT_R16_SINT, + DXGI_FORMAT_R8_UNORM, + DXGI_FORMAT_R8_UINT, + DXGI_FORMAT_R8_SNORM, + DXGI_FORMAT_R8_SINT, + }; + + for (i = 0; i < ARRAY_SIZE(formats); ++i) + { + format = formats[i]; + vk_format = vkd3d_get_vk_format(format); + dxgi_format = vkd3d_get_dxgi_format(vk_format); + ok(dxgi_format == format, "Got format %#x, expected %#x.\n", dxgi_format, format); + } +} + static bool have_d3d12_device(void) { ID3D12Device *device; @@ -927,4 +990,5 @@ START_TEST(vkd3d_api) run_test(test_vkd3d_queue); run_test(test_resource_internal_refcount); run_test(test_vulkan_resource_present_state); + run_test(test_formats); }