Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
SamplerManager.h
Go to the documentation of this file.
1/* Copyright (C) 2026 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_SAMPLERMANAGER
19#define INCLUDED_RENDERER_BACKEND_VULKAN_SAMPLERMANAGER
20
23
24#include <cstddef>
25#include <glad/vulkan.h>
26#include <unordered_map>
27
28namespace Renderer
29{
30
31namespace Backend
32{
33
34namespace Vulkan
35{
36
37class CDevice;
38
39/**
40 * A helper class to store unique samplers. The manager doesn't track usages of
41 * its samplers but keep them alive until its end. So before destroying the
42 * manager its owner should guarantee no usage.
43 */
45{
46public:
47 CSamplerManager(CDevice* device);
49
50 /**
51 * @return a sampler matches the description. The returned sampler is owned by
52 * the manager.
53 */
54 VkSampler GetOrCreateSampler(const Sampler::Desc& samplerDesc);
55
56 void CollectStatistics(IDevice::StatisticsVector& statistics) const;
57
58private:
59 CDevice* m_Device = nullptr;
60
62 {
63 size_t operator()(const Sampler::Desc& samplerDesc) const;
64 };
66 {
67 bool operator()(const Sampler::Desc& lhs, const Sampler::Desc& rhs) const;
68 };
69 std::unordered_map<Sampler::Desc, VkSampler, SamplerDescHash, SamplerDescEqual> m_SamplerMap;
70};
71
72} // namespace Vulkan
73
74} // namespace Backend
75
76} // namespace Renderer
77
78#endif // INCLUDED_RENDERER_BACKEND_VULKAN_SAMPLERMANAGER
std::vector< StatisticsItem > StatisticsVector
Definition: IDevice.h:228
Definition: Device.h:67
A helper class to store unique samplers.
Definition: SamplerManager.h:45
std::unordered_map< Sampler::Desc, VkSampler, SamplerDescHash, SamplerDescEqual > m_SamplerMap
Definition: SamplerManager.h:69
void CollectStatistics(IDevice::StatisticsVector &statistics) const
Definition: SamplerManager.cpp:144
CSamplerManager(CDevice *device)
Definition: SamplerManager.cpp:80
~CSamplerManager()
Definition: SamplerManager.cpp:85
VkSampler GetOrCreateSampler(const Sampler::Desc &samplerDesc)
Definition: SamplerManager.cpp:96
CDevice * m_Device
Definition: SamplerManager.h:59
Backend
Definition: Backend.h:28
Definition: Canvas2D.h:30
Definition: Sampler.h:54
bool operator()(const Sampler::Desc &lhs, const Sampler::Desc &rhs) const
Definition: SamplerManager.cpp:63
size_t operator()(const Sampler::Desc &samplerDesc) const
Definition: SamplerManager.cpp:41