LCOV - code coverage report
Current view: top level - source/renderer/backend/vulkan - PipelineState.h (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 0 5 0.0 %
Date: 2023-01-19 00:18:29 Functions: 0 2 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_PIPELINESTATE
      19             : #define INCLUDED_RENDERER_BACKEND_VULKAN_PIPELINESTATE
      20             : 
      21             : #include "renderer/backend/PipelineState.h"
      22             : #include "renderer/backend/vulkan/Framebuffer.h"
      23             : #include "renderer/backend/vulkan/ShaderProgram.h"
      24             : 
      25             : #include <cstdint>
      26             : #include <glad/vulkan.h>
      27             : #include <memory>
      28             : #include <unordered_map>
      29             : 
      30             : namespace Renderer
      31             : {
      32             : 
      33             : namespace Backend
      34             : {
      35             : 
      36             : namespace Vulkan
      37             : {
      38             : 
      39             : class CDevice;
      40             : class CFramebuffer;
      41             : 
      42             : class CGraphicsPipelineState final : public IGraphicsPipelineState
      43             : {
      44             : public:
      45             :     ~CGraphicsPipelineState() override;
      46             : 
      47             :     IDevice* GetDevice() override;
      48             : 
      49           0 :     IShaderProgram* GetShaderProgram() const override { return m_Desc.shaderProgram; }
      50             : 
      51             :     const SGraphicsPipelineStateDesc& GetDesc() const { return m_Desc; }
      52             : 
      53             :     VkPipeline GetOrCreatePipeline(
      54             :         const CVertexInputLayout* vertexInputLayout, CFramebuffer* framebuffer);
      55             : 
      56             :     using UID = uint32_t;
      57             :     UID GetUID() const { return m_UID; }
      58             : 
      59             : private:
      60             :     friend class CDevice;
      61             : 
      62             :     static std::unique_ptr<CGraphicsPipelineState> Create(
      63             :         CDevice* device, const SGraphicsPipelineStateDesc& desc);
      64             : 
      65           0 :     CGraphicsPipelineState()
      66           0 :     {
      67             :         static uint32_t m_LastAvailableUID = 1;
      68           0 :         m_UID = m_LastAvailableUID++;
      69           0 :     }
      70             : 
      71             :     CDevice* m_Device = nullptr;
      72             : 
      73             :     UID m_UID = 0;
      74             : 
      75             :     SGraphicsPipelineStateDesc m_Desc{};
      76             : 
      77             :     struct CacheKey
      78             :     {
      79             :         CVertexInputLayout::UID vertexInputLayoutUID;
      80             :         // TODO: try to replace the UID by the only required parameters.
      81             :         CFramebuffer::UID framebufferUID;
      82             :     };
      83             :     struct CacheKeyHash
      84             :     {
      85             :         size_t operator()(const CacheKey& cacheKey) const;
      86             :     };
      87             :     struct CacheKeyEqual
      88             :     {
      89             :         bool operator()(const CacheKey& lhs, const CacheKey& rhs) const;
      90             :     };
      91             :     std::unordered_map<CacheKey, VkPipeline, CacheKeyHash, CacheKeyEqual> m_PipelineMap;
      92             : };
      93             : 
      94             : } // namespace Vulkan
      95             : 
      96             : } // namespace Backend
      97             : 
      98             : } // namespace Renderer
      99             : 
     100             : #endif // INCLUDED_RENDERER_BACKEND_VULKAN_PIPELINESTATE

Generated by: LCOV version 1.13