[Vulkan] Load Vulkan manually for more lifetime and extension control
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
|
||||
#include "xenia/base/assert.h"
|
||||
#include "xenia/ui/vulkan/vulkan.h"
|
||||
#include "xenia/ui/vulkan/vulkan_device.h"
|
||||
#include "xenia/ui/vulkan/vulkan_util.h"
|
||||
|
||||
namespace xe {
|
||||
@@ -28,7 +29,7 @@ namespace vulkan {
|
||||
template <typename T, typename HANDLE>
|
||||
class BaseFencedPool {
|
||||
public:
|
||||
BaseFencedPool(VkDevice device) : device_(device) {}
|
||||
BaseFencedPool(const VulkanDevice& device) : device_(device) {}
|
||||
|
||||
virtual ~BaseFencedPool() {
|
||||
// TODO(benvanik): wait on fence until done.
|
||||
@@ -47,11 +48,12 @@ class BaseFencedPool {
|
||||
// Checks all pending batches for completion and scavenges their entries.
|
||||
// This should be called as frequently as reasonable.
|
||||
void Scavenge() {
|
||||
const VulkanDevice::DeviceFunctions& dfn = device_.dfn();
|
||||
while (pending_batch_list_head_) {
|
||||
auto batch = pending_batch_list_head_;
|
||||
assert_not_null(batch->fence);
|
||||
|
||||
VkResult status = vkGetFenceStatus(device_, batch->fence);
|
||||
VkResult status = dfn.vkGetFenceStatus(device_, batch->fence);
|
||||
if (status == VK_SUCCESS || status == VK_ERROR_DEVICE_LOST) {
|
||||
// Batch has completed. Reclaim.
|
||||
pending_batch_list_head_ = batch->next;
|
||||
@@ -80,6 +82,7 @@ class BaseFencedPool {
|
||||
VkFence BeginBatch(VkFence fence = nullptr) {
|
||||
assert_null(open_batch_);
|
||||
Batch* batch = nullptr;
|
||||
const VulkanDevice::DeviceFunctions& dfn = device_.dfn();
|
||||
if (free_batch_list_head_) {
|
||||
// Reuse a batch.
|
||||
batch = free_batch_list_head_;
|
||||
@@ -88,10 +91,10 @@ class BaseFencedPool {
|
||||
|
||||
if (batch->flags & kBatchOwnsFence && !fence) {
|
||||
// Reset owned fence.
|
||||
vkResetFences(device_, 1, &batch->fence);
|
||||
dfn.vkResetFences(device_, 1, &batch->fence);
|
||||
} else if ((batch->flags & kBatchOwnsFence) && fence) {
|
||||
// Transfer owned -> external
|
||||
vkDestroyFence(device_, batch->fence, nullptr);
|
||||
dfn.vkDestroyFence(device_, batch->fence, nullptr);
|
||||
batch->fence = fence;
|
||||
batch->flags &= ~kBatchOwnsFence;
|
||||
} else if (!(batch->flags & kBatchOwnsFence) && !fence) {
|
||||
@@ -100,7 +103,8 @@ class BaseFencedPool {
|
||||
info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
|
||||
info.pNext = nullptr;
|
||||
info.flags = 0;
|
||||
VkResult res = vkCreateFence(device_, &info, nullptr, &batch->fence);
|
||||
VkResult res =
|
||||
dfn.vkCreateFence(device_, &info, nullptr, &batch->fence);
|
||||
if (res != VK_SUCCESS) {
|
||||
assert_always();
|
||||
}
|
||||
@@ -121,7 +125,8 @@ class BaseFencedPool {
|
||||
info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
|
||||
info.pNext = nullptr;
|
||||
info.flags = 0;
|
||||
VkResult res = vkCreateFence(device_, &info, nullptr, &batch->fence);
|
||||
VkResult res =
|
||||
dfn.vkCreateFence(device_, &info, nullptr, &batch->fence);
|
||||
if (res != VK_SUCCESS) {
|
||||
assert_always();
|
||||
}
|
||||
@@ -239,13 +244,14 @@ class BaseFencedPool {
|
||||
}
|
||||
|
||||
void FreeAllEntries() {
|
||||
const VulkanDevice::DeviceFunctions& dfn = device_.dfn();
|
||||
// Run down free lists.
|
||||
while (free_batch_list_head_) {
|
||||
auto batch = free_batch_list_head_;
|
||||
free_batch_list_head_ = batch->next;
|
||||
|
||||
if (batch->flags & kBatchOwnsFence) {
|
||||
vkDestroyFence(device_, batch->fence, nullptr);
|
||||
dfn.vkDestroyFence(device_, batch->fence, nullptr);
|
||||
batch->fence = nullptr;
|
||||
}
|
||||
delete batch;
|
||||
@@ -258,7 +264,7 @@ class BaseFencedPool {
|
||||
}
|
||||
}
|
||||
|
||||
VkDevice device_ = nullptr;
|
||||
const VulkanDevice& device_;
|
||||
|
||||
private:
|
||||
struct Entry {
|
||||
@@ -288,7 +294,7 @@ class CommandBufferPool
|
||||
public:
|
||||
typedef BaseFencedPool<CommandBufferPool, VkCommandBuffer> Base;
|
||||
|
||||
CommandBufferPool(VkDevice device, uint32_t queue_family_index);
|
||||
CommandBufferPool(const VulkanDevice& device, uint32_t queue_family_index);
|
||||
~CommandBufferPool() override;
|
||||
|
||||
VkCommandBuffer AcquireEntry(
|
||||
@@ -308,7 +314,7 @@ class DescriptorPool : public BaseFencedPool<DescriptorPool, VkDescriptorSet> {
|
||||
public:
|
||||
typedef BaseFencedPool<DescriptorPool, VkDescriptorSet> Base;
|
||||
|
||||
DescriptorPool(VkDevice device, uint32_t max_count,
|
||||
DescriptorPool(const VulkanDevice& device, uint32_t max_count,
|
||||
std::vector<VkDescriptorPoolSize> pool_sizes);
|
||||
~DescriptorPool() override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user