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

Method createBuffer

code/28_model_loading.cpp:1151–1175  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1149 }
1150
1151 void createBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer& buffer, VkDeviceMemory& bufferMemory) {
1152 VkBufferCreateInfo bufferInfo{};
1153 bufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1154 bufferInfo.size = size;
1155 bufferInfo.usage = usage;
1156 bufferInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1157
1158 if (vkCreateBuffer(device, &bufferInfo, nullptr, &buffer) != VK_SUCCESS) {
1159 throw std::runtime_error("failed to create buffer!");
1160 }
1161
1162 VkMemoryRequirements memRequirements;
1163 vkGetBufferMemoryRequirements(device, buffer, &memRequirements);
1164
1165 VkMemoryAllocateInfo allocInfo{};
1166 allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1167 allocInfo.allocationSize = memRequirements.size;
1168 allocInfo.memoryTypeIndex = findMemoryType(memRequirements.memoryTypeBits, properties);
1169
1170 if (vkAllocateMemory(device, &allocInfo, nullptr, &bufferMemory) != VK_SUCCESS) {
1171 throw std::runtime_error("failed to allocate buffer memory!");
1172 }
1173
1174 vkBindBufferMemory(device, buffer, bufferMemory, 0);
1175 }
1176
1177 VkCommandBuffer beginSingleTimeCommands() {
1178 VkCommandBufferAllocateInfo allocInfo{};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected