1 /*
2 * Copyright (C) 2023 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 #ifdef 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 #elif defined(VK_USE_PLATFORM_MACOS_MVK)
46 // NSView is always presentable
47 return true;
48 #elif defined(VK_USE_PLATFORM_METAL_EXT)
49 // Metal layers are always presentable
50 return true;
51 #else
52 #warning "Undefined WSI platform!"
53 return false;
54 #endif
55 }
56
GetPlatformSurfaceName()57 const char* GetPlatformSurfaceName()
58 {
59 #if defined(VK_KHR_XCB_SURFACE_EXTENSION_NAME)
60 return VK_KHR_XCB_SURFACE_EXTENSION_NAME;
61 #elif defined(VK_USE_PLATFORM_XLIB_KHR)
62 return VK_KHR_XLIB_SURFACE_EXTENSION_NAME;
63 #elif defined(VK_USE_PLATFORM_MACOS_MVK)
64 return VK_MVK_MACOS_SURFACE_EXTENSION_NAME;
65 #elif defined(VK_USE_PLATFORM_METAL_EXT)
66 return VK_EXT_METAL_SURFACE_EXTENSION_NAME;
67 #else
68 #error Missing platform surface type.
69 #endif
70 }
71 RENDER_END_NAMESPACE()