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+ }
0 commit comments