LCOV - code coverage report
Current view: top level - source/renderer/backend/vulkan - SwapChain.h (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 0 6 0.0 %
Date: 2023-01-19 00:18:29 Functions: 0 8 0.0 %

          Line data    Source code
       1             : /* Copyright (C) 2023 Wildfire Games.
       2             :  * This file is part of 0 A.D.
       3             :  *
       4             :  * 0 A.D. is free software: you can redistribute it and/or modify
       5             :  * it under the terms of the GNU General Public License as published by
       6             :  * the Free Software Foundation, either version 2 of the License, or
       7             :  * (at your option) any later version.
       8             :  *
       9             :  * 0 A.D. is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12             :  * GNU General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU General Public License
      15             :  * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
      16             :  */
      17             : 
      18             : #ifndef INCLUDED_RENDERER_BACKEND_VULKAN_SWAPCHAIN
      19             : #define INCLUDED_RENDERER_BACKEND_VULKAN_SWAPCHAIN
      20             : 
      21             : #include "renderer/backend/IFramebuffer.h"
      22             : 
      23             : #include <glad/vulkan.h>
      24             : #include <memory>
      25             : #include <tuple>
      26             : #include <unordered_map>
      27             : #include <vector>
      28             : 
      29             : namespace Renderer
      30             : {
      31             : 
      32             : namespace Backend
      33             : {
      34             : 
      35             : namespace Vulkan
      36             : {
      37             : 
      38             : class CDevice;
      39             : class CFramebuffer;
      40             : class CRingCommandContext;
      41             : class CTexture;
      42             : 
      43           0 : class CSwapChain final
      44             : {
      45             : public:
      46             :     ~CSwapChain();
      47             : 
      48           0 :     VkSwapchainKHR GetVkSwapchain() { return m_SwapChain; }
      49             : 
      50           0 :     bool IsValid() const { return m_IsValid; }
      51             : 
      52             :     bool AcquireNextImage(VkSemaphore acquireImageSemaphore);
      53             :     void SubmitCommandsAfterAcquireNextImage(
      54             :         CRingCommandContext& commandContext);
      55             :     void SubmitCommandsBeforePresent(
      56             :         CRingCommandContext& commandContext);
      57             :     void Present(VkSemaphore submitDone, VkQueue queue);
      58             : 
      59             :     CFramebuffer* GetCurrentBackbuffer(
      60             :         const AttachmentLoadOp colorAttachmentLoadOp,
      61             :         const AttachmentStoreOp colorAttachmentStoreOp,
      62             :         const AttachmentLoadOp depthStencilAttachmentLoadOp,
      63             :         const AttachmentStoreOp depthStencilAttachmentStoreOp);
      64             : 
      65           0 :     CTexture* GetDepthTexture() { return m_DepthTexture.get(); }
      66             : 
      67             : private:
      68             :     friend class CDevice;
      69             : 
      70             :     static std::unique_ptr<CSwapChain> Create(
      71             :         CDevice* device, VkSurfaceKHR surface, int surfaceDrawableWidth, int surfaceDrawableHeight,
      72             :         std::unique_ptr<CSwapChain> oldSwapChain);
      73             : 
      74             :     CSwapChain();
      75             : 
      76             :     CDevice* m_Device = nullptr;
      77             : 
      78             :     bool m_IsValid = false;
      79             :     VkSwapchainKHR m_SwapChain = VK_NULL_HANDLE;
      80             : 
      81           0 :     uint32_t m_CurrentImageIndex = std::numeric_limits<uint32_t>::max();
      82             : 
      83             :     std::vector<VkImage> m_Images;
      84             :     std::vector<std::unique_ptr<CTexture>> m_Textures;
      85             :     std::unique_ptr<CTexture> m_DepthTexture;
      86             :     VkFormat m_ImageFormat = VK_FORMAT_UNDEFINED;
      87             : 
      88           0 :     struct SwapChainBackbuffer
      89             :     {
      90             :         using BackbufferKey = std::tuple<
      91             :             AttachmentLoadOp, AttachmentStoreOp,
      92             :             AttachmentLoadOp, AttachmentStoreOp>;
      93             :         struct BackbufferKeyHash
      94             :         {
      95             :             size_t operator()(const BackbufferKey& key) const;
      96             :         };
      97             :         std::unordered_map<
      98             :             BackbufferKey, std::unique_ptr<CFramebuffer>, BackbufferKeyHash> backbuffers;
      99             : 
     100             :         SwapChainBackbuffer();
     101             : 
     102             :         SwapChainBackbuffer(const SwapChainBackbuffer&) = delete;
     103             :         SwapChainBackbuffer& operator=(const SwapChainBackbuffer&) = delete;
     104             : 
     105             :         SwapChainBackbuffer(SwapChainBackbuffer&& other);
     106             :         SwapChainBackbuffer& operator=(SwapChainBackbuffer&& other);
     107             :     };
     108             :     std::vector<SwapChainBackbuffer> m_Backbuffers;
     109             : };
     110             : 
     111             : } // namespace Vulkan
     112             : 
     113             : } // namespace Backend
     114             : 
     115             : } // namespace Renderer
     116             : 
     117             : #endif // INCLUDED_RENDERER_BACKEND_VULKAN_SWAPCHAIN

Generated by: LCOV version 1.13