1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
	// Get the memory requirements for the buffer
	VkMemoryRequirements memoryReq;
	vkGetBufferMemoryRequirements(_VkSystem.device, buffer, &memoryReq);

	// Get Physical Device Properties
	VkPhysicalDeviceMemoryProperties devMemProp = {};
	vkGetPhysicalDeviceMemoryProperties(_VkSystem.physicalDevice, &devMemProp);

	// Check which index of the memory properties supports HOST_VISIBLE?
	int level = log2(memoryReq.memoryTypeBits);
	for (int i = 0; i < level; i++)
	{
		if (devMemProp.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)
		{
			level = i;
			break;
		}
	}

	// Setup Memory Allocation Information
	VkMemoryAllocateInfo allocInfo = {};
	allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
	allocInfo.allocationSize = memoryReq.size;
	allocInfo.memoryTypeIndex = level;