Skip to content

Commit 924aa5c

Browse files
committed
- Dev: complete rework of Passes (templatized by in and out attachments, attachments outside now)
1 parent 7a11043 commit 924aa5c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+988
-768
lines changed

.clang-format

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ PenaltyBreakBeforeFirstCallParameter: 0
2525
PointerAlignment: Left
2626
AlignTrailingComments: true
2727
SpaceBeforeParens: ControlStatements
28+
# SpacesInParens: true
2829

2930
# Brace wrapping options
3031
BreakBeforeBraces: Custom
@@ -34,3 +35,5 @@ BraceWrapping:
3435
AfterEnum: true
3536
SplitEmptyFunction: true
3637
SplitEmptyRecord: true
38+
39+

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ sudo apt-get install libxcursor-dev
337337
sudo apt-get install libxi-dev
338338
```
339339

340-
This uses x11 backend, if you want to use Wayland install Wayland depedencies.
340+
This uses x11 as windowing system, if you want to use Wayland install Wayland depedencies.
341341

342342
After that, follow these steps:
343343

include/engine/core/passes/bloom_pass.h

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ both X and Y axes.
2929
A (first downsampled image).
3030
- Finally, we mix the overall bloom contribution into the HDR source image, with a strong bias towards the HDR source.
3131
*/
32-
class BloomPass : public GraphicPass
32+
class BloomPass : public BaseGraphicPass<2, 1>
3333
{
3434
protected:
3535
ColorFormatType m_colorFormat = SRGBA_32F;
@@ -49,8 +49,19 @@ class BloomPass : public GraphicPass
4949
std::vector<Graphics::Framebuffer> m_bloomFramebuffers;
5050

5151
public:
52-
BloomPass(Graphics::Device* ctx, Extent2D extent, bool isDefault = false)
53-
: GraphicPass(ctx, extent, 1, 1, isDefault, "BLOOM") {
52+
/*
53+
Input Attachments:
54+
-
55+
- Lighting
56+
- Bright Lighting (HDR)
57+
58+
Output Attachments:
59+
-
60+
- Bloom + Lighting
61+
62+
*/
63+
BloomPass(Graphics::Device* device, const PassConfig<2, 1>& config, Extent2D extent)
64+
: BaseGraphicPass(device, config, extent, 1, 1, "BLOOM") {
5465
}
5566

5667
inline float get_bloom_strength() const {
@@ -60,16 +71,16 @@ class BloomPass : public GraphicPass
6071
m_bloomStrength = st;
6172
}
6273

63-
void setup_attachments(std::vector<Graphics::AttachmentInfo>& attachments,
64-
std::vector<Graphics::SubPassDependency>& dependencies);
74+
void setup_out_attachments(std::vector<Graphics::AttachmentConfig>& attachments,
75+
std::vector<Graphics::SubPassDependency>& dependencies);
6576

6677
void setup_uniforms(std::vector<Graphics::Frame>& frames);
6778

6879
void setup_shader_passes();
6980

70-
void render(Graphics::Frame& currentFrame, Scene* const scene, uint32_t presentImageIndex = 0);
81+
void execute(Graphics::Frame& currentFrame, Scene* const scene, uint32_t presentImageIndex = 0);
7182

72-
void link_previous_images(std::vector<Graphics::Image> images);
83+
void link_input_attachments();
7384

7485
void resize_attachments();
7586

include/engine/core/passes/composition_pass.h

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct VXGI { // Settings for Voxel Based GI
4747
uint32_t updateMode = 0;
4848
};
4949

50-
class CompositionPass : public GraphicPass
50+
class CompositionPass : public BaseGraphicPass<10, 2>
5151
{
5252
/*Setup*/
5353
ColorFormatType m_colorFormat;
@@ -73,8 +73,23 @@ class CompositionPass : public GraphicPass
7373
void create_prev_frame_image();
7474

7575
public:
76-
CompositionPass(Graphics::Device* ctx, VkExtent2D extent, ColorFormatType colorFormat, bool isDefault = true)
77-
: GraphicPass(ctx, extent, 1, 1, isDefault, "COMPOSITION")
76+
/*
77+
Input Attachments:
78+
-
79+
- Lighting
80+
- Bright Lighting (HDR)
81+
82+
Output Attachments:
83+
- Lighting
84+
- Bright Lighting (HDR)
85+
86+
*/
87+
CompositionPass(Graphics::Device* device,
88+
const PassConfig<10, 2>& config,
89+
VkExtent2D extent,
90+
ColorFormatType colorFormat,
91+
bool isDefault = true)
92+
: BaseGraphicPass(device, config, extent, 1, 1, "COMPOSITION")
7893
, m_colorFormat(colorFormat) {
7994
}
8095

@@ -109,16 +124,16 @@ class CompositionPass : public GraphicPass
109124
m_settings.AOtype = op;
110125
}
111126

112-
void setup_attachments(std::vector<Graphics::AttachmentInfo>& attachments,
113-
std::vector<Graphics::SubPassDependency>& dependencies);
127+
void setup_out_attachments(std::vector<Graphics::AttachmentConfig>& attachments,
128+
std::vector<Graphics::SubPassDependency>& dependencies);
114129

115130
void setup_uniforms(std::vector<Graphics::Frame>& frames);
116131

117132
void setup_shader_passes();
118133

119-
void render(Graphics::Frame& currentFrame, Scene* const scene, uint32_t presentImageIndex = 0);
134+
void execute(Graphics::Frame& currentFrame, Scene* const scene, uint32_t presentImageIndex = 0);
120135

121-
void link_previous_images(std::vector<Graphics::Image> images);
136+
void link_input_attachments();
122137

123138
void update_uniforms(uint32_t frameIndex, Scene* const scene);
124139

include/engine/core/passes/enviroment_pass.h

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,24 @@ This pass does three things:
2121
- Performs a second renderpass to compute the diuffuse irradiance cubemap.
2222
- Performs a third renderpass to compute the specular irradiance cubemap.
2323
*/
24-
class EnviromentPass : public GraphicPass
24+
class EnviromentPass : public BaseGraphicPass<1, 2>
2525
{
2626
ColorFormatType m_format;
2727
Graphics::DescriptorSet m_envDescriptorSet;
2828
Graphics::Buffer m_captureBuffer;
2929
Extent2D m_irradianceResolution;
3030

3131
public:
32-
EnviromentPass(Graphics::Device* ctx)
33-
: GraphicPass(ctx, {1, 1}, 2, CUBEMAP_FACES, false)
32+
/*
33+
34+
Output Attachments:
35+
-
36+
- Enviroment Cubemap
37+
- Diffuse Irradiance Cubemap
38+
39+
*/
40+
EnviromentPass(Graphics::Device* device, const PassConfig<1, 2>& config)
41+
: BaseGraphicPass(device, config, {1, 1}, 2, CUBEMAP_FACES, "ENVIROMENT")
3442
, m_format(SRGBA_32F)
3543
, m_irradianceResolution({1, 1}) {
3644
}
@@ -42,8 +50,8 @@ class EnviromentPass : public GraphicPass
4250
m_irradianceResolution = {res, res};
4351
}
4452

45-
void setup_attachments(std::vector<Graphics::AttachmentInfo>& attachments,
46-
std::vector<Graphics::SubPassDependency>& dependencies);
53+
void setup_out_attachments(std::vector<Graphics::AttachmentConfig>& attachments,
54+
std::vector<Graphics::SubPassDependency>& dependencies);
4755

4856
void create_framebuffer();
4957

@@ -55,9 +63,9 @@ class EnviromentPass : public GraphicPass
5563

5664
void resize_attachments();
5765

58-
void render(Graphics::Frame& currentFrame, Scene* const scene, uint32_t presentImageIndex = 0);
66+
void execute(Graphics::Frame& currentFrame, Scene* const scene, uint32_t presentImageIndex = 0);
5967

60-
void link_previous_images(std::vector<Graphics::Image> images);
68+
void link_input_attachments();
6169

6270
void cleanup();
6371
};
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
2+
#ifndef PASS_FACTORY_H
3+
#define PASS_FACTORY_H
4+
5+
#include <engine/common.h>
6+
#include <engine/core/passes/pass.h>
7+
8+
VULKAN_ENGINE_NAMESPACE_BEGIN
9+
10+
namespace Core {
11+
12+
using PassFactoryFunc = std::function<std::unique_ptr<Core::BasePass>(Graphics::Device*, void* /* config */)>;
13+
14+
class PassFactory
15+
{
16+
private:
17+
std::unordered_map<std::string, PassFactoryFunc> m_factories;
18+
19+
public:
20+
static PassFactory& instance() {
21+
static PassFactory reg;
22+
return reg;
23+
}
24+
25+
void register_type(const std::string& type, PassFactoryFunc func) {
26+
m_factories[type] = std::move(func);
27+
}
28+
29+
std::unique_ptr<Core::BasePass> create(const std::string& type, Graphics::Device* dev, void* config) {
30+
return m_factories.at(type)(dev, config);
31+
}
32+
};
33+
34+
template <typename T, typename ConfigT>
35+
std::unique_ptr<Core::BasePass> make_pass(Graphics::Device* device, void* config) {
36+
return std::make_unique<T>(device, *reinterpret_cast<ConfigT*>(config));
37+
}
38+
39+
#define REGISTER_PASS(PassType, ConfigType, NameStr) \
40+
static bool _##PassType##_registered = [] { \
41+
PassFactory::instance().register_type(NameStr, &make_pass<PassType, ConfigType>); \
42+
return true; \
43+
}()
44+
45+
} // namespace Core
46+
47+
VULKAN_ENGINE_NAMESPACE_END
48+
49+
#endif

include/engine/core/passes/forward_pass.h

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace Core {
2020
/*
2121
STANDARD FORWARD LIGHTING PASS
2222
*/
23-
class ForwardPass : public GraphicPass
23+
class ForwardPass : public BaseGraphicPass<3, 3>
2424
{
2525
/*Setup*/
2626
ColorFormatType m_colorFormat;
@@ -37,32 +37,44 @@ class ForwardPass : public GraphicPass
3737
void setup_material_descriptor(IMaterial* mat);
3838

3939
public:
40-
ForwardPass(Graphics::Device* ctx,
40+
/*
41+
Input Attachments:
42+
-
43+
- Enviroment
44+
- Diffuse Enviroment Irradiance
45+
- Sky
46+
47+
Output Attachments:
48+
-
49+
- Lighting
50+
- Bright Lighting (HDR)
51+
- Depth
52+
*/
53+
ForwardPass(Graphics::Device* device,
54+
const PassConfig<3, 3>& config,
4155
Extent2D extent,
4256
ColorFormatType colorFormat,
4357
ColorFormatType depthFormat,
44-
MSAASamples samples,
45-
bool isDefault = true)
46-
: GraphicPass(ctx, extent, 1,1, isDefault, "FORWARD")
58+
MSAASamples samples)
59+
: BaseGraphicPass(device, config, extent, 1, 1, "FORWARD")
4760
, m_colorFormat(colorFormat)
4861
, m_depthFormat(depthFormat)
4962
, m_aa(samples) {
5063
}
5164

52-
void setup_attachments(std::vector<Graphics::AttachmentInfo>& attachments,
65+
void setup_out_attachments(std::vector<Graphics::AttachmentConfig>& attachments,
5366
std::vector<Graphics::SubPassDependency>& dependencies);
5467

5568
void setup_uniforms(std::vector<Graphics::Frame>& frames);
5669

5770
void setup_shader_passes();
5871

59-
void render(Graphics::Frame& currentFrame, Scene* const scene, uint32_t presentImageIndex = 0);
72+
void execute(Graphics::Frame& currentFrame, Scene* const scene, uint32_t presentImageIndex = 0);
6073

6174
void update_uniforms(uint32_t frameIndex, Scene* const scene);
6275

63-
void link_previous_images(std::vector<Graphics::Image> images);
76+
void link_input_attachments();
6477

65-
void set_envmap_descriptor(Graphics::Image env, Graphics::Image irr);
6678
};
6779

6880
} // namespace Core

include/engine/core/passes/geometry_pass.h

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace Core {
1818
/*
1919
DEFERRED RENDERING GEOMETRY PASS
2020
*/
21-
class GeometryPass : public GraphicPass
21+
class GeometryPass : public BaseGraphicPass<3, 6>
2222
{
2323
/*Setup*/
2424
ColorFormatType m_colorFormat;
@@ -34,29 +34,44 @@ class GeometryPass : public GraphicPass
3434
void setup_material_descriptor(IMaterial* mat);
3535

3636
public:
37-
GeometryPass(Graphics::Device* ctx,
38-
Extent2D extent,
39-
ColorFormatType colorFormat,
40-
ColorFormatType depthFormat,
41-
bool isDefault = false)
42-
: GraphicPass(ctx, extent, 1, 1, isDefault, "GEOMETRY")
37+
/*
38+
Input Attachments:
39+
-
40+
- Enviroment
41+
- Diffuse Enviroment Irradiance
42+
- Sky
43+
44+
Output Attachments:
45+
-
46+
- Position buffer
47+
- Normal buffer
48+
- Albedo buffer
49+
- Material buffer
50+
- Emmissive buffer
51+
- Depth buffer
52+
*/
53+
GeometryPass(Graphics::Device* device,
54+
const PassConfig<3, 6>& config,
55+
Extent2D extent,
56+
ColorFormatType colorFormat,
57+
ColorFormatType depthFormat)
58+
: BaseGraphicPass(device, config, extent, 1, 1, "GEOMETRY")
4359
, m_colorFormat(colorFormat)
4460
, m_depthFormat(depthFormat) {
4561
}
4662

47-
void setup_attachments(std::vector<Graphics::AttachmentInfo>& attachments,
48-
std::vector<Graphics::SubPassDependency>& dependencies);
63+
void setup_out_attachments(std::vector<Graphics::AttachmentConfig>& attachments,
64+
std::vector<Graphics::SubPassDependency>& dependencies);
4965

5066
void setup_uniforms(std::vector<Graphics::Frame>& frames);
5167

5268
void setup_shader_passes();
5369

54-
void render(Graphics::Frame& currentFrame, Scene* const scene, uint32_t presentImageIndex = 0);
70+
void execute(Graphics::Frame& currentFrame, Scene* const scene, uint32_t presentImageIndex = 0);
5571

56-
void link_previous_images(std::vector<Graphics::Image> images);
72+
void link_input_attachments();
5773

5874
void update_uniforms(uint32_t frameIndex, Scene* const scene);
59-
6075
};
6176
} // namespace Core
6277
VULKAN_ENGINE_NAMESPACE_END

0 commit comments

Comments
 (0)