From 3777eb4e5c02a3a165520642fae4f38341f4e28c Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Tue, 30 Jun 2020 15:02:04 +0430 Subject: [PATCH] vkd3d: Introduce API versions. For backwards compatibility. Newer vkd3d versions may report more capabilities, but some of those may also require newer vkd3d APIs in order to use them. That's an issue for a vkd3d user like Wine, where reporting more capabilities may cause the application to try to use APIs that are not implemented in that version of Wine. Note that using ELF symbol versioning would have solved the issue for existing binaries compiled against older versions of vkd3d, but not for older source compiled against newer versions of vkd3d. Users of vkd3d-utils should define VKD3D_UTILS_API_VERSION to the vkd3d API version they wish to target. Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- demos/demo_xcb.h | 1 + include/vkd3d.h | 9 +++++++++ include/vkd3d_utils.h | 8 +++++++- libs/vkd3d-utils/vkd3d_utils.map | 1 + libs/vkd3d-utils/vkd3d_utils_main.c | 21 +++++++++++++++++---- libs/vkd3d/device.c | 8 +++++++- libs/vkd3d/vkd3d_private.h | 1 + tests/d3d12_crosstest.h | 1 + tests/vkd3d_api.c | 8 ++++++++ 9 files changed, 52 insertions(+), 6 deletions(-) diff --git a/demos/demo_xcb.h b/demos/demo_xcb.h index 6fae7909..6ce02ed5 100644 --- a/demos/demo_xcb.h +++ b/demos/demo_xcb.h @@ -18,6 +18,7 @@ */ #define VK_USE_PLATFORM_XCB_KHR +#define VKD3D_UTILS_API_VERSION VKD3D_API_VERSION_1_2 #include #include #include diff --git a/include/vkd3d.h b/include/vkd3d.h index e2d9ec81..0ef81053 100644 --- a/include/vkd3d.h +++ b/include/vkd3d.h @@ -51,6 +51,13 @@ enum vkd3d_structure_type VKD3D_FORCE_32_BIT_ENUM(VKD3D_STRUCTURE_TYPE), }; +enum vkd3d_api_version +{ + VKD3D_API_VERSION_1_0, + VKD3D_API_VERSION_1_1, + VKD3D_API_VERSION_1_2, +}; + typedef HRESULT (*PFN_vkd3d_signal_event)(HANDLE event); typedef void * (*PFN_vkd3d_thread)(void *data); @@ -98,6 +105,8 @@ struct vkd3d_application_info const char *engine_name; /* "vkd3d" if NULL */ uint32_t engine_version; /* vkd3d version if engine_name is NULL */ + + enum vkd3d_api_version api_version; }; struct vkd3d_device_create_info diff --git a/include/vkd3d_utils.h b/include/vkd3d_utils.h index 4a5ee5dd..02687ed6 100644 --- a/include/vkd3d_utils.h +++ b/include/vkd3d_utils.h @@ -21,6 +21,10 @@ #include +#ifndef VKD3D_UTILS_API_VERSION +#define VKD3D_UTILS_API_VERSION VKD3D_API_VERSION_1_0 +#endif + #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ @@ -36,13 +40,15 @@ HRESULT vkd3d_signal_event(HANDLE event); unsigned int vkd3d_wait_event(HANDLE event, unsigned int milliseconds); void vkd3d_destroy_event(HANDLE event); -HRESULT WINAPI D3D12CreateDevice(IUnknown *adapter, D3D_FEATURE_LEVEL feature_level, REFIID iid, void **device); +#define D3D12CreateDevice(a, b, c, d) D3D12CreateDeviceVKD3D(a, b, c, d, VKD3D_UTILS_API_VERSION) HRESULT WINAPI D3D12CreateRootSignatureDeserializer(const void *data, SIZE_T data_size, REFIID iid, void **deserializer); HRESULT WINAPI D3D12GetDebugInterface(REFIID iid, void **debug); HRESULT WINAPI D3D12SerializeRootSignature(const D3D12_ROOT_SIGNATURE_DESC *desc, D3D_ROOT_SIGNATURE_VERSION version, ID3DBlob **blob, ID3DBlob **error_blob); /* 1.2 */ +HRESULT WINAPI D3D12CreateDeviceVKD3D(IUnknown *adapter, D3D_FEATURE_LEVEL feature_level, + REFIID iid, void **device, enum vkd3d_api_version api_version); HRESULT WINAPI D3D12CreateVersionedRootSignatureDeserializer(const void *data, SIZE_T data_size, REFIID iid, void **deserializer); HRESULT WINAPI D3D12SerializeVersionedRootSignature(const D3D12_VERSIONED_ROOT_SIGNATURE_DESC *desc, diff --git a/libs/vkd3d-utils/vkd3d_utils.map b/libs/vkd3d-utils/vkd3d_utils.map index 9d95a841..fb391240 100644 --- a/libs/vkd3d-utils/vkd3d_utils.map +++ b/libs/vkd3d-utils/vkd3d_utils.map @@ -2,6 +2,7 @@ VKD3D_1_0 { global: D3D12CreateDevice; + D3D12CreateDeviceVKD3D; D3D12CreateRootSignatureDeserializer; D3D12CreateVersionedRootSignatureDeserializer; D3D12GetDebugInterface; diff --git a/libs/vkd3d-utils/vkd3d_utils_main.c b/libs/vkd3d-utils/vkd3d_utils_main.c index d06a7503..c19fe7f1 100644 --- a/libs/vkd3d-utils/vkd3d_utils_main.c +++ b/libs/vkd3d-utils/vkd3d_utils_main.c @@ -17,6 +17,7 @@ */ #include "vkd3d_utils_private.h" +#undef D3D12CreateDevice VKD3D_DEBUG_ENV_NAME("VKD3D_DEBUG"); @@ -27,8 +28,8 @@ HRESULT WINAPI D3D12GetDebugInterface(REFIID iid, void **debug) return E_NOTIMPL; } -HRESULT WINAPI D3D12CreateDevice(IUnknown *adapter, - D3D_FEATURE_LEVEL minimum_feature_level, REFIID iid, void **device) +HRESULT WINAPI D3D12CreateDeviceVKD3D(IUnknown *adapter, D3D_FEATURE_LEVEL minimum_feature_level, + REFIID iid, void **device, enum vkd3d_api_version api_version) { struct vkd3d_optional_instance_extensions_info optional_extensions_info; struct vkd3d_instance_create_info instance_create_info; @@ -47,15 +48,21 @@ HRESULT WINAPI D3D12CreateDevice(IUnknown *adapter, { VK_KHR_SWAPCHAIN_EXTENSION_NAME, }; + struct vkd3d_application_info application_info = + { + .type = VKD3D_STRUCTURE_TYPE_APPLICATION_INFO, + .api_version = api_version, + }; - TRACE("adapter %p, minimum_feature_level %#x, iid %s, device %p.\n", - adapter, minimum_feature_level, debugstr_guid(iid), device); + TRACE("adapter %p, minimum_feature_level %#x, iid %s, device %p, api_version %#x.\n", + adapter, minimum_feature_level, debugstr_guid(iid), device, api_version); if (adapter) FIXME("Ignoring adapter %p.\n", adapter); memset(&optional_extensions_info, 0, sizeof(optional_extensions_info)); optional_extensions_info.type = VKD3D_STRUCTURE_TYPE_OPTIONAL_INSTANCE_EXTENSIONS_INFO; + optional_extensions_info.next = &application_info; optional_extensions_info.extensions = optional_instance_extensions; optional_extensions_info.extension_count = ARRAY_SIZE(optional_instance_extensions); @@ -78,6 +85,12 @@ HRESULT WINAPI D3D12CreateDevice(IUnknown *adapter, return vkd3d_create_device(&device_create_info, iid, device); } +HRESULT WINAPI D3D12CreateDevice(IUnknown *adapter, + D3D_FEATURE_LEVEL minimum_feature_level, REFIID iid, void **device) +{ + return D3D12CreateDeviceVKD3D(adapter, minimum_feature_level, iid, device, VKD3D_API_VERSION_1_0); +} + HRESULT WINAPI D3D12CreateRootSignatureDeserializer(const void *data, SIZE_T data_size, REFIID iid, void **deserializer) { diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c index 437454da..c53856ac 100644 --- a/libs/vkd3d/device.c +++ b/libs/vkd3d/device.c @@ -506,16 +506,21 @@ static HRESULT vkd3d_instance_init(struct vkd3d_instance *instance, application_info.pEngineName = PACKAGE_NAME; application_info.engineVersion = vkd3d_get_vk_version(); application_info.apiVersion = VK_API_VERSION_1_0; + instance->api_version = VKD3D_API_VERSION_1_0; if ((vkd3d_application_info = vkd3d_find_struct(create_info->next, APPLICATION_INFO))) { - application_info.pApplicationName = vkd3d_application_info->application_name; + if (vkd3d_application_info->application_name) + application_info.pApplicationName = vkd3d_application_info->application_name; + else if (vkd3d_get_program_name(application_name)) + application_info.pApplicationName = application_name; application_info.applicationVersion = vkd3d_application_info->application_version; if (vkd3d_application_info->engine_name) { application_info.pEngineName = vkd3d_application_info->engine_name; application_info.engineVersion = vkd3d_application_info->engine_version; } + instance->api_version = vkd3d_application_info->api_version; } else if (vkd3d_get_program_name(application_name)) { @@ -523,6 +528,7 @@ static HRESULT vkd3d_instance_init(struct vkd3d_instance *instance, } TRACE("Application: %s.\n", debugstr_a(application_info.pApplicationName)); + TRACE("vkd3d API version: %u.\n", instance->api_version); if (!(extensions = vkd3d_calloc(extension_count, sizeof(*extensions)))) { diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index 97cae22e..1c36b244 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -147,6 +147,7 @@ struct vkd3d_instance void *libvulkan; uint64_t config_flags; + enum vkd3d_api_version api_version; VkDebugReportCallbackEXT vk_debug_callback; diff --git a/tests/d3d12_crosstest.h b/tests/d3d12_crosstest.h index 7b594712..7ff835ad 100644 --- a/tests/d3d12_crosstest.h +++ b/tests/d3d12_crosstest.h @@ -55,6 +55,7 @@ typedef int HRESULT; #ifdef _WIN32 # include "vkd3d_dxgi1_4.h" #else +# define VKD3D_UTILS_API_VERSION VKD3D_API_VERSION_1_2 # include # include "vkd3d.h" # include "vkd3d_utils.h" diff --git a/tests/vkd3d_api.c b/tests/vkd3d_api.c index d4fe79a8..13fa3d65 100644 --- a/tests/vkd3d_api.c +++ b/tests/vkd3d_api.c @@ -58,9 +58,16 @@ static HRESULT signal_event(HANDLE event) return S_OK; } +static const struct vkd3d_application_info instance_default_application_info = +{ + .type = VKD3D_STRUCTURE_TYPE_APPLICATION_INFO, + .api_version = VKD3D_API_VERSION_1_2, +}; + static const struct vkd3d_instance_create_info instance_default_create_info = { .type = VKD3D_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, + .next = &instance_default_application_info, .wchar_size = sizeof(WCHAR), .pfn_signal_event = signal_event, }; @@ -1078,6 +1085,7 @@ static void test_application_info(void) app_info.engine_version = 0; app_info.application_name = NULL; app_info.application_version = 0; + app_info.api_version = VKD3D_API_VERSION_1_0; create_info = instance_default_create_info; create_info.next = &app_info;