2017-10-15 19:23:10 +02:00
|
|
|
#include "dxvk_descriptor.h"
|
|
|
|
|
|
|
|
namespace dxvk {
|
|
|
|
|
|
|
|
DxvkDescriptorAlloc::DxvkDescriptorAlloc(
|
|
|
|
const Rc<vk::DeviceFn>& vkd)
|
|
|
|
: m_vkd(vkd) {
|
2017-12-20 00:16:59 +01:00
|
|
|
// Allocate one pool right away so that there
|
|
|
|
// is always at least one pool available when
|
|
|
|
// allocating a descriptor set
|
|
|
|
m_pools.push_back(createDescriptorPool());
|
2017-10-15 19:23:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DxvkDescriptorAlloc::~DxvkDescriptorAlloc() {
|
|
|
|
for (auto p : m_pools) {
|
|
|
|
m_vkd->vkDestroyDescriptorPool(
|
|
|
|
m_vkd->device(), p, nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VkDescriptorSet DxvkDescriptorAlloc::alloc(VkDescriptorSetLayout layout) {
|
2017-12-20 12:13:08 +01:00
|
|
|
VkDescriptorSet set = allocFrom(m_pools[m_poolId], layout);
|
2017-10-15 19:23:10 +02:00
|
|
|
|
|
|
|
if (set == VK_NULL_HANDLE) {
|
2017-12-20 00:16:59 +01:00
|
|
|
if (++m_poolId >= m_pools.size())
|
|
|
|
m_pools.push_back(createDescriptorPool());
|
2017-10-15 19:23:10 +02:00
|
|
|
|
2017-12-20 12:13:08 +01:00
|
|
|
set = allocFrom(m_pools[m_poolId], layout);
|
2017-10-15 19:23:10 +02:00
|
|
|
}
|
2017-12-20 00:16:59 +01:00
|
|
|
|
2017-10-15 19:23:10 +02:00
|
|
|
return set;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DxvkDescriptorAlloc::reset() {
|
|
|
|
for (auto p : m_pools) {
|
|
|
|
m_vkd->vkResetDescriptorPool(
|
|
|
|
m_vkd->device(), p, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_poolId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VkDescriptorPool DxvkDescriptorAlloc::createDescriptorPool() {
|
2018-01-09 20:04:50 +01:00
|
|
|
constexpr uint32_t MaxSets = 256;
|
|
|
|
constexpr uint32_t MaxDesc = 2048;
|
2017-10-15 19:23:10 +02:00
|
|
|
|
2017-11-18 10:42:27 +01:00
|
|
|
std::array<VkDescriptorPoolSize, 7> pools = {{
|
|
|
|
{ VK_DESCRIPTOR_TYPE_SAMPLER, MaxDesc },
|
|
|
|
{ VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, MaxDesc },
|
|
|
|
{ VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, MaxDesc },
|
|
|
|
{ VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MaxDesc },
|
|
|
|
{ VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, MaxDesc },
|
|
|
|
{ VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, MaxDesc },
|
|
|
|
{ VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, MaxDesc } }};
|
2017-10-15 19:23:10 +02:00
|
|
|
|
|
|
|
VkDescriptorPoolCreateInfo info;
|
|
|
|
info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
|
|
|
|
info.pNext = nullptr;
|
|
|
|
info.flags = 0;
|
|
|
|
info.maxSets = MaxSets;
|
|
|
|
info.poolSizeCount = pools.size();
|
|
|
|
info.pPoolSizes = pools.data();
|
|
|
|
|
|
|
|
VkDescriptorPool pool = VK_NULL_HANDLE;
|
|
|
|
if (m_vkd->vkCreateDescriptorPool(m_vkd->device(),
|
|
|
|
&info, nullptr, &pool) != VK_SUCCESS)
|
2017-12-20 00:16:59 +01:00
|
|
|
throw DxvkError("DxvkDescriptorAlloc: Failed to create descriptor pool");
|
2017-10-15 19:23:10 +02:00
|
|
|
return pool;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VkDescriptorSet DxvkDescriptorAlloc::allocFrom(
|
|
|
|
VkDescriptorPool pool,
|
|
|
|
VkDescriptorSetLayout layout) const {
|
|
|
|
VkDescriptorSetAllocateInfo info;
|
|
|
|
info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
|
|
|
|
info.pNext = nullptr;
|
|
|
|
info.descriptorPool = pool;
|
|
|
|
info.descriptorSetCount = 1;
|
|
|
|
info.pSetLayouts = &layout;
|
|
|
|
|
|
|
|
VkDescriptorSet set = VK_NULL_HANDLE;
|
|
|
|
if (m_vkd->vkAllocateDescriptorSets(m_vkd->device(), &info, &set) != VK_SUCCESS)
|
|
|
|
return VK_NULL_HANDLE;
|
|
|
|
return set;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|