Lugdunum  0.1.0
PipelineLayout.cpp
Go to the documentation of this file.
2 
3 #include <algorithm>
4 
6 
7 namespace lug {
8 namespace Graphics {
9 namespace Vulkan {
10 namespace API {
11 namespace Builder {
12 
13 PipelineLayout::PipelineLayout(const API::Device& device) : _device{device} {}
14 
15 bool PipelineLayout::build(API::PipelineLayout& pipelineLayout, VkResult* returnResult) {
16  // Build a vector of VkDescriptorSetLayout from the API::DescriptorSetLayout
17  std::vector<VkDescriptorSetLayout> vkDescriptorSetLayouts(_descriptorSetLayouts.size());
18  std::transform(
19  begin(_descriptorSetLayouts), end(_descriptorSetLayouts), begin(vkDescriptorSetLayouts),
20  [](API::DescriptorSetLayout& descriptorSetLayout){ return static_cast<VkDescriptorSetLayout>(descriptorSetLayout); }
21  );
22 
23  // Create the pipelineLayout creation information for vkCreatePipelineLayout
24  const VkPipelineLayoutCreateInfo createInfo{
25  /* createInfo.sType */ VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
26  /* createInfo.pNext */ nullptr,
27  /* createInfo.flags */ 0,
28  /* createInfo.setLayoutCount */ static_cast<uint32_t>(vkDescriptorSetLayouts.size()),
29  /* createInfo.pSetLayouts */ vkDescriptorSetLayouts.data(),
30  /* createInfo.pushConstantRangeCount */ static_cast<uint32_t>(_pushConstants.size()),
31  /* createInfo.pPushConstantRanges */ _pushConstants.data(),
32  };
33 
34  // Create the pipelineLayout
35  VkPipelineLayout vkPipelineLayout{VK_NULL_HANDLE};
36  VkResult result = vkCreatePipelineLayout(static_cast<VkDevice>(_device), &createInfo, nullptr, &vkPipelineLayout);
37 
38  if (returnResult) {
39  *returnResult = result;
40  }
41 
42  if (result != VK_SUCCESS) {
43  return false;
44  }
45 
46  pipelineLayout = API::PipelineLayout(vkPipelineLayout, &_device, std::move(_descriptorSetLayouts));
47 
48  return true;
49 }
50 
51 std::unique_ptr<API::PipelineLayout> PipelineLayout::build(VkResult* returnResult) {
52  std::unique_ptr<API::PipelineLayout> pipelineLayout = std::make_unique<API::PipelineLayout>();
53  return build(*pipelineLayout, returnResult) ? std::move(pipelineLayout) : nullptr;
54 }
55 
56 } // Builder
57 } // API
58 } // Vulkan
59 } // Graphics
60 } // lug
std::vector< API::DescriptorSetLayout > _descriptorSetLayouts
std::vector< VkPushConstantRange > _pushConstants
bool build(API::PipelineLayout &instance, VkResult *returnResult=nullptr)