title: Vulkan: How to add descriptors for a Dynamic Uniform Buffer
body: <p>I have been following a tutorial for Vulkan and am trying to implement a dynamic uniform buffer.</p>
  <p>I currently have descriptors for a uniform buffer and a combined image sampler but i am not sure how to add another descriptor for a dynamic uniform buffer.</p>
  <p>I have made some attempts but i get a lot of errors so I'm probably doing something wrong</p>
  <p>Code (for the descriptors that are working correctly):</p>
  <pre><code>void createDescriptorSetLayout() {
  
          VkDescriptorSetLayoutBinding uboLayoutBinding{};
          uboLayoutBinding.binding = 0;
          uboLayoutBinding.descriptorCount = 1;
          uboLayoutBinding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
          uboLayoutBinding.pImmutableSamplers = nullptr;
          uboLayoutBinding.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
  
          VkDescriptorSetLayoutBinding samplerLayoutBinding{};
          samplerLayoutBinding.binding = 1;
          samplerLayoutBinding.descriptorCount = 1;
          samplerLayoutBinding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
          samplerLayoutBinding.pImmutableSamplers = nullptr;
          samplerLayoutBinding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
  
          std::array&lt;VkDescriptorSetLayoutBinding, 2&gt; bindings = {uboLayoutBinding, samplerLayoutBinding};
          VkDescriptorSetLayoutCreateInfo layoutInfo{};
          layoutInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
          layoutInfo.bindingCount = static_cast&lt;uint32_t&gt;(bindings.size());
          layoutInfo.pBindings = bindings.data();
  
  
  
          if (vkCreateDescriptorSetLayout(device, &amp;layoutInfo, nullptr, &amp;descriptorSetLayout) != VK_SUCCESS) {
              throw std::runtime_error(&quot;failed to create descriptor set layout!&quot;);
          }
      }
  </code></pre>
  <pre><code>void createDescriptorPool() {
  
          std::array&lt;VkDescriptorPoolSize, 2&gt; poolSizes{};
          poolSizes[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
          poolSizes[0].descriptorCount = static_cast&lt;uint32_t&gt;(MAX_FRAMES_IN_FLIGHT);
          poolSizes[1].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
          poolSizes[1].descriptorCount = static_cast&lt;uint32_t&gt;(MAX_FRAMES_IN_FLIGHT);
  
          VkDescriptorPoolCreateInfo poolInfo{};
          poolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
          poolInfo.poolSizeCount = static_cast&lt;uint32_t&gt;(poolSizes.size());
          poolInfo.pPoolSizes = poolSizes.data();
          poolInfo.maxSets = static_cast&lt;uint32_t&gt;(MAX_FRAMES_IN_FLIGHT);
  
          if (vkCreateDescriptorPool(device, &amp;poolInfo, nullptr, &amp;descriptorPool) != VK_SUCCESS) {
              throw std::runtime_error(&quot;failed to create descriptor pool!&quot;);
          }
      }
  </code></pre>
  <pre><code>void createDescriptorSets() {
  
          std::vector&lt;VkDescriptorSetLayout&gt; layouts(MAX_FRAMES_IN_FLIGHT, descriptorSetLayout);
          VkDescriptorSetAllocateInfo allocInfo{};
          allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
          allocInfo.descriptorPool = descriptorPool;
          allocInfo.descriptorSetCount = static_cast&lt;uint32_t&gt;(MAX_FRAMES_IN_FLIGHT);
          allocInfo.pSetLayouts = layouts.data();
  
          descriptorSets.resize(MAX_FRAMES_IN_FLIGHT);
          if (vkAllocateDescriptorSets(device, &amp;allocInfo, descriptorSets.data()) != VK_SUCCESS) {
  
              throw std::runtime_error(&quot;failed to allocate descriptor sets!&quot;);
  
          }
  
          for (size_t i = 0; i &lt; MAX_FRAMES_IN_FLIGHT; i++) {
  
              VkDescriptorBufferInfo bufferInfo{};
              bufferInfo.buffer = uniformBuffers[i];
              bufferInfo.offset = 0;
              bufferInfo.range = sizeof(UniformBufferObject);
  
              VkDescriptorImageInfo imageInfo{};
              imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
              imageInfo.imageView = textureImageView;
              imageInfo.sampler = textureSampler;
  
              std::array&lt;VkWriteDescriptorSet, 2&gt; descriptorWrites{};
  
              descriptorWrites[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
              descriptorWrites[0].dstSet = descriptorSets[i];
              descriptorWrites[0].dstBinding = 0;
              descriptorWrites[0].dstArrayElement = 0;
              descriptorWrites[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
              descriptorWrites[0].descriptorCount = 1;
              descriptorWrites[0].pBufferInfo = &amp;bufferInfo;
  
              descriptorWrites[1].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
              descriptorWrites[1].dstSet = descriptorSets[i];
              descriptorWrites[1].dstBinding = 1;
              descriptorWrites[1].dstArrayElement = 0;
              descriptorWrites[1].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
              descriptorWrites[1].descriptorCount = 1;
              descriptorWrites[1].pImageInfo = &amp;imageInfo;
  
              vkUpdateDescriptorSets(device, static_cast&lt;uint32_t&gt;(descriptorWrites.size()), descriptorWrites.data(), 0, nullptr);
          }
      }
  </code></pre>
  <p>(MAX_FRAMES_IN_FLIGHT = 2)</p>