@@ -205,17 +205,29 @@ bool operator==(const SpecVarList& lhs, const SpecVarList& rhs) {
205205
206206PipelineLayout::PipelineLayout (
207207    VkDevice device,
208-     VkDescriptorSetLayout descriptor_layout)
208+     VkDescriptorSetLayout descriptor_layout,
209+     const  uint32_t  push_constants_size)
209210    : device_(device), handle_{VK_NULL_HANDLE} {
210-   //  TODO: Enable push constants
211+   VkPushConstantRange pc_range{
212+       VK_SHADER_STAGE_COMPUTE_BIT, //  stageFlags
213+       0u , //  offset
214+       push_constants_size, //  size
215+   };
216+   uint32_t  num_push_constants = 0u ;
217+   VkPushConstantRange* pc_ranges_ptr = nullptr ;
218+   if  (push_constants_size > 0u ) {
219+     num_push_constants = 1u ;
220+     pc_ranges_ptr = &pc_range;
221+   }
222+ 
211223  const  VkPipelineLayoutCreateInfo pipeline_layout_create_info{
212224      VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, //  sType
213225      nullptr , //  pNext
214226      0u , //  flags
215227      1u , //  setLayoutCount
216228      &descriptor_layout, //  pSetLayouts
217-       0u , //  pushConstantRangeCount
218-       nullptr , //  pPushConstantRanges
229+       num_push_constants , //  pushConstantRangeCount
230+       pc_ranges_ptr , //  pPushConstantRanges
219231  };
220232
221233  VK_CHECK (vkCreatePipelineLayout (
@@ -344,12 +356,19 @@ PipelineLayoutCache::~PipelineLayoutCache() {
344356}
345357
346358VkPipelineLayout PipelineLayoutCache::retrieve (
347-     const  PipelineLayoutCache::Key& key) {
359+     const  VkDescriptorSetLayout layout,
360+     const  uint32_t  push_constants_size) {
361+   PipelineLayoutCache::Key key{layout, push_constants_size};
348362  std::lock_guard<std::mutex> lock (cache_mutex_);
349363
350364  auto  it = cache_.find (key);
351365  if  (cache_.cend () == it) {
352-     it = cache_.insert ({key, PipelineLayoutCache::Value (device_, key)}).first ;
366+     it = cache_
367+              .insert (
368+                  {key,
369+                   PipelineLayoutCache::Value (
370+                       device_, layout, push_constants_size)})
371+              .first ;
353372  }
354373
355374  return  it->second .handle ();
0 commit comments