diff options
author | Kaiyi Li <kaiyili@google.com> | 2021-02-03 12:52:23 -0800 |
---|---|---|
committer | Kaiyi Li <kaiyili@google.com> | 2021-02-06 13:13:20 -0800 |
commit | ea146f7ef6886373d4d53e2cca5d939a4621a5cc (patch) | |
tree | a9deceae4b863b950fea2c74a0ae337f2fe5cb62 /stream-servers/DisplayVk.h | |
parent | 38514f1650b7abc78a98a692ab16a41784cf2fd8 (diff) | |
download | vulkan-cereal-ea146f7ef6886373d4d53e2cca5d939a4621a5cc.tar.gz |
Native VK Swapchain: add DisplayVk to orchestrate the CompositorVk and SwapChainStateVk
DisplayVk is used to connect the compositor, swapchain and gfxstream
renderer.
Similar to FrameBuffer, DisplayVk also has a two stage initialization,
first initialized by the constructor, then use the bindToSurface with a
VkSurfaceKHR to complete the initialization.
To draw a VkImage, first call importVkImage to specify an id to this
image. Then call post with this id to draw. When using with FrameBuffer,
the id is supposed to be the color buffer id. And post is supposed to be
called in FrameBuffer::post() with the same id. DisplayVk::importVkImage
and DisplayVk::releaseImport is supposed to track the lifetime of a
VkImage backed ColorBuffer.
In DisplayVk::post, a transform to stretch the ColorBuffer to fill the
entire window is used.
DisplayVk::post waits until the command buffer finishes execution. To
change this function into an asynchronous function, add extra parameters
to pass in sync objects, and signal those objects once the execution
completes, but let the function returns once the command buffer is
submitted.
Test: DisplayVk_unittests
Change-Id: I90c0e46947dfd3cd4c5c5c2c71ffbd987ca1c89d
Diffstat (limited to 'stream-servers/DisplayVk.h')
-rw-r--r-- | stream-servers/DisplayVk.h | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/stream-servers/DisplayVk.h b/stream-servers/DisplayVk.h new file mode 100644 index 00000000..0bb4f259 --- /dev/null +++ b/stream-servers/DisplayVk.h @@ -0,0 +1,67 @@ +#ifndef DISPLAY_VK_H +#define DISPLAY_VK_H + +#include <functional> +#include <memory> +#include <optional> + +#include "ColorBuffer.h" +#include "CompositorVk.h" +#include "RenderContext.h" +#include "SwapChainStateVk.h" +#include "vulkan/cereal/common/goldfish_vk_dispatch.h" + +// The DisplayVk class holds the Vulkan and other states required to draw a +// frame in a host window. + +class DisplayVk { + public: + DisplayVk(const goldfish_vk::VulkanDispatch &, VkPhysicalDevice, + uint32_t swapChainQueueFamilyIndex, + uint32_t compositorQueueFamilyIndex, VkDevice, + VkQueue compositorVkQueue, VkQueue swapChainVkQueue); + ~DisplayVk(); + void bindToSurface(VkSurfaceKHR, uint32_t width, uint32_t height); + void importVkImage(HandleType id, VkImage, VkFormat, uint32_t width, + uint32_t height); + void releaseImport(HandleType id); + // To display a colorbuffer, first import it by calling importVkImage + void post(HandleType id); + + private: + bool canComposite(VkFormat); + + const goldfish_vk::VulkanDispatch &m_vk; + VkPhysicalDevice m_vkPhysicalDevice; + VkFormatFeatureFlags m_swapChainImageFeatures; + uint32_t m_swapChainQueueFamilyIndex; + uint32_t m_compositorQueueFamilyIndex; + VkDevice m_vkDevice; + VkQueue m_compositorVkQueue; + VkQueue m_swapChainVkQueue; + VkCommandPool m_vkCommandPool; + VkSampler m_compositionVkSampler; + VkFence m_frameDrawCompleteFence; + VkSemaphore m_imageReadySem; + VkSemaphore m_frameDrawCompleteSem; + + struct ColorBufferInfo { + uint32_t m_width; + uint32_t m_height; + VkFormat m_vkFormat; + VkImageView m_vkImageView; + }; + std::unordered_map<HandleType, ColorBufferInfo> m_colorBuffers; + + std::unique_ptr<SwapChainStateVk> m_swapChainStateVk; + std::unique_ptr<CompositorVk> m_compositorVk; + struct SurfaceState { + uint32_t m_width = 0; + uint32_t m_height = 0; + std::optional<HandleType> m_prevColorBuffer = std::nullopt; + }; + std::unique_ptr<SurfaceState> m_surfaceState; + std::unordered_map<VkFormat, bool> m_canComposite; +}; + +#endif
\ No newline at end of file |