Vulkan on Android 4 — Model Rendering Part 2

Jin-Long Wu
2 min readOct 24, 2018

--

Photo by andrew jay on Unsplash

After loading models or textures from hard drive to memory, we can further transfer the data from CPU side to GPU side for performance gain. Hence we need space as the destination of the transfer and as the storage of the data.

Buffer

We can view buffers simply as linear arrays of typeless data, nothing more at all.

In Vulkan, a buffer is represented by a VkBuffer and its memory is represented by a VkDeviceMemory. Any operations on a buffer need a VkDevice. Therefore, it is specified on the constructor parameter.

The typical procedure of building a buffer is to create it with vkCreateBuffer, allocate memory for it with vkAllocateMemory, and bind it to memory with vkBindBufferMemory. At the end of life cycle of a buffer, we destroy it with vkDestroyBuffer and its memory with vkFreeMemory.

We start with the construction part, in VkBufferCreateInfo we specify the size of the buffer, what the buffer is used for, what queues are going to access it and how they access it.

Secondly, memory is needed for the buffer to actually hold the data. Before allocating the memory we have to know what types of memory to create with vkGetBufferMemoryRequirements. Once we know the requirements, we have to query the device if the requirements and our preferences are met and return the memory type index with MapMemoryTypeToIndex so that we can allocate memory with vkAllocateMemory.

Finally, binding memory to the buffer is simply a call to vkBindBufferMemory.

--

--