Skip to content

Commit

Permalink
igl | vulkan | Use DescriptorPoolsArena for uniform buffers
Browse files Browse the repository at this point in the history
Summary: Use `DescriptorPoolsArena` to manage descriptor pools for uniform buffers.

Reviewed By: EricGriffith, mmaurer

Differential Revision: D49155101

fbshipit-source-id: 52065e757e7db933dd8c5346e128c99530441da2
  • Loading branch information
corporateshark authored and facebook-github-bot committed Sep 29, 2023
1 parent ae81cfe commit 4c06457
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 59 deletions.
67 changes: 12 additions & 55 deletions src/igl/vulkan/VulkanContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class DescriptorPoolsArena final {
extinct_.push_back({pool_, lastSubmitHandle_});
}
// first, let's try to reuse the oldest extinct pool
if (!extinct_.empty()) {
if (extinct_.size() > 1) {
const ExtinctDescriptorPool p = extinct_.front();
if (ic.isRecycled(p.handle_)) {
pool_ = p.pool_;
Expand Down Expand Up @@ -371,7 +371,6 @@ VulkanContext::~VulkanContext() {
}

dslCombinedImageSamplers_.reset(nullptr);
dslBuffersUniform_.reset(nullptr);
dslBindless_.reset(nullptr);

pipelineLayoutGraphics_.reset(nullptr);
Expand All @@ -387,7 +386,7 @@ VulkanContext::~VulkanContext() {
vf_.vkDestroyDescriptorPool(device, dpBindless_, nullptr);
}
vf_.vkDestroyDescriptorPool(device, dpCombinedImageSamplers_, nullptr);
vf_.vkDestroyDescriptorPool(device, dpBuffersUniform_, nullptr);
arenaBuffersUniform_ = nullptr;
arenaBuffersStorage_ = nullptr;
vf_.vkDestroyPipelineCache(device, pipelineCache_, nullptr);
}
Expand Down Expand Up @@ -821,55 +820,13 @@ igl::Result VulkanContext::initContext(const HWDeviceDesc& desc,
}
}

// create default descriptor set layout for uniform buffers
{
// NOTE: we really want these arrays to be uninitialized
// @lint-ignore CLANGTIDY
VkDescriptorSetLayoutBinding bindings[IGL_UNIFORM_BLOCKS_BINDING_MAX];
// @lint-ignore CLANGTIDY
VkDescriptorBindingFlags bindingFlags[IGL_UNIFORM_BLOCKS_BINDING_MAX];

for (uint32_t i = 0; i != IGL_UNIFORM_BLOCKS_BINDING_MAX; i++) {
bindings[i] = ivkGetDescriptorSetLayoutBinding(i, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1);
bindingFlags[i] = VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT;
}
dslBuffersUniform_ = std::make_unique<VulkanDescriptorSetLayout>(
vf_,
device,
VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT,
IGL_UNIFORM_BLOCKS_BINDING_MAX,
bindings,
bindingFlags,
"Descriptor Set Layout: VulkanContext::dslBuffersUniform_");
}

// create default descriptor pool for uniform buffers bindings
{
// TODO: make this more manageable (dynamic) once we migrate all apps to use descriptor sets
constexpr uint32_t kNumSets = 1024;

// @lint-ignore CLANGTIDY
VkDescriptorPoolSize poolSizes[IGL_UNIFORM_BLOCKS_BINDING_MAX];
for (uint32_t i = 0; i != IGL_UNIFORM_BLOCKS_BINDING_MAX; i++) {
poolSizes[i] = VkDescriptorPoolSize{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
kNumSets * IGL_UNIFORM_BLOCKS_BINDING_MAX};
}
VK_ASSERT_RETURN(ivkCreateDescriptorPool(&vf_,
device,
VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT,
kNumSets,
IGL_UNIFORM_BLOCKS_BINDING_MAX,
poolSizes,
&dpBuffersUniform_));
bufferUniformDSets_.dsets.resize(kNumSets);
for (size_t i = 0; i != kNumSets; i++) {
VK_ASSERT_RETURN(ivkAllocateDescriptorSet(&vf_,
device,
dpBuffersUniform_,
dslBuffersUniform_->getVkDescriptorSetLayout(),
&bufferUniformDSets_.dsets[i].ds));
}
}
// create descriptor set layout and descriptor pool for uniform buffers
arenaBuffersUniform_ = std::make_unique<DescriptorPoolsArena>(vf_,
*immediate_,
device,
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
IGL_UNIFORM_BLOCKS_BINDING_MAX,
"arenaBuffersUniform_");

// create descriptor set layout and descriptor pool for storage buffers
arenaBuffersStorage_ = std::make_unique<DescriptorPoolsArena>(vf_,
Expand Down Expand Up @@ -1012,7 +969,7 @@ void VulkanContext::updatePipelineLayouts() {
// @lint-ignore CLANGTIDY
const VkDescriptorSetLayout DSLs[] = {
dslCombinedImageSamplers_->getVkDescriptorSetLayout(),
dslBuffersUniform_->getVkDescriptorSetLayout(),
arenaBuffersUniform_->getVkDescriptorSetLayout(),
arenaBuffersStorage_->getVkDescriptorSetLayout(),
config_.enableDescriptorIndexing ? dslBindless_->getVkDescriptorSetLayout() : VK_NULL_HANDLE,
};
Expand Down Expand Up @@ -1551,7 +1508,7 @@ void VulkanContext::updateBindingsTextures(VkCommandBuffer cmdBuf,
void VulkanContext::updateBindingsUniformBuffers(VkCommandBuffer cmdBuf,
VkPipelineBindPoint bindPoint,
BindingsBuffers& data) const {
VkDescriptorSet dsetBufUniform = bufferUniformDSets_.acquireNext(*immediate_);
VkDescriptorSet dsetBufUniform = arenaBuffersUniform_->getNextDescriptorSet(*immediate_);

for (uint32_t i = 0; i != IGL_UNIFORM_BLOCKS_BINDING_MAX; i++) {
VkDescriptorBufferInfo& bi = data.buffers[i];
Expand Down Expand Up @@ -1627,7 +1584,7 @@ void VulkanContext::markSubmit(const VulkanImmediateCommands::SubmitHandle& hand
bindlessDSet_.handle = handle;
}
combinedImageSamplerDSets_.updateHandles(handle);
bufferUniformDSets_.updateHandles(handle);
arenaBuffersUniform_->markSubmit(handle);
arenaBuffersStorage_->markSubmit(handle);
}

Expand Down
6 changes: 2 additions & 4 deletions src/igl/vulkan/VulkanContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,11 @@ class VulkanContext final {
std::unique_ptr<igl::vulkan::VulkanStagingDevice> stagingDevice_;
// combined image sampler slots for the current drawcall
std::unique_ptr<igl::vulkan::VulkanDescriptorSetLayout> dslCombinedImageSamplers_;
// uniform buffer slots for the current drawcall
std::unique_ptr<igl::vulkan::VulkanDescriptorSetLayout> dslBuffersUniform_;
std::unique_ptr<igl::vulkan::DescriptorPoolsArena> arenaBuffersUniform_;
std::unique_ptr<igl::vulkan::DescriptorPoolsArena> arenaBuffersStorage_;

std::unique_ptr<igl::vulkan::VulkanDescriptorSetLayout> dslBindless_; // everything
VkDescriptorPool dpCombinedImageSamplers_ = VK_NULL_HANDLE;
VkDescriptorPool dpBuffersUniform_ = VK_NULL_HANDLE;
VkDescriptorPool dpBindless_ = VK_NULL_HANDLE;
struct DescriptorSet {
VkDescriptorSet ds = VK_NULL_HANDLE;
Expand Down Expand Up @@ -297,7 +296,6 @@ class VulkanContext final {
uint32_t currentMaxBindlessSamplers_ = 8;
mutable DescriptorSet bindlessDSet_;
mutable DescriptorSetArray combinedImageSamplerDSets_;
mutable DescriptorSetArray bufferUniformDSets_;
std::unique_ptr<igl::vulkan::VulkanPipelineLayout> pipelineLayoutGraphics_;
std::unique_ptr<igl::vulkan::VulkanPipelineLayout> pipelineLayoutCompute_;
std::shared_ptr<igl::vulkan::VulkanBuffer> dummyUniformBuffer_;
Expand Down

0 comments on commit 4c06457

Please sign in to comment.