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 <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Henri Verbeet 2020-06-30 15:02:04 +04:30 committed by Alexandre Julliard
parent 11980c3944
commit 3777eb4e5c
9 changed files with 52 additions and 6 deletions

View File

@ -18,6 +18,7 @@
*/
#define VK_USE_PLATFORM_XCB_KHR
#define VKD3D_UTILS_API_VERSION VKD3D_API_VERSION_1_2
#include <vkd3d.h>
#include <vkd3d_utils.h>
#include <xcb/xcb_event.h>

View File

@ -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

View File

@ -21,6 +21,10 @@
#include <vkd3d.h>
#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,

View File

@ -2,6 +2,7 @@ VKD3D_1_0
{
global:
D3D12CreateDevice;
D3D12CreateDeviceVKD3D;
D3D12CreateRootSignatureDeserializer;
D3D12CreateVersionedRootSignatureDeserializer;
D3D12GetDebugInterface;

View File

@ -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)
{

View File

@ -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))))
{

View File

@ -147,6 +147,7 @@ struct vkd3d_instance
void *libvulkan;
uint64_t config_flags;
enum vkd3d_api_version api_version;
VkDebugReportCallbackEXT vk_debug_callback;

View File

@ -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 <pthread.h>
# include "vkd3d.h"
# include "vkd3d_utils.h"

View File

@ -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;