From: Józef Kucia jkucia@codeweavers.com
Signed-off-by: Józef Kucia jkucia@codeweavers.com --- include/vkd3d.h | 14 ++++++++++++++ libs/vkd3d/device.c | 35 ++++++++++++++++++++++++++++++++--- tests/vkd3d_api.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 3 deletions(-)
diff --git a/include/vkd3d.h b/include/vkd3d.h index 24cb34eb3c34..b78076e43927 100644 --- a/include/vkd3d.h +++ b/include/vkd3d.h @@ -43,6 +43,7 @@ enum vkd3d_structure_type VKD3D_STRUCTURE_TYPE_OPTIONAL_INSTANCE_EXTENSIONS_INFO,
VKD3D_STRUCTURE_TYPE_OPTIONAL_DEVICE_EXTENSIONS_INFO, + VKD3D_STRUCTURE_TYPE_APPLICATION_INFO,
VKD3D_FORCE_32_BIT_ENUM(VKD3D_STRUCTURE_TYPE), }; @@ -83,6 +84,19 @@ struct vkd3d_optional_instance_extensions_info uint32_t extension_count; };
+/* Extends vkd3d_instance_create_info. */ +struct vkd3d_application_info +{ + enum vkd3d_structure_type type; + const void *next; + + const char *application_name; + uint32_t application_version; + + const char *engine_name; /* "vkd3d" if NULL */ + uint32_t engine_version; /* vkd3d version if engine_name is NULL */ +}; + struct vkd3d_device_create_info { enum vkd3d_structure_type type; diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c index a107e1e6414c..3476fdead708 100644 --- a/libs/vkd3d/device.c +++ b/libs/vkd3d/device.c @@ -18,6 +18,8 @@
#include "vkd3d_private.h"
+#include <ctype.h> + #ifdef HAVE_DLFCN_H #include <dlfcn.h>
@@ -104,6 +106,21 @@ static void *vk_find_struct_(struct vk_struct *chain, VkStructureType sType) return NULL; }
+static uint32_t vkd3d_get_vk_version(void) +{ + const char *ptr = PACKAGE_VERSION; + int major, minor; + + major = atoi(ptr); + + while (isdigit(*ptr) || *ptr == '.') + ++ptr; + + minor = atoi(ptr); + + return VK_MAKE_VERSION(major, minor, 0); +} + struct vkd3d_optional_extension_info { const char *extension_name; @@ -459,6 +476,7 @@ static HRESULT vkd3d_instance_init(struct vkd3d_instance *instance, { const struct vkd3d_vk_global_procs *vk_global_procs = &instance->vk_global_procs; const struct vkd3d_optional_instance_extensions_info *optional_extensions; + const struct vkd3d_application_info *vkd3d_application_info; bool *user_extension_supported = NULL; VkApplicationInfo application_info; VkInstanceCreateInfo instance_info; @@ -509,12 +527,23 @@ static HRESULT vkd3d_instance_init(struct vkd3d_instance *instance,
application_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; application_info.pNext = NULL; - application_info.pApplicationName = PACKAGE_NAME; + application_info.pApplicationName = NULL; application_info.applicationVersion = 0; - application_info.pEngineName = NULL; - application_info.engineVersion = 0; + application_info.pEngineName = PACKAGE_NAME; + application_info.engineVersion = vkd3d_get_vk_version(); application_info.apiVersion = VK_API_VERSION_1_0;
+ if ((vkd3d_application_info = vkd3d_find_struct(create_info->next, APPLICATION_INFO))) + { + application_info.pApplicationName = vkd3d_application_info->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; + } + } + if (!(extensions = vkd3d_calloc(extension_count, sizeof(*extensions)))) { if (instance->libvulkan) diff --git a/tests/vkd3d_api.c b/tests/vkd3d_api.c index 14d0914512bc..5acec56d8646 100644 --- a/tests/vkd3d_api.c +++ b/tests/vkd3d_api.c @@ -1052,6 +1052,49 @@ static void test_formats(void) } }
+static void test_application_info(void) +{ + struct vkd3d_instance_create_info create_info; + struct vkd3d_application_info app_info; + struct vkd3d_instance *instance; + ULONG refcount; + HRESULT hr; + + app_info.type = VKD3D_STRUCTURE_TYPE_APPLICATION_INFO; + app_info.next = NULL; + app_info.engine_name = NULL; + app_info.engine_version = 0; + app_info.application_name = NULL; + app_info.application_version = 0; + + create_info = instance_default_create_info; + create_info.next = &app_info; + hr = vkd3d_create_instance(&create_info, &instance); + ok(hr == S_OK, "Failed to create instance, hr %#x.\n", hr); + refcount = vkd3d_instance_decref(instance); + ok(!refcount, "Instance has %u references left.\n", refcount); + + app_info.application_name = "vkd3d_api_tests"; + app_info.application_version = 0xdeadbeef; + hr = vkd3d_create_instance(&create_info, &instance); + ok(hr == S_OK, "Failed to create instance, hr %#x.\n", hr); + refcount = vkd3d_instance_decref(instance); + ok(!refcount, "Instance has %u references left.\n", refcount); + + app_info.engine_name = "engine_name"; + hr = vkd3d_create_instance(&create_info, &instance); + ok(hr == S_OK, "Failed to create instance, hr %#x.\n", hr); + refcount = vkd3d_instance_decref(instance); + ok(!refcount, "Instance has %u references left.\n", refcount); + + app_info.engine_name = "engine_name"; + app_info.engine_version = 2; + hr = vkd3d_create_instance(&create_info, &instance); + ok(hr == S_OK, "Failed to create instance, hr %#x.\n", hr); + refcount = vkd3d_instance_decref(instance); + ok(!refcount, "Instance has %u references left.\n", refcount); +} + static bool have_d3d12_device(void) { ID3D12Device *device; @@ -1083,4 +1126,5 @@ START_TEST(vkd3d_api) run_test(test_external_resource_map); run_test(test_external_resource_present_state); run_test(test_formats); + run_test(test_application_info); }