About Social Code
aboutsummaryrefslogtreecommitdiff
path: root/src/frygon/vulkan/fgvk_device_memory.c
blob: d4b7b418a2c4d52bdfd32400c220f3723e529e71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
 * 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;
}