• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #ifndef VULKAN_CREATE_FUNCTIONS_VK_H
17 #define VULKAN_CREATE_FUNCTIONS_VK_H
18 
19 #include <cstdint>
20 #include <vulkan/vulkan_core.h>
21 
22 #include <base/containers/string.h>
23 #include <base/containers/vector.h>
24 #include <render/namespace.h>
25 #include <render/vulkan/intf_device_vk.h>
26 
27 RENDER_BEGIN_NAMESPACE()
28 struct LowLevelQueueInfo;
29 struct VersionInfo;
30 
31 struct InstanceWrapper {
32     VkInstance instance { VK_NULL_HANDLE };
33     bool debugReportSupported { false };
34     bool debugUtilsSupported { false };
35     uint32_t apiMajor { 0u };
36     uint32_t apiMinor { 0u };
37 };
38 
39 struct PhysicalDeviceWrapper {
40     VkPhysicalDevice physicalDevice { VK_NULL_HANDLE };
41     BASE_NS::vector<VkExtensionProperties> physicalDeviceExtensions;
42     PhysicalDevicePropertiesVk physicalDeviceProperties;
43 };
44 
45 struct DeviceWrapper {
46     VkDevice device { VK_NULL_HANDLE };
47     BASE_NS::vector<BASE_NS::string> extensions;
48 };
49 
50 struct QueueProperties {
51     VkQueueFlags requiredFlags { 0 };
52     uint32_t count { 0 };
53     float priority { 1.0f };
54     bool explicitFlags { false };
55     bool canPresent { false };
56 };
57 
58 struct Window {
59 #ifdef VK_USE_PLATFORM_WIN32_KHR
60     uintptr_t hinstance;
61 #elif defined(VK_USE_PLATFORM_XCB_KHR)
62     uintptr_t connection;
63 #elif defined(VK_USE_PLATFORM_XLIB_KHR)
64     uintptr_t display;
65 #endif
66     uintptr_t window;
67 };
68 
69 class CreateFunctionsVk {
70 public:
71     static InstanceWrapper CreateInstance(const VersionInfo& engineInfo, const VersionInfo& appInfo);
72     static void DestroyInstance(VkInstance instance);
73 
74     static VkDebugReportCallbackEXT CreateDebugCallback(
75         VkInstance instance, PFN_vkDebugReportCallbackEXT callbackFunction);
76     static void DestroyDebugCallback(VkInstance instance, VkDebugReportCallbackEXT debugReport);
77 
78     static VkDebugUtilsMessengerEXT CreateDebugMessenger(
79         VkInstance instance, PFN_vkDebugUtilsMessengerCallbackEXT callbackFunction);
80     static void DestroyDebugMessenger(VkInstance instance, VkDebugUtilsMessengerEXT debugMessenger);
81 
82     static PhysicalDeviceWrapper CreatePhysicalDevice(VkInstance instance, QueueProperties const& queueProperties);
83 
84     static DeviceWrapper CreateDevice(VkInstance instance, VkPhysicalDevice physicalDevice,
85         const BASE_NS::vector<VkExtensionProperties>& physicalDeviceExtensions,
86         const VkPhysicalDeviceFeatures& featuresToEnable, const VkPhysicalDeviceFeatures2* physicalDeviceFeatures2,
87         const BASE_NS::vector<LowLevelQueueInfo>& availableQueues,
88         const BASE_NS::vector<BASE_NS::string_view>& preferredDeviceExtensions);
89     static void DestroyDevice(VkDevice device);
90 
91     static VkSurfaceKHR CreateSurface(VkInstance instance, Window const& nativeWindow);
92     static void DestroySurface(VkInstance instance, VkSurfaceKHR surface);
93 
94     static void DestroySwapchain(VkDevice device, VkSwapchainKHR swapchain);
95 
96     static BASE_NS::vector<LowLevelQueueInfo> GetAvailableQueues(
97         VkPhysicalDevice physicalDevice, const BASE_NS::vector<QueueProperties>& queueProperties);
98 
99     static VkPipelineCache CreatePipelineCache(VkDevice device, BASE_NS::array_view<const uint8_t> initialData);
100     static void DestroyPipelineCache(VkDevice device, VkPipelineCache cache);
101 };
102 RENDER_END_NAMESPACE()
103 
104 #endif // VULKAN_CREATE_FUNCTIONS_VK_H
105