Vulkan: Handle oversized push buf allocations.

This commit is contained in:
Unknown W. Brackets 2016-03-20 17:24:20 -07:00
parent 9fd040eed0
commit 6d947a057e
2 changed files with 10 additions and 6 deletions

View file

@ -63,12 +63,17 @@ bool VulkanPushBuffer::AddBuffer() {
return true;
}
void VulkanPushBuffer::NextBuffer() {
void VulkanPushBuffer::NextBuffer(size_t minSize) {
// First, unmap the current memory.
Unmap();
buf_++;
if (buf_ >= buffers_.size()) {
if (buf_ >= buffers_.size() || minSize > size_) {
// Before creating the buffer, adjust to the new size_ if necessary.
while (size_ < minSize) {
size_ <<= 1;
}
bool res = AddBuffer();
assert(res);
if (!res) {

View file

@ -42,6 +42,7 @@ public:
void Begin(VulkanContext *vulkan) {
buf_ = 0;
offset_ = 0;
// Note: we must defrag because some buffers may be smaller than size_.
Defragment(vulkan);
Map();
}
@ -72,13 +73,11 @@ public:
// When using the returned memory, make sure to bind the returned vkbuf.
// This will later allow for handling overflow correctly.
size_t Allocate(size_t numBytes, VkBuffer *vkbuf) {
assert(numBytes < size_);
size_t out = offset_;
offset_ += (numBytes + 3) & ~3; // Round up to 4 bytes.
if (offset_ >= size_) {
NextBuffer();
NextBuffer(numBytes);
out = offset_;
offset_ += (numBytes + 3) & ~3;
}
@ -116,7 +115,7 @@ public:
private:
bool AddBuffer();
void NextBuffer();
void NextBuffer(size_t minSize);
void Defragment(VulkanContext *vulkan);
VkDevice device_;