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 
23 static constexpr string_view DEVICE_EXTENSION_PORTABILITY_SUBSET { "VK_KHR_portability_subset" };
24 
GetPlatformDeviceExtensions(vector<string_view> & extensions)25 void GetPlatformDeviceExtensions(vector<string_view>& extensions)
26 {
27     extensions.push_back(DEVICE_EXTENSION_PORTABILITY_SUBSET);
28 }
29 
CanDevicePresent(VkInstance instance,VkPhysicalDevice device,uint32_t queuefamily)30 bool CanDevicePresent(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily)
31 {
32 #if defined(VK_USE_PLATFORM_MACOS_MVK)
33     // NSView is always presentable
34     return true;
35 #elif defined(VK_USE_PLATFORM_METAL_EXT)
36     // Metal layers are always presentable
37     return true;
38 #else
39 #warning "Undefined WSI platform!"
40     return false;
41 #endif
42 }
43 
GetPlatformSurfaceName()44 const char* GetPlatformSurfaceName()
45 {
46 #if defined(VK_USE_PLATFORM_MACOS_MVK)
47     return VK_MVK_MACOS_SURFACE_EXTENSION_NAME;
48 #elif defined(VK_USE_PLATFORM_METAL_EXT)
49     return VK_EXT_METAL_SURFACE_EXTENSION_NAME;
50 #else
51 #error Missing platform surface type.
52 #endif
53 }
54 RENDER_END_NAMESPACE()