/* * Copyright © 2025 Lucas Francisco Fryzek * SPDX-License-Identifier: MIT */ #include "fgvk_device_memory.h" #include "fgvk_device.h" VKAPI_ATTR VkResult VKAPI_CALL fgvk_AllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo, const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMem) { VK_FROM_HANDLE(fgvk_device, dev, device); VkResult result = VK_SUCCESS; struct fgvk_device_memory *mem; mem = vk_device_memory_create(&dev->vk, pAllocateInfo, pAllocator, sizeof(*mem)); if (!mem) return vk_error(dev, VK_ERROR_OUT_OF_HOST_MEMORY); mem->data = malloc(pAllocateInfo->allocationSize); if (!mem->data) goto fail_alloc; *pMem = fgvk_device_memory_to_handle(mem); return VK_SUCCESS; fail_alloc: vk_device_memory_destroy(&dev->vk, pAllocator, &mem->vk); return result; } VKAPI_ATTR void VKAPI_CALL fgvk_FreeMemory(VkDevice device, VkDeviceMemory _mem, const VkAllocationCallbacks *pAllocator) { VK_FROM_HANDLE(fgvk_device, dev, device); VK_FROM_HANDLE(fgvk_device_memory, mem, _mem); vk_device_memory_destroy(&dev->vk, pAllocator, &mem->vk); } VKAPI_ATTR VkResult VKAPI_CALL fgvk_MapMemory2KHR(VkDevice device, const VkMemoryMapInfoKHR *pMemoryMapInfo, void **ppData) { VK_FROM_HANDLE(fgvk_device_memory, mem, pMemoryMapInfo->memory); *ppData = mem->data; return VK_SUCCESS; } VKAPI_ATTR VkResult VKAPI_CALL fgvk_UnmapMemory2KHR(VkDevice device, const VkMemoryUnmapInfoKHR *pMemoryUnmapInfo) { return VK_SUCCESS; } VKAPI_ATTR VkResult VKAPI_CALL fgvk_FlushMappedMemoryRanges(VkDevice device, uint32_t memoryRangeCount, const VkMappedMemoryRange *pMemoryRanges) { return VK_SUCCESS; } VKAPI_ATTR VkResult VKAPI_CALL fgvk_InvalidateMappedMemoryRanges(VkDevice device, uint32_t memoryRangeCount, const VkMappedMemoryRange *pMemoryRanges) { return VK_SUCCESS; }