mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-12-02 02:33:43 +01:00
Vulkan: Cache only device in push buffers.
This commit is contained in:
1 parent
0009b55210
commit
9fd040eed0
4 files changed
+33
-32
No files matched your search
@@ -20,13 +20,14 @@
|
||||
|
||||
#include "Common/Vulkan/VulkanMemory.h"
|
||||
|
||||
VulkanPushBuffer::VulkanPushBuffer(VulkanContext *vulkan, size_t size) : ctx_(vulkan), buf_(0), offset_(0), size_(size), writePtr_(nullptr) {
|
||||
VulkanPushBuffer::VulkanPushBuffer(VulkanContext *vulkan, size_t size) : device_(vulkan->GetDevice()), buf_(0), offset_(0), size_(size), writePtr_(nullptr) {
|
||||
vulkan->MemoryTypeFromProperties(0xFFFFFFFF, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, &memoryTypeIndex_);
|
||||
|
||||
bool res = AddBuffer();
|
||||
assert(res);
|
||||
}
|
||||
|
||||
bool VulkanPushBuffer::AddBuffer() {
|
||||
VkDevice device = ctx_->GetDevice();
|
||||
BufInfo info;
|
||||
|
||||
VkBufferCreateInfo b = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
|
||||
@@ -37,21 +38,21 @@ bool VulkanPushBuffer::AddBuffer() {
|
||||
b.queueFamilyIndexCount = 0;
|
||||
b.pQueueFamilyIndices = nullptr;
|
||||
|
||||
VkResult res = vkCreateBuffer(device, &b, nullptr, &info.buffer);
|
||||
VkResult res = vkCreateBuffer(device_, &b, nullptr, &info.buffer);
|
||||
if (VK_SUCCESS != res) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Okay, that's the buffer. Now let's allocate some memory for it.
|
||||
VkMemoryAllocateInfo alloc = { VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO };
|
||||
ctx_->MemoryTypeFromProperties(0xFFFFFFFF, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, &alloc.memoryTypeIndex);
|
||||
alloc.memoryTypeIndex = memoryTypeIndex_;
|
||||
alloc.allocationSize = size_;
|
||||
|
||||
res = vkAllocateMemory(device, &alloc, nullptr, &info.deviceMemory);
|
||||
res = vkAllocateMemory(device_, &alloc, nullptr, &info.deviceMemory);
|
||||
if (VK_SUCCESS != res) {
|
||||
return false;
|
||||
}
|
||||
res = vkBindBufferMemory(device, info.buffer, info.deviceMemory, 0);
|
||||
res = vkBindBufferMemory(device_, info.buffer, info.deviceMemory, 0);
|
||||
if (VK_SUCCESS != res) {
|
||||
return false;
|
||||
}
|
||||
@@ -63,10 +64,8 @@ bool VulkanPushBuffer::AddBuffer() {
|
||||
}
|
||||
|
||||
void VulkanPushBuffer::NextBuffer() {
|
||||
VkDevice device = ctx_->GetDevice();
|
||||
|
||||
// First, unmap the current memory.
|
||||
Unmap(device);
|
||||
Unmap();
|
||||
|
||||
buf_++;
|
||||
if (buf_ >= buffers_.size()) {
|
||||
@@ -80,17 +79,17 @@ void VulkanPushBuffer::NextBuffer() {
|
||||
|
||||
// Now, move to the next buffer and map it.
|
||||
offset_ = 0;
|
||||
Map(device);
|
||||
Map();
|
||||
}
|
||||
|
||||
void VulkanPushBuffer::Defragment() {
|
||||
void VulkanPushBuffer::Defragment(VulkanContext *vulkan) {
|
||||
if (buffers_.size() <= 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Okay, we have more than one. Destroy them all and start over with a larger one.
|
||||
size_t newSize = size_ * buffers_.size();
|
||||
Destroy(ctx_);
|
||||
Destroy(vulkan);
|
||||
|
||||
size_ = newSize;
|
||||
bool res = AddBuffer();
|
||||
|
||||
Reference in new issue
Block a user