2016-04-06 13:08:59 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2016-05-05 19:32:03 +00:00
|
|
|
#ifndef VulkanWindowContext_DEFINED
|
|
|
|
#define VulkanWindowContext_DEFINED
|
2016-04-06 13:08:59 +00:00
|
|
|
|
2016-06-10 14:50:00 +00:00
|
|
|
#include "SkTypes.h" // required to pull in any SkUserConfig defines
|
|
|
|
|
2016-04-06 13:08:59 +00:00
|
|
|
#ifdef SK_VULKAN
|
|
|
|
|
|
|
|
#include "vk/GrVkBackendContext.h"
|
2018-07-02 20:15:37 +00:00
|
|
|
#include "vk/GrVkInterface.h"
|
|
|
|
#include "vk/VkTestUtils.h"
|
2016-05-05 19:32:03 +00:00
|
|
|
#include "WindowContext.h"
|
2016-04-06 13:08:59 +00:00
|
|
|
|
2016-05-20 13:01:06 +00:00
|
|
|
class GrRenderTarget;
|
2016-04-06 13:08:59 +00:00
|
|
|
|
2016-05-05 19:32:03 +00:00
|
|
|
namespace sk_app {
|
|
|
|
|
|
|
|
class VulkanWindowContext : public WindowContext {
|
2016-04-06 13:08:59 +00:00
|
|
|
public:
|
2016-05-05 19:32:03 +00:00
|
|
|
~VulkanWindowContext() override;
|
2016-04-06 13:08:59 +00:00
|
|
|
|
2016-05-20 13:01:06 +00:00
|
|
|
sk_sp<SkSurface> getBackbufferSurface() override;
|
2016-05-05 19:32:03 +00:00
|
|
|
void swapBuffers() override;
|
2016-04-06 13:08:59 +00:00
|
|
|
|
2018-07-02 20:15:37 +00:00
|
|
|
bool isValid() override { return fDevice != VK_NULL_HANDLE; }
|
2016-04-06 13:08:59 +00:00
|
|
|
|
2016-07-27 15:50:12 +00:00
|
|
|
void resize(int w, int h) override {
|
2016-05-06 20:28:57 +00:00
|
|
|
this->createSwapchain(w, h, fDisplayParams);
|
|
|
|
}
|
|
|
|
|
2016-05-09 15:49:29 +00:00
|
|
|
void setDisplayParams(const DisplayParams& params) override {
|
2017-05-02 20:15:53 +00:00
|
|
|
this->destroyContext();
|
|
|
|
fDisplayParams = params;
|
|
|
|
this->initializeContext();
|
2016-04-06 13:08:59 +00:00
|
|
|
}
|
|
|
|
|
2016-07-26 19:02:50 +00:00
|
|
|
/** Platform specific function that creates a VkSurfaceKHR for a window */
|
|
|
|
using CreateVkSurfaceFn = std::function<VkSurfaceKHR(VkInstance)>;
|
|
|
|
/** Platform specific function that determines whether presentation will succeed. */
|
2018-07-02 20:15:37 +00:00
|
|
|
using CanPresentFn = sk_gpu_test::CanPresentFn;
|
2016-07-26 19:02:50 +00:00
|
|
|
|
2017-11-10 15:03:05 +00:00
|
|
|
VulkanWindowContext(const DisplayParams&, CreateVkSurfaceFn, CanPresentFn,
|
|
|
|
PFN_vkGetInstanceProcAddr, PFN_vkGetDeviceProcAddr);
|
2016-07-26 19:02:50 +00:00
|
|
|
|
2016-04-06 13:08:59 +00:00
|
|
|
private:
|
2017-05-02 20:15:53 +00:00
|
|
|
void initializeContext();
|
2016-04-06 13:08:59 +00:00
|
|
|
void destroyContext();
|
|
|
|
|
|
|
|
struct BackbufferInfo {
|
|
|
|
uint32_t fImageIndex; // image this is associated with
|
|
|
|
VkSemaphore fAcquireSemaphore; // we signal on this for acquisition of image
|
|
|
|
VkSemaphore fRenderSemaphore; // we wait on this for rendering to be done
|
|
|
|
VkCommandBuffer fTransitionCmdBuffers[2]; // to transition layout between present and render
|
|
|
|
VkFence fUsageFences[2]; // used to ensure this data is no longer used on GPU
|
|
|
|
};
|
|
|
|
|
|
|
|
BackbufferInfo* getAvailableBackbuffer();
|
2016-07-27 15:50:12 +00:00
|
|
|
bool createSwapchain(int width, int height, const DisplayParams& params);
|
2017-12-19 18:15:02 +00:00
|
|
|
void createBuffers(VkFormat format, SkColorType colorType);
|
2016-04-06 13:08:59 +00:00
|
|
|
void destroyBuffers();
|
|
|
|
|
2018-07-02 20:15:37 +00:00
|
|
|
VkInstance fInstance = VK_NULL_HANDLE;
|
|
|
|
VkPhysicalDevice fPhysicalDevice = VK_NULL_HANDLE;
|
|
|
|
VkDevice fDevice = VK_NULL_HANDLE;
|
2018-07-02 20:16:44 +00:00
|
|
|
VkDebugReportCallbackEXT fDebugCallback = VK_NULL_HANDLE;
|
2016-04-06 13:08:59 +00:00
|
|
|
|
2017-05-02 20:15:53 +00:00
|
|
|
// Create functions
|
|
|
|
CreateVkSurfaceFn fCreateVkSurfaceFn;
|
|
|
|
CanPresentFn fCanPresentFn;
|
|
|
|
|
2017-11-10 15:03:05 +00:00
|
|
|
// Vulkan GetProcAddr functions
|
2018-07-12 14:02:37 +00:00
|
|
|
PFN_vkGetInstanceProcAddr fGetInstanceProcAddr = nullptr;
|
|
|
|
PFN_vkGetDeviceProcAddr fGetDeviceProcAddr = nullptr;
|
2017-11-10 15:03:05 +00:00
|
|
|
|
2016-04-21 18:46:23 +00:00
|
|
|
// WSI interface functions
|
2018-07-12 14:02:37 +00:00
|
|
|
PFN_vkDestroySurfaceKHR fDestroySurfaceKHR = nullptr;
|
|
|
|
PFN_vkGetPhysicalDeviceSurfaceSupportKHR fGetPhysicalDeviceSurfaceSupportKHR = nullptr;
|
|
|
|
PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR fGetPhysicalDeviceSurfaceCapabilitiesKHR =nullptr;
|
|
|
|
PFN_vkGetPhysicalDeviceSurfaceFormatsKHR fGetPhysicalDeviceSurfaceFormatsKHR = nullptr;
|
|
|
|
PFN_vkGetPhysicalDeviceSurfacePresentModesKHR fGetPhysicalDeviceSurfacePresentModesKHR =nullptr;
|
|
|
|
|
|
|
|
PFN_vkCreateSwapchainKHR fCreateSwapchainKHR = nullptr;
|
|
|
|
PFN_vkDestroySwapchainKHR fDestroySwapchainKHR = nullptr;
|
|
|
|
PFN_vkGetSwapchainImagesKHR fGetSwapchainImagesKHR = nullptr;
|
|
|
|
PFN_vkAcquireNextImageKHR fAcquireNextImageKHR = nullptr;
|
|
|
|
PFN_vkQueuePresentKHR fQueuePresentKHR = nullptr;
|
|
|
|
|
|
|
|
PFN_vkDestroyInstance fDestroyInstance = nullptr;
|
|
|
|
PFN_vkDeviceWaitIdle fDeviceWaitIdle = nullptr;
|
2018-08-01 20:48:52 +00:00
|
|
|
PFN_vkDestroyDebugReportCallbackEXT fDestroyDebugReportCallbackEXT = nullptr;
|
2018-07-12 14:02:37 +00:00
|
|
|
PFN_vkQueueWaitIdle fQueueWaitIdle = nullptr;
|
|
|
|
PFN_vkDestroyDevice fDestroyDevice = nullptr;
|
|
|
|
PFN_vkGetDeviceQueue fGetDeviceQueue = nullptr;
|
2016-04-21 18:46:23 +00:00
|
|
|
|
2018-07-02 20:15:37 +00:00
|
|
|
sk_sp<const GrVkInterface> fInterface;
|
|
|
|
|
2016-04-06 13:08:59 +00:00
|
|
|
VkSurfaceKHR fSurface;
|
|
|
|
VkSwapchainKHR fSwapchain;
|
2018-07-02 20:15:37 +00:00
|
|
|
uint32_t fGraphicsQueueIndex;
|
|
|
|
VkQueue fGraphicsQueue;
|
2016-04-06 13:08:59 +00:00
|
|
|
uint32_t fPresentQueueIndex;
|
|
|
|
VkQueue fPresentQueue;
|
2016-05-20 13:01:06 +00:00
|
|
|
|
|
|
|
uint32_t fImageCount;
|
|
|
|
VkImage* fImages; // images in the swapchain
|
|
|
|
VkImageLayout* fImageLayouts; // layouts of these images when not color attachment
|
|
|
|
sk_sp<SkSurface>* fSurfaces; // surfaces client renders to (may not be based on rts)
|
|
|
|
VkCommandPool fCommandPool;
|
|
|
|
BackbufferInfo* fBackbuffers;
|
|
|
|
uint32_t fCurrentBackbufferIndex;
|
2016-04-06 13:08:59 +00:00
|
|
|
};
|
|
|
|
|
2016-05-05 19:32:03 +00:00
|
|
|
} // namespace sk_app
|
|
|
|
|
2016-04-06 13:08:59 +00:00
|
|
|
#endif // SK_VULKAN
|
|
|
|
|
|
|
|
#endif
|