7 #include <ThirdParty/EASTL-master/include/EASTL/string.h> 11 VulkanDescriptorPool::VulkanDescriptorPool(VulkanLogicalDevice* device)
13 this->device = device;
16 VulkanDescriptorPool::~VulkanDescriptorPool()
19 vkDestroyDescriptorPool(device->GetDevice(), pool,
nullptr);
22 void VulkanDescriptorPool::AddPoolSize(VkDescriptorType type, uint32_t count)
24 VkDescriptorPoolSize size = {};
26 size.descriptorCount = count;
28 poolSizes.push_back(size);
31 void VulkanDescriptorPool::Compile(uint32_t maxSets)
33 VkDescriptorPoolCreateInfo createInfo = {};
34 createInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
35 createInfo.poolSizeCount =
static_cast<uint32_t
>(poolSizes.size());
36 createInfo.pPoolSizes = poolSizes.data();
37 createInfo.maxSets = maxSets;
38 createInfo.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
40 VkResult res = vkCreateDescriptorPool(device->GetDevice(), &createInfo,
nullptr, &pool);
41 if (res != VK_SUCCESS) {
42 eastl::string s = eastl::string(
"[ERROR] [CODE:") + std::to_string(res).c_str() +
"] Failed to create descriptor pool";
43 std::cout << s.c_str() << std::endl;
47 VkDescriptorPool VulkanDescriptorPool::GetPool()
const 52 void VulkanDescriptorPool::AllocateDescriptorSet(uint32_t descriptorSetCount, VkDescriptorSetLayout * layouts, VkDescriptorSet * sets)
const 54 VkDescriptorSetAllocateInfo allocInfo = {};
55 allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
56 allocInfo.descriptorPool = pool;
57 allocInfo.descriptorSetCount = descriptorSetCount;
58 allocInfo.pSetLayouts = layouts;
60 VkResult res = vkAllocateDescriptorSets(device->GetDevice(), &allocInfo, sets);
61 if (res != VK_SUCCESS) {
62 eastl::string s = eastl::string(
"[ERROR] [CODE:") + std::to_string(res).c_str() +
"] Failed to allocate descriptor sets";
63 std::cout << s.c_str() << std::endl;
67 void VulkanDescriptorPool::DescriptorSetBindToBuffer(VkDescriptorSet
set, VkBuffer buffer, VkDeviceSize offset,
68 VkDeviceSize range, uint32_t binding, uint32_t arrayElement,
69 VkDescriptorType type, uint32_t descriptorCount)
const 71 VkDescriptorBufferInfo bufferInfo = {};
72 bufferInfo.buffer = buffer;
73 bufferInfo.offset = offset;
74 bufferInfo.range = range;
75 VkWriteDescriptorSet descriptorWrite = {};
76 descriptorWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
77 descriptorWrite.dstSet =
set;
78 descriptorWrite.dstBinding = binding;
79 descriptorWrite.dstArrayElement = arrayElement;
80 descriptorWrite.descriptorType = type;
81 descriptorWrite.descriptorCount = descriptorCount;
82 descriptorWrite.pBufferInfo = &bufferInfo;
84 vkUpdateDescriptorSets(device->GetDevice(), 1, &descriptorWrite, 0,
nullptr);
87 void VulkanDescriptorPool::DescriptorSetBindToImage(VkDescriptorSet
set, VkImageLayout layout, VkImageView imageView, VkSampler sampler, uint32_t binding, uint32_t arrayElement, VkDescriptorType type, uint32_t descriptorCount)
const 89 VkDescriptorImageInfo imageInfo = {};
90 imageInfo.imageLayout = layout;
91 imageInfo.imageView = imageView;
92 imageInfo.sampler = sampler;
94 VkWriteDescriptorSet writeInfo = {};
95 writeInfo.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
96 writeInfo.dstSet =
set;
97 writeInfo.dstBinding = binding;
98 writeInfo.dstArrayElement = arrayElement;
99 writeInfo.descriptorType = type;
100 writeInfo.descriptorCount = descriptorCount;
101 writeInfo.pImageInfo = &imageInfo;
103 vkUpdateDescriptorSets(device->GetDevice(), 1, &writeInfo, 0,
nullptr);
108 #endif // USING_VULKAN