Grindstone Game Engine v0.2.0
An open source game engine and toolkit.
Loading...
Searching...
No Matches
TransientResourceManager.hpp
1#pragma once
2
3#include <vector>
4#include <string>
5#include <map>
6#include <stdint.h>
7
8#include <Common/HashedString.hpp>
9#include <Common/Rect.hpp>
10#include <Common/Graphics/Formats.hpp>
11#include <Common/Graphics/Buffer.hpp>
12#include <Common/Graphics/Image.hpp>
13#include <Common/Graphics/CommandBuffer.hpp>
14
15#include "AttachmentInfo.hpp"
16#include "BufferInfo.hpp"
17#include "GpuPassType.hpp"
18
19namespace Grindstone::GraphicsAPI {
20 class CommandBuffer;
21 class DescriptorSet;
22 class Buffer;
23 class Image;
24}
25
26namespace Grindstone::Renderer {
28 Math::Uint2 size;
29 uint32_t samples = 1;
30 uint32_t mipLevels = 1;
31 uint32_t depth = 1;
32 uint32_t arrayLayers = 1;
33 Grindstone::GraphicsAPI::Format format;
34
35 GraphicsAPI::ImageDimension imageDimensions = GraphicsAPI::ImageDimension::Dimension2D;
36 GraphicsAPI::MemoryUsage memoryUsage = GraphicsAPI::MemoryUsage::GPUOnly;
38
39 bool operator==(const TransientImageDescription& other) const {
40 return
41 size == other.size &&
42 samples == other.samples &&
43 mipLevels == other.mipLevels &&
44 arrayLayers == other.arrayLayers &&
45 depth == other.depth &&
46 format == other.format;
47 }
48 };
49
51 size_t size = 0;
52 Grindstone::GraphicsAPI::BufferUsage bufferUsage;
53 Grindstone::GraphicsAPI::MemoryUsage memoryUsage;
54
55 bool operator==(const TransientBufferDescription& other) const {
56 return size == other.size &&
57 bufferUsage == other.bufferUsage &&
58 memoryUsage == other.memoryUsage;
59 }
60
61 bool operator!=(const TransientBufferDescription& other) const {
62 return !(*this == other);
63 }
64 };
65
67 GraphicsAPI::Image* image;
68 GraphicsAPI::ImageLayout currentLayout;
69 GraphicsAPI::AccessFlags currentAccessFlags;
70 Grindstone::GraphicsAPI::PipelineStageBit currentPipelineStage;
71 };
72
74 GraphicsAPI::Buffer* buffer;
75 GraphicsAPI::AccessFlags currentAccessFlags;
76 };
77
82}
83
84namespace std {
85 template<>
86 struct hash<Grindstone::Renderer::TransientImageDescription> {
87 std::size_t operator()(const Grindstone::Renderer::TransientImageDescription& desc) const noexcept {
88 size_t result = std::hash<size_t>{}(
89 static_cast<size_t>(desc.size.x) |
90 static_cast<size_t>(desc.size.y) << 32
91 );
92
93 result ^= std::hash<size_t>{}(
94 static_cast<size_t>(desc.samples) |
95 static_cast<size_t>(desc.mipLevels) << 32
96 );
97
98 result ^= std::hash<size_t>{}(
99 static_cast<size_t>(desc.depth) |
100 static_cast<size_t>(desc.arrayLayers) << 32
101 );
102
103 result ^= std::hash<size_t>{}(
104 static_cast<size_t>(desc.format) |
105 static_cast<size_t>(desc.imageDimensions) << 32
106 );
107
108 result ^= std::hash<size_t>{}(
109 static_cast<size_t>(desc.memoryUsage) |
110 static_cast<size_t>(desc.imageUsage.GetValueUnderlying()) << 32
111 );
112
113 return result;
114 }
115 };
116
117 template<>
118 struct hash<Grindstone::Renderer::TransientBufferDescription> {
119 std::size_t operator()(const Grindstone::Renderer::TransientBufferDescription& desc) const noexcept {
120 size_t result = std::hash<size_t>{}(
121 static_cast<size_t>(desc.bufferUsage) |
122 static_cast<size_t>(desc.memoryUsage) << 32
123 );
124
125 result ^= std::hash<size_t>{}(static_cast<size_t>(desc.size));
126 return result;
127 }
128 };
129}
130
131namespace Grindstone::Renderer {
134 size_t poolIndex;
135 };
136
139 size_t poolIndex;
140 };
141
143 public:
144 void BeginFrame();
145
146 TransientImageKey AcquireImage(Math::Uint2 viewportResolution, Math::Uint2 swapchainResolution, const ImageDescription& desc);
147 TransientBufferKey AcquireBuffer(const BufferDescription& desc);
148
151
152 protected:
153
154 struct PooledImage {
156 int8_t lifetime;
157 bool isUsedThisFrame = false;
158 };
159
162 int8_t lifetime;
163 bool isUsedThisFrame = false;
164 };
165
166 std::unordered_map<TransientImageDescription, std::vector<PooledImage>> images;
167 std::unordered_map<TransientBufferDescription, std::vector<PooledBuffer>> buffers;
168
169 };
170}
Definition Bitset.hpp:331
Definition Buffer.hpp:49
Definition CommandBuffer.hpp:109
Definition DescriptorSet.hpp:15
Definition Image.hpp:49
Definition TransientResourceManager.hpp:142
Definition BufferInfo.hpp:12
Definition AttachmentInfo.hpp:226
Definition TransientResourceManager.hpp:73
Definition TransientResourceManager.hpp:50
Definition TransientResourceManager.hpp:137
Definition TransientResourceManager.hpp:66
Definition TransientResourceManager.hpp:27
Definition TransientResourceManager.hpp:132
Definition TransientResourceManager.hpp:160
Definition TransientResourceManager.hpp:154
Definition TransientResourceManager.hpp:78