1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "platform_vk.h"
16 
17 #include "util/log.h"
18 
19 RENDER_BEGIN_NAMESPACE()
20 using BASE_NS::string_view;
21 using BASE_NS::vector;
22 
CanDevicePresent(VkInstance instance,VkPhysicalDevice device,uint32_t queuefamily)23 bool CanDevicePresent(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily)
24 {
25 #if defined(VK_USE_PLATFORM_XCB_KHR)
26     PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR vkGetPhysicalDeviceXcbPresentationSupportKHR =
27         (PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR)vkGetInstanceProcAddr(
28             instance, "vkGetPhysicalDeviceXcbPresentationSupportKHR");
29     if (!vkGetPhysicalDeviceXcbPresentationSupportKHR) {
30         PLUGIN_LOG_E("Missing VK_KHR_xcb_surface extension");
31         return false;
32     }
33 
34     return false;
35 #elif defined(VK_USE_PLATFORM_XLIB_KHR)
36     PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR vkGetPhysicalDeviceXlibPresentationSupportKHR =
37         (PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR)vkGetInstanceProcAddr(
38             instance, "vkGetPhysicalDeviceXlibPresentationSupportKHR");
39     if (!vkGetPhysicalDeviceXlibPresentationSupportKHR) {
40         PLUGIN_LOG_E("Missing VK_KHR_xlib_surface extension");
41         return false;
42     }
43 
44     return false;
45 #else
46 #warning "Undefined WSI platform!"
47     return false;
48 #endif
49 }
50 
GetPlatformSurfaceName()51 const char* GetPlatformSurfaceName()
52 {
53 #if defined(VK_USE_PLATFORM_XCB_KHR)
54     return VK_KHR_XCB_SURFACE_EXTENSION_NAME;
55 #elif defined(VK_USE_PLATFORM_XLIB_KHR)
56     return VK_KHR_XLIB_SURFACE_EXTENSION_NAME;
57 #else
58 #error Missing platform surface type.
59 #endif
60 }
61 RENDER_END_NAMESPACE()