diff options
Diffstat (limited to 'libs/hwui/renderthread/VulkanManager.h')
-rw-r--r-- | libs/hwui/renderthread/VulkanManager.h | 60 |
1 files changed, 52 insertions, 8 deletions
diff --git a/libs/hwui/renderthread/VulkanManager.h b/libs/hwui/renderthread/VulkanManager.h index c319c9ec209f..6702649402e6 100644 --- a/libs/hwui/renderthread/VulkanManager.h +++ b/libs/hwui/renderthread/VulkanManager.h @@ -17,10 +17,18 @@ #ifndef VULKANMANAGER_H #define VULKANMANAGER_H +#if !defined(VK_USE_PLATFORM_ANDROID_KHR) +# define VK_USE_PLATFORM_ANDROID_KHR +#endif +#include <vulkan/vulkan.h> + #include <SkSurface.h> +#include <ui/Fence.h> +#include <utils/StrongPointer.h> #include <vk/GrVkBackendContext.h> +#include "IRenderPipeline.h" -#include <vulkan/vulkan.h> +class GrVkExtensions; namespace android { namespace uirenderer { @@ -30,7 +38,7 @@ class RenderThread; class VulkanSurface { public: - VulkanSurface() {} + VulkanSurface(ColorMode colorMode) : mColorMode(colorMode) {} sk_sp<SkSurface> getBackBufferSurface() { return mBackbuffer; } @@ -66,6 +74,7 @@ private: VkImage* mImages = nullptr; ImageInfo* mImageInfos; uint16_t mCurrentTime = 0; + ColorMode mColorMode; }; // This class contains the shared global Vulkan objects, such as VkInstance, VkDevice and VkQueue, @@ -79,11 +88,11 @@ public: void initialize(); // Quick check to see if the VulkanManager has been initialized. - bool hasVkContext() { return mBackendContext.get() != nullptr; } + bool hasVkContext() { return mDevice != VK_NULL_HANDLE; } // Given a window this creates a new VkSurfaceKHR and VkSwapchain and stores them inside a new // VulkanSurface object which is returned. - VulkanSurface* createSurface(ANativeWindow* window); + VulkanSurface* createSurface(ANativeWindow* window, ColorMode colorMode); // Destroy the VulkanSurface and all associated vulkan objects. void destroySurface(VulkanSurface* surface); @@ -105,12 +114,22 @@ public: // Presents the current VkImage. void swapBuffers(VulkanSurface* surface); + // Inserts a wait on fence command into the Vulkan command buffer. + status_t fenceWait(sp<Fence>& fence); + + // Creates a fence that is signaled, when all the pending Vulkan commands are flushed. + status_t createReleaseFence(sp<Fence>& nativeFence); + private: friend class RenderThread; explicit VulkanManager(RenderThread& thread); ~VulkanManager() { destroy(); } + // Sets up the VkInstance and VkDevice objects. Also fills out the passed in + // VkPhysicalDeviceFeatures struct. + bool setupDevice(GrVkExtensions&, VkPhysicalDeviceFeatures2&); + void destroyBuffers(VulkanSurface* surface); bool createSwapchain(VulkanSurface* surface); @@ -118,6 +137,8 @@ private: VulkanSurface::BackbufferInfo* getAvailableBackbuffer(VulkanSurface* surface); + bool setupDummyCommandBuffer(); + // simple wrapper class that exists only to initialize a pointer to NULL template <typename FNPTR_TYPE> class VkPtr { @@ -148,7 +169,23 @@ private: VkPtr<PFN_vkQueuePresentKHR> mQueuePresentKHR; VkPtr<PFN_vkCreateSharedSwapchainsKHR> mCreateSharedSwapchainsKHR; - // Additional vulkan functions + // Instance Functions + VkPtr<PFN_vkEnumerateInstanceVersion> mEnumerateInstanceVersion; + VkPtr<PFN_vkEnumerateInstanceExtensionProperties> mEnumerateInstanceExtensionProperties; + VkPtr<PFN_vkCreateInstance> mCreateInstance; + + VkPtr<PFN_vkDestroyInstance> mDestroyInstance; + VkPtr<PFN_vkEnumeratePhysicalDevices> mEnumeratePhysicalDevices; + VkPtr<PFN_vkGetPhysicalDeviceProperties> mGetPhysicalDeviceProperties; + VkPtr<PFN_vkGetPhysicalDeviceQueueFamilyProperties> mGetPhysicalDeviceQueueFamilyProperties; + VkPtr<PFN_vkGetPhysicalDeviceFeatures2> mGetPhysicalDeviceFeatures2; + VkPtr<PFN_vkCreateDevice> mCreateDevice; + VkPtr<PFN_vkEnumerateDeviceExtensionProperties> mEnumerateDeviceExtensionProperties; + + // Device Functions + VkPtr<PFN_vkGetDeviceQueue> mGetDeviceQueue; + VkPtr<PFN_vkDeviceWaitIdle> mDeviceWaitIdle; + VkPtr<PFN_vkDestroyDevice> mDestroyDevice; VkPtr<PFN_vkCreateCommandPool> mCreateCommandPool; VkPtr<PFN_vkDestroyCommandPool> mDestroyCommandPool; VkPtr<PFN_vkAllocateCommandBuffers> mAllocateCommandBuffers; @@ -158,13 +195,13 @@ private: VkPtr<PFN_vkEndCommandBuffer> mEndCommandBuffer; VkPtr<PFN_vkCmdPipelineBarrier> mCmdPipelineBarrier; - VkPtr<PFN_vkGetDeviceQueue> mGetDeviceQueue; VkPtr<PFN_vkQueueSubmit> mQueueSubmit; VkPtr<PFN_vkQueueWaitIdle> mQueueWaitIdle; - VkPtr<PFN_vkDeviceWaitIdle> mDeviceWaitIdle; VkPtr<PFN_vkCreateSemaphore> mCreateSemaphore; VkPtr<PFN_vkDestroySemaphore> mDestroySemaphore; + VkPtr<PFN_vkImportSemaphoreFdKHR> mImportSemaphoreFdKHR; + VkPtr<PFN_vkGetSemaphoreFdKHR> mGetSemaphoreFdKHR; VkPtr<PFN_vkCreateFence> mCreateFence; VkPtr<PFN_vkDestroyFence> mDestroyFence; VkPtr<PFN_vkWaitForFences> mWaitForFences; @@ -172,11 +209,18 @@ private: RenderThread& mRenderThread; - sk_sp<const GrVkBackendContext> mBackendContext; + VkInstance mInstance = VK_NULL_HANDLE; + VkPhysicalDevice mPhysicalDevice = VK_NULL_HANDLE; + VkDevice mDevice = VK_NULL_HANDLE; + + uint32_t mGraphicsQueueIndex; + VkQueue mGraphicsQueue = VK_NULL_HANDLE; uint32_t mPresentQueueIndex; VkQueue mPresentQueue = VK_NULL_HANDLE; VkCommandPool mCommandPool = VK_NULL_HANDLE; + VkCommandBuffer mDummyCB = VK_NULL_HANDLE; + enum class SwapBehavior { Discard, BufferAge, |