Skip to content

Commit 306bc70

Browse files
committed
- Dev: final touches and bug fix in new Pass classes.
1 parent 1224719 commit 306bc70

40 files changed

+751
-499
lines changed

examples/raytracing/application.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void Application::run(int argc, char* argv[]) {
3737
settings.clearColor = Vec4(0.02, 0.02, 0.02, 1.0);
3838
settings.enableUI = true;
3939
settings.enableRaytracing = true;
40-
settings.softwareAA = true;
40+
settings.softwareAA = SoftwareAA::FXAA;
4141

4242
init(settings);
4343
while (!m_window->get_window_should_close())

examples/renderer-app/application.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void Application::init(Systems::RendererSettings settings) {
1818
std::placeholders::_3,
1919
std::placeholders::_4));
2020

21-
m_renderer = new Systems::DeferredRenderer(m_window, ShadowResolution::MEDIUM, settings);
21+
m_renderer = new Systems::ForwardRenderer(m_window, ShadowResolution::MEDIUM, settings);
2222

2323
setup();
2424

@@ -32,8 +32,7 @@ void Application::run(int argc, char* argv[]) {
3232
settings.clearColor = Vec4(0.02, 0.02, 0.02, 1.0);
3333
settings.enableUI = true;
3434
settings.enableRaytracing = true;
35-
settings.softwareAA = true;
36-
35+
settings.softwareAA = SoftwareAA::FXAA;
3736

3837
if (argc == 1)
3938
std::cout << "No arguments submitted, initializing with default parameters..." << std::endl;

examples/sponza/application.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void Application::run(int argc, char* argv[]) {
3434
settings.clearColor = Vec4(0.02, 0.02, 0.02, 1.0);
3535
settings.enableUI = true;
3636
settings.enableRaytracing = true;
37-
settings.softwareAA = true;
37+
settings.softwareAA = SoftwareAA::FXAA;
3838

3939
init(settings);
4040
while (!m_window->get_window_should_close())

include/engine/common.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@
6464

6565
#define _LOG(msg) \
6666
{ \
67-
std::cout << "[VKEngine Log] " << msg << std::endl; \
67+
std::cout << "[VKEngine Log] " << msg << std::endl; \
6868
}
6969
#define DEBUG_LOG(msg) \
7070
{ \
71-
std::cout << "[VKEngine Debug] " << msg << std::endl; \
71+
std::cout << "[VKEngine Debug] " << msg << std::endl; \
7272
}
7373
#define ERR_LOG(msg) \
7474
{ \
75-
std::cerr << "[VKEngine Error] " << msg << std::endl; \
75+
std::cerr << "[VKEngine Error] " << msg << std::endl; \
7676
}
7777
#define VK_CHECK(x) \
7878
do \
@@ -183,7 +183,12 @@ enum class ShadowResolution
183183
HIGH = 2048,
184184
ULTRA = 4096
185185
};
186-
186+
enum class SoftwareAA
187+
{
188+
NONE = 0,
189+
FXAA = 1,
190+
TAA = 2
191+
};
187192
enum class SyncType
188193
{
189194
NONE = 0, // No framerate cap (POTENTIAL TEARING)

include/engine/core/passes/bloom_pass.h

Lines changed: 11 additions & 10 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 BaseGraphicPass<2, 1>
32+
class BloomPass : public BaseGraphicPass
3333
{
3434
protected:
3535
ColorFormatType m_colorFormat = SRGBA_32F;
@@ -60,8 +60,9 @@ class BloomPass : public BaseGraphicPass<2, 1>
6060
- Bloom + Lighting
6161
6262
*/
63-
BloomPass(Graphics::Device* device, const PassConfig<2, 1>& config, Extent2D extent)
64-
: BaseGraphicPass(device, config, extent, 1, 1, "BLOOM") {
63+
BloomPass(Graphics::Device* device, const PassLinkage<2, 1>& config, Extent2D extent, bool isDefault = false)
64+
: BaseGraphicPass(device, extent, 1, 1, true, isDefault, "BLOOM") {
65+
BasePass::store_attachments<2, 1>(config);
6566
}
6667

6768
inline float get_bloom_strength() const {
@@ -72,19 +73,19 @@ class BloomPass : public BaseGraphicPass<2, 1>
7273
}
7374

7475
void setup_out_attachments(std::vector<Graphics::AttachmentConfig>& attachments,
75-
std::vector<Graphics::SubPassDependency>& dependencies);
76+
std::vector<Graphics::SubPassDependency>& dependencies) override;
7677

77-
void setup_uniforms(std::vector<Graphics::Frame>& frames);
78+
void setup_uniforms(std::vector<Graphics::Frame>& frames) override;
7879

79-
void setup_shader_passes();
80+
void setup_shader_passes() override;
8081

81-
void execute(Graphics::Frame& currentFrame, Scene* const scene, uint32_t presentImageIndex = 0);
82+
void execute(Graphics::Frame& currentFrame, Scene* const scene, uint32_t presentImageIndex = 0) override;
8283

83-
void link_input_attachments();
84+
void link_input_attachments() override;
8485

85-
void resize_attachments();
86+
void resize_attachments() override;
8687

87-
void cleanup();
88+
void cleanup() override;
8889
};
8990

9091
} // namespace Core

include/engine/core/passes/composition_pass.h

Lines changed: 16 additions & 15 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 BaseGraphicPass<10, 2>
50+
class CompositionPass : public BaseGraphicPass
5151
{
5252
/*Setup*/
5353
ColorFormatType m_colorFormat;
@@ -84,13 +84,14 @@ class CompositionPass : public BaseGraphicPass<10, 2>
8484
- Bright Lighting (HDR)
8585
8686
*/
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")
87+
CompositionPass(Graphics::Device* device,
88+
const PassLinkage<10, 2>& config,
89+
VkExtent2D extent,
90+
ColorFormatType colorFormat,
91+
bool isDefault = false)
92+
: BaseGraphicPass(device, extent, 1, 1, true, isDefault, "COMPOSITION")
9393
, m_colorFormat(colorFormat) {
94+
BasePass::store_attachments<10, 2>(config);
9495
}
9596

9697
inline void set_SSR_settings(SSR settings) {
@@ -125,21 +126,21 @@ class CompositionPass : public BaseGraphicPass<10, 2>
125126
}
126127

127128
void setup_out_attachments(std::vector<Graphics::AttachmentConfig>& attachments,
128-
std::vector<Graphics::SubPassDependency>& dependencies);
129+
std::vector<Graphics::SubPassDependency>& dependencies) override;
129130

130-
void setup_uniforms(std::vector<Graphics::Frame>& frames);
131+
void setup_uniforms(std::vector<Graphics::Frame>& frames) override;
131132

132-
void setup_shader_passes();
133+
void setup_shader_passes() override;
133134

134-
void execute(Graphics::Frame& currentFrame, Scene* const scene, uint32_t presentImageIndex = 0);
135+
void execute(Graphics::Frame& currentFrame, Scene* const scene, uint32_t presentImageIndex = 0) override;
135136

136-
void link_input_attachments();
137+
void link_input_attachments() override;
137138

138-
void update_uniforms(uint32_t frameIndex, Scene* const scene);
139+
void update_uniforms(uint32_t frameIndex, Scene* const scene) override;
139140

140-
void resize_attachments();
141+
void resize_attachments() override;
141142

142-
void cleanup();
143+
void cleanup() override;
143144
};
144145
} // namespace Core
145146
VULKAN_ENGINE_NAMESPACE_END

include/engine/core/passes/enviroment_pass.h

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ 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 BaseGraphicPass<1, 2>
24+
class EnviromentPass : public BaseGraphicPass
2525
{
2626
ColorFormatType m_format;
2727
Graphics::DescriptorSet m_envDescriptorSet;
@@ -30,17 +30,18 @@ class EnviromentPass : public BaseGraphicPass<1, 2>
3030

3131
public:
3232
/*
33-
33+
3434
Output Attachments:
35-
-
35+
-
3636
- Enviroment Cubemap
3737
- Diffuse Irradiance Cubemap
3838
3939
*/
40-
EnviromentPass(Graphics::Device* device, const PassConfig<1, 2>& config)
41-
: BaseGraphicPass(device, config, {1, 1}, 2, CUBEMAP_FACES, "ENVIROMENT")
40+
EnviromentPass(Graphics::Device* device, const PassLinkage<1, 2>& config)
41+
: BaseGraphicPass(device, {1, 1}, 2, CUBEMAP_FACES, false, false, "ENVIROMENT")
4242
, m_format(SRGBA_32F)
4343
, m_irradianceResolution({1, 1}) {
44+
BasePass::store_attachments<1, 2>(config);
4445
}
4546

4647
inline uint32_t get_irradiance_resolution() const {
@@ -51,23 +52,23 @@ class EnviromentPass : public BaseGraphicPass<1, 2>
5152
}
5253

5354
void setup_out_attachments(std::vector<Graphics::AttachmentConfig>& attachments,
54-
std::vector<Graphics::SubPassDependency>& dependencies);
55+
std::vector<Graphics::SubPassDependency>& dependencies) override;
5556

56-
void create_framebuffer();
57+
void create_framebuffer() override;
5758

58-
void setup_uniforms(std::vector<Graphics::Frame>& frames);
59+
void setup_uniforms(std::vector<Graphics::Frame>& frames) override;
5960

60-
void setup_shader_passes();
61+
void setup_shader_passes() override;
6162

62-
void update_uniforms(uint32_t frameIndex, Scene* const scene);
63+
void update_uniforms(uint32_t frameIndex, Scene* const scene) override;
6364

64-
void resize_attachments();
65+
void resize_attachments() override;
6566

66-
void execute(Graphics::Frame& currentFrame, Scene* const scene, uint32_t presentImageIndex = 0);
67+
void execute(Graphics::Frame& currentFrame, Scene* const scene, uint32_t presentImageIndex = 0) override;
6768

68-
void link_input_attachments();
69+
void link_input_attachments() override;
6970

70-
void cleanup();
71+
void cleanup() override;
7172
};
7273

7374
} // namespace Core

include/engine/core/passes/factory/pass_factory.h

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,36 @@ VULKAN_ENGINE_NAMESPACE_BEGIN
99

1010
namespace Core {
1111

12-
using PassFactoryFunc = std::function<std::unique_ptr<Core::BasePass>(Graphics::Device*, void* /* config */)>;
13-
1412
class PassFactory
1513
{
16-
private:
17-
std::unordered_map<std::string, PassFactoryFunc> m_factories;
18-
1914
public:
2015
static PassFactory& instance() {
21-
static PassFactory reg;
22-
return reg;
16+
static PassFactory instance;
17+
return instance;
2318
}
2419

25-
void register_type(const std::string& type, PassFactoryFunc func) {
26-
m_factories[type] = std::move(func);
20+
template <typename T, typename ConfigT> void register_pass(const std::string& name) {
21+
registry[name] = &make_pass<T, ConfigT>;
2722
}
2823

29-
std::unique_ptr<Core::BasePass> create(const std::string& type, Graphics::Device* dev, void* config) {
30-
return m_factories.at(type)(dev, config);
24+
std::unique_ptr<BasePass> create(const std::string& name, Graphics::Device* dev, void* config) const {
25+
auto it = registry.find(name);
26+
if (it != registry.end())
27+
{
28+
return it->second(dev, config);
29+
}
30+
throw std::runtime_error("Pass type not registered: " + name);
3131
}
32+
33+
private:
34+
using CreatorFunc = std::function<std::unique_ptr<BasePass>(Graphics::Device*, void*)>;
35+
std::unordered_map<std::string, CreatorFunc> registry;
36+
PassFactory() = default;
3237
};
3338

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-
}
39+
#define REGISTER_PASS(factory, Type, ConfigT) factory.register_pass<Type, ConfigT>(#Type)
3840

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-
}()
41+
#define REGISTER_PASS_ALIAS(factory, alias, Type, ConfigT) factory.register_pass<Type, ConfigT>(alias)
4442

4543
} // namespace Core
4644

include/engine/core/passes/forward_pass.h

Lines changed: 29 additions & 28 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 BaseGraphicPass<3, 3>
23+
class ForwardPass : public BaseGraphicPass
2424
{
2525
/*Setup*/
2626
ColorFormatType m_colorFormat;
@@ -37,44 +37,45 @@ class ForwardPass : public BaseGraphicPass<3, 3>
3737
void setup_material_descriptor(IMaterial* mat);
3838

3939
public:
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,
55-
Extent2D extent,
56-
ColorFormatType colorFormat,
57-
ColorFormatType depthFormat,
58-
MSAASamples samples)
59-
: BaseGraphicPass(device, config, extent, 1, 1, "FORWARD")
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 PassLinkage<3, 3>& config,
55+
Extent2D extent,
56+
ColorFormatType colorFormat,
57+
ColorFormatType depthFormat,
58+
MSAASamples samples,
59+
bool isDefault = false)
60+
: BaseGraphicPass(device, extent, 1, 1, true, isDefault, "FORWARD")
6061
, m_colorFormat(colorFormat)
6162
, m_depthFormat(depthFormat)
6263
, m_aa(samples) {
64+
BasePass::store_attachments<3, 3>(config);
6365
}
6466

6567
void setup_out_attachments(std::vector<Graphics::AttachmentConfig>& attachments,
66-
std::vector<Graphics::SubPassDependency>& dependencies);
68+
std::vector<Graphics::SubPassDependency>& dependencies) override;
6769

68-
void setup_uniforms(std::vector<Graphics::Frame>& frames);
70+
void setup_uniforms(std::vector<Graphics::Frame>& frames) override;
6971

70-
void setup_shader_passes();
72+
void setup_shader_passes() override;
7173

72-
void execute(Graphics::Frame& currentFrame, Scene* const scene, uint32_t presentImageIndex = 0);
74+
void execute(Graphics::Frame& currentFrame, Scene* const scene, uint32_t presentImageIndex = 0) override;
7375

74-
void update_uniforms(uint32_t frameIndex, Scene* const scene);
75-
76-
void link_input_attachments();
76+
void update_uniforms(uint32_t frameIndex, Scene* const scene) override;
7777

78+
void link_input_attachments() override;
7879
};
7980

8081
} // namespace Core

0 commit comments

Comments
 (0)