Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
PipelineState.h
Go to the documentation of this file.
1/* Copyright (C) 2024 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
25
26#include <cstdint>
27#include <glad/vulkan.h>
28#include <memory>
29#include <unordered_map>
30
31namespace Renderer
32{
33
34namespace Backend
35{
36
37namespace Vulkan
38{
39
40class CDevice;
41class CFramebuffer;
42
44{
45public:
46 ~CGraphicsPipelineState() override;
47
48 IDevice* GetDevice() override;
49
51
52 const SGraphicsPipelineStateDesc& GetDesc() const { return m_Desc; }
53
54 VkPipeline GetOrCreatePipeline(
55 const CVertexInputLayout* vertexInputLayout, CFramebuffer* framebuffer);
56
57 DeviceObjectUID GetUID() const { return m_UID; }
58
59private:
60 friend class CDevice;
61
62 static std::unique_ptr<CGraphicsPipelineState> Create(
63 CDevice* device, const SGraphicsPipelineStateDesc& desc);
64
66
67 CDevice* m_Device = nullptr;
68
70
72
73 struct CacheKey
74 {
76 // TODO: try to replace the UID by the only required parameters.
78 };
80 {
81 size_t operator()(const CacheKey& cacheKey) const;
82 };
84 {
85 bool operator()(const CacheKey& lhs, const CacheKey& rhs) const;
86 };
87 std::unordered_map<CacheKey, VkPipeline, CacheKeyHash, CacheKeyEqual> m_PipelineMap;
88};
89
91{
92public:
93 ~CComputePipelineState() override;
94
95 IDevice* GetDevice() override;
96
98
99 const SComputePipelineStateDesc& GetDesc() const { return m_Desc; }
100
101 VkPipeline GetPipeline() { return m_Pipeline; }
102
103 DeviceObjectUID GetUID() const { return m_UID; }
104
105private:
106 friend class CDevice;
107
108 static std::unique_ptr<CComputePipelineState> Create(
109 CDevice* device, const SComputePipelineStateDesc& desc);
110
112
113 CDevice* m_Device{nullptr};
114
116
118
119 VkPipeline m_Pipeline{VK_NULL_HANDLE};
120};
121
122} // namespace Vulkan
123
124} // namespace Backend
125
126} // namespace Renderer
127
128#endif // INCLUDED_RENDERER_BACKEND_VULKAN_PIPELINESTATE
A holder for precompiled compute pipeline description.
Definition: PipelineState.h:207
Definition: IDevice.h:48
A holder for precompiled graphics pipeline description.
Definition: PipelineState.h:198
IShaderProgram is a container for multiple shaders of different types.
Definition: IShaderProgram.h:81
DeviceObjectUID m_UID
Definition: PipelineState.h:115
DeviceObjectUID GetUID() const
Definition: PipelineState.h:103
const SComputePipelineStateDesc & GetDesc() const
Definition: PipelineState.h:99
VkPipeline GetPipeline()
Definition: PipelineState.h:101
SComputePipelineStateDesc m_Desc
Definition: PipelineState.h:117
IDevice * GetDevice() override
Definition: PipelineState.cpp:343
CDevice * m_Device
Definition: PipelineState.h:113
~CComputePipelineState() override
Definition: PipelineState.cpp:336
static std::unique_ptr< CComputePipelineState > Create(CDevice *device, const SComputePipelineStateDesc &desc)
Definition: PipelineState.cpp:310
IShaderProgram * GetShaderProgram() const override
Definition: PipelineState.h:97
VkPipeline m_Pipeline
Definition: PipelineState.h:119
Definition: Device.h:60
Definition: Framebuffer.h:41
const SGraphicsPipelineStateDesc & GetDesc() const
Definition: PipelineState.h:52
IDevice * GetDevice() override
Definition: PipelineState.cpp:304
CDevice * m_Device
Definition: PipelineState.h:67
DeviceObjectUID GetUID() const
Definition: PipelineState.h:57
std::unordered_map< CacheKey, VkPipeline, CacheKeyHash, CacheKeyEqual > m_PipelineMap
Definition: PipelineState.h:87
SGraphicsPipelineStateDesc m_Desc
Definition: PipelineState.h:71
~CGraphicsPipelineState() override
Definition: PipelineState.cpp:84
static std::unique_ptr< CGraphicsPipelineState > Create(CDevice *device, const SGraphicsPipelineStateDesc &desc)
Definition: PipelineState.cpp:73
DeviceObjectUID m_UID
Definition: PipelineState.h:69
VkPipeline GetOrCreatePipeline(const CVertexInputLayout *vertexInputLayout, CFramebuffer *framebuffer)
Definition: PipelineState.cpp:94
IShaderProgram * GetShaderProgram() const override
Definition: PipelineState.h:50
Definition: ShaderProgram.h:50
static constexpr DeviceObjectUID INVALID_DEVICE_OBJECT_UID
Definition: DeviceObjectUID.h:41
uint32_t DeviceObjectUID
Unique identifier for a device object.
Definition: DeviceObjectUID.h:40
Backend
Definition: Backend.h:28
Definition: VideoMode.h:29
Definition: PipelineState.h:175
IShaderProgram * shaderProgram
Definition: PipelineState.h:178
Definition: PipelineState.h:165
IShaderProgram * shaderProgram
Definition: PipelineState.h:168
bool operator()(const CacheKey &lhs, const CacheKey &rhs) const
Definition: PipelineState.cpp:65
size_t operator()(const CacheKey &cacheKey) const
Definition: PipelineState.cpp:57
DeviceObjectUID vertexInputLayoutUID
Definition: PipelineState.h:75
DeviceObjectUID framebufferUID
Definition: PipelineState.h:77