blob: 2824fcb17a5b33065fe83b6a52ca3858c77a8876 [file] [log] [blame]
Nolan Scobief52ad202024-03-06 18:18:28 -05001/*
2 * Copyright 2024 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <include/gpu/vk/GrVkBackendContext.h>
20#include <include/gpu/vk/GrVkExtensions.h>
21
22#include <vulkan/vulkan.h>
23
24using namespace skgpu;
25
Nolan Scobie609e5972024-03-20 14:47:34 -040026namespace skgpu {
27struct VulkanBackendContext;
28} // namespace skgpu
29
Nolan Scobief52ad202024-03-06 18:18:28 -050030namespace android {
31namespace renderengine {
32namespace skia {
33
34class VulkanInterface {
35public:
36 // Create an uninitialized interface. Initialize with `init`.
37 VulkanInterface() = default;
38 ~VulkanInterface() = default;
39 VulkanInterface(const VulkanInterface&) = delete;
40 VulkanInterface& operator=(const VulkanInterface&) = delete;
41 VulkanInterface& operator=(VulkanInterface&&) = delete;
42
43 void init(bool protectedContent = false);
44 void teardown();
45
Nolan Scobiefc125ec2024-03-11 20:08:27 -040046 GrVkBackendContext getGaneshBackendContext();
Nolan Scobie609e5972024-03-20 14:47:34 -040047 VulkanBackendContext getGraphiteBackendContext();
Nolan Scobief52ad202024-03-06 18:18:28 -050048 VkSemaphore createExportableSemaphore();
49 VkSemaphore importSemaphoreFromSyncFd(int syncFd);
50 int exportSemaphoreSyncFd(VkSemaphore semaphore);
51 void destroySemaphore(VkSemaphore semaphore);
52
53 bool isInitialized() const { return mInitialized; }
54 bool isRealtimePriority() const { return mIsRealtimePriority; }
55 const std::vector<std::string>& getInstanceExtensionNames() { return mInstanceExtensionNames; }
56 const std::vector<std::string>& getDeviceExtensionNames() { return mDeviceExtensionNames; }
57
58private:
59 struct VulkanFuncs {
60 PFN_vkCreateSemaphore vkCreateSemaphore = nullptr;
61 PFN_vkImportSemaphoreFdKHR vkImportSemaphoreFdKHR = nullptr;
62 PFN_vkGetSemaphoreFdKHR vkGetSemaphoreFdKHR = nullptr;
63 PFN_vkDestroySemaphore vkDestroySemaphore = nullptr;
64
65 PFN_vkDeviceWaitIdle vkDeviceWaitIdle = nullptr;
66 PFN_vkDestroyDevice vkDestroyDevice = nullptr;
67 PFN_vkDestroyInstance vkDestroyInstance = nullptr;
68 };
69
70 static void onVkDeviceFault(void* callbackContext, const std::string& description,
71 const std::vector<VkDeviceFaultAddressInfoEXT>& addressInfos,
72 const std::vector<VkDeviceFaultVendorInfoEXT>& vendorInfos,
73 const std::vector<std::byte>& vendorBinaryData);
74
75 bool mInitialized = false;
76 VkInstance mInstance = VK_NULL_HANDLE;
77 VkPhysicalDevice mPhysicalDevice = VK_NULL_HANDLE;
78 VkDevice mDevice = VK_NULL_HANDLE;
79 VkQueue mQueue = VK_NULL_HANDLE;
80 int mQueueIndex = 0;
81 uint32_t mApiVersion = 0;
82 GrVkExtensions mGrExtensions;
83 VkPhysicalDeviceFeatures2* mPhysicalDeviceFeatures2 = nullptr;
84 VkPhysicalDeviceSamplerYcbcrConversionFeatures* mSamplerYcbcrConversionFeatures = nullptr;
85 VkPhysicalDeviceProtectedMemoryFeatures* mProtectedMemoryFeatures = nullptr;
86 VkPhysicalDeviceFaultFeaturesEXT* mDeviceFaultFeatures = nullptr;
87 GrVkGetProc mGrGetProc = nullptr;
88 bool mIsProtected = false;
89 bool mIsRealtimePriority = false;
90
91 VulkanFuncs mFuncs;
92
93 std::vector<std::string> mInstanceExtensionNames;
94 std::vector<std::string> mDeviceExtensionNames;
95};
96
97} // namespace skia
98} // namespace renderengine
99} // namespace android