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 
16 #include "platform_vk.h"
17 
18 RENDER_BEGIN_NAMESPACE()
19 using BASE_NS::string;
20 using BASE_NS::string_view;
21 using BASE_NS::unordered_map;
22 using BASE_NS::vector;
23 namespace {
24 static constexpr string_view DEVICE_EXTENSION_EXTERNAL_MEMORY { VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME };
25 static constexpr string_view DEVICE_EXTENSION_EXTERNAL_MEMORY_CAPABILITIES {
26     VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME
27 };
28 static constexpr string_view DEVICE_EXTENSION_GET_MEMORY_REQUIREMENTS2 {
29     VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME
30 };
31 static constexpr string_view DEVICE_EXTENSION_SAMPLER_YCBCR_CONVERSION {
32     VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME
33 };
34 static constexpr string_view DEVICE_EXTENSION_QUEUE_FAMILY_FOREIGN { VK_EXT_QUEUE_FAMILY_FOREIGN_EXTENSION_NAME };
35 static constexpr string_view DEVICE_EXTENSION_OPENHARMONY_EXTERNAL_MEMORY_OHOS_NATIVE_BUFFER {
36     VK_OHOS_NATIVE_BUFFER_EXTENSION_NAME
37 };
38 } // namespace
39 
GetPlatformDeviceExtensions(vector<string_view> & extensions)40 void GetPlatformDeviceExtensions(vector<string_view>& extensions)
41 {
42     extensions.push_back(DEVICE_EXTENSION_EXTERNAL_MEMORY);
43     extensions.push_back(DEVICE_EXTENSION_EXTERNAL_MEMORY_CAPABILITIES);
44     extensions.push_back(DEVICE_EXTENSION_GET_MEMORY_REQUIREMENTS2);
45     extensions.push_back(DEVICE_EXTENSION_SAMPLER_YCBCR_CONVERSION);
46     extensions.push_back(DEVICE_EXTENSION_QUEUE_FAMILY_FOREIGN);
47     extensions.push_back(DEVICE_EXTENSION_OPENHARMONY_EXTERNAL_MEMORY_OHOS_NATIVE_BUFFER);
48 }
49 
GetEnabledPlatformDeviceExtensions(const unordered_map<string,uint32_t> & enabledDeviceExtensions)50 PlatformDeviceExtensions GetEnabledPlatformDeviceExtensions(
51     const unordered_map<string, uint32_t>& enabledDeviceExtensions)
52 {
53     return PlatformDeviceExtensions { enabledDeviceExtensions.contains(
54         DEVICE_EXTENSION_OPENHARMONY_EXTERNAL_MEMORY_OHOS_NATIVE_BUFFER) };
55 }
56 RENDER_END_NAMESPACE()
57