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 <vulkan/vulkan.h>
18 
19 #include "util/log.h"
20 
21 RENDER_BEGIN_NAMESPACE()
22 using BASE_NS::string_view;
23 using BASE_NS::vector;
24 
CanDevicePresent(VkInstance instance,VkPhysicalDevice device,uint32_t queuefamily)25 bool CanDevicePresent(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily)
26 {
27 #ifdef VK_USE_PLATFORM_WIN32_KHR
28     PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR vkGetPhysicalDeviceWin32PresentationSupportKHR =
29         (PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR) reinterpret_cast<void*>(
30             vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceWin32PresentationSupportKHR"));
31     if (!vkGetPhysicalDeviceWin32PresentationSupportKHR) {
32         PLUGIN_LOG_E("Missing VK_KHR_win32_surface extension");
33         return false;
34     }
35 
36     return vkGetPhysicalDeviceWin32PresentationSupportKHR(device, queuefamily) == VK_TRUE;
37 #else
38 #warning "Undefined WSI platform!"
39     return false;
40 #endif
41 }
42 
GetPlatformSurfaceName()43 const char* GetPlatformSurfaceName()
44 {
45 #ifdef VK_USE_PLATFORM_WIN32_KHR
46     return VK_KHR_WIN32_SURFACE_EXTENSION_NAME;
47 #else
48 #error Missing platform surface type.
49 #endif
50 }
51 RENDER_END_NAMESPACE()