CircularBuffer: Allow users to bind their own memory to our buffer.
This commit is contained in:
@@ -28,11 +28,17 @@ constexpr VkDeviceSize kConstantRegisterUniformRange =
|
||||
BufferCache::BufferCache(RegisterFile* register_file,
|
||||
ui::vulkan::VulkanDevice* device, size_t capacity)
|
||||
: register_file_(register_file), device_(*device) {
|
||||
transient_buffer_ = std::make_unique<ui::vulkan::CircularBuffer>(device);
|
||||
if (!transient_buffer_->Initialize(capacity,
|
||||
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT |
|
||||
VK_BUFFER_USAGE_INDEX_BUFFER_BIT |
|
||||
VK_BUFFER_USAGE_VERTEX_BUFFER_BIT)) {
|
||||
transient_buffer_ = std::make_unique<ui::vulkan::CircularBuffer>(
|
||||
device,
|
||||
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT |
|
||||
VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
|
||||
capacity);
|
||||
|
||||
VkMemoryRequirements pool_reqs;
|
||||
transient_buffer_->GetBufferMemoryRequirements(&pool_reqs);
|
||||
gpu_memory_pool_ = device->AllocateMemory(pool_reqs);
|
||||
|
||||
if (!transient_buffer_->Initialize(gpu_memory_pool_, 0)) {
|
||||
assert_always();
|
||||
}
|
||||
|
||||
@@ -134,6 +140,10 @@ BufferCache::~BufferCache() {
|
||||
vkDestroyDescriptorSetLayout(device_, descriptor_set_layout_, nullptr);
|
||||
vkDestroyDescriptorPool(device_, descriptor_pool_, nullptr);
|
||||
transient_buffer_->Shutdown();
|
||||
|
||||
if (gpu_memory_pool_) {
|
||||
vkFreeMemory(device_, gpu_memory_pool_, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
std::pair<VkDeviceSize, VkDeviceSize> BufferCache::UploadConstantRegisters(
|
||||
@@ -221,8 +231,6 @@ std::pair<VkDeviceSize, VkDeviceSize> BufferCache::UploadConstantRegisters(
|
||||
std::pair<VkBuffer, VkDeviceSize> BufferCache::UploadIndexBuffer(
|
||||
const void* source_ptr, size_t source_length, IndexFormat format,
|
||||
std::shared_ptr<ui::vulkan::Fence> fence) {
|
||||
// TODO(benvanik): check cache.
|
||||
|
||||
// Allocate space in the buffer for our data.
|
||||
auto offset = AllocateTransientData(source_length, fence);
|
||||
if (offset == VK_WHOLE_SIZE) {
|
||||
@@ -249,8 +257,6 @@ std::pair<VkBuffer, VkDeviceSize> BufferCache::UploadIndexBuffer(
|
||||
std::pair<VkBuffer, VkDeviceSize> BufferCache::UploadVertexBuffer(
|
||||
const void* source_ptr, size_t source_length, Endian endian,
|
||||
std::shared_ptr<ui::vulkan::Fence> fence) {
|
||||
// TODO(benvanik): check cache.
|
||||
|
||||
// Allocate space in the buffer for our data.
|
||||
auto offset = AllocateTransientData(source_length, fence);
|
||||
if (offset == VK_WHOLE_SIZE) {
|
||||
@@ -324,7 +330,7 @@ void BufferCache::InvalidateCache() {
|
||||
}
|
||||
|
||||
void BufferCache::ClearCache() {
|
||||
// TODO(benvanik): caching.
|
||||
transient_cache_.clear();
|
||||
}
|
||||
|
||||
void BufferCache::Scavenge() { transient_buffer_->Scavenge(); }
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
#include "xenia/ui/vulkan/vulkan.h"
|
||||
#include "xenia/ui/vulkan/vulkan_device.h"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
namespace xe {
|
||||
namespace gpu {
|
||||
namespace vulkan {
|
||||
@@ -101,9 +103,12 @@ class BufferCache {
|
||||
RegisterFile* register_file_ = nullptr;
|
||||
VkDevice device_ = nullptr;
|
||||
|
||||
VkDeviceMemory gpu_memory_pool_ = nullptr;
|
||||
|
||||
// Staging ringbuffer we cycle through fast. Used for data we don't
|
||||
// plan on keeping past the current frame.
|
||||
std::unique_ptr<ui::vulkan::CircularBuffer> transient_buffer_ = nullptr;
|
||||
std::unordered_map<uint64_t, VkDeviceSize> transient_cache_;
|
||||
|
||||
VkDescriptorPool descriptor_pool_ = nullptr;
|
||||
VkDescriptorSetLayout descriptor_set_layout_ = nullptr;
|
||||
|
||||
@@ -111,7 +111,8 @@ TextureCache::TextureCache(Memory* memory, RegisterFile* register_file,
|
||||
register_file_(register_file),
|
||||
trace_writer_(trace_writer),
|
||||
device_(device),
|
||||
staging_buffer_(device) {
|
||||
staging_buffer_(device, VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
|
||||
kStagingBufferSize) {
|
||||
// Descriptor pool used for all of our cached descriptors.
|
||||
VkDescriptorPoolCreateInfo descriptor_pool_info;
|
||||
descriptor_pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
|
||||
@@ -152,8 +153,7 @@ TextureCache::TextureCache(Memory* memory, RegisterFile* register_file,
|
||||
nullptr, &texture_descriptor_set_layout_);
|
||||
CheckResult(err, "vkCreateDescriptorSetLayout");
|
||||
|
||||
if (!staging_buffer_.Initialize(kStagingBufferSize,
|
||||
VK_BUFFER_USAGE_TRANSFER_SRC_BIT)) {
|
||||
if (!staging_buffer_.Initialize()) {
|
||||
assert_always();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user