From aadb6609ec0fe2f2de8e42f776861c7a2e12e71b Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Sat, 8 Jan 2022 17:15:52 +0100 Subject: [PATCH] internal/vk: [Android] add workaround for Vulkan on the emulator According to the Vulkan specification the pApplicationInfo member of the VkInstanceCreateInfo structure may be NULL. However, the Android emulator crashes on vkEnumeratePhysicalDevices if set to NULL. This change adds a minimal info to please the emulator. Signed-off-by: Elias Naur --- internal/vk/vulkan.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/internal/vk/vulkan.go b/internal/vk/vulkan.go index f210d40b..1bdffd88 100644 --- a/internal/vk/vulkan.go +++ b/internal/vk/vulkan.go @@ -823,8 +823,19 @@ func CreateInstance(exts ...string) (Instance, error) { if err := vkInit(); err != nil { return nil, err } + // VK_MAKE_API_VERSION macro. + makeVer := func(variant, major, minor, patch int) C.uint32_t { + return ((((C.uint32_t)(variant)) << 29) | (((C.uint32_t)(major)) << 22) | (((C.uint32_t)(minor)) << 12) | ((C.uint32_t)(patch))) + } + appInf := C.VkApplicationInfo{ + sType: C.VK_STRUCTURE_TYPE_APPLICATION_INFO, + apiVersion: makeVer(0, 1, 0, 0), + } inf := C.VkInstanceCreateInfo{ sType: C.VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, + // pApplicationInfo may be omitted according to the spec, but the Android + // emulator crashes without it. + pApplicationInfo: &appInf, } if len(exts) > 0 { cexts := mallocCStringArr(exts)