Nolan Scobie | f52ad20 | 2024-03-06 18:18:28 -0500 | [diff] [blame] | 1 | /* |
| 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 | |
Kaylee Lubick | 1a25e4e | 2024-06-20 17:35:57 +0000 | [diff] [blame] | 19 | #include <include/gpu/vk/VulkanBackendContext.h> |
Kaylee Lubick | 925b0c1 | 2024-06-03 13:59:04 +0000 | [diff] [blame] | 20 | #include <include/gpu/vk/VulkanExtensions.h> |
| 21 | #include <include/gpu/vk/VulkanTypes.h> |
Nolan Scobie | f52ad20 | 2024-03-06 18:18:28 -0500 | [diff] [blame] | 22 | |
| 23 | #include <vulkan/vulkan.h> |
| 24 | |
| 25 | using namespace skgpu; |
| 26 | |
| 27 | namespace android { |
| 28 | namespace renderengine { |
| 29 | namespace skia { |
| 30 | |
| 31 | class VulkanInterface { |
| 32 | public: |
| 33 | // Create an uninitialized interface. Initialize with `init`. |
| 34 | VulkanInterface() = default; |
| 35 | ~VulkanInterface() = default; |
| 36 | VulkanInterface(const VulkanInterface&) = delete; |
| 37 | VulkanInterface& operator=(const VulkanInterface&) = delete; |
| 38 | VulkanInterface& operator=(VulkanInterface&&) = delete; |
| 39 | |
| 40 | void init(bool protectedContent = false); |
Nolan Scobie | 2526b2f | 2024-04-16 15:12:22 -0400 | [diff] [blame] | 41 | // Returns true and marks this VulkanInterface as "owned" if it is initialized but unused by any |
| 42 | // RenderEngine instances. Returns false if already owned, indicating that it must not be used |
| 43 | // by a new RE instance. |
| 44 | bool takeOwnership(); |
Nolan Scobie | f52ad20 | 2024-03-06 18:18:28 -0500 | [diff] [blame] | 45 | void teardown(); |
| 46 | |
Kaylee Lubick | 1a25e4e | 2024-06-20 17:35:57 +0000 | [diff] [blame] | 47 | // TODO(b/309785258) Combine these into one now that they are the same implementation. |
| 48 | VulkanBackendContext getGaneshBackendContext(); |
Nolan Scobie | 609e597 | 2024-03-20 14:47:34 -0400 | [diff] [blame] | 49 | VulkanBackendContext getGraphiteBackendContext(); |
Nolan Scobie | f52ad20 | 2024-03-06 18:18:28 -0500 | [diff] [blame] | 50 | VkSemaphore createExportableSemaphore(); |
| 51 | VkSemaphore importSemaphoreFromSyncFd(int syncFd); |
| 52 | int exportSemaphoreSyncFd(VkSemaphore semaphore); |
| 53 | void destroySemaphore(VkSemaphore semaphore); |
| 54 | |
| 55 | bool isInitialized() const { return mInitialized; } |
| 56 | bool isRealtimePriority() const { return mIsRealtimePriority; } |
| 57 | const std::vector<std::string>& getInstanceExtensionNames() { return mInstanceExtensionNames; } |
| 58 | const std::vector<std::string>& getDeviceExtensionNames() { return mDeviceExtensionNames; } |
| 59 | |
| 60 | private: |
| 61 | struct VulkanFuncs { |
| 62 | PFN_vkCreateSemaphore vkCreateSemaphore = nullptr; |
| 63 | PFN_vkImportSemaphoreFdKHR vkImportSemaphoreFdKHR = nullptr; |
| 64 | PFN_vkGetSemaphoreFdKHR vkGetSemaphoreFdKHR = nullptr; |
| 65 | PFN_vkDestroySemaphore vkDestroySemaphore = nullptr; |
| 66 | |
| 67 | PFN_vkDeviceWaitIdle vkDeviceWaitIdle = nullptr; |
| 68 | PFN_vkDestroyDevice vkDestroyDevice = nullptr; |
| 69 | PFN_vkDestroyInstance vkDestroyInstance = nullptr; |
| 70 | }; |
| 71 | |
| 72 | static void onVkDeviceFault(void* callbackContext, const std::string& description, |
| 73 | const std::vector<VkDeviceFaultAddressInfoEXT>& addressInfos, |
| 74 | const std::vector<VkDeviceFaultVendorInfoEXT>& vendorInfos, |
| 75 | const std::vector<std::byte>& vendorBinaryData); |
| 76 | |
Nolan Scobie | 2526b2f | 2024-04-16 15:12:22 -0400 | [diff] [blame] | 77 | // Note: keep all field defaults in sync with teardown() |
Nolan Scobie | f52ad20 | 2024-03-06 18:18:28 -0500 | [diff] [blame] | 78 | bool mInitialized = false; |
Nolan Scobie | 2526b2f | 2024-04-16 15:12:22 -0400 | [diff] [blame] | 79 | bool mIsOwned = false; |
Nolan Scobie | f52ad20 | 2024-03-06 18:18:28 -0500 | [diff] [blame] | 80 | VkInstance mInstance = VK_NULL_HANDLE; |
| 81 | VkPhysicalDevice mPhysicalDevice = VK_NULL_HANDLE; |
| 82 | VkDevice mDevice = VK_NULL_HANDLE; |
| 83 | VkQueue mQueue = VK_NULL_HANDLE; |
| 84 | int mQueueIndex = 0; |
| 85 | uint32_t mApiVersion = 0; |
Kaylee Lubick | 1a25e4e | 2024-06-20 17:35:57 +0000 | [diff] [blame] | 86 | skgpu::VulkanExtensions mVulkanExtensions; |
Nolan Scobie | f52ad20 | 2024-03-06 18:18:28 -0500 | [diff] [blame] | 87 | VkPhysicalDeviceFeatures2* mPhysicalDeviceFeatures2 = nullptr; |
| 88 | VkPhysicalDeviceSamplerYcbcrConversionFeatures* mSamplerYcbcrConversionFeatures = nullptr; |
| 89 | VkPhysicalDeviceProtectedMemoryFeatures* mProtectedMemoryFeatures = nullptr; |
| 90 | VkPhysicalDeviceFaultFeaturesEXT* mDeviceFaultFeatures = nullptr; |
Kaylee Lubick | 925b0c1 | 2024-06-03 13:59:04 +0000 | [diff] [blame] | 91 | skgpu::VulkanGetProc mGrGetProc = nullptr; |
Nolan Scobie | f52ad20 | 2024-03-06 18:18:28 -0500 | [diff] [blame] | 92 | bool mIsProtected = false; |
| 93 | bool mIsRealtimePriority = false; |
| 94 | |
| 95 | VulkanFuncs mFuncs; |
| 96 | |
| 97 | std::vector<std::string> mInstanceExtensionNames; |
| 98 | std::vector<std::string> mDeviceExtensionNames; |
| 99 | }; |
| 100 | |
| 101 | } // namespace skia |
| 102 | } // namespace renderengine |
| 103 | } // namespace android |