| 159 | } |
| 160 | |
| 161 | void VkHardwareBuffer::Resize(size_t newsize) |
| 162 | { |
| 163 | newsize = max(newsize, (size_t)16); // For supporting zero byte buffers |
| 164 | |
| 165 | // Grab old buffer |
| 166 | size_t oldsize = buffersize; |
| 167 | std::unique_ptr<VulkanBuffer> oldBuffer = std::move(mBuffer); |
| 168 | oldBuffer->Unmap(); |
| 169 | map = nullptr; |
| 170 | |
| 171 | // Create new buffer |
| 172 | mBuffer = BufferBuilder() |
| 173 | .Usage(mBufferType, VMA_MEMORY_USAGE_UNKNOWN, VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT) |
| 174 | .MemoryType( |
| 175 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, |
| 176 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) |
| 177 | .Size(newsize) |
| 178 | .DebugName("VkHardwareBuffer.Resized") |
| 179 | .Create(fb->device.get()); |
| 180 | buffersize = newsize; |
| 181 | |
| 182 | // Transfer data from old to new |
| 183 | fb->GetCommands()->GetTransferCommands()->copyBuffer(oldBuffer.get(), mBuffer.get(), 0, 0, oldsize); |
| 184 | fb->GetCommands()->TransferDeleteList->Add(std::move(oldBuffer)); |
| 185 | fb->GetCommands()->WaitForCommands(false); |
| 186 | fb->GetDescriptorSetManager()->UpdateHWBufferSet(); // Old buffer may be part of the bound descriptor set |
| 187 | |
| 188 | // Fetch pointer to new buffer |
| 189 | map = mBuffer->Map(0, newsize); |
| 190 | } |
| 191 | |
| 192 | void VkHardwareBuffer::Map() |
| 193 | { |
no test coverage detected