8 bool vku_allocate(int size, DevMemBlock *block)
10 VkDeviceMemory gpu_mem;
12 VkMemoryAllocateInfo gpu_alloc_inf;
13 memset(&gpu_alloc_inf, 0, sizeof gpu_alloc_inf);
14 gpu_alloc_inf.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15 gpu_alloc_inf.allocationSize = size;
17 if(vkAllocateMemory(vk_device, &gpu_alloc_inf, 0, &gpu_mem) != VK_SUCCESS) {
18 fprintf(stderr, "Failed to allocate device memory, mem size: %d\n", size);
22 block->dev_mem = gpu_mem;
29 void vku_free(VkDeviceMemory gpu_memory)
31 vkFreeMemory(vk_device, gpu_memory, 0);
34 bool vku_write_memory(VkDeviceMemory gpu_mem, int size, void *data)
37 VkResult res = vkMapMemory(vk_device, gpu_mem, 0, size, 0, (void**)&pdata);
38 if(res != VK_SUCCESS) {
39 fprintf(stderr, "Failed to map memory to write data.\n");
43 memcpy(pdata, data, size);
44 vkUnmapMemory(vk_device, gpu_mem);