vengine  0.0.1
3D graphics engine
Loading...
Searching...
No Matches
writer.cpp
Go to the documentation of this file.
1#include <cassert>
2
4
5ven::DescriptorWriter &ven::DescriptorWriter::writeBuffer(const uint32_t binding, const VkDescriptorBufferInfo *bufferInfo)
6{
7 assert(m_setLayout.m_bindings.count(binding) == 1 && "Layout does not contain specified binding");
8
9 const auto &bindingDescription = m_setLayout.m_bindings.at(binding);
10
11 assert(bindingDescription.descriptorCount == 1 && "Binding single descriptor info, but binding expects multiple");
12
13 VkWriteDescriptorSet write{};
14 write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
15 write.descriptorType = bindingDescription.descriptorType;
16 write.dstBinding = binding;
17 write.pBufferInfo = bufferInfo;
18 write.descriptorCount = 1;
19
20 m_writes.push_back(write);
21 return *this;
22}
23
24ven::DescriptorWriter &ven::DescriptorWriter::writeImage(const uint32_t binding, const VkDescriptorImageInfo *imageInfo)
25{
26 assert(m_setLayout.m_bindings.count(binding) == 1 && "Layout does not contain specified binding");
27
28 const VkDescriptorSetLayoutBinding &bindingDescription = m_setLayout.m_bindings.at(binding);
29
30 assert(bindingDescription.descriptorCount == 1 && "Binding single descriptor info, but binding expects multiple");
31
32 VkWriteDescriptorSet write{};
33 write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
34 write.descriptorType = bindingDescription.descriptorType;
35 write.dstBinding = binding;
36 write.pImageInfo = imageInfo;
37 write.descriptorCount = 1;
38
39 m_writes.push_back(write);
40 return *this;
41}
42
43bool ven::DescriptorWriter::build(VkDescriptorSet &set)
44{
45 if (!m_pool.allocateDescriptor(m_setLayout.getDescriptorSetLayout(), set)) {
46 return false;
47 }
48 overwrite(set);
49 return true;
50}
51
52void ven::DescriptorWriter::overwrite(const VkDescriptorSet &set) {
53 for (auto &[sType, pNext, dstSet, dstBinding, dstArrayElement, descriptorCount, descriptorType, pImageInfo, pBufferInfo, pTexelBufferView] : m_writes) {
54 dstSet = set;
55 }
56 vkUpdateDescriptorSets(m_pool.m_device.device(), static_cast<unsigned int>(m_writes.size()), m_writes.data(), 0, nullptr);
57}
This file contains the DescriptorsWriter class.
std::unordered_map< uint32_t, VkDescriptorSetLayoutBinding > m_bindings
Definition SetLayout.hpp:55
Class for descriptor writer.
Definition Writer.hpp:19
DescriptorWriter & writeImage(uint32_t binding, const VkDescriptorImageInfo *imageInfo)
Definition writer.cpp:24
std::vector< VkWriteDescriptorSet > m_writes
Definition Writer.hpp:41
DescriptorWriter & writeBuffer(uint32_t binding, const VkDescriptorBufferInfo *bufferInfo)
Definition writer.cpp:5
DescriptorSetLayout & m_setLayout
Definition Writer.hpp:39
void overwrite(const VkDescriptorSet &set)
Definition writer.cpp:52
bool build(VkDescriptorSet &set)
Definition writer.cpp:43