[Vulkan] Load Vulkan manually for more lifetime and extension control

This commit is contained in:
Triang3l
2021-07-11 22:56:01 +03:00
parent 458e4e1a31
commit 692e329e9c
38 changed files with 1224 additions and 788 deletions

View File

@@ -19,9 +19,11 @@ namespace vulkan {
using xe::ui::vulkan::CheckResult;
CommandBufferPool::CommandBufferPool(VkDevice device,
CommandBufferPool::CommandBufferPool(const VulkanDevice& device,
uint32_t queue_family_index)
: BaseFencedPool(device) {
const VulkanDevice::DeviceFunctions& dfn = device_.dfn();
// Create the pool used for allocating buffers.
// They are marked as transient (short-lived) and cycled frequently.
VkCommandPoolCreateInfo cmd_pool_info;
@@ -31,7 +33,7 @@ CommandBufferPool::CommandBufferPool(VkDevice device,
VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
cmd_pool_info.queueFamilyIndex = queue_family_index;
auto err =
vkCreateCommandPool(device_, &cmd_pool_info, nullptr, &command_pool_);
dfn.vkCreateCommandPool(device_, &cmd_pool_info, nullptr, &command_pool_);
CheckResult(err, "vkCreateCommandPool");
// Allocate a bunch of command buffers to start.
@@ -43,8 +45,8 @@ CommandBufferPool::CommandBufferPool(VkDevice device,
command_buffer_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
command_buffer_info.commandBufferCount = kDefaultCount;
VkCommandBuffer command_buffers[kDefaultCount];
err =
vkAllocateCommandBuffers(device_, &command_buffer_info, command_buffers);
err = dfn.vkAllocateCommandBuffers(device_, &command_buffer_info,
command_buffers);
CheckResult(err, "vkCreateCommandBuffer");
for (size_t i = 0; i < xe::countof(command_buffers); ++i) {
PushEntry(command_buffers[i], nullptr);
@@ -53,7 +55,8 @@ CommandBufferPool::CommandBufferPool(VkDevice device,
CommandBufferPool::~CommandBufferPool() {
FreeAllEntries();
vkDestroyCommandPool(device_, command_pool_, nullptr);
const VulkanDevice::DeviceFunctions& dfn = device_.dfn();
dfn.vkDestroyCommandPool(device_, command_pool_, nullptr);
command_pool_ = nullptr;
}
@@ -67,17 +70,19 @@ VkCommandBuffer CommandBufferPool::AllocateEntry(void* data) {
VkCommandBufferLevel(reinterpret_cast<uintptr_t>(data));
command_buffer_info.commandBufferCount = 1;
VkCommandBuffer command_buffer;
auto err =
vkAllocateCommandBuffers(device_, &command_buffer_info, &command_buffer);
const VulkanDevice::DeviceFunctions& dfn = device_.dfn();
auto err = dfn.vkAllocateCommandBuffers(device_, &command_buffer_info,
&command_buffer);
CheckResult(err, "vkCreateCommandBuffer");
return command_buffer;
}
void CommandBufferPool::FreeEntry(VkCommandBuffer handle) {
vkFreeCommandBuffers(device_, command_pool_, 1, &handle);
const VulkanDevice::DeviceFunctions& dfn = device_.dfn();
dfn.vkFreeCommandBuffers(device_, command_pool_, 1, &handle);
}
DescriptorPool::DescriptorPool(VkDevice device, uint32_t max_count,
DescriptorPool::DescriptorPool(const VulkanDevice& device, uint32_t max_count,
std::vector<VkDescriptorPoolSize> pool_sizes)
: BaseFencedPool(device) {
VkDescriptorPoolCreateInfo descriptor_pool_info;
@@ -88,13 +93,15 @@ DescriptorPool::DescriptorPool(VkDevice device, uint32_t max_count,
descriptor_pool_info.maxSets = max_count;
descriptor_pool_info.poolSizeCount = uint32_t(pool_sizes.size());
descriptor_pool_info.pPoolSizes = pool_sizes.data();
auto err = vkCreateDescriptorPool(device, &descriptor_pool_info, nullptr,
&descriptor_pool_);
const VulkanDevice::DeviceFunctions& dfn = device_.dfn();
auto err = dfn.vkCreateDescriptorPool(device, &descriptor_pool_info, nullptr,
&descriptor_pool_);
CheckResult(err, "vkCreateDescriptorPool");
}
DescriptorPool::~DescriptorPool() {
FreeAllEntries();
vkDestroyDescriptorPool(device_, descriptor_pool_, nullptr);
const VulkanDevice::DeviceFunctions& dfn = device_.dfn();
dfn.vkDestroyDescriptorPool(device_, descriptor_pool_, nullptr);
descriptor_pool_ = nullptr;
}
@@ -108,15 +115,17 @@ VkDescriptorSet DescriptorPool::AllocateEntry(void* data) {
set_alloc_info.descriptorPool = descriptor_pool_;
set_alloc_info.descriptorSetCount = 1;
set_alloc_info.pSetLayouts = &layout;
const VulkanDevice::DeviceFunctions& dfn = device_.dfn();
auto err =
vkAllocateDescriptorSets(device_, &set_alloc_info, &descriptor_set);
dfn.vkAllocateDescriptorSets(device_, &set_alloc_info, &descriptor_set);
CheckResult(err, "vkAllocateDescriptorSets");
return descriptor_set;
}
void DescriptorPool::FreeEntry(VkDescriptorSet handle) {
vkFreeDescriptorSets(device_, descriptor_pool_, 1, &handle);
const VulkanDevice::DeviceFunctions& dfn = device_.dfn();
dfn.vkFreeDescriptorSets(device_, descriptor_pool_, 1, &handle);
}
} // namespace vulkan