blob: c3936d98699793b12dd9d6e2f13c143ad9779f77 [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
26namespace android {
27namespace renderengine {
28namespace skia {
29
30class VulkanInterface {
31public:
32 // Create an uninitialized interface. Initialize with `init`.
33 VulkanInterface() = default;
34 ~VulkanInterface() = default;
35 VulkanInterface(const VulkanInterface&) = delete;
36 VulkanInterface& operator=(const VulkanInterface&) = delete;
37 VulkanInterface& operator=(VulkanInterface&&) = delete;
38
39 void init(bool protectedContent = false);
40 void teardown();
41
42 // TODO: b/293371537 - Graphite variant (external/skia/include/gpu/vk/VulkanBackendContext.h)
43 GrVkBackendContext getBackendContext();
44 VkSemaphore createExportableSemaphore();
45 VkSemaphore importSemaphoreFromSyncFd(int syncFd);
46 int exportSemaphoreSyncFd(VkSemaphore semaphore);
47 void destroySemaphore(VkSemaphore semaphore);
48
49 bool isInitialized() const { return mInitialized; }
50 bool isRealtimePriority() const { return mIsRealtimePriority; }
51 const std::vector<std::string>& getInstanceExtensionNames() { return mInstanceExtensionNames; }
52 const std::vector<std::string>& getDeviceExtensionNames() { return mDeviceExtensionNames; }
53
54private:
55 struct VulkanFuncs {
56 PFN_vkCreateSemaphore vkCreateSemaphore = nullptr;
57 PFN_vkImportSemaphoreFdKHR vkImportSemaphoreFdKHR = nullptr;
58 PFN_vkGetSemaphoreFdKHR vkGetSemaphoreFdKHR = nullptr;
59 PFN_vkDestroySemaphore vkDestroySemaphore = nullptr;
60
61 PFN_vkDeviceWaitIdle vkDeviceWaitIdle = nullptr;
62 PFN_vkDestroyDevice vkDestroyDevice = nullptr;
63 PFN_vkDestroyInstance vkDestroyInstance = nullptr;
64 };
65
66 static void onVkDeviceFault(void* callbackContext, const std::string& description,
67 const std::vector<VkDeviceFaultAddressInfoEXT>& addressInfos,
68 const std::vector<VkDeviceFaultVendorInfoEXT>& vendorInfos,
69 const std::vector<std::byte>& vendorBinaryData);
70
71 bool mInitialized = false;
72 VkInstance mInstance = VK_NULL_HANDLE;
73 VkPhysicalDevice mPhysicalDevice = VK_NULL_HANDLE;
74 VkDevice mDevice = VK_NULL_HANDLE;
75 VkQueue mQueue = VK_NULL_HANDLE;
76 int mQueueIndex = 0;
77 uint32_t mApiVersion = 0;
78 GrVkExtensions mGrExtensions;
79 VkPhysicalDeviceFeatures2* mPhysicalDeviceFeatures2 = nullptr;
80 VkPhysicalDeviceSamplerYcbcrConversionFeatures* mSamplerYcbcrConversionFeatures = nullptr;
81 VkPhysicalDeviceProtectedMemoryFeatures* mProtectedMemoryFeatures = nullptr;
82 VkPhysicalDeviceFaultFeaturesEXT* mDeviceFaultFeatures = nullptr;
83 GrVkGetProc mGrGetProc = nullptr;
84 bool mIsProtected = false;
85 bool mIsRealtimePriority = false;
86
87 VulkanFuncs mFuncs;
88
89 std::vector<std::string> mInstanceExtensionNames;
90 std::vector<std::string> mDeviceExtensionNames;
91};
92
93} // namespace skia
94} // namespace renderengine
95} // namespace android