Vulkan: add headless and MSAA backbuffer support (#2472)

* Swapchain class

* Headless support

* MSAA backbuffer

* Fix framebuffer resolve

layout transitions were missing and framebuffer mips and layers weren't used

* Fix blit with MSAA resolve source

only the main texture layout was transitioned

* Fix pipeline hash
This commit is contained in:
pezcode 2021-04-16 18:54:37 +02:00 committed by GitHub
parent 83039433ee
commit 9e025301a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 1512 additions and 1276 deletions

File diff suppressed because it is too large Load Diff

View File

@ -78,13 +78,13 @@
VK_IMPORT_INSTANCE_FUNC(false, vkGetPhysicalDeviceMemoryProperties); \
VK_IMPORT_INSTANCE_FUNC(true, vkGetPhysicalDeviceMemoryProperties2KHR); \
VK_IMPORT_INSTANCE_FUNC(false, vkGetPhysicalDeviceQueueFamilyProperties); \
VK_IMPORT_INSTANCE_FUNC(false, vkGetPhysicalDeviceSurfaceCapabilitiesKHR); \
VK_IMPORT_INSTANCE_FUNC(false, vkGetPhysicalDeviceSurfaceFormatsKHR); \
VK_IMPORT_INSTANCE_FUNC(false, vkGetPhysicalDeviceSurfacePresentModesKHR); \
VK_IMPORT_INSTANCE_FUNC(false, vkGetPhysicalDeviceSurfaceSupportKHR); \
VK_IMPORT_INSTANCE_FUNC(true, vkGetPhysicalDeviceSurfaceCapabilitiesKHR); \
VK_IMPORT_INSTANCE_FUNC(true, vkGetPhysicalDeviceSurfaceFormatsKHR); \
VK_IMPORT_INSTANCE_FUNC(true, vkGetPhysicalDeviceSurfacePresentModesKHR); \
VK_IMPORT_INSTANCE_FUNC(true, vkGetPhysicalDeviceSurfaceSupportKHR); \
VK_IMPORT_INSTANCE_FUNC(false, vkCreateDevice); \
VK_IMPORT_INSTANCE_FUNC(false, vkDestroyDevice); \
VK_IMPORT_INSTANCE_FUNC(false, vkDestroySurfaceKHR); \
VK_IMPORT_INSTANCE_FUNC(true, vkDestroySurfaceKHR); \
/* VK_EXT_debug_report */ \
VK_IMPORT_INSTANCE_FUNC(true, vkCreateDebugReportCallbackEXT); \
VK_IMPORT_INSTANCE_FUNC(true, vkDestroyDebugReportCallbackEXT); \
@ -93,11 +93,11 @@
#define VK_IMPORT_DEVICE \
VK_IMPORT_DEVICE_FUNC(false, vkGetDeviceQueue); \
VK_IMPORT_DEVICE_FUNC(false, vkCreateSwapchainKHR); \
VK_IMPORT_DEVICE_FUNC(false, vkDestroySwapchainKHR); \
VK_IMPORT_DEVICE_FUNC(false, vkGetSwapchainImagesKHR); \
VK_IMPORT_DEVICE_FUNC(false, vkAcquireNextImageKHR); \
VK_IMPORT_DEVICE_FUNC(false, vkQueuePresentKHR); \
VK_IMPORT_DEVICE_FUNC(true, vkCreateSwapchainKHR); \
VK_IMPORT_DEVICE_FUNC(true, vkDestroySwapchainKHR); \
VK_IMPORT_DEVICE_FUNC(true, vkGetSwapchainImagesKHR); \
VK_IMPORT_DEVICE_FUNC(true, vkAcquireNextImageKHR); \
VK_IMPORT_DEVICE_FUNC(true, vkQueuePresentKHR); \
VK_IMPORT_DEVICE_FUNC(false, vkCreateFence); \
VK_IMPORT_DEVICE_FUNC(false, vkDestroyFence); \
VK_IMPORT_DEVICE_FUNC(false, vkCreateSemaphore); \
@ -293,6 +293,7 @@ namespace bgfx { namespace vk
void release(Vk##_name&)
VK_DESTROY
VK_DESTROY_FUNC(DeviceMemory);
VK_DESTROY_FUNC(SurfaceKHR);
#undef VK_DESTROY_FUNC
struct DslBinding
@ -610,16 +611,21 @@ VK_DESTROY_FUNC(DeviceMemory);
, m_currentImageLayout(VK_IMAGE_LAYOUT_UNDEFINED)
, m_singleMsaaImage(VK_NULL_HANDLE)
, m_singleMsaaDeviceMem(VK_NULL_HANDLE)
, m_currentSingleMsaaImageLayout(VK_IMAGE_LAYOUT_UNDEFINED)
{
}
void* create(VkCommandBuffer _commandBuffer, const Memory* _mem, uint64_t _flags, uint8_t _skip);
// internal render target
VkResult create(VkCommandBuffer _commandBuffer, uint32_t _width, uint32_t _height, uint64_t _flags, VkFormat _format, VkImageAspectFlags _aspectMask);
void destroy();
void update(VkCommandBuffer _commandBuffer, uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem);
void resolve(VkCommandBuffer _commandBuffer, uint8_t _resolve);
void resolve(VkCommandBuffer _commandBuffer, uint8_t _resolve, uint32_t _layer, uint32_t _numLayers, uint32_t _mip);
void copyBufferToTexture(VkCommandBuffer _commandBuffer, VkBuffer _stagingBuffer, uint32_t _bufferImageCopyCount, VkBufferImageCopy* _bufferImageCopy);
void setImageMemoryBarrier(VkCommandBuffer _commandBuffer, VkImageLayout _newImageLayout);
VkImageLayout setImageMemoryBarrier(VkCommandBuffer _commandBuffer, VkImageLayout _newImageLayout, bool _singleMsaaImage = false);
VkImageView createView(uint32_t _layer, uint32_t _numLayers, uint32_t _mip, uint32_t _numMips, VkImageViewType _type, bool _renderTarget) const;
@ -647,8 +653,81 @@ VK_DESTROY_FUNC(DeviceMemory);
VkImage m_singleMsaaImage;
VkDeviceMemory m_singleMsaaDeviceMem;
VkImageLayout m_currentSingleMsaaImageLayout;
ReadbackVK m_readback;
private:
VkResult createImages(VkCommandBuffer _commandBuffer);
};
struct SwapChainVK
{
SwapChainVK()
: m_swapchain(VK_NULL_HANDLE)
, m_lastImageRenderedSemaphore(VK_NULL_HANDLE)
, m_lastImageAcquiredSemaphore(VK_NULL_HANDLE)
, m_backBufferColorMsaaImageView(VK_NULL_HANDLE)
{
}
VkResult create(uint32_t queueFamily, VkQueue _queue, VkCommandBuffer _commandBuffer, const Resolution& _resolution);
void destroy();
void update(VkCommandBuffer _commandBuffer, uint32_t _width, uint32_t _height, uint32_t _reset);
VkResult createSurface(uint32_t _reset);
VkResult createSwapChain(uint32_t _reset);
VkResult createRenderPass();
VkResult createFrameBuffer();
void releaseSurface();
void releaseSwapChain();
void releaseRenderPass();
void releaseFrameBuffer();
void initImageLayout(VkCommandBuffer _commandBuffer);
uint32_t findPresentMode(bool _vsync);
bool acquire(VkCommandBuffer _commandBuffer);
void present();
VkQueue m_queue;
VkSwapchainCreateInfoKHR m_sci;
VkSurfaceKHR m_surface;
VkSwapchainKHR m_swapchain;
uint32_t m_numSwapchainImages;
VkSurfaceFormatKHR m_backBufferColorFormat;
VkSurfaceFormatKHR m_backBufferColorFormatSrgb;
VkImageLayout m_backBufferColorImageLayout[BGFX_CONFIG_MAX_BACK_BUFFERS];
VkImage m_backBufferColorImage[BGFX_CONFIG_MAX_BACK_BUFFERS];
VkImageView m_backBufferColorImageView[BGFX_CONFIG_MAX_BACK_BUFFERS];
VkFramebuffer m_backBufferFrameBuffer[BGFX_CONFIG_MAX_BACK_BUFFERS];
VkFence m_backBufferFence[BGFX_CONFIG_MAX_BACK_BUFFERS];
VkRenderPass m_renderPass;
VkSemaphore m_presentDoneSemaphore[BGFX_CONFIG_MAX_BACK_BUFFERS];
VkSemaphore m_renderDoneSemaphore[BGFX_CONFIG_MAX_BACK_BUFFERS];
uint32_t m_currentSemaphore;
VkSemaphore m_lastImageRenderedSemaphore;
VkSemaphore m_lastImageAcquiredSemaphore;
uint32_t m_backBufferColorIdx;
bool m_needPresent;
bool m_needToRefreshSwapchain;
bool m_needToRecreateSurface;
VkFormat m_backBufferDepthStencilFormat;
TextureVK m_backBufferDepthStencil;
VkImageView m_backBufferDepthStencilImageView;
TextureVK m_backBufferColorMsaa;
VkImageView m_backBufferColorMsaaImageView;
MsaaSamplerVK m_sampler;
};
struct FrameBufferVK