Skip to content

Commit 21f814d

Browse files
committed
Add DescriptorSet
1 parent 1b136fb commit 21f814d

9 files changed

Lines changed: 187 additions & 2 deletions

File tree

src/engine/renderer-vulkan/GraphicsCore/Decls.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ VK_DEFINE_HANDLE( VkQueue );
5454
VK_DEFINE_NON_DISPATCHABLE_HANDLE( VkSurfaceKHR )
5555
VK_DEFINE_NON_DISPATCHABLE_HANDLE( VkSwapchainKHR )
5656

57+
VK_DEFINE_NON_DISPATCHABLE_HANDLE( VkDescriptorSetLayout )
58+
VK_DEFINE_NON_DISPATCHABLE_HANDLE( VkDescriptorSet )
59+
5760
struct GraphicsQueueRingBuffer;
5861

5962
extern GraphicsQueueRingBuffer graphicsQueue;

src/engine/renderer-vulkan/GraphicsCore/EngineConfig.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ EngineConfig GetEngineConfigForDevice( const VkPhysicalDevice& device ) {
9898
.filterMinmaxSingleComponentFormats = ( bool ) properties12.filterMinmaxSingleComponentFormats,
9999
.filterMinmaxImageComponentMapping = ( bool ) properties12.filterMinmaxImageComponentMapping,
100100

101+
.maxImages = properties12.maxPerStageDescriptorUpdateAfterBindSampledImages,
102+
.maxStorageImages = properties12.maxPerStageDescriptorUpdateAfterBindStorageImages,
103+
101104
.maxImageSize2D = limits.maxImageDimension2D,
102105
.maxImageSize3D = limits.maxImageDimension3D,
103106
.maxImageSizeCube = limits.maxImageDimensionCube,

src/engine/renderer-vulkan/GraphicsCore/EngineConfig.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ struct EngineConfig {
9999
bool filterMinmaxSingleComponentFormats;
100100
bool filterMinmaxImageComponentMapping;
101101

102+
uint32 maxImages;
103+
uint32 maxStorageImages;
104+
102105
uint32 maxImageSize2D;
103106
uint32 maxImageSize3D;
104107
uint32 maxImageSizeCube;

src/engine/renderer-vulkan/GraphicsCore/GraphicsCoreStore.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,7 @@ VkDevice device;
6363
GraphicsQueueRingBuffer graphicsQueue;
6464
GraphicsQueueRingBuffer computeQueue;
6565
GraphicsQueueRingBuffer transferQueue;
66-
GraphicsQueueRingBuffer sparseQueue;
66+
GraphicsQueueRingBuffer sparseQueue;
67+
68+
VkDescriptorSetLayout descriptorSetLayout;
69+
VkDescriptorSet descriptorSet;

src/engine/renderer-vulkan/GraphicsCore/GraphicsCoreStore.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,7 @@ extern GraphicsQueueRingBuffer computeQueue;
5656
extern GraphicsQueueRingBuffer transferQueue;
5757
extern GraphicsQueueRingBuffer sparseQueue;
5858

59+
extern VkDescriptorSetLayout descriptorSetLayout;
60+
extern VkDescriptorSet descriptorSet;
61+
5962
#endif // GRAPHICS_CORE_STORE_H

src/engine/renderer-vulkan/GraphicsCore/Instance.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5353

5454
#include "GraphicsCoreStore.h"
5555

56+
#include "Memory/DescriptorSet.h"
57+
5658
#include "Instance.h"
5759

5860

@@ -150,4 +152,6 @@ void Instance::Init( const char* engineName, const char* appName ) {
150152
}
151153

152154
Log::Notice( foundQueues );
155+
156+
AllocDescriptors( engineConfig.maxImages, engineConfig.maxStorageImages );
153157
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
===========================================================================
3+
4+
Daemon BSD Source Code
5+
Copyright (c) 2025 Daemon Developers
6+
All rights reserved.
7+
8+
This file is part of the Daemon BSD Source Code (Daemon Source Code).
9+
10+
Redistribution and use in source and binary forms, with or without
11+
modification, are permitted provided that the following conditions are met:
12+
* Redistributions of source code must retain the above copyright
13+
notice, this list of conditions and the following disclaimer.
14+
* Redistributions in binary form must reproduce the above copyright
15+
notice, this list of conditions and the following disclaimer in the
16+
documentation and/or other materials provided with the distribution.
17+
* Neither the name of the Daemon developers nor the
18+
names of its contributors may be used to endorse or promote products
19+
derived from this software without specific prior written permission.
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24+
DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY
25+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
32+
===========================================================================
33+
*/
34+
// DescriptorSet.cpp
35+
36+
#include "../Vulkan.h"
37+
38+
#include "../GraphicsCoreStore.h"
39+
40+
#include "../../GraphicsShared/Bindings.h"
41+
42+
#include "DescriptorSet.h"
43+
44+
static VkDescriptorPool descriptorPool;
45+
46+
void AllocDescriptors( const uint32 imageCount, const uint32 storageImageCount ) {
47+
VkDescriptorPoolSize imagePools[] {
48+
{
49+
.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
50+
.descriptorCount = imageCount
51+
},
52+
{
53+
.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
54+
.descriptorCount = storageImageCount
55+
}
56+
};
57+
58+
VkDescriptorPoolCreateInfo info {
59+
.flags = VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT,
60+
.maxSets = 1,
61+
.poolSizeCount = 2,
62+
.pPoolSizes = imagePools
63+
};
64+
65+
vkCreateDescriptorPool( device, &info, nullptr, &descriptorPool );
66+
67+
VkDescriptorSetLayoutBinding imageBinds[] {
68+
{
69+
.binding = BIND_IMAGES,
70+
.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
71+
.descriptorCount = imageCount,
72+
.stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT | VK_SHADER_STAGE_COMPUTE_BIT
73+
},
74+
{
75+
.binding = BIND_STORAGE_IMAGES,
76+
.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
77+
.descriptorCount = storageImageCount,
78+
.stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT | VK_SHADER_STAGE_COMPUTE_BIT
79+
}
80+
};
81+
82+
constexpr VkDescriptorBindingFlags descriptorFlags =
83+
VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT |
84+
VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT |
85+
VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT;
86+
87+
constexpr VkDescriptorBindingFlags descriptorFlagsArray[] { descriptorFlags, descriptorFlags };
88+
89+
VkDescriptorSetLayoutBindingFlagsCreateInfo descriptorIndexingInfo {
90+
.bindingCount = 2,
91+
.pBindingFlags = descriptorFlagsArray
92+
};
93+
94+
VkDescriptorSetLayoutCreateInfo descriptorLayoutInfo {
95+
.pNext = &descriptorIndexingInfo,
96+
.flags = VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT,
97+
.bindingCount = 2,
98+
.pBindings = imageBinds
99+
};
100+
101+
vkCreateDescriptorSetLayout( device, &descriptorLayoutInfo, nullptr, &descriptorSetLayout );
102+
103+
VkDescriptorSetAllocateInfo allocInfo {
104+
.descriptorPool = descriptorPool,
105+
.descriptorSetCount = 1,
106+
.pSetLayouts = &descriptorSetLayout
107+
};
108+
109+
vkAllocateDescriptorSets( device, &allocInfo, &descriptorSet );
110+
}
111+
112+
void FreeDescriptors() {
113+
vkResetDescriptorPool( device, descriptorPool, 0 );
114+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
===========================================================================
3+
4+
Daemon BSD Source Code
5+
Copyright (c) 2025 Daemon Developers
6+
All rights reserved.
7+
8+
This file is part of the Daemon BSD Source Code (Daemon Source Code).
9+
10+
Redistribution and use in source and binary forms, with or without
11+
modification, are permitted provided that the following conditions are met:
12+
* Redistributions of source code must retain the above copyright
13+
notice, this list of conditions and the following disclaimer.
14+
* Redistributions in binary form must reproduce the above copyright
15+
notice, this list of conditions and the following disclaimer in the
16+
documentation and/or other materials provided with the distribution.
17+
* Neither the name of the Daemon developers nor the
18+
names of its contributors may be used to endorse or promote products
19+
derived from this software without specific prior written permission.
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24+
DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY
25+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
32+
===========================================================================
33+
*/
34+
// DescriptorSet.h
35+
36+
#ifndef DESCRIPTOR_SET_H
37+
#define DESCRIPTOR_SET_H
38+
39+
#include "../Decls.h"
40+
41+
#include "../../Math/NumberTypes.h"
42+
43+
void AllocDescriptors( const uint32 imageCount, const uint32 storageImageCount );
44+
void FreeDescriptors();
45+
46+
#endif // DESCRIPTOR_SET_H

src/engine/renderer-vulkan/src.cmake

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,14 @@ set( utilsList
6767
${ENGINE_DIR}/renderer-vulkan/SrcDebug/Tag.h
6868
)
6969

70-
# Graphics core
70+
# Graphics Core
71+
set( graphicsCoreMemory
72+
${ENGINE_DIR}/renderer-vulkan/GraphicsCore/Memory/DescriptorSet.cpp
73+
${ENGINE_DIR}/renderer-vulkan/GraphicsCore/Memory/DescriptorSet.h
74+
)
75+
7176
set( graphicsCoreList
77+
${graphicsCoreMemory}
7278
${ENGINE_DIR}/renderer-vulkan/GraphicsCore/Decls.h
7379
${ENGINE_DIR}/renderer-vulkan/GraphicsCore/CapabilityPack.cpp
7480
${ENGINE_DIR}/renderer-vulkan/GraphicsCore/CapabilityPack.h

0 commit comments

Comments
 (0)