rework buffer allocators

This commit is contained in:
Samuliak 2025-01-18 14:42:57 +01:00
parent 24ff85b11f
commit 97b806f16f
No known key found for this signature in database
7 changed files with 391 additions and 442 deletions

View file

@ -73,20 +73,14 @@ void MetalMemoryManager::UploadToBufferCache(const void* data, size_t offset, si
if (m_bufferCacheMode == BufferCacheMode::DevicePrivate)
{
auto allocation = m_tempBufferAllocator.GetAllocation(size);
auto buffer = m_tempBufferAllocator.GetBufferOutsideOfCommandBuffer(allocation.bufferIndex);
memcpy((uint8*)buffer->contents() + allocation.offset, data, size);
auto blitCommandEncoder = m_mtlr->GetBlitCommandEncoder();
// Lock the buffer to make sure it's not deallocated before the copy is done
m_tempBufferAllocator.LockBuffer(allocation.bufferIndex);
auto allocation = m_stagingAllocator.AllocateBufferMemory(size, 1);
memcpy(allocation.memPtr, data, size);
m_mtlr->CopyBufferToBuffer(buffer, allocation.offset, m_bufferCache, offset, size, ALL_MTL_RENDER_STAGES, ALL_MTL_RENDER_STAGES);
blitCommandEncoder->copyFromBuffer(allocation.mtlBuffer, allocation.bufferOffset, m_bufferCache, offset, size);
// Mark buffer as used
m_tempBufferAllocator.MarkBufferAsUsed(allocation.bufferIndex);
// We can now safely unlock the buffer
m_tempBufferAllocator.UnlockBuffer(allocation.bufferIndex);
//m_mtlr->CopyBufferToBuffer(allocation.mtlBuffer, allocation.bufferOffset, m_bufferCache, offset, size, ALL_MTL_RENDER_STAGES, ALL_MTL_RENDER_STAGES);
}
else
{