2017-10-15 19:23:10 +02:00
|
|
|
#include "dxvk_descriptor.h"
|
2018-11-27 11:07:23 +01:00
|
|
|
#include "dxvk_device.h"
|
2017-10-15 19:23:10 +02:00
|
|
|
|
|
|
|
namespace dxvk {
|
|
|
|
|
2018-11-27 11:07:23 +01:00
|
|
|
DxvkDescriptorPool::DxvkDescriptorPool(const Rc<vk::DeviceFn>& vkd)
|
2017-10-15 19:23:10 +02:00
|
|
|
: m_vkd(vkd) {
|
2018-11-26 23:57:26 +01:00
|
|
|
constexpr uint32_t MaxSets = 2048;
|
|
|
|
|
2019-10-11 14:21:49 +02:00
|
|
|
std::array<VkDescriptorPoolSize, 9> pools = {{
|
2018-11-26 23:57:26 +01:00
|
|
|
{ VK_DESCRIPTOR_TYPE_SAMPLER, MaxSets * 2 },
|
|
|
|
{ VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, MaxSets * 3 },
|
|
|
|
{ VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, MaxSets / 8 },
|
|
|
|
{ VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MaxSets * 3 },
|
|
|
|
{ VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, MaxSets / 8 },
|
|
|
|
{ VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, MaxSets * 3 },
|
|
|
|
{ VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, MaxSets / 8 },
|
|
|
|
{ VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, MaxSets * 3 },
|
2019-04-03 17:24:04 +02:00
|
|
|
{ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, MaxSets * 2 } }};
|
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();
|
|
|
|
|
2018-11-27 11:07:23 +01:00
|
|
|
if (m_vkd->vkCreateDescriptorPool(m_vkd->device(), &info, nullptr, &m_pool) != VK_SUCCESS)
|
|
|
|
throw DxvkError("DxvkDescriptorPool: Failed to create descriptor pool");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DxvkDescriptorPool::~DxvkDescriptorPool() {
|
|
|
|
m_vkd->vkDestroyDescriptorPool(
|
|
|
|
m_vkd->device(), m_pool, nullptr);
|
2017-10-15 19:23:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-27 11:07:23 +01:00
|
|
|
VkDescriptorSet DxvkDescriptorPool::alloc(VkDescriptorSetLayout layout) {
|
2017-10-15 19:23:10 +02:00
|
|
|
VkDescriptorSetAllocateInfo info;
|
|
|
|
info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
|
|
|
|
info.pNext = nullptr;
|
2018-11-27 11:07:23 +01:00
|
|
|
info.descriptorPool = m_pool;
|
2017-10-15 19:23:10 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-11-27 11:07:23 +01:00
|
|
|
|
|
|
|
void DxvkDescriptorPool::reset() {
|
|
|
|
m_vkd->vkResetDescriptorPool(
|
|
|
|
m_vkd->device(), m_pool, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DxvkDescriptorPoolTracker::DxvkDescriptorPoolTracker(DxvkDevice* device)
|
|
|
|
: m_device(device) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DxvkDescriptorPoolTracker::~DxvkDescriptorPoolTracker() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DxvkDescriptorPoolTracker::trackDescriptorPool(Rc<DxvkDescriptorPool> pool) {
|
|
|
|
m_pools.push_back(std::move(pool));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DxvkDescriptorPoolTracker::reset() {
|
|
|
|
for (const auto& pool : m_pools) {
|
|
|
|
pool->reset();
|
|
|
|
m_device->recycleDescriptorPool(pool);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pools.clear();
|
|
|
|
}
|
|
|
|
|
2017-10-15 19:23:10 +02:00
|
|
|
}
|