Skip to content

Commit 08a93e3

Browse files
authored
Merge pull request #27 from aka411/feature/improving-render-graph
feat(render-graph): implement dynamic window resize handling
2 parents da7571a + 7862a50 commit 08a93e3

10 files changed

Lines changed: 164 additions & 92 deletions

File tree

include/rendering-system/gpu-resource-system/data-structures/gpu_mesh_system_data_structures.h

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ A uint8_t would suffice
6060
UV_1 = 1 << 4,
6161
TANGENT = 1 << 5,
6262
WEIGHTS = 1 << 6,//A vec4 most times
63-
JOINTS = 1 << 7// I have seen it be uint16 or uint32 i think
63+
JOINTS = 1 << 7// I have seen it be uint16 or uint32
6464
};
6565

6666

@@ -89,7 +89,7 @@ A uint8_t would suffice
8989
STANDARD_2_5D = static_cast<uint16_t>(VertexAttributeBits::POSITION | VertexAttributeBits::NORMAL | VertexAttributeBits::UV_0),
9090
//POSITION_ONLY
9191

92-
//yeah color or colour
92+
9393
STANDARD_2D_COLOUR = static_cast<uint16_t>(VertexAttributeBits::POSITION | VertexAttributeBits::COLOR)
9494

9595
};
@@ -103,14 +103,6 @@ A uint8_t would suffice
103103

104104

105105

106-
107-
108-
109-
110-
111-
112-
113-
114106
struct MeshUploadData
115107
{
116108
VertexFormat vertexFormat = VertexFormat::STANDARD;
@@ -157,9 +149,6 @@ A uint8_t would suffice
157149

158150

159151

160-
161-
//How about a mesh Id
162-
163152
using MeshId = uint64_t;
164153

165154
struct MeshInfo
@@ -183,29 +172,4 @@ A uint8_t would suffice
183172
};
184173

185174

186-
187-
/*
188-
Buffer A(Position) : vec3 positions for all meshes in the game.
189-
190-
Buffer B(Attributes) : Normals, UVs, and Tangents for all meshes.
191-
192-
Buffer C(Indices) : All uint32_t or uint16_t index data.
193-
194-
195-
struct DrawCall
196-
{
197-
//For all vertex data , we will also have a verteformat
198-
uint32_t vertexOffset; // Offset in the Position Stream
199-
uint32_t attributeOffset; // Offset in the UV/Normal Stream
200-
201-
uint32_t indexOffset; // Offset in the Global Index Buffer
202-
uint32_t indexCount;
203-
// ...
204-
};
205-
206-
*/
207-
208-
209-
210-
211175
}

include/rendering-system/render-graph/gpu_resource_resolver.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include <rendering-system/engine_handles.h>
33
#include <rendering-system/gpu-resource-system/data-structures/gpu_mesh_system_data_structures.h>
44
#include <rendering-system/gpu-resource-system/data-structures/gpu_material_system_data_structures.h>
5+
#include <rendering-system/render-graph/render_graph_types.h>
6+
57

68
namespace TheEngine::RenderingSystem
79
{
@@ -14,10 +16,11 @@ namespace TheEngine::RenderingSystem
1416
private:
1517

1618
GPUResourceSystem& m_gpuResourceSystem;
19+
RenderGraphResources& m_renderGraphResources;
1720

1821
public:
1922

20-
GPUResourceResolver(GPUResourceSystem& gpuResourceSystem);
23+
GPUResourceResolver(GPUResourceSystem& gpuResourceSystem, RenderGraphResources& renderGraphResources);
2124

2225
const BufferHandle getMeshBufferHandle(const VertexFormat& vertexFormat, const BufferResourceUsageHint& bufferResourceUsageHint) const;
2326
const BufferHandle getIndexBufferhandle(const IndexFormat& indexFormat, const BufferResourceUsageHint& bufferResourceUsageHint) const;
@@ -26,6 +29,10 @@ namespace TheEngine::RenderingSystem
2629

2730
//const BufferHandle getAnimationBufferHandle() const;
2831

32+
33+
//Texture
34+
const TextureHandle getTextureHandle(const std::string& name) const;
35+
const TextureHandle getTextureHandle(const VirtualTextureId virtualTextureId) const;
2936
};
3037

3138

include/rendering-system/render-graph/i_render_graph_node.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ namespace TheEngine::RenderingSystem
1919
virtual void setUp(RenderPassSetupContext& ctx, RenderGraphBuilder& builder) = 0;
2020
virtual void execute(RenderPassExecuteContext& ctx, GPUResourceResolver& gpuResourceResolver) = 0;
2121

22-
//virtual void onResize(const WindowExtent& extent, RenderGraphBuilder& builder) = 0;
23-
24-
//virtual std::string getName() const = 0;
25-
26-
2722
};
2823

2924

include/rendering-system/render-graph/render_graph.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
#pragma once
2-
#include <vector>
3-
#include <string>
4-
#include <memory>
5-
62

73

84
#include <rendering-system/render-graph/render_graph_types.h>
@@ -11,19 +7,26 @@
117
#include <rendering-system/render-graph/gpu_resource_resolver.h>
128

139

10+
1411
namespace TheEngine::RenderingSystem
1512
{
1613

1714

1815
class IRenderDevice;
16+
class ITextureManager;
1917

2018
struct RenderPassSetupContext;
2119
struct RenderPassExecuteContext;
2220

2321

22+
2423
class RenderGraph
2524
{
2625

26+
private:
27+
28+
ITextureManager& m_textureManager;
29+
RenderGraphResources m_renderGraphResources;
2730

2831
private:
2932

@@ -35,7 +38,6 @@ namespace TheEngine::RenderingSystem
3538
RenderGraphBuilder m_renderGraphBuilder;
3639

3740
RenderPassSetupContext m_renderPassSetupContext;
38-
3941

4042
private:
4143

include/rendering-system/render-graph/render_graph_builder.h

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#pragma once
22
#include <string>
3-
#include <unordered_map>
4-
#include <rendering-system/engine_handles.h>
3+
4+
55
#include <rendering-system/rhi/data-structures/gpu_texture_data_structures.h>
6-
#include <map>
6+
#include <rendering-system/render-graph/render_graph_types.h>
77

88

99
namespace TheEngine::RenderingSystem
@@ -20,26 +20,20 @@ namespace TheEngine::RenderingSystem
2020

2121
IRenderDevice& m_renderDevice;
2222

23-
std::unordered_map<std::string, TextureHandle> m_textureResources;
24-
// std::unordered_map<TextureHandle, std::string> m_textureResourcesMapping;
25-
// std::map<uint64_t, TextureHandle> m_textureBufferResource;
26-
27-
//FRAME DATA
28-
29-
23+
RenderGraphResources& m_renderGraphResources;
3024

3125
public:
3226

33-
RenderGraphBuilder(IRenderDevice& renderDevice);
27+
RenderGraphBuilder(IRenderDevice& renderDevice, RenderGraphResources& renderGraphResources);
3428

3529

3630

37-
TextureHandle createTexture(const std::string& name, TextureCreateInfo& textureCreateInfo);
31+
void createTexture(const std::string& name, TextureCreateInfo& textureCreateInfo, const ResizeParameters& resizeParameters);
3832

39-
TextureHandle readTexture(const std::string& name);//string based look up
40-
TextureHandle writeTexture(const std::string& name);
33+
VirtualTextureId readTexture(const std::string& name);
34+
VirtualTextureId writeTexture(const std::string& name);
4135

42-
TextureHandle writeSwapChainImage();
36+
// VirtualTextureId writeSwapChainImage();
4337

4438

4539

include/rendering-system/render-graph/render_graph_types.h

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
#include <string>
77
#include <rendering-system/rendering_system_data_types.h>
88

9+
10+
#include <rendering-system/engine_handles.h>
11+
#include <unordered_map>
12+
#include <vector>
13+
914
namespace TheEngine::RenderingSystem
1015
{
1116

@@ -49,14 +54,57 @@ namespace TheEngine::RenderingSystem
4954
enum class ResizingMode
5055
{
5156
ABSOLUTE,
52-
RELATIVE
57+
RELATIVE_FRAMEBUFFER,
58+
MATCH_FRAMEBUFFER
5359
};
5460

5561
struct ResizeParameters
5662
{
57-
ResizingMode resizingMode{ ResizingMode::ABSOLUTE};
63+
ResizingMode resizingMode{ ResizingMode::MATCH_FRAMEBUFFER };
5864
float relativeMultiplier{ 1.0f };
5965
};
6066

67+
struct RenderGraphTextureCreateInfo
68+
{
69+
ResizeParameters resizeParameters{};
70+
TextureCreateInfo textureCreateInfo{};
71+
};
72+
73+
74+
template<typename Tag>
75+
struct VirtualResourceHandle
76+
{
77+
size_t id{ 0 };
78+
};
79+
80+
using VirtualTextureId = VirtualResourceHandle<struct VirtualTextureTag>;
81+
82+
83+
84+
85+
86+
87+
struct RenderGraphResources
88+
{
89+
std::unordered_map<std::string, VirtualTextureId> textureResources;
90+
//Index is virtual handle
91+
std::vector<RenderGraphTextureCreateInfo> textureCreateInfos;
92+
std::vector<TextureHandle> textureHandles;
93+
94+
TextureHandle getTextureHandle(const VirtualTextureId virtualTextureId) const
95+
{
96+
assert(virtualTextureId.id < textureHandles.size());
97+
return textureHandles[virtualTextureId.id];
98+
}
99+
100+
TextureHandle getTextureHandle(const std::string& name) const
101+
{
102+
const auto& vd = textureResources.at(name);
103+
return getTextureHandle(vd);
104+
}
105+
106+
};
107+
108+
61109

62110
}

src/rendering-system/api-backend/vulkan/vulkan_texture_manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ namespace TheEngine::RenderingSystem::VulkanBackend
6161

6262

6363
//TODO : IMPLEMENT THIS
64-
64+
assert(false && "Need to write code to destroy texture");
6565

6666
}
6767

src/rendering-system/render-graph/gpu_resource_resolver.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ namespace TheEngine::RenderingSystem
88

99

1010

11-
GPUResourceResolver::GPUResourceResolver(GPUResourceSystem& gpuResourceSystem):
12-
m_gpuResourceSystem(gpuResourceSystem)
11+
GPUResourceResolver::GPUResourceResolver(GPUResourceSystem& gpuResourceSystem, RenderGraphResources& renderGraphResources):
12+
m_gpuResourceSystem(gpuResourceSystem),
13+
m_renderGraphResources(renderGraphResources)
1314
{
1415

1516
}
@@ -36,4 +37,16 @@ namespace TheEngine::RenderingSystem
3637
}
3738
*/
3839

40+
const TextureHandle GPUResourceResolver::getTextureHandle(const std::string& name) const
41+
{
42+
return m_renderGraphResources.getTextureHandle(name);
43+
}
44+
45+
const TextureHandle GPUResourceResolver::getTextureHandle(const VirtualTextureId virtualTextureId) const
46+
{
47+
return m_renderGraphResources.getTextureHandle(virtualTextureId);
48+
}
49+
50+
51+
3952
}

src/rendering-system/render-graph/render_graph.cpp

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,65 @@
11
#include <rendering-system/render-graph/render_graph.h>
22
#include <rendering-system/rhi/i_command_buffer.h>
3-
4-
3+
#include <rendering-system/gpu-resource-system/gpu_resource_system.h>
4+
#include <rendering-system/rhi/i_texture_manager.h>
55
namespace TheEngine::RenderingSystem
66
{
77

88
void RenderGraph::onWindowResize(const WindowExtent& extent)
99
{
10-
10+
//WARNING : This method assumes the caller has made sure all work submitted using all these resources here are completed
11+
1112
m_renderPassSetupContext.windowExtent = extent;
1213

13-
//assert(m_textureResources.size() == m_textureResourcesMapping.size());
14+
for (const auto texturehandle : m_renderGraphResources.textureHandles)
15+
{
16+
m_textureManager.destroyTexture(texturehandle);
17+
}
1418

15-
//delete old
16-
//create new based on new sizes
19+
m_renderGraphResources.textureHandles.clear();
20+
21+
for (const auto& renderGraphTextureCreateInfo : m_renderGraphResources.textureCreateInfos)
22+
{
23+
24+
auto modifiedTextureCreateInfo = renderGraphTextureCreateInfo.textureCreateInfo;
25+
auto& desc = modifiedTextureCreateInfo.desc;
26+
switch (renderGraphTextureCreateInfo.resizeParameters.resizingMode)
27+
{
28+
case ResizingMode::ABSOLUTE:
29+
{
30+
//Do nothing
31+
break;
32+
}
33+
34+
case ResizingMode::RELATIVE_FRAMEBUFFER:
35+
{
36+
const float multiplier = renderGraphTextureCreateInfo.resizeParameters.relativeMultiplier;
37+
desc.width = extent.framebuffer.width * multiplier;
38+
desc.height = extent.framebuffer.height * multiplier;
39+
break;
40+
}
41+
case ResizingMode::MATCH_FRAMEBUFFER:
42+
{
43+
desc.width = extent.framebuffer.width;
44+
desc.height = extent.framebuffer.height;
45+
break;
46+
}
47+
48+
}
49+
50+
m_renderGraphResources.textureHandles.push_back(m_textureManager.createTexture(modifiedTextureCreateInfo));
51+
52+
53+
}
1754

1855
}
1956

2057

2158
RenderGraph::RenderGraph(IRenderDevice& renderDevice, const RenderPassSetupContext& renderPassSetupContext, GPUResourceSystem& gpuResourceSystem) :
22-
m_renderGraphBuilder(renderDevice),
59+
m_textureManager(gpuResourceSystem.getTextureManager()),
60+
m_renderGraphBuilder(renderDevice,m_renderGraphResources),
2361
m_renderPassSetupContext(renderPassSetupContext),
24-
m_gpuResourceResolver(gpuResourceSystem)
62+
m_gpuResourceResolver(gpuResourceSystem, m_renderGraphResources)
2563
{
2664

2765

0 commit comments

Comments
 (0)