Adding nlohmanns json library

This commit is contained in:
Dynamitos
2020-05-05 01:52:07 +02:00
parent 3ef8342247
commit bb5b48698a
83 changed files with 2426 additions and 646 deletions
+41 -58
View File
@@ -5,12 +5,8 @@
using namespace Seele::Vulkan;
SubAllocation::SubAllocation(Allocation* owner, VkDeviceSize allocatedOffset, VkDeviceSize size, VkDeviceSize alignedOffset, VkDeviceSize allocatedSize)
: owner(owner)
, size(size)
, allocatedOffset(allocatedOffset)
, alignedOffset(alignedOffset)
, allocatedSize(allocatedSize)
SubAllocation::SubAllocation(Allocation *owner, VkDeviceSize allocatedOffset, VkDeviceSize size, VkDeviceSize alignedOffset, VkDeviceSize allocatedSize)
: owner(owner), size(size), allocatedOffset(allocatedOffset), alignedOffset(alignedOffset), allocatedSize(allocatedSize)
{
}
@@ -29,9 +25,9 @@ bool SubAllocation::isReadable() const
return owner->isReadable();
}
void* SubAllocation::getMappedPointer()
void *SubAllocation::getMappedPointer()
{
return (uint8*)owner->getMappedPointer() + alignedOffset;
return (uint8 *)owner->getMappedPointer() + alignedOffset;
}
void SubAllocation::flushMemory()
@@ -44,15 +40,9 @@ void SubAllocation::invalidateMemory()
owner->invalidateMemory();
}
Allocation::Allocation(PGraphics graphics, Allocator* allocator, VkDeviceSize size, uint8 memoryTypeIndex,
VkMemoryPropertyFlags properties, VkMemoryDedicatedAllocateInfo* dedicatedInfo)
: device(graphics->getDevice())
, allocator(allocator)
, bytesAllocated(0)
, bytesUsed(0)
, readable(properties & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)
, properties(properties)
, memoryTypeIndex(memoryTypeIndex)
Allocation::Allocation(PGraphics graphics, Allocator *allocator, VkDeviceSize size, uint8 memoryTypeIndex,
VkMemoryPropertyFlags properties, VkMemoryDedicatedAllocateInfo *dedicatedInfo)
: device(graphics->getDevice()), allocator(allocator), bytesAllocated(0), bytesUsed(0), readable(properties & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT), properties(properties), memoryTypeIndex(memoryTypeIndex)
{
VkMemoryAllocateInfo allocInfo =
init::MemoryAllocateInfo();
@@ -110,8 +100,8 @@ PSubAllocation Allocation::getSuballocation(VkDeviceSize requestedSize, VkDevice
{
freeAllocation->size -= size;
freeAllocation->allocatedSize -= size;
freeAllocation->allocatedOffset += allocatedOffset;
freeAllocation->alignedOffset += allocatedOffset;
freeAllocation->allocatedOffset += size;
freeAllocation->alignedOffset += size;
PSubAllocation subAlloc = new SubAllocation(this, allocatedOffset, size, alignedOffset, size);
activeAllocations[allocatedOffset] = subAlloc.getHandle();
freeRanges.erase(allocatedOffset);
@@ -123,15 +113,15 @@ PSubAllocation Allocation::getSuballocation(VkDeviceSize requestedSize, VkDevice
return nullptr;
}
void Allocation::markFree(SubAllocation* allocation)
void Allocation::markFree(SubAllocation *allocation)
{
VkDeviceSize lowerBound = allocation->allocatedOffset;
VkDeviceSize upperBound = allocation->allocatedOffset + allocation->allocatedSize;
PSubAllocation allocHandle;
for(auto freeRange : freeRanges)
for (auto freeRange : freeRanges)
{
PSubAllocation freeAlloc = freeRange.value;
if(freeAlloc->allocatedOffset + freeAlloc->allocatedSize + 1 == lowerBound)
if (freeAlloc->allocatedOffset + freeAlloc->allocatedSize + 1 == lowerBound)
{
freeAlloc->allocatedSize += allocation->allocatedSize;
allocHandle = freeAlloc;
@@ -139,9 +129,9 @@ void Allocation::markFree(SubAllocation* allocation)
}
}
auto foundAlloc = freeRanges.find(upperBound + 1);
if(foundAlloc != freeRanges.end())
if (foundAlloc != freeRanges.end())
{
if(allocHandle == nullptr)
if (allocHandle == nullptr)
{
allocHandle->allocatedSize += foundAlloc->value->allocatedSize;
freeRanges.erase(foundAlloc->key);
@@ -153,7 +143,7 @@ void Allocation::markFree(SubAllocation* allocation)
allocHandle->alignedOffset -= allocation->allocatedSize;
}
}
if(allocHandle == nullptr)
if (allocHandle == nullptr)
{
allocHandle = new SubAllocation(this, allocation->alignedOffset, allocation->size, allocation->alignedOffset, allocation->allocatedSize);
freeRanges[allocation->allocatedOffset] = allocHandle;
@@ -170,16 +160,16 @@ Allocator::Allocator(PGraphics graphics)
for (size_t i = 0; i < memProperties.memoryHeapCount; ++i)
{
VkMemoryHeap memoryHeap = memProperties.memoryHeaps[i];
HeapInfo& heapInfo = heaps[i];
HeapInfo &heapInfo = heaps[i];
heapInfo.maxSize = memoryHeap.size;
}
}
Allocator::~Allocator()
{
for(auto heap : heaps)
for (auto heap : heaps)
{
for(auto alloc : heap.allocations)
for (auto alloc : heap.allocations)
{
assert(alloc->activeAllocations.empty());
assert(alloc->freeRanges.size() == 1);
@@ -189,45 +179,45 @@ Allocator::~Allocator()
graphics = nullptr;
}
PSubAllocation Allocator::allocate(const VkMemoryRequirements2& memRequirements2, VkMemoryPropertyFlags properties, VkMemoryDedicatedAllocateInfo* dedicatedInfo)
PSubAllocation Allocator::allocate(const VkMemoryRequirements2 &memRequirements2, VkMemoryPropertyFlags properties, VkMemoryDedicatedAllocateInfo *dedicatedInfo)
{
const VkMemoryRequirements& requirements = memRequirements2.memoryRequirements;
const VkMemoryRequirements &requirements = memRequirements2.memoryRequirements;
uint8 memoryTypeIndex;
VK_CHECK(findMemoryType(requirements.memoryTypeBits, properties, &memoryTypeIndex));
uint32 heapIndex = memProperties.memoryTypes[memoryTypeIndex].heapIndex;
if(memRequirements2.pNext != nullptr)
if (memRequirements2.pNext != nullptr)
{
VkMemoryDedicatedRequirements* dedicatedReq = (VkMemoryDedicatedRequirements*)memRequirements2.pNext;
if(dedicatedReq->prefersDedicatedAllocation)
VkMemoryDedicatedRequirements *dedicatedReq = (VkMemoryDedicatedRequirements *)memRequirements2.pNext;
if (dedicatedReq->prefersDedicatedAllocation)
{
PAllocation newAllocation = new Allocation(graphics, this, requirements.size, memoryTypeIndex, properties, dedicatedInfo);
heaps[heapIndex].allocations.add(newAllocation);
return newAllocation->getSuballocation(requirements.size, requirements.alignment);
}
}
for(auto alloc : heaps[heapIndex].allocations)
for (auto alloc : heaps[heapIndex].allocations)
{
PSubAllocation suballoc = alloc->getSuballocation(requirements.size, requirements.alignment);
if(suballoc != nullptr)
if (suballoc != nullptr)
{
return suballoc;
}
}
// no suitable allocations found, allocate new block
PAllocation newAllocation = new Allocation(graphics, this, (requirements.size > MemoryBlockSize) ? requirements.size : MemoryBlockSize, memoryTypeIndex, properties, nullptr);
heaps[heapIndex].allocations.add(newAllocation);
return newAllocation->getSuballocation(requirements.size, requirements.alignment);
}
void Allocator::free(Allocation* allocation)
void Allocator::free(Allocation *allocation)
{
for(auto heap : heaps)
for (auto heap : heaps)
{
for(uint32 i = 0; i < heap.allocations.size(); ++i)
for (uint32 i = 0; i < heap.allocations.size(); ++i)
{
if(heap.allocations[i] == allocation)
if (heap.allocations[i] == allocation)
{
heap.allocations.remove(i, false);
return;
@@ -236,7 +226,7 @@ void Allocator::free(Allocation* allocation)
}
}
VkResult Allocator::findMemoryType(uint32 typeBits, VkMemoryPropertyFlags properties, uint8* typeIndex)
VkResult Allocator::findMemoryType(uint32 typeBits, VkMemoryPropertyFlags properties, uint8 *typeIndex)
{
for (uint8 memoryIndex = 0; memoryIndex < memProperties.memoryTypeCount && typeBits; ++memoryIndex)
{
@@ -250,43 +240,37 @@ VkResult Allocator::findMemoryType(uint32 typeBits, VkMemoryPropertyFlags proper
}
typeBits >>= 1;
}
return VK_ERROR_FORMAT_NOT_SUPPORTED;
}
StagingBuffer::StagingBuffer()
{
}
StagingBuffer::~StagingBuffer()
{
}
StagingManager::StagingManager(PGraphics graphics, PAllocator allocator)
: graphics(graphics)
, allocator(allocator)
: graphics(graphics), allocator(allocator)
{
}
StagingManager::~StagingManager()
{
}
void StagingManager::clearPending()
{
}
PStagingBuffer StagingManager::allocateStagingBuffer(uint32 size, VkBufferUsageFlags usage, bool bCPURead)
{
for(auto it = freeBuffers.begin(); it != freeBuffers.end(); ++it)
{
for (auto it = freeBuffers.begin(); it != freeBuffers.end(); ++it)
{
auto freeBuffer = *it;
if(freeBuffer->allocation->getSize() == size && freeBuffer->allocation->isReadable() == bCPURead)
if (freeBuffer->allocation->getSize() == size && freeBuffer->allocation->isReadable() == bCPURead)
{
activeBuffers.add(freeBuffer.getHandle());
freeBuffers.remove(it, false);
@@ -311,14 +295,13 @@ PStagingBuffer StagingManager::allocateStagingBuffer(uint32 size, VkBufferUsageF
bufferQuery.buffer = stagingBuffer->buffer;
vkGetBufferMemoryRequirements2(vulkanDevice, &bufferQuery, &memReqs);
memReqs.memoryRequirements.alignment =
(16 > memReqs.memoryRequirements.alignment) ?
16 : memReqs.memoryRequirements.alignment;
memReqs.memoryRequirements.alignment =
(16 > memReqs.memoryRequirements.alignment) ? 16 : memReqs.memoryRequirements.alignment;
stagingBuffer->allocation = allocator->allocate(memReqs, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | (bCPURead ? VK_MEMORY_PROPERTY_HOST_CACHED_BIT : VK_MEMORY_PROPERTY_HOST_COHERENT_BIT), stagingBuffer->buffer);
stagingBuffer->allocation = allocator->allocate(memReqs, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | (bCPURead ? VK_MEMORY_PROPERTY_HOST_COHERENT_BIT : VK_MEMORY_PROPERTY_HOST_CACHED_BIT), stagingBuffer->buffer);
stagingBuffer->bReadable = bCPURead;
vkBindBufferMemory(graphics->getDevice(), stagingBuffer->buffer, stagingBuffer->getMemoryHandle(), stagingBuffer->getOffset());
activeBuffers.add(stagingBuffer.getHandle());
return stagingBuffer;
}