Pyrogenesis  trunk
PipelineState.h
Go to the documentation of this file.
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 
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 
43 {
44 public:
45  ~CGraphicsPipelineState() override;
46 
47  IDevice* GetDevice() override;
48 
49  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 
66  {
67  static uint32_t m_LastAvailableUID = 1;
68  m_UID = m_LastAvailableUID++;
69  }
70 
71  CDevice* m_Device = nullptr;
72 
73  UID m_UID = 0;
74 
76 
77  struct CacheKey
78  {
80  // TODO: try to replace the UID by the only required parameters.
82  };
83  struct CacheKeyHash
84  {
85  size_t operator()(const CacheKey& cacheKey) const;
86  };
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
UID m_UID
Definition: PipelineState.h:73
const SGraphicsPipelineStateDesc & GetDesc() const
Definition: PipelineState.h:51
IDevice * GetDevice() override
Definition: PipelineState.cpp:299
Definition: ShaderProgram.h:45
CFramebuffer::UID framebufferUID
Definition: PipelineState.h:81
Definition: Device.h:59
~CGraphicsPipelineState() override
Definition: PipelineState.cpp:83
std::unordered_map< CacheKey, VkPipeline, CacheKeyHash, CacheKeyEqual > m_PipelineMap
Definition: PipelineState.h:91
Definition: Framebuffer.h:39
Definition: IDevice.h:47
Definition: PipelineState.h:164
A holder for precompiled graphics pipeline description.
Definition: PipelineState.h:190
IShaderProgram is a container for multiple shaders of different types.
Definition: IShaderProgram.h:80
CGraphicsPipelineState()
Definition: PipelineState.h:65
Backend
Definition: Backend.h:27
IShaderProgram * GetShaderProgram() const override
Definition: PipelineState.h:49
SGraphicsPipelineStateDesc m_Desc
Definition: PipelineState.h:75
IShaderProgram * shaderProgram
Definition: PipelineState.h:168
CVertexInputLayout::UID vertexInputLayoutUID
Definition: PipelineState.h:79
unsigned int uint32_t
Definition: wposix_types.h:53
Definition: VideoMode.h:28
CDevice * m_Device
Definition: PipelineState.h:71
uint32_t UID
Definition: Framebuffer.h:64
uint32_t UID
Definition: ShaderProgram.h:66
UID GetUID() const
Definition: PipelineState.h:57
uint32_t UID
Definition: PipelineState.h:56
static std::unique_ptr< CGraphicsPipelineState > Create(CDevice *device, const SGraphicsPipelineStateDesc &desc)
Definition: PipelineState.cpp:73
VkPipeline GetOrCreatePipeline(const CVertexInputLayout *vertexInputLayout, CFramebuffer *framebuffer)
Definition: PipelineState.cpp:93