rewriting swapchain/image/allocation parts
[demo] / src / vulkan / allocator.cc
diff --git a/src/vulkan/allocator.cc b/src/vulkan/allocator.cc
new file mode 100644 (file)
index 0000000..5228a72
--- /dev/null
@@ -0,0 +1,23 @@
+#include <stdio.h>
+#include <string.h>
+
+#include "allocator.h"
+#include "vk.h"
+#include "vkutil.h"
+
+VkDeviceMemory vk_allocate(int size)
+{
+       VkDeviceMemory gpu_mem;
+
+       VkMemoryAllocateInfo gpu_alloc_inf;
+       memset(&gpu_alloc_inf, 0, sizeof gpu_alloc_inf);
+       gpu_alloc_inf.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
+       gpu_alloc_inf.allocationSize = size;
+
+       if(vkAllocateMemory(vk_device, &gpu_alloc_inf, 0, &gpu_mem) != VK_SUCCESS) {
+               fprintf(stderr, "Failed to allocate device memory, mem size: %d\n");
+               return 0;
+       }
+
+       return gpu_mem;
+}