#include <Vk/DeviceMemory/DeviceMemory.hpp>
#include <Utilities/Utilities.hpp>

Vk::DeviceMemory::DeviceMemory(std::shared_ptr<Vk::Device> device, uint32_t memoryTypeIndex, VkDeviceSize size) : m_device(device)
{
    VkMemoryAllocateInfo allocInfo{};
    allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
    allocInfo.allocationSize = size;
    allocInfo.memoryTypeIndex = memoryTypeIndex;

    if (vkAllocateMemory(device->inner(), &allocInfo, nullptr, &m_deviceMemory) != VK_SUCCESS)
    {
        crash("Failed to allocate GPU memory!");
    }
}

Vk::DeviceMemory::~DeviceMemory()
{
    vkFreeMemory(m_device->inner(), m_deviceMemory, nullptr);
}

VkDeviceMemory Vk::DeviceMemory::inner()
{
    return m_deviceMemory;
}