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, ...@@ -86,18 +86,15 @@ gl::Error ContextVk::getIncompleteTexture(const gl::Context *context,
gl::Error ContextVk::initialize() gl::Error ContextVk::initialize()
{ {
// Note that this may reserve more sets than strictly necessary for a particular layout. // Note that this may reserve more sets than strictly necessary for a particular layout.
vk::DescriptorPoolSizes uniformPoolSize; VkDescriptorPoolSize uniformPoolSize = {
uniformPoolSize.push_back( VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC,
{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, GetUniformBufferDescriptorCount() * vk::kDefaultDescriptorPoolMaxSets};
GetUniformBufferDescriptorCount() * vk::kDefaultDescriptorPoolMaxSets});
vk::DescriptorPoolSizes imageSamplerPoolSize;
imageSamplerPoolSize.push_back(
{VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
mRenderer->getMaxActiveTextures() * vk::kDefaultDescriptorPoolMaxSets});
ANGLE_TRY( ANGLE_TRY(
mDynamicDescriptorPools[kUniformsDescriptorSetIndex].init(getDevice(), uniformPoolSize)); mDynamicDescriptorPools[kUniformsDescriptorSetIndex].init(getDevice(), uniformPoolSize));
VkDescriptorPoolSize imageSamplerPoolSize = {
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
mRenderer->getMaxActiveTextures() * vk::kDefaultDescriptorPoolMaxSets};
ANGLE_TRY(mDynamicDescriptorPools[kTextureDescriptorSetIndex].init(getDevice(), ANGLE_TRY(mDynamicDescriptorPools[kTextureDescriptorSetIndex].init(getDevice(),
imageSamplerPoolSize)); imageSamplerPoolSize));
......
...@@ -748,7 +748,6 @@ vk::Error ProgramVk::allocateDescriptorSet(ContextVk *contextVk, uint32_t descri ...@@ -748,7 +748,6 @@ vk::Error ProgramVk::allocateDescriptorSet(ContextVk *contextVk, uint32_t descri
const vk::DescriptorSetLayout &descriptorSetLayout = const vk::DescriptorSetLayout &descriptorSetLayout =
mDescriptorSetLayouts[descriptorSetIndex].get(); mDescriptorSetLayouts[descriptorSetIndex].get();
ANGLE_TRY(dynamicDescriptorPool->allocateSets(contextVk, descriptorSetLayout.ptr(), 1, ANGLE_TRY(dynamicDescriptorPool->allocateSets(contextVk, descriptorSetLayout.ptr(), 1,
descriptorSetIndex,
&mDescriptorSets[descriptorSetIndex])); &mDescriptorSets[descriptorSetIndex]));
return vk::NoError(); return vk::NoError();
} }
......
...@@ -76,20 +76,6 @@ VkImageCreateFlags GetImageCreateFlags(gl::TextureType textureType) ...@@ -76,20 +76,6 @@ VkImageCreateFlags GetImageCreateFlags(gl::TextureType textureType)
return 0; 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 } // anonymous namespace
// DynamicBuffer implementation. // DynamicBuffer implementation.
...@@ -280,17 +266,20 @@ void DynamicBuffer::setMinimumSizeForTesting(size_t minSize) ...@@ -280,17 +266,20 @@ void DynamicBuffer::setMinimumSizeForTesting(size_t minSize)
// DynamicDescriptorPool implementation. // DynamicDescriptorPool implementation.
DynamicDescriptorPool::DynamicDescriptorPool() DynamicDescriptorPool::DynamicDescriptorPool()
: mMaxSetsPerPool(kDefaultDescriptorPoolMaxSets), mCurrentSetsCount(0), mFreeDescriptorSets({}) : mMaxSetsPerPool(kDefaultDescriptorPoolMaxSets),
mCurrentSetsCount(0),
mPoolSize{},
mFreeDescriptorSets(0)
{ {
} }
DynamicDescriptorPool::~DynamicDescriptorPool() = default; DynamicDescriptorPool::~DynamicDescriptorPool() = default;
Error DynamicDescriptorPool::init(VkDevice device, const DescriptorPoolSizes &poolSizes) Error DynamicDescriptorPool::init(VkDevice device, const VkDescriptorPoolSize &poolSize)
{ {
ASSERT(!mCurrentDescriptorPool.valid()); ASSERT(!mCurrentDescriptorPool.valid());
mPoolSizes = poolSizes; mPoolSize = poolSize;
ANGLE_TRY(allocateNewPool(device)); ANGLE_TRY(allocateNewPool(device));
return NoError(); return NoError();
} }
...@@ -303,11 +292,9 @@ void DynamicDescriptorPool::destroy(VkDevice device) ...@@ -303,11 +292,9 @@ void DynamicDescriptorPool::destroy(VkDevice device)
Error DynamicDescriptorPool::allocateSets(ContextVk *contextVk, Error DynamicDescriptorPool::allocateSets(ContextVk *contextVk,
const VkDescriptorSetLayout *descriptorSetLayout, const VkDescriptorSetLayout *descriptorSetLayout,
uint32_t descriptorSetCount, uint32_t descriptorSetCount,
uint32_t descriptorSetIndex,
VkDescriptorSet *descriptorSetsOut) VkDescriptorSet *descriptorSetsOut)
{ {
if (mFreeDescriptorSets[descriptorSetIndex] < descriptorSetCount || if (mFreeDescriptorSets < descriptorSetCount || mCurrentSetsCount >= mMaxSetsPerPool)
mCurrentSetsCount >= mMaxSetsPerPool)
{ {
RendererVk *renderer = contextVk->getRenderer(); RendererVk *renderer = contextVk->getRenderer();
Serial currentSerial = renderer->getCurrentQueueSerial(); Serial currentSerial = renderer->getCurrentQueueSerial();
...@@ -328,8 +315,8 @@ Error DynamicDescriptorPool::allocateSets(ContextVk *contextVk, ...@@ -328,8 +315,8 @@ Error DynamicDescriptorPool::allocateSets(ContextVk *contextVk,
ANGLE_TRY(mCurrentDescriptorPool.allocateDescriptorSets(contextVk->getDevice(), allocInfo, ANGLE_TRY(mCurrentDescriptorPool.allocateDescriptorSets(contextVk->getDevice(), allocInfo,
descriptorSetsOut)); descriptorSetsOut));
ASSERT(mFreeDescriptorSets[descriptorSetIndex] >= descriptorSetCount); ASSERT(mFreeDescriptorSets >= descriptorSetCount);
mFreeDescriptorSets[descriptorSetIndex] -= descriptorSetCount; mFreeDescriptorSets -= descriptorSetCount;
mCurrentSetsCount++; mCurrentSetsCount++;
return NoError(); return NoError();
} }
...@@ -343,18 +330,12 @@ Error DynamicDescriptorPool::allocateNewPool(VkDevice device) ...@@ -343,18 +330,12 @@ Error DynamicDescriptorPool::allocateNewPool(VkDevice device)
descriptorPoolInfo.maxSets = mMaxSetsPerPool; descriptorPoolInfo.maxSets = mMaxSetsPerPool;
// Reserve pools for uniform blocks and textures. // Reserve pools for uniform blocks and textures.
descriptorPoolInfo.poolSizeCount = static_cast<uint32_t>(mPoolSizes.size()); descriptorPoolInfo.poolSizeCount = 1u;
descriptorPoolInfo.pPoolSizes = mPoolSizes.data(); descriptorPoolInfo.pPoolSizes = &mPoolSize;
mFreeDescriptorSets.fill(0); mFreeDescriptorSets = mPoolSize.descriptorCount;
mCurrentSetsCount = 0; mCurrentSetsCount = 0;
for (const VkDescriptorPoolSize &poolSize : mPoolSizes)
{
size_t setIndex = GetDescriptorSetIndexfromType(poolSize.type);
mFreeDescriptorSets[setIndex] += poolSize.descriptorCount;
}
ANGLE_TRY(mCurrentDescriptorPool.init(device, descriptorPoolInfo)); ANGLE_TRY(mCurrentDescriptorPool.init(device, descriptorPoolInfo));
return NoError(); return NoError();
} }
......
...@@ -90,8 +90,6 @@ class DynamicBuffer : angle::NonCopyable ...@@ -90,8 +90,6 @@ class DynamicBuffer : angle::NonCopyable
// using the maximum number of descriptor sets and buffers with each allocation. Currently: 2 // 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. // (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. // This is an arbitrary max. We can change this later if necessary.
constexpr uint32_t kDefaultDescriptorPoolMaxSets = 2048; constexpr uint32_t kDefaultDescriptorPoolMaxSets = 2048;
...@@ -101,7 +99,8 @@ class DynamicDescriptorPool final : angle::NonCopyable ...@@ -101,7 +99,8 @@ class DynamicDescriptorPool final : angle::NonCopyable
DynamicDescriptorPool(); DynamicDescriptorPool();
~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); void destroy(VkDevice device);
// We use the descriptor type to help count the number of free sets. // We use the descriptor type to help count the number of free sets.
...@@ -109,7 +108,6 @@ class DynamicDescriptorPool final : angle::NonCopyable ...@@ -109,7 +108,6 @@ class DynamicDescriptorPool final : angle::NonCopyable
Error allocateSets(ContextVk *contextVk, Error allocateSets(ContextVk *contextVk,
const VkDescriptorSetLayout *descriptorSetLayout, const VkDescriptorSetLayout *descriptorSetLayout,
uint32_t descriptorSetCount, uint32_t descriptorSetCount,
uint32_t descriptorSetIndex,
VkDescriptorSet *descriptorSetsOut); VkDescriptorSet *descriptorSetsOut);
// For testing only! // For testing only!
...@@ -121,8 +119,8 @@ class DynamicDescriptorPool final : angle::NonCopyable ...@@ -121,8 +119,8 @@ class DynamicDescriptorPool final : angle::NonCopyable
uint32_t mMaxSetsPerPool; uint32_t mMaxSetsPerPool;
uint32_t mCurrentSetsCount; uint32_t mCurrentSetsCount;
DescriptorPool mCurrentDescriptorPool; DescriptorPool mCurrentDescriptorPool;
DescriptorPoolSizes mPoolSizes; VkDescriptorPoolSize mPoolSize;
DescriptorSetLayoutArray<uint32_t> mFreeDescriptorSets; uint32_t mFreeDescriptorSets;
}; };
// This class' responsibility is to create index buffers needed to support line loops in Vulkan. // 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