Grindstone Game Engine
v0.2.0
An open source game engine and toolkit.
Toggle main menu visibility
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
19
namespace
Grindstone::GraphicsAPI {
20
class
CommandBuffer
;
21
class
DescriptorSet
;
22
class
Buffer
;
23
class
Image
;
24
}
25
26
namespace
Grindstone::Renderer {
27
struct
TransientImageDescription
{
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;
37
Grindstone::Containers::BitsetFlags<GraphicsAPI::ImageUsageFlags>
imageUsage;
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
50
struct
TransientBufferDescription
{
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
66
struct
TransientImageData
{
67
GraphicsAPI::Image
* image;
68
GraphicsAPI::ImageLayout currentLayout;
69
GraphicsAPI::AccessFlags currentAccessFlags;
70
Grindstone::GraphicsAPI::PipelineStageBit currentPipelineStage;
71
};
72
73
struct
TransientBufferData
{
74
GraphicsAPI::Buffer
* buffer;
75
GraphicsAPI::AccessFlags currentAccessFlags;
76
};
77
78
union
TransientResourceUnion
{
79
TransientImageData
image;
80
TransientBufferData
buffer;
81
};
82
}
83
84
namespace
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
131
namespace
Grindstone::Renderer {
132
struct
TransientImageKey
{
133
TransientImageDescription
poolkey;
134
size_t
poolIndex;
135
};
136
137
struct
TransientBufferKey
{
138
TransientBufferDescription
poolkey;
139
size_t
poolIndex;
140
};
141
142
class
TransientResourceManager
{
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
149
Grindstone::Renderer::TransientImageData
& GetTrackedImage(
TransientImageKey
key);
150
Grindstone::Renderer::TransientBufferData
& GetTrackedBuffer(
TransientBufferKey
key);
151
152
protected
:
153
154
struct
PooledImage
{
155
TransientImageData
data;
156
int8_t lifetime;
157
bool
isUsedThisFrame =
false
;
158
};
159
160
struct
PooledBuffer
{
161
TransientBufferData
data;
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
}
Grindstone::Containers::BitsetFlags
Definition
Bitset.hpp:331
Grindstone::GraphicsAPI::Buffer
Definition
Buffer.hpp:49
Grindstone::GraphicsAPI::CommandBuffer
Definition
CommandBuffer.hpp:109
Grindstone::GraphicsAPI::DescriptorSet
Definition
DescriptorSet.hpp:15
Grindstone::GraphicsAPI::Image
Definition
Image.hpp:49
Grindstone::Renderer::TransientResourceManager
Definition
TransientResourceManager.hpp:142
Grindstone::Renderer::BufferDescription
Definition
BufferInfo.hpp:12
Grindstone::Renderer::ImageDescription
Definition
AttachmentInfo.hpp:226
Grindstone::Renderer::TransientBufferData
Definition
TransientResourceManager.hpp:73
Grindstone::Renderer::TransientBufferDescription
Definition
TransientResourceManager.hpp:50
Grindstone::Renderer::TransientBufferKey
Definition
TransientResourceManager.hpp:137
Grindstone::Renderer::TransientImageData
Definition
TransientResourceManager.hpp:66
Grindstone::Renderer::TransientImageDescription
Definition
TransientResourceManager.hpp:27
Grindstone::Renderer::TransientImageKey
Definition
TransientResourceManager.hpp:132
Grindstone::Renderer::TransientResourceManager::PooledBuffer
Definition
TransientResourceManager.hpp:160
Grindstone::Renderer::TransientResourceManager::PooledImage
Definition
TransientResourceManager.hpp:154
Grindstone::Renderer::TransientResourceUnion
Definition
TransientResourceManager.hpp:78
sources
code
Common
Rendering
TransientResourceManager.hpp
Generated by
1.17.0