MCPcopy Create free account
hub / github.com/Overv/VulkanTutorial / createBuffer

Method createBuffer

code/25_sampler.cpp:998–1022  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

996 }
997
998 void createBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer& buffer, VkDeviceMemory& bufferMemory) {
999 VkBufferCreateInfo bufferInfo{};
1000 bufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1001 bufferInfo.size = size;
1002 bufferInfo.usage = usage;
1003 bufferInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1004
1005 if (vkCreateBuffer(device, &bufferInfo, nullptr, &buffer) != VK_SUCCESS) {
1006 throw std::runtime_error("failed to create buffer!");
1007 }
1008
1009 VkMemoryRequirements memRequirements;
1010 vkGetBufferMemoryRequirements(device, buffer, &memRequirements);
1011
1012 VkMemoryAllocateInfo allocInfo{};
1013 allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1014 allocInfo.allocationSize = memRequirements.size;
1015 allocInfo.memoryTypeIndex = findMemoryType(memRequirements.memoryTypeBits, properties);
1016
1017 if (vkAllocateMemory(device, &allocInfo, nullptr, &bufferMemory) != VK_SUCCESS) {
1018 throw std::runtime_error("failed to allocate buffer memory!");
1019 }
1020
1021 vkBindBufferMemory(device, buffer, bufferMemory, 0);
1022 }
1023
1024 VkCommandBuffer beginSingleTimeCommands() {
1025 VkCommandBufferAllocateInfo allocInfo{};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected