[Vulkan] Add VMA to Buffer Cache
This commit is contained in:
parent
c7ffec3260
commit
5a637d6899
|
@ -16,6 +16,8 @@
|
||||||
#include "xenia/gpu/gpu_flags.h"
|
#include "xenia/gpu/gpu_flags.h"
|
||||||
#include "xenia/gpu/vulkan/vulkan_gpu_flags.h"
|
#include "xenia/gpu/vulkan/vulkan_gpu_flags.h"
|
||||||
|
|
||||||
|
#include "third_party/vulkan/vk_mem_alloc.h"
|
||||||
|
|
||||||
namespace xe {
|
namespace xe {
|
||||||
namespace gpu {
|
namespace gpu {
|
||||||
namespace vulkan {
|
namespace vulkan {
|
||||||
|
@ -47,6 +49,15 @@ VkResult BufferCache::Initialize() {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a memory allocator for textures.
|
||||||
|
VmaAllocatorCreateInfo alloc_info = {
|
||||||
|
0, *device_, *device_, 0, 0, nullptr, nullptr,
|
||||||
|
};
|
||||||
|
status = vmaCreateAllocator(&alloc_info, &mem_allocator_);
|
||||||
|
if (status != VK_SUCCESS) {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
// Descriptor pool used for all of our cached descriptors.
|
// Descriptor pool used for all of our cached descriptors.
|
||||||
// In the steady state we don't allocate anything, so these are all manually
|
// In the steady state we don't allocate anything, so these are all manually
|
||||||
// managed.
|
// managed.
|
||||||
|
@ -150,28 +161,23 @@ VkResult BufferCache::Initialize() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void BufferCache::Shutdown() {
|
void BufferCache::Shutdown() {
|
||||||
|
if (mem_allocator_) {
|
||||||
|
vmaDestroyAllocator(mem_allocator_);
|
||||||
|
mem_allocator_ = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
if (transient_descriptor_set_) {
|
if (transient_descriptor_set_) {
|
||||||
vkFreeDescriptorSets(*device_, descriptor_pool_, 1,
|
vkFreeDescriptorSets(*device_, descriptor_pool_, 1,
|
||||||
&transient_descriptor_set_);
|
&transient_descriptor_set_);
|
||||||
transient_descriptor_set_ = nullptr;
|
transient_descriptor_set_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (descriptor_set_layout_) {
|
VK_SAFE_DESTROY(vkDestroyDescriptorSetLayout, *device_,
|
||||||
vkDestroyDescriptorSetLayout(*device_, descriptor_set_layout_, nullptr);
|
descriptor_set_layout_, nullptr);
|
||||||
descriptor_set_layout_ = nullptr;
|
VK_SAFE_DESTROY(vkDestroyDescriptorPool, *device_, descriptor_pool_, nullptr);
|
||||||
}
|
|
||||||
|
|
||||||
if (descriptor_pool_) {
|
|
||||||
vkDestroyDescriptorPool(*device_, descriptor_pool_, nullptr);
|
|
||||||
descriptor_pool_ = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
transient_buffer_->Shutdown();
|
transient_buffer_->Shutdown();
|
||||||
|
VK_SAFE_DESTROY(vkFreeMemory, *device_, gpu_memory_pool_, nullptr);
|
||||||
if (gpu_memory_pool_) {
|
|
||||||
vkFreeMemory(*device_, gpu_memory_pool_, nullptr);
|
|
||||||
gpu_memory_pool_ = nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<VkDeviceSize, VkDeviceSize> BufferCache::UploadConstantRegisters(
|
std::pair<VkDeviceSize, VkDeviceSize> BufferCache::UploadConstantRegisters(
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
#include "xenia/ui/vulkan/vulkan.h"
|
#include "xenia/ui/vulkan/vulkan.h"
|
||||||
#include "xenia/ui/vulkan/vulkan_device.h"
|
#include "xenia/ui/vulkan/vulkan_device.h"
|
||||||
|
|
||||||
|
#include "third_party/vulkan/vk_mem_alloc.h"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
namespace xe {
|
namespace xe {
|
||||||
|
@ -115,6 +117,7 @@ class BufferCache {
|
||||||
ui::vulkan::VulkanDevice* device_ = nullptr;
|
ui::vulkan::VulkanDevice* device_ = nullptr;
|
||||||
|
|
||||||
VkDeviceMemory gpu_memory_pool_ = nullptr;
|
VkDeviceMemory gpu_memory_pool_ = nullptr;
|
||||||
|
VmaAllocator mem_allocator_ = nullptr;
|
||||||
|
|
||||||
// Staging ringbuffer we cycle through fast. Used for data we don't
|
// Staging ringbuffer we cycle through fast. Used for data we don't
|
||||||
// plan on keeping past the current frame.
|
// plan on keeping past the current frame.
|
||||||
|
|
Loading…
Reference in New Issue