15db71995Sopenharmony_ci/* 25db71995Sopenharmony_ci * Copyright (c) 2015-2022 Valve Corporation 35db71995Sopenharmony_ci * Copyright (c) 2015-2022 LunarG, Inc. 45db71995Sopenharmony_ci * 55db71995Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 65db71995Sopenharmony_ci * you may not use this file except in compliance with the License. 75db71995Sopenharmony_ci * You may obtain a copy of the License at 85db71995Sopenharmony_ci * 95db71995Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 105db71995Sopenharmony_ci * 115db71995Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 125db71995Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 135db71995Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 145db71995Sopenharmony_ci * See the License for the specific language governing permissions and 155db71995Sopenharmony_ci * limitations under the License. 165db71995Sopenharmony_ci * 175db71995Sopenharmony_ci * Author: Jon Ashburn <jon@lunarg.com> 185db71995Sopenharmony_ci */ 195db71995Sopenharmony_ci 205db71995Sopenharmony_ci#include <stdio.h> 215db71995Sopenharmony_ci#include <stdlib.h> 225db71995Sopenharmony_ci#include <ctype.h> 235db71995Sopenharmony_ci#include <string> 245db71995Sopenharmony_ci#include <algorithm> 255db71995Sopenharmony_ci#include <assert.h> 265db71995Sopenharmony_ci#include <unordered_map> 275db71995Sopenharmony_ci#include <memory> 285db71995Sopenharmony_ci#include <vector> 295db71995Sopenharmony_ci 305db71995Sopenharmony_ci#include "vulkan/vk_layer.h" 315db71995Sopenharmony_ci#include "vk_dispatch_table_helper.h" 325db71995Sopenharmony_ci#include "loader/vk_loader_layer.h" 335db71995Sopenharmony_ci 345db71995Sopenharmony_ci// Export full support of instance extension VK_EXT_direct_mode_display extension 355db71995Sopenharmony_ci#if !defined(TEST_LAYER_EXPORT_DIRECT_DISP) 365db71995Sopenharmony_ci#define TEST_LAYER_EXPORT_DIRECT_DISP 0 375db71995Sopenharmony_ci#endif 385db71995Sopenharmony_ci 395db71995Sopenharmony_ci// Export full support of instance extension VK_EXT_display_surface_counter extension 405db71995Sopenharmony_ci#if !defined(TEST_LAYER_EXPORT_DISP_SURF_COUNT) 415db71995Sopenharmony_ci#define TEST_LAYER_EXPORT_DISP_SURF_COUNT 0 425db71995Sopenharmony_ci#endif 435db71995Sopenharmony_ci 445db71995Sopenharmony_ci// Export full support of device extension VK_KHR_maintenance1 extension 455db71995Sopenharmony_ci#if !defined(TEST_LAYER_EXPORT_MAINT_1) 465db71995Sopenharmony_ci#define TEST_LAYER_EXPORT_MAINT_1 0 475db71995Sopenharmony_ci#endif 485db71995Sopenharmony_ci 495db71995Sopenharmony_ci// Export full support of device extension VK_KHR_shared_presentable_image extension 505db71995Sopenharmony_ci#if !defined(TEST_LAYER_EXPORT_PRESENT_IMAGE) 515db71995Sopenharmony_ci#define TEST_LAYER_EXPORT_PRESENT_IMAGE 0 525db71995Sopenharmony_ci#endif 535db71995Sopenharmony_ci 545db71995Sopenharmony_ci#if !defined(VK_LAYER_EXPORT) 555db71995Sopenharmony_ci#if defined(__GNUC__) && __GNUC__ >= 4 565db71995Sopenharmony_ci#define VK_LAYER_EXPORT __attribute__((visibility("default"))) 575db71995Sopenharmony_ci#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590) 585db71995Sopenharmony_ci#define VK_LAYER_EXPORT __attribute__((visibility("default"))) 595db71995Sopenharmony_ci#else 605db71995Sopenharmony_ci#define VK_LAYER_EXPORT 615db71995Sopenharmony_ci#endif 625db71995Sopenharmony_ci#endif 635db71995Sopenharmony_ci 645db71995Sopenharmony_cistruct wrapped_phys_dev_obj { 655db71995Sopenharmony_ci VkLayerInstanceDispatchTable *loader_disp; 665db71995Sopenharmony_ci struct wrapped_inst_obj *inst; // parent instance object 675db71995Sopenharmony_ci void *obj; 685db71995Sopenharmony_ci}; 695db71995Sopenharmony_ci 705db71995Sopenharmony_cistruct wrapped_inst_obj { 715db71995Sopenharmony_ci VkLayerInstanceDispatchTable *loader_disp; 725db71995Sopenharmony_ci VkLayerInstanceDispatchTable layer_disp; // this layer's dispatch table 735db71995Sopenharmony_ci PFN_vkSetInstanceLoaderData pfn_inst_init; 745db71995Sopenharmony_ci struct wrapped_phys_dev_obj *ptr_phys_devs; // any enumerated phys devs 755db71995Sopenharmony_ci VkInstance obj; 765db71995Sopenharmony_ci bool layer_is_implicit; 775db71995Sopenharmony_ci bool direct_display_enabled; 785db71995Sopenharmony_ci bool display_surf_counter_enabled; 795db71995Sopenharmony_ci bool debug_utils_enabled; 805db71995Sopenharmony_ci}; 815db71995Sopenharmony_ci 825db71995Sopenharmony_cistruct wrapped_dev_obj { 835db71995Sopenharmony_ci VkLayerDispatchTable *loader_disp; 845db71995Sopenharmony_ci VkLayerDispatchTable disp; 855db71995Sopenharmony_ci PFN_vkSetDeviceLoaderData pfn_dev_init; 865db71995Sopenharmony_ci PFN_vkGetDeviceProcAddr pfn_get_dev_proc_addr; 875db71995Sopenharmony_ci VkDevice obj; 885db71995Sopenharmony_ci bool maintanence_1_enabled; 895db71995Sopenharmony_ci bool present_image_enabled; 905db71995Sopenharmony_ci bool debug_utils_enabled; 915db71995Sopenharmony_ci bool debug_report_enabled; 925db71995Sopenharmony_ci bool debug_marker_enabled; 935db71995Sopenharmony_ci}; 945db71995Sopenharmony_ci 955db71995Sopenharmony_cistruct wrapped_debug_util_mess_obj { 965db71995Sopenharmony_ci VkInstance inst; 975db71995Sopenharmony_ci VkDebugUtilsMessengerEXT obj; 985db71995Sopenharmony_ci}; 995db71995Sopenharmony_ci 1005db71995Sopenharmony_cistruct saved_wrapped_handles_storage { 1015db71995Sopenharmony_ci std::vector<wrapped_inst_obj *> instances; 1025db71995Sopenharmony_ci std::vector<wrapped_phys_dev_obj *> physical_devices; 1035db71995Sopenharmony_ci std::vector<wrapped_dev_obj *> devices; 1045db71995Sopenharmony_ci std::vector<wrapped_debug_util_mess_obj *> debug_util_messengers; 1055db71995Sopenharmony_ci}; 1065db71995Sopenharmony_ci 1075db71995Sopenharmony_cisaved_wrapped_handles_storage saved_wrapped_handles; 1085db71995Sopenharmony_ci 1095db71995Sopenharmony_ciVkInstance unwrap_instance(const VkInstance instance, wrapped_inst_obj **inst) { 1105db71995Sopenharmony_ci *inst = reinterpret_cast<wrapped_inst_obj *>(instance); 1115db71995Sopenharmony_ci auto it = std::find(saved_wrapped_handles.instances.begin(), saved_wrapped_handles.instances.end(), *inst); 1125db71995Sopenharmony_ci return (it == saved_wrapped_handles.instances.end()) ? VK_NULL_HANDLE : (*inst)->obj; 1135db71995Sopenharmony_ci} 1145db71995Sopenharmony_ci 1155db71995Sopenharmony_ciVkPhysicalDevice unwrap_phys_dev(const VkPhysicalDevice physical_device, wrapped_phys_dev_obj **phys_dev) { 1165db71995Sopenharmony_ci *phys_dev = reinterpret_cast<wrapped_phys_dev_obj *>(physical_device); 1175db71995Sopenharmony_ci auto it = std::find(saved_wrapped_handles.physical_devices.begin(), saved_wrapped_handles.physical_devices.end(), *phys_dev); 1185db71995Sopenharmony_ci return (it == saved_wrapped_handles.physical_devices.end()) ? VK_NULL_HANDLE 1195db71995Sopenharmony_ci : reinterpret_cast<VkPhysicalDevice>((*phys_dev)->obj); 1205db71995Sopenharmony_ci} 1215db71995Sopenharmony_ci 1225db71995Sopenharmony_ciVkDevice unwrap_device(const VkDevice device, wrapped_dev_obj **dev) { 1235db71995Sopenharmony_ci *dev = reinterpret_cast<wrapped_dev_obj *>(device); 1245db71995Sopenharmony_ci auto it = std::find(saved_wrapped_handles.devices.begin(), saved_wrapped_handles.devices.end(), *dev); 1255db71995Sopenharmony_ci return (it == saved_wrapped_handles.devices.end()) ? VK_NULL_HANDLE : (*dev)->obj; 1265db71995Sopenharmony_ci} 1275db71995Sopenharmony_ci 1285db71995Sopenharmony_ciVkDebugUtilsMessengerEXT unwrap_debug_util_messenger(const VkDebugUtilsMessengerEXT messenger, wrapped_debug_util_mess_obj **mess) { 1295db71995Sopenharmony_ci *mess = reinterpret_cast<wrapped_debug_util_mess_obj *>(messenger); 1305db71995Sopenharmony_ci auto it = 1315db71995Sopenharmony_ci std::find(saved_wrapped_handles.debug_util_messengers.begin(), saved_wrapped_handles.debug_util_messengers.end(), *mess); 1325db71995Sopenharmony_ci return (it == saved_wrapped_handles.debug_util_messengers.end()) ? VK_NULL_HANDLE : (*mess)->obj; 1335db71995Sopenharmony_ci} 1345db71995Sopenharmony_ci 1355db71995Sopenharmony_ciVkLayerInstanceCreateInfo *get_chain_info(const VkInstanceCreateInfo *pCreateInfo, VkLayerFunction func) { 1365db71995Sopenharmony_ci VkLayerInstanceCreateInfo *chain_info = (VkLayerInstanceCreateInfo *)pCreateInfo->pNext; 1375db71995Sopenharmony_ci while (chain_info && !(chain_info->sType == VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO && chain_info->function == func)) { 1385db71995Sopenharmony_ci chain_info = (VkLayerInstanceCreateInfo *)chain_info->pNext; 1395db71995Sopenharmony_ci } 1405db71995Sopenharmony_ci assert(chain_info != NULL); 1415db71995Sopenharmony_ci return chain_info; 1425db71995Sopenharmony_ci} 1435db71995Sopenharmony_ci 1445db71995Sopenharmony_ciVkLayerDeviceCreateInfo *get_chain_info(const VkDeviceCreateInfo *pCreateInfo, VkLayerFunction func) { 1455db71995Sopenharmony_ci VkLayerDeviceCreateInfo *chain_info = (VkLayerDeviceCreateInfo *)pCreateInfo->pNext; 1465db71995Sopenharmony_ci while (chain_info && !(chain_info->sType == VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO && chain_info->function == func)) { 1475db71995Sopenharmony_ci chain_info = (VkLayerDeviceCreateInfo *)chain_info->pNext; 1485db71995Sopenharmony_ci } 1495db71995Sopenharmony_ci assert(chain_info != NULL); 1505db71995Sopenharmony_ci return chain_info; 1515db71995Sopenharmony_ci} 1525db71995Sopenharmony_ci 1535db71995Sopenharmony_cinamespace wrap_objects { 1545db71995Sopenharmony_ci 1555db71995Sopenharmony_ciconst VkLayerProperties global_layer = { 1565db71995Sopenharmony_ci "VK_LAYER_LUNARG_wrap_objects", 1575db71995Sopenharmony_ci VK_HEADER_VERSION_COMPLETE, 1585db71995Sopenharmony_ci 1, 1595db71995Sopenharmony_ci "LunarG Test Layer", 1605db71995Sopenharmony_ci}; 1615db71995Sopenharmony_ci 1625db71995Sopenharmony_ciuint32_t loader_layer_if_version = CURRENT_LOADER_LAYER_INTERFACE_VERSION; 1635db71995Sopenharmony_ci 1645db71995Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL wrap_vkCreateInstance(const VkInstanceCreateInfo *pCreateInfo, 1655db71995Sopenharmony_ci const VkAllocationCallbacks *pAllocator, VkInstance *pInstance) { 1665db71995Sopenharmony_ci VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); 1675db71995Sopenharmony_ci PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; 1685db71995Sopenharmony_ci PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance"); 1695db71995Sopenharmony_ci if (fpCreateInstance == NULL) { 1705db71995Sopenharmony_ci return VK_ERROR_INITIALIZATION_FAILED; 1715db71995Sopenharmony_ci } 1725db71995Sopenharmony_ci // Advance the link info for the next element on the chain 1735db71995Sopenharmony_ci chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; 1745db71995Sopenharmony_ci VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance); 1755db71995Sopenharmony_ci if (result != VK_SUCCESS) { 1765db71995Sopenharmony_ci return result; 1775db71995Sopenharmony_ci } 1785db71995Sopenharmony_ci auto inst = new wrapped_inst_obj; 1795db71995Sopenharmony_ci if (!inst) return VK_ERROR_OUT_OF_HOST_MEMORY; 1805db71995Sopenharmony_ci saved_wrapped_handles.instances.push_back(inst); 1815db71995Sopenharmony_ci memset(inst, 0, sizeof(*inst)); 1825db71995Sopenharmony_ci inst->obj = (*pInstance); 1835db71995Sopenharmony_ci *pInstance = reinterpret_cast<VkInstance>(inst); 1845db71995Sopenharmony_ci // store the loader callback for initializing created dispatchable objects 1855db71995Sopenharmony_ci chain_info = get_chain_info(pCreateInfo, VK_LOADER_DATA_CALLBACK); 1865db71995Sopenharmony_ci if (chain_info) { 1875db71995Sopenharmony_ci inst->pfn_inst_init = chain_info->u.pfnSetInstanceLoaderData; 1885db71995Sopenharmony_ci result = inst->pfn_inst_init(inst->obj, reinterpret_cast<void *>(inst)); 1895db71995Sopenharmony_ci if (VK_SUCCESS != result) return result; 1905db71995Sopenharmony_ci } else { 1915db71995Sopenharmony_ci inst->pfn_inst_init = NULL; 1925db71995Sopenharmony_ci inst->loader_disp = *(reinterpret_cast<VkLayerInstanceDispatchTable **>(inst->obj)); 1935db71995Sopenharmony_ci } 1945db71995Sopenharmony_ci layer_init_instance_dispatch_table(inst->obj, &inst->layer_disp, fpGetInstanceProcAddr); 1955db71995Sopenharmony_ci bool found = false; 1965db71995Sopenharmony_ci for (uint32_t layer = 0; layer < pCreateInfo->enabledLayerCount; ++layer) { 1975db71995Sopenharmony_ci std::string layer_name = pCreateInfo->ppEnabledLayerNames[layer]; 1985db71995Sopenharmony_ci std::transform(layer_name.begin(), layer_name.end(), layer_name.begin(), 1995db71995Sopenharmony_ci [](char c) { return static_cast<char>(::tolower(static_cast<char>(c))); }); 2005db71995Sopenharmony_ci if (layer_name.find("wrap") != std::string::npos && layer_name.find("obj") != std::string::npos) { 2015db71995Sopenharmony_ci found = true; 2025db71995Sopenharmony_ci break; 2035db71995Sopenharmony_ci } 2045db71995Sopenharmony_ci } 2055db71995Sopenharmony_ci if (!found) { 2065db71995Sopenharmony_ci inst->layer_is_implicit = true; 2075db71995Sopenharmony_ci } 2085db71995Sopenharmony_ci 2095db71995Sopenharmony_ci for (uint32_t ext = 0; ext < pCreateInfo->enabledExtensionCount; ++ext) { 2105db71995Sopenharmony_ci if (!strcmp(pCreateInfo->ppEnabledExtensionNames[ext], VK_EXT_DIRECT_MODE_DISPLAY_EXTENSION_NAME)) { 2115db71995Sopenharmony_ci#if TEST_LAYER_EXPORT_DIRECT_DISP 2125db71995Sopenharmony_ci inst->direct_display_enabled = true; 2135db71995Sopenharmony_ci#endif 2145db71995Sopenharmony_ci } 2155db71995Sopenharmony_ci if (!strcmp(pCreateInfo->ppEnabledExtensionNames[ext], VK_EXT_DISPLAY_SURFACE_COUNTER_EXTENSION_NAME)) { 2165db71995Sopenharmony_ci#if TEST_LAYER_EXPORT_DISP_SURF_COUNT 2175db71995Sopenharmony_ci inst->display_surf_counter_enabled = true; 2185db71995Sopenharmony_ci#endif 2195db71995Sopenharmony_ci } 2205db71995Sopenharmony_ci if (!strcmp(pCreateInfo->ppEnabledExtensionNames[ext], VK_EXT_DEBUG_UTILS_EXTENSION_NAME)) { 2215db71995Sopenharmony_ci inst->debug_utils_enabled = true; 2225db71995Sopenharmony_ci } 2235db71995Sopenharmony_ci } 2245db71995Sopenharmony_ci 2255db71995Sopenharmony_ci return result; 2265db71995Sopenharmony_ci} 2275db71995Sopenharmony_ci 2285db71995Sopenharmony_ciVKAPI_ATTR void VKAPI_CALL wrap_vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) { 2295db71995Sopenharmony_ci wrapped_inst_obj *inst; 2305db71995Sopenharmony_ci auto vk_inst = unwrap_instance(instance, &inst); 2315db71995Sopenharmony_ci VkLayerInstanceDispatchTable *pDisp = &inst->layer_disp; 2325db71995Sopenharmony_ci pDisp->DestroyInstance(vk_inst, pAllocator); 2335db71995Sopenharmony_ci if (inst->ptr_phys_devs) delete[] inst->ptr_phys_devs; 2345db71995Sopenharmony_ci delete inst; 2355db71995Sopenharmony_ci} 2365db71995Sopenharmony_ci 2375db71995Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL wrap_vkCreateDebugUtilsMessengerEXT(VkInstance instance, 2385db71995Sopenharmony_ci const VkDebugUtilsMessengerCreateInfoEXT *pCreateInfo, 2395db71995Sopenharmony_ci const VkAllocationCallbacks *pAllocator, 2405db71995Sopenharmony_ci VkDebugUtilsMessengerEXT *pMessenger) { 2415db71995Sopenharmony_ci wrapped_inst_obj *inst; 2425db71995Sopenharmony_ci auto vk_inst = unwrap_instance(instance, &inst); 2435db71995Sopenharmony_ci VkLayerInstanceDispatchTable *pDisp = &inst->layer_disp; 2445db71995Sopenharmony_ci VkResult result = pDisp->CreateDebugUtilsMessengerEXT(vk_inst, pCreateInfo, pAllocator, pMessenger); 2455db71995Sopenharmony_ci auto mess = new wrapped_debug_util_mess_obj; 2465db71995Sopenharmony_ci if (!mess) return VK_ERROR_OUT_OF_HOST_MEMORY; 2475db71995Sopenharmony_ci saved_wrapped_handles.debug_util_messengers.push_back(mess); 2485db71995Sopenharmony_ci memset(mess, 0, sizeof(*mess)); 2495db71995Sopenharmony_ci mess->obj = (*pMessenger); 2505db71995Sopenharmony_ci *pMessenger = reinterpret_cast<VkDebugUtilsMessengerEXT>(mess); 2515db71995Sopenharmony_ci return result; 2525db71995Sopenharmony_ci} 2535db71995Sopenharmony_ci 2545db71995Sopenharmony_ciVKAPI_ATTR void VKAPI_CALL wrap_vkDestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT messenger, 2555db71995Sopenharmony_ci const VkAllocationCallbacks *pAllocator) { 2565db71995Sopenharmony_ci wrapped_inst_obj *inst; 2575db71995Sopenharmony_ci auto vk_inst = unwrap_instance(instance, &inst); 2585db71995Sopenharmony_ci VkLayerInstanceDispatchTable *pDisp = &inst->layer_disp; 2595db71995Sopenharmony_ci wrapped_debug_util_mess_obj *mess; 2605db71995Sopenharmony_ci auto vk_mess = unwrap_debug_util_messenger(messenger, &mess); 2615db71995Sopenharmony_ci pDisp->DestroyDebugUtilsMessengerEXT(vk_inst, vk_mess, pAllocator); 2625db71995Sopenharmony_ci delete mess; 2635db71995Sopenharmony_ci} 2645db71995Sopenharmony_ci 2655db71995Sopenharmony_ciVKAPI_ATTR void VKAPI_CALL wrap_vkDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface, 2665db71995Sopenharmony_ci const VkAllocationCallbacks *pAllocator) { 2675db71995Sopenharmony_ci wrapped_inst_obj *inst; 2685db71995Sopenharmony_ci auto vk_inst = unwrap_instance(instance, &inst); 2695db71995Sopenharmony_ci VkLayerInstanceDispatchTable *pDisp = &inst->layer_disp; 2705db71995Sopenharmony_ci pDisp->DestroySurfaceKHR(vk_inst, surface, pAllocator); 2715db71995Sopenharmony_ci} 2725db71995Sopenharmony_ci#if defined(VK_USE_PLATFORM_ANDROID_KHR) 2735db71995Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL wrap_vkCreateAndroidSurfaceKHR(VkInstance instance, const VkAndroidSurfaceCreateInfoKHR *pCreateInfo, 2745db71995Sopenharmony_ci const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { 2755db71995Sopenharmony_ci wrapped_inst_obj *inst; 2765db71995Sopenharmony_ci auto vk_inst = unwrap_instance(instance, &inst); 2775db71995Sopenharmony_ci VkLayerInstanceDispatchTable *pDisp = &inst->layer_disp; 2785db71995Sopenharmony_ci return pDisp->CreateAndroidSurfaceKHR(vk_inst, pCreateInfo, pAllocator, pSurface); 2795db71995Sopenharmony_ci} 2805db71995Sopenharmony_ci#endif 2815db71995Sopenharmony_ci 2825db71995Sopenharmony_ci#if defined(VK_USE_PLATFORM_WIN32_KHR) 2835db71995Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL wrap_vkCreateWin32SurfaceKHR(VkInstance instance, const VkWin32SurfaceCreateInfoKHR *pCreateInfo, 2845db71995Sopenharmony_ci const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { 2855db71995Sopenharmony_ci wrapped_inst_obj *inst; 2865db71995Sopenharmony_ci auto vk_inst = unwrap_instance(instance, &inst); 2875db71995Sopenharmony_ci VkLayerInstanceDispatchTable *pDisp = &inst->layer_disp; 2885db71995Sopenharmony_ci return pDisp->CreateWin32SurfaceKHR(vk_inst, pCreateInfo, pAllocator, pSurface); 2895db71995Sopenharmony_ci} 2905db71995Sopenharmony_ci#endif // VK_USE_PLATFORM_WIN32_KHR 2915db71995Sopenharmony_ci 2925db71995Sopenharmony_ci#if defined(VK_USE_PLATFORM_WAYLAND_KHR) 2935db71995Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL wrap_vkCreateWaylandSurfaceKHR(VkInstance instance, const VkWaylandSurfaceCreateInfoKHR *pCreateInfo, 2945db71995Sopenharmony_ci const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { 2955db71995Sopenharmony_ci wrapped_inst_obj *inst; 2965db71995Sopenharmony_ci auto vk_inst = unwrap_instance(instance, &inst); 2975db71995Sopenharmony_ci VkLayerInstanceDispatchTable *pDisp = &inst->layer_disp; 2985db71995Sopenharmony_ci return pDisp->CreateWaylandSurfaceKHR(vk_inst, pCreateInfo, pAllocator, pSurface); 2995db71995Sopenharmony_ci} 3005db71995Sopenharmony_ci#endif // VK_USE_PLATFORM_WAYLAND_KHR 3015db71995Sopenharmony_ci 3025db71995Sopenharmony_ci#if defined(VK_USE_PLATFORM_XCB_KHR) 3035db71995Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL wrap_vkCreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo, 3045db71995Sopenharmony_ci const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { 3055db71995Sopenharmony_ci wrapped_inst_obj *inst; 3065db71995Sopenharmony_ci auto vk_inst = unwrap_instance(instance, &inst); 3075db71995Sopenharmony_ci VkLayerInstanceDispatchTable *pDisp = &inst->layer_disp; 3085db71995Sopenharmony_ci return pDisp->CreateXcbSurfaceKHR(vk_inst, pCreateInfo, pAllocator, pSurface); 3095db71995Sopenharmony_ci} 3105db71995Sopenharmony_ci#endif // VK_USE_PLATFORM_XCB_KHR 3115db71995Sopenharmony_ci 3125db71995Sopenharmony_ci#if defined(VK_USE_PLATFORM_XLIB_KHR) 3135db71995Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL wrap_vkCreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo, 3145db71995Sopenharmony_ci const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { 3155db71995Sopenharmony_ci wrapped_inst_obj *inst; 3165db71995Sopenharmony_ci auto vk_inst = unwrap_instance(instance, &inst); 3175db71995Sopenharmony_ci VkLayerInstanceDispatchTable *pDisp = &inst->layer_disp; 3185db71995Sopenharmony_ci return pDisp->CreateXlibSurfaceKHR(vk_inst, pCreateInfo, pAllocator, pSurface); 3195db71995Sopenharmony_ci} 3205db71995Sopenharmony_ci#endif // VK_USE_PLATFORM_XLIB_KHR 3215db71995Sopenharmony_ci 3225db71995Sopenharmony_ci#if defined(VK_USE_PLATFORM_DIRECTFB_EXT) 3235db71995Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL wrap_vkCreateDirectFBSurfaceEXT(VkInstance instance, 3245db71995Sopenharmony_ci const VkDirectFBSurfaceCreateInfoEXT *pCreateInfo, 3255db71995Sopenharmony_ci const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { 3265db71995Sopenharmony_ci wrapped_inst_obj *inst; 3275db71995Sopenharmony_ci auto vk_inst = unwrap_instance(instance, &inst); 3285db71995Sopenharmony_ci VkLayerInstanceDispatchTable *pDisp = &inst->layer_disp; 3295db71995Sopenharmony_ci return pDisp->CreateDirectFBSurfaceEXT(vk_inst, pCreateInfo, pAllocator, pSurface); 3305db71995Sopenharmony_ci} 3315db71995Sopenharmony_ci#endif // VK_USE_PLATFORM_DIRECTFB_EXT 3325db71995Sopenharmony_ci 3335db71995Sopenharmony_ci#if defined(VK_USE_PLATFORM_MACOS_MVK) 3345db71995Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL wrap_vkCreateMacOSSurfaceMVK(VkInstance instance, const VkMacOSSurfaceCreateInfoMVK *pCreateInfo, 3355db71995Sopenharmony_ci const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { 3365db71995Sopenharmony_ci wrapped_inst_obj *inst; 3375db71995Sopenharmony_ci auto vk_inst = unwrap_instance(instance, &inst); 3385db71995Sopenharmony_ci VkLayerInstanceDispatchTable *pDisp = &inst->layer_disp; 3395db71995Sopenharmony_ci return pDisp->CreateMacOSSurfaceMVK(vk_inst, pCreateInfo, pAllocator, pSurface); 3405db71995Sopenharmony_ci} 3415db71995Sopenharmony_ci#endif // VK_USE_PLATFORM_MACOS_MVK 3425db71995Sopenharmony_ci 3435db71995Sopenharmony_ci#if defined(VK_USE_PLATFORM_IOS_MVK) 3445db71995Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL wrap_vkCreateIOSSurfaceMVK(VkInstance instance, const VkIOSSurfaceCreateInfoMVK *pCreateInfo, 3455db71995Sopenharmony_ci const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { 3465db71995Sopenharmony_ci wrapped_inst_obj *inst; 3475db71995Sopenharmony_ci auto vk_inst = unwrap_instance(instance, &inst); 3485db71995Sopenharmony_ci VkLayerInstanceDispatchTable *pDisp = &inst->layer_disp; 3495db71995Sopenharmony_ci return pDisp->CreateIOSSurfaceMVK(vk_inst, pCreateInfo, pAllocator, pSurface); 3505db71995Sopenharmony_ci} 3515db71995Sopenharmony_ci#endif // VK_USE_PLATFORM_IOS_MVK 3525db71995Sopenharmony_ci 3535db71995Sopenharmony_ci#if defined(VK_USE_PLATFORM_GGP) 3545db71995Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL wrap_vkCreateStreamDescriptorSurfaceGGP(VkInstance instance, 3555db71995Sopenharmony_ci const VkStreamDescriptorSurfaceCreateInfoGGP *pCreateInfo, 3565db71995Sopenharmony_ci const VkAllocationCallbacks *pAllocator, 3575db71995Sopenharmony_ci VkSurfaceKHR *pSurface) { 3585db71995Sopenharmony_ci wrapped_inst_obj *inst; 3595db71995Sopenharmony_ci auto vk_inst = unwrap_instance(instance, &inst); 3605db71995Sopenharmony_ci VkLayerInstanceDispatchTable *pDisp = &inst->layer_disp; 3615db71995Sopenharmony_ci return pDisp->CreateStreamDescriptorSurfaceGGP(vk_inst, pCreateInfo, pAllocator, pSurface); 3625db71995Sopenharmony_ci} 3635db71995Sopenharmony_ci#endif // VK_USE_PLATFORM_GGP 3645db71995Sopenharmony_ci 3655db71995Sopenharmony_ci#if defined(VK_USE_PLATFORM_METAL_EXT) 3665db71995Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL wrap_vkCreateMetalSurfaceEXT(VkInstance instance, const VkMetalSurfaceCreateInfoEXT *pCreateInfo, 3675db71995Sopenharmony_ci const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { 3685db71995Sopenharmony_ci wrapped_inst_obj *inst; 3695db71995Sopenharmony_ci auto vk_inst = unwrap_instance(instance, &inst); 3705db71995Sopenharmony_ci VkLayerInstanceDispatchTable *pDisp = &inst->layer_disp; 3715db71995Sopenharmony_ci return pDisp->CreateMetalSurfaceEXT(vk_inst, pCreateInfo, pAllocator, pSurface); 3725db71995Sopenharmony_ci} 3735db71995Sopenharmony_ci#endif // VK_USE_PLATFORM_METAL_EXT 3745db71995Sopenharmony_ci 3755db71995Sopenharmony_ci#if defined(VK_USE_PLATFORM_SCREEN_QNX) 3765db71995Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL wrap_vkCreateScreenSurfaceQNX(VkInstance instance, const VkScreenSurfaceCreateInfoQNX *pCreateInfo, 3775db71995Sopenharmony_ci const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { 3785db71995Sopenharmony_ci wrapped_inst_obj *inst; 3795db71995Sopenharmony_ci auto vk_inst = unwrap_instance(instance, &inst); 3805db71995Sopenharmony_ci VkLayerInstanceDispatchTable *pDisp = &inst->layer_disp; 3815db71995Sopenharmony_ci return pDisp->CreateScreenSurfaceQNX(vk_inst, pCreateInfo, pAllocator, pSurface); 3825db71995Sopenharmony_ci} 3835db71995Sopenharmony_ci#endif // VK_USE_PLATFORM_SCREEN_QNX 3845db71995Sopenharmony_ci 3855db71995Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL wrap_vkEnumeratePhysicalDevices(VkInstance instance, uint32_t *pPhysicalDeviceCount, 3865db71995Sopenharmony_ci VkPhysicalDevice *pPhysicalDevices) { 3875db71995Sopenharmony_ci wrapped_inst_obj *inst; 3885db71995Sopenharmony_ci auto vk_inst = unwrap_instance(instance, &inst); 3895db71995Sopenharmony_ci VkResult result = inst->layer_disp.EnumeratePhysicalDevices(vk_inst, pPhysicalDeviceCount, pPhysicalDevices); 3905db71995Sopenharmony_ci 3915db71995Sopenharmony_ci if (VK_SUCCESS != result) return result; 3925db71995Sopenharmony_ci 3935db71995Sopenharmony_ci if (pPhysicalDevices != NULL) { 3945db71995Sopenharmony_ci assert(pPhysicalDeviceCount); 3955db71995Sopenharmony_ci auto phys_devs = new wrapped_phys_dev_obj[*pPhysicalDeviceCount]; 3965db71995Sopenharmony_ci if (!phys_devs) return VK_ERROR_OUT_OF_HOST_MEMORY; 3975db71995Sopenharmony_ci saved_wrapped_handles.physical_devices.push_back(phys_devs); 3985db71995Sopenharmony_ci if (inst->ptr_phys_devs) delete[] inst->ptr_phys_devs; 3995db71995Sopenharmony_ci inst->ptr_phys_devs = phys_devs; 4005db71995Sopenharmony_ci for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) { 4015db71995Sopenharmony_ci if (inst->pfn_inst_init == NULL) { 4025db71995Sopenharmony_ci phys_devs[i].loader_disp = *(reinterpret_cast<VkLayerInstanceDispatchTable **>(pPhysicalDevices[i])); 4035db71995Sopenharmony_ci } else { 4045db71995Sopenharmony_ci result = inst->pfn_inst_init(vk_inst, reinterpret_cast<void *>(&phys_devs[i])); 4055db71995Sopenharmony_ci if (VK_SUCCESS != result) return result; 4065db71995Sopenharmony_ci } 4075db71995Sopenharmony_ci phys_devs[i].obj = reinterpret_cast<void *>(pPhysicalDevices[i]); 4085db71995Sopenharmony_ci phys_devs[i].inst = inst; 4095db71995Sopenharmony_ci pPhysicalDevices[i] = reinterpret_cast<VkPhysicalDevice>(&phys_devs[i]); 4105db71995Sopenharmony_ci } 4115db71995Sopenharmony_ci } 4125db71995Sopenharmony_ci return result; 4135db71995Sopenharmony_ci} 4145db71995Sopenharmony_ci 4155db71995Sopenharmony_ciVKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties *pProperties) { 4165db71995Sopenharmony_ci wrapped_phys_dev_obj *phys_dev; 4175db71995Sopenharmony_ci auto vk_phys_dev = unwrap_phys_dev(physicalDevice, &phys_dev); 4185db71995Sopenharmony_ci phys_dev->inst->layer_disp.GetPhysicalDeviceProperties(vk_phys_dev, pProperties); 4195db71995Sopenharmony_ci} 4205db71995Sopenharmony_ci 4215db71995Sopenharmony_ciVKAPI_ATTR void VKAPI_CALL wrap_vkGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, 4225db71995Sopenharmony_ci uint32_t *pQueueFamilyPropertyCount, 4235db71995Sopenharmony_ci VkQueueFamilyProperties *pQueueFamilyProperties) { 4245db71995Sopenharmony_ci wrapped_phys_dev_obj *phys_dev; 4255db71995Sopenharmony_ci auto vk_phys_dev = unwrap_phys_dev(physicalDevice, &phys_dev); 4265db71995Sopenharmony_ci phys_dev->inst->layer_disp.GetPhysicalDeviceQueueFamilyProperties(vk_phys_dev, pQueueFamilyPropertyCount, 4275db71995Sopenharmony_ci pQueueFamilyProperties); 4285db71995Sopenharmony_ci} 4295db71995Sopenharmony_ci 4305db71995Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL wrap_vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char *pLayerName, 4315db71995Sopenharmony_ci uint32_t *pPropertyCount, 4325db71995Sopenharmony_ci VkExtensionProperties *pProperties) { 4335db71995Sopenharmony_ci VkResult result = VK_SUCCESS; 4345db71995Sopenharmony_ci wrapped_phys_dev_obj *phys_dev; 4355db71995Sopenharmony_ci auto vk_phys_dev = unwrap_phys_dev(physicalDevice, &phys_dev); 4365db71995Sopenharmony_ci 4375db71995Sopenharmony_ci if (phys_dev->inst->layer_is_implicit || (pLayerName && !strcmp(pLayerName, global_layer.layerName))) { 4385db71995Sopenharmony_ci uint32_t ext_count = 0; 4395db71995Sopenharmony_ci#if TEST_LAYER_EXPORT_MAINT_1 4405db71995Sopenharmony_ci ext_count++; 4415db71995Sopenharmony_ci#endif 4425db71995Sopenharmony_ci#if TEST_LAYER_EXPORT_PRESENT_IMAGE 4435db71995Sopenharmony_ci ext_count++; 4445db71995Sopenharmony_ci#endif 4455db71995Sopenharmony_ci if (pPropertyCount) { 4465db71995Sopenharmony_ci if (pProperties) { 4475db71995Sopenharmony_ci [[maybe_unused]] uint32_t count = ext_count; 4485db71995Sopenharmony_ci if (count > *pPropertyCount) { 4495db71995Sopenharmony_ci count = *pPropertyCount; 4505db71995Sopenharmony_ci result = VK_INCOMPLETE; 4515db71995Sopenharmony_ci } 4525db71995Sopenharmony_ci 4535db71995Sopenharmony_ci ext_count = 0; 4545db71995Sopenharmony_ci#if TEST_LAYER_EXPORT_MAINT_1 4555db71995Sopenharmony_ci if (ext_count < count) { 4565db71995Sopenharmony_ci#if defined(_WIN32) 4575db71995Sopenharmony_ci strncpy_s(pProperties[ext_count].extensionName, VK_MAX_EXTENSION_NAME_SIZE, VK_KHR_MAINTENANCE1_EXTENSION_NAME, 4585db71995Sopenharmony_ci strlen(VK_KHR_MAINTENANCE1_EXTENSION_NAME) + 1); 4595db71995Sopenharmony_ci#else 4605db71995Sopenharmony_ci strncpy(pProperties[ext_count].extensionName, VK_KHR_MAINTENANCE1_EXTENSION_NAME, VK_MAX_EXTENSION_NAME_SIZE); 4615db71995Sopenharmony_ci#endif 4625db71995Sopenharmony_ci pProperties[ext_count].specVersion = 2; 4635db71995Sopenharmony_ci ext_count++; 4645db71995Sopenharmony_ci } 4655db71995Sopenharmony_ci#endif 4665db71995Sopenharmony_ci#if TEST_LAYER_EXPORT_PRESENT_IMAGE 4675db71995Sopenharmony_ci if (ext_count < count) { 4685db71995Sopenharmony_ci#if defined(_WIN32) 4695db71995Sopenharmony_ci strncpy_s(pProperties[ext_count].extensionName, VK_MAX_EXTENSION_NAME_SIZE, 4705db71995Sopenharmony_ci VK_KHR_SHARED_PRESENTABLE_IMAGE_EXTENSION_NAME, 4715db71995Sopenharmony_ci strlen(VK_KHR_SHARED_PRESENTABLE_IMAGE_EXTENSION_NAME) + 1); 4725db71995Sopenharmony_ci#else 4735db71995Sopenharmony_ci strncpy(pProperties[ext_count].extensionName, VK_KHR_SHARED_PRESENTABLE_IMAGE_EXTENSION_NAME, 4745db71995Sopenharmony_ci VK_MAX_EXTENSION_NAME_SIZE); 4755db71995Sopenharmony_ci#endif 4765db71995Sopenharmony_ci pProperties[ext_count].specVersion = 1; 4775db71995Sopenharmony_ci ext_count++; 4785db71995Sopenharmony_ci } 4795db71995Sopenharmony_ci#endif 4805db71995Sopenharmony_ci } 4815db71995Sopenharmony_ci *pPropertyCount = ext_count; 4825db71995Sopenharmony_ci } 4835db71995Sopenharmony_ci return result; 4845db71995Sopenharmony_ci } else { 4855db71995Sopenharmony_ci return phys_dev->inst->layer_disp.EnumerateDeviceExtensionProperties(vk_phys_dev, pLayerName, pPropertyCount, pProperties); 4865db71995Sopenharmony_ci } 4875db71995Sopenharmony_ci} 4885db71995Sopenharmony_ci 4895db71995Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL wrap_vkCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo, 4905db71995Sopenharmony_ci const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) { 4915db71995Sopenharmony_ci wrapped_phys_dev_obj *phys_dev; 4925db71995Sopenharmony_ci auto vk_phys_dev = unwrap_phys_dev(physicalDevice, &phys_dev); 4935db71995Sopenharmony_ci VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO); 4945db71995Sopenharmony_ci PFN_vkGetInstanceProcAddr pfn_get_inst_proc_addr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr; 4955db71995Sopenharmony_ci PFN_vkGetDeviceProcAddr pfn_get_dev_proc_addr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr; 4965db71995Sopenharmony_ci PFN_vkCreateDevice pfn_create_device = (PFN_vkCreateDevice)pfn_get_inst_proc_addr(phys_dev->inst->obj, "vkCreateDevice"); 4975db71995Sopenharmony_ci if (pfn_create_device == NULL) { 4985db71995Sopenharmony_ci return VK_ERROR_INITIALIZATION_FAILED; 4995db71995Sopenharmony_ci } 5005db71995Sopenharmony_ci // Advance the link info for the next element on the chain 5015db71995Sopenharmony_ci chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; 5025db71995Sopenharmony_ci VkResult result = pfn_create_device(vk_phys_dev, pCreateInfo, pAllocator, pDevice); 5035db71995Sopenharmony_ci if (result != VK_SUCCESS) { 5045db71995Sopenharmony_ci return result; 5055db71995Sopenharmony_ci } 5065db71995Sopenharmony_ci auto dev = new wrapped_dev_obj; 5075db71995Sopenharmony_ci if (!dev) { 5085db71995Sopenharmony_ci return VK_ERROR_OUT_OF_HOST_MEMORY; 5095db71995Sopenharmony_ci } 5105db71995Sopenharmony_ci saved_wrapped_handles.devices.push_back(dev); 5115db71995Sopenharmony_ci memset(dev, 0, sizeof(*dev)); 5125db71995Sopenharmony_ci dev->obj = *pDevice; 5135db71995Sopenharmony_ci dev->pfn_get_dev_proc_addr = pfn_get_dev_proc_addr; 5145db71995Sopenharmony_ci *pDevice = reinterpret_cast<VkDevice>(dev); 5155db71995Sopenharmony_ci 5165db71995Sopenharmony_ci // Store the loader callback for initializing created dispatchable objects 5175db71995Sopenharmony_ci chain_info = get_chain_info(pCreateInfo, VK_LOADER_DATA_CALLBACK); 5185db71995Sopenharmony_ci if (chain_info) { 5195db71995Sopenharmony_ci dev->pfn_dev_init = chain_info->u.pfnSetDeviceLoaderData; 5205db71995Sopenharmony_ci result = dev->pfn_dev_init(dev->obj, reinterpret_cast<void *>(dev)); 5215db71995Sopenharmony_ci if (VK_SUCCESS != result) { 5225db71995Sopenharmony_ci return result; 5235db71995Sopenharmony_ci } 5245db71995Sopenharmony_ci } else { 5255db71995Sopenharmony_ci dev->pfn_dev_init = NULL; 5265db71995Sopenharmony_ci } 5275db71995Sopenharmony_ci 5285db71995Sopenharmony_ci // Initialize layer's dispatch table 5295db71995Sopenharmony_ci layer_init_device_dispatch_table(dev->obj, &dev->disp, pfn_get_dev_proc_addr); 5305db71995Sopenharmony_ci 5315db71995Sopenharmony_ci for (uint32_t ext = 0; ext < pCreateInfo->enabledExtensionCount; ++ext) { 5325db71995Sopenharmony_ci if (!strcmp(pCreateInfo->ppEnabledExtensionNames[ext], VK_KHR_MAINTENANCE1_EXTENSION_NAME)) { 5335db71995Sopenharmony_ci#if TEST_LAYER_EXPORT_MAINT_1 5345db71995Sopenharmony_ci dev->maintanence_1_enabled = true; 5355db71995Sopenharmony_ci#endif 5365db71995Sopenharmony_ci } 5375db71995Sopenharmony_ci if (!strcmp(pCreateInfo->ppEnabledExtensionNames[ext], VK_KHR_SHARED_PRESENTABLE_IMAGE_EXTENSION_NAME)) { 5385db71995Sopenharmony_ci#if TEST_LAYER_EXPORT_PRESENT_IMAGE 5395db71995Sopenharmony_ci dev->present_image_enabled = true; 5405db71995Sopenharmony_ci#endif 5415db71995Sopenharmony_ci } 5425db71995Sopenharmony_ci if (!strcmp(pCreateInfo->ppEnabledExtensionNames[ext], VK_EXT_DEBUG_MARKER_EXTENSION_NAME)) { 5435db71995Sopenharmony_ci dev->debug_marker_enabled = true; 5445db71995Sopenharmony_ci } 5455db71995Sopenharmony_ci } 5465db71995Sopenharmony_ci dev->debug_utils_enabled = phys_dev->inst->debug_utils_enabled; 5475db71995Sopenharmony_ci 5485db71995Sopenharmony_ci return result; 5495db71995Sopenharmony_ci} 5505db71995Sopenharmony_ci 5515db71995Sopenharmony_ciVKAPI_ATTR void VKAPI_CALL wrap_vkDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) { 5525db71995Sopenharmony_ci wrapped_dev_obj *dev; 5535db71995Sopenharmony_ci auto vk_dev = unwrap_device(device, &dev); 5545db71995Sopenharmony_ci dev->disp.DestroyDevice(vk_dev, pAllocator); 5555db71995Sopenharmony_ci delete dev; 5565db71995Sopenharmony_ci} 5575db71995Sopenharmony_ci 5585db71995Sopenharmony_ci// Fake instance extension support 5595db71995Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL wrap_vkReleaseDisplayEXT(VkPhysicalDevice, VkDisplayKHR) { return VK_SUCCESS; } 5605db71995Sopenharmony_ci 5615db71995Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL wrap_vkGetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice, VkSurfaceKHR, 5625db71995Sopenharmony_ci VkSurfaceCapabilities2EXT *pSurfaceCapabilities) { 5635db71995Sopenharmony_ci if (nullptr != pSurfaceCapabilities) { 5645db71995Sopenharmony_ci pSurfaceCapabilities->minImageCount = 7; 5655db71995Sopenharmony_ci pSurfaceCapabilities->maxImageCount = 12; 5665db71995Sopenharmony_ci pSurfaceCapabilities->maxImageArrayLayers = 365; 5675db71995Sopenharmony_ci } 5685db71995Sopenharmony_ci return VK_SUCCESS; 5695db71995Sopenharmony_ci} 5705db71995Sopenharmony_ci 5715db71995Sopenharmony_ci// Fake device extension support 5725db71995Sopenharmony_ciVKAPI_ATTR void VKAPI_CALL wrap_vkTrimCommandPoolKHR(VkDevice, VkCommandPool, VkCommandPoolTrimFlags) {} 5735db71995Sopenharmony_ci 5745db71995Sopenharmony_ci// Return an odd error so we can verify that this actually got called 5755db71995Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL wrap_vkGetSwapchainStatusKHR(VkDevice, VkSwapchainKHR) { return VK_ERROR_NATIVE_WINDOW_IN_USE_KHR; } 5765db71995Sopenharmony_ci 5775db71995Sopenharmony_ci// Debug utils & debug marker ext stubs 5785db71995Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL wrap_vkDebugMarkerSetObjectTagEXT(VkDevice device, const VkDebugMarkerObjectTagInfoEXT *pTagInfo) { 5795db71995Sopenharmony_ci VkDebugMarkerObjectTagInfoEXT new_info = *pTagInfo; 5805db71995Sopenharmony_ci wrapped_dev_obj *dev; 5815db71995Sopenharmony_ci auto vk_dev = unwrap_device(device, &dev); 5825db71995Sopenharmony_ci if (pTagInfo && pTagInfo->objectType == VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT) { 5835db71995Sopenharmony_ci wrapped_phys_dev_obj *phys_dev; 5845db71995Sopenharmony_ci auto vk_phys_dev = unwrap_phys_dev((VkPhysicalDevice)(uintptr_t)(pTagInfo->object), &phys_dev); 5855db71995Sopenharmony_ci if (vk_phys_dev == VK_NULL_HANDLE) return VK_ERROR_DEVICE_LOST; 5865db71995Sopenharmony_ci new_info.object = (uint64_t)(uintptr_t)vk_phys_dev; 5875db71995Sopenharmony_ci } 5885db71995Sopenharmony_ci if (pTagInfo && pTagInfo->objectType == VK_DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT) { 5895db71995Sopenharmony_ci // TODO 5905db71995Sopenharmony_ci } 5915db71995Sopenharmony_ci if (pTagInfo && pTagInfo->objectType == VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT) { 5925db71995Sopenharmony_ci wrapped_inst_obj *inst; 5935db71995Sopenharmony_ci auto instance = unwrap_instance((VkInstance)(uintptr_t)(pTagInfo->object), &inst); 5945db71995Sopenharmony_ci if (instance == VK_NULL_HANDLE) return VK_ERROR_DEVICE_LOST; 5955db71995Sopenharmony_ci new_info.object = (uint64_t)(uintptr_t)instance; 5965db71995Sopenharmony_ci } 5975db71995Sopenharmony_ci return dev->disp.DebugMarkerSetObjectTagEXT(vk_dev, &new_info); 5985db71995Sopenharmony_ci} 5995db71995Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL wrap_vkDebugMarkerSetObjectNameEXT(VkDevice device, 6005db71995Sopenharmony_ci const VkDebugMarkerObjectNameInfoEXT *pNameInfo) { 6015db71995Sopenharmony_ci VkDebugMarkerObjectNameInfoEXT new_info = *pNameInfo; 6025db71995Sopenharmony_ci wrapped_dev_obj *dev; 6035db71995Sopenharmony_ci auto vk_dev = unwrap_device(device, &dev); 6045db71995Sopenharmony_ci if (pNameInfo && pNameInfo->objectType == VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT) { 6055db71995Sopenharmony_ci wrapped_phys_dev_obj *phys_dev; 6065db71995Sopenharmony_ci auto vk_phys_dev = unwrap_phys_dev((VkPhysicalDevice)(uintptr_t)(pNameInfo->object), &phys_dev); 6075db71995Sopenharmony_ci if (vk_phys_dev == VK_NULL_HANDLE) return VK_ERROR_DEVICE_LOST; 6085db71995Sopenharmony_ci new_info.object = (uint64_t)(uintptr_t)vk_phys_dev; 6095db71995Sopenharmony_ci } 6105db71995Sopenharmony_ci if (pNameInfo && pNameInfo->objectType == VK_DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT) { 6115db71995Sopenharmony_ci // TODO 6125db71995Sopenharmony_ci } 6135db71995Sopenharmony_ci if (pNameInfo && pNameInfo->objectType == VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT) { 6145db71995Sopenharmony_ci wrapped_inst_obj *inst; 6155db71995Sopenharmony_ci auto instance = unwrap_instance((VkInstance)(uintptr_t)(pNameInfo->object), &inst); 6165db71995Sopenharmony_ci if (instance == VK_NULL_HANDLE) return VK_ERROR_DEVICE_LOST; 6175db71995Sopenharmony_ci new_info.object = (uint64_t)(uintptr_t)instance; 6185db71995Sopenharmony_ci } 6195db71995Sopenharmony_ci return dev->disp.DebugMarkerSetObjectNameEXT(vk_dev, &new_info); 6205db71995Sopenharmony_ci} 6215db71995Sopenharmony_ci// Debug Marker functions that are not supported: 6225db71995Sopenharmony_ci// vkCmdDebugMarkerBeginEXT 6235db71995Sopenharmony_ci// vkCmdDebugMarkerEndEXT 6245db71995Sopenharmony_ci// vkCmdDebugMarkerInsertEXT 6255db71995Sopenharmony_ci 6265db71995Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL wrap_vkSetDebugUtilsObjectNameEXT(VkDevice device, const VkDebugUtilsObjectNameInfoEXT *pNameInfo) { 6275db71995Sopenharmony_ci VkDebugUtilsObjectNameInfoEXT new_info = *pNameInfo; 6285db71995Sopenharmony_ci wrapped_dev_obj *dev; 6295db71995Sopenharmony_ci auto vk_dev = unwrap_device(device, &dev); 6305db71995Sopenharmony_ci if (pNameInfo && pNameInfo->objectType == VK_OBJECT_TYPE_PHYSICAL_DEVICE) { 6315db71995Sopenharmony_ci wrapped_phys_dev_obj *phys_dev; 6325db71995Sopenharmony_ci auto vk_phys_dev = unwrap_phys_dev((VkPhysicalDevice)(uintptr_t)(pNameInfo->objectHandle), &phys_dev); 6335db71995Sopenharmony_ci if (vk_phys_dev == VK_NULL_HANDLE) return VK_ERROR_DEVICE_LOST; 6345db71995Sopenharmony_ci new_info.objectHandle = (uint64_t)(uintptr_t)vk_phys_dev; 6355db71995Sopenharmony_ci } 6365db71995Sopenharmony_ci if (pNameInfo && pNameInfo->objectType == VK_OBJECT_TYPE_SURFACE_KHR) { 6375db71995Sopenharmony_ci // TODO 6385db71995Sopenharmony_ci } 6395db71995Sopenharmony_ci if (pNameInfo && pNameInfo->objectType == VK_OBJECT_TYPE_INSTANCE) { 6405db71995Sopenharmony_ci wrapped_inst_obj *inst; 6415db71995Sopenharmony_ci auto instance = unwrap_instance((VkInstance)(uintptr_t)(pNameInfo->objectHandle), &inst); 6425db71995Sopenharmony_ci if (instance == VK_NULL_HANDLE) return VK_ERROR_DEVICE_LOST; 6435db71995Sopenharmony_ci new_info.objectHandle = (uint64_t)(uintptr_t)instance; 6445db71995Sopenharmony_ci } 6455db71995Sopenharmony_ci return dev->disp.SetDebugUtilsObjectNameEXT(vk_dev, &new_info); 6465db71995Sopenharmony_ci} 6475db71995Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL wrap_vkSetDebugUtilsObjectTagEXT(VkDevice device, const VkDebugUtilsObjectTagInfoEXT *pTagInfo) { 6485db71995Sopenharmony_ci VkDebugUtilsObjectTagInfoEXT new_info = *pTagInfo; 6495db71995Sopenharmony_ci wrapped_dev_obj *dev; 6505db71995Sopenharmony_ci auto vk_dev = unwrap_device(device, &dev); 6515db71995Sopenharmony_ci if (pTagInfo && pTagInfo->objectType == VK_OBJECT_TYPE_PHYSICAL_DEVICE) { 6525db71995Sopenharmony_ci wrapped_phys_dev_obj *phys_dev; 6535db71995Sopenharmony_ci auto vk_phys_dev = unwrap_phys_dev((VkPhysicalDevice)(uintptr_t)(pTagInfo->objectHandle), &phys_dev); 6545db71995Sopenharmony_ci if (vk_phys_dev == VK_NULL_HANDLE) return VK_ERROR_DEVICE_LOST; 6555db71995Sopenharmony_ci new_info.objectHandle = (uint64_t)(uintptr_t)vk_phys_dev; 6565db71995Sopenharmony_ci } 6575db71995Sopenharmony_ci if (pTagInfo && pTagInfo->objectType == VK_OBJECT_TYPE_SURFACE_KHR) { 6585db71995Sopenharmony_ci // TODO 6595db71995Sopenharmony_ci } 6605db71995Sopenharmony_ci if (pTagInfo && pTagInfo->objectType == VK_OBJECT_TYPE_INSTANCE) { 6615db71995Sopenharmony_ci wrapped_inst_obj *inst; 6625db71995Sopenharmony_ci auto instance = unwrap_instance((VkInstance)(uintptr_t)(pTagInfo->objectHandle), &inst); 6635db71995Sopenharmony_ci if (instance == VK_NULL_HANDLE) return VK_ERROR_DEVICE_LOST; 6645db71995Sopenharmony_ci new_info.objectHandle = (uint64_t)(uintptr_t)instance; 6655db71995Sopenharmony_ci } 6665db71995Sopenharmony_ci return dev->disp.SetDebugUtilsObjectTagEXT(vk_dev, &new_info); 6675db71995Sopenharmony_ci} 6685db71995Sopenharmony_ci// Debug utils functions that are not supported 6695db71995Sopenharmony_ci// vkQueueBeginDebugUtilsLabelEXT 6705db71995Sopenharmony_ci// vkQueueEndDebugUtilsLabelEXT 6715db71995Sopenharmony_ci// vkQueueInsertDebugUtilsLabelEXT 6725db71995Sopenharmony_ci// vkCmdBeginDebugUtilsLabelEXT 6735db71995Sopenharmony_ci// vkCmdEndDebugUtilsLabelEXT 6745db71995Sopenharmony_ci// vkCmdInsertDebugUtilsLabelEXT 6755db71995Sopenharmony_ci 6765db71995Sopenharmony_ciPFN_vkVoidFunction layer_intercept_device_proc(wrapped_dev_obj *dev, const char *name) { 6775db71995Sopenharmony_ci if (!name || name[0] != 'v' || name[1] != 'k') return NULL; 6785db71995Sopenharmony_ci 6795db71995Sopenharmony_ci name += 2; 6805db71995Sopenharmony_ci if (!strcmp(name, "CreateDevice")) return (PFN_vkVoidFunction)wrap_vkCreateDevice; 6815db71995Sopenharmony_ci if (!strcmp(name, "DestroyDevice")) return (PFN_vkVoidFunction)wrap_vkDestroyDevice; 6825db71995Sopenharmony_ci 6835db71995Sopenharmony_ci if (dev->maintanence_1_enabled && !strcmp(name, "TrimCommandPoolKHR")) return (PFN_vkVoidFunction)wrap_vkTrimCommandPoolKHR; 6845db71995Sopenharmony_ci if (dev->present_image_enabled && !strcmp(name, "GetSwapchainStatusKHR")) 6855db71995Sopenharmony_ci return (PFN_vkVoidFunction)wrap_vkGetSwapchainStatusKHR; 6865db71995Sopenharmony_ci 6875db71995Sopenharmony_ci if (dev->debug_marker_enabled && !strcmp(name, "DebugMarkerSetObjectTagEXT")) 6885db71995Sopenharmony_ci return (PFN_vkVoidFunction)wrap_vkDebugMarkerSetObjectTagEXT; 6895db71995Sopenharmony_ci if (dev->debug_marker_enabled && !strcmp(name, "DebugMarkerSetObjectNameEXT")) 6905db71995Sopenharmony_ci return (PFN_vkVoidFunction)wrap_vkDebugMarkerSetObjectNameEXT; 6915db71995Sopenharmony_ci if (dev->debug_utils_enabled && !strcmp(name, "SetDebugUtilsObjectNameEXT")) 6925db71995Sopenharmony_ci return (PFN_vkVoidFunction)wrap_vkSetDebugUtilsObjectNameEXT; 6935db71995Sopenharmony_ci if (dev->debug_utils_enabled && !strcmp(name, "SetDebugUtilsObjectTagEXT")) 6945db71995Sopenharmony_ci return (PFN_vkVoidFunction)wrap_vkSetDebugUtilsObjectTagEXT; 6955db71995Sopenharmony_ci 6965db71995Sopenharmony_ci return NULL; 6975db71995Sopenharmony_ci} 6985db71995Sopenharmony_ci 6995db71995Sopenharmony_ciVKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL wrap_vkGetDeviceProcAddr(VkDevice device, const char *funcName) { 7005db71995Sopenharmony_ci PFN_vkVoidFunction addr; 7015db71995Sopenharmony_ci 7025db71995Sopenharmony_ci if (!strcmp("vkGetDeviceProcAddr", funcName)) { 7035db71995Sopenharmony_ci return (PFN_vkVoidFunction)wrap_vkGetDeviceProcAddr; 7045db71995Sopenharmony_ci } 7055db71995Sopenharmony_ci 7065db71995Sopenharmony_ci if (device == VK_NULL_HANDLE) { 7075db71995Sopenharmony_ci return NULL; 7085db71995Sopenharmony_ci } 7095db71995Sopenharmony_ci 7105db71995Sopenharmony_ci wrapped_dev_obj *dev; 7115db71995Sopenharmony_ci unwrap_device(device, &dev); 7125db71995Sopenharmony_ci 7135db71995Sopenharmony_ci addr = layer_intercept_device_proc(dev, funcName); 7145db71995Sopenharmony_ci if (addr) return addr; 7155db71995Sopenharmony_ci 7165db71995Sopenharmony_ci return dev->pfn_get_dev_proc_addr(dev->obj, funcName); 7175db71995Sopenharmony_ci} 7185db71995Sopenharmony_ci 7195db71995Sopenharmony_ciPFN_vkVoidFunction layer_intercept_instance_proc(wrapped_inst_obj *inst, const char *name) { 7205db71995Sopenharmony_ci if (!name || name[0] != 'v' || name[1] != 'k') return NULL; 7215db71995Sopenharmony_ci 7225db71995Sopenharmony_ci name += 2; 7235db71995Sopenharmony_ci if (!strcmp(name, "DestroyInstance")) return (PFN_vkVoidFunction)wrap_vkDestroyInstance; 7245db71995Sopenharmony_ci if (!strcmp(name, "CreateDevice")) return (PFN_vkVoidFunction)wrap_vkCreateDevice; 7255db71995Sopenharmony_ci if (!strcmp(name, "EnumeratePhysicalDevices")) return (PFN_vkVoidFunction)wrap_vkEnumeratePhysicalDevices; 7265db71995Sopenharmony_ci 7275db71995Sopenharmony_ci if (!strcmp(name, "EnumerateDeviceExtensionProperties")) return (PFN_vkVoidFunction)wrap_vkEnumerateDeviceExtensionProperties; 7285db71995Sopenharmony_ci 7295db71995Sopenharmony_ci if (!strcmp(name, "CreateDebugUtilsMessengerEXT")) return (PFN_vkVoidFunction)wrap_vkCreateDebugUtilsMessengerEXT; 7305db71995Sopenharmony_ci if (!strcmp(name, "DestroyDebugUtilsMessengerEXT")) return (PFN_vkVoidFunction)wrap_vkDestroyDebugUtilsMessengerEXT; 7315db71995Sopenharmony_ci 7325db71995Sopenharmony_ci if (!strcmp(name, "GetPhysicalDeviceProperties")) return (PFN_vkVoidFunction)vkGetPhysicalDeviceProperties; 7335db71995Sopenharmony_ci if (!strcmp(name, "GetPhysicalDeviceQueueFamilyProperties")) 7345db71995Sopenharmony_ci return (PFN_vkVoidFunction)wrap_vkGetPhysicalDeviceQueueFamilyProperties; 7355db71995Sopenharmony_ci 7365db71995Sopenharmony_ci#if defined(VK_USE_PLATFORM_ANDROID_KHR) 7375db71995Sopenharmony_ci if (!strcmp(name, "CreateAndroidSurfaceKHR")) return (PFN_vkVoidFunction)wrap_vkCreateAndroidSurfaceKHR; 7385db71995Sopenharmony_ci#endif // VK_USE_PLATFORM_ANDROID_KHR 7395db71995Sopenharmony_ci 7405db71995Sopenharmony_ci#if defined(VK_USE_PLATFORM_WIN32_KHR) 7415db71995Sopenharmony_ci if (!strcmp(name, "CreateWin32SurfaceKHR")) return (PFN_vkVoidFunction)wrap_vkCreateWin32SurfaceKHR; 7425db71995Sopenharmony_ci#endif // VK_USE_PLATFORM_WIN32_KHR 7435db71995Sopenharmony_ci 7445db71995Sopenharmony_ci#if defined(VK_USE_PLATFORM_WAYLAND_KHR) 7455db71995Sopenharmony_ci if (!strcmp(name, "CreateWaylandSurfaceKHR")) return (PFN_vkVoidFunction)wrap_vkCreateWaylandSurfaceKHR; 7465db71995Sopenharmony_ci#endif // VK_USE_PLATFORM_WAYLAND_KHR 7475db71995Sopenharmony_ci 7485db71995Sopenharmony_ci#if defined(VK_USE_PLATFORM_XCB_KHR) 7495db71995Sopenharmony_ci if (!strcmp(name, "CreateXcbSurfaceKHR")) return (PFN_vkVoidFunction)wrap_vkCreateXcbSurfaceKHR; 7505db71995Sopenharmony_ci#endif // VK_USE_PLATFORM_XCB_KHR 7515db71995Sopenharmony_ci 7525db71995Sopenharmony_ci#if defined(VK_USE_PLATFORM_XLIB_KHR) 7535db71995Sopenharmony_ci if (!strcmp(name, "CreateXlibSurfaceKHR")) return (PFN_vkVoidFunction)wrap_vkCreateXlibSurfaceKHR; 7545db71995Sopenharmony_ci#endif // VK_USE_PLATFORM_XLIB_KHR 7555db71995Sopenharmony_ci 7565db71995Sopenharmony_ci#if defined(VK_USE_PLATFORM_DIRECTFB_EXT) 7575db71995Sopenharmony_ci if (!strcmp(name, "CreateDirectFBSurfaceEXT")) return (PFN_vkVoidFunction)wrap_vkCreateDirectFBSurfaceEXT; 7585db71995Sopenharmony_ci#endif // VK_USE_PLATFORM_DIRECTFB_EXT 7595db71995Sopenharmony_ci 7605db71995Sopenharmony_ci#if defined(VK_USE_PLATFORM_MACOS_MVK) 7615db71995Sopenharmony_ci if (!strcmp(name, "CreateMacOSSurfaceMVK")) return (PFN_vkVoidFunction)wrap_vkCreateMacOSSurfaceMVK; 7625db71995Sopenharmony_ci#endif // VK_USE_PLATFORM_MACOS_MVK 7635db71995Sopenharmony_ci 7645db71995Sopenharmony_ci#if defined(VK_USE_PLATFORM_IOS_MVK) 7655db71995Sopenharmony_ci if (!strcmp(name, "CreateIOSSurfaceMVK")) return (PFN_vkVoidFunction)wrap_vkCreateIOSSurfaceMVK; 7665db71995Sopenharmony_ci#endif // VK_USE_PLATFORM_IOS_MVK 7675db71995Sopenharmony_ci 7685db71995Sopenharmony_ci#if defined(VK_USE_PLATFORM_GGP) 7695db71995Sopenharmony_ci if (!strcmp(name, "CreateStreamDescriptorSurfaceGGP")) return (PFN_vkVoidFunction)wrap_vkCreateStreamDescriptorSurfaceGGP; 7705db71995Sopenharmony_ci#endif // VK_USE_PLATFORM_GGP 7715db71995Sopenharmony_ci 7725db71995Sopenharmony_ci#if defined(VK_USE_PLATFORM_METAL_EXT) 7735db71995Sopenharmony_ci if (!strcmp(name, "CreateMetalSurfaceEXT")) return (PFN_vkVoidFunction)wrap_vkCreateMetalSurfaceEXT; 7745db71995Sopenharmony_ci#endif // VK_USE_PLATFORM_METAL_EXT 7755db71995Sopenharmony_ci 7765db71995Sopenharmony_ci#if defined(VK_USE_PLATFORM_SCREEN_QNX) 7775db71995Sopenharmony_ci if (!strcmp(name, "CreateScreenSurfaceQNX")) return (PFN_vkVoidFunction)wrap_vkCreateScreenSurfaceQNX; 7785db71995Sopenharmony_ci#endif // VK_USE_PLATFORM_SCREEN_QNX 7795db71995Sopenharmony_ci if (!strcmp(name, "DestroySurfaceKHR")) return (PFN_vkVoidFunction)wrap_vkDestroySurfaceKHR; 7805db71995Sopenharmony_ci 7815db71995Sopenharmony_ci if (inst->direct_display_enabled && !strcmp(name, "ReleaseDisplayEXT")) return (PFN_vkVoidFunction)wrap_vkReleaseDisplayEXT; 7825db71995Sopenharmony_ci if (inst->display_surf_counter_enabled && !strcmp(name, "GetPhysicalDeviceSurfaceCapabilities2EXT")) 7835db71995Sopenharmony_ci return (PFN_vkVoidFunction)wrap_vkGetPhysicalDeviceSurfaceCapabilities2EXT; 7845db71995Sopenharmony_ci 7855db71995Sopenharmony_ci // instance_proc needs to be able to query device commands even if the extension isn't enabled (because it isn't known at this 7865db71995Sopenharmony_ci // time) 7875db71995Sopenharmony_ci if (!strcmp(name, "TrimCommandPoolKHR")) return (PFN_vkVoidFunction)wrap_vkTrimCommandPoolKHR; 7885db71995Sopenharmony_ci if (!strcmp(name, "GetSwapchainStatusKHR")) return (PFN_vkVoidFunction)wrap_vkGetSwapchainStatusKHR; 7895db71995Sopenharmony_ci 7905db71995Sopenharmony_ci if (!strcmp(name, "DebugMarkerSetObjectTagEXT")) return (PFN_vkVoidFunction)wrap_vkDebugMarkerSetObjectTagEXT; 7915db71995Sopenharmony_ci if (!strcmp(name, "DebugMarkerSetObjectNameEXT")) return (PFN_vkVoidFunction)wrap_vkDebugMarkerSetObjectNameEXT; 7925db71995Sopenharmony_ci if (inst->debug_utils_enabled && !strcmp(name, "SetDebugUtilsObjectNameEXT")) 7935db71995Sopenharmony_ci return (PFN_vkVoidFunction)wrap_vkSetDebugUtilsObjectNameEXT; 7945db71995Sopenharmony_ci if (inst->debug_utils_enabled && !strcmp(name, "SetDebugUtilsObjectTagEXT")) 7955db71995Sopenharmony_ci return (PFN_vkVoidFunction)wrap_vkSetDebugUtilsObjectTagEXT; 7965db71995Sopenharmony_ci 7975db71995Sopenharmony_ci return NULL; 7985db71995Sopenharmony_ci} 7995db71995Sopenharmony_ci 8005db71995Sopenharmony_ciVKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL wrap_vkGetInstanceProcAddr(VkInstance instance, const char *funcName) { 8015db71995Sopenharmony_ci PFN_vkVoidFunction addr; 8025db71995Sopenharmony_ci 8035db71995Sopenharmony_ci if (!strcmp(funcName, "vkGetInstanceProcAddr")) return (PFN_vkVoidFunction)wrap_vkGetInstanceProcAddr; 8045db71995Sopenharmony_ci if (!strcmp(funcName, "vkCreateInstance")) return (PFN_vkVoidFunction)wrap_vkCreateInstance; 8055db71995Sopenharmony_ci 8065db71995Sopenharmony_ci if (instance == VK_NULL_HANDLE) { 8075db71995Sopenharmony_ci return NULL; 8085db71995Sopenharmony_ci } 8095db71995Sopenharmony_ci 8105db71995Sopenharmony_ci wrapped_inst_obj *inst; 8115db71995Sopenharmony_ci unwrap_instance(instance, &inst); 8125db71995Sopenharmony_ci 8135db71995Sopenharmony_ci addr = layer_intercept_instance_proc(inst, funcName); 8145db71995Sopenharmony_ci if (addr) return addr; 8155db71995Sopenharmony_ci 8165db71995Sopenharmony_ci VkLayerInstanceDispatchTable *pTable = &inst->layer_disp; 8175db71995Sopenharmony_ci 8185db71995Sopenharmony_ci if (pTable->GetInstanceProcAddr == NULL) return NULL; 8195db71995Sopenharmony_ci return pTable->GetInstanceProcAddr(inst->obj, funcName); 8205db71995Sopenharmony_ci} 8215db71995Sopenharmony_ci 8225db71995Sopenharmony_ciVKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL GetPhysicalDeviceProcAddr(VkInstance instance, const char *funcName) { 8235db71995Sopenharmony_ci assert(instance); 8245db71995Sopenharmony_ci 8255db71995Sopenharmony_ci wrapped_inst_obj *inst; 8265db71995Sopenharmony_ci unwrap_instance(instance, &inst); 8275db71995Sopenharmony_ci VkLayerInstanceDispatchTable *pTable = &inst->layer_disp; 8285db71995Sopenharmony_ci 8295db71995Sopenharmony_ci if (pTable->GetPhysicalDeviceProcAddr == NULL) return NULL; 8305db71995Sopenharmony_ci return pTable->GetPhysicalDeviceProcAddr(inst->obj, funcName); 8315db71995Sopenharmony_ci} 8325db71995Sopenharmony_ci 8335db71995Sopenharmony_ci} // namespace wrap_objects 8345db71995Sopenharmony_ci 8355db71995Sopenharmony_ciextern "C" { 8365db71995Sopenharmony_ci// loader-layer interface v0, just wrappers since there is only a layer 8375db71995Sopenharmony_ciVK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) { 8385db71995Sopenharmony_ci return wrap_objects::wrap_vkGetInstanceProcAddr(instance, funcName); 8395db71995Sopenharmony_ci} 8405db71995Sopenharmony_ci 8415db71995Sopenharmony_ciVK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice device, const char *funcName) { 8425db71995Sopenharmony_ci return wrap_objects::wrap_vkGetDeviceProcAddr(device, funcName); 8435db71995Sopenharmony_ci} 8445db71995Sopenharmony_ci 8455db71995Sopenharmony_ciVK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *, uint32_t *, 8465db71995Sopenharmony_ci VkExtensionProperties *) { 8475db71995Sopenharmony_ci assert(0); // TODO return wrap_objects::EnumerateInstanceExtensionProperties(pLayerName, pCount, pProperties); 8485db71995Sopenharmony_ci return VK_SUCCESS; 8495db71995Sopenharmony_ci} 8505db71995Sopenharmony_ci 8515db71995Sopenharmony_ciVK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *, VkLayerProperties *) { 8525db71995Sopenharmony_ci assert(0); // TODO return wrap_objects::EnumerateInstanceLayerProperties(pCount, pProperties); 8535db71995Sopenharmony_ci return VK_SUCCESS; 8545db71995Sopenharmony_ci} 8555db71995Sopenharmony_ci 8565db71995Sopenharmony_ciVK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL 8575db71995Sopenharmony_civkEnumerateDeviceExtensionProperties([[maybe_unused]] VkPhysicalDevice physicalDevice, const char *pLayerName, uint32_t *pCount, 8585db71995Sopenharmony_ci VkExtensionProperties *pProperties) { 8595db71995Sopenharmony_ci // the layer command handles VK_NULL_HANDLE just fine internally 8605db71995Sopenharmony_ci assert(physicalDevice == VK_NULL_HANDLE); 8615db71995Sopenharmony_ci return wrap_objects::wrap_vkEnumerateDeviceExtensionProperties(VK_NULL_HANDLE, pLayerName, pCount, pProperties); 8625db71995Sopenharmony_ci} 8635db71995Sopenharmony_ci 8645db71995Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugUtilsMessengerEXT(VkInstance instance, 8655db71995Sopenharmony_ci const VkDebugUtilsMessengerCreateInfoEXT *pCreateInfo, 8665db71995Sopenharmony_ci const VkAllocationCallbacks *pAllocator, 8675db71995Sopenharmony_ci VkDebugUtilsMessengerEXT *pMessenger) { 8685db71995Sopenharmony_ci return wrap_objects::wrap_vkCreateDebugUtilsMessengerEXT(instance, pCreateInfo, pAllocator, pMessenger); 8695db71995Sopenharmony_ci} 8705db71995Sopenharmony_ci 8715db71995Sopenharmony_ciVKAPI_ATTR void VKAPI_CALL vkDestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT messenger, 8725db71995Sopenharmony_ci const VkAllocationCallbacks *pAllocator) { 8735db71995Sopenharmony_ci return wrap_objects::wrap_vkDestroyDebugUtilsMessengerEXT(instance, messenger, pAllocator); 8745db71995Sopenharmony_ci} 8755db71995Sopenharmony_ci 8765db71995Sopenharmony_ciVKAPI_ATTR void VKAPI_CALL vkDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface, const VkAllocationCallbacks *pAllocator) { 8775db71995Sopenharmony_ci return wrap_objects::wrap_vkDestroySurfaceKHR(instance, surface, pAllocator); 8785db71995Sopenharmony_ci} 8795db71995Sopenharmony_ci 8805db71995Sopenharmony_ci#if defined(VK_USE_PLATFORM_ANDROID_KHR) 8815db71995Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL test_vkCreateAndroidSurfaceKHR(VkInstance instance, const VkAndroidSurfaceCreateInfoKHR *pCreateInfo, 8825db71995Sopenharmony_ci const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { 8835db71995Sopenharmony_ci return wrap_objects::wrap_vkCreateAndroidSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface); 8845db71995Sopenharmony_ci} 8855db71995Sopenharmony_ci#endif // VK_USE_PLATFORM_WIN32_KHR 8865db71995Sopenharmony_ci 8875db71995Sopenharmony_ci#if defined(VK_USE_PLATFORM_WIN32_KHR) 8885db71995Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL vkCreateWin32SurfaceKHR(VkInstance instance, const VkWin32SurfaceCreateInfoKHR *pCreateInfo, 8895db71995Sopenharmony_ci const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { 8905db71995Sopenharmony_ci return wrap_objects::wrap_vkCreateWin32SurfaceKHR(instance, pCreateInfo, pAllocator, pSurface); 8915db71995Sopenharmony_ci} 8925db71995Sopenharmony_ci#endif // VK_USE_PLATFORM_WIN32_KHR 8935db71995Sopenharmony_ci 8945db71995Sopenharmony_ci#if defined(VK_USE_PLATFORM_WAYLAND_KHR) 8955db71995Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL vkCreateWaylandSurfaceKHR(VkInstance instance, const VkWaylandSurfaceCreateInfoKHR *pCreateInfo, 8965db71995Sopenharmony_ci const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { 8975db71995Sopenharmony_ci return wrap_objects::wrap_vkCreateWaylandSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface); 8985db71995Sopenharmony_ci} 8995db71995Sopenharmony_ci#endif // VK_USE_PLATFORM_WAYLAND_KHR 9005db71995Sopenharmony_ci 9015db71995Sopenharmony_ci#if defined(VK_USE_PLATFORM_XCB_KHR) 9025db71995Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL vkCreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo, 9035db71995Sopenharmony_ci const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { 9045db71995Sopenharmony_ci return wrap_objects::wrap_vkCreateXcbSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface); 9055db71995Sopenharmony_ci} 9065db71995Sopenharmony_ci#endif // VK_USE_PLATFORM_XCB_KHR 9075db71995Sopenharmony_ci 9085db71995Sopenharmony_ci#if defined(VK_USE_PLATFORM_XLIB_KHR) 9095db71995Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL vkCreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo, 9105db71995Sopenharmony_ci const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { 9115db71995Sopenharmony_ci return wrap_objects::wrap_vkCreateXlibSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface); 9125db71995Sopenharmony_ci} 9135db71995Sopenharmony_ci#endif // VK_USE_PLATFORM_XLIB_KHR 9145db71995Sopenharmony_ci 9155db71995Sopenharmony_ci#if defined(VK_USE_PLATFORM_DIRECTFB_EXT) 9165db71995Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL vkCreateDirectFBSurfaceEXT(VkInstance instance, const VkDirectFBSurfaceCreateInfoEXT *pCreateInfo, 9175db71995Sopenharmony_ci const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { 9185db71995Sopenharmony_ci return wrap_objects::wrap_vkCreateDirectFBSurfaceEXT(instance, pCreateInfo, pAllocator, pSurface); 9195db71995Sopenharmony_ci} 9205db71995Sopenharmony_ci#endif // VK_USE_PLATFORM_DIRECTFB_EXT 9215db71995Sopenharmony_ci 9225db71995Sopenharmony_ci#if defined(VK_USE_PLATFORM_MACOS_MVK) 9235db71995Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL vkCreateMacOSSurfaceMVK(VkInstance instance, const VkMacOSSurfaceCreateInfoMVK *pCreateInfo, 9245db71995Sopenharmony_ci const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { 9255db71995Sopenharmony_ci return wrap_objects::wrap_vkCreateMacOSSurfaceMVK(instance, pCreateInfo, pAllocator, pSurface); 9265db71995Sopenharmony_ci} 9275db71995Sopenharmony_ci#endif // VK_USE_PLATFORM_MACOS_MVK 9285db71995Sopenharmony_ci 9295db71995Sopenharmony_ci#if defined(VK_USE_PLATFORM_IOS_MVK) 9305db71995Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL vkCreateIOSSurfaceMVK(VkInstance instance, const VkIOSSurfaceCreateInfoMVK *pCreateInfo, 9315db71995Sopenharmony_ci const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { 9325db71995Sopenharmony_ci return wrap_objects::wrap_vkCreateIOSSurfaceMVK(instance, pCreateInfo, pAllocator, pSurface); 9335db71995Sopenharmony_ci} 9345db71995Sopenharmony_ci#endif // VK_USE_PLATFORM_IOS_MVK 9355db71995Sopenharmony_ci 9365db71995Sopenharmony_ci#if defined(VK_USE_PLATFORM_GGP) 9375db71995Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL vkCreateStreamDescriptorSurfaceGGP(VkInstance instance, 9385db71995Sopenharmony_ci const VkStreamDescriptorSurfaceCreateInfoGGP *pCreateInfo, 9395db71995Sopenharmony_ci const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { 9405db71995Sopenharmony_ci return wrap_objects::wrap_vkCreateStreamDescriptorSurfaceGGP(instance, pCreateInfo, pAllocator, pSurface); 9415db71995Sopenharmony_ci} 9425db71995Sopenharmony_ci#endif // VK_USE_PLATFORM_GGP 9435db71995Sopenharmony_ci 9445db71995Sopenharmony_ci#if defined(VK_USE_PLATFORM_METAL_EXT) 9455db71995Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL vkCreateMetalSurfaceEXT(VkInstance instance, const VkMetalSurfaceCreateInfoEXT *pCreateInfo, 9465db71995Sopenharmony_ci const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { 9475db71995Sopenharmony_ci return wrap_objects::wrap_vkCreateMetalSurfaceEXT(instance, pCreateInfo, pAllocator, pSurface); 9485db71995Sopenharmony_ci} 9495db71995Sopenharmony_ci#endif // VK_USE_PLATFORM_METAL_EXT 9505db71995Sopenharmony_ci 9515db71995Sopenharmony_ci#if defined(VK_USE_PLATFORM_SCREEN_QNX) 9525db71995Sopenharmony_ciVKAPI_ATTR VkResult VKAPI_CALL vkCreateScreenSurfaceQNX(VkInstance instance, const VkScreenSurfaceCreateInfoQNX *pCreateInfo, 9535db71995Sopenharmony_ci const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { 9545db71995Sopenharmony_ci return wrap_objects::wrap_vkCreateScreenSurfaceQNX(instance, pCreateInfo, pAllocator, pSurface); 9555db71995Sopenharmony_ci} 9565db71995Sopenharmony_ci#endif // VK_USE_PLATFORM_SCREEN_QNX 9575db71995Sopenharmony_ci 9585db71995Sopenharmony_ciVK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_layerGetPhysicalDeviceProcAddr(VkInstance instance, 9595db71995Sopenharmony_ci const char *funcName) { 9605db71995Sopenharmony_ci return wrap_objects::GetPhysicalDeviceProcAddr(instance, funcName); 9615db71995Sopenharmony_ci} 9625db71995Sopenharmony_ci 9635db71995Sopenharmony_ciVK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *pVersionStruct) { 9645db71995Sopenharmony_ci assert(pVersionStruct != NULL); 9655db71995Sopenharmony_ci assert(pVersionStruct->sType == LAYER_NEGOTIATE_INTERFACE_STRUCT); 9665db71995Sopenharmony_ci 9675db71995Sopenharmony_ci // Fill in the function pointers if our version is at least capable of having the structure contain them. 9685db71995Sopenharmony_ci if (pVersionStruct->loaderLayerInterfaceVersion >= 2) { 9695db71995Sopenharmony_ci pVersionStruct->pfnGetInstanceProcAddr = wrap_objects::wrap_vkGetInstanceProcAddr; 9705db71995Sopenharmony_ci pVersionStruct->pfnGetDeviceProcAddr = wrap_objects::wrap_vkGetDeviceProcAddr; 9715db71995Sopenharmony_ci pVersionStruct->pfnGetPhysicalDeviceProcAddr = vk_layerGetPhysicalDeviceProcAddr; 9725db71995Sopenharmony_ci } 9735db71995Sopenharmony_ci 9745db71995Sopenharmony_ci if (pVersionStruct->loaderLayerInterfaceVersion < CURRENT_LOADER_LAYER_INTERFACE_VERSION) { 9755db71995Sopenharmony_ci wrap_objects::loader_layer_if_version = pVersionStruct->loaderLayerInterfaceVersion; 9765db71995Sopenharmony_ci } else if (pVersionStruct->loaderLayerInterfaceVersion > CURRENT_LOADER_LAYER_INTERFACE_VERSION) { 9775db71995Sopenharmony_ci pVersionStruct->loaderLayerInterfaceVersion = CURRENT_LOADER_LAYER_INTERFACE_VERSION; 9785db71995Sopenharmony_ci } 9795db71995Sopenharmony_ci 9805db71995Sopenharmony_ci return VK_SUCCESS; 9815db71995Sopenharmony_ci} 9825db71995Sopenharmony_ci} 983