Skip to content

Commit

Permalink
[dxvk] Also reset descriptor pool when only one pool is in use
Browse files Browse the repository at this point in the history
This way we can often avoid allocating additional descriptor pools.
  • Loading branch information
doitsujin committed Jan 20, 2023
1 parent eacb8da commit 0af5ece
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
34 changes: 16 additions & 18 deletions src/dxvk/dxvk_descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ namespace dxvk {

size_t poolCount = m_descriptorPools.size();

if (poolCount > 1) {
if (poolCount > 1 || m_setsAllocated > m_manager->getMaxSetCount() / 2) {
double factor = std::max(11.0 / 3.0 - double(poolCount) / 3.0, 1.0);
isLowUsageFrame = double(m_setsUsed) * factor < double(m_setsAllocated);
}
Expand Down Expand Up @@ -244,7 +244,12 @@ namespace dxvk {
DxvkDevice* device,
DxvkContextType contextType)
: m_device(device), m_contextType(contextType) {

// Deliberately pick a very high number of descriptor sets so that
// we will typically end up using all available pool memory before
// the descriptor set limit becomes the limiting factor.
m_maxSets = m_contextType == DxvkContextType::Primary
? (env::is32BitHostPlatform() ? 24576u : 49152u)
: (512u);
}


Expand Down Expand Up @@ -288,29 +293,22 @@ namespace dxvk {
return m_vkPools[--m_vkPoolCount];
}

// Deliberately pick a very high number of descriptor sets so that
// we will typically end up using all available pool memory before
// the descriptor set limit becomes the limiting factor.
uint32_t maxSets = m_contextType == DxvkContextType::Primary
? (env::is32BitHostPlatform() ? 24576u : 49152u)
: (512u);

// Samplers and uniform buffers may be special on some implementations
// so we should allocate space for a reasonable number of both, but
// assume that all other descriptor types share pool memory.
std::array<VkDescriptorPoolSize, 8> pools = {{
{ VK_DESCRIPTOR_TYPE_SAMPLER, maxSets * 1 },
{ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, maxSets / 4 },
{ VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, maxSets / 2 },
{ VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, maxSets / 64 },
{ VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, maxSets / 2 },
{ VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, maxSets / 64 },
{ VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, maxSets * 2 },
{ VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, maxSets / 2 },
{ VK_DESCRIPTOR_TYPE_SAMPLER, m_maxSets * 1 },
{ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, m_maxSets / 4 },
{ VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, m_maxSets / 2 },
{ VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, m_maxSets / 64 },
{ VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, m_maxSets / 2 },
{ VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, m_maxSets / 64 },
{ VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, m_maxSets * 2 },
{ VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, m_maxSets / 2 },
}};

VkDescriptorPoolCreateInfo info = { VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO };
info.maxSets = maxSets;
info.maxSets = m_maxSets;
info.poolSizeCount = pools.size();
info.pPoolSizes = pools.data();

Expand Down
9 changes: 9 additions & 0 deletions src/dxvk/dxvk_descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,14 @@ namespace dxvk {

~DxvkDescriptorManager();

/**
* \brief Queries maximum number of descriptor sets per pool
* \returns Maximum set count
*/
uint32_t getMaxSetCount() const {
return m_maxSets;
}

/**
* \brief Retrieves or creates a descriptor type
* \returns The descriptor pool
Expand Down Expand Up @@ -229,6 +237,7 @@ namespace dxvk {

DxvkDevice* m_device;
DxvkContextType m_contextType;
uint32_t m_maxSets = 0;
DxvkRecycler<DxvkDescriptorPool, 8> m_pools;

dxvk::mutex m_mutex;
Expand Down

0 comments on commit 0af5ece

Please sign in to comment.