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

Method createBuffer

code/29_mipmapping.cpp:1245–1269  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1243 }
1244
1245 void createBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer& buffer, VkDeviceMemory& bufferMemory) {
1246 VkBufferCreateInfo bufferInfo{};
1247 bufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1248 bufferInfo.size = size;
1249 bufferInfo.usage = usage;
1250 bufferInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1251
1252 if (vkCreateBuffer(device, &bufferInfo, nullptr, &buffer) != VK_SUCCESS) {
1253 throw std::runtime_error("failed to create buffer!");
1254 }
1255
1256 VkMemoryRequirements memRequirements;
1257 vkGetBufferMemoryRequirements(device, buffer, &memRequirements);
1258
1259 VkMemoryAllocateInfo allocInfo{};
1260 allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1261 allocInfo.allocationSize = memRequirements.size;
1262 allocInfo.memoryTypeIndex = findMemoryType(memRequirements.memoryTypeBits, properties);
1263
1264 if (vkAllocateMemory(device, &allocInfo, nullptr, &bufferMemory) != VK_SUCCESS) {
1265 throw std::runtime_error("failed to allocate buffer memory!");
1266 }
1267
1268 vkBindBufferMemory(device, buffer, bufferMemory, 0);
1269 }
1270
1271 VkCommandBuffer beginSingleTimeCommands() {
1272 VkCommandBufferAllocateInfo allocInfo{};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected