Commit e4a6d7a3 by Jamie Madill Committed by Commit Bot

Vulkan: Make DynamicDescriptorPool single pool.

This completes a prior refactor. DynamicDescriptorPool couldn't robustly handle multiple pools so only accept one as a parameter. We were already only using one at a time in practice. This removes the need to look up the pool index from the descriptor type which became problematic later on. Bug: angleproject:2717 Change-Id: I7fb92d5ab55bbe1f35b6b9cfcd8981cc1ca358f1 Reviewed-on: https://chromium-review.googlesource.com/1127157 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarLuc Ferron <lucferron@chromium.org>
parent caa55cd7
......@@ -86,18 +86,15 @@ gl::Error ContextVk::getIncompleteTexture(const gl::Context *context,
gl::Error ContextVk::initialize()
{
// Note that this may reserve more sets than strictly necessary for a particular layout.
vk::DescriptorPoolSizes uniformPoolSize;
uniformPoolSize.push_back(
{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC,
GetUniformBufferDescriptorCount() * vk::kDefaultDescriptorPoolMaxSets});
vk::DescriptorPoolSizes imageSamplerPoolSize;
imageSamplerPoolSize.push_back(
{VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
mRenderer->getMaxActiveTextures() * vk::kDefaultDescriptorPoolMaxSets});
VkDescriptorPoolSize uniformPoolSize = {
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC,
GetUniformBufferDescriptorCount() * vk::kDefaultDescriptorPoolMaxSets};
ANGLE_TRY(
mDynamicDescriptorPools[kUniformsDescriptorSetIndex].init(getDevice(), uniformPoolSize));
VkDescriptorPoolSize imageSamplerPoolSize = {
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
mRenderer->getMaxActiveTextures() * vk::kDefaultDescriptorPoolMaxSets};
ANGLE_TRY(mDynamicDescriptorPools[kTextureDescriptorSetIndex].init(getDevice(),
imageSamplerPoolSize));
......
......@@ -748,7 +748,6 @@ vk::Error ProgramVk::allocateDescriptorSet(ContextVk *contextVk, uint32_t descri
const vk::DescriptorSetLayout &descriptorSetLayout =
mDescriptorSetLayouts[descriptorSetIndex].get();
ANGLE_TRY(dynamicDescriptorPool->allocateSets(contextVk, descriptorSetLayout.ptr(), 1,
descriptorSetIndex,
&mDescriptorSets[descriptorSetIndex]));
return vk::NoError();
}
......
......@@ -76,20 +76,6 @@ VkImageCreateFlags GetImageCreateFlags(gl::TextureType textureType)
return 0;
}
}
size_t GetDescriptorSetIndexfromType(VkDescriptorType descriptorType)
{
switch (descriptorType)
{
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
return kUniformsDescriptorSetIndex;
case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
return kTextureDescriptorSetIndex;
default:
UNREACHABLE();
return 0;
}
}
} // anonymous namespace
// DynamicBuffer implementation.
......@@ -280,17 +266,20 @@ void DynamicBuffer::setMinimumSizeForTesting(size_t minSize)
// DynamicDescriptorPool implementation.
DynamicDescriptorPool::DynamicDescriptorPool()
: mMaxSetsPerPool(kDefaultDescriptorPoolMaxSets), mCurrentSetsCount(0), mFreeDescriptorSets({})
: mMaxSetsPerPool(kDefaultDescriptorPoolMaxSets),
mCurrentSetsCount(0),
mPoolSize{},
mFreeDescriptorSets(0)
{
}
DynamicDescriptorPool::~DynamicDescriptorPool() = default;
Error DynamicDescriptorPool::init(VkDevice device, const DescriptorPoolSizes &poolSizes)
Error DynamicDescriptorPool::init(VkDevice device, const VkDescriptorPoolSize &poolSize)
{
ASSERT(!mCurrentDescriptorPool.valid());
mPoolSizes = poolSizes;
mPoolSize = poolSize;
ANGLE_TRY(allocateNewPool(device));
return NoError();
}
......@@ -303,11 +292,9 @@ void DynamicDescriptorPool::destroy(VkDevice device)
Error DynamicDescriptorPool::allocateSets(ContextVk *contextVk,
const VkDescriptorSetLayout *descriptorSetLayout,
uint32_t descriptorSetCount,
uint32_t descriptorSetIndex,
VkDescriptorSet *descriptorSetsOut)
{
if (mFreeDescriptorSets[descriptorSetIndex] < descriptorSetCount ||
mCurrentSetsCount >= mMaxSetsPerPool)
if (mFreeDescriptorSets < descriptorSetCount || mCurrentSetsCount >= mMaxSetsPerPool)
{
RendererVk *renderer = contextVk->getRenderer();
Serial currentSerial = renderer->getCurrentQueueSerial();
......@@ -328,8 +315,8 @@ Error DynamicDescriptorPool::allocateSets(ContextVk *contextVk,
ANGLE_TRY(mCurrentDescriptorPool.allocateDescriptorSets(contextVk->getDevice(), allocInfo,
descriptorSetsOut));
ASSERT(mFreeDescriptorSets[descriptorSetIndex] >= descriptorSetCount);
mFreeDescriptorSets[descriptorSetIndex] -= descriptorSetCount;
ASSERT(mFreeDescriptorSets >= descriptorSetCount);
mFreeDescriptorSets -= descriptorSetCount;
mCurrentSetsCount++;
return NoError();
}
......@@ -343,18 +330,12 @@ Error DynamicDescriptorPool::allocateNewPool(VkDevice device)
descriptorPoolInfo.maxSets = mMaxSetsPerPool;
// Reserve pools for uniform blocks and textures.
descriptorPoolInfo.poolSizeCount = static_cast<uint32_t>(mPoolSizes.size());
descriptorPoolInfo.pPoolSizes = mPoolSizes.data();
descriptorPoolInfo.poolSizeCount = 1u;
descriptorPoolInfo.pPoolSizes = &mPoolSize;
mFreeDescriptorSets.fill(0);
mFreeDescriptorSets = mPoolSize.descriptorCount;
mCurrentSetsCount = 0;
for (const VkDescriptorPoolSize &poolSize : mPoolSizes)
{
size_t setIndex = GetDescriptorSetIndexfromType(poolSize.type);
mFreeDescriptorSets[setIndex] += poolSize.descriptorCount;
}
ANGLE_TRY(mCurrentDescriptorPool.init(device, descriptorPoolInfo));
return NoError();
}
......
......@@ -90,8 +90,6 @@ class DynamicBuffer : angle::NonCopyable
// using the maximum number of descriptor sets and buffers with each allocation. Currently: 2
// (Vertex/Fragment) uniform buffers and 64 (MAX_ACTIVE_TEXTURES) image/samplers.
using DescriptorPoolSizes = angle::FixedVector<VkDescriptorPoolSize, kMaxDescriptorSetLayouts>;
// This is an arbitrary max. We can change this later if necessary.
constexpr uint32_t kDefaultDescriptorPoolMaxSets = 2048;
......@@ -101,7 +99,8 @@ class DynamicDescriptorPool final : angle::NonCopyable
DynamicDescriptorPool();
~DynamicDescriptorPool();
Error init(VkDevice device, const DescriptorPoolSizes &poolSizes);
// The DynamicDescriptorPool only handles one pool size at at time.
Error init(VkDevice device, const VkDescriptorPoolSize &poolSize);
void destroy(VkDevice device);
// We use the descriptor type to help count the number of free sets.
......@@ -109,7 +108,6 @@ class DynamicDescriptorPool final : angle::NonCopyable
Error allocateSets(ContextVk *contextVk,
const VkDescriptorSetLayout *descriptorSetLayout,
uint32_t descriptorSetCount,
uint32_t descriptorSetIndex,
VkDescriptorSet *descriptorSetsOut);
// For testing only!
......@@ -121,8 +119,8 @@ class DynamicDescriptorPool final : angle::NonCopyable
uint32_t mMaxSetsPerPool;
uint32_t mCurrentSetsCount;
DescriptorPool mCurrentDescriptorPool;
DescriptorPoolSizes mPoolSizes;
DescriptorSetLayoutArray<uint32_t> mFreeDescriptorSets;
VkDescriptorPoolSize mPoolSize;
uint32_t mFreeDescriptorSets;
};
// This class' responsibility is to create index buffers needed to support line loops in Vulkan.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment