From 26916692835ee03a8600c5236b0b7de9cf1d55b6 Mon Sep 17 00:00:00 2001 From: vinsentli Date: Sat, 10 Jan 2026 10:21:01 +0800 Subject: [PATCH 1/2] igl | vulkan | Reuse the cached VkDescriptorSet to reduce vkAllocateDescriptorSets(). --- src/igl/vulkan/VulkanContext.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/igl/vulkan/VulkanContext.cpp b/src/igl/vulkan/VulkanContext.cpp index 07ddc9955f..31b345f815 100644 --- a/src/igl/vulkan/VulkanContext.cpp +++ b/src/igl/vulkan/VulkanContext.cpp @@ -249,7 +249,12 @@ class DescriptorPoolsArena final { if (!numRemainingDSetsInPool_) { switchToNewDescriptorPool(ic, nextSubmitHandle); } - VK_ASSERT(ivkAllocateDescriptorSet(&ctx_.vf_, device_, pool_, dsl_, &dset)); + if (isNewPool_) { + VK_ASSERT(ivkAllocateDescriptorSet(&ctx_.vf_, device_, pool_, dsl_, &dset)); + allocedDSet_.emplace_back(dset); + } else { + dset = allocedDSet_[dsetCursor_++]; + } numRemainingDSetsInPool_--; return dset; } @@ -260,7 +265,7 @@ class DescriptorPoolsArena final { numRemainingDSetsInPool_ = kNumDSetsPerPool; if (pool_ != VK_NULL_HANDLE) { - extinct_.push_back({pool_, nextSubmitHandle}); + extinct_.push_back({pool_, nextSubmitHandle, allocedDSet_}); } // first, let's try to reuse the oldest extinct pool (never reuse pools that are tagged with the // same SubmitHandle because they have not yet been submitted) @@ -268,8 +273,10 @@ class DescriptorPoolsArena final { const ExtinctDescriptorPool p = extinct_.front(); if (ic.isReady(p.handle)) { pool_ = p.pool; + allocedDSet_ = p.allocedDSet; + dsetCursor_ = 0; + isNewPool_ = false; extinct_.pop_front(); - VK_ASSERT(ctx_.vf_.vkResetDescriptorPool(device_, pool_, VkDescriptorPoolResetFlags{})); return; } } @@ -288,6 +295,9 @@ class DescriptorPoolsArena final { &pool_)); VK_ASSERT(ivkSetDebugObjectName( &ctx_.vf_, device_, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (uint64_t)pool_, dpDebugName_.c_str())); + allocedDSet_.clear(); + dsetCursor_ = 0; + isNewPool_ = true; } private: @@ -296,6 +306,9 @@ class DescriptorPoolsArena final { const VulkanContext& ctx_; VkDevice device_ = VK_NULL_HANDLE; VkDescriptorPool pool_ = VK_NULL_HANDLE; + uint32_t dsetCursor_ = 0; + std::vector allocedDSet_; + bool isNewPool_ = true; //is a new created pool or an old cached pool const uint32_t numTypes_ = 0; VkDescriptorType types_[2] = {VK_DESCRIPTOR_TYPE_MAX_ENUM, VK_DESCRIPTOR_TYPE_MAX_ENUM}; const uint32_t numDescriptorsPerDSet_ = 0; @@ -307,6 +320,7 @@ class DescriptorPoolsArena final { struct ExtinctDescriptorPool { VkDescriptorPool pool = VK_NULL_HANDLE; VulkanImmediateCommands::SubmitHandle handle = {}; + std::vector allocedDSet; }; std::deque extinct_; From 5bd8ab5c8280fd96a4a43a5c692df44db66cba24 Mon Sep 17 00:00:00 2001 From: vinsentli Date: Sat, 10 Jan 2026 21:55:16 +0800 Subject: [PATCH 2/2] code review --- src/igl/vulkan/VulkanContext.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/igl/vulkan/VulkanContext.cpp b/src/igl/vulkan/VulkanContext.cpp index 31b345f815..13e6873b3f 100644 --- a/src/igl/vulkan/VulkanContext.cpp +++ b/src/igl/vulkan/VulkanContext.cpp @@ -251,9 +251,9 @@ class DescriptorPoolsArena final { } if (isNewPool_) { VK_ASSERT(ivkAllocateDescriptorSet(&ctx_.vf_, device_, pool_, dsl_, &dset)); - allocedDSet_.emplace_back(dset); + allocatedDSet_.emplace_back(dset); } else { - dset = allocedDSet_[dsetCursor_++]; + dset = allocatedDSet_[dsetCursor_++]; } numRemainingDSetsInPool_--; return dset; @@ -265,7 +265,7 @@ class DescriptorPoolsArena final { numRemainingDSetsInPool_ = kNumDSetsPerPool; if (pool_ != VK_NULL_HANDLE) { - extinct_.push_back({pool_, nextSubmitHandle, allocedDSet_}); + extinct_.push_back({pool_, nextSubmitHandle, allocatedDSet_}); } // first, let's try to reuse the oldest extinct pool (never reuse pools that are tagged with the // same SubmitHandle because they have not yet been submitted) @@ -273,7 +273,7 @@ class DescriptorPoolsArena final { const ExtinctDescriptorPool p = extinct_.front(); if (ic.isReady(p.handle)) { pool_ = p.pool; - allocedDSet_ = p.allocedDSet; + allocatedDSet_ = p.allocatedDSet; dsetCursor_ = 0; isNewPool_ = false; extinct_.pop_front(); @@ -295,7 +295,7 @@ class DescriptorPoolsArena final { &pool_)); VK_ASSERT(ivkSetDebugObjectName( &ctx_.vf_, device_, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (uint64_t)pool_, dpDebugName_.c_str())); - allocedDSet_.clear(); + allocatedDSet_.clear(); dsetCursor_ = 0; isNewPool_ = true; } @@ -307,8 +307,8 @@ class DescriptorPoolsArena final { VkDevice device_ = VK_NULL_HANDLE; VkDescriptorPool pool_ = VK_NULL_HANDLE; uint32_t dsetCursor_ = 0; - std::vector allocedDSet_; - bool isNewPool_ = true; //is a new created pool or an old cached pool + std::vector allocatedDSet_; + bool isNewPool_ = true; // is a new created pool or an old cached pool const uint32_t numTypes_ = 0; VkDescriptorType types_[2] = {VK_DESCRIPTOR_TYPE_MAX_ENUM, VK_DESCRIPTOR_TYPE_MAX_ENUM}; const uint32_t numDescriptorsPerDSet_ = 0; @@ -320,7 +320,7 @@ class DescriptorPoolsArena final { struct ExtinctDescriptorPool { VkDescriptorPool pool = VK_NULL_HANDLE; VulkanImmediateCommands::SubmitHandle handle = {}; - std::vector allocedDSet; + std::vector allocatedDSet; }; std::deque extinct_;