Fix memory alignment on Nvidia cards

This commit is contained in:
Georg Hagen
2024-05-28 22:20:02 +02:00
parent 7dd16c66b9
commit bc0e117d83
3 changed files with 13 additions and 7 deletions

View File

@@ -309,11 +309,11 @@ namespace OpenVulkano::Vulkan
vk::Buffer buffer = device.createBuffer(bufferCreateInfo);
const vk::MemoryRequirements memoryRequirements = device.getBufferMemoryRequirements(buffer);
uint32_t memtype = context->device->GetMemoryType(memoryRequirements.memoryTypeBits, properties);
if (memoryRequirements.size != size) Logger::DATA->warn("Memory Requirement Size ({0}) != Size ({1})", memoryRequirements.size, size);
MemoryAllocation* allocation = GetFreeMemoryAllocation(memoryRequirements.size, memtype);
uint32_t offset = allocation->used;
if (memoryRequirements.size != size) Logger::DATA->debug("Memory Requirement Size ({0}) != Size ({1})", memoryRequirements.size, size);
MemoryAllocation* allocation = GetFreeMemoryAllocation(memoryRequirements.size, memoryRequirements.alignment, memtype);
uint32_t offset = Utils::Align(allocation->used, memoryRequirements.alignment);
device.bindBufferMemory(buffer, allocation->memory, offset);
allocation->used += memoryRequirements.size;
allocation->used += memoryRequirements.size + (offset - allocation->used);
return new ManagedBuffer{ allocation, offset, size, buffer, usage, properties, nullptr };
}
@@ -326,12 +326,12 @@ namespace OpenVulkano::Vulkan
return alloc;
}
MemoryAllocation* ResourceManager::GetFreeMemoryAllocation(size_t size, uint32_t type, bool createIfAllFull)
MemoryAllocation* ResourceManager::GetFreeMemoryAllocation(size_t size, vk::DeviceSize alignment, uint32_t type, bool createIfAllFull)
{
MemoryAllocation* alloc = nullptr;
for (auto& allocation : allocations)
{
if (allocation->type == type && allocation->FreeSpace() >= size)
if (allocation->type == type && allocation->FreeSpace(alignment) >= size)
{
alloc = allocation.get();
break;