2019-10-05 09:50:14 +00:00
|
|
|
/*
|
|
|
|
* Created on: Oct 3, 2019
|
|
|
|
|
|
|
|
Copyright 2019 flyinghead
|
|
|
|
|
|
|
|
This file is part of Flycast.
|
|
|
|
|
|
|
|
Flycast is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Flycast is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Flycast. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include "buffer.h"
|
|
|
|
#include "utils.h"
|
2019-11-29 18:28:22 +00:00
|
|
|
#include "vulkan_context.h"
|
2019-10-05 09:50:14 +00:00
|
|
|
|
2021-03-13 13:13:39 +00:00
|
|
|
BufferData::BufferData(vk::DeviceSize size, const vk::BufferUsageFlags& usage, const vk::MemoryPropertyFlags& propertyFlags)
|
2019-12-04 18:06:14 +00:00
|
|
|
: bufferSize(size), m_usage(usage), m_propertyFlags(propertyFlags)
|
2019-10-05 09:50:14 +00:00
|
|
|
{
|
2019-11-26 09:42:44 +00:00
|
|
|
VulkanContext *context = VulkanContext::Instance();
|
|
|
|
buffer = context->GetDevice().createBufferUnique(vk::BufferCreateInfo(vk::BufferCreateFlags(), size, usage));
|
2019-12-04 14:51:26 +00:00
|
|
|
VmaAllocationCreateInfo allocInfo = {
|
2021-11-01 12:05:22 +00:00
|
|
|
(propertyFlags & vk::MemoryPropertyFlagBits::eHostCoherent) ? VMA_ALLOCATION_CREATE_MAPPED_BIT : (VmaAllocationCreateFlags)0,
|
2019-12-04 14:51:26 +00:00
|
|
|
(propertyFlags & vk::MemoryPropertyFlagBits::eDeviceLocal) ? VmaMemoryUsage::VMA_MEMORY_USAGE_GPU_ONLY : VmaMemoryUsage::VMA_MEMORY_USAGE_CPU_TO_GPU
|
|
|
|
};
|
2021-11-01 12:05:22 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
if (!(propertyFlags & vk::MemoryPropertyFlagBits::eDeviceLocal))
|
|
|
|
// cpu memory management is fucked up with moltenvk
|
|
|
|
allocInfo.flags |= VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT;
|
|
|
|
#endif
|
2019-11-26 09:42:44 +00:00
|
|
|
allocation = context->GetAllocator().AllocateForBuffer(*buffer, allocInfo);
|
2019-10-05 09:50:14 +00:00
|
|
|
}
|
2022-03-12 16:56:46 +00:00
|
|
|
|
|
|
|
BufferPacker::BufferPacker()
|
|
|
|
{
|
|
|
|
uniformAlignment = VulkanContext::Instance()->GetUniformBufferAlignment();
|
|
|
|
storageAlignment = VulkanContext::Instance()->GetStorageBufferAlignment();
|
|
|
|
}
|