void GenericBuffer::CopyTo(uint32_t offset, void* data, uint32_t size) { // TODO use always mapped functionality of VMA VkMemoryPropertyFlags memFlags; vmaGetMemoryTypeProperties(mDevice.Allocator(), mAllocationInfo.memoryType, &memFlags); if ((memFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0) throw std::runtime_error("Not visible buffer"); void* pData; if (vmaMapMemory(mDevice.Allocator(), mAllocation, &pData) != VK_SUCCESS) throw std::runtime_error("Cannot map buffer"); if ((memFlags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) == 0) { auto memRange = vk::MappedMemoryRange() .setMemory(mAllocationInfo.deviceMemory) .setOffset(mAllocationInfo.offset) .setSize(mAllocationInfo.size); mDevice.Handle().invalidateMappedMemoryRanges(memRange); } std::memcpy(data, (uint8_t*)pData + offset, size); vmaUnmapMemory(mDevice.Allocator(), mAllocation); }
void Anvil::MemoryAllocatorBackends::VMA::unmap(void* in_memory_object) { vmaUnmapMemory(m_vma_allocator_ptr->get_handle(), static_cast<VmaAllocation>(in_memory_object) ); }