Skip to content

Commit 4a056a1

Browse files
committed
-Dev: First Approach to VXGI
1 parent 856751d commit 4a056a1

File tree

34 files changed

+732
-505
lines changed

34 files changed

+732
-505
lines changed

examples/resources/scenes/sponza.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@
293293

294294
<intensity value="2" />
295295
<color r="0.14" g="0.37" b="0.58" />
296-
<direction x="2.0" y="20.0" z="5.0" />
296+
<direction x="2.0" y="30.0" z="5.0" />
297297

298298
<Shadow type="rt">
299299
<samples value="2" />

include/engine/core/passes/composition_pass.h

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,21 @@ enum class OutputBuffer
2828
EMISSIVE = 6,
2929
SSR = 7,
3030
};
31-
struct SSRSettings {
31+
struct SSR { // Settings for Screen Space Reflections
3232
uint32_t maxSteps = 64;
3333
float stride = 0.1f;
3434
uint32_t binaryRefinementSteps = 6;
3535
float thickness = 0.2f;
3636
float jitter = 0.1f;
37-
int enabled = 1;
37+
uint32_t enabled = 1;
3838
};
39+
struct VXGI { // Settings for Voxel Based GI
40+
float strength = 0.2f;
41+
uint32_t resolution = 256;
42+
uint32_t samples = 8;
43+
uint32_t enabled = 1;
44+
};
45+
3946
class CompositionPass : public GraphicPass
4047
{
4148
/*Setup*/
@@ -54,7 +61,8 @@ class CompositionPass : public GraphicPass
5461
struct Settings {
5562
OutputBuffer outputBuffer = OutputBuffer::LIGHTING;
5663
int enableAO = 1;
57-
SSRSettings ssr = {};
64+
VXGI vxgi = {};
65+
SSR ssr = {};
5866
};
5967
Settings m_settings = {};
6068

@@ -71,12 +79,18 @@ class CompositionPass : public GraphicPass
7179
, m_vignette(vignette) {
7280
}
7381

74-
inline void set_SSR_settings(SSRSettings settings) {
82+
inline void set_SSR_settings(SSR settings) {
7583
m_settings.ssr = settings;
7684
};
77-
inline SSRSettings get_SSR_settings() const {
85+
inline SSR get_SSR_settings() const {
7886
return m_settings.ssr;
7987
};
88+
inline void set_VXGI_settings(VXGI settings) {
89+
m_settings.vxgi = settings;
90+
};
91+
inline VXGI get_VXGI_settings() const {
92+
return m_settings.vxgi;
93+
};
8094
inline void set_output_buffer(OutputBuffer buffer) {
8195
m_settings.outputBuffer = buffer;
8296
};
@@ -105,6 +119,8 @@ class CompositionPass : public GraphicPass
105119

106120
void set_envmap_descriptor(Graphics::Image env, Graphics::Image irr);
107121

122+
void set_voxelization_descriptor(Graphics::Image voxel);
123+
108124
void update();
109125

110126
void cleanup();

include/engine/core/passes/pass.h

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ VULKAN_ENGINE_NAMESPACE_BEGIN
2626

2727
namespace Core {
2828

29+
/*
30+
Data containing a dependicy image's location belonging to a previows pass
31+
*/
32+
struct ImageDependency;
33+
2934
/*
3035
Core abstract class needed for a renderer to work.
3136
It controls the flow of the renderer state, what information and how it is being
@@ -47,13 +52,12 @@ class BasePass
4752
Graphics::RenderPass m_renderpass = {};
4853
std::vector<Graphics::Framebuffer> m_framebuffers;
4954
uint32_t m_framebufferImageDepth; // In case if multilayered rendering.
55+
// In case is not graphical or need auxiliar data, other graphic data can be stored onto these images
56+
std::vector<Graphics::Image> m_resourceImages;
5057

51-
Extent2D m_imageExtent;
52-
std::string m_name;
53-
54-
// Key: Vec2 (Renderpass ID, Framebuffer ID)
55-
// Value: Framebuffer's image attachment IDs
56-
std::unordered_map<iVec2, std::vector<uint32_t>> m_imageDepedanceTable;
58+
Extent2D m_imageExtent;
59+
std::string m_name;
60+
std::vector<ImageDependency> m_imageDependencies; // Previous passes image dependency list
5761

5862
// Query
5963
bool m_initiatized = false;
@@ -106,6 +110,9 @@ class BasePass
106110
inline std::vector<Graphics::Framebuffer> const get_framebuffers() const {
107111
return m_framebuffers;
108112
}
113+
inline std::vector<Graphics::Image> const get_resource_images() const {
114+
return m_resourceImages;
115+
}
109116
inline void set_attachment_clear_value(VkClearValue value, size_t attachmentLayout = 0) {
110117
m_renderpass.attachmentsInfo[attachmentLayout].clearValue = value;
111118
}
@@ -133,17 +140,14 @@ class BasePass
133140
inline std::unordered_map<std::string, Graphics::ShaderPass*> const get_shaderpasses() const {
134141
return m_shaderPasses;
135142
}
136-
137143
/*
138-
Sets a table of depedencies with different passes.
139-
- Key: Vec2 (Renderpass ID, Framebuffer ID)
140-
- Value: array of framebuffer's image attachment IDs
144+
Sets a vector of depedencies with different passes.
141145
*/
142-
inline void set_image_dependace_table(std::unordered_map<iVec2, std::vector<uint32_t>> table) {
143-
m_imageDepedanceTable = table;
146+
inline void set_image_dependencies(std::vector<ImageDependency> dependencies) {
147+
m_imageDependencies = dependencies;
144148
}
145-
inline std::unordered_map<iVec2, std::vector<uint32_t>> get_image_dependace_table() const {
146-
return m_imageDepedanceTable;
149+
inline std::vector<ImageDependency> get_image_dependencies() const {
150+
return m_imageDependencies;
147151
}
148152

149153
#pragma endregion
@@ -185,6 +189,28 @@ class BasePass
185189
#pragma endregion
186190
};
187191

192+
#pragma region IMAGE DEP
193+
194+
struct ImageDependency {
195+
uint32_t passID = 0; // The pass that produces this image
196+
uint32_t fboID = 0; // The FBO within the pass that produces this image
197+
bool isFBO = true; // If set to false, It will take the attachments from the pass resourceImages (Useful if not a
198+
// graphical pass).
199+
std::vector<uint32_t> attachmentIDs; // The attachment indeces within the FBO
200+
201+
ImageDependency(uint32_t passId, u_int fboId, std::vector<uint32_t> attachmentIds)
202+
: passID(passId)
203+
, fboID(fboId)
204+
, attachmentIDs(attachmentIds) {
205+
}
206+
ImageDependency(uint32_t passId, std::vector<uint32_t> attachmentIds)
207+
: passID(passId)
208+
, attachmentIDs(attachmentIds)
209+
, isFBO(false) {
210+
}
211+
};
212+
213+
#pragma endregion
188214
} // namespace Core
189215

190216
VULKAN_ENGINE_NAMESPACE_END

include/engine/core/passes/precomposition_pass.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ class PreCompositionPass : public GraphicPass
4848
const size_t MAX_KERNEL_MEMBERS = 64;
4949
Graphics::Buffer m_kernelBuffer;
5050
bool m_updateSamplesKernel = true;
51-
Graphics::Image m_blurredSSAO;
5251
/*Settings*/
5352
SSAOSettings m_AO = {};
5453

include/engine/core/passes/voxelization_pass.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ namespace Core {
1717

1818
class VoxelizationPass : public GraphicPass
1919
{
20-
Graphics::Image m_voxelization = {};
21-
2220
/*Descriptors*/
2321
struct FrameDescriptors {
2422
Graphics::DescriptorSet globalDescritor;
@@ -32,6 +30,7 @@ class VoxelizationPass : public GraphicPass
3230
public:
3331
VoxelizationPass(Graphics::Device* ctx, uint32_t resolution)
3432
: BasePass(ctx, {resolution, resolution}, 1, 1, false, "VOXELIZATION") {
33+
m_resourceImages.resize(1);
3534
}
3635

3736
void setup_attachments(std::vector<Graphics::AttachmentInfo>& attachments,

include/engine/core/scene/scene.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class Scene : public Object3D
182182
Setup axis-aligned bounding volume for the entire scene. This object might be necessary for some functionalities,
183183
sush as voxelization of the scene.
184184
*/
185-
void setup_AABB();
185+
void update_AABB();
186186
inline AABB get_AABB() const {
187187
return m_volume;
188188
}

include/engine/graphics/command_buffer.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,20 @@ struct CommandBuffer {
110110
void push_constants(ShaderPass& pass, ShaderStageFlags stage, const void* data, uint32_t size, uint32_t offset = 0);
111111

112112
void dispatch_compute(Extent3D grid);
113+
114+
void copy_buffer(Buffer& srcBuffer, Buffer& dstBuffer, size_t size);
115+
116+
/*
117+
Expected layout is LAYOUT_UNDEFINED
118+
*/
119+
void copy_buffer_to_image(Image& img, Buffer& buffer);
120+
121+
/*
122+
Generates mipmaps for a given image following a downsampling by 2 strategy
123+
*/
124+
void generate_mipmaps(Image& img,
125+
ImageLayout initialLayout = LAYOUT_TRANSFER_DST_OPTIMAL,
126+
ImageLayout finalLayout = LAYOUT_SHADER_READ_ONLY_OPTIMAL);
113127
};
114128
struct CommandPool {
115129
VkCommandPool handle = VK_NULL_HANDLE;

include/engine/graphics/device.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,24 @@ class Device
5454
VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME,
5555
VK_KHR_RAY_QUERY_EXTENSION_NAME};
5656
// Utils
57-
Utils::UploadContext m_uploadContext = {};
58-
Utils::QueueFamilyIndices m_queueFamilies = {};
57+
struct UploadContext {
58+
Fence uploadFence;
59+
CommandPool commandPool;
60+
CommandBuffer commandBuffer;
61+
62+
void immediate_submit(std::function<void(CommandBuffer cmd)>&& function);
63+
void cleanup();
64+
};
65+
UploadContext m_uploadContext = {};
66+
5967
#ifdef NDEBUG
6068
const bool m_enableValidationLayers{false};
6169
#else
6270
const bool m_enableValidationLayers{true};
6371
#endif
6472

73+
void create_upload_context();
74+
6575
public:
6676
/*
6777
GETTERS
@@ -113,12 +123,13 @@ class Device
113123
Framebuffer create_framebuffer(RenderPass& renderpass, Extent2D extent, uint32_t layers = 1, uint32_t id = 0);
114124
Framebuffer create_framebuffer(RenderPass& renderpass, Image& img);
115125
Semaphore create_semaphore();
116-
Fence create_fence();
126+
Fence create_fence(bool signaled = true);
117127
/*Create Frame. A frame is a data structure that contains the objects needed for synchronize each frame rendered and
118128
* buffers to contain data needed for the GPU to render*/
119129
Frame create_frame(uint16_t id);
120130
/*Create RenderPass*/
121-
RenderPass create_render_pass(std::vector<AttachmentInfo>& attachments, std::vector<SubPassDependency>& dependencies);
131+
RenderPass create_render_pass(std::vector<AttachmentInfo>& attachments,
132+
std::vector<SubPassDependency>& dependencies);
122133
/*Create Descriptor Pool*/
123134
DescriptorPool create_descriptor_pool(uint32_t maxSets,
124135
uint32_t numUBO,

include/engine/graphics/image.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ struct Image {
6666

6767
void create_GUI_handle();
6868

69-
void upload_image(VkCommandBuffer& cmd, Buffer* stagingBuffer);
70-
71-
void generate_mipmaps(VkCommandBuffer& cmd);
72-
7369
void cleanup(bool destroySampler = true);
7470

7571
Image clone() const;

include/engine/graphics/utilities/bootstrap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ VkDevice create_logical_device(std::unordered_map<QueueType, VkQueue> &queues, V
3838
// VMA
3939
VmaAllocator setup_memory(VkInstance instance, VkDevice device, VkPhysicalDevice gpu);
4040

41+
4142
}; // namespace Booter
4243

4344
} // namespace Graphics

0 commit comments

Comments
 (0)