summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrChat <arkolbed@gmail.com>2018-02-09 20:58:17 -0600
committerDrChat <arkolbed@gmail.com>2018-02-09 20:58:17 -0600
commit5a637d6899607e0085aade33ff0889d348b62e93 (patch)
tree7b399fd85c79bba8845c112b3331d876e5d0fd31
parentc7ffec32603850b642461ad8f22c0c64d24dae49 (diff)
[Vulkan] Add VMA to Buffer Cache
-rw-r--r--src/xenia/gpu/vulkan/buffer_cache.cc34
-rw-r--r--src/xenia/gpu/vulkan/buffer_cache.h3
2 files changed, 23 insertions, 14 deletions
diff --git a/src/xenia/gpu/vulkan/buffer_cache.cc b/src/xenia/gpu/vulkan/buffer_cache.cc
index 5050e7469..287292021 100644
--- a/src/xenia/gpu/vulkan/buffer_cache.cc
+++ b/src/xenia/gpu/vulkan/buffer_cache.cc
@@ -16,6 +16,8 @@
#include "xenia/gpu/gpu_flags.h"
#include "xenia/gpu/vulkan/vulkan_gpu_flags.h"
+#include "third_party/vulkan/vk_mem_alloc.h"
+
namespace xe {
namespace gpu {
namespace vulkan {
@@ -47,6 +49,15 @@ VkResult BufferCache::Initialize() {
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.
// In the steady state we don't allocate anything, so these are all manually
// managed.
@@ -150,28 +161,23 @@ VkResult BufferCache::Initialize() {
}
void BufferCache::Shutdown() {
+ if (mem_allocator_) {
+ vmaDestroyAllocator(mem_allocator_);
+ mem_allocator_ = nullptr;
+ }
+
if (transient_descriptor_set_) {
vkFreeDescriptorSets(*device_, descriptor_pool_, 1,
&transient_descriptor_set_);
transient_descriptor_set_ = nullptr;
}
- if (descriptor_set_layout_) {
- vkDestroyDescriptorSetLayout(*device_, descriptor_set_layout_, nullptr);
- descriptor_set_layout_ = nullptr;
- }
-
- if (descriptor_pool_) {
- vkDestroyDescriptorPool(*device_, descriptor_pool_, nullptr);
- descriptor_pool_ = nullptr;
- }
+ VK_SAFE_DESTROY(vkDestroyDescriptorSetLayout, *device_,
+ descriptor_set_layout_, nullptr);
+ VK_SAFE_DESTROY(vkDestroyDescriptorPool, *device_, descriptor_pool_, nullptr);
transient_buffer_->Shutdown();
-
- if (gpu_memory_pool_) {
- vkFreeMemory(*device_, gpu_memory_pool_, nullptr);
- gpu_memory_pool_ = nullptr;
- }
+ VK_SAFE_DESTROY(vkFreeMemory, *device_, gpu_memory_pool_, nullptr);
}
std::pair<VkDeviceSize, VkDeviceSize> BufferCache::UploadConstantRegisters(
diff --git a/src/xenia/gpu/vulkan/buffer_cache.h b/src/xenia/gpu/vulkan/buffer_cache.h
index ffaa8b8fd..304455404 100644
--- a/src/xenia/gpu/vulkan/buffer_cache.h
+++ b/src/xenia/gpu/vulkan/buffer_cache.h
@@ -18,6 +18,8 @@
#include "xenia/ui/vulkan/vulkan.h"
#include "xenia/ui/vulkan/vulkan_device.h"
+#include "third_party/vulkan/vk_mem_alloc.h"
+
#include <map>
namespace xe {
@@ -115,6 +117,7 @@ class BufferCache {
ui::vulkan::VulkanDevice* device_ = nullptr;
VkDeviceMemory gpu_memory_pool_ = nullptr;
+ VmaAllocator mem_allocator_ = nullptr;
// Staging ringbuffer we cycle through fast. Used for data we don't
// plan on keeping past the current frame.