Files
LibretroAdmin b5da96cd78 vulkan: VMA is gone
The renderer's three allocation sites - textures, framebuffer
attachments and buffers - now go through vk_heap, and vk_mem_alloc.h and
its wrapper are out of the tree. The core is 182 KB smaller.

core/rend/vulkan/heap.{h,cpp} is what the renderer's classes hold: the
Allocation that gives its memory back when it goes, as before, and
VulkanHeap in place of VMAllocator. An allocation's pointer comes with
it, so MapMemory() is a load.

What each kind of memory asks for:

 - textures and attachments: device-local, falling back to whatever the
   image allows; a transient attachment first tries memory the device
   only backs if it has to
 - buffers and images the CPU fills: host-visible and coherent, on the
   device where the device has such memory. VMA was asked for
   host-visible only and nothing ever flushed, which was wrong on a
   device whose host-visible memory is not coherent
 - buffers the CPU reads back (render-to-texture readback): host-visible
   and host-cached. VMA put these in device memory seen through the bus
   on a discrete card, which is write-combined and slow to read

One block for images and one for the CPU's buffers are taken when the
device is set up, so a frame gets memory as an offset rather than from
the driver. A block is 64 MB, or an eighth of the device's memory where
that is less.

tools/threads/live.sh passes on the Vulkan renderer: the screenshot, the
save-state comparison with non-threaded rendering, and save, load and
reset back to back. A run under the Khronos validation layer reports
nothing. Software Vulkan only; not run on a GPU.
2026-10-05 17:32:12 +02:00

85 lines
2.5 KiB
C++

/*
* 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/>.
*/
#pragma once
#include "vulkan.h"
#include "heap.h"
struct BufferData
{
BufferData(vk::DeviceSize size, const vk::BufferUsageFlags& usage,
const vk::MemoryPropertyFlags& propertyFlags = vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent);
~BufferData()
{
buffer.reset();
}
void upload(u32 size, const void *data, u32 bufOffset = 0) const
{
verify((m_propertyFlags & vk::MemoryPropertyFlagBits::eHostCoherent) && (m_propertyFlags & vk::MemoryPropertyFlagBits::eHostVisible));
verify(bufOffset + size <= bufferSize);
void* dataPtr = (u8 *)allocation.MapMemory() + bufOffset;
memcpy(dataPtr, data, size);
}
void upload(size_t count, u32 *sizes, const void **data, u32 bufOffset = 0) const
{
verify((m_propertyFlags & vk::MemoryPropertyFlagBits::eHostCoherent) && (m_propertyFlags & vk::MemoryPropertyFlagBits::eHostVisible));
u32 totalSize = 0;
for (int i = 0; i < count; i++)
totalSize += sizes[i];
verify(bufOffset + totalSize <= bufferSize);
void* dataPtr = (u8 *)allocation.MapMemory() + bufOffset;
for (int i = 0; i < count; i++)
{
if (data[i] != nullptr)
memcpy(dataPtr, data[i], sizes[i]);
dataPtr = (u8 *)dataPtr + sizes[i];
}
}
void download(u32 size, void *data, u32 bufOffset = 0) const
{
verify((m_propertyFlags & vk::MemoryPropertyFlagBits::eHostCoherent) && (m_propertyFlags & vk::MemoryPropertyFlagBits::eHostVisible));
verify(bufOffset + size <= bufferSize);
void* dataPtr = (u8 *)allocation.MapMemory() + bufOffset;
memcpy(data, dataPtr, size);
}
void *MapMemory()
{
return allocation.MapMemory();
}
void UnmapMemory()
{
}
vk::UniqueBuffer buffer;
vk::DeviceSize bufferSize;
Allocation allocation;
private:
vk::BufferUsageFlags m_usage;
vk::MemoryPropertyFlags m_propertyFlags;
};