1*38e8c45fSAndroid Build Coastguard Worker /* 2*38e8c45fSAndroid Build Coastguard Worker * Copyright 2024 The Android Open Source Project 3*38e8c45fSAndroid Build Coastguard Worker * 4*38e8c45fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*38e8c45fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*38e8c45fSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*38e8c45fSAndroid Build Coastguard Worker * 8*38e8c45fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*38e8c45fSAndroid Build Coastguard Worker * 10*38e8c45fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*38e8c45fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*38e8c45fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*38e8c45fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*38e8c45fSAndroid Build Coastguard Worker * limitations under the License. 15*38e8c45fSAndroid Build Coastguard Worker */ 16*38e8c45fSAndroid Build Coastguard Worker 17*38e8c45fSAndroid Build Coastguard Worker #pragma once 18*38e8c45fSAndroid Build Coastguard Worker 19*38e8c45fSAndroid Build Coastguard Worker #include <include/gpu/vk/VulkanBackendContext.h> 20*38e8c45fSAndroid Build Coastguard Worker #include <include/gpu/vk/VulkanExtensions.h> 21*38e8c45fSAndroid Build Coastguard Worker #include <include/gpu/vk/VulkanTypes.h> 22*38e8c45fSAndroid Build Coastguard Worker 23*38e8c45fSAndroid Build Coastguard Worker #include <vulkan/vulkan.h> 24*38e8c45fSAndroid Build Coastguard Worker 25*38e8c45fSAndroid Build Coastguard Worker using namespace skgpu; 26*38e8c45fSAndroid Build Coastguard Worker 27*38e8c45fSAndroid Build Coastguard Worker namespace android { 28*38e8c45fSAndroid Build Coastguard Worker namespace renderengine { 29*38e8c45fSAndroid Build Coastguard Worker namespace skia { 30*38e8c45fSAndroid Build Coastguard Worker 31*38e8c45fSAndroid Build Coastguard Worker class VulkanInterface { 32*38e8c45fSAndroid Build Coastguard Worker public: 33*38e8c45fSAndroid Build Coastguard Worker // Create an uninitialized interface. Initialize with `init`. 34*38e8c45fSAndroid Build Coastguard Worker VulkanInterface() = default; 35*38e8c45fSAndroid Build Coastguard Worker ~VulkanInterface() = default; 36*38e8c45fSAndroid Build Coastguard Worker VulkanInterface(const VulkanInterface&) = delete; 37*38e8c45fSAndroid Build Coastguard Worker VulkanInterface& operator=(const VulkanInterface&) = delete; 38*38e8c45fSAndroid Build Coastguard Worker VulkanInterface& operator=(VulkanInterface&&) = delete; 39*38e8c45fSAndroid Build Coastguard Worker 40*38e8c45fSAndroid Build Coastguard Worker void init(bool protectedContent = false); 41*38e8c45fSAndroid Build Coastguard Worker // Returns true and marks this VulkanInterface as "owned" if it is initialized but unused by any 42*38e8c45fSAndroid Build Coastguard Worker // RenderEngine instances. Returns false if already owned, indicating that it must not be used 43*38e8c45fSAndroid Build Coastguard Worker // by a new RE instance. 44*38e8c45fSAndroid Build Coastguard Worker bool takeOwnership(); 45*38e8c45fSAndroid Build Coastguard Worker void teardown(); 46*38e8c45fSAndroid Build Coastguard Worker 47*38e8c45fSAndroid Build Coastguard Worker // TODO(b/309785258) Combine these into one now that they are the same implementation. 48*38e8c45fSAndroid Build Coastguard Worker VulkanBackendContext getGaneshBackendContext(); 49*38e8c45fSAndroid Build Coastguard Worker VulkanBackendContext getGraphiteBackendContext(); 50*38e8c45fSAndroid Build Coastguard Worker VkSemaphore createExportableSemaphore(); 51*38e8c45fSAndroid Build Coastguard Worker VkSemaphore importSemaphoreFromSyncFd(int syncFd); 52*38e8c45fSAndroid Build Coastguard Worker int exportSemaphoreSyncFd(VkSemaphore semaphore); 53*38e8c45fSAndroid Build Coastguard Worker void destroySemaphore(VkSemaphore semaphore); 54*38e8c45fSAndroid Build Coastguard Worker isInitialized()55*38e8c45fSAndroid Build Coastguard Worker bool isInitialized() const { return mInitialized; } isRealtimePriority()56*38e8c45fSAndroid Build Coastguard Worker bool isRealtimePriority() const { return mIsRealtimePriority; } getInstanceExtensionNames()57*38e8c45fSAndroid Build Coastguard Worker const std::vector<std::string>& getInstanceExtensionNames() { return mInstanceExtensionNames; } getDeviceExtensionNames()58*38e8c45fSAndroid Build Coastguard Worker const std::vector<std::string>& getDeviceExtensionNames() { return mDeviceExtensionNames; } 59*38e8c45fSAndroid Build Coastguard Worker 60*38e8c45fSAndroid Build Coastguard Worker private: 61*38e8c45fSAndroid Build Coastguard Worker struct VulkanFuncs { 62*38e8c45fSAndroid Build Coastguard Worker PFN_vkCreateSemaphore vkCreateSemaphore = nullptr; 63*38e8c45fSAndroid Build Coastguard Worker PFN_vkImportSemaphoreFdKHR vkImportSemaphoreFdKHR = nullptr; 64*38e8c45fSAndroid Build Coastguard Worker PFN_vkGetSemaphoreFdKHR vkGetSemaphoreFdKHR = nullptr; 65*38e8c45fSAndroid Build Coastguard Worker PFN_vkDestroySemaphore vkDestroySemaphore = nullptr; 66*38e8c45fSAndroid Build Coastguard Worker 67*38e8c45fSAndroid Build Coastguard Worker PFN_vkDeviceWaitIdle vkDeviceWaitIdle = nullptr; 68*38e8c45fSAndroid Build Coastguard Worker PFN_vkDestroyDevice vkDestroyDevice = nullptr; 69*38e8c45fSAndroid Build Coastguard Worker PFN_vkDestroyInstance vkDestroyInstance = nullptr; 70*38e8c45fSAndroid Build Coastguard Worker }; 71*38e8c45fSAndroid Build Coastguard Worker 72*38e8c45fSAndroid Build Coastguard Worker static void onVkDeviceFault(void* callbackContext, const std::string& description, 73*38e8c45fSAndroid Build Coastguard Worker const std::vector<VkDeviceFaultAddressInfoEXT>& addressInfos, 74*38e8c45fSAndroid Build Coastguard Worker const std::vector<VkDeviceFaultVendorInfoEXT>& vendorInfos, 75*38e8c45fSAndroid Build Coastguard Worker const std::vector<std::byte>& vendorBinaryData); 76*38e8c45fSAndroid Build Coastguard Worker 77*38e8c45fSAndroid Build Coastguard Worker // Note: keep all field defaults in sync with teardown() 78*38e8c45fSAndroid Build Coastguard Worker bool mInitialized = false; 79*38e8c45fSAndroid Build Coastguard Worker bool mIsOwned = false; 80*38e8c45fSAndroid Build Coastguard Worker VkInstance mInstance = VK_NULL_HANDLE; 81*38e8c45fSAndroid Build Coastguard Worker VkPhysicalDevice mPhysicalDevice = VK_NULL_HANDLE; 82*38e8c45fSAndroid Build Coastguard Worker VkDevice mDevice = VK_NULL_HANDLE; 83*38e8c45fSAndroid Build Coastguard Worker VkQueue mQueue = VK_NULL_HANDLE; 84*38e8c45fSAndroid Build Coastguard Worker int mQueueIndex = 0; 85*38e8c45fSAndroid Build Coastguard Worker uint32_t mApiVersion = 0; 86*38e8c45fSAndroid Build Coastguard Worker skgpu::VulkanExtensions mVulkanExtensions; 87*38e8c45fSAndroid Build Coastguard Worker VkPhysicalDeviceFeatures2* mPhysicalDeviceFeatures2 = nullptr; 88*38e8c45fSAndroid Build Coastguard Worker VkPhysicalDeviceSamplerYcbcrConversionFeatures* mSamplerYcbcrConversionFeatures = nullptr; 89*38e8c45fSAndroid Build Coastguard Worker VkPhysicalDeviceProtectedMemoryFeatures* mProtectedMemoryFeatures = nullptr; 90*38e8c45fSAndroid Build Coastguard Worker VkPhysicalDeviceFaultFeaturesEXT* mDeviceFaultFeatures = nullptr; 91*38e8c45fSAndroid Build Coastguard Worker skgpu::VulkanGetProc mGrGetProc = nullptr; 92*38e8c45fSAndroid Build Coastguard Worker bool mIsProtected = false; 93*38e8c45fSAndroid Build Coastguard Worker bool mIsRealtimePriority = false; 94*38e8c45fSAndroid Build Coastguard Worker 95*38e8c45fSAndroid Build Coastguard Worker VulkanFuncs mFuncs; 96*38e8c45fSAndroid Build Coastguard Worker 97*38e8c45fSAndroid Build Coastguard Worker std::vector<std::string> mInstanceExtensionNames; 98*38e8c45fSAndroid Build Coastguard Worker std::vector<std::string> mDeviceExtensionNames; 99*38e8c45fSAndroid Build Coastguard Worker }; 100*38e8c45fSAndroid Build Coastguard Worker 101*38e8c45fSAndroid Build Coastguard Worker } // namespace skia 102*38e8c45fSAndroid Build Coastguard Worker } // namespace renderengine 103*38e8c45fSAndroid Build Coastguard Worker } // namespace android 104