-
Notifications
You must be signed in to change notification settings - Fork 204
igl | vulkan | Reuse the cached VkDescriptorSet to reduce vkAllocateDescriptorSets(). #336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
corporateshark
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please post your benchmarking results with and without this approach.
src/igl/vulkan/VulkanContext.cpp
Outdated
| VkDevice device_ = VK_NULL_HANDLE; | ||
| VkDescriptorPool pool_ = VK_NULL_HANDLE; | ||
| uint32_t dsetCursor_ = 0; | ||
| std::vector<VkDescriptorSet> allocedDSet_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about a hash table descriptor set content → VkDescriptorSet?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still thinking about it.
src/igl/vulkan/VulkanContext.cpp
Outdated
| VkDescriptorPool pool_ = VK_NULL_HANDLE; | ||
| uint32_t dsetCursor_ = 0; | ||
| std::vector<VkDescriptorSet> allocedDSet_; | ||
| bool isNewPool_ = true; //is a new created pool or an old cached pool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to cache descriptors from old pools?
Also, a space after // is missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I add a new filed allocatedDSet in ExtinctDescriptorPool to cache descriptors from old pools.
This looks very promising. Any numeric perf improvement values you've got? I'll test it on my side as well. |
|
@corporateshark has imported this pull request. If you are a Meta employee, you can view this in D90555194. |
| VK_ASSERT(ivkAllocateDescriptorSet(&ctx_.vf_, device_, pool_, dsl_, &dset)); | ||
| allocatedDSet_.emplace_back(dset); | ||
| } else { | ||
| dset = allocatedDSet_[dsetCursor_++]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential out-of-bounds access when reusing a descriptor pool. When a pool is reused (line 277), allocatedDSet_ is restored from the extinct pool, but numRemainingDSetsInPool_ is always reset to kNumDSetsPerPool (64) at line 266. If the pool was previously switched before all 64 descriptor sets were allocated, allocatedDSet_ will have fewer than 64 elements. Subsequent calls to getNextDescriptorSet() could then access allocatedDSet_[dsetCursor_++] at line 257 beyond the vector's bounds. Consider either: (1) setting numRemainingDSetsInPool_ based on the actual size of the restored allocatedDSet_ vector, or (2) ensuring that pools always have exactly kNumDSetsPerPool descriptor sets allocated before being marked as extinct.


No description provided.