Skip to content

Commit 03fdcab

Browse files
committed
- Dev: rework of descriptors. Automatic update only if necessary
1 parent a700ce2 commit 03fdcab

17 files changed

Lines changed: 405 additions & 446 deletions

include/engine/core/passes/postprocess_pass.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ void PostProcessPass<numberIN, numberOUT>::execute(Graphics::Frame& currentFrame
146146
template <std::size_t numberIN, std::size_t numberOUT> void PostProcessPass<numberIN, numberOUT>::link_input_attachments() {
147147
for (size_t i = 0; i < numberIN; i++)
148148
{
149-
this->m_descriptorPool.update_descriptor(this->m_inAttachments[i], LAYOUT_SHADER_READ_ONLY_OPTIMAL, &m_imageDescriptorSet, i);
149+
this->m_imageDescriptorSet.update(this->m_inAttachments[i], LAYOUT_SHADER_READ_ONLY_OPTIMAL, i);
150150
}
151151
}
152152

include/engine/graphics/accel.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ struct Accel {
2626
VkDeviceAddress deviceAdress = 0;
2727

2828
Buffer buffer = {};
29-
bool binded = false;
3029
uint32_t instances = 0;
3130
AccelGeometryType topology = AccelGeometryType::TRIANGLES;
3231
bool dynamic = false; // For real-time updating

include/engine/graphics/descriptors.h

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,40 @@
1616
#include <engine/graphics/utilities/initializers.h>
1717
#include <engine/graphics/utilities/translator.h>
1818
#include <unordered_map>
19+
#include <variant>
1920

2021
VULKAN_ENGINE_NAMESPACE_BEGIN
2122

2223
namespace Graphics {
2324

25+
using BoundResource = std::variant<VkImageView, VkBuffer, VkAccelerationStructureKHR>;
26+
2427
struct DescriptorSet {
25-
VkDescriptorSet handle{};
2628

27-
std::vector<Buffer*> binded_buffers;
28-
uint32_t layoutID;
29-
uint32_t bindings;
30-
bool isDynamic;
31-
bool allocated{false};
29+
VkDescriptorSet handle = VK_NULL_HANDLE;
30+
VkDevice device = VK_NULL_HANDLE;
31+
uint32_t layoutID;
32+
std::unordered_map<uint32_t, BoundResource> boundSlots;
33+
34+
bool isArrayed = false;
35+
std::unordered_map<uint32_t, BoundResource> boundArraySlots; // Resource per array slot (if arrayed)
36+
37+
/*
38+
Update for Uniform Buffers
39+
*/
40+
void update(Buffer* buffer, size_t dataSize, size_t readOffset, UniformDataType type, uint32_t binding);
41+
/*
42+
Update for Images
43+
*/
44+
void update(Image* image, ImageLayout layout, uint32_t binding, UniformDataType type = UNIFORM_COMBINED_IMAGE_SAMPLER, uint32_t arraySlot = 0);
45+
/*
46+
Update for Image Array
47+
*/
48+
void update(std::vector<Image>& images, ImageLayout layout, uint32_t binding, UniformDataType type = UNIFORM_COMBINED_IMAGE_SAMPLER);
49+
/*
50+
Update for Acceleration Structures
51+
*/
52+
void update(TLAS* accel, uint32_t binding);
3253
};
3354

3455
struct LayoutBinding {
@@ -40,49 +61,32 @@ struct LayoutBinding {
4061
}
4162
};
4263

64+
struct DescriptorLayout {
65+
VkDescriptorSetLayout handle = VK_NULL_HANDLE;
66+
VkDevice device = VK_NULL_HANDLE;
67+
68+
std::vector<LayoutBinding> bindings;
69+
70+
void cleanup();
71+
};
72+
4373
struct DescriptorPool {
44-
VkDescriptorPool handle = VK_NULL_HANDLE;
45-
VkDevice device = VK_NULL_HANDLE;
46-
std::unordered_map<uint32_t, VkDescriptorSetLayout> layouts;
74+
VkDescriptorPool handle = VK_NULL_HANDLE;
75+
VkDevice device = VK_NULL_HANDLE;
76+
std::unordered_map<uint32_t, DescriptorLayout> layouts;
4777

4878
void set_layout(uint32_t layoutSetIndex,
4979
std::vector<LayoutBinding> bindings,
5080
VkDescriptorSetLayoutCreateFlags flags = 0,
5181
VkDescriptorBindingFlagsEXT extFlags = 0);
5282

53-
inline VkDescriptorSetLayout get_layout(uint32_t layoutSetIndex) {
83+
inline DescriptorLayout get_layout(uint32_t layoutSetIndex) {
5484
return layouts[layoutSetIndex];
5585
}
5686

5787
void allocate_descriptor_set(uint32_t layoutSetIndex, DescriptorSet* descriptor);
5888
void allocate_variable_descriptor_set(uint32_t layoutSetIndex, DescriptorSet* descriptor, uint32_t count);
5989

60-
/*
61-
Set writes for Uniform Buffers
62-
*/
63-
void update_descriptor(Buffer* buffer, size_t dataSize, size_t readOffset, DescriptorSet* descriptor, UniformDataType type, uint32_t binding);
64-
/*
65-
Set writes for Images
66-
*/
67-
void update_descriptor(Image* image,
68-
ImageLayout layout,
69-
DescriptorSet* descriptor,
70-
uint32_t binding,
71-
UniformDataType type = UNIFORM_COMBINED_IMAGE_SAMPLER,
72-
uint32_t arraySlot = 0);
73-
/*
74-
Set writes for Image Array
75-
*/
76-
void update_descriptor(std::vector<Image>& images,
77-
ImageLayout layout,
78-
DescriptorSet* descriptor,
79-
uint32_t binding,
80-
UniformDataType type = UNIFORM_COMBINED_IMAGE_SAMPLER);
81-
/*
82-
Set writes for Acceleration Structures
83-
*/
84-
void update_descriptor(TLAS* accel, DescriptorSet* descriptor, uint32_t binding);
85-
8690
void cleanup();
8791
};
8892
/*

src/core/passes/TAA_pass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ void TAAPass::create_framebuffer() {
8181

8282
void TAAPass::link_input_attachments() {
8383
PostProcessPass::link_input_attachments();
84-
this->m_descriptorPool.update_descriptor(
85-
&m_interAttachments[0], LAYOUT_SHADER_READ_ONLY_OPTIMAL, &m_imageDescriptorSet, 2);
84+
this->m_imageDescriptorSet.update(
85+
&m_interAttachments[0], LAYOUT_SHADER_READ_ONLY_OPTIMAL, 2);
8686
}
8787

8888
void TAAPass::execute(Graphics::Frame& currentFrame, Scene* const scene, uint32_t presentImageIndex) {

src/core/passes/bloom_pass.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ void BloomPass::setup_shader_passes() {
8181

8282
m_shaderPasses["upsample"] = upsamplePass;
8383

84-
GraphicShaderPass* bloomPass =
85-
new GraphicShaderPass(m_device->get_handle(), m_renderpass, m_imageExtent, GET_RESOURCE_PATH("shaders/bloom/compose.glsl"));
84+
GraphicShaderPass* bloomPass = new GraphicShaderPass(m_device->get_handle(), m_renderpass, m_imageExtent, GET_RESOURCE_PATH("shaders/bloom/compose.glsl"));
8685
bloomPass->settings.descriptorSetLayoutIDs = {{GLOBAL_LAYOUT, true}};
8786
bloomPass->graphicSettings.attributes = {
8887
{POSITION_ATTRIBUTE, true}, {NORMAL_ATTRIBUTE, false}, {UV_ATTRIBUTE, true}, {TANGENT_ATTRIBUTE, false}, {COLOR_ATTRIBUTE, false}};
@@ -234,18 +233,18 @@ void BloomPass::link_input_attachments() {
234233
// Create auxiliar images for mipmaps
235234
for (size_t i = 0; i < MIPMAP_LEVELS; i++)
236235
{
237-
m_bloomMipmaps[i] = m_bloomImage.clone();
236+
m_bloomMipmaps[i] = m_bloomImage.clone();
238237
m_bloomMipmaps[i].config.baseMipLevel = i;
239238
m_bloomMipmaps[i].config.mipLevels = 1;
240239
m_bloomMipmaps[i].create_view(config);
241240
}
242241

243-
m_descriptorPool.update_descriptor(m_inAttachments[1], LAYOUT_SHADER_READ_ONLY_OPTIMAL, &m_imageDescriptorSet, 0);
244-
m_descriptorPool.update_descriptor(m_inAttachments[0], LAYOUT_SHADER_READ_ONLY_OPTIMAL, &m_imageDescriptorSet, 1);
242+
m_imageDescriptorSet.update(m_inAttachments[1], LAYOUT_SHADER_READ_ONLY_OPTIMAL, 0);
243+
m_imageDescriptorSet.update(m_inAttachments[0], LAYOUT_SHADER_READ_ONLY_OPTIMAL, 1);
245244

246-
m_descriptorPool.update_descriptor(m_bloomMipmaps, LAYOUT_GENERAL, &m_imageDescriptorSet, 2, UNIFORM_STORAGE_IMAGE);
247-
m_descriptorPool.update_descriptor(m_bloomMipmaps, LAYOUT_GENERAL, &m_imageDescriptorSet, 3);
248-
m_descriptorPool.update_descriptor(&m_bloomImage, LAYOUT_SHADER_READ_ONLY_OPTIMAL, &m_imageDescriptorSet, 4);
245+
m_imageDescriptorSet.update(m_bloomMipmaps, LAYOUT_GENERAL, 2, UNIFORM_STORAGE_IMAGE);
246+
m_imageDescriptorSet.update(m_bloomMipmaps, LAYOUT_GENERAL, 3);
247+
m_imageDescriptorSet.update(&m_bloomImage, LAYOUT_SHADER_READ_ONLY_OPTIMAL, 4);
249248
}
250249

251250
void BloomPass::resize_attachments() {

0 commit comments

Comments
 (0)