Skip to content

Commit

Permalink
igl | vulkan | Deferred deletion of VkPipelineLayout
Browse files Browse the repository at this point in the history
Summary: Deferred deletion of `VkPipelineLayout`.

Reviewed By: mmaurer

Differential Revision: D52185644

fbshipit-source-id: 42741dafa68b56cb3c86d0a003936ed5faff2f3e
  • Loading branch information
corporateshark authored and facebook-github-bot committed Dec 15, 2023
1 parent f26c8bc commit d208a19
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/igl/vulkan/VulkanContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ void VulkanContext::updatePipelineLayouts() {

// create pipeline layout
pipelineLayoutGraphics_ = std::make_unique<VulkanPipelineLayout>(
vf_,
*this,
device,
DSLs,
static_cast<uint32_t>(config_.enableDescriptorIndexing ? IGL_ARRAY_NUM_ELEMENTS(DSLs)
Expand All @@ -1020,7 +1020,7 @@ void VulkanContext::updatePipelineLayouts() {
"Pipeline Layout: VulkanContext::pipelineLayoutGraphics_");

pipelineLayoutCompute_ = std::make_unique<VulkanPipelineLayout>(
vf_,
*this,
device,
DSLs,
static_cast<uint32_t>(config_.enableDescriptorIndexing ? IGL_ARRAY_NUM_ELEMENTS(DSLs)
Expand Down
23 changes: 12 additions & 11 deletions src/igl/vulkan/VulkanPipelineLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,34 @@
#include "VulkanPipelineLayout.h"

#include <igl/vulkan/Common.h>
#include <igl/vulkan/VulkanContext.h>
#include <igl/vulkan/VulkanFunctionTable.h>

namespace igl {
namespace igl::vulkan {

namespace vulkan {

VulkanPipelineLayout::VulkanPipelineLayout(const VulkanFunctionTable& vf,
VulkanPipelineLayout::VulkanPipelineLayout(const VulkanContext& ctx,
VkDevice device,
const VkDescriptorSetLayout* layouts,
uint32_t numLayouts,
const VkPushConstantRange& range,
const char* debugName) :
vf_(vf), device_(device) {
ctx_(ctx), device_(device) {
IGL_PROFILER_FUNCTION_COLOR(IGL_PROFILER_COLOR_CREATE);

const VkPipelineLayoutCreateInfo ci = ivkGetPipelineLayoutCreateInfo(numLayouts, layouts, &range);

VK_ASSERT(vf_.vkCreatePipelineLayout(device, &ci, nullptr, &vkPipelineLayout_));
VK_ASSERT(ctx.vf_.vkCreatePipelineLayout(device, &ci, nullptr, &vkPipelineLayout_));
VK_ASSERT(ivkSetDebugObjectName(
&vf_, device_, VK_OBJECT_TYPE_PIPELINE_LAYOUT, (uint64_t)vkPipelineLayout_, debugName));
&ctx.vf_, device_, VK_OBJECT_TYPE_PIPELINE_LAYOUT, (uint64_t)vkPipelineLayout_, debugName));
}

VulkanPipelineLayout::~VulkanPipelineLayout() {
IGL_PROFILER_FUNCTION_COLOR(IGL_PROFILER_COLOR_DESTROY);

vf_.vkDestroyPipelineLayout(device_, vkPipelineLayout_, nullptr);
ctx_.deferredTask(std::packaged_task<void()>(
[vf = &ctx_.vf_, device = ctx_.getVkDevice(), layout = vkPipelineLayout_]() {
vf->vkDestroyPipelineLayout(device, layout, nullptr);
}));
}

} // namespace vulkan

} // namespace igl
} // namespace igl::vulkan
13 changes: 6 additions & 7 deletions src/igl/vulkan/VulkanPipelineLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

#pragma once

#include <igl/vulkan/VulkanFunctions.h>
#include <igl/vulkan/VulkanHelpers.h>

namespace igl {
namespace vulkan {
namespace igl::vulkan {

class VulkanContext;

class VulkanPipelineLayout final {
public:
explicit VulkanPipelineLayout(const VulkanFunctionTable& vf,
explicit VulkanPipelineLayout(const VulkanContext& ctx,
VkDevice device,
const VkDescriptorSetLayout* layouts,
uint32_t numLayouts,
Expand All @@ -31,10 +31,9 @@ class VulkanPipelineLayout final {
}

public:
const VulkanFunctionTable& vf_;
const VulkanContext& ctx_;
VkDevice device_ = VK_NULL_HANDLE;
VkPipelineLayout vkPipelineLayout_ = VK_NULL_HANDLE;
};

} // namespace vulkan
} // namespace igl
} // namespace igl::vulkan

0 comments on commit d208a19

Please sign in to comment.